From 3faf5c235830d46b111bfc6459f50071b43f6a0d Mon Sep 17 00:00:00 2001 From: notaz Date: Sun, 24 Sep 2023 23:02:12 +0300 Subject: [PATCH] input changes part4 libretro/pcsx_rearmed#765 --- include/psemu_plugin_defs.h | 27 +++++++++++--------- libpcsxcore/misc.c | 2 ++ libpcsxcore/plugins.c | 49 ++++++++++++++++++++++++++++--------- libpcsxcore/plugins.h | 2 ++ 4 files changed, 58 insertions(+), 22 deletions(-) diff --git a/include/psemu_plugin_defs.h b/include/psemu_plugin_defs.h index d005d080..c7a0d1c9 100644 --- a/include/psemu_plugin_defs.h +++ b/include/psemu_plugin_defs.h @@ -200,6 +200,9 @@ typedef struct // controller type - fill it withe predefined values above unsigned char controllerType; + unsigned char padding; + unsigned short saveSize; + int portMultitap; int requestPadIndex; @@ -214,22 +217,24 @@ typedef struct // values are in range -128 - 127 unsigned char moveX, moveY; + // Lightgun values + int absoluteX, absoluteY; + unsigned char Vib[2]; unsigned char VibF[2]; - //configuration mode Request 0x43 - int configMode; - - unsigned char txData[34]; - + struct { + unsigned char configMode; + unsigned char padMode; // 0 : digital 1: analog + unsigned char cmd4dConfig[6]; + unsigned int lastUseFrame; + unsigned int digitalModeFrames; + } ds; unsigned char multitapLongModeEnabled; - unsigned char PadMode; // 0 : digital 1: analog - unsigned char cmd4dConfig[6]; - unsigned char reserved[46]; - - //Lightgun values - int absoluteX,absoluteY; + unsigned char padding2; + unsigned char txData[34]; + unsigned char reserved[26]; } PadDataS; /* NET PlugIn v2 */ diff --git a/libpcsxcore/misc.c b/libpcsxcore/misc.c index 50caad42..da1dbea8 100644 --- a/libpcsxcore/misc.c +++ b/libpcsxcore/misc.c @@ -690,6 +690,7 @@ int SaveState(const char *file) { psxRcntFreeze(f, 1); mdecFreeze(f, 1); new_dyna_freeze(f, 1); + padFreeze(f, 1); result = 0; cleanup: @@ -760,6 +761,7 @@ int LoadState(const char *file) { psxRcntFreeze(f, 0); mdecFreeze(f, 0); new_dyna_freeze(f, 0); + padFreeze(f, 0); if (Config.HLE) psxBiosCheckExe(biosBranchCheckOld, 0x60); diff --git a/libpcsxcore/plugins.c b/libpcsxcore/plugins.c index fb0ea614..6e5cdbfe 100644 --- a/libpcsxcore/plugins.c +++ b/libpcsxcore/plugins.c @@ -23,6 +23,7 @@ #include "plugins.h" #include "cdriso.h" +#include "psxcounters.h" static char IsoFile[MAXPATHLEN] = ""; static s64 cdOpenCaseTime = 0; @@ -480,7 +481,7 @@ enum { static void initBufForRequest(int padIndex, char value) { - if (pads[padIndex].configMode) { + if (pads[padIndex].ds.configMode) { buf[0] = 0xf3; buf[1] = 0x5a; respSize = 8; } @@ -489,12 +490,24 @@ static void initBufForRequest(int padIndex, char value) { return; } + // switch to analog mode automatically after the game finishes init + if (value == 0x42 && pads[padIndex].ds.padMode == 0) + pads[padIndex].ds.digitalModeFrames++; + if (pads[padIndex].ds.digitalModeFrames == 60*4) { + pads[padIndex].ds.padMode = 1; + pads[padIndex].ds.digitalModeFrames = 0; + } + + if ((u32)(frame_counter - pads[padIndex].ds.lastUseFrame) > 60u) + pads[padIndex].ds.padMode = 0; // according to nocash + pads[padIndex].ds.lastUseFrame = frame_counter; + switch (value) { // keystate already in buffer, set by PADstartPoll_() //case CMD_READ_DATA_AND_VIBRATE : // break; case CMD_CONFIG_MODE : - if (pads[padIndex].configMode) { + if (pads[padIndex].ds.configMode) { memcpy(buf, resp43, 8); break; } @@ -505,7 +518,7 @@ static void initBufForRequest(int padIndex, char value) { break; case CMD_QUERY_MODEL_AND_MODE : memcpy(buf, resp45, 8); - buf[4] = pads[padIndex].PadMode; + buf[4] = pads[padIndex].ds.padMode; break; case CMD_QUERY_ACT : memcpy(buf, resp46_00, 8); @@ -517,7 +530,7 @@ static void initBufForRequest(int padIndex, char value) { memcpy(buf, resp4C_00, 8); break; case CMD_VIBRATION_TOGGLE: // 4d - memcpy(buf + 2, pads[padIndex].cmd4dConfig, 6); + memcpy(buf + 2, pads[padIndex].ds.cmd4dConfig, 6); break; case REQ40 : memcpy(buf, resp40, 8); @@ -548,9 +561,9 @@ static void reqIndex2Treatment(int padIndex, u8 value) { case CMD_CONFIG_MODE : //0x43 if (value == 0) { - pads[padIndex].configMode = 0; + pads[padIndex].ds.configMode = 0; } else { - pads[padIndex].configMode = 1; + pads[padIndex].ds.configMode = 1; } break; case CMD_SET_MODE_AND_LOCK : @@ -558,7 +571,7 @@ static void reqIndex2Treatment(int padIndex, u8 value) { //0x01 analog ON //0x00 analog OFF if ((value & ~1) == 0) - pads[padIndex].PadMode = value; + pads[padIndex].ds.padMode = value; break; case CMD_QUERY_ACT : //0x46 @@ -585,7 +598,7 @@ static void vibrate(int padIndex) { pad->VibF[0] = pad->Vib[0]; pad->VibF[1] = pad->Vib[1]; plat_trigger_vibrate(padIndex, pad->VibF[0], pad->VibF[1]); - //printf("vibration pad %i\n", padIndex); + //printf("vib%i %02x %02x\n", padIndex, pad->VibF[0], pad->VibF[1]); } } @@ -671,7 +684,7 @@ static void PADstartPoll_(PadDataS *pad) { respSize = 4; break; case PSE_PAD_TYPE_ANALOGPAD: // scph1150 - if (pad->PadMode == 0) + if (pad->ds.padMode == 0) goto standard; stdpar[0] = 0x73; stdpar[1] = 0x5a; @@ -730,7 +743,7 @@ static void PADpoll_dualshock(int port, unsigned char value, int pos) break; case 7: if (pads[port].txData[0] == CMD_VIBRATION_TOGGLE) - memcpy(pads[port].cmd4dConfig, pads[port].txData + 2, 6); + memcpy(pads[port].ds.cmd4dConfig, pads[port].txData + 2, 6); break; } } @@ -865,7 +878,7 @@ static int LoadPAD1plugin(const char *PAD1dll) { memset(pads, 0, sizeof(pads)); for (p = 0; p < sizeof(pads) / sizeof(pads[0]); p++) { - memset(pads[p].cmd4dConfig, 0xff, sizeof(pads[p].cmd4dConfig)); + memset(pads[p].ds.cmd4dConfig, 0xff, sizeof(pads[p].ds.cmd4dConfig)); } return 0; @@ -940,6 +953,20 @@ static int LoadPAD2plugin(const char *PAD2dll) { return 0; } +int padFreeze(void *f, int Mode) { + size_t i; + + for (i = 0; i < sizeof(pads) / sizeof(pads[0]); i++) { + pads[i].saveSize = sizeof(pads[i]); + gzfreeze(&pads[i], sizeof(pads[i])); + if (Mode == 0 && pads[i].saveSize != sizeof(pads[i])) + SaveFuncs.seek(f, pads[i].saveSize - sizeof(pads[i]), SEEK_CUR); + } + + return 0; +} + + void *hNETDriver = NULL; void CALLBACK NET__setInfo(netInfo *info) {} diff --git a/libpcsxcore/plugins.h b/libpcsxcore/plugins.h index c563470b..e43ff9ad 100644 --- a/libpcsxcore/plugins.h +++ b/libpcsxcore/plugins.h @@ -381,6 +381,8 @@ const char *GetIsoFile(void); boolean UsingIso(void); void SetCdOpenCaseTime(s64 time); +int padFreeze(void *f, int Mode); + extern void pl_gun_byte2(int port, unsigned char byte); extern void plat_trigger_vibrate(int pad, int low, int high); extern void plat_get_psx_resolution(int *xres, int *yres); -- 2.39.2