2013-11-19 11:30:58 +01:00
|
|
|
/*
|
|
|
|
|
* This file contains Nt monotonic counter code, taken from wine which is:
|
|
|
|
|
* Copyright 2002 Rex Jolliff (rex@lvcablemodem.com)
|
|
|
|
|
* Copyright 1999 Juergen Schmied
|
|
|
|
|
* Copyright 2007 Dmitry Timoshkov
|
|
|
|
|
* GNU LGPL 2.1 license
|
|
|
|
|
* */
|
2012-11-15 00:39:56 +01:00
|
|
|
#include "stdafx.h"
|
|
|
|
|
#include "Emu/SysCalls/SysCalls.h"
|
|
|
|
|
#include <sys/timeb.h>
|
|
|
|
|
|
|
|
|
|
SysCallBase sys_time("sys_time");
|
|
|
|
|
static const u64 timebase_frequency = 79800000;
|
2013-11-09 02:05:58 +01:00
|
|
|
extern int cellSysutilGetSystemParamInt(int id, mem32_t value);
|
|
|
|
|
|
|
|
|
|
int sys_time_get_timezone(mem32_t timezone, mem32_t summertime)
|
|
|
|
|
{
|
|
|
|
|
int ret;
|
|
|
|
|
ret = cellSysutilGetSystemParamInt(0x0116, timezone); //0x0116 = CELL_SYSUTIL_SYSTEMPARAM_ID_TIMEZONE
|
|
|
|
|
if (ret != CELL_OK) return ret;
|
|
|
|
|
ret = cellSysutilGetSystemParamInt(0x0117, summertime); //0x0117 = CELL_SYSUTIL_SYSTEMPARAM_ID_TIMEZONE
|
|
|
|
|
if (ret != CELL_OK) return ret;
|
|
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
2012-11-15 00:39:56 +01:00
|
|
|
|
|
|
|
|
int sys_time_get_current_time(u32 sec_addr, u32 nsec_addr)
|
|
|
|
|
{
|
|
|
|
|
sys_time.Log("sys_time_get_current_time(sec_addr=0x%x, nsec_addr=0x%x)", sec_addr, nsec_addr);
|
|
|
|
|
|
2013-06-30 10:46:29 +02:00
|
|
|
u64 time = sys_time_get_system_time();
|
|
|
|
|
|
|
|
|
|
Memory.Write64(sec_addr, time / 1000000);
|
|
|
|
|
Memory.Write64(nsec_addr, time % 1000000);
|
2012-11-15 00:39:56 +01:00
|
|
|
|
|
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s64 sys_time_get_system_time()
|
|
|
|
|
{
|
|
|
|
|
sys_time.Log("sys_time_get_system_time()");
|
2013-11-19 11:30:58 +01:00
|
|
|
#ifdef _WIN32
|
2012-11-15 00:39:56 +01:00
|
|
|
LARGE_INTEGER cycle;
|
|
|
|
|
QueryPerformanceCounter(&cycle);
|
|
|
|
|
return cycle.QuadPart;
|
2013-11-19 11:30:58 +01:00
|
|
|
#else
|
|
|
|
|
struct timespec ts;
|
|
|
|
|
if (!clock_gettime(CLOCK_MONOTONIC, &ts))
|
|
|
|
|
return ts.tv_sec * (s64)10000000 + (s64)ts.tv_nsec / (s64)100;
|
|
|
|
|
#endif
|
2012-11-15 00:39:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
u64 sys_time_get_timebase_frequency()
|
|
|
|
|
{
|
|
|
|
|
sys_time.Log("sys_time_get_timebase_frequency()");
|
|
|
|
|
|
2013-11-19 11:30:58 +01:00
|
|
|
#ifdef _WIN32
|
2012-11-15 00:39:56 +01:00
|
|
|
static LARGE_INTEGER frequency = {0ULL};
|
|
|
|
|
|
|
|
|
|
if(!frequency.QuadPart) QueryPerformanceFrequency(&frequency);
|
|
|
|
|
|
|
|
|
|
return frequency.QuadPart;
|
2013-11-19 11:30:58 +01:00
|
|
|
#else
|
|
|
|
|
return 10000000;
|
|
|
|
|
#endif
|
|
|
|
|
}
|