Qt: Load temporary saves (untested)

This commit is contained in:
Jeffrey Pfau 2016-06-07 15:06:44 -07:00
parent 87758b274c
commit 723b91dfe3
7 changed files with 45 additions and 0 deletions

View File

@ -67,6 +67,7 @@ struct mCore {
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);

View File

@ -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 @@ struct mCore* GBACoreCreate(void) {
core->loadROM = _GBACoreLoadROM;
core->loadBIOS = _GBACoreLoadBIOS;
core->loadSave = _GBACoreLoadSave;
core->loadTemporarySave = _GBACoreLoadTemporarySave;
core->loadPatch = _GBACoreLoadPatch;
core->unloadROM = _GBACoreUnloadROM;
core->reset = _GBACoreReset;

View File

@ -84,18 +84,22 @@ void GBASavedataDeinit(struct GBASavedata* savedata) {
}
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) {

View File

@ -390,6 +390,23 @@ void GameController::loadBIOS(const QString& path) {
}
}
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;

View File

@ -103,6 +103,7 @@ signals:
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);

View File

@ -313,6 +313,15 @@ void Window::replaceROM() {
}
}
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 @@ void Window::setupMenu(QMenuBar* menubar) {
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");

View File

@ -59,6 +59,7 @@ signals:
public slots:
void selectROM();
void selectSave(bool temporary);
void selectBIOS();
void selectPatch();
void enterFullScreen();