mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2025-02-23 11:28:57 +00:00
Simplify some MEMPTR usage in Intel processors.
Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
parent
3bd01e211e
commit
29edc46966
@ -142,7 +142,7 @@ namespace EightBit {
|
||||
|
||||
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 decrement(uint8_t& f, uint8_t& operand);
|
||||
|
@ -296,7 +296,11 @@ int EightBit::Intel8080::execute(uint8_t opcode) {
|
||||
const auto p = decoded.p;
|
||||
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))
|
||||
throw std::logic_error("Unhandled opcode");
|
||||
@ -304,9 +308,7 @@ int EightBit::Intel8080::execute(uint8_t opcode) {
|
||||
return cycles();
|
||||
}
|
||||
|
||||
void EightBit::Intel8080::execute(int x, int y, int z, int p, int q) {
|
||||
auto& a = A();
|
||||
auto& f = F();
|
||||
void EightBit::Intel8080::execute(uint8_t& a, uint8_t& f, int x, int y, int z, int p, int q) {
|
||||
switch (x) {
|
||||
case 0:
|
||||
switch (z) {
|
||||
@ -337,25 +339,25 @@ void EightBit::Intel8080::execute(int x, int y, int z, int p, int q) {
|
||||
switch (p) {
|
||||
case 0: // LD (BC),A
|
||||
MEMPTR() = BC();
|
||||
memptrReference();
|
||||
setByte(MEMPTR().high = a);
|
||||
setByte(MEMPTR().word++, a);
|
||||
MEMPTR().high = a;
|
||||
addCycles(7);
|
||||
break;
|
||||
case 1: // LD (DE),A
|
||||
MEMPTR() = DE();
|
||||
memptrReference();
|
||||
setByte(MEMPTR().high = a);
|
||||
setByte(MEMPTR().word++, a);
|
||||
MEMPTR().high = a;
|
||||
addCycles(7);
|
||||
break;
|
||||
case 2: // LD (nn),HL
|
||||
fetchWord();
|
||||
setWordViaMemptr(HL());
|
||||
setWord(HL());
|
||||
addCycles(16);
|
||||
break;
|
||||
case 3: // LD (nn),A
|
||||
fetchWord();
|
||||
memptrReference();
|
||||
setByte(MEMPTR().high = a);
|
||||
setByte(MEMPTR().word++, a);
|
||||
MEMPTR().high = a;
|
||||
addCycles(13);
|
||||
break;
|
||||
default:
|
||||
@ -366,25 +368,22 @@ void EightBit::Intel8080::execute(int x, int y, int z, int p, int q) {
|
||||
switch (p) {
|
||||
case 0: // LD A,(BC)
|
||||
MEMPTR() = BC();
|
||||
memptrReference();
|
||||
a = getByte();
|
||||
a = getByte(MEMPTR().word++);
|
||||
addCycles(7);
|
||||
break;
|
||||
case 1: // LD A,(DE)
|
||||
MEMPTR() = DE();
|
||||
memptrReference();
|
||||
a = getByte();
|
||||
a = getByte(MEMPTR().word++);
|
||||
addCycles(7);
|
||||
break;
|
||||
case 2: // LD HL,(nn)
|
||||
fetchWord();
|
||||
getWordViaMemptr(HL());
|
||||
getWord(HL());
|
||||
addCycles(16);
|
||||
break;
|
||||
case 3: // LD A,(nn)
|
||||
fetchWord();
|
||||
memptrReference();
|
||||
a = getByte();
|
||||
a = getByte(MEMPTR().word++);
|
||||
addCycles(13);
|
||||
break;
|
||||
default:
|
||||
|
@ -160,8 +160,8 @@ namespace EightBit {
|
||||
|
||||
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 executeOther(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(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 decrement(uint8_t& f, uint8_t& operand);
|
||||
|
@ -338,10 +338,14 @@ int EightBit::GameBoy::LR35902::execute(uint8_t opcode) {
|
||||
const auto p = decoded.p;
|
||||
const auto q = decoded.q;
|
||||
|
||||
auto& af = AF();
|
||||
auto& a = af.high;
|
||||
auto& f = af.low;
|
||||
|
||||
if (LIKELY(!m_prefixCB))
|
||||
executeOther(x, y, z, p, q);
|
||||
executeOther(a, f, x, y, z, p, q);
|
||||
else
|
||||
executeCB(x, y, z, p, q);
|
||||
executeCB(a, f, x, y, z, p, q);
|
||||
|
||||
if (UNLIKELY(cycles() == 0))
|
||||
throw std::logic_error("Unhandled opcode");
|
||||
@ -349,9 +353,7 @@ int EightBit::GameBoy::LR35902::execute(uint8_t opcode) {
|
||||
return clockCycles();
|
||||
}
|
||||
|
||||
void EightBit::GameBoy::LR35902::executeCB(int x, int y, int z, int p, int q) {
|
||||
auto& a = A();
|
||||
auto& f = F();
|
||||
void EightBit::GameBoy::LR35902::executeCB(uint8_t& a, uint8_t& f, int x, int y, int z, int p, int q) {
|
||||
switch (x) {
|
||||
case 0: { // rot[y] r[z]
|
||||
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) {
|
||||
auto& a = A();
|
||||
auto& f = F();
|
||||
void EightBit::GameBoy::LR35902::executeOther(uint8_t& a, uint8_t& f, int x, int y, int z, int p, int q) {
|
||||
switch (x) {
|
||||
case 0:
|
||||
switch (z) {
|
||||
@ -425,7 +425,7 @@ void EightBit::GameBoy::LR35902::executeOther(int x, int y, int z, int p, int q)
|
||||
break;
|
||||
case 1: // GB: LD (nn),SP
|
||||
fetchWord();
|
||||
setWordViaMemptr(SP());
|
||||
setWord(SP());
|
||||
addCycles(5);
|
||||
break;
|
||||
case 2: // GB: STOP
|
||||
|
@ -602,9 +602,9 @@ bool EightBit::Z80::otdr(uint8_t& f) {
|
||||
}
|
||||
|
||||
void EightBit::Z80::rrd(uint8_t& a, uint8_t& f) {
|
||||
MEMPTR() = HL();
|
||||
memptrReference();
|
||||
BUS().ADDRESS() = MEMPTR() = HL();
|
||||
const auto memory = getByte();
|
||||
MEMPTR().word++;
|
||||
setByte(promoteNibble(a) | highNibble(memory));
|
||||
a = (a & 0xf0) | lowNibble(memory);
|
||||
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) {
|
||||
MEMPTR() = HL();
|
||||
memptrReference();
|
||||
BUS().ADDRESS() = MEMPTR() = HL();
|
||||
const auto memory = getByte();
|
||||
MEMPTR().word++;
|
||||
setByte(promoteNibble(memory) | lowNibble(a));
|
||||
a = (a & 0xf0) | highNibble(memory);
|
||||
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) {
|
||||
case 0: // LD (nn), rp[p]
|
||||
fetchWord();
|
||||
setWordViaMemptr(RP(p));
|
||||
setWord(RP(p));
|
||||
break;
|
||||
case 1: // LD rp[p], (nn)
|
||||
fetchWord();
|
||||
getWordViaMemptr(RP(p));
|
||||
getWord(RP(p));
|
||||
break;
|
||||
default:
|
||||
UNREACHABLE;
|
||||
@ -1114,25 +1114,25 @@ void EightBit::Z80::executeOther(uint8_t& a, uint8_t& f, const int x, const int
|
||||
switch (p) {
|
||||
case 0: // LD (BC),A
|
||||
MEMPTR() = BC();
|
||||
memptrReference();
|
||||
setByte(MEMPTR().high = a);
|
||||
setByte(MEMPTR().word++, a);
|
||||
MEMPTR().high = a;
|
||||
addCycles(7);
|
||||
break;
|
||||
case 1: // LD (DE),A
|
||||
MEMPTR() = DE();
|
||||
memptrReference();
|
||||
setByte(MEMPTR().high = a);
|
||||
setByte(MEMPTR().word++, a);
|
||||
MEMPTR().high = a;
|
||||
addCycles(7);
|
||||
break;
|
||||
case 2: // LD (nn),HL
|
||||
fetchWord();
|
||||
setWordViaMemptr(HL2());
|
||||
setWord(HL2());
|
||||
addCycles(16);
|
||||
break;
|
||||
case 3: // LD (nn),A
|
||||
fetchWord();
|
||||
memptrReference();
|
||||
setByte(MEMPTR().high = a);
|
||||
setByte(MEMPTR().word++, a);
|
||||
MEMPTR().high = a;
|
||||
addCycles(13);
|
||||
break;
|
||||
default:
|
||||
@ -1143,25 +1143,22 @@ void EightBit::Z80::executeOther(uint8_t& a, uint8_t& f, const int x, const int
|
||||
switch (p) {
|
||||
case 0: // LD A,(BC)
|
||||
MEMPTR() = BC();
|
||||
memptrReference();
|
||||
a = getByte();
|
||||
a = getByte(MEMPTR().word++);
|
||||
addCycles(7);
|
||||
break;
|
||||
case 1: // LD A,(DE)
|
||||
MEMPTR() = DE();
|
||||
memptrReference();
|
||||
a = getByte();
|
||||
a = getByte(MEMPTR().word++);
|
||||
addCycles(7);
|
||||
break;
|
||||
case 2: // LD HL,(nn)
|
||||
fetchWord();
|
||||
getWordViaMemptr(HL2());
|
||||
getWord(HL2());
|
||||
addCycles(16);
|
||||
break;
|
||||
case 3: // LD A,(nn)
|
||||
fetchWord();
|
||||
memptrReference();
|
||||
a = getByte();
|
||||
a = getByte(MEMPTR().word++);
|
||||
addCycles(13);
|
||||
break;
|
||||
default:
|
||||
|
@ -120,13 +120,8 @@ namespace EightBit {
|
||||
|
||||
//
|
||||
|
||||
void memptrReference() {
|
||||
BUS().ADDRESS() = MEMPTR();
|
||||
MEMPTR().word++;
|
||||
}
|
||||
|
||||
void getWordViaMemptr(register16_t& value);
|
||||
void setWordViaMemptr(register16_t value);
|
||||
void getWord(register16_t& value);
|
||||
void setWord(register16_t value);
|
||||
|
||||
//
|
||||
|
||||
|
@ -20,16 +20,14 @@ uint8_t EightBit::IntelProcessor::pop() {
|
||||
return getByte(SP().word++);
|
||||
}
|
||||
|
||||
void EightBit::IntelProcessor::getWordViaMemptr(register16_t& value) {
|
||||
memptrReference();
|
||||
value.low = getByte();
|
||||
void EightBit::IntelProcessor::getWord(register16_t& value) {
|
||||
value.low = getByte(MEMPTR().word++);
|
||||
BUS().ADDRESS().word++;
|
||||
value.high = getByte();
|
||||
}
|
||||
|
||||
void EightBit::IntelProcessor::setWordViaMemptr(register16_t value) {
|
||||
memptrReference();
|
||||
setByte(value.low);
|
||||
void EightBit::IntelProcessor::setWord(register16_t value) {
|
||||
setByte(MEMPTR().word++, value.low);
|
||||
BUS().ADDRESS().word++;
|
||||
setByte(value.high);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user