Files
SpaghettiKart/include/macros.h
T
Tyler McGavran c85a333a3f Add new utility to calculate packed dl end and vertex count (#411)
* Add new utility to calculate packed dl end and vertex count

Requires changing a bunch of actual references to packed dl lists
 with raw numbers. Which feels extremely bad but it doesn't match
 otherwise.

Signed-off-by: Taggerung <tyler.taggerung@email.com>

* Hard code array lenghts in appropriate headers

Use macros to generate the vertex counts and packed dl end points

Heavily dependent on the array lengths being accurate. If they
 aren't stuff will break.

Signed-off-by: Taggerung <tyler.taggerung@email.com>
2023-09-10 14:21:16 -06:00

76 lines
1.9 KiB
C

#ifndef _MACROS_H_
#define _MACROS_H_
#ifndef __sgi
#define GLOBAL_ASM(...)
#endif
#if !defined(__sgi) && (!defined(NON_MATCHING) || !defined(AVOID_UB))
// asm-process isn't supported outside of IDO, and undefined behavior causes
// crashes.
//#error Matching build is only possible on IDO; please build with NON_MATCHING=1.
#endif
#define ARRAY_COUNT(arr) (s32)(sizeof(arr) / sizeof(arr[0]))
#define GLUE(a, b) a ## b
#define GLUE2(a, b) GLUE(a, b)
// Avoid compiler warnings for unused variables
#ifdef __GNUC__
#define UNUSED __attribute__((unused))
#else
#define UNUSED
#endif
// Avoid undefined behaviour for non-returning functions
#ifdef __GNUC__
#define NORETURN __attribute__((noreturn))
#else
#define NORETURN
#endif
// Static assertions
#ifdef __GNUC__
#define STATIC_ASSERT(cond, msg) _Static_assert(cond, msg)
#else
#define STATIC_ASSERT(cond, msg) typedef char GLUE2(static_assertion_failed, __LINE__)[(cond) ? 1 : -1]
#endif
// Align to 8-byte boundary for DMA requirements
#ifdef __GNUC__
#define ALIGNED8 __attribute__((aligned(8)))
#else
#define ALIGNED8
#endif
// Align to 16-byte boundary for audio lib requirements
#ifdef __GNUC__
#define ALIGNED16 __attribute__((aligned(16)))
#else
#define ALIGNED16
#endif
// convert a virtual address to physical.
#define VIRTUAL_TO_PHYSICAL(addr) ((uintptr_t)(addr) & 0x1FFFFFFF)
// convert a physical address to virtual.
#define PHYSICAL_TO_VIRTUAL(addr) ((uintptr_t)(addr) | 0x80000000)
// another way of converting virtual to physical
#define VIRTUAL_TO_PHYSICAL2(addr) ((u8 *)(addr) - 0x80000000U)
// aligns an address to the next 16 bytes
#define ALIGN16(val) (((val) + 0xF) & ~0xF)
/**
* (u8*) dl : Cast array down to u8's
* + sizeof(dl) : go to the end of the array
* - sizeof(dl[0]) : walk back 1 Gfx macro
* - 0x07000000 : get just the offset
**/
#define GET_PACKED_END(dl) (((u8*) dl) + sizeof(dl) - sizeof(dl[0]) - 0x07000000)
#endif