mirror of https://github.com/mgba-emu/mgba.git
Save/load state with file parameter
This commit is contained in:
parent
d979e04606
commit
86a2edbdf1
|
@ -163,15 +163,7 @@ bool GBASaveState(struct GBA* gba, struct VDir* dir, int slot, bool screenshot)
|
||||||
if (!vf) {
|
if (!vf) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool success = true;
|
bool success = GBASaveStateNamed(gba, vf, screenshot);
|
||||||
if (!screenshot) {
|
|
||||||
vf->truncate(vf, sizeof(struct GBASerializedState));
|
|
||||||
struct GBASerializedState* state = vf->map(vf, sizeof(struct GBASerializedState), MAP_WRITE);
|
|
||||||
GBASerialize(gba, state);
|
|
||||||
vf->unmap(vf, state, sizeof(struct GBASerializedState));
|
|
||||||
} else {
|
|
||||||
_savePNGState(gba, vf);
|
|
||||||
}
|
|
||||||
vf->close(vf);
|
vf->close(vf);
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
@ -181,14 +173,37 @@ bool GBALoadState(struct GBA* gba, struct VDir* dir, int slot) {
|
||||||
if (!vf) {
|
if (!vf) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
bool success = GBALoadStateNamed(gba, vf);
|
||||||
|
vf->close(vf);
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GBASaveStateNamed(struct GBA* gba, struct VFile* vf, bool screenshot) {
|
||||||
|
if (!screenshot) {
|
||||||
|
vf->truncate(vf, sizeof(struct GBASerializedState));
|
||||||
|
struct GBASerializedState* state = vf->map(vf, sizeof(struct GBASerializedState), MAP_WRITE);
|
||||||
|
if (!state) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
GBASerialize(gba, state);
|
||||||
|
vf->unmap(vf, state, sizeof(struct GBASerializedState));
|
||||||
|
} else {
|
||||||
|
return _savePNGState(gba, vf);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GBALoadStateNamed(struct GBA* gba, struct VFile* vf) {
|
||||||
if (!isPNG(vf)) {
|
if (!isPNG(vf)) {
|
||||||
struct GBASerializedState* state = vf->map(vf, sizeof(struct GBASerializedState), MAP_READ);
|
struct GBASerializedState* state = vf->map(vf, sizeof(struct GBASerializedState), MAP_READ);
|
||||||
|
if (!state) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
GBADeserialize(gba, state);
|
GBADeserialize(gba, state);
|
||||||
vf->unmap(vf, state, sizeof(struct GBASerializedState));
|
vf->unmap(vf, state, sizeof(struct GBASerializedState));
|
||||||
} else {
|
} else {
|
||||||
_loadPNGState(gba, vf);
|
return _loadPNGState(gba, vf);
|
||||||
}
|
}
|
||||||
vf->close(vf);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -272,6 +272,9 @@ void GBADeserialize(struct GBA* gba, struct GBASerializedState* state);
|
||||||
bool GBASaveState(struct GBA* gba, struct VDir* dir, int slot, bool screenshot);
|
bool GBASaveState(struct GBA* gba, struct VDir* dir, int slot, bool screenshot);
|
||||||
bool GBALoadState(struct GBA* gba, struct VDir* dir, int slot);
|
bool GBALoadState(struct GBA* gba, struct VDir* dir, int slot);
|
||||||
|
|
||||||
|
bool GBASaveStateNamed(struct GBA* gba, struct VFile* vf, bool screenshot);
|
||||||
|
bool GBALoadStateNamed(struct GBA* gba, struct VFile* vf);
|
||||||
|
|
||||||
struct GBASerializedState* GBAAllocateState(void);
|
struct GBASerializedState* GBAAllocateState(void);
|
||||||
void GBADeallocateState(struct GBASerializedState* state);
|
void GBADeallocateState(struct GBASerializedState* state);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue