LR35902: Fix CALL M-state order

This commit is contained in:
Jeffrey Pfau 2016-01-26 20:53:43 -08:00
parent 04281f9f11
commit fe36ff1933
1 changed files with 19 additions and 25 deletions

View File

@ -65,41 +65,35 @@ DEFINE_INSTRUCTION_LR35902(JRFinish,
DEFINE_CONDITIONAL_INSTRUCTION_LR35902(JR); DEFINE_CONDITIONAL_INSTRUCTION_LR35902(JR);
DEFINE_INSTRUCTION_LR35902(CALLFinish, DEFINE_INSTRUCTION_LR35902(CALLUpdateSPL,
--cpu->index;
cpu->bus = cpu->sp;
cpu->sp = cpu->index;
cpu->executionState = LR35902_CORE_MEMORY_STORE;
cpu->instruction = _LR35902InstructionNOP;)
DEFINE_INSTRUCTION_LR35902(CALLUpdatePCH,
if (cpu->condition) { if (cpu->condition) {
cpu->pc = (cpu->bus << 8) | cpu->index; int newPc = (cpu->bus << 8) | cpu->index;
cpu->bus = cpu->pc >> 8;
cpu->index = cpu->sp - 1;
cpu->sp = cpu->pc; // GROSS
cpu->pc = newPc;
cpu->memory.setActiveRegion(cpu, cpu->pc); cpu->memory.setActiveRegion(cpu, cpu->pc);
cpu->executionState = LR35902_CORE_STALL; cpu->executionState = LR35902_CORE_MEMORY_STORE;
cpu->instruction = _LR35902InstructionCALLUpdateSPL;
}) })
DEFINE_INSTRUCTION_LR35902(CALLUpdatePC, DEFINE_INSTRUCTION_LR35902(CALLUpdatePCL,
cpu->executionState = LR35902_CORE_READ_PC; cpu->executionState = LR35902_CORE_READ_PC;
cpu->index = cpu->bus; cpu->index = cpu->bus;
cpu->instruction = _LR35902InstructionCALLFinish;) cpu->instruction = _LR35902InstructionCALLUpdatePCH)
DEFINE_INSTRUCTION_LR35902(CALLUpdateSPL,
cpu->executionState = LR35902_CORE_READ_PC; \
cpu->instruction = _LR35902InstructionCALLUpdatePC;)
DEFINE_INSTRUCTION_LR35902(CALLUpdateSPH,
cpu->index = cpu->sp + 1;
cpu->bus = (cpu->pc + 2) >> 8;
cpu->executionState = LR35902_CORE_MEMORY_STORE;
cpu->instruction = _LR35902InstructionCALLUpdateSPL;)
#define DEFINE_CALL_INSTRUCTION_LR35902(CONDITION_NAME, CONDITION) \ #define DEFINE_CALL_INSTRUCTION_LR35902(CONDITION_NAME, CONDITION) \
DEFINE_INSTRUCTION_LR35902(CALL ## CONDITION_NAME, \ DEFINE_INSTRUCTION_LR35902(CALL ## CONDITION_NAME, \
cpu->condition = CONDITION; \ cpu->condition = CONDITION; \
if (CONDITION) { \ cpu->executionState = LR35902_CORE_READ_PC; \
cpu->sp -= 2; /* TODO: Atomic incrementing? */ \ cpu->instruction = _LR35902InstructionCALLUpdatePCL;)
cpu->index = cpu->sp; \
cpu->bus = cpu->pc + 2; \
cpu->executionState = LR35902_CORE_MEMORY_STORE; \
cpu->instruction = _LR35902InstructionCALLUpdateSPH; \
} else { \
cpu->executionState = LR35902_CORE_READ_PC; \
cpu->instruction = _LR35902InstructionCALLUpdatePC; \
})
DEFINE_CONDITIONAL_INSTRUCTION_LR35902(CALL) DEFINE_CONDITIONAL_INSTRUCTION_LR35902(CALL)