annotate src/number.s @ 94:5fa8c479dbf7

Make E notation parse correctly, and also leading decimals, and other details
author William Astle <lost@l-w.ca>
date Sun, 22 Oct 2023 17:25:16 -0600
parents a4db504611e2
children 25b44f1ac2aa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
94
5fa8c479dbf7 Make E notation parse correctly, and also leading decimals, and other details
William Astle <lost@l-w.ca>
parents: 93
diff changeset
128 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
129 std fpa0+fpa.sig
de42b8f77bc2 Fix problems related to parsing numbers (exponent, integers)
William Astle <lost@l-w.ca>
parents: 85
diff changeset
130 std fpa0+fpa.sig+2
de42b8f77bc2 Fix problems related to parsing numbers (exponent, integers)
William Astle <lost@l-w.ca>
parents: 85
diff changeset
131 std fpa0+fpa.sig+4
de42b8f77bc2 Fix problems related to parsing numbers (exponent, integers)
William Astle <lost@l-w.ca>
parents: 85
diff changeset
132 std fpa0+fpa.sig+6
de42b8f77bc2 Fix problems related to parsing numbers (exponent, integers)
William Astle <lost@l-w.ca>
parents: 85
diff changeset
133 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
134 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
135 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
136 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
137 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
138 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
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
94
5fa8c479dbf7 Make E notation parse correctly, and also leading decimals, and other details
William Astle <lost@l-w.ca>
parents: 93
diff changeset
143 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
144 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
145 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
146 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
147 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
148 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
149 cmpa #'+ ; unary plus?
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 84
diff changeset
150 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
151 cmpa #'- ; negative?
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 84
diff changeset
152 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
153 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
154 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
155 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
156 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
157 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
158 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
159 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
160 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
161 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
162 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
163 tstb ; no digits?
87
3bfd978ddb39 Make corrections in floating point parsing.
William Astle <lost@l-w.ca>
parents: 86
diff changeset
164 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
165 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
166 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
167 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
168 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
169 mul
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 84
diff changeset
170 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
171 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
172 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
173 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
174 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
175 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
176 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
177 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
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
94
5fa8c479dbf7 Make E notation parse correctly, and also leading decimals, and other details
William Astle <lost@l-w.ca>
parents: 93
diff changeset
181 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
182 stb fpaextra+2
87
3bfd978ddb39 Make corrections in floating point parsing.
William Astle <lost@l-w.ca>
parents: 86
diff changeset
183 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
184 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
185 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
186 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
187 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
188 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
189 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
190 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
191 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
192 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
193 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
194 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
195 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
196 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
197 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
198 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
199 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
200 cmpa #'+ ; positive?
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 84
diff changeset
201 beq val_parsenum8 ; brif no
93
a4db504611e2 Handle tokenized signs parsing E notation
William Astle <lost@l-w.ca>
parents: 88
diff changeset
202 cmpa #tok_plus ; tokenized plus?
a4db504611e2 Handle tokenized signs parsing E notation
William Astle <lost@l-w.ca>
parents: 88
diff changeset
203 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
204 cmpa #'- ; negative?
93
a4db504611e2 Handle tokenized signs parsing E notation
William Astle <lost@l-w.ca>
parents: 88
diff changeset
205 beq val_parsenum7a ; brif so
a4db504611e2 Handle tokenized signs parsing E notation
William Astle <lost@l-w.ca>
parents: 88
diff changeset
206 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
207 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
208 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
209 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
210 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
211 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
212 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
213 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
214 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
215 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
216 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
217 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
218 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
219 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
220 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
221 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
222 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
223 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
224 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
225 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
226 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
227 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
228 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
229 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
230 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
231 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
232 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
233 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
234 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
235 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
236 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
237 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
238 rts
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 84
diff changeset
239 ; 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
240 ; 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
241 ; to an aribtrary number of leading zeroes.
94
5fa8c479dbf7 Make E notation parse correctly, and also leading decimals, and other details
William Astle <lost@l-w.ca>
parents: 93
diff changeset
242 val_parsenum11a 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
243 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
244 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
245 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
246 ; 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
247 ; 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
248 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
249 cmpa #10
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 84
diff changeset
250 bne val_parsenum12
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 84
diff changeset
251 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
252 cmpx #0x2147
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 84
diff changeset
253 bne val_parsenum12
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 84
diff changeset
254 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
255 cmpx #0x4836
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 84
diff changeset
256 bne val_parsenum12
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 84
diff changeset
257 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
258 cmpx #0x4800
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 84
diff changeset
259 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
260 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
261 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
262 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
263 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
264 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
265 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
266 adda #64
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 84
diff changeset
267 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
268 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
269 jmp fps_normalize
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 84
diff changeset
270 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
271 sta val0+val.type
86
de42b8f77bc2 Fix problems related to parsing numbers (exponent, integers)
William Astle <lost@l-w.ca>
parents: 85
diff changeset
272 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
273 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
274 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
275 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
276 lslb
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 84
diff changeset
277 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
278 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
279 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
280 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
281 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
282 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
283 bne val_parsenum15
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 84
diff changeset
284 ; 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
285 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
286 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
287 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
288 ror fpa0+fpa.sig+1
de42b8f77bc2 Fix problems related to parsing numbers (exponent, integers)
William Astle <lost@l-w.ca>
parents: 85
diff changeset
289 ror fpa0+fpa.sig+2
de42b8f77bc2 Fix problems related to parsing numbers (exponent, integers)
William Astle <lost@l-w.ca>
parents: 85
diff changeset
290 ror fpa0+fpa.sig+3
de42b8f77bc2 Fix problems related to parsing numbers (exponent, integers)
William Astle <lost@l-w.ca>
parents: 85
diff changeset
291 ror fpa0+fpa.sig+4
de42b8f77bc2 Fix problems related to parsing numbers (exponent, integers)
William Astle <lost@l-w.ca>
parents: 85
diff changeset
292 ror val0+val.int
de42b8f77bc2 Fix problems related to parsing numbers (exponent, integers)
William Astle <lost@l-w.ca>
parents: 85
diff changeset
293 ror val0+val.int+1
de42b8f77bc2 Fix problems related to parsing numbers (exponent, integers)
William Astle <lost@l-w.ca>
parents: 85
diff changeset
294 ror val0+val.int+2
de42b8f77bc2 Fix problems related to parsing numbers (exponent, integers)
William Astle <lost@l-w.ca>
parents: 85
diff changeset
295 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
296 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
297 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
298 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
299 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
300 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
301 lsra
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 84
diff changeset
302 lsra
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 84
diff changeset
303 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
304 mul
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 84
diff changeset
305 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
306 addb ,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 84
diff changeset
307 stb ,x+
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 84
diff changeset
308 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
309 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
310 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
311 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
312 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
313 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
314 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
315 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
316 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
317 ldd zero
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 84
diff changeset
318 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
319 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
320 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
321 val_parsenum19 rts
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 84
diff changeset
322 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
323 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
324 *pragmapop list