sotn-decomp/include/common.h

57 lines
1.6 KiB
C
Raw Normal View History

2022-01-01 17:45:41 +00:00
#ifndef COMMON_H
#define COMMON_H
#include "include_asm.h"
2022-10-15 22:17:26 +00:00
#include "macros.h"
2023-05-09 11:49:20 +00:00
#include "settings.h"
2022-01-01 17:45:41 +00:00
#include "types.h"
2023-05-04 22:32:35 +00:00
#if defined(_internal_version_us)
#define VERSION_US
#define VERSION "us"
2023-05-04 22:32:35 +00:00
#elif defined(_internal_version_hd)
#define VERSION_HD
#define VERSION "hd"
#elif defined(_internal_version_beta)
#define VERSION_BETA
#define VERSION "beta"
2023-05-04 22:32:35 +00:00
#else
#warning "Version not specified. Falling back to the US version."
#define VERSION_US
#define VERSION "us"
2023-05-04 22:32:35 +00:00
#endif
2023-03-24 12:42:41 +00:00
#define LEN(x) ((s32)(sizeof(x) / sizeof(*(x))))
#define LENU(x) ((u32)(sizeof(x) / sizeof(*(x))))
2023-03-28 12:14:13 +00:00
#define STRCPY(dst, src) __builtin_memcpy(dst, src, sizeof(src))
2023-03-04 01:26:05 +00:00
#define LOH(x) (*(s16*)&(x))
2023-07-06 11:20:53 +00:00
#define LOHU(x) (*(u16*)&(x))
2023-05-27 10:13:49 +00:00
#define LOW(x) (*(s32*)&(x))
2023-07-06 11:20:53 +00:00
#define LOWU(x) (*(u32*)&(x))
2023-05-27 10:13:49 +00:00
2023-03-13 01:43:07 +00:00
#if defined(HACKS) && !defined(PERMUTER)
2023-03-12 00:13:28 +00:00
#define ALIGNED4 __attribute__((aligned(4)))
2023-03-12 00:11:04 +00:00
#else
#define ALIGNED4
#endif
2023-03-04 01:26:05 +00:00
int sprintf(char* dst, const char* fmt, ...);
#define FIX(x) ((s32)((x)*65536.0))
#define FIX_TO_I(x) ((s32)((x) >> 16))
// The second argument to CreateEntFactoryFromEntity has weird bit packing,
// this takes the 2 relevant inputs and packs them up.
// A0 should be a value like 0x##00 where ## is two hexadecimal digits.
// BLUEPRINTNUM is which blueprint gets loaded from g_FactoryBlueprints.
#define FACTORY(A0, BLUEPRINTNUM) (A0 << 8 | BLUEPRINTNUM)
// Tests multiple bits of x being set, based on the bitmask defined in y.
#define TEST_BITS(x, y) ((x & y) == y)
// PSX SDK libraries do not use float. Instead they use a fix-point number
// where 4096 is equal to 1.0.
#define FLT(x) ((s32)((x)*4096.0))
2022-01-01 17:45:41 +00:00
#endif