From 5c07678c305dbf81aa85f95f900f50863da8d668 Mon Sep 17 00:00:00 2001 From: notaz Date: Sat, 25 Nov 2023 02:52:47 +0200 Subject: [PATCH] try different dualshock analog heuristics libretro/pcsx_rearmed#765 --- include/psemu_plugin_defs.h | 4 +++- libpcsxcore/plugins.c | 25 +++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/include/psemu_plugin_defs.h b/include/psemu_plugin_defs.h index 6136ca70..4e69b167 100644 --- a/include/psemu_plugin_defs.h +++ b/include/psemu_plugin_defs.h @@ -230,7 +230,9 @@ typedef struct unsigned int lastUseFrame; unsigned int unused; unsigned char configModeUsed; - unsigned char padding[3]; + unsigned char autoAnalogTried; + unsigned char userToggled; + unsigned char padding; } ds; unsigned char multitapLongModeEnabled; unsigned char padding2; diff --git a/libpcsxcore/plugins.c b/libpcsxcore/plugins.c index d7c2acb6..bab152c6 100644 --- a/libpcsxcore/plugins.c +++ b/libpcsxcore/plugins.c @@ -494,9 +494,28 @@ static void initBufForRequest(int padIndex, char value) { return; } - if ((u32)(frame_counter - pads[padIndex].ds.lastUseFrame) > 60u + if ((u32)(frame_counter - pads[padIndex].ds.lastUseFrame) > 2*60u + && pads[padIndex].ds.configModeUsed && !Config.hacks.dualshock_init_analog) + { + //SysPrintf("Pad reset\n"); pads[padIndex].ds.padMode = 0; // according to nocash + pads[padIndex].ds.autoAnalogTried = 0; + } + else if (pads[padIndex].ds.padMode == 0 && value == CMD_READ_DATA_AND_VIBRATE + && pads[padIndex].ds.configModeUsed + && !pads[padIndex].ds.configMode + && !pads[padIndex].ds.userToggled) + { + if (pads[padIndex].ds.autoAnalogTried == 16) { + // auto-enable for convenience + SysPrintf("Auto-enabling dualshock analog mode.\n"); + pads[padIndex].ds.padMode = 1; + pads[padIndex].ds.autoAnalogTried = 255; + } + else if (pads[padIndex].ds.autoAnalogTried < 16) + pads[padIndex].ds.autoAnalogTried++; + } pads[padIndex].ds.lastUseFrame = frame_counter; switch (value) { @@ -992,8 +1011,10 @@ int padToggleAnalog(unsigned int index) { int r = -1; - if (index < sizeof(pads) / sizeof(pads[0])) + if (index < sizeof(pads) / sizeof(pads[0])) { r = (pads[index].ds.padMode ^= 1); + pads[index].ds.userToggled = 1; + } return r; } -- 2.39.5