all repos — mgba @ 31862db5a5ce03443b167053dee051664455543c

mGBA Game Boy Advance Emulator

GBA Memory: Fix DMA register writing behavior (fixes #148)
Jeffrey Pfau jeffrey@endrift.com
Wed, 04 Nov 2015 20:19:12 -0800
commit

31862db5a5ce03443b167053dee051664455543c

parent

ec32efd8e40c716b0d7908dfe25815262eb52b2f

4 files changed, 23 insertions(+), 26 deletions(-)

jump to
M CHANGESCHANGES

@@ -7,13 +7,13 @@ - Customization of GIF recording

Bugfixes: - Util: Fix PowerPC PNG read/write pixel order - Qt: Use safer isLoaded check in GameController - - GBA Memory: Fix DMAs from BIOS while not in BIOS - GBA: Fix idle skip state being retained between games - Qt: Fix a race condition in PainterGL that could lead to a crash - Qt: Fix clear button/analog buttons in gamepad mapper on some platforms - GBA Video: Fix _mix for 15-bit color - VFS: Fix VFileReadline and remove _vfdReadline - Qt: Fix font size in memory viewer + - GBA Memory: Fix DMA register writing behavior Misc: - Qt: Window size command line options are now supported - Qt: Increase usability of key mapper
M src/gba/io.csrc/gba/io.c

@@ -535,28 +535,28 @@ case REG_FIFO_B_LO:

GBAAudioWriteFIFO(&gba->audio, address, value); break; case REG_DMA0SAD_LO: - GBAMemoryWriteDMASAD(gba, 0, value); + value = GBAMemoryWriteDMASAD(gba, 0, value); break; case REG_DMA0DAD_LO: - GBAMemoryWriteDMADAD(gba, 0, value); + value = GBAMemoryWriteDMADAD(gba, 0, value); break; case REG_DMA1SAD_LO: - GBAMemoryWriteDMASAD(gba, 1, value); + value = GBAMemoryWriteDMASAD(gba, 1, value); break; case REG_DMA1DAD_LO: - GBAMemoryWriteDMADAD(gba, 1, value); + value = GBAMemoryWriteDMADAD(gba, 1, value); break; case REG_DMA2SAD_LO: - GBAMemoryWriteDMASAD(gba, 2, value); + value = GBAMemoryWriteDMASAD(gba, 2, value); break; case REG_DMA2DAD_LO: - GBAMemoryWriteDMADAD(gba, 2, value); + value = GBAMemoryWriteDMADAD(gba, 2, value); break; case REG_DMA3SAD_LO: - GBAMemoryWriteDMASAD(gba, 3, value); + value = GBAMemoryWriteDMASAD(gba, 3, value); break; case REG_DMA3DAD_LO: - GBAMemoryWriteDMADAD(gba, 3, value); + value = GBAMemoryWriteDMADAD(gba, 3, value); break; default: GBAIOWrite(gba, address, value & 0xFFFF);
M src/gba/memory.csrc/gba/memory.c

@@ -330,12 +330,7 @@ if (memory->activeRegion == REGION_BIOS) { \

LOAD_32(value, address, memory->bios); \ } else { \ GBALog(gba, GBA_LOG_GAME_ERROR, "Bad BIOS Load32: 0x%08X", address); \ - if (memory->activeDMA) { \ - /* TODO: Test on hardware */ \ - value = 0; \ - } else { \ - value = memory->biosPrefetch; \ - } \ + value = memory->biosPrefetch; \ } \ } else { \ GBALog(gba, GBA_LOG_GAME_ERROR, "Bad memory Load32: 0x%08X", address); \

@@ -451,11 +446,7 @@ if (memory->activeRegion == REGION_BIOS) {

LOAD_16(value, address, memory->bios); } else { GBALog(gba, GBA_LOG_GAME_ERROR, "Bad BIOS Load16: 0x%08X", address); - if (memory->activeDMA) { - value = 0; - } else { - value = (memory->biosPrefetch >> ((address & 2) * 8)) & 0xFFFF; - } + value = (memory->biosPrefetch >> ((address & 2) * 8)) & 0xFFFF; } } else { GBALog(gba, GBA_LOG_GAME_ERROR, "Bad memory Load16: 0x%08X", address);

@@ -1320,14 +1311,20 @@ cpu->memory.activeNonseqCycles32 = memory->waitstatesNonseq32[memory->activeRegion];

cpu->memory.activeNonseqCycles16 = memory->waitstatesNonseq16[memory->activeRegion]; } -void GBAMemoryWriteDMASAD(struct GBA* gba, int dma, uint32_t address) { +uint32_t GBAMemoryWriteDMASAD(struct GBA* gba, int dma, uint32_t address) { struct GBAMemory* memory = &gba->memory; - memory->dma[dma].source = address & 0x0FFFFFFE; + if ((dma >= 1 || address < BASE_CART0) && address >= BASE_WORKING_RAM && address < BASE_CART_SRAM) { + memory->dma[dma].source = address & 0x0FFFFFFE; + } + return memory->dma[dma].source; } -void GBAMemoryWriteDMADAD(struct GBA* gba, int dma, uint32_t address) { +uint32_t GBAMemoryWriteDMADAD(struct GBA* gba, int dma, uint32_t address) { struct GBAMemory* memory = &gba->memory; - memory->dma[dma].dest = address & 0x0FFFFFFE; + if ((dma >= 1 || address < BASE_CART0) && address >= BASE_WORKING_RAM && address < BASE_CART_SRAM) { + memory->dma[dma].dest = address & 0x0FFFFFFE; + } + return memory->dma[dma].dest; } void GBAMemoryWriteDMACNT_LO(struct GBA* gba, int dma, uint16_t count) {
M src/gba/memory.hsrc/gba/memory.h

@@ -166,8 +166,8 @@ int* cycleCounter);

void GBAAdjustWaitstates(struct GBA* gba, uint16_t parameters); -void GBAMemoryWriteDMASAD(struct GBA* gba, int dma, uint32_t address); -void GBAMemoryWriteDMADAD(struct GBA* gba, int dma, uint32_t address); +uint32_t GBAMemoryWriteDMASAD(struct GBA* gba, int dma, uint32_t address); +uint32_t GBAMemoryWriteDMADAD(struct GBA* gba, int dma, uint32_t address); void GBAMemoryWriteDMACNT_LO(struct GBA* gba, int dma, uint16_t count); uint16_t GBAMemoryWriteDMACNT_HI(struct GBA* gba, int dma, uint16_t control);