From 8a11feb739f627cd781513abfd819d75d8cd208d Mon Sep 17 00:00:00 2001 From: tomcw Date: Fri, 9 Aug 2019 22:58:12 +0100 Subject: [PATCH] NTSC TV video modes: adjust y-position by 1 pixel (#650) --- source/NTSC.cpp | 19 +++++++++++++++---- source/Video.cpp | 22 ---------------------- 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/source/NTSC.cpp b/source/NTSC.cpp index d168af4f..2b8c97b1 100644 --- a/source/NTSC.cpp +++ b/source/NTSC.cpp @@ -624,7 +624,7 @@ inline void updateFlashRate() // TODO: Flash rate should be constant (regardless inline void updateFramebufferColorTVSingleScanline( uint16_t signal, bgra_t *pTable ) { /* */ uint32_t *pLine0Address = getScanlineThis0Address(); - /* */ uint32_t *pLine1Address = getScanlinePrev1Address(); + /* */ uint32_t *pLine1Address = getScanlinePrev1Address(); // NB. TV mode uses previous 2 lines /* */ uint32_t *pLine2Address = getScanlinePrev2Address(); const uint32_t color0 = getScanlineColor( signal, pTable ); @@ -650,7 +650,7 @@ inline void updateFramebufferColorTVSingleScanline( uint16_t signal, bgra_t *pTa inline void updateFramebufferColorTVDoubleScanline( uint16_t signal, bgra_t *pTable ) { /* */ uint32_t *pLine0Address = getScanlineThis0Address(); - /* */ uint32_t *pLine1Address = getScanlinePrev1Address(); + /* */ uint32_t *pLine1Address = getScanlinePrev1Address(); // NB. TV mode uses previous 2 lines const uint32_t *pLine2Address = getScanlinePrev2Address(); const uint32_t color0 = getScanlineColor( signal, pTable ); @@ -666,7 +666,7 @@ inline void updateFramebufferColorTVDoubleScanline( uint16_t signal, bgra_t *pTa inline void updateFramebufferMonitorSingleScanline( uint16_t signal, bgra_t *pTable ) { /* */ uint32_t *pLine0Address = getScanlineThis0Address(); - /* */ uint32_t *pLine1Address = getScanlineNext1Address(); + /* */ uint32_t *pLine1Address = getScanlineNext1Address(); // NB. Monitor mode just uses next line const uint32_t color0 = getScanlineColor( signal, pTable ); const uint32_t color1 = 0; // Remove blending for consistent DHGR MIX mode (GH#631) // const uint32_t color1 = ((color0 & 0x00fcfcfc) >> 2); // 25% Blend (original) @@ -680,7 +680,7 @@ inline void updateFramebufferMonitorSingleScanline( uint16_t signal, bgra_t *pTa inline void updateFramebufferMonitorDoubleScanline( uint16_t signal, bgra_t *pTable ) { /* */ uint32_t *pLine0Address = getScanlineThis0Address(); - /* */ uint32_t *pLine1Address = getScanlineNext1Address(); + /* */ uint32_t *pLine1Address = getScanlineNext1Address(); // NB. Monitor mode just uses next line const uint32_t color0 = getScanlineColor( signal, pTable ); /* */ *pLine1Address = color0; @@ -1978,6 +1978,15 @@ void NTSC_SetVideoMode( uint32_t uVideoModeFlags, bool bDelay/*=false*/ ) } //=========================================================================== + +// TV modes don't write to the last line, so when switching from another (Monitor) mode there may be stale data left behind +void ClearLastLine(void) +{ + uint32_t* p = (uint32_t*)g_pScanLines[VIDEO_SCANNER_Y_DISPLAY * 2 - 1]; + for (UINT x = 0; x < NTSC_GetFrameBufferBorderlessWidth(); x++) + p[x] = 0; +} + void NTSC_SetVideoStyle() // (int v, int s) { int half = IsVideoStyle(VS_HALF_SCANLINES); @@ -1999,6 +2008,7 @@ void NTSC_SetVideoStyle() // (int v, int s) g_pFuncUpdateBnWPixel = updatePixelBnWColorTVDoubleScanline; g_pFuncUpdateHuePixel = updatePixelHueColorTVDoubleScanline; } + ClearLastLine(); break; case VT_COLOR_MONITOR_NTSC: @@ -2030,6 +2040,7 @@ void NTSC_SetVideoStyle() // (int v, int s) else { g_pFuncUpdateBnWPixel = g_pFuncUpdateHuePixel = updatePixelBnWColorTVDoubleScanline; } + ClearLastLine(); break; case VT_MONO_AMBER: diff --git a/source/Video.cpp b/source/Video.cpp index a5229d6d..3999cd58 100644 --- a/source/Video.cpp +++ b/source/Video.cpp @@ -556,25 +556,6 @@ void VideoRedrawScreen (void) //=========================================================================== -// TC: Hacky-fix for GH#341 - better to draw to the correct position in the framebuffer to start with! (in NTSC.cpp) -// . NB. Now the dx is corrected in NTSC.cpp, updateVideoScannerAddress() -static void VideoFrameBufferAdjust(int& xSrc, int& ySrc, bool bInvertY=false) -{ - int dx=0, dy=0; - - if (g_eVideoType == VT_MONO_TV || g_eVideoType == VT_COLOR_TV) - { - // Adjust the src locations for the NTSC video modes - dy = -1; - } - - if (bInvertY) - dy =- dy; - - xSrc += dx; - ySrc += dy; -} - void VideoRefreshScreen ( uint32_t uRedrawWholeScreenVideoMode /* =0*/, bool bRedrawWholeScreen /* =false*/ ) { if (bRedrawWholeScreen || g_nAppMode == MODE_PAUSED) @@ -593,7 +574,6 @@ void VideoRefreshScreen ( uint32_t uRedrawWholeScreenVideoMode /* =0*/, bool bRe { int xSrc = GetFrameBufferBorderWidth(); int ySrc = GetFrameBufferBorderHeight(); - VideoFrameBufferAdjust(xSrc, ySrc); // TC: Hacky-fix for GH#341 int xdest = IsFullScreen() ? GetFullScreenOffsetX() : 0; int ydest = IsFullScreen() ? GetFullScreenOffsetY() : 0; @@ -1085,8 +1065,6 @@ static void Video_MakeScreenShot(FILE *pFile, const VideoScreenShot_e ScreenShot int xSrc = GetFrameBufferBorderWidth(); int ySrc = GetFrameBufferBorderHeight(); - VideoFrameBufferAdjust(xSrc, ySrc, true); // TC: Hacky-fix for GH#341 & GH#356 - // Lines stored in reverse, so invert the y-adjust value pSrc += xSrc; // Skip left border pSrc += ySrc * GetFrameBufferWidth(); // Skip top border