From b6ec618f978532763dd03e4222556e0c3ea8977e Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Mon, 12 Jan 2015 21:12:06 +0300 Subject: [PATCH] Experimental template formatting with be_t<> support --- Utilities/BEType.h | 19 +- Utilities/Log.h | 6 +- Utilities/StrFmt.h | 509 +++++++++++++++++++++- Utilities/Thread.cpp | 6 +- Utilities/rFile.cpp | 4 +- rpcs3/Emu/ARMv7/Modules/sceLibKernel.cpp | 2 +- rpcs3/Emu/Audio/XAudio2/XAudio2Thread.cpp | 16 +- rpcs3/Emu/Cell/PPUInterpreter.h | 2 +- rpcs3/Emu/Io/XInput/XInputPadHandler.cpp | 2 +- rpcs3/Emu/SysCalls/LogBase.h | 20 +- rpcs3/Emu/SysCalls/Modules/cellCamera.cpp | 2 +- rpcs3/Emu/SysCalls/Modules/cellDmux.cpp | 4 +- rpcs3/Emu/SysCalls/Modules/cellFont.cpp | 6 +- rpcs3/Emu/SysCalls/Modules/cellGame.cpp | 2 +- rpcs3/Emu/SysCalls/Modules/cellGem.cpp | 5 +- rpcs3/Emu/SysCalls/Modules/cellResc.cpp | 2 +- rpcs3/Emu/SysCalls/Modules/cellRtc.cpp | 2 +- rpcs3/Emu/SysCalls/Modules/cellSail.cpp | 4 +- rpcs3/Emu/SysCalls/Modules/libmixer.cpp | 6 +- rpcs3/Emu/SysCalls/Modules/sceNp.cpp | 6 +- rpcs3/Emu/SysCalls/lv2/cellFs.cpp | 6 +- rpcs3/Emu/SysCalls/lv2/sys_lwmutex.cpp | 3 +- rpcs3/Emu/SysCalls/lv2/sys_mutex.cpp | 4 +- rpcs3/Emu/SysCalls/lv2/sys_prx.h | 2 +- rpcs3/Gui/MainFrame.cpp | 2 +- rpcs3/Gui/VHDDManager.cpp | 2 +- rpcs3/Loader/ELF64.cpp | 7 +- rpcs3/stdafx.cpp | 10 + rpcs3/stdafx.h | 2 +- 29 files changed, 577 insertions(+), 86 deletions(-) diff --git a/Utilities/BEType.h b/Utilities/BEType.h index d8a8c5998e..fd5c101831 100644 --- a/Utilities/BEType.h +++ b/Utilities/BEType.h @@ -284,15 +284,9 @@ union _CRT_ALIGN(16) u128 _u64[1] = _u64[0] = 0; } - std::string to_hex() const - { - return fmt::Format("%016llx%016llx", _u64[1], _u64[0]); - } + std::string to_hex() const; - std::string to_xyzw() const - { - return fmt::Format("x: %g y: %g z: %g w: %g", _f[3], _f[2], _f[1], _f[0]); - } + std::string to_xyzw() const; static __forceinline u128 byteswap(const u128 val) { @@ -608,6 +602,15 @@ public: return ToBE(); #endif } + + const stype& data() const + { +#ifdef IS_LE_MACHINE + return ToBE(); +#else + return ToLE(); +#endif + } be_t& operator = (const be_t& value) = default; diff --git a/Utilities/Log.h b/Utilities/Log.h index c40d2a82c6..90078d96ee 100644 --- a/Utilities/Log.h +++ b/Utilities/Log.h @@ -135,9 +135,9 @@ inline void log_message(Log::LogType type, Log::LogSeverity sev, const char* tex Log::LogManager::getInstance().log(msg); } -template -inline void log_message(Log::LogType type, Log::LogSeverity sev, const char* text, T arg, Ts... args) +template +inline void log_message(Log::LogType type, Log::LogSeverity sev, const char(&text)[N], T arg, Ts... args) { - Log::LogMessage msg{type, sev, fmt::Format(text, arg, args...)}; + Log::LogMessage msg{type, sev, fmt::format(text, arg, args...)}; Log::LogManager::getInstance().log(msg); } \ No newline at end of file diff --git a/Utilities/StrFmt.h b/Utilities/StrFmt.h index 963bb8b1b8..2cbf2c99e7 100644 --- a/Utilities/StrFmt.h +++ b/Utilities/StrFmt.h @@ -1,18 +1,16 @@ #pragma once + class wxString; #if defined(_MSC_VER) #define snprintf _snprintf #endif -namespace fmt{ - using std::string; - using std::ostream; - using std::ostringstream; - +namespace fmt +{ struct empty_t{}; - extern const string placeholder; + extern const std::string placeholder; template std::string AfterLast(const std::string& source, T searchstr) @@ -51,11 +49,11 @@ namespace fmt{ // `fmt::placeholder` after `pos` everything in `fmt` after pos is written // to `os`. Then `arg` is written to `os` after appending a space character template - empty_t write(const string &fmt, ostream &os, string::size_type &pos, T &&arg) + empty_t write(const std::string &fmt, std::ostream &os, std::string::size_type &pos, T &&arg) { - string::size_type ins = fmt.find(placeholder, pos); + std::string::size_type ins = fmt.find(placeholder, pos); - if (ins == string::npos) + if (ins == std::string::npos) { os.write(fmt.data() + pos, fmt.size() - pos); os << ' ' << arg; @@ -77,10 +75,10 @@ namespace fmt{ // inserted use `fmt::placeholder`. If there's not enough placeholders // the rest of the arguments are appended at the end, seperated by spaces template - string SFormat(const string &fmt, Args&& ... parameters) + std::string SFormat(const std::string &fmt, Args&& ... parameters) { - ostringstream os; - string::size_type pos = 0; + std::ostringstream os; + std::string::size_type pos = 0; std::initializer_list { write(fmt, os, pos, parameters)... }; if (!fmt.empty()) @@ -88,7 +86,7 @@ namespace fmt{ os.write(fmt.data() + pos, fmt.size() - pos); } - string result = os.str(); + std::string result = os.str(); return result; } @@ -98,10 +96,10 @@ namespace fmt{ //wrapper to deal with advance sprintf formating options with automatic length finding template - string Format(const char* fmt, Args ... parameters) + std::string Format(const char* fmt, Args ... parameters) { size_t length = 256; - string str; + std::string str; for (;;) { @@ -116,7 +114,7 @@ namespace fmt{ #endif if (printlen < length) { - str = string(buffptr.data(), printlen); + str = std::string(buffptr.data(), printlen); break; } length *= 2; @@ -175,13 +173,490 @@ namespace fmt{ return src; } + namespace detail + { + static std::string to_hex(u64 value, size_t count = 1) + { + assert(count - 1 < 16); + count = std::max(count, 16 - cntlz64(value) / 4); + + char res[16] = {}; + + for (size_t i = count - 1; ~i; i--, value /= 16) + { + res[i] = "0123456789abcdef"[value % 16]; + } + + return std::string(res, count); + } + + static size_t get_fmt_start(const char* fmt, size_t len) + { + for (size_t i = 0; i < len; i++) + { + if (fmt[i] == '%') + { + return i; + } + } + + return len; + } + + static size_t get_fmt_len(const char* fmt, size_t len) + { + assert(len >= 2 && fmt[0] == '%'); + + size_t res = 2; + + if (fmt[1] == '.' || fmt[1] == '0') + { + assert(len >= 4 && fmt[2] - '1' < 9); + res += 2; + fmt += 2; + len -= 2; + + if (fmt[1] == '1') + { + assert(len >= 3 && fmt[2] - '0' < 7); + res++; + fmt++; + len--; + } + } + + if (fmt[1] == 'l') + { + assert(len >= 3); + res++; + fmt++; + len--; + } + + if (fmt[1] == 'l') + { + assert(len >= 3); + res++; + fmt++; + len--; + } + + return res; + } + + static size_t get_fmt_precision(const char* fmt, size_t len) + { + assert(len >= 2); + + if (fmt[1] == '.' || fmt[1] == '0') + { + assert(len >= 4 && fmt[2] - '1' < 9); + + if (fmt[2] == '1') + { + assert(len >= 5 && fmt[3] - '0' < 7); + return 10 + fmt[3] - '0'; + } + + return fmt[2] - '0'; + } + + return 1; + } + + template::value> + struct get_fmt + { + static_assert(is_enum, "Unsupported fmt::format argument"); + typedef typename std::underlying_type::type underlying_type; + + static std::string text(const char* fmt, size_t len, const T& arg) + { + return get_fmt::text(fmt, len, (underlying_type)arg); + } + }; + + template + struct get_fmt, false> + { + static std::string text(const char* fmt, size_t len, const be_t& arg) + { + return get_fmt::text(fmt, len, arg.value()); + } + }; + + template<> + struct get_fmt + { + static std::string text(const char* fmt, size_t len, u8 arg) + { + if (fmt[len - 1] == 'x') + { + return to_hex(arg, get_fmt_precision(fmt, len)); + } + else if (fmt[len - 1] == 'd') + { + return std::to_string((u32)arg); + } + else + { + throw "Invalid formatting (u8)"; + } + + return{}; + } + }; + + template<> + struct get_fmt + { + static std::string text(const char* fmt, size_t len, u16 arg) + { + if (fmt[len - 1] == 'x') + { + return to_hex(arg, get_fmt_precision(fmt, len)); + } + else if (fmt[len - 1] == 'd') + { + return std::to_string((u32)arg); + } + else + { + throw "Invalid formatting (u16)"; + } + + return{}; + } + }; + + template<> + struct get_fmt + { + static std::string text(const char* fmt, size_t len, u32 arg) + { + if (fmt[len - 1] == 'x') + { + return to_hex(arg, get_fmt_precision(fmt, len)); + } + else if (fmt[len - 1] == 'd') + { + return std::to_string(arg); + } + else + { + throw "Invalid formatting (u32)"; + } + + return{}; + } + }; + + template<> + struct get_fmt + { + static std::string text(const char* fmt, size_t len, u64 arg) + { + if (fmt[len - 1] == 'x') + { + return to_hex(arg, get_fmt_precision(fmt, len)); + } + else if (fmt[len - 1] == 'd') + { + return std::to_string(arg); + } + else + { + throw "Invalid formatting (u64)"; + } + + return{}; + } + }; + + template<> + struct get_fmt + { + static std::string text(const char* fmt, size_t len, s8 arg) + { + if (fmt[len - 1] == 'x') + { + return to_hex((u8)arg, get_fmt_precision(fmt, len)); + } + else if (fmt[len - 1] == 'd') + { + return std::to_string((s32)arg); + } + else + { + throw "Invalid formatting (s8)"; + } + + return{}; + } + }; + + template<> + struct get_fmt + { + static std::string text(const char* fmt, size_t len, s16 arg) + { + if (fmt[len - 1] == 'x') + { + return to_hex((u16)arg, get_fmt_precision(fmt, len)); + } + else if (fmt[len - 1] == 'd') + { + return std::to_string((s32)arg); + } + else + { + throw "Invalid formatting (s16)"; + } + + return{}; + } + }; + + template<> + struct get_fmt + { + static std::string text(const char* fmt, size_t len, s32 arg) + { + if (fmt[len - 1] == 'x') + { + return to_hex((u32)arg, get_fmt_precision(fmt, len)); + } + else if (fmt[len - 1] == 'd') + { + return std::to_string(arg); + } + else + { + throw "Invalid formatting (s32)"; + } + + return{}; + } + }; + + template<> + struct get_fmt + { + static std::string text(const char* fmt, size_t len, s64 arg) + { + if (fmt[len - 1] == 'x') + { + return to_hex((u64)arg, get_fmt_precision(fmt, len)); + } + else if (fmt[len - 1] == 'd') + { + return std::to_string(arg); + } + else + { + throw "Invalid formatting (s64)"; + } + + return{}; + } + }; + + template<> + struct get_fmt + { + static std::string text(const char* fmt, size_t len, float arg) + { + if (fmt[len - 1] == 'x') + { + return to_hex((u32&)arg, get_fmt_precision(fmt, len)); + } + else if (fmt[len - 1] == 'f') + { + return std::to_string(arg); + } + else + { + throw "Invalid formatting (float)"; + } + + return{}; + } + }; + + template<> + struct get_fmt + { + static std::string text(const char* fmt, size_t len, double arg) + { + if (fmt[len - 1] == 'x') + { + return to_hex((u64&)arg, get_fmt_precision(fmt, len)); + } + else if (fmt[len - 1] == 'f') + { + return std::to_string(arg); + } + else + { + throw "Invalid formatting (double)"; + } + + return{}; + } + }; + + template<> + struct get_fmt + { + static std::string text(const char* fmt, size_t len, bool arg) + { + if (fmt[len - 1] == 'x') + { + return to_hex(arg, get_fmt_precision(fmt, len)); + } + else if (fmt[len - 1] == 'd') + { + return arg ? "1" : "0"; + } + else if (fmt[len - 1] == 's') + { + return arg ? "true" : "false"; + } + else + { + throw "Invalid formatting (bool)"; + } + + return{}; + } + }; + + template<> + struct get_fmt + { + static std::string text(const char* fmt, size_t len, char* arg) + { + if (fmt[len - 1] == 's') + { + return arg; + } + else + { + throw "Invalid formatting (char*)"; + } + + return{}; + } + }; + + template<> + struct get_fmt + { + static std::string text(const char* fmt, size_t len, const char* arg) + { + if (fmt[len - 1] == 's') + { + return arg; + } + else + { + throw "Invalid formatting (const char*)"; + } + + return{}; + } + }; + + template + struct get_fmt + { + static std::string text(const char* fmt, size_t len, const char(&arg)[size]) + { + if (fmt[len - 1] == 's') + { + return std::string(arg, size); + } + else + { + throw "Invalid formatting (const char[size])"; + } + + return{}; + } + }; + + template<> + struct get_fmt + { + static std::string text(const char* fmt, size_t len, const std::string& arg) + { + if (fmt[len - 1] == 's') + { + return arg; + } + else + { + throw "Invalid formatting (std::string)"; + } + + return{}; + } + }; + + template + static std::string format(const char* fmt, size_t len, const T& arg, Args... args) + { + const size_t fmt_start = get_fmt_start(fmt, len); + const size_t fmt_len = get_fmt_len(fmt + fmt_start, len - fmt_start); + const size_t fmt_end = fmt_start + fmt_len; + + return std::string(fmt, fmt_start) + get_fmt::text(fmt + fmt_start, fmt_len, arg) + format(fmt + fmt_end, len - fmt_end, args...); + } + + static std::string format(const char* fmt, size_t len) + { + const size_t fmt_start = get_fmt_start(fmt, len); + assert(fmt_start == len); + + return std::string(fmt, len); + } + }; + + // formatting function with very limited functionality (compared to printf-like formatting) and be_t<> support + /* + Supported types: + + u8, s8 (%x, %d) + u16, s16 (%x, %d) + u32, s32 (%x, %d) + u64, s64 (%x, %d) + float (%x, %f) + double (%x, %f) + bool (%x, %d, %s) + char*, const char*, const char[N], std::string (%s) + be_t<> of any appropriate type in this list + + Supported formatting: + %d - decimal; only basic std::to_string() functionality + %x - hexadecimal; %.8x - hexadecimal with the precision (from .2 to .16) + %s - string; generates "true" or "false" for bool + %f - floating point; only basic std::to_string() functionality + + Other features are not supported. + */ + template + __forceinline static std::string format(const char* fmt, Args... args) + { + return detail::format(fmt, strlen(fmt), args...); + } + //convert a wxString to a std::string encoded in utf8 //CAUTION, only use this to interface with wxWidgets classes std::string ToUTF8(const wxString& right); //convert a std::string encoded in utf8 to a wxString //CAUTION, only use this to interface with wxWidgets classes - wxString FromUTF8(const string& right); + wxString FromUTF8(const std::string& right); //TODO: remove this after every snippet that uses it is gone //WARNING: not fully compatible with CmpNoCase from wxString diff --git a/Utilities/Thread.cpp b/Utilities/Thread.cpp index a848315d9e..209ab5c01b 100644 --- a/Utilities/Thread.cpp +++ b/Utilities/Thread.cpp @@ -14,8 +14,10 @@ void SetCurrentThreadDebugName(const char* threadName) { -#ifdef _WIN32 // this is VS-specific way to set thread names for the debugger +#if defined(_MSC_VER) // this is VS-specific way to set thread names for the debugger + #pragma pack(push,8) + struct THREADNAME_INFO { DWORD dwType; @@ -23,6 +25,7 @@ void SetCurrentThreadDebugName(const char* threadName) DWORD dwThreadID; DWORD dwFlags; } info; + #pragma pack(pop) info.dwType = 0x1000; @@ -37,6 +40,7 @@ void SetCurrentThreadDebugName(const char* threadName) __except (EXCEPTION_EXECUTE_HANDLER) { } + #endif } diff --git a/Utilities/rFile.cpp b/Utilities/rFile.cpp index 912452ef89..e6f657d39e 100644 --- a/Utilities/rFile.cpp +++ b/Utilities/rFile.cpp @@ -114,7 +114,7 @@ bool rRmdir(const std::string &dir) if (int err = rmdir(dir.c_str())) #endif { - LOG_ERROR(GENERAL, "Error deleting directory %s: %i", dir.c_str(), GET_API_ERROR); + LOG_ERROR(GENERAL, "Error deleting directory %s: 0x%llx", dir.c_str(), (u64)GET_API_ERROR); return false; } return true; @@ -149,7 +149,7 @@ bool rRemoveFile(const std::string &file) if (int err = unlink(file.c_str())) #endif { - LOG_ERROR(GENERAL, "Error deleting %s: %i", file.c_str(), GET_API_ERROR); + LOG_ERROR(GENERAL, "Error deleting file %s: 0x%llx", file.c_str(), (u64)GET_API_ERROR); return false; } return true; diff --git a/rpcs3/Emu/ARMv7/Modules/sceLibKernel.cpp b/rpcs3/Emu/ARMv7/Modules/sceLibKernel.cpp index 562193cb22..6bc20e3e51 100644 --- a/rpcs3/Emu/ARMv7/Modules/sceLibKernel.cpp +++ b/rpcs3/Emu/ARMv7/Modules/sceLibKernel.cpp @@ -108,7 +108,7 @@ s32 sceKernelCreateThread( new_thread.SetStackSize(stackSize); new_thread.SetName(name); - sceLibKernel.Error("*** New ARMv7 Thread [%s] (entry=0x%x): id = %d", name.c_str(), entry, id); + sceLibKernel.Error("*** New ARMv7 Thread [%s] (entry_addr=0x%x): id = %d", name.c_str(), entry.addr(), id); new_thread.Run(); diff --git a/rpcs3/Emu/Audio/XAudio2/XAudio2Thread.cpp b/rpcs3/Emu/Audio/XAudio2/XAudio2Thread.cpp index f6da9b75fb..202adfe030 100644 --- a/rpcs3/Emu/Audio/XAudio2/XAudio2Thread.cpp +++ b/rpcs3/Emu/Audio/XAudio2/XAudio2Thread.cpp @@ -18,7 +18,7 @@ void XAudio2Thread::Init() hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED); if (FAILED(hr)) { - LOG_ERROR(GENERAL, "XAudio2Thread : CoInitializeEx() failed(0x%08x)", hr); + LOG_ERROR(GENERAL, "XAudio2Thread : CoInitializeEx() failed(0x%08x)", (u32)hr); Emu.Pause(); return; } @@ -26,7 +26,7 @@ void XAudio2Thread::Init() hr = XAudio2Create(&m_xaudio2_instance, 0, XAUDIO2_DEFAULT_PROCESSOR); if (FAILED(hr)) { - LOG_ERROR(GENERAL, "XAudio2Thread : XAudio2Create() failed(0x%08x)", hr); + LOG_ERROR(GENERAL, "XAudio2Thread : XAudio2Create() failed(0x%08x)", (u32)hr); Emu.Pause(); return; } @@ -34,7 +34,7 @@ void XAudio2Thread::Init() hr = m_xaudio2_instance->CreateMasteringVoice(&m_master_voice); if (FAILED(hr)) { - LOG_ERROR(GENERAL, "XAudio2Thread : CreateMasteringVoice() failed(0x%08x)", hr); + LOG_ERROR(GENERAL, "XAudio2Thread : CreateMasteringVoice() failed(0x%08x)", (u32)hr); m_xaudio2_instance->Release(); Emu.Pause(); } @@ -57,7 +57,7 @@ void XAudio2Thread::Play() HRESULT hr = m_source_voice->Start(); if (FAILED(hr)) { - LOG_ERROR(GENERAL, "XAudio2Thread : Start() failed(0x%08x)", hr); + LOG_ERROR(GENERAL, "XAudio2Thread : Start() failed(0x%08x)", (u32)hr); Emu.Pause(); } } @@ -68,7 +68,7 @@ void XAudio2Thread::Close() HRESULT hr = m_source_voice->FlushSourceBuffers(); if (FAILED(hr)) { - LOG_ERROR(GENERAL, "XAudio2Thread : FlushSourceBuffers() failed(0x%08x)", hr); + LOG_ERROR(GENERAL, "XAudio2Thread : FlushSourceBuffers() failed(0x%08x)", (u32)hr); Emu.Pause(); } } @@ -78,7 +78,7 @@ void XAudio2Thread::Stop() HRESULT hr = m_source_voice->Stop(); if (FAILED(hr)) { - LOG_ERROR(GENERAL, "XAudio2Thread : Stop() failed(0x%08x)", hr); + LOG_ERROR(GENERAL, "XAudio2Thread : Stop() failed(0x%08x)", (u32)hr); Emu.Pause(); } } @@ -99,7 +99,7 @@ void XAudio2Thread::Open(const void* src, int size) hr = m_xaudio2_instance->CreateSourceVoice(&m_source_voice, &waveformatex, 0, XAUDIO2_DEFAULT_FREQ_RATIO); if (FAILED(hr)) { - LOG_ERROR(GENERAL, "XAudio2Thread : CreateSourceVoice() failed(0x%08x)", hr); + LOG_ERROR(GENERAL, "XAudio2Thread : CreateSourceVoice() failed(0x%08x)", (u32)hr); Emu.Pause(); return; } @@ -125,7 +125,7 @@ void XAudio2Thread::AddData(const void* src, int size) HRESULT hr = m_source_voice->SubmitSourceBuffer(&buffer); if (FAILED(hr)) { - LOG_ERROR(GENERAL, "XAudio2Thread : AddData() failed(0x%08x)", hr); + LOG_ERROR(GENERAL, "XAudio2Thread : AddData() failed(0x%08x)", (u32)hr); Emu.Pause(); } } diff --git a/rpcs3/Emu/Cell/PPUInterpreter.h b/rpcs3/Emu/Cell/PPUInterpreter.h index 6db581ff70..aa9bba0244 100644 --- a/rpcs3/Emu/Cell/PPUInterpreter.h +++ b/rpcs3/Emu/Cell/PPUInterpreter.h @@ -4623,7 +4623,7 @@ private: Emu.Pause(); for(uint i=0; i<32; ++i) LOG_NOTICE(PPU, "r%d = 0x%llx", i, CPU.GPR[i]); - for(uint i=0; i<32; ++i) LOG_NOTICE(PPU, "f%d = %llf", i, CPU.FPR[i]); + for(uint i=0; i<32; ++i) LOG_NOTICE(PPU, "f%d = %llf", i, CPU.FPR[i]._double); for(uint i=0; i<32; ++i) LOG_NOTICE(PPU, "v%d = 0x%s [%s]", i, CPU.VPR[i].to_hex().c_str(), CPU.VPR[i].to_xyzw().c_str()); LOG_NOTICE(PPU, "CR = 0x%08x", CPU.CR.CR); LOG_NOTICE(PPU, "LR = 0x%llx", CPU.LR); diff --git a/rpcs3/Emu/Io/XInput/XInputPadHandler.cpp b/rpcs3/Emu/Io/XInput/XInputPadHandler.cpp index 27033c5d32..51c6d6474c 100644 --- a/rpcs3/Emu/Io/XInput/XInputPadHandler.cpp +++ b/rpcs3/Emu/Io/XInput/XInputPadHandler.cpp @@ -111,7 +111,7 @@ void XInputPadHandler::Close() { active = false; if (WaitForSingleObject(thread, THREAD_TIMEOUT) != WAIT_OBJECT_0) - LOG_ERROR(HLE, "XInput thread could not stop within %d milliseconds", THREAD_TIMEOUT); + LOG_ERROR(HLE, "XInput thread could not stop within %d milliseconds", (u32)THREAD_TIMEOUT); thread = nullptr; } diff --git a/rpcs3/Emu/SysCalls/LogBase.h b/rpcs3/Emu/SysCalls/LogBase.h index d3aa862efb..9c87a27a5f 100644 --- a/rpcs3/Emu/SysCalls/LogBase.h +++ b/rpcs3/Emu/SysCalls/LogBase.h @@ -31,12 +31,12 @@ public: template __noinline void Notice(const u32 id, const char* fmt, Targs... args) const { - LogOutput(LogNotice, id, " : ", fmt::Format(fmt, args...)); + LogOutput(LogNotice, id, " : ", fmt::format(fmt, args...)); } template __noinline void Notice(const char* fmt, Targs... args) const { - LogOutput(LogNotice, ": ", fmt::Format(fmt, args...)); + LogOutput(LogNotice, ": ", fmt::format(fmt, args...)); } template __forceinline void Log(const char* fmt, Targs... args) const @@ -57,42 +57,42 @@ public: template __noinline void Success(const u32 id, const char* fmt, Targs... args) const { - LogOutput(LogSuccess, id, " : ", fmt::Format(fmt, args...)); + LogOutput(LogSuccess, id, " : ", fmt::format(fmt, args...)); } template __noinline void Success(const char* fmt, Targs... args) const { - LogOutput(LogSuccess, ": ", fmt::Format(fmt, args...)); + LogOutput(LogSuccess, ": ", fmt::format(fmt, args...)); } template __noinline void Warning(const u32 id, const char* fmt, Targs... args) const { - LogOutput(LogWarning, id, " warning: ", fmt::Format(fmt, args...)); + LogOutput(LogWarning, id, " warning: ", fmt::format(fmt, args...)); } template __noinline void Warning(const char* fmt, Targs... args) const { - LogOutput(LogWarning, " warning: ", fmt::Format(fmt, args...)); + LogOutput(LogWarning, " warning: ", fmt::format(fmt, args...)); } template __noinline void Error(const u32 id, const char* fmt, Targs... args) const { - LogOutput(LogError, id, " error: ", fmt::Format(fmt, args...)); + LogOutput(LogError, id, " error: ", fmt::format(fmt, args...)); } template __noinline void Error(const char* fmt, Targs... args) const { - LogOutput(LogError, " error: ", fmt::Format(fmt, args...)); + LogOutput(LogError, " error: ", fmt::format(fmt, args...)); } template __noinline void Todo(const u32 id, const char* fmt, Targs... args) const { - LogOutput(LogError, id, " TODO: ", fmt::Format(fmt, args...)); + LogOutput(LogError, id, " TODO: ", fmt::format(fmt, args...)); } template __noinline void Todo(const char* fmt, Targs... args) const { - LogOutput(LogError, " TODO: ", fmt::Format(fmt, args...)); + LogOutput(LogError, " TODO: ", fmt::format(fmt, args...)); } }; diff --git a/rpcs3/Emu/SysCalls/Modules/cellCamera.cpp b/rpcs3/Emu/SysCalls/Modules/cellCamera.cpp index c0fe253842..467e18e214 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellCamera.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellCamera.cpp @@ -82,7 +82,7 @@ int cellCameraGetDeviceGUID() int cellCameraGetType(s32 dev_num, vm::ptr type) { - cellCamera->Warning("cellCameraGetType(dev_num=%d, type_addr=0x%x)", dev_num, type); + cellCamera->Warning("cellCameraGetType(dev_num=%d, type_addr=0x%x)", dev_num, type.addr()); if (!cellCameraInstance.m_bInitialized) return CELL_CAMERA_ERROR_NOT_INIT; diff --git a/rpcs3/Emu/SysCalls/Modules/cellDmux.cpp b/rpcs3/Emu/SysCalls/Modules/cellDmux.cpp index f030984c3e..ac2bd1368e 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellDmux.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellDmux.cpp @@ -317,7 +317,7 @@ u32 dmuxOpen(Demuxer* dmux_ptr) thread t("Demuxer[" + std::to_string(dmux_id) + "] Thread", [dmux_ptr, sptr]() { Demuxer& dmux = *dmux_ptr; - cellDmux->Notice("Demuxer thread started (mem=0x%x, size=0x%x, cb=0x%x, arg=0x%x)", dmux.memAddr, dmux.memSize, dmux.cbFunc, dmux.cbArg); + cellDmux->Notice("Demuxer thread started (mem=0x%x, size=0x%x, cb_addr=0x%x, arg=0x%x)", dmux.memAddr, dmux.memSize, dmux.cbFunc.addr(), dmux.cbArg); DemuxerTask task; DemuxerStream stream = {}; @@ -1000,7 +1000,7 @@ int cellDmuxEnableEs(u32 demuxerHandle, vm::ptr esFil *esHandle = id; cellDmux->Warning("*** New ES(dmux=%d, addr=0x%x, size=0x%x, filter(0x%x, 0x%x, 0x%x, 0x%x), cb=0x%x(arg=0x%x), spec=0x%x): id = %d", - demuxerHandle, es->memAddr, es->memSize, es->fidMajor, es->fidMinor, es->sup1, es->sup2, esCb->cbEsMsgFunc.addr(), es->cbArg, es->spec, id); + demuxerHandle, es->memAddr, es->memSize, es->fidMajor, es->fidMinor, es->sup1, es->sup2, esCb->cbEsMsgFunc.addr().ToLE(), es->cbArg, es->spec, id); DemuxerTask task(dmuxEnableEs); task.es.es = id; diff --git a/rpcs3/Emu/SysCalls/Modules/cellFont.cpp b/rpcs3/Emu/SysCalls/Modules/cellFont.cpp index 69199e2f2c..e4435ff8ed 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellFont.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellFont.cpp @@ -20,7 +20,7 @@ int cellFontInitializeWithRevision(u64 revisionFlags, vm::ptr co if (config->FileCache.size < 24) return CELL_FONT_ERROR_INVALID_PARAMETER; if (config->flags != 0) - cellFont->Warning("cellFontInitializeWithRevision: Unknown flags (0x%x)", config->flags); + cellFont->Warning("cellFontInitializeWithRevision: Unknown flags (0x%x)", config->flags.ToLE()); s_fontInternalInstance->m_buffer_addr = config->FileCache.buffer_addr; s_fontInternalInstance->m_buffer_size = config->FileCache.size; @@ -168,12 +168,12 @@ int cellFontOpenFontset(PPUThread& CPU, vm::ptr library, vm::pt case CELL_FONT_TYPE_SEURAT_CAPIE_MARU_GOTHIC_YG_DFHEI5_RSANS2_SET: case CELL_FONT_TYPE_SEURAT_CAPIE_MARU_GOTHIC_YG_DFHEI5_VAGR2_SET: case CELL_FONT_TYPE_SEURAT_CAPIE_MARU_GOTHIC_VAGR2_SET: - cellFont->Warning("cellFontOpenFontset: fontType->type = %d not supported yet. RD-R-LATIN.TTF will be used instead.", fontType->type); + cellFont->Warning("cellFontOpenFontset: fontType->type = %d not supported yet. RD-R-LATIN.TTF will be used instead.", fontType->type.ToLE()); file = "/dev_flash/data/font/SCE-PS3-RD-R-LATIN.TTF"; break; default: - cellFont->Warning("cellFontOpenFontset: fontType->type = %d not supported.", fontType->type); + cellFont->Warning("cellFontOpenFontset: fontType->type = %d not supported.", fontType->type.ToLE()); return CELL_FONT_ERROR_NO_SUPPORT_FONTSET; } diff --git a/rpcs3/Emu/SysCalls/Modules/cellGame.cpp b/rpcs3/Emu/SysCalls/Modules/cellGame.cpp index e2a82abf0f..3b4131c14c 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellGame.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellGame.cpp @@ -272,7 +272,7 @@ int cellGameDataCheckCreate2(PPUThread& CPU, u32 version, vm::ptr di if (cbSet->setParam) { // TODO: write PARAM.SFO from cbSet - cellGame->Todo("cellGameDataCheckCreate(2)(): writing PARAM.SFO parameters (addr=0x%x)", cbSet->setParam.addr()); + cellGame->Todo("cellGameDataCheckCreate(2)(): writing PARAM.SFO parameters (addr=0x%x)", cbSet->setParam.addr().ToLE()); } switch ((s32)cbResult->result) diff --git a/rpcs3/Emu/SysCalls/Modules/cellGem.cpp b/rpcs3/Emu/SysCalls/Modules/cellGem.cpp index d9f51ef96a..118a428a0a 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellGem.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellGem.cpp @@ -190,10 +190,9 @@ int cellGemGetInfo() return CELL_OK; } -// Should int be used, even when type is int_32t (s32)? -s32 cellGemGetMemorySize(be_t max_connect) +s32 cellGemGetMemorySize(s32 max_connect) { - cellGem->Warning("cellGemGetMemorySize(max_connect=%i)", max_connect); + cellGem->Warning("cellGemGetMemorySize(max_connect=%d)", max_connect); if (max_connect > CELL_GEM_MAX_NUM) return CELL_GEM_ERROR_INVALID_PARAMETER; diff --git a/rpcs3/Emu/SysCalls/Modules/cellResc.cpp b/rpcs3/Emu/SysCalls/Modules/cellResc.cpp index c87eb12b6d..c6329e366d 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellResc.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellResc.cpp @@ -1212,7 +1212,7 @@ int CreateInterlaceTable(u32 ea_addr, float srcH, float dstH, CellRescTableEleme int cellRescCreateInterlaceTable(u32 ea_addr, float srcH, CellRescTableElement depth, int length) { - cellResc->Warning("cellRescCreateInterlaceTable(ea_addr=0x%x, depth = %i, length = %i)", ea_addr, depth, length); + cellResc->Warning("cellRescCreateInterlaceTable(ea_addr=0x%x, srcH=%f, depth=%d, length=%d)", ea_addr, srcH, depth, length); if (!s_rescInternalInstance->m_bInitialized) { diff --git a/rpcs3/Emu/SysCalls/Modules/cellRtc.cpp b/rpcs3/Emu/SysCalls/Modules/cellRtc.cpp index aae606a4d1..51aaaa1cec 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellRtc.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellRtc.cpp @@ -382,7 +382,7 @@ int cellRtcSetTime_t(vm::ptr pDateTime, u64 iTime) int cellRtcSetWin32FileTime(vm::ptr pDateTime, u64 ulWin32FileTime) { - cellRtc->Log("cellRtcSetWin32FileTime(pDateTime=0x%x, ulWin32FileTime=0x%llx)", pDateTime, ulWin32FileTime); + cellRtc->Log("cellRtcSetWin32FileTime(pDateTime_addr=0x%x, ulWin32FileTime=0x%llx)", pDateTime.addr(), ulWin32FileTime); rDateTime date_time = rDateTime((time_t)ulWin32FileTime); diff --git a/rpcs3/Emu/SysCalls/Modules/cellSail.cpp b/rpcs3/Emu/SysCalls/Modules/cellSail.cpp index 9e5ee1fc73..930af9b982 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellSail.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellSail.cpp @@ -94,7 +94,7 @@ int cellSailDescriptorIsAutoSelection(vm::ptr pSelf) return CELL_OK; } -int cellSailDescriptorCreateDatabase(vm::ptr pSelf, vm::ptr pDatabase, be_t size, be_t arg) +int cellSailDescriptorCreateDatabase(vm::ptr pSelf, vm::ptr pDatabase, u32 size, u64 arg) { cellSail->Warning("cellSailDescriptorCreateDatabase(pSelf=0x%x, pDatabase=0x%x, size=0x%x, arg=0x%x", pSelf.addr(), pDatabase.addr(), size, arg); @@ -107,7 +107,7 @@ int cellSailDescriptorCreateDatabase(vm::ptr pSelf, vm::ptr< break; } default: - cellSail->Error("Unhandled stream type: %d", pSelf->streamType); + cellSail->Error("Unhandled stream type: %d", pSelf->streamType.ToLE()); } return CELL_OK; diff --git a/rpcs3/Emu/SysCalls/Modules/libmixer.cpp b/rpcs3/Emu/SysCalls/Modules/libmixer.cpp index bfafe453c1..a6859cf19b 100644 --- a/rpcs3/Emu/SysCalls/Modules/libmixer.cpp +++ b/rpcs3/Emu/SysCalls/Modules/libmixer.cpp @@ -23,8 +23,7 @@ std::vector ssp; int cellAANAddData(u32 aan_handle, u32 aan_port, u32 offset, vm::ptr addr, u32 samples) { - libmixer->Log("cellAANAddData(handle=%d, port=%d, offset=0x%x, addr=0x%x, samples=%d)", - aan_handle, aan_port, offset, addr.addr(), samples); + libmixer->Log("cellAANAddData(handle=%d, port=%d, offset=0x%x, addr_addr=0x%x, samples=%d)", aan_handle, aan_port, offset, addr.addr(), samples); u32 type = aan_port >> 16; u32 port = aan_port & 0xffff; @@ -45,8 +44,7 @@ int cellAANAddData(u32 aan_handle, u32 aan_port, u32 offset, vm::ptr addr if (aan_handle != 0x11111111 || samples != 256 || !type || offset != 0) { - libmixer->Error("cellAANAddData(handle=%d, port=%d, offset=0x%x, addr=0x%x, samples=%d): invalid parameters", - aan_handle, aan_port, offset, addr, samples); + libmixer->Error("cellAANAddData(handle=%d, port=%d, offset=0x%x, addr_addr=0x%x, samples=%d): invalid parameters", aan_handle, aan_port, offset, addr.addr(), samples); return CELL_LIBMIXER_ERROR_INVALID_PARAMATER; } diff --git a/rpcs3/Emu/SysCalls/Modules/sceNp.cpp b/rpcs3/Emu/SysCalls/Modules/sceNp.cpp index a05edc415c..5b6ac6cd11 100644 --- a/rpcs3/Emu/SysCalls/Modules/sceNp.cpp +++ b/rpcs3/Emu/SysCalls/Modules/sceNp.cpp @@ -311,7 +311,7 @@ int sceNpBasicAddFriend() int sceNpBasicGetFriendListEntryCount(vm::ptr count) { - sceNp->Warning("sceNpBasicGetFriendListEntryCount(count=%d)", count); + sceNp->Warning("sceNpBasicGetFriendListEntryCount(count_addr=0x%x)", count.addr()); if (!sceNpInstance.m_bSceNpInitialized) return SCE_NP_BASIC_ERROR_NOT_INITIALIZED; @@ -476,7 +476,7 @@ int sceNpBasicGetClanMessageEntry(u32 index, vm::ptr from) int sceNpBasicGetMessageEntryCount(u32 type, vm::ptr count) { - sceNp->Warning("sceNpBasicGetMessageEntryCount(type=%d, count=%d)", type, count); + sceNp->Warning("sceNpBasicGetMessageEntryCount(type=%d, count_addr=0x%x)", type, count.addr()); if (!sceNpInstance.m_bSceNpInitialized) return SCE_NP_BASIC_ERROR_NOT_INITIALIZED; @@ -984,7 +984,7 @@ int sceNpManagerGetAccountAge() int sceNpManagerGetContentRatingFlag(vm::ptr isRestricted, vm::ptr age) { - sceNp->Warning("sceNpManagerGetContentRatingFlag(isRestricted=%d, age=%d)", isRestricted, age); + sceNp->Warning("sceNpManagerGetContentRatingFlag(isRestricted_addr=0x%x, age_addr=0x%x)", isRestricted.addr(), age.addr()); if (!sceNpInstance.m_bSceNpInitialized) return SCE_NP_ERROR_NOT_INITIALIZED; diff --git a/rpcs3/Emu/SysCalls/lv2/cellFs.cpp b/rpcs3/Emu/SysCalls/lv2/cellFs.cpp index 39f25e1513..68247910e4 100644 --- a/rpcs3/Emu/SysCalls/lv2/cellFs.cpp +++ b/rpcs3/Emu/SysCalls/lv2/cellFs.cpp @@ -784,13 +784,13 @@ int sdata_unpack(const std::string& packed_file, const std::string& unpacked_fil if (!packed_stream || !packed_stream->IsOpened()) { - sys_fs->Error("'%s' not found! flags: 0x%08x", packed_file.c_str(), vfsRead); + sys_fs->Error("'%s' not found! flags: 0x%02x", packed_file.c_str(), vfsRead); return CELL_ENOENT; } if (!unpacked_stream || !unpacked_stream->IsOpened()) { - sys_fs->Error("'%s' couldn't be created! flags: 0x%08x", unpacked_file.c_str(), vfsWrite); + sys_fs->Error("'%s' couldn't be created! flags: 0x%02x", unpacked_file.c_str(), vfsWrite); return CELL_ENOENT; } @@ -931,7 +931,7 @@ void fsAioRead(u32 fd, vm::ptr aio, int xid, vm::ptrLog("*** fsAioRead(fd=%d, offset=0x%llx, buf_addr=0x%x, size=0x%x, error=0x%x, res=0x%x, xid=0x%x)", - fd, (u64)aio->offset, aio->buf.addr(), (u64)aio->size, error, res, xid); + fd, (u64)aio->offset, aio->buf.addr().ToLE(), (u64)aio->size, error, res, xid); } if (func) diff --git a/rpcs3/Emu/SysCalls/lv2/sys_lwmutex.cpp b/rpcs3/Emu/SysCalls/lv2/sys_lwmutex.cpp index 0e5eae950c..eee6d815bb 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_lwmutex.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_lwmutex.cpp @@ -24,7 +24,8 @@ s32 lwmutex_create(sys_lwmutex_t& lwmutex, u32 protocol, u32 recursive, u64 name lwmutex.sleep_queue = sq_id; sq->set_full_name(fmt::Format("Lwmutex(%d, addr=0x%x)", sq_id, Memory.RealToVirtualAddr(&lwmutex))); - sys_lwmutex.Notice("*** lwmutex created [%s] (attribute=0x%x): sq_id = %d", std::string((const char*)&name_u64, 8).c_str(), protocol | recursive, sq_id); + // passing be_t (test) + sys_lwmutex.Notice("*** lwmutex created [%s] (attribute=0x%x): sq_id = %d", std::string((const char*)&name_u64, 8).c_str(), lwmutex.attribute, sq_id); return CELL_OK; } diff --git a/rpcs3/Emu/SysCalls/lv2/sys_mutex.cpp b/rpcs3/Emu/SysCalls/lv2/sys_mutex.cpp index 07ca016830..b85f8e1e5e 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_mutex.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_mutex.cpp @@ -16,12 +16,12 @@ Mutex::~Mutex() { if (u32 tid = owner.read_sync()) { - sys_mutex.Notice("Mutex(%d) was owned by thread %d (recursive=%d)", id, tid, recursive_count.load()); + sys_mutex.Notice("Mutex(%d) was owned by thread %d (recursive=%d)", id.read_relaxed(), tid, recursive_count.load()); } if (u32 count = queue.count()) { - sys_mutex.Notice("Mutex(%d) was waited by %d threads", id, count); + sys_mutex.Notice("Mutex(%d) was waited by %d threads", id.read_relaxed(), count); } } diff --git a/rpcs3/Emu/SysCalls/lv2/sys_prx.h b/rpcs3/Emu/SysCalls/lv2/sys_prx.h index 2e024c1bde..f0c550ecff 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_prx.h +++ b/rpcs3/Emu/SysCalls/lv2/sys_prx.h @@ -71,7 +71,7 @@ struct sys_prx_module_info_t { be_t attributes; be_t version; - s8 name[28]; + char name[28]; be_t toc; vm::bptr exports_start; vm::bptr exports_end; diff --git a/rpcs3/Gui/MainFrame.cpp b/rpcs3/Gui/MainFrame.cpp index 5c13cc2f9f..65d98ba622 100644 --- a/rpcs3/Gui/MainFrame.cpp +++ b/rpcs3/Gui/MainFrame.cpp @@ -221,7 +221,7 @@ void MainFrame::BootGame(wxCommandEvent& WXUNUSED(event)) } else { - LOG_ERROR(HLE, "PS3 executable not found in selected folder (%s)", ctrl.GetPath().wx_str()); + LOG_ERROR(HLE, "PS3 executable not found in selected folder (%s)", fmt::ToUTF8(ctrl.GetPath())); // passing std::string (test) } } diff --git a/rpcs3/Gui/VHDDManager.cpp b/rpcs3/Gui/VHDDManager.cpp index 398c893827..aa818aa7a8 100644 --- a/rpcs3/Gui/VHDDManager.cpp +++ b/rpcs3/Gui/VHDDManager.cpp @@ -190,7 +190,7 @@ void VHDDExplorer::OnDropFiles(wxDropFilesEvent& event) for(int i=0; iSeek(handler::get_stream_offset() + phdr.p_paddr.addr()); m_stream->Read(&module_info, sizeof(module_info)); LOG_ERROR(LOADER, "%s (%x):", module_info.name, (u32)module_info.toc); - info.name = std::string((const char*)module_info.name, 28); + info.name = std::string(module_info.name, 28); info.rtoc = module_info.toc; int import_count = (module_info.imports_end - module_info.imports_start) / sizeof(sys_prx_library_info_t); if (import_count) { - LOG_ERROR(LOADER, "**** Lib '%s'has %d imports!", module_info.name, import_count); + LOG_ERROR(LOADER, "**** Lib '%s' has %d imports!", module_info.name, import_count); } sys_prx_library_info_t lib; @@ -406,7 +406,8 @@ namespace loader { if (!vm::alloc(phdr.p_vaddr.addr(), (u32)phdr.p_memsz, vm::main)) { - LOG_ERROR(LOADER, "%s(): AllocFixed(0x%llx, 0x%x) failed", __FUNCTION__, phdr.p_vaddr, (u32)phdr.p_memsz); + // addr() has be_t<> type (test) + LOG_ERROR(LOADER, "%s(): AllocFixed(0x%llx, 0x%x) failed", __FUNCTION__, phdr.p_vaddr.addr(), (u32)phdr.p_memsz); return loading_error; } diff --git a/rpcs3/stdafx.cpp b/rpcs3/stdafx.cpp index fd4f341c7b..6785d8ba9b 100644 --- a/rpcs3/stdafx.cpp +++ b/rpcs3/stdafx.cpp @@ -1 +1,11 @@ #include "stdafx.h" + +std::string u128::to_hex() const +{ + return fmt::Format("%016llx%016llx", _u64[1], _u64[0]); +} + +std::string u128::to_xyzw() const +{ + return fmt::Format("x: %g y: %g z: %g w: %g", _f[3], _f[2], _f[1], _f[0]); +} diff --git a/rpcs3/stdafx.h b/rpcs3/stdafx.h index 2ca972bc49..825c1c4007 100644 --- a/rpcs3/stdafx.h +++ b/rpcs3/stdafx.h @@ -55,8 +55,8 @@ template __forceinline T align(const T addr, int align) return (addr + (align - 1)) & ~(align - 1); } -#include "Utilities/StrFmt.h" #include "Utilities/BEType.h" +#include "Utilities/StrFmt.h" #define _PRGNAME_ "RPCS3" #define _PRGVER_ "0.0.0.5"