477
+ − 1 * Add for REAL #'s - 6809 version
+ − 2 L3FB1 pshs x Preserve X
+ − 3 tst 2,y 1st byte of mantissa 0 (means value is 0)?
+ − 4 beq L3FC7 Yes, eat temp var & leave other var alone
+ − 5 tst 8,y Is original # a 0?
+ − 6 bne L3FCB No, go do actual add
+ − 7 L3FBB ldd 1,y Copy temp var's value overtop original var (0)
+ − 8 std 7,y
+ − 9 ldd 3,y
+ − 10 std 9,y
+ − 11 lda 5,y Copy last byte of mantissa (sign bit) to orig var
+ − 12 sta $B,y
+ − 13 L3FC7 leay 6,y Eat temp var & return
+ − 14 puls pc,x
+ − 15
+ − 16 * Real add with non-zero values starts here
+ − 17 * NOTE: Exponents are 2^n, with n being the SIGNED exponent byte
+ − 18 L3FCB lda 7,y Get 1st exponent
+ − 19 suba 1,y Calculate difference in exponents
+ − 20 bvc L3FD5 Didn't exceed +127 or -128, skip ahead
+ − 21 bpl L3FBB Went too big on plus side, make temp var the answe
+ − 22 bra L3FC7 Too small, eat temp var & leave answer alone
+ − 23
+ − 24 L3FD5 bmi L3FDD If negative difference in exponents, skip ahead
+ − 25 cmpa #31 Difference of exponents within 0-31?
+ − 26 ble L3FE5 Yes, go deal with it
+ − 27 bra L3FC7 >2^31, out of range so eat temp var & return
+ − 28
+ − 29 L3FDD cmpa #-31 Difference of exponents within -1 to -31?
+ − 30 blt L3FBB <2^-31, out of range so copy temp to answer
+ − 31 ldb 1,y ???Since negative difference, copy temp exponent
+ − 32 stb 7,y overtop destination exponent?
+ − 33 * As of this point, exponent in temp var no longer needed (A=difference in exp
+ − 34 L3FE5 ldb $B,y Get sign of dest. var
+ − 35 andb #$01 Keep sign bit only
+ − 36 stb ,y Save copy over var type
+ − 37 eorb 5,y EOR with sign bit of temp var
+ − 38 andb #$01 Keep only merged sign bit
+ − 39 stb 1,y Save what resulting sign should be
+ − 40 ldb $B,y
+ − 41 andb #$FE
+ − 42 stb $B,y
+ − 43 ldb 5,y
+ − 44 andb #$FE
+ − 45 stb 5,y
+ − 46 tsta Are exponents exactly the same?
+ − 47 beq L4031 Yes, skip ahead
+ − 48 bpl L4029 Exponent difference positive, go process
+ − 49 * Exponent difference is a negative value
+ − 50 nega Force to positive
+ − 51 leax 6,y Point X to dest. var
+ − 52 bsr L4082 Shift mantissa to match other value (into X:D)
+ − 53 tst 1,y Result going to be positive?
+ − 54 beq L4039 Yes, skip ahead
+ − 55 L400B subd 4,y Essentially, X:D=X:D-(2,y)
+ − 56 exg d,x
+ − 57 * This is essentially a sign reverse on 32 bit #?
+ − 58 sbcb 3,y
+ − 59 sbca 2,y
+ − 60 bcc L404D No borrow required, skip ahead
+ − 61 coma Compliment all 4 bytes
+ − 62 comb
+ − 63 exg d,x
+ − 64 coma
+ − 65 comb
+ − 66 addd #1 +1
+ − 67 exg d,x
+ − 68 bcc L4025 If no carry, skip ahead
+ − 69 addd #1 +1 to rest of 32 bit #
+ − 70 L4025 dec ,y Drop exponent by 1
+ − 71 bra L404D
+ − 72
+ − 73 * Exponent difference is positive value
+ − 74 L4029 leax ,y Point X to temp var
+ − 75 bsr L4082 Shift mantissa to match other value (into X:D)
+ − 76 stx 2,y
+ − 77 std 4,y
+ − 78 * Equal exponents come here
+ − 79 L4031 ldx 8,y Get mantissa of dest var into X:D
+ − 80 ldd $A,y
+ − 81 tst 1,y Check exponent of temp var
+ − 82 bne L400B <>0, go process
+ − 83 L4039 addd 4,y 32 bit add of X:D + [2,y]
+ − 84 exg d,x
+ − 85 adcb 3,y
+ − 86 adca 2,y
+ − 87 bcc L404D No overflow carry after add, skip ahead
+ − 88 rora Overflow, divide 32 bit mantissa by 2
+ − 89 rorb
+ − 90 exg d,x
+ − 91 rora
+ − 92 rorb
+ − 93 inc 7,y Bump up exponent of dest var by 1
+ − 94 exg d,x
+ − 95 L404D tsta
+ − 96 bmi L4060
+ − 97 L4050 dec 7,y
+ − 98 lbvs L40DD
+ − 99 exg d,x
+ − 100 lslb
+ − 101 rola
+ − 102 exg d,x
+ − 103 rolb
+ − 104 rola
+ − 105 bpl L4050
+ − 106 L4060 exg d,x
+ − 107 addd #1
+ − 108 exg d,x
+ − 109 bcc L4071
+ − 110 addd #1
+ − 111 bcc L4071
+ − 112 rora
+ − 113 inc 7,y
+ − 114 L4071 std 8,y
+ − 115 tfr x,d
+ − 116 andb #$FE Mask out sign bit in mantissa (force to positive)
+ − 117 tst ,y Result supposed to be negative?
+ − 118 beq L407C No, leave it alone
+ − 119 incb Set sign bit (negative result)
+ − 120 L407C std $A,y Save LSW of mantissa
+ − 121 leay 6,y Eat temp var
+ − 122 puls pc,x Restore X & return
+ − 123
+ − 124 * Entry: A=ABS(difference between exponents)
+ − 125 * Y=Ptr to temp var packet\ These could be swapped depending on whether
+ − 126 * X=Ptr to dest var packet/ exponent difference is positive or negative
+ − 127 * Exit: X:D is 32 bit shifted mantissa
+ − 128 L4082 suba #16 Subtract 16 from exponent difference (2 byte shift
+ − 129 blo L40A0 Wrapped to negative, skip ahead
+ − 130 suba #8 Try subtracting 8 from it
+ − 131 blo L4091 Wrapped, go add it back in
+ − 132 * 3 byte minimum shift
+ − 133 sta <u0014 Save number of rotates needed after 3 byte move
+ − 134 clra D=High word of mantissa
+ − 135 ldb 2,x
+ − 136 bra L4097 Go get Low word of mantissa into X & process
+ − 137
+ − 138 * 2 byte minimum shift
+ − 139 L4091 adda #8 Bump # shifts back up
+ − 140 sta <u0014 Save number of rotates needed
+ − 141 ldd 2,x D=
+ − 142 L4097 ldx #0
+ − 143 tst <u0014 Any shifts required?
+ − 144 bne L40BD Yes, go do them
+ − 145 rts No, return
+ − 146
+ − 147 L40A0 adda #8 Add 8 back (back to 1 byte shift)
+ − 148 bhs L40B3 Still more left, skip ahead
+ − 149 sta <u0014
+ − 150 clra
+ − 151 ldb 2,x
+ − 152 ldx 3,x
+ − 153 tst <u0014 Any shifts to do?
+ − 154 bne L40BF Yes, go do
+ − 155 exg d,x
+ − 156 rts
+ − 157
+ − 158 L40B3 adda #8 Add 8 back again (back to original difference)
+ − 159 sta <u0014 Save # bit shifts needed
+ − 160 ldd 2,x Get 32 bit mantissa into D:X from dest var
+ − 161 ldx 4,x
+ − 162 bra L40BF Go perform shift
+ − 163
+ − 164 * NOTE: BY LOOKS OF IT MOST OF THESE D,X PAIRS CAN BE CHANGED TO D,W (Q) PAIRS
+ − 165 * ELIMINATING ALL THE EXCHANGES AND SPEEDING UP REAL CALCS BY QUITE A BIT
+ − 166 L40BD exg d,x
+ − 167 L40BF lsra
+ − 168 rorb
+ − 169 exg d,x
+ − 170 rora
+ − 171 rorb
+ − 172 dec <u0014
+ − 173 bne L40BD
+ − 174 L40C9 rts