Mercurial > hg > index.cgi
annotate src/number.s @ 93:a4db504611e2
Handle tokenized signs parsing E notation
author | William Astle <lost@l-w.ca> |
---|---|
date | Tue, 17 Oct 2023 17:26:45 -0600 |
parents | a8467c798450 |
children | 5fa8c479dbf7 |
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 ; |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
9 ; Most routines take a pointer to a value accumulator in X. Some take two pointers with the second in U. |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
10 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
11 ; 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
|
12 ; |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
13 ; * 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
|
14 ; * 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
|
15 ; * If one or both operands are not numeric, raise a type mismatch |
76
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
16 ; The operands are in (X) and (U) |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
17 val_matchtypes ldb val.type,x ; get the type of first argument |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
18 cmpb #valtype_int ; is it integer? |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
19 beq val_matchtypes0 ; brif so |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
20 cmpb #valtype_float ; is it floating point? |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
21 beq val_matchtypes1 ; brif so |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
22 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
|
23 jmp ERROR |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
24 val_matchtypes0 ldb val.type,u ; get type of second operand |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
25 cmpb #valtype_int ; is it integer? |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
26 bne val_matchtypes2 ; brif not |
80
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
27 val_matchtypes3 rts ; both types int - we're good so return |
76
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
28 val_matchtypes2 cmpb #valtype_float ; is it floating point? |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
29 bne TMERROR ; brif not - raise error |
80
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
30 pshs x ; save X which may be clobbered |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
31 leay ,x ; point to input operand as destination for conversion |
85
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
32 ; jsr fps_fromint32 ; convert first argument to floating point |
80
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
33 puls x,pc ; restore second operand pointer and return |
76
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
34 val_matchtypes1 ldb val.type,u ; get second argument type |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
35 cmpb #valtype_float ; is it floating point? |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
36 beq val_matchtypes3 ; brif so - we're good |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
37 cmpb #valtype_int ; is it integer? |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
38 bne TMERROR ; brif not - invalid type combination |
80
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
39 pshs x ; save X which mill be clobbered |
76
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
40 leax ,u ; convert (U) to floating point |
80
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
41 leay ,u |
85
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
42 ; jsr fps_fromint32 |
80
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
43 puls x,pc ; restore argument pointer and return |
76
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
44 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
80
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
45 ; Addition and subtraction of values; must enter with values of matching types and the result type already set |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
46 ; to the correct type. |
76
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
47 ; |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
48 ; Calculates (X) + (U) -> (Y) (addition) |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
49 ; Calculates (X) - (U) -> (Y) (subtraction) |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
50 val_add ldb val.type,x ; get type of left operand |
80
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
51 cmpb valtype_int ; is it integer? |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
52 lbeq int32_add ; brif so - do integer addition |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
53 cmpb #valtype_float ; floating point? |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
54 lbeq fps_add ; brif so - do floating point addition |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
55 jmp TMERROR ; we have a type we don't understand |
76
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
56 val_sub ldb val.type,x ; get type of left operand |
80
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
57 cmpb valtype_int ; is it integer? |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
58 lbeq int32_sub ; brif so - do integer addition |
76
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
59 cmpb #valtype_float ; floating point? |
80
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
60 lbeq fps_sub ; brif so - do floating point addition |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
61 jmp TMERROR ; we have a type we don't understand |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
62 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
63 ; Multiplication |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
64 ; |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
65 ; Calculates (X) × (U) -> (Y) |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
66 ; |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
67 ; The result might overflow the integer type. In this case, an actual overflow error will occur. |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
68 val_mul ldb val.type,x ; get type of left operand |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
69 cmpb #valtype_int ; integer? |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
70 lbeq int32_mul ; brif so - do integer multiplication |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
71 cmpb #valtype_float ; is it float? |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
72 lbeq fps_mul ; brif so - do floating point multiplication |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
73 jmp TMERROR ; have an unhandled type - bail on it |
76
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
74 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
80
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
75 ; Division |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
76 ; |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
77 ; Calculates (X) ÷ (U) -> (Y) |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
78 ; |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
79 ; The integer operation simply truncates the result ("rounds toward zero") |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
80 val_div ldb val.type,x ; get type of left operand |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
81 cmpb #valtype_int ; integer? |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
82 lbeq int32_div ; brif so - do integerdivision |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
83 cmpb #valtype_float ; floating point? |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
84 lbeq fps_div ; brif so - do floating point division |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
85 jmp TMERROR ; unsupported type |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
86 if 0 |
76
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
87 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
80
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
88 ; Modulus - note that this is a division operator returning effectively the remainder, not an absolute value as is |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
89 ; sometimes meant by "modulus". |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
90 ; |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
91 ; Calculates (X) <MOD> (U) -> (Y) |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
92 ; |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
93 ; Note: modulus will have the same sign as the quotient so that (U) * [(X) / (U)] + [(X) MOD (U)] gives (X) (integer) |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
94 ; Note2: the modulus can be calculated on floating point values in which case it will represent the fraction part |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
95 ; of the quotient multiplied by the divisor, again with the same sign as the quotient |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
96 val_mod ldb val.type,x ; get type of left operand |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
97 cmpb #valtype_int ; integer? |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
98 lbeq int32_mod ; do integer modulus |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
99 cmpb #valtype_float ; floating point? |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
100 lbeq fps_mod ; floating point modulus |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
101 jmp TMERROR ; unsupported type |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
79
diff
changeset
|
102 endc |
84
f959c92bc329
New first pass implementation of number parsing, untested
William Astle <lost@l-w.ca>
parents:
80
diff
changeset
|
103 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
85
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
104 ; 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
|
105 ; |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
106 ; 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
|
107 ; 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
|
108 ; 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
|
109 ; 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
|
110 ; 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
|
111 ; |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
112 ; 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
|
113 ; 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
|
114 ; |
85
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
115 ; 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
|
116 ; 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
|
117 ; 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
|
118 ; 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
|
119 ; 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
|
120 ; indicator being optional. |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
121 ; 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
|
122 ; 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
|
123 ; 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
|
124 ; an overflow error. |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
125 ; 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
|
126 ; 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
|
127 ; 4b. Set the exponent correctly then normalize the result to val0 |
84
f959c92bc329
New first pass implementation of number parsing, untested
William Astle <lost@l-w.ca>
parents:
80
diff
changeset
|
128 val_parsenum lbeq SNERROR ; brif no numberr to parse |
85
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
129 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
|
130 std fpa0+fpa.sig |
de42b8f77bc2
Fix problems related to parsing numbers (exponent, integers)
William Astle <lost@l-w.ca>
parents:
85
diff
changeset
|
131 std fpa0+fpa.sig+2 |
de42b8f77bc2
Fix problems related to parsing numbers (exponent, integers)
William Astle <lost@l-w.ca>
parents:
85
diff
changeset
|
132 std fpa0+fpa.sig+4 |
de42b8f77bc2
Fix problems related to parsing numbers (exponent, integers)
William Astle <lost@l-w.ca>
parents:
85
diff
changeset
|
133 std fpa0+fpa.sig+6 |
de42b8f77bc2
Fix problems related to parsing numbers (exponent, integers)
William Astle <lost@l-w.ca>
parents:
85
diff
changeset
|
134 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
|
135 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
|
136 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
|
137 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
|
138 sta fpaextra+2 ; set decimal position to 0 - unused if decimal not seen |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
139 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
|
140 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
|
141 sta fpaextra+3 |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
142 jsr curchar ; get back current input |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
143 bra val_parsenum1 |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
144 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
|
145 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
|
146 cmpa #'. ; does it start with a decimal? |
3bfd978ddb39
Make corrections in floating point parsing.
William Astle <lost@l-w.ca>
parents:
86
diff
changeset
|
147 beq val_parsenum5 ; brif so |
85
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
148 cmpa #'+ ; unary plus? |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
149 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
|
150 cmpa #'- ; negative? |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
151 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
|
152 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
|
153 bra val_parsenum0 ; eat the sign and see if there's more signs |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
154 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
|
155 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
|
156 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
|
157 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
|
158 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
|
159 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
|
160 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
|
161 tstb ; no digits? |
87
3bfd978ddb39
Make corrections in floating point parsing.
William Astle <lost@l-w.ca>
parents:
86
diff
changeset
|
162 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
|
163 ldb fpaextra+1 ; decimal seen? |
3bfd978ddb39
Make corrections in floating point parsing.
William Astle <lost@l-w.ca>
parents:
86
diff
changeset
|
164 bne val_parsenum2 ; brif not - skip leading zeroes |
85
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
165 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
|
166 mul |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
167 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
|
168 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
|
169 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
|
170 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
|
171 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
|
172 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
|
173 val_parsenum4 inc fpaextra ; bump digit count |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
174 lbmi OVERROR ; brif it overflowed - we can't parse more than 127 digits! |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
175 ldb fpaextra+2 ; get decimal position counter |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
176 subb fpaextra+1 ; subtract decimal flag (will be 0xff or -1 if decimal seen) |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
177 stb fpaextra+2 |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
178 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
|
179 val_parsenum5 cmpa #'. ; decimal? |
86
de42b8f77bc2
Fix problems related to parsing numbers (exponent, integers)
William Astle <lost@l-w.ca>
parents:
85
diff
changeset
|
180 bne val_parsenum6 ; brif not |
87
3bfd978ddb39
Make corrections in floating point parsing.
William Astle <lost@l-w.ca>
parents:
86
diff
changeset
|
181 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
|
182 lbeq SNERROR ; brif already seen a decimal point - syntax error |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
183 bra val_parsenum2 ; go parse more digits |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
184 val_parsenum6 cmpa #'E ; decimal exponent? |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
185 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
|
186 cmpa #'e ; lower case exponent indicator? |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
187 bne val_parsenum11 ; brif not - we have the end of the number here |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
188 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
|
189 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
|
190 cmpa #'+ ; positive? |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
191 beq val_parsenum8 ; brif no |
93
a4db504611e2
Handle tokenized signs parsing E notation
William Astle <lost@l-w.ca>
parents:
88
diff
changeset
|
192 cmpa #tok_plus ; tokenized plus? |
a4db504611e2
Handle tokenized signs parsing E notation
William Astle <lost@l-w.ca>
parents:
88
diff
changeset
|
193 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
|
194 cmpa #'- ; negative? |
93
a4db504611e2
Handle tokenized signs parsing E notation
William Astle <lost@l-w.ca>
parents:
88
diff
changeset
|
195 beq val_parsenum7a ; brif so |
a4db504611e2
Handle tokenized signs parsing E notation
William Astle <lost@l-w.ca>
parents:
88
diff
changeset
|
196 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
|
197 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
|
198 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
|
199 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
|
200 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
|
201 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
|
202 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
|
203 ldb fpaextra+4 ; get calculated exponent |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
204 lda #10 ; multiply by 10 |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
205 mul |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
206 lbcs OVERROR ; brif decimal exponent overlows ±127 - we just don't handle that |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
207 addb fpaextra+6 ; add digit in |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
208 lbmi OVERROR ; same as above - make sure exponent in range |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
209 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
|
210 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
|
211 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
|
212 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
|
213 neg fpaextra+4 ; negate resulting exponent |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
214 val_parsenum11 ldb fpaextra ; get number of digits provided |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
215 subb fpaextra+2 ; subtract out count of fractional digits giving whole number digits |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
216 addb fpaextra+4 ; add in decimal exponent adjustment |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
217 stb fpa0+fpa.exp ; set result exponent |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
218 ; 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
|
219 ; 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
|
220 ; to an aribtrary number of leading zeroes. |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
221 cmpb fpaextra ; is the exponent less than the number of digits? |
87
3bfd978ddb39
Make corrections in floating point parsing.
William Astle <lost@l-w.ca>
parents:
86
diff
changeset
|
222 blt val_parsenum13 ; brif so - return floating point (signed comparison!) |
85
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
223 cmpb #10 ; is exponent in the range for a binary integer? |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
224 bgt val_parsenum13 ; brif not - return floating point |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
225 ; 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
|
226 ; already normalized everything above and it handles exponents properly |
86
de42b8f77bc2
Fix problems related to parsing numbers (exponent, integers)
William Astle <lost@l-w.ca>
parents:
85
diff
changeset
|
227 lda fpa0+fpa.exp ; compare exponents (unbiased), exponent adjusted for above code |
de42b8f77bc2
Fix problems related to parsing numbers (exponent, integers)
William Astle <lost@l-w.ca>
parents:
85
diff
changeset
|
228 cmpa #10 |
85
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
229 bne val_parsenum12 |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
230 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
|
231 cmpx #0x2147 |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
232 bne val_parsenum12 |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
233 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
|
234 cmpx #0x4836 |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
235 bne val_parsenum12 |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
236 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
|
237 cmpx #0x4800 |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
238 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
|
239 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
|
240 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
|
241 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
|
242 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
|
243 sta val0+val.type |
86
de42b8f77bc2
Fix problems related to parsing numbers (exponent, integers)
William Astle <lost@l-w.ca>
parents:
85
diff
changeset
|
244 lda fpa0+fpa.exp ; put the bias into the exponent but subtract one for leading digit |
88
a8467c798450
Correct off by one in FP exponent handling in ascii parsing
William Astle <lost@l-w.ca>
parents:
87
diff
changeset
|
245 adda #63 |
85
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
246 sta fpa0+fpa.exp |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
247 ldy #val0+val.value ; normalize/round and return the result |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
248 jmp fps_normalize |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
249 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
|
250 sta val0+val.type |
86
de42b8f77bc2
Fix problems related to parsing numbers (exponent, integers)
William Astle <lost@l-w.ca>
parents:
85
diff
changeset
|
251 ldb #10 ; exponent needed for decimal point to the right of significand |
85
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
252 subb fpa0+fpa.exp ; number of digit shifts needed to denormalize |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
253 beq val_parsenum16 ; brif already denormalized |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
254 lslb ; do 4 shifts per digit |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
255 lslb |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
256 val_parsenum15 lsr fpa0+fpa.sig ; shift a digit right |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
257 ror fpa0+fpa.sig+1 |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
258 ror fpa0+fpa.sig+2 |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
259 ror fpa0+fpa.sig+3 |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
260 ror fpa0+fpa.sig+4 |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
261 decb ; done all shifts? |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
262 bne val_parsenum15 |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
263 ; Now convert BCD digit sequence in fpa0 significand to binary value in val0 |
86
de42b8f77bc2
Fix problems related to parsing numbers (exponent, integers)
William Astle <lost@l-w.ca>
parents:
85
diff
changeset
|
264 val_parsenum16 ldb #32 ; 40 bit shifts needed for whole significand |
85
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
265 stb fpa0+fpa.extra ; use extra precision byte as counter |
86
de42b8f77bc2
Fix problems related to parsing numbers (exponent, integers)
William Astle <lost@l-w.ca>
parents:
85
diff
changeset
|
266 val_parsenum17 lsr fpa0+fpa.sig ; shift a bit into the binary result |
de42b8f77bc2
Fix problems related to parsing numbers (exponent, integers)
William Astle <lost@l-w.ca>
parents:
85
diff
changeset
|
267 ror fpa0+fpa.sig+1 |
de42b8f77bc2
Fix problems related to parsing numbers (exponent, integers)
William Astle <lost@l-w.ca>
parents:
85
diff
changeset
|
268 ror fpa0+fpa.sig+2 |
de42b8f77bc2
Fix problems related to parsing numbers (exponent, integers)
William Astle <lost@l-w.ca>
parents:
85
diff
changeset
|
269 ror fpa0+fpa.sig+3 |
de42b8f77bc2
Fix problems related to parsing numbers (exponent, integers)
William Astle <lost@l-w.ca>
parents:
85
diff
changeset
|
270 ror fpa0+fpa.sig+4 |
de42b8f77bc2
Fix problems related to parsing numbers (exponent, integers)
William Astle <lost@l-w.ca>
parents:
85
diff
changeset
|
271 ror val0+val.int |
de42b8f77bc2
Fix problems related to parsing numbers (exponent, integers)
William Astle <lost@l-w.ca>
parents:
85
diff
changeset
|
272 ror val0+val.int+1 |
de42b8f77bc2
Fix problems related to parsing numbers (exponent, integers)
William Astle <lost@l-w.ca>
parents:
85
diff
changeset
|
273 ror val0+val.int+2 |
de42b8f77bc2
Fix problems related to parsing numbers (exponent, integers)
William Astle <lost@l-w.ca>
parents:
85
diff
changeset
|
274 ror val0+val.int+3 |
85
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
275 ldx #fpa0+fpa.sig ; point to BCD digits |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
276 val_parsenum18 lda ,x ; get byte to check |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
277 beq val_parsenum20 ; short circuit check if digits are 0 |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
278 anda #0x88 ; keep bit 3 of each digit; adjustment on >= 8 |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
279 lsra ; shift over and mulply by adjustment factor |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
280 lsra |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
281 lsra |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
282 ldb #3 ; the adjustment is a subtraction by 3 |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
283 mul |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
284 negb ; now subtract from digit |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
285 addb ,x |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
286 stb ,x+ |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
287 val_parsenum18a cmpx #fpa0+fpa.sig+5 ; done all 5 bytes? |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
288 blo val_parsenum18 ; brif not |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
289 dec fpa0+fpa.extra ; done all bits? |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
290 bne val_parsenum17 ; brif not |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
291 ldb fpa0+fpa.sign ; do we want negative? |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
292 bpl val_parsenum19 ; brif not |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
293 ldd zero ; negate the value through subtracting from 0 |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
294 subd val0+val.int+2 |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
295 std val0+val.int+2 |
84
f959c92bc329
New first pass implementation of number parsing, untested
William Astle <lost@l-w.ca>
parents:
80
diff
changeset
|
296 ldd zero |
85
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
297 sbcb val0+val.int+1 |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
298 sbca val0+val.int |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
299 std val0+val.int |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
300 val_parsenum19 rts |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
301 val_parsenum20 leax 1,x ; move to next digit |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
84
diff
changeset
|
302 bra val_parsenum18a ; go back to mainline |
76
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
303 *pragmapop list |