From 44026aa899ee52aaae51d760324cf1fffa784c0e Mon Sep 17 00:00:00 2001 From: Gauvain 'GovanifY' Roussel-Tarbouriech Date: Tue, 15 Jun 2021 17:54:24 +0200 Subject: [PATCH] sstate: major redesign, remove split freeze{out,in}, remove gsfreezedata --- pcsx2/GS/GS.cpp | 47 +-------- pcsx2/GS/GS.h | 12 +-- pcsx2/GS/GSDump.cpp | 6 +- pcsx2/GS/GSDump.h | 6 +- pcsx2/GS/GSState.cpp | 12 +-- pcsx2/GS/GSState.h | 4 +- pcsx2/GS/Renderers/Common/GSRenderer.cpp | 4 +- pcsx2/MTGS.cpp | 2 +- pcsx2/PAD/Linux/PAD.cpp | 41 -------- pcsx2/PAD/Linux/PAD.h | 2 - pcsx2/PAD/Windows/PAD.cpp | 41 -------- pcsx2/PAD/Windows/PAD.h | 2 - pcsx2/SPU2/spu2.cpp | 45 -------- pcsx2/SPU2/spu2.h | 2 - pcsx2/USB/USB.cpp | 43 -------- pcsx2/USB/USB.h | 4 - pcsx2/USB/USBNull.cpp | 4 - pcsx2/gui/Dialogs/GSDumpDialog.cpp | 2 +- pcsx2/gui/GlobalCommands.cpp | 4 +- pcsx2/gui/SysState.cpp | 125 +++++++++++++---------- 20 files changed, 97 insertions(+), 311 deletions(-) diff --git a/pcsx2/GS/GS.cpp b/pcsx2/GS/GS.cpp index f8d97e6cc2..c345e21727 100644 --- a/pcsx2/GS/GS.cpp +++ b/pcsx2/GS/GS.cpp @@ -678,7 +678,7 @@ void GSkeyEvent(GSKeyEventData* e) } } -int GSfreeze(int mode, GSFreezeData* data) +int GSfreeze(int mode, freezeData* data) { try { @@ -949,9 +949,9 @@ void GSReplay(char* lpszCmdLine, int renderer) file->Read(&crc, 4); GSsetGameCRC(crc, 0); - GSFreezeData fd; + freezeData fd; file->Read(&fd.size, 4); - fd.data = new uint8[fd.size]; + fd.data = new char[fd.size]; file->Read(fd.data, fd.size); GSfreeze(FREEZE_LOAD, &fd); @@ -1861,44 +1861,3 @@ GSRendererType GSApp::GetCurrentRendererType() const { return m_current_renderer_type; } - -void GSDoFreezeOut(void* dest) -{ - GSFreezeData fP = {0, (u8*)dest}; - if (GSfreeze(FREEZE_SIZE, &fP) != 0) - return; - if (!fP.size) - return; - - Console.Indent().WriteLn("Saving GS"); - - if (GSfreeze(FREEZE_SAVE, &fP) != 0) - throw std::runtime_error(" * GS: Error saving state!\n"); -} - - -void GSDoFreezeIn(pxInputStream& infp) -{ - GSFreezeData fP = {0, nullptr}; - if (GSfreeze(FREEZE_SIZE, &fP) != 0) - fP.size = 0; - - Console.Indent().WriteLn("Loading GS"); - - if (!infp.IsOk() || !infp.Length()) - { - // no state data to read, but GS expects some state data? - // Issue a warning to console... - if (fP.size != 0) - Console.Indent().Warning("Warning: No data for GS found. Status may be unpredictable."); - - return; - } - - ScopedAlloc data(fP.size); - fP.data = (u8*)data.GetPtr(); - - infp.Read(fP.data, fP.size); - if (GSfreeze(FREEZE_LOAD, &fP) != 0) - throw std::runtime_error(" * GS: Error loading state!\n"); -} diff --git a/pcsx2/GS/GS.h b/pcsx2/GS/GS.h index ef5a3b5006..ca07b7a684 100644 --- a/pcsx2/GS/GS.h +++ b/pcsx2/GS/GS.h @@ -1783,12 +1783,6 @@ struct GSKeyEventData uint32 key, type; }; -struct GSFreezeData -{ - int size; - uint8* data; -}; - // ST_WRITE is defined in libc, avoid this enum stateType { @@ -1872,7 +1866,7 @@ void GSgifTransfer3(uint8* mem, uint32 size); void GSvsync(int field); uint32 GSmakeSnapshot(char* path); void GSkeyEvent(GSKeyEventData* e); -int GSfreeze(int mode, GSFreezeData* data); +int GSfreeze(int mode, freezeData* data); void GSconfigure(); int GStest(); void GSirqCallback(void (*irq)()); @@ -1967,7 +1961,3 @@ struct GSErrorGlVertexArrayTooSmall : GSError extern GSApp theApp; extern bool gsopen_done; - - -void GSDoFreezeOut(void* dest); -void GSDoFreezeIn(pxInputStream& infp); \ No newline at end of file diff --git a/pcsx2/GS/GSDump.cpp b/pcsx2/GS/GSDump.cpp index 732c94966b..a259478eab 100644 --- a/pcsx2/GS/GSDump.cpp +++ b/pcsx2/GS/GSDump.cpp @@ -31,7 +31,7 @@ GSDumpBase::~GSDumpBase() fclose(m_gs); } -void GSDumpBase::AddHeader(uint32 crc, const GSFreezeData& fd, const GSPrivRegSet* regs) +void GSDumpBase::AddHeader(uint32 crc, const freezeData& fd, const GSPrivRegSet* regs) { AppendRawData(&crc, 4); AppendRawData(&fd.size, 4); @@ -91,7 +91,7 @@ void GSDumpBase::Write(const void* data, size_t size) // GSDump implementation ////////////////////////////////////////////////////////////////////// -GSDump::GSDump(const std::string& fn, uint32 crc, const GSFreezeData& fd, const GSPrivRegSet* regs) +GSDump::GSDump(const std::string& fn, uint32 crc, const freezeData& fd, const GSPrivRegSet* regs) : GSDumpBase(fn + ".gs") { AddHeader(crc, fd, regs); @@ -111,7 +111,7 @@ void GSDump::AppendRawData(uint8 c) // GSDumpXz implementation ////////////////////////////////////////////////////////////////////// -GSDumpXz::GSDumpXz(const std::string& fn, uint32 crc, const GSFreezeData& fd, const GSPrivRegSet* regs) +GSDumpXz::GSDumpXz(const std::string& fn, uint32 crc, const freezeData& fd, const GSPrivRegSet* regs) : GSDumpBase(fn + ".gs.xz") { m_strm = LZMA_STREAM_INIT; diff --git a/pcsx2/GS/GSDump.h b/pcsx2/GS/GSDump.h index f13e92cd7a..02532aadb0 100644 --- a/pcsx2/GS/GSDump.h +++ b/pcsx2/GS/GSDump.h @@ -45,7 +45,7 @@ class GSDumpBase FILE* m_gs; protected: - void AddHeader(uint32 crc, const GSFreezeData& fd, const GSPrivRegSet* regs); + void AddHeader(uint32 crc, const freezeData& fd, const GSPrivRegSet* regs); void Write(const void* data, size_t size); virtual void AppendRawData(const void* data, size_t size) = 0; @@ -66,7 +66,7 @@ class GSDump final : public GSDumpBase void AppendRawData(uint8 c) final; public: - GSDump(const std::string& fn, uint32 crc, const GSFreezeData& fd, const GSPrivRegSet* regs); + GSDump(const std::string& fn, uint32 crc, const freezeData& fd, const GSPrivRegSet* regs); virtual ~GSDump() = default; }; @@ -82,6 +82,6 @@ class GSDumpXz final : public GSDumpBase void AppendRawData(uint8 c); public: - GSDumpXz(const std::string& fn, uint32 crc, const GSFreezeData& fd, const GSPrivRegSet* regs); + GSDumpXz(const std::string& fn, uint32 crc, const freezeData& fd, const GSPrivRegSet* regs); virtual ~GSDumpXz(); }; diff --git a/pcsx2/GS/GSState.cpp b/pcsx2/GS/GSState.cpp index 85c4310b09..2b15b8c98c 100644 --- a/pcsx2/GS/GSState.cpp +++ b/pcsx2/GS/GSState.cpp @@ -2397,20 +2397,20 @@ void GSState::Transfer(const uint8* mem, uint32 size) } template -static void WriteState(uint8*& dst, T* src, size_t len = sizeof(T)) +static void WriteState(char*& dst, T* src, size_t len = sizeof(T)) { memcpy(dst, src, len); dst += len; } template -static void ReadState(T* dst, uint8*& src, size_t len = sizeof(T)) +static void ReadState(T* dst, char*& src, size_t len = sizeof(T)) { memcpy(dst, src, len); src += len; } -int GSState::Freeze(GSFreezeData* fd, bool sizeonly) +int GSState::Freeze(freezeData* fd, bool sizeonly) { if (sizeonly) { @@ -2425,7 +2425,7 @@ int GSState::Freeze(GSFreezeData* fd, bool sizeonly) Flush(); - uint8* data = fd->data; + char* data = fd->data; WriteState(data, &m_version); WriteState(data, &m_env.PRIM); @@ -2492,7 +2492,7 @@ int GSState::Freeze(GSFreezeData* fd, bool sizeonly) return 0; } -int GSState::Defrost(const GSFreezeData* fd) +int GSState::Defrost(const freezeData* fd) { if (!fd || !fd->data || fd->size == 0) { @@ -2504,7 +2504,7 @@ int GSState::Defrost(const GSFreezeData* fd) return -1; } - uint8* data = fd->data; + char* data = fd->data; int version; diff --git a/pcsx2/GS/GSState.h b/pcsx2/GS/GSState.h index 03bd843ba7..511543a962 100644 --- a/pcsx2/GS/GSState.h +++ b/pcsx2/GS/GSState.h @@ -266,8 +266,8 @@ public: void WriteCSR(uint32 csr) { m_regs->CSR.u32[1] = csr; } void ReadFIFO(uint8* mem, int size); template void Transfer(const uint8* mem, uint32 size); - int Freeze(GSFreezeData* fd, bool sizeonly); - int Defrost(const GSFreezeData* fd); + int Freeze(freezeData* fd, bool sizeonly); + int Defrost(const freezeData* fd); void GetLastTag(uint32* tag) { *tag = m_path3hack; diff --git a/pcsx2/GS/Renderers/Common/GSRenderer.cpp b/pcsx2/GS/Renderers/Common/GSRenderer.cpp index e52e3b7c91..31a8f76524 100644 --- a/pcsx2/GS/Renderers/Common/GSRenderer.cpp +++ b/pcsx2/GS/Renderers/Common/GSRenderer.cpp @@ -446,9 +446,9 @@ void GSRenderer::VSync(int field) { if (!m_dump && m_shift_key) { - GSFreezeData fd = {0, nullptr}; + freezeData fd = {0, nullptr}; Freeze(&fd, true); - fd.data = new uint8[fd.size]; + fd.data = new char[fd.size]; Freeze(&fd, false); if (m_control_key) diff --git a/pcsx2/MTGS.cpp b/pcsx2/MTGS.cpp index 6f2d70797b..3363c6028a 100644 --- a/pcsx2/MTGS.cpp +++ b/pcsx2/MTGS.cpp @@ -497,7 +497,7 @@ void SysMtgsThread::ExecuteTaskInThread() { MTGS_FreezeData* data = (MTGS_FreezeData*)tag.pointer; int mode = tag.data[0]; - data->retval = GSfreeze(mode, (GSFreezeData*)data->fdata); + data->retval = GSfreeze(mode, (freezeData*)data->fdata); } break; diff --git a/pcsx2/PAD/Linux/PAD.cpp b/pcsx2/PAD/Linux/PAD.cpp index 430a279526..f45c6d0f6b 100644 --- a/pcsx2/PAD/Linux/PAD.cpp +++ b/pcsx2/PAD/Linux/PAD.cpp @@ -290,44 +290,3 @@ void PADWriteEvent(keyEvent& evt) g_ev_fifo.push(evt); } #endif - -void PADDoFreezeOut(void* dest) -{ - freezeData fP = {0, (s8*)dest}; - if (PADfreeze(FREEZE_SIZE, &fP) != 0) - return; - if (!fP.size) - return; - - Console.Indent().WriteLn("Saving PAD"); - - if (PADfreeze(FREEZE_SAVE, &fP) != 0) - throw std::runtime_error(" * PAD: Error saving state!\n"); -} - - -void PADDoFreezeIn(pxInputStream& infp) -{ - freezeData fP = {0, nullptr}; - if (PADfreeze(FREEZE_SIZE, &fP) != 0) - fP.size = 0; - - Console.Indent().WriteLn("Loading PAD"); - - if (!infp.IsOk() || !infp.Length()) - { - // no state data to read, but PAD expects some state data? - // Issue a warning to console... - if (fP.size != 0) - Console.Indent().Warning("Warning: No data for PAD found. Status may be unpredictable."); - - return; - } - - ScopedAlloc data(fP.size); - fP.data = data.GetPtr(); - - infp.Read(fP.data, fP.size); - if (PADfreeze(FREEZE_LOAD, &fP) != 0) - throw std::runtime_error(" * PAD: Error loading state!\n"); -} diff --git a/pcsx2/PAD/Linux/PAD.h b/pcsx2/PAD/Linux/PAD.h index 47e0158bf8..bb0f9af09f 100644 --- a/pcsx2/PAD/Linux/PAD.h +++ b/pcsx2/PAD/Linux/PAD.h @@ -144,8 +144,6 @@ u8 PADpoll(u8 value); keyEvent* PADkeyEvent(); void PADupdate(int pad); void PADconfigure(); -void PADDoFreezeOut(void* dest); -void PADDoFreezeIn(pxInputStream& infp); #if defined(__unix__) void PADWriteEvent(keyEvent& evt); diff --git a/pcsx2/PAD/Windows/PAD.cpp b/pcsx2/PAD/Windows/PAD.cpp index 1136782a68..b7d2b417d8 100644 --- a/pcsx2/PAD/Windows/PAD.cpp +++ b/pcsx2/PAD/Windows/PAD.cpp @@ -1663,44 +1663,3 @@ s32 PADsetSlot(u8 port, u8 slot) // return pads[port][slot].enabled | !slot; return 1; } - -void PADDoFreezeOut(void* dest) -{ - freezeData fP = {0, (s8*)dest}; - if (PADfreeze(FREEZE_SIZE, &fP) != 0) - return; - if (!fP.size) - return; - - Console.Indent().WriteLn("Saving PAD"); - - if (PADfreeze(FREEZE_SAVE, &fP) != 0) - throw std::runtime_error(" * PAD: Error saving state!\n"); -} - - -void PADDoFreezeIn(pxInputStream& infp) -{ - freezeData fP = {0, nullptr}; - if (PADfreeze(FREEZE_SIZE, &fP) != 0) - fP.size = 0; - - Console.Indent().WriteLn("Loading PAD"); - - if (!infp.IsOk() || !infp.Length()) - { - // no state data to read, but PAD expects some state data? - // Issue a warning to console... - if (fP.size != 0) - Console.Indent().Warning("Warning: No data for PAD found. Status may be unpredictable."); - - return; - } - - ScopedAlloc data(fP.size); - fP.data = data.GetPtr(); - - infp.Read(fP.data, fP.size); - if (PADfreeze(FREEZE_LOAD, &fP) != 0) - throw std::runtime_error(" * PAD: Error loading state!\n"); -} diff --git a/pcsx2/PAD/Windows/PAD.h b/pcsx2/PAD/Windows/PAD.h index 53dae2797b..0782f62b86 100644 --- a/pcsx2/PAD/Windows/PAD.h +++ b/pcsx2/PAD/Windows/PAD.h @@ -56,5 +56,3 @@ void PADconfigure(); s32 PADfreeze(int mode, freezeData* data); s32 PADsetSlot(u8 port, u8 slot); void PADsetSettingsDir(const char* dir); -void PADDoFreezeOut(void* dest); -void PADDoFreezeIn(pxInputStream& infp); diff --git a/pcsx2/SPU2/spu2.cpp b/pcsx2/SPU2/spu2.cpp index a265fafb6a..5dfb9e0539 100644 --- a/pcsx2/SPU2/spu2.cpp +++ b/pcsx2/SPU2/spu2.cpp @@ -576,48 +576,3 @@ s32 SPU2freeze(int mode, freezeData* data) // technically unreachable, but kills a warning: return 0; } - -void SPU2DoFreezeOut(void* dest) -{ - ScopedLock lock(mtx_SPU2Status); - - freezeData fP = {0, (s8*)dest}; - if (SPU2freeze(FREEZE_SIZE, &fP) != 0) - return; - if (!fP.size) - return; - - Console.Indent().WriteLn("Saving SPU2"); - - if (SPU2freeze(FREEZE_SAVE, &fP) != 0) - throw std::runtime_error(" * SPU2: Error saving state!\n"); -} - - -void SPU2DoFreezeIn(pxInputStream& infp) -{ - ScopedLock lock(mtx_SPU2Status); - - freezeData fP = {0, nullptr}; - if (SPU2freeze(FREEZE_SIZE, &fP) != 0) - fP.size = 0; - - Console.Indent().WriteLn("Loading SPU2"); - - if (!infp.IsOk() || !infp.Length()) - { - // no state data to read, but SPU2 expects some state data? - // Issue a warning to console... - if (fP.size != 0) - Console.Indent().Warning("Warning: No data for SPU2 found. Status may be unpredictable."); - - return; - } - - ScopedAlloc data(fP.size); - fP.data = data.GetPtr(); - - infp.Read(fP.data, fP.size); - if (SPU2freeze(FREEZE_LOAD, &fP) != 0) - throw std::runtime_error(" * SPU2: Error loading state!\n"); -} diff --git a/pcsx2/SPU2/spu2.h b/pcsx2/SPU2/spu2.h index 0fc42126a0..710e27aa70 100644 --- a/pcsx2/SPU2/spu2.h +++ b/pcsx2/SPU2/spu2.h @@ -37,8 +37,6 @@ void SPU2endRecording(); void SPU2async(u32 cycles); s32 SPU2freeze(int mode, freezeData* data); -void SPU2DoFreezeIn(pxInputStream& infp); -void SPU2DoFreezeOut(void* dest); void SPU2configure(); diff --git a/pcsx2/USB/USB.cpp b/pcsx2/USB/USB.cpp index 503e99a528..598b4ba7bd 100644 --- a/pcsx2/USB/USB.cpp +++ b/pcsx2/USB/USB.cpp @@ -494,7 +494,6 @@ s32 USBfreeze(int mode, freezeData* data) } } } - } //TODO straight copying of structs can break cross-platform/cross-compiler save states 'cause padding 'n' stuff else if (mode == FREEZE_SAVE) @@ -629,45 +628,3 @@ s64 get_clock() { return clocks; } - -void USBDoFreezeOut(void* dest) -{ - freezeData fP = {0, (s8*)dest}; - if (USBfreeze(FREEZE_SIZE, &fP) != 0) - return; - if (!fP.size) - return; - - Console.Indent().WriteLn("Saving USB"); - - if (USBfreeze(FREEZE_SAVE, &fP) != 0) - throw std::runtime_error(" * USB: Error saving state!\n"); -} - - -void USBDoFreezeIn(pxInputStream& infp) -{ - freezeData fP = {(int)infp.Length(), nullptr}; - //if (USBfreeze(FREEZE_SIZE, &fP) != 0) - // fP.size = 0; - - Console.Indent().WriteLn("Loading USB"); - - if (!infp.IsOk() || !infp.Length()) - { - // no state data to read, but USB expects some state data? - // Issue a warning to console... - if (fP.size != 0) - Console.Indent().Warning("Warning: No data for USB found. Status may be unpredictable."); - - return; - } - - ScopedAlloc data(fP.size); - fP.data = data.GetPtr(); - - infp.Read(fP.data, fP.size); - //if (USBfreeze(FREEZE_LOAD, &fP) != 0) - // throw std::runtime_error(" * USB: Error loading state!\n"); - USBfreeze(FREEZE_LOAD, &fP); -} diff --git a/pcsx2/USB/USB.h b/pcsx2/USB/USB.h index e43f070def..bebd7b3c46 100644 --- a/pcsx2/USB/USB.h +++ b/pcsx2/USB/USB.h @@ -48,10 +48,6 @@ void USBwrite8(u32 addr, u8 value); void USBwrite16(u32 addr, u16 value); void USBwrite32(u32 addr, u32 value); -void USBDoFreezeOut(void* dest); -void USBDoFreezeIn(pxInputStream& infp); - - void USBsetRAM(void* mem); extern FILE* usbLog; diff --git a/pcsx2/USB/USBNull.cpp b/pcsx2/USB/USBNull.cpp index eb50208830..9d9a0e7a50 100644 --- a/pcsx2/USB/USBNull.cpp +++ b/pcsx2/USB/USBNull.cpp @@ -36,10 +36,6 @@ void USBwrite8(u32 addr, u8 value) {} void USBwrite16(u32 addr, u16 value) {} void USBwrite32(u32 addr, u32 value) {} -void USBDoFreezeOut(void* dest) {} -void USBDoFreezeIn(pxInputStream& infp) {} - - void USBsetRAM(void* mem) { ram = static_cast(mem); } FILE* usbLog = nullptr; diff --git a/pcsx2/gui/Dialogs/GSDumpDialog.cpp b/pcsx2/gui/Dialogs/GSDumpDialog.cpp index 5c7be15c29..535072e351 100644 --- a/pcsx2/gui/Dialogs/GSDumpDialog.cpp +++ b/pcsx2/gui/Dialogs/GSDumpDialog.cpp @@ -729,7 +729,7 @@ void Dialogs::GSDumpDialog::GSThread::ExecuteTaskInThread() m_dump_file->Read(state_data.get(), ss); m_dump_file->Read(®s, 8192); - GSFreezeData fd = {(int)ss, (u8*)state_data.get()}; + freezeData fd = {(int)ss, (s8*)state_data.get()}; m_root_window->m_dump_packets.clear(); while (m_dump_file->Tell() < m_dump_file->Length()) diff --git a/pcsx2/gui/GlobalCommands.cpp b/pcsx2/gui/GlobalCommands.cpp index c74955ffa2..c71ee5f846 100644 --- a/pcsx2/gui/GlobalCommands.cpp +++ b/pcsx2/gui/GlobalCommands.cpp @@ -402,9 +402,9 @@ namespace Implementations { ScopedCoreThreadPause paused_core; std::unique_ptr plugstore; - GSFreezeData fP = {0, NULL}; + freezeData fP = {0, NULL}; GSfreeze(FREEZE_SIZE, &fP); - u8* data = new u8[fP.size]; + char* data = new char[fP.size]; fP.data = data; if (CoreThread.HasActiveMachine()) { diff --git a/pcsx2/gui/SysState.cpp b/pcsx2/gui/SysState.cpp index 9630a2db7d..ec5deb5f94 100644 --- a/pcsx2/gui/SysState.cpp +++ b/pcsx2/gui/SysState.cpp @@ -45,6 +45,70 @@ static const wxChar* EntryFilename_StateVersion = L"PCSX2 Savestate Version.id"; static const wxChar* EntryFilename_Screenshot = L"Screenshot.jpg"; static const wxChar* EntryFilename_InternalStructures = L"PCSX2 Internal Structures.dat"; +enum SysState_Component : unsigned char +{ + SPU2 = 0, + PAD = 1, + USB = 2, + GS = 3, +}; + +typedef int (*SysState_FreezeFunction)(int, freezeData*); +static const SysState_FreezeFunction SysState_ComponentFreeze[] = {SPU2freeze, PADfreeze, USBfreeze, GSfreeze}; +static const char* SysState_ComponentName[] = {"SPU2", "PAD", "USB", "GS"}; + +void SysState_ComponentFreezeOutRoot(void* dest, SysState_Component comp) +{ + freezeData fP = {0, (char*)dest}; + if (SysState_ComponentFreeze[comp](FREEZE_SIZE, &fP) != 0) + return; + if (!fP.size) + return; + + Console.Indent().WriteLn("Saving %s", SysState_ComponentName[comp]); + + if (SysState_ComponentFreeze[comp](FREEZE_SAVE, &fP) != 0) + throw std::runtime_error(std::string(" * ") + SysState_ComponentName[comp] + std::string(": Error saving state!\n")); +} + +void SysState_ComponentFreezeIn(pxInputStream& infp, SysState_Component comp) +{ + freezeData fP = {0, nullptr}; + if (SysState_ComponentFreeze[comp](FREEZE_SIZE, &fP) != 0) + fP.size = 0; + + Console.Indent().WriteLn("Loading %s", SysState_ComponentName[comp]); + + if (!infp.IsOk() || !infp.Length()) + { + // no state data to read, but component expects some state data? + // Issue a warning to console... + if (fP.size != 0) + Console.Indent().Warning("Warning: No data for %s found. Status may be unpredictable.", SysState_ComponentName[comp]); + + return; + } + + ScopedAlloc data(fP.size); + fP.data = data.GetPtr(); + + infp.Read(fP.data, fP.size); + if (SysState_ComponentFreeze[comp](FREEZE_LOAD, &fP) != 0) + throw std::runtime_error(std::string(" * ") + SysState_ComponentName[comp] + std::string(": Error loading state!\n")); +} + +void SysState_ComponentFreezeOut(SaveStateBase& writer, SysState_Component comp) +{ + freezeData fP = {0, NULL}; + if (SysState_ComponentFreeze[comp](FREEZE_SIZE, &fP) == 0) + { + const int size = fP.size; + writer.PrepBlock(size); + SysState_ComponentFreezeOutRoot(writer.GetBlockPtr(), comp); + writer.CommitBlock(size); + } + return; +} // -------------------------------------------------------------------------------------- // BaseSavestateEntry @@ -210,19 +274,8 @@ public: virtual ~SavestateEntry_SPU2() = default; wxString GetFilename() const { return L"SPU2.bin"; } - void FreezeIn(pxInputStream& reader) const { return SPU2DoFreezeIn(reader); } - void FreezeOut(SaveStateBase& writer) const - { - freezeData fP = {0, NULL}; - if (SPU2freeze(FREEZE_SIZE, &fP) == 0) - { - const int size = fP.size; - writer.PrepBlock(size); - SPU2DoFreezeOut(writer.GetBlockPtr()); - writer.CommitBlock(size); - } - return; - } + void FreezeIn(pxInputStream& reader) const { return SysState_ComponentFreezeIn(reader, SPU2); } + void FreezeOut(SaveStateBase& writer) const { return SysState_ComponentFreezeOut(writer, SPU2); } bool IsRequired() const { return true; } }; @@ -232,19 +285,8 @@ public: virtual ~SavestateEntry_USB() = default; wxString GetFilename() const { return L"USB.bin"; } - void FreezeIn(pxInputStream& reader) const { return USBDoFreezeIn(reader); } - void FreezeOut(SaveStateBase& writer) const - { - freezeData fP = {0, NULL}; - if (USBfreeze(FREEZE_SIZE, &fP) == 0) - { - const int size = fP.size; - writer.PrepBlock(size); - USBDoFreezeOut(writer.GetBlockPtr()); - writer.CommitBlock(size); - } - return; - } + void FreezeIn(pxInputStream& reader) const { return SysState_ComponentFreezeIn(reader, USB); } + void FreezeOut(SaveStateBase& writer) const { return SysState_ComponentFreezeOut(writer, USB); } bool IsRequired() const { return true; } }; @@ -254,19 +296,8 @@ public: virtual ~SavestateEntry_PAD() = default; wxString GetFilename() const { return L"PAD.bin"; } - void FreezeIn(pxInputStream& reader) const { return PADDoFreezeIn(reader); } - void FreezeOut(SaveStateBase& writer) const - { - freezeData fP = {0, NULL}; - if (PADfreeze(FREEZE_SIZE, &fP) == 0) - { - const int size = fP.size; - writer.PrepBlock(size); - PADDoFreezeOut(writer.GetBlockPtr()); - writer.CommitBlock(size); - } - return; - } + void FreezeIn(pxInputStream& reader) const { return SysState_ComponentFreezeIn(reader, PAD); } + void FreezeOut(SaveStateBase& writer) const { return SysState_ComponentFreezeOut(writer, PAD); } bool IsRequired() const { return true; } }; @@ -276,19 +307,8 @@ public: virtual ~SavestateEntry_GS() = default; wxString GetFilename() const { return L"GS.bin"; } - void FreezeIn(pxInputStream& reader) const { return GSDoFreezeIn(reader); } - void FreezeOut(SaveStateBase& writer) const - { - GSFreezeData fP = {0, NULL}; - if (GSfreeze(FREEZE_SIZE, &fP) == 0) - { - const int size = fP.size; - writer.PrepBlock(size); - GSDoFreezeOut(writer.GetBlockPtr()); - writer.CommitBlock(size); - } - return; - } + void FreezeIn(pxInputStream& reader) const { return SysState_ComponentFreezeIn(reader, GS); } + void FreezeOut(SaveStateBase& writer) const { return SysState_ComponentFreezeOut(writer, GS); } bool IsRequired() const { return true; } }; @@ -744,3 +764,4 @@ void StateCopy_LoadFromSlot(uint slot, bool isFromBackup) UI_UpdateSysControls(); #endif } +