From fbe4fd396e40c691da26a33feabb27dfad78d866 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Thu, 27 Dec 2012 11:58:15 -0800 Subject: [PATCH] Add a mechanism to restore event callback ptrs. Ugh, more duplicates. Maybe can find a good way to refactor. --- Core/CoreTiming.cpp | 24 ++++++++++++++++++++---- Core/CoreTiming.h | 2 ++ Core/HW/MemoryStick.cpp | 7 +++++++ Core/HW/MemoryStick.h | 2 ++ Core/SaveState.cpp | 6 ++++++ 5 files changed, 37 insertions(+), 4 deletions(-) diff --git a/Core/CoreTiming.cpp b/Core/CoreTiming.cpp index b5d40610dd..b1999015f9 100644 --- a/Core/CoreTiming.cpp +++ b/Core/CoreTiming.cpp @@ -36,6 +36,11 @@ namespace CoreTiming struct EventType { + EventType() {} + + EventType(TimedCallback cb, const char *n) + : callback(cb), name(n) {} + TimedCallback callback; const char *name; }; @@ -125,13 +130,24 @@ void FreeTsEvent(Event* ev) int RegisterEvent(const char *name, TimedCallback callback) { - EventType type; - type.name = name; - type.callback = callback; - event_types.push_back(type); + event_types.push_back(EventType(callback, name)); return (int)event_types.size() - 1; } +void AntiCrashCallback(u64 userdata, int cyclesLate) +{ + ERROR_LOG(CPU, "Savestate broken: an unregistered event was called."); + Core_Halt("invalid timing events"); +} + +void RestoreEvent(int event_type, const char *name, TimedCallback callback) +{ + if (event_type >= event_types.size()) + event_types.resize(event_type + 1, EventType(AntiCrashCallback, "INVALID EVENT")); + + event_types[event_type] = EventType(callback, name); +} + void UnregisterAllEvents() { if (first) diff --git a/Core/CoreTiming.h b/Core/CoreTiming.h index f8883d9b35..c3ec4bc1b3 100644 --- a/Core/CoreTiming.h +++ b/Core/CoreTiming.h @@ -78,6 +78,8 @@ namespace CoreTiming // Returns the event_type identifier. int RegisterEvent(const char *name, TimedCallback callback); + // For save states. + void RestoreEvent(int event_type, const char *name, TimedCallback callback); void UnregisterAllEvents(); // userdata MAY NOT CONTAIN POINTERS. userdata might get written and reloaded from disk, diff --git a/Core/HW/MemoryStick.cpp b/Core/HW/MemoryStick.cpp index 4d83e4783c..b2a746b0af 100644 --- a/Core/HW/MemoryStick.cpp +++ b/Core/HW/MemoryStick.cpp @@ -4,6 +4,13 @@ static MemStickState memStickState = PSP_MEMORYSTICK_STATE_DRIVER_READY; static MemStickFatState memStickFatState = PSP_FAT_MEMORYSTICK_STATE_ASSIGNED; +void MemoryStick_DoState(PointerWrap &p) +{ + p.Do(memStickState); + p.Do(memStickFatState); + p.DoMarker("MemoryStick"); +} + MemStickState MemoryStick_State() { return memStickState; diff --git a/Core/HW/MemoryStick.h b/Core/HW/MemoryStick.h index 1ccd9b64fa..fbd42b827b 100644 --- a/Core/HW/MemoryStick.h +++ b/Core/HW/MemoryStick.h @@ -1,4 +1,5 @@ #include "../../Globals.h" +#include "../../Common/ChunkFile.h" // mscmhc0 states enum MemStickState { @@ -14,6 +15,7 @@ enum MemStickFatState { PSP_FAT_MEMORYSTICK_STATE_ASSIGNED = 1, }; +void MemoryStick_DoState(PointerWrap &p); MemStickState MemoryStick_State(); MemStickFatState MemoryStick_FatState(); diff --git a/Core/SaveState.cpp b/Core/SaveState.cpp index 5e2ac11242..ce70a40df0 100644 --- a/Core/SaveState.cpp +++ b/Core/SaveState.cpp @@ -22,6 +22,7 @@ #include "Core.h" #include "CoreTiming.h" #include "HLE/sceKernel.h" +#include "HW/MemoryStick.h" #include "MemMap.h" namespace SaveState @@ -57,11 +58,16 @@ namespace SaveState // This is where the magic happens. void SaveStart::DoState(PointerWrap &p) { + // Gotta do CoreTiming first since we'll restore into it. + // TODO CoreTiming + // This save state even saves its own state. p.Do(timer); + CoreTiming::RestoreEvent(timer, "SaveState", Process); p.DoMarker("SaveState"); Memory::DoState(p); + MemoryStick_DoState(p); __KernelDoState(p); }