Applesoft: Internal program storage format

Applesoft programs are stored one line at a time starting at memory location $801 and ascending in order by line number.
Each line is stored in this format:

                          $8xx
00  01  02  03  04  05  06  07  08  09  0A  0B  0C  0D  0E

00  0D  08  0A  00  97  3A  BA  22  48  49  22  00  00  00
 E   LINK   LINE #   H   :   P   "   H   I   "   E   LINK
 O                   O       R                   O
 L                   M       I                   L
                     E       N
                             T

The first two bytes are pointers to the absolute address of the beginning of the next line. The first byte is the least significant.


The next two bytes are integers representing the line number of that line. Again, the first byte is the least significant.

The next byte, a token, stands for the first Applesoft keyword. When the lines starts with "A = 1", the variable name (in ASCII) is first. The remaining command consists of keywords and symbols reduced to one byte tokens and unmodified ASCII text.

A list of Applesoft's tokens appears on page 121 of the Applesoft Reference manual.

The subsequent bytes are either "$00"s signifying the end of this line, or "$3A"s, indicating multi-statement lines, followed by a "$00.


If the link field for a line is 00 00, then Applesoft considers it the last line in the program while running or listing. The SAVE command uses a different pointer for the end of the program. $AF,B0 normally points to the high byte in the line number of the line beyond the last line.
Published Date: Feb 18, 2012