Reputation: 1
I have a doubt because my code is not working. I'm implementing a bootloader that runs the code below, when I try to load it only works in a few cases, like I explain below. My code is the next one:
ChangeGameState:
mov cx, 00H ;Here I make a delay
mov dx, 3240H ;.
mov ah, 86H ;.
int 15h ;.
jmp DetectKeyPress
DetectKeyPress:
mov ah, 01h
int 16h
jz noKeyInBuffer
xor ah, ah
int 16h
jmp exitKeyPress
noKeyInBuffer:
xor ax, ax
exitKeyPress:
jmp ProcessKey
ProcessKey:
cmp ah, 0
je ExitKey
cmp ah, 'd'
je ChangeDir1
cmp ah, 's'
je ChangeDir2
cmp ah, 'a'
je ChangeDir3
cmp ah, 'w'
je ChangeDir4
ExitKey:
jmp ChangeGameState
ChangeDir1:
;DO SOMETHING1
jmp ChangeGameState
ChangeDir2:
;DO SOMETHING2
jmp ChangeGameState
ChangeDir3:
;DO SOMETHING3
jmp ChangeGameState
ChangeDir4:
;DO SOMETHING4
jmp ChangeGameState
Now, when I try to press keys S, A and W it doesn't works, only if I press D key.. Any idea of what's going on??
Upvotes: 0
Views: 710
Reputation: 11706
The problem is that int 16h
returns the scancode in ah
, and the ASCII character in al
. So while your code is testing the scancode of the key, you should be testing the ASCII character.
So, in ProcessKey
, change cmp ah, ...
to cmp al, ...
.
Upvotes: 2