From e96e8c70c2857aed9ad0dd4c47dd5b3658c724c3 Mon Sep 17 00:00:00 2001 From: urmum-69 Date: Tue, 26 Jan 2021 08:49:45 +0000 Subject: [PATCH] fix bug where save size could be detected incorrectly, if multiple bytes in the save are identical --- source/common/cardEeprom.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/source/common/cardEeprom.c b/source/common/cardEeprom.c index e3881638..0bbeec66 100644 --- a/source/common/cardEeprom.c +++ b/source/common/cardEeprom.c @@ -96,21 +96,27 @@ uint32 cardEepromGetSize() { return 8192; if(type == 1) return 512; - if(type == 2) { - u32 buf1,buf2,buf3; + if(type == 2) { + u32 buf1,buf2,buf3 = 0x54536554; // "TeST" + // Save the first word of the EEPROM cardReadEeprom(0,(u8*)&buf1,4,type); - if ( !(buf1 != 0 || buf1 != 0xffffffff) ) { - buf3 = ~buf1; - cardWriteEeprom(0,(u8*)&buf3,4,type); - } else { - buf3 = buf1; - } + + // Write "TeST" to it + cardWriteEeprom(0,(u8*)&buf3,4,type); + + // Loop until the EEPROM mirrors and the first word shows up again int size = 8192; - while (1) { + while (1) { cardReadEeprom(size,(u8*)&buf2,4,type); if ( buf2 == buf3 ) break; size += 8192; - }; + } + + // Restore the first word + cardWriteEeprom(0,(u8*)&buf1,4,type); + + return size; + } if ( buf1 != buf3 ) cardWriteEeprom(0,(u8*)&buf1,4,type);