mirror of https://github.com/mgba-emu/mgba.git
GBA: Get GB Player working with savestates
This commit is contained in:
parent
43d9c8b754
commit
5ed05dc66f
|
@ -27,7 +27,6 @@ static void _rumbleReadPins(struct GBACartridgeHardware* hw);
|
||||||
static void _lightReadPins(struct GBACartridgeHardware* hw);
|
static void _lightReadPins(struct GBACartridgeHardware* hw);
|
||||||
|
|
||||||
static uint16_t _gbpRead(struct GBAKeyCallback*);
|
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 uint16_t _gbpSioWriteRegister(struct GBASIODriver* driver, uint32_t address, uint16_t value);
|
||||||
static int32_t _gbpSioProcessEvents(struct GBASIODriver* driver, int32_t cycles);
|
static int32_t _gbpSioProcessEvents(struct GBASIODriver* driver, int32_t cycles);
|
||||||
|
|
||||||
|
@ -52,7 +51,6 @@ void GBAHardwareClear(struct GBACartridgeHardware* hw) {
|
||||||
hw->direction = GPIO_WRITE_ONLY;
|
hw->direction = GPIO_WRITE_ONLY;
|
||||||
hw->pinState = 0;
|
hw->pinState = 0;
|
||||||
hw->direction = 0;
|
hw->direction = 0;
|
||||||
hw->gbpRunning = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GBAHardwareGPIOWrite(struct GBACartridgeHardware* hw, uint32_t address, uint16_t value) {
|
void GBAHardwareGPIOWrite(struct GBACartridgeHardware* hw, uint32_t address, uint16_t value) {
|
||||||
|
@ -501,7 +499,7 @@ bool GBAHardwarePlayerCheckScreen(const struct GBAVideo* video) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GBAHardwarePlayerUpdate(struct GBA* gba) {
|
void GBAHardwarePlayerUpdate(struct GBA* gba) {
|
||||||
if (gba->memory.hw.gbpRunning) {
|
if (gba->memory.hw.devices & HW_GB_PLAYER) {
|
||||||
if (GBAHardwarePlayerCheckScreen(&gba->video)) {
|
if (GBAHardwarePlayerCheckScreen(&gba->video)) {
|
||||||
++gba->memory.hw.gbpInputsPosted;
|
++gba->memory.hw.gbpInputsPosted;
|
||||||
gba->memory.hw.gbpInputsPosted %= 3;
|
gba->memory.hw.gbpInputsPosted %= 3;
|
||||||
|
@ -517,17 +515,18 @@ void GBAHardwarePlayerUpdate(struct GBA* gba) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (GBAHardwarePlayerCheckScreen(&gba->video)) {
|
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.d.readKeys = _gbpRead;
|
||||||
gba->memory.hw.gbpCallback.p = &gba->memory.hw;
|
gba->memory.hw.gbpCallback.p = &gba->memory.hw;
|
||||||
gba->memory.hw.gbpDriver.d.init = 0;
|
gba->memory.hw.gbpDriver.d.init = 0;
|
||||||
gba->memory.hw.gbpDriver.d.deinit = 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.unload = 0;
|
||||||
gba->memory.hw.gbpDriver.d.writeRegister = _gbpSioWriteRegister;
|
gba->memory.hw.gbpDriver.d.writeRegister = _gbpSioWriteRegister;
|
||||||
gba->memory.hw.gbpDriver.d.processEvents = _gbpSioProcessEvents;
|
gba->memory.hw.gbpDriver.d.processEvents = _gbpSioProcessEvents;
|
||||||
gba->memory.hw.gbpDriver.p = &gba->memory.hw;
|
gba->memory.hw.gbpDriver.p = &gba->memory.hw;
|
||||||
gba->memory.hw.gbpInputsPosted = 0;
|
gba->memory.hw.gbpInputsPosted = 0;
|
||||||
|
gba->memory.hw.gbpNextEvent = INT_MAX;
|
||||||
gba->keyCallback = &gba->memory.hw.gbpCallback.d;
|
gba->keyCallback = &gba->memory.hw.gbpCallback.d;
|
||||||
GBASIOSetDriver(&gba->sio, &gba->memory.hw.gbpDriver.d, SIO_NORMAL_32);
|
GBASIOSetDriver(&gba->sio, &gba->memory.hw.gbpDriver.d, SIO_NORMAL_32);
|
||||||
}
|
}
|
||||||
|
@ -541,13 +540,6 @@ uint16_t _gbpRead(struct GBAKeyCallback* callback) {
|
||||||
return 0x3FF;
|
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) {
|
uint16_t _gbpSioWriteRegister(struct GBASIODriver* driver, uint32_t address, uint16_t value) {
|
||||||
struct GBAGBPSIODriver* gbp = (struct GBAGBPSIODriver*) driver;
|
struct GBAGBPSIODriver* gbp = (struct GBAGBPSIODriver*) driver;
|
||||||
if (address == REG_SIOCNT) {
|
if (address == REG_SIOCNT) {
|
||||||
|
@ -608,6 +600,9 @@ void GBAHardwareSerialize(const struct GBACartridgeHardware* hw, struct GBASeria
|
||||||
state->hw.lightCounter = hw->lightCounter;
|
state->hw.lightCounter = hw->lightCounter;
|
||||||
state->hw.lightSample = hw->lightSample;
|
state->hw.lightSample = hw->lightSample;
|
||||||
state->hw.lightEdge = hw->lightEdge;
|
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) {
|
void GBAHardwareDeserialize(struct GBACartridgeHardware* hw, const struct GBASerializedState* state) {
|
||||||
|
@ -623,4 +618,7 @@ void GBAHardwareDeserialize(struct GBACartridgeHardware* hw, const struct GBASer
|
||||||
hw->lightCounter = state->hw.lightCounter;
|
hw->lightCounter = state->hw.lightCounter;
|
||||||
hw->lightSample = state->hw.lightSample;
|
hw->lightSample = state->hw.lightSample;
|
||||||
hw->lightEdge = state->hw.lightEdge;
|
hw->lightEdge = state->hw.lightEdge;
|
||||||
|
hw->gbpInputsPosted = state->hw.gbpInputsPosted;
|
||||||
|
hw->gbpTxPosition = state->hw.gbpTxPosition;
|
||||||
|
hw->gbpNextEvent = state->hw.gbpNextEvent;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,8 @@ enum GBAHardwareDevice {
|
||||||
HW_RUMBLE = 2,
|
HW_RUMBLE = 2,
|
||||||
HW_LIGHT_SENSOR = 4,
|
HW_LIGHT_SENSOR = 4,
|
||||||
HW_GYRO = 8,
|
HW_GYRO = 8,
|
||||||
HW_TILT = 16
|
HW_TILT = 16,
|
||||||
|
HW_GB_PLAYER = 32
|
||||||
};
|
};
|
||||||
|
|
||||||
enum GPIORegister {
|
enum GPIORegister {
|
||||||
|
@ -116,12 +117,11 @@ struct GBACartridgeHardware {
|
||||||
uint16_t tiltY;
|
uint16_t tiltY;
|
||||||
int tiltState;
|
int tiltState;
|
||||||
|
|
||||||
bool gbpRunning;
|
unsigned gbpInputsPosted;
|
||||||
int gbpInputsPosted;
|
|
||||||
int gbpTxPosition;
|
int gbpTxPosition;
|
||||||
|
int32_t gbpNextEvent;
|
||||||
struct GBAGBPKeyCallback gbpCallback;
|
struct GBAGBPKeyCallback gbpCallback;
|
||||||
struct GBAGBPSIODriver gbpDriver;
|
struct GBAGBPSIODriver gbpDriver;
|
||||||
int32_t gbpNextEvent;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void GBAHardwareInit(struct GBACartridgeHardware* gpio, uint16_t* gpioBase);
|
void GBAHardwareInit(struct GBACartridgeHardware* gpio, uint16_t* gpioBase);
|
||||||
|
|
|
@ -136,7 +136,8 @@ extern const uint32_t GBA_SAVESTATE_MAGIC;
|
||||||
* | bit 2: Has light sensor value
|
* | bit 2: Has light sensor value
|
||||||
* | bit 3: Has gyroscope value
|
* | bit 3: Has gyroscope value
|
||||||
* | bit 4: Has tilt values
|
* | bit 4: Has tilt values
|
||||||
* | bits 5 - 7: Reserved
|
* | bit 5: Has Game Boy Player attached
|
||||||
|
* | bits 6 - 7: Reserved
|
||||||
* | 0x002B8 - 0x002B9: Gyroscope sample
|
* | 0x002B8 - 0x002B9: Gyroscope sample
|
||||||
* | 0x002BA - 0x002BB: Tilt x sample
|
* | 0x002BA - 0x002BB: Tilt x sample
|
||||||
* | 0x002BC - 0x002BD: Tilt y sample
|
* | 0x002BC - 0x002BD: Tilt y sample
|
||||||
|
@ -149,8 +150,11 @@ extern const uint32_t GBA_SAVESTATE_MAGIC;
|
||||||
* | 0x002C0 - 0x002C0: Light sample
|
* | 0x002C0 - 0x002C0: Light sample
|
||||||
* | 0x002C1 - 0x002C3: Flags
|
* | 0x002C1 - 0x002C3: Flags
|
||||||
* | bits 0 - 1: Tilt state machine
|
* | bits 0 - 1: Tilt state machine
|
||||||
* | bits 2 - 31: Reserved
|
* | bits 2 - 3: GB Player inputs posted
|
||||||
* 0x002C4 - 0x002DF: Reserved (leave zero)
|
* | 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 - 0x002EF: Savedata state
|
||||||
* | 0x002E0 - 0x002E0: Savedata type
|
* | 0x002E0 - 0x002E0: Savedata type
|
||||||
* | 0x002E1 - 0x002E1: Savedata command (see savedata.h)
|
* | 0x002E1 - 0x002E1: Savedata command (see savedata.h)
|
||||||
|
@ -282,10 +286,13 @@ struct GBASerializedState {
|
||||||
unsigned lightCounter : 12;
|
unsigned lightCounter : 12;
|
||||||
unsigned lightSample : 8;
|
unsigned lightSample : 8;
|
||||||
unsigned tiltState : 2;
|
unsigned tiltState : 2;
|
||||||
unsigned : 22;
|
unsigned gbpInputsPosted : 2;
|
||||||
|
unsigned gbpTxPosition : 5;
|
||||||
|
unsigned : 15;
|
||||||
|
uint32_t gbpNextEvent : 32;
|
||||||
} hw;
|
} hw;
|
||||||
|
|
||||||
uint32_t reservedHardware[7];
|
uint32_t reservedHardware[6];
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
unsigned type : 8;
|
unsigned type : 8;
|
||||||
|
|
Loading…
Reference in New Issue