| Routines

04264: THE 'KEYBOARD INPUT' SUBROUTINE

The address of this routine is found in the initial channel information table. This important subroutine returns the code of the last key to have been pressed, but note that CAPS LOCK, the changing of the mode and the colour control parameters are handled within the subroutine.
Output
A | Code of the last key pressed
F | Carry flag set if a key was pressed
KEY_INPUT | 04264 | BIT 3,(IY+2) | Copy the edit-line or the INPUT-line to the screen if the mode has changed (bit 3 of TV-FLAG set).
| 04268 | CALL NZ,ED_COPY
| 04271 | AND A | Return with both carry and zero flags reset if no new key has been pressed (bit 5 of FLAGS reset).
| 04272 | BIT 5,(IY+1)
| 04276 | RET Z
| 04277 | LD A,(23560) | Otherwise fetch the code (LAST-K) and signal that it has been taken (reset bit 5 of FLAGS).
| 04280 | RES 5,(IY+1)
| 04284 | PUSH AF | Save the code temporarily.
| 04285 | BIT 5,(IY+2) | Clear the lower part of the display if necessary (bit 5 of TV-FLAG set), e.g. after 'scroll?'.
| 04289 | CALL NZ,CLS_LOWER
| 04292 | POP AF | Fetch the code.
| 04293 | CP " " | Accept all characters and token codes.
| 04295 | JR NC,KEY_DONE_2
| 04297 | CP 16 | Jump forward with most of the control character codes.
| 04299 | JR NC,KEY_CONTR
| 04301 | CP 6 | Jump forward with the 'mode' codes and the CAPS LOCK code.
| 04303 | JR NC,KEY_M_CL
Now deal with the FLASH, BRIGHT and INVERSE codes.
| 04305 | LD B,A | Save the code.
| 04306 | AND 1 | Keep only bit 0.
| 04308 | LD C,A | C holds 0 (=OFF) or 1 (=ON).
| 04309 | LD A,B | Fetch the code.
| 04310 | RRA | Rotate it once (losing bit 0).
| 04311 | ADD A,18 | Increase it by 18 giving 18 for FLASH, 19 for BRIGHT, and 20 for INVERSE.
| 04313 | JR KEY_DATA
The CAPS LOCK code and the mode codes are dealt with 'locally'.
KEY_M_CL | 04315 | JR NZ,KEY_MODE | Jump forward with 'mode' codes.
| 04317 | LD HL,23658 | This is FLAGS2.
| 04320 | LD A,8 | Flip bit 3 of FLAGS2. This is the CAPS LOCK flag.
| 04322 | XOR (HL)
| 04323 | LD (HL),A
| 04324 | JR KEY_FLAG | Jump forward.
KEY_MODE | 04326 | CP 14 | Check the lower limit.
| 04328 | RET C
| 04329 | SUB 13 | Reduce the range.
| 04331 | LD HL,23617 | This is MODE.
| 04334 | CP (HL) | Has it been changed?
| 04335 | LD (HL),A | Enter the new 'mode' code.
| 04336 | JR NZ,KEY_FLAG | Jump if it has changed; otherwise make it 'L mode'.
| 04338 | LD (HL),0
KEY_FLAG | 04340 | SET 3,(IY+2) | Signal 'the mode might have changed' (set bit 3 of TV-FLAG).
| 04344 | CP A | Reset the carry flag and return.
| 04345 | RET
The control key codes (apart from FLASH, BRIGHT and INVERSE) are manipulated.
KEY_CONTR | 04346 | LD B,A | Save the code.
| 04347 | AND 7 | Make the C register hold the parameter (0 to 7).
| 04349 | LD C,A
| 04350 | LD A,16 | A now holds the INK code.
| 04352 | BIT 3,B | But if the code was an 'unshifted' code then make A hold the PAPER code.
| 04354 | JR NZ,KEY_DATA
| 04356 | INC A
The parameter is saved in K-DATA and the channel address changed from KEY_INPUT to KEY_NEXT.
KEY_DATA | 04357 | LD (IY-45),C | Save the parameter at K-DATA.
| 04360 | LD DE,4365 | This is KEY_NEXT.
| 04363 | JR KEY_CHAN | Jump forward.
Note: on the first pass entering at KEY_INPUT the A register is returned holding a 'control code' and then on the next pass, entering at KEY_NEXT, it is the parameter that is returned.
KEY_NEXT | 04365 | LD A,(23565) | Fetch the parameter (K-DATA).
| 04368 | LD DE,4264 | This is KEY_INPUT.
Now set the input address in the first channel area.
KEY_CHAN | 04371 | LD HL,(23631) | Fetch the channel address (CHANS).
| 04374 | INC HL
| 04375 | INC HL
| 04376 | LD (HL),E | Now set the input address.
| 04377 | INC HL
| 04378 | LD (HL),D
Finally exit with the required code in the A register.
KEY_DONE_2 | 04379 | SCF | Show a code has been found and return.
| 04380 | RET