mirror of
https://github.com/libretro/beetle-psx-libretro.git
synced 2024-11-23 08:49:47 +00:00
Now no longer needs mednafen config file
This commit is contained in:
parent
9eeab7b391
commit
f269f2390d
19
libretro.cpp
19
libretro.cpp
@ -34,24 +34,7 @@ void retro_init()
|
||||
|
||||
if (environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &dir) && dir)
|
||||
{
|
||||
std::string eu_path = dir;
|
||||
eu_path += "/scph5502.bin";
|
||||
|
||||
std::string jp_path = dir;
|
||||
jp_path += "/scph5500.bin";
|
||||
|
||||
std::string na_path = dir;
|
||||
na_path += "/scph5501.bin";
|
||||
|
||||
MDFNSetting jp_setting = { "psx.bios_jp", MDFNSF_EMU_STATE, "SCPH-5500 BIOS", NULL, MDFNST_STRING, jp_path.c_str() };
|
||||
MDFNSetting eu_setting = { "psx.bios_eu", MDFNSF_EMU_STATE, "SCPH-5502 BIOS", NULL, MDFNST_STRING, eu_path.c_str() };
|
||||
MDFNSetting na_setting = { "psx.bios_na", MDFNSF_EMU_STATE, "SCPH-5501 BIOS", NULL, MDFNST_STRING, na_path.c_str() };
|
||||
MDFNSetting filesys = { "filesys.path_sav", MDFNSF_NOFLAGS, "Memcards", NULL, MDFNST_STRING, "." };
|
||||
settings.push_back(jp_setting);
|
||||
settings.push_back(eu_setting);
|
||||
settings.push_back(na_setting);
|
||||
settings.push_back(filesys);
|
||||
MDFNI_Initialize(dir, settings);
|
||||
MDFNI_Initialize(dir);
|
||||
|
||||
retro_base_directory = dir;
|
||||
}
|
||||
|
@ -35,16 +35,6 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
static string BaseDirectory;
|
||||
static string FileBase;
|
||||
static string FileExt; /* Includes the . character, as in ".nes" */
|
||||
static string FileBaseDirectory;
|
||||
|
||||
void MDFNI_SetBaseDirectory(const char *dir)
|
||||
{
|
||||
BaseDirectory = string(dir);
|
||||
}
|
||||
|
||||
// Really dumb, maybe we should use boost?
|
||||
static bool IsAbsolutePath(const char *path)
|
||||
{
|
||||
@ -239,53 +229,6 @@ const char * GetFNComponent(const char *str)
|
||||
return(str);
|
||||
}
|
||||
|
||||
void GetFileBase(const char *f)
|
||||
{
|
||||
const char *tp1,*tp3;
|
||||
|
||||
#if PSS_STYLE==4
|
||||
tp1=((char *)strrchr(f,':'));
|
||||
#elif PSS_STYLE==1
|
||||
tp1=((char *)strrchr(f,'/'));
|
||||
#else
|
||||
tp1=((char *)strrchr(f,'\\'));
|
||||
#if PSS_STYLE!=3
|
||||
tp3=((char *)strrchr(f,'/'));
|
||||
if(tp1<tp3) tp1=tp3;
|
||||
#endif
|
||||
#endif
|
||||
if(!tp1)
|
||||
{
|
||||
tp1=f;
|
||||
FileBaseDirectory = ".";
|
||||
}
|
||||
else
|
||||
{
|
||||
char tmpfn[tp1 - f + 1];
|
||||
|
||||
memcpy(tmpfn,f,tp1-f);
|
||||
tmpfn[tp1-f]=0;
|
||||
FileBaseDirectory = string(tmpfn);
|
||||
|
||||
tp1++;
|
||||
}
|
||||
|
||||
if(((tp3=strrchr(f,'.'))!=NULL) && (tp3>tp1))
|
||||
{
|
||||
char tmpbase[tp3 - tp1 + 1];
|
||||
|
||||
memcpy(tmpbase,tp1,tp3-tp1);
|
||||
tmpbase[tp3-tp1]=0;
|
||||
FileBase = string(tmpbase);
|
||||
FileExt = string(tp3);
|
||||
}
|
||||
else
|
||||
{
|
||||
FileBase = string(tp1);
|
||||
FileExt = "";
|
||||
}
|
||||
}
|
||||
|
||||
char *MDFN_RemoveControlChars(char *str)
|
||||
{
|
||||
char *orig = str;
|
||||
|
@ -67,7 +67,7 @@ bool MDFNI_InitializeModules(const std::vector<MDFNGI *> &ExternalSystems);
|
||||
|
||||
/* allocates memory. 0 on failure, 1 on success. */
|
||||
/* Also pass it the base directory to load the configuration file. */
|
||||
int MDFNI_Initialize(const char *basedir, const std::vector<MDFNSetting> &DriverSettings);
|
||||
int MDFNI_Initialize(const char *basedir);
|
||||
|
||||
/* Sets the base directory(save states, snapshots, etc. are saved in directories
|
||||
below this directory. */
|
||||
|
@ -238,18 +238,10 @@ MDFNGI *MDFNI_LoadCD(const char *force_module, const char *devicename)
|
||||
{
|
||||
CDInterfaces.push_back(new CDIF_MT(file_list[i].c_str()));
|
||||
}
|
||||
|
||||
GetFileBase(devicename);
|
||||
}
|
||||
else
|
||||
{
|
||||
CDInterfaces.push_back(new CDIF_MT(devicename));
|
||||
if(CDInterfaces[0]->IsPhysical())
|
||||
{
|
||||
GetFileBase("cdrom");
|
||||
}
|
||||
else
|
||||
GetFileBase(devicename);
|
||||
}
|
||||
}
|
||||
catch(std::exception &e)
|
||||
@ -464,8 +456,6 @@ MDFNGI *MDFNI_LoadGame(const char *force_module, const char *name)
|
||||
|
||||
MDFN_indent(1);
|
||||
|
||||
GetFileBase(name);
|
||||
|
||||
// Construct a NULL-delimited list of known file extensions for MDFN_fopen()
|
||||
for(unsigned int i = 0; i < MDFNSystems.size(); i++)
|
||||
{
|
||||
@ -572,13 +562,6 @@ MDFNGI *MDFNI_LoadGame(const char *force_module, const char *name)
|
||||
// Load per-game settings
|
||||
//
|
||||
// Maybe we should make a "pgcfg" subdir, and automatically load all files in it?
|
||||
#if 0
|
||||
{
|
||||
char hash_string[n + 1];
|
||||
const char *section_names[3] = { MDFNGameInfo->shortname, hash_string, NULL };
|
||||
//asdfasdfMDFN_LoadSettings(std::string(basedir) + std::string(PSS) + std::string("pergame.cfg");
|
||||
}
|
||||
#endif
|
||||
// End load per-game settings
|
||||
//
|
||||
|
||||
@ -631,102 +614,6 @@ MDFNGI *MDFNI_LoadGame(const char *force_module, const char *name)
|
||||
return(MDFNGameInfo);
|
||||
}
|
||||
|
||||
static void BuildDynamicSetting(MDFNSetting *setting, const char *system_name, const char *name, uint32 flags, const char *description, MDFNSettingType type,
|
||||
const char *default_value, const char *minimum = NULL, const char *maximum = NULL,
|
||||
bool (*validate_func)(const char *name, const char *value) = NULL, void (*ChangeNotification)(const char *name) = NULL)
|
||||
{
|
||||
char setting_name[256];
|
||||
|
||||
memset(setting, 0, sizeof(MDFNSetting));
|
||||
|
||||
trio_snprintf(setting_name, 256, "%s.%s", system_name, name);
|
||||
|
||||
setting->name = strdup(setting_name);
|
||||
setting->description = description;
|
||||
setting->type = type;
|
||||
setting->flags = flags;
|
||||
setting->default_value = default_value;
|
||||
setting->minimum = minimum;
|
||||
setting->maximum = maximum;
|
||||
setting->validate_func = validate_func;
|
||||
setting->ChangeNotification = ChangeNotification;
|
||||
}
|
||||
|
||||
std::vector<std::string> string_to_vecstrlist(const std::string &str_str)
|
||||
{
|
||||
std::vector<std::string> ret;
|
||||
const char *str = str_str.c_str();
|
||||
|
||||
bool in_quote = FALSE;
|
||||
const char *quote_begin = NULL;
|
||||
char last_char = 0;
|
||||
|
||||
while(*str || in_quote)
|
||||
{
|
||||
char c;
|
||||
|
||||
if(*str)
|
||||
c = *str;
|
||||
else // If the string has ended and we're still in a quote, get out of it!
|
||||
{
|
||||
c = '"';
|
||||
last_char = 0;
|
||||
}
|
||||
|
||||
if(last_char != '\\')
|
||||
{
|
||||
if(c == '"')
|
||||
{
|
||||
if(in_quote)
|
||||
{
|
||||
int64 str_length = str - quote_begin;
|
||||
char tmp_str[str_length];
|
||||
|
||||
memcpy(tmp_str, quote_begin, str_length);
|
||||
|
||||
ret.push_back(std::string(tmp_str));
|
||||
|
||||
quote_begin = NULL;
|
||||
in_quote = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
in_quote = TRUE;
|
||||
quote_begin = str + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
last_char = c;
|
||||
|
||||
if(*str)
|
||||
str++;
|
||||
}
|
||||
|
||||
|
||||
return(ret);
|
||||
}
|
||||
|
||||
std::string vecstrlist_to_string(const std::vector<std::string> &vslist)
|
||||
{
|
||||
std::string ret;
|
||||
|
||||
for(uint32 i = 0; i < vslist.size(); i++)
|
||||
{
|
||||
char *tmp_str = escape_string(vslist[i].c_str());
|
||||
|
||||
ret += "\"";
|
||||
|
||||
ret += std::string(tmp_str);
|
||||
|
||||
ret += "\" ";
|
||||
|
||||
free(tmp_str);
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
|
||||
|
||||
bool MDFNI_InitializeModules(const std::vector<MDFNGI *> &ExternalSystems)
|
||||
{
|
||||
static MDFNGI *InternalSystems[] =
|
||||
@ -821,65 +708,18 @@ bool MDFNI_InitializeModules(const std::vector<MDFNGI *> &ExternalSystems)
|
||||
}
|
||||
|
||||
static std::string settings_file_path;
|
||||
int MDFNI_Initialize(const char *basedir, const std::vector<MDFNSetting> &DriverSettings)
|
||||
int MDFNI_Initialize(const char *basedir)
|
||||
{
|
||||
// FIXME static
|
||||
static std::vector<MDFNSetting> dynamic_settings;
|
||||
|
||||
MDFNI_SetBaseDirectory(basedir);
|
||||
|
||||
// Generate dynamic settings
|
||||
for(unsigned int i = 0; i < MDFNSystems.size(); i++)
|
||||
{
|
||||
MDFNSetting setting;
|
||||
const char *sysname;
|
||||
|
||||
sysname = (const char *)MDFNSystems[i]->shortname;
|
||||
|
||||
if(!MDFNSystems[i]->soundchan)
|
||||
printf("0 sound channels for %s????\n", sysname);
|
||||
|
||||
if(MDFNSystems[i]->soundchan == 2)
|
||||
{
|
||||
BuildDynamicSetting(&setting, sysname, "forcemono", MDFNSF_COMMON_TEMPLATE | MDFNSF_CAT_SOUND, CSD_forcemono, MDFNST_BOOL, "0");
|
||||
dynamic_settings.push_back(setting);
|
||||
}
|
||||
|
||||
BuildDynamicSetting(&setting, sysname, "enable", MDFNSF_COMMON_TEMPLATE, CSD_enable, MDFNST_BOOL, "1");
|
||||
dynamic_settings.push_back(setting);
|
||||
}
|
||||
|
||||
if(DriverSettings.size())
|
||||
MDFN_MergeSettings(DriverSettings);
|
||||
|
||||
// First merge all settable settings, then load the settings from the SETTINGS FILE OF DOOOOM
|
||||
MDFN_MergeSettings(MednafenSettings);
|
||||
MDFN_MergeSettings(dynamic_settings);
|
||||
MDFN_MergeSettings(MDFNMP_Settings);
|
||||
|
||||
for(unsigned int x = 0; x < MDFNSystems.size(); x++)
|
||||
{
|
||||
if(MDFNSystems[x]->Settings)
|
||||
MDFN_MergeSettings(MDFNSystems[x]->Settings);
|
||||
}
|
||||
|
||||
MDFN_MergeSettings(RenamedSettings);
|
||||
|
||||
settings_file_path = std::string(basedir) + std::string(PSS) + std::string("mednafen-09x.cfg");
|
||||
if(!MDFN_LoadSettings(settings_file_path.c_str()))
|
||||
return(0);
|
||||
|
||||
#ifdef WANT_DEBUGGER
|
||||
#ifdef WANT_DEBUGGER
|
||||
MDFNDBG_Init();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return(1);
|
||||
return(1);
|
||||
}
|
||||
|
||||
void MDFNI_Kill(void)
|
||||
{
|
||||
MDFN_SaveSettings(settings_file_path.c_str());
|
||||
MDFN_KillSettings();
|
||||
/* save settings */
|
||||
}
|
||||
|
||||
#if defined(WANT_LYNX_EMU) || defined(WANT_NES_EMU)
|
||||
|
@ -25,557 +25,43 @@
|
||||
#include <list>
|
||||
#include "settings.h"
|
||||
#include "md5.h"
|
||||
#include "string/world_strtod.h"
|
||||
#include "string/escape.h"
|
||||
#include "FileStream.h"
|
||||
#include "MemoryStream.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char *name;
|
||||
char *value;
|
||||
} UnknownSetting_t;
|
||||
|
||||
std::multimap <uint32, MDFNCS> CurrentSettings;
|
||||
std::vector<UnknownSetting_t> UnknownSettings;
|
||||
|
||||
static std::string fname; // TODO: remove
|
||||
|
||||
static MDFNCS *FindSetting(const char *name, bool deref_alias = true, bool dont_freak_out_on_fail = false);
|
||||
|
||||
|
||||
static bool TranslateSettingValueUI(const char *value, unsigned long long &tlated_value)
|
||||
{
|
||||
char *endptr = NULL;
|
||||
|
||||
if(value[0] == '0' && (value[1] == 'x' || value[1] == 'X'))
|
||||
tlated_value = strtoull(value + 2, &endptr, 16);
|
||||
else
|
||||
tlated_value = strtoull(value, &endptr, 10);
|
||||
|
||||
if(!endptr || *endptr != 0)
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
return(true);
|
||||
}
|
||||
|
||||
static bool TranslateSettingValueI(const char *value, long long &tlated_value)
|
||||
{
|
||||
char *endptr = NULL;
|
||||
|
||||
if(value[0] == '0' && (value[1] == 'x' || value[1] == 'X'))
|
||||
tlated_value = strtoll(value + 2, &endptr, 16);
|
||||
else
|
||||
tlated_value = strtoll(value, &endptr, 10);
|
||||
|
||||
if(!endptr || *endptr != 0)
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
return(true);
|
||||
}
|
||||
|
||||
|
||||
static void ValidateSetting(const char *value, const MDFNSetting *setting)
|
||||
{
|
||||
MDFNSettingType base_type = setting->type;
|
||||
|
||||
if(base_type == MDFNST_UINT)
|
||||
{
|
||||
unsigned long long ullvalue;
|
||||
|
||||
if(!TranslateSettingValueUI(value, ullvalue))
|
||||
{
|
||||
throw MDFN_Error(0, _("Setting \"%s\", value \"%s\", is not set to a valid unsigned integer."), setting->name, value);
|
||||
}
|
||||
if(setting->minimum)
|
||||
{
|
||||
unsigned long long minimum;
|
||||
|
||||
TranslateSettingValueUI(setting->minimum, minimum);
|
||||
if(ullvalue < minimum)
|
||||
{
|
||||
throw MDFN_Error(0, _("Setting \"%s\" is set too small(\"%s\"); the minimum acceptable value is \"%s\"."), setting->name, value, setting->minimum);
|
||||
}
|
||||
}
|
||||
if(setting->maximum)
|
||||
{
|
||||
unsigned long long maximum;
|
||||
|
||||
TranslateSettingValueUI(setting->maximum, maximum);
|
||||
if(ullvalue > maximum)
|
||||
{
|
||||
throw MDFN_Error(0, _("Setting \"%s\" is set too large(\"%s\"); the maximum acceptable value is \"%s\"."), setting->name, value, setting->maximum);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(base_type == MDFNST_INT)
|
||||
{
|
||||
long long llvalue;
|
||||
|
||||
if(!TranslateSettingValueI(value, llvalue))
|
||||
{
|
||||
throw MDFN_Error(0, _("Setting \"%s\", value \"%s\", is not set to a valid signed integer."), setting->name, value);
|
||||
}
|
||||
if(setting->minimum)
|
||||
{
|
||||
long long minimum;
|
||||
|
||||
TranslateSettingValueI(setting->minimum, minimum);
|
||||
if(llvalue < minimum)
|
||||
{
|
||||
throw MDFN_Error(0, _("Setting \"%s\" is set too small(\"%s\"); the minimum acceptable value is \"%s\"."), setting->name, value, setting->minimum);
|
||||
}
|
||||
}
|
||||
if(setting->maximum)
|
||||
{
|
||||
long long maximum;
|
||||
|
||||
TranslateSettingValueI(setting->maximum, maximum);
|
||||
if(llvalue > maximum)
|
||||
{
|
||||
throw MDFN_Error(0, _("Setting \"%s\" is set too large(\"%s\"); the maximum acceptable value is \"%s\"."), setting->name, value, setting->maximum);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(base_type == MDFNST_FLOAT)
|
||||
{
|
||||
double dvalue;
|
||||
char *endptr = NULL;
|
||||
|
||||
dvalue = world_strtod(value, &endptr);
|
||||
|
||||
if(!endptr || *endptr != 0)
|
||||
{
|
||||
throw MDFN_Error(0, _("Setting \"%s\", value \"%s\", is not set to a floating-point(real) number."), setting->name, value);
|
||||
}
|
||||
if(setting->minimum)
|
||||
{
|
||||
double minimum;
|
||||
|
||||
minimum = world_strtod(setting->minimum, NULL);
|
||||
if(dvalue < minimum)
|
||||
{
|
||||
throw MDFN_Error(0, _("Setting \"%s\" is set too small(\"%s\"); the minimum acceptable value is \"%s\"."), setting->name, value, setting->minimum);
|
||||
}
|
||||
}
|
||||
if(setting->maximum)
|
||||
{
|
||||
double maximum;
|
||||
|
||||
maximum = world_strtod(setting->maximum, NULL);
|
||||
if(dvalue > maximum)
|
||||
{
|
||||
throw MDFN_Error(0, _("Setting \"%s\" is set too large(\"%s\"); the maximum acceptable value is \"%s\"."), setting->name, value, setting->maximum);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(base_type == MDFNST_BOOL)
|
||||
{
|
||||
if(strlen(value) != 1 || (value[0] != '0' && value[0] != '1'))
|
||||
{
|
||||
throw MDFN_Error(0, _("Setting \"%s\", value \"%s\", is not a valid boolean value."), setting->name, value);
|
||||
}
|
||||
}
|
||||
else if(base_type == MDFNST_ENUM)
|
||||
{
|
||||
const MDFNSetting_EnumList *enum_list = setting->enum_list;
|
||||
bool found = false;
|
||||
std::string valid_string_list;
|
||||
|
||||
assert(enum_list);
|
||||
|
||||
while(enum_list->string)
|
||||
{
|
||||
if(!strcasecmp(value, enum_list->string))
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if(enum_list->description) // Don't list out undocumented and deprecated values.
|
||||
valid_string_list = valid_string_list + (enum_list == setting->enum_list ? "" : " ") + std::string(enum_list->string);
|
||||
|
||||
enum_list++;
|
||||
}
|
||||
|
||||
if(!found)
|
||||
{
|
||||
throw MDFN_Error(0, _("Setting \"%s\", value \"%s\", is not a recognized string. Recognized strings: %s"), setting->name, value, valid_string_list.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(setting->validate_func && !setting->validate_func(setting->name, value))
|
||||
{
|
||||
if(base_type == MDFNST_STRING)
|
||||
throw MDFN_Error(0, _("Setting \"%s\" is not set to a valid string: \"%s\""), setting->name, value);
|
||||
else
|
||||
throw MDFN_Error(0, _("Setting \"%s\" is not set to a valid unsigned integer: \"%s\""), setting->name, value);
|
||||
}
|
||||
}
|
||||
|
||||
static uint32 MakeNameHash(const char *name)
|
||||
{
|
||||
uint32 name_hash;
|
||||
|
||||
name_hash = crc32(0, (const Bytef *)name, strlen(name));
|
||||
|
||||
return(name_hash);
|
||||
}
|
||||
|
||||
static void ParseSettingLine(std::string &linebuf, bool IsOverrideSetting = false)
|
||||
{
|
||||
MDFNCS *zesetting;
|
||||
size_t spacepos = linebuf.find(' ');
|
||||
|
||||
// EOF or bad line
|
||||
if(spacepos == std::string::npos)
|
||||
return;
|
||||
|
||||
// No name(key)
|
||||
if(spacepos == 0)
|
||||
return;
|
||||
|
||||
// No value
|
||||
if((spacepos + 1) == linebuf.size())
|
||||
return;
|
||||
|
||||
// Comment
|
||||
if(linebuf[0] == ';')
|
||||
return;
|
||||
|
||||
linebuf[spacepos] = 0;
|
||||
zesetting = FindSetting(linebuf.c_str(), true, true);
|
||||
|
||||
if(zesetting)
|
||||
{
|
||||
char *nv = strdup(linebuf.c_str() + spacepos + 1);
|
||||
|
||||
if(IsOverrideSetting)
|
||||
{
|
||||
if(zesetting->game_override)
|
||||
free(zesetting->game_override);
|
||||
|
||||
zesetting->game_override = nv;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(zesetting->value)
|
||||
free(zesetting->value);
|
||||
|
||||
zesetting->value = nv;
|
||||
}
|
||||
|
||||
ValidateSetting(nv, zesetting->desc); // TODO: Validate later(so command line options can override invalid setting file data correctly)
|
||||
}
|
||||
else if(!IsOverrideSetting)
|
||||
{
|
||||
UnknownSetting_t unks;
|
||||
|
||||
unks.name = strdup(linebuf.c_str());
|
||||
unks.value = strdup(linebuf.c_str() + spacepos + 1);
|
||||
|
||||
UnknownSettings.push_back(unks);
|
||||
}
|
||||
}
|
||||
|
||||
static void LoadSettings(Stream *fp, const char *section, bool override)
|
||||
{
|
||||
bool InCorrectSection = true; // To also allow for all-game overrides at the start of the override file, might be useful in certain scenarios.
|
||||
std::string linebuf;
|
||||
|
||||
linebuf.reserve(1024);
|
||||
|
||||
while(fp->get_line(linebuf) != -1)
|
||||
{
|
||||
if(linebuf[0] == '[')
|
||||
{
|
||||
if(section)
|
||||
{
|
||||
if(!strcasecmp(linebuf.c_str() + 1, section) && linebuf[1 + strlen(section)] == ']')
|
||||
InCorrectSection = true;
|
||||
else
|
||||
InCorrectSection = false;
|
||||
}
|
||||
}
|
||||
else if(InCorrectSection)
|
||||
{
|
||||
ParseSettingLine(linebuf, override);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool MDFN_LoadSettings(const char *path, const char *section, bool override)
|
||||
{
|
||||
MDFN_printf(_("Loading settings from \"%s\"..."), path);
|
||||
|
||||
try
|
||||
{
|
||||
MemoryStream mp(new FileStream(path, FileStream::MODE_READ));
|
||||
LoadSettings(&mp, section, override);
|
||||
}
|
||||
catch(MDFN_Error &e)
|
||||
{
|
||||
if(e.GetErrno() == ENOENT)
|
||||
{
|
||||
MDFN_indent(1);
|
||||
MDFN_printf(_("Failed: %s\n"), e.what());
|
||||
MDFN_indent(-1);
|
||||
return(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
MDFN_printf("\n");
|
||||
MDFN_PrintError(_("Failed to load settings from \"%s\": %s"), fname.c_str(), e.what());
|
||||
return(false);
|
||||
}
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
MDFN_printf("\n");
|
||||
MDFN_PrintError(_("Failed to load settings from \"%s\": %s"), fname.c_str(), e.what());
|
||||
return(false);
|
||||
}
|
||||
|
||||
MDFN_printf("\n");
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
static bool compare_sname(MDFNCS *first, MDFNCS *second)
|
||||
{
|
||||
return(strcmp(first->name, second->name) < 0);
|
||||
}
|
||||
|
||||
static void SaveSettings(Stream *fp)
|
||||
{
|
||||
std::multimap <uint32, MDFNCS>::iterator sit;
|
||||
std::list<MDFNCS *> SortedList;
|
||||
std::list<MDFNCS *>::iterator lit;
|
||||
|
||||
fp->printf(";VERSION %s\n", MEDNAFEN_VERSION);
|
||||
|
||||
fp->printf(_(";Edit this file at your own risk!\n"));
|
||||
fp->printf(_(";File format: <key><single space><value><LF or CR+LF>\n\n"));
|
||||
|
||||
for(sit = CurrentSettings.begin(); sit != CurrentSettings.end(); sit++)
|
||||
SortedList.push_back(&sit->second);
|
||||
|
||||
SortedList.sort(compare_sname);
|
||||
|
||||
for(lit = SortedList.begin(); lit != SortedList.end(); lit++)
|
||||
{
|
||||
if((*lit)->desc->type == MDFNST_ALIAS)
|
||||
continue;
|
||||
|
||||
fp->printf(";%s\n%s %s\n\n", _((*lit)->desc->description), (*lit)->name, (*lit)->value);
|
||||
}
|
||||
|
||||
if(UnknownSettings.size())
|
||||
{
|
||||
fp->printf("\n;\n;Unrecognized settings follow:\n;\n\n");
|
||||
for(unsigned int i = 0; i < UnknownSettings.size(); i++)
|
||||
{
|
||||
fp->printf("%s %s\n\n", UnknownSettings[i].name, UnknownSettings[i].value);
|
||||
}
|
||||
}
|
||||
|
||||
fp->close();
|
||||
}
|
||||
|
||||
bool MDFN_SaveSettings(const char *path)
|
||||
{
|
||||
try
|
||||
{
|
||||
FileStream fp(path, FileStream::MODE_WRITE);
|
||||
SaveSettings(&fp);
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
MDFND_PrintError(e.what());
|
||||
return(0);
|
||||
}
|
||||
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
||||
static INLINE void MergeSettingSub(const MDFNSetting *setting)
|
||||
{
|
||||
MDFNCS TempSetting;
|
||||
uint32 name_hash;
|
||||
|
||||
assert(setting->name);
|
||||
assert(setting->default_value);
|
||||
|
||||
if(FindSetting(setting->name, false, true) != NULL)
|
||||
return;
|
||||
|
||||
name_hash = MakeNameHash(setting->name);
|
||||
|
||||
TempSetting.name = strdup(setting->name);
|
||||
TempSetting.value = strdup(setting->default_value);
|
||||
TempSetting.name_hash = name_hash;
|
||||
TempSetting.desc = setting;
|
||||
TempSetting.ChangeNotification = setting->ChangeNotification;
|
||||
TempSetting.game_override = NULL;
|
||||
TempSetting.netplay_override = NULL;
|
||||
|
||||
CurrentSettings.insert(std::pair<uint32, MDFNCS>(name_hash, TempSetting)); //[name_hash] = TempSetting;
|
||||
}
|
||||
|
||||
|
||||
bool MDFN_MergeSettings(const MDFNSetting *setting)
|
||||
{
|
||||
while(setting->name != NULL)
|
||||
{
|
||||
MergeSettingSub(setting);
|
||||
setting++;
|
||||
}
|
||||
return(1);
|
||||
}
|
||||
|
||||
bool MDFN_MergeSettings(const std::vector<MDFNSetting> &setting)
|
||||
{
|
||||
for(unsigned int x = 0; x < setting.size(); x++)
|
||||
MergeSettingSub(&setting[x]);
|
||||
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
||||
void MDFN_KillSettings(void)
|
||||
{
|
||||
std::multimap <uint32, MDFNCS>::iterator sit;
|
||||
|
||||
for(sit = CurrentSettings.begin(); sit != CurrentSettings.end(); sit++)
|
||||
{
|
||||
if(sit->second.desc->type == MDFNST_ALIAS)
|
||||
continue;
|
||||
|
||||
free(sit->second.name);
|
||||
free(sit->second.value);
|
||||
}
|
||||
|
||||
if(UnknownSettings.size())
|
||||
{
|
||||
for(unsigned int i = 0; i < UnknownSettings.size(); i++)
|
||||
{
|
||||
free(UnknownSettings[i].name);
|
||||
free(UnknownSettings[i].value);
|
||||
}
|
||||
}
|
||||
CurrentSettings.clear(); // Call after the list is all handled
|
||||
UnknownSettings.clear();
|
||||
}
|
||||
|
||||
static MDFNCS *FindSetting(const char *name, bool dref_alias, bool dont_freak_out_on_fail)
|
||||
{
|
||||
MDFNCS *ret = NULL;
|
||||
uint32 name_hash;
|
||||
|
||||
//printf("Find: %s\n", name);
|
||||
|
||||
name_hash = MakeNameHash(name);
|
||||
|
||||
std::pair<std::multimap <uint32, MDFNCS>::iterator, std::multimap <uint32, MDFNCS>::iterator> sit_pair;
|
||||
std::multimap <uint32, MDFNCS>::iterator sit;
|
||||
|
||||
sit_pair = CurrentSettings.equal_range(name_hash);
|
||||
|
||||
for(sit = sit_pair.first; sit != sit_pair.second; sit++)
|
||||
{
|
||||
//printf("Found: %s\n", sit->second.name);
|
||||
if(!strcmp(sit->second.name, name))
|
||||
{
|
||||
if(dref_alias && sit->second.desc->type == MDFNST_ALIAS)
|
||||
return(FindSetting(sit->second.value, dref_alias, dont_freak_out_on_fail));
|
||||
|
||||
ret = &sit->second;
|
||||
}
|
||||
}
|
||||
|
||||
if(!ret && !dont_freak_out_on_fail)
|
||||
{
|
||||
printf("\n\nINCONCEIVABLE! Setting not found: %s\n\n", name);
|
||||
exit(1);
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
|
||||
static const char *GetSetting(const MDFNCS *setting)
|
||||
{
|
||||
const char *value;
|
||||
|
||||
if(setting->netplay_override)
|
||||
value = setting->netplay_override;
|
||||
else if(setting->game_override)
|
||||
value = setting->game_override;
|
||||
else
|
||||
value = setting->value;
|
||||
|
||||
return(value);
|
||||
}
|
||||
|
||||
static int GetEnum(const MDFNCS *setting, const char *value)
|
||||
{
|
||||
const MDFNSetting_EnumList *enum_list = setting->desc->enum_list;
|
||||
int ret = 0;
|
||||
bool found = false;
|
||||
|
||||
assert(enum_list);
|
||||
|
||||
while(enum_list->string)
|
||||
{
|
||||
if(!strcasecmp(value, enum_list->string))
|
||||
{
|
||||
found = true;
|
||||
ret = enum_list->number;
|
||||
break;
|
||||
}
|
||||
enum_list++;
|
||||
}
|
||||
|
||||
assert(found);
|
||||
return(ret);
|
||||
}
|
||||
|
||||
uint64 MDFN_GetSettingUI(const char *name)
|
||||
{
|
||||
const MDFNCS *setting = FindSetting(name);
|
||||
const char *value = GetSetting(setting);
|
||||
/* PSX */
|
||||
if(!strcmp("psx.spu.resamp_quality", name)) /* make configurable */
|
||||
return 4;
|
||||
|
||||
if(setting->desc->type == MDFNST_ENUM)
|
||||
return(GetEnum(setting, value));
|
||||
else
|
||||
{
|
||||
unsigned long long ret;
|
||||
TranslateSettingValueUI(value, ret);
|
||||
return(ret);
|
||||
}
|
||||
fprintf(stderr, "unhandled setting UI: %s\n", name);
|
||||
assert(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int64 MDFN_GetSettingI(const char *name)
|
||||
{
|
||||
const MDFNCS *setting = FindSetting(name);
|
||||
const char *value = GetSetting(FindSetting(name));
|
||||
/* PSX */
|
||||
if(!strcmp("psx.region_default", name)) /* make configurable */
|
||||
return 1; /* REGION_JP = 0, REGION_NA = 1, REGION_EU = 2 */
|
||||
|
||||
|
||||
if(setting->desc->type == MDFNST_ENUM)
|
||||
return(GetEnum(setting, value));
|
||||
else
|
||||
{
|
||||
long long ret;
|
||||
TranslateSettingValueI(value, ret);
|
||||
return(ret);
|
||||
}
|
||||
fprintf(stderr, "unhandled setting I: %s\n", name);
|
||||
assert(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
double MDFN_GetSettingF(const char *name)
|
||||
{
|
||||
return(world_strtod(GetSetting(FindSetting(name)), (char **)NULL));
|
||||
/* PSX */
|
||||
if(!strcmp("psx.input.mouse_sensitivity", name)) /* make configurable */
|
||||
return 1.00;
|
||||
|
||||
fprintf(stderr, "unhandled setting F: %s\n", name);
|
||||
assert(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool MDFN_GetSettingB(const char *name)
|
||||
@ -667,6 +153,8 @@ std::string MDFN_GetSettingS(const char *name)
|
||||
assert(0);
|
||||
return std::string(retro_base_directory) + std::string("scph5501.bin");
|
||||
}
|
||||
if(!strcmp("psx.region_default", name)) /* make configurable */
|
||||
return "na";
|
||||
/* FILESYS */
|
||||
if(!strcmp("filesys.path_firmware", name))
|
||||
{
|
||||
@ -708,182 +196,21 @@ std::string MDFN_GetSettingS(const char *name)
|
||||
return 0;
|
||||
}
|
||||
|
||||
const std::multimap <uint32, MDFNCS> *MDFNI_GetSettings(void)
|
||||
{
|
||||
return(&CurrentSettings);
|
||||
}
|
||||
|
||||
bool MDFNI_SetSetting(const char *name, const char *value, bool NetplayOverride)
|
||||
{
|
||||
MDFNCS *zesetting = FindSetting(name, true, true);
|
||||
|
||||
if(zesetting)
|
||||
{
|
||||
try
|
||||
{
|
||||
ValidateSetting(value, zesetting->desc);
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
MDFND_PrintError(e.what());
|
||||
return(0);
|
||||
}
|
||||
|
||||
// TODO: When NetplayOverride is set, make sure the setting is an emulation-related setting,
|
||||
// and that it is safe to change it(changing paths to BIOSes and such is not safe :b).
|
||||
if(NetplayOverride)
|
||||
{
|
||||
if(zesetting->netplay_override)
|
||||
free(zesetting->netplay_override);
|
||||
zesetting->netplay_override = strdup(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Overriding the per-game override. Poetic. Though not really.
|
||||
if(zesetting->game_override)
|
||||
{
|
||||
free(zesetting->game_override);
|
||||
zesetting->game_override = NULL;
|
||||
}
|
||||
|
||||
if(zesetting->value)
|
||||
free(zesetting->value);
|
||||
zesetting->value = strdup(value);
|
||||
}
|
||||
|
||||
// TODO, always call driver notification function, regardless of whether a game is loaded.
|
||||
if(zesetting->ChangeNotification)
|
||||
{
|
||||
if(MDFNGameInfo)
|
||||
zesetting->ChangeNotification(name);
|
||||
}
|
||||
return(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
MDFN_PrintError(_("Unknown setting \"%s\""), name);
|
||||
return(false);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool MDFNI_SetSettingB(const char *name, bool value)
|
||||
{
|
||||
char tmpstr[2];
|
||||
tmpstr[0] = value ? '1' : '0';
|
||||
tmpstr[1] = 0;
|
||||
|
||||
return(MDFNI_SetSetting(name, tmpstr, FALSE));
|
||||
return false;
|
||||
}
|
||||
|
||||
bool MDFNI_SetSettingUI(const char *name, uint64 value)
|
||||
{
|
||||
char tmpstr[32];
|
||||
|
||||
trio_snprintf(tmpstr, 32, "%llu", value);
|
||||
return(MDFNI_SetSetting(name, tmpstr, FALSE));
|
||||
return false;
|
||||
}
|
||||
|
||||
void MDFNI_DumpSettingsDef(const char *path)
|
||||
{
|
||||
FileStream fp(path, FileStream::MODE_WRITE);
|
||||
|
||||
std::multimap <uint32, MDFNCS>::iterator sit;
|
||||
std::list<MDFNCS *> SortedList;
|
||||
std::list<MDFNCS *>::iterator lit;
|
||||
std::map<int, const char *> tts;
|
||||
std::map<uint32, const char *>fts;
|
||||
|
||||
tts[MDFNST_INT] = "MDFNST_INT";
|
||||
tts[MDFNST_UINT] = "MDFNST_UINT";
|
||||
tts[MDFNST_BOOL] = "MDFNST_BOOL";
|
||||
tts[MDFNST_FLOAT] = "MDFNST_FLOAT";
|
||||
tts[MDFNST_STRING] = "MDFNST_STRING";
|
||||
tts[MDFNST_ENUM] = "MDFNST_ENUM";
|
||||
|
||||
fts[MDFNSF_CAT_INPUT] = "MDFNSF_CAT_INPUT";
|
||||
fts[MDFNSF_CAT_SOUND] = "MDFNSF_CAT_SOUND";
|
||||
fts[MDFNSF_CAT_VIDEO] = "MDFNSF_CAT_VIDEO";
|
||||
|
||||
fts[MDFNSF_EMU_STATE] = "MDFNSF_EMU_STATE";
|
||||
fts[MDFNSF_UNTRUSTED_SAFE] = "MDFNSF_UNTRUSTED_SAFE";
|
||||
|
||||
fts[MDFNSF_SUPPRESS_DOC] = "MDFNSF_SUPPRESS_DOC";
|
||||
fts[MDFNSF_COMMON_TEMPLATE] = "MDFNSF_COMMON_TEMPLATE";
|
||||
|
||||
fts[MDFNSF_REQUIRES_RELOAD] = "MDFNSF_REQUIRES_RELOAD";
|
||||
fts[MDFNSF_REQUIRES_RESTART] = "MDFNSF_REQUIRES_RESTART";
|
||||
|
||||
|
||||
for(sit = CurrentSettings.begin(); sit != CurrentSettings.end(); sit++)
|
||||
SortedList.push_back(&sit->second);
|
||||
|
||||
SortedList.sort(compare_sname);
|
||||
|
||||
for(lit = SortedList.begin(); lit != SortedList.end(); lit++)
|
||||
{
|
||||
const MDFNSetting *setting = (*lit)->desc;
|
||||
char *desc_escaped;
|
||||
char *desc_extra_escaped;
|
||||
|
||||
if(setting->type == MDFNST_ALIAS)
|
||||
continue;
|
||||
|
||||
fp.printf("%s\n", setting->name);
|
||||
|
||||
for(unsigned int i = 0; i < 32; i++)
|
||||
{
|
||||
if(setting->flags & (1 << i))
|
||||
fp.printf("%s ", fts[1 << i]);
|
||||
}
|
||||
fp.printf("\n");
|
||||
|
||||
desc_escaped = escape_string(setting->description ? setting->description : "");
|
||||
desc_extra_escaped = escape_string(setting->description_extra ? setting->description_extra : "");
|
||||
|
||||
|
||||
fp.printf("%s\n", desc_escaped);
|
||||
fp.printf("%s\n", desc_extra_escaped);
|
||||
|
||||
free(desc_escaped);
|
||||
free(desc_extra_escaped);
|
||||
|
||||
fp.printf("%s\n", tts[setting->type]);
|
||||
fp.printf("%s\n", setting->default_value ? setting->default_value : "");
|
||||
fp.printf("%s\n", setting->minimum ? setting->minimum : "");
|
||||
fp.printf("%s\n", setting->maximum ? setting->maximum : "");
|
||||
|
||||
if(!setting->enum_list)
|
||||
fp.printf("0\n");
|
||||
else
|
||||
{
|
||||
const MDFNSetting_EnumList *el = setting->enum_list;
|
||||
int count = 0;
|
||||
|
||||
while(el->string)
|
||||
{
|
||||
count++;
|
||||
el++;
|
||||
}
|
||||
|
||||
fp.printf("%d\n", count);
|
||||
|
||||
el = setting->enum_list;
|
||||
while(el->string)
|
||||
{
|
||||
desc_escaped = escape_string(el->description ? el->description : "");
|
||||
desc_extra_escaped = escape_string(el->description_extra ? el->description_extra : "");
|
||||
|
||||
fp.printf("%s\n", el->string);
|
||||
fp.printf("%s\n", desc_escaped);
|
||||
fp.printf("%s\n", desc_extra_escaped);
|
||||
|
||||
free(desc_escaped);
|
||||
free(desc_extra_escaped);
|
||||
|
||||
el++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fp.close();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user