diff options
author | Ben Bridle <bridle.benjamin@gmail.com> | 2023-12-24 19:54:50 +1300 |
---|---|---|
committer | Ben Bridle <bridle.benjamin@gmail.com> | 2023-12-24 19:54:50 +1300 |
commit | 2b16a99ba3d1ba6536a1db28471288a0c2274a71 (patch) | |
tree | 7df2fc16f6cf81a4d7c313a6c65e53183c721d9d /src/device_bus.rs | |
download | bedrock-core-1.0.0.zip |
First commitv1.0.0
Diffstat (limited to 'src/device_bus.rs')
-rw-r--r-- | src/device_bus.rs | 19 |
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)) + } +} |