diff --git a/src/snes/cpu_65816/cpu.rs b/src/snes/cpu_65816/cpu.rs index c9587b4..1fb6b63 100644 --- a/src/snes/cpu_65816/cpu.rs +++ b/src/snes/cpu_65816/cpu.rs @@ -3,7 +3,7 @@ use anyhow::Result; use crate::snes::bus::{Address, Bus, BusIterator}; use crate::tickable::Ticks; -use super::instruction::Instruction; +use super::instruction::{Instruction, InstructionType}; use super::regs::{Flag, RegisterFile}; /// Main SNES CPU (65816) @@ -65,12 +65,15 @@ where } /// Executes one CPU step (one instruction). - pub fn step(&mut self) -> Result { + pub fn step(&mut self) -> Result<()> { let instr = self.fetch_next_instr()?; + + let cycles = self.execute_instruction(&instr)?; + // TODO program bank? self.regs.pc = self.regs.pc.wrapping_add(instr.len as u16); - Ok(1) + Ok(()) } /// Tick peripherals @@ -79,6 +82,7 @@ where return Ok(()); } + self.cycles += 1; self.bus.tick(cycles) } @@ -89,4 +93,16 @@ where self.tick_bus(1).unwrap(); v } + + fn execute_instruction(&mut self, instr: &Instruction) -> Result<()> { + match instr.def.instr_type { + InstructionType::SEI => { + self.regs.write_flags(&[(Flag::I, true)]); + self.tick_bus(4)?; + } + _ => todo!(), + } + + Ok(()) + } }