Use a base time throughout rtc and kernel time.
This way, time doesn't move abnormally as far as the game can tell, even when savestates and fast forward and pause are used.
This commit is contained in:
parent
bbbfa715cd
commit
db54bffe14
4 changed files with 48 additions and 32 deletions
|
@ -57,6 +57,7 @@
|
||||||
#include "scePower.h"
|
#include "scePower.h"
|
||||||
#include "sceUtility.h"
|
#include "sceUtility.h"
|
||||||
#include "sceUmd.h"
|
#include "sceUmd.h"
|
||||||
|
#include "sceRtc.h"
|
||||||
#include "sceSsl.h"
|
#include "sceSsl.h"
|
||||||
#include "sceSas.h"
|
#include "sceSas.h"
|
||||||
#include "scePsmf.h"
|
#include "scePsmf.h"
|
||||||
|
@ -108,6 +109,7 @@ void __KernelInit()
|
||||||
__MpegInit(PSP_CoreParameter().useMediaEngine);
|
__MpegInit(PSP_CoreParameter().useMediaEngine);
|
||||||
__PsmfInit();
|
__PsmfInit();
|
||||||
__CtrlInit();
|
__CtrlInit();
|
||||||
|
__RtcInit();
|
||||||
__SslInit();
|
__SslInit();
|
||||||
__ImposeInit();
|
__ImposeInit();
|
||||||
__UsbInit();
|
__UsbInit();
|
||||||
|
@ -201,6 +203,7 @@ void __KernelDoState(PointerWrap &p)
|
||||||
__PowerDoState(p);
|
__PowerDoState(p);
|
||||||
__PsmfDoState(p);
|
__PsmfDoState(p);
|
||||||
__PsmfPlayerDoState(p);
|
__PsmfPlayerDoState(p);
|
||||||
|
__RtcDoState(p);
|
||||||
__SasDoState(p);
|
__SasDoState(p);
|
||||||
__SslDoState(p);
|
__SslDoState(p);
|
||||||
__UmdDoState(p);
|
__UmdDoState(p);
|
||||||
|
|
|
@ -24,14 +24,12 @@
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#include "HLE.h"
|
#include "Common/ChunkFile.h"
|
||||||
#include "../MIPS/MIPS.h"
|
#include "Core/CoreTiming.h"
|
||||||
|
#include "Core/HLE/HLE.h"
|
||||||
#include "sceKernel.h"
|
#include "Core/HLE/sceKernel.h"
|
||||||
#include "sceKernelTime.h"
|
#include "Core/HLE/sceKernelTime.h"
|
||||||
|
#include "Core/HLE/sceRtc.h"
|
||||||
#include "../CoreTiming.h"
|
|
||||||
#include "ChunkFile.h"
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
// State
|
// State
|
||||||
|
@ -160,27 +158,12 @@ u32 sceKernelLibcTime(u32 outPtr)
|
||||||
u32 sceKernelLibcGettimeofday(u32 timeAddr, u32 tzAddr)
|
u32 sceKernelLibcGettimeofday(u32 timeAddr, u32 tzAddr)
|
||||||
{
|
{
|
||||||
// TODO: tzAddr?
|
// TODO: tzAddr?
|
||||||
#ifdef _WIN32
|
if (Memory::IsValidAddress(timeAddr))
|
||||||
union {
|
|
||||||
s64 ns100; /*time since 1 Jan 1601 in 100ns units */
|
|
||||||
FILETIME ft;
|
|
||||||
} now;
|
|
||||||
|
|
||||||
struct timeval
|
|
||||||
{
|
{
|
||||||
u32 tv_sec;
|
timeval *tv = (timeval *)Memory::GetPointer(timeAddr);
|
||||||
u32 tv_usec;
|
__RtcTimeOfDay(tv);
|
||||||
};
|
}
|
||||||
|
|
||||||
timeval *tv = (timeval*)Memory::GetPointer(timeAddr);
|
|
||||||
|
|
||||||
GetSystemTimeAsFileTime (&now.ft);
|
|
||||||
tv->tv_usec = (long) ((now.ns100 / 10LL) % 1000000LL);
|
|
||||||
tv->tv_sec = (long) ((now.ns100 - 116444736000000000LL) / 10000000LL);
|
|
||||||
#else
|
|
||||||
timeval *tv = (timeval*)Memory::GetPointer(timeAddr);
|
|
||||||
gettimeofday(tv, NULL);
|
|
||||||
#endif
|
|
||||||
DEBUG_LOG(HLE,"sceKernelLibcGettimeofday(%08x, %08x)", timeAddr, tzAddr);
|
DEBUG_LOG(HLE,"sceKernelLibcGettimeofday(%08x, %08x)", timeAddr, tzAddr);
|
||||||
hleEatCycles(1885);
|
hleEatCycles(1885);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -31,6 +31,10 @@
|
||||||
#include "sceRtc.h"
|
#include "sceRtc.h"
|
||||||
#include "../CoreTiming.h"
|
#include "../CoreTiming.h"
|
||||||
|
|
||||||
|
// This is a base time that everything is relative to.
|
||||||
|
// This way, time doesn't move strangely with savestates, turbo speed, etc.
|
||||||
|
static timeval rtcBaseTime;
|
||||||
|
|
||||||
// Grabbed from JPSCP
|
// Grabbed from JPSCP
|
||||||
// This is # of microseconds between January 1, 0001 and January 1, 1970.
|
// This is # of microseconds between January 1, 0001 and January 1, 1970.
|
||||||
const u64 rtcMagicOffset = 62135596800000000L;
|
const u64 rtcMagicOffset = 62135596800000000L;
|
||||||
|
@ -72,7 +76,6 @@ time_t rtc_timegm(struct tm *tm)
|
||||||
return _mkgmtime(&modified);
|
return _mkgmtime(&modified);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Who has timegm?
|
|
||||||
#elif defined(__GLIBC__) && !defined(ANDROID)
|
#elif defined(__GLIBC__) && !defined(ANDROID)
|
||||||
#define rtc_timegm timegm
|
#define rtc_timegm timegm
|
||||||
#else
|
#else
|
||||||
|
@ -100,6 +103,30 @@ time_t rtc_timegm(struct tm *tm)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void __RtcInit()
|
||||||
|
{
|
||||||
|
// This is the base time, the only case we use gettimeofday() for.
|
||||||
|
// Everything else is relative to that, "virtual time."
|
||||||
|
gettimeofday(&rtcBaseTime, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void __RtcDoState(PointerWrap &p)
|
||||||
|
{
|
||||||
|
p.Do(rtcBaseTime);
|
||||||
|
|
||||||
|
p.DoMarker("sceRtc");
|
||||||
|
}
|
||||||
|
|
||||||
|
void __RtcTimeOfDay(timeval *tv)
|
||||||
|
{
|
||||||
|
s64 additionalUs = cyclesToUs(CoreTiming::GetTicks());
|
||||||
|
*tv = rtcBaseTime;
|
||||||
|
|
||||||
|
s64 adjustedUs = additionalUs + tv->tv_usec;
|
||||||
|
tv->tv_sec += long(adjustedUs / 1000000UL);
|
||||||
|
tv->tv_usec = adjustedUs % 1000000UL;
|
||||||
|
}
|
||||||
|
|
||||||
void __RtcTmToPspTime(ScePspDateTime &t, tm *val)
|
void __RtcTmToPspTime(ScePspDateTime &t, tm *val)
|
||||||
{
|
{
|
||||||
t.year = val->tm_year + 1900;
|
t.year = val->tm_year + 1900;
|
||||||
|
@ -207,7 +234,7 @@ u32 sceRtcGetCurrentClock(u32 pspTimePtr, int tz)
|
||||||
{
|
{
|
||||||
DEBUG_LOG(HLE, "sceRtcGetCurrentClock(%08x, %d)", pspTimePtr, tz);
|
DEBUG_LOG(HLE, "sceRtcGetCurrentClock(%08x, %d)", pspTimePtr, tz);
|
||||||
timeval tv;
|
timeval tv;
|
||||||
gettimeofday(&tv, NULL);
|
__RtcTimeOfDay(&tv);
|
||||||
|
|
||||||
time_t sec = (time_t) tv.tv_sec;
|
time_t sec = (time_t) tv.tv_sec;
|
||||||
tm *utc = gmtime(&sec);
|
tm *utc = gmtime(&sec);
|
||||||
|
@ -236,7 +263,7 @@ u32 sceRtcGetCurrentClockLocalTime(u32 pspTimePtr)
|
||||||
{
|
{
|
||||||
DEBUG_LOG(HLE, "sceRtcGetCurrentClockLocalTime(%08x)", pspTimePtr);
|
DEBUG_LOG(HLE, "sceRtcGetCurrentClockLocalTime(%08x)", pspTimePtr);
|
||||||
timeval tv;
|
timeval tv;
|
||||||
gettimeofday(&tv, NULL);
|
__RtcTimeOfDay(&tv);
|
||||||
|
|
||||||
time_t sec = (time_t) tv.tv_sec;
|
time_t sec = (time_t) tv.tv_sec;
|
||||||
tm *local = localtime(&sec);
|
tm *local = localtime(&sec);
|
||||||
|
|
|
@ -17,9 +17,12 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
void sceRtcGetCurrentTick();
|
struct timeval;
|
||||||
int sceRtcGetLastAdjustedTime(u32 tickPtr);
|
void __RtcTimeOfDay(timeval *tv);
|
||||||
|
|
||||||
void Register_sceRtc();
|
void Register_sceRtc();
|
||||||
|
void __RtcInit();
|
||||||
|
void __RtcDoState(PointerWrap &p);
|
||||||
|
|
||||||
struct ScePspDateTime {
|
struct ScePspDateTime {
|
||||||
unsigned short year;
|
unsigned short year;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue