Simplify some MEMPTR usage in Intel processors.

Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
Adrian Conlon
2018-01-10 23:08:14 +00:00
parent 3bd01e211e
commit 29edc46966
7 changed files with 52 additions and 63 deletions

View File

@@ -142,7 +142,7 @@ namespace EightBit {
static void subtract(uint8_t& f, uint8_t& operand, uint8_t value, int carry = 0); static void subtract(uint8_t& f, uint8_t& operand, uint8_t value, int carry = 0);
void execute(int x, int y, int z, int p, int q); void execute(uint8_t& a, uint8_t& f, int x, int y, int z, int p, int q);
static void increment(uint8_t& f, uint8_t& operand); static void increment(uint8_t& f, uint8_t& operand);
static void decrement(uint8_t& f, uint8_t& operand); static void decrement(uint8_t& f, uint8_t& operand);

View File

@@ -296,7 +296,11 @@ int EightBit::Intel8080::execute(uint8_t opcode) {
const auto p = decoded.p; const auto p = decoded.p;
const auto q = decoded.q; const auto q = decoded.q;
execute(x, y, z, p, q); auto& af = AF();
auto& a = af.high;
auto& f = af.low;
execute(a, f, x, y, z, p, q);
if (UNLIKELY(cycles() == 0)) if (UNLIKELY(cycles() == 0))
throw std::logic_error("Unhandled opcode"); throw std::logic_error("Unhandled opcode");
@@ -304,9 +308,7 @@ int EightBit::Intel8080::execute(uint8_t opcode) {
return cycles(); return cycles();
} }
void EightBit::Intel8080::execute(int x, int y, int z, int p, int q) { void EightBit::Intel8080::execute(uint8_t& a, uint8_t& f, int x, int y, int z, int p, int q) {
auto& a = A();
auto& f = F();
switch (x) { switch (x) {
case 0: case 0:
switch (z) { switch (z) {
@@ -337,25 +339,25 @@ void EightBit::Intel8080::execute(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();
memptrReference(); setByte(MEMPTR().word++, a);
setByte(MEMPTR().high = a); MEMPTR().high = a;
addCycles(7); addCycles(7);
break; break;
case 1: // LD (DE),A case 1: // LD (DE),A
MEMPTR() = DE(); MEMPTR() = DE();
memptrReference(); setByte(MEMPTR().word++, a);
setByte(MEMPTR().high = a); MEMPTR().high = a;
addCycles(7); addCycles(7);
break; break;
case 2: // LD (nn),HL case 2: // LD (nn),HL
fetchWord(); fetchWord();
setWordViaMemptr(HL()); setWord(HL());
addCycles(16); addCycles(16);
break; break;
case 3: // LD (nn),A case 3: // LD (nn),A
fetchWord(); fetchWord();
memptrReference(); setByte(MEMPTR().word++, a);
setByte(MEMPTR().high = a); MEMPTR().high = a;
addCycles(13); addCycles(13);
break; break;
default: default:
@@ -366,25 +368,22 @@ void EightBit::Intel8080::execute(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();
memptrReference(); a = getByte(MEMPTR().word++);
a = getByte();
addCycles(7); addCycles(7);
break; break;
case 1: // LD A,(DE) case 1: // LD A,(DE)
MEMPTR() = DE(); MEMPTR() = DE();
memptrReference(); a = getByte(MEMPTR().word++);
a = getByte();
addCycles(7); addCycles(7);
break; break;
case 2: // LD HL,(nn) case 2: // LD HL,(nn)
fetchWord(); fetchWord();
getWordViaMemptr(HL()); getWord(HL());
addCycles(16); addCycles(16);
break; break;
case 3: // LD A,(nn) case 3: // LD A,(nn)
fetchWord(); fetchWord();
memptrReference(); a = getByte(MEMPTR().word++);
a = getByte();
addCycles(13); addCycles(13);
break; break;
default: default:

View File

@@ -160,8 +160,8 @@ namespace EightBit {
static void subtract(uint8_t& f, uint8_t& operand, uint8_t value, int carry = 0); static void subtract(uint8_t& f, uint8_t& operand, uint8_t value, int carry = 0);
void executeCB(int x, int y, int z, int p, int q); void executeCB(uint8_t& a, uint8_t& f, int x, int y, int z, int p, int q);
void executeOther(int x, int y, int z, int p, int q); void executeOther(uint8_t& a, uint8_t& f, int x, int y, int z, int p, int q);
static void increment(uint8_t& f, uint8_t& operand); static void increment(uint8_t& f, uint8_t& operand);
static void decrement(uint8_t& f, uint8_t& operand); static void decrement(uint8_t& f, uint8_t& operand);

View File

@@ -338,10 +338,14 @@ int EightBit::GameBoy::LR35902::execute(uint8_t opcode) {
const auto p = decoded.p; const auto p = decoded.p;
const auto q = decoded.q; const auto q = decoded.q;
auto& af = AF();
auto& a = af.high;
auto& f = af.low;
if (LIKELY(!m_prefixCB)) if (LIKELY(!m_prefixCB))
executeOther(x, y, z, p, q); executeOther(a, f, x, y, z, p, q);
else else
executeCB(x, y, z, p, q); executeCB(a, f, x, y, z, p, q);
if (UNLIKELY(cycles() == 0)) if (UNLIKELY(cycles() == 0))
throw std::logic_error("Unhandled opcode"); throw std::logic_error("Unhandled opcode");
@@ -349,9 +353,7 @@ int EightBit::GameBoy::LR35902::execute(uint8_t opcode) {
return clockCycles(); return clockCycles();
} }
void EightBit::GameBoy::LR35902::executeCB(int x, int y, int z, int p, int q) { void EightBit::GameBoy::LR35902::executeCB(uint8_t& a, uint8_t& f, int x, int y, int z, int p, int q) {
auto& a = A();
auto& f = F();
switch (x) { switch (x) {
case 0: { // rot[y] r[z] case 0: { // rot[y] r[z]
auto operand = R(z, a); auto operand = R(z, a);
@@ -412,9 +414,7 @@ void EightBit::GameBoy::LR35902::executeCB(int x, int y, int z, int p, int q) {
} }
} }
void EightBit::GameBoy::LR35902::executeOther(int x, int y, int z, int p, int q) { void EightBit::GameBoy::LR35902::executeOther(uint8_t& a, uint8_t& f, int x, int y, int z, int p, int q) {
auto& a = A();
auto& f = F();
switch (x) { switch (x) {
case 0: case 0:
switch (z) { switch (z) {
@@ -425,7 +425,7 @@ void EightBit::GameBoy::LR35902::executeOther(int x, int y, int z, int p, int q)
break; break;
case 1: // GB: LD (nn),SP case 1: // GB: LD (nn),SP
fetchWord(); fetchWord();
setWordViaMemptr(SP()); setWord(SP());
addCycles(5); addCycles(5);
break; break;
case 2: // GB: STOP case 2: // GB: STOP

View File

@@ -602,9 +602,9 @@ bool EightBit::Z80::otdr(uint8_t& f) {
} }
void EightBit::Z80::rrd(uint8_t& a, uint8_t& f) { void EightBit::Z80::rrd(uint8_t& a, uint8_t& f) {
MEMPTR() = HL(); BUS().ADDRESS() = MEMPTR() = HL();
memptrReference();
const auto memory = getByte(); const auto memory = getByte();
MEMPTR().word++;
setByte(promoteNibble(a) | highNibble(memory)); setByte(promoteNibble(a) | highNibble(memory));
a = (a & 0xf0) | lowNibble(memory); a = (a & 0xf0) | lowNibble(memory);
adjustSZPXY<Z80>(f, a); adjustSZPXY<Z80>(f, a);
@@ -612,9 +612,9 @@ void EightBit::Z80::rrd(uint8_t& a, uint8_t& f) {
} }
void EightBit::Z80::rld(uint8_t& a, uint8_t& f) { void EightBit::Z80::rld(uint8_t& a, uint8_t& f) {
MEMPTR() = HL(); BUS().ADDRESS() = MEMPTR() = HL();
memptrReference();
const auto memory = getByte(); const auto memory = getByte();
MEMPTR().word++;
setByte(promoteNibble(memory) | lowNibble(a)); setByte(promoteNibble(memory) | lowNibble(a));
a = (a & 0xf0) | highNibble(memory); a = (a & 0xf0) | highNibble(memory);
adjustSZPXY<Z80>(f, a); adjustSZPXY<Z80>(f, a);
@@ -871,11 +871,11 @@ void EightBit::Z80::executeED(uint8_t& a, uint8_t& f, const int x, const int y,
switch (q) { switch (q) {
case 0: // LD (nn), rp[p] case 0: // LD (nn), rp[p]
fetchWord(); fetchWord();
setWordViaMemptr(RP(p)); setWord(RP(p));
break; break;
case 1: // LD rp[p], (nn) case 1: // LD rp[p], (nn)
fetchWord(); fetchWord();
getWordViaMemptr(RP(p)); getWord(RP(p));
break; break;
default: default:
UNREACHABLE; UNREACHABLE;
@@ -1114,25 +1114,25 @@ void EightBit::Z80::executeOther(uint8_t& a, uint8_t& f, const int x, const int
switch (p) { switch (p) {
case 0: // LD (BC),A case 0: // LD (BC),A
MEMPTR() = BC(); MEMPTR() = BC();
memptrReference(); setByte(MEMPTR().word++, a);
setByte(MEMPTR().high = a); MEMPTR().high = a;
addCycles(7); addCycles(7);
break; break;
case 1: // LD (DE),A case 1: // LD (DE),A
MEMPTR() = DE(); MEMPTR() = DE();
memptrReference(); setByte(MEMPTR().word++, a);
setByte(MEMPTR().high = a); MEMPTR().high = a;
addCycles(7); addCycles(7);
break; break;
case 2: // LD (nn),HL case 2: // LD (nn),HL
fetchWord(); fetchWord();
setWordViaMemptr(HL2()); setWord(HL2());
addCycles(16); addCycles(16);
break; break;
case 3: // LD (nn),A case 3: // LD (nn),A
fetchWord(); fetchWord();
memptrReference(); setByte(MEMPTR().word++, a);
setByte(MEMPTR().high = a); MEMPTR().high = a;
addCycles(13); addCycles(13);
break; break;
default: default:
@@ -1143,25 +1143,22 @@ void EightBit::Z80::executeOther(uint8_t& a, uint8_t& f, const int x, const int
switch (p) { switch (p) {
case 0: // LD A,(BC) case 0: // LD A,(BC)
MEMPTR() = BC(); MEMPTR() = BC();
memptrReference(); a = getByte(MEMPTR().word++);
a = getByte();
addCycles(7); addCycles(7);
break; break;
case 1: // LD A,(DE) case 1: // LD A,(DE)
MEMPTR() = DE(); MEMPTR() = DE();
memptrReference(); a = getByte(MEMPTR().word++);
a = getByte();
addCycles(7); addCycles(7);
break; break;
case 2: // LD HL,(nn) case 2: // LD HL,(nn)
fetchWord(); fetchWord();
getWordViaMemptr(HL2()); getWord(HL2());
addCycles(16); addCycles(16);
break; break;
case 3: // LD A,(nn) case 3: // LD A,(nn)
fetchWord(); fetchWord();
memptrReference(); a = getByte(MEMPTR().word++);
a = getByte();
addCycles(13); addCycles(13);
break; break;
default: default:

View File

@@ -120,13 +120,8 @@ namespace EightBit {
// //
void memptrReference() { void getWord(register16_t& value);
BUS().ADDRESS() = MEMPTR(); void setWord(register16_t value);
MEMPTR().word++;
}
void getWordViaMemptr(register16_t& value);
void setWordViaMemptr(register16_t value);
// //

View File

@@ -20,16 +20,14 @@ uint8_t EightBit::IntelProcessor::pop() {
return getByte(SP().word++); return getByte(SP().word++);
} }
void EightBit::IntelProcessor::getWordViaMemptr(register16_t& value) { void EightBit::IntelProcessor::getWord(register16_t& value) {
memptrReference(); value.low = getByte(MEMPTR().word++);
value.low = getByte();
BUS().ADDRESS().word++; BUS().ADDRESS().word++;
value.high = getByte(); value.high = getByte();
} }
void EightBit::IntelProcessor::setWordViaMemptr(register16_t value) { void EightBit::IntelProcessor::setWord(register16_t value) {
memptrReference(); setByte(MEMPTR().word++, value.low);
setByte(value.low);
BUS().ADDRESS().word++; BUS().ADDRESS().word++;
setByte(value.high); setByte(value.high);
} }