mirror of
https://github.com/dborth/snes9xgx.git
synced 2024-11-01 00:15:14 +01:00
add USB/SD hotswap!
This commit is contained in:
parent
fb54f957e1
commit
a594435e14
@ -31,77 +31,84 @@
|
||||
FILE * fatfile;
|
||||
|
||||
/****************************************************************************
|
||||
* fat_is_mounted
|
||||
* to check whether FAT media are detected.
|
||||
* MountFAT
|
||||
* Attempts to mount the FAT device specified
|
||||
* Sets libfat to use the device by default
|
||||
* Enables read-ahead cache for SD/USB
|
||||
***************************************************************************/
|
||||
bool MountFAT(PARTITION_INTERFACE part)
|
||||
{
|
||||
bool mounted = fatMountNormalInterface(part, 8);
|
||||
|
||||
bool FatIsMounted(PARTITION_INTERFACE partition) {
|
||||
char prefix[] = "fatX:/";
|
||||
prefix[3] = partition + '0';
|
||||
DIR_ITER *dir = diropen(prefix);
|
||||
if (dir) {
|
||||
dirclose(dir);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
if(mounted)
|
||||
{
|
||||
fatSetDefaultInterface(part);
|
||||
#ifdef HW_RVL
|
||||
if(part == PI_INTERNAL_SD || part == PI_USBSTORAGE)
|
||||
fatEnableReadAhead (part, 6, 64);
|
||||
#endif
|
||||
}
|
||||
return mounted;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* changeFATInterface
|
||||
* Checks if the device (method) specified is available, and
|
||||
* sets libfat to use the device
|
||||
* UnmountFAT
|
||||
* Unmounts the FAT device specified
|
||||
***************************************************************************/
|
||||
void UnmountFAT(PARTITION_INTERFACE part)
|
||||
{
|
||||
if(!fatUnmount(part))
|
||||
fatUnsafeUnmount(part);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* UnmountAllFAT
|
||||
* Unmounts all FAT devices
|
||||
***************************************************************************/
|
||||
void UnmountAllFAT()
|
||||
{
|
||||
#ifdef HW_RVL
|
||||
UnmountFAT(PI_INTERNAL_SD);
|
||||
UnmountFAT(PI_USBSTORAGE);
|
||||
#endif
|
||||
UnmountFAT(PI_SDGECKO_A);
|
||||
UnmountFAT(PI_SDGECKO_B);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* ChangeFATInterface
|
||||
* Unmounts all devices and attempts to mount/configure the device specified
|
||||
***************************************************************************/
|
||||
bool ChangeFATInterface(int method, bool silent)
|
||||
{
|
||||
bool devFound = false;
|
||||
bool mounted = false;
|
||||
|
||||
// unmount all FAT devices
|
||||
UnmountAllFAT();
|
||||
|
||||
if(method == METHOD_SD)
|
||||
{
|
||||
// check which SD device is loaded
|
||||
|
||||
#ifdef HW_RVL
|
||||
if (FatIsMounted(PI_INTERNAL_SD))
|
||||
{
|
||||
devFound = true;
|
||||
fatSetDefaultInterface(PI_INTERNAL_SD);
|
||||
fatEnableReadAhead (PI_INTERNAL_SD, 6, 64);
|
||||
}
|
||||
mounted = MountFAT(PI_INTERNAL_SD); // try Wii internal SD
|
||||
#endif
|
||||
|
||||
if (!devFound && FatIsMounted(PI_SDGECKO_A))
|
||||
{
|
||||
devFound = true;
|
||||
fatSetDefaultInterface(PI_SDGECKO_A);
|
||||
}
|
||||
if(!devFound && FatIsMounted(PI_SDGECKO_B))
|
||||
{
|
||||
devFound = true;
|
||||
fatSetDefaultInterface(PI_SDGECKO_B);
|
||||
}
|
||||
if(!devFound)
|
||||
{
|
||||
if(!silent)
|
||||
WaitPrompt ((char *)"SD card not found!");
|
||||
}
|
||||
if(!mounted) // internal SD not found
|
||||
mounted = MountFAT(PI_SDGECKO_A); // try SD Gecko on slot A
|
||||
if(!mounted) // internal SD and SD Gecko (on slot A) not found
|
||||
mounted = MountFAT(PI_SDGECKO_B); // try SD Gecko on slot B
|
||||
if(!mounted && !silent) // no SD device found
|
||||
WaitPrompt ((char *)"SD card not found!");
|
||||
}
|
||||
else if(method == METHOD_USB)
|
||||
{
|
||||
#ifdef HW_RVL
|
||||
if(FatIsMounted(PI_USBSTORAGE))
|
||||
{
|
||||
devFound = true;
|
||||
fatSetDefaultInterface(PI_USBSTORAGE);
|
||||
fatEnableReadAhead (PI_USBSTORAGE, 6, 64);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!silent)
|
||||
WaitPrompt ((char *)"USB flash drive not found!");
|
||||
}
|
||||
mounted = MountFAT(PI_USBSTORAGE);
|
||||
if(!mounted && !silent)
|
||||
WaitPrompt ((char *)"USB drive not found!");
|
||||
#endif
|
||||
}
|
||||
|
||||
return devFound;
|
||||
return mounted;
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
|
@ -429,7 +429,7 @@ int FileSelector (int method)
|
||||
|
||||
if (!maxfiles)
|
||||
{
|
||||
WaitPrompt ((char*) "Error reading directory !");
|
||||
WaitPrompt ((char*) "Error reading directory!");
|
||||
haverom = 1; // quit menu
|
||||
}
|
||||
}
|
||||
@ -440,6 +440,11 @@ int FileSelector (int method)
|
||||
}
|
||||
else // this is a file
|
||||
{
|
||||
// better do another unmount/remount, just in case
|
||||
if(method == METHOD_SD || method == METHOD_USB)
|
||||
if(!ChangeFATInterface(method, NOTSILENT))
|
||||
return 0;
|
||||
|
||||
// 7z file - let's open it up to select a file inside
|
||||
if(IsSz())
|
||||
{
|
||||
@ -447,7 +452,7 @@ int FileSelector (int method)
|
||||
if(!MakeROMPath(szpath, method))
|
||||
{
|
||||
WaitPrompt((char*) "Maximum filepath length reached!");
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
int szfiles = SzParse(szpath, method);
|
||||
if(szfiles)
|
||||
|
@ -69,8 +69,6 @@ extern int FrameTimer;
|
||||
extern long long prev;
|
||||
extern unsigned int timediffallowed;
|
||||
|
||||
extern void fat_enable_readahead_all();
|
||||
|
||||
/****************************************************************************
|
||||
* ipl_set_config
|
||||
* lowlevel Qoob Modchip disable
|
||||
|
Loading…
Reference in New Issue
Block a user