Routines 
Prev: 2D8E  Up: Map 
This subroutine is used to compress the floatingpoint '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.


FP_TO_BC  2DA2  RST $28  Use the calculator to make HL point to STKEND5.  
2DA3  DEFB $38  end_calc  
2DA4  LD A,(HL)  Collect the exponent byte of the 'last value'; jump if it is zero, indicating a 'small integer'.  
2DA5  AND A  
2DA6  JR Z,FP_DELETE  
2DA8  RST $28  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.  
2DA9  DEFB $A2  stk_half: V, 0.5  
2DAA  DEFB $0F  addition: V+0.5  
2DAB  DEFB $27  int: INT (V+0.5)  
2DAC  DEFB $38  end_calc  
FP_DELETE  2DAD  RST $28  Use the calculator to delete the integer from the stack; DE still points to it in memory (at STKEND).  
2DAE  DEFB $02  delete  
2DAF  DEFB $38  end_calc  
2DB0  PUSH HL  Save both stack pointers.  
2DB1  PUSH DE  
2DB2  EX DE,HL  HL now points to the number.  
2DB3  LD B,(HL)  Copy the first byte to B.  
2DB4  CALL INT_FETCH  Copy bytes 2, 3 and 4 to C, E and D.  
2DB7  XOR A  Clear the A register.  
2DB8  SUB B  This sets the carry unless B is zero.  
2DB9  BIT 7,C  This sets the zero flag if the number is positive (NZ denotes negative).  
2DBB  LD B,D  Copy the high byte to B.  
2DBC  LD C,E  And the low byte to C.  
2DBD  LD A,E  Copy the low byte to A too.  
2DBE  POP DE  Restore the stack pointers.  
2DBF  POP HL  
2DC0  RET  Finished. 
Prev: 2D8E  Up: Map 