diff --git a/bin/History.txt b/bin/History.txt index 0f0070f1..ca3cd42a 100644 --- a/bin/History.txt +++ b/bin/History.txt @@ -9,6 +9,12 @@ https://github.com/AppleWin/AppleWin/issues/new Tom Charlesworth +1.29.8.0 - ? +---------------------- +. Debugger: Changed 'cycles' to be configurable (either absolute or relative). + - extended debugger commmand: videoinfo + + 1.29.7.0 - 20 Dec 2019 ---------------------- . [Change #726] Disk II card: supported in slot 5 via '-s5 diskii' command line. diff --git a/source/Applewin.cpp b/source/Applewin.cpp index ebf779d8..8b972a94 100644 --- a/source/Applewin.cpp +++ b/source/Applewin.cpp @@ -80,6 +80,7 @@ HINSTANCE g_hInstance = (HINSTANCE)0; AppMode_e g_nAppMode = MODE_LOGO; static bool g_bLoadedSaveState = false; +static bool g_bSysClkOK = false; std::string g_sProgramDir; // Directory of where AppleWin executable resides std::string g_sDebugDir; // TODO: Not currently used @@ -433,6 +434,7 @@ void SetCurrentCLK6502(void) } //=========================================================================== + void EnterMessageLoop(void) { MSG message; @@ -1097,12 +1099,12 @@ static std::string GetFullPath(LPCSTR szFileName) static bool DoDiskInsert(const UINT slot, const int nDrive, LPCSTR szFileName) { - Disk2InterfaceCard* pDisk2Card = dynamic_cast (g_CardMgr.GetObj(slot)); + Disk2InterfaceCard& disk2Card = dynamic_cast(g_CardMgr.GetRef(slot)); std::string strPathName = GetFullPath(szFileName); if (strPathName.empty()) return false; - ImageError_e Error = pDisk2Card->InsertDisk(nDrive, strPathName.c_str(), IMAGE_USE_FILES_WRITE_PROTECT_STATUS, IMAGE_DONT_CREATE); + ImageError_e Error = disk2Card.InsertDisk(nDrive, strPathName.c_str(), IMAGE_USE_FILES_WRITE_PROTECT_STATUS, IMAGE_DONT_CREATE); return Error == eIMAGE_ERROR_NONE; } @@ -1218,40 +1220,146 @@ static bool CheckOldAppleWinVersion(void) //--------------------------------------------------------------------------- +static void ExceptionHandler(const char* pError) +{ + MessageBox( g_hFrameWindow, + pError, + TEXT("Runtime Exception"), + MB_ICONEXCLAMATION | MB_SETFOREGROUND); + + LogFileOutput("Runtime Exception: %s\n", pError); +} + +//--------------------------------------------------------------------------- + +static void ProcessCmdLine(LPSTR lpCmdLine); +static void GetAppleWinVersion(void); +static void OneTimeInitialization(HINSTANCE passinstance); +static void RepeatInitialization(void); +static void Shutdown(void); + +struct CmdLine +{ + CmdLine() + { + bShutdown = false; + bSetFullScreen = false; + bBoot = false; + bChangedDisplayResolution = false; + bSlot0LanguageCard = false; + bSlot7EmptyOnExit = false; + bestWidth = 0; + bestHeight = 0; + szImageName_harddisk[HARDDISK_1] = NULL; + szImageName_harddisk[HARDDISK_2] = NULL; + szSnapshotName = NULL; + szScreenshotFilename = NULL; + uRamWorksExPages = 0; + uSaturnBanks = 0; + newVideoType = -1; + newVideoStyleEnableMask = 0; + newVideoStyleDisableMask = 0; + newVideoRefreshRate = VR_NONE; + clockMultiplier = 0.0; // 0 => not set from cmd-line + model = A2TYPE_MAX; + + for (UINT i = 0; i < NUM_SLOTS; i++) + { + bSlotEmpty[i] = false; + slotInsert[i] = CT_Empty; + szImageName_drive[i][DRIVE_1] = NULL; + szImageName_drive[i][DRIVE_2] = NULL; + } + } + + bool bShutdown; + bool bSetFullScreen; + bool bBoot; + bool bChangedDisplayResolution; + bool bSlot0LanguageCard; + bool bSlotEmpty[NUM_SLOTS]; + bool bSlot7EmptyOnExit; + SS_CARDTYPE slotInsert[NUM_SLOTS]; + UINT bestWidth; + UINT bestHeight; + LPSTR szImageName_drive[NUM_SLOTS][NUM_DRIVES]; + LPSTR szImageName_harddisk[NUM_HARDDISKS]; + LPSTR szSnapshotName; + LPSTR szScreenshotFilename; + UINT uRamWorksExPages; + UINT uSaturnBanks; + int newVideoType; + int newVideoStyleEnableMask; + int newVideoStyleDisableMask; + VideoRefreshRate_e newVideoRefreshRate; + double clockMultiplier; + eApple2Type model; +}; + +static CmdLine g_cmdLine; + int APIENTRY WinMain(HINSTANCE passinstance, HINSTANCE, LPSTR lpCmdLine, int) { - bool bShutdown = false; - bool bSetFullScreen = false; - bool bBoot = false; - bool bChangedDisplayResolution = false; - bool bSlot0LanguageCard = false; - bool bSlotEmpty[NUM_SLOTS] = {}; - bool bSlot7EmptyOnExit = false; - SS_CARDTYPE slotInsert[NUM_SLOTS]; - UINT bestWidth = 0, bestHeight = 0; - const UINT SLOT5 = 5; - const UINT SLOT6 = 6; - LPSTR szImageName_drive[NUM_SLOTS][NUM_DRIVES] = {}; - LPSTR szImageName_harddisk[NUM_HARDDISKS] = {NULL,NULL}; - LPSTR szSnapshotName = NULL; - const std::string strCmdLine(lpCmdLine); // Keep a copy for log ouput - UINT uRamWorksExPages = 0; - UINT uSaturnBanks = 0; - int newVideoType = -1; - int newVideoStyleEnableMask = 0; - int newVideoStyleDisableMask = 0; - VideoRefreshRate_e newVideoRefreshRate = VR_NONE; - LPSTR szScreenshotFilename = NULL; - double clockMultiplier = 0.0; // 0 => not set from cmd-line - eApple2Type model = A2TYPE_MAX; + ProcessCmdLine(lpCmdLine); + GetAppleWinVersion(); + OneTimeInitialization(passinstance); - for (UINT i = 0; i < NUM_SLOTS; i++) + try { - bSlotEmpty[i] = false; - slotInsert[i] = CT_Empty; - szImageName_drive[i][DRIVE_1] = NULL; - szImageName_drive[i][DRIVE_2] = NULL; + do + { + g_bRestart = false; + + RepeatInitialization(); + + // ENTER THE MAIN MESSAGE LOOP + LogFileOutput("Main: EnterMessageLoop()\n"); + EnterMessageLoop(); + LogFileOutput("Main: LeaveMessageLoop()\n"); + + if (g_bRestart) + { + g_cmdLine.bSetFullScreen = g_bRestartFullScreen; + g_bRestartFullScreen = false; + } + + MB_Reset(); + LogFileOutput("Main: MB_Reset()\n"); + + CMouseInterface* pMouseCard = g_CardMgr.GetMouseCard(); + if (pMouseCard) + { + pMouseCard->Reset(); // Deassert any pending IRQs - GH#514 + LogFileOutput("Main: CMouseInterface::Uninitialize()\n"); + } + + DSUninit(); + LogFileOutput("Main: DSUninit()\n"); + + if (g_bHookSystemKey) + { + UninitHookThread(); + LogFileOutput("Main: UnhookFilterForKeyboard()\n"); + } + } + while (g_bRestart); } + catch(std::runtime_error exception) + { + ExceptionHandler(exception.what()); + } + catch(std::exception exception) + { + ExceptionHandler(exception.what()); + } + + Shutdown(); + return 0; +} + +static void ProcessCmdLine(LPSTR lpCmdLine) +{ + const std::string strCmdLine(lpCmdLine); // Keep a copy for log ouput while (*lpCmdLine) { @@ -1269,25 +1377,25 @@ int APIENTRY WinMain(HINSTANCE passinstance, HINSTANCE, LPSTR lpCmdLine, int) { lpCmdLine = GetCurrArg(lpNextArg); lpNextArg = GetNextArg(lpNextArg); - szImageName_drive[SLOT6][DRIVE_1] = lpCmdLine; + g_cmdLine.szImageName_drive[SLOT6][DRIVE_1] = lpCmdLine; } else if (strcmp(lpCmdLine, "-d2") == 0) { lpCmdLine = GetCurrArg(lpNextArg); lpNextArg = GetNextArg(lpNextArg); - szImageName_drive[SLOT6][DRIVE_2] = lpCmdLine; + g_cmdLine.szImageName_drive[SLOT6][DRIVE_2] = lpCmdLine; } else if (strcmp(lpCmdLine, "-h1") == 0) { lpCmdLine = GetCurrArg(lpNextArg); lpNextArg = GetNextArg(lpNextArg); - szImageName_harddisk[HARDDISK_1] = lpCmdLine; + g_cmdLine.szImageName_harddisk[HARDDISK_1] = lpCmdLine; } else if (strcmp(lpCmdLine, "-h2") == 0) { lpCmdLine = GetCurrArg(lpNextArg); lpNextArg = GetNextArg(lpNextArg); - szImageName_harddisk[HARDDISK_2] = lpCmdLine; + g_cmdLine.szImageName_harddisk[HARDDISK_2] = lpCmdLine; } else if (lpCmdLine[0] == '-' && lpCmdLine[1] == 's' && lpCmdLine[2] >= '1' && lpCmdLine[2] <= '7') { @@ -1298,9 +1406,9 @@ int APIENTRY WinMain(HINSTANCE passinstance, HINSTANCE, LPSTR lpCmdLine, int) lpCmdLine = GetCurrArg(lpNextArg); lpNextArg = GetNextArg(lpNextArg); if (strcmp(lpCmdLine, "empty") == 0) - bSlotEmpty[slot] = true; + g_cmdLine.bSlotEmpty[slot] = true; if (strcmp(lpCmdLine, "diskii") == 0) - slotInsert[slot] = CT_Disk2; + g_cmdLine.slotInsert[slot] = CT_Disk2; } else if (lpCmdLine[3] == 'd' && (lpCmdLine[4] == '1' || lpCmdLine[4] == '2')) // -s[1..7]d[1|2] { @@ -1314,7 +1422,7 @@ int APIENTRY WinMain(HINSTANCE passinstance, HINSTANCE, LPSTR lpCmdLine, int) { lpCmdLine = GetCurrArg(lpNextArg); lpNextArg = GetNextArg(lpNextArg); - szImageName_drive[slot][drive] = lpCmdLine; + g_cmdLine.szImageName_drive[slot][drive] = lpCmdLine; } } else @@ -1324,39 +1432,39 @@ int APIENTRY WinMain(HINSTANCE passinstance, HINSTANCE, LPSTR lpCmdLine, int) } else if (strcmp(lpCmdLine, "-s7-empty-on-exit") == 0) { - bSlot7EmptyOnExit = true; + g_cmdLine.bSlot7EmptyOnExit = true; } else if (strcmp(lpCmdLine, "-load-state") == 0) { lpCmdLine = GetCurrArg(lpNextArg); lpNextArg = GetNextArg(lpNextArg); - szSnapshotName = lpCmdLine; + g_cmdLine.szSnapshotName = lpCmdLine; } else if (strcmp(lpCmdLine, "-f") == 0) { - bSetFullScreen = true; + g_cmdLine.bSetFullScreen = true; } #define CMD_FS_HEIGHT "-fs-height=" else if (strncmp(lpCmdLine, CMD_FS_HEIGHT, sizeof(CMD_FS_HEIGHT)-1) == 0) { - bSetFullScreen = true; // Implied + g_cmdLine.bSetFullScreen = true; // Implied LPSTR lpTmp = lpCmdLine + sizeof(CMD_FS_HEIGHT)-1; bool bRes = false; if (strcmp(lpTmp, "best") == 0) { - bRes = GetBestDisplayResolutionForFullScreen(bestWidth, bestHeight); + bRes = GetBestDisplayResolutionForFullScreen(g_cmdLine.bestWidth, g_cmdLine.bestHeight); } else { UINT userSpecifiedHeight = atoi(lpTmp); if (userSpecifiedHeight) - bRes = GetBestDisplayResolutionForFullScreen(bestWidth, bestHeight, userSpecifiedHeight); + bRes = GetBestDisplayResolutionForFullScreen(g_cmdLine.bestWidth, g_cmdLine.bestHeight, userSpecifiedHeight); else LogFileOutput("Invalid cmd-line parameter for -fs-height=x switch\n"); } if (bRes) - LogFileOutput("Best resolution for -fs-height=x switch: Width=%d, Height=%d\n", bestWidth, bestHeight); + LogFileOutput("Best resolution for -fs-height=x switch: Width=%d, Height=%d\n", g_cmdLine.bestWidth, g_cmdLine.bestHeight); else LogFileOutput("Failed to set parameter for -fs-height=x switch\n"); } @@ -1388,12 +1496,12 @@ int APIENTRY WinMain(HINSTANCE passinstance, HINSTANCE, LPSTR lpCmdLine, int) { lpCmdLine = GetCurrArg(lpNextArg); lpNextArg = GetNextArg(lpNextArg); - uRamWorksExPages = atoi(lpCmdLine); - if (uRamWorksExPages > kMaxExMemoryBanks) - uRamWorksExPages = kMaxExMemoryBanks; + g_cmdLine.uRamWorksExPages = atoi(lpCmdLine); + if (g_cmdLine.uRamWorksExPages > kMaxExMemoryBanks) + g_cmdLine.uRamWorksExPages = kMaxExMemoryBanks; else - if (uRamWorksExPages < 1) - uRamWorksExPages = 1; + if (g_cmdLine.uRamWorksExPages < 1) + g_cmdLine.uRamWorksExPages = 1; } #endif else if (strcmp(lpCmdLine, "-s0") == 0) @@ -1402,11 +1510,11 @@ int APIENTRY WinMain(HINSTANCE passinstance, HINSTANCE, LPSTR lpCmdLine, int) lpNextArg = GetNextArg(lpNextArg); if (strcmp(lpCmdLine, "saturn") == 0 || strcmp(lpCmdLine, "saturn128") == 0) - uSaturnBanks = Saturn128K::kMaxSaturnBanks; + g_cmdLine.uSaturnBanks = Saturn128K::kMaxSaturnBanks; else if (strcmp(lpCmdLine, "saturn64") == 0) - uSaturnBanks = Saturn128K::kMaxSaturnBanks/2; + g_cmdLine.uSaturnBanks = Saturn128K::kMaxSaturnBanks/2; else if (strcmp(lpCmdLine, "languagecard") == 0 || strcmp(lpCmdLine, "lc") == 0) - bSlot0LanguageCard = true; + g_cmdLine.bSlot0LanguageCard = true; } else if (strcmp(lpCmdLine, "-f8rom") == 0) // Use custom 2K ROM at [$F800..$FFFF] { @@ -1468,6 +1576,20 @@ int APIENTRY WinMain(HINSTANCE passinstance, HINSTANCE, LPSTR lpCmdLine, int) { JoySetHookAltKeys(false); } + else if (strcmp(lpCmdLine, "-left-control-alt-buttons") == 0) + { + JoySetButtonVirtualKey(0, VK_CONTROL); + JoySetButtonVirtualKey(1, VK_MENU); + } + else if (strcmp(lpCmdLine, "-right-alt-control-buttons") == 0) + { + JoySetButtonVirtualKey(0, VK_MENU | KF_EXTENDED); + JoySetButtonVirtualKey(1, VK_CONTROL | KF_EXTENDED); + } + else if (strcmp(lpCmdLine, "-swap-buttons") == 0) + { + JoySwapButton0and1(true); + } else if (strcmp(lpCmdLine, "-spkr-inc") == 0) { lpCmdLine = GetCurrArg(lpNextArg); @@ -1509,15 +1631,15 @@ int APIENTRY WinMain(HINSTANCE passinstance, HINSTANCE, LPSTR lpCmdLine, int) } else if (strcmp(lpCmdLine, "-video-mode=rgb-monitor") == 0) // GH#616 { - newVideoType = VT_COLOR_MONITOR_RGB; + g_cmdLine.newVideoType = VT_COLOR_MONITOR_RGB; } else if (strcmp(lpCmdLine, "-video-style=vertical-blend") == 0) // GH#616 { - newVideoStyleEnableMask = VS_COLOR_VERTICAL_BLEND; + g_cmdLine.newVideoStyleEnableMask = VS_COLOR_VERTICAL_BLEND; } else if (strcmp(lpCmdLine, "-video-style=no-vertical-blend") == 0) // GH#616 { - newVideoStyleDisableMask = VS_COLOR_VERTICAL_BLEND; + g_cmdLine.newVideoStyleDisableMask = VS_COLOR_VERTICAL_BLEND; } else if (strcmp(lpCmdLine, "-rgb-card-invert-bit7") == 0) // GH#633 { @@ -1525,14 +1647,14 @@ int APIENTRY WinMain(HINSTANCE passinstance, HINSTANCE, LPSTR lpCmdLine, int) } else if (strcmp(lpCmdLine, "-screenshot-and-exit") == 0) // GH#616: For testing - Use in combination with -load-state { - szScreenshotFilename = GetCurrArg(lpNextArg); + g_cmdLine.szScreenshotFilename = GetCurrArg(lpNextArg); lpNextArg = GetNextArg(lpNextArg); } else if (strcmp(lpCmdLine, "-clock-multiplier") == 0) { lpCmdLine = GetCurrArg(lpNextArg); lpNextArg = GetNextArg(lpNextArg); - clockMultiplier = atof(lpCmdLine); + g_cmdLine.clockMultiplier = atof(lpCmdLine); } else if (strcmp(lpCmdLine, "-model") == 0) { @@ -1540,23 +1662,23 @@ int APIENTRY WinMain(HINSTANCE passinstance, HINSTANCE, LPSTR lpCmdLine, int) lpNextArg = GetNextArg(lpNextArg); if (strcmp(lpCmdLine, "apple2") == 0) - model = A2TYPE_APPLE2; + g_cmdLine.model = A2TYPE_APPLE2; else if (strcmp(lpCmdLine, "apple2p") == 0) - model = A2TYPE_APPLE2PLUS; + g_cmdLine.model = A2TYPE_APPLE2PLUS; else if (strcmp(lpCmdLine, "apple2e") == 0) - model = A2TYPE_APPLE2E; + g_cmdLine.model = A2TYPE_APPLE2E; else if (strcmp(lpCmdLine, "apple2ee") == 0) - model = A2TYPE_APPLE2EENHANCED; + g_cmdLine.model = A2TYPE_APPLE2EENHANCED; else LogFileOutput("-model: unsupported type: %s\n", lpCmdLine); } else if (_stricmp(lpCmdLine, "-50hz") == 0) // (case-insensitive) { - newVideoRefreshRate = VR_50HZ; + g_cmdLine.newVideoRefreshRate = VR_50HZ; } else if (_stricmp(lpCmdLine, "-60hz") == 0) // (case-insensitive) { - newVideoRefreshRate = VR_60HZ; + g_cmdLine.newVideoRefreshRate = VR_60HZ; } else // unsupported { @@ -1567,24 +1689,14 @@ int APIENTRY WinMain(HINSTANCE passinstance, HINSTANCE, LPSTR lpCmdLine, int) } LogFileOutput("CmdLine: %s\n", strCmdLine.c_str()); +} -#if 0 -#ifdef RIFF_SPKR - RiffInitWriteFile("Spkr.wav", SPKR_SAMPLE_RATE, 1); -#endif -#ifdef RIFF_MB - RiffInitWriteFile("Mockingboard.wav", 44100, 2); -#endif -#endif - - //----- - +static void GetAppleWinVersion(void) +{ char szPath[_MAX_PATH]; if (0 == GetModuleFileName(NULL, szPath, sizeof(szPath))) - { - strcpy(szPath, __argv[0]); - } + strcpy_s(szPath, sizeof(szPath), __argv[0]); // Extract application version and store in a global variable DWORD dwHandle, dwVerInfoSize; @@ -1615,16 +1727,27 @@ int APIENTRY WinMain(HINSTANCE passinstance, HINSTANCE, LPSTR lpCmdLine, int) } LogFileOutput("AppleWin version: %s\n", VERSIONSTRING); +} - //----- +// DO ONE-TIME INITIALIZATION +static void OneTimeInitialization(HINSTANCE passinstance) +{ +#if 0 +#ifdef RIFF_SPKR + RiffInitWriteFile("Spkr.wav", SPKR_SAMPLE_RATE, 1); +#endif +#ifdef RIFF_MB + RiffInitWriteFile("Mockingboard.wav", 44100, 2); +#endif +#endif // Initialize COM - so we can use CoCreateInstance // . NB. DSInit() & DIMouse::DirectInputInit are done when g_hFrameWindow is created (WM_CREATE) HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); LogFileOutput("Init: CoInitializeEx(), hr=0x%08X\n", hr); - const bool bSysClkOK = SysClk_InitTimer(); - LogFileOutput("Init: SysClk_InitTimer(), res=%d\n", bSysClkOK ? 1:0); + g_bSysClkOK = SysClk_InitTimer(); + LogFileOutput("Init: SysClk_InitTimer(), res=%d\n", g_bSysClkOK ? 1:0); #ifdef USE_SPEECH_API if (g_bEnableSpeech) { @@ -1636,7 +1759,6 @@ int APIENTRY WinMain(HINSTANCE passinstance, HINSTANCE, LPSTR lpCmdLine, int) DDInit(); // For WaitForVerticalBlank() #endif - // DO ONE-TIME INITIALIZATION g_hInstance = passinstance; GdiSetBatchLimit(512); LogFileOutput("Init: GdiSetBatchLimit()\n"); @@ -1655,13 +1777,11 @@ int APIENTRY WinMain(HINSTANCE passinstance, HINSTANCE, LPSTR lpCmdLine, int) ImageInitialize(); LogFileOutput("Init: ImageInitialize()\n"); +} - // - - do - { - // DO INITIALIZATION THAT MUST BE REPEATED FOR A RESTART - g_bRestart = false; +// DO INITIALIZATION THAT MUST BE REPEATED FOR A RESTART +static void RepeatInitialization(void) +{ ResetToLogoMode(); // NB. g_OldAppleWinVersion needed by LoadConfiguration() -> Config_Load_Video() @@ -1670,46 +1790,46 @@ int APIENTRY WinMain(HINSTANCE passinstance, HINSTANCE, LPSTR lpCmdLine, int) LoadConfiguration(); LogFileOutput("Main: LoadConfiguration()\n"); - if (model != A2TYPE_MAX) - SetApple2Type(model); + if (g_cmdLine.model != A2TYPE_MAX) + SetApple2Type(g_cmdLine.model); - if (newVideoType >= 0) + if (g_cmdLine.newVideoType >= 0) { - SetVideoType( (VideoType_e)newVideoType ); - newVideoType = -1; // Don't reapply after a restart + SetVideoType( (VideoType_e)g_cmdLine.newVideoType ); + g_cmdLine.newVideoType = -1; // Don't reapply after a restart } - SetVideoStyle( (VideoStyle_e) ((GetVideoStyle() | newVideoStyleEnableMask) & ~newVideoStyleDisableMask) ); + SetVideoStyle( (VideoStyle_e) ((GetVideoStyle() | g_cmdLine.newVideoStyleEnableMask) & ~g_cmdLine.newVideoStyleDisableMask) ); - if (newVideoRefreshRate != VR_NONE) + if (g_cmdLine.newVideoRefreshRate != VR_NONE) { - SetVideoRefreshRate(newVideoRefreshRate); - newVideoRefreshRate = VR_NONE; // Don't reapply after a restart + SetVideoRefreshRate(g_cmdLine.newVideoRefreshRate); + g_cmdLine.newVideoRefreshRate = VR_NONE; // Don't reapply after a restart SetCurrentCLK6502(); } - UseClockMultiplier(clockMultiplier); - clockMultiplier = 0.0; + UseClockMultiplier(g_cmdLine.clockMultiplier); + g_cmdLine.clockMultiplier = 0.0; // Apply the memory expansion switches after loading the Apple II machine type #ifdef RAMWORKS - if (uRamWorksExPages) + if (g_cmdLine.uRamWorksExPages) { - SetRamWorksMemorySize(uRamWorksExPages); + SetRamWorksMemorySize(g_cmdLine.uRamWorksExPages); SetExpansionMemType(CT_RamWorksIII); - uRamWorksExPages = 0; // Don't reapply after a restart + g_cmdLine.uRamWorksExPages = 0; // Don't reapply after a restart } #endif - if (uSaturnBanks) + if (g_cmdLine.uSaturnBanks) { - SetSaturnMemorySize(uSaturnBanks); // Set number of banks before constructing Saturn card + SetSaturnMemorySize(g_cmdLine.uSaturnBanks); // Set number of banks before constructing Saturn card SetExpansionMemType(CT_Saturn128K); - uSaturnBanks = 0; // Don't reapply after a restart + g_cmdLine.uSaturnBanks = 0; // Don't reapply after a restart } - if (bSlot0LanguageCard) + if (g_cmdLine.bSlot0LanguageCard) { SetExpansionMemType(CT_LanguageCard); - bSlot0LanguageCard = false; // Don't reapply after a restart + g_cmdLine.bSlot0LanguageCard = false; // Don't reapply after a restart } DebugInitialize(); @@ -1726,40 +1846,40 @@ int APIENTRY WinMain(HINSTANCE passinstance, HINSTANCE, LPSTR lpCmdLine, int) LogFileOutput("Main: FrameCreateWindow() - post\n"); // Allow the 4 hardcoded slots to be configurated as empty - if (bSlotEmpty[SLOT1]) + if (g_cmdLine.bSlotEmpty[SLOT1]) g_CardMgr.Remove(SLOT1); - if (bSlotEmpty[SLOT2]) + if (g_cmdLine.bSlotEmpty[SLOT2]) g_CardMgr.Remove(SLOT2); - if (bSlotEmpty[SLOT3]) + if (g_cmdLine.bSlotEmpty[SLOT3]) g_CardMgr.Remove(SLOT3); - if (bSlotEmpty[SLOT6]) + if (g_cmdLine.bSlotEmpty[SLOT6]) g_CardMgr.Remove(SLOT6); - if (slotInsert[5] != CT_Empty) + if (g_cmdLine.slotInsert[SLOT5] != CT_Empty) { - if (g_CardMgr.QuerySlot(SLOT4) == CT_MockingboardC && slotInsert[SLOT5] != CT_MockingboardC) // Currently MB occupies slot4+5 when enabled + if (g_CardMgr.QuerySlot(SLOT4) == CT_MockingboardC && g_cmdLine.slotInsert[SLOT5] != CT_MockingboardC) // Currently MB occupies slot4+5 when enabled { g_CardMgr.Remove(SLOT4); g_CardMgr.Remove(SLOT5); } - g_CardMgr.Insert(SLOT5, slotInsert[SLOT5]); + g_CardMgr.Insert(SLOT5, g_cmdLine.slotInsert[SLOT5]); } // Pre: may need g_hFrameWindow for MessageBox errors // Post: may enable HDD, required for MemInitialize()->MemInitializeIO() { bool temp = false; - InsertFloppyDisks(SLOT5, szImageName_drive[SLOT5], temp); - //szImageName_drive[SLOT5][DRIVE_1] = szImageName_drive[SLOT5][DRIVE_2] = NULL; // *Do* insert on a restart (since no way they could have changed) + InsertFloppyDisks(SLOT5, g_cmdLine.szImageName_drive[SLOT5], temp); + //g_cmdLine.szImageName_drive[SLOT5][DRIVE_1] = g_cmdLine.szImageName_drive[SLOT5][DRIVE_2] = NULL; // *Do* insert on a restart (since no way they could have changed) - InsertFloppyDisks(SLOT6, szImageName_drive[SLOT6], bBoot); - szImageName_drive[SLOT6][DRIVE_1] = szImageName_drive[SLOT6][DRIVE_2] = NULL; // Don't insert on a restart + InsertFloppyDisks(SLOT6, g_cmdLine.szImageName_drive[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(szImageName_harddisk, bBoot); - szImageName_harddisk[HARDDISK_1] = szImageName_harddisk[HARDDISK_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 - if (bSlotEmpty[7]) + if (g_cmdLine.bSlotEmpty[7]) HD_SetEnabled(false); } @@ -1770,7 +1890,7 @@ int APIENTRY WinMain(HINSTANCE passinstance, HINSTANCE, LPSTR lpCmdLine, int) if (bShowAboutDlg) { if (!AboutDlg()) - bShutdown = true; // Close everything down + g_cmdLine.bShutdown = true; // Close everything down else RegSaveString(TEXT(REG_CONFIG), TEXT(REGVALUE_VERSION), 1, VERSIONSTRING); // Only save version after user accepts license } @@ -1793,10 +1913,10 @@ int APIENTRY WinMain(HINSTANCE passinstance, HINSTANCE, LPSTR lpCmdLine, int) HD_Reset(); // GH#515 LogFileOutput("Main: HDDReset()\n"); - if (!bSysClkOK) + if (!g_bSysClkOK) { MessageBox(g_hFrameWindow, "DirectX failed to create SystemClock instance", TEXT("AppleWin Error"), MB_OK); - bShutdown = true; + g_cmdLine.bShutdown = true; } if (g_bCustomRomF8Failed) @@ -1804,15 +1924,15 @@ int APIENTRY WinMain(HINSTANCE passinstance, HINSTANCE, LPSTR lpCmdLine, int) std::string msg = "Failed to load custom F8 rom (not found or not exactly 2KiB)\n"; LogFileOutput("%s", msg.c_str()); MessageBox(g_hFrameWindow, msg.c_str(), TEXT("AppleWin Error"), MB_OK); - bShutdown = true; + g_cmdLine.bShutdown = true; } tfe_init(); LogFileOutput("Main: tfe_init()\n"); - if (szSnapshotName) + if (g_cmdLine.szSnapshotName) { - std::string strPathname(szSnapshotName); + std::string strPathname(g_cmdLine.szSnapshotName); int nIdx = strPathname.find_last_of('\\'); if (nIdx >= 0 && nIdx+1 < (int)strPathname.length()) { @@ -1822,16 +1942,16 @@ int APIENTRY WinMain(HINSTANCE passinstance, HINSTANCE, LPSTR lpCmdLine, int) // Override value just loaded from Registry by LoadConfiguration() // . NB. Registry value is not updated with this cmd-line value - Snapshot_SetFilename(szSnapshotName); + Snapshot_SetFilename(g_cmdLine.szSnapshotName); Snapshot_LoadState(); - bBoot = true; + g_cmdLine.bBoot = true; #if _DEBUG && 0 // Debug/test: Save a duplicate of the save-state file in tmp folder std::string saveName = std::string("tmp\\") + std::string(szSnapshotName); Snapshot_SetFilename(saveName); g_bSaveStateOnExit = true; bShutdown = true; #endif - szSnapshotName = NULL; + g_cmdLine.szSnapshotName = NULL; } else { @@ -1839,83 +1959,53 @@ int APIENTRY WinMain(HINSTANCE passinstance, HINSTANCE, LPSTR lpCmdLine, int) LogFileOutput("Main: Snapshot_Startup()\n"); } - if (szScreenshotFilename) + if (g_cmdLine.szScreenshotFilename) { - Video_RedrawAndTakeScreenShot(szScreenshotFilename); - bShutdown = true; + Video_RedrawAndTakeScreenShot(g_cmdLine.szScreenshotFilename); + g_cmdLine.bShutdown = true; } - if (bShutdown) + if (g_cmdLine.bShutdown) { PostMessage(g_hFrameWindow, WM_DESTROY, 0, 0); // Close everything down // NB. If shutting down, then don't post any other messages (GH#286) } else { - if (bSetFullScreen) + if (g_cmdLine.bSetFullScreen) { - if (bestWidth && bestHeight) + if (g_cmdLine.bestWidth && g_cmdLine.bestHeight) { DEVMODE devMode; memset(&devMode, 0, sizeof(devMode)); devMode.dmSize = sizeof(devMode); - devMode.dmPelsWidth = bestWidth; - devMode.dmPelsHeight = bestHeight; + devMode.dmPelsWidth = g_cmdLine.bestWidth; + devMode.dmPelsHeight = g_cmdLine.bestHeight; devMode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT; DWORD dwFlags = 0; LONG res = ChangeDisplaySettings(&devMode, dwFlags); if (res == 0) - bChangedDisplayResolution = true; + g_cmdLine.bChangedDisplayResolution = true; } PostMessage(g_hFrameWindow, WM_USER_FULLSCREEN, 0, 0); - bSetFullScreen = false; + g_cmdLine.bSetFullScreen = false; } - if (bBoot) + if (g_cmdLine.bBoot) { PostMessage(g_hFrameWindow, WM_USER_BOOT, 0, 0); - bBoot = false; + g_cmdLine.bBoot = false; } } SetMouseCardInstalled( g_CardMgr.IsMouseCardInstalled() ); +} - // ENTER THE MAIN MESSAGE LOOP - LogFileOutput("Main: EnterMessageLoop()\n"); - EnterMessageLoop(); - LogFileOutput("Main: LeaveMessageLoop()\n"); - - if (g_bRestart) - { - bSetFullScreen = g_bRestartFullScreen; - g_bRestartFullScreen = false; - } - - MB_Reset(); - LogFileOutput("Main: MB_Reset()\n"); - - CMouseInterface* pMouseCard = g_CardMgr.GetMouseCard(); - if (pMouseCard) - { -// pMouseCard->Uninitialize(); // Maybe restarting due to switching slot-4 card from MouseCard to Mockingboard - pMouseCard->Reset(); // Deassert any pending IRQs - GH#514 - LogFileOutput("Main: CMouseInterface::Uninitialize()\n"); - } - - DSUninit(); - LogFileOutput("Main: DSUninit()\n"); - - if (g_bHookSystemKey) - { - UninitHookThread(); - LogFileOutput("Main: UnhookFilterForKeyboard()\n"); - } - } - while (g_bRestart); - - if (bChangedDisplayResolution) +static void Shutdown(void) +{ + if (g_cmdLine.bChangedDisplayResolution) ChangeDisplaySettings(NULL, 0); // restore default // Release COM @@ -1936,8 +2026,6 @@ int APIENTRY WinMain(HINSTANCE passinstance, HINSTANCE, LPSTR lpCmdLine, int) if (g_hCustomRomF8 != INVALID_HANDLE_VALUE) CloseHandle(g_hCustomRomF8); - if (bSlot7EmptyOnExit) + if (g_cmdLine.bSlot7EmptyOnExit) UnplugHardDiskControllerCard(); - - return 0; } diff --git a/source/CardManager.h b/source/CardManager.h index ae317c69..41972efd 100644 --- a/source/CardManager.h +++ b/source/CardManager.h @@ -30,6 +30,12 @@ public: void Insert(UINT slot, SS_CARDTYPE type); void Remove(UINT slot); SS_CARDTYPE QuerySlot(UINT slot) { return m_slot[slot]->QueryType(); } + Card& GetRef(UINT slot) + { + SS_CARDTYPE t=QuerySlot(slot); _ASSERT((t==CT_SSC || t==CT_MouseInterface || t==CT_Disk2) && m_slot[slot]); + if (!m_slot[slot]) throw std::runtime_error("slot/card mismatch"); + return *m_slot[slot]; + } Card* GetObj(UINT slot) { SS_CARDTYPE t=QuerySlot(slot); _ASSERT(t==CT_SSC || t==CT_MouseInterface || t==CT_Disk2); return m_slot[slot]; } void InsertAux(SS_CARDTYPE type); diff --git a/source/Configuration/PageDisk.cpp b/source/Configuration/PageDisk.cpp index eae4b43c..424bdd58 100644 --- a/source/Configuration/PageDisk.cpp +++ b/source/Configuration/PageDisk.cpp @@ -135,6 +135,8 @@ BOOL CPageDisk::DlgProcInternal(HWND hWnd, UINT message, WPARAM wparam, LPARAM l if (g_CardMgr.QuerySlot(SLOT6) == CT_Disk2) InitComboFloppyDrive(hWnd, SLOT6); + else + EnableFloppyDrive(hWnd, FALSE); InitComboHDD(hWnd, SLOT7); @@ -158,20 +160,20 @@ BOOL CPageDisk::DlgProcInternal(HWND hWnd, UINT message, WPARAM wparam, LPARAM l void CPageDisk::InitComboFloppyDrive(HWND hWnd, UINT slot) { - Disk2InterfaceCard* pDisk2Card = dynamic_cast(g_CardMgr.GetObj(slot)); + Disk2InterfaceCard& disk2Card = dynamic_cast(g_CardMgr.GetRef(slot)); m_PropertySheetHelper.FillComboBox(hWnd, IDC_COMBO_DISK1, m_defaultDiskOptions, -1); m_PropertySheetHelper.FillComboBox(hWnd, IDC_COMBO_DISK2, m_defaultDiskOptions, -1); - if (!pDisk2Card->GetFullName(DRIVE_1).empty()) + if (!disk2Card.GetFullName(DRIVE_1).empty()) { - SendDlgItemMessage(hWnd, IDC_COMBO_DISK1, CB_INSERTSTRING, 0, (LPARAM)pDisk2Card->GetFullName(DRIVE_1).c_str()); + SendDlgItemMessage(hWnd, IDC_COMBO_DISK1, CB_INSERTSTRING, 0, (LPARAM)disk2Card.GetFullName(DRIVE_1).c_str()); SendDlgItemMessage(hWnd, IDC_COMBO_DISK1, CB_SETCURSEL, 0, 0); } - if (!pDisk2Card->GetFullName(DRIVE_2).empty()) + if (!disk2Card.GetFullName(DRIVE_2).empty()) { - SendDlgItemMessage(hWnd, IDC_COMBO_DISK2, CB_INSERTSTRING, 0, (LPARAM)pDisk2Card->GetFullName(DRIVE_2).c_str()); + SendDlgItemMessage(hWnd, IDC_COMBO_DISK2, CB_INSERTSTRING, 0, (LPARAM)disk2Card.GetFullName(DRIVE_2).c_str()); SendDlgItemMessage(hWnd, IDC_COMBO_DISK2, CB_SETCURSEL, 0, 0); } } @@ -228,7 +230,7 @@ void CPageDisk::EnableHDD(HWND hWnd, BOOL bEnable) EnableWindow(GetDlgItem(hWnd, IDC_HDD_SWAP), bEnable); } -void CPageDisk::EnableDisk(HWND hWnd, BOOL bEnable) +void CPageDisk::EnableFloppyDrive(HWND hWnd, BOOL bEnable) { EnableWindow(GetDlgItem(hWnd, IDC_COMBO_DISK1), bEnable); EnableWindow(GetDlgItem(hWnd, IDC_COMBO_DISK2), bEnable); @@ -300,9 +302,13 @@ void CPageDisk::HandleHDDCombo(HWND hWnd, UINT driveSelected, UINT comboSelected void CPageDisk::HandleFloppyDriveCombo(HWND hWnd, UINT driveSelected, UINT comboSelected) { - Disk2InterfaceCard* pDisk2Card = (g_CardMgr.QuerySlot(SLOT6) == CT_Disk2) - ? dynamic_cast(g_CardMgr.GetObj(SLOT6)) - : NULL; + if (g_CardMgr.QuerySlot(SLOT6) != CT_Disk2) + { + _ASSERT(0); // Shouldn't come here, as the combo is disabled + return; + } + + Disk2InterfaceCard& disk2Card = dynamic_cast(g_CardMgr.GetRef(SLOT6)); // Search from "select floppy drive" DWORD dwOpenDialogIndex = (DWORD)SendDlgItemMessage(hWnd, comboSelected, CB_FINDSTRINGEXACT, -1, (LPARAM)&m_defaultDiskOptions[0]); @@ -312,10 +318,9 @@ void CPageDisk::HandleFloppyDriveCombo(HWND hWnd, UINT driveSelected, UINT combo if (dwComboSelection == dwOpenDialogIndex) { - EnableDisk(hWnd, FALSE); // Prevent multiple Selection dialogs to be triggered - bool bRes = false; - if (pDisk2Card) bRes = pDisk2Card->UserSelectNewDiskImage(driveSelected); - EnableDisk(hWnd, TRUE); + EnableFloppyDrive(hWnd, FALSE); // Prevent multiple Selection dialogs to be triggered + bool bRes = disk2Card.UserSelectNewDiskImage(driveSelected); + EnableFloppyDrive(hWnd, TRUE); if (!bRes) { @@ -331,8 +336,7 @@ void CPageDisk::HandleFloppyDriveCombo(HWND hWnd, UINT driveSelected, UINT combo SendDlgItemMessage(hWnd, comboSelected, CB_DELETESTRING, 0, 0); } - std::string fullname; - if (pDisk2Card) fullname = pDisk2Card->GetFullName(driveSelected); + std::string fullname = disk2Card.GetFullName(driveSelected); SendDlgItemMessage(hWnd, comboSelected, CB_INSERTSTRING, 0, (LPARAM)fullname.c_str()); SendDlgItemMessage(hWnd, comboSelected, CB_SETCURSEL, 0, 0); @@ -354,7 +358,7 @@ void CPageDisk::HandleFloppyDriveCombo(HWND hWnd, UINT driveSelected, UINT combo if (RemovalConfirmation(uCommand)) { // Eject selected disk - if (pDisk2Card) pDisk2Card->EjectDisk(driveSelected); + disk2Card.EjectDisk(driveSelected); // Remove drive from list SendDlgItemMessage(hWnd, comboSelected, CB_DELETESTRING, 0, 0); } diff --git a/source/Configuration/PageDisk.h b/source/Configuration/PageDisk.h index b137a4de..16b8894c 100644 --- a/source/Configuration/PageDisk.h +++ b/source/Configuration/PageDisk.h @@ -28,7 +28,7 @@ private: void InitComboFloppyDrive(HWND hWnd, UINT slot); void InitComboHDD(HWND hWnd, UINT slot); void EnableHDD(HWND hWnd, BOOL bEnable); - void EnableDisk(HWND hWnd, BOOL bEnable); + void EnableFloppyDrive(HWND hWnd, BOOL bEnable); void HandleHDDCombo(HWND hWnd, UINT driveSelected, UINT comboSelected); void HandleFloppyDriveCombo(HWND hWnd, UINT driveSelected, UINT comboSelected); void HandleHDDSwap(HWND hWnd); diff --git a/source/Configuration/PropertySheetHelper.cpp b/source/Configuration/PropertySheetHelper.cpp index a00fdf2f..730ab15d 100644 --- a/source/Configuration/PropertySheetHelper.cpp +++ b/source/Configuration/PropertySheetHelper.cpp @@ -217,10 +217,10 @@ void CPropertySheetHelper::GetDiskBaseNameWithAWS(std::string & pszFilename) if (g_CardMgr.QuerySlot(SLOT6) != CT_Disk2) return; - const std::string & pDiskName = dynamic_cast(g_CardMgr.GetObj(SLOT6))->GetBaseName(DRIVE_1); - if (!pDiskName.empty()) + const std::string& diskName = dynamic_cast(g_CardMgr.GetRef(SLOT6)).GetBaseName(DRIVE_1); + if (!diskName.empty()) { - pszFilename = pDiskName + ".aws.yaml"; + pszFilename = diskName + ".aws.yaml"; } } diff --git a/source/Debugger/Debug.cpp b/source/Debugger/Debug.cpp index 525a5bb3..8bb66590 100644 --- a/source/Debugger/Debug.cpp +++ b/source/Debugger/Debug.cpp @@ -3756,7 +3756,7 @@ Update_t CmdDisk ( int nArgs) if (g_CardMgr.QuerySlot(SLOT6) != CT_Disk2) return ConsoleDisplayError("No DiskII card in slot-6"); - Disk2InterfaceCard* pDiskCard = dynamic_cast(g_CardMgr.GetObj(SLOT6)); + Disk2InterfaceCard& diskCard = dynamic_cast(g_CardMgr.GetRef(SLOT6)); // check for info command int iParam = 0; @@ -3769,13 +3769,13 @@ Update_t CmdDisk ( int nArgs) char buffer[200] = ""; ConsoleBufferPushFormat(buffer, "D%d at T$%s, phase $%s, offset $%X, mask $%02X, extraCycles %.2f, %s", - pDiskCard->GetCurrentDrive() + 1, - pDiskCard->GetCurrentTrackString().c_str(), - pDiskCard->GetCurrentPhaseString().c_str(), - pDiskCard->GetCurrentOffset(), - pDiskCard->GetCurrentLSSBitMask(), - pDiskCard->GetCurrentExtraCycles(), - pDiskCard->GetCurrentState() + diskCard.GetCurrentDrive() + 1, + diskCard.GetCurrentTrackString().c_str(), + diskCard.GetCurrentPhaseString().c_str(), + diskCard.GetCurrentOffset(), + diskCard.GetCurrentLSSBitMask(), + diskCard.GetCurrentExtraCycles(), + diskCard.GetCurrentState() ); return ConsoleUpdate(); @@ -3803,7 +3803,7 @@ Update_t CmdDisk ( int nArgs) if (nArgs > 2) goto _Help; - pDiskCard->EjectDisk( iDrive ); + diskCard.EjectDisk( iDrive ); FrameRefreshStatus(DRAW_LEDS | DRAW_BUTTON_DRIVES); } else @@ -3817,7 +3817,7 @@ Update_t CmdDisk ( int nArgs) if (nArgs == 3) bProtect = g_aArgs[ 3 ].nValue ? true : false; - pDiskCard->SetProtect( iDrive, bProtect ); + diskCard.SetProtect( iDrive, bProtect ); FrameRefreshStatus(DRAW_LEDS | DRAW_BUTTON_DRIVES); } else @@ -3828,7 +3828,7 @@ Update_t CmdDisk ( int nArgs) LPCTSTR pDiskName = g_aArgs[ 3 ].sArg; // DISK # "Diskname" - pDiskCard->InsertDisk( iDrive, pDiskName, IMAGE_FORCE_WRITE_PROTECTED, IMAGE_DONT_CREATE ); + diskCard.InsertDisk( iDrive, pDiskName, IMAGE_FORCE_WRITE_PROTECTED, IMAGE_DONT_CREATE ); FrameRefreshStatus(DRAW_LEDS | DRAW_BUTTON_DRIVES); } @@ -7037,7 +7037,7 @@ Update_t CmdWatchAdd (int nArgs) if (iWatch == NO_6502_TARGET) { iWatch = 0; - while ((iWatch < MAX_ZEROPAGE_POINTERS) && (g_aWatches[iWatch].bSet)) + while ((iWatch < MAX_WATCHES) && (g_aWatches[iWatch].bSet)) { iWatch++; } @@ -9642,6 +9642,14 @@ void DebugDisplay( BOOL bInitDisasm/*=FALSE*/ ) if (bInitDisasm) InitDisasm(); + if (DebugVideoMode::Instance().IsSet()) + { + uint32_t mode = 0; + DebugVideoMode::Instance().Get(&mode); + VideoRefreshScreen(mode, true); + return; + } + UpdateDisplay( UPDATE_ALL ); } diff --git a/source/Debugger/Debugger_DisassemblerData.cpp b/source/Debugger/Debugger_DisassemblerData.cpp index 0eded8e1..43f256ed 100644 --- a/source/Debugger/Debugger_DisassemblerData.cpp +++ b/source/Debugger/Debugger_DisassemblerData.cpp @@ -125,7 +125,7 @@ WORD _CmdDefineByteRange(int nArgs,int iArg,DisasmData_t & tData_) // TODO: Note: need to call ConsoleUpdate(), as may print symbol has been updated - strcpy( tData_.sSymbol, pSymbolName ); + strcpy_s( tData_.sSymbol, sizeof(tData_.sSymbol), pSymbolName ); return nAddress; } diff --git a/source/Disk2CardManager.cpp b/source/Disk2CardManager.cpp index f36229c2..3c0562b7 100644 --- a/source/Disk2CardManager.cpp +++ b/source/Disk2CardManager.cpp @@ -40,7 +40,7 @@ bool Disk2CardManager::IsConditionForFullSpeed(void) { if (g_CardMgr.QuerySlot(i) == CT_Disk2) { - if (dynamic_cast(g_CardMgr.GetObj(i))->IsConditionForFullSpeed()) + if (dynamic_cast(g_CardMgr.GetRef(i)).IsConditionForFullSpeed()) return true; // if any card is true then the condition for full-speed is true } } @@ -54,7 +54,7 @@ void Disk2CardManager::UpdateDriveState(UINT cycles) { if (g_CardMgr.QuerySlot(i) == CT_Disk2) { - dynamic_cast(g_CardMgr.GetObj(i))->UpdateDriveState(cycles); + dynamic_cast(g_CardMgr.GetRef(i)).UpdateDriveState(cycles); } } } @@ -65,7 +65,7 @@ void Disk2CardManager::Reset(const bool powerCycle /*=false*/) { if (g_CardMgr.QuerySlot(i) == CT_Disk2) { - dynamic_cast(g_CardMgr.GetObj(i))->Reset(powerCycle); + dynamic_cast(g_CardMgr.GetRef(i)).Reset(powerCycle); } } } @@ -77,7 +77,7 @@ bool Disk2CardManager::GetEnhanceDisk(void) if (g_CardMgr.QuerySlot(i) == CT_Disk2) { // All Disk2 cards should have the same setting, so just return the state of the first card - return dynamic_cast(g_CardMgr.GetObj(i))->GetEnhanceDisk(); + return dynamic_cast(g_CardMgr.GetRef(i)).GetEnhanceDisk(); } } return false; @@ -89,7 +89,7 @@ void Disk2CardManager::SetEnhanceDisk(bool enhanceDisk) { if (g_CardMgr.QuerySlot(i) == CT_Disk2) { - dynamic_cast(g_CardMgr.GetObj(i))->SetEnhanceDisk(enhanceDisk); + dynamic_cast(g_CardMgr.GetRef(i)).SetEnhanceDisk(enhanceDisk); } } } @@ -102,8 +102,8 @@ void Disk2CardManager::LoadLastDiskImage(void) if (g_CardMgr.QuerySlot(i) == CT_Disk2) { - dynamic_cast(g_CardMgr.GetObj(i))->LoadLastDiskImage(DRIVE_1); - dynamic_cast(g_CardMgr.GetObj(i))->LoadLastDiskImage(DRIVE_2); + dynamic_cast(g_CardMgr.GetRef(i)).LoadLastDiskImage(DRIVE_1); + dynamic_cast(g_CardMgr.GetRef(i)).LoadLastDiskImage(DRIVE_2); } } } @@ -114,7 +114,7 @@ void Disk2CardManager::Destroy(void) { if (g_CardMgr.QuerySlot(i) == CT_Disk2) { - dynamic_cast(g_CardMgr.GetObj(i))->Destroy(); + dynamic_cast(g_CardMgr.GetRef(i)).Destroy(); } } } diff --git a/source/DiskImageHelper.cpp b/source/DiskImageHelper.cpp index b32fc8d4..414fc1e8 100644 --- a/source/DiskImageHelper.cpp +++ b/source/DiskImageHelper.cpp @@ -56,6 +56,7 @@ ImageInfo::ImageInfo() pImageBuffer = NULL; pTrackMap = NULL; optimalBitTiming = 0; + maxNibblesPerTrack = 0; } /* DO logical order 0 1 2 3 4 5 6 7 8 9 A B C D E F */ @@ -123,11 +124,12 @@ bool CImageBase::WriteTrack(ImageInfo* pImageInfo, const int nTrack, LPBYTE pTra return false; int nLen = gzwrite(hGZFile, pImageInfo->pImageBuffer, pImageInfo->uImageSize); + int nRes = gzclose(hGZFile); // close before returning (due to error) to avoid resource leak + hGZFile = NULL; + if (nLen != pImageInfo->uImageSize) return false; - int nRes = gzclose(hGZFile); - hGZFile = NULL; if (nRes != Z_OK) return false; } @@ -244,11 +246,12 @@ bool CImageBase::WriteBlock(ImageInfo* pImageInfo, const int nBlock, LPBYTE pBlo return false; int nLen = gzwrite(hGZFile, pImageInfo->pImageBuffer, pImageInfo->uImageSize); + int nRes = gzclose(hGZFile); // close before returning (due to error) to avoid resource leak + hGZFile = NULL; + if (nLen != pImageInfo->uImageSize) return false; - int nRes = gzclose(hGZFile); - hGZFile = NULL; if (nRes != Z_OK) return false; } @@ -1398,11 +1401,12 @@ ImageError_e CImageHelperBase::CheckGZipFile(LPCTSTR pszImageFilename, ImageInfo pImageInfo->pImageBuffer = new BYTE[MAX_UNCOMPRESSED_SIZE]; int nLen = gzread(hGZFile, pImageInfo->pImageBuffer, MAX_UNCOMPRESSED_SIZE); + int nRes = gzclose(hGZFile); // close before returning (due to error) to avoid resource leak + hGZFile = NULL; + if (nLen < 0 || nLen == MAX_UNCOMPRESSED_SIZE) return eIMAGE_ERROR_BAD_SIZE; - int nRes = gzclose(hGZFile); - hGZFile = NULL; if (nRes != Z_OK) return eIMAGE_ERROR_GZ; @@ -1414,7 +1418,7 @@ ImageError_e CImageHelperBase::CheckGZipFile(LPCTSTR pszImageFilename, ImageInfo DWORD dwSize = nLen; DWORD dwOffset = 0; - CImageBase* pImageType = Detect(pImageInfo->pImageBuffer, dwSize, szExt, dwOffset, pImageInfo->bWriteProtected, pImageInfo->pTrackMap, pImageInfo->optimalBitTiming, pImageInfo->maxNibblesPerTrack); + CImageBase* pImageType = Detect(pImageInfo->pImageBuffer, dwSize, szExt, dwOffset, pImageInfo); if (!pImageType) return eIMAGE_ERROR_UNSUPPORTED; @@ -1505,7 +1509,7 @@ ImageError_e CImageHelperBase::CheckZipFile(LPCTSTR pszImageFilename, ImageInfo* DWORD dwSize = nLen; DWORD dwOffset = 0; - CImageBase* pImageType = Detect(pImageInfo->pImageBuffer, dwSize, szExt, dwOffset, pImageInfo->bWriteProtected, pImageInfo->pTrackMap, pImageInfo->optimalBitTiming, pImageInfo->maxNibblesPerTrack); + CImageBase* pImageType = Detect(pImageInfo->pImageBuffer, dwSize, szExt, dwOffset, pImageInfo); if (!pImageType) { @@ -1602,7 +1606,7 @@ ImageError_e CImageHelperBase::CheckNormalFile(LPCTSTR pszImageFilename, ImageIn return eIMAGE_ERROR_BAD_SIZE; } - pImageType = Detect(pImageInfo->pImageBuffer, dwSize, szExt, dwOffset, pImageInfo->bWriteProtected, pImageInfo->pTrackMap, pImageInfo->optimalBitTiming, pImageInfo->maxNibblesPerTrack); + pImageType = Detect(pImageInfo->pImageBuffer, dwSize, szExt, dwOffset, pImageInfo); if (bTempDetectBuffer) { delete [] pImageInfo->pImageBuffer; @@ -1747,13 +1751,12 @@ CDiskImageHelper::CDiskImageHelper(void) : m_vecImageTypes.push_back( new CWOZ2Image ); } -CImageBase* CDiskImageHelper::Detect(LPBYTE pImage, DWORD dwSize, const TCHAR* pszExt, DWORD& dwOffset, - bool& writeProtected, BYTE*& pTrackMap, BYTE& optimalBitTiming, UINT& maxNibblesPerTrack) +CImageBase* CDiskImageHelper::Detect(LPBYTE pImage, DWORD dwSize, const TCHAR* pszExt, DWORD& dwOffset, ImageInfo* pImageInfo) { dwOffset = 0; m_MacBinaryHelper.DetectHdr(pImage, dwSize, dwOffset); m_Result2IMG = m_2IMGHelper.DetectHdr(pImage, dwSize, dwOffset); - maxNibblesPerTrack = NIBBLES_PER_TRACK; // Start with the default size (for all types). May get changed below. + pImageInfo->maxNibblesPerTrack = NIBBLES_PER_TRACK; // Start with the default size (for all types). May get changed below. // CALL THE DETECTION FUNCTIONS IN ORDER, LOOKING FOR A MATCH eImageType imageType = eImageUNKNOWN; @@ -1798,14 +1801,14 @@ CImageBase* CDiskImageHelper::Detect(LPBYTE pImage, DWORD dwSize, const TCHAR* p if (imageType == eImageWOZ1 || imageType == eImageWOZ2) { - if (m_WOZHelper.ProcessChunks(pImage, dwSize, dwOffset, pTrackMap) != eMatch) + if (m_WOZHelper.ProcessChunks(pImage, dwSize, dwOffset, pImageInfo->pTrackMap) != eMatch) return NULL; -// if (m_WOZHelper.IsWriteProtected() && !writeProtected) // Force write-protected until writing is supported - writeProtected = true; +// if (m_WOZHelper.IsWriteProtected() && !pImageInfo->writeProtected) // Force write-protected until writing is supported + pImageInfo->bWriteProtected = true; - optimalBitTiming = m_WOZHelper.GetOptimalBitTiming(); - maxNibblesPerTrack = m_WOZHelper.GetMaxNibblesPerTrack(); + pImageInfo->optimalBitTiming = m_WOZHelper.GetOptimalBitTiming(); + pImageInfo->maxNibblesPerTrack = m_WOZHelper.GetMaxNibblesPerTrack(); } else { @@ -1821,8 +1824,8 @@ CImageBase* CDiskImageHelper::Detect(LPBYTE pImage, DWORD dwSize, const TCHAR* p { pImageType->SetVolumeNumber( m_2IMGHelper.GetVolumeNumber() ); - if (m_2IMGHelper.IsLocked() && !writeProtected) - writeProtected = true; + if (m_2IMGHelper.IsLocked() && !pImageInfo->bWriteProtected) + pImageInfo->bWriteProtected = true; } else { @@ -1877,8 +1880,7 @@ CHardDiskImageHelper::CHardDiskImageHelper(void) : m_vecImageTypes.push_back( new CHDVImage ); } -CImageBase* CHardDiskImageHelper::Detect(LPBYTE pImage, DWORD dwSize, const TCHAR* pszExt, DWORD& dwOffset, - bool& writeProtected, BYTE*& pTrackMap, BYTE& optimalBitTiming, UINT& maxNibblesPerTrack) +CImageBase* CHardDiskImageHelper::Detect(LPBYTE pImage, DWORD dwSize, const TCHAR* pszExt, DWORD& dwOffset, ImageInfo* pImageInfo) { dwOffset = 0; m_Result2IMG = m_2IMGHelper.DetectHdr(pImage, dwSize, dwOffset); @@ -1903,14 +1905,14 @@ CImageBase* CHardDiskImageHelper::Detect(LPBYTE pImage, DWORD dwSize, const TCHA { if (m_Result2IMG == eMatch) { - if (m_2IMGHelper.IsLocked() && !writeProtected) - writeProtected = true; + if (m_2IMGHelper.IsLocked() && !pImageInfo->bWriteProtected) + pImageInfo->bWriteProtected = true; } } - pTrackMap = 0; // TODO: WOZ - optimalBitTiming = 0; // TODO: WOZ - maxNibblesPerTrack = 0; // TODO + pImageInfo->pTrackMap = 0; // TODO: WOZ + pImageInfo->optimalBitTiming = 0; // TODO: WOZ + pImageInfo->maxNibblesPerTrack = 0; // TODO return pImageType; } diff --git a/source/DiskImageHelper.h b/source/DiskImageHelper.h index 44a02a2d..0b04a714 100644 --- a/source/DiskImageHelper.h +++ b/source/DiskImageHelper.h @@ -307,7 +307,7 @@ public: ImageError_e Open(LPCTSTR pszImageFilename, ImageInfo* pImageInfo, const bool bCreateIfNecessary, std::string& strFilenameInZip); void Close(ImageInfo* pImageInfo, const bool bDeleteFile); - virtual CImageBase* Detect(LPBYTE pImage, DWORD dwSize, const TCHAR* pszExt, DWORD& dwOffset, bool& writeProtected, BYTE*& pTrackMap, BYTE& optimalBitTiming, UINT& maxNibblesPerTrack) = 0; + virtual CImageBase* Detect(LPBYTE pImage, DWORD dwSize, const TCHAR* pszExt, DWORD& dwOffset, ImageInfo* pImageInfo) = 0; virtual CImageBase* GetImageForCreation(const TCHAR* pszExt, DWORD* pCreateImageSize) = 0; virtual UINT GetMaxImageSize(void) = 0; virtual UINT GetMinDetectSize(const UINT uImageSize, bool* pTempDetectBuffer) = 0; @@ -352,7 +352,7 @@ public: CDiskImageHelper(void); virtual ~CDiskImageHelper(void) {} - virtual CImageBase* Detect(LPBYTE pImage, DWORD dwSize, const TCHAR* pszExt, DWORD& dwOffset, bool& writeProtected, BYTE*& pTrackMap, BYTE& optimalBitTiming, UINT& maxNibblesPerTrack); + virtual CImageBase* Detect(LPBYTE pImage, DWORD dwSize, const TCHAR* pszExt, DWORD& dwOffset, ImageInfo* pImageInfo); virtual CImageBase* GetImageForCreation(const TCHAR* pszExt, DWORD* pCreateImageSize); virtual UINT GetMaxImageSize(void); virtual UINT GetMinDetectSize(const UINT uImageSize, bool* pTempDetectBuffer); @@ -378,7 +378,7 @@ public: CHardDiskImageHelper(void); virtual ~CHardDiskImageHelper(void) {} - virtual CImageBase* Detect(LPBYTE pImage, DWORD dwSize, const TCHAR* pszExt, DWORD& dwOffset, bool& writeProtected, BYTE*& pTrackMap, BYTE& optimalBitTiming, UINT& maxNibblesPerTrack); + virtual CImageBase* Detect(LPBYTE pImage, DWORD dwSize, const TCHAR* pszExt, DWORD& dwOffset, ImageInfo* pImageInfo); virtual CImageBase* GetImageForCreation(const TCHAR* pszExt, DWORD* pCreateImageSize); virtual UINT GetMaxImageSize(void); virtual UINT GetMinDetectSize(const UINT uImageSize, bool* pTempDetectBuffer); diff --git a/source/Frame.cpp b/source/Frame.cpp index 2bbe2d14..1b16ea52 100644 --- a/source/Frame.cpp +++ b/source/Frame.cpp @@ -129,7 +129,6 @@ static bool g_bIsFullScreen = false; BOOL g_bMultiMon = 0; // OFF = load window position & clamp initial frame to screen, ON = use window position as is static BOOL helpquit = 0; -static BOOL g_bPaintingWindow = 0; static HFONT smallfont = (HFONT)0; static HWND tooltipwindow = (HWND)0; static BOOL g_bUsingCursor = FALSE; // TRUE = AppleWin is using (hiding) the mouse-cursor && restricting cursor to window - see SetUsingCursor() @@ -515,7 +514,7 @@ static void DrawButton (HDC passdc, int number) { SetBkMode(dc,TRANSPARENT); LPCTSTR pszBaseName = (g_CardMgr.QuerySlot(SLOT6) == CT_Disk2) - ? dynamic_cast(g_CardMgr.GetObj(SLOT6))->GetBaseName(number-BTN_DRIVE1).c_str() + ? dynamic_cast(g_CardMgr.GetRef(SLOT6)).GetBaseName(number-BTN_DRIVE1).c_str() : ""; ExtTextOut(dc,x+offset+22,rect.top,ETO_CLIPPED,&rect, @@ -623,13 +622,14 @@ static void DrawCrosshairs (int x, int y) { } //=========================================================================== -static void DrawFrameWindow () +static void DrawFrameWindow (bool bPaintingWindow = false); +static void DrawFrameWindow (bool bPaintingWindow/*=false*/) { FrameReleaseDC(); PAINTSTRUCT ps; - HDC dc = (g_bPaintingWindow + HDC dc = bPaintingWindow ? BeginPaint(g_hFrameWindow,&ps) - : GetDC(g_hFrameWindow)); + : GetDC(g_hFrameWindow); if (!g_bIsFullScreen) { @@ -677,7 +677,7 @@ static void DrawFrameWindow () else VideoRedrawScreen(); - if (g_bPaintingWindow) + if (bPaintingWindow) EndPaint(g_hFrameWindow,&ps); else ReleaseDC(g_hFrameWindow,dc); @@ -710,14 +710,14 @@ void FrameDrawDiskLEDS( HDC passdc ) // Slot6 drive takes priority unless it's off: if (g_CardMgr.QuerySlot(SLOT6) == CT_Disk2) - dynamic_cast(g_CardMgr.GetObj(SLOT6))->GetLightStatus(&g_eStatusDrive1, &g_eStatusDrive2); + dynamic_cast(g_CardMgr.GetRef(SLOT6)).GetLightStatus(&g_eStatusDrive1, &g_eStatusDrive2); // Slot5: { Disk_Status_e eDrive1StatusSlot5 = DISK_STATUS_OFF; Disk_Status_e eDrive2StatusSlot5 = DISK_STATUS_OFF; if (g_CardMgr.QuerySlot(SLOT5) == CT_Disk2) - dynamic_cast(g_CardMgr.GetObj(SLOT5))->GetLightStatus(&eDrive1StatusSlot5, &eDrive2StatusSlot5); + dynamic_cast(g_CardMgr.GetRef(SLOT5)).GetLightStatus(&eDrive1StatusSlot5, &eDrive2StatusSlot5); if (g_eStatusDrive1 == DISK_STATUS_OFF) g_eStatusDrive1 = eDrive1StatusSlot5; if (g_eStatusDrive2 == DISK_STATUS_OFF) g_eStatusDrive2 = eDrive2StatusSlot5; @@ -775,10 +775,10 @@ void FrameDrawDiskStatus( HDC passdc ) if (g_CardMgr.QuerySlot(SLOT6) != CT_Disk2) return; - Disk2InterfaceCard* pDisk2Card = dynamic_cast(g_CardMgr.GetObj(SLOT6)); - int nActiveFloppy = pDisk2Card->GetCurrentDrive(); - int nDisk1Track = pDisk2Card->GetTrack(DRIVE_1); - int nDisk2Track = pDisk2Card->GetTrack(DRIVE_2); + Disk2InterfaceCard& disk2Card = dynamic_cast(g_CardMgr.GetRef(SLOT6)); + int nActiveFloppy = disk2Card.GetCurrentDrive(); + int nDisk1Track = disk2Card.GetTrack(DRIVE_1); + int nDisk2Track = disk2Card.GetTrack(DRIVE_2); // Probe known OS's for Track/Sector int isProDOS = mem[ 0xBF00 ] == 0x4C; @@ -1183,9 +1183,9 @@ LRESULT CALLBACK FrameWndProc ( LogFileOutput("WM_DDE_EXECUTE\n"); if (g_CardMgr.QuerySlot(SLOT6) == CT_Disk2) { - Disk2InterfaceCard* pDisk2Card = dynamic_cast(g_CardMgr.GetObj(SLOT6)); + Disk2InterfaceCard& disk2Card = dynamic_cast(g_CardMgr.GetRef(SLOT6)); LPTSTR filename = (LPTSTR)GlobalLock((HGLOBAL)lparam); - ImageError_e Error = pDisk2Card->InsertDisk(DRIVE_1, filename, IMAGE_USE_FILES_WRITE_PROTECT_STATUS, IMAGE_DONT_CREATE); + ImageError_e Error = disk2Card.InsertDisk(DRIVE_1, filename, IMAGE_USE_FILES_WRITE_PROTECT_STATUS, IMAGE_DONT_CREATE); if (Error == eIMAGE_ERROR_NONE) { if (!g_bIsFullScreen) @@ -1195,7 +1195,7 @@ LRESULT CALLBACK FrameWndProc ( } else { - pDisk2Card->NotifyInvalidImage(DRIVE_1, filename, Error); + disk2Card.NotifyInvalidImage(DRIVE_1, filename, Error); } } GlobalUnlock((HGLOBAL)lparam); @@ -1211,7 +1211,7 @@ LRESULT CALLBACK FrameWndProc ( { if (g_CardMgr.QuerySlot(SLOT6) == CT_Disk2) { - Disk2InterfaceCard* pDisk2Card = dynamic_cast(g_CardMgr.GetObj(SLOT6)); + Disk2InterfaceCard& disk2Card = dynamic_cast(g_CardMgr.GetRef(SLOT6)); TCHAR filename[MAX_PATH]; DragQueryFile((HDROP)wparam,0,filename,sizeof(filename)); POINT point; @@ -1222,7 +1222,7 @@ LRESULT CALLBACK FrameWndProc ( rect.top = buttony+BTN_DRIVE2*BUTTONCY+1; rect.bottom = rect.top+BUTTONCY; const int iDrive = PtInRect(&rect,point) ? DRIVE_2 : DRIVE_1; - ImageError_e Error = pDisk2Card->InsertDisk(iDrive, filename, IMAGE_USE_FILES_WRITE_PROTECT_STATUS, IMAGE_DONT_CREATE); + ImageError_e Error = disk2Card.InsertDisk(iDrive, filename, IMAGE_USE_FILES_WRITE_PROTECT_STATUS, IMAGE_DONT_CREATE); if (Error == eIMAGE_ERROR_NONE) { if (!g_bIsFullScreen) @@ -1236,7 +1236,7 @@ LRESULT CALLBACK FrameWndProc ( } else { - pDisk2Card->NotifyInvalidImage(iDrive, filename, Error); + disk2Card.NotifyInvalidImage(iDrive, filename, Error); } } DragFinish((HDROP)wparam); @@ -1746,10 +1746,8 @@ LRESULT CALLBACK FrameWndProc ( break; case WM_PAINT: - if (GetUpdateRect(window,NULL,0)) { - g_bPaintingWindow = 1; - DrawFrameWindow(); - g_bPaintingWindow = 0; + if (GetUpdateRect(window,NULL,0)){ + DrawFrameWindow(true); } break; @@ -2058,7 +2056,7 @@ static void ProcessButtonClick(int button, bool bFromButtonUI /*=false*/) if (g_nAppMode == MODE_LOGO) { if (g_CardMgr.QuerySlot(SLOT6) == CT_Disk2) - dynamic_cast(g_CardMgr.GetObj(SLOT6))->Boot(); + dynamic_cast(g_CardMgr.GetRef(SLOT6)).Boot(); LogFileTimeUntilFirstKeyReadReset(); g_nAppMode = MODE_RUNNING; @@ -2084,7 +2082,7 @@ static void ProcessButtonClick(int button, bool bFromButtonUI /*=false*/) case BTN_DRIVE2: if (g_CardMgr.QuerySlot(SLOT6) == CT_Disk2) { - dynamic_cast(g_CardMgr.GetObj(SLOT6))->UserSelectNewDiskImage(button-BTN_DRIVE1); + dynamic_cast(g_CardMgr.GetRef(SLOT6)).UserSelectNewDiskImage(button-BTN_DRIVE1); if (!g_bIsFullScreen) DrawButton((HDC)0,button); } @@ -2093,7 +2091,7 @@ static void ProcessButtonClick(int button, bool bFromButtonUI /*=false*/) case BTN_DRIVESWAP: if (g_CardMgr.QuerySlot(SLOT6) == CT_Disk2) { - dynamic_cast(g_CardMgr.GetObj(SLOT6))->DriveSwap(); + dynamic_cast(g_CardMgr.GetRef(SLOT6)).DriveSwap(); } break; @@ -2152,7 +2150,7 @@ void ProcessDiskPopupMenu(HWND hwnd, POINT pt, const int iDrive) if (g_CardMgr.QuerySlot(SLOT6) != CT_Disk2) return; - Disk2InterfaceCard* pDisk2Card = dynamic_cast(g_CardMgr.GetObj(SLOT6)); + Disk2InterfaceCard& disk2Card = dynamic_cast(g_CardMgr.GetRef(SLOT6)); // This is the default installation path of CiderPress. // It shall not be left blank, otherwise an explorer window will be open. @@ -2167,7 +2165,7 @@ void ProcessDiskPopupMenu(HWND hwnd, POINT pt, const int iDrive) //TODO: A directory is open if an empty path to CiderPress is set. This has to be fixed. std::string filename1= "\""; - filename1.append( pDisk2Card->GetFullName(iDrive) ); + filename1.append( disk2Card.GetFullName(iDrive) ); filename1.append("\""); std::string sFileNameEmpty = "\""; sFileNameEmpty.append("\""); @@ -2189,16 +2187,16 @@ void ProcessDiskPopupMenu(HWND hwnd, POINT pt, const int iDrive) // Check menu depending on current floppy protection { int iMenuItem = ID_DISKMENU_WRITEPROTECTION_OFF; - if (pDisk2Card->GetProtect( iDrive )) + if (disk2Card.GetProtect( iDrive )) iMenuItem = ID_DISKMENU_WRITEPROTECTION_ON; CheckMenuItem(hmenu, iMenuItem, MF_CHECKED); } - if (pDisk2Card->IsDriveEmpty(iDrive)) + if (disk2Card.IsDriveEmpty(iDrive)) EnableMenuItem(hmenu, ID_DISKMENU_EJECT, MF_GRAYED); - if (pDisk2Card->IsDiskImageWriteProtected(iDrive)) + if (disk2Card.IsDiskImageWriteProtected(iDrive)) { // If image-file is read-only (or a gzip) then disable these menu items EnableMenuItem(hmenu, ID_DISKMENU_WRITEPROTECTION_ON, MF_GRAYED); @@ -2214,13 +2212,13 @@ void ProcessDiskPopupMenu(HWND hwnd, POINT pt, const int iDrive) , hwnd, NULL ); if (iCommand == ID_DISKMENU_EJECT) - pDisk2Card->EjectDisk( iDrive ); + disk2Card.EjectDisk( iDrive ); else if (iCommand == ID_DISKMENU_WRITEPROTECTION_ON) - pDisk2Card->SetProtect( iDrive, true ); + disk2Card.SetProtect( iDrive, true ); else if (iCommand == ID_DISKMENU_WRITEPROTECTION_OFF) - pDisk2Card->SetProtect( iDrive, false ); + disk2Card.SetProtect( iDrive, false ); else if (iCommand == ID_DISKMENU_SENDTO_CIDERPRESS) { @@ -2229,7 +2227,7 @@ void ProcessDiskPopupMenu(HWND hwnd, POINT pt, const int iDrive) "Please install CiderPress.\n" "Otherwise set the path to CiderPress from Configuration->Disk."; - pDisk2Card->FlushCurrentTrack(iDrive); + disk2Card.FlushCurrentTrack(iDrive); //if(!filename1.compare("\"\"") == false) //Do not use this, for some reason it does not work!!! if(!filename1.compare(sFileNameEmpty) ) @@ -2298,7 +2296,7 @@ void ResetMachineState () MemReset(); // calls CpuInitialize() PravetsReset(); if (g_CardMgr.QuerySlot(SLOT6) == CT_Disk2) - dynamic_cast(g_CardMgr.GetObj(SLOT6))->Boot(); + dynamic_cast(g_CardMgr.GetRef(SLOT6)).Boot(); VideoResetState(); KeybReset(); if (g_CardMgr.IsSSCInstalled()) diff --git a/source/Joystick.cpp b/source/Joystick.cpp index a7edb82a..37b5ae9f 100644 --- a/source/Joystick.cpp +++ b/source/Joystick.cpp @@ -303,6 +303,24 @@ void JoyInitialize() //=========================================================================== +static bool g_swapButton0and1 = false; + +void JoySwapButton0and1(bool swap) +{ + g_swapButton0and1 = swap; +} + +static UINT g_buttonVirtKey[2] = { VK_MENU, VK_MENU | KF_EXTENDED }; + +void JoySetButtonVirtualKey(UINT button, UINT virtKey) +{ + _ASSERT(button < 2); + if (button >= 2) return; + g_buttonVirtKey[button] = virtKey; +} + +//=========================================================================== + #define SUPPORT_CURSOR_KEYS BOOL JoyProcessKey(int virtkey, bool extended, bool down, bool autorep) @@ -330,11 +348,17 @@ BOOL JoyProcessKey(int virtkey, bool extended, bool down, bool autorep) BOOL keychange = 0; bool bIsCursorKey = false; + UINT virtKeyWithExtended = ((UINT)virtkey) | (extended ? KF_EXTENDED : 0); - if (virtkey == VK_MENU) // VK_MENU == ALT Key (Button #0 or #1) + if (virtKeyWithExtended == g_buttonVirtKey[!g_swapButton0and1 ? 0 : 1]) { keychange = 1; - keydown[JK_OPENAPPLE+(extended != 0)] = down; + keydown[JK_OPENAPPLE] = down; + } + else if (virtKeyWithExtended == g_buttonVirtKey[!g_swapButton0and1 ? 1 : 0]) + { + keychange = 1; + keydown[JK_CLOSEDAPPLE] = down; } else if (!extended) { diff --git a/source/Joystick.h b/source/Joystick.h index 668d650a..d56f0637 100644 --- a/source/Joystick.h +++ b/source/Joystick.h @@ -25,6 +25,8 @@ void JoySetTrim(short nValue, bool bAxisX); short JoyGetTrim(bool bAxisX); void JoyportControl(const UINT uControl); void JoySetHookAltKeys(bool hook); +void JoySwapButton0and1(bool swap); +void JoySetButtonVirtualKey(UINT button, UINT virtKey); void JoySaveSnapshot(class YamlSaveHelper& yamlSaveHelper); void JoyLoadSnapshot(class YamlLoadHelper& yamlLoadHelper); diff --git a/source/Memory.cpp b/source/Memory.cpp index 9d8ef4c2..ecaa8263 100644 --- a/source/Memory.cpp +++ b/source/Memory.cpp @@ -1659,7 +1659,7 @@ void MemInitializeIO(void) PrintLoadRom(pCxRomPeripheral, SLOT1); // $C100 : Parallel printer f/w if (g_CardMgr.QuerySlot(SLOT2) == CT_SSC) - dynamic_cast(g_CardMgr.GetObj(SLOT2))->CommInitialize(pCxRomPeripheral, SLOT2); // $C200 : SSC + dynamic_cast(g_CardMgr.GetRef(SLOT2)).CommInitialize(pCxRomPeripheral, SLOT2); // $C200 : SSC if (g_CardMgr.QuerySlot(SLOT3) == CT_Uthernet) { @@ -1672,7 +1672,7 @@ void MemInitializeIO(void) if (g_CardMgr.QuerySlot(SLOT4) == CT_MouseInterface) { - dynamic_cast(g_CardMgr.GetObj(SLOT4))->Initialize(pCxRomPeripheral, SLOT4); // $C400 : Mouse f/w + dynamic_cast(g_CardMgr.GetRef(SLOT4)).Initialize(pCxRomPeripheral, SLOT4); // $C400 : Mouse f/w } else if (g_CardMgr.QuerySlot(SLOT4) == CT_MockingboardC || g_CardMgr.QuerySlot(SLOT4) == CT_Phasor) { @@ -1697,11 +1697,11 @@ void MemInitializeIO(void) } else if (g_CardMgr.QuerySlot(SLOT5) == CT_Disk2) { - dynamic_cast(g_CardMgr.GetObj(SLOT5))->Initialize(pCxRomPeripheral, SLOT5); // $C500 : Disk][ card + dynamic_cast(g_CardMgr.GetRef(SLOT5)).Initialize(pCxRomPeripheral, SLOT5); // $C500 : Disk][ card } if (g_CardMgr.QuerySlot(SLOT6) == CT_Disk2) - dynamic_cast(g_CardMgr.GetObj(SLOT6))->Initialize(pCxRomPeripheral, SLOT6); // $C600 : Disk][ card + dynamic_cast(g_CardMgr.GetRef(SLOT6)).Initialize(pCxRomPeripheral, SLOT6); // $C600 : Disk][ card if (g_CardMgr.QuerySlot(SLOT7) == CT_GenericHDD) HD_Load_Rom(pCxRomPeripheral, SLOT7); // $C700 : HDD f/w @@ -1836,8 +1836,8 @@ void MemReset() for( int i = 0; i < 256; i++ ) { clock = getRandomTime(); - random[ (i+0) & 0xFF ] ^= (clock >> 0) & 0xFF; - random[ (i+1) & 0xFF ] ^= (clock >> 11) & 0xFF; + random[ (i+0) & 0xFF ] = (clock >> 0) & 0xFF; + random[ (i+1) & 0xFF ] = (clock >> 11) & 0xFF; } memcpy( &memmain[ iByte ], random, 256 ); diff --git a/source/SaveState.cpp b/source/SaveState.cpp index 62815380..b83bfd14 100644 --- a/source/SaveState.cpp +++ b/source/SaveState.cpp @@ -269,13 +269,13 @@ static void ParseSlots(YamlLoadHelper& yamlLoadHelper, UINT unitVersion) { type = CT_SSC; g_CardMgr.Insert(slot, type); - bRes = dynamic_cast(g_CardMgr.GetObj(slot))->LoadSnapshot(yamlLoadHelper, slot, cardVersion); + bRes = dynamic_cast(g_CardMgr.GetRef(slot)).LoadSnapshot(yamlLoadHelper, slot, cardVersion); } else if (card == CMouseInterface::GetSnapshotCardName()) { type = CT_MouseInterface; g_CardMgr.Insert(slot, type); - bRes = dynamic_cast(g_CardMgr.GetObj(slot))->LoadSnapshot(yamlLoadHelper, slot, cardVersion); + bRes = dynamic_cast(g_CardMgr.GetRef(slot)).LoadSnapshot(yamlLoadHelper, slot, cardVersion); } else if (card == Z80_GetSnapshotCardName()) { @@ -296,7 +296,7 @@ static void ParseSlots(YamlLoadHelper& yamlLoadHelper, UINT unitVersion) { type = CT_Disk2; g_CardMgr.Insert(slot, type); - bRes = dynamic_cast(g_CardMgr.GetObj(slot))->LoadSnapshot(yamlLoadHelper, slot, cardVersion); + bRes = dynamic_cast(g_CardMgr.GetRef(slot)).LoadSnapshot(yamlLoadHelper, slot, cardVersion); } else if (card == HD_GetSnapshotCardName()) { @@ -532,13 +532,13 @@ void Snapshot_SaveState(void) Printer_SaveSnapshot(yamlSaveHelper); if (g_CardMgr.QuerySlot(SLOT2) == CT_SSC) - dynamic_cast(g_CardMgr.GetObj(SLOT2))->SaveSnapshot(yamlSaveHelper); + dynamic_cast(g_CardMgr.GetRef(SLOT2)).SaveSnapshot(yamlSaveHelper); // if (g_CardMgr.QuerySlot(SLOT3) == CT_Uthernet) // sg_Uthernet.SaveSnapshot(yamlSaveHelper); if (g_CardMgr.QuerySlot(SLOT4) == CT_MouseInterface) - dynamic_cast(g_CardMgr.GetObj(SLOT4))->SaveSnapshot(yamlSaveHelper); + dynamic_cast(g_CardMgr.GetRef(SLOT4)).SaveSnapshot(yamlSaveHelper); if (g_CardMgr.QuerySlot(SLOT4) == CT_Z80) Z80_SaveSnapshot(yamlSaveHelper, SLOT4); @@ -556,10 +556,10 @@ void Snapshot_SaveState(void) Phasor_SaveSnapshot(yamlSaveHelper, SLOT4); if (g_CardMgr.QuerySlot(SLOT5) == CT_Disk2) - dynamic_cast(g_CardMgr.GetObj(SLOT5))->SaveSnapshot(yamlSaveHelper); + dynamic_cast(g_CardMgr.GetRef(SLOT5)).SaveSnapshot(yamlSaveHelper); if (g_CardMgr.QuerySlot(SLOT6) == CT_Disk2) - dynamic_cast(g_CardMgr.GetObj(SLOT6))->SaveSnapshot(yamlSaveHelper); + dynamic_cast(g_CardMgr.GetRef(SLOT6)).SaveSnapshot(yamlSaveHelper); if (g_CardMgr.QuerySlot(SLOT7) == CT_GenericHDD) HD_SaveSnapshot(yamlSaveHelper); diff --git a/source/StdAfx.h b/source/StdAfx.h index 59e279cc..7143dd02 100644 --- a/source/StdAfx.h +++ b/source/StdAfx.h @@ -31,6 +31,7 @@ #include #include #include +#include #include #include "linux/win.h" diff --git a/test/TestDebugger/TestDebugger.cpp b/test/TestDebugger/TestDebugger.cpp index c5ecb101..beb04df7 100644 --- a/test/TestDebugger/TestDebugger.cpp +++ b/test/TestDebugger/TestDebugger.cpp @@ -239,7 +239,7 @@ int GH445_test_jmp(BYTE op) const WORD target16 = 0x1234; - int target0, target1, target2; + int target0=0, target1=0, target2=0; if (op == OPCODE_JMP_A) { target0 = NO_6502_TARGET; @@ -262,6 +262,10 @@ int GH445_test_jmp(BYTE op) mem[target0] = target2 & 0xff; mem[target1] = (target2>>8) & 0xff; } + else + { + _ASSERT(0); + } mem[regs.pc] = op; mem[(regs.pc+1)&0xFFFF] = (BYTE) (target16&0xff); @@ -542,7 +546,7 @@ int GH451_test_jmp(BYTE op) const WORD target16 = 0x1234; - int target0, target1; + int target0=0, target1=0; if (op == OPCODE_JMP_A) { target0 = NO_6502_TARGET; @@ -558,6 +562,10 @@ int GH451_test_jmp(BYTE op) target0 = (target16+regs.x)&0xffff; target1 = (target16+regs.x+1)&0xffff; } + else + { + _ASSERT(0); + } mem[regs.pc] = op; mem[(regs.pc+1)&0xFFFF] = (BYTE) (target16&0xff);