From c3e02f9c92f7f834a8baef8fc597ff6c0f5eb6b7 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Tue, 8 May 2018 10:25:09 -0700 Subject: [PATCH] GBA Savedata: Remove ability to disable realistic timing --- CHANGES | 1 + include/mgba/internal/gba/gba.h | 1 - include/mgba/internal/gba/savedata.h | 7 +++-- src/gba/dma.c | 4 +-- src/gba/gba.c | 1 - src/gba/memory.c | 4 +-- src/gba/overrides.c | 2 +- src/gba/savedata.c | 38 +++++++++++----------------- src/gba/sharkport.c | 2 +- 9 files changed, 25 insertions(+), 35 deletions(-) diff --git a/CHANGES b/CHANGES index e243f9ff7..a1bd541bb 100644 --- a/CHANGES +++ b/CHANGES @@ -52,6 +52,7 @@ Misc: - PSP2: Use system enter key by default - 3DS: Remove deprecated CSND interface - Qt: Options to mess around with layer placement + - GBA Savedata: Remove ability to disable realistic timing 0.6.3: (2017-04-14) Bugfixes: diff --git a/include/mgba/internal/gba/gba.h b/include/mgba/internal/gba/gba.h index e8bff15ee..8796f113e 100644 --- a/include/mgba/internal/gba/gba.h +++ b/include/mgba/internal/gba/gba.h @@ -112,7 +112,6 @@ struct GBA { int32_t cachedRegisters[16]; bool taintedRegisters[16]; - bool realisticTiming; bool hardCrash; bool allowOpposingDirections; diff --git a/include/mgba/internal/gba/savedata.h b/include/mgba/internal/gba/savedata.h index af4c897d0..ecf17eecf 100644 --- a/include/mgba/internal/gba/savedata.h +++ b/include/mgba/internal/gba/savedata.h @@ -87,7 +87,6 @@ struct GBASavedata { uint8_t* currentBank; struct mTiming* timing; - bool realisticTiming; unsigned settling; struct mTimingEvent dust; @@ -105,10 +104,10 @@ void GBASavedataUnmask(struct GBASavedata* savedata); size_t GBASavedataSize(const struct GBASavedata* savedata); bool GBASavedataClone(struct GBASavedata* savedata, struct VFile* out); bool GBASavedataLoad(struct GBASavedata* savedata, struct VFile* in); -void GBASavedataForceType(struct GBASavedata* savedata, enum SavedataType type, bool realisticTiming); +void GBASavedataForceType(struct GBASavedata* savedata, enum SavedataType type); -void GBASavedataInitFlash(struct GBASavedata* savedata, bool realisticTiming); -void GBASavedataInitEEPROM(struct GBASavedata* savedata, bool realisticTiming); +void GBASavedataInitFlash(struct GBASavedata* savedata); +void GBASavedataInitEEPROM(struct GBASavedata* savedata); void GBASavedataInitSRAM(struct GBASavedata* savedata); uint8_t GBASavedataReadFlash(struct GBASavedata* savedata, uint16_t address); diff --git a/src/gba/dma.c b/src/gba/dma.c index 4516b5224..59dd7da3c 100644 --- a/src/gba/dma.c +++ b/src/gba/dma.c @@ -265,7 +265,7 @@ void GBADMAService(struct GBA* gba, int number, struct GBADMA* info) { if (sourceRegion == REGION_CART2_EX && memory->savedata.type == SAVEDATA_EEPROM) { if (memory->savedata.type == SAVEDATA_AUTODETECT) { mLOG(GBA_MEM, INFO, "Detected EEPROM savegame"); - GBASavedataInitEEPROM(&memory->savedata, gba->realisticTiming); + GBASavedataInitEEPROM(&memory->savedata); } memory->dmaTransferRegister = GBASavedataReadEEPROM(&memory->savedata); } else { @@ -276,7 +276,7 @@ void GBADMAService(struct GBA* gba, int number, struct GBADMA* info) { if (destRegion == REGION_CART2_EX) { if (memory->savedata.type == SAVEDATA_AUTODETECT) { mLOG(GBA_MEM, INFO, "Detected EEPROM savegame"); - GBASavedataInitEEPROM(&memory->savedata, gba->realisticTiming); + GBASavedataInitEEPROM(&memory->savedata); } GBASavedataWriteEEPROM(&memory->savedata, memory->dmaTransferRegister, wordsRemaining); } else { diff --git a/src/gba/gba.c b/src/gba/gba.c index f14c639c9..48f8ee2af 100644 --- a/src/gba/gba.c +++ b/src/gba/gba.c @@ -105,7 +105,6 @@ static void GBAInit(void* cpu, struct mCPUComponent* component) { gba->idleOptimization = IDLE_LOOP_REMOVE; gba->idleLoop = IDLE_LOOP_NONE; - gba->realisticTiming = true; gba->hardCrash = true; gba->allowOpposingDirections = true; diff --git a/src/gba/memory.c b/src/gba/memory.c index fa279104f..0d16fc82a 100644 --- a/src/gba/memory.c +++ b/src/gba/memory.c @@ -895,7 +895,7 @@ void GBAStore16(struct ARMCore* cpu, uint32_t address, int16_t value, int* cycle case REGION_CART2_EX: if (memory->savedata.type == SAVEDATA_AUTODETECT) { mLOG(GBA_MEM, INFO, "Detected EEPROM savegame"); - GBASavedataInitEEPROM(&memory->savedata, gba->realisticTiming); + GBASavedataInitEEPROM(&memory->savedata); } GBASavedataWriteEEPROM(&memory->savedata, value, 1); break; @@ -961,7 +961,7 @@ void GBAStore8(struct ARMCore* cpu, uint32_t address, int8_t value, int* cycleCo if (memory->savedata.type == SAVEDATA_AUTODETECT) { if (address == SAVEDATA_FLASH_BASE) { mLOG(GBA_MEM, INFO, "Detected Flash savegame"); - GBASavedataInitFlash(&memory->savedata, gba->realisticTiming); + GBASavedataInitFlash(&memory->savedata); } else { mLOG(GBA_MEM, INFO, "Detected SRAM savegame"); GBASavedataInitSRAM(&memory->savedata); diff --git a/src/gba/overrides.c b/src/gba/overrides.c index 1a1e9c9ec..7227404b7 100644 --- a/src/gba/overrides.c +++ b/src/gba/overrides.c @@ -296,7 +296,7 @@ void GBAOverrideSave(struct Configuration* config, const struct GBACartridgeOver void GBAOverrideApply(struct GBA* gba, const struct GBACartridgeOverride* override) { if (override->savetype != SAVEDATA_AUTODETECT) { - GBASavedataForceType(&gba->memory.savedata, override->savetype, gba->realisticTiming); + GBASavedataForceType(&gba->memory.savedata, override->savetype); } if (override->hardware != HW_NO_OVERRIDE) { diff --git a/src/gba/savedata.c b/src/gba/savedata.c index 92f7741cb..bb19f3e34 100644 --- a/src/gba/savedata.c +++ b/src/gba/savedata.c @@ -91,7 +91,7 @@ void GBASavedataMask(struct GBASavedata* savedata, struct VFile* vf, bool writeb savedata->vf = vf; savedata->mapMode = MAP_READ; savedata->maskWriteback = writeback; - GBASavedataForceType(savedata, type, savedata->realisticTiming); + GBASavedataForceType(savedata, type); } void GBASavedataUnmask(struct GBASavedata* savedata) { @@ -103,7 +103,7 @@ void GBASavedataUnmask(struct GBASavedata* savedata) { GBASavedataDeinit(savedata); savedata->vf = savedata->realVf; savedata->mapMode = MAP_WRITE; - GBASavedataForceType(savedata, type, savedata->realisticTiming); + GBASavedataForceType(savedata, type); if (savedata->maskWriteback) { GBASavedataLoad(savedata, vf); savedata->maskWriteback = false; @@ -193,7 +193,7 @@ bool GBASavedataLoad(struct GBASavedata* savedata, struct VFile* in) { return true; } -void GBASavedataForceType(struct GBASavedata* savedata, enum SavedataType type, bool realisticTiming) { +void GBASavedataForceType(struct GBASavedata* savedata, enum SavedataType type) { if (savedata->type != SAVEDATA_AUTODETECT) { struct VFile* vf = savedata->vf; GBASavedataDeinit(savedata); @@ -203,10 +203,10 @@ void GBASavedataForceType(struct GBASavedata* savedata, enum SavedataType type, case SAVEDATA_FLASH512: case SAVEDATA_FLASH1M: savedata->type = type; - GBASavedataInitFlash(savedata, realisticTiming); + GBASavedataInitFlash(savedata); break; case SAVEDATA_EEPROM: - GBASavedataInitEEPROM(savedata, realisticTiming); + GBASavedataInitEEPROM(savedata); break; case SAVEDATA_SRAM: GBASavedataInitSRAM(savedata); @@ -219,7 +219,7 @@ void GBASavedataForceType(struct GBASavedata* savedata, enum SavedataType type, } } -void GBASavedataInitFlash(struct GBASavedata* savedata, bool realisticTiming) { +void GBASavedataInitFlash(struct GBASavedata* savedata) { if (savedata->type == SAVEDATA_AUTODETECT) { savedata->type = SAVEDATA_FLASH512; } @@ -244,13 +244,12 @@ void GBASavedataInitFlash(struct GBASavedata* savedata, bool realisticTiming) { } savedata->currentBank = savedata->data; - savedata->realisticTiming = realisticTiming; if (end < SIZE_CART_FLASH512) { memset(&savedata->data[end], 0xFF, flashSize - end); } } -void GBASavedataInitEEPROM(struct GBASavedata* savedata, bool realisticTiming) { +void GBASavedataInitEEPROM(struct GBASavedata* savedata) { if (savedata->type == SAVEDATA_AUTODETECT) { savedata->type = SAVEDATA_EEPROM; } else { @@ -271,7 +270,6 @@ void GBASavedataInitEEPROM(struct GBASavedata* savedata, bool realisticTiming) { } savedata->data = savedata->vf->map(savedata->vf, eepromSize, savedata->mapMode); } - savedata->realisticTiming = realisticTiming; if (end < SIZE_CART_EEPROM512) { memset(&savedata->data[end], 0xFF, SIZE_CART_EEPROM512 - end); } @@ -327,10 +325,8 @@ void GBASavedataWriteFlash(struct GBASavedata* savedata, uint16_t address, uint8 savedata->dirty |= SAVEDATA_DIRT_NEW; savedata->currentBank[address] = value; savedata->command = FLASH_COMMAND_NONE; - if (savedata->realisticTiming) { - mTimingDeschedule(savedata->timing, &savedata->dust); - mTimingSchedule(savedata->timing, &savedata->dust, FLASH_PROGRAM_CYCLES); - } + mTimingDeschedule(savedata->timing, &savedata->dust); + mTimingSchedule(savedata->timing, &savedata->dust, FLASH_PROGRAM_CYCLES); break; case FLASH_COMMAND_SWITCH_BANK: if (address == 0 && value < 2) { @@ -452,10 +448,8 @@ void GBASavedataWriteEEPROM(struct GBASavedata* savedata, uint16_t value, uint32 current |= (value & 0x1) << (0x7 - (savedata->writeAddress & 0x7)); savedata->dirty |= SAVEDATA_DIRT_NEW; savedata->data[savedata->writeAddress >> 3] = current; - if (savedata->realisticTiming) { - mTimingDeschedule(savedata->timing, &savedata->dust); - mTimingSchedule(savedata->timing, &savedata->dust, EEPROM_SETTLE_CYCLES); - } + mTimingDeschedule(savedata->timing, &savedata->dust); + mTimingSchedule(savedata->timing, &savedata->dust, EEPROM_SETTLE_CYCLES); ++savedata->writeAddress; } else { mLOG(GBA_SAVE, GAME_ERROR, "Writing beyond end of EEPROM: %08X", (savedata->writeAddress >> 3)); @@ -478,7 +472,7 @@ void GBASavedataWriteEEPROM(struct GBASavedata* savedata, uint16_t value, uint32 uint16_t GBASavedataReadEEPROM(struct GBASavedata* savedata) { if (savedata->command != EEPROM_COMMAND_READ) { - if (!savedata->realisticTiming || !mTimingIsScheduled(savedata->timing, &savedata->dust)) { + if (!mTimingIsScheduled(savedata->timing, &savedata->dust)) { return 1; } else { return 0; @@ -551,7 +545,7 @@ void GBASavedataSerialize(const struct GBASavedata* savedata, struct GBASerializ void GBASavedataDeserialize(struct GBASavedata* savedata, const struct GBASerializedState* state) { if (savedata->type != state->savedata.type) { mLOG(GBA_SAVE, DEBUG, "Switching save types"); - GBASavedataForceType(savedata, state->savedata.type, savedata->realisticTiming); + GBASavedataForceType(savedata, state->savedata.type); } savedata->command = state->savedata.command; GBASerializedSavedataFlags flags = state->savedata.flags; @@ -609,9 +603,7 @@ void _flashEraseSector(struct GBASavedata* savedata, uint16_t sectorStart) { mLOG(GBA_SAVE, DEBUG, "Performing unknown sector-size erase at 0x%04x", sectorStart); } savedata->settling = sectorStart >> 12; - if (savedata->realisticTiming) { - mTimingDeschedule(savedata->timing, &savedata->dust); - mTimingSchedule(savedata->timing, &savedata->dust, FLASH_ERASE_CYCLES); - } + mTimingDeschedule(savedata->timing, &savedata->dust); + mTimingSchedule(savedata->timing, &savedata->dust, FLASH_ERASE_CYCLES); memset(&savedata->currentBank[sectorStart & ~(size - 1)], 0xFF, size); } diff --git a/src/gba/sharkport.c b/src/gba/sharkport.c index 88c79eec6..ee717bdee 100644 --- a/src/gba/sharkport.c +++ b/src/gba/sharkport.c @@ -117,7 +117,7 @@ bool GBASavedataImportSharkPort(struct GBA* gba, struct VFile* vf, bool testChec switch (gba->memory.savedata.type) { case SAVEDATA_FLASH512: if (copySize > SIZE_CART_FLASH512) { - GBASavedataForceType(&gba->memory.savedata, SAVEDATA_FLASH1M, gba->memory.savedata.realisticTiming); + GBASavedataForceType(&gba->memory.savedata, SAVEDATA_FLASH1M); } // Fall through default: