Read keypress status for multiple keys?

All aspects of programming on the Commander X16.
Post Reply
mwiedmann
Posts: 72
Joined: Fri Jan 20, 2023 2:21 am
Location: New York City

Read keypress status for multiple keys?

Post by mwiedmann »

Is there a way to read the keypress status of multiple keys on the CX16? I need to read the status of multiple keys at the same time. Meaning for instance, I want to know if they are pressing W, E, and R. Or know that they are NOT pressing R.

The kernal functions seem to use a buffer.
TomXP411
Posts: 1806
Joined: Tue May 19, 2020 8:49 pm

Re: Read keypress status for multiple keys?

Post by TomXP411 »

What you have to do is trap the raw PS/2 events, then build your own table of key up/down states.

There are around 88 keys on the board, so you could either create a byte array of 88 bytes, or you could allocate 11 bytes and use a bitmap to track the 88 keys. The byte array is faster, so that's probably the way to do it - unless those 77 bytes become critical.

I don't know the PS/2 system well, but I know you can set a vector to trap the key up/down events. You can then run custom code to handle the keypress.

If you can get the scancode into the X register, you can then used indexed writes to save the key state into the key table:

For a key that was just pressed:
LDA #1
STA KEY_TABLE,X

For a key that was just released
LDA #0
STZ KEY_TABLE,X

Again, I don't know anything about the keyboard handler, so hopefully someone that has actually done this will chime in.
Stefan
Posts: 465
Joined: Thu Aug 20, 2020 8:59 am

Re: Read keypress status for multiple keys?

Post by Stefan »

There’s documentation for the custom key code handler Tom was referring to here:

https://github.com/X16Community/x16-doc ... 0Editor.md

Previously the handler was fed regular PS/2 scan codes, but from R43 it’s simplified. Each key is now represented by a 7 bit code. The last bit indicates key down (0) or up (1).

There’s also a link to the key code list in the documentation.
Post Reply