2

I'm familiar with INT 16h that waits for keyboard input, but I'm developing a game and I would like there to be a game loop, that animates things on the screen, and whenever there is a keyboard hit, the 8086 should go to my interrupt handler and tell me which key has been pressed to update my data accordingly.

How could I do so ?

nrz
  • 10,435
  • 4
  • 39
  • 71
Belbesy
  • 117
  • 1
  • 2
  • 10

2 Answers2

4

You can also poll for input with 1 in AH instead of 0, when calling INT 16.

INT 16h / AH = 01h - check for keystroke in the keyboard buffer.

    return:

        ZF = 1 if keystroke is not available.
        ZF = 0 if keystroke available.
        AH = BIOS scan code.
        AL = ASCII character.
        (if a keystroke is present, it is not removed from the keyboard buffer). 

(Source.)

Prof. Falken
  • 24,226
  • 19
  • 100
  • 173
2

In MS-DOS you can write your own custom keyboard interrupt handler, and in your custom keyboard interrupt handler code you can, for example:

  1. set a flag to inform the main loop/draw loop that a key has been pressed, together with the scan code of the key, or...

  2. Modify the code of the main loop/draw loop in your custom interrupt handler according to the scan code of the key.

For more info on writing a custom [keyboard] interrupt handler, see eg.:

Community
  • 1
  • 1
nrz
  • 10,435
  • 4
  • 39
  • 71