From 774b5be7d7df2288ae407ecbbff0206395a85c88 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Mon, 1 Sep 2014 20:16:44 +0400 Subject: [PATCH] Patch from DH applied --- Utilities/BEType.h | 75 +++++++++++- rpcs3/Emu/Memory/vm_ptr.h | 145 ++++++++++++++---------- rpcs3/Emu/Memory/vm_ref.h | 48 ++++++-- rpcs3/Emu/Memory/vm_var.h | 4 +- rpcs3/Emu/SysCalls/Modules/cellL10n.cpp | 2 +- rpcs3/Emu/SysCalls/Modules/cellPngDec.h | 2 +- rpcs3/Emu/SysCalls/Modules/libmixer.cpp | 2 +- 7 files changed, 203 insertions(+), 75 deletions(-) diff --git a/Utilities/BEType.h b/Utilities/BEType.h index 0915a0b739..fe7988823e 100644 --- a/Utilities/BEType.h +++ b/Utilities/BEType.h @@ -47,10 +47,10 @@ template struct const_se_t ((_value << 56) & 0xff00000000000000); }; -template +template class be_t { - static_assert(size == 1 || size == 2 || size == 4 || size == 8, "Bad be_t type"); + static_assert(sizeof(T2) == 1 || sizeof(T2) == 2 || sizeof(T2) == 4 || sizeof(T2) == 8, "Bad be_t type"); T m_data; public: @@ -65,7 +65,7 @@ public: { T res; - se_t::func(res, m_data); + se_t::func(res, m_data); return res; } @@ -77,7 +77,7 @@ public: void FromLE(const T& value) { - se_t::func(m_data, value); + se_t::func(m_data, value); } static be_t MakeFromLE(const T value) @@ -125,7 +125,7 @@ public: return *this; } - be_t& operator = (const be_t& right) = default; + be_t& operator = (const be_t& right) = default; template be_t& operator += (T1 right) { return *this = T(*this) + right; } template be_t& operator -= (T1 right) { return *this = T(*this) - right; } @@ -171,6 +171,71 @@ 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 +{ + typedef T type; +}; + +template +struct remove_be_t> +{ + typedef T type; +}; + +template +class to_be_t +{ + template + struct _be_type_selector + { + typedef typename T type; + }; + + template + struct _be_type_selector + { + typedef typename be_t type; + }; + +public: + //true if need swap endianes for be + static const bool value = (sizeof(T2) > 1) && std::is_arithmetic::value; + + //be_t if need swap endianes, T otherwise + typedef typename _be_type_selector< T, T2, value >::type type; +}; + +template +class to_be_t +{ +public: + //true if need swap endianes for be + static const bool value = false; + + //be_t if need swap endianes, T otherwise + typedef void type; +}; + +template +class to_be_t +{ +public: + //true if need swap endianes for be + static const bool value = false; + + //be_t if need swap endianes, T otherwise + typedef void type; +}; + template struct _se : public const_se_t {}; template struct _se, T1, value> : public const_se_t {}; diff --git a/rpcs3/Emu/Memory/vm_ptr.h b/rpcs3/Emu/Memory/vm_ptr.h index 88cab76b3c..50a2cc9780 100644 --- a/rpcs3/Emu/Memory/vm_ptr.h +++ b/rpcs3/Emu/Memory/vm_ptr.h @@ -3,77 +3,79 @@ namespace vm { template - class ptr + class _ptr_base { AT m_addr; public: - ptr operator++ (int) + typedef T type; + + _ptr_base operator++ (int) { AT result = m_addr; m_addr += sizeof(AT); - return { result }; + return make(result); } - ptr& operator++ () + _ptr_base& operator++ () { m_addr += sizeof(AT); return *this; } - ptr operator-- (int) + _ptr_base operator-- (int) { AT result = m_addr; m_addr -= sizeof(AT); - return { result }; + return make(result); } - ptr& operator-- () + _ptr_base& operator-- () { m_addr -= sizeof(AT); return *this; } - ptr& operator += (int count) + _ptr_base& operator += (int count) { m_addr += count * sizeof(AT); return *this; } - ptr& operator -= (int count) + _ptr_base& operator -= (int count) { m_addr -= count * sizeof(AT); return *this; } - ptr operator + (int count) const + _ptr_base operator + (int count) const { - return { m_addr + count * sizeof(AT) }; + return make(m_addr + count * sizeof(AT)); } - ptr operator - (int count) const + _ptr_base operator - (int count) const { - return { m_addr - count * sizeof(AT) }; + return make(m_addr - count * sizeof(AT)); } - __forceinline ptr& operator *() + __forceinline _ptr_base& operator *() { - return get_ref>(m_addr); + return vm::get_ref<_ptr_base>(m_addr); } - __forceinline const ptr& operator *() const + __forceinline const _ptr_base& operator *() const { - return get_ref>(m_addr); + return vm::get_ref>(m_addr); } - __forceinline ptr& operator [](int index) + __forceinline _ptr_base& operator [](int index) { - return get_ref>(m_addr + sizeof(AT) * index); + return vm::get_ref<_ptr_base>(m_addr + sizeof(AT) * index); } - __forceinline const ptr& operator [](int index) const + __forceinline const _ptr_base& operator [](int index) const { - return get_ref>(m_addr + sizeof(AT) * index); + return vm::get_ref>(m_addr + sizeof(AT) * index); } operator bool() const @@ -86,14 +88,14 @@ namespace vm return m_addr; } - static ptr make(AT addr) + static _ptr_base make(AT addr) { - return (ptr&)addr; + return (_ptr_base&)addr; } }; template - class ptr + class _ptr_base { AT m_addr; @@ -108,52 +110,52 @@ namespace vm return vm::get_ptr(m_addr); } - ptr operator++ (int) + _ptr_base operator++ (int) { AT result = m_addr; m_addr += sizeof(T); - return { result }; + return make(result); } - ptr& operator++ () + _ptr_base& operator++ () { m_addr += sizeof(T); return *this; } - ptr operator-- (int) + _ptr_base operator-- (int) { AT result = m_addr; m_addr -= sizeof(T); - return { result }; + return make(result); } - ptr& operator-- () + _ptr_base& operator-- () { m_addr -= sizeof(T); return *this; } - ptr& operator += (int count) + _ptr_base& operator += (int count) { m_addr += count * sizeof(T); return *this; } - ptr& operator -= (int count) + _ptr_base& operator -= (int count) { m_addr -= count * sizeof(T); return *this; } - ptr operator + (int count) const + _ptr_base operator + (int count) const { - return { m_addr + count * sizeof(T) }; + return make(m_addr + count * sizeof(T)); } - ptr operator - (int count) const + _ptr_base operator - (int count) const { - return { m_addr - count * sizeof(T) }; + return make(m_addr - count * sizeof(T)); } __forceinline T& operator *() @@ -177,14 +179,14 @@ namespace vm } /* - operator ref() + operator _ref_base() { - return { m_addr }; + return _ref_base::make(m_addr); } - operator const ref() const + operator const _ref_base() const { - return { m_addr }; + return _ref_base::make(m_addr); } */ @@ -203,14 +205,14 @@ namespace vm return vm::get_ptr(m_addr); } - static ptr make(AT addr) + static _ptr_base make(AT addr) { - return (ptr&)addr; + return (_ptr_base&)addr; } }; template - class ptr + class _ptr_base { AT m_addr; @@ -230,14 +232,14 @@ namespace vm return m_addr != 0; } - static ptr make(AT addr) + static _ptr_base make(AT addr) { - return (ptr&)addr; + return (_ptr_base&)addr; } }; template - class ptr + class _ptr_base { AT m_addr; @@ -257,14 +259,14 @@ namespace vm return m_addr != 0; } - static ptr make(AT addr) + static _ptr_base make(AT addr) { - return (ptr&)addr; + return (_ptr_base&)addr; } }; template - class ptr + class _ptr_base { AT m_addr; @@ -298,9 +300,9 @@ namespace vm return m_addr != 0; } - static ptr make(AT addr) + static _ptr_base make(AT addr) { - return (ptr&)addr; + return (_ptr_base&)addr; } operator std::function() const @@ -311,7 +313,7 @@ namespace vm }; template - class ptr + class _ptr_base { AT m_addr; @@ -325,9 +327,9 @@ namespace vm }; template - struct _func_arg> + struct _func_arg<_ptr_base> { - __forceinline static u64 get_value(const ptr arg) + __forceinline static u64 get_value(const _ptr_base arg) { return arg.addr(); } @@ -384,9 +386,9 @@ namespace vm return m_addr != 0; } - static ptr make(AT addr) + static _ptr_base make(AT addr) { - return (ptr&)addr; + return (_ptr_base&)addr; } operator std::function() const @@ -396,6 +398,33 @@ namespace vm } }; - template - class beptr : public ptr> {}; + //BE pointer to LE data + template class bptrl : public _ptr_base::type> {}; + //BE pointer to BE data + template class bptrb : public _ptr_base::type, lvl, typename to_be_t::type> {}; + //LE pointer to BE data + template class lptrb : public _ptr_base::type, lvl, AT> {}; + //LE pointer to LE data + template class lptrl : public _ptr_base {}; + namespace ps3 + { + //default pointer for HLE functions (LE ptrerence to BE data) + template class ptr : public lptrb + { + public: + static ptr make(AT addr) + { + return (ptr&)addr; + } + }; + //default pointer for HLE structures (BE ptrerence to BE data) + template class bptr : public bptrb {}; + } + namespace psv + { + //default pointer for HLE functions & structures (LE ptrerence to LE data) + template class ptr : public lptrl {}; + } + //PS3 emulation is main now, so lets it be as default + using namespace ps3; } \ No newline at end of file diff --git a/rpcs3/Emu/Memory/vm_ref.h b/rpcs3/Emu/Memory/vm_ref.h index 666b059ba7..2e47d29c16 100644 --- a/rpcs3/Emu/Memory/vm_ref.h +++ b/rpcs3/Emu/Memory/vm_ref.h @@ -5,9 +5,12 @@ namespace vm template class _ref_base { + protected: AT m_addr; public: + typedef T type; + operator T&() { return get_ref(m_addr); @@ -30,29 +33,60 @@ namespace vm }; //BE reference to LE data - template class brefl : public _ref_base> {}; + template struct brefl : public _ref_base::type> + { + _ref_base& operator = (typename T right) { get_ref(m_addr) = right; return *this; } + const _ref_base& operator = (typename T right) const { get_ref(m_addr) = right; return *this; } + }; //BE reference to BE data - template class brefb : public _ref_base, be_t> {}; + template struct brefb : public _ref_base::type, typename to_be_t::type> + { + _ref_base& operator = (typename T right) { get_ref(m_addr) = right; return *this; } + const _ref_base& operator = (typename T right) const { get_ref(m_addr) = right; return *this; } + }; //LE reference to BE data - template class lrefb : public _ref_base, AT> {}; + template struct lrefb : public _ref_base::type, AT> + { + _ref_base& operator = (typename T right) { get_ref(m_addr) = right; return *this; } + const _ref_base& operator = (typename T right) const { get_ref(m_addr) = right; return *this; } + }; //LE reference to LE data - template class lrefl : public _ref_base {}; + template struct lrefl : public _ref_base + { + _ref_base& operator = (typename T right) { get_ref(m_addr) = right; return *this; } + const _ref_base& operator = (typename T right) const { get_ref(m_addr) = right; return *this; } + }; namespace ps3 { //default reference for HLE functions (LE reference to BE data) - template class ref : public lrefb {}; + template struct ref : public lrefb + { + _ref_base& operator = (typename T right) { get_ref(m_addr) = right; return *this; } + const _ref_base& operator = (typename T right) const { get_ref(m_addr) = right; return *this; } + }; //default reference for HLE structures (BE reference to BE data) - template class bref : public brefb {}; + template struct bref : public brefb + { + _ref_base& operator = (typename T right) { get_ref(m_addr) = right; return *this; } + const _ref_base& operator = (typename T right) const { get_ref(m_addr) = right; return *this; } + }; } namespace psv { //default reference for HLE functions & structures (LE reference to LE data) - template class ref : public lrefl {}; + template struct ref : public lrefl + { + _ref_base& operator = (typename T right) { get_ref(m_addr) = right; return *this; } + const _ref_base& operator = (typename T right) const { get_ref(m_addr) = right; return *this; } + }; } + + //PS3 emulation is main now, so lets it be as default + using namespace ps3; } \ No newline at end of file diff --git a/rpcs3/Emu/Memory/vm_var.h b/rpcs3/Emu/Memory/vm_var.h index bb48bf5096..f878de752b 100644 --- a/rpcs3/Emu/Memory/vm_var.h +++ b/rpcs3/Emu/Memory/vm_var.h @@ -106,9 +106,9 @@ namespace vm } */ - template operator ptr() const + template operator ps3::ptr() const { - return ptr::make(m_addr); + return ps3::ptr::make(m_addr); } operator T&() diff --git a/rpcs3/Emu/SysCalls/Modules/cellL10n.cpp b/rpcs3/Emu/SysCalls/Modules/cellL10n.cpp index 536122f30c..db75833d76 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellL10n.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellL10n.cpp @@ -18,7 +18,7 @@ //Module cellL10n(0x001e, cellL10n_init); Module *cellL10n = nullptr; -int UTF16stoUTF8s(vm::ptr utf16, vm::ptr> utf16_len, vm::ptr utf8, vm::ptr> utf8_len) +int UTF16stoUTF8s(vm::lptrl utf16, vm::ptr> utf16_len, vm::ptr utf8, vm::ptr> 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()); diff --git a/rpcs3/Emu/SysCalls/Modules/cellPngDec.h b/rpcs3/Emu/SysCalls/Modules/cellPngDec.h index 57372d5f3b..cdbaeb97ca 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellPngDec.h +++ b/rpcs3/Emu/SysCalls/Modules/cellPngDec.h @@ -122,7 +122,7 @@ struct CellPngDecStrmParam struct CellPngDecCbCtrlStrm { - vm::beptr strmInfo, vm::ptr strmParam, u32 cbCtrlStrmArg)> cbCtrlStrmFunc; + vm::bptr strmInfo, vm::ptr strmParam, u32 cbCtrlStrmArg)> cbCtrlStrmFunc; be_t cbCtrlStrmArg; }; diff --git a/rpcs3/Emu/SysCalls/Modules/libmixer.cpp b/rpcs3/Emu/SysCalls/Modules/libmixer.cpp index 48044586e9..7fd2644af7 100644 --- a/rpcs3/Emu/SysCalls/Modules/libmixer.cpp +++ b/rpcs3/Emu/SysCalls/Modules/libmixer.cpp @@ -361,7 +361,7 @@ int cellSurMixerCreate(const mem_ptr_t config) for (auto& p : ssp) if (p.m_active && p.m_created) { - auto v = vm::ptr::make(p.m_addr); // 16-bit LE audio data + auto v = vm::lptrl::make(p.m_addr); // 16-bit LE audio data float left = 0.0f; float right = 0.0f; float speed = fabs(p.m_speed);