From cdf1cb9106d7a7cef53df7ed1d6287e5af97ee1e Mon Sep 17 00:00:00 2001 From: Andrea Date: Tue, 19 Jan 2021 20:37:43 +0000 Subject: [PATCH] Remove usages of g_hFrameWindow and g_hInstance from core emulator files. And Resource related Win32 functions. (PR #915) . Win32Frame: remove WM_USER_RESTART. --- source/CmdLine.cpp | 4 +- source/Common.h | 17 ++-- source/Configuration/PageDisk.cpp | 2 +- source/Configuration/PropertySheetHelper.cpp | 8 +- source/Debugger/Debug.cpp | 4 +- source/Debugger/Debugger_Assembler.cpp | 2 +- source/Debugger/Debugger_Commands.cpp | 6 +- source/Debugger/Debugger_Display.cpp | 6 +- source/Disk.cpp | 30 ++----- source/Disk.h | 2 +- source/DiskImageHelper.cpp | 3 +- source/FrameBase.cpp | 4 +- source/FrameBase.h | 15 ++++ source/Harddisk.cpp | 14 +--- source/Memory.cpp | 86 +++++++------------- source/MouseInterface.cpp | 15 +--- source/NTSC_CharSet.cpp | 33 +------- source/ParallelPrinter.cpp | 15 +--- source/SaveState.cpp | 12 +-- source/SerialComms.cpp | 14 +--- source/Speaker.cpp | 2 +- source/Utilities.cpp | 7 +- source/Windows/AppleWin.cpp | 8 +- source/Windows/Win32Frame.cpp | 47 ++++++++++- source/Windows/Win32Frame.h | 5 ++ source/Windows/WinFrame.cpp | 15 ++-- 26 files changed, 158 insertions(+), 218 deletions(-) diff --git a/source/CmdLine.cpp b/source/CmdLine.cpp index 348232ee..9e8268b2 100644 --- a/source/CmdLine.cpp +++ b/source/CmdLine.cpp @@ -310,7 +310,7 @@ bool ProcessCmdLine(LPSTR lpCmdLine) { std::string msg = "Failed to load video rom (not found or not exactly 2/4/8/16KiB)\n"; LogFileOutput("%s", msg.c_str()); - MessageBox(GetFrame().g_hFrameWindow, msg.c_str(), TEXT("AppleWin Error"), MB_OK); + GetFrame().FrameMessageBox(msg.c_str(), TEXT("AppleWin Error"), MB_OK); } else { @@ -528,7 +528,7 @@ bool ProcessCmdLine(LPSTR lpCmdLine) msg += strUnsupported; msg += "\n"; msg += "Continue running AppleWin?"; - int res = MessageBox(GetDesktopWindow(), // NB. g_hFrameWindow is not yet valid + int res = GetFrame().FrameMessageBox( msg.c_str(), "AppleWin Command Line", MB_ICONSTOP | MB_SETFOREGROUND | MB_YESNO); diff --git a/source/Common.h b/source/Common.h index dafcaa7a..21c8b8af 100644 --- a/source/Common.h +++ b/source/Common.h @@ -134,15 +134,14 @@ enum AppMode_e #define REGVALUE_PREF_LAST_HARDDISK_2 "Last Harddisk Image 2" #define WM_USER_BENCHMARK WM_USER+1 -#define WM_USER_RESTART WM_USER+2 -#define WM_USER_SAVESTATE WM_USER+3 -#define WM_USER_LOADSTATE WM_USER+4 -#define VK_SNAPSHOT_560 WM_USER+5 // PrintScreen -#define VK_SNAPSHOT_280 WM_USER+6 // PrintScreen+Shift -#define WM_USER_TCP_SERIAL WM_USER+7 -#define WM_USER_BOOT WM_USER+8 -#define WM_USER_FULLSCREEN WM_USER+9 -#define VK_SNAPSHOT_TEXT WM_USER+10 // PrintScreen+Ctrl +#define WM_USER_SAVESTATE WM_USER+2 +#define WM_USER_LOADSTATE WM_USER+3 +#define VK_SNAPSHOT_560 WM_USER+4 // PrintScreen +#define VK_SNAPSHOT_280 WM_USER+5 // PrintScreen+Shift +#define WM_USER_TCP_SERIAL WM_USER+6 +#define WM_USER_BOOT WM_USER+7 +#define WM_USER_FULLSCREEN WM_USER+8 +#define VK_SNAPSHOT_TEXT WM_USER+9 // PrintScreen+Ctrl enum eIRQSRC {IS_6522=0, IS_SPEECH, IS_SSC, IS_MOUSE}; diff --git a/source/Configuration/PageDisk.cpp b/source/Configuration/PageDisk.cpp index 0720f54c..71a566a0 100644 --- a/source/Configuration/PageDisk.cpp +++ b/source/Configuration/PageDisk.cpp @@ -412,7 +412,7 @@ UINT CPageDisk::RemovalConfirmation(UINT uCommand) if (bMsgBox) { - int nRes = MessageBox(GetFrame().g_hFrameWindow, szText, TEXT("Eject/Unplug Warning"), MB_ICONWARNING | MB_YESNO | MB_SETFOREGROUND); + int nRes = GetFrame().FrameMessageBox(szText, TEXT("Eject/Unplug Warning"), MB_ICONWARNING | MB_YESNO | MB_SETFOREGROUND); if (nRes == IDNO) uCommand = 0; } diff --git a/source/Configuration/PropertySheetHelper.cpp b/source/Configuration/PropertySheetHelper.cpp index e80c2b2a..e9c9dfd3 100644 --- a/source/Configuration/PropertySheetHelper.cpp +++ b/source/Configuration/PropertySheetHelper.cpp @@ -285,7 +285,7 @@ void CPropertySheetHelper::PostMsgAfterClose(HWND hWnd, PAGETYPE page) return; } - UINT uAfterClose = 0; + bool restart = false; if (m_ConfigNew.m_Apple2Type == A2TYPE_CLONE) { @@ -310,11 +310,11 @@ void CPropertySheetHelper::PostMsgAfterClose(HWND hWnd, PAGETYPE page) ApplyNewConfig(); - uAfterClose = WM_USER_RESTART; + restart = true; } - if (uAfterClose) - PostMessage(GetFrame().g_hFrameWindow, uAfterClose, 0, 0); + if (restart) + GetFrame().Restart(); } bool CPropertySheetHelper::CheckChangesForRestart(HWND hWnd) diff --git a/source/Debugger/Debug.cpp b/source/Debugger/Debug.cpp index e472553b..2affeccc 100644 --- a/source/Debugger/Debug.cpp +++ b/source/Debugger/Debug.cpp @@ -2225,7 +2225,7 @@ void _CmdColorGet( const int iScheme, const int iColor ) { TCHAR sText[ CONSOLE_WIDTH ]; wsprintf( sText, "Color: %d\nOut of range!", iColor ); - MessageBox(GetFrame().g_hFrameWindow, sText, TEXT("ERROR"), MB_OK ); + GetFrame().FrameMessageBox(sText, TEXT("ERROR"), MB_OK ); } } @@ -3042,7 +3042,7 @@ void DisasmCalcTopFromCurAddress( bool bUpdateTop ) "\tLen: %04X\n" "\tMissed: %04X"), g_nDisasmCurAddress - nLen, nLen, g_nDisasmCurAddress ); - MessageBox( GetFrame().g_hFrameWindow, sText, "ERROR", MB_OK ); + GetFrame().FrameMessageBox( sText, "ERROR", MB_OK ); #endif } } diff --git a/source/Debugger/Debugger_Assembler.cpp b/source/Debugger/Debugger_Assembler.cpp index d9154675..8177fa48 100644 --- a/source/Debugger/Debugger_Assembler.cpp +++ b/source/Debugger/Debugger_Assembler.cpp @@ -471,7 +471,7 @@ int _6502_GetOpmodeOpbyte ( const int nBaseAddress, int & iOpmode_, int & nOpby #if _DEBUG if (! g_aOpcodes) { - MessageBox(GetFrame().g_hFrameWindow, "Debugger not properly initialized", "ERROR", MB_OK ); + GetFrame().FrameMessageBox("Debugger not properly initialized", "ERROR", MB_OK ); g_aOpcodes = & g_aOpcodes65C02[ 0 ]; // Enhanced Apple //e g_aOpmodes[ AM_2 ].m_nBytes = 2; diff --git a/source/Debugger/Debugger_Commands.cpp b/source/Debugger/Debugger_Commands.cpp index 005b62b4..33fb3b7c 100644 --- a/source/Debugger/Debugger_Commands.cpp +++ b/source/Debugger/Debugger_Commands.cpp @@ -518,7 +518,7 @@ void VerifyDebuggerCommandTable() if ( g_aCommands[ iCmd ].iCommand != iCmd) { sprintf( sText, "*** ERROR *** Enumerated Commands mis-matched at #%d!", iCmd ); - MessageBoxA(GetFrame().g_hFrameWindow, sText, TEXT("ERROR"), MB_OK ); + GetFrame().FrameMessageBox(sText, TEXT("ERROR"), MB_OK ); PostQuitMessage( 1 ); } } @@ -527,14 +527,14 @@ void VerifyDebuggerCommandTable() if (strcmp( g_aCommands[ NUM_COMMANDS ].m_sName, DEBUGGER__COMMANDS_VERIFY_TXT__)) { sprintf( sText, "*** ERROR *** Total Commands mis-matched!" ); - MessageBoxA(GetFrame().g_hFrameWindow, sText, TEXT("ERROR"), MB_OK ); + GetFrame().FrameMessageBox(sText, TEXT("ERROR"), MB_OK ); PostQuitMessage( 1 ); } if (strcmp( g_aParameters[ NUM_PARAMS ].m_sName, DEBUGGER__PARAMS_VERIFY_TXT__)) { sprintf( sText, "*** ERROR *** Total Parameters mis-matched!" ); - MessageBoxA(GetFrame().g_hFrameWindow, sText, TEXT("ERROR"), MB_OK ); + GetFrame().FrameMessageBox(sText, TEXT("ERROR"), MB_OK ); PostQuitMessage( 2 ); } } diff --git a/source/Debugger/Debugger_Display.cpp b/source/Debugger/Debugger_Display.cpp index d739759f..cc494ee9 100644 --- a/source/Debugger/Debugger_Display.cpp +++ b/source/Debugger/Debugger_Display.cpp @@ -758,7 +758,7 @@ static void PrintGlyph( const int xDst, const int yDst, const int glyph ) { #if _DEBUG if ((xDst < 0) || (yDst < 0)) - MessageBox(GetFrame().g_hFrameWindow, "X or Y out of bounds!", "PrintGlyph()", MB_OK ); + GetFrame().FrameMessageBox("X or Y out of bounds!", "PrintGlyph()", MB_OK ); #endif int col = xDst / CONSOLE_FONT_WIDTH ; int row = yDst / CONSOLE_FONT_HEIGHT; @@ -874,7 +874,7 @@ int PrintText ( const char * pText, RECT & rRect ) { #if _DEBUG if (! pText) - MessageBox(GetFrame().g_hFrameWindow, "pText = NULL!", "DrawText()", MB_OK ); + GetFrame().FrameMessageBox("pText = NULL!", "DrawText()", MB_OK ); #endif int nLen = strlen( pText ); @@ -4120,7 +4120,7 @@ void UpdateDisplay (Update_t bUpdate) if (spDrawMutex) { #if DEBUG - MessageBox( GetFrame().g_hFrameWindow, "Already drawing!", "!", MB_OK ); + GetFrame().FrameMessageBox( "Already drawing!", "!", MB_OK ); #endif } spDrawMutex = true; diff --git a/source/Disk.cpp b/source/Disk.cpp index a0128c00..14a4b12e 100644 --- a/source/Disk.cpp +++ b/source/Disk.cpp @@ -696,7 +696,7 @@ ImageError_e Disk2InterfaceCard::InsertDisk(const int drive, LPCTSTR pszImageFil { TCHAR szText[100+MAX_PATH]; StringCbPrintf(szText, sizeof(szText), "Only the first file in a multi-file zip is supported\nUse disk image '%s' ?", pFloppy->m_strFilenameInZip.c_str()); - int nRes = MessageBox(GetFrame().g_hFrameWindow, szText, TEXT("Multi-Zip Warning"), MB_ICONWARNING | MB_YESNO | MB_SETFOREGROUND); + int nRes = GetFrame().FrameMessageBox(szText, TEXT("Multi-Zip Warning"), MB_ICONWARNING | MB_YESNO | MB_SETFOREGROUND); if (nRes == IDNO) { EjectDisk(drive); @@ -825,8 +825,7 @@ void Disk2InterfaceCard::NotifyInvalidImage(const int drive, LPCTSTR pszImageFil return; } - MessageBox( - GetFrame().g_hFrameWindow, + GetFrame().FrameMessageBox( szBuffer, g_pAppTitle.c_str(), MB_ICONEXCLAMATION | MB_SETFOREGROUND); @@ -1563,7 +1562,7 @@ bool Disk2InterfaceCard::UserSelectNewDiskImage(const int drive, LPCSTR pszFilen { if (!IsDriveConnected(drive)) { - MessageBox(GetFrame().g_hFrameWindow, "Drive not connected!", "Insert disk", MB_ICONEXCLAMATION|MB_SETFOREGROUND|MB_OK); + GetFrame().FrameMessageBox("Drive not connected!", "Insert disk", MB_ICONEXCLAMATION|MB_SETFOREGROUND|MB_OK); return false; } @@ -1729,8 +1728,7 @@ bool Disk2InterfaceCard::DriveSwap(void) if (m_floppyDrive[DRIVE_1].m_spinning || m_floppyDrive[DRIVE_2].m_spinning) { // 1.26.2.4 Prompt when trying to swap disks while drive is on instead of silently failing - int status = MessageBox( - GetFrame().g_hFrameWindow, + int status = GetFrame().FrameMessageBox( "WARNING:\n" "\n" "\tAttempting to swap a disk while a drive is on\n" @@ -1777,21 +1775,9 @@ bool Disk2InterfaceCard::DriveSwap(void) //=========================================================================== -bool Disk2InterfaceCard::GetFirmware(LPCSTR lpName, BYTE* pDst) +bool Disk2InterfaceCard::GetFirmware(WORD lpNameId, BYTE* pDst) { - HRSRC hResInfo = FindResource(NULL, lpName, "FIRMWARE"); - if(hResInfo == NULL) - return false; - - DWORD dwResSize = SizeofResource(NULL, hResInfo); - if(dwResSize != DISK2_FW_SIZE) - return false; - - HGLOBAL hResData = LoadResource(NULL, hResInfo); - if(hResData == NULL) - return false; - - BYTE* pData = (BYTE*) LockResource(hResData); // NB. Don't need to unlock resource + BYTE* pData = GetFrame().GetResource(lpNameId, "FIRMWARE", DISK2_FW_SIZE); if (!pData) return false; @@ -1817,10 +1803,10 @@ void Disk2InterfaceCard::InitFirmware(LPBYTE pCxRomPeripheral) // TODO: LoadRom_Disk_Floppy() void Disk2InterfaceCard::Initialize(LPBYTE pCxRomPeripheral, UINT uSlot) { - bool res = GetFirmware(MAKEINTRESOURCE(IDR_DISK2_13SECTOR_FW), m_13SectorFirmware); + bool res = GetFirmware(IDR_DISK2_13SECTOR_FW, m_13SectorFirmware); _ASSERT(res); - res = GetFirmware(MAKEINTRESOURCE(IDR_DISK2_16SECTOR_FW), m_16SectorFirmware); + res = GetFirmware(IDR_DISK2_16SECTOR_FW, m_16SectorFirmware); _ASSERT(res); // Note: We used to disable the track stepping delay in the Disk II controller firmware by diff --git a/source/Disk.h b/source/Disk.h index 4a240089..baaf5421 100644 --- a/source/Disk.h +++ b/source/Disk.h @@ -203,7 +203,7 @@ private: void SetSequencerFunction(WORD addr); void DumpSectorWOZ(FloppyDisk floppy); void DumpTrackWOZ(FloppyDisk floppy); - bool GetFirmware(LPCSTR lpName, BYTE* pDst); + bool GetFirmware(WORD lpNameId, BYTE* pDst); void InitFirmware(LPBYTE pCxRomPeripheral); void UpdateLatchForEmptyDrive(FloppyDrive* pDrive); diff --git a/source/DiskImageHelper.cpp b/source/DiskImageHelper.cpp index f7778343..8e2b48ce 100644 --- a/source/DiskImageHelper.cpp +++ b/source/DiskImageHelper.cpp @@ -40,6 +40,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "DiskImage.h" #include "Log.h" #include "Memory.h" +#include "Interface.h" ImageInfo::ImageInfo() { @@ -2051,7 +2052,7 @@ CImageBase* CDiskImageHelper::Detect(LPBYTE pImage, DWORD dwSize, const TCHAR* p if (pWozHdr->crc32 && // WOZ spec: CRC of 0 should be ignored pWozHdr->crc32 != crc32(0, pImage+sizeof(CWOZHelper::WOZHeader), dwSize-sizeof(CWOZHelper::WOZHeader))) { - int res = MessageBox(GetDesktopWindow(), "CRC mismatch\nContinue using image?", "AppleWin: WOZ Header", MB_ICONSTOP | MB_SETFOREGROUND | MB_YESNO); + int res = GetFrame().FrameMessageBox("CRC mismatch\nContinue using image?", "AppleWin: WOZ Header", MB_ICONSTOP | MB_SETFOREGROUND | MB_YESNO); if (res == IDNO) return NULL; } diff --git a/source/FrameBase.cpp b/source/FrameBase.cpp index ea41ea20..b0b7d89d 100644 --- a/source/FrameBase.cpp +++ b/source/FrameBase.cpp @@ -83,7 +83,7 @@ void FrameBase::Video_TakeScreenShot(const Video::VideoScreenShot_e ScreenShotTy { TCHAR msg[512]; StringCbPrintf(msg, 512, "You have more then %d screenshot filenames! They will no longer be saved.\n\nEither move some of your screenshots or increase the maximum in video.cpp\n", nMaxScreenShot); - MessageBox(GetFrame().g_hFrameWindow, msg, "Warning", MB_OK); + FrameMessageBox(msg, "Warning", MB_OK); g_nLastScreenShot = 0; return; } @@ -114,7 +114,7 @@ void FrameBase::Video_SaveScreenShot(const Video::VideoScreenShot_e ScreenShotTy if (g_bDisplayPrintScreenFileName) { - MessageBox(GetFrame().g_hFrameWindow, pScreenShotFileName, "Screen Captured", MB_OK); + FrameMessageBox(pScreenShotFileName, "Screen Captured", MB_OK); } } diff --git a/source/FrameBase.h b/source/FrameBase.h index 6ebbf677..bcf267ef 100644 --- a/source/FrameBase.h +++ b/source/FrameBase.h @@ -34,6 +34,21 @@ public: virtual void VideoPresentScreen(void) = 0; + // this function has the same interface as MessageBox in windows.h + virtual int FrameMessageBox(LPCSTR lpText, LPCSTR lpCaption, UINT uType) = 0; + + // this function merges LoadBitmap and GetBitmapBits from windows.h + virtual void GetBitmap(LPCSTR lpBitmapName, LONG cb, LPVOID lpvBits) = 0; + + // FindResource, MAKEINTRESOURCE, SizeofResource, LoadResource, LockResource + // Return pointer to resource if size is correct. + // NULL if resource is invalid or size check fails + // The pointer is only valid until the next call to GetResource + // (in Windows, the pointer is valid forever, but it would be very restrictive to force this on other FrameBase implementations) + virtual BYTE* GetResource(WORD id, LPCSTR lpType, DWORD expectedSize) = 0; + + virtual void Restart() = 0; + void VideoRefreshScreen(uint32_t uRedrawWholeScreenVideoMode, bool bRedrawWholeScreen); void VideoRedrawScreen(void); void VideoRedrawScreenDuringFullSpeed(DWORD dwCyclesThisFrame, bool bInit = false); diff --git a/source/Harddisk.cpp b/source/Harddisk.cpp index ccbcb965..7a70b0ed 100644 --- a/source/Harddisk.cpp +++ b/source/Harddisk.cpp @@ -362,19 +362,7 @@ void HD_Load_Rom(const LPBYTE pCxRomPeripheral, const UINT uSlot) if(!g_bHD_Enabled) return; - HRSRC hResInfo = FindResource(NULL, MAKEINTRESOURCE(IDR_HDDRVR_FW), "FIRMWARE"); - if(hResInfo == NULL) - return; - - DWORD dwResSize = SizeofResource(NULL, hResInfo); - if(dwResSize != HDDRVR_SIZE) - return; - - HGLOBAL hResData = LoadResource(NULL, hResInfo); - if(hResData == NULL) - return; - - BYTE* pData = (BYTE*) LockResource(hResData); // NB. Don't need to unlock resource + BYTE* pData = GetFrame().GetResource(IDR_HDDRVR_FW, "FIRMWARE", HDDRVR_SIZE); if(pData == NULL) return; diff --git a/source/Memory.cpp b/source/Memory.cpp index b4855a1d..b192531b 100644 --- a/source/Memory.cpp +++ b/source/Memory.cpp @@ -1493,8 +1493,7 @@ void MemInitialize() if (!memaux || !memdirty || !memimage || !memmain || !memrom || !pCxRomInternal || !pCxRomPeripheral) { - MessageBox( - GetDesktopWindow(), + GetFrame().FrameMessageBox( TEXT("The emulator was unable to allocate the memory it ") TEXT("requires. Further execution is not possible."), g_pAppTitle.c_str(), @@ -1535,22 +1534,28 @@ void MemInitializeROM(void) { // READ THE APPLE FIRMWARE ROMS INTO THE ROM IMAGE UINT ROM_SIZE = 0; - HRSRC hResInfo = NULL; + WORD resourceId = 0; switch (g_Apple2Type) { - case A2TYPE_APPLE2: hResInfo = FindResource(NULL, MAKEINTRESOURCE(IDR_APPLE2_ROM ), "ROM"); ROM_SIZE = Apple2RomSize ; break; - case A2TYPE_APPLE2PLUS: hResInfo = FindResource(NULL, MAKEINTRESOURCE(IDR_APPLE2_PLUS_ROM ), "ROM"); ROM_SIZE = Apple2RomSize ; break; - case A2TYPE_APPLE2JPLUS: hResInfo = FindResource(NULL, MAKEINTRESOURCE(IDR_APPLE2_JPLUS_ROM ), "ROM"); ROM_SIZE = Apple2RomSize ; break; - case A2TYPE_APPLE2E: hResInfo = FindResource(NULL, MAKEINTRESOURCE(IDR_APPLE2E_ROM ), "ROM"); ROM_SIZE = Apple2eRomSize; break; - case A2TYPE_APPLE2EENHANCED:hResInfo = FindResource(NULL, MAKEINTRESOURCE(IDR_APPLE2E_ENHANCED_ROM), "ROM"); ROM_SIZE = Apple2eRomSize; break; - case A2TYPE_PRAVETS82: hResInfo = FindResource(NULL, MAKEINTRESOURCE(IDR_PRAVETS_82_ROM ), "ROM"); ROM_SIZE = Apple2RomSize ; break; - case A2TYPE_PRAVETS8M: hResInfo = FindResource(NULL, MAKEINTRESOURCE(IDR_PRAVETS_8M_ROM ), "ROM"); ROM_SIZE = Apple2RomSize ; break; - case A2TYPE_PRAVETS8A: hResInfo = FindResource(NULL, MAKEINTRESOURCE(IDR_PRAVETS_8C_ROM ), "ROM"); ROM_SIZE = Apple2eRomSize; break; - case A2TYPE_TK30002E: hResInfo = FindResource(NULL, MAKEINTRESOURCE(IDR_TK3000_2E_ROM ), "ROM"); ROM_SIZE = Apple2eRomSize; break; - case A2TYPE_BASE64A: hResInfo = FindResource(NULL, MAKEINTRESOURCE(IDR_BASE_64A_ROM ), "ROM"); ROM_SIZE = Base64ARomSize; break; + case A2TYPE_APPLE2: resourceId = IDR_APPLE2_ROM ; ROM_SIZE = Apple2RomSize ; break; + case A2TYPE_APPLE2PLUS: resourceId = IDR_APPLE2_PLUS_ROM ; ROM_SIZE = Apple2RomSize ; break; + case A2TYPE_APPLE2JPLUS: resourceId = IDR_APPLE2_JPLUS_ROM ; ROM_SIZE = Apple2RomSize ; break; + case A2TYPE_APPLE2E: resourceId = IDR_APPLE2E_ROM ; ROM_SIZE = Apple2eRomSize; break; + case A2TYPE_APPLE2EENHANCED:resourceId = IDR_APPLE2E_ENHANCED_ROM; ROM_SIZE = Apple2eRomSize; break; + case A2TYPE_PRAVETS82: resourceId = IDR_PRAVETS_82_ROM ; ROM_SIZE = Apple2RomSize ; break; + case A2TYPE_PRAVETS8M: resourceId = IDR_PRAVETS_8M_ROM ; ROM_SIZE = Apple2RomSize ; break; + case A2TYPE_PRAVETS8A: resourceId = IDR_PRAVETS_8C_ROM ; ROM_SIZE = Apple2eRomSize; break; + case A2TYPE_TK30002E: resourceId = IDR_TK3000_2E_ROM ; ROM_SIZE = Apple2eRomSize; break; + case A2TYPE_BASE64A: resourceId = IDR_BASE_64A_ROM ; ROM_SIZE = Base64ARomSize; break; } - if (hResInfo == NULL) + BYTE* pData = NULL; + if (resourceId) + { + pData = GetFrame().GetResource(resourceId, "ROM", ROM_SIZE); + } + + if (pData == NULL) { TCHAR sRomFileName[ MAX_PATH ]; switch (g_Apple2Type) @@ -1577,8 +1582,7 @@ void MemInitializeROM(void) LogFileOutput("%s\n", sText); - MessageBox( - GetDesktopWindow(), + GetFrame().FrameMessageBox( sText, g_pAppTitle.c_str(), MB_ICONSTOP | MB_SETFOREGROUND); @@ -1586,18 +1590,6 @@ void MemInitializeROM(void) ExitProcess(1); } - DWORD dwResSize = SizeofResource(NULL, hResInfo); - if(dwResSize != ROM_SIZE) - return; - - HGLOBAL hResData = LoadResource(NULL, hResInfo); - if(hResData == NULL) - return; - - BYTE* pData = (BYTE*) LockResource(hResData); // NB. Don't need to unlock resource - if (pData == NULL) - return; - memset(pCxRomInternal,0,CxRomSize); memset(pCxRomPeripheral,0,CxRomSize); @@ -1617,32 +1609,18 @@ void MemInitializeCustomF8ROM(void) { const UINT F8RomSize = 0x800; const UINT F8RomOffset = Apple2RomSize-F8RomSize; + FrameBase& frame = GetFrame(); if (IsApple2Original(GetApple2Type()) && GetCardMgr().QuerySlot(SLOT0) == CT_LanguageCard) { - try + BYTE* pData = frame.GetResource(IDR_APPLE2_PLUS_ROM, "ROM", Apple2RomSize); + if (pData == NULL) { - HRSRC hResInfo = FindResource(NULL, MAKEINTRESOURCE(IDR_APPLE2_PLUS_ROM), "ROM"); - if (hResInfo == NULL) - throw false; - - DWORD dwResSize = SizeofResource(NULL, hResInfo); - if(dwResSize != Apple2RomSize) - throw false; - - HGLOBAL hResData = LoadResource(NULL, hResInfo); - if(hResData == NULL) - throw false; - - BYTE* pData = (BYTE*) LockResource(hResData); // NB. Don't need to unlock resource - if (pData == NULL) - throw false; - - memcpy(memrom+F8RomOffset, pData+F8RomOffset, F8RomSize); + frame.FrameMessageBox("Failed to read F8 (auto-start) ROM for language card in original Apple][", TEXT("AppleWin Error"), MB_OK); } - catch (bool) + else { - MessageBox( GetFrame().g_hFrameWindow, "Failed to read F8 (auto-start) ROM for language card in original Apple][", TEXT("AppleWin Error"), MB_OK ); + memcpy(memrom+F8RomOffset, pData+F8RomOffset, F8RomSize); } } @@ -1663,7 +1641,7 @@ void MemInitializeCustomF8ROM(void) if (!bRes) { - MessageBox( GetFrame().g_hFrameWindow, "Failed to read custom F8 rom", TEXT("AppleWin Error"), MB_OK ); + GetFrame().FrameMessageBox( "Failed to read custom F8 rom", TEXT("AppleWin Error"), MB_OK ); CloseHandle(g_hCustomRomF8); g_hCustomRomF8 = INVALID_HANDLE_VALUE; // Failed, so use default rom... @@ -1672,12 +1650,8 @@ void MemInitializeCustomF8ROM(void) if (GetPropertySheet().GetTheFreezesF8Rom() && IS_APPLE2) { - HGLOBAL hResData = NULL; - BYTE* pData = NULL; - - HRSRC hResInfo = FindResource(NULL, MAKEINTRESOURCE(IDR_FREEZES_F8_ROM), "ROM"); - - if (hResInfo && (SizeofResource(NULL, hResInfo) == 0x800) && (hResData = LoadResource(NULL, hResInfo)) && (pData = (BYTE*) LockResource(hResData))) + BYTE* pData = frame.GetResource(IDR_FREEZES_F8_ROM, "ROM", 0x800); + if (pData) { memcpy(memrom+Apple2RomSize-F8RomSize, pData, F8RomSize); } @@ -1719,7 +1693,7 @@ void MemInitializeCustomROM(void) if (!bRes) { - MessageBox( GetFrame().g_hFrameWindow, "Failed to read custom rom", TEXT("AppleWin Error"), MB_OK ); + GetFrame().FrameMessageBox( "Failed to read custom rom", TEXT("AppleWin Error"), MB_OK ); CloseHandle(g_hCustomRom); g_hCustomRom = INVALID_HANDLE_VALUE; // Failed, so use default rom... diff --git a/source/MouseInterface.cpp b/source/MouseInterface.cpp index de002df8..cd348929 100644 --- a/source/MouseInterface.cpp +++ b/source/MouseInterface.cpp @@ -164,20 +164,7 @@ void CMouseInterface::InitializeROM(void) return; const UINT FW_SIZE = 2*1024; - - HRSRC hResInfo = FindResource(NULL, MAKEINTRESOURCE(IDR_MOUSEINTERFACE_FW), "FIRMWARE"); - if(hResInfo == NULL) - return; - - DWORD dwResSize = SizeofResource(NULL, hResInfo); - if(dwResSize != FW_SIZE) - return; - - HGLOBAL hResData = LoadResource(NULL, hResInfo); - if(hResData == NULL) - return; - - BYTE* pData = (BYTE*) LockResource(hResData); // NB. Don't need to unlock resource + BYTE* pData = GetFrame().GetResource(IDR_MOUSEINTERFACE_FW, "FIRMWARE", FW_SIZE); if(pData == NULL) return; diff --git a/source/NTSC_CharSet.cpp b/source/NTSC_CharSet.cpp index bd264740..e4ae9087 100644 --- a/source/NTSC_CharSet.cpp +++ b/source/NTSC_CharSet.cpp @@ -76,8 +76,7 @@ static void get_csbits(csbits_t csbits, const char* resourceName, const UINT cy0 const UINT bufferSize = bitmapWidthBytes*bitmapHeight; BYTE* pBuffer = new BYTE [bufferSize]; - HBITMAP hCharBitmap = LoadBitmap(GetFrame().g_hInstance, resourceName); - GetBitmapBits(hCharBitmap, bufferSize, pBuffer); + GetFrame().GetBitmap(resourceName, bufferSize, pBuffer); for (UINT cy=cy0, ch=0; cy 0x400)) - if (MessageBox(g_hFrameWindow, + if (FrameMessageBox( TEXT("The emulator has detected a problem while running ") TEXT("the CPU benchmark. Would you like to gather more ") TEXT("information?"), @@ -261,13 +261,13 @@ void Win32Frame::Benchmark(void) (unsigned)loop, (unsigned)lastpc, (unsigned)regs.pc); - MessageBox(g_hFrameWindow, + FrameMessageBox( outstr, TEXT("Benchmarks"), MB_ICONINFORMATION | MB_SETFOREGROUND); } else - MessageBox(g_hFrameWindow, + FrameMessageBox( TEXT("The emulator was unable to locate the exact ") TEXT("point of the error. This probably means that ") TEXT("the problem is external to the emulator, ") @@ -321,7 +321,7 @@ void Win32Frame::Benchmark(void) (unsigned)(totalmhz10[0] / 10), (unsigned)(totalmhz10[0] % 10), (LPCTSTR)(IS_APPLE2 ? TEXT(" (6502)") : TEXT("")), (unsigned)(totalmhz10[1] / 10), (unsigned)(totalmhz10[1] % 10), (LPCTSTR)(IS_APPLE2 ? TEXT(" (6502)") : TEXT("")), (unsigned)realisticfps); - MessageBox(g_hFrameWindow, + FrameMessageBox( outstr, TEXT("Benchmarks"), MB_ICONINFORMATION | MB_SETFOREGROUND); @@ -575,3 +575,42 @@ Win32Frame& Win32Frame::GetWin32Frame() Win32Frame& win32Frame = dynamic_cast(frameBase); return win32Frame; } + +int Win32Frame::FrameMessageBox(LPCSTR lpText, LPCSTR lpCaption, UINT uType) +{ + const HWND handle = g_hFrameWindow ? g_hFrameWindow : GetDesktopWindow(); + return MessageBox(handle, lpText, lpCaption, uType); +} + +void Win32Frame::GetBitmap(LPCSTR lpBitmapName, LONG cb, LPVOID lpvBits) +{ + HBITMAP hBitmap = LoadBitmap(g_hInstance, lpBitmapName); + GetBitmapBits(hBitmap, cb, lpvBits); + DeleteObject(hBitmap); +} + +void Win32Frame::Restart() +{ + // Changed h/w config, eg. Apple computer type (][+ or //e), slot configuration, etc. + g_bRestart = true; + PostMessage(g_hFrameWindow, WM_CLOSE, 0, 0); +} + +BYTE* Win32Frame::GetResource(WORD id, LPCSTR lpType, DWORD dwExpectedSize) +{ + HRSRC hResInfo = FindResource(NULL, MAKEINTRESOURCE(id), lpType); + if (hResInfo == NULL) + return NULL; + + DWORD dwResSize = SizeofResource(NULL, hResInfo); + if (dwResSize != dwExpectedSize) + return NULL; + + HGLOBAL hResData = LoadResource(NULL, hResInfo); + if (hResData == NULL) + return NULL; + + BYTE* pResource = (BYTE*)LockResource(hResData); // NB. Don't need to unlock resource + + return pResource; +} diff --git a/source/Windows/Win32Frame.h b/source/Windows/Win32Frame.h index 0328ef35..41070172 100644 --- a/source/Windows/Win32Frame.h +++ b/source/Windows/Win32Frame.h @@ -48,6 +48,11 @@ public: virtual void Destroy(void); virtual void VideoPresentScreen(void); + virtual int FrameMessageBox(LPCSTR lpText, LPCSTR lpCaption, UINT uType); + virtual void GetBitmap(LPCSTR lpBitmapName, LONG cb, LPVOID lpvBits); + virtual BYTE* GetResource(WORD id, LPCSTR lpType, DWORD expectedSize); + virtual void Restart(); + bool GetFullScreenShowSubunitStatus(void); int GetFullScreenOffsetX(void); int GetFullScreenOffsetY(void); diff --git a/source/Windows/WinFrame.cpp b/source/Windows/WinFrame.cpp index c4df2e6f..6fe59df7 100644 --- a/source/Windows/WinFrame.cpp +++ b/source/Windows/WinFrame.cpp @@ -981,6 +981,7 @@ LRESULT Win32Frame::WndProc( DeleteGdiObjects(); DIMouse::DirectInputUninit(window); // NB. do before window is destroyed PostQuitMessage(0); // Post WM_QUIT message to the thread's message queue + g_hFrameWindow = (HWND)0; LogFileOutput("WM_DESTROY (done)\n"); break; @@ -1709,12 +1710,6 @@ LRESULT Win32Frame::WndProc( break; } - case WM_USER_RESTART: - // Changed h/w config, eg. Apple computer type (][+ or //e), slot configuration, etc. - g_bRestart = true; - PostMessage(window,WM_CLOSE,0,0); - break; - case WM_USER_SAVESTATE: // Save state Snapshot_SaveState(); break; @@ -1823,7 +1818,7 @@ bool Win32Frame::ConfirmReboot(bool bFromButtonUI) if (!bFromButtonUI || !g_bConfirmReboot) return true; - int res = MessageBox(g_hFrameWindow, + int res = FrameMessageBox( "Are you sure you want to reboot?\n" "(All data will be lost!)\n" "\n" @@ -2055,7 +2050,7 @@ void Win32Frame::ProcessDiskPopupMenu(HWND hwnd, POINT pt, const int iDrive) //if(!filename1.compare("\"\"") == false) //Do not use this, for some reason it does not work!!! if(!filename1.compare(sFileNameEmpty) ) { - int MB_Result = MessageBox(g_hFrameWindow, "No disk image loaded. Do you want to run CiderPress anyway?" ,"No disk image.", MB_ICONINFORMATION|MB_YESNO); + int MB_Result = FrameMessageBox("No disk image loaded. Do you want to run CiderPress anyway?" ,"No disk image.", MB_ICONINFORMATION|MB_YESNO); if (MB_Result == IDYES) { if (FileExists (PathToCiderPress )) @@ -2064,7 +2059,7 @@ void Win32Frame::ProcessDiskPopupMenu(HWND hwnd, POINT pt, const int iDrive) } else { - MessageBox(g_hFrameWindow, szCiderpressNotFoundText, szCiderpressNotFoundCaption, MB_ICONINFORMATION|MB_OK); + FrameMessageBox(szCiderpressNotFoundText, szCiderpressNotFoundCaption, MB_ICONINFORMATION|MB_OK); } } } @@ -2076,7 +2071,7 @@ void Win32Frame::ProcessDiskPopupMenu(HWND hwnd, POINT pt, const int iDrive) } else { - MessageBox(g_hFrameWindow, szCiderpressNotFoundText, szCiderpressNotFoundCaption, MB_ICONINFORMATION|MB_OK); + FrameMessageBox(szCiderpressNotFoundText, szCiderpressNotFoundCaption, MB_ICONINFORMATION|MB_OK); } } }