Remove another chunk of shared code. This time by ensuring the basic layout of registers is consistent.

Signed-off-by: Adrian.Conlon <adrian.conlon@gmail.com>
This commit is contained in:
Adrian.Conlon 2017-06-16 13:52:10 +01:00
parent c52f0a36aa
commit 327d391ecb
4 changed files with 39 additions and 80 deletions

View File

@ -38,21 +38,10 @@ namespace EightBit {
const std::array<Instruction, 0x100>& getInstructions() const { return instructions; }
register16_t& AF() { return af; }
uint8_t& A() { return AF().high; }
uint8_t& F() { return AF().low; }
register16_t& BC() { return bc; }
uint8_t& B() { return BC().high; }
uint8_t& C() { return BC().low; }
register16_t& DE() { return de; }
uint8_t& D() { return DE().high; }
uint8_t& E() { return DE().low; }
register16_t& HL() { return hl; }
uint8_t& H() { return HL().high; }
uint8_t& L() { return HL().low; }
virtual register16_t& AF() override { return af; }
virtual register16_t& BC() override { return bc; }
virtual register16_t& DE() override { return de; }
virtual register16_t& HL() override { return hl; }
bool isInterruptable() const {
return m_interrupt;
@ -81,17 +70,6 @@ namespace EightBit {
bool m_interrupt;
void clearFlag(int flag) { F() &= ~flag; }
void setFlag(int flag) { F() |= flag; }
void setFlag(int flag, int condition) { setFlag(flag, condition != 0); }
void setFlag(int flag, uint32_t condition) { setFlag(flag, condition != 0); }
void setFlag(int flag, bool condition) { condition ? setFlag(flag) : clearFlag(flag); }
void clearFlag(int flag, int condition) { clearFlag(flag, condition != 0); }
void clearFlag(int flag, uint32_t condition) { clearFlag(flag, condition != 0); }
void clearFlag(int flag, bool condition) { condition ? clearFlag(flag) : setFlag(flag); }
int execute(uint8_t opcode);
int execute(const Instruction& instruction) {

View File

@ -36,35 +36,23 @@ namespace EightBit {
// Mutable access to processor!!
register16_t& AF() {
virtual register16_t& AF() override {
m_accumulatorFlag.low &= 0xf0;
return m_accumulatorFlag;
}
uint8_t& A() { return AF().high; }
uint8_t& F() { return AF().low; }
register16_t& BC() {
virtual register16_t& BC() override {
return m_registers[BC_IDX];
}
uint8_t& B() { return BC().high; }
uint8_t& C() { return BC().low; }
register16_t& DE() {
virtual register16_t& DE() override {
return m_registers[DE_IDX];
}
uint8_t& D() { return DE().high; }
uint8_t& E() { return DE().low; }
register16_t& HL() {
virtual register16_t& HL() override {
return m_registers[HL_IDX];
}
uint8_t& H() { return HL().high; }
uint8_t& L() { return HL().low; }
virtual void reset();
virtual void initialise();
@ -87,17 +75,6 @@ namespace EightBit {
return execute(fetchByte());
}
void clearFlag(int flag) { F() &= ~flag; }
void setFlag(int flag) { F() |= flag; }
void setFlag(int flag, int condition) { setFlag(flag, condition != 0); }
void setFlag(int flag, uint32_t condition) { setFlag(flag, condition != 0); }
void setFlag(int flag, bool condition) { condition ? setFlag(flag) : clearFlag(flag); }
void clearFlag(int flag, int condition) { clearFlag(flag, condition != 0); }
void clearFlag(int flag, uint32_t condition) { clearFlag(flag, condition != 0); }
void clearFlag(int flag, bool condition) { condition ? clearFlag(flag) : setFlag(flag); }
uint8_t& R(int r) {
switch (r) {
case 0:

View File

@ -41,34 +41,22 @@ namespace EightBit {
// Mutable access to processor!!
register16_t& AF() {
virtual register16_t& AF() override {
return m_accumulatorFlags[m_accumulatorFlagsSet];
}
uint8_t& A() { return AF().high; }
uint8_t& F() { return AF().low; }
register16_t& BC() {
virtual register16_t& BC() override {
return m_registers[m_registerSet][BC_IDX];
}
uint8_t& B() { return BC().high; }
uint8_t& C() { return BC().low; }
register16_t& DE() {
virtual register16_t& DE() override {
return m_registers[m_registerSet][DE_IDX];
}
uint8_t& D() { return DE().high; }
uint8_t& E() { return DE().low; }
register16_t& HL() {
virtual register16_t& HL() override {
return m_registers[m_registerSet][HL_IDX];
}
uint8_t& H() { return HL().high; }
uint8_t& L() { return HL().low; }
register16_t& IX() { return m_ix; }
uint8_t& IXH() { return IX().high; }
uint8_t& IXL() { return IX().low; }
@ -136,17 +124,6 @@ namespace EightBit {
REFRESH() = (REFRESH() & Bit7) | incremented;
}
void clearFlag(int flag) { F() &= ~flag; }
void setFlag(int flag) { F() |= flag; }
void setFlag(int flag, int condition) { setFlag(flag, condition != 0); }
void setFlag(int flag, uint32_t condition) { setFlag(flag, condition != 0); }
void setFlag(int flag, bool condition) { condition ? setFlag(flag) : clearFlag(flag); }
void clearFlag(int flag, int condition) { clearFlag(flag, condition != 0); }
void clearFlag(int flag, uint32_t condition) { clearFlag(flag, condition != 0); }
void clearFlag(int flag, bool condition) { condition ? clearFlag(flag) : setFlag(flag); }
uint8_t& DISPLACED() {
m_memory.ADDRESS().word = MEMPTR().word = (m_prefixDD ? IX() : IY()).word + m_displacement;
return m_memory.reference();

View File

@ -10,9 +10,36 @@ namespace EightBit {
virtual void initialise();
virtual register16_t& AF() = 0;
uint8_t& A() { return AF().high; }
uint8_t& F() { return AF().low; }
virtual register16_t& BC() = 0;
uint8_t& B() { return BC().high; }
uint8_t& C() { return BC().low; }
virtual register16_t& DE() = 0;
uint8_t& D() { return DE().high; }
uint8_t& E() { return DE().low; }
virtual register16_t& HL() = 0;
uint8_t& H() { return HL().high; }
uint8_t& L() { return HL().low; }
protected:
IntelProcessor(Memory& memory);
void clearFlag(int flag) { F() &= ~flag; }
void setFlag(int flag) { F() |= flag; }
void setFlag(int flag, int condition) { setFlag(flag, condition != 0); }
void setFlag(int flag, uint32_t condition) { setFlag(flag, condition != 0); }
void setFlag(int flag, bool condition) { condition ? setFlag(flag) : clearFlag(flag); }
void clearFlag(int flag, int condition) { clearFlag(flag, condition != 0); }
void clearFlag(int flag, uint32_t condition) { clearFlag(flag, condition != 0); }
void clearFlag(int flag, bool condition) { condition ? clearFlag(flag) : setFlag(flag); }
std::array<bool, 8> m_halfCarryTableAdd = { { false, false, true, false, true, false, true, true } };
std::array<bool, 8> m_halfCarryTableSub = { { false, true, true, true, false, false, false, true } };