all repos — mgba @ 3915158c96cb6c40c0da774c8f1b13b8a4f07db5

mGBA Game Boy Advance Emulator

Update GPIO for serialization
Jeffrey Pfau jeffrey@endrift.com
Sun, 20 Jul 2014 15:53:15 -0700
commit

3915158c96cb6c40c0da774c8f1b13b8a4f07db5

parent

381fc94d7397a324207a4a48195a6a29b9e5825e

4 files changed, 66 insertions(+), 5 deletions(-)

jump to
M src/gba/gba-gpio.csrc/gba/gba-gpio.c

@@ -2,6 +2,7 @@ #include "gba.h"

#include "gba-gpio.h" #include "gba-sensors.h" +#include "gba-serialize.h" #include <time.h>

@@ -302,3 +303,25 @@ }

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; +}
M src/gba/gba-gpio.hsrc/gba/gba-gpio.h

@@ -10,7 +10,8 @@ GPIO_NONE = 0,

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 @@ int commandActive;

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 GBARTC rtc; uint16_t gyroSample; - int gyroEdge; + bool gyroEdge; }; void GBAGPIOInit(struct GBACartridgeGPIO* gpio, uint16_t* gpioBase);

@@ -107,5 +108,9 @@

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
M src/gba/gba-io.csrc/gba/gba-io.c

@@ -462,6 +462,7 @@ state->dma[i].nextEvent = gba->memory.dma[i].nextEvent;

} 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 @@ if (gba->timers[i].enable) {

gba->timersEnabled |= 1 << i; } } + GBAGPIODeserialize(&gba->memory.gpio, state); }
M src/gba/gba-serialize.hsrc/gba/gba-serialize.h

@@ -121,7 +121,25 @@ * | 0x00280 - 0x00283: DMA next source

* | 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 @@ int32_t nextCount;

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];