mirror of https://github.com/mgba-emu/mgba.git
GBA Serialize: Fix loading savegames from savestates
This commit is contained in:
parent
6c1daa914b
commit
878c6b8a2c
1
CHANGES
1
CHANGES
|
@ -16,6 +16,7 @@ Bugfixes:
|
|||
- GBA Memory: Fix mirror on non-overdumped Classic NES games
|
||||
- Qt: Initialize m_useBios
|
||||
- GBA Serialize: Fix memory corruption bug in GBAExtdataSerialize
|
||||
- GBA Serialize: Fix loading savegames from savestates
|
||||
Misc:
|
||||
- GBA: Slightly optimize GBAProcessEvents
|
||||
- Qt: Add preset for DualShock 4
|
||||
|
|
|
@ -126,7 +126,26 @@ bool GBASavedataClone(struct GBASavedata* savedata, struct VFile* out) {
|
|||
}
|
||||
|
||||
bool GBASavedataLoad(struct GBASavedata* savedata, struct VFile* in) {
|
||||
if (savedata->data) {
|
||||
if (savedata->vf) {
|
||||
off_t read = 0;
|
||||
uint8_t buffer[2048];
|
||||
memset(buffer, 0xFF, sizeof(buffer));
|
||||
savedata->vf->seek(savedata->vf, 0, SEEK_SET);
|
||||
while (savedata->vf->seek(savedata->vf, 0, SEEK_CUR) < savedata->vf->size(savedata->vf)) {
|
||||
savedata->vf->write(savedata->vf, buffer, sizeof(buffer));
|
||||
}
|
||||
savedata->vf->seek(savedata->vf, 0, SEEK_SET);
|
||||
if (in) {
|
||||
do {
|
||||
read = in->read(in, buffer, sizeof(buffer));
|
||||
read = savedata->vf->write(savedata->vf, buffer, read);
|
||||
} while (read == sizeof(buffer));
|
||||
}
|
||||
return read >= 0;
|
||||
} else if (savedata->data) {
|
||||
if (!in && savedata->type != SAVEDATA_FORCE_NONE) {
|
||||
return false;
|
||||
}
|
||||
switch (savedata->type) {
|
||||
case SAVEDATA_SRAM:
|
||||
return in->read(in, savedata->data, SIZE_CART_SRAM) == SIZE_CART_SRAM;
|
||||
|
@ -140,14 +159,6 @@ bool GBASavedataLoad(struct GBASavedata* savedata, struct VFile* in) {
|
|||
case SAVEDATA_FORCE_NONE:
|
||||
return true;
|
||||
}
|
||||
} else if (savedata->vf) {
|
||||
off_t read = 0;
|
||||
uint8_t buffer[2048];
|
||||
do {
|
||||
in->read(in, buffer, read);
|
||||
read = savedata->vf->write(savedata->vf, buffer, sizeof(buffer));
|
||||
} while (read == sizeof(buffer));
|
||||
return read >= 0;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -458,8 +458,8 @@ bool GBALoadStateNamed(struct GBA* gba, struct VFile* vf, int flags) {
|
|||
}
|
||||
if (flags & SAVESTATE_SAVEDATA && GBAExtdataGet(&extdata, EXTDATA_SAVEDATA, &item)) {
|
||||
struct VFile* svf = VFileFromMemory(item.data, item.size);
|
||||
GBASavedataLoad(&gba->memory.savedata, svf);
|
||||
if (svf) {
|
||||
GBASavedataLoad(&gba->memory.savedata, svf);
|
||||
svf->close(svf);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue