diff options
author | Adrien Plazas | 2016-07-30 02:31:22 +0200 |
---|---|---|
committer | Adrien Plazas | 2016-07-30 02:39:58 +0200 |
commit | 15504ca8fb3d4dbcb1822f2aafb4797e88f88175 (patch) | |
tree | 4a50bbbbfa0a22897fc64c850af54e604c30a6da /frontend | |
parent | 2629ef253690af33406a4dc7eef76a44004d1540 (diff) | |
download | pcsx_rearmed-15504ca8fb3d4dbcb1822f2aafb4797e88f88175.tar.gz pcsx_rearmed-15504ca8fb3d4dbcb1822f2aafb4797e88f88175.tar.bz2 pcsx_rearmed-15504ca8fb3d4dbcb1822f2aafb4797e88f88175.zip |
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.
Diffstat (limited to 'frontend')
-rw-r--r-- | frontend/libretro.c | 108 |
1 files changed, 64 insertions, 44 deletions
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(); |