From d612972e6cde9a8cc7d0f091ff09635d2e0d0271 Mon Sep 17 00:00:00 2001 From: tomcw Date: Sun, 26 Feb 2023 20:42:21 +0000 Subject: [PATCH] Add command line support for hard disk controller (hdc) in slot-5 (#1033) . -s5 hdc . -s5h1 NB. No GUI config support, so no way to plug/unplug HDDs. --- source/CmdLine.cpp | 23 ++++++++++++++++++++--- source/CmdLine.h | 6 +++--- source/Harddisk.cpp | 2 +- source/Utilities.cpp | 22 ++++++++++++---------- source/Utilities.h | 2 +- source/Windows/AppleWin.cpp | 13 +++++++++++-- 6 files changed, 48 insertions(+), 20 deletions(-) diff --git a/source/CmdLine.cpp b/source/CmdLine.cpp index 4930ecce..9dfe9265 100644 --- a/source/CmdLine.cpp +++ b/source/CmdLine.cpp @@ -148,13 +148,13 @@ bool ProcessCmdLine(LPSTR lpCmdLine) { lpCmdLine = GetCurrArg(lpNextArg); lpNextArg = GetNextArg(lpNextArg); - g_cmdLine.szImageName_harddisk[HARDDISK_1] = lpCmdLine; + g_cmdLine.szImageName_harddisk[SLOT7][HARDDISK_1] = lpCmdLine; } else if (strcmp(lpCmdLine, "-h2") == 0) { lpCmdLine = GetCurrArg(lpNextArg); lpNextArg = GetNextArg(lpNextArg); - g_cmdLine.szImageName_harddisk[HARDDISK_2] = lpCmdLine; + g_cmdLine.szImageName_harddisk[SLOT7][HARDDISK_2] = lpCmdLine; } else if (lpCmdLine[0] == '-' && lpCmdLine[1] == 's' && lpCmdLine[2] >= '1' && lpCmdLine[2] <= '7') { @@ -173,6 +173,8 @@ bool ProcessCmdLine(LPSTR lpCmdLine) g_cmdLine.slotInsert[slot] = CT_Disk2; g_cmdLine.slotInfo[slot].isDiskII13 = true; } + if (strcmp(lpCmdLine, "hdc") == 0) + g_cmdLine.slotInsert[slot] = CT_GenericHDD; if (strcmp(lpCmdLine, "parallel") == 0) { if (slot == SLOT1) @@ -199,7 +201,7 @@ bool ProcessCmdLine(LPSTR lpCmdLine) { const UINT drive = lpCmdLine[4] == '1' ? DRIVE_1 : DRIVE_2; - if (slot != 5 && slot != 6) + if (slot != SLOT5 && slot != SLOT6) { LogFileOutput("Unsupported arg: %s\n", lpCmdLine); } @@ -210,6 +212,21 @@ bool ProcessCmdLine(LPSTR lpCmdLine) g_cmdLine.szImageName_drive[slot][drive] = lpCmdLine; } } + else if (lpCmdLine[3] == 'h' && (lpCmdLine[4] == '1' || lpCmdLine[4] == '2')) // -s[1..7]h[1|2] + { + const UINT drive = lpCmdLine[4] == '1' ? HARDDISK_1 : HARDDISK_2; + + if (slot != SLOT5 && slot != SLOT7) + { + LogFileOutput("Unsupported arg: %s\n", lpCmdLine); + } + else + { + lpCmdLine = GetCurrArg(lpNextArg); + lpNextArg = GetNextArg(lpNextArg); + g_cmdLine.szImageName_harddisk[slot][drive] = lpCmdLine; + } + } else if (strcmp(lpCmdLine, "-s7-empty-on-exit") == 0) { g_cmdLine.bSlot7EmptyOnExit = true; diff --git a/source/CmdLine.h b/source/CmdLine.h index 87b2b7de..b5cf2b66 100644 --- a/source/CmdLine.h +++ b/source/CmdLine.h @@ -33,8 +33,6 @@ struct CmdLine supportDCD = false; enableDumpToRealPrinter = false; noDisk2StepperDefer = false; - szImageName_harddisk[HARDDISK_1] = NULL; - szImageName_harddisk[HARDDISK_2] = NULL; szSnapshotName = NULL; szScreenshotFilename = NULL; uRamWorksExPages = 0; @@ -60,6 +58,8 @@ struct CmdLine szImageName_drive[i][DRIVE_2] = NULL; driveConnected[i][DRIVE_1] = true; driveConnected[i][DRIVE_2] = true; + szImageName_harddisk[i][HARDDISK_1] = NULL; + szImageName_harddisk[i][HARDDISK_2] = NULL; } } @@ -79,7 +79,7 @@ struct CmdLine SlotInfo slotInfo[NUM_SLOTS]; LPCSTR szImageName_drive[NUM_SLOTS][NUM_DRIVES]; bool driveConnected[NUM_SLOTS][NUM_DRIVES]; - LPCSTR szImageName_harddisk[NUM_HARDDISKS]; + LPCSTR szImageName_harddisk[NUM_SLOTS][NUM_HARDDISKS]; LPSTR szSnapshotName; LPSTR szScreenshotFilename; UINT uRamWorksExPages; diff --git a/source/Harddisk.cpp b/source/Harddisk.cpp index 84e0b52c..0869673c 100644 --- a/source/Harddisk.cpp +++ b/source/Harddisk.cpp @@ -129,7 +129,7 @@ Overview HarddiskInterfaceCard::HarddiskInterfaceCard(UINT slot) : Card(CT_GenericHDD, slot) { - if (m_slot != SLOT7) // fixme + if (m_slot != SLOT5 && m_slot != SLOT7) // fixme ThrowErrorInvalidSlot(); m_unitNum = HARDDISK_1 << 7; // b7=unit diff --git a/source/Utilities.cpp b/source/Utilities.cpp index f01e0b67..eab7d227 100644 --- a/source/Utilities.cpp +++ b/source/Utilities.cpp @@ -371,22 +371,22 @@ static bool DoDiskInsert(const UINT slot, const int nDrive, LPCSTR szFileName) return res; } -static bool DoHardDiskInsert(const int nDrive, LPCSTR szFileName) +static bool DoHardDiskInsert(const UINT slot, const int nDrive, LPCSTR szFileName) { - _ASSERT(GetCardMgr().QuerySlot(SLOT7) == CT_GenericHDD); - if (GetCardMgr().QuerySlot(SLOT7) != CT_GenericHDD) + _ASSERT(GetCardMgr().QuerySlot(slot) == CT_GenericHDD); + if (GetCardMgr().QuerySlot(slot) != CT_GenericHDD) return false; if (szFileName[0] == '\0') { - dynamic_cast(GetCardMgr().GetRef(SLOT7)).Unplug(nDrive); + dynamic_cast(GetCardMgr().GetRef(slot)).Unplug(nDrive); return true; } std::string strPathName = GetFullPath(szFileName); if (strPathName.empty()) return false; - BOOL bRes = dynamic_cast(GetCardMgr().GetRef(SLOT7)).Insert(nDrive, strPathName); + BOOL bRes = dynamic_cast(GetCardMgr().GetRef(slot)).Insert(nDrive, strPathName); bool res = (bRes == TRUE); if (res) SetCurrentDir(strPathName); @@ -425,19 +425,21 @@ void InsertFloppyDisks(const UINT slot, LPCSTR szImageName_drive[NUM_DRIVES], bo GetFrame().FrameMessageBox("Failed to insert floppy disk(s) - see log file", "Warning", MB_ICONASTERISK | MB_OK); } -void InsertHardDisks(LPCSTR szImageName_harddisk[NUM_HARDDISKS], bool& bBoot) +void InsertHardDisks(const UINT slot, LPCSTR szImageName_harddisk[NUM_HARDDISKS], bool& bBoot) { + _ASSERT(slot == 5 || slot == 7); + if (!szImageName_harddisk[HARDDISK_1] && !szImageName_harddisk[HARDDISK_2]) return; - if (GetCardMgr().QuerySlot(SLOT7) != CT_GenericHDD) - GetCardMgr().Insert(SLOT7, CT_GenericHDD); // Enable the Harddisk controller card + if (GetCardMgr().QuerySlot(slot) != CT_GenericHDD) + GetCardMgr().Insert(slot, CT_GenericHDD); // Enable the Harddisk controller card bool bRes = true; if (szImageName_harddisk[HARDDISK_1]) { - bRes = DoHardDiskInsert(HARDDISK_1, szImageName_harddisk[HARDDISK_1]); + bRes = DoHardDiskInsert(slot, HARDDISK_1, szImageName_harddisk[HARDDISK_1]); LogFileOutput("Init: DoHardDiskInsert(HDD1), res=%d\n", bRes); GetFrame().FrameRefreshStatus(DRAW_LEDS | DRAW_DISK_STATUS); // harddisk activity LED bBoot = true; @@ -445,7 +447,7 @@ void InsertHardDisks(LPCSTR szImageName_harddisk[NUM_HARDDISKS], bool& bBoot) if (szImageName_harddisk[HARDDISK_2]) { - bRes &= DoHardDiskInsert(HARDDISK_2, szImageName_harddisk[HARDDISK_2]); + bRes &= DoHardDiskInsert(slot, HARDDISK_2, szImageName_harddisk[HARDDISK_2]); LogFileOutput("Init: DoHardDiskInsert(HDD2), res=%d\n", bRes); } diff --git a/source/Utilities.h b/source/Utilities.h index 460e8366..ccb6aa08 100644 --- a/source/Utilities.h +++ b/source/Utilities.h @@ -6,7 +6,7 @@ void LoadConfiguration(bool loadImages); void InsertFloppyDisks(const UINT slot, LPCSTR szImageName_drive[NUM_DRIVES], bool driveConnected[NUM_DRIVES], bool& bBoot); -void InsertHardDisks(LPCSTR szImageName_harddisk[NUM_HARDDISKS], bool& bBoot); +void InsertHardDisks(const UINT slot, LPCSTR szImageName_harddisk[NUM_HARDDISKS], bool& bBoot); void GetAppleWindowTitle(); void CtrlReset(); diff --git a/source/Windows/AppleWin.cpp b/source/Windows/AppleWin.cpp index 5cc2a607..726a3116 100644 --- a/source/Windows/AppleWin.cpp +++ b/source/Windows/AppleWin.cpp @@ -787,6 +787,12 @@ static void RepeatInitialization(void) GetCardMgr().Insert(SLOT6, g_cmdLine.slotInsert[SLOT6]); } + if (g_cmdLine.slotInsert[SLOT7] != CT_Empty) + { + if (GetCardMgr().QuerySlot(SLOT7) != CT_GenericHDD) // Ignore if already got HDC in slot 7 + GetCardMgr().Insert(SLOT7, g_cmdLine.slotInsert[SLOT7]); + } + for (UINT i = SLOT0; i < NUM_SLOTS; i++) { if (GetCardMgr().QuerySlot(i) == CT_Disk2 && g_cmdLine.slotInfo[i].isDiskII13) @@ -835,8 +841,11 @@ static void RepeatInitialization(void) InsertFloppyDisks(SLOT6, g_cmdLine.szImageName_drive[SLOT6], g_cmdLine.driveConnected[SLOT6], g_cmdLine.bBoot); g_cmdLine.szImageName_drive[SLOT6][DRIVE_1] = g_cmdLine.szImageName_drive[SLOT6][DRIVE_2] = NULL; // Don't insert on a restart - InsertHardDisks(g_cmdLine.szImageName_harddisk, g_cmdLine.bBoot); - g_cmdLine.szImageName_harddisk[HARDDISK_1] = g_cmdLine.szImageName_harddisk[HARDDISK_2] = NULL; // Don't insert on a restart + InsertHardDisks(SLOT5, g_cmdLine.szImageName_harddisk[SLOT5], temp); + g_cmdLine.szImageName_harddisk[SLOT5][HARDDISK_1] = g_cmdLine.szImageName_harddisk[SLOT5][HARDDISK_2] = NULL; // Don't insert on a restart + + InsertHardDisks(SLOT7, g_cmdLine.szImageName_harddisk[SLOT7], g_cmdLine.bBoot); + g_cmdLine.szImageName_harddisk[SLOT7][HARDDISK_1] = g_cmdLine.szImageName_harddisk[SLOT7][HARDDISK_2] = NULL; // Don't insert on a restart if (g_cmdLine.bSlotEmpty[SLOT7]) {