8086 listen to keyboard while drawing

半世苍凉 提交于 2019-12-14 02:29:30

问题


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 ?


回答1:


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.)




回答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.:

  • Is it possible to make a custom Interrupt in Assembly?
  • Replacing the Timer Interrupt Handler in DOS With GNU (GCC and GAS)
  • pages 31-39 of chapter 16 of some assembly tutorial
  • part 17.4 of Expert MS-DOS Programming


来源:https://stackoverflow.com/questions/13970325/8086-listen-to-keyboard-while-drawing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!