annotate src/fps.s @ 98:6837d10b67fb

Add integer <-> float conversion routines and combine some code for parsing
author William Astle <lost@l-w.ca>
date Sun, 22 Oct 2023 23:54:24 -0600
parents 69af7224f614
children 4d7fa11ebe3f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
1 *pragmapush list
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
2 *pragma list
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
4 ; Single precision floating point arithmetic package
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
5 ;
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
6 ; The single precision floating point values are stored as follows (unpacked):
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
7 ;
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
8 ; Byte Length What
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
9 ; 0 1 Exponent with a +63 bias, 0 = number is zero
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
10 ; 1 5 BCD significand (10 digits)
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
11 ; 6 1 Sign (00 = positive, FF = negative)
82
9a4e2364a966 Fix logic in int32_mul and overflow integer multiply to floating point
William Astle <lost@l-w.ca>
parents: 80
diff changeset
12 ;
9a4e2364a966 Fix logic in int32_mul and overflow integer multiply to floating point
William Astle <lost@l-w.ca>
parents: 80
diff changeset
13 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
14 ; Unpack single precision BCD floating point at (X) to fpa1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
15 fps_unpack1 ldb ,x ; get sign and exponent
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
16 bne fps_unpack1b ; brif not zero
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
17 ldd zero ; zero out the entire value to represent 0
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
18 std fpa1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
19 std fpa1+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
20 std fpa1+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
21 sta fpa1+6
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
22 rts
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
23 fps_unpack1b sex ; get sign flag to store
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
24 sta fpa1+fpa.sign ; set accumulator
89
f519075cc164 Fix various issues with floating point number display
William Astle <lost@l-w.ca>
parents: 85
diff changeset
25 andb #0x7f ; lose sign from exponent
f519075cc164 Fix various issues with floating point number display
William Astle <lost@l-w.ca>
parents: 85
diff changeset
26 stb fpa1+fpa.exp ; set exponent
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
27 ldd 1,x ; copy signficand over
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
28 std fpa1+fpa.sig
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
29 ldd 3,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
30 std fpa1+fpa.sig+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
31 lda 5,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
32 sta fpa1+fpa.sig+4
83
a492441bfc56 Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents: 82
diff changeset
33 rts
a492441bfc56 Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents: 82
diff changeset
34 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
35 ; Unpack single precision BCD floating point at (X) to fpa0
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
36 fps_unpack0 ldb ,x ; get sign and exponent
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
37 bne fps_unpack0b ; brif not zero
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
38 ldd zero ; zero out the entire value to represent 0
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
39 std fpa0
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
40 std fpa0+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
41 std fpa0+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
42 sta fpa0+6
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
43 rts
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
44 fps_unpack0b sex ; get sign flag to store
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
45 sta fpa0+fpa.sign ; set accumulator
89
f519075cc164 Fix various issues with floating point number display
William Astle <lost@l-w.ca>
parents: 85
diff changeset
46 andb #0x7f ; lose sign from exponent
f519075cc164 Fix various issues with floating point number display
William Astle <lost@l-w.ca>
parents: 85
diff changeset
47 stb fpa0+fpa.exp ; set exponent
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
48 ldd 1,x ; copy signficand over
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
49 std fpa0+fpa.sig
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
50 ldd 3,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
51 std fpa0+fpa.sig+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
52 lda 5,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
53 sta fpa0+fpa.sig+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
54 rts
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
55 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
56 ; Pack single precision BCD floating point in fpa1 to (X)
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
57 fps_pack1 lda fpa1+fpa.sign ; get sign bits
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
58 anda #0x80 ; only keep high bit
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
59 ora fpa1+fpa.exp ; merge with exponent
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
60 sta ,x ; put in destination
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
61 ldd fpa1+fpa.sig ; copy significand over
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
62 std 1,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
63 ldd fpa1+fpa.sig+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
64 std 3,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
65 lda fpa1+fpa.sig+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
66 sta 5,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
67 rts
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
68 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
69 ; Pack single precision BCD floating point in fpa0 to (X)
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
70 fps_pack0 lda fpa0+fpa.sign ; get sign bits
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
71 anda #0x80 ; only keep high bit
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
72 ora fpa0+fpa.exp ; merge with exponent
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
73 sta ,x ; put in destination
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
74 ldd fpa0+fpa.sig ; copy significand over
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
75 std 1,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
76 ldd fpa0+fpa.sig+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
77 std 3,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
78 lda fpa0+fpa.sig+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
79 sta 5,x
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
80 rts
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
81 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
82 ; Copy binary arguments
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
83 fps_copyargs clr fpa0+fpa.extra ; clear extra precision bits
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
84 clr fpa1+fpa.extra
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
85 bsr fps_unpack0 ; unpack first argument to fpa0
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
86 leax ,u ; point to second argument
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
87 bra fps_unpack1 ; now unpack it to fpa1 and return
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
88 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
89 ; Single precision BCD floating point subtraction
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
90 ; (X) - (U) -> (Y)
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
91 fps_sub bsr fps_copyargs ; copy input arguments
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
92 ldb fpa1+fpa.exp ; subtracting zero?
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
93 beq fps_add0 ; brif so - do nothing
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
94 com fpa1+fpa.sign ; invert sign
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
95 bra fps_add1 ; go handle addition of negative
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
96 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
97 ; Single precision BCD floating point addition
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
98 ; (X) + (U) -> (Y)
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
99 ;
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
100 ; Note: must denormalize the *shorter* value. However, we may end up with values the same length so we may not be able
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
101 ; to easily identify which one is larger.
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
102 ;
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
103 ; Note that the magnitude can get substantially smaller after addition of a negative so renormalization is necessary
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
104 ; after the operation. As a result, some additional precision is maintained during the addition operation to allow for
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
105 ; correct rounding.
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
106 ;
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
107 ; Rounding will be according to the standard rules: 0...4 go toward zero, 5...9 go away from zero.
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
108 fps_add bsr fps_copyargs ; fetch arguments
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
109 ldb fpa1+fpa.exp ; is second argument zero?
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
110 bne fps_add1 ; brif not
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
111 fps_add0 leax ,y ; if second argument is zero, do nothing and return first operand
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
112 bra fps_pack0
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
113 fps_add1 ldb fpa0+fpa.exp ; is first argument zero?
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
114 bne fps_add3 ; brif not
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
115 fps_add2 leax ,y ; point to output argument
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
116 bra fps_pack1 ; pack second argument to result and return
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
117 fps_add3 ldd zero ;* initialize extra precision bytes following significand which we need
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
118 std fpa0+fpa.sig+5 ;* to handle denormalization of the smaller operand
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
119 std fpa0+fpa.sig+7
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
120 sta fpa0+fpa.sig+9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
121 std fpa1+fpa.sig+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
122 std fpa1+fpa.sig+7
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
123 sta fpa1+fpa.sig+9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
124 subb fpa0+fpa.exp ; calculate exponent difference
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
125 lbeq fps_add8 ; brif same exponent - no need to denormalize
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
126 bcs fps_add4 ; brif second operand is bigger
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
127 ldx #fpa1 ; point to second operand to denormalize
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
128 cmpb #10 ; are we going to shift more than the precision?
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
129 bhs fps_add0 ; brif so - return first operand
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
130 bra fps_add5 ; go shift operand right by B places
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
131 fps_add4 negb ; get positive number of shifts
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
132 ldx #fpa0 ; shift left operand right B places
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
133 lda fpa1+fpa.exp ; set exponent of result to larger of two
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
134 sta fpa0+fpa.exp
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
135 cmpb #10 ; shifting more than precision?
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
136 bhs fps_add2 ; brif so - return second operand
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
137 fps_add5 subb #2 ; do we need at least two places?
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
138 bcs fps_add6 ; brif not
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
139 lda fpa.sig+8,x ; shift right into extra digits
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
140 sta fpa.sig+9,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
141 lda fpa.sig+7,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
142 sta fpa.sig+8,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
143 lda fpa.sig+6,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
144 sta fpa.sig+7,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
145 lda fpa.sig+5,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
146 sta fpa.sig+6,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
147 lda fpa.sig+4,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
148 sta fpa.sig+5,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
149 lda fpa.sig+3,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
150 sta fpa.sig+4,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
151 lda fpa.sig+2,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
152 sta fpa.sig+3,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
153 lda fpa.sig+1,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
154 sta fpa.sig+2,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
155 lda fpa.sig,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
156 sta fpa.sig+1,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
157 clr fpa.sig,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
158 bra fps_add5 ; go see if we have more to shift
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
159 fps_add6 incb ; do we still have a digit to shift?
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
160 bne fps_add8 ; brif not
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
161 lsr fpa.sig,x ; shift a digit right
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
162 ror fpa.sig+1,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
163 ror fpa.sig+2,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
164 ror fpa.sig+3,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
165 ror fpa.sig+4,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
166 ror fpa.sig+5,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
167 ror fpa.sig+6,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
168 ror fpa.sig+7,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
169 ror fpa.sig+8,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
170 ror fpa.sig+9,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
171 lsr fpa.sig,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
172 ror fpa.sig+1,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
173 ror fpa.sig+2,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
174 ror fpa.sig+3,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
175 ror fpa.sig+4,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
176 ror fpa.sig+5,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
177 ror fpa.sig+6,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
178 ror fpa.sig+7,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
179 ror fpa.sig+8,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
180 ror fpa.sig+9,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
181 lsr fpa.sig,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
182 ror fpa.sig+1,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
183 ror fpa.sig+2,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
184 ror fpa.sig+3,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
185 ror fpa.sig+4,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
186 ror fpa.sig+5,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
187 ror fpa.sig+6,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
188 ror fpa.sig+7,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
189 ror fpa.sig+8,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
190 ror fpa.sig+9,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
191 lsr fpa.sig,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
192 ror fpa.sig+1,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
193 ror fpa.sig+2,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
194 ror fpa.sig+3,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
195 ror fpa.sig+4,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
196 ror fpa.sig+5,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
197 ror fpa.sig+6,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
198 ror fpa.sig+7,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
199 ror fpa.sig+8,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
200 ror fpa.sig+9,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
201 fps_add8 clra ; clear carry so regular addition works below
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
202 lda fpa0+fpa.sign ; do signs differ?
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
203 eora fpa1+fpa.sign
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
204 sta fpa1+fpa.exp ; non-zero if signs differ; we don't need fpa1 exponent any more
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
205 beq fps_add11 ; brif not - just add
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
206 ldx #fpa1 ; default to second argument being smaller
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
207 lda fpa0+fpa.sig ; compare high digits of significand
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
208 cmpa fpa1+fpa.sig
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
209 bne fps_add9 ; brif top digits differ
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
210 lda fpa0+fpa.sig+1 ; next digits?
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
211 cmpa fpa1+fpa.sig+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
212 bne fps_add9 ; brif digits differ; pattern continues
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
213 lda fpa0+fpa.sig+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
214 cmpa fpa1+fpa.sig+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
215 bne fps_add9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
216 lda fpa0+fpa.sig+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
217 cmpa fpa1+fpa.sig+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
218 bne fps_add9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
219 lda fpa0+fpa.sig+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
220 cmpa fpa1+fpa.sig+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
221 bne fps_add9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
222 lda fpa0+fpa.sig+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
223 cmpa fpa1+fpa.sig+5 ; don't have to check other extras; only one set will be set
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
224 fps_add9 bhs fps_add10 ; brif first operand is bigger
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
225 ldx #fpa0 ; point to first operand as smaller
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
226 lda fpa1+fpa.sign ; set result sign to that of larger operand
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
227 sta fpa0+fpa.sign
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
228 fps_add10 ldd #0x9999 ;* calculate 9's complement of smaller operand (X must already point to it)
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
229 subd fpa.sig,x ;* we'll complete the 10's complement by setting C on the way into the
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
230 std fpa.sig,x ;* addition sequence
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
231 ldd #0x9999
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
232 subd fpa.sig+2,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
233 std fpa.sig+2,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
234 ldd #0x9999
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
235 subd fpa.sig+4,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
236 std fpa.sig+4,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
237 ldd #0x9999
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
238 subd fpa.sig+6,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
239 std fpa.sig+6,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
240 ldd #0x9999
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
241 subd fpa.sig+8,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
242 std fpa.sig+8,x
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
243 coma ; set carry going into add
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
244 fps_add11 lda fpa0+fpa.sig+9 ; do the addition (10 bytes)
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
245 adca fpa1+fpa.sig+9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
246 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
247 sta fpa0+fpa.sig+9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
248 lda fpa0+fpa.sig+8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
249 adca fpa1+fpa.sig+8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
250 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
251 sta fpa0+fpa.sig+8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
252 lda fpa0+fpa.sig+7
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
253 adca fpa1+fpa.sig+7
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
254 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
255 sta fpa0+fpa.sig+7
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
256 lda fpa0+fpa.sig+6
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
257 adca fpa1+fpa.sig+6
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
258 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
259 sta fpa0+fpa.sig+6
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
260 lda fpa0+fpa.sig+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
261 adca fpa1+fpa.sig+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
262 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
263 sta fpa0+fpa.sig+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
264 lda fpa0+fpa.sig+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
265 adca fpa1+fpa.sig+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
266 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
267 sta fpa0+fpa.sig+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
268 lda fpa0+fpa.sig+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
269 adca fpa1+fpa.sig+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
270 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
271 sta fpa0+fpa.sig+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
272 lda fpa0+fpa.sig+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
273 adca fpa1+fpa.sig+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
274 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
275 sta fpa0+fpa.sig+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
276 lda fpa0+fpa.sig+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
277 adca fpa1+fpa.sig+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
278 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
279 sta fpa0+fpa.sig+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
280 lda fpa0+fpa.sig
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
281 adca fpa1+fpa.sig
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
282 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
283 sta fpa0+fpa.sig
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
284 ror fpa1+fpa.exp ;* do sign flag and carry differ? will set V if so; we will never have
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
285 rol fpa1+fpa.exp ;* a real carry on the subtract case but might on the add case
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
286 bvc fps_normalize ; brif we didn't overflow significand - we can normalize the result
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
287 inc fpa0+fpa.exp ; bump exponent to account for overflow
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
288 lbmi OVERROR ; brif it overflowed
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
289 ror fpa0+fpa.sig ; do a bit dance
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
290 ror fpa0+fpa.sig+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
291 ror fpa0+fpa.sig+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
292 ror fpa0+fpa.sig+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
293 ror fpa0+fpa.sig+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
294 ror fpa0+fpa.sig+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
295 ror fpa0+fpa.sig+6
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
296 ror fpa0+fpa.sig+7
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
297 ror fpa0+fpa.sig+8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
298 ror fpa0+fpa.sig+9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
299 ror fpa0+fpa.sig
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
300 ror fpa0+fpa.sig+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
301 ror fpa0+fpa.sig+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
302 ror fpa0+fpa.sig+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
303 ror fpa0+fpa.sig+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
304 ror fpa0+fpa.sig+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
305 ror fpa0+fpa.sig+6
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
306 ror fpa0+fpa.sig+7
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
307 ror fpa0+fpa.sig+8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
308 ror fpa0+fpa.sig+9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
309 ror fpa0+fpa.sig
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
310 ror fpa0+fpa.sig+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
311 ror fpa0+fpa.sig+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
312 ror fpa0+fpa.sig+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
313 ror fpa0+fpa.sig+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
314 ror fpa0+fpa.sig+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
315 ror fpa0+fpa.sig+6
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
316 ror fpa0+fpa.sig+7
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
317 ror fpa0+fpa.sig+8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
318 ror fpa0+fpa.sig+9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
319 ror fpa0+fpa.sig
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
320 ror fpa0+fpa.sig+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
321 ror fpa0+fpa.sig+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
322 ror fpa0+fpa.sig+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
323 ror fpa0+fpa.sig+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
324 ror fpa0+fpa.sig+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
325 ror fpa0+fpa.sig+6
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
326 ror fpa0+fpa.sig+7
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
327 ror fpa0+fpa.sig+8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
328 ror fpa0+fpa.sig+9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
329 ; fall through to normalization routine
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
330 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
331 ; Normalize a floating point value in fpa0 with extra precision digits at fpaextra (up to 5 bytes) and return the
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
332 ; packed result at (Y)
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
333 ;
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
334 ; The first step is to shift the significand left until a nonzero digit is in the leftmost position. This will bring
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
335 ; in extra precision digits from fpaextra through fpaextra4 until either 10 shifts are done or the decimal exponent
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
336 ; underflows. In both of those cases, the result will be zero.
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
337 ;
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
338 ; Once the leftmost digit is nonzero, the leftmost extra precision digit is checked to see if it is >= 5. If so, the
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
339 ; significand will have 1 added to it. If that triggers a carry, the decimal exponent will be incremented and the
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
340 ; significand will have its leftmost digit set to 1.
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
341 ;
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
342 ; This will trigger an overflow if the decimal exponent exceeds the allowed range.
98
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
343 fps_normalize bsr fps_normalizea0 ; do the normalization in fpa0
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
344 leax ,y ; point to the desired destination
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
345 jmp fps_pack0 ; go pack the result to the correct destination
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
346 fps_normalizea0 clrb ; initialize the exponent adjustment counter
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
347 fps_normalize0 lda fpa0+fpa.sig ; do we have a nonzero digit in the first pair?
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
348 bne fps_normalize1 ; brif so
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
349 lda fpa0+fpa.sig+1 ; shift everything left 2 spaces
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
350 sta fpa0+fpa.sig
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
351 lda fpa0+fpa.sig+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
352 sta fpa0+fpa.sig+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
353 lda fpa0+fpa.sig+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
354 sta fpa0+fpa.sig+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
355 lda fpa0+fpa.sig+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
356 sta fpa0+fpa.sig+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
357 lda fpaextra
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
358 sta fpa0+fpa.sig+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
359 lda fpaextra+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
360 sta fpaextra
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
361 lda fpaextra+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
362 sta fpaextra+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
363 lda fpaextra+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
364 sta fpaextra+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
365 lda fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
366 sta fpaextra+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
367 clr fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
368 subb #2 ; account for two digit positions
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
369 cmpb #-10 ; have we shifted the whole set of digits (assumes originally normalized)
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
370 bgt fps_normalize0 ; brif not
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
371 fps_normalize4 clr fpa0+fpa.exp ; set result to zero
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
372 clr fpa0+fpa.sign
98
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
373 fps_normalize5 rts
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
374 fps_normalize1 bita #0xf0 ; is the high digit zero?
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
375 bne fps_normalize3 ; brif not
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
376 lsl fpaextra ; only need to shift one extra position here since there won't be more shifts
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
377 rol fpa0+fpa.sig+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
378 rol fpa0+fpa.sig+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
379 rol fpa0+fpa.sig+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
380 rol fpa0+fpa.sig+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
381 rol fpa0+fpa.sig
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
382 lsl fpaextra
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
383 rol fpa0+fpa.sig+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
384 rol fpa0+fpa.sig+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
385 rol fpa0+fpa.sig+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
386 rol fpa0+fpa.sig+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
387 rol fpa0+fpa.sig
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
388 lsl fpaextra
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
389 rol fpa0+fpa.sig+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
390 rol fpa0+fpa.sig+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
391 rol fpa0+fpa.sig+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
392 rol fpa0+fpa.sig+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
393 rol fpa0+fpa.sig
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
394 lsl fpaextra
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
395 rol fpa0+fpa.sig+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
396 rol fpa0+fpa.sig+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
397 rol fpa0+fpa.sig+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
398 rol fpa0+fpa.sig+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
399 rol fpa0+fpa.sig
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
400 decb ; account for digit shift
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
401 fps_normalize3 addb fpa0+fpa.exp ; adjust exponent
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
402 stb fpa0+fpa.exp
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
403 ble fps_normalize4 ; brif we underflowed to zero
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
404 ldb fpaextra ; get extra precision digit
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
405 andb #0xf0 ; keep only the highest extra precision digit
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
406 cmpb #0x50 ; do we need to round?
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
407 blo fps_normalize5 ; brif not
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
408 lda fpa0+fpa.sig+4 ; bump low digits
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
409 adda #1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
410 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
411 sta fpa0+fpa.sig+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
412 bcc fps_normalize5 ; brif no carry - done
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
413 lda fpa0+fpa.sig+3 ; keep going until all significand bytes handled
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
414 adda #1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
415 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
416 sta fpa0+fpa.sig+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
417 bcc fps_normalize5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
418 lda fpa0+fpa.sig+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
419 adda #1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
420 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
421 sta fpa0+fpa.sig+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
422 bcc fps_normalize5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
423 lda fpa0+fpa.sig+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
424 adda #1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
425 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
426 sta fpa0+fpa.sig+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
427 bcc fps_normalize5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
428 lda fpa0+fpa.sig
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
429 adda #1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
430 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
431 sta fpa0+fpa.sig
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
432 bcc fps_normalize5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
433 lda #0x10 ; overflowed the significand - shift a 1 digit in
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
434 sta fpa0+fpa.sig
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
435 inc fpa0+fpa.exp ; and bump exponent to reflect that
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
436 bpl fps_normalize5 ; brif we didn't overflow - return result
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
437 OVERROR ldb #err_ov ; raise overflow
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
438 jmp ERROR
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
439 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
440 ; Single precision BCD multiply (X) by (U)
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
441 ;
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
442 ; Calculate: (X) * (U) -> (Y)
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
443 ;
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
444 ; First, the routine calculates the new exponent and sign. The exponents simply add together while the sign is the
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
445 ; exclusive OR of the two input signs. That gives negative for differing signs and positive for matching signs.
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
446 ; Then the multiplication of the significands works by initializing an accumulator large enough to hold twice as
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
447 ; many digits as each significand to zeroes. It also needs an extra byte to the left to handle overflow for each
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
448 ; digit operation. It then works through each digit of the multiplier and uses that as a count to add the
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
449 ; multiplicand to the *high digits* of the accumulator. Then, before moving to the next digit, the accumulator and
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
450 ; mulltiplier are shifted right and the process is repeated. Once the process is done, the result required for the
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
451 ; floating point calculation will be the high 10 digits of the accumulator with extra digits stored in the
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
452 ; remaining bytes.
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
453 ;
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
454 ; Once the multiplication is complete, the significand is normalized. See above.
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
455 fps_mul jsr fps_copyargs ; fetch arguments
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
456 lda fpa0+fpa.exp ; first argumennt zero?
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
457 bne fps_mul0 ; brif not
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
458 leax ,y ; return first argument (0)
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
459 jmp fps_pack0
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
460 fps_mul0 lda fpa1+fpa.exp ; second argument zero?
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
461 bne fps_mul1 ; brif not
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
462 leax ,y ; return second argument (0)
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
463 jmp fps_pack1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
464 fps_mul1 lda fpa0+fpa.sign ; calculate result sign
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
465 eora fpa1+fpa.sign
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
466 sta fpa0+fpa.sign ; result will go into fpa0
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
467 lda fpa0+fpa.exp ; fetch exponent of multiplicand
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
468 suba #64 ; remove bias
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
469 sta fpa0+fpa.exp ; save it
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
470 lda fpa1+fpa.exp ; get exponent of multplier
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
471 suba #64 ; remove bias
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
472 adda fpa0+fpa.exp ; add exponents
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
473 cmpa #63 ; did we overflow upward?
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
474 bgt OVERROR ; brif so
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
475 cmpa #-63 ; did we underflow?
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
476 bhs fps_mul3 ; brif not
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
477 fps_mul2 clr fpa0+fpa.exp ; return zero if we underflow
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
478 leax ,y
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
479 jmp fps_pack0
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
480 fps_mul3 adda #64 ; add bias to resulting exponent
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
481 sta fpa0+fpa.exp ; save result exponent
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
482 ldd zero ;* zero out result buffer high digits (extra digits + significand and
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
483 std fpaextra ;* one extra byte to make sure lowest extra digit is zero)
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
484 std fpaextra+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
485 std fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
486 sta fpaextra+6
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
487 ldb fpa1+fpa.sig+4 ;* do each byte of multiplier significand in sequence
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
488 bsr fps_mul4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
489 ldb fpa1+fpa.sig+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
490 bsr fps_mul4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
491 ldb fpa1+fpa.sig+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
492 bsr fps_mul4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
493 ldb fpa1+fpa.sig+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
494 bsr fps_mul4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
495 ldb fpa1+fpa.sig
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
496 bsr fps_mul4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
497 ldd fpaextra+1 ; copy result into fpa0 significand (overflow byte will be zero)
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
498 std fpa0+fpa.sig
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
499 ldd fpaextra+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
500 std fpa0+fpa.sig+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
501 ldd fpaextra+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
502 sta fpa0+fpa.sig+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
503 ldd fpaextra+7
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
504 std fpa0+fpa.sig+6
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
505 ldd fpaextra+9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
506 std fpa0+fpa.sig+8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
507 jmp fps_normalize ; go normalize the result
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
508 fps_mul4 bne fps_mul6 ; brif at least one digit is nonzero
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
509 ldd fpaextra+8 ; shift right by 8 bits
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
510 std fpaextra+9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
511 ldd fpaextra+6
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
512 std fpaextra+7
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
513 ldd fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
514 std fpaextra+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
515 ldd fpaextra+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
516 sta fpaextra+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
517 ldd fpaextra
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
518 std fpaextra+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
519 clr fpaextra
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
520 rts
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
521 fps_mul5 bsr fps_mul11 ; add multiplicand to accumulator
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
522 decb ; account for iteration
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
523 fps_mul6 bitb #0x0f ; done everything for this digit?
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
524 bne fps_mul7
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
525 bsr fps_mul9 ; shift accumulator
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
526 bra fps_mul8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
527 fps_mul7 bsr fps_mul11 ; add multiplicand to accumulator
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
528 subb #0x10 ; account for iteration
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
529 fps_mul8 bitb #0xf0 ; done all iterations?
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
530 bne fps_mul7 ; brif not
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
531 fps_mul9 lsr fpaextra ; shift result
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
532 ror fpaextra+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
533 ror fpaextra+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
534 ror fpaextra+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
535 ror fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
536 ror fpaextra+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
537 ror fpaextra+6
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
538 ror fpaextra+7
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
539 ror fpaextra+8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
540 ror fpaextra+9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
541 ror fpaextra+10
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
542 lsr fpaextra
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
543 ror fpaextra+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
544 ror fpaextra+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
545 ror fpaextra+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
546 ror fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
547 ror fpaextra+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
548 ror fpaextra+6
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
549 ror fpaextra+7
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
550 ror fpaextra+8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
551 ror fpaextra+9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
552 ror fpaextra+10
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
553 lsr fpaextra
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
554 ror fpaextra+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
555 ror fpaextra+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
556 ror fpaextra+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
557 ror fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
558 ror fpaextra+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
559 ror fpaextra+6
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
560 ror fpaextra+7
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
561 ror fpaextra+8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
562 ror fpaextra+9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
563 ror fpaextra+10
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
564 lsr fpaextra
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
565 ror fpaextra+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
566 ror fpaextra+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
567 ror fpaextra+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
568 ror fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
569 ror fpaextra+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
570 ror fpaextra+6
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
571 ror fpaextra+7
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
572 ror fpaextra+8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
573 ror fpaextra+9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
574 ror fpaextra+10
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
575 rts
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
576 fps_mul11 lda fpa0+fpa.sig+4 ; add digits starting at the bottom
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
577 adda fpaextra+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
578 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
579 sta fpaextra+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
580 lda fpa0+fpa.sig+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
581 adca fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
582 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
583 sta fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
584 lda fpa0+fpa.sig+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
585 adca fpaextra+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
586 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
587 sta fpaextra+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
588 lda fpa0+fpa.sig+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
589 adca fpaextra+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
590 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
591 sta fpaextra+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
592 lda fpa0+fpa.sig
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
593 adca fpaextra+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
594 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
595 sta fpaextra+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
596 bcc fps_mul12
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
597 inc fpaextra ; handle carry out
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
598 fps_mul12 rts
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
599 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
600 ; Single precision BCD divide
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
601 ;
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
602 ; Calculate (X) ÷ (U) -> (Y)
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
603 ;
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
604 ; First, calculate the result exponent by subtracting the decimal exponent of (U) from that of (X). If the result goes
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
605 ; above the exponent range, raise overflow. If it goes below the exponent range, return zero.
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
606 ;
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
607 ; The calculate the result sign the same as for multiplcation. Also calculate the 10's complement of the divisor.
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
608 ;
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
609 ; First, we copy the divdend into the extra precision digits in fpa1 since they aren't needed for anything else
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
610 ; here. Then we set the desired nonzero digit counter to 11 to indicate 10 significant digits plus a digit for
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
611 ; rounding and set the flag indicating a nonzero digit was seen to zero to indicate it hasn't been seen. Also set
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
612 ; the extra carry byte to zero. Then we run through the digit pair routine 10 times to set 20 digits of the
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
613 ; significand and extra precision for fpa0. The digit pair routine just calls the digit loop twice while doing
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
614 ; some bookkeeping.
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
615 ;
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
616 ; We also pre-cacluate the 9's complement of the divisor and store that in fpaextra to save time during the
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
617 ; subtraction steps.
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
618 ;
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
619 ; For each digit, the process is as follows:
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
620 ;
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
621 ; 1. If the desired digit count is zero, do nothing and just return a zero for the quotient digit.
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
622 ; 2. Initialize the quotient digit to 0
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
623 ; 3. If the extra carry is nonzero, we know the result "goes" so go on to step 6
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
624 ; 4. Compare the divisor to the residue; this is faster on average than doing the subtraction and then
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
625 ; reversing the last subtraction loop.
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
626 ; 5. If the divisor goes *exactly* into the residue, bump the quotient digit, clear the desired digit count
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
627 ; and return the quotient digit; we have no need to do anything more
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
628 ; 6. If the divisor does go, subtract the divisor from the residue, bump the digit, and go back to step 3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
629 ; 7. If the resulting digit is nonzero, set the "nonzero digit seen" flag to 1 (exactly one)
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
630 ; 8. Subtract the nonzero digit flag from the desired digits flag so after enough digits, we stop doing the
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
631 ; division loops.
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
632 ; 9. Return the quotient digit.
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
633 fps_div jsr fps_copyargs ; get arguments to the accumulators
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
634 lda fpa1+fpa.exp ; get divisor exponent
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
635 bne fps_div0 ; brif not zero
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
636 DIV0ERROR ldb #err_div0 ; raise division by zero
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
637 jmp ERROR
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
638 fps_div0 suba #64 ; remove bias
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
639 sta fpa1+fpa.exp ; save for later calculation
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
640 lda fpa0+fpa.exp ; get quotient exponent
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
641 bne fps_div2 ; brif not zero - we have to do work
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
642 fps_div1 clr fpa0+fpa.exp ; make sure result is zero
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
643 leax ,y ; return zero result
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
644 jmp fps_pack0
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
645 fps_div2 suba #64 ; remove bias
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
646 suba fpa1+fpa.exp ; subtract divisor exponent
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
647 cmpa #64 ; did we overflow upward?
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
648 lbge OVERROR ; brif so
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
649 cmpa #-64 ; did we overflow downward (underflow)?
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
650 bls fps_div1 ; brif we underflow
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
651 adda #64 ; add back the bias
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
652 sta fpa0+fpa.exp ; set result exponent
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
653 lda fpa0+fpa.sign ; calculate result sign (XOR of argument signs)
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
654 eora fpa1+fpa.sign
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
655 sta fpa0+fpa.sign
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
656 ldd fpa0+fpa.sig ; initialize residue to dividend
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
657 std fpa1+fpa.sig
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
658 ldd fpa0+fpa.sig+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
659 std fpa1+fpa.sig+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
660 lda fpa0+fpa.sig+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
661 sta fpa1+fpa.sig+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
662 ldd #11 ; initialize digit counter and nonzero seen flag
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
663 std fpaextra+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
664 sta fpaextra+7 ; set ongoing extra carry digits to zero
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
665 ldd #0x9999 ;* calculate 9's complement of divisor for later; we'll introduce a carry
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
666 subd fpa1+fpa.sig ;* to the first byte to complete the 10's complement's +1 to save doing
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
667 std fpaextra ;* the extra work here
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
668 ldd #0x9999
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
669 subd fpa1+fpa.sig+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
670 std fpaextra+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
671 lda #0x99
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
672 suba fpa1+fpa.sig+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
673 sta fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
674 bsr fps_div3 ; calculate the quotient byte by byte
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
675 stb fpa0+fpa.sig
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
676 bsr fps_div3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
677 stb fpa0+fpa.sig+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
678 bsr fps_div3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
679 stb fpa0+fpa.sig+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
680 bsr fps_div3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
681 stb fpa0+fpa.sig+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
682 bsr fps_div3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
683 stb fpa0+fpa.sig+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
684 bsr fps_div3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
685 stb fpa0+fpa.sig+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
686 bsr fps_div3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
687 stb fpa0+fpa.sig+6
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
688 bsr fps_div3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
689 stb fpa0+fpa.sig+7
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
690 bsr fps_div3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
691 stb fpa0+fpa.sig+8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
692 bsr fps_div3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
693 stb fpa0+fpa.sig+9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
694 jmp fps_normalize ; go normalize the result and return
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
695 fps_div3 bsr fps_div5 ; do a digit
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
696 lslb ; shift it over
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
697 lslb
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
698 lslb
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
699 lslb
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
700 sta fpaextra+8 ; save it
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
701 bsr fps_div5 ; do next digit
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
702 addb fpaextra+8 ; combine the two quotient digits
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
703 fps_div4 rts
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
704 fps_div5 ldb fpaextra+6 ; do we even need to do the division?
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
705 beq fps_div4 ; brif not - return 0
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
706 clrb ; initialize quotient digit
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
707 fps_div6 lda fpaextra+7 ; did we have a carry last time?
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
708 bne fps_div7 ; brif so - we know it "goes"
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
709 lda fpa1+fpa.sig ; is the divisor less than the dividend residue?
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
710 cmpa fpa1+fpa.sig+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
711 bhi fps_div8 ; brif high byte is larger than residue
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
712 lda fpa1+fpa.sig+1 ; and keep going for all 5 bytes
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
713 cmpa fpa1+fpa.sig+6
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
714 bhi fps_div8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
715 lda fpa1+fpa.sig+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
716 cmpa fpa1+fpa.sig+7
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
717 bhi fps_div8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
718 lda fpa1+fpa.sig+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
719 cmpa fpa1+fpa.sig+8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
720 bhi fps_div8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
721 lda fpa1+fpa.sig+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
722 cmpa fpa1+fpa.sig+9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
723 bhi fps_div8 ; brif divisor is greater than the residue
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
724 bne fps_div7 ; brif it didn't go exactly
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
725 incb ; bump quotient for this "go"
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
726 clr fpaextra+6 ; indicate no more digits needed
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
727 rts
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
728 fps_div7 coma ; set carry to complete 10's complement of divisor
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
729 lda fpa1+fpa.sig+9 ; do the "subtraction"
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
730 adca fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
731 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
732 sta fpa1+fpa.sig+9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
733 lda fpa1+fpa.sig+8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
734 adca fpaextra+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
735 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
736 sta fpa1+fpa.sig+8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
737 lda fpa1+fpa.sig+7
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
738 adca fpaextra+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
739 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
740 sta fpa1+fpa.sig+7
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
741 lda fpa1+fpa.sig+6
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
742 adca fpaextra+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
743 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
744 sta fpa1+fpa.sig+6
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
745 lda fpa1+fpa.sig+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
746 adca fpaextra
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
747 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
748 sta fpa1+fpa.sig+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
749 lda fpaextra+7 ; and handle the carry byte
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
750 adca #0x99
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
751 sta fpaextra+7
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
752 incb ; bump digit count
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
753 bra fps_div6 ; go see if we need another subtraction
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
754 fps_div8 tstb ; nonzero digit?
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
755 beq fps_div9 ; brif not
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
756 lda #1 ; set nonzero flag
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
757 sta fpaextra+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
758 fps_div9 lda fpaextra+6 ; adjust digit count
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
759 suba fpaextra+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
760 sta fpaextra+6
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
761 lsl fpa1+fpa.sig+9 ; shift residue one decimal digit
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
762 rol fpa1+fpa.sig+8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
763 rol fpa1+fpa.sig+7
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
764 rol fpa1+fpa.sig+6
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
765 rol fpa1+fpa.sig+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
766 rol fpaextra+7
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
767 lsl fpa1+fpa.sig+9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
768 rol fpa1+fpa.sig+8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
769 rol fpa1+fpa.sig+7
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
770 rol fpa1+fpa.sig+6
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
771 rol fpa1+fpa.sig+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
772 rol fpaextra+7
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
773 lsl fpa1+fpa.sig+9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
774 rol fpa1+fpa.sig+8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
775 rol fpa1+fpa.sig+7
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
776 rol fpa1+fpa.sig+6
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
777 rol fpa1+fpa.sig+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
778 rol fpaextra+7
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
779 lsl fpa1+fpa.sig+9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
780 rol fpa1+fpa.sig+8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
781 rol fpa1+fpa.sig+7
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
782 rol fpa1+fpa.sig+6
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
783 rol fpa1+fpa.sig+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
784 rol fpaextra+7
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
785 rts
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
786 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
787 ; Convert a floating point number in val0 to a string in strbuff
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
788
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
789 ; The maximum size of a string generated here is 19 bytes representing 10 significant digits, 5 leading zeroes after the
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
790 ; decimal point, the decimal point, a leading zero, a leading sign, and a trailing NUL.
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
791 fps_toascii ldu #strbuff+1 ; point to output buffer
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
792 lda #0x20 ; set sign to "blank"
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
793 sta -1,u
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
794 clr fpaextra+1 ; set decimal point offset; zero means none
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
795 clr fpaextra+3 ; disable "E" notation
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
796 ldx #val0+val.value ; unpack value to fpa0 so we can mess with it
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
797 jsr fps_unpack0
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
798 lda fpa0+fpa.exp ; check exponent
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
799 bne fps_toascii0 ; brif not zero
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
800 lda #'0 ; make the number zero and print it
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
801 sta ,u
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
802 clr 1,u
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
803 rts
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
804 fps_toascii0 lda fpa0+fpa.sign ; negative?
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
805 bpl fps_toascii1 ; brif not
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
806 lda #'- ; negative sign
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
807 sta -1,u
92
6ac267da2216 Correctly calculate existing significand digits for fp to ascii conversion
William Astle <lost@l-w.ca>
parents: 91
diff changeset
808 fps_toascii1 lda #10 ; assume 10 significant digits exist
6ac267da2216 Correctly calculate existing significand digits for fp to ascii conversion
William Astle <lost@l-w.ca>
parents: 91
diff changeset
809 ldx #fpa0+fpa.sig+5 ; point to significand
6ac267da2216 Correctly calculate existing significand digits for fp to ascii conversion
William Astle <lost@l-w.ca>
parents: 91
diff changeset
810 fps_toascii2 ldb ,-x ; get digit pair
6ac267da2216 Correctly calculate existing significand digits for fp to ascii conversion
William Astle <lost@l-w.ca>
parents: 91
diff changeset
811 bitb #0x0f ; is right digit zero?
6ac267da2216 Correctly calculate existing significand digits for fp to ascii conversion
William Astle <lost@l-w.ca>
parents: 91
diff changeset
812 bne fps_toascii3 ; brif not - we've counted all the significant digits
6ac267da2216 Correctly calculate existing significand digits for fp to ascii conversion
William Astle <lost@l-w.ca>
parents: 91
diff changeset
813 deca ; trailing zero - uncount it
6ac267da2216 Correctly calculate existing significand digits for fp to ascii conversion
William Astle <lost@l-w.ca>
parents: 91
diff changeset
814 bitb #0xf0 ; is left digit zero?
6ac267da2216 Correctly calculate existing significand digits for fp to ascii conversion
William Astle <lost@l-w.ca>
parents: 91
diff changeset
815 bne fps_toascii3 ; brif not - we've counted all the sigificant digits
6ac267da2216 Correctly calculate existing significand digits for fp to ascii conversion
William Astle <lost@l-w.ca>
parents: 91
diff changeset
816 deca ; trailing zero - uncount it
6ac267da2216 Correctly calculate existing significand digits for fp to ascii conversion
William Astle <lost@l-w.ca>
parents: 91
diff changeset
817 cmpx #fpa0+fpa.sig ; done all significant digits?
6ac267da2216 Correctly calculate existing significand digits for fp to ascii conversion
William Astle <lost@l-w.ca>
parents: 91
diff changeset
818 bhi fps_toascii2 ; brif not
89
f519075cc164 Fix various issues with floating point number display
William Astle <lost@l-w.ca>
parents: 85
diff changeset
819 fps_toascii3 sta fpaextra ; save significant digits that exist
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
820 lda fpa0+fpa.exp ; fetch exponent
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
821 suba #64 ; remove bias
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
822 sta fpa0+fpa.exp ; save for later
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
823 bpl fps_toascii14 ; brif no leading zeroes
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
824 suba fpaextra ; get number of significant digits plus decimal count
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
825 cmpa #-15 ; do we end up with too many digits (leading 0 + significant digits)
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
826 blt fps_toascii15 ; brif too many - do scientific notation
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
827 ldd #'0*256+'. ; put a leading "0."
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
828 std ,u++
89
f519075cc164 Fix various issues with floating point number display
William Astle <lost@l-w.ca>
parents: 85
diff changeset
829 ldb fpa0+fpa.exp ; get exponent back, which is the number of leading digits (negative)
f519075cc164 Fix various issues with floating point number display
William Astle <lost@l-w.ca>
parents: 85
diff changeset
830 bra fps_toascii4a ; go add leading zeroes if needed
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
831 fps_toascii4 sta ,u+ ; put a zero
89
f519075cc164 Fix various issues with floating point number display
William Astle <lost@l-w.ca>
parents: 85
diff changeset
832 fps_toascii4a incb ; done all
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
833 bne fps_toascii4 ; brif not
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
834 fps_toascii5 ldx #fpa0+fpa.sig ; point to significand
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
835 ldd #0xf000 ; set digit mask and counter
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
836 sta fpaextra+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
837 fps_toascii6 lda ,x ; get digit pair
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
838 anda fpaextra+2 ; keep the desired digit
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
839 bita #0xf0 ; is it the left hand digit?
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
840 beq fps_toascii7 ; brif not or digit is 0
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
841 lsra ; right justify digit
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
842 lsra
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
843 lsra
89
f519075cc164 Fix various issues with floating point number display
William Astle <lost@l-w.ca>
parents: 85
diff changeset
844 lsra
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
845 fps_toascii7 adda #0x30 ; turn it into ascii
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
846 sta ,u+ ; stuff it in the output
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
847 dec fpaextra ; done all digits?
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
848 beq fps_toascii9 ; brif so
89
f519075cc164 Fix various issues with floating point number display
William Astle <lost@l-w.ca>
parents: 85
diff changeset
849 dec fpaextra+1 ; are we at the decimal point?
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
850 bne fps_toascii8 ; brif not
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
851 lda #'. ; put a decimal
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
852 sta ,u+
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
853 fps_toascii8 com fpaextra+2 ; flip digit mask
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
854 bpl fps_toascii6 ; handle another digit
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
855 leax 1,x ; move to next digit byte
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
856 bra fps_toascii6 ; now go handle next digit
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
857 fps_toascii9 ldb fpaextra+3 ; get decimal exponent to display
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
858 beq fps_toascii13
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
859 lda #'E ; output "E"
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
860 sta ,u+
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
861 tstb ; negative?
96
69af7224f614 Tweak exponent calculation in fp to ascii conversion
William Astle <lost@l-w.ca>
parents: 92
diff changeset
862 bpl fps_toascii10 ; brif not
69af7224f614 Tweak exponent calculation in fp to ascii conversion
William Astle <lost@l-w.ca>
parents: 92
diff changeset
863 comb ; positivize it, but also subtract 1?
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
864 lda #'- ; put a minus for the exponent
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
865 sta ,u+
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
866 fps_toascii10 cmpb #10 ; do we have two digits for exponent?
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
867 blo fps_toascii12 ; brif not
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
868 lda #0x2f ; initialize left digit
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
869 fps_toascii11 inca ; bump digit
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
870 subb #10 ; are we at the right digit?
91
ecca1fcfc34b Make floating point E notation convert to ASCII correctly
William Astle <lost@l-w.ca>
parents: 89
diff changeset
871 bpl fps_toascii11 ; brif not yet
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
872 addb #10 ; undo extra subtraction
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
873 sta ,u+ ; save left digit
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
874 fps_toascii12 addb #0x30 ; turn right digit to ascii
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
875 stb ,u+ ; save right digit
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
876 fps_toascii13 clr ,u ; put a NUL at the end of the result
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
877 rts
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
878 fps_toascii14 cmpa #9 ; is it in range for number of significant digits?
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
879 bgt fps_toascii15 ; brif not - do scientific notation
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
880 inca ; exponent 0 has decimal point after first digit
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
881 sta fpaextra+1 ; save decimal point location
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
882 cmpa fpaextra ; is it more than the number of significant digits?
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
883 ble fps_toascii5 ; brif not - just convert the significand
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
884 sta fpaextra ; make sure we include the pre-decimal zeroes
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
885 bra fps_toascii5 ; go convert the significand
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
886 fps_toascii15 ldb #1 ; put decimal after the first digit
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
887 stb fpaextra+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
888 sta fpaextra+3 ; enable the "E" notation with the correct exponent
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
889 bra fps_toascii5 ; actually convert the number
98
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
890 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
891 ; Convert a 32 bit integer at (X) to BCD floating point. This requires converting the 32 bit binary value to BCD which
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
892 ; can be done using the double/dabble algorithm. fpa0 and fpaextra is used as temporary storage. X must point to a value.
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
893 ; Enter at fps_fromuint to treat the 32 value as unsigned.
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
894 fps_fromint ldb val.int,x ; is the integer negative?
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
895 bpl fps_fromuint ; brif not
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
896 sex ; set sign to negative
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
897 sta fpa0+fpa.sign
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
898 ldd zero ; negate the value and store it to temporary location
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
899 subd val.int+2,x
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
900 std fpaextra+2
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
901 ldd zero
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
902 sbcb val.int+1,x
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
903 sbca val.int,x
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
904 std fpaextra
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
905 bra fps_fromint0 ; go finish the conversion
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
906 fps_fromuint clr fpa0+fpa.sign ; set sign to positive
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
907 ldd val.int+2,x ; copy value to temporary accumulator
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
908 std fpaextra+2
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
909 ldd val.int,x
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
910 std fpaextra
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
911 fps_fromint0 leay ,x ; set result destination pointer
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
912 ldd zero ; zero out destination
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
913 std fpa0+fpa.sig
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
914 std fpa0+fpa.sig+2
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
915 sta fpa0+fpa.sig+4
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
916 ldd #0x5f20 ; set exponent for decimal right of significand and 32 bit shifts
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
917 sta fpa0+fpa.exp ; save exponent
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
918 stb fpaextra+5 ; save counter
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
919 bra fps_fromint2 ; skip digit check on the first iteration since none need adjustment
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
920 fps_fromint1 ldu #fpa0+fpa.sig ; point to significand
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
921 bsr fps_fromint3 ; do adjustments, 5 bytes worth of digits
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
922 bsr fps_fromint3
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
923 bsr fps_fromint3
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
924 bsr fps_fromint3
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
925 bsr fps_fromint3
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
926 fps_fromint2 lsl fpaextra+3 ; shift left
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
927 rol fpaextra+2
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
928 rol fpaextra+1
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
929 rol fpaextra
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
930 rol fpa0+fpa.sig+4
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
931 rol fpa0+fpa.sig+3
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
932 rol fpa0+fpa.sig+2
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
933 rol fpa0+fpa.sig+1
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
934 rol fpa0+fpa.sig
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
935 dec fpaextra+5 ; done all digits?
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
936 bne fps_fromint1 ; brif not
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
937 jsr fps_normalizea0 ; go normalize the result in fpa0
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
938 ldd fpa0+fpa.sig ; copy result to destination
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
939 std val.fpssig,y
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
940 ldd fpa0+fpa.sig+2
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
941 std val.fpssig+2,y
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
942 lda fpa0+fpa.sig+4
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
943 sta val.fpssig+4,y
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
944 lda fpa0+fpa.exp
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
945 sta val.fpsexp,y
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
946 lda fpa0+fpa.sign
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
947 sta val.fpssign,y
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
948 lda #valtype_float ; set result type to floating point
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
949 sta val.type,y
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
950 rts
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
951 ; This is the digit check for the double-dabble algorith. The left digit check is only concerned if the left digit
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
952 ; is 5 or higher. Since we can make that comparison without masking the bits, we don't bother. For the right digit,
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
953 ; however, we do have to mask the upper digit off. It saves and ANDA and a subsequent indexed reload.
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
954 fps_fromint3 clrb ; set adjustment to none
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
955 lda ,u ; get digits
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
956 cmpa #0x50 ; is digit 5 or higher?
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
957 blo fps_fromint4 ; brif not
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
958 ldb #0x30 ; set adjustment factor for first digit
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
959 fps_fromint4 anda #0x0f ; keep low digit
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
960 cmpa #5 ; is it 5 or higher?
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
961 blo fps_fromint5 ; brif not
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
962 orb #0x03 ; set adjustment for second digit
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
963 fps_fromint5 addb ,u ; add adjustment to digits
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
964 stb ,u+ ; save new digit values and move on
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
965 rts
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
966 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
967 ; Convert the floating point value in the value accumulator at (X) to a 32 bit signed integer. Will trigger an overflow
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
968 ; if the magnitude is too large and it will truncate (round toward zero) any fractional value.
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
969 fps_toint lda val.fpsexp,x ; copy the exponent, sign, and significand to fpa0
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
970 sta fpa0+fpa.exp
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
971 ldd val.fpssig,x
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
972 std fpa0+fpa.sig
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
973 ldd val.fpssig+2,x
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
974 std fpa0+fpa.sig+2
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
975 lda val.fpssig+4,x
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
976 sta fpa0+fpa.sig+4
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
977 lda val.fpssign,x
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
978 sta fpa0+fpa.sign
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
979 bsr fps_tointa0 ; convert value to integer in fpa0 significand
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
980 lda #valtype_int ; set result to integer
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
981 sta val.type,x
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
982 ldd fpa0+fpa.sig+1
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
983 std val.int,x
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
984 ldd fpa0+fpa.sig+3
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
985 std val.int+2,x
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
986 rts
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
987 fps_tointa0 ldb fpa0+fpa.exp ; compare exponent (is it too big?)
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
988 cmpb #64+9
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
989 bne fps_toint0
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
990 ldd fpa0+fpa.sig ; compare top of significand
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
991 cmpd #0x2147
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
992 bne fps_toint0
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
993 ldd fpa0+fpa.sig+2 ; compare middle of significand
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
994 cmpd #0x4836
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
995 bne fps_toint0
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
996 ldd fpa0+fpa.sig+4 ; compare bottom of significand plus extra digits
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
997 cmpd #0x4800
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
998 fps_toint0 blt fps_toint1 ; brif it fits positive or negative
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
999 lbgt OVERROR ; brif it doesn't fit negative either
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1000 ldb fpa0+fpa.sign ; do we want negative?
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1001 lbpl OVERROR ; brif not - it doesn't fit
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1002 ; Enter here if we already know that the value will fit
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1003 fps_toint1 ldb #64+9 ; biased exponent needed for decimal point to the right of significand
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1004 subb fpa0+fpa.exp ; number of digit shifts needed to denormalize
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1005 beq fps_toint3 ; brif already denormalized
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1006 lslb ; do 4 shifts per digit; we're going to simply lose extra digits
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1007 lslb
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1008 fps_toint2 lsr fpa0+fpa.sig ; shift a digit right
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1009 ror fpa0+fpa.sig+1
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1010 ror fpa0+fpa.sig+2
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1011 ror fpa0+fpa.sig+3
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1012 ror fpa0+fpa.sig+4
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1013 decb ; done all shifts?
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1014 bne fps_toint2
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1015 ; Now convert BCD digit sequence in fpa0 significand to binary value in the low 32 bits of the significand
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1016 fps_toint3 ldb #32 ; 32 bit shifts needed for whole significand
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1017 stb fpa0+fpa.extra ; use extra precision byte as counter
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1018 fps_toint4 lsr fpa0+fpa.sig ; shift a bit into the binary result
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1019 ror fpa0+fpa.sig+1
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1020 ror fpa0+fpa.sig+2
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1021 ror fpa0+fpa.sig+3
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1022 ror fpa0+fpa.sig+4
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1023 ror fpa0+fpa.extra+1
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1024 ror fpa0+fpa.extra+2
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1025 ror fpa0+fpa.extra+3
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1026 ror fpa0+fpa.extra+4
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1027 ldu #fpa0+fpa.sig ; point to BCD digits
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1028 fps_toint5 lda ,u ; get byte to check
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1029 beq fps_toint8 ; short circuit check if digits are 0
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1030 anda #0x88 ; keep bit 3 of each digit; adjustment on >= 8
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1031 lsra ; shift over and mulply by adjustment factor
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1032 lsra
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1033 lsra
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1034 ldb #3 ; the adjustment is a subtraction by 3
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1035 mul
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1036 negb ; now subtract from digit
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1037 addb ,u
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1038 stb ,u+
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1039 fps_toint6 cmpu #fpa0+fpa.sig+5 ; done all 5 bytes?
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1040 blo fps_toint5 ; brif not
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1041 dec fpa0+fpa.extra ; done all bits?
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1042 bne fps_toint6 ; brif not
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1043 ldb fpa0+fpa.sign ; do we want negative?
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1044 bpl fps_toint7 ; brif not
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1045 ldd zero ; negate the value through subtracting from 0
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1046 subd fpa0+fpa.extra+3
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1047 std fpa0+fpa.extra+3
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1048 ldd zero
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1049 sbcb fpa0+fpa.extra+1
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1050 sbca fpa0+fpa.extra
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1051 std fpa0+fpa.sig+1
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1052 fps_toint7 ldd fpa0+fpa.extra+1 ; put result in the significand
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1053 std fpa0+fpa.sig+1
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1054 ldd fpa0+fpa.extra+3
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1055 std fpa0+fpa.sig+3
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1056 rts
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1057 fps_toint8 leau 1,u ; move to next digit
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1058 bra fps_toint6 ; go back to mainline
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
1059 *pragmapop list