IBM AT keyboard controller trivia
These more-or-less random facts relate to the 8042 keyboard controller in the IBM AT.
XT keyboard support
The AT keyboard controller supports the XT keyboard protocol as well as its native one. This has been documented in a number of places, but always in fairly obscure terms. The Interrupt List, for example, refers to the feature as "use 8086 codes" or "IBM PC mode"; so does the Keyboard Scancodes page. It is, however, clearly documented in 8042 INTERN.
XT keyboard support must be switched on manually, by setting bit 5 of the controller command byte. On PS/2 and later computers, this bit is used to disable the mouse, so this feature is pretty certain not to work on any system with a PS/2 mouse.
On a real IBM 5170 AT, on the other hand, it works fine. The BIOS did not detect the XT keyboard and (for unrelated reasons) will not boot without a keyboard present, so I had to boot with an AT keyboard connected, switch XT support on, and hotplug the XT keyboard. This is obviously not an ideal solution, since IBM keyboards are not supposed to be hotplugged.
If you want to try this, KBXT.EXE will set/clear the appropriate bit of the command byte:
KBXT -- displays status. KBXT XT -- switches the keyboard controller into XT mode. KBXT AT -- switches the keyboard controller into AT mode.
The keylock only blocks scancodes that correspond to set 3 keys. That is, scancodes 00h-7Fh, plus 83h and 84h. Other scancodes, such as the 0E0h prefix from an enhanced keyboard, or the Windows keys on a keyboard using set 3, are still passed through to the BIOS.
Scancode translation table
At the time the AT keyboard controller was created, Scancode Set 2 did not exist — only Sets 1 and 3. The controller contains a 128-byte table, mapping from Set 3 scancodes to Set 1. This supports all 127 Set 3 keys, even though the AT keyboard can only return 89 of them.
Some notes on scancode sets:
- Set 3, at least on genuine IBM keyboards, is a position-based system. Various references, for example, say that the Set 3 scancode for F1 is 07h. The truth is a bit more complicated; 07h is the Set 3 scancode for the leftmost function key in the row of function keys immediately above the numbers. If the function keys are on the left, as on the AT keyboard, then F1 is in a different place and so returns a different Set 3 scancode (05h).
- It's commonly said that the AT keyboard uses Set 2. It doesn't; it uses a subset of Set 3. All the actual keys on the board have the same scancodes in Set 2 and Set 3, but the extra positions under double-size keys (for example, under the right-hand Shift key) return Set 3 scancodes.
The table below describes the position of each key using the 6110344 keyboard. To avoid ambiguity, the ten function keys on the left are referred to as L1-L10, and the 24 function keys at the top are referred to as PF1-PF24. For some keys, I have also said what key would be in that position on a standard 102-key keyboard.
Keys where the translated scancode is higher than 0x54 (SysRQ) are generally not present on the AT keyboard, though eight of them correspond to unused positions under double-size keys. The translated scancodes in this case are 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x7C and 0x57.
Except for two clear ranges (0x58-0x6E correspond to PF1-PF23, and 0x70-0x75 are unused positions in the main alphanumeric area) there seems to be no attempt to group related keys. I also can't explain why PF24 should be mapped to 0x76 rather than 0x6F, the next key in sequence after PF23.
|Key||Set 3 code||Set 1 code||Notes|
|Error code||0x00||0xFF||Error code|
|L7||0x02||0x41||Never seen on the wire; the keyboard sends 0x83 instead. The controller internally changes 0x83 back to 0x02 before translating it.|
|\ (between left shift and Z)||0x13||0x70|
|Between / and Right Shift||0x51||0x73|
|Key left of Return (ISO)||0x53||0x74|
|Key above Return (ANSI)||0x5c||0x75|
|Between + and Backspace||0x5d||0x2b|
|Backtab [Del on 102-key]||0x64||0x79|
|Insert [End on 102-key]||0x65||0x7a|
|PA1 [Ins on 102-key]||0x67||0x7b|
|Under keypad 0||0x68||0x7c|
|Del [PgDn on 102-key]||0x6d||0x7e|
|PA2 [Home on 102-key]||0x6e||0x7f|
|PA3 [PgUp on 102-key]||0x6f||0x6f|
|Keypad Esc [Numlock on 102-key]||0x76||0x01|
|Keypad NumLk [Keypad / on 102-key]||0x77||0x45|
|Under keypad Enter||0x78||0x57|
|Keypad - [under keypad + on 102-key]||0x7b||0x4a|
|Keypad ScrLk [Keypad * on 102-key]||0x7e||0x46|
|Keypad Space [Keypad - on 102-key]||0x7f||0x54||Never seen on the wire. The keyboard sends 0x84 instead. The controller internally changes 0x84 back to 0x7F before translating it.|
|Keypad Space [Keypad - on 102-key]||0x84||0x54|
John Elliott 3 April 2011.