all repos — mgba @ 9e5070acf8034cf55541adf7d58c3ca51820c6ad

mGBA Game Boy Advance Emulator

GBA Hardware: LOAD_32/16-ize hardware deserialization
Jeffrey Pfau jeffrey@endrift.com
Sun, 18 Oct 2015 12:37:22 -0700
commit

9e5070acf8034cf55541adf7d58c3ca51820c6ad

parent

96f33c114a682953aa0aeebe3b77732df58151dd

3 files changed, 58 insertions(+), 37 deletions(-)

jump to
M src/gba/hardware.csrc/gba/hardware.c

@@ -591,41 +591,56 @@

// == Serialization void GBAHardwareSerialize(const struct GBACartridgeHardware* hw, struct GBASerializedState* state) { - state->hw.readWrite = hw->readWrite; + GBASerializedHWFlags1 flags1 = 0; + GBASerializedHWFlags2 flags2 = 0; + flags1 = GBASerializedHWFlags1SetReadWrite(flags1, hw->readWrite); state->hw.pinState = hw->pinState; state->hw.pinDirection = hw->direction; state->hw.devices = hw->devices; state->hw.rtc = hw->rtc; state->hw.gyroSample = hw->gyroSample; - state->hw.gyroEdge = hw->gyroEdge; + flags1 = GBASerializedHWFlags1SetGyroEdge(flags1, hw->gyroEdge); state->hw.tiltSampleX = hw->tiltX; state->hw.tiltSampleY = hw->tiltY; - state->hw.tiltState = hw->tiltState; - state->hw.lightCounter = hw->lightCounter; + flags2 = GBASerializedHWFlags2SetTiltState(flags2, hw->tiltState); + flags2 = GBASerializedHWFlags1SetLightCounter(flags2, hw->lightCounter); state->hw.lightSample = hw->lightSample; - state->hw.lightEdge = hw->lightEdge; - state->hw.gbpInputsPosted = hw->gbpInputsPosted; - state->hw.gbpTxPosition = hw->gbpTxPosition; + flags1 = GBASerializedHWFlags1SetLightEdge(flags1, hw->lightEdge); + flags2 = GBASerializedHWFlags2SetGbpInputsPosted(flags2, hw->gbpInputsPosted); + flags2 = GBASerializedHWFlags2SetGbpTxPosition(flags2, hw->gbpTxPosition); state->hw.gbpNextEvent = hw->gbpNextEvent; + state->hw.flags1 = flags1; + state->hw.flags2 = flags2; } void GBAHardwareDeserialize(struct GBACartridgeHardware* hw, const struct GBASerializedState* state) { - hw->readWrite = state->hw.readWrite; - hw->pinState = state->hw.pinState; - hw->direction = state->hw.pinDirection; + GBASerializedHWFlags1 flags1; + LOAD_16(flags1, 0, &state->hw.flags1); + hw->readWrite = GBASerializedHWFlags1GetReadWrite(flags1); + LOAD_16(hw->pinState, 0, &state->hw.pinState); + LOAD_16(hw->direction, 0, &state->hw.pinDirection); hw->devices = state->hw.devices; - hw->rtc = state->hw.rtc; - hw->gyroSample = state->hw.gyroSample; - hw->gyroEdge = state->hw.gyroEdge; - hw->tiltX = state->hw.tiltSampleX; - hw->tiltY = state->hw.tiltSampleY; - hw->tiltState = state->hw.tiltState; - hw->lightCounter = state->hw.lightCounter; + + LOAD_32(hw->rtc.bytesRemaining, 0, &state->hw.rtc.bytesRemaining); + LOAD_32(hw->rtc.transferStep, 0, &state->hw.rtc.transferStep); + LOAD_32(hw->rtc.bitsRead, 0, &state->hw.rtc.bitsRead); + LOAD_32(hw->rtc.bits, 0, &state->hw.rtc.bits); + LOAD_32(hw->rtc.commandActive, 0, &state->hw.rtc.commandActive); + LOAD_32(hw->rtc.command, 0, &state->hw.rtc.command); + LOAD_32(hw->rtc.control, 0, &state->hw.rtc.control); + memcpy(hw->rtc.time, state->hw.rtc.time, sizeof(hw->rtc.time)); + + LOAD_16(hw->gyroSample, 0, &state->hw.gyroSample); + hw->gyroEdge = GBASerializedHWFlags1GetGyroEdge(flags1); + LOAD_16(hw->tiltX, 0, &state->hw.tiltSampleX); + LOAD_16(hw->tiltY, 0, &state->hw.tiltSampleY); + hw->tiltState = GBASerializedHWFlags2GetTiltState(state->hw.flags2); + hw->lightCounter = GBASerializedHWFlags1GetLightCounter(flags1); hw->lightSample = state->hw.lightSample; - hw->lightEdge = state->hw.lightEdge; - hw->gbpInputsPosted = state->hw.gbpInputsPosted; - hw->gbpTxPosition = state->hw.gbpTxPosition; - hw->gbpNextEvent = state->hw.gbpNextEvent; + hw->lightEdge = GBASerializedHWFlags1GetLightEdge(flags1); + hw->gbpInputsPosted = GBASerializedHWFlags2GetGbpInputsPosted(state->hw.flags2); + hw->gbpTxPosition = GBASerializedHWFlags2GetGbpTxPosition(state->hw.flags2); + LOAD_32(hw->gbpNextEvent, 0, &state->hw.gbpNextEvent); if (hw->devices & HW_GB_PLAYER) { GBASIOSetDriver(&hw->p->sio, &hw->gbpDriver.d, SIO_NORMAL_32); }
M src/gba/hardware.hsrc/gba/hardware.h

@@ -98,7 +98,7 @@ DECL_BITFIELD(GPIOPin, uint16_t);

struct GBACartridgeHardware { struct GBA* p; - int devices; + uint32_t devices; enum GPIODirection readWrite; uint16_t* gpioBase;
M src/gba/serialize.hsrc/gba/serialize.h

@@ -194,6 +194,19 @@ DECL_BIT(GBASerializedAudioFlags, Ch2Hi, 13);

DECL_BITS(GBASerializedAudioFlags, Ch4Volume, 16, 4); DECL_BIT(GBASerializedAudioFlags, Ch4Dead, 20); +DECL_BITFIELD(GBASerializedHWFlags1, uint16_t); +DECL_BIT(GBASerializedHWFlags1, ReadWrite, 0); +DECL_BIT(GBASerializedHWFlags1, GyroEdge, 1); +DECL_BIT(GBASerializedHWFlags1, LightEdge, 2); +DECL_BITS(GBASerializedHWFlags1, LightCounter, 4, 12); + +DECL_BITFIELD(GBASerializedHWFlags2, uint8_t); +DECL_BITS(GBASerializedHWFlags2, TiltState, 0, 2); +DECL_BITS(GBASerializedHWFlags2, GbpInputsPosted, 2, 2); +DECL_BITS(GBASerializedHWFlags2, GbpTxPosition, 4, 5); + +DECL_BITFIELD(GBASerializedHWFlags3, uint16_t); + struct GBASerializedState { uint32_t versionMagic; uint32_t biosChecksum;

@@ -274,21 +287,14 @@ uint16_t pinState;

uint16_t pinDirection; struct GBARTC rtc; uint8_t devices; - // Do not change these to uint16_t, this breaks bincompat with some older compilers - unsigned gyroSample : 16; - unsigned tiltSampleX : 16; - unsigned tiltSampleY : 16; - unsigned readWrite : 1; - unsigned gyroEdge : 1; - unsigned lightEdge : 1; - unsigned : 1; - unsigned lightCounter : 12; - unsigned lightSample : 8; - unsigned tiltState : 2; - unsigned gbpInputsPosted : 2; - unsigned gbpTxPosition : 5; - unsigned : 15; - uint32_t gbpNextEvent : 32; + uint16_t gyroSample; + uint16_t tiltSampleX; + uint16_t tiltSampleY; + GBASerializedHWFlags1 flags1; + uint8_t lightSample; + GBASerializedHWFlags2 flags2; + GBASerializedHWFlags3 flags3; + uint32_t gbpNextEvent; } hw; uint32_t reservedHardware[6];