annotate src/fps.s @ 80:bb50ac9fdf37

Checkpoint with very basic integer and floating point arithmetic, untested This commit has implementations for floating point add, subtract, multiply, and divide, along with 32 bit signed integer equivalents. These can probably be optimized and they are untested.
author William Astle <lost@l-w.ca>
date Sat, 07 Oct 2023 02:56:59 -0600
parents
children 9a4e2364a966
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 ;
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
6 ; Floating point values are stored in 6 byte packets (single precision) organized as follows:
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
7 ; Offset Length Contents
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
8 ; 0 1 8 bit binary exponent with a bias of 128; 0 means the number is 0
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
9 ; 1 4 32 bit significand
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
10 ; 5 1 sign flag; zero for positive, 0xff for negative
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
11 ;
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
12 ; Binary operateions take pointers to their arguments in X and U. Y contains the result location. In all cases, it is
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
13 ; safe to specify either one of the arguments as the result location. Unary operations take their operand pointer in
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
14 ; X and their result pointer in Y. In all cases, there is an in place version of the unary operation that operates on
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
15 ; its input and only needs the single pointer in X.
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
16 ;
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
17 ; On the topic of optimization: these routines copy their operands to accumulators in the direct page. This saves one
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
18 ; cycle per instruction which has a nonzero offset. In addition, this means that the input operands can remain
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
19 ; unmodified by the actual operations. For instance, addition requires denormalizing one operand which would otherwise
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
20 ; have to be done in place.
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
21 ;
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
22 ; NOTE: the input pointers X and U may be clobbered.
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
24 ; Convert 32 bit unsigned integer at (X) to single precision floating point at (U)
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
25 fps_fromuint32 clr fpa0+fps.sign ; set result sign to positive
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
26 bra fps_fromint32a ; go do conversion
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
27 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
28 ; Convert 32 bit signed integer at (X) to single precision floating point at value accumulator in (Y)
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
29 fps_fromint32 ldb ,x ; set sign based on signed integer
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
30 sex
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
31 sta fpa0+fps.sign ; set result sign to the two's complement sign
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
32 bpl fps_fromint32a ; brif positive - no need to mess with bits
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
33 jsr int32_neg ; make the bits positive
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
34 fps_fromint32a ldb valtype_float ; set output value type to floating point
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
35 stb val.type,y
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
36 ldd ,x ; copy integer bits to fpa0
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
37 std fpa0+fps.sig
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
38 ldd 2,x
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
39 std fpa0+fps.sig+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
40 ldb #0xa0 ; put binary point to the right of the significand
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
41 stb fpa0+fps.exp
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
42 clr fpa0extra ; clear extra precision
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
43 jmp fps_add10 ; go normalize the result and return
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
44 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
45 ; Unary negation - negate (X) to (Y)
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
46 fps_neg ldd 2,x ; copy to output and keep exponent in A
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
47 std 2,y
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
48 ldd 4,x
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
49 std 4,y
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
50 ldd ,x
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
51 std ,y
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
52 tsta ; is the number zero?
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
53 beq fps_neg0 ; brif so - do nothing
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
54 com fps.sign,y ; flip the sign
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
55 fps_neg0 rts
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
56 fps_negx lda fps.exp,x ; is the number zero?
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
57 beq fps_negx0 ; brif so - do nothing
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
58 com fps.sign,x ; flip the sign
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
59 fps_negx0 rts
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
60 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
61 ; Copy (X) to fpa0 and (U) to fpa1
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
62 fps_copyinputs ldd ,x ; copy (X) to fpa0
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
63 std fpa0
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
64 ldd 2,x
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
65 std fpa0+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
66 ldd 4,x
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
67 std fpa0+4
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
68 ldd ,u ; copy (U) to fpa0
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
69 std fpa1
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
70 ldd 2,u
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
71 std fpa1+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
72 ldd 4,u
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
73 std fpa1+4
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
74 rts
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
75 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
76 ; Subtraction (X) - (U) to (Y)
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
77 fps_sub bsr fps_copyinputs ; copy input operands
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
78 com fpa1+fps.sign ; negate the subtrahend (don't need to handle zero here)
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
79 bra fps_add0 ; go handle it as addition
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
80 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
81 ; Addition (X) + (U) to (Y)
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
82 fps_add bsr fps_copyinputs ; copy input operands
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
83 fps_add0 lda fpa1+fps.exp ; is the second operand 0?
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
84 bne fps_add1 ; brif not
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
85 ldd fpa0 ; copy first operand to output
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
86 std ,y
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
87 ldd fpa0+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
88 std 2,y
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
89 ldd fpa0+4
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
90 std 4,y
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
91 rts
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
92 fps_add1 lda fpa0+fps.exp ; get exponent of first operand
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
93 bne fps_add2 ; brif not zero
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
94 ldd fpa1 ; copy second operand to output
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
95 std ,y
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
96 ldd fpa1+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
97 std 2,y
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
98 ldd fpa1+4
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
99 std 4,y
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
100 rts
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
101 fps_add2 clr fpa0extra ; clear extra precision bits
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
102 lda fpa0+fps.exp ; get first operand exponent
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
103 suba fpa1+fps.exp ; get difference in exponents
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
104 beq fps_add8 ; brif we don't need to denormalize - they're the same
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
105 blo fps_add3 ; brif we need to denormalize the first operand
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
106 ldx #fpa1 ; point to second operand to denormalize
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
107 bra fps_add4 ; go denormalize
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
108 fps_add3 ldb fpa1+fps.exp ; get exponent of second operand (result exponent)
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
109 stb fpa0+fps.exp ; set result exponent
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
110 ldx #fpa0 ; point to first operand to denormalize
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
111 nega ; get number of bits to shift as positive number
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
112 fps_add4 suba #8 ; is there 8 bits left?
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
113 blo fps_add5 ; brif not
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
114 ldb fps.sig+3,x ; shift significand 8 bits right
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
115 stb fpa0extra ; save extra precision bits
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
116 ldb fps.sig+2,x
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
117 stb fps.sig+3,x
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
118 ldb fps.sig+1,x
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
119 stb fps.sig+2,x
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
120 ldb fps.sig,x
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
121 stb fps.sig+1,x
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
122 clr fps.sig,x
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
123 bra fps_add4 ; see if we have another byte to shift
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
124 fps_add5 adda #8 ; adjust for extra subtract above
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
125 bra fps_add7 ; do the bit shifting
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
126 fps_add6 lsr fps.sig,x ; shift one bit right
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
127 ror fps.sig+1,x
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
128 ror fps.sig+2,x
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
129 ror fps.sig+3,x
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
130 ror fpa0extra
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
131 deca ; done all of the bits?
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
132 fps_add7 bne fps_add6 ; brif not
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
133 fps_add8 lda fpa0+fps.sign ; compare the signs of the operands
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
134 eora fpa1+fps.sign ; set A if signs differ
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
135 bne fps_add9 ; brif they differ - do subtraction
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
136 ldd fpa0+fps.sig+2 ; add low word of significands
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
137 addd fpa1+fps.sig+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
138 std fpa0+fps.sig+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
139 ldd fpa0+fps.sig ; and the high word
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
140 adcb fpa1+fps.sig+1
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
141 adca fpa1+fps.sig
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
142 std fpa0+fps.sig
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
143 bcc fps_add9 ; brif no carry
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
144 ror fpa0+fps.sig ; shift carry into significand
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
145 ror fpa0+fps.sig+1
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
146 ror fpa0+fps.sig+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
147 ror fpa0+fps.sig+3
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
148 ror fpa0extra ; and the extra bits (for rounding)
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
149 inc fpa0+fps.exp ; bump exponent to account for bit shift
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
150 bne fps_add14 ; go check for round-off if not overflow
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
151 OVERROR ldb #err_ov ; raise overflow
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
152 jmp ERROR
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
153 fps_add9 ldd fpa0+fps.sig+2 ; subtract low word
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
154 subd fpa1+fps.sig+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
155 std fpa0+fps.sig+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
156 ldd fpa0+fps.sig ; and now the high word
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
157 sbcb fpa1+fps.sig+1
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
158 sbca fpa1+fps.sig
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
159 std fpa0+fps.sig
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
160 bcc fps_add10 ; brif we didn't carry
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
161 com fpa0+fps.sign ; flip result sign - other number was bigger
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
162 com fpa0+fps.sig+3 ; negate two's complement result to be just the magnitude
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
163 com fpa0+fps.sig+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
164 com fpa0+fps.sig+1
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
165 com fpa0+fps.sig
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
166 ldx fpa0+fps.sig+2 ; add 1 to complete negation
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
167 leax 1,x
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
168 stx fpa0+fps.sig+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
169 bne fps_add10 ; brif carry doesn't propagate
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
170 ldx fpa0+fps.sig ; propagate carry
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
171 leax 1,x
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
172 stx fpa0+fps.sig ; NOTE: this cannot carry because magnitude got smaller
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
173 fps_add10 clra ; initialize exponent offset
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
174 fps_add11 ldb fpa0+fps.sig ; do we have nonzero bits in high byte of significand?
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
175 bne fps_add13 ; brif so
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
176 ldb fpa0+fps.sig+1 ; shift left 8 bits
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
177 stb fpa0+fps.sig
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
178 ldb fpa0+fps.sig+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
179 stb fpa0+fps.sig+1
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
180 ldb fpa0+fps.sig+3
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
181 stb fpa0+fps.sig+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
182 ldb fpa0extra ; and extra precision bits
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
183 stb fpa0+fps.sig+3
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
184 clr fpa0extra
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
185 addb #8 ; account for number of bits shifted
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
186 cmpb #40 ; done 40 bits?
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
187 blo fps_add11 ; brif not - see if we have more bits to shift
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
188 clr fpa0+fps.exp ; number underflowed to zero - set it so
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
189 clr fpa0+fps.sign
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
190 clr fpa0+fps.sig
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
191 clr fpa0+fps.sig+1
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
192 clr fpa0+fps.sig+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
193 clr fpa0+fps.sig+3
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
194 bra fps_add16 ; go return result
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
195 fps_add12 inca ; account for a bit shift
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
196 lsl fpa0extra ; shift significand and extra bits left
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
197 rol fpa0+fps.sig+3
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
198 rol fpa0+fps.sig+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
199 rol fpa0+fps.sig+1
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
200 rol fpa0+fps.sig
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
201 fps_add13 bpl fps_add12 ; brif we haven't normalized yet
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
202 fps_add14 ldb fpa0extra ; do we need to round?
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
203 bpl fps_add16 ; brif not
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
204 ldx fpa0+fps.sig+2 ; add one to significand
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
205 leax 1,x
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
206 stx fpa0+fps.sig+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
207 bne fps_add16 ; brif no carry
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
208 ldx fpa0+fps.sig ; bump the upper word of significand
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
209 leax 1,x
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
210 stx fpa0+fps.sig
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
211 bne fps_add16
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
212 fps_add15 inc fpa0+fps.exp ; bump exponent
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
213 beq OVERROR ; brif it overflowed
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
214 lda #0x80 ; set high bit of significand (rest is zero)
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
215 sta fpa0+fps.sig
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
216 fps_add16 ldd fpa0 ; copy result to destination
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
217 std ,y
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
218 ldd fpa0+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
219 std 2,y
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
220 ldd fpa0+4
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
221 std 4,y
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
222 rts
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
223 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
224 ; Single precision multiplication (X) × (U) to (Y)
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
225 fps_mul lda fps.exp,x ; is first operand zero?
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
226 beq fps_mul0 ; brif so - return zero
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
227 lda fps.exp,u ; is second operand zero?
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
228 bne fps_mul1 ; brif not - have to do the multiply
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
229 fps_mul0 ldd zero ; return zero result
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
230 std ,y
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
231 std 2,y
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
232 std 4,y
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
233 rts
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
234 fps_mul1 jsr fps_copyinputs ; copy input operands
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
235 lda fpa0+fps.sign ; calculate sign of result - xor of the two signs
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
236 eora fpa1+fps.sign
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
237 sta fpa0+fps.sign ; save result sign
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
238 lda fpa0+fps.exp ; get exponent of first value
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
239 adda fpa1+fps.exp ; calculate new exponent; also cancels the bias
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
240 rora ; set V if C and N differ
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
241 rola
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
242 bvc fps_mul3 ; brif maybe an overflow
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
243 adda #0x80 ; add back the bias
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
244 sta fpa0+fps.sign ; save new sign
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
245 beq fps_mul0 ; brif we underflowed - zero out sign
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
246 ; This does a shift-and-add multiplication algorithm. This is slower than an equivalent using MUL but is smaller.
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
247 ; The high order bytes will be left in fpa0 with the low order bytes in fpa0extra and fpa0extra[1-3]. The low order
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
248 ; bytes are kept for the odd case where extra precision is useful. Uses fpa0extra[4-7] as temporaries.
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
249 fps_mul2 ldd zero ; zero out temporary bytes
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
250 std fpa0extra4
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
251 std fpa0extra6
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
252 ldb fpa0+fps.sig+3 ; multiply by low byte of fpa0
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
253 bsr fps_mul4
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
254 ldb fpa0extra ; move low bites
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
255 stb fpa0extra3
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
256 ldb fpa0+fps.sig+2 ; multiply by next higher byte
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
257 bsr fps_mul4
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
258 ldb fpa0extra ; move low bits
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
259 stb fpa0extra2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
260 ldb fpa0+fps.sig+1 ; and again for the next higher byte
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
261 bsr fps_mul4
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
262 ldb fpa0extra
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
263 stb fpa0extra1
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
264 ldb fpa0+fps.sig ; and the high order byte
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
265 bsr fps_mul4
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
266 ldd fpa0extra4 ; copy high order product bits to result
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
267 std fpa0+fps.sig
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
268 ldd fpa0extra6
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
269 std fpa0+fps.sig+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
270 jmp fps_add10 ; go normalize the result and return
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
271 fps_mul3 bpl fps_mul0 ; brif we underflowed - return 0
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
272 jmp OVERROR ; raise overflow
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
273 fps_mul4 bne fps_mul5 ; brif not multiply by zero
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
274 lda fpa0+fps.sig+3 ; shift 8 bits right
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
275 sta fpa0extra
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
276 lda fpa0+fps.sig+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
277 sta fpa0+fps.sig+3
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
278 lda fpa0+fps.sig+1
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
279 sta fpa0+fps.sig+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
280 lda fpa0+fps.sig
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
281 sta fpa0+fps.sig+1
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
282 clr fpa0+fps.sig
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
283 fps_mul8 rts
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
284 fps_mul5 coma ; set C
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
285 fps_mul6 lda fpa0extra4 ; get high byte of result bytes
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
286 rorb ; is multiplier bit set?
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
287 beq fps_mul8 ; brif 8 shifts done (C set above makes sure of that)
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
288 bcc fps_mul7 ; brif bit not set - don't do addition
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
289 lda fpa0extra7 ; add multiplier (fpa1) to result
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
290 adda fpa1+fps.sig+3
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
291 sta fpa0extra7
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
292 lda fpa0extra6
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
293 adca fpa1+fps.sig+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
294 sta fpa0extra6
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
295 lda fpa0extra5
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
296 adca fpa1+fps.sig+1
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
297 sta fpa0extra5
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
298 lda fpa0extra4
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
299 adca fpa1+fps.sig
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
300 fps_mul7 rora ; rotate carry in (from add or 0)
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
301 sta fpa0extra4
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
302 ror fpa0extra5
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
303 ror fpa0extra6
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
304 ror fpa0extra7
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
305 ror fpa0extra ; and into the extra precision bits
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
306 clra ; clear carry - so shift above will terminate
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
307 bra fps_mul6 ; go do another bit
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
308 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
309 ; Single precision division (X) ÷ (U) -> (Y)
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
310 ;
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
311 ; This is basically the same algorithm used in the Color Basic ROM
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
312 fps_div lda fps.exp,u ; is divisor 0?
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
313 bne fps_div0
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
314 DIV0ERROR ldb #err_div0 ; raise division by zero
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
315 jmp ERROR
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
316 fps_div0 lda fps.exp,x ; is dividend 0?
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
317 lbeq fps_mul0 ; brif so - return 0
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
318 jsr fps_copyinputs ; copy input values
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
319 lda fpa0+fps.sign ; calculate result sign - xor of operand signs
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
320 eora fpa1+fps.sign
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
321 sta fpa0+fps.sign ; save result sign
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
322 lda fpa1+fps.exp ; get divisor exponent
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
323 nega ; negate for subtraction
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
324 adda fpa0+fps.exp ; subtract it from dividend exponent
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
325 rora ; set V if C and N differ
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
326 rola
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
327 bvc fps_mul3 ; brif overflow or underflow
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
328 adda #0x80 ; add back the bias
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
329 sta fpa0+fps.sign ; save new sign
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
330 lbeq fps_mul0 ; brif we underflowed - zero out sign
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
331 inca ; bump exponent - why?? related to the bias stuff above?
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
332 lbeq OVERROR ; brif it overflows
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
333 sta fpa0+fps.exp ; save result exponent
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
334 ldx #fpa0extra4 ; point to temporary storage bytes for quotient
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
335 ldb #4 ; counter for 4 significand bytes and one extra partial byte
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
336 stb fpa0extra1 ; save counter since we need both accumulators
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
337 ldb #1 ; shift counter flag and quotient byte
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
338 fps_div1 lda fpa1+fps.sig ; set C if fpa0 significand <= fpa1 significand
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
339 cmpa fpa0+fps.sig
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
340 bne fps_div2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
341 lda fpa1+fps.sig+1
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
342 cmpa fpa0+fps.sig+1
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
343 bne fps_div2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
344 lda fpa1+fps.sig+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
345 cmpa fpa0+fps.sig+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
346 bne fps_div2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
347 lda fpa1+fps.sig+3
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
348 cmpa fpa0+fps.sig+3
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
349 bne fps_div2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
350 coma ; set C if values are the same
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
351 fps_div2 tfr cc,a ; save C for later, C clear if fpa1 > fpa0
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
352 rolb ; shift carry into quotient
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
353 bcc fps_div3 ; brif carry clear - we haven't done 8 bits yet
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
354 stb ,x+ ; save quotient byte after a full set of bits
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
355 dec fpa0extra1 ; have we done all the bytes?
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
356 bmi fps_div7 ; brif all bytes plus extra precision - done all
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
357 beq fps_div6 ; brif all main sigificand bytes - do a couple extra bits
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
358 ldb #1 ; reset the bit counter flag
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
359 fps_div3 tfr cc,a ; get back original carry from compare
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
360 bcs fps_div5 ; brif it "went"
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
361 fps_div4 lsl fpa0+fps.sig+3 ; shift dividend left
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
362 rol fpa0+fps.sig+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
363 rol fpa0+fps.sig+1
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
364 rol fpa0+fps.sig
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
365 bcs fps_div2 ; brif it carries - next bit "goes"
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
366 bmi fps_div1 ; check magnitudes of next bit
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
367 bra fps_div2 ; carry clear - check another bit
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
368 fps_div5 lda fpa0+fps.sig+3 ; subtract divisor from dividend bits
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
369 suba fpa1+fps.sig+3
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
370 sta fpa0+fps.sig+3
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
371 lda fpa0+fps.sig+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
372 sbca fpa1+fps.sig+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
373 sta fpa0+fps.sig+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
374 lda fpa0+fps.sig+1
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
375 sbca fpa1+fps.sig+1
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
376 sta fpa0+fps.sig+1
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
377 lda fpa0+fps.sig
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
378 sbca fpa1+fps.sig
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
379 sta fpa0+fps.sig
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
380 bra fps_div4 ; now do the bit shift to line things up
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
381 fps_div6 ldb #0x40 ; only do two bits of extra precision byte
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
382 bra fps_div2 ; go handle these bitsd
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
383 fps_div7 rorb ; get extra quotient bits to bit 7,6 and bit 5 set
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
384 rorb
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
385 rorb
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
386 stb fpa0extra ; save extra precision bits
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
387 ldd fpa0extra4 ; copy result bits to fpa0
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
388 std fpa0+fps.sig
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
389 ldd fpa0extra6
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
390 std fpa0+fps.sig+2
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
391 jmp fps_add10 ; go normalize the result
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
392 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
393 ; Pack single precision number at (X) to (U)
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
394 fps_pack lda fps.sign,x ; get sign of number (will be 0 for 0)
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
395 ora #0x7f ; make sure low bits are set for merging
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
396 anda fps.sig,x ; merge with high bits of significand
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
397 ldb fps.sig+1,x ; get upper mid bits of significand
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
398 std fps.sig,u
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
399 ldd fps.sig+2,x
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
400 std fps.sig+2,u
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
401 lda fps.exp,x
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
402 sta fps.exp,u
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
403 rts
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
404 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
405 ; Unpack single precision number at (X) to (U)
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
406 fps_unpack lda fps.exp,x ; get exponent of value
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
407 beq fps_unpack0 ; brif value is zero
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
408 sta fps.exp,u
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
409 ldb fps.sig,x ; get high byte of significand
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
410 sex ; make sign value in A
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
411 sta fps.sign,u ; set sign in result
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
412 ldd fps.sig,x ; get high word of sifnificand
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
413 ora #0x80 ; make sure high bit is set
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
414 std fps.sig,u ; save high word in result
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
415 ldd fps.sig+2,x ; copy middle bytes of significand
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
416 std fps.sig+2,u
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
417 rts
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
418 fps_unpack0 sta fps.exp,u ; zero out destination
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
419 sta fps.sig,u
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
420 sta fps.sig+1,u
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
421 sta fps.sig+2,u
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
422 sta fps.sig+3,u
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
423 sta fps.sign,u
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
424 rts
bb50ac9fdf37 Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff changeset
425 *pragmapop list