IRQ1 signals data available at port 0x60 (scan code) and status in port 0x64. The ISR should read the byte, translate with a table if needed, and buffer it for the main loop. For example, scan code 0x1E is the make code for the 'A' key; 0x9E is the break code with high bit set on older sets.
Minimal ISR flow
nasm
Loading…
Scan code set 1/2/3: Layout differs; PC AT uses set 1
Shift/ctrl: Track modifier bytes separately from letters
Controller command: Port 0x64 bit 0 set means output buffer full
Do not call blocking BIOS from ISR; buffer only
Scan code sets
Set 1 uses make/break with bit 7 set on release; set 2 uses 0xF0 prefix bytes. The 8042 may buffer multiple bytes during fast typing; drain port 0x60 until empty inside the ISR or risk losing edges. Do not translate to ASCII inside the ISR if you use a complex layout table; store raw bytes and translate in the main loop where floating point and division are allowed.
Why for this exercise
You will handle IRQ1, read scan codes from port 0x60, and store them in a ring buffer. This exercise requires PIC EOI and non-blocking work inside the handler.
Decode a Scan Code Set 1 keystroke sequence in C, exactly what a PS/2 keyboard ISR does before buffering characters.
Input format:
Line 1: N, the number of scancode bytes.
Then N hex bytes (one per whitespace-separated token), e.g. "1E" is the make code for 'a', "9E" its break code.
Requirements:
Break codes have bit 7 set; modifiers are tracked on both makes and breaks.
Modifiers: left/right Shift (0x2A/0x36 make, 0xAA/0xB6 break) count presses; Ctrl (0x1D/0x9D) and Alt (0x38/0xB8) are flags; Caps Lock (0x3A make) toggles its state.
Translate make codes to ASCII with a US set-1 table: letters use case = Shift XOR Caps Lock; shifted punctuation uses the shifted column (e.g. 0x02 -> '1' or '!'). Enter (0x1C) emits a newline and Tab (0x0F) a tab.
Unknown scancodes and break codes of character keys produce nothing.
Output: "line: <decoded>" followed by "state: shift=<0|1> caps=<0|1> ctrl=<0|1> alt=<0|1>".