This is an old revision of the document!


BASIC file format

Note: the following applies to the MO5 BASIC 1.0. It wasn't checked how much of this applies to the other BASICs.

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.

OffsetDescription
0File type = 0xFF
1File size

Lines

A BASIC program is a packed linked list of program lines.

OffsetDescription
0Address of next line
2Line number in hex
4NULL-terminated line data

The end of the listing is marked with a NULL next line pointer.

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.

TokenKeywordFunction
0x80END
0x81FORINT
0x82NEXTABS
0x83DATA
0x84DIM
0x85READ
0x87GO (GOTO, GOSUB)
0x89IF
0x8ARESTORE
0x8BRETURNLEN
0x8E ASC
0x8F CHR$
0x93DEFINT
0x99 GR$ (unsure, used for DEFGR$)
0x9A LEFT$
0x9CLOCATEMID$
0x9DCLS
0x9F RND
0xA0 INKEY$
0xA1 INPUT$
0xA2EXEC
0xA4COLORSCREEN
0xA5LINE
0xA6BOX (BOXF)
0xA8ATTRB
0xA9DEF (unsure, used for DEFGR$ function?)
0xAAPOKE
0xABPRINT
0xAECLEAR
0xB9PLAY
0xBBTO (FOR … TO, GOTO)
0xBBSUB (GOSUB)
0xBFUSING (PRINT USING)
0xC4THEN
0xC6STEP
0xC7+
0xC8-
0xC9*
0xCA/
0xCCAND
0xCDOR
0xD3>
0xD4=
0xD5<
documentations/basic_internals.1426402879.txt.gz · Last modified: 2015/03/15 08:01 by pulkomandy
CC0 1.0 Universal
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0