Finally: a working daa

Signed-off-by: Adrian.Conlon <adrian.conlon@gmail.com>
This commit is contained in:
Adrian.Conlon
2017-07-20 10:42:18 +01:00
parent 9c240b7ea8
commit 1ee9a010b5

View File

@@ -320,25 +320,23 @@ void EightBit::LR35902::set(int n, uint8_t& operand) {
void EightBit::LR35902::daa(uint8_t& a, uint8_t& f) { void EightBit::LR35902::daa(uint8_t& a, uint8_t& f) {
auto updated = a; int updated = a;
auto lowAdjust = (f & HC) | (lowNibble(a) > 9);
auto highAdjust = (f & CF) | (a > 0x99);
if (f & NF) { if (f & NF) {
if (lowAdjust) if (f & HC)
updated -= 6; updated = (updated - 6) & Mask8;
if (highAdjust) if (f & CF)
updated -= 0x60; updated -= 0x60;
} else { } else {
if (lowAdjust) if ((f & HC) || lowNibble(updated) > 9)
updated += 6; updated += 6;
if (highAdjust) if ((f & CF) || updated > 0x9F)
updated += 0x60; updated += 0x60;
} }
f = (f & (CF | NF)) | (a > 0x99) | ((a ^ updated) & HC); clearFlag(f, HC | ZF);
a = updated; setFlag(f, CF, (f & CF) || (updated & Bit8));
a = updated & Mask8;
adjustZero<LR35902>(f, a); adjustZero<LR35902>(f, a);
} }