diff --git a/Utilities/BEType.h b/Utilities/BEType.h index 38d01a9952..d478e04d92 100644 --- a/Utilities/BEType.h +++ b/Utilities/BEType.h @@ -556,52 +556,49 @@ template struct const_se_t ((_value << 56) & 0xff00000000000000); }; -template -struct be_storage_t +template struct be_storage { - static_assert(!size, "Bad be_storage_t type"); + static_assert(!size, "Bad be_storage_t<> type"); }; +template struct be_storage +{ + using type = u16; +}; + +template struct be_storage +{ + using type = u32; +}; + +template struct be_storage +{ + using type = u64; +}; + +template struct be_storage +{ + using type = u128; +}; + +template using be_storage_t = typename be_storage::type; + template -struct be_storage_t +struct be_t { - typedef u8 type; -}; + using type = std::remove_cv_t; + using stype = be_storage_t>; -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; -}; - -template -class be_t -{ -public: - typedef typename std::remove_cv::type type; - typedef typename be_storage_t::type stype; - -private: stype m_data; + static_assert(!std::is_class::value, "be_t<> error: invalid type (class or structure)"); + static_assert(!std::is_union::value || std::is_same::value, "be_t<> error: invalid type (union)"); + static_assert(!std::is_pointer::value, "be_t<> error: invalid type (pointer)"); + static_assert(!std::is_reference::value, "be_t<> error: invalid type (reference)"); + static_assert(!std::is_array::value, "be_t<> error: invalid type (array)"); + static_assert(__alignof(type) == __alignof(stype), "be_t<> error: unexpected alignment"); + +private: template struct _convert { @@ -639,7 +636,7 @@ private: type ToLE() const { - return se_t::from_be(m_data); + return se_t::from_be(m_data); } void FromBE(const stype& value) @@ -649,13 +646,12 @@ private: void FromLE(const type& value) { - m_data = se_t::to_be(value); + m_data = se_t::to_be(value); } -public: static be_t MakeFromLE(const type& value) { - stype data = se_t::to_be(value); + stype data = se_t::to_be(value); return (be_t&)data; } @@ -664,6 +660,7 @@ public: return (be_t&)value; } +public: //make be_t from current machine byte ordering static be_t make(const type& value) { @@ -689,37 +686,44 @@ public: return ToBE(); } - be_t& operator = (const be_t& value) = default; + be_t& operator =(const be_t& value) = default; - be_t& operator = (const type& value) + template std::enable_if_t::value, be_t&> operator =(const CT& value) { - m_data = se_t::to_be(value); + m_data = se_t::to_be(value); return *this; } + //template::value>> operator CT() const + //{ + // return value(); + //} + operator type() const { return value(); } - template - operator const be_t() const + // conversion to another be_t type + template operator be_t() const { return be_t::make(value()); + + // TODO (complicated cases like int-float conversions are not handled correctly) //return _convert sizeof(T)) ? 1 : (sizeof(T1) < sizeof(T) ? 2 : 0))>::func(m_data); } - template be_t& operator += (T1 right) { return *this = T(*this) + right; } - template be_t& operator -= (T1 right) { return *this = T(*this) - right; } - template be_t& operator *= (T1 right) { return *this = T(*this) * right; } - template be_t& operator /= (T1 right) { return *this = T(*this) / right; } - template be_t& operator %= (T1 right) { return *this = T(*this) % right; } - template be_t& operator &= (T1 right) { return *this = T(*this) & right; } - template be_t& operator |= (T1 right) { return *this = T(*this) | right; } - template be_t& operator ^= (T1 right) { return *this = T(*this) ^ right; } - template be_t& operator <<= (T1 right) { return *this = T(*this) << right; } - template be_t& operator >>= (T1 right) { return *this = T(*this) >> right; } + template be_t& operator += (T1 right) { return *this = value() + right; } + template be_t& operator -= (T1 right) { return *this = value() - right; } + template be_t& operator *= (T1 right) { return *this = value() * right; } + template be_t& operator /= (T1 right) { return *this = value() / right; } + template be_t& operator %= (T1 right) { return *this = value() % right; } + template be_t& operator &= (T1 right) { return *this = value() & right; } + template be_t& operator |= (T1 right) { return *this = value() | right; } + template be_t& operator ^= (T1 right) { return *this = value() ^ right; } + template be_t& operator <<= (T1 right) { return *this = value() << right; } + template be_t& operator >>= (T1 right) { return *this = value() >> right; } template be_t& operator += (const be_t& right) { return *this = ToLE() + right.ToLE(); } template be_t& operator -= (const be_t& right) { return *this = ToLE() - right.ToLE(); } @@ -730,9 +734,9 @@ public: template be_t& operator |= (const be_t& right) { return *this = ToBE() | right.ToBE(); } template be_t& operator ^= (const be_t& right) { return *this = ToBE() ^ right.ToBE(); } - template be_t operator & (const be_t& right) const { be_t res; res.FromBE(ToBE() & right.ToBE()); return res; } - template be_t operator | (const be_t& right) const { be_t res; res.FromBE(ToBE() | right.ToBE()); return res; } - template be_t operator ^ (const be_t& right) const { be_t res; res.FromBE(ToBE() ^ right.ToBE()); return res; } + template be_t operator & (const be_t& right) const { be_t res; res.FromBE(ToBE() & right.ToBE()); return res; } + template be_t operator | (const be_t& right) const { be_t res; res.FromBE(ToBE() | right.ToBE()); return res; } + template be_t operator ^ (const be_t& right) const { be_t res; res.FromBE(ToBE() ^ right.ToBE()); return res; } template bool operator == (T1 right) const { return (T1)ToLE() == right; } template bool operator != (T1 right) const { return !(*this == right); } @@ -754,114 +758,48 @@ public: be_t& operator-- () { *this -= 1; return *this; } }; -template -struct is_be_t : public std::integral_constant {}; - -template -struct is_be_t, T2> : public std::integral_constant {}; - -template -struct remove_be_t +template struct is_be_t : public std::integral_constant { - typedef T type; }; -template -struct remove_be_t> +template struct is_be_t> : public std::integral_constant { - typedef T type; }; -template -class to_be_t +template struct is_be_t : public std::integral_constant::value> { - template - struct _be_type_selector - { - typedef TT type; - }; - - template - struct _be_type_selector - { - typedef be_t type; - }; - -public: - //true if need swap endianes for be - static const bool value = std::is_arithmetic::value || std::is_enum::value; - - //be_t if need swap endianes, T otherwise - typedef typename _be_type_selector< T, T2, value >::type type; - - typedef typename _be_type_selector< T, T2, !is_be_t::value >::type forced_type; }; -template -class to_be_t +template struct is_be_t : public std::integral_constant::value> { -public: - static const bool value = to_be_t::value; - typedef const typename to_be_t::type type; - typedef const typename to_be_t::forced_type forced_type; }; -template -class to_be_t +// to_be_t helper struct +template struct to_be { -public: - static const bool value = false; - typedef void type; - typedef void forced_type; + using type = std::conditional_t::value || std::is_enum::value || std::is_same::value, be_t, T>; }; -template -class to_be_t +// be_t if possible, T otherwise +template using to_be_t = typename to_be::type; + +template struct to_be { -public: - static const bool value = false; - typedef u8 type; - typedef u8 forced_type; + // move const qualifier + using type = const to_be_t; }; -template -class to_be_t +template struct to_be { -public: - static const bool value = false; - typedef s8 type; - typedef s8 forced_type; + // move volatile qualifier + using type = volatile to_be_t; }; -template -class to_be_t -{ -public: - static const bool value = false; - typedef char type; - typedef char forced_type; -}; - -template -class to_be_t -{ -public: - static const bool value = false; - typedef bool type; - typedef bool forced_type; -}; - -template -struct invert_be_t -{ - typedef typename to_be_t::type type; -}; - -template -struct invert_be_t> -{ - typedef T type; -}; +template<> struct to_be { using type = void; }; +template<> struct to_be { using type = bool; }; +template<> struct to_be { using type = char; }; +template<> struct to_be { using type = u8; }; +template<> struct to_be { using type = s8; }; template struct _se : public const_se_t {}; template struct _se, T1, value> : public const_se_t {}; @@ -880,28 +818,28 @@ struct convert_le_be_t } }; -template -struct convert_le_be_t, Tfrom> +template +struct convert_le_be_t, Tfrom> { - static be_t func(Tfrom value) + static be_t func(Tfrom value) { - return be_t::make(value); + return be_t::make(value); } }; -template -struct convert_le_be_t, be_t> +template +struct convert_le_be_t, be_t> { - static be_t func(be_t value) + static be_t func(be_t value) { return value; } }; -template -struct convert_le_be_t> +template +struct convert_le_be_t> { - static Tto func(be_t value) + static Tto func(be_t value) { return value.value(); } @@ -919,6 +857,113 @@ force_inline void convert_le_be(Tto& dst, Tfrom src) dst = convert_le_be_t::func(src); } -template using le_t = T; +template struct le_t +{ + using type = std::remove_cv_t; + using stype = be_storage_t>; -template struct to_le_t { using type = T; }; + stype m_data; + + type value() const + { + return reinterpret_cast(m_data); + } + + le_t& operator =(const le_t& value) = default; + + template std::enable_if_t::value, le_t&> operator =(const CT& value) + { + m_data = reinterpret_cast(value); + + return *this; + } + + //template operator std::enable_if_t::value, CT>() const + //{ + // return value(); + //} + + operator type() const + { + return value(); + } + + // conversion to another le_t type + //template operator const le_t() const + //{ + // return le_t::make(value()); + //} +}; + +template struct is_le_t : public std::integral_constant +{ +}; + +template struct is_le_t> : public std::integral_constant +{ +}; + +template struct is_le_t : public std::integral_constant::value> +{ +}; + +template struct is_le_t : public std::integral_constant::value> +{ +}; + +template struct to_le +{ + using type = std::conditional_t::value || std::is_enum::value || std::is_same::value, le_t, T>; +}; + +// le_t if possible, T otherwise +template using to_le_t = typename to_le::type; + +template struct to_le +{ + // move const qualifier + using type = const to_le_t; +}; + +template struct to_le +{ + // move volatile qualifier + using type = volatile to_le_t; +}; + +template<> struct to_le { using type = void; }; +template<> struct to_le { using type = bool; }; +template<> struct to_le { using type = char; }; +template<> struct to_le { using type = u8; }; +template<> struct to_le { using type = s8; }; + +// to_ne_t helper struct +template struct to_ne +{ + using type = T; +}; + +template struct to_ne> +{ + using type = T; +}; + +template struct to_ne> +{ + using type = T; +}; + +// restore native endianness for T: returns T for be_t or le_t, T otherwise +template using to_ne_t = typename to_ne::type; + +template struct to_ne +{ + // move const qualifier + using type = const to_ne_t; +}; + +template struct to_ne +{ + // move volatile qualifier + using type = volatile to_ne_t; +}; diff --git a/Utilities/GNU.h b/Utilities/GNU.h index d592131297..64a45acb63 100644 --- a/Utilities/GNU.h +++ b/Utilities/GNU.h @@ -82,42 +82,42 @@ int clock_gettime(int foo, struct timespec *ts); #endif /* __APPLE__ */ -template static inline typename std::enable_if::value, T>::type sync_val_compare_and_swap(volatile T* dest, T2 comp, T2 exch) +template static inline std::enable_if_t::value, T> sync_val_compare_and_swap(volatile T* dest, T2 comp, T2 exch) { return __sync_val_compare_and_swap(dest, comp, exch); } -template static inline typename std::enable_if::value, bool>::type sync_bool_compare_and_swap(volatile T* dest, T2 comp, T2 exch) +template static inline std::enable_if_t::value, bool> sync_bool_compare_and_swap(volatile T* dest, T2 comp, T2 exch) { return __sync_bool_compare_and_swap(dest, comp, exch); } -template static inline typename std::enable_if::value, T>::type sync_lock_test_and_set(volatile T* dest, T2 value) +template static inline std::enable_if_t::value, T> sync_lock_test_and_set(volatile T* dest, T2 value) { return __sync_lock_test_and_set(dest, value); } -template static inline typename std::enable_if::value, T>::type sync_fetch_and_add(volatile T* dest, T2 value) +template static inline std::enable_if_t::value, T> sync_fetch_and_add(volatile T* dest, T2 value) { return __sync_fetch_and_add(dest, value); } -template static inline typename std::enable_if::value, T>::type sync_fetch_and_sub(volatile T* dest, T2 value) +template static inline std::enable_if_t::value, T> sync_fetch_and_sub(volatile T* dest, T2 value) { return __sync_fetch_and_sub(dest, value); } -template static inline typename std::enable_if::value, T>::type sync_fetch_and_or(volatile T* dest, T2 value) +template static inline std::enable_if_t::value, T> sync_fetch_and_or(volatile T* dest, T2 value) { return __sync_fetch_and_or(dest, value); } -template static inline typename std::enable_if::value, T>::type sync_fetch_and_and(volatile T* dest, T2 value) +template static inline std::enable_if_t::value, T> sync_fetch_and_and(volatile T* dest, T2 value) { return __sync_fetch_and_and(dest, value); } -template static inline typename std::enable_if::value, T>::type sync_fetch_and_xor(volatile T* dest, T2 value) +template static inline std::enable_if_t::value, T> sync_fetch_and_xor(volatile T* dest, T2 value) { return __sync_fetch_and_xor(dest, value); } diff --git a/Utilities/StrFmt.h b/Utilities/StrFmt.h index 406446502c..4011878360 100644 --- a/Utilities/StrFmt.h +++ b/Utilities/StrFmt.h @@ -179,7 +179,7 @@ namespace fmt template::value> struct unveil { - typedef T result_type; + using result_type = T; force_inline static result_type get_value(const T& arg) { @@ -190,7 +190,7 @@ namespace fmt template<> struct unveil { - typedef const char* result_type; + using result_type = const char*; force_inline static result_type get_value(const char* arg) { @@ -201,7 +201,7 @@ namespace fmt template struct unveil { - typedef const char* result_type; + using result_type = const char*; force_inline static result_type get_value(const char(&arg)[N]) { @@ -212,7 +212,7 @@ namespace fmt template<> struct unveil { - typedef const char* result_type; + using result_type = const char*; force_inline static result_type get_value(const std::string& arg) { @@ -223,7 +223,7 @@ namespace fmt template struct unveil { - typedef typename std::underlying_type::type result_type; + using result_type = std::underlying_type_t; force_inline static result_type get_value(const T& arg) { @@ -231,12 +231,12 @@ namespace fmt } }; - template - struct unveil, false> + template + struct unveil, false> { - typedef typename unveil::result_type result_type; + using result_type = typename unveil::result_type; - force_inline static result_type get_value(const be_t& arg) + force_inline static result_type get_value(const be_t& arg) { return unveil::get_value(arg.value()); } diff --git a/rpcs3/CMakeLists.txt b/rpcs3/CMakeLists.txt index 4681657712..6ca487be90 100644 --- a/rpcs3/CMakeLists.txt +++ b/rpcs3/CMakeLists.txt @@ -25,7 +25,7 @@ endif() if (NOT MSVC) add_definitions(-DwxGUI) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fexceptions") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -fexceptions") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -D_DEBUG") set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -Os -D_NDEBUG") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O1 -D_NDEBUG") diff --git a/rpcs3/Emu/ARMv7/ARMv7Callback.h b/rpcs3/Emu/ARMv7/ARMv7Callback.h index 0777ed4f20..b8d7daa452 100644 --- a/rpcs3/Emu/ARMv7/ARMv7Callback.h +++ b/rpcs3/Emu/ARMv7/ARMv7Callback.h @@ -5,7 +5,7 @@ namespace vm { template - force_inline RT _ptr_base::operator()(ARMv7Context& context, T... args) const + force_inline RT _ptr_base::operator()(ARMv7Context& context, T... args) const { return psv_func_detail::func_caller::call(context, vm::cast(this->addr()), args...); } diff --git a/rpcs3/Emu/ARMv7/ARMv7Context.h b/rpcs3/Emu/ARMv7/ARMv7Context.h index dc14117845..876e55fb36 100644 --- a/rpcs3/Emu/ARMv7/ARMv7Context.h +++ b/rpcs3/Emu/ARMv7/ARMv7Context.h @@ -187,16 +187,14 @@ struct cast_armv7_gpr { static_assert(is_enum, "Invalid type for cast_armv7_gpr"); - typedef typename std::underlying_type::type underlying_type; - force_inline static u32 to_gpr(const T& value) { - return cast_armv7_gpr::to_gpr(static_cast(value)); + return cast_armv7_gpr>::to_gpr(static_cast>(value)); } force_inline static T from_gpr(const u32 reg) { - return static_cast(cast_armv7_gpr::from_gpr(reg)); + return static_cast(cast_armv7_gpr>::from_gpr(reg)); } }; diff --git a/rpcs3/Emu/ARMv7/Modules/sceDeflt.cpp b/rpcs3/Emu/ARMv7/Modules/sceDeflt.cpp index 8e31b95c72..f1ce171d65 100644 --- a/rpcs3/Emu/ARMv7/Modules/sceDeflt.cpp +++ b/rpcs3/Emu/ARMv7/Modules/sceDeflt.cpp @@ -9,7 +9,7 @@ s32 sceGzipIsValid(vm::psv::ptr pSrcGzip) throw __FUNCTION__; } -s32 sceGzipGetInfo(vm::psv::ptr pSrcGzip, vm::psv::ptr> ppvExtra, vm::psv::ptr> ppszName, vm::psv::ptr> ppszComment, vm::psv::ptr pusCrc, vm::psv::ptr> ppvData) +s32 sceGzipGetInfo(vm::psv::ptr pSrcGzip, vm::psv::pptr ppvExtra, vm::psv::pptr ppszName, vm::psv::pptr ppszComment, vm::psv::ptr pusCrc, vm::psv::pptr ppvData) { throw __FUNCTION__; } @@ -39,7 +39,7 @@ s32 sceZlibIsValid(vm::psv::ptr pSrcZlib) throw __FUNCTION__; } -s32 sceZlibGetInfo(vm::psv::ptr pSrcZlib, vm::psv::ptr pbCmf, vm::psv::ptr pbFlg, vm::psv::ptr puiDictId, vm::psv::ptr> ppvData) +s32 sceZlibGetInfo(vm::psv::ptr pSrcZlib, vm::psv::ptr pbCmf, vm::psv::ptr pbFlg, vm::psv::ptr puiDictId, vm::psv::pptr ppvData) { throw __FUNCTION__; } @@ -59,12 +59,12 @@ u32 sceZlibAdler32(u32 uiAdler, vm::psv::ptr pSrc, u32 uiSize) throw __FUNCTION__; } -s32 sceDeflateDecompress(vm::psv::ptr pDst, u32 uiBufSize, vm::psv::ptr pSrcDeflate, vm::psv::ptr> ppNext) +s32 sceDeflateDecompress(vm::psv::ptr pDst, u32 uiBufSize, vm::psv::ptr pSrcDeflate, vm::psv::pptr ppNext) { throw __FUNCTION__; } -s32 sceZipGetInfo(vm::psv::ptr pSrc, vm::psv::ptr> ppvExtra, vm::psv::ptr puiCrc, vm::psv::ptr> ppvData) +s32 sceZipGetInfo(vm::psv::ptr pSrc, vm::psv::pptr ppvExtra, vm::psv::ptr puiCrc, vm::psv::pptr ppvData) { throw __FUNCTION__; } diff --git a/rpcs3/Emu/ARMv7/Modules/sceFiber.cpp b/rpcs3/Emu/ARMv7/Modules/sceFiber.cpp index ab35f7a9be..cd2155cd1d 100644 --- a/rpcs3/Emu/ARMv7/Modules/sceFiber.cpp +++ b/rpcs3/Emu/ARMv7/Modules/sceFiber.cpp @@ -65,7 +65,7 @@ s32 sceFiberSwitch(vm::psv::ptr fiber, u32 argOnRunTo, vm::psv::ptr> fiber) +s32 sceFiberGetSelf(vm::psv::pptr fiber) { throw __FUNCTION__; } diff --git a/rpcs3/Emu/ARMv7/Modules/sceFios.cpp b/rpcs3/Emu/ARMv7/Modules/sceFios.cpp index 71dab26ea1..49831265e5 100644 --- a/rpcs3/Emu/ARMv7/Modules/sceFios.cpp +++ b/rpcs3/Emu/ARMv7/Modules/sceFios.cpp @@ -787,7 +787,7 @@ s32 sceFiosIOFilterAdd(s32 index, SceFiosIOFilterCallback pFilterCallback, vm::p throw __FUNCTION__; } -s32 sceFiosIOFilterGetInfo(s32 index, vm::psv::ptr pOutFilterCallback, vm::psv::ptr> pOutFilterContext) +s32 sceFiosIOFilterGetInfo(s32 index, vm::psv::ptr pOutFilterCallback, vm::psv::pptr pOutFilterContext) { throw __FUNCTION__; } diff --git a/rpcs3/Emu/ARMv7/Modules/sceGxm.cpp b/rpcs3/Emu/ARMv7/Modules/sceGxm.cpp index f65f49b349..2ef54331e5 100644 --- a/rpcs3/Emu/ARMv7/Modules/sceGxm.cpp +++ b/rpcs3/Emu/ARMv7/Modules/sceGxm.cpp @@ -64,7 +64,7 @@ s32 sceGxmDisplayQueueFinish() throw __FUNCTION__; } -s32 sceGxmSyncObjectCreate(vm::psv::ptr> syncObject) +s32 sceGxmSyncObjectCreate(vm::psv::pptr syncObject) { throw __FUNCTION__; } @@ -75,7 +75,7 @@ s32 sceGxmSyncObjectDestroy(vm::psv::ptr syncObject) } -s32 sceGxmCreateContext(vm::psv::ptr params, vm::psv::ptr> context) +s32 sceGxmCreateContext(vm::psv::ptr params, vm::psv::pptr context) { throw __FUNCTION__; } @@ -101,12 +101,12 @@ void sceGxmSetFragmentProgram(vm::psv::ptr context, vm::psv::ptr< throw __FUNCTION__; } -s32 sceGxmReserveVertexDefaultUniformBuffer(vm::psv::ptr context, vm::psv::ptr> uniformBuffer) +s32 sceGxmReserveVertexDefaultUniformBuffer(vm::psv::ptr context, vm::psv::pptr uniformBuffer) { throw __FUNCTION__; } -s32 sceGxmReserveFragmentDefaultUniformBuffer(vm::psv::ptr context, vm::psv::ptr> uniformBuffer) +s32 sceGxmReserveFragmentDefaultUniformBuffer(vm::psv::ptr context, vm::psv::pptr uniformBuffer) { throw __FUNCTION__; } @@ -650,7 +650,7 @@ vm::psv::ptr sceGxmVertexProgramGetProgram(vm::psv::ptr params, vm::psv::ptr> shaderPatcher) +s32 sceGxmShaderPatcherCreate(vm::psv::ptr params, vm::psv::pptr shaderPatcher) { throw __FUNCTION__; } @@ -690,12 +690,12 @@ s32 sceGxmShaderPatcherSetAuxiliarySurface(vm::psv::ptr sha throw __FUNCTION__; } -s32 sceGxmShaderPatcherCreateVertexProgram(vm::psv::ptr shaderPatcher, SceGxmShaderPatcherId programId, vm::psv::ptr attributes, u32 attributeCount, vm::psv::ptr streams, u32 streamCount, vm::psv::ptr> vertexProgram) +s32 sceGxmShaderPatcherCreateVertexProgram(vm::psv::ptr shaderPatcher, SceGxmShaderPatcherId programId, vm::psv::ptr attributes, u32 attributeCount, vm::psv::ptr streams, u32 streamCount, vm::psv::pptr vertexProgram) { throw __FUNCTION__; } -s32 sceGxmShaderPatcherCreateFragmentProgram(vm::psv::ptr shaderPatcher, SceGxmShaderPatcherId programId, SceGxmOutputRegisterFormat outputFormat, SceGxmMultisampleMode multisampleMode, vm::psv::ptr blendInfo, vm::psv::ptr vertexProgram, vm::psv::ptr> fragmentProgram) +s32 sceGxmShaderPatcherCreateFragmentProgram(vm::psv::ptr shaderPatcher, SceGxmShaderPatcherId programId, SceGxmOutputRegisterFormat outputFormat, SceGxmMultisampleMode multisampleMode, vm::psv::ptr blendInfo, vm::psv::ptr vertexProgram, vm::psv::pptr fragmentProgram) { throw __FUNCTION__; } @@ -1041,12 +1041,12 @@ s32 sceGxmGetRenderTargetMemSizes(vm::psv::ptr p throw __FUNCTION__; } -s32 sceGxmCreateRenderTarget(vm::psv::ptr params, vm::psv::ptr> renderTarget) +s32 sceGxmCreateRenderTarget(vm::psv::ptr params, vm::psv::pptr renderTarget) { throw __FUNCTION__; } -s32 sceGxmRenderTargetGetHostMem(vm::psv::ptr renderTarget, vm::psv::ptr> hostMem) +s32 sceGxmRenderTargetGetHostMem(vm::psv::ptr renderTarget, vm::psv::pptr hostMem) { throw __FUNCTION__; } diff --git a/rpcs3/Emu/ARMv7/Modules/sceHttp.cpp b/rpcs3/Emu/ARMv7/Modules/sceHttp.cpp index c98509fac4..c261e0335d 100644 --- a/rpcs3/Emu/ARMv7/Modules/sceHttp.cpp +++ b/rpcs3/Emu/ARMv7/Modules/sceHttp.cpp @@ -33,7 +33,7 @@ enum SceHttpAuthType : s32 SCE_HTTP_AUTH_RESERVED2 }; -typedef vm::psv::ptr realm, vm::psv::ptr username, vm::psv::ptr password, s32 needEntity, vm::psv::ptr> entityBody, vm::psv::ptr entitySize, vm::psv::ptr save, vm::psv::ptr userArg)> SceHttpAuthInfoCallback; +typedef vm::psv::ptr realm, vm::psv::ptr username, vm::psv::ptr password, s32 needEntity, vm::psv::pptr entityBody, vm::psv::ptr entitySize, vm::psv::ptr save, vm::psv::ptr userArg)> SceHttpAuthInfoCallback; typedef vm::psv::ptr method, vm::psv::ptr location, vm::psv::ptr userArg)> SceHttpRedirectCallback; @@ -71,7 +71,7 @@ struct SceHttpsData struct SceHttpsCaList { - vm::psv::ptr> caCerts; + vm::psv::lpptr caCerts; s32 caNum; }; @@ -167,7 +167,7 @@ s32 sceHttpGetStatusCode(s32 reqId, vm::psv::ptr statusCode) throw __FUNCTION__; } -s32 sceHttpGetAllResponseHeaders(s32 reqId, vm::psv::ptr> header, vm::psv::ptr headerSize) +s32 sceHttpGetAllResponseHeaders(s32 reqId, vm::psv::pptr header, vm::psv::ptr headerSize) { throw __FUNCTION__; } @@ -187,12 +187,12 @@ s32 sceHttpRemoveRequestHeader(s32 id, vm::psv::ptr name) throw __FUNCTION__; } -s32 sceHttpParseResponseHeader(vm::psv::ptr header, u32 headerLen, vm::psv::ptr fieldStr, vm::psv::ptr> fieldValue, vm::psv::ptr valueLen) +s32 sceHttpParseResponseHeader(vm::psv::ptr header, u32 headerLen, vm::psv::ptr fieldStr, vm::psv::pptr fieldValue, vm::psv::ptr valueLen) { throw __FUNCTION__; } -s32 sceHttpParseStatusLine(vm::psv::ptr statusLine, u32 lineLen, vm::psv::ptr httpMajorVer, vm::psv::ptr httpMinorVer, vm::psv::ptr responseCode, vm::psv::ptr> reasonPhrase, vm::psv::ptr phraseLen) +s32 sceHttpParseStatusLine(vm::psv::ptr statusLine, u32 lineLen, vm::psv::ptr httpMajorVer, vm::psv::ptr httpMinorVer, vm::psv::ptr responseCode, vm::psv::pptr reasonPhrase, vm::psv::ptr phraseLen) { throw __FUNCTION__; } @@ -312,7 +312,7 @@ s32 sceHttpSetCookieSendCallback(s32 id, SceHttpCookieSendCallback cbfunc, vm::p throw __FUNCTION__; } -s32 sceHttpsLoadCert(s32 caCertNum, vm::psv::ptr> caList, vm::psv::ptr cert, vm::psv::ptr privKey) +s32 sceHttpsLoadCert(s32 caCertNum, vm::psv::pptr caList, vm::psv::ptr cert, vm::psv::ptr privKey) { throw __FUNCTION__; } diff --git a/rpcs3/Emu/ARMv7/Modules/sceLibKernel.cpp b/rpcs3/Emu/ARMv7/Modules/sceLibKernel.cpp index 89a8c073ca..0d1c9baf29 100644 --- a/rpcs3/Emu/ARMv7/Modules/sceLibKernel.cpp +++ b/rpcs3/Emu/ARMv7/Modules/sceLibKernel.cpp @@ -25,7 +25,7 @@ s32 sceKernelFreeMemBlock(s32 uid) throw __FUNCTION__; } -s32 sceKernelGetMemBlockBase(s32 uid, vm::psv::ptr> ppBase) +s32 sceKernelGetMemBlockBase(s32 uid, vm::psv::pptr ppBase) { throw __FUNCTION__; } diff --git a/rpcs3/Emu/ARMv7/Modules/scePerf.cpp b/rpcs3/Emu/ARMv7/Modules/scePerf.cpp index a9ff8e8308..38516caafe 100644 --- a/rpcs3/Emu/ARMv7/Modules/scePerf.cpp +++ b/rpcs3/Emu/ARMv7/Modules/scePerf.cpp @@ -245,7 +245,7 @@ u32 scePerfGetTimebaseFrequency() return 1; } -s32 _sceRazorCpuInit(vm::psv::ptr pBufferBase, u32 bufferSize, u32 numPerfCounters, vm::psv::ptr> psceRazorVars) +s32 _sceRazorCpuInit(vm::psv::ptr pBufferBase, u32 bufferSize, u32 numPerfCounters, vm::psv::pptr psceRazorVars) { throw __FUNCTION__; } diff --git a/rpcs3/Emu/ARMv7/Modules/sceSas.cpp b/rpcs3/Emu/ARMv7/Modules/sceSas.cpp index 3d11ff98f1..b0961f2776 100644 --- a/rpcs3/Emu/ARMv7/Modules/sceSas.cpp +++ b/rpcs3/Emu/ARMv7/Modules/sceSas.cpp @@ -19,7 +19,7 @@ s32 sceSasInitWithGrain(vm::psv::ptr config, u32 grain, vm::psv::ptr throw __FUNCTION__; } -s32 sceSasExit(vm::psv::ptr> outBuffer, vm::psv::ptr outBufferSize) +s32 sceSasExit(vm::psv::pptr outBuffer, vm::psv::ptr outBufferSize) { throw __FUNCTION__; } diff --git a/rpcs3/Emu/ARMv7/Modules/sceSsl.cpp b/rpcs3/Emu/ARMv7/Modules/sceSsl.cpp index 02a377996a..bd32cda9dd 100644 --- a/rpcs3/Emu/ARMv7/Modules/sceSsl.cpp +++ b/rpcs3/Emu/ARMv7/Modules/sceSsl.cpp @@ -19,7 +19,7 @@ s32 sceSslGetMemoryPoolStats(vm::psv::ptr currentStat) throw __FUNCTION__; } -s32 sceSslGetSerialNumber(vm::psv::ptr sslCert, vm::psv::ptr> sboData, vm::psv::ptr sboLen) +s32 sceSslGetSerialNumber(vm::psv::ptr sslCert, vm::psv::pptr sboData, vm::psv::ptr sboLen) { throw __FUNCTION__; } diff --git a/rpcs3/Emu/ARMv7/Modules/sceUlt.cpp b/rpcs3/Emu/ARMv7/Modules/sceUlt.cpp index 68216d7ddc..5777638f92 100644 --- a/rpcs3/Emu/ARMv7/Modules/sceUlt.cpp +++ b/rpcs3/Emu/ARMv7/Modules/sceUlt.cpp @@ -536,7 +536,7 @@ s32 sceUltUlthreadTryJoin(vm::psv::ptr ulthread, vm::psv::ptr> ulthread) +s32 sceUltUlthreadGetSelf(vm::psv::pptr ulthread) { throw __FUNCTION__; } diff --git a/rpcs3/Emu/ARMv7/Modules/sceVideodec.cpp b/rpcs3/Emu/ARMv7/Modules/sceVideodec.cpp index bec390ebe1..7899777f97 100644 --- a/rpcs3/Emu/ARMv7/Modules/sceVideodec.cpp +++ b/rpcs3/Emu/ARMv7/Modules/sceVideodec.cpp @@ -126,7 +126,7 @@ struct SceAvcdecArrayPicture { u32 numOfOutput; u32 numOfElm; - vm::psv::ptr> pPicture; + vm::psv::lpptr pPicture; }; diff --git a/rpcs3/Emu/ARMv7/PSVFuncList.h b/rpcs3/Emu/ARMv7/PSVFuncList.h index fb7215a61a..9bd061b512 100644 --- a/rpcs3/Emu/ARMv7/PSVFuncList.h +++ b/rpcs3/Emu/ARMv7/PSVFuncList.h @@ -307,7 +307,7 @@ namespace psv_func_detail template force_inline RT call(F f, Tuple && t) { - typedef typename std::decay::type ttype; + using ttype = std::decay_t; return psv_func_detail::call_impl::value, std::tuple_size::value>::call(f, std::forward(t)); } diff --git a/rpcs3/Emu/Cell/PPUThread.h b/rpcs3/Emu/Cell/PPUThread.h index 31d44fad14..4a5ced3483 100644 --- a/rpcs3/Emu/Cell/PPUThread.h +++ b/rpcs3/Emu/Cell/PPUThread.h @@ -845,16 +845,14 @@ struct cast_ppu_gpr { static_assert(is_enum, "Invalid type for cast_ppu_gpr"); - typedef typename std::underlying_type::type underlying_type; - force_inline static u64 to_gpr(const T& value) { - return cast_ppu_gpr::to_gpr(static_cast(value)); + return cast_ppu_gpr>::to_gpr(static_cast>(value)); } force_inline static T from_gpr(const u64 reg) { - return static_cast(cast_ppu_gpr::from_gpr(reg)); + return static_cast(cast_ppu_gpr>::from_gpr(reg)); } }; diff --git a/rpcs3/Emu/Memory/atomic.h b/rpcs3/Emu/Memory/atomic.h index b09cf04359..6eea856d7c 100644 --- a/rpcs3/Emu/Memory/atomic.h +++ b/rpcs3/Emu/Memory/atomic.h @@ -1,46 +1,41 @@ #pragma once -template -struct _to_atomic_subtype +template struct _to_atomic_subtype { static_assert(size == 1 || size == 2 || size == 4 || size == 8 || size == 16, "Invalid atomic type"); }; -template -struct _to_atomic_subtype +template struct _to_atomic_subtype { - using type = uint8_t; + using type = u8; }; -template -struct _to_atomic_subtype +template struct _to_atomic_subtype { - using type = uint16_t; + using type = u16; }; -template -struct _to_atomic_subtype +template struct _to_atomic_subtype { - using type = uint32_t; + using type = u32; }; -template -struct _to_atomic_subtype +template struct _to_atomic_subtype { - using type = uint64_t; + using type = u64; }; -template -struct _to_atomic_subtype +template struct _to_atomic_subtype { using type = u128; }; -template -union _atomic_base +template using atomic_subtype_t = typename _to_atomic_subtype::type; + +template union _atomic_base { - using type = typename std::remove_cv::type; - using subtype = typename _to_atomic_subtype::type; + using type = std::remove_cv_t; + using subtype = atomic_subtype_t; type data; // unsafe direct access subtype sub_data; // unsafe direct access to substitute type @@ -195,42 +190,40 @@ public: } }; -// Helper definitions +template using if_integral_le_t = std::enable_if_t::value && std::is_integral::value, le_t>; +template using if_integral_be_t = std::enable_if_t::value && std::is_integral::value, be_t>; -template using if_arithmetic_le_t = const typename std::enable_if::value && std::is_arithmetic::value, le_t>::type; -template using if_arithmetic_be_t = const typename std::enable_if::value && std::is_arithmetic::value, be_t>::type; - -template inline static if_arithmetic_le_t operator ++(_atomic_base>& left) +template inline if_integral_le_t operator ++(_atomic_base>& left) { return left.from_subtype(sync_fetch_and_add(&left.sub_data, 1) + 1); } -template inline static if_arithmetic_le_t operator --(_atomic_base>& left) +template inline if_integral_le_t operator --(_atomic_base>& left) { return left.from_subtype(sync_fetch_and_sub(&left.sub_data, 1) - 1); } -template inline static if_arithmetic_le_t operator ++(_atomic_base>& left, int) +template inline if_integral_le_t operator ++(_atomic_base>& left, int) { return left.from_subtype(sync_fetch_and_add(&left.sub_data, 1)); } -template inline static if_arithmetic_le_t operator --(_atomic_base>& left, int) +template inline if_integral_le_t operator --(_atomic_base>& left, int) { return left.from_subtype(sync_fetch_and_sub(&left.sub_data, 1)); } -template inline static if_arithmetic_le_t operator +=(_atomic_base>& left, T2 right) +template inline if_integral_le_t operator +=(_atomic_base>& left, T2 right) { return left.from_subtype(sync_fetch_and_add(&left.sub_data, right) + right); } -template inline static if_arithmetic_le_t operator -=(_atomic_base>& left, T2 right) +template inline if_integral_le_t operator -=(_atomic_base>& left, T2 right) { return left.from_subtype(sync_fetch_and_sub(&left.sub_data, right) - right); } -template inline static if_arithmetic_be_t operator ++(_atomic_base>& left) +template inline if_integral_be_t operator ++(_atomic_base>& left) { be_t result; @@ -242,7 +235,7 @@ template inline static if_arithmetic_be_t operator ++(_atomic_bas return result; } -template inline static if_arithmetic_be_t operator --(_atomic_base>& left) +template inline if_integral_be_t operator --(_atomic_base>& left) { be_t result; @@ -254,7 +247,7 @@ template inline static if_arithmetic_be_t operator --(_atomic_bas return result; } -template inline static if_arithmetic_be_t operator ++(_atomic_base>& left, int) +template inline if_integral_be_t operator ++(_atomic_base>& left, int) { be_t result; @@ -266,7 +259,7 @@ template inline static if_arithmetic_be_t operator ++(_atomic_bas return result; } -template inline static if_arithmetic_be_t operator --(_atomic_base>& left, int) +template inline if_integral_be_t operator --(_atomic_base>& left, int) { be_t result; @@ -278,7 +271,7 @@ template inline static if_arithmetic_be_t operator --(_atomic_bas return result; } -template inline static if_arithmetic_be_t operator +=(_atomic_base>& left, T2 right) +template inline if_integral_be_t operator +=(_atomic_base>& left, T2 right) { be_t result; @@ -290,7 +283,7 @@ template inline static if_arithmetic_be_t operat return result; } -template inline static if_arithmetic_be_t operator -=(_atomic_base>& left, T2 right) +template inline if_integral_be_t operator -=(_atomic_base>& left, T2 right) { be_t result; @@ -304,6 +297,6 @@ template inline static if_arithmetic_be_t operat template using atomic = _atomic_base; // Atomic Type with native endianness (for emulator memory) -template using atomic_be_t = _atomic_base::type>; // Atomic BE Type (for PS3 virtual memory) +template using atomic_be_t = _atomic_base>; // Atomic BE Type (for PS3 virtual memory) -template using atomic_le_t = _atomic_base::type>; // Atomic LE Type (for PSV virtual memory) +template using atomic_le_t = _atomic_base>; // Atomic LE Type (for PSV virtual memory) diff --git a/rpcs3/Emu/Memory/vm.h b/rpcs3/Emu/Memory/vm.h index 5413ca90b3..8dea66bff7 100644 --- a/rpcs3/Emu/Memory/vm.h +++ b/rpcs3/Emu/Memory/vm.h @@ -127,10 +127,10 @@ namespace vm } }; - template - struct cast_ptr> + template + struct cast_ptr> { - force_inline static u32 cast(const be_t& addr, const char* func) + force_inline static u32 cast(const be_t& addr, const char* func) { return cast_ptr::cast(addr.value(), func); } diff --git a/rpcs3/Emu/Memory/vm_ptr.h b/rpcs3/Emu/Memory/vm_ptr.h index 973aa55719..61c828f57b 100644 --- a/rpcs3/Emu/Memory/vm_ptr.h +++ b/rpcs3/Emu/Memory/vm_ptr.h @@ -5,209 +5,29 @@ struct ARMv7Context; namespace vm { - template + template struct _ptr_base { AT m_addr; - typedef typename std::remove_cv::type type; - static const u32 address_size = sizeof(AT); + using type = T; - _ptr_base operator++ (int) - { - AT result = m_addr; - m_addr += address_size; - return make(result); - } - - _ptr_base& operator++ () - { - m_addr += address_size; - return *this; - } - - _ptr_base operator-- (int) - { - AT result = m_addr; - m_addr -= address_size; - return make(result); - } - - _ptr_base& operator-- () - { - m_addr -= address_size; - return *this; - } - - _ptr_base& operator += (AT count) - { - m_addr += count * address_size; - return *this; - } - - _ptr_base& operator -= (AT count) - { - m_addr -= count * address_size; - return *this; - } - - _ptr_base operator + (typename remove_be_t::type count) const { return make(m_addr + count * address_size); } - _ptr_base operator + (typename to_be_t::type count) const { return make(m_addr + count * address_size); } - _ptr_base operator - (typename remove_be_t::type count) const { return make(m_addr - count * address_size); } - _ptr_base operator - (typename to_be_t::type count) const { return make(m_addr - count * address_size); } - - force_inline bool operator <(const _ptr_base& right) const { return m_addr < right.m_addr; } - force_inline bool operator <=(const _ptr_base& right) const { return m_addr <= right.m_addr; } - force_inline bool operator >(const _ptr_base& right) const { return m_addr > right.m_addr; } - force_inline bool operator >=(const _ptr_base& right) const { return m_addr >= right.m_addr; } - force_inline bool operator ==(const _ptr_base& right) const { return m_addr == right.m_addr; } - force_inline bool operator !=(const _ptr_base& right) const { return m_addr != right.m_addr; } - force_inline bool operator ==(const nullptr_t& right) const { return m_addr == 0; } - force_inline bool operator !=(const nullptr_t& right) const { return m_addr != 0; } - explicit operator bool() const { return m_addr != 0; } - - force_inline _ptr_base::value, typename to_be_t::type, AT>::type> operator *() const - { - AT addr = convert_le_be(read64(convert_le_be(m_addr))); - return (_ptr_base::value, typename to_be_t::type, AT>::type>&)addr; - } - - force_inline _ptr_base::value, typename to_be_t::type, AT>::type> operator [](AT index) const - { - AT addr = convert_le_be(read64(convert_le_be(m_addr + 8 * index))); - return (_ptr_base::value, typename to_be_t::type, AT>::type>&)addr; - } - - template - operator _ptr_base() const - { - AT2 addr = convert_le_be(m_addr); - return reinterpret_cast<_ptr_base&>(addr); - } - - AT addr() const - { - return m_addr; - } - - template - void set(U&& value) - { - m_addr = convert_le_be(value); - } - - static _ptr_base make(const AT& addr) - { - return reinterpret_cast(addr); - } - - _ptr_base& operator = (const _ptr_base& right) = default; - }; - - template - struct _ptr_base - { - AT m_addr; - static_assert(!std::is_pointer::value, "vm::_ptr_base<> error: invalid type (pointer)"); static_assert(!std::is_reference::value, "vm::_ptr_base<> error: invalid type (reference)"); - typedef typename std::remove_cv::type type; - force_inline static const u32 data_size() - { - return convert_le_be(sizeof(T)); - } - - force_inline T* const operator -> () const - { - return vm::get_ptr(vm::cast(m_addr)); - } - - _ptr_base operator++ (int) - { - AT result = m_addr; - m_addr += data_size(); - return make(result); - } - - _ptr_base& operator++ () - { - m_addr += data_size(); - return *this; - } - - _ptr_base operator-- (int) - { - AT result = m_addr; - m_addr -= data_size(); - return make(result); - } - - _ptr_base& operator-- () - { - m_addr -= data_size(); - return *this; - } - - _ptr_base& operator += (AT count) - { - m_addr += count * data_size(); - return *this; - } - - _ptr_base& operator -= (AT count) - { - m_addr -= count * data_size(); - return *this; - } - - _ptr_base operator + (typename remove_be_t::type count) const { return make(convert_le_be(convert_le_be(m_addr) + count * convert_le_be(data_size()))); } - _ptr_base operator + (typename to_be_t::type count) const { return make(convert_le_be(convert_le_be(m_addr) + count * convert_le_be(data_size()))); } - _ptr_base operator - (typename remove_be_t::type count) const { return make(convert_le_be(convert_le_be(m_addr) - count * convert_le_be(data_size()))); } - _ptr_base operator - (typename to_be_t::type count) const { return make(convert_le_be(convert_le_be(m_addr) - count * convert_le_be(data_size()))); } - - force_inline T& operator *() const - { - return vm::get_ref(vm::cast(m_addr)); - } - - force_inline T& operator [](typename remove_be_t::type index) const - { - return vm::get_ref(vm::cast(m_addr + data_size() * index)); - } - - force_inline T& operator [](typename to_be_t::forced_type index) const - { - return vm::get_ref(vm::cast(m_addr + data_size() * index)); - } - - force_inline bool operator <(const _ptr_base& right) const { return m_addr < right.m_addr; } - force_inline bool operator <=(const _ptr_base& right) const { return m_addr <= right.m_addr; } - force_inline bool operator >(const _ptr_base& right) const { return m_addr > right.m_addr; } - force_inline bool operator >=(const _ptr_base& right) const { return m_addr >= right.m_addr; } - force_inline bool operator ==(const _ptr_base& right) const { return m_addr == right.m_addr; } - force_inline bool operator !=(const _ptr_base& right) const { return m_addr != right.m_addr; } - force_inline bool operator ==(const nullptr_t& right) const { return m_addr == 0; } - force_inline bool operator !=(const nullptr_t& right) const { return m_addr != 0; } - explicit operator bool() const { return m_addr != 0; } - explicit operator T*() const { return get_ptr(); } - AT addr() const { return m_addr; } - - template - void set(U&& value) + + template std::enable_if_t::value> set(const CT& value) { - m_addr = convert_le_be(value); + m_addr = value; } - template - operator _ptr_base() const + template static _ptr_base make(const AT2& addr) { - AT2 addr = convert_le_be(m_addr); - return reinterpret_cast<_ptr_base&>(addr); + return{ convert_le_be(addr) }; } T* get_ptr() const @@ -219,140 +39,59 @@ namespace vm { return vm::priv_ptr(vm::cast(m_addr)); } - - static const _ptr_base make(const AT& addr) - { - return reinterpret_cast(addr); - } - _ptr_base& operator = (const _ptr_base& right) = default; - }; - - template - struct _ptr_base - { - AT m_addr; - - AT addr() const - { - return m_addr; - } - - template - void set(U&& value) - { - m_addr = convert_le_be(value); - } - - void* get_ptr() const - { - return vm::get_ptr(vm::cast(m_addr)); - } - - void* priv_ptr() const - { - return vm::priv_ptr(vm::cast(m_addr)); - } - - explicit operator void*() const + T* operator ->() const { return get_ptr(); } - force_inline bool operator <(const _ptr_base& right) const { return m_addr < right.m_addr; } - force_inline bool operator <=(const _ptr_base& right) const { return m_addr <= right.m_addr; } - force_inline bool operator >(const _ptr_base& right) const { return m_addr > right.m_addr; } - force_inline bool operator >=(const _ptr_base& right) const { return m_addr >= right.m_addr; } - force_inline bool operator ==(const _ptr_base& right) const { return m_addr == right.m_addr; } - force_inline bool operator !=(const _ptr_base& right) const { return m_addr != right.m_addr; } - force_inline bool operator ==(const nullptr_t& right) const { return m_addr == 0; } - force_inline bool operator !=(const nullptr_t& right) const { return m_addr != 0; } - explicit operator bool() const { return m_addr != 0; } - - template - operator _ptr_base() const + std::add_lvalue_reference_t operator [](u32 index) const { - AT2 addr = convert_le_be(m_addr); - return reinterpret_cast<_ptr_base&>(addr); + static_assert(!std::is_void::value, "vm::_ptr_base<> error: operator[] is not available for void pointers"); + + return vm::get_ref(vm::cast(m_addr + sizeof32(T) * index)); } - template - operator _ptr_base() const + // enable only the conversions which are originally possible between pointer types + template::value>> operator _ptr_base() const { - AT2 addr = convert_le_be(m_addr); - return reinterpret_cast<_ptr_base&>(addr); + return{ convert_le_be(vm::cast(m_addr)) }; } - static const _ptr_base make(const AT& addr) - { - return reinterpret_cast(addr); - } - - _ptr_base& operator = (const _ptr_base& right) = default; - }; - - template - struct _ptr_base - { - AT m_addr; - - AT addr() const - { - return m_addr; - } - - template - void set(U&& value) - { - m_addr = convert_le_be(value); - } - - const void* get_ptr() const - { - return vm::get_ptr(vm::cast(m_addr)); - } - - const void* priv_ptr() const - { - return vm::priv_ptr(vm::cast(m_addr)); - } - - explicit operator const void*() const + template::value>> explicit operator T2*() const { return get_ptr(); } - force_inline bool operator <(const _ptr_base& right) const { return m_addr < right.m_addr; } - force_inline bool operator <=(const _ptr_base& right) const { return m_addr <= right.m_addr; } - force_inline bool operator >(const _ptr_base& right) const { return m_addr > right.m_addr; } - force_inline bool operator >=(const _ptr_base& right) const { return m_addr >= right.m_addr; } - force_inline bool operator ==(const _ptr_base& right) const { return m_addr == right.m_addr; } - force_inline bool operator !=(const _ptr_base& right) const { return m_addr != right.m_addr; } - force_inline bool operator ==(const nullptr_t& right) const { return m_addr == 0; } - force_inline bool operator !=(const nullptr_t& right) const { return m_addr != 0; } - explicit operator bool() const { return m_addr != 0; } - - template - operator _ptr_base() const + explicit operator bool() const { - AT2 addr = convert_le_be(m_addr); - return reinterpret_cast<_ptr_base&>(addr); + return m_addr != 0; } - static const _ptr_base make(const AT& addr) - { - return reinterpret_cast(addr); - } - - _ptr_base& operator = (const _ptr_base& right) = default; + _ptr_base& operator =(const _ptr_base&) = default; }; template - struct _ptr_base + struct _ptr_base { AT m_addr; - typedef RT(type)(T...); + using type = func_def; + + AT addr() const + { + return m_addr; + } + + template std::enable_if_t::value> set(const CT& value) + { + m_addr = value; + } + + template static _ptr_base make(const AT2& addr) + { + return{ convert_le_be(addr) }; + } // defined in CB_FUNC.h, call using specified PPU thread context RT operator()(PPUThread& CPU, T... args) const; @@ -363,50 +102,33 @@ namespace vm // defined in CB_FUNC.h, call using current PPU thread context RT operator()(T... args) const; - AT addr() const + // conversion to function object + operator std::function() const { - return m_addr; + const u32 addr = vm::cast(m_addr); + + return [addr](T... args) -> RT + { + return _ptr_base{ addr }(args...); + }; } - template - void set(U&& value) + // conversion to another function pointer + template operator _ptr_base() const { - m_addr = convert_le_be(value); + return{ convert_le_be(vm::cast(m_addr)) }; } - force_inline bool operator <(const _ptr_base& right) const { return m_addr < right.m_addr; } - force_inline bool operator <=(const _ptr_base& right) const { return m_addr <= right.m_addr; } - force_inline bool operator >(const _ptr_base& right) const { return m_addr > right.m_addr; } - force_inline bool operator >=(const _ptr_base& right) const { return m_addr >= right.m_addr; } - force_inline bool operator ==(const _ptr_base& right) const { return m_addr == right.m_addr; } - force_inline bool operator !=(const _ptr_base& right) const { return m_addr != right.m_addr; } - force_inline bool operator ==(const nullptr_t& right) const { return m_addr == 0; } - force_inline bool operator !=(const nullptr_t& right) const { return m_addr != 0; } - explicit operator bool() const { return m_addr != 0; } - - template - operator _ptr_base() const + explicit operator bool() const { - AT2 addr = convert_le_be(m_addr); - return reinterpret_cast<_ptr_base&>(addr); + return m_addr != 0; } - static const _ptr_base make(const AT& addr) - { - return reinterpret_cast(addr); - } - - operator const std::function() const - { - const AT addr = convert_le_be(m_addr); - return [addr](T... args) -> RT { return make(addr)(args...); }; - } - - _ptr_base& operator = (const _ptr_base& right) = default; + _ptr_base& operator =(const _ptr_base&) = default; }; template - struct _ptr_base + struct _ptr_base { AT m_addr; @@ -414,39 +136,51 @@ namespace vm }; // Native endianness pointer to LE data - template using ptrl = _ptr_base::type, lvl, AT>; + template using ptrl = _ptr_base, AT>; // Native endianness pointer to BE data - template using ptrb = _ptr_base::type, lvl, AT>; + template using ptrb = _ptr_base, AT>; // BE pointer to LE data - template using bptrl = _ptr_base::type, lvl, typename to_be_t::type>; + template using bptrl = _ptr_base, to_be_t>; // BE pointer to BE data - template using bptrb = _ptr_base::type, lvl, typename to_be_t::type>; + template using bptrb = _ptr_base, to_be_t>; // LE pointer to LE data - template using lptrl = _ptr_base::type, lvl, typename to_le_t::type>; + template using lptrl = _ptr_base, to_le_t>; // LE pointer to BE data - template using lptrb = _ptr_base::type, lvl, typename to_le_t::type>; + template using lptrb = _ptr_base, to_le_t>; namespace ps3 { // default pointer for PS3 HLE functions (Native endianness pointer to BE data) - template using ptr = ptrb; + template using ptr = ptrb; + + // default pointer to pointer for PS3 HLE functions (Native endianness pointer to BE pointer to BE data) + template using pptr = ptr, AT>; // default pointer for PS3 HLE structures (BE pointer to BE data) - template using bptr = bptrb; + template using bptr = bptrb; + + // default pointer to pointer for PS3 HLE structures (BE pointer to BE pointer to BE data) + template using bpptr = bptr, AT>; } namespace psv { // default pointer for PSV HLE functions (Native endianness pointer to LE data) - template using ptr = ptrl; + template using ptr = ptrl; + + // default pointer to pointer for PSV HLE functions (Native endianness pointer to LE pointer to LE data) + template using pptr = ptr>; // default pointer for PSV HLE structures (LE pointer to LE data) - template using lptr = lptrl; + template using lptr = lptrl; + + // default pointer to pointer for PSV HLE structures (LE pointer to LE pointer to LE data) + template using lpptr = lptr>; } // PS3 emulation is main now, so lets it be as default @@ -454,27 +188,198 @@ namespace vm struct null_t { - template operator _ptr_base() const + template operator _ptr_base() const { - const std::array value = {}; - return _ptr_base::make(value[0]); + return{}; } }; // vm::null is convertible to any vm::ptr type as null pointer in virtual memory static null_t null; + + // helper SFINAE type for vm::_ptr_base comparison operators (enables comparison between equal types and between any type and void*) + template using if_comparable_t = std::enable_if_t< + std::is_void::value || + std::is_void::value || + std::is_same, std::remove_cv_t>::value, + RT>; + + // helper SFINAE type for vm::_ptr_base pointer arithmetic operators and indirection (disabled for void and function pointers) + template using if_arithmetical_t = std::enable_if_t< + !std::is_void::value && !std::is_function::value, + RT>; } +// unary plus operator for vm::_ptr_base (always available) +template inline vm::_ptr_base operator +(const vm::_ptr_base& ptr) +{ + return ptr; +} + +// indirection operator for vm::_ptr_base +template inline vm::if_arithmetical_t operator *(const vm::_ptr_base& ptr) +{ + return vm::get_ref(vm::cast(ptr.m_addr)); +} + +// postfix increment operator for vm::_ptr_base +template inline vm::if_arithmetical_t> operator ++(vm::_ptr_base& ptr, int) +{ + const AT result = ptr.m_addr; + ptr.m_addr += sizeof32(T); + return{ result }; +} + +// prefix increment operator for vm::_ptr_base +template inline vm::if_arithmetical_t&> operator ++(vm::_ptr_base& ptr) +{ + ptr.m_addr += sizeof32(T); + return ptr; +} + +// postfix decrement operator for vm::_ptr_base +template inline vm::if_arithmetical_t> operator --(vm::_ptr_base& ptr, int) +{ + const AT result = ptr.m_addr; + ptr.m_addr -= sizeof32(T); + return{ result }; +} + +// prefix decrement operator for vm::_ptr_base +template inline vm::if_arithmetical_t&> operator --(vm::_ptr_base& ptr) +{ + ptr.m_addr -= sizeof32(T); + return ptr; +} + +// addition assignment operator for vm::_ptr_base (pointer += integer) +template inline vm::if_arithmetical_t&> operator +=(vm::_ptr_base& ptr, to_ne_t count) +{ + ptr.m_addr += count * sizeof32(T); + return ptr; +} + +// subtraction assignment operator for vm::_ptr_base (pointer -= integer) +template inline vm::if_arithmetical_t&> operator -=(vm::_ptr_base& ptr, to_ne_t count) +{ + ptr.m_addr -= count * sizeof32(T); + return ptr; +} + +// addition operator for vm::_ptr_base (pointer + integer) +template inline vm::if_arithmetical_t> operator +(const vm::_ptr_base& ptr, to_ne_t count) +{ + return{ convert_le_be(ptr.m_addr + count * sizeof32(T)) }; +} + +// addition operator for vm::_ptr_base (integer + pointer) +template inline vm::if_arithmetical_t> operator +(to_ne_t count, const vm::_ptr_base& ptr) +{ + return{ convert_le_be(ptr.m_addr + count * sizeof32(T)) }; +} + +// subtraction operator for vm::_ptr_base (pointer - integer) +template inline vm::if_arithmetical_t> operator -(const vm::_ptr_base& ptr, to_ne_t count) +{ + return{ convert_le_be(ptr.m_addr - count * sizeof32(T)) }; +} + +// pointer difference operator for vm::_ptr_base +template inline std::enable_if_t< + !std::is_void::value && + !std::is_void::value && + !std::is_function::value && + !std::is_function::value && + std::is_same, std::remove_cv_t>::value, + u32> operator -(const vm::_ptr_base& left, const vm::_ptr_base& right) +{ + return static_cast((left.m_addr - right.m_addr) / sizeof32(T1)); +} + +// comparison operator for vm::_ptr_base (pointer1 == pointer2) +template vm::if_comparable_t operator ==(const vm::_ptr_base& left, const vm::_ptr_base& right) +{ + return left.m_addr == right.m_addr; +} + +// comparison operator for vm::_ptr_base (pointer1 != pointer2) +template vm::if_comparable_t operator !=(const vm::_ptr_base& left, const vm::_ptr_base& right) +{ + return left.m_addr != right.m_addr; +} + +// comparison operator for vm::_ptr_base (pointer1 < pointer2) +template vm::if_comparable_t operator <(const vm::_ptr_base& left, const vm::_ptr_base& right) +{ + return left.m_addr < right.m_addr; +} + +// comparison operator for vm::_ptr_base (pointer1 <= pointer2) +template vm::if_comparable_t operator <=(const vm::_ptr_base& left, const vm::_ptr_base& right) +{ + return left.m_addr <= right.m_addr; +} + +// comparison operator for vm::_ptr_base (pointer1 > pointer2) +template vm::if_comparable_t operator >(const vm::_ptr_base& left, const vm::_ptr_base& right) +{ + return left.m_addr > right.m_addr; +} + +// comparison operator for vm::_ptr_base (pointer1 >= pointer2) +template vm::if_comparable_t operator >=(const vm::_ptr_base& left, const vm::_ptr_base& right) +{ + return left.m_addr >= right.m_addr; +} + +// external specialization for is_be_t<> (true if AT is be_t<>) + +template +struct is_be_t> : public std::integral_constant::value> +{ +}; + +// external specialization for is_le_t<> (true if AT is le_t<>) + +template +struct is_le_t> : public std::integral_constant::value> +{ +}; + +// external specialization for to_ne_t<> (change AT endianness to native) + +template +struct to_ne> +{ + using type = vm::_ptr_base>; +}; + +// external specialization for to_be_t<> (change AT endianness to BE) + +template +struct to_be> +{ + using type = vm::_ptr_base>; +}; + +// external specialization for to_le_t<> (change AT endianness to LE) + +template +struct to_le> +{ + using type = vm::_ptr_base>; +}; + namespace fmt { // external specialization for fmt::format function - template - struct unveil, false> + template + struct unveil, false> { - typedef typename unveil::result_type result_type; + using result_type = typename unveil::result_type; - force_inline static result_type get_value(const vm::_ptr_base& arg) + force_inline static result_type get_value(const vm::_ptr_base& arg) { return unveil::get_value(arg.addr()); } @@ -486,17 +391,17 @@ namespace fmt template struct cast_ppu_gpr; -template -struct cast_ppu_gpr, false> +template +struct cast_ppu_gpr, false> { - force_inline static u64 to_gpr(const vm::_ptr_base& value) + force_inline static u64 to_gpr(const vm::_ptr_base& value) { return cast_ppu_gpr::value>::to_gpr(value.addr()); } - force_inline static vm::_ptr_base from_gpr(const u64 reg) + force_inline static vm::_ptr_base from_gpr(const u64 reg) { - return vm::_ptr_base::make(cast_ppu_gpr::value>::from_gpr(reg)); + return vm::_ptr_base::make(cast_ppu_gpr::value>::from_gpr(reg)); } }; @@ -505,16 +410,16 @@ struct cast_ppu_gpr, false> template struct cast_armv7_gpr; -template -struct cast_armv7_gpr, false> +template +struct cast_armv7_gpr, false> { - force_inline static u32 to_gpr(const vm::_ptr_base& value) + force_inline static u32 to_gpr(const vm::_ptr_base& value) { return cast_armv7_gpr::value>::to_gpr(value.addr()); } - force_inline static vm::_ptr_base from_gpr(const u32 reg) + force_inline static vm::_ptr_base from_gpr(const u32 reg) { - return vm::_ptr_base::make(cast_armv7_gpr::value>::from_gpr(reg)); + return vm::_ptr_base::make(cast_armv7_gpr::value>::from_gpr(reg)); } }; diff --git a/rpcs3/Emu/Memory/vm_ref.h b/rpcs3/Emu/Memory/vm_ref.h index a2e7903d16..acd62e58f1 100644 --- a/rpcs3/Emu/Memory/vm_ref.h +++ b/rpcs3/Emu/Memory/vm_ref.h @@ -3,80 +3,88 @@ namespace vm { template - class _ref_base + struct _ref_base { - protected: AT m_addr; - public: - typedef T type; static_assert(!std::is_pointer::value, "vm::_ref_base<> error: invalid type (pointer)"); static_assert(!std::is_reference::value, "vm::_ref_base<> error: invalid type (reference)"); - typedef typename remove_be_t::type le_type; - typedef typename to_be_t::type be_type; - - operator T&() - { - return get_ref(m_addr); - } - - operator const T&() const - { - return get_ref(m_addr); - } + static_assert(!std::is_function::value, "vm::_ref_base<> error: invalid type (function)"); + static_assert(!std::is_void::value, "vm::_ref_base<> error: invalid type (void)"); AT addr() const { return m_addr; } - static _ref_base make(const AT& addr) + template static _ref_base make(const AT2& addr) { - return reinterpret_cast<_ref_base&>(addr); + return{ convert_le_be(addr) }; } - _ref_base& operator = (le_type right) + T& get_ref() const { - get_ref(m_addr) = right; - return *this; + return vm::get_ref(vm::cast(m_addr)); } - const _ref_base& operator = (le_type right) const + T& priv_ref() const { - get_ref(m_addr) = right; - return *this; + return vm::priv_ref(vm::cast(m_addr)); } - _ref_base& operator = (be_type right) + // TODO: conversion operator (seems hard to define it correctly) + //template::value || std::is_convertible, CT>::value>> operator CT() const + //{ + // return get_ref(); + //} + + operator to_ne_t() const { - get_ref(m_addr) = right; - return *this; + return get_ref(); } - const _ref_base& operator = (be_type right) const + explicit operator T&() const { - get_ref(m_addr) = right; - return *this; + return get_ref(); + } + + // copy assignment operator: + // returns T& by default, this may be wrong if called assignment operator has different return type + T& operator =(const _ref_base& right) + { + static_assert(!std::is_const::value, "vm::_ref_base<> error: operator= is not available for const reference"); + + return get_ref() = right.get_ref(); + } + + template auto operator =(const _ref_base& right) const -> decltype(std::declval() = std::declval()) + { + return get_ref() = right.get_ref(); + } + + template auto operator =(const CT& right) const -> decltype(std::declval() = std::declval()) + { + return get_ref() = right; } }; // Native endianness reference to LE data - template using refl = _ref_base::type, AT>; + template using refl = _ref_base, AT>; // Native endianness reference to BE data - template using refb = _ref_base::type, AT>; + template using refb = _ref_base, AT>; // BE reference to LE data - template using brefl = _ref_base::type, typename to_be_t::type>; + template using brefl = _ref_base, to_be_t>; // BE reference to BE data - template using brefb = _ref_base::type, typename to_be_t::type>; + template using brefb = _ref_base, to_be_t>; // LE reference to LE data - template using lrefl = _ref_base::type, typename to_le_t::type>; + template using lrefl = _ref_base, to_le_t>; // LE reference to BE data - template using lrefb = _ref_base::type, typename to_le_t::type>; + template using lrefb = _ref_base, to_le_t>; namespace ps3 { @@ -90,16 +98,138 @@ namespace vm namespace psv { // default reference for PSV HLE functions (Native endianness reference to LE data) - template using ref = refl; + template using ref = refl; // default reference for PSV HLE structures (LE reference to LE data) - template using lref = lrefl; + template using lref = lrefl; } //PS3 emulation is main now, so lets it be as default using namespace ps3; } +// postfix increment operator for vm::_ref_base +template inline auto operator ++(const vm::_ref_base& ref, int) -> decltype(std::declval()++) +{ + return ref.get_ref()++; +} + +// prefix increment operator for vm::_ref_base +template inline auto operator ++(const vm::_ref_base& ref) -> decltype(++std::declval()) +{ + return ++ref.get_ref(); +} + +// postfix decrement operator for vm::_ref_base +template inline auto operator --(const vm::_ref_base& ref, int) -> decltype(std::declval()--) +{ + return ref.get_ref()--; +} + +// prefix decrement operator for vm::_ref_base +template inline auto operator --(const vm::_ref_base& ref) -> decltype(--std::declval()) +{ + return --ref.get_ref(); +} + +// addition assignment operator for vm::_ref_base +template inline auto operator +=(const vm::_ref_base& ref, const T2& right) -> decltype(std::declval() += std::declval()) +{ + return ref.get_ref() += right; +} + +// subtraction assignment operator for vm::_ref_base +template inline auto operator -=(const vm::_ref_base& ref, const T2& right) -> decltype(std::declval() -= std::declval()) +{ + return ref.get_ref() -= right; +} + +// multiplication assignment operator for vm::_ref_base +template inline auto operator *=(const vm::_ref_base& ref, const T2& right) -> decltype(std::declval() *= std::declval()) +{ + return ref.get_ref() *= right; +} + +// division assignment operator for vm::_ref_base +template inline auto operator /=(const vm::_ref_base& ref, const T2& right) -> decltype(std::declval() /= std::declval()) +{ + return ref.get_ref() /= right; +} + +// modulo assignment operator for vm::_ref_base +template inline auto operator %=(const vm::_ref_base& ref, const T2& right) -> decltype(std::declval() %= std::declval()) +{ + return ref.get_ref() %= right; +} + +// bitwise AND assignment operator for vm::_ref_base +template inline auto operator &=(const vm::_ref_base& ref, const T2& right) -> decltype(std::declval() &= std::declval()) +{ + return ref.get_ref() &= right; +} + +// bitwise OR assignment operator for vm::_ref_base +template inline auto operator |=(const vm::_ref_base& ref, const T2& right) -> decltype(std::declval() |= std::declval()) +{ + return ref.get_ref() |= right; +} + +// bitwise XOR assignment operator for vm::_ref_base +template inline auto operator ^=(const vm::_ref_base& ref, const T2& right) -> decltype(std::declval() ^= std::declval()) +{ + return ref.get_ref() ^= right; +} + +// bitwise left shift assignment operator for vm::_ref_base +template inline auto operator <<=(const vm::_ref_base& ref, const T2& right) -> decltype(std::declval() <<= std::declval()) +{ + return ref.get_ref() <<= right; +} + +// bitwise right shift assignment operator for vm::_ref_base +template inline auto operator >>=(const vm::_ref_base& ref, const T2& right) -> decltype(std::declval() >>= std::declval()) +{ + return ref.get_ref() >>= right; +} + +// external specialization for is_be_t<> (true if AT's endianness is BE) + +template +struct is_be_t> : public std::integral_constant::value> +{ +}; + +// external specialization for is_le_t<> (true if AT's endianness is LE) + +template +struct is_le_t> : public std::integral_constant::value> +{ +}; + +// external specialization for to_ne_t<> (change AT's endianness to native) + +template +struct to_ne> +{ + using type = vm::_ref_base>; +}; + +// external specialization for to_be_t<> (change AT's endianness to BE) + +template +struct to_be> +{ + using type = vm::_ref_base>; +}; + +// external specialization for to_le_t<> (change AT's endianness to LE) + +template +struct to_le> +{ + using type = vm::_ref_base>; +}; + namespace fmt { // external specialization for fmt::format function @@ -107,7 +237,7 @@ namespace fmt template struct unveil, false> { - typedef typename unveil::result_type result_type; + using result_type = typename unveil::result_type; force_inline static result_type get_value(const vm::_ref_base& arg) { diff --git a/rpcs3/Emu/Memory/vm_var.h b/rpcs3/Emu/Memory/vm_var.h index dfef1b4a9b..a342f7df2a 100644 --- a/rpcs3/Emu/Memory/vm_var.h +++ b/rpcs3/Emu/Memory/vm_var.h @@ -108,24 +108,24 @@ namespace vm } */ - template operator _ptr_base() const + template operator _ptr_base() const { - return _ptr_base::make(m_addr); + return _ptr_base::make(m_addr); } - template operator _ptr_base() const + template operator _ptr_base() const { - return _ptr_base::make(m_addr); + return _ptr_base::make(m_addr); } - template operator _ptr_base() const + template operator _ptr_base() const { - return _ptr_base::make(m_addr); + return _ptr_base::make(m_addr); } - template operator _ptr_base() const + template operator _ptr_base() const { - return _ptr_base::make(m_addr); + return _ptr_base::make(m_addr); } operator T&() @@ -614,24 +614,24 @@ namespace vm } */ - template operator _ptr_base() const + template operator _ptr_base() const { - return _ptr_base::make(m_data.addr); + return _ptr_base::make(m_data.addr); } - template operator _ptr_base() const + template operator _ptr_base() const { - return _ptr_base::make(m_data.addr); + return _ptr_base::make(m_data.addr); } - template operator _ptr_base() const + template operator _ptr_base() const { - return _ptr_base::make(m_data.addr); + return _ptr_base::make(m_data.addr); } - template operator _ptr_base() const + template operator _ptr_base() const { - return _ptr_base::make(m_data.addr); + return _ptr_base::make(m_data.addr); } operator T&() diff --git a/rpcs3/Emu/RSX/CgBinaryProgram.h b/rpcs3/Emu/RSX/CgBinaryProgram.h index 185c0002d6..89959d0300 100644 --- a/rpcs3/Emu/RSX/CgBinaryProgram.h +++ b/rpcs3/Emu/RSX/CgBinaryProgram.h @@ -301,7 +301,7 @@ public: m_arb_shader += fmt::format("#%d ", i) + param_type + param_name + param_semantic + param_const + "\n"; - offset += sizeof(CgBinaryParameter); + offset += sizeof32(CgBinaryParameter); } m_arb_shader += "\n"; @@ -355,7 +355,7 @@ public: m_arb_shader += fmt::format("#%d ", i) + param_type + param_name + param_semantic + param_const + "\n"; - offset += sizeof(CgBinaryParameter); + offset += sizeof32(CgBinaryParameter); } m_arb_shader += "\n"; diff --git a/rpcs3/Emu/SysCalls/CB_FUNC.h b/rpcs3/Emu/SysCalls/CB_FUNC.h index 545f2b0d1f..148feb5426 100644 --- a/rpcs3/Emu/SysCalls/CB_FUNC.h +++ b/rpcs3/Emu/SysCalls/CB_FUNC.h @@ -162,7 +162,7 @@ namespace cb_detail namespace vm { template - force_inline RT _ptr_base::operator()(PPUThread& CPU, T... args) const + force_inline RT _ptr_base::operator()(PPUThread& CPU, T... args) const { const auto data = vm::get_ptr>(vm::cast(m_addr)); const u32 pc = data[0]; @@ -172,7 +172,7 @@ namespace vm } template - force_inline RT _ptr_base::operator()(T... args) const + force_inline RT _ptr_base::operator()(T... args) const { return operator()(GetCurrentPPUThread(), args...); } diff --git a/rpcs3/Emu/SysCalls/Modules.cpp b/rpcs3/Emu/SysCalls/Modules.cpp index b1eeb20cfd..a73da6981c 100644 --- a/rpcs3/Emu/SysCalls/Modules.cpp +++ b/rpcs3/Emu/SysCalls/Modules.cpp @@ -119,16 +119,19 @@ void execute_ppu_func_by_index(PPUThread& CPU, u32 index) if (old_last_syscall) { + CPU.m_last_syscall = func->id; throw "Unfortunately, this function cannot be called from the callback."; } if (!func->lle_func) { + CPU.m_last_syscall = func->id; throw "Wrong usage: LLE function not set."; } if (func->flags & MFF_FORCED_HLE) { + CPU.m_last_syscall = func->id; throw "Wrong usage: Forced HLE enabled."; } @@ -139,6 +142,7 @@ void execute_ppu_func_by_index(PPUThread& CPU, u32 index) if (index & EIF_PERFORM_BLR) { + CPU.m_last_syscall = func->id; throw "TODO: Branch with link"; // CPU.LR = CPU.PC + 4; } diff --git a/rpcs3/Emu/SysCalls/Modules/cellAdec.cpp b/rpcs3/Emu/SysCalls/Modules/cellAdec.cpp index 528cc2b3cf..4e410636b1 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellAdec.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellAdec.cpp @@ -792,7 +792,7 @@ s32 cellAdecGetPcm(u32 handle, vm::ptr outBuffer) return CELL_OK; } -s32 cellAdecGetPcmItem(u32 handle, vm::ptr> pcmItem) +s32 cellAdecGetPcmItem(u32 handle, vm::pptr pcmItem) { cellAdec.Log("cellAdecGetPcmItem(handle=0x%x, pcmItem=**0x%x)", handle, pcmItem); @@ -821,7 +821,7 @@ s32 cellAdecGetPcmItem(u32 handle, vm::ptr> pcmItem) } pcm->pcmHandle = 0; // ??? - pcm->pcmAttr.bsiInfo_addr = pcm.addr() + sizeof(CellAdecPcmItem); + pcm->pcmAttr.bsiInfo_addr = pcm.addr() + sizeof32(CellAdecPcmItem); pcm->startAddr = 0x00000312; // invalid address (no output) pcm->size = af.size; pcm->status = CELL_OK; @@ -833,7 +833,7 @@ s32 cellAdecGetPcmItem(u32 handle, vm::ptr> pcmItem) if (adecIsAtracX(adec->type)) { - auto atx = vm::ptr::make(pcm.addr() + sizeof(CellAdecPcmItem)); + auto atx = vm::ptr::make(pcm.addr() + sizeof32(CellAdecPcmItem)); atx->samplingFreq = frame->sample_rate; atx->nbytes = frame->nb_samples * sizeof(float); @@ -861,7 +861,7 @@ s32 cellAdecGetPcmItem(u32 handle, vm::ptr> pcmItem) } else if (adec->type == CELL_ADEC_TYPE_MP3) { - auto mp3 = vm::ptr::make(pcm.addr() + sizeof(CellAdecPcmItem)); + auto mp3 = vm::ptr::make(pcm.addr() + sizeof32(CellAdecPcmItem)); // TODO memset(mp3.get_ptr(), 0, sizeof(CellAdecMP3Info)); diff --git a/rpcs3/Emu/SysCalls/Modules/cellGifDec.cpp b/rpcs3/Emu/SysCalls/Modules/cellGifDec.cpp index 352cedc091..c1717474df 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellGifDec.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellGifDec.cpp @@ -18,23 +18,35 @@ extern "C" extern Module cellGifDec; -s32 cellGifDecCreate(u32 mainHandle, u32 threadInParam, u32 threadOutParam) +s32 cellGifDecCreate( + vm::ptr mainHandle, + vm::ptr threadInParam, + vm::ptr threadOutParam) { UNIMPLEMENTED_FUNC(cellGifDec); return CELL_OK; } -s32 cellGifDecExtCreate(u32 mainHandle, u32 threadInParam, u32 threadOutParam, u32 extThreadInParam, u32 extThreadOutParam) +s32 cellGifDecExtCreate( + vm::ptr mainHandle, + vm::ptr threadInParam, + vm::ptr threadOutParam, + vm::ptr extThreadInParam, + vm::ptr extThreadOutParam) { UNIMPLEMENTED_FUNC(cellGifDec); return CELL_OK; } -s32 cellGifDecOpen(u32 mainHandle, vm::ptr subHandle, vm::ptr src, vm::ptr openInfo) +s32 cellGifDecOpen( + CellGifDecMainHandle mainHandle, + vm::ptr subHandle, + vm::ptr src, + vm::ptr openInfo) { cellGifDec.Warning("cellGifDecOpen(mainHandle=0x%x, subHandle=*0x%x, src=*0x%x, openInfo=*0x%x)", mainHandle, subHandle, src, openInfo); - auto current_subHandle = std::make_shared(); + auto current_subHandle = std::make_shared(); current_subHandle->fd = 0; current_subHandle->src = *src; @@ -62,11 +74,14 @@ s32 cellGifDecOpen(u32 mainHandle, vm::ptr subHandle, vm::ptr info) +s32 cellGifDecReadHeader( + CellGifDecMainHandle mainHandle, + CellGifDecSubHandle subHandle, + vm::ptr info) { cellGifDec.Warning("cellGifDecReadHeader(mainHandle=0x%x, subHandle=0x%x, info=*0x%x)", mainHandle, subHandle, info); - const auto subHandle_data = Emu.GetIdManager().get(subHandle); + const auto subHandle_data = Emu.GetIdManager().get(subHandle); if (!subHandle_data) { @@ -83,7 +98,7 @@ s32 cellGifDecReadHeader(u32 mainHandle, u32 subHandle, vm::ptr switch(subHandle_data->src.srcSelect.data()) { case se32(CELL_GIFDEC_BUFFER): - memmove(buffer.begin(), vm::get_ptr(subHandle_data->src.streamPtr), buffer.size()); + memmove(buffer.begin(), subHandle_data->src.streamPtr.get_ptr(), buffer.size()); break; case se32(CELL_GIFDEC_FILE): @@ -116,11 +131,15 @@ s32 cellGifDecReadHeader(u32 mainHandle, u32 subHandle, vm::ptr return CELL_OK; } -s32 cellGifDecSetParameter(u32 mainHandle, u32 subHandle, vm::ptr inParam, vm::ptr outParam) +s32 cellGifDecSetParameter( + CellGifDecMainHandle mainHandle, + CellGifDecSubHandle subHandle, + vm::ptr inParam, + vm::ptr outParam) { cellGifDec.Warning("cellGifDecSetParameter(mainHandle=0x%x, subHandle=0x%x, inParam=*0x%x, outParam=*0x%x)", mainHandle, subHandle, inParam, outParam); - const auto subHandle_data = Emu.GetIdManager().get(subHandle); + const auto subHandle_data = Emu.GetIdManager().get(subHandle); if (!subHandle_data) { @@ -148,13 +167,18 @@ s32 cellGifDecSetParameter(u32 mainHandle, u32 subHandle, vm::ptr data, vm::ptr dataCtrlParam, vm::ptr dataOutInfo) +s32 cellGifDecDecodeData( + CellGifDecMainHandle mainHandle, + CellGifDecSubHandle subHandle, + vm::ptr data, + vm::ptr dataCtrlParam, + vm::ptr dataOutInfo) { cellGifDec.Warning("cellGifDecDecodeData(mainHandle=0x%x, subHandle=0x%x, data=*0x%x, dataCtrlParam=*0x%x, dataOutInfo=*0x%x)", mainHandle, subHandle, data, dataCtrlParam, dataOutInfo); dataOutInfo->status = CELL_GIFDEC_DEC_STATUS_STOP; - const auto subHandle_data = Emu.GetIdManager().get(subHandle); + const auto subHandle_data = Emu.GetIdManager().get(subHandle); if (!subHandle_data) { @@ -171,7 +195,7 @@ s32 cellGifDecDecodeData(u32 mainHandle, u32 subHandle, vm::ptr data, vm::pt switch(subHandle_data->src.srcSelect.data()) { case se32(CELL_GIFDEC_BUFFER): - memmove(gif.begin(), vm::get_ptr(subHandle_data->src.streamPtr), gif.size()); + memmove(gif.begin(), subHandle_data->src.streamPtr.get_ptr(), gif.size()); break; case se32(CELL_GIFDEC_FILE): @@ -269,11 +293,11 @@ s32 cellGifDecDecodeData(u32 mainHandle, u32 subHandle, vm::ptr data, vm::pt return CELL_OK; } -s32 cellGifDecClose(u32 mainHandle, u32 subHandle) +s32 cellGifDecClose(CellGifDecMainHandle mainHandle, CellGifDecSubHandle subHandle) { cellGifDec.Warning("cellGifDecClose(mainHandle=0x%x, subHandle=0x%x)", mainHandle, subHandle); - const auto subHandle_data = Emu.GetIdManager().get(subHandle); + const auto subHandle_data = Emu.GetIdManager().get(subHandle); if (!subHandle_data) { @@ -286,7 +310,7 @@ s32 cellGifDecClose(u32 mainHandle, u32 subHandle) return CELL_OK; } -s32 cellGifDecDestroy(u32 mainHandle) +s32 cellGifDecDestroy(CellGifDecMainHandle mainHandle) { UNIMPLEMENTED_FUNC(cellGifDec); return CELL_OK; diff --git a/rpcs3/Emu/SysCalls/Modules/cellGifDec.h b/rpcs3/Emu/SysCalls/Modules/cellGifDec.h index b958150908..ec00dedd82 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellGifDec.h +++ b/rpcs3/Emu/SysCalls/Modules/cellGifDec.h @@ -1,6 +1,6 @@ #pragma once -//Return Codes +// Return Codes enum { CELL_GIFDEC_ERROR_OPEN_FILE = 0x80611300, @@ -13,29 +13,94 @@ enum CELL_GIFDEC_ERROR_CB_PARAM = 0x80611307, }; -enum CellGifDecStreamSrcSel +enum CellGifDecStreamSrcSel : s32 { CELL_GIFDEC_FILE = 0, // Input from a file CELL_GIFDEC_BUFFER = 1, // Input from a buffer }; -enum CellGifDecColorSpace +enum CellGifDecSpuThreadEna : s32 { - CELL_GIFDEC_RGBA = 10, - CELL_GIFDEC_ARGB = 20, + CELL_GIFDEC_SPU_THREAD_DISABLE = 0, // Do not use SPU threads + CELL_GIFDEC_SPU_THREAD_ENABLE = 1, // Use SPU threads }; -enum CellGifDecRecordType +enum CellGifDecRecordType : s32 { CELL_GIFDEC_RECORD_TYPE_IMAGE_DESC = 1, // Image data block CELL_GIFDEC_RECORD_TYPE_EXTENSION = 2, // Extension block CELL_GIFDEC_RECORD_TYPE_TERMINATE = 3, // Trailer block }; -enum CellGifDecDecodeStatus +enum CellGifDecColorSpace : s32 { - CELL_GIFDEC_DEC_STATUS_FINISH = 0, //Decoding finished - CELL_GIFDEC_DEC_STATUS_STOP = 1, //Decoding halted + CELL_GIFDEC_RGBA = 10, // RGBA + CELL_GIFDEC_ARGB = 20, // ARGB +}; + +enum CellGifDecCommand : s32 +{ + CELL_GIFDEC_CONTINUE = 0, // Continue decoding + CELL_GIFDEC_STOP = 1, // Force decoding to stop +}; + +enum CellGifDecDecodeStatus : s32 +{ + CELL_GIFDEC_DEC_STATUS_FINISH = 0, // Decoding finished + CELL_GIFDEC_DEC_STATUS_STOP = 1, // Decoding was stopped +}; + +// Handles +using CellGifDecMainHandle = vm::ptr; +using CellGifDecSubHandle = u32; // vm::ptr; + +// Callbacks for memory management +using CellGifDecCbControlMalloc = func_def(u32 size, vm::ptr cbCtrlMallocArg)>; +using CellGifDecCbControlFree = func_def ptr, vm::ptr cbCtrlFreeArg)>; + +// Structs +struct CellGifDecThreadInParam +{ + be_t spuThreadEnable; // CellGifDecSpuThreadEna + be_t ppuThreadPriority; + be_t spuThreadPriority; + vm::bptr cbCtrlMallocFunc; + vm::bptr cbCtrlMallocArg; + vm::bptr cbCtrlFreeFunc; + vm::bptr cbCtrlFreeArg; +}; + +struct CellGifDecThreadOutParam +{ + be_t gifCodecVersion; +}; + +struct CellGifDecExtThreadInParam +{ + vm::bptr spurs; + u8 priority[8]; + be_t maxContention; +}; + +struct CellGifDecExtThreadOutParam +{ + be_t reserved; +}; + +struct CellGifDecSrc +{ + be_t srcSelect; // CellGifDecStreamSrcSel + vm::bptr fileName; + be_t fileOffset; + be_t fileSize; + vm::bptr streamPtr; + be_t streamSize; + be_t spuThreadEnable; // CellGifDecSpuThreadEna +}; + +struct CellGifDecOpnInfo +{ + be_t initSpaceAllocated; }; struct CellGifDecInfo @@ -50,24 +115,13 @@ struct CellGifDecInfo be_t SPixelAspectRatio; }; -struct CellGifDecSrc -{ - be_t srcSelect; - vm::bptr fileName; - be_t fileOffset; - be_t fileSize; - be_t streamPtr; - be_t streamSize; - be_t spuThreadEnable; -}; - struct CellGifDecInParam { - be_t commandPtr; - be_t colorSpace; // CellGifDecColorSpace - be_t outputColorAlpha1; - be_t outputColorAlpha2; - be_t reserved[2]; + vm::bptr commandPtr; // CellGifDecCommand + be_t colorSpace; // CellGifDecColorSpace + u8 outputColorAlpha1; + u8 outputColorAlpha2; + u8 reserved[2]; }; struct CellGifDecOutParam @@ -77,26 +131,21 @@ struct CellGifDecOutParam be_t outputHeight; be_t outputComponents; be_t outputBitDepth; - be_t outputColorSpace; // CellGifDecColorSpace + be_t outputColorSpace; // CellGifDecColorSpace be_t useMemorySpace; }; struct CellGifDecExtension { - be_t label; - be_t data; + u8 label; + vm::ptr data; }; struct CellGifDecDataOutInfo { - be_t recordType; + be_t recordType; // CellGifDecRecordType CellGifDecExtension outExtension; - be_t status; -}; - -struct CellGifDecOpnInfo -{ - be_t initSpaceAllocated; + be_t status; // CellGifDecDecodeStatus }; struct CellGifDecDataCtrlParam @@ -104,8 +153,12 @@ struct CellGifDecDataCtrlParam be_t outputBytesPerLine; }; -//Custom structs -struct CellGifDecSubHandle +// Custom structs +struct GifDecoder +{ +}; + +struct GifStream { u32 fd; u64 fileSize; diff --git a/rpcs3/Emu/SysCalls/Modules/cellJpgDec.h b/rpcs3/Emu/SysCalls/Modules/cellJpgDec.h index d4d138839e..2450eb9977 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellJpgDec.h +++ b/rpcs3/Emu/SysCalls/Modules/cellJpgDec.h @@ -71,8 +71,8 @@ struct CellJpgDecInParam be_t method; // CellJpgDecMethod be_t outputMode; // CellJpgDecOutputMode be_t outputColorSpace; // CellJpgDecColorSpace - be_t outputColorAlpha; - be_t reserved[3]; + u8 outputColorAlpha; + u8 reserved[3]; }; struct CellJpgDecOutParam diff --git a/rpcs3/Emu/SysCalls/Modules/cellL10n.cpp b/rpcs3/Emu/SysCalls/Modules/cellL10n.cpp index a29aec4262..3bb1b38525 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellL10n.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellL10n.cpp @@ -2,44 +2,60 @@ #include "Emu/Memory/Memory.h" #include "Emu/SysCalls/Modules.h" -#include "cellL10n.h" -#include -#include - #ifdef _MSC_VER #include -#include -#include #else #include #endif +//#include +#include "cellL10n.h" + extern Module cellL10n; -int UTF16stoUTF8s(vm::lptrl utf16, vm::ptr utf16_len, vm::ptr utf8, vm::ptr utf8_len) +s32 UTF16stoUTF8s(vm::ptr utf16, vm::ref utf16_len, vm::ptr utf8, vm::ref utf8_len) { - cellL10n.Warning("UTF16stoUTF8s(utf16_addr=0x%x, utf16_len_addr=0x%x, utf8_addr=0x%x, utf8_len_addr=0x%x)", - utf16.addr(), utf16_len.addr(), utf8.addr(), utf8_len.addr()); + cellL10n.Todo("UTF16stoUTF8s(utf16=*0x%x, utf16_len=*0x%x, utf8=*0x%x, utf8_len=*0x%x)", utf16, utf16_len, utf8, utf8_len); - std::u16string wstr = utf16.get_ptr(); // ??? - wstr.resize(*utf16_len); // TODO: Is this really the role of utf16_len in this function? -#ifdef _MSC_VER - std::wstring_convert,char16_t> convert; - std::string str = convert.to_bytes(wstr); + const u32 max_len = utf8_len; utf8_len = 0; - if (*utf8_len < str.size()) + for (u32 i = 0, len = 0; i < utf16_len; i++, utf8_len = len) { - *utf8_len = str.size(); - return DSTExhausted; + const char16_t ch = utf16[i]; + + // increase required length (TODO) + len = len + 1; + + // validate character (TODO) + //if () + //{ + // utf16_len -= i; + // return SRCIllegal; + //} + + if (utf8) + { + if (len > max_len) + { + utf16_len -= i; + return DSTExhausted; + } + + if (ch <= 0x7f) + { + *utf8++ = static_cast(ch); + } + else + { + *utf8++ = '?'; // TODO + } + } } - *utf8_len = str.size(); - memcpy(utf8.get_ptr(), str.c_str(), str.size()); -#endif return ConversionOK; } -int jstrchk(vm::ptr jstr) +s32 jstrchk(vm::ptr jstr) { cellL10n.Warning("jstrchk(jstr_addr=0x%x) -> utf8", jstr.addr()); @@ -48,7 +64,7 @@ int jstrchk(vm::ptr jstr) //translate code id to code name. some codepage may has another name. //If this makes your compilation fail, try replace the string code with one in "iconv -l" -bool _L10nCodeParse(int code, std::string& retCode) +bool _L10nCodeParse(s32 code, std::string& retCode) { if ((code >= _L10N_CODE_) || (code < 0)) return false; switch (code) @@ -113,7 +129,7 @@ bool _L10nCodeParse(int code, std::string& retCode) //translate code id to code name. //If this makes your compilation fail, try replace the string code with one in "iconv -l" -bool _L10nCodeParse(int code, unsigned int & retCode) +bool _L10nCodeParse(s32 code, u32& retCode) { retCode = 0; if ((code >= _L10N_CODE_) || (code < 0)) return false; @@ -182,10 +198,10 @@ bool _L10nCodeParse(int code, unsigned int & retCode) #ifdef _MSC_VER //Use code page to transform std::string to std::wstring. -int _OEM2Wide(unsigned int oem_code, const std::string src, std::wstring& dst) +s32 _OEM2Wide(u32 oem_code, const std::string src, std::wstring& dst) { //Such length returned should include the '\0' character. - int length = MultiByteToWideChar(oem_code, 0, src.c_str(), -1, NULL, 0); + s32 length = MultiByteToWideChar(oem_code, 0, src.c_str(), -1, NULL, 0); wchar_t *store = new wchar_t[length](); MultiByteToWideChar(oem_code, 0, src.c_str(), -1, (LPWSTR)store, length); @@ -199,10 +215,10 @@ int _OEM2Wide(unsigned int oem_code, const std::string src, std::wstring& dst) } //Use Code page to transform std::wstring to std::string. -int _Wide2OEM(unsigned int oem_code, const std::wstring src, std::string& dst) +s32 _Wide2OEM(u32 oem_code, const std::wstring src, std::string& dst) { //Such length returned should include the '\0' character. - int length = WideCharToMultiByte(oem_code, 0, src.c_str(), -1, NULL, 0, NULL, NULL); + s32 length = WideCharToMultiByte(oem_code, 0, src.c_str(), -1, NULL, 0, NULL, NULL); char *store = new char[length](); WideCharToMultiByte(oem_code, 0, src.c_str(), -1, store, length, NULL, NULL); @@ -216,7 +232,7 @@ int _Wide2OEM(unsigned int oem_code, const std::wstring src, std::string& dst) } //Convert Codepage to Codepage (all char*) -std::string _OemToOem(unsigned int src_code, unsigned int dst_code, const std::string str) +std::string _OemToOem(u32 src_code, u32 dst_code, const std::string str) { std::wstring wide; std::string result; _OEM2Wide(src_code, str, wide); @@ -227,9 +243,9 @@ std::string _OemToOem(unsigned int src_code, unsigned int dst_code, const std::s /* //Original piece of code. and this is for windows using with _OEM2Wide,_Wide2OEM,_OemToOem. //The Char -> Char Execution of this function has already been tested using VS and CJK text with encoding. -int _L10nConvertStr(int src_code, const void *src, size_t * src_len, int dst_code, void *dst, size_t * dst_len) +s32 _L10nConvertStr(s32 src_code, const void *src, size_t * src_len, s32 dst_code, void *dst, size_t * dst_len) { - unsigned int srcCode = 0, dstCode = 0; //OEM code pages + u32 srcCode = 0, dstCode = 0; //OEM code pages bool src_page_converted = _L10nCodeParse(src_code, srcCode); //Check if code is in list. bool dst_page_converted = _L10nCodeParse(dst_code, dstCode); @@ -251,10 +267,10 @@ int _L10nConvertStr(int src_code, const void *src, size_t * src_len, int dst_cod } //This is the one used with iconv library for linux/mac. Also char->char. //I've tested the code with console apps using codeblocks. -int _L10nConvertStr(int src_code, const void* src, size_t * src_len, int dst_code, void * dst, size_t * dst_len) +s32 _L10nConvertStr(s32 src_code, const void* src, size_t * src_len, s32 dst_code, void * dst, size_t * dst_len) { std::string srcCode, dstCode; - int retValue = ConversionOK; + s32 retValue = ConversionOK; if ((_L10nCodeParse(src_code, srcCode)) && (_L10nCodeParse(dst_code, dstCode))) { iconv_t ict = iconv_open(srcCode.c_str(), dstCode.c_str()); @@ -281,13 +297,13 @@ int _L10nConvertStr(int src_code, const void* src, size_t * src_len, int dst_cod #endif //TODO: Check the code in emulation. If support for UTF8/UTF16/UTF32/UCS2/UCS4 should use wider chars.. awful. -int L10nConvertStr(int src_code, vm::ptr src, vm::ptr src_len, int dst_code, vm::ptr dst, vm::ptr dst_len) +s32 L10nConvertStr(s32 src_code, vm::ptr src, vm::ptr src_len, s32 dst_code, vm::ptr dst, vm::ptr dst_len) { cellL10n.Error("L10nConvertStr(src_code=%d, srca_addr=0x%x, src_len_addr=0x%x, dst_code=%d, dst_addr=0x%x, dst_len_addr=0x%x)", src_code, src.addr(), src_len.addr(), dst_code, dst.addr(), dst_len.addr()); //cellL10n.Todo("L10nConvertStr: 1st char at dst: 0x%x", *((char*)src.get_ptr())); #ifdef _MSC_VER - unsigned int srcCode = 0, dstCode = 0; //OEM code pages + u32 srcCode = 0, dstCode = 0; //OEM code pages bool src_page_converted = _L10nCodeParse(src_code, srcCode); //Check if code is in list. bool dst_page_converted = _L10nCodeParse(dst_code, dstCode); @@ -308,7 +324,7 @@ int L10nConvertStr(int src_code, vm::ptr src, vm::ptr src_len, return ConversionOK; #else std::string srcCode, dstCode; - int retValue = ConversionOK; + s32 retValue = ConversionOK; if ((_L10nCodeParse(src_code, srcCode)) && (_L10nCodeParse(dst_code, dstCode))) { iconv_t ict = iconv_open(srcCode.c_str(), dstCode.c_str()); @@ -490,7 +506,7 @@ Module cellL10n("cellL10n", []() // REG_FUNC(cellL10n, UTF8stoHZs); // REG_FUNC(cellL10n, eucjp2kuten); // REG_FUNC(cellL10n, UTF8toBIG5); - // REG_FUNC(cellL10n, UTF16stoUTF8s); + REG_FUNC(cellL10n, UTF16stoUTF8s); // REG_FUNC(cellL10n, JISstoUCS2s); // REG_FUNC(cellL10n, GB18030toUTF8); // REG_FUNC(cellL10n, UTF8toSJIS); diff --git a/rpcs3/Emu/SysCalls/Modules/cellL10n.h b/rpcs3/Emu/SysCalls/Modules/cellL10n.h index 512d2a4bcf..74a8b6cec9 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellL10n.h +++ b/rpcs3/Emu/SysCalls/Modules/cellL10n.h @@ -1,9 +1,4 @@ -#include "stdafx.h" - -// Requires GCC 4.10 apparently.. -#ifdef _MSC_VER -#include -#endif +#pragma once // L10nResult enum diff --git a/rpcs3/Emu/SysCalls/Modules/cellPng.h b/rpcs3/Emu/SysCalls/Modules/cellPng.h index 79c88a83fe..3237fcd869 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellPng.h +++ b/rpcs3/Emu/SysCalls/Modules/cellPng.h @@ -162,7 +162,7 @@ struct CellPngPCAL be_t equationType; be_t numberOfParameters; vm::bptr unitName; - vm::bptr parameter; + vm::bpptr parameter; }; struct CellPngUnknownChunk diff --git a/rpcs3/Emu/SysCalls/Modules/cellPngDec.cpp b/rpcs3/Emu/SysCalls/Modules/cellPngDec.cpp index 58eab5a692..c6180006a1 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellPngDec.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellPngDec.cpp @@ -18,7 +18,7 @@ extern "C" extern Module cellPngDec; s32 pngDecCreate( - vm::ptr mainHandle, + vm::ptr mainHandle, vm::ptr param, vm::ptr ext = vm::null) { @@ -41,7 +41,7 @@ s32 pngDecCreate( } // use virtual memory address as a handle - *mainHandle = dec.addr(); + *mainHandle = dec; return CELL_OK; } @@ -58,7 +58,7 @@ s32 pngDecDestroy(CellPngDecMainHandle dec) s32 pngDecOpen( CellPngDecMainHandle dec, - vm::ptr subHandle, + vm::ptr subHandle, vm::ptr src, vm::ptr openInfo, vm::ptr cb = vm::null, @@ -105,7 +105,7 @@ s32 pngDecOpen( } // use virtual memory address as a handle - *subHandle = stream.addr(); + *subHandle = stream; // set memory info openInfo->initSpaceAllocated = 4096; @@ -366,7 +366,10 @@ s32 pngDecodeData( return CELL_OK; } -s32 cellPngDecCreate(vm::ptr mainHandle, vm::ptr threadInParam, vm::ptr threadOutParam) +s32 cellPngDecCreate( + vm::ptr mainHandle, + vm::ptr threadInParam, + vm::ptr threadOutParam) { cellPngDec.Warning("cellPngDecCreate(mainHandle=**0x%x, threadInParam=*0x%x, threadOutParam=*0x%x)", mainHandle, threadInParam, threadOutParam); @@ -380,7 +383,7 @@ s32 cellPngDecCreate(vm::ptr mainHandle, vm::ptr mainHandle, + vm::ptr mainHandle, vm::ptr threadInParam, vm::ptr threadOutParam, vm::ptr extThreadInParam, @@ -410,7 +413,7 @@ s32 cellPngDecDestroy(CellPngDecMainHandle mainHandle) s32 cellPngDecOpen( CellPngDecMainHandle mainHandle, - vm::ptr subHandle, + vm::ptr subHandle, vm::ptr src, vm::ptr openInfo) { @@ -422,7 +425,7 @@ s32 cellPngDecOpen( s32 cellPngDecExtOpen( CellPngDecMainHandle mainHandle, - vm::ptr subHandle, + vm::ptr subHandle, vm::ptr src, vm::ptr openInfo, vm::ptr cbCtrlStrm, @@ -514,7 +517,7 @@ s32 cellPngDecExtDecodeData( s32 cellPngDecGetUnknownChunks( CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, - vm::ptr> unknownChunk, + vm::pptr unknownChunk, vm::ptr unknownChunkNumber) { UNIMPLEMENTED_FUNC(cellPngDec); @@ -615,7 +618,7 @@ s32 cellPngDecGetTextChunk( CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr textInfoNum, - vm::ptr> textInfo) + vm::pptr textInfo) { UNIMPLEMENTED_FUNC(cellPngDec); return CELL_OK; diff --git a/rpcs3/Emu/SysCalls/Modules/cellPngDec.h b/rpcs3/Emu/SysCalls/Modules/cellPngDec.h index 361d83fe07..037019fe65 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellPngDec.h +++ b/rpcs3/Emu/SysCalls/Modules/cellPngDec.h @@ -6,12 +6,6 @@ enum : u32 PNGDEC_CODEC_VERSION = 0x00420000, }; -struct PngDecoder; -struct PngStream; - -typedef vm::ptr CellPngDecMainHandle; -typedef vm::ptr CellPngDecSubHandle; - // Return Codes enum { @@ -28,7 +22,7 @@ enum }; // Consts -enum CellPngDecColorSpace : u32 +enum CellPngDecColorSpace : s32 { CELL_PNGDEC_GRAYSCALE = 1, CELL_PNGDEC_RGB = 2, @@ -38,62 +32,66 @@ enum CellPngDecColorSpace : u32 CELL_PNGDEC_ARGB = 20, }; -enum CellPngDecSpuThreadEna : u32 +enum CellPngDecSpuThreadEna : s32 { CELL_PNGDEC_SPU_THREAD_DISABLE = 0, CELL_PNGDEC_SPU_THREAD_ENABLE = 1, }; -enum CellPngDecStreamSrcSel : u32 +enum CellPngDecStreamSrcSel : s32 { CELL_PNGDEC_FILE = 0, CELL_PNGDEC_BUFFER = 1, }; -enum CellPngDecInterlaceMode : u32 +enum CellPngDecInterlaceMode : s32 { CELL_PNGDEC_NO_INTERLACE = 0, CELL_PNGDEC_ADAM7_INTERLACE = 1, }; -enum CellPngDecOutputMode : u32 +enum CellPngDecOutputMode : s32 { CELL_PNGDEC_TOP_TO_BOTTOM = 0, CELL_PNGDEC_BOTTOM_TO_TOP = 1, }; -enum CellPngDecPackFlag : u32 +enum CellPngDecPackFlag : s32 { CELL_PNGDEC_1BYTE_PER_NPIXEL = 0, CELL_PNGDEC_1BYTE_PER_1PIXEL = 1, }; -enum CellPngDecAlphaSelect : u32 +enum CellPngDecAlphaSelect : s32 { CELL_PNGDEC_STREAM_ALPHA = 0, CELL_PNGDEC_FIX_ALPHA = 1, }; -enum CellPngDecCommand : u32 +enum CellPngDecCommand : s32 { CELL_PNGDEC_CONTINUE = 0, CELL_PNGDEC_STOP = 1, }; -enum CellPngDecDecodeStatus : u32 +enum CellPngDecDecodeStatus : s32 { CELL_PNGDEC_DEC_STATUS_FINISH = 0, CELL_PNGDEC_DEC_STATUS_STOP = 1, }; -// Callbacks -typedef vm::ptr(CellPngDecCbControlMalloc)(u32 size, vm::ptr cbCtrlMallocArg); -typedef s32(CellPngDecCbControlFree)(vm::ptr ptr, vm::ptr cbCtrlFreeArg); +// Handles +using CellPngDecMainHandle = vm::ptr; +using CellPngDecSubHandle = vm::ptr; + +// Callbacks for memory management +using CellPngDecCbControlMalloc = func_def(u32 size, vm::ptr cbCtrlMallocArg)>; +using CellPngDecCbControlFree = func_def ptr, vm::ptr cbCtrlFreeArg)>; // Structs struct CellPngDecThreadInParam { - be_t spuThreadEnable; + be_t spuThreadEnable; // CellPngDecSpuThreadEna be_t ppuThreadPriority; be_t spuThreadPriority; vm::bptr cbCtrlMallocFunc; @@ -104,7 +102,7 @@ struct CellPngDecThreadInParam struct CellPngDecExtThreadInParam { - be_t spurs_addr; // it could be vm::bptr, but nobody will use SPURS in HLE implementation + vm::bptr spurs; u8 priority[8]; be_t maxContention; }; @@ -121,13 +119,13 @@ struct CellPngDecExtThreadOutParam struct CellPngDecSrc { - be_t srcSelect; + be_t srcSelect; // CellPngDecStreamSrcSel vm::bptr fileName; be_t fileOffset; be_t fileSize; vm::bptr streamPtr; be_t streamSize; - be_t spuThreadEnable; + be_t spuThreadEnable; // CellGifDecSpuThreadEna }; struct CellPngDecOpnInfo @@ -140,20 +138,20 @@ struct CellPngDecInfo be_t imageWidth; be_t imageHeight; be_t numComponents; - be_t colorSpace; + be_t colorSpace; // CellPngDecColorSpace be_t bitDepth; - be_t interlaceMethod; + be_t interlaceMethod; // CellPngDecInterlaceMode be_t chunkInformation; }; struct CellPngDecInParam { - vm::bptr commandPtr; - be_t outputMode; - be_t outputColorSpace; + vm::bptr commandPtr; // CellPngDecCommand + be_t outputMode; // CellPngDecOutputMode + be_t outputColorSpace; // CellPngDecColorSpace be_t outputBitDepth; - be_t outputPackFlag; - be_t outputAlphaSelect; + be_t outputPackFlag; // CellPngDecPackFlag + be_t outputAlphaSelect; // CellPngDecAlphaSelect be_t outputColorAlpha; }; @@ -164,8 +162,8 @@ struct CellPngDecOutParam be_t outputHeight; be_t outputComponents; be_t outputBitDepth; - be_t outputMode; - be_t outputColorSpace; + be_t outputMode; // CellPngDecOutputMode + be_t outputColorSpace; // CellPngDecOutputMode be_t useMemorySpace; }; @@ -179,99 +177,22 @@ struct CellPngDecDataOutInfo be_t chunkInformation; be_t numText; be_t numUnknownChunk; - be_t status; + be_t status; // CellPngDecDecodeStatus }; -// Functions -s32 cellPngDecCreate(vm::ptr mainHandle, vm::ptr threadInParam, vm::ptr threadOutParam); - -s32 cellPngDecExtCreate( - vm::ptr mainHandle, - vm::ptr threadInParam, - vm::ptr threadOutParam, - vm::ptr extThreadInParam, - vm::ptr extThreadOutParam); - -s32 cellPngDecOpen( - CellPngDecMainHandle mainHandle, - vm::ptr subHandle, - vm::ptr src, - vm::ptr openInfo); - -s32 cellPngDecReadHeader(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr info); - -s32 cellPngDecSetParameter( - CellPngDecMainHandle mainHandle, - CellPngDecSubHandle subHandle, - vm::ptr inParam, - vm::ptr outParam); - -s32 cellPngDecDecodeData( - CellPngDecMainHandle mainHandle, - CellPngDecSubHandle subHandle, - vm::ptr data, - vm::ptr dataCtrlParam, - vm::ptr dataOutInfo); - -s32 cellPngDecClose(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle); - -s32 cellPngDecDestroy(CellPngDecMainHandle mainHandle); - -s32 cellPngDecGetTextChunk( - CellPngDecMainHandle mainHandle, - CellPngDecSubHandle subHandle, - vm::ptr textInfoNum, - vm::ptr> textInfo); - -s32 cellPngDecGetPLTE(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr plte); - -s32 cellPngDecGetgAMA(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr gama); - -s32 cellPngDecGetsRGB(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr srgb); - -s32 cellPngDecGetiCCP(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr iccp); - -s32 cellPngDecGetsBIT(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr sbit); - -s32 cellPngDecGettRNS(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr trns); - -s32 cellPngDecGethIST(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr hist); - -s32 cellPngDecGettIME(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr time); - -s32 cellPngDecGetbKGD(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr bkgd); - -s32 cellPngDecGetsPLT(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr splt); - -s32 cellPngDecGetoFFs(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr offs); - -s32 cellPngDecGetpHYs(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr phys); - -s32 cellPngDecGetsCAL(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr scal); - -s32 cellPngDecGetcHRM(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr chrm); - -s32 cellPngDecGetpCAL(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr pcal); - -s32 cellPngDecGetUnknownChunks( - CellPngDecMainHandle mainHandle, - CellPngDecSubHandle subHandle, - vm::ptr> unknownChunk, - vm::ptr unknownChunkNumber); - - -enum CellPngDecBufferMode +// Defines for decoding partial streams +enum CellPngDecBufferMode : s32 { CELL_PNGDEC_LINE_MODE = 1, }; -enum CellPngDecSpuMode +enum CellPngDecSpuMode : s32 { CELL_PNGDEC_RECEIVE_EVENT = 0, CELL_PNGDEC_TRYRECEIVE_EVENT = 1, }; -// Structs +// Structs for decoding partial streams struct CellPngDecStrmInfo { be_t decodedStrmSize; @@ -283,8 +204,6 @@ struct CellPngDecStrmParam be_t strmSize; }; -typedef s32(CellPngDecCbControlStream)(vm::ptr strmInfo, vm::ptr strmParam, vm::ptr cbCtrlStrmArg); - struct CellPngDecDispInfo { be_t outputFrameWidthByte; @@ -305,21 +224,11 @@ struct CellPngDecDispParam vm::bptr nextOutputImage; }; -// Callback -typedef s32(CellPngDecCbControlDisp)(vm::ptr dispInfo, vm::ptr dispParam, vm::ptr cbCtrlDispArg); - -// Structs struct CellPngDecOpnParam { be_t selectChunk; }; -struct CellPngDecCbCtrlStrm -{ - vm::bptr cbCtrlStrmFunc; - be_t> cbCtrlStrmArg; -}; - struct CellPngDecExtInfo { be_t reserved; @@ -327,9 +236,9 @@ struct CellPngDecExtInfo struct CellPngDecExtInParam { - be_t bufferMode; + be_t bufferMode; // CellPngDecBufferMode be_t outputCounts; - be_t spuMode; + be_t spuMode; // CellPngDecSpuMode }; struct CellPngDecExtOutParam @@ -338,44 +247,22 @@ struct CellPngDecExtOutParam be_t outputHeight; }; +// Callbacks for decoding partial streams +using CellPngDecCbControlStream = func_def strmInfo, vm::ptr strmParam, vm::ptr cbCtrlStrmArg)>; +using CellPngDecCbControlDisp = func_def dispInfo, vm::ptr dispParam, vm::ptr cbCtrlDispArg)>; + +struct CellPngDecCbCtrlStrm +{ + vm::bptr cbCtrlStrmFunc; + vm::bptr cbCtrlStrmArg; +}; + struct CellPngDecCbCtrlDisp { vm::bptr cbCtrlDispFunc; - be_t> cbCtrlDispArg; + vm::bptr cbCtrlDispArg; }; -// Functions -s32 cellPngDecExtOpen( - CellPngDecMainHandle mainHandle, - vm::ptr subHandle, - vm::ptr src, - vm::ptr openInfo, - vm::ptr cbCtrlStrm, - vm::ptr opnParam); - -s32 cellPngDecExtReadHeader( - CellPngDecMainHandle mainHandle, - CellPngDecSubHandle subHandle, - vm::ptr info, - vm::ptr extInfo); - -s32 cellPngDecExtSetParameter( - CellPngDecMainHandle mainHandle, - CellPngDecSubHandle subHandle, - vm::ptr inParam, - vm::ptr outParam, - vm::ptr extInParam, - vm::ptr extOutParam); - -s32 cellPngDecExtDecodeData( - CellPngDecMainHandle mainHandle, - CellPngDecSubHandle subHandle, - vm::ptr data, - vm::ptr dataCtrlParam, - vm::ptr dataOutInfo, - vm::ptr cbCtrlDisp, - vm::ptr dispParam); - // Custom structs struct PngDecoder { @@ -398,4 +285,4 @@ struct PngStream CellPngDecStrmInfo streamInfo; CellPngDecStrmParam streamParam; -}; \ No newline at end of file +}; diff --git a/rpcs3/Emu/SysCalls/Modules/cellSearch.h b/rpcs3/Emu/SysCalls/Modules/cellSearch.h index 835bea7e9d..8c61d51018 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellSearch.h +++ b/rpcs3/Emu/SysCalls/Modules/cellSearch.h @@ -24,8 +24,6 @@ enum CELL_SEARCH_ERROR_GENERIC = 0x8002C8FF, }; -typedef be_t CellSearchId; - // Constants enum { @@ -173,7 +171,7 @@ struct CellSearchContentId struct CellSearchResultParam { - be_t searchId; + be_t searchId; be_t resultNum; }; @@ -271,7 +269,7 @@ struct CellSearchVideoSceneInfo be_t sceneType; be_t startTime_ms; be_t endTime_ms; - be_t videoId; + CellSearchContentId videoId; char title[CELL_SEARCH_TITLE_LEN_MAX + 1]; char reserved[3]; char tags[CELL_SEARCH_TAG_NUM_MAX][CELL_SEARCH_TAG_LEN_MAX]; diff --git a/rpcs3/Emu/SysCalls/Modules/cellSpurs.cpp b/rpcs3/Emu/SysCalls/Modules/cellSpurs.cpp index 4f95d79c20..9f96909219 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellSpurs.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellSpurs.cpp @@ -1263,7 +1263,7 @@ s32 _cellSpursWorkloadFlagReceiver(vm::ptr spurs, u32 wid, u32 is_set return CELL_OK; } -s32 cellSpursGetWorkloadFlag(vm::ptr spurs, vm::ptr> flag) +s32 cellSpursGetWorkloadFlag(vm::ptr spurs, vm::pptr flag) { cellSpurs.Warning("%s(spurs_addr=0x%x, flag_addr=0x%x)", __FUNCTION__, spurs.addr(), flag.addr()); @@ -2736,7 +2736,7 @@ s32 cellSpursTasksetSetExceptionEventHandler(vm::ptr taskset, return CELL_SPURS_TASK_ERROR_INVAL; } - if (taskset->m.exception_handler != 0) + if (taskset->m.exception_handler) { return CELL_SPURS_TASK_ERROR_BUSY; } @@ -2996,7 +2996,7 @@ s32 spursTraceInitialize(vm::ptr spurs, vm::ptr b return CELL_SPURS_CORE_ERROR_INVAL; } - if (spurs->m.traceBuffer != 0) + if (spurs->m.traceBuffer) { return CELL_SPURS_CORE_ERROR_STAT; } diff --git a/rpcs3/Emu/SysCalls/Modules/cellSpurs.h b/rpcs3/Emu/SysCalls/Modules/cellSpurs.h index fb84c1f541..8a049fc7cf 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellSpurs.h +++ b/rpcs3/Emu/SysCalls/Modules/cellSpurs.h @@ -388,8 +388,8 @@ struct CellSpurs u8 unk0[0x20]; // 0x00 - SPU exceptionh handler 0x08 - SPU exception handler args be_t sem; // 0x20 u8 unk1[0x8]; - vm::bptr hook; // 0x30 - vm::bptr hookArg; // 0x38 + vm::bptr hook; // 0x30 + vm::bptr hookArg; // 0x38 u8 unk2[0x40]; }; @@ -409,7 +409,7 @@ struct CellSpurs struct WorkloadInfo { - vm::bptr addr; // Address of the executable + vm::bptr addr; // Address of the executable be_t arg; // spu argument be_t size; atomic_be_t uniqueId; // The unique id is the same for all workloads with the same addr @@ -423,8 +423,8 @@ struct CellSpurs { static const uint size = 0x10; - vm::bptr nameClass; - vm::bptr nameInstance; + vm::bptr nameClass; + vm::bptr nameInstance; }; union @@ -475,7 +475,7 @@ struct CellSpurs u8 wklStatus2[0x10]; // 0xE0 u8 wklEvent2[0x10]; // 0xF0 _sub_str1 wklF1[0x10]; // 0x100 - vm::bptr traceBuffer; // 0x900 + vm::bptr traceBuffer; // 0x900 be_t traceStartIndex[6]; // 0x908 u8 unknown7[0x948 - 0x920]; // 0x920 be_t traceDataSize; // 0x948 @@ -641,7 +641,7 @@ struct CellSpursTaskset struct TaskInfo { CellSpursTaskArgument args; // 0x00 - vm::bptr elf_addr; // 0x10 + vm::bptr elf_addr; // 0x10 be_t context_save_storage_and_alloc_ls_blocks; // 0x18 This is (context_save_storage_addr | allocated_ls_blocks) CellSpursTaskLsPattern ls_pattern; // 0x20 }; @@ -662,7 +662,7 @@ struct CellSpursTaskset be_t enabled; // 0x30 be_t signalled; // 0x40 be_t waiting; // 0x50 - vm::bptr spurs; // 0x60 + vm::bptr spurs; // 0x60 be_t args; // 0x68 u8 enable_clear_ls; // 0x70 u8 x71; // 0x71 @@ -671,8 +671,8 @@ struct CellSpursTaskset be_t wid; // 0x74 be_t x78; // 0x78 TaskInfo task_info[128]; // 0x80 - vm::bptr exception_handler; // 0x1880 - vm::bptr exception_handler_arg; // 0x1888 + vm::bptr exception_handler; // 0x1880 + vm::bptr exception_handler_arg; // 0x1888 be_t size; // 0x1890 u32 unk2; // 0x1894 u32 event_flag_id1; // 0x1898 @@ -750,8 +750,8 @@ struct CellSpursTaskset2 struct TaskInfo { CellSpursTaskArgument args; - vm::bptr elf_addr; - vm::bptr context_save_storage; // This is (context_save_storage_addr | allocated_ls_blocks) + vm::bptr elf_addr; + vm::bptr context_save_storage; // This is (context_save_storage_addr | allocated_ls_blocks) CellSpursTaskLsPattern ls_pattern; }; @@ -771,7 +771,7 @@ struct CellSpursTaskset2 be_t enabled_set[4]; // 0x30 be_t signal_received_set[4]; // 0x40 be_t waiting_set[4]; // 0x50 - vm::bptr spurs; // 0x60 + vm::bptr spurs; // 0x60 be_t args; // 0x68 u8 enable_clear_ls; // 0x70 u8 x71; // 0x71 @@ -780,8 +780,8 @@ struct CellSpursTaskset2 be_t wid; // 0x74 be_t x78; // 0x78 TaskInfo task_info[128]; // 0x80 - vm::bptr exception_handler; // 0x1880 - vm::bptr exception_handler_arg; // 0x1888 + vm::bptr exception_handler; // 0x1880 + vm::bptr exception_handler_arg; // 0x1888 be_t size; // 0x1890 u32 unk2; // 0x1894 u32 event_flag_id1; // 0x1898 @@ -872,8 +872,8 @@ struct CellSpursTaskInfo const be_t eaElf_addr; //void *eaElf const be_t eaContext_addr; //void *eaContext be_t sizeContext; - be_t state; - be_t hasSignal; + u8 state; + u8 hasSignal; const be_t CellSpursTaskExitCode_addr; u8 guid[8]; //be_t reserved[]; @@ -895,10 +895,10 @@ struct SpursKernelContext u8 wklLocPendingContention[0x10]; // 0x190 u8 priority[0x10]; // 0x1A0 u8 x1B0[0x10]; // 0x1B0 - vm::bptr spurs; // 0x1C0 + vm::bptr spurs; // 0x1C0 be_t spuNum; // 0x1C8 be_t dmaTagId; // 0x1CC - vm::bptr wklCurrentAddr; // 0x1D0 + vm::bptr wklCurrentAddr; // 0x1D0 be_t wklCurrentUniqueId; // 0x1D8 be_t wklCurrentId; // 0x1DC be_t exitToKernelAddr; // 0x1E0 @@ -932,7 +932,7 @@ struct SpursTasksetContext u8 tempAreaTaskset[0x80]; // 0x2700 u8 tempAreaTaskInfo[0x30]; // 0x2780 be_t x27B0; // 0x27B0 - vm::bptr taskset; // 0x27B8 + vm::bptr taskset; // 0x27B8 be_t kernelMgmtAddr; // 0x27C0 be_t syscallAddr; // 0x27C4 be_t x27C8; // 0x27C8 diff --git a/rpcs3/Emu/SysCalls/Modules/cellSync.cpp b/rpcs3/Emu/SysCalls/Modules/cellSync.cpp index f3e233a314..db6ec1be46 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellSync.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellSync.cpp @@ -1811,7 +1811,7 @@ s32 cellSyncLFQueueDepth(vm::ptr queue, vm::ptr depth) return CELL_OK; } -s32 _cellSyncLFQueueGetSignalAddress(vm::ptr queue, vm::ptr> ppSignal) +s32 _cellSyncLFQueueGetSignalAddress(vm::ptr queue, vm::pptr ppSignal) { cellSync.Log("_cellSyncLFQueueGetSignalAddress(queue=*0x%x, ppSignal=**0x%x)", queue, ppSignal); diff --git a/rpcs3/Emu/SysCalls/Modules/cellSync.h b/rpcs3/Emu/SysCalls/Modules/cellSync.h index c291d608c1..d5c9430752 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellSync.h +++ b/rpcs3/Emu/SysCalls/Modules/cellSync.h @@ -71,7 +71,7 @@ struct CellSyncRwm atomic_be_t data; be_t m_size; - vm::bptr m_buffer; + vm::bptr m_buffer; }; static_assert(sizeof(CellSyncRwm) == 16, "CellSyncRwm: wrong size"); @@ -87,7 +87,7 @@ struct CellSyncQueue atomic_be_t data; be_t m_size; be_t m_depth; - vm::bptr m_buffer; + vm::bptr m_buffer; be_t reserved; }; @@ -155,7 +155,7 @@ struct CellSyncLFQueue be_t m_size; // 0x10 be_t m_depth; // 0x14 - vm::bptr m_buffer; // 0x18 + vm::bptr m_buffer; // 0x18 u8 m_bs[4]; // 0x20 be_t m_direction; // 0x24 be_t m_v1; // 0x28 @@ -164,7 +164,7 @@ struct CellSyncLFQueue be_t m_hs1[15]; // 0x32 atomic_be_t pop2; // 0x50 be_t m_hs2[15]; // 0x52 - vm::bptr m_eaSignal; // 0x70 + vm::bptr m_eaSignal; // 0x70 be_t m_v2; // 0x78 be_t m_eq_id; // 0x7C diff --git a/rpcs3/Emu/SysCalls/Modules/cellVdec.cpp b/rpcs3/Emu/SysCalls/Modules/cellVdec.cpp index 665f8da71b..8315babc45 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellVdec.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellVdec.cpp @@ -795,7 +795,7 @@ s32 _nid_a21aa896(PPUThread& CPU, u32 handle, vm::ptr return cellVdecGetPicture(handle, format, outBuff); } -s32 cellVdecGetPicItem(u32 handle, vm::ptr> picItem) +s32 cellVdecGetPicItem(u32 handle, vm::pptr picItem) { cellVdec.Log("cellVdecGetPicItem(handle=0x%x, picItem=**0x%x)", handle, picItem); diff --git a/rpcs3/Emu/SysCalls/Modules/libmixer.cpp b/rpcs3/Emu/SysCalls/Modules/libmixer.cpp index ca2bd68e5d..69eb7ea158 100644 --- a/rpcs3/Emu/SysCalls/Modules/libmixer.cpp +++ b/rpcs3/Emu/SysCalls/Modules/libmixer.cpp @@ -368,7 +368,7 @@ int cellSurMixerCreate(vm::ptr config) for (auto& p : ssp) if (p.m_active && p.m_created) { - auto v = vm::lptrl::make(p.m_addr); // 16-bit LE audio data + auto v = vm::ptrl::make(p.m_addr); // 16-bit LE audio data float left = 0.0f; float right = 0.0f; float speed = fabs(p.m_speed); diff --git a/rpcs3/Emu/SysCalls/Modules/sceNpClans.cpp b/rpcs3/Emu/SysCalls/Modules/sceNpClans.cpp index d47cfb7955..3ea66374d1 100644 --- a/rpcs3/Emu/SysCalls/Modules/sceNpClans.cpp +++ b/rpcs3/Emu/SysCalls/Modules/sceNpClans.cpp @@ -377,7 +377,7 @@ int sceNpClansPostChallenge(vm::ptr handle, u32 clanId, if (!sceNpClansInstance.m_bSceNpClansInitialized) return SCE_NP_CLANS_ERROR_NOT_INITIALIZED; - if (data != 0) + if (data) return SCE_NP_CLANS_ERROR_NOT_SUPPORTED; //todo diff --git a/rpcs3/Emu/SysCalls/Modules/sceNpClans.h b/rpcs3/Emu/SysCalls/Modules/sceNpClans.h index d870d5bd07..838458c071 100644 --- a/rpcs3/Emu/SysCalls/Modules/sceNpClans.h +++ b/rpcs3/Emu/SysCalls/Modules/sceNpClans.h @@ -108,8 +108,7 @@ enum }; // Request handle for clan API -struct SceNpClansRequest; -typedef vm::ptr SceNpClansRequestHandle; +using SceNpClansRequestHandle = vm::ptr; // Paging request structure struct SceNpClansPagingRequest diff --git a/rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp b/rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp index b356d14ada..b916a50550 100644 --- a/rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp +++ b/rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp @@ -897,9 +897,20 @@ s32 sys_raw_spu_image_load(s32 id, vm::ptr img) sysPrxForUser.Warning("sys_raw_spu_image_load(id=%d, img=*0x%x)", id, img); // TODO: use segment info + + const auto stamp0 = get_system_time(); + memcpy(vm::get_ptr(RAW_SPU_BASE_ADDR + RAW_SPU_OFFSET * id), vm::get_ptr(img->addr), 256 * 1024); + + const auto stamp1 = get_system_time(); + vm::write32(RAW_SPU_BASE_ADDR + RAW_SPU_OFFSET * id + RAW_SPU_PROB_OFFSET + SPU_NPC_offs, img->entry_point | be_t::make(1)); + const auto stamp2 = get_system_time(); + + LOG_ERROR(GENERAL, "memcpy() latency: %lldus", (stamp1 - stamp0)); + LOG_ERROR(GENERAL, "MMIO latency: %lldus", (stamp2 - stamp1)); + return CELL_OK; } diff --git a/rpcs3/Emu/SysCalls/SC_FUNC.h b/rpcs3/Emu/SysCalls/SC_FUNC.h index 898d1f2220..7ffde175f1 100644 --- a/rpcs3/Emu/SysCalls/SC_FUNC.h +++ b/rpcs3/Emu/SysCalls/SC_FUNC.h @@ -136,7 +136,7 @@ namespace ppu_func_detail template force_inline RT call(F f, Tuple && t) { - typedef typename std::decay::type ttype; + using ttype = std::decay_t; return ppu_func_detail::call_impl::value, std::tuple_size::value>::call(f, std::forward(t)); } diff --git a/rpcs3/Emu/SysCalls/lv2/sys_process.cpp b/rpcs3/Emu/SysCalls/lv2/sys_process.cpp index c552e3aa45..1effa3cd6c 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_process.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_process.cpp @@ -80,7 +80,7 @@ void sys_game_process_exitspawn(vm::ptr path, u32 argv_addr, u32 env if (argv_addr) { - auto argvp = vm::ptr>::make(argv_addr); + auto argvp = vm::pptr::make(argv_addr); while (argvp && *argvp) { argv.push_back(argvp[0].get_ptr()); @@ -94,7 +94,7 @@ void sys_game_process_exitspawn(vm::ptr path, u32 argv_addr, u32 env if (envp_addr) { - auto envp = vm::ptr>::make(envp_addr); + auto envp = vm::pptr::make(envp_addr); while (envp && *envp) { env.push_back(envp[0].get_ptr()); @@ -154,7 +154,7 @@ void sys_game_process_exitspawn2(vm::ptr path, u32 argv_addr, u32 en if (argv_addr) { - auto argvp = vm::ptr>::make(argv_addr); + auto argvp = vm::pptr::make(argv_addr); while (argvp && *argvp) { argv.push_back(argvp[0].get_ptr()); @@ -169,7 +169,7 @@ void sys_game_process_exitspawn2(vm::ptr path, u32 argv_addr, u32 en if (envp_addr) { - auto envp = vm::ptr>::make(envp_addr); + auto envp = vm::pptr::make(envp_addr); while (envp && *envp) { env.push_back(envp[0].get_ptr()); diff --git a/rpcs3/Emu/SysCalls/lv2/sys_prx.cpp b/rpcs3/Emu/SysCalls/lv2/sys_prx.cpp index d89ec25a9b..377e40ceff 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_prx.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_prx.cpp @@ -140,7 +140,7 @@ s32 sys_prx_load_module(vm::ptr path, u64 flags, vm::ptr path_list, u64 flags, vm::ptr pOpt, vm::ptr id_list) +s32 sys_prx_load_module_list(s32 count, vm::pptr path_list, u64 flags, vm::ptr pOpt, vm::ptr id_list) { sys_prx.Warning("sys_prx_load_module_list(count=%d, path_list=*0x%x, flags=0x%llx, pOpt=*0x%x, id_list=*0x%x)", count, path_list, flags, pOpt, id_list); diff --git a/rpcs3/Emu/SysCalls/lv2/sys_prx.h b/rpcs3/Emu/SysCalls/lv2/sys_prx.h index 215aa3a4a6..d0b329cfe6 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_prx.h +++ b/rpcs3/Emu/SysCalls/lv2/sys_prx.h @@ -87,7 +87,7 @@ struct sys_prx_relocation_info_t u8 index_value; u8 index_addr; be_t type; - vm::bptr ptr; + vm::bptr ptr; }; @@ -102,14 +102,14 @@ struct sys_prx_start_module_option_t { be_t size; be_t put; - vm::bptr argv), 1, u64> entry_point; + vm::bptr argv), u64> entry_point; }; struct sys_prx_stop_module_option_t { be_t size; be_t put; - vm::bptr argv), 1, u64> entry_point; + vm::bptr argv), u64> entry_point; }; struct sys_prx_unload_module_option_t @@ -135,7 +135,7 @@ REG_ID_TYPE(lv2_prx_t, 0x23); // SYS_PRX_OBJECT // SysCalls s32 sys_prx_load_module(vm::ptr path, u64 flags, vm::ptr pOpt); -s32 sys_prx_load_module_list(s32 count, vm::ptr path_list, u64 flags, vm::ptr pOpt, vm::ptr id_list); +s32 sys_prx_load_module_list(s32 count, vm::pptr path_list, u64 flags, vm::ptr pOpt, vm::ptr id_list); s32 sys_prx_load_module_on_memcontainer(); s32 sys_prx_load_module_by_fd(); s32 sys_prx_load_module_on_memcontainer_by_fd(); diff --git a/rpcs3/Loader/ELF64.h b/rpcs3/Loader/ELF64.h index baa634eb95..8580c5be69 100644 --- a/rpcs3/Loader/ELF64.h +++ b/rpcs3/Loader/ELF64.h @@ -40,8 +40,8 @@ namespace loader be_t p_type; be_t p_flags; be_t p_offset; - bptr p_vaddr; - bptr p_paddr; + bptr p_vaddr; + bptr p_paddr; be_t p_filesz; be_t p_memsz; be_t p_align; @@ -52,7 +52,7 @@ namespace loader be_t sh_name; be_t sh_type; be_t sh_flags; - bptr sh_addr; + bptr sh_addr; be_t sh_offset; be_t sh_size; be_t sh_link; diff --git a/rpcs3/stdafx.h b/rpcs3/stdafx.h index 0b3601d755..1b730b9109 100644 --- a/rpcs3/stdafx.h +++ b/rpcs3/stdafx.h @@ -57,6 +57,18 @@ template force_inline T align(const T addr, int align) return (addr + (align - 1)) & ~(align - 1); } +template struct sizeof32_t +{ + static const u32 value = static_cast(sizeof(T)); + + static_assert(value == sizeof(T), "sizeof32() error: sizeof() is too big"); +}; + +// return 32 bit sizeof() to avoid widening/narrowing conversions with size_t +#define sizeof32(type) sizeof32_t::value + +template using func_def = T; // workaround for MSVC bug: `using X = func_def;` instead of `using X = void();` + #include "Utilities/BEType.h" #include "Utilities/StrFmt.h"