mirror of https://github.com/mgba-emu/mgba.git
Serialize ROM CRC32 for error checking
This commit is contained in:
parent
b4d6d11d19
commit
7a0f86ae99
|
@ -14,6 +14,8 @@ 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->romCrc32 = gba->romCrc32;
|
||||
|
||||
state->id = ((struct GBACartridge*) gba->memory.rom)->id;
|
||||
memcpy(state->title, ((struct GBACartridge*) gba->memory.rom)->title, sizeof(state->title));
|
||||
|
||||
|
@ -46,6 +48,9 @@ void GBADeserialize(struct GBA* gba, struct GBASerializedState* state) {
|
|||
GBALog(gba, GBA_LOG_WARN, "Savestate is for a different game");
|
||||
return;
|
||||
}
|
||||
if (state->romCrc32 != gba->romCrc32) {
|
||||
GBALog(gba, GBA_LOG_WARN, "Savestate is for a different version of the game");
|
||||
}
|
||||
memcpy(gba->cpu->gprs, state->cpu.gprs, sizeof(gba->cpu->gprs));
|
||||
gba->cpu->cpsr = state->cpu.cpsr;
|
||||
gba->cpu->spsr = state->cpu.spsr;
|
||||
|
|
|
@ -10,7 +10,8 @@ const uint32_t GBA_SAVESTATE_MAGIC;
|
|||
/* Savestate format:
|
||||
* 0x00000 - 0x00003: Version Magic (0x01000000)
|
||||
* 0x00004 - 0x00007: BIOS checksum (e.g. 0xBAAE187F for official BIOS)
|
||||
* 0x00008 - 0x0000F: Reserved (leave zero)
|
||||
* 0x00008 - 0x0000B: ROM CRC32
|
||||
* 0x0000C - 0x0000F: Reserved (leave zero)
|
||||
* 0x00010 - 0x0001B: Game title (e.g. METROID4USA)
|
||||
* 0x0001C - 0x0001F: Game code (e.g. AMTE)
|
||||
* 0x00020 - 0x0012F: CPU state:
|
||||
|
@ -133,7 +134,8 @@ const uint32_t GBA_SAVESTATE_MAGIC;
|
|||
struct GBASerializedState {
|
||||
uint32_t versionMagic;
|
||||
uint32_t biosChecksum;
|
||||
uint32_t reservedHeader[2];
|
||||
uint32_t romCrc32;
|
||||
uint32_t reservedHeader;
|
||||
|
||||
char title[12];
|
||||
uint32_t id;
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "gba-sio.h"
|
||||
#include "gba-thread.h"
|
||||
|
||||
#include "util/crc32.h"
|
||||
#include "util/memory.h"
|
||||
#include "util/patch.h"
|
||||
#include "util/vfs.h"
|
||||
|
@ -390,6 +391,7 @@ void GBALoadROM(struct GBA* gba, struct VFile* vf, struct VFile* sav, const char
|
|||
gba->memory.rom = gba->pristineRom;
|
||||
gba->activeFile = fname;
|
||||
gba->memory.romSize = gba->pristineRomSize;
|
||||
gba->romCrc32 = crc32(gba->memory.rom, gba->memory.romSize);
|
||||
GBASavedataInit(&gba->memory.savedata, sav);
|
||||
GBAGPIOInit(&gba->memory.gpio, &((uint16_t*) gba->memory.rom)[GPIO_REG_DATA >> 1]);
|
||||
_checkOverrides(gba, ((struct GBACartridge*) gba->memory.rom)->id);
|
||||
|
@ -429,6 +431,7 @@ void GBAApplyPatch(struct GBA* gba, struct Patch* patch) {
|
|||
return;
|
||||
}
|
||||
gba->memory.romSize = patchedSize;
|
||||
gba->romCrc32 = crc32(gba->memory.rom, gba->memory.romSize);
|
||||
}
|
||||
|
||||
void GBATimerUpdateRegister(struct GBA* gba, int timer) {
|
||||
|
|
|
@ -101,6 +101,7 @@ struct GBA {
|
|||
struct GBARRContext* rr;
|
||||
void* pristineRom;
|
||||
size_t pristineRomSize;
|
||||
uint32_t romCrc32;
|
||||
struct VFile* romVf;
|
||||
struct VFile* biosVf;
|
||||
|
||||
|
|
Loading…
Reference in New Issue