From 0d9396b6316a79768e14676880266acf0fe175d6 Mon Sep 17 00:00:00 2001 From: Tyler McGavran Date: Fri, 25 Aug 2023 20:02:37 -0400 Subject: [PATCH] Make some adjustments to the SaveData struct (#381) Also get rid of some fake variables from a bss file. Matched a couple functions too. Signed-off-by: Taggerung --- asm/bss_8001C4D0_1.s | 59 +-- .../code_80091750/func_800A1BE0.s | 4 +- asm/non_matchings/menus/func_800B4A9C.s | 149 ------- asm/non_matchings/menus/func_800B5020.s | 137 ------- asm/non_matchings/menus/func_800B5218.s | 4 +- asm/non_matchings/menus/func_800B559C.s | 12 +- asm/non_matchings/menus/func_800B578C.s | 4 +- asm/non_matchings/menus/func_800B5948.s | 44 --- ctx_includes.c | 1 + include/common_structs.h | 53 --- include/save_data.h | 67 ++++ include/variables.h | 8 - src/code_80091750.c | 2 +- src/code_800B45E0.c | 371 ++++++++---------- src/code_800B45E0.h | 44 +-- src/menus.c | 11 +- 16 files changed, 258 insertions(+), 712 deletions(-) delete mode 100644 asm/non_matchings/menus/func_800B4A9C.s delete mode 100644 asm/non_matchings/menus/func_800B5020.s delete mode 100644 asm/non_matchings/menus/func_800B5948.s create mode 100644 include/save_data.h diff --git a/asm/bss_8001C4D0_1.s b/asm/bss_8001C4D0_1.s index 6cf36d81f..d54cc9ec8 100644 --- a/asm/bss_8001C4D0_1.s +++ b/asm/bss_8001C4D0_1.s @@ -50,65 +50,12 @@ glabel gControllerPak1FileNote glabel gControllerPak2FileNote .skip 8 -glabel D_8018EB90 -.skip 18 - -glabel D_8018EBA2 -.skip 366 - -# start of eight byte struct -glabel D_8018ED10 -.skip 1 - -glabel D_8018ED11 -.skip 1 - -glabel D_8018ED12 -.skip 1 - -glabel D_8018ED13 -.skip 1 - -glabel gSaveDataSoundMode -.skip 2 - -# crc 1 -glabel D_8018ED16 -.skip 1 - -# crc 2 -glabel D_8018ED17 -.skip 55 -# end eight byte struct at 8018ED18? - -glabel D_8018ED4E -.skip 58 - -# another save data struct (8 bytes again I hope) -glabel D_8018ED88 -.skip 1 - -glabel D_8018ED89 -.skip 1 - -glabel D_8018ED8A -.skip 1 - -glabel D_8018ED8B -.skip 1 - -glabel gSaveDataSoundModeBackup -.skip 2 - -glabel D_8018ED8E -.skip 1 - -glabel D_8018ED8F -.skip 1 +# SaveData +glabel gSaveData +.skip 512 glabel D_8018ED90 .skip 1 -# end backup save data struct glabel D_8018ED91 .skip 3 diff --git a/asm/non_matchings/code_80091750/func_800A1BE0.s b/asm/non_matchings/code_80091750/func_800A1BE0.s index 453dcb12f..93b124ca0 100644 --- a/asm/non_matchings/code_80091750/func_800A1BE0.s +++ b/asm/non_matchings/code_80091750/func_800A1BE0.s @@ -6,13 +6,13 @@ glabel func_800A1BE0 /* 0A27F0 800A1BF0 82E20000 */ lb $v0, ($s7) /* 0A27F4 800A1BF4 AFB5003C */ sw $s5, 0x3c($sp) /* 0A27F8 800A1BF8 AFB30034 */ sw $s3, 0x34($sp) -/* 0A27FC 800A1BFC 3C098019 */ lui $t1, %hi(D_8018EB90) # $t1, 0x8019 +/* 0A27FC 800A1BFC 3C098019 */ lui $t1, %hi(gSaveData) # $t1, 0x8019 /* 0A2800 800A1C00 AFBE0048 */ sw $fp, 0x48($sp) /* 0A2804 800A1C04 AFB60040 */ sw $s6, 0x40($sp) /* 0A2808 800A1C08 AFB40038 */ sw $s4, 0x38($sp) /* 0A280C 800A1C0C AFB00028 */ sw $s0, 0x28($sp) /* 0A2810 800A1C10 F7B40020 */ sdc1 $f20, 0x20($sp) -/* 0A2814 800A1C14 2529EB90 */ addiu $t1, %lo(D_8018EB90) # addiu $t1, $t1, -0x1470 +/* 0A2814 800A1C14 2529EB90 */ addiu $t1, %lo(gSaveData) # addiu $t1, $t1, -0x1470 /* 0A2818 800A1C18 3C13800E */ lui $s3, %hi(D_800E7834) # $s3, 0x800e /* 0A281C 800A1C1C 3C158015 */ lui $s5, %hi(gDisplayListHead) # $s5, 0x8015 /* 0A2820 800A1C20 AFBF004C */ sw $ra, 0x4c($sp) diff --git a/asm/non_matchings/menus/func_800B4A9C.s b/asm/non_matchings/menus/func_800B4A9C.s deleted file mode 100644 index 5b091ac97..000000000 --- a/asm/non_matchings/menus/func_800B4A9C.s +++ /dev/null @@ -1,149 +0,0 @@ -glabel func_800B4A9C -/* 0B569C 800B4A9C 27BDFFC8 */ addiu $sp, $sp, -0x38 -/* 0B56A0 800B4AA0 AFB00018 */ sw $s0, 0x18($sp) -/* 0B56A4 800B4AA4 00808025 */ move $s0, $a0 -/* 0B56A8 800B4AA8 AFBF001C */ sw $ra, 0x1c($sp) -/* 0B56AC 800B4AAC 02002825 */ move $a1, $s0 -/* 0B56B0 800B4AB0 0C02D3AD */ jal func_800B4EB4 -/* 0B56B4 800B4AB4 00002025 */ move $a0, $zero -/* 0B56B8 800B4AB8 3C01000F */ lui $at, (0x000FFFFF >> 16) # lui $at, 0xf -/* 0B56BC 800B4ABC 3421FFFF */ ori $at, (0x000FFFFF & 0xFFFF) # ori $at, $at, 0xffff -/* 0B56C0 800B4AC0 00417024 */ and $t6, $v0, $at -/* 0B56C4 800B4AC4 3C010009 */ lui $at, (0x000927C0 >> 16) # lui $at, 9 -/* 0B56C8 800B4AC8 342127C0 */ ori $at, (0x000927C0 & 0xFFFF) # ori $at, $at, 0x27c0 -/* 0B56CC 800B4ACC 01C1082B */ sltu $at, $t6, $at -/* 0B56D0 800B4AD0 10200015 */ beqz $at, .L800B4B28 -/* 0B56D4 800B4AD4 02002025 */ move $a0, $s0 -/* 0B56D8 800B4AD8 240F0001 */ li $t7, 1 -/* 0B56DC 800B4ADC 06010003 */ bgez $s0, .L800B4AEC -/* 0B56E0 800B4AE0 0010C083 */ sra $t8, $s0, 2 -/* 0B56E4 800B4AE4 26010003 */ addiu $at, $s0, 3 -/* 0B56E8 800B4AE8 0001C083 */ sra $t8, $at, 2 -.L800B4AEC: -/* 0B56EC 800B4AEC 0018C880 */ sll $t9, $t8, 2 -/* 0B56F0 800B4AF0 0338C823 */ subu $t9, $t9, $t8 -/* 0B56F4 800B4AF4 0019C940 */ sll $t9, $t9, 5 -/* 0B56F8 800B4AF8 06010004 */ bgez $s0, .L800B4B0C -/* 0B56FC 800B4AFC 320B0003 */ andi $t3, $s0, 3 -/* 0B5700 800B4B00 11600002 */ beqz $t3, .L800B4B0C -/* 0B5704 800B4B04 00000000 */ nop -/* 0B5708 800B4B08 256BFFFC */ addiu $t3, $t3, -4 -.L800B4B0C: -/* 0B570C 800B4B0C 000B6080 */ sll $t4, $t3, 2 -/* 0B5710 800B4B10 018B6023 */ subu $t4, $t4, $t3 -/* 0B5714 800B4B14 000C60C0 */ sll $t4, $t4, 3 -/* 0B5718 800B4B18 032C6821 */ addu $t5, $t9, $t4 -/* 0B571C 800B4B1C 3C018019 */ lui $at, %hi(D_8018EBA2) # 0x8019 -/* 0B5720 800B4B20 002D0821 */ addu $at, $at, $t5 -/* 0B5724 800B4B24 A02FEBA2 */ sb $t7, %lo(D_8018EBA2)($at) # -0x145e($at) -.L800B4B28: -/* 0B5728 800B4B28 06010003 */ bgez $s0, .L800B4B38 -/* 0B572C 800B4B2C 00107083 */ sra $t6, $s0, 2 -/* 0B5730 800B4B30 26010003 */ addiu $at, $s0, 3 -/* 0B5734 800B4B34 00017083 */ sra $t6, $at, 2 -.L800B4B38: -/* 0B5738 800B4B38 000EC080 */ sll $t8, $t6, 2 -/* 0B573C 800B4B3C 030EC023 */ subu $t8, $t8, $t6 -/* 0B5740 800B4B40 0018C140 */ sll $t8, $t8, 5 -/* 0B5744 800B4B44 06010004 */ bgez $s0, .L800B4B58 -/* 0B5748 800B4B48 320B0003 */ andi $t3, $s0, 3 -/* 0B574C 800B4B4C 11600002 */ beqz $t3, .L800B4B58 -/* 0B5750 800B4B50 00000000 */ nop -/* 0B5754 800B4B54 256BFFFC */ addiu $t3, $t3, -4 -.L800B4B58: -/* 0B5758 800B4B58 000BC880 */ sll $t9, $t3, 2 -/* 0B575C 800B4B5C 032BC823 */ subu $t9, $t9, $t3 -/* 0B5760 800B4B60 0019C8C0 */ sll $t9, $t9, 3 -/* 0B5764 800B4B64 3C0F8019 */ lui $t7, %hi(D_8018EB90) # $t7, 0x8019 -/* 0B5768 800B4B68 25EFEB90 */ addiu $t7, %lo(D_8018EB90) # addiu $t7, $t7, -0x1470 -/* 0B576C 800B4B6C 03196021 */ addu $t4, $t8, $t9 -/* 0B5770 800B4B70 018F5021 */ addu $t2, $t4, $t7 -/* 0B5774 800B4B74 0C02D3EC */ jal func_800B4FB0 -/* 0B5778 800B4B78 AFAA0024 */ sw $t2, 0x24($sp) -/* 0B577C 800B4B7C 8FAA0024 */ lw $t2, 0x24($sp) -/* 0B5780 800B4B80 02002025 */ move $a0, $s0 -/* 0B5784 800B4B84 0C02D21D */ jal func_800B4874 -/* 0B5788 800B4B88 AFAA0024 */ sw $t2, 0x24($sp) -/* 0B578C 800B4B8C 8FAA0024 */ lw $t2, 0x24($sp) -/* 0B5790 800B4B90 02002025 */ move $a0, $s0 -/* 0B5794 800B4B94 914D0017 */ lbu $t5, 0x17($t2) -/* 0B5798 800B4B98 11A2003B */ beq $t5, $v0, .L800B4C88 -/* 0B579C 800B4B9C 00000000 */ nop -/* 0B57A0 800B4BA0 0C02D1CA */ jal func_800B4728 -/* 0B57A4 800B4BA4 AFAA0024 */ sw $t2, 0x24($sp) -/* 0B57A8 800B4BA8 0C02D631 */ jal func_800B58C4 -/* 0B57AC 800B4BAC 02002025 */ move $a0, $s0 -/* 0B57B0 800B4BB0 14400031 */ bnez $v0, .L800B4C78 -/* 0B57B4 800B4BB4 8FAA0024 */ lw $t2, 0x24($sp) -/* 0B57B8 800B4BB8 3C0D8019 */ lui $t5, %hi(D_8018EB90) # $t5, 0x8019 -/* 0B57BC 800B4BBC 25ADEB90 */ addiu $t5, %lo(D_8018EB90) # addiu $t5, $t5, -0x1470 -/* 0B57C0 800B4BC0 3C05800F */ lui $a1, %hi(D_800F2E60) # $a1, 0x800f -/* 0B57C4 800B4BC4 00003825 */ move $a3, $zero -/* 0B57C8 800B4BC8 24A52E60 */ addiu $a1, %lo(D_800F2E60) # addiu $a1, $a1, 0x2e60 -/* 0B57CC 800B4BCC 00001825 */ move $v1, $zero -/* 0B57D0 800B4BD0 06010003 */ bgez $s0, .L800B4BE0 -/* 0B57D4 800B4BD4 001070C3 */ sra $t6, $s0, 3 -/* 0B57D8 800B4BD8 26010007 */ addiu $at, $s0, 7 -/* 0B57DC 800B4BDC 000170C3 */ sra $t6, $at, 3 -.L800B4BE0: -/* 0B57E0 800B4BE0 000E58C0 */ sll $t3, $t6, 3 -/* 0B57E4 800B4BE4 016E5823 */ subu $t3, $t3, $t6 -/* 0B57E8 800B4BE8 000B58C0 */ sll $t3, $t3, 3 -/* 0B57EC 800B4BEC 06010004 */ bgez $s0, .L800B4C00 -/* 0B57F0 800B4BF0 32180007 */ andi $t8, $s0, 7 -/* 0B57F4 800B4BF4 13000002 */ beqz $t8, .L800B4C00 -/* 0B57F8 800B4BF8 00000000 */ nop -/* 0B57FC 800B4BFC 2718FFF8 */ addiu $t8, $t8, -8 -.L800B4C00: -/* 0B5800 800B4C00 0018C880 */ sll $t9, $t8, 2 -/* 0B5804 800B4C04 0338C823 */ subu $t9, $t9, $t8 -/* 0B5808 800B4C08 01796021 */ addu $t4, $t3, $t9 -/* 0B580C 800B4C0C 258F0188 */ addiu $t7, $t4, 0x188 -/* 0B5810 800B4C10 01ED4021 */ addu $t0, $t7, $t5 -/* 0B5814 800B4C14 24090003 */ li $t1, 3 -.L800B4C18: -/* 0B5818 800B4C18 01031021 */ addu $v0, $t0, $v1 -/* 0B581C 800B4C1C 904E0000 */ lbu $t6, ($v0) -/* 0B5820 800B4C20 01432021 */ addu $a0, $t2, $v1 -/* 0B5824 800B4C24 24630001 */ addiu $v1, $v1, 1 -/* 0B5828 800B4C28 A08E0000 */ sb $t6, ($a0) -/* 0B582C 800B4C2C 90580018 */ lbu $t8, 0x18($v0) -/* 0B5830 800B4C30 31CB00FF */ andi $t3, $t6, 0xff -/* 0B5834 800B4C34 A098000F */ sb $t8, 0xf($a0) -/* 0B5838 800B4C38 90A60000 */ lbu $a2, ($a1) -/* 0B583C 800B4C3C 331900FF */ andi $t9, $t8, 0xff -/* 0B5840 800B4C40 15660004 */ bne $t3, $a2, .L800B4C54 -/* 0B5844 800B4C44 00000000 */ nop -/* 0B5848 800B4C48 17260002 */ bne $t9, $a2, .L800B4C54 -/* 0B584C 800B4C4C 00000000 */ nop -/* 0B5850 800B4C50 24E70001 */ addiu $a3, $a3, 1 -.L800B4C54: -/* 0B5854 800B4C54 1469FFF0 */ bne $v1, $t1, .L800B4C18 -/* 0B5858 800B4C58 24A50001 */ addiu $a1, $a1, 1 -/* 0B585C 800B4C5C 14E90003 */ bne $a3, $t1, .L800B4C6C -/* 0B5860 800B4C60 240C0001 */ li $t4, 1 -/* 0B5864 800B4C64 10000002 */ b .L800B4C70 -/* 0B5868 800B4C68 A1400012 */ sb $zero, 0x12($t2) -.L800B4C6C: -/* 0B586C 800B4C6C A14C0012 */ sb $t4, 0x12($t2) -.L800B4C70: -/* 0B5870 800B4C70 0C02D178 */ jal func_800B45E0 -/* 0B5874 800B4C74 02002025 */ move $a0, $s0 -.L800B4C78: -/* 0B5878 800B4C78 0C02D567 */ jal func_800B559C -/* 0B587C 800B4C7C 02002025 */ move $a0, $s0 -/* 0B5880 800B4C80 10000008 */ b .L800B4CA4 -/* 0B5884 800B4C84 8FBF001C */ lw $ra, 0x1c($sp) -.L800B4C88: -/* 0B5888 800B4C88 0C02D631 */ jal func_800B58C4 -/* 0B588C 800B4C8C 02002025 */ move $a0, $s0 -/* 0B5890 800B4C90 50400004 */ beql $v0, $zero, .L800B4CA4 -/* 0B5894 800B4C94 8FBF001C */ lw $ra, 0x1c($sp) -/* 0B5898 800B4C98 0C02D567 */ jal func_800B559C -/* 0B589C 800B4C9C 02002025 */ move $a0, $s0 -/* 0B58A0 800B4CA0 8FBF001C */ lw $ra, 0x1c($sp) -.L800B4CA4: -/* 0B58A4 800B4CA4 8FB00018 */ lw $s0, 0x18($sp) -/* 0B58A8 800B4CA8 27BD0038 */ addiu $sp, $sp, 0x38 -/* 0B58AC 800B4CAC 03E00008 */ jr $ra -/* 0B58B0 800B4CB0 00000000 */ nop diff --git a/asm/non_matchings/menus/func_800B5020.s b/asm/non_matchings/menus/func_800B5020.s deleted file mode 100644 index 552e3aebe..000000000 --- a/asm/non_matchings/menus/func_800B5020.s +++ /dev/null @@ -1,137 +0,0 @@ -glabel func_800B5020 -/* 0B5C20 800B5020 3C0E8019 */ lui $t6, %hi(gCupSelection) # $t6, 0x8019 -/* 0B5C24 800B5024 81CEEE09 */ lb $t6, %lo(gCupSelection)($t6) -/* 0B5C28 800B5028 3C188019 */ lui $t8, %hi(gCupCourseSelection) # $t8, 0x8019 -/* 0B5C2C 800B502C 8318EE0B */ lb $t8, %lo(gCupCourseSelection)($t8) -/* 0B5C30 800B5030 000E7880 */ sll $t7, $t6, 2 -/* 0B5C34 800B5034 27BDFFC0 */ addiu $sp, $sp, -0x40 -/* 0B5C38 800B5038 01F81021 */ addu $v0, $t7, $t8 -/* 0B5C3C 800B503C AFB30020 */ sw $s3, 0x20($sp) -/* 0B5C40 800B5040 3C0C8019 */ lui $t4, %hi(D_8018EB90) # $t4, 0x8019 -/* 0B5C44 800B5044 AFB50028 */ sw $s5, 0x28($sp) -/* 0B5C48 800B5048 AFB40024 */ sw $s4, 0x24($sp) -/* 0B5C4C 800B504C AFB2001C */ sw $s2, 0x1c($sp) -/* 0B5C50 800B5050 AFB10018 */ sw $s1, 0x18($sp) -/* 0B5C54 800B5054 AFB00014 */ sw $s0, 0x14($sp) -/* 0B5C58 800B5058 258CEB90 */ addiu $t4, %lo(D_8018EB90) # addiu $t4, $t4, -0x1470 -/* 0B5C5C 800B505C 3C13000F */ lui $s3, (0x000FFFFF >> 16) # lui $s3, 0xf -/* 0B5C60 800B5060 0080A825 */ move $s5, $a0 -/* 0B5C64 800B5064 AFBF002C */ sw $ra, 0x2c($sp) -/* 0B5C68 800B5068 AFA50044 */ sw $a1, 0x44($sp) -/* 0B5C6C 800B506C 00008825 */ move $s1, $zero -/* 0B5C70 800B5070 04410003 */ bgez $v0, .L800B5080 -/* 0B5C74 800B5074 0002C883 */ sra $t9, $v0, 2 -/* 0B5C78 800B5078 24410003 */ addiu $at, $v0, 3 -/* 0B5C7C 800B507C 0001C883 */ sra $t9, $at, 2 -.L800B5080: -/* 0B5C80 800B5080 00194080 */ sll $t0, $t9, 2 -/* 0B5C84 800B5084 01194023 */ subu $t0, $t0, $t9 -/* 0B5C88 800B5088 00084140 */ sll $t0, $t0, 5 -/* 0B5C8C 800B508C 04410004 */ bgez $v0, .L800B50A0 -/* 0B5C90 800B5090 30490003 */ andi $t1, $v0, 3 -/* 0B5C94 800B5094 11200002 */ beqz $t1, .L800B50A0 -/* 0B5C98 800B5098 00000000 */ nop -/* 0B5C9C 800B509C 2529FFFC */ addiu $t1, $t1, -4 -.L800B50A0: -/* 0B5CA0 800B50A0 00095080 */ sll $t2, $t1, 2 -/* 0B5CA4 800B50A4 01495023 */ subu $t2, $t2, $t1 -/* 0B5CA8 800B50A8 000A50C0 */ sll $t2, $t2, 3 -/* 0B5CAC 800B50AC 010A5821 */ addu $t3, $t0, $t2 -/* 0B5CB0 800B50B0 016C9021 */ addu $s2, $t3, $t4 -/* 0B5CB4 800B50B4 3673FFFF */ ori $s3, (0x000FFFFF & 0xFFFF) # ori $s3, $s3, 0xffff -/* 0B5CB8 800B50B8 00008025 */ move $s0, $zero -/* 0B5CBC 800B50BC 24140005 */ li $s4, 5 -/* 0B5CC0 800B50C0 AFA20030 */ sw $v0, 0x30($sp) -.L800B50C4: -/* 0B5CC4 800B50C4 0C02D37D */ jal func_800B4DF4 -/* 0B5CC8 800B50C8 02502021 */ addu $a0, $s2, $s0 -/* 0B5CCC 800B50CC 00536824 */ and $t5, $v0, $s3 -/* 0B5CD0 800B50D0 02AD082B */ sltu $at, $s5, $t5 -/* 0B5CD4 800B50D4 54200005 */ bnel $at, $zero, .L800B50EC -/* 0B5CD8 800B50D8 2A210005 */ slti $at, $s1, 5 -/* 0B5CDC 800B50DC 26310001 */ addiu $s1, $s1, 1 -/* 0B5CE0 800B50E0 1634FFF8 */ bne $s1, $s4, .L800B50C4 -/* 0B5CE4 800B50E4 26100003 */ addiu $s0, $s0, 3 -/* 0B5CE8 800B50E8 2A210005 */ slti $at, $s1, 5 -.L800B50EC: -/* 0B5CEC 800B50EC 14200003 */ bnez $at, .L800B50FC -/* 0B5CF0 800B50F0 24040004 */ li $a0, 4 -/* 0B5CF4 800B50F4 1000003F */ b .L800B51F4 -/* 0B5CF8 800B50F8 2402FFFF */ li $v0, -1 -.L800B50FC: -/* 0B5CFC 800B50FC 2A210004 */ slti $at, $s1, 4 -/* 0B5D00 800B5100 10200033 */ beqz $at, .L800B51D0 -/* 0B5D04 800B5104 02503821 */ addu $a3, $s2, $s0 -/* 0B5D08 800B5108 240E0004 */ li $t6, 4 -/* 0B5D0C 800B510C 01D11023 */ subu $v0, $t6, $s1 -/* 0B5D10 800B5110 304F0003 */ andi $t7, $v0, 3 -/* 0B5D14 800B5114 000F1023 */ negu $v0, $t7 -/* 0B5D18 800B5118 1040000E */ beqz $v0, .L800B5154 -/* 0B5D1C 800B511C 24450004 */ addiu $a1, $v0, 4 -/* 0B5D20 800B5120 00041880 */ sll $v1, $a0, 2 -/* 0B5D24 800B5124 00641823 */ subu $v1, $v1, $a0 -.L800B5128: -/* 0B5D28 800B5128 02431021 */ addu $v0, $s2, $v1 -/* 0B5D2C 800B512C 9058FFFD */ lbu $t8, -3($v0) -/* 0B5D30 800B5130 9059FFFE */ lbu $t9, -2($v0) -/* 0B5D34 800B5134 9049FFFF */ lbu $t1, -1($v0) -/* 0B5D38 800B5138 2484FFFF */ addiu $a0, $a0, -1 -/* 0B5D3C 800B513C 2463FFFD */ addiu $v1, $v1, -3 -/* 0B5D40 800B5140 A0580000 */ sb $t8, ($v0) -/* 0B5D44 800B5144 A0590001 */ sb $t9, 1($v0) -/* 0B5D48 800B5148 14A4FFF7 */ bne $a1, $a0, .L800B5128 -/* 0B5D4C 800B514C A0490002 */ sb $t1, 2($v0) -/* 0B5D50 800B5150 1224001F */ beq $s1, $a0, .L800B51D0 -.L800B5154: -/* 0B5D54 800B5154 00041880 */ sll $v1, $a0, 2 -/* 0B5D58 800B5158 00112880 */ sll $a1, $s1, 2 -/* 0B5D5C 800B515C 00B12823 */ subu $a1, $a1, $s1 -/* 0B5D60 800B5160 00641823 */ subu $v1, $v1, $a0 -.L800B5164: -/* 0B5D64 800B5164 02431021 */ addu $v0, $s2, $v1 -/* 0B5D68 800B5168 9048FFFD */ lbu $t0, -3($v0) -/* 0B5D6C 800B516C 904AFFFE */ lbu $t2, -2($v0) -/* 0B5D70 800B5170 904CFFFA */ lbu $t4, -6($v0) -/* 0B5D74 800B5174 A0480000 */ sb $t0, ($v0) -/* 0B5D78 800B5178 A04A0001 */ sb $t2, 1($v0) -/* 0B5D7C 800B517C 904AFFF6 */ lbu $t2, -0xa($v0) -/* 0B5D80 800B5180 9048FFF5 */ lbu $t0, -0xb($v0) -/* 0B5D84 800B5184 904DFFFB */ lbu $t5, -5($v0) -/* 0B5D88 800B5188 904EFFFC */ lbu $t6, -4($v0) -/* 0B5D8C 800B518C 904FFFF7 */ lbu $t7, -9($v0) -/* 0B5D90 800B5190 9058FFF8 */ lbu $t8, -8($v0) -/* 0B5D94 800B5194 9059FFF9 */ lbu $t9, -7($v0) -/* 0B5D98 800B5198 9049FFF4 */ lbu $t1, -0xc($v0) -/* 0B5D9C 800B519C 904BFFFF */ lbu $t3, -1($v0) -/* 0B5DA0 800B51A0 2463FFF4 */ addiu $v1, $v1, -0xc -/* 0B5DA4 800B51A4 A04CFFFD */ sb $t4, -3($v0) -/* 0B5DA8 800B51A8 A04AFFF9 */ sb $t2, -7($v0) -/* 0B5DAC 800B51AC A048FFF8 */ sb $t0, -8($v0) -/* 0B5DB0 800B51B0 A04DFFFE */ sb $t5, -2($v0) -/* 0B5DB4 800B51B4 A04EFFFF */ sb $t6, -1($v0) -/* 0B5DB8 800B51B8 A04FFFFA */ sb $t7, -6($v0) -/* 0B5DBC 800B51BC A058FFFB */ sb $t8, -5($v0) -/* 0B5DC0 800B51C0 A059FFFC */ sb $t9, -4($v0) -/* 0B5DC4 800B51C4 A049FFF7 */ sb $t1, -9($v0) -/* 0B5DC8 800B51C8 14A3FFE6 */ bne $a1, $v1, .L800B5164 -/* 0B5DCC 800B51CC A04B0002 */ sb $t3, 2($v0) -.L800B51D0: -/* 0B5DD0 800B51D0 00E02025 */ move $a0, $a3 -/* 0B5DD4 800B51D4 02A02825 */ move $a1, $s5 -/* 0B5DD8 800B51D8 0C02D373 */ jal populate_time_trial_record -/* 0B5DDC 800B51DC 8FA60044 */ lw $a2, 0x44($sp) -/* 0B5DE0 800B51E0 240B0001 */ li $t3, 1 -/* 0B5DE4 800B51E4 A24B0012 */ sb $t3, 0x12($s2) -/* 0B5DE8 800B51E8 0C02D178 */ jal func_800B45E0 -/* 0B5DEC 800B51EC 8FA40030 */ lw $a0, 0x30($sp) -/* 0B5DF0 800B51F0 02201025 */ move $v0, $s1 -.L800B51F4: -/* 0B5DF4 800B51F4 8FBF002C */ lw $ra, 0x2c($sp) -/* 0B5DF8 800B51F8 8FB00014 */ lw $s0, 0x14($sp) -/* 0B5DFC 800B51FC 8FB10018 */ lw $s1, 0x18($sp) -/* 0B5E00 800B5200 8FB2001C */ lw $s2, 0x1c($sp) -/* 0B5E04 800B5204 8FB30020 */ lw $s3, 0x20($sp) -/* 0B5E08 800B5208 8FB40024 */ lw $s4, 0x24($sp) -/* 0B5E0C 800B520C 8FB50028 */ lw $s5, 0x28($sp) -/* 0B5E10 800B5210 03E00008 */ jr $ra -/* 0B5E14 800B5214 27BD0040 */ addiu $sp, $sp, 0x40 diff --git a/asm/non_matchings/menus/func_800B5218.s b/asm/non_matchings/menus/func_800B5218.s index 200985638..0bf099959 100644 --- a/asm/non_matchings/menus/func_800B5218.s +++ b/asm/non_matchings/menus/func_800B5218.s @@ -52,8 +52,8 @@ glabel func_800B5218 /* 0B5ED4 800B52D4 10200021 */ beqz $at, .L800B535C /* 0B5ED8 800B52D8 00001025 */ move $v0, $zero /* 0B5EDC 800B52DC 8FA30038 */ lw $v1, 0x38($sp) -/* 0B5EE0 800B52E0 3C0C8019 */ lui $t4, %hi(D_8018EB90) # $t4, 0x8019 -/* 0B5EE4 800B52E4 258CEB90 */ addiu $t4, %lo(D_8018EB90) # addiu $t4, $t4, -0x1470 +/* 0B5EE0 800B52E0 3C0C8019 */ lui $t4, %hi(gSaveData) # $t4, 0x8019 +/* 0B5EE4 800B52E4 258CEB90 */ addiu $t4, %lo(gSaveData) # addiu $t4, $t4, -0x1470 /* 0B5EE8 800B52E8 04610003 */ bgez $v1, .L800B52F8 /* 0B5EEC 800B52EC 0003C083 */ sra $t8, $v1, 2 /* 0B5EF0 800B52F0 24610003 */ addiu $at, $v1, 3 diff --git a/asm/non_matchings/menus/func_800B559C.s b/asm/non_matchings/menus/func_800B559C.s index 16ca14cdc..5ee54672f 100644 --- a/asm/non_matchings/menus/func_800B559C.s +++ b/asm/non_matchings/menus/func_800B559C.s @@ -21,12 +21,12 @@ glabel func_800B559C /* 0B61E4 800B55E4 001678C0 */ sll $t7, $s6, 3 /* 0B61E8 800B55E8 01F67823 */ subu $t7, $t7, $s6 /* 0B61EC 800B55EC 000F78C0 */ sll $t7, $t7, 3 -/* 0B61F0 800B55F0 3C198019 */ lui $t9, %hi(D_8018EB90) # $t9, 0x8019 -/* 0B61F4 800B55F4 2739EB90 */ addiu $t9, %lo(D_8018EB90) # addiu $t9, $t9, -0x1470 +/* 0B61F0 800B55F0 3C198019 */ lui $t9, %hi(gSaveData) # $t9, 0x8019 +/* 0B61F4 800B55F4 2739EB90 */ addiu $t9, %lo(gSaveData) # addiu $t9, $t9, -0x1470 /* 0B61F8 800B55F8 25F80188 */ addiu $t8, $t7, 0x188 /* 0B61FC 800B55FC 000398C0 */ sll $s3, $v1, 3 -/* 0B6200 800B5600 3C158019 */ lui $s5, %hi(D_8018EB90) # $s5, 0x8019 -/* 0B6204 800B5604 26B5EB90 */ addiu $s5, %lo(D_8018EB90) # addiu $s5, $s5, -0x1470 +/* 0B6200 800B5600 3C158019 */ lui $s5, %hi(gSaveData) # $s5, 0x8019 +/* 0B6204 800B5604 26B5EB90 */ addiu $s5, %lo(gSaveData) # addiu $s5, $s5, -0x1470 /* 0B6208 800B5608 26730008 */ addiu $s3, $s3, 8 /* 0B620C 800B560C 03199021 */ addu $s2, $t8, $t9 /* 0B6210 800B5610 24140018 */ li $s4, 24 @@ -104,9 +104,9 @@ glabel func_800B559C /* 0B630C 800B570C 00000000 */ nop .L800B5710: /* 0B6310 800B5710 001660C0 */ sll $t4, $s6, 3 -/* 0B6314 800B5714 3C158019 */ lui $s5, %hi(D_8018EB90) # $s5, 0x8019 +/* 0B6314 800B5714 3C158019 */ lui $s5, %hi(gSaveData) # $s5, 0x8019 /* 0B6318 800B5718 01966023 */ subu $t4, $t4, $s6 -/* 0B631C 800B571C 26B5EB90 */ addiu $s5, %lo(D_8018EB90) # addiu $s5, $s5, -0x1470 +/* 0B631C 800B571C 26B5EB90 */ addiu $s5, %lo(gSaveData) # addiu $s5, $s5, -0x1470 /* 0B6320 800B5720 000C60C0 */ sll $t4, $t4, 3 /* 0B6324 800B5724 02AC9021 */ addu $s2, $s5, $t4 /* 0B6328 800B5728 26520188 */ addiu $s2, $s2, 0x188 diff --git a/asm/non_matchings/menus/func_800B578C.s b/asm/non_matchings/menus/func_800B578C.s index 67f5ac858..9e2072794 100644 --- a/asm/non_matchings/menus/func_800B578C.s +++ b/asm/non_matchings/menus/func_800B578C.s @@ -2,8 +2,8 @@ glabel func_800B578C /* 0B638C 800B578C 000470C0 */ sll $t6, $a0, 3 /* 0B6390 800B5790 01C47023 */ subu $t6, $t6, $a0 /* 0B6394 800B5794 000E70C0 */ sll $t6, $t6, 3 -/* 0B6398 800B5798 3C188019 */ lui $t8, %hi(D_8018EB90) # $t8, 0x8019 -/* 0B639C 800B579C 2718EB90 */ addiu $t8, %lo(D_8018EB90) # addiu $t8, $t8, -0x1470 +/* 0B6398 800B5798 3C188019 */ lui $t8, %hi(gSaveData) # $t8, 0x8019 +/* 0B639C 800B579C 2718EB90 */ addiu $t8, %lo(gSaveData) # addiu $t8, $t8, -0x1470 /* 0B63A0 800B57A0 25CF0188 */ addiu $t7, $t6, 0x188 /* 0B63A4 800B57A4 01F83021 */ addu $a2, $t7, $t8 /* 0B63A8 800B57A8 00001825 */ move $v1, $zero diff --git a/asm/non_matchings/menus/func_800B5948.s b/asm/non_matchings/menus/func_800B5948.s deleted file mode 100644 index b0cee2c55..000000000 --- a/asm/non_matchings/menus/func_800B5948.s +++ /dev/null @@ -1,44 +0,0 @@ -glabel update_save_data_backup -/* 0B6548 800B5948 3C0E8019 */ lui $t6, %hi(D_8018ED10) # $t6, 0x8019 -/* 0B654C 800B594C 91CEED10 */ lbu $t6, %lo(D_8018ED10)($t6) -/* 0B6550 800B5950 3C018019 */ lui $at, %hi(D_8018ED88) # $at, 0x8019 -/* 0B6554 800B5954 3C0F8019 */ lui $t7, %hi(D_8018ED11) # $t7, 0x8019 -/* 0B6558 800B5958 A02EED88 */ sb $t6, %lo(D_8018ED88)($at) -/* 0B655C 800B595C 91EFED11 */ lbu $t7, %lo(D_8018ED11)($t7) -/* 0B6560 800B5960 3C018019 */ lui $at, %hi(D_8018ED89) # $at, 0x8019 -/* 0B6564 800B5964 3C188019 */ lui $t8, %hi(D_8018ED12) # $t8, 0x8019 -/* 0B6568 800B5968 A02FED89 */ sb $t7, %lo(D_8018ED89)($at) -/* 0B656C 800B596C 9318ED12 */ lbu $t8, %lo(D_8018ED12)($t8) -/* 0B6570 800B5970 3C018019 */ lui $at, %hi(D_8018ED8A) # $at, 0x8019 -/* 0B6574 800B5974 3C198019 */ lui $t9, %hi(D_8018ED13) # $t9, 0x8019 -/* 0B6578 800B5978 A038ED8A */ sb $t8, %lo(D_8018ED8A)($at) -/* 0B657C 800B597C 9339ED13 */ lbu $t9, %lo(D_8018ED13)($t9) -/* 0B6580 800B5980 3C018019 */ lui $at, %hi(D_8018ED8B) # $at, 0x8019 -/* 0B6584 800B5984 3C088019 */ lui $t0, %hi(gSaveDataSoundMode) # $t0, 0x8019 -/* 0B6588 800B5988 A039ED8B */ sb $t9, %lo(D_8018ED8B)($at) -/* 0B658C 800B598C 9108ED14 */ lbu $t0, %lo(gSaveDataSoundMode)($t0) -/* 0B6590 800B5990 27BDFFE8 */ addiu $sp, $sp, -0x18 -/* 0B6594 800B5994 AFBF0014 */ sw $ra, 0x14($sp) -/* 0B6598 800B5998 3C018019 */ lui $at, %hi(gSaveDataSoundModeBackup) # $at, 0x8019 -/* 0B659C 800B599C 0C02D67D */ jal compute_save_data_checksum_backup_1 -/* 0B65A0 800B59A0 A028ED8C */ sb $t0, %lo(gSaveDataSoundModeBackup)($at) -/* 0B65A4 800B59A4 3C018019 */ lui $at, %hi(D_8018ED8E) # $at, 0x8019 -/* 0B65A8 800B59A8 0C02D6AB */ jal compute_save_data_checksum_backup_2 -/* 0B65AC 800B59AC A022ED8E */ sb $v0, %lo(D_8018ED8E)($at) -/* 0B65B0 800B59B0 3C068019 */ lui $a2, %hi(D_8018ED88) # $a2, 0x8019 -/* 0B65B4 800B59B4 3C098019 */ lui $t1, %hi(D_8018EB90) # $t1, 0x8019 -/* 0B65B8 800B59B8 24C6ED88 */ addiu $a2, %lo(D_8018ED88) # addiu $a2, $a2, -0x1278 -/* 0B65BC 800B59BC 2529EB90 */ addiu $t1, %lo(D_8018EB90) # addiu $t1, $t1, -0x1470 -/* 0B65C0 800B59C0 00C92823 */ subu $a1, $a2, $t1 -/* 0B65C4 800B59C4 3C018019 */ lui $at, %hi(D_8018ED8F) # $at, 0x8019 -/* 0B65C8 800B59C8 000550C2 */ srl $t2, $a1, 3 -/* 0B65CC 800B59CC 3C048015 */ lui $a0, %hi(gSIEventMesgQueue) # $a0, 0x8015 -/* 0B65D0 800B59D0 A022ED8F */ sb $v0, %lo(D_8018ED8F)($at) -/* 0B65D4 800B59D4 2484F0B8 */ addiu $a0, %lo(gSIEventMesgQueue) # addiu $a0, $a0, -0xf48 -/* 0B65D8 800B59D8 314500FF */ andi $a1, $t2, 0xff -/* 0B65DC 800B59DC 0C034014 */ jal osEepromLongWrite -/* 0B65E0 800B59E0 24070008 */ li $a3, 8 -/* 0B65E4 800B59E4 8FBF0014 */ lw $ra, 0x14($sp) -/* 0B65E8 800B59E8 27BD0018 */ addiu $sp, $sp, 0x18 -/* 0B65EC 800B59EC 03E00008 */ jr $ra -/* 0B65F0 800B59F0 00000000 */ nop diff --git a/ctx_includes.c b/ctx_includes.c index b7122c35f..aadd26b28 100644 --- a/ctx_includes.c +++ b/ctx_includes.c @@ -15,6 +15,7 @@ #include "include/kart_attributes.h" #include "include/macros.h" #include "include/objects.h" +#include "include/save_data.h" #include "include/segment_symbols.h" #include "include/segments.h" #include "include/sounds.h" diff --git a/include/common_structs.h b/include/common_structs.h index 3372ea73a..a718ac995 100644 --- a/include/common_structs.h +++ b/include/common_structs.h @@ -379,59 +379,6 @@ typedef struct { /* 0x0DD4 */ // s16 unk_DD4; } Player; // size = 0xDD8 -typedef struct { - // 6 little endian 3-byte records. - // When converted to big endian the bottom 5 nibbles can be interpreted as the centisecond count for that record. - // The top nibble is the character ID of the charcter used to set that record - // The first 5 records are the top 5 3-lap records - // The 6th record is the best 1-lap record - u8 records[6][3]; - // It's unknown what these bytes are used for - // Byte 1 might be an indicator that there is a ghost available for that course - u8 unknownBytes[6]; -} CourseTimeTrialRecords; // size = 0x18 - -typedef struct { - // Each cup is made up of 4 courses - CourseTimeTrialRecords courseRecords[4]; -} CupTimeTrialRecords; // size = 0x60 - -typedef struct { - // There are 4 cups total - CupTimeTrialRecords cupRecords[4]; -} AllCourseTimeTrialRecords; // size = 0x180 - -typedef struct { - // Records 0 through 3 are for the first cup's courses - // Records 4 through 7 are for the second cup's courses - u8 bestThreelaps[8][3]; - u8 bestSinglelaps[8][3]; - // It's unknown what these bytes are used for - u8 unknownBytes[8]; -} OnlyBestTimeTrialRecords; // size = 0x38 - -typedef struct { - AllCourseTimeTrialRecords allCourseTimeTrialRecords; - // GP Points scored for each CC mode - // 1st place is 3 points, 2nd is 2, etc. - // Lowest dibit is the Mushroom Cup, 2nd dibit is the Flower Cup, etc - u8 grandPrixPoints[4]; - u8 soundMode; - // It's unknown what the first byte is used for - u8 checksum[3]; - // For some reason there's 2 entries covering 4 cups - // Instead of 4 entries, one per cup. Or even just one big entry for all 4 cups - // Its also unknown why these are here when they're identical to the values found - // in allCourseTimeTrialRecords - OnlyBestTimeTrialRecords onlyBestTimeTrialRecords[2]; - // If checksum[1] or checksum[2] does not match their expected value, - // the grandPrixPoints and soundMode are reset. Then if the backup data's - // checksums are valid, copy the backup data to the main data. - u8 grandPrixPointsBackup[4]; - u8 soundModeBackup; - u8 checksumBackup[3]; -} SaveData; // size = 0x200 - typedef struct { /* 0x00 */ char unk_00[0x1D]; /* 0x1D */ s8 unk_1D; diff --git a/include/save_data.h b/include/save_data.h new file mode 100644 index 000000000..b5e0ebb9b --- /dev/null +++ b/include/save_data.h @@ -0,0 +1,67 @@ +#ifndef SAVE_DATA_H +#define SAVE_DATA_H + +#include "common_structs.h" + +typedef struct { + // 6 little endian 3-byte records. + // When converted to big endian the bottom 5 nibbles can be interpreted as the centisecond count for that record. + // The top nibble is the character ID of the charcter used to set that record + // The first 5 records are the top 5 3-lap records + // The 6th record is the best 1-lap record + u8 records[6][3]; + // It's unknown what these bytes are used for + // Byte 1 might be an indicator that there is a ghost available for that course + u8 unknownBytes[6]; +} CourseTimeTrialRecords; // size = 0x18 + +typedef struct { + // Each cup is made up of 4 courses + CourseTimeTrialRecords courseRecords[4]; +} CupTimeTrialRecords; // size = 0x60 + +typedef struct { + // There are 4 cups total + CupTimeTrialRecords cupRecords[4]; +} AllCourseTimeTrialRecords; // size = 0x180 + +typedef struct { + // Records 0 through 3 are for the first cup's courses + // Records 4 through 7 are for the second cup's courses + u8 bestThreelaps[8][3]; + u8 bestSinglelaps[8][3]; + // It's unknown what these bytes are used for + u8 unknownBytes[8]; +} OnlyBestTimeTrialRecords; // size = 0x38 + +typedef struct { + // GP Points scored for each CC mode + // 1st place is 3 points, 2nd is 2, etc. + // Lowest dibit is the Mushroom Cup, 2nd dibit is the Flower Cup, etc + u8 grandPrixPoints[4]; + u8 soundMode; + // It's unknown what the first byte is used for + u8 checksum[3]; +} Stuff; // size = 0x8 + +typedef struct { + /* 0x000 */ AllCourseTimeTrialRecords allCourseTimeTrialRecords; + /* 0x180 */ Stuff main; + /** + * For some reason there's 2 entries covering 4 cups + * Instead of 4 entries, one per cup. Or even just one big entry for all 4 cups + * Its also unknown why these are here when they're identical to the values found + * in allCourseTimeTrialRecords + **/ + /* 0x188 */ OnlyBestTimeTrialRecords onlyBestTimeTrialRecords[2]; + /** + * If checksum[1] or checksum[2] does not match their expected value, + * the grandPrixPoints and soundMode are reset. Then if the backup data's + * checksums are valid, copy the backup data to the main data. + **/ + /* 0x1F8 */ Stuff backup; +} SaveData; // size = 0x200 + +extern SaveData gSaveData; + +#endif \ No newline at end of file diff --git a/include/variables.h b/include/variables.h index 71f0f6417..51e9f1e0c 100644 --- a/include/variables.h +++ b/include/variables.h @@ -40,10 +40,6 @@ extern s8 gHumanPlayerCount; extern s32 gIsMirrorMode; // D_800DC604 -extern f32 gKartFrictionTable[]; -extern f32 gKartBoundingBoxTable[]; -extern f32 gKartGravityTable[]; - extern f32 gLapCompletionPercentByPlayerId[8]; // D_801644A8 extern s32 gLapCountByPlayerId[8]; // D_80164390 @@ -60,8 +56,6 @@ extern s32 gPlayerCountSelection1; extern s32 gPlayerIsThrottleActive[]; // D_801653E0 extern s32 gGPCurrentRaceRankByPlayerId[]; // D_801643B8 -extern u8 gSaveDataSoundMode; // D_8018ED14 -extern u8 gSaveDataSoundModeBackup; // D_8018ED8C //extern u32 gScreenModeSelection; // D_800DC530 extern u32 gSegmentTable[16]; // D_80150258 extern OSMesgQueue gSIEventMesgQueue; // D_8014F0B8 @@ -83,8 +77,6 @@ extern Player* gPlayerSeven; extern Player* gPlayerEight; extern Player* gPlayerOneCopy; -extern SaveData D_8018EB90; - extern struct_8018CA70_entry D_8018CA70[]; extern Mtx D_80183D60[]; diff --git a/src/code_80091750.c b/src/code_80091750.c index 1467e1301..ea3d8fdd1 100644 --- a/src/code_80091750.c +++ b/src/code_80091750.c @@ -8338,7 +8338,7 @@ void func_800A1BE0(struct_8018D9E0_entry *arg0) { phi_s2 = 1; switch (phi_s0) { /* irregular */ case 1: - if (D_8018EB90.allCourseTimeTrialRecords.cupRecords[((s32) temp_v0 / 4)].courseRecords[((s32) temp_v0 % 4)].records[0].unk12 == 0) { + if (gSaveData.allCourseTimeTrialRecords.cupRecords[((s32) temp_v0 / 4)].courseRecords[((s32) temp_v0 % 4)].records[0].unk12 == 0) { block_9: phi_s1 = 1; } diff --git a/src/code_800B45E0.c b/src/code_800B45E0.c index a62a9cd22..cbbcbc7db 100644 --- a/src/code_800B45E0.c +++ b/src/code_800B45E0.c @@ -7,6 +7,7 @@ #include "code_80091750.h" #include "menus.h" +#include "save_data.h" #include "staff_ghosts.h" /*** macros ***/ @@ -14,7 +15,7 @@ #define PFS_GAME_CODE(c0, c1, c2, c3) ((u32)(((c0) << 24) | ((c1) << 16) | ((c2) << 8) | (c3))) // calculate an eeprom address based off of the ram address of the SaveData variable // very fragile! -#define EEPROM_ADDR(ptr) (((uintptr_t)(ptr) - (uintptr_t)(&D_8018EB90)) / 8) +#define EEPROM_ADDR(ptr) (((uintptr_t)(ptr) - (uintptr_t)(&gSaveData)) / 8) /*** data ***/ u16 gCompanyCode = PFS_COMPANY_CODE('0', '1'); @@ -23,19 +24,16 @@ s8 gControllerPak1State = BAD; s8 sControllerPak2State = BAD; /*** rodata ***/ -// default time trial records? +// default time trial records in little endian form const u8 D_800F2E60[4] = {0xc0, 0x27, 0x09, 0x00}; // osPfsFindFile -> gGameName ("MARIOKART64" in nosFont) const u8 gGameName[] = {0x26, 0x1a, 0x2b, 0x22, 0x28, 0x24, 0x1a, 0x2b, 0x2d, 0x16, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00}; // ext_name param to osPfsFindFile (four total bytes, but only one is setable) const u8 gExtCode[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; -/*** forward declarations ***/ -s32 func_800B58C4(s32 arg0); - // new file start? void func_800B45E0(s32 arg0) { - CourseTimeTrialRecords* courseTimeTrialRecordsPtr = &D_8018EB90.allCourseTimeTrialRecords \ + CourseTimeTrialRecords* courseTimeTrialRecordsPtr = &gSaveData.allCourseTimeTrialRecords \ .cupRecords[arg0 / 4] \ .courseRecords[arg0 % 4]; @@ -44,9 +42,10 @@ void func_800B45E0(s32 arg0) { } void write_save_data_grand_prix_points_and_sound_mode(void) { - D_8018ED16 = compute_save_data_checksum_1(); - D_8018ED17 = compute_save_data_checksum_2(); - osEepromLongWrite(&gSIEventMesgQueue, EEPROM_ADDR(&D_8018ED10), (u8 *)&D_8018ED10, 8); + Stuff *main = &gSaveData.main; + main->checksum[1] = compute_save_data_checksum_1(); + main->checksum[2] = compute_save_data_checksum_2(); + osEepromLongWrite(&gSIEventMesgQueue, EEPROM_ADDR(main), main, sizeof(Stuff)); } void func_800B46D0(void) { @@ -65,7 +64,7 @@ void func_800B4728(s32 arg0) { s32 i, j; CourseTimeTrialRecords* courseTimeTrialRecords; - courseTimeTrialRecords = &D_8018EB90.allCourseTimeTrialRecords \ + courseTimeTrialRecords = &gSaveData.allCourseTimeTrialRecords \ .cupRecords[arg0 / 4] \ .courseRecords[arg0 % 4]; @@ -88,11 +87,12 @@ void func_800B4728(s32 arg0) { } void reset_save_data_grand_prix_points_and_sound_mode(void) { - D_8018ED10.grandPrixPointsMushroomCup = 0; - D_8018ED11 = 0; - D_8018ED12 = 0; - D_8018ED13 = 0; - gSaveDataSoundMode = SOUND_STEREO; + s32 cup_index; + Stuff *main = &gSaveData.main; + for (cup_index = 0; cup_index < 4; cup_index++) { + main->grandPrixPoints[cup_index] = 0; + } + main->soundMode = SOUND_STEREO; gSoundMode = SOUND_STEREO; func_800B44BC(); write_save_data_grand_prix_points_and_sound_mode(); @@ -103,7 +103,7 @@ u8 func_800B4874(s32 courseIdx) { s32 j; s32 i; s32 ret; - u8 *records = D_8018EB90.allCourseTimeTrialRecords \ + u8 *records = gSaveData.allCourseTimeTrialRecords \ .cupRecords[courseIdx / 4] \ .courseRecords[courseIdx % 4] \ .records[0]; @@ -120,26 +120,26 @@ u8 func_800B4874(s32 courseIdx) { u8 compute_save_data_checksum_1(void) { - u8 *raw = (void *)&D_8018ED10; + u8 *grandPrixPoints = &gSaveData.main.grandPrixPoints; s32 i; s32 crc = 0; for (i = 0; i < 5; i++) { - crc += ((raw[i] + 1) * (i + 1)) + i; + crc += ((grandPrixPoints[i] + 1) * (i + 1)) + i; } return crc % 0x100; } u8 compute_save_data_checksum_2(void) { - s32 tmp = D_8018ED16 + 90; + s32 tmp = gSaveData.main.checksum[1] + 90; return (tmp % 256); } void load_save_data(void) { s32 i; - osEepromLongRead(&gSIEventMesgQueue, EEPROM_ADDR(&D_8018EB90), (u8 *)&D_8018EB90, sizeof(SaveData)); + osEepromLongRead(&gSIEventMesgQueue, EEPROM_ADDR(&gSaveData), (u8 *)&gSaveData, sizeof(SaveData)); // 16: 4 cup records * 4 course records? for (i = 0; i < 16; i++) { func_800B4A9C(i); @@ -147,41 +147,42 @@ void load_save_data(void) { validate_save_data(); - gSoundMode = gSaveDataSoundMode; + gSoundMode = gSaveData.main.soundMode; if (gSoundMode >= NUM_SOUND_MODES) { gSoundMode = SOUND_MONO; } } -#ifdef NON_MATCHING -// nonmatching: off in the copy time trials loop -// check integrity of time trial data? void func_800B4A9C(s32 course) { + OnlyBestTimeTrialRecords *test; CourseTimeTrialRecords *sp24; s32 i; if ((func_800B4EB4(0, course) & 0xFFFFF) < 0x927C0U) { - D_8018EB90.allCourseTimeTrialRecords + gSaveData.allCourseTimeTrialRecords .cupRecords[course / 4] .courseRecords[course % 4] .unknownBytes[0] = 1; } - sp24 = &D_8018EB90.allCourseTimeTrialRecords.cupRecords[course / 4].courseRecords[course % 4]; + sp24 = &gSaveData.allCourseTimeTrialRecords.cupRecords[course / 4].courseRecords[course % 4]; func_800B4FB0(course); if(sp24) {} - if (func_800B4874(course) != sp24->unknownBytes[5]) { + if (sp24->unknownBytes[5] != func_800B4874(course)) { func_800B4728(course); if (func_800B58C4(course) == 0) { s32 a3 = 0; + test = &gSaveData.onlyBestTimeTrialRecords[course / 8]; for (i = 0; i < 3; i++) { - sp24->records[0][i] = D_8018EB90.onlyBestTimeTrialRecords[course / 8].bestThreelaps[course % 8][i]; - sp24->records[5][i] = D_8018EB90.onlyBestTimeTrialRecords[course / 8].bestSinglelaps[course % 8][i]; + sp24->records[TIME_TRIAL_3LAP_RECORD_1][i] = test->bestThreelaps[course % 8][i]; + sp24->records[TIME_TRIAL_1LAP_RECORD][i] = test->bestSinglelaps[course % 8][i]; - if ((D_8018EB90.onlyBestTimeTrialRecords[course / 8].bestThreelaps[course % 8][i] & 0xFF) == D_800F2E60[i]) { - if ((D_8018EB90.onlyBestTimeTrialRecords[course / 8].bestSinglelaps[course % 8][i] & 0xFF) == D_800F2E60[i]) { + // This is checking (in a roundabout way) if the given record + // is the default value of 0x927C0 + if (sp24->records[TIME_TRIAL_3LAP_RECORD_1][i] == D_800F2E60[i]) { + if (sp24->records[TIME_TRIAL_1LAP_RECORD][i] == D_800F2E60[i]) { a3 += 1; } } @@ -201,39 +202,23 @@ void func_800B4A9C(s32 course) { func_800B559C(course); } } -#else -GLOBAL_ASM("asm/non_matchings/menus/func_800B4A9C.s") -#endif void validate_save_data(void) { - if (D_8018ED16 != (compute_save_data_checksum_1()) || (D_8018ED17 != compute_save_data_checksum_2())) { + s32 cup_index; + Stuff *main = &gSaveData.main; + Stuff *backup = &gSaveData.backup; + if (main->checksum[1] != (compute_save_data_checksum_1()) || (main->checksum[2] != compute_save_data_checksum_2())) { reset_save_data_grand_prix_points_and_sound_mode(); if (validate_save_data_checksum_backup() == 0) { - D_8018ED10.grandPrixPointsMushroomCup = D_8018ED88.grandPrixPointsMushroomCup; - if ((D_8018ED16 && D_8018ED16) && D_8018ED16) - { + for (cup_index = 0; cup_index < 4; cup_index++) { + main->grandPrixPoints[cup_index] = backup->grandPrixPoints[cup_index]; } - D_8018ED11 = D_8018ED89; - if ((D_8018ED16 && D_8018ED16) && D_8018ED16) - { - } - - D_8018ED12 = D_8018ED8A; - if ((D_8018ED16 && D_8018ED16) && D_8018ED16) - { - } - - D_8018ED13 = D_8018ED8B; - if ((D_8018ED16 && D_8018ED16) && D_8018ED16) - { - } - - gSaveDataSoundMode = gSaveDataSoundModeBackup; - D_8018ED16 = compute_save_data_checksum_backup_1(); - D_8018ED17 = compute_save_data_checksum_backup_2(); - osEepromLongWrite(&gSIEventMesgQueue, EEPROM_ADDR(&D_8018ED10), (u8 *)&D_8018ED10, 8); + main->soundMode = backup->soundMode; + main->checksum[1] = compute_save_data_checksum_backup_1(); + main->checksum[2] = compute_save_data_checksum_backup_2(); + osEepromLongWrite(&gSIEventMesgQueue, EEPROM_ADDR(main), main, sizeof(Stuff)); } update_save_data_backup(); return; @@ -271,7 +256,7 @@ u32 func_800B4DF4(u8 *arr) { // Get a time trial record, infer course index s32 func_800B4E24(s32 recordIndex) { return func_800B4DF4( - D_8018EB90.allCourseTimeTrialRecords \ + gSaveData.allCourseTimeTrialRecords \ .cupRecords[(((gCupSelection * 4) + gCupCourseSelection) / 4)] \ .courseRecords[(((gCupSelection * 4) + gCupCourseSelection) % 4)] \ .records[recordIndex] @@ -281,7 +266,7 @@ s32 func_800B4E24(s32 recordIndex) { // Get a time trial record, but take the course index as an argument u32 func_800B4EB4(s32 recordIndex, s32 courseIndex) { return func_800B4DF4( - D_8018EB90.allCourseTimeTrialRecords \ + gSaveData.allCourseTimeTrialRecords \ .cupRecords[(courseIndex / 4)] \ .courseRecords[(courseIndex % 4)] \ .records[recordIndex] @@ -291,7 +276,7 @@ u32 func_800B4EB4(s32 recordIndex, s32 courseIndex) { // Get Best Lap record of the inferred course index s32 func_800B4F2C(void) { return func_800B4DF4( - D_8018EB90.allCourseTimeTrialRecords \ + gSaveData.allCourseTimeTrialRecords \ .cupRecords[(((gCupSelection * 4) + gCupCourseSelection) / 4)] \ .courseRecords[(((gCupSelection * 4) + gCupCourseSelection) % 4)] \ .records[TIME_TRIAL_1LAP_RECORD] @@ -301,67 +286,56 @@ s32 func_800B4F2C(void) { // Get the best single lap time record of the given course index s32 func_800B4FB0(s32 courseIndex) { return func_800B4DF4( - D_8018EB90.allCourseTimeTrialRecords \ + gSaveData.allCourseTimeTrialRecords \ .cupRecords[(courseIndex / 4)] \ .courseRecords[(courseIndex % 4)] \ .records[TIME_TRIAL_1LAP_RECORD] ); } -#ifdef NON_MATCHING -// nonmatching: the loops s32 func_800B5020(u32 time, s32 charId) { + s32 stackPadding[3]; s32 course; // sp30 + s32 i; + s32 j; CourseTimeTrialRecords *tt; - s32 i, j; course = gCupSelection * 4 + gCupCourseSelection; - tt = &D_8018EB90.allCourseTimeTrialRecords + tt = &gSaveData.allCourseTimeTrialRecords .cupRecords[course / 4] .courseRecords[course % 4]; - for (i = 0; i < 5; i++) { - // L800B50C4 + i = 0; + for (; i < 5; i++) { if (time < (func_800B4DF4(tt->records[i]) & 0x000FFFFF)) { break; } } - // L800B50EC + + // `time` is: + // Not less than any records + // Only less than the 1-lap record + // Either way, we aren't going to update any records if (i >= 5) { return -1; } - // L800B50FC - if (i < 4) { - //s32 idx = -((4 - i) & 3); - for (j = 4; j > (4 - i); j--) { - tt->records[j][0] = tt->records[j - 1][0]; - tt->records[j][1] = tt->records[j - 1][1]; - tt->records[j][2] = tt->records[j - 1][2]; - } - // L800B5154 - for ( ; j != i; j--) { - tt->records[j][0] = tt->records[j - 1][0]; - tt->records[j][1] = tt->records[j - 1][1]; - tt->records[j][2] = tt->records[j - 1][2]; - } + for (j = TIME_TRIAL_3LAP_RECORD_5; j > i; j--) { + tt->records[j][0] = tt->records[j - 1][0]; + tt->records[j][1] = tt->records[j - 1][1]; + tt->records[j][2] = tt->records[j - 1][2]; } - // L800B51D0 + populate_time_trial_record(tt->records[i], time, charId); tt->unknownBytes[0] = 1; func_800B45E0(course); return i; } -#else -GLOBAL_ASM("asm/non_matchings/menus/func_800B5020.s") -#endif #ifdef MIPS_TO_C -//generated by mips_to_c commit 792017ad9d422c2467bd42686f383a5c41f41c75 -void populate_time_trial_record(u8 *, u32, s32, s32); /* extern */ +//generated by m2c commit eefca95b040d7ee0c617bc58f9ac6cd1cf7bce87 on Aug-23-2023 extern ? D_8018CA74; -s8 gCharacterSelections[4]; /* unable to generate initializer; const */ s32 func_800B5218(void) { s32 sp38; @@ -369,70 +343,60 @@ s32 func_800B5218(void) { s32 sp24; u8 *sp20; struct_8018CA70_entry *sp18; - ? *temp_a1; - s32 temp_a0; - s32 temp_v0; + ? *var_a1; s32 temp_v1; - u32 temp_a1_2; - u8 *temp_v0_2; - ? *phi_a1; - struct_8018CA70_entry *phi_a2; - s32 phi_v0; - struct_8018CA70_entry *phi_a2_2; - s32 phi_a3; - s32 phi_v0_2; - s32 phi_a3_2; + s32 var_a3; + s32 var_v0; + s32 var_v0_2; + struct_8018CA70_entry *var_a2; + u32 temp_a0; + u32 temp_a1; + u8 *temp_v0; sp38 = (gCupSelection * 4) + gCupCourseSelection; + var_a3 = 1; + var_a2 = D_8018CA70; + var_a1 = &D_8018CA74; + var_v0_2 = 1; sp28 = (s32) *gCharacterSelections; - phi_a1 = &D_8018CA74; - phi_a2 = D_8018CA70; - phi_v0 = 1; - phi_a3_2 = 1; do { - temp_v1 = phi_a1->unk20; - temp_a0 = phi_a2->lap1Duration; - phi_a2_2 = phi_a2; - phi_a3 = phi_a3_2; - if (temp_v1 < temp_a0) { - phi_a2_2 = (phi_v0 * 4) + D_8018CA70; - phi_a3 = 1 << phi_v0; + temp_v1 = var_a1->unk20; + temp_a0 = var_a2->lapDurations[0]; + if (temp_v1 < (s32) temp_a0) { + var_a3 = 1 << var_v0_2; + var_a2 = (var_v0_2 * 4) + D_8018CA70; } else if (temp_a0 == temp_v1) { - phi_a3 = phi_a3_2 | (1 << phi_v0); + var_a3 |= 1 << var_v0_2; } - temp_v0 = phi_v0 + 1; - temp_a1 = phi_a1 + 4; - phi_a1 = temp_a1; - phi_a2 = phi_a2_2; - phi_v0 = temp_v0; - phi_a3_2 = phi_a3; - } while (temp_v0 != 3); - sp18 = phi_a2_2; - sp24 = phi_a3; - temp_a1_2 = phi_a2_2->lap1Duration; - phi_v0_2 = 0; - if (temp_a1_2 < (u32) (func_800B4F2C(temp_a0, temp_a1, phi_a2_2, phi_a3) & 0xFFFFF)) { - temp_v0_2 = &D_8018EB90.allCourseTimeTrialRecords.cupRecords[sp38].courseRecords[sp38].records[0]; - sp20 = temp_v0_2; - sp24 = phi_a3; - populate_time_trial_record(temp_v0_2 + 0xF, temp_a1_2, sp28, phi_a3); - temp_v0_2->unk12 = 1; + var_v0_2 += 1; + var_a1 += 4; + } while (var_v0_2 != 3); + sp18 = var_a2; + sp24 = var_a3; + temp_a1 = var_a2->lapDurations[0]; + var_v0 = 0; + if (temp_a1 < (u32) (func_800B4F2C((s32) temp_a0, var_a1, var_a2, var_a3) & 0xFFFFF)) { + temp_v0 = &gSaveData.allCourseTimeTrialRecords.cupRecords[0].courseRecords[0].records[0][((sp38 / 4) * 0x60) + ((sp38 % 4) * 0x18)]; + sp20 = temp_v0; + sp24 = var_a3; + populate_time_trial_record(temp_v0 + 0xF, temp_a1, sp28); + temp_v0->unk12 = 1; func_800B45E0(sp38); - phi_v0_2 = sp24; + var_v0 = sp24; } - return phi_v0_2; + return var_v0; } #else GLOBAL_ASM("asm/non_matchings/menus/func_800B5218.s") #endif void func_800B536C(s32 arg0) { - u8* points; + u8 *points; u8 tmp; s32 tmp2; if (arg0 >= 0) { - points = &D_8018EB90.grandPrixPoints[gCCSelection]; + points = &gSaveData.main.grandPrixPoints[gCCSelection]; tmp = func_800B54EC(gCupSelection, *points); tmp2 = 3 - arg0; @@ -454,7 +418,7 @@ void func_800B5404(s32 arg0, s32 arg1) if (arg0 >= 0) { temp2 = arg1 / 4; - points = &D_8018EB90.grandPrixPoints[arg1 % 4]; + points = &gSaveData.main.grandPrixPoints[arg1 % 4]; temp = func_800B54EC(temp2, *points); if ((arg0 < 3) && (temp < (temp_a0 = 3 - arg0))) { @@ -468,7 +432,7 @@ void func_800B5404(s32 arg0, s32 arg1) // Get Grand Prix points for a given cup and CC mode u8 func_800B54C0(s32 cup, s32 cc_mode) { - return func_800B54EC(cup, D_8018ED10.grandPrixPointsArray[cc_mode]); + return func_800B54EC(cup, gSaveData.main.grandPrixPoints[cc_mode]); } // Get Grand Prix points scored for a given cup @@ -497,7 +461,7 @@ u8 func_800B5508(s32 cup, s32 ccGrandPrixPoints, s32 points_scored) { // Check if all 4 cups have gold cups scored // for a given CC mode s32 func_800B5530(s32 cc_mode) { - if (D_8018ED10.grandPrixPointsArray[cc_mode] == 0xFF) { + if (gSaveData.main.grandPrixPoints[cc_mode] == 0xFF) { return 1; } return 0; @@ -514,18 +478,16 @@ s32 func_800B557C(void) { } #ifdef MIPS_TO_C -//generated by m2c commit 8267401fa4ef7a38942dcca43353cc1bcc6efabc -extern u8 D_800F2E60; - +//generated by m2c commit eefca95b040d7ee0c617bc58f9ac6cd1cf7bce87 on Aug-23-2023 void func_800B559C(s32 course) { CourseTimeTrialRecords *temp_a2; + OnlyBestTimeTrialRecords *temp_s2; OnlyBestTimeTrialRecords *temp_s2_2; s32 temp_s6; s32 var_s1; s32 var_v0; s32 var_v0_2; u8 *temp_a0; - u8 *temp_s2; u8 *var_a0; u8 temp_t3; u8 temp_t9; @@ -535,10 +497,10 @@ void func_800B559C(s32 course) { temp_s6 = course / 8; var_s1 = temp_s6 * 8; if (var_s1 < (var_s1 + 8)) { - temp_s2 = &D_8018EB90.allCourseTimeTrialRecords.cupRecords[0].courseRecords[0].records[0][(temp_s6 * 0x38) + 0x188]; + temp_s2 = &gSaveData.onlyBestTimeTrialRecords[temp_s6]; do { - var_a0 = &D_800F2E60; - temp_a2 = &D_8018EB90.allCourseTimeTrialRecords.cupRecords[var_s1 / 4].courseRecords[var_s1 % 4]; + var_a0 = D_800F2E60; + temp_a2 = &gSaveData.allCourseTimeTrialRecords.cupRecords[var_s1 / 4].courseRecords[var_s1 % 4]; var_v0 = 0; if (temp_a2->unknownBytes[5] != func_800B4874(var_s1)) { do { @@ -563,66 +525,62 @@ void func_800B559C(s32 course) { var_s1 += 1; } while (var_s1 < ((temp_s6 * 8) + 8)); } - temp_s2_2 = &D_8018EB90.onlyBestTimeTrialRecords[temp_s6]; + temp_s2_2 = &gSaveData.onlyBestTimeTrialRecords[temp_s6]; temp_s2_2->unknownBytes[6] = func_800B578C(temp_s6); temp_s2_2->unknownBytes[7] = func_800B5888(temp_s6); - osEepromLongWrite(&gSIEventMesgQueue, ((u32) (temp_s2_2 - &D_8018EB90) >> 3) & 0xFF, temp_s2_2->bestThreelaps[0], 0x00000038); + osEepromLongWrite(&gSIEventMesgQueue, ((u32) (temp_s2_2 - &gSaveData) >> 3) & 0xFF, temp_s2_2->bestThreelaps[0], 0x00000038); } #else GLOBAL_ASM("asm/non_matchings/menus/func_800B559C.s") #endif #ifdef MIPS_TO_C -//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307 -extern SaveData D_8018EB90; - +//generated by m2c commit eefca95b040d7ee0c617bc58f9ac6cd1cf7bce87 on Aug-23-2023 s32 func_800B578C(s32 arg0) { - s32 temp_a0; + OnlyBestTimeTrialRecords *var_a2; + OnlyBestTimeTrialRecords *var_t0; s32 temp_a1; + s32 temp_lo; s32 temp_v1; - u8 *temp_a2; - void *temp_a3; - s32 phi_a0; - s32 phi_v0; - s32 phi_v1; - void *phi_a3; - s32 phi_v1_2; - u8 *phi_t0; - u8 *phi_a2; + s32 var_a0; + s32 var_v0; + s32 var_v1; + u8 *var_a3; + u8 temp_t5; + u8 temp_t9; - temp_a2 = (arg0 * 0x38) + 0x188 + &D_8018EB90; - phi_v0 = 0; - phi_v1_2 = 0; - phi_t0 = temp_a2; - phi_a2 = temp_a2; + var_a2 = &gSaveData.onlyBestTimeTrialRecords[arg0]; + var_v1 = 0; + var_t0 = var_a2; + var_v0 = 0; do { - temp_a1 = phi_v0 + 1; - phi_a0 = 1; - phi_v0 = temp_a1; - phi_v1 = phi_v1_2 + ((*phi_t0 + 1) * temp_a1); - phi_a3 = phi_a2 + 1; - phi_a2 += 0x11; + temp_a1 = var_v0 + 1; + var_a3 = &var_a2->bestThreelaps[0][1]; + temp_lo = (var_t0->bestThreelaps[0][0] + 1) * temp_a1; + var_a2 += 0x11; + var_v0 = temp_a1; + var_a0 = 1; + var_v1 += temp_lo; loop_2: - temp_a3 = phi_a3 + 4; - temp_a0 = phi_a0 + 4; - temp_v1 = phi_v1 + ((phi_a3->unk0 + 1) * temp_a1) + phi_a0 + ((phi_a3->unk1 + 1) * temp_a1) + phi_a0 + 1 + ((temp_a3->unk-2 + 1) * temp_a1) + phi_a0 + 2 + ((temp_a3->unk-1 + 1) * temp_a1) + phi_a0 + 3; - phi_a0 = temp_a0; - phi_v1 = temp_v1; - phi_a3 = temp_a3; - phi_v1_2 = temp_v1; - if (temp_a0 != 0x11) { + temp_t5 = var_a3->unk0; + temp_t9 = var_a3->unk1; + var_a3 += 4; + temp_v1 = var_v1 + ((temp_t5 + 1) * temp_a1) + var_a0 + ((temp_t9 + 1) * temp_a1) + var_a0 + 1 + ((var_a3->unk-2 + 1) * temp_a1) + var_a0 + 2 + ((var_a3->unk-1 + 1) * temp_a1) + var_a0; + var_a0 += 4; + var_v1 = temp_v1 + 3; + if (var_a0 != 0x11) { goto loop_2; } - phi_t0 += 0x11; + var_t0 += 0x11; } while (temp_a1 != 3); - return (temp_v1 % 0x100) & 0xFF; + return (var_v1 % 256) & 0xFF; } #else GLOBAL_ASM("asm/non_matchings/menus/func_800B578C.s") #endif s32 func_800B5888(s32 arg0) { - s32 tmp = ((*(&D_8018ED4E + (arg0 * sizeof(OnlyBestTimeTrialRecords))) + 90)); + s32 tmp = gSaveData.onlyBestTimeTrialRecords[arg0].unknownBytes[6] + 90; return (tmp % 256) & 0xFF; } @@ -633,7 +591,7 @@ s32 func_800B58C4(s32 arg0) UNUSED s32 pad2; UNUSED s32 pad3; - temp_v1 = &D_8018EB90.onlyBestTimeTrialRecords[arg0 / 8]; + temp_v1 = &gSaveData.onlyBestTimeTrialRecords[arg0 / 8]; if ((temp_v1->unknownBytes[6] != (func_800B578C(arg0 / 8) ^ 0)) || (temp_v1->unknownBytes[7] != (func_800B5888(arg0 / 8) ^ 0))) { return 1; @@ -642,59 +600,40 @@ s32 func_800B58C4(s32 arg0) return 0; } -#ifdef MIPS_TO_C -//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307 -s8 compute_save_data_checksum_backup_1(); // extern -s8 compute_save_data_checksum_backup_2(); // extern -extern SaveData D_8018EB90; -extern union GrandPrixPointsUnion D_8018ED10; -extern u8 D_8018ED11; -extern u8 D_8018ED12; -extern u8 D_8018ED13; -extern u8 gSaveDataSoundMode; -extern union GrandPrixPointsUnion D_8018ED88; -extern u8 D_8018ED89; -extern u8 D_8018ED8A; -extern u8 D_8018ED8B; -extern u8 gSaveDataSoundModeBackup; -extern s8 D_8018ED8E; -extern s8 D_8018ED8F; -extern OSMesgQueue gSIEventMesgQueue; - void update_save_data_backup(void) { - D_8018ED88.grandPrixPointsMushroomCup = D_8018ED10.grandPrixPointsMushroomCup; - D_8018ED89 = D_8018ED11; - D_8018ED8A = D_8018ED12; - D_8018ED8B = D_8018ED13; - gSaveDataSoundModeBackup = gSaveDataSoundMode; - D_8018ED8E = compute_save_data_checksum_backup_1(); - D_8018ED8F = compute_save_data_checksum_backup_2(); - osEepromLongWrite(&gSIEventMesgQueue, ((&D_8018ED88 - &D_8018EB90) >> 3) & 0xFF, &D_8018ED88, 8); + s32 cup_index; + Stuff *main = &gSaveData.main; + Stuff *backup = &gSaveData.backup; + for (cup_index = 0; cup_index < 4; cup_index++) { + backup->grandPrixPoints[cup_index] = main->grandPrixPoints[cup_index]; + } + backup->soundMode = main->soundMode; + backup->checksum[1] = compute_save_data_checksum_backup_1(); + backup->checksum[2] = compute_save_data_checksum_backup_2(); + osEepromLongWrite(&gSIEventMesgQueue, EEPROM_ADDR(backup), backup, sizeof(Stuff)); } -#else -GLOBAL_ASM("asm/non_matchings/menus/func_800B5948.s") -#endif u8 compute_save_data_checksum_backup_1(void) { - u8 *raw = (void *)&D_8018ED88; + u8 *backupGrandPrixPoints = gSaveData.backup.grandPrixPoints; s32 i; s32 crc = 0; for (i = 0; i < 5; i++) { - crc += ((raw[i] + 1) * (i + 1)) + i; + crc += ((backupGrandPrixPoints[i] + 1) * (i + 1)) + i; } return crc % 0x100; } u8 compute_save_data_checksum_backup_2(void) { - s32 tmp = D_8018ED8E + 90; + s32 tmp = gSaveData.backup.checksum[1] + 90; return (tmp % 256); } s32 validate_save_data_checksum_backup(void) { - if (D_8018ED8E != compute_save_data_checksum_backup_1() || D_8018ED8F != compute_save_data_checksum_backup_2()) { + u8 *backupChecksum = gSaveData.backup.checksum; + if (backupChecksum[1] != compute_save_data_checksum_backup_1() || backupChecksum[2] != compute_save_data_checksum_backup_2()) { return 1; } diff --git a/src/code_800B45E0.h b/src/code_800B45E0.h index 82c55069f..dc74309f2 100644 --- a/src/code_800B45E0.h +++ b/src/code_800B45E0.h @@ -12,29 +12,22 @@ #define CONTROLLER_3 2 #define CONTROLLER_4 3 -#define PFS_NO_ERROR 0 // controller pak no error return +#define PFS_NO_ERROR 0 // controller pak no error return #define PFS_NO_PAK_INSERTED 1 // no pak pressent or wrong device inserted into the controller -#define PFS_PAK_BAD_READ 2 // controller pak error while data transfer -#define PFS_FILE_OVERFLOW 4 // too many files written to in the controller pak -#define PFS_INVALID_DATA -1 // bad arguments, game note does not exist, osPfsInit was not called. +#define PFS_PAK_BAD_READ 2 // controller pak error while data transfer +#define PFS_FILE_OVERFLOW 4 // too many files written to in the controller pak +#define PFS_INVALID_DATA -1 // bad arguments, game note does not exist, osPfsInit was not called. // controller pak test functions -#define PFS_NUM_FILES_ERROR -2 +#define PFS_NUM_FILES_ERROR -2 #define PFS_FREE_BLOCKS_ERROR -3 -#define PFS_PAK_STATE_OK -4 +#define PFS_PAK_STATE_OK -4 #define NO_PAK 0 #define PAK 1 #define PAK_NOT_INSERTED -1 -union GrandPrixPointsUnion -{ - u8 grandPrixPointsArray[4]; - u8 grandPrixPointsMushroomCup; -}; - /* Function Prototypes */ -void load_save_data(void); void func_800B45E0(s32); void write_save_data_grand_prix_points_and_sound_mode(); void func_800B46D0(void); @@ -44,13 +37,16 @@ u8 func_800B4874(s32); s32 func_800B639C(s32); u8 compute_save_data_checksum_1(); u8 compute_save_data_checksum_2(); -void func_800B4A10(); +void load_save_data(void); void func_800B4A9C(s32); void validate_save_data(void); +void populate_time_trial_record(u8 *timeTrialRecord, u32 time, s32 characterId); +u32 func_800B4DF4(u8*); s32 func_800B4E24(s32); u32 func_800B4EB4(s32, s32); s32 func_800B4F2C(); s32 func_800B4FB0(s32); +s32 func_800B5020(u32, s32); void func_800B5404(s32, s32); u8 func_800B54C0(s32, s32); u8 func_800B54EC(s32, s32); @@ -61,7 +57,8 @@ s32 func_800B555C(); s32 func_800B557C(); void func_800B559C(s32); s32 func_800B578C(s32); -s32 func_800B5888(s32); +s32 func_800B5888(s32); +s32 func_800B58C4(s32); void update_save_data_backup(); u8 compute_save_data_checksum_backup_1(void); u8 compute_save_data_checksum_backup_2(void); @@ -79,7 +76,7 @@ s32 func_800B65F4(s32, s32); void func_800B6708(void); void func_800B6798(void); u8 func_800B6828(s32); -u8 func_800B68F4(s32); +u8 func_800B68F4(s32); s32 func_800B69BC(s32); s32 func_800B6A68(); @@ -93,11 +90,6 @@ extern u32 gGameCode; // osPfs gamecode extern s8 gControllerPak1State; // Current state of Controller Pak 1 extern struct_8018EE10_entry D_8018EE10[]; extern struct_8018EE10_entry *D_8018D9C0; -extern u8 D_8018ED16; // D_8018EB90.checksum[1] -extern u8 D_8018ED17; // D_8018EB90.checksum[2] -extern u8 D_8018ED4E; // D_8018EB90.onlyBestTimeTrialRecords[0].unknownBytes[6] -extern union GrandPrixPointsUnion D_8018ED10; // Direct reference to the grandPrixPoints section of save data -extern union GrandPrixPointsUnion D_8018ED88; // D_8018EB90.grandPrixPointsBackup[0] extern s8 sControllerPak2State; // Current state of the Controller Pak 2 extern const u8 D_800F2E60[]; @@ -115,16 +107,6 @@ extern s32 gControllerPak1NumFilesUsed; extern s32 gControllerPak1MaxWriteableFiles; extern s32 gControllerPak1FileNote; // osPfs file_no receiver/out param extern s32 gControllerPak2FileNote; -extern SaveData D_8018EB90; -extern u8 D_8018ED11; -extern u8 D_8018ED12; -extern u8 D_8018ED13; -extern u8 gSaveDataSoundMode; // D_8018ED14 -extern u8 D_8018ED89; -extern u8 D_8018ED8A; -extern u8 D_8018ED8B; -extern u8 D_8018ED8E; // D_8018EB90.checksumBackup[1] -extern u8 D_8018ED8F; // D_8018EB90.checksumBackup[2] extern s8 D_8018EDE5; extern s8 D_8018EDE6; extern s8 D_8018EDE7; diff --git a/src/menus.c b/src/menus.c index ba13d65d1..c30dc64d4 100644 --- a/src/menus.c +++ b/src/menus.c @@ -14,6 +14,7 @@ #include "code_800B45E0.h" #include "main.h" #include "staff_ghosts.h" +#include "save_data.h" #include /** Externs to be put into headers **/ @@ -268,7 +269,7 @@ void options_menu_act(struct Controller *controller, u16 arg1) { sp38->unk8 = -1; } if (sp2C && gSoundMode != sp38->unk4) { - gSaveDataSoundMode = gSoundMode; + gSaveData.main.soundMode = gSoundMode; write_save_data_grand_prix_points_and_sound_mode(); update_save_data_backup(); sp38->unk4 = gSoundMode; @@ -277,7 +278,7 @@ void options_menu_act(struct Controller *controller, u16 arg1) { func_8009E280(); play_sound2(SOUND_MENU_GO_BACK); if (gSoundMode != sp38->unk4) { - gSaveDataSoundMode = gSoundMode; + gSaveData.main.soundMode = gSoundMode; write_save_data_grand_prix_points_and_sound_mode(); update_save_data_backup(); sp38->unk4 = gSoundMode; @@ -705,7 +706,7 @@ void course_data_menu_act(struct Controller *controller, UNUSED u16 arg1) { } sp28 = find_8018D9E0_entry_dupe(0xE8); - sp24 = &D_8018EB90.allCourseTimeTrialRecords + sp24 = &gSaveData.allCourseTimeTrialRecords .cupRecords[gTimeTrialDataCourseIndex / 4] .courseRecords[gTimeTrialDataCourseIndex % 4]; if (gCourseRecordsMenuSelection == 2 && func_800B639C(gTimeTrialDataCourseIndex) < 0) { @@ -1131,7 +1132,7 @@ void splash_menu_act(struct Controller *controller, u16 arg1) { } play_sound2(SOUND_MENU_CURSOR_MOVE); func_800B44BC(); - gSaveDataSoundMode = gSoundMode; + gSaveData.main.soundMode = gSoundMode; write_save_data_grand_prix_points_and_sound_mode(); update_save_data_backup(); } @@ -1142,7 +1143,7 @@ void splash_menu_act(struct Controller *controller, u16 arg1) { } play_sound2(SOUND_MENU_CURSOR_MOVE); func_800B44BC(); - gSaveDataSoundMode = gSoundMode; + gSaveData.main.soundMode = gSoundMode; write_save_data_grand_prix_points_and_sound_mode(); } if (btnAndStick & U_JPAD) {