0

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

TomZe
  • 19
  • 2
  • 7
  • May this question and answer be of some help? https://stackoverflow.com/q/47115120/4271923 ... BTW, PC keyboards are notoriously known for being unreliable at reporting multiple keys, especially games like Mortal Kombat and similar (two players at keyboard with 3-4 keys at the same time) did suffer a lot from it, to the point, where they were unplayable (unless one player had joystick instead). Up to 3-4 keys at the same time it should mostly work, unless your keyboard has some special unfortunate combination which does not. – Ped7g Feb 11 '18 at 18:56
  • The common way (also in that Q+A) in DOS was to install your own keyboard interrupt handler, which does your own flag settings to keep key-map fresh for the code running in foreground (and this of course makes the BIOS interrupt inhibited, so don't call DOS services like "input string" or BIOS "get pressed key", as those will not receive anything as long as your keyboard handler is installed). Also make sure you understand what are "interrupt handlers", how they are installed/removed, and why that code should be minimal and very quick. – Ped7g Feb 11 '18 at 18:59
  • @Ped7g I feel like this is overkill to make my own interrupt . Any way to do that with that DOS/BiOS/PORT ? – TomZe Feb 11 '18 at 19:06
  • I case there isn’t. Can I get only the key Down input . I mean making long pressing the key not work and only checking for presses? – TomZe Feb 11 '18 at 19:09
  • no BIOS, the BIOS is handling keyboard as typewriter, so no multikeys. But if you need only single action per key press, then BIOS should actually work ok for you? Although it maybe sends the keypress upon release, not upon hit? What is your problem with buffered BIOS then exactly (usually low repeat rate is problem, plus making the buffer filled and beeping)? If you want just single keypress, you can create in your code shadow array of controls, which will refresh "last_state" during check, and detect key press only when last_state was 0 before, and now key is pressed from interrupt (0->1). – Ped7g Feb 11 '18 at 19:18
  • @Ped7g can you do a full answer on that idea ? , also note that I, not making mortal combat and the user shouldn’t except more than 2-4 keys to would at the same time .. – TomZe Feb 12 '18 at 05:14
  • @TomZe see [What is the best way to move an object on the screen?](https://stackoverflow.com/a/29579522/2521214) and pay attention to keyboard interrupt and the key maps ... – Spektre Feb 12 '18 at 08:14

0 Answers0