LR35902: Mostly fix DAA
Jeffrey Pfau jeffrey@endrift.com
Thu, 21 Jan 2016 00:59:59 -0800
1 files changed,
16 insertions(+),
7 deletions(-)
jump to
M
src/lr35902/isa-lr35902.c
→
src/lr35902/isa-lr35902.c
@@ -590,14 +590,23 @@ cpu->f.h = 1;
cpu->f.n = 1;) DEFINE_INSTRUCTION_LR35902(DAA, - if ((cpu->a & 0xF) > 0x9 || cpu->f.h) { - cpu->a += 0x6; - } - if ((cpu->a & 0xF0) > 0x90 || cpu->f.c) { - cpu->a += 0x60; - cpu->f.c = 1; + if (cpu->f.n) { + if (cpu->f.h) { + cpu->a += 0xFA; + } + if (cpu->f.c) { + cpu->a += 0xA0; + } } else { - cpu->f.c = 0; + if ((cpu->a & 0xF) > 0x9 || cpu->f.h) { + cpu->a += 0x6; + } + if ((cpu->a & 0xF0) > 0x90 || cpu->f.c) { + cpu->a += 0x60; + cpu->f.c = 1; + } else { + cpu->f.c = 0; + } } cpu->f.h = 0; cpu->f.z = !cpu->a;)