我有这段代码:
bits 16
org 0x7C00
start: jmp main
key: dw 0x1e, 'a', 0x30, 'b'
print:
mov ah, 0x0E
int 0x10
keyboard:
cli
in al, 0x64
test al, 1
jz return
test al, 0x20
jnz return
in al, 0x60
call convert
call print
sti
convert:
mov bx, 0
.LOOP:
cmp al, [key+bx]
je .conv
add bx, 2
jmp .LOOP
.conv:
mov al, [key+bx+1]
ret
return:
ret
main:
call keyboard
jmp main
times 510 - ($-$$) db 0
dw 0xAA55
它检查keypressess,每次按一个键,我将它保存到注册al,然后想要打印出来。
但是只有扫描码被保存,我需要用ASCII字符替换它,我用数组'key'来做,但它不起作用,只打印出一个键然后程序只是滞后。
答案 0 :(得分:0)
我通过分离keydowns和keyup来修复它 代码:
bits 16
org 0x7C00
mov cl, 0
start: jmp main
keydown: db 0x1e, 'a', 0x30, 'b'
keyup: db 0x9e, 'a', 0xb0, 'b'
print:
mov ah, 0x0E
int 0x10
keyboard:
cli
in al, 0x64
test al, 1
jz return
test al, 0x20
jnz return
in al, 0x60
cmp cl, 0
je keypress
jmp keyrelease
keyrelease:
mov cl, 0
sti
ret
keypress:
mov cl, 1
call convert
call print
sti
ret
convert:
mov bx, 0
.LOOP:
cmp al, [keydown+bx]
je .conv
add bx, 2
jmp .LOOP
.conv:
mov al, [keydown+bx+1]
ret
return:
ret
main:
call keyboard
jmp main
times 510 - ($-$$) db 0
dw 0xAA55