diff options
author | Oxore <oxore@protonmail.com> | 2019-09-30 03:56:26 +0300 |
---|---|---|
committer | Oxore <oxore@protonmail.com> | 2019-09-30 03:56:26 +0300 |
commit | 615ef873ca3aff557b21658b54a7cb1081404d86 (patch) | |
tree | 434c30a9d3f918a031cca85ddb6e1b1276bca512 /src/core.rs | |
parent | 48030bad83a067388e473cba08f7b48b846c5468 (diff) |
Implement basic ram loader from hex
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 { |