From 412a44fafd7b483c954b97109b953f2ad3715bf3 Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Fri, 29 Dec 2017 14:49:53 +0000 Subject: [PATCH] Correct some page crossing conditions affecting 6502 cycle counts. Signed-off-by: Adrian Conlon --- M6502/inc/mos6502.h | 27 +++++++++++++++------------ M6502/src/mos6502.cpp | 2 +- Ricoh2A03/inc/Ricoh2A03.h | 2 ++ 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/M6502/inc/mos6502.h b/M6502/inc/mos6502.h index 628eb10..170ee35 100644 --- a/M6502/inc/mos6502.h +++ b/M6502/inc/mos6502.h @@ -113,14 +113,18 @@ namespace EightBit { MEMPTR().low += Y(); } - void Address_AbsoluteX() { + bool Address_AbsoluteX() { Address_Absolute(); + const auto page = MEMPTR().high; MEMPTR().word += X(); + return MEMPTR().high != page; } - void Address_AbsoluteY() { + bool Address_AbsoluteY() { Address_Absolute(); + const auto page = MEMPTR().high; MEMPTR().word += Y(); + return MEMPTR().high != page; } void Address_IndexedIndirectX() { @@ -128,9 +132,11 @@ namespace EightBit { getWord(0, MEMPTR().low, MEMPTR()); } - void Address_IndirectIndexedY() { + bool Address_IndirectIndexedY() { Address_ZeroPageIndirect(); + const auto page = MEMPTR().high; MEMPTR().word += Y(); + return MEMPTR().high != page; } #pragma endregion Addresses @@ -156,18 +162,16 @@ namespace EightBit { } uint8_t AM_AbsoluteX() { - Address_AbsoluteX(); - BUS().ADDRESS() = MEMPTR(); - if (BUS().ADDRESS().low == Mask8) + if (Address_AbsoluteX()) addCycle(); + BUS().ADDRESS() = MEMPTR(); return getByte(); } uint8_t AM_AbsoluteY() { - Address_AbsoluteY(); - BUS().ADDRESS() = MEMPTR(); - if (BUS().ADDRESS().low == Mask8) + if (Address_AbsoluteY()) addCycle(); + BUS().ADDRESS() = MEMPTR(); return getByte(); } @@ -187,10 +191,9 @@ namespace EightBit { } uint8_t AM_IndirectIndexedY() { - Address_IndirectIndexedY(); - BUS().ADDRESS() = MEMPTR(); - if (BUS().ADDRESS().low == Mask8) + if (Address_IndirectIndexedY()) addCycle(); + BUS().ADDRESS() = MEMPTR(); return getByte(); } diff --git a/M6502/src/mos6502.cpp b/M6502/src/mos6502.cpp index 51f1220..c85be38 100644 --- a/M6502/src/mos6502.cpp +++ b/M6502/src/mos6502.cpp @@ -5,7 +5,7 @@ EightBit::MOS6502::MOS6502(Bus& bus) : Processor(bus) { m_timings = { //// 0 1 2 3 4 5 6 7 8 9 A B C D E F - /* 0 */ 7, 6, 0, 0, 0, 4, 5, 0, 3, 2, 2, 0, 0, 4, 6, 0, + /* 0 */ 7, 6, 0, 0, 0, 3, 5, 0, 3, 2, 2, 0, 0, 4, 6, 0, /* 1 */ 2, 5, 0, 0, 0, 4, 6, 0, 2, 4, 0, 0, 0, 4, 7, 0, /* 2 */ 6, 6, 0, 0, 3, 3, 5, 0, 4, 2, 2, 0, 4, 4, 6, 0, /* 3 */ 2, 5, 0, 0, 0, 4, 6, 0, 2, 4, 0, 0, 0, 4, 7, 0, diff --git a/Ricoh2A03/inc/Ricoh2A03.h b/Ricoh2A03/inc/Ricoh2A03.h index faddac2..9ad4efc 100644 --- a/Ricoh2A03/inc/Ricoh2A03.h +++ b/Ricoh2A03/inc/Ricoh2A03.h @@ -10,6 +10,8 @@ namespace EightBit { Ricoh2A03(Bus& bus); virtual ~Ricoh2A03() = default; + int clockCycles() const { return cycles(); } + protected: virtual void SBC(uint8_t data) final; virtual void ADC(uint8_t data) final;