-add functions to auto-determine load/save device

-libfat cleanup, add sd gecko support
-tweak to mouse code
This commit is contained in:
dborth 2008-08-08 07:57:01 +00:00
parent c3bead1447
commit 09cb10dfb6
11 changed files with 188 additions and 149 deletions

View File

@ -30,10 +30,11 @@ SetupCheats()
char cheatFile[150] = { '\0' };
if(GCSettings.SaveMethod == METHOD_SD)
sprintf (cheatFile, "%s/snes9x/cheats/%s.cht", ROOTSDDIR, Memory.ROMFilename);
else if(GCSettings.SaveMethod == METHOD_USB)
sprintf (cheatFile, "%s/snes9x/cheats/%s.cht", ROOTUSBDIR, Memory.ROMFilename);
if(GCSettings.SaveMethod == METHOD_SD || GCSettings.SaveMethod == METHOD_USB)
{
changeFATInterface(GCSettings.SaveMethod);
sprintf (cheatFile, "%s/snes9x/cheats/%s.cht", ROOTFATDIR, Memory.ROMFilename);
}
// load cheat file if present
if(strlen(cheatFile) > 0)

View File

@ -51,6 +51,52 @@ bool fat_is_mounted(PARTITION_INTERFACE partition) {
return false;
}
/****************************************************************************
* changeFATInterface
* Checks if the device (method) specified is available, and
* sets libfat to use the device
****************************************************************************/
bool changeFATInterface(int method)
{
bool devFound = false;
if(method == METHOD_SD)
{
// check which SD device is loaded
#ifdef HW_RVL
if (fat_is_mounted(PI_INTERNAL_SD))
{
devFound = true;
fatSetDefaultInterface(PI_INTERNAL_SD);
}
#endif
if (!devFound && fat_is_mounted(PI_SDGECKO_A))
{
devFound = true;
fatSetDefaultInterface(PI_SDGECKO_A);
}
if(!devFound && fat_is_mounted(PI_SDGECKO_B))
{
devFound = true;
fatSetDefaultInterface(PI_SDGECKO_B);
}
}
else if(method == METHOD_USB)
{
#ifdef HW_RVL
if(fat_is_mounted(PI_USBSTORAGE))
{
devFound = true;
fatSetDefaultInterface(PI_USBSTORAGE);
}
#endif
}
return devFound;
}
/****************************************************************************
* fat_enable_readahead_all
****************************************************************************/
@ -160,10 +206,7 @@ int updateFATdirname(int method)
sprintf(temp, "/%s/..", GCSettings.LoadFolder);
if (strcmp(currFATdir, temp) == 0)
{
if(method == METHOD_SD)
sprintf(currFATdir,"%s",ROOTSDDIR);
else
sprintf(currFATdir,"%s",ROOTUSBDIR);
sprintf(currFATdir,"%s",ROOTFATDIR);
}
/* update current directory name */
@ -200,10 +243,7 @@ int parseFATdirectory(int method)
WaitPrompt(msg);
// if we can't open the previous dir, open root dir
if(method == METHOD_SD)
sprintf(currFATdir,"%s",ROOTSDDIR);
else
sprintf(currFATdir,"%s",ROOTUSBDIR);
sprintf(currFATdir,"%s",ROOTFATDIR);
fatdir = diropen(currFATdir);

View File

@ -21,10 +21,11 @@
#include <sys/stat.h>
#include <unistd.h>
#define ROOTSDDIR "fat3:/"
#define ROOTUSBDIR "fat4:/"
#define ROOTFATDIR "fat:/"
bool fat_remount(PARTITION_INTERFACE partition);
bool fat_is_mounted(PARTITION_INTERFACE partition);
bool changeFATInterface(int method);
static int FileSortCallback(const void *f1, const void *f2);
int updateFATdirname(int method);
int parseFATdirectory(int method);

View File

@ -13,7 +13,6 @@
#include <string.h>
#include <wiiuse/wpad.h>
#include <fat.h>
#include <sys/dir.h>
#include "snes9x.h"
#include "memmap.h"
@ -51,67 +50,43 @@ extern int screenheight;
extern FILEENTRIES filelist[MAXFILES];
/****************************************************************************
* Auto-determines the load method
* THIS CODE STILL NEEDS WORK
* autoLoadMethod()
* Auto-determines and sets the load method
* Returns method set
****************************************************************************/
int autoLoadMethod()
{
return METHOD_SD;
if(changeFATInterface(METHOD_SD))
return METHOD_SD;
else if(changeFATInterface(METHOD_USB))
return METHOD_USB;
else
{
WaitPrompt((char*) "Unable to auto-determine load method!");
return 0; // no method found
}
}
/****************************************************************************
* Auto-determines the save method
* THIS CODE STILL NEEDS WORK
* autoSaveMethod()
* Auto-determines and sets the save method
* Returns method set
****************************************************************************/
int autoSaveMethod()
{
return METHOD_SD;
int method = -1;
while(method < 0)
if(changeFATInterface(METHOD_SD))
return METHOD_SD;
else if(changeFATInterface(METHOD_USB))
return METHOD_USB;
else if(TestCard(CARD_SLOTA, NOTSILENT))
return METHOD_MC_SLOTA;
else if(TestCard(CARD_SLOTB, NOTSILENT))
return METHOD_MC_SLOTB;
else
{
WaitPrompt((char*) "Checking SD");
if(diropen(ROOTSDDIR))
{
WaitPrompt((char*) "Found SD!");
method = METHOD_SD;
break;
}
WaitPrompt((char*) "Checking USB");
if(diropen(ROOTUSBDIR))
{
WaitPrompt((char*) "Found USB!");
method = METHOD_USB;
break;
}
WaitPrompt((char*) "Checking Slot A");
// check Memory Card Slot A
if(MountCard(CARD_SLOTA, SILENT) == 0)
{
WaitPrompt((char*) "Found Memory Card A!");
method = METHOD_MC_SLOTA;
break;
}
WaitPrompt((char*) "Checking Slot B");
// check Memory Card Slot B
if(MountCard(CARD_SLOTB, SILENT) == 0)
{
WaitPrompt((char*) "Found Memory Card B!");
method = METHOD_MC_SLOTB;
break;
}
// no method found
WaitPrompt((char*) "Error: Could not determine save method.");
method = 0;
WaitPrompt((char*) "Unable to auto-determine save method!");
return 0; // no method found
}
return method;
}
/****************************************************************************
@ -534,10 +509,8 @@ OpenFAT (int method)
havedir = 0; // gamecube only
/* change current dir to snes roms directory */
if(method == METHOD_SD)
sprintf ( currFATdir, "%s/%s", ROOTSDDIR, GCSettings.LoadFolder );
else
sprintf ( currFATdir, "%s/%s", ROOTUSBDIR, GCSettings.LoadFolder );
changeFATInterface(GCSettings.LoadMethod);
sprintf ( currFATdir, "%s/%s", ROOTFATDIR, GCSettings.LoadFolder );
/* Parse initial root directory and get entries list */
if ((maxfiles = parseFATdirectory (method)))

View File

@ -66,18 +66,57 @@ ClearSaveBuffer ()
int
CardFileExists (char *filename, int slot)
{
int CardError;
int CardError;
CardError = CARD_FindFirst (slot, &CardDir, TRUE);
while (CardError != CARD_ERROR_NOFILE)
{
CardError = CARD_FindNext (&CardDir);
CardError = CARD_FindFirst (slot, &CardDir, TRUE);
while (CardError != CARD_ERROR_NOFILE)
{
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;
}
/****************************************************************************
* TestCard
*
* Checks to see if a card is in the card slot specified
****************************************************************************/
bool TestCard(int slot, bool silent)
{
/*** Initialize Card System ***/
memset (SysArea, 0, CARD_WORKAREA);
CARD_Init ("SNES", "00");
/*** Try to mount the card ***/
if (MountCard(slot, silent) == 0)
{
// Mount successful!
if(!silent)
{
if (slot == CARD_SLOTA)
WaitPrompt((char*) "Mounted Slot A Memory Card!");
else
WaitPrompt((char*) "Mounted Slot B Memory Card!");
}
CARD_Unmount (slot);
return true;
}
else
{
if(!silent)
{
if (slot == CARD_SLOTA)
WaitPrompt((char*) "Unable to Mount Slot A Memory Card!");
else
WaitPrompt((char*) "Unable to Mount Slot B Memory Card!");
}
return false;
}
}
/****************************************************************************
@ -87,7 +126,7 @@ CardFileExists (char *filename, int slot)
* workarounds implemented for when the mount fails.
* Returns the result of the last attempted CARD_Mount command.
****************************************************************************/
int MountCard(int cslot, bool8 silent)
int MountCard(int cslot, bool silent)
{
int ret;
int tries;

View File

@ -21,6 +21,7 @@ int VerifyMCFile (unsigned char *buf, int slot, char *filename, int datasize);
int LoadBufferFromMC (unsigned char *buf, int slot, char *filename, bool8 silent);
int SaveBufferToMC (unsigned char *buf, int slot, char *filename, int datasize, bool8 silent);
int MountCard(int cslot, bool8 silent);
int MountCard(int cslot, bool silent);
bool TestCard(int slot, bool silent);
#endif

View File

@ -145,13 +145,10 @@ NGCFreezeGame (int method, bool8 silent)
int offset = 0;
char msg[100];
if (method == METHOD_SD) // SD
if (method == METHOD_SD || method == METHOD_USB) // SD
{
sprintf (filename, "%s/%s/%s.frz", ROOTSDDIR, GCSettings.SaveFolder, Memory.ROMFilename);
}
if (method == METHOD_USB) // USB
{
sprintf (filename, "%s/%s/%s.frz", ROOTUSBDIR, GCSettings.SaveFolder, Memory.ROMFilename);
changeFATInterface(GCSettings.SaveMethod);
sprintf (filename, "%s/%s/%s.frz", ROOTFATDIR, GCSettings.SaveFolder, Memory.ROMFilename);
}
else if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) // MC Slot A or B
{
@ -192,14 +189,12 @@ NGCFreezeGame (int method, bool8 silent)
}
else
{
if(method == METHOD_SD)
sprintf(msg, "Couldn't save to %s/%s/", ROOTSDDIR, GCSettings.SaveFolder);
else
sprintf(msg, "Couldn't save to %s/%s/", ROOTUSBDIR, GCSettings.SaveFolder);
changeFATInterface(GCSettings.SaveMethod);
sprintf(msg, "Couldn't save to %s/%s/", ROOTFATDIR, GCSettings.SaveFolder);
WaitPrompt (msg);
}
}
else if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTA) // MC Slot A or B
else if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) // MC Slot A or B
{
if (!silent)
ShowAction ((char*) "Saving freeze game...");
@ -353,10 +348,8 @@ NGCUnfreezeGame (int method, bool8 silent)
if (method == METHOD_SD || method == METHOD_USB) // SD & USB
{
if(method == METHOD_SD)
sprintf (filename, "%s/%s/%s.frz", ROOTSDDIR, GCSettings.SaveFolder, Memory.ROMFilename);
else
sprintf (filename, "%s/%s/%s.frz", ROOTUSBDIR, GCSettings.SaveFolder, Memory.ROMFilename);
changeFATInterface(GCSettings.SaveMethod);
sprintf (filename, "%s/%s/%s.frz", ROOTFATDIR, GCSettings.SaveFolder, Memory.ROMFilename);
handle = fopen (filename, "rb");

View File

@ -617,7 +617,7 @@ ConfigureButtons (u16 ctrlr_type)
menu = oldmenu;
} // end configurebuttons()
int ctlrmenucount = 9;
int ctlrmenucount = 10;
char ctlrmenu[][50] = {
// toggle:
"MultiTap",
@ -807,7 +807,6 @@ mainmenu (int selectedMenu)
quit = 1;
break;
}
}
/*** Remove any still held buttons ***/

View File

@ -45,40 +45,40 @@ char prefscomment[2][32] = { {PREFSVERSTRING}, {"Preferences"} };
int
preparePrefsData ()
{
int offset = sizeof (saveicon);
int size;
int offset = sizeof (saveicon);
int size;
memset (savebuffer, 0, SAVEBUFFERSIZE);
memset (savebuffer, 0, SAVEBUFFERSIZE);
/*** Copy in save icon ***/
memcpy (savebuffer, saveicon, offset);
memcpy (savebuffer, saveicon, offset);
/*** And the prefscomments ***/
memcpy (savebuffer + offset, prefscomment, 64);
offset += 64;
memcpy (savebuffer + offset, prefscomment, 64);
offset += 64;
/*** Save all settings ***/
size = sizeof (Settings);
memcpy (savebuffer + offset, &Settings, size);
offset += size;
/*** Save all settings ***/
size = sizeof (Settings);
memcpy (savebuffer + offset, &Settings, size);
offset += size;
/*** Save GC specific settings ***/
size = sizeof (GCSettings);
memcpy (savebuffer + offset, &GCSettings, size);
offset += size;
/*** Save GC specific settings ***/
size = sizeof (GCSettings);
memcpy (savebuffer + offset, &GCSettings, size);
offset += size;
/*** Save buttonmaps ***/
size = sizeof (unsigned int) *12; // this size applies to all padmaps
memcpy (savebuffer + offset, &gcpadmap, size);
offset += size;
memcpy (savebuffer + offset, &wmpadmap, size);
offset += size;
memcpy (savebuffer + offset, &ccpadmap, size);
offset += size;
memcpy (savebuffer + offset, &ncpadmap, size);
offset += size;
/*** Save buttonmaps ***/
size = sizeof (unsigned int) *12; // this size applies to all padmaps
memcpy (savebuffer + offset, &gcpadmap, size);
offset += size;
memcpy (savebuffer + offset, &wmpadmap, size);
offset += size;
memcpy (savebuffer + offset, &ccpadmap, size);
offset += size;
memcpy (savebuffer + offset, &ncpadmap, size);
offset += size;
return offset;
return offset;
}
@ -118,7 +118,6 @@ decodePrefsData ()
return false;
}
/****************************************************************************
* Save Preferences
****************************************************************************/
@ -140,10 +139,8 @@ SavePrefs (int method, bool silent)
if(method == METHOD_SD || method == METHOD_USB)
{
if(method == METHOD_SD)
sprintf (filepath, "%s/%s/%s", ROOTSDDIR, GCSettings.SaveFolder, PREFS_FILE_NAME);
else
sprintf (filepath, "%s/%s/%s", ROOTUSBDIR, GCSettings.SaveFolder, PREFS_FILE_NAME);
changeFATInterface(GCSettings.SaveMethod);
sprintf (filepath, "%s/%s/%s", ROOTFATDIR, GCSettings.SaveFolder, PREFS_FILE_NAME);
offset = SaveBufferToFAT (filepath, datasize, silent);
}
else if(method == METHOD_SMB)
@ -190,10 +187,8 @@ LoadPrefs (int method, bool silent)
if(method == METHOD_SD || method == METHOD_USB)
{
if(method == METHOD_SD)
sprintf (filepath, "%s/%s/%s", ROOTSDDIR, GCSettings.SaveFolder, PREFS_FILE_NAME);
else
sprintf (filepath, "%s/%s/%s", ROOTUSBDIR, GCSettings.SaveFolder, PREFS_FILE_NAME);
changeFATInterface(GCSettings.SaveMethod);
sprintf (filepath, "%s/%s/%s", ROOTFATDIR, GCSettings.SaveFolder, PREFS_FILE_NAME);
offset = LoadBufferFromFAT (filepath, silent);
}
else if(method == METHOD_SMB)

View File

@ -646,7 +646,6 @@ void SetControllers ()
{
if (Settings.MultiPlayer5Master == true)
{
S9xSetController (0, CTL_JOYPAD, 0, 0, 0, 0);
S9xSetController (1, CTL_MP5, 1, 2, 3, -1);
}
@ -657,8 +656,9 @@ void SetControllers ()
}
else if (Settings.MouseMaster == true)
{
S9xSetController (0, CTL_JOYPAD, 0, 0, 0, 0);
S9xSetController (1, CTL_MOUSE, (GCSettings.Mouse == 2), 0, 0, 0);
// some games (eg: Mario Paint) don't allow the mouse in port 2
S9xSetController (0, CTL_MOUSE, (GCSettings.Mouse == 2), 0, 0, 0);
S9xSetController (1, CTL_JOYPAD, 1, 0, 0, 0);
}
else if (Settings.JustifierMaster == true)
{
@ -835,7 +835,9 @@ main ()
/*** Initialize libFAT for SD and USB ***/
fatInitDefault();
//fatInit(8192, false);
#ifdef HW_RVL
//fat_enable_readahead_all();
#endif
/*** Initialize DVD subsystem ***/
DVD_Init ();

View File

@ -250,11 +250,8 @@ LoadSRAM (int method, bool silent)
if(method == METHOD_SD || method == METHOD_USB)
{
if(method == METHOD_SD)
sprintf (filepath, "%s/%s/%s.srm", ROOTSDDIR, GCSettings.SaveFolder, Memory.ROMFilename);
else
sprintf (filepath, "%s/%s/%s.srm", ROOTUSBDIR, GCSettings.SaveFolder, Memory.ROMFilename);
changeFATInterface(GCSettings.SaveMethod);
sprintf (filepath, "%s/%s/%s.srm", ROOTFATDIR, GCSettings.SaveFolder, Memory.ROMFilename);
offset = LoadBufferFromFAT (filepath, silent);
}
else if(method == METHOD_SMB)
@ -313,10 +310,8 @@ SaveSRAM (int method, bool silent)
{
if(method == METHOD_SD || method == METHOD_USB)
{
if(method == METHOD_SD)
sprintf (filepath, "%s/%s/%s.srm", ROOTSDDIR, GCSettings.SaveFolder, Memory.ROMFilename);
else
sprintf (filepath, "%s/%s/%s.srm", ROOTUSBDIR, GCSettings.SaveFolder, Memory.ROMFilename);
changeFATInterface(GCSettings.SaveMethod);
sprintf (filepath, "%s/%s/%s.srm", ROOTFATDIR, GCSettings.SaveFolder, Memory.ROMFilename);
offset = SaveBufferToFAT (filepath, datasize, silent);
}
else if(method == METHOD_SMB)