all repos — mgba @ c0b965a41ed22373b76cc6bd8d23e0ff3bdf9c99

mGBA Game Boy Advance Emulator

LR35902: Fix a ton of Z flags
Jeffrey Pfau jeffrey@endrift.com
Wed, 20 Jan 2016 22:57:49 -0800
commit

c0b965a41ed22373b76cc6bd8d23e0ff3bdf9c99

parent

6c399882f9f07dfb959f84f5a0e364b7188f85b1

1 files changed, 9 insertions(+), 9 deletions(-)

jump to
M src/lr35902/isa-lr35902.csrc/lr35902/isa-lr35902.c

@@ -158,7 +158,7 @@ #define DEFINE_CP_INSTRUCTION_LR35902(NAME, OPERAND) \

DEFINE_INSTRUCTION_LR35902(CP ## NAME, \ int diff = cpu->a - OPERAND; \ cpu->f.n = 1; \ - cpu->f.z = !diff; \ + cpu->f.z = !(diff & 0xFF); \ cpu->f.h = (cpu->a & 0xF) - (OPERAND & 0xF) < 0; \ cpu->f.c = diff < 0;)

@@ -265,7 +265,7 @@ DEFINE_INSTRUCTION_LR35902(ADD ## NAME, \

int diff = cpu->a + OPERAND; \ cpu->a = diff; \ cpu->f.n = 0; \ - cpu->f.z = !diff; \ + cpu->f.z = !cpu->a; \ cpu->f.h = (cpu->a & 0xF) + (OPERAND & 0xF) >= 0x10; \ cpu->f.c = diff >= 0x100;)

@@ -274,7 +274,7 @@ DEFINE_INSTRUCTION_LR35902(ADC ## NAME, \

int diff = cpu->a + OPERAND + cpu->f.c; \ cpu->a = diff; \ cpu->f.n = 0; \ - cpu->f.z = !diff; \ + cpu->f.z = !cpu->a; \ cpu->f.h = (cpu->a & 0xF) + ((OPERAND + cpu->f.c) & 0xF) >= 0x10; \ cpu->f.c = diff > 0x100;)

@@ -283,7 +283,7 @@ DEFINE_INSTRUCTION_LR35902(SUB ## NAME, \

int diff = cpu->a - OPERAND; \ cpu->a = diff; \ cpu->f.n = 1; \ - cpu->f.z = !diff; \ + cpu->f.z = !cpu->a; \ cpu->f.h = (cpu->a & 0xF) - (OPERAND & 0xF) < 0; \ cpu->f.c = diff < 0;)

@@ -292,7 +292,7 @@ DEFINE_INSTRUCTION_LR35902(SBC ## NAME, \

int diff = cpu->a - OPERAND - cpu->f.c; \ cpu->a = diff; \ cpu->f.n = 1; \ - cpu->f.z = !diff; \ + cpu->f.z = !cpu->a; \ cpu->f.h = (cpu->a & 0xF) - ((OPERAND + cpu->f.c) & 0xF) < 0; \ cpu->f.c = diff < 0;)

@@ -524,7 +524,7 @@ DEFINE_INSTRUCTION_LR35902(INC ## NAME, \

int diff = OPERAND + 1; \ OPERAND = diff; \ cpu->f.n = 0; \ - cpu->f.z = !diff; \ + cpu->f.z = !OPERAND; \ /* TODO: Find explanation of H flag */) #define DEFINE_DEC_INSTRUCTION_LR35902(NAME, OPERAND) \

@@ -532,7 +532,7 @@ DEFINE_INSTRUCTION_LR35902(DEC ## NAME, \

int diff = OPERAND - 1; \ OPERAND = diff; \ cpu->f.n = 1; \ - cpu->f.z = !diff; \ + cpu->f.z = !OPERAND; \ /* TODO: Find explanation of H flag */) DEFINE_ALU_INSTRUCTION_LR35902_NOHL(INC);

@@ -542,7 +542,7 @@ DEFINE_INSTRUCTION_LR35902(INC_HLDelay,

int diff = cpu->bus + 1; cpu->bus = diff; cpu->f.n = 0; - cpu->f.z = !diff; + cpu->f.z = !cpu->bus; cpu->f.h = (cpu->bus & 0xF) == 0xF; cpu->instruction = _LR35902InstructionNOP; cpu->executionState = LR35902_CORE_MEMORY_STORE;)

@@ -556,7 +556,7 @@ DEFINE_INSTRUCTION_LR35902(DEC_HLDelay,

int diff = cpu->bus - 1; cpu->bus = diff; cpu->f.n = 1; - cpu->f.z = !diff; + cpu->f.z = !cpu->bus; cpu->f.h = (cpu->bus & 0xF) == 0; cpu->instruction = _LR35902InstructionNOP; cpu->executionState = LR35902_CORE_MEMORY_STORE;)