Files
tww/include/global.h
T
Jcw87 92e7ebe1f7 Fixes for other compilers (#1230)
* add COMPOUND_LITERAL macro for non-standard struct initializer casts

* fix f_pc_profile_lst for other compilers

* std::__tag_va_List compiler compatibility

* JStudio fix

* fix return

* don't use NULL for non-pointer variables
2026-10-03 18:57:22 -04:00

111 lines
4.3 KiB
C++

#ifndef _global_h_
#define _global_h_
#include "dolphin/types.h"
#define ARRAY_SIZE(o) (sizeof(o) / sizeof(o[0]))
#define ARRAY_SSIZE(o) ((int)(sizeof(o) / sizeof(o[0])))
// Align X to the previous N bytes (N must be power of two)
#define ALIGN_PREV(X, N) ((X) & ~((N)-1))
// Align X to the next N bytes (N must be power of two)
#define ALIGN_NEXT(X, N) ALIGN_PREV(((X) + (N-1)), N)
#define IS_ALIGNED(X, N) (((X) & ((N)-1)) == 0)
#define IS_NOT_ALIGNED(X, N) (((X) & ((N)-1)) != 0)
// Silence unused parameter warnings.
// TP debug suggests the original devs used something like this.
#define UNUSED(x) ((void)(x))
#define JUT_EXPECT(...)
#define ASSERT(...)
#define LOGF(FMT, ...)
#define _SDA_BASE_(dummy) 0
#define _SDA2_BASE_(dummy) 0
#ifndef offsetof
#define offsetof(type, member) ((size_t) & (((type*)0)->member))
#endif
#define SQUARE(x) ((x) * (x))
#if defined(__cplusplus) && __cplusplus >= 201103L
#define COMPOUND_LITERAL(x)
#else
#define COMPOUND_LITERAL(x) (x)
#endif
#ifdef __MWERKS__
#define GLUE(a, b) a##b
#define GLUE2(a, b) GLUE(a, b)
#define STATIC_ASSERT(cond) typedef char GLUE2(static_assertion_failed, __LINE__)[(cond) ? 1 : -1]
#define ALIGN_DECL(alignment, decl) decl ATTRIBUTE_ALIGN(alignment)
#define SECTION_DATA __declspec(section ".data")
#define SECTION_INIT __declspec(section ".init")
#define ASM asm
#define WEAKFUNC __declspec(weak)
#else
#define STATIC_ASSERT(...)
#define ALIGN_DECL(alignment, decl) ATTRIBUTE_ALIGN(alignment) decl
#define SECTION_DATA
#define SECTION_INIT
#define ASM
#define WEAKFUNC
#endif
// Intrinsics
extern int __cntlzw(uint);
extern int __rlwimi(int, int, int, int, int);
extern void __dcbz(void*, int);
extern void __sync();
#define VERSION_DEMO 0
#define VERSION_JPN 1
#define VERSION_USA 2
#define VERSION_PAL 3
#if VERSION == VERSION_DEMO
#define VERSION_SELECT(DEMO, JPN, USA, PAL) (DEMO)
#define DEMO_SELECT(DEMO, RETAIL) (DEMO)
#elif VERSION <= VERSION_JPN
#define VERSION_SELECT(DEMO, JPN, USA, PAL) (JPN)
#define DEMO_SELECT(DEMO, RETAIL) (RETAIL)
#elif VERSION == VERSION_USA
#define VERSION_SELECT(DEMO, JPN, USA, PAL) (USA)
#define DEMO_SELECT(DEMO, RETAIL) (RETAIL)
#elif VERSION == VERSION_PAL
#define VERSION_SELECT(DEMO, JPN, USA, PAL) (PAL)
#define DEMO_SELECT(DEMO, RETAIL) (RETAIL)
#endif
#ifdef __MWERKS__
#define SJIS(character, value) character
#else
#define SJIS(character, value) ((u32)value)
#endif
// Hack to make strings with no references appear in the string pool for matching.
#define DEAD_STRING(s) OSReport(s)
// Hack to trick the compiler into not inlining functions that use this macro.
#define FORCE_DONT_INLINE \
(void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; \
(void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; \
(void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; \
(void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; \
(void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; \
(void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; \
(void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; \
(void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; \
(void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; \
(void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; \
(void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; \
(void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; \
(void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; \
(void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; \
(void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; \
(void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0;
#endif