LR35902: Implement POP/PUSH

This commit is contained in:
Jeffrey Pfau 2016-01-15 15:08:37 -08:00
parent 5bce4480db
commit 3603958e02
2 changed files with 44 additions and 10 deletions

View File

@ -203,11 +203,11 @@
DECLARE_INSTRUCTION_LR35902(EMITTER, CPHL), \ DECLARE_INSTRUCTION_LR35902(EMITTER, CPHL), \
DECLARE_INSTRUCTION_LR35902(EMITTER, CPA), \ DECLARE_INSTRUCTION_LR35902(EMITTER, CPA), \
DECLARE_INSTRUCTION_LR35902(EMITTER, RETNZ), \ DECLARE_INSTRUCTION_LR35902(EMITTER, RETNZ), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, POPBC), \
DECLARE_INSTRUCTION_LR35902(EMITTER, JPNZ), \ DECLARE_INSTRUCTION_LR35902(EMITTER, JPNZ), \
DECLARE_INSTRUCTION_LR35902(EMITTER, JP), \ DECLARE_INSTRUCTION_LR35902(EMITTER, JP), \
DECLARE_INSTRUCTION_LR35902(EMITTER, CALLNZ), \ 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, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, RETZ), \ DECLARE_INSTRUCTION_LR35902(EMITTER, RETZ), \
@ -219,11 +219,11 @@
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, RETNC), \ DECLARE_INSTRUCTION_LR35902(EMITTER, RETNC), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, POPDE), \
DECLARE_INSTRUCTION_LR35902(EMITTER, JPNC), \ DECLARE_INSTRUCTION_LR35902(EMITTER, JPNC), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, CALLNC), \ 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, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, RETC), \ 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, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, LDIOA), \ DECLARE_INSTRUCTION_LR35902(EMITTER, LDIOA), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, POPHL), \
DECLARE_INSTRUCTION_LR35902(EMITTER, LDIOCA), \ DECLARE_INSTRUCTION_LR35902(EMITTER, LDIOCA), \
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, PUSHHL), \
DECLARE_INSTRUCTION_LR35902(EMITTER, AND), \ DECLARE_INSTRUCTION_LR35902(EMITTER, AND), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
@ -251,11 +251,11 @@
DECLARE_INSTRUCTION_LR35902(EMITTER, XOR), \ DECLARE_INSTRUCTION_LR35902(EMITTER, XOR), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, LDAIO), \ DECLARE_INSTRUCTION_LR35902(EMITTER, LDAIO), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, POPAF), \
DECLARE_INSTRUCTION_LR35902(EMITTER, LDAIOC), \ DECLARE_INSTRUCTION_LR35902(EMITTER, LDAIOC), \
DECLARE_INSTRUCTION_LR35902(EMITTER, DI), \ DECLARE_INSTRUCTION_LR35902(EMITTER, DI), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, PUSHAF), \
DECLARE_INSTRUCTION_LR35902(EMITTER, OR), \ DECLARE_INSTRUCTION_LR35902(EMITTER, OR), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \
DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \ DECLARE_INSTRUCTION_LR35902(EMITTER, STUB), \

View File

@ -84,7 +84,7 @@ DEFINE_INSTRUCTION_LR35902(CALLUpdateSPH,
DEFINE_INSTRUCTION_LR35902(CALL ## CONDITION_NAME, \ DEFINE_INSTRUCTION_LR35902(CALL ## CONDITION_NAME, \
cpu->condition = CONDITION; \ cpu->condition = CONDITION; \
if (CONDITION) { \ if (CONDITION) { \
cpu->sp -= 2; \ cpu->sp -= 2; /* TODO: Atomic incrementing? */ \
cpu->index = cpu->sp; \ cpu->index = cpu->sp; \
cpu->bus = cpu->pc + 2; \ cpu->bus = cpu->pc + 2; \
cpu->executionState = LR35902_CORE_MEMORY_STORE; \ cpu->executionState = LR35902_CORE_MEMORY_STORE; \
@ -98,7 +98,7 @@ DEFINE_CONDITIONAL_INSTRUCTION_LR35902(CALL)
DEFINE_INSTRUCTION_LR35902(RETUpdateSPL, DEFINE_INSTRUCTION_LR35902(RETUpdateSPL,
cpu->pc |= cpu->bus << 8; cpu->pc |= cpu->bus << 8;
cpu->sp += 2; cpu->sp += 2; /* TODO: Atomic incrementing? */
cpu->memory.setActiveRegion(cpu, cpu->pc); cpu->memory.setActiveRegion(cpu, cpu->pc);
cpu->executionState = LR35902_CORE_STALL;) cpu->executionState = LR35902_CORE_STALL;)
@ -382,6 +382,40 @@ DEFINE_INSTRUCTION_LR35902(DECSP,
--cpu->sp; --cpu->sp;
cpu->executionState = LR35902_CORE_STALL;) 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(DI, cpu->irqh.setInterrupts(cpu, false));
DEFINE_INSTRUCTION_LR35902(EI, cpu->irqh.setInterrupts(cpu, true)); DEFINE_INSTRUCTION_LR35902(EI, cpu->irqh.setInterrupts(cpu, true));