From 1f892a27d41416d6c0f6faef667ffc9fe1dc5d46 Mon Sep 17 00:00:00 2001 From: tomcw Date: Sun, 14 Sep 2014 16:12:55 +0100 Subject: [PATCH] Simplified main-loop a bit more, and removed more globals from AppleWin.cpp --- source/Applewin.cpp | 21 +++------------------ source/Applewin.h | 1 - source/CPU.cpp | 24 ++++++++++++++++++++++++ source/CPU.h | 2 ++ source/Memory.cpp | 9 +-------- source/Memory.h | 1 - source/Video.cpp | 13 ++++++------- 7 files changed, 36 insertions(+), 35 deletions(-) diff --git a/source/Applewin.cpp b/source/Applewin.cpp index d34aa828..da398bff 100644 --- a/source/Applewin.cpp +++ b/source/Applewin.cpp @@ -63,8 +63,6 @@ eApple2Type g_Apple2Type = A2TYPE_APPLE2EENHANCED; DWORD cumulativecycles = 0; // Wraps after ~1hr 9mins DWORD cyclenum = 0; // Used by SpkrToggle() for non-wave sound -DWORD emulmsec = 0; -static DWORD emulmsec_frac = 0; bool g_bFullSpeed = false; //Pravets 8A/C variables @@ -229,14 +227,10 @@ void ContinueExecution(void) if (nCyclesToExecute < 0) nCyclesToExecute = 0; - DWORD dwExecutedCycles = CpuExecute(nCyclesToExecute); - g_dwCyclesThisFrame += dwExecutedCycles; + cyclenum = CpuExecute(nCyclesToExecute); + g_dwCyclesThisFrame += cyclenum; - // - - cyclenum = dwExecutedCycles; - - DiskUpdatePosition(dwExecutedCycles); + DiskUpdatePosition(cyclenum); JoyUpdatePosition(); SpkrUpdate(cyclenum); @@ -245,15 +239,6 @@ void ContinueExecution(void) // - const DWORD CLKS_PER_MS = (DWORD)g_fCurrentCLK6502 / 1000; - - emulmsec_frac += dwExecutedCycles; - if (emulmsec_frac > CLKS_PER_MS) - { - emulmsec += emulmsec_frac / CLKS_PER_MS; - emulmsec_frac %= CLKS_PER_MS; - } - if (g_dwCyclesThisFrame >= dwClksPerFrame) { g_dwCyclesThisFrame -= dwClksPerFrame; diff --git a/source/Applewin.h b/source/Applewin.h index 85ceae66..365948e4 100644 --- a/source/Applewin.h +++ b/source/Applewin.h @@ -15,7 +15,6 @@ extern eApple2Type g_Apple2Type; extern DWORD cumulativecycles; extern DWORD cyclenum; -extern DWORD emulmsec; extern bool g_bFullSpeed; //Pravets 8A/C only variables diff --git a/source/CPU.cpp b/source/CPU.cpp index f54cdb45..fc8829d5 100644 --- a/source/CPU.cpp +++ b/source/CPU.cpp @@ -465,6 +465,29 @@ ULONG CpuGetCyclesThisVideoFrame(const ULONG nExecutedCycles) } #endif +//--------------------------------------------------------------------------- + +static DWORD g_dwEmulationTime_ms = 0; + +static void UpdateEmulationTime(const DWORD dwExecutedCycles) +{ + static DWORD dwEmulationTimeFrac_clks = 0; + + const DWORD CLKS_PER_MS = (DWORD)g_fCurrentCLK6502 / 1000; + + dwEmulationTimeFrac_clks += dwExecutedCycles; + if (dwEmulationTimeFrac_clks > CLKS_PER_MS) + { + g_dwEmulationTime_ms += dwEmulationTimeFrac_clks / CLKS_PER_MS; + dwEmulationTimeFrac_clks %= CLKS_PER_MS; + } +} + +DWORD CpuGetEmulationTime_ms(void) +{ + return g_dwEmulationTime_ms; +} + //=========================================================================== DWORD CpuExecute(const DWORD uCycles) @@ -479,6 +502,7 @@ DWORD CpuExecute(const DWORD uCycles) const DWORD uExecutedCycles = InternalCpuExecute(uCycles); MB_UpdateCycles(uExecutedCycles); // Update 6522s (NB. Do this before updating g_nCumulativeCycles below) + UpdateEmulationTime(uExecutedCycles); // diff --git a/source/CPU.h b/source/CPU.h index 2e21591b..58c5d886 100644 --- a/source/CPU.h +++ b/source/CPU.h @@ -31,3 +31,5 @@ DWORD CpuSetSnapshot(SS_CPU6502* pSS); BYTE CpuRead(USHORT addr, ULONG uExecutedCycles); void CpuWrite(USHORT addr, BYTE a, ULONG uExecutedCycles); + +DWORD CpuGetEmulationTime_ms(void); diff --git a/source/Memory.cpp b/source/Memory.cpp index 25f00c92..f1a19fd9 100644 --- a/source/Memory.cpp +++ b/source/Memory.cpp @@ -88,7 +88,7 @@ MEMORY MANAGEMENT SOFT SWITCHES $C005 W RAMWRTON Write enable aux memory from $0200-$BFFF $C006 W INTCXROMOFF Enable slot ROM from $C100-$CFFF $C007 W INTCXROMON Enable main ROM from $C100-$CFFF - $C008 W ALZTPOFF Enable main memory from $0000-$01FF & avl BSR + $C008 W ALTZPOFF Enable main memory from $0000-$01FF & avl BSR $C009 W ALTZPON Enable aux memory from $0000-$01FF & avl BSR $C00A W SLOTC3ROMOFF Enable main ROM from $C300-$C3FF $C00B W SLOTC3ROMON Enable slot ROM from $C300-$C3FF @@ -1074,13 +1074,6 @@ void MemDestroy () //=========================================================================== -bool MemGet80Store() -{ - return SW_80STORE != 0; -} - -//=========================================================================== - bool MemCheckSLOTCXROM() { return SW_SLOTCXROM ? true : false; diff --git a/source/Memory.h b/source/Memory.h index 55ff2065..c418422c 100644 --- a/source/Memory.h +++ b/source/Memory.h @@ -38,7 +38,6 @@ extern UINT g_uMaxExPages; // user requested ram pages (from cmd line) void RegisterIoHandler(UINT uSlot, iofunction IOReadC0, iofunction IOWriteC0, iofunction IOReadCx, iofunction IOWriteCx, LPVOID lpSlotParameter, BYTE* pExpansionRom); void MemDestroy (); -bool MemGet80Store(); bool MemCheckSLOTCXROM(); LPBYTE MemGetAuxPtr(const WORD); LPBYTE MemGetMainPtr(const WORD); diff --git a/source/Video.cpp b/source/Video.cpp index 58dbfc27..eeb64f0d 100644 --- a/source/Video.cpp +++ b/source/Video.cpp @@ -278,12 +278,11 @@ static /*bool*/ UINT g_VideoForceFullRedraw = 1; static LPBYTE framebufferaddr = (LPBYTE)0; static LONG g_nFrameBufferPitch = 0; -static DWORD lastpageflip = 0; COLORREF monochrome = RGB(0xC0,0xC0,0xC0); static BOOL rebuiltsource = 0; static LPBYTE vidlastmem = NULL; -static int g_bVideoMode = VF_TEXT; +static UINT g_bVideoMode = VF_TEXT; DWORD g_eVideoType = VT_COLOR_TVEMU; DWORD g_uHalfScanLines = 1; // drop 50% scan lines for a more authentic look @@ -2465,8 +2464,9 @@ static void DebugRefresh(char uDebugFlag) { static DWORD uLastRefreshTime = 0; - const DWORD uTimeBetweenRefreshes = uLastRefreshTime ? emulmsec - uLastRefreshTime : 0; - uLastRefreshTime = emulmsec; + const DWORD dwEmuTime_ms = CpuGetEmulationTime_ms(); + const DWORD uTimeBetweenRefreshes = uLastRefreshTime ? dwEmuTime_ms - uLastRefreshTime : 0; + uLastRefreshTime = dwEmuTime_ms; if (!uTimeBetweenRefreshes) return; // 1st time in func @@ -2726,7 +2726,6 @@ BYTE VideoSetMode (WORD, WORD address, BYTE write, BYTE, ULONG uExecutedCycles) 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); @@ -2858,8 +2857,8 @@ WORD VideoGetScannerAddress(bool* pbVblBar_OUT, const DWORD uExecutedCycles) // machine state switches // int nHires = (SW_HIRES && !SW_TEXT) ? 1 : 0; - int nPage2 = (SW_PAGE2) ? 1 : 0; - int n80Store = (MemGet80Store()) ? 1 : 0; + int nPage2 = SW_PAGE2 ? 1 : 0; + int n80Store = SW_80STORE ? 1 : 0; // calculate video parameters according to display standard //