Key Handlers in assembly
im working on a project in witch the program has to do a few lines of code when specific keys are down (pressed) i have tried using Ah 1 int 21 and AH 1 int 16 and direct connect to keyboard with in al , 60h
but all of these seem to have one big problem . if the user press more than one key at a time the program fails to detect that . what i really need is reading the input buffer in a loop and executing code for specific keys .
This Code Sample runs at my main loop every frame:
;in al,60h
;mov cl,al
;in al,61h
;mov ah,al #Tried this didn't work...
;or al,80h
;out 61h,al
;mov al,ah
;out 61h,al
;mov al,cl
xor bx, bx
_poll_key:
mov ah, 01h
int 16h
jz _poll_key
xor ah, ah
int 16h
mov bl, al
call dispatch_key
jmp _poll_key
dispatch_key:
mov al , ah
;________________________________________
cmp al , 11h ; W HexScanCode
jne NotW
sub rbx , 160
mov ah , red
mov bx , rbx
mov es:[bx] , ah
NotW:
cmp al , 1Fh; S HexScanCode
jne NotS
add rbx , 160
mov ah , red
mov bx , rbx
mov es:[bx] , ah
NotS :
cmp al , 20h; D HexScanCode
jne NotD
add rbx , 2
mov ah , red
mov bx , rbx
mov es:[bx] , ah
NotD:
cmp al , 1Eh ; A HexScanCode
jne NotA
sub rbx , 2
mov ah , red
mov bx , rbx
mov es:[bx] , ah
NotA:
;Second Player___________________________________________________________________
cmp al , 17h ; I HexScanCode
jne NotI
sub bbx , 160
mov ah , blue
mov bx , bbx
mov es:[bx] , ah
NotI:
cmp al , 25h ; K HexScanCode
jne NotK
add bbx , 160
mov ah , blue
mov bx , bbx
mov es:[bx] , ah
NotK:
cmp al , 26h ; L HexScanCode
jne Notl
add bbx , 2
mov ah , blue
mov bx , bbx
mov es:[bx] , ah
Notl:
cmp al , 24h; J HexScanCode
jne Notj
sub bbx , 2
mov ah , blue
mov bx , bbx
mov es:[bx] , ah
Notj:
cmp al , 10h ; Q HexScanCode
je finish
;;;;;;;;;;;;;;;;;;;
;First Player
mov ah , blue
mov bx , bbx
;UP
sub bx , 160
mov es:[bx] , ah
add bx , 160
;Down
add bx , 160
mov es:[bx] , ah
sub bx , 160
;Right
add bx , 2
mov es:[bx] , ah
sub bx , 2
;Left
sub bx , 2
mov es:[bx] , ah
add bx , 2
;Second Player
mov ah , red
mov bx , rbx
;Up
sub bx , 160
mov es:[bx] , ah
add bx , 160
;Down
add bx , 160
mov es:[bx] , ah
sub bx , 160
;Right
add bx , 2
mov es:[bx] , ah
sub bx , 2
;Left
sub bx , 2
mov es:[bx] , ah
add bx , 2
;
this code can only handel one key at a time... Witch is not what im looking for
here's some blueprints of how an optimal solution would look:
loop:
LoopUntilInputBufferEmpty:
;{get ACII / ScanCode From Input Buffer}
cmp al , {...}
jne KeyHandel1
;Code
KeyHandel1
cmp al , {...}
jne KeyHandel2
;Code
KeyHandel2
cmp al , {...}
jne KeyHandel3
;Code
KeyHandel3:
cmp {bufferEmpty?} , {Yes}
jne LoopUntilBufferEmpty
;
;{All Main Loop Code}
jmp loop
SHORT: Handeling a few key pressed at the same time
Any one know of a way to achive that ?
-Thanks Ahead
链接地址: http://www.djcxy.com/p/62706.html上一篇: HttpWebResponse LastModified
下一篇: 装配中的关键处理程序