Skip to content

Commit

Permalink
Serialization cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkwhoffmann committed Jan 20, 2024
1 parent 62bbf8f commit 40cf957
Show file tree
Hide file tree
Showing 51 changed files with 231 additions and 199 deletions.
12 changes: 6 additions & 6 deletions Emulator/Base/CoreComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,35 +213,35 @@ class CoreComponent : public CoreObject, NoCopy, NoAssign {
#define RESET_SNAPSHOT_ITEMS(hard) \
if (hard) { \
util::SerHardResetter resetter; \
applyToResetItems(resetter); \
serialize(resetter); \
} else { \
util::SerSoftResetter resetter; \
applyToResetItems(resetter); \
serialize(resetter); \
}

#define COMPUTE_SNAPSHOT_SIZE \
util::SerCounter counter; \
applyToPersistentItems(counter); \
applyToResetItems(counter); \
serialize(counter); \
return counter.count;

#define COMPUTE_SNAPSHOT_CHECKSUM \
util::SerChecker checker; \
applyToPersistentItems(checker); \
applyToResetItems(checker); \
serialize(checker); \
return checker.hash;

#define LOAD_SNAPSHOT_ITEMS \
util::SerReader reader(buffer); \
applyToPersistentItems(reader); \
applyToResetItems(reader); \
serialize(reader); \
debug(SNP_DEBUG, "Recreated from %zu bytes\n", reader.ptr - buffer); \
return (isize)(reader.ptr - buffer);

#define SAVE_SNAPSHOT_ITEMS \
util::SerWriter writer(buffer); \
applyToPersistentItems(writer); \
applyToResetItems(writer); \
serialize(writer); \
debug(SNP_DEBUG, "Serialized to %zu bytes\n", writer.ptr - buffer); \
return (isize)(writer.ptr - buffer);

Expand Down
8 changes: 4 additions & 4 deletions Emulator/Cartridges/Cartridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ Cartridge::_size()
{
util::SerCounter counter;
applyToPersistentItems(counter);
applyToResetItems(counter);
serialize(counter);

isize result = counter.count;

Expand All @@ -265,7 +265,7 @@ Cartridge::_checksum()
{
util::SerChecker checker;
applyToPersistentItems(checker);
applyToResetItems(checker);
serialize(checker);

return util::fnvIt64(checker.hash, __checksum());
}
Expand All @@ -277,7 +277,7 @@ Cartridge::_load(const u8 *buffer)

util::SerReader reader(buffer);
applyToPersistentItems(reader);
applyToResetItems(reader);
serialize(reader);

// Load ROM
for (isize i = 0; i < numPackets; i++) {
Expand Down Expand Up @@ -307,7 +307,7 @@ Cartridge::_save(u8 *buffer)
{
util::SerWriter writer(buffer);
applyToPersistentItems(writer);
applyToResetItems(writer);
serialize(writer);

// Save ROM
for (isize i = 0; i < numPackets; i++) {
Expand Down
2 changes: 1 addition & 1 deletion Emulator/Cartridges/Cartridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class Cartridge : public SubComponent {
}

template <class T>
void applyToResetItems(T& worker, bool hard = true)
void serialize(T& worker)
{
worker

Expand Down
6 changes: 3 additions & 3 deletions Emulator/Cartridges/CartridgeRom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ CartridgeRom::_size()
{
util::SerCounter counter;
applyToPersistentItems(counter);
applyToResetItems(counter);
serialize(counter);

return size + counter.count;
}
Expand All @@ -51,7 +51,7 @@ CartridgeRom::_load(const u8 *buffer)
{
util::SerReader reader(buffer);
applyToPersistentItems(reader);
applyToResetItems(reader);
serialize(reader);

// Delete the old packet and create a new one with the proper size
if (rom) delete[] rom;
Expand All @@ -69,7 +69,7 @@ CartridgeRom::_save(u8 *buffer)
{
util::SerWriter writer(buffer);
applyToPersistentItems(writer);
applyToResetItems(writer);
serialize(writer);

// Write packet data
for (int i = 0; i < size; i++) util::write8(writer.ptr, rom[i]);
Expand Down
2 changes: 1 addition & 1 deletion Emulator/Cartridges/CartridgeRom.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class CartridgeRom : public SubComponent {
}

template <class T>
void applyToResetItems(T& worker, bool hard = true)
void serialize(T& worker)
{
}

Expand Down
2 changes: 1 addition & 1 deletion Emulator/Cartridges/CustomCartridges/EasyFlash.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class EasyFlash : public Cartridge {
}

template <class T>
void applyToResetItems(T& worker, bool hard = true)
void serialize(T& worker)
{
worker

Expand Down
13 changes: 6 additions & 7 deletions Emulator/Cartridges/CustomCartridges/Epyx.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,13 @@ class Epyx : public Cartridge {
}

template <class T>
void applyToResetItems(T& worker, bool hard = true)
void serialize(T& worker)
{
if (hard) {

worker

<< cycle;
}
if (util::isSoftResetter(worker)) return;

worker

<< cycle;
}

isize __size() override { COMPUTE_SNAPSHOT_SIZE }
Expand Down
2 changes: 1 addition & 1 deletion Emulator/Cartridges/CustomCartridges/Expert.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Expert : public Cartridge {
}

template <class T>
void applyToResetItems(T& worker, bool hard = true)
void serialize(T& worker)
{
}

Expand Down
2 changes: 1 addition & 1 deletion Emulator/Cartridges/CustomCartridges/FinalIII.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class FinalIII : public Cartridge {
}

template <class T>
void applyToResetItems(T& worker, bool hard = true)
void serialize(T& worker)
{
worker << qD;
}
Expand Down
2 changes: 1 addition & 1 deletion Emulator/Cartridges/CustomCartridges/GeoRam.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class GeoRAM : public Cartridge {
}

template <class T>
void applyToResetItems(T& worker, bool hard = true)
void serialize(T& worker)
{
}

Expand Down
2 changes: 1 addition & 1 deletion Emulator/Cartridges/CustomCartridges/Isepic.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Isepic : public Cartridge {
}

template <class T>
void applyToResetItems(T& worker, bool hard = true)
void serialize(T& worker)
{
worker

Expand Down
2 changes: 1 addition & 1 deletion Emulator/Cartridges/CustomCartridges/PageFox.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class PageFox : public Cartridge {
}

template <class T>
void applyToResetItems(T& worker, bool hard = true)
void serialize(T& worker)
{
}

Expand Down
2 changes: 1 addition & 1 deletion Emulator/Cartridges/CustomCartridges/Reu.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class Reu : public Cartridge {
}

template <class T>
void applyToResetItems(T& worker, bool hard = true)
void serialize(T& worker)
{
}

Expand Down
2 changes: 1 addition & 1 deletion Emulator/Cartridges/CustomCartridges/StarDos.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class StarDos : public Cartridge {
}

template <class T>
void applyToResetItems(T& worker, bool hard = true)
void serialize(T& worker)
{
worker

Expand Down
2 changes: 1 addition & 1 deletion Emulator/Cartridges/CustomCartridges/SuperGames.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class SuperGames : public Cartridge {
}

template <class T>
void applyToResetItems(T& worker, bool hard = true)
void serialize(T& worker)
{
worker

Expand Down
2 changes: 1 addition & 1 deletion Emulator/Cartridges/FlashRom.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class FlashRom : public SubComponent {
}

template <class T>
void applyToResetItems(T& worker, bool hard = true)
void serialize(T& worker)
{
}

Expand Down
27 changes: 13 additions & 14 deletions Emulator/Components/C64.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,21 +348,20 @@ class C64 : public Thread {
}

template <class T>
void applyToResetItems(T& worker, bool hard = true)
void serialize(T& worker)
{
if (hard) {

worker

<< trigger
<< id
<< data
<< nextTrigger
<< frame
<< scanline
<< rasterCycle
<< ultimax;
}
if (util::isSoftResetter(worker)) return;

worker

<< trigger
<< id
<< data
<< nextTrigger
<< frame
<< scanline
<< rasterCycle
<< ultimax;
}

public:
Expand Down
2 changes: 1 addition & 1 deletion Emulator/Components/CIA/CIA.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ class CIA : public SubComponent {
}

template <class T>
void applyToResetItems(T& worker, bool hard = true)
void serialize(T& worker)
{
worker

Expand Down
2 changes: 1 addition & 1 deletion Emulator/Components/CIA/TOD.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class TOD : public SubComponent {
}

template <class T>
void applyToResetItems(T& worker, bool hard = true)
void serialize(T& worker)
{
worker

Expand Down
13 changes: 7 additions & 6 deletions Emulator/Components/CPU/CPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,8 @@ class CPU : public Peddle {
}

template <class T>
void applyToResetItems(T& worker, bool hard = true)
void serialize(T& worker)
{
if (hard) {

worker << clock;
}

worker

<< flags
Expand Down Expand Up @@ -135,6 +130,12 @@ class CPU : public Peddle {
<< dischargeCycleBit3
<< dischargeCycleBit6
<< dischargeCycleBit7;

if (util::isSoftResetter(worker)) return;

worker

<< clock;
}

isize _size() override { COMPUTE_SNAPSHOT_SIZE }
Expand Down
2 changes: 1 addition & 1 deletion Emulator/Components/LogicBoard/ControlPort.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class ControlPort : public SubComponent {
}

template <class T>
void applyToResetItems(T& worker, bool hard = true)
void serialize(T& worker)
{
}

Expand Down
8 changes: 4 additions & 4 deletions Emulator/Components/LogicBoard/ExpansionPort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ ExpansionPort::_size()
{
util::SerCounter counter;
applyToPersistentItems(counter);
applyToResetItems(counter);
serialize(counter);

if (cartridge) counter.count += cartridge->size();
return counter.count;
Expand All @@ -43,7 +43,7 @@ ExpansionPort::_checksum()
util::SerChecker checker;

applyToPersistentItems(checker);
applyToResetItems(checker);
serialize(checker);

if (cartridge) {
checker.hash = util::fnvIt64(checker.hash, cartridge->checksum());
Expand All @@ -57,7 +57,7 @@ ExpansionPort::_load(const u8 *buffer)
{
util::SerReader reader(buffer);
applyToPersistentItems(reader);
applyToResetItems(reader);
serialize(reader);

// Load cartridge (if any)
if (crtType != CRT_NONE) {
Expand All @@ -74,7 +74,7 @@ ExpansionPort::_save(u8 *buffer)
{
util::SerWriter writer(buffer);
applyToPersistentItems(writer);
applyToResetItems(writer);
serialize(writer);

// Save cartridge (if any)
if (crtType != CRT_NONE) {
Expand Down
2 changes: 1 addition & 1 deletion Emulator/Components/LogicBoard/ExpansionPort.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class ExpansionPort : public SubComponent {
}

template <class T>
void applyToResetItems(T& worker, bool hard = true)
void serialize(T& worker)
{
}

Expand Down
2 changes: 1 addition & 1 deletion Emulator/Components/LogicBoard/IEC.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class IEC : public SubComponent {
}

template <class T>
void applyToResetItems(T& worker, bool hard = true)
void serialize(T& worker)
{
worker

Expand Down
2 changes: 1 addition & 1 deletion Emulator/Components/LogicBoard/PowerSupply.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class PowerSupply : public SubComponent {
}

template <class T>
void applyToResetItems(T& worker, bool hard = true)
void serialize(T& worker)
{
}

Expand Down
Loading

0 comments on commit 40cf957

Please sign in to comment.