Skip to main content

Device

Trait Device 

Source
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§

Source

fn with_data(data: &[u8]) -> Self
where Self: Sized,

Creates a new device instance initialized with the provided data.

§Arguments
  • data - A slice containing the initial data for the device.
Source

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.
Source

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

Reads a byte from the specified address.

§Arguments
  • addr - The address to read from.
§Returns

The byte read from the device.

Source

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.
Source

fn addr_space_size() -> u32
where 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.

Source

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§

Source

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.
Source

fn addr_bits_count() -> u8
where Self: Sized,

Returns the number of address bits needed to address this device (static method).

§Returns

The number of address bits.

Source

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.

Source

fn wrap_addr(addr: u16) -> u16
where Self: Sized,

Wraps an address to fit within the device’s address space.

This is useful for devices whose address space is smaller than 16 bits.

§Arguments
  • addr - The address to wrap.
§Returns

The wrapped address.

Source

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.

Implementors§

Source§

impl<T1, T2> Device for Adjacent<T1, T2>
where T1: Device + Default, T2: Device + Default,

Source§

impl<T, const N: u32> Device for Mirror<T, N>
where T: Device + Default,

Source§

impl<TR, TW> Device for ReadWrite<TR, TW>
where TR: Device + Default, TW: Device + Default,

Source§

impl<const ADDR_BITS: u8> Device for Socket<ADDR_BITS>

Source§

impl<const SIZE: usize> Device for Ram<SIZE>

Source§

impl<const SIZE: usize> Device for Rom<SIZE>