Improved to_be_t

Fixed cellCameraGetType
Removed be_array_t
Improved cb_caller
This commit is contained in:
DHrpcs3 2014-09-16 14:23:58 +03:00
parent 29c2e84fa1
commit b0569639a9
4 changed files with 70 additions and 59 deletions

View File

@ -294,38 +294,49 @@ public:
return ToLE();
}
be_t& operator = (const be_t& value) = default;
be_t& operator = (T value)
{
m_data = se_t<T, sizeof(T2)>::func(value);
return *this;
}
template<typename T1>
operator const be_t<T1>() const
{
if (sizeof(T1) > sizeof(T) || std::is_floating_point<T>::value || std::is_floating_point<T1>::value)
template<typename Tto, typename Tfrom, int mode>
struct _convert
{
T1 res = se_t<T1, sizeof(T1)>::func(ToLE());
return (be_t<T1>&)res;
}
else if (sizeof(T1) < sizeof(T))
static __forceinline be_t<Tto>& func(Tfrom& be_value)
{
Tto res = be_value;
return (be_t<Tto>&)res;
}
};
template<typename Tto, typename Tfrom>
struct _convert<Tto, Tfrom, 1>
{
T1 res = ToBE() >> ((sizeof(T) - sizeof(T1)) * 8);
return (be_t<T1>&)res;
}
else
static __forceinline be_t<Tto>& func(Tfrom& be_value)
{
Tto res = se_t<Tto, sizeof(Tto)>::func(se_t<Tfrom, sizeof(Tfrom)>::func(be_value););
return (be_t<Tto>&)res;
}
};
template<typename Tto, typename Tfrom>
struct _convert<Tto, Tfrom, 2>
{
T1 res = ToBE();
return (be_t<T1>&)res;
}
}
static __forceinline be_t<Tto>& func(Tfrom& be_value)
{
Tto res = be_value >> ((sizeof(Tfrom)-sizeof(Tto)) * 8);
return (be_t<Tto>&)res;
}
};
be_t& operator = (const T& right)
{
m_data = se_t<T, sizeof(T2)>::func(right);
return *this;
}
be_t& operator = (const be_t& right) = default;
be_t& operator = (const be_t<const T, const T2>& right)
{
m_data = right.ToBE();
return *this;
return _convert<T1, T, ((sizeof(T1) > sizeof(T)) ? 1 : (sizeof(T1) < sizeof(T) ? 2 : 0))>::func(m_data);
}
template<typename T1> be_t& operator += (T1 right) { return *this = T(*this) + right; }
@ -482,7 +493,7 @@ class to_be_t
public:
//true if need swap endianes for be
static const bool value = (sizeof(T2) > 1) && std::is_arithmetic<T>::value;
static const bool value = (sizeof(T2) > 1) && (std::is_arithmetic<T>::value || std::is_enum<T>::value);
//be_t<T, size> if need swap endianes, T otherwise
typedef typename _be_type_selector< T, T2, value >::type type;
@ -530,24 +541,6 @@ template<typename T, typename T1, T1 value> struct _se<be_t<T>, T1, value> : pub
#define se32(x) _se<u32, decltype(x), x>::value
#define se64(x) _se<u64, decltype(x), x>::value
// template that helps to define be_t arrays in unions
template<typename T, size_t size>
class be_array_t
{
be_t<T> data[size];
public:
__forceinline be_t<T>& operator [] (size_t index)
{
return data[index];
}
__forceinline const be_t<T>& operator [] (size_t index) const
{
return data[index];
}
};
template<typename T> __forceinline static u8 Read8(T& f)
{
u8 ret;

View File

@ -146,13 +146,25 @@ namespace cb_detail
{
__forceinline static RT call(PPUThread& CPU, u32 pc, u32 rtoc, T... args)
{
const bool stack = _bind_func_args<0, 0, 0>(CPU, args...);
const bool stack = _bind_func_args<0, 0, 0, T...>(CPU, args...);
if (stack) CPU.GPR[1] -= FIXED_STACK_FRAME_SIZE;
CPU.FastCall2(pc, rtoc);
if (stack) CPU.GPR[1] += FIXED_STACK_FRAME_SIZE;
return _func_res<RT>::get_value(CPU);
}
};
template<typename... T>
struct _func_caller<void, T...>
{
__forceinline static void call(PPUThread& CPU, u32 pc, u32 rtoc, T... args)
{
const bool stack = _bind_func_args<0, 0, 0, T...>(CPU, args...);
if (stack) CPU.GPR[1] -= FIXED_STACK_FRAME_SIZE;
CPU.FastCall2(pc, rtoc);
if (stack) CPU.GPR[1] += FIXED_STACK_FRAME_SIZE;
}
};
}
namespace vm
@ -174,6 +186,13 @@ namespace vm
}
template<typename RT, typename... T>
struct cb_caller : public cb_detail::_func_caller<RT, T...>
RT cb_call(PPUThread& CPU, u32 pc, u32 rtoc, T... args)
{
};
return cb_detail::_func_caller<RT, T...>::call(CPU, pc, rtoc, args...);
}
template<typename... T>
void cb_call(PPUThread& CPU, u32 pc, u32 rtoc, T... args)
{
cb_detail::_func_caller<void, T...>::call(CPU, pc, rtoc, args...);
}

View File

@ -68,18 +68,17 @@ int cellCameraGetDeviceGUID()
return CELL_OK;
}
int cellCameraGetType(s32 dev_num, CellCameraType type)
int cellCameraGetType(s32 dev_num, vm::ptr<CellCameraType> type)
{
cellCamera->Warning("cellCameraGetType(dev_num=%d, type_addr=0x%x)", dev_num, type);
if (Ini.CameraType.GetValue() == 1)
type = CELL_CAMERA_EYETOY;
else if (Ini.CameraType.GetValue() == 2)
type = CELL_CAMERA_EYETOY2;
else if (Ini.CameraType.GetValue() == 3)
type == CELL_CAMERA_USBVIDEOCLASS;
else
type = CELL_CAMERA_TYPE_UNKNOWN;
switch (Ini.CameraType.GetValue())
{
case 1: *type = CELL_CAMERA_EYETOY; break;
case 2: *type = CELL_CAMERA_EYETOY2; break;
case 3: *type = CELL_CAMERA_USBVIDEOCLASS; break;
default: *type = CELL_CAMERA_TYPE_UNKNOWN; break;
}
return CELL_OK;
}

View File

@ -93,14 +93,14 @@ struct CellSpurs2
struct CellSpursAttribute
{
static const auto align = 8;
static const auto size = 512;
static const uint align = 8;
static const uint size = 512;
union
{
// raw data
u8 _u8[size];
be_array_t<u32, size / sizeof(u32)> _u32;
struct { be_t<u32> _u32[size / sizeof(u32)]; };
// real structure
struct