all repos — mgba @ 5ee336d274fd481c9eb4eb0ee9b49d598aa4340a

mGBA Game Boy Advance Emulator

Fix masking savegames so it can write to a masked savegame
Jeffrey Pfau jeffrey@endrift.com
Mon, 04 Aug 2014 23:46:33 -0700
commit

5ee336d274fd481c9eb4eb0ee9b49d598aa4340a

parent

82b31c46f11c81193809e26479d8699b771b1be1

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

jump to
M src/gba/gba-savedata.csrc/gba/gba-savedata.c

@@ -19,6 +19,7 @@ savedata->command = EEPROM_COMMAND_NULL;

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 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 @@ end = savedata->vf->seek(savedata->vf, 0, SEEK_END);

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 @@ end = savedata->vf->seek(savedata->vf, 0, SEEK_END);

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 @@ end = savedata->vf->seek(savedata->vf, 0, SEEK_END);

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) {
M src/gba/gba-savedata.hsrc/gba/gba-savedata.h

@@ -57,6 +57,8 @@ enum SavedataType type;

uint8_t* data; enum SavedataCommand command; struct VFile* vf; + + int mapMode; struct VFile* realVf; int readBitsRemaining;