Match 4 functions in math_util, do some tidying up of imports for math_util (#144)

* Match func_802B5450, func_802B5F00, func_802B71CC

* Match func_802B4FF8

Also do some import fixing

Signed-off-by: Taggerung <tyler.taggerung@gmail.com>
This commit is contained in:
Tyler McGavran
2022-01-18 07:46:58 -05:00
committed by GitHub
parent 5e577b8999
commit e413e2ec00
9 changed files with 118 additions and 647 deletions
+1 -1
View File
@@ -2,7 +2,7 @@
#include <macros.h>
#include <types.h>
#include <mk64.h>
#include "math_util.h"
#include "trig_tables.h"
//#ifdef MIPS_TO_C
//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307
+76 -143
View File
@@ -1,20 +1,14 @@
#include <ultra64.h>
#include <macros.h>
#include <types.h>
#include <common_structs.h>
#include <math_util.h>
#include <variables.h>
#include <main.h>
// Location based from sm64.
// This may need to be moved before framebuffers.c
// If math_util has data that does not line-up with trig_tables.
#include "trig_tables.inc.c"
f32 func_802B4F60(s32 arg0, f32 arg2, f32 arg3); // static
f32 func_802B6434(f32, f32, f32 *, f32 *); // static
s16 func_802B7830(f32 y, f32 x);
extern f32 gSineTable[];
extern f32 gCosineTable[];
#ifdef MIPS_TO_C
//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307
? func_802B4F60(s32 arg0, ? arg2, ? arg3) {
@@ -38,65 +32,31 @@ extern f32 gCosineTable[];
GLOBAL_ASM("asm/non_matchings/math_util/func_802B4F60.s")
#endif
#ifdef MIPS_TO_C
//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307
? func_802B75F8(void *, s32, u16 *, s32); // extern
extern u16 D_80150112;
extern void *gDisplayListHead;
? func_802B4FF8(Mat4 arg0, s32 arg1) {
s32 temp_a3;
u16 temp_v0;
void *temp_v0_2;
void *temp_v0_3;
void *temp_v0_4;
void *temp_v0_5;
temp_v0 = D_80150112;
temp_a3 = arg1;
if (temp_v0 >= 0x80) {
s32 func_802B4FF8(Mat4 arg0, s32 arg1) {
if (D_80150112 >= 0x80) {
return 0;
}
arg1 = temp_a3;
func_802B75F8(gGfxPool + (temp_v0 << 6) + 0xCAC0, arg0, &D_80150112, temp_a3);
if (arg1 != 0) {
if (arg1 != 1) {
if (arg1 != 2) {
if (arg1 != 3) {
} else {
temp_v0_2 = gDisplayListHead;
gDisplayListHead = temp_v0_2 + 8;
temp_v0_2->unk0 = 0x1040040;
temp_v0_2->unk4 = (gGfxPool + (D_80150112 << 6) + 0xCAC0) & 0x1FFFFFFF;
D_80150112 = D_80150112 + 1;
}
} else {
temp_v0_3 = gDisplayListHead;
gDisplayListHead = temp_v0_3 + 8;
temp_v0_3->unk0 = 0x1000040;
temp_v0_3->unk4 = (gGfxPool + (D_80150112 << 6) + 0xCAC0) & 0x1FFFFFFF;
D_80150112 = D_80150112 + 1;
}
} else {
temp_v0_4 = gDisplayListHead;
gDisplayListHead = temp_v0_4 + 8;
temp_v0_4->unk0 = 0x1060040;
temp_v0_4->unk4 = (gGfxPool + (D_80150112 << 6) + 0xCAC0) & 0x1FFFFFFF;
D_80150112 = D_80150112 + 1;
}
} else {
temp_v0_5 = gDisplayListHead;
gDisplayListHead = temp_v0_5 + 8;
temp_v0_5->unk0 = 0x1020040;
temp_v0_5->unk4 = (gGfxPool + (D_80150112 << 6) + 0xCAC0) & 0x1FFFFFFF;
D_80150112 = D_80150112 + 1;
func_802B75F8(&gGfxPool->mtxPool[D_80150112 + 0x32B], arg0);
switch (arg1) { /* irregular */
case 0:
gSPMatrix(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(&gGfxPool->mtxPool[D_80150112 + 0x32B]), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
D_80150112 += 1;
break;
case 1:
gSPMatrix(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(&gGfxPool->mtxPool[D_80150112 + 0x32B]), G_MTX_PUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
D_80150112 += 1;
break;
case 3:
gSPMatrix(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(&gGfxPool->mtxPool[D_80150112 + 0x32B]), G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW);
D_80150112 += 1;
break;
case 2:
gSPMatrix(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(&gGfxPool->mtxPool[D_80150112 + 0x32B]), G_MTX_NOPUSH | G_MTX_MUL | G_MTX_MODELVIEW);
D_80150112 += 1;
break;
}
return 1;
}
#else
GLOBAL_ASM("asm/non_matchings/math_util/func_802B4FF8.s")
#endif
f32 func_802B51E8(struct UnkStruct_802B51E8 *arg0, struct UnkStruct_802B51E8 *arg1) {
f32 temp_f12;
@@ -237,30 +197,31 @@ void mtxf_identity(Mat4 mtx) {
}
}
#ifdef MIPS_TO_C
//generated by mips_to_c commit bd0364fa19633bd6201f8007e2d0a7ed87825909
void func_802B5450(void *arg0, void *arg1, void *arg2) {
arg1->unk30 = arg2->unk0 + arg0->unk30;
arg1->unk34 = arg2->unk4 + arg0->unk34;
arg1->unk38 = arg2->unk8 + arg0->unk38;
arg1->unk3C = arg0->unk3C;
arg1->unk0 = arg0->unk0;
arg1->unk4 = arg0->unk4;
arg1->unk8 = arg0->unk8;
arg1->unkC = arg0->unkC;
arg1->unk10 = arg0->unk10;
arg1->unk14 = arg0->unk14;
arg1->unk18 = arg0->unk18;
arg1->unk1C = arg0->unk1C;
arg1->unk20 = arg0->unk20;
arg1->unk24 = arg0->unk24;
arg1->unk28 = arg0->unk28;
arg1->unk2C = arg0->unk2C;
void func_802B5450(Mat4 arg0, Mat4 arg1, Mat4 arg2) {
arg1[3][0] = arg0[3][0] + arg2[0][0];
arg1[3][1] = arg0[3][1] + arg2[0][1];
arg1[3][2] = arg0[3][2] + arg2[0][2];
arg1[3][3] = arg0[3][3];
arg1[0][0] = arg0[0][0];
arg1[0][1] = arg0[0][1];
arg1[0][2] = arg0[0][2];
arg1[0][3] = arg0[0][3];
arg1[1][0] = arg0[1][0];
arg1[1][1] = arg0[1][1];
arg1[1][2] = arg0[1][2];
arg1[1][3] = arg0[1][3];
arg1[2][0] = arg0[2][0];
arg1[2][1] = arg0[2][1];
arg1[2][2] = arg0[2][2];
arg1[2][3] = arg0[2][3];
}
#else
GLOBAL_ASM("asm/non_matchings/math_util/func_802B5450.s")
#endif
/* extern */
UNUSED void func_802B54EC(Mat4 arg0, Mat4 arg1, Mat4 arg2) {
arg1[3][0] = arg0[3][0] + arg2[0][0];
arg1[3][1] = arg0[3][1] + arg2[0][1];
arg1[3][2] = arg0[3][2] + arg2[0][2];
}
void mtxf_translate(Mat4 dest, Vec3f b) {
mtxf_identity(dest);
dest[3][0] = b[0];
@@ -729,22 +690,17 @@ loop_4:
GLOBAL_ASM("asm/non_matchings/math_util/func_802B5D64.s")
#endif
#ifdef MIPS_TO_C
//generated by mips_to_c commit bd0364fa19633bd6201f8007e2d0a7ed87825909
void func_802B5F00(void *arg0, f32 arg1) {
arg0->unk0 = arg0->unk0 * arg1;
arg0->unk10 = arg0->unk10 * arg1;
arg0->unk20 = arg0->unk20 * arg1;
arg0->unk4 = arg0->unk4 * arg1;
arg0->unk14 = arg0->unk14 * arg1;
arg0->unk24 = arg0->unk24 * arg1;
arg0->unk8 = arg0->unk8 * arg1;
arg0->unk18 = arg0->unk18 * arg1;
arg0->unk28 = arg0->unk28 * arg1;
void func_802B5F00(Mat4 arg0, f32 arg1) {
arg0[0][0] *= arg1;
arg0[1][0] *= arg1;
arg0[2][0] *= arg1;
arg0[0][1] *= arg1;
arg0[1][1] *= arg1;
arg0[2][1] *= arg1;
arg0[0][2] *= arg1;
arg0[1][2] *= arg1;
arg0[2][2] *= arg1;
}
#else
GLOBAL_ASM("asm/non_matchings/math_util/func_802B5F00.s")
#endif
#ifdef MIPS_TO_C
//generated by mips_to_c commit bd0364fa19633bd6201f8007e2d0a7ed87825909
@@ -1374,49 +1330,26 @@ void func_802B6D58(void *arg0, void *arg1, void *arg2) {
GLOBAL_ASM("asm/non_matchings/math_util/func_802B6D58.s")
#endif
#ifdef MIPS_TO_C
//generated by mips_to_c commit bd0364fa19633bd6201f8007e2d0a7ed87825909
? func_802B5398(f32 *, ?); /* extern */
void func_802B71CC(void *arg1, void *arg2) {
f32 sp5C;
f32 sp58;
f32 sp54;
f32 sp50;
f32 sp4C;
f32 sp48;
f32 sp44;
f32 sp40;
f32 sp3C;
f32 sp38;
f32 sp34;
f32 sp30;
f32 sp2C;
f32 sp28;
f32 sp24;
f32 sp20;
sp20 = (arg2->unk30 * arg1->unkC) + ((arg1->unk0 * arg2->unk0) + (arg1->unk4 * arg2->unk10) + (arg1->unk8 * arg2->unk20));
sp24 = (arg2->unk34 * arg1->unkC) + ((arg1->unk0 * arg2->unk4) + (arg1->unk4 * arg2->unk14) + (arg1->unk8 * arg2->unk24));
sp28 = (arg2->unk38 * arg1->unkC) + ((arg1->unk0 * arg2->unk8) + (arg1->unk4 * arg2->unk18) + (arg1->unk8 * arg2->unk28));
sp2C = (arg2->unk3C * arg1->unkC) + ((arg1->unk0 * arg2->unkC) + (arg1->unk4 * arg2->unk1C) + (arg1->unk8 * arg2->unk2C));
sp30 = (arg2->unk30 * arg1->unk1C) + ((arg1->unk10 * arg2->unk0) + (arg1->unk14 * arg2->unk10) + (arg1->unk18 * arg2->unk20));
sp34 = (arg2->unk34 * arg1->unk1C) + ((arg1->unk10 * arg2->unk4) + (arg1->unk14 * arg2->unk14) + (arg1->unk18 * arg2->unk24));
sp38 = (arg2->unk38 * arg1->unk1C) + ((arg1->unk10 * arg2->unk8) + (arg1->unk14 * arg2->unk18) + (arg1->unk18 * arg2->unk28));
sp3C = (arg2->unk3C * arg1->unk1C) + ((arg1->unk10 * arg2->unkC) + (arg1->unk14 * arg2->unk1C) + (arg1->unk18 * arg2->unk2C));
sp40 = (arg2->unk30 * arg1->unk2C) + ((arg1->unk20 * arg2->unk0) + (arg1->unk24 * arg2->unk10) + (arg1->unk28 * arg2->unk20));
sp44 = (arg2->unk34 * arg1->unk2C) + ((arg1->unk20 * arg2->unk4) + (arg1->unk24 * arg2->unk14) + (arg1->unk28 * arg2->unk24));
sp48 = (arg2->unk38 * arg1->unk2C) + ((arg1->unk20 * arg2->unk8) + (arg1->unk24 * arg2->unk18) + (arg1->unk28 * arg2->unk28));
sp4C = (arg2->unk3C * arg1->unk2C) + ((arg1->unk20 * arg2->unkC) + (arg1->unk24 * arg2->unk1C) + (arg1->unk28 * arg2->unk2C));
sp50 = (arg2->unk30 * arg1->unk3C) + ((arg1->unk30 * arg2->unk0) + (arg1->unk34 * arg2->unk10) + (arg1->unk38 * arg2->unk20));
sp54 = (arg2->unk34 * arg1->unk3C) + ((arg1->unk30 * arg2->unk4) + (arg1->unk34 * arg2->unk14) + (arg1->unk38 * arg2->unk24));
sp58 = (arg2->unk38 * arg1->unk3C) + ((arg1->unk30 * arg2->unk8) + (arg1->unk34 * arg2->unk18) + (arg1->unk38 * arg2->unk28));
sp5C = (arg2->unk3C * arg1->unk3C) + ((arg1->unk30 * arg2->unkC) + (arg1->unk34 * arg2->unk1C) + (arg1->unk38 * arg2->unk2C));
func_802B5398(&sp20, 0x10);
void func_802B71CC(Mat4 arg0, Mat4 arg1, Mat4 arg2) {
Mat4 product;
product[0][0] = (arg1[0][0] * arg2[0][0]) + (arg1[0][1] * arg2[1][0]) + (arg1[0][2] * arg2[2][0]) + (arg1[0][3] * arg2[3][0]);
product[0][1] = (arg1[0][0] * arg2[0][1]) + (arg1[0][1] * arg2[1][1]) + (arg1[0][2] * arg2[2][1]) + (arg1[0][3] * arg2[3][1]);
product[0][2] = (arg1[0][0] * arg2[0][2]) + (arg1[0][1] * arg2[1][2]) + (arg1[0][2] * arg2[2][2]) + (arg1[0][3] * arg2[3][2]);
product[0][3] = (arg1[0][0] * arg2[0][3]) + (arg1[0][1] * arg2[1][3]) + (arg1[0][2] * arg2[2][3]) + (arg1[0][3] * arg2[3][3]);
product[1][0] = (arg1[1][0] * arg2[0][0]) + (arg1[1][1] * arg2[1][0]) + (arg1[1][2] * arg2[2][0]) + (arg1[1][3] * arg2[3][0]);
product[1][1] = (arg1[1][0] * arg2[0][1]) + (arg1[1][1] * arg2[1][1]) + (arg1[1][2] * arg2[2][1]) + (arg1[1][3] * arg2[3][1]);
product[1][2] = (arg1[1][0] * arg2[0][2]) + (arg1[1][1] * arg2[1][2]) + (arg1[1][2] * arg2[2][2]) + (arg1[1][3] * arg2[3][2]);
product[1][3] = (arg1[1][0] * arg2[0][3]) + (arg1[1][1] * arg2[1][3]) + (arg1[1][2] * arg2[2][3]) + (arg1[1][3] * arg2[3][3]);
product[2][0] = (arg1[2][0] * arg2[0][0]) + (arg1[2][1] * arg2[1][0]) + (arg1[2][2] * arg2[2][0]) + (arg1[2][3] * arg2[3][0]);
product[2][1] = (arg1[2][0] * arg2[0][1]) + (arg1[2][1] * arg2[1][1]) + (arg1[2][2] * arg2[2][1]) + (arg1[2][3] * arg2[3][1]);
product[2][2] = (arg1[2][0] * arg2[0][2]) + (arg1[2][1] * arg2[1][2]) + (arg1[2][2] * arg2[2][2]) + (arg1[2][3] * arg2[3][2]);
product[2][3] = (arg1[2][0] * arg2[0][3]) + (arg1[2][1] * arg2[1][3]) + (arg1[2][2] * arg2[2][3]) + (arg1[2][3] * arg2[3][3]);
product[3][0] = (arg1[3][0] * arg2[0][0]) + (arg1[3][1] * arg2[1][0]) + (arg1[3][2] * arg2[2][0]) + (arg1[3][3] * arg2[3][0]);
product[3][1] = (arg1[3][0] * arg2[0][1]) + (arg1[3][1] * arg2[1][1]) + (arg1[3][2] * arg2[2][1]) + (arg1[3][3] * arg2[3][1]);
product[3][2] = (arg1[3][0] * arg2[0][2]) + (arg1[3][1] * arg2[1][2]) + (arg1[3][2] * arg2[2][2]) + (arg1[3][3] * arg2[3][2]);
product[3][3] = (arg1[3][0] * arg2[0][3]) + (arg1[3][1] * arg2[1][3]) + (arg1[3][2] * arg2[2][3]) + (arg1[3][3] * arg2[3][3]);
func_802B5398(arg0, product, 0x10);
}
#else
GLOBAL_ASM("asm/non_matchings/math_util/func_802B71CC.s")
#endif
#ifdef MIPS_TO_C
//generated by mips_to_c commit bd0364fa19633bd6201f8007e2d0a7ed87825909
+14 -19
View File
@@ -4,25 +4,7 @@
#include <PR/ultratypes.h>
#include "types.h"
/*
* The sine and cosine tables overlap, but "#define gCosineTable (gSineTable +
* 0x400)" doesn't give expected codegen; gSineTable and gCosineTable need to
* be different symbols for code to match. Most likely the tables were placed
* adjacent to each other, and gSineTable cut short, such that reads overflow
* into gCosineTable.
*
* These kinds of out of bounds reads are undefined behavior, and break on
* e.g. GCC (which doesn't place the tables next to each other, and probably
* exploits array sizes for range analysis-based optimizations as well).
* Thus, for non-IDO compilers we use the standard-compliant version.
*/
extern f32 gSineTable[];
#ifdef AVOID_UB
#define gCosineTable (gSineTable + 0x400)
#else
extern f32 gCosineTable[];
#endif
#include "trig_tables.h"
//#define sins(x) gSineTable[(u16) (x) >> 4]
//#define coss(x) gCosineTable[(u16) (x) >> 4]
@@ -32,4 +14,17 @@ extern f32 gCosineTable[];
#define sqr(x) ((x) * (x))
s32 func_802B4FF8(Mat4, s32);
void mtxf_identity(Mat4);
void func_802B5398(Mat4, Mat4, s32);
void func_802B5450(Mat4, Mat4, Mat4);
void func_802B54EC(Mat4, Mat4, Mat4);
void mtxf_translate(Mat4, Vec3f);
void func_802B5F00(Mat4, f32);
void func_802B71CC(Mat4, Mat4, Mat4);
void func_802B75F8(Mtx*, Mat4);
u32 func_802B7830(f32, f32);
f32 sins(u16);
f32 coss(u16);
#endif // MATH_UTIL_H