GBA DMA: Emulate DMA bus
Jeffrey Pfau jeffrey@endrift.com
Sun, 02 Nov 2014 16:54:11 -0800
3 files changed,
29 insertions(+),
7 deletions(-)
M
src/gba/gba-memory.c
→
src/gba/gba-memory.c
@@ -209,9 +209,13 @@ value = 0xDEADBEEF;
#define LOAD_BAD \ GBALog(gba, GBA_LOG_GAME_ERROR, "Bad memory Load32: 0x%08X", address); \ - value = cpu->prefetch; \ - if (cpu->executionMode == MODE_THUMB) { \ - value |= value << 16; \ + if (cpu->cycles >= cpu->nextEvent) { \ + value = gba->bus; \ + } else { \ + value = cpu->prefetch; \ + if (cpu->executionMode == MODE_THUMB) { \ + value |= value << 16; \ + } \ } int32_t GBALoad32(struct ARMCore* cpu, uint32_t address, int* cycleCounter) {@@ -339,7 +343,11 @@ GBALog(gba, GBA_LOG_STUB, "Unimplemented memory Load16: 0x%08X", address);
break; default: GBALog(gba, GBA_LOG_GAME_ERROR, "Bad memory Load16: 0x%08X", address); - value = cpu->prefetch; + if (cpu->cycles >= cpu->nextEvent) { + value = gba->bus; + } else { + value = cpu->prefetch; + } break; }@@ -424,7 +432,11 @@ }
break; default: GBALog(gba, GBA_LOG_GAME_ERROR, "Bad memory Load8: 0x%08x", address); - value = cpu->prefetch & 0xFF; + if (cpu->cycles >= cpu->nextEvent) { + value = gba->bus; + } else { + value = cpu->prefetch; + } break; }@@ -1096,17 +1108,18 @@ cycles += memory->waitstatesSeq16[sourceRegion] + memory->waitstatesSeq16[destRegion];
} } + int32_t word; if (width == 4) { - int32_t word; word = cpu->memory.load32(cpu, source, 0); + gba->bus = word; cpu->memory.store32(cpu, dest, word, 0); source += sourceOffset; dest += destOffset; --wordsRemaining; } else { - uint16_t word; if (sourceRegion == REGION_CART2_EX && memory->savedata.type == SAVEDATA_EEPROM) { word = GBASavedataReadEEPROM(&memory->savedata); + gba->bus = word | (word << 16); cpu->memory.store16(cpu, dest, word, 0); source += sourceOffset; dest += destOffset;@@ -1117,12 +1130,14 @@ GBALog(gba, GBA_LOG_INFO, "Detected EEPROM savegame");
GBASavedataInitEEPROM(&memory->savedata); } word = cpu->memory.load16(cpu, source, 0); + gba->bus = word | (word << 16); GBASavedataWriteEEPROM(&memory->savedata, word, wordsRemaining); source += sourceOffset; dest += destOffset; --wordsRemaining; } else { word = cpu->memory.load16(cpu, source, 0); + gba->bus = word | (word << 16); cpu->memory.store16(cpu, dest, word, 0); source += sourceOffset; dest += destOffset;
M
src/gba/gba.c
→
src/gba/gba.c
@@ -210,6 +210,11 @@ int32_t cycles = cpu->cycles;
int32_t nextEvent = INT_MAX; int32_t testEvent; + gba->bus = cpu->prefetch; + if (cpu->executionMode == MODE_THUMB) { + gba->bus |= cpu->prefetch << 16; + } + if (gba->springIRQ) { ARMRaiseIRQ(cpu); gba->springIRQ = 0;
M
src/gba/gba.h
→
src/gba/gba.h
@@ -94,6 +94,8 @@ struct GBASync* sync;
struct ARMDebugger* debugger; + uint32_t bus; + int timersEnabled; struct GBATimer timers[4];