BASIC file formats

From Ninerpedia
Revision as of 03:00, 29 March 2015 by Mizapf (talk | contribs)
Jump to navigation Jump to search

BASIC programs written for TI BASIC and Extended BASIC are not stored as plain text in memory. This is different with assembler programs which are edited as text files and then assembled to a Tagged Object Code file.

This is not appropriate for BASIC. When the program is started, and it would be stored as plain text, the BASIC interpreter would have to parse the line first, finding out the commands and the arguments, and then execute it. This is typical for script languages of today, but it would be just too slow, and we know well that TI BASIC and Extended BASIC are quite slow, compared with other platforms.

BASIC lines are tokenized. For each command or special character or character sequence that has a meaning in BASIC there is a one-byte code, the token. Example:

Command Token (hex)
NEW 00
SAVE 07
EDIT 09
PRINT 9c
& b8
"..." (quoted string) c7
SEG$ d8
VALIDATE fe

You can find a complete table here.

So let us take a simple BASIC line like

PRINT "HELLO"

There will not be a string like "PRINT" in memory, because the parser recognized this word as a command and replaced it with its token. Second, there is a string following the command, which is enclosed in quotes. The contents can be anything, so the parser must copy it into memory as is.

Eventually, the line is converted to the following byte sequence:

09 9c c7 05 48 45 4c 4c 4f 00
line length PRINT "..." string length H E L L O end


TODO: continue