diff options
Diffstat (limited to 'src/core.rs')
-rw-r--r-- | src/core.rs | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/core.rs b/src/core.rs index b51cf80..6d9a5e1 100644 --- a/src/core.rs +++ b/src/core.rs @@ -1,3 +1,4 @@ +use crate::ram::Ram; use std::fmt; #[derive(Debug, Clone)] @@ -37,12 +38,12 @@ impl fmt::Display for Op { pub struct Core { pc: u16, - ram: [u8; u16::max_value() as usize + 1], + ram: Ram, } impl Core { - pub fn new() -> Self { - Self { pc: 0, ram: [0; u16::max_value() as usize + 1] } + pub fn with_ram_from_hex(hex: String) -> Self { + Self { pc: 0, ram: Ram::from_hex(hex) } } pub fn step(&mut self) -> u16 { @@ -52,7 +53,7 @@ impl Core { } pub fn op(&self) -> Opcode { - self.ram[self.pc as usize].op().0 + self.ram.array[self.pc as usize].op().0 } /// @@ -61,10 +62,10 @@ impl Core { /// fn fetch(&mut self) -> Op { let mut operand1 = None; - let opcode = self.ram[self.pc as usize].opcode(); - let size = self.ram[self.pc as usize].opsize(); + let opcode = self.ram.array[self.pc as usize].opcode(); + let size = self.ram.array[self.pc as usize].opsize(); if size == 2 { - operand1 = Some(self.ram[self.pc as usize]); + operand1 = Some(self.ram.array[self.pc as usize]); } self.pc += size as u16; Op { |