GBA: Make sure unloading a ROM frees the AGBPrint buffer

This commit is contained in:
Vicki Pfau 2023-09-15 22:06:05 -07:00
parent 4b9072de03
commit b46278b3ed
3 changed files with 17 additions and 11 deletions

View File

@ -147,6 +147,7 @@ void GBAMemoryInit(struct GBA* gba);
void GBAMemoryDeinit(struct GBA* gba);
void GBAMemoryReset(struct GBA* gba);
void GBAMemoryClearAGBPrint(struct GBA* gba);
uint32_t GBALoad32(struct ARMCore* cpu, uint32_t address, int* cycleCounter);
uint32_t GBALoad16(struct ARMCore* cpu, uint32_t address, int* cycleCounter);

View File

@ -132,6 +132,7 @@ static void GBAInit(void* cpu, struct mCPUComponent* component) {
}
void GBAUnloadROM(struct GBA* gba) {
GBAMemoryClearAGBPrint(gba);
if (gba->memory.rom && !gba->isPristine) {
if (gba->yankedRomSize) {
gba->yankedRomSize = 0;

View File

@ -128,6 +128,21 @@ void GBAMemoryReset(struct GBA* gba) {
GBAAdjustWaitstates(gba, 0);
GBAAdjustEWRAMWaitstates(gba, 0x0D00);
GBAMemoryClearAGBPrint(gba);
gba->memory.prefetch = false;
gba->memory.lastPrefetchedPc = 0;
if (!gba->memory.wram || !gba->memory.iwram) {
GBAMemoryDeinit(gba);
mLOG(GBA_MEM, FATAL, "Could not map memory");
}
GBADMAReset(gba);
memset(&gba->memory.matrix, 0, sizeof(gba->memory.matrix));
}
void GBAMemoryClearAGBPrint(struct GBA* gba) {
gba->memory.activeRegion = -1;
gba->memory.agbPrintProtect = 0;
gba->memory.agbPrintBase = 0;
@ -140,17 +155,6 @@ void GBAMemoryReset(struct GBA* gba) {
mappedMemoryFree(gba->memory.agbPrintBufferBackup, GBA_SIZE_AGB_PRINT);
gba->memory.agbPrintBufferBackup = NULL;
}
gba->memory.prefetch = false;
gba->memory.lastPrefetchedPc = 0;
if (!gba->memory.wram || !gba->memory.iwram) {
GBAMemoryDeinit(gba);
mLOG(GBA_MEM, FATAL, "Could not map memory");
}
GBADMAReset(gba);
memset(&gba->memory.matrix, 0, sizeof(gba->memory.matrix));
}
static void _analyzeForIdleLoop(struct GBA* gba, struct ARMCore* cpu, uint32_t address) {