From b5fee5b5d915c98252b9c452c78cf7827eb5e30d Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Thu, 18 Jan 2018 21:17:45 +0000 Subject: [PATCH] Make explicit the notion of page based loads in M6502. Signed-off-by: Adrian Conlon --- M6502/inc/mos6502.h | 12 ++++++------ M6502/src/mos6502.cpp | 28 +++++++++++++++++++--------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/M6502/inc/mos6502.h b/M6502/inc/mos6502.h index 21f9a5a..937ee81 100644 --- a/M6502/inc/mos6502.h +++ b/M6502/inc/mos6502.h @@ -65,7 +65,9 @@ namespace EightBit { adjustNegative(datum); } - void getWord(uint8_t page, uint8_t offset, register16_t& output); + void getWordPaged(uint8_t page, uint8_t offset, register16_t& output); + uint8_t getBytePaged(uint8_t page, uint8_t offset); + void setBytePaged(uint8_t page, uint8_t offset, uint8_t value); virtual void push(uint8_t value) final; virtual uint8_t pop() final; @@ -83,12 +85,12 @@ namespace EightBit { void Address_ZeroPageIndirect() { Address_ZeroPage(); - getWord(0, MEMPTR().low, MEMPTR()); + getWordPaged(0, MEMPTR().low, MEMPTR()); } void Address_Indirect() { Address_Absolute(); - getWord(MEMPTR().high, MEMPTR().low, MEMPTR()); + getWordPaged(MEMPTR().high, MEMPTR().low, MEMPTR()); } void Address_ZeroPageX() { @@ -117,7 +119,7 @@ namespace EightBit { void Address_IndexedIndirectX() { Address_ZeroPageX(); - getWord(0, MEMPTR().low, MEMPTR()); + getWordPaged(0, MEMPTR().low, MEMPTR()); } bool Address_IndirectIndexedY() { @@ -310,8 +312,6 @@ namespace EightBit { void JMP_ind(); void BRK(); - const uint16_t PageOne = 0x100; - // All interrupt vectors are on the 0xFF page const uint8_t IRQvector = 0xfe; const uint8_t RSTvector = 0xfc; diff --git a/M6502/src/mos6502.cpp b/M6502/src/mos6502.cpp index 57984e2..f412089 100644 --- a/M6502/src/mos6502.cpp +++ b/M6502/src/mos6502.cpp @@ -47,23 +47,33 @@ int EightBit::MOS6502::step() { void EightBit::MOS6502::reset() { Processor::reset(); - getWord(0xff, RSTvector, PC()); + getWordPaged(0xff, RSTvector, PC()); } -void EightBit::MOS6502::getWord(uint8_t page, uint8_t offset, register16_t& output) { - BUS().ADDRESS().low = offset; - BUS().ADDRESS().high = page; - output.low = getByte(); +void EightBit::MOS6502::getWordPaged(uint8_t page, uint8_t offset, register16_t& output) { + output.low = getBytePaged(page, offset); BUS().ADDRESS().low++; output.high = getByte(); } +uint8_t EightBit::MOS6502::getBytePaged(uint8_t page, uint8_t offset) { + BUS().ADDRESS().low = offset; + BUS().ADDRESS().high = page; + return getByte(); +} + +void EightBit::MOS6502::setBytePaged(uint8_t page, uint8_t offset, uint8_t value) { + BUS().ADDRESS().low = offset; + BUS().ADDRESS().high = page; + setByte(value); +} + void EightBit::MOS6502::interrupt(uint8_t vector) { raise(HALT()); pushWord(PC()); push(P()); setFlag(P(), IF); - getWord(0xff, vector, PC()); + getWordPaged(0xff, vector, PC()); } int EightBit::MOS6502::execute(uint8_t cell) { @@ -352,11 +362,11 @@ int EightBit::MOS6502::execute(uint8_t cell) { //// void EightBit::MOS6502::push(uint8_t value) { - setByte(PageOne + S()--, value); + setBytePaged(1, S()--, value); } uint8_t EightBit::MOS6502::pop() { - return getByte(PageOne + ++S()); + return getBytePaged(1, ++S()); } //// @@ -535,5 +545,5 @@ void EightBit::MOS6502::BRK() { pushWord(PC()); PHP(); setFlag(P(), IF); - getWord(0xff, IRQvector, PC()); + getWordPaged(0xff, IRQvector, PC()); }