I have this code:
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
It checks for keypressess and everytime I press a key, I save it to register al and then wanna print it out.
But it is only the scancode that gets saved and i need to replace it with ASCII character, I do that with the array 'key', but it doesn't work and only prints out only 1 key and then the program just lags.
I fixed it by separating keydowns and keyups The code:
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