Submitted by Steve Fewell
Starting Address: &9CC9
Entry criteria: if called from &9CCA, the flags indicate the value type we
are working with (Int,Float,String); otherwise, (called from &9CC9) X contains
this information.
If we are working with an integer value: the IWA contains the value to compare.
BASIC Text pointer points to the expression to compare IWA with.
Exit: Zero Flag = 1 if values are equal. Carry is set if value 1 > value 2; clear otherwise.
Y = 00.
Description:
Test the value type (X). If the value is a string, then do Compare String routine,
If the value is a Float, then do compare Float routine, otherwise continue with this routine
as the 1st value to compare is an Integer.
Push the IWA to the Stack (first value to compare).
Gosub &9E4C to get the result of the expression (in the BASIC program text line),
[we need to process expression level (+,-) upwards as any operators below this level should
only be evaluated once this compare has been evaluated].
If the second value is a string then generate a Type Mismatch error.
If the second value is a float then goto &9C65, to convert the first value to a Float
and continue with the Compare Float values routine (as the values are now Float not Integer).
Reverse the sign of the IWA (second value) and the Integer on the Stack (first value).
This causes positive numbers to correctly be identified as greater than negative values.
Pop the Integer from the stack (first value) and compare each byte with the corresponding byte
of the IWA (second value) LSB first.
C = 1 if the first value is > the second value.
&2A contains a value if the two values are not equal, this is returned in A.
Exit with A and C set as appropriate.
9CC6 | L | 076 146 144 | 4C 92 90 | JMP &9092 Type Mismatch error |
9CC9 | 138 | 8A | TXA | |
9CCA | 6 | 240 054 | F0 36 | BEQ 54 --> &9D02 Compare String values |
9CCC | 0 | 048 180 | 30 B4 | BMI -76 --> &9C82 Compare Float values |
9CCE | - | 165 045 | A5 2D | LDA &2D |
9CD0 | H | 072 | 48 | PHA |
9CD1 | , | 165 044 | A5 2C | LDA &2C |
9CD3 | H | 072 | 48 | PHA |
9CD4 | + | 165 043 | A5 2B | LDA &2B |
9CD6 | H | 072 | 48 | PHA |
9CD7 | * | 165 042 | A5 2A | LDA &2A |
9CD9 | H | 072 | 48 | PHA |
9CDA | L | 032 076 158 | 20 4C 9E | JSR &9E4C Expression handler [(+,-) level and above] |
9CDD | 168 | A8 | TAY | |
9CDE | 240 230 | F0 E6 | BEQ -26 --> &9CC6 Generate Type mismatch error | |
9CE0 | 0 | 048 131 | 30 83 | BMI -125 --> &9C65 Convert 1st Integer to Float and compare Float values |
9CE2 | - | 165 045 | A5 2D | LDA &2D |
9CE4 | I | 073 128 | 49 80 | EOR#&80 |
9CE6 | - | 133 045 | 85 2D | STA &2D |
9CE8 | 8 | 056 | 38 | SEC |
9CE9 | h | 104 | 68 | PLA |
9CEA | * | 229 042 | E5 2A | SBC &2A |
9CEC | * | 133 042 | 85 2A | STA &2A |
9CEE | h | 104 | 68 | PLA |
9CEF | + | 229 043 | E5 2B | SBC &2B |
9CF1 | * | 004 042 | 04 2A | TSB &2A |
9CF3 | h | 104 | 68 | PLA |
9CF4 | , | 229 044 | E5 2C | SBC &2C |
9CF6 | * | 004 042 | 04 2A | TSB &2A |
9CF8 | h | 104 | 68 | PLA |
9CF9 | 160 000 | A0 00 | LDY#&00 | |
9CFB | I | 073 128 | 49 80 | EOR#&80 |
9CFD | - | 229 045 | E5 2D | SBC &2D |
9CFF | * | 005 042 | 05 2A | ORA &2A |
9D01 | ` | 096 | 60 | RTS |