snes9xgx/source/preferences.cpp

746 lines
24 KiB
C++
Raw Normal View History

/****************************************************************************
2010-01-27 23:20:37 +01:00
* Snes9x Nintendo Wii/Gamecube Port
*
2018-12-27 00:10:12 +01:00
* Tantric 2008-2019
*
* preferences.cpp
*
* Preferences save/load to XML file
***************************************************************************/
#include <gccore.h>
#include <stdio.h>
#include <string.h>
2011-01-20 03:52:56 +01:00
#include <dirent.h>
#include <sys/stat.h>
#include <ogcsys.h>
2008-08-22 22:23:32 +02:00
#include <mxml.h>
2010-03-22 00:43:54 +01:00
#include "snes9xgx.h"
2009-03-11 18:28:37 +01:00
#include "menu.h"
2008-08-07 07:19:17 +02:00
#include "fileop.h"
2009-03-11 18:28:37 +01:00
#include "filebrowser.h"
2008-09-27 09:13:52 +02:00
#include "input.h"
2009-03-11 18:28:37 +01:00
#include "button_mapping.h"
#include "snes9x/apu/apu.h"
2010-01-25 22:05:38 +01:00
struct SGCSettings GCSettings;
/****************************************************************************
* Prepare Preferences Data
*
* This sets up the save buffer for saving.
***************************************************************************/
static mxml_node_t *xml = NULL;
static mxml_node_t *data = NULL;
static mxml_node_t *section = NULL;
static mxml_node_t *item = NULL;
static mxml_node_t *elem = NULL;
2008-08-20 09:58:55 +02:00
2009-10-02 00:35:12 +02:00
static char temp[200];
2008-08-20 09:58:55 +02:00
static const char * toStr(int i)
2008-08-20 09:58:55 +02:00
{
sprintf(temp, "%d", i);
return temp;
}
2009-10-02 00:35:12 +02:00
static const char * FtoStr(float i)
2008-10-24 07:11:01 +02:00
{
sprintf(temp, "%.2f", i);
return temp;
}
2008-08-20 09:58:55 +02:00
static void createXMLSection(const char * name, const char * description)
2008-08-20 09:58:55 +02:00
{
section = mxmlNewElement(data, "section");
mxmlElementSetAttr(section, "name", name);
mxmlElementSetAttr(section, "description", description);
}
static void createXMLSetting(const char * name, const char * description, const char * value)
2008-08-20 09:58:55 +02:00
{
item = mxmlNewElement(section, "setting");
mxmlElementSetAttr(item, "name", name);
mxmlElementSetAttr(item, "value", value);
mxmlElementSetAttr(item, "description", description);
}
static void createXMLController(u32 controller[], const char * name, const char * description)
2008-08-20 09:58:55 +02:00
{
item = mxmlNewElement(section, "controller");
mxmlElementSetAttr(item, "name", name);
mxmlElementSetAttr(item, "description", description);
// create buttons
2008-09-27 09:13:52 +02:00
for(int i=0; i < MAXJP; i++)
2008-08-20 09:58:55 +02:00
{
elem = mxmlNewElement(item, "button");
mxmlElementSetAttr(elem, "number", toStr(i));
mxmlElementSetAttr(elem, "assignment", toStr(controller[i]));
}
}
static const char * XMLSaveCallback(mxml_node_t *node, int where)
{
const char *name;
name = node->value.element.name;
if(where == MXML_WS_BEFORE_CLOSE)
{
if(!strcmp(name, "file") || !strcmp(name, "section"))
return ("\n");
else if(!strcmp(name, "controller"))
return ("\n\t");
}
if (where == MXML_WS_BEFORE_OPEN)
{
if(!strcmp(name, "file"))
return ("\n");
else if(!strcmp(name, "section"))
return ("\n\n");
else if(!strcmp(name, "setting") || !strcmp(name, "controller"))
return ("\n\t");
else if(!strcmp(name, "button"))
return ("\n\t\t");
}
return (NULL);
}
static int
2009-10-02 00:35:12 +02:00
preparePrefsData ()
{
2008-08-20 09:58:55 +02:00
xml = mxmlNewXML("1.0");
mxmlSetWrapMargin(0); // disable line wrapping
2008-08-20 09:58:55 +02:00
data = mxmlNewElement(xml, "file");
mxmlElementSetAttr(data, "app", APPNAME);
mxmlElementSetAttr(data, "version", APPVERSION);
2008-08-20 09:58:55 +02:00
createXMLSection("File", "File Settings");
createXMLSetting("AutoLoad", "Auto Load", toStr(GCSettings.AutoLoad));
createXMLSetting("AutoSave", "Auto Save", toStr(GCSettings.AutoSave));
createXMLSetting("LoadMethod", "Load Method", toStr(GCSettings.LoadMethod));
createXMLSetting("SaveMethod", "Save Method", toStr(GCSettings.SaveMethod));
createXMLSetting("LoadFolder", "Load Folder", GCSettings.LoadFolder);
createXMLSetting("LastFileLoaded", "Last File Loaded", GCSettings.LastFileLoaded);
2008-08-20 09:58:55 +02:00
createXMLSetting("SaveFolder", "Save Folder", GCSettings.SaveFolder);
createXMLSetting("AppendAuto", "Append Auto to .SAV Files", toStr(GCSettings.AppendAuto));
2008-08-20 09:58:55 +02:00
createXMLSetting("CheatFolder", "Cheats Folder", GCSettings.CheatFolder);
createXMLSetting("ScreenshotsFolder", "Screenshots Folder", GCSettings.ScreenshotsFolder);
2016-12-09 01:51:57 +01:00
createXMLSetting("CoverFolder", "Covers Folder", GCSettings.CoverFolder);
2018-08-27 04:33:04 +02:00
createXMLSetting("ArtworkFolder", "Artwork Folder", GCSettings.ArtworkFolder);
2016-12-09 01:51:57 +01:00
2008-08-20 09:58:55 +02:00
createXMLSection("Network", "Network Settings");
createXMLSetting("smbip", "Share Computer IP", GCSettings.smbip);
createXMLSetting("smbshare", "Share Name", GCSettings.smbshare);
createXMLSetting("smbuser", "Share Username", GCSettings.smbuser);
createXMLSetting("smbpwd", "Share Password", GCSettings.smbpwd);
2009-03-11 18:28:37 +01:00
createXMLSection("Video", "Video Settings");
2008-08-20 09:58:55 +02:00
2009-04-27 09:49:38 +02:00
createXMLSetting("videomode", "Video Mode", toStr(GCSettings.videomode));
2009-11-16 09:13:02 +01:00
createXMLSetting("zoomHor", "Horizontal Zoom Level", FtoStr(GCSettings.zoomHor));
createXMLSetting("zoomVert", "Vertical Zoom Level", FtoStr(GCSettings.zoomVert));
2008-08-20 09:58:55 +02:00
createXMLSetting("render", "Video Filtering", toStr(GCSettings.render));
createXMLSetting("widescreen", "Aspect Ratio Correction", toStr(GCSettings.widescreen));
createXMLSetting("crosshair", "Crosshair", toStr(GCSettings.crosshair));
createXMLSetting("FilterMethod", "Filter Method", toStr(GCSettings.FilterMethod));
createXMLSetting("xshift", "Horizontal Video Shift", toStr(GCSettings.xshift));
createXMLSetting("yshift", "Vertical Video Shift", toStr(GCSettings.yshift));
createXMLSetting("sfxOverclock", "SuperFX Overclock", toStr(GCSettings.sfxOverclock));
createXMLSetting("Interpolation", "Interpolation", toStr(GCSettings.Interpolation));
2008-08-20 09:58:55 +02:00
2009-03-11 18:28:37 +01:00
createXMLSection("Menu", "Menu Settings");
#ifdef HW_RVL
2009-03-11 18:28:37 +01:00
createXMLSetting("WiimoteOrientation", "Wiimote Orientation", toStr(GCSettings.WiimoteOrientation));
#endif
2009-03-11 18:28:37 +01:00
createXMLSetting("ExitAction", "Exit Action", toStr(GCSettings.ExitAction));
createXMLSetting("MusicVolume", "Music Volume", toStr(GCSettings.MusicVolume));
createXMLSetting("SFXVolume", "Sound Effects Volume", toStr(GCSettings.SFXVolume));
2009-05-30 08:28:12 +02:00
createXMLSetting("Rumble", "Rumble", toStr(GCSettings.Rumble));
2010-01-25 22:05:38 +01:00
createXMLSetting("language", "Language", toStr(GCSettings.language));
2016-12-09 01:51:57 +01:00
createXMLSetting("PreviewImage", "Preview Image", toStr(GCSettings.PreviewImage));
2008-08-20 09:58:55 +02:00
createXMLSection("Controller", "Controller Settings");
2009-03-11 18:28:37 +01:00
createXMLSetting("Controller", "Controller", toStr(GCSettings.Controller));
2008-08-20 09:58:55 +02:00
2009-03-11 18:28:37 +01:00
createXMLController(btnmap[CTRL_PAD][CTRLR_GCPAD], "btnmap_pad_gcpad", "SNES Pad - GameCube Controller");
#ifdef HW_RVL
2009-03-11 18:28:37 +01:00
createXMLController(btnmap[CTRL_PAD][CTRLR_WIIMOTE], "btnmap_pad_wiimote", "SNES Pad - Wiimote");
createXMLController(btnmap[CTRL_PAD][CTRLR_CLASSIC], "btnmap_pad_classic", "SNES Pad - Classic Controller");
createXMLController(btnmap[CTRL_PAD][CTRLR_WUPC], "btnmap_pad_wupc", "SNES Pad - Wii U Pro Controller");
createXMLController(btnmap[CTRL_PAD][CTRLR_WIIDRC], "btnmap_pad_wiidrc", "SNES Pad - Wii U Gamepad");
2009-03-11 18:28:37 +01:00
createXMLController(btnmap[CTRL_PAD][CTRLR_NUNCHUK], "btnmap_pad_nunchuk", "SNES Pad - Nunchuk + Wiimote");
#endif
2009-03-11 18:28:37 +01:00
createXMLController(btnmap[CTRL_SCOPE][CTRLR_GCPAD], "btnmap_scope_gcpad", "Superscope - GameCube Controller");
#ifdef HW_RVL
2009-03-11 18:28:37 +01:00
createXMLController(btnmap[CTRL_SCOPE][CTRLR_WIIMOTE], "btnmap_scope_wiimote", "Superscope - Wiimote");
#endif
2009-03-20 09:26:10 +01:00
createXMLController(btnmap[CTRL_MOUSE][CTRLR_GCPAD], "btnmap_mouse_gcpad", "Mouse - GameCube Controller");
#ifdef HW_RVL
2009-03-11 18:28:37 +01:00
createXMLController(btnmap[CTRL_MOUSE][CTRLR_WIIMOTE], "btnmap_mouse_wiimote", "Mouse - Wiimote");
#endif
2009-03-11 18:28:37 +01:00
createXMLController(btnmap[CTRL_JUST][CTRLR_GCPAD], "btnmap_just_gcpad", "Justifier - GameCube Controller");
#ifdef HW_RVL
2009-03-11 18:28:37 +01:00
createXMLController(btnmap[CTRL_JUST][CTRLR_WIIMOTE], "btnmap_just_wiimote", "Justifier - Wiimote");
#endif
int datasize = mxmlSaveString(xml, (char *)savebuffer, SAVEBUFFERSIZE, XMLSaveCallback);
2008-08-20 09:58:55 +02:00
mxmlDelete(xml);
return datasize;
}
/****************************************************************************
* loadXMLSetting
*
* Load XML elements into variables for an individual variable
***************************************************************************/
static void loadXMLSetting(char * var, const char * name, int maxsize)
2008-08-20 09:58:55 +02:00
{
item = mxmlFindElement(xml, xml, "setting", "name", name, MXML_DESCEND);
if(item)
{
const char * tmp = mxmlElementGetAttr(item, "value");
if(tmp)
snprintf(var, maxsize, "%s", tmp);
}
2008-08-20 09:58:55 +02:00
}
static void loadXMLSetting(int * var, const char * name)
2008-08-20 09:58:55 +02:00
{
item = mxmlFindElement(xml, xml, "setting", "name", name, MXML_DESCEND);
if(item)
{
const char * tmp = mxmlElementGetAttr(item, "value");
if(tmp)
*var = atoi(tmp);
}
2008-08-20 09:58:55 +02:00
}
static void loadXMLSetting(float * var, const char * name)
2008-10-24 07:11:01 +02:00
{
item = mxmlFindElement(xml, xml, "setting", "name", name, MXML_DESCEND);
if(item)
{
const char * tmp = mxmlElementGetAttr(item, "value");
if(tmp)
*var = atof(tmp);
}
2008-10-24 07:11:01 +02:00
}
2008-08-20 09:58:55 +02:00
/****************************************************************************
* loadXMLController
*
* Load XML elements into variables for a controller mapping
***************************************************************************/
static void loadXMLController(u32 controller[], const char * name)
2008-08-20 09:58:55 +02:00
{
item = mxmlFindElement(xml, xml, "controller", "name", name, MXML_DESCEND);
if(item)
{
// populate buttons
2008-09-27 09:13:52 +02:00
for(int i=0; i < MAXJP; i++)
2008-08-20 09:58:55 +02:00
{
elem = mxmlFindElement(item, xml, "button", "number", toStr(i), MXML_DESCEND);
if(elem)
{
const char * tmp = mxmlElementGetAttr(elem, "assignment");
if(tmp)
controller[i] = atoi(tmp);
}
2008-08-20 09:58:55 +02:00
}
}
}
/****************************************************************************
* decodePrefsData
*
* Decodes preferences - parses XML and loads preferences into the variables
***************************************************************************/
static bool
2009-10-02 00:35:12 +02:00
decodePrefsData ()
{
bool result = false;
2008-08-20 09:58:55 +02:00
xml = mxmlLoadString(NULL, (char *)savebuffer, MXML_TEXT_CALLBACK);
2008-08-20 09:58:55 +02:00
if(xml)
{
// check settings version
item = mxmlFindElement(xml, xml, "file", "version", NULL, MXML_DESCEND);
if(item) // a version entry exists
{
const char * version = mxmlElementGetAttr(item, "version");
2008-08-20 09:58:55 +02:00
2009-03-28 20:03:35 +01:00
if(version && strlen(version) == 5)
{
2009-03-28 20:03:35 +01:00
// this code assumes version in format X.X.X
// XX.X.X, X.XX.X, or X.X.XX will NOT work
int verMajor = version[0] - '0';
int verMinor = version[2] - '0';
int verPoint = version[4] - '0';
// check that the versioning is valid
if(!(verMajor >= 4 && verMajor <= 9 &&
2009-03-28 20:03:35 +01:00
verMinor >= 0 && verMinor <= 9 &&
verPoint >= 0 && verPoint <= 9)) {
2009-03-28 20:03:35 +01:00
result = false;
}
else {
2009-03-28 20:03:35 +01:00
result = true;
}
}
}
2008-08-20 09:58:55 +02:00
if(result)
{
// File Settings
loadXMLSetting(&GCSettings.AutoLoad, "AutoLoad");
loadXMLSetting(&GCSettings.AutoSave, "AutoSave");
loadXMLSetting(&GCSettings.LoadMethod, "LoadMethod");
loadXMLSetting(&GCSettings.SaveMethod, "SaveMethod");
loadXMLSetting(GCSettings.LoadFolder, "LoadFolder", sizeof(GCSettings.LoadFolder));
loadXMLSetting(GCSettings.LastFileLoaded, "LastFileLoaded", sizeof(GCSettings.LastFileLoaded));
loadXMLSetting(GCSettings.SaveFolder, "SaveFolder", sizeof(GCSettings.SaveFolder));
loadXMLSetting(&GCSettings.AppendAuto, "AppendAuto");
loadXMLSetting(GCSettings.CheatFolder, "CheatFolder", sizeof(GCSettings.CheatFolder));
loadXMLSetting(GCSettings.ScreenshotsFolder, "ScreenshotsFolder", sizeof(GCSettings.ScreenshotsFolder));
2016-12-09 01:51:57 +01:00
loadXMLSetting(GCSettings.CoverFolder, "CoverFolder", sizeof(GCSettings.CoverFolder));
loadXMLSetting(GCSettings.ArtworkFolder, "ArtworkFolder", sizeof(GCSettings.ArtworkFolder));
// Network Settings
loadXMLSetting(GCSettings.smbip, "smbip", sizeof(GCSettings.smbip));
loadXMLSetting(GCSettings.smbshare, "smbshare", sizeof(GCSettings.smbshare));
loadXMLSetting(GCSettings.smbuser, "smbuser", sizeof(GCSettings.smbuser));
loadXMLSetting(GCSettings.smbpwd, "smbpwd", sizeof(GCSettings.smbpwd));
2009-03-11 18:28:37 +01:00
// Video Settings
2009-04-27 09:49:38 +02:00
loadXMLSetting(&GCSettings.videomode, "videomode");
2009-11-16 09:13:02 +01:00
loadXMLSetting(&GCSettings.zoomHor, "zoomHor");
loadXMLSetting(&GCSettings.zoomVert, "zoomVert");
loadXMLSetting(&GCSettings.render, "render");
loadXMLSetting(&GCSettings.widescreen, "widescreen");
loadXMLSetting(&GCSettings.crosshair, "crosshair");
loadXMLSetting(&GCSettings.FilterMethod, "FilterMethod");
loadXMLSetting(&GCSettings.xshift, "xshift");
loadXMLSetting(&GCSettings.yshift, "yshift");
// Audio Settings
loadXMLSetting(&GCSettings.Interpolation, "Interpolation");
// Emulation Settings
2016-03-12 21:58:51 +01:00
loadXMLSetting(&GCSettings.sfxOverclock, "sfxOverclock");
2016-03-12 21:58:51 +01:00
2009-03-11 18:28:37 +01:00
// Menu Settings
loadXMLSetting(&GCSettings.WiimoteOrientation, "WiimoteOrientation");
loadXMLSetting(&GCSettings.ExitAction, "ExitAction");
loadXMLSetting(&GCSettings.MusicVolume, "MusicVolume");
loadXMLSetting(&GCSettings.SFXVolume, "SFXVolume");
2009-05-30 08:28:12 +02:00
loadXMLSetting(&GCSettings.Rumble, "Rumble");
2010-01-25 22:05:38 +01:00
loadXMLSetting(&GCSettings.language, "language");
2016-12-09 01:51:57 +01:00
loadXMLSetting(&GCSettings.PreviewImage, "PreviewImage");
2009-03-11 18:28:37 +01:00
// Controller Settings
2009-03-11 18:28:37 +01:00
loadXMLSetting(&GCSettings.Controller, "Controller");
loadXMLController(btnmap[CTRL_PAD][CTRLR_GCPAD], "btnmap_pad_gcpad");
loadXMLController(btnmap[CTRL_PAD][CTRLR_WIIMOTE], "btnmap_pad_wiimote");
loadXMLController(btnmap[CTRL_PAD][CTRLR_CLASSIC], "btnmap_pad_classic");
loadXMLController(btnmap[CTRL_PAD][CTRLR_WUPC], "btnmap_pad_wupc");
loadXMLController(btnmap[CTRL_PAD][CTRLR_WIIDRC], "btnmap_pad_wiidrc");
2009-03-11 18:28:37 +01:00
loadXMLController(btnmap[CTRL_PAD][CTRLR_NUNCHUK], "btnmap_pad_nunchuk");
loadXMLController(btnmap[CTRL_SCOPE][CTRLR_GCPAD], "btnmap_scope_gcpad");
loadXMLController(btnmap[CTRL_SCOPE][CTRLR_WIIMOTE], "btnmap_scope_wiimote");
loadXMLController(btnmap[CTRL_MOUSE][CTRLR_GCPAD], "btnmap_mouse_gcpad");
loadXMLController(btnmap[CTRL_MOUSE][CTRLR_WIIMOTE], "btnmap_mouse_wiimote");
loadXMLController(btnmap[CTRL_JUST][CTRLR_GCPAD], "btnmap_just_gcpad");
loadXMLController(btnmap[CTRL_JUST][CTRLR_WIIMOTE], "btnmap_just_wiimote");
2016-03-12 21:58:51 +01:00
}
mxmlDelete(xml);
}
return result;
}
2010-01-25 22:05:38 +01:00
/****************************************************************************
* FixInvalidSettings
*
* Attempts to correct at least some invalid settings - the ones that
* might cause crashes
***************************************************************************/
void FixInvalidSettings()
{
2010-06-04 23:50:24 +02:00
if(GCSettings.LoadMethod > 6)
2010-01-25 22:05:38 +01:00
GCSettings.LoadMethod = DEVICE_AUTO;
2010-06-04 23:50:24 +02:00
if(GCSettings.SaveMethod > 6)
2010-01-25 22:05:38 +01:00
GCSettings.SaveMethod = DEVICE_AUTO;
if(!(GCSettings.zoomHor > 0.5 && GCSettings.zoomHor < 1.5))
GCSettings.zoomHor = 1.0;
if(!(GCSettings.zoomVert > 0.5 && GCSettings.zoomVert < 1.5))
GCSettings.zoomVert = 1.0;
if(!(GCSettings.xshift > -50 && GCSettings.xshift < 50))
GCSettings.xshift = 0;
if(!(GCSettings.yshift > -50 && GCSettings.yshift < 50))
GCSettings.yshift = 0;
if(!(GCSettings.MusicVolume >= 0 && GCSettings.MusicVolume <= 100))
GCSettings.MusicVolume = 20;
2010-01-25 22:05:38 +01:00
if(!(GCSettings.SFXVolume >= 0 && GCSettings.SFXVolume <= 100))
GCSettings.SFXVolume = 40;
2010-08-29 23:43:32 +02:00
if(GCSettings.language < 0 || GCSettings.language >= LANG_LENGTH)
2010-01-25 22:05:38 +01:00
GCSettings.language = LANG_ENGLISH;
if(GCSettings.Controller > CTRL_PAD4 || GCSettings.Controller < CTRL_MOUSE)
GCSettings.Controller = CTRL_PAD2;
if(!(GCSettings.render >= 0 && GCSettings.render < 5))
2018-08-27 04:33:04 +02:00
GCSettings.render = 3;
2010-01-25 22:05:38 +01:00
if(!(GCSettings.videomode >= 0 && GCSettings.videomode < 5))
GCSettings.videomode = 0;
}
/****************************************************************************
* DefaultSettings
*
* Sets all the defaults!
***************************************************************************/
void
DefaultSettings ()
{
memset (&GCSettings, 0, sizeof (GCSettings));
ResetControls(); // controller button mappings
GCSettings.LoadMethod = DEVICE_AUTO; // Auto, SD, DVD, USB, Network (SMB)
GCSettings.SaveMethod = DEVICE_AUTO; // Auto, SD, USB, Network (SMB)
sprintf (GCSettings.LoadFolder, "%s/roms", APPFOLDER); // Path to game files
sprintf (GCSettings.SaveFolder, "%s/saves", APPFOLDER); // Path to save files
sprintf (GCSettings.CheatFolder, "%s/cheats", APPFOLDER); // Path to cheat files
2016-12-09 01:51:57 +01:00
sprintf (GCSettings.ScreenshotsFolder, "%s/screenshots", APPFOLDER); // Path to screenshot files
sprintf (GCSettings.CoverFolder, "%s/covers", APPFOLDER); // Path to cover files
2018-08-27 04:33:04 +02:00
sprintf (GCSettings.ArtworkFolder, "%s/artwork", APPFOLDER); // Path to artwork files
2010-01-25 22:05:38 +01:00
GCSettings.AutoLoad = 1;
GCSettings.AutoSave = 1;
GCSettings.Controller = CTRL_PAD2;
GCSettings.videomode = 0; // automatic video mode detection
2018-08-27 04:33:04 +02:00
GCSettings.render = 3; // Filtered (sharp)
2010-01-25 22:05:38 +01:00
GCSettings.FilterMethod = FILTER_NONE; // no hq2x
GCSettings.widescreen = 0;
#ifdef HW_RVL
if (CONF_GetAspectRatio() == CONF_ASPECT_16_9)
GCSettings.widescreen = 1;
#endif
2010-01-25 22:05:38 +01:00
GCSettings.zoomHor = 1.0; // horizontal zoom level
GCSettings.zoomVert = 1.0; // vertical zoom level
GCSettings.xshift = 0; // horizontal video shift
GCSettings.yshift = 0; // vertical video shift
GCSettings.crosshair = 1;
2010-01-25 22:05:38 +01:00
GCSettings.WiimoteOrientation = 0;
GCSettings.ExitAction = 0;
GCSettings.AutoloadGame = 0;
GCSettings.MusicVolume = 20;
2010-01-25 22:05:38 +01:00
GCSettings.SFXVolume = 40;
GCSettings.Rumble = 1;
2016-12-09 01:51:57 +01:00
GCSettings.PreviewImage = 0;
2010-01-25 22:34:12 +01:00
#ifdef HW_RVL
2010-01-25 22:05:38 +01:00
GCSettings.language = CONF_GetLanguage();
2010-03-16 00:29:02 +01:00
if(GCSettings.language == LANG_JAPANESE ||
GCSettings.language == LANG_SIMP_CHINESE ||
GCSettings.language == LANG_TRAD_CHINESE ||
GCSettings.language == LANG_KOREAN)
GCSettings.language = LANG_ENGLISH;
2010-01-25 22:34:12 +01:00
#else
GCSettings.language = LANG_ENGLISH;
#endif
2010-01-25 22:05:38 +01:00
/****************** SNES9x Settings ***********************/
// Default ALL to false
memset (&Settings, 0, sizeof (Settings));
// General
2010-01-27 23:08:56 +01:00
Settings.MouseMaster = true;
Settings.SuperScopeMaster = true;
Settings.JustifierMaster = true;
Settings.MultiPlayer5Master = true;
2010-01-28 05:00:25 +01:00
Settings.DontSaveOopsSnapshot = true;
2011-02-15 18:08:35 +01:00
Settings.ApplyCheats = true;
2010-01-25 22:05:38 +01:00
Settings.HDMATimingHack = 100;
Settings.BlockInvalidVRAMAccessMaster = true;
Settings.IsPatched = 0;
2010-01-25 22:05:38 +01:00
// Sound
2018-08-14 19:00:45 +02:00
Settings.SoundSync = true;
2010-01-25 22:05:38 +01:00
Settings.SixteenBitSound = true;
2010-01-27 23:08:56 +01:00
Settings.Stereo = true;
2010-03-31 04:50:05 +02:00
Settings.ReverseStereo = true;
Settings.SoundPlaybackRate = 48000;
Settings.SoundInputRate = 31920;
2018-08-14 19:00:45 +02:00
Settings.DynamicRateControl = true;
Settings.SeparateEchoBuffer = false;
// Interpolation Method
GCSettings.Interpolation = 0;
Settings.InterpolationMethod = DSP_INTERPOLATION_GAUSSIAN;
2010-01-25 22:05:38 +01:00
// Graphics
Settings.Transparency = true;
Settings.SupportHiRes = true;
Settings.MaxSpriteTilesPerLine = 34;
2010-01-25 22:05:38 +01:00
Settings.SkipFrames = AUTO_FRAMERATE;
Settings.TurboSkipFrames = 19;
Settings.DisplayFrameRate = false;
Settings.AutoDisplayMessages = 0;
Settings.InitialInfoStringTimeout = 200; // # frames to display messages for
// Frame timings in 50hz and 60hz cpu mode
Settings.FrameTimePAL = 20000;
Settings.FrameTimeNTSC = 16667;
2016-03-12 21:58:51 +01:00
GCSettings.sfxOverclock = 0;
/* Initialize SuperFX CPU to normal speed by default */
Settings.SuperFXSpeedPerLine = 5823405;
Settings.SuperFXClockMultiplier = 100;
Settings.OverclockMode = 0;
Settings.OneClockCycle = 6;
Settings.OneSlowClockCycle = 8;
Settings.TwoClockCycles = 12;
2010-01-25 22:05:38 +01:00
}
/****************************************************************************
* Save Preferences
***************************************************************************/
2009-10-02 00:35:12 +02:00
static char prefpath[MAXPATHLEN] = { 0 };
bool
SavePrefs (bool silent)
{
2009-10-02 00:35:12 +02:00
char filepath[MAXPATHLEN];
2008-11-12 08:50:39 +01:00
int datasize;
int offset = 0;
2009-10-02 00:35:12 +02:00
int device = 0;
if(prefpath[0] != 0)
{
sprintf(filepath, "%s/%s", prefpath, PREF_FILE_NAME);
2009-10-02 00:35:12 +02:00
FindDevice(filepath, &device);
}
else if(appPath[0] != 0)
{
2009-10-05 03:32:33 +02:00
sprintf(filepath, "%s/%s", appPath, PREF_FILE_NAME);
strcpy(prefpath, appPath);
2009-10-02 00:35:12 +02:00
FindDevice(filepath, &device);
}
else
{
2009-10-06 08:37:53 +02:00
device = autoSaveMethod(silent);
2009-10-02 00:35:12 +02:00
if(device == 0)
return false;
sprintf(filepath, "%s%s", pathPrefix[device], APPFOLDER);
2011-01-20 03:52:56 +01:00
DIR *dir = opendir(filepath);
2010-08-14 07:55:21 +02:00
if (!dir)
{
2010-08-14 07:55:21 +02:00
if(mkdir(filepath, 0777) != 0)
return false;
sprintf(filepath, "%s%s/roms", pathPrefix[device], APPFOLDER);
2010-08-14 07:55:21 +02:00
if(mkdir(filepath, 0777) != 0)
return false;
sprintf(filepath, "%s%s/saves", pathPrefix[device], APPFOLDER);
2010-08-14 07:55:21 +02:00
if(mkdir(filepath, 0777) != 0)
return false;
}
else
{
2011-01-20 03:52:56 +01:00
closedir(dir);
}
2009-11-29 09:12:40 +01:00
sprintf(filepath, "%s%s/%s", pathPrefix[device], APPFOLDER, PREF_FILE_NAME);
sprintf(prefpath, "%s%s", pathPrefix[device], APPFOLDER);
2009-10-02 00:35:12 +02:00
}
if(device == 0)
2008-11-12 08:50:39 +01:00
return false;
if (!silent)
2008-12-18 19:36:30 +01:00
ShowAction ("Saving preferences...");
2009-03-17 06:09:45 +01:00
FixInvalidSettings();
2008-11-12 08:50:39 +01:00
AllocSaveBuffer ();
2009-10-02 00:35:12 +02:00
datasize = preparePrefsData ();
2008-11-12 08:50:39 +01:00
2009-10-02 00:35:12 +02:00
offset = SaveFile(filepath, datasize, silent);
2008-09-27 09:13:52 +02:00
FreeSaveBuffer ();
2009-03-11 18:28:37 +01:00
CancelAction();
if (offset > 0)
{
2008-08-20 09:58:55 +02:00
if (!silent)
2009-03-11 18:28:37 +01:00
InfoPrompt("Preferences saved");
2008-08-20 09:58:55 +02:00
return true;
}
2008-08-20 09:58:55 +02:00
return false;
}
/****************************************************************************
2009-10-02 00:35:12 +02:00
* Load Preferences from specified filepath
***************************************************************************/
bool
LoadPrefsFromMethod (char * path)
{
bool retval = false;
int offset = 0;
char filepath[MAXPATHLEN];
sprintf(filepath, "%s/%s", path, PREF_FILE_NAME);
2008-09-27 09:13:52 +02:00
AllocSaveBuffer ();
2009-10-02 00:35:12 +02:00
offset = LoadFile(filepath, SILENT);
if (offset > 0)
2009-10-02 00:35:12 +02:00
retval = decodePrefsData ();
2008-09-04 04:42:27 +02:00
2008-09-27 09:13:52 +02:00
FreeSaveBuffer ();
2009-10-02 00:35:12 +02:00
if(retval)
2009-12-23 08:21:05 +01:00
{
strcpy(prefpath, path);
2008-09-27 09:13:52 +02:00
2009-12-23 08:21:05 +01:00
if(appPath[0] == 0)
strcpy(appPath, prefpath);
}
return retval;
}
2008-09-04 04:42:27 +02:00
/****************************************************************************
* Load Preferences
* Checks sources consecutively until we find a preference file
***************************************************************************/
2009-03-11 18:28:37 +01:00
static bool prefLoaded = false;
2008-09-04 04:42:27 +02:00
bool LoadPrefs()
{
2009-03-11 18:28:37 +01:00
if(prefLoaded) // already attempted loading
return true;
2008-09-04 04:42:27 +02:00
bool prefFound = false;
2009-12-23 08:21:05 +01:00
char filepath[5][MAXPATHLEN];
2009-10-02 00:35:12 +02:00
int numDevices;
#ifdef HW_RVL
2009-12-23 08:21:05 +01:00
numDevices = 5;
sprintf(filepath[0], "%s", appPath);
2009-12-23 08:21:05 +01:00
sprintf(filepath[1], "sd:/apps/%s", APPFOLDER);
sprintf(filepath[2], "usb:/apps/%s", APPFOLDER);
sprintf(filepath[3], "sd:/%s", APPFOLDER);
sprintf(filepath[4], "usb:/%s", APPFOLDER);
2009-10-02 00:35:12 +02:00
#else
2009-11-29 09:12:40 +01:00
numDevices = 2;
sprintf(filepath[0], "carda:/%s", APPFOLDER);
sprintf(filepath[1], "cardb:/%s", APPFOLDER);
2009-10-02 00:35:12 +02:00
#endif
for(int i=0; i<numDevices; i++)
{
2009-10-02 00:35:12 +02:00
prefFound = LoadPrefsFromMethod(filepath[i]);
if(prefFound)
break;
}
2008-09-04 04:42:27 +02:00
2009-03-11 18:28:37 +01:00
prefLoaded = true; // attempted to load preferences
if(prefFound) {
2009-03-17 06:09:45 +01:00
FixInvalidSettings();
}
2009-12-23 08:21:05 +01:00
// rename snes9x to snes9xgx
if(GCSettings.LoadMethod == DEVICE_SD)
{
2011-01-20 03:52:56 +01:00
if(ChangeInterface(DEVICE_SD, NOTSILENT) && opendir("sd:/snes9x"))
2009-12-23 08:21:05 +01:00
rename("sd:/snes9x", "sd:/snes9xgx");
}
else if(GCSettings.LoadMethod == DEVICE_USB)
{
2011-01-20 03:52:56 +01:00
if(ChangeInterface(DEVICE_USB, NOTSILENT) && opendir("usb:/snes9x"))
2009-12-23 08:21:05 +01:00
rename("usb:/snes9x", "usb:/snes9xgx");
}
else if(GCSettings.LoadMethod == DEVICE_SMB)
{
2011-01-20 03:52:56 +01:00
if(ChangeInterface(DEVICE_SMB, NOTSILENT) && opendir("smb:/snes9x"))
2009-12-23 08:21:05 +01:00
rename("smb:/snes9x", "smb:/snes9xgx");
}
// update folder locations
if(strcmp(GCSettings.LoadFolder, "snes9x/roms") == 0)
sprintf(GCSettings.LoadFolder, "snes9xgx/roms");
if(strcmp(GCSettings.SaveFolder, "snes9x/saves") == 0)
sprintf(GCSettings.SaveFolder, "snes9xgx/saves");
if(strcmp(GCSettings.CheatFolder, "snes9x/cheats") == 0)
sprintf(GCSettings.CheatFolder, "snes9xgx/cheats");
if(strcmp(GCSettings.ScreenshotsFolder, "snes9x/screenshots") == 0)
sprintf(GCSettings.ScreenshotsFolder, "snes9xgx/screenshots");
2009-03-17 06:09:45 +01:00
2016-12-09 01:51:57 +01:00
if(strcmp(GCSettings.CoverFolder, "snes9x/covers") == 0)
sprintf(GCSettings.CoverFolder, "snes9xgx/covers");
2018-08-27 04:33:04 +02:00
if(strcmp(GCSettings.ArtworkFolder, "snes9x/artwork") == 0)
sprintf(GCSettings.ArtworkFolder, "snes9xgx/artwork");
2016-12-09 01:51:57 +01:00
// attempt to create directories if they don't exist
if(GCSettings.LoadMethod == DEVICE_SD || GCSettings.LoadMethod == DEVICE_USB) {
char dirPath[MAXPATHLEN];
sprintf(dirPath, "%s%s", pathPrefix[GCSettings.LoadMethod], GCSettings.ScreenshotsFolder);
CreateDirectory(dirPath);
sprintf(dirPath, "%s%s", pathPrefix[GCSettings.LoadMethod], GCSettings.CoverFolder);
CreateDirectory(dirPath);
sprintf(dirPath, "%s%s", pathPrefix[GCSettings.LoadMethod], GCSettings.ArtworkFolder);
CreateDirectory(dirPath);
sprintf(dirPath, "%s%s", pathPrefix[GCSettings.LoadMethod], GCSettings.CheatFolder);
CreateDirectory(dirPath);
}
ChangeLanguage();
#ifdef HW_RVL
bg_music = (u8 * )bg_music_ogg;
bg_music_size = bg_music_ogg_size;
LoadBgMusic();
#endif
2008-09-04 04:42:27 +02:00
return prefFound;
}