summaryrefslogtreecommitdiff
path: root/src/memory.rs
blob: 372a029702a1ce42a46468cf1ff11acc8580f056 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
extern crate num_traits;

pub trait Memory<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)
    }
}