PlayAgain changes to PCSX-ReARMed, made 2026-10-30 by the PlayAgain project (playagain.app). libpcsxcore/misc.c and the other files below are changed: a save state keeps what a load used to lose, and a load no longer rewrites a timer's count. Licensed under GPL-2.0, as the files it changes. diff --git a/libpcsxcore/misc.c b/libpcsxcore/misc.c index 3867a66..38b86a0 100644 --- a/libpcsxcore/misc.c +++ b/libpcsxcore/misc.c @@ -724,7 +724,15 @@ struct misc_save_data { u32 frame_counter; int CdromFrontendId; u32 save_counter; + // PlayAgain: what a load used to lose, so that any load is exact. A state + // without PA_MISC_MAGIC here is an older one: these stay as a load leaves them. + u32 pa_magic; + u32 pa_subCycle; + s32 pa_pad_reqPos; + u32 pa_pad_replug_frame; + u8 pa_McdFlag[2]; }; +#define PA_MISC_MAGIC 0x314E4150 // "PAN1" #define EX_SCREENPIC_SIZE (128 * 96 * 3) @@ -761,6 +769,11 @@ int SaveState(const char *file) { misc->frame_counter = frame_counter; misc->CdromFrontendId = CdromFrontendId; misc->save_counter = ++save_counter; + misc->pa_magic = PA_MISC_MAGIC; + misc->pa_subCycle = psxRegs.subCycle; + padGetPollState(&misc->pa_pad_reqPos, &misc->pa_pad_replug_frame); + misc->pa_McdFlag[0] = McdFlag[0]; + misc->pa_McdFlag[1] = McdFlag[1]; psxCpu->Notify(R3000ACPU_NOTIFY_BEFORE_SAVE, NULL); @@ -933,6 +946,7 @@ int LoadState(const char *file) { sioFreeze(f, 0); cdrFreeze(f, 0); psxHwFreeze(f, 0); + psxRcntLoadExact = misc->pa_magic == PA_MISC_MAGIC; psxRcntFreeze(f, 0); mdecFreeze(f, 0); @@ -950,6 +964,16 @@ int LoadState(const char *file) { psxCpu->Notify(R3000ACPU_NOTIFY_AFTER_LOAD_STATE, NULL); + // After padFreeze (padChanged clears the pad state), the interpreter's + // after-load handler (it zeroes subCycle) and sioFreeze (it raises the + // cards' "new card" flag, and a game then rewrites the card). + if (misc->pa_magic == PA_MISC_MAGIC) { + psxRegs.subCycle = misc->pa_subCycle; + padSetPollState(misc->pa_pad_reqPos, misc->pa_pad_replug_frame); + McdFlag[0] = misc->pa_McdFlag[0]; + McdFlag[1] = misc->pa_McdFlag[1]; + } + result = 0; cleanup: memset(misc, 0, sizeof(*misc)); diff --git a/libpcsxcore/pad.c b/libpcsxcore/pad.c index 6d95f50..139e8a5 100644 --- a/libpcsxcore/pad.c +++ b/libpcsxcore/pad.c @@ -609,6 +609,18 @@ int padFreeze(void *f, int Mode) return 0; } +void padGetPollState(s32 *reqPos, u32 *replug_frame) +{ + *reqPos = g.reqPos; + *replug_frame = g.replug_frame; +} + +void padSetPollState(s32 reqPos, u32 replug_frame) +{ + g.reqPos = reqPos; + g.replug_frame = replug_frame; +} + int padToggleAnalog(unsigned int index) { int r = -1; diff --git a/libpcsxcore/plugins.h b/libpcsxcore/plugins.h index 80831c0..c0110a9 100644 --- a/libpcsxcore/plugins.h +++ b/libpcsxcore/plugins.h @@ -133,6 +133,8 @@ unsigned char PAD2_startPoll(void); unsigned char PAD2_poll(unsigned char, int *); int padFreeze(void *f, int Mode); +void padGetPollState(s32 *reqPos, u32 *replug_frame); +void padSetPollState(s32 reqPos, u32 replug_frame); int padToggleAnalog(unsigned int index); void padReset(void); void padChanged(void); diff --git a/libpcsxcore/psxcounters.c b/libpcsxcore/psxcounters.c index 471980e..14da29f 100644 --- a/libpcsxcore/psxcounters.c +++ b/libpcsxcore/psxcounters.c @@ -585,6 +585,8 @@ void psxRcntInit() /******************************************************************************/ +int psxRcntLoadExact; + s32 psxRcntFreeze( void *f, s32 Mode ) { u32 spuSyncCount = 0; @@ -604,7 +606,9 @@ s32 psxRcntFreeze( void *f, s32 Mode ) { _psxRcntWmode( i, rcnts[i].mode ); count = (psxRegs.cycle - rcnts[i].cycleStart) / rcnts[i].rate; - if (count > 0x1000) + // (PlayAgain) rewriting the count drops the fraction a slow counter + // holds in cycleStart; a state that says so keeps the saved one. + if (count > 0x1000 && !psxRcntLoadExact) _psxRcntWcount( i, count & 0xffff ); } scheduleRcntBase(); diff --git a/libpcsxcore/psxcounters.h b/libpcsxcore/psxcounters.h index ceaf8b8..ebd3ac6 100644 --- a/libpcsxcore/psxcounters.h +++ b/libpcsxcore/psxcounters.h @@ -52,6 +52,7 @@ u32 psxRcntRcount2(); u32 psxRcntRmode(u32 index); u32 psxRcntRtarget(u32 index); +extern int psxRcntLoadExact; s32 psxRcntFreeze(void *f, s32 Mode); double psxGetFps();