From 5ee336d274fd481c9eb4eb0ee9b49d598aa4340a Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Mon, 4 Aug 2014 23:46:33 -0700 Subject: [PATCH] Fix masking savegames so it can write to a masked savegame --- src/gba/gba-savedata.c | 9 ++++++--- src/gba/gba-savedata.h | 2 ++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/gba/gba-savedata.c b/src/gba/gba-savedata.c index 02fadf7a8..4e3e6cf98 100644 --- a/src/gba/gba-savedata.c +++ b/src/gba/gba-savedata.c @@ -19,6 +19,7 @@ void GBASavedataInit(struct GBASavedata* savedata, struct VFile* vf) { savedata->flashState = FLASH_STATE_RAW; savedata->vf = vf; savedata->realVf = vf; + savedata->mapMode = MAP_WRITE; } void GBASavedataDeinit(struct GBASavedata* savedata) { @@ -65,11 +66,13 @@ void GBASavedataDeinit(struct GBASavedata* savedata) { void GBASavedataMask(struct GBASavedata* savedata, struct VFile* vf) { GBASavedataDeinit(savedata); savedata->vf = vf; + savedata->mapMode = MAP_READ; } void GBASavedataUnmask(struct GBASavedata* savedata) { GBASavedataDeinit(savedata); savedata->vf = savedata->realVf; + savedata->mapMode = MAP_WRITE; } bool GBASavedataClone(struct GBASavedata* savedata, struct VFile* out) { @@ -115,7 +118,7 @@ void GBASavedataInitFlash(struct GBASavedata* savedata) { if (end < SIZE_CART_FLASH512) { savedata->vf->truncate(savedata->vf, SIZE_CART_FLASH1M); } - savedata->data = savedata->vf->map(savedata->vf, SIZE_CART_FLASH1M, MAP_WRITE); + savedata->data = savedata->vf->map(savedata->vf, SIZE_CART_FLASH1M, savedata->mapMode); } savedata->currentBank = savedata->data; @@ -140,7 +143,7 @@ void GBASavedataInitEEPROM(struct GBASavedata* savedata) { if (end < SIZE_CART_EEPROM) { savedata->vf->truncate(savedata->vf, SIZE_CART_EEPROM); } - savedata->data = savedata->vf->map(savedata->vf, SIZE_CART_EEPROM, MAP_WRITE); + savedata->data = savedata->vf->map(savedata->vf, SIZE_CART_EEPROM, savedata->mapMode); } if (end < SIZE_CART_EEPROM) { memset(&savedata->data[end], 0xFF, SIZE_CART_EEPROM - end); @@ -163,7 +166,7 @@ void GBASavedataInitSRAM(struct GBASavedata* savedata) { if (end < SIZE_CART_SRAM) { savedata->vf->truncate(savedata->vf, SIZE_CART_SRAM); } - savedata->data = savedata->vf->map(savedata->vf, SIZE_CART_SRAM, MAP_WRITE); + savedata->data = savedata->vf->map(savedata->vf, SIZE_CART_SRAM, savedata->mapMode); } if (end < SIZE_CART_SRAM) { diff --git a/src/gba/gba-savedata.h b/src/gba/gba-savedata.h index 5cb5c517b..08654ca6a 100644 --- a/src/gba/gba-savedata.h +++ b/src/gba/gba-savedata.h @@ -57,6 +57,8 @@ struct GBASavedata { uint8_t* data; enum SavedataCommand command; struct VFile* vf; + + int mapMode; struct VFile* realVf; int readBitsRemaining;