From 4ca6aaea333f095289d4090fa6e579ef9de6a17e Mon Sep 17 00:00:00 2001 From: tomcw Date: Sat, 31 Dec 2022 19:51:05 +0000 Subject: [PATCH] Add save-state support for new unit: 'Game I/O Connector' --- source/CopyProtectionDongles.cpp | 34 ++++++++++++++++++++++++++++++++ source/CopyProtectionDongles.h | 3 +++ source/SaveState.cpp | 27 ++++++++++++++++++++++++- 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/source/CopyProtectionDongles.cpp b/source/CopyProtectionDongles.cpp index f86ec3d8..afe7cfa2 100644 --- a/source/CopyProtectionDongles.cpp +++ b/source/CopyProtectionDongles.cpp @@ -34,6 +34,7 @@ #include "CopyProtectionDongles.h" #include "Memory.h" +#include "YamlHelper.h" static DONGLETYPE copyProtectionDongleType = DT_EMPTY; @@ -80,3 +81,36 @@ int CopyProtectionDonglePB2(void) break; } } + +const std::string& CopyProtectionDongle_GetSnapshotStructName_SDSSpeedStar(void) +{ + static const std::string name("SDS SpeedStar dongle"); + return name; +} + +void CopyProtectionDongleSaveSnapshot(YamlSaveHelper& yamlSaveHelper) +{ + if (copyProtectionDongleType == DT_SDSSPEEDSTAR) + { + YamlSaveHelper::Label label(yamlSaveHelper, "%s: null\n", CopyProtectionDongle_GetSnapshotStructName_SDSSpeedStar().c_str()); + // NB. No state for this dongle + } + else + { + _ASSERT(0); + } +} + +void CopyProtectionDongleLoadSnapshot(YamlLoadHelper& yamlLoadHelper) +{ + bool found = false; + std::string s = yamlLoadHelper.LoadString_NoThrow(CopyProtectionDongle_GetSnapshotStructName_SDSSpeedStar(), found); + if (found) + { + copyProtectionDongleType = DT_SDSSPEEDSTAR; + } + else + { + _ASSERT(0); + } +} diff --git a/source/CopyProtectionDongles.h b/source/CopyProtectionDongles.h index bb50a7bf..f019d2d9 100644 --- a/source/CopyProtectionDongles.h +++ b/source/CopyProtectionDongles.h @@ -11,3 +11,6 @@ int CopyProtectionDonglePB0(void); int CopyProtectionDonglePB1(void); int CopyProtectionDonglePB2(void); bool SdsSpeedStar(void); + +void CopyProtectionDongleSaveSnapshot(class YamlSaveHelper& yamlSaveHelper); +void CopyProtectionDongleLoadSnapshot(class YamlLoadHelper& yamlLoadHelper); diff --git a/source/SaveState.cpp b/source/SaveState.cpp index c9e9f92a..c0ab53eb 100644 --- a/source/SaveState.cpp +++ b/source/SaveState.cpp @@ -33,6 +33,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "Interface.h" #include "CardManager.h" +#include "CopyProtectionDongles.h" #include "Debug.h" #include "Joystick.h" #include "Keyboard.h" @@ -66,10 +67,13 @@ static YamlHelper yamlHelper; // v5: Extended: cpu (added 'Defer IRQ By 1 Opcode') // v6: Added 'Unit Miscellaneous' for NoSlotClock(NSC) // v7: Extended: joystick (added 'Paddle Inactive Cycle') -#define UNIT_APPLE2_VER 7 +// v8: Added 'Unit Game I/O Connector' for Game I/O Connector +#define UNIT_APPLE2_VER 8 #define UNIT_SLOTS_VER 1 +#define UNIT_GAME_IO_CONNECTOR_VER 1 + #define UNIT_MISC_VER 1 //----------------------------------------------------------------------------- @@ -178,6 +182,12 @@ static const std::string& GetSnapshotUnitSlotsName(void) return name; } +static const std::string& GetSnapshotUnitGameIOConnectorName(void) +{ + static const std::string name("Game I/O Connector"); + return name; +} + static const std::string& GetSnapshotUnitMiscName(void) { static const std::string name("Miscellaneous"); @@ -329,6 +339,10 @@ static void ParseUnit(void) { ParseSlots(yamlLoadHelper, unitVersion); } + else if (unit == GetSnapshotUnitGameIOConnectorName()) + { + CopyProtectionDongleLoadSnapshot(yamlLoadHelper); + } else if (unit == GetSnapshotUnitMiscName()) { // NB. could extend for other misc devices - see how ParseSlots() calls GetMapNextSlotNumber() @@ -365,6 +379,8 @@ static void Snapshot_LoadState_v2(void) GetCardMgr().Remove(slot); GetCardMgr().RemoveAux(); + SetCopyProtectionDongleType(DT_EMPTY); + MemReset(); // Also calls CpuInitialize() GetPravets().Reset(); @@ -478,6 +494,15 @@ void Snapshot_SaveState(void) GetCardMgr().SaveSnapshot(yamlSaveHelper); } + // Unit: Game I/O Connector + if (GetCopyProtectionDongleType() != DT_EMPTY) + { + yamlSaveHelper.UnitHdr(GetSnapshotUnitGameIOConnectorName(), UNIT_GAME_IO_CONNECTOR_VER); + YamlSaveHelper::Label unit(yamlSaveHelper, "%s:\n", SS_YAML_KEY_STATE); + + CopyProtectionDongleSaveSnapshot(yamlSaveHelper); + } + // Miscellaneous if (MemHasNoSlotClock()) {