2010-12-29 18:00:21 +00:00
|
|
|
#include "general.h"
|
|
|
|
#include "conf/config_file.h"
|
2010-12-29 19:05:57 +00:00
|
|
|
#include "config.h.def"
|
2010-12-29 18:00:21 +00:00
|
|
|
#include <assert.h>
|
2010-12-29 18:18:37 +00:00
|
|
|
#include <string.h>
|
2010-12-30 00:38:20 +00:00
|
|
|
#include "hqflt/filters.h"
|
2010-12-29 18:00:21 +00:00
|
|
|
|
|
|
|
struct settings g_settings;
|
|
|
|
|
|
|
|
static void set_defaults(void)
|
|
|
|
{
|
2010-12-29 19:50:50 +00:00
|
|
|
const char *def_video = NULL;
|
|
|
|
const char *def_audio = NULL;
|
|
|
|
|
|
|
|
switch (VIDEO_DEFAULT_DRIVER)
|
|
|
|
{
|
|
|
|
case VIDEO_GL:
|
|
|
|
def_video = "glfw";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (AUDIO_DEFAULT_DRIVER)
|
|
|
|
{
|
|
|
|
case AUDIO_RSOUND:
|
|
|
|
def_audio = "rsound";
|
|
|
|
break;
|
|
|
|
case AUDIO_OSS:
|
|
|
|
def_audio = "oss";
|
|
|
|
break;
|
|
|
|
case AUDIO_ALSA:
|
|
|
|
def_audio = "alsa";
|
|
|
|
break;
|
|
|
|
case AUDIO_ROAR:
|
|
|
|
def_audio = "roar";
|
|
|
|
break;
|
|
|
|
case AUDIO_AL:
|
|
|
|
def_audio = "openal";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// No input atm ... It is in the GLFW driver.
|
|
|
|
|
|
|
|
if (def_video)
|
|
|
|
strncpy(g_settings.video.driver, def_video, sizeof(g_settings.video.driver) - 1);
|
|
|
|
if (def_audio)
|
|
|
|
strncpy(g_settings.audio.driver, def_audio, sizeof(g_settings.audio.driver) - 1);
|
|
|
|
|
2010-12-29 18:00:21 +00:00
|
|
|
g_settings.video.xscale = xscale;
|
|
|
|
g_settings.video.yscale = yscale;
|
2010-12-29 18:18:37 +00:00
|
|
|
g_settings.video.fullscreen = fullscreen;
|
2010-12-29 18:00:21 +00:00
|
|
|
g_settings.video.fullscreen_x = fullscreen_x;
|
|
|
|
g_settings.video.fullscreen_y = fullscreen_y;
|
|
|
|
g_settings.video.vsync = vsync;
|
2010-12-29 18:18:37 +00:00
|
|
|
g_settings.video.smooth = video_smooth;
|
2010-12-29 18:00:21 +00:00
|
|
|
g_settings.video.force_aspect = force_aspect;
|
|
|
|
|
|
|
|
g_settings.audio.enable = audio_enable;
|
|
|
|
g_settings.audio.out_rate = out_rate;
|
|
|
|
g_settings.audio.in_rate = in_rate;
|
|
|
|
if (audio_device)
|
|
|
|
strncpy(g_settings.audio.device, audio_device, sizeof(g_settings.audio.device));
|
|
|
|
g_settings.audio.latency = out_latency;
|
|
|
|
g_settings.audio.sync = audio_sync;
|
|
|
|
g_settings.audio.src_quality = SAMPLERATE_QUALITY;
|
|
|
|
|
|
|
|
assert(sizeof(g_settings.input.binds[0]) >= sizeof(snes_keybinds_1));
|
|
|
|
assert(sizeof(g_settings.input.binds[1]) >= sizeof(snes_keybinds_2));
|
|
|
|
memcpy(g_settings.input.binds[0], snes_keybinds_1, sizeof(snes_keybinds_1));
|
|
|
|
memcpy(g_settings.input.binds[1], snes_keybinds_2, sizeof(snes_keybinds_2));
|
2010-12-29 18:43:17 +00:00
|
|
|
|
|
|
|
g_settings.input.save_state_key = SAVE_STATE_KEY;
|
|
|
|
g_settings.input.load_state_key = LOAD_STATE_KEY;
|
|
|
|
g_settings.input.toggle_fullscreen_key = TOGGLE_FULLSCREEN;
|
2010-12-29 20:12:56 +00:00
|
|
|
g_settings.input.axis_threshold = AXIS_THRESHOLD;
|
2010-12-29 18:00:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void parse_config(void)
|
|
|
|
{
|
|
|
|
memset(&g_settings, 0, sizeof(struct settings));
|
|
|
|
config_file_t *conf = NULL;
|
|
|
|
|
2010-12-30 00:33:40 +00:00
|
|
|
if (strlen(g_extern.config_path) > 0)
|
2010-12-29 18:00:21 +00:00
|
|
|
{
|
2010-12-30 00:33:40 +00:00
|
|
|
conf = config_file_new(g_extern.config_path);
|
|
|
|
if (!conf)
|
|
|
|
{
|
|
|
|
SSNES_ERR("Couldn't find config at path: \"%s\"\n", g_extern.config_path);
|
|
|
|
exit(1);
|
|
|
|
}
|
2010-12-29 18:00:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-12-30 00:33:40 +00:00
|
|
|
const char *xdg = getenv("XDG_CONFIG_HOME");
|
2010-12-29 18:00:21 +00:00
|
|
|
const char *home = getenv("HOME");
|
2010-12-30 00:33:40 +00:00
|
|
|
if (xdg)
|
|
|
|
{
|
|
|
|
char conf_path[strlen(xdg) + strlen("/ssnes ")];
|
|
|
|
strcpy(conf_path, xdg);
|
|
|
|
strcat(conf_path, "/ssnes");
|
|
|
|
conf = config_file_new(conf_path);
|
|
|
|
}
|
|
|
|
else if (home)
|
2010-12-29 18:00:21 +00:00
|
|
|
{
|
|
|
|
char conf_path[strlen(home) + strlen("/.ssnesrc ")];
|
|
|
|
strcpy(conf_path, xdg);
|
|
|
|
strcat(conf_path, "/.ssnesrc");
|
|
|
|
conf = config_file_new(conf_path);
|
|
|
|
}
|
2010-12-30 00:33:40 +00:00
|
|
|
else // Try /etc/ssnes.conf as a final test ...
|
|
|
|
conf = config_file_new("/etc/ssnes.conf");
|
2010-12-29 18:00:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
set_defaults();
|
|
|
|
if (conf == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
int tmp_int;
|
|
|
|
double tmp_double;
|
|
|
|
bool tmp_bool;
|
|
|
|
char *tmp_str;
|
|
|
|
|
|
|
|
// Video settings.
|
|
|
|
if (config_get_double(conf, "video_xscale", &tmp_double))
|
|
|
|
g_settings.video.xscale = tmp_double;
|
|
|
|
|
|
|
|
if (config_get_double(conf, "video_yscale", &tmp_double))
|
|
|
|
g_settings.video.yscale = tmp_double;
|
|
|
|
|
|
|
|
if (config_get_int(conf, "video_fullscreen_x", &tmp_int))
|
|
|
|
g_settings.video.fullscreen_x = tmp_int;
|
|
|
|
|
|
|
|
if (config_get_int(conf, "video_fullscreen_y", &tmp_int))
|
|
|
|
g_settings.video.fullscreen_y = tmp_int;
|
|
|
|
|
|
|
|
if (config_get_bool(conf, "video_vsync", &tmp_bool))
|
|
|
|
g_settings.video.vsync = tmp_bool;
|
|
|
|
|
|
|
|
if (config_get_bool(conf, "video_smooth", &tmp_bool))
|
|
|
|
g_settings.video.smooth = tmp_bool;
|
|
|
|
|
|
|
|
if (config_get_bool(conf, "video_force_aspect", &tmp_bool))
|
|
|
|
g_settings.video.force_aspect = tmp_bool;
|
|
|
|
|
2010-12-30 00:33:40 +00:00
|
|
|
if (config_get_string(conf, "video_cg_shader", &tmp_str))
|
2010-12-29 18:00:21 +00:00
|
|
|
{
|
|
|
|
strncpy(g_settings.video.cg_shader_path, tmp_str, sizeof(g_settings.video.cg_shader_path) - 1);
|
|
|
|
free(tmp_str);
|
|
|
|
}
|
|
|
|
|
2010-12-30 00:33:40 +00:00
|
|
|
#ifdef HAVE_FILTER
|
|
|
|
if (config_get_string(conf, "video_filter", &tmp_str))
|
2010-12-29 18:00:21 +00:00
|
|
|
{
|
2010-12-30 00:33:40 +00:00
|
|
|
unsigned filter = 0;
|
|
|
|
if (strcasecmp(FILTER_HQ2X_STR, tmp_str) == 0)
|
|
|
|
filter = FILTER_HQ2X;
|
|
|
|
else if (strcasecmp(FILTER_HQ4X_STR, tmp_str) == 0)
|
|
|
|
filter = FILTER_HQ4X;
|
|
|
|
else if (strcasecmp(FILTER_GRAYSCALE_STR, tmp_str) == 0)
|
|
|
|
filter = FILTER_GRAYSCALE;
|
|
|
|
else if (strcasecmp(FILTER_BLEED_STR, tmp_str) == 0)
|
|
|
|
filter = FILTER_BLEED;
|
|
|
|
else if (strcasecmp(FILTER_NTSC_STR, tmp_str) == 0)
|
|
|
|
filter = FILTER_NTSC;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SSNES_ERR(
|
|
|
|
"Invalid filter... Valid filters are:\n"
|
|
|
|
"\t%s\n"
|
|
|
|
"\t%s\n"
|
|
|
|
"\t%s\n"
|
|
|
|
"\t%s\n"
|
|
|
|
"\t%s\n",
|
|
|
|
FILTER_HQ2X_STR, FILTER_HQ4X_STR, FILTER_GRAYSCALE_STR,
|
2010-12-30 00:38:20 +00:00
|
|
|
FILTER_BLEED_STR, FILTER_NTSC_STR);
|
2010-12-30 00:33:40 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2010-12-29 18:00:21 +00:00
|
|
|
free(tmp_str);
|
2010-12-30 00:38:20 +00:00
|
|
|
g_settings.video.filter = filter;
|
2010-12-29 18:00:21 +00:00
|
|
|
}
|
2010-12-30 00:33:40 +00:00
|
|
|
#endif
|
2010-12-29 18:00:21 +00:00
|
|
|
|
2010-12-29 20:12:56 +00:00
|
|
|
// Input Settings.
|
|
|
|
if (config_get_double(conf, "input_axis_threshold", &tmp_double))
|
|
|
|
g_settings.input.axis_threshold = tmp_double;
|
|
|
|
|
2010-12-29 18:00:21 +00:00
|
|
|
// Audio settings.
|
|
|
|
if (config_get_bool(conf, "audio_enable", &tmp_bool))
|
|
|
|
g_settings.audio.enable = tmp_bool;
|
|
|
|
|
|
|
|
if (config_get_int(conf, "audio_out_rate", &tmp_int))
|
|
|
|
g_settings.audio.out_rate = tmp_int;
|
|
|
|
|
|
|
|
if (config_get_int(conf, "audio_in_rate", &tmp_int))
|
|
|
|
g_settings.audio.in_rate = tmp_int;
|
|
|
|
|
|
|
|
if (config_get_string(conf, "audio_device", &tmp_str))
|
|
|
|
{
|
|
|
|
strncpy(g_settings.audio.device, tmp_str, sizeof(g_settings.audio.device) - 1);
|
|
|
|
free(tmp_str);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config_get_int(conf, "audio_latency", &tmp_int))
|
|
|
|
g_settings.audio.latency = tmp_int;
|
|
|
|
|
|
|
|
if (config_get_bool(conf, "audio_sync", &tmp_bool))
|
|
|
|
g_settings.audio.sync = tmp_bool;
|
|
|
|
|
|
|
|
if (config_get_int(conf, "audio_src_quality", &tmp_int))
|
|
|
|
{
|
2010-12-30 00:33:40 +00:00
|
|
|
int quals[] = { SRC_ZERO_ORDER_HOLD, SRC_LINEAR, SRC_SINC_FASTEST,
|
|
|
|
SRC_SINC_MEDIUM_QUALITY, SRC_SINC_BEST_QUALITY };
|
2010-12-29 18:00:21 +00:00
|
|
|
|
|
|
|
if (tmp_int > 0 && tmp_int < 6)
|
|
|
|
g_settings.audio.src_quality = quals[tmp_int];
|
|
|
|
}
|
|
|
|
|
2010-12-29 19:50:50 +00:00
|
|
|
if (config_get_string(conf, "video_driver", &tmp_str))
|
|
|
|
{
|
|
|
|
strncpy(g_settings.video.driver, tmp_str, sizeof(g_settings.video.driver) - 1);
|
|
|
|
free(tmp_str);
|
|
|
|
}
|
|
|
|
if (config_get_string(conf, "audio_driver", &tmp_str))
|
|
|
|
{
|
|
|
|
strncpy(g_settings.audio.driver, tmp_str, sizeof(g_settings.audio.driver) - 1);
|
|
|
|
free(tmp_str);
|
|
|
|
}
|
|
|
|
|
2010-12-29 20:12:56 +00:00
|
|
|
if (config_get_string(conf, "video_cg_shader_path", &tmp_str))
|
|
|
|
{
|
|
|
|
strncpy(g_settings.video.cg_shader_path, tmp_str, sizeof(g_settings.video.cg_shader_path) - 1);
|
|
|
|
free(tmp_str);
|
|
|
|
}
|
|
|
|
|
2010-12-29 18:00:21 +00:00
|
|
|
// TODO: Keybinds.
|
|
|
|
|
|
|
|
config_file_free(conf);
|
|
|
|
}
|