Added a very poorly implemented PAL/NTSC toggle

This commit is contained in:
2026-05-17 15:02:31 +01:00
parent f1140fa115
commit 1730687009
8 changed files with 78 additions and 56 deletions

View File

@@ -5,6 +5,7 @@ namespace Core.Video
{
public class SmsVdp
{
public bool IsPalRegion { get; set; } = false;
// The VDP's private memory! The CPU cannot touch these arrays directly.
public byte[] VRAM { get; private set; } = new byte[0x4000]; // 16KB Video RAM
public byte[] CRAM { get; private set; } = new byte[0x20]; // 32 Bytes Color Palette
@@ -104,19 +105,17 @@ namespace Core.Video
public byte ReadVCounter()
{
// 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
if (IsPalRegion)
{
return (byte)_currentScanline;
// PAL Math: 313 lines. Counts 0 to 242, jumps to 186 (0xBA), counts to 255.
if (_currentScanline <= 242) return (byte)_currentScanline;
else return (byte)(_currentScanline - 57);
}
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);
// NTSC Math: 262 lines. Counts 0 to 218, jumps to 213 (0xD5), counts to 255.
if (_currentScanline <= 218) return (byte)_currentScanline;
else return (byte)(_currentScanline - 6);
}
}
public byte ReadHCounter()
@@ -174,7 +173,9 @@ namespace Core.Video
// 3. MOVE TO THE NEXT LINE
_currentScanline++;
if (_currentScanline > 261)
int maxLines = IsPalRegion ? 313 : 262;
if (_currentScanline > maxLines -1)
{
_currentScanline = 0;
}