Submitted by Steve Fewell
Description:
If called from &9D2F then set BASIC Text Pointer B = BASIC Text Pointer A.
The lowest level of the expression handler starts at address &9D3B.
There are many levels to the expression handler, each level calls the level above
(to evaluate any higher-level operators) before checking whether any of its operators
need to be evaluated.
The Expression handler is structured as follows:
JSR &9D3B [Entry point (lowest level)] Handle (OR, EOR)
JSR &9D81 handle (AND)
JSR &9DA9 handle (<, =, >)
JSR &9E4C handle (+, -)
JSR &9FC7 handle (*, /, MOD, DIV)
JSR &A012 handle (Skip spaces and ^)
JSR &AD36 handle (leading -, Variable name/value, Open Bracket, BASIC Keyword (functions))
Some routines have additional entry points which enable a previous value to be stored
on the stack and/or a new value obtained before evaluating the expression.
This is so that any previous value is not lost during the expression handling,
in situations where more than 1 value may be required to be worked on at the same time.
After evaluating the operator, the routine usually jumps back into the expression handler
at the same level as the previous operator - this checks for further operators with the same
priority (precedence) before carrying on with the lower levels. I.e. an expression can contain
many multiplications, one after the other, all which much be evaluated before the lower level is
returned to (i.e. 2 + X * Y * Z). The exception for this, is the relational operators (<, =, >);
these cannot be located one after the other, as this is not allowed in BASIC.
If there are no more operators/values to evaluate (&9D46), then the PTR B offset is decremented,
Y = Value type, and ?&27 is also set to the value type, and then exit.
Note: On exit X contains the next non-space character found after the expression (pointed to
by &1B). Many of the routines that call this expression handler use this as a quick way of
knowing what the next character is.
9D2F | 165 011 | A5 0B | LDA &0B | |
9D31 | 133 025 | 85 19 | STA &19 | |
9D33 | 165 012 | A5 0C | LDA &0C | |
9D35 | 133 026 | 85 1A | STA &1A | |
9D37 | 165 010 | A5 0A | LDA &0A | |
9D39 | 133 027 | 85 1B | STA &1B | |
9D3B | 032 129 157 | 20 81 9D | JSR &9D81 Expression Handler level 2 (AND) | |
9D3E | 224 132 | E0 84 | CPX#&84 Token value for OR | |
9D40 | 240 010 | F0 0A | BEQ 10 --> &9D4C OR operator | |
9D42 | 224 130 | E0 82 | CPX#&82 Token value for EOR | |
9D44 | 240 032 | F0 20 | BEQ 32 --> &9D66 EOR operator | |
9D46 | 198 027 | C6 1B | DEC &1B | |
9D48 | 168 | A8 | TAY | |
9D49 | ' | 133 039 | 85 27 | STA &27 |
9D4B | ` | 096 | 60 | RTS |
9D81 Expression Handler Level 2 [AND]
9D7B | 032 190 150 | 20 BE 96 | JSR &96BE Check for Integer & convert to Integer if Float | |
9D7E | & | 032 038 188 | 20 26 BC | JSR &BC26 Push Integer to Stack |
9D81 | 032 169 157 | 20 A9 9D | JSR &9DA9 Expression Handler level 3 (<, =, >) | |
9D84 | 224 128 | E0 80 | CPX#&80 Token value for AND | |
9D86 | 240 001 | F0 01 | BEQ 1 --> &9D89 AND operator | |
9D88 | ` | 096 | 60 | RTS |
9DA9 Expression Handler Level 3 [<, =, >]
9DA9 | L | 032 076 158 | 20 4C 9E | JSR &9E4C Expression Handler level 4 (+, -) |
9DAC | ? | 224 063 | E0 3F | CPX#&3F '?' |
9DAE | 176 004 | B0 04 | BCS 4 --> &9DB4 | |
9DB0 | < | 224 060 | E0 3C | CPX#&3C |
9DB2 | 176 001 | B0 01 | BCS 1 --> &9DB5 '=' and other Relational operators | |
9DB4 | ` | 096 | 60 | RTS |
9E4C Expression Handler Level 4 [+, -]
9E4C | 032 199 159 | 20 C7 9F | JSR &9FC7 Expression Handler level 5 (*, /, MOD, DIV) | |
9E4F | + | 224 043 | E0 2B | CPX#&2B '+' |
9E51 | 240 005 | F0 05 | BEQ 5 --> &9E58 '+' Operator - Addition | |
9E53 | - | 224 045 | E0 2D | CPX#&2D '-' |
9E55 | f | 240 102 | F0 66 | BEQ 102 --> &9EBD '-' Operator - Subtraction |
9E57 | ` | 096 | 60 | RTS |
9FC7 Expression Handler Level 5 [*, /, MOD, DIV]
9FC1 | L; | 076 059 159 | 4C 3B 9F | JMP &9F3B | |
9FC4 | & | 032 038 188 | 20 26 BC | JSR &BC26 Push Integer to Stack | |
9FC7 | 032 018 160 | 20 12 A0 | JSR &A012 | JSR &A012 Expression Handler level 6 (Skip Spaces, ^) | |
9FCA | * | 224 042 | E0 2A | CPX#&2A '*' | |
9FCC | 240 243 | F0 F3 | BEQ -13 --> &9FC1 | ||
9FCE | / | 224 047 | E0 2F | CPX#&2F '/' | |
9FD0 | 240 009 | F0 09 | BEQ 9 --> &9FDB '/' Operator - Division | ||
9FD2 | 224 131 | E0 83 | CPX#&83 Token value for MOD | ||
9FD4 | 240 031 | F0 1F | BEQ 31 --> &9FF5 Integer MOD routine | ||
9FD6 | 224 129 | E0 81 | CPX#&81 Token value for DIV | ||
9FD8 | # | 240 035 | F0 23 | BEQ 35 --> &9FFD Integer DIV routine | |
9FDA | ` | 096 | 60 | RTS |
A012 Expression Handler Level 6 [Skip spaces, ^]
A00F | & | 032 038 188 | 20 26 BC | JSR &BC26 Push Integer to Stack |
A012 | 6 | 032 054 173 | 20 36 AD | JSR &AD36 Evaluate Variable / Value / BASIC Keyword (Function)/ Open bracket |
A015 | H | 072 | 48 | PHA |
A016 | 164 027 | A4 1B | LDY &1B | |
A018 | 230 027 | E6 1B | INC &1B | |
A01A | 177 025 | B1 19 | LDA (&19),Y | |
A01C | 201 032 | C9 20 | CMP#&20 <space> | |
A01E | 240 246 | F0 F6 | BEQ -10 --> &A016 | |
A020 | 170 | AA | TAX | |
A021 | h | 104 | 68 | PLA |
A022 | ^ | 224 094 | E0 5E | CPX#&5E '^' |
A024 | 240 001 | F0 01 | BEQ 1 --> &A027 '^' operator | |
A026 | ` | 096 | 60 | RTS |
The disassembly for the "AD36 Expression Handler Level 7 [Unary -, Variable/Value, Open bracket, BASIC Keyword (function)]" routine is in the separate description for "AD36 Evaluate Variable/Value"