ASM用ASCII字符替换扫描代码 [英] ASM Replacing scancodes with ASCII characters

查看:177
本文介绍了ASM用ASCII字符替换扫描代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有此代码:

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,然后再将其打印出来.

It checks for keypressess and everytime I press a key, I save it to register al and then wanna print it out.

但是只保存了扫描代码,我需要用ASCII字符替换它,我使用数组'key'来做到这一点,但是它不起作用,仅打印出1个键,然后程序仅输出滞后.

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

这篇关于ASM用ASCII字符替换扫描代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆