Skip to content

Commit

Permalink
Use correct timing in absolute addressing pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
johnor committed Sep 15, 2019
1 parent d1e4b0a commit 924fc7f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
8 changes: 6 additions & 2 deletions core/src/mos6502.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -629,10 +629,14 @@ Pipeline Mos6502::create_zeropage_indexed_addressing_steps(

Pipeline Mos6502::create_absolute_addressing_steps() {
Pipeline result;
result.push([=]() { ++registers_->pc; });
result.push([=]() {
tmp_ = mmu_->read_byte(registers_->pc);
++registers_->pc;
});
result.push([=]() {
const uint16_t upper = mmu_->read_byte(registers_->pc) << 8;
++registers_->pc;
effective_address_ = mmu_->read_word(registers_->pc - 2);
effective_address_ = tmp_ | upper;
});
return result;
}
Expand Down
18 changes: 14 additions & 4 deletions core/test/src/test_cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,8 +510,13 @@ class CpuAbsoluteTest : public CpuTest {
stage_instruction(instruction);
expected.pc += 2;

EXPECT_CALL(mmu, read_word(start_pc + 1))
.WillOnce(Return(effective_address));
const uint8_t lower_address = effective_address & 0x00FF;
const uint8_t upper_address = (effective_address & 0xFF00) >> 8;

EXPECT_CALL(mmu, read_byte(start_pc + 1))
.WillOnce(Return(lower_address));
EXPECT_CALL(mmu, read_byte(start_pc + 2))
.WillOnce(Return(upper_address));
EXPECT_CALL(mmu, read_byte(effective_address))
.WillOnce(Return(memory_content));

Expand All @@ -524,8 +529,13 @@ class CpuAbsoluteTest : public CpuTest {
stage_instruction(instruction);
expected.pc += 2;

EXPECT_CALL(mmu, read_word(start_pc + 1))
.WillOnce(Return(effective_address));
const uint8_t lower_address = effective_address & 0x00FF;
const uint8_t upper_address = (effective_address & 0xFF00) >> 8;

EXPECT_CALL(mmu, read_byte(start_pc + 1))
.WillOnce(Return(lower_address));
EXPECT_CALL(mmu, read_byte(start_pc + 2))
.WillOnce(Return(upper_address));
EXPECT_CALL(mmu, write_byte(effective_address, memory_content));

step_execution(4);
Expand Down

0 comments on commit 924fc7f

Please sign in to comment.