ASM Replacing scancodes with ASCII characters

旧时模样 提交于 2019-12-12 04:12:41

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/39743535/asm-replacing-scancodes-with-ascii-characters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!