all repos — mgba @ db4a873d9caab6fbb4d368690b382f7082dd1b12

mGBA Game Boy Advance Emulator

GB: Rearrange some scheduling for better callback ability
Vicki Pfau vi@endrift.com
Tue, 18 Apr 2017 01:51:41 -0700
commit

db4a873d9caab6fbb4d368690b382f7082dd1b12

parent

3b69fb767ccb42325e4f6b49b2ab8f39c13e7b40

2 files changed, 9 insertions(+), 9 deletions(-)

jump to
M src/gb/video.csrc/gb/video.c

@@ -127,7 +127,7 @@ next = GB_VIDEO_HORIZONTAL_LENGTH;

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,15 +252,15 @@ video->renderer->getPixels(video->renderer, &stride, (const void**) &pixels);

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); } }
M src/lr35902/lr35902.csrc/lr35902/lr35902.c

@@ -158,6 +158,10 @@

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 @@ }

cpu->executionState = LR35902_CORE_FETCH; cpu->instruction(cpu); ++cpu->cycles; - if (cpu->cycles >= cpu->nextEvent) { - cpu->irqh.processEvents(cpu); - running = false; - } } }