diff --git a/Utilities/BEType.h b/Utilities/BEType.h index 768e25770c..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) { @@ -378,65 +372,97 @@ template struct se_t; template struct se_t { - static __forceinline T func(const T src) + static __forceinline u8 to_be(const T& src) { - return src; + return (u8&)src; + } + + static __forceinline T from_be(const u8 src) + { + return (T&)src; } }; template struct se_t { - static __forceinline T func(const T src) + static __forceinline u16 to_be(const T& src) { - const u16 res = _byteswap_ushort((u16&)src); + return _byteswap_ushort((u16&)src); + } + + static __forceinline T from_be(const u16 src) + { + const u16 res = _byteswap_ushort(src); return (T&)res; } }; template struct se_t { - static __forceinline T func(const T src) + static __forceinline u32 to_be(const T& src) { - const u32 res = _byteswap_ulong((u32&)src); + return _byteswap_ulong((u32&)src); + } + + static __forceinline T from_be(const u32 src) + { + const u32 res = _byteswap_ulong(src); return (T&)res; } }; template struct se_t { - static __forceinline T func(const T src) + static __forceinline u64 to_be(const T& src) { - const u64 res = _byteswap_uint64((u64&)src); + return _byteswap_uint64((u64&)src); + } + + static __forceinline T from_be(const u64 src) + { + const u64 res = _byteswap_uint64(src); return (T&)res; } }; -//template T re(const T val) { T res; se_t::func(res, val); return res; } -//template void re(T1& dst, const T2 val) { se_t::func(dst, val); } - -template struct const_se_t; -template struct const_se_t +template struct se_t { - static const T value = (T)_value; + static __forceinline u128 to_be(const T& src) + { + return u128::byteswap((u128&)src); + } + + static __forceinline T from_be(const u128& src) + { + const u128 res = u128::byteswap(src); + return (T&)res; + } }; -template struct const_se_t +template struct const_se_t; + +template struct const_se_t { - static const T value = ((_value >> 8) & 0xff) | ((_value << 8) & 0xff00); + static const u8 value = _value; }; -template struct const_se_t +template struct const_se_t { - static const T value = + static const u16 value = ((_value >> 8) & 0xff) | ((_value << 8) & 0xff00); +}; + +template struct const_se_t +{ + static const u32 value = ((_value >> 24) & 0x000000ff) | ((_value >> 8) & 0x0000ff00) | ((_value << 8) & 0x00ff0000) | ((_value << 24) & 0xff000000); }; -template struct const_se_t +template struct const_se_t { - static const T value = + static const u64 value = ((_value >> 56) & 0x00000000000000ff) | ((_value >> 40) & 0x000000000000ff00) | ((_value >> 24) & 0x0000000000ff0000) | @@ -447,17 +473,53 @@ template struct const_se_t ((_value << 56) & 0xff00000000000000); }; +template +struct be_storage_t +{ + static_assert(!size, "Bad be_storage_t type"); +}; + +template +struct be_storage_t +{ + typedef u8 type; +}; + +template +struct be_storage_t +{ + typedef u16 type; +}; + +template +struct be_storage_t +{ + typedef u32 type; +}; + +template +struct be_storage_t +{ + typedef u64 type; +}; + +template +struct be_storage_t +{ + typedef u128 type; +}; + +#define IS_LE_MACHINE + template class be_t { - static_assert(sizeof(T2) == 1 || sizeof(T2) == 2 || sizeof(T2) == 4 || sizeof(T2) == 8, "Bad be_t type"); - public: typedef typename std::remove_cv::type type; - static const bool is_le_machine = true; + typedef typename be_storage_t::type stype; private: - type m_data; + stype m_data; template struct _convert @@ -490,62 +552,71 @@ private: }; public: - const type& ToBE() const + const stype& ToBE() const { return m_data; } type ToLE() const { - return se_t::func(m_data); + return se_t::from_be(m_data); } - void FromBE(const type& value) + void FromBE(const stype& value) { m_data = value; } void FromLE(const type& value) { - m_data = se_t::func(value); + m_data = se_t::to_be(value); } - static be_t MakeFromLE(const type value) + static be_t MakeFromLE(const type& value) { - type data = se_t::func(value); + stype data = se_t::to_be(value); return (be_t&)data; } - static be_t MakeFromBE(const type value) + static be_t MakeFromBE(const stype& value) { return (be_t&)value; } //make be_t from current machine byte ordering - static be_t make(const type value) + static be_t make(const type& value) { - return is_le_machine ? MakeFromLE(value) : MakeFromBE(value); +#ifdef IS_LE_MACHINE + return MakeFromLE(value); +#else + return MakeFromBE(value); +#endif } //get value in current machine byte ordering __forceinline type value() const { - return is_le_machine ? ToLE() : ToBE(); +#ifdef IS_LE_MACHINE + return ToLE(); +#else + return ToBE(); +#endif } - //be_t() = default; - //be_t(const be_t& value) = default; - - //be_t(type value) - //{ - // m_data = se_t::func(value); - //} + const stype& data() const + { +#ifdef IS_LE_MACHINE + return ToBE(); +#else + return ToLE(); +#endif + } be_t& operator = (const be_t& value) = default; - be_t& operator = (type value) + be_t& operator = (const type& value) { - m_data = se_t::func(value); + m_data = se_t::to_be(value); return *this; } @@ -821,4 +892,4 @@ template __forceinline void convert_le_be(Tto& dst, Tfrom&& src) { dst = convert_le_be_t::func(src); -} \ No newline at end of file +} diff --git a/Utilities/GNU.h b/Utilities/GNU.h index 91fc34ae50..b1988b4dfa 100644 --- a/Utilities/GNU.h +++ b/Utilities/GNU.h @@ -289,9 +289,7 @@ static __forceinline uint64_t InterlockedXor(volatile uint64_t* dest, uint64_t v static __forceinline uint32_t cntlz32(uint32_t arg) { -#if defined(__GNUG__) - return __builtin_clzl(arg); -#else +#if defined(_MSC_VER) unsigned long res; if (!_BitScanReverse(&res, arg)) { @@ -301,14 +299,21 @@ static __forceinline uint32_t cntlz32(uint32_t arg) { return res ^ 31; } +#else + if (arg) + { + return __builtin_clzll((uint64_t)arg) - 32; + } + else + { + return 32; + } #endif } static __forceinline uint64_t cntlz64(uint64_t arg) { -#if defined(__GNUG__) - return __builtin_clzll(arg); -#else +#if defined(_MSC_VER) unsigned long res; if (!_BitScanReverse64(&res, arg)) { @@ -318,6 +323,15 @@ static __forceinline uint64_t cntlz64(uint64_t arg) { return res ^ 63; } +#else + if (arg) + { + return __builtin_clzll(arg); + } + else + { + return 64; + } #endif } diff --git a/Utilities/Log.h b/Utilities/Log.h index c40d2a82c6..2fde92ee46 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 +template inline void log_message(Log::LogType type, Log::LogSeverity sev, const char* text, 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.cpp b/Utilities/StrFmt.cpp index 1d3e6144e0..7835bf0c9e 100644 --- a/Utilities/StrFmt.cpp +++ b/Utilities/StrFmt.cpp @@ -1,7 +1,16 @@ #include "stdafx.h" -#include "StrFmt.h" #include +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]); +} + extern const std::string fmt::placeholder = "???"; std::string replace_first(const std::string& src, const std::string& from, const std::string& to) diff --git a/Utilities/StrFmt.h b/Utilities/StrFmt.h index 963bb8b1b8..919de94e27 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,509 @@ 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 (char[size])"; + // } + + // 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{}; + } + }; + + 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); + } + + 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...); + } + }; + + // 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*, std::string (%s) + be_t<> of any appropriate type in this list + enum 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/Crypto/unedat.cpp b/rpcs3/Crypto/unedat.cpp index 27ddbffb6a..f4d57c49d0 100644 --- a/rpcs3/Crypto/unedat.cpp +++ b/rpcs3/Crypto/unedat.cpp @@ -288,7 +288,7 @@ int decrypt_data(rFile *in, rFile *out, EDAT_HEADER *edat, NPD_HEADER *npd, unsi if (!decrypt(hash_mode, crypto_mode, (npd->version == 4), enc_data, dec_data, length, key_result, iv, hash, hash_result)) { if (verbose) - LOG_WARNING(LOADER, "EDAT: Block at offset 0x%llx has invalid hash!", offset); + LOG_WARNING(LOADER, "EDAT: Block at offset 0x%llx has invalid hash!", (u64)offset); return 1; } @@ -695,7 +695,7 @@ bool extract_data(rFile *input, rFile *output, const char* input_file_name, unsi LOG_NOTICE(LOADER, "SDAT HEADER"); LOG_NOTICE(LOADER, "SDAT flags: 0x%08X", EDAT->flags); LOG_NOTICE(LOADER, "SDAT block size: 0x%08X", EDAT->block_size); - LOG_NOTICE(LOADER, "SDAT file size: 0x%08X", EDAT->file_size); + LOG_NOTICE(LOADER, "SDAT file size: 0x%08X", (u64)EDAT->file_size); } // Generate SDAT key. @@ -708,7 +708,7 @@ bool extract_data(rFile *input, rFile *output, const char* input_file_name, unsi LOG_NOTICE(LOADER, "EDAT HEADER"); LOG_NOTICE(LOADER, "EDAT flags: 0x%08X", EDAT->flags); LOG_NOTICE(LOADER, "EDAT block size: 0x%08X", EDAT->block_size); - LOG_NOTICE(LOADER, "EDAT file size: 0x%08X", EDAT->file_size); + LOG_NOTICE(LOADER, "EDAT file size: 0x%08X", (u64)EDAT->file_size); } // Perform header validation (EDAT only). diff --git a/rpcs3/Crypto/unpkg.cpp b/rpcs3/Crypto/unpkg.cpp index bf9fd0edea..4dcac95248 100644 --- a/rpcs3/Crypto/unpkg.cpp +++ b/rpcs3/Crypto/unpkg.cpp @@ -164,12 +164,12 @@ bool UnpackEntry(rFile& dec_pkg_f, const PKGEntry& entry, std::string dir) dec_pkg_f.Read(buf, entry.name_size); buf[entry.name_size] = 0; - switch (entry.type.ToBE() >> 24) + switch (entry.type.data()) { - case PKG_FILE_ENTRY_NPDRM: - case PKG_FILE_ENTRY_NPDRMEDAT: - case PKG_FILE_ENTRY_SDAT: - case PKG_FILE_ENTRY_REGULAR: + case se32(PKG_FILE_ENTRY_NPDRM): + case se32(PKG_FILE_ENTRY_NPDRMEDAT): + case se32(PKG_FILE_ENTRY_SDAT): + case se32(PKG_FILE_ENTRY_REGULAR): { rFile out; auto path = dir + std::string(buf, entry.name_size); @@ -199,7 +199,7 @@ bool UnpackEntry(rFile& dec_pkg_f, const PKGEntry& entry, std::string dir) } } - case PKG_FILE_ENTRY_FOLDER: + case se32(PKG_FILE_ENTRY_FOLDER): { auto path = dir + std::string(buf, entry.name_size); if (!rExists(path) && !rMkdir(path)) @@ -213,7 +213,7 @@ bool UnpackEntry(rFile& dec_pkg_f, const PKGEntry& entry, std::string dir) default: { - LOG_ERROR(LOADER, "PKG Loader: unknown PKG file entry: 0x%x", entry.type.ToLE()); + LOG_ERROR(LOADER, "PKG Loader: unknown PKG file entry: 0x%x", entry.type); return false; } } 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/Cell/RawSPUThread.cpp b/rpcs3/Emu/Cell/RawSPUThread.cpp index 9ee54411c0..ba4c98f363 100644 --- a/rpcs3/Emu/Cell/RawSPUThread.cpp +++ b/rpcs3/Emu/Cell/RawSPUThread.cpp @@ -141,7 +141,7 @@ bool RawSPUThread::Write32(const u64 addr, const u32 value) { // calling Exec() directly in SIGSEGV handler may cause problems // (probably because Exec() creates new thread, faults of this thread aren't handled by this handler anymore) - Emu.GetCallbackManager().Async([this]() + Emu.GetCallbackManager().Async([this](PPUThread& PPU) { SPU.Status.SetValue(SPU_STATUS_RUNNING); Exec(); 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/Memory/vm_ptr.h b/rpcs3/Emu/Memory/vm_ptr.h index 60ae33900b..df230aad00 100644 --- a/rpcs3/Emu/Memory/vm_ptr.h +++ b/rpcs3/Emu/Memory/vm_ptr.h @@ -356,7 +356,7 @@ namespace vm public: typedef RT(*type)(T...); - RT call(CPUThread& CPU, T... args) const; // defined in CB_FUNC.h, call using specified CPU thread context + RT operator()(CPUThread& CPU, T... args) const; // defined in CB_FUNC.h, call using specified CPU thread context RT operator()(T... args) const; // defined in CB_FUNC.h, call using current CPU thread context diff --git a/rpcs3/Emu/RSX/RSXThread.cpp b/rpcs3/Emu/RSX/RSXThread.cpp index 660781eb51..1832b97cb6 100644 --- a/rpcs3/Emu/RSX/RSXThread.cpp +++ b/rpcs3/Emu/RSX/RSXThread.cpp @@ -289,9 +289,9 @@ void RSXThread::DoCmd(const u32 fcmd, const u32 cmd, const u32 args_addr, const if (m_flip_handler) { auto cb = m_flip_handler; - Emu.GetCallbackManager().Async([cb]() + Emu.GetCallbackManager().Async([cb](PPUThread& CPU) { - cb(1); + cb(CPU, 1); }); } @@ -2201,9 +2201,9 @@ void RSXThread::DoCmd(const u32 fcmd, const u32 cmd, const u32 args_addr, const { const u32 cause = ARGS(0); auto cb = m_user_handler; - Emu.GetCallbackManager().Async([cb, cause]() + Emu.GetCallbackManager().Async([cb, cause](PPUThread& CPU) { - cb(cause); + cb(CPU, cause); }); } break; @@ -2370,9 +2370,9 @@ void RSXThread::Task() if (m_vblank_handler) { auto cb = m_vblank_handler; - Emu.GetCallbackManager().Async([cb]() + Emu.GetCallbackManager().Async([cb](PPUThread& CPU) { - cb(1); + cb(CPU, 1); }); } continue; diff --git a/rpcs3/Emu/SysCalls/CB_FUNC.h b/rpcs3/Emu/SysCalls/CB_FUNC.h index ed711656c1..78b82961dc 100644 --- a/rpcs3/Emu/SysCalls/CB_FUNC.h +++ b/rpcs3/Emu/SysCalls/CB_FUNC.h @@ -163,18 +163,19 @@ namespace cb_detail namespace vm { template - __forceinline RT _ptr_base::call(CPUThread& CPU, T... args) const + __forceinline RT _ptr_base::operator()(CPUThread& CPU, T... args) const { const u32 pc = vm::get_ref>((u32)m_addr); const u32 rtoc = vm::get_ref>((u32)m_addr + 4); + assert(CPU.GetType() == CPU_THREAD_PPU); return cb_detail::_func_caller::call(static_cast(CPU), pc, rtoc, args...); } template - __forceinline RT _ptr_base::operator ()(T... args) const + __forceinline RT _ptr_base::operator()(T... args) const { - return call(GetCurrentPPUThread(), args...); + return operator()(GetCurrentPPUThread(), args...); } } diff --git a/rpcs3/Emu/SysCalls/Callback.cpp b/rpcs3/Emu/SysCalls/Callback.cpp index 71fa8ba830..e01b341fbe 100644 --- a/rpcs3/Emu/SysCalls/Callback.cpp +++ b/rpcs3/Emu/SysCalls/Callback.cpp @@ -7,25 +7,33 @@ #include "Emu/ARMv7/ARMv7Thread.h" #include "Callback.h" -void CallbackManager::Register(const std::function& func) +void CallbackManager::Register(const std::function& func) { std::lock_guard lock(m_mutex); - m_cb_list.push_back(func); + m_cb_list.push_back([=](CPUThread& CPU) -> s32 + { + assert(CPU.GetType() == CPU_THREAD_PPU); + return func(static_cast(CPU)); + }); } -void CallbackManager::Async(const std::function& func) +void CallbackManager::Async(const std::function& func) { std::lock_guard lock(m_mutex); - m_async_list.push_back(func); + m_async_list.push_back([=](CPUThread& CPU) + { + assert(CPU.GetType() == CPU_THREAD_PPU); + func(static_cast(CPU)); + }); + m_cb_thread->Notify(); } -bool CallbackManager::Check(s32& result) +bool CallbackManager::Check(CPUThread& CPU, s32& result) { - std::function func = nullptr; - + std::function func; { std::lock_guard lock(m_mutex); @@ -38,7 +46,7 @@ bool CallbackManager::Check(s32& result) if (func) { - result = func(); + result = func(CPU); return true; } else @@ -80,7 +88,7 @@ void CallbackManager::Init() while (!Emu.IsStopped()) { - std::function func = nullptr; + std::function func; { std::lock_guard lock(m_mutex); @@ -93,9 +101,10 @@ void CallbackManager::Init() if (func) { - func(); + func(*m_cb_thread); continue; } + m_cb_thread->WaitForAnySignal(); } }); diff --git a/rpcs3/Emu/SysCalls/Callback.h b/rpcs3/Emu/SysCalls/Callback.h index ba16b38830..7cb6b8699b 100644 --- a/rpcs3/Emu/SysCalls/Callback.h +++ b/rpcs3/Emu/SysCalls/Callback.h @@ -1,20 +1,21 @@ #pragma once class CPUThread; +class PPUThread; class CallbackManager { - std::vector> m_cb_list; - std::vector> m_async_list; + std::vector> m_cb_list; + std::vector> m_async_list; CPUThread* m_cb_thread; std::mutex m_mutex; public: - void Register(const std::function& func); // register callback (called in Check() method) + void Register(const std::function& func); // register callback (called in Check() method) - void Async(const std::function& func); // register callback for callback thread (called immediately) + void Async(const std::function& func); // register callback for callback thread (called immediately) - bool Check(s32& result); // call one callback registered by Register() method + bool Check(CPUThread& CPU, s32& result); // call one callback registered by Register() method void Init(); 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/cellAdec.cpp b/rpcs3/Emu/SysCalls/Modules/cellAdec.cpp index 139ab029f0..8e91455acf 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellAdec.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellAdec.cpp @@ -174,7 +174,7 @@ next: buf_size -= adec.reader.size; res += adec.reader.size; - adec.cbFunc.call(*adec.adecCb, adec.id, CELL_ADEC_MSG_TYPE_AUDONE, adec.task.au.auInfo_addr, adec.cbArg); + adec.cbFunc(*adec.adecCb, adec.id, CELL_ADEC_MSG_TYPE_AUDONE, adec.task.au.auInfo_addr, adec.cbArg); adec.job.pop(adec.task); @@ -279,7 +279,7 @@ u32 adecOpen(AudioDecoder* adec_ptr) { // TODO: finalize cellAdec->Warning("adecEndSeq:"); - adec.cbFunc.call(*adec.adecCb, adec.id, CELL_ADEC_MSG_TYPE_SEQDONE, CELL_OK, adec.cbArg); + adec.cbFunc(*adec.adecCb, adec.id, CELL_ADEC_MSG_TYPE_SEQDONE, CELL_OK, adec.cbArg); adec.just_finished = true; break; @@ -455,12 +455,12 @@ u32 adecOpen(AudioDecoder* adec_ptr) if (adec.frames.push(frame, &adec.is_closed)) { frame.data = nullptr; // to prevent destruction - adec.cbFunc.call(*adec.adecCb, adec.id, CELL_ADEC_MSG_TYPE_PCMOUT, CELL_OK, adec.cbArg); + adec.cbFunc(*adec.adecCb, adec.id, CELL_ADEC_MSG_TYPE_PCMOUT, CELL_OK, adec.cbArg); } } } - adec.cbFunc.call(*adec.adecCb, adec.id, CELL_ADEC_MSG_TYPE_AUDONE, task.au.auInfo_addr, adec.cbArg); + adec.cbFunc(*adec.adecCb, adec.id, CELL_ADEC_MSG_TYPE_AUDONE, task.au.auInfo_addr, adec.cbArg); break; } 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 5c17b81125..ac2bd1368e 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellDmux.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellDmux.cpp @@ -83,7 +83,7 @@ PesHeader::PesHeader(DemuxerStream& stream) ElementaryStream::ElementaryStream(Demuxer* dmux, u32 addr, u32 size, u32 fidMajor, u32 fidMinor, u32 sup1, u32 sup2, vm::ptr cbFunc, u32 cbArg, u32 spec) : dmux(dmux) - , memAddr(a128(addr)) + , memAddr(align(addr, 128)) , memSize(size - (addr - memAddr)) , fidMajor(fidMajor) , fidMinor(fidMinor) @@ -92,7 +92,7 @@ ElementaryStream::ElementaryStream(Demuxer* dmux, u32 addr, u32 size, u32 fidMaj , cbFunc(cbFunc) , cbArg(cbArg) , spec(spec) - , put(a128(addr)) + , put(align(addr, 128)) , put_count(0) , got_count(0) , released(0) @@ -184,7 +184,7 @@ void ElementaryStream::push_au(u32 size, u64 dts, u64 pts, u64 userdata, bool ra addr = put; - put = a128(put + 128 + size); + put = align(put + 128 + size, 128); put_count++; } @@ -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 = {}; @@ -347,10 +347,10 @@ u32 dmuxOpen(Demuxer* dmux_ptr) if (!stream.peek(code)) { // demuxing finished - auto dmuxMsg = vm::ptr::make(a128(dmux.memAddr) + (cb_add ^= 16)); + auto dmuxMsg = vm::ptr::make(dmux.memAddr + (cb_add ^= 16)); dmuxMsg->msgType = CELL_DMUX_MSG_TYPE_DEMUX_DONE; dmuxMsg->supplementalInfo = stream.userdata; - dmux.cbFunc.call(*dmux.dmuxCb, dmux.id, dmuxMsg, dmux.cbArg); + dmux.cbFunc(*dmux.dmuxCb, dmux.id, dmuxMsg, dmux.cbArg); dmux.is_running = false; continue; @@ -497,10 +497,10 @@ u32 dmuxOpen(Demuxer* dmux_ptr) //cellDmux->Notice("ATX AU pushed (ats=0x%llx, frame_size=%d)", ((be_t*)data)->ToLE(), frame_size); - auto esMsg = vm::ptr::make(a128(dmux.memAddr) + (cb_add ^= 16)); + auto esMsg = vm::ptr::make(dmux.memAddr + (cb_add ^= 16)); esMsg->msgType = CELL_DMUX_ES_MSG_TYPE_AU_FOUND; esMsg->supplementalInfo = stream.userdata; - es.cbFunc.call(*dmux.dmuxCb, dmux.id, es.id, esMsg, es.cbArg); + es.cbFunc(*dmux.dmuxCb, dmux.id, es.id, esMsg, es.cbArg); } } else @@ -562,10 +562,10 @@ u32 dmuxOpen(Demuxer* dmux_ptr) es.push_au(old_size, es.last_dts, es.last_pts, stream.userdata, false /* TODO: set correct value */, 0); // callback - auto esMsg = vm::ptr::make(a128(dmux.memAddr) + (cb_add ^= 16)); + auto esMsg = vm::ptr::make(dmux.memAddr + (cb_add ^= 16)); esMsg->msgType = CELL_DMUX_ES_MSG_TYPE_AU_FOUND; esMsg->supplementalInfo = stream.userdata; - es.cbFunc.call(*dmux.dmuxCb, dmux.id, es.id, esMsg, es.cbArg); + es.cbFunc(*dmux.dmuxCb, dmux.id, es.id, esMsg, es.cbArg); } if (pes.has_ts) @@ -634,10 +634,10 @@ u32 dmuxOpen(Demuxer* dmux_ptr) case dmuxResetStream: case dmuxResetStreamAndWaitDone: { - auto dmuxMsg = vm::ptr::make(a128(dmux.memAddr) + (cb_add ^= 16)); + auto dmuxMsg = vm::ptr::make(dmux.memAddr + (cb_add ^= 16)); dmuxMsg->msgType = CELL_DMUX_MSG_TYPE_DEMUX_DONE; dmuxMsg->supplementalInfo = stream.userdata; - dmux.cbFunc.call(*dmux.dmuxCb, dmux.id, dmuxMsg, dmux.cbArg); + dmux.cbFunc(*dmux.dmuxCb, dmux.id, dmuxMsg, dmux.cbArg); stream = {}; dmux.is_running = false; @@ -722,10 +722,10 @@ u32 dmuxOpen(Demuxer* dmux_ptr) es.push_au(old_size, es.last_dts, es.last_pts, stream.userdata, false, 0); // callback - auto esMsg = vm::ptr::make(a128(dmux.memAddr) + (cb_add ^= 16)); + auto esMsg = vm::ptr::make(dmux.memAddr + (cb_add ^= 16)); esMsg->msgType = CELL_DMUX_ES_MSG_TYPE_AU_FOUND; esMsg->supplementalInfo = stream.userdata; - es.cbFunc.call(*dmux.dmuxCb, dmux.id, es.id, esMsg, es.cbArg); + es.cbFunc(*dmux.dmuxCb, dmux.id, es.id, esMsg, es.cbArg); } if (es.raw_data.size()) @@ -734,10 +734,10 @@ u32 dmuxOpen(Demuxer* dmux_ptr) } // callback - auto esMsg = vm::ptr::make(a128(dmux.memAddr) + (cb_add ^= 16)); + auto esMsg = vm::ptr::make(dmux.memAddr + (cb_add ^= 16)); esMsg->msgType = CELL_DMUX_ES_MSG_TYPE_FLUSH_DONE; esMsg->supplementalInfo = stream.userdata; - es.cbFunc.call(*dmux.dmuxCb, dmux.id, es.id, esMsg, es.cbArg); + es.cbFunc(*dmux.dmuxCb, dmux.id, es.id, esMsg, es.cbArg); break; } @@ -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/cellDmux.h b/rpcs3/Emu/SysCalls/Modules/cellDmux.h index 6f0ed352b3..8a2a70cc5b 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellDmux.h +++ b/rpcs3/Emu/SysCalls/Modules/cellDmux.h @@ -1,8 +1,5 @@ #pragma once -// align size or address to 128 -#define a128(x) ((x + 127) & (~127)) - // Error Codes enum { 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/cellMsgDialog.cpp b/rpcs3/Emu/SysCalls/Modules/cellMsgDialog.cpp index f6f7fefbbe..a652d134f9 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellMsgDialog.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellMsgDialog.cpp @@ -171,10 +171,10 @@ s32 cellMsgDialogOpen2(u32 type, vm::ptr msgString, vm::ptr s32 + const s32 status = (s32)g_msg_dialog_status; + Emu.GetCallbackManager().Register([callback, userData, status](PPUThread& PPU) -> s32 { - callback(status, userData); + callback(PPU, status, userData); return CELL_OK; }); } diff --git a/rpcs3/Emu/SysCalls/Modules/cellPngDec.cpp b/rpcs3/Emu/SysCalls/Modules/cellPngDec.cpp index 973c1dff2b..ad1edb197e 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellPngDec.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellPngDec.cpp @@ -77,7 +77,7 @@ s64 pngDecOpen( stream->fd = 0; stream->src = *src; - switch ((u32)src->srcSelect.ToBE()) + switch (src->srcSelect.ToBE()) { case se32(CELL_PNGDEC_BUFFER): stream->fileSize = src->streamSize.ToLE(); @@ -145,7 +145,7 @@ s64 pngReadHeader( auto buffer_32 = buffer.To>(); vm::var> pos, nread; - switch ((u32)stream->src.srcSelect.ToBE()) + switch (stream->src.srcSelect.ToBE()) { case se32(CELL_PNGDEC_BUFFER): memmove(buffer.begin(), stream->src.streamPtr.get_ptr(), buffer.size()); @@ -206,7 +206,7 @@ s64 pngDecSetParameter( current_outParam.outputHeight = current_info.imageHeight; current_outParam.outputColorSpace = inParam->outputColorSpace; - switch ((u32)current_outParam.outputColorSpace.ToBE()) + switch (current_outParam.outputColorSpace.ToBE()) { case se32(CELL_PNGDEC_PALETTE): case se32(CELL_PNGDEC_GRAYSCALE): @@ -254,7 +254,7 @@ s64 pngDecodeData( vm::var png((u32)fileSize); vm::var> pos, nread; - switch ((u32)stream->src.srcSelect.ToBE()) + switch (stream->src.srcSelect.ToBE()) { case se32(CELL_PNGDEC_BUFFER): memmove(png.begin(), stream->src.streamPtr.get_ptr(), png.size()); @@ -283,7 +283,7 @@ s64 pngDecodeData( const int bytesPerLine = (u32)dataCtrlParam->outputBytesPerLine; uint image_size = width * height; - switch ((u32)current_outParam.outputColorSpace.ToBE()) + switch (current_outParam.outputColorSpace.ToBE()) { case se32(CELL_PNGDEC_RGB): case se32(CELL_PNGDEC_RGBA): 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/cellSysutil.cpp b/rpcs3/Emu/SysCalls/Modules/cellSysutil.cpp index 06c419b4b8..cae2a74172 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellSysutil.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellSysutil.cpp @@ -316,23 +316,23 @@ void sysutilSendSystemCommand(u64 status, u64 param) { if (cb.func) { - Emu.GetCallbackManager().Register([=]() -> s32 + Emu.GetCallbackManager().Register([=](PPUThread& PPU) -> s32 { - cb.func(status, param, cb.arg); + cb.func(PPU, status, param, cb.arg); return CELL_OK; }); } } } -s32 cellSysutilCheckCallback() +s32 cellSysutilCheckCallback(PPUThread& CPU) { cellSysutil->Log("cellSysutilCheckCallback()"); s32 res; u32 count = 0; - while (Emu.GetCallbackManager().Check(res)) + while (Emu.GetCallbackManager().Check(CPU, res)) { count++; diff --git a/rpcs3/Emu/SysCalls/Modules/cellVdec.cpp b/rpcs3/Emu/SysCalls/Modules/cellVdec.cpp index ddf5726ff4..7776ebfbc0 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellVdec.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellVdec.cpp @@ -147,7 +147,7 @@ next: buf_size -= vdec.reader.size; res += vdec.reader.size; - vdec.cbFunc.call(*vdec.vdecCb, vdec.id, CELL_VDEC_MSG_TYPE_AUDONE, CELL_OK, vdec.cbArg); + vdec.cbFunc(*vdec.vdecCb, vdec.id, CELL_VDEC_MSG_TYPE_AUDONE, CELL_OK, vdec.cbArg); vdec.job.pop(vdec.task); @@ -259,7 +259,7 @@ u32 vdecOpen(VideoDecoder* vdec_ptr) // TODO: finalize cellVdec->Warning("vdecEndSeq:"); - vdec.cbFunc.call(*vdec.vdecCb, vdec.id, CELL_VDEC_MSG_TYPE_SEQDONE, CELL_OK, vdec.cbArg); + vdec.cbFunc(*vdec.vdecCb, vdec.id, CELL_VDEC_MSG_TYPE_SEQDONE, CELL_OK, vdec.cbArg); vdec.just_finished = true; break; @@ -516,12 +516,12 @@ u32 vdecOpen(VideoDecoder* vdec_ptr) if (vdec.frames.push(frame, &vdec.is_closed)) { frame.data = nullptr; // to prevent destruction - vdec.cbFunc.call(*vdec.vdecCb, vdec.id, CELL_VDEC_MSG_TYPE_PICOUT, CELL_OK, vdec.cbArg); + vdec.cbFunc(*vdec.vdecCb, vdec.id, CELL_VDEC_MSG_TYPE_PICOUT, CELL_OK, vdec.cbArg); } } } - vdec.cbFunc.call(*vdec.vdecCb, vdec.id, CELL_VDEC_MSG_TYPE_AUDONE, CELL_OK, vdec.cbArg); + vdec.cbFunc(*vdec.vdecCb, vdec.id, CELL_VDEC_MSG_TYPE_AUDONE, CELL_OK, vdec.cbArg); break; } @@ -693,7 +693,7 @@ int cellVdecGetPicture(u32 handle, vm::ptr format, vm:: if (outBuff) { - u32 buf_size = a128(av_image_get_buffer_size(vdec->ctx->pix_fmt, vdec->ctx->width, vdec->ctx->height, 1)); + const u32 buf_size = align(av_image_get_buffer_size(vdec->ctx->pix_fmt, vdec->ctx->width, vdec->ctx->height, 1), 128); if (format->formatType != CELL_VDEC_PICFMT_YUV420_PLANAR) { @@ -753,7 +753,7 @@ int cellVdecGetPicItem(u32 handle, vm::ptr picItem_ptr) info->codecType = vdec->type; info->startAddr = 0x00000123; // invalid value (no address for picture) - info->size = a128(av_image_get_buffer_size(vdec->ctx->pix_fmt, vdec->ctx->width, vdec->ctx->height, 1)); + info->size = align(av_image_get_buffer_size(vdec->ctx->pix_fmt, vdec->ctx->width, vdec->ctx->height, 1), 128); info->auNum = 1; info->auPts[0].lower = (u32)vf.pts; info->auPts[0].upper = vf.pts >> 32; diff --git a/rpcs3/Emu/SysCalls/Modules/cellVdec.h b/rpcs3/Emu/SysCalls/Modules/cellVdec.h index e03cc26f06..e53955e70e 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellVdec.h +++ b/rpcs3/Emu/SysCalls/Modules/cellVdec.h @@ -1,7 +1,5 @@ #pragma once -#define a128(x) ((x + 127) & (~127)) - // Error Codes enum { diff --git a/rpcs3/Emu/SysCalls/Modules/libmixer.cpp b/rpcs3/Emu/SysCalls/Modules/libmixer.cpp index 21646f4d1c..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; } @@ -358,7 +356,7 @@ int cellSurMixerCreate(vm::ptr config) memset(mixdata, 0, sizeof(mixdata)); if (surMixerCb) { - surMixerCb.call(cb_thread, surMixerCbArg, (u32)mixcount, 256); + surMixerCb(cb_thread, surMixerCbArg, (u32)mixcount, 256); } //u64 stamp1 = get_system_time(); 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/Modules/sysPrxForUser.cpp b/rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp index 767c3c04da..1629d3fb05 100644 --- a/rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp +++ b/rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp @@ -295,7 +295,7 @@ s32 _sys_spu_printf_attach_group(PPUThread& CPU, u32 group) return CELL_ESTAT; } - return spu_printf_agcb.call(CPU, group); + return spu_printf_agcb(CPU, group); } s32 _sys_spu_printf_detach_group(PPUThread& CPU, u32 group) @@ -307,7 +307,7 @@ s32 _sys_spu_printf_detach_group(PPUThread& CPU, u32 group) return CELL_ESTAT; } - return spu_printf_dgcb.call(CPU, group); + return spu_printf_dgcb(CPU, group); } s32 _sys_spu_printf_attach_thread(PPUThread& CPU, u32 thread) @@ -319,7 +319,7 @@ s32 _sys_spu_printf_attach_thread(PPUThread& CPU, u32 thread) return CELL_ESTAT; } - return spu_printf_atcb.call(CPU, thread); + return spu_printf_atcb(CPU, thread); } s32 _sys_spu_printf_detach_thread(PPUThread& CPU, u32 thread) @@ -331,7 +331,7 @@ s32 _sys_spu_printf_detach_thread(PPUThread& CPU, u32 thread) return CELL_ESTAT; } - return spu_printf_dtcb.call(CPU, thread); + return spu_printf_dtcb(CPU, thread); } s32 _sys_snprintf(vm::ptr dst, u32 count, vm::ptr fmt) // va_args... diff --git a/rpcs3/Emu/SysCalls/lv2/cellFs.cpp b/rpcs3/Emu/SysCalls/lv2/cellFs.cpp index ec5e07daed..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; } @@ -919,7 +919,6 @@ void fsAioRead(u32 fd, vm::ptr aio, int xid, vm::ptroffset); - // TODO: use code from cellFsRead or something if (nbytes != (u32)nbytes) { error = CELL_ENOMEM; @@ -932,14 +931,14 @@ 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) // start callback thread + if (func) { - Emu.GetCallbackManager().Async([func, aio, error, xid, res]() + Emu.GetCallbackManager().Async([func, aio, error, xid, res](PPUThread& CPU) { - func(aio, error, xid, res); + func(CPU, aio, error, xid, res); }); } 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_ppu_thread.cpp b/rpcs3/Emu/SysCalls/lv2/sys_ppu_thread.cpp index bb1b49eead..4f2d19d532 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_ppu_thread.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_ppu_thread.cpp @@ -217,7 +217,7 @@ void sys_ppu_thread_once(PPUThread& CPU, vm::ptr> once_ctrl, vm::p be_t cmp = be_t::make(SYS_PPU_THREAD_ONCE_INIT); if (once_ctrl->compare_and_swap(cmp, be_t::make(SYS_PPU_THREAD_DONE_INIT)) == cmp) { - init.call(CPU); + init(CPU); } } 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/Emu/System.cpp b/rpcs3/Emu/System.cpp index 9e9da63152..ee84464bd8 100644 --- a/rpcs3/Emu/System.cpp +++ b/rpcs3/Emu/System.cpp @@ -11,6 +11,7 @@ #include "Emu/Cell/SPUThread.h" #include "Emu/Cell/PPUInstrTable.h" #include "Emu/FS/vfsFile.h" +#include "Emu/FS/vfsLocalFile.h" #include "Emu/FS/vfsDeviceLocalFile.h" #include "Emu/DbgCommand.h" @@ -261,7 +262,7 @@ void Emulator::Load() if (!m_loader.load(f)) { - LOG_ERROR(LOADER, "Loading '%s' failed", m_elf_path.c_str()); + LOG_ERROR(LOADER, "Loading '%s' failed", m_path.c_str()); vm::close(); return; } 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.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"