GBA: LOAD/STORE-ize savedata serialization

This commit is contained in:
Jeffrey Pfau 2015-10-19 22:03:55 -07:00
parent fc84a33760
commit ba69030c47
2 changed files with 25 additions and 21 deletions

View File

@ -444,13 +444,15 @@ void GBASavedataClean(struct GBASavedata* savedata, uint32_t frameCount) {
void GBASavedataSerialize(const struct GBASavedata* savedata, struct GBASerializedState* state, bool includeData) { void GBASavedataSerialize(const struct GBASavedata* savedata, struct GBASerializedState* state, bool includeData) {
state->savedata.type = savedata->type; state->savedata.type = savedata->type;
state->savedata.command = savedata->command; state->savedata.command = savedata->command;
state->savedata.flashState = savedata->flashState; GBASerializedSavedataFlags flags = 0;
state->savedata.flashBank = savedata->currentBank == &savedata->data[0x10000]; flags = GBASerializedSavedataFlagsSetFlashState(flags, savedata->flashState);
state->savedata.readBitsRemaining = savedata->readBitsRemaining; flags = GBASerializedSavedataFlagsTestFillFlashBank(flags, savedata->currentBank == &savedata->data[0x10000]);
state->savedata.readAddress = savedata->readAddress; state->savedata.flags = flags;
state->savedata.writeAddress = savedata->writeAddress; STORE_32(savedata->readBitsRemaining, 0, &state->savedata.readBitsRemaining);
state->savedata.settlingSector = savedata->settling; STORE_32(savedata->readAddress, 0, &state->savedata.readAddress);
state->savedata.settlingDust = savedata->dust; 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 UNUSED(includeData); // TODO
} }
@ -463,15 +465,16 @@ void GBASavedataDeserialize(struct GBASavedata* savedata, const struct GBASerial
GBASavedataForceType(savedata, state->savedata.type, savedata->realisticTiming); GBASavedataForceType(savedata, state->savedata.type, savedata->realisticTiming);
} }
savedata->command = state->savedata.command; savedata->command = state->savedata.command;
savedata->flashState = state->savedata.flashState; GBASerializedSavedataFlags flags = state->savedata.flags;
savedata->readBitsRemaining = state->savedata.readBitsRemaining; savedata->flashState = GBASerializedSavedataFlagsGetFlashState(flags);
savedata->readAddress = state->savedata.readAddress; LOAD_32(savedata->readBitsRemaining, 0, &state->savedata.readBitsRemaining);
savedata->writeAddress = state->savedata.writeAddress; LOAD_32(savedata->readAddress, 0, &state->savedata.readAddress);
savedata->settling = state->savedata.settlingSector; LOAD_32(savedata->writeAddress, 0, &state->savedata.writeAddress);
savedata->dust = state->savedata.settlingDust; LOAD_16(savedata->settling, 0, &state->savedata.settlingSector);
LOAD_16(savedata->dust, 0, &state->savedata.settlingDust);
if (savedata->type == SAVEDATA_FLASH1M) { if (savedata->type == SAVEDATA_FLASH1M) {
_flashSwitchBank(savedata, state->savedata.flashBank); _flashSwitchBank(savedata, GBASerializedSavedataFlagsGetFlashBank(flags));
} }
UNUSED(includeData); // TODO UNUSED(includeData); // TODO

View File

@ -207,6 +207,10 @@ DECL_BITS(GBASerializedHWFlags2, GbpTxPosition, 4, 5);
DECL_BITFIELD(GBASerializedHWFlags3, uint16_t); DECL_BITFIELD(GBASerializedHWFlags3, uint16_t);
DECL_BITFIELD(GBASerializedSavedataFlags, uint8_t);
DECL_BITS(GBASerializedSavedataFlags, FlashState, 0, 2);
DECL_BIT(GBASerializedSavedataFlags, FlashBank, 4);
struct GBASerializedState { struct GBASerializedState {
uint32_t versionMagic; uint32_t versionMagic;
uint32_t biosChecksum; uint32_t biosChecksum;
@ -300,13 +304,10 @@ struct GBASerializedState {
uint32_t reservedHardware[6]; uint32_t reservedHardware[6];
struct { struct {
unsigned type : 8; uint8_t type;
unsigned command : 8; uint8_t command;
unsigned flashState : 2; GBASerializedSavedataFlags flags;
unsigned : 2; uint8_t reserved;
unsigned flashBank : 1;
unsigned : 3;
unsigned : 8;
int32_t readBitsRemaining; int32_t readBitsRemaining;
uint32_t readAddress; uint32_t readAddress;
uint32_t writeAddress; uint32_t writeAddress;