====== BASIC file format ====== The format is similar for all versions of the BASIC but there are some differences. The most obvious one is that the list of tokens was expanded, but there are other changes as well. ===== Header ===== BASIC sources aren't stored in plain ASCII. To allow faster loading and parsing, they are stored in bytecode format. The file stats with the marker 0xFF, followed by the file size, and then comes BASIC lines. ^Offset^Description^ |0|File type = 0xFF| |1|File size| ===== Lines ===== A BASIC program is a packed linked list of program lines. ^Offset^Description^ |0|Address of next line| |2|Line number in hex| |4|NULL-terminated line data| The end of the listing is marked with a NULL next line pointer. The "address of next line" is the absolute address on MO5, but on TO8 it is the length of the line. FIXME Which scheme is used in the other versions of the BASIC? The line data is a mix of tokens and ASCII characters. The tokens are used to encode all the keywords and functions, but everything else (numbers, strings, comments) is stored in ASCII. ===== Token list ===== The token encoding is a simple search and replace system. This means some instructions don't have a dedicated token. For example, ''BOXF'' is the token ''BOX'' followed by the letter ''F''. There are no ''GOTO'' and ''GOSUB'' tokens, but instead separate ''GO'', ''TO'', and ''SUB'' tokens which can be combined. The ''TO'' token is also used in for loops. There are two sets of tokens, for keywords and functions. The function tokens are escaped with the character 0xFF. The distinction between keywords and functions is a bit fuzzy, for example COLOR is a keyword, but SCREEN is a function. ^Token^Keyword^Function^ |0x80|''END''| |0x81|''FOR''|''INT''| |0x82|''NEXT''|''ABS''| |0x83|''DATA''| |0x84|''DIM''| |0x85|''READ''| |0x86| |0x87|''GO'' (GOTO, GOSUB)| |0x88| |0x89|''IF''| |0x8A|''RESTORE''|''PEEK''| |0x8B|''RETURN''|''LEN''| |0x8C|'| | |0x8D| |''VAL''| |0x8E|''STOP''|''ASC''| |0x8F|''ELSE''|''CHR$''| |0x90| |0x91| |0x92| |0x93|''DEFINT''| |0x94| |0x95| |''HEX$''| |0x96|''ON''| |0x97| |0x98|''ERROR''| |0x99|''RESUME''|''GR$'' (unsure, used for DEFGR$)| |0x9A| |''LEFT$''| |0x9B| |''RIGHT$''| |0x9C|''LOCATE''|''MID$''| |0x9D|''CLS''| |0x9E|''CONSOLE''|''VARPTR''| |0x9F|''PSET''|''RND''| |0xA0| |''INKEY$''| |0xA1| |''INPUT$''| |0xA2|''EXEC''|''CRSLIN''| |0xA3|''BEEP''| |0xA4|''COLOR''|''SCREEN''| |0xA5|''LINE''|''POS''| |0xA6|''BOX'' (BOXF)|''PTRIG''| |0xA7| |0xA8|''ATTRB''| |0xA9|''DEF'' (unsure, used for DEFGR$ function?)| |0xAA|''POKE''| |0xAB|''PRINT''| |0xAC| |0xAD| |0xAE|''CLEAR''| |0xAF| |0xB0|''KEY''|''SPACE$''| |0xB1| |''STRING$''| | | ^Extended BASIC functions^ |0xB2| |''DSKI$''| |0xB3|''LOAD'' (LOADM)|''FKEY$''| |0xB4| |0xB5|''OPEN''| |0xB6|''CLOSE''| |0xB7|''INPEN''| |0xB8| |0xB9|''PLAY''| |0xBA|''TAB(''|''PALETTE''| |0xBB|''TO'' (FOR ... TO, GOTO)|''BANK'' |0xBC|''SUB'' (GOSUB)|''HEAD''| |0xBD|''FN''|''ROT''| |0xBE| |''SHOW''| |0xBF|''USING'' (PRINT USING)|''ZOOM''| |0xC0| |0xC1|''ERL''| |0xC2|''ERR''| |0xC3| |0xC4|''THEN''| |0xC5|''NOT''| |0xC6|''STEP''| |0xC7|''+''| |0xC8|''-''| |0xC9|''*''| |0xCA|''/''| |0xCB| |0xCC|''AND''| |0xCD|''OR''| |0xCE| |0xCF| |0xD0| |0xD1|''MOD''| |0xD2|''@''| |0xD3|''>''| |0xD4|''=''| |0xD5|''<''| ^DOS BASIC^Opcode^ |0xD6|''DSKINI''| |0xD7| |0xD8| |0xD9| |0xDA| |0xDB| |0xDC| |0xDD|''PUT''| |0xDE|''GET''| |0xDF| |0xE0| |0xE1| |0xE2| |0xE3| |0xE4| |0xE5| |0xE6|''COPY''| |0xE7| |0xE8| |0xE9| |0xEA| |0xEB| |0xEC| |0xED| |0xEE| |0xEF|''DO''| |0xF0|''LOOP''| |0xF1|''EXIT''| |0xF2| |0xF3| |0xF4| |0xF5| |0xF6| |0xF7| |0xF8|''TURTLE''|