diff --git a/src/main.rs b/src/main.rs index 70c7b14..a8134c6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -40,7 +40,7 @@ enum OpCodes { // registers //////////////// -// +// // condition flags // @@ -130,16 +130,49 @@ impl Registers { } //////////////// -// VM interface +// memory //////////////// - const MEM_SIZE: usize = 1 << 16; -struct VM { - mem: [u16; MEM_SIZE] +struct Memory { + data: [u16; MEM_SIZE], } +impl Memory { + fn new() -> Memory { + Memory { + data: [0; MEM_SIZE], + } + } + + fn set_mem(&mut self, addr: u16, val: u16) { + self.data[addr as usize] = val; + } + + fn get_mem(&self, addr: u16) -> u16 { + return self.data[addr as usize]; + } +} + +//////////////// +// VM interface +//////////////// + +struct VM { + mem: Memory, +} + +impl VM { + fn new() -> VM { + VM { mem: Memory::new() } + } +} + +//////////////// +// driver code +//////////////// + fn main() { println!("Hello, world!");