GBA DMA: Fix temporal sorting of DMAs of different priorities
Vicki Pfau vi@endrift.com
Tue, 18 Sep 2018 00:42:32 -0700
2 files changed,
8 insertions(+),
3 deletions(-)
M
CHANGES
→
CHANGES
@@ -54,6 +54,7 @@ - GBA Serialize: Fix loading states in Hblank
- PSP2: Fix more issues causing poor audio - GBA Memory: Fix Vast Fame support (taizou) (fixes mgba.io/i/1170) - GB, GBA Savedata: Fix unmasking savedata crash + - GBA DMA: Fix temporal sorting of DMAs of different priorities Misc: - GBA Timer: Use global cycles for timers - GBA: Extend oddly-sized ROMs to full address space (fixes mgba.io/i/722)
M
src/gba/dma.c
→
src/gba/dma.c
@@ -202,13 +202,17 @@
void GBADMAUpdate(struct GBA* gba) { int i; struct GBAMemory* memory = &gba->memory; + uint32_t currentTime = mTimingCurrentTime(&gba->timing); + int32_t leastTime = INT_MAX; memory->activeDMA = -1; - uint32_t currentTime = mTimingCurrentTime(&gba->timing); for (i = 0; i < 4; ++i) { struct GBADMA* dma = &memory->dma[i]; if (GBADMARegisterIsEnable(dma->reg) && dma->nextCount) { - memory->activeDMA = i; - break; + int32_t time = dma->when - currentTime; + if (memory->activeDMA == -1 || (dma->count == dma->nextCount && time < leastTime)) { + leastTime = time; + memory->activeDMA = i; + } } }