all repos — mgba @ 6456a886695e6290fee373255fef014f47c20562

mGBA Game Boy Advance Emulator

Reset memory when reseting the board (fixes #94)
Jeffrey Pfau jeffrey@endrift.com
Sat, 19 Jul 2014 04:13:25 -0700
commit

6456a886695e6290fee373255fef014f47c20562

parent

823b97603a2538b6b103b8f2388a7124cdcde5fa

3 files changed, 37 insertions(+), 18 deletions(-)

jump to
M src/gba/gba-memory.csrc/gba/gba-memory.c

@@ -31,27 +31,12 @@ cpu->memory.store8 = GBAStore8;

gba->memory.bios = (uint32_t*) hleBios; gba->memory.fullBios = 0; - gba->memory.wram = anonymousMemoryMap(SIZE_WORKING_RAM); - gba->memory.iwram = anonymousMemoryMap(SIZE_WORKING_IRAM); + gba->memory.wram = 0; + gba->memory.iwram = 0; gba->memory.rom = 0; gba->memory.gpio.p = gba; - memset(gba->memory.io, 0, sizeof(gba->memory.io)); - memset(gba->memory.dma, 0, sizeof(gba->memory.dma)); + int i; - for (i = 0; i < 4; ++i) { - gba->memory.dma[i].count = 0x10000; - gba->memory.dma[i].nextEvent = INT_MAX; - } - gba->memory.activeDMA = -1; - gba->memory.nextDMA = INT_MAX; - gba->memory.eventDiff = 0; - - if (!gba->memory.wram || !gba->memory.iwram) { - GBAMemoryDeinit(gba); - GBALog(gba, GBA_LOG_FATAL, "Could not map memory"); - return; - } - for (i = 0; i < 16; ++i) { gba->memory.waitstatesNonseq16[i] = GBA_BASE_WAITSTATES[i]; gba->memory.waitstatesSeq16[i] = GBA_BASE_WAITSTATES_SEQ[i];

@@ -90,6 +75,35 @@ if (gba->memory.rom) {

mappedMemoryFree(gba->memory.rom, gba->memory.romSize); } GBASavedataDeinit(&gba->memory.savedata); +} + +void GBAMemoryReset(struct GBA* gba) { + if (gba->memory.wram) { + mappedMemoryFree(gba->memory.wram, SIZE_WORKING_RAM); + } + gba->memory.wram = anonymousMemoryMap(SIZE_WORKING_RAM); + + if (gba->memory.iwram) { + mappedMemoryFree(gba->memory.iwram, SIZE_WORKING_IRAM); + } + gba->memory.iwram = anonymousMemoryMap(SIZE_WORKING_IRAM); + + memset(gba->memory.io, 0, sizeof(gba->memory.io)); + memset(gba->memory.dma, 0, sizeof(gba->memory.dma)); + int i; + for (i = 0; i < 4; ++i) { + gba->memory.dma[i].count = 0x10000; + gba->memory.dma[i].nextEvent = INT_MAX; + } + gba->memory.activeDMA = -1; + gba->memory.nextDMA = INT_MAX; + gba->memory.eventDiff = 0; + + if (!gba->memory.wram || !gba->memory.iwram) { + GBAMemoryDeinit(gba); + GBALog(gba, GBA_LOG_FATAL, "Could not map memory"); + return; + } } static void GBASetActiveRegion(struct ARMCore* cpu, uint32_t address) {
M src/gba/gba-memory.hsrc/gba/gba-memory.h

@@ -138,6 +138,8 @@

void GBAMemoryInit(struct GBA* gba); void GBAMemoryDeinit(struct GBA* gba); +void GBAMemoryReset(struct GBA* gba); + int32_t GBALoad32(struct ARMCore* cpu, uint32_t address, int* cycleCounter); int16_t GBALoad16(struct ARMCore* cpu, uint32_t address, int* cycleCounter); uint16_t GBALoadU16(struct ARMCore* cpu, uint32_t address, int* cycleCounter);
M src/gba/gba.csrc/gba/gba.c

@@ -179,6 +179,9 @@ ARMSetPrivilegeMode(cpu, MODE_SUPERVISOR);

cpu->gprs[ARM_SP] = SP_BASE_SUPERVISOR; ARMSetPrivilegeMode(cpu, MODE_SYSTEM); cpu->gprs[ARM_SP] = SP_BASE_SYSTEM; + + struct GBA* gba = (struct GBA*) cpu->master; + GBAMemoryReset(gba); } static void GBAProcessEvents(struct ARMCore* cpu) {