diff options
| author | MegaMech <MegaMech@users.noreply.github.com> | 2022-06-14 02:37:54 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-14 01:37:54 -0700 |
| commit | d9bd7bfbc0f6d45312d6d13b1902e9ae4e4b839e (patch) | |
| tree | ff88776da6c86bd467a560f2e631a6bff6d23edd /src | |
| parent | ed3dad7e1a38f126b9364e3134eb43d0ab30671e (diff) | |
crash_screen decomp and misc (#221)
* crash_screen decomp and misc
Diffstat (limited to 'src')
| -rw-r--r-- | src/code_800AF9B0.c | 16 | ||||
| -rw-r--r-- | src/code_80290C20.c | 64 | ||||
| -rw-r--r-- | src/crash_screen.c | 470 | ||||
| -rw-r--r-- | src/math_util.c | 624 | ||||
| -rw-r--r-- | src/math_util.h | 6 |
5 files changed, 433 insertions, 747 deletions
diff --git a/src/code_800AF9B0.c b/src/code_800AF9B0.c index 4aa937ea2..5d4b81183 100644 --- a/src/code_800AF9B0.c +++ b/src/code_800AF9B0.c @@ -2161,17 +2161,11 @@ GLOBAL_ASM("asm/non_matchings/code_800AF9B0/func_800B29D8.s") #endif s32 func_800B34E8(s32 arg0) { - if (arg0 == gCharacterGridSelections[0]) { - return 0; - } - if (arg0 == D_8018EDE5) { - return 0; - } - if (arg0 == D_8018EDE6) { - return 0; - } - if (arg0 == D_8018EDE7) { - return 0; + s32 i; + for (i =0; i < 4; i++) { + if (arg0 == gCharacterGridSelections[i]) { + return 0; + } } return 1; } diff --git a/src/code_80290C20.c b/src/code_80290C20.c index 36c061c5a..f824d7216 100644 --- a/src/code_80290C20.c +++ b/src/code_80290C20.c @@ -18,6 +18,9 @@ extern uintptr_t gSegmentTable[]; extern void func_802AAAAC(Player *); extern Player gPlayers[]; +extern s32 D_8015F59C; +extern s32 D_8015F5A0; + s32 func_80290C20(Camera *camera) { if (camera->unk14 == 0) { return 1; @@ -31,42 +34,43 @@ s32 func_80290C20(Camera *camera) { return 0; } -#ifdef MIPS_TO_C +//#ifdef MIPS_TO_C //generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307 void func_802AF5D8(u32, s8, s32); // extern extern s32 D_8015F5A4; -void func_80290CAC(u32 arg0) { - s32 *temp_s0; - s32 *phi_s0; - - temp_s0 = *(&gSegmentTable + ((arg0 >> 0x18) * 4)) + (arg0 & 0xFFFFFF) + 0x80000000; - phi_s0 = temp_s0; - if (*temp_s0 != 0) { - do { - if ((phi_s0->unk6 & 0x8000) != 0) { - D_8015F59C = 1; - } else { - D_8015F59C = 0; - } - if ((phi_s0->unk6 & 0x2000) != 0) { - D_8015F5A0 = 1; - } else { - D_8015F5A0 = 0; - } - if ((phi_s0->unk6 & 0x4000) != 0) { - D_8015F5A4 = 1; - } else { - D_8015F5A4 = 0; - } - func_802AF5D8(phi_s0->unk0, phi_s0->unk4, phi_s0->unk5); - phi_s0 += 8; - } while (phi_s0->unk8 != 0); +struct Unk0CAC { + s32 unk0; + u8 unk4; + u8 unk5; + u16 unk6; +}; + +void func_80290CAC(uintptr_t arg0) { + s32 segment = SEGMENT_NUMBER2(arg0); + s32 offset = SEGMENT_OFFSET(arg0); + struct Unk0CAC *data = VIRTUAL_TO_PHYSICAL2(gSegmentTable[segment] + offset); + + while(data->unk0 != 0) { + if ((data->unk6 & 0x8000) != 0) { + D_8015F59C = 1; + } else { + D_8015F59C = 0; + } + if ((data->unk6 & 0x2000) != 0) { + D_8015F5A0 = 1; + } else { + D_8015F5A0 = 0; + } + if ((data->unk6 & 0x4000) != 0) { + D_8015F5A4 = 1; + } else { + D_8015F5A4 = 0; + } + func_802AF5D8(data->unk0, data->unk4, data->unk5); + data++; } } -#else -GLOBAL_ASM("asm/non_matchings/code_80290C20/func_80290CAC.s") -#endif #ifdef MIPS_TO_C //generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307 diff --git a/src/crash_screen.c b/src/crash_screen.c index 87d999bb6..1a0a31bcb 100644 --- a/src/crash_screen.c +++ b/src/crash_screen.c @@ -20,14 +20,14 @@ void *get_faulted_thread(); // static void start_debug_thread(); // static void thread9_crash_screen(s32 arg0); // static extern void *gControllerOne; -extern s32 D_800DC670; +extern s32 sCounter; -extern ? D_800DC6FC; +extern ? sCrashScreenButtonSequence; extern ? D_80162790; extern ? D_80162D40; extern ? D_80162D58; extern uintptr_t pFramebuffer; -extern s32 D_80162D60; +extern s32 buttonSequenceIndex; extern void *D_80162D64; */ @@ -38,8 +38,11 @@ ALIGNED8 u8 gDebugThreadStack[0x400]; OSMesgQueue D_80162D40; OSMesg D_80162D58; uintptr_t pFramebuffer; -s32 D_80162D60; -void *D_80162D64; +s32 sButtonSequenceIndex; +//void *D_80162D64; + +#define DRAW_CODE 0xFFFF +#define CHARACTER_DASH 16 extern void osSetEventMesg(OSEvent, OSMesgQueue *, OSMesg); extern s32 osRecvMesg(OSMesgQueue *, OSMesg *, s32); @@ -49,15 +52,14 @@ extern struct Controller *gControllerOne; //s32 shift = 0; -u32 D_800DC670 = 0; +s32 sCounter = 0; u8 crashScreenFont[][8] = { #include "textures/crash_screen/crash_screen_font.ia1.inc.c" }; -u16 D_800DC6FC[10] = { - 32, 2048, 512, 1024, 256, 16, 32, 16384, 32768, 65535 - // 0x0020, 0x0800, 0x0200, 0x0400, 0x0100, 0x0010, 0x0020, 0x4000, 0x8000, 0xffff +u16 sCrashScreenButtonSequence[] = { + L_TRIG, U_JPAD, L_JPAD, D_JPAD, R_JPAD, R_TRIG, L_TRIG, B_BUTTON, A_BUTTON, DRAW_CODE }; void crash_screen_draw_glyph(u16 *framebuffer, s32 x, s32 y, s32 glyph) { @@ -83,10 +85,10 @@ void crash_screen_draw_glyph(u16 *framebuffer, s32 x, s32 y, s32 glyph) { #ifdef MIPS_TO_C //generated by mips_to_c commit bd0364fa19633bd6201f8007e2d0a7ed87825909 -? osViSwapBuffer(s32); /* extern */ -? osWritebackDCacheAll(s32, s32, s16, s16); /* extern */ -void crash_screen_draw_square(s32 arg0, s32 arg1) { +#define WHITE_COLOUR 0xFFFF +#define RED_COLOUR 0xF801 +void crash_screen_draw_square(u16 *framebuffer) { s32 temp_a0; s32 temp_a1; s32 temp_a1_2; @@ -109,198 +111,176 @@ void crash_screen_draw_square(s32 arg0, s32 arg1) { s32 phi_a0_3; s32 phi_a1_3; s32 phi_a1_4; - - phi_s2 = 0x28; - phi_s0 = 0x2E; - phi_a0_2 = arg0; - phi_a1_3 = arg1; - do { - phi_s1 = phi_s2; - phi_a0 = phi_a0_2; - phi_a1_2 = phi_a1_3; - phi_a0_3 = phi_a0_2; - phi_a1_4 = phi_a1_3; - if (phi_s2 < phi_s0) { - do { - phi_v1 = phi_s2; - phi_v1_2 = phi_s2; + s32 i, j, k; + + //phi_s2 = 0x28; + //phi_s0 = 0x2E; + phi_a0_2 = framebuffer; + //phi_a1_3 = arg1; + for (i = 46; i > 44; i--) { + //phi_s1 = phi_s2; + //phi_a0 = phi_a0_2; + //phi_a1_2 = phi_a1_3; + // phi_a0_3 = phi_a0_2; + //phi_a1_4 = phi_a1_3; + //if (phi_s2 < phi_s0) { + for (j = 40; j < i; j++) { + //phi_v1 = phi_s2; + //phi_v1_2 = phi_s2; if (phi_s2 < phi_s0) { - temp_a0 = phi_s0 - phi_s2; - temp_t0 = temp_a0 & 3; - temp_ra = arg0 + (phi_s1 * 0x280); - phi_a0_3 = temp_a0; + //temp_a0 = i - j; + temp_t0 = (i - j) & 3; + //temp_ra = framebuffer + (phi_s1 * 0x280); + //phi_a0_3 = temp_a0; if (temp_t0 != 0) { phi_v0 = temp_ra + (phi_s2 * 2); - do { - temp_v1 = phi_v1 + 1; - phi_v1 = temp_v1; - phi_v1_2 = temp_v1; - if (temp_a0 == 6) { - *phi_v0 = 0xF801; + do { // (temp_t0 + j;) { + j++; + //temp_v1 = phi_v1 + 1; + //phi_v1 = temp_v1; + //phi_v1_2 = temp_v1; + if (i - j == 6) { + framebuffer[i * 640 + j * 2] = RED_COLOUR; } else { - *phi_v0 = 0xFFFF; + framebuffer[i * 640 + j * 2] = WHITE_COLOUR; } - phi_v0 += 2; - } while ((temp_t0 + phi_s2) != temp_v1); + j += 2; + } while ((temp_t0 + j) != j); phi_a1_4 = temp_v1 * 2; if (temp_v1 != phi_s0) { - goto block_10; + break; // goto 10 } } else { -block_10: - temp_a1 = phi_v1_2 * 2; - phi_v0_2 = temp_ra + temp_a1; +//block_10: + //temp_a1 = phi_v1_2 * 2; + phi_v0_2 = framebuffer[i * 640 + j * 2]; phi_a1 = temp_a1; - do { - temp_a1_2 = phi_a1 + 8; - phi_a1 = temp_a1_2; - phi_a1_4 = temp_a1_2; - if (temp_a0 == 6) { - phi_v0_2->unk0 = 0xF801; - } else { - phi_v0_2->unk0 = 0xFFFF; - } - if (temp_a0 == 6) { - phi_v0_2->unk2 = 0xF801; - } else { - phi_v0_2->unk2 = 0xFFFF; - } - if (temp_a0 == 6) { - phi_v0_2->unk4 = 0xF801; - } else { - phi_v0_2->unk4 = 0xFFFF; - } + for (k = j + 8; k < j * 2; k += 8) { + //do { + //temp_a1_2 = phi_a1 + 8; + //phi_a1 = temp_a1_2; + //phi_a1_4 = temp_a1_2; if (temp_a0 == 6) { - phi_v0_2->unk6 = 0xF801; + framebuffer[i * 640 + j * 2] = RED_COLOUR; } else { - phi_v0_2->unk6 = 0xFFFF; + framebuffer[i * 640 + j * 2] = WHITE_COLOUR; } - phi_v0_2 += 8; - } while (temp_a1_2 != (phi_s0 * 2)); + //if (temp_a0 == 6) { + // phi_v0_2->unk2 = RED_COLOUR; + //} else { + // phi_v0_2->unk2 = WHITE_COLOUR; + //} + //if (temp_a0 == 6) { + // phi_v0_2->unk4 = RED_COLOUR; + //} else { + // phi_v0_2->unk4 = WHITE_COLOUR; + //} + //if (temp_a0 == 6) { + // phi_v0_2->unk6 = RED_COLOUR; + //} else { + // phi_v0_2->unk6 = WHITE_COLOUR; + //} + //phi_v0_2 += 8; + } //while (temp_a1_2 != (phi_s0 * 2)); } } - temp_s1 = phi_s1 + 1; - phi_s1 = temp_s1; - phi_a0 = phi_a0_3; - phi_a1_2 = phi_a1_4; - } while (temp_s1 != phi_s0); - } - temp_s0 = phi_s0 - 1; - phi_s2 += 1; - phi_s0 = temp_s0; - phi_a0_2 = phi_a0; - phi_a1_3 = phi_a1_2; - } while (temp_s0 != 0x2C); - osWritebackDCacheAll(phi_a0, phi_a1_2, 0xF801, 0xFFFF); - osViSwapBuffer(arg0); + //temp_s1 = phi_s1 + 1; + //phi_s1 = temp_s1; + //phi_a0 = phi_a0_3; + //phi_a1_2 = phi_a1_4; + } //while (temp_s1 != phi_s0); + + //temp_s0 = phi_s0 - 1; + //phi_s2 += 1; + //phi_s0 = temp_s0; + //phi_a0_2 = phi_a0; + //phi_a1_3 = phi_a1_2; + //i--; + } //while (temp_s0 != 44); + osWritebackDCacheAll(); + osViSwapBuffer(framebuffer); } #else GLOBAL_ASM("asm/non_matchings/crash_screen/crash_screen_draw_square.s") #endif -#ifdef MIPS_TO_C -//generated by mips_to_c commit bd0364fa19633bd6201f8007e2d0a7ed87825909 -? crash_screen_draw_glyph(s32, s32, s32, u32); /* extern */ -? osViSwapBuffer(s32); /* extern */ -? osWritebackDCacheAll(); /* extern */ -extern s32 D_800DC670; - -void crash_screen_draw_info(s32 arg0, void *arg1) { - s32 temp_a2; - s32 temp_s0; - s32 temp_s1; - s32 temp_s1_3; - s32 temp_s1_4; - s32 temp_t0; - s32 temp_v1; - u32 temp_s1_2; - u32 temp_t3; - u32 temp_t4; - void *temp_s2; - void *temp_v0; - void *phi_v0; - s32 phi_v1; - s32 phi_a2; - s32 phi_t0; - s32 phi_s1; - u32 phi_s4; - s32 phi_s1_2; - u32 phi_s4_2; - s32 phi_s1_3; - u32 phi_s4_3; - void *phi_a3; - - phi_t0 = 0; - do { - phi_a2 = 0; - phi_a3 = arg0 + (((D_800DC670 * 0x18) + phi_t0 + 0x30) * 0x280); -loop_2: - phi_v0 = phi_a3; - phi_v1 = 0; -loop_3: - temp_v1 = phi_v1 + 4; - phi_v0->unkCA = 1; - phi_v0->unkCC = 1; - phi_v0->unkCE = 1; - temp_v0 = phi_v0 + 8; - temp_v0->unkC0 = 1; - phi_v0 = temp_v0; - phi_v1 = temp_v1; - if (temp_v1 != 0x78) { - goto loop_3; - } - temp_a2 = phi_a2 + 1; - phi_a2 = temp_a2; - phi_a3 += 0x280; - if (temp_a2 < 0x10) { - goto loop_2; +/** + * Draws three black boxes then prints crash info in the following format: + * Line 1: threadId - address of faulted instruction - error code + * Line 2: Address in the return address register + * Line 3: Machine code of faulted instruction + * + * The R4300i manual discusses exceptions in more depth. + * + * @param framebuffer + * @param faulted thread + **/ +void crash_screen_draw_info(u16 *framebuffer, OSThread *thread) { + __OSThreadContext *context = &thread->context; + s32 i, j, x, y, h; + uintptr_t faultedAddr; + u32 exception; + s32 math; + u32 crashInfo; + s32 temp; + + // Draw three black boxes + for (h = 0; h < 3; h++) { + + math = (48 + (sCounter * 24)) + h * 20; + + for (i = 0; i < 16; i++) { + for (j = 0; j < 120; j++) { + // Set pixels to black + framebuffer[((i + math) * 320) + (j + 100)] = 0x0001; + } } - temp_t0 = phi_t0 + 0x14; - phi_t0 = temp_t0; - } while (temp_t0 < 0x3C); - temp_s0 = (D_800DC670 * 0x18) + 0x35; - crash_screen_draw_glyph(arg0, 0x6C, temp_s0, arg1->unk14 & 0xF); - crash_screen_draw_glyph(arg0, 0x74, temp_s0, 0x10); - temp_s2 = arg1 + 0x20; - phi_s1 = 0xB4; - phi_s4 = temp_s2->unkFC; - phi_s1_2 = 0xB4; - phi_s1_3 = 0xB4; - do { - crash_screen_draw_glyph(arg0, phi_s1, temp_s0, phi_s4 & 0xF); - temp_s1 = phi_s1 - 8; - phi_s1 = temp_s1; - phi_s4 = phi_s4 >> 4; - } while (temp_s1 >= 0x7C); - temp_s1_2 = (temp_s2->unk100 >> 2) & 0x1F; - crash_screen_draw_glyph(arg0, 0xBC, temp_s0, 0x10); - crash_screen_draw_glyph(arg0, 0xC4, temp_s0, temp_s1_2 >> 4); - crash_screen_draw_glyph(arg0, 0xCC, temp_s0, temp_s1_2 & 0xF); - phi_s4_2 = temp_s2->unkE4; - do { - crash_screen_draw_glyph(arg0, phi_s1_2, 0x49, phi_s4_2 & 0xF); - temp_s1_3 = phi_s1_2 - 8; - temp_t3 = phi_s4_2 >> 4; - phi_s1_2 = temp_s1_3; - phi_s4_2 = temp_t3; - phi_s4_3 = temp_t3; - } while (temp_s1_3 >= 0x7C); - temp_t4 = temp_s2->unkFC & ~3; - if ((temp_t4 >= 0x80000001) && (temp_t4 < 0x803FFF7F)) { - phi_s4_3 = *temp_t4; } - do { - crash_screen_draw_glyph(arg0, phi_s1_3, 0x5D, phi_s4_3 & 0xF); - temp_s1_4 = phi_s1_3 - 8; - phi_s1_3 = temp_s1_4; - phi_s4_3 = phi_s4_3 >> 4; - } while (temp_s1_4 >= 0x7C); + + // Draw crash information over the black boxes. + temp = (sCounter * 24); + y = temp + 53; + crash_screen_draw_glyph(framebuffer, 108, y, thread->id & 0xF); + crash_screen_draw_glyph(framebuffer, 116, y, CHARACTER_DASH); + + // Address of faulted instruction. + crashInfo = context->pc; + + for (x = 180; x >= 124; x -= 8) { + crash_screen_draw_glyph(framebuffer, x, y, crashInfo & 0xF); + crashInfo >>= 4; + } + + exception = (context->cause >> 2) & 0x1F; + crash_screen_draw_glyph(framebuffer, 188, y, CHARACTER_DASH); + crash_screen_draw_glyph(framebuffer, 196, y, exception >> 4); + crash_screen_draw_glyph(framebuffer, 204, y, exception & 0xF); + + // Address in the Return Address register. + crashInfo = context->ra; + + for (x = 180; x >= 124; x -= 8) { + crash_screen_draw_glyph(framebuffer, x, 73, crashInfo & 0xF); + crashInfo >>= 4; + } + + // Address of faulted instruction. + faultedAddr = context->pc & (~3); + + // Ensure the address to the faulted instruction is a memory address. + // @bug if this check fails, the ra register is printed a second time. + if ((faultedAddr > 0x80000000) && (faultedAddr < 0x803FFF7F)) { + // Cast the address to its value; the faulty machine code. + crashInfo = *(u32*)faultedAddr; + } + for (x = 180; x >= 124; x -= 4) { + crash_screen_draw_glyph(framebuffer, x, 93, crashInfo & 0xF); + x -= 4; + crashInfo >>= 4; + } osWritebackDCacheAll(); - osViSwapBuffer(arg0); + osViSwapBuffer(framebuffer); } -#else -GLOBAL_ASM("asm/non_matchings/crash_screen/crash_screen_draw_info.s") -#endif OSThread *get_faulted_thread(void) { OSThread *thread; @@ -316,104 +296,60 @@ OSThread *get_faulted_thread(void) { return NULL; } -#ifdef MIPS_TO_C -//generated by mips_to_c commit bd0364fa19633bd6201f8007e2d0a7ed87825909 +/** + * @brief Retrieves faulted thread and displays debug info after the user inputs the button sequence. + * Button sequence: L, Up, Left, Down, Right, R, L, B, A + **/ +void thread9_crash_screen(UNUSED void *arg0) +{ + static OSThread *thread; + OSMesg mesg; -//OSThread *get_faulted_thread(); -void crash_screen_draw_square(s32, void*); -void crash_screen_draw_info(s32, void*); + osSetEventMesg(12, &D_80162D40, (OSMesg) 16); + osSetEventMesg(10, &D_80162D40, (OSMesg) 16); + sButtonSequenceIndex = 0; -void thread9_crash_screen(UNUSED s32 arg0) { - OSMesg mesg; - OSThread *thread; - //s32 pad[2]; - u16 temp_v0_2; - - osSetEventMesg(OS_EVENT_FAULT, &D_80162D40, (OSMesg) 16); - osSetEventMesg(OS_EVENT_CPU_BREAK, &D_80162D40, (OSMesg) 16); - D_80162D60 = 0; - loop_1: - do { - do { + while (1) { osRecvMesg(&D_80162D40, &mesg, 1); thread = get_faulted_thread(); - } while (thread == NULL); - - if (D_800DC670 == 0) { - crash_screen_draw_square(pFramebuffer, D_80162D64); - do { - //temp_v0_2 = gControllerOne->buttonPressed; - //loop_4: - do { - read_controllers(); - } - while (temp_v0_2 == 0); - //if (temp_v0_2 == 0) { - //goto loop_4; - //} - //temp_v1 = D_80162D60; - //} while (thread == NULL); - if (temp_v0_2 == D_800DC6FC[D_80162D60]) { - D_80162D60++; - } else { - D_80162D60 = 0; - } - } while (D_800DC6FC[D_80162D60] != 0xFFFF); - crash_screen_draw_info(pFramebuffer, D_80162D64); - } -} while (D_800DC670 >= 5); - D_800DC670++; - goto loop_1; - /* - ? sp44; - s32 temp_v0; - s32 temp_v1; - u16 temp_v0_2; - - osSetEventMesg(0xC, &D_80162D40, 0x10); - osSetEventMesg(0xA, &D_80162D40, 0x10); - D_80162D60 = 0; -loop_1: - osRecvMesg(&D_80162D40, &sp44, 1); - temp_v0 = get_faulted_thread(); - D_80162D64 = temp_v0; - if (temp_v0 == 0) { - goto loop_1; - } - if (D_800DC670 == 0) { - crash_screen_draw_square(pFramebuffer); - do { -loop_4: - read_controllers(); - temp_v0_2 = gControllerOne->unk6; - if (temp_v0_2 == 0) { - goto loop_4; + + if (thread) { + // Run only on the first iteration. + if (sCounter == 0) { + crash_screen_draw_square(pFramebuffer); + + while(1) + { + read_controllers(); + + if (!gControllerOne->buttonPressed) { continue; } + + if (gControllerOne->buttonPressed == sCrashScreenButtonSequence[sButtonSequenceIndex]) { + sButtonSequenceIndex++; + } else { + sButtonSequenceIndex = 0; + } + + // draws crash info when DRAW_CODE is reached + if (sCrashScreenButtonSequence[sButtonSequenceIndex] == DRAW_CODE) { + break; + } + } + crash_screen_draw_info(pFramebuffer, thread); + } - temp_v1 = D_80162D60; - if (temp_v0_2 == *(&D_800DC6FC + (temp_v1 * 2))) { - D_80162D60 = temp_v1 + 1; - } else { - D_80162D60 = 0; + if (sCounter < 5) { + sCounter++; } - } while (*(&D_800DC6FC + (D_80162D60 * 2)) != 0xFFFF); - crash_screen_draw_info(pFramebuffer, D_80162D64); - } - if (D_800DC670 >= 5) { - goto loop_1; + } } - D_800DC670 += 1; - goto loop_1; - */ } -#else -GLOBAL_ASM("asm/non_matchings/crash_screen/thread9_crash_screen.s") -#endif -void crash_screen_set_framebuffer(s32 arg0) { - pFramebuffer = arg0; +void crash_screen_set_framebuffer(uintptr_t *framebuffer) { + pFramebuffer = framebuffer; } -extern void thread9_crash_screen(); +extern void thread9_crash_screen(void *); void create_debug_thread(void) { osCreateMesgQueue(&D_80162D40, &D_80162D58, 1); diff --git a/src/math_util.c b/src/math_util.c index 3e6da738b..f4a03e829 100644 --- a/src/math_util.c +++ b/src/math_util.c @@ -11,27 +11,51 @@ #ifdef MIPS_TO_C //generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307 -? func_802B4F60(s32 arg0, ? arg2, ? arg3) { - ? sp30; +void func_802B6434(Vec3f arg0, Mat4 arg1); +void *vec3f_copy(Vec3f, Vec3f); +// weird stuff going on. But this is an unused func... So who cares. +UNUSED s32 func_802B4F60(UNUSED s32 arg0, Vec3f arg2, UNUSED f32 arg3, UNUSED f32 arg4) { + Mat4 sp30; + f32 sp2C; + f32 pad; + Vec3f sp1C; + + vec3f_copy(sp1C, arg2); + sp2C = sp30[1][3]; // permuter + sp2C = (((sp1C[0] * sp30[0][3]) + (((0, sp1C[1])) * sp2C)) + (sp1C[2] * sp30[2][3])) + sp30[3][3]; + + //sp2C = (sp1C[0] * sp30[0][3]) + (sp1C[1] * sp30[1][3]) + (sp1C[2] * sp30[2][3]) + sp30[3][3]; + func_802B6434(sp1C, sp30); + + if (sp2C <= 0) { + return 0; + } + return 1; +} +/* +s32 func_802B4F60(s32 arg0, f32* arg1, ? arg2, ? arg3) { f32 sp2C; f32 sp1C; - f32 temp_f2; - ? phi_v0; - - vec3f_copy(&sp1C); - temp_f2 = sp6C + ((sp3C * sp1C) + (sp4C * sp20) + (sp5C * sp24)); - sp2C = temp_f2; - func_802B6434(sp1C, sp20, &sp1C, &sp30); - phi_v0 = 1; - if (temp_f2 <= 0.0f) { - phi_v0 = 0; + ? var_v0; + + vec3f_copy(&sp1C, arg1); + sp2C = sp6C + ((sp30[3] * sp1C) + (sp4C * sp20) + (sp5C * sp24)); + func_802B6434(&sp1C, (f32 (*)[4]) &sp30[0]); + var_v0 = 1; + if (sp2C <= 0.0f) { + var_v0 = 0; } - return phi_v0; + return var_v0; } +*/ #else GLOBAL_ASM("asm/non_matchings/math_util/func_802B4F60.s") #endif +UNUSED func_802B4FF0() { + +} + s32 func_802B4FF8(Mat4 arg0, s32 arg1) { if (D_80150112 >= 0x80) { return 0; @@ -133,7 +157,7 @@ UNUSED void *sm64_vec3f_set(Vec3f dest, f32 x, f32 y, f32 z) { #ifdef MIPS_TO_C //generated by mips_to_c commit bd0364fa19633bd6201f8007e2d0a7ed87825909 -void func_802B5350(void *arg0, void *arg1) { +UNUSED void func_802B5350(void *arg0, void *arg1) { s32 temp_v0; void *temp_a2; void *temp_v1; @@ -161,30 +185,12 @@ void func_802B5350(void *arg0, void *arg1) { GLOBAL_ASM("asm/non_matchings/math_util/func_802B5350.s") #endif -#ifdef MIPS_TO_C -//generated by mips_to_c commit bd0364fa19633bd6201f8007e2d0a7ed87825909 -void func_802B5398(void *arg0, s32 *arg1, s32 arg2) { - void *temp_a0; - s32 *phi_a1; - void *phi_a0; - s32 phi_a2; - - phi_a1 = arg1; - phi_a0 = arg0; - phi_a2 = arg2 - 1; - if (arg2 > 0) { - do { - temp_a0 = phi_a0 + 4; - temp_a0->unk-4 = *phi_a1; - phi_a1 += 4; - phi_a0 = temp_a0; - phi_a2 += -1; - } while (phi_a2 > 0); - } +// mtxf_copy +void func_802B5398(s32 *dest, s32 *src, s32 arg2) { + while (arg2-- > 0) { + *dest++ = *src++; + } } -#else -GLOBAL_ASM("asm/non_matchings/math_util/func_802B5398.s") -#endif void mtxf_identity(Mat4 mtx) { register s32 i; @@ -228,130 +234,44 @@ void mtxf_translate(Mat4 dest, Vec3f b) { dest[3][1] = b[1]; dest[3][2] = b[2]; } +extern f64 D_802B9FB0; // = 0.017453292222222222; +// Note the use of `2` which generates diff asm than just using floats (2.0f). +void func_802B5564(Mat4 arg0, u16 *arg1, f32 arg2, f32 arg3, f32 arg4, f32 arg5, f32 arg6) { + f32 temp; + s32 i, j; + mtxf_identity(arg0); + arg2 *= D_802B9FB0; + temp = cosf(arg2 / 2) / sinf(arg2 / 2); + arg0[0][0] = temp / arg3; + arg0[1][1] = temp; + arg0[2][2] = (arg4 + arg5) / (arg4 - arg5); + arg0[2][3] = -1.0f; + arg0[3][2] = (2 * arg4 * arg5) / (arg4 - arg5); + arg0[3][3] = 0.0f; -#ifdef MIPS_TO_C -//generated by mips_to_c commit bd0364fa19633bd6201f8007e2d0a7ed87825909 -f32 cosf(f32, f32); /* extern */ -? mtxf_identity(f32); /* extern */ -f32 sinf(f32); /* extern */ -static f64 D_802B9FB0 = 0.017453292222222222; - -void func_802B5564(void *arg0, s16 *arg1, f32 arg2, f32 arg3, f32 arg4, f32 arg5, f32 arg6) { - f32 sp20; - f32 sp1C; - f32 temp_f10; - f32 temp_f10_2; - f32 temp_f12; - f32 temp_f12_2; - f32 temp_f12_3; - f32 temp_f12_4; - f32 temp_f14; - f32 temp_f14_2; - f32 temp_f14_3; - f32 temp_f14_4; - f32 temp_f16; - f32 temp_f16_2; - f32 temp_f18; - f32 temp_f2; - f64 temp_f0; - s32 temp_v1; - u32 temp_t8; - void *temp_v0; - void *temp_v0_2; - f32 phi_f10; - void *phi_v0; - f32 phi_f16; - f32 phi_f12; - f32 phi_f14; - s32 phi_v1; - f32 phi_f10_2; - void *phi_v0_2; - f32 phi_f16_2; - f32 phi_f12_2; - f32 phi_f14_2; - - temp_f14 = arg2; - arg2 = temp_f14; - mtxf_identity(temp_f14); - temp_f14_2 = arg2 * D_802B9FB0; - temp_f12 = temp_f14_2 / 2.0f; - sp1C = temp_f12; - sp20 = cosf(temp_f12, temp_f14_2); - temp_f2 = sp20 / sinf(temp_f12); - temp_f18 = arg4 + arg5; - temp_f12_2 = arg4 - arg5; - arg0->unk2C = -1.0f; - arg0->unk14 = temp_f2; - arg0->unk28 = temp_f18 / temp_f12_2; - arg0->unk0 = temp_f2 / arg3; - arg0->unk3C = 0.0f; - arg0->unk38 = (2.0f * arg4 * arg5) / temp_f12_2; - temp_f16 = arg0->unk4; - temp_f10 = arg0->unk0 * arg6; - temp_f12_3 = arg0->unk8; - temp_f14_3 = arg0->unkC; - phi_f10 = temp_f10; - phi_v0 = arg0; - phi_f16 = temp_f16; - phi_f12 = temp_f12_3; - phi_f14 = temp_f14_3; - phi_v1 = 1; - phi_f10_2 = temp_f10; - phi_v0_2 = arg0; - phi_f16_2 = temp_f16; - phi_f12_2 = temp_f12_3; - phi_f14_2 = temp_f14_3; - if (1 != 4) { - do { - temp_f16_2 = phi_v0->unk14; - temp_f12_4 = phi_v0->unk18; - temp_v1 = phi_v1 + 1; - temp_f14_4 = phi_v0->unk1C; - phi_v0->unk0 = phi_f10; - temp_f10_2 = phi_v0->unk10 * arg6; - phi_v0->unk4 = phi_f16 * arg6; - phi_v0->unk8 = phi_f12 * arg6; - temp_v0 = phi_v0 + 0x10; - temp_v0->unk-4 = phi_f14 * arg6; - phi_f10 = temp_f10_2; - phi_v0 = temp_v0; - phi_f16 = temp_f16_2; - phi_f12 = temp_f12_4; - phi_f14 = temp_f14_4; - phi_v1 = temp_v1; - phi_f10_2 = temp_f10_2; - phi_v0_2 = temp_v0; - phi_f16_2 = temp_f16_2; - phi_f12_2 = temp_f12_4; - phi_f14_2 = temp_f14_4; - } while (temp_v1 != 4); + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + arg0[i][j] *= arg6; + } } - temp_v0_2 = phi_v0_2 + 0x10; - temp_v0_2->unk-10 = phi_f10_2; - temp_v0_2->unk-C = phi_f16_2 * arg6; - temp_v0_2->unk-8 = phi_f12_2 * arg6; - temp_v0_2->unk-4 = phi_f14_2 * arg6; + if (arg1 != 0) { - temp_f0 = temp_f18; - if (temp_f0 <= 2.0) { + if ((arg4 + arg5) <= 2.0) { *arg1 = 0xFFFF; - return; } - temp_t8 = 131072.0 / temp_f0; - *arg1 = temp_t8; - if ((temp_t8 & 0xFFFF) <= 0) { - *arg1 = 1; + else { + *arg1 = 131072.0 / (arg4 + arg5); + if (*arg1 <= 0) { + *arg1 = 1; + } } - /* Duplicate return node #7. Try simplifying control flow for better match */ } } -#else -GLOBAL_ASM("asm/non_matchings/math_util/func_802B5564.s") -#endif #ifdef MIPS_TO_C //generated by mips_to_c commit bd0364fa19633bd6201f8007e2d0a7ed87825909 -void func_802B5794(void *arg0, void *arg1, void *arg2) { +// Similar to sm64's mtxf_lookat +void func_802B5794(void* arg0, void* arg1, void* arg2) { f32 sp4C; f32 sp48; f32 sp30; @@ -377,12 +297,12 @@ void func_802B5794(void *arg0, void *arg1, void *arg2) { temp_f12 = arg2->unk0 - arg1->unk0; temp_f14 = arg2->unk4 - arg1->unk4; temp_f2 = arg2->unk8 - arg1->unk8; - temp_f16 = -1.0 / sqrtf((temp_f12 * temp_f12) + (temp_f14 * temp_f14) + (temp_f2 * temp_f2)); + temp_f16 = (f32) (-1.0 / (f64) sqrtf((temp_f12 * temp_f12) + (temp_f14 * temp_f14) + (temp_f2 * temp_f2))); temp_f12_2 = temp_f12 * temp_f16; temp_f14_2 = temp_f14 * temp_f16; temp_f2_2 = temp_f2 * temp_f16; temp_f16_2 = 0.0f - (1.0f * temp_f12_2); - temp_f22 = 1.0 / sqrtf((temp_f2_2 * temp_f2_2) + 0.0f + (temp_f16_2 * temp_f16_2)); + temp_f22 = (f32) (1.0 / (f64) sqrtf((temp_f2_2 * temp_f2_2) + 0.0f + (temp_f16_2 * temp_f16_2))); temp_f28 = temp_f2_2 * temp_f22; temp_f18 = temp_f16_2 * temp_f22; temp_f6 = temp_f14_2 * temp_f18; @@ -390,7 +310,7 @@ void func_802B5794(void *arg0, void *arg1, void *arg2) { temp_f20 = temp_f6 - (temp_f2_2 * 0.0f); temp_f16_3 = (temp_f2_2 * temp_f28) - (temp_f12_2 * sp30); temp_f18_2 = (temp_f12_2 * 0.0f) - (temp_f14_2 * temp_f28); - temp_f22_2 = 1.0 / sqrtf((temp_f20 * temp_f20) + (temp_f16_3 * temp_f16_3) + (temp_f18_2 * temp_f18_2)); + temp_f22_2 = (f32) (1.0 / (f64) sqrtf((temp_f20 * temp_f20) + (temp_f16_3 * temp_f16_3) + (temp_f18_2 * temp_f18_2))); temp_f20_2 = temp_f20 * temp_f22_2; temp_f10 = temp_f18_2 * temp_f22_2; sp4C = temp_f16_3 * temp_f22_2; @@ -398,118 +318,63 @@ void func_802B5794(void *arg0, void *arg1, void *arg2) { arg0->unk0 = temp_f28; arg0->unk10 = 0.0f; arg0->unk20 = sp30; - arg0->unk30 = -((arg1->unk8 * sp30) + ((arg1->unk0 * temp_f28) + (arg1->unk4 * 0.0f))); + arg0->unk30 = (f32) -((arg1->unk8 * sp30) + ((arg1->unk0 * temp_f28) + (arg1->unk4 * 0.0f))); arg0->unk4 = temp_f20_2; arg0->unk24 = sp48; arg0->unk14 = sp4C; arg0->unk8 = temp_f12_2; arg0->unk18 = temp_f14_2; arg0->unk28 = temp_f2_2; - arg0->unk34 = -((arg1->unk8 * sp48) + ((arg1->unk0 * temp_f20_2) + (arg1->unk4 * sp4C))); + arg0->unk34 = (f32) -((arg1->unk8 * sp48) + ((arg1->unk0 * temp_f20_2) + (arg1->unk4 * sp4C))); arg0->unkC = 0.0f; arg0->unk1C = 0.0f; arg0->unk2C = 0.0f; arg0->unk3C = 1.0f; - arg0->unk38 = -((arg1->unk8 * temp_f2_2) + ((arg1->unk0 * temp_f12_2) + (arg1->unk4 * temp_f14_2))); + arg0->unk38 = (f32) -((arg1->unk8 * temp_f2_2) + ((arg1->unk0 * temp_f12_2) + (arg1->unk4 * temp_f14_2))); } #else GLOBAL_ASM("asm/non_matchings/math_util/func_802B5794.s") #endif -#ifdef MIPS_TO_C -//generated by mips_to_c commit bd0364fa19633bd6201f8007e2d0a7ed87825909 -? mtxf_identity(void *); /* extern */ -f32 sins(s32); /* extern */ -f32 coss(s32); /* extern */ +void func_802B59DC(Mat4 arg0, s16 arg1) { + f32 sp28 = sins(arg1); + f32 temp_f0 = coss(arg1); -void func_802B59DC(void *arg0, s32 arg1) { - f32 sp2C; - f32 sp28; - s32 sp24; - f32 temp_f0; - s32 temp_a0; - - temp_a0 = arg1 & 0xFFFF; - sp24 = temp_a0; - temp_f0 = sins(temp_a0); - sp2C = temp_f0; - sp28 = coss(temp_a0); mtxf_identity(arg0); - arg0->unk18 = temp_f0; - arg0->unk24 = -temp_f0; - arg0->unk14 = sp28; - arg0->unk28 = sp28; + arg0[1][1] = temp_f0; + arg0[1][2] = sp28; + arg0[2][1] = -sp28; + arg0[2][2] = temp_f0; } -#else -GLOBAL_ASM("asm/non_matchings/math_util/func_802B59DC.s") -#endif -#ifdef MIPS_TO_C -//generated by mips_to_c commit bd0364fa19633bd6201f8007e2d0a7ed87825909 -//This function did not have a glabel in the original assembly, as such it may -//be unused/unnamed -? mtxf_identity(void *); /* extern */ -f32 sins(s32); /* extern */ -f32 coss(s32); /* extern */ +void func_802B5A44(Mat4 arg0, s16 arg1) { + f32 temp_f0 = sins(arg1); + f32 sp28 = coss(arg1); -void func_802B5A44(void *arg0, s32 arg1) { - f32 sp2C; - f32 sp28; - s32 sp24; - f32 temp_f0; - s32 temp_a0; - - temp_a0 = arg1 & 0xFFFF; - sp24 = temp_a0; - temp_f0 = sins(temp_a0); - sp2C = temp_f0; - sp28 = coss(temp_a0); mtxf_identity(arg0); - arg0->unk20 = temp_f0; - arg0->unk8 = -temp_f0; - arg0->unk0 = sp28; - arg0->unk28 = sp28; + arg0[0][0] = sp28; + arg0[0][2] = -temp_f0; + arg0[2][0] = temp_f0; + arg0[2][2] = sp28; } -#else -GLOBAL_ASM("asm/non_matchings/math_util/func_802B5A44.s") -#endif -#ifdef MIPS_TO_C -//generated by mips_to_c commit bd0364fa19633bd6201f8007e2d0a7ed87825909 -//This function did not have a glabel in the original assembly, as such it may -//be unused/unnamed -? mtxf_identity(void *); /* extern */ -f32 sins(s32); /* extern */ -f32 coss(s32); /* extern */ +void func_802B5AAC(Mat4 arg0, s16 arg1) { + f32 temp_f0 = sins(arg1); + f32 sp28 = coss(arg1); -void func_802B5AAC(void *arg0, s32 arg1) { - f32 sp2C; - f32 sp28; - s32 sp24; - f32 temp_f0; - s32 temp_a0; - - temp_a0 = arg1 & 0xFFFF; - sp24 = temp_a0; - temp_f0 = sins(temp_a0); - sp2C = temp_f0; - sp28 = coss(temp_a0); mtxf_identity(arg0); - arg0->unk4 = temp_f0; - arg0->unk10 = -temp_f0; - arg0->unk0 = sp28; - arg0->unk14 = sp28; + arg0[0][0] = sp28; + arg0[0][1] = temp_f0; + arg0[1][0] = -temp_f0; + arg0[1][1] = sp28; } -#else -GLOBAL_ASM("asm/non_matchings/math_util/func_802B5AAC.s") -#endif #ifdef MIPS_TO_C //generated by mips_to_c commit bd0364fa19633bd6201f8007e2d0a7ed87825909 -f32 sins(u16); /* extern */ -f32 coss(u16); /* extern */ +//f32 sins(u16); /* extern */ +//f32 coss(u16); /* extern */ -void func_802B5B14(void *arg0, void *arg1) { +void func_802B5B14(Vec3f arg0, Vec3s arg1) { f32 sp70; f32 sp6C; f32 sp68; @@ -521,31 +386,35 @@ void func_802B5B14(void *arg0, void *arg1) { f32 sp48; f32 sp40; f32 sp3C; - f32 sp38; - f32 sp30; - f32 sp2C; - f32 sp28; - f32 temp_f0; + f32 sp38 = sins(arg1[0]); + f32 sp30 = sins(arg1[1]); + f32 sp2C = coss(arg1[1]); + f32 sp28 = sins(arg1[2]); + f32 temp_f0 = coss(arg1[2]); + f32 temp_f20 = coss(arg1[0]); f32 temp_f10; - f32 temp_f12; + //f32 temp_f12; f32 temp_f18; - f32 temp_f20; f32 temp_f4; f32 temp_f6; - sp38 = sins(arg1->unk0); - temp_f20 = coss(arg1->unk0); - sp30 = sins(arg1->unk2); - sp2C = coss(arg1->unk2); - sp28 = sins(arg1->unk4); - temp_f0 = coss(arg1->unk4); - temp_f4 = arg0->unk0; - temp_f12 = sp38 * sp30; - sp3C = temp_f4; - sp40 = arg0->unk4; - temp_f6 = (sp2C * temp_f0) + (temp_f12 * sp28); + //sp38 = sins(arg1->unk0); + //temp_f20 = coss(arg1->unk0); + //sp30 = sins(arg1->unk2); + //sp2C = coss(arg1->unk2); + //sp28 = sins(arg1->unk4); + //temp_f0 = coss(arg1->unk4); + //temp_f4 = arg0[0]; + //temp_f12 = sp38 * sp30; + //sp3C = temp_f4; + + sp3C = arg0[0]; + sp40 = arg0[1]; + + + temp_f6 = (sp2C * temp_f0) + (sp38 * sp30 * sp28); sp48 = temp_f6; - sp58 = (-sp2C * sp28) + (temp_f12 * temp_f0); + sp58 = (-sp2C * sp28) + (sp38 * sp30 * temp_f0); sp68 = temp_f20 * sp30; sp4C = temp_f20 * sp28; temp_f18 = sp38 * sp2C; @@ -555,54 +424,28 @@ void func_802B5B14(void *arg0, void *arg1) { sp50 = temp_f10; sp60 = (sp30 * sp28) + (temp_f18 * temp_f0); sp70 = temp_f20 * sp2C; - arg0->unk0 = (temp_f10 * sp40) + ((temp_f4 * temp_f6) + (sp40 * sp4C)); - arg0->unk4 = (sp60 * sp40) + ((temp_f4 * sp58) + (sp40 * sp5C)); - arg0->unk8 = (sp70 * sp40) + ((sp3C * sp68) + (sp40 * sp6C)); + arg0[0] = (temp_f10 * sp40) + ((sp3C * temp_f6) + (sp40 * sp4C)); + arg0[1] = (sp60 * sp40) + ((sp3C * sp58) + (sp40 * sp5C)); + arg0[2] = (sp70 * sp40) + ((sp3C * sp68) + (sp40 * sp6C)); } #else GLOBAL_ASM("asm/non_matchings/math_util/func_802B5B14.s") #endif -#ifdef MIPS_TO_C -//generated by mips_to_c commit bd0364fa19633bd6201f8007e2d0a7ed87825909 -f32 sins(s32); /* extern */ -f32 coss(s32); /* extern */ - -void func_802B5CAC(u16 arg0, s32 arg1, void *arg2) { - f32 sp2C; - f32 sp28; - f32 sp24; - s32 sp1C; - f32 temp_f10; - s32 temp_a0; +void func_802B5CAC(s16 arg0, s16 arg1, Vec3f arg2) { + f32 sp2C = sins(arg1); + f32 sp28 = coss(arg1); + f32 sp24 = sins(arg0); + f32 temp_f10 = coss(arg0); - temp_a0 = arg1 & 0xFFFF; - sp1C = temp_a0; - sp2C = sins(temp_a0); - sp28 = coss(temp_a0); - sp1C = arg0; - sp24 = sins(arg0); - temp_f10 = sp28 * coss(arg0); - arg2->unk0 = sp28 * sp24; - arg2->unk4 = sp2C; - arg2->unk8 = -temp_f10; + arg2[0] = sp28 * sp24; + arg2[1] = sp2C; + arg2[2] = -(sp28 * temp_f10); } -#else -GLOBAL_ASM("asm/non_matchings/math_util/func_802B5CAC.s") -#endif -#ifdef MIPS_TO_C -//generated by mips_to_c commit bd0364fa19633bd6201f8007e2d0a7ed87825909 -//This function did not have a glabel in the original assembly, as such it may -//be unused/unnamed -? func_802B5D64(?, s16, s16, ?); /* extern */ - -void func_802B5D30(s16 arg0, s16 arg1, ? arg2) { +void func_802B5D30(s16 arg0, s16 arg1, s32 arg2) { func_802B5D64(0x9000000, arg0, arg1, arg2); } -#else -GLOBAL_ASM("asm/non_matchings/math_util/func_802B5D30.s") -#endif #ifdef MIPS_TO_C //generated by mips_to_c commit bd0364fa19633bd6201f8007e2d0a7ed87825909 @@ -844,118 +687,60 @@ void func_802B6214(void *arg0, void *arg1, void *arg2) { GLOBAL_ASM("asm/non_matchings/math_util/func_802B6214.s") #endif -#ifdef MIPS_TO_C -//generated by mips_to_c commit bd0364fa19633bd6201f8007e2d0a7ed87825909 -//This function did not have a glabel in the original assembly, as such it may -//be unused/unnamed -void func_802B6374(void *arg0) { +UNUSED void func_802B6374(Vec3f arg0) { f32 temp_f0; - f32 temp_f12; - f32 temp_f14; - f32 temp_f18; - f32 temp_f2; - - temp_f12 = arg0->unk0; - temp_f14 = arg0->unk4; - temp_f2 = arg0->unk8; - temp_f0 = sqrtf((temp_f2 * temp_f2) + ((temp_f12 * temp_f12) + (temp_f14 * temp_f14))); - temp_f18 = temp_f14 / temp_f0; - arg0->unk0 = temp_f12 / temp_f0; - arg0->unk4 = temp_f18; - arg0->unk8 = temp_f2 / temp_f0; + temp_f0 = sqrtf((arg0[0] * arg0[0]) + (arg0[1] * arg0[1]) + (arg0[2] * arg0[2])); + arg0[0] /= temp_f0; + arg0[1] /= temp_f0; + arg0[2] /= temp_f0; } -#else -GLOBAL_ASM("asm/non_matchings/math_util/func_802B6374.s") -#endif -#ifdef MIPS_TO_C -//generated by mips_to_c commit bd0364fa19633bd6201f8007e2d0a7ed87825909 -void func_802B63B8(void *arg0, void *arg1) { +void func_802B63B8(Vec3f arg0, Mat3 arg1) { f32 temp_f12; - f32 temp_f14; f32 temp_f16; - f32 temp_f2; - f32 temp_f6; + f32 temp_f14; - temp_f12 = arg0->unk0; - temp_f14 = arg0->unk4; - temp_f2 = arg0->unk8; - temp_f6 = arg1->unk18 * temp_f12; - temp_f16 = (temp_f2 * arg1->unk14) + ((arg1->unkC * temp_f12) + (arg1->unk10 * temp_f14)); - arg0->unk0 = (temp_f2 * arg1->unk8) + ((arg1->unk0 * temp_f12) + (arg1->unk4 * temp_f14)); - arg0->unk4 = temp_f16; - arg0->unk8 = (temp_f2 * arg1->unk20) + (temp_f6 + (arg1->unk1C * temp_f14)); + temp_f12 = (arg1[0][0] * arg0[0]) + (arg1[0][1] * arg0[1]) + (arg1[0][2] * arg0[2]); + temp_f16 = (arg1[1][0] * arg0[0]) + (arg1[1][1] * arg0[1]) + (arg1[1][2] * arg0[2]); + temp_f14 = (arg1[2][0] * arg0[0]) + (arg1[2][1] * arg0[1]) + (arg1[2][2] * arg0[2]); + + arg0[0] = temp_f12; + arg0[1] = temp_f16; + arg0[2] = temp_f14; } -#else -GLOBAL_ASM("asm/non_matchings/math_util/func_802B63B8.s") -#endif -#ifdef MIPS_TO_C -//generated by mips_to_c commit bd0364fa19633bd6201f8007e2d0a7ed87825909 -void func_802B6434(void *arg0, void *arg1) { - f32 temp_f12; - f32 temp_f14; - f32 temp_f16; +void func_802B6434(Vec3f arg0, Mat4 arg1) { + f32 temp_f2; + f32 temp_f16; f32 temp_f6; - temp_f12 = arg0->unk0; - temp_f14 = arg0->unk4; - temp_f2 = arg0->unk8; - temp_f6 = arg1->unk20 * temp_f12; - temp_f16 = (temp_f2 * arg1->unk18) + ((arg1->unk10 * temp_f12) + (arg1->unk14 * temp_f14)); - arg0->unk0 = (temp_f2 * arg1->unk8) + ((arg1->unk0 * temp_f12) + (arg1->unk4 * temp_f14)); - arg0->unk4 = temp_f16; - arg0->unk8 = (temp_f2 * arg1->unk28) + (temp_f6 + (arg1->unk24 * temp_f14)); + temp_f2 = ((arg1[0][0] * arg0[0]) + (arg1[0][1] * arg0[1]) + (arg1[0][2] * arg0[2])); + temp_f16 = ((arg1[1][0] * arg0[0]) + (arg1[1][1] * arg0[1]) + (arg1[1][2] * arg0[2])); + temp_f6 = (arg1[2][0] * arg0[0]) + (arg1[2][1] * arg0[1]) + (arg1[2][2] * arg0[2]); + + + arg0[0] = temp_f2; + arg0[1] = temp_f16; + arg0[2] = temp_f6; } -#else -GLOBAL_ASM("asm/non_matchings/math_util/func_802B6434.s") -#endif -#ifdef MIPS_TO_C -//generated by mips_to_c commit bd0364fa19633bd6201f8007e2d0a7ed87825909 -//This function did not have a glabel in the original assembly, as such it may -//be unused/unnamed -void func_802B64B0(s32 arg0, ? arg1, ? arg2, ? arg3) { +UNUSED void func_802B64B0(s32 arg0, s32 arg1, s32 arg2, s32 arg3) { } -#else -GLOBAL_ASM("asm/non_matchings/math_util/func_802B64B0.s") -#endif -#ifdef MIPS_TO_C -//generated by mips_to_c commit bd0364fa19633bd6201f8007e2d0a7ed87825909 -f32 sins(s32, void *); /* extern */ -f32 coss(s32); /* extern */ +void func_802B64C4(Vec3f arg0, s16 arg1) { + f32 sp2C = sins(arg1); + f32 temp_f0 = coss(arg1); -void func_802B64C4(void *arg0, s32 arg1) { - f32 sp2C; - s32 sp18; - f32 temp_f0; - f32 temp_f10; - f32 temp_f12; - f32 temp_f2; - f32 temp_f4; - s32 temp_a0; - void *temp_a2; + f32 temp1 = arg0[0]; + f32 temp2 = arg0[1]; + f32 temp3 = arg0[2]; - temp_a2 = arg0; - temp_a0 = arg1 & 0xFFFF; - sp18 = temp_a0; - arg0 = temp_a2; - sp2C = sins(temp_a0, temp_a2); - temp_f0 = coss(temp_a0); - temp_f2 = arg0->unk0; - temp_f12 = arg0->unk8; - temp_f4 = temp_f0 * temp_f2; - arg0->unk4 = arg0->unk4; - temp_f10 = sp2C * temp_f2; - arg0->unk0 = temp_f4 - (sp2C * temp_f12); - arg0->unk8 = temp_f10 + (temp_f0 * temp_f12); + arg0[0] = temp_f0 * temp1 - (sp2C * temp3); + arg0[1] = temp2; + arg0[2] = sp2C * temp1 + (temp_f0 * temp3); } -#else -GLOBAL_ASM("asm/non_matchings/math_util/func_802B64C4.s") -#endif #ifdef MIPS_TO_C //generated by mips_to_c commit bd0364fa19633bd6201f8007e2d0a7ed87825909 @@ -1635,39 +1420,19 @@ s16 func_802B7F34(f32 arg0, f32 arg1, f32 arg2, f32 arg3) { return atan2s(arg2 - arg0, arg3 - arg1); } -#ifdef MIPS_TO_C -//generated by mips_to_c commit bd0364fa19633bd6201f8007e2d0a7ed87825909 -s16 func_802B7F34(f32, f32, ?32, ?32); /* extern */ +void func_802B7F7C(Vec3f arg0, Vec3f arg1, Vec3s arg2) { + f32 temp_f14 = arg0[0]; + f32 sp28 = arg0[1]; + f32 temp_f12 = arg0[2]; -void func_802B7F7C(void *arg0, void *arg1, void *arg2) { - f32 sp2C; - f32 sp28; - f32 sp24; - ?32 sp20; - ?32 sp1C; - ?32 sp18; - ?32 temp_f0; - ?32 temp_f2; - f32 temp_f12; - f32 temp_f14; + f32 temp_f2 = arg1[0]; + f32 sp1C = arg1[1]; + f32 temp_f0 = arg1[2]; - temp_f14 = arg0->unk0; - sp28 = arg0->unk4; - temp_f12 = arg0->unk8; - temp_f2 = arg1->unk0; - sp1C = arg1->unk4; - temp_f0 = arg1->unk8; - sp2C = temp_f14; - sp24 = temp_f12; - sp20 = temp_f2; - sp18 = temp_f0; - arg2->unk2 = func_802B7F34(temp_f12, temp_f14, temp_f0, temp_f2); - arg2->unk0 = func_802B7F34(sp28, sp24, sp1C, temp_f0); - arg2->unk4 = func_802B7F34(sp2C, sp28, sp20, sp1C); + arg2[1] = func_802B7F34(temp_f12, temp_f14, temp_f0, temp_f2); + arg2[0] = func_802B7F34(sp28, temp_f12, sp1C, temp_f0); + arg2[2] = func_802B7F34(temp_f14, sp28, temp_f2, sp1C); } -#else -GLOBAL_ASM("asm/non_matchings/math_util/func_802B7F7C.s") -#endif f32 sins(u16 arg0) { return gSineTable[arg0 >> 4]; @@ -1677,34 +1442,21 @@ f32 coss(u16 arg0) { return gCosineTable[arg0 >> 4]; } -#ifdef MIPS_TO_C -//generated by mips_to_c commit bd0364fa19633bd6201f8007e2d0a7ed87825909 -? func_802B8058(s32 arg0, s32 arg1, s32 arg2) { - s32 temp_t7; - s32 temp_t8; - s32 temp_v1; - - temp_v1 = arg0 & 0xFFFF; - temp_t7 = arg1 & 0xFFFF; - temp_t8 = arg2 & 0xFFFF; - if (temp_t7 < temp_v1) { - if (temp_t7 >= temp_t8) { +s32 func_802B8058(u16 arg0, u16 arg1, u16 arg2) { + if (arg1 < arg0) { + if (arg1 >= arg2) { return 0; } - if (temp_t8 >= temp_v1) { + if (arg2 >= arg0) { + return 0; + } + } else { + if ((arg1 >= arg2) && (arg2 >= arg0)) { return 0; } - /* Duplicate return node #8. Try simplifying control flow for better match */ - return 1; - } - if ((temp_t7 >= temp_t8) && (temp_t8 >= temp_v1)) { - return 0; } return 1; } -#else -GLOBAL_ASM("asm/non_matchings/math_util/func_802B8058.s") -#endif #ifdef MIPS_TO_C //generated by mips_to_c commit bd0364fa19633bd6201f8007e2d0a7ed87825909 diff --git a/src/math_util.h b/src/math_util.h index 76d78eeb4..58009f8b8 100644 --- a/src/math_util.h +++ b/src/math_util.h @@ -24,15 +24,15 @@ void *vec3f_copy(Vec3f, Vec3f); void vec3s_copy(Vec3s, Vec3s); void *sm64_vec3f_set(Vec3f, f32, f32, f32); void mtxf_identity(Mat4); -void func_802B5398(Mat4, Mat4, s32); +//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_802B59DC(Mat4, s32); +void func_802B59DC(Mat4, s16); void func_802B5F74(Mat4, Vec3f, Vec3s); f32 func_802B80D0(Vec3f, Vec3f, u16, f32, f32, f32); void func_802B5F00(Mat4, f32); -void func_802B63B8(Vec3f, f32*); +void func_802B63B8(Vec3f, Mat3); void func_802B64C4(Vec3f, s16); void func_802B71CC(Mat4, Mat4, Mat4); void func_802B75F8(Mtx*, Mat4); |
