From 33098926577f52a74730de1708a427e275a9bc88 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Tue, 9 Feb 2021 00:28:42 -0800 Subject: [PATCH] GB, GBA Serialize: Attempt to fix MSVC build --- include/mgba/internal/gb/serialize.h | 4 ++-- include/mgba/internal/gba/serialize.h | 4 ++-- src/gb/serialize.c | 22 +++++++++++----------- src/gba/serialize.c | 18 +++++++++--------- src/platform/qt/SaveConverter.cpp | 4 ++-- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/include/mgba/internal/gb/serialize.h b/include/mgba/internal/gb/serialize.h index b3cde1661..18ac83b09 100644 --- a/include/mgba/internal/gb/serialize.h +++ b/include/mgba/internal/gb/serialize.h @@ -13,8 +13,8 @@ CXX_GUARD_START #include #include -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); diff --git a/include/mgba/internal/gba/serialize.h b/include/mgba/internal/gba/serialize.h index e901329bd..bf6a93774 100644 --- a/include/mgba/internal/gba/serialize.h +++ b/include/mgba/internal/gba/serialize.h @@ -14,8 +14,8 @@ CXX_GUARD_START #include #include -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); diff --git a/src/gb/serialize.c b/src/gb/serialize.c index f9c37b48f..f50d0bb86 100644 --- a/src/gb/serialize.c +++ b/src/gb/serialize.c @@ -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; diff --git a/src/gba/serialize.c b/src/gba/serialize.c index fbb7d99d9..f6eafa6a4 100644 --- a/src/gba/serialize.c +++ b/src/gba/serialize.c @@ -14,8 +14,8 @@ #include -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) { diff --git a/src/platform/qt/SaveConverter.cpp b/src/platform/qt/SaveConverter.cpp index d7c351501..3ccc952d6 100644 --- a/src/platform/qt/SaveConverter.cpp +++ b/src/platform/qt/SaveConverter.cpp @@ -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));