mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2024-12-23 15:29:24 +00:00
Some more shared code.
Signed-off-by: Adrian.Conlon <adrian.conlon@gmail.com>
This commit is contained in:
parent
f776379e96
commit
af375ab10f
@ -109,12 +109,8 @@ namespace EightBit {
|
||||
//
|
||||
|
||||
void compare(uint8_t value) {
|
||||
const auto& a = A();
|
||||
auto& f = F();
|
||||
uint16_t subtraction = a - value;
|
||||
adjustSZP<Intel8080>(f, (uint8_t)subtraction);
|
||||
adjustAuxiliaryCarrySub(f, a, value, subtraction);
|
||||
setFlag(f, CF, subtraction & Bit8);
|
||||
auto check = A();
|
||||
sub(check, value);
|
||||
}
|
||||
|
||||
void anda(uint8_t value) {
|
||||
@ -159,15 +155,18 @@ namespace EightBit {
|
||||
HL().word = (uint16_t)sum;
|
||||
}
|
||||
|
||||
void sub(uint8_t value, int carry = 0) {
|
||||
auto& a = A();
|
||||
void sub(uint8_t& operand, uint8_t value, int carry = 0) {
|
||||
auto& f = F();
|
||||
register16_t difference;
|
||||
difference.word = a - value - carry;
|
||||
adjustAuxiliaryCarrySub(f, a, value, difference.word);
|
||||
a = difference.low;
|
||||
difference.word = operand - value - carry;
|
||||
adjustAuxiliaryCarrySub(f, operand, value, difference.word);
|
||||
operand = difference.low;
|
||||
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) {
|
||||
|
@ -124,8 +124,6 @@ namespace EightBit {
|
||||
void executeCB(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 postDecrement(uint8_t& f, uint8_t value);
|
||||
|
||||
|
@ -50,18 +50,14 @@ int EightBit::LR35902::interrupt(uint8_t value) {
|
||||
|
||||
#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) {
|
||||
adjustZero(f, value);
|
||||
adjustZero<LR35902>(f, value);
|
||||
clearFlag(f, NF);
|
||||
clearFlag(f, HC, lowNibble(value));
|
||||
}
|
||||
|
||||
void EightBit::LR35902::postDecrement(uint8_t& f, uint8_t value) {
|
||||
adjustZero(f, value);
|
||||
adjustZero<LR35902>(f, value);
|
||||
setFlag(f, NF);
|
||||
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);
|
||||
setFlag(f, CF, result.word & Bit8);
|
||||
adjustZero(f, operand);
|
||||
adjustZero<LR35902>(f, operand);
|
||||
}
|
||||
|
||||
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, CF, result.word & Bit8);
|
||||
adjustZero(f, operand);
|
||||
adjustZero<LR35902>(f, operand);
|
||||
}
|
||||
|
||||
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;
|
||||
setFlag(f, HC);
|
||||
clearFlag(f, CF | NF);
|
||||
adjustZero(f, operand);
|
||||
adjustZero<LR35902>(f, operand);
|
||||
}
|
||||
|
||||
void EightBit::LR35902::xorr(uint8_t& operand, uint8_t value) {
|
||||
auto& f = F();
|
||||
operand ^= value;
|
||||
clearFlag(f, HC | CF | NF);
|
||||
adjustZero(f, operand);
|
||||
adjustZero<LR35902>(f, operand);
|
||||
}
|
||||
|
||||
void EightBit::LR35902::orr(uint8_t& operand, uint8_t value) {
|
||||
auto& f = F();
|
||||
operand |= value;
|
||||
clearFlag(f, HC | CF | NF);
|
||||
adjustZero(f, operand);
|
||||
adjustZero<LR35902>(f, operand);
|
||||
}
|
||||
|
||||
void EightBit::LR35902::compare(uint8_t value) {
|
||||
@ -259,7 +255,7 @@ void EightBit::LR35902::rlc(uint8_t& operand) {
|
||||
setFlag(f, CF, carry);
|
||||
carry ? operand |= Bit0 : operand &= ~Bit0;
|
||||
clearFlag(f, NF | HC);
|
||||
adjustZero(f, operand);
|
||||
adjustZero<LR35902>(f, operand);
|
||||
}
|
||||
|
||||
void EightBit::LR35902::rrc(uint8_t& operand) {
|
||||
@ -269,7 +265,7 @@ void EightBit::LR35902::rrc(uint8_t& operand) {
|
||||
carry ? operand |= Bit7 : operand &= ~Bit7;
|
||||
setFlag(f, CF, carry);
|
||||
clearFlag(f, NF | HC);
|
||||
adjustZero(f, operand);
|
||||
adjustZero<LR35902>(f, operand);
|
||||
}
|
||||
|
||||
void EightBit::LR35902::rl(uint8_t& operand) {
|
||||
@ -280,7 +276,7 @@ void EightBit::LR35902::rl(uint8_t& operand) {
|
||||
oldCarry ? operand |= Bit0 : operand &= ~Bit0;
|
||||
setFlag(f, CF, newCarry);
|
||||
clearFlag(f, NF | HC);
|
||||
adjustZero(f, operand);
|
||||
adjustZero<LR35902>(f, operand);
|
||||
}
|
||||
|
||||
void EightBit::LR35902::rr(uint8_t& operand) {
|
||||
@ -291,7 +287,7 @@ void EightBit::LR35902::rr(uint8_t& operand) {
|
||||
operand |= oldCarry << 7;
|
||||
setFlag(f, CF, newCarry);
|
||||
clearFlag(f, NF | HC);
|
||||
adjustZero(f, operand);
|
||||
adjustZero<LR35902>(f, operand);
|
||||
}
|
||||
|
||||
//
|
||||
@ -302,7 +298,7 @@ void EightBit::LR35902::sla(uint8_t& operand) {
|
||||
operand <<= 1;
|
||||
setFlag(f, CF, newCarry);
|
||||
clearFlag(f, NF | HC);
|
||||
adjustZero(f, operand);
|
||||
adjustZero<LR35902>(f, operand);
|
||||
}
|
||||
|
||||
void EightBit::LR35902::sra(uint8_t& operand) {
|
||||
@ -313,7 +309,7 @@ void EightBit::LR35902::sra(uint8_t& operand) {
|
||||
operand |= new7;
|
||||
setFlag(f, CF, newCarry);
|
||||
clearFlag(f, NF | HC);
|
||||
adjustZero(f, operand);
|
||||
adjustZero<LR35902>(f, operand);
|
||||
}
|
||||
|
||||
void EightBit::LR35902::srl(uint8_t& operand) {
|
||||
@ -323,7 +319,7 @@ void EightBit::LR35902::srl(uint8_t& operand) {
|
||||
operand &= ~Bit7; // clear bit 7
|
||||
setFlag(f, CF, newCarry);
|
||||
clearFlag(f, NF | HC);
|
||||
adjustZero(f, operand);
|
||||
adjustZero<LR35902>(f, operand);
|
||||
}
|
||||
|
||||
#pragma endregion Shift and rotate
|
||||
@ -375,7 +371,7 @@ void EightBit::LR35902::daa() {
|
||||
|
||||
f = (f & (CF | NF)) | (A() > 0x99) | ((A() ^ a) & HC);
|
||||
|
||||
adjustZero(f, a);
|
||||
adjustZero<LR35902>(f, a);
|
||||
|
||||
A() = a;
|
||||
}
|
||||
@ -404,7 +400,7 @@ void EightBit::LR35902::swap(uint8_t& operand) {
|
||||
auto low = lowNibble(operand);
|
||||
auto high = highNibble(operand);
|
||||
operand = promoteNibble(low) | demoteNibble(high);
|
||||
adjustZero(f, operand);
|
||||
adjustZero<LR35902>(f, operand);
|
||||
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));
|
||||
break;
|
||||
}
|
||||
adjustZero(F(), R(z));
|
||||
adjustZero<LR35902>(F(), R(z));
|
||||
cycles += 2;
|
||||
if (z == 6)
|
||||
cycles += 2;
|
||||
|
@ -356,10 +356,9 @@ void EightBit::Z80::orr(uint8_t& operand, uint8_t value) {
|
||||
}
|
||||
|
||||
void EightBit::Z80::compare(uint8_t value) {
|
||||
auto& f = F();
|
||||
auto check = A();
|
||||
sub(check, value);
|
||||
adjustXY<Z80>(f, value);
|
||||
adjustXY<Z80>(F(), value);
|
||||
}
|
||||
|
||||
#pragma endregion ALU
|
||||
|
Loading…
Reference in New Issue
Block a user