cpu/
event.rs

1//! Input and output events.
2use std::error::Error;
3use std::fmt::{self, Display, Formatter};
4
5use base::Unsigned6Bit;
6use base::charset::DescribedChar;
7
8use super::alarm::Alarm;
9
10/// An input event.
11#[derive(Debug)]
12pub enum InputEvent {
13    PetrMountPaperTape { data: Vec<u8> },
14    LwKeyboardInput { data: Vec<Unsigned6Bit> },
15}
16
17/// A failed input event.
18#[derive(Debug)]
19pub enum InputEventError {
20    /// `BufferUnavailable` means that an input event has occurred on
21    /// a device whose buffer is still being used by the CPU.
22    /// Sometimes this can happen if the program running on the TX-2
23    /// makes use of the hold bit too much in some sequence, with the
24    /// result that the sequence that should be reading the device
25    /// (and hence freeing the buffer) isn't getting a chance to do
26    /// this.
27    BufferUnavailable,
28
29    /// `InputOnUnattachedUnit` means that the user has generated
30    /// input on a unit which has not been attached.  That is, the
31    /// simulator does not believe that this hardware exists in the
32    /// system at all.  This would likely be due to some configuration
33    /// inconsistency between the user interface and the simulator
34    /// core.
35    InputOnUnattachedUnit,
36
37    InputEventNotValidForDevice,
38    InvalidReentrantCall,
39
40    Alarm(Alarm),
41}
42
43impl Display for InputEventError {
44    fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), fmt::Error> {
45        match self {
46            InputEventError::BufferUnavailable => f.write_str("buffer unavailable"),
47            InputEventError::InputOnUnattachedUnit => {
48                f.write_str("input on a unit which is not attached")
49            }
50            InputEventError::InputEventNotValidForDevice => {
51                f.write_str("input event is not valid for this device")
52            }
53            InputEventError::InvalidReentrantCall => f.write_str("inalid re-entrant call"),
54            InputEventError::Alarm(alarm) => alarm.fmt(f),
55        }
56    }
57}
58
59impl Error for InputEventError {}
60
61/// An output event.
62#[derive(Debug, PartialEq, Eq)]
63pub enum OutputEvent {
64    /// A code has arrived at a Lincoln Writer.
65    LincolnWriterPrint {
66        unit: Unsigned6Bit,
67        ch: DescribedChar,
68    },
69}