[Gamecube/Wii] reduced SRAM file size

This commit is contained in:
EkeEke 2014-12-14 18:55:02 +01:00
parent 8392d93fcb
commit 7fe5b09e3e
5 changed files with 27 additions and 8 deletions

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 MiB

After

Width:  |  Height:  |  Size: 3.7 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 MiB

After

Width:  |  Height:  |  Size: 3.8 MiB

View File

@ -3,7 +3,7 @@
* *
* FAT and Memory Card SRAM/State slots managment * FAT and Memory Card SRAM/State slots managment
* *
* Copyright Eke-Eke (2008-2012), based on original code from Softdev (2006) * Copyright Eke-Eke (2008-2014), based on original code from Softdev (2006)
* *
* Redistribution and use of this code or any derivative works are permitted * Redistribution and use of this code or any derivative works are permitted
* provided that the following conditions are met: * provided that the following conditions are met:
@ -553,6 +553,7 @@ int slot_load(int slot, int device)
/* Uncompress file */ /* Uncompress file */
uncompress ((Bytef *)buffer, &filesize, (Bytef *)(in + 2112 + 4), done - 2112 - 4); uncompress ((Bytef *)buffer, &filesize, (Bytef *)(in + 2112 + 4), done - 2112 - 4);
done = filesize;
free(in); free(in);
} }
@ -568,8 +569,16 @@ int slot_load(int slot, int device)
} }
else else
{ {
/* load SRAM */ /* load SRAM (max. 64 KB)*/
memcpy(sram.sram, buffer, 0x10000); if (done < 0x10000)
{
memcpy(sram.sram, buffer, done);
memset(sram.sram + done, 0xFF, 0x10000 - done);
}
else
{
memcpy(sram.sram, buffer, 0x10000);
}
/* update CRC */ /* update CRC */
sram.crc = crc32(0, sram.sram, 0x10000); sram.crc = crc32(0, sram.sram, 0x10000);
@ -609,8 +618,19 @@ int slot_save(int slot, int device)
return 0; return 0;
} }
/* max. supported SRAM size */
filesize = 0x10000;
/* only save modified SRAM size */
do
{
if (sram.sram[filesize-1] != 0xff)
break;
}
while (--filesize > 0);
/* only save if SRAM has been modified */ /* only save if SRAM has been modified */
if (crc32(0, &sram.sram[0], 0x10000) == sram.crc) if ((filesize == 0) || (crc32(0, &sram.sram[0], 0x10000) == sram.crc))
{ {
GUI_WaitPrompt("Warning","Backup RAM not modified !"); GUI_WaitPrompt("Warning","Backup RAM not modified !");
return 0; return 0;
@ -619,7 +639,7 @@ int slot_save(int slot, int device)
GUI_MsgBoxOpen("Information","Saving Backup RAM ...",1); GUI_MsgBoxOpen("Information","Saving Backup RAM ...",1);
/* allocate buffer */ /* allocate buffer */
buffer = (u8 *)memalign(32, 0x10000); buffer = (u8 *)memalign(32, filesize);
if (!buffer) if (!buffer)
{ {
GUI_WaitPrompt("Error","Unable to allocate memory !"); GUI_WaitPrompt("Error","Unable to allocate memory !");
@ -627,8 +647,7 @@ int slot_save(int slot, int device)
} }
/* copy SRAM data */ /* copy SRAM data */
memcpy(buffer, sram.sram, 0x10000); memcpy(buffer, sram.sram, filesize);
filesize = 0x10000;
/* update CRC */ /* update CRC */
sram.crc = crc32(0, sram.sram, 0x10000); sram.crc = crc32(0, sram.sram, 0x10000);

View File

@ -3,7 +3,7 @@
* *
* FAT and Memory Card SRAM/Savestate files managment * FAT and Memory Card SRAM/Savestate files managment
* *
* Copyright Eke-Eke (2008-2012), based on original code from Softdev (2006) * Copyright Eke-Eke (2008-2014), based on original code from Softdev (2006)
* *
* Redistribution and use of this code or any derivative works are permitted * Redistribution and use of this code or any derivative works are permitted
* provided that the following conditions are met: * provided that the following conditions are met: