diff --git a/source/Debugger/Debug.cpp b/source/Debugger/Debug.cpp index d011686a..36c9cec9 100644 --- a/source/Debugger/Debug.cpp +++ b/source/Debugger/Debug.cpp @@ -311,7 +311,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA bool g_bTraceHeader = false; // semaphore, flag header to be printed DWORD extbench = 0; - int g_bDebuggerViewingAppleOutput = false; // NOTE: alias for bVideoModeFlags! bool g_bIgnoreNextKey = false; @@ -380,6 +379,67 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA WORD DisasmCalcAddressFromLines( WORD iAddress, int nLines ); +// DebugVideoMode _____________________________________________________________ + +// Fix for GH#345 +// Wrap & protect the debugger's video mode in its own class: +// . This may seem like overkill but it stops the video mode being (erroneously) additionally used as a flag. +// . VideoMode is a bitmap of video flags and a VideoMode value of zero is a valid video mode (GR,PAGE1,non-mixed). +class DebugVideoMode // NB. Implemented as a singleton +{ +protected: + DebugVideoMode() + { + Reset(); + } + +public: + ~DebugVideoMode(){} + + static DebugVideoMode& Instance() + { + return m_Instance; + } + + void Reset(void) + { + m_bIsVideoModeValid = false; + m_uVideoMode = 0; + } + + bool IsSet(void) + { + return m_bIsVideoModeValid; + } + + bool Get(UINT* pVideoMode) + { + if (pVideoMode) + *pVideoMode = m_bIsVideoModeValid ? m_uVideoMode : 0; + return m_bIsVideoModeValid; + } + + void Set(UINT videoMode) + { + m_bIsVideoModeValid = true; + m_uVideoMode = videoMode; + } + +private: + bool m_bIsVideoModeValid; + UINT m_uVideoMode; + + static DebugVideoMode m_Instance; +}; + +DebugVideoMode DebugVideoMode::m_Instance; + +bool DebugGetVideoMode(UINT* pVideoMode) +{ + return DebugVideoMode::Instance().Get(pVideoMode); +} + + // File _______________________________________________________________________ int _GetFileSize( FILE *hFile ) @@ -6728,11 +6788,8 @@ Update_t _ViewOutput( ViewVideoPage_t iPage, int bVideoModeFlags ) default: break; } -#if _DEBUG - if (bVideoModeFlags == 0) - MessageBoxA( NULL, "bVideoModeFlags = ZERO !?", "Information", MB_OK ); -#endif - g_bDebuggerViewingAppleOutput = bVideoModeFlags; + + DebugVideoMode::Instance().Set(bVideoModeFlags); VideoRefreshScreen( bVideoModeFlags, true ); return UPDATE_NOTHING; // intentional } @@ -6766,11 +6823,11 @@ Update_t _ViewOutput( ViewVideoPage_t iPage, int bVideoModeFlags ) // Lo-Res Update_t CmdViewOutput_GRX (int nArgs) { - return _ViewOutput( VIEW_PAGE_X, VF_80STORE ); // NTSC VideoRefresh() Hack: flags != 0 + return _ViewOutput( VIEW_PAGE_X, 0 ); } Update_t CmdViewOutput_GR1 (int nArgs) { - return _ViewOutput( VIEW_PAGE_1, VF_80STORE ); // NTSC VideoRefresh() Hack: flags != 0 + return _ViewOutput( VIEW_PAGE_1, 0 ); } Update_t CmdViewOutput_GR2 (int nArgs) { @@ -7286,7 +7343,8 @@ Update_t CmdWindowViewData (int nArgs) Update_t CmdWindowViewOutput (int nArgs) { VideoRedrawScreen(); - g_bDebuggerViewingAppleOutput = true; + + DebugVideoMode::Instance().Set(g_uVideoMode); return UPDATE_NOTHING; // intentional } @@ -8421,7 +8479,7 @@ void DebugBegin () g_nDisasmCurAddress = regs.pc; DisasmCalcTopBotAddress(); - g_bDebuggerViewingAppleOutput = false; + DebugVideoMode::Instance().Reset(); UpdateDisplay( UPDATE_ALL ); @@ -9106,7 +9164,7 @@ void DebuggerProcessKey( int keycode ) if (g_nAppMode != MODE_DEBUG) return; - if (g_bDebuggerViewingAppleOutput) + if (DebugVideoMode::Instance().IsSet()) { if ((VK_SHIFT == keycode) || (VK_CONTROL == keycode) || (VK_MENU == keycode)) { @@ -9116,7 +9174,7 @@ void DebuggerProcessKey( int keycode ) // Normally any key press takes us out of "Viewing Apple Output" g_nAppMode // VK_F# are already processed, so we can't use them to cycle next video g_nAppMode // if ((g_nAppMode != MODE_LOGO) && (g_nAppMode != MODE_DEBUG)) - g_bDebuggerViewingAppleOutput = false; + DebugVideoMode::Instance().Reset(); UpdateDisplay( UPDATE_ALL ); // 1 return; } @@ -9475,7 +9533,7 @@ void DebuggerProcessKey( int keycode ) } // switch } - if (bUpdateDisplay && !g_bDebuggerViewingAppleOutput) // & UPDATE_BACKGROUND) + if (bUpdateDisplay && !DebugVideoMode::Instance().IsSet()) // & UPDATE_BACKGROUND) UpdateDisplay( bUpdateDisplay ); } @@ -9509,7 +9567,7 @@ void DebuggerCursorUpdate() static DWORD nBeg = GetTickCount(); // timeGetTime(); DWORD nNow = GetTickCount(); // timeGetTime(); - if (((nNow - nBeg) >= nUpdateInternal_ms) && !g_bDebuggerViewingAppleOutput) + if (((nNow - nBeg) >= nUpdateInternal_ms) && !DebugVideoMode::Instance().IsSet()) { nBeg = nNow; diff --git a/source/Debugger/Debug.h b/source/Debugger/Debug.h index add6cca5..c05f897c 100644 --- a/source/Debugger/Debug.h +++ b/source/Debugger/Debug.h @@ -104,9 +104,6 @@ // Disassembly extern int g_aDisasmTargets[ MAX_DISPLAY_LINES ]; -// Display - extern int g_bDebuggerViewingAppleOutput; - // Font extern int g_nFontHeight; extern int g_iFontSpacing; @@ -238,6 +235,8 @@ DEBUG_TOGGLE_KEY = VK_F1 + BTN_DEBUG }; + bool DebugGetVideoMode(UINT* pVideoMode); + void DebugBegin (); void DebugContinueStepping (); void DebugDestroy (); diff --git a/source/Debugger/Debugger_Display.cpp b/source/Debugger/Debugger_Display.cpp index 7bb24bfd..bc9651e1 100644 --- a/source/Debugger/Debugger_Display.cpp +++ b/source/Debugger/Debugger_Display.cpp @@ -789,7 +789,7 @@ void DebuggerPrintColor( int x, int y, const conchar_t * pText ) //=========================================================================== bool CanDrawDebugger() { - if (g_bDebuggerViewingAppleOutput) + if (DebugGetVideoMode(NULL)) return false; if ((g_nAppMode == MODE_DEBUG) || (g_nAppMode == MODE_STEPPING)) diff --git a/source/Frame.cpp b/source/Frame.cpp index 3020acaf..a482d15d 100644 --- a/source/Frame.cpp +++ b/source/Frame.cpp @@ -1177,7 +1177,7 @@ LRESULT CALLBACK FrameWndProc ( size_t nSize = 0; // if viewing the debugger, get the last virtual debugger screen - if ((g_nAppMode == MODE_DEBUG) && !g_bDebuggerViewingAppleOutput) + if ((g_nAppMode == MODE_DEBUG) && !DebugGetVideoMode(NULL)) nSize = Util_GetDebuggerText( pText ); else nSize = Util_GetTextScreen( pText ); @@ -1244,7 +1244,16 @@ LRESULT CALLBACK FrameWndProc ( VideoReinitialize(); if (g_nAppMode != MODE_LOGO) { - VideoRefreshScreen( g_nAppMode == MODE_DEBUG ? g_bDebuggerViewingAppleOutput : 0); + if (g_nAppMode == MODE_DEBUG) + { + UINT debugVideoMode; + bool bIsVideoModeValid = DebugGetVideoMode(&debugVideoMode); + VideoRefreshScreen( bIsVideoModeValid ? debugVideoMode : 0, bIsVideoModeValid ); + } + else + { + VideoRefreshScreen(0); + } } Config_Save_Video(); diff --git a/source/Video.cpp b/source/Video.cpp index c8a8a960..d7025779 100644 --- a/source/Video.cpp +++ b/source/Video.cpp @@ -1129,7 +1129,7 @@ void VideoRedrawScreenAfterFullSpeed(DWORD dwCyclesThisFrame) void VideoRedrawScreen (void) { - // NB. Can't rely on g_uVideoMode being non-zero (ie. so it can double up as a flag) since 'non-mixed GR' mode == 0x00. + // NB. Can't rely on g_uVideoMode being non-zero (ie. so it can double up as a flag) since 'GR,PAGE1,non-mixed' mode == 0x00. VideoRefreshScreen( g_uVideoMode, true ); } @@ -1193,7 +1193,7 @@ static void VideoFrameBufferAdjust(int& xSrc, int& ySrc, bool bInvertY=false) ySrc += dy; } -void VideoRefreshScreen ( int bVideoModeFlags, bool bRedrawWholeScreen /* =false*/ ) +void VideoRefreshScreen ( int uRedrawWholeScreenVideoMode /* =0*/, bool bRedrawWholeScreen /* =false*/ ) { #if defined(_DEBUG) && defined(DEBUG_REFRESH_TIMINGS) DebugRefresh(0); @@ -1201,11 +1201,11 @@ void VideoRefreshScreen ( int bVideoModeFlags, bool bRedrawWholeScreen /* =false if (bRedrawWholeScreen || g_nAppMode == MODE_PAUSED) { - // bVideoModeFlags set if: + // uVideoModeForWholeScreen set if: // . MODE_DEBUG : always // . MODE_RUNNING : called from VideoRedrawScreen(), eg. during full-speed if (bRedrawWholeScreen) - NTSC_SetVideoMode( bVideoModeFlags ); + NTSC_SetVideoMode( uRedrawWholeScreenVideoMode ); NTSC_VideoRedrawWholeScreen(); } diff --git a/source/Video.h b/source/Video.h index 2c6a8ac7..f7decf3d 100644 --- a/source/Video.h +++ b/source/Video.h @@ -172,7 +172,7 @@ void VideoRealizePalette (HDC); void VideoRedrawScreenDuringFullSpeed(DWORD dwCyclesThisFrame, bool bInit = false); void VideoRedrawScreenAfterFullSpeed(DWORD dwCyclesThisFrame); void VideoRedrawScreen (void); -void VideoRefreshScreen (int bVideoFlags, bool bRedrawWholeScreen = false); +void VideoRefreshScreen (int uRedrawWholeScreenVideoMode = 0, bool bRedrawWholeScreen = false); void VideoReinitialize (); void VideoResetState (); WORD VideoGetScannerAddress(bool* pbVblBar_OUT, const DWORD uExecutedCycles);