mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2024-09-02 07:28:56 +00:00
Share more of push/pop implementation across processors.
Signed-off-by: Adrian.Conlon <adrian.conlon@gmail.com>
This commit is contained in:
parent
73a34f4fae
commit
59e9adf57c
@ -87,10 +87,8 @@ namespace EightBit {
|
||||
adjustNegative(datum);
|
||||
}
|
||||
|
||||
void pushByte(uint8_t value);
|
||||
uint8_t popByte();
|
||||
void pushWord(register16_t value);
|
||||
void popWord(register16_t& output);
|
||||
virtual void push(uint8_t value) override;
|
||||
virtual uint8_t pop() override;
|
||||
|
||||
#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) {
|
||||
pushWord(PC());
|
||||
pushByte(P());
|
||||
push(P());
|
||||
setFlag(P(), IF);
|
||||
getWord(vector, PC());
|
||||
}
|
||||
@ -144,7 +144,7 @@ int EightBit::MOS6502::execute(uint8_t cell) {
|
||||
RTI();
|
||||
break;
|
||||
case 0b010: // PHA
|
||||
pushByte(A());
|
||||
push(A());
|
||||
break;
|
||||
case 0b011: // JMP
|
||||
JMP_abs();
|
||||
@ -165,7 +165,7 @@ int EightBit::MOS6502::execute(uint8_t cell) {
|
||||
RTS();
|
||||
break;
|
||||
case 0b010: // PLA
|
||||
adjustNZ(A() = popByte());
|
||||
adjustNZ(A() = pop());
|
||||
break;
|
||||
case 0b011: // JMP (abs)
|
||||
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);
|
||||
}
|
||||
|
||||
uint8_t EightBit::MOS6502::popByte() {
|
||||
uint8_t EightBit::MOS6502::pop() {
|
||||
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) {
|
||||
@ -508,12 +498,11 @@ void EightBit::MOS6502::Branch(bool flag) {
|
||||
|
||||
void EightBit::MOS6502::PHP() {
|
||||
setFlag(P(), BF);
|
||||
pushByte(P());
|
||||
push(P());
|
||||
}
|
||||
|
||||
void EightBit::MOS6502::PLP() {
|
||||
P() = popByte();
|
||||
setFlag(P(), RF);
|
||||
P() = pop() | RF;
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -123,20 +123,10 @@ namespace EightBit {
|
||||
m_memory.write(--SP().word, value);
|
||||
}
|
||||
|
||||
void pushWord(const register16_t& value) {
|
||||
push(value.high);
|
||||
push(value.low);
|
||||
}
|
||||
|
||||
virtual uint8_t pop() {
|
||||
return m_memory.read(SP().word++);
|
||||
}
|
||||
|
||||
void popWord(register16_t& output) {
|
||||
output.low = pop();
|
||||
output.high = pop();
|
||||
}
|
||||
|
||||
void fetchWord() {
|
||||
Processor::fetchWord(MEMPTR());
|
||||
}
|
||||
|
@ -88,6 +88,19 @@ namespace EightBit {
|
||||
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:
|
||||
register16_t pc;
|
||||
bool m_halted;
|
||||
|
Loading…
Reference in New Issue
Block a user