mirror of https://github.com/mgba-emu/mgba.git
GBA: Savestates can store currently used cheats
This commit is contained in:
parent
26e9e8d63f
commit
0501944b5a
|
@ -6,6 +6,7 @@
|
||||||
#include "serialize.h"
|
#include "serialize.h"
|
||||||
|
|
||||||
#include "gba/audio.h"
|
#include "gba/audio.h"
|
||||||
|
#include "gba/cheats.h"
|
||||||
#include "gba/io.h"
|
#include "gba/io.h"
|
||||||
#include "gba/rr/rr.h"
|
#include "gba/rr/rr.h"
|
||||||
#include "gba/supervisor/thread.h"
|
#include "gba/supervisor/thread.h"
|
||||||
|
@ -426,6 +427,20 @@ bool GBASaveStateNamed(struct GBA* gba, struct VFile* vf, int flags) {
|
||||||
}
|
}
|
||||||
svf->close(svf);
|
svf->close(svf);
|
||||||
}
|
}
|
||||||
|
struct VFile* cheatVf = 0;
|
||||||
|
if (flags & SAVESTATE_CHEATS && gba->cpu->components && gba->cpu->components[GBA_COMPONENT_CHEAT_DEVICE]) {
|
||||||
|
struct GBACheatDevice* device = (struct GBACheatDevice*) gba->cpu->components[GBA_COMPONENT_CHEAT_DEVICE];
|
||||||
|
cheatVf = VFileMemChunk(0, 0);
|
||||||
|
if (cheatVf) {
|
||||||
|
GBACheatSaveFile(device, cheatVf);
|
||||||
|
struct GBAExtdataItem item = {
|
||||||
|
.size = cheatVf->size(cheatVf),
|
||||||
|
.data = cheatVf->map(cheatVf, cheatVf->size(cheatVf), MAP_READ),
|
||||||
|
.clean = 0
|
||||||
|
};
|
||||||
|
GBAExtdataPut(&extdata, EXTDATA_CHEATS, &item);
|
||||||
|
}
|
||||||
|
};
|
||||||
#ifdef USE_PNG
|
#ifdef USE_PNG
|
||||||
if (!(flags & SAVESTATE_SCREENSHOT)) {
|
if (!(flags & SAVESTATE_SCREENSHOT)) {
|
||||||
#else
|
#else
|
||||||
|
@ -435,6 +450,9 @@ bool GBASaveStateNamed(struct GBA* gba, struct VFile* vf, int flags) {
|
||||||
struct GBASerializedState* state = vf->map(vf, sizeof(struct GBASerializedState), MAP_WRITE);
|
struct GBASerializedState* state = vf->map(vf, sizeof(struct GBASerializedState), MAP_WRITE);
|
||||||
if (!state) {
|
if (!state) {
|
||||||
GBAExtdataDeinit(&extdata);
|
GBAExtdataDeinit(&extdata);
|
||||||
|
if (cheatVf) {
|
||||||
|
cheatVf->close(cheatVf);
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
GBASerialize(gba, state);
|
GBASerialize(gba, state);
|
||||||
|
@ -442,6 +460,9 @@ bool GBASaveStateNamed(struct GBA* gba, struct VFile* vf, int flags) {
|
||||||
vf->seek(vf, sizeof(struct GBASerializedState), SEEK_SET);
|
vf->seek(vf, sizeof(struct GBASerializedState), SEEK_SET);
|
||||||
GBAExtdataSerialize(&extdata, vf);
|
GBAExtdataSerialize(&extdata, vf);
|
||||||
GBAExtdataDeinit(&extdata);
|
GBAExtdataDeinit(&extdata);
|
||||||
|
if (cheatVf) {
|
||||||
|
cheatVf->close(cheatVf);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
#ifdef USE_PNG
|
#ifdef USE_PNG
|
||||||
}
|
}
|
||||||
|
@ -502,6 +523,17 @@ bool GBALoadStateNamed(struct GBA* gba, struct VFile* vf, int flags) {
|
||||||
svf->close(svf);
|
svf->close(svf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (flags & SAVESTATE_CHEATS && gba->cpu->components && gba->cpu->components[GBA_COMPONENT_CHEAT_DEVICE] && GBAExtdataGet(&extdata, EXTDATA_CHEATS, &item)) {
|
||||||
|
if (item.size) {
|
||||||
|
struct GBACheatDevice* device = (struct GBACheatDevice*) gba->cpu->components[GBA_COMPONENT_CHEAT_DEVICE];
|
||||||
|
struct VFile* svf = VFileFromMemory(item.data, item.size);
|
||||||
|
if (svf) {
|
||||||
|
GBACheatDeviceClear(device);
|
||||||
|
GBACheatParseFile(device, svf);
|
||||||
|
svf->close(svf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
GBAExtdataDeinit(&extdata);
|
GBAExtdataDeinit(&extdata);
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
|
@ -339,11 +339,13 @@ enum GBAExtdataTag {
|
||||||
EXTDATA_NONE = 0,
|
EXTDATA_NONE = 0,
|
||||||
EXTDATA_SCREENSHOT = 1,
|
EXTDATA_SCREENSHOT = 1,
|
||||||
EXTDATA_SAVEDATA = 2,
|
EXTDATA_SAVEDATA = 2,
|
||||||
|
EXTDATA_CHEATS = 3,
|
||||||
EXTDATA_MAX
|
EXTDATA_MAX
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SAVESTATE_SCREENSHOT 1
|
#define SAVESTATE_SCREENSHOT 1
|
||||||
#define SAVESTATE_SAVEDATA 2
|
#define SAVESTATE_SAVEDATA 2
|
||||||
|
#define SAVESTATE_CHEATS 4
|
||||||
|
|
||||||
struct GBAExtdataItem {
|
struct GBAExtdataItem {
|
||||||
int32_t size;
|
int32_t size;
|
||||||
|
|
Loading…
Reference in New Issue