pub struct CodeMap { /* private fields */ }unstable only.Expand description
What execution has revealed about each byte of cartridge memory.
Only execution writes here, nothing decodes ahead of it. A byte is only code if it has been executed, which the disassembler cannot work out on its own: 6502 instructions are one to three bytes with no alignment, so a decode that starts inside data stays out of step with the real instruction boundaries until it happens to realign.
Keyed by Memory offset instead of CPU address, so a mark survives bank switches to another
address. Two banks that share an address do not share marks. See Memory::prg_offset.
Saved per ROM, so a session opens knowing what earlier ones ran. The generation is left out of that: it numbers changes for a view watching this map, and one just read has none to number.
Implementations§
Source§impl CodeMap
impl CodeMap
Sourcepub fn new(len: usize, rom_crc32: u32) -> Self
pub fn new(len: usize, rom_crc32: u32) -> Self
A map covering len bytes of the cart with CRC rom_crc32, with nothing yet known about
any of them.
Sourcepub fn mark(&mut self, offset: usize, kind: ByteKind)
pub fn mark(&mut self, offset: usize, kind: ByteKind)
Mark what the byte at offset has been shown to be.
An offset past the end of the memory this was built for is ignored, so a caller can pass on whatever a page table gave it without checking.
Sourcepub fn kind(&self, offset: usize) -> ByteKind
pub fn kind(&self, offset: usize) -> ByteKind
What is known about the byte at offset, empty for one nothing has revealed yet.
Sourcepub fn is_code(&self, offset: usize) -> bool
pub fn is_code(&self, offset: usize) -> bool
Whether the byte at offset has run as the first byte of an instruction.
Sourcepub const fn generation(&self) -> u64
pub const fn generation(&self) -> u64
Bumped whenever mark records something new.
A view built from the map becomes stale as code executes. Comparing this is how a consumer knows to rebuild.
Sourcepub fn covers(&self, memory: &Memory) -> bool
pub fn covers(&self, memory: &Memory) -> bool
Whether this was recorded against memory.
An offset means nothing against another arena, so a map kept across a cart change has to be refused rather than reused. The CRC says which game and the length says the geometry - two dumps of one game can differ in trainer or padding, and an arena built with no ROM to hash has only the geometry to go on.