diff options
Diffstat (limited to 'arm9/lib/libnns/include')
-rw-r--r-- | arm9/lib/libnns/include/NNS_FND_heapcommon.h | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/arm9/lib/libnns/include/NNS_FND_heapcommon.h b/arm9/lib/libnns/include/NNS_FND_heapcommon.h index e6fab69c..8128e74b 100644 --- a/arm9/lib/libnns/include/NNS_FND_heapcommon.h +++ b/arm9/lib/libnns/include/NNS_FND_heapcommon.h @@ -7,6 +7,18 @@ typedef struct NNSiFndHeapHead NNSiFndHeapHead; +typedef s32 NNSiIntPtr; +typedef u32 NNSiUIntPtr; + +#define NNSi_FndGetBitValue(data, st, bits) (((data) >>(st)) & ((1 <<(bits)) -1)) +#define NNSi_FndSetBitValue(data, st, bits, val) do { \ + u32 maskBits = (u32)((1 << (bits)) - 1); \ + u32 newVal = (val) & maskBits; \ + (void)(maskBits <<= st); \ + (data) &= ~maskBits; \ + (data) |= newVal << (st); \ +} while (FALSE); + struct NNSiFndHeapHead { u32 signature; @@ -23,4 +35,56 @@ struct NNSiFndHeapHead typedef NNSiFndHeapHead* NNSFndHeapHandle; // Type to represent heap handle +static inline NNSiUIntPtr NNSiGetUIntPtr(const void* ptr) +{ + return (NNSiUIntPtr)ptr; +} + +static inline u32 GetOffsetFromPtr(const void* start, const void* end) +{ + return NNSiGetUIntPtr(end) - NNSiGetUIntPtr(start); +} + +static inline void* AddU32ToPtr(void* ptr, u32 val) +{ + return (void*)( NNSiGetUIntPtr(ptr) + val ); +} + +static inline const void* AddU32ToCPtr(const void* ptr, u32 val) +{ + return (const void*)( NNSiGetUIntPtr(ptr) + val ); +} + +static inline void* SubU32ToPtr(void* ptr, u32 val) +{ + return (void*)(NNSiGetUIntPtr(ptr) - val); +} + +static inline const void* SubU32ToCPtr(const void* ptr, u32 val) +{ + return (const void*)(NNSiGetUIntPtr(ptr) - val); +} + +static inline int ComparePtr(const void* a, const void* b) +{ + const u8* wa = a; + const u8* wb = b; + + return wa - wb; +} + + +static inline u16 GetOptForHeap(const NNSiFndHeapHead* pHeapHd) +{ + return (u16)NNSi_FndGetBitValue(pHeapHd->attribute, 0, 8); +} + +static inline void SetOptForHeap( + NNSiFndHeapHead* pHeapHd, + u16 optFlag + ) +{ + NNSi_FndSetBitValue(pHeapHd->attribute, 0, 8, optFlag); +} + #endif //GUARD_NNS_FND_HEAPCOMMON_H |