From b52e47bbb58fde296cd7d1ff70d27560dfb5b8e5 Mon Sep 17 00:00:00 2001 From: omarandlorraine <64254276+omarandlorraine@users.noreply.github.com> Date: Mon, 30 Oct 2023 01:22:37 +0000 Subject: [PATCH] Fix the PHP opcode (#92) * unit test for php * get test passing --------- Co-authored-by: Sam M W --- src/cpu.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/cpu.rs b/src/cpu.rs index 9cab04d..4514369 100644 --- a/src/cpu.rs +++ b/src/cpu.rs @@ -427,7 +427,7 @@ impl CPU { } (Instruction::PHP, OpInput::UseImplied) => { // Push status - let val = self.registers.status.bits(); + let val = self.registers.status.bits() | 0x30; self.push_on_stack(val); } (Instruction::PLA, OpInput::UseImplied) => { @@ -1153,6 +1153,16 @@ mod tests { assert!(cpu.registers.status.contains(Status::PS_CARRY)); } + #[test] + fn php_sets_bits_4_and_5() { + let mut cpu = CPU::new(Ram::new()); + cpu.execute_instruction((Instruction::PHP, OpInput::UseImplied)); + cpu.execute_instruction((Instruction::PLA, OpInput::UseImplied)); + cpu.execute_instruction((Instruction::AND, OpInput::UseImmediate(0x30))); + + assert_eq!(cpu.registers.accumulator, 0x30); + } + #[test] fn and_test() { let mut cpu = CPU::new(Ram::new());