diff --git a/CMakeLists.txt b/CMakeLists.txt index caaee3093..5fd1b01c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -765,6 +765,8 @@ add_library(${CoreLibName} ${CoreLinkType} Core/PSPLoaders.h Core/PSPMixer.cpp Core/PSPMixer.h + Core/SaveState.cpp + Core/SaveState.h Core/System.cpp Core/System.h Core/Util/BlockAllocator.cpp diff --git a/Common/ChunkFile.h b/Common/ChunkFile.h index 00d859300..eda388211 100644 --- a/Common/ChunkFile.h +++ b/Common/ChunkFile.h @@ -428,6 +428,30 @@ public: return true; } + template + static bool Verify(T& _class) + { + u8 *ptr = 0; + + // Step 1: Measure the space required. + PointerWrap p(&ptr, PointerWrap::MODE_MEASURE); + _class.DoState(p); + size_t const sz = (size_t)ptr; + std::vector buffer(sz); + + // Step 2: Dump the state. + ptr = &buffer[0]; + p.SetMode(PointerWrap::MODE_WRITE); + _class.DoState(p); + + // Step 3: Verify the state. + ptr = &buffer[0]; + p.SetMode(PointerWrap::MODE_VERIFY); + _class.DoState(p); + + return true; + } + private: struct SChunkHeader { diff --git a/Core/Core.vcxproj b/Core/Core.vcxproj index f10562449..089671dfb 100644 --- a/Core/Core.vcxproj +++ b/Core/Core.vcxproj @@ -253,6 +253,7 @@ + @@ -371,6 +372,7 @@ + diff --git a/Core/Core.vcxproj.filters b/Core/Core.vcxproj.filters index 0784ba189..d6bf753d6 100644 --- a/Core/Core.vcxproj.filters +++ b/Core/Core.vcxproj.filters @@ -348,6 +348,9 @@ HLE\Libraries + + Core + @@ -641,6 +644,9 @@ HLE\Libraries + + Core + diff --git a/Core/HLE/sceKernel.cpp b/Core/HLE/sceKernel.cpp index 9ef1122e4..da528027e 100644 --- a/Core/HLE/sceKernel.cpp +++ b/Core/HLE/sceKernel.cpp @@ -141,7 +141,6 @@ void __KernelDoState(PointerWrap &p) kernelObjects.DoState(p); p.DoMarker("KernelObjects"); // TODO - // kernelObjects // modules // core timing // memstick diff --git a/Core/SaveState.cpp b/Core/SaveState.cpp new file mode 100644 index 000000000..bbf0e2328 --- /dev/null +++ b/Core/SaveState.cpp @@ -0,0 +1,46 @@ +// Copyright (c) 2012- PPSSPP Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0 or later versions. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official git repository and contact information can be found at +// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. + +#include "SaveState.h" +#include "MemMap.h" +#include "HLE/sceKernel.h" + +// TODO: Need a way to schedule via CoreTiming and actually run then. + +bool SaveState::Load(std::string &filename) +{ + SaveState state; + return CChunkFileReader::Load(filename, REVISION, state); +} + +bool SaveState::Save(std::string &filename) +{ + SaveState state; + return CChunkFileReader::Save(filename, REVISION, state); +} + +bool SaveState::Verify() +{ + SaveState state; + return CChunkFileReader::Verify(state); +} + +void SaveState::DoState(PointerWrap &p) +{ + Memory::DoState(p); + __KernelDoState(p); +} \ No newline at end of file diff --git a/Core/SaveState.h b/Core/SaveState.h new file mode 100644 index 000000000..f0edfcf92 --- /dev/null +++ b/Core/SaveState.h @@ -0,0 +1,33 @@ +// Copyright (c) 2012- PPSSPP Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0 or later versions. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official git repository and contact information can be found at +// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. + +#include "../Common/ChunkFile.h" + +struct SaveState +{ + // TODO: Better place for this? + static const int REVISION = 1; + + // Load the specified file into the current state. + static bool Load(std::string &filename); + // Save the current state to the specified file. + static bool Save(std::string &filename); + // For testing / automated tests. Runs a save state verification pass. + static bool Verify(); + + void DoState(PointerWrap &p); +}; \ No newline at end of file diff --git a/Qt/Core.pro b/Qt/Core.pro index 2a14f42b0..6c2cada92 100755 --- a/Qt/Core.pro +++ b/Qt/Core.pro @@ -121,6 +121,7 @@ SOURCES += ../Core/CPU.cpp \ # Core ../Core/MemMapFunctions.cpp \ ../Core/PSPLoaders.cpp \ ../Core/PSPMixer.cpp \ + ../Core/SaveState.cpp \ ../Core/System.cpp \ ../Core/Util/BlockAllocator.cpp \ ../Core/Util/PPGeDraw.cpp \ @@ -227,6 +228,7 @@ HEADERS += ../Core/CPU.h \ ../Core/MemMap.h \ ../Core/PSPLoaders.h \ ../Core/PSPMixer.h \ + ../Core/SaveState.h \ ../Core/System.h \ ../Core/Util/BlockAllocator.h \ ../Core/Util/PPGeDraw.h \ diff --git a/android/jni/Android.mk b/android/jni/Android.mk index 409fffe70..22887307f 100644 --- a/android/jni/Android.mk +++ b/android/jni/Android.mk @@ -95,6 +95,7 @@ LOCAL_SRC_FILES := \ $(SRC)/Core/PSPLoaders.cpp \ $(SRC)/Core/MemMap.cpp \ $(SRC)/Core/MemMapFunctions.cpp \ + $(SRC)/Core/SaveState.cpp \ $(SRC)/Core/System.cpp \ $(SRC)/Core/PSPMixer.cpp \ $(SRC)/Core/Debugger/Breakpoints.cpp \