ASM 用 ASCII 字符替换扫描码
ASM Replacing scancodes with ASCII characters
我有这个代码:
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
它会检查按键,每次我按下一个键,我都会将它保存到 register al 然后想打印出来。
但只有扫描码被保存,我需要用 ASCII 字符替换它,我用数组 'key' 这样做,但它不起作用,只打印出 1 个键和那么程序就滞后了。
我通过分离 keydowns 和 keyups 来修复它
代码:
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
我有这个代码:
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
它会检查按键,每次我按下一个键,我都会将它保存到 register al 然后想打印出来。
但只有扫描码被保存,我需要用 ASCII 字符替换它,我用数组 'key' 这样做,但它不起作用,只打印出 1 个键和那么程序就滞后了。
我通过分离 keydowns 和 keyups 来修复它 代码:
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