aboutsummaryrefslogtreecommitdiff
path: root/frontend/libretro.c
diff options
context:
space:
mode:
authorAdrien Plazas2016-07-29 19:23:29 +0200
committerAdrien Plazas2016-07-29 19:23:29 +0200
commit8136cafb75203da58874df9af36c19cac06f715d (patch)
tree87818d662505b1231cccba46898bf7eafab7484d /frontend/libretro.c
parent41ad29beb13d815c2cfa9abb3fc8e87f80e7370e (diff)
downloadpcsx_rearmed-8136cafb75203da58874df9af36c19cac06f715d.tar.gz
pcsx_rearmed-8136cafb75203da58874df9af36c19cac06f715d.tar.bz2
pcsx_rearmed-8136cafb75203da58874df9af36c19cac06f715d.zip
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.
Diffstat (limited to 'frontend/libretro.c')
-rw-r--r--frontend/libretro.c117
1 files changed, 30 insertions, 87 deletions
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";