Prev: 11662 Up: Map Next: 11713
11682: THE 'FLOATING-POINT TO BC' SUBROUTINE
Used by the routines at E_LINE_NO, FIND_INT1, S_RND and FP_TO_A.
This subroutine is used to compress the floating-point 'last value' on the calculator stack into the BC register pair. If the result is too large, i.e. greater than 65536, then the subroutine returns with the carry flag set. If the 'last value' is negative then the zero flag is reset. The low byte of the result is also copied to the A register.
Output
A LSB of the value (same as C)
BC Last value from the calculator stack
F Carry flag set on overflow
F Zero flag set if the value is positive, reset if negative
FP_TO_BC 11682 RST 40 Use the calculator to make HL point to STKEND-5.
11683 DEFB 56 end_calc
11684 LD A,(HL) Collect the exponent byte of the 'last value'; jump if it is zero, indicating a 'small integer'.
11685 AND A
11686 JR Z,FP_DELETE
11688 RST 40 Now use the calculator to round the 'last value' (V) to the nearest integer, which also changes it to 'small integer' form on the calculator stack if that is possible, i.e. if -65535.5<=V<65535.5.
11689 DEFB 162 stk_half: V, 0.5
11690 DEFB 15 addition: V+0.5
11691 DEFB 39 int: INT (V+0.5)
11692 DEFB 56 end_calc
FP_DELETE 11693 RST 40 Use the calculator to delete the integer from the stack; DE still points to it in memory (at STKEND).
11694 DEFB 2 delete
11695 DEFB 56 end_calc
11696 PUSH HL Save both stack pointers.
11697 PUSH DE
11698 EX DE,HL HL now points to the number.
11699 LD B,(HL) Copy the first byte to B.
11700 CALL INT_FETCH Copy bytes 2, 3 and 4 to C, E and D.
11703 XOR A Clear the A register.
11704 SUB B This sets the carry unless B is zero.
11705 BIT 7,C This sets the zero flag if the number is positive (NZ denotes negative).
11707 LD B,D Copy the high byte to B.
11708 LD C,E And the low byte to C.
11709 LD A,E Copy the low byte to A too.
11710 POP DE Restore the stack pointers.
11711 POP HL
11712 RET Finished.
Prev: 11662 Up: Map Next: 11713