Skip to main content

RomFile

Struct RomFile 

Source
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: PrgMemory

PRG (program) memory sizes.

§chr_memory: ChrMemory

CHR (character/graphics) memory sizes.

§mapper: RomMapper

iNES mapper number identifying the cartridge board hardware.

§default_expansion_device: ExpansionDevice

Default expansion device identifier (NES 2.0).

§misc_rom_count: u8

Number 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: RomTimingRegion

CPU/PPU timing mode (0 = NTSC, 1 = PAL, 2 = Multi-region, 3 = Dendy).

§console_type: ConsoleType

Console type (0 = NES/Famicom, 1 = VS System, 2 = Playchoice-10, 3 = Extended).

§hardwired_nametable_layout: bool

Nametable mirroring mode from header bit 0 (true = vertical, false = horizontal).

§is_battery_backed: bool

Whether the cartridge contains battery-backed persistent memory.

§trainer_present: bool

Whether a 512-byte trainer is present before PRG data.

§alternative_nametables: bool

Whether the ROM uses alternative nametable layouts.

§submapper_number: u8

Submapper 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

Source

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:

Trait Implementations§

Source§

impl Clone for RomFile

Source§

fn clone(&self) -> RomFile

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RomFile

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for RomFile

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<&[u8]> for RomFile

Source§

fn from(data: &[u8]) -> Self

Converts to this type from the input type.
Source§

impl From<&(&[u8], String)> for RomFile

Source§

fn from((data, name): &(&[u8], String)) -> Self

Converts to this type from the input type.
Source§

impl From<&RomFile> for RomFile

Source§

fn from(rom: &RomFile) -> Self

Converts to this type from the input type.
Source§

impl From<&String> for RomFile

Available on non-WebAssembly only.
Source§

fn from(path: &String) -> Self

Converts to this type from the input type.
Source§

impl Hash for RomFile

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for RomFile

Source§

fn eq(&self, other: &RomFile) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for RomFile

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for RomFile

Source§

impl StructuralPartialEq for RomFile

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,