Synchronize the internal clock with host time when unpausing the emulator
This commit is contained in:
@@ -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 *);
|
||||
|
||||
|
30
src/nvr.c
30
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)
|
||||
|
@@ -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);
|
||||
|
@@ -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. */
|
||||
|
Reference in New Issue
Block a user