问题
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:
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...
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