diff --git a/snes-core/src/cpu/instructionstemp/mod.rs b/snes-core/src/cpu/instructionstemp/mod.rs index c8936ac..fbcc704 100644 --- a/snes-core/src/cpu/instructionstemp/mod.rs +++ b/snes-core/src/cpu/instructionstemp/mod.rs @@ -58,6 +58,7 @@ pub mod pld; pub mod plp; pub mod plx; pub mod ply; +pub mod rep; pub mod bit_common; pub mod dec_common; pub mod decoder_common; diff --git a/snes-core/src/cpu/instructionstemp/rep.rs b/snes-core/src/cpu/instructionstemp/rep.rs new file mode 100644 index 0000000..12b47d6 --- /dev/null +++ b/snes-core/src/cpu/instructionstemp/rep.rs @@ -0,0 +1,46 @@ +use crate::cpu::{bus::Bus, registers::Registers}; + +use crate::cpu::cycles; +use crate::utils::addressing::AddressingMode; +use super::{CPUInstruction, Decode, read_8bit_from_address}; +use super::decoder_common; + +static INSTR_NAME: &'static str = "REP"; + +pub struct REP {} + +impl CPUInstruction for REP { + fn execute(&self, registers: &mut Registers, bus: &mut Bus) { + let byte = read_8bit_from_address(registers, bus, AddressingMode::Immediate); + registers.reset_rep_byte(byte); + let (bytes, cycles) = cycles::increment_cycles_rep(); + registers.increment_pc(bytes); registers.cycles += cycles; + } +} + +impl Decode for REP { + fn mnemonic(&self, registers: &Registers, bus: &Bus, opcode: u8) -> String { + decoder_common::mnemonic_8bit_immediate(opcode, INSTR_NAME, registers, bus) + } +} + + +#[cfg(test)] +mod cpu_instructions_tests { + use super::*; + + #[test] + fn test() { + let mut registers = Registers::new(); + let mut bus = Bus::new(); + registers.emulation_mode = false; + registers.pc = 0x0000; + registers.p = 0xFF; + bus.write(0x0001, 0xFF); + let instruction = REP{}; + instruction.execute(&mut registers, &mut bus); + assert_eq!(registers.p, 0x00); + assert_eq!(registers.pc, 0x0002); + assert_eq!(registers.cycles, 3); + } +}