BBC BASIC program line format ============================= BBC BASIC programs are usually stored in a tokenised format. Acorn/Wilson format BASIC is stored as: +----+------+------+------+----------------+----+ +----+-----+ | CR | line | line | line | tokenised line | CR | etc. | CR | &FF | | | high | low |length| contents | | | | | +----+------+------+------+----------------+----+ +----+-----+ | ^ +-------- start + length = next CR ------------->------+ Russell format BASIC is stored as: +------+------+------+----------------+----+ +----+-----+-----+-----+ | line | line | line | tokenised line | CR | etc. | CR | &00 | &00 | &FF | |length| low | high | contents | | | | | | | +------+------+------+----------------+----+ +----+-----+-----+-----+ | ^ +-------- start + length = next length byte ---->------+ Line numbers within a line are also tokenised, encoded to make them easily found by RENUMBER, and to prevent them appearing to be control characters or tokens by forcing them into the range &40-&7F. Byte 0 : 141 Byte 1 :(((lsb AND &C0) DIV 4) OR ((msb AND &C0) DIV 16)) EOR &54 Byte 2 : (lsb AND &3F) OR &40 Byte 3 : (msb AND &3F) OR &40 6502 BASIC line numbers can go to a maximum of 32767 (&7FFF), other BASICs can use the full range to 65279 (&FEFF). Most of the tokens used by different versions of BBC BASIC are the same, but extended tokens are different. The differences are between: * Acorn/Wilson BASIC descended from the 6502 version, the 32000, ARM, PDP11, 6809 and others - uses 2-byte extended tokens * Russell BASIC descended from the Z80 version, 80x86, Windows, SDL - uses 1-byte extended tokens. A running program can tell what format the program is in by examining TOP-3: IF ?(TOP-3)=0 THEN Russell format IF ?(TOP-3)>0 THEN Acorn format