all repos — mgba @ 039a64ee62da13d83c09c7f7f017a69358e19c71

mGBA Game Boy Advance Emulator

SM83: Improve mid-M-cycle interrupts
Vicki Pfau vi@endrift.com
Wed, 17 Mar 2021 18:12:37 -0700
commit

039a64ee62da13d83c09c7f7f017a69358e19c71

parent

f853de37b9969afc7ccd145f6e7f06cf9e76a3eb

2 files changed, 14 insertions(+), 5 deletions(-)

jump to
M CHANGESCHANGES

@@ -64,6 +64,7 @@ - GBA Video: Implement green swap (fixes mgba.io/i/1609)

- GBA Video: Emulate sprite cycle limits in OpenGL renderer (fixes mgba.io/i/1635) - GBA Video: Fix OBJWIN erratic rendering in OpenGL renderer - SM83: Emulate HALT bug + - SM83: Improve mid-M-cycle interrupts Other fixes: - 3DS: Fix thread cleanup - All: Improve export headers (fixes mgba.io/i/1738)
M src/sm83/sm83.csrc/sm83/sm83.c

@@ -153,11 +153,19 @@ bool running = true;

_SM83Step(cpu); int t = cpu->tMultiplier; if (cpu->cycles + t * 2 >= cpu->nextEvent) { - int32_t diff = cpu->nextEvent - cpu->cycles; - cpu->cycles = cpu->nextEvent; - cpu->executionState += diff >> (t - 1); // NB: This assumes tMultiplier is either 1 or 2 - cpu->irqh.processEvents(cpu); - cpu->cycles += (SM83_CORE_EXECUTE - cpu->executionState) * t; + if (cpu->cycles >= cpu->nextEvent) { + cpu->irqh.processEvents(cpu); + } + cpu->cycles += t; + ++cpu->executionState; + if (cpu->cycles >= cpu->nextEvent) { + cpu->irqh.processEvents(cpu); + } + cpu->cycles += t; + ++cpu->executionState; + if (cpu->cycles >= cpu->nextEvent) { + cpu->irqh.processEvents(cpu); + } running = false; } else { cpu->cycles += t * 2;