Page 1 of 1

Vice C64 Keyboard Missed Keystrokes

Posted: Sat May 14, 2022 6:20 pm
by Cube Inc
I went looking through the keyboard source code of Vice to see what I may learn therein, and I wanted to give you guys a bit of an update on what I have found so far. Some of this will probably be well known to some, but perhaps to others it will be new so I shall assume we all know nothing about the way keyboards and keyboard input on the C64 works and go from there.

Anyone who has opened up their Commodore 64 will have discovered a 20-pin ribbon cable of sorts connecting the keyboard mechanism from the top cover or "lid" of the '64 to the mainboard. The reason it has so many wires is that the keyboard keys are individual switches that form an electrical matrix - every time you press a key, you are causing an intersection between a row of data lines and a column of data lines. Which key you press will determine which data lines get connected together, and the C64 reads this information via one of its CIA interface chips.

Modern PC keyboards on the other hand, deliver the keystroke data as events - not as intersecting X/Y coordinates. Each time a key is pressed, this generates a down event with a keycode corresponding to the key that was pressed, and when you let up that key the keyboard controller generates an up event for that same keycode. These keycodes have to be converted into the appropriate characters or modifiers (like Shift, Control, Alt, Windows, etc.) and so they pass through a keyboard map that contains a list of the raw keycode values and the key names that those codes represent according to the region and style of the keyboard.

There is an option to enable both Keyboard debugging in VICE and Keyboard Mapping debugging in VICE. When turned on, VICE will add details about the specific keyboard events it receives from the operating system (the raw keycodes, not their mapped values) but what is interesting to observe is that with this debugging turned on, you can see that VICE receives the keyboard events, even when those key presses do not appear in the emulated C64.

I did find an interesting feature in VICE, where you can cause it to start up and to type [whatever text you want] into the emulated machine. Presumably this would be to trigger automatic loading and running of programs from the host operating system - perfect for having a BBS start and run automatically with the PC when it starts up. What was also interesting is that I found I could type a considerable amount of text into this feature and the '64 had all of the text I'd asked it to as though I had just magically typed it ridiculously fast. This would seem to indicate that there is a way to have keys stored in a buffer and then passed into the emulated CIA chip one key at a time in such a way that it correctly picks up each keystroke, even though they are input much faster than you or I could possibly do so. This could also lead to a problem.

I also noticed as I watched the keycodes fly by while typing that I often would down the next key before I had upped the last key. I started to wonder if this may have been part of the problem the '64 was encountering, because over time I have noticed that certain keys seem to get missed with more frequency than others: the 'e' of the word "the", for example, often gets missed. Looking at the CIA key map for the C64 (borrowed from here: https://ist.uwaterloo.ca/~schepers/MJK/ ... matrix.gif)

Image

'T' and 'E' both share the same data line on Port B.

That is all I have really dug into so far on this, but I have some ideas and a couple of things I'd like to try to see if I might improve the detection of individual keys while typing quickly in VICE as this is now proving to be the biggest nuissance I have when using the program.

Image

Re: Vice C64 Keyboard Missed Keystrokes

Posted: Fri Jun 24, 2022 4:37 am
by hendrb01
I have also noticed that there seems to be a lag in the pickup of joystick movements. I know Port 1 is linked to the keyboard input, don't rememeber if 2 is as well. So are these two issues related?