-Save/Load preferences are now on Preferences menu

-Save/Load Method set to Auto - will automatically determine method (NOT YET IMPLEMENTED - defaults to SD for the moment)
-All ROM, SRAM, Freeze, and preferences are saved/loaded according to these preferences
-new cheats menu! Loads .CHT file from /cheats folder, must match file name of ROM
-combined SRAM / Freeze Managers into new "Game Option" menu
-SRAM / Freeze - game (re)loaded automatically after loading a SRAM or Freeze from Game Options
-SRAM load/save defaults to ON
-Game Options, Return to Game, Reload Game do not show up until a game has been loaded
-added ROM Information page to Game Option menu
-licence/credits moved to Credits page
-menu code tweaks
-USB support
-added future support for Wii DVD / Network loading
-MultiTap & SuperScope moved to controller configuration
-combined/rewrote SRAM/preferences/freeze code - this is now much cleaner and less repetitve - a few steps closer to being workable
-a lot of function parameters have been changed and standardized
-if preferences can't be loaded at the start and/or are reset, preferences menu pops up
-if Home button is pressed when a game is running, Game Menu pops up
-a bunch of misc. bug fixes
-probably some more things
This commit is contained in:
dborth 2008-08-07 03:25:02 +00:00
parent 1478cee2a3
commit 17d6488545
23 changed files with 2096 additions and 2151 deletions

48
source/ngc/cheatmgr.cpp Normal file
View File

@ -0,0 +1,48 @@
/****************************************************************************
* Snes9x 1.51
*
* Nintendo Wii/Gamecube Port
* Tantric August 2008
*
* cheatmgr.cpp
*
* Cheat handling
****************************************************************************/
#include "snes9xGx.h"
#include "memmap.h"
#include "sdload.h"
#include "cheats.h"
extern SCheatData Cheat;
/****************************************************************************
* SetupCheats
*
* Erases any prexisting cheats, loads cheats from a cheat file
* Called when a ROM is first loaded
****************************************************************************/
void
SetupCheats()
{
S9xInitCheatData ();
S9xDeleteCheats ();
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);
// load cheat file if present
if(strlen(cheatFile) > 0)
{
if(S9xLoadCheatFile (cheatFile))
{
// disable all cheats loaded from the file
for (uint16 i = 0; i < Cheat.num_cheats; i++)
S9xDisableCheat(i);
}
}
}

12
source/ngc/cheatmgr.h Normal file
View File

@ -0,0 +1,12 @@
/****************************************************************************
* Snes9x 1.51
*
* Nintendo Wii/Gamecube Port
* Tantric August 2008
*
* cheatmgr.h
*
* Cheat handling
****************************************************************************/
void SetupCheats();

View File

@ -1,5 +1,5 @@
/**************************************************************************** /****************************************************************************
* Snes9x 1.50 * Snes9x 1.50
* *
* Nintendo Gamecube Filesel - borrowed from GPP * Nintendo Gamecube Filesel - borrowed from GPP
* *
@ -15,7 +15,6 @@
#include <fat.h> #include <fat.h>
#include <sys/dir.h> #include <sys/dir.h>
#include "snes9x.h" #include "snes9x.h"
#include "memmap.h" #include "memmap.h"
#include "debug.h" #include "debug.h"
@ -44,95 +43,84 @@
int maxfiles; int maxfiles;
int havedir = 0; int havedir = 0;
int hasloaded = 0; int hasloaded = 0;
int loadtype = 0;
int LoadDVDFile (unsigned char *buffer); int LoadDVDFile (unsigned char *buffer);
bool haveSDdir = 0; int haveFATdir = 0;
bool haveUSBdir = 0;
extern unsigned long ARAM_ROMSIZE; extern unsigned long ARAM_ROMSIZE;
extern int screenheight; extern int screenheight;
extern FILEENTRIES filelist[MAXFILES]; extern FILEENTRIES filelist[MAXFILES];
/** /****************************************************************************
* Showfile screen * Auto-determines the load method
* THIS CODE STILL NEEDS WORK
****************************************************************************/
int autoLoadMethod()
{
return METHOD_SD;
}
/****************************************************************************
* Auto-determines the save method
* THIS CODE STILL NEEDS WORK
****************************************************************************/
int autoSaveMethod()
{
return METHOD_SD;
int method = -1;
while(method < 0)
{
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;
}
return method;
}
/****************************************************************************
* StripExt
* *
* Display the file selection to the user * Strips an extension from a filename
*/ ****************************************************************************/
static void
ShowFiles (int offset, int selection)
{
int i, j;
char text[MAXPATHLEN];
int ypos;
int w;
setfontsize(18);
clearscreen ();
ypos = (screenheight - ((PAGESIZE - 1) * 20)) >> 1; void StripExt(char* returnstring, char * inputstring)
if (screenheight == 480)
ypos += 24;
else
ypos += 10;
j = 0;
for (i = offset; i < (offset + PAGESIZE) && (i < maxfiles); i++)
{
if (filelist[i].flags) // if a dir
{
strcpy (text, "[");
strcat (text, filelist[i].displayname);
strcat (text, "]");
}
else
strcpy (text, filelist[i].displayname);
if (j == (selection - offset))
{
/*** Highlighted text entry ***/
for ( w = 0; w < 20; w++ )
DrawLineFast( 30, 610, ( j * 20 ) + (ypos-16) + w, 0x80, 0x80, 0x80 );
setfontcolour (0x00, 0x00, 0xe0);
DrawText (-1, (j * 20) + ypos, text);
setfontcolour (0x00, 0x00, 0x00);
}
else
{
/*** Normal entry ***/
DrawText (-1, (j * 20) + ypos, text);
}
j++;
}
showscreen ();
}
/**
* SNESROMSOffset
*
* Function to check for and return offset to a directory called SNESROMS, if
* any
*/
int SNESROMSOffset()
{
int i;
for ( i = 0; i < maxfiles; i++ )
if (strcmp(filelist[i].filename, "SNESROMS") == 0)
return i;
return 0;
}
void strip_ext(char* inputstring, char* returnstring)
{ {
char* loc_dot; char* loc_dot;
@ -144,40 +132,117 @@ void strip_ext(char* inputstring, char* returnstring)
return; return;
} }
/** /****************************************************************************
* Showfile screen
*
* Display the file selection to the user
****************************************************************************/
static void
ShowFiles (int offset, int selection)
{
int i, j;
char text[MAXPATHLEN];
int ypos;
int w;
clearscreen ();
setfontsize (28);
DrawText (-1, 60, (char*)"Choose Game");
setfontsize(18);
ypos = (screenheight - ((PAGESIZE - 1) * 20)) >> 1;
if (screenheight == 480)
ypos += 24;
else
ypos += 10;
j = 0;
for (i = offset; i < (offset + PAGESIZE) && (i < maxfiles); i++)
{
if (filelist[i].flags) // if a dir
{
strcpy (text, "[");
strcat (text, filelist[i].displayname);
strcat (text, "]");
}
else
{
// hide file extension on listing (.7z, .fig, .smc)
StripExt(text, filelist[i].displayname);
}
if (j == (selection - offset))
{
/*** Highlighted text entry ***/
for ( w = 0; w < 20; w++ )
DrawLineFast( 30, 610, ( j * 20 ) + (ypos-16) + w, 0x80, 0x80, 0x80 );
setfontcolour (0x00, 0x00, 0xe0);
DrawText (50, (j * 20) + ypos, text);
setfontcolour (0x00, 0x00, 0x00);
}
else
{
/*** Normal entry ***/
DrawText (50, (j * 20) + ypos, text);
}
j++;
}
showscreen ();
}
/****************************************************************************
* SNESROMSOffset
*
* Function to check for and return offset to a directory called SNESROMS, if
* any
****************************************************************************/
int SNESROMSOffset()
{
int i;
for ( i = 0; i < maxfiles; i++ )
if (strcmp(filelist[i].filename, "SNESROMS") == 0)
return i;
return 0;
}
/****************************************************************************
* FileSelector * FileSelector
* *
* Let user select a file from the DVD listing * Let user select a file from the listing
*/ ****************************************************************************/
int offset = 0; int offset = 0;
int selection = 0; int selection = 0;
#define PADCAL 40 #define PADCAL 40
int int
FileSelector () FileSelector (int method)
{ {
u32 p, wp, ph, wh; u32 p, wp, ph, wh;
signed char a, c; signed char a, c;
int haverom = 0; int haverom = 0;
int redraw = 1; int redraw = 1;
int selectit = 0; int selectit = 0;
float mag = 0; float mag, mag2 = 0;
float mag2 = 0; u16 ang, ang2 = 0;
u16 ang = 0;
u16 ang2 = 0;
int scroll_delay = 0; int scroll_delay = 0;
bool move_selection = 0; bool move_selection = 0;
#define SCROLL_INITIAL_DELAY 15 #define SCROLL_INITIAL_DELAY 15
#define SCROLL_LOOP_DELAY 4 #define SCROLL_LOOP_DELAY 2
while (haverom == 0) while (haverom == 0)
{ {
if (redraw) if (redraw)
ShowFiles (offset, selection); ShowFiles (offset, selection);
redraw = 0; redraw = 0;
VIDEO_WaitVSync(); // slow things down a bit so we don't overread the pads VIDEO_WaitVSync(); // slow things down a bit so we don't overread the pads
p = PAD_ButtonsDown (0); p = PAD_ButtonsDown (0);
ph = PAD_ButtonsHeld (0); ph = PAD_ButtonsHeld (0);
#ifdef HW_RVL #ifdef HW_RVL
@ -190,10 +255,10 @@ FileSelector ()
#endif #endif
a = PAD_StickY (0); a = PAD_StickY (0);
c = PAD_SubStickX (0); c = PAD_SubStickX (0);
/*** Check for exit combo ***/ /*** Check for exit combo ***/
if ( (c < -70) || (wp & WPAD_BUTTON_HOME) || (wp & WPAD_CLASSIC_BUTTON_HOME) ) return 0; if ( (c < -70) || (wp & WPAD_BUTTON_HOME) || (wp & WPAD_CLASSIC_BUTTON_HOME) ) return 0;
/*** Check buttons, perform actions ***/ /*** Check buttons, perform actions ***/
if ( (p & PAD_BUTTON_A) || selectit || (wp & (WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A)) ) if ( (p & PAD_BUTTON_A) || selectit || (wp & (WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A)) )
{ {
@ -201,36 +266,27 @@ FileSelector ()
selectit = 0; selectit = 0;
if (filelist[selection].flags) /*** This is directory ***/ if (filelist[selection].flags) /*** This is directory ***/
{ {
if (loadtype == LOAD_SDC || loadtype == LOAD_USB) if (method == METHOD_SD || method == METHOD_USB)
{ {
/* memorize last entries list, actual root directory and selection for next access */ /* memorize last entries list, actual root directory and selection for next access */
if (loadtype == LOAD_SDC) haveFATdir = 1;
haveSDdir = 1;
else
haveUSBdir = 1;
/* update current directory and set new entry list if directory has changed */ /* update current directory and set new entry list if directory has changed */
int status = updateFATdirname(); int status = updateFATdirname(method);
if (status == 1) // ok, open directory if (status == 1) // ok, open directory
{ {
maxfiles = parseFATdirectory(); maxfiles = parseFATdirectory(method);
if (!maxfiles) if (!maxfiles)
{ {
WaitPrompt ((char*) "Error reading directory !"); WaitPrompt ((char*) "Error reading directory !");
haverom = 1; // quit SD menu haverom = 1; // quit FAT menu
if (loadtype == LOAD_SDC) // reset everything at next access haveFATdir = 0; // reset everything at next access
haveSDdir = 0;
else
haveUSBdir = 0;
} }
} }
else if (status == -1) // directory name too long else if (status == -1) // directory name too long
{ {
haverom = 1; // quit SD menu haverom = 1; // quit FAT menu
if (loadtype == LOAD_SDC) // reset everything at next access haveFATdir = 0; // reset everything at next access
haveSDdir = 0;
else
haveUSBdir = 0;
} }
} }
else else
@ -249,43 +305,44 @@ FileSelector ()
} }
else // this is a file else // this is a file
{ {
rootdir = filelist[selection].offset; rootdir = filelist[selection].offset;
rootdirlength = filelist[selection].length; rootdirlength = filelist[selection].length;
/*** store the filename (used for sram/freeze naming) ***/ // store the filename (used for sram/freeze naming)
strip_ext(filelist[selection].filename, Memory.ROMFilename); // store stripped filename in Memory.ROMFilename StripExt(Memory.ROMFilename, filelist[selection].filename); // store stripped filename in Memory.ROMFilename
switch (loadtype) switch (method)
{ {
case LOAD_DVD: case METHOD_SD:
case METHOD_USB:
/*** Load from FAT ***/
/* memorize last entries list, actual root directory and selection for next access */
haveFATdir = 1;
ARAM_ROMSIZE = LoadFATFile (filelist[selection].filename,
filelist[selection].length);
break;
case METHOD_DVD:
/*** Now load the DVD file to it's offset ***/ /*** Now load the DVD file to it's offset ***/
ARAM_ROMSIZE = LoadDVDFile (Memory.ROM); ARAM_ROMSIZE = LoadDVDFile (Memory.ROM);
break; break;
case LOAD_SMB: case METHOD_SMB:
/*** Load from SMB ***/ /*** Load from SMB ***/
ARAM_ROMSIZE = LoadSMBFile (filelist[selection].filename, ARAM_ROMSIZE =
LoadSMBFile (filelist[selection].filename,
filelist[selection].length); filelist[selection].length);
break;
case LOAD_USB:
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; break;
} }
if (ARAM_ROMSIZE > 0) if (ARAM_ROMSIZE > 0)
{ {
hasloaded = 1; hasloaded = 1;
Memory.LoadROM ("BLANK.SMC"); Memory.LoadROM ("BLANK.SMC");
Memory.LoadSRAM ("BLANK"); Memory.LoadSRAM ("BLANK");
haverom = 1; haverom = 1;
return 1; return 1;
} }
else else
@ -297,19 +354,19 @@ FileSelector ()
} // End of A } // End of A
if ( (p & PAD_BUTTON_B) || (wp & (WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B)) ) if ( (p & PAD_BUTTON_B) || (wp & (WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B)) )
{ {
while ( (PAD_ButtonsDown(0) & PAD_BUTTON_B) while ( (PAD_ButtonsDown(0) & PAD_BUTTON_B)
#ifdef HW_RVL #ifdef HW_RVL
|| (WPAD_ButtonsDown(0) & (WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B)) || (WPAD_ButtonsDown(0) & (WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B))
#endif #endif
) )
VIDEO_WaitVSync(); VIDEO_WaitVSync();
//if ((strcmp(filelist[1].filename,"..") == 0) && (strlen (filelist[0].filename) != 0)) //if ((strcmp(filelist[1].filename,"..") == 0) && (strlen (filelist[0].filename) != 0))
if ( strcmp(filelist[0].filename,"..") == 0 ) if ( strcmp(filelist[0].filename,"..") == 0 )
{ {
selection = 0; selection = 0;
selectit = 1; selectit = 1;
} }
else if ( strcmp(filelist[1].filename,"..") == 0 ) else if ( strcmp(filelist[1].filename,"..") == 0 )
{ {
selection = selectit = 1; selection = selectit = 1;
} else { } else {
@ -321,14 +378,14 @@ FileSelector ()
if ( (p & PAD_BUTTON_DOWN) || (wp & (WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN)) ) { /*** Button just pressed ***/ if ( (p & PAD_BUTTON_DOWN) || (wp & (WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN)) ) { /*** Button just pressed ***/
scroll_delay = SCROLL_INITIAL_DELAY; // reset scroll delay. scroll_delay = SCROLL_INITIAL_DELAY; // reset scroll delay.
move_selection = 1; //continue (move selection) move_selection = 1; //continue (move selection)
} }
else if (scroll_delay == 0) { /*** Button is held ***/ else if (scroll_delay == 0) { /*** Button is held ***/
scroll_delay = SCROLL_LOOP_DELAY; scroll_delay = SCROLL_LOOP_DELAY;
move_selection = 1; //continue (move selection) move_selection = 1; //continue (move selection)
} else { } else {
scroll_delay--; // wait scroll_delay--; // wait
} }
if (move_selection) if (move_selection)
{ {
selection++; selection++;
@ -341,18 +398,18 @@ FileSelector ()
} }
} // End of down } // End of down
if ( ((p | ph) & PAD_BUTTON_UP) || ((wp | wh) & (WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP)) || (a > PADCAL) || (mag>JOY_THRESHOLD && (ang>300 || ang<50)) ) if ( ((p | ph) & PAD_BUTTON_UP) || ((wp | wh) & (WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP)) || (a > PADCAL) || (mag>JOY_THRESHOLD && (ang>300 || ang<50)) )
{ {
if ( (p & PAD_BUTTON_UP) || (wp & (WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP)) ) { /*** Button just pressed***/ if ( (p & PAD_BUTTON_UP) || (wp & (WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP)) ) { /*** Button just pressed***/
scroll_delay = SCROLL_INITIAL_DELAY; // reset scroll delay. scroll_delay = SCROLL_INITIAL_DELAY; // reset scroll delay.
move_selection = 1; //continue (move selection) move_selection = 1; //continue (move selection)
} }
else if (scroll_delay == 0) { /*** Button is held ***/ else if (scroll_delay == 0) { /*** Button is held ***/
scroll_delay = SCROLL_LOOP_DELAY; scroll_delay = SCROLL_LOOP_DELAY;
move_selection = 1; //continue (move selection) move_selection = 1; //continue (move selection)
} else { } else {
scroll_delay--; // wait scroll_delay--; // wait
} }
if (move_selection) if (move_selection)
{ {
selection--; selection--;
@ -397,18 +454,16 @@ FileSelector ()
return 0; return 0;
} }
/** /****************************************************************************
* OpenDVD * OpenDVD
* *
* Function to load a DVD directory and display to user. * Function to load a DVD directory and display to user.
*/ ****************************************************************************/
int int
OpenDVD () OpenDVD (int method)
{ {
int romsdiroffset = 0; int romsdiroffset = 0;
loadtype = LOAD_DVD;
if (!getpvd()) if (!getpvd())
{ {
ShowAction((char*) "Mounting DVD ... Wait"); ShowAction((char*) "Mounting DVD ... Wait");
@ -417,13 +472,12 @@ OpenDVD ()
if (!getpvd()) if (!getpvd())
return 0; /* no correct ISO9660 DVD */ return 0; /* no correct ISO9660 DVD */
} }
if (havedir == 0) if (havedir == 0)
{ {
offset = selection = 0; /* reset file selector */ offset = selection = 0; /* reset file selector */
haveSDdir = 0; /* prevent conflicts with SDCARD, USB file selector */ haveFATdir = 0; /* prevent conflicts with FAT file selector */
haveUSBdir = 0;
if ((maxfiles = parsedirectory ())) if ((maxfiles = parsedirectory ()))
{ {
if ( romsdiroffset = SNESROMSOffset() ) if ( romsdiroffset = SNESROMSOffset() )
@ -433,210 +487,120 @@ OpenDVD ()
offset = selection = 0; offset = selection = 0;
maxfiles = parsedirectory (); maxfiles = parsedirectory ();
} }
int ret = FileSelector (); int ret = FileSelector (method);
havedir = 1; havedir = 1;
return ret; return ret;
} }
} }
else else
return FileSelector (); return FileSelector (method);
return 0; return 0;
} }
/** /****************************************************************************
* OpenSMB * OpenSMB
* *
* Function to load from an SMB share * Function to load from an SMB share
*/ ****************************************************************************/
int int
OpenSMB () OpenSMB (int method)
{ {
loadtype = LOAD_SMB; if ((maxfiles = parseSMBDirectory ()))
if ((maxfiles = parseSMBDirectory ()))
{ {
char txt[80]; char txt[80];
sprintf(txt,"maxfiles = %d", maxfiles); sprintf(txt,"maxfiles = %d", maxfiles);
return FileSelector (); return FileSelector (method);
} }
return 0; return 0;
} }
/****************************************************************************
* OpenFAT
*
* Function to load from FAT
****************************************************************************/
int
OpenFAT (int method)
{
char msg[80];
//if (haveFATdir == 0)
//{
/* don't mess with DVD entries */
havedir = 0; // gamecube only
// is_mounted /* change current dir to snes roms directory */
// if(method == METHOD_SD)
// to check whether FAT media are detected. sprintf ( currFATdir, "%s/%s", ROOTSDDIR, GCSettings.LoadFolder );
bool fat_is_mounted(PARTITION_INTERFACE partition) { else
char prefix[] = "fatX:/"; sprintf ( currFATdir, "%s/%s", ROOTUSBDIR, GCSettings.LoadFolder );
prefix[3] = partition + '0';
DIR_ITER *dir = diropen(prefix);
if (dir) {
dirclose(dir);
return true;
}
return false;
}
void fat_enable_readahead_all() { /* Parse initial root directory and get entries list */
int i; if ((maxfiles = parseFATdirectory (method)))
for (i=1; i <= 4; ++i) {
if (fat_is_mounted((PARTITION_INTERFACE)i)) fatEnableReadAhead((PARTITION_INTERFACE)i, 64, 128);
}
}
bool fat_remount(PARTITION_INTERFACE partition) {
//ShowAction("remounting...");
/* // removed to make usb work...
if (fat_is_mounted(partition))
{ {
fatUnmount(partition); /* Select an entry */
return FileSelector (method);
} }
*/ else
fatMountNormalInterface(partition, 8);
fatSetDefaultInterface(partition);
//fatEnableReadAhead(partition, 64, 128);
if (fat_is_mounted(partition))
{ {
//ShowAction("remount successful."); /* no entries found */
sleep(1); sprintf (msg, "No Files Found!");
return 1; WaitPrompt (msg);
} else {
ShowAction("FAT mount failed.");
sleep(1);
return 0; return 0;
} }
//}
/* Retrieve previous entries list and made a new selection */
//else
// return FileSelector (method);
return 0;
} }
/** /****************************************************************************
* OpenSD * OpenROM
* * Opens device specified by method, displays a list of ROMS
* Function to load from an SD Card ****************************************************************************/
*/
int int
OpenSD () OpenROM (int method)
{ {
char msg[80]; int loadROM = 0;
char buf[50] = "";
loadtype = LOAD_SDC;
/* if(method == METHOD_AUTO)
fatUnmount(PI_INTERNAL_SD); method = autoLoadMethod();
fatMountNormalInterface(PI_INTERNAL_SD,8);
//fatEnableReadAhead(PI_INTERNAL_SD, 64, 128); switch (method)
fatSetDefaultInterface(PI_INTERNAL_SD); {
//chdir("fat0:/"); case METHOD_SD:
*/ case METHOD_USB:
#ifdef HW_RVL loadROM = OpenFAT (method);
// only remount on wii break;
if (!fat_remount (PI_INTERNAL_SD)) case METHOD_DVD:
return 0; // Load from DVD
#endif loadROM = OpenDVD (method);
break;
if (haveSDdir == 0) case METHOD_SMB:
{ // Load from Network (SMB)
/* don't mess with DVD entries */ loadROM = OpenSMB (method);
havedir = 0; break;
haveUSBdir = 0; }
/* change current dir to snes roms directory */ return loadROM;
sprintf ( currSDdir, "%s/%s", ROOTSDDIR, SNESROMDIR );
/* Parse initial root directory and get entries list */
if ((maxfiles = parseFATdirectory ()))
{
/* Select an entry */
return FileSelector ();
}
else
{
/* no entries found */
sprintf (msg, "No Files Found!");
WaitPrompt (msg);
return 0;
}
}
/* Retrieve previous entries list and made a new selection */
else
return FileSelector ();
return 0;
} }
/** /****************************************************************************
* OpenUSB
*
* Function to load from a USB device (wii only)
*/
int
OpenUSB ()
{
char msg[80];
char buf[50] = "";
/*
//fatUnmount(PI_USBSTORAGE);
fatUnmount(PI_INTERNAL_SD);
//if(!fatMountNormalInterface(PI_USBSTORAGE,8))
// return 0;
//fatEnableReadAhead(PI_USBSTORAGE, 64, 128);
fatSetDefaultInterface(PI_USBSTORAGE);
*/
#ifdef HW_RVL
// make compiler happy
if (!fat_remount (PI_USBSTORAGE))
return 0;
#endif
loadtype = LOAD_USB;
if (haveUSBdir == 0)
{
/* don't mess with DVD, SDCARD entries */
havedir = 0;
haveSDdir = 0;
/* change current dir to snes roms directory */
sprintf ( currSDdir, "%s/%s", ROOTSDDIR, SNESROMDIR );
/* Parse initial root directory and get entries list */
if ((maxfiles = parseFATdirectory ()))
{
/* Select an entry */
return FileSelector ();
}
else
{
/* no entries found */
sprintf (msg, "No Files Found!");
WaitPrompt (msg);
return 0;
}
}
/* Retrieve previous entries list and made a new selection */
else
return FileSelector ();
return 0;
}
/**
* LoadDVDFile * LoadDVDFile
*
* This function will load a file from DVD, in BIN, SMD or ZIP format. * 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 * The values for offset and length are inherited from rootdir and
* rootdirlength. * rootdirlength.
* *
* The buffer parameter should re-use the initial ROM buffer. * The buffer parameter should re-use the initial ROM buffer.
*/ ****************************************************************************/
int int
LoadDVDFile (unsigned char *buffer) LoadDVDFile (unsigned char *buffer)
{ {

View File

@ -1,5 +1,5 @@
/**************************************************************************** /****************************************************************************
* Snes9x 1.50 * Snes9x 1.50
* *
* Nintendo Gamecube Filesel - borrowed from GPP * Nintendo Gamecube Filesel - borrowed from GPP
* *
@ -10,17 +10,8 @@
#ifndef _NGCFILESEL_ #ifndef _NGCFILESEL_
#define _NGCFILESEL_ #define _NGCFILESEL_
int OpenDVD (); int OpenROM (int method);
int OpenSMB (); int autoLoadMethod();
int OpenSD (); int autoSaveMethod();
int OpenUSB ();
#define LOAD_DVD 1
#define LOAD_SMB 2
#define LOAD_SDC 4
#define LOAD_USB 8
#define ROOTSDDIR "fat3:/"
#define SNESROMDIR "snes9x/roms"
#define SNESSAVEDIR "snes9x/saves"
#endif #endif

View File

@ -1,5 +1,5 @@
/**************************************************************************** /****************************************************************************
* Snes9x 1.50 * Snes9x 1.50
* *
* Nintendo Gamecube Screen Font Driver * Nintendo Gamecube Screen Font Driver
* *
@ -31,6 +31,7 @@
#include "dkpro.h" #include "dkpro.h"
#include "snes9xGX.h" #include "snes9xGX.h"
#include "memmap.h"
#include "aram.h" #include "aram.h"
#include <zlib.h> #include <zlib.h>
@ -49,24 +50,23 @@ extern int screenheight;
extern unsigned int *xfb[2]; extern unsigned int *xfb[2];
extern int whichfb; extern int whichfb;
/** /****************************************************************************
* Unpack the devkit pro logo * Unpack the devkit pro logo
*/ ****************************************************************************/
static u32 *dkproraw; static u32 *dkproraw;
/*** Permanent backdrop ***/ /*** Permanent backdrop ***/
#ifdef HW_RVL #ifdef HW_RVL
u32 *backdrop; u32 *backdrop;
#else #else
static u32 *backdrop; static u32 *backdrop;
#endif #endif
static void unpackbackdrop ();
unsigned int getcolour (u8 r1, u8 g1, u8 b1); unsigned int getcolour (u8 r1, u8 g1, u8 b1);
void DrawLineFast( int startx, int endx, int y, u8 r, u8 g, u8 b ); void DrawLineFast( int startx, int endx, int y, u8 r, u8 g, u8 b );
u32 getrgb( u32 ycbr, u32 low ); u32 getrgb( u32 ycbr, u32 low );
/** /****************************************************************************
* Initialisation of libfreetype * Initialisation of libfreetype
*/ ****************************************************************************/
int int
FT_Init () FT_Init ()
{ {
@ -91,11 +91,11 @@ FT_Init ()
} }
/** /****************************************************************************
* setfontsize * setfontsize
* *
* Set the screen font size in pixels * Set the screen font size in pixels
*/ ****************************************************************************/
void void
setfontsize (int pixelsize) setfontsize (int pixelsize)
{ {
@ -107,6 +107,10 @@ setfontsize (int pixelsize)
printf ("Error setting pixel sizes!"); printf ("Error setting pixel sizes!");
} }
/****************************************************************************
* DrawCharacter
* Draws a single character on the screen
****************************************************************************/
static void static void
DrawCharacter (FT_Bitmap * bmp, FT_Int x, FT_Int y) DrawCharacter (FT_Bitmap * bmp, FT_Int x, FT_Int y)
{ {
@ -144,11 +148,11 @@ DrawCharacter (FT_Bitmap * bmp, FT_Int x, FT_Int y)
} }
} }
/** /****************************************************************************
* DrawText * DrawText
* *
* Place the font bitmap on the screen * Place the font bitmap on the screen
*/ ****************************************************************************/
void void
DrawText (int x, int y, char *text) DrawText (int x, int y, char *text)
{ {
@ -161,6 +165,8 @@ DrawText (int x, int y, char *text)
if (n == 0) if (n == 0)
return; return;
setfontcolour (0x00, 0x00, 0x00);
/*** x == -1, auto centre ***/ /*** x == -1, auto centre ***/
if (x == -1) if (x == -1)
{ {
@ -198,11 +204,11 @@ DrawText (int x, int y, char *text)
} }
} }
/** /****************************************************************************
* setfontcolour * setfontcolour
* *
* Uses RGB triple values. * Uses RGB triple values.
*/ ****************************************************************************/
void void
setfontcolour (u8 r, u8 g, u8 b) setfontcolour (u8 r, u8 g, u8 b)
{ {
@ -213,47 +219,11 @@ setfontcolour (u8 r, u8 g, u8 b)
fontlo = fontcolour & 0xffff; fontlo = fontcolour & 0xffff;
} }
/** /****************************************************************************
* Licence Information
*
* THIS MUST NOT BE REMOVED IN ANY DERIVATIVE WORK.
*/
void
licence ()
{
int ypos = ((screenheight - (282 + dkpro_HEIGHT)) >> 1);
if (screenheight == 480)
ypos += 42;
else
ypos += 24;
setfontsize (16);
setfontcolour (0x00, 0x00, 0x00);
DrawText (-1, ypos += 40, (char*)"Snes9x - Copyright (c) Snes9x Team 1996 - 2006");
DrawText (-1, ypos += 40, (char*)"This is free software, and you are welcome to");
DrawText (-1, ypos += 20, (char*)"redistribute it under the conditions of the");
DrawText (-1, ypos += 20, (char*)"GNU GENERAL PUBLIC LICENSE Version 2");
DrawText (-1, ypos +=
20, (char*)"Additionally, the developers of this port disclaim");
DrawText (-1, ypos +=
20, (char*)"all copyright interests in the Nintendo GameCube");
DrawText (-1, ypos +=
20, (char*)"porting code. You are free to use it as you wish");
DrawText (-1, ypos += 40, (char*)"Developed with DevkitPPC and libOGC");
DrawText (-1, ypos += 20, (char*)"http://www.devkitpro.org");
}
/**
* dkunpack * dkunpack
* *
* Support function to expand the DevkitPro logo * Support function to expand the DevkitPro logo
*/ ****************************************************************************/
int int
dkunpack () dkunpack ()
{ {
@ -271,11 +241,11 @@ dkunpack ()
return 0; return 0;
} }
/** /****************************************************************************
* showdklogo * showdklogo
* *
* Display the DevkitPro logo * Display the DevkitPro logo
*/ ****************************************************************************/
void void
showdklogo () showdklogo ()
{ {
@ -302,13 +272,69 @@ showdklogo ()
free (dkproraw); free (dkproraw);
} }
/** /****************************************************************************
* Display credits, legal copyright and licence
*
* THIS MUST NOT BE REMOVED IN ANY DERIVATIVE WORK.
****************************************************************************/
void
Credits ()
{
clearscreen ();
setfontcolour (0x00, 0x00, 0x00);
setfontsize (28);
DrawText (-1, 60, (char*)"Credits");
int ypos = 25;
if (screenheight == 480)
ypos += 52;
else
ypos += 32;
setfontsize (18);
DrawText (-1, ypos += 30, (char*)"Technical");
setfontsize (14);
DrawText (-1, ypos += 22, (char*)"Snes9x v1.5.1 - Snes9x Team");
DrawText (-1, ypos += 18, (char*)"GameCube Port 2.0 WIP6 and earlier - SoftDev");
DrawText (-1, ypos += 18, (char*)"Additional improvements to 2.0 WIP6 - eke-eke");
DrawText (-1, ypos += 18, (char*)"GameCube 2.0.1bx enhancements - crunchy2");
DrawText (-1, ypos += 18, (char*)"v00x updates - michniewski & Tantric");
DrawText (-1, ypos += 18, (char*)"GX - http://www.gc-linux.org");
DrawText (-1, ypos += 18, (char*)"libogc - Shagkur & wintermute");
setfontsize (18);
DrawText (-1, ypos += 30, (char*)"Testing");
setfontsize (14);
DrawText (-1, ypos += 22, (char*)"crunchy2 / tehskeen users / others");
setfontsize (18);
DrawText (-1, ypos += 30, (char*)"Documentation");
setfontsize (14);
DrawText (-1, ypos += 22, (char*)"brakken, crunchy2, michniewski");
setfontsize (12);
DrawText (-1, ypos += 50, (char*)"Snes9x - Copyright (c) Snes9x Team 1996 - 2006");
DrawText (-1, ypos += 15, (char*)"This software is open source and may be copied, distributed, or modified");
DrawText (-1, ypos += 15, (char*)"under the terms of the GNU General Public License (GPL) Version 2.");
showscreen ();
}
/****************************************************************************
* getcolour * getcolour
* *
* Simply converts RGB to Y1CbY2Cr format * Simply converts RGB to Y1CbY2Cr format
* *
* I got this from a pastebin, so thanks to whoever originally wrote it! * I got this from a pastebin, so thanks to whoever originally wrote it!
*/ ****************************************************************************/
unsigned int unsigned int
getcolour (u8 r1, u8 g1, u8 b1) getcolour (u8 r1, u8 g1, u8 b1)
@ -334,9 +360,9 @@ getcolour (u8 r1, u8 g1, u8 b1)
return ((y1 << 24) | (cb << 16) | (y2 << 8) | cr); return ((y1 << 24) | (cb << 16) | (y2 << 8) | cr);
} }
/** /****************************************************************************
* Unpackbackdrop * Unpackbackdrop
*/ ****************************************************************************/
void void
unpackbackdrop () unpackbackdrop ()
{ {
@ -371,22 +397,9 @@ unpackbackdrop ()
} }
/** /****************************************************************************
* Display legal copyright and licence
*/
void
legal ()
{
unpackbackdrop ();
clearscreen ();
licence ();
showdklogo ();
showscreen ();
}
/**
* Wait for user to press A * Wait for user to press A
*/ ****************************************************************************/
void void
WaitButtonA () WaitButtonA ()
{ {
@ -399,20 +412,20 @@ WaitButtonA ()
#endif #endif
} }
/** /****************************************************************************
* Wait for user to press A or B. Returns 0 = B; 1 = A * Wait for user to press A or B. Returns 0 = B; 1 = A
*/ ****************************************************************************/
int int
WaitButtonAB () WaitButtonAB ()
{ {
#ifdef HW_RVL #ifdef HW_RVL
u32 gc_btns, wm_btns; u32 gc_btns, wm_btns;
while ( (PAD_ButtonsDown (0) & (PAD_BUTTON_A | PAD_BUTTON_B)) while ( (PAD_ButtonsDown (0) & (PAD_BUTTON_A | PAD_BUTTON_B))
|| (WPAD_ButtonsDown(0) & (WPAD_BUTTON_A | WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_A | WPAD_CLASSIC_BUTTON_B)) || (WPAD_ButtonsDown(0) & (WPAD_BUTTON_A | WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_A | WPAD_CLASSIC_BUTTON_B))
) VIDEO_WaitVSync(); ) VIDEO_WaitVSync();
while ( TRUE ) while ( TRUE )
{ {
gc_btns = PAD_ButtonsDown (0); gc_btns = PAD_ButtonsDown (0);
@ -424,9 +437,9 @@ WaitButtonAB ()
} }
#else #else
u32 gc_btns; u32 gc_btns;
while ( (PAD_ButtonsDown (0) & (PAD_BUTTON_A | PAD_BUTTON_B)) ) VIDEO_WaitVSync(); while ( (PAD_ButtonsDown (0) & (PAD_BUTTON_A | PAD_BUTTON_B)) ) VIDEO_WaitVSync();
while ( TRUE ) while ( TRUE )
{ {
gc_btns = PAD_ButtonsDown (0); gc_btns = PAD_ButtonsDown (0);
@ -438,9 +451,9 @@ WaitButtonAB ()
#endif #endif
} }
/** /****************************************************************************
* Show a prompt * Show a prompt
*/ ****************************************************************************/
void void
WaitPrompt (char *msg) WaitPrompt (char *msg)
{ {
@ -459,10 +472,10 @@ WaitPrompt (char *msg)
WaitButtonA (); WaitButtonA ();
} }
/** /****************************************************************************
* Show a prompt with choice of two options. Returns 1 if A button was pressed * Show a prompt with choice of two options. Returns 1 if A button was pressed
and 0 if B button was pressed. and 0 if B button was pressed.
*/ ****************************************************************************/
int int
WaitPromptChoice (char *msg, char *bmsg, char *amsg) WaitPromptChoice (char *msg, char *bmsg, char *amsg)
{ {
@ -483,9 +496,9 @@ WaitPromptChoice (char *msg, char *bmsg, char *amsg)
return WaitButtonAB (); return WaitButtonAB ();
} }
/** /****************************************************************************
* Show an action in progress * Show an action in progress
*/ ****************************************************************************/
void void
ShowAction (char *msg) ShowAction (char *msg)
{ {
@ -505,62 +518,81 @@ ShowAction (char *msg)
* Generic Menu Routines * Generic Menu Routines
****************************************************************************/ ****************************************************************************/
void void
DrawMenu (char items[][20], char *title, int maxitems, int selected, int fontsize) DrawMenu (char items[][50], char *title, int maxitems, int selected, int fontsize, int x)
{ {
int i, w; int i, w = 0;
int ypos; int ypos = 0;
int n = 1;
#if 0 ypos = 65;
int bounding[] = { 80, 40, 600, 40, 560, 94, 40, 94 };
int base[] = { 80, screenheight - 90, 600, screenheight - 90,
560, screenheight - 40, 40, screenheight - 40
};
#endif
//ypos = (screenheight - (maxitems * 32)) >> 1; previous if (screenheight == 480)
ypos = (screenheight - (maxitems * (fontsize + 8))) >> 1; ypos += 52;
else
ypos += 32;
if (screenheight == 480) clearscreen ();
ypos += 52;
else
ypos += 32;
clearscreen (); setfontcolour (0, 0, 0);
//#if 0 if (title != NULL)
// DrawPolygon (4, bounding, 0x00, 0x00, 0xc0);
// DrawPolygon (4, base, 0x00, 0x00, 0xc0);
setfontsize (30);
if (title != NULL)
DrawText (-1, 60, title);
setfontsize (12);
DrawText (510, screenheight - 20, "Snes9x GX 004");
//#endif
setfontsize (fontsize); // set font size
setfontcolour (0, 0, 0);
for (i = 0; i < maxitems; i++)
{
if (i == selected)
{ {
//for( w = 0; w < 32; w++ ) setfontsize (28);
for( w = 0; w < (fontsize + 8); w++ ) DrawText (-1, 60, title);
//DrawLineFast( 30, 610, (i << 5) + (ypos-26) + w, 0x80, 0x80, 0x80 ); previous
DrawLineFast( 30, 610, i * (fontsize + 8) + (ypos-(fontsize + 2)) + w, 0x80, 0x80, 0x80 );
setfontcolour (0xff, 0xff, 0xff);
//DrawText (-1, (i << 5) + ypos, items[i]); previous
DrawText (-1, i * (fontsize + 8) + ypos, items[i]);
setfontcolour (0x00, 0x00, 0x00);
} }
else
DrawText (-1, i * (fontsize + 8) + ypos, items[i]);
//DrawText (-1, i * 32 + ypos, items[i]); previous
}
showscreen (); setfontsize (12);
DrawText (510, screenheight - 20, (char *)"Snes9x GX 005");
// Draw menu items
setfontsize (fontsize); // set font size
for (i = 0; i < maxitems; i++)
{
if(strlen(items[i]) > 0)
{
if (i == selected)
{
for( w = 0; w < (fontsize + 8); w++ )
DrawLineFast( 30, 610, n * (fontsize + 8) + (ypos-(fontsize + 2)) + w, 0x80, 0x80, 0x80 );
setfontcolour (0xff, 0xff, 0xff);
DrawText (x, n * (fontsize + 8) + ypos, items[i]);
setfontcolour (0x00, 0x00, 0x00);
}
else
{
DrawText (x, n * (fontsize + 8) + ypos, items[i]);
}
n++;
}
}
showscreen ();
}
/****************************************************************************
* FindMenuItem
*
* Help function to find the next visible menu item on the list
* Supports menu wrap-around
****************************************************************************/
int FindMenuItem(char items[][50], int maxitems, int currentItem, int direction)
{
int nextItem = currentItem + direction;
if(nextItem < 0)
nextItem = maxitems-1;
else if(nextItem >= maxitems)
nextItem = 0;
if(strlen(items[nextItem]) > 0)
return nextItem;
else
return FindMenuItem(&items[0], maxitems, nextItem, direction);
} }
/**************************************************************************** /****************************************************************************
@ -570,8 +602,9 @@ DrawMenu (char items[][20], char *title, int maxitems, int selected, int fontsiz
* It's here to keep all the font / interface stuff together. * It's here to keep all the font / interface stuff together.
****************************************************************************/ ****************************************************************************/
int menu = 0; int menu = 0;
int int
RunMenu (char items[][20], int maxitems, char *title, int fontsize) RunMenu (char items[][50], int maxitems, char *title, int fontsize, int x)
{ {
int redraw = 1; int redraw = 1;
int quit = 0; int quit = 0;
@ -582,8 +615,7 @@ RunMenu (char items[][20], int maxitems, char *title, int fontsize)
float mag2 = 0; float mag2 = 0;
u16 ang = 0; u16 ang = 0;
u16 ang2 = 0; u16 ang2 = 0;
//while (!(PAD_ButtonsDown (0) & PAD_BUTTON_B) && (quit == 0))
while (quit == 0) while (quit == 0)
{ {
if (redraw) if (redraw)
@ -591,7 +623,7 @@ RunMenu (char items[][20], int maxitems, char *title, int fontsize)
DrawMenu (&items[0], title, maxitems, menu, fontsize); DrawMenu (&items[0], title, maxitems, menu, fontsize);
redraw = 0; redraw = 0;
} }
p = PAD_ButtonsDown (0); p = PAD_ButtonsDown (0);
#ifdef HW_RVL #ifdef HW_RVL
wp = WPAD_ButtonsDown (0); wp = WPAD_ButtonsDown (0);
@ -600,57 +632,137 @@ RunMenu (char items[][20], int maxitems, char *title, int fontsize)
wp = 0; wp = 0;
#endif #endif
a = PAD_StickY (0); a = PAD_StickY (0);
VIDEO_WaitVSync(); // slow things down a bit so we don't overread the pads VIDEO_WaitVSync(); // slow things down a bit so we don't overread the pads
/*** Look for up ***/ /*** Look for up ***/
if ( (p & PAD_BUTTON_UP) || (wp & (WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP)) || (a > 70) || (mag>JOY_THRESHOLD && (ang>300 || ang<50)) ) if ( (p & PAD_BUTTON_UP) || (wp & (WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP)) || (a > 70) || (mag>JOY_THRESHOLD && (ang>300 || ang<50)) )
{ {
redraw = 1; redraw = 1;
menu--; menu = FindMenuItem(&items[0], maxitems, menu, -1);
} }
/*** Look for down ***/ /*** Look for down ***/
if ( (p & PAD_BUTTON_DOWN) || (wp & (WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN)) || (a < -70) || (mag>JOY_THRESHOLD && (ang>130 && ang<230)) ) if ( (p & PAD_BUTTON_DOWN) || (wp & (WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN)) || (a < -70) || (mag>JOY_THRESHOLD && (ang>130 && ang<230)) )
{ {
redraw = 1; redraw = 1;
menu++; menu = FindMenuItem(&items[0], maxitems, menu, +1);
} }
if ((p & PAD_BUTTON_A) || (wp & (WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A))) if ((p & PAD_BUTTON_A) || (wp & (WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A)))
{ {
quit = 1; quit = 1;
ret = menu; ret = menu;
} }
if ((p & PAD_BUTTON_B) || (wp & (WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B))) if ((p & PAD_BUTTON_B) || (wp & (WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B)))
{ {
quit = -1; quit = -1;
ret = -1; ret = -1;
} }
if (menu == maxitems)
menu = 0;
if (menu < 0)
menu = maxitems - 1;
} }
/*** Wait for B button to be released before proceeding ***/ /*** Wait for B button to be released before proceeding ***/
while ( (PAD_ButtonsDown(0) & PAD_BUTTON_B) while ( (PAD_ButtonsDown(0) & PAD_BUTTON_B)
#ifdef HW_RVL #ifdef HW_RVL
|| (WPAD_ButtonsDown(0) & (WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B)) || (WPAD_ButtonsDown(0) & (WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B))
#endif #endif
) )
{ {
ret = -1; ret = -1;
VIDEO_WaitVSync(); VIDEO_WaitVSync();
} }
return ret; return ret;
} }
/****************************************************************************
* ROM Information Screen
****************************************************************************/
void RomInfo()
{
clearscreen ();
int ypos = 65;
if (screenheight == 480)
ypos += 52;
else
ypos += 32;
setfontsize (28);
DrawText (-1, 60, (char*)"Rom Information");
setfontsize (16);
setfontcolour (0x00, 0x00, 0x00);
#define MENU_INFO_ROM "ROM"
#define MENU_INFO_ROMID "ROMID"
#define MENU_INFO_COMPANY "Company"
#define MENU_INFO_SIZE "Size"
#define MENU_INFO_SRAM "SRAM"
#define MENU_INFO_TYPE "Type"
#define MENU_INFO_CHECKSUM "Checksum"
#define MENU_INFO_TVTYPE "TV Type"
#define MENU_INFO_FRAMES "Frames"
#define MENU_INFO_CRC32 "CRC32"
char fmtString[1024];
ypos += 20;
DrawText (150, ypos, (char *)MENU_INFO_ROM);
DrawText (300, ypos, Memory.ROMName);
ypos += 20;
DrawText (150, ypos, (char *)MENU_INFO_ROMID);
DrawText (300, ypos, Memory.ROMId);
ypos += 20;
DrawText (150, ypos, (char *)MENU_INFO_COMPANY);
DrawText (300, ypos, Memory.CompanyId);
ypos += 20;
DrawText (150, ypos, (char *)MENU_INFO_SIZE);
sprintf(fmtString, "%d", Memory.ROMSize);
DrawText (300, ypos, fmtString);
ypos += 20;
DrawText (150, ypos, (char *)MENU_INFO_SRAM);
sprintf(fmtString, "%d", Memory.SRAMSize);
DrawText (300, ypos, fmtString);
ypos += 20;
DrawText (150, ypos, (char *)MENU_INFO_TYPE);
sprintf(fmtString, "%d", Memory.ROMType);
DrawText (300, ypos, fmtString);
ypos += 20;
DrawText (150, ypos, (char *)MENU_INFO_CHECKSUM);
sprintf(fmtString, "%04x / %04x", Memory.ROMChecksum, Memory.ROMComplementChecksum);
DrawText (300, ypos, fmtString);
ypos += 20;
DrawText (150, ypos, (char *)MENU_INFO_TVTYPE);
sprintf(fmtString, "%s", Settings.PAL ? "PAL" : "NTSC");
DrawText (300, ypos, fmtString);
ypos += 20;
DrawText (150, ypos, (char *)MENU_INFO_FRAMES);
sprintf(fmtString, "%d", Memory.ROMFramesPerSecond);
DrawText (300, ypos, fmtString);
ypos += 20;
DrawText (150, ypos, (char *)MENU_INFO_CRC32);
sprintf(fmtString, "%08X", Memory.ROMCRC32);
DrawText (300, ypos, fmtString);
showscreen ();
}
/**************************************************************************** /****************************************************************************
* DrawLine * DrawLine
* *
@ -811,27 +923,27 @@ void DrawLineFast( int startx, int endx, int y, u8 r, u8 g, u8 b )
u32 colour, clo, chi; u32 colour, clo, chi;
u32 lo,hi; u32 lo,hi;
u8 *s, *d; u8 *s, *d;
//colour = getcolour(r, g, b); //colour = getcolour(r, g, b);
colour = ( r << 16 | g << 8 | b ); colour = ( r << 16 | g << 8 | b );
d = (u8 *)&colour; d = (u8 *)&colour;
d[1] = c_adjust(d[1], DSTWEIGHT); d[1] = c_adjust(d[1], DSTWEIGHT);
d[2] = c_adjust(d[2], DSTWEIGHT); d[2] = c_adjust(d[2], DSTWEIGHT);
d[3] = c_adjust(d[3], DSTWEIGHT); d[3] = c_adjust(d[3], DSTWEIGHT);
width = ( endx - startx ) >> 1; width = ( endx - startx ) >> 1;
offset = ( y << 8 ) + ( y << 6 ) + ( startx >> 1 ); offset = ( y << 8 ) + ( y << 6 ) + ( startx >> 1 );
for ( i = 0; i < width; i++ ) for ( i = 0; i < width; i++ )
{ {
lo = getrgb(xfb[whichfb][offset], 0); lo = getrgb(xfb[whichfb][offset], 0);
hi = getrgb(xfb[whichfb][offset], 1); hi = getrgb(xfb[whichfb][offset], 1);
s = (u8 *)&hi; s = (u8 *)&hi;
s[1] = ( ( c_adjust(s[1],SRCWEIGHT) ) + d[1] ); s[1] = ( ( c_adjust(s[1],SRCWEIGHT) ) + d[1] );
s[2] = ( ( c_adjust(s[2],SRCWEIGHT) ) + d[2] ); s[2] = ( ( c_adjust(s[2],SRCWEIGHT) ) + d[2] );
s[3] = ( ( c_adjust(s[3],SRCWEIGHT) ) + d[3] ); s[3] = ( ( c_adjust(s[3],SRCWEIGHT) ) + d[3] );
s = (u8 *)&lo; s = (u8 *)&lo;
s[1] = ( ( c_adjust(s[1],SRCWEIGHT) ) + d[1] ); s[1] = ( ( c_adjust(s[1],SRCWEIGHT) ) + d[1] );
s[2] = ( ( c_adjust(s[2],SRCWEIGHT) ) + d[2] ); s[2] = ( ( c_adjust(s[2],SRCWEIGHT) ) + d[2] );
@ -840,21 +952,21 @@ void DrawLineFast( int startx, int endx, int y, u8 r, u8 g, u8 b )
clo = getcolour( s[1], s[2], s[3] ); clo = getcolour( s[1], s[2], s[3] );
s = (u8 *)&hi; s = (u8 *)&hi;
chi = getcolour( s[1], s[2], s[3] ); chi = getcolour( s[1], s[2], s[3] );
xfb[whichfb][offset++] = (chi & 0xffff0000 ) | ( clo & 0xffff) ; xfb[whichfb][offset++] = (chi & 0xffff0000 ) | ( clo & 0xffff) ;
} }
} }
/** /*****************************************************************************
* Ok, I'm useless with Y1CBY2CR colour. * Ok, I'm useless with Y1CBY2CR colour.
* So convert back to RGB so I can work with it -;) * So convert back to RGB so I can work with it -;)
*/ ****************************************************************************/
u32 getrgb( u32 ycbr, u32 low ) u32 getrgb( u32 ycbr, u32 low )
{ {
u8 r,g,b; u8 r,g,b;
u32 y; u32 y;
s8 cb,cr; s8 cb,cr;
if ( low ) if ( low )
y = ( ycbr & 0xff00 ) >> 8; y = ( ycbr & 0xff00 ) >> 8;
else else
@ -862,16 +974,14 @@ u32 getrgb( u32 ycbr, u32 low )
cr = ycbr & 0xff; cr = ycbr & 0xff;
cb = ( ycbr & 0xff0000 ) >> 16; cb = ( ycbr & 0xff0000 ) >> 16;
cr -= 128; cr -= 128;
cb -= 128; cb -= 128;
r = (u8)((float)y + 1.371 * (float)cr); r = (u8)((float)y + 1.371 * (float)cr);
g = (u8)((float)y - 0.698 * (float)cr - 0.336 * (float)cb); g = (u8)((float)y - 0.698 * (float)cr - 0.336 * (float)cb);
b = (u8)((float)y + 1.732 * (float)cb); b = (u8)((float)y + 1.732 * (float)cb);
return (u32)( r << 16 | g << 8 | b ); return (u32)( r << 16 | g << 8 | b );
} }

View File

@ -1,5 +1,5 @@
/**************************************************************************** /****************************************************************************
* Snes9x 1.50 * Snes9x 1.50
* *
* Nintendo Gamecube Screen Font Driver * Nintendo Gamecube Screen Font Driver
* *
@ -22,13 +22,14 @@
int FT_Init (); int FT_Init ();
void setfontsize (int pixelsize); void setfontsize (int pixelsize);
void DrawText (int x, int y, char *text);
void legal ();
void highlight (int on);
void WaitButtonA ();
void setfontcolour (u8 r, u8 g, u8 b); void setfontcolour (u8 r, u8 g, u8 b);
int RunMenu (char items[][20], int maxitems, char *title, int fontsize = 24); void DrawText (int x, int y, char *text);
void DrawMenu (char items[][20], char *title, int maxitems, int selected, int fontsize = 24); void unpackbackdrop ();
void Credits ();
void RomInfo ();
void WaitButtonA ();
int RunMenu (char items[][50], int maxitems, char *title, int fontsize = 20, int x = -1);
void DrawMenu (char items[][50], char *title, int maxitems, int selected, int fontsize = 20, int x = -1);
void WaitPrompt (char *msg); void WaitPrompt (char *msg);
int WaitPromptChoice (char *msg, char* bmsg, char* amsg); int WaitPromptChoice (char *msg, char* bmsg, char* amsg);
void ShowAction (char *msg); void ShowAction (char *msg);

View File

@ -46,8 +46,6 @@ card_dir CardDir;
card_file CardFile; card_file CardFile;
card_stat CardStatus; card_stat CardStatus;
extern void uselessinquiry();
/**************************************************************************** /****************************************************************************
* Clear the savebuffer * Clear the savebuffer
@ -89,15 +87,14 @@ 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) int MountCard(int cslot, bool8 silent)
{ {
int ret; int ret;
int tries; int tries;
EXI_ProbeReset(); EXI_ProbeReset();
//Mount the card // Mount the card
ret = CARD_Mount (cslot, SysArea, NULL); ret = CARD_Mount (cslot, SysArea, NULL);
tries = 0; tries = 0;
@ -108,17 +105,19 @@ int MountCard(int cslot)
WaitPrompt((char*) "Replug card in slot A!"); WaitPrompt((char*) "Replug card in slot A!");
else else
WaitPrompt((char*) "Replug card in slot B!"); WaitPrompt((char*) "Replug card in slot B!");
ShowAction ((char*) ""); ShowAction ((char*) "");
ret = CARD_Mount (cslot, SysArea, NULL); ret = CARD_Mount (cslot, SysArea, NULL);
tries++; tries++;
} }
tries = 0; tries = 0;
while ( tries < 5 && ret == CARD_ERROR_NOCARD ) while ( tries < 5 && ret == CARD_ERROR_NOCARD )
{ {
EXI_ProbeReset (); EXI_ProbeReset ();
ShowAction ((char*) "Mounting card...");
if(!silent)
ShowAction ((char*) "Mounting card...");
CARD_Unmount (cslot); CARD_Unmount (cslot);
usleep(500000); // wait half second usleep(500000); // wait half second
ShowAction ((char*) ""); ShowAction ((char*) "");
@ -131,14 +130,17 @@ int MountCard(int cslot)
while ( tries < 5 && ret == CARD_ERROR_UNLOCKED ) while ( tries < 5 && ret == CARD_ERROR_UNLOCKED )
{ {
EXI_ProbeReset (); EXI_ProbeReset ();
ShowAction ((char*) "Waiting for unlock...");
if(!silent)
ShowAction ((char*) "Waiting for unlock...");
usleep(500000); // wait half second usleep(500000); // wait half second
ShowAction ((char*) ""); if(!silent)
ShowAction ((char*) "");
usleep(500000); // wait half second usleep(500000); // wait half second
ret = CARD_Probe(cslot); ret = CARD_Probe(cslot);
tries++; tries++;
} }
return ret; return ret;
} }
@ -159,36 +161,36 @@ VerifyMCFile (unsigned char *buf, int slot, char *filename, int datasize)
/*** Initialize Card System ***/ /*** Initialize Card System ***/
memset (SysArea, 0, CARD_WORKAREA); memset (SysArea, 0, CARD_WORKAREA);
CARD_Init ("SNES", "00"); CARD_Init ("SNES", "00");
/*** Try to mount the card ***/ /*** Try to mount the card ***/
CardError = MountCard(slot); CardError = MountCard(slot, NOTSILENT);
if (CardError == 0) if (CardError == 0)
{ {
/*** Get Sector Size ***/ /*** Get Sector Size ***/
CARD_GetSectorSize (slot, &SectorSize); CARD_GetSectorSize (slot, &SectorSize);
if (!CardFileExists (filename, slot)) if (!CardFileExists (filename, slot))
{ {
CARD_Unmount (slot); CARD_Unmount (slot);
WaitPrompt((char*) "Unable to open file for verify!"); WaitPrompt((char*) "Unable to open file for verify!");
return 0; return 0;
} }
memset (&CardFile, 0, sizeof (CardFile)); memset (&CardFile, 0, sizeof (CardFile));
CardError = CARD_Open (slot, filename, &CardFile); CardError = CARD_Open (slot, filename, &CardFile);
blocks = CardFile.len; blocks = CardFile.len;
if (blocks < SectorSize) if (blocks < SectorSize)
blocks = SectorSize; blocks = SectorSize;
if (blocks % SectorSize) if (blocks % SectorSize)
blocks += SectorSize; blocks += SectorSize;
if (blocks > (unsigned int)datasize) if (blocks > (unsigned int)datasize)
blocks = datasize; blocks = datasize;
memset (verifbuffer, 0, VERIFBUFFERSIZE); memset (verifbuffer, 0, VERIFBUFFERSIZE);
bytesleft = blocks; bytesleft = blocks;
bytesread = 0; bytesread = 0;
@ -202,16 +204,16 @@ VerifyMCFile (unsigned char *buf, int slot, char *filename, int datasize)
WaitPrompt((char*) "File did not verify!"); WaitPrompt((char*) "File did not verify!");
return 0; return 0;
} }
bytesleft -= SectorSize; bytesleft -= SectorSize;
bytesread += SectorSize; bytesread += SectorSize;
sprintf (msg, "Verified %d of %d bytes", bytesread, blocks); sprintf (msg, "Verified %d of %d bytes", bytesread, blocks);
ShowProgress (msg, bytesread, blocks); ShowProgress (msg, bytesread, blocks);
} }
CARD_Close (&CardFile); CARD_Close (&CardFile);
CARD_Unmount (slot); CARD_Unmount (slot);
return 1; return 1;
} }
else else
@ -219,7 +221,7 @@ VerifyMCFile (unsigned char *buf, int slot, char *filename, int datasize)
WaitPrompt((char*) "Unable to Mount Slot A Memory Card!"); WaitPrompt((char*) "Unable to Mount Slot A Memory Card!");
else else
WaitPrompt((char*) "Unable to Mount Slot B Memory Card!"); WaitPrompt((char*) "Unable to Mount Slot B Memory Card!");
return 0; return 0;
} }
@ -240,35 +242,34 @@ LoadBufferFromMC (unsigned char *buf, int slot, char *filename, bool8 silent)
/*** Initialize Card System ***/ /*** Initialize Card System ***/
memset (SysArea, 0, CARD_WORKAREA); memset (SysArea, 0, CARD_WORKAREA);
CARD_Init ("SNES", "00"); CARD_Init ("SNES", "00");
/*** Try to mount the card ***/ /*** Try to mount the card ***/
CardError = MountCard(slot); CardError = MountCard(slot, NOTSILENT);
if (CardError == 0) if (CardError == 0)
{ {
/*** Get Sector Size ***/ /*** Get Sector Size ***/
CARD_GetSectorSize (slot, &SectorSize); CARD_GetSectorSize (slot, &SectorSize);
if (!CardFileExists (filename, slot)) if (!CardFileExists (filename, slot))
{ {
if ( !silent ) WaitPrompt((char*) "Unable to open file");
WaitPrompt((char*) "Unable to open file");
return 0; return 0;
} }
memset (&CardFile, 0, sizeof (CardFile)); memset (&CardFile, 0, sizeof (CardFile));
CardError = CARD_Open (slot, filename, &CardFile); CardError = CARD_Open (slot, filename, &CardFile);
blocks = CardFile.len; blocks = CardFile.len;
if (blocks < SectorSize) if (blocks < SectorSize)
blocks = SectorSize; blocks = SectorSize;
if (blocks % SectorSize) if (blocks % SectorSize)
blocks += SectorSize; blocks += SectorSize;
memset (buf, 0, 0x22000); memset (buf, 0, 0x22000);
bytesleft = blocks; bytesleft = blocks;
bytesread = 0; bytesread = 0;
while (bytesleft > 0) while (bytesleft > 0)
@ -276,9 +277,12 @@ LoadBufferFromMC (unsigned char *buf, int slot, char *filename, bool8 silent)
CARD_Read (&CardFile, buf + bytesread, SectorSize, bytesread); CARD_Read (&CardFile, buf + bytesread, SectorSize, bytesread);
bytesleft -= SectorSize; bytesleft -= SectorSize;
bytesread += SectorSize; bytesread += SectorSize;
sprintf (msg, "Read %d of %d bytes", bytesread, blocks); if ( !silent )
ShowProgress (msg, bytesread, blocks); {
sprintf (msg, "Read %d of %d bytes", bytesread, blocks);
ShowProgress (msg, bytesread, blocks);
}
} }
CARD_Close (&CardFile); CARD_Close (&CardFile);
CARD_Unmount (slot); CARD_Unmount (slot);
@ -288,7 +292,7 @@ LoadBufferFromMC (unsigned char *buf, int slot, char *filename, bool8 silent)
WaitPrompt((char*) "Unable to Mount Slot A Memory Card!"); WaitPrompt((char*) "Unable to Mount Slot A Memory Card!");
else else
WaitPrompt((char*) "Unable to Mount Slot B Memory Card!"); WaitPrompt((char*) "Unable to Mount Slot B Memory Card!");
return bytesread; return bytesread;
} }
@ -303,26 +307,26 @@ SaveBufferToMC (unsigned char *buf, int slot, char *filename, int datasize, bool
unsigned int blocks; unsigned int blocks;
unsigned int SectorSize; unsigned int SectorSize;
char msg[80]; char msg[80];
/*** Initialize Card System ***/ /*** Initialize Card System ***/
memset (SysArea, 0, CARD_WORKAREA); memset (SysArea, 0, CARD_WORKAREA);
CARD_Init ("SNES", "00"); CARD_Init ("SNES", "00");
/*** Try to mount the card ***/ /*** Try to mount the card ***/
CardError = MountCard(slot); CardError = MountCard(slot, NOTSILENT);
if (CardError == 0) if (CardError == 0)
{ {
/*** Get Sector Size ***/ /*** Get Sector Size ***/
CARD_GetSectorSize (slot, &SectorSize); CARD_GetSectorSize (slot, &SectorSize);
if (datasize) if (datasize)
{ {
/*** Calculate number of blocks required ***/ /*** Calculate number of blocks required ***/
blocks = (datasize / SectorSize) * SectorSize; blocks = (datasize / SectorSize) * SectorSize;
if (datasize % SectorSize) if (datasize % SectorSize)
blocks += SectorSize; blocks += SectorSize;
/*** Does this file exist ? ***/ /*** Does this file exist ? ***/
if (CardFileExists (filename, slot)) if (CardFileExists (filename, slot))
{ {
@ -334,11 +338,11 @@ SaveBufferToMC (unsigned char *buf, int slot, char *filename, int datasize, bool
WaitPrompt((char*) "Unable to open card file!"); WaitPrompt((char*) "Unable to open card file!");
return 0; return 0;
} }
// if ( (s32)blocks < CardFile.len ) /*** new data is shorter ***/ // if ( (s32)blocks < CardFile.len ) /*** new data is shorter ***/
// { // {
// CARD_Close (&CardFile); // CARD_Close (&CardFile);
// //
// /*** Delete the existing longer file ***/ // /*** Delete the existing longer file ***/
// CardError = CARD_Delete(slot, filename); // CardError = CARD_Delete(slot, filename);
// if (CardError) // if (CardError)
@ -347,7 +351,7 @@ SaveBufferToMC (unsigned char *buf, int slot, char *filename, int datasize, bool
// WaitPrompt((char*) "Unable to delete existing file!"); // WaitPrompt((char*) "Unable to delete existing file!");
// return 0; // return 0;
// } // }
// //
// /*** Create new, shorter file ***/ // /*** Create new, shorter file ***/
// CardError = CARD_Create (slot, filename, blocks, &CardFile); // CardError = CARD_Create (slot, filename, blocks, &CardFile);
// if (CardError) // if (CardError)
@ -356,14 +360,14 @@ SaveBufferToMC (unsigned char *buf, int slot, char *filename, int datasize, bool
// WaitPrompt((char*) "Unable to create updated card file!"); // WaitPrompt((char*) "Unable to create updated card file!");
// return 0; // return 0;
// } // }
// //
// } // }
// else // else
if ( (s32)blocks > CardFile.len ) /*** new data is longer ***/ if ( (s32)blocks > CardFile.len ) /*** new data is longer ***/
{ {
CARD_Close (&CardFile); CARD_Close (&CardFile);
/*** Try to create temp file to check available space ***/ /*** Try to create temp file to check available space ***/
CardError = CARD_Create (slot, "TEMPFILESNES9XGX201", blocks, &CardFile); CardError = CARD_Create (slot, "TEMPFILESNES9XGX201", blocks, &CardFile);
if (CardError) if (CardError)
@ -372,7 +376,7 @@ SaveBufferToMC (unsigned char *buf, int slot, char *filename, int datasize, bool
WaitPrompt((char*) "Not enough space to update file!"); WaitPrompt((char*) "Not enough space to update file!");
return 0; return 0;
} }
/*** Delete the temporary file ***/ /*** Delete the temporary file ***/
CARD_Close (&CardFile); CARD_Close (&CardFile);
CardError = CARD_Delete(slot, "TEMPFILESNES9XGX201"); CardError = CARD_Delete(slot, "TEMPFILESNES9XGX201");
@ -382,7 +386,7 @@ SaveBufferToMC (unsigned char *buf, int slot, char *filename, int datasize, bool
WaitPrompt((char*) "Unable to delete temporary file!"); WaitPrompt((char*) "Unable to delete temporary file!");
return 0; return 0;
} }
/*** Delete the existing shorter file ***/ /*** Delete the existing shorter file ***/
CardError = CARD_Delete(slot, filename); CardError = CARD_Delete(slot, filename);
if (CardError) if (CardError)
@ -391,7 +395,7 @@ SaveBufferToMC (unsigned char *buf, int slot, char *filename, int datasize, bool
WaitPrompt((char*) "Unable to delete existing file!"); WaitPrompt((char*) "Unable to delete existing file!");
return 0; return 0;
} }
/*** Create new, longer file ***/ /*** Create new, longer file ***/
CardError = CARD_Create (slot, filename, blocks, &CardFile); CardError = CARD_Create (slot, filename, blocks, &CardFile);
if (CardError) if (CardError)
@ -409,14 +413,14 @@ SaveBufferToMC (unsigned char *buf, int slot, char *filename, int datasize, bool
if (CardError) if (CardError)
{ {
CARD_Unmount (slot); CARD_Unmount (slot);
if ( CardError = CARD_ERROR_INSSPACE ) if ( CardError == CARD_ERROR_INSSPACE )
WaitPrompt((char*) "Not enough space to create file!"); WaitPrompt((char*) "Not enough space to create file!");
else else
WaitPrompt((char*) "Unable to create card file!"); WaitPrompt((char*) "Unable to create card file!");
return 0; return 0;
} }
} }
/*** Now, have an open file handle, ready to send out the data ***/ /*** Now, have an open file handle, ready to send out the data ***/
CARD_GetStatus (slot, CardFile.filenum, &CardStatus); CARD_GetStatus (slot, CardFile.filenum, &CardStatus);
CardStatus.icon_addr = 0x0; CardStatus.icon_addr = 0x0;
@ -424,7 +428,7 @@ SaveBufferToMC (unsigned char *buf, int slot, char *filename, int datasize, bool
CardStatus.icon_speed = 1; CardStatus.icon_speed = 1;
CardStatus.comment_addr = 2048; CardStatus.comment_addr = 2048;
CARD_SetStatus (slot, CardFile.filenum, &CardStatus); CARD_SetStatus (slot, CardFile.filenum, &CardStatus);
int byteswritten = 0; int byteswritten = 0;
int bytesleft = blocks; int bytesleft = blocks;
while (bytesleft > 0) while (bytesleft > 0)
@ -434,14 +438,14 @@ SaveBufferToMC (unsigned char *buf, int slot, char *filename, int datasize, bool
SectorSize, byteswritten); SectorSize, byteswritten);
bytesleft -= SectorSize; bytesleft -= SectorSize;
byteswritten += SectorSize; byteswritten += SectorSize;
sprintf (msg, "Wrote %d of %d bytes", byteswritten, blocks); sprintf (msg, "Wrote %d of %d bytes", byteswritten, blocks);
ShowProgress (msg, byteswritten, blocks); ShowProgress (msg, byteswritten, blocks);
} }
CARD_Close (&CardFile); CARD_Close (&CardFile);
CARD_Unmount (slot); CARD_Unmount (slot);
if ( GCSettings.VerifySaves ) if ( GCSettings.VerifySaves )
{ {
/*** Verify the written file, but only up to the length we wrote /*** Verify the written file, but only up to the length we wrote
@ -463,129 +467,9 @@ SaveBufferToMC (unsigned char *buf, int slot, char *filename, int datasize, bool
WaitPrompt((char*) "Unable to Mount Slot A Memory Card!"); WaitPrompt((char*) "Unable to Mount Slot A Memory Card!");
else else
WaitPrompt((char*) "Unable to Mount Slot B Memory Card!"); WaitPrompt((char*) "Unable to Mount Slot B Memory Card!");
return 0; return 0;
} }
/****************************************************************************
* Memory Card SRAM Load
****************************************************************************/
void
LoadSRAMFromMC (int slot, int silent)
{
char filename[MAXPATHLEN];
int offset = 0;
ShowAction ((char*) "Loading SRAM from MC...");
// check for 'old' version of sram
sprintf (filename, "%s.srm", Memory.ROMName); // Build old SRAM filename
offset = LoadBufferFromMC (savebuffer, slot, filename, silent); // load file
if (offset > 0) // old sram found
{
if (WaitPromptChoice ((char*)"Old SRAM found. Convert and delete?", (char*)"Cancel", (char*)"Do it"))
{
decodesavedata (offset);
CARD_Delete (slot, filename); // delete old sram
SaveSRAMToMC (slot, silent);
}
}
//
/*** Build SRAM filename ***/
sprintf (filename, "%s.srm", Memory.ROMFilename);
offset = LoadBufferFromMC (savebuffer, slot, filename, silent);
if ( offset > 0 )
{
decodesavedata (offset);
if ( !silent )
{
sprintf (filename, "Loaded %d bytes", offset);
WaitPrompt (filename);
}
S9xSoftReset();
}
}
/****************************************************************************
* Memory Card SRAM Save
****************************************************************************/
void
SaveSRAMToMC (int slot, int silent)
{
char filename[128];
int datasize;
int offset;
if (!silent)
ShowAction ((char*) "Saving SRAM to MC...");
/*** Build SRAM filename ***/
sprintf (filename, "%s.srm", Memory.ROMFilename);
datasize = prepareMCsavedata ();
offset = SaveBufferToMC (savebuffer, slot, filename, datasize, silent);
if ( (offset > 0) && (!silent))
{
sprintf (filename, "Wrote %d bytes", offset);
WaitPrompt (filename);
}
}
/****************************************************************************
* Memory Card Preferences Load
****************************************************************************/
void
LoadPrefsFromMC (int slot, int silent)
{
int offset;
char msg[80];
ShowAction ((char*) "Loading Prefs from MC...");
offset = LoadBufferFromMC (savebuffer, slot, PREFS_FILE_NAME, silent);
if ( offset > 0 )
{
decodePrefsData ();
if ( !silent )
{
sprintf (msg, "Loaded %d bytes", offset);
WaitPrompt (msg);
}
}
}
/****************************************************************************
* Memory Card Preferences Save
****************************************************************************/
void
SavePrefsToMC (int slot, int silent)
{
int datasize;
int offset;
char msg[80];
if (!silent)
ShowAction ((char*) "Saving Prefs to MC...");
datasize = preparePrefsData ();
offset = SaveBufferToMC (savebuffer, slot, PREFS_FILE_NAME, datasize, silent);
if ( offset > 0 && !silent)
{
sprintf (msg, "Wrote %d bytes", offset);
WaitPrompt (msg);
}
}

View File

@ -21,11 +21,6 @@ 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);
void LoadSRAMFromMC (int slot, int silent);
void SaveSRAMToMC (int slot, int silent);
void LoadPrefsFromMC (int slot, int silent);
void SavePrefsToMC (int slot, int silent);
#endif #endif

View File

@ -30,6 +30,7 @@
#include "filesel.h" #include "filesel.h"
#include "ftfont.h" #include "ftfont.h"
#include "smbload.h" #include "smbload.h"
#include "sdload.h"
#include "mcsave.h" #include "mcsave.h"
extern "C" extern "C"
@ -98,12 +99,12 @@ NGCFreezeMemBuffer ()
{ {
int i; int i;
char buffer[1024]; char buffer[1024];
bufoffset = 0; bufoffset = 0;
S9xUpdateRTC (); S9xUpdateRTC ();
S9xSRTCPreSaveState (); S9xSRTCPreSaveState ();
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
{ {
SoundData.channels[i].previous16[0] = SoundData.channels[i].previous16[0] =
@ -111,16 +112,16 @@ NGCFreezeMemBuffer ()
SoundData.channels[i].previous16[1] = SoundData.channels[i].previous16[1] =
(int16) SoundData.channels[i].previous[1]; (int16) SoundData.channels[i].previous[1];
} }
sprintf (buffer, "%s:%04d\n", SNAPSHOT_MAGIC, SNAPSHOT_VERSION); sprintf (buffer, "%s:%04d\n", SNAPSHOT_MAGIC, SNAPSHOT_VERSION);
PutMem (buffer, strlen (buffer)); PutMem (buffer, strlen (buffer));
sprintf (buffer, "NAM:%06d:%s%c", (int) strlen (Memory.ROMFilename) + 1, sprintf (buffer, "NAM:%06d:%s%c", (int) strlen (Memory.ROMFilename) + 1,
Memory.ROMFilename, 0); Memory.ROMFilename, 0);
PutMem (buffer, strlen (buffer) + 1); PutMem (buffer, strlen (buffer) + 1);
NGCFreezeStruct (); NGCFreezeStruct ();
return 0; return 0;
} }
@ -131,162 +132,167 @@ NGCFreezeMemBuffer ()
* Do freeze game for Nintendo Gamecube * Do freeze game for Nintendo Gamecube
*/ */
int int
NGCFreezeGame (int where, bool8 silent) NGCFreezeGame (int method, bool8 silent)
{ {
char filename[1024]; if(method == METHOD_AUTO)
SMBFILE smbfile; method = autoSaveMethod();
FILE *handle;
int len = 0;
int wrote = 0;
int offset = 0;
char msg[100];
if (where == 4)
{
/*** Freeze to SMB ***/
sprintf (filename, "/%s/%s.frz", SNESSAVEDIR, Memory.ROMFilename);
}
else if (where == 2 || where == 3)
{
/*** Freeze to SDCard in slot A or slot B ***/
#ifdef SDUSE_LFN char filename[1024];
sprintf (filename, "%s/%s/%s.frz", ROOTSDDIR, SNESSAVEDIR, Memory.ROMFilename); SMBFILE smbfile;
#else FILE *handle;
/*** Until we have LFN on SD ... ***/ int len = 0;
sprintf (filename, "%s/%s/%08x.frz", ROOTSDDIR, SNESSAVEDIR, Memory.ROMCRC32); int wrote = 0;
#endif int offset = 0;
} char msg[100];
else
{ if (method == METHOD_SD) // SD
/*** Freeze to MC in slot A or slot B ***/ {
sprintf (filename, "%s.snz", Memory.ROMFilename); sprintf (filename, "%s/%s/%s.frz", ROOTSDDIR, GCSettings.SaveFolder, Memory.ROMFilename);
} }
if (method == METHOD_USB) // USB
S9xSetSoundMute (TRUE); {
S9xPrepareSoundForSnapshotSave (FALSE); sprintf (filename, "%s/%s/%s.frz", ROOTUSBDIR, GCSettings.SaveFolder, Memory.ROMFilename);
}
NGCFreezeMemBuffer (); else if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) // MC Slot A or B
{
S9xPrepareSoundForSnapshotSave (TRUE); sprintf (filename, "%s.snz", Memory.ROMFilename);
S9xSetSoundMute (FALSE); }
else if (method == METHOD_SMB) // SMB
if (where == 4) /*** SMB ***/ {
{ sprintf (filename, "/%s/%s.frz", GCSettings.SaveFolder, Memory.ROMFilename);
ConnectSMB (); }
smbfile = SMB_Open (filename, SMB_OPEN_WRITING | SMB_DENY_NONE, S9xSetSoundMute (TRUE);
SMB_OF_CREATE | SMB_OF_TRUNCATE); S9xPrepareSoundForSnapshotSave (FALSE);
if (smbfile) NGCFreezeMemBuffer ();
{
S9xPrepareSoundForSnapshotSave (TRUE);
S9xSetSoundMute (FALSE);
if (method == METHOD_SD || method == METHOD_USB) // FAT devices
{
handle = fopen (filename, "wb");
if (handle > 0)
{
if (!silent) if (!silent)
ShowAction ((char*) "Saving freeze game..."); ShowAction ((char*) "Saving freeze game...");
len = bufoffset;
offset = 0;
while (len > 0)
{
if (len > 1024)
wrote =
SMB_Write ((char *) membuffer + offset, 1024, offset,
smbfile);
else
wrote =
SMB_Write ((char *) membuffer + offset, len, offset,
smbfile);
offset += wrote;
len -= wrote;
}
SMB_Close (smbfile);
if ( !silent )
{
sprintf (filename, "Written %d bytes", bufoffset);
WaitPrompt (filename);
}
}
else
{
char msg[100];
sprintf(msg, "Couldn't save to SMB:\\%s\\", SNESSAVEDIR);
WaitPrompt (msg);
}
}
else if (where == 2 || where == 3) /*** SDCard slot A or slot B ***/
{
handle = fopen (filename, "wb");
if (handle > 0)
{
if (!silent)
ShowAction ((char*) "Saving freeze game...");
len = fwrite (membuffer, 1, bufoffset, handle);
fclose (handle);
if (len != bufoffset) len = fwrite (membuffer, 1, bufoffset, handle);
WaitPrompt((char*) "Error writing freeze file"); fclose (handle);
else if ( !silent )
{ if (len != bufoffset)
sprintf (filename, "Written %d bytes", bufoffset); WaitPrompt((char*) "Error writing freeze file");
WaitPrompt (filename); else if ( !silent )
} {
sprintf (filename, "Written %d bytes", bufoffset);
} WaitPrompt (filename);
else }
{ }
sprintf(msg, "Couldn't save to %s/%s/", ROOTSDDIR, SNESSAVEDIR); else
WaitPrompt (msg); {
} if(method == METHOD_SD)
} sprintf(msg, "Couldn't save to %s/%s/", ROOTSDDIR, GCSettings.SaveFolder);
else /*** MC in slot A or slot B ***/ else
{ sprintf(msg, "Couldn't save to %s/%s/", ROOTUSBDIR, GCSettings.SaveFolder);
WaitPrompt (msg);
}
}
else if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTA) // MC Slot A or B
{
if (!silent) if (!silent)
ShowAction ((char*) "Saving freeze game..."); ShowAction ((char*) "Saving freeze game...");
ClearSaveBuffer ();
/*** Copy in save icon ***/
int offset = sizeof (saveicon);
memcpy (savebuffer, saveicon, offset);
/*** And the freezecomment ***/
sprintf (freezecomment[1], "%s", Memory.ROMName);
memcpy (savebuffer + offset, freezecomment, 64);
offset += 64;
/*** Zip and copy in the freeze ***/ ClearSaveBuffer ();
uLongf DestBuffSize = (uLongf) SAVEBUFFERSIZE;
int err= compress2((Bytef*)(savebuffer+offset+8), (uLongf*)&DestBuffSize, (const Bytef*)membuffer, (uLongf)bufoffset, Z_BEST_COMPRESSION); /*** Copy in save icon ***/
int offset = sizeof (saveicon);
if(err!=Z_OK) memcpy (savebuffer, saveicon, offset);
{
sprintf (msg, "zip error %s ",zError(err)); /*** And the freezecomment ***/
WaitPrompt (msg); sprintf (freezecomment[1], "%s", Memory.ROMFilename);
return 0; memcpy (savebuffer + offset, freezecomment, 64);
} offset += 64;
/*** Zip and copy in the freeze ***/
uLongf DestBuffSize = (uLongf) SAVEBUFFERSIZE;
int err= compress2((Bytef*)(savebuffer+offset+8), (uLongf*)&DestBuffSize, (const Bytef*)membuffer, (uLongf)bufoffset, Z_BEST_COMPRESSION);
if(err!=Z_OK)
{
sprintf (msg, "zip error %s ",zError(err));
WaitPrompt (msg);
return 0;
}
int zippedsize = (int)DestBuffSize; int zippedsize = (int)DestBuffSize;
memcpy (savebuffer + offset, &zippedsize, 4); memcpy (savebuffer + offset, &zippedsize, 4);
offset += 4; offset += 4;
int decompressedsize = (int)bufoffset; int decompressedsize = (int)bufoffset;
memcpy (savebuffer + offset, &decompressedsize, 4); memcpy (savebuffer + offset, &decompressedsize, 4);
offset += 4; offset += 4;
offset += zippedsize; offset += zippedsize;
int ret = SaveBufferToMC ( savebuffer, where, filename, offset, SILENT ); int ret;
if ( ret && !silent )
{ if(method == METHOD_MC_SLOTA)
sprintf (filename, "Written %d bytes", ret); ret = SaveBufferToMC ( savebuffer, CARD_SLOTA, filename, offset, SILENT );
WaitPrompt (filename); else
} ret = SaveBufferToMC ( savebuffer, CARD_SLOTB, filename, offset, SILENT );
}
if ( ret && !silent )
{
sprintf (filename, "Written %d bytes", ret);
WaitPrompt (filename);
}
}
else if (method == METHOD_SMB) // SMB
{
ConnectSMB ();
smbfile = SMB_Open (filename, SMB_OPEN_WRITING | SMB_DENY_NONE,
SMB_OF_CREATE | SMB_OF_TRUNCATE);
if (smbfile)
{
if (!silent)
ShowAction ((char*) "Saving freeze game...");
len = bufoffset;
offset = 0;
while (len > 0)
{
if (len > 1024)
wrote =
SMB_Write ((char *) membuffer + offset, 1024, offset,
smbfile);
else
wrote =
SMB_Write ((char *) membuffer + offset, len, offset,
smbfile);
offset += wrote;
len -= wrote;
}
SMB_Close (smbfile);
if ( !silent )
{
sprintf (filename, "Written %d bytes", bufoffset);
WaitPrompt (filename);
}
}
else
{
char msg[100];
sprintf(msg, "Couldn't save to SMB:\\%s\\", GCSettings.SaveFolder);
WaitPrompt (msg);
}
}
return 0; return 0;
} }
@ -331,7 +337,7 @@ NGCUnFreezeBlock (char *name, uint8 * block, int size)
* NGCUnfreezeGame * NGCUnfreezeGame
*/ */
int int
NGCUnfreezeGame (int from, bool8 silent) NGCUnfreezeGame (int method, bool8 silent)
{ {
char filename[1024]; char filename[1024];
SMBFILE smbfile; SMBFILE smbfile;
@ -339,151 +345,156 @@ NGCUnfreezeGame (int from, bool8 silent)
int read = 0; int read = 0;
int offset = 0; int offset = 0;
char msg[80]; char msg[80];
bufoffset = 0; bufoffset = 0;
if (from == 4) if(method == METHOD_AUTO)
{ method = autoLoadMethod();
/*** From SMB ***/
sprintf (filename, "\\%s\\%s.frz", SNESSAVEDIR, Memory.ROMFilename); if (method == METHOD_SD || method == METHOD_USB) // SD & USB
ConnectSMB (); {
if(method == METHOD_SD)
/*** Read the file into memory ***/ sprintf (filename, "%s/%s/%s.frz", ROOTSDDIR, GCSettings.SaveFolder, Memory.ROMFilename);
smbfile = else
SMB_Open (filename, SMB_OPEN_READING | SMB_DENY_NONE, SMB_OF_OPEN); sprintf (filename, "%s/%s/%s.frz", ROOTUSBDIR, GCSettings.SaveFolder, Memory.ROMFilename);
if (smbfile) handle = fopen (filename, "rb");
{
ShowAction ((char*) "Loading freeze file..."); if (handle > 0)
while ((read = {
SMB_Read ((char *) membuffer + offset, 1024, offset, if ( !silent )
smbfile)) > 0) ShowAction ((char*) "Loading freeze file...");
offset += read;
offset = 0;
SMB_Close (smbfile); /*** Usual chunks into memory ***/
while ((read = fread (membuffer + offset, 1, 2048, handle)) > 0)
ShowAction ((char*) "Unpacking freeze file"); offset += read;
if (S9xUnfreezeGame ("AGAME") != SUCCESS)
{ fclose (handle);
WaitPrompt((char*) "Error thawing");
return 0; if ( !silent )
} ShowAction ((char*) "Unpacking freeze file");
}
else if ( !silent ) if (S9xUnfreezeGame ("AGAME") != SUCCESS)
{ {
WaitPrompt((char*) "No freeze file found"); WaitPrompt((char*) "Error thawing");
return 0; return 0;
} }
}
else
{
WaitPrompt((char*) "No freeze file found");
return 0;
}
return 1;
} }
else if (from == 2 || from == 3) /*** From SD slot A or slot B ***/
{ else if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) // MC in slot A or slot B
{
#ifdef SDUSE_LFN if ( !silent )
sprintf (filename, "%s/%s/%s.frz", ROOTSDDIR, SNESSAVEDIR, Memory.ROMFilename); ShowAction ((char*) "Loading freeze file...");
#else
/*** From SDCard ***/ sprintf (filename, "%s.snz", Memory.ROMFilename);
sprintf (filename, "%s/%s/%08x.frz", ROOTSDDIR, SNESSAVEDIR, Memory.ROMCRC32);
#endif int ret = 0;
handle = fopen (filename, "rb"); if(method == METHOD_MC_SLOTA)
LoadBufferFromMC ( savebuffer, CARD_SLOTA, filename, silent );
if (handle > 0) else
{ LoadBufferFromMC ( savebuffer, CARD_SLOTB, filename, silent );
ShowAction ((char*) "Loading freeze file...");
if ( ret )
offset = 0; {
/*** Usual chunks into memory ***/ if ( !silent )
while ((read = fread (membuffer + offset, 1, 2048, handle)) > ShowAction ((char*) "Unpacking freeze file");
0)
offset += read; // skip the saveicon and comment
offset = (sizeof(saveicon) + 64);
fclose (handle); uLongf zipsize = 0;
uLongf decompressedsize = 0;
ShowAction ((char*) "Unpacking freeze file");
memcpy (&zipsize, savebuffer+offset, 4);
if (S9xUnfreezeGame ("AGAME") != SUCCESS) offset += 4;
{
WaitPrompt((char*) "Error thawing"); memcpy (&decompressedsize, savebuffer+offset, 4);
return 0; offset += 4;
}
} memset(membuffer, 0, MEMBUFFER);
else if ( !silent )
{ uLongf DestBuffSize = MEMBUFFER;
WaitPrompt((char*) "No freeze file found"); int err= uncompress((Bytef*)membuffer, (uLongf*)&DestBuffSize, (const Bytef*)(savebuffer + offset), zipsize);
return 0;
} if ( err!=Z_OK )
{
sprintf (msg, "unzip error %s ",zError(err));
WaitPrompt (msg);
return 0;
}
if ( DestBuffSize != decompressedsize )
{
WaitPrompt((char*) "Unzipped size doesn't match expected size!");
return 0;
}
if (S9xUnfreezeGame ("AGAME") != SUCCESS)
{
WaitPrompt((char*) "Error thawing");
return 0;
}
}
else
{
return 0;
}
return 1;
} }
else /*** From MC in slot A or slot B ***/ else if (method == METHOD_SMB) // Network (SMB)
{ {
ShowAction ((char*) "Loading freeze file..."); sprintf (filename, "\\%s\\%s.frz", GCSettings.SaveFolder, Memory.ROMFilename);
ConnectSMB ();
sprintf (filename, "%s.snz", Memory.ROMFilename);
int ret = LoadBufferFromMC ( savebuffer, from, filename, silent );
if ( ret )
{
ShowAction ((char*) "Unpacking freeze file");
// skip the saveicon and comment
offset = (sizeof(saveicon) + 64);
uLongf zipsize = 0;
uLongf decompressedsize = 0;
memcpy (&zipsize, savebuffer+offset, 4);
offset += 4;
memcpy (&decompressedsize, savebuffer+offset, 4);
offset += 4;
memset(membuffer, 0, MEMBUFFER);
uLongf DestBuffSize = MEMBUFFER; /*** Read the file into memory ***/
int err= uncompress((Bytef*)membuffer, (uLongf*)&DestBuffSize, (const Bytef*)(savebuffer + offset), zipsize); smbfile =
SMB_Open (filename, SMB_OPEN_READING | SMB_DENY_NONE, SMB_OF_OPEN);
if ( err!=Z_OK )
{
sprintf (msg, "unzip error %s ",zError(err));
WaitPrompt (msg);
return 0;
}
if ( DestBuffSize != decompressedsize ) if (smbfile)
{ {
WaitPrompt((char*) "Unzipped size doesn't match expected size!"); if ( !silent )
return 0; ShowAction ((char*) "Loading freeze file...");
} while ((read =
SMB_Read ((char *) membuffer + offset, 1024, offset,
smbfile)) > 0)
offset += read;
if (S9xUnfreezeGame ("AGAME") != SUCCESS) SMB_Close (smbfile);
{
WaitPrompt((char*) "Error thawing");
return 0;
}
}
else if ( !silent )
{
sprintf(msg, "Couldn't load from MC slot %s", (from ? "B" : "A"));
WaitPrompt (msg);
return 0;
}
if ( !silent )
ShowAction ((char*) "Unpacking freeze file");
if (S9xUnfreezeGame ("AGAME") != SUCCESS)
{
WaitPrompt((char*) "Error thawing");
return 0;
}
}
else if ( !silent )
{
WaitPrompt((char*) "No freeze file found");
return 0;
}
return 1;
} }
return 0; // if we reached here, nothing was done!
return 1;
} }
void quickLoadFreeze (bool8 silent) void quickLoadFreeze (bool8 silent)
{ {
if ( QUICK_SAVE_SLOT >= 0 ) NGCUnfreezeGame ( GCSettings.SaveMethod, silent );
NGCUnfreezeGame ( QUICK_SAVE_SLOT, silent );
} }
void quickSaveFreeze (bool8 silent) void quickSaveFreeze (bool8 silent)
{ {
if ( QUICK_SAVE_SLOT >= 0 ) NGCFreezeGame ( GCSettings.SaveMethod, silent );
NGCFreezeGame ( QUICK_SAVE_SLOT, silent );
} }

View File

@ -25,8 +25,8 @@ typedef struct
} }
MEMFILE; MEMFILE;
int NGCFreezeGame (int where, bool8 silent); int NGCFreezeGame (int method, bool8 silent);
int NGCUnfreezeGame (int from, bool8 silent); int NGCUnfreezeGame (int method, bool8 silent);
void quickLoadFreeze (bool8 silent); void quickLoadFreeze (bool8 silent);
void quickSaveFreeze (bool8 silent); void quickSaveFreeze (bool8 silent);

File diff suppressed because it is too large Load Diff

View File

@ -10,6 +10,6 @@
#define _NGCMENU_ #define _NGCMENU_
void mainmenu (); void mainmenu (int selectedMenu);
#endif #endif

View File

@ -21,6 +21,7 @@
#include "mcsave.h" #include "mcsave.h"
#include "sdload.h" #include "sdload.h"
#include "smbload.h" #include "smbload.h"
#include "filesel.h"
extern unsigned char savebuffer[]; extern unsigned char savebuffer[];
extern int currconfig[4]; extern int currconfig[4];
@ -31,14 +32,15 @@ extern unsigned int wmpadmap[];
extern unsigned int ccpadmap[]; extern unsigned int ccpadmap[];
extern unsigned int ncpadmap[]; extern unsigned int ncpadmap[];
#define PREFSVERSTRING "Snes9x GX 004a Prefs" #define PREFS_FILE_NAME "snes9xGx.prf"
#define PREFSVERSTRING "Snes9x GX 005 Prefs"
char prefscomment[2][32] = { {PREFSVERSTRING}, {"Preferences"} }; char prefscomment[2][32] = { {PREFSVERSTRING}, {"Preferences"} };
/**************************************************************************** /****************************************************************************
* Prepare Preferences Data * Prepare Preferences Data
* *
* This sets up the save buffer for saving to a memory card. * This sets up the save buffer for saving.
****************************************************************************/ ****************************************************************************/
int int
preparePrefsData () preparePrefsData ()
@ -64,7 +66,7 @@ preparePrefsData ()
size = sizeof (GCSettings); size = sizeof (GCSettings);
memcpy (savebuffer + offset, &GCSettings, size); memcpy (savebuffer + offset, &GCSettings, size);
offset += size; offset += size;
/*** Save buttonmaps ***/ /*** Save buttonmaps ***/
size = sizeof (unsigned int) *12; // this size applies to all padmaps size = sizeof (unsigned int) *12; // this size applies to all padmaps
memcpy (savebuffer + offset, &gcpadmap, size); memcpy (savebuffer + offset, &gcpadmap, size);
@ -75,7 +77,7 @@ preparePrefsData ()
offset += size; offset += size;
memcpy (savebuffer + offset, &ncpadmap, size); memcpy (savebuffer + offset, &ncpadmap, size);
offset += size; offset += size;
return offset; return offset;
} }
@ -83,71 +85,157 @@ preparePrefsData ()
/**************************************************************************** /****************************************************************************
* Decode Preferences Data * Decode Preferences Data
****************************************************************************/ ****************************************************************************/
void bool
decodePrefsData () decodePrefsData ()
{ {
int offset; int offset;
char prefscomment[32]; char prefscomment[32];
int size; int size;
offset = sizeof (saveicon); offset = sizeof (saveicon);
memcpy (prefscomment, savebuffer + offset, 32); memcpy (prefscomment, savebuffer + offset, 32);
if ( strcmp (prefscomment, PREFSVERSTRING) == 0 ) if ( strcmp (prefscomment, PREFSVERSTRING) == 0 )
{ {
offset += 64; offset += 64;
memcpy (&Settings, savebuffer + offset, sizeof (Settings)); memcpy (&Settings, savebuffer + offset, sizeof (Settings));
offset += sizeof (Settings); offset += sizeof (Settings);
memcpy (&GCSettings, savebuffer + offset, sizeof (GCSettings)); memcpy (&GCSettings, savebuffer + offset, sizeof (GCSettings));
offset += sizeof (GCSettings); offset += sizeof (GCSettings);
// load padmaps (order important) // load padmaps (order important)
size = sizeof (unsigned int) *12; size = sizeof (unsigned int) *12;
memcpy (&gcpadmap, savebuffer + offset, size); memcpy (&gcpadmap, savebuffer + offset, size);
offset += size; offset += size;
memcpy (&wmpadmap, savebuffer + offset, size); memcpy (&wmpadmap, savebuffer + offset, size);
offset += size; offset += size;
memcpy (&ccpadmap, savebuffer + offset, size); memcpy (&ccpadmap, savebuffer + offset, size);
offset += size; offset += size;
memcpy (&ncpadmap, savebuffer + offset, size); memcpy (&ncpadmap, savebuffer + offset, size);
return true;
} }
else else
WaitPrompt((char*) "Preferences reset - check settings!"); return false;
} }
void quickLoadPrefs (bool8 silent)
/****************************************************************************
* Save Preferences
****************************************************************************/
bool
SavePrefs (int method, bool silent)
{ {
switch ( QUICK_SAVE_SLOT ) if(method == METHOD_AUTO)
method = autoSaveMethod();
bool retval = false;
char filepath[1024];
int datasize;
int offset = 0;
datasize = preparePrefsData ();
if (!silent)
ShowAction ((char*) "Saving preferences...");
if(method == METHOD_SD || method == METHOD_USB)
{ {
case CARD_SLOTA: if(method == METHOD_SD)
case CARD_SLOTB: sprintf (filepath, "%s/%s/%s", ROOTSDDIR, GCSettings.SaveFolder, PREFS_FILE_NAME);
LoadPrefsFromMC(QUICK_SAVE_SLOT, silent); else
break; sprintf (filepath, "%s/%s/%s", ROOTUSBDIR, GCSettings.SaveFolder, PREFS_FILE_NAME);
offset = SaveBufferToFAT (filepath, datasize, silent);
case CARD_SLOTA+2:
case CARD_SLOTB+2:
LoadPrefsFromSD(silent);
break;
case CARD_SLOTA+4:
LoadPrefsFromSMB(silent);
break;
} }
else if(method == METHOD_SMB)
{
sprintf (filepath, "%s\\%s", GCSettings.SaveFolder, PREFS_FILE_NAME);
offset = SaveBufferToSMB (filepath, datasize, silent);
}
else if(method == METHOD_MC_SLOTA)
{
offset = SaveBufferToMC (savebuffer, CARD_SLOTA, PREFS_FILE_NAME, datasize, silent);
}
else if(method == METHOD_MC_SLOTB)
{
offset = SaveBufferToMC (savebuffer, CARD_SLOTB, PREFS_FILE_NAME, datasize, silent);
}
if (offset > 0)
{
retval = decodePrefsData ();
if ( !silent )
{
sprintf (filepath, "Wrote %d bytes", offset);
WaitPrompt (filepath);
}
}
return retval;
} }
void quickSavePrefs (bool8 silent) /****************************************************************************
* Load Preferences
****************************************************************************/
bool
LoadPrefs (int method, bool silent)
{ {
switch ( QUICK_SAVE_SLOT ) if(method == METHOD_AUTO)
method = autoSaveMethod(); // we use 'Save' folder because preferences need R/W
bool retval = false;
char filepath[1024];
int offset = 0;
if ( !silent )
ShowAction ((char*) "Loading preferences...");
if(method == METHOD_SD || method == METHOD_USB)
{ {
case CARD_SLOTA: if(method == METHOD_SD)
case CARD_SLOTB: sprintf (filepath, "%s/%s/%s", ROOTSDDIR, GCSettings.SaveFolder, PREFS_FILE_NAME);
SavePrefsToMC(QUICK_SAVE_SLOT, silent); else
break; sprintf (filepath, "%s/%s/%s", ROOTUSBDIR, GCSettings.SaveFolder, PREFS_FILE_NAME);
case CARD_SLOTA+2: offset = LoadBufferFromFAT (filepath, silent);
case CARD_SLOTB+2:
SavePrefsToSD(silent);
break;
case CARD_SLOTA+4:
SavePrefsToSMB(silent);
break;
} }
else if(method == METHOD_SMB)
{
sprintf (filepath, "%s\\%s", GCSettings.SaveFolder, PREFS_FILE_NAME);
LoadBufferFromSMB (filepath, silent);
}
else if(method == METHOD_MC_SLOTA)
{
offset = LoadBufferFromMC (savebuffer, CARD_SLOTA, PREFS_FILE_NAME, silent);
}
else if(method == METHOD_MC_SLOTB)
{
offset = LoadBufferFromMC (savebuffer, CARD_SLOTB, PREFS_FILE_NAME, silent);
}
if (offset > 0)
{
retval = decodePrefsData ();
if ( !silent )
{
sprintf (filepath, "Loaded %d bytes", offset);
WaitPrompt(filepath);
}
}
return retval;
}
/****************************************************************************
* Quick Load Preferences
****************************************************************************/
bool quickLoadPrefs (bool8 silent)
{
return LoadPrefs(GCSettings.SaveMethod, silent);
}
/****************************************************************************
* Quick Save Preferences
****************************************************************************/
bool quickSavePrefs (bool8 silent)
{
return SavePrefs(GCSettings.SaveMethod, silent);
} }

View File

@ -9,10 +9,9 @@
* Preferences save/load preferences utilities * Preferences save/load preferences utilities
****************************************************************************/ ****************************************************************************/
#define PREFS_FILE_NAME "snes9xGx.prf"
int preparePrefsData (); int preparePrefsData ();
void decodePrefsData (); bool decodePrefsData ();
bool SavePrefs (int method, bool silent);
void quickLoadPrefs (bool8 silent); bool LoadPrefs (int method, bool silent);
void quickSavePrefs (bool8 silent); bool quickLoadPrefs (bool8 silent);
bool quickSavePrefs (bool8 silent);

View File

@ -133,8 +133,8 @@
Snes9x homepage: http://www.snes9x.com Snes9x homepage: http://www.snes9x.com
Permission to use, copy, modify and/or distribute Snes9x in both binary Permission to use, copy, modify and/or distribute Snes9x in both binary
and source form, for non-commercial purposes, is hereby granted without and source form, for non-commercial purposes, is hereby granted without
fee, providing that this license information and copyright notice appear fee, providing that this license information and copyright notice appear
with all copies and any derived work. with all copies and any derived work.
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
@ -162,81 +162,90 @@
void void
DefaultSettings () DefaultSettings ()
{ {
/*** Default ALL to false ***/ /************** GameCube/Wii Settings *********************/
memset (&Settings, 0, sizeof (Settings)); GCSettings.LoadMethod = METHOD_AUTO; // Auto, SD, DVD, USB, Network (SMB)
sprintf (GCSettings.LoadFolder,"snes9x/roms"); // Path to game files
GCSettings.SaveMethod = METHOD_AUTO; // Auto, SD, Memory Card Slot A, Memory Card Slot B, USB, Network (SMB)
sprintf (GCSettings.SaveFolder,"snes9x/saves"); // Path to save files
GCSettings.AutoLoad = 1;
GCSettings.AutoSave = 1;
strncpy (GCSettings.gcip, GC_IP, 15);
strncpy (GCSettings.gwip, GW_IP, 15);
strncpy (GCSettings.mask, MASK, 15);
strncpy (GCSettings.smbip, SMB_IP, 15);
strncpy (GCSettings.smbuser, SMB_USER, 19);
strncpy (GCSettings.smbpwd, SMB_PWD, 19);
strncpy (GCSettings.smbgcid, SMB_GCID, 19);
strncpy (GCSettings.smbsvid, SMB_SVID, 19);
strncpy (GCSettings.smbshare, SMB_SHARE, 19);
GCSettings.NGCZoom = 0;
GCSettings.VerifySaves = 0;
GCSettings.render = 0;
GCSettings.Superscope = 0;
GCSettings.Mouse = 0;
/****************** SNES9x Settings ***********************/
/*** Default ALL to false ***/
memset (&Settings, 0, sizeof (Settings));
/*** General ***/ /*** General ***/
Settings.MouseMaster = false;
Settings.SuperScopeMaster = false;
Settings.MultiPlayer5Master = false; Settings.MouseMaster = false;
Settings.JustifierMaster = true; Settings.SuperScopeMaster = false;
Settings.ShutdownMaster = false; Settings.MultiPlayer5Master = false;
Settings.CyclesPercentage = 100; // snes9x 1.50 and earlier Settings.JustifierMaster = true;
Settings.ShutdownMaster = false;
/* Eke-Eke: specific to snes9x 1.51 */ Settings.CyclesPercentage = 100; // snes9x 1.50 and earlier
// Settings.BlockInvalidVRAMAccess = true; Settings.ApplyCheats = true;
// Settings.HDMATimingHack = 100;
/* Eke-Eke: specific to snes9x 1.51 */
// Settings.BlockInvalidVRAMAccess = true;
// Settings.HDMATimingHack = 100;
/*** Sound defaults. On GC this is 32Khz/16bit/Stereo/InterpolatedSound ***/ /*** Sound defaults. On GC this is 32Khz/16bit/Stereo/InterpolatedSound ***/
Settings.APUEnabled = true; Settings.APUEnabled = true;
Settings.NextAPUEnabled = true; Settings.NextAPUEnabled = true;
Settings.SoundPlaybackRate = 32000; Settings.SoundPlaybackRate = 32000;
Settings.Stereo = true; Settings.Stereo = true;
Settings.SixteenBitSound = true; Settings.SixteenBitSound = true;
Settings.SoundEnvelopeHeightReading = true; Settings.SoundEnvelopeHeightReading = true;
Settings.DisableSampleCaching = true; Settings.DisableSampleCaching = true;
Settings.InterpolatedSound = true; Settings.InterpolatedSound = true;
Settings.ReverseStereo = false; Settings.ReverseStereo = false;
/*** Graphics ***/ /*** Graphics ***/
Settings.Transparency = true; Settings.Transparency = true;
Settings.SupportHiRes = true; Settings.SupportHiRes = true;
Settings.SkipFrames = 10; Settings.SkipFrames = 10;
Settings.TurboSkipFrames = 19; Settings.TurboSkipFrames = 19;
Settings.DisplayFrameRate = false; Settings.DisplayFrameRate = false;
// Settings.AutoDisplayMessages = 1; /*** eke-eke snes9x 1.51 ***/ // Settings.AutoDisplayMessages = 1; /*** eke-eke snes9x 1.51 ***/
/* Eke-Eke: frame timings in 50hz and 60hz cpu mode */ /* Eke-Eke: frame timings in 50hz and 60hz cpu mode */
Settings.FrameTimePAL = 20000; Settings.FrameTimePAL = 20000;
Settings.FrameTimeNTSC = 16667; Settings.FrameTimeNTSC = 16667;
/*** SDD1 - Star Ocean Returns -;) ***/ /*** SDD1 - Star Ocean Returns -;) ***/
Settings.SDD1Pack = true; Settings.SDD1Pack = true;
GCSettings.AutoLoad = 1; Settings.ForceNTSC = 0;
GCSettings.AutoSave = 1; Settings.ForcePAL = 0;
Settings.ForceHiROM = 0;
strncpy (GCSettings.gcip, GC_IP, 15); Settings.ForceLoROM = 0;
strncpy (GCSettings.gwip, GW_IP, 15); Settings.ForceHeader = 0;
strncpy (GCSettings.mask, MASK, 15); Settings.ForceNoHeader = 0;
strncpy (GCSettings.smbip, SMB_IP, 15); Settings.ForceTransparency = 0;
strncpy (GCSettings.smbuser, SMB_USER, 19); Settings.ForceInterleaved = 0;
strncpy (GCSettings.smbpwd, SMB_PWD, 19); Settings.ForceInterleaved2 = 0;
strncpy (GCSettings.smbgcid, SMB_GCID, 19); Settings.ForceInterleaveGD24 = 0;
strncpy (GCSettings.smbsvid, SMB_SVID, 19); Settings.ForceNotInterleaved = 0;
strncpy (GCSettings.smbshare, SMB_SHARE, 19); Settings.ForceNoSuperFX = 0;
Settings.ForceSuperFX = 0;
GCSettings.NGCZoom = 0; Settings.ForceDSP1 = 0;
GCSettings.VerifySaves = 0; Settings.ForceNoDSP1 = 0;
GCSettings.render = 0;
GCSettings.Superscope = 0;
GCSettings.Mouse = 0;
Settings.ForceNTSC = 0;
Settings.ForcePAL = 0;
Settings.ForceHiROM = 0;
Settings.ForceLoROM = 0;
Settings.ForceHeader = 0;
Settings.ForceNoHeader = 0;
Settings.ForceTransparency = 0;
Settings.ForceInterleaved = 0;
Settings.ForceInterleaved2 = 0;
Settings.ForceInterleaveGD24 = 0;
Settings.ForceNotInterleaved = 0;
Settings.ForceNoSuperFX = 0;
Settings.ForceSuperFX = 0;
Settings.ForceDSP1 = 0;
Settings.ForceNoDSP1 = 0;
} }

View File

@ -7,7 +7,7 @@
* *
* sdload.cpp * sdload.cpp
* *
* Load ROMS from SD Card * Load ROMS from FAT
****************************************************************************/ ****************************************************************************/
#include <gccore.h> #include <gccore.h>
#include <stdio.h> #include <stdio.h>
@ -22,20 +22,75 @@
#include "filesel.h" #include "filesel.h"
#include "sram.h" #include "sram.h"
#include "preferences.h" #include "preferences.h"
#include "snes9xGx.h"
#include <zlib.h> #include <zlib.h>
extern unsigned char savebuffer[]; extern unsigned char savebuffer[];
extern char output[16384]; extern char output[16384];
FILE * filehandle; FILE * filehandle;
char currSDdir[MAXPATHLEN]; char currFATdir[MAXPATHLEN];
extern int offset; extern int offset;
extern int selection; extern int selection;
extern int loadtype;
extern FILEENTRIES filelist[MAXFILES]; extern FILEENTRIES filelist[MAXFILES];
/****************************************************************************
* fat_is_mounted
* to check whether FAT media are detected.
****************************************************************************/
bool fat_is_mounted(PARTITION_INTERFACE partition) {
char prefix[] = "fatX:/";
prefix[3] = partition + '0';
DIR_ITER *dir = diropen(prefix);
if (dir) {
dirclose(dir);
return true;
}
return false;
}
/****************************************************************************
* fat_enable_readahead_all
****************************************************************************/
void fat_enable_readahead_all() {
int i;
for (i=1; i <= 4; ++i) {
if (fat_is_mounted((PARTITION_INTERFACE)i)) fatEnableReadAhead((PARTITION_INTERFACE)i, 64, 128);
}
}
/****************************************************************************
* fat_remount
****************************************************************************/
bool fat_remount(PARTITION_INTERFACE partition) {
//ShowAction("remounting...");
/* // removed to make usb work...
if (fat_is_mounted(partition))
{
fatUnmount(partition);
}
*/
fatMountNormalInterface(partition, 8);
fatSetDefaultInterface(partition);
//fatEnableReadAhead(partition, 64, 128);
if (fat_is_mounted(partition))
{
//ShowAction("remount successful.");
sleep(1);
return 1;
} else {
ShowAction("FAT mount failed.");
sleep(1);
return 0;
}
}
/*************************************************************************** /***************************************************************************
* FileSortCallback * FileSortCallback
* *
@ -44,7 +99,7 @@ extern FILEENTRIES filelist[MAXFILES];
* .. * ..
* <dirs> * <dirs>
* <files> * <files>
***************************************************************************/ ***************************************************************************/
static int FileSortCallback(const void *f1, const void *f2) static int FileSortCallback(const void *f1, const void *f2)
{ {
/* Special case for implicit directories */ /* Special case for implicit directories */
@ -55,101 +110,113 @@ static int FileSortCallback(const void *f1, const void *f2)
if(strcmp(((FILEENTRIES *)f1)->filename, "..") == 0) { return -1; } if(strcmp(((FILEENTRIES *)f1)->filename, "..") == 0) { return -1; }
if(strcmp(((FILEENTRIES *)f2)->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. */ /* If one is a file and one is a directory the directory is first. */
if(((FILEENTRIES *)f1)->flags == 1 && ((FILEENTRIES *)f2)->flags == 0) return -1; if(((FILEENTRIES *)f1)->flags == 1 && ((FILEENTRIES *)f2)->flags == 0) return -1;
if(((FILEENTRIES *)f1)->flags == 0 && ((FILEENTRIES *)f2)->flags == 1) return 1; if(((FILEENTRIES *)f1)->flags == 0 && ((FILEENTRIES *)f2)->flags == 1) return 1;
return stricmp(((FILEENTRIES *)f1)->filename, ((FILEENTRIES *)f2)->filename); return stricmp(((FILEENTRIES *)f1)->filename, ((FILEENTRIES *)f2)->filename);
} }
/*************************************************************************** /***************************************************************************
* Update FAT (sdcard, usb) curent directory name * Update FATCARD curent directory name
***************************************************************************/ ***************************************************************************/
int updateFATdirname() int updateFATdirname(int method)
{ {
int size=0; int size=0;
char *test; char *test;
char temp[1024]; char temp[1024];
/* current directory doesn't change */ /* current directory doesn't change */
if (strcmp(filelist[selection].filename,".") == 0) return 0; if (strcmp(filelist[selection].filename,".") == 0)
{
/* go up to parent directory */ return 0;
else if (strcmp(filelist[selection].filename,"..") == 0) }
{ /* go up to parent directory */
/* determine last subdirectory namelength */ else if (strcmp(filelist[selection].filename,"..") == 0)
sprintf(temp,"%s",currSDdir); {
test = strtok(temp,"/"); /* determine last subdirectory namelength */
while (test != NULL) { sprintf(temp,"%s",currFATdir);
size = strlen(test); test = strtok(temp,"/");
test = strtok(NULL,"/"); while (test != NULL)
} {
size = strlen(test);
/* remove last subdirectory name */ test = strtok(NULL,"/");
size = strlen(currSDdir) - size - 1; }
currSDdir[size] = 0;
/* handles root name */ /* remove last subdirectory name */
if (strcmp(currSDdir, "/") == 0) size = strlen(currFATdir) - size - 1;
currFATdir[size] = 0;
return 1; return 1;
} }
else /* Open a directory */ /* Open a directory */
{ else
/* test new directory namelength */ {
if ((strlen(currSDdir)+1+strlen(filelist[selection].filename)) < MAXPATHLEN) /* test new directory namelength */
if ((strlen(currFATdir)+1+strlen(filelist[selection].filename)) < MAXPATHLEN)
{ {
/* handles root name */ /* handles root name */
sprintf(temp, "/%s/..", SNESROMDIR); sprintf(temp, "/%s/..", GCSettings.LoadFolder);
if (strcmp(currSDdir, temp) == 0) if (strcmp(currFATdir, temp) == 0)
sprintf(currSDdir,"%s",ROOTSDDIR); {
if(method == METHOD_SD)
sprintf(currFATdir,"%s",ROOTSDDIR);
else
sprintf(currFATdir,"%s",ROOTUSBDIR);
}
/* update current directory name */ /* update current directory name */
sprintf(currSDdir, "%s/%s",currSDdir, filelist[selection].filename); sprintf(currFATdir, "%s/%s",currFATdir, filelist[selection].filename);
return 1; return 1;
} else { }
WaitPrompt((char*)"Dirname is too long !"); else
{
WaitPrompt((char*)"Dirname is too long !");
return -1; return -1;
} }
} }
} }
/*************************************************************************** /***************************************************************************
* Browse FAT (sdcard, usb) subdirectories * Browse FAT subdirectories
***************************************************************************/ ***************************************************************************/
int parseFATdirectory() { int parseFATdirectory(int method)
{
int nbfiles = 0; int nbfiles = 0;
DIR_ITER *sddir; DIR_ITER *fatdir;
char filename[MAXPATHLEN]; char filename[MAXPATHLEN];
struct stat filestat; struct stat filestat;
char msg[128]; char msg[128];
/* initialize selection */ /* initialize selection */
selection = offset = 0; selection = offset = 0;
/* open the directory */ /* open the directory */
sddir = diropen(currSDdir); fatdir = diropen(currFATdir);
if (sddir == NULL) { if (fatdir == NULL)
/*** if we can't open the previous dir, open root dir ***/ {
if (loadtype == LOAD_USB) sprintf(msg, "Error opening %s", currFATdir);
sprintf(currSDdir,"fat4:/");
else // LOAD_SDC
//sprintf(currSDdir,"%s",ROOTSDDIR);
sprintf(currSDdir,"fat3:/");
sddir = diropen(currSDdir);
WaitPrompt(msg); WaitPrompt(msg);
if (sddir == NULL) {
sprintf(msg, "Error opening %s", currSDdir); // if we can't open the previous dir, open root dir
if(method == METHOD_SD)
sprintf(currFATdir,"%s",ROOTSDDIR);
else
sprintf(currFATdir,"%s",ROOTUSBDIR);
fatdir = diropen(currFATdir);
if (fatdir == NULL)
{
sprintf(msg, "Error opening %s", currFATdir);
WaitPrompt(msg); WaitPrompt(msg);
return 0; return 0;
} }
} }
/* Move to DVD structure - this is required for the file selector */ /* Move to DVD structure - this is required for the file selector */
while(dirnext(sddir,filename,&filestat) == 0) { while(dirnext(fatdir,filename,&filestat) == 0) {
if(strcmp(filename,".") != 0) { if(strcmp(filename,".") != 0) {
memset(&filelist[nbfiles], 0, sizeof(FILEENTRIES)); memset(&filelist[nbfiles], 0, sizeof(FILEENTRIES));
strncpy(filelist[nbfiles].filename, filename, MAXPATHLEN); strncpy(filelist[nbfiles].filename, filename, MAXPATHLEN);
@ -159,23 +226,22 @@ int parseFATdirectory() {
nbfiles++; nbfiles++;
} }
} }
/*** close directory ***/ /*** close directory ***/
dirclose(sddir); dirclose(fatdir);
/* Sort the file list */ /* Sort the file list */
qsort(filelist, nbfiles, sizeof(FILEENTRIES), FileSortCallback); qsort(filelist, nbfiles, sizeof(FILEENTRIES), FileSortCallback);
return nbfiles; return nbfiles;
} }
/**************************************************************************** /****************************************************************************
* LoadSDFile * LoadFATFile
****************************************************************************/ ****************************************************************************/
extern bool haveSDdir; extern int haveFATdir;
extern bool haveUSBdir;
int int
LoadSDFile (char *filename, int length) LoadFATFile (char *filename, int length)
{ {
char zipbuffer[2048]; char zipbuffer[2048];
char filepath[MAXPATHLEN]; char filepath[MAXPATHLEN];
@ -186,16 +252,15 @@ LoadSDFile (char *filename, int length)
rbuffer = (unsigned char *) Memory.ROM; rbuffer = (unsigned char *) Memory.ROM;
/* Check filename length */ /* Check filename length */
if ((strlen(currSDdir)+1+strlen(filelist[selection].filename)) < MAXPATHLEN) if ((strlen(currFATdir)+1+strlen(filelist[selection].filename)) < MAXPATHLEN)
sprintf(filepath, "%s/%s",currSDdir,filelist[selection].filename); sprintf(filepath, "%s/%s",currFATdir,filelist[selection].filename);
else else
{ {
WaitPrompt((char*) "Maximum Filename Length reached !"); WaitPrompt((char*) "Maximum Filename Length reached !");
haveSDdir = 0; // reset everything before next access haveFATdir = 0; // reset everything before next access
haveUSBdir = 0;
return -1; return -1;
} }
handle = fopen (filepath, "rb"); handle = fopen (filepath, "rb");
if (handle > 0) if (handle > 0)
{ {
@ -204,7 +269,7 @@ LoadSDFile (char *filename, int length)
if (IsZipFile (zipbuffer)) if (IsZipFile (zipbuffer))
{ {
/*** Unzip the ROM ***/ /*** Unzip the ROM ***/
size = UnZipBuffer (rbuffer, 0, 0, handle); // unzip from SD size = UnZipBuffer (rbuffer, 0, 0, handle); // unzip from FAT
fclose (handle); fclose (handle);
return size; return size;
@ -213,17 +278,17 @@ LoadSDFile (char *filename, int length)
else else
{ {
/*** Just load the file up ***/ /*** Just load the file up ***/
fseek(handle, 0, SEEK_END); fseek(handle, 0, SEEK_END);
length = ftell(handle); // get filesize length = ftell(handle); // get filesize
fseek(handle, 2048, SEEK_SET); // seek back to point where we left off fseek(handle, 2048, SEEK_SET); // seek back to point where we left off
sprintf (filepath, "Loading %d bytes", length); sprintf (filepath, "Loading %d bytes", length);
ShowAction (filepath); ShowAction (filepath);
memcpy (rbuffer, zipbuffer, 2048); // copy what we already read memcpy (rbuffer, zipbuffer, 2048); // copy what we already read
fread (rbuffer + 2048, 1, length - 2048, handle); fread (rbuffer + 2048, 1, length - 2048, handle);
fclose (handle); fclose (handle);
return length; return length;
} }
} }
@ -236,20 +301,18 @@ LoadSDFile (char *filename, int length)
return 0; return 0;
} }
/**************************************************************************** /****************************************************************************
* Load savebuffer from SD card file * Load savebuffer from FAT file
****************************************************************************/ ****************************************************************************/
int int
LoadBufferFromSD (char *filepath, bool silent) LoadBufferFromFAT (char *filepath, bool silent)
{ {
FILE *handle; FILE *handle;
int offset = 0; int offset = 0;
int read = 0; int read = 0;
handle = fopen (filepath, "rb"); handle = fopen (filepath, "rb");
if (handle <= 0) if (handle <= 0)
{ {
if ( !silent ) if ( !silent )
@ -260,33 +323,32 @@ LoadBufferFromSD (char *filepath, bool silent)
} }
return 0; return 0;
} }
memset (savebuffer, 0, 0x22000); memset (savebuffer, 0, 0x22000);
/*** This is really nice, just load the file and decode it ***/ /*** This is really nice, just load the file and decode it ***/
while ((read = fread (savebuffer + offset, 1, 1024, handle)) > 0) while ((read = fread (savebuffer + offset, 1, 1024, handle)) > 0)
{ {
offset += read; offset += read;
} }
fclose (handle); fclose (handle);
return offset; return offset;
} }
/**************************************************************************** /****************************************************************************
* Write savebuffer to SD card file * Write savebuffer to FAT card file
****************************************************************************/ ****************************************************************************/
int int
SaveBufferToSD (char *filepath, int datasize, bool silent) SaveBufferToFAT (char *filepath, int datasize, bool silent)
{ {
FILE *handle; FILE *handle;
if (datasize) if (datasize)
{ {
handle = fopen (filepath, "wb"); handle = fopen (filepath, "wb");
if (handle <= 0) if (handle <= 0)
{ {
char msg[100]; char msg[100];
@ -294,152 +356,10 @@ SaveBufferToSD (char *filepath, int datasize, bool silent)
WaitPrompt (msg); WaitPrompt (msg);
return 0; return 0;
} }
fwrite (savebuffer, 1, datasize, handle); fwrite (savebuffer, 1, datasize, handle);
fclose (handle); fclose (handle);
} }
return datasize; return datasize;
} }
/****************************************************************************
* Save SRAM to SD Card
****************************************************************************/
void SaveSRAMToSD (bool silent)
{
char filepath[1024];
int datasize;
int offset;
if (!silent)
ShowAction ((char*) "Saving SRAM to SD...");
#ifdef SDUSE_LFN
sprintf (filepath, "%s/%s/%s.srm", ROOTSDDIR, SNESSAVEDIR, Memory.ROMFilename);
#else
sprintf (filepath, "%s/%s/%08x.srm", ROOTSDDIR, SNESSAVEDIR, Memory.ROMCRC32);
#endif
datasize = prepareEXPORTsavedata ();
if ( datasize )
{
offset = SaveBufferToSD (filepath, datasize, silent);
if ( (offset > 0) && (!silent) )
{
sprintf (filepath, "Wrote %d bytes", offset);
WaitPrompt (filepath);
}
}
}
/****************************************************************************
* Load SRAM From SD Card
****************************************************************************/
void
LoadSRAMFromSD (bool silent)
{
char filepath[MAXPATHLEN];
int offset = 0;
ShowAction ((char*) "Loading SRAM from SD...");
// check for 'old' version of sram
sprintf (filepath, "%s/%s/%s.srm", ROOTSDDIR, SNESSAVEDIR, Memory.ROMName); // Build old SRAM filename
offset = LoadBufferFromSD (filepath, silent); // load file
if (offset > 0) // old sram found
{
if (WaitPromptChoice ((char*)"Old SRAM found. Convert and delete?", (char*)"Cancel", (char*)"Do it"))
{
decodesavedata (offset);
remove (filepath); // delete old sram
SaveSRAMToSD (silent);
}
}
//
#ifdef SDUSE_LFN
sprintf (filepath, "%s/%s/%s.srm", ROOTSDDIR, SNESSAVEDIR, Memory.ROMFilename);
#else
sprintf (filepath, "%s/%s/%08x.srm", ROOTSDDIR, SNESSAVEDIR, Memory.ROMCRC32);
#endif
offset = LoadBufferFromSD (filepath, silent);
if (offset > 0)
{
decodesavedata (offset);
if ( !silent )
{
sprintf (filepath, "Loaded %d bytes", offset);
WaitPrompt(filepath);
}
S9xSoftReset();
}
}
/****************************************************************************
* Save Preferences to SD Card
****************************************************************************/
void
SavePrefsToSD (bool silent)
{
char filepath[1024];
int datasize;
int offset;
if (!silent)
ShowAction ((char*) "Saving prefs to SD...");
#ifdef SDUSE_LFN
sprintf (filepath, "%s/%s/%s", ROOTSDDIR, SNESSAVEDIR, PREFS_FILE_NAME);
#else
sprintf (filepath, "%s/%s/%s", ROOTSDDIR, SNESSAVEDIR, PREFS_FILE_NAME);
#endif
datasize = preparePrefsData ();
offset = SaveBufferToSD (filepath, datasize, silent);
if ( (offset > 0) && (!silent) )
{
sprintf (filepath, "Wrote %d bytes", offset);
WaitPrompt (filepath);
}
}
/****************************************************************************
* Load Preferences from SD Card
****************************************************************************/
void
LoadPrefsFromSD (bool silent)
{
char filepath[1024];
int offset = 0;
ShowAction ((char*) "Loading prefs from SD...");
#ifdef SDUSE_LFN
sprintf (filepath, "%s/%s/%s", ROOTSDDIR, SNESSAVEDIR, PREFS_FILE_NAME);
#else
sprintf (filepath, "%s/%s/%s", ROOTSDDIR, SNESSAVEDIR, PREFS_FILE_NAME);
#endif
offset = LoadBufferFromSD (filepath, silent);
if (offset > 0)
{
decodePrefsData ();
if ( !silent )
{
sprintf (filepath, "Loaded %d bytes", offset);
WaitPrompt(filepath);
}
}
}

View File

@ -21,15 +21,17 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
static int FileSortCallback(const void *f1, const void *f2); #define ROOTSDDIR "fat3:/"
int updateFATdirname(); #define ROOTUSBDIR "fat4:/"
int parseFATdirectory();
int LoadSDFile (char *filename, int length);
void SaveSRAMToSD (bool silent);
void LoadSRAMFromSD (bool silent);
void SavePrefsToSD (bool silent);
void LoadPrefsFromSD (bool silent);
extern char currSDdir[MAXPATHLEN]; bool fat_remount(PARTITION_INTERFACE partition);
static int FileSortCallback(const void *f1, const void *f2);
int updateFATdirname(int method);
int parseFATdirectory(int method);
int LoadFATFile (char *filename, int length);
int SaveBufferToFAT (char *filepath, int datasize, bool silent);
int LoadBufferFromFAT (char *filepath, bool silent);
extern char currFATdir[MAXPATHLEN];
#endif #endif

View File

@ -53,26 +53,26 @@ void
ConnectSMB () ConnectSMB ()
{ {
int ret; int ret;
if (SMBTimer > SMBTIMEOUT) if (SMBTimer > SMBTIMEOUT)
{ {
connected = 0; connected = 0;
SMBTimer = 0; SMBTimer = 0;
} }
if (connected == 0) if (connected == 0)
{ {
if (netinited == 0) if (netinited == 0)
{ {
ShowAction ((char*) "Setting up network interface ..."); ShowAction ((char*) "Setting up network interface ...");
ret = if_config (smbinfo.gcip, smbinfo.gwip, smbinfo.mask, 0); ret = if_config (smbinfo.gcip, smbinfo.gwip, smbinfo.mask, 0);
netinited = 1; netinited = 1;
} }
ShowAction ((char*) "Connecting to share ..."); ShowAction ((char*) "Connecting to share ...");
SMB_Destroy (); SMB_Destroy ();
if (SMB_Init (smbinfo.smbuser, smbinfo.smbpwd, if (SMB_Init (smbinfo.smbuser, smbinfo.smbpwd,
smbinfo.smbgcid, smbinfo.smbsvid, smbinfo.smbshare, smbinfo.smbgcid, smbinfo.smbsvid, smbinfo.smbshare,
smbinfo.smbip) != SMB_SUCCESS) smbinfo.smbip) != SMB_SUCCESS)
@ -82,7 +82,7 @@ ConnectSMB ()
return; return;
} }
} }
connected = 1; connected = 1;
} }
@ -101,7 +101,7 @@ parseSMBDirectory ()
ConnectSMB (); ConnectSMB ();
strcpy (searchpath, SNESROMDIR); strcpy (searchpath, GCSettings.LoadFolder);
strcat (searchpath, "\\*.*"); strcat (searchpath, "\\*.*");
if (SMB_FindFirst if (SMB_FindFirst
@ -152,7 +152,7 @@ LoadSMBFile (char *filename, int length)
z_stream zs; z_stream zs;
int res, outbytes; int res, outbytes;
strcpy (filepath, SNESROMDIR); strcpy (filepath, GCSettings.LoadFolder);
strcat (filepath, "\\"); strcat (filepath, "\\");
strcat (filepath, filename); strcat (filepath, filename);
rbuffer = (char *) Memory.ROM; rbuffer = (char *) Memory.ROM;
@ -160,10 +160,10 @@ LoadSMBFile (char *filename, int length)
int have = 0; int have = 0;
ConnectSMB (); ConnectSMB ();
if ( connected ) if ( connected )
{ {
/*** Open the file for reading ***/ /*** Open the file for reading ***/
smbfile = smbfile =
SMB_Open (filepath, SMB_OPEN_READING | SMB_DENY_NONE, SMB_OF_OPEN); SMB_Open (filepath, SMB_OPEN_READING | SMB_DENY_NONE, SMB_OF_OPEN);
@ -172,7 +172,7 @@ LoadSMBFile (char *filename, int length)
while (total < length) while (total < length)
{ {
bytesread = SMB_Read (zipbuffer, 16384, offset, smbfile); bytesread = SMB_Read (zipbuffer, 16384, offset, smbfile);
if (pass == 0) if (pass == 0)
{ {
/*** Is this a Zip file ? ***/ /*** Is this a Zip file ? ***/
@ -188,13 +188,13 @@ LoadSMBFile (char *filename, int length)
zs.avail_in = 0; zs.avail_in = 0;
zs.next_in = Z_NULL; zs.next_in = Z_NULL;
res = inflateInit2 (&zs, -MAX_WBITS); res = inflateInit2 (&zs, -MAX_WBITS);
if (res != Z_OK) if (res != Z_OK)
{ {
SMB_Close (smbfile); SMB_Close (smbfile);
return 0; return 0;
} }
zs.avail_in = zs.avail_in =
16384 - (sizeof (PKZIPHEADER) + 16384 - (sizeof (PKZIPHEADER) +
FLIP16 (pkzip.filenameLength) + FLIP16 (pkzip.filenameLength) +
@ -205,7 +205,7 @@ LoadSMBFile (char *filename, int length)
FLIP16 (pkzip.extraDataLength)); FLIP16 (pkzip.extraDataLength));
} }
} }
if (zip) if (zip)
{ {
if (pass) if (pass)
@ -213,16 +213,16 @@ LoadSMBFile (char *filename, int length)
zs.avail_in = bytesread; zs.avail_in = bytesread;
zs.next_in = (Bytef *) zipbuffer; zs.next_in = (Bytef *) zipbuffer;
} }
do do
{ {
zs.avail_out = ZIPCHUNK; zs.avail_out = ZIPCHUNK;
zs.next_out = (Bytef *) output; zs.next_out = (Bytef *) output;
res = inflate (&zs, Z_NO_FLUSH); res = inflate (&zs, Z_NO_FLUSH);
have = ZIPCHUNK - zs.avail_out; have = ZIPCHUNK - zs.avail_out;
if (have) if (have)
{ {
memcpy (rbuffer + outbytes, output, have); memcpy (rbuffer + outbytes, output, have);
@ -233,10 +233,10 @@ LoadSMBFile (char *filename, int length)
} }
else else
memcpy (rbuffer + offset, zipbuffer, bytesread); memcpy (rbuffer + offset, zipbuffer, bytesread);
total += bytesread; total += bytesread;
offset += bytesread; offset += bytesread;
if (!zip) if (!zip)
{ {
sprintf (buffer, "Read %d of %d bytes", total, length); sprintf (buffer, "Read %d of %d bytes", total, length);
@ -249,19 +249,19 @@ LoadSMBFile (char *filename, int length)
ShowProgress (buffer, outbytes, pkzip.uncompressedSize); ShowProgress (buffer, outbytes, pkzip.uncompressedSize);
} }
//ShowAction (buffer); //ShowAction (buffer);
pass++; pass++;
} }
if (zip) if (zip)
{ {
inflateEnd (&zs); inflateEnd (&zs);
total = outbytes; total = outbytes;
} }
SMB_Close (smbfile); SMB_Close (smbfile);
return total; return total;
} }
else else
@ -271,7 +271,7 @@ LoadSMBFile (char *filename, int length)
return 0; return 0;
} }
} }
return 0; return 0;
} }
@ -286,15 +286,15 @@ SaveBufferToSMB (char *filepath, int datasize, bool8 silent)
int dsize = datasize; int dsize = datasize;
int wrote = 0; int wrote = 0;
int offset = 0; int offset = 0;
ConnectSMB (); ConnectSMB ();
if ( connected ) if ( connected )
{ {
smbfile = smbfile =
SMB_Open (filepath, SMB_OPEN_WRITING | SMB_DENY_NONE, SMB_Open (filepath, SMB_OPEN_WRITING | SMB_DENY_NONE,
SMB_OF_CREATE | SMB_OF_TRUNCATE); SMB_OF_CREATE | SMB_OF_TRUNCATE);
if (smbfile) if (smbfile)
{ {
while (dsize > 0) while (dsize > 0)
@ -305,14 +305,14 @@ SaveBufferToSMB (char *filepath, int datasize, bool8 silent)
else else
wrote = wrote =
SMB_Write ((char *) savebuffer + offset, dsize, offset, smbfile); SMB_Write ((char *) savebuffer + offset, dsize, offset, smbfile);
offset += wrote; offset += wrote;
dsize -= wrote; dsize -= wrote;
} }
SMB_Close (smbfile); SMB_Close (smbfile);
SMBTimer = 0; SMBTimer = 0;
return offset; return offset;
} }
else else
@ -322,7 +322,7 @@ SaveBufferToSMB (char *filepath, int datasize, bool8 silent)
WaitPrompt (msg); WaitPrompt (msg);
} }
} }
return 0; return 0;
} }
@ -332,18 +332,19 @@ SaveBufferToSMB (char *filepath, int datasize, bool8 silent)
****************************************************************************/ ****************************************************************************/
int int
LoadBufferFromSMB (char *filepath, bool8 silent) LoadBufferFromSMB (char *filepath, bool8 silent)
{ {
SMBFILE smbfile; SMBFILE smbfile;
int ret; int ret;
int offset = 0; int offset = 0;
ConnectSMB (); ConnectSMB ();
if ( connected ) if ( connected )
{ {
smbfile = smbfile =
SMB_Open (filepath, SMB_OPEN_READING | SMB_DENY_NONE, SMB_OF_OPEN); SMB_Open (filepath, SMB_OPEN_READING | SMB_DENY_NONE, SMB_OF_OPEN);
if (!smbfile) if (!smbfile)
{ {
if (!silent) if (!silent)
@ -354,131 +355,18 @@ LoadBufferFromSMB (char *filepath, bool8 silent)
} }
return 0; return 0;
} }
memset (savebuffer, 0, 0x22000); memset (savebuffer, 0, 0x22000);
while ((ret = while ((ret =
SMB_Read ((char *) savebuffer + offset, 1024, offset, SMB_Read ((char *) savebuffer + offset, 1024, offset,
smbfile)) > 0) smbfile)) > 0)
offset += ret; offset += ret;
SMB_Close (smbfile); SMB_Close (smbfile);
return offset; return offset;
} }
return 0; return 0;
} }
/****************************************************************************
* Save SRAM to SMB
****************************************************************************/
void
SaveSRAMToSMB (bool8 silent)
{
char filepath[1024];
int datasize;
int offset;
sprintf (filepath, "%s\\%s.srm", SNESSAVEDIR, Memory.ROMFilename);
if (!silent)
ShowAction ((char*) "Saving SRAM to SMB...");
datasize = prepareEXPORTsavedata ();
if ( datasize )
{
offset = SaveBufferToSMB (filepath, datasize, silent);
if ( (offset > 0) && (!silent) )
{
sprintf (filepath, "Wrote %d bytes", offset);
WaitPrompt (filepath);
}
}
}
/****************************************************************************
* Load SRAM from SMB
****************************************************************************/
void
LoadSRAMFromSMB (bool8 silent)
{
char filepath[1024];
int offset;
sprintf (filepath, "%s\\%s.srm", SNESSAVEDIR, Memory.ROMFilename);
ShowAction ((char*) "Loading SRAM from SMB...");
offset = LoadBufferFromSMB (filepath, silent);
if (offset > 0)
{
decodesavedata (offset);
if ( !silent )
{
sprintf (filepath, "Loaded %d bytes", offset);
WaitPrompt(filepath);
}
S9xSoftReset();
}
}
/****************************************************************************
* Save Preferences to SMB
****************************************************************************/
void
SavePrefsToSMB (bool8 silent)
{
char filepath[1024];
int datasize;
int offset;
sprintf (filepath, "%s\\%s", SNESSAVEDIR, PREFS_FILE_NAME);
if (!silent)
ShowAction ((char*) "Saving preferences to SMB...");
datasize = preparePrefsData ();
if ( datasize )
{
offset = SaveBufferToSMB (filepath, datasize, silent);
if ( (offset > 0) && (!silent) )
{
sprintf (filepath, "Wrote %d bytes", offset);
WaitPrompt (filepath);
}
}
}
/****************************************************************************
* Load Preferences from SMB
****************************************************************************/
void
LoadPrefsFromSMB (bool8 silent)
{
char filepath[1024];
int offset;
ShowAction ((char*) "Loading preferences from SMB...");
sprintf (filepath, "%s\\%s", SNESSAVEDIR, PREFS_FILE_NAME);
offset = LoadBufferFromSMB (filepath, silent);
if (offset > 0)
{
decodePrefsData ();
if ( !silent )
{
sprintf (filepath, "Loaded %d bytes", offset);
WaitPrompt(filepath);
}
}
}

View File

@ -11,15 +11,14 @@
****************************************************************************/ ****************************************************************************/
#ifndef _NGCSMB_ #ifndef _NGCSMB_
#define _NGCSMB_ #define _NGCSMB_
void ConnectSMB (); void ConnectSMB ();
int parseSMBDirectory (); int parseSMBDirectory ();
int LoadSMBFile (char *filename, int length); int LoadSMBFile (char *filename, int length);
void SaveSRAMToSMB (bool8 silent); int LoadBufferFromSMB (char *filepath, bool8 silent);
void LoadSRAMFromSMB (bool8 silent); int SaveBufferToSMB (char *filepath, int datasize, bool8 silent);
void SavePrefsToSMB (bool8 silent);
void LoadPrefsFromSMB (bool8 silent);
typedef struct typedef struct
{ {
@ -35,4 +34,5 @@ typedef struct
} }
SMBINFO; SMBINFO;
#endif #endif

View File

@ -131,8 +131,8 @@
Snes9x homepage: http://www.snes9x.com Snes9x homepage: http://www.snes9x.com
Permission to use, copy, modify and/or distribute Snes9x in both binary Permission to use, copy, modify and/or distribute Snes9x in both binary
and source form, for non-commercial purposes, is hereby granted without and source form, for non-commercial purposes, is hereby granted without
fee, providing that this license information and copyright notice appear fee, providing that this license information and copyright notice appear
with all copies and any derived work. with all copies and any derived work.
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
@ -159,11 +159,11 @@
#include <ogcsys.h> #include <ogcsys.h>
#include <unistd.h> #include <unistd.h>
#include <fat.h>
#include <wiiuse/wpad.h> #include <wiiuse/wpad.h>
#include <sdcard/card_cmn.h> #include <sdcard/card_cmn.h>
#include <sdcard/wiisd_io.h> #include <sdcard/wiisd_io.h>
#include <sdcard/card_io.h> #include <sdcard/card_io.h>
#include <fat.h>
#include "snes9x.h" #include "snes9x.h"
#include "memmap.h" #include "memmap.h"
@ -190,6 +190,7 @@
#include "preferences.h" #include "preferences.h"
#include "gctime.h" #include "gctime.h"
#include "button_mapping.h" #include "button_mapping.h"
#include "sdload.h"
unsigned long ARAM_ROMSIZE = 0; unsigned long ARAM_ROMSIZE = 0;
int ConfigRequested = 0; int ConfigRequested = 0;
@ -523,8 +524,7 @@ NGCReportButtons ()
if ( GCSettings.AutoSave == 1 ) if ( GCSettings.AutoSave == 1 )
{ {
//if ( WaitPromptChoice ((char*)"Save SRAM?", (char*)"Don't Save", (char*)"Save") ) quickSaveSRAM ( SILENT );
quickSaveSRAM ( SILENT );
} }
else if ( GCSettings.AutoSave == 2 ) else if ( GCSettings.AutoSave == 2 )
{ {
@ -540,7 +540,7 @@ NGCReportButtons ()
} }
} }
mainmenu (); mainmenu (3); // go to game menu
FrameTimer = 0; FrameTimer = 0;
ConfigRequested = 0; ConfigRequested = 0;
@ -613,6 +613,7 @@ void SetControllers ()
} }
} }
/**************************************************************************** /****************************************************************************
* Set the default mapping for NGC * Set the default mapping for NGC
****************************************************************************/ ****************************************************************************/
@ -692,7 +693,7 @@ SetDefaultButtonMap ()
maxcode = 0x60; maxcode = 0x60;
S9xMapPointer( maxcode++, S9xGetCommandT("Pointer Superscope"), false); S9xMapPointer( maxcode++, S9xGetCommandT("Pointer Superscope"), false);
// add mouses here // add mouses here
SetControllers (); SetControllers ();
} }
@ -701,7 +702,7 @@ SetDefaultButtonMap ()
* Emulation loop * Emulation loop
* *
* The 'clock' timer is long gone. * The 'clock' timer is long gone.
* System now only uses vbl as hardware clock, so force PAL50 if you need 50hz * System now only uses vbl as hardware clock, so force PAL50 if you need 50hz
****************************************************************************/ ****************************************************************************/
/* Eke-Eke: initialize frame Sync */ /* Eke-Eke: initialize frame Sync */
extern void S9xInitSync(); extern void S9xInitSync();
@ -714,7 +715,7 @@ emulate ()
AudioStart (); AudioStart ();
S9xInitSync(); S9xInitSync();
setFrameTimerMethod(); // also called in NGCReportButtons() setFrameTimerMethod(); // also called in NGCReportButtons()
while (1) while (1)
{ {
@ -747,19 +748,19 @@ int
main () main ()
{ {
unsigned int save_flags; unsigned int save_flags;
int selectedMenu = -1;
/*** Initialise GC ***/ /*** Initialise GC ***/
InitGCVideo (); /*** Get the ball rolling ***/ InitGCVideo (); /*** Get the ball rolling ***/
/*** Initialize libFAT and SD cards ***/ /*** Initialize libFAT for SD and USB ***/
fatInitDefault(); fatInitDefault();
//fatInit(8192, false); //fatInit(8192, false);
//fat_enable_readahead_all(); //fat_enable_readahead_all();
/*** Initialize DVD subsystem ***/ /*** Initialize DVD subsystem ***/
DVD_Init (); DVD_Init ();
#ifdef FORCE_WII #ifdef FORCE_WII
isWii = TRUE; isWii = TRUE;
#else #else
@ -777,61 +778,63 @@ main ()
WPAD_SetVRes(WPAD_CHAN_ALL,640,480); WPAD_SetVRes(WPAD_CHAN_ALL,640,480);
#endif #endif
/*** Initialise freetype ***/ /*** Initialise freetype ***/
if (FT_Init ()) if (FT_Init ())
{ {
printf ("Cannot initialise font subsystem!\n"); printf ("Cannot initialise font subsystem!\n");
while (1); while (1);
} }
setfontsize (16);/***sets the font size.***/
/*** Set defaults ***/ /*** Set defaults ***/
DefaultSettings (); DefaultSettings ();
S9xUnmapAllControls (); S9xUnmapAllControls ();
SetDefaultButtonMap (); SetDefaultButtonMap ();
printf ("Initialise Memory\n"); printf ("Initialise Memory\n");
/*** Allocate SNES Memory ***/ /*** Allocate SNES Memory ***/
if (!Memory.Init ()) if (!Memory.Init ())
while (1); while (1);
printf ("Initialise APU\n"); printf ("Initialise APU\n");
/*** Allocate APU ***/ /*** Allocate APU ***/
if (!S9xInitAPU ()) if (!S9xInitAPU ())
while (1); while (1);
/*** Set Pixel Renderer to match 565 ***/ /*** Set Pixel Renderer to match 565 ***/
S9xSetRenderPixelFormat (RGB565); S9xSetRenderPixelFormat (RGB565);
/*** Initialise Snes Sound System ***/ /*** Initialise Snes Sound System ***/
S9xInitSound (5, TRUE, 1024); S9xInitSound (5, TRUE, 1024);
printf ("Initialise GFX\n"); printf ("Initialise GFX\n");
/*** Initialise Graphics ***/ /*** Initialise Graphics ***/
setGFX (); setGFX ();
if (!S9xGraphicsInit ()) if (!S9xGraphicsInit ())
while (1); while (1);
legal (); unpackbackdrop ();
WaitButtonA ();
// Load preferences // Load preferences
quickLoadPrefs(SILENT); if(!quickLoadPrefs(SILENT))
{
WaitPrompt((char*) "Preferences reset - check settings!");
selectedMenu = 2; // change to preferences menu
}
// Correct any relevant saved settings that are invalid // Correct any relevant saved settings that are invalid
Settings.FrameTimeNTSC = 16667; Settings.FrameTimeNTSC = 16667;
Settings.FrameTimePAL = 20000; Settings.FrameTimePAL = 20000;
if ( Settings.TurboSkipFrames <= Settings.SkipFrames ) if ( Settings.TurboSkipFrames <= Settings.SkipFrames )
Settings.TurboSkipFrames = 20; Settings.TurboSkipFrames = 20;
/*** No appended ROM, so get the user to load one ***/ /*** No appended ROM, so get the user to load one ***/
if (ARAM_ROMSIZE == 0) if (ARAM_ROMSIZE == 0)
{ {
while (ARAM_ROMSIZE == 0) while (ARAM_ROMSIZE == 0)
{ {
mainmenu (); mainmenu (selectedMenu);
} }
} }
else else
@ -841,14 +844,14 @@ main ()
if (!Memory.LoadROM ("VIRTUAL.ROM")) if (!Memory.LoadROM ("VIRTUAL.ROM"))
while (1); while (1);
CPU.Flags = save_flags; CPU.Flags = save_flags;
/*** Load SRAM ***/ /*** Load SRAM ***/
Memory.LoadSRAM ("DVD"); Memory.LoadSRAM ("DVD");
} }
/*** Emulate ***/ /*** Emulate ***/
emulate (); emulate ();
/*** NO! - We're never leaving here ! ***/ /*** NO! - We're never leaving here ! ***/
while (1); while (1);
return 0; return 0;

View File

@ -131,8 +131,8 @@
Snes9x homepage: http://www.snes9x.com Snes9x homepage: http://www.snes9x.com
Permission to use, copy, modify and/or distribute Snes9x in both binary Permission to use, copy, modify and/or distribute Snes9x in both binary
and source form, for non-commercial purposes, is hereby granted without and source form, for non-commercial purposes, is hereby granted without
fee, providing that this license information and copyright notice appear fee, providing that this license information and copyright notice appear
with all copies and any derived work. with all copies and any derived work.
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
@ -166,9 +166,23 @@
#define NOTSILENT 0 #define NOTSILENT 0
#define SILENT 1 #define SILENT 1
enum {
METHOD_AUTO,
METHOD_SD,
METHOD_USB,
METHOD_DVD,
METHOD_SMB,
METHOD_MC_SLOTA,
METHOD_MC_SLOTB
};
struct SGCSettings{ struct SGCSettings{
uint8 AutoLoad; uint8 AutoLoad;
uint8 AutoSave; uint8 AutoSave;
uint8 LoadMethod; // For ROMS: Auto, SD, DVD, USB, Network (SMB)
char LoadFolder[200]; // Path to game files
uint8 SaveMethod; // For SRAM, Freeze, Prefs: Auto, SD, Memory Card Slot A, Memory Card Slot B, USB, SMB
char SaveFolder[200]; // Path to save files
char gcip[16]; char gcip[16];
char gwip[16]; char gwip[16];
char mask[16]; char mask[16];
@ -181,9 +195,8 @@ struct SGCSettings{
bool8 NGCZoom; bool8 NGCZoom;
uint8 VerifySaves; uint8 VerifySaves;
u16 render; // 0 - original, 1 - no AA u16 render; // 0 - original, 1 - no AA
u32 QuickSaveSlot; // -1 Disabled - no prefs are loaded, 0 Memory card in slot A, 1 Memory card in slot B, 2 SD card in slot A, 3 SD card in slot B, 4 SMB share, 5 USB u16 Superscope;
u16 Superscope; u16 Mouse;
u16 Mouse;
}; };
START_EXTERN_C START_EXTERN_C
@ -197,21 +210,6 @@ END_EXTERN_C
#define JOY_THRESHOLD 0.70 // for wii (expansion) analogues #define JOY_THRESHOLD 0.70 // for wii (expansion) analogues
#endif
/*** QUICK_SAVE_SLOT defines where preferences are loaded and saved, and also
where SRAM and Freezes are auto loaded or saved if enabled:
-1 Disabled - no prefs are loaded
0 Memory card in slot A
1 Memory card in slot B
2 SD card in slot A
3 SD card in slot B
4 SMB share ***/
#ifndef QUICK_SAVE_SLOT
#define QUICK_SAVE_SLOT 2 // save to SD
#endif
/*** default SMB settings ***/ /*** default SMB settings ***/
#ifndef GC_IP #ifndef GC_IP
#define GC_IP "192.168.1.32" /*** IP to assign the GameCube ***/ #define GC_IP "192.168.1.32" /*** IP to assign the GameCube ***/
@ -240,3 +238,5 @@ END_EXTERN_C
#ifndef SMB_IP #ifndef SMB_IP
#define SMB_IP "192.168.1.100" /*** IP Address of share server ***/ #define SMB_IP "192.168.1.100" /*** IP Address of share server ***/
#endif #endif
#endif

View File

@ -21,14 +21,13 @@
#include "mcsave.h" #include "mcsave.h"
#include "sdload.h" #include "sdload.h"
#include "smbload.h" #include "smbload.h"
#include "filesel.h"
extern unsigned char savebuffer[]; extern unsigned char savebuffer[];
//extern int currconfig[4];
extern int padcal; extern int padcal;
extern unsigned short gcpadmap[]; extern unsigned short gcpadmap[];
//extern unsigned short padmap[4];
char sramcomment[2][32] = { {"Snes9x GX 004 SRAM"}, {"Savegame"} }; char sramcomment[2][32] = { {"Snes9x GX 005 SRAM"}, {"Savegame"} };
/**************************************************************************** /****************************************************************************
* Prepare Memory Card SRAM Save Data * Prepare Memory Card SRAM Save Data
@ -47,7 +46,7 @@ prepareMCsavedata ()
memcpy (savebuffer, saveicon, offset); memcpy (savebuffer, saveicon, offset);
/*** And the sramcomments ***/ /*** And the sramcomments ***/
sprintf (sramcomment[1], "%s", Memory.ROMName); sprintf (sramcomment[1], "%s", Memory.ROMFilename);
memcpy (savebuffer + offset, sramcomment, 64); memcpy (savebuffer + offset, sramcomment, 64);
offset += 64; offset += 64;
@ -59,7 +58,7 @@ prepareMCsavedata ()
memcpy (savebuffer + offset, &size, 4); memcpy (savebuffer + offset, &size, 4);
offset += 4; offset += 4;
/*** Copy SRAM ***/ /*** Copy SRAM ***/
if (size != 0) if (size != 0)
{ {
@ -72,7 +71,7 @@ prepareMCsavedata ()
offset += 16; offset += 16;
// memcpy (savebuffer + offset, &padcal, 4); // memcpy (savebuffer + offset, &padcal, 4);
offset += 4; offset += 4;
return offset; return offset;
} }
@ -91,7 +90,7 @@ prepareEXPORTsavedata ()
ClearSaveBuffer (); ClearSaveBuffer ();
/*** Copy in the sramcomments ***/ /*** Copy in the sramcomments ***/
sprintf (sramcomment[1], "%s", Memory.ROMName); sprintf (sramcomment[1], "%s", Memory.ROMFilename);
memcpy (savebuffer + offset, sramcomment, 64); memcpy (savebuffer + offset, sramcomment, 64);
offset += 64; offset += 64;
@ -105,19 +104,19 @@ prepareEXPORTsavedata ()
{ {
// make it a 512 byte header so it is compatible with other platforms // make it a 512 byte header so it is compatible with other platforms
offset = 512; offset = 512;
/*** Copy in the SRAM ***/ /*** Copy in the SRAM ***/
size = Memory.SRAMSize ? (1 << (Memory.SRAMSize + 3)) * 128 : 0; size = Memory.SRAMSize ? (1 << (Memory.SRAMSize + 3)) * 128 : 0;
if (size > 0x20000) if (size > 0x20000)
size = 0x20000; size = 0x20000;
if (size != 0) if (size != 0)
{ {
memcpy (savebuffer + offset, Memory.SRAM, size); memcpy (savebuffer + offset, Memory.SRAM, size);
offset += size; offset += size;
} }
return offset; return offset;
} }
else else
@ -136,32 +135,32 @@ decodesavedata (int readsize)
int offset; int offset;
int size; int size;
char sramcomment[32]; char sramcomment[32];
// Check for exportable format sram - it has the sram comment at the start // Check for exportable format sram - it has the sram comment at the start
memcpy (sramcomment, savebuffer, 32); memcpy (sramcomment, savebuffer, 32);
if ( (strncmp (sramcomment, "Snes9x GX 2.0", 13) == 0) || (strncmp (sramcomment, "Snes9x GX 00", 12) == 0) ) // version 2.0.XX or 00x if ( (strncmp (sramcomment, "Snes9x GX 2.0", 13) == 0) || (strncmp (sramcomment, "Snes9x GX 00", 12) == 0) ) // version 2.0.XX or 00x
{ {
offset = 64; offset = 64;
// Get the control pad configuration // Get the control pad configuration
// memcpy (&currconfig, savebuffer + offset, 16); // memcpy (&currconfig, savebuffer + offset, 16);
offset += 16; offset += 16;
// memcpy (&padcal, savebuffer + offset, 4); // memcpy (&padcal, savebuffer + offset, 4);
offset += 4; offset += 4;
// for (size = 0; size < 4; size++) // for (size = 0; size < 4; size++)
// gcpadmap[size] = padmap[currconfig[size]]; // gcpadmap[size] = padmap[currconfig[size]];
// move to start of SRAM which is after the 512 byte header // move to start of SRAM which is after the 512 byte header
offset = 512; offset = 512;
// import the SRAM // import the SRAM
size = Memory.SRAMSize ? (1 << (Memory.SRAMSize + 3)) * 128 : 0; size = Memory.SRAMSize ? (1 << (Memory.SRAMSize + 3)) * 128 : 0;
if (size > 0x20000) if (size > 0x20000)
size = 0x20000; size = 0x20000;
memcpy (Memory.SRAM, savebuffer + offset, size); memcpy (Memory.SRAM, savebuffer + offset, size);
offset += size; offset += size;
} }
@ -170,7 +169,7 @@ decodesavedata (int readsize)
// else, check for a v2.0 memory card format save // else, check for a v2.0 memory card format save
offset = sizeof (saveicon); offset = sizeof (saveicon);
memcpy (sramcomment, savebuffer + offset, 32); memcpy (sramcomment, savebuffer + offset, 32);
if ( strncmp (sramcomment, "Snes9x GX 2.0", 13) == 0 ) if ( strncmp (sramcomment, "Snes9x GX 2.0", 13) == 0 )
{ {
//WaitPrompt((char*) "Memory Card format save"); //WaitPrompt((char*) "Memory Card format save");
@ -179,18 +178,18 @@ decodesavedata (int readsize)
offset += 4; offset += 4;
memcpy (Memory.SRAM, savebuffer + offset, size); memcpy (Memory.SRAM, savebuffer + offset, size);
offset += size; offset += size;
// If it is an old 2.0 format save, skip over the Settings as we // If it is an old 2.0 format save, skip over the Settings as we
// don't save them in SRAM now // don't save them in SRAM now
if ( strcmp (sramcomment, "Snes9x GX 2.0") == 0 ) if ( strcmp (sramcomment, "Snes9x GX 2.0") == 0 )
offset += sizeof (Settings); offset += sizeof (Settings);
// Get the control pad configuration // Get the control pad configuration
// memcpy (&currconfig, savebuffer + offset, 16); // memcpy (&currconfig, savebuffer + offset, 16);
offset += 16; offset += 16;
// memcpy (&padcal, savebuffer + offset, 4); // memcpy (&padcal, savebuffer + offset, 4);
offset += 4; offset += 4;
// for (size = 0; size < 4; size++) // for (size = 0; size < 4; size++)
// gcpadmap[size] = padmap[currconfig[size]]; // gcpadmap[size] = padmap[currconfig[size]];
} }
@ -198,20 +197,20 @@ decodesavedata (int readsize)
{ {
// it's an older SnesGx memory card format save // it's an older SnesGx memory card format save
size = Memory.SRAMSize ? ( 1 << (Memory.SRAMSize + 3)) * 128 : 0; size = Memory.SRAMSize ? ( 1 << (Memory.SRAMSize + 3)) * 128 : 0;
// import the SRAM // import the SRAM
if ( size ) if ( size )
memcpy(&Memory.SRAM[0], &savebuffer[sizeof(saveicon)+68], size); memcpy(&Memory.SRAM[0], &savebuffer[sizeof(saveicon)+68], size);
// Ignore the settings saved in the file // Ignore the settings saved in the file
// NOTE: need to add import of joypad config?? Nah. // NOTE: need to add import of joypad config?? Nah.
} }
else else
{ {
// else, check for SRAM from other version/platform of snes9x // else, check for SRAM from other version/platform of snes9x
size = Memory.SRAMSize ? (1 << (Memory.SRAMSize + 3)) * 128 : 0; size = Memory.SRAMSize ? (1 << (Memory.SRAMSize + 3)) * 128 : 0;
if ( readsize == size || readsize == size + SRTC_SRAM_PAD) if ( readsize == size || readsize == size + SRTC_SRAM_PAD)
{ {
//WaitPrompt("readsize=size or + SRTC_SRAM_PAD"); //WaitPrompt("readsize=size or + SRTC_SRAM_PAD");
@ -233,39 +232,136 @@ decodesavedata (int readsize)
} }
} }
void quickLoadSRAM (bool8 silent) /****************************************************************************
* Load SRAM
****************************************************************************/
bool
LoadSRAM (int method, bool silent)
{ {
switch ( QUICK_SAVE_SLOT ) if(method == METHOD_AUTO)
{ method = autoLoadMethod();
case CARD_SLOTA:
case CARD_SLOTB: bool retval = false;
LoadSRAMFromMC(QUICK_SAVE_SLOT, silent); char filepath[1024];
break; int offset = 0;
case CARD_SLOTA+2:
case CARD_SLOTB+2: if(!silent)
LoadSRAMFromSD(silent); ShowAction ((char*) "Loading SRAM...");
break;
case CARD_SLOTA+4: if(method == METHOD_SD || method == METHOD_USB)
LoadSRAMFromSMB(SILENT); {
break; 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);
offset = LoadBufferFromFAT (filepath, silent);
}
else if(method == METHOD_SMB)
{
sprintf (filepath, "%s\\%s.srm", GCSettings.SaveFolder, Memory.ROMFilename);
offset = LoadBufferFromSMB (filepath, silent);
}
else if(method == METHOD_MC_SLOTA)
{
sprintf (filepath, "%s.srm", Memory.ROMFilename);
offset = LoadBufferFromMC (savebuffer, CARD_SLOTA, filepath, silent);
}
else if(method == METHOD_MC_SLOTB)
{
sprintf (filepath, "%s.srm", Memory.ROMFilename);
offset = LoadBufferFromMC (savebuffer, CARD_SLOTB, filepath, silent);
}
if (offset > 0)
{
decodesavedata (offset);
if ( !silent )
{
sprintf (filepath, "Loaded %d bytes", offset);
WaitPrompt(filepath);
}
S9xSoftReset();
retval = true;
}
return retval;
} }
void quickSaveSRAM (bool8 silent) /****************************************************************************
* Save SRAM
****************************************************************************/
bool
SaveSRAM (int method, bool silent)
{ {
switch ( QUICK_SAVE_SLOT ) if(method == METHOD_AUTO)
{ method = autoSaveMethod();
case CARD_SLOTA:
case CARD_SLOTB: bool retval = false;
SaveSRAMToMC(QUICK_SAVE_SLOT, silent); char filepath[1024];
break; int datasize;
case CARD_SLOTA+2: int offset = 0;
case CARD_SLOTB+2:
SaveSRAMToSD(silent); if (!silent)
break; ShowAction ((char*) "Saving SRAM...");
case CARD_SLOTA+4:
SaveSRAMToSMB(SILENT); if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB)
break; datasize = prepareMCsavedata ();
} else
datasize = prepareEXPORTsavedata ();
if ( datasize )
{
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);
offset = SaveBufferToFAT (filepath, datasize, silent);
}
else if(method == METHOD_SMB)
{
sprintf (filepath, "%s\\%s.srm", GCSettings.SaveFolder, Memory.ROMFilename);
offset = SaveBufferToSMB (filepath, datasize, silent);
}
else if(method == METHOD_MC_SLOTA)
{
sprintf (filepath, "%s.srm", Memory.ROMFilename);
offset = SaveBufferToMC (savebuffer, CARD_SLOTA, filepath, datasize, silent);
}
else if(method == METHOD_MC_SLOTB)
{
sprintf (filepath, "%s.srm", Memory.ROMFilename);
offset = SaveBufferToMC (savebuffer, CARD_SLOTB, filepath, datasize, silent);
}
if (offset > 0)
{
if ( !silent )
{
sprintf (filepath, "Wrote %d bytes", offset);
WaitPrompt(filepath);
}
retval = true;
}
}
return retval;
} }
/****************************************************************************
* Quick Load SRAM
****************************************************************************/
bool quickLoadSRAM (bool silent)
{
return LoadSRAM(GCSettings.SaveMethod, silent);
}
/****************************************************************************
* Quick Save SRAM
****************************************************************************/
bool quickSaveSRAM (bool silent)
{
return SaveSRAM(GCSettings.SaveMethod, silent);
}

View File

@ -13,5 +13,7 @@ int prepareMCsavedata ();
int prepareEXPORTsavedata (); int prepareEXPORTsavedata ();
void decodesavedata (int readsize); void decodesavedata (int readsize);
void quickLoadSRAM (bool8 silent); bool SaveSRAM (int method, bool silent);
void quickSaveSRAM (bool8 silent); bool LoadSRAM (int method, bool silent);
bool quickLoadSRAM (bool silent);
bool quickSaveSRAM (bool silent);