Twilight Princess
Decompilation of The Legend of Zelda: Twilight Princess
Loading...
Searching...
No Matches
global.h
Go to the documentation of this file.
1#ifndef _global_h_
2#define _global_h_
3
4// Version ordering defined in configure.py
5#define VERSION_GCN_USA 0
6#define VERSION_GCN_PAL 1
7#define VERSION_GCN_JPN 2
8#define VERSION_WII_USA_R0 3
9#define VERSION_WII_USA_R2 4
10#define VERSION_WII_PAL 5
11#define VERSION_WII_JPN 6
12#define VERSION_WII_KOR 7
13#define VERSION_WII_USA_KIOSK 8
14#define VERSION_WII_PAL_KIOSK 9
15#define VERSION_SHIELD 10
16#define VERSION_SHIELD_PROD 11
17#define VERSION_SHIELD_DEBUG 12
18
19#define PLATFORM_GCN (VERSION >= VERSION_GCN_USA && VERSION <= VERSION_GCN_JPN)
20#define PLATFORM_WII (VERSION >= VERSION_WII_USA_R0 && VERSION <= VERSION_WII_PAL_KIOSK)
21#define PLATFORM_SHIELD (VERSION >= VERSION_SHIELD && VERSION <= VERSION_SHIELD_DEBUG)
22
23#define REGION_USA (VERSION == VERSION_GCN_USA || VERSION == VERSION_WII_USA_R0 || VERSION == VERSION_WII_USA_R2 || VERSION == VERSION_WII_USA_KIOSK)
24#define REGION_PAL (VERSION == VERSION_GCN_PAL || VERSION == VERSION_WII_PAL || VERSION == VERSION_WII_PAL_KIOSK)
25#define REGION_JPN (VERSION == VERSION_GCN_JPN || VERSION == VERSION_WII_JPN)
26#define REGION_KOR (VERSION == VERSION_WII_KOR)
27#define REGION_CHN (VERSION == VERSION_SHIELD || VERSION == VERSION_SHIELD_PROD || VERSION == VERSION_SHIELD_DEBUG)
28
29// define DEBUG if it isn't already so it can be used in conditions
30#ifndef DEBUG
31#define DEBUG 0
32#endif
33
34#define MSL_INLINE inline
35
36#define ARRAY_SIZE(o) (s32)(sizeof(o) / sizeof(o[0]))
37#define ARRAY_SIZEU(o) (sizeof(o) / sizeof(o[0]))
38
39// Align X to the previous N bytes (N must be power of two)
40#define ALIGN_PREV(X, N) ((X) & ~((N)-1))
41// Align X to the next N bytes (N must be power of two)
42#define ALIGN_NEXT(X, N) ALIGN_PREV(((X) + (N)-1), N)
43#define IS_ALIGNED(X, N) (((X) & ((N)-1)) == 0)
44#define IS_NOT_ALIGNED(X, N) (((X) & ((N)-1)) != 0)
45
46#define ROUND(n, a) (((u32)(n) + (a)-1) & ~((a)-1))
47#define TRUNC(n, a) (((u32)(n)) & ~((a)-1))
48
49// Silence unused parameter warnings.
50// Necessary for debug matches.
51#define UNUSED(x) ((void)(x))
52
53#ifdef __MWERKS__
54#ifndef decltype
55#define decltype __decltype__
56#endif
57#endif
58
59#define _SDA_BASE_(dummy) 0
60#define _SDA2_BASE_(dummy) 0
61
62#ifdef __MWERKS__
63#define GLUE(a, b) a##b
64#define GLUE2(a, b) GLUE(a, b)
65
66#if VERSION == VERSION_GCN_USA
67#define STATIC_ASSERT(cond) typedef char GLUE2(static_assertion_failed, __LINE__)[(cond) ? 1 : -1]
68#else
69#define STATIC_ASSERT(...)
70#endif
71#else
72#define STATIC_ASSERT(...)
73#endif
74
75#ifndef __MWERKS__
76// Silence clangd errors about MWCC PPC intrinsics by declaring them here.
77extern int __cntlzw(unsigned int);
78extern int __rlwimi(int, int, int, int, int);
79extern void __dcbf(void*, int);
80extern void __dcbz(void*, int);
81extern void __sync();
82extern int __abs(int);
83void* __memcpy(void*, const void*, int);
84#endif
85
86#define FAST_DIV(x, n) (x >> (n / 2))
87
88#define SQUARE(x) ((x) * (x))
89
90#define POINTER_ADD_TYPE(type_, ptr_, offset_) ((type_)((unsigned long)(ptr_) + (unsigned long)(offset_)))
91#define POINTER_ADD(ptr_, offset_) POINTER_ADD_TYPE(__typeof__(ptr_), ptr_, offset_)
92
93// floating-point constants
94static const float INF = 2000000000.0f;
95
96// hack to make strings with no references compile properly
97#define DEAD_STRING(s) OSReport(s)
98
99#define READU32_BE(ptr, offset) \
100 (((u32)ptr[offset] << 24) | ((u32)ptr[offset + 1] << 16) | ((u32)ptr[offset + 2] << 8) | (u32)ptr[offset + 3]);
101
102#ifndef NO_INLINE
103#ifdef __MWERKS__
104#define NO_INLINE __attribute__((never_inline))
105#else
106#define NO_INLINE
107#endif
108#endif
109
110// Hack to trick the compiler into not inlining functions that use this macro.
111#define FORCE_DONT_INLINE \
112 (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; \
113 (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; \
114 (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; \
115 (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; \
116 (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; \
117 (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; \
118 (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; \
119 (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; \
120 (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; \
121 (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; \
122 (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; \
123 (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; \
124 (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; \
125 (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; \
126 (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; \
127 (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0; (void*)0;
128
129#ifdef __MWERKS__
130#define SJIS(character, value) character
131#else
132#define SJIS(character, value) ((u32)value)
133#endif
134
135#ifdef __MWERKS__
136#define ASM asm
137#else
138#define ASM
139#endif
140
141// potential fakematch?
142#if PLATFORM_SHIELD
143 #define UNSET_FLAG(var, flag, type) (var) &= (type)~(flag)
144#else
145 #define UNSET_FLAG(var, flag, type) (var) &= ~(flag)
146#endif
147
148// potential fakematch?
149#if DEBUG
150#define FABSF fabsf
151#else
152#define FABSF std::fabsf
153#endif
154
155#endif
int __abs(int)
void __dcbf(void *, int)
int __rlwimi(int, int, int, int, int)
static const float INF
Definition global.h:94
void __dcbz(void *, int)
int __cntlzw(unsigned int)
void * __memcpy(void *, const void *, int)
void __sync()