Merge pull request #475 from Xele02/sceRtc

Implement sceRtcGetDosTime and sceRtcSetDosTime
This commit is contained in:
Henrik Rydgård 2013-01-23 00:32:34 -08:00
commit 0d67acc52b
2 changed files with 46 additions and 9 deletions

View File

@ -373,14 +373,14 @@ u32 sceIoWrite(int id, void *data_ptr, int size)
if (id == 2) {
//stderr!
const char *str = (const char*) data_ptr;
DEBUG_LOG(HLE, "stderr: %s", str);
INFO_LOG(HLE, "stderr: %s", str);
return size;
} else if (id == 1) {
//stdout!
char *str = (char *) data_ptr;
char temp = str[size];
str[size] = 0;
DEBUG_LOG(HLE, "stdout: %s", str);
INFO_LOG(HLE, "stdout: %s", str);
str[size] = temp;
return size;
}

View File

@ -74,6 +74,7 @@ void __RtcTmToPspTime(ScePspDateTime &t, tm *val)
t.hour = val->tm_hour;
t.minute = val->tm_min;
t.second = val->tm_sec;
t.microsecond = 0;
}
//based on http://stackoverflow.com/a/11197532
@ -515,12 +516,22 @@ int sceRtcGetTime64_t(u32 datePtr, u32 timePtr)
int sceRtcSetDosTime(u32 datePtr, u32 dosTime)
{
ERROR_LOG(HLE, "HACK sceRtcSetDosTime(%d,%d)", datePtr, dosTime);
DEBUG_LOG(HLE, "sceRtcSetDosTime(%d,%d)", datePtr, dosTime);
if (Memory::IsValidAddress(datePtr))
{
ScePspDateTime pt;
__RtcTicksToPspTime(pt, dosTime);
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;
Memory::WriteStruct(datePtr, &pt);
}
else
@ -532,19 +543,45 @@ int sceRtcSetDosTime(u32 datePtr, u32 dosTime)
int sceRtcGetDosTime(u32 datePtr, u32 dosTime)
{
ERROR_LOG(HLE, "HACK sceRtcGetDosTime(%d,%d)", datePtr, dosTime);
int retValue = 0;
DEBUG_LOG(HLE, "sceRtcGetDosTime(%d,%d)", datePtr, dosTime);
if (Memory::IsValidAddress(datePtr)&&Memory::IsValidAddress(dosTime))
{
ScePspDateTime pt;
Memory::ReadStruct(datePtr, &pt);
u64 result = __RtcPspTimeToTicks(pt);
Memory::Write_U64(result, dosTime);
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);
}
else
{
return 1;
retValue = -1;
}
return 0;
return retValue;
}