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)
This commit is contained in:
CasualPokePlayer 2025-07-25 18:14:30 -07:00
parent e727ca4a96
commit 120c652cb0
1 changed files with 14 additions and 9 deletions

View File

@ -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;
}
}