diff --git a/source/CopyProtectionDongles.cpp b/source/CopyProtectionDongles.cpp index afe7cfa2..9fdf8eb0 100644 --- a/source/CopyProtectionDongles.cpp +++ b/source/CopyProtectionDongles.cpp @@ -31,6 +31,7 @@ Matthew D'Asaro Dec 2022 */ #include "StdAfx.h" +#include #include "CopyProtectionDongles.h" #include "Memory.h" @@ -82,7 +83,11 @@ int CopyProtectionDonglePB2(void) } } -const std::string& CopyProtectionDongle_GetSnapshotStructName_SDSSpeedStar(void) +//=========================================================================== + +static const UINT kUNIT_VERSION = 1; + +static const std::string& GetSnapshotStructName_SDSSpeedStar(void) { static const std::string name("SDS SpeedStar dongle"); return name; @@ -92,7 +97,7 @@ void CopyProtectionDongleSaveSnapshot(YamlSaveHelper& yamlSaveHelper) { if (copyProtectionDongleType == DT_SDSSPEEDSTAR) { - YamlSaveHelper::Label label(yamlSaveHelper, "%s: null\n", CopyProtectionDongle_GetSnapshotStructName_SDSSpeedStar().c_str()); + yamlSaveHelper.SaveString(SS_YAML_KEY_DEVICE, GetSnapshotStructName_SDSSpeedStar()); // NB. No state for this dongle } else @@ -101,11 +106,20 @@ void CopyProtectionDongleSaveSnapshot(YamlSaveHelper& yamlSaveHelper) } } -void CopyProtectionDongleLoadSnapshot(YamlLoadHelper& yamlLoadHelper) +void CopyProtectionDongleLoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT version) { - bool found = false; - std::string s = yamlLoadHelper.LoadString_NoThrow(CopyProtectionDongle_GetSnapshotStructName_SDSSpeedStar(), found); - if (found) + if (version < 1 || version > kUNIT_VERSION) + { + std::ostringstream msg; + msg << "Version " << version; + msg << " is not supported for game I/O device."; + + throw std::runtime_error(msg.str()); + } + + std::string device = yamlLoadHelper.LoadString(SS_YAML_KEY_DEVICE); + + if (device == GetSnapshotStructName_SDSSpeedStar()) { copyProtectionDongleType = DT_SDSSPEEDSTAR; } diff --git a/source/CopyProtectionDongles.h b/source/CopyProtectionDongles.h index f019d2d9..7b4ace5e 100644 --- a/source/CopyProtectionDongles.h +++ b/source/CopyProtectionDongles.h @@ -13,4 +13,4 @@ int CopyProtectionDonglePB2(void); bool SdsSpeedStar(void); void CopyProtectionDongleSaveSnapshot(class YamlSaveHelper& yamlSaveHelper); -void CopyProtectionDongleLoadSnapshot(class YamlLoadHelper& yamlLoadHelper); +void CopyProtectionDongleLoadSnapshot(class YamlLoadHelper& yamlLoadHelper, UINT version); diff --git a/source/SaveState.cpp b/source/SaveState.cpp index c0ab53eb..641c2152 100644 --- a/source/SaveState.cpp +++ b/source/SaveState.cpp @@ -341,7 +341,7 @@ static void ParseUnit(void) } else if (unit == GetSnapshotUnitGameIOConnectorName()) { - CopyProtectionDongleLoadSnapshot(yamlLoadHelper); + CopyProtectionDongleLoadSnapshot(yamlLoadHelper, unitVersion); } else if (unit == GetSnapshotUnitMiscName()) { diff --git a/source/YamlHelper.h b/source/YamlHelper.h index 33345183..409203b4 100644 --- a/source/YamlHelper.h +++ b/source/YamlHelper.h @@ -11,6 +11,7 @@ #define SS_YAML_KEY_TYPE "Type" #define SS_YAML_KEY_CARD "Card" #define SS_YAML_KEY_STATE "State" +#define SS_YAML_KEY_DEVICE "Device" #define SS_YAML_VALUE_AWSS "AppleWin Save State"