2012-12-05 23:47:39 +00:00
|
|
|
// Copyright (c) 2012- PPSSPP Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
2013-07-29 03:43:25 +00:00
|
|
|
#include "Common/CommonWindows.h"
|
2013-07-29 03:52:09 +00:00
|
|
|
#include <Winsock2.h>
|
2012-12-05 23:47:39 +00:00
|
|
|
#else
|
|
|
|
#include <sys/time.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <time.h>
|
|
|
|
#include "base/timeutil.h"
|
|
|
|
|
2013-05-20 00:54:14 +00:00
|
|
|
#include "Core/HLE/HLE.h"
|
|
|
|
#include "Core/MIPS/MIPS.h"
|
|
|
|
#include "Core/Reporting.h"
|
|
|
|
#include "Core/CoreTiming.h"
|
2012-12-05 23:47:39 +00:00
|
|
|
|
2013-05-20 00:54:14 +00:00
|
|
|
#include "Core/HLE/sceKernel.h"
|
|
|
|
#include "Core/HLE/sceRtc.h"
|
2012-12-05 23:47:39 +00:00
|
|
|
|
2013-05-05 17:12:29 +00:00
|
|
|
// This is a base time that everything is relative to.
|
|
|
|
// This way, time doesn't move strangely with savestates, turbo speed, etc.
|
2013-07-25 06:58:45 +00:00
|
|
|
static PSPTimeval rtcBaseTime;
|
2013-09-11 07:12:33 +00:00
|
|
|
static u64 rtcBaseTicks;
|
2013-05-05 17:12:29 +00:00
|
|
|
|
2012-12-05 23:47:39 +00:00
|
|
|
// Grabbed from JPSCP
|
2013-05-26 00:27:34 +00:00
|
|
|
// This is the # of microseconds between January 1, 0001 and January 1, 1970.
|
|
|
|
const u64 rtcMagicOffset = 62135596800000000ULL;
|
|
|
|
// This is the # of microseconds between January 1, 0001 and January 1, 1601 (for Win32 FILETIME.)
|
|
|
|
const u64 rtcFiletimeOffset = 50491123200000000ULL;
|
2012-12-05 23:47:39 +00:00
|
|
|
|
2013-12-13 23:07:53 +00:00
|
|
|
// 400 years is a convenient number, since leap days and everything cycle every 400 years.
|
|
|
|
// 400 years is in other words 20871 full weeks.
|
|
|
|
const u64 rtc400YearTicks = (u64)20871 * 7 * 24 * 3600 * 1000000ULL;
|
|
|
|
|
2012-12-05 23:47:39 +00:00
|
|
|
const int PSP_TIME_INVALID_YEAR = -1;
|
|
|
|
const int PSP_TIME_INVALID_MONTH = -2;
|
|
|
|
const int PSP_TIME_INVALID_DAY = -3;
|
|
|
|
const int PSP_TIME_INVALID_HOUR = -4;
|
|
|
|
const int PSP_TIME_INVALID_MINUTES = -5;
|
|
|
|
const int PSP_TIME_INVALID_SECONDS = -6;
|
|
|
|
const int PSP_TIME_INVALID_MICROSECONDS = -7;
|
|
|
|
|
|
|
|
u64 __RtcGetCurrentTick()
|
|
|
|
{
|
|
|
|
// TODO: It's probably expecting ticks since January 1, 0001?
|
2013-10-24 08:10:09 +00:00
|
|
|
return CoreTiming::GetGlobalTimeUs() + rtcBaseTicks;
|
2012-12-05 23:47:39 +00:00
|
|
|
}
|
|
|
|
|
2013-01-25 16:32:30 +00:00
|
|
|
#if defined(_WIN32)
|
2013-05-26 00:27:34 +00:00
|
|
|
#define FILETIME_FROM_UNIX_EPOCH_US (rtcMagicOffset - rtcFiletimeOffset)
|
2012-12-05 23:47:39 +00:00
|
|
|
|
|
|
|
void gettimeofday(timeval *tv, void *ignore)
|
|
|
|
{
|
|
|
|
FILETIME ft_utc, ft_local;
|
|
|
|
GetSystemTimeAsFileTime(&ft_utc);
|
|
|
|
ft_local = ft_utc;
|
|
|
|
|
|
|
|
u64 from_1601_us = (((u64) ft_local.dwHighDateTime << 32ULL) + (u64) ft_local.dwLowDateTime) / 10ULL;
|
|
|
|
u64 from_1970_us = from_1601_us - FILETIME_FROM_UNIX_EPOCH_US;
|
|
|
|
|
|
|
|
tv->tv_sec = long(from_1970_us / 1000000UL);
|
|
|
|
tv->tv_usec = from_1970_us % 1000000UL;
|
|
|
|
}
|
2013-01-25 16:32:30 +00:00
|
|
|
|
|
|
|
time_t rtc_timegm(struct tm *tm)
|
|
|
|
{
|
2013-09-09 15:50:49 +00:00
|
|
|
return _mkgmtime(tm);
|
2013-01-25 16:32:30 +00:00
|
|
|
}
|
|
|
|
|
2013-10-25 07:42:27 +00:00
|
|
|
#elif (defined(__GLIBC__) && !defined(ANDROID)) || defined(BLACKBERRY) || defined(__SYMBIAN32__)
|
2013-01-25 16:32:30 +00:00
|
|
|
#define rtc_timegm timegm
|
|
|
|
#else
|
|
|
|
|
|
|
|
time_t rtc_timegm(struct tm *tm)
|
|
|
|
{
|
|
|
|
time_t ret;
|
|
|
|
char *tz;
|
|
|
|
std::string tzcopy;
|
|
|
|
|
|
|
|
tz = getenv("TZ");
|
|
|
|
if (tz)
|
|
|
|
tzcopy = tz;
|
|
|
|
|
|
|
|
setenv("TZ", "", 1);
|
|
|
|
tzset();
|
|
|
|
ret = mktime(tm);
|
|
|
|
if (tz)
|
|
|
|
setenv("TZ", tzcopy.c_str(), 1);
|
|
|
|
else
|
|
|
|
unsetenv("TZ");
|
|
|
|
tzset();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-12-05 23:47:39 +00:00
|
|
|
#endif
|
|
|
|
|
2013-05-05 17:12:29 +00:00
|
|
|
void __RtcInit()
|
|
|
|
{
|
|
|
|
// This is the base time, the only case we use gettimeofday() for.
|
|
|
|
// Everything else is relative to that, "virtual time."
|
2013-07-25 06:58:45 +00:00
|
|
|
timeval tv;
|
|
|
|
gettimeofday(&tv, NULL);
|
|
|
|
rtcBaseTime.tv_sec = tv.tv_sec;
|
|
|
|
rtcBaseTime.tv_usec = tv.tv_usec;
|
2013-09-11 07:12:33 +00:00
|
|
|
// Precalculate the current time in microseconds (rtcMagicOffset is offset to 1970.)
|
2013-09-11 07:15:49 +00:00
|
|
|
rtcBaseTicks = 1000000ULL * rtcBaseTime.tv_sec + rtcBaseTime.tv_usec + rtcMagicOffset;
|
2013-05-05 17:12:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void __RtcDoState(PointerWrap &p)
|
|
|
|
{
|
2013-09-15 03:23:03 +00:00
|
|
|
auto s = p.Section("sceRtc", 1);
|
|
|
|
if (!s)
|
|
|
|
return;
|
|
|
|
|
2013-05-05 17:12:29 +00:00
|
|
|
p.Do(rtcBaseTime);
|
2013-09-11 07:12:33 +00:00
|
|
|
// Update the precalc, pointless to savestate this as it's just based on the other value.
|
2013-09-11 07:15:49 +00:00
|
|
|
rtcBaseTicks = 1000000ULL * rtcBaseTime.tv_sec + rtcBaseTime.tv_usec + rtcMagicOffset;
|
2013-05-05 17:12:29 +00:00
|
|
|
}
|
|
|
|
|
2013-07-25 06:58:45 +00:00
|
|
|
void __RtcTimeOfDay(PSPTimeval *tv)
|
2013-05-05 17:12:29 +00:00
|
|
|
{
|
2013-10-24 08:10:09 +00:00
|
|
|
s64 additionalUs = CoreTiming::GetGlobalTimeUs();
|
2013-05-05 17:12:29 +00:00
|
|
|
*tv = rtcBaseTime;
|
|
|
|
|
|
|
|
s64 adjustedUs = additionalUs + tv->tv_usec;
|
|
|
|
tv->tv_sec += long(adjustedUs / 1000000UL);
|
|
|
|
tv->tv_usec = adjustedUs % 1000000UL;
|
|
|
|
}
|
|
|
|
|
2012-12-05 23:47:39 +00:00
|
|
|
void __RtcTmToPspTime(ScePspDateTime &t, tm *val)
|
|
|
|
{
|
|
|
|
t.year = val->tm_year + 1900;
|
|
|
|
t.month = val->tm_mon + 1;
|
|
|
|
t.day = val->tm_mday;
|
|
|
|
t.hour = val->tm_hour;
|
|
|
|
t.minute = val->tm_min;
|
|
|
|
t.second = val->tm_sec;
|
2013-01-23 00:25:32 +00:00
|
|
|
t.microsecond = 0;
|
2012-12-05 23:47:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void __RtcTicksToPspTime(ScePspDateTime &t, u64 ticks)
|
|
|
|
{
|
2013-01-25 00:40:38 +00:00
|
|
|
int numYearAdd = 0;
|
2013-12-13 23:07:53 +00:00
|
|
|
if (ticks < 1000000ULL)
|
2012-12-05 23:47:39 +00:00
|
|
|
{
|
2013-01-25 00:40:38 +00:00
|
|
|
t.year = 1;
|
|
|
|
t.month = 1;
|
|
|
|
t.day = 1;
|
|
|
|
t.hour = 0;
|
|
|
|
t.minute = 0;
|
|
|
|
t.second = 0;
|
|
|
|
t.microsecond = ticks % 1000000ULL;
|
|
|
|
return;
|
2012-12-05 23:47:39 +00:00
|
|
|
}
|
2013-12-13 23:07:53 +00:00
|
|
|
else if (ticks < rtcMagicOffset)
|
2012-12-05 23:47:39 +00:00
|
|
|
{
|
2013-01-25 00:40:38 +00:00
|
|
|
// Need to get a year past 1970 for gmtime
|
|
|
|
// Add enough 400 year to pass over 1970.
|
2013-12-13 23:07:53 +00:00
|
|
|
numYearAdd = (int) ((rtcMagicOffset - ticks) / rtc400YearTicks + 1);
|
|
|
|
ticks += rtc400YearTicks * numYearAdd;
|
|
|
|
}
|
2012-12-05 23:47:39 +00:00
|
|
|
|
2013-12-13 23:07:53 +00:00
|
|
|
while (ticks >= rtcMagicOffset + rtc400YearTicks)
|
|
|
|
{
|
|
|
|
ticks -= rtc400YearTicks;
|
|
|
|
--numYearAdd;
|
2012-12-05 23:47:39 +00:00
|
|
|
}
|
|
|
|
|
2013-01-25 00:40:38 +00:00
|
|
|
time_t time = (ticks - rtcMagicOffset) / 1000000ULL;
|
|
|
|
t.microsecond = ticks % 1000000ULL;
|
2012-12-05 23:47:39 +00:00
|
|
|
|
2013-01-25 16:34:04 +00:00
|
|
|
tm *local = gmtime(&time);
|
|
|
|
if (!local)
|
|
|
|
{
|
2013-09-07 20:02:55 +00:00
|
|
|
ERROR_LOG(SCERTC, "Date is too high/low to handle, pretending to work.");
|
2013-01-25 16:34:04 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-12-05 23:47:39 +00:00
|
|
|
|
2013-01-25 00:40:38 +00:00
|
|
|
t.year = local->tm_year + 1900 - numYearAdd * 400;
|
|
|
|
t.month = local->tm_mon + 1;
|
|
|
|
t.day = local->tm_mday;
|
|
|
|
t.hour = local->tm_hour;
|
|
|
|
t.minute = local->tm_min;
|
|
|
|
t.second = local->tm_sec;
|
2012-12-05 23:47:39 +00:00
|
|
|
}
|
|
|
|
|
2013-01-25 00:40:38 +00:00
|
|
|
u64 __RtcPspTimeToTicks(ScePspDateTime &pt)
|
2012-12-05 23:47:39 +00:00
|
|
|
{
|
2013-01-25 00:40:38 +00:00
|
|
|
tm local;
|
|
|
|
local.tm_year = pt.year - 1900;
|
|
|
|
local.tm_mon = pt.month - 1;
|
|
|
|
local.tm_mday = pt.day;
|
|
|
|
local.tm_wday = -1;
|
|
|
|
local.tm_yday = -1;
|
|
|
|
local.tm_hour = pt.hour;
|
|
|
|
local.tm_min = pt.minute;
|
|
|
|
local.tm_sec = pt.second;
|
|
|
|
local.tm_isdst = 0;
|
2012-12-05 23:47:39 +00:00
|
|
|
|
2013-12-13 23:07:53 +00:00
|
|
|
s64 tickOffset = 0;
|
|
|
|
while (local.tm_year < 70)
|
|
|
|
{
|
|
|
|
tickOffset -= rtc400YearTicks;
|
|
|
|
local.tm_year += 400;
|
|
|
|
}
|
|
|
|
while (local.tm_year >= 470)
|
|
|
|
{
|
|
|
|
tickOffset += rtc400YearTicks;
|
|
|
|
local.tm_year -= 400;
|
|
|
|
}
|
|
|
|
|
2013-01-25 16:32:30 +00:00
|
|
|
time_t seconds = rtc_timegm(&local);
|
2013-01-25 00:40:38 +00:00
|
|
|
u64 result = rtcMagicOffset + (u64) seconds * 1000000ULL;
|
|
|
|
result += pt.microsecond;
|
2013-12-13 23:07:53 +00:00
|
|
|
return result + tickOffset;
|
2012-12-05 23:47:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool __RtcValidatePspTime(ScePspDateTime &t)
|
|
|
|
{
|
2013-01-25 00:40:38 +00:00
|
|
|
return t.year > 0 && t.year <= 9999;
|
2012-12-05 23:47:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
u32 sceRtcGetTickResolution()
|
|
|
|
{
|
2013-09-07 20:02:55 +00:00
|
|
|
DEBUG_LOG(SCERTC, "sceRtcGetTickResolution()");
|
2012-12-05 23:47:39 +00:00
|
|
|
return 1000000;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 sceRtcGetCurrentTick(u32 tickPtr)
|
|
|
|
{
|
2013-11-28 08:30:04 +00:00
|
|
|
VERBOSE_LOG(SCERTC, "sceRtcGetCurrentTick(%08x)", tickPtr);
|
2012-12-05 23:47:39 +00:00
|
|
|
|
|
|
|
u64 curTick = __RtcGetCurrentTick();
|
|
|
|
if (Memory::IsValidAddress(tickPtr))
|
|
|
|
Memory::Write_U64(curTick, tickPtr);
|
2013-05-05 06:35:46 +00:00
|
|
|
hleEatCycles(300);
|
2013-11-28 08:30:04 +00:00
|
|
|
hleReSchedule("rtc current tick");
|
2012-12-05 23:47:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-11-28 08:30:04 +00:00
|
|
|
u64 sceRtcGetAccumulativeTime()
|
2012-12-05 23:47:39 +00:00
|
|
|
{
|
2013-11-28 08:30:04 +00:00
|
|
|
DEBUG_LOG(SCERTC, "sceRtcGetAccumulativeTime()");
|
|
|
|
hleEatCycles(300);
|
|
|
|
hleReSchedule("rtc accumulative time");
|
2012-12-05 23:47:39 +00:00
|
|
|
return __RtcGetCurrentTick();
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 sceRtcGetCurrentClock(u32 pspTimePtr, int tz)
|
|
|
|
{
|
2013-09-07 20:02:55 +00:00
|
|
|
DEBUG_LOG(SCERTC, "sceRtcGetCurrentClock(%08x, %d)", pspTimePtr, tz);
|
2013-07-25 06:58:45 +00:00
|
|
|
PSPTimeval tv;
|
2013-05-05 17:12:29 +00:00
|
|
|
__RtcTimeOfDay(&tv);
|
2012-12-05 23:47:39 +00:00
|
|
|
|
|
|
|
time_t sec = (time_t) tv.tv_sec;
|
|
|
|
tm *utc = gmtime(&sec);
|
2012-11-24 17:39:30 +00:00
|
|
|
if (!utc)
|
|
|
|
{
|
2013-09-07 20:02:55 +00:00
|
|
|
ERROR_LOG(SCERTC, "Date is too high/low to handle, pretending to work.");
|
2012-11-24 17:39:30 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2012-12-05 23:47:39 +00:00
|
|
|
|
|
|
|
utc->tm_isdst = -1;
|
|
|
|
utc->tm_min += tz;
|
2013-01-25 16:32:30 +00:00
|
|
|
rtc_timegm(utc); // Return gmt time with timezone offset.
|
2012-12-05 23:47:39 +00:00
|
|
|
|
|
|
|
ScePspDateTime ret;
|
|
|
|
__RtcTmToPspTime(ret, utc);
|
|
|
|
ret.microsecond = tv.tv_usec;
|
|
|
|
|
|
|
|
if (Memory::IsValidAddress(pspTimePtr))
|
|
|
|
Memory::WriteStruct(pspTimePtr, &ret);
|
|
|
|
|
2013-05-05 06:35:46 +00:00
|
|
|
hleEatCycles(1900);
|
2013-11-28 08:30:04 +00:00
|
|
|
hleReSchedule("rtc current clock");
|
2012-12-05 23:47:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 sceRtcGetCurrentClockLocalTime(u32 pspTimePtr)
|
|
|
|
{
|
2013-09-07 20:02:55 +00:00
|
|
|
DEBUG_LOG(SCERTC, "sceRtcGetCurrentClockLocalTime(%08x)", pspTimePtr);
|
2013-07-25 06:58:45 +00:00
|
|
|
PSPTimeval tv;
|
2013-05-05 17:12:29 +00:00
|
|
|
__RtcTimeOfDay(&tv);
|
2012-12-05 23:47:39 +00:00
|
|
|
|
|
|
|
time_t sec = (time_t) tv.tv_sec;
|
|
|
|
tm *local = localtime(&sec);
|
2012-11-24 17:39:30 +00:00
|
|
|
if (!local)
|
|
|
|
{
|
2013-09-07 20:02:55 +00:00
|
|
|
ERROR_LOG(SCERTC, "Date is too high/low to handle, pretending to work.");
|
2012-11-24 17:39:30 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2012-12-05 23:47:39 +00:00
|
|
|
|
|
|
|
ScePspDateTime ret;
|
|
|
|
__RtcTmToPspTime(ret, local);
|
|
|
|
ret.microsecond = tv.tv_usec;
|
|
|
|
|
|
|
|
if (Memory::IsValidAddress(pspTimePtr))
|
|
|
|
Memory::WriteStruct(pspTimePtr, &ret);
|
|
|
|
|
2013-05-05 06:35:46 +00:00
|
|
|
hleEatCycles(2000);
|
2013-11-28 08:30:04 +00:00
|
|
|
hleReSchedule("rtc current clock local");
|
2012-12-05 23:47:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 sceRtcSetTick(u32 pspTimePtr, u32 tickPtr)
|
|
|
|
{
|
2013-09-07 20:02:55 +00:00
|
|
|
DEBUG_LOG(SCERTC, "sceRtcSetTick(%08x, %08x)", pspTimePtr, tickPtr);
|
2012-12-05 23:47:39 +00:00
|
|
|
if (Memory::IsValidAddress(pspTimePtr) && Memory::IsValidAddress(tickPtr))
|
|
|
|
{
|
|
|
|
u64 ticks = Memory::Read_U64(tickPtr);
|
|
|
|
|
|
|
|
ScePspDateTime ret;
|
|
|
|
__RtcTicksToPspTime(ret, ticks);
|
|
|
|
Memory::WriteStruct(pspTimePtr, &ret);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 sceRtcGetTick(u32 pspTimePtr, u32 tickPtr)
|
|
|
|
{
|
2013-09-07 20:02:55 +00:00
|
|
|
DEBUG_LOG(SCERTC, "sceRtcGetTick(%08x, %08x)", pspTimePtr, tickPtr);
|
2012-12-05 23:47:39 +00:00
|
|
|
ScePspDateTime pt;
|
|
|
|
|
|
|
|
if (Memory::IsValidAddress(pspTimePtr) && Memory::IsValidAddress(tickPtr))
|
|
|
|
{
|
|
|
|
Memory::ReadStruct(pspTimePtr, &pt);
|
|
|
|
|
|
|
|
if (!__RtcValidatePspTime(pt))
|
|
|
|
return SCE_KERNEL_ERROR_INVALID_VALUE;
|
|
|
|
|
2013-01-25 00:40:38 +00:00
|
|
|
u64 result = __RtcPspTimeToTicks(pt);
|
2012-12-05 23:47:39 +00:00
|
|
|
|
|
|
|
Memory::Write_U64(result, tickPtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 sceRtcGetDayOfWeek(u32 year, u32 month, u32 day)
|
|
|
|
{
|
2013-09-07 20:02:55 +00:00
|
|
|
DEBUG_LOG(SCERTC, "sceRtcGetDayOfWeek(%d, %d, %d)", year, month, day);
|
2013-01-22 07:55:01 +00:00
|
|
|
|
|
|
|
if(month == 0) // Mark month 0 as august, don't know why, but works
|
|
|
|
{
|
|
|
|
month = 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(month > 12) // After month 12, psp months does 31/31/30/31/30 and repeat
|
|
|
|
{
|
|
|
|
int restMonth = month-12;
|
|
|
|
int grp5 = restMonth / 5;
|
|
|
|
restMonth = restMonth % 5;
|
|
|
|
day += grp5 * (31*3+30*2);
|
|
|
|
static u32 t[] = { 31, 31*2, 31*2+30, 31*3+30, 31*3+30*2 };
|
|
|
|
day += t[restMonth-1];
|
|
|
|
month = 12;
|
2012-12-05 23:47:39 +00:00
|
|
|
}
|
2013-01-22 07:55:01 +00:00
|
|
|
|
|
|
|
tm local;
|
|
|
|
local.tm_year = year - 1900;
|
|
|
|
local.tm_mon = month - 1;
|
|
|
|
local.tm_mday = day;
|
|
|
|
local.tm_wday = -1;
|
|
|
|
local.tm_yday = -1;
|
|
|
|
local.tm_hour = 0;
|
|
|
|
local.tm_min = 0;
|
|
|
|
local.tm_sec = 0;
|
|
|
|
local.tm_isdst = -1;
|
|
|
|
|
|
|
|
mktime(&local);
|
|
|
|
return local.tm_wday;
|
2012-12-05 23:47:39 +00:00
|
|
|
}
|
|
|
|
|
2013-12-13 23:10:35 +00:00
|
|
|
bool __RtcIsLeapYear(u32 year)
|
2012-12-05 23:47:39 +00:00
|
|
|
{
|
2013-12-13 23:10:35 +00:00
|
|
|
return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
|
|
|
|
}
|
2012-12-05 23:47:39 +00:00
|
|
|
|
2013-12-13 23:10:35 +00:00
|
|
|
int __RtcDaysInMonth(u32 year, u32 month)
|
|
|
|
{
|
2012-12-05 23:47:39 +00:00
|
|
|
switch (month)
|
|
|
|
{
|
|
|
|
case 4:
|
|
|
|
case 6:
|
|
|
|
case 9:
|
|
|
|
case 11:
|
2013-12-13 23:10:35 +00:00
|
|
|
return 30;
|
|
|
|
|
2012-12-05 23:47:39 +00:00
|
|
|
case 2:
|
2013-12-13 23:10:35 +00:00
|
|
|
if (__RtcIsLeapYear(year))
|
|
|
|
return 29;
|
|
|
|
return 28;
|
2012-12-05 23:47:39 +00:00
|
|
|
|
|
|
|
default:
|
2013-12-13 23:10:35 +00:00
|
|
|
return 31;
|
2012-12-05 23:47:39 +00:00
|
|
|
}
|
2013-12-13 23:10:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
u32 sceRtcGetDaysInMonth(u32 year, u32 month)
|
|
|
|
{
|
|
|
|
DEBUG_LOG(SCERTC, "sceRtcGetDaysInMonth(%d, %d)", year, month);
|
|
|
|
|
|
|
|
if (year == 0 || month == 0 || month > 12)
|
|
|
|
return SCE_KERNEL_ERROR_INVALID_ARGUMENT;
|
2012-12-05 23:47:39 +00:00
|
|
|
|
2013-12-13 23:10:35 +00:00
|
|
|
return __RtcDaysInMonth(year, month);
|
2012-12-05 23:47:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
u32 sceRtcIsLeapYear(u32 year)
|
|
|
|
{
|
2013-09-07 20:02:55 +00:00
|
|
|
DEBUG_LOG(SCERTC, "sceRtcIsLeapYear(%d)", year);
|
2013-12-13 23:10:35 +00:00
|
|
|
return __RtcIsLeapYear(year) ? 1 : 0;
|
2012-12-05 23:47:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int sceRtcConvertLocalTimeToUTC(u32 tickLocalPtr,u32 tickUTCPtr)
|
|
|
|
{
|
2013-09-07 20:02:55 +00:00
|
|
|
DEBUG_LOG(SCERTC, "sceRtcConvertLocalTimeToUTC(%d, %d)", tickLocalPtr, tickUTCPtr);
|
2012-12-05 23:47:39 +00:00
|
|
|
if (Memory::IsValidAddress(tickLocalPtr) && Memory::IsValidAddress(tickUTCPtr))
|
|
|
|
{
|
|
|
|
u64 srcTick = Memory::Read_U64(tickLocalPtr);
|
2013-01-25 00:40:38 +00:00
|
|
|
// TODO : Let the user select his timezone / daylight saving instead of taking system param ?
|
2013-10-25 07:42:27 +00:00
|
|
|
#if defined(__GLIBC__) || defined(BLACKBERRY) || defined(__SYMBIAN32__)
|
2013-01-25 00:40:38 +00:00
|
|
|
time_t timezone = 0;
|
|
|
|
tm *time = localtime(&timezone);
|
|
|
|
srcTick -= time->tm_gmtoff*1000000ULL;
|
2013-01-25 16:32:30 +00:00
|
|
|
#else
|
|
|
|
srcTick -= -timezone * 1000000ULL;
|
|
|
|
#endif
|
2012-12-05 23:47:39 +00:00
|
|
|
Memory::Write_U64(srcTick, tickUTCPtr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int sceRtcConvertUtcToLocalTime(u32 tickUTCPtr,u32 tickLocalPtr)
|
|
|
|
{
|
2013-09-07 20:02:55 +00:00
|
|
|
DEBUG_LOG(SCERTC, "sceRtcConvertLocalTimeToUTC(%d, %d)", tickLocalPtr, tickUTCPtr);
|
2012-12-05 23:47:39 +00:00
|
|
|
if (Memory::IsValidAddress(tickLocalPtr) && Memory::IsValidAddress(tickUTCPtr))
|
|
|
|
{
|
|
|
|
u64 srcTick = Memory::Read_U64(tickUTCPtr);
|
2013-01-25 00:40:38 +00:00
|
|
|
// TODO : Let the user select his timezone / daylight saving instead of taking system param ?
|
2013-10-25 07:42:27 +00:00
|
|
|
#if defined(__GLIBC__) || defined(BLACKBERRY) || defined(__SYMBIAN32__)
|
2013-01-25 00:40:38 +00:00
|
|
|
time_t timezone = 0;
|
|
|
|
tm *time = localtime(&timezone);
|
|
|
|
srcTick += time->tm_gmtoff*1000000ULL;
|
2013-01-25 16:32:30 +00:00
|
|
|
#else
|
|
|
|
srcTick += -timezone * 1000000ULL;
|
|
|
|
#endif
|
2012-12-05 23:47:39 +00:00
|
|
|
Memory::Write_U64(srcTick, tickLocalPtr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int sceRtcCheckValid(u32 datePtr)
|
|
|
|
{
|
2013-09-07 20:02:55 +00:00
|
|
|
DEBUG_LOG(SCERTC, "sceRtcCheckValid(%d)", datePtr);
|
2012-12-05 23:47:39 +00:00
|
|
|
|
|
|
|
if (Memory::IsValidAddress(datePtr))
|
|
|
|
{
|
|
|
|
ScePspDateTime pt;
|
|
|
|
Memory::ReadStruct(datePtr, &pt);
|
2012-12-15 06:06:13 +00:00
|
|
|
if (pt.year < 1 || pt.year > 9999)
|
2012-12-16 19:26:18 +00:00
|
|
|
{
|
2012-12-15 06:06:13 +00:00
|
|
|
return PSP_TIME_INVALID_YEAR;
|
|
|
|
}
|
|
|
|
else if (pt.month < 1 || pt.month > 12)
|
|
|
|
{
|
|
|
|
return PSP_TIME_INVALID_MONTH;
|
|
|
|
}
|
|
|
|
else if (pt.day < 1 || pt.day > 31)
|
2012-12-05 23:47:39 +00:00
|
|
|
{
|
2012-12-15 06:06:13 +00:00
|
|
|
return PSP_TIME_INVALID_DAY;
|
|
|
|
}
|
2013-12-13 23:10:35 +00:00
|
|
|
else if (pt.day > __RtcDaysInMonth((s16)pt.year, (s16)pt.month))
|
2012-12-05 23:47:39 +00:00
|
|
|
{
|
2012-12-15 06:06:13 +00:00
|
|
|
return PSP_TIME_INVALID_DAY;
|
|
|
|
}
|
2013-10-05 16:32:34 +00:00
|
|
|
else if (pt.hour < 0 || pt.hour > 23)
|
2012-12-05 23:47:39 +00:00
|
|
|
{
|
2012-12-15 06:06:13 +00:00
|
|
|
return PSP_TIME_INVALID_HOUR;
|
|
|
|
}
|
2013-10-05 16:32:34 +00:00
|
|
|
else if (pt.minute < 0 || pt.minute > 59)
|
2012-12-05 23:47:39 +00:00
|
|
|
{
|
2012-12-15 06:06:13 +00:00
|
|
|
return PSP_TIME_INVALID_MINUTES;
|
|
|
|
}
|
2013-10-05 16:32:34 +00:00
|
|
|
else if (pt.second < 0 || pt.second > 59)
|
2012-12-05 23:47:39 +00:00
|
|
|
{
|
2012-12-15 06:06:13 +00:00
|
|
|
return PSP_TIME_INVALID_SECONDS;
|
|
|
|
}
|
2013-07-29 03:28:32 +00:00
|
|
|
else if (pt.microsecond >= 1000000UL)
|
2012-12-05 23:47:39 +00:00
|
|
|
{
|
2012-12-15 06:06:13 +00:00
|
|
|
return PSP_TIME_INVALID_MICROSECONDS;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return 0;
|
|
|
|
}
|
2012-12-05 23:47:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-12-15 06:06:13 +00:00
|
|
|
return -1;
|
2012-12-05 23:47:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-05 23:48:20 +00:00
|
|
|
int sceRtcSetTime_t(u32 datePtr, u32 time)
|
2012-12-05 23:47:39 +00:00
|
|
|
{
|
2013-09-07 20:02:55 +00:00
|
|
|
DEBUG_LOG(SCERTC, "sceRtcSetTime_t(%08x,%d)", datePtr, time);
|
2012-12-05 23:47:39 +00:00
|
|
|
if (Memory::IsValidAddress(datePtr))
|
|
|
|
{
|
|
|
|
ScePspDateTime pt;
|
2013-01-25 00:40:38 +00:00
|
|
|
__RtcTicksToPspTime(pt, time*1000000ULL + rtcMagicOffset);
|
2012-12-05 23:47:39 +00:00
|
|
|
Memory::WriteStruct(datePtr, &pt);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-12 21:37:58 +00:00
|
|
|
int sceRtcSetTime64_t(u32 datePtr, u64 time)
|
|
|
|
{
|
2013-09-07 20:02:55 +00:00
|
|
|
DEBUG_LOG(SCERTC, "sceRtcSetTime64_t(%08x,%lld)", datePtr, time);
|
2012-12-12 21:37:58 +00:00
|
|
|
if (Memory::IsValidAddress(datePtr))
|
|
|
|
{
|
|
|
|
ScePspDateTime pt;
|
2013-01-25 00:40:38 +00:00
|
|
|
__RtcTicksToPspTime(pt, time*1000000ULL + rtcMagicOffset);
|
2012-12-12 21:37:58 +00:00
|
|
|
Memory::WriteStruct(datePtr, &pt);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-05 23:47:39 +00:00
|
|
|
int sceRtcGetTime_t(u32 datePtr, u32 timePtr)
|
|
|
|
{
|
2013-09-07 20:02:55 +00:00
|
|
|
DEBUG_LOG(SCERTC, "sceRtcGetTime_t(%08x,%08x)", datePtr, timePtr);
|
2012-12-05 23:47:39 +00:00
|
|
|
if (Memory::IsValidAddress(datePtr)&&Memory::IsValidAddress(timePtr))
|
|
|
|
{
|
|
|
|
ScePspDateTime pt;
|
|
|
|
Memory::ReadStruct(datePtr, &pt);
|
2013-01-25 00:40:38 +00:00
|
|
|
u32 result = (u32) ((__RtcPspTimeToTicks(pt)-rtcMagicOffset)/1000000ULL);
|
2012-12-08 21:01:37 +00:00
|
|
|
Memory::Write_U32(result, timePtr);
|
2012-12-05 23:47:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-12 21:15:11 +00:00
|
|
|
int sceRtcGetTime64_t(u32 datePtr, u32 timePtr)
|
|
|
|
{
|
2013-09-07 20:02:55 +00:00
|
|
|
DEBUG_LOG(SCERTC, "sceRtcGetTime64_t(%08x,%08x)", datePtr, timePtr);
|
2012-12-12 21:15:11 +00:00
|
|
|
if (Memory::IsValidAddress(datePtr)&&Memory::IsValidAddress(timePtr))
|
|
|
|
{
|
|
|
|
ScePspDateTime pt;
|
|
|
|
Memory::ReadStruct(datePtr, &pt);
|
2013-01-25 00:40:38 +00:00
|
|
|
u64 result = (__RtcPspTimeToTicks(pt)-rtcMagicOffset)/1000000ULL;
|
2012-12-12 21:15:11 +00:00
|
|
|
Memory::Write_U64(result, timePtr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-05 23:47:39 +00:00
|
|
|
int sceRtcSetDosTime(u32 datePtr, u32 dosTime)
|
|
|
|
{
|
2013-09-07 20:02:55 +00:00
|
|
|
DEBUG_LOG(SCERTC, "sceRtcSetDosTime(%d,%d)", datePtr, dosTime);
|
2012-12-05 23:47:39 +00:00
|
|
|
if (Memory::IsValidAddress(datePtr))
|
|
|
|
{
|
|
|
|
ScePspDateTime pt;
|
|
|
|
|
2013-01-23 00:25:32 +00:00
|
|
|
int hms = dosTime & 0xFFFF;
|
|
|
|
int ymd = dosTime >> 16;
|
|
|
|
|
|
|
|
pt.year = 1980 + (ymd >> 9);
|
|
|
|
pt.month = (ymd >> 5) & 0xF;
|
|
|
|
pt.day = ymd & 0x1F;
|
|
|
|
pt.hour = hms >> 11;
|
|
|
|
pt.minute = (hms >> 5) & 0x3F;
|
|
|
|
pt.second = (hms << 1) & 0x3E;
|
|
|
|
pt.microsecond = 0;
|
|
|
|
|
2012-12-05 23:47:39 +00:00
|
|
|
Memory::WriteStruct(datePtr, &pt);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int sceRtcGetDosTime(u32 datePtr, u32 dosTime)
|
|
|
|
{
|
2013-01-23 00:25:32 +00:00
|
|
|
int retValue = 0;
|
2013-09-07 20:02:55 +00:00
|
|
|
DEBUG_LOG(SCERTC, "sceRtcGetDosTime(%d,%d)", datePtr, dosTime);
|
2012-12-05 23:47:39 +00:00
|
|
|
if (Memory::IsValidAddress(datePtr)&&Memory::IsValidAddress(dosTime))
|
|
|
|
{
|
|
|
|
ScePspDateTime pt;
|
|
|
|
Memory::ReadStruct(datePtr, &pt);
|
2013-01-23 00:25:32 +00:00
|
|
|
|
|
|
|
u32 result = 0;
|
|
|
|
if(pt.year < 1980)
|
|
|
|
{
|
|
|
|
result = 0;
|
|
|
|
retValue = -1;
|
|
|
|
}
|
|
|
|
else if(pt.year >= 2108)
|
|
|
|
{
|
|
|
|
result = 0xFF9FBF7D;
|
|
|
|
retValue = -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int year = ((pt.year - 1980) & 0x7F) << 9;
|
|
|
|
int month = ((pt.month) & 0xF ) << 5;
|
|
|
|
int hour = ((pt.hour) & 0x1F ) << 11;
|
|
|
|
int minute = ((pt.minute) & 0x3F ) << 5;
|
|
|
|
int day = (pt.day) & 0x1F;
|
|
|
|
int second = ((pt.second) >> 1) & 0x1F;
|
|
|
|
int ymd = year | month | day;
|
|
|
|
int hms = hour | minute | second;
|
|
|
|
result = (ymd << 16) | hms;
|
|
|
|
retValue = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Memory::Write_U32(result, dosTime);
|
2012-12-05 23:47:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-01-23 00:25:32 +00:00
|
|
|
retValue = -1;
|
2012-12-05 23:47:39 +00:00
|
|
|
}
|
2013-01-23 00:25:32 +00:00
|
|
|
return retValue;
|
2012-12-05 23:47:39 +00:00
|
|
|
}
|
|
|
|
|
2013-05-26 00:27:34 +00:00
|
|
|
int sceRtcSetWin32FileTime(u32 datePtr, u64 win32Time)
|
2012-12-05 23:47:39 +00:00
|
|
|
{
|
2013-05-26 00:27:34 +00:00
|
|
|
if (!Memory::IsValidAddress(datePtr))
|
|
|
|
{
|
2013-09-07 20:02:55 +00:00
|
|
|
ERROR_LOG_REPORT(SCERTC, "sceRtcSetWin32FileTime(%08x, %lld): invalid address", datePtr, win32Time);
|
2013-05-26 00:27:34 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-09-07 20:02:55 +00:00
|
|
|
DEBUG_LOG(SCERTC, "sceRtcSetWin32FileTime(%08x, %lld)", datePtr, win32Time);
|
2013-05-26 00:27:34 +00:00
|
|
|
|
|
|
|
u64 ticks = (win32Time / 10) + rtcFiletimeOffset;
|
|
|
|
auto pspTime = Memory::GetStruct<ScePspDateTime>(datePtr);
|
|
|
|
__RtcTicksToPspTime(*pspTime, ticks);
|
2012-12-05 23:47:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int sceRtcGetWin32FileTime(u32 datePtr, u32 win32TimePtr)
|
|
|
|
{
|
2013-05-26 00:27:34 +00:00
|
|
|
if (!Memory::IsValidAddress(datePtr))
|
|
|
|
{
|
2013-09-07 20:02:55 +00:00
|
|
|
ERROR_LOG_REPORT(SCERTC, "sceRtcGetWin32FileTime(%08x, %08x): invalid address", datePtr, win32TimePtr);
|
2013-05-26 00:27:34 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-09-07 20:02:55 +00:00
|
|
|
DEBUG_LOG(SCERTC, "sceRtcGetWin32FileTime(%08x, %08x)", datePtr, win32TimePtr);
|
2013-05-26 00:27:34 +00:00
|
|
|
if (!Memory::IsValidAddress(win32TimePtr))
|
|
|
|
return SCE_KERNEL_ERROR_INVALID_VALUE;
|
|
|
|
|
|
|
|
auto pspTime = Memory::GetStruct<ScePspDateTime>(datePtr);
|
|
|
|
u64 result = __RtcPspTimeToTicks(*pspTime);
|
|
|
|
|
|
|
|
if (!__RtcValidatePspTime(*pspTime) || result < rtcFiletimeOffset)
|
|
|
|
{
|
|
|
|
Memory::Write_U64(0, win32TimePtr);
|
|
|
|
return SCE_KERNEL_ERROR_INVALID_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
Memory::Write_U64((result - rtcFiletimeOffset) * 10, win32TimePtr);
|
2012-12-05 23:47:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int sceRtcCompareTick(u32 tick1Ptr, u32 tick2Ptr)
|
|
|
|
{
|
2013-09-07 20:02:55 +00:00
|
|
|
DEBUG_LOG(SCERTC, "sceRtcCompareTick(%d,%d)", tick1Ptr, tick2Ptr);
|
2012-12-23 20:51:05 +00:00
|
|
|
if (Memory::IsValidAddress(tick1Ptr) && Memory::IsValidAddress(tick2Ptr))
|
2012-12-05 23:47:39 +00:00
|
|
|
{
|
|
|
|
u64 tick1 = Memory::Read_U64(tick1Ptr);
|
|
|
|
u64 tick2 = Memory::Read_U64(tick2Ptr);
|
2012-12-15 06:06:13 +00:00
|
|
|
if (tick1 > tick2)
|
2012-12-05 23:47:39 +00:00
|
|
|
return 1;
|
2012-12-15 06:06:13 +00:00
|
|
|
if (tick1 < tick2)
|
2012-12-05 23:47:39 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int sceRtcTickAddTicks(u32 destTickPtr, u32 srcTickPtr, u64 numTicks)
|
|
|
|
{
|
|
|
|
if (Memory::IsValidAddress(destTickPtr) && Memory::IsValidAddress(srcTickPtr))
|
|
|
|
{
|
|
|
|
u64 srcTick = Memory::Read_U64(srcTickPtr);
|
|
|
|
|
|
|
|
srcTick += numTicks;
|
|
|
|
Memory::Write_U64(srcTick, destTickPtr);
|
|
|
|
}
|
|
|
|
|
2013-09-07 20:02:55 +00:00
|
|
|
DEBUG_LOG(SCERTC, "sceRtcTickAddTicks(%x,%x,%llu)", destTickPtr, srcTickPtr, numTicks);
|
2012-12-05 23:47:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int sceRtcTickAddMicroseconds(u32 destTickPtr,u32 srcTickPtr, u64 numMS)
|
|
|
|
{
|
|
|
|
if (Memory::IsValidAddress(destTickPtr) && Memory::IsValidAddress(srcTickPtr))
|
|
|
|
{
|
|
|
|
s64 srcTick = (s64)Memory::Read_U64(srcTickPtr);
|
|
|
|
|
|
|
|
srcTick += numMS;
|
|
|
|
Memory::Write_U64(srcTick, destTickPtr);
|
|
|
|
}
|
|
|
|
|
2013-09-07 20:02:55 +00:00
|
|
|
DEBUG_LOG(SCERTC, "sceRtcTickAddMicroseconds(%x,%x,%llu)", destTickPtr, srcTickPtr, numMS);
|
2012-12-05 23:47:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int sceRtcTickAddSeconds(u32 destTickPtr, u32 srcTickPtr, u64 numSecs)
|
|
|
|
{
|
|
|
|
if (Memory::IsValidAddress(destTickPtr) && Memory::IsValidAddress(srcTickPtr))
|
|
|
|
{
|
|
|
|
s64 srcTick = (s64)Memory::Read_U64(srcTickPtr);
|
|
|
|
|
|
|
|
srcTick += numSecs * 1000000UL;
|
|
|
|
Memory::Write_U64(srcTick, destTickPtr);
|
|
|
|
}
|
2013-09-07 20:02:55 +00:00
|
|
|
DEBUG_LOG(SCERTC, "sceRtcTickAddSeconds(%x,%x,%llu)", destTickPtr, srcTickPtr, numSecs);
|
2012-12-05 23:47:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int sceRtcTickAddMinutes(u32 destTickPtr, u32 srcTickPtr, u64 numMins)
|
|
|
|
{
|
|
|
|
if (Memory::IsValidAddress(destTickPtr) && Memory::IsValidAddress(srcTickPtr))
|
|
|
|
{
|
|
|
|
s64 srcTick = (s64)Memory::Read_U64(srcTickPtr);
|
|
|
|
|
|
|
|
srcTick += numMins*60000000UL;
|
|
|
|
Memory::Write_U64(srcTick, destTickPtr);
|
|
|
|
}
|
2013-09-07 20:02:55 +00:00
|
|
|
DEBUG_LOG(SCERTC, "sceRtcTickAddMinutes(%x,%x,%llu)", destTickPtr, srcTickPtr, numMins);
|
2012-12-05 23:47:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int sceRtcTickAddHours(u32 destTickPtr, u32 srcTickPtr, int numHours)
|
|
|
|
{
|
|
|
|
if (Memory::IsValidAddress(destTickPtr) && Memory::IsValidAddress(srcTickPtr))
|
|
|
|
{
|
|
|
|
s64 srcTick = (s64)Memory::Read_U64(srcTickPtr);
|
|
|
|
srcTick += numHours*3600000000UL;
|
|
|
|
Memory::Write_U64(srcTick, destTickPtr);
|
|
|
|
}
|
2013-09-07 20:02:55 +00:00
|
|
|
DEBUG_LOG(SCERTC, "sceRtcTickAddMinutes(%d,%d,%d)", destTickPtr, srcTickPtr, numHours);
|
2012-12-05 23:47:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int sceRtcTickAddDays(u32 destTickPtr, u32 srcTickPtr, int numDays)
|
|
|
|
{
|
|
|
|
if (Memory::IsValidAddress(destTickPtr) && Memory::IsValidAddress(srcTickPtr))
|
|
|
|
{
|
|
|
|
s64 srcTick = (s64)Memory::Read_U64(srcTickPtr);
|
|
|
|
|
|
|
|
srcTick += numDays*86400000000UL;
|
|
|
|
Memory::Write_U64(srcTick, destTickPtr);
|
|
|
|
}
|
2013-09-07 20:02:55 +00:00
|
|
|
DEBUG_LOG(SCERTC, "sceRtcTickAddDays(%d,%d,%d)", destTickPtr, srcTickPtr, numDays);
|
2012-12-05 23:47:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int sceRtcTickAddWeeks(u32 destTickPtr, u32 srcTickPtr, int numWeeks)
|
|
|
|
{
|
|
|
|
if (Memory::IsValidAddress(destTickPtr) && Memory::IsValidAddress(srcTickPtr))
|
|
|
|
{
|
|
|
|
s64 srcTick = (s64)Memory::Read_U64(srcTickPtr);
|
|
|
|
|
|
|
|
srcTick += numWeeks*604800000000UL;
|
|
|
|
Memory::Write_U64(srcTick, destTickPtr);
|
|
|
|
}
|
2013-09-07 20:02:55 +00:00
|
|
|
DEBUG_LOG(SCERTC, "sceRtcTickAddWeeks(%d,%d,%d)", destTickPtr, srcTickPtr, numWeeks);
|
2012-12-05 23:47:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int sceRtcTickAddMonths(u32 destTickPtr, u32 srcTickPtr, int numMonths)
|
|
|
|
{
|
|
|
|
if (Memory::IsValidAddress(destTickPtr) && Memory::IsValidAddress(srcTickPtr))
|
|
|
|
{
|
|
|
|
u64 srcTick = Memory::Read_U64(srcTickPtr);
|
2012-12-15 06:06:13 +00:00
|
|
|
|
2012-12-05 23:47:39 +00:00
|
|
|
ScePspDateTime pt;
|
|
|
|
memset(&pt, 0, sizeof(pt));
|
2012-12-05 23:48:20 +00:00
|
|
|
|
2013-01-25 00:40:38 +00:00
|
|
|
__RtcTicksToPspTime(pt,srcTick);
|
|
|
|
if(((pt.year-1)*12+pt.month) + numMonths < 1 || ((pt.year-1)*12+pt.month) + numMonths > 9999*12)
|
|
|
|
{
|
|
|
|
srcTick = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(numMonths < 0)
|
2012-12-05 23:48:20 +00:00
|
|
|
{
|
2013-01-25 00:40:38 +00:00
|
|
|
pt.year += numMonths/12;
|
|
|
|
int restMonth = pt.month + numMonths%12;
|
|
|
|
if(restMonth < 1)
|
|
|
|
{
|
|
|
|
pt.month = 12+restMonth;
|
|
|
|
pt.year--;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pt.month = restMonth;
|
|
|
|
}
|
2012-12-05 23:48:20 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-01-25 00:40:38 +00:00
|
|
|
pt.year += numMonths/12;
|
|
|
|
pt.month += numMonths%12;
|
|
|
|
if(pt.month > 12)
|
|
|
|
{
|
|
|
|
pt.month -= 12;
|
|
|
|
pt.year++;
|
|
|
|
}
|
2012-12-05 23:48:20 +00:00
|
|
|
}
|
2013-01-25 00:40:38 +00:00
|
|
|
u64 yearTicks = __RtcPspTimeToTicks(pt);
|
|
|
|
srcTick =yearTicks;
|
2012-12-05 23:47:39 +00:00
|
|
|
}
|
|
|
|
Memory::Write_U64(srcTick, destTickPtr);
|
|
|
|
}
|
|
|
|
|
2013-09-07 20:02:55 +00:00
|
|
|
DEBUG_LOG(SCERTC, "sceRtcTickAddMonths(%d,%d,%d)", destTickPtr, srcTickPtr, numMonths);
|
2012-12-05 23:47:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int sceRtcTickAddYears(u32 destTickPtr, u32 srcTickPtr, int numYears)
|
|
|
|
{
|
|
|
|
if (Memory::IsValidAddress(destTickPtr) && Memory::IsValidAddress(srcTickPtr))
|
|
|
|
{
|
|
|
|
u64 srcTick = Memory::Read_U64(srcTickPtr);
|
|
|
|
|
|
|
|
ScePspDateTime pt;
|
|
|
|
memset(&pt, 0, sizeof(pt));
|
|
|
|
|
2013-01-25 00:40:38 +00:00
|
|
|
__RtcTicksToPspTime(pt,srcTick);
|
|
|
|
if(pt.year + numYears <= 0 || pt.year + numYears > 9999)
|
2012-12-05 23:47:39 +00:00
|
|
|
{
|
2013-01-25 00:40:38 +00:00
|
|
|
srcTick = 0;
|
2012-12-05 23:47:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-01-25 00:40:38 +00:00
|
|
|
pt.year += numYears;
|
2012-12-05 23:47:39 +00:00
|
|
|
u64 yearTicks = __RtcPspTimeToTicks(pt);
|
2013-01-25 00:40:38 +00:00
|
|
|
srcTick =yearTicks;
|
2012-12-05 23:47:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Memory::Write_U64(srcTick, destTickPtr);
|
|
|
|
}
|
|
|
|
|
2013-09-07 20:02:55 +00:00
|
|
|
DEBUG_LOG(SCERTC, "sceRtcTickAddYears(%d,%d,%d)", destTickPtr, srcTickPtr, numYears);
|
2012-12-05 23:47:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int sceRtcParseDateTime(u32 destTickPtr, u32 dateStringPtr)
|
|
|
|
{
|
2013-09-07 20:02:55 +00:00
|
|
|
ERROR_LOG_REPORT(SCERTC, "UNIMPL sceRtcParseDateTime(%d,%d)", destTickPtr, dateStringPtr);
|
2012-12-05 23:47:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-04-29 03:40:09 +00:00
|
|
|
int sceRtcGetLastAdjustedTime(u32 tickPtr)
|
|
|
|
{
|
|
|
|
u64 curTick = __RtcGetCurrentTick();
|
|
|
|
if (Memory::IsValidAddress(tickPtr))
|
|
|
|
Memory::Write_U64(curTick, tickPtr);
|
2013-09-07 20:02:55 +00:00
|
|
|
DEBUG_LOG(SCERTC, "sceRtcGetLastAdjustedTime(%d)", tickPtr);
|
2013-04-29 03:40:09 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-06-12 08:46:06 +00:00
|
|
|
//Returns 0 on success, according to Project Diva 2nd jpcsptrace log
|
|
|
|
int sceRtcSetAlarmTick(u32 unknown1, u32 unknown2)
|
|
|
|
{
|
2013-09-07 20:02:55 +00:00
|
|
|
ERROR_LOG(SCERTC, "UNIMPL sceRtcSetAlarmTick(%x, %x)", unknown1, unknown2);
|
2013-06-12 08:46:06 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-15 06:06:13 +00:00
|
|
|
const HLEFunction sceRtc[] =
|
2012-12-05 23:47:39 +00:00
|
|
|
{
|
2013-04-29 05:32:36 +00:00
|
|
|
{0xC41C2853, &WrapU_V<sceRtcGetTickResolution>, "sceRtcGetTickResolution"},
|
|
|
|
{0x3f7ad767, &WrapU_U<sceRtcGetCurrentTick>, "sceRtcGetCurrentTick"},
|
2013-11-28 08:30:04 +00:00
|
|
|
{0x011F03C1, &WrapU64_V<sceRtcGetAccumulativeTime>, "sceRtcGetAccumulativeTime"},
|
|
|
|
{0x029CA3B3, &WrapU64_V<sceRtcGetAccumulativeTime>, "sceRtcGetAccumlativeTime"},
|
2013-04-29 05:32:36 +00:00
|
|
|
{0x4cfa57b0, &WrapU_UI<sceRtcGetCurrentClock>, "sceRtcGetCurrentClock"},
|
|
|
|
{0xE7C27D1B, &WrapU_U<sceRtcGetCurrentClockLocalTime>, "sceRtcGetCurrentClockLocalTime"},
|
|
|
|
{0x34885E0D, &WrapI_UU<sceRtcConvertUtcToLocalTime>, "sceRtcConvertUtcToLocalTime"},
|
|
|
|
{0x779242A2, &WrapI_UU<sceRtcConvertLocalTimeToUTC>, "sceRtcConvertLocalTimeToUTC"},
|
|
|
|
{0x42307A17, &WrapU_U<sceRtcIsLeapYear>, "sceRtcIsLeapYear"},
|
|
|
|
{0x05ef322c, &WrapU_UU<sceRtcGetDaysInMonth>, "sceRtcGetDaysInMonth"},
|
|
|
|
{0x57726bc1, &WrapU_UUU<sceRtcGetDayOfWeek>, "sceRtcGetDayOfWeek"},
|
|
|
|
{0x4B1B5E82, &WrapI_U<sceRtcCheckValid>, "sceRtcCheckValid"},
|
|
|
|
{0x3a807cc8, &WrapI_UU<sceRtcSetTime_t>, "sceRtcSetTime_t"},
|
|
|
|
{0x27c4594c, &WrapI_UU<sceRtcGetTime_t>, "sceRtcGetTime_t"},
|
|
|
|
{0xF006F264, &WrapI_UU<sceRtcSetDosTime>, "sceRtcSetDosTime"},
|
|
|
|
{0x36075567, &WrapI_UU<sceRtcGetDosTime>, "sceRtcGetDosTime"},
|
2013-05-26 00:27:34 +00:00
|
|
|
{0x7ACE4C04, &WrapI_UU64<sceRtcSetWin32FileTime>, "sceRtcSetWin32FileTime"},
|
2013-04-29 05:32:36 +00:00
|
|
|
{0xCF561893, &WrapI_UU<sceRtcGetWin32FileTime>, "sceRtcGetWin32FileTime"},
|
|
|
|
{0x7ED29E40, &WrapU_UU<sceRtcSetTick>, "sceRtcSetTick"},
|
|
|
|
{0x6FF40ACC, &WrapU_UU<sceRtcGetTick>, "sceRtcGetTick"},
|
|
|
|
{0x9ED0AE87, &WrapI_UU<sceRtcCompareTick>, "sceRtcCompareTick"},
|
|
|
|
{0x44F45E05, &WrapI_UUU64<sceRtcTickAddTicks>, "sceRtcTickAddTicks"},
|
|
|
|
{0x26D25A5D, &WrapI_UUU64<sceRtcTickAddMicroseconds>, "sceRtcTickAddMicroseconds"},
|
|
|
|
{0xF2A4AFE5, &WrapI_UUU64<sceRtcTickAddSeconds>, "sceRtcTickAddSeconds"},
|
|
|
|
{0xE6605BCA, &WrapI_UUU64<sceRtcTickAddMinutes>, "sceRtcTickAddMinutes"},
|
|
|
|
{0x26D7A24A, &WrapI_UUI<sceRtcTickAddHours>, "sceRtcTickAddHours"},
|
|
|
|
{0xE51B4B7A, &WrapI_UUI<sceRtcTickAddDays>, "sceRtcTickAddDays"},
|
|
|
|
{0xCF3A2CA8, &WrapI_UUI<sceRtcTickAddWeeks>, "sceRtcTickAddWeeks"},
|
|
|
|
{0xDBF74F1B, &WrapI_UUI<sceRtcTickAddMonths>, "sceRtcTickAddMonths"},
|
|
|
|
{0x42842C77, &WrapI_UUI<sceRtcTickAddYears>, "sceRtcTickAddYears"},
|
2012-12-05 23:47:39 +00:00
|
|
|
{0xC663B3B9, 0, "sceRtcFormatRFC2822"},
|
|
|
|
{0x7DE6711B, 0, "sceRtcFormatRFC2822LocalTime"},
|
|
|
|
{0x0498FB3C, 0, "sceRtcFormatRFC3339"},
|
|
|
|
{0x27F98543, 0, "sceRtcFormatRFC3339LocalTime"},
|
2013-04-29 05:32:36 +00:00
|
|
|
{0xDFBC5F16, &WrapI_UU<sceRtcParseDateTime>, "sceRtcParseDateTime"},
|
2012-12-05 23:47:39 +00:00
|
|
|
{0x28E1E988, 0, "sceRtcParseRFC3339"},
|
2013-04-29 05:32:36 +00:00
|
|
|
{0xe1c93e47, &WrapI_UU<sceRtcGetTime64_t>, "sceRtcGetTime64_t"},
|
|
|
|
{0x1909c99b, &WrapI_UU64<sceRtcSetTime64_t>, "sceRtcSetTime64_t"},
|
|
|
|
{0x62685E98, &WrapI_U<sceRtcGetLastAdjustedTime>, "sceRtcGetLastAdjustedTime"},
|
2013-05-20 01:28:05 +00:00
|
|
|
{0x203ceb0d, 0, "sceRtcGetLastReincarnatedTime"},
|
2013-06-12 08:46:06 +00:00
|
|
|
{0x7d1fbed3, &WrapI_UU<sceRtcSetAlarmTick>, "sceRtcSetAlarmTick"},
|
2013-12-03 07:36:55 +00:00
|
|
|
{0xf5fcc995, 0, "sceRtcGetCurrentNetworkTick"},
|
2013-06-30 18:40:52 +00:00
|
|
|
{0x81fcda34, 0, "sceRtcIsAlarmed"},
|
|
|
|
{0xfb3b18cd, 0, "sceRtcRegisterCallback"},
|
|
|
|
{0x6a676d2d, 0, "sceRtcUnregisterCallback"},
|
|
|
|
{0xc2ddbeb5, 0, "sceRtcGetAlarmTick"},
|
2012-12-05 23:47:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void Register_sceRtc()
|
|
|
|
{
|
|
|
|
RegisterModule("sceRtc", ARRAY_SIZE(sceRtc), sceRtc);
|
|
|
|
}
|