all repos — mgba @ 5ed05dc66f3cff5e065a70ea79e857ddcec0570e

mGBA Game Boy Advance Emulator

GBA: Get GB Player working with savestates
Jeffrey Pfau jeffrey@endrift.com
Mon, 13 Jul 2015 21:19:01 -0700
commit

5ed05dc66f3cff5e065a70ea79e857ddcec0570e

parent

43d9c8b754b4ccc2376ac319d56da25a7ced8eda

3 files changed, 26 insertions(+), 21 deletions(-)

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

@@ -27,7 +27,6 @@

static void _lightReadPins(struct GBACartridgeHardware* hw); static uint16_t _gbpRead(struct GBAKeyCallback*); -static bool _gbpSioLoad(struct GBASIODriver* driver); static uint16_t _gbpSioWriteRegister(struct GBASIODriver* driver, uint32_t address, uint16_t value); static int32_t _gbpSioProcessEvents(struct GBASIODriver* driver, int32_t cycles);

@@ -52,7 +51,6 @@ hw->devices = HW_NONE;

hw->direction = GPIO_WRITE_ONLY; hw->pinState = 0; hw->direction = 0; - hw->gbpRunning = false; } void GBAHardwareGPIOWrite(struct GBACartridgeHardware* hw, uint32_t address, uint16_t value) {

@@ -501,7 +499,7 @@ return hash == _logoHash;

} void GBAHardwarePlayerUpdate(struct GBA* gba) { - if (gba->memory.hw.gbpRunning) { + if (gba->memory.hw.devices & HW_GB_PLAYER) { if (GBAHardwarePlayerCheckScreen(&gba->video)) { ++gba->memory.hw.gbpInputsPosted; gba->memory.hw.gbpInputsPosted %= 3;

@@ -517,17 +515,18 @@ if (gba->keyCallback || gba->sio.drivers.normal) {

return; } if (GBAHardwarePlayerCheckScreen(&gba->video)) { - gba->memory.hw.gbpRunning = true; + gba->memory.hw.devices |= HW_GB_PLAYER; gba->memory.hw.gbpCallback.d.readKeys = _gbpRead; gba->memory.hw.gbpCallback.p = &gba->memory.hw; gba->memory.hw.gbpDriver.d.init = 0; gba->memory.hw.gbpDriver.d.deinit = 0; - gba->memory.hw.gbpDriver.d.load = _gbpSioLoad; + gba->memory.hw.gbpDriver.d.load = 0; gba->memory.hw.gbpDriver.d.unload = 0; gba->memory.hw.gbpDriver.d.writeRegister = _gbpSioWriteRegister; gba->memory.hw.gbpDriver.d.processEvents = _gbpSioProcessEvents; gba->memory.hw.gbpDriver.p = &gba->memory.hw; gba->memory.hw.gbpInputsPosted = 0; + gba->memory.hw.gbpNextEvent = INT_MAX; gba->keyCallback = &gba->memory.hw.gbpCallback.d; GBASIOSetDriver(&gba->sio, &gba->memory.hw.gbpDriver.d, SIO_NORMAL_32); }

@@ -539,13 +538,6 @@ if (gbpCallback->p->gbpInputsPosted == 2) {

return 0x30F; } return 0x3FF; -} - -bool _gbpSioLoad(struct GBASIODriver* driver) { - struct GBAGBPSIODriver* gbp = (struct GBAGBPSIODriver*) driver; - gbp->p->gbpTxPosition = 0; - gbp->p->gbpNextEvent = INT_MAX; - return true; } uint16_t _gbpSioWriteRegister(struct GBASIODriver* driver, uint32_t address, uint16_t value) {

@@ -608,6 +600,9 @@ state->hw.tiltState = hw->tiltState;

state->hw.lightCounter = hw->lightCounter; state->hw.lightSample = hw->lightSample; state->hw.lightEdge = hw->lightEdge; + state->hw.gbpInputsPosted = hw->gbpInputsPosted; + state->hw.gbpTxPosition = hw->gbpTxPosition; + state->hw.gbpNextEvent = hw->gbpNextEvent; } void GBAHardwareDeserialize(struct GBACartridgeHardware* hw, const struct GBASerializedState* state) {

@@ -623,4 +618,7 @@ hw->tiltState = state->hw.tiltState;

hw->lightCounter = state->hw.lightCounter; 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; }
M src/gba/hardware.hsrc/gba/hardware.h

@@ -33,7 +33,8 @@ HW_RTC = 1,

HW_RUMBLE = 2, HW_LIGHT_SENSOR = 4, HW_GYRO = 8, - HW_TILT = 16 + HW_TILT = 16, + HW_GB_PLAYER = 32 }; enum GPIORegister {

@@ -116,12 +117,11 @@ uint16_t tiltX;

uint16_t tiltY; int tiltState; - bool gbpRunning; - int gbpInputsPosted; + unsigned gbpInputsPosted; int gbpTxPosition; + int32_t gbpNextEvent; struct GBAGBPKeyCallback gbpCallback; struct GBAGBPSIODriver gbpDriver; - int32_t gbpNextEvent; }; void GBAHardwareInit(struct GBACartridgeHardware* gpio, uint16_t* gpioBase);
M src/gba/serialize.hsrc/gba/serialize.h

@@ -136,7 +136,8 @@ * | bit 1: Has rumble value (reserved)

* | bit 2: Has light sensor value * | bit 3: Has gyroscope value * | bit 4: Has tilt values - * | bits 5 - 7: Reserved + * | bit 5: Has Game Boy Player attached + * | bits 6 - 7: Reserved * | 0x002B8 - 0x002B9: Gyroscope sample * | 0x002BA - 0x002BB: Tilt x sample * | 0x002BC - 0x002BD: Tilt y sample

@@ -149,8 +150,11 @@ * | bits 4 - 15: Light counter

* | 0x002C0 - 0x002C0: Light sample * | 0x002C1 - 0x002C3: Flags * | bits 0 - 1: Tilt state machine - * | bits 2 - 31: Reserved - * 0x002C4 - 0x002DF: Reserved (leave zero) + * | bits 2 - 3: GB Player inputs posted + * | bits 4 - 8: GB Player transmit position + * | bits 9 - 23: Reserved + * 0x002C4 - 0x002C7: Game Boy Player next event + * 0x002C8 - 0x002DF: Reserved (leave zero) * 0x002E0 - 0x002EF: Savedata state * | 0x002E0 - 0x002E0: Savedata type * | 0x002E1 - 0x002E1: Savedata command (see savedata.h)

@@ -282,10 +286,13 @@ unsigned : 1;

unsigned lightCounter : 12; unsigned lightSample : 8; unsigned tiltState : 2; - unsigned : 22; + unsigned gbpInputsPosted : 2; + unsigned gbpTxPosition : 5; + unsigned : 15; + uint32_t gbpNextEvent : 32; } hw; - uint32_t reservedHardware[7]; + uint32_t reservedHardware[6]; struct { unsigned type : 8;