GB, GBA Serialize: Attempt to fix MSVC build

This commit is contained in:
Vicki Pfau 2021-02-09 00:28:42 -08:00
parent b92bb30a72
commit 3309892657
5 changed files with 26 additions and 26 deletions

View File

@ -13,8 +13,8 @@ CXX_GUARD_START
#include <mgba/core/core.h>
#include <mgba/internal/gb/gb.h>
extern const uint32_t GB_SAVESTATE_MAGIC;
extern const uint32_t GB_SAVESTATE_VERSION;
extern MGBA_EXPORT const uint32_t GBSavestateMagic;
extern MGBA_EXPORT const uint32_t GBSavestateVersion;
mLOG_DECLARE_CATEGORY(GB_STATE);

View File

@ -14,8 +14,8 @@ CXX_GUARD_START
#include <mgba/internal/gba/gba.h>
#include <mgba/internal/gb/serialize.h>
extern const uint32_t GBA_SAVESTATE_MAGIC;
extern const uint32_t GBA_SAVESTATE_VERSION;
extern MGBA_EXPORT const uint32_t GBASavestateMagic;
extern MGBA_EXPORT const uint32_t GBASavestateVersion;
mLOG_DECLARE_CATEGORY(GBA_STATE);

View File

@ -13,11 +13,11 @@
mLOG_DEFINE_CATEGORY(GB_STATE, "GB Savestate", "gb.serialize");
const uint32_t GB_SAVESTATE_MAGIC = 0x00400000;
const uint32_t GB_SAVESTATE_VERSION = 0x00000002;
MGBA_EXPORT const uint32_t GBSavestateMagic = 0x00400000;
MGBA_EXPORT const uint32_t GBSavestateVersion = 0x00000002;
void GBSerialize(struct GB* gb, struct GBSerializedState* state) {
STORE_32LE(GB_SAVESTATE_MAGIC + GB_SAVESTATE_VERSION, 0, &state->versionMagic);
STORE_32LE(GBSavestateMagic + GBSavestateVersion, 0, &state->versionMagic);
STORE_32LE(gb->romCrc32, 0, &state->romCrc32);
STORE_32LE(gb->timing.masterCycles, 0, &state->masterCycles);
STORE_64LE(gb->timing.globalCycles, 0, &state->globalCycles);
@ -76,20 +76,20 @@ bool GBDeserialize(struct GB* gb, const struct GBSerializedState* state) {
int16_t check16;
uint16_t ucheck16;
LOAD_32LE(ucheck, 0, &state->versionMagic);
if (ucheck > GB_SAVESTATE_MAGIC + GB_SAVESTATE_VERSION) {
mLOG(GB_STATE, WARN, "Invalid or too new savestate: expected %08X, got %08X", GB_SAVESTATE_MAGIC + GB_SAVESTATE_VERSION, ucheck);
if (ucheck > GBSavestateMagic + GBSavestateVersion) {
mLOG(GB_STATE, WARN, "Invalid or too new savestate: expected %08X, got %08X", GBSavestateMagic + GBSavestateVersion, ucheck);
error = true;
} else if (ucheck < GB_SAVESTATE_MAGIC) {
mLOG(GB_STATE, WARN, "Invalid savestate: expected %08X, got %08X", GB_SAVESTATE_MAGIC + GB_SAVESTATE_VERSION, ucheck);
} else if (ucheck < GBSavestateMagic) {
mLOG(GB_STATE, WARN, "Invalid savestate: expected %08X, got %08X", GBSavestateMagic + GBSavestateVersion, ucheck);
error = true;
} else if (ucheck < GB_SAVESTATE_MAGIC + GB_SAVESTATE_VERSION) {
mLOG(GB_STATE, WARN, "Old savestate: expected %08X, got %08X, continuing anyway", GB_SAVESTATE_MAGIC + GB_SAVESTATE_VERSION, ucheck);
} else if (ucheck < GBSavestateMagic + GBSavestateVersion) {
mLOG(GB_STATE, WARN, "Old savestate: expected %08X, got %08X, continuing anyway", GBSavestateMagic + GBSavestateVersion, ucheck);
}
bool canSgb = ucheck >= GB_SAVESTATE_MAGIC + 2;
bool canSgb = ucheck >= GBSavestateMagic + 2;
if (gb->memory.rom && memcmp(state->title, ((struct GBCartridge*) &gb->memory.rom[0x100])->titleLong, sizeof(state->title))) {
LOAD_32LE(ucheck, 0, &state->versionMagic);
if (ucheck > GB_SAVESTATE_MAGIC + 2 || memcmp(state->title, ((struct GBCartridge*) gb->memory.rom)->titleLong, sizeof(state->title))) {
if (ucheck > GBSavestateMagic + 2 || memcmp(state->title, ((struct GBCartridge*) gb->memory.rom)->titleLong, sizeof(state->title))) {
// There was a bug in previous versions where the memory address being compared was wrong
mLOG(GB_STATE, WARN, "Savestate is for a different game");
error = true;

View File

@ -14,8 +14,8 @@
#include <fcntl.h>
const uint32_t GBA_SAVESTATE_MAGIC = 0x01000000;
const uint32_t GBA_SAVESTATE_VERSION = 0x00000004;
MGBA_EXPORT const uint32_t GBASavestateMagic = 0x01000000;
MGBA_EXPORT const uint32_t GBASavestateVersion = 0x00000004;
mLOG_DEFINE_CATEGORY(GBA_STATE, "GBA Savestate", "gba.serialize");
@ -25,7 +25,7 @@ struct GBABundledState {
};
void GBASerialize(struct GBA* gba, struct GBASerializedState* state) {
STORE_32(GBA_SAVESTATE_MAGIC + GBA_SAVESTATE_VERSION, 0, &state->versionMagic);
STORE_32(GBASavestateMagic + GBASavestateVersion, 0, &state->versionMagic);
STORE_32(gba->biosChecksum, 0, &state->biosChecksum);
STORE_32(gba->romCrc32, 0, &state->romCrc32);
STORE_32(gba->timing.masterCycles, 0, &state->masterCycles);
@ -87,14 +87,14 @@ bool GBADeserialize(struct GBA* gba, const struct GBASerializedState* state) {
int32_t check;
uint32_t ucheck;
LOAD_32(ucheck, 0, &state->versionMagic);
if (ucheck > GBA_SAVESTATE_MAGIC + GBA_SAVESTATE_VERSION) {
mLOG(GBA_STATE, WARN, "Invalid or too new savestate: expected %08X, got %08X", GBA_SAVESTATE_MAGIC + GBA_SAVESTATE_VERSION, ucheck);
if (ucheck > GBASavestateMagic + GBASavestateVersion) {
mLOG(GBA_STATE, WARN, "Invalid or too new savestate: expected %08X, got %08X", GBASavestateMagic + GBASavestateVersion, ucheck);
error = true;
} else if (ucheck < GBA_SAVESTATE_MAGIC) {
mLOG(GBA_STATE, WARN, "Invalid savestate: expected %08X, got %08X", GBA_SAVESTATE_MAGIC + GBA_SAVESTATE_VERSION, ucheck);
} else if (ucheck < GBASavestateMagic) {
mLOG(GBA_STATE, WARN, "Invalid savestate: expected %08X, got %08X", GBASavestateMagic + GBASavestateVersion, ucheck);
error = true;
} else if (ucheck < GBA_SAVESTATE_MAGIC + GBA_SAVESTATE_VERSION) {
mLOG(GBA_STATE, WARN, "Old savestate: expected %08X, got %08X, continuing anyway", GBA_SAVESTATE_MAGIC + GBA_SAVESTATE_VERSION, ucheck);
} else if (ucheck < GBASavestateMagic + GBASavestateVersion) {
mLOG(GBA_STATE, WARN, "Old savestate: expected %08X, got %08X, continuing anyway", GBASavestateMagic + GBASavestateVersion, ucheck);
}
LOAD_32(ucheck, 0, &state->biosChecksum);
if (ucheck != gba->biosChecksum) {

View File

@ -266,7 +266,7 @@ mPlatform SaveConverter::getStatePlatform(VFile* vf) {
core->deinit(core);
if (state) {
LOAD_32LE(magic, 0, state);
if (magic - GBA_SAVESTATE_MAGIC <= GBA_SAVESTATE_VERSION) {
if (magic - GBASavestateMagic <= GBASavestateVersion) {
platform = mPLATFORM_GBA;
}
mappedMemoryFree(state, core->stateSize(core));
@ -281,7 +281,7 @@ mPlatform SaveConverter::getStatePlatform(VFile* vf) {
core->deinit(core);
if (state) {
LOAD_32LE(magic, 0, state);
if (magic - GB_SAVESTATE_MAGIC <= GB_SAVESTATE_VERSION) {
if (magic - GBSavestateMagic <= GBSavestateVersion) {
platform = mPLATFORM_GB;
}
mappedMemoryFree(state, core->stateSize(core));