Simplified main-loop a bit more, and removed more globals from AppleWin.cpp

This commit is contained in:
tomcw 2014-09-14 16:12:55 +01:00
parent bc45812f4e
commit 1f892a27d4
7 changed files with 36 additions and 35 deletions

View File

@ -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;

View File

@ -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

View File

@ -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);
//

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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
//