diff options
Diffstat (limited to 'src/core.rs')
-rw-r--r-- | src/core.rs | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/src/core.rs b/src/core.rs index 0062e1c..6c6eefd 100644 --- a/src/core.rs +++ b/src/core.rs @@ -1,14 +1,51 @@ +use std::fmt; + +#[derive(Debug)] +pub enum Op { + Nop, + Illegal, +} + +impl fmt::Display for Op { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{:?}", self) + } +} + pub struct Core { pc: u16, + ram: [u8; u16::max_value() as usize + 1], } impl Core { pub fn new() -> Self { - Core { pc: 0 } + Core { pc: 0, ram: [0; u16::max_value() as usize + 1] } } pub fn step(&mut self) -> u16 { - self.pc += 1; + self.pc += self.ram[self.pc as usize].instruction_size(); self.pc } + + pub fn op(&self) -> Op { + self.ram[self.pc as usize].op() + } +} + +pub trait Isa { + fn op(&self) -> Op; + fn instruction_size(&self) -> u16; +} + +impl Isa for u8 { + fn op(&self) -> Op { + match *self { + 0 => Op::Nop, + _ => Op::Illegal + } + } + + fn instruction_size(&self) -> u16 { + 1 + } } |