From b47280290e6c6a807290259d660e04045b71b18c Mon Sep 17 00:00:00 2001 From: sonninnos Date: Thu, 22 Feb 2024 12:42:39 +0200 Subject: [PATCH] Change DualShock analog toggle combo behavior --- libretro.cpp | 28 +++++++++++++++++++++------- libretro_core_options.h | 9 +++++---- mednafen/psx/input/dualshock.cpp | 12 +++++++++++- 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/libretro.cpp b/libretro.cpp index 9a5ba8130..0bd84847b 100644 --- a/libretro.cpp +++ b/libretro.cpp @@ -386,6 +386,7 @@ static void extract_directory(char *buf, const char *path, size_t size) #include bool setting_apply_analog_toggle = false; +bool setting_apply_analog_default = false; bool use_mednafen_memcard0_method = false; extern MDFNGI EmulatedPSX; @@ -1980,7 +1981,7 @@ static void InitCommon(std::vector *_CDInterfaces, const bool EmulateMem PSX_CDC = new PS_CDC(); PSX_FIO = new FrontIO(emulate_memcard, emulate_multitap); - PSX_FIO->SetAMCT(MDFN_GetSettingB("psx.input.analog_mode_ct")); + PSX_FIO->SetAMCT(setting_psx_analog_toggle); for(unsigned i = 0; i < 2; i++) { char buf[64]; @@ -1988,7 +1989,7 @@ static void InitCommon(std::vector *_CDInterfaces, const bool EmulateMem PSX_FIO->SetCrosshairsColor(i, MDFN_GetSettingUI(buf)); } - input_set_fio( PSX_FIO ); + input_set_fio(PSX_FIO); DMA_Init(); @@ -3624,18 +3625,31 @@ static void check_variables(bool startup) var.key = BEETLE_OPT(analog_toggle); if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { - if ((strcmp(var.value, "enabled") == 0) - && setting_psx_analog_toggle != 1) + if ((strcmp(var.value, "disabled") == 0) + && setting_psx_analog_toggle) + { + setting_psx_analog_toggle = 0; + setting_apply_analog_toggle = true; + setting_apply_analog_default = false; + } + else if ((strcmp(var.value, "enabled") == 0) + && (!setting_psx_analog_toggle || setting_apply_analog_default)) { setting_psx_analog_toggle = 1; setting_apply_analog_toggle = true; + setting_apply_analog_default = false; } - else if ((strcmp(var.value, "disabled") == 0) - && setting_psx_analog_toggle != 0) + else if ((strcmp(var.value, "enabled-analog") == 0) + && (!setting_psx_analog_toggle || !setting_apply_analog_default)) { - setting_psx_analog_toggle = 0; + setting_psx_analog_toggle = 1; setting_apply_analog_toggle = true; + setting_apply_analog_default = true; } + + /* No need to apply if going to do it in InitCommon */ + if (startup) + setting_apply_analog_toggle = false; } var.key = BEETLE_OPT(analog_toggle_combo); diff --git a/libretro_core_options.h b/libretro_core_options.h index 16a17e155..2280dde1f 100644 --- a/libretro_core_options.h +++ b/libretro_core_options.h @@ -384,14 +384,15 @@ struct retro_core_option_v2_definition option_defs_us[] = { }, { BEETLE_OPT(analog_toggle), - "Enable DualShock Analog Mode Toggle", + "DualShock Analog Mode Toggle", NULL, - "When the input device type is DualShock, this option allows the emulated DualShock to be toggled between DIGITAL and ANALOG mode like original hardware. When disabled, the DualShock is locked to ANALOG mode and when enabled, the DualShock can be toggled between DIGITAL and ANALOG mode by using the selected buttons combination.", + "When the input device type is DualShock, this option allows the emulated DualShock to be toggled between DIGITAL and ANALOG mode like original hardware. Mode can also be toggled by using the selected button combination.", NULL, "input", { { "disabled", NULL }, { "enabled", NULL }, + { "enabled-analog", "Default-Analog" }, { NULL, NULL }, }, "disabled" @@ -400,7 +401,7 @@ struct retro_core_option_v2_definition option_defs_us[] = { BEETLE_OPT(analog_toggle_combo), "DualShock Analog Mode Combo", NULL, - "Choose the buttons combination that will be used to toggle between DIGITAL and ANALOG mode for the emulated DualShock. Only works when 'Enable DualShock Analog Mode Toggle' is enabled.", + "Choose the button combination that will be used to toggle between DIGITAL and ANALOG mode for the emulated DualShock.", NULL, "input", { @@ -422,7 +423,7 @@ struct retro_core_option_v2_definition option_defs_us[] = { BEETLE_OPT(analog_toggle_hold), "DualShock Analog Mode Combo Hold Delay", NULL, - "Sets the hold time for the analog mode combo buttons. Only works when 'Enable DualShock Analog Mode Toggle' is enabled.", + "Set the hold time for the analog mode combo buttons.", NULL, "input", { diff --git a/mednafen/psx/input/dualshock.cpp b/mednafen/psx/input/dualshock.cpp index 471cdeba0..5905f6c71 100644 --- a/mednafen/psx/input/dualshock.cpp +++ b/mednafen/psx/input/dualshock.cpp @@ -149,14 +149,24 @@ void InputDevice_DualShock::ResetTS(void) lastts = 0; } +#ifdef __LIBRETRO__ +extern bool setting_apply_analog_default; +#endif + void InputDevice_DualShock::SetAMCT(bool enabled) { + bool amct_prev_info = amct_enabled; amct_enabled = enabled; if(amct_enabled) - analog_mode = false; + analog_mode = setting_apply_analog_default; else analog_mode = true; + if (amct_prev_info == analog_mode && amct_prev_info == amct_enabled) + return; + + am_prev_info = analog_mode; + MDFN_DispMessage(2, RETRO_LOG_INFO, RETRO_MESSAGE_TARGET_OSD, RETRO_MESSAGE_TYPE_NOTIFICATION_ALT, "%s: Analog toggle is %s, sticks are %s",