Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
leiradel opened this issue Jul 8, 2022 · 2 comments

Comments

@leiradel
Copy link
Contributor

leiradel commented Jul 8, 2022

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.

@floooh
Copy link
Owner

floooh commented Jul 8, 2022

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():

chips/systems/cpc.h

Lines 663 to 695 in c011ef1

void cpc_key_down(cpc_t* sys, int key_code) {
CHIPS_ASSERT(sys && sys->valid);
if (sys->joystick_type == CPC_JOYSTICK_DIGITAL) {
switch (key_code) {
case 0x20: sys->kbd_joymask |= CPC_JOYSTICK_BTN0; break;
case 0x08: sys->kbd_joymask |= CPC_JOYSTICK_LEFT; break;
case 0x09: sys->kbd_joymask |= CPC_JOYSTICK_RIGHT; break;
case 0x0A: sys->kbd_joymask |= CPC_JOYSTICK_DOWN; break;
case 0x0B: sys->kbd_joymask |= CPC_JOYSTICK_UP; break;
default: kbd_key_down(&sys->kbd, key_code); break;
}
}
else {
kbd_key_down(&sys->kbd, key_code);
}
}
void cpc_key_up(cpc_t* sys, int key_code) {
CHIPS_ASSERT(sys && sys->valid);
if (sys->joystick_type == CPC_JOYSTICK_DIGITAL) {
switch (key_code) {
case 0x20: sys->kbd_joymask &= ~CPC_JOYSTICK_BTN0; break;
case 0x08: sys->kbd_joymask &= ~CPC_JOYSTICK_LEFT; break;
case 0x09: sys->kbd_joymask &= ~CPC_JOYSTICK_RIGHT; break;
case 0x0A: sys->kbd_joymask &= ~CPC_JOYSTICK_DOWN; break;
case 0x0B: sys->kbd_joymask &= ~CPC_JOYSTICK_UP; break;
default: kbd_key_up(&sys->kbd, key_code); break;
}
}
else {
kbd_key_up(&sys->kbd, key_code);
}
}

...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):

chips/systems/cpc.h

Lines 707 to 710 in c011ef1

void cpc_joystick(cpc_t* sys, uint8_t mask) {
CHIPS_ASSERT(sys && sys->valid);
sys->joy_joymask = mask;
}

...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 ;)

@leiradel
Copy link
Contributor Author

I get it know, thanks for the detailed explanation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants