Skip to main content

Cartridge

Struct Cartridge 

Source
#[non_exhaustive]
pub struct Cartridge {
Show 15 fields pub prg_rom: Box<[u8]>, pub chr_rom: Box<[u8]>, pub mapper_id: u16, pub submapper: u8, pub mirroring: Mirroring, pub region: Region, pub console_type: ConsoleType, pub vs_ppu_type: VsPpuType, pub vs_dual_system: bool, pub prg_ram_size: u32, pub chr_ram_size: u32, pub has_battery: bool, pub has_trainer: bool, pub is_nes2: bool, pub nametable_wiring_bits: u8,
}
Expand description

Concrete iNES / NES 2.0 cartridge value.

prg_rom and chr_rom are read-only ROM banks. prg_ram_size and chr_ram_size are requested sizes; mapper implementations allocate the matching RAM buffers in their constructors.

Field set follows docs/cartridge-format.md §Public API. mapper (the boxed dyn Mapper from docs/mappers.md) is constructed by crate::parse and stored on the cartridge separately from this metadata header so the metadata is cheap to clone.

#[non_exhaustive] since v3.0.0 (T-API-EXTENSIBLE): outside this crate a cartridge comes from crate::parse (or the other loaders), or from Cartridge::synthetic for a device with no cartridge header; set the public fields that differ afterwards. A later header field is then not a break, as nametable_wiring_bits was at v2.9.9.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§prg_rom: Box<[u8]>

PRG-ROM bytes. Length is a multiple of 16 KiB for standard sizes; may be irregular when the NES 2.0 exponent-multiplier encoding is used.

§chr_rom: Box<[u8]>

CHR-ROM bytes. Empty when the cartridge uses CHR-RAM (length 0).

§mapper_id: u16

12-bit mapper id (iNES 1.0 only uses the low 8 bits).

§submapper: u8

4-bit submapper id (NES 2.0 only; always 0 for iNES 1.0).

§mirroring: Mirroring

Initial mirroring as selected by the header.

§region: Region

Region from NES 2.0 byte 12; defaults to Region::Ntsc for iNES 1.0.

§console_type: ConsoleType

Console type from NES 2.0 byte 7; always ConsoleType::Nes for iNES 1.0.

§vs_ppu_type: VsPpuType

Vs. System PPU type from NES 2.0 byte 13 (low nibble), valid only when console_type == ConsoleType::VsSystem; VsPpuType::None otherwise.

§vs_dual_system: bool

True when the header marks a Vs. DualSystem board (NES 2.0 byte-13 high nibble = Vs. hardware type 5/6). Detection only; the two-CPU/two-PPU emulation is a documented v2.0 deferral.

§prg_ram_size: u32

Requested PRG-RAM size in bytes.

§chr_ram_size: u32

Requested CHR-RAM size in bytes (0 if the cart ships with CHR-ROM only).

§has_battery: bool

True if the cartridge has non-volatile save data: battery-backed PRG-RAM per the header, or (v2.9.6) a self-flashable board’s flash (mappers 30 and 111), set by the loader whatever the header’s bit says.

§has_trainer: bool

True if a 512-byte trainer was present in the file (loaded at $7000-$71FF).

§is_nes2: bool

True if the file format is NES 2.0 (vs. iNES 1.0).

§nametable_wiring_bits: u8

The raw iNES byte-6 nametable bits, byte6 & 0x09 (bit 3 four-screen, bit 0 the arrangement bit), before Self::mirroring folds them. Mappers 30 (UNROM 512) and 218 (Magic Floor) wire CIRAM from these bits directly, so two headers that both say FourScreen can build different machines; v2.9.9 carries the bits so the movie and netplay board check can tell them apart (core re-audit NC-10). Zero for formats without an iNES header (FDS, NSF).

Implementations§

Source§

impl Cartridge

Source

pub fn synthetic(mapper_id: u16, prg_ram_size: u32, chr_ram_size: u32) -> Self

v3.0.0 — metadata for a machine whose program does not come from a cartridge header (the FDS, an NSF player): empty PRG/CHR-ROM, NTSC, horizontal mirroring, a stock NES, no battery, trainer or NES 2.0 header, and the given mapper id and RAM sizes. The bus consults little of it for such a machine; the device owns its own storage. Set any field that differs after construction.

Source

pub fn uses_chr_ram(&self) -> bool

Returns true when this cartridge ships PRG-ROM only (no CHR-ROM bank).

Trait Implementations§

Source§

impl Clone for Cartridge

Source§

fn clone(&self) -> Cartridge

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Cartridge

Source§

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

Formats the value using the given formatter. Read more

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> 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.