config: move some settings to a global config

This commit is contained in:
David Hrdlička
2025-05-03 01:45:21 +02:00
parent 4b55dc8cae
commit fac052a50f
3 changed files with 146 additions and 98 deletions

View File

@@ -160,7 +160,7 @@ int window_remember;
int vid_resize; /* (C) allow resizing */ int vid_resize; /* (C) allow resizing */
int invert_display = 0; /* (C) invert the display */ int invert_display = 0; /* (C) invert the display */
int suppress_overscan = 0; /* (C) suppress overscans */ int suppress_overscan = 0; /* (C) suppress overscans */
int lang_id = 0; /* (C) language id */ int lang_id = 0; /* (G) language id */
int scale = 0; /* (C) screen scale factor */ int scale = 0; /* (C) screen scale factor */
int dpi_scale = 0; /* (C) DPI scaling of the emulated int dpi_scale = 0; /* (C) DPI scaling of the emulated
screen */ screen */
@@ -168,7 +168,7 @@ int vid_api = 0; /* (C) video r
int vid_cga_contrast = 0; /* (C) video */ int vid_cga_contrast = 0; /* (C) video */
int video_fullscreen = 0; /* (C) video */ int video_fullscreen = 0; /* (C) video */
int video_fullscreen_scale = 0; /* (C) video */ int video_fullscreen_scale = 0; /* (C) video */
int video_fullscreen_first = 0; /* (C) video */ int video_fullscreen_first = 0; /* (G) video */
int enable_overscan = 0; /* (C) video */ int enable_overscan = 0; /* (C) video */
int force_43 = 0; /* (C) video */ int force_43 = 0; /* (C) video */
int video_filter_method = 1; /* (C) video */ int video_filter_method = 1; /* (C) video */
@@ -199,13 +199,13 @@ int cpu = 0; /* (C) cpu typ
int fpu_type = 0; /* (C) fpu type */ int fpu_type = 0; /* (C) fpu type */
int fpu_softfloat = 0; /* (C) fpu uses softfloat */ int fpu_softfloat = 0; /* (C) fpu uses softfloat */
int time_sync = 0; /* (C) enable time sync */ int time_sync = 0; /* (C) enable time sync */
int confirm_reset = 1; /* (C) enable reset confirmation */ int confirm_reset = 1; /* (G) enable reset confirmation */
int confirm_exit = 1; /* (C) enable exit confirmation */ int confirm_exit = 1; /* (G) enable exit confirmation */
int confirm_save = 1; /* (C) enable save confirmation */ int confirm_save = 1; /* (G) enable save confirmation */
int enable_discord = 0; /* (C) enable Discord integration */ int enable_discord = 0; /* (C) enable Discord integration */
int pit_mode = -1; /* (C) force setting PIT mode */ int pit_mode = -1; /* (C) force setting PIT mode */
int fm_driver = 0; /* (C) select FM sound driver */ int fm_driver = 0; /* (C) select FM sound driver */
int open_dir_usr_path = 0; /* (C) default file open dialog directory int open_dir_usr_path = 0; /* (G) default file open dialog directory
of usr_path */ of usr_path */
int video_fullscreen_scale_maximized = 0; /* (C) Whether fullscreen scaling settings int video_fullscreen_scale_maximized = 0; /* (C) Whether fullscreen scaling settings
also apply when maximized. */ also apply when maximized. */
@@ -215,7 +215,7 @@ int hook_enabled = 1; /* (C) Keyboar
int test_mode = 0; /* (C) Test mode */ int test_mode = 0; /* (C) Test mode */
char uuid[MAX_UUID_LEN] = { '\0' }; /* (C) UUID or machine identifier */ char uuid[MAX_UUID_LEN] = { '\0' }; /* (C) UUID or machine identifier */
int sound_muted = 0; /* (C) Is sound muted? */ int sound_muted = 0; /* (C) Is sound muted? */
int inhibit_multimedia_keys; /* (C) Inhibit multimedia keys on Windows. */ int inhibit_multimedia_keys; /* (G) Inhibit multimedia keys on Windows. */
int other_ide_present = 0; /* IDE controllers from non-IDE cards are int other_ide_present = 0; /* IDE controllers from non-IDE cards are
present */ present */
@@ -229,27 +229,27 @@ struct accelKey acc_keys[NUM_ACCELS];
struct accelKey def_acc_keys[NUM_ACCELS] = { struct accelKey def_acc_keys[NUM_ACCELS] = {
{ .name="send_ctrl_alt_del", .desc="Send Control+Alt+Del", { .name="send_ctrl_alt_del", .desc="Send Control+Alt+Del",
.seq="Ctrl+F12" }, .seq="Ctrl+F12" },
{ .name="send_ctrl_alt_esc", .desc="Send Control+Alt+Escape", { .name="send_ctrl_alt_esc", .desc="Send Control+Alt+Escape",
.seq="Ctrl+F10" }, .seq="Ctrl+F10" },
{ .name="fullscreen", .desc="Toggle fullscreen", { .name="fullscreen", .desc="Toggle fullscreen",
.seq="Ctrl+Alt+PgUp" }, .seq="Ctrl+Alt+PgUp" },
{ .name="screenshot", .desc="Screenshot", { .name="screenshot", .desc="Screenshot",
.seq="Ctrl+F11" }, .seq="Ctrl+F11" },
{ .name="release_mouse", .desc="Release mouse pointer", { .name="release_mouse", .desc="Release mouse pointer",
.seq="Ctrl+End" }, .seq="Ctrl+End" },
{ .name="hard_reset", .desc="Hard reset", { .name="hard_reset", .desc="Hard reset",
.seq="Ctrl+Alt+F12" }, .seq="Ctrl+Alt+F12" },
{ .name="pause", .desc="Toggle pause", { .name="pause", .desc="Toggle pause",
.seq="Ctrl+Alt+F1" }, .seq="Ctrl+Alt+F1" },
{ .name="mute", .desc="Toggle mute", { .name="mute", .desc="Toggle mute",
.seq="Ctrl+Alt+M" } .seq="Ctrl+Alt+M" }
}; };
@@ -271,6 +271,7 @@ extern double exp_pow_table[0x800];
char exe_path[2048]; /* path (dir) of executable */ char exe_path[2048]; /* path (dir) of executable */
char usr_path[1024]; /* path (dir) of user data */ char usr_path[1024]; /* path (dir) of user data */
char cfg_path[1024]; /* full path of config file */ char cfg_path[1024]; /* full path of config file */
char global_cfg_path[1024]; /* full path of config file */
FILE *stdlog = NULL; /* file to log output to */ FILE *stdlog = NULL; /* file to log output to */
#if 0 #if 0
int scrnsz_x = SCREEN_RES_X; /* current screen size, X */ int scrnsz_x = SCREEN_RES_X; /* current screen size, X */
@@ -308,7 +309,7 @@ static int suppr_seen = 1;
void pclog_ensure_stdlog_open(void); void pclog_ensure_stdlog_open(void);
#endif #endif
/* /*
Ensures STDLOG is open for pclog_ex and pclog_ex_cyclic Ensures STDLOG is open for pclog_ex and pclog_ex_cyclic
*/ */
void pclog_ensure_stdlog_open(void) void pclog_ensure_stdlog_open(void)
@@ -616,6 +617,7 @@ pc_show_usage(char *s)
"-M or --missing\t\t- dump missing machines and video cards\n" "-M or --missing\t\t- dump missing machines and video cards\n"
"-N or --noconfirm\t\t- do not ask for confirmation on quit\n" "-N or --noconfirm\t\t- do not ask for confirmation on quit\n"
"-P or --vmpath path\t\t- set 'path' to be root for vm\n" "-P or --vmpath path\t\t- set 'path' to be root for vm\n"
"-O or --global path\t\t- set 'path' to be global config file\n"
"-R or --rompath path\t\t- set 'path' to be ROM path\n" "-R or --rompath path\t\t- set 'path' to be ROM path\n"
#ifndef USE_SDL_UI #ifndef USE_SDL_UI
"-S or --settings\t\t\t- show only the settings dialog\n" "-S or --settings\t\t\t- show only the settings dialog\n"
@@ -655,6 +657,7 @@ pc_init(int argc, char *argv[])
char *ppath = NULL; char *ppath = NULL;
char *rpath = NULL; char *rpath = NULL;
char *cfg = NULL; char *cfg = NULL;
char *global = NULL;
char *p; char *p;
char temp[2048]; char temp[2048];
char *fn[FDD_NUM] = { NULL }; char *fn[FDD_NUM] = { NULL };
@@ -769,6 +772,11 @@ usage:
#ifdef DEPRECATE_USAGE #ifdef DEPRECATE_USAGE
deprecated = 0; deprecated = 0;
#endif #endif
} else if (!strcasecmp(argv[c], "--global") || !strcasecmp(argv[c], "-O")) {
if ((c + 1) == argc || plat_dir_check(argv[c + 1]))
goto usage;
global = argv[++c];
} else if (!strcasecmp(argv[c], "--image") || !strcasecmp(argv[c], "-I")) { } else if (!strcasecmp(argv[c], "--image") || !strcasecmp(argv[c], "-I")) {
if ((c + 1) == argc) if ((c + 1) == argc)
goto usage; goto usage;
@@ -996,6 +1004,14 @@ usage:
/* At this point, we can safely create the full path name. */ /* At this point, we can safely create the full path name. */
path_append_filename(cfg_path, usr_path, p); path_append_filename(cfg_path, usr_path, p);
/* Build the global configuration file path. */
if (global == NULL) {
plat_get_global_config_dir(global_cfg_path, sizeof(global_cfg_path));
path_append_filename(global_cfg_path, global_cfg_path, CONFIG_FILE);
} else {
strncpy(global_cfg_path, global, sizeof(global_cfg_path) - 1);
}
/* /*
* Get the current directory's name * Get the current directory's name
* *
@@ -1025,7 +1041,8 @@ usage:
pclog("# ROM path: %s\n", rom_path->path); pclog("# ROM path: %s\n", rom_path->path);
} }
pclog("# Configuration file: %s\n#\n\n", cfg_path); pclog("# Global configuration file: %s\n", global_cfg_path);
pclog("# VM configuration file: %s\n#\n\n", cfg_path);
/* /*
* We are about to read the configuration file, which MAY * We are about to read the configuration file, which MAY
* put data into global variables (the hard- and floppy * put data into global variables (the hard- and floppy

View File

@@ -88,6 +88,7 @@ static int cy;
static int cw; static int cw;
static int ch; static int ch;
static ini_t config; static ini_t config;
static ini_t global;
#ifdef ENABLE_CONFIG_LOG #ifdef ENABLE_CONFIG_LOG
int config_do_log = ENABLE_CONFIG_LOG; int config_do_log = ENABLE_CONFIG_LOG;
@@ -107,6 +108,35 @@ config_log(const char *fmt, ...)
# define config_log(fmt, ...) # define config_log(fmt, ...)
#endif #endif
/* Load global configuration */
static void
load_global(void)
{
ini_section_t cat = ini_find_section(global, "");
char *p;
p = ini_section_get_string(cat, "language", NULL);
if (p != NULL)
lang_id = plat_language_code(p);
else
lang_id = plat_language_code(DEFAULT_LANGUAGE);
open_dir_usr_path = ini_section_get_int(cat, "open_dir_usr_path", 0);
confirm_reset = ini_section_get_int(cat, "confirm_reset", 1);
confirm_exit = ini_section_get_int(cat, "confirm_exit", 1);
confirm_save = ini_section_get_int(cat, "confirm_save", 1);
video_fullscreen_first = ini_section_get_int(cat, "video_fullscreen_first", 1);
inhibit_multimedia_keys = ini_section_get_int(cat, "inhibit_multimedia_keys", 0);
mouse_sensitivity = ini_section_get_double(cat, "mouse_sensitivity", 1.0);
if (mouse_sensitivity < 0.1)
mouse_sensitivity = 0.1;
else if (mouse_sensitivity > 2.0)
mouse_sensitivity = 2.0;
}
/* Load "General" section. */ /* Load "General" section. */
static void static void
@@ -128,12 +158,8 @@ load_general(void)
video_fullscreen_scale = ini_section_get_int(cat, "video_fullscreen_scale", 1); video_fullscreen_scale = ini_section_get_int(cat, "video_fullscreen_scale", 1);
video_fullscreen_first = ini_section_get_int(cat, "video_fullscreen_first", 1);
video_filter_method = ini_section_get_int(cat, "video_filter_method", 1); video_filter_method = ini_section_get_int(cat, "video_filter_method", 1);
inhibit_multimedia_keys = ini_section_get_int(cat, "inhibit_multimedia_keys", 0);
force_43 = !!ini_section_get_int(cat, "force_43", 0); force_43 = !!ini_section_get_int(cat, "force_43", 0);
scale = ini_section_get_int(cat, "scale", 1); scale = ini_section_get_int(cat, "scale", 1);
if (scale > 9) if (scale > 9)
@@ -179,26 +205,8 @@ load_general(void)
hide_tool_bar = ini_section_get_int(cat, "hide_tool_bar", 0); hide_tool_bar = ini_section_get_int(cat, "hide_tool_bar", 0);
sound_muted = ini_section_get_int(cat, "sound_muted", 0); sound_muted = ini_section_get_int(cat, "sound_muted", 0);
confirm_reset = ini_section_get_int(cat, "confirm_reset", 1);
confirm_exit = ini_section_get_int(cat, "confirm_exit", 1);
confirm_save = ini_section_get_int(cat, "confirm_save", 1);
p = ini_section_get_string(cat, "language", NULL);
if (p != NULL)
lang_id = plat_language_code(p);
else
lang_id = plat_language_code(DEFAULT_LANGUAGE);
mouse_sensitivity = ini_section_get_double(cat, "mouse_sensitivity", 1.0);
if (mouse_sensitivity < 0.1)
mouse_sensitivity = 0.1;
else if (mouse_sensitivity > 2.0)
mouse_sensitivity = 2.0;
enable_discord = !!ini_section_get_int(cat, "enable_discord", 0); enable_discord = !!ini_section_get_int(cat, "enable_discord", 0);
open_dir_usr_path = ini_section_get_int(cat, "open_dir_usr_path", 0);
video_framerate = ini_section_get_int(cat, "video_gl_framerate", -1); video_framerate = ini_section_get_int(cat, "video_gl_framerate", -1);
video_vsync = ini_section_get_int(cat, "video_gl_vsync", 0); video_vsync = ini_section_get_int(cat, "video_gl_vsync", 0);
@@ -1800,7 +1808,21 @@ config_load(void)
int i; int i;
ini_section_t c; ini_section_t c;
config_log("Loading config file '%s'..\n", cfg_path); config_log("Loading global config file '%s'...\n", global_cfg_path);
global = ini_read(global_cfg_path);
if (global == NULL) {
global = ini_new();
lang_id = plat_language_code(DEFAULT_LANGUAGE);
config_log("Global config file not present or invalid!\n");
} else {
load_global();
}
config_log("Loading VM config file '%s'...\n", cfg_path);
memset(hdd, 0, sizeof(hard_disk_t)); memset(hdd, 0, sizeof(hard_disk_t));
memset(cdrom, 0, sizeof(cdrom_t) * CDROM_NUM); memset(cdrom, 0, sizeof(cdrom_t) * CDROM_NUM);
@@ -1812,8 +1834,7 @@ config_load(void)
config = ini_read(cfg_path); config = ini_read(cfg_path);
if (config == NULL) { if (config == NULL) {
config = ini_new(); config = ini_new();
config_changed = 1;
cpu_f = (cpu_family_t *) &cpu_families[0]; cpu_f = (cpu_family_t *) &cpu_families[0];
cpu = 0; cpu = 0;
@@ -1873,9 +1894,7 @@ config_load(void)
cassette_pcm = 0; cassette_pcm = 0;
cassette_ui_writeprot = 0; cassette_ui_writeprot = 0;
lang_id = plat_language_code(DEFAULT_LANGUAGE); config_log("VM config file not present or invalid!\n");
config_log("Config file not present or invalid!\n");
} else { } else {
load_general(); /* General */ load_general(); /* General */
for (i = 0; i < MONITORS_NUM; i++) for (i = 0; i < MONITORS_NUM; i++)
@@ -1913,29 +1932,74 @@ config_load(void)
if (c != NULL) if (c != NULL)
ini_rename_section(c, "3Dfx Voodoo Banshee"); ini_rename_section(c, "3Dfx Voodoo Banshee");
/* Mark the configuration as changed. */ config_log("VM config loaded.\n\n");
config_changed = 1;
config_log("Config loaded.\n\n");
} }
/* Mark the configuration as changed. */
config_changed = 1;
video_copy = (video_grayscale || invert_display) ? video_transform_copy : memcpy; video_copy = (video_grayscale || invert_display) ? video_transform_copy : memcpy;
} }
/* Save global configuration */
static void
save_global(void)
{
ini_section_t cat = ini_find_or_create_section(global, "");
char buffer[512] = { 0 };
if (lang_id == plat_language_code(DEFAULT_LANGUAGE))
ini_section_delete_var(cat, "language");
else {
plat_language_code_r(lang_id, buffer, 511);
ini_section_set_string(cat, "language", buffer);
}
if (open_dir_usr_path)
ini_section_set_int(cat, "open_dir_usr_path", open_dir_usr_path);
else
ini_section_delete_var(cat, "open_dir_usr_path");
if (confirm_reset != 1)
ini_section_set_int(cat, "confirm_reset", confirm_reset);
else
ini_section_delete_var(cat, "confirm_reset");
if (confirm_exit != 1)
ini_section_set_int(cat, "confirm_exit", confirm_exit);
else
ini_section_delete_var(cat, "confirm_exit");
if (confirm_save != 1)
ini_section_set_int(cat, "confirm_save", confirm_save);
else
ini_section_delete_var(cat, "confirm_save");
if (video_fullscreen_first == 1)
ini_section_delete_var(cat, "video_fullscreen_first");
else
ini_section_set_int(cat, "video_fullscreen_first", video_fullscreen_first);
if (inhibit_multimedia_keys == 1)
ini_section_set_int(cat, "inhibit_multimedia_keys", inhibit_multimedia_keys);
else
ini_section_delete_var(cat, "inhibit_multimedia_keys");
if (mouse_sensitivity != 1.0)
ini_section_set_double(cat, "mouse_sensitivity", mouse_sensitivity);
else
ini_section_delete_var(cat, "mouse_sensitivity");
}
/* Save "General" section. */ /* Save "General" section. */
static void static void
save_general(void) save_general(void)
{ {
ini_section_t cat = ini_find_or_create_section(config, "General"); ini_section_t cat = ini_find_or_create_section(config, "General");
char temp[512]; char temp[512];
char buffer[512] = { 0 };
const char *va_name; const char *va_name;
ini_section_set_int(cat, "inhibit_multimedia_keys", inhibit_multimedia_keys);
if (inhibit_multimedia_keys == 0)
ini_section_delete_var(cat, "inhibit_multimedia_keys");
ini_section_set_int(cat, "sound_muted", sound_muted); ini_section_set_int(cat, "sound_muted", sound_muted);
if (sound_muted == 0) if (sound_muted == 0)
ini_section_delete_var(cat, "sound_muted"); ini_section_delete_var(cat, "sound_muted");
@@ -1955,11 +2019,6 @@ save_general(void)
else else
ini_section_set_int(cat, "video_fullscreen_scale", video_fullscreen_scale); ini_section_set_int(cat, "video_fullscreen_scale", video_fullscreen_scale);
if (video_fullscreen_first == 1)
ini_section_delete_var(cat, "video_fullscreen_first");
else
ini_section_set_int(cat, "video_fullscreen_first", video_fullscreen_first);
if (video_filter_method == 1) if (video_filter_method == 1)
ini_section_delete_var(cat, "video_filter_method"); ini_section_delete_var(cat, "video_filter_method");
else else
@@ -2041,43 +2100,11 @@ save_general(void)
else else
ini_section_delete_var(cat, "hide_tool_bar"); ini_section_delete_var(cat, "hide_tool_bar");
if (confirm_reset != 1)
ini_section_set_int(cat, "confirm_reset", confirm_reset);
else
ini_section_delete_var(cat, "confirm_reset");
if (confirm_exit != 1)
ini_section_set_int(cat, "confirm_exit", confirm_exit);
else
ini_section_delete_var(cat, "confirm_exit");
if (confirm_save != 1)
ini_section_set_int(cat, "confirm_save", confirm_save);
else
ini_section_delete_var(cat, "confirm_save");
if (mouse_sensitivity != 1.0)
ini_section_set_double(cat, "mouse_sensitivity", mouse_sensitivity);
else
ini_section_delete_var(cat, "mouse_sensitivity");
if (lang_id == plat_language_code(DEFAULT_LANGUAGE))
ini_section_delete_var(cat, "language");
else {
plat_language_code_r(lang_id, buffer, 511);
ini_section_set_string(cat, "language", buffer);
}
if (enable_discord) if (enable_discord)
ini_section_set_int(cat, "enable_discord", enable_discord); ini_section_set_int(cat, "enable_discord", enable_discord);
else else
ini_section_delete_var(cat, "enable_discord"); ini_section_delete_var(cat, "enable_discord");
if (open_dir_usr_path)
ini_section_set_int(cat, "open_dir_usr_path", open_dir_usr_path);
else
ini_section_delete_var(cat, "open_dir_usr_path");
if (video_framerate != -1) if (video_framerate != -1)
ini_section_set_int(cat, "video_gl_framerate", video_framerate); ini_section_set_int(cat, "video_gl_framerate", video_framerate);
else else
@@ -3133,6 +3160,9 @@ save_other_removable_devices(void)
void void
config_save(void) config_save(void)
{ {
save_global(); /* Global */
ini_write(global, global_cfg_path);
save_general(); /* General */ save_general(); /* General */
for (uint8_t i = 0; i < MONITORS_NUM; i++) for (uint8_t i = 0; i < MONITORS_NUM; i++)
save_monitor(i); /* Monitors */ save_monitor(i); /* Monitors */

View File

@@ -175,6 +175,7 @@ extern int hook_enabled; /* (C) Keyboard hook is enabled */
extern char exe_path[2048]; /* path (dir) of executable */ extern char exe_path[2048]; /* path (dir) of executable */
extern char usr_path[1024]; /* path (dir) of user data */ extern char usr_path[1024]; /* path (dir) of user data */
extern char cfg_path[1024]; /* full path of config file */ extern char cfg_path[1024]; /* full path of config file */
extern char global_cfg_path[1024]; /* full path of global config file */
extern int open_dir_usr_path; /* default file open dialog directory of usr_path */ extern int open_dir_usr_path; /* default file open dialog directory of usr_path */
extern char uuid[MAX_UUID_LEN]; /* UUID or machine identifier */ extern char uuid[MAX_UUID_LEN]; /* UUID or machine identifier */
#ifndef USE_NEW_DYNAREC #ifndef USE_NEW_DYNAREC