How MS-DOS 6.22 Handles BIOS Keyboard Interrupts
This article explains the multi-layered process by which MS-DOS 6.22 processes keyboard input, tracing execution from physical keypresses up through system BIOS interrupts to DOS API calls. In MS-DOS 6.22, input handling relies on a cooperative chain between hardware interrupts (IRQ1/INT 09h), BIOS software services (INT 16h), and DOS kernel routines (INT 21h), ensuring backward compatibility with IBM PC architecture while providing structured keyboard services to user applications.
The Hardware Interrupt Layer (INT 09h)
When a key is pressed or released, the physical keyboard sends a make or break scan code to the system's keyboard controller (typically an Intel 8042 or compatible chip). The controller asserts the IRQ1 line on the Programmable Interrupt Controller (PIC), which vectors to CPU interrupt INT 09h.
The BIOS provides the default handler for INT 09h. This routine executes the following steps:
- Reads the raw scan code directly from I/O port
60h. - Acknowledges the hardware interrupt and sends an End of Interrupt
(EOI) command to the PIC at port
20h. - Evaluates modifier keys (Shift, Ctrl, Alt, Caps Lock, Num Lock) and
updates the BIOS Data Area (BDA) keyboard flag byte at memory address
0040:0017h. - Translates valid scan codes into a two-byte sequence consisting of the ASCII character code and the original scan code.
- Stores this two-byte pair into the BIOS keyboard circular buffer,
located at
0040:001Ehto0040:003Dh. If the buffer is full, the BIOS typically emits a hardware beep and discards the keypress.
The BIOS Software Service Layer (INT 16h)
The BIOS provides the INT 16h interface as a standard API to allow the operating system and applications to read from the keyboard buffer without interacting directly with port hardware or interrupt flags.
MS-DOS 6.22 primarily relies on two standard INT 16h functions:
- AH = 00h (or 10h for extended keyboards): Wait for
and read the next character from the circular buffer. This call blocks
execution until a key is available, advances the buffer head pointer,
and returns the ASCII character in the
ALregister and the scan code in theAHregister. - AH = 01h (or 11h for extended keyboards): Check the
status of the keyboard buffer without blocking. It sets or clears the
Zero Flag (ZF) to indicate whether a keystroke is waiting and previews
the character in
AXwithout removing it from the buffer.
The MS-DOS 6.22 Layer (INT 21h)
MS-DOS 6.22 abstracts the BIOS layer by exposing console input
functions via INT 21h, mediated by the standard input
device driver (CON) in IO.SYS. When a DOS
application requests keyboard input, MSDOS.SYS processes
the command by issuing calls to INT 16h.
Common INT 21h keyboard functions mapped to BIOS calls include:
- AH = 01h (Character Input with Echo): Invokes BIOS INT 16h (AH=00h) to retrieve a character, checks for termination conditions, and routes the character through DOS video services to display it on the screen.
- AH = 06h (Direct Console I/O): When invoked with
DL = FFh, DOS issues BIOS INT 16h (AH=01h) to poll for waiting input, immediately returning control to the application without blocking if no key is present. - AH = 07h and AH = 08h (Character Input without
Echo): Directly retrieves the keycode via BIOS INT 16h (AH=00h)
and returns it in
ALwithout rendering it to the display. Function 08h also inspects the character for Ctrl+C. - AH = 0Ah (Buffered Input): Repeatedly calls BIOS
INT 16h to populate a designated memory buffer with characters until an
Enter key (ASCII
0Dh) is received, handling backspace functionality internally.
Break Handling and Device Interception
MS-DOS 6.22 monitors the BIOS data area and interrupt stream for control characters. If the user presses Ctrl+Break, the INT 09h BIOS handler triggers INT 1Bh. The default MS-DOS handler intercepts this vector, flags an internal break condition, and subsequently routes execution to INT 23h, allowing either DOS or the running application to terminate gracefully.
When utilities such as KEYB.COM (keyboard localization)
or ANSI.SYS are loaded in MS-DOS 6.22, they intercept the
standard execution path by hooking into INT 09h or
INT 16h. This allows DOS to remap characters according
to regional code pages or inject extended escape sequences before
passing the finalized input data to the standard INT 21h file and
console pipelines.