GB, GBA: Clean up some corner cases with ROM fd closing

This commit is contained in:
Vicki Pfau 2024-10-08 04:34:30 -07:00
parent 7e474db93a
commit eaf45b9ab8
5 changed files with 6 additions and 11 deletions

View File

@ -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) {

View File

@ -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);

View File

@ -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;
}

View File

@ -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;

View File

@ -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];