use crate::*; pub struct SystemDevice { /// Name and version of this system. pub name: ReadBuffer, /// Authors of this system. pub authors: ReadBuffer, /// Mask of all devices waiting to wake from sleep. pub wakers: u16, /// Device that most recently woke the system. pub waker: u8, /// True if the system has been put to sleep. pub asleep: bool, /// Mask of all available devices. pub devices: u16, /// Name of the first custom devices. pub custom1: ReadBuffer, /// Name of the second custom devices. pub custom2: ReadBuffer, /// Name of the third custom devices. pub custom3: ReadBuffer, /// Name of the fourth custom devices. pub custom4: ReadBuffer, } impl Device for SystemDevice { fn read(&mut self, port: u8) -> u8 { match port { 0x0 => 0x00, 0x1 => 0x00, 0x2 => self.waker, 0x3 => 0x00, 0x4 => 0x00, 0x5 => 0x00, 0x6 => 0x00, 0x7 => 0x00, 0x8 => self.name.read(), 0x9 => self.authors.read(), 0xa => 0x00, 0xb => 0x00, 0xc => 0x00, 0xd => 0x00, 0xe => read_h!(self.devices), 0xf => read_l!(self.devices), _ => unreachable!(), } } fn write(&mut self, port: u8, value: u8) -> Option { match port { 0x0 => write_h!(self.wakers, value), 0x1 => { write_l!(self.wakers, value); self.asleep = true; return Some(Signal::Sleep); }, 0x2 => (), 0x3 => return Some(Signal::Fork), 0x4 => (), 0x5 => (), 0x6 => (), 0x7 => (), 0x8 => self.name.pointer = 0, 0x9 => self.authors.pointer = 0, 0xa => (), 0xb => (), 0xc => (), 0xd => (), 0xe => (), 0xf => (), _ => unreachable!(), }; return None; } fn wake(&mut self) -> bool { false } } impl SystemDevice { pub fn new(devices: u16) -> Self { Self { name: get_name(), authors: get_authors(), wakers: 0, waker: 0, asleep: false, devices, custom1: ReadBuffer::new(), custom2: ReadBuffer::new(), custom3: ReadBuffer::new(), custom4: ReadBuffer::new(), } } } fn get_name() -> ReadBuffer { let pkg_version = env!("CARGO_PKG_VERSION"); let pkg_name = env!("CARGO_PKG_NAME"); ReadBuffer::from_str(&format!("{pkg_name}/{pkg_version}")) } fn get_authors() -> ReadBuffer { let pkg_authors = env!("CARGO_PKG_AUTHORS"); let mut authors_string = String::new(); for author in pkg_authors.split(':') { authors_string.push_str(author); authors_string.push('\n'); } ReadBuffer::from_str(&authors_string) }