From aa41c89e6841f2cc839af0074274c193b614efef Mon Sep 17 00:00:00 2001 From: Aaron Culliney Date: Sat, 7 Apr 2018 11:32:52 -0700 Subject: [PATCH] Lite refactor video timing --- src/audio/mockingboard.c | 5 +++- src/audio/speaker.c | 4 ++- src/display.c | 3 +-- src/timing.c | 54 ++++++++++------------------------------ src/timing.h | 27 +++++++++++++++++--- 5 files changed, 45 insertions(+), 48 deletions(-) diff --git a/src/audio/mockingboard.c b/src/audio/mockingboard.c index bba293b0..81e01d42 100644 --- a/src/audio/mockingboard.c +++ b/src/audio/mockingboard.c @@ -2368,7 +2368,7 @@ void MB_UpdateCycles(ULONG uExecutedCycles) if(g_SoundcardType == CT_Empty) return; - timing_checkpoint_cycles(); + timing_checkpointCycles(); unsigned long uCycles = cycles_count_total - g_uLastCumulativeCycles; g_uLastCumulativeCycles = cycles_count_total; #if MB_TRACING @@ -2385,6 +2385,9 @@ void MB_UpdateCycles(ULONG uExecutedCycles) _ASSERT(uCycles < 0x10000); #endif uint16_t nClocks = (uint16_t) uCycles; + if (nClocks == 0) { + return; + } for(int i=0; i= dwClksPerFrame) { - g_dwCyclesThisFrame -= dwClksPerFrame; + // video frame counter overflow ... + if (cycles_this_frame >= CYCLES_FRAME) { + cycles_this_frame -= CYCLES_FRAME; MB_EndOfVideoFrame(); } @@ -536,15 +509,14 @@ void timing_stopCPU(void) { } } -unsigned int CpuGetCyclesThisVideoFrame(void) { +unsigned int timing_currentVideoFrameCycles(void) { ASSERT_ON_CPU_THREAD(); - - timing_checkpoint_cycles(); - return g_dwCyclesThisFrame + cycles_checkpoint_count; + timing_checkpointCycles(); + return cycles_this_frame + cycles_checkpoint_count; } -// Called when an IO-reg is accessed & accurate global cycle count info is needed -void timing_checkpoint_cycles(void) { +// Called when accurate global cycle count info is needed +void timing_checkpointCycles(void) { ASSERT_ON_CPU_THREAD(); const int32_t d = run_args.cpu65_cycle_count - cycles_checkpoint_count; diff --git a/src/timing.h b/src/timing.h index 1ae684c6..5ac4d64a 100644 --- a/src/timing.h +++ b/src/timing.h @@ -33,7 +33,6 @@ #define EXECUTION_PERIOD_NSECS 1000000UL // NANOSECONDS_PER_SECOND / EXECUTION_CHURN_RATE // timing values cribbed from AppleWin ... reference: Sather's _Understanding the Apple IIe_ -// TODO: revisit this if/when attempting to actually sync up VBL/VSYNC to actual device vsync // 14318181.81... #define _M14 (157500000.0 / 11.0) @@ -43,6 +42,19 @@ #define CLK_6502 ((_M14 * 65.0) / 912.0) #define CLK_6502_INT ((unsigned int)CLK_6502) +// HBL & VBL constants +// UtAIIe:3-13 "There are exactly 17030 (65 x 262) 6502 cycles in every television scan of an American Apple" +#define CYCLES_HBL 25 +#define CYCLES_VIS_BEGIN CYCLES_HBL +#define CYCLES_VIS 40 +#define CYCLES_SCANLINE (CYCLES_HBL + CYCLES_VIS) // 65 +#define SCANLINES_VBL 70 +#define SCANLINES_MIX (20*8) // 160 +#define SCANLINES_VIS (64*3) // 192 +#define SCANLINES_VBL_BEGIN SCANLINES_VIS +#define SCANLINES_FRAME (SCANLINES_VBL + SCANLINES_VIS) // 262 +#define CYCLES_FRAME (CYCLES_SCANLINE * SCANLINES_FRAME) // 17030 + #define CPU_SCALE_SLOWEST 0.25 #define CPU_SCALE_FASTEST_PIVOT 4.0 #define CPU_SCALE_FASTEST (CPU_SCALE_FASTEST_PIVOT + 0.0625) @@ -118,12 +130,21 @@ void cpu_resume(void); */ bool cpu_isPaused(void); +// ---------------------------------------------------------------------------- +// Video frame and IRQ fine-grained timing. + /* - * checkpoints current cycle count and updates total (for timing-dependent I/O) + * Get current cycles count within this video frame */ -void timing_checkpoint_cycles(void); +unsigned int timing_currentVideoFrameCycles() CALL_ON_CPU_THREAD; + +/* + * Checkpoints current cycle count and updates total (for timing-dependent I/O) + */ +void timing_checkpointCycles(void) CALL_ON_CPU_THREAD; // ---------------------------------------------------------------------------- +// save/restore state bool timing_saveState(StateHelper_s *helper);