Refactoring, include "rom image" in save.

This commit is contained in:
Christian Speckner 2024-08-14 21:21:37 +02:00
parent fcc05a84fc
commit daf83faff3
7 changed files with 95 additions and 38 deletions

View File

@ -270,9 +270,13 @@ bool CartridgeELF::save(Serializer& out) const
out.putInt(myInitFunctionIndex); out.putInt(myInitFunctionIndex);
out.putByte(static_cast<uInt8>(myConsoleTiming)); out.putByte(static_cast<uInt8>(myConsoleTiming));
myTransactionQueue.save(out); out.putByteArray(myLastPeekResult.get(), 0x1000);
myCortexEmu.save(out);
myVcsLib.save(out); if (!myTransactionQueue.save(out)) return false;
if (!myCortexEmu.save(out)) return false;
if (!myVcsLib.save(out)) return false;
myCortexEmu.saveDirtyRegions(out);
} }
catch(...) { catch(...) {
cerr << "ERROR: failed to save ELF\n"; cerr << "ERROR: failed to save ELF\n";

View File

@ -559,7 +559,7 @@ CortexM0::CortexM0()
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CortexM0::MemoryRegion::save(Serializer& serializer) const void CortexM0::MemoryRegion::serialize(Serializer& serializer) const
{ {
if (type != MemoryRegionType::directCode && type != MemoryRegionType::directData) return; if (type != MemoryRegionType::directCode && type != MemoryRegionType::directData) return;
@ -589,8 +589,9 @@ void CortexM0::MemoryRegion::save(Serializer& serializer) const
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CortexM0::save(Serializer& serializer) const bool CortexM0::save(Serializer& serializer) const
{ {
try {
for (size_t i = 0; i < 16; i++) for (size_t i = 0; i < 16; i++)
serializer.putInt(reg_norm[i]); serializer.putInt(reg_norm[i]);
@ -598,10 +599,28 @@ void CortexM0::save(Serializer& serializer) const
serializer.putInt(cFlag); serializer.putInt(cFlag);
serializer.putInt(vFlag); serializer.putInt(vFlag);
serializer.putLong(myCycleCounter); serializer.putLong(myCycleCounter);
for (size_t i = 0; i < myNextRegionIndex; i++)
myRegions[i].save(serializer);
} }
catch (...) {
cerr << "ERROR: failed to save cortex M0\n";
return false;
}
return true;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool CortexM0::load(Serializer& serializer)
{
return false;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CortexM0::saveDirtyRegions(Serializer& serializer) const
{
for (size_t i = 0; i < myNextRegionIndex; i++)
myRegions[i].serialize(serializer);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CortexM0::MemoryRegion::reset() void CortexM0::MemoryRegion::reset()

View File

@ -25,11 +25,12 @@
#include <variant> #include <variant>
#include "Serializable.hxx"
#include "bspf.hxx" #include "bspf.hxx"
class Serializer; class Serializer;
class CortexM0 class CortexM0: public Serializable
{ {
public: public:
using err_t = uInt64; using err_t = uInt64;
@ -118,7 +119,9 @@ class CortexM0
CortexM0& mapDefault(BusTransactionDelegate* delegate); CortexM0& mapDefault(BusTransactionDelegate* delegate);
void save(Serializer& serializer) const; bool save(Serializer& serializer) const override;
bool load(Serializer& serializer) override;
void saveDirtyRegions(Serializer& serialized) const;
CortexM0& reset(); CortexM0& reset();
CortexM0& setPc(uInt32 pc); CortexM0& setPc(uInt32 pc);
@ -181,7 +184,7 @@ class CortexM0
> access; > access;
void reset(); void reset();
void save(Serializer& serializer) const; void serialize(Serializer& serializer) const;
private: private:
MemoryRegion(const MemoryRegion&) = delete; MemoryRegion(const MemoryRegion&) = delete;

View File

@ -66,18 +66,32 @@ BusTransactionQueue& BusTransactionQueue::reset()
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void BusTransactionQueue::save(Serializer& serializer) const bool BusTransactionQueue::save(Serializer& serializer) const
{ {
try {
serializer.putInt(myQueueSize); serializer.putInt(myQueueSize);
serializer.putShort(myNextInjectAddress); serializer.putShort(myNextInjectAddress);
serializer.putLong(myTimestamp); serializer.putLong(myTimestamp);
for (size_t i = 0; i < myQueueSize; i++) for (size_t i = 0; i < myQueueSize; i++)
myQueue[(myQueueNext + i) % myQueueCapacity].save(serializer); myQueue[(myQueueNext + i) % myQueueCapacity].serialize(serializer);
}
catch (...) {
cerr << "ERROR: failed to save bus transaction queue\n";
return false;
}
return true;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void BusTransactionQueue::Transaction::save(Serializer& serializer) const bool BusTransactionQueue::load(Serializer& serializer)
{
return true;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void BusTransactionQueue::Transaction::serialize(Serializer& serializer) const
{ {
serializer.putShort(address); serializer.putShort(address);
serializer.putShort(mask); serializer.putShort(mask);

View File

@ -18,11 +18,12 @@
#ifndef BUS_TRANSACTION_QUEUE #ifndef BUS_TRANSACTION_QUEUE
#define BUS_TRANSACTION_QUEUE #define BUS_TRANSACTION_QUEUE
#include "Serializable.hxx"
#include "bspf.hxx" #include "bspf.hxx"
class Serializer; class Serializer;
class BusTransactionQueue { class BusTransactionQueue: public Serializable {
public: public:
struct Transaction { struct Transaction {
static Transaction transactionYield(uInt16 address, uInt64 timestamp, uInt16 mask); static Transaction transactionYield(uInt16 address, uInt64 timestamp, uInt16 mask);
@ -36,7 +37,7 @@ class BusTransactionQueue {
uInt64 timestamp{0}; uInt64 timestamp{0};
bool yield{false}; bool yield{false};
void save(Serializer& serializer) const; void serialize(Serializer& serializer) const;
}; };
public: public:
@ -45,7 +46,8 @@ class BusTransactionQueue {
BusTransactionQueue& reset(); BusTransactionQueue& reset();
void save(Serializer& serializer) const; bool save(Serializer& serializer) const override;
bool load(Serializer& serializer) override;
BusTransactionQueue& setNextInjectAddress(uInt16 address); BusTransactionQueue& setNextInjectAddress(uInt16 address);
uInt16 getNextInjectAddress() const; uInt16 getNextInjectAddress() const;

View File

@ -112,8 +112,9 @@ VcsLib::VcsLib(BusTransactionQueue& transactionQueue)
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void VcsLib::save(Serializer& serializer) const bool VcsLib::save(Serializer& serializer) const
{ {
try {
serializer.putByte(myStuffMaskA); serializer.putByte(myStuffMaskA);
serializer.putByte(myStuffMaskX); serializer.putByte(myStuffMaskX);
serializer.putByte(myStuffMaskY); serializer.putByte(myStuffMaskY);
@ -122,8 +123,20 @@ void VcsLib::save(Serializer& serializer) const
serializer.putShort(myCurrentAddress); serializer.putShort(myCurrentAddress);
serializer.putBool(myCurrentValue); serializer.putBool(myCurrentValue);
if (!myRand.save(serializer)) if (!myRand.save(serializer)) return false;
throw runtime_error("failed to save RNG"); }
catch (...) {
cerr << "ERROR: failed to save vcslib\n";
return false;
}
return true;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool VcsLib::load(Serializer& serializer)
{
return false;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -22,15 +22,17 @@
#include "Random.hxx" #include "Random.hxx"
#include "CortexM0.hxx" #include "CortexM0.hxx"
#include "BusTransactionQueue.hxx" #include "BusTransactionQueue.hxx"
#include "Serializable.hxx"
class Serializer; class Serializer;
class VcsLib: public CortexM0::BusTransactionDelegate { class VcsLib: public CortexM0::BusTransactionDelegate, public Serializable {
public: public:
explicit VcsLib(BusTransactionQueue& transactionQueue); explicit VcsLib(BusTransactionQueue& transactionQueue);
~VcsLib() override = default; ~VcsLib() override = default;
void save(Serializer& serializer) const; bool save(Serializer& serializer) const override;
bool load(Serializer& serializer) override;
void reset(); void reset();