GBA: Improve reset behavior of various hardware components

This commit is contained in:
Vicki Pfau 2024-12-11 17:24:22 -08:00
parent 655211651a
commit edaa27796b
5 changed files with 33 additions and 1 deletions

View File

@ -86,6 +86,7 @@ struct GBACartridgeHardware {
}; };
void GBAHardwareInit(struct GBACartridgeHardware* gpio, uint16_t* gpioBase); void GBAHardwareInit(struct GBACartridgeHardware* gpio, uint16_t* gpioBase);
void GBAHardwareReset(struct GBACartridgeHardware* gpio);
void GBAHardwareClear(struct GBACartridgeHardware* gpio); void GBAHardwareClear(struct GBACartridgeHardware* gpio);
void GBAHardwareInitRTC(struct GBACartridgeHardware* gpio); void GBAHardwareInitRTC(struct GBACartridgeHardware* gpio);

View File

@ -91,6 +91,7 @@ struct GBASavedataRTCBuffer {
}; };
void GBASavedataInit(struct GBASavedata* savedata, struct VFile* vf); void GBASavedataInit(struct GBASavedata* savedata, struct VFile* vf);
void GBASavedataReset(struct GBASavedata* savedata);
void GBASavedataDeinit(struct GBASavedata* savedata); void GBASavedataDeinit(struct GBASavedata* savedata);
void GBASavedataMask(struct GBASavedata* savedata, struct VFile* vf, bool writeback); void GBASavedataMask(struct GBASavedata* savedata, struct VFile* vf, bool writeback);

View File

@ -47,6 +47,20 @@ void GBAHardwareInit(struct GBACartridgeHardware* hw, uint16_t* base) {
GBAHardwareClear(hw); GBAHardwareClear(hw);
} }
void GBAHardwareReset(struct GBACartridgeHardware* hw) {
hw->readWrite = GPIO_WRITE_ONLY;
hw->pinState = 0;
hw->direction = 0;
hw->lightCounter = 0;
hw->lightEdge = false;
hw->lightSample = 0xFF;
hw->gyroSample = 0;
hw->gyroEdge = 0;
hw->tiltX = 0xFFF;
hw->tiltY = 0xFFF;
hw->tiltState = 0;
}
void GBAHardwareClear(struct GBACartridgeHardware* hw) { void GBAHardwareClear(struct GBACartridgeHardware* hw) {
hw->devices = HW_NONE | (hw->devices & HW_GB_PLAYER_DETECTION); hw->devices = HW_NONE | (hw->devices & HW_GB_PLAYER_DETECTION);
hw->readWrite = GPIO_WRITE_ONLY; hw->readWrite = GPIO_WRITE_ONLY;
@ -503,6 +517,7 @@ void GBAHardwareDeserialize(struct GBACartridgeHardware* hw, const struct GBASer
hw->devices = state->hw.devices; hw->devices = state->hw.devices;
if ((hw->devices & HW_GPIO) && hw->gpioBase) { if ((hw->devices & HW_GPIO) && hw->gpioBase) {
// TODO: This needs to update the pristine state somehow
if (hw->readWrite) { if (hw->readWrite) {
STORE_16(hw->pinState, 0, hw->gpioBase); STORE_16(hw->pinState, 0, hw->gpioBase);
STORE_16(hw->direction, 2, hw->gpioBase); STORE_16(hw->direction, 2, hw->gpioBase);

View File

@ -138,6 +138,16 @@ void GBAMemoryReset(struct GBA* gba) {
mLOG(GBA_MEM, FATAL, "Could not map memory"); mLOG(GBA_MEM, FATAL, "Could not map memory");
} }
if (!gba->memory.rom) {
gba->isPristine = false;
}
if (gba->memory.hw.devices & HW_GPIO) {
_pristineCow(gba);
}
GBASavedataReset(&gba->memory.savedata);
GBAHardwareReset(&gba->memory.hw);
GBADMAReset(gba); GBADMAReset(gba);
GBAUnlCartReset(gba); GBAUnlCartReset(gba);
memset(&gba->memory.matrix, 0, sizeof(gba->memory.matrix)); memset(&gba->memory.matrix, 0, sizeof(gba->memory.matrix));

View File

@ -45,7 +45,7 @@ static void _ashesToAshes(struct mTiming* timing, void* user, uint32_t cyclesLat
void GBASavedataInit(struct GBASavedata* savedata, struct VFile* vf) { void GBASavedataInit(struct GBASavedata* savedata, struct VFile* vf) {
savedata->type = GBA_SAVEDATA_AUTODETECT; savedata->type = GBA_SAVEDATA_AUTODETECT;
savedata->data = 0; savedata->data = NULL;
savedata->command = EEPROM_COMMAND_NULL; savedata->command = EEPROM_COMMAND_NULL;
savedata->flashState = FLASH_STATE_RAW; savedata->flashState = FLASH_STATE_RAW;
savedata->vf = vf; savedata->vf = vf;
@ -63,6 +63,11 @@ void GBASavedataInit(struct GBASavedata* savedata, struct VFile* vf) {
savedata->dust.callback = _ashesToAshes; savedata->dust.callback = _ashesToAshes;
} }
void GBASavedataReset(struct GBASavedata* savedata) {
savedata->command = EEPROM_COMMAND_NULL;
savedata->flashState = FLASH_STATE_RAW;
}
void GBASavedataDeinit(struct GBASavedata* savedata) { void GBASavedataDeinit(struct GBASavedata* savedata) {
if (savedata->vf) { if (savedata->vf) {
size_t size = GBASavedataSize(savedata); size_t size = GBASavedataSize(savedata);