1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2024-11-13 04:39:36 +00:00

Fix misc GCC compatibility issues (#1463)

* Fix osGetMemSize being optimized to `return 8MB` by gcc

Co-authored-by: Tharo <17233964+Thar0@users.noreply.github.com>
Co-authored-by: ariahiro64 <45049787+ariahiro64@users.noreply.github.com>

* Workaround f32 to s16 cast for binang being UB if binang doesn't fit s16

Co-authored-by: Tharo <17233964+Thar0@users.noreply.github.com>
Co-authored-by: ariahiro64 <45049787+ariahiro64@users.noreply.github.com>

* osGetMemSize fixup

* include z64math in z64camera

Co-authored-by: Tharo <17233964+Thar0@users.noreply.github.com>
Co-authored-by: ariahiro64 <45049787+ariahiro64@users.noreply.github.com>
This commit is contained in:
Dragorn421 2022-12-13 02:55:57 +01:00 committed by GitHub
parent da06e9a701
commit 83163f4d4b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 5 deletions

View file

@ -3,10 +3,11 @@
#include "ultra64.h"
#include "z64cutscene.h"
#include "z64math.h"
#include "z64save.h"
// these two angle conversion macros are slightly inaccurate
#define CAM_DEG_TO_BINANG(degrees) (s16)((degrees) * 182.04167f + .5f)
#define CAM_DEG_TO_BINANG(degrees) (s16)TRUNCF_BINANG((degrees) * 182.04167f + .5f)
#define CAM_BINANG_TO_DEG(binang) ((f32)(binang) * (360.0001525f / 65535.0f))
#define CAM_STAT_CUT 0

View file

@ -100,9 +100,15 @@ typedef VecSphGeo VecGeo;
#define IS_ZERO(f) (fabsf(f) < 0.008f)
// Casting a float to an integer, when the float value is larger than what the integer type can hold,
// leads to undefined behavior. For example (f32)0x8000 doesn't fit in a s16, so it cannot be cast to s16.
// This isn't an issue with IDO, but is one with for example GCC.
// A partial workaround is to cast to s32 then s16, hoping all binang values used will fit a s32.
#define TRUNCF_BINANG(f) (s16)(s32)(f)
// Angle conversion macros
#define DEG_TO_BINANG(degrees) (s16)((degrees) * (0x8000 / 180.0f))
#define RAD_TO_BINANG(radians) (s16)((radians) * (0x8000 / M_PI))
#define DEG_TO_BINANG(degrees) (s16)TRUNCF_BINANG((degrees) * (0x8000 / 180.0f))
#define RAD_TO_BINANG(radians) (s16)TRUNCF_BINANG((radians) * (0x8000 / M_PI))
#define RAD_TO_DEG(radians) ((radians) * (180.0f / M_PI))
#define DEG_TO_RAD(degrees) ((degrees) * (M_PI / 180.0f))
#define BINANG_TO_DEG(binang) ((f32)(binang) * (180.0f / 0x8000))

View file

@ -3,13 +3,13 @@
#define STEP 0x100000
u32 osGetMemSize(void) {
u32* ptr;
vu32* ptr;
u32 size = 0x400000;
u32 data0;
u32 data1;
while (size < 0x800000) {
ptr = (u32*)(0xA0000000 + size);
ptr = (vu32*)(K1BASE + size);
data0 = *ptr;
data1 = ptr[STEP / 4 - 1];