mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2025-08-09 00:25:10 +00:00
Share more of push/pop implementation across processors.
Signed-off-by: Adrian.Conlon <adrian.conlon@gmail.com>
This commit is contained in:
@@ -87,10 +87,8 @@ namespace EightBit {
|
|||||||
adjustNegative(datum);
|
adjustNegative(datum);
|
||||||
}
|
}
|
||||||
|
|
||||||
void pushByte(uint8_t value);
|
virtual void push(uint8_t value) override;
|
||||||
uint8_t popByte();
|
virtual uint8_t pop() override;
|
||||||
void pushWord(register16_t value);
|
|
||||||
void popWord(register16_t& output);
|
|
||||||
|
|
||||||
#pragma region 6502 addressing modes
|
#pragma region 6502 addressing modes
|
||||||
|
|
||||||
|
@@ -80,7 +80,7 @@ void EightBit::MOS6502::getWord(uint16_t offset, register16_t& output) {
|
|||||||
|
|
||||||
void EightBit::MOS6502::interrupt(uint16_t vector) {
|
void EightBit::MOS6502::interrupt(uint16_t vector) {
|
||||||
pushWord(PC());
|
pushWord(PC());
|
||||||
pushByte(P());
|
push(P());
|
||||||
setFlag(P(), IF);
|
setFlag(P(), IF);
|
||||||
getWord(vector, PC());
|
getWord(vector, PC());
|
||||||
}
|
}
|
||||||
@@ -144,7 +144,7 @@ int EightBit::MOS6502::execute(uint8_t cell) {
|
|||||||
RTI();
|
RTI();
|
||||||
break;
|
break;
|
||||||
case 0b010: // PHA
|
case 0b010: // PHA
|
||||||
pushByte(A());
|
push(A());
|
||||||
break;
|
break;
|
||||||
case 0b011: // JMP
|
case 0b011: // JMP
|
||||||
JMP_abs();
|
JMP_abs();
|
||||||
@@ -165,7 +165,7 @@ int EightBit::MOS6502::execute(uint8_t cell) {
|
|||||||
RTS();
|
RTS();
|
||||||
break;
|
break;
|
||||||
case 0b010: // PLA
|
case 0b010: // PLA
|
||||||
adjustNZ(A() = popByte());
|
adjustNZ(A() = pop());
|
||||||
break;
|
break;
|
||||||
case 0b011: // JMP (abs)
|
case 0b011: // JMP (abs)
|
||||||
JMP_ind();
|
JMP_ind();
|
||||||
@@ -347,24 +347,14 @@ int EightBit::MOS6502::execute(uint8_t cell) {
|
|||||||
|
|
||||||
////
|
////
|
||||||
|
|
||||||
void EightBit::MOS6502::pushByte(uint8_t value) {
|
void EightBit::MOS6502::push(uint8_t value) {
|
||||||
setByte(PageOne + S()--, value);
|
setByte(PageOne + S()--, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t EightBit::MOS6502::popByte() {
|
uint8_t EightBit::MOS6502::pop() {
|
||||||
return getByte(PageOne + ++S());
|
return getByte(PageOne + ++S());
|
||||||
}
|
}
|
||||||
|
|
||||||
void EightBit::MOS6502::pushWord(register16_t value) {
|
|
||||||
pushByte(value.high);
|
|
||||||
pushByte(value.low);
|
|
||||||
}
|
|
||||||
|
|
||||||
void EightBit::MOS6502::popWord(register16_t& output) {
|
|
||||||
output.low = popByte();
|
|
||||||
output.high = popByte();
|
|
||||||
}
|
|
||||||
|
|
||||||
////
|
////
|
||||||
|
|
||||||
void EightBit::MOS6502::ROR(uint8_t& output) {
|
void EightBit::MOS6502::ROR(uint8_t& output) {
|
||||||
@@ -508,12 +498,11 @@ void EightBit::MOS6502::Branch(bool flag) {
|
|||||||
|
|
||||||
void EightBit::MOS6502::PHP() {
|
void EightBit::MOS6502::PHP() {
|
||||||
setFlag(P(), BF);
|
setFlag(P(), BF);
|
||||||
pushByte(P());
|
push(P());
|
||||||
}
|
}
|
||||||
|
|
||||||
void EightBit::MOS6502::PLP() {
|
void EightBit::MOS6502::PLP() {
|
||||||
P() = popByte();
|
P() = pop() | RF;
|
||||||
setFlag(P(), RF);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@@ -123,20 +123,10 @@ namespace EightBit {
|
|||||||
m_memory.write(--SP().word, value);
|
m_memory.write(--SP().word, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void pushWord(const register16_t& value) {
|
|
||||||
push(value.high);
|
|
||||||
push(value.low);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual uint8_t pop() {
|
virtual uint8_t pop() {
|
||||||
return m_memory.read(SP().word++);
|
return m_memory.read(SP().word++);
|
||||||
}
|
}
|
||||||
|
|
||||||
void popWord(register16_t& output) {
|
|
||||||
output.low = pop();
|
|
||||||
output.high = pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
void fetchWord() {
|
void fetchWord() {
|
||||||
Processor::fetchWord(MEMPTR());
|
Processor::fetchWord(MEMPTR());
|
||||||
}
|
}
|
||||||
|
@@ -88,6 +88,19 @@ namespace EightBit {
|
|||||||
return execute(fetchByte());
|
return execute(fetchByte());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void push(uint8_t value) = 0;
|
||||||
|
virtual uint8_t pop() = 0;
|
||||||
|
|
||||||
|
void pushWord(const register16_t& value) {
|
||||||
|
push(value.high);
|
||||||
|
push(value.low);
|
||||||
|
}
|
||||||
|
|
||||||
|
void popWord(register16_t& output) {
|
||||||
|
output.low = pop();
|
||||||
|
output.high = pop();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
register16_t pc;
|
register16_t pc;
|
||||||
bool m_halted;
|
bool m_halted;
|
||||||
|
Reference in New Issue
Block a user