Mercurial > hg > index.cgi
annotate src/fps-bin.s @ 85:663d8e77b579
Implmement BCD floating point and update number parsing and printing
Implements a BCD floating point system with 10 decimal digits of precistion
and an exponent range of -63 to +63. Also include parsing integer and
floating point values and printing them out.
author | William Astle <lost@l-w.ca> |
---|---|
date | Sun, 15 Oct 2023 22:15:36 -0600 |
parents | src/fps.s@a492441bfc56 |
children |
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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
82
9a4e2364a966
Fix logic in int32_mul and overflow integer multiply to floating point
William Astle <lost@l-w.ca>
parents:
80
diff
changeset
|
45 ; Convert 64 bit unsigned value at (X) to single precision floating point in value accumulator at (Y) |
9a4e2364a966
Fix logic in int32_mul and overflow integer multiply to floating point
William Astle <lost@l-w.ca>
parents:
80
diff
changeset
|
46 ; |
9a4e2364a966
Fix logic in int32_mul and overflow integer multiply to floating point
William Astle <lost@l-w.ca>
parents:
80
diff
changeset
|
47 ; Cases: |
9a4e2364a966
Fix logic in int32_mul and overflow integer multiply to floating point
William Astle <lost@l-w.ca>
parents:
80
diff
changeset
|
48 ; * byte 0 is first nonzero - exponent at 64 bits right, use upper 0 to 4 |
9a4e2364a966
Fix logic in int32_mul and overflow integer multiply to floating point
William Astle <lost@l-w.ca>
parents:
80
diff
changeset
|
49 ; * byte 1 is first nonzero - exponent at 56 bits right, use bytes 1 to 5 |
9a4e2364a966
Fix logic in int32_mul and overflow integer multiply to floating point
William Astle <lost@l-w.ca>
parents:
80
diff
changeset
|
50 ; * byte 2 is first nonzero - exponent at 48 bits right, use bytes 2 to 6 |
9a4e2364a966
Fix logic in int32_mul and overflow integer multiply to floating point
William Astle <lost@l-w.ca>
parents:
80
diff
changeset
|
51 ; * otherwise - exponent at 40 bits right, use bytes 3 to 7 |
9a4e2364a966
Fix logic in int32_mul and overflow integer multiply to floating point
William Astle <lost@l-w.ca>
parents:
80
diff
changeset
|
52 fps_fromuint64 clra ; set sign to positive |
9a4e2364a966
Fix logic in int32_mul and overflow integer multiply to floating point
William Astle <lost@l-w.ca>
parents:
80
diff
changeset
|
53 fps_fromuint64s sta fpa0+fps.sign ; save sign of result |
9a4e2364a966
Fix logic in int32_mul and overflow integer multiply to floating point
William Astle <lost@l-w.ca>
parents:
80
diff
changeset
|
54 ldb #0xc0 ; exponent if binary point is 64 bits to the right |
9a4e2364a966
Fix logic in int32_mul and overflow integer multiply to floating point
William Astle <lost@l-w.ca>
parents:
80
diff
changeset
|
55 lda ,x+ ; is the first byte zero? |
9a4e2364a966
Fix logic in int32_mul and overflow integer multiply to floating point
William Astle <lost@l-w.ca>
parents:
80
diff
changeset
|
56 bne fps_fromuint64a ; brif not |
9a4e2364a966
Fix logic in int32_mul and overflow integer multiply to floating point
William Astle <lost@l-w.ca>
parents:
80
diff
changeset
|
57 subb #8 ; lose a byte off exponent |
9a4e2364a966
Fix logic in int32_mul and overflow integer multiply to floating point
William Astle <lost@l-w.ca>
parents:
80
diff
changeset
|
58 lda ,x+ ; is the second byte zero? |
9a4e2364a966
Fix logic in int32_mul and overflow integer multiply to floating point
William Astle <lost@l-w.ca>
parents:
80
diff
changeset
|
59 bne fps_fromuint64a ; brif not |
9a4e2364a966
Fix logic in int32_mul and overflow integer multiply to floating point
William Astle <lost@l-w.ca>
parents:
80
diff
changeset
|
60 subb #8 ; lose another byte off exponent |
9a4e2364a966
Fix logic in int32_mul and overflow integer multiply to floating point
William Astle <lost@l-w.ca>
parents:
80
diff
changeset
|
61 lda ,x+ ; is third byte zero? |
9a4e2364a966
Fix logic in int32_mul and overflow integer multiply to floating point
William Astle <lost@l-w.ca>
parents:
80
diff
changeset
|
62 bne fps_fromuint64a ; brif not |
9a4e2364a966
Fix logic in int32_mul and overflow integer multiply to floating point
William Astle <lost@l-w.ca>
parents:
80
diff
changeset
|
63 subb #8 ; lose another byte |
9a4e2364a966
Fix logic in int32_mul and overflow integer multiply to floating point
William Astle <lost@l-w.ca>
parents:
80
diff
changeset
|
64 lda ,x+ ; get first byte to copy |
9a4e2364a966
Fix logic in int32_mul and overflow integer multiply to floating point
William Astle <lost@l-w.ca>
parents:
80
diff
changeset
|
65 fps_fromuint64a stb fpa0+fps.exp ; save exponent |
9a4e2364a966
Fix logic in int32_mul and overflow integer multiply to floating point
William Astle <lost@l-w.ca>
parents:
80
diff
changeset
|
66 sta fpa0+fps.sig ; save high byte of significand |
9a4e2364a966
Fix logic in int32_mul and overflow integer multiply to floating point
William Astle <lost@l-w.ca>
parents:
80
diff
changeset
|
67 ldd ,x ; copy next two bytes to significand |
9a4e2364a966
Fix logic in int32_mul and overflow integer multiply to floating point
William Astle <lost@l-w.ca>
parents:
80
diff
changeset
|
68 std fpa0+fps.sig+1 |
9a4e2364a966
Fix logic in int32_mul and overflow integer multiply to floating point
William Astle <lost@l-w.ca>
parents:
80
diff
changeset
|
69 ldd 2,x ; and the final byte and extra precision |
9a4e2364a966
Fix logic in int32_mul and overflow integer multiply to floating point
William Astle <lost@l-w.ca>
parents:
80
diff
changeset
|
70 sta fpa0+fps.sig+3 |
9a4e2364a966
Fix logic in int32_mul and overflow integer multiply to floating point
William Astle <lost@l-w.ca>
parents:
80
diff
changeset
|
71 stb fpa0extra |
9a4e2364a966
Fix logic in int32_mul and overflow integer multiply to floating point
William Astle <lost@l-w.ca>
parents:
80
diff
changeset
|
72 jmp fps_add10 ; go normalize the result and return |
9a4e2364a966
Fix logic in int32_mul and overflow integer multiply to floating point
William Astle <lost@l-w.ca>
parents:
80
diff
changeset
|
73 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
83
a492441bfc56
Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents:
82
diff
changeset
|
74 ; Fast multiply (X) by 10, in place. |
a492441bfc56
Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents:
82
diff
changeset
|
75 ; |
a492441bfc56
Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents:
82
diff
changeset
|
76 ; * first, save original value |
a492441bfc56
Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents:
82
diff
changeset
|
77 ; * then, shift left by 2 bits (add 2 to exponent) |
a492441bfc56
Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents:
82
diff
changeset
|
78 ; * then, add original value |
a492441bfc56
Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents:
82
diff
changeset
|
79 ; * then, shift left one more (add 1 to exponent) |
a492441bfc56
Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents:
82
diff
changeset
|
80 ; |
a492441bfc56
Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents:
82
diff
changeset
|
81 ; This should be faster than multiplying by 10. |
a492441bfc56
Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents:
82
diff
changeset
|
82 fps_mul10 leas -fps.size,s ; make a temporary to hold original value |
a492441bfc56
Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents:
82
diff
changeset
|
83 ldd ,x ; copy original value |
a492441bfc56
Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents:
82
diff
changeset
|
84 std ,s |
a492441bfc56
Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents:
82
diff
changeset
|
85 ldd 2,x |
a492441bfc56
Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents:
82
diff
changeset
|
86 std 2,s |
a492441bfc56
Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents:
82
diff
changeset
|
87 ldd 4,x |
a492441bfc56
Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents:
82
diff
changeset
|
88 std 4,s |
a492441bfc56
Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents:
82
diff
changeset
|
89 lda fps.exp,x ; bump original exponent by 2 (times 4) |
a492441bfc56
Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents:
82
diff
changeset
|
90 adda #2 |
a492441bfc56
Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents:
82
diff
changeset
|
91 bcc fps_mul10b ; brif it overflowed |
a492441bfc56
Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents:
82
diff
changeset
|
92 fps_mul10a jmp OVERROR ; raise overflow |
a492441bfc56
Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents:
82
diff
changeset
|
93 fps_mul10b sta fps.exp,x |
a492441bfc56
Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents:
82
diff
changeset
|
94 leay ,x |
a492441bfc56
Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents:
82
diff
changeset
|
95 leau ,s |
a492441bfc56
Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents:
82
diff
changeset
|
96 bsr fps_add ; add original value (times 5) |
a492441bfc56
Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents:
82
diff
changeset
|
97 leas fps.size,s ; clean up temporary |
a492441bfc56
Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents:
82
diff
changeset
|
98 inc fps.exp,y ; bump exponent (times 10) in result |
a492441bfc56
Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents:
82
diff
changeset
|
99 beq fps_mul10a ; brif it overflowed |
a492441bfc56
Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents:
82
diff
changeset
|
100 rts |
a492441bfc56
Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents:
82
diff
changeset
|
101 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
80
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
102 ; 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
|
103 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
|
104 std 2,y |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
105 ldd 4,x |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
106 std 4,y |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
107 ldd ,x |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
108 std ,y |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
109 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
|
110 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
|
111 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
|
112 fps_neg0 rts |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
113 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
|
114 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
|
115 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
|
116 fps_negx0 rts |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
117 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
118 ; 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
|
119 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
|
120 std fpa0 |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
121 ldd 2,x |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
122 std fpa0+2 |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
123 ldd 4,x |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
124 std fpa0+4 |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
125 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
|
126 std fpa1 |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
127 ldd 2,u |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
128 std fpa1+2 |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
129 ldd 4,u |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
130 std fpa1+4 |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
131 rts |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
132 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
133 ; 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
|
134 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
|
135 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
|
136 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
|
137 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
138 ; 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
|
139 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
|
140 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
|
141 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
|
142 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
|
143 std ,y |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
144 ldd fpa0+2 |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
145 std 2,y |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
146 ldd fpa0+4 |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
147 std 4,y |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
148 rts |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
149 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
|
150 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
|
151 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
|
152 std ,y |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
153 ldd fpa1+2 |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
154 std 2,y |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
155 ldd fpa1+4 |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
156 std 4,y |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
157 rts |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
158 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
|
159 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
|
160 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
|
161 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
|
162 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
|
163 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
|
164 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
|
165 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
|
166 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
|
167 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
|
168 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
|
169 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
|
170 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
|
171 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
|
172 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
|
173 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
|
174 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
|
175 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
|
176 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
|
177 ldb fps.sig,x |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
178 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
|
179 clr fps.sig,x |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
180 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
|
181 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
|
182 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
|
183 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
|
184 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
|
185 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
|
186 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
|
187 ror fpa0extra |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
188 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
|
189 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
|
190 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
|
191 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
|
192 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
|
193 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
|
194 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
|
195 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
|
196 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
|
197 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
|
198 adca fpa1+fps.sig |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
199 std fpa0+fps.sig |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
200 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
|
201 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
|
202 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
|
203 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
|
204 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
|
205 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
|
206 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
|
207 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
|
208 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
|
209 jmp ERROR |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
210 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
|
211 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
|
212 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
|
213 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
|
214 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
|
215 sbca fpa1+fps.sig |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
216 std fpa0+fps.sig |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
217 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
|
218 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
|
219 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
|
220 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
|
221 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
|
222 com fpa0+fps.sig |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
223 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
|
224 leax 1,x |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
225 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
|
226 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
|
227 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
|
228 leax 1,x |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
229 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
|
230 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
|
231 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
|
232 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
|
233 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
|
234 stb fpa0+fps.sig |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
235 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
|
236 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
|
237 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
|
238 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
|
239 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
|
240 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
|
241 clr fpa0extra |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
242 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
|
243 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
|
244 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
|
245 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
|
246 clr fpa0+fps.sign |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
247 clr fpa0+fps.sig |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
248 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
|
249 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
|
250 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
|
251 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
|
252 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
|
253 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
|
254 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
|
255 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
|
256 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
|
257 rol fpa0+fps.sig |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
258 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
|
259 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
|
260 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
|
261 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
|
262 leax 1,x |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
263 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
|
264 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
|
265 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
|
266 leax 1,x |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
267 stx fpa0+fps.sig |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
268 bne fps_add16 |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
269 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
|
270 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
|
271 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
|
272 sta fpa0+fps.sig |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
273 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
|
274 std ,y |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
275 ldd fpa0+2 |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
276 std 2,y |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
277 ldd fpa0+4 |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
278 std 4,y |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
279 rts |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
280 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
281 ; 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
|
282 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
|
283 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
|
284 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
|
285 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
|
286 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
|
287 std ,y |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
288 std 2,y |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
289 std 4,y |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
290 rts |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
291 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
|
292 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
|
293 eora fpa1+fps.sign |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
294 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
|
295 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
|
296 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
|
297 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
|
298 rola |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
299 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
|
300 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
|
301 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
|
302 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
|
303 ; 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
|
304 ; 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
|
305 ; 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
|
306 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
|
307 std fpa0extra4 |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
308 std fpa0extra6 |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
309 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
|
310 bsr fps_mul4 |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
311 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
|
312 stb fpa0extra3 |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
313 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
|
314 bsr fps_mul4 |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
315 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
|
316 stb fpa0extra2 |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
317 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
|
318 bsr fps_mul4 |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
319 ldb fpa0extra |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
320 stb fpa0extra1 |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
321 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
|
322 bsr fps_mul4 |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
323 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
|
324 std fpa0+fps.sig |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
325 ldd fpa0extra6 |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
326 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
|
327 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
|
328 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
|
329 jmp OVERROR ; raise overflow |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
330 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
|
331 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
|
332 sta fpa0extra |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
333 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
|
334 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
|
335 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
|
336 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
|
337 lda fpa0+fps.sig |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
338 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
|
339 clr fpa0+fps.sig |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
340 fps_mul8 rts |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
341 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
|
342 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
|
343 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
|
344 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
|
345 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
|
346 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
|
347 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
|
348 sta fpa0extra7 |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
349 lda fpa0extra6 |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
350 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
|
351 sta fpa0extra6 |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
352 lda fpa0extra5 |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
353 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
|
354 sta fpa0extra5 |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
355 lda fpa0extra4 |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
356 adca fpa1+fps.sig |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
357 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
|
358 sta fpa0extra4 |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
359 ror fpa0extra5 |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
360 ror fpa0extra6 |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
361 ror fpa0extra7 |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
362 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
|
363 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
|
364 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
|
365 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
83
a492441bfc56
Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents:
82
diff
changeset
|
366 ; Divide (X) by 10 in place |
a492441bfc56
Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents:
82
diff
changeset
|
367 fps_const10 fcb 0x83,0xa0,0x00,0x00,0x00,0x00 ; single precision unpacked constant 10 |
a492441bfc56
Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents:
82
diff
changeset
|
368 fps_div10 ldu #fps_const10 ; point to constant 10 |
a492441bfc56
Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents:
82
diff
changeset
|
369 leay ,x ; put output in input |
a492441bfc56
Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents:
82
diff
changeset
|
370 ; fall through to regular division |
a492441bfc56
Add utility multiply and divide by 10 routines
William Astle <lost@l-w.ca>
parents:
82
diff
changeset
|
371 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
80
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
372 ; 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
|
373 ; |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
374 ; 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
|
375 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
|
376 bne fps_div0 |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
377 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
|
378 jmp ERROR |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
379 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
|
380 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
|
381 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
|
382 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
|
383 eora fpa1+fps.sign |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
384 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
|
385 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
|
386 nega ; negate for subtraction |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
387 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
|
388 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
|
389 rola |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
390 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
|
391 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
|
392 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
|
393 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
|
394 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
|
395 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
|
396 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
|
397 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
|
398 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
|
399 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
|
400 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
|
401 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
|
402 cmpa fpa0+fps.sig |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
403 bne fps_div2 |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
404 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
|
405 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
|
406 bne fps_div2 |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
407 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
|
408 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
|
409 bne fps_div2 |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
410 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
|
411 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
|
412 bne fps_div2 |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
413 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
|
414 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
|
415 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
|
416 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
|
417 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
|
418 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
|
419 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
|
420 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
|
421 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
|
422 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
|
423 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
|
424 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
|
425 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
|
426 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
|
427 rol fpa0+fps.sig |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
428 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
|
429 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
|
430 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
|
431 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
|
432 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
|
433 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
|
434 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
|
435 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
|
436 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
|
437 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
|
438 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
|
439 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
|
440 lda fpa0+fps.sig |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
441 sbca fpa1+fps.sig |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
442 sta fpa0+fps.sig |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
443 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
|
444 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
|
445 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
|
446 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
|
447 rorb |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
448 rorb |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
449 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
|
450 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
|
451 std fpa0+fps.sig |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
452 ldd fpa0extra6 |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
453 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
|
454 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
|
455 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
456 ; 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
|
457 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
|
458 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
|
459 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
|
460 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
|
461 std fps.sig,u |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
462 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
|
463 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
|
464 lda fps.exp,x |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
465 sta fps.exp,u |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
466 rts |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
467 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
468 ; 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
|
469 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
|
470 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
|
471 sta fps.exp,u |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
472 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
|
473 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
|
474 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
|
475 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
|
476 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
|
477 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
|
478 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
|
479 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
|
480 rts |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
481 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
|
482 sta fps.sig,u |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
483 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
|
484 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
|
485 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
|
486 sta fps.sign,u |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
487 rts |
bb50ac9fdf37
Checkpoint with very basic integer and floating point arithmetic, untested
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
488 *pragmapop list |