Applesoft BASIC is the floating-point BASIC from Microsoft that the Apple II Plus and later machines have in ROM. A program in memory
is a list of lines kept between the address in TXTTAB ($67/$68, normally $0801) and the
address in VARTAB ($69/$6A). A DOS 3.3 A file is those bytes preceded by their length;
a ProDOS BAS file is those bytes alone, its aux type being the load address.
In a file
| File system | What is stored |
|---|---|
DOS 3.3, type A | 2 bytes: the length of the program (low byte first); then the program, length bytes |
ProDOS, type BAS ($FC) | the program, as many bytes as the end of file says |
The explorer gives the viewer the program without the DOS length. Some files carry more after the program: the real
RENUMBER file on the DOS 3.3 System Master is 3,071 bytes of which the program is 765; the rest is the machine-code routine the program installs. The viewer marks
such bytes as extra.
Lines
| Field | Size | Meaning |
|---|---|---|
| Next line | 2 | The address the next line is stored at, low byte first. The address after the last line is followed by $00 $00 |
| Line number | 2 | Low byte first; 0 to 63999 |
| Text | any | The statements; keywords are tokens, everything else is ASCII (with the high bit clear) |
| End | 1 | $00 |
The next-line addresses are absolute, written for the address the program was in when it was saved. Loading a program at another address
relies on the ROM relinking the lines. The viewer works out the address from the first line (its pointer minus its length) and checks every other line against it; a program
whose pointers disagree is reported line by line. A real example, the first line of HELLO on the DOS 3.3 System Master (after the 2-byte DOS length A3 01, 419 bytes): 09 08 0A 00 89 3A 97 00. The line is 8 bytes long, so the next line is at $0801 + 8 = $0809; its number is $000A, 10; its text is the tokens $89 (TEXT), a colon and $97 (HOME), and a zero ends it.
The end of the program
A next-line address of $0000 ends the program, so the last line is followed by two zero bytes. A file that has no such pair, or a last line without its $00, is not read as a program.
Tokens
A byte from $80 to $EA outside a string, a REM and the text of DATA is a keyword. The table was compared
with the keyword table in the Apple IIgs ROM 01 (the Applesoft ROM of the enhanced IIe, at $D0D0) and with the Applesoft image on the real DOS 3.3 System Master disk: 107 words, the same in both. Bytes above $EA are not tokens. A listing puts a space before and after each keyword, as LIST does.
| Token | Keyword | Token | Keyword | Token | Keyword | Token | Keyword |
|---|---|---|---|---|---|---|---|
$80 | END | $81 | FOR | $82 | NEXT | $83 | DATA |
$84 | INPUT | $85 | DEL | $86 | DIM | $87 | READ |
$88 | GR | $89 | TEXT | $8A | PR# | $8B | IN# |
$8C | CALL | $8D | PLOT | $8E | HLIN | $8F | VLIN |
$90 | HGR2 | $91 | HGR | $92 | HCOLOR= | $93 | HPLOT |
$94 | DRAW | $95 | XDRAW | $96 | HTAB | $97 | HOME |
$98 | ROT= | $99 | SCALE= | $9A | SHLOAD | $9B | TRACE |
$9C | NOTRACE | $9D | NORMAL | $9E | INVERSE | $9F | FLASH |
$A0 | COLOR= | $A1 | POP | $A2 | VTAB | $A3 | HIMEM: |
$A4 | LOMEM: | $A5 | ONERR | $A6 | RESUME | $A7 | RECALL |
$A8 | STORE | $A9 | SPEED= | $AA | LET | $AB | GOTO |
$AC | RUN | $AD | IF | $AE | RESTORE | $AF | & |
$B0 | GOSUB | $B1 | RETURN | $B2 | REM | $B3 | STOP |
$B4 | ON | $B5 | WAIT | $B6 | LOAD | $B7 | SAVE |
$B8 | DEF | $B9 | POKE | $BA | $BB | CONT | |
$BC | LIST | $BD | CLEAR | $BE | GET | $BF | NEW |
$C0 | TAB( | $C1 | TO | $C2 | FN | $C3 | SPC( |
$C4 | THEN | $C5 | AT | $C6 | NOT | $C7 | STEP |
$C8 | + | $C9 | - | $CA | * | $CB | / |
$CC | ^ | $CD | AND | $CE | OR | $CF | > |
$D0 | = | $D1 | < | $D2 | SGN | $D3 | INT |
$D4 | ABS | $D5 | USR | $D6 | FRE | $D7 | SCRN( |
$D8 | PDL | $D9 | POS | $DA | SQR | $DB | RND |
$DC | LOG | $DD | EXP | $DE | COS | $DF | SIN |
$E0 | TAN | $E1 | ATN | $E2 | PEEK | $E3 | LEN |
$E4 | STR$ | $E5 | VAL | $E6 | ASC | $E7 | CHR$ |
$E8 | LEFT$ | $E9 | RIGHT$ | $EA | MID$ |
Inside a quoted string, after REM and in the items of DATA up to the next colon the bytes are plain characters. The tokeniser drops spaces elsewhere, so a
listing shows the spaces the ROM's LIST adds, not the ones the programmer typed. A line number after GOTO, GOSUB, THEN and RUN is kept as ASCII digits, not as a token or a
binary number, so a viewer can find it: the explorer checks each against the lines of the program and reports the ones that are not there.
What was compared
- the keyword table with the IIgs ROM and the real FPBASIC image (107 of 107 words);
- eight real programs of the DOS 3.3 System Master (185 lines): every next-line address agrees with the length of the lines before it, every program ends with
$00 $00, and every line number afterGOTO,GOSUBandTHENis a line that exists; - the one ProDOS
BASfile on this Mac (COPY.MEon the ProDOS utilities disk) reads as a consistent program with no length prefix.
No Applesoft program in a file with a different load address (a program saved with TXTTAB moved) was available, so that case is checked on a built file only.