aboutsummaryrefslogtreecommitdiff
path: root/libpcsxcore/psxcounters.c
diff options
context:
space:
mode:
authornotaz2012-11-10 22:06:12 +0200
committernotaz2012-11-10 22:06:12 +0200
commita29f182fb4cf03fb74ec809746cee757f6d47715 (patch)
treeca7e376ccf43c782d0b975fc63abf88a7f22dbe4 /libpcsxcore/psxcounters.c
parentcc8ae53ee4b7c36540b616e5b9bd16a10efd168a (diff)
downloadpcsx_rearmed-a29f182fb4cf03fb74ec809746cee757f6d47715.tar.gz
pcsx_rearmed-a29f182fb4cf03fb74ec809746cee757f6d47715.tar.bz2
pcsx_rearmed-a29f182fb4cf03fb74ec809746cee757f6d47715.zip
psxcounters: refresh internal state after savestate load
fixes some glitching after pre-r14 save load
Diffstat (limited to 'libpcsxcore/psxcounters.c')
-rw-r--r--libpcsxcore/psxcounters.c107
1 files changed, 63 insertions, 44 deletions
diff --git a/libpcsxcore/psxcounters.c b/libpcsxcore/psxcounters.c
index 8fc33b4..3e6d417 100644
--- a/libpcsxcore/psxcounters.c
+++ b/libpcsxcore/psxcounters.c
@@ -152,6 +152,52 @@ u32 _psxRcntRcount( u32 index )
return count;
}
+static
+void _psxRcntWmode( u32 index, u32 value )
+{
+ rcnts[index].mode = value;
+
+ switch( index )
+ {
+ case 0:
+ if( value & Rc0PixelClock )
+ {
+ rcnts[index].rate = 5;
+ }
+ else
+ {
+ rcnts[index].rate = 1;
+ }
+ break;
+ case 1:
+ if( value & Rc1HSyncClock )
+ {
+ rcnts[index].rate = (PSXCLK / (FrameRate[Config.PsxType] * HSyncTotal[Config.PsxType]));
+ }
+ else
+ {
+ rcnts[index].rate = 1;
+ }
+ break;
+ case 2:
+ if( value & Rc2OneEighthClock )
+ {
+ rcnts[index].rate = 8;
+ }
+ else
+ {
+ rcnts[index].rate = 1;
+ }
+
+ // TODO: wcount must work.
+ if( value & Rc2Disable )
+ {
+ rcnts[index].rate = 0xffffffff;
+ }
+ break;
+ }
+}
+
/******************************************************************************/
static
@@ -357,50 +403,10 @@ void psxRcntWmode( u32 index, u32 value )
{
verboseLog( 1, "[RCNT %i] wmode: %x\n", index, value );
- rcnts[index].mode = value;
- rcnts[index].irqState = 0;
-
- switch( index )
- {
- case 0:
- if( value & Rc0PixelClock )
- {
- rcnts[index].rate = 5;
- }
- else
- {
- rcnts[index].rate = 1;
- }
- break;
- case 1:
- if( value & Rc1HSyncClock )
- {
- rcnts[index].rate = (PSXCLK / (FrameRate[Config.PsxType] * HSyncTotal[Config.PsxType]));
- }
- else
- {
- rcnts[index].rate = 1;
- }
- break;
- case 2:
- if( value & Rc2OneEighthClock )
- {
- rcnts[index].rate = 8;
- }
- else
- {
- rcnts[index].rate = 1;
- }
-
- // TODO: wcount must work.
- if( value & Rc2Disable )
- {
- rcnts[index].rate = 0xffffffff;
- }
- break;
- }
-
+ _psxRcntWmode( index, value );
_psxRcntWcount( index, 0 );
+
+ rcnts[index].irqState = 0;
psxRcntSet();
}
@@ -497,6 +503,9 @@ void psxRcntInit()
s32 psxRcntFreeze( gzFile f, s32 Mode )
{
+ u32 count;
+ s32 i;
+
gzfreeze( &rcnts, sizeof(rcnts) );
gzfreeze( &hSyncCount, sizeof(hSyncCount) );
gzfreeze( &spuSyncCount, sizeof(spuSyncCount) );
@@ -504,9 +513,19 @@ s32 psxRcntFreeze( gzFile f, s32 Mode )
gzfreeze( &psxNextsCounter, sizeof(psxNextsCounter) );
if (Mode == 0)
+ {
+ // don't trust things from a savestate
+ for( i = 0; i < CounterQuantity; ++i )
+ {
+ _psxRcntWmode( i, rcnts[i].mode );
+ count = (psxRegs.cycle - rcnts[i].cycleStart) / rcnts[i].rate;
+ _psxRcntWcount( i, count );
+ }
hsync_steps = (psxRegs.cycle - rcnts[3].cycleStart) / rcnts[3].target;
+ psxRcntSet();
- base_cycle = 0;
+ base_cycle = 0;
+ }
return 0;
}