diff options
| author | ChiefFruitcake <96551211+ChiefFruitcake@users.noreply.github.com> | 2021-12-31 18:06:28 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-31 16:06:28 -0700 |
| commit | f250fb6e451ed32b0d6b8febdd3587d245675787 (patch) | |
| tree | a6a8df8398d605319928d663b9d582d26f485b2d /src/code_800AF9B0.c | |
| parent | 494c36bdb15bae2aeb618ad4d2fb85fa7b570627 (diff) | |
First decompile attempt. code_800AF9B0 (#121)
* Decompile a couple code_800AF9B0 functions
* Match func_800B34E8, func_800B44AC, and func_800B45E0
* Use sizeof in func_800B45E0 instead of hard-coded numbers
* Match func_800B4520. Separate unused function func_800B4560 into new asm file
* Match func_800B5B2C and func_800B6A68. Create new unused func_800B6AF8
* Match func_800B4874 and func_800B4A10
* Improve matched functions reading time trial records
* Match func_800B13B0. Name variables related to data menu
* Match func_800B3B58. Remove warnings due to pointer type in osEepromLongWrite calls
* Rename gStartMenuCounterForDemos to gMenuTimingCounter
* Match func_800B5F30
Diffstat (limited to 'src/code_800AF9B0.c')
| -rw-r--r-- | src/code_800AF9B0.c | 746 |
1 files changed, 314 insertions, 432 deletions
diff --git a/src/code_800AF9B0.c b/src/code_800AF9B0.c index 9c622cfc9..30426a6b7 100644 --- a/src/code_800AF9B0.c +++ b/src/code_800AF9B0.c @@ -1,13 +1,67 @@ #include <ultra64.h> #include <macros.h> #include <defines.h> +#include <PR/os.h> +#include <types.h> #include "global.h" #include "common_structs.h" -u32 func_802A7B70(u16 x); -extern u32 D_8018EDB8; -extern u32 D_8018EDBC; -extern SaveData D_8018EB90; +void func_8009E1C0(); +void func_8009E208(); +void func_8009E258(); +void func_800B44AC(void); +void func_800B44BC(void); +s32 func_800B4520(void); +void func_800B4670(void); +void func_800B4728(s32 arg0); +void func_800B4820(void); +s32 func_800B492C(void); +s32 func_800B49E4(void); +void func_800B559C(s32 arg0); +void func_800B5948(void); +void play_sound2(s32); +void func_800CA330(s32); +u32 func_802A7B70(u16 x); + +extern u16 gEnableDebugMode; // D_800DC520 +extern s32 gModeSelection; // D_800DC53C +extern s32 D_800DC540; +extern s16 gCurrentCourseId; // D_800DC5A0 +extern u16 D_800E86F0; +extern s32 D_800E86F4; +extern s8 D_800E86F8; +extern s8 D_800E86FC; +extern s16 gCupCourseOrder[NUM_CUPS][NUM_COURSES_PER_CUP]; // D_800F2BB4 +extern u8 D_800F2E64; +extern u8 D_800F2E74; +extern OSMesgQueue gSIEventMesgQueue; // D_8014F0B8 +extern s32 D_8018E7A8; +extern s8 D_8018E7B0; +extern OSPfs D_8018E868; +extern OSPfs D_8018E8D0; +extern s32 D_8018EB78; +extern s32 D_8018EB7C; +extern s32 D_8018EB84; +extern SaveData D_8018EB90; +extern u8 D_8018ED10[4]; // Direct reference to the grandPrixPoints section of save data +extern u8 D_8018ED11; +extern u8 D_8018ED12; +extern u8 D_8018ED13; +extern s8 D_8018ED16; +extern s8 D_8018ED17; +extern u32 D_8018EDB8; +extern u32 D_8018EDBC; +extern s8 gCharacterSelections; // D_8018EDE4 +extern s8 D_8018EDE5; +extern s8 D_8018EDE6; +extern s8 D_8018EDE7; +extern s8 D_8018EDEC; +extern s8 gTimeTrialDataCourseIndex; // D_8018EDF7 +extern s8 gCourseRecordsMenuSelection; // D_8018EDF8 +extern s32 gMenuTimingCounter; // D_8018EE00 +extern s8 gCupSelection; // D_8018EE09 +extern s8 D_8018EE0A; +extern s8 gCupCourseSelection; // D_8018EE0B void func_800AF9B0(void) { D_8018EDB8 = func_802A7B70(7680); @@ -1049,93 +1103,66 @@ void func_800B053C(void *arg0, u16 arg1) { GLOBAL_ASM("asm/non_matchings/code_800AF9B0/func_800B053C.s") #endif -#ifdef MIPS_TO_C -//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307 -? func_8009E1C0(); // extern -? func_8009E258(); // extern -s32 func_800B4520(u16); // extern -? play_sound2(?, s8 *); // extern -extern s8 D_8018EDEC; -extern s8 gTimeTrialDataCourseIndex; -extern s8 D_8018EDF8; - -void func_800B13B0(void *arg0, ? arg1) { - u16 sp1E; - s32 sp18; - s8 temp_v0; - s8 temp_v0_2; - s8 temp_v0_3; - s8 temp_v0_4; - u16 temp_t8; - u16 phi_a1; - s8 *phi_a1_2; - - temp_t8 = (arg0->unk6 | arg0->unkC) & 0xFFFF; - phi_a1 = temp_t8; - if ((gEnableDebugMode == 0) && ((temp_t8 & 0x1000) != 0)) { - phi_a1 = (temp_t8 | 0x8000) & 0xFFFF; +// Handle navigating the data menu interface +void func_800B13B0(struct Controller *controller, s32 arg1) { + u16 buttonAndStickPress = (controller->buttonPressed | controller->stickPressed); + + // Make pressing Start have the same effect as pressing A + if ((gEnableDebugMode == 0) && ((buttonAndStickPress & 0x1000) != 0)) { + buttonAndStickPress |= 0x8000; } - sp1E = phi_a1; - if (func_800B4520(phi_a1) == 0) { + + if (func_800B4520() == 0) { if (D_8018EDEC == 1) { - if ((phi_a1 & 0x400) != 0) { - temp_v0 = gTimeTrialDataCourseIndex; - if ((temp_v0 % 4) != 3) { - gTimeTrialDataCourseIndex = temp_v0 + 1; - sp18 = phi_a1; - play_sound2(0x49008000, &gTimeTrialDataCourseIndex); + // If DPad/Stick down pressed, move selection down if not already in bottom row + if ((buttonAndStickPress & 0x400) != 0) { + if ((gTimeTrialDataCourseIndex % 4) != 3) { + ++gTimeTrialDataCourseIndex; + play_sound2(0x49008000); } } - if ((phi_a1 & 0x800) != 0) { - temp_v0_2 = gTimeTrialDataCourseIndex; - if ((temp_v0_2 & 3) != 0) { - gTimeTrialDataCourseIndex = temp_v0_2 - 1; - sp18 = phi_a1; - play_sound2(0x49008000, &gTimeTrialDataCourseIndex); + // If DPad/Stick up pressed, move selection up if not already in top row + if ((buttonAndStickPress & 0x800) != 0) { + if ((gTimeTrialDataCourseIndex & 3) != 0) { + --gTimeTrialDataCourseIndex; + play_sound2(0x49008000); } } - phi_a1_2 = &gTimeTrialDataCourseIndex; - if ((phi_a1 & 0x100) != 0) { - temp_v0_3 = gTimeTrialDataCourseIndex; - if ((temp_v0_3 / 4) != 3) { - gTimeTrialDataCourseIndex = temp_v0_3 + 4; - sp18 = phi_a1; - play_sound2(0x49008000, &gTimeTrialDataCourseIndex); - phi_a1_2 = &gTimeTrialDataCourseIndex; + // If DPad/Stick right pressed, move selection right if not already in right-most column + if ((buttonAndStickPress & 0x100) != 0) { + if ((gTimeTrialDataCourseIndex / 4) != 3) { + gTimeTrialDataCourseIndex += 4; + play_sound2(0x49008000); } } - if ((phi_a1 & 0x200) != 0) { - temp_v0_4 = *phi_a1_2; - if ((temp_v0_4 / 4) != 0) { - *phi_a1_2 = temp_v0_4 - 4; - sp18 = phi_a1; - play_sound2(0x49008000, phi_a1_2); + // If DPad/Stick left pressed, move selection left if not already in left-most column + if ((buttonAndStickPress & 0x200) != 0) { + if ((gTimeTrialDataCourseIndex / 4) != 0) { + gTimeTrialDataCourseIndex -= 4; + play_sound2(0x49008000); } } - if ((phi_a1 & 0x4000) != 0) { + // If B pressed, go to main menu + if ((buttonAndStickPress & 0x4000) != 0) { func_8009E258(); play_sound2(0x49008002); return; } - if ((phi_a1 & 0x8000) != 0) { - D_8018EDF8 = 0; + // If A pressed, go to selected course's records + if ((buttonAndStickPress & 0x8000) != 0) { + gCourseRecordsMenuSelection = 0; func_8009E1C0(); play_sound2(0x49008016); - return; } - // Duplicate return node #23. Try simplifying control flow for better match - return; - } - if ((phi_a1 & 0x8000) != 0) { + } + // If D_8018EDEC != 1 and A pressed, go to main menu + // (Will D_8018EDEC ever not equal 1 when entering the data menu?) + else if ((buttonAndStickPress & 0x8000) != 0) { func_8009E258(); play_sound2(0x49008016); } - // Duplicate return node #23. Try simplifying control flow for better match } } -#else -GLOBAL_ASM("asm/non_matchings/code_800AF9B0/func_800B13B0.s") -#endif #ifdef MIPS_TO_C //generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307 @@ -1155,7 +1182,7 @@ extern f64 D_800F2DB0; extern ? D_8018EB90; extern s8 D_8018EDEC; extern s8 gTimeTrialDataCourseIndex; -extern s8 D_8018EDF8; +extern s8 gCourseRecordsMenuSelection; extern s8 D_8018EDF9; void func_800B15AC(void *arg0, ? arg1) { @@ -1251,7 +1278,7 @@ void func_800B15AC(void *arg0, ? arg1) { } if ((sp18 & 0x8000) != 0) { if (D_8018EDF9 != 0) { - temp_v0_4 = D_8018EDF8; + temp_v0_4 = gCourseRecordsMenuSelection; phi_a1 = 0; if (temp_v0_4 != 1) { if (temp_v0_4 != 2) { @@ -1298,7 +1325,7 @@ void func_800B15AC(void *arg0, ? arg1) { phi_a3 = phi_v1; if ((phi_v1 & 0x200) != 0) { temp_a1_2 = gTimeTrialDataCourseIndex; - if (temp_a1_2 > TIME_TRIAL_DATA_LUIGI_RACEWAY) { + if (temp_a1_2 > 0) { gTimeTrialDataCourseIndex = temp_a1_2 - 1; sp18 = phi_v1; play_sound2(0x49008000, temp_a1_2); @@ -1307,7 +1334,7 @@ void func_800B15AC(void *arg0, ? arg1) { } if ((phi_a3 & 0x100) != 0) { temp_a1_3 = gTimeTrialDataCourseIndex; - if (temp_a1_3 < TIME_TRIAL_DATA_RAINBOW_ROAD) { + if (temp_a1_3 < 0xF) { gTimeTrialDataCourseIndex = temp_a1_3 + 1; sp18 = phi_a3; play_sound2(0x49008000, temp_a1_3); @@ -1317,33 +1344,33 @@ void func_800B15AC(void *arg0, ? arg1) { temp_a1_4 = gTimeTrialDataCourseIndex; temp_a2_2 = func_800AAEF4(0xE8); temp_t4 = ((temp_a1_4 / 4) * 0x60) + ((temp_a1_4 % 4) * 0x18); - if (D_8018EDF8 == 2) { + if (gCourseRecordsMenuSelection == 2) { sp28 = temp_a2_2; sp18 = phi_a3; sp24 = temp_t4 + &D_8018EB90; if (func_800B639C(temp_a1_4, temp_a1_4, temp_a2_2, phi_a3) < 0) { - D_8018EDF8 = D_8018EDF8 - 1; + gCourseRecordsMenuSelection = gCourseRecordsMenuSelection - 1; } } - temp_v0_6 = D_8018EDF8; - phi_v1_2 = &D_8018EDF8; + temp_v0_6 = gCourseRecordsMenuSelection; + phi_v1_2 = &gCourseRecordsMenuSelection; if ((temp_v0_6 == 1) && ((temp_t4 + &D_8018EB90)->unk12 == 0)) { - D_8018EDF8 = temp_v0_6 - 1; + gCourseRecordsMenuSelection = temp_v0_6 - 1; } if ((phi_a3 & 0x800) != 0) { - temp_v0_7 = D_8018EDF8; + temp_v0_7 = gCourseRecordsMenuSelection; if (temp_v0_7 > 0) { - D_8018EDF8 = temp_v0_7 - 1; - temp_v0_8 = D_8018EDF8; + gCourseRecordsMenuSelection = temp_v0_7 - 1; + temp_v0_8 = gCourseRecordsMenuSelection; if ((temp_v0_8 == 1) && ((temp_t4 + &D_8018EB90)->unk12 == 0)) { - D_8018EDF8 = temp_v0_8 - 1; + gCourseRecordsMenuSelection = temp_v0_8 - 1; } sp28 = temp_a2_2; sp18 = phi_a3; sp24 = temp_t4 + &D_8018EB90; play_sound2(0x49008000); temp_f0_3 = temp_a2_2->unk24; - phi_v1_2 = &D_8018EDF8; + phi_v1_2 = &gCourseRecordsMenuSelection; if (temp_f0_3 < D_800F2D90) { temp_a2_2->unk24 = temp_f0_3 + 4.0; } @@ -1361,11 +1388,11 @@ void func_800B15AC(void *arg0, ? arg1) { if ((temp_v0_10 == 1) && ((temp_t4 + &D_8018EB90)->unk12 == 0)) { *phi_v1_2 = temp_v0_10 + 1; } - if ((*phi_v1_2 == 2) && (sp28 = temp_a2_2, sp18 = phi_a3, sp24 = temp_t4 + &D_8018EB90, phi_a3_2 = phi_a3, phi_a2 = temp_a2_2, phi_v1_3 = &D_8018EDF8, (func_800B639C(gTimeTrialDataCourseIndex) < 0))) { + if ((*phi_v1_2 == 2) && (sp28 = temp_a2_2, sp18 = phi_a3, sp24 = temp_t4 + &D_8018EB90, phi_a3_2 = phi_a3, phi_a2 = temp_a2_2, phi_v1_3 = &gCourseRecordsMenuSelection, (func_800B639C(gTimeTrialDataCourseIndex) < 0))) { if ((temp_t4 + &D_8018EB90)->unk12 == 0) { - D_8018EDF8 = 0; + gCourseRecordsMenuSelection = 0; } else { - D_8018EDF8 = 1; + gCourseRecordsMenuSelection = 1; } } else { sp28 = temp_a2_2; @@ -1374,7 +1401,7 @@ void func_800B15AC(void *arg0, ? arg1) { temp_f0_4 = temp_a2_2->unk24; phi_a3_2 = phi_a3; phi_a2 = temp_a2_2; - phi_v1_3 = &D_8018EDF8; + phi_v1_3 = &gCourseRecordsMenuSelection; if (temp_f0_4 < D_800F2D98) { temp_a2_2->unk24 = temp_f0_4 + 4.0; } @@ -2169,7 +2196,7 @@ void func_800B29D8(void *arg0, u16 arg1) { } func_800B44AC(); temp_t7_2 = D_8018EDF3; - gStartMenuCounterForDemos = 0; + gMenuTimingCounter = 0; phi_v1_3 = &D_800F2B70 + ((temp_t7_2 * 0xC) + (*(&D_800E86AB + temp_t7_2) * 4)); } else { phi_v1_3 = &D_800F2B70 + ((temp_v0_4 * 0xC) + (temp_a0_3 * 4)); @@ -2178,7 +2205,7 @@ void func_800B29D8(void *arg0, u16 arg1) { break; case 5: case 8: - if ((arg1 == 0) && ((temp_t7_3 = gStartMenuCounterForDemos + 1, gStartMenuCounterForDemos = temp_t7_3, (temp_t7_3 == 0x64)) || ((temp_t7_3 % 300) == 0)) && ((temp_v0_5 = D_8018EDF3, temp_v1_4 = *(&D_800F2B70 + ((temp_v0_5 * 0xC) + (*(&D_800E86AB + temp_v0_5) * 4))), (temp_v1_4 == 0)) || (temp_v1_4 == 2))) { + if ((arg1 == 0) && ((temp_t7_3 = gMenuTimingCounter + 1, gMenuTimingCounter = temp_t7_3, (temp_t7_3 == 0x64)) || ((temp_t7_3 % 300) == 0)) && ((temp_v0_5 = D_8018EDF3, temp_v1_4 = *(&D_800F2B70 + ((temp_v0_5 * 0xC) + (*(&D_800E86AB + temp_v0_5) * 4))), (temp_v1_4 == 0)) || (temp_v1_4 == 2))) { sp1C = phi_v1; play_sound2(0x4900900E, arg1, phi_v1); } @@ -2248,7 +2275,7 @@ block_64: } else { D_8018EDED = 6; play_sound2(0x49008001, temp_a1); - gStartMenuCounterForDemos = 0; + gMenuTimingCounter = 0; } temp_t7_4 = D_8018EDF3; phi_v1_3 = &D_800F2B70 + ((temp_t7_4 * 0xC) + (*(&D_800E86AB + temp_t7_4) * 4)); @@ -2258,7 +2285,7 @@ block_64: break; case 6: case 7: - if ((arg1 == 0) && ((temp_t7_5 = gStartMenuCounterForDemos + 1, gStartMenuCounterForDemos = temp_t7_5, (temp_t7_5 == 0x3C)) || ((temp_t7_5 % 300) == 0))) { + if ((arg1 == 0) && ((temp_t7_5 = gMenuTimingCounter + 1, gMenuTimingCounter = temp_t7_5, (temp_t7_5 == 0x3C)) || ((temp_t7_5 % 300) == 0))) { sp1C = phi_v1; play_sound2(0x4900900F, arg1, phi_v1); } @@ -2276,7 +2303,7 @@ block_64: func_800B44AC(); play_sound2(0x49008002); temp_t7_6 = D_8018EDF3; - gStartMenuCounterForDemos = 0; + gMenuTimingCounter = 0; phi_v1_3 = &D_800F2B70 + ((temp_t7_6 * 0xC) + (*(&D_800E86AB + temp_t7_6) * 4)); } else if ((phi_v1 & 0x8000) != 0) { func_8009E1C0(); @@ -2306,14 +2333,7 @@ block_64: GLOBAL_ASM("asm/non_matchings/code_800AF9B0/func_800B29D8.s") #endif -#ifdef MIPS_TO_C -//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307 -extern s8 D_8018EDE5; -extern s8 D_8018EDE6; -extern s8 D_8018EDE7; -extern s8 gCharacterSelections; - -? func_800B34E8(s32 arg0) { +s32 func_800B34E8(s32 arg0) { if (arg0 == gCharacterSelections) { return 0; } @@ -2328,9 +2348,6 @@ extern s8 gCharacterSelections; } return 1; } -#else -GLOBAL_ASM("asm/non_matchings/code_800AF9B0/func_800B34E8.s") -#endif #ifdef MIPS_TO_C //generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307 @@ -2345,110 +2362,68 @@ to all jump sources and move the label, or add a nop to the delay slot). GLOBAL_ASM("asm/non_matchings/code_800AF9B0/func_800B3554.s") #endif -#ifdef MIPS_TO_C -//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307 -? func_8009E1C0(); // extern -? func_8009E208(); // extern -? func_800B44AC(s8 *, s8 *, u16); // extern -s32 func_800B4520(u16); // extern -? func_800CA330(?); // extern -? play_sound2(?, s8 *, u16); // extern -extern s32 D_800DC540; -extern s8 D_8018EDEC; -extern s32 gStartMenuCounterForDemos; -extern s8 D_8018EE0A; -extern s8 gCupSelection; -extern ? gCupCourseOrder; - -void func_800B3B58(void *arg0, u16 arg1) { - u16 sp26; - s32 sp1C; - s32 temp_t5; - s32 temp_v0_2; - s8 temp_v0; - s8 temp_v0_3; - s8 temp_v0_4; - s8 temp_v0_5; - s8 temp_v0_6; - u16 temp_t8; - u16 phi_a2; - s32 phi_v1; - s8 phi_v0; - s8 *phi_a1; - s32 phi_v1_2; - s32 phi_v0_2; - s8 *phi_a1_2; +// Handle navigating the course menu interface +void func_800B3B58(struct Controller *arg0, u16 arg1) { + u16 buttonAndStickPress = (arg0->buttonPressed | arg0->stickPressed); - temp_t8 = (arg0->unk6 | arg0->unkC) & 0xFFFF; - phi_a2 = temp_t8; - if ((gEnableDebugMode == 0) && ((temp_t8 & 0x1000) != 0)) { - phi_a2 = (temp_t8 | 0x8000) & 0xFFFF; + if ((gEnableDebugMode == 0) && ((buttonAndStickPress & 0x1000) != 0)) { + buttonAndStickPress |= 0x8000; } - sp26 = phi_a2; - if (func_800B4520(phi_a2) == 0) { - temp_v0 = D_8018EDEC; - if (temp_v0 != 1) { - if (temp_v0 != 2) { - if (temp_v0 != 3) { - if (temp_v0 != 4) { - return; - } - goto block_22; - } - if ((arg1 == 0) && ((temp_t5 = gStartMenuCounterForDemos + 1, gStartMenuCounterForDemos = temp_t5, (temp_t5 == 0x3C)) || ((temp_t5 % 0x12C) == 0))) { - sp1C = phi_a2; - play_sound2(0x4900900F, &D_8018EDEC, phi_a2); - } - if ((phi_a2 & 0x4000) != 0) { - temp_v0_2 = gModeSelection; - if (temp_v0_2 != GRAND_PRIX) { - if (temp_v0_2 != BATTLE) { - D_8018EDEC = 2; - } else { - D_8018EDEC = 4; - } - } else { - D_8018EDEC = 1; - } + + if (func_800B4520() == 0) { + switch (D_8018EDEC) { + case 1: + if ((buttonAndStickPress & 0x100) != 0) { + if (gCupSelection < SPECIAL_CUP) { + D_8018EE0A = gCupSelection; + ++gCupSelection; func_800B44AC(); - play_sound2(0x49008002); - return; + play_sound2(0x49008000); } - if ((phi_a2 & 0x8000) != 0) { - func_8009E1C0(); - func_800CA330(0x19); - play_sound2(0x49008016); + } + if (((buttonAndStickPress & 0x200) != 0) && (gCupSelection > MUSHROOM_CUP)) { + D_8018EE0A = gCupSelection; + --gCupSelection; + func_800B44AC(); + play_sound2(0x49008000); + } + + D_800DC540 = gCupSelection; + gCurrentCourseId = gCupCourseOrder[gCupSelection][gCupCourseSelection]; + if ((buttonAndStickPress & 0x4000) != 0) { + func_8009E208(); + play_sound2(0x49008002); + } + else if ((buttonAndStickPress & 0x8000) != 0) { + if (gModeSelection != GRAND_PRIX) { + D_8018EDEC = 2; + play_sound2(0x49008001); + } else { + D_8018EDEC = 3; + play_sound2(0x49008001); + gCurrentCourseId = gCupCourseOrder[gCupSelection][CUP_COURSE_ONE]; + gMenuTimingCounter = 0; } - // Duplicate return node #48. Try simplifying control flow for better match - return; + func_800B44AC(); } -block_22: - phi_v1 = phi_a2; - if ((phi_a2 & 0x400) != 0) { - temp_v0_3 = gCupCourseSelection; - if (temp_v0_3 < 3) { - gCupCourseSelection = temp_v0_3 + 1; - sp1C = phi_a2; - func_800B44AC(&gCupCourseSelection, &D_8018EDEC, phi_a2); + break; + case 2: + case 4: + if (((buttonAndStickPress & 0x400) != 0) && (gCupCourseSelection < CUP_COURSE_FOUR)) { + ++gCupCourseSelection; + func_800B44AC(); play_sound2(0x49008000); - phi_v1 = sp1C; - } } - temp_v0_4 = gCupCourseSelection; - phi_v0 = temp_v0_4; - phi_a1 = &D_8018EDEC; - if (((phi_v1 & 0x800) != 0) && (temp_v0_4 > 0)) { - gCupCourseSelection = temp_v0_4 - 1; - sp1C = phi_v1; - func_800B44AC(&gCupCourseSelection, &D_8018EDEC); + if (((buttonAndStickPress & 0x800) != 0) && (gCupCourseSelection > CUP_COURSE_ONE)) { + --gCupCourseSelection; + func_800B44AC(); play_sound2(0x49008000); - phi_v0 = gCupCourseSelection; - phi_a1 = &D_8018EDEC; } - gCurrentCourseId = *(&gCupCourseOrder + ((gCupSelection * 8) + (phi_v0 * 2))); - if ((phi_v1 & 0x4000) != 0) { - if (*phi_a1 == 2) { - *phi_a1 = 1; + + gCurrentCourseId = gCupCourseOrder[gCupSelection][gCupCourseSelection]; + if ((buttonAndStickPress & 0x4000) != 0) { + if (D_8018EDEC == 2) { + D_8018EDEC = 1; } else { func_8009E208(); } @@ -2456,66 +2431,46 @@ block_22: play_sound2(0x49008002); return; } - if ((phi_v1 & 0x8000) != 0) { - *phi_a1 = 3; - play_sound2(0x49008001, phi_a1); + if ((buttonAndStickPress & 0x8000) != 0) { + D_8018EDEC = 3; + play_sound2(0x49008001); func_800B44AC(); - gStartMenuCounterForDemos = 0; - return; + gMenuTimingCounter = 0; } - // Duplicate return node #48. Try simplifying control flow for better match - return; - } - phi_v1_2 = phi_a2; - if ((phi_a2 & 0x100) != 0) { - temp_v0_5 = gCupSelection; - if (temp_v0_5 < SPECIAL_CUP) { - D_8018EE0A = temp_v0_5; - gCupSelection = temp_v0_5 + 1; - sp1C = phi_a2; + break; + case 3: + + if ((arg1 == 0) && ((++gMenuTimingCounter == 0x3C) || ((gMenuTimingCounter % 300) == 0))) { + play_sound2(0x4900900F); + } + + if ((buttonAndStickPress & 0x4000) != 0) { + switch(gModeSelection) + { + case GRAND_PRIX: + D_8018EDEC = 1; + break; + case BATTLE: + D_8018EDEC = 4; + break; + default: + D_8018EDEC = 2; + break; + } + func_800B44AC(); - play_sound2(0x49008000); - phi_v1_2 = sp1C; + play_sound2(0x49008002); + return; } - } - temp_v0_6 = gCupSelection; - phi_v0_2 = temp_v0_6; - phi_a1_2 = &D_8018EDEC; - if (((phi_v1_2 & 0x200) != 0) && (temp_v0_6 > MUSHROOM_CUP)) { - D_8018EE0A = temp_v0_6; - gCupSelection = temp_v0_6 - 1; - sp1C = phi_v1_2; - func_800B44AC(); - play_sound2(0x49008000); - phi_v0_2 = gCupSelection; - phi_a1_2 = &D_8018EDEC; - } - D_800DC540 = phi_v0_2; - gCurrentCourseId = *(&gCupCourseOrder + ((phi_v0_2 * 8) + (gCupCourseSelection * 2))); - if ((phi_v1_2 & 0x4000) != 0) { - func_8009E208(); - play_sound2(0x49008002); - return; - } - if ((phi_v1_2 & 0x8000) != 0) { - if (gModeSelection != GRAND_PRIX) { - *phi_a1_2 = 2; - play_sound2(0x49008001, phi_a1_2); - } else { - *phi_a1_2 = 3; - play_sound2(0x49008001, phi_a1_2); - gCurrentCourseId = *(&gCupCourseOrder + (gCupSelection * 8)); - gStartMenuCounterForDemos = 0; + if ((buttonAndStickPress & 0x8000) != 0) { + func_8009E1C0(); + func_800CA330(0x19); + play_sound2(0x49008016); } - func_800B44AC(); - return; + break; } - // Duplicate return node #48. Try simplifying control flow for better match } } -#else -GLOBAL_ASM("asm/non_matchings/code_800AF9B0/func_800B3B58.s") -#endif #ifdef MIPS_TO_C //generated by mips_to_c commit bd0364fa19633bd6201f8007e2d0a7ed87825909 @@ -2553,7 +2508,7 @@ extern s8 gTimeTrialDataCourseIndex; extern s8 gDebugGotoScene; extern s8 D_8018EDFB; extern s8 D_8018EDFC; -extern s32 gStartMenuCounterForDemos; +extern s32 gMenuTimingCounter; extern s32 D_8018EE04; extern s8 D_8018EE08; extern s8 D_8018EE0A; @@ -2582,7 +2537,7 @@ void func_800B3F74(u32 arg0) { s8 *phi_v0_2; gDebugMenuSelection = DEBUG_MENU_DISABLED; - gStartMenuCounterForDemos = 0; + gMenuTimingCounter = 0; D_8018EE04 = 0; D_8018EE08 = 0; D_8015F890 = 0; @@ -2787,16 +2742,9 @@ void func_800B3F74(u32 arg0) { GLOBAL_ASM("asm/non_matchings/code_800AF9B0/func_800B3F74.s") #endif -#ifdef MIPS_TO_C -//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307 -extern s32 D_8018E7A8; - void func_800B44AC(void) { D_8018E7A8 = 0x20; } -#else -GLOBAL_ASM("asm/non_matchings/code_800AF9B0/func_800B44AC.s") -#endif #ifdef MIPS_TO_C //generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307 @@ -2816,65 +2764,51 @@ void func_800B44BC(void) { GLOBAL_ASM("asm/non_matchings/code_800AF9B0/func_800B44BC.s") #endif -#ifdef MIPS_TO_C -//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307 -extern s8 D_8018E7B0; - -? func_800B4520(void) { - s8 temp_v0; +s32 func_800B4520(void) { - temp_v0 = D_8018E7B0; - if ((temp_v0 == 2) || (temp_v0 == 3) || (temp_v0 == 4) || (temp_v0 == 7)) { + if ((D_8018E7B0 == 2) || (D_8018E7B0 == 3) || (D_8018E7B0 == 4) || (D_8018E7B0 == 7)) { return 1; } return 0; } -#else -GLOBAL_ASM("asm/non_matchings/code_800AF9B0/func_800B4520.s") -#endif #ifdef MIPS_TO_C -//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307 -s8 func_800B4874(); // extern -extern ? D_8018EB90; -extern OSMesgQueue gSIEventMesgQueue; +//generated by mips_to_c commit cc33060578851a93591ed035e96ffd1f15c765f1 +? func_800CF774(? *, s32); /* extern */ +extern ? D_800F2BE8; +extern ? D_800F2BF8; +extern ? D_800F2C0C; +extern s32 D_80162DE0; +extern s32 D_8018D9C0; +extern ? D_8018EE16; -void func_800B45E0(s32 arg0) { - u8 *temp_a2; +// Separated from assembly in code_800AF9B0/func_800B4520.s +UNUSED void func_800B4560(s32 arg0, s32 arg1) { + s32 sp18; - temp_a2 = &D_8018EB90 + ((arg0 / 4) * 0x60) + ((arg0 % 4) * 0x18); - temp_a2->unk17 = func_800B4874(); - osEepromLongWrite(&gSIEventMesgQueue, ((temp_a2 - &D_8018EB90) >> 3) & 0xFF, temp_a2, 0x18); + sp18 = D_8018D9C0; + func_800CF774(&D_800F2BE8, D_80162DE0); + func_800CF774(&D_800F2BF8, (s32) *(&D_8018EE16 + (arg0 << 7))); + func_800CF774(&D_800F2C0C, (s32) ((arg1 << 7) + sp18)->unk6); } #else -GLOBAL_ASM("asm/non_matchings/code_800AF9B0/func_800B45E0.s") +GLOBAL_ASM("asm/non_matchings/code_800AF9B0/func_800B4560.s") #endif -#ifdef MIPS_TO_C -//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307 -s8 func_800B492C(); // extern -s8 func_800B49E4(); // extern -extern ? D_8018EB90; -extern u8 D_8018ED10; -extern s8 D_8018ED16; -extern s8 D_8018ED17; -extern OSMesgQueue gSIEventMesgQueue; +void func_800B45E0(s32 arg0) { + CourseTimeTrialRecords* courseTimeTrialRecordsPtr = &D_8018EB90.allCourseTimeTrialRecords \ + .cupRecords[arg0 / 4] \ + .courseRecords[arg0 % 4]; + + courseTimeTrialRecordsPtr->unknownBytes[5] = func_800B4874(); + osEepromLongWrite(&gSIEventMesgQueue, ((u32)courseTimeTrialRecordsPtr - (u32)&D_8018EB90) >> 3, (u8*) courseTimeTrialRecordsPtr, sizeof(CourseTimeTrialRecords)); +} void func_800B4670(void) { D_8018ED16 = func_800B492C(); D_8018ED17 = func_800B49E4(); - osEepromLongWrite(&gSIEventMesgQueue, ((&D_8018ED10 - &D_8018EB90) >> 3) & 0xFF, &D_8018ED10, 8); + osEepromLongWrite(&gSIEventMesgQueue, (((u32)&D_8018ED10 - (u32)&D_8018EB90) >> 3), (u8*) &D_8018ED10, 8); } -#else -GLOBAL_ASM("asm/non_matchings/code_800AF9B0/func_800B4670.s") -#endif - -#ifdef MIPS_TO_C -//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307 -? func_800B4728(s32); // extern -? func_800B4820(); // extern -? func_800B559C(s32); // extern -? func_800B5948(); // extern void func_800B46D0(void) { s32 temp_s0; @@ -2886,13 +2820,10 @@ void func_800B46D0(void) { func_800B559C(phi_s0); temp_s0 = phi_s0 + 1; phi_s0 = temp_s0; - } while (temp_s0 != 0x10); + } while (phi_s0 != 0x10); func_800B4820(); func_800B5948(); } -#else -GLOBAL_ASM("asm/non_matchings/code_800AF9B0/func_800B46D0.s") -#endif #ifdef MIPS_TO_C //generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307 @@ -2946,19 +2877,8 @@ loop_2: GLOBAL_ASM("asm/non_matchings/code_800AF9B0/func_800B4728.s") #endif -#ifdef MIPS_TO_C -//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307 -? func_800B44BC(); // extern -? func_800B4670(); // extern -extern s8 D_8018ED10; -extern s8 D_8018ED11; -extern s8 D_8018ED12; -extern s8 D_8018ED13; -extern s8 gSaveDataSoundMode; -extern s8 gSoundMode; - void func_800B4820(void) { - D_8018ED10 = 0; + D_8018ED10[0] = 0; D_8018ED11 = 0; D_8018ED12 = 0; D_8018ED13 = 0; @@ -2967,46 +2887,31 @@ void func_800B4820(void) { func_800B44BC(); func_800B4670(); } -#else -GLOBAL_ASM("asm/non_matchings/code_800AF9B0/func_800B4820.s") -#endif - -#ifdef MIPS_TO_C -//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307 -extern ? D_8018EB90; s32 func_800B4874(s32 arg0) { + s32 temp_a0; s32 temp_a1; - s32 temp_a3; s32 temp_v1; - s32 phi_a0; - s32 phi_a1; - s32 phi_v1; - s32 phi_a2; - - phi_a1 = 0; - phi_a2 = 0; - phi_v1 = 0; - do { - phi_a0 = 0; -loop_2: - temp_a3 = phi_a0 + 1; - temp_v1 = phi_v1 + (*(((arg0 / 4) * 0x60) + ((arg0 % 4) * 0x18) + &D_8018EB90 + phi_a2 + phi_a0) * temp_a3) + phi_a1; - phi_a0 = temp_a3; - phi_v1 = temp_v1; - phi_v1 = temp_v1; - if (temp_a3 != 3) { - goto loop_2; + u8* records = &D_8018EB90.allCourseTimeTrialRecords \ + .cupRecords[arg0 / 4] \ + .courseRecords[arg0 % 4] \ + .records[0][0]; + + temp_v1 = 0; + temp_a1 = 0; + while (temp_a1 < 7) + { + temp_a0 = 0; + while (temp_a0 < 3) + { + temp_v1 += (*((records + 3*temp_a1 + temp_a0)) * (temp_a0 + 1)) + temp_a1; + ++temp_a0; } - temp_a1 = phi_a1 + 1; - phi_a1 = temp_a1; - phi_a2 += 3; - } while (temp_a1 != 7); - return (temp_v1 % 0x100) & 0xFF; + ++temp_a1; + } + + return (temp_v1 % 256) & 0xFF; } -#else -GLOBAL_ASM("asm/non_matchings/code_800AF9B0/func_800B4874.s") -#endif #ifdef MIPS_TO_C //generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307 @@ -3033,36 +2938,24 @@ s32 func_800B49E4(void) { GLOBAL_ASM("asm/non_matchings/code_800AF9B0/func_800B49E4.s") #endif -#ifdef MIPS_TO_C -//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307 -? func_800B4A9C(s32); // extern -? func_800B4CB4(); // extern -extern u8 D_8018EB90; -extern u8 gSaveDataSoundMode; -extern u8 gSoundMode; -extern OSMesgQueue gSIEventMesgQueue; - void func_800B4A10(void) { s32 temp_s0; - u8 temp_t6; - s32 phi_s0; - osEepromLongRead(&gSIEventMesgQueue, 0, &D_8018EB90, 0x200); - phi_s0 = 0; - do { - func_800B4A9C(phi_s0); - temp_s0 = phi_s0 + 1; - phi_s0 = temp_s0; - } while (temp_s0 != 0x10); + osEepromLongRead(&gSIEventMesgQueue, 0, (u8*) &D_8018EB90, 0x200); //0x200: sizeof(SaveData)? + temp_s0 = 0; + while (temp_s0 < 16) // 16: 4 cup records * 4 course records? + { + func_800B4A9C(temp_s0); + ++temp_s0; + } + func_800B4CB4(); + gSoundMode = gSaveDataSoundMode; - if ((gSaveDataSoundMode & 0xFF) >= NUM_SOUND_OPTIONS) { + if (gSoundMode >= NUM_SOUND_MODES) { gSoundMode = SOUND_MONO; } } -#else -GLOBAL_ASM("asm/non_matchings/code_800AF9B0/func_800B4A10.s") -#endif #ifdef MIPS_TO_C //generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307 @@ -3509,7 +3402,6 @@ void func_800B5404(s32 arg0, s32 arg1) { GLOBAL_ASM("asm/non_matchings/code_800AF9B0/func_800B5404.s") #endif -extern u8 D_8018ED10[4]; // Direct reference to the grandPrixPoints section of save data u8 func_800B54EC(s32, s32); u8 func_800B5508(s32, s32, s32); @@ -3806,28 +3698,22 @@ extern u8 D_8018ED8F; GLOBAL_ASM("asm/non_matchings/code_800AF9B0/func_800B5AD8.s") #endif -#ifdef MIPS_TO_C -//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307 -extern OSMesgQueue gSIEventMesgQueue; - -? func_800B5B2C(s32 arg0) { +s32 func_800B5B2C(s32 arg0) { u8 sp1F; - ? phi_v0; + s32 phi_v0; if ((arg0 >= 4) || (arg0 < 0)) { return 0; } - arg0 = arg0; + osPfsIsPlug(&gSIEventMesgQueue, &sp1F); - phi_v0 = 0; + if ((sp1F & (1 << arg0)) != 0) { - phi_v0 = 1; + return 1; } - return phi_v0; + + return 0; } -#else -GLOBAL_ASM("asm/non_matchings/code_800AF9B0/func_800B5B2C.s") -#endif #ifdef MIPS_TO_C //generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307 @@ -4007,17 +3893,6 @@ block_25: GLOBAL_ASM("asm/non_matchings/code_800AF9B0/func_800B5DA4.s") #endif -#ifdef MIPS_TO_C -//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307 -s32 func_800B5B2C(?); // extern -s32 func_800CE720(? *, OSPfs *, ?); // extern -extern s8 D_800E86F8; -extern OSPfs D_8018E868; -extern s32 D_8018EB78; -extern s32 D_8018EB7C; -extern s32 gControllerPakNumPagesFree; -extern ? gSIEventMesgQueue; - s32 func_800B5F30(void) { s32 sp1C; @@ -4042,17 +3917,6 @@ s32 func_800B5F30(void) { } return -1; } -#else -GLOBAL_ASM("asm/non_matchings/code_800AF9B0/func_800B5F30.s") -#endif - -#ifdef MIPS_TO_C -//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307 -s32 func_800B5B2C(?); // extern -s32 func_800CE720(? *, ? *, ?); // extern -extern s8 D_800E86FC; -extern ? D_8018E8D0; -extern ? gSIEventMesgQueue; s32 func_800B6014(void) { s32 temp_v0; @@ -4069,9 +3933,6 @@ s32 func_800B6014(void) { } return -1; } -#else -GLOBAL_ASM("asm/non_matchings/code_800AF9B0/func_800B6014.s") -#endif #ifdef MIPS_TO_C //generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307 @@ -4567,34 +4428,55 @@ void func_800B69BC(s32 arg0) { GLOBAL_ASM("asm/non_matchings/code_800AF9B0/func_800B69BC.s") #endif -#ifdef MIPS_TO_C -//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307 -? func_800B69BC(s32); // extern -extern u16 D_800E86F0; -extern u32 D_800E86F4; -extern u8 D_800F2E64; -extern u8 D_800F2E74; -extern OSPfs D_8018E868; -extern s32 D_8018EB84; - s32 func_800B6A68(void) { + s32 pad; s32 sp30; s32 temp_s0; - s32 temp_v0; - s32 phi_s0; - temp_v0 = osPfsAllocateFile(&D_8018E868, D_800E86F0, D_800E86F4, &D_800F2E64, &D_800F2E74, 0x7900, &D_8018EB84); - sp30 = temp_v0; - if (temp_v0 == 0) { - phi_s0 = 0; - do { - func_800B69BC(phi_s0); - temp_s0 = phi_s0 + 1; - phi_s0 = temp_s0; - } while (temp_s0 != 2); + sp30 = osPfsAllocateFile(&D_8018E868, D_800E86F0, D_800E86F4, &D_800F2E64, &D_800F2E74, 0x7900, &D_8018EB84); + if (sp30 == 0) { + temp_s0 = 0; + while (temp_s0 < 2) + { + func_800B69BC(temp_s0); + ++temp_s0; + } } + return sp30; } + +#ifdef MIPS_TO_C +//generated by mips_to_c commit cc33060578851a93591ed035e96ffd1f15c765f1 +s32 func_800B5B2C(?); /* extern */ +? func_800B6A68(); /* extern */ +s32 func_800CE720(? *, ? *, ?); /* extern */ +s32 osPfsFindFile(? *, u16, s32, ? *, ? *, ? *); /* extern */ +s32 osPfsFreeBlocks(? *, s32 *); /* extern */ +s32 osPfsNumFiles(? *, s32 *, s32 *); /* extern */ +extern u16 D_800E86F0; +extern s32 D_800E86F4; +extern ? D_800F2E64; +extern ? D_800F2E74; +extern ? D_8018E868; +extern s32 D_8018EB78; +extern s32 D_8018EB7C; +extern ? D_8018EB84; +extern s32 gControllerPakNumPagesFree; +extern ? gSIEventMesgQueue; + +// Separated from assembly in code_800AF9B0/func_800B6A68.s +UNUSED void func_800B6AF8(void) { + s32 temp_t1; + + if ((func_800B5B2C(0) != 0) && (func_800CE720(&gSIEventMesgQueue, &D_8018E868, 0) == 0) && (osPfsFindFile(&D_8018E868, D_800E86F0, D_800E86F4, &D_800F2E64, &D_800F2E74, &D_8018EB84) != 0) && (osPfsNumFiles(&D_8018E868, &D_8018EB78, &D_8018EB7C) == 0) && (D_8018EB7C < D_8018EB78) && (osPfsFreeBlocks(&D_8018E868, &gControllerPakNumPagesFree) == 0)) { + temp_t1 = (s32) gControllerPakNumPagesFree >> 8; + gControllerPakNumPagesFree = temp_t1; + if (temp_t1 >= 0x79) { + func_800B6A68(); + } + } +} #else -GLOBAL_ASM("asm/non_matchings/code_800AF9B0/func_800B6A68.s") +GLOBAL_ASM("asm/non_matchings/code_800AF9B0/func_800B6AF8.s") #endif |
