2020-07-19 06:15:50 +02:00
|
|
|
#ifndef _MACROS_H_
|
|
|
|
#define _MACROS_H_
|
|
|
|
|
2021-12-16 09:33:47 +01:00
|
|
|
#include "types.h"
|
2021-03-09 18:10:12 +01:00
|
|
|
#include "include_asm.h"
|
2020-07-19 06:15:50 +02:00
|
|
|
|
2021-11-19 15:31:28 +01:00
|
|
|
#ifndef M2CTX
|
2021-07-16 20:27:27 +02:00
|
|
|
#define BSS __attribute__ ((section (".bss")))
|
2022-01-06 14:40:01 +01:00
|
|
|
#define TRANSPARENT_UNION __attribute__ ((__transparent_union__))
|
2021-11-19 15:31:28 +01:00
|
|
|
#else
|
|
|
|
#define BSS static
|
2022-01-06 14:40:01 +01:00
|
|
|
#define TRANSPARENT_UNION
|
2021-11-19 15:31:28 +01:00
|
|
|
#endif
|
2021-07-16 20:27:27 +02:00
|
|
|
|
2020-12-02 00:23:26 +01:00
|
|
|
#define ALIGN16(val) (((val) + 0xF) & ~0xF)
|
2022-08-10 17:29:06 +02:00
|
|
|
#define ALIGN8(val) (((val) + 0x7) & ~0x7)
|
2020-12-02 00:23:26 +01:00
|
|
|
|
2022-01-08 06:43:11 +01:00
|
|
|
#define A(sym) NS(AREA, sym)
|
2021-01-01 02:20:39 +01:00
|
|
|
#define N(sym) NS(NAMESPACE, sym)
|
|
|
|
|
2020-08-09 04:17:37 +02:00
|
|
|
#define ARRAY_COUNT(arr) (s32)(sizeof(arr) / sizeof(arr[0]))
|
2020-08-12 03:01:33 +02:00
|
|
|
|
2022-09-15 21:39:16 +02:00
|
|
|
#define PTR_LIST_END ((void*) -1)
|
|
|
|
|
2021-03-25 09:56:12 +01:00
|
|
|
#define PHYSICAL_TO_VIRTUAL(addr) (void*)((u32)(addr) + 0x80000000)
|
|
|
|
#define VIRTUAL_TO_PHYSICAL(addr) (u32)((u8*)(addr) - 0x80000000)
|
|
|
|
|
2021-07-19 10:22:43 +02:00
|
|
|
#ifdef DEBUG
|
|
|
|
#define ASSERT(condition) \
|
|
|
|
if (!(condition)) { \
|
|
|
|
func_80025F44("Assertion failed: " #condition, __FILE__, __LINE__); \
|
|
|
|
while (TRUE) {} \
|
|
|
|
}
|
|
|
|
#define PANIC() \
|
|
|
|
func_80025F44("Panic!", __FILE__, __LINE__); \
|
|
|
|
while (TRUE) {}
|
|
|
|
#else
|
|
|
|
#define ASSERT(condition) if (!(condition)) { while (TRUE) {} }
|
|
|
|
#define PANIC() while (TRUE) {}
|
|
|
|
#endif
|
2020-08-17 14:09:19 +02:00
|
|
|
|
2022-02-08 19:24:51 +01:00
|
|
|
#define BADGE_MENU_PAGE(index) (&gPauseBadgesPages[index])
|
|
|
|
#define ITEM_MENU_PAGE(index) (&gPauseItemsPages[index])
|
|
|
|
|
|
|
|
#define MENU_PANEL_SELECTED_GRID_DATA(panel) \
|
|
|
|
(panel)->gridData[(panel)->page * (panel)->numCols * (panel)->numRows + \
|
|
|
|
(panel)->numCols * (panel)->row + \
|
|
|
|
(panel)->col]
|
2020-11-10 21:21:37 +01:00
|
|
|
|
2020-10-13 03:28:01 +02:00
|
|
|
#define MAX_MAPVARS 16
|
|
|
|
#define MAX_MAPFLAGS 3
|
|
|
|
|
2020-11-08 21:40:26 +01:00
|
|
|
#define MAX_ANIMATED_MODELS 16
|
|
|
|
#define MAX_ANIMATED_MESHES 16
|
2021-04-13 02:07:05 +02:00
|
|
|
#define MAX_ENTITY_MODELS 256
|
2020-10-22 02:07:00 +02:00
|
|
|
#define MAX_MODELS 256
|
2021-06-21 06:30:57 +02:00
|
|
|
#define MAX_MODEL_TRANSFORM_GROUPS 4
|
2020-10-13 03:28:01 +02:00
|
|
|
#define MAX_SCRIPTS 128
|
2020-10-22 02:07:00 +02:00
|
|
|
#define MAX_NPCS 64
|
|
|
|
#define MAX_TRIGGERS 64
|
|
|
|
#define MAX_SHADOWS 60
|
|
|
|
#define MAX_ENTITIES 30
|
|
|
|
#define MAX_DYNAMIC_ENTITIES 16
|
2021-03-28 20:31:15 +02:00
|
|
|
#define MAX_TEX_PANNERS 16
|
2021-04-29 19:09:30 +02:00
|
|
|
#define MAX_ITEM_ENTITIES 256
|
2020-10-13 03:28:01 +02:00
|
|
|
|
2021-07-22 20:48:30 +02:00
|
|
|
#define SCREEN_WIDTH 320
|
|
|
|
#define SCREEN_HEIGHT 240
|
|
|
|
|
2022-07-03 08:42:28 +02:00
|
|
|
// Size of tmem in bytes (4kB)
|
|
|
|
#define TMEM_SIZE 0x1000
|
|
|
|
// Height of tiles to use when copying fullscreen images (6)
|
|
|
|
#define SCREEN_COPY_TILE_HEIGHT ((TMEM_SIZE) / ((SCREEN_WIDTH) * (2)))
|
|
|
|
|
2020-10-26 22:45:24 +01:00
|
|
|
// Alternative to libultra's M_PI: non-float version; more digits cause issues
|
2021-04-29 19:31:16 +02:00
|
|
|
#define PI 3.141592f
|
|
|
|
#define PI_D 3.141592
|
|
|
|
#define TAU 6.28318f
|
2021-07-08 17:53:00 +02:00
|
|
|
#define PI_S 3.14159f // Shorter PI
|
2020-10-26 22:45:24 +01:00
|
|
|
|
2022-09-04 23:12:30 +02:00
|
|
|
// Angle conversion macros
|
|
|
|
#define DEG_TO_BINANG(x) ((x) * (0x8000 / 180.0f))
|
|
|
|
#define RAD_TO_BINANG(x) ((x) * (f32)(0x8000 / M_PI))
|
2022-09-15 21:39:16 +02:00
|
|
|
#define DEG_TO_RAD(deg) (((deg) * TAU) / 360.0f)
|
2022-09-04 23:12:30 +02:00
|
|
|
|
|
|
|
// Should be 1.0f / 0x7FFF, but precision is wrong for a double
|
|
|
|
#define SHT_MINV 3.051851e-05
|
|
|
|
|
2022-09-13 08:26:57 +02:00
|
|
|
#define SPRITE_WORLD_SCALE_F (5.0f/7.0f)
|
2022-08-07 14:42:54 +02:00
|
|
|
#define SPRITE_WORLD_SCALE_D (5.0/7.0)
|
2021-04-22 05:19:31 +02:00
|
|
|
|
2022-09-24 11:04:13 +02:00
|
|
|
#define SPRITE_ID(name, pal_anim) ((name) << 16 | (pal_anim))
|
|
|
|
|
2022-01-14 19:54:45 +01:00
|
|
|
#define BATTLE_ENTITY_ID_MASK 0x800
|
|
|
|
|
2022-03-26 12:47:10 +01:00
|
|
|
#define COLLISION_WITH_NPC_BIT 0x2000
|
|
|
|
#define COLLISION_WITH_ENTITY_BIT 0x4000
|
|
|
|
#define COLLISION_IGNORE_ENTITIES 0x40000
|
|
|
|
#define COLLISION_ONLY_ENTITIES 0x100000
|
|
|
|
|
2021-07-12 11:15:00 +02:00
|
|
|
#define PACK_FILL_COLOR(r, g, b, a) (GPACK_RGBA5551(r, g, b, a) << 0x10) | GPACK_RGBA5551(r, g, b, a)
|
2022-07-03 08:42:28 +02:00
|
|
|
#define PACK_FILL_DEPTH(z,dz) (GPACK_ZDZ(z, dz) << 0x10) | GPACK_ZDZ(z, dz)
|
2021-07-12 11:15:00 +02:00
|
|
|
|
2022-09-04 23:12:30 +02:00
|
|
|
#define SQ(x) ((x) * (x))
|
|
|
|
#define CUBE(x) ((x) * (x) * (x))
|
|
|
|
#define QUART(x) ((x) * (x) * (x) * (x))
|
2020-09-11 22:29:52 +02:00
|
|
|
|
2021-08-18 18:28:32 +02:00
|
|
|
/// Fixed-point short literal
|
2020-10-20 05:08:28 +02:00
|
|
|
#define F16(f) (s16)(f * 327.67f)
|
|
|
|
|
2021-08-18 18:28:32 +02:00
|
|
|
/// X.10 fixed-point literal
|
|
|
|
#define X10(f) (s32)(f * 1024.0f)
|
|
|
|
|
2020-12-28 08:09:39 +01:00
|
|
|
#define _NS(x, y) x ## _ ## y
|
|
|
|
#define NS(x, y) _NS(x, y)
|
2020-10-21 15:12:24 +02:00
|
|
|
|
2021-01-15 04:19:49 +01:00
|
|
|
#define ASCII_TO_U32(a, b, c, d) ((u32)((a << 24) | (b << 16) | (c << 8) | (d << 0)))
|
|
|
|
|
2022-09-06 17:26:53 +02:00
|
|
|
#define ITEM_VIS_GROUP(itemID, visGroupID) ((visGroupID) << 16 | (itemID))
|
|
|
|
|
2022-09-13 08:26:57 +02:00
|
|
|
// loads integrator with standard parameter set used for falling
|
|
|
|
|
|
|
|
#define LOAD_INTEGRATOR_FALL(ptr) \
|
|
|
|
(ptr)[0] = 0.11430f; \
|
|
|
|
(ptr)[1] = -0.28710f; \
|
|
|
|
(ptr)[2] = -0.18230f; \
|
|
|
|
(ptr)[3] = 0.01152f; \
|
|
|
|
|
2022-04-29 06:32:16 +02:00
|
|
|
/* common AI function and script variables */
|
|
|
|
// ai script
|
|
|
|
#define AI_TEMP_STATE functionTemp[0]
|
|
|
|
#define AI_TEMP_STATE_AFTER_SUSPEND functionTemp[1]
|
|
|
|
#define AI_PATROL_GOAL_INDEX functionTemp[2]
|
|
|
|
// melee enemy
|
|
|
|
#define AI_VAR_ATTACK_STATE varTable[0]
|
|
|
|
#define AI_VAR_MELEE_PRE_TIME varTable[1]
|
|
|
|
#define AI_VAR_MELEE_HIT_TIME varTable[2]
|
|
|
|
#define AI_VAR_MELEE_MISS_TIME varTable[3]
|
|
|
|
#define AI_VAR_NEXT_STATE varTable[7]
|
|
|
|
// melee hitbox
|
|
|
|
#define AI_VAR_HITNPC_YOFFSET varTable[0]
|
|
|
|
#define AI_VAR_HITNPC_DIST varTable[1]
|
|
|
|
#define AI_VAR_HITNPC_2 varTable[2]
|
|
|
|
#define AI_VAR_HITNPC_3 varTable[3]
|
|
|
|
#define AI_VAR_HITNPC_4 varTable[4]
|
|
|
|
#define AI_VAR_HITNPC_SOUND varTable[15]
|
|
|
|
// projectile hitbox
|
|
|
|
#define VAR_PROJECTILE_HITBOX_STATE varTable[0]
|
|
|
|
#define AI_PROJECTILE_AMMO_COUNT varTable[3]
|
|
|
|
|
2020-08-12 03:01:33 +02:00
|
|
|
#endif
|