2012-11-01 16:19:01 +01: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
|
2012-11-04 23:01:49 +01:00
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
2012-11-01 16:19:01 +01:00
|
|
|
|
|
|
|
// 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
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#include "HLE.h"
|
|
|
|
#include "../MIPS/MIPS.h"
|
|
|
|
|
|
|
|
#include "sceKernel.h"
|
|
|
|
#include "sceKernelTime.h"
|
|
|
|
|
|
|
|
#include "../CoreTiming.h"
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Other clock stuff
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
struct SceKernelSysClock
|
|
|
|
{
|
|
|
|
u32 lo;
|
|
|
|
u32 hi;
|
|
|
|
};
|
|
|
|
|
|
|
|
void sceKernelGetSystemTime()
|
|
|
|
{
|
|
|
|
SceKernelSysClock *clock = (SceKernelSysClock*)Memory::GetPointer(PARAM(0));
|
|
|
|
u64 t = CoreTiming::GetTicks() / CoreTiming::GetClockFrequencyMHz();
|
|
|
|
clock->lo = (u32)t;
|
|
|
|
clock->hi = t >> 32;
|
|
|
|
DEBUG_LOG(HLE,"sceKernelGetSystemTime(out:%08x%08x)",clock->hi, clock->lo);
|
|
|
|
RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void sceKernelGetSystemTimeLow()
|
|
|
|
{
|
|
|
|
// This clock should tick at 1 Mhz.
|
|
|
|
u64 t = CoreTiming::GetTicks() / CoreTiming::GetClockFrequencyMHz();
|
2012-11-07 20:59:56 +01:00
|
|
|
// DEBUG_LOG(HLE,"%08x=sceKernelGetSystemTimeLow()",(u32)t);
|
2012-11-01 16:19:01 +01:00
|
|
|
RETURN((u32)t);
|
|
|
|
}
|
|
|
|
|
|
|
|
void sceKernelGetSystemTimeWide()
|
|
|
|
{
|
|
|
|
u64 t = CoreTiming::GetTicks() / CoreTiming::GetClockFrequencyMHz();
|
|
|
|
DEBUG_LOG(HLE,"%i=sceKernelGetSystemTimeWide()",(u32)t);
|
|
|
|
RETURN((u32)t);
|
|
|
|
currentMIPS->r[3] = t >> 32;
|
|
|
|
}
|
|
|
|
|
|
|
|
void sceKernelUSec2SysClock()
|
|
|
|
{
|
|
|
|
u32 microseconds = PARAM(0);
|
|
|
|
SceKernelSysClock *clock = (SceKernelSysClock*)Memory::GetPointer(PARAM(1));
|
|
|
|
clock->lo = microseconds; //TODO: fix
|
|
|
|
DEBUG_LOG(HLE,"sceKernelUSec2SysClock(%i, %08x )",PARAM(0), PARAM(1));
|
|
|
|
RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void sceKernelSysClock2USec()
|
|
|
|
{
|
|
|
|
SceKernelSysClock clock;
|
|
|
|
Memory::ReadStruct(PARAM(0), &clock);
|
|
|
|
DEBUG_LOG(HLE, "sceKernelSysClock2USec(clock = , lo = %08x, hi = %08x)", PARAM(1), PARAM(2));
|
|
|
|
u64 time = clock.lo | ((u64)clock.hi << 32);
|
2012-11-06 16:01:41 +01:00
|
|
|
if (Memory::IsValidAddress(PARAM(1)))
|
|
|
|
Memory::Write_U32((u32)(time / 1000000), PARAM(1));
|
|
|
|
if (Memory::IsValidAddress(PARAM(2)))
|
|
|
|
Memory::Write_U32((u32)(time % 1000000), PARAM(2));
|
2012-11-01 16:19:01 +01:00
|
|
|
RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void sceKernelSysClock2USecWide()
|
|
|
|
{
|
|
|
|
u64 clock = PARAM(0) | ((u64)PARAM(1) << 32);
|
|
|
|
DEBUG_LOG(HLE, "sceKernelSysClock2USecWide(clock = %llu, lo = %08x, hi = %08x)", clock, PARAM(2), PARAM(3));
|
2012-11-06 16:01:41 +01:00
|
|
|
if (Memory::IsValidAddress(PARAM(2)))
|
|
|
|
Memory::Write_U32((u32)(clock / 1000000), PARAM(2));
|
|
|
|
if (Memory::IsValidAddress(PARAM(3)))
|
|
|
|
Memory::Write_U32((u32)(clock % 1000000), PARAM(3));
|
2012-11-01 16:19:01 +01:00
|
|
|
RETURN(0);
|
|
|
|
}
|
|
|
|
|
2012-11-20 10:59:23 +01:00
|
|
|
u32 sceKernelUSec2SysClockWide(u32 usec)
|
2012-11-20 01:04:39 +01:00
|
|
|
{
|
2012-11-20 10:59:23 +01:00
|
|
|
DEBUG_LOG(HLE, "sceKernelUSec2SysClockWide(%i)", usec);
|
|
|
|
return usec * 1000000; // ?
|
2012-11-20 01:04:39 +01:00
|
|
|
}
|
|
|
|
|
2012-11-20 10:59:23 +01:00
|
|
|
u32 sceKernelLibcClock()
|
2012-11-01 16:19:01 +01:00
|
|
|
{
|
2013-01-02 00:35:31 -08:00
|
|
|
u32 retVal = (u32) (CoreTiming::GetTicks() / CoreTiming::GetClockFrequencyMHz());
|
|
|
|
DEBUG_LOG(HLE, "%i = sceKernelLibcClock", retVal);
|
2012-11-20 10:59:23 +01:00
|
|
|
return retVal;
|
2012-11-01 16:19:01 +01:00
|
|
|
}
|
|
|
|
|
2013-01-01 21:27:18 -08:00
|
|
|
u32 sceKernelLibcTime(u32 outPtr)
|
2012-11-01 16:19:01 +01:00
|
|
|
{
|
2013-01-01 21:27:18 -08:00
|
|
|
time_t t;
|
|
|
|
time(&t);
|
|
|
|
|
|
|
|
DEBUG_LOG(HLE, "%i = sceKernelLibcTime(%08X)", (u32) t, outPtr);
|
|
|
|
|
|
|
|
if (Memory::IsValidAddress(outPtr))
|
|
|
|
Memory::Write_U32((u32) t, outPtr);
|
2013-01-02 00:35:31 -08:00
|
|
|
else if (outPtr != 0)
|
|
|
|
return 0;
|
2013-01-01 21:27:18 -08:00
|
|
|
|
|
|
|
return (u32) t;
|
2012-11-01 16:19:01 +01:00
|
|
|
}
|
|
|
|
|
2012-11-05 10:05:09 +01:00
|
|
|
void sceKernelLibcGettimeofday()
|
2012-11-01 16:19:01 +01:00
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
union {
|
|
|
|
s64 ns100; /*time since 1 Jan 1601 in 100ns units */
|
|
|
|
FILETIME ft;
|
|
|
|
} now;
|
|
|
|
|
|
|
|
struct timeval
|
|
|
|
{
|
|
|
|
u32 tv_sec;
|
|
|
|
u32 tv_usec;
|
|
|
|
};
|
|
|
|
|
2012-11-05 10:05:09 +01:00
|
|
|
timeval *tv = (timeval*)Memory::GetPointer(PARAM(0));
|
2012-11-01 16:19:01 +01:00
|
|
|
DEBUG_LOG(HLE,"sceKernelLibcGettimeofday()");
|
|
|
|
|
|
|
|
GetSystemTimeAsFileTime (&now.ft);
|
|
|
|
tv->tv_usec = (long) ((now.ns100 / 10LL) % 1000000LL);
|
|
|
|
tv->tv_sec = (long) ((now.ns100 - 116444736000000000LL) / 10000000LL);
|
|
|
|
#endif
|
2012-11-05 10:05:09 +01:00
|
|
|
RETURN(0);
|
2012-11-01 16:19:01 +01:00
|
|
|
}
|