all repos — mgba @ 7cb30ba83e0805cba80ee6ccca8fe9c1bdc61b39

mGBA Game Boy Advance Emulator

GBA Savedata: Fix crash when resizing flash
Vicki Pfau vi@endrift.com
Wed, 01 Nov 2017 16:57:39 -0700
commit

7cb30ba83e0805cba80ee6ccca8fe9c1bdc61b39

parent

74bd78f38226e00c900b3bb8672a828d750aced6

2 files changed, 10 insertions(+), 3 deletions(-)

jump to
M CHANGESCHANGES

@@ -24,6 +24,7 @@ - GB Video: Only trigger STAT write IRQs when screen is on (fixes mgba.io/i/912)

- GBA Cheats: Fix PARv3 slide codes (fixes mgba.io/i/919) - GBA Video: OBJWIN can change blend params after OBJ is drawn (fixes mgba.io/i/921) - GBA DMA: Fix invalid DMA reads (fixes mgba.io/i/142) + - GBA Savedata: Fix crash when resizing flash Misc: - GBA Timer: Use global cycles for timers - GBA: Extend oddly-sized ROMs to full address space (fixes mgba.io/i/722)
M src/gba/savedata.csrc/gba/savedata.c

@@ -576,9 +576,15 @@ savedata->currentBank = &savedata->data[bank << 16];

if (bank > 0 && savedata->type == SAVEDATA_FLASH512) { mLOG(GBA_SAVE, INFO, "Updating flash chip from 512kb to 1Mb"); savedata->type = SAVEDATA_FLASH1M; - if (savedata->vf && savedata->vf->size(savedata->vf) == SIZE_CART_FLASH512) { - savedata->vf->truncate(savedata->vf, SIZE_CART_FLASH1M); - memset(&savedata->data[SIZE_CART_FLASH512], 0xFF, SIZE_CART_FLASH512); + if (savedata->vf) { + savedata->vf->unmap(savedata->vf, savedata->data, SIZE_CART_FLASH512); + if (savedata->vf->size(savedata->vf) == SIZE_CART_FLASH512) { + savedata->vf->truncate(savedata->vf, SIZE_CART_FLASH1M); + savedata->data = savedata->vf->map(savedata->vf, SIZE_CART_FLASH1M, MAP_WRITE); + memset(&savedata->data[SIZE_CART_FLASH512], 0xFF, SIZE_CART_FLASH512); + } else { + savedata->data = savedata->vf->map(savedata->vf, SIZE_CART_FLASH1M, MAP_WRITE); + } } } }