all repos — mgba @ a8b473870df67c9a7ae0e9f21d9b2fd5862ae507

mGBA Game Boy Advance Emulator

LR35902: Mostly fix DAA
Jeffrey Pfau jeffrey@endrift.com
Thu, 21 Jan 2016 00:59:59 -0800
commit

a8b473870df67c9a7ae0e9f21d9b2fd5862ae507

parent

6ab3bdcc461e9348c30689775cc6a7fc619ce70f

1 files changed, 16 insertions(+), 7 deletions(-)

jump to
M src/lr35902/isa-lr35902.csrc/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;)