From ba69030c473100d11a5e78843701d3f6eb054615 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Mon, 19 Oct 2015 22:03:55 -0700 Subject: [PATCH] GBA: LOAD/STORE-ize savedata serialization --- src/gba/savedata.c | 31 +++++++++++++++++-------------- src/gba/serialize.h | 15 ++++++++------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/gba/savedata.c b/src/gba/savedata.c index daa8aca68..de535aea1 100644 --- a/src/gba/savedata.c +++ b/src/gba/savedata.c @@ -444,13 +444,15 @@ void GBASavedataClean(struct GBASavedata* savedata, uint32_t frameCount) { void GBASavedataSerialize(const struct GBASavedata* savedata, struct GBASerializedState* state, bool includeData) { state->savedata.type = savedata->type; state->savedata.command = savedata->command; - state->savedata.flashState = savedata->flashState; - state->savedata.flashBank = savedata->currentBank == &savedata->data[0x10000]; - state->savedata.readBitsRemaining = savedata->readBitsRemaining; - state->savedata.readAddress = savedata->readAddress; - state->savedata.writeAddress = savedata->writeAddress; - state->savedata.settlingSector = savedata->settling; - state->savedata.settlingDust = savedata->dust; + GBASerializedSavedataFlags flags = 0; + flags = GBASerializedSavedataFlagsSetFlashState(flags, savedata->flashState); + flags = GBASerializedSavedataFlagsTestFillFlashBank(flags, savedata->currentBank == &savedata->data[0x10000]); + state->savedata.flags = flags; + STORE_32(savedata->readBitsRemaining, 0, &state->savedata.readBitsRemaining); + STORE_32(savedata->readAddress, 0, &state->savedata.readAddress); + STORE_32(savedata->writeAddress, 0, &state->savedata.writeAddress); + STORE_16(savedata->settling, 0, &state->savedata.settlingSector); + STORE_16(savedata->dust, 0, &state->savedata.settlingDust); UNUSED(includeData); // TODO } @@ -463,15 +465,16 @@ void GBASavedataDeserialize(struct GBASavedata* savedata, const struct GBASerial GBASavedataForceType(savedata, state->savedata.type, savedata->realisticTiming); } savedata->command = state->savedata.command; - savedata->flashState = state->savedata.flashState; - savedata->readBitsRemaining = state->savedata.readBitsRemaining; - savedata->readAddress = state->savedata.readAddress; - savedata->writeAddress = state->savedata.writeAddress; - savedata->settling = state->savedata.settlingSector; - savedata->dust = state->savedata.settlingDust; + GBASerializedSavedataFlags flags = state->savedata.flags; + savedata->flashState = GBASerializedSavedataFlagsGetFlashState(flags); + LOAD_32(savedata->readBitsRemaining, 0, &state->savedata.readBitsRemaining); + LOAD_32(savedata->readAddress, 0, &state->savedata.readAddress); + LOAD_32(savedata->writeAddress, 0, &state->savedata.writeAddress); + LOAD_16(savedata->settling, 0, &state->savedata.settlingSector); + LOAD_16(savedata->dust, 0, &state->savedata.settlingDust); if (savedata->type == SAVEDATA_FLASH1M) { - _flashSwitchBank(savedata, state->savedata.flashBank); + _flashSwitchBank(savedata, GBASerializedSavedataFlagsGetFlashBank(flags)); } UNUSED(includeData); // TODO diff --git a/src/gba/serialize.h b/src/gba/serialize.h index 60d63fe15..e33fb1792 100644 --- a/src/gba/serialize.h +++ b/src/gba/serialize.h @@ -207,6 +207,10 @@ DECL_BITS(GBASerializedHWFlags2, GbpTxPosition, 4, 5); DECL_BITFIELD(GBASerializedHWFlags3, uint16_t); +DECL_BITFIELD(GBASerializedSavedataFlags, uint8_t); +DECL_BITS(GBASerializedSavedataFlags, FlashState, 0, 2); +DECL_BIT(GBASerializedSavedataFlags, FlashBank, 4); + struct GBASerializedState { uint32_t versionMagic; uint32_t biosChecksum; @@ -300,13 +304,10 @@ struct GBASerializedState { uint32_t reservedHardware[6]; struct { - unsigned type : 8; - unsigned command : 8; - unsigned flashState : 2; - unsigned : 2; - unsigned flashBank : 1; - unsigned : 3; - unsigned : 8; + uint8_t type; + uint8_t command; + GBASerializedSavedataFlags flags; + uint8_t reserved; int32_t readBitsRemaining; uint32_t readAddress; uint32_t writeAddress;