From f88ccb63202e956846ed944a449a5fed1c9dd690 Mon Sep 17 00:00:00 2001 From: Johan Norberg Date: Sun, 26 Jan 2020 14:46:43 -0600 Subject: [PATCH] Use read_byte in mos6502::reset() * read_word will be removed in the future once all addressing modes are using the correct timings. --- core/src/mos6502.cpp | 4 +++- core/test/src/test_cpu.cpp | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/core/src/mos6502.cpp b/core/src/mos6502.cpp index 5f9bed88..432b5f8c 100644 --- a/core/src/mos6502.cpp +++ b/core/src/mos6502.cpp @@ -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 { diff --git a/core/test/src/test_cpu.cpp b/core/test/src/test_cpu.cpp index e74ca9c7..9da55177 100644 --- a/core/test/src/test_cpu.cpp +++ b/core/test/src/test_cpu.cpp @@ -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(); @@ -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;