Skip to content

Commit

Permalink
Use read_byte in mos6502::reset()
Browse files Browse the repository at this point in the history
* read_word will be removed in the future once all addressing modes are
  using the correct timings.
  • Loading branch information
johnor committed Jan 26, 2020
1 parent 76fc697 commit f88ccb6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion core/src/mos6502.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,9 @@ void Mos6502::reset() {
pipeline_.clear();
nmi_ = false;

registers_->pc = mmu_->read_word(kResetAddress);
const uint16_t lower = mmu_->read_byte(kResetAddress);
const uint16_t upper = mmu_->read_byte(kResetAddress + 1u) << 8u;
registers_->pc = upper | lower;
}

CpuState Mos6502::state() const {
Expand Down
6 changes: 4 additions & 2 deletions core/test/src/test_cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,8 @@ class CpuAbsoluteTest : public CpuTest {

TEST_F(CpuTest, reset) {
expected.pc = 0xDEAD;
EXPECT_CALL(mmu, read_word(kResetAddress)).WillOnce(Return(0xDEAD));
EXPECT_CALL(mmu, read_byte(kResetAddress)).WillOnce(Return(0xAD));
EXPECT_CALL(mmu, read_byte(kResetAddress + 1u)).WillOnce(Return(0xDE));

cpu->reset();

Expand All @@ -713,7 +714,8 @@ TEST_F(CpuTest, reset) {

TEST_F(CpuTest, reset_clears_pipeline) {
stage_instruction(SEC);
EXPECT_CALL(mmu, read_word(kResetAddress)).WillOnce(Return(0xDEAD));
EXPECT_CALL(mmu, read_byte(kResetAddress)).WillOnce(Return(0xAD));
EXPECT_CALL(mmu, read_byte(kResetAddress + 1u)).WillOnce(Return(0xDE));
EXPECT_CALL(mmu, read_byte(0xDEAD)).WillOnce(Return(0x00));
expected.pc = 0xDEAD + 1;

Expand Down

0 comments on commit f88ccb6

Please sign in to comment.