mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2024-12-22 09:30:32 +00:00
Simplify and remove a bunch of code. Getting there!
Signed-off-by: Adrian.Conlon <adrian.conlon@gmail.com>
This commit is contained in:
parent
705351d179
commit
71e6902aeb
@ -176,11 +176,6 @@ namespace EightBit {
|
|||||||
void orr(uint8_t& operand, uint8_t value);
|
void orr(uint8_t& operand, uint8_t value);
|
||||||
void compare(uint8_t value);
|
void compare(uint8_t value);
|
||||||
|
|
||||||
void rlca();
|
|
||||||
void rrca();
|
|
||||||
void rla();
|
|
||||||
void rra();
|
|
||||||
|
|
||||||
void rlc(uint8_t& operand);
|
void rlc(uint8_t& operand);
|
||||||
void rrc(uint8_t& operand);
|
void rrc(uint8_t& operand);
|
||||||
void rl(uint8_t& operand);
|
void rl(uint8_t& operand);
|
||||||
|
@ -309,24 +309,6 @@ void EightBit::LR35902::srl(uint8_t& operand) {
|
|||||||
adjustZero(operand);
|
adjustZero(operand);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
void EightBit::LR35902::rlca() {
|
|
||||||
rlc(A());
|
|
||||||
}
|
|
||||||
|
|
||||||
void EightBit::LR35902::rrca() {
|
|
||||||
rrc(A());
|
|
||||||
}
|
|
||||||
|
|
||||||
void EightBit::LR35902::rla() {
|
|
||||||
rl(A());
|
|
||||||
}
|
|
||||||
|
|
||||||
void EightBit::LR35902::rra() {
|
|
||||||
rr(A());
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma endregion Shift and rotate
|
#pragma endregion Shift and rotate
|
||||||
|
|
||||||
#pragma region BIT/SET/RES
|
#pragma region BIT/SET/RES
|
||||||
@ -537,22 +519,22 @@ void EightBit::LR35902::executeOther(int x, int y, int z, int p, int q) {
|
|||||||
switch (p) {
|
switch (p) {
|
||||||
case 0: // LD (BC),A
|
case 0: // LD (BC),A
|
||||||
MEMPTR() = BC();
|
MEMPTR() = BC();
|
||||||
setViaMemptr(A());
|
MEMPTR().high = memptrReference() = A();
|
||||||
cycles += 2;
|
cycles += 2;
|
||||||
break;
|
break;
|
||||||
case 1: // LD (DE),A
|
case 1: // LD (DE),A
|
||||||
MEMPTR() = DE();
|
MEMPTR() = DE();
|
||||||
setViaMemptr(A());
|
MEMPTR().high = memptrReference() = A();
|
||||||
cycles += 2;
|
cycles += 2;
|
||||||
break;
|
break;
|
||||||
case 2: // GB: LDI (HL),A
|
case 2: // GB: LDI (HL),A
|
||||||
MEMPTR().word = HL().word++;
|
MEMPTR().word = HL().word++;
|
||||||
setViaMemptr(A());
|
MEMPTR().high = memptrReference() = A();
|
||||||
cycles += 2;
|
cycles += 2;
|
||||||
break;
|
break;
|
||||||
case 3: // GB: LDD (HL),A
|
case 3: // GB: LDD (HL),A
|
||||||
MEMPTR().word = HL().word--;
|
MEMPTR().word = HL().word--;
|
||||||
setViaMemptr(A());
|
MEMPTR().high = memptrReference() = A();
|
||||||
cycles += 2;
|
cycles += 2;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -561,12 +543,12 @@ void EightBit::LR35902::executeOther(int x, int y, int z, int p, int q) {
|
|||||||
switch (p) {
|
switch (p) {
|
||||||
case 0: // LD A,(BC)
|
case 0: // LD A,(BC)
|
||||||
MEMPTR() = BC();
|
MEMPTR() = BC();
|
||||||
A() = getViaMemptr();
|
A() = memptrReference();
|
||||||
cycles += 2;
|
cycles += 2;
|
||||||
break;
|
break;
|
||||||
case 1: // LD A,(DE)
|
case 1: // LD A,(DE)
|
||||||
MEMPTR() = DE();
|
MEMPTR() = DE();
|
||||||
A() = getViaMemptr();
|
A() = memptrReference();
|
||||||
cycles += 2;
|
cycles += 2;
|
||||||
break;
|
break;
|
||||||
case 2: // GB: LDI A,(HL)
|
case 2: // GB: LDI A,(HL)
|
||||||
@ -613,16 +595,16 @@ void EightBit::LR35902::executeOther(int x, int y, int z, int p, int q) {
|
|||||||
case 7: // Assorted operations on accumulator/flags
|
case 7: // Assorted operations on accumulator/flags
|
||||||
switch (y) {
|
switch (y) {
|
||||||
case 0:
|
case 0:
|
||||||
rlca();
|
rlc(A());
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
rrca();
|
rrc(A());
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
rla();
|
rl(A());
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
rra();
|
rr(A());
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
daa();
|
daa();
|
||||||
|
@ -124,6 +124,7 @@ namespace EightBit {
|
|||||||
bool m_prefixFD;
|
bool m_prefixFD;
|
||||||
|
|
||||||
int8_t m_displacement;
|
int8_t m_displacement;
|
||||||
|
bool m_displaced;
|
||||||
|
|
||||||
int fetchExecute() {
|
int fetchExecute() {
|
||||||
M1() = true;
|
M1() = true;
|
||||||
@ -131,7 +132,7 @@ namespace EightBit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void incrementRefresh() {
|
void incrementRefresh() {
|
||||||
auto incremented = ((REFRESH() & Mask7) + 1) & Mask7;
|
auto incremented = (REFRESH() + 1) & Mask7;
|
||||||
REFRESH() = (REFRESH() & Bit7) | incremented;
|
REFRESH() = (REFRESH() & Bit7) | incremented;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,8 +148,6 @@ namespace EightBit {
|
|||||||
void clearFlag(int flag, bool condition) { condition ? clearFlag(flag) : setFlag(flag); }
|
void clearFlag(int flag, bool condition) { condition ? clearFlag(flag) : setFlag(flag); }
|
||||||
|
|
||||||
uint8_t& DISPLACED() {
|
uint8_t& DISPLACED() {
|
||||||
if (!(m_prefixDD || m_prefixFD))
|
|
||||||
throw std::logic_error("Unprefixed indexed displacement requested");
|
|
||||||
m_memory.ADDRESS().word = MEMPTR().word = (m_prefixDD ? IX() : IY()).word + m_displacement;
|
m_memory.ADDRESS().word = MEMPTR().word = (m_prefixDD ? IX() : IY()).word + m_displacement;
|
||||||
return m_memory.reference();
|
return m_memory.reference();
|
||||||
}
|
}
|
||||||
@ -164,11 +163,11 @@ namespace EightBit {
|
|||||||
case 3:
|
case 3:
|
||||||
return E();
|
return E();
|
||||||
case 4:
|
case 4:
|
||||||
return ALT_HL().high;
|
return HL2().high;
|
||||||
case 5:
|
case 5:
|
||||||
return ALT_HL().low;
|
return HL2().low;
|
||||||
case 6:
|
case 6:
|
||||||
if (m_prefixDD || m_prefixFD) {
|
if (m_displaced) {
|
||||||
m_displacement = fetchByte();
|
m_displacement = fetchByte();
|
||||||
return DISPLACED();
|
return DISPLACED();
|
||||||
}
|
}
|
||||||
@ -208,17 +207,19 @@ namespace EightBit {
|
|||||||
case 3:
|
case 3:
|
||||||
return sp;
|
return sp;
|
||||||
case HL_IDX:
|
case HL_IDX:
|
||||||
return ALT_HL();
|
return HL2();
|
||||||
default:
|
default:
|
||||||
return m_registers[m_registerSet][rp];
|
return m_registers[m_registerSet][rp];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
register16_t& ALT_HL() {
|
register16_t& HL2() {
|
||||||
if (m_prefixDD)
|
if (m_displaced) {
|
||||||
return IX();
|
if (m_prefixDD)
|
||||||
else if (m_prefixFD)
|
return IX();
|
||||||
return IY();
|
else if (m_prefixFD)
|
||||||
|
return IY();
|
||||||
|
}
|
||||||
return HL();
|
return HL();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -227,7 +228,7 @@ namespace EightBit {
|
|||||||
case 3:
|
case 3:
|
||||||
return AF();
|
return AF();
|
||||||
case HL_IDX:
|
case HL_IDX:
|
||||||
return ALT_HL();
|
return HL2();
|
||||||
default:
|
default:
|
||||||
return m_registers[m_registerSet][rp];
|
return m_registers[m_registerSet][rp];
|
||||||
}
|
}
|
||||||
@ -312,19 +313,14 @@ namespace EightBit {
|
|||||||
void orr(uint8_t& operand, uint8_t value);
|
void orr(uint8_t& operand, uint8_t value);
|
||||||
void compare(uint8_t value);
|
void compare(uint8_t value);
|
||||||
|
|
||||||
void rlca();
|
uint8_t& rlc(uint8_t& operand);
|
||||||
void rrca();
|
uint8_t& rrc(uint8_t& operand);
|
||||||
void rla();
|
uint8_t& rl(uint8_t& operand);
|
||||||
void rra();
|
uint8_t& rr(uint8_t& operand);
|
||||||
|
uint8_t& sla(uint8_t& operand);
|
||||||
void rlc(uint8_t& operand);
|
uint8_t& sra(uint8_t& operand);
|
||||||
void rrc(uint8_t& operand);
|
uint8_t& sll(uint8_t& operand);
|
||||||
void rl(uint8_t& operand);
|
uint8_t& srl(uint8_t& operand);
|
||||||
void rr(uint8_t& operand);
|
|
||||||
void sla(uint8_t& operand);
|
|
||||||
void sra(uint8_t& operand);
|
|
||||||
void sll(uint8_t& operand);
|
|
||||||
void srl(uint8_t& operand);
|
|
||||||
|
|
||||||
void bit(int n, uint8_t& operand);
|
void bit(int n, uint8_t& operand);
|
||||||
void res(int n, uint8_t& operand);
|
void res(int n, uint8_t& operand);
|
||||||
|
189
Z80/src/Z80.cpp
189
Z80/src/Z80.cpp
@ -391,25 +391,27 @@ void EightBit::Z80::compare(uint8_t value) {
|
|||||||
|
|
||||||
#pragma region Shift and rotate
|
#pragma region Shift and rotate
|
||||||
|
|
||||||
void EightBit::Z80::rlc(uint8_t& operand) {
|
uint8_t& EightBit::Z80::rlc(uint8_t& operand) {
|
||||||
auto carry = operand & Bit7;
|
auto carry = operand & Bit7;
|
||||||
operand <<= 1;
|
operand <<= 1;
|
||||||
setFlag(CF, carry);
|
|
||||||
carry ? operand |= Bit0 : operand &= ~Bit0;
|
carry ? operand |= Bit0 : operand &= ~Bit0;
|
||||||
|
setFlag(CF, carry);
|
||||||
clearFlag(NF | HC);
|
clearFlag(NF | HC);
|
||||||
adjustXY(operand);
|
adjustXY(operand);
|
||||||
|
return operand;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EightBit::Z80::rrc(uint8_t& operand) {
|
uint8_t& EightBit::Z80::rrc(uint8_t& operand) {
|
||||||
auto carry = operand & Bit0;
|
auto carry = operand & Bit0;
|
||||||
operand >>= 1;
|
operand >>= 1;
|
||||||
carry ? operand |= Bit7 : operand &= ~Bit7;
|
carry ? operand |= Bit7 : operand &= ~Bit7;
|
||||||
setFlag(CF, carry);
|
setFlag(CF, carry);
|
||||||
clearFlag(NF | HC);
|
clearFlag(NF | HC);
|
||||||
adjustXY(operand);
|
adjustXY(operand);
|
||||||
|
return operand;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EightBit::Z80::rl(uint8_t& operand) {
|
uint8_t& EightBit::Z80::rl(uint8_t& operand) {
|
||||||
auto oldCarry = F() & CF;
|
auto oldCarry = F() & CF;
|
||||||
auto newCarry = operand & Bit7;
|
auto newCarry = operand & Bit7;
|
||||||
operand <<= 1;
|
operand <<= 1;
|
||||||
@ -417,9 +419,10 @@ void EightBit::Z80::rl(uint8_t& operand) {
|
|||||||
setFlag(CF, newCarry);
|
setFlag(CF, newCarry);
|
||||||
clearFlag(NF | HC);
|
clearFlag(NF | HC);
|
||||||
adjustXY(operand);
|
adjustXY(operand);
|
||||||
|
return operand;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EightBit::Z80::rr(uint8_t& operand) {
|
uint8_t& EightBit::Z80::rr(uint8_t& operand) {
|
||||||
auto oldCarry = F() & CF;
|
auto oldCarry = F() & CF;
|
||||||
auto newCarry = operand & Bit0;
|
auto newCarry = operand & Bit0;
|
||||||
operand >>= 1;
|
operand >>= 1;
|
||||||
@ -427,19 +430,21 @@ void EightBit::Z80::rr(uint8_t& operand) {
|
|||||||
setFlag(CF, newCarry);
|
setFlag(CF, newCarry);
|
||||||
clearFlag(NF | HC);
|
clearFlag(NF | HC);
|
||||||
adjustXY(operand);
|
adjustXY(operand);
|
||||||
|
return operand;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
void EightBit::Z80::sla(uint8_t& operand) {
|
uint8_t& EightBit::Z80::sla(uint8_t& operand) {
|
||||||
auto newCarry = operand & Bit7;
|
auto newCarry = operand & Bit7;
|
||||||
operand <<= 1;
|
operand <<= 1;
|
||||||
setFlag(CF, newCarry);
|
setFlag(CF, newCarry);
|
||||||
clearFlag(NF | HC);
|
clearFlag(NF | HC);
|
||||||
adjustXY(operand);
|
adjustXY(operand);
|
||||||
|
return operand;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EightBit::Z80::sra(uint8_t& operand) {
|
uint8_t& EightBit::Z80::sra(uint8_t& operand) {
|
||||||
auto new7 = operand & Bit7;
|
auto new7 = operand & Bit7;
|
||||||
auto newCarry = operand & Bit0;
|
auto newCarry = operand & Bit0;
|
||||||
operand >>= 1;
|
operand >>= 1;
|
||||||
@ -447,18 +452,20 @@ void EightBit::Z80::sra(uint8_t& operand) {
|
|||||||
setFlag(CF, newCarry);
|
setFlag(CF, newCarry);
|
||||||
clearFlag(NF | HC);
|
clearFlag(NF | HC);
|
||||||
adjustXY(operand);
|
adjustXY(operand);
|
||||||
|
return operand;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EightBit::Z80::sll(uint8_t& operand) {
|
uint8_t& EightBit::Z80::sll(uint8_t& operand) {
|
||||||
auto newCarry = operand & Bit7;
|
auto newCarry = operand & Bit7;
|
||||||
operand <<= 1;
|
operand <<= 1;
|
||||||
operand |= 1;
|
operand |= 1;
|
||||||
setFlag(CF, newCarry);
|
setFlag(CF, newCarry);
|
||||||
clearFlag(NF | HC);
|
clearFlag(NF | HC);
|
||||||
adjustXY(operand);
|
adjustXY(operand);
|
||||||
|
return operand;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EightBit::Z80::srl(uint8_t& operand) {
|
uint8_t& EightBit::Z80::srl(uint8_t& operand) {
|
||||||
auto newCarry = operand & Bit0;
|
auto newCarry = operand & Bit0;
|
||||||
operand >>= 1;
|
operand >>= 1;
|
||||||
operand &= ~Bit7; // clear bit 7
|
operand &= ~Bit7; // clear bit 7
|
||||||
@ -466,24 +473,7 @@ void EightBit::Z80::srl(uint8_t& operand) {
|
|||||||
clearFlag(NF | HC);
|
clearFlag(NF | HC);
|
||||||
adjustXY(operand);
|
adjustXY(operand);
|
||||||
setFlag(ZF, operand);
|
setFlag(ZF, operand);
|
||||||
}
|
return operand;
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
void EightBit::Z80::rlca() {
|
|
||||||
rlc(A());
|
|
||||||
}
|
|
||||||
|
|
||||||
void EightBit::Z80::rrca() {
|
|
||||||
rrc(A());
|
|
||||||
}
|
|
||||||
|
|
||||||
void EightBit::Z80::rla() {
|
|
||||||
rl(A());
|
|
||||||
}
|
|
||||||
|
|
||||||
void EightBit::Z80::rra() {
|
|
||||||
rr(A());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma endregion Shift and rotate
|
#pragma endregion Shift and rotate
|
||||||
@ -524,7 +514,7 @@ void EightBit::Z80::daa() {
|
|||||||
|
|
||||||
uint8_t a = A();
|
uint8_t a = A();
|
||||||
|
|
||||||
auto lowAdjust = (F() & HC) | ((A() & Mask4) > 9);
|
auto lowAdjust = (F() & HC) | (lowNibble(A()) > 9);
|
||||||
auto highAdjust = (F() & CF) | (A() > 0x99);
|
auto highAdjust = (F() & CF) | (A() > 0x99);
|
||||||
|
|
||||||
if (F() & NF) {
|
if (F() & NF) {
|
||||||
@ -578,7 +568,7 @@ void EightBit::Z80::xhtl(register16_t& operand) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void EightBit::Z80::xhtl() {
|
void EightBit::Z80::xhtl() {
|
||||||
xhtl(ALT_HL());
|
xhtl(HL2());
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma endregion Miscellaneous instructions
|
#pragma endregion Miscellaneous instructions
|
||||||
@ -632,9 +622,8 @@ bool EightBit::Z80::cpdr() {
|
|||||||
cpd();
|
cpd();
|
||||||
MEMPTR().word = pc.word - 1;
|
MEMPTR().word = pc.word - 1;
|
||||||
auto again = (F() & PF) && !(F() & ZF); // See CPD
|
auto again = (F() & PF) && !(F() & ZF); // See CPD
|
||||||
if (!again) {
|
if (!again)
|
||||||
MEMPTR().word--;
|
MEMPTR().word--;
|
||||||
}
|
|
||||||
return again;
|
return again;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -762,22 +751,18 @@ bool EightBit::Z80::otdr() {
|
|||||||
|
|
||||||
void EightBit::Z80::rrd() {
|
void EightBit::Z80::rrd() {
|
||||||
MEMPTR() = HL();
|
MEMPTR() = HL();
|
||||||
auto memory = getViaMemptr();
|
auto memory = memptrReference();
|
||||||
auto accumulator = A();
|
m_memory.reference() = promoteNibble(A()) | highNibble(memory);
|
||||||
A() = (accumulator & 0xf0) | lowNibble(memory);
|
A() = (A() & 0xf0) | lowNibble(memory);
|
||||||
uint8_t updated = promoteNibble(lowNibble(accumulator)) | highNibble(memory);
|
|
||||||
m_memory.reference() = updated;
|
|
||||||
adjustSZPXY(A());
|
adjustSZPXY(A());
|
||||||
clearFlag(NF | HC);
|
clearFlag(NF | HC);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EightBit::Z80::rld() {
|
void EightBit::Z80::rld() {
|
||||||
MEMPTR() = HL();
|
MEMPTR() = HL();
|
||||||
auto memory = getViaMemptr();
|
auto memory = memptrReference();
|
||||||
auto accumulator = A();
|
m_memory.reference() = promoteNibble(memory) | lowNibble(A());
|
||||||
uint8_t updated = lowNibble(accumulator) | promoteNibble(memory);
|
A() = (A() & 0xf0) | highNibble(memory);
|
||||||
A() = (accumulator & 0xf0) | highNibble(memory);
|
|
||||||
m_memory.reference() = updated;
|
|
||||||
adjustSZPXY(A());
|
adjustSZPXY(A());
|
||||||
clearFlag(NF | HC);
|
clearFlag(NF | HC);
|
||||||
}
|
}
|
||||||
@ -786,7 +771,7 @@ void EightBit::Z80::rld() {
|
|||||||
|
|
||||||
int EightBit::Z80::step() {
|
int EightBit::Z80::step() {
|
||||||
ExecutingInstruction.fire(*this);
|
ExecutingInstruction.fire(*this);
|
||||||
m_prefixCB = m_prefixDD = m_prefixED = m_prefixFD = false;
|
m_displaced = m_prefixCB = m_prefixDD = m_prefixED = m_prefixFD = false;
|
||||||
cycles = 0;
|
cycles = 0;
|
||||||
return fetchExecute();
|
return fetchExecute();
|
||||||
}
|
}
|
||||||
@ -803,7 +788,7 @@ int EightBit::Z80::execute(uint8_t opcode) {
|
|||||||
auto p = (y & 0b110) >> 1;
|
auto p = (y & 0b110) >> 1;
|
||||||
auto q = (y & 1);
|
auto q = (y & 1);
|
||||||
|
|
||||||
if (!(m_prefixCB && (m_prefixDD || m_prefixFD))) {
|
if (!(m_prefixCB && m_displaced)) {
|
||||||
incrementRefresh();
|
incrementRefresh();
|
||||||
M1() = false;
|
M1() = false;
|
||||||
}
|
}
|
||||||
@ -826,75 +811,31 @@ void EightBit::Z80::executeCB(int x, int y, int z, int p, int q) {
|
|||||||
case 0: // rot[y] r[z]
|
case 0: // rot[y] r[z]
|
||||||
switch (y) {
|
switch (y) {
|
||||||
case 0:
|
case 0:
|
||||||
if (m_prefixDD || m_prefixFD) {
|
adjustSZP(m_displaced ? R2(z) = rlc(DISPLACED()) : rlc(R(z)));
|
||||||
rlc(DISPLACED());
|
|
||||||
R2(z) = DISPLACED();
|
|
||||||
} else {
|
|
||||||
rlc(R(z));
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
if (m_prefixDD || m_prefixFD) {
|
adjustSZP(m_displaced ? R2(z) = rrc(DISPLACED()) : rrc(R(z)));
|
||||||
rrc(DISPLACED());
|
|
||||||
R2(z) = DISPLACED();
|
|
||||||
} else {
|
|
||||||
rrc(R(z));
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
if (m_prefixDD || m_prefixFD) {
|
adjustSZP(m_displaced ? R2(z) = rl(DISPLACED()) : rl(R(z)));
|
||||||
rl(DISPLACED());
|
|
||||||
R2(z) = DISPLACED();
|
|
||||||
} else {
|
|
||||||
rl(R(z));
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
if (m_prefixDD || m_prefixFD) {
|
adjustSZP(m_displaced ? R2(z) = rr(DISPLACED()) : rr(R(z)));
|
||||||
rr(DISPLACED());
|
|
||||||
R2(z) = DISPLACED();
|
|
||||||
} else {
|
|
||||||
rr(R(z));
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
if (m_prefixDD || m_prefixFD) {
|
adjustSZP(m_displaced ? R2(z) = sla(DISPLACED()) : sla(R(z)));
|
||||||
sla(DISPLACED());
|
|
||||||
R2(z) = DISPLACED();
|
|
||||||
} else {
|
|
||||||
sla(R(z));
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
if (m_prefixDD || m_prefixFD) {
|
adjustSZP(m_displaced ? R2(z) = sra(DISPLACED()) : sra(R(z)));
|
||||||
sra(DISPLACED());
|
|
||||||
R2(z) = DISPLACED();
|
|
||||||
} else {
|
|
||||||
sra(R(z));
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
if (m_prefixDD || m_prefixFD) {
|
adjustSZP(m_displaced ? R2(z) = sll(DISPLACED()) : sll(R(z)));
|
||||||
sll(DISPLACED());
|
|
||||||
R2(z) = DISPLACED();
|
|
||||||
} else {
|
|
||||||
sll(R(z));
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
if (m_prefixDD || m_prefixFD) {
|
adjustSZP(m_displaced ? R2(z) = srl(DISPLACED()) : srl(R(z)));
|
||||||
srl(DISPLACED());
|
|
||||||
R2(z) = DISPLACED();
|
|
||||||
} else {
|
|
||||||
srl(R(z));
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (m_prefixDD || m_prefixFD)
|
if (m_displaced) {
|
||||||
adjustSZP(DISPLACED());
|
|
||||||
else
|
|
||||||
adjustSZP(R(z));
|
|
||||||
if (m_prefixDD || m_prefixFD) {
|
|
||||||
cycles += 23;
|
cycles += 23;
|
||||||
} else {
|
} else {
|
||||||
cycles += 8;
|
cycles += 8;
|
||||||
@ -903,7 +844,7 @@ void EightBit::Z80::executeCB(int x, int y, int z, int p, int q) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 1: // BIT y, r[z]
|
case 1: // BIT y, r[z]
|
||||||
if (m_prefixDD || m_prefixFD) {
|
if (m_displaced) {
|
||||||
bit(y, DISPLACED());
|
bit(y, DISPLACED());
|
||||||
adjustXY(MEMPTR().high);
|
adjustXY(MEMPTR().high);
|
||||||
cycles += 20;
|
cycles += 20;
|
||||||
@ -920,7 +861,7 @@ void EightBit::Z80::executeCB(int x, int y, int z, int p, int q) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 2: // RES y, r[z]
|
case 2: // RES y, r[z]
|
||||||
if (m_prefixDD || m_prefixFD) {
|
if (m_displaced) {
|
||||||
res(y, DISPLACED());
|
res(y, DISPLACED());
|
||||||
R2(z) = DISPLACED();
|
R2(z) = DISPLACED();
|
||||||
cycles += 23;
|
cycles += 23;
|
||||||
@ -932,7 +873,7 @@ void EightBit::Z80::executeCB(int x, int y, int z, int p, int q) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 3: // SET y, r[z]
|
case 3: // SET y, r[z]
|
||||||
if (m_prefixDD || m_prefixFD) {
|
if (m_displaced) {
|
||||||
set(y, DISPLACED());
|
set(y, DISPLACED());
|
||||||
R2(z) = DISPLACED();
|
R2(z) = DISPLACED();
|
||||||
cycles += 23;
|
cycles += 23;
|
||||||
@ -961,7 +902,7 @@ void EightBit::Z80::executeED(int x, int y, int z, int p, int q) {
|
|||||||
if (y != 6) // IN r[y],(C)
|
if (y != 6) // IN r[y],(C)
|
||||||
R(y) = m_memory.DATA();
|
R(y) = m_memory.DATA();
|
||||||
adjustSZPXY(m_memory.DATA());
|
adjustSZPXY(m_memory.DATA());
|
||||||
clearFlag(HC | NF);
|
clearFlag(NF | HC);
|
||||||
cycles += 12;
|
cycles += 12;
|
||||||
break;
|
break;
|
||||||
case 1: // Output to port with 16-bit address
|
case 1: // Output to port with 16-bit address
|
||||||
@ -977,10 +918,10 @@ void EightBit::Z80::executeED(int x, int y, int z, int p, int q) {
|
|||||||
case 2: // 16-bit add/subtract with carry
|
case 2: // 16-bit add/subtract with carry
|
||||||
switch (q) {
|
switch (q) {
|
||||||
case 0: // SBC HL, rp[p]
|
case 0: // SBC HL, rp[p]
|
||||||
sbcViaMemptr(ALT_HL(), RP(p));
|
sbcViaMemptr(HL2(), RP(p));
|
||||||
break;
|
break;
|
||||||
case 1: // ADC HL, rp[p]
|
case 1: // ADC HL, rp[p]
|
||||||
adcViaMemptr(ALT_HL(), RP(p));
|
adcViaMemptr(HL2(), RP(p));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
cycles += 15;
|
cycles += 15;
|
||||||
@ -1053,7 +994,7 @@ void EightBit::Z80::executeED(int x, int y, int z, int p, int q) {
|
|||||||
case 3: // LD A,R
|
case 3: // LD A,R
|
||||||
A() = REFRESH();
|
A() = REFRESH();
|
||||||
adjustSZXY(A());
|
adjustSZXY(A());
|
||||||
clearFlag(HC | NF);
|
clearFlag(NF | HC);
|
||||||
setFlag(PF, IFF2());
|
setFlag(PF, IFF2());
|
||||||
cycles += 9;
|
cycles += 9;
|
||||||
break;
|
break;
|
||||||
@ -1205,7 +1146,7 @@ void EightBit::Z80::executeOther(int x, int y, int z, int p, int q) {
|
|||||||
cycles += 10;
|
cycles += 10;
|
||||||
break;
|
break;
|
||||||
case 1: // ADD HL,rp
|
case 1: // ADD HL,rp
|
||||||
addViaMemptr(ALT_HL(), RP(p));
|
addViaMemptr(HL2(), RP(p));
|
||||||
cycles += 11;
|
cycles += 11;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1216,22 +1157,22 @@ void EightBit::Z80::executeOther(int x, int y, int z, int p, int q) {
|
|||||||
switch (p) {
|
switch (p) {
|
||||||
case 0: // LD (BC),A
|
case 0: // LD (BC),A
|
||||||
MEMPTR() = BC();
|
MEMPTR() = BC();
|
||||||
setViaMemptr(A());
|
MEMPTR().high = memptrReference() = A();
|
||||||
cycles += 7;
|
cycles += 7;
|
||||||
break;
|
break;
|
||||||
case 1: // LD (DE),A
|
case 1: // LD (DE),A
|
||||||
MEMPTR() = DE();
|
MEMPTR() = DE();
|
||||||
setViaMemptr(A());
|
MEMPTR().high = memptrReference() = A();
|
||||||
cycles += 7;
|
cycles += 7;
|
||||||
break;
|
break;
|
||||||
case 2: // LD (nn),HL
|
case 2: // LD (nn),HL
|
||||||
fetchWord();
|
fetchWord();
|
||||||
setWordViaMemptr(ALT_HL());
|
setWordViaMemptr(HL2());
|
||||||
cycles += 16;
|
cycles += 16;
|
||||||
break;
|
break;
|
||||||
case 3: // LD (nn),A
|
case 3: // LD (nn),A
|
||||||
fetchWord();
|
fetchWord();
|
||||||
setViaMemptr(A());
|
MEMPTR().high = memptrReference() = A();
|
||||||
cycles += 13;
|
cycles += 13;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1240,22 +1181,22 @@ void EightBit::Z80::executeOther(int x, int y, int z, int p, int q) {
|
|||||||
switch (p) {
|
switch (p) {
|
||||||
case 0: // LD A,(BC)
|
case 0: // LD A,(BC)
|
||||||
MEMPTR() = BC();
|
MEMPTR() = BC();
|
||||||
A() = getViaMemptr();
|
A() = memptrReference();
|
||||||
cycles += 7;
|
cycles += 7;
|
||||||
break;
|
break;
|
||||||
case 1: // LD A,(DE)
|
case 1: // LD A,(DE)
|
||||||
MEMPTR() = DE();
|
MEMPTR() = DE();
|
||||||
A() = getViaMemptr();
|
A() = memptrReference();
|
||||||
cycles += 7;
|
cycles += 7;
|
||||||
break;
|
break;
|
||||||
case 2: // LD HL,(nn)
|
case 2: // LD HL,(nn)
|
||||||
fetchWord();
|
fetchWord();
|
||||||
getWordViaMemptr(ALT_HL());
|
getWordViaMemptr(HL2());
|
||||||
cycles += 16;
|
cycles += 16;
|
||||||
break;
|
break;
|
||||||
case 3: // LD A,(nn)
|
case 3: // LD A,(nn)
|
||||||
fetchWord();
|
fetchWord();
|
||||||
A() = getViaMemptr();
|
A() = memptrReference();
|
||||||
cycles += 13;
|
cycles += 13;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1283,25 +1224,25 @@ void EightBit::Z80::executeOther(int x, int y, int z, int p, int q) {
|
|||||||
if (y == 6)
|
if (y == 6)
|
||||||
cycles += 7;
|
cycles += 7;
|
||||||
break;
|
break;
|
||||||
case 6: { // 8-bit load immediate
|
case 6: // 8-bit load immediate
|
||||||
R(y) = fetchByte(); // LD r,n
|
R(y) = fetchByte(); // LD r,n
|
||||||
cycles += 7;
|
cycles += 7;
|
||||||
if (y == 6)
|
if (y == 6)
|
||||||
cycles += 3;
|
cycles += 3;
|
||||||
break;
|
break;
|
||||||
} case 7: // Assorted operations on accumulator/flags
|
case 7: // Assorted operations on accumulator/flags
|
||||||
switch (y) {
|
switch (y) {
|
||||||
case 0:
|
case 0:
|
||||||
rlca();
|
rlc(A());
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
rrca();
|
rrc(A());
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
rla();
|
rl(A());
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
rra();
|
rr(A());
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
daa();
|
daa();
|
||||||
@ -1325,7 +1266,7 @@ void EightBit::Z80::executeOther(int x, int y, int z, int p, int q) {
|
|||||||
halt();
|
halt();
|
||||||
} else {
|
} else {
|
||||||
bool normal = true;
|
bool normal = true;
|
||||||
if (m_prefixDD || m_prefixFD) {
|
if (m_displaced) {
|
||||||
if (z == 6) {
|
if (z == 6) {
|
||||||
switch (y) {
|
switch (y) {
|
||||||
case 4:
|
case 4:
|
||||||
@ -1413,11 +1354,11 @@ void EightBit::Z80::executeOther(int x, int y, int z, int p, int q) {
|
|||||||
cycles += 4;
|
cycles += 4;
|
||||||
break;
|
break;
|
||||||
case 2: // JP HL
|
case 2: // JP HL
|
||||||
pc = ALT_HL();
|
pc = HL2();
|
||||||
cycles += 4;
|
cycles += 4;
|
||||||
break;
|
break;
|
||||||
case 3: // LD SP,HL
|
case 3: // LD SP,HL
|
||||||
sp = ALT_HL();
|
sp = HL2();
|
||||||
cycles += 4;
|
cycles += 4;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1436,7 +1377,7 @@ void EightBit::Z80::executeOther(int x, int y, int z, int p, int q) {
|
|||||||
break;
|
break;
|
||||||
case 1: // CB prefix
|
case 1: // CB prefix
|
||||||
m_prefixCB = true;
|
m_prefixCB = true;
|
||||||
if (m_prefixDD || m_prefixFD)
|
if (m_displaced)
|
||||||
m_displacement = fetchByte();
|
m_displacement = fetchByte();
|
||||||
fetchExecute();
|
fetchExecute();
|
||||||
break;
|
break;
|
||||||
@ -1495,7 +1436,7 @@ void EightBit::Z80::executeOther(int x, int y, int z, int p, int q) {
|
|||||||
cycles += 17;
|
cycles += 17;
|
||||||
break;
|
break;
|
||||||
case 1: // DD prefix
|
case 1: // DD prefix
|
||||||
m_prefixDD = true;
|
m_displaced = m_prefixDD = true;
|
||||||
fetchExecute();
|
fetchExecute();
|
||||||
break;
|
break;
|
||||||
case 2: // ED prefix
|
case 2: // ED prefix
|
||||||
@ -1503,7 +1444,7 @@ void EightBit::Z80::executeOther(int x, int y, int z, int p, int q) {
|
|||||||
fetchExecute();
|
fetchExecute();
|
||||||
break;
|
break;
|
||||||
case 3: // FD prefix
|
case 3: // FD prefix
|
||||||
m_prefixFD = true;
|
m_displaced = m_prefixFD = true;
|
||||||
fetchExecute();
|
fetchExecute();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -42,31 +42,20 @@ namespace EightBit {
|
|||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
uint8_t getViaMemptr() {
|
uint8_t& memptrReference() {
|
||||||
m_memory.ADDRESS() = MEMPTR();
|
m_memory.ADDRESS() = MEMPTR();
|
||||||
MEMPTR().word++;
|
MEMPTR().word++;
|
||||||
return m_memory.reference();
|
return m_memory.reference();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setViaMemptr(uint8_t value) {
|
|
||||||
m_memory.ADDRESS() = MEMPTR();
|
|
||||||
MEMPTR().word++;
|
|
||||||
m_memory.reference() = value;
|
|
||||||
MEMPTR().high = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
void getWordViaMemptr(register16_t& value) {
|
void getWordViaMemptr(register16_t& value) {
|
||||||
m_memory.ADDRESS() = MEMPTR();
|
value.low = memptrReference();
|
||||||
MEMPTR().word++;
|
|
||||||
value.low = m_memory.reference();
|
|
||||||
m_memory.ADDRESS().word++;
|
m_memory.ADDRESS().word++;
|
||||||
value.high = m_memory.reference();
|
value.high = m_memory.reference();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setWordViaMemptr(register16_t value) {
|
void setWordViaMemptr(register16_t value) {
|
||||||
m_memory.ADDRESS() = MEMPTR();
|
memptrReference() = value.low;
|
||||||
MEMPTR().word++;
|
|
||||||
m_memory.reference() = value.low;
|
|
||||||
m_memory.ADDRESS().word++;
|
m_memory.ADDRESS().word++;
|
||||||
m_memory.reference() = value.high;
|
m_memory.reference() = value.high;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user