Mercurial > hg > index.cgi
annotate src/number.s @ 103:2f97bfecffab
Reorganize the operand matching routine
author | William Astle <lost@l-w.ca> |
---|---|
date | Mon, 30 Oct 2023 22:20:06 -0600 |
parents | b0422868a7b1 |
children | 9d57279c900e |
rev | line source |
---|---|
76
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
1 *pragmapush list |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
2 *pragma list |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
4 ; Arithmetic package |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
5 ; |
80
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
6 ; This section contains routines that handle floating point and integer arithmetic. It mostly delegates to int.s and |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
7 ; fps.s. |
76
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
8 ; |
101
b0422868a7b1
Clean up numeric operator dispatch.
William Astle <lost@l-w.ca>
parents:
100
diff
changeset
|
9 ; Most of these routines take a single parameter in val0 or two parameters in val0 and val1. They will typically return |
b0422868a7b1
Clean up numeric operator dispatch.
William Astle <lost@l-w.ca>
parents:
100
diff
changeset
|
10 ; their results in val0. |
b0422868a7b1
Clean up numeric operator dispatch.
William Astle <lost@l-w.ca>
parents:
100
diff
changeset
|
11 ; |
b0422868a7b1
Clean up numeric operator dispatch.
William Astle <lost@l-w.ca>
parents:
100
diff
changeset
|
12 ; For binary operations, the left operand will be in val1 and the right operand will be in val0. |
76
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
13 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
14 ; Match operands for a numeric calculation. This works as follows: |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
15 ; |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
16 ; * If both operands are the same, ensure the type is numeric and return |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
17 ; * If one operand is floating point, convert the other to floating point, as long as it is numeric |
80
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
18 ; * If one or both operands are not numeric, raise a type mismatch |
101
b0422868a7b1
Clean up numeric operator dispatch.
William Astle <lost@l-w.ca>
parents:
100
diff
changeset
|
19 ; The operands are in val0 and val1 |
b0422868a7b1
Clean up numeric operator dispatch.
William Astle <lost@l-w.ca>
parents:
100
diff
changeset
|
20 val_matchtypes ldb val0+val.type ; get the type of first argument |
103
2f97bfecffab
Reorganize the operand matching routine
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
21 cmpb val1+val.type ; do types match? |
2f97bfecffab
Reorganize the operand matching routine
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
22 bne val_matchtypes1 ; brif not |
2f97bfecffab
Reorganize the operand matching routine
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
23 cmpb #valtype_int ; integer? |
2f97bfecffab
Reorganize the operand matching routine
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
24 beq val_matchtypes0 ; brif so - it's good |
2f97bfecffab
Reorganize the operand matching routine
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
25 cmpb #valtype_float ; floating point? |
2f97bfecffab
Reorganize the operand matching routine
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
26 bne TMERROR ; brif not |
2f97bfecffab
Reorganize the operand matching routine
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
27 val_matchtypes0 rts ; types match and are good |
76
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
28 TMERROR ldb #err_tm ; raise a type mismatch |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
29 jmp ERROR |
103
2f97bfecffab
Reorganize the operand matching routine
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
30 val_matchtypes1 cmpb #valtype_float ; is first argument float? |
76
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
31 bne val_matchtypes2 ; brif not |
103
2f97bfecffab
Reorganize the operand matching routine
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
32 ldb val1+val.type ; get second type |
2f97bfecffab
Reorganize the operand matching routine
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
33 cmpb #valtype_int ; is it integer? |
2f97bfecffab
Reorganize the operand matching routine
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
34 bne TMERROR ; brif not - don't know how to convert |
2f97bfecffab
Reorganize the operand matching routine
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
35 ldx #val1 ; go convert val1 to floating point |
101
b0422868a7b1
Clean up numeric operator dispatch.
William Astle <lost@l-w.ca>
parents:
100
diff
changeset
|
36 jmp fps_fromint |
103
2f97bfecffab
Reorganize the operand matching routine
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
37 val_matchtypes2 cmpb #valtype_int ; are we an integer? |
2f97bfecffab
Reorganize the operand matching routine
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
38 bne TMERROR ; brif not - we don't know how to convert |
2f97bfecffab
Reorganize the operand matching routine
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
39 ldb val1+val.type ; get second type |
76
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
40 cmpb #valtype_float ; is it floating point? |
103
2f97bfecffab
Reorganize the operand matching routine
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
41 bne TMERROR ; brif not - we don't know how to convert |
2f97bfecffab
Reorganize the operand matching routine
William Astle <lost@l-w.ca>
parents:
101
diff
changeset
|
42 ldx #val0 ; convert val0 to floating point |
101
b0422868a7b1
Clean up numeric operator dispatch.
William Astle <lost@l-w.ca>
parents:
100
diff
changeset
|
43 jmp fps_fromint |
84
f959c92bc329
New first pass implementation of number parsing, untested
William Astle <lost@l-w.ca>
parents:
80
diff
changeset
|
44 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
85
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
45 ; Parse a number to either an integer or a floating point value and return the result in val0 |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
46 ; |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
47 ; This works by first detecting any sign indicators and handling those. Multiple prefix signs are supported. Note that |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
48 ; in the regular expression evaluation sequence, unary minus and plus will be handled by the expression evaluator so |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
49 ; in that case, the number evaluator would not need to care about those. However, in the case of an arbitrary string |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
50 ; fed into the evaluator, those must be handled. Note that there is no need to handle tokenized sign indicators because |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
51 ; the only place where they would be tokenized is in a proper expression. |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
52 ; |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
53 ; Once leading signs are handled, any base specifiers or other modifiers are handled. If none of those intercept the |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
54 ; parsing, the regular number parsing continues as follows. |
84
f959c92bc329
New first pass implementation of number parsing, untested
William Astle <lost@l-w.ca>
parents:
80
diff
changeset
|
55 ; |
85
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
56 ; 1. Read a sequence of digits. The digits are stored in backed BCD form in the significand of fpa0. An arbitrary number |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
57 ; of leading zeroes will be skipped. A count of significant digits is maintained while reading digits as is the |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
58 ; position of a decimal point if one is encountered. Once one digit more than the maximum possible precision of any |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
59 ; supported number type is read, subsequent digits will not be stored, but the counters will still be updated. |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
60 ; 2. Any subsequent "E" or "e" followed by either a positive or negative decimal exponent is read, with the sign |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
61 ; indicator being optional. |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
62 ; 3. The decimal offset calculated in (1) is adjusted by the exponent read in (2) if any. |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
63 ; 4. Range checks are completed as follows: |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
64 ; 4a. If the calculated decimal exponent is beyond the supported range of any floating point or integer type, raise |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
65 ; an overflow error. |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
66 ; 4b. If the number is an integer in the range of -0x80000000 to 0x7fffffff, it is converted to a signed binary integer |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
67 ; and the result is returned |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
68 ; 4b. Set the exponent correctly then normalize the result to val0 |
94
5fa8c479dbf7
Make E notation parse correctly, and also leading decimals, and other details
William Astle <lost@l-w.ca>
parents:
93
diff
changeset
|
69 val_parsenum ldd zero ; zero out digit accumulator |
86
de42b8f77bc2
Fix problems related to parsing numbers (exponent, integers)
William Astle <lost@l-w.ca>
parents:
85
diff
changeset
|
70 std fpa0+fpa.sig |
de42b8f77bc2
Fix problems related to parsing numbers (exponent, integers)
William Astle <lost@l-w.ca>
parents:
85
diff
changeset
|
71 std fpa0+fpa.sig+2 |
de42b8f77bc2
Fix problems related to parsing numbers (exponent, integers)
William Astle <lost@l-w.ca>
parents:
85
diff
changeset
|
72 std fpa0+fpa.sig+4 |
de42b8f77bc2
Fix problems related to parsing numbers (exponent, integers)
William Astle <lost@l-w.ca>
parents:
85
diff
changeset
|
73 std fpa0+fpa.sig+6 |
de42b8f77bc2
Fix problems related to parsing numbers (exponent, integers)
William Astle <lost@l-w.ca>
parents:
85
diff
changeset
|
74 std fpa0+fpa.sig+8 |
85
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
75 sta fpa0+fpa.sign ; set number sign to positive |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
76 std fpaextra+4 ; clear out decimal exponent and sign |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
77 std fpaextra ; set digit count and decimal flag to zero and no decimal |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
78 sta fpaextra+2 ; set decimal position to 0 - unused if decimal not seen |
94
5fa8c479dbf7
Make E notation parse correctly, and also leading decimals, and other details
William Astle <lost@l-w.ca>
parents:
93
diff
changeset
|
79 sta fpaextra+6 ; set number of leading zeroes seen |
85
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
80 ldx #fpa0+fpa.sig ; point to digit storage location |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
81 lda #0xf0 ; set digit mask |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
82 sta fpaextra+3 |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
83 jsr curchar ; get back current input |
94
5fa8c479dbf7
Make E notation parse correctly, and also leading decimals, and other details
William Astle <lost@l-w.ca>
parents:
93
diff
changeset
|
84 bne val_parsenum1 ; brif we have input |
5fa8c479dbf7
Make E notation parse correctly, and also leading decimals, and other details
William Astle <lost@l-w.ca>
parents:
93
diff
changeset
|
85 jmp SNERROR ; raise syntax error |
85
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
86 val_parsenum0 jsr nextchar ; fetch next input |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
87 val_parsenum1 bcs val_parsenum3 ; brif digit - short ciruit other checks |
87
3bfd978ddb39
Make corrections in floating point parsing.
William Astle <lost@l-w.ca>
parents:
86
diff
changeset
|
88 cmpa #'. ; does it start with a decimal? |
94
5fa8c479dbf7
Make E notation parse correctly, and also leading decimals, and other details
William Astle <lost@l-w.ca>
parents:
93
diff
changeset
|
89 beq val_parsenum5a ; brif so |
85
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
90 cmpa #'+ ; unary plus? |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
91 beq val_parsenum0 ; brif so - it's a no-op but supported for symmetry with unary minus |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
92 cmpa #'- ; negative? |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
93 bne val_parsenum5 ; brif not |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
94 com fpa0+fpa.sign ; invert the sign |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
95 bra val_parsenum0 ; eat the sign and see if there's more signs |
94
5fa8c479dbf7
Make E notation parse correctly, and also leading decimals, and other details
William Astle <lost@l-w.ca>
parents:
93
diff
changeset
|
96 val_parsenum1a inc fpaextra+6 ; bump zero counter |
85
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
97 val_parsenum2 jsr nextchar ; fetch next character in number |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
98 bcc val_parsenum5 ; brif not a digit |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
99 val_parsenum3 ldb fpaextra ; is it within the digit count? |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
100 cmpb #11 ; (11 digits holds both 10 digit fp and 32 bit integer) |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
101 bhs val_parsenum4 ; brif so - don't convert it |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
102 suba #0x30 ; binary-ize the digit |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
103 bne val_parsenum3a ; brif not zero |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
104 tstb ; no digits? |
87
3bfd978ddb39
Make corrections in floating point parsing.
William Astle <lost@l-w.ca>
parents:
86
diff
changeset
|
105 bne val_parsenum3a ; brif not - we've seen something significant |
3bfd978ddb39
Make corrections in floating point parsing.
William Astle <lost@l-w.ca>
parents:
86
diff
changeset
|
106 ldb fpaextra+1 ; decimal seen? |
94
5fa8c479dbf7
Make E notation parse correctly, and also leading decimals, and other details
William Astle <lost@l-w.ca>
parents:
93
diff
changeset
|
107 bne val_parsenum1a ; brif so - count the leading zeros |
5fa8c479dbf7
Make E notation parse correctly, and also leading decimals, and other details
William Astle <lost@l-w.ca>
parents:
93
diff
changeset
|
108 bra val_parsenum2 ; otherwise don't count it and skip it |
85
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
109 val_parsenum3a ldb #0x11 ; put in both digit spots |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
110 mul |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
111 andb fpaextra+3 ; only keep the one we need |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
112 orb ,x ; merge with existing digit |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
113 stb ,x ; put in digit location |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
114 com fpaextra+3 ; flip digit position mask |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
115 bpl val_parsenum4 ; brif not moving to new location |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
116 leax 1,x ; move to new digit storage location |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
117 val_parsenum4 inc fpaextra ; bump digit count |
94
5fa8c479dbf7
Make E notation parse correctly, and also leading decimals, and other details
William Astle <lost@l-w.ca>
parents:
93
diff
changeset
|
118 bmi val_overror ; brif it overflowed - we can't parse more than 127 digits! |
85
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
119 bra val_parsenum2 ; go handle another digit or whatever |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
120 val_parsenum5 cmpa #'. ; decimal? |
86
de42b8f77bc2
Fix problems related to parsing numbers (exponent, integers)
William Astle <lost@l-w.ca>
parents:
85
diff
changeset
|
121 bne val_parsenum6 ; brif not |
94
5fa8c479dbf7
Make E notation parse correctly, and also leading decimals, and other details
William Astle <lost@l-w.ca>
parents:
93
diff
changeset
|
122 val_parsenum5a ldb fpaextra ;* set decimal offset (digits to the left of decimal), account for |
5fa8c479dbf7
Make E notation parse correctly, and also leading decimals, and other details
William Astle <lost@l-w.ca>
parents:
93
diff
changeset
|
123 stb fpaextra+2 |
87
3bfd978ddb39
Make corrections in floating point parsing.
William Astle <lost@l-w.ca>
parents:
86
diff
changeset
|
124 com fpaextra+1 ; flag decimal seen |
85
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
125 lbeq SNERROR ; brif already seen a decimal point - syntax error |
94
5fa8c479dbf7
Make E notation parse correctly, and also leading decimals, and other details
William Astle <lost@l-w.ca>
parents:
93
diff
changeset
|
126 bra val_parsenum2 ; process more digits |
5fa8c479dbf7
Make E notation parse correctly, and also leading decimals, and other details
William Astle <lost@l-w.ca>
parents:
93
diff
changeset
|
127 val_parsenum6 ldb fpaextra ; get number of digits provided; will be exponent if no decimal |
5fa8c479dbf7
Make E notation parse correctly, and also leading decimals, and other details
William Astle <lost@l-w.ca>
parents:
93
diff
changeset
|
128 tst fpaextra+1 ; decimal seen? |
5fa8c479dbf7
Make E notation parse correctly, and also leading decimals, and other details
William Astle <lost@l-w.ca>
parents:
93
diff
changeset
|
129 beq val_parsenum6a ; brif not |
5fa8c479dbf7
Make E notation parse correctly, and also leading decimals, and other details
William Astle <lost@l-w.ca>
parents:
93
diff
changeset
|
130 ldb fpaextra+2 ; get decimal offset - this is the exponent |
5fa8c479dbf7
Make E notation parse correctly, and also leading decimals, and other details
William Astle <lost@l-w.ca>
parents:
93
diff
changeset
|
131 val_parsenum6a decb ; adjust for the decimal position in the significand |
5fa8c479dbf7
Make E notation parse correctly, and also leading decimals, and other details
William Astle <lost@l-w.ca>
parents:
93
diff
changeset
|
132 subb fpaextra+6 ; account for leading zeroes after the decimal point |
5fa8c479dbf7
Make E notation parse correctly, and also leading decimals, and other details
William Astle <lost@l-w.ca>
parents:
93
diff
changeset
|
133 bvs val_overror ; brif it overflowed |
5fa8c479dbf7
Make E notation parse correctly, and also leading decimals, and other details
William Astle <lost@l-w.ca>
parents:
93
diff
changeset
|
134 stb fpa0+fpa.exp ; save base exponent of number |
5fa8c479dbf7
Make E notation parse correctly, and also leading decimals, and other details
William Astle <lost@l-w.ca>
parents:
93
diff
changeset
|
135 cmpa #'E ; decimal exponent? |
85
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
136 beq val_parsenum7 ; brif so |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
137 cmpa #'e ; lower case exponent indicator? |
94
5fa8c479dbf7
Make E notation parse correctly, and also leading decimals, and other details
William Astle <lost@l-w.ca>
parents:
93
diff
changeset
|
138 bne val_parsenum11b ; brif not - we have the end of the number here |
85
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
139 val_parsenum7 jsr nextchar ; eat exponent indicator |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
140 bcs val_parsenum9 ; brif digit |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
141 cmpa #'+ ; positive? |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
142 beq val_parsenum8 ; brif no |
93
a4db504611e2
Handle tokenized signs parsing E notation
William Astle <lost@l-w.ca>
parents:
88
diff
changeset
|
143 cmpa #tok_plus ; tokenized plus? |
a4db504611e2
Handle tokenized signs parsing E notation
William Astle <lost@l-w.ca>
parents:
88
diff
changeset
|
144 beq val_parsenum8 ; brif so |
85
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
145 cmpa #'- ; negative? |
93
a4db504611e2
Handle tokenized signs parsing E notation
William Astle <lost@l-w.ca>
parents:
88
diff
changeset
|
146 beq val_parsenum7a ; brif so |
a4db504611e2
Handle tokenized signs parsing E notation
William Astle <lost@l-w.ca>
parents:
88
diff
changeset
|
147 cmpa #tok_minus ; tokenized minus? |
85
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
148 lbne SNERROR ; brif not positive, negative, or digit |
93
a4db504611e2
Handle tokenized signs parsing E notation
William Astle <lost@l-w.ca>
parents:
88
diff
changeset
|
149 val_parsenum7a com fpaextra+5 ; make sign of exponent negative |
85
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
150 val_parsenum8 jsr nextchar ; eat exponent sign/get next digit |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
151 bcc val_parsenum10 ; brif not a digit - done with number |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
152 val_parsenum9 suba #0x30 ; binary-ize the digit |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
153 sta fpaextra+6 ; save digit value |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
154 ldb fpaextra+4 ; get calculated exponent |
94
5fa8c479dbf7
Make E notation parse correctly, and also leading decimals, and other details
William Astle <lost@l-w.ca>
parents:
93
diff
changeset
|
155 lda #10 ; multiply by 10, MUL sets C equal to bit 7 of B |
85
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
156 mul |
94
5fa8c479dbf7
Make E notation parse correctly, and also leading decimals, and other details
William Astle <lost@l-w.ca>
parents:
93
diff
changeset
|
157 bcc val_parsenum9a ; don't brif ±127 - we just don't handle that |
5fa8c479dbf7
Make E notation parse correctly, and also leading decimals, and other details
William Astle <lost@l-w.ca>
parents:
93
diff
changeset
|
158 val_overror jmp OVERROR ; raise overflow |
5fa8c479dbf7
Make E notation parse correctly, and also leading decimals, and other details
William Astle <lost@l-w.ca>
parents:
93
diff
changeset
|
159 val_parsenum9a addb fpaextra+6 ; add digit in |
5fa8c479dbf7
Make E notation parse correctly, and also leading decimals, and other details
William Astle <lost@l-w.ca>
parents:
93
diff
changeset
|
160 bvs val_overror ; brif we went above 63 |
85
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
161 stb fpaextra+4 ; save new decimal exponent |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
162 bra val_parsenum8 ; handle another digit |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
163 val_parsenum10 lda fpaextra+5 ; get sign of exponent |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
164 bpl val_parsenum11 ; brif positive |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
165 neg fpaextra+4 ; negate resulting exponent |
94
5fa8c479dbf7
Make E notation parse correctly, and also leading decimals, and other details
William Astle <lost@l-w.ca>
parents:
93
diff
changeset
|
166 val_parsenum11 ldb fpa0+fpa.exp ; get significand exponent |
85
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
167 addb fpaextra+4 ; add in decimal exponent adjustment |
94
5fa8c479dbf7
Make E notation parse correctly, and also leading decimals, and other details
William Astle <lost@l-w.ca>
parents:
93
diff
changeset
|
168 bvs val_overror ; brif it overflowed |
5fa8c479dbf7
Make E notation parse correctly, and also leading decimals, and other details
William Astle <lost@l-w.ca>
parents:
93
diff
changeset
|
169 stb fpa0+fpa.exp |
5fa8c479dbf7
Make E notation parse correctly, and also leading decimals, and other details
William Astle <lost@l-w.ca>
parents:
93
diff
changeset
|
170 val_parsenum11b cmpb #63 ; too high? |
5fa8c479dbf7
Make E notation parse correctly, and also leading decimals, and other details
William Astle <lost@l-w.ca>
parents:
93
diff
changeset
|
171 bgt val_overror ; brif too high |
5fa8c479dbf7
Make E notation parse correctly, and also leading decimals, and other details
William Astle <lost@l-w.ca>
parents:
93
diff
changeset
|
172 cmpb #-64 ; too low? |
5fa8c479dbf7
Make E notation parse correctly, and also leading decimals, and other details
William Astle <lost@l-w.ca>
parents:
93
diff
changeset
|
173 bge val_parsenum11a ; brif so - minimize to "0" |
5fa8c479dbf7
Make E notation parse correctly, and also leading decimals, and other details
William Astle <lost@l-w.ca>
parents:
93
diff
changeset
|
174 ldb #valtype_int ; set result to integer |
5fa8c479dbf7
Make E notation parse correctly, and also leading decimals, and other details
William Astle <lost@l-w.ca>
parents:
93
diff
changeset
|
175 stb val0+val.type |
5fa8c479dbf7
Make E notation parse correctly, and also leading decimals, and other details
William Astle <lost@l-w.ca>
parents:
93
diff
changeset
|
176 ldd zero ; set result to zero |
5fa8c479dbf7
Make E notation parse correctly, and also leading decimals, and other details
William Astle <lost@l-w.ca>
parents:
93
diff
changeset
|
177 std val0+val.int |
5fa8c479dbf7
Make E notation parse correctly, and also leading decimals, and other details
William Astle <lost@l-w.ca>
parents:
93
diff
changeset
|
178 std val0+val.int+2 |
5fa8c479dbf7
Make E notation parse correctly, and also leading decimals, and other details
William Astle <lost@l-w.ca>
parents:
93
diff
changeset
|
179 rts |
85
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
180 ; Normalization is not required here though rounding might be. Rounding will be handled during floating point return. |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
181 ; By ensuring there were no leading zeroes converted, the result is already pre-normalized without losing precision due |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
182 ; to an aribtrary number of leading zeroes. |
95
25b44f1ac2aa
Fix detection of integer value on ascii conversion
William Astle <lost@l-w.ca>
parents:
94
diff
changeset
|
183 val_parsenum11a cmpb #9 ; is the exponent greater than possible for a 32 bit integer? |
25b44f1ac2aa
Fix detection of integer value on ascii conversion
William Astle <lost@l-w.ca>
parents:
94
diff
changeset
|
184 bgt val_parsenum13 |
25b44f1ac2aa
Fix detection of integer value on ascii conversion
William Astle <lost@l-w.ca>
parents:
94
diff
changeset
|
185 lda fpaextra ; fetch the number of digits |
25b44f1ac2aa
Fix detection of integer value on ascii conversion
William Astle <lost@l-w.ca>
parents:
94
diff
changeset
|
186 deca ; account for the decimal point offset |
25b44f1ac2aa
Fix detection of integer value on ascii conversion
William Astle <lost@l-w.ca>
parents:
94
diff
changeset
|
187 cmpa fpa0+fpa.exp ; do we have more digits than the exponent (fractional)? |
25b44f1ac2aa
Fix detection of integer value on ascii conversion
William Astle <lost@l-w.ca>
parents:
94
diff
changeset
|
188 bgt val_parsenum13 ; brif we have more digits than exponent |
85
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
189 ; Compare with 2147483648, the maximum *negative* value; note that this is a floating point comparison because we |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
190 ; already normalized everything above and it handles exponents properly |
95
25b44f1ac2aa
Fix detection of integer value on ascii conversion
William Astle <lost@l-w.ca>
parents:
94
diff
changeset
|
191 lda fpa0+fpa.exp ; compare exponents (unbiased) |
25b44f1ac2aa
Fix detection of integer value on ascii conversion
William Astle <lost@l-w.ca>
parents:
94
diff
changeset
|
192 cmpa #9 |
85
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
193 bne val_parsenum12 |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
194 ldx fpa0+fpa.sig ; compare top of significand |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
195 cmpx #0x2147 |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
196 bne val_parsenum12 |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
197 ldx fpa0+fpa.sig+2 ; compare middle of significand |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
198 cmpx #0x4836 |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
199 bne val_parsenum12 |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
200 ldx fpa0+fpa.sig+4 ; compare bottom of significand plus extra digits |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
201 cmpx #0x4800 |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
202 val_parsenum12 bgt val_parsenum13 ; brif too big for integer |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
203 blt val_parsenum14 ; brif it fits in a positive integer |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
204 ldb fpa0+fpa.sign ; negative? |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
205 bpl val_parsenum14 ; brif not - doesn't fit in integer |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
206 val_parsenum13 lda #valtype_float ; set return value to floating point |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
207 sta val0+val.type |
94
5fa8c479dbf7
Make E notation parse correctly, and also leading decimals, and other details
William Astle <lost@l-w.ca>
parents:
93
diff
changeset
|
208 lda fpa0+fpa.exp ; put the bias into the exponent |
5fa8c479dbf7
Make E notation parse correctly, and also leading decimals, and other details
William Astle <lost@l-w.ca>
parents:
93
diff
changeset
|
209 adda #64 |
85
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
210 sta fpa0+fpa.exp |
98
6837d10b67fb
Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents:
95
diff
changeset
|
211 jsr fps_normalizea0 ; normalize fpa0 |
100
6db72a92ff7a
Make value accumulator descriptions consistent and make usage consistent
William Astle <lost@l-w.ca>
parents:
98
diff
changeset
|
212 ldx #val0 ; pack the result to the right place and return |
6db72a92ff7a
Make value accumulator descriptions consistent and make usage consistent
William Astle <lost@l-w.ca>
parents:
98
diff
changeset
|
213 jmp fps_pack0 |
85
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
214 val_parsenum14 lda #valtype_int ; set value type to integer |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
215 sta val0+val.type |
98
6837d10b67fb
Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents:
95
diff
changeset
|
216 ldb fpa0+fpa.exp ; add the exponent bias in |
6837d10b67fb
Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents:
95
diff
changeset
|
217 addb #64 |
6837d10b67fb
Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents:
95
diff
changeset
|
218 stb fpa0+fpa.exp |
6837d10b67fb
Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents:
95
diff
changeset
|
219 jsr fps_toint1 ; go convert to an integer |
6837d10b67fb
Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents:
95
diff
changeset
|
220 ldd fpa0+fpa.sig+1 ; copy result to val0 |
6837d10b67fb
Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents:
95
diff
changeset
|
221 std val0+val.int |
6837d10b67fb
Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents:
95
diff
changeset
|
222 ldd fpa0+fpa.sig+3 |
85
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
223 std val0+val.int+2 |
98
6837d10b67fb
Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents:
95
diff
changeset
|
224 rts |
76
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
225 *pragmapop list |