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,20 +589,39 @@ void CortexM0::MemoryRegion::save(Serializer& serializer) const
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CortexM0::save(Serializer& serializer) const bool CortexM0::save(Serializer& serializer) const
{ {
for (size_t i = 0; i < 16; i++) try {
serializer.putInt(reg_norm[i]); for (size_t i = 0; i < 16; i++)
serializer.putInt(reg_norm[i]);
serializer.putInt(znFlags); serializer.putInt(znFlags);
serializer.putInt(cFlag); serializer.putInt(cFlag);
serializer.putInt(vFlag); serializer.putInt(vFlag);
serializer.putLong(myCycleCounter); serializer.putLong(myCycleCounter);
}
catch (...) {
cerr << "ERROR: failed to save cortex M0\n";
return false;
}
for (size_t i = 0; i < myNextRegionIndex; i++) return true;
myRegions[i].save(serializer);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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
{ {
serializer.putInt(myQueueSize); try {
serializer.putShort(myNextInjectAddress); serializer.putInt(myQueueSize);
serializer.putLong(myTimestamp); serializer.putShort(myNextInjectAddress);
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,18 +112,31 @@ VcsLib::VcsLib(BusTransactionQueue& transactionQueue)
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void VcsLib::save(Serializer& serializer) const bool VcsLib::save(Serializer& serializer) const
{ {
serializer.putByte(myStuffMaskA); try {
serializer.putByte(myStuffMaskX); serializer.putByte(myStuffMaskA);
serializer.putByte(myStuffMaskY); serializer.putByte(myStuffMaskX);
serializer.putBool(myIsWaitingForRead); serializer.putByte(myStuffMaskY);
serializer.putShort(myWaitingForReadAddress); serializer.putBool(myIsWaitingForRead);
serializer.putShort(myCurrentAddress); serializer.putShort(myWaitingForReadAddress);
serializer.putBool(myCurrentValue); serializer.putShort(myCurrentAddress);
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();