OSTime nanosToTicks(OSTime nanoseconds) { // Division is done in two parts to try to maintain accuracy, 31250 * 32000 = 1*10^9 auto timerSpeed = static_cast<uint64_t>(OSGetSystemInfo()->busSpeed / 4); return (static_cast<uint64_t>(nanoseconds) * (timerSpeed / 31250)) / 32000; }
void _GX2InitVsync() { gVsyncThreadQueue = OSAllocFromSystem<OSThreadQueue>(); gVsyncAlarm = OSAllocFromSystem<OSAlarm>(); auto ticks = (static_cast<OSTime>(OSGetSystemInfo()->clockSpeed / 4) * 60) / 1000; OSCreateAlarm(gVsyncAlarm); OSSetPeriodicAlarm(gVsyncAlarm, 0, OSGetTime(), ticks, pVsyncAlarmHandler); }
// Time since system start up OSTime OSGetSystemTime() { return OSGetTime() - OSGetSystemInfo()->baseTime; }