2008-08-06 03:09:59 +02:00
|
|
|
/****************************************************************************
|
2008-09-12 07:28:40 +02:00
|
|
|
* Snes9x 1.51 Nintendo Wii/Gamecube Port
|
2008-08-14 00:44:59 +02:00
|
|
|
*
|
2008-08-06 03:09:59 +02:00
|
|
|
* softdev July 2006
|
|
|
|
* svpe June 2007
|
|
|
|
* crunchy2 May-July 2007
|
2008-09-23 06:54:53 +02:00
|
|
|
* Michniewski 2008
|
2008-08-10 05:14:39 +02:00
|
|
|
* Tantric August 2008
|
|
|
|
*
|
|
|
|
* filesel.cpp
|
|
|
|
*
|
|
|
|
* Generic file routines - reading, writing, browsing
|
2008-09-12 07:28:40 +02:00
|
|
|
***************************************************************************/
|
|
|
|
|
2008-08-06 03:09:59 +02:00
|
|
|
#include <gccore.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2008-08-06 03:39:43 +02:00
|
|
|
#include <wiiuse/wpad.h>
|
2008-08-06 04:31:44 +02:00
|
|
|
#include <sys/dir.h>
|
2008-09-26 06:34:33 +02:00
|
|
|
#include <malloc.h>
|
2008-08-10 05:14:39 +02:00
|
|
|
|
2008-08-19 08:05:57 +02:00
|
|
|
#ifdef WII_DVD
|
2008-08-23 05:20:54 +02:00
|
|
|
extern "C" {
|
2008-08-19 08:05:57 +02:00
|
|
|
#include <di/di.h>
|
2008-08-23 05:20:54 +02:00
|
|
|
}
|
|
|
|
#endif
|
2008-08-19 08:05:57 +02:00
|
|
|
|
2008-08-06 03:09:59 +02:00
|
|
|
#include "snes9x.h"
|
|
|
|
#include "memmap.h"
|
|
|
|
|
2008-09-09 19:36:48 +02:00
|
|
|
#include "snes9xGX.h"
|
2008-08-06 03:09:59 +02:00
|
|
|
#include "dvd.h"
|
2008-08-07 07:19:17 +02:00
|
|
|
#include "menudraw.h"
|
2008-08-06 03:09:59 +02:00
|
|
|
#include "video.h"
|
|
|
|
#include "aram.h"
|
2008-08-10 05:14:39 +02:00
|
|
|
#include "smbop.h"
|
2008-08-07 07:33:24 +02:00
|
|
|
#include "fileop.h"
|
2008-08-12 05:25:16 +02:00
|
|
|
#include "memcardop.h"
|
2008-08-20 06:07:38 +02:00
|
|
|
#include "input.h"
|
2008-08-06 03:09:59 +02:00
|
|
|
|
2008-08-10 05:14:39 +02:00
|
|
|
int offset;
|
|
|
|
int selection;
|
|
|
|
char currentdir[MAXPATHLEN];
|
2008-08-06 03:39:43 +02:00
|
|
|
int maxfiles;
|
2008-08-06 03:09:59 +02:00
|
|
|
extern int screenheight;
|
2008-08-10 05:14:39 +02:00
|
|
|
extern unsigned long ARAM_ROMSIZE;
|
2008-08-16 02:02:08 +02:00
|
|
|
|
|
|
|
int havedir = -1;
|
|
|
|
extern u64 dvddir;
|
|
|
|
extern int dvddirlength;
|
|
|
|
|
2008-08-10 05:14:39 +02:00
|
|
|
int hasloaded = 0;
|
2008-08-06 03:39:43 +02:00
|
|
|
|
2008-08-14 00:44:59 +02:00
|
|
|
// Global file entry table
|
|
|
|
FILEENTRIES filelist[MAXFILES];
|
|
|
|
|
2008-09-26 06:34:33 +02:00
|
|
|
unsigned char *savebuffer = NULL;
|
2008-08-12 05:25:16 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
2008-09-27 09:13:52 +02:00
|
|
|
* AllocSaveBuffer ()
|
|
|
|
* Clear and allocate the savebuffer
|
2008-09-12 07:28:40 +02:00
|
|
|
***************************************************************************/
|
2008-08-12 05:25:16 +02:00
|
|
|
void
|
2008-09-27 09:13:52 +02:00
|
|
|
AllocSaveBuffer ()
|
2008-08-12 05:25:16 +02:00
|
|
|
{
|
2008-09-27 09:13:52 +02:00
|
|
|
if (savebuffer != NULL)
|
2008-09-26 06:34:33 +02:00
|
|
|
free(savebuffer);
|
|
|
|
|
|
|
|
savebuffer = (unsigned char *) memalign(32, SAVEBUFFERSIZE);
|
|
|
|
memset (savebuffer, 0, SAVEBUFFERSIZE);
|
2008-08-12 05:25:16 +02:00
|
|
|
}
|
|
|
|
|
2008-09-27 09:13:52 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* FreeSaveBuffer ()
|
|
|
|
* Free the savebuffer memory
|
|
|
|
***************************************************************************/
|
|
|
|
void
|
|
|
|
FreeSaveBuffer ()
|
|
|
|
{
|
|
|
|
if (savebuffer != NULL)
|
|
|
|
free(savebuffer);
|
2008-09-27 09:57:03 +02:00
|
|
|
|
|
|
|
savebuffer = NULL;
|
2008-09-27 09:13:52 +02:00
|
|
|
}
|
|
|
|
|
2008-08-07 05:25:02 +02:00
|
|
|
/****************************************************************************
|
2008-08-08 09:57:01 +02:00
|
|
|
* autoLoadMethod()
|
|
|
|
* Auto-determines and sets the load method
|
|
|
|
* Returns method set
|
2008-08-07 05:25:02 +02:00
|
|
|
****************************************************************************/
|
|
|
|
int autoLoadMethod()
|
2008-08-06 03:09:59 +02:00
|
|
|
{
|
2008-08-12 05:25:16 +02:00
|
|
|
ShowAction ((char*) "Attempting to determine load method...");
|
|
|
|
|
|
|
|
if(ChangeFATInterface(METHOD_SD, SILENT))
|
2008-08-08 09:57:01 +02:00
|
|
|
return METHOD_SD;
|
2008-08-12 05:25:16 +02:00
|
|
|
else if(ChangeFATInterface(METHOD_USB, SILENT))
|
2008-08-08 09:57:01 +02:00
|
|
|
return METHOD_USB;
|
2008-08-16 02:02:08 +02:00
|
|
|
else if(TestDVD())
|
2008-08-12 05:25:16 +02:00
|
|
|
return METHOD_DVD;
|
|
|
|
else if(ConnectShare (SILENT))
|
|
|
|
return METHOD_SMB;
|
2008-08-08 09:57:01 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
WaitPrompt((char*) "Unable to auto-determine load method!");
|
|
|
|
return 0; // no method found
|
|
|
|
}
|
2008-08-07 05:25:02 +02:00
|
|
|
}
|
2008-08-06 03:09:59 +02:00
|
|
|
|
2008-08-07 05:25:02 +02:00
|
|
|
/****************************************************************************
|
2008-08-08 09:57:01 +02:00
|
|
|
* autoSaveMethod()
|
|
|
|
* Auto-determines and sets the save method
|
|
|
|
* Returns method set
|
2008-08-07 05:25:02 +02:00
|
|
|
****************************************************************************/
|
|
|
|
int autoSaveMethod()
|
|
|
|
{
|
2008-08-12 05:25:16 +02:00
|
|
|
ShowAction ((char*) "Attempting to determine save method...");
|
|
|
|
|
|
|
|
if(ChangeFATInterface(METHOD_SD, SILENT))
|
2008-08-08 09:57:01 +02:00
|
|
|
return METHOD_SD;
|
2008-08-12 05:25:16 +02:00
|
|
|
else if(ChangeFATInterface(METHOD_USB, SILENT))
|
2008-08-08 09:57:01 +02:00
|
|
|
return METHOD_USB;
|
2008-08-08 10:13:13 +02:00
|
|
|
else if(TestCard(CARD_SLOTA, SILENT))
|
2008-08-08 09:57:01 +02:00
|
|
|
return METHOD_MC_SLOTA;
|
2008-08-08 10:13:13 +02:00
|
|
|
else if(TestCard(CARD_SLOTB, SILENT))
|
2008-08-08 09:57:01 +02:00
|
|
|
return METHOD_MC_SLOTB;
|
2008-08-12 05:25:16 +02:00
|
|
|
else if(ConnectShare (SILENT))
|
|
|
|
return METHOD_SMB;
|
2008-08-08 09:57:01 +02:00
|
|
|
else
|
2008-08-07 05:25:02 +02:00
|
|
|
{
|
2008-08-08 09:57:01 +02:00
|
|
|
WaitPrompt((char*) "Unable to auto-determine save method!");
|
|
|
|
return 0; // no method found
|
2008-08-07 05:25:02 +02:00
|
|
|
}
|
|
|
|
}
|
2008-08-06 03:09:59 +02:00
|
|
|
|
2008-09-12 07:28:40 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* UpdateDirName()
|
|
|
|
* Update curent directory name for file browser
|
2008-08-10 05:14:39 +02:00
|
|
|
***************************************************************************/
|
2008-08-16 02:02:08 +02:00
|
|
|
int UpdateDirName(int method)
|
2008-08-10 05:14:39 +02:00
|
|
|
{
|
|
|
|
int size=0;
|
2008-09-27 09:13:52 +02:00
|
|
|
char * test;
|
2008-08-10 05:14:39 +02:00
|
|
|
char temp[1024];
|
|
|
|
|
2008-08-16 02:02:08 +02:00
|
|
|
// update DVD directory (does not utilize 'currentdir')
|
|
|
|
if(method == METHOD_DVD)
|
|
|
|
{
|
|
|
|
dvddir = filelist[selection].offset;
|
|
|
|
dvddirlength = filelist[selection].length;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-08-10 05:14:39 +02:00
|
|
|
/* current directory doesn't change */
|
|
|
|
if (strcmp(filelist[selection].filename,".") == 0)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* go up to parent directory */
|
|
|
|
else if (strcmp(filelist[selection].filename,"..") == 0)
|
|
|
|
{
|
|
|
|
/* determine last subdirectory namelength */
|
|
|
|
sprintf(temp,"%s",currentdir);
|
|
|
|
test = strtok(temp,"/");
|
|
|
|
while (test != NULL)
|
|
|
|
{
|
|
|
|
size = strlen(test);
|
|
|
|
test = strtok(NULL,"/");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* remove last subdirectory name */
|
|
|
|
size = strlen(currentdir) - size - 1;
|
|
|
|
currentdir[size] = 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
/* Open a directory */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* test new directory namelength */
|
|
|
|
if ((strlen(currentdir)+1+strlen(filelist[selection].filename)) < MAXPATHLEN)
|
|
|
|
{
|
|
|
|
/* update current directory name */
|
|
|
|
sprintf(currentdir, "%s/%s",currentdir, filelist[selection].filename);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WaitPrompt((char*)"Directory name is too long !");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-12 07:28:40 +02:00
|
|
|
/****************************************************************************
|
2008-08-10 05:14:39 +02:00
|
|
|
* FileSortCallback
|
|
|
|
*
|
|
|
|
* Quick sort callback to sort file entries with the following order:
|
|
|
|
* .
|
|
|
|
* ..
|
|
|
|
* <dirs>
|
|
|
|
* <files>
|
|
|
|
***************************************************************************/
|
|
|
|
int FileSortCallback(const void *f1, const void *f2)
|
|
|
|
{
|
|
|
|
/* Special case for implicit directories */
|
|
|
|
if(((FILEENTRIES *)f1)->filename[0] == '.' || ((FILEENTRIES *)f2)->filename[0] == '.')
|
|
|
|
{
|
|
|
|
if(strcmp(((FILEENTRIES *)f1)->filename, ".") == 0) { return -1; }
|
|
|
|
if(strcmp(((FILEENTRIES *)f2)->filename, ".") == 0) { return 1; }
|
|
|
|
if(strcmp(((FILEENTRIES *)f1)->filename, "..") == 0) { return -1; }
|
|
|
|
if(strcmp(((FILEENTRIES *)f2)->filename, "..") == 0) { return 1; }
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If one is a file and one is a directory the directory is first. */
|
2008-08-17 07:25:33 +02:00
|
|
|
if(((FILEENTRIES *)f1)->flags && !(((FILEENTRIES *)f2)->flags)) return -1;
|
|
|
|
if(!(((FILEENTRIES *)f1)->flags) && ((FILEENTRIES *)f2)->flags) return 1;
|
2008-08-10 05:14:39 +02:00
|
|
|
|
|
|
|
return stricmp(((FILEENTRIES *)f1)->filename, ((FILEENTRIES *)f2)->filename);
|
|
|
|
}
|
|
|
|
|
2008-08-07 05:25:02 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* StripExt
|
|
|
|
*
|
|
|
|
* Strips an extension from a filename
|
2008-09-12 07:28:40 +02:00
|
|
|
***************************************************************************/
|
2008-08-06 03:09:59 +02:00
|
|
|
|
2008-08-07 05:25:02 +02:00
|
|
|
void StripExt(char* returnstring, char * inputstring)
|
|
|
|
{
|
|
|
|
char* loc_dot;
|
2008-08-07 07:19:17 +02:00
|
|
|
|
2008-08-07 05:25:02 +02:00
|
|
|
strcpy (returnstring, inputstring);
|
|
|
|
loc_dot = strrchr(returnstring,'.');
|
|
|
|
if (loc_dot != NULL)
|
2008-09-27 10:36:22 +02:00
|
|
|
*loc_dot = 0; // strip file extension
|
2008-08-07 05:25:02 +02:00
|
|
|
}
|
2008-08-06 03:09:59 +02:00
|
|
|
|
2008-08-07 05:25:02 +02:00
|
|
|
/****************************************************************************
|
2008-08-06 03:09:59 +02:00
|
|
|
* FileSelector
|
|
|
|
*
|
2008-08-07 05:25:02 +02:00
|
|
|
* Let user select a file from the listing
|
2008-09-12 07:28:40 +02:00
|
|
|
***************************************************************************/
|
2008-08-20 06:07:38 +02:00
|
|
|
int FileSelector (int method)
|
2008-08-06 03:09:59 +02:00
|
|
|
{
|
2008-08-20 06:07:38 +02:00
|
|
|
u32 p = 0;
|
|
|
|
u32 wp = 0;
|
|
|
|
u32 ph = 0;
|
|
|
|
u32 wh = 0;
|
|
|
|
signed char gc_ay = 0;
|
|
|
|
signed char gc_sx = 0;
|
|
|
|
signed char wm_ay = 0;
|
|
|
|
signed char wm_sx = 0;
|
2008-08-20 09:58:55 +02:00
|
|
|
|
2008-08-06 03:09:59 +02:00
|
|
|
int haverom = 0;
|
|
|
|
int redraw = 1;
|
|
|
|
int selectit = 0;
|
2008-08-20 09:58:55 +02:00
|
|
|
|
2008-08-06 03:55:59 +02:00
|
|
|
int scroll_delay = 0;
|
|
|
|
bool move_selection = 0;
|
|
|
|
#define SCROLL_INITIAL_DELAY 15
|
2008-08-07 05:25:02 +02:00
|
|
|
#define SCROLL_LOOP_DELAY 2
|
|
|
|
|
|
|
|
while (haverom == 0)
|
2008-08-06 03:09:59 +02:00
|
|
|
{
|
|
|
|
if (redraw)
|
2008-08-14 00:44:59 +02:00
|
|
|
ShowFiles (filelist, maxfiles, offset, selection);
|
2008-08-06 03:09:59 +02:00
|
|
|
redraw = 0;
|
2008-08-06 03:45:56 +02:00
|
|
|
|
2008-08-06 03:55:59 +02:00
|
|
|
VIDEO_WaitVSync(); // slow things down a bit so we don't overread the pads
|
2008-08-07 05:25:02 +02:00
|
|
|
|
2008-08-20 06:07:38 +02:00
|
|
|
gc_ay = PAD_StickY (0);
|
|
|
|
gc_sx = PAD_SubStickX (0);
|
2008-08-20 09:58:55 +02:00
|
|
|
|
2008-08-06 03:09:59 +02:00
|
|
|
p = PAD_ButtonsDown (0);
|
2008-08-06 03:55:59 +02:00
|
|
|
ph = PAD_ButtonsHeld (0);
|
2008-08-06 03:45:56 +02:00
|
|
|
#ifdef HW_RVL
|
2008-08-20 06:07:38 +02:00
|
|
|
wm_ay = WPAD_StickY (0, 0);
|
|
|
|
wm_sx = WPAD_StickX (0, 1);
|
|
|
|
|
2008-08-06 03:39:43 +02:00
|
|
|
wp = WPAD_ButtonsDown (0);
|
2008-08-06 03:55:59 +02:00
|
|
|
wh = WPAD_ButtonsHeld (0);
|
2008-08-06 03:45:56 +02:00
|
|
|
#endif
|
2008-08-07 05:25:02 +02:00
|
|
|
|
2008-08-06 03:55:59 +02:00
|
|
|
/*** Check for exit combo ***/
|
2008-08-20 06:07:38 +02:00
|
|
|
if ( (gc_sx < -70) || (wm_sx < -70) || (wp & WPAD_BUTTON_HOME) || (wp & WPAD_CLASSIC_BUTTON_HOME) )
|
2008-08-10 05:14:39 +02:00
|
|
|
return 0;
|
2008-08-07 05:25:02 +02:00
|
|
|
|
2008-08-06 03:55:59 +02:00
|
|
|
/*** Check buttons, perform actions ***/
|
2008-08-12 05:25:16 +02:00
|
|
|
if ( (p & PAD_BUTTON_A) || selectit || (wp & (WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A)) )
|
|
|
|
{
|
|
|
|
if ( selectit )
|
|
|
|
selectit = 0;
|
|
|
|
if (filelist[selection].flags) // This is directory
|
|
|
|
{
|
|
|
|
/* update current directory and set new entry list if directory has changed */
|
2008-08-16 02:02:08 +02:00
|
|
|
int status = UpdateDirName(method);
|
2008-08-12 05:25:16 +02:00
|
|
|
if (status == 1) // ok, open directory
|
|
|
|
{
|
|
|
|
switch (method)
|
|
|
|
{
|
|
|
|
case METHOD_SD:
|
|
|
|
case METHOD_USB:
|
|
|
|
maxfiles = ParseFATdirectory(method);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case METHOD_DVD:
|
|
|
|
maxfiles = ParseDVDdirectory();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case METHOD_SMB:
|
|
|
|
maxfiles = ParseSMBdirectory();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!maxfiles)
|
|
|
|
{
|
|
|
|
WaitPrompt ((char*) "Error reading directory !");
|
|
|
|
haverom = 1; // quit menu
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (status == -1) // directory name too long
|
|
|
|
{
|
2008-08-16 02:02:08 +02:00
|
|
|
haverom = 1; // quit menu
|
2008-08-12 05:25:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else // this is a file
|
|
|
|
{
|
|
|
|
// store the filename (w/o ext) - used for sram/freeze naming
|
|
|
|
StripExt(Memory.ROMFilename, filelist[selection].filename);
|
|
|
|
|
|
|
|
ShowAction ((char *)"Loading...");
|
|
|
|
|
|
|
|
switch (method)
|
|
|
|
{
|
|
|
|
case METHOD_SD:
|
|
|
|
case METHOD_USB:
|
2008-09-27 00:28:57 +02:00
|
|
|
ARAM_ROMSIZE = LoadFATFile ();
|
2008-08-12 05:25:16 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case METHOD_DVD:
|
2008-08-16 02:02:08 +02:00
|
|
|
dvddir = filelist[selection].offset;
|
|
|
|
dvddirlength = filelist[selection].length;
|
2008-09-27 00:28:57 +02:00
|
|
|
ARAM_ROMSIZE = LoadDVDFile ();
|
2008-08-12 05:25:16 +02:00
|
|
|
break;
|
2008-08-07 07:19:17 +02:00
|
|
|
|
2008-08-07 05:25:02 +02:00
|
|
|
case METHOD_SMB:
|
2008-08-12 05:25:16 +02:00
|
|
|
ARAM_ROMSIZE =
|
2008-09-27 00:28:57 +02:00
|
|
|
LoadSMBFile ();
|
2008-08-12 05:25:16 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ARAM_ROMSIZE > 0)
|
|
|
|
{
|
|
|
|
hasloaded = 1; // indicator for memmap.cpp
|
|
|
|
Memory.LoadROM ("BLANK.SMC");
|
|
|
|
Memory.LoadSRAM ("BLANK");
|
|
|
|
haverom = 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WaitPrompt((char*) "Error loading ROM!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
redraw = 1;
|
|
|
|
} // End of A
|
2008-08-06 03:45:56 +02:00
|
|
|
if ( (p & PAD_BUTTON_B) || (wp & (WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B)) )
|
2008-08-06 03:09:59 +02:00
|
|
|
{
|
2008-08-07 05:25:02 +02:00
|
|
|
while ( (PAD_ButtonsDown(0) & PAD_BUTTON_B)
|
2008-08-06 03:45:56 +02:00
|
|
|
#ifdef HW_RVL
|
2008-08-07 05:25:02 +02:00
|
|
|
|| (WPAD_ButtonsDown(0) & (WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B))
|
2008-08-06 03:45:56 +02:00
|
|
|
#endif
|
|
|
|
)
|
2008-08-06 03:09:59 +02:00
|
|
|
VIDEO_WaitVSync();
|
2008-08-07 05:25:02 +02:00
|
|
|
if ( strcmp(filelist[0].filename,"..") == 0 )
|
2008-08-06 03:39:43 +02:00
|
|
|
{
|
|
|
|
selection = 0;
|
|
|
|
selectit = 1;
|
|
|
|
}
|
2008-08-07 05:25:02 +02:00
|
|
|
else if ( strcmp(filelist[1].filename,"..") == 0 )
|
2008-08-06 03:39:43 +02:00
|
|
|
{
|
2008-08-06 03:09:59 +02:00
|
|
|
selection = selectit = 1;
|
2008-08-06 03:39:43 +02:00
|
|
|
} else {
|
2008-08-06 03:09:59 +02:00
|
|
|
return 0;
|
2008-08-06 03:39:43 +02:00
|
|
|
}
|
|
|
|
} // End of B
|
2008-08-20 06:07:38 +02:00
|
|
|
if ( ((p | ph) & PAD_BUTTON_DOWN) || ((wp | wh) & (WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN)) || (gc_ay < -PADCAL) || (wm_ay < -PADCAL) )
|
2008-08-06 03:09:59 +02:00
|
|
|
{
|
2008-08-06 03:55:59 +02:00
|
|
|
if ( (p & PAD_BUTTON_DOWN) || (wp & (WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN)) ) { /*** Button just pressed ***/
|
|
|
|
scroll_delay = SCROLL_INITIAL_DELAY; // reset scroll delay.
|
|
|
|
move_selection = 1; //continue (move selection)
|
2008-08-07 05:25:02 +02:00
|
|
|
}
|
2008-08-06 03:55:59 +02:00
|
|
|
else if (scroll_delay == 0) { /*** Button is held ***/
|
|
|
|
scroll_delay = SCROLL_LOOP_DELAY;
|
|
|
|
move_selection = 1; //continue (move selection)
|
|
|
|
} else {
|
|
|
|
scroll_delay--; // wait
|
|
|
|
}
|
2008-08-07 05:25:02 +02:00
|
|
|
|
2008-08-06 03:55:59 +02:00
|
|
|
if (move_selection)
|
|
|
|
{
|
|
|
|
selection++;
|
|
|
|
if (selection == maxfiles)
|
|
|
|
selection = offset = 0;
|
|
|
|
if ((selection - offset) >= PAGESIZE)
|
|
|
|
offset += PAGESIZE;
|
|
|
|
redraw = 1;
|
|
|
|
move_selection = 0;
|
|
|
|
}
|
2008-08-06 03:39:43 +02:00
|
|
|
} // End of down
|
2008-08-20 06:07:38 +02:00
|
|
|
if ( ((p | ph) & PAD_BUTTON_UP) || ((wp | wh) & (WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP)) || (gc_ay > PADCAL) || (wm_ay > PADCAL) )
|
2008-08-07 05:25:02 +02:00
|
|
|
{
|
2008-08-06 03:55:59 +02:00
|
|
|
if ( (p & PAD_BUTTON_UP) || (wp & (WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP)) ) { /*** Button just pressed***/
|
|
|
|
scroll_delay = SCROLL_INITIAL_DELAY; // reset scroll delay.
|
|
|
|
move_selection = 1; //continue (move selection)
|
2008-08-07 05:25:02 +02:00
|
|
|
}
|
2008-08-06 03:55:59 +02:00
|
|
|
else if (scroll_delay == 0) { /*** Button is held ***/
|
|
|
|
scroll_delay = SCROLL_LOOP_DELAY;
|
|
|
|
move_selection = 1; //continue (move selection)
|
|
|
|
} else {
|
|
|
|
scroll_delay--; // wait
|
|
|
|
}
|
2008-08-07 05:25:02 +02:00
|
|
|
|
2008-08-06 03:55:59 +02:00
|
|
|
if (move_selection)
|
|
|
|
{
|
|
|
|
selection--;
|
|
|
|
if (selection < 0) {
|
|
|
|
selection = maxfiles - 1;
|
|
|
|
offset = selection - PAGESIZE + 1;
|
|
|
|
}
|
|
|
|
if (selection < offset)
|
|
|
|
offset -= PAGESIZE;
|
|
|
|
if (offset < 0)
|
|
|
|
offset = 0;
|
|
|
|
redraw = 1;
|
|
|
|
move_selection = 0;
|
|
|
|
}
|
2008-08-06 03:39:43 +02:00
|
|
|
} // End of Up
|
2008-08-06 03:45:56 +02:00
|
|
|
if ( (p & PAD_BUTTON_LEFT) || (wp & (WPAD_BUTTON_LEFT | WPAD_CLASSIC_BUTTON_LEFT)) )
|
2008-08-06 03:09:59 +02:00
|
|
|
{
|
|
|
|
/*** Go back a page ***/
|
|
|
|
selection -= PAGESIZE;
|
|
|
|
if (selection < 0)
|
|
|
|
{
|
|
|
|
selection = maxfiles - 1;
|
|
|
|
offset = selection - PAGESIZE + 1;
|
|
|
|
}
|
|
|
|
if (selection < offset)
|
|
|
|
offset -= PAGESIZE;
|
|
|
|
if (offset < 0)
|
|
|
|
offset = 0;
|
|
|
|
redraw = 1;
|
|
|
|
}
|
2008-08-06 03:45:56 +02:00
|
|
|
if ( (p & PAD_BUTTON_RIGHT) || (wp & (WPAD_BUTTON_RIGHT | WPAD_CLASSIC_BUTTON_RIGHT)) )
|
2008-08-06 03:09:59 +02:00
|
|
|
{
|
|
|
|
/*** Go forward a page ***/
|
|
|
|
selection += PAGESIZE;
|
|
|
|
if (selection > maxfiles - 1)
|
|
|
|
selection = offset = 0;
|
|
|
|
if ((selection - offset) >= PAGESIZE)
|
|
|
|
offset += PAGESIZE;
|
|
|
|
redraw = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-08-07 05:25:02 +02:00
|
|
|
/****************************************************************************
|
2008-08-06 03:09:59 +02:00
|
|
|
* OpenDVD
|
|
|
|
*
|
|
|
|
* Function to load a DVD directory and display to user.
|
2008-09-12 07:28:40 +02:00
|
|
|
***************************************************************************/
|
2008-08-06 03:09:59 +02:00
|
|
|
int
|
2008-08-07 05:25:02 +02:00
|
|
|
OpenDVD (int method)
|
2008-08-06 03:09:59 +02:00
|
|
|
{
|
2008-08-12 05:25:16 +02:00
|
|
|
if (!getpvd())
|
|
|
|
{
|
|
|
|
ShowAction((char*) "Loading DVD...");
|
2008-08-19 08:05:57 +02:00
|
|
|
#ifdef HW_DOL
|
2008-08-16 02:02:08 +02:00
|
|
|
DVD_Mount(); // mount the DVD unit again
|
2008-08-19 08:05:57 +02:00
|
|
|
#elif WII_DVD
|
|
|
|
u32 val;
|
|
|
|
DI_GetCoverRegister(&val);
|
|
|
|
if(val & 0x1) // True if no disc inside, use (val & 0x2) for true if disc inside.
|
|
|
|
{
|
2008-08-20 09:58:55 +02:00
|
|
|
WaitPrompt((char *)"No disc inserted!");
|
2008-08-19 08:05:57 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
DI_Mount();
|
|
|
|
while(DI_GetStatus() & DVD_INIT);
|
|
|
|
#endif
|
2008-08-16 02:02:08 +02:00
|
|
|
|
2008-08-12 05:25:16 +02:00
|
|
|
if (!getpvd())
|
2008-08-19 08:05:57 +02:00
|
|
|
{
|
|
|
|
WaitPrompt ((char *)"Invalid DVD.");
|
2008-08-16 02:02:08 +02:00
|
|
|
return 0; // not a ISO9660 DVD
|
2008-08-19 08:05:57 +02:00
|
|
|
}
|
2008-08-12 05:25:16 +02:00
|
|
|
}
|
2008-08-07 05:25:02 +02:00
|
|
|
|
2008-08-16 02:02:08 +02:00
|
|
|
maxfiles = ParseDVDdirectory(); // load root folder
|
|
|
|
|
|
|
|
// switch to rom folder
|
|
|
|
SwitchDVDFolder(GCSettings.LoadFolder);
|
|
|
|
|
|
|
|
if (maxfiles > 0)
|
2008-08-12 05:25:16 +02:00
|
|
|
{
|
2008-08-16 02:02:08 +02:00
|
|
|
return FileSelector (method);
|
2008-08-12 05:25:16 +02:00
|
|
|
}
|
|
|
|
else
|
2008-08-16 02:02:08 +02:00
|
|
|
{
|
|
|
|
// no entries found
|
|
|
|
WaitPrompt ((char *)"No Files Found!");
|
|
|
|
return 0;
|
|
|
|
}
|
2008-08-06 03:09:59 +02:00
|
|
|
}
|
|
|
|
|
2008-08-07 05:25:02 +02:00
|
|
|
/****************************************************************************
|
2008-08-06 03:09:59 +02:00
|
|
|
* OpenSMB
|
|
|
|
*
|
|
|
|
* Function to load from an SMB share
|
2008-09-12 07:28:40 +02:00
|
|
|
***************************************************************************/
|
2008-08-06 03:09:59 +02:00
|
|
|
int
|
2008-08-07 05:25:02 +02:00
|
|
|
OpenSMB (int method)
|
2008-08-06 03:09:59 +02:00
|
|
|
{
|
2008-08-10 05:14:39 +02:00
|
|
|
// Connect to network share
|
2008-08-12 05:25:16 +02:00
|
|
|
if(ConnectShare (NOTSILENT))
|
2008-08-10 05:14:39 +02:00
|
|
|
{
|
|
|
|
// change current dir to root dir
|
2008-08-10 10:09:22 +02:00
|
|
|
sprintf(currentdir, "/%s", GCSettings.LoadFolder);
|
2008-08-06 04:31:44 +02:00
|
|
|
|
2008-08-12 05:25:16 +02:00
|
|
|
maxfiles = ParseSMBdirectory ();
|
|
|
|
if (maxfiles > 0)
|
2008-08-10 05:14:39 +02:00
|
|
|
{
|
|
|
|
return FileSelector (method);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// no entries found
|
|
|
|
WaitPrompt ((char *)"No Files Found!");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
2008-08-06 04:31:44 +02:00
|
|
|
}
|
|
|
|
|
2008-08-07 05:25:02 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* OpenFAT
|
|
|
|
*
|
|
|
|
* Function to load from FAT
|
2008-09-12 07:28:40 +02:00
|
|
|
***************************************************************************/
|
2008-08-07 05:25:02 +02:00
|
|
|
int
|
|
|
|
OpenFAT (int method)
|
|
|
|
{
|
2008-08-12 05:25:16 +02:00
|
|
|
if(ChangeFATInterface(method, NOTSILENT))
|
2008-08-06 04:31:44 +02:00
|
|
|
{
|
2008-08-10 05:14:39 +02:00
|
|
|
// change current dir to snes roms directory
|
|
|
|
sprintf ( currentdir, "%s/%s", ROOTFATDIR, GCSettings.LoadFolder );
|
2008-08-07 05:25:02 +02:00
|
|
|
|
2008-08-10 05:14:39 +02:00
|
|
|
// Parse initial root directory and get entries list
|
2008-08-12 05:25:16 +02:00
|
|
|
maxfiles = ParseFATdirectory (method);
|
|
|
|
if (maxfiles > 0)
|
2008-08-10 05:14:39 +02:00
|
|
|
{
|
|
|
|
// Select an entry
|
|
|
|
return FileSelector (method);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// no entries found
|
|
|
|
WaitPrompt ((char *)"No Files Found!");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2008-08-07 05:25:02 +02:00
|
|
|
return 0;
|
2008-08-06 04:31:44 +02:00
|
|
|
}
|
|
|
|
|
2008-08-07 05:25:02 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* OpenROM
|
|
|
|
* Opens device specified by method, displays a list of ROMS
|
2008-09-12 07:28:40 +02:00
|
|
|
***************************************************************************/
|
2008-08-07 05:25:02 +02:00
|
|
|
|
2008-08-06 03:09:59 +02:00
|
|
|
int
|
2008-08-07 05:25:02 +02:00
|
|
|
OpenROM (int method)
|
2008-08-06 03:09:59 +02:00
|
|
|
{
|
2008-08-07 05:25:02 +02:00
|
|
|
int loadROM = 0;
|
2008-08-07 07:19:17 +02:00
|
|
|
|
2008-08-07 05:25:02 +02:00
|
|
|
if(method == METHOD_AUTO)
|
|
|
|
method = autoLoadMethod();
|
2008-08-06 04:31:44 +02:00
|
|
|
|
2008-08-07 05:25:02 +02:00
|
|
|
switch (method)
|
|
|
|
{
|
|
|
|
case METHOD_SD:
|
|
|
|
case METHOD_USB:
|
|
|
|
loadROM = OpenFAT (method);
|
|
|
|
break;
|
|
|
|
case METHOD_DVD:
|
|
|
|
// Load from DVD
|
|
|
|
loadROM = OpenDVD (method);
|
|
|
|
break;
|
|
|
|
case METHOD_SMB:
|
|
|
|
// Load from Network (SMB)
|
|
|
|
loadROM = OpenSMB (method);
|
|
|
|
break;
|
|
|
|
}
|
2008-08-07 07:19:17 +02:00
|
|
|
|
2008-08-07 05:25:02 +02:00
|
|
|
return loadROM;
|
2008-08-06 03:09:59 +02:00
|
|
|
}
|