BusDevice

Trait BusDevice 

Source
pub trait BusDevice: Debug {
    type Timestamp: Sized;
    type NextDevice: BusDevice<Timestamp = Self::Timestamp>;

    // Required methods
    fn next_device_mut(&mut self) -> &mut Self::NextDevice;
    fn next_device_ref(&self) -> &Self::NextDevice;
    fn into_next_device(self) -> Self::NextDevice;

    // Provided methods
    fn reset(&mut self, timestamp: Self::Timestamp) { ... }
    fn update_timestamp(&mut self, timestamp: Self::Timestamp) { ... }
    fn next_frame(&mut self, eof_timestamp: Self::Timestamp) { ... }
    fn read_io(
        &mut self,
        port: u16,
        timestamp: Self::Timestamp,
    ) -> Option<(u8, Option<NonZeroU16>)> { ... }
    fn write_io(
        &mut self,
        port: u16,
        data: u8,
        timestamp: Self::Timestamp,
    ) -> Option<u16> { ... }
    fn type_id(&self) -> TypeId
       where Self: 'static { ... }
}
Expand description

An interface for emulating devices that communicate with the emulated CPU via I/O requests.

This trait allows attaching many, different devices to form a so-called “daisy chain”.

Implementations of this trait should be provided as an associated type of ControlUnit::BusDevice.

Required Associated Types§

Source

type Timestamp: Sized

A type used as a time-stamp.

Source

type NextDevice: BusDevice<Timestamp = Self::Timestamp>

A type of the next device in a daisy chain.

Required Methods§

Source

fn next_device_mut(&mut self) -> &mut Self::NextDevice

Returns a mutable reference to the next device.

Source

fn next_device_ref(&self) -> &Self::NextDevice

Returns a reference to the next device.

Source

fn into_next_device(self) -> Self::NextDevice

Destructs self and returns the instance of the next bus device.

Provided Methods§

Source

fn reset(&mut self, timestamp: Self::Timestamp)

Resets the device and all devices in this chain.

This method is called from ControlUnit::reset.

Default implementation forwards this call to the next device.

NOTE: Implementations should always forward this call down the chain after optionally applying it to self.

Source

fn update_timestamp(&mut self, timestamp: Self::Timestamp)

This method should be called near the end of each frame.

Default implementation forwards this call to the next device.

NOTE: Implementations should always forward this call down the chain after optionally applying it to self.

Source

fn next_frame(&mut self, eof_timestamp: Self::Timestamp)

This method should be called just before the T-state counter of the control unit is wrapped when preparing for the next frame.

It allows the devices that are tracking time to adjust stored timestamps accordingly by subtracting the total number of T-states per frame from the stored ones. The eof_timestamp argument indicates the total number of T-states in a single frame.

Optionally enables implementations to perform an end-of-frame action.

Default implementation forwards this call to the next device.

NOTE: Implementations should always forward this call down the chain after optionally applying it to self.

Source

fn read_io( &mut self, port: u16, timestamp: Self::Timestamp, ) -> Option<(u8, Option<NonZeroU16>)>

This method is called by the control unit during an I/O read cycle.

Default implementation forwards this call to the next device.

Returns an optional tuple with the (data, insert wait states).

NOTE: Implementations should only need to forward this call if it does not apply to this device or if not all bits are modified by the implementing device. In the latter case the result from the forwarded call should be logically ANDed with the result of reading from this device and if the upstream result is None the result should be returned with all unused bits set to 1.

Source

fn write_io( &mut self, port: u16, data: u8, timestamp: Self::Timestamp, ) -> Option<u16>

This method is called by the control unit during an I/O write cycle.

Returns Some(insert wait states) if the device has blocked writing through it.

Default implementation forwards this call to the next device.

NOTE: Implementations should only forward this call to the next device if it does not apply to this device or if the device doesn’t block writing. If the device blocks writing to downstream devices and the port matches, this method must return true. Otherwise this method should return the forwarded result.

Source

fn type_id(&self) -> TypeId
where Self: 'static,

Gets the TypeId of self.

A required part for the ability to downcast dynamic BusDevice instances.

§Safety

The default implementation of this method must not be overwritten by the specializations. Consider this method as final.

Implementations on Foreign Types§

Source§

impl<D: BusDevice> BusDevice for Box<D>

Source§

type Timestamp = <D as BusDevice>::Timestamp

Source§

type NextDevice = <D as BusDevice>::NextDevice

Source§

fn next_device_mut(&mut self) -> &mut Self::NextDevice

Source§

fn next_device_ref(&self) -> &Self::NextDevice

Source§

fn into_next_device(self) -> Self::NextDevice

Source§

fn reset(&mut self, timestamp: Self::Timestamp)

Source§

fn update_timestamp(&mut self, timestamp: Self::Timestamp)

Source§

fn next_frame(&mut self, eof_timestamp: Self::Timestamp)

Source§

fn read_io( &mut self, port: u16, timestamp: Self::Timestamp, ) -> Option<(u8, Option<NonZeroU16>)>

Source§

fn write_io( &mut self, port: u16, data: u8, timestamp: Self::Timestamp, ) -> Option<u16>

Implementors§