GB: Rearrange some scheduling for better callback ability

This commit is contained in:
Vicki Pfau 2017-04-18 01:51:41 -07:00
parent 3b69fb767c
commit db4a873d9c
2 changed files with 9 additions and 9 deletions

View File

@ -127,7 +127,7 @@ void _endMode0(struct mTiming* timing, void* context, uint32_t cyclesLate) {
video->mode = 1;
video->modeEvent.callback = _endMode1;
_updateFrameCount(timing, video, cyclesLate);
mTimingSchedule(&video->p->timing, &video->frameEvent, -cyclesLate);
if (GBRegisterSTATIsVblankIRQ(video->stat) || GBRegisterSTATIsOAMIRQ(video->stat)) {
video->p->memory.io[REG_IF] |= (1 << GB_IRQ_LCDSTAT);
@ -252,16 +252,16 @@ void _updateFrameCount(struct mTiming* timing, void* context, uint32_t cyclesLat
video->p->stream->postVideoFrame(video->p->stream, pixels, stride);
}
if (!GBRegisterLCDCIsEnable(video->p->memory.io[REG_LCDC])) {
mTimingSchedule(timing, &video->frameEvent, GB_VIDEO_TOTAL_LENGTH);
}
for (c = 0; c < mCoreCallbacksListSize(&video->p->coreCallbacks); ++c) {
struct mCoreCallbacks* callbacks = mCoreCallbacksListGetPointer(&video->p->coreCallbacks, c);
if (callbacks->videoFrameStarted) {
callbacks->videoFrameStarted(callbacks->context);
}
}
if (!GBRegisterLCDCIsEnable(video->p->memory.io[REG_LCDC])) {
mTimingSchedule(timing, &video->frameEvent, GB_VIDEO_TOTAL_LENGTH);
}
}
static void _cleanOAM(struct GBVideo* video, int y) {

View File

@ -158,6 +158,10 @@ void LR35902Tick(struct LR35902Core* cpu) {
void LR35902Run(struct LR35902Core* cpu) {
bool running = true;
while (running || cpu->executionState != LR35902_CORE_FETCH) {
if (cpu->cycles >= cpu->nextEvent) {
cpu->irqh.processEvents(cpu);
break;
}
_LR35902Step(cpu);
if (cpu->cycles + 2 >= cpu->nextEvent) {
int32_t diff = cpu->nextEvent - cpu->cycles;
@ -172,9 +176,5 @@ void LR35902Run(struct LR35902Core* cpu) {
cpu->executionState = LR35902_CORE_FETCH;
cpu->instruction(cpu);
++cpu->cycles;
if (cpu->cycles >= cpu->nextEvent) {
cpu->irqh.processEvents(cpu);
running = false;
}
}
}