From 8538e99a089118d0dc004eddbf48f453fbf9ebbc Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Fri, 19 Jun 2015 04:25:29 -0700 Subject: [PATCH] GBA: Flash erase timing changes --- CHANGES | 1 + src/gba/savedata.c | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 96675d4d3..4a37e4abe 100644 --- a/CHANGES +++ b/CHANGES @@ -80,6 +80,7 @@ Misc: - Qt: Make the default fullscreen binding for Windows be Alt-Enter - GBA Video: Refactor software renderer into separate files - ARM7: Add emulation for Undefined CPU mode + - GBA: More accurate cycle estimation for ROM prefetch and flash save chips 0.2.1: (2015-05-13) Bugfixes: diff --git a/src/gba/savedata.c b/src/gba/savedata.c index 68cccf685..0321b36bd 100644 --- a/src/gba/savedata.c +++ b/src/gba/savedata.c @@ -14,6 +14,11 @@ #include #include +// Some testing was done here... +// Erase cycles can vary greatly. +// Some games may vary anywhere between about 2000 cycles to up to 30000 cycles. (Observed on a Macronix (09C2) chip). +// Other games vary from very little, with a fairly solid 20500 cycle count. (Observed on a SST (D4BF) chip). +// An average estimation is as follows. #define FLASH_SETTLE_CYCLES 18000 static void _flashSwitchBank(struct GBASavedata* savedata, int bank); @@ -234,7 +239,9 @@ uint8_t GBASavedataReadFlash(struct GBASavedata* savedata, uint16_t address) { } } if (savedata->dust > 0 && (address >> 12) == savedata->settling) { - --savedata->dust; + // Give some overhead for waitstates and the comparison + // This estimation can probably be improved + savedata->dust -= 10; return 0x5F; } return savedata->currentBank[address];