mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2025-08-12 05:24:56 +00:00
Performance mods: probably about 30% speedup: the best yet.
Signed-off-by: Adrian.Conlon <adrian.conlon@gmail.com>
This commit is contained in:
@@ -166,7 +166,7 @@ namespace EightBit {
|
|||||||
return m_memory.reference();
|
return m_memory.reference();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t& R(int r) {
|
uint8_t& R(int r, uint8_t& a) {
|
||||||
switch (r) {
|
switch (r) {
|
||||||
case 0:
|
case 0:
|
||||||
return B();
|
return B();
|
||||||
@@ -188,14 +188,14 @@ namespace EightBit {
|
|||||||
m_memory.ADDRESS() = HL();
|
m_memory.ADDRESS() = HL();
|
||||||
return m_memory.reference();
|
return m_memory.reference();
|
||||||
case 7:
|
case 7:
|
||||||
return A();
|
return a;
|
||||||
default:
|
default:
|
||||||
__assume(0);
|
__assume(0);
|
||||||
}
|
}
|
||||||
throw std::logic_error("Unhandled registry mechanism");
|
throw std::logic_error("Unhandled registry mechanism");
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t& R2(int r) {
|
uint8_t& R2(int r, uint8_t& a) {
|
||||||
switch (r) {
|
switch (r) {
|
||||||
case 0:
|
case 0:
|
||||||
return B();
|
return B();
|
||||||
@@ -213,7 +213,7 @@ namespace EightBit {
|
|||||||
m_memory.ADDRESS() = HL();
|
m_memory.ADDRESS() = HL();
|
||||||
return m_memory.reference();
|
return m_memory.reference();
|
||||||
case 7:
|
case 7:
|
||||||
return A();
|
return a;
|
||||||
default:
|
default:
|
||||||
__assume(0);
|
__assume(0);
|
||||||
}
|
}
|
||||||
|
@@ -818,28 +818,28 @@ void EightBit::Z80::executeCB(int x, int y, int z) {
|
|||||||
case 0: // rot[y] r[z]
|
case 0: // rot[y] r[z]
|
||||||
switch (y) {
|
switch (y) {
|
||||||
case 0:
|
case 0:
|
||||||
adjustSZP<Z80>(f, m_displaced ? R2(z) = rlc(f, DISPLACED()) : rlc(f, R(z)));
|
adjustSZP<Z80>(f, m_displaced ? R2(z, a) = rlc(f, DISPLACED()) : rlc(f, R(z, a)));
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
adjustSZP<Z80>(f, m_displaced ? R2(z) = rrc(f, DISPLACED()) : rrc(f, R(z)));
|
adjustSZP<Z80>(f, m_displaced ? R2(z, a) = rrc(f, DISPLACED()) : rrc(f, R(z, a)));
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
adjustSZP<Z80>(f, m_displaced ? R2(z) = rl(f, DISPLACED()) : rl(f, R(z)));
|
adjustSZP<Z80>(f, m_displaced ? R2(z, a) = rl(f, DISPLACED()) : rl(f, R(z, a)));
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
adjustSZP<Z80>(f, m_displaced ? R2(z) = rr(f, DISPLACED()) : rr(f, R(z)));
|
adjustSZP<Z80>(f, m_displaced ? R2(z, a) = rr(f, DISPLACED()) : rr(f, R(z, a)));
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
adjustSZP<Z80>(f, m_displaced ? R2(z) = sla(f, DISPLACED()) : sla(f, R(z)));
|
adjustSZP<Z80>(f, m_displaced ? R2(z, a) = sla(f, DISPLACED()) : sla(f, R(z, a)));
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
adjustSZP<Z80>(f, m_displaced ? R2(z) = sra(f, DISPLACED()) : sra(f, R(z)));
|
adjustSZP<Z80>(f, m_displaced ? R2(z, a) = sra(f, DISPLACED()) : sra(f, R(z, a)));
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
adjustSZP<Z80>(f, m_displaced ? R2(z) = sll(f, DISPLACED()) : sll(f, R(z)));
|
adjustSZP<Z80>(f, m_displaced ? R2(z, a) = sll(f, DISPLACED()) : sll(f, R(z, a)));
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
adjustSZP<Z80>(f, m_displaced ? R2(z) = srl(f, DISPLACED()) : srl(f, R(z)));
|
adjustSZP<Z80>(f, m_displaced ? R2(z, a) = srl(f, DISPLACED()) : srl(f, R(z, a)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (m_displaced) {
|
if (m_displaced) {
|
||||||
@@ -856,7 +856,7 @@ void EightBit::Z80::executeCB(int x, int y, int z) {
|
|||||||
adjustXY<Z80>(f, MEMPTR().high);
|
adjustXY<Z80>(f, MEMPTR().high);
|
||||||
cycles += 20;
|
cycles += 20;
|
||||||
} else {
|
} else {
|
||||||
auto operand = bit(f, y, R(z));
|
auto operand = bit(f, y, R(z, a));
|
||||||
cycles += 8;
|
cycles += 8;
|
||||||
if (z == 6) {
|
if (z == 6) {
|
||||||
adjustXY<Z80>(f, MEMPTR().high);
|
adjustXY<Z80>(f, MEMPTR().high);
|
||||||
@@ -868,10 +868,10 @@ void EightBit::Z80::executeCB(int x, int y, int z) {
|
|||||||
break;
|
break;
|
||||||
case 2: // RES y, r[z]
|
case 2: // RES y, r[z]
|
||||||
if (m_displaced) {
|
if (m_displaced) {
|
||||||
R2(z) = res(y, DISPLACED());
|
R2(z, a) = res(y, DISPLACED());
|
||||||
cycles += 23;
|
cycles += 23;
|
||||||
} else {
|
} else {
|
||||||
res(y, R(z));
|
res(y, R(z, a));
|
||||||
cycles += 8;
|
cycles += 8;
|
||||||
if (z == 6)
|
if (z == 6)
|
||||||
cycles += 7;
|
cycles += 7;
|
||||||
@@ -879,10 +879,10 @@ void EightBit::Z80::executeCB(int x, int y, int z) {
|
|||||||
break;
|
break;
|
||||||
case 3: // SET y, r[z]
|
case 3: // SET y, r[z]
|
||||||
if (m_displaced) {
|
if (m_displaced) {
|
||||||
R2(z) = set(y, DISPLACED());
|
R2(z, a) = set(y, DISPLACED());
|
||||||
cycles += 23;
|
cycles += 23;
|
||||||
} else {
|
} else {
|
||||||
set(y, R(z));
|
set(y, R(z, a));
|
||||||
cycles += 8;
|
cycles += 8;
|
||||||
if (z == 6)
|
if (z == 6)
|
||||||
cycles += 7;
|
cycles += 7;
|
||||||
@@ -906,7 +906,7 @@ void EightBit::Z80::executeED(int x, int y, int z, int p, int q) {
|
|||||||
MEMPTR().word++;
|
MEMPTR().word++;
|
||||||
readPort();
|
readPort();
|
||||||
if (y != 6) // IN r[y],(C)
|
if (y != 6) // IN r[y],(C)
|
||||||
R(y) = m_memory.DATA();
|
R(y, a) = m_memory.DATA();
|
||||||
adjustSZPXY<Z80>(f, m_memory.DATA());
|
adjustSZPXY<Z80>(f, m_memory.DATA());
|
||||||
clearFlag(f, NF | HC);
|
clearFlag(f, NF | HC);
|
||||||
cycles += 12;
|
cycles += 12;
|
||||||
@@ -917,7 +917,7 @@ void EightBit::Z80::executeED(int x, int y, int z, int p, int q) {
|
|||||||
if (y == 6) // OUT (C),0
|
if (y == 6) // OUT (C),0
|
||||||
m_memory.placeDATA(0);
|
m_memory.placeDATA(0);
|
||||||
else // OUT (C),r[y]
|
else // OUT (C),r[y]
|
||||||
m_memory.placeDATA(R(y));
|
m_memory.placeDATA(R(y, a));
|
||||||
writePort();
|
writePort();
|
||||||
cycles += 12;
|
cycles += 12;
|
||||||
break;
|
break;
|
||||||
@@ -1243,17 +1243,17 @@ void EightBit::Z80::executeOther(int x, int y, int z, int p, int q) {
|
|||||||
cycles += 6;
|
cycles += 6;
|
||||||
break;
|
break;
|
||||||
case 4: // 8-bit INC
|
case 4: // 8-bit INC
|
||||||
postIncrement(f, ++R(y)); // INC r
|
postIncrement(f, ++R(y, a)); // INC r
|
||||||
cycles += 4;
|
cycles += 4;
|
||||||
break;
|
break;
|
||||||
case 5: // 8-bit DEC
|
case 5: // 8-bit DEC
|
||||||
postDecrement(f, --R(y)); // DEC r
|
postDecrement(f, --R(y, a)); // DEC r
|
||||||
cycles += 4;
|
cycles += 4;
|
||||||
if (y == 6)
|
if (y == 6)
|
||||||
cycles += 7;
|
cycles += 7;
|
||||||
break;
|
break;
|
||||||
case 6: { // 8-bit load immediate
|
case 6: { // 8-bit load immediate
|
||||||
auto& r = R(y); // LD r,n
|
auto& r = R(y, a); // LD r,n
|
||||||
r = fetchByte();
|
r = fetchByte();
|
||||||
cycles += 7;
|
cycles += 7;
|
||||||
if (y == 6)
|
if (y == 6)
|
||||||
@@ -1303,11 +1303,11 @@ void EightBit::Z80::executeOther(int x, int y, int z, int p, int q) {
|
|||||||
if (z == 6) {
|
if (z == 6) {
|
||||||
switch (y) {
|
switch (y) {
|
||||||
case 4:
|
case 4:
|
||||||
H() = R(z);
|
H() = R(z, a);
|
||||||
normal = false;
|
normal = false;
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
L() = R(z);
|
L() = R(z, a);
|
||||||
normal = false;
|
normal = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1315,18 +1315,18 @@ void EightBit::Z80::executeOther(int x, int y, int z, int p, int q) {
|
|||||||
if (y == 6) {
|
if (y == 6) {
|
||||||
switch (z) {
|
switch (z) {
|
||||||
case 4:
|
case 4:
|
||||||
R(y) = H();
|
R(y, a) = H();
|
||||||
normal = false;
|
normal = false;
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
R(y) = L();
|
R(y, a) = L();
|
||||||
normal = false;
|
normal = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (normal)
|
if (normal)
|
||||||
R(y) = R(z);
|
R(y, a) = R(z, a);
|
||||||
if ((y == 6) || (z == 6)) // M operations
|
if ((y == 6) || (z == 6)) // M operations
|
||||||
cycles += 3;
|
cycles += 3;
|
||||||
}
|
}
|
||||||
@@ -1335,28 +1335,28 @@ void EightBit::Z80::executeOther(int x, int y, int z, int p, int q) {
|
|||||||
case 2: // Operate on accumulator and register/memory location
|
case 2: // Operate on accumulator and register/memory location
|
||||||
switch (y) {
|
switch (y) {
|
||||||
case 0: // ADD A,r
|
case 0: // ADD A,r
|
||||||
add(f, a, R(z));
|
add(f, a, R(z, a));
|
||||||
break;
|
break;
|
||||||
case 1: // ADC A,r
|
case 1: // ADC A,r
|
||||||
adc(f, a, R(z));
|
adc(f, a, R(z, a));
|
||||||
break;
|
break;
|
||||||
case 2: // SUB r
|
case 2: // SUB r
|
||||||
sub(f, a, R(z));
|
sub(f, a, R(z, a));
|
||||||
break;
|
break;
|
||||||
case 3: // SBC A,r
|
case 3: // SBC A,r
|
||||||
sbc(f, a, R(z));
|
sbc(f, a, R(z, a));
|
||||||
break;
|
break;
|
||||||
case 4: // AND r
|
case 4: // AND r
|
||||||
andr(f, a, R(z));
|
andr(f, a, R(z, a));
|
||||||
break;
|
break;
|
||||||
case 5: // XOR r
|
case 5: // XOR r
|
||||||
xorr(f, a, R(z));
|
xorr(f, a, R(z, a));
|
||||||
break;
|
break;
|
||||||
case 6: // OR r
|
case 6: // OR r
|
||||||
orr(f, a, R(z));
|
orr(f, a, R(z, a));
|
||||||
break;
|
break;
|
||||||
case 7: // CP r
|
case 7: // CP r
|
||||||
compare(f, a, R(z));
|
compare(f, a, R(z, a));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
__assume(0);
|
__assume(0);
|
||||||
|
@@ -39,16 +39,16 @@ namespace EightBit {
|
|||||||
|
|
||||||
Memory(uint16_t addressMask);
|
Memory(uint16_t addressMask);
|
||||||
|
|
||||||
virtual register16_t& ADDRESS() { return m_address; }
|
register16_t& ADDRESS() { return m_address; }
|
||||||
virtual uint8_t& DATA() { return *m_data; }
|
uint8_t& DATA() { return *m_data; }
|
||||||
|
|
||||||
virtual uint8_t& placeDATA(uint8_t value) {
|
uint8_t& placeDATA(uint8_t value) {
|
||||||
m_temporary = value;
|
m_temporary = value;
|
||||||
m_data = &m_temporary;
|
m_data = &m_temporary;
|
||||||
return DATA();
|
return DATA();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual uint8_t& referenceDATA(uint8_t& value) {
|
uint8_t& referenceDATA(uint8_t& value) {
|
||||||
m_data = &value;
|
m_data = &value;
|
||||||
return DATA();
|
return DATA();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user