2008-08-06 03:09:59 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Snes9x 1.50
|
|
|
|
*
|
|
|
|
* Nintendo Gamecube Port
|
|
|
|
* crunchy2 April 2007-July 2007
|
|
|
|
*
|
|
|
|
* preferences.cpp
|
|
|
|
*
|
|
|
|
* Preferences save/load preferences utilities
|
|
|
|
****************************************************************************/
|
|
|
|
#include <gccore.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ogcsys.h>
|
|
|
|
|
|
|
|
#include "snes9x.h"
|
|
|
|
#include "memmap.h"
|
|
|
|
#include "srtc.h"
|
2008-08-12 05:25:16 +02:00
|
|
|
|
|
|
|
#include "snes9xGx.h"
|
|
|
|
#include "images/saveicon.h"
|
2008-08-07 07:19:17 +02:00
|
|
|
#include "menudraw.h"
|
2008-08-12 05:25:16 +02:00
|
|
|
#include "memcardop.h"
|
2008-08-07 07:19:17 +02:00
|
|
|
#include "fileop.h"
|
2008-08-10 05:14:39 +02:00
|
|
|
#include "smbop.h"
|
2008-08-07 05:25:02 +02:00
|
|
|
#include "filesel.h"
|
2008-08-06 03:09:59 +02:00
|
|
|
|
|
|
|
extern unsigned char savebuffer[];
|
|
|
|
extern int currconfig[4];
|
|
|
|
|
2008-08-06 03:45:56 +02:00
|
|
|
// button map configurations
|
|
|
|
extern unsigned int gcpadmap[];
|
|
|
|
extern unsigned int wmpadmap[];
|
|
|
|
extern unsigned int ccpadmap[];
|
|
|
|
extern unsigned int ncpadmap[];
|
|
|
|
|
2008-08-07 05:25:02 +02:00
|
|
|
#define PREFS_FILE_NAME "snes9xGx.prf"
|
2008-08-12 05:25:16 +02:00
|
|
|
#define PREFSVERSTRING "Snes9x GX 005 Prefs"
|
2008-08-06 03:09:59 +02:00
|
|
|
|
|
|
|
char prefscomment[2][32] = { {PREFSVERSTRING}, {"Preferences"} };
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Prepare Preferences Data
|
|
|
|
*
|
2008-08-07 05:25:02 +02:00
|
|
|
* This sets up the save buffer for saving.
|
2008-08-06 03:09:59 +02:00
|
|
|
****************************************************************************/
|
|
|
|
int
|
|
|
|
preparePrefsData ()
|
|
|
|
{
|
2008-08-08 09:57:01 +02:00
|
|
|
int offset = sizeof (saveicon);
|
|
|
|
int size;
|
2008-08-06 03:09:59 +02:00
|
|
|
|
2008-08-08 09:57:01 +02:00
|
|
|
memset (savebuffer, 0, SAVEBUFFERSIZE);
|
2008-08-06 03:09:59 +02:00
|
|
|
|
|
|
|
/*** Copy in save icon ***/
|
2008-08-08 09:57:01 +02:00
|
|
|
memcpy (savebuffer, saveicon, offset);
|
2008-08-06 03:09:59 +02:00
|
|
|
|
|
|
|
/*** And the prefscomments ***/
|
2008-08-08 09:57:01 +02:00
|
|
|
memcpy (savebuffer + offset, prefscomment, 64);
|
|
|
|
offset += 64;
|
|
|
|
|
|
|
|
/*** Save all settings ***/
|
|
|
|
size = sizeof (Settings);
|
|
|
|
memcpy (savebuffer + offset, &Settings, size);
|
|
|
|
offset += size;
|
|
|
|
|
|
|
|
/*** Save GC specific settings ***/
|
|
|
|
size = sizeof (GCSettings);
|
|
|
|
memcpy (savebuffer + offset, &GCSettings, size);
|
|
|
|
offset += size;
|
|
|
|
|
|
|
|
/*** Save buttonmaps ***/
|
|
|
|
size = sizeof (unsigned int) *12; // this size applies to all padmaps
|
|
|
|
memcpy (savebuffer + offset, &gcpadmap, size);
|
|
|
|
offset += size;
|
|
|
|
memcpy (savebuffer + offset, &wmpadmap, size);
|
|
|
|
offset += size;
|
|
|
|
memcpy (savebuffer + offset, &ccpadmap, size);
|
|
|
|
offset += size;
|
|
|
|
memcpy (savebuffer + offset, &ncpadmap, size);
|
|
|
|
offset += size;
|
|
|
|
|
|
|
|
return offset;
|
2008-08-06 03:09:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Decode Preferences Data
|
|
|
|
****************************************************************************/
|
2008-08-07 05:25:02 +02:00
|
|
|
bool
|
2008-08-06 03:09:59 +02:00
|
|
|
decodePrefsData ()
|
|
|
|
{
|
2008-08-07 05:25:02 +02:00
|
|
|
int offset;
|
|
|
|
char prefscomment[32];
|
|
|
|
int size;
|
|
|
|
|
|
|
|
offset = sizeof (saveicon);
|
|
|
|
memcpy (prefscomment, savebuffer + offset, 32);
|
|
|
|
|
2008-08-06 03:09:59 +02:00
|
|
|
if ( strcmp (prefscomment, PREFSVERSTRING) == 0 )
|
|
|
|
{
|
2008-08-07 05:25:02 +02:00
|
|
|
offset += 64;
|
|
|
|
memcpy (&Settings, savebuffer + offset, sizeof (Settings));
|
|
|
|
offset += sizeof (Settings);
|
|
|
|
memcpy (&GCSettings, savebuffer + offset, sizeof (GCSettings));
|
|
|
|
offset += sizeof (GCSettings);
|
|
|
|
// load padmaps (order important)
|
|
|
|
size = sizeof (unsigned int) *12;
|
|
|
|
memcpy (&gcpadmap, savebuffer + offset, size);
|
|
|
|
offset += size;
|
|
|
|
memcpy (&wmpadmap, savebuffer + offset, size);
|
|
|
|
offset += size;
|
|
|
|
memcpy (&ccpadmap, savebuffer + offset, size);
|
|
|
|
offset += size;
|
|
|
|
memcpy (&ncpadmap, savebuffer + offset, size);
|
|
|
|
|
|
|
|
return true;
|
2008-08-06 03:09:59 +02:00
|
|
|
}
|
2008-08-07 05:25:02 +02:00
|
|
|
else
|
|
|
|
return false;
|
2008-08-06 03:09:59 +02:00
|
|
|
}
|
|
|
|
|
2008-08-07 05:25:02 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Save Preferences
|
|
|
|
****************************************************************************/
|
|
|
|
bool
|
|
|
|
SavePrefs (int method, bool silent)
|
2008-08-06 03:09:59 +02:00
|
|
|
{
|
2008-08-07 05:25:02 +02:00
|
|
|
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)
|
|
|
|
{
|
2008-08-12 05:25:16 +02:00
|
|
|
if(ChangeFATInterface(method, NOTSILENT))
|
|
|
|
{
|
|
|
|
sprintf (filepath, "%s/%s/%s", ROOTFATDIR, GCSettings.SaveFolder, PREFS_FILE_NAME);
|
|
|
|
offset = SaveBufferToFAT (filepath, datasize, silent);
|
|
|
|
}
|
2008-08-07 05:25:02 +02:00
|
|
|
}
|
|
|
|
else if(method == METHOD_SMB)
|
|
|
|
{
|
2008-08-10 05:14:39 +02:00
|
|
|
sprintf (filepath, "%s/%s", GCSettings.SaveFolder, PREFS_FILE_NAME);
|
2008-08-07 05:25:02 +02:00
|
|
|
offset = SaveBufferToSMB (filepath, datasize, silent);
|
|
|
|
}
|
|
|
|
else if(method == METHOD_MC_SLOTA)
|
|
|
|
{
|
2008-08-12 05:25:16 +02:00
|
|
|
offset = SaveBufferToMC (savebuffer, CARD_SLOTA, (char *)PREFS_FILE_NAME, datasize, silent);
|
2008-08-07 05:25:02 +02:00
|
|
|
}
|
|
|
|
else if(method == METHOD_MC_SLOTB)
|
|
|
|
{
|
2008-08-12 05:25:16 +02:00
|
|
|
offset = SaveBufferToMC (savebuffer, CARD_SLOTB, (char *)PREFS_FILE_NAME, datasize, silent);
|
2008-08-07 05:25:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (offset > 0)
|
2008-08-06 03:09:59 +02:00
|
|
|
{
|
2008-08-07 05:25:02 +02:00
|
|
|
retval = decodePrefsData ();
|
|
|
|
if ( !silent )
|
2008-08-12 05:25:16 +02:00
|
|
|
WaitPrompt ((char *)"Preferences saved");
|
2008-08-06 03:09:59 +02:00
|
|
|
}
|
2008-08-07 05:25:02 +02:00
|
|
|
return retval;
|
2008-08-06 03:09:59 +02:00
|
|
|
}
|
|
|
|
|
2008-08-07 05:25:02 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Load Preferences
|
|
|
|
****************************************************************************/
|
|
|
|
bool
|
|
|
|
LoadPrefs (int method, bool silent)
|
2008-08-06 03:09:59 +02:00
|
|
|
{
|
2008-08-07 05:25:02 +02:00
|
|
|
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)
|
|
|
|
{
|
2008-08-12 05:25:16 +02:00
|
|
|
if(ChangeFATInterface(method, NOTSILENT))
|
|
|
|
{
|
|
|
|
sprintf (filepath, "%s/%s/%s", ROOTFATDIR, GCSettings.SaveFolder, PREFS_FILE_NAME);
|
|
|
|
offset = LoadBufferFromFAT (filepath, silent);
|
|
|
|
}
|
2008-08-07 05:25:02 +02:00
|
|
|
}
|
|
|
|
else if(method == METHOD_SMB)
|
|
|
|
{
|
2008-08-10 05:14:39 +02:00
|
|
|
sprintf (filepath, "%s/%s", GCSettings.SaveFolder, PREFS_FILE_NAME);
|
2008-08-12 05:25:16 +02:00
|
|
|
offset = LoadBufferFromSMB (filepath, silent);
|
2008-08-07 05:25:02 +02:00
|
|
|
}
|
|
|
|
else if(method == METHOD_MC_SLOTA)
|
|
|
|
{
|
2008-08-12 05:25:16 +02:00
|
|
|
offset = LoadBufferFromMC (savebuffer, CARD_SLOTA, (char *)PREFS_FILE_NAME, silent);
|
2008-08-07 05:25:02 +02:00
|
|
|
}
|
|
|
|
else if(method == METHOD_MC_SLOTB)
|
|
|
|
{
|
2008-08-12 05:25:16 +02:00
|
|
|
offset = LoadBufferFromMC (savebuffer, CARD_SLOTB, (char *)PREFS_FILE_NAME, silent);
|
2008-08-07 05:25:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (offset > 0)
|
2008-08-06 03:09:59 +02:00
|
|
|
{
|
2008-08-07 05:25:02 +02:00
|
|
|
retval = decodePrefsData ();
|
|
|
|
if ( !silent )
|
2008-08-12 05:25:16 +02:00
|
|
|
WaitPrompt((char *)"Preferences loaded");
|
2008-08-06 03:09:59 +02:00
|
|
|
}
|
2008-08-07 05:25:02 +02:00
|
|
|
return retval;
|
|
|
|
}
|