diff options
author | Oxore <oxore@protonmail.com> | 2020-03-05 00:33:55 +0300 |
---|---|---|
committer | Oxore <oxore@protonmail.com> | 2020-03-05 00:36:29 +0300 |
commit | 19e0e4cb5f26df537bf07b428700bea30460fd5b (patch) | |
tree | 8f55e2525d107d28899aa3b486c3c8485965aa04 /src/bus.rs | |
parent | 7d4dfd8af842796c4eb8a88df0cc5ab30f99232d (diff) |
Use bus for all memory types, etc.
Rename Memory to Bus
Diffstat (limited to 'src/bus.rs')
-rw-r--r-- | src/bus.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/bus.rs b/src/bus.rs new file mode 100644 index 0000000..e3b6579 --- /dev/null +++ b/src/bus.rs @@ -0,0 +1,19 @@ +extern crate num_traits; + +pub trait Bus<Addr> +where + Addr: Copy + core::ops::Add<Output = Addr> + num_traits::identities::One, +{ + fn get(&self, a: Addr) -> u8; + + fn set(&mut self, a: Addr, v: u8); + + fn get_word(&self, a: Addr) -> u16 { + u16::from(self.get(a)) | (u16::from(self.get(a + Addr::one())) << 8) + } + + fn set_word(&mut self, a: Addr, v: u16) { + self.set(a, (v & 0xFF) as u8); + self.set(a + Addr::one(), (v >> 8) as u8) + } +} |