From 2c8f5ce86404169aee1e60df483c124791ff4e69 Mon Sep 17 00:00:00 2001 From: tomcw Date: Fri, 2 Feb 2018 20:19:48 +0000 Subject: [PATCH] Support floating-bus in full-speed mode (#508, #519, #532) --- source/Debugger/Debug.cpp | 2 +- source/Memory.cpp | 2 +- source/NTSC.cpp | 17 ++++++++++++++--- source/NTSC.h | 3 ++- source/Video.cpp | 14 ++++++++++---- 5 files changed, 28 insertions(+), 10 deletions(-) diff --git a/source/Debugger/Debug.cpp b/source/Debugger/Debug.cpp index 69ccb862..9c4b4f98 100644 --- a/source/Debugger/Debug.cpp +++ b/source/Debugger/Debug.cpp @@ -8066,7 +8066,7 @@ void OutputTraceLine () if (g_bTraceFileWithVideoScanner) { - uint16_t addr = NTSC_VideoGetScannerAddress(); + uint16_t addr = NTSC_VideoGetScannerAddress(0); BYTE data = mem[addr]; fprintf( g_hTraceFile, diff --git a/source/Memory.cpp b/source/Memory.cpp index b976a46c..2c06897e 100644 --- a/source/Memory.cpp +++ b/source/Memory.cpp @@ -1625,7 +1625,7 @@ void MemReset() BYTE MemReadFloatingBus(const ULONG uExecutedCycles) { // return mem[ VideoGetScannerAddress(NULL, uExecutedCycles) ]; // NG: ANSI STORY (End Credits) - repro by running from "Turn the disk over" - return mem[ NTSC_VideoGetScannerAddress() ]; // OK: This does the 2-cycle adjust for ANSI STORY (End Credits) + return mem[ NTSC_VideoGetScannerAddress(uExecutedCycles) ]; // OK: This does the 2-cycle adjust for ANSI STORY (End Credits) } //=========================================================================== diff --git a/source/NTSC.cpp b/source/NTSC.cpp index 92e3f738..bd8cc8c7 100644 --- a/source/NTSC.cpp +++ b/source/NTSC.cpp @@ -1430,10 +1430,21 @@ uint32_t*NTSC_VideoGetChromaTable( bool bHueTypeMonochrome, bool bMonitorTypeCol } //=========================================================================== - -// NB. NTSC video-scanner doesn't get updated during full-speed, so video-dependent Apple II code can hang -uint16_t NTSC_VideoGetScannerAddress ( void ) +void NTSC_VideoClockResync(const DWORD dwCyclesThisFrame) { + g_nVideoClockVert = (uint16_t) (dwCyclesThisFrame / VIDEO_SCANNER_MAX_HORZ) % VIDEO_SCANNER_MAX_VERT; + g_nVideoClockHorz = (uint16_t) (dwCyclesThisFrame % VIDEO_SCANNER_MAX_HORZ); +} + +//=========================================================================== +uint16_t NTSC_VideoGetScannerAddress ( const ULONG uExecutedCycles ) +{ + if (g_bFullSpeed) + { + // Ensure that NTSC video-scanner gets updated during full-speed, so video-dependent Apple II code doesn't hang + NTSC_VideoClockResync( CpuGetCyclesThisVideoFrame(uExecutedCycles) ); + } + const uint16_t currVideoClockVert = g_nVideoClockVert; const uint16_t currVideoClockHorz = g_nVideoClockHorz; diff --git a/source/NTSC.h b/source/NTSC.h index 58f851d6..50ea29d1 100644 --- a/source/NTSC.h +++ b/source/NTSC.h @@ -11,7 +11,8 @@ extern void NTSC_SetVideoStyle(); extern void NTSC_SetVideoTextMode( int cols ); extern uint32_t*NTSC_VideoGetChromaTable( bool bHueTypeMonochrome, bool bMonitorTypeColorTV ); - extern uint16_t NTSC_VideoGetScannerAddress( void ); + extern void NTSC_VideoClockResync( const DWORD dwCyclesThisFrame ); + extern uint16_t NTSC_VideoGetScannerAddress( const ULONG uExecutedCycles ); extern void NTSC_VideoInit( uint8_t *pFramebuffer ); extern void NTSC_VideoReinitialize( DWORD cyclesThisFrame ); extern void NTSC_VideoInitAppleType(); diff --git a/source/Video.cpp b/source/Video.cpp index e93473f5..c9c4eedc 100644 --- a/source/Video.cpp +++ b/source/Video.cpp @@ -567,10 +567,16 @@ void VideoRedrawScreenDuringFullSpeed(DWORD dwCyclesThisFrame, bool bInit /*=fal void VideoRedrawScreenAfterFullSpeed(DWORD dwCyclesThisFrame) { - const int nScanLines = bVideoScannerNTSC ? kNTSCScanLines : kPALScanLines; - - g_nVideoClockVert = (uint16_t) (dwCyclesThisFrame / kHClocks) % nScanLines; - g_nVideoClockHorz = (uint16_t) (dwCyclesThisFrame % kHClocks); + if (bVideoScannerNTSC) + { + NTSC_VideoClockResync(dwCyclesThisFrame); + } + else // PAL + { + _ASSERT(0); + g_nVideoClockVert = (uint16_t) (dwCyclesThisFrame / kHClocks) % kPALScanLines; + g_nVideoClockHorz = (uint16_t) (dwCyclesThisFrame % kHClocks); + } VideoRedrawScreen(); // Better (no flicker) than using: NTSC_VideoReinitialize() or VideoReinitialize() }