artemisamsx / artemisa

Schematics, PCB designs and HDL simulations to build a 8-bits MSX computer
Other
62 stars 11 forks source link

Combination of arrow up, left and space doesn't work #125

Closed apoloval closed 4 years ago

apoloval commented 4 years ago

Playing Batman the Movie (Ocean, 1989), I detected a problem in the PS2 Keyboard adapter.

Walking to the left, in some part of the level 1 you have to launch the batrope to the platform above to save a cliff. This means pressing left key, up key and fire key at once. When using the cursor keys + spacebar as fire key, this is simply impossible. The space key is ignored when cursor up and cursor left and pressed.

Surprisingly, the rest of combinations with the cursor keys work as expected. Top+right+fire, down+right+fire, left+down+fire... all they work.

apoloval commented 4 years ago

I've been actually working on this for several days. This is what I've found.

First, I suspected of a bug in the PS2 adapter firmware. Since we are using the PS2KeyboardAdvanced library, it was not really easy to know why this was happening. The implementation of the library was a real mess. It has a lot of global state that is modified from the interruption routine. The code is really hard to follow.

Thus, I decided to make my own implementation (70df6553f6ee63c106439bbf2ca61cc48a89846f and 19cea1e2220818620bc9d1dbe393ff7af1e85c93). This new version simplifies the code a lot. It doesn't assume the client code will use the keyboard as a source of keycodes. It lowers the abstraction level a little bit more, so the main sketch has to handle scancodes coming from the keyboard. This gives much more control over the keyboard.

After this, the tests revealed that the issue was not in the firmware. It all was documented in 322621504afeae4a9266aa7246526be5ccbca4ce. In summary, most low-end PS2 keyboards have this defect. Their matrix is disposed in a way that this causes a key ghost. It is a well known issue for PC game makers.

Finally, it seems the bug cannot be fixed.

Since the new PS2 library opens new opportunities to implement some other interested features, I just left it and removed the code of PS2KeyboardAdvanced.