mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-02-26 08:55:58 +00:00
Warning fixes (and maybe a bugfix) in sceRtc
This commit is contained in:
parent
6c25a9dcaf
commit
fba61b2a2a
@ -154,13 +154,13 @@ void __RtcTicksToPspTime(ScePspDateTime &t, u64 ticks)
|
||||
t.microsecond = ticks % 1000000;
|
||||
}
|
||||
|
||||
u64 JumpYMD(u64 year, u64 month, u64 day) {
|
||||
return 367*year - 7*(year+(month+9)/12)/4 + 275*month/9 + day;
|
||||
u64 JumpYMD(u64 year, u64 month, u64 day) {
|
||||
return 367*year - 7*(year+(month+9)/12)/4 + 275*month/9 + day;
|
||||
}
|
||||
|
||||
u64 JumpSeconds(u64 year, u64 month, u64 day, u64 hour, u64 minute, u64 second) {
|
||||
static const u64 secs_per_day = 24 * 60 * 60;
|
||||
return JumpYMD(year, month, day) * secs_per_day + hour * 3600 + minute * 60 + second;
|
||||
static const u64 secs_per_day = 24 * 60 * 60;
|
||||
return JumpYMD(year, month, day) * secs_per_day + hour * 3600 + minute * 60 + second;
|
||||
}
|
||||
|
||||
u64 __RtcPspTimeToTicks(ScePspDateTime &t)
|
||||
@ -336,7 +336,7 @@ u32 sceRtcGetDaysInMonth(u32 year, u32 month)
|
||||
u32 sceRtcIsLeapYear(u32 year)
|
||||
{
|
||||
ERROR_LOG(HLE, "sceRtcIsLeapYear(%d)", year);
|
||||
return (year % 4 == 0) && !(year % 100 == 0)|| (year % 400 == 0);
|
||||
return (year % 4 == 0) && (!(year % 100 == 0) || (year % 400 == 0));
|
||||
}
|
||||
|
||||
int sceRtcConvertLocalTimeToUTC(u32 tickLocalPtr,u32 tickUTCPtr)
|
||||
@ -374,51 +374,56 @@ int sceRtcConvertUtcToLocalTime(u32 tickUTCPtr,u32 tickLocalPtr)
|
||||
int sceRtcCheckValid(u32 datePtr)
|
||||
{
|
||||
DEBUG_LOG(HLE, "sceRtcCheckValid(%d)", datePtr);
|
||||
int ret = 0;
|
||||
|
||||
if (Memory::IsValidAddress(datePtr))
|
||||
{
|
||||
ScePspDateTime pt;
|
||||
Memory::ReadStruct(datePtr, &pt);
|
||||
if (pt.year < 1 || pt.year > 9999)
|
||||
if (pt.year < 1 || pt.year > 9999)
|
||||
{
|
||||
ret = PSP_TIME_INVALID_YEAR;
|
||||
}
|
||||
else if (pt.month < 1 || pt.month > 12)
|
||||
return PSP_TIME_INVALID_YEAR;
|
||||
}
|
||||
else if (pt.month < 1 || pt.month > 12)
|
||||
{
|
||||
ret = PSP_TIME_INVALID_MONTH;
|
||||
}
|
||||
else if (pt.day < 1 || pt.day > 31) // TODO: Needs to check actual days in month, including leaps
|
||||
return PSP_TIME_INVALID_MONTH;
|
||||
}
|
||||
else if (pt.day < 1 || pt.day > 31)
|
||||
{
|
||||
ret = PSP_TIME_INVALID_DAY;
|
||||
}
|
||||
else if (pt.hour > 23)
|
||||
return PSP_TIME_INVALID_DAY;
|
||||
}
|
||||
else if (pt.day > 31) // TODO: Needs to check actual days in month, including leaps
|
||||
{
|
||||
ret = PSP_TIME_INVALID_HOUR;
|
||||
}
|
||||
else if (pt.minute > 59)
|
||||
return PSP_TIME_INVALID_DAY;
|
||||
}
|
||||
else if (pt.hour > 23)
|
||||
{
|
||||
ret = PSP_TIME_INVALID_MINUTES;
|
||||
}
|
||||
else if (pt.second > 59)
|
||||
return PSP_TIME_INVALID_HOUR;
|
||||
}
|
||||
else if (pt.minute > 59)
|
||||
{
|
||||
ret = PSP_TIME_INVALID_SECONDS;
|
||||
}
|
||||
else if (pt.microsecond >= 1000000)
|
||||
return PSP_TIME_INVALID_MINUTES;
|
||||
}
|
||||
else if (pt.second > 59)
|
||||
{
|
||||
ret = PSP_TIME_INVALID_MICROSECONDS;
|
||||
}
|
||||
return PSP_TIME_INVALID_SECONDS;
|
||||
}
|
||||
else if (pt.microsecond >= 1000000)
|
||||
{
|
||||
return PSP_TIME_INVALID_MICROSECONDS;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ret=-1;
|
||||
return -1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int sceRtcSetTime_t(u32 datePtr, u32 time)
|
||||
{
|
||||
ERROR_LOG(HLE, "HACK sceRtcSetTime_t(%d,%d)", datePtr, time);
|
||||
ERROR_LOG(HLE, "HACK sceRtcSetTime_t(%08x,%d)", datePtr, time);
|
||||
if (Memory::IsValidAddress(datePtr))
|
||||
{
|
||||
ScePspDateTime pt;
|
||||
@ -435,7 +440,7 @@ int sceRtcSetTime_t(u32 datePtr, u32 time)
|
||||
|
||||
int sceRtcSetTime64_t(u32 datePtr, u64 time)
|
||||
{
|
||||
ERROR_LOG(HLE, "HACK sceRtcSetTime64_t(%d,%lld)", datePtr, time);
|
||||
ERROR_LOG(HLE, "HACK sceRtcSetTime64_t(%08x,%lld)", datePtr, time);
|
||||
if (Memory::IsValidAddress(datePtr))
|
||||
{
|
||||
ScePspDateTime pt;
|
||||
@ -450,10 +455,9 @@ int sceRtcSetTime64_t(u32 datePtr, u64 time)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int sceRtcGetTime_t(u32 datePtr, u32 timePtr)
|
||||
{
|
||||
ERROR_LOG(HLE, "HACK sceRtcGetTime_t(%d,%d)", datePtr, timePtr);
|
||||
ERROR_LOG(HLE, "HACK sceRtcGetTime_t(%08x,%08x)", datePtr, timePtr);
|
||||
if (Memory::IsValidAddress(datePtr)&&Memory::IsValidAddress(timePtr))
|
||||
{
|
||||
ScePspDateTime pt;
|
||||
@ -469,10 +473,9 @@ int sceRtcGetTime_t(u32 datePtr, u32 timePtr)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int sceRtcGetTime64_t(u32 datePtr, u32 timePtr)
|
||||
{
|
||||
ERROR_LOG(HLE, "HACK sceRtcGetTime64_t(%d,%d)", datePtr, timePtr);
|
||||
ERROR_LOG(HLE, "HACK sceRtcGetTime64_t(%08x,%08x)", datePtr, timePtr);
|
||||
if (Memory::IsValidAddress(datePtr)&&Memory::IsValidAddress(timePtr))
|
||||
{
|
||||
ScePspDateTime pt;
|
||||
@ -488,8 +491,6 @@ int sceRtcGetTime64_t(u32 datePtr, u32 timePtr)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int sceRtcSetDosTime(u32 datePtr, u32 dosTime)
|
||||
{
|
||||
ERROR_LOG(HLE, "HACK sceRtcSetDosTime(%d,%d)", datePtr, dosTime);
|
||||
@ -544,16 +545,10 @@ int sceRtcCompareTick(u32 tick1Ptr, u32 tick2Ptr)
|
||||
{
|
||||
u64 tick1 = Memory::Read_U64(tick1Ptr);
|
||||
u64 tick2 = Memory::Read_U64(tick2Ptr);
|
||||
|
||||
if (tick1 > tick2)
|
||||
{
|
||||
if (tick1 > tick2)
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (tick1 < tick2)
|
||||
{
|
||||
if (tick1 < tick2)
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -617,7 +612,6 @@ 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);
|
||||
}
|
||||
@ -656,7 +650,7 @@ int sceRtcTickAddMonths(u32 destTickPtr, u32 srcTickPtr, int numMonths)
|
||||
if (Memory::IsValidAddress(destTickPtr) && Memory::IsValidAddress(srcTickPtr))
|
||||
{
|
||||
u64 srcTick = Memory::Read_U64(srcTickPtr);
|
||||
|
||||
|
||||
// slightly bodgy but we need to add months to a pt and then convert to ticks to cover different day count in months and leapyears
|
||||
ScePspDateTime pt;
|
||||
memset(&pt, 0, sizeof(pt));
|
||||
@ -665,7 +659,7 @@ int sceRtcTickAddMonths(u32 destTickPtr, u32 srcTickPtr, int numMonths)
|
||||
numMonths = -numMonths;;
|
||||
int years = numMonths /12;
|
||||
int realmonths = numMonths % 12;
|
||||
|
||||
|
||||
pt.year = years;
|
||||
pt.month = realmonths;
|
||||
u64 monthTicks =__RtcPspTimeToTicks(pt);
|
||||
@ -684,7 +678,6 @@ int sceRtcTickAddMonths(u32 destTickPtr, u32 srcTickPtr, int numMonths)
|
||||
{
|
||||
int years = numMonths /12;
|
||||
int realmonths = numMonths % 12;
|
||||
|
||||
pt.year = years;
|
||||
pt.month = realmonths;
|
||||
srcTick +=__RtcPspTimeToTicks(pt);
|
||||
@ -696,7 +689,7 @@ int sceRtcTickAddMonths(u32 destTickPtr, u32 srcTickPtr, int numMonths)
|
||||
return 0;
|
||||
}
|
||||
|
||||
//TODO: off by 6 days every 2000 years.
|
||||
// TODO: off by 6 days every 2000 years.
|
||||
int sceRtcTickAddYears(u32 destTickPtr, u32 srcTickPtr, int numYears)
|
||||
{
|
||||
if (Memory::IsValidAddress(destTickPtr) && Memory::IsValidAddress(srcTickPtr))
|
||||
@ -739,10 +732,10 @@ int sceRtcParseDateTime(u32 destTickPtr, u32 dateStringPtr)
|
||||
return 0;
|
||||
}
|
||||
|
||||
const HLEFunction sceRtc[] =
|
||||
const HLEFunction sceRtc[] =
|
||||
{
|
||||
{0xC41C2853, WrapU_V<sceRtcGetTickResolution>, "sceRtcGetTickResolution"},
|
||||
{0x3f7ad767, WrapU_U<sceRtcGetCurrentTick>, "sceRtcGetCurrentTick"},
|
||||
{0x3f7ad767, WrapU_U<sceRtcGetCurrentTick>, "sceRtcGetCurrentTick"},
|
||||
{0x011F03C1, WrapU64_V<sceRtcGetAcculumativeTime>, "sceRtcGetAccumulativeTime"},
|
||||
{0x029CA3B3, WrapU64_V<sceRtcGetAcculumativeTime>, "sceRtcGetAccumlativeTime"},
|
||||
{0x4cfa57b0, WrapU_UI<sceRtcGetCurrentClock>, "sceRtcGetCurrentClock"},
|
||||
@ -763,7 +756,7 @@ const HLEFunction sceRtc[] =
|
||||
{0x6FF40ACC, WrapU_UU<sceRtcGetTick>, "sceRtcGetTick"},
|
||||
{0x9ED0AE87, WrapI_UU<sceRtcCompareTick>, "sceRtcCompareTick"},
|
||||
{0x44F45E05, WrapI_UUU64<sceRtcTickAddTicks>, "sceRtcTickAddTicks"},
|
||||
{0x26D25A5D, WrapI_UUU64<sceRtcTickAddMicroseconds>, "sceRtcTickAddMicroseconds"},
|
||||
{0x26D25A5D, WrapI_UUU64<sceRtcTickAddMicroseconds>, "sceRtcTickAddMicroseconds"},
|
||||
{0xF2A4AFE5, WrapI_UUU64<sceRtcTickAddSeconds>, "sceRtcTickAddSeconds"},
|
||||
{0xE6605BCA, WrapI_UUU64<sceRtcTickAddMinutes>, "sceRtcTickAddMinutes"},
|
||||
{0x26D7A24A, WrapI_UUI<sceRtcTickAddHours>, "sceRtcTickAddHours"},
|
||||
@ -781,8 +774,6 @@ const HLEFunction sceRtc[] =
|
||||
{0x1909c99b, WrapI_UU64<sceRtcSetTime64_t>, "sceRtcSetTime64_t"},
|
||||
};
|
||||
|
||||
|
||||
|
||||
void Register_sceRtc()
|
||||
{
|
||||
RegisterModule("sceRtc", ARRAY_SIZE(sceRtc), sceRtc);
|
||||
|
Loading…
x
Reference in New Issue
Block a user