#[non_exhaustive]pub struct Header {Show 20 fields
pub is_nes2: bool,
pub mapper_id: u16,
pub submapper: u8,
pub prg_size: usize,
pub chr_size: usize,
pub mirroring: Mirroring,
pub region: Region,
pub console_type: ConsoleType,
pub vs_ppu_type: VsPpuType,
pub vs_hardware_type: Option<VsHardwareType>,
pub extended_console_type: Option<ExtendedConsoleType>,
pub misc_rom_count: u8,
pub default_expansion_device: ExpansionDevice,
pub prg_ram_size: u32,
pub prg_nvram_size: u32,
pub chr_ram_size: u32,
pub chr_nvram_size: u32,
pub has_battery: bool,
pub has_trainer: bool,
pub four_screen: bool,
}Expand description
Parsed header view, format-detected.
Every field a 16-byte iNES / NES 2.0 header defines is modelled (since
v2.9.8): what is left over are the reserved bits (byte 12 bits 2-7, byte 13
for console types 0 and 2, byte 13 bits 4-7 for console type 3, byte 14
bits 2-7, byte 15 bit 7) and, on an iNES 1.0 header, bytes 8-15, which are
not part of that format. serialize_header_preserving keeps all of those.
iNES 1.0. The NES 2.0-only fields hold a fixed value on an iNES 1.0
header, whatever its bytes 8-15 contain (old dumpers wrote signatures
there): submapper 0, region NTSC, console_type NES,
vs_hardware_type / extended_console_type None, vs_ppu_type
VsPpuType::None, misc_rom_count 0, default_expansion_device
ExpansionDevice::Unspecified, both NVRAM sizes 0, and the two RAM sizes
the nominal values described on each field.
#[non_exhaustive]: outside this crate, build one with Header::default
and field assignment (or parse_header), so a field added later is not
an API break.
The 5 boolean flags directly mirror the iNES / NES 2.0 wire format and so are not refactorable into an enum without losing parser fidelity.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.is_nes2: boolTrue if the file is NES 2.0 (header byte 7 bits 2-3 == 10).
mapper_id: u1612-bit mapper id (iNES 1.0 fills only the low 8 bits).
submapper: u84-bit submapper id (NES 2.0 only; 0 on iNES 1.0).
prg_size: usizePRG-ROM size in bytes.
chr_size: usizeCHR-ROM size in bytes (0 if cart uses CHR-RAM).
mirroring: MirroringEffective initial mirroring.
region: RegionRegion from NES 2.0 byte 12; defaults to NTSC for iNES 1.0.
console_type: ConsoleTypeConsole type from NES 2.0 byte 7; always ConsoleType::Nes for iNES 1.0.
vs_ppu_type: VsPpuTypeVs. System PPU type from NES 2.0 byte 13 low nibble, valid only when
console_type == ConsoleType::VsSystem (otherwise VsPpuType::None).
Resolves to the output palette + 2C05 quirks via VsPpuType::ppu_palette
/ VsPpuType::is_2c05. The reserved nibbles ($1, $6, $7,
$C-$F) decode as VsPpuType::Rp2C03, so they do not survive a
canonical re-encode; serialize_header_preserving keeps them.
vs_hardware_type: Option<VsHardwareType>Vs. hardware type from NES 2.0 byte 13 high nibble: Some exactly when
the header is NES 2.0 and console_type == ConsoleType::VsSystem.
Types 5 and 6 are the Vs. DualSystem boards; see
Header::is_vs_dual_system.
extended_console_type: Option<ExtendedConsoleType>Extended console type from NES 2.0 byte 13 low nibble: Some exactly
when the header is NES 2.0 and console_type == ConsoleType::Extended.
misc_rom_count: u8Number of miscellaneous ROMs present (NES 2.0 byte 14 bits 0-1, so
0..=3; 0 on iNES 1.0). The miscellaneous ROM area itself is whatever
follows CHR-ROM in the file.
default_expansion_device: ExpansionDeviceDefault expansion device (NES 2.0 byte 15 bits 0-6;
ExpansionDevice::Unspecified on iNES 1.0).
prg_ram_size: u32Volatile PRG-RAM size in bytes: NES 2.0 byte 10 low nibble. iNES 1.0 has no size field, so it reports a nominal 8 KiB.
Until v2.9.8 this field held the volatile and non-volatile sizes
summed; that total is now Header::prg_ram_window.
prg_nvram_size: u32Non-volatile (battery-backed) PRG-RAM / EEPROM size in bytes: NES 2.0
byte 10 high nibble. 0 on iNES 1.0, which has no NVRAM split (whether
its nominal RAM is battery-backed is Header::has_battery).
chr_ram_size: u32Volatile CHR-RAM size in bytes: NES 2.0 byte 11 low nibble. iNES 1.0 reports a nominal 8 KiB when there is no CHR-ROM, otherwise 0.
chr_nvram_size: u32Non-volatile CHR-RAM size in bytes: NES 2.0 byte 11 high nibble. 0 on iNES 1.0. No board in this crate allocates CHR-NVRAM from it.
has_battery: boolTrue when battery-backed PRG-RAM is present (header[6] bit 1).
has_trainer: boolTrue when a 512-byte trainer follows the header (header[6] bit 2).
four_screen: boolTrue when bit 3 of header[6] forces four-screen mode.
Implementations§
Source§impl Header
impl Header
Sourcepub const fn prg_ram_window(&self) -> u32
pub const fn prg_ram_window(&self) -> u32
The whole PRG-RAM window a board allocates at $6000-$7FFF: the
volatile and non-volatile sizes together. Some carts (StarTropics /
MMC6) declare their save RAM only in the NVRAM nibble, so reading the
volatile size alone would leave them with none.
Sourcepub const fn is_vs_dual_system(&self) -> bool
pub const fn is_vs_dual_system(&self) -> bool
True when the header names a Vs. DualSystem board (Vs. hardware type
5 or 6). Drives DUAL-system detection; see docs/cartridge-format.md.
Trait Implementations§
impl Copy for Header
Source§impl Default for Header
impl Default for Header
Source§fn default() -> Self
fn default() -> Self
An iNES 1.0 header for mapper 0 with no ROM, horizontal mirroring, and
every other field at the value parse_header gives an iNES 1.0 file
with all-zero bytes 4-15, so parse_header(&canonical(default)) is
the default again.