Code: Select all
ORG 100
;http://www.osdever.net/documents/wout_kbd.php?the_id=15
;http://plumeria.vmth.ucdavis.edu/~saintly/newbie/expertcentral/closed/91645.html
KBD_OBF equ 1
KBD_IBF equ 2
KBD_GTO equ 0x40
KBD_PERR equ 0x80
KBD_DATA_REG equ 0x60
KBD_CNTL_REG equ 0x64
KBD_STATUS_REG equ 0x64
KBD_CMND_SELF_TEST equ 0xAA
start:
mov ah,9
mov dx,startMSG
int 0x21 ;Tell the user what this is.
;I'm testing the kb now, so stop sending any signals making the computer think it's a keyboard stroke
cli
;Flush it
call kbd_wait_for_input
mov ah,9
mov dx,KBTesting
int 0x21
mov al,KBD_CMND_SELF_TEST
mov dx,KBD_CNTL_REG
call kbd_write
call kbd_wait_for_input
cmp al,0x55
jz good
; mov [BadMSG],al
mov ah,9
mov dx,BadMSG
int 0x21
jmp short next
good:
mov ah,9
mov dx,GoodMSG
int 0x21
next:
;The testing is done. The keyboard is ready for sending anything.
sti
xor ax,ax
int 0x16
int 0x20 ;done
kbd_wait_for_input:
in al,KBD_STATUS_REG
mov ah,al
; Wait for input data to become available. This bit will
; then be cleared by the following read of the DATA
; register.
and al,KBD_OBF
jnz kbd_wait_for_input
in al,KBD_DATA_REG
; Check to see if a timeout error has occurred. This means
; that transmission was started but did not complete in the
; normal time cycle. PERR is set when a parity error occurred
; in the last transmission.
and ah,KBD_GTO | KBD_PERR
jnz kbd_wait_for_input
ret
kbd_write:
push ax
again:
in al,KBD_STATUS_REG
and al,KBD_IBF
jnz again
pop ax
out dx,al
ret
startMSG db "Veniamin's Keyboard Program Thing.. (Direct IO stuff) :)",10,13,"$"
KBTesting db "Keyboard self test...$"
GoodMSG db "Successfull :)",10,13,"$"
BadMSG db "Unsuccessfull :(",10,13,"$"