diff --git a/asm/non_matchings/camera/func_8006A1C4.s b/asm/non_matchings/camera/func_8006A1C4.s deleted file mode 100644 index 33386841..00000000 --- a/asm/non_matchings/camera/func_8006A1C4.s +++ /dev/null @@ -1,173 +0,0 @@ -glabel func_8006A1C4 -/* 06ADC4 8006A1C4 27BDFFA8 */ addiu $sp, $sp, -0x58 -/* 06ADC8 8006A1C8 AFB20020 */ sw $s2, 0x20($sp) -/* 06ADCC 8006A1CC 00809025 */ move $s2, $a0 -/* 06ADD0 8006A1D0 AFBF0024 */ sw $ra, 0x24($sp) -/* 06ADD4 8006A1D4 AFA5005C */ sw $a1, 0x5c($sp) -/* 06ADD8 8006A1D8 3C048012 */ lui $a0, %hi(sSIMesgQueue) # $a0, 0x8012 -/* 06ADDC 8006A1DC AFB1001C */ sw $s1, 0x1c($sp) -/* 06ADE0 8006A1E0 AFB00018 */ sw $s0, 0x18($sp) -/* 06ADE4 8006A1E4 248410E0 */ addiu $a0, %lo(sSIMesgQueue) # addiu $a0, $a0, 0x10e0 -/* 06ADE8 8006A1E8 27A50050 */ addiu $a1, $sp, 0x50 -/* 06ADEC 8006A1EC 0C0322EC */ jal osRecvMesg -/* 06ADF0 8006A1F0 00003025 */ move $a2, $zero -/* 06ADF4 8006A1F4 1440005D */ bnez $v0, .L8006A36C -/* 06ADF8 8006A1F8 3C068012 */ lui $a2, %hi(sControllerData+24) # $a2, 0x8012 -/* 06ADFC 8006A1FC 3C028012 */ lui $v0, %hi(sControllerData) # $v0, 0x8012 -/* 06AE00 8006A200 3C038012 */ lui $v1, %hi(sControllerData+24) # $v1, 0x8012 -/* 06AE04 8006A204 24631128 */ addiu $v1, %lo(sControllerData+24) # addiu $v1, $v1, 0x1128 -/* 06AE08 8006A208 24421110 */ addiu $v0, %lo(sControllerData) # addiu $v0, $v0, 0x1110 -/* 06AE0C 8006A20C 24C61128 */ addiu $a2, %lo(sControllerData+24) # addiu $a2, $a2, 0x1128 -.L8006A210: -/* 06AE10 8006A210 88410000 */ lwl $at, ($v0) -/* 06AE14 8006A214 98410003 */ lwr $at, 3($v0) -/* 06AE18 8006A218 24420006 */ addiu $v0, $v0, 6 -/* 06AE1C 8006A21C A8C10000 */ swl $at, ($a2) -/* 06AE20 8006A220 B8C10003 */ swr $at, 3($a2) -/* 06AE24 8006A224 9441FFFE */ lhu $at, -2($v0) -/* 06AE28 8006A228 24C60006 */ addiu $a2, $a2, 6 -/* 06AE2C 8006A22C A4C1FFFE */ sh $at, -2($a2) -/* 06AE30 8006A230 0043082B */ sltu $at, $v0, $v1 -/* 06AE34 8006A234 1420FFF6 */ bnez $at, .L8006A210 -/* 06AE38 8006A238 00000000 */ nop -/* 06AE3C 8006A23C 3C048012 */ lui $a0, %hi(sControllerData) # $a0, 0x8012 -/* 06AE40 8006A240 0C033429 */ jal osContGetReadData -/* 06AE44 8006A244 24841110 */ addiu $a0, %lo(sControllerData) # addiu $a0, $a0, 0x1110 -/* 06AE48 8006A248 12400043 */ beqz $s2, .L8006A358 -/* 06AE4C 8006A24C 8FA4005C */ lw $a0, 0x5c($sp) -/* 06AE50 8006A250 0C01BAA4 */ jal get_settings -/* 06AE54 8006A254 00000000 */ nop -/* 06AE58 8006A258 32430003 */ andi $v1, $s2, 3 -/* 06AE5C 8006A25C 10600004 */ beqz $v1, .L8006A270 -/* 06AE60 8006A260 AFA2004C */ sw $v0, 0x4c($sp) -/* 06AE64 8006A264 00402025 */ move $a0, $v0 -/* 06AE68 8006A268 0C01D174 */ jal read_eeprom_data -/* 06AE6C 8006A26C 306500FF */ andi $a1, $v1, 0xff -.L8006A270: -/* 06AE70 8006A270 32580008 */ andi $t8, $s2, 8 -/* 06AE74 8006A274 1300000D */ beqz $t8, .L8006A2AC -/* 06AE78 8006A278 32590004 */ andi $t9, $s2, 4 -/* 06AE7C 8006A27C 0C027124 */ jal func_8009C490 -/* 06AE80 8006A280 00000000 */ nop -/* 06AE84 8006A284 00008025 */ move $s0, $zero -/* 06AE88 8006A288 00408825 */ move $s1, $v0 -.L8006A28C: -/* 06AE8C 8006A28C 8E250000 */ lw $a1, ($s1) -/* 06AE90 8006A290 0C01D081 */ jal func_80074204 -/* 06AE94 8006A294 02002025 */ move $a0, $s0 -/* 06AE98 8006A298 26100001 */ addiu $s0, $s0, 1 -/* 06AE9C 8006A29C 24010003 */ li $at, 3 -/* 06AEA0 8006A2A0 1601FFFA */ bne $s0, $at, .L8006A28C -/* 06AEA4 8006A2A4 26310004 */ addiu $s1, $s1, 4 -/* 06AEA8 8006A2A8 32590004 */ andi $t9, $s2, 4 -.L8006A2AC: -/* 06AEAC 8006A2AC 13200005 */ beqz $t9, .L8006A2C4 -/* 06AEB0 8006A2B0 00122203 */ sra $a0, $s2, 8 -/* 06AEB4 8006A2B4 308C0003 */ andi $t4, $a0, 3 -/* 06AEB8 8006A2B8 8FA5004C */ lw $a1, 0x4c($sp) -/* 06AEBC 8006A2BC 0C01D081 */ jal func_80074204 -/* 06AEC0 8006A2C0 01802025 */ move $a0, $t4 -.L8006A2C4: -/* 06AEC4 8006A2C4 32420030 */ andi $v0, $s2, 0x30 -/* 06AEC8 8006A2C8 00026903 */ sra $t5, $v0, 4 -/* 06AECC 8006A2CC 11A00005 */ beqz $t5, .L8006A2E4 -/* 06AED0 8006A2D0 324E0040 */ andi $t6, $s2, 0x40 -/* 06AED4 8006A2D4 8FA4004C */ lw $a0, 0x4c($sp) -/* 06AED8 8006A2D8 0C01D1BC */ jal write_eeprom_data -/* 06AEDC 8006A2DC 31A500FF */ andi $a1, $t5, 0xff -/* 06AEE0 8006A2E0 324E0040 */ andi $t6, $s2, 0x40 -.L8006A2E4: -/* 06AEE4 8006A2E4 11C00005 */ beqz $t6, .L8006A2FC -/* 06AEE8 8006A2E8 00122283 */ sra $a0, $s2, 0xa -/* 06AEEC 8006A2EC 308F0003 */ andi $t7, $a0, 3 -/* 06AEF0 8006A2F0 8FA5004C */ lw $a1, 0x4c($sp) -/* 06AEF4 8006A2F4 0C01D137 */ jal write_save_data -/* 06AEF8 8006A2F8 01E02025 */ move $a0, $t7 -.L8006A2FC: -/* 06AEFC 8006A2FC 32580080 */ andi $t8, $s2, 0x80 -/* 06AF00 8006A300 13000005 */ beqz $t8, .L8006A318 -/* 06AF04 8006A304 00122283 */ sra $a0, $s2, 0xa -/* 06AF08 8006A308 30990003 */ andi $t9, $a0, 3 -/* 06AF0C 8006A30C 8FA5004C */ lw $a1, 0x4c($sp) -/* 06AF10 8006A310 0C01D0C7 */ jal erase_save_file -/* 06AF14 8006A314 03202025 */ move $a0, $t9 -.L8006A318: -/* 06AF18 8006A318 324C0100 */ andi $t4, $s2, 0x100 -/* 06AF1C 8006A31C 11800006 */ beqz $t4, .L8006A338 -/* 06AF20 8006A320 324D0200 */ andi $t5, $s2, 0x200 -/* 06AF24 8006A324 0C027A9B */ jal get_eeprom_settings_pointer -/* 06AF28 8006A328 00000000 */ nop -/* 06AF2C 8006A32C 0C01D21D */ jal read_eeprom_settings -/* 06AF30 8006A330 00402025 */ move $a0, $v0 -/* 06AF34 8006A334 324D0200 */ andi $t5, $s2, 0x200 -.L8006A338: -/* 06AF38 8006A338 11A00006 */ beqz $t5, .L8006A354 -/* 06AF3C 8006A33C 00009025 */ move $s2, $zero -/* 06AF40 8006A340 0C027A9B */ jal get_eeprom_settings_pointer -/* 06AF44 8006A344 00000000 */ nop -/* 06AF48 8006A348 0C01D25F */ jal write_eeprom_settings -/* 06AF4C 8006A34C 00402025 */ move $a0, $v0 -/* 06AF50 8006A350 00009025 */ move $s2, $zero -.L8006A354: -/* 06AF54 8006A354 8FA4005C */ lw $a0, 0x5c($sp) -.L8006A358: -/* 06AF58 8006A358 0C01C9C6 */ jal rumble_controllers -/* 06AF5C 8006A35C 00000000 */ nop -/* 06AF60 8006A360 3C048012 */ lui $a0, %hi(sSIMesgQueue) # $a0, 0x8012 -/* 06AF64 8006A364 0C0333F8 */ jal osContStartReadData -/* 06AF68 8006A368 248410E0 */ addiu $a0, %lo(sSIMesgQueue) # addiu $a0, $a0, 0x10e0 -.L8006A36C: -/* 06AF6C 8006A36C 3C0A800E */ lui $t2, %hi(sNoControllerPluggedIn) # $t2, 0x800e -/* 06AF70 8006A370 3C09800E */ lui $t1, %hi(gButtonMask) # $t1, 0x800e -/* 06AF74 8006A374 3C068012 */ lui $a2, %hi(sControllerData+24) # $a2, 0x8012 -/* 06AF78 8006A378 3C028012 */ lui $v0, %hi(sControllerData) # $v0, 0x8012 -/* 06AF7C 8006A37C 3C088012 */ lui $t0, %hi(gControllerButtonsPressed) # $t0, 0x8012 -/* 06AF80 8006A380 3C078012 */ lui $a3, %hi(gControllerButtonsReleased) # $a3, 0x8012 -/* 06AF84 8006A384 3C0B8012 */ lui $t3, %hi(sPlayerID) # $t3, 0x8012 -/* 06AF88 8006A388 9529D304 */ lhu $t1, %lo(gButtonMask)($t1) -/* 06AF8C 8006A38C 8D4AD300 */ lw $t2, %lo(sNoControllerPluggedIn)($t2) -/* 06AF90 8006A390 256B1150 */ addiu $t3, %lo(sPlayerID) # addiu $t3, $t3, 0x1150 -/* 06AF94 8006A394 24E71148 */ addiu $a3, %lo(gControllerButtonsReleased) # addiu $a3, $a3, 0x1148 -/* 06AF98 8006A398 25081140 */ addiu $t0, %lo(gControllerButtonsPressed) # addiu $t0, $t0, 0x1140 -/* 06AF9C 8006A39C 24421110 */ addiu $v0, %lo(sControllerData) # addiu $v0, $v0, 0x1110 -/* 06AFA0 8006A3A0 24C61128 */ addiu $a2, %lo(sControllerData+24) # addiu $a2, $a2, 0x1128 -.L8006A3A4: -/* 06AFA4 8006A3A4 11400002 */ beqz $t2, .L8006A3B0 -/* 06AFA8 8006A3A8 00000000 */ nop -/* 06AFAC 8006A3AC A4400000 */ sh $zero, ($v0) -.L8006A3B0: -/* 06AFB0 8006A3B0 94430000 */ lhu $v1, ($v0) -/* 06AFB4 8006A3B4 94C40000 */ lhu $a0, ($a2) -/* 06AFB8 8006A3B8 00000000 */ nop -/* 06AFBC 8006A3BC 00642826 */ xor $a1, $v1, $a0 -/* 06AFC0 8006A3C0 00657024 */ and $t6, $v1, $a1 -/* 06AFC4 8006A3C4 0085C024 */ and $t8, $a0, $a1 -/* 06AFC8 8006A3C8 01C97824 */ and $t7, $t6, $t1 -/* 06AFCC 8006A3CC 0309C824 */ and $t9, $t8, $t1 -/* 06AFD0 8006A3D0 A50F0000 */ sh $t7, ($t0) -/* 06AFD4 8006A3D4 11400002 */ beqz $t2, .L8006A3E0 -/* 06AFD8 8006A3D8 A4F90000 */ sh $t9, ($a3) -/* 06AFDC 8006A3DC A4400006 */ sh $zero, 6($v0) -.L8006A3E0: -/* 06AFE0 8006A3E0 94430006 */ lhu $v1, 6($v0) -/* 06AFE4 8006A3E4 94C40006 */ lhu $a0, 6($a2) -/* 06AFE8 8006A3E8 24E70004 */ addiu $a3, $a3, 4 -/* 06AFEC 8006A3EC 00642826 */ xor $a1, $v1, $a0 -/* 06AFF0 8006A3F0 00656024 */ and $t4, $v1, $a1 -/* 06AFF4 8006A3F4 00857024 */ and $t6, $a0, $a1 -/* 06AFF8 8006A3F8 01C97824 */ and $t7, $t6, $t1 -/* 06AFFC 8006A3FC 01896824 */ and $t5, $t4, $t1 -/* 06B000 8006A400 A50D0002 */ sh $t5, 2($t0) -/* 06B004 8006A404 A4EFFFFE */ sh $t7, -2($a3) -/* 06B008 8006A408 24C6000C */ addiu $a2, $a2, 0xc -/* 06B00C 8006A40C 2442000C */ addiu $v0, $v0, 0xc -/* 06B010 8006A410 14EBFFE4 */ bne $a3, $t3, .L8006A3A4 -/* 06B014 8006A414 25080004 */ addiu $t0, $t0, 4 -/* 06B018 8006A418 8FBF0024 */ lw $ra, 0x24($sp) -/* 06B01C 8006A41C 02401025 */ move $v0, $s2 -/* 06B020 8006A420 8FB20020 */ lw $s2, 0x20($sp) -/* 06B024 8006A424 8FB00018 */ lw $s0, 0x18($sp) -/* 06B028 8006A428 8FB1001C */ lw $s1, 0x1c($sp) -/* 06B02C 8006A42C 03E00008 */ jr $ra -/* 06B030 8006A430 27BD0058 */ addiu $sp, $sp, 0x58 - diff --git a/asm/non_matchings/game/func_8006DCF8.s b/asm/non_matchings/game/func_8006DCF8.s index 48f071f2..711428e8 100644 --- a/asm/non_matchings/game/func_8006DCF8.s +++ b/asm/non_matchings/game/func_8006DCF8.s @@ -105,7 +105,7 @@ glabel func_8006DCF8 /* 06EA74 8006DE74 00000000 */ nop /* 06EA78 8006DE78 0C027068 */ jal get_save_file_index /* 06EA7C 8006DE7C 00000000 */ nop -/* 06EA80 8006DE80 0C01BB12 */ jal func_8006EC48 +/* 06EA80 8006DE80 0C01BB12 */ jal safe_mark_write_save_file /* 06EA84 8006DE84 00402025 */ move $a0, $v0 /* 06EA88 8006DE88 10000114 */ b .L8006E2DC /* 06EA8C 8006DE8C 8FBF0024 */ lw $ra, 0x24($sp) @@ -164,7 +164,7 @@ glabel L8006DF00 /* 06EB54 8006DF54 00000000 */ nop /* 06EB58 8006DF58 0C027068 */ jal get_save_file_index /* 06EB5C 8006DF5C 00000000 */ nop -/* 06EB60 8006DF60 0C01BB12 */ jal func_8006EC48 +/* 06EB60 8006DF60 0C01BB12 */ jal safe_mark_write_save_file /* 06EB64 8006DF64 00402025 */ move $a0, $v0 /* 06EB68 8006DF68 100000DC */ b .L8006E2DC /* 06EB6C 8006DF6C 8FBF0024 */ lw $ra, 0x24($sp) @@ -206,7 +206,7 @@ glabel L8006DF70 /* 06EBF0 8006DFF0 00000000 */ nop /* 06EBF4 8006DFF4 0C027068 */ jal get_save_file_index /* 06EBF8 8006DFF8 00000000 */ nop -/* 06EBFC 8006DFFC 0C01BB12 */ jal func_8006EC48 +/* 06EBFC 8006DFFC 0C01BB12 */ jal safe_mark_write_save_file /* 06EC00 8006E000 00402025 */ move $a0, $v0 /* 06EC04 8006E004 100000B5 */ b .L8006E2DC /* 06EC08 8006E008 8FBF0024 */ lw $ra, 0x24($sp) diff --git a/asm/non_matchings/menu/func_80086AFC.s b/asm/non_matchings/menu/func_80086AFC.s index 56b10a19..36199069 100644 --- a/asm/non_matchings/menu/func_80086AFC.s +++ b/asm/non_matchings/menu/func_80086AFC.s @@ -47,7 +47,7 @@ glabel L80086B54 /* 087798 80086B98 8FBF0014 */ lw $ra, 0x14($sp) .L80086B9C: /* 08779C 80086B9C 90640006 */ lbu $a0, 6($v1) -/* 0877A0 80086BA0 0C01BB06 */ jal func_8006EC18 +/* 0877A0 80086BA0 0C01BB06 */ jal force_mark_write_save_file /* 0877A4 80086BA4 AFA60028 */ sw $a2, 0x28($sp) /* 0877A8 80086BA8 3C098012 */ lui $t1, %hi(D_80126BE4) # $t1, 0x8012 /* 0877AC 80086BAC 25296BE4 */ addiu $t1, %lo(D_80126BE4) # addiu $t1, $t1, 0x6be4 @@ -111,7 +111,7 @@ glabel L80086B54 /* 087890 80086C90 AFA20038 */ sw $v0, 0x38($sp) .L80086C94: /* 087894 80086C94 90E40006 */ lbu $a0, 6($a3) -/* 087898 80086C98 0C01BB2B */ jal func_8006ECAC +/* 087898 80086C98 0C01BB2B */ jal mark_save_file_to_erase /* 08789C 80086C9C 00000000 */ nop /* 0878A0 80086CA0 3C198012 */ lui $t9, %hi(D_80126BD4) # $t9, 0x8012 /* 0878A4 80086CA4 8F396BD4 */ lw $t9, %lo(D_80126BD4)($t9) @@ -152,7 +152,7 @@ glabel L80086CDC .L80086D2C: /* 08792C 80086D2C 0C01B9DC */ jal func_8006E770 /* 087930 80086D30 24050003 */ li $a1, 3 -/* 087934 80086D34 0C01BAFF */ jal func_8006EBFC +/* 087934 80086D34 0C01BAFF */ jal mark_to_write_flap_and_course_times /* 087938 80086D38 00000000 */ nop /* 08793C 80086D3C 3C0500FF */ lui $a1, (0x00FFFFF0 >> 16) # lui $a1, 0xff /* 087940 80086D40 34A5FFF0 */ ori $a1, (0x00FFFFF0 & 0xFFFF) # ori $a1, $a1, 0xfff0 @@ -213,7 +213,7 @@ glabel L80086D54 /* 087A10 80086E10 000A7900 */ sll $t7, $t2, 4 /* 087A14 80086E14 016F6821 */ addu $t5, $t3, $t7 /* 087A18 80086E18 91A40006 */ lbu $a0, 6($t5) -/* 087A1C 80086E1C 0C01BB06 */ jal func_8006EC18 +/* 087A1C 80086E1C 0C01BB06 */ jal force_mark_write_save_file /* 087A20 80086E20 AFA60028 */ sw $a2, 0x28($sp) /* 087A24 80086E24 3C098012 */ lui $t1, %hi(D_80126BE4) # $t1, 0x8012 /* 087A28 80086E28 25296BE4 */ addiu $t1, %lo(D_80126BE4) # addiu $t1, $t1, 0x6be4 @@ -367,7 +367,7 @@ glabel L80086F74 /* 087C54 80087054 00C02825 */ move $a1, $a2 /* 087C58 80087058 AFA20038 */ sw $v0, 0x38($sp) .L8008705C: -/* 087C5C 8008705C 0C01BAD7 */ jal func_8006EB5C +/* 087C5C 8008705C 0C01BAD7 */ jal mark_to_read_flap_and_course_times /* 087C60 80087060 00000000 */ nop /* 087C64 80087064 10000059 */ b .L800871CC /* 087C68 80087068 8FBF0014 */ lw $ra, 0x14($sp) diff --git a/asm/non_matchings/menu/func_8008B4C8.s b/asm/non_matchings/menu/func_8008B4C8.s index db482d28..8e76c822 100644 --- a/asm/non_matchings/menu/func_8008B4C8.s +++ b/asm/non_matchings/menu/func_8008B4C8.s @@ -34,7 +34,7 @@ glabel func_8008B4C8 /* 08C140 8008B540 00008025 */ move $s0, $zero /* 08C144 8008B544 24120001 */ li $s2, 1 /* 08C148 8008B548 3C01800E */ lui $at, %hi(gMenuDelay) # $at, 0x800e -/* 08C14C 8008B54C 0C01BAEA */ jal func_8006EBA8 +/* 08C14C 8008B54C 0C01BAEA */ jal mark_read_all_save_files /* 08C150 8008B550 AC32F47C */ sw $s2, %lo(gMenuDelay)($at) /* 08C154 8008B554 3C04800E */ lui $a0, %hi(sMenuTransitionFadeIn) # $a0, 0x800e /* 08C158 8008B558 0C030076 */ jal transition_begin diff --git a/asm/non_matchings/menu/func_80095728.s b/asm/non_matchings/menu/func_80095728.s index f76bc229..d28bdd29 100644 --- a/asm/non_matchings/menu/func_80095728.s +++ b/asm/non_matchings/menu/func_80095728.s @@ -980,7 +980,7 @@ glabel L800964DC /* 097120 80096520 304F007F */ andi $t7, $v0, 0x7f /* 097124 80096524 11E00008 */ beqz $t7, .L80096548 /* 097128 80096528 304D0080 */ andi $t5, $v0, 0x80 -/* 09712C 8009652C 0C01BAF1 */ jal func_8006EBC4 +/* 09712C 8009652C 0C01BAF1 */ jal mark_to_write_flap_times /* 097130 80096530 00000000 */ nop /* 097134 80096534 8FB8002C */ lw $t8, 0x2c($sp) /* 097138 80096538 00000000 */ nop @@ -990,7 +990,7 @@ glabel L800964DC .L80096548: /* 097148 80096548 11A00004 */ beqz $t5, .L8009655C /* 09714C 8009654C 00002025 */ move $a0, $zero -/* 097150 80096550 0C01BAF8 */ jal func_8006EBE0 +/* 097150 80096550 0C01BAF8 */ jal mark_to_write_course_times /* 097154 80096554 00000000 */ nop /* 097158 80096558 00002025 */ move $a0, $zero .L8009655C: diff --git a/asm/non_matchings/menu/menu_trophy_race_rankings_loop.s b/asm/non_matchings/menu/menu_trophy_race_rankings_loop.s index 66dcbd8b..7c71f1df 100644 --- a/asm/non_matchings/menu/menu_trophy_race_rankings_loop.s +++ b/asm/non_matchings/menu/menu_trophy_race_rankings_loop.s @@ -384,7 +384,7 @@ glabel menu_trophy_race_rankings_loop /* 09A168 80099568 A56E000E */ sh $t6, 0xe($t3) /* 09A16C 8009956C 0C027068 */ jal get_save_file_index /* 09A170 80099570 AFAC0034 */ sw $t4, 0x34($sp) -/* 09A174 80099574 0C01BB12 */ jal func_8006EC48 +/* 09A174 80099574 0C01BB12 */ jal safe_mark_write_save_file /* 09A178 80099578 00402025 */ move $a0, $v0 /* 09A17C 8009957C 8FAC0034 */ lw $t4, 0x34($sp) /* 09A180 80099580 00000000 */ nop diff --git a/asm/non_matchings/menu/render_file_select_menu.s b/asm/non_matchings/menu/render_file_select_menu.s index d86ca701..8cc658fc 100644 --- a/asm/non_matchings/menu/render_file_select_menu.s +++ b/asm/non_matchings/menu/render_file_select_menu.s @@ -274,10 +274,10 @@ glabel render_file_select_menu /* 08DD74 8008D174 3C088012 */ lui $t0, %hi(D_80126488) # $t0, 0x8012 /* 08DD78 8008D178 3C028012 */ lui $v0, %hi(D_80126494) # $v0, 0x8012 /* 08DD7C 8008D17C 8C426494 */ lw $v0, %lo(D_80126494)($v0) -/* 08DD80 8008D180 3C188012 */ lui $t8, %hi(D_8012648C) # $t8, 0x8012 +/* 08DD80 8008D180 3C188012 */ lui $t8, %hi(gSaveFileIndex3) # $t8, 0x8012 /* 08DD84 8008D184 14400007 */ bnez $v0, .L8008D1A4 /* 08DD88 8008D188 00000000 */ nop -/* 08DD8C 8008D18C 8F18648C */ lw $t8, %lo(D_8012648C)($t8) +/* 08DD8C 8008D18C 8F18648C */ lw $t8, %lo(gSaveFileIndex3)($t8) /* 08DD90 8008D190 00000000 */ nop /* 08DD94 8008D194 16780003 */ bne $s3, $t8, .L8008D1A4 /* 08DD98 8008D198 00000000 */ nop @@ -285,8 +285,8 @@ glabel render_file_select_menu /* 08DDA0 8008D1A0 24120001 */ li $s2, 1 .L8008D1A4: /* 08DDA4 8008D1A4 1840001A */ blez $v0, .L8008D210 -/* 08DDA8 8008D1A8 3C198012 */ lui $t9, %hi(D_80126490) # $t9, 0x8012 -/* 08DDAC 8008D1AC 8F396490 */ lw $t9, %lo(D_80126490)($t9) +/* 08DDA8 8008D1A8 3C198012 */ lui $t9, %hi(gSaveFileIndex2) # $t9, 0x8012 +/* 08DDAC 8008D1AC 8F396490 */ lw $t9, %lo(gSaveFileIndex2)($t9) /* 08DDB0 8008D1B0 00000000 */ nop /* 08DDB4 8008D1B4 16790016 */ bne $s3, $t9, .L8008D210 /* 08DDB8 8008D1B8 00000000 */ nop @@ -294,10 +294,10 @@ glabel render_file_select_menu /* 08DDC0 8008D1C0 24120001 */ li $s2, 1 .L8008D1C4: /* 08DDC4 8008D1C4 8D086488 */ lw $t0, %lo(D_80126488)($t0) -/* 08DDC8 8008D1C8 3C098012 */ lui $t1, %hi(D_8012648C) # $t1, 0x8012 +/* 08DDC8 8008D1C8 3C098012 */ lui $t1, %hi(gSaveFileIndex3) # $t1, 0x8012 /* 08DDCC 8008D1CC 11000007 */ beqz $t0, .L8008D1EC /* 08DDD0 8008D1D0 3C0A8012 */ lui $t2, %hi(D_801263E0) # $t2, 0x8012 -/* 08DDD4 8008D1D4 8D29648C */ lw $t1, %lo(D_8012648C)($t1) +/* 08DDD4 8008D1D4 8D29648C */ lw $t1, %lo(gSaveFileIndex3)($t1) /* 08DDD8 8008D1D8 00000000 */ nop /* 08DDDC 8008D1DC 1669000C */ bne $s3, $t1, .L8008D210 /* 08DDE0 8008D1E0 00000000 */ nop diff --git a/asm/non_matchings/objects/func_8000CC7C.s b/asm/non_matchings/objects/func_8000CC7C.s index c3cf456e..c68d107a 100644 --- a/asm/non_matchings/objects/func_8000CC7C.s +++ b/asm/non_matchings/objects/func_8000CC7C.s @@ -1390,7 +1390,7 @@ glabel L8000D98C /* 00EC00 8000E000 02402025 */ move $a0, $s2 /* 00EC04 8000E004 0C027068 */ jal get_save_file_index /* 00EC08 8000E008 00000000 */ nop -/* 00EC0C 8000E00C 0C01BB12 */ jal func_8006EC48 +/* 00EC0C 8000E00C 0C01BB12 */ jal safe_mark_write_save_file /* 00EC10 8000E010 00402025 */ move $a0, $v0 .L8000E014: /* 00EC14 8000E014 8FAE0130 */ lw $t6, 0x130($sp) diff --git a/asm/non_matchings/objects/func_80022E18.s b/asm/non_matchings/objects/func_80022E18.s index b3328d38..9b0542ca 100644 --- a/asm/non_matchings/objects/func_80022E18.s +++ b/asm/non_matchings/objects/func_80022E18.s @@ -132,7 +132,7 @@ glabel func_80022E18 /* 023C08 80023008 01054825 */ or $t1, $t0, $a1 /* 023C0C 8002300C 0C027068 */ jal get_save_file_index /* 023C10 80023010 A4C90014 */ sh $t1, 0x14($a2) -/* 023C14 80023014 0C01BB12 */ jal func_8006EC48 +/* 023C14 80023014 0C01BB12 */ jal safe_mark_write_save_file /* 023C18 80023018 00402025 */ move $a0, $v0 /* 023C1C 8002301C 10000004 */ b .L80023030 /* 023C20 80023020 8FAB001C */ lw $t3, 0x1c($sp) diff --git a/asm/non_matchings/unknown_05CEF0/func_8005CB68.s b/asm/non_matchings/unknown_05CEF0/func_8005CB68.s index 53c73200..6d645809 100644 --- a/asm/non_matchings/unknown_05CEF0/func_8005CB68.s +++ b/asm/non_matchings/unknown_05CEF0/func_8005CB68.s @@ -325,7 +325,7 @@ glabel func_8005CB68 /* 05DC14 8005D014 25CF0001 */ addiu $t7, $t6, 1 /* 05DC18 8005D018 0C027068 */ jal get_save_file_index /* 05DC1C 8005D01C A3AF0043 */ sb $t7, 0x43($sp) -/* 05DC20 8005D020 0C01BB12 */ jal func_8006EC48 +/* 05DC20 8005D020 0C01BB12 */ jal safe_mark_write_save_file /* 05DC24 8005D024 00402025 */ move $a0, $v0 .L8005D028: /* 05DC28 8005D028 83AD0043 */ lb $t5, 0x43($sp) diff --git a/src/asset_loading.c b/src/asset_loading.c index 34cc2e47..77fd20d4 100644 --- a/src/asset_loading.c +++ b/src/asset_loading.c @@ -184,7 +184,7 @@ void dmacopy(u32 romOffset, u32 ramAddress, s32 numBytes) { numBytesToDMA = numBytes; } osPiStartDma(&gAssetsDmaIoMesg, OS_MESG_PRI_NORMAL, OS_READ, romOffset, (u32 *) ramAddress, numBytesToDMA, &gDmaMesgQueue); - osRecvMesg(&gDmaMesgQueue, &dmaMesg, 1); + osRecvMesg(&gDmaMesgQueue, &dmaMesg, OS_MESG_BLOCK); numBytes -= numBytesToDMA; romOffset += numBytesToDMA; ramAddress += numBytesToDMA; diff --git a/src/audiomgr.c b/src/audiomgr.c index 458c9fb2..d558444c 100644 --- a/src/audiomgr.c +++ b/src/audiomgr.c @@ -241,7 +241,7 @@ static void __amMain(UNUSED void *arg) { osScAddClient(gAudioSched, (OSScClient *) &audioStack, &__am.audioFrameMsgQ, OS_MESG_BLOCK); while (!done) { - (void) osRecvMesg(&__am.audioFrameMsgQ, (OSMesg *) &msg, 1); + (void) osRecvMesg(&__am.audioFrameMsgQ, (OSMesg *) &msg, OS_MESG_BLOCK); switch (msg->gen.type) { case OS_SC_RETRACE_MSG: //TODO: Check type of ACMDList? diff --git a/src/camera.c b/src/camera.c index b37ebac7..28e364ea 100644 --- a/src/camera.c +++ b/src/camera.c @@ -95,10 +95,6 @@ u8 D_800DD2F8[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; -s32 sNoControllerPluggedIn = FALSE; // Looks to be a boolean for whether a controller is plugged in. FALSE if plugged in, and TRUE if not. - -s16 gButtonMask = 0xFFFF; - /*******************************/ /************ .bss ************/ @@ -133,15 +129,6 @@ MatrixS gPerspectiveMatrixS; MatrixS D_80121020; Matrix D_80121060; Matrix D_801210A0; -OSMesgQueue sSIMesgQueue; -OSMesg sSIMesgBuf; -OSMesg gSIMesg; -OSContStatus status; -UNUSED s32 D_80121108[2]; //Padding? -OSContPad sControllerData[8]; -u16 gControllerButtonsPressed[4]; -u16 gControllerButtonsReleased[4]; -u8 sPlayerID[16]; /******************************/ @@ -1375,154 +1362,3 @@ UNUSED void debug_print_float_matrix_values(f32 *mtx) { } rmonPrintf("\n"); } - -/** - * Return the serial interface message queue. -*/ -OSMesgQueue *get_si_mesg_queue(void) { - return &sSIMesgQueue; -} - -/** - * Initialise the player controllers, and return the status when finished. - */ -s32 init_controllers(void) { - UNUSED s32 *temp1; - u8 bitpattern; - UNUSED s32 *temp2; - - osCreateMesgQueue(&sSIMesgQueue, &sSIMesgBuf, 1); - osSetEventMesg(OS_EVENT_SI, &sSIMesgQueue, gSIMesg); - osContInit(&sSIMesgQueue, &bitpattern, &status); - osContStartReadData(&sSIMesgQueue); - initialise_player_ids(); - - sNoControllerPluggedIn = FALSE; - - if ((bitpattern & CONT_ABSOLUTE) && (!(status.errno & CONT_NO_RESPONSE_ERROR))) { - return CONTROLLER_EXISTS; - } - - if (!bitpattern) {} // Fakematch - - sNoControllerPluggedIn = TRUE; - - return CONTROLLER_MISSING; -} - -GLOBAL_ASM("asm/non_matchings/camera/func_8006A1C4.s") - -/** - * Set the first 4 player ID's to the controller numbers, so players can input in the menus after boot. - * Official name: joyResetMap - */ -void initialise_player_ids(void) { - s32 i; - for (i = 0; i < MAXCONTROLLERS; i++) { - sPlayerID[i] = i; - } -} - -/** - * Assign the first four player ID's to the index of the connected players. - * Assign the next four player ID's to the index of the players who are not connected. - * Official name: joyCreateMap - */ -void assign_player_ids(s8 *activePlayers) { - s32 i; - s32 temp = 0; - for (i = 0; i < MAXCONTROLLERS; i++) { - if (activePlayers[i]) { - sPlayerID[temp++] = i; - } - } - for (i = 0; i < MAXCONTROLLERS; i++) { - if (!activePlayers[i]) { - sPlayerID[temp++] = i; - } - } -} - -/** - * Returns the id of the selected index. - * Official name: joyGetController - */ -u8 get_player_id(s32 player) { - return sPlayerID[player]; -} - -/** - * Swaps the ID's of the first two indexes. - * This applies in 2 player adventure, so that player 2 can control the car in the overworld. - */ -void swap_player_1_and_2_ids(void) { - u8 tempID = sPlayerID[0]; - sPlayerID[0] = sPlayerID[1]; - sPlayerID[1] = tempID; -} - -/** - * Returns the buttons that are currently pressed down on the controller. - * Official name: joyGetButtons - */ -u16 get_buttons_held_from_player(s32 player) { - return sControllerData[sPlayerID[player]].button; -} - -/** - * Returns the buttons that are newly pressed during that frame. - * NOTE: This was a u16, but we only got a match in menu_ghost_data_loop when it was a u32 for some reason - */ -u32 get_buttons_pressed_from_player(s32 player) { - return gControllerButtonsPressed[sPlayerID[player]]; -} - -/** - * Returns the buttons that are no longer pressed in that frame. - */ -u16 get_buttons_released_from_player(s32 player) { - return gControllerButtonsReleased[sPlayerID[player]]; -} - -/** - * Clamps the X joystick axis of the selected player to 70 and returns it. - */ -s8 clamp_joystick_x_axis(s32 player) { - return clamp_joystick(sControllerData[sPlayerID[player]].stick_x); -} - -/** - * Clamps the Y joystick axis of the selected player to 70 and returns it. - */ -s8 clamp_joystick_y_axis(s32 player) { - return clamp_joystick(sControllerData[sPlayerID[player]].stick_y); -} - -/** - * Keeps the joysticks axis reads no higher than 70 (of a possible 127 or -128) - * Will also pull the reading towards the centre. - */ -s8 clamp_joystick(s8 stickMag) { - if (stickMag < JOYSTICK_DEADZONE && stickMag > -JOYSTICK_DEADZONE) { - return 0; - } - if (stickMag > 0) { - stickMag -= 8; - if (stickMag > JOYSTICK_MAX_RANGE) { - stickMag = JOYSTICK_MAX_RANGE; - } - } else { - stickMag += 8; - if (stickMag < -JOYSTICK_MAX_RANGE) { - stickMag = -JOYSTICK_MAX_RANGE; - } - } - return stickMag; -} - -/** - * Used when anti-cheat/anti-tamper has failed in func_8006A6B0() - */ -void disable_button_mask(void) { - gButtonMask = 0; -} diff --git a/src/camera.h b/src/camera.h index 1df7cf4d..7b4240f9 100644 --- a/src/camera.h +++ b/src/camera.h @@ -120,19 +120,6 @@ Matrix *func_80069DBC(void); f32 func_80069DC8(f32 x, f32 y, f32 z); void set_camera_shake_by_distance(f32 x, f32 y, f32 z, f32 dist, f32 magnitude); void set_camera_shake(f32 magnitude); -OSMesgQueue *get_si_mesg_queue(void); -void initialise_player_ids(void); -void assign_player_ids(s8 *activePlayers); -u8 get_player_id(s32 player); -void swap_player_1_and_2_ids(void); -u16 get_buttons_held_from_player(s32 player); -u32 get_buttons_pressed_from_player(s32 player); -u16 get_buttons_released_from_player(s32 player); -s8 clamp_joystick_x_axis(s32 player); -s8 clamp_joystick_y_axis(s32 player); -s8 clamp_joystick(s8 stickMag); -void disable_button_mask(void); -s32 init_controllers(void); void func_80067D3C(Gfx **dlist, MatrixS **mats); void render_ortho_triangle_image(Gfx **dList, MatrixS **mtx, Vertex **vtx, ObjectSegment *segment, Sprite *sprite, s32 flags); s32 render_sprite_billboard(Gfx **dlist, MatrixS **mtx, Vertex **vertexList, Object *obj, unk80068514_arg4 *arg4, s32 flags); @@ -143,7 +130,6 @@ void copy_viewports_to_stack(void); // Non Matching void func_80065EA0(void); -s32 func_8006A1C4(s32 arg0, s32 logicUpdateRate); void func_80066CDC(Gfx **dlist, MatrixS **mats); #endif diff --git a/src/controller.c b/src/controller.c new file mode 100644 index 00000000..2bf48ea2 --- /dev/null +++ b/src/controller.c @@ -0,0 +1,232 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x8006A100 */ + +#include "controller.h" +#include "game.h" + +s32 sNoControllerPluggedIn = FALSE; // Looks to be a boolean for whether a controller is plugged in. FALSE if plugged in, and TRUE if not. +u16 gButtonMask = 0xFFFF; //Used when anti-cheat/anti-tamper has failed in func_8006A6B0() + +OSMesgQueue sSIMesgQueue; +OSMesg sSIMesgBuf; +OSMesg gSIMesg; +OSContStatus status; +UNUSED s32 D_80121108[2]; +OSContPad sControllerCurrData[MAXCONTROLLERS]; +OSContPad sControllerPrevData[MAXCONTROLLERS]; +u16 gControllerButtonsPressed[MAXCONTROLLERS]; +u16 gControllerButtonsReleased[MAXCONTROLLERS]; +u8 sPlayerID[16]; + +/** + * Return the serial interface message queue. + */ +OSMesgQueue *get_si_mesg_queue(void) { + return &sSIMesgQueue; +} + +/** + * Initialise the player controllers, and return the status when finished. + */ +s32 init_controllers(void) { + UNUSED s32 *temp1; + u8 bitpattern; + UNUSED s32 *temp2; + + osCreateMesgQueue(&sSIMesgQueue, &sSIMesgBuf, 1); + osSetEventMesg(OS_EVENT_SI, &sSIMesgQueue, gSIMesg); + osContInit(&sSIMesgQueue, &bitpattern, &status); + osContStartReadData(&sSIMesgQueue); + initialise_player_ids(); + + sNoControllerPluggedIn = FALSE; + + if ((bitpattern & CONT_ABSOLUTE) && (!(status.errno & CONT_NO_RESPONSE_ERROR))) { + return CONTROLLER_EXISTS; + } + + if (!bitpattern) {} // Fakematch + + sNoControllerPluggedIn = TRUE; + + return CONTROLLER_MISSING; +} + +/** + * Reads arg0 for a set of flags on whether to read, write, or erase any save data. + * Also reads the latest inputs from the controllers, and sets their values. + */ +s32 handle_save_data_and_read_controller(s32 saveDataFlags, s32 updateRate) { + Settings **allSaves; + OSMesg unusedMsg; + Settings *settings; + s32 i; + + if (osRecvMesg(&sSIMesgQueue, &unusedMsg, OS_MESG_NOBLOCK) == 0) { + //Back up old controller data + for (i = 0; i < MAXCONTROLLERS; i++) { + sControllerPrevData[i] = sControllerCurrData[i]; + } + osContGetReadData(sControllerCurrData); + if (saveDataFlags != 0) { + settings = get_settings(); + if (SAVE_DATA_FLAG_READ_EEPROM_INDEX(saveDataFlags)) { + read_eeprom_data(settings, SAVE_DATA_FLAG_READ_EEPROM_INDEX(saveDataFlags)); + } + if (saveDataFlags & SAVE_DATA_FLAG_READ_ALL_SAVE_DATA) { + allSaves = get_all_save_files_ptr(); + for (i = 0; i < NUMBER_OF_SAVE_FILES; i++) { + read_save_file(i, allSaves[i]); + } + } + if (saveDataFlags & SAVE_DATA_FLAG_READ_SAVE_DATA) { + read_save_file(SAVE_DATA_FLAG_READ_SAVE_FILE_NUMBER(saveDataFlags), settings); + } + if (SAVE_DATA_FLAG_WRITE_EEPROM_INDEX(saveDataFlags)) { + write_eeprom_data(settings, SAVE_DATA_FLAG_WRITE_EEPROM_INDEX(saveDataFlags)); + } + if (saveDataFlags & SAVE_DATA_FLAG_WRITE_SAVE_DATA) { + write_save_data(SAVE_DATA_FLAG_WRITE_SAVE_FILE_NUMBER(saveDataFlags), settings); + } + if (saveDataFlags & SAVE_DATA_FLAG_ERASE_SAVE_DATA) { + erase_save_file(SAVE_DATA_FLAG_WRITE_SAVE_FILE_NUMBER(saveDataFlags), settings); + } + // @bug These next two if statements check the same bits + // as the ones used to set the save file number to read from. + if (saveDataFlags & SAVE_DATA_FLAG_READ_EEPROM_SETTINGS) { + read_eeprom_settings(get_eeprom_settings_pointer()); + } + if (saveDataFlags & SAVE_DATA_FLAG_WRITE_EEPROM_SETTINGS) { + write_eeprom_settings(get_eeprom_settings_pointer()); + } + //Reset all flags + saveDataFlags = 0; + } + rumble_controllers(updateRate); + osContStartReadData(&sSIMesgQueue); + } + for (i = 0; i < MAXCONTROLLERS; i++) { + if (sNoControllerPluggedIn) { + sControllerCurrData[i].button = 0; + } + //XOR the diff between the last read of the controller data with the current read to see what buttons have been pushed and released. + gControllerButtonsPressed[i] = ((sControllerCurrData[i].button ^ sControllerPrevData[i].button) & sControllerCurrData[i].button) & gButtonMask; + gControllerButtonsReleased[i] = ((sControllerCurrData[i].button ^ sControllerPrevData[i].button) & sControllerPrevData[i].button) & gButtonMask; + } + return saveDataFlags; +} + +/** + * Set the first 4 player ID's to the controller numbers, so players can input in the menus after boot. + * Official name: joyResetMap + */ +void initialise_player_ids(void) { + s32 i; + for (i = 0; i < MAXCONTROLLERS; i++) { + sPlayerID[i] = i; + } +} + +/** + * Assign the first four player ID's to the index of the connected players. + * Assign the next four player ID's to the index of the players who are not connected. + * Official name: joyCreateMap + */ +void assign_player_ids(s8 *activePlayers) { + s32 i; + s32 temp = 0; + for (i = 0; i < MAXCONTROLLERS; i++) { + if (activePlayers[i]) { + sPlayerID[temp++] = i; + } + } + for (i = 0; i < MAXCONTROLLERS; i++) { + if (!activePlayers[i]) { + sPlayerID[temp++] = i; + } + } +} + +/** + * Returns the id of the selected index. + * Official name: joyGetController + */ +u8 get_player_id(s32 player) { + return sPlayerID[player]; +} + +/** + * Swaps the ID's of the first two indexes. + * This applies in 2 player adventure, so that player 2 can control the car in the overworld. + */ +void swap_player_1_and_2_ids(void) { + u8 tempID = sPlayerID[0]; + sPlayerID[0] = sPlayerID[1]; + sPlayerID[1] = tempID; +} + +/** + * Returns the buttons that are currently pressed down on the controller. + * Official name: joyGetButtons + */ +u16 get_buttons_held_from_player(s32 player) { + return sControllerCurrData[sPlayerID[player]].button; +} + +/** + * Returns the buttons that are newly pressed during that frame. + * NOTE: This was a u16, but we only got a match in menu_ghost_data_loop when it was a u32 for some reason + */ +u32 get_buttons_pressed_from_player(s32 player) { + return gControllerButtonsPressed[sPlayerID[player]]; +} + +/** + * Returns the buttons that are no longer pressed in that frame. + */ +u16 get_buttons_released_from_player(s32 player) { + return gControllerButtonsReleased[sPlayerID[player]]; +} + +/** + * Clamps the X joystick axis of the selected player to 70 and returns it. + */ +s8 clamp_joystick_x_axis(s32 player) { + return clamp_joystick(sControllerCurrData[sPlayerID[player]].stick_x); +} + +/** + * Clamps the Y joystick axis of the selected player to 70 and returns it. + */ +s8 clamp_joystick_y_axis(s32 player) { + return clamp_joystick(sControllerCurrData[sPlayerID[player]].stick_y); +} + +/** + * Keeps the joysticks axis reads no higher than 70 (of a possible 127 or -128) + * Will also pull the reading towards the centre. + */ +s8 clamp_joystick(s8 stickMag) { + if (stickMag < JOYSTICK_DEADZONE && stickMag > -JOYSTICK_DEADZONE) { + return 0; + } + if (stickMag > 0) { + stickMag -= 8; + if (stickMag > JOYSTICK_MAX_RANGE) { + stickMag = JOYSTICK_MAX_RANGE; + } + } else { + stickMag += 8; + if (stickMag < -JOYSTICK_MAX_RANGE) { + stickMag = -JOYSTICK_MAX_RANGE; + } + } + return stickMag; +} + +/** + * Used when anti-cheat/anti-tamper has failed in func_8006A6B0() + */ +void disable_button_mask(void) { + gButtonMask = 0; +} diff --git a/src/controller.h b/src/controller.h new file mode 100644 index 00000000..f898ade6 --- /dev/null +++ b/src/controller.h @@ -0,0 +1,30 @@ +#ifndef _CONTROLLER_H_ +#define _CONTROLLER_H_ + +#include "types.h" +#include "macros.h" +#include "structs.h" +#include "libultra_internal.h" + +#define CONTROLLER_MISSING -1 +#define CONTROLLER_EXISTS 0 + +#define JOYSTICK_DEADZONE 8 +#define JOYSTICK_MAX_RANGE 70 + +OSMesgQueue *get_si_mesg_queue(void); +s32 init_controllers(void); +s32 handle_save_data_and_read_controller(s32 saveDataFlags, s32 updateRate); +void initialise_player_ids(void); +void assign_player_ids(s8 *activePlayers); +u8 get_player_id(s32 player); +void swap_player_1_and_2_ids(void); +u16 get_buttons_held_from_player(s32 player); +u32 get_buttons_pressed_from_player(s32 player); +u16 get_buttons_released_from_player(s32 player); +s8 clamp_joystick_x_axis(s32 player); +s8 clamp_joystick_y_axis(s32 player); +s8 clamp_joystick(s8 stickMag); +void disable_button_mask(void); + +#endif diff --git a/src/game.c b/src/game.c index 5bfbdf08..5fa1d629 100644 --- a/src/game.c +++ b/src/game.c @@ -43,6 +43,7 @@ #include "racer.h" #include "particles.h" #include "math_util.h" +#include "controller.h" /************ .rodata ************/ @@ -88,7 +89,7 @@ UNUSED char gBuildString[40] = "Version 7.7 29/09/97 15.00 L.Schuneman"; s8 sAntiPiracyTriggered = 0; UNUSED s32 D_800DD378 = 1; -s32 D_800DD37C = 0; +s32 gSaveDataFlags = 0; s32 gScreenStatus = OSMESG_SWAP_BUFFER; s32 sControllerStatus = 0; UNUSED s32 D_800DD388 = 0; @@ -868,10 +869,9 @@ s32 func_8006C300(void) { /** * Main looping function for the main thread. */ - void thread3_main(UNUSED void *unused) { init_game(); - D_800DD37C = func_8006A1C4(D_800DD37C, 0); + gSaveDataFlags = handle_save_data_and_read_controller(gSaveDataFlags, 0); sBootDelayTimer = 0; sRenderContext = DRAW_INTRO; while (1) { @@ -991,7 +991,7 @@ void main_game_loop(void) { init_rsp(&gCurrDisplayList); init_rdp_and_framebuffer(&gCurrDisplayList); render_background(&gCurrDisplayList, (Matrix *) &gGameCurrMatrix, TRUE); - D_800DD37C = func_8006A1C4(D_800DD37C, sLogicUpdateRate); + gSaveDataFlags = handle_save_data_and_read_controller(gSaveDataFlags, sLogicUpdateRate); if (get_lockup_status()) { render_epc_lock_up_display(); sRenderContext = DRAW_CRASH_SCREEN; @@ -1381,7 +1381,7 @@ void ingame_logic_loop(s32 updateRate) { gLevelLoadTimer = 0; gPostRaceViewPort = NULL; func_8006CC14(); - func_8006EC48(get_save_file_index()); + safe_mark_write_save_file(get_save_file_index()); if (sp40 != 0) { gIsLoading = FALSE; switch (sp40) { @@ -1442,7 +1442,7 @@ void ingame_logic_loop(s32 updateRate) { } load_level_2(gPlayableMapId, D_80123500, D_80123504, gLevelDefaultVehicleID); } else { - func_8006EC48(get_save_file_index()); + safe_mark_write_save_file(get_save_file_index()); load_menu_with_level_background(MENU_TITLE, -1, 0); } D_801234FC = 0; @@ -1451,7 +1451,7 @@ void ingame_logic_loop(s32 updateRate) { gPostRaceViewPort = NULL; func_8006CC14(); load_level_2(gPlayableMapId, D_80123500, D_80123504, gLevelDefaultVehicleID); - func_8006EC48(get_save_file_index()); + safe_mark_write_save_file(get_save_file_index()); D_801234F8 = 0; } } @@ -1625,7 +1625,7 @@ void func_8006DCF8(s32 updateRate) { gIsPaused = FALSE; gPostRaceViewPort = NULL; load_level_2(gPlayableMapId, D_80123500, D_80123504, gLevelDefaultVehicleID); - func_8006EC48(get_save_file_index()); + safe_mark_write_save_file(get_save_file_index()); return; } if ((menuLoopResult != -1) && (menuLoopResult & 0x100)) { @@ -1642,7 +1642,7 @@ void func_8006DCF8(s32 updateRate) { D_80123508 = 0x64; sRenderContext = DRAW_GAME; load_level_2(gPlayableMapId, D_80123500, D_80123504, gLevelDefaultVehicleID); - func_8006EC48(get_save_file_index()); + safe_mark_write_save_file(get_save_file_index()); break; case 1: D_80123504 = 0; @@ -1659,7 +1659,7 @@ void func_8006DCF8(s32 updateRate) { D_80123508 = temp2; } load_level_2(gPlayableMapId, D_80123500, D_80123504, gLevelDefaultVehicleID); - func_8006EC48(get_save_file_index()); + safe_mark_write_save_file(get_save_file_index()); break; case 2: sRenderContext = DRAW_GAME; @@ -1777,7 +1777,11 @@ void calc_and_alloc_heap_for_settings(void) { gSettingsPtr->courseTimesPtr[1] = (u16 *)((u8 *)gSettingsPtr + sizes[12]); gSettingsPtr->courseTimesPtr[2] = (u16 *)((u8 *)gSettingsPtr + sizes[13]); gSettingsPtr->unk4C = (Settings4C *) &D_80121250; - D_800DD37C = 263; + gSaveDataFlags = // Set bits 0/1/2/8 and wipe out all others + SAVE_DATA_FLAG_READ_FLAP_TIMES | + SAVE_DATA_FLAG_READ_COURSE_TIMES | + SAVE_DATA_FLAG_READ_SAVE_DATA | + SAVE_DATA_FLAG_READ_EEPROM_SETTINGS; } void func_8006E5BC(void) { @@ -1818,7 +1822,7 @@ void func_8006E770(Settings *settings, s32 arg1) { get_number_of_levels_and_worlds(&numLevels, &numWorlds); temp_v0 = (u16 *)get_misc_asset(MISC_ASSET_UNK17); - for (i = 0; i < 3; i++) { // 3 = number of save files? + for (i = 0; i < NUMBER_OF_SAVE_FILES; i++) { for (j = 0; j < numLevels; j++) { index = (j * 12) + (i * 4); if (arg1 & 1) { @@ -1896,64 +1900,108 @@ s32 func_8006EB14(void) { return gPlayableMapId; } -/* Unused? */ -void func_8006EB24(void) { - D_800DD37C |= 0x01; +/** + * Marks a flag to read flap times from the eeprom + */ +UNUSED void mark_to_read_flap_times(void) { + gSaveDataFlags |= SAVE_DATA_FLAG_READ_FLAP_TIMES; } -/* Unused? */ -void func_8006EB40(void) { - D_800DD37C |= 0x02; +/** + * Marks a flag to read course times from the eeprom + */ +UNUSED void mark_to_read_course_times(void) { + gSaveDataFlags |= SAVE_DATA_FLAG_READ_COURSE_TIMES; } -void func_8006EB5C(void) { - D_800DD37C |= 0x03; +/** + * Marks a flag to read both flap times and course times from the eeprom + */ +void mark_to_read_flap_and_course_times(void) { + gSaveDataFlags |= (SAVE_DATA_FLAG_READ_FLAP_TIMES | SAVE_DATA_FLAG_READ_COURSE_TIMES); } -void func_8006EB78(s32 saveFileIndex) { - D_800DD37C &= -0x301; - D_800DD37C |= (0x04 | ((saveFileIndex & 3) << 8)); +/** + * Marks a flag to read the save file from the passed index from flash. + */ +void mark_read_save_file(s32 saveFileIndex) { + //Wipe out bits 8 and 9 + gSaveDataFlags &= ~(SAVE_DATA_FLAG_READ_EEPROM_SETTINGS | SAVE_DATA_FLAG_WRITE_EEPROM_SETTINGS); + //Place saveFileIndex at bits 8 and 9 and set bit 2 + gSaveDataFlags |= (SAVE_DATA_FLAG_READ_SAVE_DATA | ((saveFileIndex & SAVE_DATA_FLAG_INDEX_VALUE) << 8)); } -void func_8006EBA8(void) { - D_800DD37C |= 0x08; +/** + * Marks a flag to read all save file data from flash. + */ +void mark_read_all_save_files(void) { + gSaveDataFlags |= SAVE_DATA_FLAG_READ_ALL_SAVE_DATA; //Set bit 3 } -void func_8006EBC4(void) { - D_800DD37C |= 0x10; +/** + * Marks a flag to write flap times to the eeprom + */ +void mark_to_write_flap_times(void) { + gSaveDataFlags |= SAVE_DATA_FLAG_WRITE_FLAP_TIMES; } -void func_8006EBE0(void) { - D_800DD37C |= 0x20; +/** + * Marks a flag to write course times to the eeprom + */ +void mark_to_write_course_times(void) { + gSaveDataFlags |= SAVE_DATA_FLAG_WRITE_COURSE_TIMES; } -void func_8006EBFC(void) { - D_800DD37C |= 0x30; +/** + * Marks a flag to write both flap times and course times to the eeprom + */ +void mark_to_write_flap_and_course_times(void) { + gSaveDataFlags |= (SAVE_DATA_FLAG_WRITE_FLAP_TIMES | SAVE_DATA_FLAG_WRITE_COURSE_TIMES); } -void func_8006EC18(s32 arg0) { - D_800DD37C &= -0xC01; - D_800DD37C |= (0x40 | ((arg0 & 3) << 0xA)); +/** + * Forcefully marks a flag to write a save file to flash. + */ +void force_mark_write_save_file(s32 saveFileIndex) { + gSaveDataFlags &= ~SAVE_DATA_FLAG_WRITE_SAVE_FILE_NUMBER_BITS; //Wipe out bits 10 and 11 + gSaveDataFlags |= (SAVE_DATA_FLAG_WRITE_SAVE_DATA | ((saveFileIndex & 3) << 10)); //Set bit 6 and place saveFileIndex into bits 10 and 11 } -void func_8006EC48(s32 saveFileIndex) { +/** + * Marks a flag to write a save file to flash as long as we're not in tracks mode, and we're in the draw game render context. + * This should prevent save data from being overwritten outside of Adventure Mode. + */ +void safe_mark_write_save_file(s32 saveFileIndex) { if (sRenderContext == DRAW_GAME && !is_in_tracks_mode()) { - D_800DD37C &= -0xC01; - D_800DD37C |= (0x40 | ((saveFileIndex & 3) << 0xA)); + gSaveDataFlags &= ~SAVE_DATA_FLAG_WRITE_SAVE_FILE_NUMBER_BITS; //Wipe out bits 10 and 11 + gSaveDataFlags |= (SAVE_DATA_FLAG_WRITE_SAVE_DATA | ((saveFileIndex & 3) << 10));; //Set bit 6 and place saveFileIndex into bits 10 and 11 } } -void func_8006ECAC(s32 arg0) { - D_800DD37C = ((arg0 & 0x03) << 10) | 0x80; +/** + * Marks a flag to erase a save file from flash later + */ +void mark_save_file_to_erase(s32 saveFileIndex) { + //Set bit 7 and and place saveFileIndex into bits 10 and 11 while wiping everything else + gSaveDataFlags = SAVE_DATA_FLAG_ERASE_SAVE_DATA | ((saveFileIndex & 3) << 10); } -UNUSED void func_8006ECC4(void) { - D_800DD37C |= 0x100; +/** + * Marks a flag to read eeprom settings from flash later + * @bug: Because this is the same bit used for reading save files, + * it will change the save file number to read from + */ +UNUSED void mark_read_eeprom_settings(void) { + gSaveDataFlags |= SAVE_DATA_FLAG_READ_EEPROM_SETTINGS; // Set bit 8 } -//Always called after updating a value in sEepromSettings -void func_8006ECE0(void) { - D_800DD37C |= 0x200; +/** + * Marks a flag to write eeprom settings to flash later + * @bug: Because this is the same bit used for reading save files, + * it will change the save file number to read from + */ +void mark_write_eeprom_settings(void) { + gSaveDataFlags |= SAVE_DATA_FLAG_WRITE_EEPROM_SETTINGS; // Set bit 9 } /** diff --git a/src/game.h b/src/game.h index 00065da5..6a61a9be 100644 --- a/src/game.h +++ b/src/game.h @@ -35,6 +35,41 @@ enum NumberOfPlayers { FOUR_PLAYERS = 3 }; +/** + * Bit 00: Read Eeprom Data flap times + * Bit 01: Read Eeprom Data course times + * Bit 02: Read Save File from bits 8 and 9 + * Bit 03: Read All Save Files + * Bit 04: Write Eeprom Data flap times + * Bit 05: Write Eeprom Data course times + * Bit 06: Write Save Data from bits 10 and 11 + * Bit 07: Erase Save File from bits 10 and 11 + * Bit 08: Read Save File Number Part 1 @bug Also Read Eeprom settings + * Bit 09: Read Save File Number Part 2 @bug Also Write Eeprom Settings + * Bit 10: Write Save File Number Part 1 + * Bit 11: Write Save File Number Part 2 + */ +extern s32 gSaveDataFlags; +#define SAVE_DATA_FLAG_INDEX_VALUE (1 << 0 | 1 << 1) //2 bits for 4 different values + +#define SAVE_DATA_FLAG_READ_FLAP_TIMES (1 << 0) +#define SAVE_DATA_FLAG_READ_COURSE_TIMES (1 << 1) +#define SAVE_DATA_FLAG_READ_SAVE_DATA (1 << 2) +#define SAVE_DATA_FLAG_READ_ALL_SAVE_DATA (1 << 3) +#define SAVE_DATA_FLAG_WRITE_FLAP_TIMES (1 << 4) +#define SAVE_DATA_FLAG_WRITE_COURSE_TIMES (1 << 5) +#define SAVE_DATA_FLAG_WRITE_SAVE_DATA (1 << 6) +#define SAVE_DATA_FLAG_ERASE_SAVE_DATA (1 << 7) +#define SAVE_DATA_FLAG_READ_EEPROM_SETTINGS (1 << 8) //@bug Bits 8 and 9 are reused for checking the read save file number +#define SAVE_DATA_FLAG_WRITE_EEPROM_SETTINGS (1 << 9) // ^^ +#define SAVE_DATA_FLAG_READ_SAVE_FILE_NUMBER_BITS (1 << 8 | 1 << 9) //These are reused as above +#define SAVE_DATA_FLAG_WRITE_SAVE_FILE_NUMBER_BITS (1 << 10 | 1 << 11) + +#define SAVE_DATA_FLAG_READ_EEPROM_INDEX(flags) (flags & (SAVE_DATA_FLAG_READ_FLAP_TIMES | SAVE_DATA_FLAG_READ_COURSE_TIMES)) +#define SAVE_DATA_FLAG_WRITE_EEPROM_INDEX(flags) ((flags & (SAVE_DATA_FLAG_WRITE_FLAP_TIMES | SAVE_DATA_FLAG_WRITE_COURSE_TIMES)) >> 4) +#define SAVE_DATA_FLAG_READ_SAVE_FILE_NUMBER(flags) ((flags >> 8) & SAVE_DATA_FLAG_INDEX_VALUE) +#define SAVE_DATA_FLAG_WRITE_SAVE_FILE_NUMBER(flags) ((flags >> 10) & SAVE_DATA_FLAG_INDEX_VALUE) + Vehicle get_map_default_vehicle(s32 mapId); s32 get_map_available_vehicles(s32 mapId); s8 func_8006B14C(s32 mapId); @@ -88,19 +123,19 @@ s8 is_game_paused(void); s8 is_postrace_viewport_active(void); s32 is_reset_pressed(void); s32 func_8006EB14(void); -void func_8006EB24(void); -void func_8006EB40(void); -void func_8006EB5C(void); -void func_8006EB78(s32 saveFileIndex); -void func_8006EBA8(void); -void func_8006EBC4(void); -void func_8006EBE0(void); -void func_8006EBFC(void); -void func_8006EC18(s32 arg0); -void func_8006EC48(s32 saveFileIndex); -void func_8006ECAC(s32 arg0); -void func_8006ECC4(void); -void func_8006ECE0(void); +void mark_to_read_flap_times(void); +void mark_to_read_course_times(void); +void mark_to_read_flap_and_course_times(void); +void mark_read_save_file(s32 saveFileIndex); +void mark_read_all_save_files(void); +void mark_to_write_flap_times(void); +void mark_to_write_course_times(void); +void mark_to_write_flap_and_course_times(void); +void force_mark_write_save_file(s32 saveFileIndex); +void safe_mark_write_save_file(s32 saveFileIndex); +void mark_save_file_to_erase(s32 saveFileIndex); +void mark_read_eeprom_settings(void); +void mark_write_eeprom_settings(void); s32 check_dmem_validity(void); void func_8006F140(s32 arg0); void func_8006F20C(void); diff --git a/src/game_text.c b/src/game_text.c index c889eb27..c56297cd 100644 --- a/src/game_text.c +++ b/src/game_text.c @@ -6,6 +6,7 @@ #include "objects.h" #include "racer.h" #include "game.h" +#include "controller.h" /************ .data ************/ diff --git a/src/game_ui.c b/src/game_ui.c index 57164365..770e775f 100644 --- a/src/game_ui.c +++ b/src/game_ui.c @@ -20,6 +20,7 @@ #include "audiosfx.h" #include "printf.h" #include "unknown_008C40.h" +#include "controller.h" extern u32 osTvType; diff --git a/src/menu.c b/src/menu.c index 7b87ea0c..11f2f82a 100644 --- a/src/menu.c +++ b/src/menu.c @@ -30,6 +30,7 @@ #include "unknown_078050.h" #include "unknown_0255E0.h" #include "lib/src/mips1/al/alSynStartVoiceParams.h" +#include "controller.h" /** * @file Contains all the code used for every menu in the game. @@ -104,8 +105,8 @@ s32 gTrackSelectViewPortX; s32 gTrackSelectViewportY; s32 D_80126484; s32 D_80126488; -s32 D_8012648C; -s32 D_80126490; +s32 gSaveFileIndex3; +s32 gSaveFileIndex2; s32 D_80126494; s32 D_80126498; s32 D_8012649C; @@ -3049,7 +3050,7 @@ void menu_save_options_init(void) { D_800DFC50[0].texture = D_80126550[TEXTURE_ICON_SAVE_CPAK]; D_800DFC60[0].texture = D_80126550[TEXTURE_ICON_SAVE_BIN]; func_8008E4B0(); - func_8006EBA8(); + mark_read_all_save_files(); transition_begin(&sMenuTransitionFadeOut); } @@ -3220,7 +3221,7 @@ s32 func_800867D4(void) { switch (D_80126A0C[D_80126BD4].unk0) { case 1: //Some other type of game data? - func_8006EB78(D_80126A0C[D_80126BD4].controllerIndex); + mark_read_save_file(D_80126A0C[D_80126BD4].controllerIndex); func_800861C8(D_80126A04, &D_80126A00); ret = func_800860A8(0, &D_80126A18, D_80126A04, &D_80126A00, get_game_data_file_size(), -1); break; @@ -4719,7 +4720,7 @@ void menu_game_select_init(void) { D_800DF460 = 0; D_801263E0 = 2; transition_begin(&sMenuTransitionFadeOut); - func_8006EBA8(); + mark_read_all_save_files(); func_8001B790(); gOpacityDecayTimer = 1; func_8009C6D4(0x43); @@ -4892,7 +4893,7 @@ void menu_file_select_init(void) { func_8009C674(D_800E0398); allocate_menu_images(D_800E03A4); func_8007FFEC(6); - func_8006EBA8(); + mark_read_all_save_files(); gOpacityDecayTimer = 1; gSaveFileIndex = 0; gMenuDelay = 0; @@ -5010,12 +5011,12 @@ void render_file_select_menu(UNUSED s32 updateRate) { for (i = 0; i < 3; i++) { s2 = FALSE; if (D_80126484 != FALSE) { - if (D_80126494 == 0 && i == D_8012648C) { + if (D_80126494 == 0 && i == gSaveFileIndex3) { s2 = TRUE; - } else if (D_80126494 > 0 && i == D_80126490) { + } else if (D_80126494 > 0 && i == gSaveFileIndex2) { s2 = TRUE; } - } else if (D_80126488 != FALSE && i == D_8012648C) { + } else if (D_80126488 != FALSE && i == gSaveFileIndex3) { s2 = TRUE; } else if (D_801263E0 == 0 && i == gSaveFileIndex) { s2 = TRUE; @@ -5110,13 +5111,13 @@ s32 func_8008D5F8(UNUSED s32 updateRate) { return 1; case 1: play_sound_global(SOUND_SELECT2, NULL); - D_8012648C = gSaveFileIndex; + gSaveFileIndex3 = gSaveFileIndex; D_80126484 = TRUE; D_80126494 = 0; return 0; case 2: play_sound_global(SOUND_SELECT2, NULL); - D_8012648C = gSaveFileIndex; + gSaveFileIndex3 = gSaveFileIndex; D_80126488 = TRUE; D_80126494 = 0; return 0; @@ -5192,35 +5193,35 @@ void func_8008D8BC(UNUSED s32 updateRate) { return; } if (buttonsPressed & (A_BUTTON | START_BUTTON)) { - if (gSavefileInfo[D_8012648C].isStarted) { + if (gSavefileInfo[gSaveFileIndex3].isStarted) { play_sound_global(SOUND_SELECT2, NULL); - func_8006EB78(D_8012648C); - D_80126490 = D_8012648C; + mark_read_save_file(gSaveFileIndex3); + gSaveFileIndex2 = gSaveFileIndex3; D_80126494 = 1; return; } play_sound_global(SOUND_MENU_BACK3, NULL); return; } - prevValue = D_8012648C; - if ((xAxisDirection < 0) && (D_8012648C > 0)) { - D_8012648C--; + prevValue = gSaveFileIndex3; + if ((xAxisDirection < 0) && (gSaveFileIndex3 > 0)) { + gSaveFileIndex3--; } - if ((xAxisDirection > 0) && (D_8012648C < 2)) { - D_8012648C++; + if ((xAxisDirection > 0) && (gSaveFileIndex3 < 2)) { + gSaveFileIndex3++; } - if (prevValue != D_8012648C) { + if (prevValue != gSaveFileIndex3) { play_sound_global(SOUND_MENU_PICK2, NULL); } } else if (D_80126494 == 1) { if (buttonsPressed & B_BUTTON) { play_sound_global(SOUND_MENU_BACK3, NULL); - D_8012648C = D_80126490; + gSaveFileIndex3 = gSaveFileIndex2; D_80126494 = 0; return; } if (buttonsPressed & (A_BUTTON | START_BUTTON)) { - if (!gSavefileInfo[D_80126490].isStarted) { + if (!gSavefileInfo[gSaveFileIndex2].isStarted) { play_sound_global(SOUND_SELECT2, NULL); D_80126494 = 2; return; @@ -5228,31 +5229,31 @@ void func_8008D8BC(UNUSED s32 updateRate) { play_sound_global(SOUND_MENU_BACK3, NULL); return; } - prevValue = D_80126490; - if ((xAxisDirection < 0) && (D_80126490 > 0)) { - D_80126490--; + prevValue = gSaveFileIndex2; + if ((xAxisDirection < 0) && (gSaveFileIndex2 > 0)) { + gSaveFileIndex2--; } - if ((xAxisDirection > 0) && (D_80126490 < 2)) { - D_80126490++; + if ((xAxisDirection > 0) && (gSaveFileIndex2 < 2)) { + gSaveFileIndex2++; } - if (prevValue != D_80126490) { + if (prevValue != gSaveFileIndex2) { play_sound_global(SOUND_MENU_PICK2, NULL); } } else { if (buttonsPressed & (A_BUTTON | START_BUTTON)) { play_sound_global(SOUND_SELECT2, NULL); - func_8006EC18(D_80126490); - gSavefileInfo[D_80126490].isAdventure2 = FALSE; - gSavefileInfo[D_80126490].isStarted = TRUE; - gSavefileInfo[D_80126490].balloonCount = *settings->balloonsPtr; + force_mark_write_save_file(gSaveFileIndex2); + gSavefileInfo[gSaveFileIndex2].isAdventure2 = FALSE; + gSavefileInfo[gSaveFileIndex2].isStarted = TRUE; + gSavefileInfo[gSaveFileIndex2].balloonCount = *settings->balloonsPtr; if (settings->cutsceneFlags & CUTSCENE_ADVENTURE_TWO) { - gSavefileInfo[D_80126490].isAdventure2 = TRUE; + gSavefileInfo[gSaveFileIndex2].isAdventure2 = TRUE; } - for (i = 0; gSavefileInfo[D_8012648C].name[i] != '\0'; i++) { - gSavefileInfo[D_80126490].name[i] = gSavefileInfo[D_8012648C].name[i]; + for (i = 0; gSavefileInfo[gSaveFileIndex3].name[i] != '\0'; i++) { + gSavefileInfo[gSaveFileIndex2].name[i] = gSavefileInfo[gSaveFileIndex3].name[i]; } - gSavefileInfo[D_80126490].name[i] = '\0'; - gSaveFileIndex = D_80126490; + gSavefileInfo[gSaveFileIndex2].name[i] = '\0'; + gSaveFileIndex = gSaveFileIndex2; D_801263E0 = 0; D_80126484 = FALSE; return; @@ -5283,7 +5284,7 @@ void func_8008DC7C(UNUSED s32 updateRate) { D_80126488 = FALSE; return; } else if (buttonsPressed & (A_BUTTON | START_BUTTON)) { - if (gSavefileInfo[D_8012648C].isStarted != 0) { + if (gSavefileInfo[gSaveFileIndex3].isStarted != 0) { play_sound_global(SOUND_SELECT2, NULL); D_80126494 = 1; return; @@ -5292,37 +5293,37 @@ void func_8008DC7C(UNUSED s32 updateRate) { return; } - temp = D_8012648C; + temp = gSaveFileIndex3; //Left if (controllerXAxisDirection < 0) { - if (D_8012648C > 0) { - D_8012648C--; + if (gSaveFileIndex3 > 0) { + gSaveFileIndex3--; } } //Right if (controllerXAxisDirection > 0) { - if (D_8012648C < 2) { - D_8012648C++; + if (gSaveFileIndex3 < 2) { + gSaveFileIndex3++; } } - if (D_8012648C != temp) { + if (gSaveFileIndex3 != temp) { play_sound_global(SOUND_MENU_PICK2, NULL); } } else { if (buttonsPressed & (A_BUTTON | START_BUTTON)) { play_sound_global(SOUND_SELECT2, NULL); - func_8006ECAC(D_8012648C); - gSavefileInfo[D_8012648C].isAdventure2 = 0; - gSavefileInfo[D_8012648C].isStarted = 0; - gSavefileInfo[D_8012648C].balloonCount = 0; - gSavefileInfo[D_8012648C].name[0] = 'D'; - gSavefileInfo[D_8012648C].name[1] = 'K'; - gSavefileInfo[D_8012648C].name[2] = 'R'; - gSavefileInfo[D_8012648C].name[3] = '\0'; - gSaveFileIndex = D_8012648C; + mark_save_file_to_erase(gSaveFileIndex3); + gSavefileInfo[gSaveFileIndex3].isAdventure2 = 0; + gSavefileInfo[gSaveFileIndex3].isStarted = 0; + gSavefileInfo[gSaveFileIndex3].balloonCount = 0; + gSavefileInfo[gSaveFileIndex3].name[0] = 'D'; + gSavefileInfo[gSaveFileIndex3].name[1] = 'K'; + gSavefileInfo[gSaveFileIndex3].name[2] = 'R'; + gSavefileInfo[gSaveFileIndex3].name[3] = '\0'; + gSaveFileIndex = gSaveFileIndex3; D_801263E0 = 0; D_80126488 = FALSE; } else if (buttonsPressed & B_BUTTON) { @@ -5400,7 +5401,7 @@ s32 menu_file_select_loop(s32 updateRate) { gSavefileInfo[gSaveFileIndex].isStarted = 1; gSavefileInfo[gSaveFileIndex].balloonCount = 0; settings->filename = compress_filename_string(gSavefileInfo[gSaveFileIndex].name, 3); - func_8006EB78(gSaveFileIndex); + mark_read_save_file(gSaveFileIndex); set_music_fade_timer(-128); transition_begin(&sMenuTransitionFadeIn); gMenuDelay = 1; @@ -5411,8 +5412,8 @@ s32 menu_file_select_loop(s32 updateRate) { if (currentMenuDelay > 0) { if (gSavefileInfo[gSaveFileIndex].isStarted != 0) { play_sound_global(SOUND_SELECT2, NULL); - func_8006EB78(gSaveFileIndex); - set_music_fade_timer(-0x80); + mark_read_save_file(gSaveFileIndex); + set_music_fade_timer(-128); } else { D_80126CC0 = 1; D_800E0FB0 = 0; @@ -8310,7 +8311,7 @@ s32 get_multiplayer_racer_count(void) { return (gMultiplayerSelectedNumberOfRacers + 1) << 1; // Doesn't match with multiply. } -Settings **func_8009C490(void) { +Settings **get_all_save_files_ptr(void) { return (Settings **)gSavefileData; } @@ -9071,13 +9072,13 @@ u64 *get_eeprom_settings_pointer(void) { s32 set_eeprom_settings_value(u64 valueToSet) { sEepromSettings |= valueToSet; - func_8006ECE0(); + mark_write_eeprom_settings(); return TRUE; } s32 unset_eeprom_settings_value(u64 valueToUnset) { sEepromSettings &= ~valueToUnset; - func_8006ECE0(); + mark_write_eeprom_settings(); return TRUE; } @@ -9129,7 +9130,7 @@ void set_language(s32 language) { sEepromSettings |= langFlag; //Then set them according to the selected lang load_menu_text(language); - func_8006ECE0(); + mark_write_eeprom_settings(); } /** diff --git a/src/menu.h b/src/menu.h index c8b24412..f0230fc7 100644 --- a/src/menu.h +++ b/src/menu.h @@ -818,7 +818,7 @@ s32 get_filtered_cheats(void); s32 get_number_of_active_players(void); s32 get_active_player_count(void); s32 get_multiplayer_racer_count(void); -Settings** func_8009C490(void); +Settings **get_all_save_files_ptr(void); void func_8009C49C(void); void func_8009C4A8(s16 *arg0); void func_8009C508(s32 arg0); diff --git a/src/object_functions.c b/src/object_functions.c index e9196232..15bfbf88 100644 --- a/src/object_functions.c +++ b/src/object_functions.c @@ -30,6 +30,7 @@ #include "object_models.h" #include "lib/src/libc/rmonPrintf.h" #include "collision.h" +#include "controller.h" /************ .data ************/ diff --git a/src/racer.c b/src/racer.c index 47e97f3c..b495e567 100644 --- a/src/racer.c +++ b/src/racer.c @@ -26,6 +26,7 @@ #include "object_models.h" #include "audiosfx.h" #include "collision.h" +#include "controller.h" #define MAX_NUMBER_OF_GHOST_NODES 360 diff --git a/src/save_data.c b/src/save_data.c index 65d47a43..dee21ab7 100644 --- a/src/save_data.c +++ b/src/save_data.c @@ -11,6 +11,7 @@ #include "objects.h" #include "game.h" #include "unknown_0CEC50.h" +#include "controller.h" /************ .data ************/ @@ -220,7 +221,7 @@ void func_80072708(void) { D_800DE48C = 3; } -void rumble_controllers(s32 arg0) { +void rumble_controllers(s32 updateRate) { unk_801241B8 *temp; s32 pfsStatus; u8 i; @@ -228,7 +229,7 @@ void rumble_controllers(s32 arg0) { u8 pfsBitPattern; if ((D_801241E6 != 0) || ((D_800DE48C != 0))) { - gRumbleDetectionTimer += arg0; + gRumbleDetectionTimer += updateRate; if (gRumbleDetectionTimer >= 121) { gRumbleDetectionTimer = 0; osPfsIsPlug(sControllerMesgQueue, &pfsBitPattern); @@ -264,8 +265,8 @@ void rumble_controllers(s32 arg0) { temp->unk8 = 0; osMotorStop(&pfs[i]); } else { - temp->unk4 -= arg0; - temp->unk8 += arg0; + temp->unk4 -= updateRate; + temp->unk8 += updateRate; if (temp->unk8 < 0) { continue; } else if (temp->unk8 >= 601) { @@ -792,7 +793,7 @@ s32 read_time_data_from_controller_pak(s32 controllerIndex, char *fileExt, Setti status = read_data_from_controller_pak(controllerIndex, fileNumber, (u8 *)cpakData, fileSize); if (status == CONTROLLER_PAK_GOOD) { if (*cpakData == TIMD) { - func_80073588(settings, (u8 *) (cpakData + 1), 3); + func_80073588(settings, (u8 *) (cpakData + 1), SAVE_DATA_FLAG_READ_FLAP_TIMES | SAVE_DATA_FLAG_READ_COURSE_TIMES); } else { status = CONTROLLER_PAK_BAD_DATA; } @@ -833,7 +834,7 @@ s32 write_time_data_to_controller_pak(s32 controllerIndex, Settings *arg1) { } // Returns TRUE / FALSE for whether a given save file is a new game. Also populates the settings object. -s32 func_80074204(s32 saveFileNum, Settings *settings) { +s32 read_save_file(s32 saveFileNum, Settings *settings) { s32 startingAddress; u64 *saveData; s32 address; @@ -975,11 +976,11 @@ s32 write_save_data(s32 saveFileNum, Settings *settings) { /** * Read Eeprom Data for addresses 0x10 - 0x39 * arg1 is a flag - * arg1 is descended from (D_800DD37C & 3) so the first 2 bits of that value. - * bit 1 is for 0x10 - 0x27 - * bit 2 is for 0x28 - 0x39 + * arg1 is descended from (gSaveDataFlags & 3) so the first 2 bits of that value. + * bit 1 is for 0x10 - 0x27 - SAVE_DATA_FLAG_READ_FLAP_TIMES + * bit 2 is for 0x28 - 0x39 - SAVE_DATA_FLAG_READ_COURSE_TIMES */ -s32 read_eeprom_data(Settings *arg0, u8 arg1) { +s32 read_eeprom_data(Settings *settings, u8 flags) { u64 *alloc; s32 i; @@ -989,20 +990,20 @@ s32 read_eeprom_data(Settings *arg0, u8 arg1) { alloc = allocate_from_main_pool_safe(0x200, COLOUR_TAG_WHITE); - if (arg1 & 1) { + if (flags & SAVE_DATA_FLAG_READ_FLAP_TIMES) { s32 blocks = 24; for (i = 0; i < blocks; i++) { osEepromRead(get_si_mesg_queue(), i + 0x10, (u8 *)&alloc[i]); } - func_80073588(arg0, (u8 *) alloc, 1); + func_80073588(settings, (u8 *) alloc, SAVE_DATA_FLAG_READ_FLAP_TIMES); } - if (arg1 & 2) { + if (flags & SAVE_DATA_FLAG_READ_COURSE_TIMES) { s32 blocks = 24; for (i = 0; i < blocks; i++) { osEepromRead(get_si_mesg_queue(), i + 0x28, (u8 *)(&alloc[24] + i)); } - func_80073588(arg0, (u8 *) alloc, 2); + func_80073588(settings, (u8 *) alloc, SAVE_DATA_FLAG_READ_COURSE_TIMES); } free_from_memory_pool(alloc); @@ -1013,10 +1014,11 @@ s32 read_eeprom_data(Settings *arg0, u8 arg1) { * Write Eeprom Data for addresses 0x10 - 0x39 * 0x80 - 0x1C8 in file * arg1 is a flag - * bit 1 is for 0x10 - 0x27 - * bit 2 is for 0x28 - 0x39 + * arg1 is descended from gSaveDataFlags bits 4 and 5. + * bit 1 is for 0x10 - 0x27 - SAVE_DATA_FLAG_READ_FLAP_TIMES + * bit 2 is for 0x28 - 0x39 - SAVE_DATA_FLAG_READ_COURSE_TIMES */ -s32 write_eeprom_data(Settings *arg0, u8 arg1) { +s32 write_eeprom_data(Settings *settings, u8 flags) { u64 *alloc; s32 i; @@ -1026,9 +1028,9 @@ s32 write_eeprom_data(Settings *arg0, u8 arg1) { alloc = allocate_from_main_pool_safe(0x200, COLOUR_TAG_WHITE); - func_800738A4(arg0, (u8 *)alloc); + func_800738A4(settings, (u8 *)alloc); - if (arg1 & 1) { + if (flags & SAVE_DATA_FLAG_READ_FLAP_TIMES) { s32 size = 24; if (1){} //Fake Match if (!is_reset_pressed()) { @@ -1038,7 +1040,7 @@ s32 write_eeprom_data(Settings *arg0, u8 arg1) { } } - if (arg1 & 2) { + if (flags & SAVE_DATA_FLAG_READ_COURSE_TIMES) { s32 size = 24; if (!is_reset_pressed()) { for (i = 0; i != size; i++) { @@ -1992,7 +1994,7 @@ SIDeviceStatus write_controller_pak_file(s32 controllerIndex, s32 fileNumber, ch u32 game_code; ret = get_si_device_status(controllerIndex); - if (ret != 0) { + if (ret != CONTROLLER_PAK_GOOD) { start_reading_controller_data(controllerIndex); return ret; } diff --git a/src/save_data.h b/src/save_data.h index d08d1724..d304842b 100644 --- a/src/save_data.h +++ b/src/save_data.h @@ -21,6 +21,8 @@ // This is RARE's unique code #define COMPANY_CODE 0x3459 +#define NUMBER_OF_SAVE_FILES 3 + typedef enum { CONTROLLER_PAK_GOOD, NO_CONTROLLER_PAK, @@ -51,8 +53,8 @@ s32 write_game_data_to_controller_pak(s32 controllerIndex, Settings *arg1); s32 read_time_data_from_controller_pak(s32 controllerIndex, char *fileExt, Settings *settings); s32 write_time_data_to_controller_pak(s32 controllerIndex, Settings *arg1); s32 write_save_data(s32 saveFileNum, Settings *settings); -s32 read_eeprom_data(Settings *arg0, u8 arg1); -s32 write_eeprom_data(Settings *arg0, u8 arg1); +s32 read_eeprom_data(Settings *settings, u8 flags); +s32 write_eeprom_data(Settings *settings, u8 flags); s32 calculate_eeprom_settings_checksum(u64 eepromSettings); s32 read_eeprom_settings(u64 *eepromSettings); s32 write_eeprom_settings(u64 *eepromSettings); @@ -78,12 +80,12 @@ s32 get_file_type(s32 controllerIndex, s32 fileNum); void func_80072578(s16 controllerIndex, s16 arg1, s16 arg2); void func_80072348(s16 controllerIndex, u8 arg1); void func_80072424(s16 controllerIndex, u8 arg1, f32 arg2); -void rumble_controllers(s32 arg0); +void rumble_controllers(s32 updateRate); void init_controller_paks(void); void func_80072E28(s32 arg0, u32 arg1); s32 func_80072C54(s32 arg0); void populate_settings_from_save_data(Settings *settings, u8 *saveData); -s32 func_80074204(s32 saveFileNum, Settings *settings); +s32 read_save_file(s32 saveFileNum, Settings *settings); void erase_save_file(s32 saveFileNum, Settings *settings); SIDeviceStatus func_800756D4(s32 controllerIndex, u8 *arg1, u8 *arg2, u8 *arg3, s16 *arg4); SIDeviceStatus get_file_extension(s32 controllerIndex, s32 fileType, char *fileExt); diff --git a/src/vehicle_tricky.c b/src/vehicle_tricky.c index 9c4fadac..4426284a 100644 --- a/src/vehicle_tricky.c +++ b/src/vehicle_tricky.c @@ -365,7 +365,7 @@ void func_8005CB68(Object_Racer *racer, s8 *arg1) { func_8006F140(3); } arg1_ret++; - func_8006EC48(get_save_file_index()); + safe_mark_write_save_file(get_save_file_index()); } *arg1 = arg1_ret; }