Skip to content

Commit

Permalink
Implement SEI instruction
Browse files Browse the repository at this point in the history
  • Loading branch information
twvd committed Oct 9, 2023
1 parent f548b41 commit 563537a
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/snes/cpu_65816/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -65,12 +65,15 @@ where
}

/// Executes one CPU step (one instruction).
pub fn step(&mut self) -> Result<Ticks> {
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
Expand All @@ -79,6 +82,7 @@ where
return Ok(());
}

self.cycles += 1;
self.bus.tick(cycles)
}

Expand All @@ -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(())
}
}

0 comments on commit 563537a

Please sign in to comment.