Make explicit the notion of page based loads in M6502.

Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
Adrian Conlon 2018-01-18 21:17:45 +00:00
parent 21bd8a06e6
commit b5fee5b5d9
2 changed files with 25 additions and 15 deletions

View File

@ -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;

View File

@ -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());
}