chips icon indicating copy to clipboard operation
chips copied to clipboard

Unable to use the space bar when there's a CPC_JOYSTICK_DIGITAL attached

Open leiradel opened this issue 2 years ago • 2 comments

In cpc_key_down/up, if there's a CPC_JOYSTICK_DIGITAL, the space key will be converted to the joystick button CPC_JOYSTICK_BTN0, making it impossible to produce a space in the emulator.

I'd love to submit a PR but I have zero knowledge about the CPC and am unsure what the fix would be.

leiradel avatar Jul 08 '22 14:07 leiradel

Yeah that's the case when the "keyboard joystick emulation" is active (which is enabled by calling cpc_set_joystick_type(cpc, CPC_JOYSTICK_DIGITAL) which allows to feed joystick input throught the host machine's keyboard), in that case the space key is the joystick's fire button, and the keyboard arrow keys are the directions.

The "routing" happens here in cpc_key_down() and cpc_key_up():

https://github.com/floooh/chips/blob/c011ef1b3a5968aa8b8638eda701b08948e1c53b/systems/cpc.h#L663-L695

...the idea of this "either / or routing" is that pressing the space or arrow keys shouldn't feed both keyboard and joystick input on the same keys.

There's a second way to feed joystick input into the emulator via the cpc_joystick() function (not the best name tbh):

https://github.com/floooh/chips/blob/c011ef1b3a5968aa8b8638eda701b08948e1c53b/systems/cpc.h#L707-L710

...normally this is intended for the case the there's an actual joystick or gamepad attached to the host machine.

But in general: you should just disable/ignore the "keyboard joystick emulation" by not setting the joystick type via cpc_set_joystick_type(), and instead provide the joystick input via the function cpc_joystick().

PS: I realize now that all those function names could be a bit more intuitive ;)

floooh avatar Jul 08 '22 16:07 floooh

I get it know, thanks for the detailed explanation.

leiradel avatar Jul 17 '22 10:07 leiradel