-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

@ -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); void StripExt(char* returnstring, char * inputstring)
clearscreen ();
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
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,31 +132,108 @@ 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)
{ {
@ -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,32 +305,33 @@ 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;
} }
@ -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");
@ -421,8 +476,7 @@ OpenDVD ()
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 ()))
{ {
@ -434,209 +488,119 @@ OpenDVD ()
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];
// is_mounted //if (haveFATdir == 0)
// //{
// to check whether FAT media are detected. /* don't mess with DVD entries */
bool fat_is_mounted(PARTITION_INTERFACE partition) { havedir = 0; // gamecube only
char prefix[] = "fatX:/";
prefix[3] = partition + '0';
DIR_ITER *dir = diropen(prefix);
if (dir) {
dirclose(dir);
return true;
}
return false;
}
void fat_enable_readahead_all() { /* change current dir to snes roms directory */
int i; if(method == METHOD_SD)
for (i=1; i <= 4; ++i) { sprintf ( currFATdir, "%s/%s", ROOTSDDIR, GCSettings.LoadFolder );
if (fat_is_mounted((PARTITION_INTERFACE)i)) fatEnableReadAhead((PARTITION_INTERFACE)i, 64, 128); else
} sprintf ( currFATdir, "%s/%s", ROOTUSBDIR, GCSettings.LoadFolder );
}
bool fat_remount(PARTITION_INTERFACE partition) { /* Parse initial root directory and get entries list */
//ShowAction("remounting..."); if ((maxfiles = parseFATdirectory (method)))
/* // 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)
method = autoLoadMethod();
/* switch (method)
fatUnmount(PI_INTERNAL_SD); {
fatMountNormalInterface(PI_INTERNAL_SD,8); case METHOD_SD:
//fatEnableReadAhead(PI_INTERNAL_SD, 64, 128); case METHOD_USB:
fatSetDefaultInterface(PI_INTERNAL_SD); loadROM = OpenFAT (method);
//chdir("fat0:/"); break;
*/ case METHOD_DVD:
#ifdef HW_RVL // Load from DVD
// only remount on wii loadROM = OpenDVD (method);
if (!fat_remount (PI_INTERNAL_SD)) break;
return 0; case METHOD_SMB:
#endif // Load from Network (SMB)
loadROM = OpenSMB (method);
break;
}
if (haveSDdir == 0) return loadROM;
{
/* don't mess with DVD entries */
havedir = 0;
haveUSBdir = 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;
} }
/** /****************************************************************************
* 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

@ -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

@ -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,9 +50,9 @@ 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
@ -59,14 +60,13 @@ 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,9 +412,9 @@ 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 ()
@ -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;
@ -583,7 +616,6 @@ RunMenu (char items[][20], int maxitems, char *title, int fontsize)
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)
@ -607,14 +639,14 @@ RunMenu (char items[][20], int maxitems, char *title, int fontsize)
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)))
@ -628,12 +660,6 @@ RunMenu (char items[][20], int maxitems, char *title, int fontsize)
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 ***/
@ -651,6 +677,92 @@ RunMenu (char items[][20], int maxitems, char *title, int fontsize)
} }
/****************************************************************************
* 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
* *
@ -845,10 +957,10 @@ void DrawLineFast( int startx, int endx, int y, u8 r, u8 g, u8 b )
} }
} }
/** /*****************************************************************************
* 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;
@ -873,5 +985,3 @@ u32 getrgb( u32 ycbr, u32 low )
return (u32)( r << 16 | g << 8 | b ); return (u32)( r << 16 | g << 8 | b );
} }

View File

@ -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;
@ -118,7 +115,9 @@ int MountCard(int cslot)
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,9 +130,12 @@ 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++;
@ -161,7 +163,7 @@ VerifyMCFile (unsigned char *buf, int slot, char *filename, int datasize)
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)
{ {
@ -242,7 +244,7 @@ LoadBufferFromMC (unsigned char *buf, int slot, char *filename, bool8 silent)
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)
{ {
@ -251,8 +253,7 @@ LoadBufferFromMC (unsigned char *buf, int slot, char *filename, bool8 silent)
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;
} }
@ -277,8 +278,11 @@ LoadBufferFromMC (unsigned char *buf, int slot, char *filename, bool8 silent)
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);
@ -309,7 +313,7 @@ SaveBufferToMC (unsigned char *buf, int slot, char *filename, int datasize, bool
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)
{ {
@ -409,7 +413,7 @@ 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!");
@ -468,124 +472,4 @@ SaveBufferToMC (unsigned char *buf, int slot, char *filename, int datasize, bool
} }
/****************************************************************************
* 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"
@ -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) char filename[1024];
{ SMBFILE smbfile;
/*** Freeze to SMB ***/ FILE *handle;
sprintf (filename, "/%s/%s.frz", SNESSAVEDIR, Memory.ROMFilename); int len = 0;
} int wrote = 0;
else if (where == 2 || where == 3) int offset = 0;
{ char msg[100];
/*** Freeze to SDCard in slot A or slot B ***/
#ifdef SDUSE_LFN if (method == METHOD_SD) // SD
sprintf (filename, "%s/%s/%s.frz", ROOTSDDIR, SNESSAVEDIR, Memory.ROMFilename); {
#else sprintf (filename, "%s/%s/%s.frz", ROOTSDDIR, GCSettings.SaveFolder, Memory.ROMFilename);
/*** Until we have LFN on SD ... ***/ }
sprintf (filename, "%s/%s/%08x.frz", ROOTSDDIR, SNESSAVEDIR, Memory.ROMCRC32); if (method == METHOD_USB) // USB
#endif {
} sprintf (filename, "%s/%s/%s.frz", ROOTUSBDIR, GCSettings.SaveFolder, Memory.ROMFilename);
else }
{ else if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) // MC Slot A or B
/*** Freeze to MC in slot A or slot B ***/ {
sprintf (filename, "%s.snz", Memory.ROMFilename); sprintf (filename, "%s.snz", Memory.ROMFilename);
} }
else if (method == METHOD_SMB) // SMB
{
sprintf (filename, "/%s/%s.frz", GCSettings.SaveFolder, Memory.ROMFilename);
}
S9xSetSoundMute (TRUE); S9xSetSoundMute (TRUE);
S9xPrepareSoundForSnapshotSave (FALSE); S9xPrepareSoundForSnapshotSave (FALSE);
NGCFreezeMemBuffer (); NGCFreezeMemBuffer ();
S9xPrepareSoundForSnapshotSave (TRUE); S9xPrepareSoundForSnapshotSave (TRUE);
S9xSetSoundMute (FALSE); S9xSetSoundMute (FALSE);
if (where == 4) /*** SMB ***/ if (method == METHOD_SD || method == METHOD_USB) // FAT devices
{ {
ConnectSMB (); handle = fopen (filename, "wb");
smbfile = SMB_Open (filename, SMB_OPEN_WRITING | SMB_DENY_NONE, if (handle > 0)
SMB_OF_CREATE | SMB_OF_TRUNCATE); {
if (smbfile)
{
if (!silent) if (!silent)
ShowAction ((char*) "Saving freeze game..."); ShowAction ((char*) "Saving freeze game...");
len = bufoffset; len = fwrite (membuffer, 1, bufoffset, handle);
offset = 0; fclose (handle);
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; if (len != bufoffset)
len -= wrote; WaitPrompt((char*) "Error writing freeze file");
} else if ( !silent )
{
SMB_Close (smbfile); sprintf (filename, "Written %d bytes", bufoffset);
WaitPrompt (filename);
if ( !silent ) }
{ }
sprintf (filename, "Written %d bytes", bufoffset); else
WaitPrompt (filename); {
} if(method == METHOD_SD)
} sprintf(msg, "Couldn't save to %s/%s/", ROOTSDDIR, GCSettings.SaveFolder);
else else
{ sprintf(msg, "Couldn't save to %s/%s/", ROOTUSBDIR, GCSettings.SaveFolder);
char msg[100]; WaitPrompt (msg);
sprintf(msg, "Couldn't save to SMB:\\%s\\", SNESSAVEDIR); }
WaitPrompt (msg); }
} else if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTA) // MC Slot A or B
} {
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)
WaitPrompt((char*) "Error writing freeze file");
else if ( !silent )
{
sprintf (filename, "Written %d bytes", bufoffset);
WaitPrompt (filename);
}
}
else
{
sprintf(msg, "Couldn't save to %s/%s/", ROOTSDDIR, SNESSAVEDIR);
WaitPrompt (msg);
}
}
else /*** MC in slot A or slot B ***/
{
if (!silent) if (!silent)
ShowAction ((char*) "Saving freeze game..."); ShowAction ((char*) "Saving freeze game...");
ClearSaveBuffer (); ClearSaveBuffer ();
/*** Copy in save icon ***/ /*** Copy in save icon ***/
int offset = sizeof (saveicon); int offset = sizeof (saveicon);
memcpy (savebuffer, saveicon, offset); memcpy (savebuffer, saveicon, offset);
/*** And the freezecomment ***/ /*** And the freezecomment ***/
sprintf (freezecomment[1], "%s", Memory.ROMName); sprintf (freezecomment[1], "%s", Memory.ROMFilename);
memcpy (savebuffer + offset, freezecomment, 64); memcpy (savebuffer + offset, freezecomment, 64);
offset += 64; offset += 64;
/*** Zip and copy in the freeze ***/ /*** Zip and copy in the freeze ***/
uLongf DestBuffSize = (uLongf) SAVEBUFFERSIZE; uLongf DestBuffSize = (uLongf) SAVEBUFFERSIZE;
int err= compress2((Bytef*)(savebuffer+offset+8), (uLongf*)&DestBuffSize, (const Bytef*)membuffer, (uLongf)bufoffset, Z_BEST_COMPRESSION); int err= compress2((Bytef*)(savebuffer+offset+8), (uLongf*)&DestBuffSize, (const Bytef*)membuffer, (uLongf)bufoffset, Z_BEST_COMPRESSION);
if(err!=Z_OK) if(err!=Z_OK)
{ {
sprintf (msg, "zip error %s ",zError(err)); sprintf (msg, "zip error %s ",zError(err));
WaitPrompt (msg); WaitPrompt (msg);
return 0; 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 )
{
sprintf (filename, "Written %d bytes", ret);
WaitPrompt (filename);
}
}
if(method == METHOD_MC_SLOTA)
ret = SaveBufferToMC ( savebuffer, CARD_SLOTA, filename, offset, SILENT );
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;
@ -342,148 +348,153 @@ NGCUnfreezeGame (int from, bool8 silent)
bufoffset = 0; bufoffset = 0;
if (from == 4) if(method == METHOD_AUTO)
{ method = autoLoadMethod();
/*** From SMB ***/
sprintf (filename, "\\%s\\%s.frz", SNESSAVEDIR, Memory.ROMFilename);
ConnectSMB ();
/*** Read the file into memory ***/ if (method == METHOD_SD || method == METHOD_USB) // SD & USB
smbfile = {
SMB_Open (filename, SMB_OPEN_READING | SMB_DENY_NONE, SMB_OF_OPEN); if(method == METHOD_SD)
sprintf (filename, "%s/%s/%s.frz", ROOTSDDIR, GCSettings.SaveFolder, Memory.ROMFilename);
else
sprintf (filename, "%s/%s/%s.frz", ROOTUSBDIR, GCSettings.SaveFolder, Memory.ROMFilename);
if (smbfile) handle = fopen (filename, "rb");
{
ShowAction ((char*) "Loading freeze file...");
while ((read =
SMB_Read ((char *) membuffer + offset, 1024, offset,
smbfile)) > 0)
offset += read;
SMB_Close (smbfile); if (handle > 0)
{
if ( !silent )
ShowAction ((char*) "Loading freeze file...");
ShowAction ((char*) "Unpacking freeze file"); offset = 0;
if (S9xUnfreezeGame ("AGAME") != SUCCESS) /*** Usual chunks into memory ***/
{ while ((read = fread (membuffer + offset, 1, 2048, handle)) > 0)
WaitPrompt((char*) "Error thawing"); offset += read;
return 0;
}
}
else if ( !silent )
{
WaitPrompt((char*) "No freeze file found");
return 0;
}
}
else if (from == 2 || from == 3) /*** From SD slot A or slot B ***/
{
#ifdef SDUSE_LFN fclose (handle);
sprintf (filename, "%s/%s/%s.frz", ROOTSDDIR, SNESSAVEDIR, Memory.ROMFilename);
#else
/*** From SDCard ***/
sprintf (filename, "%s/%s/%08x.frz", ROOTSDDIR, SNESSAVEDIR, Memory.ROMCRC32);
#endif
handle = fopen (filename, "rb"); if ( !silent )
ShowAction ((char*) "Unpacking freeze file");
if (handle > 0)
{
ShowAction ((char*) "Loading freeze file...");
offset = 0;
/*** Usual chunks into memory ***/
while ((read = fread (membuffer + offset, 1, 2048, handle)) >
0)
offset += read;
fclose (handle);
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;
}
}
else /*** From MC in slot A or slot B ***/
{
ShowAction ((char*) "Loading freeze file...");
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;
int err= uncompress((Bytef*)membuffer, (uLongf*)&DestBuffSize, (const Bytef*)(savebuffer + offset), zipsize);
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 if ( !silent )
{
sprintf(msg, "Couldn't load from MC slot %s", (from ? "B" : "A"));
WaitPrompt (msg);
return 0;
}
if (S9xUnfreezeGame ("AGAME") != SUCCESS)
{
WaitPrompt((char*) "Error thawing");
return 0;
}
}
else
{
WaitPrompt((char*) "No freeze file found");
return 0;
}
return 1;
} }
return 1; else if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) // MC in slot A or slot B
{
if ( !silent )
ShowAction ((char*) "Loading freeze file...");
sprintf (filename, "%s.snz", Memory.ROMFilename);
int ret = 0;
if(method == METHOD_MC_SLOTA)
LoadBufferFromMC ( savebuffer, CARD_SLOTA, filename, silent );
else
LoadBufferFromMC ( savebuffer, CARD_SLOTB, filename, silent );
if ( ret )
{
if ( !silent )
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;
int err= uncompress((Bytef*)membuffer, (uLongf*)&DestBuffSize, (const Bytef*)(savebuffer + offset), zipsize);
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 if (method == METHOD_SMB) // Network (SMB)
{
sprintf (filename, "\\%s\\%s.frz", GCSettings.SaveFolder, Memory.ROMFilename);
ConnectSMB ();
/*** Read the file into memory ***/
smbfile =
SMB_Open (filename, SMB_OPEN_READING | SMB_DENY_NONE, SMB_OF_OPEN);
if (smbfile)
{
if ( !silent )
ShowAction ((char*) "Loading freeze file...");
while ((read =
SMB_Read ((char *) membuffer + offset, 1024, offset,
smbfile)) > 0)
offset += read;
SMB_Close (smbfile);
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!
} }
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 ()
@ -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

@ -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.JustifierMaster = true;
Settings.ShutdownMaster = false;
Settings.CyclesPercentage = 100; // snes9x 1.50 and earlier
/* Eke-Eke: specific to snes9x 1.51 */
// Settings.BlockInvalidVRAMAccess = true; Settings.MouseMaster = false;
// Settings.HDMATimingHack = 100; Settings.SuperScopeMaster = false;
Settings.MultiPlayer5Master = false;
Settings.JustifierMaster = true;
Settings.ShutdownMaster = false;
Settings.CyclesPercentage = 100; // snes9x 1.50 and earlier
Settings.ApplyCheats = true;
/* 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;
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;
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;
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
* *
@ -64,64 +119,72 @@ static int FileSortCallback(const void *f1, const void *f2)
} }
/*************************************************************************** /***************************************************************************
* 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)
{
return 0;
}
/* go up to parent directory */
else if (strcmp(filelist[selection].filename,"..") == 0)
{
/* determine last subdirectory namelength */
sprintf(temp,"%s",currFATdir);
test = strtok(temp,"/");
while (test != NULL)
{
size = strlen(test);
test = strtok(NULL,"/");
}
/* go up to parent directory */ /* remove last subdirectory name */
else if (strcmp(filelist[selection].filename,"..") == 0) size = strlen(currFATdir) - size - 1;
{ currFATdir[size] = 0;
/* determine last subdirectory namelength */
sprintf(temp,"%s",currSDdir);
test = strtok(temp,"/");
while (test != NULL) {
size = strlen(test);
test = strtok(NULL,"/");
}
/* remove last subdirectory name */ return 1;
size = strlen(currSDdir) - size - 1; }
currSDdir[size] = 0; /* Open a directory */
else
/* handles root name */ {
if (strcmp(currSDdir, "/") == 0) /* test new directory namelength */
if ((strlen(currFATdir)+1+strlen(filelist[selection].filename)) < MAXPATHLEN)
return 1;
}
else /* Open a directory */
{
/* test new directory namelength */
if ((strlen(currSDdir)+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 { }
else
{
WaitPrompt((char*)"Dirname is too long !"); 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];
@ -130,26 +193,30 @@ int parseFATdirectory() {
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);
@ -161,7 +228,7 @@ int parseFATdirectory() {
} }
/*** 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);
@ -170,12 +237,11 @@ int parseFATdirectory() {
} }
/**************************************************************************** /****************************************************************************
* 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,13 +252,12 @@ 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;
} }
@ -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;
@ -236,15 +301,13 @@ 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;
@ -274,14 +337,13 @@ LoadBufferFromSD (char *filepath, bool silent)
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)
{ {
@ -301,145 +363,3 @@ SaveBufferToSD (char *filepath, int datasize, bool silent)
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

@ -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;
@ -332,6 +332,7 @@ 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;
@ -369,116 +370,3 @@ LoadBufferFromSMB (char *filepath, bool8 silent)
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

@ -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
****************************************************************************/ ****************************************************************************/
@ -747,16 +748,16 @@ 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 ();
@ -784,7 +785,6 @@ main ()
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 ();
@ -814,11 +814,14 @@ main ()
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;
@ -831,7 +834,7 @@ main ()
{ {
while (ARAM_ROMSIZE == 0) while (ARAM_ROMSIZE == 0)
{ {
mainmenu (); mainmenu (selectedMenu);
} }
} }
else else

View File

@ -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;
@ -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;
@ -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);