Savestates: Add missing things from Savestates (#4917)

Savestates: Add missing variables from Savestates
This commit is contained in:
refractionpcsx2 2021-10-20 10:41:50 +01:00 committed by GitHub
parent c3e5b4225b
commit 24e73b3134
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 155 additions and 28 deletions

View File

@ -131,9 +131,15 @@ static __fi void cpuRcntSet()
{ {
int i; int i;
// Default to next VBlank
nextsCounter = cpuRegs.cycle; nextsCounter = cpuRegs.cycle;
nextCounter = vsyncCounter.CycleT - (cpuRegs.cycle - vsyncCounter.sCycle); nextCounter = vsyncCounter.CycleT - (cpuRegs.cycle - vsyncCounter.sCycle);
// Also check next HSync
s32 nextHsync = hsyncCounter.CycleT - (cpuRegs.cycle - hsyncCounter.sCycle);
if (nextHsync < nextCounter)
nextCounter = nextHsync;
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
_rcntSet( i ); _rcntSet( i );
@ -1044,13 +1050,8 @@ void SaveStateBase::rcntFreeze()
Freeze( vSyncInfo ); Freeze( vSyncInfo );
Freeze( gsVideoMode ); Freeze( gsVideoMode );
Freeze( gsIsInterlaced ); Freeze( gsIsInterlaced );
Freeze( gates );
if( IsLoading() ) if( IsLoading() )
{ cpuRcntSet();
// make sure the gate flags are set based on the counter modes...
for( int i=0; i<4; i++ )
_rcntSetGate( i );
iopEventAction = 1; // probably not needed but won't hurt anything either.
}
} }

View File

@ -852,9 +852,6 @@ void SaveStateBase::gifDmaFreeze()
{ {
// Note: mfifocycles is not a persistent var, so no need to save it here. // Note: mfifocycles is not a persistent var, so no need to save it here.
FreezeTag("GIFdma"); FreezeTag("GIFdma");
Freeze(gif.gifstate); Freeze(gif);
Freeze(gif.gifqwc);
Freeze(gif.gspath3done);
Freeze(gif.gscycles);
Freeze(gif_fifo); Freeze(gif_fifo);
} }

View File

@ -881,7 +881,9 @@ void SaveStateBase::psxRcntFreeze()
Freeze(psxCounters); Freeze(psxCounters);
Freeze(psxNextCounter); Freeze(psxNextCounter);
Freeze(psxNextsCounter); Freeze(psxNextsCounter);
Freeze(psxvblankgate);
Freeze(psxhblankgate);
if (IsLoading()) if (IsLoading())
psxRcntSetGates(); psxRcntUpdate();
} }

View File

@ -32,6 +32,8 @@ enum MTVU_EVENT
MTVU_VU_EXECUTE, // Execute VU program MTVU_VU_EXECUTE, // Execute VU program
MTVU_VU_WRITE_MICRO, // Write to VU micro-mem MTVU_VU_WRITE_MICRO, // Write to VU micro-mem
MTVU_VU_WRITE_DATA, // Write to VU data-mem MTVU_VU_WRITE_DATA, // Write to VU data-mem
MTVU_VU_WRITE_VIREGS,// Write to VU registers
MTVU_VU_WRITE_VFREGS,// Write to VU registers
MTVU_VIF_WRITE_COL, // Write to Vif col reg MTVU_VIF_WRITE_COL, // Write to Vif col reg
MTVU_VIF_WRITE_ROW, // Write to Vif row reg MTVU_VIF_WRITE_ROW, // Write to Vif row reg
MTVU_VIF_UNPACK, // Execute Vif Unpack MTVU_VIF_UNPACK, // Execute Vif Unpack
@ -62,6 +64,8 @@ void SaveStateBase::mtvuFreeze()
vu1Thread.WriteRow(vif1); vu1Thread.WriteRow(vif1);
vu1Thread.WriteMicroMem(0, VU1.Micro, 0x4000); vu1Thread.WriteMicroMem(0, VU1.Micro, 0x4000);
vu1Thread.WriteDataMem(0, VU1.Mem, 0x4000); vu1Thread.WriteDataMem(0, VU1.Mem, 0x4000);
vu1Thread.WriteVIRegs(&VU1.VI[0]);
vu1Thread.WriteVFRegs(&VU1.VF[0]);
} }
for (size_t i = 0; i < 4; ++i) for (size_t i = 0; i < 4; ++i)
{ {
@ -168,6 +172,12 @@ void VU_Thread::ExecuteRingBuffer()
Read(&vuRegs.Mem[vu_data_addr], size); Read(&vuRegs.Mem[vu_data_addr], size);
break; break;
} }
case MTVU_VU_WRITE_VIREGS:
Read(&vuRegs.VI, size_u32(32));
break;
case MTVU_VU_WRITE_VFREGS:
Read(&vuRegs.VF, size_u32(4*32));
break;
case MTVU_VIF_WRITE_COL: case MTVU_VIF_WRITE_COL:
Read(&vif.MaskCol, sizeof(vif.MaskCol)); Read(&vif.MaskCol, sizeof(vif.MaskCol));
break; break;
@ -491,6 +501,26 @@ void VU_Thread::WriteDataMem(u32 vu_data_addr, void* data, u32 size)
KickStart(); KickStart();
} }
void VU_Thread::WriteVIRegs(REG_VI* viRegs)
{
MTVU_LOG("MTVU - WriteRegs!");
ReserveSpace(1 + size_u32(32));
Write(MTVU_VU_WRITE_VIREGS);
Write(viRegs, size_u32(32));
CommitWritePos();
KickStart();
}
void VU_Thread::WriteVFRegs(VECTOR* vfRegs)
{
MTVU_LOG("MTVU - WriteRegs!");
ReserveSpace(1 + size_u32(32*4));
Write(MTVU_VU_WRITE_VFREGS);
Write(vfRegs, size_u32(32*4));
CommitWritePos();
KickStart();
}
void VU_Thread::WriteCol(vifStruct& _vif) void VU_Thread::WriteCol(vifStruct& _vif)
{ {
MTVU_LOG("MTVU - WriteCol!"); MTVU_LOG("MTVU - WriteCol!");

View File

@ -86,6 +86,10 @@ public:
// Writes to VU's Data Memory (size in bytes) // Writes to VU's Data Memory (size in bytes)
void WriteDataMem(u32 vu_data_addr, void* data, u32 size); void WriteDataMem(u32 vu_data_addr, void* data, u32 size);
void WriteVIRegs(REG_VI* viRegs);
void WriteVFRegs(VECTOR* vfRegs);
void WriteCol(vifStruct& _vif); void WriteCol(vifStruct& _vif);
void WriteRow(vifStruct& _vif); void WriteRow(vifStruct& _vif);

View File

@ -212,7 +212,6 @@ __ri void iopEventTest()
g_iopNextEventCycle = psxNextsCounter+psxNextCounter; g_iopNextEventCycle = psxNextsCounter+psxNextCounter;
} }
if (psxRegs.interrupt) if (psxRegs.interrupt)
{ {
iopEventTestIsActive = true; iopEventTestIsActive = true;

View File

@ -22,8 +22,6 @@
static bool spr0finished = false; static bool spr0finished = false;
static bool spr1finished = false; static bool spr1finished = false;
static bool spr0lastqwc = false;
static bool spr1lastqwc = false;
static u32 mfifotransferred = 0; static u32 mfifotransferred = 0;
static void TestClearVUs(u32 madr, u32 qwc, bool isWrite) static void TestClearVUs(u32 madr, u32 qwc, bool isWrite)
@ -342,8 +340,6 @@ void SPRFROMinterrupt()
return; return;
} }
spr0lastqwc = false;
spr0ch.chcr.STR = false; spr0ch.chcr.STR = false;
hwDmacIrq(DMAC_FROM_SPR); hwDmacIrq(DMAC_FROM_SPR);
DMA_LOG("SPR0 DMA End"); DMA_LOG("SPR0 DMA End");
@ -539,7 +535,6 @@ void SPRTOinterrupt()
DMA_LOG("SPR1 DMA End"); DMA_LOG("SPR1 DMA End");
spr1ch.chcr.STR = false; spr1ch.chcr.STR = false;
spr1lastqwc = false;
hwDmacIrq(DMAC_TO_SPR); hwDmacIrq(DMAC_TO_SPR);
} }

View File

@ -32,6 +32,7 @@
#include "common/pxStreams.h" #include "common/pxStreams.h"
#include "common/SafeArray.inl" #include "common/SafeArray.inl"
#include "common/StringUtil.h"
#include "SPU2/spu2.h" #include "SPU2/spu2.h"
#include "USB/USB.h" #include "USB/USB.h"
#ifdef _WIN32 #ifdef _WIN32
@ -214,16 +215,29 @@ SaveStateBase& SaveStateBase::FreezeInternals()
Freeze(AllowParams2); Freeze(AllowParams2);
Freeze(g_GameStarted); Freeze(g_GameStarted);
Freeze(g_GameLoading); Freeze(g_GameLoading);
Freeze(ElfCRC);
char localDiscSerial[256];
StringUtil::Strlcpy(localDiscSerial, DiscSerial.ToUTF8(), sizeof(localDiscSerial));
Freeze(localDiscSerial);
if (IsLoading())
DiscSerial = wxString::FromUTF8(localDiscSerial);
// Third Block - Cycle Timers and Events // Third Block - Cycle Timers and Events
// ------------------------------------- // -------------------------------------
FreezeTag( "Cycles" ); FreezeTag( "Cycles" );
Freeze(EEsCycle); Freeze(EEsCycle);
Freeze(EEoCycle); Freeze(EEoCycle);
Freeze(iopCycleEE);
Freeze(iopBreak);
Freeze(g_nextEventCycle); Freeze(g_nextEventCycle);
Freeze(g_iopNextEventCycle); Freeze(g_iopNextEventCycle);
Freeze(s_iLastCOP0Cycle); Freeze(s_iLastCOP0Cycle);
Freeze(s_iLastPERFCycle); Freeze(s_iLastPERFCycle);
Freeze(nextCounter);
Freeze(nextsCounter);
Freeze(psxNextsCounter);
Freeze(psxNextCounter);
// Fourth Block - EE-related systems // Fourth Block - EE-related systems
// --------------------------------- // ---------------------------------
@ -231,6 +245,7 @@ SaveStateBase& SaveStateBase::FreezeInternals()
rcntFreeze(); rcntFreeze();
gsFreeze(); gsFreeze();
vuMicroFreeze(); vuMicroFreeze();
vuJITFreeze();
vif0Freeze(); vif0Freeze();
vif1Freeze(); vif1Freeze();
sifFreeze(); sifFreeze();
@ -252,7 +267,6 @@ SaveStateBase& SaveStateBase::FreezeInternals()
cdrFreeze(); cdrFreeze();
cdvdFreeze(); cdvdFreeze();
// technically this is HLE BIOS territory, but we don't have enough such stuff // technically this is HLE BIOS territory, but we don't have enough such stuff
// to merit an HLE Bios sub-section... yet. // to merit an HLE Bios sub-section... yet.
deci2Freeze(); deci2Freeze();

View File

@ -31,7 +31,7 @@ enum class FreezeAction
// the lower 16 bit value. IF the change is breaking of all compatibility with old // the lower 16 bit value. IF the change is breaking of all compatibility with old
// states, increment the upper 16 bit value, and clear the lower 16 bits to 0. // states, increment the upper 16 bit value, and clear the lower 16 bits to 0.
static const u32 g_SaveVersion = (0x9A26 << 16) | 0x0000; static const u32 g_SaveVersion = (0x9A27 << 16) | 0x0000;
// the freezing data between submodules and core // the freezing data between submodules and core
// an interesting thing to note is that this dates back from before plugin // an interesting thing to note is that this dates back from before plugin
@ -152,6 +152,7 @@ protected:
void mtvuFreeze(); void mtvuFreeze();
void rcntFreeze(); void rcntFreeze();
void vuMicroFreeze(); void vuMicroFreeze();
void vuJITFreeze();
void vif0Freeze(); void vif0Freeze();
void vif1Freeze(); void vif1Freeze();
void sifFreeze(); void sifFreeze();

View File

@ -17,11 +17,10 @@
#include "PrecompiledHeader.h" #include "PrecompiledHeader.h"
#include "Common.h" #include "Common.h"
#include "VUmicro.h" #include "VUmicro.h"
#include "MTVU.h"
__aligned16 VURegs vuRegs[2]; __aligned16 VURegs vuRegs[2];
vuMemoryReserve::vuMemoryReserve() vuMemoryReserve::vuMemoryReserve()
: _parent( L"VU0/1 on-chip memory", VU1_PROGSIZE + VU1_MEMSIZE + VU0_PROGSIZE + VU0_MEMSIZE ) : _parent( L"VU0/1 on-chip memory", VU1_PROGSIZE + VU1_MEMSIZE + VU0_PROGSIZE + VU0_MEMSIZE )
{ {
@ -78,19 +77,95 @@ void vuMemoryReserve::Reset()
void SaveStateBase::vuMicroFreeze() void SaveStateBase::vuMicroFreeze()
{ {
if(IsSaving())
vu1Thread.WaitVU();
FreezeTag( "vuMicroRegs" ); FreezeTag( "vuMicroRegs" );
Freeze(VU0.ACC); // VU0 state information
Freeze(VU0.code);
Freeze(VU0.ACC);
Freeze(VU0.VF); Freeze(VU0.VF);
Freeze(VU0.VI); Freeze(VU0.VI);
Freeze(VU0.q);
Freeze(VU0.cycle);
Freeze(VU0.flags);
Freeze(VU0.code);
Freeze(VU0.start_pc);
Freeze(VU0.branch);
Freeze(VU0.branchpc);
Freeze(VU0.delaybranchpc);
Freeze(VU0.takedelaybranch);
Freeze(VU0.ebit);
Freeze(VU0.pending_q);
Freeze(VU0.pending_p);
Freeze(VU0.blockhasmbit);
Freeze(VU0.micro_macflags);
Freeze(VU0.micro_clipflags);
Freeze(VU0.micro_statusflags);
Freeze(VU0.macflag);
Freeze(VU0.statusflag);
Freeze(VU0.clipflag);
Freeze(VU0.nextBlockCycles);
Freeze(VU0.VIBackupCycles);
Freeze(VU0.VIOldValue);
Freeze(VU0.VIRegNumber);
Freeze(VU0.fmac);
Freeze(VU0.fmacreadpos);
Freeze(VU0.fmacwritepos);
Freeze(VU0.fmaccount);
Freeze(VU0.fdiv);
Freeze(VU0.efu);
Freeze(VU0.ialu);
Freeze(VU0.ialureadpos);
Freeze(VU0.ialuwritepos);
Freeze(VU0.ialucount);
// VU1 state information
Freeze(VU1.ACC); Freeze(VU1.ACC);
u32& temp_vu1_code = VU1.code;
Freeze(temp_vu1_code);
Freeze(VU1.VF); Freeze(VU1.VF);
Freeze(VU1.VI); Freeze(VU1.VI);
Freeze(VU1.q);
Freeze(VU1.p);
Freeze(VU1.cycle);
Freeze(VU1.flags);
Freeze(VU1.code);
Freeze(VU1.start_pc);
Freeze(VU1.branch);
Freeze(VU1.branchpc);
Freeze(VU1.delaybranchpc);
Freeze(VU1.takedelaybranch);
Freeze(VU1.ebit);
Freeze(VU1.pending_q);
Freeze(VU1.pending_p);
Freeze(VU1.blockhasmbit);
Freeze(VU1.micro_macflags);
Freeze(VU1.micro_clipflags);
Freeze(VU1.micro_statusflags);
Freeze(VU1.macflag);
Freeze(VU1.statusflag);
Freeze(VU1.clipflag);
Freeze(VU1.nextBlockCycles);
Freeze(VU1.xgkickaddr);
Freeze(VU1.xgkickdiff);
Freeze(VU1.xgkicksizeremaining);
Freeze(VU1.xgkicklastcycle);
Freeze(VU1.xgkickcyclecount);
Freeze(VU1.xgkickenable);
Freeze(VU1.xgkickendpacket);
Freeze(VU1.VIBackupCycles);
Freeze(VU1.VIOldValue);
Freeze(VU1.VIRegNumber);
Freeze(VU1.fmac);
Freeze(VU1.fmacreadpos);
Freeze(VU1.fmacwritepos);
Freeze(VU1.fmaccount);
Freeze(VU1.fdiv);
Freeze(VU1.efu);
Freeze(VU1.ialu);
Freeze(VU1.ialureadpos);
Freeze(VU1.ialuwritepos);
Freeze(VU1.ialucount);
} }

View File

@ -506,3 +506,12 @@ void recMicroVU1::ResumeXGkick()
return; return;
((mVUrecCallXG)microVU1.startFunctXG)(); ((mVUrecCallXG)microVU1.startFunctXG)();
} }
void SaveStateBase::vuJITFreeze()
{
if (IsSaving())
vu1Thread.WaitVU();
Freeze(microVU0.prog.lpState);
Freeze(microVU1.prog.lpState);
}