2014-07-31 18:08:02 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
namespace vm
|
|
|
|
|
{
|
2014-08-01 18:27:48 +02:00
|
|
|
template<typename T, typename AT = u32>
|
|
|
|
|
class _ref_base
|
|
|
|
|
{
|
2014-09-01 18:16:44 +02:00
|
|
|
protected:
|
2014-08-01 18:27:48 +02:00
|
|
|
AT m_addr;
|
|
|
|
|
|
|
|
|
|
public:
|
2014-09-01 18:16:44 +02:00
|
|
|
typedef T type;
|
2014-09-01 23:22:07 +02:00
|
|
|
typedef typename remove_be_t<T>::type le_type;
|
|
|
|
|
typedef typename to_be_t<T>::type be_type;
|
2014-09-01 18:16:44 +02:00
|
|
|
|
2014-08-01 18:27:48 +02:00
|
|
|
operator T&()
|
|
|
|
|
{
|
|
|
|
|
return get_ref<T>(m_addr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
operator const T&() const
|
|
|
|
|
{
|
|
|
|
|
return get_ref<const T>(m_addr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AT addr() const
|
|
|
|
|
{
|
|
|
|
|
return m_addr;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-31 17:01:48 +02:00
|
|
|
static _ref_base make(AT addr)
|
2014-08-01 18:27:48 +02:00
|
|
|
{
|
2014-08-31 01:06:43 +02:00
|
|
|
return (_ref_base&)addr;
|
2014-08-01 18:27:48 +02:00
|
|
|
}
|
2014-09-01 23:22:07 +02:00
|
|
|
|
|
|
|
|
_ref_base& operator = (le_type right)
|
|
|
|
|
{
|
|
|
|
|
get_ref<T>(m_addr) = right;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const _ref_base& operator = (le_type right) const
|
|
|
|
|
{
|
|
|
|
|
get_ref<T>(m_addr) = right;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_ref_base& operator = (be_type right)
|
|
|
|
|
{
|
|
|
|
|
get_ref<T>(m_addr) = right;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const _ref_base& operator = (be_type right) const
|
|
|
|
|
{
|
|
|
|
|
get_ref<T>(m_addr) = right;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
2014-08-01 18:27:48 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//BE reference to LE data
|
2014-09-01 18:16:44 +02:00
|
|
|
template<typename T, typename AT = u32> struct brefl : public _ref_base<T, typename to_be_t<AT>::type>
|
|
|
|
|
{
|
2014-09-01 23:41:36 +02:00
|
|
|
using _ref_base<T, typename to_be_t<AT>::type>::operator=;
|
2014-09-01 18:16:44 +02:00
|
|
|
};
|
2014-08-01 18:27:48 +02:00
|
|
|
|
|
|
|
|
//BE reference to BE data
|
2014-09-01 18:16:44 +02:00
|
|
|
template<typename T, typename AT = u32> struct brefb : public _ref_base<typename to_be_t<T>::type, typename to_be_t<AT>::type>
|
|
|
|
|
{
|
2014-09-01 23:41:36 +02:00
|
|
|
using _ref_base<typename to_be_t<T>::type, typename to_be_t<AT>::type>::operator=;
|
2014-09-01 18:16:44 +02:00
|
|
|
};
|
2014-08-01 18:27:48 +02:00
|
|
|
|
|
|
|
|
//LE reference to BE data
|
2014-09-01 18:16:44 +02:00
|
|
|
template<typename T, typename AT = u32> struct lrefb : public _ref_base<typename to_be_t<T>::type, AT>
|
|
|
|
|
{
|
2014-09-01 23:41:36 +02:00
|
|
|
using _ref_base<typename to_be_t<T>::type, AT>::operator=;
|
2014-09-01 18:16:44 +02:00
|
|
|
};
|
2014-08-01 18:27:48 +02:00
|
|
|
|
|
|
|
|
//LE reference to LE data
|
2014-09-01 18:16:44 +02:00
|
|
|
template<typename T, typename AT = u32> struct lrefl : public _ref_base<T, AT>
|
|
|
|
|
{
|
2014-09-01 23:41:36 +02:00
|
|
|
using _ref_base<T, AT>::operator=;
|
2014-09-01 18:16:44 +02:00
|
|
|
};
|
2014-08-01 18:27:48 +02:00
|
|
|
|
|
|
|
|
namespace ps3
|
|
|
|
|
{
|
|
|
|
|
//default reference for HLE functions (LE reference to BE data)
|
2014-09-01 18:16:44 +02:00
|
|
|
template<typename T, typename AT = u32> struct ref : public lrefb<T, AT>
|
|
|
|
|
{
|
2014-09-01 23:41:36 +02:00
|
|
|
using lrefb<T, AT>::operator=;
|
2014-09-01 18:16:44 +02:00
|
|
|
};
|
2014-08-01 18:27:48 +02:00
|
|
|
|
|
|
|
|
//default reference for HLE structures (BE reference to BE data)
|
2014-09-01 18:16:44 +02:00
|
|
|
template<typename T, typename AT = u32> struct bref : public brefb<T, AT>
|
|
|
|
|
{
|
2014-09-01 23:41:36 +02:00
|
|
|
using brefb<T, AT>::operator=;
|
2014-09-01 18:16:44 +02:00
|
|
|
};
|
2014-08-01 18:27:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace psv
|
|
|
|
|
{
|
|
|
|
|
//default reference for HLE functions & structures (LE reference to LE data)
|
2014-09-01 18:16:44 +02:00
|
|
|
template<typename T, typename AT = u32> struct ref : public lrefl<T, AT>
|
|
|
|
|
{
|
2014-09-01 23:46:02 +02:00
|
|
|
using lrefl<T, AT>::operator=;
|
2014-09-01 18:16:44 +02:00
|
|
|
};
|
2014-08-01 18:27:48 +02:00
|
|
|
}
|
2014-09-01 18:16:44 +02:00
|
|
|
|
|
|
|
|
//PS3 emulation is main now, so lets it be as default
|
|
|
|
|
using namespace ps3;
|
2015-01-13 18:38:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace fmt
|
|
|
|
|
{
|
|
|
|
|
// external specializations for fmt::format function
|
|
|
|
|
namespace detail
|
|
|
|
|
{
|
|
|
|
|
template<typename T, typename AT>
|
|
|
|
|
struct get_fmt<vm::ps3::ref<T, AT>, false>
|
|
|
|
|
{
|
|
|
|
|
__forceinline static std::string text(const char* fmt, size_t len, const vm::ps3::ref<T, AT>& arg)
|
|
|
|
|
{
|
|
|
|
|
return get_fmt<AT>::text(fmt, len, arg.addr());
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<typename T, typename AT>
|
|
|
|
|
struct get_fmt<vm::ps3::bref<T, AT>, false>
|
|
|
|
|
{
|
|
|
|
|
__forceinline static std::string text(const char* fmt, size_t len, const vm::ps3::bref<T, AT>& arg)
|
|
|
|
|
{
|
|
|
|
|
return get_fmt<AT>::text(fmt, len, arg.addr());
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<typename T, typename AT>
|
|
|
|
|
struct get_fmt<vm::psv::ref<T, AT>, false>
|
|
|
|
|
{
|
|
|
|
|
__forceinline static std::string text(const char* fmt, size_t len, const vm::psv::ref<T, AT>& arg)
|
|
|
|
|
{
|
|
|
|
|
return get_fmt<AT>::text(fmt, len, arg.addr());
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|