diff --git a/pcsx2/Counters.c b/pcsx2/Counters.c index bd7d4d4626..8264db0b79 100644 --- a/pcsx2/Counters.c +++ b/pcsx2/Counters.c @@ -56,12 +56,19 @@ static __forceinline void _rcntSet( int i ) u32 c; if (!(counters[i].mode & 0x80) || (counters[i].mode & 0x3) == 0x3) return; // Stopped + // psxNextCounter is relative to the cpuRegs.cycle when rcntUpdate() was last called. + // However, the current _rcntSet could be called at any cycle count, so we need to take + // that into account. Adding the difference from that cycle count to the current one + // will do the trick! + c = ((0x10000 - counters[i].count) * counters[i].rate) - (cpuRegs.cycle - counters[i].sCycleT); + c += cpuRegs.cycle - psxNextsCounter; // adjust for time passed since last rcntUpdate(); if (c < nextCounter) nextCounter = c; //if(!(counters[i].mode & 0x100) || counters[i].target > 0xffff) continue; c = ((counters[i].target - counters[i].count) * counters[i].rate) - (cpuRegs.cycle - counters[i].sCycleT); + c += cpuRegs.cycle - psxNextsCounter; // adjust for time passed since last rcntUpdate(); if (c < nextCounter) nextCounter = c; } diff --git a/pcsx2/PsxCounters.c b/pcsx2/PsxCounters.c index 49464b418d..d1debd9759 100644 --- a/pcsx2/PsxCounters.c +++ b/pcsx2/PsxCounters.c @@ -63,14 +63,21 @@ __forceinline static void _rcntSet( int i, int bitwise ) assert( i < 3 ); #endif + // psxNextCounter is relative to the cpuRegs.cycle when rcntUpdate() was last called. + // However, the current _rcntSet could be called at any cycle count, so we need to take + // that into account. Adding the difference from that cycle count to the current one + // will do the trick! + if(psxCounters[i].rate == PSXHBLANK) return; c = (u64)((overflowCap - psxCounters[i].count) * psxCounters[i].rate) - (psxRegs.cycle - psxCounters[i].sCycleT); + c += cpuRegs.cycle - psxNextsCounter; // adjust for time passed since last rcntUpdate(); if (c < psxNextCounter) psxNextCounter = (u32)c; //if((psxCounters[i].mode & 0x10) == 0 || psxCounters[i].target > 0xffff) continue; c = (u64)((psxCounters[i].target - psxCounters[i].count) * psxCounters[i].rate) - (psxRegs.cycle - psxCounters[i].sCycleT); + c += cpuRegs.cycle - psxNextsCounter; // adjust for time passed since last rcntUpdate(); if (c < psxNextCounter) psxNextCounter = (u32)c; } diff --git a/pcsx2/x86/iR3000A.cpp b/pcsx2/x86/iR3000A.cpp index 055ae4bee9..36d147e56d 100644 --- a/pcsx2/x86/iR3000A.cpp +++ b/pcsx2/x86/iR3000A.cpp @@ -582,6 +582,11 @@ static int recInit() { } static void recReset() { + +#ifdef PCSX2_DEVBUILD + SysPrintf("IOP Recompiler data reset\n"); +#endif + memset(recRAM, 0, sizeof(BASEBLOCK)/4*0x200000); memset(recROM, 0, sizeof(BASEBLOCK)/4*0x400000); memset(recROM1,0, sizeof(BASEBLOCK)/4*0x040000); diff --git a/pcsx2/x86/ix86-32/iR5900-32.c b/pcsx2/x86/ix86-32/iR5900-32.c index fd7b154a43..0d125e26e0 100644 --- a/pcsx2/x86/ix86-32/iR5900-32.c +++ b/pcsx2/x86/ix86-32/iR5900-32.c @@ -1589,7 +1589,7 @@ int recInit( void ) } //////////////////////////////////////////////////// -void recReset( void ) { +static void recReset( void ) { #ifdef PCSX2_DEVBUILD SysPrintf("EE Recompiler data reset\n"); #endif