From 6ea2c7d6a853bd6a803773c6d4507f5abd93b903 Mon Sep 17 00:00:00 2001 From: DH Date: Sat, 9 Nov 2013 14:25:12 +0200 Subject: [PATCH] - Fixed memory leaks in cellRtc module. - Fixed CPUThread crash. - Improved ARMv7 Interpreter. --- rpcs3/Emu/ARMv7/ARMv7Interpreter.h | 229 +++- rpcs3/Emu/ARMv7/ARMv7Thread.cpp | 4 +- rpcs3/Emu/CPU/CPUThread.cpp | 10 +- rpcs3/Emu/SysCalls/Modules/cellRtc.cpp | 1215 +++++++++--------- rpcs3/Emu/SysCalls/Modules/cellSysmodule.cpp | 214 +-- rpcs3/Loader/ELF32.cpp | 6 +- 6 files changed, 949 insertions(+), 729 deletions(-) diff --git a/rpcs3/Emu/ARMv7/ARMv7Interpreter.h b/rpcs3/Emu/ARMv7/ARMv7Interpreter.h index 8d32701813..a11144e9b6 100644 --- a/rpcs3/Emu/ARMv7/ARMv7Interpreter.h +++ b/rpcs3/Emu/ARMv7/ARMv7Interpreter.h @@ -10,6 +10,229 @@ public: { } + enum SRType + { + SRType_None, + SRType_LSL, + SRType_LSR, + SRType_ASR, + SRType_ROR, + SRType_RRX, + }; + + template + bool IsZero(T x) + { + return x == T(0); + } + + template + bool IsOnes(T x) + { + return x == ~T(0); + } + + template + u8 IsZeroBit(T x) + { + return IsZero(x) ? 1 : 0; + } + + template + bool IsOnesBit(T x, u8 len = sizeof(T) * 8) + { + return IsOnes(x) ? 1 : 0; + } + + template + u8 BitCount(T x, u8 len = sizeof(T) * 8) + { + u8 result = 0; + + for(u8 mask=1 << (len - 1); mask; mask >>= 1) + { + if(x & mask) result++; + } + + return result; + } + + template + s8 LowestSetBit(T x, u8 len = sizeof(T) * 8) + { + if(!x) return len; + + u8 result = 0; + + for(T mask=1, i=0; i + s8 HighestSetBit(T x, u8 len = sizeof(T) * 8) + { + if(!x) return -1; + + u8 result = len; + + for(T mask=T(1) << (len - 1); (x & mask) == 0; mask >>= 1) + { + result--; + } + + return result; + } + + template + s8 CountLeadingZeroBits(T x, u8 len = sizeof(T) * 8) + { + return len - 1 - HighestSetBit(x, len); + } + + SRType DecodeImmShift(u8 type, u8 imm5, uint* shift_n) + { + SRType shift_t; + + switch(type) + { + case 0: shift_t = SRType_LSL; if(shift_n) *shift_n = imm5; break; + case 1: shift_t = SRType_LSR; if(shift_n) *shift_n = imm5 == 0 ? 32 : imm5; break; + case 2: shift_t = SRType_ASR; if(shift_n) *shift_n = imm5 == 0 ? 32 : imm5; break; + case 3: + if(imm5 == 0) + { + shift_t = SRType_RRX; if(shift_n) *shift_n = 1; + } + else + { + shift_t = SRType_ROR; if(shift_n) *shift_n = imm5; + } + break; + } + + return shift_t; + } + + SRType DecodeRegShift(u8 type) + { + SRType shift_t; + + switch(type) + { + case 0: shift_t = SRType_LSL; break; + case 1: shift_t = SRType_LSR; break; + case 2: shift_t = SRType_ASR; break; + case 3: shift_t = SRType_ROR; break; + } + + return shift_t; + } + + u32 LSL_C(u32 x, int shift, bool& carry_out) + { + u32 extended_x = x << shift; + carry_out = (extended_x >> 31) ? 1 : 0; + return extended_x & ~(1 << 31); + } + + u32 LSL(u32 x, int shift) + { + if(!shift) return x; + bool carry_out; + return LSL_C(x, shift, carry_out); + } + + u32 LSR_C(u32 x, int shift, bool& carry_out) + { + carry_out = (x >> (shift - 1)) & 0x1; + return x >> shift; + } + + u32 LSR(u32 x, int shift) + { + if(!shift) return x; + bool carry_out; + return LSR_C(x, shift, carry_out); + } + + s32 ASR_C(s32 x, int shift, bool& carry_out) + { + carry_out = (x >> (shift - 1)) & 0x1; + return x >> shift; + } + + s32 ASR(s32 x, int shift) + { + if(!shift) return x; + bool carry_out; + return ASR_C(x, shift, carry_out); + } + + u32 ROR_C(u32 x, int shift, bool& carry_out) + { + u32 result = LSR(x, shift) | LSL(x, 32 - shift); + carry_out = (result >> 30) & 0x1; + return result; + } + + s32 ROR(s32 x, int shift) + { + if(!shift) return x; + bool carry_out; + return ROR_C(x, shift, carry_out); + } + + template T RRX_C(T x, bool carry_in, bool& carry_out) + { + carry_out = x & 0x1; + return ((u32)carry_in << 31) | (x & 0x7ffffffe); + } + + s32 RRX(s32 x, int shift) + { + if(!shift) return x; + bool carry_out; + return RRX_C(x, shift, carry_out); + } + + template T Shift_C(T value, SRType type, uint amount, bool carry_in, bool& carry_out) + { + if(amount) + { + switch(type) + { + case SRType_LSL: return LSL_C(value, amount, carry_out); + case SRType_LSR: return LSR_C(value, amount, carry_out); + case SRType_ASR: return ASR_C(value, amount, carry_out); + case SRType_ROR: return ROR_C(value, amount, carry_out); + case SRType_RRX: return RRX_C(value, amount, carry_out); + } + } + + carry_out = carry_in; + return value; + } + + template T Shift(T value, SRType type, uint amount, bool carry_in) + { + bool carry_out; + return Shift_C(value, type, amount, carry_in, carry_out); + } + + template T AddWithCarry(T x, T y, bool carry_in, bool& carry_out, bool& overflow) + { + uint unsigned_sum = (uint)x + (uint)y + (uint)carry_in; + int signed_sum = (int)x + (int)y + (int)carry_in; + T result = unsigned_sum & ~(T(1) << (sizeof(T) - 1)); + carry_out = (uint)result != unsigned_sum; + overflow = (int)result != signed_sum; + return result; + } + bool ConditionPassed(u8 cond) { bool result; @@ -51,20 +274,20 @@ protected: { if(regs_list & mask) { + CPU.SP -= 4; Memory.Write32(CPU.SP, CPU.read_gpr(i)); - CPU.SP += 4; } } } void POP(u16 regs_list) { - for(u16 mask=(0x1 << 15), i=15; mask; mask >>= 1, i++) + for(u16 mask=(0x1 << 15), i=15; mask; mask >>= 1, i--) { if(regs_list & mask) { - CPU.SP -= 4; CPU.write_gpr(i, Memory.Read32(CPU.SP)); + CPU.SP += 4; } } } diff --git a/rpcs3/Emu/ARMv7/ARMv7Thread.cpp b/rpcs3/Emu/ARMv7/ARMv7Thread.cpp index 15fc560c76..ee0b69a996 100644 --- a/rpcs3/Emu/ARMv7/ARMv7Thread.cpp +++ b/rpcs3/Emu/ARMv7/ARMv7Thread.cpp @@ -24,12 +24,12 @@ void ARMv7Thread::InitStack() m_stack_addr = Memory.Alloc(0x10000, 1); } - m_stack_point = m_stack_addr; + m_stack_point = m_stack_addr + m_stack_size; } u64 ARMv7Thread::GetFreeStackSize() const { - return GetStackSize() - (SP - GetStackAddr()); + return SP - GetStackAddr(); } void ARMv7Thread::SetArg(const uint pos, const u64 arg) diff --git a/rpcs3/Emu/CPU/CPUThread.cpp b/rpcs3/Emu/CPU/CPUThread.cpp index 6c792b2cc1..4733867bea 100644 --- a/rpcs3/Emu/CPU/CPUThread.cpp +++ b/rpcs3/Emu/CPU/CPUThread.cpp @@ -33,6 +33,11 @@ void CPUThread::Close() { m_free_data = true; } + else + { + delete m_dec; + m_dec = nullptr; + } Stop(); } @@ -242,7 +247,6 @@ void CPUThread::Stop() Reset(); DoStop(); Emu.CheckStatus(); - delete m_dec; wxGetApp().SendDbgCommand(DID_STOPED_THREAD, this); } @@ -326,5 +330,9 @@ void CPUThread::Task() //ConLog.Write("%s leave", CPUThread::GetFName()); if(m_free_data) + { + delete m_dec; + m_dec = nullptr; free(this); + } } diff --git a/rpcs3/Emu/SysCalls/Modules/cellRtc.cpp b/rpcs3/Emu/SysCalls/Modules/cellRtc.cpp index 579a50c86a..967b0dedf3 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellRtc.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellRtc.cpp @@ -1,35 +1,36 @@ -#include "stdafx.h" -#include "Emu/SysCalls/SysCalls.h" -#include "Emu/SysCalls/SC_FUNC.h" - -void cellRtc_init(); -Module cellRtc(0x0009, cellRtc_init); - -// Return Codes -enum -{ - CELL_RTC_ERROR_NOT_INITIALIZED = 0x80010601, - CELL_RTC_ERROR_INVALID_POINTER = 0x80010602, - CELL_RTC_ERROR_INVALID_VALUE = 0x80010603, - CELL_RTC_ERROR_INVALID_ARG = 0x80010604, - CELL_RTC_ERROR_NOT_SUPPORTED = 0x80010605, - CELL_RTC_ERROR_NO_CLOCK = 0x80010606, - CELL_RTC_ERROR_BAD_PARSE = 0x80010607, - CELL_RTC_ERROR_INVALID_YEAR = 0x80010621, - CELL_RTC_ERROR_INVALID_MONTH = 0x80010622, - CELL_RTC_ERROR_INVALID_DAY = 0x80010623, - CELL_RTC_ERROR_INVALID_HOUR = 0x80010624, - CELL_RTC_ERROR_INVALID_MINUTE = 0x80010625, - CELL_RTC_ERROR_INVALID_SECOND = 0x80010626, - CELL_RTC_ERROR_INVALID_MICROSECOND = 0x80010627, -}; - -struct CellRtcTick -{ - u64 tick; -}; - -struct CellRtcDateTime { +#include "stdafx.h" +#include "Emu/SysCalls/SysCalls.h" +#include "Emu/SysCalls/SC_FUNC.h" + +void cellRtc_init(); +Module cellRtc(0x0009, cellRtc_init); + +// Return Codes +enum +{ + CELL_RTC_ERROR_NOT_INITIALIZED = 0x80010601, + CELL_RTC_ERROR_INVALID_POINTER = 0x80010602, + CELL_RTC_ERROR_INVALID_VALUE = 0x80010603, + CELL_RTC_ERROR_INVALID_ARG = 0x80010604, + CELL_RTC_ERROR_NOT_SUPPORTED = 0x80010605, + CELL_RTC_ERROR_NO_CLOCK = 0x80010606, + CELL_RTC_ERROR_BAD_PARSE = 0x80010607, + CELL_RTC_ERROR_INVALID_YEAR = 0x80010621, + CELL_RTC_ERROR_INVALID_MONTH = 0x80010622, + CELL_RTC_ERROR_INVALID_DAY = 0x80010623, + CELL_RTC_ERROR_INVALID_HOUR = 0x80010624, + CELL_RTC_ERROR_INVALID_MINUTE = 0x80010625, + CELL_RTC_ERROR_INVALID_SECOND = 0x80010626, + CELL_RTC_ERROR_INVALID_MICROSECOND = 0x80010627, +}; + +struct CellRtcTick +{ + u64 tick; +}; + +struct CellRtcDateTime +{ u16 year; u16 month; u16 day; @@ -37,590 +38,572 @@ struct CellRtcDateTime { u16 minute; u16 second; u32 microsecond; -}; - -long convertToUNIXTime(u16 seconds, u16 minutes, u16 hours, u16 days, int years) { - return (seconds + minutes*60 + hours*3600 + days*86400 + (years-70)*31536000 + ((years-69)/4)*86400 - ((years-1)/100)*86400 + ((years+299)/400)*86400); -} - -u64 convertToWin32FILETIME(u16 seconds, u16 minutes, u16 hours, u16 days, int years) { - long unixtime = convertToUNIXTime(seconds, minutes, hours, days, years); - LONGLONG win32time = Int32x32To64(unixtime, 10000000) + 116444736000000000; - u64 win32filetime = (u64) win32time | win32time >> 32; - return win32filetime; -} - -int cellRtcGetCurrentTick(mem64_t tick) -{ - cellRtc.Log("cellRtcGetCurrentTick(tick_addr=0x%x)", tick.GetAddr()); - CellRtcTick *current_tick = new CellRtcTick; - wxDateTime unow = wxDateTime::UNow(); - current_tick->tick = unow.GetTicks(); - tick = current_tick->tick; - return CELL_OK; -} - -int cellRtcGetCurrentClock(u32 clock_addr, int time_zone) -{ - cellRtc.Log("cellRtcGetCurrentClock(clock_addr=0x%x, time_zone=%d)", clock_addr, time_zone); - CellRtcDateTime *current_clock = new CellRtcDateTime; - wxDateTime unow = wxDateTime::UNow(); - - // Add time_zone as offset in minutes. - wxTimeSpan tz = wxTimeSpan::wxTimeSpan(0, (long) time_zone, 0, 0); - unow.Add(tz); - - current_clock->year = unow.GetYear(wxDateTime::TZ::UTC); - current_clock->month = unow.GetMonth(wxDateTime::TZ::UTC); - current_clock->day = unow.GetDay(wxDateTime::TZ::UTC); - current_clock->hour = unow.GetHour(wxDateTime::TZ::UTC); - current_clock->minute = unow.GetMinute(wxDateTime::TZ::UTC); - current_clock->second = unow.GetSecond(wxDateTime::TZ::UTC); - current_clock->microsecond = unow.GetMillisecond(wxDateTime::TZ::UTC) * 1000; - - Memory.Write16(clock_addr, current_clock->year); - Memory.Write16(clock_addr + 2, current_clock->month); - Memory.Write16(clock_addr + 4, current_clock->day); - Memory.Write16(clock_addr + 6, current_clock->hour); - Memory.Write16(clock_addr + 8, current_clock->minute); - Memory.Write16(clock_addr + 10, current_clock->second); - Memory.Write32(clock_addr + 12, current_clock->microsecond); - - return CELL_OK; -} - -int cellRtcGetCurrentClockLocalTime(u32 clock_addr) -{ - cellRtc.Log("cellRtcGetCurrentClockLocalTime(clock_addr=0x%x)", clock_addr); - CellRtcDateTime *current_clock = new CellRtcDateTime; - wxDateTime unow = wxDateTime::UNow(); - - current_clock->year = unow.GetYear(wxDateTime::TZ::Local); - current_clock->month = unow.GetMonth(wxDateTime::TZ::Local); - current_clock->day = unow.GetDay(wxDateTime::TZ::Local); - current_clock->hour = unow.GetHour(wxDateTime::TZ::Local); - current_clock->minute = unow.GetMinute(wxDateTime::TZ::Local); - current_clock->second = unow.GetSecond(wxDateTime::TZ::Local); - current_clock->microsecond = unow.GetMillisecond(wxDateTime::TZ::Local) * 1000; - - Memory.Write16(clock_addr, current_clock->year); - Memory.Write16(clock_addr + 2, current_clock->month); - Memory.Write16(clock_addr + 4, current_clock->day); - Memory.Write16(clock_addr + 6, current_clock->hour); - Memory.Write16(clock_addr + 8, current_clock->minute); - Memory.Write16(clock_addr + 10, current_clock->second); - Memory.Write32(clock_addr + 12, current_clock->microsecond); - - return CELL_OK; -} - -int cellRtcFormatRfc2822(u32 rfc_addr, u32 tick_addr, int time_zone) -{ - cellRtc.Log("cellRtcFormatRfc2822(rfc_addr=0x%x, tick_addr=0x%x, time_zone=%d)", rfc_addr, tick_addr, time_zone); - CellRtcTick *current_tick = new CellRtcTick; - current_tick->tick = Memory.Read64(tick_addr); - - // Add time_zone as offset in minutes. - wxTimeSpan tz = wxTimeSpan::wxTimeSpan(0, (long) time_zone, 0, 0); - - // Get date from ticks + tz. - wxDateTime date = wxDateTime::wxDateTime((time_t)current_tick->tick); - date.Add(tz); - - // Format date string in RFC2822 format (e.g.: Mon, 01 Jan 1990 12:00:00 +0000). - const wxString& str = date.Format("%a, %d %b %Y %T %z", wxDateTime::TZ::UTC); - Memory.WriteString(rfc_addr, str); - - return CELL_OK; -} - -int cellRtcFormatRfc2822LocalTime(u32 rfc_addr, u32 tick_addr) -{ - cellRtc.Log("cellRtcFormatRfc2822LocalTime(rfc_addr=0x%x, tick_addr=0x%x)", rfc_addr, tick_addr); - CellRtcTick *current_tick = new CellRtcTick; - current_tick->tick = Memory.Read64(tick_addr); - - // Get date from ticks. - wxDateTime date = wxDateTime::wxDateTime((time_t)current_tick->tick); - - // Format date string in RFC2822 format (e.g.: Mon, 01 Jan 1990 12:00:00 +0000). - const wxString& str = date.Format("%a, %d %b %Y %T %z", wxDateTime::TZ::Local); - Memory.WriteString(rfc_addr, str); - - return CELL_OK; -} - -int cellRtcFormatRfc3339(u32 rfc_addr, u32 tick_addr, int time_zone) -{ - cellRtc.Log("cellRtcFormatRfc3339(rfc_addr=0x%x, tick_addr=0x%x, time_zone=%d)", rfc_addr, tick_addr, time_zone); - CellRtcTick *current_tick = new CellRtcTick; - current_tick->tick = Memory.Read64(tick_addr); - - // Add time_zone as offset in minutes. - wxTimeSpan tz = wxTimeSpan::wxTimeSpan(0, (long) time_zone, 0, 0); - - // Get date from ticks + tz. - wxDateTime date = wxDateTime::wxDateTime((time_t)current_tick->tick); - date.Add(tz); - - // Format date string in RFC3339 format (e.g.: 1990-01-01T12:00:00.00Z). - const wxString& str = date.Format("%FT%T.%zZ", wxDateTime::TZ::UTC); - Memory.WriteString(rfc_addr, str); - - return CELL_OK; -} - -int cellRtcFormatRfc3339LocalTime(u32 rfc_addr, u32 tick_addr) -{ - cellRtc.Log("cellRtcFormatRfc3339LocalTime(rfc_addr=0x%x, tick_addr=0x%x)", rfc_addr, tick_addr); - CellRtcTick *current_tick = new CellRtcTick; - current_tick->tick = Memory.Read64(tick_addr); - - // Get date from ticks. - wxDateTime date = wxDateTime::wxDateTime((time_t)current_tick->tick); - - // Format date string in RFC3339 format (e.g.: 1990-01-01T12:00:00.00Z). - const wxString& str = date.Format("%FT%T.%zZ", wxDateTime::TZ::Local); - Memory.WriteString(rfc_addr, str); - - return CELL_OK; -} - -int cellRtcParseDateTime(mem64_t tick, u32 datetime_addr) -{ - cellRtc.Log("cellRtcParseDateTime(tick_addr=0x%x, datetime_addr=0x%x)", tick.GetAddr(), datetime_addr); - - const wxString& format = Memory.ReadString(datetime_addr); - - // Get date from formatted string. - wxDateTime date; - date.ParseDateTime(format); - - tick = date.GetTicks(); - - return CELL_OK; -} - -int cellRtcParseRfc3339(mem64_t tick, u32 datetime_addr) -{ - cellRtc.Log("cellRtcParseRfc3339(tick_addr=0x%x, datetime_addr=0x%x)", tick.GetAddr(), datetime_addr); - - const wxString& format = Memory.ReadString(datetime_addr); - - // Get date from RFC3339 formatted string. - wxDateTime date; - date.ParseDateTime(format); - - tick = date.GetTicks(); - - return CELL_OK; -} - -int cellRtcGetTick(u32 clock_addr, mem64_t tick) -{ - cellRtc.Log("cellRtcGetTick(clock_addr=0x%x, tick_addr=0x%x)", clock_addr, tick.GetAddr()); - - CellRtcDateTime *clock = new CellRtcDateTime; - clock->year = Memory.Read16(clock_addr); - clock->month = Memory.Read16(clock_addr + 2); - clock->day = Memory.Read16(clock_addr + 4); - clock->hour = Memory.Read16(clock_addr + 6); - clock->minute = Memory.Read16(clock_addr + 8); - clock->second = Memory.Read16(clock_addr + 10); - clock->microsecond = Memory.Read32(clock_addr + 12); - - wxDateTime datetime = wxDateTime::wxDateTime(clock->day, (wxDateTime::Month)clock->month, clock->year, clock->hour, clock->minute, clock->second, (clock->microsecond / 1000)); - tick = datetime.GetTicks(); - - return CELL_OK; -} - -int cellRtcSetTick(u32 clock_addr, u32 tick_addr) -{ - cellRtc.Log("cellRtcSetTick(clock_addr=0x%x, tick_addr=0x%x)", clock_addr, tick_addr); - CellRtcTick *current_tick = new CellRtcTick; - current_tick->tick = Memory.Read64(tick_addr); - - wxDateTime date = wxDateTime::wxDateTime((time_t)current_tick->tick); - - CellRtcDateTime *clock = new CellRtcDateTime; - clock->year = date.GetYear(wxDateTime::TZ::UTC); - clock->month = date.GetMonth(wxDateTime::TZ::UTC); - clock->day = date.GetDay(wxDateTime::TZ::UTC); - clock->hour = date.GetHour(wxDateTime::TZ::UTC); - clock->minute = date.GetMinute(wxDateTime::TZ::UTC); - clock->second = date.GetSecond(wxDateTime::TZ::UTC); - clock->microsecond = date.GetMillisecond(wxDateTime::TZ::UTC) * 1000; - - Memory.Write16(clock_addr, clock->year); - Memory.Write16(clock_addr + 2, clock->month); - Memory.Write16(clock_addr + 4, clock->day); - Memory.Write16(clock_addr + 6, clock->hour); - Memory.Write16(clock_addr + 8, clock->minute); - Memory.Write16(clock_addr + 10, clock->second); - Memory.Write32(clock_addr + 12, clock->microsecond); - - return CELL_OK; -} - -int cellRtcTickAddTicks(mem64_t tick, u32 tick_add_addr, long add) -{ - cellRtc.Log("cellRtcTickAddTicks(tick_addr=0x%x, tick_add_addr=0x%x, add=%l)", tick.GetAddr(), tick_add_addr, add); - tick = Memory.Read64(tick_add_addr) + add; - - return CELL_OK; -} - -int cellRtcTickAddMicroseconds(mem64_t tick, u32 tick_add_addr, long add) -{ - cellRtc.Log("cellRtcTickAddMicroseconds(tick_addr=0x%x, tick_add_addr=0x%x, add=%l)", tick.GetAddr(), tick_add_addr, add); - - wxDateTime date = wxDateTime::wxDateTime((time_t)Memory.Read64(tick_add_addr)); - wxTimeSpan microseconds = wxTimeSpan::wxTimeSpan(0, 0, 0, add / 1000); - date.Add(microseconds); - tick = date.GetTicks(); - - return CELL_OK; -} - -int cellRtcTickAddSeconds(mem64_t tick, u32 tick_add_addr, long add) -{ - cellRtc.Log("cellRtcTickAddSeconds(tick_addr=0x%x, tick_add_addr=0x%x, add=%l)", tick.GetAddr(), tick_add_addr, add); - - wxDateTime date = wxDateTime::wxDateTime((time_t)Memory.Read64(tick_add_addr)); - wxTimeSpan seconds = wxTimeSpan::wxTimeSpan(0, 0, add, 0); - date.Add(seconds); - tick = date.GetTicks(); - - return CELL_OK; -} - -int cellRtcTickAddMinutes(mem64_t tick, u32 tick_add_addr, long add) -{ - cellRtc.Log("cellRtcTickAddMinutes(tick_addr=0x%x, tick_add_addr=0x%x, add=%l)", tick.GetAddr(), tick_add_addr, add); - - wxDateTime date = wxDateTime::wxDateTime((time_t)Memory.Read64(tick_add_addr)); - wxTimeSpan minutes = wxTimeSpan::wxTimeSpan(0, add, 0, 0); - date.Add(minutes); - tick = date.GetTicks(); - - return CELL_OK; -} - -int cellRtcTickAddHours(mem64_t tick, u32 tick_add_addr, int add) -{ - cellRtc.Log("cellRtcTickAddHours(tick_addr=0x%x, tick_add_addr=0x%x, add=%l)", tick.GetAddr(), tick_add_addr, add); - - wxDateTime date = wxDateTime::wxDateTime((time_t)Memory.Read64(tick_add_addr)); - wxTimeSpan hours = wxTimeSpan::wxTimeSpan(add, 0, 0, 0); - date.Add(hours); - tick = date.GetTicks(); - - return CELL_OK; -} - -int cellRtcTickAddDays(mem64_t tick, u32 tick_add_addr, int add) -{ - cellRtc.Log("cellRtcTickAddDays(tick_addr=0x%x, tick_add_addr=0x%x, add=%l)", tick.GetAddr(), tick_add_addr, add); - - wxDateTime date = wxDateTime::wxDateTime((time_t)Memory.Read64(tick_add_addr)); - wxDateSpan days = wxDateSpan::wxDateSpan(0, 0, 0, add); - date.Add(days); - tick = date.GetTicks(); - - return CELL_OK; -} - -int cellRtcTickAddWeeks(mem64_t tick, u32 tick_add_addr, int add) -{ - cellRtc.Log("cellRtcTickAddWeeks(tick_addr=0x%x, tick_add_addr=0x%x, add=%l)", tick.GetAddr(), tick_add_addr, add); - - wxDateTime date = wxDateTime::wxDateTime((time_t)Memory.Read64(tick_add_addr)); - wxDateSpan weeks = wxDateSpan::wxDateSpan(0, 0, add, 0); - date.Add(weeks); - tick = date.GetTicks(); - - return CELL_OK; -} - -int cellRtcTickAddMonths(mem64_t tick, u32 tick_add_addr, int add) -{ - cellRtc.Log("cellRtcTickAddMonths(tick_addr=0x%x, tick_add_addr=0x%x, add=%l)", tick.GetAddr(), tick_add_addr, add); - - wxDateTime date = wxDateTime::wxDateTime((time_t)Memory.Read64(tick_add_addr)); - wxDateSpan months = wxDateSpan::wxDateSpan(0, add, 0, 0); - date.Add(months); - tick = date.GetTicks(); - - return CELL_OK; -} - -int cellRtcTickAddYears(mem64_t tick, u32 tick_add_addr, int add) -{ - cellRtc.Log("cellRtcTickAddYears(tick_addr=0x%x, tick_add_addr=0x%x, add=%l)", tick.GetAddr(), tick_add_addr, add); - - wxDateTime date = wxDateTime::wxDateTime((time_t)Memory.Read64(tick_add_addr)); - wxDateSpan years = wxDateSpan::wxDateSpan(add, 0, 0, 0); - date.Add(years); - tick = date.GetTicks(); - - return CELL_OK; -} - -int cellRtcConvertUtcToLocalTime(u32 tick_utc_addr, mem64_t tick_local) -{ - cellRtc.Log("cellRtcConvertUtcToLocalTime(tick_utc_addr=0x%x, tick_local_addr=0x%x)", tick_utc_addr, tick_local.GetAddr()); - wxDateTime time = wxDateTime::wxDateTime((time_t)Memory.Read64(tick_utc_addr)); - wxDateTime local_time = time.FromUTC(false); - tick_local = local_time.GetTicks(); - return CELL_OK; -} - -int cellRtcConvertLocalTimeToUtc(u32 tick_local_addr, mem64_t tick_utc) -{ - cellRtc.Log("cellRtcConvertLocalTimeToUtc(tick_local_addr=0x%x, tick_utc_addr=0x%x)", tick_local_addr, tick_utc.GetAddr()); - wxDateTime time = wxDateTime::wxDateTime((time_t)Memory.Read64(tick_local_addr)); - wxDateTime utc_time = time.ToUTC(false); - tick_utc = utc_time.GetTicks(); - return CELL_OK; -} - -int cellRtcGetDosTime(u32 datetime_addr, mem64_t dos_time) -{ - cellRtc.Log("cellRtcGetDosTime(datetime_addr=0x%x, dos_time_addr=0x%x)", datetime_addr, dos_time.GetAddr()); - CellRtcDateTime *datetime = new CellRtcDateTime; - datetime->year = Memory.Read16(datetime_addr); - datetime->month = Memory.Read16(datetime_addr + 2); - datetime->day = Memory.Read16(datetime_addr + 4); - datetime->hour = Memory.Read16(datetime_addr + 6); - datetime->minute = Memory.Read16(datetime_addr + 8); - datetime->second = Memory.Read16(datetime_addr + 10); - datetime->microsecond = Memory.Read32(datetime_addr + 12); - - // Convert to DOS time. - wxDateTime date_time = wxDateTime::wxDateTime(datetime->day, (wxDateTime::Month)datetime->month, datetime->year, datetime->hour, datetime->minute, datetime->second, (datetime->microsecond / 1000)); - dos_time = date_time.GetAsDOS(); - - return CELL_OK; -} - -int cellRtcGetTime_t(u32 datetime_addr, mem64_t posix_time) -{ - cellRtc.Log("cellRtcGetTime_t(datetime_addr=0x%x, posix_time_addr=0x%x)", datetime_addr, posix_time.GetAddr()); - CellRtcDateTime *datetime = new CellRtcDateTime; - datetime->year = Memory.Read16(datetime_addr); - datetime->month = Memory.Read16(datetime_addr + 2); - datetime->day = Memory.Read16(datetime_addr + 4); - datetime->hour = Memory.Read16(datetime_addr + 6); - datetime->minute = Memory.Read16(datetime_addr + 8); - datetime->second = Memory.Read16(datetime_addr + 10); - datetime->microsecond = Memory.Read32(datetime_addr + 12); - - // Convert to POSIX time_t. - wxDateTime date_time = wxDateTime::wxDateTime(datetime->day, (wxDateTime::Month)datetime->month, datetime->year, datetime->hour, datetime->minute, datetime->second, (datetime->microsecond / 1000)); +}; + +long convertToUNIXTime(u16 seconds, u16 minutes, u16 hours, u16 days, int years) +{ + return (seconds + minutes*60 + hours*3600 + days*86400 + (years-70)*31536000 + ((years-69)/4)*86400 - ((years-1)/100)*86400 + ((years+299)/400)*86400); +} + +u64 convertToWin32FILETIME(u16 seconds, u16 minutes, u16 hours, u16 days, int years) +{ + long unixtime = convertToUNIXTime(seconds, minutes, hours, days, years); + LONGLONG win32time = Int32x32To64(unixtime, 10000000) + 116444736000000000; + u64 win32filetime = (u64) win32time | win32time >> 32; + return win32filetime; +} + +int cellRtcGetCurrentTick(mem64_t tick) +{ + cellRtc.Log("cellRtcGetCurrentTick(tick_addr=0x%x)", tick.GetAddr()); + wxDateTime unow = wxDateTime::UNow(); + tick = unow.GetTicks(); + return CELL_OK; +} + +int cellRtcGetCurrentClock(u32 clock_addr, int time_zone) +{ + cellRtc.Log("cellRtcGetCurrentClock(clock_addr=0x%x, time_zone=%d)", clock_addr, time_zone); + wxDateTime unow = wxDateTime::UNow(); + + // Add time_zone as offset in minutes. + wxTimeSpan tz = wxTimeSpan::wxTimeSpan(0, (long) time_zone, 0, 0); + unow.Add(tz); + + Memory.Write16(clock_addr, unow.GetYear(wxDateTime::TZ::UTC)); + Memory.Write16(clock_addr + 2, unow.GetMonth(wxDateTime::TZ::UTC)); + Memory.Write16(clock_addr + 4, unow.GetDay(wxDateTime::TZ::UTC)); + Memory.Write16(clock_addr + 6, unow.GetHour(wxDateTime::TZ::UTC)); + Memory.Write16(clock_addr + 8, unow.GetMinute(wxDateTime::TZ::UTC)); + Memory.Write16(clock_addr + 10, unow.GetSecond(wxDateTime::TZ::UTC)); + Memory.Write32(clock_addr + 12, unow.GetMillisecond(wxDateTime::TZ::UTC) * 1000); + + return CELL_OK; +} + +int cellRtcGetCurrentClockLocalTime(u32 clock_addr) +{ + cellRtc.Log("cellRtcGetCurrentClockLocalTime(clock_addr=0x%x)", clock_addr); + wxDateTime unow = wxDateTime::UNow(); + + Memory.Write16(clock_addr, unow.GetYear(wxDateTime::TZ::Local)); + Memory.Write16(clock_addr + 2, unow.GetMonth(wxDateTime::TZ::Local)); + Memory.Write16(clock_addr + 4, unow.GetDay(wxDateTime::TZ::Local)); + Memory.Write16(clock_addr + 6, unow.GetHour(wxDateTime::TZ::Local)); + Memory.Write16(clock_addr + 8, unow.GetMinute(wxDateTime::TZ::Local)); + Memory.Write16(clock_addr + 10, unow.GetSecond(wxDateTime::TZ::Local)); + Memory.Write32(clock_addr + 12, unow.GetMillisecond(wxDateTime::TZ::Local) * 1000); + + return CELL_OK; +} + +int cellRtcFormatRfc2822(u32 rfc_addr, u32 tick_addr, int time_zone) +{ + cellRtc.Log("cellRtcFormatRfc2822(rfc_addr=0x%x, tick_addr=0x%x, time_zone=%d)", rfc_addr, tick_addr, time_zone); + CellRtcTick current_tick; + current_tick.tick = Memory.Read64(tick_addr); + + // Add time_zone as offset in minutes. + wxTimeSpan tz = wxTimeSpan::wxTimeSpan(0, (long) time_zone, 0, 0); + + // Get date from ticks + tz. + wxDateTime date = wxDateTime::wxDateTime((time_t)current_tick.tick); + date.Add(tz); + + // Format date string in RFC2822 format (e.g.: Mon, 01 Jan 1990 12:00:00 +0000). + const wxString& str = date.Format("%a, %d %b %Y %T %z", wxDateTime::TZ::UTC); + Memory.WriteString(rfc_addr, str); + + return CELL_OK; +} + +int cellRtcFormatRfc2822LocalTime(u32 rfc_addr, u32 tick_addr) +{ + cellRtc.Log("cellRtcFormatRfc2822LocalTime(rfc_addr=0x%x, tick_addr=0x%x)", rfc_addr, tick_addr); + CellRtcTick current_tick; + current_tick.tick = Memory.Read64(tick_addr); + + // Get date from ticks. + wxDateTime date = wxDateTime::wxDateTime((time_t)current_tick.tick); + + // Format date string in RFC2822 format (e.g.: Mon, 01 Jan 1990 12:00:00 +0000). + const wxString& str = date.Format("%a, %d %b %Y %T %z", wxDateTime::TZ::Local); + Memory.WriteString(rfc_addr, str); + + return CELL_OK; +} + +int cellRtcFormatRfc3339(u32 rfc_addr, u32 tick_addr, int time_zone) +{ + cellRtc.Log("cellRtcFormatRfc3339(rfc_addr=0x%x, tick_addr=0x%x, time_zone=%d)", rfc_addr, tick_addr, time_zone); + CellRtcTick current_tick; + current_tick.tick = Memory.Read64(tick_addr); + + // Add time_zone as offset in minutes. + wxTimeSpan tz = wxTimeSpan::wxTimeSpan(0, (long) time_zone, 0, 0); + + // Get date from ticks + tz. + wxDateTime date = wxDateTime::wxDateTime((time_t)current_tick.tick); + date.Add(tz); + + // Format date string in RFC3339 format (e.g.: 1990-01-01T12:00:00.00Z). + const wxString& str = date.Format("%FT%T.%zZ", wxDateTime::TZ::UTC); + Memory.WriteString(rfc_addr, str); + + return CELL_OK; +} + +int cellRtcFormatRfc3339LocalTime(u32 rfc_addr, u32 tick_addr) +{ + cellRtc.Log("cellRtcFormatRfc3339LocalTime(rfc_addr=0x%x, tick_addr=0x%x)", rfc_addr, tick_addr); + CellRtcTick current_tick; + current_tick.tick = Memory.Read64(tick_addr); + + // Get date from ticks. + wxDateTime date = wxDateTime::wxDateTime((time_t)current_tick.tick); + + // Format date string in RFC3339 format (e.g.: 1990-01-01T12:00:00.00Z). + const wxString& str = date.Format("%FT%T.%zZ", wxDateTime::TZ::Local); + Memory.WriteString(rfc_addr, str); + + return CELL_OK; +} + +int cellRtcParseDateTime(mem64_t tick, u32 datetime_addr) +{ + cellRtc.Log("cellRtcParseDateTime(tick_addr=0x%x, datetime_addr=0x%x)", tick.GetAddr(), datetime_addr); + + const wxString& format = Memory.ReadString(datetime_addr); + + // Get date from formatted string. + wxDateTime date; + date.ParseDateTime(format); + + tick = date.GetTicks(); + + return CELL_OK; +} + +int cellRtcParseRfc3339(mem64_t tick, u32 datetime_addr) +{ + cellRtc.Log("cellRtcParseRfc3339(tick_addr=0x%x, datetime_addr=0x%x)", tick.GetAddr(), datetime_addr); + + const wxString& format = Memory.ReadString(datetime_addr); + + // Get date from RFC3339 formatted string. + wxDateTime date; + date.ParseDateTime(format); + + tick = date.GetTicks(); + + return CELL_OK; +} + +int cellRtcGetTick(u32 clock_addr, mem64_t tick) +{ + cellRtc.Log("cellRtcGetTick(clock_addr=0x%x, tick_addr=0x%x)", clock_addr, tick.GetAddr()); + + CellRtcDateTime clock; + clock.year = Memory.Read16(clock_addr); + clock.month = Memory.Read16(clock_addr + 2); + clock.day = Memory.Read16(clock_addr + 4); + clock.hour = Memory.Read16(clock_addr + 6); + clock.minute = Memory.Read16(clock_addr + 8); + clock.second = Memory.Read16(clock_addr + 10); + clock.microsecond = Memory.Read32(clock_addr + 12); + + wxDateTime datetime = wxDateTime::wxDateTime(clock.day, (wxDateTime::Month)clock.month, clock.year, clock.hour, clock.minute, clock.second, (clock.microsecond / 1000)); + tick = datetime.GetTicks(); + + return CELL_OK; +} + +int cellRtcSetTick(u32 clock_addr, u32 tick_addr) +{ + cellRtc.Log("cellRtcSetTick(clock_addr=0x%x, tick_addr=0x%x)", clock_addr, tick_addr); + CellRtcTick current_tick; + current_tick.tick = Memory.Read64(tick_addr); + + wxDateTime date = wxDateTime::wxDateTime((time_t)current_tick.tick); + + CellRtcDateTime clock; + clock.year = date.GetYear(wxDateTime::TZ::UTC); + clock.month = date.GetMonth(wxDateTime::TZ::UTC); + clock.day = date.GetDay(wxDateTime::TZ::UTC); + clock.hour = date.GetHour(wxDateTime::TZ::UTC); + clock.minute = date.GetMinute(wxDateTime::TZ::UTC); + clock.second = date.GetSecond(wxDateTime::TZ::UTC); + clock.microsecond = date.GetMillisecond(wxDateTime::TZ::UTC) * 1000; + + Memory.Write16(clock_addr, clock.year); + Memory.Write16(clock_addr + 2, clock.month); + Memory.Write16(clock_addr + 4, clock.day); + Memory.Write16(clock_addr + 6, clock.hour); + Memory.Write16(clock_addr + 8, clock.minute); + Memory.Write16(clock_addr + 10, clock.second); + Memory.Write32(clock_addr + 12, clock.microsecond); + + return CELL_OK; +} + +int cellRtcTickAddTicks(mem64_t tick, u32 tick_add_addr, long add) +{ + cellRtc.Log("cellRtcTickAddTicks(tick_addr=0x%x, tick_add_addr=0x%x, add=%l)", tick.GetAddr(), tick_add_addr, add); + tick = Memory.Read64(tick_add_addr) + add; + + return CELL_OK; +} + +int cellRtcTickAddMicroseconds(mem64_t tick, u32 tick_add_addr, long add) +{ + cellRtc.Log("cellRtcTickAddMicroseconds(tick_addr=0x%x, tick_add_addr=0x%x, add=%l)", tick.GetAddr(), tick_add_addr, add); + + wxDateTime date = wxDateTime::wxDateTime((time_t)Memory.Read64(tick_add_addr)); + wxTimeSpan microseconds = wxTimeSpan::wxTimeSpan(0, 0, 0, add / 1000); + date.Add(microseconds); + tick = date.GetTicks(); + + return CELL_OK; +} + +int cellRtcTickAddSeconds(mem64_t tick, u32 tick_add_addr, long add) +{ + cellRtc.Log("cellRtcTickAddSeconds(tick_addr=0x%x, tick_add_addr=0x%x, add=%l)", tick.GetAddr(), tick_add_addr, add); + + wxDateTime date = wxDateTime::wxDateTime((time_t)Memory.Read64(tick_add_addr)); + wxTimeSpan seconds = wxTimeSpan::wxTimeSpan(0, 0, add, 0); + date.Add(seconds); + tick = date.GetTicks(); + + return CELL_OK; +} + +int cellRtcTickAddMinutes(mem64_t tick, u32 tick_add_addr, long add) +{ + cellRtc.Log("cellRtcTickAddMinutes(tick_addr=0x%x, tick_add_addr=0x%x, add=%l)", tick.GetAddr(), tick_add_addr, add); + + wxDateTime date = wxDateTime::wxDateTime((time_t)Memory.Read64(tick_add_addr)); + wxTimeSpan minutes = wxTimeSpan::wxTimeSpan(0, add, 0, 0); + date.Add(minutes); + tick = date.GetTicks(); + + return CELL_OK; +} + +int cellRtcTickAddHours(mem64_t tick, u32 tick_add_addr, int add) +{ + cellRtc.Log("cellRtcTickAddHours(tick_addr=0x%x, tick_add_addr=0x%x, add=%l)", tick.GetAddr(), tick_add_addr, add); + + wxDateTime date = wxDateTime::wxDateTime((time_t)Memory.Read64(tick_add_addr)); + wxTimeSpan hours = wxTimeSpan::wxTimeSpan(add, 0, 0, 0); + date.Add(hours); + tick = date.GetTicks(); + + return CELL_OK; +} + +int cellRtcTickAddDays(mem64_t tick, u32 tick_add_addr, int add) +{ + cellRtc.Log("cellRtcTickAddDays(tick_addr=0x%x, tick_add_addr=0x%x, add=%l)", tick.GetAddr(), tick_add_addr, add); + + wxDateTime date = wxDateTime::wxDateTime((time_t)Memory.Read64(tick_add_addr)); + wxDateSpan days = wxDateSpan::wxDateSpan(0, 0, 0, add); + date.Add(days); + tick = date.GetTicks(); + + return CELL_OK; +} + +int cellRtcTickAddWeeks(mem64_t tick, u32 tick_add_addr, int add) +{ + cellRtc.Log("cellRtcTickAddWeeks(tick_addr=0x%x, tick_add_addr=0x%x, add=%l)", tick.GetAddr(), tick_add_addr, add); + + wxDateTime date = wxDateTime::wxDateTime((time_t)Memory.Read64(tick_add_addr)); + wxDateSpan weeks = wxDateSpan::wxDateSpan(0, 0, add, 0); + date.Add(weeks); + tick = date.GetTicks(); + + return CELL_OK; +} + +int cellRtcTickAddMonths(mem64_t tick, u32 tick_add_addr, int add) +{ + cellRtc.Log("cellRtcTickAddMonths(tick_addr=0x%x, tick_add_addr=0x%x, add=%l)", tick.GetAddr(), tick_add_addr, add); + + wxDateTime date = wxDateTime::wxDateTime((time_t)Memory.Read64(tick_add_addr)); + wxDateSpan months = wxDateSpan::wxDateSpan(0, add, 0, 0); + date.Add(months); + tick = date.GetTicks(); + + return CELL_OK; +} + +int cellRtcTickAddYears(mem64_t tick, u32 tick_add_addr, int add) +{ + cellRtc.Log("cellRtcTickAddYears(tick_addr=0x%x, tick_add_addr=0x%x, add=%l)", tick.GetAddr(), tick_add_addr, add); + + wxDateTime date = wxDateTime::wxDateTime((time_t)Memory.Read64(tick_add_addr)); + wxDateSpan years = wxDateSpan::wxDateSpan(add, 0, 0, 0); + date.Add(years); + tick = date.GetTicks(); + + return CELL_OK; +} + +int cellRtcConvertUtcToLocalTime(u32 tick_utc_addr, mem64_t tick_local) +{ + cellRtc.Log("cellRtcConvertUtcToLocalTime(tick_utc_addr=0x%x, tick_local_addr=0x%x)", tick_utc_addr, tick_local.GetAddr()); + wxDateTime time = wxDateTime::wxDateTime((time_t)Memory.Read64(tick_utc_addr)); + wxDateTime local_time = time.FromUTC(false); + tick_local = local_time.GetTicks(); + return CELL_OK; +} + +int cellRtcConvertLocalTimeToUtc(u32 tick_local_addr, mem64_t tick_utc) +{ + cellRtc.Log("cellRtcConvertLocalTimeToUtc(tick_local_addr=0x%x, tick_utc_addr=0x%x)", tick_local_addr, tick_utc.GetAddr()); + wxDateTime time = wxDateTime::wxDateTime((time_t)Memory.Read64(tick_local_addr)); + wxDateTime utc_time = time.ToUTC(false); + tick_utc = utc_time.GetTicks(); + return CELL_OK; +} + +int cellRtcGetDosTime(u32 datetime_addr, mem64_t dos_time) +{ + cellRtc.Log("cellRtcGetDosTime(datetime_addr=0x%x, dos_time_addr=0x%x)", datetime_addr, dos_time.GetAddr()); + CellRtcDateTime datetime; + datetime.year = Memory.Read16(datetime_addr); + datetime.month = Memory.Read16(datetime_addr + 2); + datetime.day = Memory.Read16(datetime_addr + 4); + datetime.hour = Memory.Read16(datetime_addr + 6); + datetime.minute = Memory.Read16(datetime_addr + 8); + datetime.second = Memory.Read16(datetime_addr + 10); + datetime.microsecond = Memory.Read32(datetime_addr + 12); + + // Convert to DOS time. + wxDateTime date_time = wxDateTime::wxDateTime(datetime.day, (wxDateTime::Month)datetime.month, datetime.year, datetime.hour, datetime.minute, datetime.second, (datetime.microsecond / 1000)); + dos_time = date_time.GetAsDOS(); + + return CELL_OK; +} + +int cellRtcGetTime_t(u32 datetime_addr, mem64_t posix_time) +{ + cellRtc.Log("cellRtcGetTime_t(datetime_addr=0x%x, posix_time_addr=0x%x)", datetime_addr, posix_time.GetAddr()); + CellRtcDateTime datetime; + datetime.year = Memory.Read16(datetime_addr); + datetime.month = Memory.Read16(datetime_addr + 2); + datetime.day = Memory.Read16(datetime_addr + 4); + datetime.hour = Memory.Read16(datetime_addr + 6); + datetime.minute = Memory.Read16(datetime_addr + 8); + datetime.second = Memory.Read16(datetime_addr + 10); + datetime.microsecond = Memory.Read32(datetime_addr + 12); + + // Convert to POSIX time_t. + wxDateTime date_time = wxDateTime::wxDateTime(datetime.day, (wxDateTime::Month)datetime.month, datetime.year, datetime.hour, datetime.minute, datetime.second, (datetime.microsecond / 1000)); posix_time = convertToUNIXTime(date_time.GetSecond(wxDateTime::TZ::UTC), date_time.GetMinute(wxDateTime::TZ::UTC), - date_time.GetHour(wxDateTime::TZ::UTC), date_time.GetDay(wxDateTime::TZ::UTC), date_time.GetYear(wxDateTime::TZ::UTC)); - - return CELL_OK; -} - -int cellRtcGetWin32FileTime(u32 datetime_addr, mem64_t win32_time) -{ - cellRtc.Log("cellRtcGetWin32FileTime(datetime_addr=0x%x, win32_time_addr=0x%x)", datetime_addr, win32_time.GetAddr()); - CellRtcDateTime *datetime = new CellRtcDateTime; - datetime->year = Memory.Read16(datetime_addr); - datetime->month = Memory.Read16(datetime_addr + 2); - datetime->day = Memory.Read16(datetime_addr + 4); - datetime->hour = Memory.Read16(datetime_addr + 6); - datetime->minute = Memory.Read16(datetime_addr + 8); - datetime->second = Memory.Read16(datetime_addr + 10); - datetime->microsecond = Memory.Read32(datetime_addr + 12); - - // Convert to WIN32 FILETIME. - wxDateTime date_time = wxDateTime::wxDateTime(datetime->day, (wxDateTime::Month)datetime->month, datetime->year, datetime->hour, datetime->minute, datetime->second, (datetime->microsecond / 1000)); + date_time.GetHour(wxDateTime::TZ::UTC), date_time.GetDay(wxDateTime::TZ::UTC), date_time.GetYear(wxDateTime::TZ::UTC)); + + return CELL_OK; +} + +int cellRtcGetWin32FileTime(u32 datetime_addr, mem64_t win32_time) +{ + cellRtc.Log("cellRtcGetWin32FileTime(datetime_addr=0x%x, win32_time_addr=0x%x)", datetime_addr, win32_time.GetAddr()); + CellRtcDateTime datetime; + datetime.year = Memory.Read16(datetime_addr); + datetime.month = Memory.Read16(datetime_addr + 2); + datetime.day = Memory.Read16(datetime_addr + 4); + datetime.hour = Memory.Read16(datetime_addr + 6); + datetime.minute = Memory.Read16(datetime_addr + 8); + datetime.second = Memory.Read16(datetime_addr + 10); + datetime.microsecond = Memory.Read32(datetime_addr + 12); + + // Convert to WIN32 FILETIME. + wxDateTime date_time = wxDateTime::wxDateTime(datetime.day, (wxDateTime::Month)datetime.month, datetime.year, datetime.hour, datetime.minute, datetime.second, (datetime.microsecond / 1000)); win32_time = convertToWin32FILETIME(date_time.GetSecond(wxDateTime::TZ::UTC), date_time.GetMinute(wxDateTime::TZ::UTC), - date_time.GetHour(wxDateTime::TZ::UTC), date_time.GetDay(wxDateTime::TZ::UTC), date_time.GetYear(wxDateTime::TZ::UTC)); - - return CELL_OK; -} - -int cellRtcSetDosTime(u32 datetime_addr, u32 dos_time_addr) -{ - cellRtc.Log("cellRtcSetDosTime(datetime_addr=0x%x, dos_time_addr=0x%x)", datetime_addr, dos_time_addr); - - wxDateTime date_time; - wxDateTime dos_time = date_time.SetFromDOS(Memory.Read32(dos_time_addr)); - - CellRtcDateTime *datetime = new CellRtcDateTime; - datetime->year = dos_time.GetYear(wxDateTime::TZ::UTC); - datetime->month = dos_time.GetMonth(wxDateTime::TZ::UTC); - datetime->day = dos_time.GetDay(wxDateTime::TZ::UTC); - datetime->hour = dos_time.GetHour(wxDateTime::TZ::UTC); - datetime->minute = dos_time.GetMinute(wxDateTime::TZ::UTC); - datetime->second = dos_time.GetSecond(wxDateTime::TZ::UTC); - datetime->microsecond = dos_time.GetMillisecond(wxDateTime::TZ::UTC) * 1000; - - Memory.Write16(datetime_addr, datetime->year); - Memory.Write16(datetime_addr + 2, datetime->month); - Memory.Write16(datetime_addr + 4, datetime->day); - Memory.Write16(datetime_addr + 6, datetime->hour); - Memory.Write16(datetime_addr + 8, datetime->minute); - Memory.Write16(datetime_addr + 10, datetime->second); - Memory.Write32(datetime_addr + 12, datetime->microsecond); - - return CELL_OK; -} - -int cellRtcSetTime_t(u32 datetime_addr, u32 posix_time_addr) -{ - cellRtc.Log("cellRtcSetTime_t(datetime_addr=0x%x, posix_time_addr=0x%x)", datetime_addr, posix_time_addr); - - wxDateTime date_time = wxDateTime::wxDateTime((time_t)Memory.Read64(posix_time_addr)); - - CellRtcDateTime *datetime = new CellRtcDateTime; - datetime->year = date_time.GetYear(wxDateTime::TZ::UTC); - datetime->month = date_time.GetMonth(wxDateTime::TZ::UTC); - datetime->day = date_time.GetDay(wxDateTime::TZ::UTC); - datetime->hour = date_time.GetHour(wxDateTime::TZ::UTC); - datetime->minute = date_time.GetMinute(wxDateTime::TZ::UTC); - datetime->second = date_time.GetSecond(wxDateTime::TZ::UTC); - datetime->microsecond = date_time.GetMillisecond(wxDateTime::TZ::UTC) * 1000; - - Memory.Write16(datetime_addr, datetime->year); - Memory.Write16(datetime_addr + 2, datetime->month); - Memory.Write16(datetime_addr + 4, datetime->day); - Memory.Write16(datetime_addr + 6, datetime->hour); - Memory.Write16(datetime_addr + 8, datetime->minute); - Memory.Write16(datetime_addr + 10, datetime->second); - Memory.Write32(datetime_addr + 12, datetime->microsecond); - - return CELL_OK; -} - -int cellRtcSetWin32FileTime(u32 datetime_addr, u32 win32_time_addr) -{ - cellRtc.Log("cellRtcSetWin32FileTime(datetime_addr=0x%x, win32_time_addr=0x%x)", datetime_addr, win32_time_addr); - - wxDateTime date_time = wxDateTime::wxDateTime((time_t)Memory.Read64(win32_time_addr)); - - CellRtcDateTime *datetime = new CellRtcDateTime; - datetime->year = date_time.GetYear(wxDateTime::TZ::UTC); - datetime->month = date_time.GetMonth(wxDateTime::TZ::UTC); - datetime->day = date_time.GetDay(wxDateTime::TZ::UTC); - datetime->hour = date_time.GetHour(wxDateTime::TZ::UTC); - datetime->minute = date_time.GetMinute(wxDateTime::TZ::UTC); - datetime->second = date_time.GetSecond(wxDateTime::TZ::UTC); - datetime->microsecond = date_time.GetMillisecond(wxDateTime::TZ::UTC) * 1000; - - Memory.Write16(datetime_addr, datetime->year); - Memory.Write16(datetime_addr + 2, datetime->month); - Memory.Write16(datetime_addr + 4, datetime->day); - Memory.Write16(datetime_addr + 6, datetime->hour); - Memory.Write16(datetime_addr + 8, datetime->minute); - Memory.Write16(datetime_addr + 10, datetime->second); - Memory.Write32(datetime_addr + 12, datetime->microsecond); - - return CELL_OK; -} - -int cellRtcIsLeapYear(int year) -{ - cellRtc.Log("cellRtcIsLeapYear(year=%d)", year); - - wxDateTime datetime; - return datetime.IsLeapYear(year, wxDateTime::Gregorian); -} - -int cellRtcGetDaysInMonth(int year, int month) -{ - cellRtc.Log("cellRtcGetDaysInMonth(year=%d, month=%d)", year, month); - - wxDateTime datetime; - return datetime.GetNumberOfDays((wxDateTime::Month) month, year, wxDateTime::Gregorian); -} - -int cellRtcGetDayOfWeek(int year, int month, int day) -{ - cellRtc.Log("cellRtcGetDayOfWeek(year=%d, month=%d, day=%d)", year, month, day); - - wxDateTime datetime; - datetime.SetToWeekDay((wxDateTime::WeekDay) day, 1, (wxDateTime::Month) month, year); - return datetime.GetWeekDay(); -} - -int cellRtcCheckValid(u32 datetime_addr) -{ - cellRtc.Log("cellRtcCheckValid(datetime_addr=0x%x)", datetime_addr); - CellRtcDateTime *datetime = new CellRtcDateTime; - datetime->year = Memory.Read16(datetime_addr); - datetime->month = Memory.Read16(datetime_addr + 2); - datetime->day = Memory.Read16(datetime_addr + 4); - datetime->hour = Memory.Read16(datetime_addr + 6); - datetime->minute = Memory.Read16(datetime_addr + 8); - datetime->second = Memory.Read16(datetime_addr + 10); - datetime->microsecond = Memory.Read32(datetime_addr + 12); - - if((datetime->year < 1) || (datetime->year > 9999)) return CELL_RTC_ERROR_INVALID_YEAR; - else if((datetime->month < 1) || (datetime->month > 12)) return CELL_RTC_ERROR_INVALID_MONTH; - else if((datetime->day < 1) || (datetime->day > 31)) return CELL_RTC_ERROR_INVALID_DAY; - else if((datetime->hour < 0) || (datetime->hour > 23)) return CELL_RTC_ERROR_INVALID_HOUR; - else if((datetime->minute < 0) || (datetime->minute > 59)) return CELL_RTC_ERROR_INVALID_MINUTE; - else if((datetime->second < 0) || (datetime->second > 59)) return CELL_RTC_ERROR_INVALID_SECOND; - else if((datetime->microsecond < 0) || (datetime->microsecond > 999999)) return CELL_RTC_ERROR_INVALID_MICROSECOND; - else return CELL_OK; -} - -int cellRtcCompareTick(u32 tick_addr_1, u32 tick_addr_2) -{ - cellRtc.Log("cellRtcCompareTick(tick_addr_1=0x%x, tick_addr_2=0x%x)", tick_addr_1, tick_addr_2); - long tick1 = Memory.Read64(tick_addr_1); - long tick2 = Memory.Read64(tick_addr_2); - - if(tick1 < tick2) return -1; - else if(tick1 > tick2) return 1; - else return CELL_OK; -} - -void cellRtc_init() -{ - cellRtc.AddFunc(0x9dafc0d9, cellRtcGetCurrentTick); - cellRtc.AddFunc(0x32c941cf, cellRtcGetCurrentClock); - cellRtc.AddFunc(0x2cce9cf5, cellRtcGetCurrentClockLocalTime); - - cellRtc.AddFunc(0x5491b9d5, cellRtcFormatRfc2822); - cellRtc.AddFunc(0xa07c3d2f, cellRtcFormatRfc2822LocalTime); - cellRtc.AddFunc(0xd9c0b463, cellRtcFormatRfc3339); - cellRtc.AddFunc(0x1324948a, cellRtcFormatRfc3339LocalTime); - cellRtc.AddFunc(0xc5bc0fac, cellRtcParseDateTime); - cellRtc.AddFunc(0xcf11c3d6, cellRtcParseRfc3339); - - cellRtc.AddFunc(0xc7bdb7eb, cellRtcGetTick); - cellRtc.AddFunc(0x99b13034, cellRtcSetTick); - cellRtc.AddFunc(0x269a1882, cellRtcTickAddTicks); - cellRtc.AddFunc(0xf8509925, cellRtcTickAddMicroseconds); - cellRtc.AddFunc(0xccce71bd, cellRtcTickAddSeconds); - cellRtc.AddFunc(0x2f010bfa, cellRtcTickAddMinutes); - cellRtc.AddFunc(0xd41d3bd2, cellRtcTickAddHours); - cellRtc.AddFunc(0x75744e2a, cellRtcTickAddDays); - cellRtc.AddFunc(0x64c63fd5, cellRtcTickAddWeeks); - cellRtc.AddFunc(0xe0ecbb45, cellRtcTickAddMonths); - cellRtc.AddFunc(0x332a74dd, cellRtcTickAddYears); - cellRtc.AddFunc(0xc48d5002, cellRtcConvertUtcToLocalTime); - cellRtc.AddFunc(0x46ca7fe0, cellRtcConvertLocalTimeToUtc); - - // (TODO: Time Information Manipulation Functions missing) - - cellRtc.AddFunc(0xdfff32cf, cellRtcGetDosTime); - cellRtc.AddFunc(0xcb90c761, cellRtcGetTime_t); - cellRtc.AddFunc(0xe7086f05, cellRtcGetWin32FileTime); - cellRtc.AddFunc(0x9598d4b3, cellRtcSetDosTime); - cellRtc.AddFunc(0xbb543189, cellRtcSetTime_t); - cellRtc.AddFunc(0x5f68c268, cellRtcSetWin32FileTime); - - cellRtc.AddFunc(0x5316b4a8, cellRtcIsLeapYear); - cellRtc.AddFunc(0x5b6a0a1d, cellRtcGetDaysInMonth); - cellRtc.AddFunc(0xc2d8cf95, cellRtcGetDayOfWeek); - cellRtc.AddFunc(0x7f1086e6, cellRtcCheckValid); - - cellRtc.AddFunc(0xfb51fc61, cellRtcCompareTick); + date_time.GetHour(wxDateTime::TZ::UTC), date_time.GetDay(wxDateTime::TZ::UTC), date_time.GetYear(wxDateTime::TZ::UTC)); + + return CELL_OK; +} + +int cellRtcSetDosTime(u32 datetime_addr, u32 dos_time_addr) +{ + cellRtc.Log("cellRtcSetDosTime(datetime_addr=0x%x, dos_time_addr=0x%x)", datetime_addr, dos_time_addr); + + wxDateTime date_time; + wxDateTime dos_time = date_time.SetFromDOS(Memory.Read32(dos_time_addr)); + + CellRtcDateTime datetime; + datetime.year = dos_time.GetYear(wxDateTime::TZ::UTC); + datetime.month = dos_time.GetMonth(wxDateTime::TZ::UTC); + datetime.day = dos_time.GetDay(wxDateTime::TZ::UTC); + datetime.hour = dos_time.GetHour(wxDateTime::TZ::UTC); + datetime.minute = dos_time.GetMinute(wxDateTime::TZ::UTC); + datetime.second = dos_time.GetSecond(wxDateTime::TZ::UTC); + datetime.microsecond = dos_time.GetMillisecond(wxDateTime::TZ::UTC) * 1000; + + Memory.Write16(datetime_addr, datetime.year); + Memory.Write16(datetime_addr + 2, datetime.month); + Memory.Write16(datetime_addr + 4, datetime.day); + Memory.Write16(datetime_addr + 6, datetime.hour); + Memory.Write16(datetime_addr + 8, datetime.minute); + Memory.Write16(datetime_addr + 10, datetime.second); + Memory.Write32(datetime_addr + 12, datetime.microsecond); + + return CELL_OK; +} + +int cellRtcSetTime_t(u32 datetime_addr, u32 posix_time_addr) +{ + cellRtc.Log("cellRtcSetTime_t(datetime_addr=0x%x, posix_time_addr=0x%x)", datetime_addr, posix_time_addr); + + wxDateTime date_time = wxDateTime::wxDateTime((time_t)Memory.Read64(posix_time_addr)); + + CellRtcDateTime datetime; + datetime.year = date_time.GetYear(wxDateTime::TZ::UTC); + datetime.month = date_time.GetMonth(wxDateTime::TZ::UTC); + datetime.day = date_time.GetDay(wxDateTime::TZ::UTC); + datetime.hour = date_time.GetHour(wxDateTime::TZ::UTC); + datetime.minute = date_time.GetMinute(wxDateTime::TZ::UTC); + datetime.second = date_time.GetSecond(wxDateTime::TZ::UTC); + datetime.microsecond = date_time.GetMillisecond(wxDateTime::TZ::UTC) * 1000; + + Memory.Write16(datetime_addr, datetime.year); + Memory.Write16(datetime_addr + 2, datetime.month); + Memory.Write16(datetime_addr + 4, datetime.day); + Memory.Write16(datetime_addr + 6, datetime.hour); + Memory.Write16(datetime_addr + 8, datetime.minute); + Memory.Write16(datetime_addr + 10, datetime.second); + Memory.Write32(datetime_addr + 12, datetime.microsecond); + + return CELL_OK; +} + +int cellRtcSetWin32FileTime(u32 datetime_addr, u32 win32_time_addr) +{ + cellRtc.Log("cellRtcSetWin32FileTime(datetime_addr=0x%x, win32_time_addr=0x%x)", datetime_addr, win32_time_addr); + + wxDateTime date_time = wxDateTime::wxDateTime((time_t)Memory.Read64(win32_time_addr)); + + CellRtcDateTime datetime; + datetime.year = date_time.GetYear(wxDateTime::TZ::UTC); + datetime.month = date_time.GetMonth(wxDateTime::TZ::UTC); + datetime.day = date_time.GetDay(wxDateTime::TZ::UTC); + datetime.hour = date_time.GetHour(wxDateTime::TZ::UTC); + datetime.minute = date_time.GetMinute(wxDateTime::TZ::UTC); + datetime.second = date_time.GetSecond(wxDateTime::TZ::UTC); + datetime.microsecond = date_time.GetMillisecond(wxDateTime::TZ::UTC) * 1000; + + Memory.Write16(datetime_addr, datetime.year); + Memory.Write16(datetime_addr + 2, datetime.month); + Memory.Write16(datetime_addr + 4, datetime.day); + Memory.Write16(datetime_addr + 6, datetime.hour); + Memory.Write16(datetime_addr + 8, datetime.minute); + Memory.Write16(datetime_addr + 10, datetime.second); + Memory.Write32(datetime_addr + 12, datetime.microsecond); + + return CELL_OK; +} + +int cellRtcIsLeapYear(int year) +{ + cellRtc.Log("cellRtcIsLeapYear(year=%d)", year); + + wxDateTime datetime; + return datetime.IsLeapYear(year, wxDateTime::Gregorian); +} + +int cellRtcGetDaysInMonth(int year, int month) +{ + cellRtc.Log("cellRtcGetDaysInMonth(year=%d, month=%d)", year, month); + + wxDateTime datetime; + return datetime.GetNumberOfDays((wxDateTime::Month) month, year, wxDateTime::Gregorian); +} + +int cellRtcGetDayOfWeek(int year, int month, int day) +{ + cellRtc.Log("cellRtcGetDayOfWeek(year=%d, month=%d, day=%d)", year, month, day); + + wxDateTime datetime; + datetime.SetToWeekDay((wxDateTime::WeekDay) day, 1, (wxDateTime::Month) month, year); + return datetime.GetWeekDay(); +} + +int cellRtcCheckValid(u32 datetime_addr) +{ + cellRtc.Log("cellRtcCheckValid(datetime_addr=0x%x)", datetime_addr); + CellRtcDateTime datetime; + datetime.year = Memory.Read16(datetime_addr); + datetime.month = Memory.Read16(datetime_addr + 2); + datetime.day = Memory.Read16(datetime_addr + 4); + datetime.hour = Memory.Read16(datetime_addr + 6); + datetime.minute = Memory.Read16(datetime_addr + 8); + datetime.second = Memory.Read16(datetime_addr + 10); + datetime.microsecond = Memory.Read32(datetime_addr + 12); + + if((datetime.year < 1) || (datetime.year > 9999)) return CELL_RTC_ERROR_INVALID_YEAR; + else if((datetime.month < 1) || (datetime.month > 12)) return CELL_RTC_ERROR_INVALID_MONTH; + else if((datetime.day < 1) || (datetime.day > 31)) return CELL_RTC_ERROR_INVALID_DAY; + else if((datetime.hour < 0) || (datetime.hour > 23)) return CELL_RTC_ERROR_INVALID_HOUR; + else if((datetime.minute < 0) || (datetime.minute > 59)) return CELL_RTC_ERROR_INVALID_MINUTE; + else if((datetime.second < 0) || (datetime.second > 59)) return CELL_RTC_ERROR_INVALID_SECOND; + else if((datetime.microsecond < 0) || (datetime.microsecond > 999999)) return CELL_RTC_ERROR_INVALID_MICROSECOND; + else return CELL_OK; +} + +int cellRtcCompareTick(u32 tick_addr_1, u32 tick_addr_2) +{ + cellRtc.Log("cellRtcCompareTick(tick_addr_1=0x%x, tick_addr_2=0x%x)", tick_addr_1, tick_addr_2); + u64 tick1 = Memory.Read64(tick_addr_1); + u64 tick2 = Memory.Read64(tick_addr_2); + + if(tick1 < tick2) return -1; + else if(tick1 > tick2) return 1; + else return CELL_OK; +} + +void cellRtc_init() +{ + cellRtc.AddFunc(0x9dafc0d9, cellRtcGetCurrentTick); + cellRtc.AddFunc(0x32c941cf, cellRtcGetCurrentClock); + cellRtc.AddFunc(0x2cce9cf5, cellRtcGetCurrentClockLocalTime); + + cellRtc.AddFunc(0x5491b9d5, cellRtcFormatRfc2822); + cellRtc.AddFunc(0xa07c3d2f, cellRtcFormatRfc2822LocalTime); + cellRtc.AddFunc(0xd9c0b463, cellRtcFormatRfc3339); + cellRtc.AddFunc(0x1324948a, cellRtcFormatRfc3339LocalTime); + cellRtc.AddFunc(0xc5bc0fac, cellRtcParseDateTime); + cellRtc.AddFunc(0xcf11c3d6, cellRtcParseRfc3339); + + cellRtc.AddFunc(0xc7bdb7eb, cellRtcGetTick); + cellRtc.AddFunc(0x99b13034, cellRtcSetTick); + cellRtc.AddFunc(0x269a1882, cellRtcTickAddTicks); + cellRtc.AddFunc(0xf8509925, cellRtcTickAddMicroseconds); + cellRtc.AddFunc(0xccce71bd, cellRtcTickAddSeconds); + cellRtc.AddFunc(0x2f010bfa, cellRtcTickAddMinutes); + cellRtc.AddFunc(0xd41d3bd2, cellRtcTickAddHours); + cellRtc.AddFunc(0x75744e2a, cellRtcTickAddDays); + cellRtc.AddFunc(0x64c63fd5, cellRtcTickAddWeeks); + cellRtc.AddFunc(0xe0ecbb45, cellRtcTickAddMonths); + cellRtc.AddFunc(0x332a74dd, cellRtcTickAddYears); + cellRtc.AddFunc(0xc48d5002, cellRtcConvertUtcToLocalTime); + cellRtc.AddFunc(0x46ca7fe0, cellRtcConvertLocalTimeToUtc); + + // (TODO: Time Information Manipulation Functions missing) + + cellRtc.AddFunc(0xdfff32cf, cellRtcGetDosTime); + cellRtc.AddFunc(0xcb90c761, cellRtcGetTime_t); + cellRtc.AddFunc(0xe7086f05, cellRtcGetWin32FileTime); + cellRtc.AddFunc(0x9598d4b3, cellRtcSetDosTime); + cellRtc.AddFunc(0xbb543189, cellRtcSetTime_t); + cellRtc.AddFunc(0x5f68c268, cellRtcSetWin32FileTime); + + cellRtc.AddFunc(0x5316b4a8, cellRtcIsLeapYear); + cellRtc.AddFunc(0x5b6a0a1d, cellRtcGetDaysInMonth); + cellRtc.AddFunc(0xc2d8cf95, cellRtcGetDayOfWeek); + cellRtc.AddFunc(0x7f1086e6, cellRtcCheckValid); + + cellRtc.AddFunc(0xfb51fc61, cellRtcCompareTick); } \ No newline at end of file diff --git a/rpcs3/Emu/SysCalls/Modules/cellSysmodule.cpp b/rpcs3/Emu/SysCalls/Modules/cellSysmodule.cpp index 09317ea35a..2a88e575f5 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellSysmodule.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellSysmodule.cpp @@ -16,11 +16,11 @@ enum }; const char *getModuleName(int id) { - struct Entry { + struct + { const char *name; int id; - }; - static const Entry entries[] = { + } static const entries[] = { {"CELL_SYSMODULE_INVALID", 0x0000ffff}, {"CELL_SYSMODULE_NET", 0x00000000}, {"CELL_SYSMODULE_HTTP", 0x00000001}, @@ -28,109 +28,113 @@ const char *getModuleName(int id) { {"CELL_SYSMODULE_SSL", 0x00000003}, {"CELL_SYSMODULE_HTTPS", 0x00000004}, {"CELL_SYSMODULE_VDEC", 0x00000005}, - {"CELL_SYSMODULE_ADEC", 0x00000006}, - {"CELL_SYSMODULE_DMUX", 0x00000007}, - {"CELL_SYSMODULE_VPOST", 0x00000008}, - {"CELL_SYSMODULE_RTC", 0x00000009}, - {"CELL_SYSMODULE_SPURS", 0x0000000a}, - {"CELL_SYSMODULE_OVIS", 0x0000000b}, - {"CELL_SYSMODULE_SHEAP", 0x0000000c}, - {"CELL_SYSMODULE_SYNC", 0x0000000d}, - {"CELL_SYSMODULE_FS", 0x0000000e}, - {"CELL_SYSMODULE_JPGDEC", 0x0000000f}, - {"CELL_SYSMODULE_GCM_SYS", 0x00000010}, - {"CELL_SYSMODULE_GCM", 0x00000010}, - {"CELL_SYSMODULE_AUDIO", 0x00000011}, - {"CELL_SYSMODULE_PAMF", 0x00000012}, - {"CELL_SYSMODULE_ATRAC3PLUS", 0x00000013}, - {"CELL_SYSMODULE_NETCTL", 0x00000014}, - {"CELL_SYSMODULE_SYSUTIL", 0x00000015}, - {"CELL_SYSMODULE_SYSUTIL_NP", 0x00000016}, - {"CELL_SYSMODULE_IO", 0x00000017}, - {"CELL_SYSMODULE_PNGDEC", 0x00000018}, - {"CELL_SYSMODULE_FONT", 0x00000019}, - {"CELL_SYSMODULE_FONTFT", 0x0000001a}, - {"CELL_SYSMODULE_FREETYPE", 0x0000001b}, - {"CELL_SYSMODULE_USBD", 0x0000001c}, - {"CELL_SYSMODULE_SAIL", 0x0000001d}, - {"CELL_SYSMODULE_L10N", 0x0000001e}, - {"CELL_SYSMODULE_RESC", 0x0000001f}, - {"CELL_SYSMODULE_DAISY", 0x00000020}, - {"CELL_SYSMODULE_KEY2CHAR", 0x00000021}, - {"CELL_SYSMODULE_MIC", 0x00000022}, - {"CELL_SYSMODULE_CAMERA", 0x00000023}, - {"CELL_SYSMODULE_VDEC_MPEG2", 0x00000024}, - {"CELL_SYSMODULE_VDEC_AVC", 0x00000025}, - {"CELL_SYSMODULE_ADEC_LPCM", 0x00000026}, - {"CELL_SYSMODULE_ADEC_AC3", 0x00000027}, - {"CELL_SYSMODULE_ADEC_ATX", 0x00000028}, - {"CELL_SYSMODULE_ADEC_AT3", 0x00000029}, - {"CELL_SYSMODULE_DMUX_PAMF", 0x0000002a}, - {"CELL_SYSMODULE_VDEC_AL", 0x0000002b}, - {"CELL_SYSMODULE_ADEC_AL", 0x0000002c}, - {"CELL_SYSMODULE_DMUX_AL", 0x0000002d}, - {"CELL_SYSMODULE_LV2DBG", 0x0000002e}, - {"CELL_SYSMODULE_USBPSPCM", 0x00000030}, - {"CELL_SYSMODULE_AVCONF_EXT", 0x00000031}, - {"CELL_SYSMODULE_SYSUTIL_USERINFO", 0x00000032}, - {"CELL_SYSMODULE_SYSUTIL_SAVEDATA", 0x00000033}, - {"CELL_SYSMODULE_SUBDISPLAY", 0x00000034}, - {"CELL_SYSMODULE_SYSUTIL_REC", 0x00000035}, - {"CELL_SYSMODULE_VIDEO_EXPORT", 0x00000036}, - {"CELL_SYSMODULE_SYSUTIL_GAME_EXEC", 0x00000037}, - {"CELL_SYSMODULE_SYSUTIL_NP2", 0x00000038}, - {"CELL_SYSMODULE_SYSUTIL_AP", 0x00000039}, - {"CELL_SYSMODULE_SYSUTIL_NP_CLANS", 0x0000003a}, - {"CELL_SYSMODULE_SYSUTIL_OSK_EXT", 0x0000003b}, - {"CELL_SYSMODULE_VDEC_DIVX", 0x0000003c}, - {"CELL_SYSMODULE_JPGENC", 0x0000003d}, - {"CELL_SYSMODULE_SYSUTIL_GAME", 0x0000003e}, - {"CELL_SYSMODULE_BGDL", 0x0000003f}, - {"CELL_SYSMODULE_FREETYPE_TT", 0x00000040}, - {"CELL_SYSMODULE_SYSUTIL_VIDEO_UPLOAD", 0x00000041}, - {"CELL_SYSMODULE_SYSUTIL_SYSCONF_EXT", 0x00000042}, - {"CELL_SYSMODULE_FIBER", 0x00000043}, - {"CELL_SYSMODULE_SYSUTIL_NP_COMMERCE2", 0x00000044}, - {"CELL_SYSMODULE_SYSUTIL_NP_TUS", 0x00000045}, - {"CELL_SYSMODULE_VOICE", 0x00000046}, - {"CELL_SYSMODULE_ADEC_CELP8", 0x00000047}, - {"CELL_SYSMODULE_CELP8ENC", 0x00000048}, - {"CELL_SYSMODULE_SYSUTIL_LICENSEAREA", 0x00000049}, - {"CELL_SYSMODULE_SYSUTIL_MUSIC2", 0x0000004a}, - {"CELL_SYSMODULE_SYSUTIL_SCREENSHOT", 0x0000004e}, - {"CELL_SYSMODULE_SYSUTIL_MUSIC_DECODE", 0x0000004f}, - {"CELL_SYSMODULE_SPURS_JQ", 0x00000050}, - {"CELL_SYSMODULE_PNGENC", 0x00000052}, - {"CELL_SYSMODULE_SYSUTIL_MUSIC_DECODE2", 0x00000053}, - {"CELL_SYSMODULE_SYNC2", 0x00000055}, - {"CELL_SYSMODULE_SYSUTIL_NP_UTIL", 0x00000056}, - {"CELL_SYSMODULE_RUDP", 0x00000057}, - {"CELL_SYSMODULE_SYSUTIL_NP_SNS", 0x00000059}, - {"CELL_SYSMODULE_GEM", 0x0000005a}, - {"CELL_SYSMODULE_CELPENC", 0x0000f00a}, - {"CELL_SYSMODULE_GIFDEC", 0x0000f010}, - {"CELL_SYSMODULE_ADEC_CELP", 0x0000f019}, - {"CELL_SYSMODULE_ADEC_M2BC", 0x0000f01b}, - {"CELL_SYSMODULE_ADEC_M4AAC", 0x0000f01d}, - {"CELL_SYSMODULE_ADEC_MP3", 0x0000f01e}, - {"CELL_SYSMODULE_IMEJP", 0x0000f023}, - {"CELL_SYSMODULE_SYSUTIL_MUSIC", 0x0000f028}, - {"CELL_SYSMODULE_PHOTO_EXPORT", 0x0000f029}, - {"CELL_SYSMODULE_PRINT", 0x0000f02a}, - {"CELL_SYSMODULE_PHOTO_IMPORT", 0x0000f02b}, - {"CELL_SYSMODULE_MUSIC_EXPORT", 0x0000f02c}, - {"CELL_SYSMODULE_PHOTO_DECODE", 0x0000f02e}, - {"CELL_SYSMODULE_SYSUTIL_SEARCH", 0x0000f02f}, - {"CELL_SYSMODULE_SYSUTIL_AVCHAT2", 0x0000f030}, - {"CELL_SYSMODULE_SAIL_REC", 0x0000f034}, - {"CELL_SYSMODULE_SYSUTIL_NP_TROPHY", 0x0000f035}, - {"CELL_SYSMODULE_LIBATRAC3MULTI", 0x0000f054}, + {"CELL_SYSMODULE_ADEC", 0x00000006}, + {"CELL_SYSMODULE_DMUX", 0x00000007}, + {"CELL_SYSMODULE_VPOST", 0x00000008}, + {"CELL_SYSMODULE_RTC", 0x00000009}, + {"CELL_SYSMODULE_SPURS", 0x0000000a}, + {"CELL_SYSMODULE_OVIS", 0x0000000b}, + {"CELL_SYSMODULE_SHEAP", 0x0000000c}, + {"CELL_SYSMODULE_SYNC", 0x0000000d}, + {"CELL_SYSMODULE_FS", 0x0000000e}, + {"CELL_SYSMODULE_JPGDEC", 0x0000000f}, + {"CELL_SYSMODULE_GCM_SYS", 0x00000010}, + {"CELL_SYSMODULE_GCM", 0x00000010}, + {"CELL_SYSMODULE_AUDIO", 0x00000011}, + {"CELL_SYSMODULE_PAMF", 0x00000012}, + {"CELL_SYSMODULE_ATRAC3PLUS", 0x00000013}, + {"CELL_SYSMODULE_NETCTL", 0x00000014}, + {"CELL_SYSMODULE_SYSUTIL", 0x00000015}, + {"CELL_SYSMODULE_SYSUTIL_NP", 0x00000016}, + {"CELL_SYSMODULE_IO", 0x00000017}, + {"CELL_SYSMODULE_PNGDEC", 0x00000018}, + {"CELL_SYSMODULE_FONT", 0x00000019}, + {"CELL_SYSMODULE_FONTFT", 0x0000001a}, + {"CELL_SYSMODULE_FREETYPE", 0x0000001b}, + {"CELL_SYSMODULE_USBD", 0x0000001c}, + {"CELL_SYSMODULE_SAIL", 0x0000001d}, + {"CELL_SYSMODULE_L10N", 0x0000001e}, + {"CELL_SYSMODULE_RESC", 0x0000001f}, + {"CELL_SYSMODULE_DAISY", 0x00000020}, + {"CELL_SYSMODULE_KEY2CHAR", 0x00000021}, + {"CELL_SYSMODULE_MIC", 0x00000022}, + {"CELL_SYSMODULE_CAMERA", 0x00000023}, + {"CELL_SYSMODULE_VDEC_MPEG2", 0x00000024}, + {"CELL_SYSMODULE_VDEC_AVC", 0x00000025}, + {"CELL_SYSMODULE_ADEC_LPCM", 0x00000026}, + {"CELL_SYSMODULE_ADEC_AC3", 0x00000027}, + {"CELL_SYSMODULE_ADEC_ATX", 0x00000028}, + {"CELL_SYSMODULE_ADEC_AT3", 0x00000029}, + {"CELL_SYSMODULE_DMUX_PAMF", 0x0000002a}, + {"CELL_SYSMODULE_VDEC_AL", 0x0000002b}, + {"CELL_SYSMODULE_ADEC_AL", 0x0000002c}, + {"CELL_SYSMODULE_DMUX_AL", 0x0000002d}, + {"CELL_SYSMODULE_LV2DBG", 0x0000002e}, + {"CELL_SYSMODULE_USBPSPCM", 0x00000030}, + {"CELL_SYSMODULE_AVCONF_EXT", 0x00000031}, + {"CELL_SYSMODULE_SYSUTIL_USERINFO", 0x00000032}, + {"CELL_SYSMODULE_SYSUTIL_SAVEDATA", 0x00000033}, + {"CELL_SYSMODULE_SUBDISPLAY", 0x00000034}, + {"CELL_SYSMODULE_SYSUTIL_REC", 0x00000035}, + {"CELL_SYSMODULE_VIDEO_EXPORT", 0x00000036}, + {"CELL_SYSMODULE_SYSUTIL_GAME_EXEC", 0x00000037}, + {"CELL_SYSMODULE_SYSUTIL_NP2", 0x00000038}, + {"CELL_SYSMODULE_SYSUTIL_AP", 0x00000039}, + {"CELL_SYSMODULE_SYSUTIL_NP_CLANS", 0x0000003a}, + {"CELL_SYSMODULE_SYSUTIL_OSK_EXT", 0x0000003b}, + {"CELL_SYSMODULE_VDEC_DIVX", 0x0000003c}, + {"CELL_SYSMODULE_JPGENC", 0x0000003d}, + {"CELL_SYSMODULE_SYSUTIL_GAME", 0x0000003e}, + {"CELL_SYSMODULE_BGDL", 0x0000003f}, + {"CELL_SYSMODULE_FREETYPE_TT", 0x00000040}, + {"CELL_SYSMODULE_SYSUTIL_VIDEO_UPLOAD", 0x00000041}, + {"CELL_SYSMODULE_SYSUTIL_SYSCONF_EXT", 0x00000042}, + {"CELL_SYSMODULE_FIBER", 0x00000043}, + {"CELL_SYSMODULE_SYSUTIL_NP_COMMERCE2", 0x00000044}, + {"CELL_SYSMODULE_SYSUTIL_NP_TUS", 0x00000045}, + {"CELL_SYSMODULE_VOICE", 0x00000046}, + {"CELL_SYSMODULE_ADEC_CELP8", 0x00000047}, + {"CELL_SYSMODULE_CELP8ENC", 0x00000048}, + {"CELL_SYSMODULE_SYSUTIL_LICENSEAREA", 0x00000049}, + {"CELL_SYSMODULE_SYSUTIL_MUSIC2", 0x0000004a}, + {"CELL_SYSMODULE_SYSUTIL_SCREENSHOT", 0x0000004e}, + {"CELL_SYSMODULE_SYSUTIL_MUSIC_DECODE", 0x0000004f}, + {"CELL_SYSMODULE_SPURS_JQ", 0x00000050}, + {"CELL_SYSMODULE_PNGENC", 0x00000052}, + {"CELL_SYSMODULE_SYSUTIL_MUSIC_DECODE2", 0x00000053}, + {"CELL_SYSMODULE_SYNC2", 0x00000055}, + {"CELL_SYSMODULE_SYSUTIL_NP_UTIL", 0x00000056}, + {"CELL_SYSMODULE_RUDP", 0x00000057}, + {"CELL_SYSMODULE_SYSUTIL_NP_SNS", 0x00000059}, + {"CELL_SYSMODULE_GEM", 0x0000005a}, + {"CELL_SYSMODULE_CELPENC", 0x0000f00a}, + {"CELL_SYSMODULE_GIFDEC", 0x0000f010}, + {"CELL_SYSMODULE_ADEC_CELP", 0x0000f019}, + {"CELL_SYSMODULE_ADEC_M2BC", 0x0000f01b}, + {"CELL_SYSMODULE_ADEC_M4AAC", 0x0000f01d}, + {"CELL_SYSMODULE_ADEC_MP3", 0x0000f01e}, + {"CELL_SYSMODULE_IMEJP", 0x0000f023}, + {"CELL_SYSMODULE_SYSUTIL_MUSIC", 0x0000f028}, + {"CELL_SYSMODULE_PHOTO_EXPORT", 0x0000f029}, + {"CELL_SYSMODULE_PRINT", 0x0000f02a}, + {"CELL_SYSMODULE_PHOTO_IMPORT", 0x0000f02b}, + {"CELL_SYSMODULE_MUSIC_EXPORT", 0x0000f02c}, + {"CELL_SYSMODULE_PHOTO_DECODE", 0x0000f02e}, + {"CELL_SYSMODULE_SYSUTIL_SEARCH", 0x0000f02f}, + {"CELL_SYSMODULE_SYSUTIL_AVCHAT2", 0x0000f030}, + {"CELL_SYSMODULE_SAIL_REC", 0x0000f034}, + {"CELL_SYSMODULE_SYSUTIL_NP_TROPHY", 0x0000f035}, + {"CELL_SYSMODULE_LIBATRAC3MULTI", 0x0000f054}, }; - for (int i = 0; i < 103; ++i) { - if (entries[i].id == id) { - return entries[i].name; - } - } + + for (int i = 0; i < sizeof(entries) / sizeof(entries[0]); ++i) + { + if (entries[i].id == id) + { + return entries[i].name; + } + } + return 0; } diff --git a/rpcs3/Loader/ELF32.cpp b/rpcs3/Loader/ELF32.cpp index f56160fb4d..6684a4f584 100644 --- a/rpcs3/Loader/ELF32.cpp +++ b/rpcs3/Loader/ELF32.cpp @@ -59,7 +59,7 @@ bool ELF32Loader::LoadEhdrInfo() return false; } - entry = ehdr.GetEntry() & ~0x3; + entry = ehdr.GetEntry(); if(entry == 0) { ConLog.Error("elf32 error: entry is null!"); @@ -86,10 +86,12 @@ bool ELF32Loader::LoadPhdrInfo() phdr_arr.Move(phdr); } - if(!Memory.IsGoodAddr(entry)) + if(/*!Memory.IsGoodAddr(entry)*/ entry & 0x1) { //entry is physical, convert to virtual + entry &= ~0x1; + for(size_t i=0; i= entry && entry < phdr_arr[i].p_paddr + phdr_arr[i].p_memsz)