all repos — mgba @ 0bfbc2079e4ec38e247cb6297ad7530d379a9a5a

mGBA Game Boy Advance Emulator

LR35902: Implement more LD forms
Jeffrey Pfau jeffrey@endrift.com
Fri, 15 Jan 2016 02:03:15 -0800
commit

0bfbc2079e4ec38e247cb6297ad7530d379a9a5a

parent

c3abc16a94a021cb6dc111834d3672ffd2fa9f00

3 files changed, 98 insertions(+), 15 deletions(-)

jump to
M src/lr35902/emitter-lr35902.hsrc/lr35902/emitter-lr35902.h

@@ -11,8 +11,8 @@ EMITTER ## NAME

#define DECLARE_LR35902_EMITTER_BLOCK(EMITTER) \ DECLARE_INSTRUCTION_LR35902(EMITTER, NOP), \ - DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ - DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ + DECLARE_INSTRUCTION_LR35902(EMITTER, LDBC), \ + DECLARE_INSTRUCTION_LR35902(EMITTER, LDBC_A), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \

@@ -26,8 +26,8 @@ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \

DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, LDC_), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ - DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ - DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ + DECLARE_INSTRUCTION_LR35902(EMITTER, LDDE), \ + DECLARE_INSTRUCTION_LR35902(EMITTER, LDDE_A), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \

@@ -43,8 +43,8 @@ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \

DECLARE_INSTRUCTION_LR35902(EMITTER, LDE_), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, JRNZ), \ - DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ - DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ + DECLARE_INSTRUCTION_LR35902(EMITTER, LDHL), \ + DECLARE_INSTRUCTION_LR35902(EMITTER, LDIHLA), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \

@@ -59,12 +59,12 @@ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \

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, 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, LDHL), \ + DECLARE_INSTRUCTION_LR35902(EMITTER, LDHL_), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, JRC), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
M src/lr35902/isa-lr35902.csrc/lr35902/isa-lr35902.c

@@ -189,11 +189,6 @@ #define DEFINE_LDA__INSTRUCTION_LR35902(NAME, OPERAND) \

DEFINE_INSTRUCTION_LR35902(LDA_ ## NAME, \ cpu->a = OPERAND;) -#define DEFINE_LD_INSTRUCTION_LR35902(NAME, OPERAND) \ - DEFINE_INSTRUCTION_LR35902(LD ## NAME, \ - cpu->executionState = LR35902_CORE_READ_PC; \ - cpu->instruction = _LR35902InstructionLD ## NAME ## _Bus;) - #define DEFINE_ALU_INSTRUCTION_LR35902_NOHL(NAME) \ DEFINE_ ## NAME ## _INSTRUCTION_LR35902(A, cpu->a); \ DEFINE_ ## NAME ## _INSTRUCTION_LR35902(B, cpu->b); \

@@ -208,7 +203,7 @@ cpu->index = LR35902ReadHL(cpu); \

cpu->executionState = LR35902_CORE_MEMORY_MOVE_INDEX_STORE; \ cpu->instruction = _LR35902InstructionNOP;) -DEFINE_INSTRUCTION_LR35902(LDHL, \ +DEFINE_INSTRUCTION_LR35902(LDHL_, \ cpu->executionState = LR35902_CORE_READ_PC; \ cpu->instruction = _LR35902InstructionLDHL_Bus;)

@@ -245,6 +240,70 @@ DEFINE_ALU_INSTRUCTION_LR35902(LDH_);

DEFINE_ALU_INSTRUCTION_LR35902(LDL_); DEFINE_ALU_INSTRUCTION_LR35902_NOHL(LDHL_); DEFINE_ALU_INSTRUCTION_LR35902(LDA_); + +DEFINE_INSTRUCTION_LR35902(LDBCDelay, \ + cpu->c = cpu->bus; \ + cpu->executionState = LR35902_CORE_READ_PC; \ + cpu->instruction = _LR35902InstructionLDB_Bus;) + +DEFINE_INSTRUCTION_LR35902(LDBC, \ + cpu->executionState = LR35902_CORE_READ_PC; \ + cpu->instruction = _LR35902InstructionLDBCDelay;) + +DEFINE_INSTRUCTION_LR35902(LDBC_A, \ + cpu->index = LR35902ReadBC(cpu); \ + cpu->bus = cpu->a; \ + cpu->executionState = LR35902_CORE_MEMORY_MOVE_INDEX_STORE; \ + cpu->instruction = _LR35902InstructionNOP;) + +DEFINE_INSTRUCTION_LR35902(LDDEDelay, \ + cpu->e = cpu->bus; \ + cpu->executionState = LR35902_CORE_READ_PC; \ + cpu->instruction = _LR35902InstructionLDD_Bus;) + +DEFINE_INSTRUCTION_LR35902(LDDE, \ + cpu->executionState = LR35902_CORE_READ_PC; \ + cpu->instruction = _LR35902InstructionLDDEDelay;) + +DEFINE_INSTRUCTION_LR35902(LDDE_A, \ + cpu->index = LR35902ReadDE(cpu); \ + cpu->bus = cpu->a; \ + cpu->executionState = LR35902_CORE_MEMORY_MOVE_INDEX_STORE; \ + cpu->instruction = _LR35902InstructionNOP;) + +DEFINE_INSTRUCTION_LR35902(LDHLDelay, \ + cpu->l = cpu->bus; \ + cpu->executionState = LR35902_CORE_READ_PC; \ + cpu->instruction = _LR35902InstructionLDH_Bus;) + +DEFINE_INSTRUCTION_LR35902(LDHL, \ + cpu->executionState = LR35902_CORE_READ_PC; \ + cpu->instruction = _LR35902InstructionLDHLDelay;) + +DEFINE_INSTRUCTION_LR35902(LDSPFinish, cpu->sp |= cpu->bus << 8;) + +DEFINE_INSTRUCTION_LR35902(LDSPDelay, \ + cpu->sp = cpu->bus; \ + cpu->executionState = LR35902_CORE_READ_PC; \ + cpu->instruction = _LR35902InstructionLDSPFinish;) + +DEFINE_INSTRUCTION_LR35902(LDSP, \ + cpu->executionState = LR35902_CORE_READ_PC; \ + cpu->instruction = _LR35902InstructionLDSPDelay;) + +DEFINE_INSTRUCTION_LR35902(LDIHLA, \ + cpu->index = LR35902ReadHL(cpu); \ + LR35902WriteHL(cpu, cpu->index + 1); \ + cpu->bus = cpu->a; \ + cpu->executionState = LR35902_CORE_MEMORY_MOVE_INDEX_STORE; \ + cpu->instruction = _LR35902InstructionNOP;) + +DEFINE_INSTRUCTION_LR35902(LDDHLA, \ + cpu->index = LR35902ReadHL(cpu); \ + LR35902WriteHL(cpu, cpu->index - 1); \ + cpu->bus = cpu->a; \ + cpu->executionState = LR35902_CORE_MEMORY_MOVE_INDEX_STORE; \ + cpu->instruction = _LR35902InstructionNOP;) DEFINE_INSTRUCTION_LR35902(LDIAFinish, \ cpu->index |= cpu->bus << 8;
M src/lr35902/lr35902.hsrc/lr35902/lr35902.h

@@ -138,6 +138,30 @@ LOAD_16LE(hl, 0, &cpu->hl);

return hl; } +static inline void LR35902WriteHL(struct LR35902Core* cpu, uint16_t hl) { + STORE_16LE(hl, 0, &cpu->hl); +} + +static inline uint16_t LR35902ReadBC(struct LR35902Core* cpu) { + uint16_t bc; + LOAD_16LE(bc, 0, &cpu->bc); + return bc; +} + +static inline void LR35902WriteBC(struct LR35902Core* cpu, uint16_t bc) { + STORE_16LE(bc, 0, &cpu->bc); +} + +static inline uint16_t LR35902ReadDE(struct LR35902Core* cpu) { + uint16_t de; + LOAD_16LE(de, 0, &cpu->de); + return de; +} + +static inline void LR35902WriteDE(struct LR35902Core* cpu, uint16_t de) { + STORE_16LE(de, 0, &cpu->de); +} + void LR35902Init(struct LR35902Core* cpu); void LR35902Deinit(struct LR35902Core* cpu); void LR35902SetComponents(struct LR35902Core* cpu, struct LR35902Component* master, int extra, struct LR35902Component** extras);