Skip to content

Commit

Permalink
fix bug where save size could be detected incorrectly, if multiple by…
Browse files Browse the repository at this point in the history
…tes in the save are identical
  • Loading branch information
urmum-69 committed Jan 26, 2021
1 parent 154a21c commit e96e8c7
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions source/common/cardEeprom.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit e96e8c7

Please sign in to comment.