fixed memory card support

This commit is contained in:
ekeeke31 2010-05-07 08:19:32 +00:00
parent 44073ca30e
commit a6fdb00469
2 changed files with 16 additions and 46 deletions

View File

@ -54,7 +54,6 @@ static u8 savebuffer[STATE_SIZE] ATTRIBUTE_ALIGN (32);
static int CardMount(int slot) static int CardMount(int slot)
{ {
int tries = 0; int tries = 0;
int CardError;
#if defined(HW_DOL) #if defined(HW_DOL)
*(unsigned long *) (0xCC006800) |= 1 << 13; /*** Disable Encryption ***/ *(unsigned long *) (0xCC006800) |= 1 << 13; /*** Disable Encryption ***/
uselessinquiry (); uselessinquiry ();
@ -64,8 +63,7 @@ static int CardMount(int slot)
while (tries < 10) while (tries < 10)
{ {
VIDEO_WaitVSync (); VIDEO_WaitVSync ();
CardError = CARD_Mount (slot, SysArea, NULL); /*** Don't need or want a callback ***/ if (CARD_Mount(slot, SysArea, NULL) == CARD_ERROR_READY)
if (CardError == 0)
return 1; return 1;
else else
EXI_ProbeReset (); EXI_ProbeReset ();
@ -74,24 +72,6 @@ static int CardMount(int slot)
return 0; return 0;
} }
/****************************************************************************
* CardFileExists
*
* Wrapper to search through the files on the card.
****************************************************************************/
static int CardFileExists (char *filename, int slot)
{
card_dir CardDir;
int CardError = CARD_FindFirst (slot, &CardDir, TRUE);
while (CardError >= 0)
{
CardError = CARD_FindNext (&CardDir);
if (strcmp ((char *) CardDir.filename, filename) == 0)
return 1;
}
return 0;
}
/**************************************************************************** /****************************************************************************
* Slot Management * Slot Management
* *
@ -130,7 +110,7 @@ void slot_autodetect(int slot, int device, t_slot *ptr)
char filename[MAXPATHLEN]; char filename[MAXPATHLEN];
memset(ptr,0,sizeof(t_slot)); memset(ptr,0,sizeof(t_slot));
if (device == 0) if (!device)
{ {
/* FAT support */ /* FAT support */
if (slot > 0) if (slot > 0)
@ -175,7 +155,7 @@ void slot_autodetect(int slot, int device, t_slot *ptr)
{ {
/* Open file */ /* Open file */
card_file CardFile; card_file CardFile;
if (CARD_Open(device, filename, &CardFile)) if (CARD_Open(device, filename, &CardFile) == CARD_ERROR_READY)
{ {
/* Retrieve date & close */ /* Retrieve date & close */
card_stat CardStatus; card_stat CardStatus;
@ -200,7 +180,7 @@ int slot_delete(int slot, int device)
char filename[MAXPATHLEN]; char filename[MAXPATHLEN];
int ret = 0; int ret = 0;
if (device == 0) if (!device)
{ {
/* FAT support */ /* FAT support */
if (slot > 0) if (slot > 0)
@ -235,8 +215,7 @@ int slot_delete(int slot, int device)
/* Mount CARD */ /* Mount CARD */
if (CardMount(device)) if (CardMount(device))
{ {
/* Open file */ /* Delete file */
if (CardFileExists(filename, device))
ret = CARD_Delete(device,filename); ret = CARD_Delete(device,filename);
CARD_Unmount(device); CARD_Unmount(device);
} }
@ -259,7 +238,7 @@ int slot_load(int slot, int device)
/* clean buffer */ /* clean buffer */
memset(savebuffer, 0, STATE_SIZE); memset(savebuffer, 0, STATE_SIZE);
if (device == 0) if (!device)
{ {
/* FAT support */ /* FAT support */
if (slot > 0) if (slot > 0)
@ -298,7 +277,7 @@ int slot_load(int slot, int device)
else else
{ {
/* Memory Card support */ /* Memory Card support */
if (index > 0) if (slot > 0)
sprintf(filename, "MD-%04X.gp%d", realchecksum, slot - 1); sprintf(filename, "MD-%04X.gp%d", realchecksum, slot - 1);
else else
sprintf(filename, "MD-%04X.srm", realchecksum); sprintf(filename, "MD-%04X.srm", realchecksum);
@ -317,7 +296,7 @@ int slot_load(int slot, int device)
/* Retrieve the sector size */ /* Retrieve the sector size */
u32 SectorSize = 0; u32 SectorSize = 0;
int CardError = CARD_GetSectorSize(device, &SectorSize); int CardError = CARD_GetSectorSize(device, &SectorSize);
if (SectorSize) if (SectorSize > 0)
{ {
/* Open file */ /* Open file */
card_file CardFile; card_file CardFile;
@ -404,7 +383,7 @@ int slot_save(int slot, int device)
filesize = 0x10000; filesize = 0x10000;
} }
if (device == 0) if (!device)
{ {
/* FAT support */ /* FAT support */
if (slot > 0) if (slot > 0)
@ -445,7 +424,7 @@ int slot_save(int slot, int device)
else else
{ {
/* Memory Card support */ /* Memory Card support */
if (index > 0) if (slot > 0)
sprintf(filename, "MD-%04X.gp%d", realchecksum, slot - 1); sprintf(filename, "MD-%04X.gp%d", realchecksum, slot - 1);
else else
sprintf(filename, "MD-%04X.srm", realchecksum); sprintf(filename, "MD-%04X.srm", realchecksum);
@ -479,17 +458,8 @@ int slot_save(int slot, int device)
/* Check if file already exists */ /* Check if file already exists */
card_file CardFile; card_file CardFile;
if (CardFileExists(filename,device)) if (CARD_Open(device, filename, &CardFile) == CARD_ERROR_READY)
{ {
CardError = CARD_Open(device, filename, &CardFile);
if (CardError)
{
sprintf(action, "Unable to open file (%d)", CardError);
GUI_WaitPrompt("Error",action);
CARD_Unmount(device);
return 0;
}
int size = filesize - CardFile.len; int size = filesize - CardFile.len;
CARD_Close(&CardFile); CARD_Close(&CardFile);
memset(&CardFile,0,sizeof(CardFile)); memset(&CardFile,0,sizeof(CardFile));
@ -499,14 +469,14 @@ int slot_save(int slot, int device)
CardError = CARD_Create(device, "TEMP", size, &CardFile); CardError = CARD_Create(device, "TEMP", size, &CardFile);
if (CardError) if (CardError)
{ {
sprintf(action, "Unable to create temporary file (%d)", CardError); sprintf(action, "Not enough memory space left (%d)", CardError);
GUI_WaitPrompt("Error",action); GUI_WaitPrompt("Error",action);
CARD_Unmount(device); CARD_Unmount(device);
return 0; return 0;
} }
CARD_Close(&CardFile); CARD_Close(&CardFile);
CARD_Delete(device, "TEMP");
memset(&CardFile,0,sizeof(CardFile)); memset(&CardFile,0,sizeof(CardFile));
CARD_Delete(device, "TEMP");
} }
/* delete previously existing slot */ /* delete previously existing slot */

View File

@ -2327,7 +2327,7 @@ static int savemenu(void)
bg_saves[1].state |= IMAGE_VISIBLE; bg_saves[1].state |= IMAGE_VISIBLE;
/* state slot */ /* state slot */
if (slot && slots[slot].valid) if (!config.s_device && slot && slots[slot].valid)
{ {
/* open screenshot file */ /* open screenshot file */
sprintf (filename, "%s/saves/%s__%d.png", DEFAULT_PATH, rom_filename, slot - 1); sprintf (filename, "%s/saves/%s__%d.png", DEFAULT_PATH, rom_filename, slot - 1);