diff --git a/Common/ChunkFile.h b/Common/ChunkFile.h index 7228365cc..83270c32a 100644 --- a/Common/ChunkFile.h +++ b/Common/ChunkFile.h @@ -31,6 +31,7 @@ #include #include #include +#include #include "Common.h" #include "FileUtil.h" @@ -133,7 +134,26 @@ public: for(i = 0; i < deq_size; i++) DoVoid(&x[i],sizeof(T)); } - + + // Store STL lists. + template + void Do(std::list &x) + { + T dv; + Do(x, dv); + } + + template + void Do(std::list &x, T &default_val) + { + u32 list_size = (u32)x.size(); + x.resize(list_size, default_val); + + typename std::list::iterator itr, end; + for (itr = x.begin(), end = x.end(); itr != end; ++itr) + Do(*itr); + } + // Store strings. void Do(std::string &x) { diff --git a/Core/HLE/sceKernelMemory.cpp b/Core/HLE/sceKernelMemory.cpp index 0b5a3c49b..2b06e0108 100644 --- a/Core/HLE/sceKernelMemory.cpp +++ b/Core/HLE/sceKernelMemory.cpp @@ -59,9 +59,6 @@ struct FPL : KernelObject const char *GetTypeName() {return "FPL";} static u32 GetMissingErrorCode() { return SCE_KERNEL_ERROR_UNKNOWN_FPLID; } int GetIDType() const { return SCE_KERNEL_TMID_Fpl; } - NativeFPL nf; - bool *blocks; - u32 address; int findFreeBlock() { for (int i = 0; i < nf.numBlocks; i++) { @@ -85,6 +82,18 @@ struct FPL : KernelObject } return false; } + + virtual void DoState(PointerWrap &p) + { + p.Do(nf); + p.DoArray(blocks, nf.numBlocks); + p.Do(address); + p.DoMarker("FPL"); + } + + NativeFPL nf; + bool *blocks; + u32 address; }; struct SceKernelVplInfo @@ -103,9 +112,18 @@ struct VPL : KernelObject const char *GetTypeName() {return "VPL";} static u32 GetMissingErrorCode() { return SCE_KERNEL_ERROR_UNKNOWN_VPLID; } int GetIDType() const { return SCE_KERNEL_TMID_Vpl; } + + virtual void DoState(PointerWrap &p) + { + p.Do(nv); + p.Do(size); + p.Do(address); + alloc.DoState(p); + p.DoMarker("VPL"); + } + SceKernelVplInfo nv; u32 size; - bool *freeBlocks; u32 address; BlockAllocator alloc; }; @@ -364,6 +382,14 @@ public: } bool IsValid() {return address != (u32)-1;} BlockAllocator *alloc; + + virtual void DoState(PointerWrap &p) + { + p.Do(address); + p.Do(name); + p.DoMarker("PMB"); + } + u32 address; char name[32]; }; diff --git a/Core/Util/BlockAllocator.cpp b/Core/Util/BlockAllocator.cpp index 27183cbff..66cc8484e 100644 --- a/Core/Util/BlockAllocator.cpp +++ b/Core/Util/BlockAllocator.cpp @@ -297,3 +297,13 @@ u32 BlockAllocator::GetTotalFreeBytes() } return sum; } + +void BlockAllocator::DoState(PointerWrap &p) +{ + Block default_value(0, 0, false); + p.Do(blocks, default_value); + p.Do(rangeStart_); + p.Do(rangeSize_); + p.Do(grain_); + p.DoMarker("BlockAllocator"); +} diff --git a/Core/Util/BlockAllocator.h b/Core/Util/BlockAllocator.h index 7ed26d3fc..dc75a8292 100644 --- a/Core/Util/BlockAllocator.h +++ b/Core/Util/BlockAllocator.h @@ -2,6 +2,7 @@ #pragma once #include "../../Globals.h" +#include "../../Common/ChunkFile.h" #include #include @@ -22,7 +23,7 @@ public: void ListBlocks(); - // WARNING: size can be modified upwards! + // WARNING: size can be modified upwards! u32 Alloc(u32 &size, bool fromTop = false, const char *tag = 0); u32 AllocAt(u32 position, u32 size, const char *tag = 0); @@ -42,6 +43,8 @@ public: u32 GetLargestFreeBlockSize(); u32 GetTotalFreeBytes(); + void DoState(PointerWrap &p); + private: void CheckBlocks();