GB: Convert EI to mTiming
Jeffrey Pfau jeffrey@endrift.com
Thu, 10 Nov 2016 21:39:01 -0800
3 files changed,
18 insertions(+),
22 deletions(-)
M
src/gb/gb.c
→
src/gb/gb.c
@@ -39,6 +39,8 @@ static void GBSetInterrupts(struct LR35902Core* cpu, bool enable);
static void GBIllegal(struct LR35902Core* cpu); static void GBStop(struct LR35902Core* cpu); +static void _enableInterrupts(struct mTiming* timing, void* user, uint32_t cyclesLate); + #ifdef _3DS extern uint32_t* romBuffer; extern size_t romBufferSize;@@ -85,6 +87,10 @@ gb->stream = NULL;
mTimingInit(&gb->timing, &gb->cpu->cycles, &gb->cpu->nextEvent); gb->audio.timing = &gb->timing; + + gb->eiPending.name = "GB EI"; + gb->eiPending.callback = _enableInterrupts; + gb->eiPending.context = gb; } static void GBDeinit(struct mCPUComponent* component) {@@ -426,7 +432,6 @@ cpu->pc = 0x100;
} gb->cpuBlocked = false; - gb->eiPending = INT_MAX; gb->doubleSpeed = 0; cpu->memory.setActiveRegion(cpu, cpu->pc);@@ -536,17 +541,6 @@
cpu->cycles = 0; cpu->nextEvent = INT_MAX; - if (gb->eiPending != INT_MAX) { - gb->eiPending -= cycles; - if (gb->eiPending <= 0) { - gb->memory.ime = true; - GBUpdateIRQs(gb); - gb->eiPending = INT_MAX; - } else { - nextEvent = gb->eiPending; - } - } - nextEvent = cycles; do { nextEvent = mTimingTick(&gb->timing, nextEvent);@@ -566,14 +560,20 @@ void GBSetInterrupts(struct LR35902Core* cpu, bool enable) {
struct GB* gb = (struct GB*) cpu->master; if (!enable) { gb->memory.ime = enable; - gb->eiPending = INT_MAX; + mTimingDeschedule(&gb->timing, &gb->eiPending); GBUpdateIRQs(gb); } else { - if (cpu->nextEvent > cpu->cycles + 4) { - cpu->nextEvent = cpu->cycles + 4; - } - gb->eiPending = cpu->cycles + 4; + mTimingDeschedule(&gb->timing, &gb->eiPending); + mTimingSchedule(&gb->timing, &gb->eiPending, 4); } +} + +static void _enableInterrupts(struct mTiming* timing, void* user, uint32_t cyclesLate) { + UNUSED(timing); + UNUSED(cyclesLate); + struct GB* gb = user; + gb->memory.ime = true; + GBUpdateIRQs(gb); } void GBHalt(struct LR35902Core* cpu) {
M
src/gb/gb.h
→
src/gb/gb.h
@@ -79,7 +79,7 @@ struct mCoreCallbacks* coreCallbacks;
struct mAVStream* stream; bool cpuBlocked; - int32_t eiPending; + struct mTimingEvent eiPending; unsigned doubleSpeed; };
M
src/gb/serialize.c
→
src/gb/serialize.c
@@ -50,8 +50,6 @@ state->cpu.bus = gb->cpu->bus;
state->cpu.executionState = gb->cpu->executionState; STORE_16LE(gb->cpu->irqVector, 0, &state->cpu.irqVector); - STORE_32LE(gb->eiPending, 0, &state->cpu.eiPending); - GBSerializedCpuFlags flags = 0; flags = GBSerializedCpuFlagsSetCondition(flags, gb->cpu->condition); flags = GBSerializedCpuFlagsSetIrqPending(flags, gb->cpu->irqPending);@@ -169,8 +167,6 @@ LOAD_16LE(gb->cpu->index, 0, &state->cpu.index);
gb->cpu->bus = state->cpu.bus; gb->cpu->executionState = state->cpu.executionState; LOAD_16LE(gb->cpu->irqVector, 0, &state->cpu.irqVector); - - LOAD_32LE(gb->eiPending, 0, &state->cpu.eiPending); GBSerializedCpuFlags flags; LOAD_32LE(flags, 0, &state->cpu.flags);