First post, by superfury
I'm trying to get my PS/2 keyboard emulation correct. I already have basic handlers that convert from the platform (PSP(w/ OSK when used), Windows or Linux) to an universal format used by the keyboard (104 keys as numbers).
So far I've implemented:
- When a key is pressed, it's press count (0-103) is registered and the key is marked as pressed.
- When a key is released, it's marked as released on top of it's pressed status (so both pressed and released when pressed, else nothing happens).
In the timer (ran at a high speed):
- When a key is marked as pressed and released, it immediately sends it's release code to the PS/2 keyboard buffer and marked as unpressed (reset to it's default state).
Then within the same timer, after processing the above information (key releases), it starts checking for input speed and new key presses:
- When no keys are pressed anymore, the step (the delay in 1ms periods between checking for input and processing it) and key_pressed_counter(increasing number, containing 1 more than the last key number pressed. This goes from 0-last key pressed, which is an incrementing number containing the order of key presses (including releases which were pressed)) are cleared.
- Finally, the input is handled:
-- When the current 1ms count (incremented by 1 each interval) exceeds the step (The amount of ms between checking and processing input)), (new) input is handled:
-- The current 1ms count is reset to zero.
-- When keys are pressed:
--- keypresses are handled.
--- The next step is calculated (depending on if there are active keys and step. If step is set, it's set to the repeat rate, else repeat delay)).
The handling of a key press checks the step variable. If it's set it's assumed the key is typematic, else non-typematic.
- Typematic key(s) are handled only the last key pressed (the earlier ones not being resent). When a key is released, the last pressed key becomes the active key (so if you press A,D,S,F, release F then S becomes the active key(the last in the line of active keys order still pressed)).
- Non-typematic key(s) are always pressed (more at one pressed key gets triggered in one loop before returning to the caller).
Is this correct? Or have I made a mistake in my keyboard emulation (PS/2 keyboard)?
https://bitbucket.org/superfury/x86emu/src/2d … ard.c?at=master
Edit: Fixed it according to the official documentation, stopping input when any key is released (including rapid input).
https://bitbucket.org/superfury/x86emu/src/8a … ard.c?at=master
Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io