GB: Add loading a temporary save
Jeffrey Pfau jeffrey@endrift.com
Sun, 28 Aug 2016 01:45:04 -0700
4 files changed,
40 insertions(+),
8 deletions(-)
M
src/gb/core.c
→
src/gb/core.c
@@ -170,6 +170,12 @@ static bool _GBCoreLoadSave(struct mCore* core, struct VFile* vf) {
return GBLoadSave(core->board, vf); } +static bool _GBCoreLoadTemporarySave(struct mCore* core, struct VFile* vf) { + struct GB* gb = core->board; + GBSavedataMask(gb, vf); + return true; // TODO: Return a real value +} + static bool _GBCoreLoadPatch(struct mCore* core, struct VFile* vf) { if (!vf) { return false;@@ -459,6 +465,7 @@ core->isROM = GBIsROM;
core->loadROM = _GBCoreLoadROM; core->loadBIOS = _GBCoreLoadBIOS; core->loadSave = _GBCoreLoadSave; + core->loadTemporarySave = _GBCoreLoadTemporarySave; core->loadPatch = _GBCoreLoadPatch; core->unloadROM = _GBCoreUnloadROM; core->reset = _GBCoreReset;
M
src/gb/gb.c
→
src/gb/gb.c
@@ -99,6 +99,7 @@ }
bool GBLoadSave(struct GB* gb, struct VFile* vf) { gb->sramVf = vf; + gb->sramRealVf = vf; if (vf) { // TODO: Do this in bank-switching code if (vf->size(vf) < 0x20000) {@@ -109,6 +110,31 @@ }
return gb->memory.sram; } +static void GBSramDeinit(struct GB* gb) { + if (gb->sramVf) { + gb->sramVf->unmap(gb->sramVf, gb->memory.sram, 0x20000); + gb->sramVf = 0; + } else if (gb->memory.sram) { + mappedMemoryFree(gb->memory.sram, 0x20000); + } + gb->memory.sram = 0; +} + +void GBSavedataMask(struct GB* gb, struct VFile* vf) { + GBSramDeinit(gb); + gb->sramVf = vf; + gb->memory.sram = vf->map(vf, 0x20000, MAP_READ); +} + +void GBSavedataUnmask(struct GB* gb) { + GBSramDeinit(gb); + if (gb->sramVf == gb->sramRealVf) { + return; + } + gb->sramVf = gb->sramRealVf; + gb->memory.sram = gb->sramVf->map(gb->sramVf, 0x20000, MAP_WRITE); +} + void GBUnloadROM(struct GB* gb) { // TODO: Share with GBAUnloadROM if (gb->memory.rom && gb->memory.romBase != gb->memory.rom) {@@ -131,13 +157,7 @@ gb->pristineRom = 0;
gb->romVf = 0; } - if (gb->sramVf) { - gb->sramVf->unmap(gb->sramVf, gb->memory.sram, 0x8000); - gb->sramVf = 0; - } else if (gb->memory.sram) { - mappedMemoryFree(gb->memory.sram, 0x8000); - } - gb->memory.sram = 0; + GBSramDeinit(gb); } void GBLoadBIOS(struct GB* gb, struct VFile* vf) {@@ -262,6 +282,8 @@ GBTimerReset(&gb->timer);
GBIOReset(gb); GBAudioReset(&gb->audio); GBSIOReset(&gb->sio); + + GBSavedataUnmask(gb); } void GBUpdateIRQs(struct GB* gb) {
M
src/gb/gb.h
→
src/gb/gb.h
@@ -66,6 +66,7 @@ uint32_t romCrc32;
struct VFile* romVf; struct VFile* biosVf; struct VFile* sramVf; + struct VFile* sramRealVf; struct mAVStream* stream;@@ -112,6 +113,9 @@ void GBYankROM(struct GB* gb);
void GBUnloadROM(struct GB* gb); void GBLoadBIOS(struct GB* gb, struct VFile* vf); + +void GBSavedataMask(struct GB* gb, struct VFile* vf); +void GBSavedataUnmask(struct GB* gb); struct Patch; void GBApplyPatch(struct GB* gb, struct Patch* patch);
M
src/platform/qt/Window.cpp
→
src/platform/qt/Window.cpp
@@ -891,7 +891,6 @@
QAction* loadTemporarySave = new QAction(tr("Load temporary save..."), fileMenu); connect(loadTemporarySave, &QAction::triggered, [this]() { this->selectSave(true); }); m_gameActions.append(loadTemporarySave); - m_gbaActions.append(loadTemporarySave); addControlledAction(fileMenu, loadTemporarySave, "loadTemporarySave"); addControlledAction(fileMenu, fileMenu->addAction(tr("Load &patch..."), this, SLOT(selectPatch())), "loadPatch");