Compare commits

...

3 Commits

Author SHA1 Message Date
Adrian Conlon
93088b355c M6502: Unify accumulator write page boundary fixup code 2023-12-31 14:58:15 +00:00
Adrian Conlon
e4fbeebfa7 Correct problem in page boundary condition for M6502. 2023-12-31 14:32:16 +00:00
Adrian Conlon
84a2d0f952 Whoops: failed to check cycle problems in M6502 tests 2023-12-31 14:21:17 +00:00
3 changed files with 19 additions and 8 deletions

View File

@ -159,6 +159,8 @@ bool checker_t::checkState(test_t test) {
const auto& actual_action = std::get<2>(actual); const auto& actual_action = std::get<2>(actual);
check("Cycle action", expected_action, std::string_view(actual_action)); check("Cycle action", expected_action, std::string_view(actual_action));
} }
if (!m_messages.empty())
return false;
const auto final = test.final(); const auto final = test.final();
const auto pc_good = check("PC", final.pc(), cpu.PC().word); const auto pc_good = check("PC", final.pc(), cpu.PC().word);

View File

@ -188,6 +188,12 @@ namespace EightBit {
void sta_AbsoluteX() noexcept; void sta_AbsoluteX() noexcept;
void sta_AbsoluteY() noexcept; void sta_AbsoluteY() noexcept;
void sta_IndirectIndexedY() noexcept;
void write_A_with_fixup(const register16_t& address, uint8_t unfixed_page) noexcept {
getBytePaged(unfixed_page, address.low); // Possible fixup for page boundary crossing
memoryWrite(address, A());
}
uint8_t x = 0; // index register X uint8_t x = 0; // index register X
uint8_t y = 0; // index register Y uint8_t y = 0; // index register Y

View File

@ -73,14 +73,14 @@ void EightBit::MOS6502::handleINT() noexcept {
void EightBit::MOS6502::interrupt() noexcept { void EightBit::MOS6502::interrupt() noexcept {
const bool reset = m_handlingRESET; const bool reset = m_handlingRESET;
const bool nmi = m_handlingNMI; const bool nmi = m_handlingNMI;
const bool irq = m_handlingINT;
const bool hardware = nmi || irq || reset;
const bool software = !hardware;
if (reset) { if (reset) {
dummyPush(PC().high); dummyPush(PC().high);
dummyPush(PC().low); dummyPush(PC().low);
dummyPush(P()); dummyPush(P());
} else { } else {
const bool irq = m_handlingINT;
const bool hardware = nmi || irq || reset;
const bool software = !hardware;
pushWord(PC()); pushWord(PC());
push(P() | (software ? BF : 0)); push(P() | (software ? BF : 0));
} }
@ -266,7 +266,7 @@ int EightBit::MOS6502::execute() noexcept {
case 0x8f: memoryWrite(Address_Absolute(), A() & X()); break; // *SAX (absolute) case 0x8f: memoryWrite(Address_Absolute(), A() & X()); break; // *SAX (absolute)
case 0x90: branch(!carry()); break; // BCC (relative) case 0x90: branch(!carry()); break; // BCC (relative)
case 0x91: memoryRead(Address_IndirectIndexedY().first); memoryWrite(A()); break; // STA (indirect indexed Y) case 0x91: sta_IndirectIndexedY(); break; // STA (indirect indexed Y)
case 0x92: break; case 0x92: break;
case 0x93: break; case 0x93: break;
case 0x94: memoryWrite(Address_ZeroPageX(), Y()); break; // STY (zero page, X) case 0x94: memoryWrite(Address_ZeroPageX(), Y()); break; // STY (zero page, X)
@ -748,12 +748,15 @@ void EightBit::MOS6502::sre(const uint8_t value) noexcept {
void EightBit::MOS6502::sta_AbsoluteX() noexcept { void EightBit::MOS6502::sta_AbsoluteX() noexcept {
const auto [address, page] = Address_AbsoluteX(); const auto [address, page] = Address_AbsoluteX();
getBytePaged(page, address.low); write_A_with_fixup(address, page);
memoryWrite(address, A());
} }
void EightBit::MOS6502::sta_AbsoluteY() noexcept { void EightBit::MOS6502::sta_AbsoluteY() noexcept {
const auto [address, page] = Address_AbsoluteY(); const auto [address, page] = Address_AbsoluteY();
getBytePaged(page, address.low); write_A_with_fixup(address, page);
memoryWrite(address, A()); }
void EightBit::MOS6502::sta_IndirectIndexedY() noexcept {
const auto [address, page] = Address_IndirectIndexedY();
write_A_with_fixup(address, page);
} }