Skip to content

Commit

Permalink
Add dummy read for pha and php
Browse files Browse the repository at this point in the history
  • Loading branch information
johnor committed Oct 1, 2020
1 parent 5ed58ea commit ff31bd9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 6 additions & 2 deletions core/src/mos6502.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ Pipeline Mos6502::parse_next_instruction() {
create_left_shift_instruction(*state_.current_opcode, false));
break;
case Instruction::PhpImplied:
result.push([] { /* Do nothing. */ });
result.push([this] { /* dummy read */
mmu_->read_byte(registers_->pc);
});
result.push([this] { stack_.push_byte(registers_->p | B_FLAG); });
break;
case Instruction::BplRelative:
Expand Down Expand Up @@ -198,7 +200,9 @@ Pipeline Mos6502::parse_next_instruction() {
create_right_shift_instruction(*state_.current_opcode, false));
break;
case Instruction::PhaImplied:
result.push([] { /* Do nothing. */ });
result.push([this] { /* dummy read */
mmu_->read_byte(registers_->pc);
});
result.push([this] { stack_.push_byte(registers_->a); });
break;
case Instruction::JmpAbsolute:
Expand Down
6 changes: 6 additions & 0 deletions core/test/src/test_cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ TEST_F(CpuTest, state_is_initialized) {
TEST_F(CpuTest, state_opcode_returns_instruction) {
registers.pc = 0x1234;
stage_instruction(PHP);
// Dummy read
EXPECT_CALL(mmu, read_byte(0x1235));
step_execution(1);

const CpuState state = cpu->state();
Expand Down Expand Up @@ -159,6 +161,8 @@ TEST_F(CpuTest, php_sets_b_flag) {
expected.sp = 0x09;
expected.p = registers.p;

// Dummy read
EXPECT_CALL(mmu, read_byte(expected.pc));
EXPECT_CALL(
mmu, write_byte(kStackOffset + registers.sp, registers.p | B_FLAG));

Expand Down Expand Up @@ -282,6 +286,8 @@ TEST_F(CpuTest, pha) {
registers.sp = 0x05;
registers.a = 0x84;

// Dummy read
EXPECT_CALL(mmu, read_byte(expected.pc));
EXPECT_CALL(mmu, write_byte(kStackOffset + registers.sp, registers.a));

expected.sp = 0x04;
Expand Down

0 comments on commit ff31bd9

Please sign in to comment.