summaryrefslogtreecommitdiff
path: root/src/device_bus.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/device_bus.rs')
-rw-r--r--src/device_bus.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/device_bus.rs b/src/device_bus.rs
new file mode 100644
index 0000000..38a1a24
--- /dev/null
+++ b/src/device_bus.rs
@@ -0,0 +1,19 @@
+use crate::*;
+
+pub trait DeviceBus {
+ fn read_u8(&mut self, port: u8) -> u8;
+
+ fn write_u8(&mut self, value: u8, port: u8) -> Option<Signal>;
+
+ fn read_u16(&mut self, port: u8) -> u16 {
+ let high = self.read_u8(port);
+ let low = self.read_u8(port.wrapping_add(1));
+ u16::from_be_bytes([high, low])
+ }
+
+ fn write_u16(&mut self, value: u16, port: u8) -> Option<Signal> {
+ let [h, l] = value.to_be_bytes();
+ self.write_u8(h, port);
+ self.write_u8(l, port.wrapping_add(1))
+ }
+}