Tuesday, October 30, 2012

Keyboard Buffer


A part of the PC’s BIOS data area i.e., memory at segment 0040h is used as keyboard buffer. This area also holds pointers to keyboard buffer and key status.


The keyboard buffer is organized as a circular queue. It has four 2-byte wide pointers: kbufbegin, kbufend, kbufhead and kbuftail. Here you should note one important thing: these pointers are just 2-byte wide (not 4-byte wide), which means these pointers hold only the OFFSET address (all are at segment 0040h). kbufbegin and kbufend points to the beginning and end of the keyboard buffer and these pointers do not move. Whereas the  kbufhead and kbuftail points to the character on the keyboard buffer and so these pointers do move.

 
Keyboard buffer is a character (i.e., 1 byte wide) array. The size of the keyboard buffer may vary from system to system. Some people say that the size of the keyboard buffer is 32 bytes, which is wrong, because the size of the keyboard buffer can be changed. Keyboard buffer holds ASCII code and scan code on alternate bytes.
 
Whenever a key is been inputted through keyboard, it is being temporarily stored in  keyboard buffer, before it is processed by the BIOS. When we try to input more keystrokes, we will get a beep sound indicating that the keyboard buffer is full. The pointer kbuftail points to the recently inputted key and the pointer  kbufhead points to the key that is being currently processed. So when the keyboard buffer is empty, the pointer kbufhead and kbuftail holds the same address (i.e., points to the same data).

DOS Memory Map

Reference for the students who are programming in C.

Location (hex)Purpose
00000 - 0003FFInterrupt vector area
INTPurpose
INT 0 - 780x86 vectors
INT 8 - F8259 INT controller vectors
INT 10 - 1FBIOS vectors
INT 20 - 2FDOS and network vectors
INT 30 - 3FDevice vectors (mouse, hard disk, etc.)
00400 - 00407COM1 - COM4 I/O port base addresses
00408 - 0040FLPT1 - LPT4 I/O port base addresses
00410 - 00411Equipment flag word, returned in AX by an INT 11h
BitPurpose
15 - 14Number of parallel printers (LPT1 - 4)
13Internal modem installed
12Joystick installed
11 - 9Number of serial ports (COM1 - 4)
8Unused
7 - 6Number of disk drives
5 - 4Video mode
3 - 2Unused
1Math coprocessor installed
0Disk installed
00413 - 00414Memory size in kilobytes (0 - 640K)
00417Keyboard control byte
BitPurpose
7Insert locked
6Caps locked
5Numbers locked
4Scroll locked
3Alternate key pressed
2Control key pressed
1Left shift key pressed
0Right shift key pressed
00418Keyboard control byte
BitPurpose
7Insert key pressed
6Caps key pressed
5Numbers lock key pressed
4Scroll lock key pressed
3Pause locked
2System req. key pressed
1Left Alt key pressed
0Right control key pressed
0041A - 0041BHead of keyboard buffer pointer
0041C - 0041DTail of keyboard buffer pointer
0041E - 0043D32-byte keyboard buffer
0043FDrive motor status, a 1 indicates a drive motor is running
BitPurpose
0Drive A
1Drive B
2Drive C
3Drive D
7some drive motor is running
00449Current video mode indicated by a 1-bit:
BitMode
040x25 monochrome
140x25 color
280x25 monochrome
380x25 color
4320x200 color
5320x200 monochrome
6640x200 monochrome
7monochrome
0044A - 0044BNumber of columns on the screen
0044C - 0044DSize of the video page buffer
0044E - 0044FStarting offset of the video buffer
00460 - 00461Starting and ending lined of the cursor
00462Currently displayed page
0046C - 0046FA double word timer incremented by INT 8 (in little endian order)
00475Number of hard disks on system
00480 - 00481Offset address for start of keyboard buffer
00482 - 00483Offset address for end of keyboard buffer
00496Keyboard mode state and type flags:
BitAction
0Last scan code was E1
1Last scan code was E0
2Right Ctrl pressed
3Right Alt pressed
4Extended keyboard installed
5Force NumLock if read ID and KBX
6Last code was ACK
7Read ID in progress
00497Keyboard LED flags:
BitLED
0ScrollLock
1NumLock
2CapsLock
00700 - 9FFFFProgram and Data area
04DB9Start of device drivers, Buffers, if in low memory
053F0Start of resident COMMAND.COM
A0000 - AFFFFEGA/VGA video buffer
B0000 - B0FFFMonochrome video buffer
B8000 - B0FA0Color text screen area
F0000 - FFFFFROM BIOS area