Patch from DH applied

This commit is contained in:
Nekotekina 2014-09-01 20:16:44 +04:00
parent f31ed4e9f2
commit 774b5be7d7
7 changed files with 203 additions and 75 deletions

View file

@ -47,10 +47,10 @@ template<typename T, s64 _value> struct const_se_t<T, _value, 8>
((_value << 56) & 0xff00000000000000); ((_value << 56) & 0xff00000000000000);
}; };
template<typename T, int size=sizeof(T)> template<typename T, typename T2 = T>
class be_t 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; T m_data;
public: public:
@ -65,7 +65,7 @@ public:
{ {
T res; T res;
se_t<T>::func(res, m_data); se_t<T, sizeof(T2)>::func(res, m_data);
return res; return res;
} }
@ -77,7 +77,7 @@ public:
void FromLE(const T& value) void FromLE(const T& value)
{ {
se_t<T>::func(m_data, value); se_t<T, sizeof(T2)>::func(m_data, value);
} }
static be_t MakeFromLE(const T value) static be_t MakeFromLE(const T value)
@ -125,7 +125,7 @@ public:
return *this; return *this;
} }
be_t<T,size>& operator = (const be_t<T,size>& right) = default; be_t& operator = (const be_t& right) = default;
template<typename T1> be_t& operator += (T1 right) { return *this = T(*this) + right; } template<typename T1> be_t& operator += (T1 right) { return *this = T(*this) + right; }
template<typename T1> be_t& operator -= (T1 right) { return *this = T(*this) - right; } template<typename T1> be_t& operator -= (T1 right) { return *this = T(*this) - right; }
@ -171,6 +171,71 @@ public:
be_t& operator-- () { *this -= 1; return *this; } be_t& operator-- () { *this -= 1; return *this; }
}; };
template<typename T, typename T2 = T>
struct is_be_t : public std::integral_constant<bool, false> {};
template<typename T, typename T2>
struct is_be_t<be_t<T, T2>, T2> : public std::integral_constant<bool, true>
{
};
template<typename T>
struct remove_be_t
{
typedef T type;
};
template<typename T, typename T2>
struct remove_be_t<be_t<T, T2>>
{
typedef T type;
};
template<typename T, typename T2 = T>
class to_be_t
{
template<typename T, typename T2, bool is_need_swap>
struct _be_type_selector
{
typedef typename T type;
};
template<typename T, typename T2>
struct _be_type_selector<T, T2, true>
{
typedef typename be_t<T, T2> type;
};
public:
//true if need swap endianes for be
static const bool value = (sizeof(T2) > 1) && std::is_arithmetic<T>::value;
//be_t<T, size> if need swap endianes, T otherwise
typedef typename _be_type_selector< T, T2, value >::type type;
};
template<typename T>
class to_be_t<T, void>
{
public:
//true if need swap endianes for be
static const bool value = false;
//be_t<T, size> if need swap endianes, T otherwise
typedef void type;
};
template<typename T>
class to_be_t<T, const void>
{
public:
//true if need swap endianes for be
static const bool value = false;
//be_t<T, size> if need swap endianes, T otherwise
typedef void type;
};
template<typename T, typename T1, T1 value> struct _se : public const_se_t<T, value> {}; template<typename T, typename T1, T1 value> struct _se : public const_se_t<T, value> {};
template<typename T, typename T1, T1 value> struct _se<be_t<T>, T1, value> : public const_se_t<T, value> {}; template<typename T, typename T1, T1 value> struct _se<be_t<T>, T1, value> : public const_se_t<T, value> {};

View file

@ -3,77 +3,79 @@
namespace vm namespace vm
{ {
template<typename T, int lvl = 1, typename AT = u32> template<typename T, int lvl = 1, typename AT = u32>
class ptr class _ptr_base
{ {
AT m_addr; AT m_addr;
public: public:
ptr operator++ (int) typedef T type;
_ptr_base operator++ (int)
{ {
AT result = m_addr; AT result = m_addr;
m_addr += sizeof(AT); m_addr += sizeof(AT);
return { result }; return make(result);
} }
ptr& operator++ () _ptr_base& operator++ ()
{ {
m_addr += sizeof(AT); m_addr += sizeof(AT);
return *this; return *this;
} }
ptr operator-- (int) _ptr_base operator-- (int)
{ {
AT result = m_addr; AT result = m_addr;
m_addr -= sizeof(AT); m_addr -= sizeof(AT);
return { result }; return make(result);
} }
ptr& operator-- () _ptr_base& operator-- ()
{ {
m_addr -= sizeof(AT); m_addr -= sizeof(AT);
return *this; return *this;
} }
ptr& operator += (int count) _ptr_base& operator += (int count)
{ {
m_addr += count * sizeof(AT); m_addr += count * sizeof(AT);
return *this; return *this;
} }
ptr& operator -= (int count) _ptr_base& operator -= (int count)
{ {
m_addr -= count * sizeof(AT); m_addr -= count * sizeof(AT);
return *this; 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<T, lvl - 1, AT>& operator *() __forceinline _ptr_base<T, lvl - 1, AT>& operator *()
{ {
return get_ref<ptr<T, lvl - 1, AT>>(m_addr); return vm::get_ref<_ptr_base<T, lvl - 1, AT>>(m_addr);
} }
__forceinline const ptr<T, lvl - 1, AT>& operator *() const __forceinline const _ptr_base<T, lvl - 1, AT>& operator *() const
{ {
return get_ref<const ptr<T, lvl - 1, AT>>(m_addr); return vm::get_ref<const _ptr_base<T, lvl - 1, AT>>(m_addr);
} }
__forceinline ptr<T, lvl - 1, AT>& operator [](int index) __forceinline _ptr_base<T, lvl - 1, AT>& operator [](int index)
{ {
return get_ref<ptr<T, lvl - 1, AT>>(m_addr + sizeof(AT) * index); return vm::get_ref<_ptr_base<T, lvl - 1, AT>>(m_addr + sizeof(AT) * index);
} }
__forceinline const ptr<T, lvl - 1, AT>& operator [](int index) const __forceinline const _ptr_base<T, lvl - 1, AT>& operator [](int index) const
{ {
return get_ref<const ptr<T, lvl - 1, AT>>(m_addr + sizeof(AT) * index); return vm::get_ref<const _ptr_base<T, lvl - 1, AT>>(m_addr + sizeof(AT) * index);
} }
operator bool() const operator bool() const
@ -86,14 +88,14 @@ namespace vm
return m_addr; return m_addr;
} }
static ptr make(AT addr) static _ptr_base make(AT addr)
{ {
return (ptr&)addr; return (_ptr_base&)addr;
} }
}; };
template<typename T, typename AT> template<typename T, typename AT>
class ptr<T, 1, AT> class _ptr_base<T, 1, AT>
{ {
AT m_addr; AT m_addr;
@ -108,52 +110,52 @@ namespace vm
return vm::get_ptr<const T>(m_addr); return vm::get_ptr<const T>(m_addr);
} }
ptr operator++ (int) _ptr_base operator++ (int)
{ {
AT result = m_addr; AT result = m_addr;
m_addr += sizeof(T); m_addr += sizeof(T);
return { result }; return make(result);
} }
ptr& operator++ () _ptr_base& operator++ ()
{ {
m_addr += sizeof(T); m_addr += sizeof(T);
return *this; return *this;
} }
ptr operator-- (int) _ptr_base operator-- (int)
{ {
AT result = m_addr; AT result = m_addr;
m_addr -= sizeof(T); m_addr -= sizeof(T);
return { result }; return make(result);
} }
ptr& operator-- () _ptr_base& operator-- ()
{ {
m_addr -= sizeof(T); m_addr -= sizeof(T);
return *this; return *this;
} }
ptr& operator += (int count) _ptr_base& operator += (int count)
{ {
m_addr += count * sizeof(T); m_addr += count * sizeof(T);
return *this; return *this;
} }
ptr& operator -= (int count) _ptr_base& operator -= (int count)
{ {
m_addr -= count * sizeof(T); m_addr -= count * sizeof(T);
return *this; 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 *() __forceinline T& operator *()
@ -177,14 +179,14 @@ namespace vm
} }
/* /*
operator ref<T>() operator _ref_base<T, AT>()
{ {
return { m_addr }; return _ref_base<T, AT>::make(m_addr);
} }
operator const ref<T>() const operator const _ref_base<T, AT>() const
{ {
return { m_addr }; return _ref_base<T, AT>::make(m_addr);
} }
*/ */
@ -203,14 +205,14 @@ namespace vm
return vm::get_ptr<T>(m_addr); return vm::get_ptr<T>(m_addr);
} }
static ptr make(AT addr) static _ptr_base make(AT addr)
{ {
return (ptr&)addr; return (_ptr_base&)addr;
} }
}; };
template<typename AT> template<typename AT>
class ptr<void, 1, AT> class _ptr_base<void, 1, AT>
{ {
AT m_addr; AT m_addr;
@ -230,14 +232,14 @@ namespace vm
return m_addr != 0; return m_addr != 0;
} }
static ptr make(AT addr) static _ptr_base make(AT addr)
{ {
return (ptr&)addr; return (_ptr_base&)addr;
} }
}; };
template<typename AT> template<typename AT>
class ptr<const void, 1, AT> class _ptr_base<const void, 1, AT>
{ {
AT m_addr; AT m_addr;
@ -257,14 +259,14 @@ namespace vm
return m_addr != 0; return m_addr != 0;
} }
static ptr make(AT addr) static _ptr_base make(AT addr)
{ {
return (ptr&)addr; return (_ptr_base&)addr;
} }
}; };
template<typename RT, typename AT> template<typename RT, typename AT>
class ptr<RT(*)(), 1, AT> class _ptr_base<RT(*)(), 1, AT>
{ {
AT m_addr; AT m_addr;
@ -298,9 +300,9 @@ namespace vm
return m_addr != 0; 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<RT()>() const operator std::function<RT()>() const
@ -311,7 +313,7 @@ namespace vm
}; };
template<typename AT, typename RT, typename ...T> template<typename AT, typename RT, typename ...T>
class ptr<RT(*)(T...), 1, AT> class _ptr_base<RT(*)(T...), 1, AT>
{ {
AT m_addr; AT m_addr;
@ -325,9 +327,9 @@ namespace vm
}; };
template<typename TT, typename ATT> template<typename TT, typename ATT>
struct _func_arg<ptr<TT, 1, ATT>> struct _func_arg<_ptr_base<TT, 1, ATT>>
{ {
__forceinline static u64 get_value(const ptr<TT, 1, ATT> arg) __forceinline static u64 get_value(const _ptr_base<TT, 1, ATT> arg)
{ {
return arg.addr(); return arg.addr();
} }
@ -384,9 +386,9 @@ namespace vm
return m_addr != 0; 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<RT(T...)>() const operator std::function<RT(T...)>() const
@ -396,6 +398,33 @@ namespace vm
} }
}; };
template<typename T, int lvl = 1, typename AT = u32> //BE pointer to LE data
class beptr : public ptr<T, lvl, be_t<AT>> {}; template<typename T, int lvl = 1, typename AT = u32> class bptrl : public _ptr_base<T, lvl, typename to_be_t<AT>::type> {};
//BE pointer to BE data
template<typename T, int lvl = 1, typename AT = u32> class bptrb : public _ptr_base<typename to_be_t<T>::type, lvl, typename to_be_t<AT>::type> {};
//LE pointer to BE data
template<typename T, int lvl = 1, typename AT = u32> class lptrb : public _ptr_base<typename to_be_t<T>::type, lvl, AT> {};
//LE pointer to LE data
template<typename T, int lvl = 1, typename AT = u32> class lptrl : public _ptr_base<T, lvl, AT> {};
namespace ps3
{
//default pointer for HLE functions (LE ptrerence to BE data)
template<typename T, int lvl = 1, typename AT = u32> class ptr : public lptrb<T, lvl, AT>
{
public:
static ptr make(AT addr)
{
return (ptr&)addr;
}
};
//default pointer for HLE structures (BE ptrerence to BE data)
template<typename T, int lvl = 1, typename AT = u32> class bptr : public bptrb<T, lvl, AT> {};
}
namespace psv
{
//default pointer for HLE functions & structures (LE ptrerence to LE data)
template<typename T, int lvl = 1, typename AT = u32> class ptr : public lptrl<T, lvl, AT> {};
}
//PS3 emulation is main now, so lets it be as default
using namespace ps3;
} }

View file

@ -5,9 +5,12 @@ namespace vm
template<typename T, typename AT = u32> template<typename T, typename AT = u32>
class _ref_base class _ref_base
{ {
protected:
AT m_addr; AT m_addr;
public: public:
typedef T type;
operator T&() operator T&()
{ {
return get_ref<T>(m_addr); return get_ref<T>(m_addr);
@ -30,29 +33,60 @@ namespace vm
}; };
//BE reference to LE data //BE reference to LE data
template<typename T, typename AT = u32> class brefl : public _ref_base<T, be_t<AT>> {}; template<typename T, typename AT = u32> struct brefl : public _ref_base<T, typename to_be_t<AT>::type>
{
_ref_base& operator = (typename T right) { get_ref<T>(m_addr) = right; return *this; }
const _ref_base& operator = (typename T right) const { get_ref<T>(m_addr) = right; return *this; }
};
//BE reference to BE data //BE reference to BE data
template<typename T, typename AT = u32> class brefb : public _ref_base<be_t<T>, be_t<AT>> {}; template<typename T, typename AT = u32> struct brefb : public _ref_base<typename to_be_t<T>::type, typename to_be_t<AT>::type>
{
_ref_base& operator = (typename T right) { get_ref<T>(m_addr) = right; return *this; }
const _ref_base& operator = (typename T right) const { get_ref<T>(m_addr) = right; return *this; }
};
//LE reference to BE data //LE reference to BE data
template<typename T, typename AT = u32> class lrefb : public _ref_base<be_t<T>, AT> {}; template<typename T, typename AT = u32> struct lrefb : public _ref_base<typename to_be_t<T>::type, AT>
{
_ref_base& operator = (typename T right) { get_ref<T>(m_addr) = right; return *this; }
const _ref_base& operator = (typename T right) const { get_ref<T>(m_addr) = right; return *this; }
};
//LE reference to LE data //LE reference to LE data
template<typename T, typename AT = u32> class lrefl : public _ref_base<T, AT> {}; template<typename T, typename AT = u32> struct lrefl : public _ref_base<T, AT>
{
_ref_base& operator = (typename T right) { get_ref<T>(m_addr) = right; return *this; }
const _ref_base& operator = (typename T right) const { get_ref<T>(m_addr) = right; return *this; }
};
namespace ps3 namespace ps3
{ {
//default reference for HLE functions (LE reference to BE data) //default reference for HLE functions (LE reference to BE data)
template<typename T, typename AT = u32> class ref : public lrefb<T, AT> {}; template<typename T, typename AT = u32> struct ref : public lrefb<T, AT>
{
_ref_base& operator = (typename T right) { get_ref<T>(m_addr) = right; return *this; }
const _ref_base& operator = (typename T right) const { get_ref<T>(m_addr) = right; return *this; }
};
//default reference for HLE structures (BE reference to BE data) //default reference for HLE structures (BE reference to BE data)
template<typename T, typename AT = u32> class bref : public brefb<T, AT> {}; template<typename T, typename AT = u32> struct bref : public brefb<T, AT>
{
_ref_base& operator = (typename T right) { get_ref<T>(m_addr) = right; return *this; }
const _ref_base& operator = (typename T right) const { get_ref<T>(m_addr) = right; return *this; }
};
} }
namespace psv namespace psv
{ {
//default reference for HLE functions & structures (LE reference to LE data) //default reference for HLE functions & structures (LE reference to LE data)
template<typename T, typename AT = u32> class ref : public lrefl<T, AT> {}; template<typename T, typename AT = u32> struct ref : public lrefl<T, AT>
{
_ref_base& operator = (typename T right) { get_ref<T>(m_addr) = right; return *this; }
const _ref_base& operator = (typename T right) const { get_ref<T>(m_addr) = right; return *this; }
};
} }
//PS3 emulation is main now, so lets it be as default
using namespace ps3;
} }

View file

@ -106,9 +106,9 @@ namespace vm
} }
*/ */
template<typename AT> operator ptr<T, 1, AT>() const template<typename AT> operator ps3::ptr<T, 1, AT>() const
{ {
return ptr<T, 1, AT>::make(m_addr); return ps3::ptr<T, 1, AT>::make(m_addr);
} }
operator T&() operator T&()

View file

@ -18,7 +18,7 @@
//Module cellL10n(0x001e, cellL10n_init); //Module cellL10n(0x001e, cellL10n_init);
Module *cellL10n = nullptr; Module *cellL10n = nullptr;
int UTF16stoUTF8s(vm::ptr<const char16_t> utf16, vm::ptr<be_t<u32>> utf16_len, vm::ptr<char> utf8, vm::ptr<be_t<u32>> utf8_len) int UTF16stoUTF8s(vm::lptrl<const char16_t> utf16, vm::ptr<be_t<u32>> utf16_len, vm::ptr<char> utf8, vm::ptr<be_t<u32>> utf8_len)
{ {
cellL10n->Warning("UTF16stoUTF8s(utf16_addr=0x%x, utf16_len_addr=0x%x, utf8_addr=0x%x, utf8_len_addr=0x%x)", 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()); utf16.addr(), utf16_len.addr(), utf8.addr(), utf8_len.addr());

View file

@ -122,7 +122,7 @@ struct CellPngDecStrmParam
struct CellPngDecCbCtrlStrm struct CellPngDecCbCtrlStrm
{ {
vm::beptr<void(*)(vm::ptr<CellPngDecStrmInfo> strmInfo, vm::ptr<CellPngDecStrmParam> strmParam, u32 cbCtrlStrmArg)> cbCtrlStrmFunc; vm::bptr<void(*)(vm::ptr<CellPngDecStrmInfo> strmInfo, vm::ptr<CellPngDecStrmParam> strmParam, u32 cbCtrlStrmArg)> cbCtrlStrmFunc;
be_t<u32> cbCtrlStrmArg; be_t<u32> cbCtrlStrmArg;
}; };

View file

@ -361,7 +361,7 @@ int cellSurMixerCreate(const mem_ptr_t<CellSurMixerConfig> config)
for (auto& p : ssp) if (p.m_active && p.m_created) for (auto& p : ssp) if (p.m_active && p.m_created)
{ {
auto v = vm::ptr<s16>::make(p.m_addr); // 16-bit LE audio data auto v = vm::lptrl<s16>::make(p.m_addr); // 16-bit LE audio data
float left = 0.0f; float left = 0.0f;
float right = 0.0f; float right = 0.0f;
float speed = fabs(p.m_speed); float speed = fabs(p.m_speed);