Prev: 031E Up: Map Next: 03B5
0333: THE 'KEYBOARD DECODING' SUBROUTINE
Used by the routines at KEYBOARD and S_INKEY.
This subroutine is entered with the 'main code' in the E register, the value of FLAGS in the D register, the value of MODE in the C register and the 'shift byte' in the B register.
By considering these four values and referring, as necessary, to the six key tables a 'final code' is produced. This is returned in the A register.
Input
B Shift key pressed (+18 or +27), or +FF if no shift key pressed
C MODE
D FLAGS
E Main code (from the main key table)
Output
A Final code (from the key tables)
K_DECODE 0333 LD A,E Copy the 'main code'.
0334 CP $3A Jump forward if a digit key is being considered; also SPACE, ENTER and both shifts.
0336 JR C,K_DIGIT
0338 DEC C Decrement the MODE value.
0339 JP M,K_KLC_LET Jump forward, as needed, for modes 'K', 'L', 'C' and 'E'.
033C JR Z,K_E_LET
Only 'graphics' mode remains and the 'final code' for letter keys in graphics mode is computed from the 'main code'.
033E ADD A,$4F Add the offset.
0340 RET Return with the 'final code'.
Letter keys in extended mode are considered next.
K_E_LET 0341 LD HL,$01EB The base address for table 'b'.
0344 INC B Jump forward to use this table if neither shift key is being pressed.
0345 JR Z,K_LOOK_UP
0347 LD HL,$0205 Otherwise use the base address for table 'c'.
Key tables 'b-f' are all served by the following look-up routine. In all cases a 'final code' is found and returned.
K_LOOK_UP 034A LD D,$00 Clear the D register.
034C ADD HL,DE Index the required table and fetch the 'final code'.
034D LD A,(HL)
034E RET Then return.
Letter keys in 'K', 'L' or 'C' modes are now considered. But first the special SYMBOL SHIFT codes have to be dealt with.
K_KLC_LET 034F LD HL,$0229 The base address for table 'e'.
0352 BIT 0,B Jump back if using the SYMBOL SHIFT key and a letter key.
0354 JR Z,K_LOOK_UP
0356 BIT 3,D Jump forward if currently in 'K' mode.
0358 JR Z,K_TOKENS
035A BIT 3,(IY+$30) If CAPS LOCK is set (bit 3 of FLAGS2 set) then return with the 'main code'.
035E RET NZ
035F INC B Also return in the same manner if CAPS SHIFT is being pressed.
0360 RET NZ
0361 ADD A,$20 However if lower case codes are required then +20 has to be added to the 'main code' to give the correct 'final code'.
0363 RET
The 'final code' values for tokens are found by adding +A5 to the 'main code'.
K_TOKENS 0364 ADD A,$A5 Add the required offset and return.
0366 RET
Next the digit keys, SPACE, ENTER and both shifts are considered.
K_DIGIT 0367 CP "0" Proceed only with the digit keys, i.e. return with SPACE (+20), ENTER (+0D) and both shifts (+0E).
0369 RET C
036A DEC C Now separate the digit keys into three groups - according to the mode.
036B JP M,K_KLC_DGT Jump with 'K', 'L' and 'C' modes, and also with 'G' mode. Continue with 'E' mode.
036E JR NZ,K_GRA_DGT
0370 LD HL,$0254 The base address for table 'f'.
0373 BIT 5,B Use this table for SYMBOL SHIFT and a digit key in extended mode.
0375 JR Z,K_LOOK_UP
0377 CP "8" Jump forward with digit keys '8' and '9'.
0379 JR NC,K_8_9
The digit keys '0' to '7' in extended mode are to give either a 'paper colour code' or an 'ink colour code' depending on the use of CAPS SHIFT.
037B SUB $20 Reduce the range +30 to +37 giving +10 to +17.
037D INC B Return with this 'paper colour code' if CAPS SHIFT is not being used.
037E RET Z
037F ADD A,$08 But if it is then the range is to be +18 to +1F instead - indicating an 'ink colour code'.
0381 RET
The digit keys '8' and '9' are to give 'BRIGHT' and 'FLASH' codes.
K_8_9 0382 SUB $36 +38 and +39 go to +02 and +03.
0384 INC B Return with these codes if CAPS SHIFT is not being used. (These are 'BRIGHT' codes.)
0385 RET Z
0386 ADD A,$FE Subtract '2' if CAPS SHIFT is being used; giving +00 and +01 (as 'FLASH' codes).
0388 RET
The digit keys in graphics mode are to give the block graphic characters (+80 to +8F), the GRAPHICS code (+0F) and the DELETE code (+0C).
K_GRA_DGT 0389 LD HL,$0230 The base address of table 'd'.
038C CP "9" Use this table directly for both digit key '9' that is to give GRAPHICS, and digit key '0' that is to give DELETE.
038E JR Z,K_LOOK_UP
0390 CP "0"
0392 JR Z,K_LOOK_UP
0394 AND $07 For keys '1' to '8' make the range +80 to +87.
0396 ADD A,$80
0398 INC B Return with a value from this range if neither shift key is being pressed.
0399 RET Z
039A XOR $0F But if 'shifted' make the range +88 to +8F.
039C RET
Finally consider the digit keys in 'K', 'L' and 'C' modes.
K_KLC_DGT 039D INC B Return directly if neither shift key is being used. (Final codes +30 to +39.)
039E RET Z
039F BIT 5,B Use table 'd' if the CAPS SHIFT key is also being pressed.
03A1 LD HL,$0230
03A4 JR NZ,K_LOOK_UP
The codes for the various digit keys and SYMBOL SHIFT can now be found.
03A6 SUB $10 Reduce the range to give +20 to +29.
03A8 CP $22 Separate the '@' character from the others.
03AA JR Z,K_AT_CHAR
03AC CP $20 The '_' character has also to be separated.
03AE RET NZ Return now with the 'final codes' +21, +23 to +29.
03AF LD A,"_" Give the '_' character a code of +5F.
03B1 RET
K_AT_CHAR 03B2 LD A,"@" Give the '@' character a code of +40.
03B4 RET
Prev: 031E Up: Map Next: 03B5