summaryrefslogtreecommitdiff
path: root/src/code
diff options
context:
space:
mode:
authorpetrie911 <pmontag@DESKTOP-LG8A167.localdomain>2021-09-27 20:59:19 -0500
committerpetrie911 <pmontag@DESKTOP-LG8A167.localdomain>2021-09-27 20:59:19 -0500
commit9b5864da9de089925e700e02b58f6a53d4572fbd (patch)
treeb9e963b2e259dfcc8387712f2b15ccf3176f79de /src/code
parent62ddc37c0e1f1a25c272c087e92143cbb23bd353 (diff)
parent14ad66b4ed6079872fc4c546007a150ae658f3aa (diff)
merge master
Diffstat (limited to 'src/code')
-rw-r--r--src/code/sys_math.c92
-rw-r--r--src/code/z_actor_dlftbls.c8
-rw-r--r--src/code/z_kanfont.c8
-rw-r--r--src/code/z_scene.c20
-rw-r--r--src/code/z_scene_table.c2
-rw-r--r--src/code/z_vr_box.c32
6 files changed, 121 insertions, 41 deletions
diff --git a/src/code/sys_math.c b/src/code/sys_math.c
index 4142cd598..9b274c7e2 100644
--- a/src/code/sys_math.c
+++ b/src/code/sys_math.c
@@ -1,15 +1,93 @@
+/**
+ * Maths library: two factorials, integer power, wrappers for libultra's sins and coss (the main ones used), and some
+ * random functions moved from OoT's z_actor
+ */
#include "global.h"
-#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math/func_80179300.s")
+static f32 sFactorialTbl[] = { 1.0f, 1.0f, 2.0f, 6.0f, 24.0f, 120.0f, 720.0f,
+ 5040.0f, 40320.0f, 362880.0f, 3628800.0f, 39916800.0f, 479001600.0f };
-#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math/func_80179400.s")
+// Rename to Math_FactorialF
+/**
+ * Takes a float, returns the factorial of it(s trunctation), iteratively
+ * Unused
+ */
+f32 func_80179300(f32 n) {
+ f32 ret = 1.0f;
+ s32 i;
-#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math/pow_int.s")
+ //! @bug No check for negative argument. Will return 1.0f if the argument truncates to a negative int.
+ for (i = n; i > 1; i--) {
+ ret *= i;
+ }
+ return ret;
+}
-#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math/sin_rad.s")
+// Rename to Math_Factorial
+/**
+ * Takes an int and returns its factorial as a float. Uses the lookup table for n <= 12.
+ * Unused
+ */
+f32 func_80179400(s32 n) {
+ f32 ret;
+ s32 i;
-#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math/cos_rad.s")
+ //! @bug No check for negative argument. Will read the array out-of-bounds if the argument is negative.
+ //! (The OoT version does an unsigned check instead, which will return sFactorialTbl[12] for a negative argument.)
+ if (n > 12) {
+ ret = sFactorialTbl[12];
+ for (i = 13; i <= n; i++) {
+ ret *= i;
+ }
+ } else {
+ ret = sFactorialTbl[n];
+ }
+ return ret;
+}
-#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math/Rand_ZeroFloat.s")
+// Rename to Math_PowF
+/**
+ * Returns base^{exp} if exp is nonnegative and 1.0f otherwise.
+ * Unused
+ */
+f32 pow_int(f32 base, s32 exp) {
+ f32 ret = 1.0f;
-#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math/randPlusMinusPoint5Scaled.s")
+ while (exp > 0) {
+ exp--;
+ ret *= base;
+ }
+
+ return ret;
+}
+
+// Rename to Math_SinF
+/**
+ * Takes an angle in radians and returns the sine.
+ */
+f32 sin_rad(f32 rad) {
+ return sins(RADF_TO_BINANG(rad)) * SHT_MINV;
+}
+
+// Rename to Math_CosF
+/**
+ * Takes an angle in radians and returns the cosine.
+ */
+f32 cos_rad(f32 rad) {
+ return coss(RADF_TO_BINANG(rad)) * SHT_MINV;
+}
+
+/**
+ * Returns a pseudo-random floating-point number between 0.0f and scale. Originally in z_actor in OoT.
+ */
+f32 Rand_ZeroFloat(f32 scale) {
+ return Rand_ZeroOne() * scale;
+}
+
+// Rename to Rand_CenteredFloat
+/**
+ * Returns a pseudo-random floating-point number between (- scale / 2) and (scale / 2). Originally in z_actor in OoT.
+ */
+f32 randPlusMinusPoint5Scaled(f32 scale) {
+ return Rand_Centered() * scale;
+}
diff --git a/src/code/z_actor_dlftbls.c b/src/code/z_actor_dlftbls.c
index 63dcc9c58..4165e4c9b 100644
--- a/src/code/z_actor_dlftbls.c
+++ b/src/code/z_actor_dlftbls.c
@@ -1,10 +1,10 @@
#include "global.h"
#include "initvars.h"
-#define ACTOR_OVERLAY(name, allocType) \
- { \
- (u32) _ovl_##name##SegmentRomStart, (u32)_ovl_##name##SegmentRomEnd, _ovl_##name##SegmentStart, \
- _ovl_##name##SegmentEnd, NULL, &name##_InitVars, NULL, allocType, 0 \
+#define ACTOR_OVERLAY(name, allocType) \
+ { \
+ SEGMENT_ROM_START(ovl_##name), SEGMENT_ROM_END(ovl_##name), SEGMENT_START(ovl_##name), \
+ SEGMENT_END(ovl_##name), NULL, &name##_InitVars, NULL, allocType, 0 \
}
#define ACTOR_OVERLAY_INTERNAL(name, allocType) \
diff --git a/src/code/z_kanfont.c b/src/code/z_kanfont.c
index f85911fc6..b678642b1 100644
--- a/src/code/z_kanfont.c
+++ b/src/code/z_kanfont.c
@@ -9,12 +9,13 @@ void Font_LoadCharNES(GlobalContext* globalCtx, u8 codePointIndex, s32 offset) {
Font* font = &msgCtx->font;
DmaMgr_SendRequest0(&font->charBuf[font->unk_11D88][offset],
- &_nes_font_staticSegmentRomStart[(codePointIndex - ' ') * FONT_CHAR_TEX_SIZE],
+ &((u8*)SEGMENT_ROM_START(nes_font_static))[(codePointIndex - ' ') * FONT_CHAR_TEX_SIZE],
FONT_CHAR_TEX_SIZE);
}
void Font_LoadMessageBoxEndIcon(Font* font, u16 icon) {
- DmaMgr_SendRequest0(&font->iconBuf, &_message_staticSegmentRomStart[5 * 0x1000 + icon * FONT_CHAR_TEX_SIZE],
+ DmaMgr_SendRequest0(&font->iconBuf,
+ &((u8*)SEGMENT_ROM_START(message_static))[5 * 0x1000 + icon * FONT_CHAR_TEX_SIZE],
FONT_CHAR_TEX_SIZE);
}
@@ -36,7 +37,8 @@ void Font_LoadOrderedFont(Font* font) {
loadOffset = 0;
}
// UB to convert pointer to u32
- DmaMgr_SendRequest0(writeLocation, (u32)_nes_font_staticSegmentRomStart + loadOffset, FONT_CHAR_TEX_SIZE);
+ DmaMgr_SendRequest0(writeLocation, (uintptr_t)SEGMENT_ROM_START(nes_font_static) + loadOffset,
+ FONT_CHAR_TEX_SIZE);
if (sFontOrdering[codePointIndex] == 0x8C) {
break;
}
diff --git a/src/code/z_scene.c b/src/code/z_scene.c
index efaadf4bf..e77144528 100644
--- a/src/code/z_scene.c
+++ b/src/code/z_scene.c
@@ -221,8 +221,8 @@ void Scene_HeaderCmdEntranceList(GlobalContext* globalCtx, SceneCmd* cmd) {
// SceneTableEntry Header Command 0x07: Special Files
void Scene_HeaderCmdSpecialFiles(GlobalContext* globalCtx, SceneCmd* cmd) {
static RomFile tatlMessageFiles[2] = {
- { (u32)_elf_message_fieldSegmentRomStart, (u32)_elf_message_fieldSegmentRomEnd },
- { (u32)_elf_message_ydanSegmentRomStart, (u32)_elf_message_ydanSegmentRomEnd },
+ { SEGMENT_ROM_START(elf_message_field), SEGMENT_ROM_END(elf_message_field) },
+ { SEGMENT_ROM_START(elf_message_ydan), SEGMENT_ROM_END(elf_message_ydan) },
};
if (cmd->specialFiles.subKeepIndex != 0) {
@@ -344,14 +344,14 @@ void Scene_HeaderCmdEnvLightSettings(GlobalContext* globalCtx, SceneCmd* cmd) {
s32 Scene_LoadAreaTextures(GlobalContext* globalCtx, s32 fileIndex) {
static RomFile sceneTextureFiles[9] = {
{ 0, 0 }, // Default
- { (u32)_scene_texture_01SegmentRomStart, (u32)_scene_texture_01SegmentRomEnd },
- { (u32)_scene_texture_02SegmentRomStart, (u32)_scene_texture_02SegmentRomEnd },
- { (u32)_scene_texture_03SegmentRomStart, (u32)_scene_texture_03SegmentRomEnd },
- { (u32)_scene_texture_04SegmentRomStart, (u32)_scene_texture_04SegmentRomEnd },
- { (u32)_scene_texture_05SegmentRomStart, (u32)_scene_texture_05SegmentRomEnd },
- { (u32)_scene_texture_06SegmentRomStart, (u32)_scene_texture_06SegmentRomEnd },
- { (u32)_scene_texture_07SegmentRomStart, (u32)_scene_texture_07SegmentRomEnd },
- { (u32)_scene_texture_08SegmentRomStart, (u32)_scene_texture_08SegmentRomEnd },
+ { SEGMENT_ROM_START(scene_texture_01), SEGMENT_ROM_END(scene_texture_01) },
+ { SEGMENT_ROM_START(scene_texture_02), SEGMENT_ROM_END(scene_texture_02) },
+ { SEGMENT_ROM_START(scene_texture_03), SEGMENT_ROM_END(scene_texture_03) },
+ { SEGMENT_ROM_START(scene_texture_04), SEGMENT_ROM_END(scene_texture_04) },
+ { SEGMENT_ROM_START(scene_texture_05), SEGMENT_ROM_END(scene_texture_05) },
+ { SEGMENT_ROM_START(scene_texture_06), SEGMENT_ROM_END(scene_texture_06) },
+ { SEGMENT_ROM_START(scene_texture_07), SEGMENT_ROM_END(scene_texture_07) },
+ { SEGMENT_ROM_START(scene_texture_08), SEGMENT_ROM_END(scene_texture_08) },
};
u32 vromStart = sceneTextureFiles[fileIndex].vromStart;
u32 size = sceneTextureFiles[fileIndex].vromEnd - vromStart;
diff --git a/src/code/z_scene_table.c b/src/code/z_scene_table.c
index cee8546f0..8372c350a 100644
--- a/src/code/z_scene_table.c
+++ b/src/code/z_scene_table.c
@@ -1,7 +1,7 @@
#include "global.h"
#define SCENE_ENTRY(name, textId, config) \
- { { (u32)_##name##SegmentRomStart, (u32)_##name##SegmentRomEnd }, textId, 0, config, 0 }
+ { { SEGMENT_ROM_START(name), SEGMENT_ROM_END(name) }, textId, 0, config, 0 }
#define SCENE_ENTRY_NONE() \
{ { 0, 0 }, 0, 0, 0, 0 }
diff --git a/src/code/z_vr_box.c b/src/code/z_vr_box.c
index 5c00758d2..1fca4801d 100644
--- a/src/code/z_vr_box.c
+++ b/src/code/z_vr_box.c
@@ -50,21 +50,21 @@ void func_801431E8(GameState* gamestate, SkyboxContext* skyboxCtx, s16 skyType)
} else {
// Send a DMA request for the cloudy sky texture
skyboxCtx->skyboxStaticSegment[0] = &D_80025D00;
- size = (u32)_d2_cloud_staticSegmentRomEnd - (u32)_d2_cloud_staticSegmentRomStart;
+ size = SEGMENT_ROM_SIZE(d2_cloud_static);
offset = (void*)ALIGN8((u32)skyboxCtx->skyboxStaticSegment[0] + size);
- DmaMgr_SendRequest0(skyboxCtx->skyboxStaticSegment[0], (u32)_d2_cloud_staticSegmentRomStart, size);
+ DmaMgr_SendRequest0(skyboxCtx->skyboxStaticSegment[0], SEGMENT_ROM_START(d2_cloud_static), size);
// Send a DMA request for the clear sky texture
skyboxCtx->skyboxStaticSegment[1] = offset;
- size = (u32)_d2_fine_staticSegmentRomEnd - (u32)_d2_fine_staticSegmentRomStart;
+ size = SEGMENT_ROM_SIZE(d2_fine_static);
offset = (void*)ALIGN8((u32)offset + size);
- DmaMgr_SendRequest0(skyboxCtx->skyboxStaticSegment[1], (u32)_d2_fine_staticSegmentRomStart, size);
+ DmaMgr_SendRequest0(skyboxCtx->skyboxStaticSegment[1], SEGMENT_ROM_START(d2_fine_static), size);
// Send a DMA request for the skybox palette
skyboxCtx->skyboxPaletteStaticSegment = offset;
- size = (u32)_d2_fine_pal_staticSegmentRomEnd - (u32)_d2_fine_pal_staticSegmentRomStart;
+ size = SEGMENT_ROM_SIZE(d2_fine_pal_static);
offset = (void*)ALIGN8((u32)offset + size);
- DmaMgr_SendRequest0(skyboxCtx->skyboxPaletteStaticSegment, (u32)_d2_fine_pal_staticSegmentRomStart, size);
+ DmaMgr_SendRequest0(skyboxCtx->skyboxPaletteStaticSegment, SEGMENT_ROM_START(d2_fine_pal_static), size);
skyboxCtx->primR = 145;
skyboxCtx->primG = 120;
@@ -91,16 +91,16 @@ void func_80143324(GlobalContext* globalCtx, SkyboxContext* skyboxCtx, s16 skyTy
if (globalCtx->envCtx.unk_10 == 0) {
// Send a DMA request for the clear sky texture
- size = (u32)_d2_fine_staticSegmentRomEnd - (u32)_d2_fine_staticSegmentRomStart;
+ size = SEGMENT_ROM_SIZE(d2_fine_static);
DmaMgr_SendRequestImpl(&skyboxCtx->unk188, skyboxCtx->skyboxStaticSegment[0],
- (u32)_d2_fine_staticSegmentRomStart, size, 0, &skyboxCtx->loadQueue, NULL);
+ SEGMENT_ROM_START(d2_fine_static), size, 0, &skyboxCtx->loadQueue, NULL);
} else {
// Send a DMA request for the cloudy sky texture
- size = (u32)_d2_cloud_staticSegmentRomEnd - (u32)_d2_cloud_staticSegmentRomStart;
+ size = SEGMENT_ROM_SIZE(d2_cloud_static);
DmaMgr_SendRequestImpl(&skyboxCtx->unk188, skyboxCtx->skyboxStaticSegment[0],
- (u32)_d2_cloud_staticSegmentRomStart, size, 0, &skyboxCtx->loadQueue, NULL);
+ SEGMENT_ROM_START(d2_cloud_static), size, 0, &skyboxCtx->loadQueue, NULL);
}
osRecvMesg(&skyboxCtx->loadQueue, NULL, 1);
@@ -108,26 +108,26 @@ void func_80143324(GlobalContext* globalCtx, SkyboxContext* skyboxCtx, s16 skyTy
if (globalCtx->envCtx.unk_11 == 0) {
// Send a DMA request for the clear sky texture
- size = (u32)_d2_fine_staticSegmentRomEnd - (u32)_d2_fine_staticSegmentRomStart;
+ size = SEGMENT_ROM_SIZE(d2_fine_static);
DmaMgr_SendRequestImpl(&skyboxCtx->unk1A8, skyboxCtx->skyboxStaticSegment[1],
- (u32)_d2_fine_staticSegmentRomStart, size, 0, &skyboxCtx->loadQueue, NULL);
+ SEGMENT_ROM_START(d2_fine_static), size, 0, &skyboxCtx->loadQueue, NULL);
} else {
// Send a DMA request for the cloudy sky texture
- size = (u32)_d2_cloud_staticSegmentRomEnd - (u32)_d2_cloud_staticSegmentRomStart;
+ size = SEGMENT_ROM_SIZE(d2_cloud_static);
DmaMgr_SendRequestImpl(&skyboxCtx->unk1A8, skyboxCtx->skyboxStaticSegment[1],
- (u32)_d2_cloud_staticSegmentRomStart, size, 0, &skyboxCtx->loadQueue, NULL);
+ SEGMENT_ROM_START(d2_cloud_static), size, 0, &skyboxCtx->loadQueue, NULL);
}
osRecvMesg(&skyboxCtx->loadQueue, NULL, 1);
osCreateMesgQueue(&skyboxCtx->loadQueue, &skyboxCtx->loadMsg, 1);
- size = (u32)_d2_fine_pal_staticSegmentRomEnd - (u32)_d2_fine_pal_staticSegmentRomStart;
+ size = SEGMENT_ROM_SIZE(d2_fine_pal_static);
// Send a DMA request for the skybox palette
DmaMgr_SendRequestImpl(&skyboxCtx->unk1C8, skyboxCtx->skyboxPaletteStaticSegment,
- (u32)_d2_fine_pal_staticSegmentRomStart, size, 0, &skyboxCtx->loadQueue, NULL);
+ SEGMENT_ROM_START(d2_fine_pal_static), size, 0, &skyboxCtx->loadQueue, NULL);
osRecvMesg(&skyboxCtx->loadQueue, NULL, 1);
}