From c7388eb174fb68492bb2656a3d746edb422bd21e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Hrdli=C4=8Dka?= Date: Wed, 1 Aug 2018 18:07:52 +0200 Subject: [PATCH] config: replace numeric `enable_sync` setting with `time_sync` string This shouldn't break existing configs. Existing "enable_sync" setings are automatically replaced with an appropriate "time_sync" value. In case "enable_sync" and "time_sync" settings are both present in a configuration file (shouldn't happen without manually editing the config), "time_sync" takes precedence. --- src/86box.h | 2 +- src/config.c | 29 +++++++++++++++++++++++------ src/machine/m_europc.c | 2 +- src/machine/m_xt_t1000.c | 2 +- src/nvr.c | 4 ++-- src/nvr_at.c | 2 +- src/pc.c | 2 +- src/win/win_settings.c | 6 +++--- 8 files changed, 33 insertions(+), 16 deletions(-) diff --git a/src/86box.h b/src/86box.h index eaac682d3..ffd4ec002 100644 --- a/src/86box.h +++ b/src/86box.h @@ -104,7 +104,7 @@ extern int cpu_manufacturer, /* (C) cpu manufacturer */ cpu, /* (C) cpu type */ cpu_use_dynarec, /* (C) cpu uses/needs Dyna */ enable_external_fpu; /* (C) enable external FPU */ -extern int enable_sync; /* (C) enable time sync */ +extern int time_sync; /* (C) enable time sync */ extern int network_type; /* (C) net provider type */ extern int network_card; /* (C) net interface num */ extern char network_host[512]; /* (C) host network intf */ diff --git a/src/config.c b/src/config.c index f419539da..ff45cfbd8 100644 --- a/src/config.c +++ b/src/config.c @@ -528,10 +528,24 @@ load_machine(void) enable_external_fpu = !!config_get_int(cat, "cpu_enable_fpu", 0); - enable_sync = !!config_get_int(cat, "enable_sync", 1); + p = config_get_string(cat, "time_sync", NULL); + if (p != NULL) { + if (!strcmp(p, "disabled")) + time_sync = TIME_SYNC_DISABLED; + else + if (!strcmp(p, "local")) + time_sync = TIME_SYNC_ENABLED; + else + if (!strcmp(p, "utc") || !strcmp(p, "gmt")) + time_sync = TIME_SYNC_ENABLED | TIME_SYNC_UTC; + else + time_sync = TIME_SYNC_ENABLED; + } else + time_sync = !!config_get_int(cat, "enable_sync", 1); /* Remove this after a while.. */ config_delete_var(cat, "nvr_path"); + config_delete_var(cat, "enable_sync"); } @@ -1278,7 +1292,7 @@ config_load(void) machine = machine_get_machine_from_internal_name("ibmpc"); gfxcard = GFX_CGA; vid_api = plat_vidapi("default"); - enable_sync = 1; + time_sync = TIME_SYNC_ENABLED; joystick_type = 7; if (hdc_name) { free(hdc_name); @@ -1455,10 +1469,13 @@ save_machine(void) else config_set_int(cat, "cpu_enable_fpu", enable_external_fpu); - if (enable_sync == 1) - config_delete_var(cat, "enable_sync"); - else - config_set_int(cat, "enable_sync", enable_sync); + if (time_sync & TIME_SYNC_ENABLED) + if (time_sync & TIME_SYNC_UTC) + config_set_string(cat, "time_sync", "utc"); + else + config_set_string(cat, "time_sync", "local"); + else + config_set_string(cat, "time_sync", "disabled"); delete_section_if_empty(cat); } diff --git a/src/machine/m_europc.c b/src/machine/m_europc.c index df464e73e..022152553 100644 --- a/src/machine/m_europc.c +++ b/src/machine/m_europc.c @@ -280,7 +280,7 @@ rtc_start(nvr_t *nvr) struct tm tm; /* Initialize the internal and chip times. */ - if (enable_sync & TIME_SYNC_ENABLED) { + if (time_sync & TIME_SYNC_ENABLED) { /* Use the internal clock's time. */ nvr_time_get(&tm); rtc_time_set(nvr->regs, &tm); diff --git a/src/machine/m_xt_t1000.c b/src/machine/m_xt_t1000.c index 97924dd5e..4ff7aa41b 100644 --- a/src/machine/m_xt_t1000.c +++ b/src/machine/m_xt_t1000.c @@ -258,7 +258,7 @@ tc8521_start(nvr_t *nvr) struct tm tm; /* Initialize the internal and chip times. */ - if (enable_sync & TIME_SYNC_ENABLED) { + if (time_sync & TIME_SYNC_ENABLED) { /* Use the internal clock's time. */ nvr_time_get(&tm); tc8521_time_set(nvr->regs, &tm); diff --git a/src/nvr.c b/src/nvr.c index 65d8114a4..a35f75559 100644 --- a/src/nvr.c +++ b/src/nvr.c @@ -181,10 +181,10 @@ nvr_init(nvr_t *nvr) /* Initialize the internal clock as needed. */ memset(&intclk, 0x00, sizeof(intclk)); - if (enable_sync & TIME_SYNC_ENABLED) { + if (time_sync & TIME_SYNC_ENABLED) { /* Get the current time of day, and convert to local time. */ (void)time(&now); - if(enable_sync & TIME_SYNC_UTC) + if(time_sync & TIME_SYNC_UTC) tm = gmtime(&now); else tm = localtime(&now); diff --git a/src/nvr_at.c b/src/nvr_at.c index 773bb5502..29e5e5bcb 100644 --- a/src/nvr_at.c +++ b/src/nvr_at.c @@ -554,7 +554,7 @@ nvr_write(uint16_t addr, uint8_t val, void *priv) if ((local->addr < RTC_REGA) || ((local->cent != 0xff) && (local->addr == local->cent))) { if ((local->addr != 1) && (local->addr != 3) && (local->addr != 5)) { - if ((old != val) && !(enable_sync & TIME_SYNC_ENABLED)) { + if ((old != val) && !(time_sync & TIME_SYNC_ENABLED)) { /* Update internal clock. */ time_get(nvr, &tm); nvr_time_set(&tm); diff --git a/src/pc.c b/src/pc.c index 88fa42579..659f3778c 100644 --- a/src/pc.c +++ b/src/pc.c @@ -119,7 +119,7 @@ int cpu_manufacturer = 0, /* (C) cpu manufacturer */ cpu_use_dynarec = 0, /* (C) cpu uses/needs Dyna */ cpu = 3, /* (C) cpu type */ enable_external_fpu = 0; /* (C) enable external FPU */ -int enable_sync = 0; /* (C) enable time sync */ +int time_sync = 0; /* (C) enable time sync */ /* Statistics. */ extern int diff --git a/src/win/win_settings.c b/src/win/win_settings.c index 838450cd1..193c82aea 100644 --- a/src/win/win_settings.c +++ b/src/win/win_settings.c @@ -202,7 +202,7 @@ win_settings_init(void) temp_dynarec = cpu_use_dynarec; #endif temp_fpu = enable_external_fpu; - temp_sync = enable_sync & TIME_SYNC_ENABLED; + temp_sync = time_sync & TIME_SYNC_ENABLED; /* Video category */ temp_gfxcard = gfxcard; @@ -305,7 +305,7 @@ win_settings_changed(void) i = i || (temp_dynarec != cpu_use_dynarec); #endif i = i || (temp_fpu != enable_external_fpu); - i = i || (temp_sync != (enable_sync & TIME_SYNC_ENABLED)); + i = i || (temp_sync != (time_sync & TIME_SYNC_ENABLED)); /* Video category */ i = i || (gfxcard != temp_gfxcard); @@ -403,7 +403,7 @@ win_settings_save(void) cpu_use_dynarec = temp_dynarec; #endif enable_external_fpu = temp_fpu; - enable_sync = temp_sync; + time_sync = temp_sync; /* Video category */ gfxcard = temp_gfxcard;