From 8369e0d9767c00eb28b17a1a8f3e9212b617a1a7 Mon Sep 17 00:00:00 2001 From: Adrian Conlon <98398945+AdrianConlon@users.noreply.github.com> Date: Mon, 4 Mar 2024 17:07:22 +0000 Subject: [PATCH] Address calculations are a little easier, if they're always 16-bit --- M6502/inc/mos6502.h | 6 +++--- M6502/src/mos6502.cpp | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/M6502/inc/mos6502.h b/M6502/inc/mos6502.h index 278b8e8..1a02a6d 100644 --- a/M6502/inc/mos6502.h +++ b/M6502/inc/mos6502.h @@ -94,11 +94,11 @@ namespace EightBit { [[nodiscard]] auto Address_Immediate() noexcept { return PC()++; } [[nodiscard]] auto Address_Absolute() noexcept { return fetchWord(); } - [[nodiscard]] auto Address_ZeroPage() noexcept { return fetchByte(); } + [[nodiscard]] auto Address_ZeroPage() noexcept { return register16_t(fetchByte(), 0); } [[nodiscard]] register16_t Address_ZeroPageIndirect() noexcept; [[nodiscard]] register16_t Address_Indirect() noexcept; - [[nodiscard]] uint8_t Address_ZeroPageX() noexcept; - [[nodiscard]] uint8_t Address_ZeroPageY() noexcept; + [[nodiscard]] register16_t Address_ZeroPageX() noexcept; + [[nodiscard]] register16_t Address_ZeroPageY() noexcept; [[nodiscard]] std::pair Address_AbsoluteX() noexcept; [[nodiscard]] std::pair Address_AbsoluteY() noexcept; [[nodiscard]] register16_t Address_IndexedIndirectX() noexcept; diff --git a/M6502/src/mos6502.cpp b/M6502/src/mos6502.cpp index 7d31af6..5b87bc3 100644 --- a/M6502/src/mos6502.cpp +++ b/M6502/src/mos6502.cpp @@ -425,7 +425,7 @@ void EightBit::MOS6502::dummyPush(const uint8_t value) noexcept { //// EightBit::register16_t EightBit::MOS6502::Address_ZeroPageIndirect() noexcept { - BUS().ADDRESS() = { Address_ZeroPage(), 0 }; + BUS().ADDRESS() = Address_ZeroPage(); return getWordPaged(); } @@ -434,16 +434,16 @@ EightBit::register16_t EightBit::MOS6502::Address_Indirect() noexcept { return getWordPaged(); } -uint8_t EightBit::MOS6502::Address_ZeroPageX() noexcept { +EightBit::register16_t EightBit::MOS6502::Address_ZeroPageX() noexcept { const auto address = Address_ZeroPage(); memoryRead(address); - return address + X(); + return register16_t(address.low + X(), 0); } -uint8_t EightBit::MOS6502::Address_ZeroPageY() noexcept { +EightBit::register16_t EightBit::MOS6502::Address_ZeroPageY() noexcept { const auto address = Address_ZeroPage(); memoryRead(address); - return address + Y(); + return register16_t(address.low + Y(), 0); } std::pair EightBit::MOS6502::Address_AbsoluteX() noexcept { @@ -459,7 +459,7 @@ std::pair EightBit::MOS6502::Address_AbsoluteY( } EightBit::register16_t EightBit::MOS6502::Address_IndexedIndirectX() noexcept { - BUS().ADDRESS() = { Address_ZeroPageX(), 0 }; + BUS().ADDRESS() = Address_ZeroPageX(); return getWordPaged(); }