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

View File

@ -51,6 +51,52 @@ bool fat_is_mounted(PARTITION_INTERFACE partition) {
return false; 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 * fat_enable_readahead_all
****************************************************************************/ ****************************************************************************/
@ -160,10 +206,7 @@ int updateFATdirname(int method)
sprintf(temp, "/%s/..", GCSettings.LoadFolder); sprintf(temp, "/%s/..", GCSettings.LoadFolder);
if (strcmp(currFATdir, temp) == 0) if (strcmp(currFATdir, temp) == 0)
{ {
if(method == METHOD_SD) sprintf(currFATdir,"%s",ROOTFATDIR);
sprintf(currFATdir,"%s",ROOTSDDIR);
else
sprintf(currFATdir,"%s",ROOTUSBDIR);
} }
/* update current directory name */ /* update current directory name */
@ -200,10 +243,7 @@ int parseFATdirectory(int method)
WaitPrompt(msg); WaitPrompt(msg);
// if we can't open the previous dir, open root dir // if we can't open the previous dir, open root dir
if(method == METHOD_SD) sprintf(currFATdir,"%s",ROOTFATDIR);
sprintf(currFATdir,"%s",ROOTSDDIR);
else
sprintf(currFATdir,"%s",ROOTUSBDIR);
fatdir = diropen(currFATdir); fatdir = diropen(currFATdir);

View File

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

View File

@ -13,7 +13,6 @@
#include <string.h> #include <string.h>
#include <wiiuse/wpad.h> #include <wiiuse/wpad.h>
#include <fat.h>
#include <sys/dir.h> #include <sys/dir.h>
#include "snes9x.h" #include "snes9x.h"
#include "memmap.h" #include "memmap.h"
@ -51,67 +50,43 @@ extern int screenheight;
extern FILEENTRIES filelist[MAXFILES]; extern FILEENTRIES filelist[MAXFILES];
/**************************************************************************** /****************************************************************************
* Auto-determines the load method * autoLoadMethod()
* THIS CODE STILL NEEDS WORK * Auto-determines and sets the load method
* Returns method set
****************************************************************************/ ****************************************************************************/
int autoLoadMethod() int autoLoadMethod()
{ {
if(changeFATInterface(METHOD_SD))
return 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 * autoSaveMethod()
* THIS CODE STILL NEEDS WORK * Auto-determines and sets the save method
* Returns method set
****************************************************************************/ ****************************************************************************/
int autoSaveMethod() int autoSaveMethod()
{ {
if(changeFATInterface(METHOD_SD))
return METHOD_SD; return METHOD_SD;
int method = -1; else if(changeFATInterface(METHOD_USB))
return METHOD_USB;
while(method < 0) 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"); WaitPrompt((char*) "Unable to auto-determine save method!");
return 0; // no method found
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;
}
return method;
} }
/**************************************************************************** /****************************************************************************
@ -534,10 +509,8 @@ OpenFAT (int method)
havedir = 0; // gamecube only havedir = 0; // gamecube only
/* change current dir to snes roms directory */ /* change current dir to snes roms directory */
if(method == METHOD_SD) changeFATInterface(GCSettings.LoadMethod);
sprintf ( currFATdir, "%s/%s", ROOTSDDIR, GCSettings.LoadFolder ); sprintf ( currFATdir, "%s/%s", ROOTFATDIR, GCSettings.LoadFolder );
else
sprintf ( currFATdir, "%s/%s", ROOTUSBDIR, GCSettings.LoadFolder );
/* Parse initial root directory and get entries list */ /* Parse initial root directory and get entries list */
if ((maxfiles = parseFATdirectory (method))) if ((maxfiles = parseFATdirectory (method)))

View File

@ -80,6 +80,45 @@ CardFileExists (char *filename, int slot)
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;
}
}
/**************************************************************************** /****************************************************************************
* MountCard * MountCard
* *
@ -87,7 +126,7 @@ CardFileExists (char *filename, int slot)
* workarounds implemented for when the mount fails. * workarounds implemented for when the mount fails.
* Returns the result of the last attempted CARD_Mount command. * 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 ret;
int tries; 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 LoadBufferFromMC (unsigned char *buf, int slot, char *filename, bool8 silent);
int SaveBufferToMC (unsigned char *buf, int slot, char *filename, int datasize, 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 #endif

View File

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

View File

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

View File

@ -118,7 +118,6 @@ decodePrefsData ()
return false; return false;
} }
/**************************************************************************** /****************************************************************************
* Save Preferences * Save Preferences
****************************************************************************/ ****************************************************************************/
@ -140,10 +139,8 @@ SavePrefs (int method, bool silent)
if(method == METHOD_SD || method == METHOD_USB) if(method == METHOD_SD || method == METHOD_USB)
{ {
if(method == METHOD_SD) changeFATInterface(GCSettings.SaveMethod);
sprintf (filepath, "%s/%s/%s", ROOTSDDIR, GCSettings.SaveFolder, PREFS_FILE_NAME); sprintf (filepath, "%s/%s/%s", ROOTFATDIR, GCSettings.SaveFolder, PREFS_FILE_NAME);
else
sprintf (filepath, "%s/%s/%s", ROOTUSBDIR, GCSettings.SaveFolder, PREFS_FILE_NAME);
offset = SaveBufferToFAT (filepath, datasize, silent); offset = SaveBufferToFAT (filepath, datasize, silent);
} }
else if(method == METHOD_SMB) 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 || method == METHOD_USB)
{ {
if(method == METHOD_SD) changeFATInterface(GCSettings.SaveMethod);
sprintf (filepath, "%s/%s/%s", ROOTSDDIR, GCSettings.SaveFolder, PREFS_FILE_NAME); sprintf (filepath, "%s/%s/%s", ROOTFATDIR, GCSettings.SaveFolder, PREFS_FILE_NAME);
else
sprintf (filepath, "%s/%s/%s", ROOTUSBDIR, GCSettings.SaveFolder, PREFS_FILE_NAME);
offset = LoadBufferFromFAT (filepath, silent); offset = LoadBufferFromFAT (filepath, silent);
} }
else if(method == METHOD_SMB) else if(method == METHOD_SMB)

View File

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

View File

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