Skip to main content

Input queue

The gamepad buttons are read directly, which has some inaccuracies if the IO address is not polled frequently enough.

For keyboard input, such inaccuracies could cause fast keystrokes to be missed. This is solved by receiving keystrokes as an input queue which can store up to 16 events until the program reads them. In the future, this queue may also be used for other input devices, as distinguished by the IO_INPUT_EVENT::KIND field.

Each event includes both an KEYID field indicating the physical keyboard button, as well as a HASCII field indicating the HASCII character number.

Reading the queue

Whenever an input event occurs, it is first written to IO::INPUT_QUEUE[IO::INPUT_QUEUE_END_INDEX], and then IO::INPUT_QUEUE_END_INDEX is incremented. Instead of reaching 16, the index wraps back to 0. A program can read these events by polling for changes in IO::INPUT_QUEUE_END_INDEX. The Hybrix framework CONSOLE::READ_KEY() function implements such an algorithm.

I/O definitions

CLASS IO_INPUT_EVENT # SIZE 4
# 0 = KEY DOWN
# 1 = KEY REPEAT
# 2 = KEY UP
# 3 = RESYNC; ALL KEYS UP
VAR KIND: BYTE

# IDENTIFIES THE KEYBOARD BUTTON, OR 0 FOR ALTERNATE INPUT SOURCES
VAR KEYID: BYTE

# IDENTIFIES THE TRANSLATED HASCII, OR 0 FOR KEYS THAT DON'T TYPE ANYTHING
# RIGHT NOW THE HIGH BYTE IS ALWAYS 0, BUT IN THE FUTURE IT WILL BE USED
# FOR UTF-16 CHARACTERS
VAR HASCII: PAIR
END CLASS

MODULE IO
. . .
VAR INPUT_QUEUE_END_INDEX: BYTE LOCATED AT $D0_003F
INSET INPUT_QUEUE: IO_INPUT_EVENT[INSET 16] LOCATED AT $D0_00C0 # ..$D0_00FF
. . .
END MODULE