LR35902: Implement remaining ALU instructions

This commit is contained in:
Jeffrey Pfau 2016-01-17 01:47:33 -08:00
parent 76c41a62ba
commit 7a104c07a7
2 changed files with 76 additions and 36 deletions

View File

@ -138,38 +138,38 @@
DECLARE_INSTRUCTION_LR35902(EMITTER, LDA_L), \
DECLARE_INSTRUCTION_LR35902(EMITTER, LDA_HL), \
DECLARE_INSTRUCTION_LR35902(EMITTER, LDA_A), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, ADDB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, ADDC), \
DECLARE_INSTRUCTION_LR35902(EMITTER, ADDD), \
DECLARE_INSTRUCTION_LR35902(EMITTER, ADDE), \
DECLARE_INSTRUCTION_LR35902(EMITTER, ADDH), \
DECLARE_INSTRUCTION_LR35902(EMITTER, ADDL), \
DECLARE_INSTRUCTION_LR35902(EMITTER, ADDHL), \
DECLARE_INSTRUCTION_LR35902(EMITTER, ADDA), \
DECLARE_INSTRUCTION_LR35902(EMITTER, ADCB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, ADCC), \
DECLARE_INSTRUCTION_LR35902(EMITTER, ADCD), \
DECLARE_INSTRUCTION_LR35902(EMITTER, ADCE), \
DECLARE_INSTRUCTION_LR35902(EMITTER, ADCH), \
DECLARE_INSTRUCTION_LR35902(EMITTER, ADCL), \
DECLARE_INSTRUCTION_LR35902(EMITTER, ADCHL), \
DECLARE_INSTRUCTION_LR35902(EMITTER, ADCA), \
DECLARE_INSTRUCTION_LR35902(EMITTER, SUBB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, SUBC), \
DECLARE_INSTRUCTION_LR35902(EMITTER, SUBD), \
DECLARE_INSTRUCTION_LR35902(EMITTER, SUBE), \
DECLARE_INSTRUCTION_LR35902(EMITTER, SUBH), \
DECLARE_INSTRUCTION_LR35902(EMITTER, SUBL), \
DECLARE_INSTRUCTION_LR35902(EMITTER, SUBHL), \
DECLARE_INSTRUCTION_LR35902(EMITTER, SUBA), \
DECLARE_INSTRUCTION_LR35902(EMITTER, SBCB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, SBCC), \
DECLARE_INSTRUCTION_LR35902(EMITTER, SBCD), \
DECLARE_INSTRUCTION_LR35902(EMITTER, SBCE), \
DECLARE_INSTRUCTION_LR35902(EMITTER, SBCH), \
DECLARE_INSTRUCTION_LR35902(EMITTER, SBCL), \
DECLARE_INSTRUCTION_LR35902(EMITTER, SBCHL), \
DECLARE_INSTRUCTION_LR35902(EMITTER, SBCA), \
DECLARE_INSTRUCTION_LR35902(EMITTER, ANDB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, ANDC), \
DECLARE_INSTRUCTION_LR35902(EMITTER, ANDD), \
@ -208,7 +208,7 @@
DECLARE_INSTRUCTION_LR35902(EMITTER, JP), \
DECLARE_INSTRUCTION_LR35902(EMITTER, CALLNZ), \
DECLARE_INSTRUCTION_LR35902(EMITTER, PUSHBC), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, ADD), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, RETZ), \
DECLARE_INSTRUCTION_LR35902(EMITTER, RET), \
@ -216,7 +216,7 @@
DECLARE_INSTRUCTION_LR35902(EMITTER, CB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, CALLZ), \
DECLARE_INSTRUCTION_LR35902(EMITTER, CALL), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, ADC), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, RETNC), \
DECLARE_INSTRUCTION_LR35902(EMITTER, POPDE), \
@ -224,7 +224,7 @@
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, CALLNC), \
DECLARE_INSTRUCTION_LR35902(EMITTER, PUSHDE), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, SUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, RETC), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
@ -232,7 +232,7 @@
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, CALLC), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, SBC), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, LDIOA), \
DECLARE_INSTRUCTION_LR35902(EMITTER, POPHL), \

View File

@ -235,6 +235,42 @@ static void _LR35902InstructionLDL_Bus(struct LR35902Core*);
static void _LR35902InstructionLDHL_Bus(struct LR35902Core*);
static void _LR35902InstructionLDA_Bus(struct LR35902Core*);
#define DEFINE_ADD_INSTRUCTION_LR35902(NAME, OPERAND) \
DEFINE_INSTRUCTION_LR35902(ADD ## NAME, \
int diff = cpu->a + OPERAND; \
cpu->a = diff; \
cpu->f.n = 0; \
cpu->f.z = !diff; \
cpu->f.c = diff >= 0x100; \
/* TODO: Find explanation of H flag */)
#define DEFINE_ADC_INSTRUCTION_LR35902(NAME, OPERAND) \
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.c = diff > 0x100; \
/* TODO: Find explanation of H flag */)
#define DEFINE_SUB_INSTRUCTION_LR35902(NAME, OPERAND) \
DEFINE_INSTRUCTION_LR35902(SUB ## NAME, \
int diff = cpu->a - OPERAND; \
cpu->a = diff; \
cpu->f.n = 1; \
cpu->f.z = !diff; \
cpu->f.c = diff < 0; \
/* TODO: Find explanation of H flag */)
#define DEFINE_SBC_INSTRUCTION_LR35902(NAME, OPERAND) \
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.c = diff < 0; \
/* TODO: Find explanation of H flag */)
DEFINE_ALU_INSTRUCTION_LR35902(LDB_);
DEFINE_ALU_INSTRUCTION_LR35902(LDC_);
DEFINE_ALU_INSTRUCTION_LR35902(LDD_);
@ -245,6 +281,10 @@ DEFINE_ALU_INSTRUCTION_LR35902_NOHL(LDHL_);
DEFINE_ALU_INSTRUCTION_LR35902(LDA_);
DEFINE_ALU_INSTRUCTION_LR35902_MEM(LDA_, BC);
DEFINE_ALU_INSTRUCTION_LR35902_MEM(LDA_, DE);
DEFINE_ALU_INSTRUCTION_LR35902(ADD);
DEFINE_ALU_INSTRUCTION_LR35902(ADC);
DEFINE_ALU_INSTRUCTION_LR35902(SUB);
DEFINE_ALU_INSTRUCTION_LR35902(SBC);
DEFINE_INSTRUCTION_LR35902(LDBCDelay, \
cpu->c = cpu->bus; \