Bring the LR35902 and i8080 increment/decrement implementations in line with the Z80.

Signed-off-by: Adrian.Conlon <adrian.conlon@gmail.com>
This commit is contained in:
Adrian.Conlon 2017-07-22 10:23:13 +01:00
parent 19966f6ad8
commit 9a264c7c06
3 changed files with 32 additions and 36 deletions

View File

@ -90,14 +90,14 @@ namespace EightBit {
clearFlag(f, AC, calculateHalfCarrySub(before, value, calculation));
}
static void postIncrement(uint8_t& f, uint8_t value) {
adjustSZP<Intel8080>(f, value);
clearFlag(f, AC, lowNibble(value));
static void increment(uint8_t& f, uint8_t& operand) {
adjustSZP<Intel8080>(f, ++operand);
clearFlag(f, AC, lowNibble(operand));
}
static void postDecrement(uint8_t& f, uint8_t value) {
adjustSZP<Intel8080>(f, value);
setFlag(f, AC, lowNibble(value) != Mask4);
static void decrement(uint8_t& f, uint8_t& operand) {
adjustSZP<Intel8080>(f, --operand);
setFlag(f, AC, lowNibble(operand) != Mask4);
}
static Instruction INS(instruction_t method, AddressingMode mode, std::string disassembly, int cycles);
@ -420,34 +420,30 @@ namespace EightBit {
// increment and decrement
void inr_a() { postIncrement(F(), ++A()); }
void inr_b() { postIncrement(F(), ++B()); }
void inr_c() { postIncrement(F(), ++C()); }
void inr_d() { postIncrement(F(), ++D()); }
void inr_e() { postIncrement(F(), ++E()); }
void inr_h() { postIncrement(F(), ++H()); }
void inr_l() { postIncrement(F(), ++L()); }
void inr_a() { increment(F(), A()); }
void inr_b() { increment(F(), B()); }
void inr_c() { increment(F(), C()); }
void inr_d() { increment(F(), D()); }
void inr_e() { increment(F(), E()); }
void inr_h() { increment(F(), H()); }
void inr_l() { increment(F(), L()); }
void inr_m() {
m_memory.ADDRESS() = HL();
auto value = m_memory.reference();
postIncrement(F(), ++value);
m_memory.reference() = value;
increment(F(), m_memory.reference());
}
void dcr_a() { postDecrement(F(), --A()); }
void dcr_b() { postDecrement(F(), --B()); }
void dcr_c() { postDecrement(F(), --C()); }
void dcr_d() { postDecrement(F(), --D()); }
void dcr_e() { postDecrement(F(), --E()); }
void dcr_h() { postDecrement(F(), --H()); }
void dcr_l() { postDecrement(F(), --L()); }
void dcr_a() { decrement(F(), A()); }
void dcr_b() { decrement(F(), B()); }
void dcr_c() { decrement(F(), C()); }
void dcr_d() { decrement(F(), D()); }
void dcr_e() { decrement(F(), E()); }
void dcr_h() { decrement(F(), H()); }
void dcr_l() { decrement(F(), L()); }
void dcr_m() {
m_memory.ADDRESS() = HL();
auto value = m_memory.reference();
postDecrement(F(), --value);
m_memory.reference() = value;
decrement(F(), m_memory.reference());
}
void inx_b() { ++BC().word; }

View File

@ -162,8 +162,8 @@ 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 postIncrement(uint8_t& f, uint8_t value);
static void postDecrement(uint8_t& f, uint8_t value);
static void increment(uint8_t& f, uint8_t& operand);
static void decrement(uint8_t& f, uint8_t& operand);
void reti();

View File

@ -51,16 +51,16 @@ int EightBit::LR35902::interrupt(uint8_t value) {
#pragma region Flag manipulation helpers
void EightBit::LR35902::postIncrement(uint8_t& f, uint8_t value) {
adjustZero<LR35902>(f, value);
void EightBit::LR35902::increment(uint8_t& f, uint8_t& operand) {
clearFlag(f, NF);
clearFlag(f, HC, lowNibble(value));
adjustZero<LR35902>(f, ++operand);
clearFlag(f, HC, lowNibble(operand));
}
void EightBit::LR35902::postDecrement(uint8_t& f, uint8_t value) {
adjustZero<LR35902>(f, value);
void EightBit::LR35902::decrement(uint8_t& f, uint8_t& operand) {
setFlag(f, NF);
clearFlag(f, HC, lowNibble(value + 1));
clearFlag(f, HC, lowNibble(operand));
adjustZero<LR35902>(f, --operand);
}
#pragma endregion Flag manipulation helpers
@ -573,7 +573,7 @@ void EightBit::LR35902::executeOther(int x, int y, int z, int p, int q) {
cycles += 2;
break;
case 4: // 8-bit INC
postIncrement(f, ++R(y, a)); // INC r
increment(f, R(y, a)); // INC r
cycles++;
if (y == 6) {
m_bus.fireWriteBusEvent();
@ -581,7 +581,7 @@ void EightBit::LR35902::executeOther(int x, int y, int z, int p, int q) {
}
break;
case 5: // 8-bit DEC
postDecrement(f, --R(y, a)); // DEC r
decrement(f, R(y, a)); // DEC r
cycles++;
if (y == 6) {
m_bus.fireWriteBusEvent();