From 4dfadfd27a93c82a7b248f24773a802fe890235e Mon Sep 17 00:00:00 2001 From: arpruss Date: Sat, 31 Dec 2022 21:27:46 -0600 Subject: [PATCH 1/3] support PowerPad via keyboard qwer/asdf/zxcv --- src/drivers/libretro/libretro.c | 52 ++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/src/drivers/libretro/libretro.c b/src/drivers/libretro/libretro.c index cdec31d..442330a 100644 --- a/src/drivers/libretro/libretro.c +++ b/src/drivers/libretro/libretro.c @@ -51,6 +51,8 @@ #define RETRO_DEVICE_GAMEPAD RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD, 1) #define RETRO_DEVICE_ZAPPER RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_MOUSE, 0) #define RETRO_DEVICE_ARKANOID RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_MOUSE, 1) +#define RETRO_DEVICE_POWERPADA RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_KEYBOARD, 0) +#define RETRO_DEVICE_POWERPADB RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_KEYBOARD, 1) #define RETRO_DEVICE_FC_ARKANOID RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_MOUSE, 2) #define RETRO_DEVICE_FC_OEKAKIDS RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_MOUSE, 3) @@ -130,6 +132,19 @@ static const keymap bindmap[] = { { RETRO_DEVICE_ID_JOYPAD_RIGHT, JOY_RIGHT }, }; +static const uint32_t powerpadamap[] = { + RETROK_r, RETROK_e, RETROK_w, RETROK_q, + RETROK_f, RETROK_d, RETROK_s, RETROK_a, + RETROK_v, RETROK_c, RETROK_x, RETROK_z, +}; + +static const uint32_t powerpadbmap[] = { + RETROK_q, RETROK_w, RETROK_e, RETROK_r, + RETROK_a, RETROK_s, RETROK_d, RETROK_f, + RETROK_z, RETROK_x, RETROK_c, RETROK_v, +}; + + typedef struct { bool enable_4player; /* four-score / 4-player adapter used */ bool up_down_allowed; /* disabled simultaneous up+down and left+right dpad combinations */ @@ -144,6 +159,7 @@ typedef struct { uint32_t JSReturn; /* player input data, 1 byte per player (1-4) */ uint32_t MouseData[MAX_PORTS][4]; /* nes mouse data */ uint32_t FamicomData[3]; /* Famicom expansion port data */ + uint32_t PowerPadData; } NES_INPUT_T; static NES_INPUT_T nes_input = { 0 }; @@ -1182,6 +1198,16 @@ static void update_nes_controllers(unsigned port, unsigned device) FCEUI_SetInput(port, SI_ARKANOID, nes_input.MouseData[port], 0); FCEU_printf(" Player %u: Arkanoid\n", port + 1); break; + case RETRO_DEVICE_POWERPADA: + nes_input.type[port] = RETRO_DEVICE_POWERPADA; + FCEUI_SetInput(port, SI_POWERPADA, &nes_input.PowerPadData, 0); + FCEU_printf(" Player %u: Powerpad\n", port + 1); + break; + case RETRO_DEVICE_POWERPADB: + nes_input.type[port] = RETRO_DEVICE_POWERPADB; + FCEUI_SetInput(port, SI_POWERPADB, &nes_input.PowerPadData, 0); + FCEU_printf(" Player %u: Powerpad\n", port + 1); + break; case RETRO_DEVICE_GAMEPAD: default: nes_input.type[port] = RETRO_DEVICE_GAMEPAD; @@ -1237,6 +1263,8 @@ static unsigned nes_to_libretro(int d) return RETRO_DEVICE_ZAPPER; case SI_ARKANOID: return RETRO_DEVICE_ARKANOID; + case SI_POWERPADB: + return RETRO_DEVICE_POWERPADB; } return (RETRO_DEVICE_GAMEPAD); @@ -1530,6 +1558,8 @@ void retro_set_environment(retro_environment_t cb) { "Gamepad", RETRO_DEVICE_GAMEPAD }, { "Arkanoid", RETRO_DEVICE_ARKANOID }, { "Zapper", RETRO_DEVICE_ZAPPER }, + { "PowerPad A", RETRO_DEVICE_POWERPADA }, + { "PowerPad B", RETRO_DEVICE_POWERPADB }, { 0, 0 }, }; @@ -1557,7 +1587,7 @@ void retro_set_environment(retro_environment_t cb) static const struct retro_controller_info ports[] = { { pads1, 3 }, - { pads2, 4 }, + { pads2, 6 }, { pads3, 2 }, { pads4, 2 }, { pads5, 6 }, @@ -2206,6 +2236,15 @@ static void check_variables(bool startup) update_option_visibility(); } +void get_powerpad_input(unsigned port, uint32 variant, uint32_t *ppdata) +{ + *ppdata = 0; + const uint32_t* map = (variant == RETRO_DEVICE_POWERPADA) ? powerpadamap : powerpadbmap; + for (unsigned k = 0 ; k < 12 ; k++) + if (input_cb(0, RETRO_DEVICE_KEYBOARD, 0, map[k])) + *ppdata |= (1 << k); +} + static int mzx = 0, mzy = 0; void get_mouse_input(unsigned port, uint32_t *zapdata) @@ -2462,6 +2501,17 @@ static void FCEUD_UpdateInput(void) } } + for (port = 0; port < MAX_PORTS; port++) + { + switch (nes_input.type[port]) + { + case RETRO_DEVICE_POWERPADB: + case RETRO_DEVICE_POWERPADA: + get_powerpad_input(port, nes_input.type[port], &nes_input.PowerPadData); + break; + } + } + /* famicom inputs */ switch (nes_input.type[4]) { From d266ba2e20af804e38dd376930d0f2051375a9b0 Mon Sep 17 00:00:00 2001 From: arpruss Date: Sun, 1 Jan 2023 07:30:56 -0600 Subject: [PATCH 2/3] allow for two controllers to add up to a single PowerPad --- src/drivers/libretro/libretro.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/drivers/libretro/libretro.c b/src/drivers/libretro/libretro.c index 442330a..56ee54b 100644 --- a/src/drivers/libretro/libretro.c +++ b/src/drivers/libretro/libretro.c @@ -1566,6 +1566,8 @@ void retro_set_environment(retro_environment_t cb) static const struct retro_controller_description pads3[] = { { "Auto", RETRO_DEVICE_AUTO }, { "Gamepad", RETRO_DEVICE_GAMEPAD }, + { "PowerPad A", RETRO_DEVICE_POWERPADA }, + { "PowerPad B", RETRO_DEVICE_POWERPADB }, { 0, 0 }, }; @@ -1588,7 +1590,7 @@ void retro_set_environment(retro_environment_t cb) static const struct retro_controller_info ports[] = { { pads1, 3 }, { pads2, 6 }, - { pads3, 2 }, + { pads3, 4 }, { pads4, 2 }, { pads5, 6 }, { 0, 0 }, @@ -2236,9 +2238,8 @@ static void check_variables(bool startup) update_option_visibility(); } -void get_powerpad_input(unsigned port, uint32 variant, uint32_t *ppdata) +void add_powerpad_input(unsigned port, uint32 variant, uint32_t *ppdata) { - *ppdata = 0; const uint32_t* map = (variant == RETRO_DEVICE_POWERPADA) ? powerpadamap : powerpadbmap; for (unsigned k = 0 ; k < 12 ; k++) if (input_cb(0, RETRO_DEVICE_KEYBOARD, 0, map[k])) @@ -2501,13 +2502,14 @@ static void FCEUD_UpdateInput(void) } } + nes_input.PowerPadData = 0; for (port = 0; port < MAX_PORTS; port++) { switch (nes_input.type[port]) { case RETRO_DEVICE_POWERPADB: case RETRO_DEVICE_POWERPADA: - get_powerpad_input(port, nes_input.type[port], &nes_input.PowerPadData); + add_powerpad_input(port, nes_input.type[port], &nes_input.PowerPadData); break; } } From f473a2a34678a7a6dd133ccfe859c69eb9daf494 Mon Sep 17 00:00:00 2001 From: arpruss Date: Sun, 1 Jan 2023 08:09:19 -0600 Subject: [PATCH 3/3] fix UI Power Pad spacing --- src/drivers/libretro/libretro.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/drivers/libretro/libretro.c b/src/drivers/libretro/libretro.c index 56ee54b..da11921 100644 --- a/src/drivers/libretro/libretro.c +++ b/src/drivers/libretro/libretro.c @@ -1201,12 +1201,12 @@ static void update_nes_controllers(unsigned port, unsigned device) case RETRO_DEVICE_POWERPADA: nes_input.type[port] = RETRO_DEVICE_POWERPADA; FCEUI_SetInput(port, SI_POWERPADA, &nes_input.PowerPadData, 0); - FCEU_printf(" Player %u: Powerpad\n", port + 1); + FCEU_printf(" Player %u: Power Pad\n", port + 1); break; case RETRO_DEVICE_POWERPADB: nes_input.type[port] = RETRO_DEVICE_POWERPADB; FCEUI_SetInput(port, SI_POWERPADB, &nes_input.PowerPadData, 0); - FCEU_printf(" Player %u: Powerpad\n", port + 1); + FCEU_printf(" Player %u: Power Pad\n", port + 1); break; case RETRO_DEVICE_GAMEPAD: default: @@ -1558,16 +1558,16 @@ void retro_set_environment(retro_environment_t cb) { "Gamepad", RETRO_DEVICE_GAMEPAD }, { "Arkanoid", RETRO_DEVICE_ARKANOID }, { "Zapper", RETRO_DEVICE_ZAPPER }, - { "PowerPad A", RETRO_DEVICE_POWERPADA }, - { "PowerPad B", RETRO_DEVICE_POWERPADB }, + { "Power Pad A", RETRO_DEVICE_POWERPADA }, + { "Power Pad B", RETRO_DEVICE_POWERPADB }, { 0, 0 }, }; static const struct retro_controller_description pads3[] = { { "Auto", RETRO_DEVICE_AUTO }, { "Gamepad", RETRO_DEVICE_GAMEPAD }, - { "PowerPad A", RETRO_DEVICE_POWERPADA }, - { "PowerPad B", RETRO_DEVICE_POWERPADB }, + { "Power Pad A", RETRO_DEVICE_POWERPADA }, + { "Power Pad B", RETRO_DEVICE_POWERPADB }, { 0, 0 }, };