diff --git a/Utilities/BEType.h b/Utilities/BEType.h index 38d01a9952..b75b5291d3 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_t -{ - typedef u8 type; -}; - -template -struct be_storage_t +template struct be_storage { typedef u16 type; }; -template -struct be_storage_t +template struct be_storage { typedef u32 type; }; -template -struct be_storage_t +template struct be_storage { typedef u64 type; }; -template -struct be_storage_t +template struct be_storage { typedef u128 type; }; -template -class be_t -{ -public: - typedef typename std::remove_cv::type type; - typedef typename be_storage_t::type stype; +template using be_storage_t = typename be_storage::type; + +template +struct be_t +{ + using type = std::remove_cv_t; + using stype = be_storage_t; -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 operator std::enable_if_t::value, 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,40 @@ 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 +// to_be_t helper struct +template struct to_be { - 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; + using type = std::conditional_t::value || std::is_enum::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 = to_be_t::value; - typedef const typename to_be_t::type type; - typedef const typename to_be_t::forced_type 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 void type; - typedef void forced_type; + // move volatile qualifier + using type = volatile to_be_t>; }; -template -class to_be_t -{ -public: - static const bool value = false; - typedef u8 type; - typedef u8 forced_type; -}; - -template -class to_be_t -{ -public: - static const bool value = false; - typedef s8 type; - typedef s8 forced_type; -}; - -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 +810,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 +849,85 @@ 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 to_le +{ + using type = std::conditional_t::value || std::is_enum::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; +}; + +// 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> +{ + using type = T; +}; + +template struct to_ne> +{ + using type = 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/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/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..fc4e430bb6 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 @@ -197,8 +192,8 @@ public: // Helper definitions -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 using if_arithmetic_le_t = std::enable_if_t::value && std::is_arithmetic::value, le_t>; +template using if_arithmetic_be_t = std::enable_if_t::value && std::is_arithmetic::value, be_t>; template inline static if_arithmetic_le_t operator ++(_atomic_base>& left) { @@ -304,6 +299,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..11fe0307f4 100644 --- a/rpcs3/Emu/Memory/vm_ptr.h +++ b/rpcs3/Emu/Memory/vm_ptr.h @@ -10,7 +10,11 @@ namespace vm { AT m_addr; - typedef typename std::remove_cv::type type; + using type = T; + + 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)"); + static const u32 address_size = sizeof(AT); _ptr_base operator++ (int) @@ -51,10 +55,8 @@ namespace vm 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); } + _ptr_base operator + (to_ne_t count) const { return make(m_addr + count * address_size); } + _ptr_base operator - (to_ne_t 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; } @@ -66,23 +68,21 @@ namespace vm 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 + force_inline _ptr_base::value, to_be_t, AT>> 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; + return (_ptr_base::value, to_be_t, AT>>&)addr; } - force_inline _ptr_base::value, typename to_be_t::type, AT>::type> operator [](AT index) const + force_inline _ptr_base::value, to_be_t, AT>> 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; + return (_ptr_base::value, to_be_t, AT>>&)addr; } - template - operator _ptr_base() const + template operator _ptr_base() const { - AT2 addr = convert_le_be(m_addr); - return reinterpret_cast<_ptr_base&>(addr); + return{ convert_le_be(m_addr) }; } AT addr() const @@ -90,15 +90,14 @@ namespace vm return m_addr; } - template - void set(U&& value) + template void set(U&& value) { m_addr = convert_le_be(value); } - static _ptr_base make(const AT& addr) + template static _ptr_base make(const AT2& addr) { - return reinterpret_cast(addr); + return{ convert_le_be(addr) }; } _ptr_base& operator = (const _ptr_base& right) = default; @@ -108,10 +107,11 @@ namespace vm struct _ptr_base { AT m_addr; + + using type = T; 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() { @@ -161,22 +161,15 @@ namespace vm 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()))); } + _ptr_base operator + (to_ne_t count) const { return make(convert_le_be(convert_le_be(m_addr) +count * convert_le_be(data_size()))); } + _ptr_base operator - (to_ne_t 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 + force_inline T& operator [](to_ne_t index) const { return vm::get_ref(vm::cast(m_addr + data_size() * index)); } @@ -191,25 +184,22 @@ namespace vm 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(); } + + template operator _ptr_base() const + { + return{ convert_le_be(m_addr) }; + } AT addr() const { return m_addr; } - template - void set(U&& value) + template void set(U&& value) { m_addr = convert_le_be(value); } - template - operator _ptr_base() const - { - AT2 addr = convert_le_be(m_addr); - return reinterpret_cast<_ptr_base&>(addr); - } - T* get_ptr() const { return vm::get_ptr(vm::cast(m_addr)); @@ -220,9 +210,9 @@ namespace vm return vm::priv_ptr(vm::cast(m_addr)); } - static const _ptr_base make(const AT& addr) + template static _ptr_base make(const AT2& addr) { - return reinterpret_cast(addr); + return{ convert_le_be(addr) }; } _ptr_base& operator = (const _ptr_base& right) = default; @@ -269,23 +259,19 @@ namespace vm 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 + template operator _ptr_base() const { - AT2 addr = convert_le_be(m_addr); - return reinterpret_cast<_ptr_base&>(addr); + return{ convert_le_be(m_addr) }; } - template - operator _ptr_base() const + template operator _ptr_base() const { - AT2 addr = convert_le_be(m_addr); - return reinterpret_cast<_ptr_base&>(addr); + return{ convert_le_be(m_addr) }; } - static const _ptr_base make(const AT& addr) + template static _ptr_base make(const AT2& addr) { - return reinterpret_cast(addr); + return{ convert_le_be(addr) }; } _ptr_base& operator = (const _ptr_base& right) = default; @@ -332,16 +318,14 @@ namespace vm 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 + template operator _ptr_base() const { - AT2 addr = convert_le_be(m_addr); - return reinterpret_cast<_ptr_base&>(addr); + return{ convert_le_be(m_addr) }; } - static const _ptr_base make(const AT& addr) + template static _ptr_base make(const AT2& addr) { - return reinterpret_cast(addr); + return{ convert_le_be(addr) }; } _ptr_base& operator = (const _ptr_base& right) = default; @@ -384,16 +368,14 @@ namespace vm 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 + template operator _ptr_base() const { - AT2 addr = convert_le_be(m_addr); - return reinterpret_cast<_ptr_base&>(addr); + return{ convert_le_be(m_addr) }; } - static const _ptr_base make(const AT& addr) + template static _ptr_base make(const AT2& addr) { - return reinterpret_cast(addr); + return{ convert_le_be(addr) }; } operator const std::function() const @@ -414,22 +396,22 @@ namespace vm }; // Native endianness pointer to LE data - template using ptrl = _ptr_base::type, lvl, AT>; + template using ptrl = _ptr_base, lvl, AT>; // Native endianness pointer to BE data - template using ptrb = _ptr_base::type, lvl, AT>; + template using ptrb = _ptr_base, lvl, AT>; // BE pointer to LE data - template using bptrl = _ptr_base::type, lvl, typename to_be_t::type>; + template using bptrl = _ptr_base, lvl, 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, lvl, 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, lvl, 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, lvl, to_le_t>; namespace ps3 { @@ -456,8 +438,7 @@ namespace vm { template operator _ptr_base() const { - const std::array value = {}; - return _ptr_base::make(value[0]); + return{}; } }; @@ -465,6 +446,37 @@ namespace vm static null_t null; } +// external specialization for is_be_t<> + +template +struct is_be_t> : public std::integral_constant::value> +{ +}; + +// external specialization for to_ne_t<> + +template +struct to_ne> +{ + using type = vm::_ptr_base>; +}; + +// external specialization for to_be_t<> + +template +struct to_be> +{ + using type = vm::_ptr_base>; +}; + +// external specialization for to_le_t<> (not used) + +template +struct to_le> +{ + using type = vm::_ptr_base>; +}; + namespace fmt { // external specialization for fmt::format function @@ -472,7 +484,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::_ptr_base& arg) { diff --git a/rpcs3/Emu/Memory/vm_ref.h b/rpcs3/Emu/Memory/vm_ref.h index a2e7903d16..ccc5528370 100644 --- a/rpcs3/Emu/Memory/vm_ref.h +++ b/rpcs3/Emu/Memory/vm_ref.h @@ -3,26 +3,30 @@ namespace vm { template - class _ref_base + struct _ref_base { - protected: - AT m_addr; + const AT m_addr; + + using type = T; - 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&() + //template operator std::enable_if_t::value, CT>() + //{ + // return get_ref(m_addr); + //} + + // temporarily, because SFINAE doesn't work for some reason: + + operator to_ne_t() const { return get_ref(m_addr); } - operator const T&() const + operator T() const { - return get_ref(m_addr); + return get_ref(m_addr); } AT addr() const @@ -32,28 +36,16 @@ namespace vm static _ref_base make(const AT& addr) { - return reinterpret_cast<_ref_base&>(addr); + return{ addr }; } - _ref_base& operator = (le_type right) + template const _ref_base& operator =(const _ref_base& right) const { get_ref(m_addr) = right; return *this; } - const _ref_base& operator = (le_type right) const - { - get_ref(m_addr) = right; - return *this; - } - - _ref_base& operator = (be_type right) - { - get_ref(m_addr) = right; - return *this; - } - - const _ref_base& operator = (be_type right) const + template std::enable_if_t::value, const _ref_base&> operator =(const CT& right) const { get_ref(m_addr) = right; return *this; @@ -61,22 +53,22 @@ namespace vm }; // 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 { @@ -98,7 +90,38 @@ namespace vm //PS3 emulation is main now, so lets it be as default using namespace ps3; -} +}; + +// external specialization for is_be_t<> + +template +struct is_be_t> : public std::integral_constant::value> +{ +}; + +// external specialization for to_ne_t<> + +template +struct to_ne> +{ + using type = vm::_ref_base>; +}; + +// external specialization for to_be_t<> + +template +struct to_be> +{ + using type = vm::_ref_base>; +}; + +// external specialization for to_le_t<> (not used) + +template +struct to_le> +{ + using type = vm::_ref_base>; +}; namespace fmt { @@ -107,7 +130,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/SysCalls/Modules/cellGifDec.h b/rpcs3/Emu/SysCalls/Modules/cellGifDec.h index b958150908..9b599425ff 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, @@ -19,10 +19,10 @@ enum CellGifDecStreamSrcSel CELL_GIFDEC_BUFFER = 1, // Input from a buffer }; -enum CellGifDecColorSpace +enum CellGifDecSpuThreadEna { - 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 @@ -32,10 +32,22 @@ enum CellGifDecRecordType CELL_GIFDEC_RECORD_TYPE_TERMINATE = 3, // Trailer block }; +enum CellGifDecColorSpace +{ + CELL_GIFDEC_RGBA = 10, // RGBA + CELL_GIFDEC_ARGB = 20, // ARGB +}; + +enum CellGifDecCommand +{ + CELL_GIFDEC_CONTINUE = 0, // Continue decoding + CELL_GIFDEC_STOP = 1, // Force decoding to stop +}; + enum CellGifDecDecodeStatus { - CELL_GIFDEC_DEC_STATUS_FINISH = 0, //Decoding finished - CELL_GIFDEC_DEC_STATUS_STOP = 1, //Decoding halted + CELL_GIFDEC_DEC_STATUS_FINISH = 0, // Decoding finished + CELL_GIFDEC_DEC_STATUS_STOP = 1, // Decoding was stopped }; struct CellGifDecInfo @@ -65,9 +77,9 @@ struct CellGifDecInParam { be_t commandPtr; be_t colorSpace; // CellGifDecColorSpace - be_t outputColorAlpha1; - be_t outputColorAlpha2; - be_t reserved[2]; + u8 outputColorAlpha1; + u8 outputColorAlpha2; + u8 reserved[2]; }; struct CellGifDecOutParam @@ -83,8 +95,8 @@ struct CellGifDecOutParam struct CellGifDecExtension { - be_t label; - be_t data; + u8 label; + vm::ptr data; }; struct CellGifDecDataOutInfo 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..4bdaa41196 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellL10n.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellL10n.cpp @@ -2,44 +2,47 @@ #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 "cellL10n.h" +#include +#include +#include + 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.Warning("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::u16string wstr; + wstr.resize(utf16_len); + + for (auto& wc : wstr) + { + wc = *utf16++; + } + + std::wstring_convert, char16_t> convert; std::string str = convert.to_bytes(wstr); - if (*utf8_len < str.size()) + if (utf8_len < str.size()) { - *utf8_len = str.size(); + utf8_len = str.size(); return DSTExhausted; } - *utf8_len = str.size(); + 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 +51,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 +116,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 +185,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 +202,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 +219,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 +230,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 +254,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 +284,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 +311,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 +493,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/cellPngDec.cpp b/rpcs3/Emu/SysCalls/Modules/cellPngDec.cpp index 58eab5a692..fc59a1410a 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, diff --git a/rpcs3/Emu/SysCalls/Modules/cellPngDec.h b/rpcs3/Emu/SysCalls/Modules/cellPngDec.h index 361d83fe07..4837b2024e 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellPngDec.h +++ b/rpcs3/Emu/SysCalls/Modules/cellPngDec.h @@ -6,11 +6,8 @@ enum : u32 PNGDEC_CODEC_VERSION = 0x00420000, }; -struct PngDecoder; -struct PngStream; - -typedef vm::ptr CellPngDecMainHandle; -typedef vm::ptr CellPngDecSubHandle; +using CellPngDecMainHandle = vm::ptr; +using CellPngDecSubHandle = vm::ptr; // Return Codes enum @@ -28,7 +25,7 @@ enum }; // Consts -enum CellPngDecColorSpace : u32 +enum CellPngDecColorSpace : s32 { CELL_PNGDEC_GRAYSCALE = 1, CELL_PNGDEC_RGB = 2, @@ -38,62 +35,62 @@ 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 +// Callbacks for memory management typedef vm::ptr(CellPngDecCbControlMalloc)(u32 size, vm::ptr cbCtrlMallocArg); typedef s32(CellPngDecCbControlFree)(vm::ptr 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 +101,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 +118,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 +137,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 +161,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,14 +176,17 @@ 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 cellPngDecCreate( + vm::ptr mainHandle, + vm::ptr threadInParam, + vm::ptr threadOutParam); s32 cellPngDecExtCreate( - vm::ptr mainHandle, + vm::ptr mainHandle, vm::ptr threadInParam, vm::ptr threadOutParam, vm::ptr extThreadInParam, @@ -194,11 +194,14 @@ s32 cellPngDecExtCreate( s32 cellPngDecOpen( CellPngDecMainHandle mainHandle, - vm::ptr subHandle, + vm::ptr subHandle, vm::ptr src, vm::ptr openInfo); -s32 cellPngDecReadHeader(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr info); +s32 cellPngDecReadHeader( + CellPngDecMainHandle mainHandle, + CellPngDecSubHandle subHandle, + vm::ptr info); s32 cellPngDecSetParameter( CellPngDecMainHandle mainHandle, @@ -217,11 +220,123 @@ s32 cellPngDecClose(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHand s32 cellPngDecDestroy(CellPngDecMainHandle mainHandle); -s32 cellPngDecGetTextChunk( +// Defines for decoding partial streams +enum CellPngDecBufferMode : s32 +{ + CELL_PNGDEC_LINE_MODE = 1, +}; + +enum CellPngDecSpuMode : s32 +{ + CELL_PNGDEC_RECEIVE_EVENT = 0, + CELL_PNGDEC_TRYRECEIVE_EVENT = 1, +}; + +// Structs for decoding partial streams +struct CellPngDecStrmInfo +{ + be_t decodedStrmSize; +}; + +struct CellPngDecStrmParam +{ + vm::bptr strmPtr; + be_t strmSize; +}; + +struct CellPngDecDispInfo +{ + be_t outputFrameWidthByte; + be_t outputFrameHeight; + be_t outputStartXByte; + be_t outputStartY; + be_t outputWidthByte; + be_t outputHeight; + be_t outputBitDepth; + be_t outputComponents; + be_t nextOutputStartY; + be_t scanPassCount; + vm::bptr outputImage; +}; + +struct CellPngDecDispParam +{ + vm::bptr nextOutputImage; +}; + +struct CellPngDecOpnParam +{ + be_t selectChunk; +}; + +struct CellPngDecExtInfo +{ + be_t reserved; +}; + +struct CellPngDecExtInParam +{ + be_t bufferMode; // CellPngDecBufferMode + be_t outputCounts; + be_t spuMode; // CellPngDecSpuMode +}; + +struct CellPngDecExtOutParam +{ + be_t outputWidthByte; + be_t outputHeight; +}; + +// Callbacks for decoding partial streams +typedef s32(CellPngDecCbControlStream)(vm::ptr strmInfo, vm::ptr strmParam, vm::ptr cbCtrlStrmArg); +typedef s32(CellPngDecCbControlDisp)(vm::ptr dispInfo, vm::ptr dispParam, vm::ptr cbCtrlDispArg); + +struct CellPngDecCbCtrlStrm +{ + vm::bptr cbCtrlStrmFunc; + vm::bptr cbCtrlStrmArg; +}; + +struct CellPngDecCbCtrlDisp +{ + vm::bptr cbCtrlDispFunc; + vm::bptr cbCtrlDispArg; +}; + +// Functions for decoding partial streams +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 textInfoNum, - vm::ptr> textInfo); + 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); + +// Functions for accessing ancillary chunks +s32 cellPngDecGetTextChunk(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr textInfoNum, vm::ptr> textInfo); s32 cellPngDecGetPLTE(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr plte); @@ -253,128 +368,7 @@ s32 cellPngDecGetcHRM(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHa s32 cellPngDecGetpCAL(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr pcal); -s32 cellPngDecGetUnknownChunks( - CellPngDecMainHandle mainHandle, - CellPngDecSubHandle subHandle, - vm::ptr> unknownChunk, - vm::ptr unknownChunkNumber); - - -enum CellPngDecBufferMode -{ - CELL_PNGDEC_LINE_MODE = 1, -}; - -enum CellPngDecSpuMode -{ - CELL_PNGDEC_RECEIVE_EVENT = 0, - CELL_PNGDEC_TRYRECEIVE_EVENT = 1, -}; - -// Structs -struct CellPngDecStrmInfo -{ - be_t decodedStrmSize; -}; - -struct CellPngDecStrmParam -{ - vm::bptr strmPtr; - be_t strmSize; -}; - -typedef s32(CellPngDecCbControlStream)(vm::ptr strmInfo, vm::ptr strmParam, vm::ptr cbCtrlStrmArg); - -struct CellPngDecDispInfo -{ - be_t outputFrameWidthByte; - be_t outputFrameHeight; - be_t outputStartXByte; - be_t outputStartY; - be_t outputWidthByte; - be_t outputHeight; - be_t outputBitDepth; - be_t outputComponents; - be_t nextOutputStartY; - be_t scanPassCount; - vm::bptr outputImage; -}; - -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; -}; - -struct CellPngDecExtInParam -{ - be_t bufferMode; - be_t outputCounts; - be_t spuMode; -}; - -struct CellPngDecExtOutParam -{ - be_t outputWidthByte; - be_t outputHeight; -}; - -struct CellPngDecCbCtrlDisp -{ - vm::bptr cbCtrlDispFunc; - be_t> 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); +s32 cellPngDecGetUnknownChunks(CellPngDecMainHandle mainHandle, CellPngDecSubHandle subHandle, vm::ptr> unknownChunk, vm::ptr unknownChunkNumber); // Custom structs struct PngDecoder 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.h b/rpcs3/Emu/SysCalls/Modules/cellSpurs.h index fb84c1f541..f2ef406994 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellSpurs.h +++ b/rpcs3/Emu/SysCalls/Modules/cellSpurs.h @@ -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[]; 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.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)); }