2021-06-08 12:25:17 +00:00
|
|
|
;Reads a keypress and prints its BIOS keycode.
|
2021-05-30 16:12:19 +00:00
|
|
|
|
|
|
|
keycode:
|
|
|
|
|
|
|
|
;Read a keypress
|
|
|
|
mov ah, 0x0
|
|
|
|
int 0x16
|
|
|
|
|
|
|
|
;Store the keycode
|
|
|
|
mov [.scan], ah
|
|
|
|
mov [.ascii], al
|
|
|
|
|
|
|
|
;Print the prefix
|
|
|
|
mov si, .prefix
|
|
|
|
call printstr
|
|
|
|
|
|
|
|
;Convert the scancode to a hex string
|
2021-06-10 15:16:14 +00:00
|
|
|
mov al, [.scan]
|
2021-05-30 16:12:19 +00:00
|
|
|
mov di, .keycode
|
2021-06-16 19:00:45 +00:00
|
|
|
call .byte2hex
|
2021-05-30 16:12:19 +00:00
|
|
|
|
|
|
|
;Convert the ascii value to a hex string
|
2021-06-10 15:16:14 +00:00
|
|
|
mov al, [.ascii]
|
2021-05-30 16:12:19 +00:00
|
|
|
mov di, .keycode
|
|
|
|
add di, 0x2
|
2021-06-16 19:00:45 +00:00
|
|
|
call .byte2hex
|
2021-05-30 16:12:19 +00:00
|
|
|
|
|
|
|
;Print the keycode
|
|
|
|
mov si, .keycode
|
|
|
|
call println
|
|
|
|
|
|
|
|
ret
|
|
|
|
|
2021-06-10 15:16:14 +00:00
|
|
|
.prefix db "0x", 0x0
|
2021-05-30 16:12:19 +00:00
|
|
|
|
2021-06-10 15:16:14 +00:00
|
|
|
.scan db 0x0
|
|
|
|
.ascii db 0x0
|
2021-05-30 16:12:19 +00:00
|
|
|
|
2021-06-10 15:16:14 +00:00
|
|
|
.keycode times 0x5 db 0x0
|
2021-06-16 19:00:45 +00:00
|
|
|
|
|
|
|
.byte2hex:
|
|
|
|
|
|
|
|
;Store the initial registers in the stack
|
|
|
|
push si
|
|
|
|
push ax
|
|
|
|
push bx
|
|
|
|
push cx
|
|
|
|
|
|
|
|
;Move the byte to AH
|
|
|
|
mov ah, al
|
|
|
|
|
|
|
|
;Set a key for the hex digits
|
|
|
|
mov si, .key
|
|
|
|
|
|
|
|
;Set a counter for the two hex digits
|
|
|
|
mov cx, 0x2
|
|
|
|
|
|
|
|
.loop:
|
|
|
|
|
|
|
|
;Read a nibble
|
|
|
|
rol ax, 0x1
|
|
|
|
rol ax, 0x1
|
|
|
|
rol ax, 0x1
|
|
|
|
rol ax, 0x1
|
|
|
|
mov bx, ax
|
|
|
|
|
|
|
|
;Convert the nibble to a hex digit
|
|
|
|
and bx, 0xf
|
|
|
|
mov bl, [si + bx]
|
|
|
|
|
|
|
|
;Store the hex digit
|
|
|
|
mov [di], bl
|
|
|
|
|
|
|
|
;Repeat
|
|
|
|
inc di
|
|
|
|
dec cx
|
|
|
|
jnz .loop
|
|
|
|
|
|
|
|
;Load the initial registers from the stack
|
|
|
|
pop cx
|
|
|
|
pop bx
|
|
|
|
pop ax
|
|
|
|
pop si
|
|
|
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
.key db "0123456789abcdef"
|