Some more shared code.

Signed-off-by: Adrian.Conlon <adrian.conlon@gmail.com>
This commit is contained in:
Adrian.Conlon 2017-06-22 19:00:53 +01:00
parent f776379e96
commit af375ab10f
4 changed files with 29 additions and 37 deletions

View File

@ -109,12 +109,8 @@ namespace EightBit {
// //
void compare(uint8_t value) { void compare(uint8_t value) {
const auto& a = A(); auto check = A();
auto& f = F(); sub(check, value);
uint16_t subtraction = a - value;
adjustSZP<Intel8080>(f, (uint8_t)subtraction);
adjustAuxiliaryCarrySub(f, a, value, subtraction);
setFlag(f, CF, subtraction & Bit8);
} }
void anda(uint8_t value) { void anda(uint8_t value) {
@ -159,15 +155,18 @@ namespace EightBit {
HL().word = (uint16_t)sum; HL().word = (uint16_t)sum;
} }
void sub(uint8_t value, int carry = 0) { void sub(uint8_t& operand, uint8_t value, int carry = 0) {
auto& a = A();
auto& f = F(); auto& f = F();
register16_t difference; register16_t difference;
difference.word = a - value - carry; difference.word = operand - value - carry;
adjustAuxiliaryCarrySub(f, a, value, difference.word); adjustAuxiliaryCarrySub(f, operand, value, difference.word);
a = difference.low; operand = difference.low;
setFlag(f, CF, difference.word & Bit8); setFlag(f, CF, difference.word & Bit8);
adjustSZP<Intel8080>(f, a); adjustSZP<Intel8080>(f, operand);
}
void sub(uint8_t value, int carry = 0) {
sub(A(), value, carry);
} }
void sbb(uint8_t value) { void sbb(uint8_t value) {

View File

@ -124,8 +124,6 @@ namespace EightBit {
void executeCB(int x, int y, int z, int p, int q); 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 executeOther(int x, int y, int z, int p, int q);
static void adjustZero(uint8_t& f, uint8_t value);
static void postIncrement(uint8_t& f, uint8_t value); static void postIncrement(uint8_t& f, uint8_t value);
static void postDecrement(uint8_t& f, uint8_t value); static void postDecrement(uint8_t& f, uint8_t value);

View File

@ -50,18 +50,14 @@ int EightBit::LR35902::interrupt(uint8_t value) {
#pragma region Flag manipulation helpers #pragma region Flag manipulation helpers
void EightBit::LR35902::adjustZero(uint8_t& f, uint8_t value) {
clearFlag(f, ZF, value);
}
void EightBit::LR35902::postIncrement(uint8_t& f, uint8_t value) { void EightBit::LR35902::postIncrement(uint8_t& f, uint8_t value) {
adjustZero(f, value); adjustZero<LR35902>(f, value);
clearFlag(f, NF); clearFlag(f, NF);
clearFlag(f, HC, lowNibble(value)); clearFlag(f, HC, lowNibble(value));
} }
void EightBit::LR35902::postDecrement(uint8_t& f, uint8_t value) { void EightBit::LR35902::postDecrement(uint8_t& f, uint8_t value) {
adjustZero(f, value); adjustZero<LR35902>(f, value);
setFlag(f, NF); setFlag(f, NF);
clearFlag(f, HC, lowNibble(value + 1)); clearFlag(f, HC, lowNibble(value + 1));
} }
@ -194,7 +190,7 @@ void EightBit::LR35902::add(uint8_t& operand, uint8_t value, int carry) {
clearFlag(f, NF); clearFlag(f, NF);
setFlag(f, CF, result.word & Bit8); setFlag(f, CF, result.word & Bit8);
adjustZero(f, operand); adjustZero<LR35902>(f, operand);
} }
void EightBit::LR35902::adc(uint8_t& operand, uint8_t value) { void EightBit::LR35902::adc(uint8_t& operand, uint8_t value) {
@ -214,7 +210,7 @@ void EightBit::LR35902::sub(uint8_t& operand, uint8_t value, int carry) {
setFlag(f, NF); setFlag(f, NF);
setFlag(f, CF, result.word & Bit8); setFlag(f, CF, result.word & Bit8);
adjustZero(f, operand); adjustZero<LR35902>(f, operand);
} }
void EightBit::LR35902::sbc(uint8_t& operand, uint8_t value) { void EightBit::LR35902::sbc(uint8_t& operand, uint8_t value) {
@ -226,21 +222,21 @@ void EightBit::LR35902::andr(uint8_t& operand, uint8_t value) {
operand &= value; operand &= value;
setFlag(f, HC); setFlag(f, HC);
clearFlag(f, CF | NF); clearFlag(f, CF | NF);
adjustZero(f, operand); adjustZero<LR35902>(f, operand);
} }
void EightBit::LR35902::xorr(uint8_t& operand, uint8_t value) { void EightBit::LR35902::xorr(uint8_t& operand, uint8_t value) {
auto& f = F(); auto& f = F();
operand ^= value; operand ^= value;
clearFlag(f, HC | CF | NF); clearFlag(f, HC | CF | NF);
adjustZero(f, operand); adjustZero<LR35902>(f, operand);
} }
void EightBit::LR35902::orr(uint8_t& operand, uint8_t value) { void EightBit::LR35902::orr(uint8_t& operand, uint8_t value) {
auto& f = F(); auto& f = F();
operand |= value; operand |= value;
clearFlag(f, HC | CF | NF); clearFlag(f, HC | CF | NF);
adjustZero(f, operand); adjustZero<LR35902>(f, operand);
} }
void EightBit::LR35902::compare(uint8_t value) { void EightBit::LR35902::compare(uint8_t value) {
@ -259,7 +255,7 @@ void EightBit::LR35902::rlc(uint8_t& operand) {
setFlag(f, CF, carry); setFlag(f, CF, carry);
carry ? operand |= Bit0 : operand &= ~Bit0; carry ? operand |= Bit0 : operand &= ~Bit0;
clearFlag(f, NF | HC); clearFlag(f, NF | HC);
adjustZero(f, operand); adjustZero<LR35902>(f, operand);
} }
void EightBit::LR35902::rrc(uint8_t& operand) { void EightBit::LR35902::rrc(uint8_t& operand) {
@ -269,7 +265,7 @@ void EightBit::LR35902::rrc(uint8_t& operand) {
carry ? operand |= Bit7 : operand &= ~Bit7; carry ? operand |= Bit7 : operand &= ~Bit7;
setFlag(f, CF, carry); setFlag(f, CF, carry);
clearFlag(f, NF | HC); clearFlag(f, NF | HC);
adjustZero(f, operand); adjustZero<LR35902>(f, operand);
} }
void EightBit::LR35902::rl(uint8_t& operand) { void EightBit::LR35902::rl(uint8_t& operand) {
@ -280,7 +276,7 @@ void EightBit::LR35902::rl(uint8_t& operand) {
oldCarry ? operand |= Bit0 : operand &= ~Bit0; oldCarry ? operand |= Bit0 : operand &= ~Bit0;
setFlag(f, CF, newCarry); setFlag(f, CF, newCarry);
clearFlag(f, NF | HC); clearFlag(f, NF | HC);
adjustZero(f, operand); adjustZero<LR35902>(f, operand);
} }
void EightBit::LR35902::rr(uint8_t& operand) { void EightBit::LR35902::rr(uint8_t& operand) {
@ -291,7 +287,7 @@ void EightBit::LR35902::rr(uint8_t& operand) {
operand |= oldCarry << 7; operand |= oldCarry << 7;
setFlag(f, CF, newCarry); setFlag(f, CF, newCarry);
clearFlag(f, NF | HC); clearFlag(f, NF | HC);
adjustZero(f, operand); adjustZero<LR35902>(f, operand);
} }
// //
@ -302,7 +298,7 @@ void EightBit::LR35902::sla(uint8_t& operand) {
operand <<= 1; operand <<= 1;
setFlag(f, CF, newCarry); setFlag(f, CF, newCarry);
clearFlag(f, NF | HC); clearFlag(f, NF | HC);
adjustZero(f, operand); adjustZero<LR35902>(f, operand);
} }
void EightBit::LR35902::sra(uint8_t& operand) { void EightBit::LR35902::sra(uint8_t& operand) {
@ -313,7 +309,7 @@ void EightBit::LR35902::sra(uint8_t& operand) {
operand |= new7; operand |= new7;
setFlag(f, CF, newCarry); setFlag(f, CF, newCarry);
clearFlag(f, NF | HC); clearFlag(f, NF | HC);
adjustZero(f, operand); adjustZero<LR35902>(f, operand);
} }
void EightBit::LR35902::srl(uint8_t& operand) { void EightBit::LR35902::srl(uint8_t& operand) {
@ -323,7 +319,7 @@ void EightBit::LR35902::srl(uint8_t& operand) {
operand &= ~Bit7; // clear bit 7 operand &= ~Bit7; // clear bit 7
setFlag(f, CF, newCarry); setFlag(f, CF, newCarry);
clearFlag(f, NF | HC); clearFlag(f, NF | HC);
adjustZero(f, operand); adjustZero<LR35902>(f, operand);
} }
#pragma endregion Shift and rotate #pragma endregion Shift and rotate
@ -375,7 +371,7 @@ void EightBit::LR35902::daa() {
f = (f & (CF | NF)) | (A() > 0x99) | ((A() ^ a) & HC); f = (f & (CF | NF)) | (A() > 0x99) | ((A() ^ a) & HC);
adjustZero(f, a); adjustZero<LR35902>(f, a);
A() = a; A() = a;
} }
@ -404,7 +400,7 @@ void EightBit::LR35902::swap(uint8_t& operand) {
auto low = lowNibble(operand); auto low = lowNibble(operand);
auto high = highNibble(operand); auto high = highNibble(operand);
operand = promoteNibble(low) | demoteNibble(high); operand = promoteNibble(low) | demoteNibble(high);
adjustZero(f, operand); adjustZero<LR35902>(f, operand);
clearFlag(f, NF | HC | CF); clearFlag(f, NF | HC | CF);
} }
@ -466,7 +462,7 @@ void EightBit::LR35902::executeCB(int x, int y, int z, int p, int q) {
srl(R(z)); srl(R(z));
break; break;
} }
adjustZero(F(), R(z)); adjustZero<LR35902>(F(), R(z));
cycles += 2; cycles += 2;
if (z == 6) if (z == 6)
cycles += 2; cycles += 2;

View File

@ -356,10 +356,9 @@ void EightBit::Z80::orr(uint8_t& operand, uint8_t value) {
} }
void EightBit::Z80::compare(uint8_t value) { void EightBit::Z80::compare(uint8_t value) {
auto& f = F();
auto check = A(); auto check = A();
sub(check, value); sub(check, value);
adjustXY<Z80>(f, value); adjustXY<Z80>(F(), value);
} }
#pragma endregion ALU #pragma endregion ALU