annotate src/fps.s @ 107:1f2f6c2a1fde

Use correct decimal exponent instead of binary for int to float conversion
author William Astle <lost@l-w.ca>
date Mon, 30 Oct 2023 22:26:44 -0600
parents 1396fe221ff7
children 1a5da3594a9e
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
102
baead5689afc Fix logic errors in floating point addition routine
William Astle <lost@l-w.ca>
parents: 100
diff changeset
124 ldb fpa0+fpa.exp ; fetch exponent of second argument
baead5689afc Fix logic errors in floating point addition routine
William Astle <lost@l-w.ca>
parents: 100
diff changeset
125 subb fpa1+fpa.exp ; calculate exponent difference
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
126 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
127 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
128 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
129 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
130 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
131 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
132 fps_add4 negb ; get positive number of shifts
102
baead5689afc Fix logic errors in floating point addition routine
William Astle <lost@l-w.ca>
parents: 100
diff changeset
133 cmpb #10 ; shifting more than precision?
baead5689afc Fix logic errors in floating point addition routine
William Astle <lost@l-w.ca>
parents: 100
diff changeset
134 bhs fps_add2 ; brif so - return second operand
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
135 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
136 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
137 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
138 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
139 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
140 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
141 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
142 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
143 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
144 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
145 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
146 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
147 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
148 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
149 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
150 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
151 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
152 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
153 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
154 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
155 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
156 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
157 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
158 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
159 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
160 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
161 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
162 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
163 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
164 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
165 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
166 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
167 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
168 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
169 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
170 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
171 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
172 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
173 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
174 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
175 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
176 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
177 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
178 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
179 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
180 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
181 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
182 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
183 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
184 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
185 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
186 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
187 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
188 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
189 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
190 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
191 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
192 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
193 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
194 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
195 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
196 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
197 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
198 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
199 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
200 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
201 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
202 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
203 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
204 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
205 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
206 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
207 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
208 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
209 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
210 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
211 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
212 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
213 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
214 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
215 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
216 bne fps_add9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
217 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
218 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
219 bne fps_add9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
220 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
221 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
222 bne fps_add9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
223 lda fpa0+fpa.sig+5
102
baead5689afc Fix logic errors in floating point addition routine
William Astle <lost@l-w.ca>
parents: 100
diff changeset
224 cmpa fpa1+fpa.sig+5 ; don't have to check other extras; the first extra will be decisive
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
225 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
226 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
227 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
228 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
229 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
230 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
231 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
232 ldd #0x9999
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
233 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
234 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
235 ldd #0x9999
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
236 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
237 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
238 ldd #0x9999
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
239 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
240 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
241 ldd #0x9999
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
242 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
243 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
244 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
245 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
246 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
247 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
248 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
249 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
250 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
251 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
252 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
253 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
254 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
255 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
256 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
257 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
258 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
259 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
260 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
261 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
262 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
263 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
264 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
265 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
266 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
267 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
268 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
269 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
270 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
271 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
272 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
273 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
274 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
275 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
276 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
277 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
278 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
279 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
280 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
281 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
282 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
283 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
284 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
285 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
286 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
287 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
288 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
289 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
290 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
291 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
292 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
293 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
294 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
295 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
296 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
297 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
298 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
299 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
300 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
301 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
302 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
303 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
304 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
305 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
306 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
307 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
308 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
309 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
310 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
311 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
312 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
313 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
314 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
315 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
316 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
317 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
318 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
319 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
320 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
321 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
322 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
323 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
324 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
325 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
326 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
327 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
328 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
329 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
330 ; 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
331 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
332 ; 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
333 ; 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
334 ;
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
335 ; 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
336 ; 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
337 ; 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
338 ;
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
339 ; 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
340 ; 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
341 ; 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
342 ;
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
343 ; 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
344 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
345 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
346 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
347 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
348 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
349 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
350 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
351 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
352 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
353 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
354 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
355 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
356 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
357 sta fpa0+fpa.sig+3
104
eecb576c76c6 Make normalization use the extra precision in the fp accumulator
William Astle <lost@l-w.ca>
parents: 102
diff changeset
358 lda fpa0+fpa.extra
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
359 sta fpa0+fpa.sig+4
104
eecb576c76c6 Make normalization use the extra precision in the fp accumulator
William Astle <lost@l-w.ca>
parents: 102
diff changeset
360 lda fpa0+fpa.extra+1
eecb576c76c6 Make normalization use the extra precision in the fp accumulator
William Astle <lost@l-w.ca>
parents: 102
diff changeset
361 sta fpa0+fpa.extra
eecb576c76c6 Make normalization use the extra precision in the fp accumulator
William Astle <lost@l-w.ca>
parents: 102
diff changeset
362 lda fpa0+fpa.extra+2
eecb576c76c6 Make normalization use the extra precision in the fp accumulator
William Astle <lost@l-w.ca>
parents: 102
diff changeset
363 sta fpa0+fpa.extra+1
eecb576c76c6 Make normalization use the extra precision in the fp accumulator
William Astle <lost@l-w.ca>
parents: 102
diff changeset
364 lda fpa0+fpa.extra+3
eecb576c76c6 Make normalization use the extra precision in the fp accumulator
William Astle <lost@l-w.ca>
parents: 102
diff changeset
365 sta fpa0+fpa.extra+2
eecb576c76c6 Make normalization use the extra precision in the fp accumulator
William Astle <lost@l-w.ca>
parents: 102
diff changeset
366 lda fpa0+fpa.extra+4
eecb576c76c6 Make normalization use the extra precision in the fp accumulator
William Astle <lost@l-w.ca>
parents: 102
diff changeset
367 sta fpa0+fpa.extra+3
eecb576c76c6 Make normalization use the extra precision in the fp accumulator
William Astle <lost@l-w.ca>
parents: 102
diff changeset
368 clr fpa0+fpa.extra+4
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
369 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
370 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
371 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
372 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
373 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
374 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
375 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
376 bne fps_normalize3 ; brif not
104
eecb576c76c6 Make normalization use the extra precision in the fp accumulator
William Astle <lost@l-w.ca>
parents: 102
diff changeset
377 lsl fpa0+fpa.extra ; only need to shift one extra position here since there won't be more shifts
85
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+4
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+3
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+2
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+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
382 rol fpa0+fpa.sig
104
eecb576c76c6 Make normalization use the extra precision in the fp accumulator
William Astle <lost@l-w.ca>
parents: 102
diff changeset
383 lsl fpa0+fpa.extra
85
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+4
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+3
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+2
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+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
388 rol fpa0+fpa.sig
104
eecb576c76c6 Make normalization use the extra precision in the fp accumulator
William Astle <lost@l-w.ca>
parents: 102
diff changeset
389 lsl fpa0+fpa.extra
85
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+4
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+3
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+2
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+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
394 rol fpa0+fpa.sig
104
eecb576c76c6 Make normalization use the extra precision in the fp accumulator
William Astle <lost@l-w.ca>
parents: 102
diff changeset
395 lsl fpa0+fpa.extra
85
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+4
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+3
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+2
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+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
400 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
401 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
402 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
403 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
404 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
405 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
406 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
407 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
408 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
409 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
410 adda #1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
411 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
412 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
413 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
414 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
415 adda #1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
416 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
417 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
418 bcc fps_normalize5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
419 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
420 adda #1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
421 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
422 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
423 bcc fps_normalize5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
424 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
425 adda #1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
426 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
427 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
428 bcc fps_normalize5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
429 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
430 adda #1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
431 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
432 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
433 bcc fps_normalize5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
434 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
435 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
436 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
437 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
438 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
439 jmp ERROR
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
440 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
441 ; 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
442 ;
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
443 ; 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
444 ;
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
445 ; 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
446 ; 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
447 ; 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
448 ; 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
449 ; 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
450 ; 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
451 ; 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
452 ; 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
453 ; remaining bytes.
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
454 ;
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
455 ; 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
456 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
457 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
458 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
459 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
460 jmp fps_pack0
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
461 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
462 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
463 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
464 jmp fps_pack1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
465 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
466 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
467 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
468 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
469 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
470 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
471 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
472 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
473 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
474 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
475 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
476 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
477 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
478 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
479 leax ,y
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
480 jmp fps_pack0
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
481 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
482 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
483 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
484 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
485 std fpaextra+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
486 std fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
487 sta fpaextra+6
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
488 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
489 bsr fps_mul4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
490 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
491 bsr fps_mul4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
492 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
493 bsr fps_mul4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
494 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
495 bsr fps_mul4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
496 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
497 bsr fps_mul4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
498 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
499 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
500 ldd fpaextra+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
501 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
502 ldd fpaextra+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
503 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
504 ldd fpaextra+7
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
505 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
506 ldd fpaextra+9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
507 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
508 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
509 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
510 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
511 std fpaextra+9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
512 ldd fpaextra+6
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
513 std fpaextra+7
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
514 ldd fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
515 std fpaextra+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
516 ldd fpaextra+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
517 sta fpaextra+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
518 ldd fpaextra
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
519 std fpaextra+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
520 clr fpaextra
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
521 rts
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
522 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
523 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
524 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
525 bne fps_mul7
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
526 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
527 bra fps_mul8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
528 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
529 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
530 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
531 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
532 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
533 ror fpaextra+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
534 ror fpaextra+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
535 ror fpaextra+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
536 ror fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
537 ror fpaextra+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
538 ror fpaextra+6
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
539 ror fpaextra+7
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
540 ror fpaextra+8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
541 ror fpaextra+9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
542 ror fpaextra+10
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
543 lsr fpaextra
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
544 ror fpaextra+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
545 ror fpaextra+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
546 ror fpaextra+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
547 ror fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
548 ror fpaextra+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
549 ror fpaextra+6
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
550 ror fpaextra+7
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
551 ror fpaextra+8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
552 ror fpaextra+9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
553 ror fpaextra+10
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
554 lsr fpaextra
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
555 ror fpaextra+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
556 ror fpaextra+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
557 ror fpaextra+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
558 ror fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
559 ror fpaextra+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
560 ror fpaextra+6
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
561 ror fpaextra+7
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
562 ror fpaextra+8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
563 ror fpaextra+9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
564 ror fpaextra+10
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
565 lsr fpaextra
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
566 ror fpaextra+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
567 ror fpaextra+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
568 ror fpaextra+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
569 ror fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
570 ror fpaextra+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
571 ror fpaextra+6
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
572 ror fpaextra+7
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
573 ror fpaextra+8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
574 ror fpaextra+9
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
575 ror fpaextra+10
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
576 rts
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
577 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
578 adda fpaextra+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
579 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
580 sta fpaextra+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
581 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
582 adca fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
583 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
584 sta fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
585 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
586 adca fpaextra+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
587 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
588 sta fpaextra+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
589 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
590 adca fpaextra+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
591 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
592 sta fpaextra+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
593 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
594 adca fpaextra+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
595 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
596 sta fpaextra+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
597 bcc fps_mul12
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
598 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
599 fps_mul12 rts
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
600 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
601 ; 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
602 ;
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
603 ; 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
604 ;
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
605 ; 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
606 ; 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
607 ;
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
608 ; 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
609 ;
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
610 ; 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
611 ; 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
612 ; 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
613 ; 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
614 ; 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
615 ; some bookkeeping.
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
616 ;
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
617 ; 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
618 ; subtraction steps.
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
619 ;
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
620 ; 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
621 ;
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
622 ; 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
623 ; 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
624 ; 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
625 ; 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
626 ; 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
627 ; 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
628 ; 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
629 ; 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
630 ; 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
631 ; 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
632 ; division loops.
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
633 ; 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
634 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
635 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
636 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
637 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
638 jmp ERROR
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
639 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
640 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
641 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
642 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
643 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
644 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
645 jmp fps_pack0
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
646 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
647 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
648 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
649 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
650 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
651 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
652 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
653 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
654 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
655 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
656 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
657 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
658 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
659 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
660 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
661 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
662 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
663 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
664 std fpaextra+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
665 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
666 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
667 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
668 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
669 ldd #0x9999
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
670 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
671 std fpaextra+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
672 lda #0x99
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
673 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
674 sta fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
675 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
676 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
677 bsr fps_div3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
678 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
679 bsr fps_div3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
680 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
681 bsr fps_div3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
682 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
683 bsr fps_div3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
684 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
685 bsr fps_div3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
686 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
687 bsr fps_div3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
688 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
689 bsr fps_div3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
690 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
691 bsr fps_div3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
692 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
693 bsr fps_div3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
694 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
695 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
696 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
697 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
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 lslb
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
701 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
702 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
703 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
704 fps_div4 rts
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
705 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
706 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
707 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
708 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
709 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
710 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
711 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
712 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
713 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
714 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
715 bhi fps_div8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
716 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
717 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
718 bhi fps_div8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
719 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
720 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
721 bhi fps_div8
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
722 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
723 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
724 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
725 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
726 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
727 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
728 rts
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
729 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
730 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
731 adca fpaextra+4
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
732 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
733 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
734 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
735 adca fpaextra+3
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
736 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
737 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
738 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
739 adca fpaextra+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
740 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
741 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
742 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
743 adca fpaextra+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
744 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
745 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
746 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
747 adca fpaextra
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
748 daa
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
749 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
750 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
751 adca #0x99
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
752 sta fpaextra+7
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
753 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
754 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
755 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
756 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
757 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
758 sta fpaextra+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
759 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
760 suba fpaextra+5
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
761 sta fpaextra+6
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
762 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
763 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
764 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
765 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
766 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
767 rol fpaextra+7
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
768 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
769 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
770 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
771 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
772 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
773 rol fpaextra+7
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
774 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
775 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
776 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
777 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
778 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
779 rol fpaextra+7
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
780 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
781 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
782 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
783 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
784 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
785 rol fpaextra+7
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
786 rts
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
787 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
788 ; 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
789
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
790 ; 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
791 ; 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
792 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
793 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
794 sta -1,u
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
795 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
796 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
797 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
798 jsr fps_unpack0
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
799 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
800 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
801 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
802 sta ,u
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
803 clr 1,u
80
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
804 rts
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
805 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
806 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
807 lda #'- ; negative sign
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
808 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
809 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
810 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
811 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
812 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
813 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
814 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
815 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
816 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
817 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
818 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
819 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
820 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
821 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
822 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
823 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
824 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
825 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
826 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
827 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
828 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
829 std ,u++
89
f519075cc164 Fix various issues with floating point number display
William Astle <lost@l-w.ca>
parents: 85
diff changeset
830 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
831 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
832 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
833 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
834 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
835 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
836 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
837 sta fpaextra+2
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
838 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
839 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
840 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
841 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
842 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
843 lsra
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
844 lsra
89
f519075cc164 Fix various issues with floating point number display
William Astle <lost@l-w.ca>
parents: 85
diff changeset
845 lsra
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
846 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
847 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
848 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
849 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
850 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
851 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
852 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
853 sta ,u+
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
854 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
855 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
856 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
857 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
858 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
859 beq fps_toascii13
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
860 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
861 sta ,u+
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
862 tstb ; negative?
96
69af7224f614 Tweak exponent calculation in fp to ascii conversion
William Astle <lost@l-w.ca>
parents: 92
diff changeset
863 bpl fps_toascii10 ; brif not
69af7224f614 Tweak exponent calculation in fp to ascii conversion
William Astle <lost@l-w.ca>
parents: 92
diff changeset
864 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
865 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
866 sta ,u+
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
867 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
868 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
869 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
870 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
871 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
872 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
873 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
874 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
875 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
876 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
877 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
878 rts
85
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
879 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
880 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
881 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
882 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
883 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
884 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
885 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
886 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
887 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
888 stb fpaextra+1
663d8e77b579 Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents: 83
diff changeset
889 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
890 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
891 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
892 ; 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
893 ; 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
894 ; 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
895 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
896 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
897 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
898 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
899 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
900 subd val.int+2,x
105
65cb0a0297b3 Make integer to floating point conversion use extra bits in fp accumulator
William Astle <lost@l-w.ca>
parents: 104
diff changeset
901 std fpa0+fpa.extra+2
98
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
902 ldd zero
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
903 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
904 sbca val.int,x
105
65cb0a0297b3 Make integer to floating point conversion use extra bits in fp accumulator
William Astle <lost@l-w.ca>
parents: 104
diff changeset
905 std fpa0+fpa.extra
98
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
906 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
907 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
908 ldd val.int+2,x ; copy value to temporary accumulator
105
65cb0a0297b3 Make integer to floating point conversion use extra bits in fp accumulator
William Astle <lost@l-w.ca>
parents: 104
diff changeset
909 std fpa0+fpa.extra+2
98
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
910 ldd val.int,x
105
65cb0a0297b3 Make integer to floating point conversion use extra bits in fp accumulator
William Astle <lost@l-w.ca>
parents: 104
diff changeset
911 std fpa0+fpa.extra
100
6db72a92ff7a Make value accumulator descriptions consistent and make usage consistent
William Astle <lost@l-w.ca>
parents: 99
diff changeset
912 fps_fromint0 ldd zero ; zero out destination
98
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
107
1f2f6c2a1fde Use correct decimal exponent instead of binary for int to float conversion
William Astle <lost@l-w.ca>
parents: 106
diff changeset
916 ldd #0x4920 ; set exponent for decimal right of 10 digit significand
98
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
105
65cb0a0297b3 Make integer to floating point conversion use extra bits in fp accumulator
William Astle <lost@l-w.ca>
parents: 104
diff changeset
918 stb fpa0+fpa.extra+4 ; save counter
98
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
105
65cb0a0297b3 Make integer to floating point conversion use extra bits in fp accumulator
William Astle <lost@l-w.ca>
parents: 104
diff changeset
926 fps_fromint2 lsl fpa0+fpa.extra+3 ; shift left
65cb0a0297b3 Make integer to floating point conversion use extra bits in fp accumulator
William Astle <lost@l-w.ca>
parents: 104
diff changeset
927 rol fpa0+fpa.extra+2
65cb0a0297b3 Make integer to floating point conversion use extra bits in fp accumulator
William Astle <lost@l-w.ca>
parents: 104
diff changeset
928 rol fpa0+fpa.extra+1
65cb0a0297b3 Make integer to floating point conversion use extra bits in fp accumulator
William Astle <lost@l-w.ca>
parents: 104
diff changeset
929 rol fpa0+fpa.extra
98
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
105
65cb0a0297b3 Make integer to floating point conversion use extra bits in fp accumulator
William Astle <lost@l-w.ca>
parents: 104
diff changeset
935 dec fpa0+fpa.extra+4 ; done all digits?
98
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 lda #valtype_float ; set result type to floating point
106
1396fe221ff7 Set value type in correct location for int to float conversion
William Astle <lost@l-w.ca>
parents: 105
diff changeset
938 sta val.type,x
100
6db72a92ff7a Make value accumulator descriptions consistent and make usage consistent
William Astle <lost@l-w.ca>
parents: 99
diff changeset
939 jsr fps_normalizea0 ; go normalize fpa0
6db72a92ff7a Make value accumulator descriptions consistent and make usage consistent
William Astle <lost@l-w.ca>
parents: 99
diff changeset
940 jmp fps_pack0 ; pack the result to the original accumulator
98
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
941 ; 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
942 ; 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
943 ; 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
944 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
945 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
946 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
947 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
948 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
949 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
950 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
951 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
952 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
953 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
954 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
955 rts
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
956 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
957 ; 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
958 ; if the magnitude is too large and it will truncate (round toward zero) any fractional value.
100
6db72a92ff7a Make value accumulator descriptions consistent and make usage consistent
William Astle <lost@l-w.ca>
parents: 99
diff changeset
959 fps_toint jsr fps_unpack0 ; unpack the floating point value to fpa0
98
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
960 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
961 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
962 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
963 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
964 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
965 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
966 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
967 rts
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
968 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
969 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
970 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
971 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
972 cmpd #0x2147
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
973 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
974 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
975 cmpd #0x4836
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
976 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
977 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
978 cmpd #0x4800
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
979 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
980 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
981 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
982 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
983 ; 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
984 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
985 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
986 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
987 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
988 lslb
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
989 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
990 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
991 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
992 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
993 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
994 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
995 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
996 ; 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
997 fps_toint3 ldb #32 ; 32 bit shifts needed for whole significand
99
4d7fa11ebe3f Fix error in float to int and clean up some code
William Astle <lost@l-w.ca>
parents: 98
diff changeset
998 stb fpa0+fpa.exp ; use extra precision byte as counter
98
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
999 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
1000 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
1001 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
1002 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
1003 ror fpa0+fpa.sig+4
99
4d7fa11ebe3f Fix error in float to int and clean up some code
William Astle <lost@l-w.ca>
parents: 98
diff changeset
1004 ror fpa0+fpa.extra
98
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1005 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
1006 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
1007 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
1008 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
1009 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
1010 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
1011 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
1012 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
1013 lsra
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1014 lsra
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1015 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
1016 mul
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1017 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
1018 addb ,u
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1019 stb ,u+
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1020 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
1021 blo fps_toint5 ; brif not
99
4d7fa11ebe3f Fix error in float to int and clean up some code
William Astle <lost@l-w.ca>
parents: 98
diff changeset
1022 dec fpa0+fpa.exp ; done all bits?
4d7fa11ebe3f Fix error in float to int and clean up some code
William Astle <lost@l-w.ca>
parents: 98
diff changeset
1023 bne fps_toint4 ; brif not
98
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1024 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
1025 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
1026 ldd zero ; negate the value through subtracting from 0
99
4d7fa11ebe3f Fix error in float to int and clean up some code
William Astle <lost@l-w.ca>
parents: 98
diff changeset
1027 subd fpa0+fpa.extra+2
4d7fa11ebe3f Fix error in float to int and clean up some code
William Astle <lost@l-w.ca>
parents: 98
diff changeset
1028 std fpa0+fpa.extra+2
98
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1029 ldd zero
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1030 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
1031 sbca fpa0+fpa.extra
99
4d7fa11ebe3f Fix error in float to int and clean up some code
William Astle <lost@l-w.ca>
parents: 98
diff changeset
1032 std fpa0+fpa.extra
4d7fa11ebe3f Fix error in float to int and clean up some code
William Astle <lost@l-w.ca>
parents: 98
diff changeset
1033 fps_toint7 ldd fpa0+fpa.extra ; put result in the significand
98
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1034 std fpa0+fpa.sig+1
99
4d7fa11ebe3f Fix error in float to int and clean up some code
William Astle <lost@l-w.ca>
parents: 98
diff changeset
1035 ldd fpa0+fpa.extra+2
98
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1036 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
1037 rts
6837d10b67fb Add integer <-> float conversion routines and combine some code for parsing
William Astle <lost@l-w.ca>
parents: 96
diff changeset
1038 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
1039 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
1040 *pragmapop list