diff --git a/src/bin/main.rs b/src/bin/main.rs index a26caeb..b4c9d88 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -34,7 +34,8 @@ fn main() { let mut machine = machine::Machine::new(); // "Load" a program - machine.memory.set_byte(&Address(0), 5); + machine.memory.set_byte(&Address(0), 0x69); // ADC immediate opcode + machine.memory.set_byte(&Address(1), 0x07); // Immediate operand // Obviously this will run the full program, just diff --git a/src/machine.rs b/src/machine.rs index cab4f3d..775162b 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -28,7 +28,7 @@ use address::AddressDiff; use std::fmt; use instruction::Instruction; -use instruction::ADC; +use instruction::{ADC, NOP}; use memory::Memory; use registers::{ Registers, Status, StatusArgs }; use registers::{ ps_negative, ps_overflow, ps_zero, ps_carry }; @@ -55,12 +55,15 @@ impl Machine { // Will need smarter logic to fetch the correct number of bytes // for instruction - self.registers.program_counter.add(&AddressDiff(1)); + self.registers.program_counter = self.registers.program_counter + AddressDiff(1); instr } pub fn decode_instruction(&mut self, raw_instruction: u8) -> Instruction { - ADC + match raw_instruction { + 0x69 => ADC, + _ => NOP + } } pub fn execute_instruction(&mut self, instruction: Instruction) { @@ -68,6 +71,9 @@ impl Machine { ADC => { println!("executing add with carry"); self.add_with_carry(1); + }, + NOP => { + println!("nop instr"); } _ => println!("attempting to execute unimplemented instruction") };