2020-03-17 04:31:30 +00:00
|
|
|
#ifndef _MACROS_H_
|
|
|
|
#define _MACROS_H_
|
|
|
|
|
|
|
|
#define ARRAY_COUNT(arr) (s32)(sizeof(arr) / sizeof(arr[0]))
|
|
|
|
#define ARRAY_COUNTU(arr) (u32)(sizeof(arr) / sizeof(arr[0]))
|
|
|
|
|
2020-09-01 01:06:44 +00:00
|
|
|
#define PHYSICAL_TO_VIRTUAL(addr) (void*)((u32)(addr) + 0x80000000)
|
|
|
|
#define VIRTUAL_TO_PHYSICAL(addr) (u32)((u8*)(addr) - 0x80000000)
|
|
|
|
#define SEGMENTED_TO_VIRTUAL(addr) PHYSICAL_TO_VIRTUAL(gSegments[SEGMENT_NUMBER(addr)] + SEGMENT_OFFSET(addr))
|
2020-03-17 04:31:30 +00:00
|
|
|
|
|
|
|
#define ALIGN16(val) (((val) + 0xF) & ~0xF)
|
2021-07-25 22:34:25 +00:00
|
|
|
#define ALIGN32(val) (((val) + 0x1F) & ~0x1F)
|
2021-08-31 22:53:35 +00:00
|
|
|
#define ALIGN64(val) (((val) + 0x3F) & ~0x3F)
|
2021-07-25 22:34:25 +00:00
|
|
|
#define ALIGN256(val) (((val) + 0xFF) & ~0xFF)
|
2020-03-17 04:31:30 +00:00
|
|
|
|
|
|
|
#define SQ(x) ((x)*(x))
|
|
|
|
#define ABS(x) ((x) >= 0 ? (x) : -(x))
|
2021-01-19 19:27:57 +00:00
|
|
|
#define DECR(x) ((x) == 0 ? 0 : --(x))
|
2020-04-16 21:36:12 +00:00
|
|
|
#define CLAMP(x, min, max) ((x) < (min) ? (min) : (x) > (max) ? (max) : (x))
|
2020-04-30 18:41:09 +00:00
|
|
|
#define CLAMP_MAX(x, max) ((x) > (max) ? (max) : (x))
|
|
|
|
#define CLAMP_MIN(x, min) ((x) < (min) ? (min) : (x))
|
2021-03-20 19:10:10 +00:00
|
|
|
#define MEDIAN3(a1, a2, a3) ((a2 >= a1) ? ((a3 >= a2) ? a2 : ((a1 >= a3) ? a1 : a3)) : ((a2 >= a3) ? a2 : ((a3 >= a1) ? a1 : a3)))
|
2020-04-16 21:36:12 +00:00
|
|
|
|
|
|
|
#define RGBA8(r, g, b, a) (((r & 0xFF) << 24) | ((g & 0xFF) << 16) | ((b & 0xFF) << 8) | ((a & 0xFF) << 0))
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-08-31 10:22:03 +00:00
|
|
|
#define GET_PLAYER(globalCtx) ((Player*)(globalCtx)->actorCtx.actorLists[ACTORCAT_PLAYER].head)
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-08-31 10:22:03 +00:00
|
|
|
#define GET_ACTIVE_CAM(globalCtx) ((globalCtx)->cameraPtrs[(globalCtx)->activeCamera])
|
2020-05-09 20:58:02 +00:00
|
|
|
|
2021-08-21 23:12:57 +00:00
|
|
|
#define LINK_IS_ADULT (gSaveContext.linkAge == 0)
|
|
|
|
#define LINK_IS_CHILD (gSaveContext.linkAge == 1)
|
|
|
|
|
2020-03-17 04:31:30 +00:00
|
|
|
#define YEARS_CHILD 5
|
|
|
|
#define YEARS_ADULT 17
|
2021-08-21 23:12:57 +00:00
|
|
|
#define LINK_AGE_IN_YEARS (!LINK_IS_ADULT ? YEARS_CHILD : YEARS_ADULT)
|
|
|
|
|
|
|
|
#define IS_DAY (gSaveContext.nightFlag == 0)
|
|
|
|
#define IS_NIGHT (gSaveContext.nightFlag == 1)
|
2020-03-17 04:31:30 +00:00
|
|
|
|
|
|
|
#define SLOT(item) gItemSlots[item]
|
2020-10-11 17:45:08 +00:00
|
|
|
#define INV_CONTENT(item) gSaveContext.inventory.items[SLOT(item)]
|
|
|
|
#define AMMO(item) gSaveContext.inventory.ammo[SLOT(item)]
|
2020-03-17 04:31:30 +00:00
|
|
|
#define BEANS_BOUGHT AMMO(ITEM_BEAN + 1)
|
|
|
|
|
2020-10-11 17:45:08 +00:00
|
|
|
#define ALL_EQUIP_VALUE(equip) ((s32)(gSaveContext.inventory.equipment & gEquipMasks[equip]) >> gEquipShifts[equip])
|
2020-03-17 04:31:30 +00:00
|
|
|
#define CUR_EQUIP_VALUE(equip) ((s32)(gSaveContext.equips.equipment & gEquipMasks[equip]) >> gEquipShifts[equip])
|
2020-10-11 17:45:08 +00:00
|
|
|
#define CHECK_OWNED_EQUIP(equip, value) ((gBitFlags[value] << gEquipShifts[equip]) & gSaveContext.inventory.equipment)
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-10-11 17:45:08 +00:00
|
|
|
#define CUR_UPG_VALUE(upg) ((s32)(gSaveContext.inventory.upgrades & gUpgradeMasks[upg]) >> gUpgradeShifts[upg])
|
2020-03-17 04:31:30 +00:00
|
|
|
#define CAPACITY(upg, value) gUpgradeCapacities[upg][value]
|
|
|
|
#define CUR_CAPACITY(upg) CAPACITY(upg, CUR_UPG_VALUE(upg))
|
|
|
|
|
2020-10-11 17:45:08 +00:00
|
|
|
#define CHECK_QUEST_ITEM(item) (gBitFlags[item] & gSaveContext.inventory.questItems)
|
2020-12-03 21:55:01 +00:00
|
|
|
#define CHECK_DUNGEON_ITEM(item, dungeonIndex) (gSaveContext.inventory.dungeonItems[dungeonIndex] & gBitFlags[item])
|
2020-04-16 21:36:12 +00:00
|
|
|
|
2021-05-02 23:15:16 +00:00
|
|
|
#define GET_GS_FLAGS(index) \
|
|
|
|
((gSaveContext.gsFlags[(index) >> 2] & gGsFlagsMask[(index) & 3]) >> gGsFlagsShift[(index) & 3])
|
|
|
|
#define SET_GS_FLAGS(index, value) \
|
|
|
|
(gSaveContext.gsFlags[(index) >> 2] |= (value) << gGsFlagsShift[(index) & 3])
|
|
|
|
|
2021-01-05 19:57:18 +00:00
|
|
|
#define HIGH_SCORE(score) (gSaveContext.highScores[score])
|
|
|
|
|
2020-09-19 01:45:39 +00:00
|
|
|
#define B_BTN_ITEM ((gSaveContext.buttonStatus[0] == ITEM_NONE) \
|
|
|
|
? ITEM_NONE \
|
|
|
|
: (gSaveContext.equips.buttonItems[0] == ITEM_SWORD_KNIFE) \
|
|
|
|
? ITEM_SWORD_BGS \
|
|
|
|
: gSaveContext.equips.buttonItems[0])
|
|
|
|
|
|
|
|
#define C_BTN_ITEM(button) ((gSaveContext.buttonStatus[button + 1] != BTN_DISABLED) \
|
|
|
|
? gSaveContext.equips.buttonItems[button + 1] \
|
|
|
|
: ITEM_NONE)
|
|
|
|
|
2020-10-03 15:22:44 +00:00
|
|
|
#define CHECK_BTN_ALL(state, combo) (~((state) | ~(combo)) == 0)
|
|
|
|
#define CHECK_BTN_ANY(state, combo) (((state) & (combo)) != 0)
|
|
|
|
|
2020-03-18 21:18:25 +00:00
|
|
|
|
2020-06-14 03:29:59 +00:00
|
|
|
#define LOG(exp, value, format, file, line) \
|
|
|
|
do { \
|
|
|
|
LogUtils_LogThreadId(file, line); \
|
|
|
|
osSyncPrintf(exp " = " format "\n", value); \
|
|
|
|
} while (0)
|
2020-04-04 17:28:53 +00:00
|
|
|
|
2020-04-05 10:32:08 +00:00
|
|
|
#define LOG_STRING(string, file, line) LOG(#string, string, "%s", file, line)
|
2020-04-16 21:36:12 +00:00
|
|
|
#define LOG_ADDRESS(exp, value, file, line) LOG(exp, value, "%08x", file, line)
|
2020-04-04 17:28:53 +00:00
|
|
|
#define LOG_TIME(exp, value, file, line) LOG(exp, value, "%lld", file, line)
|
2020-04-05 10:32:08 +00:00
|
|
|
#define LOG_NUM(exp, value, file, line) LOG(exp, value, "%d", file, line)
|
2020-06-14 03:29:59 +00:00
|
|
|
#define LOG_HEX(exp, value, file, line) LOG(exp, value, "%x", file, line)
|
2020-12-29 18:11:11 +00:00
|
|
|
#define LOG_FLOAT(exp, value, file, line) LOG(exp, value, "%f", file, line)
|
2020-04-04 17:28:53 +00:00
|
|
|
|
2020-08-29 23:00:17 +00:00
|
|
|
#define SET_NEXT_GAMESTATE(curState, newInit, newStruct) \
|
2021-02-15 17:29:06 +00:00
|
|
|
do { \
|
|
|
|
(curState)->init = newInit; \
|
|
|
|
(curState)->size = sizeof(newStruct); \
|
|
|
|
} while (0)
|
2020-08-29 23:00:17 +00:00
|
|
|
|
|
|
|
#define SET_FULLSCREEN_VIEWPORT(view) \
|
|
|
|
{ \
|
|
|
|
Viewport viewport; \
|
|
|
|
viewport.bottomY = SCREEN_HEIGHT; \
|
|
|
|
viewport.rightX = SCREEN_WIDTH; \
|
|
|
|
viewport.topY = 0; \
|
|
|
|
viewport.leftX = 0; \
|
|
|
|
View_SetViewport(view, &viewport); \
|
|
|
|
} \
|
|
|
|
(void)0
|
|
|
|
|
2020-10-29 21:31:09 +00:00
|
|
|
extern GraphicsContext* __gfxCtx;
|
2020-08-30 16:51:46 +00:00
|
|
|
|
2020-10-29 21:31:09 +00:00
|
|
|
#define WORK_DISP __gfxCtx->work.p
|
|
|
|
#define POLY_OPA_DISP __gfxCtx->polyOpa.p
|
|
|
|
#define POLY_XLU_DISP __gfxCtx->polyXlu.p
|
|
|
|
#define OVERLAY_DISP __gfxCtx->overlay.p
|
|
|
|
|
|
|
|
// __gfxCtx shouldn't be used directly.
|
|
|
|
// Use the DISP macros defined above when writing to display buffers.
|
2020-08-30 16:51:46 +00:00
|
|
|
#define OPEN_DISPS(gfxCtx, file, line) \
|
|
|
|
{ \
|
2020-10-29 21:31:09 +00:00
|
|
|
GraphicsContext* __gfxCtx; \
|
2020-08-30 16:51:46 +00:00
|
|
|
Gfx* dispRefs[4]; \
|
2020-10-29 21:31:09 +00:00
|
|
|
__gfxCtx = gfxCtx; \
|
2021-02-14 00:49:40 +00:00
|
|
|
(void)__gfxCtx; \
|
2020-08-30 16:51:46 +00:00
|
|
|
Graph_OpenDisps(dispRefs, gfxCtx, file, line)
|
2020-08-29 23:00:17 +00:00
|
|
|
|
|
|
|
#define CLOSE_DISPS(gfxCtx, file, line) \
|
|
|
|
Graph_CloseDisps(dispRefs, gfxCtx, file, line); \
|
|
|
|
} \
|
|
|
|
(void)0
|
|
|
|
|
|
|
|
/**
|
2020-04-30 18:41:09 +00:00
|
|
|
* `x` vertex x
|
|
|
|
* `y` vertex y
|
|
|
|
* `z` vertex z
|
|
|
|
* `s` texture s coordinate
|
|
|
|
* `t` texture t coordinate
|
|
|
|
* `crnx` red component of color vertex, or x component of normal vertex
|
|
|
|
* `cgny` green component of color vertex, or y component of normal vertex
|
|
|
|
* `cbnz` blue component of color vertex, or z component of normal vertex
|
|
|
|
* `a` alpha
|
2020-06-14 03:29:59 +00:00
|
|
|
*/
|
2020-05-18 18:24:00 +00:00
|
|
|
#define VTX(x,y,z,s,t,crnx,cgny,cbnz,a) { { { x, y, z }, 0, { s, t }, { crnx, cgny, cbnz, a } } }
|
|
|
|
|
|
|
|
#define VTX_T(x,y,z,s,t,cr,cg,cb,a) { { x, y, z }, 0, { s, t }, { cr, cg, cb, a } }
|
2020-04-30 18:41:09 +00:00
|
|
|
|
2021-04-29 18:39:46 +00:00
|
|
|
#ifdef NDEBUG
|
|
|
|
#define ASSERT(cond, msg, file, line) ((void)0)
|
|
|
|
#elif defined(REAL_ASSERT_MACRO)
|
|
|
|
#define ASSERT(cond, msg, file, line) ((cond) ? ((void)0) : __assert(#cond, __FILE__, __LINE__))
|
|
|
|
#else
|
|
|
|
#define ASSERT(cond, msg, file, line) ((cond) ? ((void)0) : __assert(msg, file, line))
|
|
|
|
#endif
|
|
|
|
|
2021-05-02 23:15:16 +00:00
|
|
|
#define gDPSetTileCustom(pkt, fmt, siz, width, height, pal, cms, cmt, masks, maskt, shifts, shiftt) \
|
|
|
|
do { \
|
|
|
|
gDPPipeSync(pkt); \
|
|
|
|
gDPTileSync(pkt); \
|
|
|
|
gDPSetTile(pkt, fmt, siz, (((width)*siz##_TILE_BYTES) + 7) >> 3, 0, G_TX_LOADTILE, 0, cmt, maskt, shiftt, cms, \
|
|
|
|
masks, shifts); \
|
|
|
|
gDPTileSync(pkt); \
|
|
|
|
gDPSetTile(pkt, fmt, siz, (((width)*siz##_TILE_BYTES) + 7) >> 3, 0, G_TX_RENDERTILE, pal, cmt, maskt, shiftt, \
|
|
|
|
cms, masks, shifts); \
|
|
|
|
gDPSetTileSize(pkt, G_TX_RENDERTILE, 0, 0, ((width)-1) << G_TEXTURE_IMAGE_FRAC, \
|
|
|
|
((height)-1) << G_TEXTURE_IMAGE_FRAC); \
|
|
|
|
} while (0)
|
|
|
|
|
2020-03-17 04:31:30 +00:00
|
|
|
#endif
|