Submitted by Steve Fewell
Routine:SplitFWA
Name: Split Floating-Point Value
Starting Address: &82E0
Entry criteria: The FWA contains the value to split.
Exit: The FWA contains the fractional value.
&49 contains the 1-byte Integer value.
Z (zero flag) is set if the fractrional value is zero.
Description:
If the FWA exponent is positive then return FWA sign (sets Z flag to 1 if zero) and
set &49 to 0, as the Integer part of the number is zero. The number in the FWA is
a fractional value (there is no integer part).
Otherwise, the FWA value contains an Integer part.
Clear the FWB (in &8275 routine), and keep incrementing the exponent and moving
FWA Mantissa bits right (ROR, divide by 2) moving any overflowed bits into the FWB mantissa.
Until the exponent = #&:A0. This removes the fractional part of the FWA Mantissa value
into the FWB Mantissa. If the FWA sign byte is set (negative value) then the Integer value in
the FWA Mantissa will be complemented (to negate it).
Store FWA Mantissa byte 4 in &49, this is the LSB of the Integer value in the FWA.
The rest of the Integer value in the FWA will be lost. &49 now contains the 1-byte
Integer value of the Integer part of the FWA value.
Copy the FWB Mantissa to the FWA Mantissa, so that the FWA Mantissa contains the
Fractional part of the original value.
Set the FWA exponent to #&80, as the whole of the FWA Mantissa now contains a fractional
value.
If the FWA Mantissa 1 is not negative, then Normalise FWA (&81F7) and exit.
(I'm not too sure what the meaning of the next 3 lines is! Anyone know?)
Reverse the FWA sign byte (EOR &2E with #&80).
If the FWA sign is negative then decrement &49 and complement the FWA value.
If the FWA sign is positive then increment &49 and complement the FWA value.
Exit with the required values in the FWA and &49.
82E0 | 0 | 165 048 | A5 30 | LDA &30 |
82E2 | 0 | 048 005 | 30 05 | BMI 5 --> &82E9 |
82E4 | dI | 100 073 | 64 49 | STZ &49 |
82E6 | L | 076 242 163 | 4C F2 A3 | JMP &A3F2 Floating-Point Sign |
82E9 | u | 032 117 130 | 20 75 82 | JSR &8275 Move fractional part of the FWA value to FWB |
82EC | 4 | 165 052 | A5 34 | LDA &34 |
82EE | I | 133 073 | 85 49 | STA &49 |
82F0 | S | 032 083 131 | 20 53 83 | JSR &8353 Copy FWB Mantissa + Rounding bytes to FWA |
82F3 | 169 128 | A9 80 | LDA#&80 | |
82F5 | 0 | 133 048 | 85 30 | STA &30 |
82F7 | 1 | 166 049 | A6 31 | LDX &31 |
82F9 | 016 015 | 10 0F | BPL 15 --> &830A Normalise FWA and exit | |
82FB | E. | 069 046 | 45 2E | EOR &2E |
82FD | . | 133 046 | 85 2E | STA &2E |
82FF | 016 004 | 10 04 | BPL 4 --> &8305 | |
8301 | I | 230 073 | E6 49 | INC &49 |
8303 | 128 002 | 80 02 | BRA 2 --> &8307 | |
8305 | I | 198 073 | C6 49 | DEC &49 |
8307 | 032 200 130 | 20 C8 82 | JSR &82C8 Reverse order complement of FWA | |
830A | L | 076 247 129 | 4C F7 81 | JMP &81F7 Normalise FWA#1 |
8275 | 0 | 165 048 | A5 30 | LDA &30 |
8277 | 016 246 | 10 F6 | BPL -10 --> &826F Copy FWA to FWB and Clear FWA | |
8279 | p | 032 112 165 | 20 70 A5 | JSR &A570 Clear FWB |
827C | 1 | 164 049 | A4 31 | LDY &31 |
827E | ... Jump to Reverse Order Complement |
826F | 032 011 164 | 20 0B A4 | JSR &A40B Copy FWA to FWB | |
8272 | L | 076 180 166 | 4C B4 A6 | JMP &A6B4 Clear FWA |