Qt: Load temporary saves (untested)
Jeffrey Pfau jeffrey@endrift.com
Tue, 07 Jun 2016 15:06:44 -0700
7 files changed,
45 insertions(+),
0 deletions(-)
M
src/core/core.h
→
src/core/core.h
@@ -67,6 +67,7 @@
bool (*isROM)(struct VFile* vf); bool (*loadROM)(struct mCore*, struct VFile* vf); bool (*loadSave)(struct mCore*, struct VFile* vf); + bool (*loadTemporarySave)(struct mCore*, struct VFile* vf); void (*unloadROM)(struct mCore*); bool (*loadBIOS)(struct mCore*, struct VFile* vf, int biosID);
M
src/gba/core.c
→
src/gba/core.c
@@ -192,6 +192,11 @@ static bool _GBACoreLoadSave(struct mCore* core, struct VFile* vf) {
return GBALoadSave(core->board, vf); } +static bool _GBACoreLoadTemporarySave(struct mCore* core, struct VFile* vf) { + GBASavedataMask(core->board, vf); + return true; // TODO: Return a real value +} + static bool _GBACoreLoadPatch(struct mCore* core, struct VFile* vf) { if (!vf) { return false;@@ -488,6 +493,7 @@ core->isROM = GBAIsROM;
core->loadROM = _GBACoreLoadROM; core->loadBIOS = _GBACoreLoadBIOS; core->loadSave = _GBACoreLoadSave; + core->loadTemporarySave = _GBACoreLoadTemporarySave; core->loadPatch = _GBACoreLoadPatch; core->unloadROM = _GBACoreUnloadROM; core->reset = _GBACoreReset;
M
src/gba/savedata.c
→
src/gba/savedata.c
@@ -84,18 +84,22 @@ savedata->type = SAVEDATA_AUTODETECT;
} void GBASavedataMask(struct GBASavedata* savedata, struct VFile* vf) { + enum SavedataType type = savedata->type; GBASavedataDeinit(savedata); savedata->vf = vf; savedata->mapMode = MAP_READ; + GBASavedataForceType(savedata, type, savedata->realisticTiming); } void GBASavedataUnmask(struct GBASavedata* savedata) { if (savedata->mapMode != MAP_READ) { return; } + enum SavedataType type = savedata->type; GBASavedataDeinit(savedata); savedata->vf = savedata->realVf; savedata->mapMode = MAP_WRITE; + GBASavedataForceType(savedata, type, savedata->realisticTiming); } bool GBASavedataClone(struct GBASavedata* savedata, struct VFile* out) {
M
src/platform/qt/GameController.cpp
→
src/platform/qt/GameController.cpp
@@ -390,6 +390,23 @@ openGame();
} } +void GameController::loadSave(const QString& path, bool temporary) { + if (!isLoaded()) { + return; + } + VFile* vf = VFileDevice::open(path, temporary ? O_RDONLY : O_RDWR); + if (!vf) { + LOG(QT, ERROR) << tr("Failed to open save file: %1").arg(path); + return; + } + + if (temporary) { + m_threadContext.core->loadTemporarySave(m_threadContext.core, vf); + } else { + m_threadContext.core->loadSave(m_threadContext.core, vf); + } +} + void GameController::yankPak() { if (!m_gameOpen) { return;
M
src/platform/qt/GameController.h
→
src/platform/qt/GameController.h
@@ -103,6 +103,7 @@
public slots: void loadGame(const QString& path); void loadBIOS(const QString& path); + void loadSave(const QString& path, bool temporary = true); void yankPak(); void replaceGame(const QString& path); void setUseBIOS(bool);
M
src/platform/qt/Window.cpp
→
src/platform/qt/Window.cpp
@@ -313,6 +313,15 @@ m_controller->replaceGame(filename);
} } +void Window::selectSave(bool temporary) { + QStringList formats{"*.sav"}; + QString filter = tr("Game Boy Advance save files (%1)").arg(formats.join(QChar(' '))); + QString filename = GBAApp::app()->getOpenFileName(this, tr("Select save"), filter); + if (!filename.isEmpty()) { + m_controller->loadSave(filename, temporary); + } +} + void Window::multiplayerChanged() { disconnect(nullptr, this, SLOT(multiplayerChanged())); int attached = 1;@@ -812,6 +821,12 @@ m_shortcutController->addMenu(fileMenu);
installEventFilter(m_shortcutController); addControlledAction(fileMenu, fileMenu->addAction(tr("Load &ROM..."), this, SLOT(selectROM()), QKeySequence::Open), "loadROM"); + 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 &BIOS..."), this, SLOT(selectBIOS())), "loadBIOS"); addControlledAction(fileMenu, fileMenu->addAction(tr("Load &patch..."), this, SLOT(selectPatch())), "loadPatch"); addControlledAction(fileMenu, fileMenu->addAction(tr("Boot BIOS"), m_controller, SLOT(bootBIOS())), "bootBIOS");
M
src/platform/qt/Window.h
→
src/platform/qt/Window.h
@@ -59,6 +59,7 @@ void fpsTargetChanged(float target);
public slots: void selectROM(); + void selectSave(bool temporary); void selectBIOS(); void selectPatch(); void enterFullScreen();