Skip to content

Commit 25b2fa4

Browse files
authored
macros.h 3/5: Split various macros (#2512)
* split out various macros * fix * fix2 * fix dw * libc path * fix macro * does this fix bss * fix bss
1 parent d4528a0 commit 25b2fa4

35 files changed

+137
-92
lines changed

include/avoid_ub.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#ifndef AVOID_UB_H
2+
#define AVOID_UB_H
3+
4+
/**
5+
* This macro is used when the return type of a function is incorrect
6+
*/
7+
#ifndef AVOID_UB
8+
#define BAD_RETURN(type) type
9+
#else
10+
#define BAD_RETURN(type) void
11+
#endif
12+
13+
#endif

include/color.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,6 @@ typedef union Color_RGBA16 {
3333
u16 rgba;
3434
} Color_RGBA16;
3535

36+
#define RGBA8(r, g, b, a) ((((r) & 0xFF) << 24) | (((g) & 0xFF) << 16) | (((b) & 0xFF) << 8) | (((a) & 0xFF) << 0))
37+
3638
#endif

include/fault.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#ifndef FAULT_H
22
#define FAULT_H
33

4-
#include "ultra64.h"
5-
#include "attributes.h"
4+
#include "libu64/debug.h"
65
#include "libu64/pad.h"
6+
#include "attributes.h"
7+
#include "ultra64.h"
78

89
#if !PLATFORM_N64
910
// These are the same as the 3-bit ansi color codes
@@ -50,6 +51,12 @@ void Fault_Init(void);
5051
NORETURN void Fault_AddHungupAndCrashImpl(const char* exp1, const char* exp2);
5152
NORETURN void Fault_AddHungupAndCrash(const char* file, int line);
5253

54+
#if PLATFORM_N64 || DEBUG_FEATURES
55+
#define HUNGUP_AND_CRASH(file, line) Fault_AddHungupAndCrash(file, line)
56+
#else
57+
#define HUNGUP_AND_CRASH(file, line) LogUtils_HungupThread(file, line)
58+
#endif
59+
5360
// Client Registration
5461

5562
void Fault_AddClient(FaultClient* client, void* callback, void* arg0, void* arg1);

include/gfx.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
#include "thga.h"
88
#include "versions.h"
99

10+
#define SCREEN_WIDTH 320
11+
#define SCREEN_HEIGHT 240
12+
1013
// Texture memory size, 4 KiB
1114
#define TMEM_SIZE 0x1000
1215

@@ -124,4 +127,39 @@ void Graph_ThreadEntry(void*);
124127
extern u64 gMojiFontTLUTs[4][4]; // original name: "moji_tlut"
125128
extern u64 gMojiFontTex[]; // original name: "font_ff"
126129

130+
/**
131+
* `x` vertex x
132+
* `y` vertex y
133+
* `z` vertex z
134+
* `s` texture s coordinate
135+
* `t` texture t coordinate
136+
* `crnx` red component of color vertex, or x component of normal vertex
137+
* `cgny` green component of color vertex, or y component of normal vertex
138+
* `cbnz` blue component of color vertex, or z component of normal vertex
139+
* `a` alpha
140+
*/
141+
#define VTX(x,y,z,s,t,crnx,cgny,cbnz,a) { { { x, y, z }, 0, { s, t }, { crnx, cgny, cbnz, a } } }
142+
143+
#define VTX_T(x,y,z,s,t,cr,cg,cb,a) { { x, y, z }, 0, { s, t }, { cr, cg, cb, a } }
144+
145+
#define gDPSetTileCustom(pkt, fmt, siz, uls, ult, lrs, lrt, pal, \
146+
cms, cmt, masks, maskt, shifts, shiftt) \
147+
_DW({ \
148+
gDPPipeSync(pkt); \
149+
gDPTileSync(pkt); \
150+
gDPSetTile(pkt, fmt, siz, \
151+
(((((lrs) - (uls) + 1) * siz##_TILE_BYTES) + 7) >> 3), 0, \
152+
G_TX_LOADTILE, 0, cmt, maskt, shiftt, cms, masks, \
153+
shifts); \
154+
gDPTileSync(pkt); \
155+
gDPSetTile(pkt, fmt, siz, \
156+
(((((lrs) - (uls) + 1) * siz##_LINE_BYTES) + 7) >> 3), 0, \
157+
G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, shifts); \
158+
gDPSetTileSize(pkt, G_TX_RENDERTILE, \
159+
(uls) << G_TEXTURE_IMAGE_FRAC, \
160+
(ult) << G_TEXTURE_IMAGE_FRAC, \
161+
(lrs) << G_TEXTURE_IMAGE_FRAC, \
162+
(lrt) << G_TEXTURE_IMAGE_FRAC); \
163+
})
164+
127165
#endif

include/language_array.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef LANGUAGE_ARRAY_H
2+
#define LANGUAGE_ARRAY_H
3+
4+
#include "versions.h"
5+
6+
#if OOT_NTSC
7+
#define LANGUAGE_ARRAY(jpn, eng, ger, fra) { jpn, eng }
8+
#else
9+
#define LANGUAGE_ARRAY(jpn, eng, ger, fra) { eng, ger, fra }
10+
#endif
11+
12+
#endif

include/macros.h

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,10 @@
11
#ifndef MACROS_H
22
#define MACROS_H
33

4-
#include "versions.h"
5-
6-
#define SCREEN_WIDTH 320
7-
#define SCREEN_HEIGHT 240
8-
9-
#ifndef AVOID_UB
10-
#define BAD_RETURN(type) type
11-
#else
12-
#define BAD_RETURN(type) void
13-
#endif
14-
154
#define ARRAY_COUNT(arr) (s32)(sizeof(arr) / sizeof(arr[0]))
165
#define ARRAY_COUNTU(arr) (u32)(sizeof(arr) / sizeof(arr[0]))
176
#define ARRAY_COUNT_2D(arr) (s32)(sizeof(arr) / sizeof(arr[0][0]))
187

19-
#define ABS(x) ((x) >= 0 ? (x) : -(x))
20-
#define DECR(x) ((x) == 0 ? 0 : --(x))
21-
#define CLAMP(x, min, max) ((x) < (min) ? (min) : (x) > (max) ? (max) : (x))
22-
#define CLAMP_MAX(x, max) ((x) > (max) ? (max) : (x))
23-
#define CLAMP_MIN(x, min) ((x) < (min) ? (min) : (x))
24-
25-
#define SWAP(type, a, b) \
26-
{ \
27-
type _temp = (a); \
28-
(a) = (b); \
29-
(b) = _temp; \
30-
} \
31-
(void)0
32-
33-
#define RGBA8(r, g, b, a) ((((r) & 0xFF) << 24) | (((g) & 0xFF) << 16) | (((b) & 0xFF) << 8) | (((a) & 0xFF) << 0))
34-
358
#define CHECK_FLAG_ALL(flags, mask) (((flags) & (mask)) == (mask))
369

37-
#if PLATFORM_N64 || DEBUG_FEATURES
38-
#define HUNGUP_AND_CRASH(file, line) Fault_AddHungupAndCrash(file, line)
39-
#else
40-
#define HUNGUP_AND_CRASH(file, line) LogUtils_HungupThread(file, line)
41-
#endif
42-
43-
#define MATRIX_FINALIZE_AND_LOAD(pkt, gfxCtx, file, line) \
44-
gSPMatrix(pkt, MATRIX_FINALIZE(gfxCtx, file, line), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW)
45-
46-
#if OOT_NTSC
47-
#define LANGUAGE_ARRAY(jpn, eng, ger, fra) { jpn, eng }
48-
#else
49-
#define LANGUAGE_ARRAY(jpn, eng, ger, fra) { eng, ger, fra }
50-
#endif
51-
52-
/**
53-
* `x` vertex x
54-
* `y` vertex y
55-
* `z` vertex z
56-
* `s` texture s coordinate
57-
* `t` texture t coordinate
58-
* `crnx` red component of color vertex, or x component of normal vertex
59-
* `cgny` green component of color vertex, or y component of normal vertex
60-
* `cbnz` blue component of color vertex, or z component of normal vertex
61-
* `a` alpha
62-
*/
63-
#define VTX(x,y,z,s,t,crnx,cgny,cbnz,a) { { { x, y, z }, 0, { s, t }, { crnx, cgny, cbnz, a } } }
64-
65-
#define VTX_T(x,y,z,s,t,cr,cg,cb,a) { { x, y, z }, 0, { s, t }, { cr, cg, cb, a } }
66-
67-
#define gDPSetTileCustom(pkt, fmt, siz, uls, ult, lrs, lrt, pal, \
68-
cms, cmt, masks, maskt, shifts, shiftt) \
69-
_DW({ \
70-
gDPPipeSync(pkt); \
71-
gDPTileSync(pkt); \
72-
gDPSetTile(pkt, fmt, siz, \
73-
(((((lrs) - (uls) + 1) * siz##_TILE_BYTES) + 7) >> 3), 0, \
74-
G_TX_LOADTILE, 0, cmt, maskt, shiftt, cms, masks, \
75-
shifts); \
76-
gDPTileSync(pkt); \
77-
gDPSetTile(pkt, fmt, siz, \
78-
(((((lrs) - (uls) + 1) * siz##_LINE_BYTES) + 7) >> 3), 0, \
79-
G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, shifts); \
80-
gDPSetTileSize(pkt, G_TX_RENDERTILE, \
81-
(uls) << G_TEXTURE_IMAGE_FRAC, \
82-
(ult) << G_TEXTURE_IMAGE_FRAC, \
83-
(lrs) << G_TEXTURE_IMAGE_FRAC, \
84-
(lrt) << G_TEXTURE_IMAGE_FRAC); \
85-
})
86-
8710
#endif

include/sys_matrix.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ Mtx* Matrix_Finalize(struct GraphicsContext* gfxCtx);
6464

6565
#endif
6666

67+
#define MATRIX_FINALIZE_AND_LOAD(pkt, gfxCtx, file, line) \
68+
gSPMatrix(pkt, MATRIX_FINALIZE(gfxCtx, file, line), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW)
69+
6770
/* Vector operations */
6871

6972
void Matrix_MultVec3f(Vec3f* src, Vec3f* dest);

include/z64.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// TODO: This file still exists ONLY to provide neccesary headers to extracted assets.
55
// After assets are modified to include the headers they need directly, delete this file.
66

7+
#include "gfx.h"
78
#include "sequence.h"
89
#include "sys_matrix.h"
910
#include "ultra64.h"

include/z64animation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef Z64_ANIMATION_H
22
#define Z64_ANIMATION_H
33

4+
#include "avoid_ub.h"
45
#include "ultra64.h"
56
#include "z64dma.h"
67
#include "z64math.h"

include/z64math.h

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
#ifndef Z64MATH_H
22
#define Z64MATH_H
33

4-
#include "ultra64.h"
54
#include "math.h"
6-
7-
#define SQ(x) ((x)*(x))
8-
#define VEC_SET(V,X,Y,Z) (V).x=(X);(V).y=(Y);(V).z=(Z)
5+
#include "ultra64.h"
96

107
typedef union FloatInt {
118
f32 f;
@@ -95,6 +92,27 @@ typedef VecSphGeo VecSph;
9592
// Pitch is 0 along the xz-plane (horizon)
9693
typedef VecSphGeo VecGeo;
9794

95+
/**
96+
* Macros
97+
*/
98+
99+
// General number macros
100+
#define SQ(x) ((x)*(x))
101+
#define ABS(x) ((x) >= 0 ? (x) : -(x))
102+
#define DECR(x) ((x) == 0 ? 0 : --(x))
103+
#define CLAMP(x, min, max) ((x) < (min) ? (min) : (x) > (max) ? (max) : (x))
104+
#define CLAMP_MAX(x, max) ((x) > (max) ? (max) : (x))
105+
#define CLAMP_MIN(x, min) ((x) < (min) ? (min) : (x))
106+
107+
#define SWAP(type, a, b) \
108+
{ \
109+
type _temp = (a); \
110+
(a) = (b); \
111+
(b) = _temp; \
112+
} \
113+
(void)0
114+
115+
// LERP macros
98116
#define LERP(x, y, scale) (((y) - (x)) * (scale) + (x))
99117
#define LERP32(x, y, scale) ((s32)(((y) - (x)) * (scale)) + (x))
100118
#define LERP16(x, y, scale) ((s16)(((y) - (x)) * (scale)) + (x))
@@ -110,6 +128,7 @@ typedef VecSphGeo VecGeo;
110128
(dst)->z = (v0)->z + (((v1)->z - (v0)->z) * t); \
111129
}
112130

131+
// Floating point macros
113132
#define IS_ZERO(f) (fabsf(f) < 0.008f)
114133

115134
// Casting a float to an integer, when the float value is larger than what the integer type can hold,
@@ -145,6 +164,7 @@ typedef VecSphGeo VecGeo;
145164
#define CAM_BINANG_TO_DEG(binang) ((f32)(binang) * (360.0001525f / 65535.0f))
146165

147166
// Vector macros
167+
#define VEC_SET(V,X,Y,Z) (V).x=(X);(V).y=(Y);(V).z=(Z)
148168
#define SQXZ(vec) ((vec).x * (vec).x + (vec).z * (vec).z)
149169
#define DOTXZ(vec1, vec2) ((vec1).x * (vec2).x + (vec1).z * (vec2).z)
150170
#define SQXYZ(vec) ((vec).x * (vec).x + (vec).y * (vec).y + (vec).z * (vec).z)

0 commit comments

Comments
 (0)