GBA DMA: Fix temporal sorting of DMAs of different priorities

This commit is contained in:
Vicki Pfau 2018-09-18 00:42:32 -07:00
parent ce658ff3a5
commit 108b0fc867
2 changed files with 8 additions and 3 deletions

View File

@ -54,6 +54,7 @@ Bugfixes:
- 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)

View File

@ -202,13 +202,17 @@ void _dmaEvent(struct mTiming* timing, void* context, uint32_t cyclesLate) {
void GBADMAUpdate(struct GBA* gba) {
int i;
struct GBAMemory* memory = &gba->memory;
memory->activeDMA = -1;
uint32_t currentTime = mTimingCurrentTime(&gba->timing);
int32_t leastTime = INT_MAX;
memory->activeDMA = -1;
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;
}
}
}