扫描键盘以获取扫描代码

时间:2014-07-28 05:28:04

标签: assembly keyboard operating-system x86 osdev

所以我正在学习如何制作操作系统。 问题是每个网站都说扫描键盘以获取扫描码以检测输入。 如何“扫描”键盘? 我知道这个问题看起来很荒谬,但我真的不知道该怎么做,我需要帮助。我还要提一下,我搜索了很多。

1 个答案:

答案 0 :(得分:0)

不使用ISR(x86-CPU)轮询键盘端口的示例:

cli
mov  al, 2               ; dissable IRQ 1
out  21h, al
sti
;---------------------------------------------
AGAIN:
in   al, 64h             ; get status byte 
test al, 1               ; check outputbuffer
jz  short NOKEY
test al, 20h             ; PS2-Mouse byte?
jnz short NOKEY
in   al, 60h             ; get scancode (makecode or breakcode)

; place your code here for comparing.....

NOKEY:
jmp AGAIN
;---------------------------------------------
QUIT:
cli
xor  al, al              ; enable IRQ 1
out  21h, al
sti
;---------------------------------------------
; DATA 
TASTTAB DB 02h,03h,04h,05h,06h,07h,08h,09h,0Ah,0Bh,0Ch,0Dh
        DB 10h,11h,12h,13h,14h,15h,16h,17h,18h,19h,1Ah,1Bh,1Eh,1Fh
        DB 20h,21h,22h,23h,24h,25h,26h,27h,28h,29h,2Bh,2Ch,2Dh,2Eh,2Fh
        DB 30h,31h,32h,33h,34h,35h,39h
        DB 56h
tablen =  ($-TASTTAB)

TEXTTAB DB "1234567890ß'"      ; (using german letters)
        DB "qwertzuiopü+as"
        DB "dfghjklöä^#yxcv"
        DB "bnm,.- "
        DB "<"
textablen  =  ($-TEXTTAB)

在ISR中,只需使用“ in al,60h ”来获取扫描码。