Applesoft BASIC tokenized file

Applesoft BASIC was licensed from Microsoft (with some changes by Apple) and originally made available to be loaded from tape or disk. Apple models starting with the Apple II+ (the first new model after the Apple II) had Applesoft BASIC in ROM instead of the older Integer BASIC. An Applesoft I language was first released in 1977, followed by Applesoft II Floating Point BASIC in 1978, which is the most-used version. The later Apple III Business BASIC was based on Applesoft.

There were some notorious bugs in Applesoft, such as an implementation of ONERR GOTO which messed up the program stack, requiring some devious peeks, pokes, and calls to get around it. Unfortunately, the fact that the language was stored in ROM (except for users of really old Apples who loaded it from disk or tape) made it difficult to update with bug fixes (unlike today's software that pesters you to install new updates practically every time you start your computer), and they couldn't fix it in newer machines either, since that would break all the old programs that expected the bug. So Apple users were stuck with the bugs for the whole life of that platform.

Applesoft BASIC programs were stored in a tokenized format, in files which were designated in Apple DOS directories as type "A".

Similar to a number of other BASIC tokenizations (but distinct from Integer BASIC tokenization), Applesoft programs preserved ASCII characters unchanged in the 7-bit range (bytes with high bit clear) and used the "high bit set" byte values (#128-#255) to store tokens. BASIC lines were separated by the null byte (00), and started with a two-byte address of the next program line in memory, then a two-byte little-endian integer giving the line number, then the tokenized commands and literal characters of the program line.

The token list reveals what is probably the most obscure command in Applesoft BASIC (or maybe any BASIC at all), SHLOAD. Urban Dictionary defines this as a synonym for "shitload", but Applesoft uses it as a command to load a shape table from cassette. Yes, cassette... to do the same from disk required some messy PEEKs and POKEs. Well, doing just about anything on an Apple II ended up requiring PEEKs and POKEs and CALLs... if you were a serious Apple programmer, you probably had some of those Beagle Bros. charts listing them.

Microsoft released a compiler for Applesoft called TASC (The AppleSoft Compiler).

Tokens
Blank values indicate either that the token is unused or is used for something unknown.

Format documentation

 * Description of tokenization and program/data memory usage
 * List of tokens
 * Applesoft BASIC Internal Structure

Manuals

 * 1977 Applesoft manual
 * 1978 Applesoft II "blue book" manual
 * 1978 Applesoft II green-covered manual
 * TASC (The Applesoft Compiler) manual
 * Apple III Business BASIC Manual Volume 1
 * Apple III Business BASIC Manual Volume 2

Tools

 * Links to Applesoft emulators
 * JSMESS in-browser Apple II emulator
 * JSMESS in-browser Apple IIe emulator
 * JSMESS in-browser Apple IIc emulator
 * Applesoft BASIC emulator in JavaScript

Other links

 * Documented disassembled code from Applesoft ROMs
 * 1978 source to Microsoft 6502 BASIC (ancestral to Applesoft; token list embedded is not quite the same)