mirror of https://github.com/mgba-emu/mgba.git
GB: Add loading a temporary save
This commit is contained in:
parent
d708a1025d
commit
68859f9fd8
|
@ -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 @@ struct mCore* GBCoreCreate(void) {
|
|||
core->loadROM = _GBCoreLoadROM;
|
||||
core->loadBIOS = _GBCoreLoadBIOS;
|
||||
core->loadSave = _GBCoreLoadSave;
|
||||
core->loadTemporarySave = _GBCoreLoadTemporarySave;
|
||||
core->loadPatch = _GBCoreLoadPatch;
|
||||
core->unloadROM = _GBCoreUnloadROM;
|
||||
core->reset = _GBCoreReset;
|
||||
|
|
36
src/gb/gb.c
36
src/gb/gb.c
|
@ -99,6 +99,7 @@ bool GBLoadROM(struct GB* gb, struct VFile* vf) {
|
|||
|
||||
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 @@ bool GBLoadSave(struct GB* gb, struct VFile* vf) {
|
|||
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 @@ void GBUnloadROM(struct GB* gb) {
|
|||
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 @@ void GBReset(struct LR35902Core* cpu) {
|
|||
GBIOReset(gb);
|
||||
GBAudioReset(&gb->audio);
|
||||
GBSIOReset(&gb->sio);
|
||||
|
||||
GBSavedataUnmask(gb);
|
||||
}
|
||||
|
||||
void GBUpdateIRQs(struct GB* gb) {
|
||||
|
|
|
@ -66,6 +66,7 @@ struct GB {
|
|||
struct VFile* romVf;
|
||||
struct VFile* biosVf;
|
||||
struct VFile* sramVf;
|
||||
struct VFile* sramRealVf;
|
||||
|
||||
struct mAVStream* stream;
|
||||
|
||||
|
@ -113,6 +114,9 @@ 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);
|
||||
|
||||
|
|
|
@ -891,7 +891,6 @@ void Window::setupMenu(QMenuBar* menubar) {
|
|||
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");
|
||||
|
|
Loading…
Reference in New Issue