fixed bug with PNG file support introduced in previous revision

fixed GC Memory Card Support on Wii
added Memory Card sector size error check
This commit is contained in:
ekeeke31 2010-04-14 12:28:12 +00:00
parent 3339a4c467
commit 0ac9bd43da
3 changed files with 243 additions and 226 deletions

View File

@ -102,8 +102,7 @@ static int FAT_ManageFile(char *filename, u8 direction, u8 filetype)
return 0; return 0;
} }
sprintf (fname, "Saved %d bytes successfully", done); GUI_MsgBoxClose();
GUI_WaitPrompt("Information",fname);
return 1; return 1;
case 1: /* LOADING */ case 1: /* LOADING */
@ -144,8 +143,7 @@ static int FAT_ManageFile(char *filename, u8 direction, u8 filetype)
} }
} }
sprintf (fname, "Loaded %d bytes successfully", done); GUI_MsgBoxClose();
GUI_WaitPrompt("Information",fname);
return 1; return 1;
} }
@ -165,16 +163,20 @@ static int MountTheCard (u8 slot)
{ {
int tries = 0; int tries = 0;
int CardError; int CardError;
*(unsigned long *) (0xcc006800) |= 1 << 13; /*** Disable Encryption ***/ #if defined(HW_DOL)
#ifndef HW_RVL *(unsigned long *) (0xCC006800) |= 1 << 13; /*** Disable Encryption ***/
uselessinquiry (); uselessinquiry ();
#elif defined(HW_RVL)
*(unsigned long *) (0xCD006800) |= 1 << 13; /*** Disable Encryption ***/
#endif #endif
while (tries < 10) while (tries < 10)
{ {
VIDEO_WaitVSync (); VIDEO_WaitVSync ();
CardError = CARD_Mount (slot, SysArea, NULL); /*** Don't need or want a callback ***/ CardError = CARD_Mount (slot, SysArea, NULL); /*** Don't need or want a callback ***/
if (CardError == 0) return 1; if (CardError == 0)
else EXI_ProbeReset (); return 1;
else
EXI_ProbeReset ();
tries++; tries++;
} }
return 0; return 0;
@ -192,7 +194,8 @@ static int CardFileExists (char *filename, u8 slot)
while (CardError != CARD_ERROR_NOFILE) while (CardError != CARD_ERROR_NOFILE)
{ {
CardError = CARD_FindNext (&CardDir); CardError = CARD_FindNext (&CardDir);
if (strcmp ((char *) CardDir.filename, filename) == 0) return 1; if (strcmp ((char *) CardDir.filename, filename) == 0)
return 1;
} }
return 0; return 0;
} }
@ -250,12 +253,15 @@ void memfile_autosave(s8 autosram, s8 autostate)
****************************************************************************/ ****************************************************************************/
int ManageSRAM (u8 direction, u8 device) int ManageSRAM (u8 direction, u8 device)
{ {
if (!cart.romsize) return 0; if (!cart.romsize)
return 0;
char filename[MAXJOLIET]; char filename[MAXJOLIET];
if (direction) GUI_MsgBoxOpen("Information","Loading SRAM ...",1); if (direction)
else GUI_MsgBoxOpen("Information","Saving SRAM ...",1); GUI_MsgBoxOpen("Information","Loading SRAM ...",1);
else
GUI_MsgBoxOpen("Information","Saving SRAM ...",1);
/* clean buffer */ /* clean buffer */
memset(savebuffer, 0, STATE_SIZE); memset(savebuffer, 0, STATE_SIZE);
@ -270,7 +276,7 @@ int ManageSRAM (u8 direction, u8 device)
/* Memory CARD support */ /* Memory CARD support */
char action[80]; char action[80];
int CardError; int CardError;
unsigned int SectorSize; unsigned int SectorSize = 0;
int blocks; int blocks;
char comment[2][32] = { {"Genesis Plus 1.2a"}, {"SRAM Save"} }; char comment[2][32] = { {"Genesis Plus 1.2a"}, {"SRAM Save"} };
int outbytes = 0; int outbytes = 0;
@ -311,12 +317,16 @@ int ManageSRAM (u8 direction, u8 device)
/*** Retrieve the sector size ***/ /*** Retrieve the sector size ***/
CardError = CARD_GetSectorSize (CARDSLOT, &SectorSize); CardError = CARD_GetSectorSize (CARDSLOT, &SectorSize);
if (SectorSize)
{
switch (direction) switch (direction)
{ {
case 0: /*** Saving ***/ case 0: /*** Saving ***/
/*** Determine number of blocks on this card ***/ /*** Determine number of blocks on this card ***/
blocks = (outbytes / SectorSize) * SectorSize; blocks = (outbytes / SectorSize) * SectorSize;
if (outbytes % SectorSize) blocks += SectorSize; if (outbytes % SectorSize)
blocks += SectorSize;
/*** Check if a previous save exists ***/ /*** Check if a previous save exists ***/
if (CardFileExists (filename,CARDSLOT)) if (CardFileExists (filename,CARDSLOT))
@ -382,11 +392,12 @@ int ManageSRAM (u8 direction, u8 device)
CARD_Close (&CardFile); CARD_Close (&CardFile);
CARD_Unmount (CARDSLOT); CARD_Unmount (CARDSLOT);
sram.crc = crc32 (0, &sram.sram[0], 0x10000); sram.crc = crc32 (0, &sram.sram[0], 0x10000);
sprintf (action, "Saved %d bytes successfully", blocks); GUI_MsgBoxClose();
GUI_WaitPrompt("Information",action);
return 1; return 1;
default: /*** Loading ***/ default: /*** Loading ***/
if (!CardFileExists (filename,CARDSLOT)) if (!CardFileExists (filename,CARDSLOT))
{ {
GUI_WaitPrompt("Error","File does not exist !"); GUI_WaitPrompt("Error","File does not exist !");
@ -405,12 +416,13 @@ int ManageSRAM (u8 direction, u8 device)
} }
blocks = CardFile.len; blocks = CardFile.len;
if (blocks < SectorSize) blocks = SectorSize; if (blocks < SectorSize)
if (blocks % SectorSize) blocks++; blocks = SectorSize;
if (blocks % SectorSize)
blocks++;
/*** Just read the file back in ***/ /*** Just read the file back in ***/
sbo = 0; sbo = 0;
int size = blocks;
while (blocks > 0) while (blocks > 0)
{ {
CARD_Read (&CardFile, &savebuffer[sbo], SectorSize, sbo); CARD_Read (&CardFile, &savebuffer[sbo], SectorSize, sbo);
@ -425,14 +437,15 @@ int ManageSRAM (u8 direction, u8 device)
outzipped = 0x10000; outzipped = 0x10000;
uncompress ((Bytef *) &sram.sram, &outzipped, (Bytef *) &savebuffer[2112+sizeof(inzipped)], inzipped); uncompress ((Bytef *) &sram.sram, &outzipped, (Bytef *) &savebuffer[2112+sizeof(inzipped)], inzipped);
sram.crc = crc32 (0, &sram.sram[0], 0x10000); sram.crc = crc32 (0, &sram.sram[0], 0x10000);
GUI_MsgBoxClose();
/*** Inform user ***/
sprintf (action, "Loaded %d bytes successfully", size);
GUI_WaitPrompt("Information",action);
return 1; return 1;
} }
} }
GUI_WaitPrompt("Error","Invalid sector size");
return 0;
}
GUI_WaitPrompt("Error","Unable to mount memory card"); GUI_WaitPrompt("Error","Unable to mount memory card");
return 0; return 0;
} }
@ -447,12 +460,15 @@ int ManageSRAM (u8 direction, u8 device)
****************************************************************************/ ****************************************************************************/
int ManageState (u8 direction, u8 device) int ManageState (u8 direction, u8 device)
{ {
if (!cart.romsize) return 0; if (!cart.romsize)
return 0;
char filename[MAXJOLIET]; char filename[MAXJOLIET];
if (direction) GUI_MsgBoxOpen("Information","Loading State ...",1); if (direction)
else GUI_MsgBoxOpen("Information","Saving State ...",1); GUI_MsgBoxOpen("Information","Loading State ...",1);
else
GUI_MsgBoxOpen("Information","Saving State ...",1);
/* clean buffer */ /* clean buffer */
memset(savebuffer, 0, STATE_SIZE); memset(savebuffer, 0, STATE_SIZE);
@ -504,12 +520,15 @@ int ManageState (u8 direction, u8 device)
/*** Retrieve the sector size ***/ /*** Retrieve the sector size ***/
CardError = CARD_GetSectorSize (CARDSLOT, &SectorSize); CardError = CARD_GetSectorSize (CARDSLOT, &SectorSize);
if (SectorSize)
{
switch (direction) switch (direction)
{ {
case 0: /*** Saving ***/ case 0: /*** Saving ***/
/*** Determine number of blocks on this card ***/ /*** Determine number of blocks on this card ***/
blocks = (outbytes / SectorSize) * SectorSize; blocks = (outbytes / SectorSize) * SectorSize;
if (outbytes % SectorSize) blocks += SectorSize; if (outbytes % SectorSize)
blocks += SectorSize;
/*** Check if a previous save exists ***/ /*** Check if a previous save exists ***/
if (CardFileExists (filename, CARDSLOT)) if (CardFileExists (filename, CARDSLOT))
@ -574,11 +593,12 @@ int ManageState (u8 direction, u8 device)
CARD_Close (&CardFile); CARD_Close (&CardFile);
CARD_Unmount (CARDSLOT); CARD_Unmount (CARDSLOT);
sprintf (action, "Saved %d bytes successfully", blocks); GUI_MsgBoxClose();
GUI_WaitPrompt("Information",action);
return 1; return 1;
default: /*** Loading ***/ default: /*** Loading ***/
if (!CardFileExists (filename, CARDSLOT)) if (!CardFileExists (filename, CARDSLOT))
{ {
GUI_WaitPrompt("Error","File does not exist !"); GUI_WaitPrompt("Error","File does not exist !");
@ -597,12 +617,13 @@ int ManageState (u8 direction, u8 device)
} }
blocks = CardFile.len; blocks = CardFile.len;
if (blocks < SectorSize) blocks = SectorSize; if (blocks < SectorSize)
if (blocks % SectorSize) blocks++; blocks = SectorSize;
if (blocks % SectorSize)
blocks++;
/*** Just read the file back in ***/ /*** Just read the file back in ***/
sbo = 0; sbo = 0;
int size = blocks;
while (blocks > 0) while (blocks > 0)
{ {
CARD_Read (&CardFile, &savebuffer[sbo], SectorSize, sbo); CARD_Read (&CardFile, &savebuffer[sbo], SectorSize, sbo);
@ -611,17 +632,18 @@ int ManageState (u8 direction, u8 device)
} }
CARD_Close (&CardFile); CARD_Close (&CardFile);
CARD_Unmount (CARDSLOT); CARD_Unmount (CARDSLOT);
GUI_MsgBoxClose();
/*** Load State ***/ /*** Load State ***/
state_load(&savebuffer[2112]); state_load(&savebuffer[2112]);
/*** Inform user ***/
sprintf (action, "Loaded %d bytes successfully", size);
GUI_WaitPrompt("Information",action);
return 1; return 1;
} }
} }
GUI_WaitPrompt("Error","Invalid sector size");
return 0;
}
GUI_WaitPrompt("Error","Unable to mount memory card !"); GUI_WaitPrompt("Error","Unable to mount memory card !");
return 0; return 0;
} }

View File

@ -2286,12 +2286,10 @@ static int loadsavemenu (int which)
case 1: case 1:
case 2: case 2:
SILENT = 1;
if (which == 1) if (which == 1)
quit = ManageState(ret-1,device); quit = ManageState(ret-1,device);
else if (which == 0) else if (which == 0)
quit = ManageSRAM(ret-1,device); quit = ManageSRAM(ret-1,device);
SILENT = 0;
if (quit) if (quit)
return 1; return 1;
break; break;

View File

@ -963,14 +963,11 @@ gx_texture *gxTextureOpenPNG(const u8 *png_data, FILE *png_file)
return NULL; return NULL;
} }
if (!png_sig_cmp (magic, 0, 8)) if (png_sig_cmp (magic, 0, 8))
{
if (fread (magic, 1, 8, png_file) != 8)
{ {
png_destroy_read_struct(&png_ptr,&info_ptr,NULL); png_destroy_read_struct(&png_ptr,&info_ptr,NULL);
return NULL; return NULL;
} }
}
/* set IO callback for read function */ /* set IO callback for read function */
png_init_io (png_ptr, png_file); png_init_io (png_ptr, png_file);