Skip to content

Commit

Permalink
Merge pull request #894 from sonninnos/analog-combo
Browse files Browse the repository at this point in the history
Change DualShock analog toggle combo behavior
  • Loading branch information
LibretroAdmin committed Feb 27, 2024
2 parents 43cf1df + b472802 commit 17a27f8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 12 deletions.
28 changes: 21 additions & 7 deletions libretro.cpp
Expand Up @@ -386,6 +386,7 @@ static void extract_directory(char *buf, const char *path, size_t size)
#include <ctype.h>

bool setting_apply_analog_toggle = false;
bool setting_apply_analog_default = false;
bool use_mednafen_memcard0_method = false;

extern MDFNGI EmulatedPSX;
Expand Down Expand Up @@ -1980,15 +1981,15 @@ static void InitCommon(std::vector<CDIF *> *_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];
snprintf(buf, sizeof(buf), "psx.input.port%u.gun_chairs", i + 1);
PSX_FIO->SetCrosshairsColor(i, MDFN_GetSettingUI(buf));
}

input_set_fio( PSX_FIO );
input_set_fio(PSX_FIO);

DMA_Init();

Expand Down Expand Up @@ -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);
Expand Down
9 changes: 5 additions & 4 deletions libretro_core_options.h
Expand Up @@ -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"
Expand All @@ -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",
{
Expand All @@ -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",
{
Expand Down
12 changes: 11 additions & 1 deletion mednafen/psx/input/dualshock.cpp
Expand Up @@ -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",
Expand Down

0 comments on commit 17a27f8

Please sign in to comment.