You may also use polling to read from the keyboard without using interrupts (see code snippets below).
Make and break codes for each key depend on the scancode set:
Only scancode set 2 is widely supported and relatively free of bugs. However, the 8042 can be (and usually is) programmed to convert set 2 scancodes from the keyboard to set 1. The 8042 also handles some non-keyboard functions, such as resetting the CPU, controlling the A20 gate, and communicating with a PS/2 mouse.
104-key US keyboard | Set 1 scancodes | Set 2 scancodes | Set 3 scancodes |
105-key British keyboard (from Tim Robinson and Beth Stone) | Set 1 scancodes | Set 2 scancodes | Set 3 scancodes |
104-key German keyboard (this is guesswork) | Set 1 scancodes | Set 2 scancodes | Set 3 scancodes |
Polled keyboard input routine (does not use interrupts):
read_kbd: in al,64h ; read status byte and al,01h ; wait for OBF==1 jz read_kbd in al,60h ; read scancode byte ret
Enable A20 gate and verify it's on: see bootstrap code snippets
Turn on all three keyboard LEDs:
call kbd mov al,0EDh ; 8048 command byte to set LEDs out 60h,al call kbd ; b0 is ScrollLock, b1 is NumLock, b2 is CapsLock mov al,07h out 60h,al ... kbd0: jmp short $+2 in al,60h kbd: jmp short $+2 in al,64h test al,1 jnz kbd0 test al,2 jnz kbd retReset the PC:
; Warning: this function may not work unless A20 is enabled ; See http://my.execpc.com/~geezer/osd/gotchas/index.htm#a20_reboot ; ; set the POST reset word at 0040h:0072h ; 0000h for cold boot, 1234h to bypass memory test (warm boot) mov ax,40h mov es,ax mov ax,0 mov [es:72h],ax ; bit b0 of the 8042 'Output Port' drives the CPU reset line ; pulse it low to reset the system call kbd ; kbd routine above mov al,0FEh ; 8042 command byte to pulse Output Port pin out 64h,al
- converting scan codes to ASCII, Unicode, UTF, etc.