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.
Implementations§
source§impl BiChannelIO
impl BiChannelIO
sourcepub fn new(
reader: impl Read + Send + 'static,
writer: impl Write + Send + 'static,
flush_every_byte: bool,
) -> Self
pub fn new( reader: impl Read + Send + 'static, writer: impl Write + Send + 'static, flush_every_byte: bool, ) -> Self
Creates a new bi-channel IO device with the given reader and writer.
This invokes the reader’s Read::read method every time the IO input receives a byte.
Note that internally, this uses the Read::bytes iterator.
Thus, the same cautions of using that iterator apply here.
This calls the writer’s Write::write_all method
every time a byte needs to be written to the IO output.
This IO calls Write::flush when the IO is ready to drop.
This function also has a flush_every_byte flag, which designates
whether Write::flush is also called for every byte.
This may be useful to enable for displaying real time 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.
sourcepub fn stdio() -> Self
pub fn stdio() -> Self
Creates a bi-channel IO device with std::io::stdin being the reader channel
and std::io::stdout being the writer channel.
Note that the simulator will only have access to the input data after a new line is typed (in terminal stdin). Similarly, printed output will only appear once (terminal) stdout is flushed or once a new line is sent.