Support Cortechs Corp CodeWriter protection key (#1205)

This commit is contained in:
TomCh
2023-03-31 12:01:19 +01:00
committed by GitHub
parent 48f4a03e6c
commit 7aef95f071
5 changed files with 69 additions and 13 deletions
+60 -7
View File
@@ -4,7 +4,7 @@
Copyright (C) 1994-1996, Michael O'Brien
Copyright (C) 1999-2001, Oliver Schmidt
Copyright (C) 2002-2005, Tom Charlesworth
Copyright (C) 2006-2022, Tom Charlesworth, Michael Pohoreski
Copyright (C) 2006-2023, Tom Charlesworth, Michael Pohoreski
AppleWin is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -26,9 +26,8 @@
Emulate hardware copy protection dongles for Apple II
Currently supported:
- Southwestern Data Systems DataKey for SpeedStar Applesoft Compiler
Matthew D'Asaro Dec 2022
- Southwestern Data Systems DataKey for SpeedStar Applesoft Compiler (Matthew D'Asaro Dec 2022)
- Dynatech Microsoftware / Cortechs Corp protection key for "CodeWriter"
*/
#include "StdAfx.h"
#include <sstream>
@@ -39,6 +38,20 @@
static DONGLETYPE copyProtectionDongleType = DT_EMPTY;
static const BYTE codewriterInitialLFSR = 0x6B; // %1101011 (7-bit LFSR)
static BYTE codewriterLFSR = codewriterInitialLFSR;
static void codeWriterResetLFSR()
{
codewriterLFSR = codewriterInitialLFSR;
}
static void codeWriterClockLFSR()
{
BYTE bit = ((codewriterLFSR >> 1) ^ (codewriterLFSR >> 0)) & 1;
codewriterLFSR = (codewriterLFSR >> 1) | (bit << 6);
}
void SetCopyProtectionDongleType(DONGLETYPE type)
{
copyProtectionDongleType = type;
@@ -49,9 +62,26 @@ DONGLETYPE GetCopyProtectionDongleType(void)
return copyProtectionDongleType;
}
void DongleControl(WORD address)
{
UINT AN = ((address - 8) >> 1) & 7;
bool state = address & 1; // ie. C058 = AN0_off; C059 = AN0_on
if (copyProtectionDongleType == DT_EMPTY || copyProtectionDongleType == DT_SDSSPEEDSTAR)
return;
if (copyProtectionDongleType == DT_CODEWRITER)
{
if ((AN == 3 && state == true) || MemGetAnnunciator(3)) // reset or was already reset? (ie. takes precedent over AN2)
codeWriterResetLFSR();
else if (AN == 2 && state == false && MemGetAnnunciator(2) == true) // AN2 true->false edge?
codeWriterClockLFSR();
}
}
// This protection dongle consists of a NAND gate connected with AN1 and AN2 on the inputs
// PB2 on the output, and AN0 connected to power it.
bool SdsSpeedStar(void)
static bool SdsSpeedStar(void)
{
return !MemGetAnnunciator(0) || !(MemGetAnnunciator(1) && MemGetAnnunciator(2));
}
@@ -75,7 +105,9 @@ int CopyProtectionDonglePB2(void)
{
case DT_SDSSPEEDSTAR: // Southwestern Data Systems DataKey for SpeedStar Applesoft Compiler
return SdsSpeedStar();
break;
case DT_CODEWRITER: // Dynatech Microsoftware / Cortechs Corp protection key for "CodeWriter"
return codewriterLFSR & 1;
default:
return -1;
@@ -85,7 +117,12 @@ int CopyProtectionDonglePB2(void)
//===========================================================================
static const UINT kUNIT_VERSION = 1;
#define SS_YAML_KEY_CODEWRITER_INDEX "LFSR"
// Unit version history:
// 1: Add SDS SpeedStar dongle
// 2: Add Cortechs Corp CodeWriter protection key
static const UINT kUNIT_VERSION = 2;
static const std::string& GetSnapshotStructName_SDSSpeedStar(void)
{
@@ -93,6 +130,12 @@ static const std::string& GetSnapshotStructName_SDSSpeedStar(void)
return name;
}
static const std::string& GetSnapshotStructName_CodeWriter(void)
{
static const std::string name("Cortechs Corp CodeWriter protection key");
return name;
}
void CopyProtectionDongleSaveSnapshot(YamlSaveHelper& yamlSaveHelper)
{
if (copyProtectionDongleType == DT_SDSSPEEDSTAR)
@@ -100,6 +143,11 @@ void CopyProtectionDongleSaveSnapshot(YamlSaveHelper& yamlSaveHelper)
yamlSaveHelper.SaveString(SS_YAML_KEY_DEVICE, GetSnapshotStructName_SDSSpeedStar());
// NB. No state for this dongle
}
else if (copyProtectionDongleType == DT_CODEWRITER)
{
yamlSaveHelper.SaveString(SS_YAML_KEY_DEVICE, GetSnapshotStructName_CodeWriter());
yamlSaveHelper.SaveHexUint8(SS_YAML_KEY_CODEWRITER_INDEX, codewriterLFSR);
}
else
{
_ASSERT(0);
@@ -123,6 +171,11 @@ void CopyProtectionDongleLoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT versi
{
copyProtectionDongleType = DT_SDSSPEEDSTAR;
}
else if (device == GetSnapshotStructName_CodeWriter())
{
copyProtectionDongleType = DT_CODEWRITER;
codewriterLFSR = yamlLoadHelper.LoadUint(SS_YAML_KEY_CODEWRITER_INDEX);
}
else
{
_ASSERT(0);