Giter Site home page Giter Site logo

Comments (2)

floooh avatar floooh commented on June 12, 2024

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

from chips.

leiradel avatar leiradel commented on June 12, 2024

I get it know, thanks for the detailed explanation.

from chips.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.