Tried to fix Sonic 1 demo loop

This commit is contained in:
2026-05-16 20:18:07 +01:00
parent aa9cc552e6
commit b1ff22c9e6

View File

@@ -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)