pub trait Device {
// Required methods
fn with_data(data: &[u8]) -> Self
where Self: Sized;
fn init_data(&mut self, data: &[u8]);
fn read(&self, addr: u16) -> u8;
fn write(&mut self, data: u8, addr: u16);
fn addr_space_size() -> u32
where Self: Sized;
fn addr_space_size_dyn(&self) -> u32;
// Provided methods
fn cache_current_read_data(&self, destination: &mut [u8]) { ... }
fn addr_bits_count() -> u8
where Self: Sized { ... }
fn addr_bits_count_dyn(&self) -> u8 { ... }
fn wrap_addr(addr: u16) -> u16
where Self: Sized { ... }
fn is_connected(&self) -> bool { ... }
}Expand description
Trait for memory-mapped devices in a 6502 system.
The Device trait defines a common interface for all memory-mapped devices, such as RAM, ROM,
and composite devices. It provides methods for reading and writing memory, initializing device
data, and querying address space properties. All device types in this crate implement this trait.
Required Methods§
Sourcefn with_data(data: &[u8]) -> Selfwhere
Self: Sized,
fn with_data(data: &[u8]) -> Selfwhere
Self: Sized,
Creates a new device instance initialized with the provided data.
§Arguments
data- A slice containing the initial data for the device.
Sourcefn init_data(&mut self, data: &[u8])
fn init_data(&mut self, data: &[u8])
Initializes the device with the provided data.
§Arguments
data- A slice containing the data to copy into the device.
Sourcefn write(&mut self, data: u8, addr: u16)
fn write(&mut self, data: u8, addr: u16)
Writes a byte to the specified address.
§Arguments
data- The byte to write.addr- The address to write to.
Sourcefn addr_space_size() -> u32where
Self: Sized,
fn addr_space_size() -> u32where
Self: Sized,
Returns the total size of the device’s address space in bytes (static method).
§Returns
The size of the address space in bytes.
Sourcefn addr_space_size_dyn(&self) -> u32
fn addr_space_size_dyn(&self) -> u32
Returns the total size of the device’s address space in bytes (dynamic method).
§Returns
The size of the address space in bytes.
Provided Methods§
Sourcefn cache_current_read_data(&self, destination: &mut [u8])
fn cache_current_read_data(&self, destination: &mut [u8])
Copies the current contents of the device into the provided destination buffer.
§Arguments
destination- The buffer to copy the device contents to.
Sourcefn addr_bits_count() -> u8where
Self: Sized,
fn addr_bits_count() -> u8where
Self: Sized,
Returns the number of address bits needed to address this device (static method).
§Returns
The number of address bits.
Sourcefn addr_bits_count_dyn(&self) -> u8
fn addr_bits_count_dyn(&self) -> u8
Returns the number of address bits needed to address this device (dynamic method).
§Returns
The number of address bits.
Sourcefn is_connected(&self) -> bool
fn is_connected(&self) -> bool
Returns true if the device is currently connected.
This can be used for devices that may be hot-swapped or disconnected at runtime.