From eaf45b9ab8d2a5902a80fbea5a9210fcda08a7a9 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Tue, 8 Oct 2024 04:34:30 -0700 Subject: [PATCH] GB, GBA: Clean up some corner cases with ROM fd closing --- src/gb/gb.c | 4 +--- src/gb/memory.c | 2 -- src/gba/core.c | 3 +++ src/gba/gba.c | 6 ++---- src/gba/memory.c | 2 -- 5 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/gb/gb.c b/src/gb/gb.c index fa0d6482f..875cbf86e 100644 --- a/src/gb/gb.c +++ b/src/gb/gb.c @@ -483,12 +483,10 @@ void GBApplyPatch(struct GB* gb, struct Patch* patch) { mappedMemoryFree(newRom, GB_SIZE_CART_MAX); return; } - if (gb->romVf) { + if (gb->romVf && gb->isPristine) { #ifndef FIXED_ROM_BUFFER gb->romVf->unmap(gb->romVf, gb->memory.rom, gb->pristineRomSize); #endif - gb->romVf->close(gb->romVf); - gb->romVf = NULL; } gb->isPristine = false; if (gb->memory.romBase == gb->memory.rom) { diff --git a/src/gb/memory.c b/src/gb/memory.c index e41050784..dccd91e08 100644 --- a/src/gb/memory.c +++ b/src/gb/memory.c @@ -1017,8 +1017,6 @@ void _pristineCow(struct GB* gb) { } if (gb->romVf) { gb->romVf->unmap(gb->romVf, gb->memory.rom, gb->memory.romSize); - gb->romVf->close(gb->romVf); - gb->romVf = NULL; } gb->memory.rom = newRom; GBMBCSwitchBank(gb, gb->memory.currentBank); diff --git a/src/gba/core.c b/src/gba/core.c index e81e66dac..1d3fffb9e 100644 --- a/src/gba/core.c +++ b/src/gba/core.c @@ -668,6 +668,9 @@ static size_t _GBACoreROMSize(const struct mCore* core) { if (gba->romVf) { return gba->romVf->size(gba->romVf); } + if (gba->mbVf) { + return gba->mbVf->size(gba->mbVf); + } return gba->pristineRomSize; } diff --git a/src/gba/gba.c b/src/gba/gba.c index 187d83373..6b833838e 100644 --- a/src/gba/gba.c +++ b/src/gba/gba.c @@ -557,16 +557,14 @@ void GBAApplyPatch(struct GBA* gba, struct Patch* patch) { mappedMemoryFree(newRom, GBA_SIZE_ROM0); return; } - if (gba->romVf) { + if (gba->memory.rom) { #ifndef FIXED_ROM_BUFFER if (!gba->isPristine) { - mappedMemoryFree(gba->memory.rom, GBA_SIZE_ROM0); + mappedMemoryFree(gba->memory.rom, gba->memory.romSize); } else { gba->romVf->unmap(gba->romVf, gba->memory.rom, gba->pristineRomSize); } #endif - gba->romVf->close(gba->romVf); - gba->romVf = NULL; } gba->isPristine = false; gba->memory.rom = newRom; diff --git a/src/gba/memory.c b/src/gba/memory.c index 09d3e7a74..3243fc5a1 100644 --- a/src/gba/memory.c +++ b/src/gba/memory.c @@ -1894,8 +1894,6 @@ void _pristineCow(struct GBA* gba) { } if (gba->romVf) { gba->romVf->unmap(gba->romVf, gba->memory.rom, gba->memory.romSize); - gba->romVf->close(gba->romVf); - gba->romVf = NULL; } gba->memory.rom = newRom; gba->memory.hw.gpioBase = &((uint16_t*) gba->memory.rom)[GPIO_REG_DATA >> 1];