From b1ff22c9e6445c4846914879b2deec7f3ae0d310 Mon Sep 17 00:00:00 2001 From: Marc Parsons Date: Sat, 16 May 2026 20:18:07 +0100 Subject: [PATCH] Tried to fix Sonic 1 demo loop --- Core/Video/SmsVdp.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Core/Video/SmsVdp.cs b/Core/Video/SmsVdp.cs index 7a67b33..278db60 100644 --- a/Core/Video/SmsVdp.cs +++ b/Core/Video/SmsVdp.cs @@ -104,10 +104,20 @@ namespace Core.Video public byte ReadVCounter() { - // Note: On real NTSC hardware, the V-Counter jumps slightly around - // the VBlank period to keep the math 8-bit, but simply returning - // the raw current scanline is perfectly fine to get us booting! - return (byte)_currentScanline; + // NTSC Hardware Quirk: The Master System outputs 262 lines, + // but an 8-bit register can only hold a maximum value of 255! + // To prevent a hardware overflow to 0, the silicon jumps backward during VBlank. + + if (_currentScanline <= 218) // 0xDA + { + return (byte)_currentScanline; + } + else + { + // At scanline 219, the counter jumps back to 213 (0xD5). + // It then counts up to exactly 255 (0xFF) at the end of the frame. + return (byte)(_currentScanline - 6); + } } public void Update(int tStates)