From 120c652cb010b5ed93af654bd7ff750c14669b0f Mon Sep 17 00:00:00 2001 From: CasualPokePlayer <50538166+CasualPokePlayer@users.noreply.github.com> Date: Fri, 25 Jul 2025 18:14:30 -0700 Subject: [PATCH] Use iNES v2 region for iNES v1 if available iNES v1 doesn't have any way reliable way to detect the region. While there are bits for such, they were added late to the spec and thus no ROM bothers to set them. The only reliable way to detect the region with iNES (outside of gamedb) is to use iNES v2's region indicator. Commit also fixes up the region detection for the case of Dendy (which later iNES v2 gives a bit for) See #4402, doesn't completely fix it as quickerNES is still accepting the ROM (it doesn't support PAL, so it should be rejecting it outright) --- .../Consoles/Nintendo/NES/NES.iNES.cs | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.iNES.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.iNES.cs index 028d34a0e4..f51b7c32d8 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.iNES.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.iNES.cs @@ -64,15 +64,15 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES case 0: CartV2.PadV = 1; break; case 1: CartV2.PadH = 1; break; } - switch (data[12] & 1) + + CartV2.System = (data[12] & 3) switch { - case 0: - CartV2.System = "NES-NTSC"; - break; - case 1: - CartV2.System = "NES-PAL"; - break; - } + // 2 indicates dual NTSC/PAL compatibility, might as well use NTSC + 0 or 2 => "NES-NTSC", + 1 => "NES-PAL", + 3 => "Dendy", + _ => CartV2.System + }; if ((data[6] & 4) != 0) CartV2.TrainerSize = 512; @@ -95,7 +95,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES Cart.PrgSize *= 16; Cart.ChrSize *= 8; - Cart.WramBattery = (data[6] & 2) != 0; Cart.WramSize = 8; // should be data[8], but that never worked @@ -116,6 +115,12 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES if (data[6].Bit(2)) Cart.TrainerSize = 512; + // iNES v1 does not have a reliable way to indicate the game's region + // Officially, data[9] bit 0 indicates region, but practically no ROM uses it + // Unofficially, data[10] bit 1-0 indicates region, but practically no ROM uses it + // However, iNES v2 will reliably indicate the game's region, so we can use that if present + Cart.System = CartV2?.System; + return true; } }