diff --git a/src/lr35902/emitter-lr35902.h b/src/lr35902/emitter-lr35902.h index ef4511377..e27ad41c5 100644 --- a/src/lr35902/emitter-lr35902.h +++ b/src/lr35902/emitter-lr35902.h @@ -203,11 +203,11 @@ 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, 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, 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, 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), \ diff --git a/src/lr35902/isa-lr35902.c b/src/lr35902/isa-lr35902.c index 8fbe076b5..f81ff6b9b 100644 --- a/src/lr35902/isa-lr35902.c +++ b/src/lr35902/isa-lr35902.c @@ -84,7 +84,7 @@ DEFINE_INSTRUCTION_LR35902(CALLUpdateSPH, 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;) @@ -382,6 +382,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));