diff --git a/src/lr35902/emitter-lr35902.h b/src/lr35902/emitter-lr35902.h index e27ad41c5..80433b9a9 100644 --- a/src/lr35902/emitter-lr35902.h +++ b/src/lr35902/emitter-lr35902.h @@ -14,23 +14,23 @@ DECLARE_INSTRUCTION_LR35902(EMITTER, LDBC), \ DECLARE_INSTRUCTION_LR35902(EMITTER, LDBC_A), \ DECLARE_INSTRUCTION_LR35902(EMITTER, INCBC), \ - DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ - DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ + DECLARE_INSTRUCTION_LR35902(EMITTER, INCB), \ + DECLARE_INSTRUCTION_LR35902(EMITTER, DECB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, LDB_), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, DECBC), \ - DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ - DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ + DECLARE_INSTRUCTION_LR35902(EMITTER, INCC), \ + DECLARE_INSTRUCTION_LR35902(EMITTER, DECC), \ DECLARE_INSTRUCTION_LR35902(EMITTER, LDC_), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, LDDE), \ DECLARE_INSTRUCTION_LR35902(EMITTER, LDDE_A), \ DECLARE_INSTRUCTION_LR35902(EMITTER, INCDE), \ - DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ - DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ + DECLARE_INSTRUCTION_LR35902(EMITTER, INCD), \ + DECLARE_INSTRUCTION_LR35902(EMITTER, DECD), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, LDD_), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ @@ -38,40 +38,40 @@ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, DECDE), \ - DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ - DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ + DECLARE_INSTRUCTION_LR35902(EMITTER, INCE), \ + DECLARE_INSTRUCTION_LR35902(EMITTER, DECE), \ DECLARE_INSTRUCTION_LR35902(EMITTER, LDE_), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, JRNZ), \ DECLARE_INSTRUCTION_LR35902(EMITTER, LDHL), \ DECLARE_INSTRUCTION_LR35902(EMITTER, LDIHLA), \ DECLARE_INSTRUCTION_LR35902(EMITTER, INCHL), \ - DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ - DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ + DECLARE_INSTRUCTION_LR35902(EMITTER, INCH), \ + DECLARE_INSTRUCTION_LR35902(EMITTER, DECH), \ DECLARE_INSTRUCTION_LR35902(EMITTER, LDH_), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, JRZ), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, DECHL), \ - DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ - DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ + DECLARE_INSTRUCTION_LR35902(EMITTER, INCL), \ + DECLARE_INSTRUCTION_LR35902(EMITTER, DECL), \ DECLARE_INSTRUCTION_LR35902(EMITTER, LDL_), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, JRNC), \ DECLARE_INSTRUCTION_LR35902(EMITTER, LDSP), \ DECLARE_INSTRUCTION_LR35902(EMITTER, LDDHLA), \ DECLARE_INSTRUCTION_LR35902(EMITTER, INCSP), \ - DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ - DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ + DECLARE_INSTRUCTION_LR35902(EMITTER, INC_HL), \ + DECLARE_INSTRUCTION_LR35902(EMITTER, DEC_HL), \ DECLARE_INSTRUCTION_LR35902(EMITTER, LDHL_), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, JRC), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, DECSP), \ - DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ - DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ + DECLARE_INSTRUCTION_LR35902(EMITTER, INCA), \ + DECLARE_INSTRUCTION_LR35902(EMITTER, DECA), \ DECLARE_INSTRUCTION_LR35902(EMITTER, LDA_), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, LDB_B), \ @@ -243,7 +243,7 @@ DECLARE_INSTRUCTION_LR35902(EMITTER, AND), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ - DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ + DECLARE_INSTRUCTION_LR35902(EMITTER, JPHL), \ DECLARE_INSTRUCTION_LR35902(EMITTER, LDIA), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ diff --git a/src/lr35902/isa-lr35902.c b/src/lr35902/isa-lr35902.c index f81ff6b9b..2ffebf534 100644 --- a/src/lr35902/isa-lr35902.c +++ b/src/lr35902/isa-lr35902.c @@ -43,6 +43,10 @@ DEFINE_INSTRUCTION_LR35902(JPDelay, DEFINE_CONDITIONAL_INSTRUCTION_LR35902(JP); +DEFINE_INSTRUCTION_LR35902(JPHL, + cpu->pc = LR35902ReadHL(cpu); + cpu->memory.setActiveRegion(cpu, cpu->pc);) + DEFINE_INSTRUCTION_LR35902(JRFinish, if (cpu->condition) { cpu->pc += (int8_t) cpu->bus; @@ -360,7 +364,7 @@ DEFINE_INSTRUCTION_LR35902(LDIOA, \ cpu->executionState = LR35902_CORE_READ_PC; \ cpu->instruction = _LR35902InstructionLDIOADelay;) -#define DEFINE_INCDEC_INSTRUCTION_LR35902(REG) \ +#define DEFINE_INCDEC_WIDE_INSTRUCTION_LR35902(REG) \ DEFINE_INSTRUCTION_LR35902(INC ## REG, \ uint16_t reg = LR35902Read ## REG (cpu); \ LR35902Write ## REG (cpu, reg + 1); \ @@ -370,9 +374,57 @@ DEFINE_INSTRUCTION_LR35902(LDIOA, \ LR35902Write ## REG (cpu, reg - 1); \ cpu->executionState = LR35902_CORE_STALL;) -DEFINE_INCDEC_INSTRUCTION_LR35902(BC); -DEFINE_INCDEC_INSTRUCTION_LR35902(DE); -DEFINE_INCDEC_INSTRUCTION_LR35902(HL); +DEFINE_INCDEC_WIDE_INSTRUCTION_LR35902(BC); +DEFINE_INCDEC_WIDE_INSTRUCTION_LR35902(DE); +DEFINE_INCDEC_WIDE_INSTRUCTION_LR35902(HL); + + +#define DEFINE_INC_INSTRUCTION_LR35902(NAME, OPERAND) \ + DEFINE_INSTRUCTION_LR35902(INC ## NAME, \ + int diff = OPERAND + 1; \ + OPERAND = diff; \ + cpu->f.n = 0; \ + cpu->f.z = !diff; \ + /* TODO: Find explanation of H flag */) + +#define DEFINE_DEC_INSTRUCTION_LR35902(NAME, OPERAND) \ + DEFINE_INSTRUCTION_LR35902(DEC ## NAME, \ + int diff = OPERAND - 1; \ + OPERAND = diff; \ + cpu->f.n = 1; \ + cpu->f.z = !diff; \ + /* TODO: Find explanation of H flag */) + +DEFINE_ALU_INSTRUCTION_LR35902_NOHL(INC); +DEFINE_ALU_INSTRUCTION_LR35902_NOHL(DEC); + +DEFINE_INSTRUCTION_LR35902(INC_HLDelay, + int diff = cpu->bus + 1; + cpu->bus = diff; + cpu->f.n = 0; + cpu->f.z = !diff; + /* TODO: Find explanation of H flag */ + cpu->instruction = _LR35902InstructionNOP; + cpu->executionState = LR35902_CORE_MEMORY_STORE;) + +DEFINE_INSTRUCTION_LR35902(INC_HL, + cpu->index = LR35902ReadHL(cpu); + cpu->instruction = _LR35902InstructionINC_HLDelay; + cpu->executionState = LR35902_CORE_MEMORY_LOAD;) + +DEFINE_INSTRUCTION_LR35902(DEC_HLDelay, + int diff = cpu->bus - 1; + cpu->bus = diff; + cpu->f.n = 1; + cpu->f.z = !diff; + /* TODO: Find explanation of H flag */ + cpu->instruction = _LR35902InstructionNOP; + cpu->executionState = LR35902_CORE_MEMORY_STORE;) + +DEFINE_INSTRUCTION_LR35902(DEC_HL, + cpu->index = LR35902ReadHL(cpu); + cpu->instruction = _LR35902InstructionDEC_HLDelay; + cpu->executionState = LR35902_CORE_MEMORY_LOAD;) DEFINE_INSTRUCTION_LR35902(INCSP, ++cpu->sp;