From e5a87b506384391d6d1f41a7aa55eb3ab9d4d0c6 Mon Sep 17 00:00:00 2001
From: Matthew D'Asaro <63818343+medasaro@users.noreply.github.com>
Date: Fri, 16 Dec 2022 01:04:29 -0800
Subject: [PATCH] Add support for hardware copy protection dongles in game i/o
socket (#1153, PR #1154)
Changes:
- Add a drop-down menu to the 'Advanced' tab that lets the user select a dongle in use
- Add a new file "CopyProtectionDongles.cpp" that is a place to put drivers for these.
- Add a driver for the one known dongle we have now - Speed Star
- Modify Joystick.cpp to allow PB0-PB2 to be "pushed" by the protection dongle.
---
AppleWinExpress2019.vcxproj | 2 +
AppleWinExpress2019.vcxproj.filters | 6 ++
resource/Applewin.rc | 2 +
resource/resource.h | 3 +-
source/Common.h | 1 +
source/Configuration/PageAdvanced.cpp | 24 ++++++++
source/Configuration/PageAdvanced.h | 2 +
source/CopyProtectionDongles.cpp | 85 +++++++++++++++++++++++++++
source/CopyProtectionDongles.h | 11 ++++
source/Joystick.cpp | 9 ++-
source/Memory.cpp | 1 +
source/Utilities.cpp | 8 +++
12 files changed, 152 insertions(+), 2 deletions(-)
create mode 100644 source/CopyProtectionDongles.cpp
create mode 100644 source/CopyProtectionDongles.h
diff --git a/AppleWinExpress2019.vcxproj b/AppleWinExpress2019.vcxproj
index 94c69529..caabd4ce 100644
--- a/AppleWinExpress2019.vcxproj
+++ b/AppleWinExpress2019.vcxproj
@@ -53,6 +53,7 @@
+
@@ -167,6 +168,7 @@
+
diff --git a/AppleWinExpress2019.vcxproj.filters b/AppleWinExpress2019.vcxproj.filters
index d6419dda..67636af7 100644
--- a/AppleWinExpress2019.vcxproj.filters
+++ b/AppleWinExpress2019.vcxproj.filters
@@ -268,6 +268,9 @@
Source Files\Configuration
+
+ Source Files
+
@@ -609,6 +612,9 @@
Source Files\Uthernet
+
+ Source Files
+
diff --git a/resource/Applewin.rc b/resource/Applewin.rc
index 7c563bfc..26de9f3d 100644
--- a/resource/Applewin.rc
+++ b/resource/Applewin.rc
@@ -256,6 +256,8 @@ BEGIN
COMBOBOX IDC_CLONETYPE,35,185,100,100,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
CONTROL "The Free&ze's non-autostart F8 rom (Apple ][ or ][+ only)",IDC_THE_FREEZES_F8_ROM_FW,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,10,201,194,10
+ LTEXT "&Copy Protection Dongle:",IDC_STATIC,5,220,82,8
+ COMBOBOX IDC_COMBO_CP_DONGLE,89,218,100,100,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
END
diff --git a/resource/resource.h b/resource/resource.h
index 94ef1002..d230cb09 100644
--- a/resource/resource.h
+++ b/resource/resource.h
@@ -113,6 +113,7 @@
#define IDC_COMBO_DISK1 1080
#define IDC_COMBO_DISK2 1081
#define IDC_CHECK_FS_SHOW_SUBUNIT_STATUS 1082
+#define IDC_COMBO_CP_DONGLE 1082
#define IDC_CHECK_VERTICAL_BLEND 1083
#define IDC_CHECK_50HZ_VIDEO 1084
#define IDC_COMBO_DISK1_SLOT5 1085
@@ -137,7 +138,7 @@
#define _APS_NO_MFC 1
#define _APS_NEXT_RESOURCE_VALUE 149
#define _APS_NEXT_COMMAND_VALUE 40012
-#define _APS_NEXT_CONTROL_VALUE 1082
+#define _APS_NEXT_CONTROL_VALUE 1083
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
diff --git a/source/Common.h b/source/Common.h
index 6047aa54..70940355 100644
--- a/source/Common.h
+++ b/source/Common.h
@@ -73,6 +73,7 @@ enum AppMode_e
#define REGVALUE_MB_VOLUME "Mockingboard Volume"
#define REGVALUE_SAVESTATE_FILENAME "Save State Filename"
#define REGVALUE_SAVE_STATE_ON_EXIT "Save State On Exit"
+#define REGVALUE_COPYPROTECTIONDONGLE_TYPE "Copy Protection Dongle Type"
#define REGVALUE_HDD_ENABLED "Harddisk Enable" // Deprecated from 1.30.5
#define REGVALUE_JOYSTICK0_EMU_TYPE "Joystick0 Emu Type v3" // GH#434: Added at 1.26.3.0 (previously was "Joystick0 Emu Type")
#define REGVALUE_JOYSTICK1_EMU_TYPE "Joystick1 Emu Type v3" // GH#434: Added at 1.26.3.0 (previously was "Joystick1 Emu Type")
diff --git a/source/Configuration/PageAdvanced.cpp b/source/Configuration/PageAdvanced.cpp
index ea98579d..1ea6e885 100644
--- a/source/Configuration/PageAdvanced.cpp
+++ b/source/Configuration/PageAdvanced.cpp
@@ -31,6 +31,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "../Registry.h"
#include "../SaveState.h"
#include "../CardManager.h"
+#include "../CopyProtectionDongles.h"
#include "../resource/resource.h"
CPageAdvanced* CPageAdvanced::ms_this = 0; // reinit'd in ctor
@@ -43,6 +44,11 @@ const TCHAR CPageAdvanced::m_CloneChoices[] =
TEXT("TK3000 //e\0") // Brazilian
TEXT("Base 64A\0"); // Taiwanese
+enum COPYPROTECTIONDONGLECHOICE { MENUITEM_NONE, MENUITEM_SPEEDSTAR };
+const TCHAR CPageAdvanced::m_CopyProtectionDongleChoices[] =
+ TEXT("None\0")
+ TEXT("SDS DataKey - Speed Star\0"); // Protection dongle for Southwestern Data Systems "Speed Star" Applesoft Compiler
+
INT_PTR CALLBACK CPageAdvanced::DlgProc(HWND hWnd, UINT message, WPARAM wparam, LPARAM lparam)
{
@@ -123,6 +129,13 @@ INT_PTR CPageAdvanced::DlgProcInternal(HWND hWnd, UINT message, WPARAM wparam, L
m_PropertySheetHelper.GetConfigNew().m_Apple2Type = NewCloneType;
m_PropertySheetHelper.GetConfigNew().m_CpuType = ProbeMainCpuDefault(NewCloneType);
}
+
+ case IDC_COMBO_CP_DONGLE:
+ if (HIWORD(wparam) == CBN_SELCHANGE)
+ {
+ const DWORD NewCopyProtectionDongleMenuItem = (DWORD)SendDlgItemMessage(hWnd, IDC_COMBO_CP_DONGLE, CB_GETCURSEL, 0, 0);
+ SetCopyProtectionDongleType(NewCopyProtectionDongleMenuItem);
+ }
break;
}
break;
@@ -179,6 +192,9 @@ void CPageAdvanced::DlgOK(HWND hWnd)
g_bSaveStateOnExit = IsDlgButtonChecked(hWnd, IDC_SAVESTATE_ON_EXIT) ? true : false;
REGSAVE(TEXT(REGVALUE_SAVE_STATE_ON_EXIT), g_bSaveStateOnExit ? 1 : 0);
+ // Save the copy protection dongle type
+ REGSAVE(TEXT(REGVALUE_COPYPROTECTIONDONGLE_TYPE), GetCopyProtectionDongleType());
+
if (GetCardMgr().IsParallelPrinterCardInstalled())
{
ParallelPrinterCard* card = GetCardMgr().GetParallelPrinterCard();
@@ -217,6 +233,7 @@ void CPageAdvanced::InitOptions(HWND hWnd)
{
InitFreezeDlgButton(hWnd);
InitCloneDropdownMenu(hWnd);
+ InitCopyProtectionDongleDropdownMenu(hWnd);
}
// Advanced->Clone: Menu item to eApple2Type
@@ -282,3 +299,10 @@ void CPageAdvanced::InitCloneDropdownMenu(HWND hWnd)
const bool bIsClone = IsClone( m_PropertySheetHelper.GetConfigNew().m_Apple2Type );
EnableWindow(GetDlgItem(hWnd, IDC_CLONETYPE), bIsClone ? TRUE : FALSE);
}
+
+void CPageAdvanced::InitCopyProtectionDongleDropdownMenu(HWND hWnd)
+{
+ // Set copy protection dongle menu choice
+ const int nCurrentChoice = GetCopyProtectionDongleType();
+ m_PropertySheetHelper.FillComboBox(hWnd, IDC_COMBO_CP_DONGLE, m_CopyProtectionDongleChoices, nCurrentChoice);
+}
diff --git a/source/Configuration/PageAdvanced.h b/source/Configuration/PageAdvanced.h
index d40b0794..ef59d157 100644
--- a/source/Configuration/PageAdvanced.h
+++ b/source/Configuration/PageAdvanced.h
@@ -35,9 +35,11 @@ private:
int GetCloneMenuItem(void);
void InitFreezeDlgButton(HWND hWnd);
void InitCloneDropdownMenu(HWND hWnd);
+ void InitCopyProtectionDongleDropdownMenu(HWND hWnd);
static CPageAdvanced* ms_this;
static const TCHAR m_CloneChoices[];
+ static const TCHAR m_CopyProtectionDongleChoices[];
const PAGETYPE m_Page;
CPropertySheetHelper& m_PropertySheetHelper;
diff --git a/source/CopyProtectionDongles.cpp b/source/CopyProtectionDongles.cpp
new file mode 100644
index 00000000..a26d6cd3
--- /dev/null
+++ b/source/CopyProtectionDongles.cpp
@@ -0,0 +1,85 @@
+/*
+ AppleWin : An Apple //e emulator for Windows
+
+ Copyright (C) 1994-1996, Michael O'Brien
+ Copyright (C) 1999-2001, Oliver Schmidt
+ Copyright (C) 2002-2005, Tom Charlesworth
+ Copyright (C) 2006-2007, 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
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ AppleWin is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with AppleWin; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+/*
+ CopyProtectionDongles.cpp
+
+ Emulate hardware copy protection dongles for Apple II
+
+ Currently supported:
+ - Southwestern Data Systems SoftKey for Speed Star Applesoft Compiler
+
+ Matthew D'Asaro Dec 2022
+*/
+#include "StdAfx.h"
+
+#include "CopyProtectionDongles.h"
+#include "Memory.h"
+
+static DWORD copyProtectionDongleType = 0;
+
+// Must be in the same order as in PageAdvanced.cpp
+enum COPYPROTECTIONDONGLETYPE { NONE, SDSSPEEDSTAR };
+
+void SetCopyProtectionDongleType(DWORD type)
+{
+ copyProtectionDongleType = type;
+}
+
+DWORD GetCopyProtectionDongleType(void)
+{
+ return copyProtectionDongleType;
+}
+
+// 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)
+{
+ return !MemGetAnnunciator(0) || !(MemGetAnnunciator(1) && MemGetAnnunciator(2));
+}
+
+// Returns the copy protection dongle state of PB0. A return value of -1 means not used by copy protection dongle
+int CopyProtectionDonglePB0(void)
+{
+ return -1;
+}
+
+// Returns the copy protection dongle state of PB1. A return value of -1 means not used by copy protection dongle
+int CopyProtectionDonglePB1(void)
+{
+ return -1;
+}
+
+// Returns the copy protection dongle state of PB2. A return value of -1 means not used by copy protection dongle
+int CopyProtectionDonglePB2(void)
+{
+ switch (copyProtectionDongleType)
+ {
+ case SDSSPEEDSTAR: // Southwestern Data Systems SoftKey for Speed Star Applesoft Compiler
+ return SdsSpeedStar();
+ break;
+
+ default:
+ return -1;
+ break;
+ }
+}
diff --git a/source/CopyProtectionDongles.h b/source/CopyProtectionDongles.h
new file mode 100644
index 00000000..4104c7ce
--- /dev/null
+++ b/source/CopyProtectionDongles.h
@@ -0,0 +1,11 @@
+#pragma once
+
+#include "Common.h"
+
+
+void SetCopyProtectionDongleType(DWORD type);
+DWORD GetCopyProtectionDongleType(void);
+int CopyProtectionDonglePB0(void);
+int CopyProtectionDonglePB1(void);
+int CopyProtectionDonglePB2(void);
+bool SdsSpeedStar(void);
diff --git a/source/Joystick.cpp b/source/Joystick.cpp
index 323c5dbd..a5239236 100644
--- a/source/Joystick.cpp
+++ b/source/Joystick.cpp
@@ -45,6 +45,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "Memory.h"
#include "YamlHelper.h"
#include "Interface.h"
+#include "CopyProtectionDongles.h"
#include "Configuration/PropertySheet.h"
@@ -576,6 +577,8 @@ BYTE __stdcall JoyReadButton(WORD pc, WORD address, BYTE, BYTE, ULONG nExecutedC
pressed = !swapButtons0and1 ? CheckButton0Pressed() : CheckButton1Pressed();
const UINT button0 = !swapButtons0and1 ? 0 : 1;
DoAutofire(button0, pressed);
+ if(CopyProtectionDonglePB0() >= 0) //If a copy protection dongle needs PB0, this overrides the joystick
+ pressed = CopyProtectionDonglePB0();
}
break;
@@ -584,11 +587,15 @@ BYTE __stdcall JoyReadButton(WORD pc, WORD address, BYTE, BYTE, ULONG nExecutedC
pressed = !swapButtons0and1 ? CheckButton1Pressed() : CheckButton0Pressed();
const UINT button1 = !swapButtons0and1 ? 1 : 0;
DoAutofire(button1, pressed);
+ if (CopyProtectionDonglePB1() >= 0) //If a copy protection dongle needs PB1, this overrides the joystick
+ pressed = CopyProtectionDonglePB1();
}
break;
case 0x63:
- if (IS_APPLE2 && (joyinfo[joytype[1]] == DEVICE_NONE))
+ if (CopyProtectionDonglePB2() >= 0) //If a copy protection dongle needs PB2, this overrides the joystick
+ pressed = CopyProtectionDonglePB2();
+ else if (IS_APPLE2 && (joyinfo[joytype[1]] == DEVICE_NONE))
{
// Apple II/II+ with no joystick has the "SHIFT key mod"
// See Sather's Understanding The Apple II p7-36
diff --git a/source/Memory.cpp b/source/Memory.cpp
index c5ed317b..0a9f349b 100644
--- a/source/Memory.cpp
+++ b/source/Memory.cpp
@@ -56,6 +56,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "Tape.h"
#include "RGBMonitor.h"
#include "VidHD.h"
+#include "CopyProtectionDongles.h"
#include "z80emu.h"
#include "Z80VICE/z80.h"
diff --git a/source/Utilities.cpp b/source/Utilities.cpp
index 5820b9bc..9c6106d4 100644
--- a/source/Utilities.cpp
+++ b/source/Utilities.cpp
@@ -47,6 +47,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "Mockingboard.h"
#include "Interface.h"
#include "SoundCore.h"
+#include "CopyProtectionDongles.h"
#include "Configuration/IPropertySheet.h"
#include "Tfe/PCapBackend.h"
@@ -167,6 +168,13 @@ void LoadConfiguration(bool loadImages)
else
LoadConfigOldJoystick_v1(JN_JOYSTICK1);
+
+ DWORD copyProtectionDongleType;
+ if (REGLOAD(TEXT(REGVALUE_COPYPROTECTIONDONGLE_TYPE), ©ProtectionDongleType))
+ SetCopyProtectionDongleType(copyProtectionDongleType);
+ else
+ SetCopyProtectionDongleType(0); // None
+
DWORD dwSoundType;
REGLOAD_DEFAULT(TEXT(REGVALUE_SOUND_EMULATION), &dwSoundType, REG_SOUNDTYPE_WAVE);
switch (dwSoundType)