If memory serves, with a touch of Googling to refresh myself on the numbers...
The BIOS doesn't offer what you want. It's managing an input stream of text characters. Which is strongly related to catching key down events but will not allow you to tell which keys are depressed now, only which keys at some point weren't depressed and then became depressed in the past.
You need to use int 21h
, function 25h
to install your own handler for int 9h
. That way you'll get the key up and key down events directly from the hardware.
Within your handler, read port 60h
to determine why the interrupt has occurred. The low seven bits are a key code. If the top bit is clear then the key has transitioned to pressed. If the top bit is set then the key has transitioned to unpressed.
You then need to out 20h
to port 20h
to acknowledge the interrupt.
So you might keep a table of 128 bytes, initialised as all 80h
. In your handler, just store value
to value&7h
.
In your actual game code, if you want to know whether key n
is pressed at that moment, read the nth value from your table and branch on sign. Positive = pressed, negative = unpressed.
(Addendum: you should also get the existing vector when you launch and restore it before you exit, or else you've just accidentally written the hooking part of a TSR, probably without doing the SR part)