diff --git a/snes-core/src/cpu/cpu.rs b/snes-core/src/cpu/cpu.rs index 82487b1..bffbbf3 100644 --- a/snes-core/src/cpu/cpu.rs +++ b/snes-core/src/cpu/cpu.rs @@ -3,7 +3,7 @@ use super::registers::Registers; pub struct CPU { pub registers: Registers, pub cycles: usize, // TODO: remove cycles from here - pub is_stopped: bool, + pub is_stopped: bool, // TODO: remove from here pub is_waiting_interrupt: bool, } diff --git a/snes-core/src/cpu/instructionstemp/mod.rs b/snes-core/src/cpu/instructionstemp/mod.rs index 956b160..8743884 100644 --- a/snes-core/src/cpu/instructionstemp/mod.rs +++ b/snes-core/src/cpu/instructionstemp/mod.rs @@ -72,6 +72,7 @@ pub mod sep; pub mod sta; pub mod stx; pub mod sty; +pub mod stp; pub mod bit_common; pub mod dec_common; pub mod decoder_common; diff --git a/snes-core/src/cpu/instructionstemp/stp.rs b/snes-core/src/cpu/instructionstemp/stp.rs new file mode 100644 index 0000000..1ef5d1c --- /dev/null +++ b/snes-core/src/cpu/instructionstemp/stp.rs @@ -0,0 +1,42 @@ +use crate::cpu::{bus::Bus, registers::Registers}; + +use crate::cpu::cycles; +use super::{CPUInstruction, Decode}; +use super::decoder_common; + +static INSTR_NAME: &'static str = "STP"; + +pub struct STP {} + +impl CPUInstruction for STP { + fn execute(&self, registers: &mut Registers, _bus: &mut Bus) { + registers.is_cpu_stopped = true; + let (bytes, cycles) = cycles::increment_cycles_stp(); + registers.increment_pc(bytes); registers.cycles += cycles; + } +} + +impl Decode for STP { + fn mnemonic(&self, _registers: &Registers, _bus: &Bus, opcode: u8) -> String { + decoder_common::mnemonic_single_byte_instr(opcode, INSTR_NAME) + } +} + + +#[cfg(test)] +mod cpu_instructions_tests { + use super::*; + + #[test] + fn test() { + let mut registers = Registers::new(); + let mut bus = Bus::new(); + registers.is_cpu_stopped = false; + registers.pc = 0x0000; + let instruction = STP{}; + instruction.execute(&mut registers, &mut bus); + assert_eq!(registers.pc, 0x0001); + assert_eq!(registers.is_cpu_stopped, true); + assert_eq!(registers.cycles, 3); + } +} diff --git a/snes-core/src/cpu/registers.rs b/snes-core/src/cpu/registers.rs index 484b360..f7d96cd 100644 --- a/snes-core/src/cpu/registers.rs +++ b/snes-core/src/cpu/registers.rs @@ -11,6 +11,7 @@ pub struct Registers { pub dbr: u8, // Data bank register pub pc: u16, // Program counter pub emulation_mode: bool, + pub is_cpu_stopped: bool, pub cycles: usize, } @@ -27,6 +28,7 @@ impl Registers { dbr: 0, pc: 0, emulation_mode: true, + is_cpu_stopped: false, cycles: 0, } }