summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--src/mame/video/igs017_igs031.cpp2
-rw-r--r--src/osd/eigccppc.h19
-rw-r--r--src/osd/eigccx86.h36
-rw-r--r--src/osd/eivcx86.h41
-rw-r--r--src/osd/modules/debugger/debugqt.cpp2
-rw-r--r--src/osd/modules/lib/osdlib_macosx.cpp146
-rw-r--r--src/osd/modules/lib/osdlib_unix.cpp67
-rw-r--r--src/osd/modules/lib/osdlib_win32.cpp106
-rw-r--r--src/osd/osdcore.cpp40
-rw-r--r--src/osd/sdl/window.cpp2
10 files changed, 44 insertions, 417 deletions
diff --git a/src/mame/video/igs017_igs031.cpp b/src/mame/video/igs017_igs031.cpp
index 8e8993e0fa7..9708d4413e8 100644
--- a/src/mame/video/igs017_igs031.cpp
+++ b/src/mame/video/igs017_igs031.cpp
@@ -374,7 +374,7 @@ int igs017_igs031_device::debug_viewer(bitmap_ind16 &bitmap,const rectangle &cli
popmessage("a: %08X w: %03X p: %02x-%02x-%02x",a,w,m_sprites_gfx[a/3*3+0],m_sprites_gfx[a/3*3+1],m_sprites_gfx[a/3*3+2]);
m_debug_addr = a;
m_debug_width = w;
- osd_sleep(200000);
+ osd_sleep(osd_ticks_per_second() / 1000 * 200);
return 1;
}
#endif
diff --git a/src/osd/eigccppc.h b/src/osd/eigccppc.h
index d9cd2ee1828..7d61ee49752 100644
--- a/src/osd/eigccppc.h
+++ b/src/osd/eigccppc.h
@@ -284,23 +284,4 @@ _count_leading_ones(UINT32 value)
return result;
}
-
-/***************************************************************************
- INLINE TIMING FUNCTIONS
-***************************************************************************/
-
-/*-------------------------------------------------
- get_profile_ticks - return a tick counter
- from the processor that can be used for
- profiling. It does not need to run at any
- particular rate.
--------------------------------------------------*/
-
-#define get_profile_ticks _get_profile_ticks
-static inline INT64 ATTR_UNUSED ATTR_FORCE_INLINE _get_profile_ticks(void)
-{
- // fix me - should use the time base
- return osd_ticks();
-}
-
#endif /* __EIGCCPPC__ */
diff --git a/src/osd/eigccx86.h b/src/osd/eigccx86.h
index 3494e33b5db..1d5c30d151c 100644
--- a/src/osd/eigccx86.h
+++ b/src/osd/eigccx86.h
@@ -521,40 +521,4 @@ _count_leading_ones(UINT32 value)
return result;
}
-/***************************************************************************
- INLINE TIMING FUNCTIONS
-***************************************************************************/
-
-/*-------------------------------------------------
- get_profile_ticks - return a tick counter
- from the processor that can be used for
- profiling. It does not need to run at any
- particular rate.
--------------------------------------------------*/
-
-#define get_profile_ticks _get_profile_ticks
-
-#ifndef __x86_64__
-static inline UINT64 ATTR_UNUSED ATTR_FORCE_INLINE _get_profile_ticks(void)
-{
- UINT64 result;
- __asm__ __volatile__ (
- "rdtsc"
- : "=A" (result)
- );
- return result;
-}
-#else
-static inline UINT64 ATTR_UNUSED ATTR_FORCE_INLINE _get_profile_ticks(void)
-{
- _x86_union r;
- __asm__ __volatile__ (
- "rdtsc"
- : "=a" (r.u32.l), "=d" (r.u32.h)
- );
-
- return (UINT64) r.u64;
-}
-#endif
-
#endif /* __EIGCCX86__ */
diff --git a/src/osd/eivcx86.h b/src/osd/eivcx86.h
index b6139f70c26..503594d3a99 100644
--- a/src/osd/eivcx86.h
+++ b/src/osd/eivcx86.h
@@ -460,45 +460,4 @@ static inline UINT8 _count_leading_ones(UINT32 value)
}
#endif
-
-
-/***************************************************************************
- INLINE TIMING FUNCTIONS
-***************************************************************************/
-
-/*-------------------------------------------------
- get_profile_ticks - return a tick counter
- from the processor that can be used for
- profiling. It does not need to run at any
- particular rate.
--------------------------------------------------*/
-
-#define get_profile_ticks _get_profile_ticks
-
-#ifdef PTR64
-
-static inline osd_ticks_t _get_profile_ticks(void)
-{
- return __rdtsc();
-}
-
-#else
-
-static inline osd_ticks_t _get_profile_ticks(void)
-{
- UINT64 result;
- UINT64 *presult = &result;
-
- __asm {
- __asm _emit 0Fh __asm _emit 031h // rdtsc
- mov ebx, presult
- mov [ebx],eax
- mov [ebx+4],edx
- }
-
- return result;
-}
-
-#endif
-
#endif /* __EIVCX86__ */
diff --git a/src/osd/modules/debugger/debugqt.cpp b/src/osd/modules/debugger/debugqt.cpp
index e553585f729..ac6c6a9d95c 100644
--- a/src/osd/modules/debugger/debugqt.cpp
+++ b/src/osd/modules/debugger/debugqt.cpp
@@ -317,7 +317,7 @@ void debug_qt::wait_for_debugger(device_t &device, bool firststop)
mainQtWindow->setProcessor(&device);
// Run our own QT event loop
- osd_sleep(50000);
+ osd_sleep(osd_ticks_per_second() / 1000 * 50);
qApp->processEvents(QEventLoop::AllEvents, 1);
// Refresh everyone if requested
diff --git a/src/osd/modules/lib/osdlib_macosx.cpp b/src/osd/modules/lib/osdlib_macosx.cpp
index 0d89e6c3596..501719c1e3c 100644
--- a/src/osd/modules/lib/osdlib_macosx.cpp
+++ b/src/osd/modules/lib/osdlib_macosx.cpp
@@ -14,11 +14,6 @@
#include <sys/types.h>
#include <signal.h>
-#include <mach/mach.h>
-#include <mach/mach_time.h>
-#include <mach/mach_traps.h>
-#include <Carbon/Carbon.h>
-
// MAME headers
#include "osdcore.h"
#include "osdlib.h"
@@ -55,30 +50,6 @@ void osd_process_kill(void)
}
//============================================================
-// osd_num_processors
-//============================================================
-
-int osd_get_num_processors(void)
-{
- int processors = 1;
-
- struct host_basic_info host_basic_info;
- unsigned int count;
- kern_return_t r;
- mach_port_t my_mach_host_self;
-
- count = HOST_BASIC_INFO_COUNT;
- my_mach_host_self = mach_host_self();
- if ( ( r = host_info(my_mach_host_self, HOST_BASIC_INFO, (host_info_t)(&host_basic_info), &count)) == KERN_SUCCESS )
- {
- processors = host_basic_info.avail_cpus;
- }
- mach_port_deallocate(mach_task_self(), my_mach_host_self);
-
- return processors;
-}
-
-//============================================================
// osd_malloc
//============================================================
@@ -166,120 +137,3 @@ void osd_break_into_debugger(const char *message)
#endif
}
-
-//============================================================
-// PROTOTYPES
-//============================================================
-
-static osd_ticks_t init_cycle_counter(void);
-static osd_ticks_t mach_cycle_counter(void);
-
-//============================================================
-// STATIC VARIABLES
-//============================================================
-
-static osd_ticks_t (*cycle_counter)(void) = init_cycle_counter;
-static osd_ticks_t (*ticks_counter)(void) = init_cycle_counter;
-static osd_ticks_t ticks_per_second;
-
-//============================================================
-// init_cycle_counter
-//
-// to avoid total grossness, this function is split by subarch
-//============================================================
-
-static osd_ticks_t init_cycle_counter(void)
-{
- osd_ticks_t start, end;
- osd_ticks_t a, b;
-
- cycle_counter = mach_cycle_counter;
- ticks_counter = mach_cycle_counter;
-
- // wait for an edge on the timeGetTime call
- a = SDL_GetTicks();
- do
- {
- b = SDL_GetTicks();
- } while (a == b);
-
- // get the starting cycle count
- start = (*cycle_counter)();
-
- // now wait for 1/4 second total
- do
- {
- a = SDL_GetTicks();
- } while (a - b < 250);
-
- // get the ending cycle count
- end = (*cycle_counter)();
-
- // compute ticks_per_sec
- ticks_per_second = (end - start) * 4;
-
- // return the current cycle count
- return (*cycle_counter)();
-}
-
-//============================================================
-// performance_cycle_counter
-//============================================================
-
-//============================================================
-// mach_cycle_counter
-//============================================================
-static osd_ticks_t mach_cycle_counter(void)
-{
- return mach_absolute_time();
-}
-
-//============================================================
-// osd_ticks
-//============================================================
-
-osd_ticks_t osd_ticks(void)
-{
- return (*cycle_counter)();
-}
-
-
-//============================================================
-// osd_ticks_per_second
-//============================================================
-
-osd_ticks_t osd_ticks_per_second(void)
-{
- if (ticks_per_second == 0)
- {
- // if we haven't computed the value yet, there's no time like the present
- init_cycle_counter();
- }
- return ticks_per_second;
-}
-
-
-
-//============================================================
-// osd_sleep
-//============================================================
-
-void osd_sleep(osd_ticks_t duration)
-{
- UINT32 msec;
-
- // make sure we've computed ticks_per_second
- if (ticks_per_second == 0)
- (void)osd_ticks();
-
- // convert to milliseconds, rounding down
- msec = (UINT32)(duration * 1000 / ticks_per_second);
-
- // only sleep if at least 2 full milliseconds
- if (msec >= 2)
- {
- // take a couple of msecs off the top for good measure
- msec -= 2;
- usleep(msec*1000);
- }
-}
diff --git a/src/osd/modules/lib/osdlib_unix.cpp b/src/osd/modules/lib/osdlib_unix.cpp
index a275eb04192..3075ea63769 100644
--- a/src/osd/modules/lib/osdlib_unix.cpp
+++ b/src/osd/modules/lib/osdlib_unix.cpp
@@ -13,8 +13,7 @@
#include <sys/mman.h>
#include <sys/types.h>
#include <signal.h>
-#include <time.h>
-#include <sys/time.h>
+
#ifdef SDLMAME_EMSCRIPTEN
#include <emscripten.h>
#endif
@@ -51,20 +50,6 @@ void osd_process_kill(void)
}
//============================================================
-// osd_num_processors
-//============================================================
-
-int osd_get_num_processors(void)
-{
- int processors = 1;
-
-#if defined(_SC_NPROCESSORS_ONLN)
- processors = sysconf(_SC_NPROCESSORS_ONLN);
-#endif
- return processors;
-}
-
-//============================================================
// osd_malloc
//============================================================
@@ -150,53 +135,3 @@ void osd_break_into_debugger(const char *message)
printf("Ignoring MAME exception: %s\n", message);
#endif
}
-
-
-//============================================================
-// osd_ticks
-//============================================================
-
-osd_ticks_t osd_ticks(void)
-{
-#ifdef SDLMAME_EMSCRIPTEN
- return (osd_ticks_t)(emscripten_get_now() * 1000.0);
-#else
- struct timeval tp;
- static osd_ticks_t start_sec = 0;
-
- gettimeofday(&tp, NULL);
- if (start_sec==0)
- start_sec = tp.tv_sec;
- return (tp.tv_sec - start_sec) * (osd_ticks_t) 1000000 + tp.tv_usec;
-#endif
-}
-
-
-//============================================================
-// osd_ticks_per_second
-//============================================================
-
-osd_ticks_t osd_ticks_per_second(void)
-{
- return (osd_ticks_t) 1000000;
-}
-
-//============================================================
-// osd_sleep
-//============================================================
-
-void osd_sleep(osd_ticks_t duration)
-{
- UINT32 msec;
-
- // convert to milliseconds, rounding down
- msec = (UINT32)(duration * 1000 / osd_ticks_per_second());
-
- // only sleep if at least 2 full milliseconds
- if (msec >= 2)
- {
- // take a couple of msecs off the top for good measure
- msec -= 2;
- usleep(msec*1000);
- }
-}
diff --git a/src/osd/modules/lib/osdlib_win32.cpp b/src/osd/modules/lib/osdlib_win32.cpp
index 75218574aff..bb6f136be90 100644
--- a/src/osd/modules/lib/osdlib_win32.cpp
+++ b/src/osd/modules/lib/osdlib_win32.cpp
@@ -101,21 +101,6 @@ void osd_process_kill(void)
}
//============================================================
-// osd_num_processors
-//============================================================
-
-int osd_get_num_processors(void)
-{
- SYSTEM_INFO info;
-
- // otherwise, fetch the info from the system
- GetSystemInfo(&info);
-
- // max out at 4 for now since scaling above that seems to do poorly
- return MIN(info.dwNumberOfProcessors, 4);
-}
-
-//============================================================
// osd_malloc
//============================================================
@@ -256,94 +241,3 @@ void osd_break_into_debugger(const char *message)
#endif
}
-//============================================================
-// GLOBAL VARIABLES
-//============================================================
-
-static osd_ticks_t ticks_per_second = 0;
-static osd_ticks_t suspend_ticks = 0;
-static BOOL using_qpc = TRUE;
-
-
-
-//============================================================
-// osd_ticks
-//============================================================
-
-osd_ticks_t osd_ticks(void)
-{
- LARGE_INTEGER performance_count;
-
- // if we're suspended, just return that
- if (suspend_ticks != 0)
- return suspend_ticks;
-
- // if we have a per second count, just go for it
- if (ticks_per_second != 0)
- {
- // QueryPerformanceCounter if we can
- if (using_qpc)
- {
- QueryPerformanceCounter(&performance_count);
- return (osd_ticks_t)performance_count.QuadPart - suspend_ticks;
- }
-
- // otherwise, fall back to timeGetTime
- else
- return (osd_ticks_t)timeGetTime() - suspend_ticks;
- }
-
- // if not, we have to determine it
- using_qpc = QueryPerformanceFrequency(&performance_count) && (performance_count.QuadPart != 0);
- if (using_qpc)
- ticks_per_second = (osd_ticks_t)performance_count.QuadPart;
- else
- ticks_per_second = 1000;
-
- // call ourselves to get the first value
- return osd_ticks();
-}
-
-
-//============================================================
-// osd_ticks_per_second
-//============================================================
-
-osd_ticks_t osd_ticks_per_second(void)
-{
- if (ticks_per_second == 0)
- osd_ticks();
- return ticks_per_second;
-}
-
-//============================================================
-// osd_sleep
-//============================================================
-
-void osd_sleep(osd_ticks_t duration)
-{
- DWORD msec;
-
- // make sure we've computed ticks_per_second
- if (ticks_per_second == 0)
- (void)osd_ticks();
-
- // convert to milliseconds, rounding down
- msec = (DWORD)(duration * 1000 / ticks_per_second);
-
- // only sleep if at least 2 full milliseconds
- if (msec >= 2)
- {
- HANDLE current_thread = GetCurrentThread();
- int old_priority = GetThreadPriority(current_thread);
-
- // take a couple of msecs off the top for good measure
- msec -= 2;
-
- // bump our thread priority super high so that we get
- // priority when we need it
- SetThreadPriority(current_thread, THREAD_PRIORITY_TIME_CRITICAL);
- Sleep(msec);
- SetThreadPriority(current_thread, old_priority);
- }
-}
diff --git a/src/osd/osdcore.cpp b/src/osd/osdcore.cpp
index 632124e2e7c..206cb5ed642 100644
--- a/src/osd/osdcore.cpp
+++ b/src/osd/osdcore.cpp
@@ -2,6 +2,8 @@
// copyright-holders:Aaron Giles
#include "osdcore.h"
+#include <thread>
+#include <chrono>
static const int MAXSTACK = 10;
static osd_output *m_stack[MAXSTACK];
@@ -141,3 +143,41 @@ void CLIB_DECL osd_printf_log(const char *format, ...)
va_end(argptr);
}
#endif
+
+//============================================================
+// osd_ticks
+//============================================================
+
+osd_ticks_t osd_ticks(void)
+{
+ return std::chrono::high_resolution_clock::now().time_since_epoch().count();
+}
+
+
+//============================================================
+// osd_ticks_per_second
+//============================================================
+
+osd_ticks_t osd_ticks_per_second(void)
+{
+ return std::chrono::high_resolution_clock::period::den;
+}
+
+//============================================================
+// osd_sleep
+//============================================================
+
+void osd_sleep(osd_ticks_t duration)
+{
+ std::this_thread::sleep_for(std::chrono::high_resolution_clock::duration(duration));
+}
+
+//============================================================
+// osd_num_processors
+//============================================================
+
+int osd_get_num_processors(void)
+{
+ // max out at 4 for now since scaling above that seems to do poorly
+ return MIN(std::thread::hardware_concurrency(), 4);
+}
diff --git a/src/osd/sdl/window.cpp b/src/osd/sdl/window.cpp
index 0c5bb7a51ca..2a0147afea5 100644
--- a/src/osd/sdl/window.cpp
+++ b/src/osd/sdl/window.cpp
@@ -310,7 +310,7 @@ static void sdlwindow_sync(void)
while (!osd_work_queue_wait(work_queue, osd_ticks_per_second()*10))
{
osd_printf_warning("sdlwindow_sync: Sleeping...\n");
- osd_sleep(100000);
+ osd_sleep(osd_ticks_per_second() / 1000 * 100);
}
}
}