From 57ba330072b7a55c37c89bb3ed7f48096e2e1ff7 Mon Sep 17 00:00:00 2001 From: TomCh Date: Wed, 21 Aug 2024 22:15:34 +0100 Subject: [PATCH] Support Hayden dongle (#1312, PR #1325) --- source/Configuration/PageAdvanced.cpp | 3 ++- source/CopyProtectionDongles.cpp | 32 +++++++++++++++++++++++++-- source/CopyProtectionDongles.h | 4 ++-- source/SaveState.cpp | 5 +++-- 4 files changed, 37 insertions(+), 7 deletions(-) diff --git a/source/Configuration/PageAdvanced.cpp b/source/Configuration/PageAdvanced.cpp index acbcf0cd..64f6c4b6 100644 --- a/source/Configuration/PageAdvanced.cpp +++ b/source/Configuration/PageAdvanced.cpp @@ -50,7 +50,8 @@ const TCHAR CPageAdvanced::m_gameIOConnectorChoices[] = "Cortechs Corp - CodeWriter\0" /* Protection key for Dynatech Microsoftware / Cortechs Corp "CodeWriter" */ "Robocom Ltd - Robo 500\0" /* Interface Module for Robocom Ltd's Robo 500 */ "Robocom Ltd - Robo 1000\0" /* Interface Module for Robocom Ltd's Robo 1000 */ - "Robocom Ltd - Robo 1500, CAD-2P\0"; /* Interface Module for Robocom Ltd's Robo 1500, Robo Systems CAD-2P */ + "Robocom Ltd - Robo 1500, CAD-2P\0" /* Interface Module for Robocom Ltd's Robo 1500, Robo Systems CAD-2P */ + "Hayden - Applesoft Compiler\0"; /* Protection key for Hayden's Applsoft Compiler (1981) */ INT_PTR CALLBACK CPageAdvanced::DlgProc(HWND hWnd, UINT message, WPARAM wparam, LPARAM lparam) diff --git a/source/CopyProtectionDongles.cpp b/source/CopyProtectionDongles.cpp index a39e574a..91741aff 100644 --- a/source/CopyProtectionDongles.cpp +++ b/source/CopyProtectionDongles.cpp @@ -29,6 +29,7 @@ - Southwestern Data Systems' datakey for SpeedStar Applesoft Compiler (Matthew D'Asaro Dec 2022) - Dynatech Microsoftware / Cortechs Corp's protection key for "CodeWriter" - Robocom Ltd's Interface Module for Robo Graphics 500/1000/1500 & RoboCAD 1/2 (BitStik joystick plugs in on top) + - Hayden's protection key for "Applesoft Compiler" */ #include "StdAfx.h" #include @@ -96,6 +97,9 @@ int CopyProtectionDonglePB0(void) // Returns the copy protection dongle state of PB1. A return value of -1 means not used by copy protection dongle int CopyProtectionDonglePB1(void) { + if (copyProtectionDongleType == DT_HAYDENCOMPILER) + return 0; // connected to GND + return -1; } @@ -118,6 +122,15 @@ int CopyProtectionDonglePB2(void) // Returns the copy protection dongle state of PDL(n). A return value of -1 means not used by copy protection dongle int CopyProtectionDonglePDL(UINT pdl) { + if (copyProtectionDongleType == DT_HAYDENCOMPILER && pdl == 3) + { + static BYTE haydenValue[4] = {0xFF, 0x96, 0x96, 0x50}; // Derived from reverse-engineered Hayden code - although other than 0xFF, actual values are unknown. + UINT haydenDongleMode = ((UINT)MemGetAnnunciator(2) << 1) | (UINT)MemGetAnnunciator(0); + return haydenValue[haydenDongleMode]; + } + + // + if (copyProtectionDongleType != DT_ROBOCOM500 && copyProtectionDongleType != DT_ROBOCOM1000 && copyProtectionDongleType != DT_ROBOCOM1500) return -1; @@ -162,7 +175,7 @@ int CopyProtectionDonglePDL(UINT pdl) // 1: Add SDS SpeedStar dongle // 2: Add Cortechs Corp CodeWriter protection key // Add Robocom Ltd - Robo 500/1000/1500 Interface Modules -static const UINT kUNIT_VERSION = 2; +// 3: Add Hayden Compiler protection key static const std::string& GetSnapshotStructName_SDSSpeedStar(void) { @@ -194,6 +207,12 @@ static const std::string& GetSnapshotStructName_Robocom1500(void) return name; } +static const std::string& GetSnapshotStructName_HaydenCompiler(void) +{ + static const std::string name("Hayden - Applesoft Compiler protection key"); + return name; +} + void CopyProtectionDongleSaveSnapshot(YamlSaveHelper& yamlSaveHelper) { if (copyProtectionDongleType == DT_SDSSPEEDSTAR) @@ -221,13 +240,18 @@ void CopyProtectionDongleSaveSnapshot(YamlSaveHelper& yamlSaveHelper) yamlSaveHelper.SaveString(SS_YAML_KEY_DEVICE, GetSnapshotStructName_Robocom1500()); // NB. No state for this dongle } + else if (copyProtectionDongleType == DT_HAYDENCOMPILER) + { + yamlSaveHelper.SaveString(SS_YAML_KEY_DEVICE, GetSnapshotStructName_HaydenCompiler()); + // NB. No state for this dongle + } else { _ASSERT(0); } } -void CopyProtectionDongleLoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT version) +void CopyProtectionDongleLoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT version, UINT kUNIT_VERSION) { if (version < 1 || version > kUNIT_VERSION) { @@ -261,6 +285,10 @@ void CopyProtectionDongleLoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT versi { copyProtectionDongleType = DT_ROBOCOM1500; } + else if (device == GetSnapshotStructName_HaydenCompiler()) + { + copyProtectionDongleType = DT_HAYDENCOMPILER; + } else { _ASSERT(0); diff --git a/source/CopyProtectionDongles.h b/source/CopyProtectionDongles.h index b5276002..cec4729a 100644 --- a/source/CopyProtectionDongles.h +++ b/source/CopyProtectionDongles.h @@ -3,7 +3,7 @@ #include "Common.h" // Must be in the same order as in PageAdvanced.cpp -enum DONGLETYPE { DT_EMPTY, DT_SDSSPEEDSTAR, DT_CODEWRITER, DT_ROBOCOM500, DT_ROBOCOM1000, DT_ROBOCOM1500 }; +enum DONGLETYPE { DT_EMPTY, DT_SDSSPEEDSTAR, DT_CODEWRITER, DT_ROBOCOM500, DT_ROBOCOM1000, DT_ROBOCOM1500, DT_HAYDENCOMPILER }; void SetCopyProtectionDongleType(DONGLETYPE type); DONGLETYPE GetCopyProtectionDongleType(void); @@ -14,4 +14,4 @@ int CopyProtectionDonglePB2(void); int CopyProtectionDonglePDL(UINT pdl); void CopyProtectionDongleSaveSnapshot(class YamlSaveHelper& yamlSaveHelper); -void CopyProtectionDongleLoadSnapshot(class YamlLoadHelper& yamlLoadHelper, UINT version); +void CopyProtectionDongleLoadSnapshot(class YamlLoadHelper& yamlLoadHelper, UINT version, UINT kUNIT_VERSION); diff --git a/source/SaveState.cpp b/source/SaveState.cpp index bce5f697..e912a0ef 100644 --- a/source/SaveState.cpp +++ b/source/SaveState.cpp @@ -72,7 +72,8 @@ static YamlHelper yamlHelper; #define UNIT_SLOTS_VER 1 -#define UNIT_GAME_IO_CONNECTOR_VER 1 +// See CopyProtectionDongle.cppS +#define UNIT_GAME_IO_CONNECTOR_VER 3 #define UNIT_MISC_VER 1 @@ -341,7 +342,7 @@ static void ParseUnit(void) } else if (unit == GetSnapshotUnitGameIOConnectorName()) { - CopyProtectionDongleLoadSnapshot(yamlLoadHelper, unitVersion); + CopyProtectionDongleLoadSnapshot(yamlLoadHelper, unitVersion, UNIT_GAME_IO_CONNECTOR_VER); } else if (unit == GetSnapshotUnitMiscName()) {