Struct lc3_ensemble::sim::io::BiChannelIO

source ·
pub struct BiChannelIO { /* private fields */ }
Expand description

An IO that reads from one channel and writes to another.

This binds the reader channel to the KBSR and KBDR. When a character is ready from the reader channel, the KBSR status is enabled and the character is accessible from the KBDR.

This binds the writer channel to the DSR and DDR. When a character is ready to be written to the writer channel, the DSR status is enabled and the character can be written to the DDR.

This IO type also exposes the MCR in the MCR MMIO address.

Implementations§

source§

impl BiChannelIO

source

pub fn new( reader: impl FnMut() -> Result<u8, Stop> + Send + 'static, writer: impl FnMut(u8) -> Result<(), Stop> + Send + 'static ) -> Self

Creates a new bi-channel IO device with the given reader and writer.

This calls the reader function every time the IO input receives a byte. The reader function should block until a byte is ready, or return Stop if there are no more bytes to read.

This calls the writer function every time a byte needs to be written to the IO output.

This uses threads to read and write from input and output. As such, the channels will continue to poll input and output even when the simulator is not running. As such, care should be taken to not send messages through the reader thread while the simulator is not running.

source

pub fn stdio() -> Self

Creates a bi-channel IO device with stdin being the read data and stdout being the write data.

Note that due to how stdin works in terminals, data is only sent once a new line is typed. Additionally, this flushes stdout every time a byte is written.

Trait Implementations§

source§

impl From<BiChannelIO> for SimIO

source§

fn from(value: BiChannelIO) -> Self

Converts to this type from the input type.
source§

impl IODevice for BiChannelIO

source§

fn io_read(&self, addr: u16) -> Option<u16>

Reads the data at the given memory-mapped address. Read more
source§

fn io_write(&self, addr: u16, data: u16) -> bool

Writes the data to the given memory-mapped address. Read more
source§

fn close(self)

Tries to close this IO device.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V