From ae233fe1fcfe00412fbc8ecf1a188eff03adace5 Mon Sep 17 00:00:00 2001 From: tomcw Date: Tue, 8 Jul 2014 20:58:48 +0100 Subject: [PATCH] Remove redundant 'BOOL behind' which was always zero. - allowed some simplification to VideoSetMode() Tidy up ContinueExecution(), removing unused 'BOOL pageflipping'. Refactor VideoCheckPage() to make it more readable. --- source/Applewin.cpp | 23 +++++--------------- source/Applewin.h | 1 - source/Video.cpp | 52 +++++++++++++++++++++++++-------------------- 3 files changed, 34 insertions(+), 42 deletions(-) diff --git a/source/Applewin.cpp b/source/Applewin.cpp index 34dcb502..ccceefea 100644 --- a/source/Applewin.cpp +++ b/source/Applewin.cpp @@ -44,7 +44,6 @@ TCHAR *g_pAppTitle = TITLE_APPLE_2E_ENHANCED; eApple2Type g_Apple2Type = A2TYPE_APPLE2EENHANCED; -BOOL behind = 0; // Redundant DWORD cumulativecycles = 0; // Wraps after ~1hr 9mins DWORD cyclenum = 0; // Used by SpkrToggle() for non-wave sound DWORD emulmsec = 0; @@ -163,8 +162,6 @@ void SetPriorityNormal(void) void ContinueExecution(void) { - static BOOL pageflipping = 0; //? - const double fUsecPerSec = 1.e6; #if 1 const UINT nExecutionPeriodUsec = 1000; // 1.0ms @@ -241,22 +238,16 @@ void ContinueExecution(void) emulmsec_frac %= CLKS_PER_MS; } - // - // DETERMINE WHETHER THE SCREEN WAS UPDATED, THE DISK WAS SPINNING, - // OR THE KEYBOARD I/O PORTS WERE BEING EXCESSIVELY QUERIED THIS CLOCKTICK - VideoCheckPage(0); - BOOL screenupdated = VideoHasRefreshed(); - BOOL systemidle = 0; //(KeybGetNumQueries() > (clockgran << 2)); // && (!ranfinegrain); // TO DO - - if (screenupdated) - pageflipping = 3; - // if (g_dwCyclesThisFrame >= dwClksPerFrame) { g_dwCyclesThisFrame -= dwClksPerFrame; + // DETERMINE WHETHER THE SCREEN WAS UPDATED THIS CLOCKTICK + VideoCheckPage(0); // force=0 + const BOOL screenupdated = VideoHasRefreshed(); // Only called from here. Clears & returns 'hasrefreshed' flag. + if (g_nAppMode != MODE_LOGO) { VideoUpdateFlash(); @@ -276,20 +267,16 @@ void ContinueExecution(void) static DWORD lasttime = 0; DWORD currtime = GetTickCount(); if ((!g_bFullSpeed) || - (currtime-lasttime >= (DWORD)((g_bGraphicsMode || !systemidle) ? 100 : 25))) + (currtime-lasttime >= (DWORD)(g_bGraphicsMode ? 100 : 25))) { VideoRefreshScreen(); lasttime = currtime; } - screenupdated = 1; } lastupdates[1] = lastupdates[0]; lastupdates[0] = anyupdates; anyupdates = 0; - - if (pageflipping) - pageflipping--; } MB_EndOfVideoFrame(); diff --git a/source/Applewin.h b/source/Applewin.h index af17cebc..1c113d27 100644 --- a/source/Applewin.h +++ b/source/Applewin.h @@ -10,7 +10,6 @@ extern TCHAR *g_pAppTitle; extern eApple2Type g_Apple2Type; -extern BOOL behind; extern DWORD cumulativecycles; extern DWORD cyclenum; extern DWORD emulmsec; diff --git a/source/Video.cpp b/source/Video.cpp index bedf9cec..1f35fb89 100644 --- a/source/Video.cpp +++ b/source/Video.cpp @@ -3117,14 +3117,22 @@ BYTE VideoCheckMode (WORD, WORD address, BYTE, BYTE, ULONG uExecutedCycles) } //=========================================================================== -void VideoCheckPage (BOOL force) { - if ((g_bVideoDisplayPage2 != (SW_PAGE2 != 0)) && - (force || (emulmsec-lastpageflip > 500))) { - g_bVideoDisplayPage2 = (SW_PAGE2 != 0); - VideoRefreshScreen(); - hasrefreshed = 1; - lastpageflip = emulmsec; - } + +// Check if we should call VideoRefreshScreen() based on unexpected page +// - Only called from a single place in main ContinueExecution() loop +void VideoCheckPage(BOOL force) +{ + const bool bUnexpectedPage = (g_bVideoDisplayPage2 != (SW_PAGE2 != 0)); + //_ASSERT(!bUnexpectedPage); // [TC] Q: When does this happen? A: EG. When page-flipping && Scroll-Lock is pressed + + if (bUnexpectedPage && // Unexpected page && + (force || (emulmsec-lastpageflip > 500))) // force || >500ms since last flip + { + g_bVideoDisplayPage2 = (SW_PAGE2 != 0); + VideoRefreshScreen(); + hasrefreshed = 1; + lastpageflip = emulmsec; + } } //=========================================================================== @@ -3701,24 +3709,22 @@ BYTE VideoSetMode (WORD, WORD address, BYTE write, BYTE, ULONG uExecutedCycles) else oldpage2 = SW_PAGE2; } - if (oldpage2 != SW_PAGE2) { - static DWORD lastrefresh = 0; - if ((g_bVideoDisplayPage2 && !SW_PAGE2) || (!behind)) { - g_bVideoDisplayPage2 = (SW_PAGE2 != 0); - if (!g_VideoForceFullRedraw) { - VideoRefreshScreen(); - hasrefreshed = 1; - lastrefresh = emulmsec; - } - } - else if ((!SW_PAGE2) && (!g_VideoForceFullRedraw) && (emulmsec-lastrefresh >= 20)) { - g_bVideoDisplayPage2 = 0; - VideoRefreshScreen(); - hasrefreshed = 1; - lastrefresh = emulmsec; + + if (oldpage2 != SW_PAGE2) + { + g_bVideoDisplayPage2 = (SW_PAGE2 != 0); + if (!g_VideoForceFullRedraw) + { +#if 1 + VideoRefreshScreen(); + hasrefreshed = 1; +#else + g_VideoForceFullRedraw = 1; // GH#129,GH204: Defer the redraw until the main ContinueExecution() loop (TODO: What effect does this have on other games?) +#endif } lastpageflip = emulmsec; } + return MemReadFloatingBus(uExecutedCycles); }