mirror of https://github.com/mgba-emu/mgba.git
Savestate game checks
This commit is contained in:
parent
26c1fbd48f
commit
872c3ceba3
|
@ -13,6 +13,9 @@ const uint32_t GBA_SAVESTATE_MAGIC = 0x01000000;
|
|||
|
||||
void GBASerialize(struct GBA* gba, struct GBASerializedState* state) {
|
||||
state->versionMagic = GBA_SAVESTATE_MAGIC;
|
||||
state->biosChecksum = gba->biosChecksum;
|
||||
state->id = ((struct GBACartridge*) gba->memory.rom)->id;
|
||||
memcpy(state->title, ((struct GBACartridge*) gba->memory.rom)->title, sizeof(state->title));
|
||||
|
||||
memcpy(state->cpu.gprs, gba->cpu.gprs, sizeof(state->cpu.gprs));
|
||||
state->cpu.cpsr = gba->cpu.cpsr;
|
||||
|
@ -28,6 +31,18 @@ void GBASerialize(struct GBA* gba, struct GBASerializedState* state) {
|
|||
}
|
||||
|
||||
void GBADeserialize(struct GBA* gba, struct GBASerializedState* state) {
|
||||
if (state->versionMagic != GBA_SAVESTATE_MAGIC) {
|
||||
GBALog(gba, GBA_LOG_WARN, "Invalid or too new savestate");
|
||||
return;
|
||||
}
|
||||
if (state->biosChecksum != gba->biosChecksum) {
|
||||
GBALog(gba, GBA_LOG_WARN, "Savestate created using a different version of the BIOS");
|
||||
return;
|
||||
}
|
||||
if (state->id != ((struct GBACartridge*) gba->memory.rom)->id || memcmp(state->title, ((struct GBACartridge*) gba->memory.rom)->title, sizeof(state->title))) {
|
||||
GBALog(gba, GBA_LOG_WARN, "Savestate is for a different game");
|
||||
return;
|
||||
}
|
||||
memcpy(gba->cpu.gprs, state->cpu.gprs, sizeof(gba->cpu.gprs));
|
||||
gba->cpu.cpsr = state->cpu.cpsr;
|
||||
gba->cpu.spsr = state->cpu.spsr;
|
||||
|
|
|
@ -133,6 +133,8 @@ void GBAInit(struct GBA* gba) {
|
|||
|
||||
gba->logLevel = GBA_LOG_INFO | GBA_LOG_WARN | GBA_LOG_ERROR;
|
||||
|
||||
gba->biosChecksum = GBAChecksum(gba->memory.bios, SIZE_BIOS);
|
||||
|
||||
ARMReset(&gba->cpu);
|
||||
}
|
||||
|
||||
|
@ -371,6 +373,7 @@ void GBALoadBIOS(struct GBA* gba, int fd) {
|
|||
} else {
|
||||
GBALog(gba, GBA_LOG_WARN, "BIOS checksum incorrect");
|
||||
}
|
||||
gba->biosChecksum = checksum;
|
||||
if ((gba->cpu.gprs[ARM_PC] >> BASE_OFFSET) == BASE_BIOS) {
|
||||
gba->memory.d.setActiveRegion(&gba->memory.d, gba->cpu.gprs[ARM_PC]);
|
||||
}
|
||||
|
|
|
@ -86,6 +86,7 @@ struct GBA {
|
|||
} timers[4];
|
||||
|
||||
int springIRQ;
|
||||
uint32_t biosChecksum;
|
||||
int* keySource;
|
||||
struct GBARotationSource* rotationSource;
|
||||
struct GBARumble* rumble;
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
#include "hle-bios.h"
|
||||
|
||||
const unsigned int hleBiosLength = 196;
|
||||
const unsigned char hleBios[] = {
|
||||
#include "gba-memory.h"
|
||||
|
||||
const size_t hleBiosLength = 196;
|
||||
const uint8_t hleBios[SIZE_BIOS] = {
|
||||
0x06, 0x00, 0x00, 0xea, 0xfe, 0xff, 0xff, 0xea, 0x05, 0x00, 0x00, 0xea,
|
||||
0xfe, 0xff, 0xff, 0xea, 0xfe, 0xff, 0xff, 0xea, 0x00, 0x00, 0xa0, 0xe1,
|
||||
0x0e, 0x00, 0x00, 0xea, 0xfe, 0xff, 0xff, 0xea, 0x02, 0xf3, 0xa0, 0xe3,
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
#ifndef HLE_BIOS_H
|
||||
#define HLE_BIOS_H
|
||||
|
||||
extern const unsigned int hleBiosLength;
|
||||
extern const unsigned char hleBios[];
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
extern const size_t hleBiosLength;
|
||||
extern const uint8_t hleBios[];
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue