GTK: Config code cleanup.

This commit is contained in:
Brandon Wright 2020-06-21 15:25:54 -05:00
parent 4c89a52e63
commit 0f0914cca5
5 changed files with 353 additions and 355 deletions

View File

@ -1,7 +1,7 @@
project('snes9x-gtk', project('snes9x-gtk',
['c', 'cpp'], ['c', 'cpp'],
version: '1.60', version: '1.60',
default_options: ['cpp_std=c++11']) default_options: ['cpp_std=c++14'])
args = ['-DSNES9X_GTK', '-DUNZIP_SUPPORT', '-DNETPLAY_SUPPORT', '-DJMA_SUPPORT', '-Wall', '-W', '-Wno-unused-parameter'] args = ['-DSNES9X_GTK', '-DUNZIP_SUPPORT', '-DNETPLAY_SUPPORT', '-DJMA_SUPPORT', '-Wall', '-W', '-Wno-unused-parameter']
srcs = [] srcs = []

View File

@ -227,6 +227,13 @@ Binding::Binding (const char *raw_string)
} }
} }
std::string Binding::as_string()
{
char buf[PATH_MAX];
to_string(buf, false);
return std::string(buf);
}
void void
Binding::to_string (char *str, bool translate) Binding::to_string (char *str, bool translate)
{ {

View File

@ -8,6 +8,7 @@
#define __GTK_BINDING_H #define __GTK_BINDING_H
#include "gtk_2_3_compat.h" #include "gtk_2_3_compat.h"
#include <string>
#define AXIS_POS 1 #define AXIS_POS 1
#define AXIS_NEG 0 #define AXIS_NEG 0
@ -44,6 +45,7 @@ class Binding
Binding (); Binding ();
Binding (const char *str); Binding (const char *str);
void to_string (char *str, bool translate = true); void to_string (char *str, bool translate = true);
std::string as_string();
unsigned int hex (); unsigned int hex ();
unsigned int base_hex (); unsigned int base_hex ();
void clear (); void clear ();

View File

@ -212,194 +212,185 @@ void Snes9xConfig::joystick_register_centers ()
void Snes9xConfig::flush_joysticks() void Snes9xConfig::flush_joysticks()
{ {
int i; for (int i = 0; joystick[i] != NULL; i++)
for (i = 0; joystick[i] != NULL; i++)
joystick[i]->flush(); joystick[i]->flush();
} }
void Snes9xConfig::set_joystick_mode(int mode) void Snes9xConfig::set_joystick_mode(int mode)
{ {
int i; for (int i = 0; joystick[i] != NULL; i++)
for (i = 0; joystick[i] != NULL; i++)
joystick[i]->mode = mode; joystick[i]->mode = mode;
} }
static inline void outbool (ConfigFile &cf, const char *key, bool value, const char *comment = "")
{
cf.SetBool (key, value, "true", "false", comment);
}
int Snes9xConfig::save_config_file() int Snes9xConfig::save_config_file()
{ {
char key[PATH_MAX];
char buffer[PATH_MAX];
ConfigFile cf; ConfigFile cf;
std::string section = "";
#undef z auto outbool = [&](std::string name, bool b, std::string comment = "") {
#define z "Display::" cf.SetBool((section + "::" + name).c_str(), b, "true", "false", comment.c_str());
outbool (cf, z"FullscreenOnOpen", full_screen_on_open,"Set the screen resolution after opening a ROM"); };
outbool (cf, z"ChangeDisplayResolution", change_display_resolution, "Set the resolution in fullscreen mode");
cf.SetInt (z"VideoMode", xrr_index, "Platform-specific video mode number");
outbool (cf, z"ScaleToFit", scale_to_fit, "Scale the image to fit the window size");
outbool (cf, z"MaintainAspectRatio", maintain_aspect_ratio, "Resize the screen to the proportions set by aspect ratio option");
cf.SetInt (z"AspectRatio", aspect_ratio, "0: uncorrected, 1: uncorrected integer scale, 2: 4:3, 3: 4/3 integer scale, 4: NTSC/PAL, 5: NTSC/PAL integer scale");
cf.SetInt (z"SoftwareScaleFilter", scale_method, "Build-specific number of filter used for software scaling");
cf.SetInt (z"ScanlineFilterIntensity", scanline_filter_intensity, "0: 0%, 1: 12.5%, 2: 25%, 3: 50%, 4: 100%");
outbool (cf, z"ShowOverscanArea", overscan);
cf.SetInt (z"HiresEffect", hires_effect, "0: Downscale to low-res, 1: Leave as-is, 2: Upscale low-res screens");
cf.SetInt (z"ForceInvertedByteOrder", force_inverted_byte_order);
outbool (cf, z"Multithreading", multithreading, "Apply filters using multiple threads");
cf.SetInt (z"NumberOfThreads", num_threads);
cf.SetInt (z"HardwareAcceleration", hw_accel, "0: None, 1: OpenGL, 2: XVideo");
outbool (cf, z"BilinearFilter", Settings.BilinearFilter, "Smoothes scaled image");
cf.SetInt (z"SplashBackground", splash_image, "0: Black, 1: Color bars, 2: Pattern, 3: Blue, 4: Default");
#undef z auto outstring = [&](std::string name, std::string str, std::string comment = "") {
#define z "NTSC::" cf.SetString((section + "::" + name).c_str(), str, comment.c_str());
cf.SetString (z"Hue", std::to_string (ntsc_setup.hue)); };
cf.SetString (z"Saturation", std::to_string (ntsc_setup.saturation));
cf.SetString (z"Contrast", std::to_string (ntsc_setup.contrast)); auto outint = [&](std::string name, int i, std::string comment = "") {
cf.SetString (z"Brightness", std::to_string (ntsc_setup.brightness)); cf.SetInt((section + "::" + name).c_str(), i, comment.c_str());
cf.SetString (z"Sharpness", std::to_string (ntsc_setup.sharpness)); };
cf.SetString (z"Artifacts", std::to_string (ntsc_setup.artifacts));
cf.SetString (z"Gamma", std::to_string (ntsc_setup.gamma)); section = "Display";
cf.SetString (z"Bleed", std::to_string (ntsc_setup.bleed)); outbool("FullscreenOnOpen", full_screen_on_open, "Set the screen resolution after opening a ROM");
cf.SetString (z"Fringing", std::to_string (ntsc_setup.fringing)); outbool("ChangeDisplayResolution", change_display_resolution, "Set the resolution in fullscreen mode");
cf.SetString (z"Resolution", std::to_string (ntsc_setup.resolution)); outbool("ScaleToFit", scale_to_fit, "Scale the image to fit the window size");
outbool (cf, z"MergeFields", ntsc_setup.merge_fields); outbool("ShowOverscanArea", overscan);
cf.SetInt (z"ScanlineIntensity", ntsc_scanline_intensity); outbool("MaintainAspectRatio", maintain_aspect_ratio, "Resize the screen to the proportions set by aspect ratio option");
outbool("Multithreading", multithreading, "Apply filters using multiple threads");
outbool("BilinearFilter", Settings.BilinearFilter, "Smoothes scaled image");
outbool("ForceInvertedByteOrder", force_inverted_byte_order);
outint("VideoMode", xrr_index, "Platform-specific video mode number");
outint("AspectRatio", aspect_ratio, "0: uncorrected, 1: uncorrected integer scale, 2: 4:3, 3: 4/3 integer scale, 4: NTSC/PAL, 5: NTSC/PAL integer scale");
outint("SoftwareScaleFilter", scale_method, "Build-specific number of filter used for software scaling");
outint("ScanlineFilterIntensity", scanline_filter_intensity, "0: 0%, 1: 12.5%, 2: 25%, 3: 50%, 4: 100%");
outint("HiresEffect", hires_effect, "0: Downscale to low-res, 1: Leave as-is, 2: Upscale low-res screens");
outint("NumberOfThreads", num_threads);
outint("HardwareAcceleration", hw_accel, "0: None, 1: OpenGL, 2: XVideo");
outint("SplashBackground", splash_image, "0: Black, 1: Color bars, 2: Pattern, 3: Blue, 4: Default");
section = "NTSC";
outstring("Hue", std::to_string(ntsc_setup.hue));
outstring("Saturation", std::to_string(ntsc_setup.saturation));
outstring("Contrast", std::to_string(ntsc_setup.contrast));
outstring("Brightness", std::to_string(ntsc_setup.brightness));
outstring("Sharpness", std::to_string(ntsc_setup.sharpness));
outstring("Artifacts", std::to_string(ntsc_setup.artifacts));
outstring("Gamma", std::to_string(ntsc_setup.gamma));
outstring("Bleed", std::to_string(ntsc_setup.bleed));
outstring("Fringing", std::to_string(ntsc_setup.fringing));
outstring("Resolution", std::to_string(ntsc_setup.resolution));
outbool("MergeFields", ntsc_setup.merge_fields);
outint("ScanlineIntensity", ntsc_scanline_intensity);
#ifdef USE_OPENGL #ifdef USE_OPENGL
#undef z section = "OpenGL";
#define z "OpenGL::" outbool("VSync", sync_to_vblank);
outbool (cf, z"VSync", sync_to_vblank); outbool("glFinish", use_glfinish);
outbool (cf, z"glFinish", use_glfinish); outbool("SyncControl", use_sync_control);
outbool (cf, z"SyncControl", use_sync_control); outbool("UseNonPowerOfTwoTextures", npot_textures);
outbool (cf, z"UsePixelBufferObjects", use_pbos); outbool("EnableCustomShaders", use_shaders);
cf.SetInt (z"PixelBufferObjectBitDepth", pbo_format); outbool("UsePixelBufferObjects", use_pbos);
outbool (cf, z"UseNonPowerOfTwoTextures", npot_textures); outint("PixelBufferObjectBitDepth", pbo_format);
outbool (cf, z"EnableCustomShaders", use_shaders); outstring("ShaderFile", shader_filename);
cf.SetString (z"ShaderFile", shader_filename);
#endif #endif
#undef z section = "Sound";
#define z "Sound::" outbool("MuteSound", mute_sound);
outbool (cf, z"MuteSound", mute_sound); outbool("MuteSoundDuringTurbo", mute_sound_turbo);
outbool (cf, z"MuteSoundDuringTurbo", mute_sound_turbo); outint("BufferSize", sound_buffer_size, "Buffer size in milliseconds");
cf.SetInt (z"BufferSize", sound_buffer_size, "Buffer size in milliseconds"); outint("Driver", sound_driver);
cf.SetInt (z"Driver", sound_driver); outint("InputRate", sound_input_rate);
cf.SetInt (z"InputRate", sound_input_rate); outbool("DynamicRateControl", Settings.DynamicRateControl);
outbool (cf, z"DynamicRateControl", Settings.DynamicRateControl); outint("DynamicRateControlLimit", Settings.DynamicRateLimit);
cf.SetInt (z"DynamicRateControlLimit", Settings.DynamicRateLimit); outbool("AutomaticInputRate", auto_input_rate, "Guess input rate by asking the monitor what its refresh rate is");
outbool (cf, z"AutomaticInputRate", auto_input_rate, "Guess input rate by asking the monitor what its refresh rate is"); outint("PlaybackRate", gui_config->sound_playback_rate, "1: 8000Hz, 2: 11025Hz, 3: 16000Hz, 4: 22050Hz, 5: 32000Hz, 6: 44100Hz, 7: 48000Hz");
cf.SetInt (z"PlaybackRate", gui_config->sound_playback_rate, "1: 8000Hz, 2: 11025Hz, 3: 16000Hz, 4: 22050Hz, 5: 32000Hz, 6: 44100Hz, 7: 48000Hz");
#undef z section = "Files";
#define z "Files::" outstring("LastDirectory", last_directory);
outstring("LastShaderDirectory", last_shader_directory);
outstring("SRAMDirectory", sram_directory);
outstring("SaveStateDirectory", savestate_directory);
outstring("CheatDirectory", cheat_directory);
outstring("PatchDirectory", patch_directory);
outstring("ExportDirectory", export_directory);
cf.SetString (z"LastDirectory", last_directory); section = "Window State";
cf.SetString (z"LastShaderDirectory", last_shader_directory); outint("MainWidth", window_width);
cf.SetString (z"SRAMDirectory", sram_directory); outint("MainHeight", window_height);
cf.SetString (z"SaveStateDirectory", savestate_directory); outint("PreferencesWidth", preferences_width);
cf.SetString (z"CheatDirectory", cheat_directory); outint("PreferencesHeight", preferences_height);
cf.SetString (z"PatchDirectory", patch_directory); outint("ShaderParametersWidth", shader_parameters_width);
cf.SetString (z"ExportDirectory", export_directory); outint("ShaderParametersHeight", shader_parameters_height);
outint("CurrentDisplayTab", current_display_tab);
#undef z outbool("UIVisible", ui_visible);
#define z "Window State::" outbool("EnableIcons", enable_icons);
cf.SetInt (z"MainWidth", window_width);
cf.SetInt (z"MainHeight", window_height);
cf.SetInt (z"PreferencesWidth", preferences_width);
cf.SetInt (z"PreferencesHeight", preferences_height);
cf.SetInt (z"ShaderParametersWidth", shader_parameters_width);
cf.SetInt (z"ShaderParametersHeight", shader_parameters_height);
cf.SetInt (z"CurrentDisplayTab", current_display_tab);
outbool (cf, z"UIVisible", ui_visible);
outbool (cf, z"EnableIcons", enable_icons);
if (default_esc_behavior != ESC_TOGGLE_MENUBAR) if (default_esc_behavior != ESC_TOGGLE_MENUBAR)
outbool (cf, z"Fullscreen", 0); outbool("Fullscreen", 0);
else else
outbool (cf, z"Fullscreen", fullscreen); outbool("Fullscreen", fullscreen);
#undef z section = "Netplay";
#define z "Netplay::" outbool("ActAsServer", netplay_is_server);
outbool (cf, z"ActAsServer", netplay_is_server); outbool("UseResetToSync", netplay_sync_reset);
outbool (cf, z"UseResetToSync", netplay_sync_reset); outbool("SendROM", netplay_send_rom);
outbool (cf, z"SendROM", netplay_send_rom); outint("DefaultPort", netplay_default_port);
cf.SetInt (z"DefaultPort", netplay_default_port); outint("MaxFrameLoss", netplay_max_frame_loss);
cf.SetInt (z"MaxFrameLoss", netplay_max_frame_loss); outint("LastUsedPort", netplay_last_port);
cf.SetInt (z"LastUsedPort", netplay_last_port); outstring("LastUsedROM", netplay_last_rom);
cf.SetString (z"LastUsedROM", netplay_last_rom); outstring("LastUsedHost", netplay_last_host);
cf.SetString (z"LastUsedHost", netplay_last_host);
#undef z section = "Behavior";
#define z "Behavior::" outbool("PauseEmulationWhenFocusLost", pause_emulation_on_switch);
outbool (cf, z"PauseEmulationWhenFocusLost", pause_emulation_on_switch); outint("DefaultESCKeyBehavior", default_esc_behavior);
cf.SetInt (z"DefaultESCKeyBehavior", default_esc_behavior); outbool("PreventScreensaver", prevent_screensaver);
outbool (cf, z"PreventScreensaver", prevent_screensaver); outbool("UseModalDialogs", modal_dialogs);
outbool (cf, z"UseModalDialogs", modal_dialogs); outint("RewindBufferSize", rewind_buffer_size, "Amount of memory (in MB) to use for rewinding");
cf.SetInt (z"RewindBufferSize", rewind_buffer_size, "Amount of memory (in MB) to use for rewinding"); outint("RewindGranularity", rewind_granularity, "Only save rewind snapshots every N frames");
cf.SetInt (z"RewindGranularity", rewind_granularity, "Only save rewind snapshots every N frames"); outint("CurrentSaveSlot", current_save_slot);
cf.SetInt (z"CurrentSaveSlot", current_save_slot);
#undef z section = "Emulation";
#define z "Emulation::" outbool("EmulateTransparency", Settings.Transparency);
outbool (cf, z"EmulateTransparency", Settings.Transparency); outbool("DisplayTime", Settings.DisplayTime);
outbool (cf, z"DisplayTime", Settings.DisplayTime); outbool("DisplayFrameRate", Settings.DisplayFrameRate);
outbool (cf, z"DisplayFrameRate", Settings.DisplayFrameRate); outbool("DisplayPressedKeys", Settings.DisplayPressedKeys);
outbool (cf, z"DisplayPressedKeys", Settings.DisplayPressedKeys); outint("SpeedControlMethod", Settings.SkipFrames, "0: Time the frames to 50 or 60Hz, 1: Same, but skip frames if too slow, 2: Synchronize to the sound buffer, 3: Unlimited, except potentially by vsync");
cf.SetInt (z"SpeedControlMethod", Settings.SkipFrames, "0: Time the frames to 50 or 60Hz, 1: Same, but skip frames if too slow, 2: Synchronize to the sound buffer, 3: Unlimited, except potentially by vsync"); outint("SaveSRAMEveryNSeconds", Settings.AutoSaveDelay);
cf.SetInt (z"SaveSRAMEveryNSeconds", Settings.AutoSaveDelay); outbool("BlockInvalidVRAMAccess", Settings.BlockInvalidVRAMAccessMaster);
outbool (cf, z"BlockInvalidVRAMAccess", Settings.BlockInvalidVRAMAccessMaster); outbool("AllowDPadContradictions", Settings.UpAndDown, "Allow the D-Pad to press both up + down at the same time, or left + right");
outbool (cf, z"AllowDPadContradictions", Settings.UpAndDown, "Allow the D-Pad to press both up + down at the same time, or left + right");
#undef z section = "Hacks";
#define z "Hacks::" outint("SuperFXClockMultiplier", Settings.SuperFXClockMultiplier);
cf.SetInt (z"SuperFXClockMultiplier", Settings.SuperFXClockMultiplier); outint("SoundInterpolationMethod", Settings.InterpolationMethod, "0: None, 1: Linear, 2: Gaussian (what the hardware uses), 3: Cubic, 4: Sinc");
cf.SetInt (z"SoundInterpolationMethod", Settings.InterpolationMethod, "0: None, 1: Linear, 2: Gaussian (what the hardware uses), 3: Cubic, 4: Sinc"); outbool("RemoveSpriteLimit", Settings.MaxSpriteTilesPerLine == 34 ? 0 : 1);
outbool (cf, z"RemoveSpriteLimit", Settings.MaxSpriteTilesPerLine == 34 ? 0 : 1); outbool("OverclockCPU", Settings.OneClockCycle == 6 ? 0 : 1);
outbool (cf, z"OverclockCPU", Settings.OneClockCycle == 6 ? 0 : 1); outbool("EchoBufferHack", Settings.SeparateEchoBuffer, "Prevents echo buffer from overwriting APU RAM");
outbool (cf, z"EchoBufferHack", Settings.SeparateEchoBuffer, "Prevents echo buffer from overwriting APU RAM");
#undef z section = "Input";
#define z "Input::"
controllers controller = CTL_NONE; controllers controller = CTL_NONE;
int8 id[4]; int8 id[4];
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
{ {
const char *output_string; std::string name;
snprintf (buffer, PATH_MAX, z"ControllerPort%d", i); std::string value;
name = "ControllerPort" + std::to_string(i);
S9xGetController(i, &controller, &id[0], &id[1], &id[2], &id[3]); S9xGetController(i, &controller, &id[0], &id[1], &id[2], &id[3]);
switch (controller) switch (controller)
{ {
case CTL_JOYPAD: case CTL_JOYPAD:
output_string = "joypad"; value = "joypad";
break; break;
case CTL_MOUSE: case CTL_MOUSE:
output_string = "mouse"; value = "mouse";
break; break;
case CTL_SUPERSCOPE: case CTL_SUPERSCOPE:
output_string = "superscope"; value = "superscope";
break; break;
case CTL_MP5: case CTL_MP5:
output_string = "multitap"; value = "multitap";
break; break;
case CTL_JUSTIFIER: case CTL_JUSTIFIER:
output_string = "justifier"; value = "justifier";
break; break;
default: default:
output_string = "none"; value = "none";
} }
cf.SetString (buffer, output_string); outstring(name, value);
} }
cf.SetInt (z"JoystickThreshold", joystick_threshold); outint("JoystickThreshold", joystick_threshold);
#undef z
for (int i = 0; i < NUM_JOYPADS; i++) for (int i = 0; i < NUM_JOYPADS; i++)
{ {
@ -407,17 +398,15 @@ int Snes9xConfig::save_config_file ()
for (int j = 0; j < NUM_JOYPAD_LINKS; j++) for (int j = 0; j < NUM_JOYPAD_LINKS; j++)
{ {
snprintf (key, PATH_MAX, "Joypad %d::%s", i, b_links[j].snes9x_name); section = "Joypad " + std::to_string(i);
joypad.data[j].to_string (buffer, false); outstring(b_links[j].snes9x_name, joypad.data[j].as_string());
cf.SetString (key, std::string (buffer));
} }
} }
section = "Shortcuts";
for (int i = NUM_JOYPAD_LINKS; b_links[i].snes9x_name; i++) for (int i = NUM_JOYPAD_LINKS; b_links[i].snes9x_name; i++)
{ {
snprintf (key, PATH_MAX, "Shortcuts::%s", b_links[i].snes9x_name); outstring(b_links[i].snes9x_name, shortcut[i - NUM_JOYPAD_LINKS].as_string());
shortcut[i - NUM_JOYPAD_LINKS].to_string (buffer, false);
cf.SetString (key, std::string (buffer));
} }
cf.SetNiceAlignment(true); cf.SetNiceAlignment(true);
@ -430,13 +419,11 @@ int Snes9xConfig::save_config_file ()
int Snes9xConfig::load_config_file() int Snes9xConfig::load_config_file()
{ {
struct stat file_info; struct stat file_info;
std::string path;
ConfigFile cf; ConfigFile cf;
char key[PATH_MAX];
load_defaults(); load_defaults();
path = get_config_dir (); std::string path = get_config_dir();
if (stat(path.c_str(), &file_info)) if (stat(path.c_str(), &file_info))
{ {
@ -465,179 +452,181 @@ int Snes9xConfig::load_config_file ()
return -1; return -1;
std::string none; std::string none;
#define inbool(key, var) { if (cf.Exists (key)) var = cf.GetBool (key); } std::string section;
#define inint(key, var) { if (cf.Exists(key)) var = cf.GetInt (key); }
#define infloat(key, var) { if (cf.Exists(key)) var = atof (cf.GetString (key, none).c_str()); }
#define instr(key, var) var = cf.GetString (key, none);
#undef z auto inbool = [&](std::string name, auto &b) {
#define z "Display::" if (cf.Exists((section + "::" + name).c_str()))
inbool (z"FullscreenOnOpen", full_screen_on_open); b = cf.GetBool((section + "::" + name).c_str());
inbool (z"ChangeDisplayResolution", change_display_resolution); };
inint (z"VideoMode", xrr_index);
inbool (z"ScaleToFit", scale_to_fit);
inbool (z"MaintainAspectRatio", maintain_aspect_ratio);
inint (z"AspectRatio", aspect_ratio);
inint (z"SoftwareScaleFilter", scale_method);
inint (z"ScanlineFilterIntensity", scanline_filter_intensity);
inbool (z"ShowOverscanArea", overscan);
inint (z"HiresEffect", hires_effect);
inint (z"ForceInvertedByteOrder", force_inverted_byte_order);
inbool (z"Multithreading", multithreading);
inint (z"NumberOfThreads", num_threads);
inint (z"HardwareAcceleration", hw_accel);
inbool (z"BilinearFilter", Settings.BilinearFilter);
inint (z"SplashBackground", splash_image);
#undef z auto inint = [&](std::string name, auto &i) {
#define z "NTSC::" if (cf.Exists((section + "::" + name).c_str()))
infloat (z"Hue", ntsc_setup.hue); i = cf.GetInt((section + "::" + name).c_str());
infloat (z"Saturation", ntsc_setup.saturation); };
infloat (z"Contrast", ntsc_setup.contrast);
infloat (z"Brightness", ntsc_setup.brightness); auto indouble = [&](std::string name, double &d) {
infloat (z"Sharpness", ntsc_setup.sharpness); if (cf.Exists((section + "::" + name).c_str()))
infloat (z"Artifacts", ntsc_setup.artifacts); d = atof(cf.GetString((section + "::" + name).c_str()));
infloat (z"Gamma", ntsc_setup.gamma); };
infloat (z"Bleed", ntsc_setup.bleed);
infloat (z"Fringing", ntsc_setup.fringing); auto instr = [&](std::string name, std::string &str) {
infloat (z"Resolution", ntsc_setup.resolution); str = cf.GetString((section + "::" + name).c_str(), none);
inbool (z"MergeFields", ntsc_setup.merge_fields); };
inint (z"ScanlineIntensity", ntsc_scanline_intensity);
section = "Display";
inbool("FullscreenOnOpen", full_screen_on_open);
inbool("ChangeDisplayResolution", change_display_resolution);
inint("VideoMode", xrr_index);
inbool("ScaleToFit", scale_to_fit);
inbool("MaintainAspectRatio", maintain_aspect_ratio);
inint("AspectRatio", aspect_ratio);
inint("SoftwareScaleFilter", scale_method);
inint("ScanlineFilterIntensity", scanline_filter_intensity);
inbool("ShowOverscanArea", overscan);
inint("HiresEffect", hires_effect);
inbool("ForceInvertedByteOrder", force_inverted_byte_order);
inbool("Multithreading", multithreading);
inint("NumberOfThreads", num_threads);
inint("HardwareAcceleration", hw_accel);
inbool("BilinearFilter", Settings.BilinearFilter);
inint("SplashBackground", splash_image);
section = "NTSC";
indouble("Hue", ntsc_setup.hue);
indouble("Saturation", ntsc_setup.saturation);
indouble("Contrast", ntsc_setup.contrast);
indouble("Brightness", ntsc_setup.brightness);
indouble("Sharpness", ntsc_setup.sharpness);
indouble("Artifacts", ntsc_setup.artifacts);
indouble("Gamma", ntsc_setup.gamma);
indouble("Bleed", ntsc_setup.bleed);
indouble("Fringing", ntsc_setup.fringing);
indouble("Resolution", ntsc_setup.resolution);
inbool("MergeFields", ntsc_setup.merge_fields);
inint("ScanlineIntensity", ntsc_scanline_intensity);
#ifdef USE_OPENGL #ifdef USE_OPENGL
#undef z section = "OpenGL";
#define z "OpenGL::" inbool("VSync", sync_to_vblank);
inbool (z"VSync", sync_to_vblank); inbool("glFinish", use_glfinish);
inbool (z"glFinish", use_glfinish); inbool("SyncControl", use_sync_control);
inbool (z"SyncControl", use_sync_control); inbool("UsePixelBufferObjects", use_pbos);
inbool (z"UsePixelBufferObjects", use_pbos); inint("PixelBufferObjectBitDepth", pbo_format);
inint (z"PixelBufferObjectBitDepth", pbo_format); inbool("UseNonPowerOfTwoTextures", npot_textures);
inbool (z"UseNonPowerOfTwoTextures", npot_textures); inbool("EnableCustomShaders", use_shaders);
inbool (z"EnableCustomShaders", use_shaders); instr("ShaderFile", shader_filename);
instr (z"ShaderFile", shader_filename);
#endif #endif
#undef z section = "Sound";
#define z "Sound::" inbool("MuteSound", mute_sound);
inbool (z"MuteSound", mute_sound); inbool("MuteSoundDuringTurbo", mute_sound_turbo);
inbool (z"MuteSoundDuringTurbo", mute_sound_turbo); inint("BufferSize", sound_buffer_size);
inint (z"BufferSize", sound_buffer_size); inint("Driver", sound_driver);
inint (z"Driver", sound_driver); inint("InputRate", sound_input_rate);
inint (z"InputRate", sound_input_rate); inbool("DynamicRateControl", Settings.DynamicRateControl);
inbool (z"DynamicRateControl", Settings.DynamicRateControl); inint("DynamicRateControlLimit", Settings.DynamicRateLimit);
inint (z"DynamicRateControlLimit", Settings.DynamicRateLimit); inbool("AutomaticInputRate", auto_input_rate);
inbool (z"AutomaticInputRate", auto_input_rate); inint("PlaybackRate", gui_config->sound_playback_rate);
inint (z"PlaybackRate", gui_config->sound_playback_rate);
#undef z section = "Files";
#define z "Files::" instr("LastDirectory", last_directory);
instr (z"LastDirectory", last_directory); instr("LastShaderDirectory", last_shader_directory);
instr (z"LastShaderDirectory", last_shader_directory); instr("SRAMDirectory", sram_directory);
instr (z"SRAMDirectory", sram_directory); instr("SaveStateDirectory", savestate_directory);
instr (z"SaveStateDirectory", savestate_directory); instr("CheatDirectory", cheat_directory);
instr (z"CheatDirectory", cheat_directory); instr("PatchDirectory", patch_directory);
instr (z"PatchDirectory", patch_directory); instr("ExportDirectory", export_directory);
instr (z"ExportDirectory", export_directory);
#undef z section = "Window State";
#define z "Window State::" inint("MainWidth", window_width);
inint("MainHeight", window_height);
inint("PreferencesWidth", preferences_width);
inint("PreferencesHeight", preferences_height);
inint("ShaderParametersWidth", shader_parameters_width);
inint("ShaderParametersHeight", shader_parameters_height);
inint("CurrentDisplayTab", current_display_tab);
inbool("UIVisible", ui_visible);
inbool("Fullscreen", fullscreen);
inbool("EnableIcons", enable_icons);
inint (z"MainWidth", window_width); section = "Netplay";
inint (z"MainHeight", window_height); inbool("ActAsServer", netplay_is_server);
inint (z"PreferencesWidth", preferences_width); inbool("UseResetToSync", netplay_sync_reset);
inint (z"PreferencesHeight", preferences_height); inbool("SendROM", netplay_send_rom);
inint (z"ShaderParametersWidth", shader_parameters_width); inint("DefaultPort", netplay_default_port);
inint (z"ShaderParametersHeight", shader_parameters_height); inint("MaxFrameLoss", netplay_max_frame_loss);
inint (z"CurrentDisplayTab", current_display_tab); inint("LastUsedPort", netplay_last_port);
inbool (z"UIVisible", ui_visible); instr("LastUsedROM", netplay_last_rom);
inbool (z"Fullscreen", fullscreen); instr("LastUsedHost", netplay_last_host);
inbool (z"EnableIcons", enable_icons);
#undef z section = "Behavior";
#define z "Netplay::" inbool("PauseEmulationWhenFocusLost", pause_emulation_on_switch);
inbool (z"ActAsServer", netplay_is_server); inint("DefaultESCKeyBehavior", default_esc_behavior);
inbool (z"UseResetToSync", netplay_sync_reset); inbool("PreventScreensaver", prevent_screensaver);
inbool (z"SendROM", netplay_send_rom); inbool("UseModalDialogs", modal_dialogs);
inint (z"DefaultPort", netplay_default_port); inint("RewindBufferSize", rewind_buffer_size);
inint (z"MaxFrameLoss", netplay_max_frame_loss); inint("RewindGranularity", rewind_granularity);
inint (z"LastUsedPort", netplay_last_port); inint("CurrentSaveSlot", current_save_slot);
instr (z"LastUsedROM", netplay_last_rom);
instr (z"LastUsedHost", netplay_last_host);
#undef z section = "Emulation";
#define z "Behavior::" inbool("EmulateTransparency", Settings.Transparency);
inbool (z"PauseEmulationWhenFocusLost", pause_emulation_on_switch); inbool("DisplayTime", Settings.DisplayTime);
inint (z"DefaultESCKeyBehavior", default_esc_behavior); inbool("DisplayFrameRate", Settings.DisplayFrameRate);
inbool (z"PreventScreensaver", prevent_screensaver); inbool("DisplayPressedKeys", Settings.DisplayPressedKeys);
inbool (z"UseModalDialogs", modal_dialogs); inint("SpeedControlMethod", Settings.SkipFrames);
inint (z"RewindBufferSize", rewind_buffer_size); inint("SaveSRAMEveryNSeconds", Settings.AutoSaveDelay);
inint (z"RewindGranularity", rewind_granularity); inbool("BlockInvalidVRAMAccess", Settings.BlockInvalidVRAMAccessMaster);
inint (z"CurrentSaveSlot", current_save_slot); inbool("AllowDPadContradictions", Settings.UpAndDown);
#undef z section = "Hacks";
#define z "Emulation::" inint("SuperFXClockMultiplier", Settings.SuperFXClockMultiplier);
inbool (z"EmulateTransparency", Settings.Transparency); inint("SoundInterpolationMethod", Settings.InterpolationMethod);
inbool (z"DisplayTime", Settings.DisplayTime);
inbool (z"DisplayFrameRate", Settings.DisplayFrameRate);
inbool (z"DisplayPressedKeys", Settings.DisplayPressedKeys);
inint (z"SpeedControlMethod", Settings.SkipFrames);
inint (z"SaveSRAMEveryNSeconds", Settings.AutoSaveDelay);
inbool (z"BlockInvalidVRAMAccess", Settings.BlockInvalidVRAMAccessMaster);
inbool (z"AllowDPadContradictions", Settings.UpAndDown);
#undef z
#define z "Hacks::"
inint (z"SuperFXClockMultiplier", Settings.SuperFXClockMultiplier);
inint (z"SoundInterpolationMethod", Settings.InterpolationMethod);
bool RemoveSpriteLimit = false; bool RemoveSpriteLimit = false;
inbool (z"RemoveSpriteLimit", RemoveSpriteLimit); inbool("RemoveSpriteLimit", RemoveSpriteLimit);
bool OverclockCPU = false; bool OverclockCPU = false;
inbool (z"OverclockCPU", OverclockCPU); inbool("OverclockCPU", OverclockCPU);
inbool (z"EchoBufferHack", Settings.SeparateEchoBuffer); inbool("EchoBufferHack", Settings.SeparateEchoBuffer);
#undef z section = "Input";
#define z "Input::"
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
{ {
snprintf (key, PATH_MAX, z"ControllerPort%d", i); std::string name = "ControllerPort" + std::to_string(i);
std::string tmp = cf.GetString (key, ""); std::string value;
instr(name, value);
if (tmp.find ("joypad") != std::string::npos) if (value.find("joypad") != std::string::npos)
S9xSetController(i, CTL_JOYPAD, i, 0, 0, 0); S9xSetController(i, CTL_JOYPAD, i, 0, 0, 0);
else if (tmp.find ("multitap") != std::string::npos) else if (value.find("multitap") != std::string::npos)
S9xSetController(i, CTL_MP5, i, i + 1, i + 2, i + 3); S9xSetController(i, CTL_MP5, i, i + 1, i + 2, i + 3);
else if (tmp.find ("superscope") != std::string::npos) else if (value.find("superscope") != std::string::npos)
S9xSetController(i, CTL_SUPERSCOPE, 0, 0, 0, 0); S9xSetController(i, CTL_SUPERSCOPE, 0, 0, 0, 0);
else if (tmp.find ("mouse") != std::string::npos) else if (value.find("mouse") != std::string::npos)
S9xSetController(i, CTL_MOUSE, i, 0, 0, 0); S9xSetController(i, CTL_MOUSE, i, 0, 0, 0);
else if (tmp.find ("none") != std::string::npos) else if (value.find("none") != std::string::npos)
S9xSetController(i, CTL_NONE, 0, 0, 0, 0); S9xSetController(i, CTL_NONE, 0, 0, 0, 0);
} }
inint (z"JoystickThreshold", joystick_threshold); inint("JoystickThreshold", joystick_threshold);
#undef z
std::string buffer; std::string buffer;
for (int i = 0; i < NUM_JOYPADS; i++) for (int i = 0; i < NUM_JOYPADS; i++)
{ {
auto &joypad = pad[i]; auto &joypad = pad[i];
section = "Joypad " + std::to_string(i);
for (int j = 0; j < NUM_JOYPAD_LINKS; j++) for (int j = 0; j < NUM_JOYPAD_LINKS; j++)
{ {
snprintf (key, PATH_MAX, "Joypad %d::%s", i, b_links[j].snes9x_name); instr(b_links[j].snes9x_name, buffer);
instr (key, buffer);
joypad.data[j] = Binding(buffer.c_str()); joypad.data[j] = Binding(buffer.c_str());
} }
} }
section = "Shortcuts";
for (int i = NUM_JOYPAD_LINKS; b_links[i].snes9x_name; i++) for (int i = NUM_JOYPAD_LINKS; b_links[i].snes9x_name; i++)
{ {
snprintf (key, PATH_MAX, "Shortcuts::%s", b_links[i].snes9x_name); instr(b_links[i].snes9x_name, buffer);
instr (key, buffer);
shortcut[i - NUM_JOYPAD_LINKS] = Binding(buffer.c_str()); shortcut[i - NUM_JOYPAD_LINKS] = Binding(buffer.c_str());
} }

View File

@ -140,28 +140,28 @@ S9xGetDirectory (enum s9x_getdirtype dirtype)
switch (dirtype) switch (dirtype)
{ {
case HOME_DIR: case HOME_DIR:
snprintf(path, PATH_MAX + 1, get_config_dir().c_str()); snprintf(path, PATH_MAX + 1, "%s", get_config_dir().c_str());
break; break;
case SNAPSHOT_DIR: case SNAPSHOT_DIR:
snprintf(path, PATH_MAX + 1, gui_config->savestate_directory.c_str()); snprintf(path, PATH_MAX + 1, "%s", gui_config->savestate_directory.c_str());
break; break;
case PATCH_DIR: case PATCH_DIR:
snprintf(path, PATH_MAX + 1, gui_config->patch_directory.c_str()); snprintf(path, PATH_MAX + 1, "%s", gui_config->patch_directory.c_str());
break; break;
case CHEAT_DIR: case CHEAT_DIR:
snprintf(path, PATH_MAX + 1, gui_config->cheat_directory.c_str()); snprintf(path, PATH_MAX + 1, "%s", gui_config->cheat_directory.c_str());
break; break;
case SRAM_DIR: case SRAM_DIR:
snprintf(path, PATH_MAX + 1, gui_config->sram_directory.c_str()); snprintf(path, PATH_MAX + 1, "%s", gui_config->sram_directory.c_str());
break; break;
case SCREENSHOT_DIR: case SCREENSHOT_DIR:
case SPC_DIR: case SPC_DIR:
snprintf(path, PATH_MAX + 1, gui_config->export_directory.c_str()); snprintf(path, PATH_MAX + 1, "%s", gui_config->export_directory.c_str());
break; break;
default: default:
@ -249,7 +249,7 @@ S9xBasenameNoExt (const char *f)
ext = strrchr (f, '.'); ext = strrchr (f, '.');
if (!ext) if (!ext)
snprintf (filename, PATH_MAX, base); snprintf (filename, PATH_MAX, "%s", base);
else else
{ {
int len = ext - base; int len = ext - base;
@ -288,7 +288,7 @@ S9xOpenSnapshotFile (const char *fname, bool8 read_only, STREAM *file)
if (*drive || *dir == '/' || (*dir == '.' && (*(dir + 1) == '/'))) if (*drive || *dir == '/' || (*dir == '.' && (*(dir + 1) == '/')))
{ {
snprintf (filename, PATH_MAX + 1, fname); snprintf (filename, PATH_MAX + 1, "%s", fname);
if (!file_exists (filename)) if (!file_exists (filename))
{ {