mirror of https://github.com/mgba-emu/mgba.git
GBA Hardware: LOAD_32/16-ize hardware deserialization
This commit is contained in:
parent
96f33c114a
commit
9e5070acf8
|
@ -591,41 +591,56 @@ int32_t _gbpSioProcessEvents(struct GBASIODriver* driver, int32_t cycles) {
|
||||||
// == Serialization
|
// == Serialization
|
||||||
|
|
||||||
void GBAHardwareSerialize(const struct GBACartridgeHardware* hw, struct GBASerializedState* state) {
|
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.pinState = hw->pinState;
|
||||||
state->hw.pinDirection = hw->direction;
|
state->hw.pinDirection = hw->direction;
|
||||||
state->hw.devices = hw->devices;
|
state->hw.devices = hw->devices;
|
||||||
state->hw.rtc = hw->rtc;
|
state->hw.rtc = hw->rtc;
|
||||||
state->hw.gyroSample = hw->gyroSample;
|
state->hw.gyroSample = hw->gyroSample;
|
||||||
state->hw.gyroEdge = hw->gyroEdge;
|
flags1 = GBASerializedHWFlags1SetGyroEdge(flags1, hw->gyroEdge);
|
||||||
state->hw.tiltSampleX = hw->tiltX;
|
state->hw.tiltSampleX = hw->tiltX;
|
||||||
state->hw.tiltSampleY = hw->tiltY;
|
state->hw.tiltSampleY = hw->tiltY;
|
||||||
state->hw.tiltState = hw->tiltState;
|
flags2 = GBASerializedHWFlags2SetTiltState(flags2, hw->tiltState);
|
||||||
state->hw.lightCounter = hw->lightCounter;
|
flags2 = GBASerializedHWFlags1SetLightCounter(flags2, hw->lightCounter);
|
||||||
state->hw.lightSample = hw->lightSample;
|
state->hw.lightSample = hw->lightSample;
|
||||||
state->hw.lightEdge = hw->lightEdge;
|
flags1 = GBASerializedHWFlags1SetLightEdge(flags1, hw->lightEdge);
|
||||||
state->hw.gbpInputsPosted = hw->gbpInputsPosted;
|
flags2 = GBASerializedHWFlags2SetGbpInputsPosted(flags2, hw->gbpInputsPosted);
|
||||||
state->hw.gbpTxPosition = hw->gbpTxPosition;
|
flags2 = GBASerializedHWFlags2SetGbpTxPosition(flags2, hw->gbpTxPosition);
|
||||||
state->hw.gbpNextEvent = hw->gbpNextEvent;
|
state->hw.gbpNextEvent = hw->gbpNextEvent;
|
||||||
|
state->hw.flags1 = flags1;
|
||||||
|
state->hw.flags2 = flags2;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GBAHardwareDeserialize(struct GBACartridgeHardware* hw, const struct GBASerializedState* state) {
|
void GBAHardwareDeserialize(struct GBACartridgeHardware* hw, const struct GBASerializedState* state) {
|
||||||
hw->readWrite = state->hw.readWrite;
|
GBASerializedHWFlags1 flags1;
|
||||||
hw->pinState = state->hw.pinState;
|
LOAD_16(flags1, 0, &state->hw.flags1);
|
||||||
hw->direction = state->hw.pinDirection;
|
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->devices = state->hw.devices;
|
||||||
hw->rtc = state->hw.rtc;
|
|
||||||
hw->gyroSample = state->hw.gyroSample;
|
LOAD_32(hw->rtc.bytesRemaining, 0, &state->hw.rtc.bytesRemaining);
|
||||||
hw->gyroEdge = state->hw.gyroEdge;
|
LOAD_32(hw->rtc.transferStep, 0, &state->hw.rtc.transferStep);
|
||||||
hw->tiltX = state->hw.tiltSampleX;
|
LOAD_32(hw->rtc.bitsRead, 0, &state->hw.rtc.bitsRead);
|
||||||
hw->tiltY = state->hw.tiltSampleY;
|
LOAD_32(hw->rtc.bits, 0, &state->hw.rtc.bits);
|
||||||
hw->tiltState = state->hw.tiltState;
|
LOAD_32(hw->rtc.commandActive, 0, &state->hw.rtc.commandActive);
|
||||||
hw->lightCounter = state->hw.lightCounter;
|
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->lightSample = state->hw.lightSample;
|
||||||
hw->lightEdge = state->hw.lightEdge;
|
hw->lightEdge = GBASerializedHWFlags1GetLightEdge(flags1);
|
||||||
hw->gbpInputsPosted = state->hw.gbpInputsPosted;
|
hw->gbpInputsPosted = GBASerializedHWFlags2GetGbpInputsPosted(state->hw.flags2);
|
||||||
hw->gbpTxPosition = state->hw.gbpTxPosition;
|
hw->gbpTxPosition = GBASerializedHWFlags2GetGbpTxPosition(state->hw.flags2);
|
||||||
hw->gbpNextEvent = state->hw.gbpNextEvent;
|
LOAD_32(hw->gbpNextEvent, 0, &state->hw.gbpNextEvent);
|
||||||
if (hw->devices & HW_GB_PLAYER) {
|
if (hw->devices & HW_GB_PLAYER) {
|
||||||
GBASIOSetDriver(&hw->p->sio, &hw->gbpDriver.d, SIO_NORMAL_32);
|
GBASIOSetDriver(&hw->p->sio, &hw->gbpDriver.d, SIO_NORMAL_32);
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,7 +98,7 @@ DECL_BITFIELD(GPIOPin, uint16_t);
|
||||||
|
|
||||||
struct GBACartridgeHardware {
|
struct GBACartridgeHardware {
|
||||||
struct GBA* p;
|
struct GBA* p;
|
||||||
int devices;
|
uint32_t devices;
|
||||||
enum GPIODirection readWrite;
|
enum GPIODirection readWrite;
|
||||||
uint16_t* gpioBase;
|
uint16_t* gpioBase;
|
||||||
|
|
||||||
|
|
|
@ -194,6 +194,19 @@ DECL_BIT(GBASerializedAudioFlags, Ch2Hi, 13);
|
||||||
DECL_BITS(GBASerializedAudioFlags, Ch4Volume, 16, 4);
|
DECL_BITS(GBASerializedAudioFlags, Ch4Volume, 16, 4);
|
||||||
DECL_BIT(GBASerializedAudioFlags, Ch4Dead, 20);
|
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 {
|
struct GBASerializedState {
|
||||||
uint32_t versionMagic;
|
uint32_t versionMagic;
|
||||||
uint32_t biosChecksum;
|
uint32_t biosChecksum;
|
||||||
|
@ -274,21 +287,14 @@ struct GBASerializedState {
|
||||||
uint16_t pinDirection;
|
uint16_t pinDirection;
|
||||||
struct GBARTC rtc;
|
struct GBARTC rtc;
|
||||||
uint8_t devices;
|
uint8_t devices;
|
||||||
// Do not change these to uint16_t, this breaks bincompat with some older compilers
|
uint16_t gyroSample;
|
||||||
unsigned gyroSample : 16;
|
uint16_t tiltSampleX;
|
||||||
unsigned tiltSampleX : 16;
|
uint16_t tiltSampleY;
|
||||||
unsigned tiltSampleY : 16;
|
GBASerializedHWFlags1 flags1;
|
||||||
unsigned readWrite : 1;
|
uint8_t lightSample;
|
||||||
unsigned gyroEdge : 1;
|
GBASerializedHWFlags2 flags2;
|
||||||
unsigned lightEdge : 1;
|
GBASerializedHWFlags3 flags3;
|
||||||
unsigned : 1;
|
uint32_t gbpNextEvent;
|
||||||
unsigned lightCounter : 12;
|
|
||||||
unsigned lightSample : 8;
|
|
||||||
unsigned tiltState : 2;
|
|
||||||
unsigned gbpInputsPosted : 2;
|
|
||||||
unsigned gbpTxPosition : 5;
|
|
||||||
unsigned : 15;
|
|
||||||
uint32_t gbpNextEvent : 32;
|
|
||||||
} hw;
|
} hw;
|
||||||
|
|
||||||
uint32_t reservedHardware[6];
|
uint32_t reservedHardware[6];
|
||||||
|
|
Loading…
Reference in New Issue