Prev: 2070 Up: Map Next: 21B9
2089: THE 'INPUT' COMMAND ROUTINE
The address of this routine is found in the parameter table.
This routine allows for values entered from the keyboard to be assigned to variables. It is also possible to have print items embedded in the INPUT statement and these items are printed in the lower part of the display.
Input
Output
INPUT 2089 CALL SYNTAX_Z Jump forward if syntax is being checked.
208C JR Z,INPUT_1
208E LD A,$01 Open channel 'K'.
2090 CALL CHAN_OPEN
2093 CALL CLS_LOWER The lower part of the display is cleared.
INPUT_1 2096 LD (IY+$02),$01 Signal that the lower screen is being handled (set bit 0 of TV-FLAG and reset all other bits).
209A CALL IN_ITEM_1 Call the subroutine to deal with the INPUT items.
209D CALL CHECK_END Move on to the next statement if checking syntax.
20A0 LD BC,($5C88) Fetch the current print position (S-POSN).
20A4 LD A,($5C6B) Jump forward if the current position is above the lower screen (see DF-SZ).
20A7 CP B
20A8 JR C,INPUT_2
20AA LD C,$21 Otherwise set the print position to the top of the lower screen.
20AC LD B,A
INPUT_2 20AD LD ($5C88),BC Reset S-POSN.
20B1 LD A,$19 Now set the scroll counter (SCR-CT).
20B3 SUB B
20B4 LD ($5C8C),A
20B7 RES 0,(IY+$02) Signal 'main screen' (reset bit 0 of TV-FLAG).
20BB CALL CL_SET Set the system variables and exit via CLS_LOWER.
20BE JP CLS_LOWER
The INPUT items and embedded PRINT items are dealt with in turn by the following loop.
IN_ITEM_1 20C1 CALL PR_POSN_1 Consider first any position control characters.
20C4 JR Z,IN_ITEM_1
20C6 CP "(" Jump forward if the present character is not a '('.
20C8 JR NZ,IN_ITEM_2
20CA RST $20 Fetch the next character.
20CB CALL PRINT_2 Now call the PRINT command routine to handle the items inside the brackets.
20CE RST $18 Fetch the present character.
20CF CP ")" Give report C unless the character is a ')'.
20D1 JP NZ,REPORT_C
20D4 RST $20 Fetch the next character and jump forward to see if there are any further INPUT items.
20D5 JP IN_NEXT_2
Now consider whether INPUT LINE is being used.
IN_ITEM_2 20D8 CP $CA Jump forward if it is not 'LINE'.
20DA JR NZ,IN_ITEM_3
20DC RST $20 Advance CH-ADD.
20DD CALL CLASS_01 Determine the destination address for the variable.
20E0 SET 7,(IY+$37) Signal 'using INPUT LINE' (set bit 7 of FLAGX).
20E4 BIT 6,(IY+$01) Give report C unless using a string variable (bit 6 of FLAGS reset).
20E8 JP NZ,REPORT_C
20EB JR IN_PROMPT Jump forward to issue the prompt message.
Proceed to handle simple INPUT variables.
IN_ITEM_3 20ED CALL ALPHA Jump to consider going round the loop again if the present character is not a letter.
20F0 JP NC,IN_NEXT_1
20F3 CALL CLASS_01 Determine the destination address for the variable.
20F6 RES 7,(IY+$37) Signal 'not INPUT LINE' (reset bit 7 of FLAGX).
The prompt message is now built up in the work space.
IN_PROMPT 20FA CALL SYNTAX_Z Jump forward if only checking syntax.
20FD JP Z,IN_NEXT_2
2100 CALL SET_WORK The work space is set to null.
2103 LD HL,$5C71 This is FLAGX.
2106 RES 6,(HL) Signal 'string result'.
2108 SET 5,(HL) Signal 'INPUT mode'.
210A LD BC,$0001 Allow the prompt message only a single location.
210D BIT 7,(HL) Jump forward if using 'LINE'.
210F JR NZ,IN_PR_2
2111 LD A,($5C3B) Jump forward if awaiting a numeric entry (bit 6 of FLAGS set).
2114 AND $40
2116 JR NZ,IN_PR_1
2118 LD C,$03 A string entry will need three locations.
IN_PR_1 211A OR (HL) Bit 6 of FLAGX will become set for a numeric entry.
211B LD (HL),A
IN_PR_2 211C RST $30 The required number of locations is made available.
211D LD (HL),$0D A 'carriage return' goes into the last location.
211F LD A,C Test bit 6 of the C register and jump forward if only one location was required.
2120 RRCA
2121 RRCA
2122 JR NC,IN_PR_3
2124 LD A,"\"" A 'double quotes' character goes into the first and second locations.
2126 LD (DE),A
2127 DEC HL
2128 LD (HL),A
IN_PR_3 2129 LD ($5C5B),HL The position of the cursor (K-CUR) can now be saved.
In the case of INPUT LINE the EDITOR can be called without further preparation but for other types of INPUT the error stack has to be changed so as to trap errors.
212C BIT 7,(IY+$37) Jump forward with 'INPUT LINE' (bit 7 of FLAGX set).
2130 JR NZ,IN_VAR_3
2132 LD HL,($5C5D) Save the current values of CH-ADD and ERR-SP on the machine stack.
2135 PUSH HL
2136 LD HL,($5C3D)
2139 PUSH HL
IN_VAR_1 213A LD HL,$213A This will be the 'return point' in case of errors.
213D PUSH HL
213E BIT 4,(IY+$30) Only change the error stack pointer (ERR-SP) if using channel 'K' (bit 4 of FLAGS2 set).
2142 JR Z,IN_VAR_2
2144 LD ($5C3D),SP
IN_VAR_2 2148 LD HL,($5C61) Set HL to the start of the INPUT line (WORKSP) and remove any floating-point forms. (There will not be any except perhaps after an error.)
214B CALL REMOVE_FP
214E LD (IY+$00),$FF Signal 'no error yet' by resetting ERR-NR.
2152 CALL EDITOR Now get the INPUT and with the syntax/run flag (bit 7 of FLAGS) indicating syntax, check the INPUT for errors; jump if in order; return to IN_VAR_1 if not.
2155 RES 7,(IY+$01)
2159 CALL IN_ASSIGN
215C JR IN_VAR_4
IN_VAR_3 215E CALL EDITOR Get a 'LINE'.
All the system variables have to be reset before the actual assignment of a value can be made.
IN_VAR_4 2161 LD (IY+$22),$00 The cursor address (K-CUR) is reset.
2165 CALL IN_CHAN_K The jump is taken if using other than channel 'K'.
2168 JR NZ,IN_VAR_5
216A CALL ED_COPY The input-line is copied to the display and the position in ECHO-E made the current position in the lower screen.
216D LD BC,($5C82)
2171 CALL CL_SET
IN_VAR_5 2174 LD HL,$5C71 This is FLAGX.
2177 RES 5,(HL) Signal 'edit mode'.
2179 BIT 7,(HL) Jump forward if handling an INPUT LINE.
217B RES 7,(HL)
217D JR NZ,IN_VAR_6
217F POP HL Drop the address IN-VAR-1.
2180 POP HL Reset the ERR-SP to its original address.
2181 LD ($5C3D),HL
2184 POP HL Save the original CH-ADD address in X-PTR.
2185 LD ($5C5F),HL
2188 SET 7,(IY+$01) Now with the syntax/run flag (bit 7 of FLAGS) indicating 'run' make the assignment.
218C CALL IN_ASSIGN
218F LD HL,($5C5F) Restore the original address to CH-ADD and clear X-PTR.
2192 LD (IY+$26),$00
2196 LD ($5C5D),HL
2199 JR IN_NEXT_2 Jump forward to see if there are further INPUT items.
IN_VAR_6 219B LD HL,($5C63) The length of the 'LINE' in the work space is found (STKBOT-WORKSP-1).
219E LD DE,($5C61)
21A2 SCF
21A3 SBC HL,DE
21A5 LD B,H DE points to the start and BC holds the length.
21A6 LD C,L
21A7 CALL STK_STO These parameters are stacked and the actual assignment made.
21AA CALL LET
21AD JR IN_NEXT_2 Also jump forward to consider further items.
Further items in the INPUT statement are considered.
IN_NEXT_1 21AF CALL PR_ITEM_1 Handle any print items.
IN_NEXT_2 21B2 CALL PR_POSN_1 Handle any position controllers.
21B5 JP Z,IN_ITEM_1 Go around the loop again if there are further items; otherwise return.
21B8 RET
Prev: 2070 Up: Map Next: 21B9