Routine: Input
Function: Get a number from the user and convert it into Floating point format
Called by: Almvis, Calib, Measno
Calls: Keyb, Mult, Regld, Regsv
Entry: HL points to variable's location
Exit: Input variable stored at HL
Preserved: All
INPUT CALL REGSV
PUSH HL
INP0 LD B,5
LD A,255
LD HL,INPBUF
; Use storage space at Inpbuf as temporary space.
INP1 LD (HL),A
INC HL
DJNZ INP1
; Clear the storage space.
LD (HL),0
LD A,2
LD (INPDGT),A
; Inpdgt holds the number of digits entered +2.
LD IX,INPBUF
LD A,(IX+5)
JR INP7
INP2 CALL KEYB
CP 255
JR Z,INP2
; Detect a keypress and see if it is a decimal point: if not then jump to Inp4.
CP 17
JR NZ,INP4
LD HL,INPDGT
BIT 7,(HL)
JR NZ,INP2
; If 6 digits have already been entered then allow no more!
SET 7,(HL)
LD A,(HL)
CP 130
JR NZ,INP3
INC (HL)
INP3 SET 4,(IX+5)
; Enter a decimal point.
JR INP2
INP4 CP 21
JR Z,INPENT
; 'Enter' causes a jump to the conversion part of the subroutine, 'Clr' causes the input buffer to be cleared.
CP 19
JR Z,INP0
CP 10
JR P,INP2
; Do not allow a non-numeric keypress.
OR A
JR NZ,INP5
; A zero entered requires special treatment depending on whether or not it is the first digit to be entered, in which case it is ignored.
LD D,A
LD A,(INPDGT)
CP 2
JR Z,INP2
LD A,D
INP5 LD HL,INPDGT
BIT 3,(HL)
; If 6 digits have already been entered then allow no more! Otherwise increment the number of digits flag.
JR NZ,INP2
INC (HL)
LD HL,INPBUF+5
LD D,A
LD A,(INPDGT)
CP 3
JR NZ,INP6
LD (HL),255
INP6 LD A,D
LD HL,INPBUF
LD DE,INPBUF
LD BC,5
INC HL
LDIR
; Shift the digits in the display buffer left to make room for the typed digit.
LD (IX+5),A
LD HL,INPDGT
BIT 7,(HL)
JR NZ,INP8
INP7 OR 16
INP8 LD C,8
LD B,6
LD HL,INPBUF+5
INP9 OUT (C),A
RL A
RL D
INC C
DEC HL
LD A,(HL)
DJNZ INP9
; Display all the digits in the display buffer.
LD A,D
CPL
OUT (144),A
; Set the digit blanking register according to digits entered. Note that initially the input buffer contains 255s; these are rotated into the D register in the above loop, which after inversion gives the correct value to be sent to the digit blanking register.
JP INP2
INPENT LD HL,0
; Conversion of data in the input buffer to floating point format.
LD D,H
LD E,H
LD IX,INPBUF
LD B,6
LD C,0
INP10 PUSH BC
LD A,(IX)
INC IX
CP 255
JR NZ,INP11
XOR A
; Enter zeros for 255s in the input buffer.
INP11 BIT 4,A
JR Z,INP12
; Detect the decimal point when it occurs and save its location in the C register for later use.
POP BC
LD C,B
DEC C
PUSH BC
AND 15
; The following is the actual decimal to binary conversion for 1 digit; it is repeated 6 times for the entire input buffer.
INP12 CALL INPSHF
LD (INPHI),DE
LD (INPLO),HL
CALL INPSHF
CALL INPSHF
LD BC,(INPLO)
ADD HL,BC
EX DE,HL
LD BC,(INPHI)
ADC HL,BC
EX DE,HL
LD C,A
LD B,0
ADD HL,BC
JR NC,INP13
INC E
INP13 POP BC
DJNZ INP10
; Repeat the conversion 6 times: the counter is held in the B register.
LD B,32
XOR A
OR L
OR H
OR E
JR NZ,INP15
; If zero was entered, the following section inserts a floating point zero at the desired input variable location, then returns. Floating point zero is defined as 0,0,0,0,128. For non-zero numbers jump to Inp15.
POP HL
LD B,4
INP14 LD (HL),0
INC HL
DJNZ INP14
LD (HL),128
CALL REGLD
RET
; Normalise the number.
INP15 SLA A
RL H
RL E
RL D
DEC B
BIT 7,D
LD (INPBUF),HL
LD (INPBUF+2),DE
LD A,B
LD (INPBUF+4),A
LD B,C
LD A,B
OR A
JR Z,INP17
; If an integer was entered then no multiplications are necessary (jump to Inp17); otherwise multiply by a tenth, C number of times, to take account of the position of the decimal point in the input buffer.
INP16 PUSH BC
LD BC,INPBUF
LD DE,TENTH
LD HL,INPBUF
CALL MULT
POP BC
DJNZ INP16
INP17 POP HL
LD IX,INPBUF
LD B,5
INP18 LD A,(IX)
LD (HL),A
INC HL
INC IX
DJNZ INP18
; Transfer the result to the desired variable location specified by HL and return.
CALL REGLD
RET
INPSHF ADD HL,HL
EX DE,HL
ADC HL,HL
EX DE,HL
; This subroutine shifts the DE and HL register pairs by 1 bit left.
RET