mirror of https://github.com/mgba-emu/mgba.git
GB: Convert EI to mTiming
This commit is contained in:
parent
e429d726dc
commit
86571c8496
34
src/gb/gb.c
34
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 @@ static void GBInit(void* cpu, struct mCPUComponent* component) {
|
|||
|
||||
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 @@ void GBReset(struct LR35902Core* cpu) {
|
|||
}
|
||||
|
||||
gb->cpuBlocked = false;
|
||||
gb->eiPending = INT_MAX;
|
||||
gb->doubleSpeed = 0;
|
||||
|
||||
cpu->memory.setActiveRegion(cpu, cpu->pc);
|
||||
|
@ -536,17 +541,6 @@ void GBProcessEvents(struct LR35902Core* cpu) {
|
|||
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,16 +560,22 @@ 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) {
|
||||
if (!cpu->irqPending) {
|
||||
cpu->cycles = cpu->nextEvent;
|
||||
|
|
|
@ -79,7 +79,7 @@ struct GB {
|
|||
struct mAVStream* stream;
|
||||
|
||||
bool cpuBlocked;
|
||||
int32_t eiPending;
|
||||
struct mTimingEvent eiPending;
|
||||
unsigned doubleSpeed;
|
||||
};
|
||||
|
||||
|
|
|
@ -50,8 +50,6 @@ void GBSerialize(struct GB* gb, struct GBSerializedState* state) {
|
|||
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);
|
||||
|
@ -170,8 +168,6 @@ bool GBDeserialize(struct GB* gb, const struct GBSerializedState* state) {
|
|||
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);
|
||||
gb->cpu->condition = GBSerializedCpuFlagsGetCondition(flags);
|
||||
|
|
Loading…
Reference in New Issue