Trait nes_ppu::Mapper

source ·
pub trait Mapper {
    // Required methods
    fn read(&mut self, addr: u16) -> u8;
    fn write(&mut self, addr: u16, value: u8);
}
Expand description

Memory map used by the PPU to access video memory.

This trait enables the Ppu to read from video memory while rendering, in order to fetch tile and pattern data. In addition, internal palette data is accessible to the user by using certain address ranges.

The PPU uses the following address ranges to look up the corresponding data:

  • 0x0000..=0x0FFF: Pattern table 1
  • 0x1000..=0x1FFF: Pattern table 2
  • 0x2000..=0x23FF: Nametable 1
  • 0x2400..=0x27FF: Nametable 2
  • 0x2800..=0x2BFF: Nametable 3
  • 0x2C00..=0x2FFF: Nametable 4

Addresses outside of these ranges can be mapped to anything. Furthermore, you may map addresses to overlapping regions of memory. For example, it is common to map the addresses for nametables 1 and 2 to the same memory that the addresses for nametables 3 and 4 are mapped to.

The address range 0x3F00..=0x3F1F and all subsequent addresses up to 0x3FFF always map to internal palette memory. On its own, the PPU will never access the mapper to read or write to addresses in this range. The only situation where the mapper can be accessed with an address in 0x3F00..=0x3FFF is via a call to Ppu::read_data().

Read more on the NESdev Wiki:

Required Methods§

source

fn read(&mut self, addr: u16) -> u8

Returns the value mapped to the provided 14-bit address.

This function is allowed to have side effects and consecutive reads of the same address do not need to return the same value.

A memory read does not actually need to occur.

source

fn write(&mut self, addr: u16, value: u8)

Writes to the value mapped to the provided 14-bit address.

This function is allowed to have side effects beyond the expressed memory write, and subsequent reads from the same address do not need to return value.

A memory write does not actually need to occur.

Implementors§