From 1ee9a010b5d38b740c2c2cd0711902b172d240bd Mon Sep 17 00:00:00 2001 From: "Adrian.Conlon" Date: Thu, 20 Jul 2017 10:42:18 +0100 Subject: [PATCH] Finally: a working daa Signed-off-by: Adrian.Conlon --- LR35902/src/LR35902.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/LR35902/src/LR35902.cpp b/LR35902/src/LR35902.cpp index 7ee6a87..9f7bcf4 100644 --- a/LR35902/src/LR35902.cpp +++ b/LR35902/src/LR35902.cpp @@ -320,25 +320,23 @@ void EightBit::LR35902::set(int n, uint8_t& operand) { void EightBit::LR35902::daa(uint8_t& a, uint8_t& f) { - auto updated = a; - - auto lowAdjust = (f & HC) | (lowNibble(a) > 9); - auto highAdjust = (f & CF) | (a > 0x99); + int updated = a; if (f & NF) { - if (lowAdjust) - updated -= 6; - if (highAdjust) + if (f & HC) + updated = (updated - 6) & Mask8; + if (f & CF) updated -= 0x60; } else { - if (lowAdjust) + if ((f & HC) || lowNibble(updated) > 9) updated += 6; - if (highAdjust) + if ((f & CF) || updated > 0x9F) updated += 0x60; } - f = (f & (CF | NF)) | (a > 0x99) | ((a ^ updated) & HC); - a = updated; + clearFlag(f, HC | ZF); + setFlag(f, CF, (f & CF) || (updated & Bit8)); + a = updated & Mask8; adjustZero(f, a); }