all repos — mgba @ 3603958e02f2ad89f6c675432254991778161d83

mGBA Game Boy Advance Emulator

LR35902: Implement POP/PUSH
Jeffrey Pfau jeffrey@endrift.com
Fri, 15 Jan 2016 15:08:37 -0800
commit

3603958e02f2ad89f6c675432254991778161d83

parent

5bce4480db17fcb0a3a091a5ca2407c77fdbc596

2 files changed, 44 insertions(+), 10 deletions(-)

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

@@ -203,11 +203,11 @@ DECLARE_INSTRUCTION_LR35902(EMITTER, CPL), \

DECLARE_INSTRUCTION_LR35902(EMITTER, CPHL), \ DECLARE_INSTRUCTION_LR35902(EMITTER, CPA), \ DECLARE_INSTRUCTION_LR35902(EMITTER, RETNZ), \ - DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ + DECLARE_INSTRUCTION_LR35902(EMITTER, POPBC), \ DECLARE_INSTRUCTION_LR35902(EMITTER, JPNZ), \ DECLARE_INSTRUCTION_LR35902(EMITTER, JP), \ DECLARE_INSTRUCTION_LR35902(EMITTER, CALLNZ), \ - DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ + DECLARE_INSTRUCTION_LR35902(EMITTER, PUSHBC), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, RETZ), \

@@ -219,11 +219,11 @@ DECLARE_INSTRUCTION_LR35902(EMITTER, CALL), \

DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, RETNC), \ - DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ + DECLARE_INSTRUCTION_LR35902(EMITTER, POPDE), \ DECLARE_INSTRUCTION_LR35902(EMITTER, JPNC), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, CALLNC), \ - DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ + DECLARE_INSTRUCTION_LR35902(EMITTER, PUSHDE), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, RETC), \

@@ -235,11 +235,11 @@ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \

DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, LDIOA), \ - DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ + DECLARE_INSTRUCTION_LR35902(EMITTER, POPHL), \ DECLARE_INSTRUCTION_LR35902(EMITTER, LDIOCA), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ - DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ + DECLARE_INSTRUCTION_LR35902(EMITTER, PUSHHL), \ DECLARE_INSTRUCTION_LR35902(EMITTER, AND), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \

@@ -251,11 +251,11 @@ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \

DECLARE_INSTRUCTION_LR35902(EMITTER, XOR), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, LDAIO), \ - DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ + DECLARE_INSTRUCTION_LR35902(EMITTER, POPAF), \ DECLARE_INSTRUCTION_LR35902(EMITTER, LDAIOC), \ DECLARE_INSTRUCTION_LR35902(EMITTER, DI), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ - DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ + DECLARE_INSTRUCTION_LR35902(EMITTER, PUSHAF), \ DECLARE_INSTRUCTION_LR35902(EMITTER, OR), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
M src/lr35902/isa-lr35902.csrc/lr35902/isa-lr35902.c

@@ -84,7 +84,7 @@ #define DEFINE_CALL_INSTRUCTION_LR35902(CONDITION_NAME, CONDITION) \

DEFINE_INSTRUCTION_LR35902(CALL ## CONDITION_NAME, \ cpu->condition = CONDITION; \ if (CONDITION) { \ - cpu->sp -= 2; \ + cpu->sp -= 2; /* TODO: Atomic incrementing? */ \ cpu->index = cpu->sp; \ cpu->bus = cpu->pc + 2; \ cpu->executionState = LR35902_CORE_MEMORY_STORE; \

@@ -98,7 +98,7 @@ DEFINE_CONDITIONAL_INSTRUCTION_LR35902(CALL)

DEFINE_INSTRUCTION_LR35902(RETUpdateSPL, cpu->pc |= cpu->bus << 8; - cpu->sp += 2; + cpu->sp += 2; /* TODO: Atomic incrementing? */ cpu->memory.setActiveRegion(cpu, cpu->pc); cpu->executionState = LR35902_CORE_STALL;)

@@ -381,6 +381,40 @@

DEFINE_INSTRUCTION_LR35902(DECSP, --cpu->sp; cpu->executionState = LR35902_CORE_STALL;) + + +#define DEFINE_POPPUSH_INSTRUCTION_LR35902(REG, HH, H, L) \ + DEFINE_INSTRUCTION_LR35902(POP ## REG ## Delay, \ + cpu-> L = cpu->bus; \ + cpu->index = cpu->sp; \ + ++cpu->sp; \ + cpu->instruction = _LR35902InstructionLD ## HH ## _Bus; \ + cpu->executionState = LR35902_CORE_MEMORY_LOAD;) \ + DEFINE_INSTRUCTION_LR35902(POP ## REG, \ + cpu->index = cpu->sp; \ + ++cpu->sp; \ + cpu->instruction = _LR35902InstructionPOP ## REG ## Delay; \ + cpu->executionState = LR35902_CORE_MEMORY_LOAD;) \ + DEFINE_INSTRUCTION_LR35902(PUSH ## REG ## Finish, \ + cpu->instruction = _LR35902InstructionNOP; \ + cpu->executionState = LR35902_CORE_STALL;) \ + DEFINE_INSTRUCTION_LR35902(PUSH ## REG ## Delay, \ + --cpu->sp; \ + cpu->index = cpu->sp; \ + cpu->bus = cpu-> L; \ + cpu->instruction = _LR35902InstructionPUSH ## REG ## Finish; \ + cpu->executionState = LR35902_CORE_MEMORY_STORE;) \ + DEFINE_INSTRUCTION_LR35902(PUSH ## REG, \ + --cpu->sp; \ + cpu->index = cpu->sp; \ + cpu->bus = cpu-> H; \ + cpu->instruction = _LR35902InstructionPUSH ## REG ## Delay; \ + cpu->executionState = LR35902_CORE_MEMORY_STORE;) + +DEFINE_POPPUSH_INSTRUCTION_LR35902(BC, B, b, c); +DEFINE_POPPUSH_INSTRUCTION_LR35902(DE, D, d, e); +DEFINE_POPPUSH_INSTRUCTION_LR35902(HL, H, h, l); +DEFINE_POPPUSH_INSTRUCTION_LR35902(AF, A, a, f.packed); DEFINE_INSTRUCTION_LR35902(DI, cpu->irqh.setInterrupts(cpu, false)); DEFINE_INSTRUCTION_LR35902(EI, cpu->irqh.setInterrupts(cpu, true));