Recently I had an opportunity to reacquaint myself with the DOS KEYB utility. KEYB is interesting in that it is designed primarily for international users, but one can also run KEYB US
to load KEYB with standard US layout.
It is obvious that the KEYB utility was written by IBM. Unlike most of DOS, KEYB not only uses documented BIOS interfaces, but makes quite a few assumptions about how the keyboard BIOS works internally, in ways that were never documented.
This starts when KEYB loads and needs to detect whether the system BIOS supports extended keyboards or not—that is, whether the BIOS supports INT 16h functions 10h and 11h. To do that, KEYB calls INT 16h function 92h. Which is not, in fact, a BIOS function at all.
Rather, KEYB knows exactly how the IBM INT 16h implementation works. KEYB expects that when encountering an unsupported (too high) function, BIOS INT 16h keeps decrementing register AH until it decides that it’s too low, and then returns with that modified AH. On systems with extended keyboard support (newer PC/AT systems and most later machines), AH will be decremented to 80h. On old systems, AH will be decremented to somewhere around 8Eh. On machines with 122-key support, AH will be decremented even further, below 80h. In any case, KEYB executes INT 16h/92h and if the resulting AH value is 80h or less, it assumes that extended keyboard BIOS should be enabled.
Because KEYB “knows” exactly how the keyboard BIOS works, it gets away with only overriding half of it. While KEYB installs an INT 9h handler (corresponding to IRQ 1, or the keyboard hardware interrupt), it leaves INT 16h (the user callable BIOS keyboard service) untouched. In fact, the INT 9h handler in KEYB clearly started its life as a copy of the INT 9h handler in the IBM PC/AT BIOS, which only IBM could legally do.
Continue reading