1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 10:42:36 +01:00

Improved mem_ptr_t.

Implemented mem_func_ptr_t.
This commit is contained in:
DH 2014-06-01 12:38:37 +03:00
parent da2c5bbda0
commit c00f4b6022
4 changed files with 171 additions and 169 deletions

View File

@ -87,7 +87,7 @@ MemoryBlock* MemoryBlock::SetRange(const u64 start, const u32 size)
bool MemoryBlock::IsMyAddress(const u64 addr)
{
return mem && addr >= GetStartAddr() && addr <= GetEndAddr();
return mem && addr >= GetStartAddr() && addr < GetEndAddr();
}
template <typename T>

View File

@ -598,147 +598,216 @@ public:
{
return m_addr == 0;
}
bool operator == (const mem_base_t& right) const { return m_addr == right.m_addr; }
bool operator != (const mem_base_t& right) const { return m_addr != right.m_addr; }
bool operator > (const mem_base_t& right) const { return m_addr > right.m_addr; }
bool operator < (const mem_base_t& right) const { return m_addr < right.m_addr; }
bool operator >= (const mem_base_t& right) const { return m_addr >= right.m_addr; }
bool operator <= (const mem_base_t& right) const { return m_addr <= right.m_addr; }
bool operator == (T* right) const { return (T*)&Memory[m_addr] == right; }
bool operator != (T* right) const { return (T*)&Memory[m_addr] != right; }
bool operator > (T* right) const { return (T*)&Memory[m_addr] > right; }
bool operator < (T* right) const { return (T*)&Memory[m_addr] < right; }
bool operator >= (T* right) const { return (T*)&Memory[m_addr] >= right; }
bool operator <= (T* right) const { return (T*)&Memory[m_addr] <= right; }
};
template<typename T, typename AT = u32>
class mem_ptr_t : public mem_base_t<T, AT>
template<typename T, int lvl = 1, typename AT = u32>
class mem_ptr_t : public mem_base_t<AT, AT>
{
public:
mem_ptr_t(AT addr) : mem_base_t<AT, AT>(addr)
{
}
template<typename NT> operator mem_ptr_t<NT, lvl, AT>&() { return (mem_ptr_t<NT, lvl, AT>&)*this; }
template<typename NT> operator const mem_ptr_t<NT, lvl, AT>&() const { return (const mem_ptr_t<NT, lvl, AT>&)*this; }
mem_ptr_t operator++ (int)
{
mem_ptr_t ret(m_addr);
m_addr += sizeof(AT);
return ret;
}
mem_ptr_t& operator++ ()
{
m_addr += sizeof(AT);
return *this;
}
mem_ptr_t operator-- (int)
{
mem_ptr_t ret(m_addr);
m_addr -= sizeof(AT);
return ret;
}
mem_ptr_t& operator-- ()
{
m_addr -= sizeof(AT);
return *this;
}
mem_ptr_t& operator += (uint count)
{
m_addr += count * sizeof(AT);
return *this;
}
mem_ptr_t& operator -= (uint count)
{
m_addr -= count * sizeof(AT);
return *this;
}
mem_ptr_t operator + (uint count) const
{
return m_addr + count * sizeof(AT);
}
mem_ptr_t operator - (uint count) const
{
return m_addr - count * sizeof(AT);
}
__forceinline mem_ptr_t<T, lvl - 1, AT>& operator *()
{
return (mem_ptr_t<T, lvl - 1, AT>&)Memory[m_addr];
}
__forceinline const mem_ptr_t<T, lvl - 1, AT>& operator *() const
{
return (const mem_ptr_t<T, lvl - 1, AT>&)Memory[m_addr];
}
__forceinline mem_ptr_t<T, lvl - 1, AT>& operator [](uint index)
{
return (mem_ptr_t<T, lvl - 1, AT>&)Memory[m_addr + sizeof(AT) * index];
}
__forceinline const mem_ptr_t<T, lvl - 1, AT>& operator [](uint index) const
{
return (const mem_ptr_t<T, lvl - 1, AT>&)Memory[m_addr + sizeof(AT) * index];
}
bool IsGood() const
{
return (*this)->IsGood() && mem_base_t<T, AT>::IsGood();
}
__forceinline bool IsGoodAddr() const
{
return mem_base_t<T, AT>::IsGood();
}
};
template<typename T, typename AT>
class mem_ptr_t<T, 1, AT> : public mem_base_t<T, AT>
{
public:
mem_ptr_t(AT addr) : mem_base_t<T, AT>(addr)
{
}
template<typename NT> operator mem_ptr_t<NT, AT>&() { return (mem_ptr_t<NT, AT>&)*this; }
template<typename NT> operator const mem_ptr_t<NT, AT>&() const { return (const mem_ptr_t<NT, AT>&)*this; }
template<typename NT> operator mem_ptr_t<NT, 1, AT>&() { return (mem_ptr_t<NT, 1, AT>&)*this; }
template<typename NT> operator const mem_ptr_t<NT, 1, AT>&() const { return (const mem_ptr_t<NT, 1, AT>&)*this; }
T* operator -> ()
__forceinline T* operator -> ()
{
return (T*)&Memory[this->m_addr];
return (T*)&Memory[m_addr];
}
const T* operator -> () const
__forceinline const T* operator -> () const
{
return (const T*)&Memory[this->m_addr];
return (const T*)&Memory[m_addr];
}
mem_ptr_t operator++ (int)
{
mem_ptr_t ret(this->m_addr);
this->m_addr += sizeof(T);
mem_ptr_t ret(m_addr);
m_addr += sizeof(T);
return ret;
}
mem_ptr_t& operator++ ()
{
this->m_addr += sizeof(T);
m_addr += sizeof(T);
return *this;
}
mem_ptr_t operator-- (int)
{
mem_ptr_t ret(this->m_addr);
this->m_addr -= sizeof(T);
mem_ptr_t ret(m_addr);
m_addr -= sizeof(T);
return ret;
}
mem_ptr_t& operator-- ()
{
this->m_addr -= sizeof(T);
m_addr -= sizeof(T);
return *this;
}
mem_ptr_t& operator += (uint count)
{
this->m_addr += count * sizeof(T);
m_addr += count * sizeof(T);
return *this;
}
mem_ptr_t& operator -= (uint count)
{
this->m_addr -= count * sizeof(T);
m_addr -= count * sizeof(T);
return *this;
}
mem_ptr_t operator + (uint count) const
{
return this->m_addr + count * sizeof(T);
return m_addr + count * sizeof(T);
}
mem_ptr_t operator - (uint count) const
{
return this->m_addr - count * sizeof(T);
return m_addr - count * sizeof(T);
}
T& operator *()
__forceinline T& operator *()
{
return (T&)Memory[this->m_addr];
return (T&)Memory[m_addr];
}
const T& operator *() const
__forceinline const T& operator *() const
{
return (T&)Memory[this->m_addr];
return (T&)Memory[m_addr];
}
T& operator [](uint index)
__forceinline T& operator [](uint index)
{
return (T&)Memory[this->m_addr + sizeof(T) * index];
return (T&)Memory[m_addr + sizeof(T) * index];
}
const T& operator [](uint index) const
__forceinline const T& operator [](uint index) const
{
return (const T&)Memory[this->m_addr + sizeof(T) * index];
return (const T&)Memory[m_addr + sizeof(T) * index];
}
bool operator == (mem_ptr_t right) const { return this->m_addr == right.m_addr; }
bool operator != (mem_ptr_t right) const { return this->m_addr != right.m_addr; }
bool operator > (mem_ptr_t right) const { return this->m_addr > right.m_addr; }
bool operator < (mem_ptr_t right) const { return this->m_addr < right.m_addr; }
bool operator >= (mem_ptr_t right) const { return this->m_addr >= right.m_addr; }
bool operator <= (mem_ptr_t right) const { return this->m_addr <= right.m_addr; }
bool operator == (T* right) const { return (T*)&Memory[this->m_addr] == right; }
bool operator != (T* right) const { return (T*)&Memory[this->m_addr] != right; }
bool operator > (T* right) const { return (T*)&Memory[this->m_addr] > right; }
bool operator < (T* right) const { return (T*)&Memory[this->m_addr] < right; }
bool operator >= (T* right) const { return (T*)&Memory[this->m_addr] >= right; }
bool operator <= (T* right) const { return (T*)&Memory[this->m_addr] <= right; }
};
template<typename AT>
class mem_ptr_t<void, AT> : public mem_base_t<u8, AT>
class mem_ptr_t<void, 1, AT> : public mem_base_t<u8, AT>
{
public:
mem_ptr_t(AT addr) : mem_base_t<u8, AT>(addr)
{
}
template<typename NT> operator mem_ptr_t<NT>&() { return (mem_ptr_t<NT>&)*this; }
template<typename NT> operator const mem_ptr_t<NT>&() const { return (const mem_ptr_t<NT>&)*this; }
bool operator == (mem_ptr_t right) const { return this->m_addr == right.m_addr; }
bool operator != (mem_ptr_t right) const { return this->m_addr != right.m_addr; }
bool operator > (mem_ptr_t right) const { return this->m_addr > right.m_addr; }
bool operator < (mem_ptr_t right) const { return this->m_addr < right.m_addr; }
bool operator >= (mem_ptr_t right) const { return this->m_addr >= right.m_addr; }
bool operator <= (mem_ptr_t right) const { return this->m_addr <= right.m_addr; }
bool operator == (void* right) const { return (void*)&Memory[this->m_addr] == right; }
bool operator != (void* right) const { return (void*)&Memory[this->m_addr] != right; }
bool operator > (void* right) const { return (void*)&Memory[this->m_addr] > right; }
bool operator < (void* right) const { return (void*)&Memory[this->m_addr] < right; }
bool operator >= (void* right) const { return (void*)&Memory[this->m_addr] >= right; }
bool operator <= (void* right) const { return (void*)&Memory[this->m_addr] <= right; }
template<typename NT> operator mem_ptr_t<NT, 1, AT>&() { return (mem_ptr_t<NT, 1, AT>&)*this; }
template<typename NT> operator const mem_ptr_t<NT, 1, AT>&() const { return (const mem_ptr_t<NT, 1, AT>&)*this; }
};
template<typename T> static bool operator == (T* left, mem_ptr_t<T> right) { return left == (T*)&Memory[right.GetAddr()]; }
template<typename T> static bool operator != (T* left, mem_ptr_t<T> right) { return left != (T*)&Memory[right.GetAddr()]; }
template<typename T> static bool operator > (T* left, mem_ptr_t<T> right) { return left > (T*)&Memory[right.GetAddr()]; }
template<typename T> static bool operator < (T* left, mem_ptr_t<T> right) { return left < (T*)&Memory[right.GetAddr()]; }
template<typename T> static bool operator >= (T* left, mem_ptr_t<T> right) { return left >= (T*)&Memory[right.GetAddr()]; }
template<typename T> static bool operator <= (T* left, mem_ptr_t<T> right) { return left <= (T*)&Memory[right.GetAddr()]; }
template<typename T, typename AT = u32>
class mem_beptr_t : public mem_ptr_t<T, be_t<AT>> {};
template<typename T, int lvl = 1, typename AT = u32>
class mem_beptr_t : public mem_ptr_t<T, lvl, be_t<AT>> {};
template<typename T, typename AT = u32> class mem_t : public mem_base_t<T, AT>
{
@ -749,19 +818,19 @@ public:
mem_t& operator = (T right)
{
(be_t<T>&)Memory[this->m_addr] = right;
(be_t<T>&)Memory[m_addr] = right;
return *this;
}
__forceinline T GetValue()
{
return (be_t<T>&)Memory[this->m_addr];
return (be_t<T>&)Memory[m_addr];
}
operator const T() const
{
return (be_t<T>&)Memory[this->m_addr];
return (be_t<T>&)Memory[m_addr];
}
mem_t& operator += (T right) { return *this = (*this) + right; }
@ -776,7 +845,7 @@ public:
mem_t& operator >>= (T right) { return *this = (*this) >> right; }
};
template<typename T, typename AT=u32> class mem_list_ptr_t : public mem_base_t<T, AT>
template<typename T, typename AT = u32> class mem_list_ptr_t : public mem_base_t<T, AT>
{
public:
mem_list_ptr_t(u32 addr) : mem_base_t<T>(addr)
@ -785,23 +854,24 @@ public:
void operator = (T right)
{
(be_t<T>&)Memory[this->m_addr] = right;
(be_t<T>&)Memory[m_addr] = right;
}
u32 operator += (T right)
{
*this = right;
this->m_addr += sizeof(T);
return this->m_addr;
m_addr += sizeof(T);
return m_addr;
}
u32 AppendRawBytes(const u8 *bytes, size_t count)
{
Memory.CopyFromReal(m_addr, bytes, count);
m_addr += count;
return m_addr;
}
u32 AppendRawBytes(const u8 * bytes, size_t count) {
Memory.CopyFromReal(this->m_addr, bytes, count);
this->m_addr += count;
return this->m_addr;
}
u32 Skip(const u32 offset) { return this->m_addr += offset; }
u32 Skip(const u32 offset) { return m_addr += offset; }
operator be_t<T>*() { return GetPtr(); }
operator void*() { return GetPtr(); }
@ -810,17 +880,17 @@ public:
const char* GetString() const
{
return (const char*)&Memory[this->m_addr];
return (const char*)&Memory[m_addr];
}
be_t<T>* GetPtr()
{
return (be_t<T>*)&Memory[this->m_addr];
return (be_t<T>*)&Memory[m_addr];
}
const be_t<T>* GetPtr() const
{
return (const be_t<T>*)&Memory[this->m_addr];
return (const be_t<T>*)&Memory[m_addr];
}
};
@ -871,8 +941,8 @@ struct _func_arg<mem_base_t<T, u32>>
}
};
template<typename T> struct _func_arg<mem_ptr_t<T, u32>> : public _func_arg<mem_base_t<T, u32>> {};
template<> struct _func_arg<mem_ptr_t<void, u32>> : public _func_arg<mem_base_t<u8, u32>> {};
template<typename T, int lvl> struct _func_arg<mem_ptr_t<T, lvl, u32>> : public _func_arg<mem_base_t<T, u32>> {};
template<int lvl> struct _func_arg<mem_ptr_t<void, lvl, u32>> : public _func_arg<mem_base_t<u8, u32>>{};
template<typename T> struct _func_arg<mem_list_ptr_t<T, u32>> : public _func_arg<mem_base_t<T, u32>> {};
template<typename T> struct _func_arg<mem_t<T, u32>> : public _func_arg<mem_base_t<T, u32>> {};
@ -885,10 +955,11 @@ struct _func_arg<be_t<T>>
}
};
template<typename T> class mem_func_ptr_t;
template<typename T, typename AT = u32> class mem_func_ptr_t;
template<typename T, typename AT = u32> class mem_func_beptr_t : public mem_func_ptr_t<T, be_t<AT>> {};
template<typename RT>
class mem_func_ptr_t<RT (*)()> : public mem_base_t<u64>
template<typename RT, typename AT>
class mem_func_ptr_t<RT (*)(), AT> : public mem_base_t<u64, AT>
{
__forceinline void call_func(bool is_async)
{
@ -909,95 +980,26 @@ public:
}
};
template<typename RT, typename T1>
class mem_func_ptr_t<RT (*)(T1)> : public mem_base_t<u64>
template<typename AT, typename RT, typename ...T>
class mem_func_ptr_t<RT(*)(T...), AT> : public mem_base_t<u64, AT>
{
__forceinline void call_func(bool is_async, T1 a1)
__forceinline void call_func(bool is_async, T... args)
{
Callback cb;
cb.SetAddr(m_addr);
cb.Handle(_func_arg<T1>::get_value(a1));
cb.Handle(_func_arg<T>::get_value(args)...);
cb.Branch(!is_async);
}
public:
__forceinline void operator()(T1 a1)
__forceinline void operator()(T... args)
{
call_func(false, a1);
call_func(false, args...);
}
__forceinline void async(T1 a1)
__forceinline void async(T... args)
{
call_func(true, a1);
}
};
template<typename RT, typename T1, typename T2>
class mem_func_ptr_t<RT (*)(T1, T2)> : public mem_base_t<u64>
{
__forceinline void call_func(bool is_async, T1 a1, T2 a2)
{
Callback cb;
cb.SetAddr(m_addr);
cb.Handle(_func_arg<T1>::get_value(a1), _func_arg<T2>::get_value(a2));
cb.Branch(!is_async);
}
public:
__forceinline void operator()(T1 a1, T2 a2)
{
call_func(false, a1, a2);
}
__forceinline void async(T1 a1, T2 a2)
{
call_func(true, a1, a2);
}
};
template<typename RT, typename T1, typename T2, typename T3>
class mem_func_ptr_t<RT (*)(T1, T2, T3)> : public mem_base_t<u64>
{
__forceinline void call_func(bool is_async, T1 a1, T2 a2, T3 a3)
{
Callback cb;
cb.SetAddr(m_addr);
cb.Handle(_func_arg<T1>::get_value(a1), _func_arg<T2>::get_value(a2), _func_arg<T3>::get_value(a3));
cb.Branch(!is_async);
}
public:
__forceinline void operator()(T1 a1, T2 a2, T3 a3)
{
call_func(false, a1, a2, a3);
}
__forceinline void async(T1 a1, T2 a2, T3 a3)
{
call_func(true, a1, a2, a3);
}
};
template<typename RT, typename T1, typename T2, typename T3, typename T4>
class mem_func_ptr_t<RT (*)(T1, T2, T3, T4)> : public mem_base_t<u64>
{
__forceinline void call_func(bool is_async, T1 a1, T2 a2, T3 a3, T4 a4)
{
Callback cb;
cb.SetAddr(m_addr);
cb.Handle(_func_arg<T1>::get_value(a1), _func_arg<T2>::get_value(a2), _func_arg<T3>::get_value(a3), _func_arg<T4>::get_value(a4));
cb.Branch(!is_async);
}
public:
__forceinline void operator()(T1 a1, T2 a2, T3 a3, T4 a4)
{
call_func(false, a1, a2, a3, a4);
}
__forceinline void async(T1 a1, T2 a2, T3 a3, T4 a4)
{
call_func(true, a1, a2, a3, a4);
call_func(true, args...);
}
};

View File

@ -256,8 +256,8 @@ int cellGcmSetDebugOutputLevel(int level)
int cellGcmSetDisplayBuffer(u32 id, u32 offset, u32 pitch, u32 width, u32 height)
{
cellGcmSys.Warning("cellGcmSetDisplayBuffer(id=0x%x,offset=0x%x,pitch=%d,width=%d,height=%d)",
id, offset, width ? pitch/width : pitch, width, height);
//cellGcmSys.Warning("cellGcmSetDisplayBuffer(id=0x%x,offset=0x%x,pitch=%d,width=%d,height=%d)",
// id, offset, width ? pitch/width : pitch, width, height);
if(id > 7) return CELL_EINVAL;
gcmBuffer* buffers = (gcmBuffer*)Memory.GetMemFromAddr(Emu.GetGSManager().GetRender().m_gcm_buffers_addr);

View File

@ -857,7 +857,7 @@ int cellHddGameCheck(u32 version, u32 dirName_addr, u32 errDialog, mem_func_ptr_
MemoryAllocator<CellHddGameStatGet> get;
MemoryAllocator<CellHddGameStatSet> set;
get->hddFreeSizeKB = 40000000; // 40 GB, TODO: Use the free space of the computer's HDD where RPCS3 is being run.
get->hddFreeSizeKB = 40 * 1024 * 1024; // 40 GB, TODO: Use the free space of the computer's HDD where RPCS3 is being run.
get->isNewData = CELL_HDDGAME_ISNEWDATA_EXIST;
get->sysSizeKB = 0; // TODO
get->st_atime__ = 0; // TODO