pub trait Memory {
type Timestamp: Sized;
fn read_mem(&self, address: u16, ts: Self::Timestamp) -> u8 { ... }
fn read_mem16(&self, address: u16, ts: Self::Timestamp) -> u16 { ... }
fn read_opcode(&mut self, pc: u16, ir: u16, ts: Self::Timestamp) -> u8 { ... }
fn write_mem(&mut self, address: u16, value: u8, ts: Self::Timestamp) { ... }
fn read_debug(&self, address: u16) -> u8 { ... }
}
Expand description
This trait defines an interface for accessing the host’s memory.
Please also see cycles module.
Required Associated Types§
sourcetype Timestamp: Sized
type Timestamp: Sized
This type is being used for timestamping memory operations. See also Clock::Timestamp.
Provided Methods§
sourcefn read_mem(&self, address: u16, ts: Self::Timestamp) -> u8
fn read_mem(&self, address: u16, ts: Self::Timestamp) -> u8
Should return a single byte read from the memory present at the given address
.
This method is being used by the Cpu to read data from memory
during the MEMRW
read cycle.
The timestamp
given here has been previously returned from Clock::add_mreq.
For reading data during M1
cycles Memory::read_opcode is being used instead.
The default implementation forwards call to Memory::read_debug.
sourcefn read_mem16(&self, address: u16, ts: Self::Timestamp) -> u16
fn read_mem16(&self, address: u16, ts: Self::Timestamp) -> u16
Should return the unaligned, 2 consecutive bytes from the memory present at the given
address
as a 16-bit unsigned integer in a LE
(least significant byte first) order.
This method is being used by the Cpu to read 16 bit values from memory
during the MEMRW
read cycle.
The real CPU splits this read but we are cutting corners here slightly.
The timestamp
given here has been previously returned from Clock::add_mreq.
The default implementation composes a 16-bit value from two calls to Memory::read_debug.
sourcefn read_opcode(&mut self, pc: u16, ir: u16, ts: Self::Timestamp) -> u8
fn read_opcode(&mut self, pc: u16, ir: u16, ts: Self::Timestamp) -> u8
Should return a single byte read from the memory present at the given pc
address.
This method is being used by the Cpu to read instruction opcodes
from memory during the M1
cycle and can be used e.g. for implementing ROM/instruction
traps.
Other, non M1
related Cpu read operations, are performed
via Memory::read_mem and Memory::read_mem16 methods.
pc
contains an address in memory from which the opcode should be read.ir
contains a memory refresh value that the real CPU would put on the bus during the memory refresh cycle.timestamp
has been previously returned from Clock::add_m1.
The default implementation forwards call to Memory::read_debug.
sourcefn write_mem(&mut self, address: u16, value: u8, ts: Self::Timestamp)
fn write_mem(&mut self, address: u16, value: u8, ts: Self::Timestamp)
Should write a byte value
into the memory at the given address
.
This method is being used by the Cpu to write data into memory
during the MEMRW
write cycle.
The timestamp
given here has been previously returned from Clock::add_mreq.
The default implementation is a no-op.
sourcefn read_debug(&self, address: u16) -> u8
fn read_debug(&self, address: u16) -> u8
Should return a single byte read from the memory present at the given address
.
This method is being used by the Cpu debugger to get a relative jump argument of a conditional instruction when a condition is not satisfied. If the debugger is not being used, this call should be optimized out by the compiler unless your implementation performs a volatile read here.
The default implementation returns u8::MAX
.