mirror of https://github.com/mgba-emu/mgba.git
Update GPIO for serialization
This commit is contained in:
parent
381fc94d73
commit
3915158c96
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "gba-gpio.h"
|
||||
#include "gba-sensors.h"
|
||||
#include "gba-serialize.h"
|
||||
|
||||
#include <time.h>
|
||||
|
||||
|
@ -302,3 +303,25 @@ void _rumbleReadPins(struct GBACartridgeGPIO* gpio) {
|
|||
|
||||
rumble->setRumble(rumble, gpio->p3);
|
||||
}
|
||||
|
||||
// == Serialization
|
||||
|
||||
void GBAGPIOSerialize(struct GBACartridgeGPIO* gpio, struct GBASerializedState* state) {
|
||||
state->gpio.readWrite = gpio->readWrite;
|
||||
state->gpio.pinState = gpio->pinState;
|
||||
state->gpio.pinDirection = gpio->direction;
|
||||
state->gpio.devices = gpio->gpioDevices;
|
||||
state->gpio.rtc = gpio->rtc;
|
||||
state->gpio.gyroSample = gpio->gyroSample;
|
||||
state->gpio.gyroEdge = gpio->gyroEdge;
|
||||
}
|
||||
|
||||
void GBAGPIODeserialize(struct GBACartridgeGPIO* gpio, struct GBASerializedState* state) {
|
||||
gpio->readWrite = state->gpio.readWrite;
|
||||
gpio->pinState = state->gpio.pinState;
|
||||
gpio->direction = state->gpio.pinDirection;
|
||||
// TODO: Deterministic RTC
|
||||
gpio->rtc = state->gpio.rtc;
|
||||
gpio->gyroSample = state->gpio.gyroSample;
|
||||
gpio->gyroEdge = state->gpio.gyroEdge;
|
||||
}
|
||||
|
|
|
@ -10,7 +10,8 @@ enum GPIODevice {
|
|||
GPIO_RTC = 1,
|
||||
GPIO_RUMBLE = 2,
|
||||
GPIO_LIGHT_SENSOR = 4,
|
||||
GPIO_GYRO = 8
|
||||
GPIO_GYRO = 8,
|
||||
GPIO_TILT = 16
|
||||
};
|
||||
|
||||
enum GPIORegister {
|
||||
|
@ -61,7 +62,7 @@ struct GBARTC {
|
|||
union RTCCommandData command;
|
||||
union RTCControl control;
|
||||
uint8_t time[7];
|
||||
};
|
||||
} __attribute__((packed));
|
||||
|
||||
struct GBARumble {
|
||||
void (*setRumble)(struct GBARumble*, int enable);
|
||||
|
@ -96,7 +97,7 @@ struct GBACartridgeGPIO {
|
|||
struct GBARTC rtc;
|
||||
|
||||
uint16_t gyroSample;
|
||||
int gyroEdge;
|
||||
bool gyroEdge;
|
||||
};
|
||||
|
||||
void GBAGPIOInit(struct GBACartridgeGPIO* gpio, uint16_t* gpioBase);
|
||||
|
@ -108,4 +109,8 @@ void GBAGPIOInitGyro(struct GBACartridgeGPIO* gpio);
|
|||
|
||||
void GBAGPIOInitRumble(struct GBACartridgeGPIO* gpio);
|
||||
|
||||
struct GBASerializedState;
|
||||
void GBAGPIOSerialize(struct GBACartridgeGPIO* gpio, struct GBASerializedState* state);
|
||||
void GBAGPIODeserialize(struct GBACartridgeGPIO* gpio, struct GBASerializedState* state);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -462,6 +462,7 @@ void GBAIOSerialize(struct GBA* gba, struct GBASerializedState* state) {
|
|||
}
|
||||
|
||||
memcpy(state->timers, gba->timers, sizeof(state->timers));
|
||||
GBAGPIOSerialize(&gba->memory.gpio, state);
|
||||
}
|
||||
|
||||
void GBAIODeserialize(struct GBA* gba, struct GBASerializedState* state) {
|
||||
|
@ -489,4 +490,5 @@ void GBAIODeserialize(struct GBA* gba, struct GBASerializedState* state) {
|
|||
gba->timersEnabled |= 1 << i;
|
||||
}
|
||||
}
|
||||
GBAGPIODeserialize(&gba->memory.gpio, state);
|
||||
}
|
||||
|
|
|
@ -121,7 +121,25 @@ const uint32_t GBA_SAVESTATE_MAGIC;
|
|||
* | 0x00284 - 0x00287: DMA next destination
|
||||
* | 0x00288 - 0x0028B: DMA next count
|
||||
* | 0x0028C - 0x0028F: DMA next event
|
||||
* 0x00290 - 0x003FF: Reserved (leave zero)
|
||||
* 0x00290 - 0x002BF: GPIO state
|
||||
* | 0x00290 - 0x00291: Pin state
|
||||
* | 0x00292 - 0x00293: Direction state
|
||||
* | 0x00294 - 0x002B6: RTC state (see gba-gpio.h for format)
|
||||
* | 0x002B7 - 0x002B7: GPIO devices
|
||||
* | bit 0: Has RTC values
|
||||
* | bit 1: Has rumble value (reserved)
|
||||
* | bit 2: Has light sensor value (reserved)
|
||||
* | bit 3: Has gyroscope value
|
||||
* | bit 4: Has tilt values (reserved)
|
||||
* | bits 5 - 7: Reserved
|
||||
* | 0x002B8 - 0x002B9: Gyroscope sample
|
||||
* | 0x002BA - 0x002BB: Tilt x sample (reserved)
|
||||
* | 0x002BC - 0x002BD: Tilt y sample (reserved)
|
||||
* | 0x002BE - 0x002BF: Flags
|
||||
* | bit 0: Is read enabled
|
||||
* | bit 1: Gyroscope sample is edge
|
||||
* | bits 2 - 15: Reserved
|
||||
* 0x002C0 - 0x003FF: Reserved (leave zero)
|
||||
* 0x00400 - 0x007FF: I/O memory
|
||||
* 0x00800 - 0x00BFF: Palette
|
||||
* 0x00C00 - 0x00FFF: OAM
|
||||
|
@ -217,7 +235,20 @@ struct GBASerializedState {
|
|||
int32_t nextEvent;
|
||||
} dma[4];
|
||||
|
||||
uint32_t reservedGpio[92];
|
||||
struct {
|
||||
uint16_t pinState;
|
||||
uint16_t pinDirection;
|
||||
struct GBARTC rtc;
|
||||
uint8_t devices;
|
||||
uint16_t gyroSample;
|
||||
uint16_t tiltSampleX;
|
||||
uint16_t tiltSampleY;
|
||||
enum GPIODirection readWrite : 1;
|
||||
unsigned gyroEdge : 1;
|
||||
unsigned reserved : 14;
|
||||
} gpio;
|
||||
|
||||
uint32_t reserved[80];
|
||||
|
||||
uint16_t io[SIZE_IO >> 1];
|
||||
uint16_t pram[SIZE_PALETTE_RAM >> 1];
|
||||
|
|
Loading…
Reference in New Issue