Code: Select all
;______________________________________________________________________________________________________
;Wait for keyboard keypress
;IN: nothing
;OUT: CF sets on keyup and CF clears on keydown
; AL ASCII code
; AH SCAN code
waitKeyboard:
push ebx
mov byte[kbdHandler.keyboardChanged], 0
.keyLoop:
cmp byte[kbdHandler.keyboardChanged], 1 ;Check if key press
jne .keyLoop
mov ah, bl ;BL contains scancode
mov al, ah
bt ax, 7 ;Check if keyup
jc .end
;Check if shift is pressed
cmp al, 54 ;Right shift key
je .shiftSet
cmp al, 42 ;Left shift key
je .shiftSet
jmp .next
.shiftSet:
mov byte[.shiftFlag], 1 ;.shiftFlag variable indicated weather shift is pressed or released
mov al, 0
stc
jmp .actualEnd
.next:
cmp byte[.shiftFlag], 1 ;Use shift key characters if shift is pressed
je .shiftIsSet
movzx ebx, al
add ebx, .keys ;Index scan code in Keys array
mov al, byte[ebx]
clc
jmp .actualEnd
.shiftIsSet:
movzx ebx, al
add ebx, .keysShift ;Index scan code in shift-Keys array
mov al, byte[ebx]
clc
jmp .actualEnd
;Now we have to check if shift is released
.end:
stc
cmp al, 182 ;Right shift released
je .noShift
cmp al, 170 ;Left shift released
je .noShift
mov al, 0
stc
jmp .actualEnd
.noShift:
mov al, 0
mov byte[.shiftFlag], 0
stc
.actualEnd:
pop ebx
ret
;--------Variables----------;
.shiftFlag:
db 0
.keys:
db 27,0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', 8, 9, 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']'
db 13, 29, 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', "'", '`', 42, '\', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/'
db 54, 55, 56, ' '
.keysShift:
db 27,0, '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', 8, 9, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}'
db 13, 29, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '"', '~', 42, '|', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?'
db 54, 55, 56, ' '
;_________________________________________________________________________________________________
Code: Select all
Keyboard interrupt IRQ 1
kbdHandler:
push eax
xor eax,eax
in al,0x60
.next:
cmp byte[.keyboardChanged], 0 ;If any code is waiting for keyboard
je .send ;send it in BL
jmp .end
.send:
mov bl, al
.end:
mov byte[.keyboardChanged], 1
mov al, 0x20
out 0x20, al
pop eax
iret
.keyboardChanged: db 0
Any suggesions?