| Spectrum ROM | Routines |
| Prev: 00798 | Up: Map |
|
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.
|
|||||||||||||||||
| K_DECODE | 00819 | LD A,E | Copy the 'main code'. | ||||||||||||||
| 00820 | CP 58 | Jump forward if a digit key is being considered; also SPACE, ENTER and both shifts. | |||||||||||||||
| 00822 | JR C,K_DIGIT | ||||||||||||||||
| 00824 | DEC C | Decrement the MODE value. | |||||||||||||||
| 00825 | JP M,K_KLC_LET | Jump forward, as needed, for modes 'K', 'L', 'C' and 'E'. | |||||||||||||||
| 00828 | 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'.
|
|||||||||||||||||
| 00830 | ADD A,79 | Add the offset. | |||||||||||||||
| 00832 | RET | Return with the 'final code'. | |||||||||||||||
|
Letter keys in extended mode are considered next.
|
|||||||||||||||||
| K_E_LET | 00833 | LD HL,491 | The base address for table 'b'. | ||||||||||||||
| 00836 | INC B | Jump forward to use this table if neither shift key is being pressed. | |||||||||||||||
| 00837 | JR Z,K_LOOK_UP | ||||||||||||||||
| 00839 | LD HL,517 | 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 | 00842 | LD D,0 | Clear the D register. | ||||||||||||||
| 00844 | ADD HL,DE | Index the required table and fetch the 'final code'. | |||||||||||||||
| 00845 | LD A,(HL) | ||||||||||||||||
| 00846 | 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 | 00847 | LD HL,553 | The base address for table 'e'. | ||||||||||||||
| 00850 | BIT 0,B | Jump back if using the SYMBOL SHIFT key and a letter key. | |||||||||||||||
| 00852 | JR Z,K_LOOK_UP | ||||||||||||||||
| 00854 | BIT 3,D | Jump forward if currently in 'K' mode. | |||||||||||||||
| 00856 | JR Z,K_TOKENS | ||||||||||||||||
| 00858 | BIT 3,(IY+48) | If CAPS LOCK is set (bit 3 of FLAGS2 set) then return with the 'main code'. | |||||||||||||||
| 00862 | RET NZ | ||||||||||||||||
| 00863 | INC B | Also return in the same manner if CAPS SHIFT is being pressed. | |||||||||||||||
| 00864 | RET NZ | ||||||||||||||||
| 00865 | ADD A,32 | However if lower case codes are required then +20 has to be added to the 'main code' to give the correct 'final code'. | |||||||||||||||
| 00867 | RET | ||||||||||||||||
|
The 'final code' values for tokens are found by adding +A5 to the 'main code'.
|
|||||||||||||||||
| K_TOKENS | 00868 | ADD A,165 | Add the required offset and return. | ||||||||||||||
| 00870 | RET | ||||||||||||||||
|
Next the digit keys, SPACE, ENTER and both shifts are considered.
|
|||||||||||||||||
| K_DIGIT | 00871 | CP "0" | Proceed only with the digit keys, i.e. return with SPACE (+20), ENTER (+0D) and both shifts (+0E). | ||||||||||||||
| 00873 | RET C | ||||||||||||||||
| 00874 | DEC C | Now separate the digit keys into three groups - according to the mode. | |||||||||||||||
| 00875 | JP M,K_KLC_DGT | Jump with 'K', 'L' and 'C' modes, and also with 'G' mode. Continue with 'E' mode. | |||||||||||||||
| 00878 | JR NZ,K_GRA_DGT | ||||||||||||||||
| 00880 | LD HL,596 | The base address for table 'f'. | |||||||||||||||
| 00883 | BIT 5,B | Use this table for SYMBOL SHIFT and a digit key in extended mode. | |||||||||||||||
| 00885 | JR Z,K_LOOK_UP | ||||||||||||||||
| 00887 | CP "8" | Jump forward with digit keys '8' and '9'. | |||||||||||||||
| 00889 | 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.
|
|||||||||||||||||
| 00891 | SUB 32 | Reduce the range +30 to +37 giving +10 to +17. | |||||||||||||||
| 00893 | INC B | Return with this 'paper colour code' if CAPS SHIFT is not being used. | |||||||||||||||
| 00894 | RET Z | ||||||||||||||||
| 00895 | ADD A,8 | But if it is then the range is to be +18 to +1F instead - indicating an 'ink colour code'. | |||||||||||||||
| 00897 | RET | ||||||||||||||||
|
The digit keys '8' and '9' are to give 'BRIGHT' and 'FLASH' codes.
|
|||||||||||||||||
| K_8_9 | 00898 | SUB 54 | +38 and +39 go to +02 and +03. | ||||||||||||||
| 00900 | INC B | Return with these codes if CAPS SHIFT is not being used. (These are 'BRIGHT' codes.) | |||||||||||||||
| 00901 | RET Z | ||||||||||||||||
| 00902 | ADD A,254 | Subtract '2' if CAPS SHIFT is being used; giving +00 and +01 (as 'FLASH' codes). | |||||||||||||||
| 00904 | 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 | 00905 | LD HL,560 | The base address of table 'd'. | ||||||||||||||
| 00908 | 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. | |||||||||||||||
| 00910 | JR Z,K_LOOK_UP | ||||||||||||||||
| 00912 | CP "0" | ||||||||||||||||
| 00914 | JR Z,K_LOOK_UP | ||||||||||||||||
| 00916 | AND 7 | For keys '1' to '8' make the range +80 to +87. | |||||||||||||||
| 00918 | ADD A,128 | ||||||||||||||||
| 00920 | INC B | Return with a value from this range if neither shift key is being pressed. | |||||||||||||||
| 00921 | RET Z | ||||||||||||||||
| 00922 | XOR 15 | But if 'shifted' make the range +88 to +8F. | |||||||||||||||
| 00924 | RET | ||||||||||||||||
|
Finally consider the digit keys in 'K', 'L' and 'C' modes.
|
|||||||||||||||||
| K_KLC_DGT | 00925 | INC B | Return directly if neither shift key is being used. (Final codes +30 to +39.) | ||||||||||||||
| 00926 | RET Z | ||||||||||||||||
| 00927 | BIT 5,B | Use table 'd' if the CAPS SHIFT key is also being pressed. | |||||||||||||||
| 00929 | LD HL,560 | ||||||||||||||||
| 00932 | JR NZ,K_LOOK_UP | ||||||||||||||||
|
The codes for the various digit keys and SYMBOL SHIFT can now be found.
|
|||||||||||||||||
| 00934 | SUB 16 | Reduce the range to give +20 to +29. | |||||||||||||||
| 00936 | CP 34 | Separate the '@' character from the others. | |||||||||||||||
| 00938 | JR Z,K_AT_CHAR | ||||||||||||||||
| 00940 | CP 32 | The '_' character has also to be separated. | |||||||||||||||
| 00942 | RET NZ | Return now with the 'final codes' +21, +23 to +29. | |||||||||||||||
| 00943 | LD A,"_" | Give the '_' character a code of +5F. | |||||||||||||||
| 00945 | RET | ||||||||||||||||
| K_AT_CHAR | 00946 | LD A,"@" | Give the '@' character a code of +40. | ||||||||||||||
| 00948 | RET | ||||||||||||||||
| Prev: 00798 | Up: Map |