Skip to content

Commit

Permalink
platform, fixes for compiling with keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
irixxxx committed Jan 16, 2025
1 parent 7e75e91 commit 800a5c9
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 33 deletions.
16 changes: 8 additions & 8 deletions pico/pico.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,16 @@ struct PicoEState;
// pico.c
#define XPCM_BUFFER_SIZE 64
enum {
KEY_RELEASED = 0,
KEY_DOWN,
KEY_UP,
PKEY_RELEASED = 0,
PKEY_DOWN,
PKEY_UP,
};
enum {
SHIFT_RELEASED = 0,
SHIFT_DOWN,
SHIFT_UP_HELD_DOWN,
SHIFT_RELEASED_HELD_DOWN,
SHIFT_UP
PSHIFT_RELEASED = 0,
PSHIFT_DOWN,
PSHIFT_UP_HELD_DOWN,
PSHIFT_RELEASED_HELD_DOWN,
PSHIFT_UP
};
typedef struct
{
Expand Down
40 changes: 20 additions & 20 deletions pico/pico/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@ static u32 PicoRead8_pico_kb(u32 a)
// otherwise it will be zero and the game won't clear its Shift key state.
u32 key_code = (key_shift
&& !key
&& PicoPicohw.kb.key_state != KEY_UP
&& PicoPicohw.kb.shift_state != SHIFT_UP_HELD_DOWN)
&& PicoPicohw.kb.key_state != PKEY_UP
&& PicoPicohw.kb.shift_state != PSHIFT_UP_HELD_DOWN)
? key_shift
: PicoPicohw.kb.shift_state == SHIFT_UP ? PEVB_KBD_LSHIFT : key;
: PicoPicohw.kb.shift_state == PSHIFT_UP ? PEVB_KBD_LSHIFT : key;
u32 key_code_7654 = (key_code & 0xf0) >> 4;
u32 key_code_3210 = (key_code & 0x0f);
switch(PicoPicohw.kb.i) {
Expand Down Expand Up @@ -186,31 +186,31 @@ static u32 PicoRead8_pico_kb(u32 a)
d = 6;
if (PicoPicohw.kb.active) {
if (key) {
PicoPicohw.kb.key_state = KEY_DOWN;
PicoPicohw.kb.key_state = PKEY_DOWN;
}
if (!key) {
PicoPicohw.kb.key_state = !PicoPicohw.kb.key_state ? 0 : (PicoPicohw.kb.key_state + 1) % (KEY_UP + 1);
PicoPicohw.kb.key_state = !PicoPicohw.kb.key_state ? 0 : (PicoPicohw.kb.key_state + 1) % (PKEY_UP + 1);
PicoPicohw.kb.start_time_keydown = 0;
}
if (key_shift && !key) {
if (PicoPicohw.kb.shift_state < SHIFT_RELEASED_HELD_DOWN) {
if (PicoPicohw.kb.shift_state < PSHIFT_RELEASED_HELD_DOWN) {
PicoPicohw.kb.shift_state++;
}
PicoPicohw.kb.start_time_keydown = 0;
}
if (!key_shift) {
PicoPicohw.kb.shift_state = !PicoPicohw.kb.shift_state ? 0 : (PicoPicohw.kb.shift_state + 1) % (SHIFT_UP + 1);
PicoPicohw.kb.shift_state = !PicoPicohw.kb.shift_state ? 0 : (PicoPicohw.kb.shift_state + 1) % (PSHIFT_UP + 1);
}

if (PicoPicohw.kb.key_state == KEY_DOWN || PicoPicohw.kb.shift_state == SHIFT_DOWN) {
if (PicoPicohw.kb.key_state == PKEY_DOWN || PicoPicohw.kb.shift_state == PSHIFT_DOWN) {
if (PicoPicohw.kb.start_time_keydown == 0) {
d |= 8; // Send key down a.k.a. make
PicoPicohw.kb.time_keydown = 0;
PicoPicohw.kb.start_time_keydown = get_ticks();
if (PicoPicohw.kb.key_state == KEY_DOWN)
elprintf(EL_PICOHW, "PicoPicohw.kb.key_state: KEY DOWN\n");
if (PicoPicohw.kb.key_state == PKEY_DOWN)
elprintf(EL_PICOHW, "PicoPicohw.kb.key_state: PKEY DOWN\n");
else
elprintf(EL_PICOHW, "PicoPicohw.kb.key_state: SHIFT DOWN\n");
elprintf(EL_PICOHW, "PicoPicohw.kb.key_state: PSHIFT DOWN\n");
}
// Simulate key repeat while held down a.k.a. typematic
PicoPicohw.kb.time_keydown = get_ticks() - PicoPicohw.kb.start_time_keydown;
Expand All @@ -219,25 +219,25 @@ static u32 PicoRead8_pico_kb(u32 a)
&& key_code != PEVB_KBD_CAPSLOCK
&& key_code != PEVB_KBD_LSHIFT) {
d |= 8; // Send key down a.k.a. make
if (PicoPicohw.kb.key_state == KEY_DOWN)
elprintf(EL_PICOHW, "PicoPicohw.kb.key_state: KEY DOWN\n");
if (PicoPicohw.kb.key_state == PKEY_DOWN)
elprintf(EL_PICOHW, "PicoPicohw.kb.key_state: PKEY DOWN\n");
else
elprintf(EL_PICOHW, "PicoPicohw.kb.key_state: SHIFT DOWN\n");
elprintf(EL_PICOHW, "PicoPicohw.kb.key_state: PSHIFT DOWN\n");
}
// Must register key up while typematic not active (expected by Kibodeu Piko)
if ((d & 8) == 0) {
d |= 1; // Send key up a.k.a. break
}
}
if (PicoPicohw.kb.key_state == KEY_UP
|| PicoPicohw.kb.shift_state == SHIFT_UP_HELD_DOWN
|| PicoPicohw.kb.shift_state == SHIFT_UP) {
if (PicoPicohw.kb.key_state == PKEY_UP
|| PicoPicohw.kb.shift_state == PSHIFT_UP_HELD_DOWN
|| PicoPicohw.kb.shift_state == PSHIFT_UP) {
d |= 1; // Send key up a.k.a. break
PicoPicohw.kb.start_time_keydown = 0;
if (PicoPicohw.kb.key_state == KEY_UP)
elprintf(EL_PICOHW, "PicoPicohw.kb.key_state: KEY UP\n");
if (PicoPicohw.kb.key_state == PKEY_UP)
elprintf(EL_PICOHW, "PicoPicohw.kb.key_state: PKEY UP\n");
else
elprintf(EL_PICOHW, "PicoPicohw.kb.key_state: SHIFT UP\n");
elprintf(EL_PICOHW, "PicoPicohw.kb.key_state: PSHIFT UP\n");
}
}
break;
Expand Down
4 changes: 2 additions & 2 deletions platform/common/emu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1296,7 +1296,7 @@ void emu_update_input(void)
int actions[IN_BINDTYPE_COUNT] = { 0, };
int actions_kbd[IN_BIND_LAST] = { 0, };
int pl_actions[4];
int events;
int events, i;

in_update(actions);

Expand Down Expand Up @@ -1355,7 +1355,7 @@ void emu_update_input(void)

// update keyboard input
PicoIn.kbd = 0;
for (int i = 0; i < IN_BIND_LAST; i++) {
for (i = 0; i < IN_BIND_LAST; i++) {
if (actions_kbd[i]) {
unsigned int action = actions_kbd[i];
unsigned int key = (action & 0xff);
Expand Down
2 changes: 1 addition & 1 deletion platform/libpicofe
5 changes: 5 additions & 0 deletions platform/opendingux/inputmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ const char * _in_sdl_key_names[SDLK_LAST] = {
};
const char * const *in_sdl_key_names = _in_sdl_key_names;

const struct in_default_bind in_sdl_kbd_map[] = {
// Opendingux devices usually don't have a keyboard.
{ 0, 0, 0 }
};


static void nameset(int x1, const char *name)
{
Expand Down
2 changes: 1 addition & 1 deletion platform/ps2/in_ps2.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,6 @@ void in_ps2_init(struct in_default_bind *defbinds)
in_ps2_keys[lg2(PAD_CROSS)] = "Cross";
in_ps2_keys[lg2(PAD_SQUARE)] = "Square";

in_register_driver(&in_ps2_drv, defbinds, NULL);
in_register_driver(&in_ps2_drv, defbinds, NULL, NULL);
}

2 changes: 1 addition & 1 deletion platform/psp/in_psp.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,6 @@ void in_psp_init(struct in_default_bind *defbinds)
in_psp_keys[lg2(PSP_NUB_DOWN)] = "Analog down";
in_psp_keys[lg2(PSP_NUB_RIGHT)] = "Analog right";

in_register_driver(&in_psp_drv, defbinds, NULL);
in_register_driver(&in_psp_drv, defbinds, NULL, NULL);
}

0 comments on commit 800a5c9

Please sign in to comment.