diff --git a/Core/Sdd1.cpp b/Core/Sdd1.cpp index ed2292e..3e6d34c 100644 --- a/Core/Sdd1.cpp +++ b/Core/Sdd1.cpp @@ -101,6 +101,7 @@ void Sdd1::Serialize(Serializer &s) s.StreamArray(_state.DmaAddress, 8); s.StreamArray(_state.DmaLength, 8); s.StreamArray(_state.SelectedBanks, 4); + s.Stream(_sdd1Mmc.get()); } uint8_t Sdd1::Peek(uint32_t addr) diff --git a/Core/Sdd1Decomp.cpp b/Core/Sdd1Decomp.cpp index 8b6b1ee..d171cbb 100644 --- a/Core/Sdd1Decomp.cpp +++ b/Core/Sdd1Decomp.cpp @@ -64,6 +64,11 @@ uint8_t SDD1_IM::getCodeword(uint8_t code_len) return codeword; } +void SDD1_IM::Serialize(Serializer &s) +{ + s.Stream(_readAddr, bit_count); +} + SDD1_GCD::SDD1_GCD(SDD1_IM *associatedIM) : IM(associatedIM) { @@ -165,6 +170,11 @@ uint8_t SDD1_BG::getBit(bool *endOfRun) } +void SDD1_BG::Serialize(Serializer &s) +{ + s.Stream(MPScount, LPSind); +} + ///////////////////////////////////////////////// @@ -264,6 +274,13 @@ uint8_t SDD1_PEM::getBit(uint8_t context) return bit ^ currentMPS; } +void SDD1_PEM::Serialize(Serializer &s) +{ + for(int i = 0; i < 32; i++) { + s.Stream(contextInfo[i].status, contextInfo[i].MPS); + } +} + ////////////////////////////////////////////////////////////// @@ -347,6 +364,12 @@ uint8_t SDD1_CM::getBit(void) } +void SDD1_CM::Serialize(Serializer &s) +{ + s.Stream(bitplanesInfo, contextBitsInfo, bit_number, currBitplane); + s.StreamArray(prevBitplaneBits, 8); +} + ////////////////////////////////////////////////// @@ -412,6 +435,12 @@ uint8_t SDD1_OL::decompressByte() throw std::runtime_error("SDD1_OL::decompressByte: Unexpected value"); } +void SDD1_OL::Serialize(Serializer &s) +{ + s.Stream(bitplanesInfo); + s.StreamArray(_regs, 3); +} + void Sdd1Decomp::Init(Sdd1Mmc *mmc, uint32_t readAddr) { uint8_t firstByte = mmc->ReadRom(readAddr); @@ -434,6 +463,22 @@ uint8_t Sdd1Decomp::GetDecompressedByte() return OL.decompressByte(); } +void Sdd1Decomp::Serialize(Serializer &s) +{ + s.Stream(&IM); + s.Stream(&BG0); + s.Stream(&BG1); + s.Stream(&BG2); + s.Stream(&BG3); + s.Stream(&BG4); + s.Stream(&BG5); + s.Stream(&BG6); + s.Stream(&BG7); + s.Stream(&PEM); + s.Stream(&CM); + s.Stream(&OL); +} + Sdd1Decomp::Sdd1Decomp() : GCD(&IM), BG0(&GCD, 0), BG1(&GCD, 1), BG2(&GCD, 2), BG3(&GCD, 3), diff --git a/Core/Sdd1Decomp.h b/Core/Sdd1Decomp.h index 0a0e14a..e927326 100644 --- a/Core/Sdd1Decomp.h +++ b/Core/Sdd1Decomp.h @@ -1,5 +1,6 @@ #pragma once #include "stdafx.h" +#include "../Utilities/ISerializable.h" /************************************************************************ @@ -33,7 +34,7 @@ understood. class Sdd1Mmc; -class SDD1_IM +class SDD1_IM : public ISerializable { //Input Manager Sdd1Mmc* _sdd1Mmc; public: @@ -41,10 +42,11 @@ public: void prepareDecomp(Sdd1Mmc *mmc, uint32_t readAddr); uint8_t getCodeword(const uint8_t code_len); + void Serialize(Serializer &s) override; + private: uint32_t _readAddr; uint8_t bit_count; - }; //////////////////////////////////////////////////// @@ -56,7 +58,7 @@ class SDD1_GCD public: SDD1_GCD(SDD1_IM *associatedIM); void getRunCount(uint8_t code_num, uint8_t *MPScount, bool *LPSind); - + private: SDD1_IM * const IM; @@ -65,13 +67,15 @@ private: ////////////////////////////////////////////////////// -class SDD1_BG +class SDD1_BG : public ISerializable { // Bits Generator public: SDD1_BG(SDD1_GCD *associatedGCD, uint8_t code); void prepareDecomp(void); uint8_t getBit(bool *endOfRun); + + void Serialize(Serializer &s) override; private: const uint8_t code_num; @@ -84,7 +88,7 @@ private: //////////////////////////////////////////////// -class SDD1_PEM +class SDD1_PEM : public ISerializable { //Probability Estimation Module public: @@ -94,6 +98,8 @@ public: SDD1_BG *associatedBG6, SDD1_BG *associatedBG7); void prepareDecomp(void); uint8_t getBit(uint8_t context); + + void Serialize(Serializer &s) override; private: struct state @@ -115,13 +121,15 @@ private: /////////////////////////////////////////////////// -class SDD1_CM +class SDD1_CM : public ISerializable { //Context Model public: SDD1_CM(SDD1_PEM *associatedPEM); void prepareDecomp(uint8_t firstByte); uint8_t getBit(void); + + void Serialize(Serializer &s) override; private: uint8_t bitplanesInfo; @@ -136,13 +144,15 @@ private: /////////////////////////////////////////////////// -class SDD1_OL +class SDD1_OL : public ISerializable { //Output Logic public: SDD1_OL(SDD1_CM *associatedCM); void prepareDecomp(uint8_t firstByte); uint8_t decompressByte(); + + void Serialize(Serializer &s) override; private: uint8_t bitplanesInfo; @@ -151,13 +161,15 @@ private: }; -class Sdd1Decomp +class Sdd1Decomp : public ISerializable { public: Sdd1Decomp(); void Init(Sdd1Mmc *mmc, uint32_t readAddr); uint8_t GetDecompressedByte(); + void Serialize(Serializer &s) override; + private: SDD1_IM IM; SDD1_GCD GCD; diff --git a/Core/Sdd1Mmc.cpp b/Core/Sdd1Mmc.cpp index e18e7f6..789afcd 100644 --- a/Core/Sdd1Mmc.cpp +++ b/Core/Sdd1Mmc.cpp @@ -82,3 +82,8 @@ AddressInfo Sdd1Mmc::GetAbsoluteAddress(uint32_t address) { return GetHandler(address)->GetAbsoluteAddress(address); } + +void Sdd1Mmc::Serialize(Serializer &s) +{ + s.Stream(&_decompressor); +} diff --git a/Core/Sdd1Mmc.h b/Core/Sdd1Mmc.h index 8c5ef0f..db6185d 100644 --- a/Core/Sdd1Mmc.h +++ b/Core/Sdd1Mmc.h @@ -3,10 +3,11 @@ #include "IMemoryHandler.h" #include "Sdd1Types.h" #include "Sdd1Decomp.h" +#include "../Utilities/ISerializable.h" class BaseCartridge; -class Sdd1Mmc : public IMemoryHandler +class Sdd1Mmc : public IMemoryHandler, public ISerializable { private: Sdd1State* _state; @@ -27,4 +28,6 @@ public: virtual void PeekBlock(uint8_t * output) override; virtual void Write(uint32_t addr, uint8_t value) override; virtual AddressInfo GetAbsoluteAddress(uint32_t address) override; + + void Serialize(Serializer &s) override; }; \ No newline at end of file