Synchronize the internal clock with host time when unpausing the emulator

This commit is contained in:
Alexander Babikov
2021-10-17 04:52:53 +05:00
parent db239d64e5
commit a6af62835b
4 changed files with 27 additions and 11 deletions

View File

@@ -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 *);

View File

@@ -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)

View File

@@ -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);

View File

@@ -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. */