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)