INT 16h, and Typematic Delay and Repeat


Over the last couple of years, I have aggravated players of my little games in a number of ways.

One of those way has been in how I handle input.

For simplicity of implementation, I typically trigger on a key press (i.e. a key on the keyboard goes from not being pressed to being pressed), and on a gamepad control release (i.e. a button, and DPAD directions work mostly like buttons, goes from being pressed to not being pressed).

Why was this annoying?

All of my game were controlled by tapping keys or buttons.

So I decided to listen to this feedback and pivot.

I remembered that keyboard have two types of delay associated with them.

When you press a key, you get a key in the buffer immediately.

Then there is a delay.

After the delay, the keyboard would start delivering new keys to the buffer at a particular rate.

So, I recalled from my ancient tribal knowledge of DOS that there was a key delay and a key repeat.

And that was what I decided I should implement in the game.

Both for gamepad as well as for keyboard.

It turns out that I don't need to use old and new captured state of the keyboard, as I no longer needed to check the transitions from not pressed to pressed to not pressed.

What I did need to track was when the next time the key would trigger an event.

I used a dictionary.

When a key (or button) is pressed, there is no entry in the next event table, so I just trigger the associated command.

When a key/button is released, i remove any entry from the next event table.

On the initial press, I put a value into the next event table.

When holding, I check against the next event table to see when I can trigger it again, and when I can, trigger the event and update the next event table.

Which means I didn't need the previous state of the device. Effectively, the next event table takes its place.

So this made the implementation quite simple, but what values are regular keyboard input?

This was the part of the journey that was less straightforward.

I quickly found the keyboard control panel blade that allows me to set the delay (first timer) and repeat rate.

These don't have times in millisecond. They just have a number of settings between Fast and Slow.

So down that rabbit hole I went. I got a partial answer, but not a complete one.

This particular control panel blade harkens back to the ancient BIOS interrupts of yore.

In particular, INT 16h, AH=3h, AL=5h

The documentation(or the doc I found, anyway) tells me that the initial delay is 250, 500, 750, or 1000ms.

The documentation tells me that the value for the repeat rate in... an unknown unit that I thought might have been characters per second, but doesn't seem to be with the experiment I did.

All of that to say I came up with my initial delay of 1s, and my delay after the initial of 0.3s.

So that was a long way to go, But the real treasure was the friend I made along the way.

Oh, wait. I didn't make any friend on this particular journey.

No treasure for me.

Files

a-game-in-vbnet-about-yer-the-monster-and-starting-with-nothing-windows.zip 33 MB
Version 18 Jun 25, 2023
a-game-in-vbnet-about-yer-the-monster-and-starting-with-nothing-linux.zip 32 MB
Version 18 Jun 25, 2023
a-game-in-vbnet-about-yer-the-monster-and-starting-with-nothing-mac.zip 33 MB
Version 18 Jun 25, 2023

Get A Game in VB.NET About Yer the Monster and Starting with Nothing

Leave a comment

Log in with itch.io to leave a comment.