Now a call to 031E K TEST converts the key number into a_main_code, merely by looking it up in the table at 0205: the main code is the character code for a digit 30h to 39h a capital letter 41h to 5Ah ENTER 0Dh or space 20h the Extend mode shift 0Eh; marked SYMBOL SHIFT in the table in the notes, but its effect is always the E shift. The table has all the main codes arranged in order of key number. Now KEYBOARD introduces a_delay into the key response: see NB 2 below, and under 02BF KEYBOARD. Next a call to 0333 K DECODE converts the main code intoa_final_code, taking account of the shifts and the current inputmode: this can be any of the character or token codes, see NB 3 below. Finally KEYBOARD stores the final code in 5C08 LAST K and sets bit 5 of FLAGS, the "new key" signal. When a code from the keyboard is required, LAST K will be read by 10A8 KEY INPUT,set as the input routine for channel K by 15AF initial channel information. The key value, shift byte, main code and final code are all various kinds of_key_codes. In the notes this term usually means the final code. NB 1._Scanning_the_keyboard for the key value. Each of the eight input ports listed below gets input from one_line_of_keys - actually a half-line, containing five keys each. See the old Spectrum handbook, page 160, or the Plus 2 handbook, page 139. FEFE CAPS SHIFT -> V FE = 11111110 FDFE A -> G FD = 11111101 FBFE Q -> T FB = 11111011 F7FE 1 -> 5 F7 = 11110111 EFFE 0 -> 6 EF = 11101111 DFFE P -> Y * DF = 11011111 BFFE ENTER -> H BF = 10111111 7FFE SPACE -> B 7F = 01111111 * Misprinted "P to 7" in the old handbook. Each half-line is scanned with an_initial_key_value, 2Fhfor the first, decrementing to 28h for the last. If a key is being pressed, the port will receive a byte which is all ones except for one of the bits zero -> 4, depending on its place in the line: bit zero for the outer key down to bit 4 for the one nearest the middle of the keyboard. The following table shows the hex number received for each key, its last five_key_bits in binary, and the initial key value IKV for each half-line. The first three key bits may have any values. Port IKV Key bits FEFE: 2F 11110b/FE 11101b/FD 11011b/FB 10111b/F7 01111b/EF C SHIFT Z X C V FDFE: 2E 11110b/FE 11101b/FD 11011b/FB 10111b/F7 01111b/EF A S D F G FBFE: 2D 11110b/FE 11101b/FD 11011b/FB 10111b/F7 01111b/EF Q W E R T F7FE: 2C 11110b/FE 11101b/FD 11011b/FB 10111b/F7 01111b/EF 1 2 3 4 5 EFFE: 2B 01111b/EF 10111b/F7 11011b/FD 11101b/FB 11110b/FE 6 7 8 9 0 DFFE: 2A 01111b/EF 10111b/F7 11011b/FD 11101b/FB 11110b/FE Y U I O P BFFE: 29 01111b/EF 10111b/F7 11011b/FD 11101b/FB 11110b/FE H J K L ENTER 7FFE: 28 01111b/EF 10111b/F7 11011b/FD 11101b/FB 11110b/FE B N M S SHIFT SPACE Later models of the Spectrum have extra keys, but use the same key bits: the extra keys merely duplicate the "old" keys with simultaneous shift operation. Now 0281 KEY BITS reduces the initial key value by 8 foreach bit starting from the right till the zero bit is found, resulting in the_key_values, also sometimes called_key_numbers, shown below: these numbers, from 00 = "B" to 26h/40d = "A", are the order in which the keys appear in the main key table (a) at 0205.