mirror of https://github.com/mgba-emu/mgba.git
Core: Scheduling should be relative to current cycles
This commit is contained in:
parent
bf9be29ad5
commit
e423cd45e5
|
@ -7,9 +7,10 @@
|
|||
|
||||
DEFINE_VECTOR(mTimingEventList, struct mTimingEvent*);
|
||||
|
||||
void mTimingInit(struct mTiming* timing) {
|
||||
void mTimingInit(struct mTiming* timing, int32_t* relativeCycles) {
|
||||
mTimingEventListInit(&timing->events, 0);
|
||||
timing->masterCycles = 0;
|
||||
timing->relativeCycles = relativeCycles;
|
||||
}
|
||||
|
||||
void mTimingDeinit(struct mTiming* timing) {
|
||||
|
@ -22,7 +23,7 @@ void mTimingClear(struct mTiming* timing) {
|
|||
}
|
||||
|
||||
void mTimingSchedule(struct mTiming* timing, struct mTimingEvent* event, int32_t when) {
|
||||
event->when = when + timing->masterCycles;
|
||||
event->when = when + timing->masterCycles + *timing->relativeCycles;
|
||||
size_t e;
|
||||
for (e = 0; e < mTimingEventListSize(&timing->events); ++e) {
|
||||
struct mTimingEvent* next = *mTimingEventListGetPointer(&timing->events, e);
|
||||
|
|
|
@ -23,9 +23,10 @@ struct mTiming {
|
|||
struct mTimingEventList events;
|
||||
|
||||
uint32_t masterCycles;
|
||||
int32_t* relativeCycles;
|
||||
};
|
||||
|
||||
void mTimingInit(struct mTiming* timing);
|
||||
void mTimingInit(struct mTiming* timing, int32_t* relativeCycles);
|
||||
void mTimingDeinit(struct mTiming* timing);
|
||||
void mTimingClear(struct mTiming* timing);
|
||||
void mTimingSchedule(struct mTiming* timing, struct mTimingEvent*, int32_t when);
|
||||
|
|
13
src/gb/gb.c
13
src/gb/gb.c
|
@ -83,7 +83,7 @@ static void GBInit(void* cpu, struct mCPUComponent* component) {
|
|||
gb->coreCallbacks = NULL;
|
||||
gb->stream = NULL;
|
||||
|
||||
mTimingInit(&gb->timing);
|
||||
mTimingInit(&gb->timing, &gb->cpu->cycles);
|
||||
}
|
||||
|
||||
static void GBDeinit(struct mCPUComponent* component) {
|
||||
|
@ -529,9 +529,12 @@ void GBProcessEvents(struct LR35902Core* cpu) {
|
|||
struct GB* gb = (struct GB*) cpu->master;
|
||||
do {
|
||||
int32_t cycles = cpu->nextEvent;
|
||||
int32_t nextEvent = INT_MAX;
|
||||
int32_t nextEvent;
|
||||
int32_t testEvent;
|
||||
|
||||
cpu->cycles -= cycles;
|
||||
cpu->nextEvent = INT_MAX;
|
||||
|
||||
if (gb->eiPending != INT_MAX) {
|
||||
gb->eiPending -= cycles;
|
||||
if (gb->eiPending <= 0) {
|
||||
|
@ -544,10 +547,7 @@ void GBProcessEvents(struct LR35902Core* cpu) {
|
|||
}
|
||||
|
||||
mTimingTick(&gb->timing, cycles);
|
||||
testEvent = mTimingNextEvent(&gb->timing);
|
||||
if (testEvent < nextEvent) {
|
||||
nextEvent = testEvent;
|
||||
}
|
||||
nextEvent = cpu->nextEvent;
|
||||
|
||||
testEvent = GBAudioProcessEvents(&gb->audio, cycles >> gb->doubleSpeed);
|
||||
if (testEvent != INT_MAX) {
|
||||
|
@ -557,7 +557,6 @@ void GBProcessEvents(struct LR35902Core* cpu) {
|
|||
}
|
||||
}
|
||||
|
||||
cpu->cycles -= cycles;
|
||||
cpu->nextEvent = nextEvent;
|
||||
|
||||
if (cpu->halted) {
|
||||
|
|
|
@ -409,7 +409,6 @@ void _GBMemoryHDMAService(struct mTiming* timing, void* context, uint32_t cycles
|
|||
++gb->memory.hdmaSource;
|
||||
++gb->memory.hdmaDest;
|
||||
--gb->memory.hdmaRemaining;
|
||||
gb->cpu->cycles += 2;
|
||||
if (gb->memory.hdmaRemaining) {
|
||||
mTimingSchedule(timing, &gb->memory.hdmaEvent, 2 - cyclesLate);
|
||||
} else {
|
||||
|
@ -426,6 +425,7 @@ void _GBMemoryHDMAService(struct mTiming* timing, void* context, uint32_t cycles
|
|||
gb->memory.io[REG_HDMA5] = 0xFF;
|
||||
}
|
||||
}
|
||||
gb->cpu->cycles += 2;
|
||||
}
|
||||
|
||||
struct OAMBlock {
|
||||
|
|
Loading…
Reference in New Issue