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 10x1000..=0x1FFF
: Pattern table 20x2000..=0x23FF
: Nametable 10x2400..=0x27FF
: Nametable 20x2800..=0x2BFF
: Nametable 30x2C00..=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§
sourcefn read(&mut self, addr: u16) -> u8
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.
sourcefn write(&mut self, addr: u16, value: u8)
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.