2023-10-13 10:50:53 +03:00
|
|
|
#ifndef MACROS_H
|
|
|
|
#define MACROS_H
|
|
|
|
|
2024-02-18 18:43:21 +03:00
|
|
|
#include "alignment.h"
|
2024-03-24 11:01:28 +03:00
|
|
|
#include "libc/math.h"
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#define __sinf sinf
|
|
|
|
#define __cosf cosf
|
2024-02-18 18:43:21 +03:00
|
|
|
|
2023-11-13 19:18:43 +03:00
|
|
|
#define SCREEN_WIDTH 320
|
|
|
|
#define SCREEN_HEIGHT 240
|
|
|
|
|
2024-01-29 00:27:23 +03:00
|
|
|
#define RAND_FLOAT(max) (Rand_ZeroOne()*(max))
|
|
|
|
#define RAND_INT(max) ((s32)(Rand_ZeroOne()*(max)))
|
|
|
|
#define RAND_FLOAT_CENTERED(width) ((Rand_ZeroOne()-0.5f)*(width))
|
2024-02-10 21:09:27 +03:00
|
|
|
#define RAND_DOUBLE_CENTERED(width) ((Rand_ZeroOne()-0.5)*(width))
|
2024-02-02 06:05:17 +03:00
|
|
|
#define RAND_RANGE(min, max) (((max) - (min)) * (Rand_ZeroOne() - (min) / ((min) - (max))))
|
2024-01-29 00:27:23 +03:00
|
|
|
|
|
|
|
#define RAND_FLOAT_SEEDED(max) (Rand_ZeroOneSeeded()*(max))
|
|
|
|
#define RAND_INT_SEEDED(max) ((s32)(Rand_ZeroOneSeeded()*(max)))
|
|
|
|
#define RAND_FLOAT_CENTERED_SEEDED(width) ((Rand_ZeroOneSeeded()-0.5f)*(width))
|
|
|
|
|
Match Libultra (#120)
* Matched perspective, contquery, contreaddata, recvmesg and sendmesg
* Fixed libultra compilation flags
* Matched viblack
* Matched virepeatline, visetmode, visetspecial and viswapbuf
* Matched cartrominit, dpsetstat, sptask, sptaskyield, visetevent, createthread, gettime, setthreadpri, settime, settimer and starthread
* Fixed bss bs
* Matched even more libultra stuff
* Matched even more
* __osRdbSend
* Decompiled most of the functions of libultra <3
* Matched last functions
* Added a separation to libultra macros
* Removed ARRLEN from controller.h
* Fix libultra warnings
---------
Co-authored-by: Alejandro Javier Asenjo Nitti <alejandro.asenjo88@gmail.com>
2024-02-14 18:24:31 +03:00
|
|
|
#define SEGMENTED_TO_VIRTUAL(segment) ((void*)OS_PHYSICAL_TO_K0(gSegments[((uintptr_t)(segment)<<4)>>0x1C]+(((uintptr_t)(segment))&0xFFFFFF)))
|
2023-11-16 05:14:33 +03:00
|
|
|
|
2023-10-16 19:32:12 +03:00
|
|
|
#define ARRAY_COUNT(arr) (s32)(sizeof(arr) / sizeof(arr[0]))
|
2024-02-10 21:09:27 +03:00
|
|
|
#define ARRAY_COUNTU(arr) (u32)(sizeof(arr) / sizeof(arr[0]))
|
2023-10-13 10:50:53 +03:00
|
|
|
|
2023-12-09 21:53:24 +03:00
|
|
|
#define SIGN_OF(x) (((x) > 0) ? 1 : ((x) == 0) ? 0 : -1)
|
|
|
|
#define SQ(x) ((x) * (x))
|
2024-02-19 16:05:11 +03:00
|
|
|
#define CUBE(x) ((x) * (x) * (x))
|
2024-03-12 22:46:25 +03:00
|
|
|
|
|
|
|
#define DOT_XYZ(v1Ptr, v2Ptr) ((v1Ptr)->x * (v2Ptr)->x + (v1Ptr)->y * (v2Ptr)->y + (v1Ptr)->z * (v2Ptr)->z)
|
|
|
|
#define VEC3F_MAG(vecPtr) sqrtf(DOT_XYZ(vecPtr, vecPtr))
|
2024-01-23 19:04:12 +03:00
|
|
|
#define ABS(x) ((x) >= 0 ? (x) : -(x))
|
2024-03-01 21:57:44 +03:00
|
|
|
#define ABSF(x) ((x) >= 0.0f ? (x) : -(x))
|
|
|
|
#define ROUND(float) ((s32)((float)+0.5f))
|
2023-11-16 05:14:33 +03:00
|
|
|
|
2024-02-17 01:04:22 +03:00
|
|
|
#define RAD_TO_DEG(radians) (((radians) * 180.0f) / M_PI)
|
|
|
|
#define DEG_TO_RAD(degrees) (((degrees) / 180.0f) * M_PI)
|
|
|
|
|
2024-03-24 11:01:28 +03:00
|
|
|
// TODO: Fix these
|
|
|
|
#define SIN_DEG(angle) /*sinf*/(M_DTOR * angle)
|
|
|
|
#define COS_DEG(angle) /*cosf*/(M_DTOR * angle)
|
2024-02-17 01:04:22 +03:00
|
|
|
|
2024-03-24 11:01:28 +03:00
|
|
|
#define USEC_TO_CYCLES(n) (((u64)(n)*(OS_CLOCK_RATE/15625LL))/(1000000LL/15625LL))
|
2023-11-08 01:32:09 +03:00
|
|
|
#define MSEC_TO_CYCLES(n) (USEC_TO_CYCLES((n) * 1000LL))
|
|
|
|
|
2024-03-24 11:01:28 +03:00
|
|
|
#define CYCLES_TO_USEC(c) (((u64)(c)*(1000000LL/15625LL))/(OS_CLOCK_RATE/15625LL))
|
2024-01-10 20:55:08 +03:00
|
|
|
#define CYCLES_TO_MSEC(c) ((s32)CYCLES_TO_USEC(c)/1000)
|
|
|
|
|
Match Libultra (#120)
* Matched perspective, contquery, contreaddata, recvmesg and sendmesg
* Fixed libultra compilation flags
* Matched viblack
* Matched virepeatline, visetmode, visetspecial and viswapbuf
* Matched cartrominit, dpsetstat, sptask, sptaskyield, visetevent, createthread, gettime, setthreadpri, settime, settimer and starthread
* Fixed bss bs
* Matched even more libultra stuff
* Matched even more
* __osRdbSend
* Decompiled most of the functions of libultra <3
* Matched last functions
* Added a separation to libultra macros
* Removed ARRLEN from controller.h
* Fix libultra warnings
---------
Co-authored-by: Alejandro Javier Asenjo Nitti <alejandro.asenjo88@gmail.com>
2024-02-14 18:24:31 +03:00
|
|
|
/*
|
|
|
|
* Macros for libultra
|
|
|
|
*/
|
|
|
|
|
2024-01-13 16:43:04 +03:00
|
|
|
#if defined(__sgi)
|
|
|
|
#define PRINTF
|
|
|
|
#else
|
|
|
|
#define PRINTF(...)
|
|
|
|
#endif
|
|
|
|
|
Match Libultra (#120)
* Matched perspective, contquery, contreaddata, recvmesg and sendmesg
* Fixed libultra compilation flags
* Matched viblack
* Matched virepeatline, visetmode, visetspecial and viswapbuf
* Matched cartrominit, dpsetstat, sptask, sptaskyield, visetevent, createthread, gettime, setthreadpri, settime, settimer and starthread
* Fixed bss bs
* Matched even more libultra stuff
* Matched even more
* __osRdbSend
* Decompiled most of the functions of libultra <3
* Matched last functions
* Added a separation to libultra macros
* Removed ARRLEN from controller.h
* Fix libultra warnings
---------
Co-authored-by: Alejandro Javier Asenjo Nitti <alejandro.asenjo88@gmail.com>
2024-02-14 18:24:31 +03:00
|
|
|
#define ALIGNED(x) __attribute__((aligned(x)))
|
|
|
|
#define ARRLEN(x) ((s32)(sizeof(x) / sizeof(x[0])))
|
|
|
|
#define STUBBED_PRINTF(x) ((void)(x))
|
|
|
|
#define UNUSED __attribute__((unused))
|
|
|
|
|
|
|
|
#ifndef __GNUC__
|
|
|
|
#define __attribute__(x)
|
|
|
|
#endif
|
|
|
|
|
2023-10-13 12:19:10 +03:00
|
|
|
#endif // MACROS_H
|