mirror of https://github.com/mgba-emu/mgba.git
LR35902: Improve stalling behavior
This commit is contained in:
parent
b104a5cd1c
commit
5bce4480db
|
@ -27,8 +27,7 @@ DEFINE_INSTRUCTION_LR35902(JPFinish,
|
||||||
if (cpu->condition) {
|
if (cpu->condition) {
|
||||||
cpu->pc = (cpu->bus << 8) | cpu->index;
|
cpu->pc = (cpu->bus << 8) | cpu->index;
|
||||||
cpu->memory.setActiveRegion(cpu, cpu->pc);
|
cpu->memory.setActiveRegion(cpu, cpu->pc);
|
||||||
// TODO: Stall properly
|
cpu->executionState = LR35902_CORE_STALL;
|
||||||
cpu->cycles += 4;
|
|
||||||
})
|
})
|
||||||
|
|
||||||
DEFINE_INSTRUCTION_LR35902(JPDelay,
|
DEFINE_INSTRUCTION_LR35902(JPDelay,
|
||||||
|
@ -48,8 +47,7 @@ DEFINE_INSTRUCTION_LR35902(JRFinish,
|
||||||
if (cpu->condition) {
|
if (cpu->condition) {
|
||||||
cpu->pc += (int8_t) cpu->bus;
|
cpu->pc += (int8_t) cpu->bus;
|
||||||
cpu->memory.setActiveRegion(cpu, cpu->pc);
|
cpu->memory.setActiveRegion(cpu, cpu->pc);
|
||||||
// TODO: Stall properly
|
cpu->executionState = LR35902_CORE_STALL;
|
||||||
cpu->cycles += 4;
|
|
||||||
})
|
})
|
||||||
|
|
||||||
#define DEFINE_JR_INSTRUCTION_LR35902(CONDITION_NAME, CONDITION) \
|
#define DEFINE_JR_INSTRUCTION_LR35902(CONDITION_NAME, CONDITION) \
|
||||||
|
@ -64,8 +62,7 @@ DEFINE_INSTRUCTION_LR35902(CALLFinish,
|
||||||
if (cpu->condition) {
|
if (cpu->condition) {
|
||||||
cpu->pc = (cpu->bus << 8) | cpu->index;
|
cpu->pc = (cpu->bus << 8) | cpu->index;
|
||||||
cpu->memory.setActiveRegion(cpu, cpu->pc);
|
cpu->memory.setActiveRegion(cpu, cpu->pc);
|
||||||
// TODO: Stall properly
|
cpu->executionState = LR35902_CORE_STALL;
|
||||||
cpu->cycles += 4;
|
|
||||||
})
|
})
|
||||||
|
|
||||||
DEFINE_INSTRUCTION_LR35902(CALLUpdatePC,
|
DEFINE_INSTRUCTION_LR35902(CALLUpdatePC,
|
||||||
|
@ -103,8 +100,7 @@ DEFINE_INSTRUCTION_LR35902(RETUpdateSPL,
|
||||||
cpu->pc |= cpu->bus << 8;
|
cpu->pc |= cpu->bus << 8;
|
||||||
cpu->sp += 2;
|
cpu->sp += 2;
|
||||||
cpu->memory.setActiveRegion(cpu, cpu->pc);
|
cpu->memory.setActiveRegion(cpu, cpu->pc);
|
||||||
// TODO: Stall properly
|
cpu->executionState = LR35902_CORE_STALL;)
|
||||||
cpu->cycles += 4;)
|
|
||||||
|
|
||||||
DEFINE_INSTRUCTION_LR35902(RETUpdateSPH,
|
DEFINE_INSTRUCTION_LR35902(RETUpdateSPH,
|
||||||
if (cpu->condition) {
|
if (cpu->condition) {
|
||||||
|
@ -368,14 +364,11 @@ DEFINE_INSTRUCTION_LR35902(LDIOA, \
|
||||||
DEFINE_INSTRUCTION_LR35902(INC ## REG, \
|
DEFINE_INSTRUCTION_LR35902(INC ## REG, \
|
||||||
uint16_t reg = LR35902Read ## REG (cpu); \
|
uint16_t reg = LR35902Read ## REG (cpu); \
|
||||||
LR35902Write ## REG (cpu, reg + 1); \
|
LR35902Write ## REG (cpu, reg + 1); \
|
||||||
/* TODO: Stall properly */ \
|
cpu->executionState = LR35902_CORE_STALL;) \
|
||||||
cpu->cycles += 4;) \
|
|
||||||
DEFINE_INSTRUCTION_LR35902(DEC ## REG, \
|
DEFINE_INSTRUCTION_LR35902(DEC ## REG, \
|
||||||
uint16_t reg = LR35902Read ## REG (cpu); \
|
uint16_t reg = LR35902Read ## REG (cpu); \
|
||||||
LR35902Write ## REG (cpu, reg - 1); \
|
LR35902Write ## REG (cpu, reg - 1); \
|
||||||
/* TODO: Stall properly */ \
|
cpu->executionState = LR35902_CORE_STALL;)
|
||||||
cpu->cycles += 4;) \
|
|
||||||
|
|
||||||
|
|
||||||
DEFINE_INCDEC_INSTRUCTION_LR35902(BC);
|
DEFINE_INCDEC_INSTRUCTION_LR35902(BC);
|
||||||
DEFINE_INCDEC_INSTRUCTION_LR35902(DE);
|
DEFINE_INCDEC_INSTRUCTION_LR35902(DE);
|
||||||
|
@ -383,13 +376,11 @@ DEFINE_INCDEC_INSTRUCTION_LR35902(HL);
|
||||||
|
|
||||||
DEFINE_INSTRUCTION_LR35902(INCSP,
|
DEFINE_INSTRUCTION_LR35902(INCSP,
|
||||||
++cpu->sp;
|
++cpu->sp;
|
||||||
// TODO: Stall properly
|
cpu->executionState = LR35902_CORE_STALL;)
|
||||||
cpu->cycles += 4;)
|
|
||||||
|
|
||||||
DEFINE_INSTRUCTION_LR35902(DECSP,
|
DEFINE_INSTRUCTION_LR35902(DECSP,
|
||||||
--cpu->sp;
|
--cpu->sp;
|
||||||
// TODO: Stall properly
|
cpu->executionState = LR35902_CORE_STALL;)
|
||||||
cpu->cycles += 4;)
|
|
||||||
|
|
||||||
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));
|
||||||
|
|
|
@ -85,7 +85,8 @@ void LR35902Tick(struct LR35902Core* cpu) {
|
||||||
cpu->pc = cpu->irqVector;
|
cpu->pc = cpu->irqVector;
|
||||||
cpu->irqPending = false;
|
cpu->irqPending = false;
|
||||||
cpu->irqh.setInterrupts(cpu, false);
|
cpu->irqh.setInterrupts(cpu, false);
|
||||||
// TODO: stall
|
cpu->instruction = _lr35902InstructionTable[0]; // NOP
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
cpu->bus = cpu->memory.load8(cpu, cpu->pc);
|
cpu->bus = cpu->memory.load8(cpu, cpu->pc);
|
||||||
cpu->instruction = _lr35902InstructionTable[cpu->bus];
|
cpu->instruction = _lr35902InstructionTable[cpu->bus];
|
||||||
|
@ -104,6 +105,9 @@ void LR35902Tick(struct LR35902Core* cpu) {
|
||||||
cpu->bus = cpu->memory.load8(cpu, cpu->pc);
|
cpu->bus = cpu->memory.load8(cpu, cpu->pc);
|
||||||
++cpu->pc;
|
++cpu->pc;
|
||||||
break;
|
break;
|
||||||
|
case LR35902_CORE_STALL:
|
||||||
|
cpu->instruction = _lr35902InstructionTable[0]; // NOP
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,7 @@ enum LR35902ExecutionState {
|
||||||
LR35902_CORE_MEMORY_LOAD = 4,
|
LR35902_CORE_MEMORY_LOAD = 4,
|
||||||
LR35902_CORE_MEMORY_STORE = 8,
|
LR35902_CORE_MEMORY_STORE = 8,
|
||||||
LR35902_CORE_READ_PC = 12,
|
LR35902_CORE_READ_PC = 12,
|
||||||
|
LR35902_CORE_STALL = 16
|
||||||
};
|
};
|
||||||
|
|
||||||
struct LR35902Memory {
|
struct LR35902Memory {
|
||||||
|
|
Loading…
Reference in New Issue