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"
|
2014-06-17 17:44:03 +02:00
|
|
|
#include "Utilities/Log.h"
|
2014-06-02 19:27:24 +02:00
|
|
|
#include "Emu/Memory/Memory.h"
|
|
|
|
|
#include "Emu/System.h"
|
2012-11-15 00:39:56 +01:00
|
|
|
#include "Emu/SysCalls/SysCalls.h"
|
2014-06-25 00:38:34 +02:00
|
|
|
#include "sys_time.h"
|
2012-11-15 00:39:56 +01:00
|
|
|
|
|
|
|
|
SysCallBase sys_time("sys_time");
|
2014-02-16 16:23:58 +01:00
|
|
|
|
|
|
|
|
//static const u64 timebase_frequency = 79800000;
|
2013-11-09 02:05:58 +01:00
|
|
|
extern int cellSysutilGetSystemParamInt(int id, mem32_t value);
|
|
|
|
|
|
2014-02-24 07:54:42 +01:00
|
|
|
// Auxiliary functions
|
2014-02-20 03:16:17 +01:00
|
|
|
u64 get_time()
|
2014-02-16 16:23:58 +01:00
|
|
|
{
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
LARGE_INTEGER cycle;
|
|
|
|
|
LARGE_INTEGER freq;
|
|
|
|
|
QueryPerformanceCounter(&cycle);
|
|
|
|
|
QueryPerformanceFrequency(&freq);
|
2014-02-20 03:16:17 +01:00
|
|
|
return cycle.QuadPart * 10000000 / freq.QuadPart;
|
2014-02-16 16:23: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;
|
2014-04-28 05:38:43 +02:00
|
|
|
|
|
|
|
|
// Should never occur.
|
|
|
|
|
assert(0);
|
|
|
|
|
return 0;
|
2014-02-16 16:23:58 +01:00
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-24 07:54:42 +01:00
|
|
|
// Returns some relative time in microseconds, don't change this fact
|
2014-02-20 03:16:17 +01:00
|
|
|
u64 get_system_time()
|
|
|
|
|
{
|
|
|
|
|
return get_time() / 10;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-24 07:54:42 +01:00
|
|
|
|
|
|
|
|
// Functions
|
2014-06-25 00:38:34 +02:00
|
|
|
s32 sys_time_get_timezone(mem32_t timezone, mem32_t summertime)
|
2014-02-24 07:54:42 +01:00
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-25 00:38:34 +02:00
|
|
|
s32 sys_time_get_current_time(u32 sec_addr, u32 nsec_addr)
|
2012-11-15 00:39:56 +01:00
|
|
|
{
|
|
|
|
|
sys_time.Log("sys_time_get_current_time(sec_addr=0x%x, nsec_addr=0x%x)", sec_addr, nsec_addr);
|
|
|
|
|
|
2014-02-20 03:16:17 +01:00
|
|
|
u64 time = get_time();
|
2013-06-30 10:46:29 +02:00
|
|
|
|
2014-02-20 03:16:17 +01:00
|
|
|
Memory.Write64(sec_addr, time / 10000000);
|
|
|
|
|
Memory.Write64(nsec_addr, (time % 10000000) * 100);
|
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()");
|
2014-02-16 16:23:58 +01:00
|
|
|
return get_system_time();
|
2012-11-15 00:39:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
u64 sys_time_get_timebase_frequency()
|
|
|
|
|
{
|
|
|
|
|
sys_time.Log("sys_time_get_timebase_frequency()");
|
2014-02-16 16:23:58 +01:00
|
|
|
return 10000000;
|
2013-11-19 11:30:58 +01:00
|
|
|
}
|