From cf06497456cf576d8c68de67cf039a07160e0e49 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Fri, 18 Feb 2022 20:31:05 -0800 Subject: [PATCH] GBA DMA: Enhanced logging (closes #2454) --- CHANGES | 1 + include/mgba/internal/gba/dma.h | 4 ++++ src/gba/dma.c | 20 ++++++++++++++------ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/CHANGES b/CHANGES index 846ab2a3c..a76c5c7af 100644 --- a/CHANGES +++ b/CHANGES @@ -44,6 +44,7 @@ Misc: - Core: Suspend runloop when a core crashes - GB Video: Add default SGB border - GBA: Automatically skip BIOS if ROM has invalid logo + - GBA DMA: Enhanced logging (closes mgba.io/i/2454) - mGUI: Add margin to right-aligned menu text (fixes mgba.io/i/871) - Qt: Rearrange menus some - Qt: Clean up cheats dialog diff --git a/include/mgba/internal/gba/dma.h b/include/mgba/internal/gba/dma.h index 6f880c971..192b3995a 100644 --- a/include/mgba/internal/gba/dma.h +++ b/include/mgba/internal/gba/dma.h @@ -10,6 +10,8 @@ CXX_GUARD_START +#include + enum GBADMAControl { GBA_DMA_INCREMENT = 0, GBA_DMA_DECREMENT = 1, @@ -34,6 +36,8 @@ DECL_BITS(GBADMARegister, Timing, 12, 2); DECL_BIT(GBADMARegister, DoIRQ, 14); DECL_BIT(GBADMARegister, Enable, 15); +mLOG_DECLARE_CATEGORY(GBA_DMA); + struct GBADMA { GBADMARegister reg; diff --git a/src/gba/dma.c b/src/gba/dma.c index 5807e506f..759140da6 100644 --- a/src/gba/dma.c +++ b/src/gba/dma.c @@ -8,6 +8,8 @@ #include #include +mLOG_DEFINE_CATEGORY(GBA_DMA, "GBA DMA", "gba.dma"); + static void _dmaEvent(struct mTiming* timing, void* context, uint32_t cyclesLate); static void GBADMAService(struct GBA* gba, int number, struct GBADMA* info); @@ -43,10 +45,10 @@ static bool _isValidDMADAD(int dma, uint32_t address) { uint32_t GBADMAWriteSAD(struct GBA* gba, int dma, uint32_t address) { struct GBAMemory* memory = &gba->memory; - address &= 0x0FFFFFFE; if (_isValidDMASAD(dma, address)) { - memory->dma[dma].source = address; + memory->dma[dma].source = address & 0x0FFFFFFE; } else { + mLOG(GBA_DMA, GAME_ERROR, "Invalid DMA source address: 0x%08X", address); memory->dma[dma].source = 0; } return memory->dma[dma].source; @@ -57,6 +59,8 @@ uint32_t GBADMAWriteDAD(struct GBA* gba, int dma, uint32_t address) { address &= 0x0FFFFFFE; if (_isValidDMADAD(dma, address)) { memory->dma[dma].dest = address; + } else { + mLOG(GBA_DMA, GAME_ERROR, "Invalid DMA destination address: 0x%08X", address); } return memory->dma[dma].dest; } @@ -78,7 +82,7 @@ uint16_t GBADMAWriteCNT_HI(struct GBA* gba, int dma, uint16_t control) { currentDma->reg = control; if (GBADMARegisterIsDRQ(currentDma->reg)) { - mLOG(GBA_MEM, STUB, "DRQ not implemented"); + mLOG(GBA_DMA, STUB, "DRQ not implemented"); } if (!wasEnabled && GBADMARegisterIsEnable(currentDma->reg)) { @@ -87,11 +91,15 @@ uint16_t GBADMAWriteCNT_HI(struct GBA* gba, int dma, uint16_t control) { uint32_t width = 2 << GBADMARegisterGetWidth(currentDma->reg); if (currentDma->nextSource & (width - 1)) { - mLOG(GBA_MEM, GAME_ERROR, "Misaligned DMA source address: 0x%08X", currentDma->nextSource); + mLOG(GBA_DMA, GAME_ERROR, "Misaligned DMA source address: 0x%08X", currentDma->nextSource); } if (currentDma->nextDest & (width - 1)) { - mLOG(GBA_MEM, GAME_ERROR, "Misaligned DMA destination address: 0x%08X", currentDma->nextDest); + mLOG(GBA_DMA, GAME_ERROR, "Misaligned DMA destination address: 0x%08X", currentDma->nextDest); } + mLOG(GBA_DMA, INFO, "Starting DMA %i 0x%08X -> 0x%08X (%04X:%04X)", dma, + currentDma->nextSource, currentDma->nextDest, + currentDma->reg, currentDma->count & 0xFFFF); + currentDma->nextSource &= -width; currentDma->nextDest &= -width; @@ -114,7 +122,7 @@ void GBADMASchedule(struct GBA* gba, int number, struct GBADMA* info) { case GBA_DMA_TIMING_CUSTOM: switch (number) { case 0: - mLOG(GBA_MEM, WARN, "Discarding invalid DMA0 scheduling"); + mLOG(GBA_DMA, WARN, "Discarding invalid DMA0 scheduling"); return; case 1: case 2: