Split NES 2.0 combined pieces

This commit is contained in:
Matt Nadareski
2026-03-06 15:53:16 -05:00
parent 93a6926b43
commit b339f213b8
4 changed files with 117 additions and 75 deletions

View File

@@ -8,49 +8,93 @@ namespace SabreTools.Data.Models.NES
{
// All common header parts take up bytes 0-7
/// <summary>
/// Mapper MSB/Submapper
/// </summary>
/// <remarks>
/// Bits 0-3 - Mapper number bits 8-11
/// Bits 4-7 - Submapper number
/// </remarks>
public byte MapperMSBSubmapper { get; set; }
#region Byte 8
/// <summary>
/// PRG-ROM/CHR-ROM size MSB
/// Mapper MSB bits 8-11
/// </summary>
/// <remarks>
/// Bits 0-3 - PRG-ROM size MSB
/// Bits 4-7 - CHR-ROM size MSB
/// </remarks>
public byte PRGCHRMSB { get; set; }
/// <remarks>Byte 8, Bits 0-3</remarks>
public byte MapperMSB { get; set; }
/// <summary>
/// PRG-RAM/EEPROM size
/// Submapper
/// </summary>
/// <remarks>Byte 8, Bits 4-7</remarks>
public byte Submapper { get; set; }
#endregion
#region Byte 9
/// <summary>
/// PRG-ROM size MSB bits 8-11
/// </summary>
/// <remarks>Byte 9, Bits 0-3</remarks>
public byte PRGROMSizeMSB { get; set; }
/// <summary>
/// CHR-ROM size MSB bits 8-11
/// </summary>
/// <remarks>Byte 9, Bits 4-7</remarks>
public byte CHRROMSizeMSB { get; set; }
#endregion
#region Byte 10
/// <summary>
/// PRG-RAM (volatile) shift count
/// </summary>
/// <remarks>
/// Bits 0-3 - PRG-RAM (volatile) shift count
/// Bits 4-7 - PRG-NVRAM/EEPROM (non-volatile) shift count
/// Byte 10, Bits 0-3
///
/// If the shift count is zero, there is no CHR-(NV)RAM.
/// If the shift count is zero, there is no RAM.
/// If the shift count is non-zero, the actual size is
/// "64 << shift count" bytes, i.e. 8192 bytes for a shift count of 7.
/// </remarks>
public byte PRGRAMEEPROMSize { get; set; }
public byte PRGRAMShiftCount { get; set; }
/// <summary>
/// CHR-RAM size
/// PRG-NVRAM/EEPROM (non-volatile) shift count
/// </summary>
/// <remarks>
/// Bits 0-3 - CHR-RAM size (volatile) shift count
/// Bits 4-7 - CHR-NVRAM size (non-volatile) shift count
/// Byte 10, Bits 4-7
///
/// If the shift count is zero, there is no CHR-(NV)RAM.
/// If the shift count is zero, there is no NVRAM.
/// If the shift count is non-zero, the actual size is
/// "64 << shift count" bytes, i.e. 8192 bytes for a shift count of 7.
/// </remarks>
public byte CHRRAMSize { get; set; }
public byte PRGNVRAMEEPROMShiftCount { get; set; }
#endregion
#region Byte 11
/// <summary>
/// CHR-RAM size (volatile) shift count
/// </summary>
/// <remarks>
/// Byte 11, Bits 0-3
///
/// If the shift count is zero, there is no RAM.
/// If the shift count is non-zero, the actual size is
/// "64 << shift count" bytes, i.e. 8192 bytes for a shift count of 7.
/// </remarks>
public byte CHRRAMShiftCount { get; set; }
/// <summary>
/// CHR-NVRAM size (non-volatile) shift count
/// </summary>
/// <remarks>
/// Byte 11, Bits 4-7
///
/// If the shift count is zero, there is no NVRAM.
/// If the shift count is non-zero, the actual size is
/// "64 << shift count" bytes, i.e. 8192 bytes for a shift count of 7.
/// </remarks>
public byte CHRNVRAMShiftCount { get; set; }
#endregion
/// <summary>
/// CPU/PPU timing mode

View File

@@ -44,12 +44,12 @@ namespace SabreTools.Serialization.Readers
int chrRomSize = cart.Header.CHRROMSize * 8192;
if (cart.Header is Header2 header2)
{
byte msb = (byte)(header2.PRGCHRMSB & 0x0F);
ushort extendedSize = (ushort)((msb << 8) | header.PRGROMSize);
ushort extendedSize = (ushort)((header2.PRGROMSizeMSB << 8)
| header.PRGROMSize);
prgRomSize = extendedSize * 16384;
msb = (byte)(header2.PRGCHRMSB >> 4);
extendedSize = (ushort)((msb << 8) | header.CHRROMSize);
extendedSize = (ushort)((header2.CHRROMSizeMSB << 8)
| header.CHRROMSize);
chrRomSize = extendedSize * 8192;
}
@@ -114,22 +114,38 @@ namespace SabreTools.Serialization.Readers
obj.PRGROMSize = prgRomSize;
obj.CHRROMSize = chrRomSize;
// Flag 6
// Byte 6
obj.NametableArrangement = nametableArrangement;
obj.BatteryBackedPRGRAM = batteryBackedPrgRam;
obj.TrainerPresent = trainerPresent;
obj.AlternativeNametableLayout = alternativeNametableLayout;
obj.MapperLowerNibble = mapperLowerNibble;
// Flag 7
// Byte 7
obj.ConsoleType = consoleType;
obj.NES20 = nes20;
obj.MapperUpperNibble = mapperUpperNibble;
obj.MapperMSBSubmapper = data.ReadByteValue();
obj.PRGCHRMSB = data.ReadByteValue();
obj.PRGRAMEEPROMSize = data.ReadByteValue();
obj.CHRRAMSize = data.ReadByteValue();
// Byte 8
byte byte8 = data.ReadByteValue();
obj.MapperMSB = (byte)(byte8 & 0x0F);
obj.Submapper = (byte)((byte8 >> 4) & 0x0F);
// Byte 9
byte byte9 = data.ReadByteValue();
obj.PRGROMSizeMSB = (byte)(byte9 & 0x0F);
obj.CHRROMSizeMSB = (byte)((byte9 >> 4) & 0x0F);
// Byte 10
byte byte10 = data.ReadByteValue();
obj.PRGRAMShiftCount = (byte)(byte10 & 0x0F);
obj.PRGNVRAMEEPROMShiftCount = (byte)((byte10 >> 4) & 0x0F);
// Byte 11
byte byte11 = data.ReadByteValue();
obj.CHRRAMShiftCount = (byte)(byte11 & 0x0F);
obj.CHRNVRAMShiftCount = (byte)((byte11 >> 4) & 0x0F);
obj.CPUPPUTiming = (CPUPPUTiming)data.ReadByteValue();
obj.ExtendedSystemType = data.ReadByteValue();
obj.MiscellaneousROMs = data.ReadByteValue();

View File

@@ -124,47 +124,39 @@ namespace SabreTools.Serialization.Wrappers
else if (header is Header2 header2)
{
// Byte 8
byte mapperMsb = (byte)(header2.MapperMSBSubmapper & 0x0F);
ushort extendedMapperNumber = (ushort)((mapperMsb << 8)
ushort extendedMapperNumber = (ushort)((header2.MapperMSB << 8)
| (byte)((header.MapperUpperNibble << 4)
| header.MapperLowerNibble));
byte submapperNumber = (byte)(header2.MapperMSBSubmapper >> 4);
builder.AppendLine(mapperMsb, " Mapper MSB");
builder.AppendLine(header2.MapperMSB, " Mapper MSB");
builder.AppendLine(extendedMapperNumber, " Extended mapper number");
builder.AppendLine(submapperNumber, " Submapper number");
builder.AppendLine(header2.Submapper, " Submapper");
// Byte 9
byte prgRomMsb = (byte)(header2.PRGCHRMSB & 0x0F);
ushort extendedPrgRomSize = (ushort)((prgRomMsb << 8) | header.PRGROMSize);
byte chrRomMsb = (byte)(header2.PRGCHRMSB >> 4);
ushort extendedChrRomSize = (ushort)((chrRomMsb << 8) | header.CHRROMSize);
ushort extendedPrgRomSize = (ushort)((header2.PRGROMSizeMSB << 8) | header.PRGROMSize);
ushort extendedChrRomSize = (ushort)((header2.CHRROMSizeMSB << 8) | header.CHRROMSize);
builder.AppendLine(prgRomMsb, " PRG-ROM size MSB");
builder.AppendLine(header2.PRGROMSizeMSB, " PRG-ROM size MSB");
builder.AppendLine(extendedPrgRomSize, " Extended PRG-ROM size");
builder.AppendLine(chrRomMsb, " CHR-ROM size MSB");
builder.AppendLine(header2.CHRROMSizeMSB, " CHR-ROM size MSB");
builder.AppendLine(extendedChrRomSize, " Extended CHR-ROM size");
// Byte 10
byte prgRamShiftCount = (byte)(header2.PRGRAMEEPROMSize & 0x0F);
int prgRamSize = prgRamShiftCount > 0 ? 64 << prgRamShiftCount : 0;
byte eepromShiftCount = (byte)(header2.PRGRAMEEPROMSize >> 4);
int eepromSize = eepromShiftCount > 0 ? 64 << eepromShiftCount : 0;
int prgRamSize = header2.PRGRAMShiftCount > 0 ? 64 << header2.PRGRAMShiftCount : 0;
int eepromSize = header2.PRGNVRAMEEPROMShiftCount > 0 ? 64 << header2.PRGNVRAMEEPROMShiftCount : 0;
builder.AppendLine(prgRamShiftCount, " PRG-RAM shift count");
builder.AppendLine(header2.PRGRAMShiftCount, " PRG-RAM shift count");
builder.AppendLine(prgRamSize, " PRG-RAM size");
builder.AppendLine(eepromShiftCount, " PRG-NVRAM/EEPROM shift count");
builder.AppendLine(header2.PRGNVRAMEEPROMShiftCount, " PRG-NVRAM/EEPROM shift count");
builder.AppendLine(eepromSize, " PRG-NVRAM/EEPROM size");
// Byte 11
byte chrRamShiftCount = (byte)(header2.CHRRAMSize & 0x0F);
int chrRamSize = chrRamShiftCount > 0 ? 64 << chrRamShiftCount : 0;
byte chrNvramShiftCount = (byte)(header2.CHRRAMSize >> 4);
int chrNvramSize = chrNvramShiftCount > 0 ? 64 << chrNvramShiftCount : 0;
int chrRamSize = header2.CHRRAMShiftCount > 0 ? 64 << header2.CHRRAMShiftCount : 0;
int chrNvramSize = header2.CHRNVRAMShiftCount > 0 ? 64 << header2.CHRNVRAMShiftCount : 0;
builder.AppendLine(chrRamShiftCount, " CHR-RAM shift count");
builder.AppendLine(header2.CHRRAMShiftCount, " CHR-RAM shift count");
builder.AppendLine(chrRamSize, " CHR-RAM size");
builder.AppendLine(chrNvramShiftCount, " CHR-NVRAM shift count");
builder.AppendLine(header2.CHRNVRAMShiftCount, " CHR-NVRAM shift count");
builder.AppendLine(chrNvramSize, " CHR-NVRAM size");
// Byte 12

View File

@@ -42,7 +42,7 @@ namespace SabreTools.Serialization.Wrappers
int chrRomSize = Header.CHRROMSize * 8192;
if (Header is Header2 header2)
chrRomSize = ((header2.PRGCHRMSB >> 4) << 8) | chrRomSize;
chrRomSize = (header2.CHRROMSizeMSB << 8) | chrRomSize;
return chrRomSize;
}
@@ -65,7 +65,7 @@ namespace SabreTools.Serialization.Wrappers
int mapperNumber = (Header.MapperUpperNibble << 4) | Header.MapperLowerNibble;
if (Header is Header2 header2)
mapperNumber = ((header2.MapperMSBSubmapper & 0x0F) << 8) | mapperNumber;
mapperNumber = (header2.MapperMSB << 8) | mapperNumber;
return mapperNumber;
}
@@ -90,18 +90,11 @@ namespace SabreTools.Serialization.Wrappers
return 0;
if (Header is Header1 header1)
{
return header1.PRGRAMSize > 0 ? header1.PRGRAMSize * 8192 : 8192;
}
else if (Header is Header2 header2)
{
byte shift = (byte)(header2.PRGRAMEEPROMSize & 0x0F);
return shift > 0 ? 64 << shift : 0;
}
return header2.PRGRAMShiftCount > 0 ? 64 << header2.PRGRAMShiftCount : 0;
else
{
return 0;
}
}
}
@@ -119,7 +112,7 @@ namespace SabreTools.Serialization.Wrappers
int prgRomSize = Header.PRGROMSize * 16384;
if (Header is Header2 header2)
prgRomSize = ((header2.PRGCHRMSB & 0x0F) << 8) | prgRomSize;
prgRomSize = (header2.PRGROMSizeMSB << 8) | prgRomSize;
return prgRomSize;
}
@@ -219,8 +212,7 @@ namespace SabreTools.Serialization.Wrappers
if (Header is null || Header is not Header2 header2)
return 0;
byte shift = (byte)(header2.CHRRAMSize >> 4);
return shift > 0 ? 64 << shift : 0;
return header2.CHRNVRAMShiftCount > 0 ? 64 << header2.CHRNVRAMShiftCount : 0;
}
}
@@ -236,8 +228,7 @@ namespace SabreTools.Serialization.Wrappers
if (Header is null || Header is not Header2 header2)
return 0;
byte shift = (byte)(header2.CHRRAMSize & 0x0F);
return shift > 0 ? 64 << shift : 0;
return header2.CHRRAMShiftCount > 0 ? 64 << header2.CHRRAMShiftCount : 0;
}
}
@@ -322,8 +313,7 @@ namespace SabreTools.Serialization.Wrappers
if (Header is null || Header is not Header2 header2)
return 0;
byte shift = (byte)(header2.PRGRAMEEPROMSize >> 4);
return shift > 0 ? 64 << shift : 0;
return header2.PRGNVRAMEEPROMShiftCount > 0 ? 64 << header2.PRGNVRAMEEPROMShiftCount : 0;
}
}
@@ -339,7 +329,7 @@ namespace SabreTools.Serialization.Wrappers
if (Header is null || Header is not Header2 header2)
return 0;
return header2.MapperMSBSubmapper >> 4;
return header2.Submapper;
}
}