Fix the PHP opcode (#92)

* unit test for php

* get test passing

---------

Co-authored-by: Sam M W <you@example.com>
This commit is contained in:
omarandlorraine 2023-10-30 01:22:37 +00:00 committed by GitHub
parent 6ce85db45c
commit b52e47bbb5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 1 deletions

View File

@ -427,7 +427,7 @@ impl<M: Bus> CPU<M> {
}
(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());