all repos — mgba @ 50d735b99b0dbb6e24eda5c40176f1519dc651ec

mGBA Game Boy Advance Emulator

GBA Savedata: EEPROM performance fixes
Vicki Pfau vi@endrift.com
Fri, 12 Oct 2018 11:11:48 -0700
commit

50d735b99b0dbb6e24eda5c40176f1519dc651ec

parent

af1d114f49450c39e0253500952a94fe490e6734

5 files changed, 28 insertions(+), 13 deletions(-)

jump to
M CHANGESCHANGES

@@ -1,6 +1,8 @@

0.8.0: (Future) Bugfixes: - GBA: All IRQs have 7 cycle delay (fixes mgba.io/i/539, mgba.io/i/1208) +Misc: + - GBA Savedata: EEPROM performance fixes 0.7.0: (Future) Features:
M include/mgba/internal/gba/savedata.hinclude/mgba/internal/gba/savedata.h

@@ -23,7 +23,8 @@ SAVEDATA_FORCE_NONE = 0,

SAVEDATA_SRAM = 1, SAVEDATA_FLASH512 = 2, SAVEDATA_FLASH1M = 3, - SAVEDATA_EEPROM = 4 + SAVEDATA_EEPROM = 4, + SAVEDATA_EEPROM512 = 5 }; enum SavedataCommand {
M src/gba/dma.csrc/gba/dma.c

@@ -266,11 +266,7 @@ cpu->memory.store32(cpu, dest, memory->dmaTransferRegister, 0);

memory->dmaTransferRegister &= 0xFFFF0000; memory->dmaTransferRegister |= memory->dmaTransferRegister >> 16; } else { - if (sourceRegion == REGION_CART2_EX && memory->savedata.type == SAVEDATA_EEPROM) { - if (memory->savedata.type == SAVEDATA_AUTODETECT) { - mLOG(GBA_MEM, INFO, "Detected EEPROM savegame"); - GBASavedataInitEEPROM(&memory->savedata); - } + if (sourceRegion == REGION_CART2_EX && (memory->savedata.type == SAVEDATA_EEPROM || memory->savedata.type == SAVEDATA_EEPROM512)) { memory->dmaTransferRegister = GBASavedataReadEEPROM(&memory->savedata); } else { if (source) {
M src/gba/memory.csrc/gba/memory.c

@@ -558,7 +558,7 @@ }

break; case REGION_CART2_EX: wait = memory->waitstatesNonseq16[address >> BASE_OFFSET]; - if (memory->savedata.type == SAVEDATA_EEPROM) { + if (memory->savedata.type == SAVEDATA_EEPROM || memory->savedata.type == SAVEDATA_EEPROM512) { value = GBASavedataReadEEPROM(&memory->savedata); } else if ((address & (SIZE_CART0 - 1)) < memory->romSize) { LOAD_16(value, address & (SIZE_CART0 - 2), memory->rom);
M src/gba/savedata.csrc/gba/savedata.c

@@ -77,6 +77,9 @@ break;

case SAVEDATA_EEPROM: mappedMemoryFree(savedata->data, SIZE_CART_EEPROM); break; + case SAVEDATA_EEPROM512: + mappedMemoryFree(savedata->data, SIZE_CART_EEPROM512); + break; case SAVEDATA_FORCE_NONE: case SAVEDATA_AUTODETECT: break;

@@ -127,6 +130,8 @@ case SAVEDATA_FLASH1M:

return out->write(out, savedata->data, SIZE_CART_FLASH1M) == SIZE_CART_FLASH1M; case SAVEDATA_EEPROM: return out->write(out, savedata->data, SIZE_CART_EEPROM) == SIZE_CART_EEPROM; + case SAVEDATA_EEPROM512: + return out->write(out, savedata->data, SIZE_CART_EEPROM512) == SIZE_CART_EEPROM512; case SAVEDATA_AUTODETECT: case SAVEDATA_FORCE_NONE: return true;

@@ -152,7 +157,9 @@ return SIZE_CART_FLASH512;

case SAVEDATA_FLASH1M: return SIZE_CART_FLASH1M; case SAVEDATA_EEPROM: - return (savedata->vf && savedata->vf->size(savedata->vf) == SIZE_CART_EEPROM512) ? SIZE_CART_EEPROM512 : SIZE_CART_EEPROM; + return SIZE_CART_EEPROM; + case SAVEDATA_EEPROM512: + return SIZE_CART_EEPROM512; case SAVEDATA_FORCE_NONE: return 0; case SAVEDATA_AUTODETECT:

@@ -218,6 +225,7 @@ savedata->type = type;

GBASavedataInitFlash(savedata); break; case SAVEDATA_EEPROM: + case SAVEDATA_EEPROM512: GBASavedataInitEEPROM(savedata); break; case SAVEDATA_SRAM:

@@ -263,22 +271,26 @@ }

void GBASavedataInitEEPROM(struct GBASavedata* savedata) { if (savedata->type == SAVEDATA_AUTODETECT) { - savedata->type = SAVEDATA_EEPROM; - } else { + savedata->type = SAVEDATA_EEPROM512; + } else if (savedata->type != SAVEDATA_EEPROM512 && savedata->type != SAVEDATA_EEPROM) { mLOG(GBA_SAVE, WARN, "Can't re-initialize savedata"); return; } int32_t eepromSize = SIZE_CART_EEPROM512; + if (savedata->type == SAVEDATA_EEPROM) { + eepromSize = SIZE_CART_EEPROM; + } off_t end; if (!savedata->vf) { end = 0; savedata->data = anonymousMemoryMap(SIZE_CART_EEPROM); } else { end = savedata->vf->size(savedata->vf); - if (end < SIZE_CART_EEPROM512) { - savedata->vf->truncate(savedata->vf, SIZE_CART_EEPROM512); - } else if (end > SIZE_CART_EEPROM512) { + if (end < eepromSize) { + savedata->vf->truncate(savedata->vf, eepromSize); + } else if (end >= SIZE_CART_EEPROM) { eepromSize = SIZE_CART_EEPROM; + savedata->type = SAVEDATA_EEPROM; } savedata->data = savedata->vf->map(savedata->vf, eepromSize, savedata->mapMode); }

@@ -420,6 +432,10 @@ static void _ensureEeprom(struct GBASavedata* savedata, uint32_t size) {

if (size < SIZE_CART_EEPROM512) { return; } + if (savedata->type == SAVEDATA_EEPROM) { + return; + } + savedata->type = SAVEDATA_EEPROM; if (!savedata->vf || savedata->vf->size(savedata->vf) > SIZE_CART_EEPROM512) { return; }