diff --git a/src/include/86box/nvr.h b/src/include/86box/nvr.h index b0157088c..b841d7e6a 100644 --- a/src/include/86box/nvr.h +++ b/src/include/86box/nvr.h @@ -112,6 +112,7 @@ extern int nvr_save(void); extern int nvr_is_leap(int year); extern int nvr_get_days(int month, int year); +extern void nvr_time_sync(); extern void nvr_time_get(struct tm *); extern void nvr_time_set(struct tm *); diff --git a/src/nvr.c b/src/nvr.c index ee9dcaaca..46e0f6c5a 100644 --- a/src/nvr.c +++ b/src/nvr.c @@ -166,8 +166,6 @@ onesec_timer(void *priv) void nvr_init(nvr_t *nvr) { - struct tm *tm; - time_t now; int c; /* Set up the NVR file's name. */ @@ -178,15 +176,7 @@ nvr_init(nvr_t *nvr) /* Initialize the internal clock as needed. */ memset(&intclk, 0x00, sizeof(intclk)); if (time_sync & TIME_SYNC_ENABLED) { - /* Get the current time of day, and convert to local time. */ - (void)time(&now); - if(time_sync & TIME_SYNC_UTC) - tm = gmtime(&now); - else - tm = localtime(&now); - - /* Set the internal clock. */ - nvr_time_set(tm); + nvr_time_sync(); } else { /* Reset the internal clock to 1980/01/01 00:00. */ intclk.tm_mon = 1; @@ -325,6 +315,24 @@ nvr_close(void) } +void +nvr_time_sync(void) +{ + struct tm *tm; + time_t now; + + /* Get the current time of day, and convert to local time. */ + (void)time(&now); + if(time_sync & TIME_SYNC_UTC) + tm = gmtime(&now); + else + tm = localtime(&now); + + /* Set the internal clock. */ + nvr_time_set(tm); +} + + /* Get current time from internal clock. */ void nvr_time_get(struct tm *tm) diff --git a/src/unix/unix.c b/src/unix/unix.c index c583f7f50..d7db5cbef 100644 --- a/src/unix/unix.c +++ b/src/unix/unix.c @@ -708,6 +708,9 @@ plat_pause(int p) static wchar_t oldtitle[512]; wchar_t title[512]; + if ((p == 0) && (time_sync & TIME_SYNC_ENABLED)) + nvr_time_sync(); + dopause = p; if (p) { wcsncpy(oldtitle, ui_window_title(NULL), sizeof_w(oldtitle) - 1); diff --git a/src/win/win_ui.c b/src/win/win_ui.c index c6a8983a6..f2d00ef1c 100644 --- a/src/win/win_ui.c +++ b/src/win/win_ui.c @@ -1586,6 +1586,10 @@ plat_pause(int p) ui_window_title(oldtitle); } + /* If un-pausing, synchronize the internal clock with the host's time. */ + if ((p == 0) && (time_sync & TIME_SYNC_ENABLED)) + nvr_time_sync(); + dopause = p; /* Update the actual menu. */