pub struct RomFile {Show 18 fields
pub name: Option<String>,
pub prg_memory: PrgMemory,
pub chr_memory: ChrMemory,
pub mapper: RomMapper,
pub default_expansion_device: ExpansionDevice,
pub misc_rom_count: u8,
pub extended_console_type: Option<ExtendedConsoleType>,
pub vs_system_hardware_type: Option<VsHardwareType>,
pub vs_system_ppu_type: Option<VsSystemPpuType>,
pub timing_region: RomTimingRegion,
pub console_type: ConsoleType,
pub hardwired_nametable_layout: bool,
pub is_battery_backed: bool,
pub trainer_present: bool,
pub alternative_nametables: bool,
pub submapper_number: u8,
pub data_checksum: [u8; 32],
pub data: Vec<u8>,
}Expand description
A parsed NES ROM file.
Contains all metadata extracted from the ROM header (mapper number, memory sizes, mirroring, etc.) as well as the raw ROM data used for loading into the emulator’s memory map.
§Loading a ROM
use monsoon_core::emulation::rom::RomFile;
let rom = RomFile::load(raw_bytes, Some("my_game.nes".to_string())).expect("invalid ROM");
println!("Mapper: {}", rom.mapper);§Constructing a ROM programmatically
Use RomBuilder for test scenarios where you need custom ROM metadata
without providing actual ROM data.
Fields§
§name: Option<String>Human-readable name of the ROM (typically the file name).
prg_memory: PrgMemoryPRG (program) memory sizes.
chr_memory: ChrMemoryCHR (character/graphics) memory sizes.
mapper: RomMapperiNES mapper number identifying the cartridge board hardware.
default_expansion_device: ExpansionDeviceDefault expansion device identifier (NES 2.0).
misc_rom_count: u8Number of miscellaneous ROM areas (NES 2.0).
extended_console_type: Option<ExtendedConsoleType>Extended console type (NES 2.0), if applicable.
vs_system_hardware_type: Option<VsHardwareType>VS System hardware type, if applicable.
vs_system_ppu_type: Option<VsSystemPpuType>VS System PPU type, if applicable.
timing_region: RomTimingRegionCPU/PPU timing mode (0 = NTSC, 1 = PAL, 2 = Multi-region, 3 = Dendy).
console_type: ConsoleTypeConsole type (0 = NES/Famicom, 1 = VS System, 2 = Playchoice-10, 3 = Extended).
hardwired_nametable_layout: boolNametable mirroring mode from header bit 0 (true = vertical, false =
horizontal).
is_battery_backed: boolWhether the cartridge contains battery-backed persistent memory.
trainer_present: boolWhether a 512-byte trainer is present before PRG data.
alternative_nametables: boolWhether the ROM uses alternative nametable layouts.
submapper_number: u8Submapper number (NES 2.0).
data_checksum: [u8; 32]SHA-256 checksum of the raw ROM data.
data: Vec<u8>Raw ROM file bytes. Skipped during serialization to reduce save state size.
Implementations§
Source§impl RomFile
impl RomFile
Sourcepub fn load(data: &[u8], name: Option<String>) -> Result<RomFile, ParseError>
pub fn load(data: &[u8], name: Option<String>) -> Result<RomFile, ParseError>
Parses a ROM file from raw bytes.
Auto-detects the ROM format (iNES, NES 2.0, archaic iNES, etc.)
from the header and extracts all metadata. The raw data is stored
in data and a SHA-256 checksum is computed.
§Arguments
data— The complete ROM file as a byte slice.name— An optional human-readable name (e.g., the file name).
§Errors
Returns a ParseError if:
- The data is too short to contain a valid header
(
ParseError::InvalidHeader). - The ROM format is not recognized (
ParseError::UnsupportedFormat). - The header declares sizes larger than the file
(
ParseError::SizeBiggerThanFile).