GBA Savedata: Fix crash when resizing flash

This commit is contained in:
Vicki Pfau 2017-11-01 16:57:39 -07:00
parent 74bd78f382
commit 7cb30ba83e
2 changed files with 10 additions and 3 deletions

View File

@ -24,6 +24,7 @@ Bugfixes:
- 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)

View File

@ -576,9 +576,15 @@ void _flashSwitchBank(struct GBASavedata* savedata, int bank) {
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);
}
}
}
}