From c00f4b60224b18f3f91155ac2ca8ed941a0679a6 Mon Sep 17 00:00:00 2001 From: DH Date: Sun, 1 Jun 2014 12:38:37 +0300 Subject: [PATCH] Improved mem_ptr_t. Implemented mem_func_ptr_t. --- rpcs3/Emu/Memory/Memory.cpp | 2 +- rpcs3/Emu/Memory/Memory.h | 332 +++++++++++---------- rpcs3/Emu/SysCalls/Modules/cellGcmSys.cpp | 4 +- rpcs3/Emu/SysCalls/Modules/cellSysutil.cpp | 2 +- 4 files changed, 171 insertions(+), 169 deletions(-) diff --git a/rpcs3/Emu/Memory/Memory.cpp b/rpcs3/Emu/Memory/Memory.cpp index 7a1ca1e8b2..349c7606fd 100644 --- a/rpcs3/Emu/Memory/Memory.cpp +++ b/rpcs3/Emu/Memory/Memory.cpp @@ -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 diff --git a/rpcs3/Emu/Memory/Memory.h b/rpcs3/Emu/Memory/Memory.h index e5d56a111c..ffecf8e33c 100644 --- a/rpcs3/Emu/Memory/Memory.h +++ b/rpcs3/Emu/Memory/Memory.h @@ -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 -class mem_ptr_t : public mem_base_t +template +class mem_ptr_t : public mem_base_t +{ +public: + mem_ptr_t(AT addr) : mem_base_t(addr) + { + } + + template operator mem_ptr_t&() { return (mem_ptr_t&)*this; } + template operator const mem_ptr_t&() const { return (const mem_ptr_t&)*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& operator *() + { + return (mem_ptr_t&)Memory[m_addr]; + } + + __forceinline const mem_ptr_t& operator *() const + { + return (const mem_ptr_t&)Memory[m_addr]; + } + + __forceinline mem_ptr_t& operator [](uint index) + { + return (mem_ptr_t&)Memory[m_addr + sizeof(AT) * index]; + } + + __forceinline const mem_ptr_t& operator [](uint index) const + { + return (const mem_ptr_t&)Memory[m_addr + sizeof(AT) * index]; + } + + bool IsGood() const + { + return (*this)->IsGood() && mem_base_t::IsGood(); + } + + __forceinline bool IsGoodAddr() const + { + return mem_base_t::IsGood(); + } +}; + +template +class mem_ptr_t : public mem_base_t { public: mem_ptr_t(AT addr) : mem_base_t(addr) { } - template operator mem_ptr_t&() { return (mem_ptr_t&)*this; } - template operator const mem_ptr_t&() const { return (const mem_ptr_t&)*this; } + template operator mem_ptr_t&() { return (mem_ptr_t&)*this; } + template operator const mem_ptr_t&() const { return (const mem_ptr_t&)*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 -class mem_ptr_t : public mem_base_t +class mem_ptr_t : public mem_base_t { public: mem_ptr_t(AT addr) : mem_base_t(addr) { } - template operator mem_ptr_t&() { return (mem_ptr_t&)*this; } - template operator const mem_ptr_t&() const { return (const mem_ptr_t&)*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 operator mem_ptr_t&() { return (mem_ptr_t&)*this; } + template operator const mem_ptr_t&() const { return (const mem_ptr_t&)*this; } }; -template static bool operator == (T* left, mem_ptr_t right) { return left == (T*)&Memory[right.GetAddr()]; } -template static bool operator != (T* left, mem_ptr_t right) { return left != (T*)&Memory[right.GetAddr()]; } -template static bool operator > (T* left, mem_ptr_t right) { return left > (T*)&Memory[right.GetAddr()]; } -template static bool operator < (T* left, mem_ptr_t right) { return left < (T*)&Memory[right.GetAddr()]; } -template static bool operator >= (T* left, mem_ptr_t right) { return left >= (T*)&Memory[right.GetAddr()]; } -template static bool operator <= (T* left, mem_ptr_t right) { return left <= (T*)&Memory[right.GetAddr()]; } - -template -class mem_beptr_t : public mem_ptr_t> {}; +template +class mem_beptr_t : public mem_ptr_t> {}; template class mem_t : public mem_base_t { @@ -749,19 +818,19 @@ public: mem_t& operator = (T right) { - (be_t&)Memory[this->m_addr] = right; + (be_t&)Memory[m_addr] = right; return *this; } __forceinline T GetValue() { - return (be_t&)Memory[this->m_addr]; + return (be_t&)Memory[m_addr]; } operator const T() const { - return (be_t&)Memory[this->m_addr]; + return (be_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 class mem_list_ptr_t : public mem_base_t +template class mem_list_ptr_t : public mem_base_t { public: mem_list_ptr_t(u32 addr) : mem_base_t(addr) @@ -785,23 +854,24 @@ public: void operator = (T right) { - (be_t&)Memory[this->m_addr] = right; + (be_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*() { 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* GetPtr() { - return (be_t*)&Memory[this->m_addr]; + return (be_t*)&Memory[m_addr]; } const be_t* GetPtr() const { - return (const be_t*)&Memory[this->m_addr]; + return (const be_t*)&Memory[m_addr]; } }; @@ -871,8 +941,8 @@ struct _func_arg> } }; -template struct _func_arg> : public _func_arg> {}; -template<> struct _func_arg> : public _func_arg> {}; +template struct _func_arg> : public _func_arg> {}; +template struct _func_arg> : public _func_arg>{}; template struct _func_arg> : public _func_arg> {}; template struct _func_arg> : public _func_arg> {}; @@ -885,10 +955,11 @@ struct _func_arg> } }; -template class mem_func_ptr_t; +template class mem_func_ptr_t; +template class mem_func_beptr_t : public mem_func_ptr_t> {}; -template -class mem_func_ptr_t : public mem_base_t +template +class mem_func_ptr_t : public mem_base_t { __forceinline void call_func(bool is_async) { @@ -909,95 +980,26 @@ public: } }; -template -class mem_func_ptr_t : public mem_base_t +template +class mem_func_ptr_t : public mem_base_t { - __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::get_value(a1)); + cb.Handle(_func_arg::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 -class mem_func_ptr_t : public mem_base_t -{ - __forceinline void call_func(bool is_async, T1 a1, T2 a2) - { - Callback cb; - cb.SetAddr(m_addr); - cb.Handle(_func_arg::get_value(a1), _func_arg::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 -class mem_func_ptr_t : public mem_base_t -{ - __forceinline void call_func(bool is_async, T1 a1, T2 a2, T3 a3) - { - Callback cb; - cb.SetAddr(m_addr); - cb.Handle(_func_arg::get_value(a1), _func_arg::get_value(a2), _func_arg::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 -class mem_func_ptr_t : public mem_base_t -{ - __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::get_value(a1), _func_arg::get_value(a2), _func_arg::get_value(a3), _func_arg::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...); } }; diff --git a/rpcs3/Emu/SysCalls/Modules/cellGcmSys.cpp b/rpcs3/Emu/SysCalls/Modules/cellGcmSys.cpp index 55a01b8af2..d1e10a5e36 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellGcmSys.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellGcmSys.cpp @@ -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); diff --git a/rpcs3/Emu/SysCalls/Modules/cellSysutil.cpp b/rpcs3/Emu/SysCalls/Modules/cellSysutil.cpp index 080e5d4721..e7d5a7f2c2 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellSysutil.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellSysutil.cpp @@ -857,7 +857,7 @@ int cellHddGameCheck(u32 version, u32 dirName_addr, u32 errDialog, mem_func_ptr_ MemoryAllocator get; MemoryAllocator 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