Routine: Fpint
Function: Converts a floating point number to a two byte integer. The FP number must be positive and <65536.
Called by: Measno, Visc
Calls: Error
Entry: IX points to FP number
Exit: HL holds the integer part
Preserved: None
FPINT LD B,(IX+4)
LD D,(IX+3)
LD E,(IX+2)
LD H,(IX+1)
LD L,(IX)
LD A,B
; Read the floating point number into the Z80 registers.
CP 17
JR C,FPINT1
CP 128
JR C,FPINT4
; If the floating point number is too big then jump to fpint4 and signal error code 6; otherwise if it is zero, set HL to zero and return.
LD L,0
LD H,L
RET
FPINT1 BIT 7,D
JR NZ,FPINT5
; If negative, signal error 7. The rest of the routine is just shifting until the exponent becomes zero.
INC B
XOR A
LD C,A
SET 7,D
JR FPINT3
FPINT2 RL L
RL H
RL E
EL D
RL C
RL A
FPINT3 DJNZ FPINT2
; Load the integer part of the floating point number into HL, and return.
LD L,C
LD H,A
RET
FPINT4 LD A,6
CALL ERROR
RET
FPINT5 LD A,7
CALL ERROR
RET