home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Unsorted BBS Collection
/
thegreatunsorted.tar
/
thegreatunsorted
/
programming
/
misc_programming
/
kb
< prev
next >
Wrap
Text File
|
1990-01-04
|
9KB
|
170 lines
Chapter 5
Keyboard Services
-----------------
1. Introduction
The ROM BIOS contains two keyboard-related services, a Keyboard ISR and
a Keyboard DSR (see Figure 1-1):
* Keyboard ISR
The BIOS Keyboard Interrupt Service Routine (ISR) is invoked via
H/W INT 9h each time a key is pressed. The BIOS Keyboard ISR
processes keyboard data and converts it into information that is
useful to the system. In most cases, this conversion results in
the Keyboard ISR placing a two byte character code into the keyboard
buffer.
* Keyboard DSR
The BIOS Keyboard Device Service Routine (DSR) is invoked via S/W
INT 16h. The BIOS Keyboard DSR provides an interface through which
the operating system or application S/W can interface with the
keyboard buffer. The Keyboard DSR contains functions that read the
BIOS keyboard buffer, write to the buffer, return the status of the
buffer, and so on.
KB H/W ┌────────┐ ┌───────────┐ ┌────────┐ Request ┌──────┐
Interrupt │ KB ISR ├────>│ KB buffer │<─────>│ KB DSR │<─────────┤ │
(IRQ 1) │ │ └───────────┘ │ │ │ User │
──────────>│ INT 9 │ ┌───────────┐ │ INT 16 │ Data │ │
│ │<───>│ KB flags │<─────>│ │<────────>│ │
└────────┘ └───────────┘ └────────┘ └──────┘
BIOS Data
Figure 1-1. The relation between the Keyboard ISR and DSR
---------------------------------------------------------
2. Keyboard ISR (INT 9h) Operation
2.1 Keyboard H/W Architecture
Figure 2-1 shows the keyboard H/W architecture. The keyboard
controller 8042 support the PS/2 MOUSE and KEYBOARD SECURITY.
And the 8041 doesn't support the PS/2 MOUSE and KEYBOARD SECURITY,
it is used for supporting the standard PC/AT-compatible machine.
The code that is transferred between the 8042 and the keyboard is
in serial form through the DATA and CLK lines. Once the 8042
wants to send a code to the CPU, it generates IRQ 1 which invokes
the INT 9 Keyboard ISR.
┌─────────┐ ┌─────────────┐ KDATA ┌─────┐
│ │ │ Keyboard ├────────┤ │
│ │ DATA │ Controller │ KCLK │ KB │
│ │<════════════>│ ├────────┤ │
│ CPU │ │ 8042 │ └─────┘
│ │ Control │ (8041) ├─────────────────────┐
│ │═════════════>│ │ │
│ │ │ │ MDATA ┌-----┐ │
│ │<─┐ │ │--------| | │
└─────────┘ │ │ │ MCLK |MOUSE| │
│ │ │--------| | │
│ │ │ └-----┘ │
│ │ │--------┐ │
│ └─────────────┘ | │
│ | │
│ ┌─────────────┐ | │
│ │ Interrupt │ IRQ 12 | │
│ INT │ Control │<-------┘ │
└───────────┤ System │ │
│ │ IRQ 1 │
│ 8259 * 2 │<────────────────────┘
└─────────────┘
Figure 2-1. Keyboard H/W Architecture
-------------------------------------
2.2 Key Code
The code generated by the keyboard H/W is called "scan code". For
84-key keyboard, each key has one and only one scan code. For
101/102-key keyboard, the enhanced key simulates a sequence of
84-key keyboard scan codes plus some special code (E0h, E1h). The
scan code can be separated to two types: "make code" and "break
code". The keyboard H/W generates the key's make code each time the
key is pressed, and it generates the key's break code each time the
key is released. For PC-compatible key codes, the byte associated
with a key's break code is identical to the one associated with its
make code except that bit 7 is set.
2.3 Keyboard ISR Processing
The Keyboard ISR analyzes each scan code as follows:
* Codes generated by keyboard shift or toggle keys cause the
Keyboard ISR to update the keyboard flags:
017h -- byte -- keyboard flag 1
bit 7 = 1 -- Insert function active
bit 6 = 1 -- Caps Lock function active
bit 5 = 1 -- Num Lock function active
bit 4 = 1 -- Scroll Lock function active
bit 3 = 1 -- Alt key pressed
bit 2 = 1 -- Ctrl key pressed
bit 1 = 1 -- left Shift key pressed
bit 0 = 1 -- right Shift key pressed
018h -- byte -- keyboard flag 2
bit 7 = 1 -- Insert key pressed
bit 6 = 1 -- Caps Lock key pressed
bit 5 = 1 -- Num Lock key pressed
bit 4 = 1 -- Scroll Lock key pressed
bit 3 = 1 -- suspend (Pause key pressed) active
bit 2 = 1 -- System Request key pressed
bit 1 = 1 -- left Alt key pressed
bit 0 = 1 -- left Ctrl key pressed
* Codes that correspond to ASCII or special key values (e.g.,
function or edit keys) are converted into two byte character
codes and are placed in a 16 word keyboard buffer. Figure 2-2
shows the structure of the keyboard buffer, it's a ring queue.
Keyboard ISR place the character code to the keyboard buffer
pointed to by the KB tail, then increments KB tail by 1 word.
If KB tail is equal to the KB buffer End, it will wrap around to
the KB buffer Start. If keyboard buffer is full, Keyboard ISR
will issue a short beep and discard this character code.
KB buffer KB head KB tail KB buffer
Start │ │ End
│ │ │ │
V V V V
┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐
│ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
└───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┘
Figure 2-2. The structure of the keyboard buffer
------------------------------------------------
* Shift key combinations, such as Ctrl-Alt-Del, Ctrl-Alt-Esc, and
Ctrl-Alt-'+', are converted into requests for keyboard ISR
internal functions, such as Warm-Start, Setup, and Change-Speed.
3. Keyboard DSR (INT 16h) Operation
3.1 Scan Code/Character Code Combinations
The code placed to the keyboard buffer by Keyboard ISR is called
"scan code/character code combination", because most of the codes
contain a scan code and a character code. Keyboard DSR takes this
code and make some transformations for 84-key compatible code, then
passes the code to the caller.
3.2 Keyboard DSR Functions
The Keyboard DSR functions can be roughly separated in two parts:
standard functions and extended functions. Standard function
supports the 84-key compatible codes, and the extended functions
supports the 101/102-key extended codes. All the Keyboard DSR
functions are listed as follows:
(ah) = 0 Read key
(ah) = 1 Read status
(ah) = 2 Return current shift status
(ah) = 3 Set typematic rate
(ah) = 4 reserved
(ah) = 5 Write key
(ah) = 6 - 0fh reserved
(ah) = 10h Extented read key
(ah) = 11h Extented read status
(ah) = 12h Extented return current shift status
(ah) = 13h - 0ffh reserved