diff --git a/Core/CoreTiming.cpp b/Core/CoreTiming.cpp index b1999015f..31b9bbb0a 100644 --- a/Core/CoreTiming.cpp +++ b/Core/CoreTiming.cpp @@ -24,6 +24,7 @@ #include "CoreTiming.h" #include "Core.h" #include "HLE/sceKernelThread.h" +#include "../Common/ChunkFile.h" int CPU_HZ = 222000000; @@ -55,12 +56,6 @@ struct BaseEvent // Event *next; }; -template -struct LinkedListItem : public T -{ - LinkedListItem *next; -}; - typedef LinkedListItem Event; Event *first; @@ -79,6 +74,7 @@ s64 idledCycles; static std::recursive_mutex externalEventSection; +// Warning: not included in save state. void (*advanceCallback)(int cyclesExecuted) = NULL; void SetClockFrequencyMHz(int cpuMhz) @@ -140,9 +136,9 @@ void AntiCrashCallback(u64 userdata, int cyclesLate) Core_Halt("invalid timing events"); } -void RestoreEvent(int event_type, const char *name, TimedCallback callback) +void RestoreRegisterEvent(int event_type, const char *name, TimedCallback callback) { - if (event_type >= event_types.size()) + if (event_type >= (int) event_types.size()) event_types.resize(event_type + 1, EventType(AntiCrashCallback, "INVALID EVENT")); event_types[event_type] = EventType(callback, name); @@ -311,6 +307,7 @@ u64 UnscheduleEvent(int event_type, u64 userdata) return result; } +// Warning: not included in save state. void RegisterAdvanceCallback(void (*callback)(int cyclesExecuted)) { advanceCallback = callback; @@ -546,4 +543,27 @@ std::string GetScheduledEventsSummary() return text; } +void Event_DoState(PointerWrap &p, BaseEvent *ev) +{ + p.Do(*ev); +} + +void DoState(PointerWrap &p) +{ + size_t n = event_types.size(); + p.Do(n); + // These (should) be filled in later by the modules. + event_types.resize(n, EventType(AntiCrashCallback, "INVALID EVENT")); + + p.DoLinkedList(first, (Event **) NULL); + p.DoLinkedList(tsFirst, &tsLast); + + p.Do(CPU_HZ); + p.Do(downcount); + p.Do(slicelength); + p.Do(globalTimer); + p.Do(idledCycles); + p.DoMarker("CoreTiming"); +} + } // namespace diff --git a/Core/CoreTiming.h b/Core/CoreTiming.h index c3ec4bc1b..e5aa8f877 100644 --- a/Core/CoreTiming.h +++ b/Core/CoreTiming.h @@ -32,6 +32,7 @@ // ScheduleEvent(periodInCycles - cyclesLate, callback, "whatever") #include "../Globals.h" +#include "../Common/ChunkFile.h" #include @@ -79,7 +80,7 @@ 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 RestoreRegisterEvent(int event_type, const char *name, TimedCallback callback); void UnregisterAllEvents(); // userdata MAY NOT CONTAIN POINTERS. userdata might get written and reloaded from disk, @@ -105,10 +106,13 @@ namespace CoreTiming void LogPendingEvents(); + // Warning: not included in save states. void RegisterAdvanceCallback(void (*callback)(int cyclesExecuted)); std::string GetScheduledEventsSummary(); + void DoState(PointerWrap &p); + void SetClockFrequencyMHz(int cpuMhz); int GetClockFrequencyMHz(); extern int downcount; diff --git a/Core/SaveState.cpp b/Core/SaveState.cpp index ce70a40df..bbf8717b9 100644 --- a/Core/SaveState.cpp +++ b/Core/SaveState.cpp @@ -55,15 +55,17 @@ namespace SaveState static std::vector pending; static std::recursive_mutex mutex; + void Process(u64 userdata, int cyclesLate); + // This is where the magic happens. void SaveStart::DoState(PointerWrap &p) { // Gotta do CoreTiming first since we'll restore into it. - // TODO CoreTiming + CoreTiming::DoState(p); // This save state even saves its own state. p.Do(timer); - CoreTiming::RestoreEvent(timer, "SaveState", Process); + CoreTiming::RestoreRegisterEvent(timer, "SaveState", Process); p.DoMarker("SaveState"); Memory::DoState(p); @@ -71,8 +73,6 @@ namespace SaveState __KernelDoState(p); } - void Process(u64 userdata, int cyclesLate); - void Enqueue(SaveState::Operation op) { std::lock_guard guard(mutex);