LR35902: Fix core never exiting with certain event patterns

This commit is contained in:
Jeffrey Pfau 2016-09-27 04:42:20 -07:00
parent fc69cdce60
commit 559c3212fd
2 changed files with 9 additions and 3 deletions

View File

@ -22,6 +22,7 @@ Bugfixes:
- GB: Initialize audio properly - GB: Initialize audio properly
- GB MBC: Fix RTC access when no save file is loaded - GB MBC: Fix RTC access when no save file is loaded
- GB: Properly clear KEY1 bit 0 when switching speeds - GB: Properly clear KEY1 bit 0 when switching speeds
- LR35902: Fix core never exiting with certain event patterns
Misc: Misc:
- All: Only update version info if needed - All: Only update version info if needed
- FFmpeg: Encoding cleanup - FFmpeg: Encoding cleanup

View File

@ -156,13 +156,16 @@ void LR35902Tick(struct LR35902Core* cpu) {
} }
void LR35902Run(struct LR35902Core* cpu) { void LR35902Run(struct LR35902Core* cpu) {
while (true) { bool running = 1;
while (running > 0 || cpu->executionState != LR35902_CORE_FETCH) {
_LR35902Step(cpu); _LR35902Step(cpu);
if (cpu->cycles + 2 >= cpu->nextEvent) { if (cpu->cycles + 2 >= cpu->nextEvent) {
int32_t diff = cpu->nextEvent - cpu->cycles; int32_t diff = cpu->nextEvent - cpu->cycles;
cpu->cycles = cpu->nextEvent; cpu->cycles = cpu->nextEvent;
cpu->executionState += diff;
cpu->irqh.processEvents(cpu); cpu->irqh.processEvents(cpu);
cpu->cycles += 2 - diff; cpu->cycles += 2 - diff;
running = -1;
} else { } else {
cpu->cycles += 2; cpu->cycles += 2;
} }
@ -170,8 +173,10 @@ void LR35902Run(struct LR35902Core* cpu) {
cpu->instruction(cpu); cpu->instruction(cpu);
++cpu->cycles; ++cpu->cycles;
if (cpu->cycles >= cpu->nextEvent) { if (cpu->cycles >= cpu->nextEvent) {
break; running = 0;
} }
} }
cpu->irqh.processEvents(cpu); if (!running) {
cpu->irqh.processEvents(cpu);
}
} }