[This is a work in progress, about 90% complete]
Here is a complete annotated disassembly of Altair BASIC 3.2 (4K). I have faithfully followed the program order, and the code naturally divides into three sections - the Interpreter, the Maths Package, and Initialisation.
Each of these sections is more-or-less logically subdivided into a number of subsections.
Interpreter (Explanation) - Explanations and
overviews of most of the internal logic used in BASIC. It describes the memory
layout, key concepts, structures and variables, and you shouldn't look at a
line of code until you've read through this.
| Section | Base | Size | Key Functions | |
| 1.1 | Restarts | 0000 | 61 | Start, SyntaxCheck, NextChar, OutChar, CompareHLDE, FTestSign, PushNextWord |
| 1.2 | 003D | 189 | [no code in this section] | |
| 1.3 | Error Codes & Globals | 00FA | 152 | [no code in this section] |
| 1.4 | Utility Functions | 0192 | 101 | GetFlowPtr, CopyMemoryUp, CheckEnoughVarSpace, CheckEnoughMem, OutOfMemory, SyntaxError, DivideByZero, Error |
| 1.5 | The BASIC Prompt & Program Storage | 01F7 | 375 | Stop, Main, StoreProgramLine, FindProgramLine, New, Run, ResetAll, InputLineWith'?', Tokenize, InputLine |
| 1.6 | Terminal I/O | 036E | 32 | OutChar_tail, InputChar |
| 1.7 | LIST Handler | 038E | 71 | List |
| 1.8 | FOR Handler | 03D5 | 76 | For |
| 1.9 | Execution | 0421 | 61 | ExecNext, Exec |
| 1.10 | More Utility Functions | 045E | 63 | NextChar_tail, Restore, TestBreakKey, CharIsAlpha, GetSubscript |
| 1.11 | Goto, Gosub, and Return | 049D | 101 | LineNumberFromStr, Gosub, Goto, Return, FindNextStatement |
| 1.12 | Assigning Variables | 0502 | 20 | Let, AssignVar |
| 1.13 | IF Handler | 0516 | 63 | If |
| 1.14 | Printing | 0555 | 143 | Print, NewLine, PrintString, ToNextTabBreak, Tab |
| 1.15 | INPUT & READ Handlers | 05E4 | 101 | Input, Read |
| 1.16 | NEXT Handler | 0649 | 65 | Next |
| 1.17 | Expression Evaluation | 068A | 135 | EvalExpression, EvalTerm |
| 1.18 | Variable Management | 0711 | 232 | Dim, GetVar, GetArrayVar |
Total size: 2041 bytes
Math package (explained) - All the concepts
needed to understand the math package.
| Section | Base | Size | Key Functions | |
| 2.1 | Utility Functions | 07F9 | 17 | FWordToFloat, FAddOneHalf |
| 2.2 | 080A | 81 | FSub, FAdd | |
| 2.3 | Mantissa Magic | 085B | 136 | FNormalise, FMantissaLeft, FMantissaInc, Overflow, FAddMantissas, FNegateInt, FMantissaRtOnce, FMantissaRtMult |
| 2.4 | Multiplication & Division | 08E3 | 247 | FMul, FDiv, FDivByTen, FMulByTen, FZero, FExponentAdd |
| 2.5 | Sign Magic | 09DA | 40 | FTestSign_tail, InvSignToInt, SignToInt, Sgn, FCharToFloat, Abs, FNegate |
| 2.6 | Moving FACCUM about | 0A02 | 53 | FPush, FLoadFromMem, FLoadFromBCDE, FCopyToBCDE, FLoadBCDE, FCopyToMem |
| 2.7 | Unpacking & Comparison | 0A37 | 64 | FUnpack, FCompare |
| 2.8 | Converting to Integers | 0A77 | 60 | FAsInteger, FMantissaDec, Int |
| 2.9 | Reading Numbers | 0AB3 | 124 | FIn |
| 2.10 | Printing Numbers | 0B2F | 242 | PrintIN, PrintInt, FOut |
| 2.11 | SQR | 0C21 | 62 | Sqr |
| 2.12 | RND | 0C5F | 54 | Rnd |
| 2.13 | SIN | 0C95 | 130 | Sin |
Total size: 1307 bytes.
| Section | Base | Size | Key Functions | |
| 3.1 | IO Detection | 0D21 | 109 | Init |
| 3.2 | 0D8E | 367 |
Total size: 478 bytes.