aboutsummaryrefslogtreecommitdiff
path: root/src/memory.rs
blob: 854b0ea3dec8aff9f11788b0f10cf1645bfe1950 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use isa::{Instruction};

pub struct Memory {
    memory: Vec<u32>,
}

impl Memory {
    pub fn new(size: usize) -> Memory {
        Memory {
            memory: Vec::with_capacity(size),
        }
    }

    pub fn read_word(&self, address: usize) -> Option<u32> {
        self.memory.get(address).map(Clone::clone)
    }

    pub fn read_instruction(&self, pc: usize) -> Option<Instruction> {
        self.memory.get(pc).map(Clone::clone).map(Instruction::new)
    }
}