2008-08-06 03:09:59 +02:00
|
|
|
/****************************************************************************
|
2008-10-16 03:48:08 +02:00
|
|
|
* Snes9x 1.50
|
|
|
|
*
|
|
|
|
* Nintendo Gamecube Filesel - borrowed from GPP
|
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-10-16 03:48:08 +02:00
|
|
|
****************************************************************************/
|
2008-08-06 03:09:59 +02:00
|
|
|
#include <gccore.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2008-08-19 08:05:57 +02:00
|
|
|
|
2008-08-06 03:09:59 +02:00
|
|
|
#include "snes9x.h"
|
|
|
|
#include "memmap.h"
|
2008-10-16 03:48:08 +02:00
|
|
|
#include "debug.h"
|
|
|
|
#include "cpuexec.h"
|
|
|
|
#include "ppu.h"
|
|
|
|
#include "apu.h"
|
|
|
|
#include "display.h"
|
|
|
|
#include "gfx.h"
|
|
|
|
#include "soundux.h"
|
|
|
|
#include "spc700.h"
|
|
|
|
#include "spc7110.h"
|
|
|
|
#include "controls.h"
|
|
|
|
|
|
|
|
#include "snes9xGx.h"
|
2008-08-06 03:09:59 +02:00
|
|
|
#include "dvd.h"
|
2008-10-16 03:48:08 +02:00
|
|
|
#include "ftfont.h"
|
2008-08-06 03:09:59 +02:00
|
|
|
#include "video.h"
|
|
|
|
#include "aram.h"
|
2008-10-16 03:48:08 +02:00
|
|
|
#include "ngcunzip.h"
|
|
|
|
#include "filesel.h"
|
|
|
|
#include "smbload.h"
|
|
|
|
#include "sdload.h"
|
|
|
|
#include "mcsave.h"
|
|
|
|
|
|
|
|
#define PAGESIZE 17
|
|
|
|
static int maxfiles;
|
|
|
|
int havedir = 0;
|
|
|
|
int hasloaded = 0;
|
|
|
|
int loadtype = 0;
|
|
|
|
int LoadDVDFile (unsigned char *buffer);
|
|
|
|
int haveSDdir = 0;
|
|
|
|
extern unsigned long ARAM_ROMSIZE;
|
2008-08-06 03:09:59 +02:00
|
|
|
extern int screenheight;
|
2008-10-16 03:48:08 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Showfile screen
|
|
|
|
*
|
|
|
|
* Display the file selection to the user
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ShowFiles (int offset, int selection)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
char text[80];
|
|
|
|
int ypos;
|
|
|
|
int w;
|
|
|
|
|
|
|
|
clearscreen ();
|
2008-08-14 00:44:59 +02:00
|
|
|
|
2008-10-16 03:48:08 +02:00
|
|
|
setfontsize (16);
|
2008-08-12 05:25:16 +02:00
|
|
|
|
2008-10-16 03:48:08 +02:00
|
|
|
ypos = (screenheight - ((PAGESIZE - 1) * 20)) >> 1;
|
2008-09-26 06:34:33 +02:00
|
|
|
|
2008-10-16 03:48:08 +02:00
|
|
|
if (screenheight == 480)
|
|
|
|
ypos += 24;
|
|
|
|
else
|
|
|
|
ypos += 10;
|
2008-08-12 05:25:16 +02:00
|
|
|
|
2008-10-16 03:48:08 +02:00
|
|
|
j = 0;
|
|
|
|
for (i = offset; i < (offset + PAGESIZE) && (i < maxfiles); i++)
|
2008-09-27 09:57:03 +02:00
|
|
|
|
2008-10-16 03:48:08 +02:00
|
|
|
{
|
|
|
|
if (filelist[i].flags)
|
2008-09-27 09:13:52 +02:00
|
|
|
|
2008-10-16 03:48:08 +02:00
|
|
|
{
|
|
|
|
strcpy (text, "[");
|
|
|
|
strcat (text, filelist[i].displayname);
|
|
|
|
strcat (text, "]");
|
|
|
|
}
|
2008-08-06 03:09:59 +02:00
|
|
|
|
2008-10-16 03:48:08 +02:00
|
|
|
else
|
|
|
|
strcpy (text, filelist[i].displayname);
|
|
|
|
if (j == (selection - offset))
|
2008-08-06 03:09:59 +02:00
|
|
|
|
2008-10-16 03:48:08 +02:00
|
|
|
{
|
2008-08-10 05:14:39 +02:00
|
|
|
|
2008-10-16 03:48:08 +02:00
|
|
|
/*** Highlighted text entry ***/
|
|
|
|
for ( w = 0; w < 20; w++ )
|
|
|
|
DrawLineFast( 30, 610, ( j * 20 ) + (ypos-16) + w, 0x80, 0x80, 0x80 );
|
2008-10-14 11:21:34 +02:00
|
|
|
|
2008-10-16 03:48:08 +02:00
|
|
|
setfontcolour (0x00, 0x00, 0xe0);
|
|
|
|
DrawText (-1, (j * 20) + ypos, text);
|
|
|
|
setfontcolour (0x00, 0x00, 0x00);
|
|
|
|
}
|
2008-08-10 05:14:39 +02:00
|
|
|
|
2008-10-16 03:48:08 +02:00
|
|
|
else
|
2008-10-05 23:56:18 +02:00
|
|
|
|
2008-10-16 03:48:08 +02:00
|
|
|
{
|
|
|
|
/*** Normal entry ***/
|
|
|
|
DrawText (-1, (j * 20) + ypos, text);
|
|
|
|
}
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
showscreen ();
|
2008-10-05 23:56:18 +02:00
|
|
|
|
2008-10-16 03:48:08 +02:00
|
|
|
setfontsize (24);
|
2008-10-14 11:21:34 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-10-16 03:48:08 +02:00
|
|
|
/**
|
|
|
|
* SNESROMSOffset
|
|
|
|
*
|
|
|
|
* Function to check for and return offset to a directory called SNESROMS, if
|
|
|
|
* any
|
|
|
|
*/
|
|
|
|
int SNESROMSOffset()
|
2008-08-07 05:25:02 +02:00
|
|
|
{
|
2008-10-16 03:48:08 +02:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for ( i = 0; i < maxfiles; i++ )
|
|
|
|
if (strcmp(filelist[i].filename, "SNESROMS") == 0)
|
|
|
|
return i;
|
|
|
|
return 0;
|
2008-08-07 05:25:02 +02:00
|
|
|
}
|
2008-08-06 03:09:59 +02:00
|
|
|
|
2008-10-16 03:48:08 +02:00
|
|
|
/**
|
2008-08-06 03:09:59 +02:00
|
|
|
* FileSelector
|
|
|
|
*
|
2008-10-16 03:48:08 +02:00
|
|
|
* Let user select a file from the DVD listing
|
|
|
|
*/
|
|
|
|
int offset = 0;
|
|
|
|
int selection = 0;
|
2008-08-20 09:58:55 +02:00
|
|
|
|
2008-10-16 03:48:08 +02:00
|
|
|
#define PADCAL 40
|
|
|
|
int
|
|
|
|
FileSelector ()
|
|
|
|
{
|
|
|
|
short p;
|
|
|
|
signed char a;
|
2008-08-06 03:09:59 +02:00
|
|
|
int haverom = 0;
|
|
|
|
int redraw = 1;
|
|
|
|
int selectit = 0;
|
2008-10-16 03:48:08 +02:00
|
|
|
|
|
|
|
while (haverom == 0)
|
2008-08-06 03:09:59 +02:00
|
|
|
{
|
|
|
|
if (redraw)
|
2008-10-16 03:48:08 +02:00
|
|
|
ShowFiles (offset, selection);
|
2008-08-06 03:09:59 +02:00
|
|
|
redraw = 0;
|
|
|
|
p = PAD_ButtonsDown (0);
|
2008-10-16 03:48:08 +02:00
|
|
|
a = PAD_StickY (0);
|
|
|
|
if ((p & PAD_BUTTON_A) || selectit)
|
2008-08-06 03:09:59 +02:00
|
|
|
{
|
2008-10-16 03:48:08 +02:00
|
|
|
if ( selectit )
|
|
|
|
selectit = 0;
|
|
|
|
if (filelist[selection].flags) /*** This is directory ***/
|
|
|
|
{
|
|
|
|
if (loadtype == LOAD_SDC)
|
|
|
|
{
|
|
|
|
/* memorize last entries list, actual root directory and selection for next access */
|
|
|
|
haveSDdir = 1;
|
|
|
|
|
|
|
|
/* update current directory and set new entry list if directory has changed */
|
|
|
|
int status = updateSDdirname();
|
|
|
|
if (status == 1)
|
|
|
|
{
|
|
|
|
maxfiles = parseSDdirectory();
|
|
|
|
if (!maxfiles)
|
|
|
|
{
|
|
|
|
WaitPrompt ("Error reading directory !");
|
|
|
|
haverom = 1; // quit SD menu
|
|
|
|
haveSDdir = 0; // reset everything at next access
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (status == -1)
|
|
|
|
{
|
|
|
|
haverom = 1; // quit SD menu
|
|
|
|
haveSDdir = 0; // reset everything at next access
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( (strcmp (filelist[selection].filename, "..") == 0)
|
|
|
|
&& ((unsigned int)rootdir == filelist[selection].offset) )
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rootdir = filelist[selection].offset;
|
|
|
|
rootdirlength = filelist[selection].length;
|
|
|
|
offset = selection = 0;
|
|
|
|
maxfiles = parsedirectory ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rootdir = filelist[selection].offset;
|
|
|
|
rootdirlength = filelist[selection].length;
|
|
|
|
|
|
|
|
switch (loadtype)
|
|
|
|
{
|
|
|
|
case LOAD_DVD:
|
|
|
|
/*** Now load the DVD file to it's offset ***/
|
|
|
|
ARAM_ROMSIZE = LoadDVDFile (Memory.ROM);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOAD_SMB:
|
|
|
|
/*** Load from SMB ***/
|
|
|
|
ARAM_ROMSIZE =
|
|
|
|
LoadSMBFile (filelist[selection].filename,
|
|
|
|
filelist[selection].length);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOAD_SDC:
|
|
|
|
/*** Load from SD Card ***/
|
|
|
|
/* memorize last entries list, actual root directory and selection for next access */
|
|
|
|
haveSDdir = 1;
|
|
|
|
ARAM_ROMSIZE = LoadSDFile (filelist[selection].filename,
|
|
|
|
filelist[selection].length);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ARAM_ROMSIZE > 0)
|
|
|
|
{
|
|
|
|
hasloaded = 1;
|
|
|
|
Memory.LoadROM ("BLANK.SMC");
|
|
|
|
|
|
|
|
Memory.LoadSRAM ("BLANK");
|
|
|
|
haverom = 1;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WaitPrompt("Error loading ROM!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
redraw = 1;
|
|
|
|
}
|
|
|
|
if ( p & PAD_BUTTON_B )
|
|
|
|
{
|
|
|
|
while ( PAD_ButtonsDown(0) & PAD_BUTTON_B )
|
2008-08-06 03:09:59 +02:00
|
|
|
VIDEO_WaitVSync();
|
2008-10-16 03:48:08 +02:00
|
|
|
if ((strcmp(filelist[1].filename,"..") == 0) && (strlen (filelist[0].filename) != 0))
|
2008-08-06 03:09:59 +02:00
|
|
|
selection = selectit = 1;
|
2008-10-16 03:48:08 +02:00
|
|
|
else
|
2008-08-06 03:09:59 +02:00
|
|
|
return 0;
|
2008-10-16 03:48:08 +02:00
|
|
|
}
|
|
|
|
if ((p & PAD_BUTTON_DOWN) || (a < -PADCAL))
|
2008-08-06 03:09:59 +02:00
|
|
|
{
|
2008-10-16 03:48:08 +02:00
|
|
|
selection++;
|
|
|
|
if (selection == maxfiles)
|
|
|
|
selection = offset = 0;
|
|
|
|
if ((selection - offset) >= PAGESIZE)
|
|
|
|
offset += PAGESIZE;
|
|
|
|
redraw = 1;
|
|
|
|
} // End of down
|
|
|
|
if ((p & PAD_BUTTON_UP) || (a > PADCAL))
|
2008-08-07 05:25:02 +02:00
|
|
|
{
|
2008-10-16 03:48:08 +02:00
|
|
|
selection--;
|
|
|
|
if (selection < 0)
|
|
|
|
{
|
|
|
|
selection = maxfiles - 1;
|
|
|
|
offset = selection - PAGESIZE + 1;
|
|
|
|
}
|
|
|
|
if (selection < offset)
|
|
|
|
offset -= PAGESIZE;
|
|
|
|
if (offset < 0)
|
|
|
|
offset = 0;
|
|
|
|
redraw = 1;
|
|
|
|
} // End of Up
|
|
|
|
if (PAD_ButtonsHeld (0) & PAD_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-10-16 03:48:08 +02:00
|
|
|
if (PAD_ButtonsHeld (0) & PAD_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-10-16 03:48:08 +02:00
|
|
|
/**
|
2008-08-06 03:09:59 +02:00
|
|
|
* OpenDVD
|
|
|
|
*
|
|
|
|
* Function to load a DVD directory and display to user.
|
2008-10-16 03:48:08 +02:00
|
|
|
*/
|
2008-08-06 03:09:59 +02:00
|
|
|
int
|
2008-10-16 03:48:08 +02:00
|
|
|
OpenDVD ()
|
2008-08-06 03:09:59 +02:00
|
|
|
{
|
2008-10-16 03:48:08 +02:00
|
|
|
int romsdiroffset = 0;
|
|
|
|
|
|
|
|
loadtype = LOAD_DVD;
|
|
|
|
|
|
|
|
if (!getpvd())
|
|
|
|
{
|
|
|
|
ShowAction("Mounting DVD ... Wait");
|
|
|
|
DVD_Mount(); /* mount the DVD unit again */
|
|
|
|
havedir = 0; /* this may be a new DVD: content need to be parsed again */
|
|
|
|
if (!getpvd())
|
|
|
|
return 0; /* no correct ISO9660 DVD */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (havedir == 0)
|
|
|
|
{
|
|
|
|
offset = selection = 0; /* reset file selector */
|
|
|
|
haveSDdir = 0; /* prevent conflicts with SDCARD file selector */
|
|
|
|
|
|
|
|
if ((maxfiles = parsedirectory ()))
|
|
|
|
{
|
|
|
|
if ( romsdiroffset = SNESROMSOffset() )
|
|
|
|
{
|
|
|
|
rootdir = filelist[romsdiroffset].offset;
|
|
|
|
rootdirlength = filelist[romsdiroffset].length;
|
|
|
|
offset = selection = 0;
|
|
|
|
maxfiles = parsedirectory ();
|
|
|
|
}
|
|
|
|
|
|
|
|
int ret = FileSelector ();
|
|
|
|
havedir = 1;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
return FileSelector ();
|
|
|
|
|
|
|
|
return 0;
|
2008-08-06 03:09:59 +02:00
|
|
|
}
|
|
|
|
|
2008-10-16 03:48:08 +02:00
|
|
|
/**
|
2008-08-06 03:09:59 +02:00
|
|
|
* OpenSMB
|
|
|
|
*
|
|
|
|
* Function to load from an SMB share
|
2008-10-16 03:48:08 +02:00
|
|
|
*/
|
2008-08-06 03:09:59 +02:00
|
|
|
int
|
2008-10-16 03:48:08 +02:00
|
|
|
OpenSMB ()
|
2008-08-06 03:09:59 +02:00
|
|
|
{
|
2008-10-16 03:48:08 +02:00
|
|
|
loadtype = LOAD_SMB;
|
|
|
|
|
|
|
|
if ((maxfiles = parseSMBDirectory ()))
|
|
|
|
{
|
|
|
|
char txt[80];
|
|
|
|
sprintf(txt,"maxfiles = %d", maxfiles);
|
|
|
|
|
|
|
|
return FileSelector ();
|
|
|
|
}
|
|
|
|
return 0;
|
2008-08-06 04:31:44 +02:00
|
|
|
}
|
|
|
|
|
2008-10-16 03:48:08 +02:00
|
|
|
/**
|
|
|
|
* OpenSD
|
2008-08-07 05:25:02 +02:00
|
|
|
*
|
2008-10-16 03:48:08 +02:00
|
|
|
* Function to load from an SD Card
|
|
|
|
*/
|
2008-08-07 05:25:02 +02:00
|
|
|
int
|
2008-10-16 03:48:08 +02:00
|
|
|
OpenSD (int slot)
|
2008-08-07 05:25:02 +02:00
|
|
|
{
|
2008-10-16 03:48:08 +02:00
|
|
|
char msg[80];
|
|
|
|
|
|
|
|
loadtype = LOAD_SDC;
|
|
|
|
|
|
|
|
if (haveSDdir == 0)
|
|
|
|
{
|
|
|
|
/* don't mess with DVD entries */
|
|
|
|
havedir = 0;
|
|
|
|
|
|
|
|
/* Initialise libOGC SD functions */
|
|
|
|
SDCARD_Init ();
|
|
|
|
|
|
|
|
/* Reset SDCARD root directory */
|
|
|
|
sprintf(rootSDdir,"dev%d:\\SNESROMS", slot);
|
|
|
|
|
|
|
|
/* Parse initial root directory and get entries list */
|
|
|
|
if ((maxfiles = parseSDdirectory ()))
|
|
|
|
{
|
|
|
|
/* Select an entry */
|
|
|
|
return FileSelector ();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* no entries found */
|
|
|
|
sprintf (msg, "SNESROMS not found on SDCARD (slot %s)", slot ? "B" : "A");
|
|
|
|
WaitPrompt (msg);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Retrieve previous entries list and made a new selection */
|
|
|
|
else
|
|
|
|
return FileSelector ();
|
|
|
|
|
|
|
|
return 0;
|
2008-08-06 04:31:44 +02:00
|
|
|
}
|
|
|
|
|
2008-08-07 05:25:02 +02:00
|
|
|
|
2008-10-16 03:48:08 +02:00
|
|
|
/**
|
|
|
|
* LoadDVDFile
|
|
|
|
*
|
|
|
|
* This function will load a file from DVD, in BIN, SMD or ZIP format.
|
|
|
|
* The values for offset and length are inherited from rootdir and
|
|
|
|
* rootdirlength.
|
|
|
|
*
|
|
|
|
* The buffer parameter should re-use the initial ROM buffer.
|
|
|
|
*/
|
2008-08-06 03:09:59 +02:00
|
|
|
int
|
2008-10-16 03:48:08 +02:00
|
|
|
LoadDVDFile (unsigned char *buffer)
|
2008-08-06 03:09:59 +02:00
|
|
|
{
|
2008-10-16 03:48:08 +02:00
|
|
|
int offset;
|
|
|
|
int blocks;
|
|
|
|
int i;
|
|
|
|
u64 discoffset;
|
|
|
|
char readbuffer[2048];
|
|
|
|
|
|
|
|
/*** SDCard Addition ***/
|
|
|
|
if (rootdirlength == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*** How many 2k blocks to read ***/
|
|
|
|
blocks = rootdirlength / 2048;
|
|
|
|
offset = 0;
|
|
|
|
discoffset = rootdir;
|
|
|
|
ShowAction ("Loading ... Wait");
|
|
|
|
dvd_read (readbuffer, 2048, discoffset);
|
|
|
|
|
|
|
|
if (!IsZipFile (readbuffer))
|
|
|
|
|
|
|
|
{
|
|
|
|
for (i = 0; i < blocks; i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
dvd_read (readbuffer, 2048, discoffset);
|
|
|
|
memcpy (buffer + offset, readbuffer, 2048);
|
|
|
|
offset += 2048;
|
|
|
|
discoffset += 2048;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*** And final cleanup ***/
|
|
|
|
if (rootdirlength % 2048)
|
|
|
|
|
|
|
|
{
|
|
|
|
i = rootdirlength % 2048;
|
|
|
|
dvd_read (readbuffer, 2048, discoffset);
|
|
|
|
memcpy (buffer + offset, readbuffer, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
return UnZipBuffer (buffer, discoffset, rootdirlength);
|
|
|
|
}
|
|
|
|
return rootdirlength;
|
2008-08-06 03:09:59 +02:00
|
|
|
}
|