2014-06-21 17:00:58 +00:00
|
|
|
/*
|
2015-10-22 05:13:26 +00:00
|
|
|
* Apple // emulator for *ix
|
2014-06-21 17:00:58 +00:00
|
|
|
*
|
|
|
|
* This software package is subject to the GNU General Public License
|
2015-10-22 05:13:26 +00:00
|
|
|
* version 3 or later (your choice) as published by the Free Software
|
2014-06-21 17:00:58 +00:00
|
|
|
* Foundation.
|
|
|
|
*
|
2015-10-22 05:13:26 +00:00
|
|
|
* Copyright 2013-2015 Aaron Culliney
|
2014-06-21 17:00:58 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2017-08-20 06:05:58 +00:00
|
|
|
#if __APPLE__
|
|
|
|
|
2014-06-21 17:00:58 +00:00
|
|
|
#include "common.h"
|
|
|
|
#include <mach/mach_time.h>
|
|
|
|
|
|
|
|
// Derived from http://stackoverflow.com/questions/5167269/clock-gettime-alternative-in-mac-os-x
|
|
|
|
// 2014/06/21
|
|
|
|
|
|
|
|
#define ORWL_NANO (+1.0E-9)
|
|
|
|
#define ORWL_GIGA UINT64_C(1000000000)
|
|
|
|
|
|
|
|
static double orwl_timebase = 0.0;
|
|
|
|
static uint64_t orwl_timestart = 0;
|
|
|
|
|
2016-02-23 05:36:08 +00:00
|
|
|
static void _init_darwin_shim(void) {
|
2015-12-05 06:22:48 +00:00
|
|
|
LOG("Initializing Darwin Shim");
|
2014-06-21 17:00:58 +00:00
|
|
|
mach_timebase_info_data_t tb = { 0 };
|
|
|
|
mach_timebase_info(&tb);
|
|
|
|
orwl_timebase = tb.numer;
|
|
|
|
orwl_timebase /= tb.denom;
|
|
|
|
orwl_timestart = mach_absolute_time();
|
|
|
|
}
|
|
|
|
|
2016-02-23 05:36:08 +00:00
|
|
|
static __attribute__((constructor)) void __init_darwin_shim(void) {
|
|
|
|
emulator_registerStartupCallback(CTOR_PRIORITY_LATE, &_init_darwin_shim);
|
|
|
|
}
|
|
|
|
|
2016-10-17 01:51:50 +00:00
|
|
|
int my_clock_gettime(int clk_id, struct timespec *tp) {
|
2014-06-21 17:00:58 +00:00
|
|
|
double diff = (mach_absolute_time() - orwl_timestart) * orwl_timebase;
|
|
|
|
tp->tv_sec = diff * ORWL_NANO;
|
|
|
|
tp->tv_nsec = diff - (tp->tv_sec * ORWL_GIGA);
|
|
|
|
return 0;
|
|
|
|
}
|
2017-08-20 06:05:58 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|