From 30d43b8abe6aef8844aa1f48f505ba238a01c2a6 Mon Sep 17 00:00:00 2001 From: Adrien Plazas Date: Fri, 29 Jul 2016 19:18:27 +0200 Subject: [PATCH] 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(-) diff --git a/frontend/libretro.c b/frontend/libretro.c index 4de0185b..274d6d5f 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"; -- 2.39.5