From 8136cafb75203da58874df9af36c19cac06f715d Mon Sep 17 00:00:00 2001 From: Adrien Plazas Date: Fri, 29 Jul 2016 19:23:29 +0200 Subject: libretro: Refactor reading controller type Refactor the way the controller type variables are read as we were doing 8 times almost exactly the same thing. This makes the code more readable and maintainable. --- frontend/libretro.c | 117 ++++++++++++++-------------------------------------- 1 file changed, 30 insertions(+), 87 deletions(-) (limited to 'frontend') diff --git a/frontend/libretro.c b/frontend/libretro.c index bdce90e..2e00623 100644 --- a/frontend/libretro.c +++ b/frontend/libretro.c @@ -33,6 +33,8 @@ #include "3ds/3ds_utils.h" #endif +#define PORTS_NUMBER 8 + static retro_video_refresh_t video_cb; static retro_input_poll_t input_poll_cb; static retro_input_state_t input_state_cb; @@ -375,6 +377,32 @@ unsigned retro_api_version(void) return RETRO_API_VERSION; } +static void update_controller_port_device(unsigned port) +{ + if (port >= PORTS_NUMBER) + return; + + static const char **CONTROLLER_VARIABLE = { + "pcsx_rearmed_pad1type", "pcsx_rearmed_pad2type", + "pcsx_rearmed_pad3type", "pcsx_rearmed_pad4type", + "pcsx_rearmed_pad5type", "pcsx_rearmed_pad6type", + "pcsx_rearmed_pad7type", "pcsx_rearmed_pad8type", + }; + + struct retro_variable var; + + var.value = NULL; + var.key = "pcsx_rearmed_pad1type"; + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) + { + in_type[0] = PSE_PAD_TYPE_STANDARD; + if (strcmp(var.value, "analog") == 0) + in_type[0] = PSE_PAD_TYPE_ANALOGPAD; + else if (strcmp(var.value, "negcon") == 0) + in_type[0] = PSE_PAD_TYPE_NEGCON; + } +} + void retro_set_controller_port_device(unsigned port, unsigned device) { SysPrintf("port %u device %u",port,device); @@ -1070,93 +1098,8 @@ static void update_variables(bool in_flight) Config.PsxType = 1; } - var.value = NULL; - var.key = "pcsx_rearmed_pad1type"; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) - { - in_type[0] = PSE_PAD_TYPE_STANDARD; - if (strcmp(var.value, "analog") == 0) - in_type[0] = PSE_PAD_TYPE_ANALOGPAD; - else if (strcmp(var.value, "negcon") == 0) - in_type[0] = PSE_PAD_TYPE_NEGCON; - } - - var.value = NULL; - var.key = "pcsx_rearmed_pad2type"; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) - { - in_type[1] = PSE_PAD_TYPE_STANDARD; - if (strcmp(var.value, "analog") == 0) - in_type[1] = PSE_PAD_TYPE_ANALOGPAD; - else if (strcmp(var.value, "negcon") == 0) - in_type[1] = PSE_PAD_TYPE_NEGCON; - } - - var.value = NULL; - var.key = "pcsx_rearmed_pad3type"; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) - { - in_type[2] = PSE_PAD_TYPE_STANDARD; - if (strcmp(var.value, "analog") == 0) - in_type[2] = PSE_PAD_TYPE_ANALOGPAD; - else if (strcmp(var.value, "negcon") == 0) - in_type[2] = PSE_PAD_TYPE_NEGCON; - } - - var.value = NULL; - var.key = "pcsx_rearmed_pad4type"; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) - { - in_type[3] = PSE_PAD_TYPE_STANDARD; - if (strcmp(var.value, "analog") == 0) - in_type[3] = PSE_PAD_TYPE_ANALOGPAD; - else if (strcmp(var.value, "negcon") == 0) - in_type[3] = PSE_PAD_TYPE_NEGCON; - } - - var.value = NULL; - var.key = "pcsx_rearmed_pad5type"; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) - { - in_type[4] = PSE_PAD_TYPE_STANDARD; - if (strcmp(var.value, "analog") == 0) - in_type[4] = PSE_PAD_TYPE_ANALOGPAD; - else if (strcmp(var.value, "negcon") == 0) - in_type[4] = PSE_PAD_TYPE_NEGCON; - } - - var.value = NULL; - var.key = "pcsx_rearmed_pad6type"; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) - { - in_type[5] = PSE_PAD_TYPE_STANDARD; - if (strcmp(var.value, "analog") == 0) - in_type[5] = PSE_PAD_TYPE_ANALOGPAD; - else if (strcmp(var.value, "negcon") == 0) - in_type[5] = PSE_PAD_TYPE_NEGCON; - } - - var.value = NULL; - var.key = "pcsx_rearmed_pad7type"; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) - { - in_type[6] = PSE_PAD_TYPE_STANDARD; - if (strcmp(var.value, "analog") == 0) - in_type[6] = PSE_PAD_TYPE_ANALOGPAD; - else if (strcmp(var.value, "negcon") == 0) - in_type[6] = PSE_PAD_TYPE_NEGCON; - } - - var.value = NULL; - var.key = "pcsx_rearmed_pad8type"; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) - { - in_type[7] = PSE_PAD_TYPE_STANDARD; - if (strcmp(var.value, "analog") == 0) - in_type[7] = PSE_PAD_TYPE_ANALOGPAD; - else if (strcmp(var.value, "negcon") == 0) - in_type[7] = PSE_PAD_TYPE_NEGCON; - } + for (int i = 0; i < PORTS_NUMBER; i++) + update_controller_port_device(i); var.value = NULL; var.key = "pcsx_rearmed_multitap1"; -- cgit v1.2.3 From 3c0fb5542ef648d094487c5533bcdc73a75116ea Mon Sep 17 00:00:00 2001 From: Adrien Plazas Date: Fri, 29 Jul 2016 19:33:02 +0200 Subject: Add PSE_PAD_TYPE_NONE Allow to set no controller to a port. This will be used in the next commit to allow auto detecting whether multitaps are plugged. --- frontend/libretro.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'frontend') diff --git a/frontend/libretro.c b/frontend/libretro.c index 2e00623..4de0185 100644 --- a/frontend/libretro.c +++ b/frontend/libretro.c @@ -62,7 +62,7 @@ int in_type[8] = { PSE_PAD_TYPE_STANDARD, PSE_PAD_TYPE_STANDARD, PSE_PAD_TYPE_STANDARD, PSE_PAD_TYPE_STANDARD }; int in_analog_left[8][2] = {{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 }}; int in_analog_right[8][2] = {{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 }}; -unsigned short in_keystate[8]; +unsigned short in_keystate[PORTS_NUMBER]; int multitap1 = 0; int multitap2 = 0; int in_enable_vibration = 1; @@ -335,14 +335,14 @@ void retro_set_environment(retro_environment_t cb) static const struct retro_variable vars[] = { { "pcsx_rearmed_frameskip", "Frameskip; 0|1|2|3" }, { "pcsx_rearmed_region", "Region; Auto|NTSC|PAL" }, - { "pcsx_rearmed_pad1type", "Pad 1 Type; standard|analog|negcon" }, - { "pcsx_rearmed_pad2type", "Pad 2 Type; standard|analog|negcon" }, - { "pcsx_rearmed_pad3type", "Pad 3 Type; standard|analog|negcon" }, - { "pcsx_rearmed_pad4type", "Pad 4 Type; standard|analog|negcon" }, - { "pcsx_rearmed_pad5type", "Pad 5 Type; standard|analog|negcon" }, - { "pcsx_rearmed_pad6type", "Pad 6 Type; standard|analog|negcon" }, - { "pcsx_rearmed_pad7type", "Pad 7 Type; standard|analog|negcon" }, - { "pcsx_rearmed_pad8type", "Pad 8 Type; standard|analog|negcon" }, + { "pcsx_rearmed_pad1type", "Pad 1 Type; none|standard|analog|negcon" }, + { "pcsx_rearmed_pad2type", "Pad 2 Type; none|standard|analog|negcon" }, + { "pcsx_rearmed_pad3type", "Pad 3 Type; none|standard|analog|negcon" }, + { "pcsx_rearmed_pad4type", "Pad 4 Type; none|standard|analog|negcon" }, + { "pcsx_rearmed_pad5type", "Pad 5 Type; none|standard|analog|negcon" }, + { "pcsx_rearmed_pad6type", "Pad 6 Type; none|standard|analog|negcon" }, + { "pcsx_rearmed_pad7type", "Pad 7 Type; none|standard|analog|negcon" }, + { "pcsx_rearmed_pad8type", "Pad 8 Type; none|standard|analog|negcon" }, { "pcsx_rearmed_multitap1", "Multitap 1; disabled|enabled" }, { "pcsx_rearmed_multitap2", "Multitap 2; disabled|enabled" }, #ifndef DRC_DISABLE @@ -395,11 +395,14 @@ static void update_controller_port_device(unsigned port) var.key = "pcsx_rearmed_pad1type"; if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) { - in_type[0] = PSE_PAD_TYPE_STANDARD; - if (strcmp(var.value, "analog") == 0) + if (strcmp(var.value, "standard") == 0) + in_type[0] = PSE_PAD_TYPE_STANDARD; + else if (strcmp(var.value, "analog") == 0) in_type[0] = PSE_PAD_TYPE_ANALOGPAD; else if (strcmp(var.value, "negcon") == 0) in_type[0] = PSE_PAD_TYPE_NEGCON; + else // 'none' case + in_type[0] = PSE_PAD_TYPE_NONE; } } @@ -1265,8 +1268,12 @@ void retro_run(void) // reset all keystate, query libretro for keystate int j; - for(i = 0; i < 8; i++) { + for(i = 0; i < PORTS_NUMBER; i++) { in_keystate[i] = 0; + + if (in_type[i] == PSE_PAD_TYPE_NONE) + continue; + // query libretro for keystate for (j = 0; j < RETRO_PSX_MAP_LEN; j++) if (input_state_cb(i, RETRO_DEVICE_JOYPAD, 0, j)) -- cgit v1.2.3 From 30d43b8abe6aef8844aa1f48f505ba238a01c2a6 Mon Sep 17 00:00:00 2001 From: Adrien Plazas Date: Fri, 29 Jul 2016 19:18:27 +0200 Subject: libretro: Allow to auto detect multitaps Add the 'auto' multitape vairable value. This allows to automatically detect multitaps based on the number of plugged controllers. --- frontend/libretro.c | 61 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 19 deletions(-) (limited to 'frontend') diff --git a/frontend/libretro.c b/frontend/libretro.c index 4de0185..274d6d5 100644 --- a/frontend/libretro.c +++ b/frontend/libretro.c @@ -343,8 +343,8 @@ void retro_set_environment(retro_environment_t cb) { "pcsx_rearmed_pad6type", "Pad 6 Type; none|standard|analog|negcon" }, { "pcsx_rearmed_pad7type", "Pad 7 Type; none|standard|analog|negcon" }, { "pcsx_rearmed_pad8type", "Pad 8 Type; none|standard|analog|negcon" }, - { "pcsx_rearmed_multitap1", "Multitap 1; disabled|enabled" }, - { "pcsx_rearmed_multitap2", "Multitap 2; disabled|enabled" }, + { "pcsx_rearmed_multitap1", "Multitap 1; auto|disabled|enabled" }, + { "pcsx_rearmed_multitap2", "Multitap 2; auto|disabled|enabled" }, #ifndef DRC_DISABLE { "pcsx_rearmed_drc", "Dynamic recompiler; enabled|disabled" }, #endif @@ -406,6 +406,45 @@ static void update_controller_port_device(unsigned port) } } +static void update_multitap() +{ + struct retro_variable var; + + var.value = NULL; + var.key = "pcsx_rearmed_multitap1"; + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) + { + if (strcmp(var.value, "enabled") == 0) + multitap1 = 1; + else if (strcmp(var.value, "disabled") == 0) + multitap1 = 0; + else // 'auto' case + { + // If a gamepad is plugged after port 2, we need a first multitap. + multitap1 = 0; + for (int port = 2; port < PORTS_NUMBER; port++) + multitap1 |= in_type[port] != PSE_PAD_TYPE_NONE; + } + } + + var.value = NULL; + var.key = "pcsx_rearmed_multitap2"; + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) + { + if (strcmp(var.value, "enabled") == 0) + multitap2 = 1; + else if (strcmp(var.value, "disabled") == 0) + multitap2 = 0; + else // 'auto' case + { + // If a gamepad is plugged after port 4, we need a second multitap. + multitap2 = 0; + for (int port = 4; port < PORTS_NUMBER; port++) + multitap2 |= in_type[port] != PSE_PAD_TYPE_NONE; + } + } +} + void retro_set_controller_port_device(unsigned port, unsigned device) { SysPrintf("port %u device %u",port,device); @@ -1104,23 +1143,7 @@ static void update_variables(bool in_flight) for (int i = 0; i < PORTS_NUMBER; i++) update_controller_port_device(i); - var.value = NULL; - var.key = "pcsx_rearmed_multitap1"; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) - { - if (strcmp(var.value, "enabled") == 0) - multitap1 = 1; - else multitap1 = 0; - } - - var.value = NULL; - var.key = "pcsx_rearmed_multitap2"; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) - { - if (strcmp(var.value, "enabled") == 0) - multitap2 = 1; - else multitap2 = 0; - } + update_multitap(); #ifdef __ARM_NEON__ var.value = "NULL"; -- cgit v1.2.3 From 8c047f6f65a084cdd6755d59ce040511557590c1 Mon Sep 17 00:00:00 2001 From: Adrien Plazas Date: Fri, 29 Jul 2016 19:00:29 +0200 Subject: libretro: Implement retro_set_controller_port_device() Add the 'default' value to controller type variables and set it as the default value and implements the retro_set_controller_port_device() function. When the variable's value is 'default', the value set via the function is used, otherwise the value of the variable is used. This allows the frontends to use retro_set_controller_port_device() or the variables, pleasing both the users and frontends prefering the standard API and the ones prefering the custom API. --- frontend/libretro.c | 51 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 12 deletions(-) (limited to 'frontend') diff --git a/frontend/libretro.c b/frontend/libretro.c index 274d6d5..d6c1ab8 100644 --- a/frontend/libretro.c +++ b/frontend/libretro.c @@ -335,14 +335,14 @@ void retro_set_environment(retro_environment_t cb) static const struct retro_variable vars[] = { { "pcsx_rearmed_frameskip", "Frameskip; 0|1|2|3" }, { "pcsx_rearmed_region", "Region; Auto|NTSC|PAL" }, - { "pcsx_rearmed_pad1type", "Pad 1 Type; none|standard|analog|negcon" }, - { "pcsx_rearmed_pad2type", "Pad 2 Type; none|standard|analog|negcon" }, - { "pcsx_rearmed_pad3type", "Pad 3 Type; none|standard|analog|negcon" }, - { "pcsx_rearmed_pad4type", "Pad 4 Type; none|standard|analog|negcon" }, - { "pcsx_rearmed_pad5type", "Pad 5 Type; none|standard|analog|negcon" }, - { "pcsx_rearmed_pad6type", "Pad 6 Type; none|standard|analog|negcon" }, - { "pcsx_rearmed_pad7type", "Pad 7 Type; none|standard|analog|negcon" }, - { "pcsx_rearmed_pad8type", "Pad 8 Type; none|standard|analog|negcon" }, + { "pcsx_rearmed_pad1type", "Pad 1 Type; default|none|standard|analog|negcon" }, + { "pcsx_rearmed_pad2type", "Pad 2 Type; default|none|standard|analog|negcon" }, + { "pcsx_rearmed_pad3type", "Pad 3 Type; default|none|standard|analog|negcon" }, + { "pcsx_rearmed_pad4type", "Pad 4 Type; default|none|standard|analog|negcon" }, + { "pcsx_rearmed_pad5type", "Pad 5 Type; default|none|standard|analog|negcon" }, + { "pcsx_rearmed_pad6type", "Pad 6 Type; default|none|standard|analog|negcon" }, + { "pcsx_rearmed_pad7type", "Pad 7 Type; default|none|standard|analog|negcon" }, + { "pcsx_rearmed_pad8type", "Pad 8 Type; default|none|standard|analog|negcon" }, { "pcsx_rearmed_multitap1", "Multitap 1; auto|disabled|enabled" }, { "pcsx_rearmed_multitap2", "Multitap 2; auto|disabled|enabled" }, #ifndef DRC_DISABLE @@ -377,7 +377,7 @@ unsigned retro_api_version(void) return RETRO_API_VERSION; } -static void update_controller_port_device(unsigned port) +static void update_controller_port_device(unsigned port, unsigned device) { if (port >= PORTS_NUMBER) return; @@ -392,7 +392,7 @@ static void update_controller_port_device(unsigned port) struct retro_variable var; var.value = NULL; - var.key = "pcsx_rearmed_pad1type"; + var.key = CONTROLLER_VARIABLE[port]; if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) { if (strcmp(var.value, "standard") == 0) @@ -401,8 +401,29 @@ static void update_controller_port_device(unsigned port) in_type[0] = PSE_PAD_TYPE_ANALOGPAD; else if (strcmp(var.value, "negcon") == 0) in_type[0] = PSE_PAD_TYPE_NEGCON; - else // 'none' case + else if (strcmp(var.value, "none") == 0) in_type[0] = PSE_PAD_TYPE_NONE; + else // 'default' case + { + switch (device) + { + case RETRO_DEVICE_JOYPAD: + in_type[port] = PSE_PAD_TYPE_STANDARD; + break; + case RETRO_DEVICE_ANALOG: + in_type[port] = PSE_PAD_TYPE_ANALOGPAD; + break; + case RETRO_DEVICE_MOUSE: + in_type[port] = PSE_PAD_TYPE_MOUSE; + break; + case RETRO_DEVICE_LIGHTGUN: + in_type[port] = PSE_PAD_TYPE_GUN; + break; + case RETRO_DEVICE_NONE: + default: + in_type[port] = PSE_PAD_TYPE_NONE; + } + } } } @@ -448,6 +469,12 @@ static void update_multitap() void retro_set_controller_port_device(unsigned port, unsigned device) { SysPrintf("port %u device %u",port,device); + + if (port >= PORTS_NUMBER) + return; + + update_controller_port_device(port, device); + update_multitap(); } void retro_get_system_info(struct retro_system_info *info) @@ -1141,7 +1168,7 @@ static void update_variables(bool in_flight) } for (int i = 0; i < PORTS_NUMBER; i++) - update_controller_port_device(i); + update_controller_port_device(i, RETRO_DEVICE_NONE); update_multitap(); -- cgit v1.2.3 From a06f5a7008c19fb65c037f539439c029834026b3 Mon Sep 17 00:00:00 2001 From: Adrien Plazas Date: Sat, 30 Jul 2016 00:59:47 +0200 Subject: libretro: Fix key passing of update_controller_port_device() Change the way the key of the controler type variables is passed to one which doesn't crash. --- frontend/libretro.c | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) (limited to 'frontend') diff --git a/frontend/libretro.c b/frontend/libretro.c index d6c1ab8..b812d91 100644 --- a/frontend/libretro.c +++ b/frontend/libretro.c @@ -382,17 +382,36 @@ static void update_controller_port_device(unsigned port, unsigned device) if (port >= PORTS_NUMBER) return; - static const char **CONTROLLER_VARIABLE = { - "pcsx_rearmed_pad1type", "pcsx_rearmed_pad2type", - "pcsx_rearmed_pad3type", "pcsx_rearmed_pad4type", - "pcsx_rearmed_pad5type", "pcsx_rearmed_pad6type", - "pcsx_rearmed_pad7type", "pcsx_rearmed_pad8type", - }; - struct retro_variable var; var.value = NULL; - var.key = CONTROLLER_VARIABLE[port]; + switch (port) { + case 0: + var.key = "pcsx_rearmed_pad1type"; + break; + case 1: + var.key = "pcsx_rearmed_pad2type"; + break; + case 2: + var.key = "pcsx_rearmed_pad3type"; + break; + case 3: + var.key = "pcsx_rearmed_pad4type"; + break; + case 4: + var.key = "pcsx_rearmed_pad5type"; + break; + case 5: + var.key = "pcsx_rearmed_pad6type"; + break; + case 6: + var.key = "pcsx_rearmed_pad7type"; + break; + case 7: + var.key = "pcsx_rearmed_pad8type"; + break; + } + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) { if (strcmp(var.value, "standard") == 0) -- cgit v1.2.3 From 3dc2e39eebfc512aa0d8f1a2ce435aaa8a599ac1 Mon Sep 17 00:00:00 2001 From: Adrien Plazas Date: Sat, 30 Jul 2016 00:56:59 +0200 Subject: libretro: Check 'environ_cb' in controller setters Check that 'environ_cb' is valid before using it in update_multitap() and update_controller_port_device() as they may be called from retro_set_controller_port_device() before 'environ_cb' is set. --- frontend/libretro.c | 85 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 51 insertions(+), 34 deletions(-) (limited to 'frontend') diff --git a/frontend/libretro.c b/frontend/libretro.c index b812d91..936776e 100644 --- a/frontend/libretro.c +++ b/frontend/libretro.c @@ -383,6 +383,7 @@ static void update_controller_port_device(unsigned port, unsigned device) return; struct retro_variable var; + int default_case = 0; var.value = NULL; switch (port) { @@ -412,7 +413,7 @@ static void update_controller_port_device(unsigned port, unsigned device) break; } - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) + if (environ_cb && (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)) { if (strcmp(var.value, "standard") == 0) in_type[0] = PSE_PAD_TYPE_STANDARD; @@ -423,65 +424,81 @@ static void update_controller_port_device(unsigned port, unsigned device) else if (strcmp(var.value, "none") == 0) in_type[0] = PSE_PAD_TYPE_NONE; else // 'default' case + default_case = 1; + } + else + default_case = 1; + + if (default_case) + switch (device) { - switch (device) - { - case RETRO_DEVICE_JOYPAD: - in_type[port] = PSE_PAD_TYPE_STANDARD; - break; - case RETRO_DEVICE_ANALOG: - in_type[port] = PSE_PAD_TYPE_ANALOGPAD; - break; - case RETRO_DEVICE_MOUSE: - in_type[port] = PSE_PAD_TYPE_MOUSE; - break; - case RETRO_DEVICE_LIGHTGUN: - in_type[port] = PSE_PAD_TYPE_GUN; - break; - case RETRO_DEVICE_NONE: - default: - in_type[port] = PSE_PAD_TYPE_NONE; - } + case RETRO_DEVICE_JOYPAD: + in_type[port] = PSE_PAD_TYPE_STANDARD; + break; + case RETRO_DEVICE_ANALOG: + in_type[port] = PSE_PAD_TYPE_ANALOGPAD; + break; + case RETRO_DEVICE_MOUSE: + in_type[port] = PSE_PAD_TYPE_MOUSE; + break; + case RETRO_DEVICE_LIGHTGUN: + in_type[port] = PSE_PAD_TYPE_GUN; + break; + case RETRO_DEVICE_NONE: + default: + in_type[port] = PSE_PAD_TYPE_NONE; } - } } static void update_multitap() { struct retro_variable var; + int auto_case; var.value = NULL; var.key = "pcsx_rearmed_multitap1"; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) + auto_case = 0; + if (environ_cb && (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)) { if (strcmp(var.value, "enabled") == 0) multitap1 = 1; else if (strcmp(var.value, "disabled") == 0) multitap1 = 0; else // 'auto' case - { - // If a gamepad is plugged after port 2, we need a first multitap. - multitap1 = 0; - for (int port = 2; port < PORTS_NUMBER; port++) - multitap1 |= in_type[port] != PSE_PAD_TYPE_NONE; - } + auto_case = 1; + } + else + auto_case == 1; + + if (auto_case) + { + // If a gamepad is plugged after port 2, we need a first multitap. + multitap1 = 0; + for (int port = 2; port < PORTS_NUMBER; port++) + multitap1 |= in_type[port] != PSE_PAD_TYPE_NONE; } var.value = NULL; var.key = "pcsx_rearmed_multitap2"; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) + auto_case = 0; + if (environ_cb && (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)) { if (strcmp(var.value, "enabled") == 0) multitap2 = 1; else if (strcmp(var.value, "disabled") == 0) multitap2 = 0; else // 'auto' case - { - // If a gamepad is plugged after port 4, we need a second multitap. - multitap2 = 0; - for (int port = 4; port < PORTS_NUMBER; port++) - multitap2 |= in_type[port] != PSE_PAD_TYPE_NONE; - } + auto_case = 1; + } + else + auto_case == 1; + + if (auto_case) + { + // If a gamepad is plugged after port 4, we need a second multitap. + multitap2 = 0; + for (int port = 4; port < PORTS_NUMBER; port++) + multitap2 |= in_type[port] != PSE_PAD_TYPE_NONE; } } -- cgit v1.2.3 From 15504ca8fb3d4dbcb1822f2aafb4797e88f88175 Mon Sep 17 00:00:00 2001 From: Adrien Plazas Date: Sat, 30 Jul 2016 02:31:22 +0200 Subject: libretro: Split update_controller_port_device() Split update_controller_port_device() into update_controller_port_variable() updating the controllers from the variables, update_controller_port_device() updating the controllers from retro_set_controller_port_device() and controller_port_variable() sharing getting the controller variable between the two. Avoid setting to PSE_PAD_TYPE_NONE controllers whose variable is set to 'default' when updating them. --- frontend/libretro.c | 108 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 64 insertions(+), 44 deletions(-) (limited to 'frontend') diff --git a/frontend/libretro.c b/frontend/libretro.c index 936776e..b13f9c7 100644 --- a/frontend/libretro.c +++ b/frontend/libretro.c @@ -56,10 +56,10 @@ extern char Mcd1Data[MCD_SIZE]; extern char McdDisable[2]; /* PCSX ReARMed core calls and stuff */ -int in_type[8] = { PSE_PAD_TYPE_STANDARD, PSE_PAD_TYPE_STANDARD, - PSE_PAD_TYPE_STANDARD, PSE_PAD_TYPE_STANDARD, - PSE_PAD_TYPE_STANDARD, PSE_PAD_TYPE_STANDARD, - PSE_PAD_TYPE_STANDARD, PSE_PAD_TYPE_STANDARD }; +int in_type[8] = { PSE_PAD_TYPE_NONE, PSE_PAD_TYPE_NONE, + PSE_PAD_TYPE_NONE, PSE_PAD_TYPE_NONE, + PSE_PAD_TYPE_NONE, PSE_PAD_TYPE_NONE, + PSE_PAD_TYPE_NONE, PSE_PAD_TYPE_NONE }; int in_analog_left[8][2] = {{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 }}; int in_analog_right[8][2] = {{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 }}; unsigned short in_keystate[PORTS_NUMBER]; @@ -377,43 +377,53 @@ unsigned retro_api_version(void) return RETRO_API_VERSION; } -static void update_controller_port_device(unsigned port, unsigned device) +static int controller_port_variable(unsigned port, struct retro_variable *var) { if (port >= PORTS_NUMBER) - return; + return 0; - struct retro_variable var; - int default_case = 0; + if (!environ_cb) + return 0; - var.value = NULL; + var->value = NULL; switch (port) { case 0: - var.key = "pcsx_rearmed_pad1type"; + var->key = "pcsx_rearmed_pad1type"; break; case 1: - var.key = "pcsx_rearmed_pad2type"; + var->key = "pcsx_rearmed_pad2type"; break; case 2: - var.key = "pcsx_rearmed_pad3type"; + var->key = "pcsx_rearmed_pad3type"; break; case 3: - var.key = "pcsx_rearmed_pad4type"; + var->key = "pcsx_rearmed_pad4type"; break; case 4: - var.key = "pcsx_rearmed_pad5type"; + var->key = "pcsx_rearmed_pad5type"; break; case 5: - var.key = "pcsx_rearmed_pad6type"; + var->key = "pcsx_rearmed_pad6type"; break; case 6: - var.key = "pcsx_rearmed_pad7type"; + var->key = "pcsx_rearmed_pad7type"; break; case 7: - var.key = "pcsx_rearmed_pad8type"; + var->key = "pcsx_rearmed_pad8type"; break; } - if (environ_cb && (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)) + return environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, var) || var->value; +} + +static void update_controller_port_variable(unsigned port) +{ + if (port >= PORTS_NUMBER) + return; + + struct retro_variable var; + + if (controller_port_variable(port, &var)) { if (strcmp(var.value, "standard") == 0) in_type[0] = PSE_PAD_TYPE_STANDARD; @@ -423,31 +433,41 @@ static void update_controller_port_device(unsigned port, unsigned device) in_type[0] = PSE_PAD_TYPE_NEGCON; else if (strcmp(var.value, "none") == 0) in_type[0] = PSE_PAD_TYPE_NONE; - else // 'default' case - default_case = 1; + // else 'default' case, do nothing } - else - default_case = 1; +} - if (default_case) - switch (device) - { - case RETRO_DEVICE_JOYPAD: - in_type[port] = PSE_PAD_TYPE_STANDARD; - break; - case RETRO_DEVICE_ANALOG: - in_type[port] = PSE_PAD_TYPE_ANALOGPAD; - break; - case RETRO_DEVICE_MOUSE: - in_type[port] = PSE_PAD_TYPE_MOUSE; - break; - case RETRO_DEVICE_LIGHTGUN: - in_type[port] = PSE_PAD_TYPE_GUN; - break; - case RETRO_DEVICE_NONE: - default: - in_type[port] = PSE_PAD_TYPE_NONE; - } +static void update_controller_port_device(unsigned port, unsigned device) +{ + if (port >= PORTS_NUMBER) + return; + + struct retro_variable var; + + if (!controller_port_variable(port, &var)) + return; + + if (strcmp(var.value, "default") != 0) + return; + + switch (device) + { + case RETRO_DEVICE_JOYPAD: + in_type[port] = PSE_PAD_TYPE_STANDARD; + break; + case RETRO_DEVICE_ANALOG: + in_type[port] = PSE_PAD_TYPE_ANALOGPAD; + break; + case RETRO_DEVICE_MOUSE: + in_type[port] = PSE_PAD_TYPE_MOUSE; + break; + case RETRO_DEVICE_LIGHTGUN: + in_type[port] = PSE_PAD_TYPE_GUN; + break; + case RETRO_DEVICE_NONE: + default: + in_type[port] = PSE_PAD_TYPE_NONE; + } } static void update_multitap() @@ -468,7 +488,7 @@ static void update_multitap() auto_case = 1; } else - auto_case == 1; + auto_case = 1; if (auto_case) { @@ -491,7 +511,7 @@ static void update_multitap() auto_case = 1; } else - auto_case == 1; + auto_case = 1; if (auto_case) { @@ -1204,7 +1224,7 @@ static void update_variables(bool in_flight) } for (int i = 0; i < PORTS_NUMBER; i++) - update_controller_port_device(i, RETRO_DEVICE_NONE); + update_controller_port_variable(i); update_multitap(); -- cgit v1.2.3