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
0x86
0x87GO (GOTO, GOSUB)
0x88
0x89IF
0x8ARESTOREPEEK
0x8BRETURNLEN
0x8C'
0x8D VAL
0x8ESTOPASC
0x8FELSECHR$
0x90
0x91
0x92
0x93DEFINT
0x94
0x95 HEX$
0x96ON
0x97
0x98ERROR
0x99RESUMEGR$ (unsure, used for DEFGR$)
0x9A LEFT$
0x9B RIGHT$
0x9CLOCATEMID$
0x9DCLS
0x9ECONSOLEVARPTR
0x9FPSETRND
0xA0 INKEY$
0xA1 INPUT$
0xA2EXECCRSLIN
0xA3BEEP
0xA4COLORSCREEN
0xA5LINEPOS
0xA6BOX (BOXF)PTRIG
0xA7
0xA8ATTRB
0xA9DEF (unsure, used for DEFGR$ function?)
0xAAPOKE
0xABPRINT
0xAC
0xAD
0xAECLEAR
0xAF
0xB0KEYSPACE$
0xB1 STRING$
Extended BASIC functions
0xB2 DSKI$
0xB3LOAD (LOADM)FKEY$
0xB4
0xB5OPEN
0xB6CLOSE
0xB7INPEN
0xB8
0xB9PLAY
0xBATAB(PALETTE
0xBBTO (FOR … TO, GOTO)
0xBCSUB (GOSUB)HEAD
0xBDFNROT
0xBE SHOW
0xBFUSING (PRINT USING)ZOOM
0xC0
0xC1ERL
0xC2ERR
0xC3
0xC4THEN
0xC5NOT
0xC6STEP
0xC7+
0xC8-
0xC9*
0xCA/
0xCB
0xCCAND
0xCDOR
0xCE
0xCF
0xD0
0xD1MOD
0xD2@
0xD3>
0xD4=
0xD5<
DOS BASICOpcode
0xD6DSKINI
0xD7
0xD8
0xD9
0xDA
0xDB
0xDC
0xDDPUT
0xDEGET
0xDF
0xE0
0xE1
0xE2
0xE3
0xE4
0xE5
0xE6COPY
0xE7
0xE8
0xE9
0xEA
0xEB
0xEC
0xED
0xEE
0xEFDO
0xF0LOOP
0xF1EXIT
0xF2
0xF3
0xF4
0xF5
0xF6
0xF7
0xF8TURTLE
documentations/basic_internals.1426411086.txt.gz · Last modified: 2015/03/15 10:18 by pulkomandy
CC0 1.0 Universal
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0