diff --git a/Core/MemMap.h b/Core/MemMap.h index 416891e015..9d06555653 100644 --- a/Core/MemMap.h +++ b/Core/MemMap.h @@ -269,17 +269,82 @@ struct PSPPointer { u32 ptr; - T &operator*() const + inline T &operator*() const { return *(T *)(Memory::base + ptr); } - T &operator[](int i) const + inline T &operator[](int i) const { return *((T *)(Memory::base + ptr) + i); } - T *operator->() const + inline T *operator->() const + { + return (T *)(Memory::base + ptr); + } + + inline PSPPointer operator+(int i) const + { + PSPPointer other; + other.ptr = ptr + i * sizeof(T); + return other; + } + + inline PSPPointer &operator=(u32 p) + { + ptr = p; + return *this; + } + + inline PSPPointer &operator+=(int i) + { + ptr = ptr + i * sizeof(T); + return *this; + } + + inline PSPPointer operator-(int i) const + { + PSPPointer other; + other.ptr = ptr - i * sizeof(T); + return other; + } + + inline PSPPointer &operator-=(int i) + { + ptr = ptr - i * sizeof(T); + return *this; + } + + inline PSPPointer &operator++() + { + ptr += sizeof(T); + return *this; + } + + inline PSPPointer operator++(int i) + { + PSPPointer other; + other.ptr = ptr; + ptr += sizeof(T); + return other; + } + + inline PSPPointer &operator--() + { + ptr -= sizeof(T); + return *this; + } + + inline PSPPointer operator--(int i) + { + PSPPointer other; + other.ptr = ptr; + ptr -= sizeof(T); + return other; + } + + inline operator T*() { return (T *)(Memory::base + ptr); } @@ -290,5 +355,41 @@ struct PSPPointer } }; +template +inline bool operator==(const PSPPointer &lhs, const PSPPointer &rhs) +{ + return lhs.ptr == rhs.ptr; +} + +template +inline bool operator!=(const PSPPointer &lhs, const PSPPointer &rhs) +{ + return lhs.ptr != rhs.ptr; +} + +template +inline bool operator<(const PSPPointer &lhs, const PSPPointer &rhs) +{ + return lhs.ptr < rhs.ptr; +} + +template +inline bool operator>(const PSPPointer &lhs, const PSPPointer &rhs) +{ + return lhs.ptr > rhs.ptr; +} + +template +inline bool operator<=(const PSPPointer &lhs, const PSPPointer &rhs) +{ + return lhs.ptr <= rhs.ptr; +} + +template +inline bool operator>=(const PSPPointer &lhs, const PSPPointer &rhs) +{ + return lhs.ptr >= rhs.ptr; +} + #endif