[−][src]Struct pir_8_emu::vm::Ports
256B of I/O ports with R/W tracking and per-port handler logic
Methods
impl Ports
[src]
pub fn new() -> Ports
[src]
Create fresh zero-initialised unread and unwritten ports with no handlers
pub fn install_handler<H: PortHandler + 'static>(
&mut self,
handler: H,
ports: &[u8]
) -> Result<usize, (H, PortHandlerInstallError)>
[src]
&mut self,
handler: H,
ports: &[u8]
) -> Result<usize, (H, PortHandlerInstallError)>
Install the specified handler on the specified ports
On success, calls PortHandler::init()
on the specified handler
and returns a unique ID thereof
Will return an error if the specified ports are already occupied, or the handler doesn't take the amount of ports specified, or too many handlers've been registered
Examples
struct InitableHandler(Option<u8>); impl PortHandler for InitableHandler { fn init(&mut self, ports: &[u8]) { self.0 = Some(ports[0]); } } let mut ports = Ports::new(); let handler_id = ports.install_handler(InitableHandler(None), &[0xA1]) .map_err(|(_, e)| e).unwrap(); assert_eq!(ports.get_handler(handler_id).and_then(|h| h.downcast_ref()), Some(&InitableHandler(Some(0xA1))));
pub fn get_handler(&self, idx: usize) -> Option<&(dyn PortHandler + 'static)>
[src]
Get reference to the handler with the specified ID, if exists
pub fn get_handler_mut(
&mut self,
idx: usize
) -> Option<&mut (dyn PortHandler + 'static)>
[src]
&mut self,
idx: usize
) -> Option<&mut (dyn PortHandler + 'static)>
Get mutable reference to the handler with the specified ID, if exists
pub fn uninstall_handler(
&mut self,
idx: usize
) -> Option<Box<dyn PortHandler + 'static>>
[src]
&mut self,
idx: usize
) -> Option<Box<dyn PortHandler + 'static>>
Remove, unregister, and deinitialise the handler with the specified ID and return it, if exists
Examples
struct DeInitableHandler(Option<u8>, bool); impl PortHandler for DeInitableHandler { fn init(&mut self, ports: &[u8]) { self.0 = Some(ports[0]); } fn uninit(&mut self) { self.1 = true; } } let mut ports = Ports::new(); let handler_id = ports.install_handler(DeInitableHandler(None, false), &[0xA1]) .map_err(|(_, e)| e).unwrap(); assert_eq!(ports.uninstall_handler(handler_id).and_then(|h| h.downcast().ok()), Some(Box::new(DeInitableHandler(Some(0xA1), true)))); assert!(ports.get_handler(handler_id).is_none());
pub fn read(&mut self, port: u8) -> u8
[src]
Read from the specified port
If a handler is installed there, delegate thereto and cache the result
Marks the port read
Examples
struct PassthroughHandler; impl PortHandler for PassthroughHandler { fn handle_read(&mut self, port: u8) -> u8 { port } } let mut ports = Ports::new(); ports.install_handler(PassthroughHandler, &[0xA1]).map_err(|(_, e)| e).unwrap(); assert_eq!(ports.read(0xBE), 0); assert_eq!(ports.read(0xA1), 0xA1);
pub fn write(&mut self, port: u8, byte: u8)
[src]
Write to the specified port
If a handler is installed there, delegate thereto
Caches the specified byte
Marks the port written
Examples
struct StorageHandler(u8); impl PortHandler for StorageHandler { fn handle_read(&mut self, _: u8) -> u8 { self.0 * 2 } fn handle_write(&mut self, _: u8, data: u8) { self.0 = data; } } let mut ports = Ports::new(); let handler_id = ports.install_handler(StorageHandler(3), &[0xA1]) .map_err(|(_, e)| e).unwrap(); assert_eq!(ports.read(0xA1), 6); ports.write(0xA1, 12); assert_eq!(ports.read(0xA1), 24); assert_eq!(ports.get_handler(handler_id).and_then(|h| h.downcast_ref()), Some(&StorageHandler(12)));
pub fn iter_rw(&self) -> PortsReadWrittenIterator
[src]
Get an iterator over the read and written port cells
Examples
let mut ports = Ports::new(); let val = ports.read(0xA1); ports.write(0x4B, val); println!("{}", ports.read(0x4B)); ports.write(0xEB, 0x12); // (address, value, was_read, was_written) assert_eq!(ports.iter_rw().collect::<Vec<_>>(), &[(0x4B, 0x00, true, true), (0xA1, 0x00, true, false), (0xEB, 0x12, false, true)]);
pub fn reset_rw(&mut self)
[src]
Mark all ports as unread and unwritten
Examples
let mut ports = Ports::new(); let val = ports.read(0xA1); ports.write(0x4B, val); println!("{}", ports.read(0x4B)); ports.write(0xEB, 0x12); ports.reset_rw(); assert_eq!(ports.iter_rw().collect::<Vec<_>>(), &[]);
Trait Implementations
impl Debug for Ports
[src]
impl Default for Ports
[src]
impl Drop for Ports
[src]
impl Eq for Ports
[src]
impl Hash for Ports
[src]
fn hash<H: Hasher>(&self, state: &mut H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Index<Range<u8>> for Ports
[src]
type Output = [u8]
The returned type after indexing.
fn index(&self, index: Range<u8>) -> &Self::Output
[src]
impl Index<RangeFrom<u8>> for Ports
[src]
type Output = [u8]
The returned type after indexing.
fn index(&self, index: RangeFrom<u8>) -> &Self::Output
[src]
impl Index<RangeFull> for Ports
[src]
type Output = [u8]
The returned type after indexing.
fn index(&self, index: RangeFull) -> &Self::Output
[src]
impl Index<RangeInclusive<u8>> for Ports
[src]
type Output = [u8]
The returned type after indexing.
fn index(&self, index: RangeInclusive<u8>) -> &Self::Output
[src]
impl Index<RangeTo<u8>> for Ports
[src]
type Output = [u8]
The returned type after indexing.
fn index(&self, index: RangeTo<u8>) -> &Self::Output
[src]
impl Index<RangeToInclusive<u8>> for Ports
[src]
type Output = [u8]
The returned type after indexing.
fn index(&self, index: RangeToInclusive<u8>) -> &Self::Output
[src]
impl IndexMut<Range<u8>> for Ports
[src]
impl IndexMut<RangeFrom<u8>> for Ports
[src]
impl IndexMut<RangeFull> for Ports
[src]
impl IndexMut<RangeInclusive<u8>> for Ports
[src]
fn index_mut(&mut self, index: RangeInclusive<u8>) -> &mut Self::Output
[src]
impl IndexMut<RangeTo<u8>> for Ports
[src]
impl IndexMut<RangeToInclusive<u8>> for Ports
[src]
fn index_mut(&mut self, index: RangeToInclusive<u8>) -> &mut Self::Output
[src]
impl Ord for Ports
[src]
fn cmp(&self, other: &Ports) -> Ordering
[src]
fn max(self, other: Self) -> Self
1.21.0[src]
fn min(self, other: Self) -> Self
1.21.0[src]
fn clamp(self, min: Self, max: Self) -> Self
[src]
impl PartialEq<[u8]> for Ports
[src]
impl PartialEq<Ports> for Ports
[src]
impl PartialOrd<Ports> for Ports
[src]
Auto Trait Implementations
impl !RefUnwindSafe for Ports
impl !Send for Ports
impl !Sync for Ports
impl Unpin for Ports
impl !UnwindSafe for Ports
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Downcast for T where
T: Any,
[src]
T: Any,
fn into_any(self: Box<T>) -> Box<dyn Any + 'static>
[src]
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
[src]
fn as_any(&self) -> &(dyn Any + 'static)
[src]
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,