From 80f28dd5a1544010d1a775e6a1d0fa6f255dacaf Mon Sep 17 00:00:00 2001 From: Dirk Hoffmann Date: Sun, 21 Jan 2024 11:41:20 +0100 Subject: [PATCH] Fixed severe snapshot saving bugs --- Emulator/Base/CoreComponent.cpp | 2 + Emulator/Components/CPU/CPU.h | 18 +++++---- .../Components/LogicBoard/ExpansionPort.cpp | 6 ++- Emulator/Components/Memory/C64Memory.h | 9 ++--- Emulator/Components/VICII/VICII.h | 2 + .../Misc/RetroShell/InterpreterDebugCmds.cpp | 2 +- Emulator/Peripherals/Drive/DiskTypes.h | 39 ++++++++++++------- 7 files changed, 48 insertions(+), 30 deletions(-) diff --git a/Emulator/Base/CoreComponent.cpp b/Emulator/Base/CoreComponent.cpp index 0fb620b09..bb95c861e 100755 --- a/Emulator/Base/CoreComponent.cpp +++ b/Emulator/Base/CoreComponent.cpp @@ -94,6 +94,8 @@ CoreComponent::load(const u8 *buffer) // Check integrity if (hash != _checksum() || FORCE_SNAP_CORRUPTED) { + + debug(SNP_DEBUG, "Corrupted snapshot detected\n"); throw VC64Error(ERROR_SNAP_CORRUPTED); } diff --git a/Emulator/Components/CPU/CPU.h b/Emulator/Components/CPU/CPU.h index ef04f3dea..e0cc03c19 100755 --- a/Emulator/Components/CPU/CPU.h +++ b/Emulator/Components/CPU/CPU.h @@ -95,12 +95,17 @@ class CPU : public Peddle { << flags << next - << reg.a - << reg.x - << reg.y << reg.pc << reg.pc0 << reg.sp + << reg.a + << reg.x + << reg.y + << reg.adl + << reg.adh + << reg.idl + << reg.d + << reg.ovl << reg.sr.n << reg.sr.v << reg.sr.b @@ -108,11 +113,8 @@ class CPU : public Peddle { << reg.sr.i << reg.sr.z << reg.sr.c - << reg.adl - << reg.adh - << reg.idl - << reg.d - << reg.ovl + << reg.pport.data + << reg.pport.direction << rdyLine << rdyLineUp << rdyLineDown diff --git a/Emulator/Components/LogicBoard/ExpansionPort.cpp b/Emulator/Components/LogicBoard/ExpansionPort.cpp index 4292b07ca..98bd08a74 100644 --- a/Emulator/Components/LogicBoard/ExpansionPort.cpp +++ b/Emulator/Components/LogicBoard/ExpansionPort.cpp @@ -56,12 +56,16 @@ ExpansionPort::_load(const u8 *buffer) util::SerReader reader(buffer); serialize(reader); + // Delete existing cartridge + cartridge = nullptr; + // Load cartridge (if any) if (crtType != CRT_NONE) { + cartridge = std::unique_ptr(Cartridge::makeWithType(c64, crtType)); reader.ptr += cartridge->load(reader.ptr); } - + debug(SNP_DEBUG, "Recreated from %ld bytes\n", isize(reader.ptr - buffer)); return isize(reader.ptr - buffer); } diff --git a/Emulator/Components/Memory/C64Memory.h b/Emulator/Components/Memory/C64Memory.h index 136d0d43c..af79c6591 100644 --- a/Emulator/Components/Memory/C64Memory.h +++ b/Emulator/Components/Memory/C64Memory.h @@ -94,7 +94,11 @@ class C64Memory : public SubComponent { worker << rom; + } + template + void serialize(T& worker) + { if (util::isResetter(worker)) return; worker @@ -104,11 +108,6 @@ class C64Memory : public SubComponent { << peekSrc << pokeTarget; } - - template - void serialize(T& worker) - { - } isize _size() override; u64 _checksum() override; diff --git a/Emulator/Components/VICII/VICII.h b/Emulator/Components/VICII/VICII.h index 697e66f86..cf01da3c4 100755 --- a/Emulator/Components/VICII/VICII.h +++ b/Emulator/Components/VICII/VICII.h @@ -671,8 +671,10 @@ class VICII : public SubComponent { << spriteDmaOnOff << expansionFF << cleared_bits_in_d017 + << collision << lpLine << lpIrqHasOccurred + << memSrc << ultimax << dataBusPhi1 << dataBusPhi2 diff --git a/Emulator/Misc/RetroShell/InterpreterDebugCmds.cpp b/Emulator/Misc/RetroShell/InterpreterDebugCmds.cpp index 4222c85b3..4e035fc11 100644 --- a/Emulator/Misc/RetroShell/InterpreterDebugCmds.cpp +++ b/Emulator/Misc/RetroShell/InterpreterDebugCmds.cpp @@ -232,7 +232,7 @@ Interpreter::initDebugShell(Command &root) for (isize i = 0; i < 2; i++) { - string cia = (i == 0) ? "cia1" : "cia1"; + string cia = (i == 0) ? "cia1" : "cia2"; root.add({cia, ""}, "Displays the component state", diff --git a/Emulator/Peripherals/Drive/DiskTypes.h b/Emulator/Peripherals/Drive/DiskTypes.h index f054e9694..d6b56c7f4 100644 --- a/Emulator/Peripherals/Drive/DiskTypes.h +++ b/Emulator/Peripherals/Drive/DiskTypes.h @@ -12,6 +12,10 @@ #include "Aliases.h" #include "Reflection.h" +#ifdef __cplusplus +#include "Serialization.h" +#endif + // // Constants // @@ -220,16 +224,18 @@ struct DiskErrorCodeEnum : util::Reflection { */ #ifdef __cplusplus -union DiskData +struct DiskData : public util::Serializable { - struct - { - u8 _pad[maxBytesOnTrack]; - u8 halftrack[85][maxBytesOnTrack]; + union { + + struct + { + u8 _pad[maxBytesOnTrack]; + u8 halftrack[85][maxBytesOnTrack]; + }; + + u8 track[43][2 * maxBytesOnTrack]; }; - - u8 track[43][2 * maxBytesOnTrack]; - template void operator<<(W& worker) { @@ -248,15 +254,18 @@ union DiskData */ #ifdef __cplusplus -union DiskLength +struct DiskLength : public util::Serializable { - struct - { - isize _pad; - isize halftrack[85]; + union { + + struct + { + isize _pad; + isize halftrack[85]; + }; + + isize track[43][2]; }; - - isize track[43][2]; template void operator<<(W& worker)