diff --git a/src/kernel/timer.c b/src/kernel/timer.c index f8e10de0..00d0db85 100644 --- a/src/kernel/timer.c +++ b/src/kernel/timer.c @@ -615,6 +615,10 @@ DWORD GUIAPI GetTickCount (void) { #ifdef _MGRM_PROCESSES return SHAREDRES_TIMER_COUNTER; +#elif defined(_MGRM_STANDALONE) + extern DWORD __mg_os_get_time(void); + __mg_timer_counter = __mg_os_get_time() / 10; + return __mg_timer_counter; #else return __mg_timer_counter; #endif diff --git a/src/misc/nposix.c b/src/misc/nposix.c index 74c6c222..abf381f9 100644 --- a/src/misc/nposix.c +++ b/src/misc/nposix.c @@ -430,6 +430,63 @@ void __mg_os_time_delay (int ms) #endif } +#ifndef __NOUNIX__ + +#include +#include +#include + +static struct timeval timeval_startup; +void __mg_os_start_time(void) +{ + gettimeofday(&timeval_startup, NULL); +} + +DWORD __mg_os_get_time(void) +{ + DWORD ds, dms; + struct timeval current; + + gettimeofday(¤t, NULL); + ds = (current.tv_sec - timeval_startup.tv_sec); + + if (current.tv_sec == timeval_startup.tv_sec) { + dms = (current.tv_usec - timeval_startup.tv_usec) / 1000L; + } + else if (current.tv_usec >= timeval_startup.tv_usec) { + dms = (current.tv_usec - timeval_startup.tv_usec) / 1000L; + } + else { + assert(ds > 0); + + ds--; + dms = 1000L - (timeval_startup.tv_usec - current.tv_usec) / 1000L; + } + + return ds * 1000 + dms; +} + +#elif defined(WIN32) + +#include + +#pragma comment(lib, "winmm.lib") + +void __mg_os_start_time(void) +{ + // do nothing +} + +DWORD __mg_os_get_time(void) { + return timeGetTime(); +} + +#else + +#error "Please implement __mg_os_start_time and __mg_os_get_time for your OS" + +#endif + /* ------------------------------ I/O -------------------------------- */ void __mg_rewind (FILE *fp) { diff --git a/src/standalone/standalone.c b/src/standalone/standalone.c index 7192b605..72d1fc5e 100644 --- a/src/standalone/standalone.c +++ b/src/standalone/standalone.c @@ -64,35 +64,6 @@ #include "menu.h" #include "ourhdr.h" -#ifndef __NOUNIX__ - -#include -#include -#include - -static struct timeval timeval_startup; -static DWORD get_timer_count(const struct timeval* current) -{ - DWORD ds = (current->tv_sec - timeval_startup.tv_sec); - DWORD dms; - - if (current->tv_sec == timeval_startup.tv_sec) { - dms = (current->tv_usec - timeval_startup.tv_usec) / 1000L; - } - else if (current->tv_usec >= timeval_startup.tv_usec) { - dms = (current->tv_usec - timeval_startup.tv_usec) / 1000L; - } - else { - assert(ds > 0); - - ds--; - dms = 1000L - (timeval_startup.tv_usec - current->tv_usec) / 1000L; - } - - return ds * 100 + dms / 10; -} -#endif - extern DWORD __mg_timer_counter; static DWORD old_timer_counter = 0; @@ -188,6 +159,9 @@ static void ParseEvent (PMSGQUEUE msg_que, int event) } } +extern void __mg_os_start_time(void); +extern DWORD __mg_os_get_time(void); + BOOL GUIAPI salone_StandAloneStartup (void) { mg_fd_zero (&mg_rfdset); @@ -197,9 +171,7 @@ BOOL GUIAPI salone_StandAloneStartup (void) mg_InstallIntervalTimer (); #endif -#ifndef __NOUNIX__ - gettimeofday(&timeval_startup, NULL); -#endif + __mg_os_start_time(); return TRUE; } @@ -232,11 +204,6 @@ BOOL salone_IdleHandler4StandAlone (PMSGQUEUE msg_queue) fd_set* esetptr = NULL; EXTRA_INPUT_EVENT extra; // Since 4.0.0; for extra input events -#ifndef __NOUNIX__ - struct timeval timeval_current; - gettimeofday(&timeval_current, NULL); -#endif - if (old_timer_counter != __mg_timer_counter) { old_timer_counter = __mg_timer_counter; SetDesktopTimerFlag (); @@ -277,7 +244,7 @@ BOOL salone_IdleHandler4StandAlone (PMSGQUEUE msg_queue) n = IAL_WaitEvent (mg_maxfd, &rset, wsetptr, esetptr, msg_queue?&sel_timeout:&sel_timeout_nd, &extra); /* update __mg_timer_counter */ - __mg_timer_counter = get_timer_count(&timeval_current); + __mg_timer_counter = __mg_os_get_time()/10; #endif if (msg_queue == NULL)