GBA: LOAD/STORE-ize savedata serialization
Jeffrey Pfau jeffrey@endrift.com
Mon, 19 Oct 2015 22:03:55 -0700
2 files changed,
25 insertions(+),
21 deletions(-)
M
src/gba/savedata.c
→
src/gba/savedata.c
@@ -444,13 +444,15 @@
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 @@ if (savedata->type != state->savedata.type) {
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
M
src/gba/serialize.h
→
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 @@
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;