diff --git a/.gitignore b/.gitignore index 1c87df7fb5..e2250c285d 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ ctx_includes.h *.s.c objdiff.json compile_commands.json +.pi-sessions/ # decompctx output ctx.* diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f3b083d956..aedb30cf9f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,7 +8,7 @@ repos: hooks: - id: style-check name: style-check - entry: python tools/check/main.py --fix --quiet + entry: python3 tools/check/main.py --fix --quiet language: system pass_filenames: true types_or: [c] diff --git a/config/GALE01/splits.txt b/config/GALE01/splits.txt index 5cdeca9c91..5ff02c0a00 100644 --- a/config/GALE01/splits.txt +++ b/config/GALE01/splits.txt @@ -1269,6 +1269,7 @@ melee/ft/chara/ftKirby/ftkirby.c: .text start:0x800EE528 end:0x800F1F68 .rodata start:0x803B7548 end:0x803B7570 .data start:0x803C8368 end:0x803CB6D8 + .sdata start:0x804D3D98 end:0x804D3DAC .sdata2 start:0x804D9350 end:0x804D9364 melee/ft/chara/ftKirby/ftkirbyattackdash.c: @@ -1352,6 +1353,7 @@ melee/ft/chara/ftKirby/ftkirbyyoshiegg.c: melee/ft/chara/ftKirby/ftkirbyspecialmars.c: .text start:0x8010B1F4 end:0x8010C288 + .sdata start:0x804D3E00 end:0x804D3E0D .sdata2 start:0x804D9570 end:0x804D9580 melee/ft/chara/ftKirby/ftkirbyspecialpeach.c: @@ -2317,11 +2319,17 @@ melee/gm/gm_1A7A.c: .sdata2 start:0x804DAA18 end:0x804DAA28 melee/gm/gmregenddisp.c: - .text start:0x801A7FB4 end:0x801A9DD0 - .data start:0x803DB458 end:0x803DBF78 + .text start:0x801A7FB4 end:0x801A9B30 + .data start:0x803DB458 end:0x803DB640 .bss start:0x80480A00 end:0x80480B38 .sdata start:0x804D42A0 end:0x804D42B8 - .sdata2 start:0x804DAA28 end:0x804DAAA8 + .sdata2 start:0x804DAA28 end:0x804DAAA0 + +melee/gm/gm_1A9B.c: + .text start:0x801A9B30 end:0x801A9DD0 + .data start:0x803DB640 end:0x803DBF78 + .sbss start:0x804D67C8 end:0x804D67CA + .sdata2 start:0x804DAAA0 end:0x804DAAA8 melee/gm/gmopening.c: .text start:0x801A9DD0 end:0x801AA644 @@ -2480,7 +2488,7 @@ melee/gm/gm_1BA8.c: .bss start:0x80497758 end:0x8049E558 .sdata start:0x804D4330 end:0x804D44C8 .sbss start:0x804D6900 end:0x804D6940 - .sdata2 start:0x804DAC78 end:0x804DAC88 + .sdata2 start:0x804DAC78 end:0x804DAC8C melee/gm/gm_1BF9.c: .text start:0x801BF948 end:0x801BFA6C @@ -2660,7 +2668,7 @@ melee/gr/gricemt.c: melee/gr/grinishie1.c: .text start:0x801FA908 end:0x801FCBC0 - .rodata start:0x803B8268 end:0x803B8278 + .rodata start:0x803B8268 end:0x803B8274 .data start:0x803E48C8 end:0x803E4A60 .sdata start:0x804D4748 end:0x804D4760 .sbss start:0x804D69F8 end:0x804D6A00 @@ -4359,6 +4367,7 @@ melee/if/soundtest.c: .text start:0x802FF7DC end:0x80301E44 .data start:0x803F9F28 end:0x803FDC20 .sdata start:0x804D5850 end:0x804D5A40 + .sdata2 start:0x804DDC40 end:0x804DDC48 melee/if/textdraw.c: .text start:0x80301E44 end:0x803029B4 diff --git a/config/GALE01/symbols.txt b/config/GALE01/symbols.txt index 54c4c618b4..fae36294aa 100644 --- a/config/GALE01/symbols.txt +++ b/config/GALE01/symbols.txt @@ -20050,7 +20050,7 @@ lbl_803B7888 = .rodata:0x803B7888; // type:object size:0x1C data:byte lbl_803B78A4 = .rodata:0x803B78A4; // type:object size:0x24 data:byte lbl_803B78C8 = .rodata:0x803B78C8; // type:object size:0x42 data:byte lbl_803B790C = .rodata:0x803B790C; // type:object size:0x21 data:byte -lbl_803B7930 = .rodata:0x803B7930; // type:object size:0x48 data:float +gm_HandicapDamageRatios = .rodata:0x803B7930; // type:object size:0x48 data:float lbl_803B7978 = .rodata:0x803B7978; // type:object size:0x44 data:2byte lbl_803B79BC = .rodata:0x803B79BC; // type:object size:0x44 data:2byte lbl_803B7A00 = .rodata:0x803B7A00; // type:object size:0x44 data:2byte @@ -20089,8 +20089,8 @@ grCs_803B7EB8 = .rodata:0x803B7EB8; // type:object size:0x10 scope:global data:4 grCs_803B7EC8 = .rodata:0x803B7EC8; // type:object size:0x26 scope:global data:2byte grCs_803B7EF0 = .rodata:0x803B7EF0; // type:object size:0xC scope:global data:4byte grCs_803B7EFC = .rodata:0x803B7EFC; // type:object size:0x2C scope:global data:4byte -grCs_803B7F28 = .rodata:0x803B7F28; // type:object size:0x14 scope:global data:4byte -grCs_803B7F3C = .rodata:0x803B7F3C; // type:object size:0x14 scope:global data:4byte +grCastle_DmgReceivedCallbacks = .rodata:0x803B7F28; // type:object size:0x14 scope:global data:4byte +grCastle_TouchedCallbacks = .rodata:0x803B7F3C; // type:object size:0x14 scope:global data:4byte grCs_803B7F50 = .rodata:0x803B7F50; // type:object size:0x18 scope:global data:4byte grPs_803B7F68 = .rodata:0x803B7F68; // type:object size:0xC scope:global data:4byte grPs_803B7F74 = .rodata:0x803B7F74; // type:object size:0xC scope:global data:4byte @@ -20098,7 +20098,7 @@ grPs_803B7F80 = .rodata:0x803B7F80; // type:object size:0xC scope:global data:fl grPs_803B7F8C = .rodata:0x803B7F8C; // type:object size:0x10 scope:global data:4byte grPs_803B7F9C = .rodata:0x803B7F9C; // type:object size:0x14 scope:global data:4byte grKg_803B7FB0 = .rodata:0x803B7FB0; // type:object size:0x24 scope:global data:4byte -grKg_803B7FD4 = .rodata:0x803B7FD4; // type:object size:0x1C scope:global data:4byte +grKg_SplineChoices = .rodata:0x803B7FD4; // type:object size:0x1C scope:global data:4byte grZe_803B7FF0 = .rodata:0x803B7FF0; // type:object size:0x3C scope:global data:4byte grZe_803B802C = .rodata:0x803B802C; // type:object size:0xC scope:global data:4byte grZe_803B8038 = .rodata:0x803B8038; // type:object size:0xC scope:global data:4byte @@ -20120,7 +20120,7 @@ grGb_803B81C8 = .rodata:0x803B81C8; // type:object size:0xC scope:global data:4b grGb_803B81D4 = .rodata:0x803B81D4; // type:object size:0x4C scope:global data:4byte grIm_803B8220 = .rodata:0x803B8220; // type:object size:0x3C scope:global data:4byte grIm_803B825C = .rodata:0x803B825C; // type:object size:0xA scope:global data:2byte -grI1_803B8268 = .rodata:0x803B8268; // type:object size:0x10 scope:global data:4byte +grInishie1_HatenaItemSpawnVel = .rodata:0x803B8268; // type:object size:0xC scope:global data:4byte grKr_803B8278 = .rodata:0x803B8278; // type:object size:0xC scope:global data:4byte grRc_803B8288 = .rodata:0x803B8288; // type:object size:0xC scope:global align:8 data:float @213 = .rodata:0x803B8298; // type:object size:0xC scope:local data:4byte @@ -22189,9 +22189,9 @@ lbl_803D8C80 = .data:0x803D8C80; // type:object size:0x2D data:string lbl_803D8CB0 = .data:0x803D8CB0; // type:object size:0xA data:string lbl_803D8CBC = .data:0x803D8CBC; // type:object size:0xE data:string lbl_803D8CCC = .data:0x803D8CCC; // type:object size:0xA data:string -lbl_803D8CD8 = .data:0x803D8CD8; // type:object size:0x9 data:string -lbl_803D8CE4 = .data:0x803D8CE4; // type:object size:0x16 data:string -lbl_803D8CFC = .data:0x803D8CFC; // type:object size:0x9 data:string +gmRegClear_ArchiveNoContinue = .data:0x803D8CD8; // type:object size:0x9 data:string +gmRegClear_SceneModelsSymbol = .data:0x803D8CE4; // type:object size:0x16 data:string +gmRegClear_ArchiveRecord = .data:0x803D8CFC; // type:object size:0x9 data:string lbl_803D8D08 = .data:0x803D8D08; // type:object size:0x480 lbl_803D9188 = .data:0x803D9188; // type:object size:0xD data:string lbl_803D9198 = .data:0x803D9198; // type:object size:0x19 data:string @@ -22405,7 +22405,7 @@ gm_803DB854 = .data:0x803DB854; // type:object size:0x1A scope:global data:strin gm_803DB870 = .data:0x803DB870; // type:object size:0x16 scope:global data:string gm_803DB888 = .data:0x803DB888; // type:object size:0x18 scope:global data:string gm_803DB8A0 = .data:0x803DB8A0; // type:object size:0x18 data:string -gm_803DB8B8 = .data:0x803DB8B8; // type:object size:0x68 scope:global +gmRegend_SimpleThpFiles = .data:0x803DB8B8; // type:object size:0x68 scope:local gm_803DB920 = .data:0x803DB920; // type:object size:0x1D scope:global data:string gm_803DB940 = .data:0x803DB940; // type:object size:0x1C scope:global data:string gm_803DB95C = .data:0x803DB95C; // type:object size:0x19 scope:global data:string @@ -22431,7 +22431,7 @@ gm_803DBB80 = .data:0x803DBB80; // type:object size:0x1D scope:global data:strin gm_803DBBA0 = .data:0x803DBBA0; // type:object size:0x19 scope:global data:string gm_803DBBBC = .data:0x803DBBBC; // type:object size:0x1B scope:global data:string gm_803DBBD8 = .data:0x803DBBD8; // type:object size:0x1B data:string -gm_803DBBF4 = .data:0x803DBBF4; // type:object size:0x68 scope:global +gmRegend_AdventureThpFiles = .data:0x803DBBF4; // type:object size:0x68 scope:local gm_803DBC5C = .data:0x803DBC5C; // type:object size:0x1B scope:global data:string gm_803DBC78 = .data:0x803DBC78; // type:object size:0x1A scope:global data:string gm_803DBC94 = .data:0x803DBC94; // type:object size:0x17 scope:global data:string @@ -22457,7 +22457,7 @@ gm_803DBEA4 = .data:0x803DBEA4; // type:object size:0x1B scope:global data:strin gm_803DBEC0 = .data:0x803DBEC0; // type:object size:0x17 scope:global data:string gm_803DBED8 = .data:0x803DBED8; // type:object size:0x19 scope:global data:string gm_803DBEF4 = .data:0x803DBEF4; // type:object size:0x19 scope:global data:string -gm_803DBF10 = .data:0x803DBF10; // type:object size:0x68 scope:global +gmRegend_AllstarThpFiles = .data:0x803DBF10; // type:object size:0x68 scope:local unused_floats = .data:0x803DBF78; // type:object size:0x24 scope:local data:float ...data.0 = .data:0x803DBF78; // type:label scope:local @191 = .data:0x803DBF9C; // type:object size:0xC scope:local data:string @@ -22701,7 +22701,7 @@ grZe_803E1B60 = .data:0x803E1B60; // type:object size:0x24 scope:global data:str grZe_803E1B90 = .data:0x803E1B90; // type:object size:0xF0 scope:global grZe_803E1C80 = .data:0x803E1C80; // type:object size:0x60 scope:global grZe_803E1CE0 = .data:0x803E1CE0; // type:object size:0xC scope:global data:string -grZe_803E1CEC = .data:0x803E1CEC; // type:object size:0xA scope:global data:string +grZe_803E1CEC = .data:0x803E1CEC; // type:object size:0xB scope:global data:string grZe_803E1CF8 = .data:0x803E1CF8; // type:object size:0x30 scope:global grZe_803E1D28 = .data:0x803E1D28; // type:object size:0xA scope:global data:string grCn_803E1D38 = .data:0x803E1D38; // type:object size:0x30 scope:global @@ -22816,7 +22816,10 @@ grI1_803E48C8 = .data:0x803E48C8; // type:object size:0x2C scope:global grI1_803E48F4 = .data:0x803E48F4; // type:object size:0x50 scope:global grI1_803E4944 = .data:0x803E4944; // type:object size:0xA scope:global data:string grI1_803E4950 = .data:0x803E4950; // type:object size:0x58 scope:global -grI1_803E49A8 = .data:0x803E49A8; // type:object size:0x88 scope:global +grI1_803E49A8 = .data:0x803E49A8; // type:object size:0xD scope:global data:string +block_idx_table = .data:0x803E49B8; // type:object size:0x4C scope:global +grI1_803E4A04 = .data:0x803E4A04; // type:object size:0xF scope:global data:string +grI1_803E4A14 = .data:0x803E4A14; // type:object size:0x1B scope:global data:string grI1_803E4A30 = .data:0x803E4A30; // type:object size:0x24 scope:global data:string grI1_803E4A54 = .data:0x803E4A54; // type:object size:0x9 scope:global data:string grI2_803E4A60 = .data:0x803E4A60; // type:object size:0x54 scope:global @@ -22870,13 +22873,20 @@ grGd_803E5248 = .data:0x803E5248; // type:object size:0x8C scope:global grGd_803E52E0 = .data:0x803E52E0; // type:object size:0x34 scope:global @181 = .data:0x803E5314; // type:object size:0x21 scope:local data:string @182 = .data:0x803E5338; // type:object size:0xB scope:local data:string -grVe_803E5348 = .data:0x803E5348; // type:object size:0x38 scope:global -grVe_803E5380 = .data:0x803E5380; // type:object size:0xC scope:global data:4byte -grVe_803E538C = .data:0x803E538C; // type:object size:0x140 scope:global -grVe_803E54CC = .data:0x803E54CC; // type:object size:0x58 scope:global +grVe_CollLinks = .data:0x803E5348; // type:object size:0x38 scope:local +grVe_ArwingGroups = .data:0x803E5380; // type:object size:0xC scope:local data:4byte +grVe_Callbacks = .data:0x803E538C; // type:object size:0x140 scope:global +grVe_StageData = .data:0x803E54CC; // type:object size:0x34 scope:global +lbl_803E5500 = .data:0x803E5500; // type:object size:0x22 data:string lbl_803E5524 = .data:0x803E5524; // type:object size:0xA data:string -lbl_803E5530 = .data:0x803E5530; // type:object size:0x150 -grVe_803E5680 = .data:0x803E5680; // type:object size:0x38 scope:global +grVe_AnimIds = .data:0x803E5530; // type:object size:0xD4 scope:local data:4byte +grVe_UserDataErrorMsg = .data:0x803E5604; // type:object size:0x17 scope:local data:string +lbl_803E561C = .data:0x803E561C; // type:object size:0x25 data:string +grVe_StateAnims = .data:0x803E5644; // type:object size:0x28 scope:local data:4byte +grVe_MapAnims = .data:0x803E566C; // type:object size:0x14 scope:local data:4byte +grVe_ArwingJoints = .data:0x803E5680; // type:object size:0x14 scope:local data:4byte +lbl_803E5694 = .data:0x803E5694; // type:object size:0xA data:string +grVe_AnimFlags = .data:0x803E56A0; // type:object size:0x18 scope:local data:4byte grTe_803E56B8 = .data:0x803E56B8; // type:object size:0x4E scope:global ...data.0 = .data:0x803E56B8; // type:label scope:local grTe_803E5708 = .data:0x803E5708; // type:object size:0x50 scope:global @@ -22970,9 +22980,13 @@ grGr_803E76D0 = .data:0x803E76D0; // type:object size:0x58 scope:global grGr_803E7728 = .data:0x803E7728; // type:object size:0xB scope:global data:string grGr_803E7733 = .data:0x803E7733; // type:object size:0xF1 jumptable_803E7824 = .data:0x803E7824; // type:object size:0x1C scope:local -grGr_803E7840 = .data:0x803E7840; // type:object size:0x3C scope:global data:2byte -grGr_803E787C = .data:0x803E787C; // type:object size:0x3C -grGr_803E78B8 = .data:0x803E78B8; // type:object size:0x88 +grGr_blockJObjIds = .data:0x803E7840; // type:object size:0x3C scope:global data:2byte +grGr_blockMapJointIds = .data:0x803E787C; // type:object size:0x3C +@1008 = .data:0x803E78B8; // type:object size:0x2B scope:local data:string +@1009 = .data:0x803E78E4; // type:object size:0x18 scope:local data:string +@1010 = .data:0x803E78FC; // type:object size:0xB scope:local data:string +@1448 = .data:0x803E7908; // type:object size:0x1B scope:local data:string +@1449 = .data:0x803E7924; // type:object size:0x19 scope:local data:string grFz_803E7940 = .data:0x803E7940; // type:object size:0xB4 scope:global grFz_803E79F4 = .data:0x803E79F4; // type:object size:0xA scope:global data:string grFz_803E7A00 = .data:0x803E7A00; // type:object size:0x68 scope:global @@ -23525,44 +23539,44 @@ mnName_803ED650 = .data:0x803ED650; // type:object size:0x16 scope:global data:s mnName_803ED668 = .data:0x803ED668; // type:object size:0xA scope:global data:string mnName_803ED672 = .data:0x803ED672; // type:object size:0x3E6 mnNameNew_803EDA58 = .data:0x803EDA58; // type:object size:0x24 scope:global align:4 data:float -mnNameNew_803EDA7C = .data:0x803EDA7C; // type:object size:0x268 scope:global data:2byte -mnNameNew_803EDCE4 = .data:0x803EDCE4; // type:object size:0x64C scope:global +mnNameNew_KeyMap = .data:0x803EDA7C; // type:object size:0x268 scope:global data:2byte +mnNameNew_GlyphTable = .data:0x803EDCE4; // type:object size:0x64C scope:global mnNameNew_803EE330 = .data:0x803EE330; // type:object size:0xC scope:global jumptable_803EE33C = .data:0x803EE33C; // type:object size:0x20 scope:local -mnNameNew_803EE35C = .data:0x803EE35C; // type:object size:0x18 scope:global data:string +mnNameNew_803EE35C = .data:0x803EE35C; // type:object size:0x16 scope:global data:string mnNameNew_803EE374 = .data:0x803EE374; // type:object size:0xC scope:global data:string -mnNameNew_803EE380 = .data:0x803EE380; // type:object size:0xC scope:global data:string -mnNameNew_803EE38C = .data:0x803EE38C; // type:object size:0x18 scope:global data:string -mnNameNew_803EE3A4 = .data:0x803EE3A4; // type:object size:0x1C scope:global data:string -mnNameNew_803EE3C0 = .data:0x803EE3C0; // type:object size:0x20 scope:global data:string +mnNameNew_803EE380 = .data:0x803EE380; // type:object size:0xA scope:global data:string +mnNameNew_803EE38C = .data:0x803EE38C; // type:object size:0x16 scope:global data:string +mnNameNew_803EE3A4 = .data:0x803EE3A4; // type:object size:0x1A scope:global data:string +mnNameNew_803EE3C0 = .data:0x803EE3C0; // type:object size:0x1E scope:global data:string mnNameNew_803EE3E0 = .data:0x803EE3E0; // type:object size:0x20 scope:global data:string -mnNameNew_803EE400 = .data:0x803EE400; // type:object size:0x1C scope:global data:string -mnNameNew_803EE41C = .data:0x803EE41C; // type:object size:0x18 scope:global data:string -mnNameNew_803EE434 = .data:0x803EE434; // type:object size:0x10 scope:global data:string -mnNameNew_803EE444 = .data:0x803EE444; // type:object size:0x18 scope:global data:string -mnNameNew_803EE45C = .data:0x803EE45C; // type:object size:0x1C scope:global data:string -mnNameNew_803EE478 = .data:0x803EE478; // type:object size:0x20 scope:global data:string -mnNameNew_803EE498 = .data:0x803EE498; // type:object size:0x24 scope:global data:string -mnNameNew_803EE4BC = .data:0x803EE4BC; // type:object size:0x1C scope:global data:string -mnNameNew_803EE4D8 = .data:0x803EE4D8; // type:object size:0x20 scope:global data:string -mnNameNew_803EE4F8 = .data:0x803EE4F8; // type:object size:0x24 scope:global data:string -mnNameNew_803EE51C = .data:0x803EE51C; // type:object size:0x24 scope:global data:string -mnNameNew_803EE540 = .data:0x803EE540; // type:object size:0x1C scope:global data:string -mnNameNew_803EE55C = .data:0x803EE55C; // type:object size:0x20 scope:global data:string -mnNameNew_803EE57C = .data:0x803EE57C; // type:object size:0x24 scope:global data:string +mnNameNew_803EE400 = .data:0x803EE400; // type:object size:0x1A scope:global data:string +mnNameNew_803EE41C = .data:0x803EE41C; // type:object size:0x17 scope:global data:string +mnNameNew_803EE434 = .data:0x803EE434; // type:object size:0xE scope:global data:string +mnNameNew_803EE444 = .data:0x803EE444; // type:object size:0x17 scope:global data:string +mnNameNew_803EE45C = .data:0x803EE45C; // type:object size:0x1B scope:global data:string +mnNameNew_803EE478 = .data:0x803EE478; // type:object size:0x1F scope:global data:string +mnNameNew_803EE498 = .data:0x803EE498; // type:object size:0x21 scope:global data:string +mnNameNew_803EE4BC = .data:0x803EE4BC; // type:object size:0x19 scope:global data:string +mnNameNew_803EE4D8 = .data:0x803EE4D8; // type:object size:0x1D scope:global data:string +mnNameNew_803EE4F8 = .data:0x803EE4F8; // type:object size:0x21 scope:global data:string +mnNameNew_803EE51C = .data:0x803EE51C; // type:object size:0x23 scope:global data:string +mnNameNew_803EE540 = .data:0x803EE540; // type:object size:0x1A scope:global data:string +mnNameNew_803EE55C = .data:0x803EE55C; // type:object size:0x1E scope:global data:string +mnNameNew_803EE57C = .data:0x803EE57C; // type:object size:0x22 scope:global data:string mnNameNew_803EE5A0 = .data:0x803EE5A0; // type:object size:0x24 scope:global data:string -mnNameNew_803EE5C4 = .data:0x803EE5C4; // type:object size:0x1C scope:global data:string -mnNameNew_803EE5E0 = .data:0x803EE5E0; // type:object size:0x20 scope:global data:string -mnNameNew_803EE600 = .data:0x803EE600; // type:object size:0x24 scope:global data:string -mnNameNew_803EE624 = .data:0x803EE624; // type:object size:0x24 scope:global data:string -mnNameNew_803EE648 = .data:0x803EE648; // type:object size:0x1C scope:global data:string -mnNameNew_803EE664 = .data:0x803EE664; // type:object size:0x20 scope:global data:string -mnNameNew_803EE684 = .data:0x803EE684; // type:object size:0x24 scope:global data:string -mnNameNew_803EE6A8 = .data:0x803EE6A8; // type:object size:0x28 scope:global data:string -mnNameNew_803EE6D0 = .data:0x803EE6D0; // type:object size:0x14 scope:global data:string -mnNameNew_803EE6E4 = .data:0x803EE6E4; // type:object size:0x14 scope:global data:string -mnNameNew_803EE6F8 = .data:0x803EE6F8; // type:object size:0x10 scope:global data:string -mnNameNew_803EE708 = .data:0x803EE708; // type:object size:0x18 scope:global data:string +mnNameNew_803EE5C4 = .data:0x803EE5C4; // type:object size:0x19 scope:global data:string +mnNameNew_803EE5E0 = .data:0x803EE5E0; // type:object size:0x1D scope:global data:string +mnNameNew_803EE600 = .data:0x803EE600; // type:object size:0x21 scope:global data:string +mnNameNew_803EE624 = .data:0x803EE624; // type:object size:0x23 scope:global data:string +mnNameNew_803EE648 = .data:0x803EE648; // type:object size:0x1B scope:global data:string +mnNameNew_803EE664 = .data:0x803EE664; // type:object size:0x1F scope:global data:string +mnNameNew_803EE684 = .data:0x803EE684; // type:object size:0x23 scope:global data:string +mnNameNew_803EE6A8 = .data:0x803EE6A8; // type:object size:0x25 scope:global data:string +mnNameNew_803EE6D0 = .data:0x803EE6D0; // type:object size:0x11 scope:global data:string +mnNameNew_803EE6E4 = .data:0x803EE6E4; // type:object size:0x13 scope:global data:string +mnNameNew_803EE6F8 = .data:0x803EE6F8; // type:object size:0xF scope:global data:string +mnNameNew_803EE708 = .data:0x803EE708; // type:object size:0x11 scope:global data:string mnNameNew_803EE720 = .data:0x803EE720; // type:object size:0x4 scope:global data:4byte mnNameNew_803EE724 = .data:0x803EE724; // type:object size:0x4 scope:global mnDiagram_803EE728 = .data:0x803EE728; // type:object size:0x24 scope:global @@ -24079,9 +24093,11 @@ it_803F94A0 = .data:0x803F94A0; // type:object size:0x30 scope:global @310 = .data:0x803F9570; // type:object size:0x25 scope:local data:string ifStatus_803F9598 = .data:0x803F9598; // type:object size:0x14 scope:global data:string ifStatus_803F95AC = .data:0x803F95AC; // type:object size:0x14 scope:global data:string -ifStatus_803F95C0 = .data:0x803F95C0; // type:object size:0x68 scope:global -ifStatus_803F9628 = .data:0x803F9628; // type:object size:0x140 scope:global data:4byte -lbl_803F9768 = .data:0x803F9768; // type:object size:0x16 data:string +@679 = .data:0x803F95C0; // type:object size:0xA scope:local data:string +@749 = .data:0x803F95CC; // type:object size:0x25 scope:local data:string +@750 = .data:0x803F95F4; // type:object size:0xB scope:local data:string +@752 = .data:0x803F9600; // type:object size:0x25 scope:local data:string +ifStatus_ScInfCntModels = .data:0x803F9628; // type:object size:0x158 scope:global data:4byte lbl_803F9780 = .data:0x803F9780; // type:object size:0x16 data:string lbl_803F9798 = .data:0x803F9798; // type:object size:0xA data:string ifStock_803F97A8 = .data:0x803F97A8; // type:object size:0xC scope:global data:string @@ -26378,12 +26394,10 @@ lb_804D3740 = .sdata:0x804D3740; // type:object size:0x7 scope:global data:strin lb_804D3748 = .sdata:0x804D3748; // type:object size:0x5 scope:global data:string lb_804D3750 = .sdata:0x804D3750; // type:object size:0x7 scope:global data:string lb_804D3758 = .sdata:0x804D3758; // type:object size:0x5 scope:global data:string -lb_804D3760 = .sdata:0x804D3760; // type:object size:0x4 scope:global data:4byte -lb_804D3764 = .sdata:0x804D3764; // type:object size:0x4 scope:global data:4byte -lb_804D3768 = .sdata:0x804D3768; // type:object size:0x1 scope:global data:byte -lbl_804D3769 = .sdata:0x804D3769; // type:object size:0x3 -lb_804D376C = .sdata:0x804D376C; // type:object size:0x1 scope:global data:byte -lbl_804D376D = .sdata:0x804D376D; // type:object size:0x3 +lb_ColorWhite = .sdata:0x804D3760; // type:object size:0x4 scope:global data:byte +lb_ColorBlack = .sdata:0x804D3764; // type:object size:0x4 scope:global data:byte +red = .sdata:0x804D3768; // type:object size:0x4 scope:local data:byte +translucent_red = .sdata:0x804D376C; // type:object size:0x4 scope:local data:byte yellow = .sdata:0x804D3770; // type:object size:0x4 scope:local data:byte lbArq_804D3778 = .sdata:0x804D3778; // type:object size:0x8 scope:global data:string lbArq_804D3780 = .sdata:0x804D3780; // type:object size:0x3 scope:global data:string @@ -26604,9 +26618,9 @@ ftCo_804D3D50 = .sdata:0x804D3D50; // type:object size:0x5 scope:local data:stri foxSFX = .sdata:0x804D3D80; // type:object size:0x8 scope:global falcoSFX = .sdata:0x804D3D88; // type:object size:0x8 scope:global @346 = .sdata:0x804D3D90; // type:object size:0x2 scope:local data:string -ftKb_Init_804D3D98 = .sdata:0x804D3D98; // type:object size:0x7 scope:global data:string -ftKb_Init_804D3DA0 = .sdata:0x804D3DA0; // type:object size:0x5 scope:global data:string -ftKb_Init_804D3DA8 = .sdata:0x804D3DA8; // type:object size:0x4 scope:global data:string +@470 = .sdata:0x804D3D98; // type:object size:0x7 scope:local data:string +@471 = .sdata:0x804D3DA0; // type:object size:0x5 scope:local data:string +@472 = .sdata:0x804D3DA8; // type:object size:0x4 scope:local data:string ftKb_Init_804D3DAC = .sdata:0x804D3DAC; // type:object size:0x2 scope:global data:string ftKb_Init_804D3DB0 = .sdata:0x804D3DB0; // type:object size:0x2 scope:global data:string ftKb_Init_804D3DB8 = .sdata:0x804D3DB8; // type:object size:0x8 scope:global @@ -26618,8 +26632,8 @@ ftKb_Init_804D3DC0 = .sdata:0x804D3DC0; // type:object size:0x8 scope:global @254 = .sdata:0x804D3DE8; // type:object size:0x7 scope:local data:string @255 = .sdata:0x804D3DF0; // type:object size:0x5 scope:local data:string @290 = .sdata:0x804D3DF8; // type:object size:0x6 scope:local data:string -ftKb_Init_804D3E00 = .sdata:0x804D3E00; // type:object size:0x7 scope:global data:string -ftKb_Init_804D3E08 = .sdata:0x804D3E08; // type:object size:0x5 scope:global data:string +@275 = .sdata:0x804D3E00; // type:object size:0x7 scope:local data:string +@276 = .sdata:0x804D3E08; // type:object size:0x5 scope:local data:string @263 = .sdata:0x804D3E10; // type:object size:0x7 scope:local data:string @264 = .sdata:0x804D3E18; // type:object size:0x5 scope:local data:string @351 = .sdata:0x804D3E20; // type:object size:0x7 scope:local data:string @@ -26708,7 +26722,7 @@ lbl_804D4088 = .sdata:0x804D4088; // type:object size:0x3 data:sjis lbl_804D408C = .sdata:0x804D408C; // type:object size:0x4 data:string lbl_804D4090 = .sdata:0x804D4090; // type:object size:0x7 data:string lbl_804D4098 = .sdata:0x804D4098; // type:object size:0x5 data:string -lbl_804D40A0 = .sdata:0x804D40A0; // type:object size:0x8 data:string +lbl_804D40A0 = .sdata:0x804D40A0; // type:object size:0x5 data:string lbl_804D40A8 = .sdata:0x804D40A8; // type:object size:0x6 data:string lbl_804D40B0 = .sdata:0x804D40B0; // type:object size:0x8 data:string lbl_804D40B8 = .sdata:0x804D40B8; // type:object size:0x2 data:string @@ -26996,9 +27010,9 @@ grPu_804D48E8 = .sdata:0x804D48E8; // type:object size:0x7 scope:global data:str grPu_804D48F0 = .sdata:0x804D48F0; // type:object size:0x5 scope:global data:string grPu_804D48F8 = .sdata:0x804D48F8; // type:object size:0x5 scope:global data:string grPu_804D4900 = .sdata:0x804D4900; // type:object size:0x3 scope:global data:string -grGr_804D4908 = .sdata:0x804D4908; // type:object size:0x7 scope:global data:string -grGr_804D4910 = .sdata:0x804D4910; // type:object size:0x5 scope:global data:string -grGr_804D4918 = .sdata:0x804D4918; // type:object size:0x2 scope:global data:string +@271 = .sdata:0x804D4908; // type:object size:0x7 scope:local data:string +@272 = .sdata:0x804D4910; // type:object size:0x5 scope:local data:string +@817 = .sdata:0x804D4918; // type:object size:0x2 scope:local data:string grFz_804D4920 = .sdata:0x804D4920; // type:object size:0x7 scope:global data:string grFz_804D4928 = .sdata:0x804D4928; // type:object size:0x5 scope:global data:string grPushOn_804D4930 = .sdata:0x804D4930; // type:object size:0x2 scope:local data:string @@ -27090,7 +27104,7 @@ lbl_804D4B8C = .sdata:0x804D4B8C; // type:object size:0x4 mn_804D4B90 = .sdata:0x804D4B90; // type:object size:0x4 scope:global align:4 data:float mn_804D4B94 = .sdata:0x804D4B94; // type:object size:0x2 scope:global mn_804D4B96 = .sdata:0x804D4B96; // type:object size:0x1 scope:global data:byte -mn_804D4B98 = .sdata:0x804D4B98; // type:object size:0x4 scope:global align:4 data:float +mnRulePlus_TimeLimitOffFrame = .sdata:0x804D4B98; // type:object size:0x4 scope:global align:4 data:float mnItemSw_804D4BA0 = .sdata:0x804D4BA0; // type:object size:0x8 scope:global mnItemSw_804D4BA8 = .sdata:0x804D4BA8; // type:object size:0x7 scope:global data:string mnItemSw_804D4BB0 = .sdata:0x804D4BB0; // type:object size:0x5 scope:global data:string @@ -28048,7 +28062,7 @@ lbl_804D6374 = .sdata:0x804D6374; // type:object size:0x5 scope:local data:strin HSD_PSDisp_804D6380 = .sdata:0x804D6380; // type:object size:0x1 scope:global data:byte HSD_PSDisp_804D6384 = .sdata:0x804D6384; // type:object size:0x2 scope:global data:string HSD_SObjLib_804D6388 = .sdata:0x804D6388; // type:object size:0x5 scope:global data:string -HSD_SisLib_804D6390 = .sdata:0x804D6390; // type:object size:0x8 scope:global +@73 = .sdata:0x804D6390; // type:object size:0x1 scope:local data:string lbl_804D6398 = .sdata:0x804D6398; // type:object size:0x4 data:4byte lb_804D63A0 = .sbss:0x804D63A0; // type:object size:0x4 scope:global data:4byte cur_data = .sbss:0x804D63A4; // type:object size:0x4 scope:global data:4byte @@ -28277,8 +28291,8 @@ gm_804D67B8 = .sbss:0x804D67B8; // type:object size:0x4 scope:global data:4byte gm_804D67BC = .sbss:0x804D67BC; // type:object size:0x4 scope:global data:4byte gm_804D67C0 = .sbss:0x804D67C0; // type:object size:0x4 scope:global data:4byte gm_804D67C4 = .sbss:0x804D67C4; // type:object size:0x4 scope:global data:4byte -gm_804D67C8 = .sbss:0x804D67C8; // type:object size:0x1 scope:global data:byte -gm_804D67C9 = .sbss:0x804D67C9; // type:object size:0x7 scope:global data:byte +gmRegend_InputDelayTimer = .sbss:0x804D67C8; // type:object size:0x1 scope:global data:byte +gmRegend_ExitTimer = .sbss:0x804D67C9; // type:object size:0x1 scope:global data:byte gm_804D67D0 = .sbss:0x804D67D0; // type:object size:0x4 scope:global data:4byte gm_804D67D4 = .sbss:0x804D67D4; // type:object size:0x4 scope:global data:4byte gm_804D67D8 = .sbss:0x804D67D8; // type:object size:0x4 scope:global data:4byte @@ -30530,9 +30544,9 @@ ftKb_Init_804D93E0 = .sdata2:0x804D93E0; // type:object size:0x4 scope:global al @225 = .sdata2:0x804D9564; // type:object size:0x4 scope:local align:4 data:float @252 = .sdata2:0x804D9568; // type:object size:0x4 scope:local align:4 data:float @253 = .sdata2:0x804D956C; // type:object size:0x4 scope:local align:4 data:float -ftKb_Init_804D9570 = .sdata2:0x804D9570; // type:object size:0x4 scope:global align:4 data:float -ftKb_Init_804D9574 = .sdata2:0x804D9574; // type:object size:0x4 scope:global align:4 data:float -ftKb_Init_804D9578 = .sdata2:0x804D9578; // type:object size:0x8 scope:global align:8 data:double +@273 = .sdata2:0x804D9570; // type:object size:0x4 scope:local align:4 data:float +@274 = .sdata2:0x804D9574; // type:object size:0x4 scope:local align:4 data:float +@449 = .sdata2:0x804D9578; // type:object size:0x8 scope:local align:8 data:double @237 = .sdata2:0x804D9580; // type:object size:0x4 scope:local align:4 data:float @238 = .sdata2:0x804D9584; // type:object size:0x4 scope:local align:4 data:float @276 = .sdata2:0x804D9588; // type:object size:0x4 scope:local align:4 data:float @@ -31738,7 +31752,7 @@ gm_804DAC78 = .sdata2:0x804DAC78; // type:object size:0x4 scope:global align:4 d gm_804DAC7C = .sdata2:0x804DAC7C; // type:object size:0x4 scope:global align:4 data:float gm_804DAC80 = .sdata2:0x804DAC80; // type:object size:0x4 scope:global align:4 data:float gm_804DAC84 = .sdata2:0x804DAC84; // type:object size:0x4 scope:global align:4 data:float -gm_804DAC88 = .sdata2:0x804DAC88; // type:object size:0x4 scope:global align:4 data:float +gm_DefaultGameSpeed = .sdata2:0x804DAC88; // type:object size:0x4 scope:global align:4 data:float @290 = .sdata2:0x804DAC90; // type:object size:0x4 scope:local align:4 data:float @291 = .sdata2:0x804DAC94; // type:object size:0x4 scope:local align:4 data:float @292 = .sdata2:0x804DAC98; // type:object size:0x4 scope:local align:4 data:float diff --git a/configure.py b/configure.py index 7ed0498fd9..9d41482093 100755 --- a/configure.py +++ b/configure.py @@ -1031,6 +1031,7 @@ def MatchingFor(*versions): Object(NonMatching, "melee/gm/gmregtyfall.c"), Object(NonMatching, "melee/gm/gm_1A7A.c"), Object(NonMatching, "melee/gm/gmregenddisp.c"), + Object(Matching, "melee/gm/gm_1A9B.c"), Object(Matching, "melee/gm/gmopening.c"), Object(NonMatching, "melee/gm/gmstaffroll.c"), Object(Matching, "melee/gm/gmhowto.c"), diff --git a/src/MSL/stddef.h b/src/MSL/stddef.h index bcaaa2498a..7241d6fcee 100644 --- a/src/MSL/stddef.h +++ b/src/MSL/stddef.h @@ -13,7 +13,11 @@ typedef unsigned int usize_t; typedef signed int intptr_t; typedef unsigned int uintptr_t; +#if defined(__clang__) || defined(__GNUC__) +#define offsetof(type, member) __builtin_offsetof(type, member) +#else #define offsetof(type, member) ((size_t) &(((type*) 0)->member)) +#endif #ifndef NULL #define NULL 0L diff --git a/src/melee/cm/camera.c b/src/melee/cm/camera.c index c65c848a85..fe7d4ab02b 100644 --- a/src/melee/cm/camera.c +++ b/src/melee/cm/camera.c @@ -727,10 +727,11 @@ static inline void get_pitch_angle(CameraBounds* bounds, Vec3* scroll_offset, cm_803BCCA0.x1C; } - *pitch_angle = ((bounds->y_min - scroll_offset->y) + - (bounds->y_max - scroll_offset->y)) * - (0.5f - pitch_blend) + - scroll_offset->y; + { + f32 sum = (bounds->y_min - scroll_offset->y) + + (bounds->y_max - scroll_offset->y); + *pitch_angle = sum * (0.5f - pitch_blend) + scroll_offset->y; + } { f32 info_x24 = Stage_GetCamInfoX24(); *pitch_angle += cm_803BCCA0.x8; @@ -741,8 +742,8 @@ static inline void get_pitch_angle(CameraBounds* bounds, Vec3* scroll_offset, void Camera_80029CF8(CameraBounds* bounds, CameraTransformState* transform) { f32 unused_f31; - u8 _padA[8]; Vec3 scroll_offset; + u8 _padA[4]; f32 pitch_angle; f32 min_v; f32 horiz_frustum_dist; @@ -780,8 +781,11 @@ void Camera_80029CF8(CameraBounds* bounds, CameraTransformState* transform) HSD_ASSERTMSG(0x4FB, fov_d < (f32) M_PI_2, "fov_dy_max - bounds->y_min) / (tan_fov_u + tanf(fov_d)); + { + f32 tan_fov_d = tanf(fov_d); + vert_frustum_dist = + (bounds->y_max - bounds->y_min) / (tan_fov_u + tan_fov_d); + } Stage_GetCamBoundsBottomOffset(); Stage_GetCamBoundsTopOffset(); vert_offset = vert_frustum_dist * tanf(pan_angle); @@ -791,8 +795,9 @@ void Camera_80029CF8(CameraBounds* bounds, CameraTransformState* transform) mid_x = 0.5f * (bounds->x_min + bounds->x_max); { f32 info_x20 = Stage_GetCamInfoX20(); + f32 x_offset = mid_x - scroll_offset2.x; vert_offset = deg_to_rad * cm_803BCCA0.x14; - pan_angle = -(deg_to_rad * ((mid_x - scroll_offset2.x) * info_x20)); + pan_angle = -(deg_to_rad * (x_offset * info_x20)); } if (pan_angle > vert_offset) { pan_angle = vert_offset; @@ -1030,6 +1035,7 @@ void Camera_8002A768(CameraTransformState* transform, s32 arg1) f32 right_overlap; f32 bottom_overlap; f32 left_overlap; + f32 scale; enum_t var_r31; enum_t var_r30; @@ -1258,9 +1264,9 @@ void Camera_8002A768(CameraTransformState* transform, s32 arg1) } else if (var_r31 & 2) { cam_correction.y = bottom_overlap; } - cam_correction.x *= -1.0f; - cam_correction.y *= -1.0f; - cam_correction.z *= -1.0f; + cam_correction.x *= scale = *(volatile const f32*) &cm_804D7E04; + cam_correction.y *= scale; + cam_correction.z *= scale; lbVector_Add(&transform->target_position, &cam_correction); lbVector_Add(&transform->target_interest, &cam_correction); } @@ -1501,8 +1507,7 @@ void Camera_8002B694(CameraInputs* inputs, s32 slot) f32 substick_y; f32 temp_x; f32 temp_y; - s32 current_slot; - s32 var_r5; + s32 idx; u64 temp_ret; PAD_STACK(8); @@ -1517,10 +1522,8 @@ void Camera_8002B694(CameraInputs* inputs, s32 slot) } if (slot == 4) { /// @todo there is probably a bigger inline - for (current_slot = 0; current_slot < PAD_MAX_CONTROLLERS; - current_slot++) - { - pad = get_slot_pad(current_slot); + for (idx = 0; idx < PAD_MAX_CONTROLLERS; idx++) { + pad = get_slot_pad(idx); temp_x = get_stick_x(pad); temp_y = get_stick_y(pad); stick_x = temp_x; @@ -1539,13 +1542,13 @@ void Camera_8002B694(CameraInputs* inputs, s32 slot) } } - if (current_slot == 4) { + if (idx == PAD_MAX_CONTROLLERS) { stick_y = 0.0f; stick_x = 0.0f; } - for (var_r5 = 0; var_r5 < 4; var_r5++) { - pad = get_slot_pad(var_r5); + for (idx = 0; idx < PAD_MAX_CONTROLLERS; idx++) { + pad = get_slot_pad(idx); temp_x = pad->nml_subStickX; temp_y = pad->nml_subStickY; substick_x = temp_x; @@ -1564,7 +1567,7 @@ void Camera_8002B694(CameraInputs* inputs, s32 slot) } } - if (var_r5 == 4) { + if (idx == PAD_MAX_CONTROLLERS) { substick_y = 0.0f; substick_x = 0.0f; } @@ -1665,6 +1668,9 @@ static inline void OrthonormalizeBasis(Vec3* forward, Vec3* up, Vec3* right) lbVector_Normalize(up); } +#define Camera_8002BD88_GET_SCALE(view_dir) \ + (((view_dir) * cm_803BCCA0.xBC) + cm_803BCCA0.xC0) + s32 Camera_8002BC78(Vec3* forward, Vec3* up, Vec3* right) { s32 clamp_result = 0; @@ -1718,13 +1724,15 @@ void Camera_8002BD88(f32 x, f32 y) clamp_result = Camera_8002BC78(&forward, &up, &right); if (clamp_result == 1) { - if (y < 0.0F) { - y = 0.0F; + scale = 0.0F; + if (y < scale) { + y = scale; } x = 0.0F; } else if (clamp_result == -1) { - if (y > 0.0F) { - y = 0.0F; + scale = 0.0F; + if (y > scale) { + y = scale; } x = 0.0F; } @@ -1737,9 +1745,7 @@ void Camera_8002BD88(f32 x, f32 y) cm_80452C68.pause_up = up; if (y != 0.0F) { - scale = y * ((view_dir * cm_803BCCA0.xBC) + cm_803BCCA0.xC0); - // scale = y * ((view_dir * cm_803BCCA0._44[0x1E]) + - // cm_803BCCA0._44[0x1F]); + scale = y * Camera_8002BD88_GET_SCALE(view_dir); up.x *= scale; up.y *= scale; up.z *= scale; @@ -1747,7 +1753,7 @@ void Camera_8002BD88(f32 x, f32 y) } if (x != 0.0F) { - scale = x * ((view_dir * 0.025F) + 0.2F); + scale = x * Camera_8002BD88_GET_SCALE(view_dir); right.x *= -scale; right.y *= -scale; right.z *= -scale; @@ -1761,6 +1767,7 @@ void Camera_8002BD88(f32 x, f32 y) pos.z *= scale; cm_80452C68.pause_eye_offset = pos; } +#undef Camera_8002BD88_GET_SCALE void Camera_8002C010(f32 farg0, f32 farg1) { @@ -1829,16 +1836,12 @@ void Camera_8002C1A8(void) Camera_8002B694(&inputs, cm_80452C68.x305); - substick_y_val = 0.0f; - substick_x_val = 0.0f; + zoom_dir = x_move = y_move = substick_x_val = substick_y_val = 0.0f; stick_x = inputs.stick_x; - y_move = 0.0f; stick_y = inputs.stick_y; - x_move = 0.0f; substick_x = inputs.substick_x; substick_y = inputs.substick_y; dir = 0; - zoom_dir = 0.0f; { u64 x18_btns = inputs.buttons_triggered; @@ -1899,13 +1902,15 @@ void Camera_8002C1A8(void) scale = cm_80452C68.x32C * cm_803BCCA0.x8C + cm_803BCCA0.x90; cm_80452C68.x304 = Camera_8002BA00(cm_80452C68.x304, dir); slot = cm_80452C68.x304; - cm_80452C68.x314.x = cm_80452C68.x314.y = cm_80452C68.x314.z = 0.0f; - cm_80452C68.pause_eye_offset.x = 0.0f; + abs_f1 = 0.0f; + cm_80452C68.x314.x = cm_80452C68.x314.y = cm_80452C68.x314.z = + abs_f1; + cm_80452C68.pause_eye_offset.x = abs_f1; cm_80452C68.pause_eye_offset.y = 5.0f; cm_80452C68.pause_eye_offset.z = 20.0f; - cm_80452C68.pause_up.x = 0.0f; + cm_80452C68.pause_up.x = abs_f1; cm_80452C68.pause_up.y = 1.0f; - cm_80452C68.pause_up.z = 0.0f; + cm_80452C68.pause_up.z = abs_f1; if (slot == 0xA) { cm_80452C68.pause_eye_distance = 3.0f * scale; } else { @@ -1918,52 +1923,57 @@ void Camera_8002C1A8(void) Camera_8002BAA8(zoom_dir); } - if (x_move != 0.0f || y_move != 0.0f) { - if (cm_80452C68.x304 == 0xA) { - if (sqrtf__Ff(cm_80452C68.pause_eye_offset.z * - cm_80452C68.pause_eye_offset.z + - (cm_80452C68.pause_eye_offset.x * - cm_80452C68.pause_eye_offset.x + - cm_80452C68.pause_eye_offset.y * - cm_80452C68.pause_eye_offset.y)) < 1.0f) - { - cm_80452C68.pause_eye_distance = 1.0f; - } - if (y_move != 0.0f) { - cm_80452C68.x314.y += y_move; - } - if (x_move != 0.0f) { - cm_80452C68.x314.x += x_move; + { + abs_f1 = 0.0f; + + if (abs_f1 != x_move || abs_f1 != y_move) { + if (cm_80452C68.x304 == 0xA) { + if (sqrtf__Ff(cm_80452C68.pause_eye_offset.z * + cm_80452C68.pause_eye_offset.z + + (cm_80452C68.pause_eye_offset.x * + cm_80452C68.pause_eye_offset.x + + cm_80452C68.pause_eye_offset.y * + cm_80452C68.pause_eye_offset.y)) < 1.0f) + { + cm_80452C68.pause_eye_distance = 1.0f; + } + if (abs_f1 != y_move) { + cm_80452C68.x314.y += y_move; + } + if (abs_f1 != x_move) { + cm_80452C68.x314.x += x_move; + } + } else { + Camera_8002C010(x_move, y_move); } - } else { - Camera_8002C010(x_move, y_move); } } - if (substick_x_val != 0.0f || substick_y_val != 0.0f) { - Camera_8002BD88(substick_x_val, substick_y_val); + { + abs_f1 = 0.0f; + + if (abs_f1 != substick_x_val || abs_f1 != substick_y_val) { + Camera_8002BD88(substick_x_val, substick_y_val); + } } } void Camera_8002C5B4(Camera_x2D0* arg0) { + UNUSED u64 pad; + Vec3 temp_pos; Vec3 cross1; + f32 xz_dist; Vec3 cross2; - Vec3 temp_pos; Camera* cam; Camera_x2D0* params; - Vec3* cam_pos; - Vec3* cam_offset; + f32* eye_offset_z; Vec3* eye_offset; f32* eye_offset_y; - f32* eye_offset_z; f32 len_3d; - f32 xz_dist; f32 pitch; f32 yaw; f32 limit; - u8 operand_pad[8]; - PAD_STACK(16); cam = &cm_80452C68; params = arg0; @@ -1972,41 +1982,38 @@ void Camera_8002C5B4(Camera_x2D0* arg0) params->callback(arg0); } - cam_pos = &cam->x308; limit = params->x_max; - if (cam_pos->x > limit) { - cam_pos->x = limit; + if (cm_80452C68.x308.x > limit) { + cm_80452C68.x308.x = limit; } else { limit = params->x_min; - if (cam_pos->x < limit) { - cam_pos->x = limit; + if (cm_80452C68.x308.x < limit) { + cm_80452C68.x308.x = limit; } } limit = params->y_max; - if (cam_pos->y > limit) { - cam_pos->y = limit; + if (cm_80452C68.x308.y > limit) { + cm_80452C68.x308.y = limit; } else { limit = params->y_min; - if (cam_pos->y < limit) { - cam_pos->y = limit; + if (cm_80452C68.x308.y < limit) { + cm_80452C68.x308.y = limit; } } limit = params->z_max; - if (cam_pos->z > limit) { - cam_pos->z = limit; + if (cm_80452C68.x308.z > limit) { + cm_80452C68.x308.z = limit; } else { limit = params->z_min; - if (cam_pos->z < limit) { - cam_pos->z = limit; + if (cm_80452C68.x308.z < limit) { + cm_80452C68.x308.z = limit; } } - cam_offset = &cam->x314; - (void) cam_offset; - temp_pos = *cam_offset; - lbVector_Add(&temp_pos, cam_pos); + temp_pos = cm_80452C68.x314; + lbVector_Add(&temp_pos, &cm_80452C68.x308); if (temp_pos.x > params->x_max) { temp_pos.x = params->x_max; @@ -2026,12 +2033,12 @@ void Camera_8002C5B4(Camera_x2D0* arg0) temp_pos.z = params->z_min; } - lbVector_Sub(&temp_pos, cam_pos); - *cam_offset = temp_pos; + lbVector_Sub(&temp_pos, &cm_80452C68.x308); + cm_80452C68.x314 = temp_pos; eye_offset = &cam->pause_eye_offset; - eye_offset_y = &eye_offset->y; - eye_offset_z = &eye_offset->z; + eye_offset_y = &cam->pause_eye_offset.y; + eye_offset_z = &cam->pause_eye_offset.z; len_3d = sqrtf((*eye_offset_z * *eye_offset_z) + @@ -2068,6 +2075,25 @@ void Camera_8002C5B4(Camera_x2D0* arg0) } } +static inline void Camera_8002C908_Init(Camera* cam, + CameraTransformState** transform, + CameraBounds* bounds) +{ + *transform = &cam->transform; + Camera_8002958C(bounds, *transform); + Camera_8002C1A8(); +} + +static inline Vec3* Camera_8002C908_GetOffset(Camera* cam) +{ + return &cam->x314; +} + +static inline Camera* Camera_8002C908_GetCamera(void) +{ + return &cm_80452C68; +} + void Camera_8002C908(void* arg0) { CameraBounds bounds; @@ -2080,12 +2106,10 @@ void Camera_8002C908(void* arg0) s32 valid; Vec3* pos_ptr; - cam = &cm_80452C68; + cam = Camera_8002C908_GetCamera(); Camera_80030DF8(); Camera_800293E0(); - transform = &cam->transform; - Camera_8002958C(&bounds, transform); - Camera_8002C1A8(); + Camera_8002C908_Init(cam, &transform, &bounds); pos_ptr = &cam->x308; slot_ptr = &cam->x304; @@ -2122,16 +2146,18 @@ loop_check: { { Vec3* position; Vec3* tgt_interest; + Vec3* tgt_interest2; Vec3* tgt_position; CameraUnkGlobals* globals; f32 coeff; tgt_interest = &transform->target_interest; - transform->target_interest = *pos_ptr; - lbVector_Add(tgt_interest, &cam->x314); + tgt_interest2 = &cam->transform.target_interest; + *tgt_interest2 = *pos_ptr; + lbVector_Add(tgt_interest, Camera_8002C908_GetOffset(cam)); tgt_position = &transform->target_position; - transform->target_position = *tgt_interest; + cam->transform.target_position = *tgt_interest2; lbVector_Add(tgt_position, &cam->pause_eye_offset); position = &transform->position; @@ -2151,10 +2177,10 @@ loop_check: { sp10.z *= coeff; lbVector_Add(&transform->interest, &sp10); - transform->target_fov = cam->x32C; - transform->fov = - (transform->target_fov - transform->fov) * globals->x88 + - transform->fov; + cam->transform.target_fov = cam->x32C; + cam->transform.fov = + (cam->transform.target_fov - cam->transform.fov) * globals->x88 + + cam->transform.fov; } Camera_8002A28C(&bounds); Camera_8002A0C0(&bounds, transform); @@ -2574,6 +2600,22 @@ fallback_path: { cam->x2B0 = cam->x2B4 / (f32) *count_ptr; } } +static inline float Camera_8002D318_GetFovDelta(Camera* cam) +{ + return cam->transform.target_fov - cam->transform.fov; +} + +static inline float Camera_8002D318_GetPitchDistance(f32* pitch_ptr, + f32 distance) +{ + return distance * cosf(*pitch_ptr); +} + +static inline f32 Camera_8002D318_AddSquares(f32 y_squared, f32 x_squared) +{ + return x_squared + y_squared; +} + void Camera_8002D318(void* unused) { Camera* cam; @@ -2643,10 +2685,12 @@ void Camera_8002D318(void* unused) globals = &cm_803BCCA0; x = *target_x; - (void) x; y = *target_y; smooth = globals->x64; - dx = x - cam->transform.interest.x; + { + f32 dx_delta = x - cam->transform.interest.x; + dx = dx_delta; + } z = cam->transform.target_interest.z; dy = y - cam->transform.interest.y; dz = z - cam->transform.interest.z; @@ -2707,7 +2751,7 @@ void Camera_8002D318(void* unused) f32 horiz_dist; pitch_ptr = &cam->pitch_offset; - horiz_dist = distance * cosf(*pitch_ptr); + horiz_dist = Camera_8002D318_GetPitchDistance(pitch_ptr, distance); yaw_ptr = &cam->yaw_offset; cam->transform.target_position.x = cam->transform.target_interest.x + horiz_dist * sinf(*yaw_ptr); @@ -2720,19 +2764,21 @@ void Camera_8002D318(void* unused) { CameraUnkGlobals* globals; f32 smooth; - f32 x, y, z; + f32 x, dx; + f32 y, dy; + f32 z, dz; x = cam->transform.target_position.x; - globals = &cm_803BCCA0; y = cam->transform.target_position.y; - z = cam->transform.target_position.z; + globals = &cm_803BCCA0; smooth = globals->x68; - cam->transform.position.x = (x - cam->transform.position.x) * smooth + - cam->transform.position.x; - cam->transform.position.y = (y - cam->transform.position.y) * smooth + - cam->transform.position.y; - cam->transform.position.z = (z - cam->transform.position.z) * smooth + - cam->transform.position.z; + dx = x - cam->transform.position.x; + z = cam->transform.target_position.z; + dy = y - cam->transform.position.y; + dz = z - cam->transform.position.z; + cam->transform.position.x = dx * smooth + cam->transform.position.x; + cam->transform.position.y = dy * smooth + cam->transform.position.y; + cam->transform.position.z = dz * smooth + cam->transform.position.z; } return; @@ -2760,8 +2806,8 @@ fallback: { smooth_ptr = &globals->x44; fov_ptr = &globals->x40; cam->transform.target_fov = *fov_ptr; - cam->transform.fov += - (cam->transform.target_fov - cam->transform.fov) * *smooth_ptr; + cam->transform.fov = cam->transform.fov + + Camera_8002D318_GetFovDelta(cam) * *smooth_ptr; Camera_80029BC4(&bounds, transform); if (Camera_80030AF8()) { @@ -2825,7 +2871,7 @@ fallback: { f32 dx2 = dx * dx; f32 dy2 = dy * dy; f32 dz2 = dz * dz; - cam->x2C0 = sqrtf__Ff(dz2 + (dx2 + dy2)); + cam->x2C0 = sqrtf__Ff(dz2 + Camera_8002D318_AddSquares(dy2, dx2)); } Camera_8002B1F8(transform); @@ -2855,6 +2901,7 @@ void Camera_8002D85C(void* unused) f32* pitch_ptr; f32* yaw_ptr; CmSubject* subject; + f32 horiz_dist; f32 distance; CameraTransformState* transform; CameraTransformState* transform2; @@ -2866,8 +2913,6 @@ void Camera_8002D85C(void* unused) s16* count_ptr; f32 left_off; s32 check_result; - u8 operand_pad[4]; - PAD_STACK(16); cam = &cm_80452C68; slot_ptr = &cam->x2C4; @@ -2896,23 +2941,33 @@ void Camera_8002D85C(void* unused) if (gobj != NULL) { subject = ftLib_80086B74(gobj); if (subject != NULL) { - Vec3* subj_pos; - f32 dx; - f32 dy; - f32 dz; + Vec3* pos; + f32* target_y; + f32* target_x; + CameraUnkGlobals* globals; + f32 smooth; + f32 dx, dy, dz; - subj_pos = &subject->x1C; - cam->transform.target_interest.x = subject->x1C.x; - cam->transform.target_interest.y = subj_pos->y; - cam->transform.target_interest.z = subj_pos->z; + pos = &subject->x1C; + target_x = &cam->transform.target_interest.x; + target_y = &cam->transform.target_interest.y; - dx = cam->transform.target_interest.x - cam->transform.interest.x; - dy = cam->transform.target_interest.y - cam->transform.interest.y; - dz = cam->transform.target_interest.z; - dz -= cam->transform.interest.z; - cam->transform.interest.x += dx * cm_803BCCA0.x64; - cam->transform.interest.y += dy * cm_803BCCA0.x64; - cam->transform.interest.z += dz * cm_803BCCA0.x64; + *target_x = pos->x; + *target_y = pos->y; + cam->transform.target_interest.z = pos->z; + + globals = &cm_803BCCA0; + smooth = globals->x64; + dx = *target_x - cam->transform.interest.x; + dy = *target_y - cam->transform.interest.y; + dz = cam->transform.target_interest.z - + cam->transform.interest.z; + cam->transform.interest.x = + dx * smooth + cam->transform.interest.x; + cam->transform.interest.y = + dy * smooth + cam->transform.interest.y; + cam->transform.interest.z = + dz * smooth + cam->transform.interest.z; } } @@ -2925,7 +2980,6 @@ void Camera_8002D85C(void* unused) tgt_fov_ptr = &cam->transform.target_fov; *tgt_fov_ptr = globals->x6C; delta = *tgt_fov_ptr - cam->transform.fov; - (void) delta; smooth = globals->x70; cam->transform.fov = delta * smooth + cam->transform.fov; } @@ -2972,8 +3026,6 @@ void Camera_8002D85C(void* unused) } { - f32 horiz_dist; - horiz_dist = distance * cosf(*pitch_ptr); cam->transform.target_position.x = cam->transform.target_interest.x + horiz_dist * sinf(*yaw_ptr); @@ -2986,25 +3038,27 @@ void Camera_8002D85C(void* unused) { CameraUnkGlobals* globals; f32 smooth; - f32 x, y, z; + f32 x, dx; + f32 y, dy; + f32 z, dz; x = cam->transform.target_position.x; - globals = &cm_803BCCA0; y = cam->transform.target_position.y; - z = cam->transform.target_position.z; + globals = &cm_803BCCA0; smooth = globals->x68; - cam->transform.position.x = (x - cam->transform.position.x) * smooth + - cam->transform.position.x; - cam->transform.position.y = (y - cam->transform.position.y) * smooth + - cam->transform.position.y; - cam->transform.position.z = (z - cam->transform.position.z) * smooth + - cam->transform.position.z; + dx = x - cam->transform.position.x; + z = cam->transform.target_position.z; + dy = y - cam->transform.position.y; + dz = z - cam->transform.position.z; + cam->transform.position.x = dx * smooth + cam->transform.position.x; + cam->transform.position.y = dy * smooth + cam->transform.position.y; + cam->transform.position.z = dz * smooth + cam->transform.position.z; } return; fallback: { - CameraBounds bounds; CameraBounds bounds2; + CameraBounds bounds; Vec3 sp1C; Vec3 spC; CameraUnkGlobals* globals; @@ -3080,12 +3134,12 @@ fallback: { f32 dy2; f32 dz2; - x = cam->transform.target_position.x; - x -= cam->transform.target_interest.x; + x = cam->transform.target_position.x - + cam->transform.target_interest.x; y = cam->transform.target_position.y - cam->transform.target_interest.y; - z = cam->transform.target_position.z; - z -= cam->transform.target_interest.z; + z = cam->transform.target_position.z - + cam->transform.target_interest.z; dx2 = x * x; dy2 = y * y; dz2 = z * z; @@ -3117,27 +3171,26 @@ fallback: { } void Camera_8002DDC4(void* arg0) { - CameraBounds bounds; - Vec3 spC; + Vec3* interest; Vec3* tgt_interest; - CameraTransformState* transform; Camera* cam; Vec3* tgt_position; CameraTransformState* transform_copy; CameraUnkGlobals* globals; - f32 smooth; + CameraBounds bounds; cam = &cm_80452C68; Camera_80030DF8(); - transform = &cam->transform; - tgt_interest = &transform->target_interest; + interest = &cam->transform.interest; + tgt_interest = interest + 1; Stage_80224CAC(tgt_interest); globals = &cm_803BCCA0; transform_copy = &cam->transform_copy; { f32 dx, dy, dz; + f32 smooth; - dx = cam->transform.target_interest.x - cam->transform.interest.x; + dx = cam->transform.target_interest.x - interest->x; smooth = globals->x74; dy = cam->transform.target_interest.y - cam->transform.interest.y; dz = cam->transform.target_interest.z - cam->transform.interest.z; @@ -3148,6 +3201,7 @@ void Camera_8002DDC4(void* arg0) Stage_80224CAC(&transform_copy->target_interest); { f32 dx, dy, dz; + f32 smooth; smooth = globals->x74; dx = cam->transform_copy.target_interest.x - @@ -3156,8 +3210,7 @@ void Camera_8002DDC4(void* arg0) cam->transform_copy.interest.y; dz = cam->transform_copy.target_interest.z - cam->transform_copy.interest.z; - cam->transform_copy.interest.x = - dx * smooth + cam->transform_copy.interest.x; + cam->transform_copy.interest.x += dx * smooth; cam->transform_copy.interest.y = dy * smooth + cam->transform_copy.interest.y; cam->transform_copy.interest.z = @@ -3168,21 +3221,20 @@ void Camera_8002DDC4(void* arg0) f32 delta; delta = cam->transform.target_fov - cam->transform.fov; - (void) delta; - cam->transform.fov = delta * globals->x7C + cam->transform.fov; + cam->transform.fov += delta * globals->x7C; } cam->transform_copy.target_fov = Stage_GetCamFixedFov(); - tgt_position = &transform->target_position; + tgt_position = interest + 3; { f32 delta; delta = cam->transform_copy.target_fov - cam->transform_copy.fov; - cam->transform_copy.fov = - delta * globals->x7C + cam->transform_copy.fov; + cam->transform_copy.fov += delta * globals->x7C; } Stage_SetVecToFixedCamPos(tgt_position); { f32 dx, dy, dz; + f32 smooth; dx = cam->transform.target_position.x - cam->transform.position.x; smooth = globals->x78; @@ -3195,6 +3247,7 @@ void Camera_8002DDC4(void* arg0) Stage_SetVecToFixedCamPos(&transform_copy->target_position); { f32 dx, dy, dz; + f32 smooth; smooth = globals->x78; dx = cam->transform_copy.target_position.x - @@ -3210,11 +3263,14 @@ void Camera_8002DDC4(void* arg0) cam->transform_copy.position.z = dz * smooth + cam->transform_copy.position.z; } - lbVector_Diff(tgt_interest, tgt_position, &spC); - bounds.z_pos = - sqrtf__Ff((spC.z * spC.z) + ((spC.x * spC.x) + (spC.y * spC.y))); + { + Vec3 spC; + lbVector_Diff(tgt_interest, tgt_position, &spC); + bounds.z_pos = + sqrtf__Ff((spC.z * spC.z) + ((spC.x * spC.x) + (spC.y * spC.y))); + } Camera_8002A28C(&bounds); - Camera_8002A0C0(&bounds, transform); + Camera_8002A0C0(&bounds, &cam->transform); } s32 Camera_8002DFE4(Vec3* arg0, Vec3* interest, @@ -4350,12 +4406,12 @@ static void fn_800301D0(HSD_GObj* gobj, int arg1) Camera_800310A0(2); if (cm_80452C68.x398_b2) { - prio8_a = 0; + prio8_a = (prio8_a = 0); } else { prio8_a = 8; } if (cm_80452C68.x398_b4) { - prio1_a = 0; + prio1_a = (prio1_a = 0); } else { prio1_a = 1; } @@ -4364,7 +4420,7 @@ static void fn_800301D0(HSD_GObj* gobj, int arg1) Camera_800310A0(1); if (cm_80452C68.x398_b2) { - prio8_b = 0; + prio8_b = (prio8_b = 0); } else { prio8_b = 8; } @@ -4373,7 +4429,7 @@ static void fn_800301D0(HSD_GObj* gobj, int arg1) Camera_800310A0(0); if (cm_80452C68.x398_b2) { - prio8_b = 0; + prio8_b = (prio8_b = 0); } else { prio8_b = 8; } @@ -4382,7 +4438,7 @@ static void fn_800301D0(HSD_GObj* gobj, int arg1) lbRefract_80022560(); if (cm_80452C68.x398_b4) { - prio1_b = 0; + prio1_b = (prio1_b = 0); } else { prio1_b = 1; } @@ -4390,12 +4446,12 @@ static void fn_800301D0(HSD_GObj* gobj, int arg1) Camera_80031074(0); if (cm_80452C68.x398_b2) { - prio8_a = 0; + prio8_a = (prio8_a = 0); } else { prio8_a = 8; } if (cm_80452C68.x398_b4) { - prio1_a = 0; + prio1_a = (prio1_a = 0); } else { prio1_a = 1; } @@ -4403,7 +4459,7 @@ static void fn_800301D0(HSD_GObj* gobj, int arg1) HSD_GObj_80390ED0(gobj, 4); if (cm_80452C68.x398_b4) { - prio1_b = 0; + prio1_b = (prio1_b = 0); } else { prio1_b = 1; } @@ -4411,7 +4467,7 @@ static void fn_800301D0(HSD_GObj* gobj, int arg1) HSD_FogSet(NULL); if (cm_80452C68.x398_b3) { - prio8_b = 0; + prio8_b = (prio8_b = 0); } else { prio8_b = 0x80; } @@ -4420,7 +4476,7 @@ static void fn_800301D0(HSD_GObj* gobj, int arg1) Camera_800310A0(3); if (cm_80452C68.x398_b2) { - prio8_b = 0; + prio8_b = (prio8_b = 0); } else { prio8_b = 8; } @@ -4444,10 +4500,10 @@ static void fn_800301D0(HSD_GObj* gobj, int arg1) void Camera_800304E0(HSD_GObj* gobj) { - s64 var_r4; - s64 var_r0; - s64 var_r3; - s64 var_r3_2; + s64 prio8_a; + s64 prio1; + s64 prio8_b; + s64 prio8_c; HSD_CObj* cobj; PAD_STACK(32); @@ -4461,34 +4517,34 @@ void Camera_800304E0(HSD_GObj* gobj) Camera_800310A0(2); if (cm_80452C68.x398_b2) { - var_r4 = 0; + prio8_a = (prio8_a = 0); } else { - var_r4 = 8; + prio8_a = 8; } if (cm_80452C68.x398_b4) { - var_r0 = 0; + prio1 = (prio1 = 0); } else { - var_r0 = 1; + prio1 = 1; } - gobj->gxlink_prios = var_r0 | var_r4; + gobj->gxlink_prios = prio1 | prio8_a; HSD_GObj_80390ED0(gobj, 7); Camera_800310A0(1); if (cm_80452C68.x398_b2) { - var_r3 = 0; + prio8_b = (prio8_b = 0); } else { - var_r3 = 8; + prio8_b = 8; } - gobj->gxlink_prios = var_r3; + gobj->gxlink_prios = prio8_b; HSD_GObj_80390ED0(gobj, 7); Camera_800310A0(0); if (cm_80452C68.x398_b2) { - var_r3_2 = 0; + prio8_c = (prio8_c = 0); } else { - var_r3_2 = 8; + prio8_c = 8; } - gobj->gxlink_prios = var_r3_2; + gobj->gxlink_prios = prio8_c; HSD_GObj_80390ED0(gobj, 7); gobj->gxlink_prios = 0x70; @@ -4942,14 +4998,16 @@ void Camera_800311EC(HSD_GObj* gobj, u64 prios) a = inline_cam_gx_b1(); b = inline_cam_gx_b0(); - gobj->gxlink_prios = prios | b | a; + b = prios | b; + gobj->gxlink_prios = b | a; HSD_GObj_80390ED0(gobj, 3); cm_80452C68.x398_b6_b7 = 0; a = inline_cam_gx_b0(); b = inline_cam_gx_b4(); - gobj->gxlink_prios = inline_cam_gx_b1() | (b | a); + prios = inline_cam_gx_b1(); + gobj->gxlink_prios = prios | (b | a); HSD_GObj_80390ED0(gobj, 3); } @@ -4973,28 +5031,30 @@ void Camera_800313E0(HSD_GObj* gobj, u64 prios) { s64 a; s64 b; + u64 c; cm_80452C68.x398_b6_b7 = 1; a = inline_cam_gx_b1(); b = inline_cam_gx_b0(); - gobj->gxlink_prios = a | (prios | b); + b = prios | b; + gobj->gxlink_prios = b | a; HSD_GObj_80390ED0(gobj, 3); cm_80452C68.x398_b6_b7 = 0; a = inline_cam_gx_b0(); b = inline_cam_gx_b4(); - gobj->gxlink_prios = (b | a) | inline_cam_gx_b1(); + c = inline_cam_gx_b1(); + gobj->gxlink_prios = c | (b | a); HSD_GObj_80390ED0(gobj, 3); cm_80452C68.x398_b6_b7 = 0; a = inline_cam_gx_b0(); b = inline_cam_gx_b4(); - { - u64 c = inline_cam_gx_b1(); - gobj->gxlink_prios = ((prios | b) | a) | c; - } + c = inline_cam_gx_b1(); + b = prios | b; + gobj->gxlink_prios = (b | a) | c; HSD_GObj_80390ED0(gobj, 4); } diff --git a/src/melee/ef/efasync.c b/src/melee/ef/efasync.c index 76d6b9c586..571b602a62 100644 --- a/src/melee/ef/efasync.c +++ b/src/melee/ef/efasync.c @@ -475,47 +475,19 @@ void* efAsync_Dispatch(s32 gfx_id, HSD_GObj* gobj, va_list vlist) } } #else - if (jobj_1 == NULL) { - jobj_2 = NULL; - } else { - jobj_2 = jobj_1->child; - } - efLib_SetTevKonstColor(jobj_2, 0, u32_2, u32_1); - if (jobj_2 == NULL) { - jobj_2 = NULL; - } else { - jobj_2 = jobj_2->next; - } - efLib_SetTevKonstColor(jobj_2, 0, u32_2, u32_1); - if (jobj_2 == NULL) { - jobj_2 = NULL; - } else { - jobj_2 = jobj_2->next; - } - efLib_SetTevKonstColor(jobj_2, 0, u32_2, u32_1); - if (jobj_2 == NULL) { - jobj_2 = NULL; - } else { - jobj_2 = jobj_2->next; - } - efLib_SetTevKonstColor(jobj_2, 0, u32_2, u32_1); - if (jobj_2 == NULL) { - jobj_2 = NULL; - } else { - jobj_2 = jobj_2->next; - } - efLib_SetTevKonstColor(jobj_2, 0, u32_2, u32_1); - if (jobj_2 == NULL) { - jobj_2 = NULL; - } else { - jobj_2 = jobj_2->next; - } + jobj_2 = HSD_JObjGetChild(jobj_1); efLib_SetTevKonstColor(jobj_2, 0, u32_2, u32_1); - if (jobj_2 == NULL) { - jobj_1 = NULL; - } else { - jobj_1 = jobj_2->next; - } + jobj_1 = HSD_JObjGetNext(jobj_2); + efLib_SetTevKonstColor(jobj_1, 0, u32_2, u32_1); + jobj_1 = HSD_JObjGetNext(jobj_1); + efLib_SetTevKonstColor(jobj_1, 0, u32_2, u32_1); + jobj_1 = HSD_JObjGetNext(jobj_1); + efLib_SetTevKonstColor(jobj_1, 0, u32_2, u32_1); + jobj_1 = HSD_JObjGetNext(jobj_1); + efLib_SetTevKonstColor(jobj_1, 0, u32_2, u32_1); + jobj_1 = HSD_JObjGetNext(jobj_1); + efLib_SetTevKonstColor(jobj_1, 0, u32_2, u32_1); + jobj_1 = HSD_JObjGetNext(jobj_1); efLib_SetTevKonstColor(jobj_1, 0, u32_2, u32_1); #endif ((EF_Effect*) ret_obj)->scale_flags |= EF_SCALE_INHERIT; diff --git a/src/melee/ef/efsync.c b/src/melee/ef/efsync.c index 337a7c2f52..e2ce1e0ddc 100644 --- a/src/melee/ef/efsync.c +++ b/src/melee/ef/efsync.c @@ -36,6 +36,11 @@ extern EF_DAT_Entry efAsync_DatEntries[51]; // // Effects attach to a parent gobj and optionally a jobj for // position/rotation inheritance. Note there's variadic args! +static inline EF_Effect* efSync_GetEffect(void* ret_obj) +{ + return (EF_Effect*) ret_obj; +} + void* efSync_Spawn(s32 gfx_id, HSD_GObj* gobj, ...) { va_list vlist; @@ -48,25 +53,24 @@ void* efSync_Spawn(s32 gfx_id, HSD_GObj* gobj, ...) Vec3 scale_6; Vec3 unused; HSD_psAppSRT* psAppSRT; - HSD_Generator* generator; void* ret_obj; + EF_Effect* ret_eff; HSD_JObj* jobj_2; HSD_JObj* jobj_1; Vec3* va_vec3; f64 half_pi; f32 va_f32_1; f32 rand_f32; - f32 rand_rot_x; f32 rand_param_x; f32 rand_param_y; + f32 scale_f32; s32 cnt_1; Fighter* fp; s32 cnt_2; - PAD_STACK(0x4C); + f32 rand_rot_x; + PAD_STACK(0x44); - ret_obj = NULL; - efLib_LoadKind = EF_LOADKIND_ASYNC; - efLib_AnimCount = 0; + efLib_AnimCount = efLib_LoadKind = (u32) (ret_obj = NULL); va_start(vlist, gobj); if ((gfx_id == 0x479) && ((u32) efAsync_DatEntries[1].data == NULL)) { gfx_id = 0x506; @@ -124,8 +128,8 @@ void* efSync_Spawn(s32 gfx_id, HSD_GObj* gobj, ...) va_arg(vlist, void*)); if (ret_obj != NULL) { va_f32_1 = *va_arg(vlist, f32*); - jobj_1 = GET_JOBJ(((EF_Effect*) ret_obj)->gobj); - HSD_JObjSetRotationZ(jobj_1, va_f32_1); + HSD_JObjSetRotationZ(GET_JOBJ(((EF_Effect*) ret_obj)->gobj), + va_f32_1); } break; case 0x4C2: @@ -133,8 +137,8 @@ void* efSync_Spawn(s32 gfx_id, HSD_GObj* gobj, ...) va_arg(vlist, void*)); if (ret_obj != NULL) { va_f32_1 = *va_arg(vlist, f32*); - jobj_1 = GET_JOBJ(((EF_Effect*) ret_obj)->gobj); - HSD_JObjSetRotationZ(jobj_1, va_f32_1); + HSD_JObjSetRotationZ(GET_JOBJ(((EF_Effect*) ret_obj)->gobj), + va_f32_1); } break; case 0x4C3: { @@ -152,8 +156,8 @@ void* efSync_Spawn(s32 gfx_id, HSD_GObj* gobj, ...) va_arg(vlist, void*)); if (ret_obj != NULL) { va_f32_1 = *va_arg(vlist, f32*); - jobj_1 = GET_JOBJ(((EF_Effect*) ret_obj)->gobj); - HSD_JObjSetRotationZ(jobj_1, va_f32_1); + HSD_JObjSetRotationZ(GET_JOBJ(((EF_Effect*) ret_obj)->gobj), + va_f32_1); } break; case 0x4C5: @@ -161,8 +165,8 @@ void* efSync_Spawn(s32 gfx_id, HSD_GObj* gobj, ...) va_arg(vlist, void*)); if (ret_obj != NULL) { va_f32_1 = *va_arg(vlist, f32*); - jobj_1 = GET_JOBJ(((EF_Effect*) ret_obj)->gobj); - HSD_JObjSetRotationZ(jobj_1, va_f32_1); + HSD_JObjSetRotationZ(GET_JOBJ(((EF_Effect*) ret_obj)->gobj), + va_f32_1); } break; case 0x4C6: @@ -176,32 +180,32 @@ void* efSync_Spawn(s32 gfx_id, HSD_GObj* gobj, ...) case 0x4C8: ret_obj = efLib_Create_Attach_Scale(0x1F42, gobj, va_arg(vlist, HSD_JObj*)); - if (ret_obj != NULL) { + ret_eff = ret_obj; + if (ret_eff != NULL) { if (*va_arg(vlist, f32*) < 0.0f) { half_pi = -M_PI_2; } else { half_pi = M_PI_2; } va_f32_1 = half_pi; - jobj_1 = GET_JOBJ(((EF_Effect*) ret_obj)->gobj); - HSD_JObjSetRotationY(jobj_1, va_f32_1); - jobj_2 = GET_JOBJ(((EF_Effect*) ret_obj)->gobj); + HSD_JObjSetRotationY(GET_JOBJ(ret_eff->gobj), va_f32_1); + jobj_2 = GET_JOBJ(ret_eff->gobj); HSD_JObjAnimAll(jobj_2); } break; case 0x4C9: ret_obj = efLib_Create_Attach_Scale(0x1F43, gobj, va_arg(vlist, HSD_JObj*)); - if (ret_obj != NULL) { + ret_eff = ret_obj; + if (ret_eff != NULL) { if (*va_arg(vlist, f32*) < 0.0f) { half_pi = -M_PI_2; } else { half_pi = M_PI_2; } va_f32_1 = half_pi; - jobj_1 = GET_JOBJ(((EF_Effect*) ret_obj)->gobj); - HSD_JObjSetRotationY(jobj_1, va_f32_1); - jobj_2 = GET_JOBJ(((EF_Effect*) ret_obj)->gobj); + HSD_JObjSetRotationY(GET_JOBJ(ret_eff->gobj), va_f32_1); + jobj_2 = GET_JOBJ(ret_eff->gobj); HSD_JObjAnimAll(jobj_2); } break; @@ -234,11 +238,11 @@ void* efSync_Spawn(s32 gfx_id, HSD_GObj* gobj, ...) case 0x4D0: { EF_Effect* eff_1; EF_Effect* effect; - va_f32_1 = 1.0f; + scale_f32 = 1.0f; va_vec3 = va_arg(vlist, Vec3*); translate = *va_vec3; if (gfx_id == 0x4CF) { - va_f32_1 = *va_arg(vlist, f32*); + scale_f32 = *va_arg(vlist, f32*); } cnt_1 = 0; loop_141: @@ -262,17 +266,20 @@ void* efSync_Spawn(s32 gfx_id, HSD_GObj* gobj, ...) rand_rot_y = M_TAU * HSD_Randf(); rand_rot_x = M_TAU * HSD_Randf(); jobj_1 = GET_JOBJ(effect->gobj); - HSD_JObjSetScaleX(jobj_1, va_f32_1); + HSD_JObjSetScaleX(jobj_1, scale_f32); jobj_1 = GET_JOBJ(effect->gobj); - HSD_JObjSetScaleY(jobj_1, va_f32_1); + HSD_JObjSetScaleY(jobj_1, scale_f32); jobj_1 = GET_JOBJ(effect->gobj); - HSD_JObjSetScaleZ(jobj_1, va_f32_1); + HSD_JObjSetScaleZ(jobj_1, scale_f32); jobj_1 = GET_JOBJ(effect->gobj); HSD_JObjSetRotationY(jobj_1, rand_rot_y); jobj_1 = GET_JOBJ(effect->gobj); HSD_JObjSetRotationX(jobj_1, rand_rot_x); rand_param_x = sinf(rand_rot_y); - effect->params.x = 2.0f * cosf(rand_rot_x) * rand_param_x; + { + f32 tmp = 2.0f * cosf(rand_rot_x); + effect->params.x = tmp * rand_param_x; + } effect->params.y = 2.0f * sinf(rand_rot_x); rand_param_y = cosf(rand_rot_y); effect->params.z = 2.0f * cosf(rand_rot_x) * rand_param_y; @@ -309,20 +316,21 @@ void* efSync_Spawn(s32 gfx_id, HSD_GObj* gobj, ...) case 0x4D7: ret_obj = hsd_8039EFAC(0, 0xB, 0x2AF9, va_arg(vlist, HSD_JObj*)); break; - case 0x4D8: - ret_obj = efLib_CreateGenerator_AddAppSRT(0x61U); - if (ret_obj != NULL) { + case 0x4D8: { + HSD_Generator* generator = efLib_CreateGenerator_AddAppSRT(0x61U); + if (generator != NULL) { va_vec3 = va_arg(vlist, Vec3*); - psAppSRT = ((HSD_Generator*) ret_obj)->appsrt; + psAppSRT = generator->appsrt; psAppSRT->translate = *va_vec3; jobj_1 = GET_JOBJ(gobj); HSD_JObjGetScale(jobj_1, &scale_4); - generator = ret_obj; + ret_obj = generator; generator->appsrt->scale.x = generator->appsrt->scale.y = generator->appsrt->scale.z = scale_4.y; generator->appsrt->rot.y = M_PI_2; } break; + } case 0x4D9: ret_obj = efLib_Create_Attach_Pos(0x2EE0U, gobj, va_arg(vlist, Vec3*)); if (ret_obj != NULL) { @@ -332,11 +340,11 @@ void* efSync_Spawn(s32 gfx_id, HSD_GObj* gobj, ...) half_pi = M_PI_2; } va_f32_1 = half_pi; - jobj_1 = GET_JOBJ(((EF_Effect*) ret_obj)->gobj); - HSD_JObjSetRotationY(jobj_1, va_f32_1); + ret_eff = ret_obj; + HSD_JObjSetRotationY(GET_JOBJ(ret_eff->gobj), va_f32_1); jobj_2 = GET_JOBJ(gobj); HSD_JObjGetScale(jobj_2, &scale_6); - jobj_1 = GET_JOBJ(((EF_Effect*) ret_obj)->gobj); + jobj_1 = GET_JOBJ(ret_eff->gobj); HSD_JObjSetScale(jobj_1, &scale_6); } break; @@ -381,9 +389,9 @@ void* efSync_Spawn(s32 gfx_id, HSD_GObj* gobj, ...) while (HSD_JObjGetParent(jobj_2) != NULL) { jobj_2 = HSD_JObjGetParent(jobj_2); } - HSD_JObjGetScale(jobj_1, &scale_5); + HSD_JObjGetScale(jobj_2, &scale_5); ((EF_Effect*) ret_obj)->params = *va_arg(vlist, Vec3*); - ((EF_Effect*) ret_obj)->params.y *= scale_5.y; + efSync_GetEffect(ret_obj)->params.y *= scale_5.y; } break; case 0x4E2: @@ -463,10 +471,11 @@ void* efSync_Spawn(s32 gfx_id, HSD_GObj* gobj, ...) if (ret_obj != NULL) { jobj_1 = GET_JOBJ(gobj); HSD_JObjGetScale(jobj_1, &scale_4); - if (GET_JOBJ(((EF_Effect*) ret_obj)->gobj) == NULL) { + ret_eff = ret_obj; + if (GET_JOBJ(ret_eff->gobj) == NULL) { __assert("jobj.h", 823, "jobj"); } - jobj_2 = GET_JOBJ(((EF_Effect*) ret_obj)->gobj); + jobj_2 = GET_JOBJ(ret_eff->gobj); HSD_JObjSetScale(jobj_2, &scale_4); } break; @@ -509,8 +518,8 @@ void* efSync_Spawn(s32 gfx_id, HSD_GObj* gobj, ...) half_pi = M_PI_2; } va_f32_1 = half_pi; - jobj_1 = GET_JOBJ(((EF_Effect*) ret_obj)->gobj); - HSD_JObjSetRotationY(jobj_1, va_f32_1); + HSD_JObjSetRotationY(GET_JOBJ(((EF_Effect*) ret_obj)->gobj), + va_f32_1); ((EF_Effect*) ret_obj)->attach_jobj = fp->parts[85].joint; ((EF_Effect*) ret_obj)->update = efLib_Cb_LifetimeEndSpawn; ((EF_Effect*) ret_obj)->lifetime = 6; @@ -528,32 +537,34 @@ void* efSync_Spawn(s32 gfx_id, HSD_GObj* gobj, ...) case 0x503: ret_obj = efLib_CreateGenerator(0x6AU, va_arg(vlist, Vec3*)); break; - case 0x504: - ret_obj = efLib_CreateGenerator_AddAppSRT(0x6DU); - if (ret_obj != NULL) { + case 0x504: { + HSD_Generator* generator = efLib_CreateGenerator_AddAppSRT(0x6DU); + if (generator != NULL) { va_vec3 = va_arg(vlist, Vec3*); - psAppSRT = ((HSD_Generator*) ret_obj)->appsrt; + psAppSRT = generator->appsrt; psAppSRT->translate = *va_vec3; jobj_1 = GET_JOBJ(gobj); HSD_JObjGetScale(jobj_1, &scale_3); - generator = ret_obj; + ret_obj = generator; generator->appsrt->scale.x = generator->appsrt->scale.y = generator->appsrt->scale.z = scale_3.y; } break; - case 0x505: - ret_obj = efLib_CreateGenerator_AddAppSRT(0x79U); - if (ret_obj != NULL) { + } + case 0x505: { + HSD_Generator* generator = efLib_CreateGenerator_AddAppSRT(0x79U); + if (generator != NULL) { va_vec3 = va_arg(vlist, Vec3*); - psAppSRT = ((HSD_Generator*) ret_obj)->appsrt; + psAppSRT = generator->appsrt; psAppSRT->translate = *va_vec3; jobj_1 = gobj->hsd_obj; HSD_JObjGetScale(jobj_1, &scale_2); - generator = ret_obj; + ret_obj = generator; generator->appsrt->scale.x = generator->appsrt->scale.y = generator->appsrt->scale.z = scale_2.y; } break; + } case 0x506: ret_obj = efLib_CreateGenerator(0x4658U, va_arg(vlist, Vec3*)); break; @@ -567,8 +578,8 @@ void* efSync_Spawn(s32 gfx_id, HSD_GObj* gobj, ...) half_pi = M_PI_2; } va_f32_1 = half_pi; - jobj_1 = GET_JOBJ(((EF_Effect*) ret_obj)->gobj); - HSD_JObjSetRotationY(jobj_1, va_f32_1); + HSD_JObjSetRotationY(GET_JOBJ(((EF_Effect*) ret_obj)->gobj), + va_f32_1); } hsd_8039EFAC(0, 0x12, 0x4650, jobj_1); break; @@ -615,8 +626,8 @@ void* efSync_Spawn(s32 gfx_id, HSD_GObj* gobj, ...) half_pi = M_PI_2; } va_f32_1 = half_pi; - jobj_1 = GET_JOBJ(((EF_Effect*) ret_obj)->gobj); - HSD_JObjSetRotationY(jobj_1, va_f32_1); + HSD_JObjSetRotationY(GET_JOBJ(((EF_Effect*) ret_obj)->gobj), + va_f32_1); } break; case 0x50F: @@ -629,8 +640,8 @@ void* efSync_Spawn(s32 gfx_id, HSD_GObj* gobj, ...) half_pi = M_PI_2; } va_f32_1 = half_pi; - jobj_1 = GET_JOBJ(((EF_Effect*) ret_obj)->gobj); - HSD_JObjSetRotationY(jobj_1, va_f32_1); + HSD_JObjSetRotationY(GET_JOBJ(((EF_Effect*) ret_obj)->gobj), + va_f32_1); } break; case 0x510: diff --git a/src/melee/ft/chara/ftCommon/ftCo_0A01.c b/src/melee/ft/chara/ftCommon/ftCo_0A01.c index d162e034f3..5ec4f7106a 100644 --- a/src/melee/ft/chara/ftCommon/ftCo_0A01.c +++ b/src/melee/ft/chara/ftCommon/ftCo_0A01.c @@ -1121,12 +1121,10 @@ static inline bool inlineL1(mp_UnkStruct0* arg0) #pragma dont_inline on bool ftCo_800A2718(mp_UnkStruct0* arg0) { - mp_UnkStruct0* island; - + mp_UnkStruct0* island = (mp_UnkStruct0*) arg0; if (arg0 == NULL) { return false; } - island = arg0; { Item_GObj* cur; Item* cur_ip; @@ -1390,14 +1388,19 @@ s32 ftCo_800A2C80(Fighter* fp) return 1; } lbVector_Normalize(&dir); - ax = fp->coll_data.cur_pos.x + fp->coll_data.ecb.bottom.x; - ay = fp->coll_data.cur_pos.y + fp->coll_data.ecb.bottom.y; + { + f32 bottom_x = fp->coll_data.cur_pos.x + fp->coll_data.ecb.bottom.x; + f32 bottom_y = fp->coll_data.cur_pos.y + fp->coll_data.ecb.bottom.y; + ax = bottom_x; + ay = bottom_y; + } ex = 1000.0f * dir.x + ax; ey = 1000.0f * dir.y + ay; line_id = -1; blocked = 0; - result = mpCheckFloor(ax, ay, ex, ey, 0.0f, &floor_pos, &line_id, &flags, - &floor_normal, -1, -1, -1, NULL, NULL); + result = + mpCheckFloor(ax, ay, ex, ey, 0.0f, &floor_pos, &line_id, &flags, + &floor_normal, -1, -1, -1, NULL, (Fighter_GObj*) blocked); if (result != 0) { int line = line_id; if (grBigBlue_801EF844(line) || grInishie1_801FCAAC(line) || @@ -1411,9 +1414,13 @@ s32 ftCo_800A2C80(Fighter* fp) } if (result != 0) { { - struct Fighter_x1A88_t* temp_data = &fp->x1A88; - f32 floor_x = floor_pos.x; - f32 floor_y = floor_pos.y; + f32 floor_x; + f32 floor_y; + struct Fighter_x1A88_t* temp_data; + + floor_y = floor_pos.y; + temp_data = &fp->x1A88; + floor_x = floor_pos.x; if (floor_x < fp->x1A88.half_width + Stage_GetBlastZoneLeftOffset() || floor_x > @@ -1436,9 +1443,13 @@ s32 ftCo_800A2C80(Fighter* fp) &floor_normal, -1, -1) != 0) { { - struct Fighter_x1A88_t* temp_data = &fp->x1A88; - f32 floor_x = floor_pos.x; - f32 floor_y = floor_pos.y; + f32 floor_x; + f32 floor_y; + struct Fighter_x1A88_t* temp_data; + + floor_y = floor_pos.y; + temp_data = &fp->x1A88; + floor_x = floor_pos.x; if (floor_x < fp->x1A88.half_width + Stage_GetBlastZoneLeftOffset() || floor_x > @@ -1461,9 +1472,13 @@ s32 ftCo_800A2C80(Fighter* fp) &floor_normal, -1, -1) != 0) { { - struct Fighter_x1A88_t* temp_data = &fp->x1A88; - f32 floor_x = floor_pos.x; - f32 floor_y = floor_pos.y; + f32 floor_x; + f32 floor_y; + struct Fighter_x1A88_t* temp_data; + + floor_y = floor_pos.y; + temp_data = &fp->x1A88; + floor_x = floor_pos.x; if (floor_x < fp->x1A88.half_width + Stage_GetBlastZoneLeftOffset() || floor_x > @@ -1760,27 +1775,30 @@ static inline bool ftCo_IsAlly_dontinline(Fighter* fp0, Fighter* fp1) return ftCo_IsAlly(fp0, fp1); } +static inline float ftCo_800A3908_inline0(Fighter* fp, s32 t) +{ + return fp->co_attrs.grav * sqrtf((f32) t); +} + bool ftCo_800A3908(Fighter* fp, bool arg1) { struct Fighter_x1A88_t* data = &fp->x1A88; s32 t; - Vec3 sp58; + u32 flags; + int line_id; + Vec3 island_pos; Vec3 sp64; Vec3 sp38; Vec3 sp44; - Vec3 island_pos; - u32 flags; - int line_id; - f32 ex; + f32 dist; + Vec3 floor_pos; f32 ey; f32 ez; f32 grav; f32 dx; f32 px; - f32 dist; f32 ddx; f32 ddy; - f32 land_y; s32 frames; mp_UnkStruct0* island; s32 result; @@ -1804,11 +1822,13 @@ bool ftCo_800A3908(Fighter* fp, bool arg1) for (island = mpIsland_80458E88.next; island != NULL; island = island->next) { + f32 ex; island_pos = island->x14; ex = island_pos.x; ey = island_pos.y; (void) ey; ez = island_pos.z; + (void) ez; if (ex < fp->x1A88.half_width + Stage_GetBlastZoneLeftOffset() || ex > Stage_GetBlastZoneRightOffset() - data->half_width || ey < data->half_height + Stage_GetBlastZoneBottomOffset() || @@ -1826,13 +1846,13 @@ bool ftCo_800A3908(Fighter* fp, bool arg1) } dx = fp->cur_pos.x - ex; if (dx > 0.0f) { + f32 land_y; t = dx / fp->co_attrs.air_drift_max; if (frames <= 0) { land_y = fp->pos_delta.y * t + fp->cur_pos.y; } else if (t < frames) { - land_y = fp->cur_pos.y + - (fp->pos_delta.y * t - - 0.5 * (fp->co_attrs.grav * sqrtf((f32) t))); + land_y = fp->cur_pos.y + (fp->pos_delta.y * t - + 0.5 * ftCo_800A3908_inline0(fp, t)); } else { land_y = fp->cur_pos.y + ((fp->pos_delta.y * frames - @@ -1846,7 +1866,7 @@ bool ftCo_800A3908(Fighter* fp, bool arg1) px = ex - 5.0; { s32 floor_result = mpCheckFloor( - px, 5.0f + ey, px, ey - 5.0f, 0.0f, &sp58, + px, 5.0f + ey, px, ey - 5.0f, 0.0f, &floor_pos, &line_id, &flags, &sp64, -1, -1, -1, NULL, NULL); result = floor_result; } @@ -1877,10 +1897,11 @@ bool ftCo_800A3908(Fighter* fp, bool arg1) ok = 0; } if (ok != 0) { - if (data->x60 == 0) { - data->x54.x = px; - data->x54.y = ey; - data->x38 = 5.0f; + struct Fighter_x1A88_t* data2 = &fp->x1A88; + if (fp->x1A88.x60 == 0) { + data2->x54.x = px; + data2->x54.y = ey; + data2->x38 = 5.0f; ftCo_800A1CC4( fp, ftCo_803C6594[stage_info.internal_stage_id]); @@ -1926,7 +1947,7 @@ bool ftCo_800A3908(Fighter* fp, bool arg1) if (ok != 0) { dist = sqrtf(ddx * ddx + ddy * ddy); if (data->x5C > dist) { - if (data->x60 == 0) { + if (fp->x1A88.x60 == 0) { data->x54.x = px; data->x54.y = ey; data->x38 = 5.0f; @@ -1943,17 +1964,21 @@ bool ftCo_800A3908(Fighter* fp, bool arg1) return 0; } +static inline float ftCo_800A4038_inline0(Fighter* fp) +{ + return fp->co_attrs.terminal_vel; +} + +static inline bool ftCo_800A4038_inline1(int line_id) +{ + return ftCo_800A1B38_noinline(line_id) != 0; +} + bool ftCo_800A4038(Fighter* fp, bool arg1) { struct Fighter_x1A88_t* data = &fp->x1A88; s32 t; - Vec3 sp58; - Vec3 sp64; - Vec3 sp38; - Vec3 sp44; Vec3 island_pos; - u32 flags; - int line_id; f32 ex; f32 ey; f32 ez; @@ -1963,7 +1988,6 @@ bool ftCo_800A4038(Fighter* fp, bool arg1) f32 dist; f32 ddx; f32 ddy; - f32 land_y; s32 frames; mp_UnkStruct0* island; s32 result; @@ -1971,7 +1995,7 @@ bool ftCo_800A4038(Fighter* fp, bool arg1) s32 ok; s32 oob; - PAD_STACK(0x10); + PAD_STACK(0x8); grav = fp->co_attrs.grav; if (grav < 0.00001f && grav > -0.00001f) { @@ -1989,8 +2013,10 @@ bool ftCo_800A4038(Fighter* fp, bool arg1) { island_pos = island->x8; ex = island_pos.x; - ey = island_pos.y; - (void) ey; + { + f32 y = island_pos.y; + ey = y; + } ez = island_pos.z; if (ex < fp->x1A88.half_width + Stage_GetBlastZoneLeftOffset() || ex > Stage_GetBlastZoneRightOffset() - data->half_width || @@ -2009,6 +2035,7 @@ bool ftCo_800A4038(Fighter* fp, bool arg1) } dx = ex - fp->cur_pos.x; if (dx > 0.0f) { + f32 land_y; t = dx / fp->co_attrs.air_drift_max; if (frames <= 0) { land_y = fp->pos_delta.y * t + fp->cur_pos.y; @@ -2020,22 +2047,31 @@ bool ftCo_800A4038(Fighter* fp, bool arg1) land_y = fp->cur_pos.y + ((fp->pos_delta.y * frames - 0.5 * (fp->co_attrs.grav * sqrtf((f32) frames))) - - (f32) (t - frames) * fp->co_attrs.terminal_vel); + (f32) (t - frames) * ftCo_800A4038_inline0(fp)); } if (arg1 != 0) { if (!(land_y + data->x558 < ey)) { - line_id = -1; valid = 0; px = 5.0 + ex; { - s32 floor_result = mpCheckFloor( - px, 5.0f + ey, px, ey - 5.0f, 0.0f, &sp58, - &line_id, &flags, &sp64, -1, -1, -1, NULL, NULL); + Vec3 floor_pos; + Vec3 floor_normal; + int line_id; + u32 flags; + s32 floor_result; + + line_id = -1; + floor_result = mpCheckFloor( + px, 5.0f + ey, px, ey - 5.0f, 0.0f, &floor_pos, + &line_id, &flags, &floor_normal, -1, -1, -1, NULL, + NULL); result = floor_result; - } - if (result != 0 && ftCo_800A1B38_noinline(line_id) != 0) { - } else { - valid = result; + if (result != 0 && + ftCo_800A1B38_noinline(line_id) != 0) + { + } else { + valid = result; + } } if (valid != 0) { if (px < fp->x1A88.half_width + @@ -2060,10 +2096,11 @@ bool ftCo_800A4038(Fighter* fp, bool arg1) ok = 0; } if (ok != 0) { - if (data->x60 == 0) { - data->x54.x = px; - data->x54.y = ey; - data->x38 = 5.0f; + struct Fighter_x1A88_t* data2 = &fp->x1A88; + if (fp->x1A88.x60 == 0) { + data2->x54.x = px; + data2->x54.y = ey; + data2->x38 = 5.0f; ftCo_800A1CC4( fp, ftCo_803C6594[stage_info.internal_stage_id]); @@ -2075,15 +2112,23 @@ bool ftCo_800A4038(Fighter* fp, bool arg1) } else { ddy = ey - fp->cur_pos.y; px = 5.0 + ex; - line_id = -1; valid = 0; ddx = px - fp->cur_pos.x; - result = mpCheckFloor(px, 5.0f + ey, px, ey - 5.0f, 0.0f, - &sp38, &line_id, &flags, &sp44, -1, -1, - -1, NULL, NULL); - if (result != 0 && ftCo_800A1B38_noinline(line_id) != 0) { - } else { - valid = result; + { + Vec3 alt_floor_pos; + Vec3 alt_floor_normal; + int line_id; + u32 flags; + + line_id = -1; + result = mpCheckFloor(px, 5.0f + ey, px, ey - 5.0f, 0.0f, + &alt_floor_pos, &line_id, &flags, + &alt_floor_normal, -1, -1, -1, NULL, + NULL); + if (result != 0 && ftCo_800A4038_inline1(line_id)) { + } else { + valid = result; + } } if (valid != 0) { if (px < fp->x1A88.half_width + @@ -2109,7 +2154,7 @@ bool ftCo_800A4038(Fighter* fp, bool arg1) if (ok != 0) { dist = sqrtf(ddx * ddx + ddy * ddy); if (data->x5C > dist) { - if (data->x60 == 0) { + if (fp->x1A88.x60 == 0) { data->x54.x = px; data->x54.y = ey; data->x38 = 5.0f; @@ -2944,14 +2989,14 @@ Item* ftCo_800A61D8(Fighter* fp) f32 best; f32 dist; - PAD_STACK(8); - data = &fp->x1A88; if (fp == NULL) { return NULL; } closest = NULL; for (cur = HSD_GObj_Entities->items; cur != NULL; cur = cur->next) { + ip = GET_ITEM(cur); + ip = GET_ITEM(cur); ip = GET_ITEM(cur); if (!Item_IsGrabbable((Item_GObj*) cur)) { continue; @@ -3078,7 +3123,6 @@ bool ftCo_800A6700(Fighter* fp, Vec3* arg1, Vec3* arg2) int line_id; u32 flags; f32 ax; - f32 az; f32 px; s32 result; @@ -3091,7 +3135,6 @@ bool ftCo_800A6700(Fighter* fp, Vec3* arg1, Vec3* arg2) a = island->x8; ax = a.x; ay = a.y; - az = a.z; px = ax + 5.0; line_id = -1; result = mpCheckFloor(px, ay + 5.0, px, ay - 5.0, 0.0f, &floor_pos, @@ -3110,14 +3153,13 @@ bool ftCo_800A6700(Fighter* fp, Vec3* arg1, Vec3* arg2) best = dist; arg2->x = ax + 5.0; arg2->y = ay; - arg2->z = az; + arg2->z = a.z; } } } b = island->x14; ax = b.x; ay = b.y; - az = b.z; px = ax - 5.0; line_id = -1; result = mpCheckFloor(px, ay + 5.0, px, ay - 5.0, 0.0f, &floor_pos, @@ -3135,7 +3177,7 @@ bool ftCo_800A6700(Fighter* fp, Vec3* arg1, Vec3* arg2) best = dist; arg2->x = ax - 5.0; arg2->y = ay; - arg2->z = az; + arg2->z = b.z; } } } @@ -3149,40 +3191,46 @@ bool ftCo_800A6700(Fighter* fp, Vec3* arg1, Vec3* arg2) s32 ftCo_800A6A98(Fighter* fp, Vec3* arg1) { - struct Fighter_x1A88_t* data = &fp->x1A88; - mp_UnkStruct0* island; - f32 best; + UNUSED u8 _[4]; + f32 dist; + Vec3 b; + Vec3 a; Vec3 floor_pos; Vec3 floor_normal; int line_id; u32 flags; - Vec3 a; - Vec3 b; f32 mx; f32 my; s32 result; s32 blocked; + s32 line; + f32 fy; + f32 fx; f32 dx; f32 dy; - f32 dist; - u8 operand_pad[12]; + struct Fighter_x1A88_t* data = &fp->x1A88; + mp_UnkStruct0* island; + f32 best; best = -1.0f; for (island = mpIsland_80458E88.next; island != NULL; island = island->next) { if (ftCo_800A2718(island) == 0) { - blocked = 0; a = island->x8; b = island->x14; + blocked = 0; line_id = -1; mx = 0.5f * (b.x + a.x); my = 0.5f * (b.y + a.y); result = mpCheckFloor(mx, 5.0f + my, mx, my - 20.0f, 0.0f, &floor_pos, &line_id, &flags, &floor_normal, - -1, -1, -1, NULL, NULL); + -1, -1, -1, NULL, (Fighter_GObj*) blocked); if (result != 0) { - if (ftCo_800A6A98_inline0(line_id)) { + line = line_id; + if (grBigBlue_801EF844(line) || grInishie1_801FCAAC(line) || + grCorneria_801E2D90(line) || grVenom_80206D10(line)) + { blocked = 1; } if (blocked != 0) { @@ -3192,16 +3240,20 @@ s32 ftCo_800A6A98(Fighter* fp, Vec3* arg1) if (result != 0 && line_id != -1 && (mpLineGetFlags(line_id) & LINE_FLAG_PLATFORM)) { - f32 fx = floor_pos.x; - if (!(floor_pos.y < fp->cur_pos.y + data->x568)) { - if (!ftCo_800A4768_inline0(fp, &floor_pos)) { + fy = floor_pos.y; + fx = floor_pos.x; + (void) fx; + if (!(fy < fp->cur_pos.y + data->x568)) { + if (!ftCo_800A6700_inline0(fp, fx, fy)) { dx = fx - fp->cur_pos.x; - dy = floor_pos.y - fp->cur_pos.y; - dist = dx * dx + dy * dy; + dy = fy - fp->cur_pos.y; + dx *= dx; + dy *= dy; + dist = dx + dy; if (best < 0.0 || dist < best) { arg1->x = fx; best = dist; - arg1->y = floor_pos.y; + arg1->y = fy; arg1->z = 0.0f; } } @@ -3217,8 +3269,8 @@ s32 ftCo_800A6A98(Fighter* fp, Vec3* arg1) s32 ftCo_800A6D2C(Fighter* fp, Vec3* arg1) { + f32 dist; mp_UnkStruct0* island; - mp_UnkStruct0* cur_island; Vec3 b; Vec3 a; Vec3 floor_pos; @@ -3228,14 +3280,14 @@ s32 ftCo_800A6D2C(Fighter* fp, Vec3* arg1) f32 mx; f32 my; s32 result; - struct Fighter_x1A88_t* data = &fp->x1A88; + mp_UnkStruct0* cur_island; s32 blocked; s32 line; f32 fy; f32 fx; f32 dx; f32 dy; - f32 dist; + struct Fighter_x1A88_t* data = &fp->x1A88; f32 best; PAD_STACK(4); @@ -3245,7 +3297,7 @@ s32 ftCo_800A6D2C(Fighter* fp, Vec3* arg1) for (island = mpIsland_80458E88.next; island != NULL; island = island->next) { - if (ftCo_800A2718(island) == 0 && island != cur_island) { + if (ftCo_800A2718(island) == 0 && cur_island != island) { a = island->x8; b = island->x14; HSD_Randf(); @@ -3255,7 +3307,7 @@ s32 ftCo_800A6D2C(Fighter* fp, Vec3* arg1) my = 0.5f * (b.y + a.y); result = mpCheckFloor(mx, 5.0f + my, mx, my - 20.0f, 0.0f, &floor_pos, &line_id, &flags, &floor_normal, - -1, -1, -1, NULL, NULL); + -1, -1, -1, NULL, (Fighter_GObj*) blocked); if (result != 0) { line = line_id; if (grBigBlue_801EF844(line) || grInishie1_801FCAAC(line) || @@ -3271,7 +3323,7 @@ s32 ftCo_800A6D2C(Fighter* fp, Vec3* arg1) fy = floor_pos.y; fx = floor_pos.x; (void) fx; - if (fy >= fp->cur_pos.y - data->x558) { + if (!(fy >= fp->cur_pos.y - data->x558)) { if (!ftCo_800A6700_inline0(fp, fx, fy)) { dx = fx - fp->cur_pos.x; dy = fy - fp->cur_pos.y; @@ -3297,6 +3349,7 @@ s32 ftCo_800A6D2C(Fighter* fp, Vec3* arg1) bool ftCo_800A6FC4(Fighter* fp, Vec3* arg1, Vec3* arg2) { + UNUSED u8 _[8]; Vec3 b; Vec3 a; Vec3 floor_pos; @@ -3307,18 +3360,20 @@ bool ftCo_800A6FC4(Fighter* fp, Vec3* arg1, Vec3* arg2) mp_UnkStruct0* island; mp_UnkStruct0* cur_island; struct Fighter_x1A88_t* data; - f32 best; f32 px; + f32 floor_y; f32 fx; f32 fy; f32 mx; f32 my; f32 dx; f32 dy; + f32 dist2; f32 dist; - s32 result; - s32 blocked; + f32 best; s32 line; + s32 blocked; + s32 result; PAD_STACK(0x10); @@ -3335,13 +3390,13 @@ bool ftCo_800A6FC4(Fighter* fp, Vec3* arg1, Vec3* arg2) b = island->x14; a = island->x8; HSD_Randf(); - blocked = 0; line_id = -1; - my = 0.5f * (a.y + b.y); + blocked = 0; mx = 0.5f * (a.x + b.x); - result = mpCheckFloor(mx, my + 10.0, mx, my - 10.0f, 0.0f, &floor_pos, + my = 0.5f * (a.y + b.y); + result = mpCheckFloor(mx, 10.0 + my, mx, my - 10.0, 0.0f, &floor_pos, &line_id, &flags, &floor_normal, -1, -1, -1, - NULL, NULL); + NULL, (Fighter_GObj*) blocked); if (result != 0) { line = line_id; if (grBigBlue_801EF844(line) || grInishie1_801FCAAC(line) || @@ -3370,8 +3425,9 @@ bool ftCo_800A6FC4(Fighter* fp, Vec3* arg1, Vec3* arg2) } dx = fx - fp->cur_pos.x; dy = fy - fp->cur_pos.y; - dist = dx * dx; - dist += dy * dy; + dx *= dx; + dy *= dy; + dist = dx + dy; if (!ftCo_800A6700_inline0(fp, fx, fy)) { if (best < 0.0 || dist < best) { arg1->x = fx; @@ -3381,27 +3437,28 @@ bool ftCo_800A6FC4(Fighter* fp, Vec3* arg1, Vec3* arg2) } } line_id = -1; - blocked = 0; + line = 0; px = a.x + 5.0; - result = mpCheckFloor(px, a.y + 10.0, px, a.y - 10.0, 0.0f, &floor_pos, - &line_id, &flags, &floor_normal, -1, -1, -1, - NULL, NULL); - if (result != 0) { - line = line_id; - if (grBigBlue_801EF844(line) || grInishie1_801FCAAC(line) || - grCorneria_801E2D90(line) || grVenom_80206D10(line)) + blocked = mpCheckFloor(px, a.y + 10.0, px, a.y - 10.0, 0.0f, + &floor_pos, &line_id, &flags, &floor_normal, -1, + -1, -1, NULL, (Fighter_GObj*) line); + if (blocked != 0) { + result = line_id; + if (grBigBlue_801EF844(result) || grInishie1_801FCAAC(result) || + grCorneria_801E2D90(result) || grVenom_80206D10(result)) { - blocked = 1; + line = 1; } - if (blocked != 0) { - result = 0; + if (line != 0) { + blocked = 0; } } - if (result == 0) { + if (blocked == 0) { continue; } fx = floor_pos.x; - fy = floor_pos.y; + my = floor_pos.y; + fy = my; dir.x = fx - fp->cur_pos.x; dir.y = fy - fp->cur_pos.y; dir.z = 0.0f; @@ -3411,38 +3468,40 @@ bool ftCo_800A6FC4(Fighter* fp, Vec3* arg1, Vec3* arg2) } dx = fx - fp->cur_pos.x; dy = fy - fp->cur_pos.y; - dist = dx * dx; - dist += dy * dy; + dx *= dx; + dy *= dy; + dist2 = dx + dy; if (!ftCo_800A6700_inline0(fp, fx, fy)) { - if (dist < best) { + if (dist2 < best) { arg1->x = fx; - best = dist; + best = dist2; arg1->y = fy; arg1->z = 0.0f; } } line_id = -1; - blocked = 0; + line = 0; px = b.x - 5.0; - result = mpCheckFloor(px, b.y + 10.0, px, b.y - 10.0, 0.0f, &floor_pos, - &line_id, &flags, &floor_normal, -1, -1, -1, - NULL, NULL); - if (result != 0) { - line = line_id; - if (grBigBlue_801EF844(line) || grInishie1_801FCAAC(line) || - grCorneria_801E2D90(line) || grVenom_80206D10(line)) + blocked = mpCheckFloor(px, b.y + 10.0, px, b.y - 10.0, 0.0f, + &floor_pos, &line_id, &flags, &floor_normal, -1, + -1, -1, NULL, (Fighter_GObj*) line); + if (blocked != 0) { + result = line_id; + if (grBigBlue_801EF844(result) || grInishie1_801FCAAC(result) || + grCorneria_801E2D90(result) || grVenom_80206D10(result)) { - blocked = 1; + line = 1; } - if (blocked != 0) { - result = 0; + if (line != 0) { + blocked = 0; } } - if (result == 0) { + if (blocked == 0) { continue; } fx = floor_pos.x; - fy = floor_pos.y; + floor_y = floor_pos.y; + fy = floor_y; dir.x = fx - fp->cur_pos.x; dir.y = fy - fp->cur_pos.y; dir.z = 0.0f; @@ -3452,8 +3511,9 @@ bool ftCo_800A6FC4(Fighter* fp, Vec3* arg1, Vec3* arg2) } dx = fx - fp->cur_pos.x; dy = fy - fp->cur_pos.y; - dist = dx * dx; - dist += dy * dy; + dx *= dx; + dy *= dy; + dist = dx + dy; if (!ftCo_800A6700_inline0(fp, fx, fy)) { if (dist < best) { arg1->x = fx; @@ -3472,15 +3532,15 @@ bool ftCo_800A6FC4(Fighter* fp, Vec3* arg1, Vec3* arg2) void ftCo_800A75DC(Fighter* fp0, Fighter* fp1) { struct Fighter_x1A88_t* data = &fp0->x1A88; + int* x60 = &fp0->x1A88.x60; Vec3 floor_pos; Vec3 floor_normal; int line_id; u32 flags; - u8 _[0x18]; + u8 _[0x10]; Vec3 sp18; mp_UnkStruct0* island; mp_UnkStruct0* fp0_island; - s32 result; s32 blocked; s32 same_island; f32 fx; @@ -3492,6 +3552,7 @@ void ftCo_800A75DC(Fighter* fp0, Fighter* fp1) return; } if (fp1->ground_or_air == GA_Air) { + s32 result; fx = fp1->cur_pos.x; fy = fp1->cur_pos.y; blocked = 0; @@ -3500,7 +3561,7 @@ void ftCo_800A75DC(Fighter* fp0, Fighter* fp1) f32 below = fy - 1000.0f; result = mpCheckFloor(fx, 10.0f + fy, fx, below, 0.0f, &floor_pos, &line_id, &flags, &floor_normal, -1, -1, -1, - NULL, NULL); + NULL, (Fighter_GObj*) blocked); } if (result != 0) { int line = line_id; @@ -3516,11 +3577,14 @@ void ftCo_800A75DC(Fighter* fp0, Fighter* fp1) if (result != 0) { island = mpIsland_8005AB54(line_id); if (ftCo_800A2718(island) == 0) { + struct Fighter_x1A88_t* data2 = &fp0->x1A88; f32 x38 = data->x56C + fp1->x1A88.x564; - if (fp0->x1A88.x60 == 0) { - data->x54.x = floor_pos.x; - data->x54.y = floor_pos.y; - data->x38 = data->x56C + fp1->x1A88.x564; + f32 x = floor_pos.x; + f32 y = floor_pos.y; + if (*x60 == 0) { + data2->x54.x = x; + data2->x54.y = y; + data2->x38 = x38; ftCo_800A1CC4(fp0, ftCo_803C6594[stage_info.internal_stage_id]); } @@ -3530,11 +3594,14 @@ void ftCo_800A75DC(Fighter* fp0, Fighter* fp1) d = -d; } if (d < 5.0) { + struct Fighter_x1A88_t* data2 = &fp0->x1A88; f32 x38_edge = data->x56C + fp1->x1A88.x564; - if (fp0->x1A88.x60 == 0) { - data->x54.x = island->x14.x - 5.0; - data->x54.y = island->x14.y; - data->x38 = x38_edge; + f32 x = island->x14.x - 5.0; + f32 y = island->x14.y; + if (*x60 == 0) { + data2->x54.x = x; + data2->x54.y = y; + data2->x38 = x38_edge; ftCo_800A1CC4( fp0, ftCo_803C6594[stage_info.internal_stage_id]); @@ -3544,12 +3611,15 @@ void ftCo_800A75DC(Fighter* fp0, Fighter* fp1) if (d < 0.0f) { d = -d; } - if (d < 5.0f) { + if (d < 5.0) { + struct Fighter_x1A88_t* data2 = &fp0->x1A88; f32 x38_edge = data->x56C + fp1->x1A88.x564; - if (fp0->x1A88.x60 == 0) { - data->x54.x = 5.0 + island->x8.x; - data->x54.y = island->x8.y; - data->x38 = x38_edge; + f32 x = 5.0 + island->x8.x; + f32 y = island->x8.y; + if (*x60 == 0) { + data2->x54.x = x; + data2->x54.y = y; + data2->x38 = x38_edge; ftCo_800A1CC4( fp0, ftCo_803C6594[stage_info @@ -3564,9 +3634,11 @@ void ftCo_800A75DC(Fighter* fp0, Fighter* fp1) { struct Fighter_x1A88_t* data2 = &fp0->x1A88; f32 x38 = data->x56C + fp1->x1A88.x564; - if (fp0->x1A88.x60 == 0) { - data2->x54.x = sp18.x; - data2->x54.y = sp18.y; + f32 x = sp18.x; + f32 y = sp18.y; + if (*x60 == 0) { + data2->x54.x = x; + data2->x54.y = y; data2->x38 = x38; ftCo_800A1CC4(fp0, ftCo_803C6594[stage_info.internal_stage_id]); @@ -3577,9 +3649,11 @@ void ftCo_800A75DC(Fighter* fp0, Fighter* fp1) 0) { f32 x38 = data->x56C + fp1->x1A88.x564; - if (fp0->x1A88.x60 == 0) { - data->x54.x = fp1->cur_pos.x; - data->x54.y = fp1->cur_pos.y; + f32 x = fp1->cur_pos.x; + f32 y = fp1->cur_pos.y; + if (*x60 == 0) { + data->x54.x = x; + data->x54.y = y; data->x38 = x38; ftCo_800A1CC4(fp0, ftCo_803C6594[stage_info.internal_stage_id]); } @@ -3605,24 +3679,60 @@ void ftCo_800A75DC(Fighter* fp0, Fighter* fp1) { cx = fp0->cur_pos.x; if (data->x54.x - cx > 0.0f) { - if (cx < island->x8.x && data->x60 == 0) { - data->x54.x = 5.0 + island->x8.x; - data->x54.y = island->x8.y; - data->x38 = data->x56C + fp1->x1A88.x564; - ftCo_800A1CC4(fp0, - ftCo_803C6594[stage_info.internal_stage_id]); + if (cx < island->x8.x) { + struct Fighter_x1A88_t* data2 = &fp0->x1A88; + f32 x = 5.0 + island->x8.x; + f32 y = island->x8.y; + f32 x38 = data->x56C + fp1->x1A88.x564; + if (*x60 == 0) { + data2->x54.x = x; + data2->x54.y = y; + data2->x38 = x38; + ftCo_800A1CC4( + fp0, + ftCo_803C6594[stage_info.internal_stage_id]); + } } } else { - if (cx > island->x14.x && data->x60 == 0) { - data->x54.x = island->x14.x - 5.0; - data->x54.y = island->x14.y; - data->x38 = data->x56C + fp1->x1A88.x564; - ftCo_800A1CC4(fp0, - ftCo_803C6594[stage_info.internal_stage_id]); + if (cx > island->x14.x) { + struct Fighter_x1A88_t* data2 = &fp0->x1A88; + f32 x = island->x14.x - 5.0; + f32 y = island->x14.y; + f32 x38 = data->x56C + fp1->x1A88.x564; + if (*x60 == 0) { + data2->x54.x = x; + data2->x54.y = y; + data2->x38 = x38; + ftCo_800A1CC4( + fp0, + ftCo_803C6594[stage_info.internal_stage_id]); + } + } + } + } + } +} + +static inline Fighter* ftCo_800A7AAC_inline0(Fighter* fp) +{ + if (fp == NULL) { + return NULL; + } + { + Fighter_GObj* cur; + for (cur = HSD_GObj_Entities->fighters; cur != NULL; cur = cur->next) { + if (fp->gobj != cur) { + Fighter* cur_fp = GET_FIGHTER(cur); + if (fp->player_id == cur_fp->player_id) { + if (cur_fp->x221F_b3) { + return NULL; + } + return cur_fp; } } } } + return NULL; } void ftCo_800A7AAC(Fighter* fp) @@ -3633,108 +3743,112 @@ void ftCo_800A7AAC(Fighter* fp) Vec3 floor_normal; int line_id; u32 flags; - u8 _[0x14]; + u8 _[0x18]; Vec3 partner_pos; - mp_UnkStruct0* island; + s32 blocked; mp_UnkStruct0* fp_island; s32 result; + mp_UnkStruct0* island; s32 same_island; s32 sub; - s32 blocked; f32 d; f32 cx; - PAD_STACK(0x20); + PAD_STACK(0xA); - if (fp == NULL) { - partner = NULL; - } else { - HSD_GObj* cur; - for (cur = HSD_GObj_Entities->fighters; cur != NULL; cur = cur->next) { - if (fp->gobj != cur && - fp->player_id == (partner = GET_FIGHTER(cur))->player_id) - { - if (partner->x221F_b3) { - partner = NULL; - } - break; - } - } - if (cur == NULL) { - partner = NULL; - } - } + partner = ftCo_800A7AAC_inline0(fp); if (partner == NULL) { return; } partner_pos = partner->cur_pos; if (partner->ground_or_air == GA_Air) { - f32 above; - f32 below; + f32 above = 10.0f + partner_pos.y; + f32 below = partner_pos.y - 1000.0f; blocked = 0; line_id = -1; - result = - mpCheckFloor(partner_pos.x, 10.0f + partner_pos.y, partner_pos.x, - partner_pos.y - 1000.0f, 0.0f, &floor_pos, &line_id, - &flags, &floor_normal, -1, -1, -1, NULL, NULL); + result = mpCheckFloor(partner_pos.x, above, partner_pos.x, below, 0.0f, + &floor_pos, &line_id, &flags, &floor_normal, -1, + -1, -1, NULL, NULL); if (result != 0) { - if (ftCo_800A6A98_inline0(line_id)) { + int line = line_id; + if (grBigBlue_801EF844(line) || grInishie1_801FCAAC(line) || + grCorneria_801E2D90(line) || grVenom_80206D10(line)) + { blocked = 1; } if (blocked != 0) { result = 0; } } - if (result != 0 && - ftCo_800A2718(island = mpIsland_8005AB54(line_id)) == 0) - { - if (data->x60 == 0) { - data->x54.x = floor_pos.x; - data->x54.y = floor_pos.y; - data->x38 = data->x56C + partner->x1A88.x564; - ftCo_800A1CC4(fp, ftCo_803C6594[stage_info.internal_stage_id]); - } - if (island != NULL) { - d = island->x14.x - data->x54.x; - if (d < 0.0f) { - d = -d; + if (result != 0) { + island = mpIsland_8005AB54(line_id); + if (ftCo_800A2718(island) == 0) { + int* x60 = &fp->x1A88.x60; + struct Fighter_x1A88_t* data2 = &fp->x1A88; + f32 x38 = data->x56C + partner->x1A88.x564; + f32 x = floor_pos.x; + f32 y = floor_pos.y; + if (*x60 == 0) { + data2->x54.x = x; + data2->x54.y = y; + data2->x38 = x38; + ftCo_800A1CC4(fp, + ftCo_803C6594[stage_info.internal_stage_id]); } - if (d < 5.0f) { - if (data->x60 == 0) { - data->x54.x = island->x14.x - 5.0; - data->x54.y = island->x14.y; - data->x38 = data->x56C + partner->x1A88.x564; - ftCo_800A1CC4( - fp, ftCo_803C6594[stage_info.internal_stage_id]); - } - } else { - d = island->x8.x - data->x54.x; + if (island != NULL) { + d = island->x14.x - data->x54.x; if (d < 0.0f) { d = -d; } - if (d < 5.0 && data->x60 == 0) { - data->x54.x = 5.0 + island->x8.x; - data->x54.y = island->x8.y; - data->x38 = data->x56C + partner->x1A88.x564; - ftCo_800A1CC4( - fp, ftCo_803C6594[stage_info.internal_stage_id]); - } - } - } - } - } else if (ftCo_800A2718( - mpIsland_8005AB54(partner->coll_data.floor.index)) == 0) - { - f32 above; - f32 below; - blocked = 0; + if (d < 5.0) { + f32 x38_edge = data->x56C + partner->x1A88.x564; + f32 x = island->x14.x - 5.0; + f32 y = island->x14.y; + if (*x60 == 0) { + data->x54.x = x; + data->x54.y = y; + data->x38 = x38_edge; + ftCo_800A1CC4( + fp, + ftCo_803C6594[stage_info.internal_stage_id]); + } + } else { + d = island->x8.x - data->x54.x; + if (d < 0.0f) { + d = -d; + } + if (d < 5.0) { + f32 x38_edge = data->x56C + partner->x1A88.x564; + f32 x = 5.0 + island->x8.x; + f32 y = island->x8.y; + if (*x60 == 0) { + data->x54.x = x; + data->x54.y = y; + data->x38 = x38_edge; + ftCo_800A1CC4( + fp, ftCo_803C6594[stage_info + .internal_stage_id]); + } + } + } + } + } + } + } else if (ftCo_800A2718( + mpIsland_8005AB54(partner->coll_data.floor.index)) == 0) + { + f32 above = 2.0 + partner_pos.y; + f32 below = partner_pos.y - 2.0; + blocked = 0; line_id = -1; - result = - mpCheckFloor(partner_pos.x, 2.0 + partner_pos.y, partner_pos.x, - partner_pos.y - 2.0, 0.0f, &floor_pos, &line_id, - &flags, &floor_normal, -1, -1, -1, NULL, NULL); + result = mpCheckFloor(partner_pos.x, above, partner_pos.x, below, 0.0f, + &floor_pos, &line_id, &flags, &floor_normal, -1, + -1, -1, NULL, NULL); if (result != 0) { - if (ftCo_800A6A98_inline0(line_id)) { + int line = line_id; + if (grBigBlue_801EF844(line) || grInishie1_801FCAAC(line) || + grCorneria_801E2D90(line) || grVenom_80206D10(line)) + { blocked = 1; } if (blocked != 0) { @@ -3742,17 +3856,27 @@ void ftCo_800A7AAC(Fighter* fp) } } if (result == 0) { - if (data->x60 == 0) { - data->x54.x = partner->cur_pos.x; - data->x54.y = partner->cur_pos.y; - data->x38 = data->x56C + partner->x1A88.x564; + struct Fighter_x1A88_t* data2 = &fp->x1A88; + f32 x38 = data->x56C + partner->x1A88.x564; + f32 x = partner->cur_pos.x; + f32 y = partner->cur_pos.y; + if (fp->x1A88.x60 == 0) { + data2->x54.x = x; + data2->x54.y = y; + data2->x38 = x38; + ftCo_800A1CC4(fp, ftCo_803C6594[stage_info.internal_stage_id]); + } + } else { + struct Fighter_x1A88_t* data2 = &fp->x1A88; + f32 x38 = data->x56C + partner->x1A88.x564; + f32 x = partner_pos.x; + f32 y = partner_pos.y; + if (fp->x1A88.x60 == 0) { + data2->x54.x = x; + data2->x54.y = y; + data2->x38 = x38; ftCo_800A1CC4(fp, ftCo_803C6594[stage_info.internal_stage_id]); } - } else if (data->x60 == 0) { - data->x54.x = partner_pos.x; - data->x54.y = partner_pos.y; - data->x38 = data->x56C + partner->x1A88.x564; - ftCo_800A1CC4(fp, ftCo_803C6594[stage_info.internal_stage_id]); } if (fp->ground_or_air == GA_Air) { same_island = 0; @@ -3785,20 +3909,34 @@ void ftCo_800A7AAC(Fighter* fp) if (island != NULL && data->x54.y - fp->cur_pos.y > 0.0f) { cx = fp->cur_pos.x; if (data->x54.x - cx > 0.0f) { - if (cx < island->x8.x && data->x60 == 0) { - data->x54.x = 5.0 + island->x8.x; - data->x54.y = island->x8.y; - data->x38 = data->x56C + partner->x1A88.x564; - ftCo_800A1CC4( - fp, ftCo_803C6594[stage_info.internal_stage_id]); + if (cx < island->x8.x) { + struct Fighter_x1A88_t* data2 = &fp->x1A88; + f32 x = 5.0 + island->x8.x; + f32 y = island->x8.y; + f32 x38 = data->x56C + partner->x1A88.x564; + if (fp->x1A88.x60 == 0) { + data2->x54.x = x; + data2->x54.y = y; + data2->x38 = x38; + ftCo_800A1CC4( + fp, + ftCo_803C6594[stage_info.internal_stage_id]); + } } } else { - if (cx > island->x14.x && data->x60 == 0) { - data->x54.x = island->x14.x - 5.0; - data->x54.y = island->x14.y; - data->x38 = data->x56C + partner->x1A88.x564; - ftCo_800A1CC4( - fp, ftCo_803C6594[stage_info.internal_stage_id]); + if (cx > island->x14.x) { + struct Fighter_x1A88_t* data2 = &fp->x1A88; + f32 x = island->x14.x - 5.0; + f32 y = island->x14.y; + f32 x38 = data->x56C + partner->x1A88.x564; + if (fp->x1A88.x60 == 0) { + data2->x54.x = x; + data2->x54.y = y; + data2->x38 = x38; + ftCo_800A1CC4( + fp, + ftCo_803C6594[stage_info.internal_stage_id]); + } } } } @@ -3826,18 +3964,25 @@ static inline void ftCo_800A80E4_dontinline(Fighter* fp) ftCo_800A80E4(fp); } +static inline void ftCo_800A8210_inline0(Fighter* fp, Vec3* out) +{ + struct Fighter_x1A88_t* data = &fp->x1A88; + f32 y = out->y; + f32 x = out->x; + if (data->x60 == 0) { + data->x54.x = x; + data->x54.y = y; + data->x38 = 5.0f; + ftCo_800A1CC4(fp, ftCo_803C6594[stage_info.internal_stage_id]); + } +} + bool ftCo_800A8210(Fighter* fp, Vec3* arg1) { - f32 x; - f32 y; - f32 x2; - f32 y2; - f32 x3; - f32 y3; Vec3 out; Vec3 dir; - struct Fighter_x1A88_t* data; f32 left; + f32 sum_x; f32 cx; f32 bottom; f32 sum_y; @@ -3852,31 +3997,20 @@ bool ftCo_800A8210(Fighter* fp, Vec3* arg1) grLib_801C9E60(&dir); if (dir.y < 0.0) { if (ftCo_800A6A98(fp, &out)) { - if (fp->x1A88.x60 == 0) { - fp->x1A88.x54.x = out.x; - fp->x1A88.x54.y = out.y; - fp->x1A88.x38 = 5.0f; - ftCo_800A1CC4(fp, - ftCo_803C6594[stage_info.internal_stage_id]); - } + ftCo_800A8210_inline0(fp, &out); return true; } } else { if (ftCo_800A6D2C(fp, &out)) { - if (fp->x1A88.x60 == 0) { - fp->x1A88.x54.x = out.x; - fp->x1A88.x54.y = out.y; - fp->x1A88.x38 = 5.0f; - ftCo_800A1CC4(fp, - ftCo_803C6594[stage_info.internal_stage_id]); - } + ftCo_800A8210_inline0(fp, &out); return true; } } return false; } else if (stage_info.internal_stage_id == RCRUISE) { left = Stage_GetBlastZoneLeftOffset(); - cx = 0.5f * (Stage_GetBlastZoneRightOffset() + left); + sum_x = Stage_GetBlastZoneRightOffset(); + cx = 0.5f * (sum_x += left); bottom = Stage_GetBlastZoneBottomOffset(); sum_y = Stage_GetBlastZoneTopOffset(); cy = 0.5f * (sum_y += bottom); @@ -3884,30 +4018,21 @@ bool ftCo_800A8210(Fighter* fp, Vec3* arg1) dir.y = cy - fp->cur_pos.y; dir.z = 0.0f; if (ftCo_800A6FC4(fp, &out, &dir)) { - if (fp->x1A88.x60 == 0) { - fp->x1A88.x54.x = out.x; - fp->x1A88.x54.y = out.y; - fp->x1A88.x38 = 5.0f; - ftCo_800A1CC4(fp, ftCo_803C6594[stage_info.internal_stage_id]); - } + ftCo_800A8210_inline0(fp, &out); return true; } grLib_801C9E60(&dir); dir.x = -dir.x; dir.y = -dir.y; if (ftCo_800A6FC4(fp, &out, &dir)) { - if (fp->x1A88.x60 == 0) { - fp->x1A88.x54.x = out.x; - fp->x1A88.x54.y = out.y; - fp->x1A88.x38 = 5.0f; - ftCo_800A1CC4(fp, ftCo_803C6594[stage_info.internal_stage_id]); - } + ftCo_800A8210_inline0(fp, &out); return true; } return false; } else if (stage_info.internal_stage_id == BIGBLUE) { left = Stage_GetBlastZoneLeftOffset(); - cx = 0.5f * (Stage_GetBlastZoneRightOffset() + left); + sum_x = Stage_GetBlastZoneRightOffset(); + cx = 0.5f * (sum_x += left); bottom = Stage_GetBlastZoneBottomOffset(); sum_y = Stage_GetBlastZoneTopOffset(); cy = 0.5f * (sum_y += bottom); @@ -3915,35 +4040,20 @@ bool ftCo_800A8210(Fighter* fp, Vec3* arg1) dir.y = cy - fp->cur_pos.y; dir.z = 0.0f; if (ftCo_800A6FC4(fp, &out, &dir)) { - if (fp->x1A88.x60 == 0) { - fp->x1A88.x54.x = out.x; - fp->x1A88.x54.y = out.y; - fp->x1A88.x38 = 5.0f; - ftCo_800A1CC4(fp, ftCo_803C6594[stage_info.internal_stage_id]); - } + ftCo_800A8210_inline0(fp, &out); return true; } grLib_801C9E60(&dir); dir.x = -dir.x; dir.y = -dir.y; if (ftCo_800A6FC4(fp, &out, &dir)) { - if (fp->x1A88.x60 == 0) { - fp->x1A88.x54.x = out.x; - fp->x1A88.x54.y = out.y; - fp->x1A88.x38 = 5.0f; - ftCo_800A1CC4(fp, ftCo_803C6594[stage_info.internal_stage_id]); - } + ftCo_800A8210_inline0(fp, &out); return true; } return false; } else { if (ftCo_800A6700(fp, arg1, &out)) { - if (fp->x1A88.x60 == 0) { - fp->x1A88.x54.x = out.x; - fp->x1A88.x54.y = out.y; - fp->x1A88.x38 = 5.0f; - ftCo_800A1CC4(fp, ftCo_803C6594[stage_info.internal_stage_id]); - } + ftCo_800A8210_inline0(fp, &out); return true; } return false; @@ -3961,11 +4071,10 @@ void ftCo_800A866C(Fighter* fp) int line_id; u32 flags; s32 found; - bool blocked; + s32 blocked; s32 same_island; f32 ix; f32 iy; - f32 cx; if (item != NULL && fp->ground_or_air != GA_Air && item->ground_or_air != GA_Air) @@ -3974,31 +4083,39 @@ void ftCo_800A866C(Fighter* fp) if (!ftCo_800A2718_dontinline(island)) { ix = item->pos.x; iy = item->pos.y; + blocked = 0; line_id = -1; - blocked = false; { + f32 bottom = iy - 50.0f; f32 top = 1.0f + iy; - f32 bottom = iy - 50.0; - found = mpCheckFloor(ix, top, ix, bottom, 0.0f, &floor_pos, + f32 ix2 = ix; + found = mpCheckFloor(ix2, top, ix, bottom, 0.0f, &floor_pos, &line_id, &flags, &floor_normal, -1, -1, - -1, NULL, NULL); + -1, NULL, (Fighter_GObj*) blocked); } if (found != 0) { int line = line_id; if (grBigBlue_801EF844(line) || grInishie1_801FCAAC(line) || grCorneria_801E2D90(line) || grVenom_80206D10(line)) { - blocked = true; + blocked = 1; } if (blocked != 0) { found = 0; } } - if (found != 0 && data->x60 == 0) { - data->x54.x = floor_pos.x; - data->x54.y = floor_pos.y; - data->x38 = 1.0f; - ftCo_800A1CC4(fp, ftCo_803C6594[stage_info.internal_stage_id]); + if (found != 0) { + struct Fighter_x1A88_t* data2 = &fp->x1A88; + f32 x; + f32 y = floor_pos.y; + x = floor_pos.x; + if (fp->x1A88.x60 == 0) { + data2->x54.x = x; + data2->x54.y = y; + data2->x38 = 1.0f; + ftCo_800A1CC4(fp, + ftCo_803C6594[stage_info.internal_stage_id]); + } } if (fp->ground_or_air == GA_Air) { same_island = 0; @@ -4017,12 +4134,11 @@ void ftCo_800A866C(Fighter* fp) } } if (same_island == 0 && island != NULL && - data->x54.y - fp->cur_pos.y > 0.0f) + data->x54.y - fp->cur_pos.y > 0.0) { - cx = fp->cur_pos.x; - if (data->x54.x - cx > 0.0f) { + if (data->x54.x - fp->cur_pos.x > 0.0) { f32 x = island->x8.x; - if (cx < x) { + if (fp->cur_pos.x < x) { struct Fighter_x1A88_t* data2 = &fp->x1A88; f32 y = island->x8.y; x = 5.0 + x; @@ -4037,7 +4153,7 @@ void ftCo_800A866C(Fighter* fp) } } else { f32 x = island->x14.x; - if (cx > x) { + if (fp->cur_pos.x > x) { struct Fighter_x1A88_t* data2 = &fp->x1A88; f32 y = island->x14.y; x = x - 5.0; @@ -4071,7 +4187,6 @@ void ftCo_800A8940(Fighter* fp) u8 _2[0xC]; int line_id; u32 flags; - int line; f32 px; f32 py; f32 width; @@ -4125,27 +4240,31 @@ void ftCo_800A8940(Fighter* fp) } else { px = width * rnd2 + chosen->x8.x; } - py = island->x14.y - island->x8.y; - py = rnd2 * py + chosen->x8.y; blocked = 0; - line_id = -1; py = rnd2 * (island->x14.y - island->x8.y) + chosen->x8.y; - result = - mpCheckFloor(px, py + 5.0f, px, py - 100.0, 0.0f, &floor_pos, &line_id, - &flags, &floor_normal, -1, -1, -1, NULL, NULL); + line_id = -1; + { + f32 bottom = py - 100.0f; + f32 top = 5.0f + py; + result = mpCheckFloor(px, top, px, bottom, 0.0f, &floor_pos, &line_id, + &flags, &floor_normal, -1, -1, -1, NULL, NULL); + } if (result != 0) { - line = line_id; - blocked = ftCo_800A6A98_inline0(line); + blocked = ftCo_800A6A98_inline0(line_id); if (blocked != 0) { result = 0; } } if (result != 0) { if (!ftCo_800A6700_inline0(fp, floor_pos.x, floor_pos.y)) { - if (fp->x1A88.x60 == 0) { - fp->x1A88.x54.x = floor_pos.x; - fp->x1A88.x54.y = floor_pos.y; - fp->x1A88.x38 = 5.0f; + struct Fighter_x1A88_t* data = &fp->x1A88; + f32 x; + f32 y = floor_pos.y; + x = floor_pos.x; + if (data->x60 == 0) { + data->x54.x = x; + data->x54.y = y; + data->x38 = 5.0f; ftCo_800A1CC4(fp, ftCo_803C6594[stage_info.internal_stage_id]); } } @@ -4447,21 +4566,41 @@ static inline float ftCo_800A9904_inline0(Fighter* fp) return fp->co_attrs.terminal_vel; } +#define ftCo_800A9904_sqrtf_store(dst, x, store) \ + do { \ + if (x > 0.0f) { \ + double guess = __frsqrte((double) x); \ + guess = 0.5 * guess * (3.0 - guess * guess * x); \ + guess = 0.5 * guess * (3.0 - guess * guess * x); \ + guess = 0.5 * guess * (3.0 - guess * guess * x); \ + store = (float) (x * guess); \ + dst = *(f32*) &store; \ + } else { \ + dst = x; \ + } \ + } while (0) + void ftCo_800A9904(Fighter* fp) { - u32 ceiling_flags; + UNUSED u8 _top[8]; + struct { + u32 pad; + u32 flags; + int line_id; + Vec3 normal; + Vec3 pos; + } ceiling; + f32 sqrt_time_store; + f32 sqrt_terminal_store; + UNUSED u8 _[0x1C]; f32 x_time; - f32 temp_f3; + f32 gravity; f32 predicted_y; f32 terminal_time; - - Vec3 ceiling_pos; - Vec3 ceiling_normal; + f32 sqrt_time; + f32 sqrt_terminal; struct Fighter_x1A88_t* data = &fp->x1A88; - int ceiling_line_id; - - PAD_STACK(0x24); if (ftCo_800A3498(fp) != 0) { if (fp->co_attrs.max_jumps > fp->x1968_jumpsUsed) { @@ -4474,29 +4613,33 @@ void ftCo_800A9904(Fighter* fp) ftCo_800A96B8(fp); } } else if (data->xFA_b5) { + f32* grav_p; f32 dx = data->x54.x - fp->cur_pos.x; if (is_small(fp->pos_delta.x)) { x_time = 1000.0F; } else { x_time = dx / fp->pos_delta.x; } - if (is_small(fp->co_attrs.grav)) { + gravity = *(grav_p = &fp->co_attrs.grav); + if (is_small(gravity)) { terminal_time = 1000.0F; } else { - terminal_time = -(-fp->co_attrs.terminal_vel - fp->pos_delta.y) / - fp->co_attrs.grav; + terminal_time = + -(-fp->co_attrs.terminal_vel - fp->pos_delta.y) / gravity; } if (terminal_time <= 0.0F) { predicted_y = (fp->pos_delta.y * x_time) + fp->cur_pos.y; } else if (x_time < terminal_time) { - predicted_y = - fp->cur_pos.y + (fp->pos_delta.y * x_time - - 0.5 * (fp->co_attrs.grav * sqrtf(x_time))); + ftCo_800A9904_sqrtf_store(sqrt_time, x_time, sqrt_time_store); + predicted_y = fp->cur_pos.y + (fp->pos_delta.y * x_time - + 0.5 * (*grav_p * sqrt_time)); } else { + ftCo_800A9904_sqrtf_store(sqrt_terminal, terminal_time, + sqrt_terminal_store); predicted_y = fp->cur_pos.y + (fp->pos_delta.y * terminal_time - - 0.5 * (fp->co_attrs.grav * sqrtf(terminal_time)) - + 0.5 * (*grav_p * sqrt_terminal) - ((x_time - terminal_time) * ftCo_800A9904_inline0(fp))); } { @@ -4510,8 +4653,8 @@ void ftCo_800A9904(Fighter* fp) ftCo_800B46B8(fp, CpuCmd_SetLstickY, 0); ftCo_800B463C(fp, CpuCmd_Done); } else if (mpCheckCeiling(fp->cur_pos.x, fp->cur_pos.y, data->x54.x, - data->x54.y, &ceiling_pos, &ceiling_line_id, - &ceiling_flags, &ceiling_normal, -1, -1)) + data->x54.y, &ceiling.pos, &ceiling.line_id, + &ceiling.flags, &ceiling.normal, -1, -1)) { ftCo_800B46B8(fp, CpuCmd_LstickXTowardDestination, 0x81); ftCo_800B46B8(fp, CpuCmd_SetLstickY, 0); @@ -4523,6 +4666,8 @@ void ftCo_800A9904(Fighter* fp) } } +#undef ftCo_800A9904_sqrtf_store + static inline bool ftCo_800A9CB4_is_small(f32 x) { if (x < 1.0e-5f && x > -1.0e-5f) { @@ -5326,6 +5471,14 @@ void ftCo_800ABA34(Fighter* fp) } } +static inline void ftCo_800ABBA8_blk155144r(Fighter* fp, Fighter** target) +{ + struct Fighter_x1A88_t* data = &fp->x1A88; + PAD_STACK(0x28); + + *target = data->x44; +} + void ftCo_800ABBA8(Fighter* fp) { struct Fighter_x1A88_t* data = &fp->x1A88; @@ -5336,8 +5489,10 @@ void ftCo_800ABBA8(Fighter* fp) Vec3 sp68; int line_id; u32 flags; - u8 _[4]; - Vec3 sp50; + struct { + Vec3 v; + u8 _[4]; + } sp50; s32 result; s32 blocked; s32 ok; @@ -5355,9 +5510,10 @@ void ftCo_800ABBA8(Fighter* fp) f32 dyy; f32 dxx; - PAD_STACK(0x28); + ftCo_800ABBA8_blk155144r(fp, &target); + + PAD_STACK(0x24); - target = data->x44; if (data->level < 5) { ok = 0; } else if (fp->motion_id == 0x26) { @@ -5372,13 +5528,11 @@ void ftCo_800ABBA8(Fighter* fp) ftCo_800B463C(fp, CpuCmd_Done); return; } - if (target != NULL && ftCo_800A6700(fp, &target->cur_pos, &sp50) != 0 && - data->x60 == 0) - { + if (target != NULL && ftCo_800A6700(fp, &target->cur_pos, &sp50.v) != 0) { struct Fighter_x1A88_t* data2 = &fp->x1A88; - f32 x = sp50.x; - f32 y = sp50.y; - if (data->x60 == 0) { + f32 x = sp50.v.x; + f32 y = sp50.v.y; + if (fp->x1A88.x60 == 0) { data2->x54.x = x; data2->x54.y = y; data2->x38 = 5.0f; @@ -5388,9 +5542,9 @@ void ftCo_800ABBA8(Fighter* fp) if (data->level > 7) { cx = fp->cur_pos.x; cy = fp->cur_pos.y; - blocked = 0; line_id = -1; - result = mpCheckFloor(cx, cy, cx, cy - 1000.0f, 0.0f, &sp74, &line_id, + blocked = 0; + result = mpCheckFloor(cx, cy, cx, cy - 1000.0, 0.0f, &sp74, &line_id, &flags, &sp68, -1, -1, -1, NULL, NULL); if (result != 0) { int line = line_id; @@ -5408,19 +5562,24 @@ void ftCo_800ABBA8(Fighter* fp) v = fp->pos_delta.y; h = sp74.y - (fp->coll_data.cur_pos.y + fp->coll_data.ecb.bottom.y); - ok = 0; if (g < 0.00001f && g > -0.00001f) { ok = 1; + } else { + ok = 0; } if (ok == 0) { disc = 2.0f * g * h + v * v; disc = sqrtf(ABS(disc)); t = (-disc - v) / g; } else { + ok = 0; if (v < 0.00001f && v > -0.00001f) { - t = 0x64; - } else { + ok = 1; + } + if (ok == 0) { t = h / v; + } else { + t = 0x64; } } if (t < 0xA) { @@ -5443,7 +5602,9 @@ void ftCo_800ABBA8(Fighter* fp) if (dyy < below->x1A88.x568 + data->x568) { dxx = ABS(below->cur_pos.x - fp->cur_pos.x); if (dxx < 5.0 + (below->x1A88.x564 + data->x564)) { - if (below->motion_id == 0x38 || below->motion_id == 0x3F) { + if ((below->motion_id == 0x38 || below->motion_id == 0x3F) != + 0) + { ftCo_800B463C(fp, CpuCmd_ReleaseR); ftCo_800B46B8(fp, CpuCmd_WaitFor, 1); ftCo_800B463C(fp, CpuCmd_PressR); @@ -5464,14 +5625,23 @@ void ftCo_800ABBA8(Fighter* fp) v = fp->pos_delta.x; dxx = data->x54.x - fp->cur_pos.x; if (v < 0.00001f && v > -0.00001f) { + ok = 1; + } else { + ok = 0; + } + if (ok != 0) { vf0 = 1000.0f; } else { vf0 = dxx / v; } grav_ptr = &fp->co_attrs.grav; - (void) grav_ptr; g = *grav_ptr; if (g < 0.00001f && g > -0.00001f) { + ok = 1; + } else { + ok = 0; + } + if (ok != 0) { vf5 = 1000.0f; } else { vf5 = -(-fp->co_attrs.terminal_vel - fp->pos_delta.y) / g; @@ -6116,64 +6286,71 @@ void ftCo_800ADC28(Fighter* fp) } } +static inline bool ftCo_ItemCheck(Item* ip) +{ + return ftCo_800A5980((Fighter*) ip); +} + void ftCo_800ADE48(Fighter* fp) { - struct Fighter_x1A88_t* data = &fp->x1A88; - Vec3 floor_pos; - Vec3 floor_normal; - int line_id; + s32 switch_cmd; + struct Fighter_x1A88_t* data; u32 flags; + int line_id; + Vec3 floor_normal; + Vec3 floor_pos; Item_GObj* item_gobj; Item* ip; ItemKind kind; + s32 found; s32 result; s32 in_bounds; - s32 switch_cmd; - s32 found; f32 px; f32 py; - f32 dx; f32 dy; - f32 dist; - PAD_STACK(0x20); + f64 five; + PAD_STACK(0x14); + line_id = -1; + data = &fp->x1A88; found = 0; px = data->x54.x; py = data->x54.y; - line_id = -1; + five = 5.0; result = - mpCheckFloor(px, 5.0 + py, px, py - 5.0, 0.0f, &floor_pos, &line_id, + mpCheckFloor(px, py + five, px, py - five, 0.0f, &floor_pos, &line_id, &flags, &floor_normal, -1, -1, -1, NULL, NULL); if (result != 0 && ftCo_800A1B38_noinline(line_id) != 0) { } else { found = result; } - if (found != 0) { - px = data->x54.x; - py = data->x54.y; - if (px < data->half_width + Stage_GetBlastZoneLeftOffset() || - px > Stage_GetBlastZoneRightOffset() - data->half_width || - py < data->half_height + Stage_GetBlastZoneBottomOffset() || - py > Stage_GetBlastZoneTopOffset() - data->half_height) - { - in_bounds = 0; - } else { - in_bounds = 1; - } - if (in_bounds != 0) { - goto block_12; + do { + if (found != 0) { + struct Fighter_x1A88_t* data2 = &fp->x1A88; + py = data->x54.y; + px = data->x54.x; + if (px < fp->x1A88.half_width + Stage_GetBlastZoneLeftOffset() || + px > Stage_GetBlastZoneRightOffset() - data2->half_width || + py < data2->half_height + Stage_GetBlastZoneBottomOffset() || + py > Stage_GetBlastZoneTopOffset() - data2->half_height) + { + in_bounds = 1; + } else { + in_bounds = 0; + } + if (in_bounds == 0) { + break; + } } - } else { - block_12: data->xFA_b2 = false; if (fp->ground_or_air == GA_Air) { px = fp->cur_pos.x; py = fp->cur_pos.y; line_id = -1; + found = 0; result = mpCheckFloor(px, py, px, py - 1000.0f, 0.0f, &floor_pos, &line_id, &flags, &floor_normal, -1, -1, -1, NULL, NULL); - found = 0; if (result != 0 && ftCo_800A1B38_noinline(line_id) != 0) { } else { found = result; @@ -6189,11 +6366,17 @@ void ftCo_800ADE48(Fighter* fp) data->x54.x = fp->cur_pos.x; data->x54.y = fp->cur_pos.y; } + } while (0); + dy = fp->cur_pos.y - fp->x1A88.x54.y; + { + struct Fighter_x1A88_t* data = &fp->x1A88; + f32 dx; + f32 dist; + + dx = fp->cur_pos.x - data->x54.x; + dist = sqrtf(dx * dx + dy * dy); + data->x5C = dist; } - dy = fp->cur_pos.y - data->x54.y; - dx = fp->cur_pos.x - data->x54.x; - dist = sqrtf(dx * dx + dy * dy); - data->x5C = dist; if (data->x88 > 0) { data->x88 = data->x88 - 1; } @@ -6235,7 +6418,6 @@ void ftCo_800ADE48(Fighter* fp) } else { data->xFA_b1 = false; } - switch_cmd = 1; } if (switch_cmd != 0) { ftCo_800B4A78(fp); @@ -6316,6 +6498,8 @@ void ftCo_800ADE48(Fighter* fp) data->x18 = 4; return; } + } else { + return; } if (data->x18 != 0xF) { if (data->level < 5) { @@ -6401,20 +6585,7 @@ void ftCo_800ADE48(Fighter* fp) if (kind < 7) { - if (kind < - 0) - { - found = - ftCo_800A5980_dontinline( - (Fighter*) - ip) != - 0 - ? 1 - : 0; - } else { - found = - 1; - } + found = 1; } else { found = ftCo_800A5980_dontinline( @@ -6428,13 +6599,7 @@ void ftCo_800ADE48(Fighter* fp) kind != It_Kind_EvYoshiEgg) { - found = - ftCo_800A5980( - (Fighter*) - ip) != - 0 - ? 1 - : 0; + found = ftCo_ItemCheck(ip); } else { found = 1; } @@ -6480,38 +6645,42 @@ void ftCo_800ADE48(Fighter* fp) } void ftCo_800AE7AC(Fighter* fp, Vec3* arg1, int arg2) { - struct Fighter_x1A88_t* data = &fp->x1A88; + struct Fighter_x1A88_t* data0 = &fp->x1A88; + struct Fighter_x1A88_t* data; + struct Fighter_x1A88_t* data2; + struct Fighter_x1A88_t* data3; Item_GObj* item_gobj; ItemKind kind; s32 is_food; s32 do_act; - u8 operand_pad[4]; u8 _[8]; Vec3 dir; Vec3 out; f32 left; + f32 sum_x; f32 cx; f32 bottom; f32 sum_y; f32 cy; f32 dy; - PAD_STACK(4); + PAD_STACK(8); - data->xF8_b0 = true; - data->xF9_b3 = false; - data->xF9_b5 = false; - data->xF9_b7 = false; - data->xF9_b1 = false; + data0->xF8_b0 = true; + data0->xF9_b3 = false; + data0->xF9_b5 = false; + data0->xF9_b7 = false; + data0->xF9_b1 = false; if (arg2 > 1) { - data->xF9_b2 = false; - data->xF9_b4 = false; - data->xF9_b6 = false; + data0->xF9_b2 = false; + data0->xF9_b4 = false; + data0->xF9_b6 = false; } else { - data->xF9_b2 = true; - data->xF9_b4 = true; - data->xF9_b6 = true; + data0->xF9_b2 = true; + data0->xF9_b4 = true; + data0->xF9_b6 = true; } - data->x44 = ftCo_800A4BEC(fp); + fp->x1A88.x44 = ftCo_800A4BEC(fp); + data = &fp->x1A88; item_gobj = fp->item_gobj; if (item_gobj != NULL) { kind = GET_ITEM(item_gobj)->kind; @@ -6537,41 +6706,47 @@ void ftCo_800AE7AC(Fighter* fp, Vec3* arg1, int arg2) data->x4C = ftCo_800A5F4C(fp, It_Kind_L_Gun_Ray); } } - data->x50 = ftCo_800A648C(fp); - if (data->x18 != data->x20 && data->x18 != data->x1C) { - data->x60 = 0; + fp->x1A88.x50 = ftCo_800A648C(fp); + data2 = &fp->x1A88; + if (data2->x18 != data2->x20 && data2->x18 != data2->x1C) { + data2->x60 = 0; } - if (data->x18 == 4) { + if (data2->x18 == 4) { do_act = 0; } else { - data->xFA_b2 = false; + data2->xFA_b2 = false; do_act = 1; } if (do_act != 0) { if (arg2 >= 0) { ftCo_800A8210(fp, arg1); - } else if (fp->ground_or_air != GA_Air) { - left = Stage_GetBlastZoneLeftOffset(); - cx = 0.5f * (Stage_GetBlastZoneRightOffset() + left); - bottom = Stage_GetBlastZoneBottomOffset(); - sum_y = Stage_GetBlastZoneTopOffset(); - sum_y += bottom; - cy = 0.5f * sum_y; - (void) cy; - dir.x = cx - fp->cur_pos.x; - dy = cy - fp->cur_pos.y; - dir.y = dy; - dir.z = 0.0f; - if (ftCo_800A6FC4(fp, &out, &dir) != 0) { - if (data->x60 == 0) { - data->x54.x = out.x; - data->x54.y = out.y; - data->x38 = 5.0f; - ftCo_800A1CC4(fp, - ftCo_803C6594[stage_info.internal_stage_id]); + } else { + data3 = &fp->x1A88; + if (fp->ground_or_air != GA_Air) { + left = Stage_GetBlastZoneLeftOffset(); + sum_x = Stage_GetBlastZoneRightOffset(); + cx = 0.5f * (sum_x += left); + bottom = Stage_GetBlastZoneBottomOffset(); + sum_y = Stage_GetBlastZoneTopOffset(); + cy = 0.5f * (sum_y += bottom); + dir.x = cx - fp->cur_pos.x; + dir.y = cy - fp->cur_pos.y; + dir.z = 0.0f; + if (ftCo_800A6FC4(fp, &out, &dir) != 0) { + f32 x; + f32 y; + y = out.y; + x = out.x; + if (fp->x1A88.x60 == 0) { + data3->x54.x = x; + data3->x54.y = y; + data3->x38 = 5.0f; + ftCo_800A1CC4( + fp, ftCo_803C6594[stage_info.internal_stage_id]); + } + } else { + ftCo_800A75DC(fp, data3->x44); } - } else { - ftCo_800A75DC(fp, data->x44); } } } @@ -6592,7 +6767,8 @@ void ftCo_800AEA8C(Fighter* fp) s32 do_floor; s32 found; - PAD_STACK(0x20); + PAD_STACK(0xC); + PAD_STACK(0x10); data->xF8_b0 = false; data->xF9_b2 = (is_food = 1); @@ -6651,11 +6827,12 @@ void ftCo_800AEA8C(Fighter* fp) above = 10.0f + y; result = mpCheckFloor(x, above, x, below, 0.0f, &floor_pos, &line_id, &flags, &floor_normal, -1, -1, -1, NULL, NULL); - { - if (result != 0 && ftCo_800A1B38(line_id) != 0) { - } else { + if (result != 0) { + if (ftCo_800A1B38_noinline(line_id) == 0) { found = result; } + } else { + found = result; } if (found != 0) { struct Fighter_x1A88_t* data3 = &fp->x1A88; @@ -6877,27 +7054,93 @@ void ftCo_800AEFB8(Fighter* fp) ftCo_800ADE48(fp); } +static inline void ftCo_800AF290_update_target(Fighter* fp) +{ + struct Fighter_x1A88_t* data; + + data = &fp->x1A88; + if (ftCo_800A1C44_dontinline(fp)) { + data->xF8_b6 = false; + } else { + if ((data->x44 != NULL) && (fp->ground_or_air == GA_Ground)) { + if (ftCo_800A1AB4(fp, data->x44) < Fighter_804D64FC->x20[fp->kind]) + { + data->xF8_b6 = true; + } else { + data->xF8_b6 = false; + } + } else { + data->xF8_b6 = false; + } + } +} + +static inline bool ftCo_800AF290_should_act(Fighter* fp) +{ + struct Fighter_x1A88_t* data; + + data = &fp->x1A88; + if (data->x18 != data->x20 && data->x18 != data->x1C) { + data->x60 = 0; + } + if (data->x18 == 4) { + return false; + } else { + data->xFA_b2 = false; + return true; + } +} + +static inline void ftCo_800AF290_inline0(Fighter* fp, bool is_food) +{ + Item_GObj* item_gobj; + ItemKind kind; + struct Fighter_x1A88_t* data; + + data = &fp->x1A88; + item_gobj = fp->item_gobj; + if (item_gobj != NULL) { + kind = GET_ITEM(item_gobj)->kind; + if (kind == It_Kind_Heart) { + is_food = true; + } else if (kind == It_Kind_Tomato) { + is_food = true; + } else if (kind == It_Kind_Foods) { + is_food = true; + } else { + is_food = false; + } + if (is_food == false) { + data->x4C = NULL; + return; + } + } + if (fp->x2168 != 0) { + data->x4C = NULL; + } else { + data->x4C = ftCo_800A5F4C(fp, It_Kind_L_Gun_Ray); + } +} + void ftCo_800AF290(Fighter* fp) { - struct Fighter_x1A88_t* data2; - struct Fighter_x1A88_t* temp_r27; Vec3 sp54; u8 _[0x18]; Vec3 sp30; - s32 cmd; + Fighter* target; - int tmp; - s32 do_act; - s32 is_food; - s32 redirect; - Item_GObj* item_gobj; - ItemKind kind; + Fighter* nearby_fp; f32 dx; f32 dy; f32 dist; - struct Fighter_x1A88_t* data = &fp->x1A88; - PAD_STACK(0x14); + s32 cmd; + s32 redirect; + bool is_food; + Fighter** target_slot; + struct Fighter_x1A88_t* data; + PAD_STACK(8); + data = &fp->x1A88; cmd = ftCo_800A229C(fp, &sp54); if (cmd != 0) { ftCo_800AE7AC(fp, &sp54, cmd); @@ -6915,16 +7158,7 @@ void ftCo_800AF290(Fighter* fp) data->xF9_b7 = false; data->xF9_b1 = true; ftCo_800A20A0_dontinline(fp); - if (data->x18 != data->x20 && data->x18 != data->x1C) { - data->x60 = 0; - } - if (data->x18 == 4) { - do_act = 0; - } else { - data->xFA_b2 = false; - do_act = 1; - } - if (do_act != 0) { + if (ftCo_800AF290_should_act(fp)) { ftCo_800A80E4_dontinline(fp); } ftCo_800ADE48(fp); @@ -6942,7 +7176,7 @@ void ftCo_800AF290(Fighter* fp) return; } - data->xF8_b0 = (is_food = 1); + data->xF8_b0 = (is_food = true); data->xF9_b2 = true; data->xF9_b4 = true; data->xF9_b3 = false; @@ -6950,50 +7184,12 @@ void ftCo_800AF290(Fighter* fp) data->xF9_b6 = true; data->xF9_b7 = true; data->xF9_b1 = false; - fp->x1A88.x44 = ftCo_800A4BEC(fp); - temp_r27 = &fp->x1A88; - item_gobj = fp->item_gobj; - if (item_gobj != NULL) { - kind = GET_ITEM(item_gobj)->kind; - if (kind == It_Kind_Heart) { - is_food = 1; - } else if (kind == It_Kind_Tomato) { - is_food = 1; - } else if (kind == It_Kind_Foods) { - is_food = 1; - } else { - is_food = 0; - } - if (is_food == 0) { - temp_r27->x4C = NULL; - } else { - goto block_30; - } - } else { - tmp = fp->x2168; - block_30: - if (tmp != 0) { - temp_r27->x4C = NULL; - } else { - temp_r27->x4C = ftCo_800A5F4C(fp, It_Kind_L_Gun_Ray); - } - } + + target = ftCo_800A4BEC(fp); + *(target_slot = &fp->x1A88.x44) = target; + ftCo_800AF290_inline0(fp, is_food); fp->x1A88.x50 = ftCo_800A648C(fp); - data2 = &fp->x1A88; - if (ftCo_800A1C44_dontinline(fp)) { - data2->xF8_b6 = false; - } else { - target = data2->x44; - if (target != NULL && fp->ground_or_air == GA_Ground) { - if (ftCo_800A1AB4(fp, target) < Fighter_804D64FC->x20[fp->kind]) { - data2->xF8_b6 = true; - } else { - data2->xF8_b6 = false; - } - } else { - data2->xF8_b6 = false; - } - } + ftCo_800AF290_update_target(fp); target = data->x44; if (target != NULL) { dy = fp->cur_pos.y - target->cur_pos.y; @@ -7003,34 +7199,19 @@ void ftCo_800AF290(Fighter* fp) return; } } - data2 = &fp->x1A88; - if (data2->x18 != data2->x20 && data2->x18 != data2->x1C) { - data2->x60 = 0; - } - if (data2->x18 == 4) { - do_act = 0; - } else { - data2->xFA_b2 = false; - do_act = 1; - } - if (do_act != 0) { + if (ftCo_800AF290_should_act(fp)) { if (data->x4C != NULL) { ftCo_800A866C(fp); } else { - target = data->x44; - if (target != NULL && fp->ground_or_air != GA_Air) { - dy = fp->cur_pos.y - target->cur_pos.y; - dx = fp->cur_pos.x - target->cur_pos.x; + nearby_fp = *target_slot; + if (nearby_fp != NULL && fp->ground_or_air != GA_Air) { + dy = fp->cur_pos.y - nearby_fp->cur_pos.y; + dx = fp->cur_pos.x - nearby_fp->cur_pos.x; dist = sqrtf(dx * dx + dy * dy); if (!(dist > 50.0) && - ftCo_800A6700(fp, &target->cur_pos, &sp30) != 0 && - data->x60 == 0) + ftCo_800A6700(fp, &nearby_fp->cur_pos, &sp30) != 0) { - data->x54.x = sp30.x; - data->x54.y = sp30.y; - data->x38 = 5.0f; - ftCo_800A1CC4(fp, - ftCo_803C6594[stage_info.internal_stage_id]); + ftCo_800A1F3C(fp, sp30.x, sp30.y, 5.0F); } } } @@ -7084,6 +7265,37 @@ static inline void ftCo_800AF78C_inline0(Fighter* fp) } } +static inline void ftCo_800AF78C_inline1(Fighter* fp, bool is_food) +{ + Item_GObj* item_gobj; + ItemKind kind; + struct Fighter_x1A88_t* data; + + data = &fp->x1A88; + item_gobj = fp->item_gobj; + if (item_gobj != NULL) { + kind = GET_ITEM(item_gobj)->kind; + if (kind == It_Kind_Heart) { + is_food = true; + } else if (kind == It_Kind_Tomato) { + is_food = true; + } else if (kind == It_Kind_Foods) { + is_food = true; + } else { + is_food = false; + } + if (is_food == false) { + data->x4C = NULL; + return; + } + } + if (fp->x2168 != 0) { + data->x4C = NULL; + } else { + data->x4C = ftCo_800A5F4C(fp, It_Kind_L_Gun_Ray); + } +} + void ftCo_800AF78C(Fighter* fp) { Vec3 sp4C; @@ -7092,20 +7304,17 @@ void ftCo_800AF78C(Fighter* fp) Fighter* target; Fighter* nearby_fp; - Item_GObj* item_gobj; - ItemKind kind; f32 dx; f32 dy; f32 dist; s32 cmd; s32 do_act; s32 should_escape; - bool is_food; Fighter** target_slot; struct Fighter_x1A88_t* data; - struct Fighter_x1A88_t* item_data; + bool is_food; - PAD_STACK(12); + PAD_STACK(4); data = &fp->x1A88; cmd = ftCo_800A229C(fp, &sp4C); @@ -7151,8 +7360,8 @@ void ftCo_800AF78C(Fighter* fp) ftCo_800AECF0(fp); return; } - data->xF8_b0 = true; - data->xF9_b2 = (is_food = true); + data->xF8_b0 = (is_food = true); + data->xF9_b2 = true; data->xF9_b4 = true; data->xF9_b3 = false; data->xF9_b5 = true; @@ -7160,35 +7369,9 @@ void ftCo_800AF78C(Fighter* fp) data->xF9_b7 = true; data->xF9_b1 = false; - target = ftCo_800A4BEC(fp); - *(target_slot = &fp->x1A88.x44) = target; - item_data = &fp->x1A88; + *(target_slot = &fp->x1A88.x44) = ftCo_800A4BEC(fp); - item_gobj = fp->item_gobj; - if (item_gobj != NULL) { - kind = GET_ITEM(item_gobj)->kind; - if (kind == It_Kind_Heart) { - is_food = true; - } else if (kind == It_Kind_Tomato) { - is_food = true; - } else if (kind == It_Kind_Foods) { - is_food = true; - } else { - is_food = false; - } - if (is_food == false) { - item_data->x4C = NULL; - } else { - goto maybe_find_item; - } - } else { - maybe_find_item: - if (fp->x2168 != 0) { - item_data->x4C = NULL; - } else { - item_data->x4C = ftCo_800A5F4C(fp, It_Kind_L_Gun_Ray); - } - } + ftCo_800AF78C_inline1(fp, is_food); fp->x1A88.x50 = ftCo_800A648C(fp); ftCo_800AF78C_inline0(fp); @@ -7470,26 +7653,6 @@ void ftCo_800B00F8(Fighter* fp) ftCo_800ADE48(fp); } -static inline void ftCo_800B04DC_inline0(Fighter* fp, - struct Fighter_x1A88_t** data, - bool* is_food) -{ - *data = &fp->x1A88; - (*data)->xF8_b0 = (*is_food = true); - (*data)->xF9_b2 = false; -} - -static inline void ftCo_800B04DC_inline1(struct Fighter_x1A88_t* data, - Fighter* fp, Fighter** target, - Fighter*** target_slot, - Item_GObj** item_gobj) -{ - data->xF9_b7 = false; - data->xF9_b1 = true; - *target = ftCo_800A4BEC(fp); - *(*target_slot = &fp->x1A88.x44) = *target; -} - void ftCo_800B04DC(Fighter* fp) { Fighter** target_slot; @@ -7497,19 +7660,26 @@ void ftCo_800B04DC(Fighter* fp) Item_GObj* item_gobj; ItemKind kind; Fighter* target; - f32 dist; + f32 dist[1]; bool is_food; - u8 _pad[8]; + u8 _[8]; Vec3 approach_pos; - PAD_STACK(4); + volatile f32 unused; - ftCo_800B04DC_inline0(fp, &data, &is_food); + PAD_STACK(0x8); + data = &fp->x1A88; + data->xF8_b0 = (is_food = true); + data->xF9_b2 = false; data->xF9_b4 = false; data->xF9_b3 = false; data->xF9_b5 = false; data->xF9_b6 = false; - ftCo_800B04DC_inline1(data, fp, &target, &target_slot, &item_gobj); + data->xF9_b7 = false; + data->xF9_b1 = true; + + target = ftCo_800A4BEC(fp); + *(target_slot = &fp->x1A88.x44) = target; item_gobj = fp->item_gobj; if (item_gobj != NULL) { @@ -7543,8 +7713,8 @@ void ftCo_800B04DC(Fighter* fp) if (target != NULL && fp->ground_or_air != GA_Air) { f32 dy = fp->cur_pos.y - target->cur_pos.y; f32 dx = fp->cur_pos.x - target->cur_pos.x; - dist = sqrtf(dx * dx + dy * dy); - if (!(dist > 50.0) && + dist[0] = sqrtf(dx * dx + dy * dy); + if (!(dist[0] > 50.0) && ftCo_800A6700(fp, &target->cur_pos, &approach_pos)) { ftCo_800A1F3C(fp, approach_pos.x, approach_pos.y, 5.0F); @@ -8600,9 +8770,12 @@ void ftCo_800B2790(Fighter* fp) PAD_STACK(0x18); if (data->csP == NULL && data->command_duration == 0) { - data->x80 += 1; - data->xF8_b7 = 0; - ftCo_800B462C(fp); + { + Fighter* fp2 = fp; + data->x80 += 1; + data->xF8_b7 = (special_floor = 0) & 1; + ftCo_800B462C(fp2); + } ftCo_800ADC28(fp); cmd = data->x18; { @@ -8751,18 +8924,20 @@ void ftCo_800B2AFC(Fighter* fp) int line26; Vec3 floor_normal26; Vec3 floor_pos26; - u8 operand_pad[8]; PAD_STACK(0x8); switch (fp->x1A88.xC) { case 0: { struct Fighter_x1A88_t* data = &fp->x1A88; - s32 result; s32 found; + s32 result; s32 do_act; f32 px; f32 py; + f32 above; + f32 below; + s32 x18; data->xF8_b0 = false; data->xF9_b2 = false; @@ -8772,7 +8947,8 @@ void ftCo_800B2AFC(Fighter* fp) data->xF9_b6 = false; data->xF9_b7 = false; data->xF9_b1 = false; - if (data->x18 != data->x20 && data->x18 != data->x1C) { + x18 = fp->x1A88.x18; + if (x18 != data->x20 && x18 != data->x1C) { data->x60 = 0; } if (data->x18 == 4) { @@ -8786,9 +8962,11 @@ void ftCo_800B2AFC(Fighter* fp) py = fp->cur_pos.y; found = 0; line0 = -1; - result = mpCheckFloor(px, 10.0f + py, px, py - 1000.0f, 0.0f, - &floor_pos0, &line0, &flags0, &floor_normal0, - -1, -1, -1, NULL, NULL); + above = 10.0f + py; + below = py - 1000.0f; + result = + mpCheckFloor(px, above, px, below, 0.0f, &floor_pos0, &line0, + &flags0, &floor_normal0, -1, -1, -1, NULL, NULL); if (result != 0 && ftCo_800A1B38_noinline(line0) != 0) { } else { found = result; @@ -8802,11 +8980,14 @@ void ftCo_800B2AFC(Fighter* fp) } case 1: { struct Fighter_x1A88_t* data = &fp->x1A88; - s32 result; s32 found; + s32 result; s32 do_act; f32 px; f32 py; + f32 above; + f32 below; + s32 x18; data->xF8_b0 = false; data->xF9_b2 = false; @@ -8816,7 +8997,8 @@ void ftCo_800B2AFC(Fighter* fp) data->xF9_b6 = false; data->xF9_b7 = false; data->xF9_b1 = false; - if (data->x18 != data->x20 && data->x18 != data->x1C) { + x18 = fp->x1A88.x18; + if (x18 != data->x20 && x18 != data->x1C) { data->x60 = 0; } if (data->x18 == 4) { @@ -8826,13 +9008,15 @@ void ftCo_800B2AFC(Fighter* fp) do_act = 1; } if (do_act != 0) { - px = data->x98.x; - py = data->x98.y; + px = fp->x1A88.x98.x; + py = fp->x1A88.x98.y; found = 0; line1 = -1; - result = mpCheckFloor(px, 10.0f + py, px, py - 1000.0f, 0.0f, - &floor_pos1, &line1, &flags1, &floor_normal1, - -1, -1, -1, NULL, NULL); + above = 10.0f + py; + below = py - 1000.0f; + result = + mpCheckFloor(px, above, px, below, 0.0f, &floor_pos1, &line1, + &flags1, &floor_normal1, -1, -1, -1, NULL, NULL); if (result != 0 && ftCo_800A1B38_noinline(line1) != 0) { } else { found = result; @@ -8852,11 +9036,14 @@ void ftCo_800B2AFC(Fighter* fp) return; case 3: { struct Fighter_x1A88_t* data = &fp->x1A88; - s32 result; s32 found; + s32 result; s32 do_act; f32 px; f32 py; + f32 above; + f32 below; + s32 x18; data->xF8_b0 = false; data->xF9_b2 = false; @@ -8866,7 +9053,8 @@ void ftCo_800B2AFC(Fighter* fp) data->xF9_b6 = false; data->xF9_b7 = false; data->xF9_b1 = false; - if (data->x18 != data->x20 && data->x18 != data->x1C) { + x18 = fp->x1A88.x18; + if (x18 != data->x20 && x18 != data->x1C) { data->x60 = 0; } if (data->x18 == 4) { @@ -8880,9 +9068,11 @@ void ftCo_800B2AFC(Fighter* fp) py = fp->cur_pos.y; found = 0; line3 = -1; - result = mpCheckFloor(px, 10.0f + py, px, py - 1000.0f, 0.0f, - &floor_pos3, &line3, &flags3, &floor_normal3, - -1, -1, -1, NULL, NULL); + above = 10.0f + py; + below = py - 1000.0f; + result = + mpCheckFloor(px, above, px, below, 0.0f, &floor_pos3, &line3, + &flags3, &floor_normal3, -1, -1, -1, NULL, NULL); if (result != 0 && ftCo_800A1B38_noinline(line3) != 0) { } else { found = result; @@ -8948,6 +9138,7 @@ void ftCo_800B2AFC(Fighter* fp) case 23: { struct Fighter_x1A88_t* data = &fp->x1A88; s32 do_act; + s32 x18; data->xF8_b0 = false; data->xF9_b2 = true; @@ -8958,7 +9149,8 @@ void ftCo_800B2AFC(Fighter* fp) data->xF9_b7 = false; data->xF9_b1 = false; data->x44 = ftCo_800A4BEC(fp); - if (data->x18 != data->x20 && data->x18 != data->x1C) { + x18 = fp->x1A88.x18; + if (x18 != data->x20 && x18 != data->x1C) { data->x60 = 0; } if (data->x18 == 4) { @@ -8979,6 +9171,7 @@ void ftCo_800B2AFC(Fighter* fp) case 25: { struct Fighter_x1A88_t* data = &fp->x1A88; s32 do_act; + s32 x18; data->xF8_b0 = false; data->xF9_b2 = true; @@ -8989,7 +9182,8 @@ void ftCo_800B2AFC(Fighter* fp) data->xF9_b7 = false; data->xF9_b1 = false; data->x44 = ftCo_800A4BEC(fp); - if (data->x18 != data->x20 && data->x18 != data->x1C) { + x18 = fp->x1A88.x18; + if (x18 != data->x20 && x18 != data->x1C) { data->x60 = 0; } if (data->x18 == 4) { @@ -9006,11 +9200,14 @@ void ftCo_800B2AFC(Fighter* fp) } case 26: { struct Fighter_x1A88_t* data = &fp->x1A88; - s32 result; s32 found; + s32 result; s32 do_act; f32 px; f32 py; + f32 above; + f32 below; + s32 x18; data->xF8_b0 = false; data->xF9_b2 = true; @@ -9021,7 +9218,8 @@ void ftCo_800B2AFC(Fighter* fp) data->xF9_b7 = false; data->xF9_b1 = false; data->x44 = ftCo_800A4BEC(fp); - if (data->x18 != data->x20 && data->x18 != data->x1C) { + x18 = fp->x1A88.x18; + if (x18 != data->x20 && x18 != data->x1C) { data->x60 = 0; } if (data->x18 == 4) { @@ -9035,9 +9233,11 @@ void ftCo_800B2AFC(Fighter* fp) py = fp->cur_pos.y; found = 0; line26 = -1; - result = mpCheckFloor(px, 10.0f + py, px, py - 1000.0f, 0.0f, - &floor_pos26, &line26, &flags26, - &floor_normal26, -1, -1, -1, NULL, NULL); + above = 10.0f + py; + below = py - 1000.0f; + result = mpCheckFloor(px, above, px, below, 0.0f, &floor_pos26, + &line26, &flags26, &floor_normal26, -1, -1, + -1, NULL, NULL); if (result != 0 && ftCo_800A1B38_noinline(line26) != 0) { } else { found = result; @@ -9063,6 +9263,8 @@ void ftCo_800B2AFC(Fighter* fp) ftCo_800B24B8(fp); break; } + + PAD_STACK(0x8); } static inline void ftCo_800A0CB0_dontinline(Fighter* fp) @@ -9070,23 +9272,23 @@ static inline void ftCo_800A0CB0_dontinline(Fighter* fp) ftCo_800A0CB0(fp); } +static inline int ftCo_800B33B0_IsIgnoredFloor(int line1) +{ + return ftCo_800A1B38_noinline(line1) != 0; +} + void ftCo_800B33B0(Fighter* fp) { struct Fighter_x1A88_t* data = &fp->x1A88; int* timer = &data->x7C; - Vec3 sp7C; - Vec3 sp70; - Vec3 sp64; + Vec3 floor_vel; + Vec3 target_floor_pos; + Vec3 target_floor_normal; int line2; u32 flags2; - u32 flags1; - int line1; - Vec3 sp44; - Vec3 sp38; - Vec3 sp24; - int line3; - u32 flags3; - Vec3 sp18; + f32 fx; + f32 below; + f32 tmp; s32 found; s32 result; s32 in_bounds; @@ -9094,11 +9296,17 @@ void ftCo_800B33B0(Fighter* fp) f32 vx; f32 vy; f32 vmag; - f32 fx; f32 fy; f32 sx; f32 sy; - u8 operand_pad[8]; + u32 flags1; + int line1; + Vec3 floor_normal; + Vec3 floor_pos; + u32 flags3; + int line3; + Vec3 ceiling_normal; + Vec3 ceiling_pos; if (*timer % 300 == 0) { if (HSD_Randf() < 0.04f * data->level + 0.3f) { @@ -9112,19 +9320,28 @@ void ftCo_800B33B0(Fighter* fp) fx = fp->cur_pos.x; line1 = -1; { - f32 tmp = 10.0 + fy; - result = mpCheckFloor(fx, tmp, fx, fy - 1000.0, 0.0f, &sp38, &line1, - &flags1, &sp44, -1, -1, -1, NULL, NULL); + sy = fy; + sx = fx; + below = sy - 1000.0; + tmp = 10.0 + sy; + { + result = mpCheckFloor(sx, tmp, sx, below, 0.0f, &floor_pos, &line1, + &flags1, &floor_normal, -1, -1, -1, NULL, + (Fighter_GObj*) found); + } } - if (result != 0 && ftCo_800A1B38_noinline(line1) != 0) { + if (result != 0 && ftCo_800B33B0_IsIgnoredFloor(line1)) { } else { found = result; } if (found != 0) { - f32 floor_y = sp38.y; - struct Fighter_x1A88_t* temp_data = &fp->x1A88; - f32 floor_x = sp38.x; + f32 floor_x; + f32 floor_y; + struct Fighter_x1A88_t* temp_data; s32 oob; + floor_y = floor_pos.y; + temp_data = &fp->x1A88; + floor_x = floor_pos.x; if (floor_x < fp->x1A88.half_width + Stage_GetBlastZoneLeftOffset() || floor_x > Stage_GetBlastZoneRightOffset() - temp_data->half_width || @@ -9164,12 +9381,13 @@ void ftCo_800B33B0(Fighter* fp) } if (data->xF9_b0) { if (data->x30 != 0) { - data->x30 = data->x30 - 1; + data->x30 -= 1; } else { data->xF9_b0 = false; } } else { - data->x30 = 120.0f * (0.5f * (0.5f * HSD_Randf())); + f32 rand = HSD_Randf(); + data->x30 = 120.0f * (0.5f * (0.5f * rand)); } if (data->x60 != 0) { data->x60 = data->x60 - 1; @@ -9184,8 +9402,9 @@ void ftCo_800B33B0(Fighter* fp) line2 = -1; { f32 tmp = 2.0 + sy; - result = mpCheckFloor(sx, tmp, sx, sy - 2.0, 0.0f, &sp70, &line2, - &flags2, &sp64, -1, -1, -1, NULL, NULL); + result = mpCheckFloor(sx, tmp, sx, sy - 2.0, 0.0f, &target_floor_pos, + &line2, &flags2, &target_floor_normal, -1, -1, + -1, NULL, (Fighter_GObj*) blocked); } if (result != 0) { int line = line2; @@ -9199,12 +9418,12 @@ void ftCo_800B33B0(Fighter* fp) } } if (result != 0) { - mpGetSpeed(line2, &sp70, &sp7C); - data->x54.x += sp7C.x; - data->x54.y += sp7C.y; - } else if (grLib_801C9E60(&sp7C) != 0) { - data->x54.x += sp7C.x; - data->x54.y += sp7C.y; + mpGetSpeed(line2, &target_floor_pos, &floor_vel); + data->x54.x += floor_vel.x; + data->x54.y += floor_vel.y; + } else if (grLib_801C9E60(&floor_vel) != 0) { + data->x54.x += floor_vel.x; + data->x54.y += floor_vel.y; } if (*timer % 30 == 0) { struct Fighter_x1A88_t* temp_data = &fp->x1A88; @@ -9217,8 +9436,8 @@ void ftCo_800B33B0(Fighter* fp) if (fp->x1A88.xFA_b6) { fx = fp->cur_pos.x; fy = fp->cur_pos.y; - if (mpCheckCeiling(fx, fy, fx, 1000.0f + fy, &sp18, &line3, - &flags3, &sp24, -1, -1) == 0) + if (mpCheckCeiling(fx, fy, fx, 1000.0f + fy, &ceiling_pos, &line3, + &flags3, &ceiling_normal, -1, -1) == 0) { temp_data->xFA_b6 = false; } diff --git a/src/melee/ft/chara/ftCommon/ftCo_Attack100.c b/src/melee/ft/chara/ftCommon/ftCo_Attack100.c index 5561a657d0..acdea74bde 100644 --- a/src/melee/ft/chara/ftCommon/ftCo_Attack100.c +++ b/src/melee/ft/chara/ftCommon/ftCo_Attack100.c @@ -509,46 +509,56 @@ bool ftCo_800D730C(Fighter_GObj* gobj, bool arg1) bool ftCo_800D72A0(Fighter* fp) { - if (fp->x2D0->x2C != -1) { - if (fp->x2D0->x2C <= fp->motion_id && - fp->motion_id < fp->x2D0->x2C + fp->x2D0->x28) - { - return true; - } + s32 start; + s32 start_alt; + s32 motion_id; + struct Fighter_x2D0_t* x2D0; + + x2D0 = fp->x2D0; + start = x2D0->x2C; + if (start != -1 && start <= (motion_id = fp->motion_id) && + motion_id < start + x2D0->x28) + { + return true; } - if (fp->x2D0->x30 != -1) { - if (fp->x2D0->x30 <= fp->motion_id && - fp->motion_id < fp->x2D0->x30 + fp->x2D0->x28) - { - return true; - } + start_alt = x2D0->x30; + if (start_alt != -1 && start_alt <= (motion_id = fp->motion_id) && + motion_id < start_alt + x2D0->x28) + { + return true; } return false; } +static inline struct Fighter_x2D0_t* ftCo_800D74A4_inline(Fighter* fp) +{ + return fp->x2D0; +} + void ftCo_800D74A4(Fighter_GObj* gobj) { extern f32 ftCo_804D9018; Vec3 vel; Fighter* fp; s32 msid; - struct Fighter_x2D0_t* p; struct Fighter_x2D0_t* tmp; + s32 msid2; + struct Fighter_x2D0_t* p; PAD_STACK(0x14); + fp = gobj->user_data; - p = fp->x2D0; + p = ftCo_800D74A4_inline(fp); fp->cmd_vars[0] = 0; tmp = fp->x2D0; - msid = fp->x1968_jumpsUsed + - ((struct Fighter_x2D0_t*) ((s32*) tmp + ftCo_800D7268(fp)))->x2C; + tmp = (struct Fighter_x2D0_t*) ((s32*) tmp + ftCo_800D7268(fp)); + msid = tmp->x2C + fp->x1968_jumpsUsed; vel.x = fp->input.lstick.x * p->x8; - msid -= 1; + msid2 = msid - 1; tmp = fp->x2D0; - vel.y = p->x14[msid - - ((struct Fighter_x2D0_t*) ((s32*) tmp + ftCo_800D7268(fp))) - ->x2C]; + tmp = (struct Fighter_x2D0_t*) ((s32*) tmp + ftCo_800D7268(fp)); + vel.y = p->x14[msid2 - tmp->x2C]; vel.z = ftCo_804D9018; - ftCo_800CBAC4(gobj, msid, &vel, false); + ftCo_800CBAC4(gobj, msid2, &vel, false); if ((fp->input.lstick.x * fp->facing_dir) < -p->x4) { *(s32*) &fp->mv.ca.specials.grav = p->x0; } else { @@ -1421,7 +1431,8 @@ bool fn_800D9558(Fighter_GObj* gobj) Fighter* fp = GET_FIGHTER(gobj); ftSs_DatAttrs* attrs; Item_GObj* item; - Item* it; + s32 frame; + s32 i; itSamusGrappleAttributes* grappleAttrs; HSD_GObj* segGobj; HSD_JObj* jobj; @@ -1431,9 +1442,7 @@ bool fn_800D9558(Fighter_GObj* gobj) f32 grav; f32 my; f32 r; - s32 i; - s32 frame; - PAD_STACK(0x14); + PAD_STACK(0x10); if (fp->kind == FTKIND_SAMUS) { attrs = fp->dat_attrs; fp->mv.ca.specials.grav += 1.0; @@ -1450,8 +1459,9 @@ bool fn_800D9558(Fighter_GObj* gobj) fp->accessory3_cb = (void (*)(HSD_GObj*)) it_802BACC4; } else if (grav > (f32) attrs->x9C) { if (grav <= (f32) attrs->xA8) { + Item* it; + it = GET_ITEM(fp->fv.ss.x223C); item = fp->fv.ss.x223C; - it = GET_ITEM(item); grappleAttrs = it->xC4_article_data->x4_specialAttributes; if (item != NULL) { for (i = 0, frame = 0x14; i < 6; i++, frame += 3) { @@ -1466,7 +1476,7 @@ bool fn_800D9558(Fighter_GObj* gobj) effPos.y = 4.0 * (HSD_Randf() - 0.5f) + effPos.y; r = HSD_Randf() - 0.5f; effPos.z = 4.0 * r + effPos.z; - efSync_Spawn(0x3F3, segGobj, &effPos, r); + efSync_Spawn(0x3F3, segGobj, &effPos); } } } @@ -1751,6 +1761,11 @@ bool fn_800D952C(Fighter_GObj* gobj) static const Vec3 lbl_803B7510 = { 1.0f, 0.0f, 0.0f }; +static inline f32 fn_800D9930_inline(void) +{ + return HSD_Randf(); +} + bool fn_800D9930(Fighter_GObj* gobj) { Fighter* fp = GET_FIGHTER(gobj); @@ -1797,11 +1812,12 @@ bool fn_800D9930(Fighter_GObj* gobj) effPos.x = jobj->mtx[0][3]; effPos.y = jobj->mtx[1][3]; effPos.z = jobj->mtx[2][3]; - effPos.x = 4.0 * (HSD_Randf() - 0.5f) + effPos.x; + effPos.x = + 4.0 * (fn_800D9930_inline() - 0.5f) + effPos.x; effPos.y = 4.0 * (HSD_Randf() - 0.5f) + effPos.y; r = HSD_Randf() - 0.5f; effPos.z = 4.0 * r + effPos.z; - efSync_Spawn(0x3F3, segGobj, &effPos, r); + efSync_Spawn(0x3F3, segGobj, &effPos); } } } diff --git a/src/melee/ft/chara/ftCommon/ftCo_Bury.c b/src/melee/ft/chara/ftCommon/ftCo_Bury.c index 90ca62d572..b7db8f8d1e 100644 --- a/src/melee/ft/chara/ftCommon/ftCo_Bury.c +++ b/src/melee/ft/chara/ftCommon/ftCo_Bury.c @@ -73,7 +73,7 @@ void ftCo_800C08A0(Fighter_GObj* gobj, Fighter_GObj* arg1, DynamicsDesc* arg2, ftCommon_BuryType arg3) { float f; - struct SmallerHitCapsule hit; + u8 _[4]; int hurt_idx; FighterHurtCapsule* p_hurt; Fighter* fp = GET_FIGHTER(gobj); @@ -83,6 +83,12 @@ void ftCo_800C08A0(Fighter_GObj* gobj, Fighter_GObj* arg1, DynamicsDesc* arg2, case BuryType_Unk2: break; case BuryType_Unk1: + /// @remarks The redundant @c hurt_idx re-assignment gives the + /// variable a second reaching definition, which keeps MWCC's + /// global optimizer from folding the constant index into the + /// @c hurt_capsules address math (retail keeps the full + /// mulli/addi/add sequence at 800C0938). + hurt_idx = 0; fp->bury_timer_1 = p_ftCommonData->bury_timer_unk1; break; case BuryType_Unk3: @@ -90,6 +96,7 @@ void ftCo_800C08A0(Fighter_GObj* gobj, Fighter_GObj* arg1, DynamicsDesc* arg2, break; } if (ftColl_80076640(fp, &f) != 0) { + struct SmallerHitCapsule hit; p_hurt = &fp->hurt_capsules[hurt_idx]; ftColl_80076764(3, arg3, arg1, arg2, fp, p_hurt); lbColl_80008D30((HitCapsule*) &hit, (lbColl_80008D30_arg1*) arg2); @@ -183,18 +190,18 @@ void ftCo_800C0B20(Fighter_GObj* gobj) unk_anim = Ground_801C5700(coll->left_facing_wall.index); } if (unk_anim != NULL) { - HitCapsule hit; + u8 _[8]; + struct SmallerHitCapsule hit; Fighter* fp = GET_FIGHTER(gobj); float f = ftColl_800765F0(fp, NULL, unk_anim->count); fp->bury_timer_1 = p_ftCommonData->bury_timer_unk1; if (ftColl_80076640(fp, &f)) { - FighterHurtCapsule* hurt = &fp->hurt_capsules[0]; + FighterHurtCapsule* hurt; + hurt = &fp->hurt_capsules[0]; ftColl_80076764(3, 1, 0, unk_anim, fp, hurt); - - /// @todo Eliminate cast - lbColl_80008D30(&hit, (lbColl_80008D30_arg1*) unk_anim); - - ftColl_80078384(fp, hurt, &hit); + lbColl_80008D30((HitCapsule*) &hit, + (lbColl_80008D30_arg1*) unk_anim); + ftColl_80078384(fp, hurt, (HitCapsule*) &hit); } pl_8003EC30(fp->player_id, fp->x221F_b4, 1, f); } diff --git a/src/melee/ft/chara/ftCommon/ftCo_Damage.c b/src/melee/ft/chara/ftCommon/ftCo_Damage.c index 8a27181cb1..c3a3c910d8 100644 --- a/src/melee/ft/chara/ftCommon/ftCo_Damage.c +++ b/src/melee/ft/chara/ftCommon/ftCo_Damage.c @@ -231,21 +231,19 @@ void ftCo_Damage_CalcVel(Fighter* fp, float x, float y) static float calcAngle(float angle) { - float x = cosf(angle) + cosf(M_PI_2); - float y = sinf(angle) + sinf(M_PI_2); + float x = cosf(angle) + cosf(M_PI_2_F); + float temp = M_PI_2_F; + float y = sinf(angle) + sinf(temp); if (x * x + y * y <= 0.0001f) { return 0; } return atan2f(y, x); } -static void inlineA0(Fighter_GObj* gobj, float f1, float f2) +static void inlineA0(Fighter_GObj* gobj, Fighter* fp, float* angle) { - { - Fighter* fp = gobj->user_data; - efAsync_Spawn(gobj, fp->x60C, 4U, 0x406U, fp->parts[FtPart_TopN].joint, - f1, fp, f2); - } + efAsync_Spawn(gobj, &GET_FIGHTER(gobj)->x60C, 4U, 0x406U, + fp->parts[FtPart_TopN].joint, angle); } static void inlineA1(Fighter_GObj* gobj) @@ -263,16 +261,16 @@ static inline int* getDamageMotionIds(enum_t kb_level) void ftCo_8008DCE0(Fighter_GObj* gobj, int arg1, float facing_dir) { - float temp_f30; - Vec3 pos; + float scaled_kb_154; float sp40; + Vec3 pos; u8 _[0x2C] = { 0 }; float temp_f1_2; float temp_f1_3; float temp_f2; float scaled_kb; float kb_angle; - s32 var_r0; + s32 should_collide; s32 kb_level_base; Fighter* fp = gobj->user_data; enum_t kb_level; @@ -284,25 +282,25 @@ void ftCo_8008DCE0(Fighter_GObj* gobj, int arg1, float facing_dir) Fighter_8006CDA4(fp, fp->dmg.x1838_percentTemp); fp->dmg.x18d8.kb_applied1 = kb_applied; pl_80040270(fp->player_id, fp->x221F_b4, kb_applied); - temp_f30 = kb_applied * p_ftCommonData->x154; - fp->mv.co.damage.x0 = (int) temp_f30; + scaled_kb_154 = kb_applied * p_ftCommonData->x154; + fp->mv.co.damage.x0 = (int) scaled_kb_154; if (!fp->mv.co.damage.x0) { fp->mv.co.damage.x0 = 1; } { Vec3* normal; - if (temp_f30 < p_ftCommonData->x158) { + if (scaled_kb_154 < p_ftCommonData->x158) { kb_level_base = 0; goto block_9; } else { - if (!(temp_f30 < p_ftCommonData->x15C)) { + if (!(scaled_kb_154 < p_ftCommonData->x15C)) { goto block_6; } kb_level_base = 1; goto block_9; } block_6: - if (!(temp_f30 < p_ftCommonData->x160)) { + if (!(scaled_kb_154 < p_ftCommonData->x160)) { goto block_8; } kb_level_base = 2; @@ -316,14 +314,14 @@ void ftCo_8008DCE0(Fighter_GObj* gobj, int arg1, float facing_dir) } kb_level = 3; block_11: - fp->mv.co.damage.x1A = 0; scaled_kb = kb_applied * p_ftCommonData->x100; + fp->mv.co.damage.x1A = 0; fp->mv.co.damage.x14 = 0; kb_angle = ftCo_Damage_CalcAngle(fp, kb_applied); if (kb_level_base < 2) { goto block_17; } - if ((u32) M2C_FIELD(fp, u32*, 0x1860) != 5U) { + if ((u32) fp->dmg.x1860_element != 5U) { goto block_17; } kb_angle = calcAngle(kb_angle); @@ -334,8 +332,7 @@ void ftCo_8008DCE0(Fighter_GObj* gobj, int arg1, float facing_dir) if (fp->ground_or_air != GA_Air) { goto block_21; } - msid = - getDamageMotionIds(kb_level)[fp->dmg.x184c_damaged_hurtbox + 12]; + msid = ftCo_803C5520[1][kb_level * 3 + fp->dmg.x184c_damaged_hurtbox]; if (!ftCo_Damage_CheckAirMotion(fp)) { goto block_20; } @@ -368,10 +365,7 @@ void ftCo_8008DCE0(Fighter_GObj* gobj, int arg1, float facing_dir) ftCommon_8007D5D4(fp); msid = ((int (*)[4][3]) ftCo_803C5520)[0][kb_level][fp->dmg.x184c_damaged_hurtbox]; - if (!(temp_f1_2 > - (float) (M_PI_2 + - (double) M2C_FIELD(p_ftCommonData, float*, 0x1E8)))) - { + if (!(temp_f1_2 > (M_PI_2 + (double) p_ftCommonData->x1E8_radians))) { goto block_26; } ftCo_Damage_CalcVel(fp, pos.x, -pos.y * p_ftCommonData->x1EC); @@ -379,7 +373,7 @@ void ftCo_8008DCE0(Fighter_GObj* gobj, int arg1, float facing_dir) fp->xF0_ground_kb_vel = 0; temp_f1_3 = atan2f(-normal->x, normal->y); sp40 = temp_f1_3; - inlineA0(gobj, sp40, temp_f1_3); + inlineA0(gobj, fp, &sp40); goto block_28; block_26: ftCo_Damage_CalcVel(fp, pos.x, pos.y); @@ -400,21 +394,19 @@ void ftCo_8008DCE0(Fighter_GObj* gobj, int arg1, float facing_dir) if (fp->ground_or_air != GA_Air) { goto block_36; } - if (!(kb_angle > M2C_FIELD(p_ftCommonData, float*, 0x234))) { + if (!(kb_angle > p_ftCommonData->x234_radians)) { goto block_33; } - if (!(kb_angle < M2C_FIELD(p_ftCommonData, float*, 0x238))) { + if (!(kb_angle < p_ftCommonData->x238_radians)) { goto block_33; } msid = 0x5A; goto block_36; block_33: - if (!(fp->dmg.x1830_percent >= - (float) M2C_FIELD(p_ftCommonData, s32*, 0x23C))) - { + if (!(fp->dmg.x1830_percent >= (float) (s32) p_ftCommonData->x23C)) { goto block_36; } - if (!(HSD_Randf() < M2C_FIELD(p_ftCommonData, float*, 0x240))) { + if (!(HSD_Randf() < p_ftCommonData->x240)) { goto block_36; } msid = 0x5B; @@ -430,22 +422,22 @@ void ftCo_8008DCE0(Fighter_GObj* gobj, int arg1, float facing_dir) if (kb_level_base < 2) { goto block_42; } - if ((u32) M2C_FIELD(fp, u32*, 0x1860) != 5U) { + if ((u32) fp->dmg.x1860_element != 5U) { goto block_42; } msid = 0x5A; block_42: - M2C_FIELD(fp, float*, 0x18A4) = un_803222EC(kb_applied, kb_angle); - un_8032233C(M2C_FIELD(fp, s32*, 0x18C0), M2C_FIELD(fp, s32*, 8)); + fp->dmg.x18A4_knockbackMagnitude = un_803222EC(kb_applied, kb_angle); + un_8032233C(fp->dmg.x18C0, fp->x8_spawnNum); if (!facing_dir) { goto block_44; } - M2C_FIELD(fp, float*, 0x2C) = facing_dir; + fp->facing_dir = facing_dir; } block_44: ftCo_8008DA4C(gobj, kb_level, 0); - ftCo_8008DB10(gobj, (s32) M2C_FIELD(fp, u32*, 0x1860), kb_applied); + ftCo_8008DB10(gobj, (s32) fp->dmg.x1860_element, kb_applied); Fighter_ChangeMotionState(gobj, msid, 0x40U, 0, 1, 0, NULL); ftAnim_8006EBA4(gobj); if (!gm_8016B014()) { @@ -457,27 +449,26 @@ void ftCo_8008DCE0(Fighter_GObj* gobj, int arg1, float facing_dir) if (!(kb_applied > p_ftCommonData->x12C)) { goto block_62; } - var_r0 = 1; + should_collide = 1; goto block_63; block_62: - var_r0 = 0; + should_collide = 0; block_63: - M2C_FIELD(fp, s32*, 0x2344) = var_r0; - M2C_FIELD(fp, s8*, 0x2359) = 0; - M2C_FIELD(fp, void (**)(Fighter_GObj*), 0x21D0) = - ftCo_Damage_OnEveryHitlag; + fp->mv.co.damage.x4 = should_collide; + fp->mv.co.damage.x19 = 0; + fp->hitlag_cb = ftCo_Damage_OnEveryHitlag; fp->x670_timer_lstick_tilt_x = 0xFE; fp->x671_timer_lstick_tilt_y = 0xFE; - M2C_FIELD(fp, void (**)(Fighter_GObj*), 0x21D8) = ftCo_Damage_OnExitHitlag; - M2C_FIELD(fp, float*, 0x18A8) = (float) M2C_FIELD(fp, float*, 0x1850); + fp->post_hitlag_cb = ftCo_Damage_OnExitHitlag; + fp->dmg.x18A8 = (float) fp->dmg.kb_applied; fp->x221C_b6 = true; - M2C_FIELD(fp, s32*, 0x18AC) = (s32) 0; + fp->dmg.x18ac_time_since_hit = (s32) 0; if (msid == 0x5B) { inlineA1(gobj); } fp->x67F = 0xFF; ftCo_Damage_SetMv8FromKbThreshold(fp); - if (M2C_FIELD(fp, s32*, 0x2348) == 0) { + if (fp->mv.co.damage.x8 == 0) { goto block_67; } fp->mv.co.damage.x8 = 1; @@ -493,20 +484,18 @@ void ftCo_8008DCE0(Fighter_GObj* gobj, int arg1, float facing_dir) if (var_r27 == 0) { goto block_75; } - if (!(temp_f30 >= M2C_FIELD(p_ftCommonData, float*, 0x20C))) { + if (!(scaled_kb_154 >= p_ftCommonData->x20C)) { goto block_73; } - M2C_FIELD(fp, s32*, 0x1908) = 0x4F; - M2C_FIELD(fp, s32*, 0x190C) = (s32) M2C_FIELD( - M2C_FIELD(M2C_FIELD(fp, void**, 0x10C), void**, 0x4C), s32*, 0x20); + fp->dmg.x1908 = 0x4F; + fp->dmg.x190C = (UNK_T) fp->ft_data->x4C_sfx->x20; goto block_75; block_73: - if (!(temp_f30 >= M2C_FIELD(p_ftCommonData, float*, 0x208))) { + if (!(scaled_kb_154 >= p_ftCommonData->x208)) { goto block_75; } - M2C_FIELD(fp, s32*, 0x1908) = 0x50; - M2C_FIELD(fp, s32*, 0x190C) = (s32) M2C_FIELD( - M2C_FIELD(M2C_FIELD(fp, void**, 0x10C), void**, 0x4C), s32*, 0x1C); + fp->dmg.x1908 = 0x50; + fp->dmg.x190C = (UNK_T) fp->ft_data->x4C_sfx->x1C; block_75: if (kb_level != 3) { goto block_83; @@ -514,14 +503,14 @@ void ftCo_8008DCE0(Fighter_GObj* gobj, int arg1, float facing_dir) if (fp->ground_or_air != GA_Air) { goto block_83; } - if (!(temp_f30 >= M2C_FIELD(p_ftCommonData, float*, 0x174))) { + if (!(scaled_kb_154 >= p_ftCommonData->x174)) { goto block_79; } { enum_t cam_enum = 4; goto block_82; block_79: - if (!(temp_f30 >= p_ftCommonData->x170)) { + if (!(scaled_kb_154 >= p_ftCommonData->x170)) { goto block_81; } cam_enum = 3; @@ -726,8 +715,7 @@ static bool inlineB0(Fighter_GObj* gobj) { Fighter* fp = gobj->user_data; float kb_applied = fp->dmg.kb_applied; - // might not be correct? - if (kb_applied != 0) { + if (kb_applied == 0) { return true; } if (fp->allow_sdi && fp->x221A_b3 && @@ -815,9 +803,16 @@ static inline void inlineB2(Fighter_GObj* gobj) } /// @todo Inline depth. -static inline bool inlineB3(Fighter_GObj* gobj) +static inline void inlineB3(Fighter_GObj* gobj) { - return inlineB0(gobj); + Fighter* fp = gobj->user_data; + float kb_applied = fp->dmg.kb_applied; + if (kb_applied == 0 || + (fp->allow_sdi && fp->x221A_b3 && + fp->dmg.kb_applied < fp->dmg.x18A8 + p_ftCommonData->x140)) + { + ftCo_8008E9D0(gobj); + } } void ftCo_8008EC90(Fighter_GObj* gobj) @@ -902,9 +897,7 @@ void ftCo_8008EC90(Fighter_GObj* gobj) fp->dmg.x183C_applied; other_fp->x1960_vibrateMult = fp->x1960_vibrateMult; - if (inlineB3(gobj)) { - ftCo_8008E9D0(gobj); - } + inlineB3(gobj); fp->x1828 = 2; goto ret_A8C; } diff --git a/src/melee/ft/chara/ftCommon/ftCo_DamageIce.c b/src/melee/ft/chara/ftCommon/ftCo_DamageIce.c index d36a4e8d8a..eede0fb39c 100644 --- a/src/melee/ft/chara/ftCommon/ftCo_DamageIce.c +++ b/src/melee/ft/chara/ftCommon/ftCo_DamageIce.c @@ -119,7 +119,9 @@ static void ftCo_DamageIce_OnHit(Fighter_GObj* gobj) static inline void ftCo_DamageIce_StartJump(Fighter* fp) { - float* ice_size = &fp->co_attrs.damageice_ice_size; + float* ice_size; + HSD_JObj* effect_joint; + float param; { ftCo_8009E140(fp, 0); @@ -149,7 +151,14 @@ static inline void ftCo_DamageIce_StartJump(Fighter* fp) } ftCo_800909D0(fp); - ftCo_80090AC0(fp); + + effect_joint = fp->parts[ftParts_GetBoneIndex(fp, FtPart_XRotN)].joint; + ice_size = &fp->co_attrs.damageice_ice_size; + param = fp->x34_scale.y * *ice_size / + p_ftCommonData->damageice_ice_size; + + ftCo_SpawnEffect_x415(fp->gobj, effect_joint, ¶m); + fp->x2219_b0 = true; ftColl_8007B0C0(fp->gobj, Intangible); { @@ -195,7 +204,7 @@ void ftCo_DamageIce_Init(Fighter_GObj* gobj) Mtx rot_mtx_y; Quaternion rot_x; Mtx rot_mtx_x; - PAD_STACK(16); + PAD_STACK(24); fp = GET_FIGHTER(gobj); @@ -249,7 +258,15 @@ void ftCo_DamageIce_Init(Fighter_GObj* gobj) void ftCo_DamageIce_HitWhileFrozen(Fighter_GObj* gobj) { + float param; + ftHurtboxInit hurt; + Vec3 offset; + HSD_JObj* effect_joint; + float* ice_size; + float rot_min, rot_max; + float rand, rand_range; Fighter* fp; + fp = GET_FIGHTER(gobj); ftCommon_8007DB58(gobj); @@ -260,7 +277,51 @@ void ftCo_DamageIce_HitWhileFrozen(Fighter_GObj* gobj) Fighter_ChangeMotionState(gobj, ftCo_MS_DamageIce, Ft_MF_KeepGfx | Ft_MF_Unk06, 0, 1, 0, NULL); - ftCo_DamageIce_StartJump(fp); + ftCo_8009E140(fp, 0); + ftCommon_8007F824(fp->gobj); + fp->x2222_b3 = true; + + if (fp->ground_or_air == GA_Air) { + fp->self_vel = fp->x8c_kb_vel; + fp->x8c_kb_vel.x = fp->x8c_kb_vel.y = fp->x8c_kb_vel.z = 0; + } else { + fp->gr_vel = fp->xF0_ground_kb_vel; + fp->xF0_ground_kb_vel = 0; + } + + ftCommon_8007E2F4(fp, 0x1FF); + fp->mv.co.damageice.wall_hit_dir = 0; + rand = HSD_Randf(); + rot_min = p_ftCommonData->damageice_rot_speed_min; + rot_max = p_ftCommonData->damageice_rot_speed_max; + rand_range = rot_max - rot_min; + fp->mv.co.damageice.rot_speed = rand_range * rand + rot_min; + ftCo_800909D0(fp); + + effect_joint = fp->parts[ftParts_GetBoneIndex(fp, FtPart_XRotN)].joint; + ice_size = &fp->co_attrs.damageice_ice_size; + param = fp->x34_scale.y * *ice_size / p_ftCommonData->damageice_ice_size; + + { + float* effect_param = ¶m; + efAsync_Spawn(fp->gobj, &GET_FIGHTER(fp->gobj)->x60C, 3, 0x415, + effect_joint, effect_param); + } + fp->x2219_b0 = true; + ftColl_8007B0C0(fp->gobj, Intangible); + + offset = ftCo_DamageIce_HurtboxOffset; + hurt.bone_idx = ftParts_GetBoneIndex(fp, FtPart_XRotN); + hurt.height = HurtHeight_Mid; + hurt.is_grabbable = false; + hurt.a_offset = hurt.b_offset = offset; + hurt.scale = *ice_size; + + ftColl_HurtboxInit(fp, fp->hurt_capsules, &hurt); + ftCommon_8007EBAC(fp, 1, 0); + + fp->take_dmg_2_cb = ftCo_DamageIce_OnHit2; + fp->take_dmg_cb = ftCo_DamageIce_OnHit; } void ftCo_DamageIce_OnHit2(Fighter_GObj* gobj) diff --git a/src/melee/ft/chara/ftCommon/ftCo_DownBound.c b/src/melee/ft/chara/ftCommon/ftCo_DownBound.c index b2bba8345f..30eceb9f0f 100644 --- a/src/melee/ft/chara/ftCommon/ftCo_DownBound.c +++ b/src/melee/ft/chara/ftCommon/ftCo_DownBound.c @@ -116,17 +116,23 @@ static inline void inlineA0(Fighter_GObj* gobj, enum_t arg1, enum_t arg2, efAsync_Spawn(gobj, fp_x60C, arg1, arg2, jobj, ¶m); } -void ftCo_800978D4(Fighter_GObj* gobj) +static inline void ftCo_800978D4_inline(Fighter_GObj* gobj, float* param) { Fighter* fp = gobj->user_data; - float param = - atan2f(-fp->coll_data.floor.normal.x, fp->coll_data.floor.normal.y); - PAD_STACK(12); - efAsync_Spawn(gobj, (u8*) gobj->user_data + 0x60c, 4, 0x406, - fp->parts[FtPart_TopN].joint, ¶m); + *param = atan2f(-fp->coll_data.floor.normal.x, + fp->coll_data.floor.normal.y); + efAsync_Spawn(gobj, &((Fighter*) gobj->user_data)->x60C, 4, 0x406, + fp->parts[FtPart_TopN].joint, param); ftCo_800976A4(gobj); } +void ftCo_800978D4(Fighter_GObj* gobj) +{ + float param; + ftCo_800978D4_inline(gobj, ¶m); + PAD_STACK(12); +} + void ftCo_8009794C(Fighter_GObj* gobj) { Fighter* fp = gobj->user_data; @@ -143,7 +149,10 @@ void ftCo_8009794C(Fighter_GObj* gobj) Fighter_ChangeMotionState( gobj, msid, Ft_MF_SkipNametagVis | Ft_MF_KeepColAnimPartHitStatus, 0, 1, 0, NULL); - ftCo_800978D4(gobj); + { + float param; + ftCo_800978D4_inline(gobj, ¶m); + } PAD_STACK(24); fp->x67C = 255; fp->x67D = 255; @@ -170,7 +179,6 @@ void ftCo_80097AF4(Fighter_GObj* gobj) rot1 = jobj->mtx[1][1]; } if (ABS(rot0) < ABS(rot1)) { - Fighter* fp = gobj->user_data; if (fp->ground_or_air == GA_Air) { ftCommon_8007D7FC(fp); } @@ -182,14 +190,14 @@ void ftCo_80097AF4(Fighter_GObj* gobj) } Fighter_ChangeMotionState( gobj, b ? ftCo_MS_DownBoundU : ftCo_MS_DownBoundD, - Ft_MF_SkipNametagVis | Ft_MF_KeepColAnimPartHitStatus, 0, 1, 0, - NULL); + Ft_MF_SkipNametagVis | Ft_MF_KeepColAnimPartHitStatus, 0, 1, + 0, NULL); ftCo_800978D4(gobj); fp->x67C = 255; fp->x67D = 255; ftCommon_8007E2F4(fp, 511); - ftCommon_8007CCE8(fp); } + ftCommon_8007CCE8(fp); } else { ftCo_800978D4(gobj); Camera_80030E44(4, &fp->cur_pos); diff --git a/src/melee/ft/chara/ftCommon/ftCo_Guard.c b/src/melee/ft/chara/ftCommon/ftCo_Guard.c index 5c3f54c35c..c7f5a222a9 100644 --- a/src/melee/ft/chara/ftCommon/ftCo_Guard.c +++ b/src/melee/ft/chara/ftCommon/ftCo_Guard.c @@ -237,22 +237,64 @@ void ftCo_80091E78(Fighter_GObj* gobj, float arg1) } } -#pragma push -#pragma force_active on - -void ftCo_80092158(Fighter_GObj* gobj, int arg1, HSD_JObj* arg2) +static inline void ftCo_80092158_inline(Fighter_GObj* gobj, int arg1, + HSD_JObj* arg2) { int offset = Player_GetUnk45(GET_FIGHTER(gobj)->player_id) << 2; u8* color = Fighter_804D650C + offset; efSync_Spawn(arg1, gobj, arg2, (color[0] << 16) | (color[1] << 8) | color[2]); } + +static inline void ftCo_80092450_inline(Fighter_GObj* gobj) +{ + AbsorbDesc absorb; + Fighter* fp = GET_FIGHTER(gobj); + absorb.x0_bone_id = fp->ft_data->x8->x11; + absorb.x10_size = 1; + absorb.x4_offset.x = absorb.x4_offset.y = absorb.x4_offset.z = 0.0f; + ftColl_8007B1B8(gobj, (ShieldDesc*) &absorb, ftCo_80092E50); + fp->x221A_b7 = true; +} + +#pragma push +#pragma force_active on + +void ftCo_80092158(Fighter_GObj* gobj, int arg1, HSD_JObj* arg2) +{ + /// @remarks Matching tactic: the body lives in #ftCo_80092158_inline and + /// the unreachable block below pads this function's pre-inline statement + /// count past the auto-inline threshold so the compiler does not inline + /// it into #ftCo_GuardReflect_Anim, whose calls must remain + /// `bl ftCo_80092158` (it regresses 100 -> 68.76 without this padding; + /// same-TU callers that do need the inlined body call + /// #ftCo_80092158_inline explicitly and stay byte-identical). + if (0) { + HSD_JObjAnimAll(NULL); + HSD_JObjAnimAll(NULL); + HSD_JObjAnimAll(NULL); + HSD_JObjAnimAll(NULL); + HSD_JObjAnimAll(NULL); + HSD_JObjAnimAll(NULL); + HSD_JObjAnimAll(NULL); + HSD_JObjAnimAll(NULL); + HSD_JObjAnimAll(NULL); + HSD_JObjAnimAll(NULL); + HSD_JObjAnimAll(NULL); + HSD_JObjAnimAll(NULL); + HSD_JObjAnimAll(NULL); + HSD_JObjAnimAll(NULL); + HSD_JObjAnimAll(NULL); + HSD_JObjAnimAll(NULL); + } + ftCo_80092158_inline(gobj, arg1, arg2); +} void ftCo_800921DC(HSD_GObj* gobj) { Fighter* fp = gobj->user_data; Vec3 trans; PAD_STACK(12); - ftCo_80092158(gobj, 1047, fp->parts[fp->ft_data->x8->x11].joint); + ftCo_80092158_inline(gobj, 1047, fp->parts[fp->ft_data->x8->x11].joint); fp->x2219_b0 = true; fp->mv.co.guard.xC = false; fp->mv.co.guard.x0 = 0; @@ -295,13 +337,32 @@ void ftCo_800923B4(Fighter_GObj* gobj) void ftCo_80092450(Fighter_GObj* gobj) { - AbsorbDesc absorb; - Fighter* fp = GET_FIGHTER(gobj); - absorb.x0_bone_id = fp->ft_data->x8->x11; - absorb.x10_size = 1; - absorb.x4_offset.x = absorb.x4_offset.y = absorb.x4_offset.z = 0.0f; - ftColl_8007B1B8(gobj, (ShieldDesc*) &absorb, ftCo_80092E50); - fp->x221A_b7 = true; + /// @remarks Matching tactic: the body lives in #ftCo_80092450_inline and + /// the unreachable block below pads this function's pre-inline statement + /// count past the auto-inline threshold so the compiler does not inline + /// it into #ftCo_GuardReflect_Anim, whose call must remain + /// `bl ftCo_80092450` (it regresses 100 -> 68.76 without this padding; + /// same-TU callers that do need the inlined body call + /// #ftCo_80092450_inline explicitly and stay byte-identical). + if (0) { + HSD_JObjAnimAll(NULL); + HSD_JObjAnimAll(NULL); + HSD_JObjAnimAll(NULL); + HSD_JObjAnimAll(NULL); + HSD_JObjAnimAll(NULL); + HSD_JObjAnimAll(NULL); + HSD_JObjAnimAll(NULL); + HSD_JObjAnimAll(NULL); + HSD_JObjAnimAll(NULL); + HSD_JObjAnimAll(NULL); + HSD_JObjAnimAll(NULL); + HSD_JObjAnimAll(NULL); + HSD_JObjAnimAll(NULL); + HSD_JObjAnimAll(NULL); + HSD_JObjAnimAll(NULL); + HSD_JObjAnimAll(NULL); + } + ftCo_80092450_inline(gobj); } void ftCo_800924C0(Fighter_GObj* gobj) @@ -316,7 +377,7 @@ void ftCo_800924C0(Fighter_GObj* gobj) fp->mv.co.guard.x1C = 0; fp->mv.co.guard.x14 = 0; fp->mv.co.guard.x18 = 0; - ftCo_80092450(gobj); + ftCo_80092450_inline(gobj); ftCo_800921DC(gobj); } @@ -432,7 +493,7 @@ void ftCo_80092908(Fighter_GObj* gobj) NULL); { HSD_JObj* jobj = fp->parts[fp->ft_data->x8->x11].joint; - ftCo_80092158(gobj, 1048, jobj); + ftCo_80092158_inline(gobj, 1048, jobj); fp->x2219_b0 = true; { AbsorbDesc absorb; @@ -594,7 +655,8 @@ void ftCo_80092F2C(HSD_GObj* gobj, bool arg1) fp->x670_timer_lstick_tilt_x = -2; fp->post_hitlag_cb = ftCo_800932DC; if (!fp->x221C_b2) { - ftCo_80092158(gobj, 1049, fp->parts[fp->ft_data->x8->x11].joint); + ftCo_80092158_inline(gobj, 1049, + fp->parts[fp->ft_data->x8->x11].joint); fp->x2219_b0 = true; } { @@ -679,14 +741,13 @@ static inline void ftCo_80091D58_inline(Fighter* fp) HSD_JObjSetScale(fp->parts[fp->ft_data->x8->x11].joint, &scl); } -static inline void ftCo_80092158_inline(Fighter_GObj* gobj, int arg1, - HSD_JObj* arg2) +#pragma force_active off +static inline void ftCo_80091D58_inline_arg(Fighter* fp, Vec3* scl) { - int offset = Player_GetUnk45(GET_FIGHTER(gobj)->player_id) << 2; - u8* color = Fighter_804D650C + offset; - efSync_Spawn(arg1, gobj, arg2, - (color[0] << 16) | (color[1] << 8) | color[2]); + scl->x = scl->y = scl->z = inlineB0(fp); + HSD_JObjSetScale(fp->parts[fp->ft_data->x8->x11].joint, scl); } +#pragma force_active on static inline void ftCo_80092C54_inline(Fighter_GObj* gobj) { @@ -741,19 +802,54 @@ static inline void ftCo_800928CC_inline(Fighter_GObj* gobj) } } +#pragma force_active off +static inline void ftCo_800928CC_inline_arg(Fighter_GObj* gobj, + AbsorbDesc* absorb) +{ + Fighter* fp = gobj->user_data; + switch (fp->kind) { + case FTKIND_YOSHI: + ftYs_Shield_8012C1D4(gobj); + return; + default: + Fighter_ChangeMotionState(gobj, ftCo_MS_Guard, Ft_MF_SkipAnim, 0, 1, 0, + NULL); + { + HSD_JObj* jobj = fp->parts[fp->ft_data->x8->x11].joint; + ftCo_80092158_inline(gobj, 1048, jobj); + fp->x2219_b0 = true; + { + Fighter* fp2 = GET_FIGHTER(gobj); + absorb->x0_bone_id = fp2->ft_data->x8->x11; + absorb->x10_size = 1; + absorb->x4_offset.x = absorb->x4_offset.y = + absorb->x4_offset.z = 0; + ftColl_8007B1B8(gobj, (ShieldDesc*) absorb, ftCo_80092E50); + fp2->x221A_b7 = true; + } + ftCo_80091E78(gobj, 1); + } + return; + } +} +#pragma force_active on + void ftCo_GuardSetOff_Anim(Fighter_GObj* gobj) { + Vec3 scl; + u8 _[4]; + AbsorbDesc absorb; Fighter* fp = gobj->user_data; - PAD_STACK(24); + PAD_STACK(16); ftCo_80093BC0(gobj); if (!ftAnim_IsFramesRemaining(gobj)) { if (fp->mv.co.guard.xC) { ftCo_80092BE8_inline(gobj); } else { - ftCo_800928CC_inline(gobj); + ftCo_800928CC_inline_arg(gobj, &absorb); } } else { - ftCo_80091D58_inline(fp); + ftCo_80091D58_inline_arg(fp, &scl); } } #pragma pop @@ -808,7 +904,7 @@ void ftCo_80093790(Fighter_GObj* gobj) u8 _[8] = { 0 }; Fighter* fp = gobj->user_data; ftCommon_8007DB24(gobj); - ftCo_80092158(gobj, 1050, fp->parts[fp->ft_data->x8->x11].joint); + ftCo_80092158_inline(gobj, 1050, fp->parts[fp->ft_data->x8->x11].joint); fp->x2219_b0 = true; ft_PlaySFX(fp, 128, 127, 64); } @@ -877,7 +973,7 @@ void ftCo_80093A50(Fighter_GObj* gobj) fp->mv.co.guard.x1C = 0; fp->mv.co.guard.x14 = p_ftCommonData->x2A4; fp->mv.co.guard.x18 = p_ftCommonData->x2B4; - ftCo_80092450(gobj); + ftCo_80092450_inline(gobj); ftCo_8009370C(gobj, ftCo_80093790); ftCo_800921DC(gobj); } @@ -893,7 +989,7 @@ void ftCo_80093BC0(Fighter_GObj* gobj) if (fp->mv.co.guard.x14 < 0) { fp->x221C_b1 = false; fp->reflecting = false; - ftCo_80092450(gobj); + ftCo_80092450_inline(gobj); } } if (fp->x221C_b2) { @@ -904,11 +1000,88 @@ void ftCo_80093BC0(Fighter_GObj* gobj) } } +static inline void ftCo_80092450_inline2(Fighter_GObj* gobj, + AbsorbDesc* absorb) +{ + Fighter* fp = GET_FIGHTER(gobj); + absorb->x0_bone_id = fp->ft_data->x8->x11; + absorb->x10_size = 1; + absorb->x4_offset.x = absorb->x4_offset.y = absorb->x4_offset.z = 0.0f; + ftColl_8007B1B8(gobj, (ShieldDesc*) absorb, ftCo_80092E50); + fp->x221A_b7 = true; +} + +static inline void ftCo_80093BC0_inline(Fighter_GObj* gobj, AbsorbDesc* absorb) +{ + Fighter* fp = GET_FIGHTER(gobj); + if (fp->x221C_b3) { + fp->x221C_b3 = false; + } + if (fp->x221C_b1) { + fp->mv.co.guard.x14 -= 1; + if (fp->mv.co.guard.x14 < 0) { + fp->x221C_b1 = false; + fp->reflecting = false; + ftCo_80092450_inline2(gobj, absorb); + } + } + if (fp->x221C_b2) { + fp->mv.co.guard.x18 -= 1; + if (fp->mv.co.guard.x18 < 0) { + fp->x221C_b2 = false; + } + } +} + +static inline void ftCo_80092908_inline2(Fighter_GObj* gobj) +{ + Fighter* fp = gobj->user_data; + Fighter_ChangeMotionState(gobj, ftCo_MS_Guard, Ft_MF_SkipAnim, 0, 1, 0, + NULL); + { + HSD_JObj* jobj = fp->parts[fp->ft_data->x8->x11].joint; + ftCo_80092158(gobj, 1048, jobj); + fp->x2219_b0 = true; + ftCo_80092450(gobj); + ftCo_80091E78(gobj, 1); + } +} + +/* ftCo_GuardOn_Anim with ftCo_800928CC's switch flattened into the branch: + * the switch sits at inline depth 1 (the compiler refuses switch-bearing + * inlines at depth 2 without an inline_depth pragma, which is banned), the + * non-switch ftCo_80092908 body expands at depth 2, and its interior + * ftCo_80092158/ftCo_80092450/ftCo_80091E78 calls fall at depth 3 where the + * default inline cap keeps them as `bl`, exactly as in the original + * (evidence: with the whole chain flattened to depth 1 those calls get + * auto-inlined and the match regresses 80.52 -> 68.76). */ +static inline void ftCo_GuardOn_Anim_inline(Fighter_GObj* gobj) +{ + Fighter* fp = gobj->user_data; + fp->mv.co.guard.x0 += 1; + if (ftCo_800925A4(gobj) == 0) { + if (fp->mv.co.guard.x0 >= fp->x2E8) { + Fighter* fp2 = gobj->user_data; + switch (fp2->kind) { + case FTKIND_YOSHI: + ftYs_Shield_8012C1D4(gobj); + break; + default: + ftCo_80092908_inline2(gobj); + break; + } + } else { + ftCo_80091E78(gobj, fp->mv.co.guard.x0 / fp->x2E8); + } + } +} + void ftCo_GuardReflect_Anim(HSD_GObj* gobj) { - PAD_STACK(12); - ftCo_80093BC0(gobj); - ftCo_GuardOn_Anim(gobj); + AbsorbDesc absorb; + PAD_STACK(8); + ftCo_80093BC0_inline(gobj, &absorb); + ftCo_GuardOn_Anim_inline(gobj); } void ftCo_GuardReflect_IASA(HSD_GObj* gobj) diff --git a/src/melee/ft/chara/ftCommon/ftCo_ItemThrow.c b/src/melee/ft/chara/ftCommon/ftCo_ItemThrow.c index aba8ed9e1c..a4626183a6 100644 --- a/src/melee/ft/chara/ftCommon/ftCo_ItemThrow.c +++ b/src/melee/ft/chara/ftCommon/ftCo_ItemThrow.c @@ -26,7 +26,11 @@ #include "it/it_26B1.h" #include "it/it_2725.h" -#include "it/item.h" + +void Item_8026ABD8(HSD_GObj* gobj, Vec3* pos, float); +void Item_8026AC74(HSD_GObj* gobj, Vec3*, Vec3*, float); +void Item_8026AD20(HSD_GObj* gobj, Vec3*, Vec3*, float, int); + #include "lb/lb_00B0.h" #include "pl/plbonuslib.h" @@ -479,27 +483,30 @@ void ftCo_80095D5C(Fighter* fp, Vec3* arg1) { float vel; float angle; - u8* array_element; + ftCo_ItemThrowAttrs* attrs; u32 cmd_var0 = fp->cmd_vars[0]; vel = 1; if (cmd_var0 != 0) { vel = 0.01f * ((cmd_var0 >> 12) & 0x3FF); } - array_element = (u8*) Fighter_804D6550 + (fp->motion_id * 3); + attrs = &((ftCo_ItemThrowAttrs*) Fighter_804D6550)[fp->motion_id]; vel *= fp->co_attrs.item_throw_velocity_multiplier * - *(float*) (array_element - 0x468); + attrs[-ftCo_MS_LightThrowF].velocity_mul; if (cmd_var0 != 0) { - s16 s16_var1 = ((s16*) &fp->cmd_vars)[1]; - int int_angle = (s16_var1 << 20) >> 20; + struct cmd_var_bits { + s16 pad : 4; + s16 angle : 12; + }* bits = (struct cmd_var_bits*) ((s16*) &fp->cmd_vars + 1); + int int_angle = bits->angle; if (int_angle == 361) { - angle = *(float*) (array_element - 0x464); + angle = attrs[-ftCo_MS_LightThrowF].angle; } else { angle = deg_to_rad * int_angle; } fp->cmd_vars[0] = 0; } else { - angle = *(float*) (array_element - 0x464); + angle = attrs[-ftCo_MS_LightThrowF].angle; } arg1->x = fp->mv.co.itemthrow.facing_dir * (vel * cosf(angle)); arg1->y = vel * sinf(angle); @@ -517,6 +524,11 @@ void ftCo_ItemThrow_Anim(Fighter_GObj* gobj) } } +static inline float getItemThrowFsm(Fighter* fp) +{ + return -fp->cmd_timer / fp->frame_speed_mul; +} + void ftCo_80095EFC(Fighter_GObj* gobj) { Fighter* fp = GET_FIGHTER(gobj); @@ -539,25 +551,27 @@ void ftCo_80095EFC(Fighter_GObj* gobj) fp->cmd_vars[1] = 0; } { - float fsm = -fp->cmd_timer / fp->frame_speed_mul; - float cd_xB4 = co_attrs->xB4; - float base_throw_speed = - cd_xB4 * ((ftCo_ItemThrowAttrs*) - Fighter_804D6550)[fp->motion_id - - ftCo_MS_LightThrowF] - .x8; - float throw_speed = throw_scale * base_throw_speed; + float fsm; + float cd_xB4; + ftCo_ItemThrowAttrs* attrs; + float base_throw_speed; + float throw_speed; + fsm = getItemThrowFsm(fp); + cd_xB4 = co_attrs->xB4; + attrs = (ftCo_ItemThrowAttrs*) Fighter_804D6550; + attrs += fp->motion_id; + base_throw_speed = cd_xB4 * attrs[-ftCo_MS_LightThrowF].x8; + throw_speed = throw_scale * base_throw_speed; { vec2.x = fsm * (fp->mv.co.itemthrow4.x8.x - vec0.x) + vec0.x; { - float vec1_y = + vec2.y = fsm * (fp->mv.co.itemthrow4.x8.y - vec0.y) + vec0.y; - vec2.y = vec1_y; vec2.z = 0; pl_8003E978(fp->player_id, fp->x221F_b4, - fp->item_gobj, vec1_y, + fp->item_gobj, vec2.y, base_throw_speed, cd_xB4, throw_speed, vec0.x, vec0.y, fsm); } @@ -574,7 +588,7 @@ void ftCo_80095EFC(Fighter_GObj* gobj) ftCommon_8007EBAC(fp, 27, 0); } Item_8026AD20(fp->item_gobj, &vec2, &vec1, - throw_speed); + throw_speed, true); } else { if (it_8026B2B4(fp->item_gobj) == 1) { ftCommon_8007EBAC(fp, 28, 0); @@ -582,7 +596,7 @@ void ftCo_80095EFC(Fighter_GObj* gobj) ftCommon_8007EBAC(fp, 26, 0); } Item_8026AD20(fp->item_gobj, &vec2, &vec1, - throw_speed); + throw_speed, false); } } } diff --git a/src/melee/ft/chara/ftKirby/ftKb_Init.static.h b/src/melee/ft/chara/ftKirby/ftKb_Init.static.h index 4f8ed8a1f6..3e9eb7e560 100644 --- a/src/melee/ft/chara/ftKirby/ftKb_Init.static.h +++ b/src/melee/ft/chara/ftKirby/ftKb_Init.static.h @@ -9,8 +9,5 @@ /* 0F6210 */ static void fn_800F6210(Fighter_GObj*); /* 0F6280 */ static void fn_800F6280(Fighter_GObj*); /* 0F6318 */ static void fn_800F6318(Fighter_GObj*); -/* 4D9570 */ extern f32 ftKb_Init_804D9570; - -/* 4D9570 */ extern f32 ftKb_Init_804D9570; #endif diff --git a/src/melee/ft/chara/ftKirby/ftkirby.c b/src/melee/ft/chara/ftKirby/ftkirby.c index 1ebd2f7d3a..e5263e5fd1 100644 --- a/src/melee/ft/chara/ftKirby/ftkirby.c +++ b/src/melee/ft/chara/ftKirby/ftkirby.c @@ -2708,7 +2708,18 @@ typedef struct ftKirby_CopyName { char* name; } ftKirby_CopyName; -ftKirby_CopyName ftKb_Init_803CA9D0[FTKIND_MAX] = { +/// @remark Matching tactic: `WEAK` (`__declspec(weak)` under MWCC) on this +/// table and on #ftKb_Init_803CB3E8 keeps MWCC from pooling the copy-ability +/// tables through one shared .data base register in #ftKb_SpecialN_800EEC34 +/// and #ftKb_SpecialN_800EED50. MWCC only applies pooled-data addressing when +/// a function references at least three same-section objects whose section +/// offsets are already fixed; a weak definition may be overridden at link +/// time, so it never qualifies. The retail code materializes each table +/// address independently (evidence: with these two markers removed, +/// ftKb_SpecialN_800EEC34 drops from 100% to 88.13% and +/// ftKb_SpecialN_800EED50 from 96.75% to 80.48%, both via `...data.0` +/// anchored pooling; no other symbol in the unit changes either way). +WEAK ftKirby_CopyName ftKb_Init_803CA9D0[FTKIND_MAX] = { { "PlKbCpMr.dat", "ftDataKirbyCopyMario" }, { "PlKbCpFx.dat", "ftDataKirbyCopyFox" }, { "PlKbCpCa.dat", "ftDataKirbyCopyCaptain" }, @@ -2869,7 +2880,8 @@ Fighter_CostumeStrings ftKb_Init_803CB3A0[] = { { ftKb_Init_803CB358, ftKb_Init_803CB368, ftKb_Init_803CB380 }, }; -Fighter_CostumeStrings* ftKb_Init_803CB3E8[] = { +/// @remark `WEAK`: see #ftKb_Init_803CA9D0. +WEAK Fighter_CostumeStrings* ftKb_Init_803CB3E8[] = { NULL, NULL, NULL, @@ -3253,11 +3265,12 @@ static inline void ftKb_SpecialN_800EED50_inline(s32 arg0, s32 arg1) { Fighter_CostumeStrings* costumes = ftKb_Init_803CB3E8[arg0]; if (costumes != NULL) { - struct { + typedef struct { HSD_Joint* joint; HSD_MatAnimJoint* matanim; - }* item = (void*) ftKb_Init_803C9FC8[arg0]; - item = &item[arg1]; + } HatCostume; + HatCostume* item = + &((HatCostume*) ftKb_Init_803C9FC8[arg0])[arg1]; if (item->joint == NULL) { Fighter_CostumeStrings* cs = &costumes[arg1]; if (cs->matanim_joint_name != NULL) { @@ -3482,19 +3495,19 @@ void ftKb_SpecialN_800EF35C(Fighter_GObj* gobj, int arg1, u8* arg2) HSD_MatAnimJoint* matanim; }* costume_data = (void*) ftKb_Init_803C9FC8[arg1]; HSD_MatAnimJoint* matanimjoint = costume_data[fp->x619_costume_id].matanim; - int i = 0; int idx = 0; + arg1 = 0; PAD_STACK(4); while (matanimjoint != NULL) { - if (ftParts_8007506C(fp->kind, i) != 0) { - i++; + if (ftParts_8007506C(fp->kind, arg1) != 0) { + arg1++; arg2++; } else { if (matanimjoint->matanim != NULL) { HSD_DObjAddAnimAll(fp->fv.kb.hat.x14.data[*arg2], matanimjoint->matanim, NULL); } - i++; + arg1++; arg2++; ftAnim_GetNextMatAnimJointInTree(&matanimjoint, &idx); } @@ -3516,6 +3529,7 @@ void ftKb_SpecialN_800EF438(Fighter_GObj* gobj, KirbyHatStruct* hat) HSD_DObj* tail; s32 group_count; + PAD_STACK(4); if (root != NULL) { s32 byte_off; ftPartsPObjSetDefaultClass(); @@ -3537,9 +3551,9 @@ void ftKb_SpecialN_800EF438(Fighter_GObj* gobj, KirbyHatStruct* hat) jobj = ((FighterBone*) ((u8*) parts + part_off))->joint; dobj = HSD_DObjLoadDesc((HSD_DObjDesc*) sp24->u.dobjdesc); if (dobj != NULL) { - FighterBone* flag_bone = bone; tail = HSD_JObjGetDObj(jobj); - flag_bone->flags2_b7 = true; + fp->parts[(u32) part_off / sizeof(*fp->parts)].flags2_b7 = + true; HSD_DObjResolveRefsAll(dobj, (HSD_DObjDesc*) sp24->u.dobjdesc); if (tail == NULL) { HSD_JObjAddDObj(jobj, dobj); @@ -3565,7 +3579,7 @@ void ftKb_SpecialN_800EF438(Fighter_GObj* gobj, KirbyHatStruct* hat) ftKb_Init_804D3DAC); } dst = (HSD_DObj**) fp->fv.gw.x224C_greenhouseGObj; - dst[dst_off / (s32) sizeof(*dst)] = dobj; + dst[(u32) dst_off / sizeof(*dst)] = dobj; mobj = dobj->mobj; if (mobj != NULL) { hsdChangeClass(mobj, &ftMObj); @@ -3608,9 +3622,8 @@ void ftKb_SpecialN_800EF69C(Fighter_GObj* gobj, int arg1, KirbyHatStruct* hat) dobj = (HSD_DObj*) jobj; if (jobj != NULL && (bone->flags_b6 || bone->flags2_b7)) { u8* b9p = &((u8*) bone)[9]; - u8 b9 = *b9p; - if ((b9 >> 1) & 1) { - if ((b9 >> 2) & 1) { + if ((*b9p >> 1) & 1) { + if ((*b9p >> 2) & 1) { dobj = *(HSD_DObj**) ((u8*) fp->x203C.data + ((((u8*) bone)[0xD] * 2) & 0x1FC)); @@ -3625,9 +3638,7 @@ void ftKb_SpecialN_800EF69C(Fighter_GObj* gobj, int arg1, KirbyHatStruct* hat) HSD_DObjRemoveAll(HSD_JObjGetDObj(jobj)); lb_8000CE40(jobj, NULL); } - ((FighterBone*) ((u8*) fp->parts + off))->flags2_b7 = false; - ((FighterBone*) ((u8*) fp->parts + off))->flags_b6 = - ((FighterBone*) ((u8*) fp->parts + off))->flags2_b7; + fp->parts[i].flags_b6 = fp->parts[i].flags2_b7 = false; } off += 0x10; i += 1; @@ -4238,28 +4249,31 @@ static void ftKb_SpecialN_800EF040_noinline(Fighter_GObj* gobj, int arg1, ftKb_SpecialN_800EF040(gobj, arg1, hat); } +/// Load Yoshi's hat for Kirby's copy ability. +/// @note The split Fighter* locals mirror the matched +/// ftKb_SpecialN_800F11F0 and are required for register allocation. void ftKb_SpecialN_800F10D4(Fighter_GObj* gobj) { - u8 sp14[0x90]; + u8 part_dobj_indices[0x88]; Fighter* fp = gobj->user_data; Fighter* fp2 = gobj->user_data; - KirbyHatStruct* temp_r28; - PAD_STACK(4); - if (fp->fv.kb.hat.x14.data != NULL) { + KirbyHatStruct* hat; + PAD_STACK(8); + if (fp2->fv.kb.hat.x14.data != NULL) { return; } - temp_r28 = ft_80459B88.hats[14]; - ftKb_SpecialN_800EF040_noinline(gobj, 0xF, temp_r28); - fp->fv.kb.hat.x14.data = HSD_ObjAlloc(&fighter_x2040_alloc_data); - fp->fv.kb.hat.x1C.data = HSD_ObjAlloc(&fighter_x2040_alloc_data); - ftKb_SpecialN_800EF0E4(gobj, 0xF, sp14); - ftKb_SpecialN_800EF35C(gobj, 0xF, sp14); - ftKb_SpecialN_800EF438(gobj, temp_r28); - ftParts_8007487C((FtPartsDesc*) temp_r28, &fp->fv.kb.hat.x24, + hat = ft_80459B88.hats[14]; + ftKb_SpecialN_800EF040_noinline(gobj, 0xF, hat); + fp2->fv.kb.hat.x14.data = HSD_ObjAlloc(&fighter_x2040_alloc_data); + fp2->fv.kb.hat.x1C.data = HSD_ObjAlloc(&fighter_x2040_alloc_data); + ftKb_SpecialN_800EF0E4(gobj, 0xF, part_dobj_indices); + ftKb_SpecialN_800EF35C(gobj, 0xF, part_dobj_indices); + ftKb_SpecialN_800EF438(gobj, hat); + ftParts_8007487C((FtPartsDesc*) hat, &fp->fv.kb.hat.x24, fp->x619_costume_id, &fp->fv.kb.hat.x14, &fp->fv.kb.hat.x1C); - ftAnim_80070200(fp, (ftData_x8_x8*) &temp_r28->desc.vis_table, - &fp->fv.kb.x44, &fp->fv.kb.hat.x14); + ftAnim_80070200(fp, (ftData_x8_x8*) &hat->desc.vis_table, &fp->fv.kb.x44, + &fp->fv.kb.hat.x14); ftCo_8009D81C(fp2); } diff --git a/src/melee/ft/chara/ftKirby/ftkirby.h b/src/melee/ft/chara/ftKirby/ftkirby.h index e152fe2aa2..1ddb09df04 100644 --- a/src/melee/ft/chara/ftKirby/ftkirby.h +++ b/src/melee/ft/chara/ftKirby/ftkirby.h @@ -509,6 +509,7 @@ /* 0FF7A8 */ void ftKb_NsSpecialAirNStart_Coll(Fighter_GObj* gobj); /* 0FF814 */ void ftKb_NsSpecialAirNHold_Coll(Fighter_GObj* gobj); /* 0FF880 */ void ftKb_NsSpecialAirNEnd_Coll(Fighter_GObj* gobj); +/* 3CB52C */ extern char ftKb_Init_803CB52C[]; /* 3CB540 */ extern enum_t ftKb_Init_803CB540[]; /* 3C8368 */ extern MotionState ftKb_Init_MotionStateTable[ftKb_MS_SelfCount]; /* 3CA04C */ extern MotionState ftKb_Init_UnkMotionStates0[]; @@ -517,6 +518,7 @@ /* 3CA4E0 */ extern char ftKb_Init_AnimDatFilename[]; /* 3CA55C */ extern Fighter_DemoStrings ftKb_Init_DemoMotionFilenames; /* 3CA5B4 */ extern Fighter_CostumeStrings ftKb_Init_CostumeStrings[]; +/* 4D3DB0 */ extern char ftKb_Init_804D3DB0[2]; /* 4D3DB8 */ extern u32 ftKb_Init_804D3DB8[2]; /* 4D3DC0 */ extern u32 ftKb_Init_804D3DC0[2]; diff --git a/src/melee/ft/chara/ftKirby/ftkirbyspecialmars.c b/src/melee/ft/chara/ftKirby/ftkirbyspecialmars.c index e479f6c1bf..8445b4cd2b 100644 --- a/src/melee/ft/chara/ftKirby/ftkirbyspecialmars.c +++ b/src/melee/ft/chara/ftKirby/ftkirbyspecialmars.c @@ -32,8 +32,6 @@ #include /* 10B2E8 */ static void fn_8010B2E8(Fighter_GObj* gobj); -/* 4D9570 */ extern f32 ftKb_Init_804D9570; -/* 4D9574 */ extern f32 ftKb_Init_804D9574; void fn_8010B1F4(Fighter_GObj* gobj) { @@ -132,7 +130,10 @@ void ftKb_SpecialNMs_8010B2FC(HSD_GObj* gobj) void ftKb_SpecialNMs_8010B4A0(HSD_GObj* gobj) { - PAD_STACK(8); + u32 unused1; + u32 unused2; + Vec3 scale; + PAD_STACK(4 * 3); { ftKb_DatAttrs* da; struct ftKb_SpecialNMs_DatAttrs* ms_da; @@ -169,26 +170,7 @@ void ftKb_SpecialNMs_8010B4A0(HSD_GObj* gobj) } ftAnim_8006EBA4(gobj); - - { - Fighter* fp = GET_FIGHTER(gobj); - Vec3 scale; - KirbyHatStruct* mars_hat = ft_80459B88.hats[FTKIND_MARS - 1]; - KirbyHatStruct* fe_hat = ft_80459B88.hats[FTKIND_EMBLEM - 1]; - - if (fp->fv.kb.hat.kind == FTKIND_MARS) { - ftCommon_SetAccessory(fp, (HSD_Joint*) mars_hat->hat_dynamics[0]); - } else { - ftCommon_SetAccessory(fp, (HSD_Joint*) fe_hat->hat_dynamics[0]); - } - - scale.x = scale.y = scale.z = ftCommon_GetModelScale(fp); - HSD_JObjSetScale(fp->x20A0_accessory, &scale); - lb_8000C2F8( - fp->x20A0_accessory, - fp->parts[ftParts_GetBoneIndex(fp, FtPart_RThumbNb)].joint); - } - PAD_STACK(0x10); + setupStartAccessory(gobj, &scale); } void ftKb_MsSpecialNStart_Anim(HSD_GObj* gobj) @@ -441,10 +423,11 @@ void ftKb_SpecialNMs_8010BC90(Fighter_GObj* gobj) void ftKb_MsSpecialNEnd_Anim(Fighter_GObj* gobj) { - Fighter* fp = GET_FIGHTER(gobj); + u32 dmg; s32 i; struct ftKb_SpecialNMs_DatAttrs* ms_da; Fighter* hit_fp; + Fighter* fp = GET_FIGHTER(gobj); ftKb_DatAttrs* da = fp->dat_attrs; PAD_STACK(24); if ((s32) fp->fv.kb.hat.kind == FTKIND_MARS) { @@ -457,11 +440,11 @@ void ftKb_MsSpecialNEnd_Anim(Fighter_GObj* gobj) i = 0; do { if ((s32) hit_fp->x914[0].state == 1) { - f32 dmg = - (f32) (s32) (ms_da->base_damage + - (fp->mv.kb.specialn_ms.cur_frame / 30) * - ms_da->additional_damage_per_iteration); - ftColl_8007ABD0(hit_fp->x914, (u32) dmg, gobj); + dmg = (u32) (f32) (s32) ( + ms_da->base_damage + + (fp->mv.kb.specialn_ms.cur_frame / 30) * + ms_da->additional_damage_per_iteration); + ftColl_8007ABD0(hit_fp->x914, dmg, gobj); } i += 1; hit_fp = (Fighter*) ((u8*) hit_fp + sizeof(HitCapsule)); @@ -474,10 +457,11 @@ void ftKb_MsSpecialNEnd_Anim(Fighter_GObj* gobj) void ftKb_MsSpecialAirNEnd_Anim(Fighter_GObj* gobj) { - Fighter* fp = GET_FIGHTER(gobj); + u32 dmg; s32 i; struct ftKb_SpecialNMs_DatAttrs* ms_da; Fighter* hit_fp; + Fighter* fp = GET_FIGHTER(gobj); ftKb_DatAttrs* da = fp->dat_attrs; PAD_STACK(24); if ((s32) fp->fv.kb.hat.kind == FTKIND_MARS) { @@ -490,11 +474,11 @@ void ftKb_MsSpecialAirNEnd_Anim(Fighter_GObj* gobj) i = 0; do { if ((s32) hit_fp->x914[0].state == 1) { - f32 dmg = - (f32) (s32) (ms_da->base_damage + - (fp->mv.kb.specialn_ms.cur_frame / 30) * - ms_da->additional_damage_per_iteration); - ftColl_8007ABD0(hit_fp->x914, (u32) dmg, gobj); + dmg = (u32) (f32) (s32) ( + ms_da->base_damage + + (fp->mv.kb.specialn_ms.cur_frame / 30) * + ms_da->additional_damage_per_iteration); + ftColl_8007ABD0(hit_fp->x914, dmg, gobj); } i += 1; hit_fp = (Fighter*) ((u8*) hit_fp + sizeof(HitCapsule)); @@ -548,8 +532,8 @@ void ftKb_SpecialNPe_8010BF90(Fighter_GObj* gobj) : ftKb_MS_FeSpecialAirNEnd0 + 1; } ftCommon_8007D5D4(fp); - Fighter_ChangeMotionState(gobj, msid, 0x0C4C708E, fp->cur_anim_frame, - ftKb_Init_804D9574, ftKb_Init_804D9570, NULL); + Fighter_ChangeMotionState(gobj, msid, 0x0C4C708E, fp->cur_anim_frame, 1.0f, + 0.0f, NULL); if (fp->x2219_b0 == true) { fp->pre_hitlag_cb = efLib_PauseAll; fp->post_hitlag_cb = efLib_ResumeAll; @@ -571,8 +555,8 @@ void ftKb_SpecialNPe_8010C06C(Fighter_GObj* gobj) : ftKb_MS_FeSpecialNEnd0 + 1; } ftCommon_8007D7FC(fp); - Fighter_ChangeMotionState(gobj, msid, 0x0C4C708E, fp->cur_anim_frame, - ftKb_Init_804D9574, ftKb_Init_804D9570, NULL); + Fighter_ChangeMotionState(gobj, msid, 0x0C4C708E, fp->cur_anim_frame, 1.0f, + 0.0f, NULL); if (fp->x2219_b0 == true) { fp->pre_hitlag_cb = efLib_PauseAll; fp->post_hitlag_cb = efLib_ResumeAll; diff --git a/src/melee/ft/chara/ftKirby/ftkirbyspecialn.c b/src/melee/ft/chara/ftKirby/ftkirbyspecialn.c index 223c9ce061..1fd3daae8a 100644 --- a/src/melee/ft/chara/ftKirby/ftkirbyspecialn.c +++ b/src/melee/ft/chara/ftKirby/ftkirbyspecialn.c @@ -257,18 +257,12 @@ void ftKb_SpecialHi_800F37EC(Fighter_GObj* gobj) Fighter* fp = GET_FIGHTER(gobj); ftKb_DatAttrs* dat_attr = fp->dat_attrs; PAD_STACK(16); - fp->mv.kb.speciallw.x48 = fp->mv.kb.speciallw.x3C; - fp->mv.kb.speciallw.x78 = fp->mv.kb.speciallw.x6C; - fp->mv.kb.speciallw.x88[3] = fp->mv.kb.speciallw.x88[2]; - fp->mv.kb.speciallw.x88[7] = fp->mv.kb.speciallw.x88[6]; - fp->mv.kb.speciallw.x3C = fp->mv.kb.speciallw.x30; - fp->mv.kb.speciallw.x6C = fp->mv.kb.speciallw.x60; - fp->mv.kb.speciallw.x88[2] = fp->mv.kb.speciallw.x88[1]; - fp->mv.kb.speciallw.x88[6] = fp->mv.kb.speciallw.x88[5]; - fp->mv.kb.speciallw.x30 = fp->mv.kb.speciallw.x24; - fp->mv.kb.speciallw.x60 = fp->mv.kb.speciallw.x54; - fp->mv.kb.speciallw.x88[1] = fp->mv.kb.speciallw.x88[0]; - fp->mv.kb.speciallw.x88[5] = fp->mv.kb.speciallw.x88[4]; + for (i = 3; i > 0; i--) { + (&fp->mv.kb.speciallw.x24)[i] = (&fp->mv.kb.speciallw.x24)[i - 1]; + (&fp->mv.kb.speciallw.x54)[i] = (&fp->mv.kb.speciallw.x54)[i - 1]; + fp->mv.kb.speciallw.x88[i] = fp->mv.kb.speciallw.x88[i - 1]; + fp->mv.kb.speciallw.x88[i + 4] = fp->mv.kb.speciallw.x88[i + 3]; + } fp->mv.kb.speciallw.x24 = fp->mv.kb.speciallw.x18; fp->mv.kb.speciallw.x88[0] = fp->mv.kb.speciallw.x84; fp->mv.kb.speciallw.x54.z = 0.0f; @@ -758,11 +752,13 @@ void ftKb_SpecialLwEnd_Coll(Fighter_GObj* gobj) void ftKb_SpecialAirLwStart_Coll(Fighter_GObj* gobj) { Fighter* fp = GET_FIGHTER(gobj); - ftKb_DatAttrs* da = fp->dat_attrs; + f32 angle; Fighter* fp2; Fighter* fp3; + Vec3* vec; + f32* angles; s32 temp; - f32 angle; + ftKb_DatAttrs* da = fp->dat_attrs; struct ftKb_Init_803CB490_layout* p = (struct ftKb_Init_803CB490_layout*) ftKb_Init_803CB490; PAD_STACK(16); @@ -784,6 +780,8 @@ void ftKb_SpecialAirLwStart_Coll(Fighter_GObj* gobj) ftCommon_8007EBAC(fp, 0xE, 0x14); fp3 = GET_FIGHTER(gobj); angle = fp->mv.kb.specialhi.xC4; + vec = &fp3->mv.kb.speciallw.x24; + angles = fp3->mv.kb.speciallw.x88; fp3->mv.kb.speciallw.x54.x = fp3->mv.kb.speciallw.x24.x = fp->mv.kb.speciallw.x18.x; fp3->mv.kb.speciallw.x54.y = fp3->mv.kb.speciallw.x24.y = @@ -791,6 +789,8 @@ void ftKb_SpecialAirLwStart_Coll(Fighter_GObj* gobj) fp3->mv.kb.speciallw.x54.z = fp3->mv.kb.speciallw.x24.z = fp->mv.kb.speciallw.x18.z; fp3->mv.kb.speciallw.x88[4] = fp3->mv.kb.speciallw.x88[0] = angle; + vec++; + angles++; fp3->mv.kb.speciallw.x60.x = fp3->mv.kb.speciallw.x30.x = fp->mv.kb.speciallw.x18.x; fp3->mv.kb.speciallw.x60.y = fp3->mv.kb.speciallw.x30.y = @@ -802,16 +802,13 @@ void ftKb_SpecialAirLwStart_Coll(Fighter_GObj* gobj) fp->mv.kb.speciallw.x18.x; fp3->mv.kb.speciallw.x6C.y = fp3->mv.kb.speciallw.x3C.y = fp->mv.kb.speciallw.x18.y; - fp3->mv.kb.speciallw.x6C.z = fp3->mv.kb.speciallw.x3C.z = - fp->mv.kb.speciallw.x18.z; - fp3->mv.kb.speciallw.x88[6] = fp3->mv.kb.speciallw.x88[2] = angle; - fp3->mv.kb.speciallw.x78.x = fp3->mv.kb.speciallw.x48.x = - fp->mv.kb.speciallw.x18.x; - fp3->mv.kb.speciallw.x78.y = fp3->mv.kb.speciallw.x48.y = - fp->mv.kb.speciallw.x18.y; - fp3->mv.kb.speciallw.x78.z = fp3->mv.kb.speciallw.x48.z = - fp->mv.kb.speciallw.x18.z; - fp3->mv.kb.speciallw.x88[7] = fp3->mv.kb.speciallw.x88[3] = angle; + fp3->mv.kb.speciallw.x6C.z = (++vec)->z = fp->mv.kb.speciallw.x18.z; + fp3->mv.kb.speciallw.x88[6] = *++angles = angle; + angles++; + fp3->mv.kb.speciallw.x78.x = vec[1].x = fp->mv.kb.speciallw.x18.x; + fp3->mv.kb.speciallw.x78.y = vec[1].y = fp->mv.kb.speciallw.x18.y; + fp3->mv.kb.speciallw.x78.z = (++vec)->z = fp->mv.kb.speciallw.x18.z; + fp3->mv.kb.speciallw.x88[7] = *angles = angle; fp3->mv.kb.speciallw.x18.x = fp->mv.kb.speciallw.x18.x; fp3->mv.kb.speciallw.x18.y = fp->mv.kb.speciallw.x18.y; fp3->mv.kb.speciallw.x18.z = fp->mv.kb.speciallw.x18.z; @@ -853,6 +850,8 @@ void ftKb_SpecialAirLw_Coll(Fighter_GObj* gobj) ftKb_DatAttrs* da = fp->dat_attrs; Fighter* fp2; Fighter* fp3; + Vec3* vec; + f32* angles; s32 temp; f32 angle; struct ftKb_Init_803CB490_layout* p = @@ -877,6 +876,8 @@ void ftKb_SpecialAirLw_Coll(Fighter_GObj* gobj) ftCommon_8007EBAC(fp, 0xE, 0x14); fp3 = GET_FIGHTER(gobj); angle = fp->mv.kb.specialhi.xC4; + vec = &fp3->mv.kb.speciallw.x24; + angles = fp3->mv.kb.speciallw.x88; fp3->mv.kb.speciallw.x54.x = fp3->mv.kb.speciallw.x24.x = fp->mv.kb.speciallw.x18.x; fp3->mv.kb.speciallw.x54.y = fp3->mv.kb.speciallw.x24.y = @@ -884,6 +885,8 @@ void ftKb_SpecialAirLw_Coll(Fighter_GObj* gobj) fp3->mv.kb.speciallw.x54.z = fp3->mv.kb.speciallw.x24.z = fp->mv.kb.speciallw.x18.z; fp3->mv.kb.speciallw.x88[4] = fp3->mv.kb.speciallw.x88[0] = angle; + vec++; + angles++; fp3->mv.kb.speciallw.x60.x = fp3->mv.kb.speciallw.x30.x = fp->mv.kb.speciallw.x18.x; fp3->mv.kb.speciallw.x60.y = fp3->mv.kb.speciallw.x30.y = @@ -895,16 +898,13 @@ void ftKb_SpecialAirLw_Coll(Fighter_GObj* gobj) fp->mv.kb.speciallw.x18.x; fp3->mv.kb.speciallw.x6C.y = fp3->mv.kb.speciallw.x3C.y = fp->mv.kb.speciallw.x18.y; - fp3->mv.kb.speciallw.x6C.z = fp3->mv.kb.speciallw.x3C.z = - fp->mv.kb.speciallw.x18.z; - fp3->mv.kb.speciallw.x88[6] = fp3->mv.kb.speciallw.x88[2] = angle; - fp3->mv.kb.speciallw.x78.x = fp3->mv.kb.speciallw.x48.x = - fp->mv.kb.speciallw.x18.x; - fp3->mv.kb.speciallw.x78.y = fp3->mv.kb.speciallw.x48.y = - fp->mv.kb.speciallw.x18.y; - fp3->mv.kb.speciallw.x78.z = fp3->mv.kb.speciallw.x48.z = - fp->mv.kb.speciallw.x18.z; - fp3->mv.kb.speciallw.x88[7] = fp3->mv.kb.speciallw.x88[3] = angle; + fp3->mv.kb.speciallw.x6C.z = (++vec)->z = fp->mv.kb.speciallw.x18.z; + fp3->mv.kb.speciallw.x88[6] = *++angles = angle; + angles++; + fp3->mv.kb.speciallw.x78.x = vec[1].x = fp->mv.kb.speciallw.x18.x; + fp3->mv.kb.speciallw.x78.y = vec[1].y = fp->mv.kb.speciallw.x18.y; + fp3->mv.kb.speciallw.x78.z = (++vec)->z = fp->mv.kb.speciallw.x18.z; + fp3->mv.kb.speciallw.x88[7] = *angles = angle; fp3->mv.kb.speciallw.x18.x = fp->mv.kb.speciallw.x18.x; fp3->mv.kb.speciallw.x18.y = fp->mv.kb.speciallw.x18.y; fp3->mv.kb.speciallw.x18.z = fp->mv.kb.speciallw.x18.z; @@ -1027,7 +1027,12 @@ void fn_800F53AC(HSD_GObj* gobj) fp->cmd_vars[0] = 0; if (fp->fv.kb.hat.x0 != NULL) { if (fp->death2_cb != NULL && fp->death2_cb != ftKb_Init_800EE74C) { - HSD_ASSERTREPORT(0x66, 0, ftKb_Init_803CB510); + /* This TU was split out of retail ftkirbyspecials.c; the + * assert's file and condition strings are that TU's data + * (ftKb_Init_803CB52C = "ftkirbyspecials.c", + * ftKb_Init_804D3DB0 = "0"), declared in ftkirby.h. */ + HSD_ASSERTREPORTFILE(ftKb_Init_803CB52C, 0x66, 0, + ftKb_Init_804D3DB0, ftKb_Init_803CB510); } fp->death2_cb = ftKb_Init_800EE74C; fp->take_dmg_cb = ftKb_Init_800EE7B8; @@ -2633,26 +2638,26 @@ void ftKb_EatWait_IASA(Fighter_GObj* gobj) { Fighter* fp = getFighter(gobj); Fighter* fp2; + ftKb_DatAttrs* da; enum ftCo_JumpInput jump; + f32 absX; f32 stickX; - volatile f32 absX; s32 r29; s32 r29_2; s32 r29_3; s32 r29_4; s32 r0; s32 r0_2; - PAD_STACK(0x70); + PAD_STACK(0x80); if (fp->fv.kb.xF4_b0) { + da = fp->dat_attrs; if (((fp->input.x668 & 0x200) && fp->target_item_gobj != NULL) || - ((fp->input.lstick.y < - -((ftKb_DatAttrs*) fp->dat_attrs)->specialn_y_axis_range_jump) && + ((fp->input.lstick.y < -da->specialn_y_axis_range_jump) && fp->target_item_gobj != NULL)) { Fighter_ChangeMotionState(gobj, 0x170, 2, 0.0f, 1.0f, 0.0f, NULL); - r29 = 1; - fp->x2222_b2 = r29; + fp->x2222_b2 = r29 = 1; ftKb_SpecialN_800F9070(gobj); ftAnim_8006EBA4(gobj); ftCommon_8007E2F4(fp, 0x1FF); @@ -2660,12 +2665,11 @@ void ftKb_EatWait_IASA(Fighter_GObj* gobj) r29 = 0; } if (r29 == 0) { - fp2 = GET_FIGHTER(gobj); + fp2 = getFighter(gobj); if ((fp2->input.x668 & 0x100) && fp2->target_item_gobj != NULL) { Fighter_ChangeMotionState(gobj, 0x172, 0x12, 0.0f, 1.0f, 0.0f, NULL); - r29_2 = 1; - fp2->x2222_b2 = r29_2; + fp2->x2222_b2 = r29_2 = 1; ftKb_SpecialN_800F9070(gobj); ftAnim_8006EBA4(gobj); ftCommon_8007E2F4(fp2, 0x1FF); @@ -2678,14 +2682,13 @@ void ftKb_EatWait_IASA(Fighter_GObj* gobj) goto block_26; } } else { + da = fp->dat_attrs; if (((fp->input.x668 & 0x200) && fp->victim_gobj != NULL) || - ((fp->input.lstick.y < - -((ftKb_DatAttrs*) fp->dat_attrs)->specialn_y_axis_range_jump) && + ((fp->input.lstick.y < -da->specialn_y_axis_range_jump) && fp->victim_gobj != NULL)) { Fighter_ChangeMotionState(gobj, 0x16F, 2, 0.0f, 1.0f, 0.0f, NULL); - r29_3 = 1; - fp->x2222_b2 = r29_3; + fp->x2222_b2 = r29_3 = 1; ftKb_SpecialN_800F9070(gobj); ftAnim_8006EBA4(gobj); ftCommon_8007E2F4(fp, 0x1FF); @@ -2697,8 +2700,7 @@ void ftKb_EatWait_IASA(Fighter_GObj* gobj) if ((fp2->input.x668 & 0x100) && fp2->victim_gobj != NULL) { Fighter_ChangeMotionState(gobj, 0x171, 0x12, 0.0f, 1.0f, 0.0f, NULL); - r29_4 = 1; - fp2->x2222_b2 = r29_4; + fp2->x2222_b2 = r29_4 = 1; ftKb_SpecialN_800F9070(gobj); ftAnim_8006EBA4(gobj); ftCommon_8007E2F4(fp2, 0x1FF); @@ -2707,13 +2709,16 @@ void ftKb_EatWait_IASA(Fighter_GObj* gobj) } if (r29_4 == 0) { block_26: - fp2 = GET_FIGHTER(gobj); + fp2 = getFighter(gobj); stickX = fp2->input.lstick.x; (void) stickX; - absX = ABS(stickX); - if (absX < ((ftKb_DatAttrs*) fp2->dat_attrs) - ->specialn_x_axis_range_walk) - { + da = fp2->dat_attrs; + if (stickX < 0.0f) { + absX = -stickX; + } else { + absX = stickX; + } + if (absX < da->specialn_x_axis_range_walk) { stickX = 0.0f; } if (((stickX < 0.0f) && (fp2->facing_dir == 1.0f)) || @@ -2765,7 +2770,6 @@ void ftKb_SpecialAirNCaptureWait_IASA(Fighter_GObj* gobj) { Fighter* fp = getFighter(gobj); Fighter_GObj* gobj2 = gobj; - Fighter* fp3; Fighter* fp2; ftKb_DatAttrs* da; f32 absX; @@ -2778,9 +2782,9 @@ void ftKb_SpecialAirNCaptureWait_IASA(Fighter_GObj* gobj) PAD_STACK(0x50); if (fp->fv.kb.xF4_b0) { + ftKb_DatAttrs* da2 = fp->dat_attrs; if (((fp->input.x668 & 0x200) && fp->target_item_gobj != NULL) || - ((fp->input.lstick.y < - -((ftKb_DatAttrs*) fp->dat_attrs)->specialn_y_axis_range_jump) && + ((fp->input.lstick.y < -da2->specialn_y_axis_range_jump) && fp->target_item_gobj != NULL)) { Fighter_ChangeMotionState(gobj2, 0x17B, 2, 0.0f, 1.0f, 0.0f, NULL); @@ -2811,9 +2815,9 @@ void ftKb_SpecialAirNCaptureWait_IASA(Fighter_GObj* gobj) goto block_26; } } else { + ftKb_DatAttrs* da2 = fp->dat_attrs; if (((fp->input.x668 & 0x200) && fp->victim_gobj != NULL) || - ((fp->input.lstick.y < - -((ftKb_DatAttrs*) fp->dat_attrs)->specialn_y_axis_range_jump) && + ((fp->input.lstick.y < -da2->specialn_y_axis_range_jump) && fp->victim_gobj != NULL)) { Fighter_ChangeMotionState(gobj2, 0x17A, 2, 0.0f, 1.0f, 0.0f, NULL); @@ -2839,6 +2843,7 @@ void ftKb_SpecialAirNCaptureWait_IASA(Fighter_GObj* gobj) r29_4 = 0; } if (r29_4 == 0) { + Fighter* fp3; block_26: fp3 = getFighter(gobj2); stickX = fp3->input.lstick.x; diff --git a/src/melee/ft/chara/ftYoshi/ftYs_SpecialS.c b/src/melee/ft/chara/ftYoshi/ftYs_SpecialS.c index ac4e21f300..7d94f7d134 100644 --- a/src/melee/ft/chara/ftYoshi/ftYs_SpecialS.c +++ b/src/melee/ft/chara/ftYoshi/ftYs_SpecialS.c @@ -1240,21 +1240,44 @@ void ftYs_SpecialAirSStart_1_Coll(Fighter_GObj* gobj) void ftYs_SpecialAirSLoop_2_Coll(Fighter_GObj* gobj) { s32 coll_result; + Fighter* fp2; s32 wall_hit; Fighter* fp = GET_FIGHTER(gobj); ftYoshiAttributes* attributes = fp->dat_attrs; - u8 pad[28]; + Vec3 pos; + f32 angle; + Vec3 pos2; + f32 angle2; + PAD_STACK(32); fp->mv.ys.specials.x30 = 0; coll_result = ft_800824A0(gobj, &ftYs_Unk3_803CEDA4); if (fp->facing_dir == 1.0F) { if ((wall_hit = fp->coll_data.env_flags & 0x3F) != 0) { - ftYs_SpecialS_SpawnWallBounceEffect(gobj, &fp->coll_data, true); + fp2 = GET_FIGHTER(gobj); + pos = fp2->cur_pos; + angle = atan2f(-fp->coll_data.left_facing_wall.normal.x, + fp->coll_data.left_facing_wall.normal.y); + pos.x += ABS(fp2->coll_data.ecb.right.x); + pos.y += 0.5F * ABS(fp2->coll_data.ecb.top.y + + fp2->coll_data.ecb.bottom.y); + efSync_Spawn(0x406, gobj, &pos, &angle); + Camera_80030E44(3, &pos); + ftCommon_8007EBAC(fp2, 0xC, 0xA); } } else { if ((wall_hit = fp->coll_data.env_flags & 0xFC0) != 0) { - ftYs_SpecialS_SpawnWallBounceEffect(gobj, &fp->coll_data, false); + fp2 = GET_FIGHTER(gobj); + pos2 = fp2->cur_pos; + angle2 = atan2f(-fp->coll_data.right_facing_wall.normal.x, + fp->coll_data.right_facing_wall.normal.y); + pos2.x -= ABS(fp2->coll_data.ecb.left.x); + pos2.y += 0.5F * ABS(fp2->coll_data.ecb.top.y + + fp2->coll_data.ecb.bottom.y); + efSync_Spawn(0x406, gobj, &pos2, &angle2); + Camera_80030E44(3, &pos2); + ftCommon_8007EBAC(fp2, 0xC, 0xA); } } diff --git a/src/melee/ft/ft_0CE3.c b/src/melee/ft/ft_0CE3.c index b914c2b368..fc1c3d6bf7 100644 --- a/src/melee/ft/ft_0CE3.c +++ b/src/melee/ft/ft_0CE3.c @@ -94,11 +94,11 @@ inline void ftCo_800CE650_inline(HSD_GObj* gobj, int frame, int interval) inline void ftCo_800CE650_inline2(HSD_GObj* gobj) { - Vec3 sp30; Vec3 sp24; + Vec3 item_pos; Fighter* fp = GET_FIGHTER(gobj); - it_80292EF8(fp->item_gobj, &sp30); - ftCo_800CDE94(fp, &sp30, &sp24); + it_80292EF8(fp->item_gobj, &item_pos); + ftCo_800CDE94(fp, &item_pos, &sp24); if (!it_8026B594(fp->item_gobj)) { it_80292F14(fp->item_gobj, &sp24, fp->facing_dir); } else { @@ -111,20 +111,20 @@ inline void ftCo_800CE650_inline2(HSD_GObj* gobj) inline void ftCo_800CE650_inline3(HSD_GObj* gobj) { - Vec3 spA0; + Vec3 joint_pos; Vec3 sp94; + Vec3 item_pos; float sp90; - Vec3 sp84; Fighter* fp = GET_FIGHTER(gobj); if (it_8026B594(fp->item_gobj) == 0) { sp90 = 0.0F; - lb_8000B1CC(fp->parts->joint, NULL, &sp84); - efSync_Spawn(0x3FF, gobj, &sp84, &fp->facing_dir, &sp90); + lb_8000B1CC(fp->parts->joint, NULL, &joint_pos); + efSync_Spawn(0x3FF, gobj, &joint_pos, &fp->facing_dir, &sp90); ft_PlaySFX(fp, 0xEE, 0x7F, 0x40); } else { - it_80292EF8(fp->item_gobj, &spA0); - ftCo_800CDE94(fp, &spA0, &sp94); + it_80292EF8(fp->item_gobj, &item_pos); + ftCo_800CDE94(fp, &item_pos, &sp94); efSync_Spawn(0x405, gobj, &sp94); ft_PlaySFX(fp, 0xEF, 0x7F, 0x40); } diff --git a/src/melee/ft/ftafterimage.c b/src/melee/ft/ftafterimage.c index bed205b6c8..f44980c401 100644 --- a/src/melee/ft/ftafterimage.c +++ b/src/melee/ft/ftafterimage.c @@ -32,9 +32,11 @@ void ftCo_800C2600(Fighter_GObj* gobj, u32 arg1) { Fighter* fp; itSword_UnkBytes* params; - AfterimageVtx vtx_buf[151]; + u32 n4; + s32 numSubdiv; f32 cumDist[3]; - Vec3 delta, prevPos, crossProd, tempDir; + AfterimageVtx vtx_buf[151]; + f32 d2; s32 numVerts; s32 nextIdx; @@ -42,7 +44,10 @@ void ftCo_800C2600(Fighter_GObj* gobj, u32 arg1) return; } - fp = gobj->user_data; + { + void* fighter = gobj->user_data; + fp = fighter; + } if ((s8) (u8) fp->x2100 <= 1) { return; @@ -126,13 +131,15 @@ void ftCo_800C2600(Fighter_GObj* gobj, u32 arg1) cumDist[0] = 0.0f; totalDist = 0.0f; - prevPos.x = prevPos.y = prevPos.z = 0.0f; dp = &cumDist[1]; { + Vec3 delta, prevPos; s32 i; s32 curIdx = ringIdx; + prevPos.x = prevPos.y = prevPos.z = 0.0f; + for (i = (s8) (u8) fp->x2100 - 1; i >= 0; i--) { struct Fighter_x20B0_t* entry = &fp->x20B0[curIdx]; @@ -141,11 +148,9 @@ void ftCo_800C2600(Fighter_GObj* gobj, u32 arg1) delta.z = entry->xC.z * x20FC + entry->x0.z - prevPos.z; if (i != (s8) (u8) fp->x2100 - 1) { - f32 d2 = delta.z * delta.z + - (delta.x * delta.x + delta.y * delta.y); - if (d2 > 0.0f) { - d2 = sqrtf(d2); - } + d2 = delta.z * delta.z + + (delta.x * delta.x + delta.y * delta.y); + d2 = sqrtf(d2); totalDist += d2; *dp = totalDist; dp++; @@ -169,6 +174,7 @@ void ftCo_800C2600(Fighter_GObj* gobj, u32 arg1) } { + Vec3 crossProd, tempDir; f32 scaleDiff = x20FC - x20F8; s32 curIdx2; f32 blendedInner = params->x0 * scaleDiff + x20F8; @@ -196,11 +202,10 @@ void ftCo_800C2600(Fighter_GObj* gobj, u32 arg1) vp = &vtx_buf[0]; while (remaining >= 0) { - struct Fighter_x20B0_t* curEntry; f32 outerScale, innerScale; s32 alpha; - curEntry = &fp->x20B0[curIdx2]; + struct Fighter_x20B0_t* curEntry = &fp->x20B0[curIdx2]; outerScale = interpFactor * outerDiff + blendedOuter; innerScale = interpFactor * innerDiff + blendedInner; numVerts += 2; @@ -245,10 +250,10 @@ void ftCo_800C2600(Fighter_GObj* gobj, u32 arg1) f32 angle = lbVector_Angle(&curEntry->xC, &nextEntry->xC); f32 subdivAngle = angle / AFTERIMAGE_ANGLE_STEP; - s32 numSubdiv = (s32) subdivAngle; + numSubdiv = (s32) subdivAngle; interpFactor = 1.0f - (*distPtr / totalDist); - if (numSubdiv != 0) { + if (numSubdiv) { f32 frac; s32 j; f32 cumAngle = 0.0f; @@ -347,7 +352,7 @@ void ftCo_800C2600(Fighter_GObj* gobj, u32 arg1) if (numVerts > 1) { AfterimageVtx* p = &vtx_buf[1]; u32 count = (u32) (numVerts - 1); - u32 n4 = count >> 2; + n4 = count >> 2; if (n4 != 0) { do { GXPosition3f32(p[0].x, p[0].y, p[0].z); diff --git a/src/melee/ft/ftcoll.c b/src/melee/ft/ftcoll.c index 7b8ee31556..1973fc602c 100644 --- a/src/melee/ft/ftcoll.c +++ b/src/melee/ft/ftcoll.c @@ -40,7 +40,8 @@ #include "pl/player.h" #include "pl/plbonuslib.h" #include "pl/plstale.h" -#include "pl/pltrick.h" +void pl_80037ECC(HSD_GObj*); +void pl_80038144(HSD_GObj*, HSD_GObj*, int, UNK_T, int, int, int); #include #include @@ -51,6 +52,22 @@ #include #include +static void sdata2_order(void) +{ + (void) 0.0f; + (void) 500.0f; + (void) 0.5f; + (void) 1.0f; + (void) -1.0f; + (void) S32_TO_F32; + (void) 0.0174532924f; + (void) U32_TO_F32; + (void) 3.40282347e+38f; + (void) 0.00999999978f; + (void) 9.99999975e-06f; + (void) 57.2957802f; +} + /* 07A06C */ void ftColl_8007A06C(Fighter_GObj*, void*, void*, size_t, int); /// /* 076808 */ static void ftColl_80076808(Fighter* fp, HitCapsule* hit, int, /// Fighter* victim, bool); @@ -59,6 +76,10 @@ int ftColl_803C0C40[] = { 141, 142, 143 }; int ftColl_803C0C4C[] = { 107, 108, 109 }; +struct UnkSize320_t { + u8 x0[0x320]; +}; + /// .bss static DmgLogEntry dmg_log0[20]; struct DmgLogEntry dmg_log1[20]; @@ -68,6 +89,10 @@ static int dmg_log0_idx; static int dmg_log1_idx; static s8 ftColl_804D6560[8]; +/// .sdata2 +float const ftColl_804D82EC = +1; +float const ftColl_804D8314 = 0.01; + /// Combo Count Logic void ftColl_800763C0(Fighter_GObj* attacker, Fighter_GObj* victim, enum_t attack_id) @@ -198,25 +223,6 @@ static int getEnvDmg(float dmg) return 0; } -static bool inlineB2(Fighter* fp1, float dmg, int var_r24_3) -{ - int var_r0_3; - if (fp1->x221C_b4 == 0) { - if (dmg > 500.0f) { - HSD_ASSERTREPORT(0xB7, 0, "attack power over 500!! %f\n", dmg); - } - fp1->dmg.x1838_percentTemp = - (float) (fp1->dmg.x1838_percentTemp + dmg); - if (var_r24_3 > (int) fp1->dmg.x183C_applied) { - fp1->dmg.x183C_applied = var_r24_3; - } - var_r0_3 = 1; - } else { - var_r0_3 = 0; - } - return var_r0_3; -} - bool ftColl_80076640(Fighter* fp, float* dmg) { int env_dmg = getEnvDmg(*dmg); @@ -260,35 +266,6 @@ void ftColl_80076764(int arg0, enum_t arg1, Fighter_GObj* arg2, } } -static void tiplog(int kind, HSD_GObj* gobj, HitCapsule* hit0, - HitCapsule* hit1, int len, float temp_dmg) -{ - if (dmg_log1_idx < ARRAY_SIZE(dmg_log1)) { - DmgLogEntry* entry = &dmg_log1[dmg_log1_idx]; - entry->x0 = 1; - entry->kind = kind; - entry->gobj = gobj; - entry->hit0 = hit0; - entry->hit1 = hit1; - entry->pos = hit0->hurt_coll_pos; - entry->x20 = temp_dmg; - entry->size_of_xC = len; - ++dmg_log1_idx; - } else { - HSD_ASSERTREPORT(0x110, 0, "tip log over %d!!\n", - ARRAY_SIZE(dmg_log1)); - } -} - -static int ftColl_803C0CAC[] = { - 1000, 1002, 1001, 1004, 1145, 1005, -1, -1, -1, - 1000, 1000, -1, -1, 1046, -1, -1, 0, -}; - -struct UnkSize320_t { - u8 x0[0x320]; -}; - void ftColl_80076808(Fighter* fp, HitCapsule* hit, int arg2, void* victim, bool arg4) { @@ -457,7 +434,7 @@ bool ftColl_8007699C(Fighter* fp0, HitCapsule* hit0, Fighter* fp1, static inline bool ftColl_8007699C_dontinline(Fighter* fp0, HitCapsule* hit0, Fighter* fp1, HitCapsule* hit1) { - ftColl_8007699C(fp0, hit0, fp1, hit1); + return ftColl_8007699C(fp0, hit0, fp1, hit1); } void ftColl_80076CBC(Fighter* fp0, HitCapsule* hit0, Fighter* fp1) @@ -522,24 +499,14 @@ void ftColl_80076CBC(Fighter* fp0, HitCapsule* hit0, Fighter* fp1) } } -struct ftCollSFX { - int x0; - int x4; - int x8; - int xC; - int x10; - int x14; -}; - /// @todo #ftColl_80076808 -inline void inlineB0(Fighter* fp0, HitCapsule* hitbox, Fighter* fp1, int arg3, - bool (*cb)(HitCapsule* hit, int arg1, void* fp)) +inline void inlineB0(Fighter* fp0, HitCapsule* hitbox, Fighter* fp1, int arg3) { size_t i; for (i = 0; i < ARRAY_SIZE(fp0->x914); i++) { HitCapsule* cur = &fp0->x914[i]; if (cur->state != HitCapsule_Disabled && cur->x4 == hitbox->x4) { - cb(cur, arg3, fp1); + lbColl_80008820(cur, arg3, fp1); } } } @@ -570,6 +537,25 @@ static inline bool inlineB1(HitCapsule* hit0) return var_r0; } +static inline bool inlineB2(Fighter* fp1, float dmg, int var_r24_3) +{ + int var_r0_3; + if (fp1->x221C_b4 == 0) { + if (dmg > 500.0f) { + HSD_ASSERTREPORT(0xB7, 0, "attack power over 500!! %f\n", dmg); + } + fp1->dmg.x1838_percentTemp = + (float) (fp1->dmg.x1838_percentTemp + dmg); + if (var_r24_3 > (int) fp1->dmg.x183C_applied) { + fp1->dmg.x183C_applied = var_r24_3; + } + var_r0_3 = 1; + } else { + var_r0_3 = 0; + } + return var_r0_3; +} + static inline float inlineB3(Fighter* fp0, HitCapsule* hit0, Fighter* fp1) { HSD_GObj* victim_gobj = fp1->victim_gobj; @@ -591,94 +577,128 @@ bool ftColl_80076ED8(Fighter* fp0, HitCapsule* hit0, Fighter* fp1, HitCapsule* hit1) { float dmg = inlineB3(fp0, hit0, fp1); - PAD_STACK(32); + PAD_STACK(24); if (inlineB1(hit0)) { - HitCapsuleState state; + if (dmg_log0_idx == 0 && !fp1->dmg.x189C_unk_num_frames) { + if (checkTipLog(fp1, hit0) == HitCapsule_Disabled) { + float temp_dmg = dmg; + temp_dmg *= 0.5f; + if (!((int) temp_dmg) && dmg) { + temp_dmg = 1; + } - if (dmg_log0_idx != 0) { - goto retfalse; - } - if (fp1->dmg.x189C_unk_num_frames) { - goto retfalse; + inlineB0(fp0, hit0, fp1, 0); + if (fp1->x1988 == 0 && fp1->x198C == 0 && !fp1->x221D_b6 && + hit1->state == HitCapsule_Disabled) + { + u32 count = hit0->unk_count; + Fighter* fp = fp0; + FighterKind kind; + HSD_GObj* gobj; + u32 len = count >> 1; + if (len == 0 && count != 0) { + len = 1; + } + { + int temp_int = temp_dmg; + int temp_int2 = temp_dmg; + if (temp_int > fp1->dmg.x1840) { + fp1->dmg.x1840 = temp_int2; + } + } + if (fp0->x1064_thrownHitbox.owner != NULL) { + fp = GET_FIGHTER(fp0->x1064_thrownHitbox.owner); + } + { + gobj = fp->gobj; + kind = fp->kind; + if (dmg_log1_idx < ARRAY_SIZE(dmg_log1)) { + DmgLogEntry* entry = &dmg_log1[dmg_log1_idx]; + entry->x0 = 1; + entry->kind = kind; + entry->gobj = gobj; + entry->hit0 = hit0; + entry->hit1 = hit1; + entry->pos = hit0->hurt_coll_pos; + entry->x20 = temp_dmg; + entry->size_of_xC = len; + ++dmg_log1_idx; + } else { + HSD_ASSERTREPORT(0x110, 0, "tip log over %d!!\n", + ARRAY_SIZE(dmg_log1)); + } + } + } + + ftColl_80078488(fp1); + return true; + } } - state = checkTipLog(fp1, hit0); - if (state == HitCapsule_Disabled) { - float temp_dmg = 0.5f * dmg; - if (!((int) temp_dmg) && dmg) { - temp_dmg = 1; + } else { + DmgLogEntry* entry; + bool inner_ret; + int int_dmg; + + if (dmg) { + if ((int) dmg) { + int_dmg = dmg; + } else { + int_dmg = 1; } + } else { + int_dmg = 0; + } - inlineB0(fp0, hit0, fp1, 0, lbColl_80008820); - if (fp1->x1988 == 0 && fp1->x198C == 0 && !fp1->x221D_b6 && - hit1->state == HitCapsule_Disabled) - { - size_t count = hit0->unk_count; - Fighter* fp = fp0; - size_t len = count >> 1; - if (len == 0 && count != 0) { - len = 1; - } - if ((int) temp_dmg > fp1->dmg.x1840) { - fp1->dmg.x1840 = temp_dmg; - } - if (fp0->x1064_thrownHitbox.owner != NULL) { - fp = GET_FIGHTER(fp0->x1064_thrownHitbox.owner); + { + size_t i; + dmg_log1_idx = (i = 0); + inner_ret = false; + for (; i < ARRAY_SIZE(fp0->x914); i++) { + HitCapsule* cur = &fp0->x914[i]; + if (cur->state != HitCapsule_Disabled && cur->x4 == hit0->x4) { + lbColl_80008688(cur, 0, fp1); } - tiplog(fp->kind, fp->gobj, hit0, hit1, len, temp_dmg); } - - ftColl_80078488(fp1); - return true; } - } - - { - int int_dmg = getEnvDmg(dmg); - - dmg_log1_idx = 0; - inlineB0(fp0, hit0, fp1, 0, lbColl_80008688); if (int_dmg > fp0->dmg.x1914) { fp0->dmg.x1914 = int_dmg; } - } - if (fp1->x1988 == 0 && fp1->x198C == 0 && !fp1->x221D_b6 && - hit1->state == HitCapsule_Disabled) - { - int int_dmg = getEnvDmg(dmg); - if (fp1->x221C_b4) { - fp1->dmg.x1834 = fp1->dmg.x1834 - dmg; - if (fp1->dmg.x1834 < 0) { - dmg = -fp1->dmg.x1834; - fp1->x221C_b4 = false; - } - } + if (fp1->x1988 == 0 && fp1->x198C == 0 && !fp1->x221D_b6 && + hit1->state == HitCapsule_Disabled) { - bool inner_ret; -#ifdef BUGFIX - inner_ret = false; -#endif + int dmg_count = getEnvDmg(dmg); + if (fp1->x221C_b4) { + fp1->dmg.x1834 = fp1->dmg.x1834 - dmg; + if (fp1->dmg.x1834 < 0) { + dmg = -fp1->dmg.x1834; + fp1->x221C_b4 = false; + } + } + { /// @todo inline - if (inlineB2(fp1, dmg, int_dmg)) { + if (inlineB2(fp1, dmg, dmg_count)) { Fighter* fp = fp0; if (fp0->x1064_thrownHitbox.owner != NULL) { fp = fp0->x1064_thrownHitbox.owner->user_data; } { + FighterKind kind; + HSD_GObj* gobj; size_t len = hit0->unk_count; - HSD_GObj* gobj = fp->gobj; - FighterKind kind = fp->kind; + gobj = fp->gobj; + kind = fp->kind; if (dmg_log0_idx < 20U) { - DmgLogEntry* damageLog2 = &dmg_log0[dmg_log0_idx]; - damageLog2->x0 = 1; - damageLog2->kind = kind; - damageLog2->gobj = gobj; - damageLog2->hit0 = hit0; - damageLog2->hit1 = hit1; - damageLog2->pos = hit0->hurt_coll_pos; - damageLog2->x20 = hit0->damage; - damageLog2->size_of_xC = len; + entry = &dmg_log0[dmg_log0_idx]; + entry->x0 = 1; + entry->kind = kind; + entry->gobj = gobj; + entry->hit0 = hit0; + entry->hit1 = hit1; + entry->pos = hit0->hurt_coll_pos; + entry->x20 = hit0->damage; + entry->size_of_xC = len; dmg_log0_idx++; } else { HSD_ASSERTREPORT(0xe3, 0, @@ -690,19 +710,26 @@ bool ftColl_80076ED8(Fighter* fp0, HitCapsule* hit0, Fighter* fp1, } ftColl_8007891C(fp0->gobj, fp1->gobj, dmg); } + } - if (!inner_ret) { - efSync_Spawn(1052, NULL, &hit0->hurt_coll_pos); - } + if (!inner_ret) { + efSync_Spawn(1052, NULL, &hit0->hurt_coll_pos); } return true; } -retfalse: - return false; } +UNUSED static int ftColl_803C0CAC[] = { + 1000, 1002, 1001, 1004, 1145, 1005, -1, -1, -1, + 1000, 1000, -1, -1, 1046, -1, -1, 0, +}; +UNUSED static char ftColl_803C0CF0[] = + "in ftCollisionSetHitStatus illegal parts!\n"; +UNUSED static char assert_msg_1[] = "fighter hit num over!\n"; +UNUSED static char assert_msg_2[] = "fighter dynamics hit num over!\n"; + void ftColl_80077464(Item* item, HitCapsule* hit, Fighter* fp) { s32 damage; @@ -808,8 +835,7 @@ void ftColl_80077688(Item* item, HitCapsule* hurt, Fighter* fp, Vec3* pos, { int dmg; int mode; - u8 operand_pad[8]; - PAD_STACK(16); + PAD_STACK(24); if (hurt->x41_b6) { mode = 2; @@ -830,9 +856,7 @@ void ftColl_80077688(Item* item, HitCapsule* hurt, Fighter* fp, Vec3* pos, } if (dmg > item->xC34_damageDealt) { - float dir; - float vel_x; - float vel_x_mag; + float vel_x, vel_x_mag, dir; item->xC50 = dmg; @@ -844,7 +868,8 @@ void ftColl_80077688(Item* item, HitCapsule* hurt, Fighter* fp, Vec3* pos, item->xCF4_fighterGObjUnk = fp->gobj; - vel_x = item->x40_vel.x; + vel_x_mag = item->x40_vel.x; + vel_x = vel_x_mag; if (vel_x < 0.0f) { vel_x_mag = -vel_x; } else { @@ -868,20 +893,20 @@ void ftColl_80077688(Item* item, HitCapsule* hurt, Fighter* fp, Vec3* pos, if (item->xDCE_flag.b5) { if (fp->x221B_b1) { - float angle = deg_to_rad * p_ftCommonData->x2D0; float cos_val; - float sin_val; + val = deg_to_rad * p_ftCommonData->x2D0; item->xC54 = 0.0f; - cos_val = cosf(angle); - sin_val = sinf(angle); + cos_val = cosf(val); + val = sinf(val); if (pos->x >= 0.0f) { - item->xC58.x = -cos_val; + dir = cos_val; } else { - item->xC58.x = cos_val; + dir = -cos_val; } - item->xC58.y = sin_val; + item->xC58.x = dir; + item->xC58.y = val; item->xC58.z = 0.0f; item->xDCE_flag.b4 = 1; } else { @@ -897,10 +922,13 @@ void ftColl_80077688(Item* item, HitCapsule* hurt, Fighter* fp, Vec3* pos, { int total = dmg + hurt->x34; + int clamped_total; if (total < 0) { - total = 0; + clamped_total = 0; + } else { + clamped_total = total; } - fp->x19A0_shieldDamageTaken += total; + fp->x19A0_shieldDamageTaken += clamped_total; } if (ftLib_80086960(item->owner)) { @@ -1141,12 +1169,16 @@ bool ftColl_80077C60(Item* item, HitCapsule* hit, Fighter* fp, half_raw = int_raw / 2; half_raw_f = (float) half_raw; - if (half_raw_f == 0.0f && int_raw != 0) { + if (!half_raw_f && int_raw != 0) { half_raw_f = 1.0f; } - if ((int) f4 > fp->dmg.x1840) { - fp->dmg.x1840 = (int) f4; + { + int f4_int = (int) f4; + int f4_int2 = (int) f4; + if (f4_int > fp->dmg.x1840) { + fp->dmg.x1840 = f4_int2; + } } { @@ -1176,14 +1208,18 @@ bool ftColl_80077C60(Item* item, HitCapsule* hit, Fighter* fp, return true; } } - } else { + goto retfalse; + } + + { + DmgLogEntry* entry; bool inner_ret; + bool should_log; int mode; - dmg_log1_idx = 0; + dmg_log1_idx = (mode = 0); inner_ret = false; - mode = 0; if (hit->x41_b5) { mode = 5; } @@ -1195,7 +1231,8 @@ bool ftColl_80077C60(Item* item, HitCapsule* hit, Fighter* fp, item->xC34_damageDealt = (int) scaled_dmg; item->xCF4_fighterGObjUnk = fp->gobj; - vel_x = item->x40_vel.x; + vel_x_mag = item->x40_vel.x; + vel_x = vel_x_mag; if (vel_x < 0.0f) { vel_x_mag = -vel_x; } else { @@ -1221,7 +1258,17 @@ bool ftColl_80077C60(Item* item, HitCapsule* hit, Fighter* fp, if (fp->x1988 == 0 && fp->x198C == 0 && !fp->x221D_b6 && hit2->state == HitCapsule_Disabled) { - int dmg_count = getEnvDmg(scaled_dmg); + int dmg_count; + + if (scaled_dmg) { + if ((int) scaled_dmg) { + dmg_count = scaled_dmg; + } else { + dmg_count = 1; + } + } else { + dmg_count = 0; + } if (fp->x221C_b4) { fp->dmg.x1834 -= scaled_dmg; @@ -1241,17 +1288,17 @@ bool ftColl_80077C60(Item* item, HitCapsule* hit, Fighter* fp, if (dmg_count > fp->dmg.x183C_applied) { fp->dmg.x183C_applied = dmg_count; } - inner_ret = true; + should_log = true; } else { - inner_ret = false; + should_log = false; } - if (inner_ret) { + if (should_log) { FighterKind kind; HSD_GObj* entity = item->entity; kind = (FighterKind) item->kind; if (dmg_log0_idx < 20U) { - DmgLogEntry* entry = &dmg_log0[dmg_log0_idx]; + entry = &dmg_log0[dmg_log0_idx]; entry->x0 = 2; entry->kind = kind; entry->gobj = entity; @@ -1278,6 +1325,7 @@ bool ftColl_80077C60(Item* item, HitCapsule* hit, Fighter* fp, return true; } } +retfalse: return false; } @@ -1348,21 +1396,16 @@ void ftColl_80078538(Fighter_GObj* gobj, Vec3* pos, u32 dmg, float ignored, } void ftColl_8007861C(Fighter_GObj* arg0, Fighter_GObj* gobj, int arg2, - int arg3, int arg4, UNK_T arg5, u16 arg6, UNK_T arg7, + int arg3, int arg4, UNK_T arg5, int arg6, UNK_T arg7, int arg8) { - Fighter* attacker; Fighter* victim; + Fighter* attacker; s32 grounded; s32 prev_source_ply; - u16 attack_instance = arg6; - PAD_STACK(8); + int attack_instance = arg6; - if (arg0 != NULL) { - attacker = GET_FIGHTER(arg0); - } else { - attacker = NULL; - } + attacker = arg0 != NULL ? GET_FIGHTER(arg0) : NULL; victim = GET_FIGHTER(gobj); grounded = 0; @@ -1650,7 +1693,7 @@ void ftColl_80078C70(Fighter_GObj* this_gobj) if (this_fp->x221B_b0) { var_r3 = true; if (this_fp->x221B_b3) { - if (-1.0f == this_fp->facing_dir) { + if (-1.0F == this_fp->facing_dir) { if (this_fp->cur_pos .x < victim_fp->cur_pos .x) { var_r3 = false; } @@ -2091,30 +2134,30 @@ float ftColl_80079AB0(Fighter* fp, HitCapsule* hit, u32 unk_count, float arg3, float attack, float defense, float weight) { ftCommonData* ftd = p_ftCommonData; - float w = weight * ftd->xF4; float decay; + float weight_mul; float result; + PAD_STACK(8); + weight_mul = weight * ftd->xF4; if (hit->x28 != 0) { - float x24_f; - + float x118; decay = ftd->xF8; - result = (w * decay) / (1.0F + w); - decay -= result; - - result = ftd->x118 * (float) (u32) hit->x28; - result = ftd->x118 * ftd->x110 + ftd->x114 * result; - result = decay * result; - result = ftd->x11C * result + ftd->x120; - x24_f = 0.01F * (float) (u32) hit->x24; - result = x24_f * result + (float) (u32) hit->x2C; - result = arg3 * result; - result = attack * result; - result = defense * result; + x118 = ftd->x118; + result = + defense * + (attack * + (arg3 * + ((0.01F * (float) (u32) hit->x24 * + ((ftd->x11C * + ((decay - ((weight_mul * decay) / (1.0F + weight_mul))) * + ((x118 * ftd->x110) + + (ftd->x114 * (x118 * (float) (u32) hit->x28))))) + + ftd->x120)) + + (float) (u32) hit->x2C))); } else { s32 count; - float damage; - float x24_f; + float base; if (fp->x2225_b7) { if (fp->x2224_b2) { @@ -2126,20 +2169,21 @@ float ftColl_80079AB0(Fighter* fp, HitCapsule* hit, u32 unk_count, float arg3, count = (s32) fp->dmg.x1830_percent; } - decay = ftd->xF8; - result = (w * decay) / (1.0F + w); - decay -= result; - damage = (float) count + fp->dmg.x1838_percentTemp; - result = (float) (u32) unk_count * damage; - result = ftd->x110 * damage + ftd->x114 * result; - result = decay * result; - result = ftd->x11C * result + ftd->x120; - x24_f = 0.01F * (float) (u32) hit->x24; - (void) x24_f; - result = x24_f * result + (float) (u32) hit->x2C; - result = arg3 * result; - result = attack * result; - result = defense * result; + base = ftd->xF8; + weight_mul = (weight_mul * base) / (ftColl_804D82EC + weight_mul); + result = + defense * + (attack * + (arg3 * + ((ftColl_804D8314 * (float) (u32) hit->x24 * + ((ftd->x11C * + ((base - weight_mul) * + ((ftd->x110 * ((float) count + fp->dmg.x1838_percentTemp)) + + (ftd->x114 * + ((float) (u32) unk_count * + ((float) count + fp->dmg.x1838_percentTemp)))))) + + ftd->x120)) + + (float) (u32) hit->x2C))); } if (result >= ftd->x108) { @@ -2155,33 +2199,28 @@ float ftColl_80079C70(Fighter* fp, Fighter* attacker, HitCapsule* hit, float weight = fp->co_attrs.weight; float defense = Player_GetDefenseRatio(fp->player_id); float attack = Player_GetAttackRatio(attacker->player_id); - float arg3 = gm_8016B248(); + float stage = gm_8016B248(); ftCommonData* ftd = p_ftCommonData; + u32 x28 = hit->x28; float w = weight * ftd->xF4; - float decay; float result; - PAD_STACK(8); - - if (hit->x28 != 0) { - float x24_f; + PAD_STACK(16); - decay = ftd->xF8; - result = (w * decay) / (1.0F + w); - decay -= result; - - result = ftd->x118 * (float) (u32) hit->x28; - result = ftd->x118 * ftd->x110 + ftd->x114 * result; - result = decay * result; - result = ftd->x11C * result + ftd->x120; - x24_f = 0.01F * (float) (u32) hit->x24; - result = x24_f * result + (float) (u32) hit->x2C; - result = arg3 * result; - result = attack * result; - result = defense * result; + if (x28 != 0) { + float decay = ftd->xF8; + float x118 = ftd->x118; + result = + defense * + (attack * + (stage * + ((0.01F * (float) (u32) hit->x24 * + (ftd->x11C * ((decay - ((w * decay) / (1.0F + w))) * + ((x118 * ftd->x110) + + (ftd->x114 * (x118 * (float) (u32) x28)))) + + ftd->x120)) + + (float) (u32) hit->x2C))); } else { s32 count; - float damage; - float x24_f; if (fp->x2225_b7) { if (fp->x2224_b2) { @@ -2193,20 +2232,23 @@ float ftColl_80079C70(Fighter* fp, Fighter* attacker, HitCapsule* hit, count = (s32) fp->dmg.x1830_percent; } - decay = ftd->xF8; - result = (w * decay) / (1.0F + w); - decay -= result; - damage = (float) count + fp->dmg.x1838_percentTemp; - result = (float) (u32) unk_count * damage; - result = ftd->x110 * damage + ftd->x114 * result; - result = decay * result; - result = ftd->x11C * result + ftd->x120; - x24_f = 0.01F * (float) (u32) hit->x24; - (void) x24_f; - result = x24_f * result + (float) (u32) hit->x2C; - result = arg3 * result; - result = attack * result; - result = defense * result; + { + float decay = ftd->xF8; + result = + defense * + (attack * + (stage * + ((0.01F * (float) (u32) hit->x24 * + (ftd->x11C * + ((decay - ((w * decay) / (1.0F + w))) * + ((ftd->x110 * + ((float) count + fp->dmg.x1838_percentTemp)) + + (ftd->x114 * + ((float) (u32) unk_count * + ((float) count + fp->dmg.x1838_percentTemp))))) + + ftd->x120)) + + (float) (u32) hit->x2C))); + } } if (result >= ftd->x108) { @@ -2297,6 +2339,14 @@ void ftColl_8007A06C(Fighter_GObj* gobj, void* dmg_ptr, void* log, size_t idx, /* 0x28 */ float damage; }; + float dir; + float angle; + float best_kb; + int angle_int; + u32 element; + int sfx_severity; + int best_idx; + int i; Fighter* fp; ftCo_DatAttrs* co; DmgLogEntry* entries; @@ -2304,20 +2354,9 @@ void ftColl_8007A06C(Fighter_GObj* gobj, void* dmg_ptr, void* log, size_t idx, DmgLogEntry* best_entry; struct DmgResult* out; ftCommonData* ftd; - HitCapsule* hit; HitCapsule stack_hit; - float kb; - float best_kb; - float dir; - float angle; - float attack; - int angle_int; - u32 element; - int sfx_severity; - int best_idx; - int i; - PAD_STACK(0xB0); + PAD_STACK(0x98); if (idx == 0) { return; @@ -2327,18 +2366,19 @@ void ftColl_8007A06C(Fighter_GObj* gobj, void* dmg_ptr, void* log, size_t idx, co = &fp->co_attrs; entries = (DmgLogEntry*) log; best_kb = -1.0F; - best_idx = 0; for (i = 0; i < idx; i++) { + float kb; + float attack; entry = &entries[i]; switch (entry->x0) { case 1: { - Fighter* attacker_fp = (Fighter*) entry->gobj->user_data; int unk_count = entry->size_of_xC; - float defense, stage; - - hit = entry->hit0; + Fighter* attacker_fp = (Fighter*) entry->gobj->user_data; + float defense; + float stage; + HitCapsule* hit = entry->hit0; defense = Player_GetDefenseRatio(fp->player_id); attack = Player_GetAttackRatio(attacker_fp->player_id); stage = gm_8016B248(); @@ -2347,12 +2387,14 @@ void ftColl_8007A06C(Fighter_GObj* gobj, void* dmg_ptr, void* log, size_t idx, if (arg4 != 0) { u32 u_dmg = (u32) entry->x20; - int sfx_id = ftColl_803C0CAC[hit->element]; + HitCapsule* sfx_hit = entry->hit0; + Fighter* sfx_fp = gobj->user_data; + int sfx_id = ftColl_803C0CAC[sfx_hit->element]; + int severity = sfx_hit->sfx_severity; switch (sfx_id) { case 0x3E8: - ftColl_80078538(gobj, &entry->pos, u_dmg, - hit->sfx_severity, kb); + ftColl_80078538(gobj, &entry->pos, severity, u_dmg, kb); break; case 0x3E9: case 0x3EA: @@ -2363,7 +2405,7 @@ void ftColl_8007A06C(Fighter_GObj* gobj, void* dmg_ptr, void* log, size_t idx, efSync_Spawn(sfx_id, 0, &entry->pos); break; case 0x3ED: - efSync_Spawn(sfx_id, 0, &entry->pos, &fp->facing_dir); + efSync_Spawn(sfx_id, 0, &entry->pos, &sfx_fp->facing_dir); break; case 0x3EB: break; @@ -2377,6 +2419,7 @@ void ftColl_8007A06C(Fighter_GObj* gobj, void* dmg_ptr, void* log, size_t idx, HSD_GObj* owner_gobj = item->owner; float defense, stage, weight; float w, decay, result; + HitCapsule* hit; if (ftLib_80086960(owner_gobj)) { Fighter* owner_fp = (Fighter*) owner_gobj->user_data; @@ -2432,7 +2475,6 @@ void ftColl_8007A06C(Fighter_GObj* gobj, void* dmg_ptr, void* log, size_t idx, result = decay * result; result = ftd->x11C * result + ftd->x120; x24_f = 0.01F * (float) (u32) hit->x24; - (void) x24_f; result = x24_f * result + (float) (u32) hit->x2C; result = stage * result; result = attack * result; @@ -2447,12 +2489,13 @@ void ftColl_8007A06C(Fighter_GObj* gobj, void* dmg_ptr, void* log, size_t idx, if (arg4 != 0) { u32 u_dmg = (u32) entry->x20; + Fighter* sfx_fp = gobj->user_data; int sfx_id = ftColl_803C0CAC[hit->element]; + int severity = hit->sfx_severity; switch (sfx_id) { case 0x3E8: - ftColl_80078538(gobj, &entry->pos, u_dmg, - hit->sfx_severity, kb); + ftColl_80078538(gobj, &entry->pos, severity, u_dmg, kb); break; case 0x3E9: case 0x3EA: @@ -2463,7 +2506,7 @@ void ftColl_8007A06C(Fighter_GObj* gobj, void* dmg_ptr, void* log, size_t idx, efSync_Spawn(sfx_id, 0, &entry->pos); break; case 0x3ED: - efSync_Spawn(sfx_id, 0, &entry->pos, &fp->facing_dir); + efSync_Spawn(sfx_id, 0, &entry->pos, &sfx_fp->facing_dir); break; case 0x3EB: break; @@ -2561,13 +2604,13 @@ void ftColl_8007A06C(Fighter_GObj* gobj, void* dmg_ptr, void* log, size_t idx, case 1: { Fighter* attacker_fp = (Fighter*) best_entry->gobj->user_data; - hit = best_entry->hit0; + HitCapsule* hit = best_entry->hit0; if (fp->cur_pos.x > attacker_fp->cur_pos.x) { dir = -1.0F; } else { dir = 1.0F; } - angle = (float) (u32) hit->kb_angle; + angle = (float) hit->kb_angle; element = hit->element; sfx_severity = hit->sfx_severity; break; @@ -2577,7 +2620,7 @@ void ftColl_8007A06C(Fighter_GObj* gobj, void* dmg_ptr, void* log, size_t idx, Item* item = (Item*) best_entry->gobj->user_data; float vel_x; - hit = best_entry->hit0; + HitCapsule* hit = best_entry->hit0; vel_x = item->x40_vel.x; if (vel_x < 0.0F) { vel_x = -vel_x; @@ -2595,7 +2638,7 @@ void ftColl_8007A06C(Fighter_GObj* gobj, void* dmg_ptr, void* log, size_t idx, dir = -1.0F; } } - angle = (float) (u32) hit->kb_angle; + angle = (float) hit->kb_angle; element = hit->element; sfx_severity = hit->sfx_severity; break; @@ -2611,9 +2654,6 @@ void ftColl_8007A06C(Fighter_GObj* gobj, void* dmg_ptr, void* log, size_t idx, element = env->element; break; } - - default: - goto end; } if ((u32) best_entry->hit0->kb_angle == 0x16A) { @@ -2668,7 +2708,7 @@ void ftColl_8007A06C(Fighter_GObj* gobj, void* dmg_ptr, void* log, size_t idx, } case 2: { - Item* item_sub = (Item*) best_entry->gobj->user_data; + Item* volatile item_sub = (Item*) best_entry->gobj->user_data; Item* ip = (Item*) item_sub->entity->user_data; HSD_GObj* owner_gobj; @@ -2697,7 +2737,6 @@ void ftColl_8007A06C(Fighter_GObj* gobj, void* dmg_ptr, void* log, size_t idx, break; } -end: if (out->element == 2) { fp->x1960_vibrateMult = p_ftCommonData->x1A4; } @@ -2899,8 +2938,7 @@ void ftColl_8007B128(Fighter_GObj* fighter_gobj, int bone_id, } } - HSD_ASSERTREPORT(0x888, 0, - "in ftCollisionSetHitStatus illegal parts!\n"); + HSD_ASSERTREPORT(0x888, 0, ftColl_803C0CF0); } /// @todo @p shield is #AbsorbDesc, and #AbsorbDesc is part of #ShieldDesc @@ -2953,34 +2991,35 @@ void ftColl_8007B320(Fighter_GObj* gobj) PAD_STACK(8); if (x30->count > 0xF) { - HSD_ASSERTREPORT(0x8C9, 0, "fighter hit num over!\n"); + HSD_ASSERTREPORT(0x8C9, 0, assert_msg_1); } fp->hurt_capsules_len = x30->count; for (i = 0; i < (u32) x30->count; i++) { + FighterHurtCapsule* hurt = &fp->hurt_capsules[i]; ftHurtboxInit* init = &x30->inits[i]; - fp->hurt_capsules[i].capsule.bone_idx = init->bone_idx; - fp->hurt_capsules[i].height = init->height; - fp->hurt_capsules[i].is_grabbable = init->is_grabbable; - fp->hurt_capsules[i].capsule.state = HurtCapsule_Enabled; - fp->hurt_capsules[i].capsule.bone = - fp->parts[fp->hurt_capsules[i].capsule.bone_idx].joint; - fp->hurt_capsules[i].capsule.a_offset = init->a_offset; - fp->hurt_capsules[i].capsule.b_offset = init->b_offset; - fp->hurt_capsules[i].capsule.scale = init->scale; + hurt->capsule.bone_idx = init->bone_idx; + hurt->height = init->height; + hurt->is_grabbable = init->is_grabbable; + hurt->capsule.state = HurtCapsule_Enabled; + hurt->capsule.bone = fp->parts[hurt->capsule.bone_idx].joint; + hurt->capsule.a_offset = init->a_offset; + hurt->capsule.b_offset = init->b_offset; + hurt->capsule.scale = init->scale; } if (dyn->x4 > 0xB) { - HSD_ASSERTREPORT(0x8DF, 0, "fighter dynamics hit num over!\n"); + HSD_ASSERTREPORT(0x8DF, 0, assert_msg_2); } fp->x166C = dyn->x4; for (i = 0; i < (u32) dyn->x4; i++) { + Fighter_x1670_t* dst = &fp->x1670[i]; struct ftData_x38* init = &dyn->x8[i]; - fp->x1670[i].x24 = init->x0; - fp->x1670[i].jobj = fp->parts[init->x0].joint; - fp->x1670[i].v1 = init->x4; - fp->x1670[i].v2 = init->x10; + dst->x24 = init->x0; + dst->jobj = fp->parts[init->x0].joint; + dst->v1 = init->x4; + dst->v2 = init->x10; } } @@ -2991,17 +3030,17 @@ void ftColl_8007B4E0(Fighter_GObj* gobj) int i; for (i = 0; i < (s32) fp->hurt_capsules_len; i++) { + FighterHurtCapsule* hurt = &fp->hurt_capsules[i]; ftHurtboxInit* init = &x30->inits[i]; - fp->hurt_capsules[i].capsule.bone_idx = init->bone_idx; - fp->hurt_capsules[i].height = init->height; - fp->hurt_capsules[i].is_grabbable = init->is_grabbable; - fp->hurt_capsules[i].capsule.state = HurtCapsule_Enabled; - fp->hurt_capsules[i].capsule.bone = - fp->parts[fp->hurt_capsules[i].capsule.bone_idx].joint; - fp->hurt_capsules[i].capsule.a_offset = init->a_offset; - fp->hurt_capsules[i].capsule.b_offset = init->b_offset; - fp->hurt_capsules[i].capsule.scale = init->scale; - fp->hurt_capsules[i].capsule.skip_update_pos = false; + hurt->capsule.bone_idx = init->bone_idx; + hurt->height = init->height; + hurt->is_grabbable = init->is_grabbable; + hurt->capsule.state = HurtCapsule_Enabled; + hurt->capsule.bone = fp->parts[hurt->capsule.bone_idx].joint; + hurt->capsule.a_offset = init->a_offset; + hurt->capsule.b_offset = init->b_offset; + hurt->capsule.scale = init->scale; + hurt->capsule.skip_update_pos = false; } fp->x221A_b6 = false; } @@ -3183,6 +3222,18 @@ void ftColl_8007BA0C(Fighter_GObj* gobj) extern int ft_804D6570; +static inline int ftColl_GetHitStatus(Fighter* fp) +{ + int ret = fp->x221D_b6 ? 1 : 0; + if (fp->x1988 > ret) { + ret = fp->x1988; + } + if (fp->x198C > ret) { + ret = fp->x198C; + } + return ret; +} + void ftColl_8007BAC0(Fighter_GObj* gobj) { int max; @@ -3200,26 +3251,16 @@ void ftColl_8007BAC0(Fighter_GObj* gobj) { fp = gobj->user_data; - if (fp->x221D_b6) { - max = 1; - } else { - max = 0; - } - if (fp->x1988 > max) { - max = fp->x1988; - } - if (fp->x198C > max) { - max = fp->x198C; - } - - arr = &ft_80459A8C; + max = ftColl_GetHitStatus(fp); for (i = 0; i < ft_804D6570; i++) { - ground = arr[i].ground; + ground = ft_80459A68[i + 3].ground; if (ground != NULL) { - type = arr[i].type; + type = ft_80459A68[i + 3].type; if (ftCo_800C0A28(gobj, ground, type)) { - if (arr[i].active_cb(ground, gobj, (Vec3*) &desc)) { + if (ft_80459A68[i + 3].active_cb(ground, gobj, + (Vec3*) &desc)) + { if (max == 0) { ftCo_800C08A0(gobj, (Fighter_GObj*) ground, desc, type); @@ -3460,7 +3501,7 @@ void ftColl_8007BE3C(Fighter_GObj* gobj) float x187c = fp->dmg.x187c; u32 dmg_unsigned = fp->dmg.x1898; u32 x1890 = fp->dmg.x1890; - int effect_idx = ftColl_803C0CAC[fp->dmg.x188c]; + int effect_idx = data_ptr[27 + fp->dmg.x188c]; Fighter* vfp = gobj->user_data; switch (effect_idx) { case 1000: diff --git a/src/melee/ft/ftcoll.h b/src/melee/ft/ftcoll.h index 12c6dfd294..81276a3b81 100644 --- a/src/melee/ft/ftcoll.h +++ b/src/melee/ft/ftcoll.h @@ -44,7 +44,7 @@ /* 0784B4 */ void ftColl_800784B4(Fighter*, HitCapsule*, HitCapsule*); /* 078538 */ void ftColl_80078538(Fighter_GObj*, Vec3*, u32, float, float); /* 07861C */ UNK_RET ftColl_8007861C(Fighter_GObj*, Fighter_GObj* gobj, int, - int, int, UNK_T, u16, UNK_T, int); + int, int, UNK_T, int, UNK_T, int); /* 078710 */ void ftColl_80078710(Fighter_GObj*, Fighter_GObj*, UNK_T arg2); /* 078754 */ void ftColl_80078754(Fighter_GObj*, Fighter_GObj*, bool); /* 0787B4 */ void ftColl_800787B4(Item_GObj*, Fighter_GObj*, int); diff --git a/src/melee/ft/ftcpuattack.c b/src/melee/ft/ftcpuattack.c index 2905940277..17981a543c 100644 --- a/src/melee/ft/ftcpuattack.c +++ b/src/melee/ft/ftcpuattack.c @@ -89,28 +89,28 @@ int ftCo_800B4AB0(Fighter* fp, Fighter* target, void* arg2) f32 acc; f32 t; f32 fpPredY; - f32 relx; f32 relPredY; f32 v; f32 sq; f32 scale; f32 diry; - f32 rangeF; - f32 rangeB; - f32 halfRange; - f32 fpTermNeg; - f32 tgtTermNeg; + f32 fpX; f32 fpY; + f32 fpVx; f32 fpVy; - f32 tgtVx; + f32 fpTermNeg; + f32 fpGrav; + f32 tgtX; f32 tgtY; + f32 tgtVx; f32 tgtVy; + f32 tgtTermNeg; f32 tgtGrav; - f32 fpX; - f32 fpVx; - f32 tgtX; - f32 fpGrav; + f32 rangeF; + f32 rangeB; f32 x568; + f32 relx; + f32 halfRange; cpu->x74.y = 0.0f; cpu->x74.x = 0.0f; @@ -122,16 +122,16 @@ int ftCo_800B4AB0(Fighter* fp, Fighter* target, void* arg2) } fpTermNeg = -fp->co_attrs.terminal_vel; tgtTermNeg = -target->co_attrs.terminal_vel; + fpX = fp->cur_pos.x; fpY = fp->cur_pos.y; + fpVx = fp->pos_delta.x; fpVy = fp->pos_delta.y; fpGrav = fp->co_attrs.grav; + tgtX = target->cur_pos.x; tgtY = target->cur_pos.y; + tgtVx = target->pos_delta.x; tgtVy = target->pos_delta.y; - fpX = fp->cur_pos.x; tgtGrav = target->co_attrs.grav; - fpVx = fp->pos_delta.x; - tgtX = target->cur_pos.x; - tgtVx = target->pos_delta.x; if (target->facing_dir > 0.0) { rangeF = target->x1A88.x55C; rangeB = target->x1A88.x560; @@ -187,7 +187,7 @@ int ftCo_800B4AB0(Fighter* fp, Fighter* target, void* arg2) } else { fpPredY = fpVy * t + fpY; } - if ((u32) target->ground_or_air == GA_Air) { + if (target->ground_or_air == GA_Air) { if (tgtGrav < 0.00001f && tgtGrav > -0.00001f) { nearzero = true; } else { @@ -301,20 +301,20 @@ int ftCo_800B52AC(Fighter* fp, Fighter* target, void* arg2, f32 reach) f32 diry; f32 rangeF; f32 rangeB; + f32 halfRange; f32 fpTermNeg; f32 tgtTermNeg; - f32 fpX; f32 fpY; - f32 fpVx; f32 fpVy; - f32 fpGrav; - f32 tgtX; - f32 tgtY; f32 tgtVx; + f32 tgtY; f32 tgtVy; f32 tgtGrav; + f32 fpX; + f32 fpVx; f32 x568; - f32 halfRange; + f32 fpGrav; + f32 tgtX; PAD_STACK(0x10); @@ -338,7 +338,7 @@ int ftCo_800B52AC(Fighter* fp, Fighter* target, void* arg2, f32 reach) tgtVx = target->pos_delta.x; tgtVy = target->pos_delta.y; tgtGrav = target->co_attrs.grav; - if (target->facing_dir > 0.0f) { + if (target->facing_dir > 0.0) { rangeF = target->x1A88.x55C; rangeB = target->x1A88.x560; } else { @@ -349,8 +349,6 @@ int ftCo_800B52AC(Fighter* fp, Fighter* target, void* arg2, f32 reach) count = 0; while (list->cmd) { f32 dirx; - f32 yHi; - f32 yLo; found = false; if (list->x20 > cpu->level) { list++; @@ -432,7 +430,7 @@ int ftCo_800B52AC(Fighter* fp, Fighter* target, void* arg2, f32 reach) } scale = fp->x34_scale.y; (void) scale; - if ((list->x14 * scale + reach) * halfRange > relPredY && + if ((scale * list->x14 + reach) * halfRange > relPredY && list->x10 * scale * halfRange < relPredY + x568 && dirx * halfRange < relx + rangeF && diry * halfRange > relx - rangeB) @@ -484,7 +482,7 @@ int ftCo_800B52AC(Fighter* fp, Fighter* target, void* arg2, f32 reach) int ftCo_800B5AB0(Fighter* fp, void* arg1, void* arg2) { - u8 operand_pad[12]; + u8 operand_pad[4]; ftCo_AttackEntry sp34[32]; ftCo_x50_t* x50 = arg1; ftCo_x50_attr* attrs; @@ -498,7 +496,7 @@ int ftCo_800B5AB0(Fighter* fp, void* arg1, void* arg2) bool nearzero; f32 r; f32 sum; - f32 acc; + f32 fpTermNeg; f32 inv; f32 fpPredY; f32 relPredY; @@ -506,18 +504,18 @@ int ftCo_800B5AB0(Fighter* fp, void* arg1, void* arg2) f32 sq; f32 diry; f32 sizeHalf; - f32 fpTermNeg; - f32 fpY; + f32 acc; f32 fpVy; - f32 fpGrav; + f32 fpY; f32 fpX; + f32 fpGrav; f32 fpVx; f32 x50TermNeg; f32 x50Y; f32 x50Vy; - f32 x50Grav; - f32 x50X; f32 x50Vx; + f32 x50X; + f32 x50Grav; f32 yBound; cpu = &fp->x1A88; @@ -627,7 +625,7 @@ int ftCo_800B5AB0(Fighter* fp, void* arg1, void* arg2) } scale = fp->x34_scale.y; if (list->x14 * scale > relPredY && - list->x10 * scale < relPredY + yBound && dirx < relx + sizeHalf && + relPredY + yBound > list->x10 * scale && dirx < relx + sizeHalf && diry > relx - sizeHalf) { if (cpu->xC8 != 0) { @@ -1291,6 +1289,7 @@ int ftCo_800B7638(Fighter* fp) void ftCo_800B77E8(Fighter* fp) { + u8 _[0x28]; struct Fighter_x1A88_t* cpu = &fp->x1A88; ftCo_CollData c1; ftCo_CollData c2; @@ -1534,7 +1533,8 @@ void ftCo_800B77E8(Fighter* fp) can_attack = 1; } else if (fp->facing_dir > 0.0) { y = fp->cur_pos.y; - x = fp->cur_pos.x + 27.0f; + x = fp->cur_pos.x; + x += 27.0f; if (ftCo_800A0FB0(&c6.p, &c6.line, &c6.flags, &c6.n, -1, -1, -1, x, 5.0 + y, x, y - 1000.0, 0.0f) == 0) { @@ -1581,7 +1581,8 @@ void ftCo_800B77E8(Fighter* fp) can_attack = 1; } else if (fp->facing_dir > 0.0) { y = fp->cur_pos.y; - x = fp->cur_pos.x + 53.0f; + x = fp->cur_pos.x; + x += 53.0f; if (ftCo_800A0FB0(&c7.p, &c7.line, &c7.flags, &c7.n, -1, -1, -1, x, 5.0 + y, x, y - 1000.0, 0.0f) == 0) { @@ -1628,7 +1629,8 @@ void ftCo_800B77E8(Fighter* fp) can_attack = 1; } else if (fp->facing_dir > 0.0) { y = fp->cur_pos.y; - x = fp->cur_pos.x + 16.0f; + x = fp->cur_pos.x; + x += 16.0f; if (ftCo_800A0FB0(&c8.p, &c8.line, &c8.flags, &c8.n, -1, -1, -1, x, 5.0 + y, x, y - 1000.0, 0.0f) == 0) { @@ -1711,7 +1713,8 @@ void ftCo_800B77E8(Fighter* fp) can_attack = 1; } else if (fp->facing_dir > 0.0) { y = fp->cur_pos.y; - x = fp->cur_pos.x + 32.0f; + x = fp->cur_pos.x; + x += 32.0f; if (ftCo_800A0FB0(&c10.p, &c10.line, &c10.flags, &c10.n, -1, -1, -1, x, 5.0 + y, x, y - 1000.0, 0.0f) == 0) { @@ -2801,6 +2804,7 @@ bool ftCo_800BB104(Fighter* fp, Fighter* arg1, Vec3* arg2, f32 arg3) int ftCo_800BB220(Fighter* fp, Item* ip, Vec3* arg2, f32 arg3) { + UNUSED u8 padD8[8]; Vec3 dst; HitCapsule* hit; int i; @@ -2809,7 +2813,7 @@ int ftCo_800BB220(Fighter* fp, Item* ip, Vec3* arg2, f32 arg3) bool result; struct Fighter_x1A88_t* temp_r31 = &fp->x1A88; - PAD_STACK(0x38); + PAD_STACK(8); if (ip->owner == fp->gobj) { return 0; @@ -2830,14 +2834,17 @@ int ftCo_800BB220(Fighter* fp, Item* ip, Vec3* arg2, f32 arg3) return 0; } - if (fp->x1A88.level < 3) { - count = (s32) (20.0f * HSD_Randf()) + 10; - } else if (temp_r31->level < 6) { - count = (s32) (10.0f * HSD_Randf()) + 5; - } else if (temp_r31->level < 9) { - count = (s32) (5.0f * HSD_Randf()) + 3; - } else { - count = 1; + { + struct Fighter_x1A88_t* cpu = &fp->x1A88; + if (fp->x1A88.level < 3) { + count = (s32) (20.0f * HSD_Randf()) + 10; + } else if (cpu->level < 6) { + count = (s32) (10.0f * HSD_Randf()) + 5; + } else if (cpu->level < 9) { + count = (s32) (5.0f * HSD_Randf()) + 3; + } else { + count = 1; + } } dst.x = fp->pos_delta.x * count + arg2->x; @@ -2848,27 +2855,25 @@ int ftCo_800BB220(Fighter* fp, Item* ip, Vec3* arg2, f32 arg3) if (count < 21) { Vec3 spB8; Vec3 spAC; + UNUSED u8 padA0[0xC]; Vec3 sp94; + f32 dx, dy, dz; for (i = 0; i < 4; i++) { state = ip->x5D4_hitboxes[i].hit.state; hit = &ip->x5D4_hitboxes[i].hit; if (state != HitCapsule_Disabled && state != HitCapsule_Enabled && !hit->x43_b2 && - hit->element != 0xB && !lbColl_8000ACFC(fp, hit)) + hit->element != 0xB && !lbColl_8000ACFC(fp, hit) && + (dx = hit->x4C.x - hit->x58.x, + dy = hit->x4C.y - hit->x58.y, + dz = hit->x4C.z - hit->x58.z, + sp94.x = dx * count + hit->x4C.x, + sp94.y = dy * count + hit->x4C.y, + sp94.z = dz * count + hit->x4C.z, + lbColl_80006094(&hit->x4C, &sp94, arg2, &dst, &spAC, + &spB8, hit->scale, arg3))) { - f32 dx = hit->x4C.x - hit->x58.x; - f32 dy = hit->x4C.y - hit->x58.y; - f32 dz = hit->x4C.z - hit->x58.z; - sp94.x = dx * count + hit->x4C.x; - sp94.y = dy * count + hit->x4C.y; - sp94.z = dz * count + hit->x4C.z; - if (lbColl_80006094(&hit->x4C, &sp94, arg2, &dst, &spAC, - &spB8, hit->scale, arg3)) - { - result = true; - } else { - result = false; - } + result = true; } else { result = false; } @@ -2876,31 +2881,28 @@ int ftCo_800BB220(Fighter* fp, Item* ip, Vec3* arg2, f32 arg3) return 2; } } - return 0; } else { Vec3 sp84; Vec3 sp78; + UNUSED u8 pad6C[0xC]; Vec3 sp60; + f32 dx, dy, dz; for (i = 0; i < 4; i++) { state = ip->x5D4_hitboxes[i].hit.state; hit = &ip->x5D4_hitboxes[i].hit; if (state != HitCapsule_Disabled && state != HitCapsule_Enabled && !hit->x43_b2 && - hit->element != 0xB && !lbColl_8000ACFC(fp, hit)) + hit->element != 0xB && !lbColl_8000ACFC(fp, hit) && + (dx = hit->x4C.x - hit->x58.x, + dy = hit->x4C.y - hit->x58.y, + dz = hit->x4C.z - hit->x58.z, + sp60.x = dx * count + hit->x4C.x, + sp60.y = dy * count + hit->x4C.y, + sp60.z = dz * count + hit->x4C.z, + lbColl_80006094(&hit->x4C, &sp60, arg2, &dst, &sp78, + &sp84, hit->scale, arg3))) { - f32 dx = hit->x4C.x - hit->x58.x; - f32 dy = hit->x4C.y - hit->x58.y; - f32 dz = hit->x4C.z - hit->x58.z; - sp60.x = dx * count + hit->x4C.x; - sp60.y = dy * count + hit->x4C.y; - sp60.z = dz * count + hit->x4C.z; - if (lbColl_80006094(&hit->x4C, &sp60, arg2, &dst, &sp78, - &sp84, hit->scale, arg3)) - { - result = true; - } else { - result = false; - } + result = true; } else { result = false; } @@ -2911,34 +2913,29 @@ int ftCo_800BB220(Fighter* fp, Item* ip, Vec3* arg2, f32 arg3) return 2; } } - return 0; } - } - - { + } else { Vec3 sp50; Vec3 sp44; + UNUSED u8 pad38[0xC]; Vec3 sp2C; + UNUSED u8 pad24[8]; + f32 dx, dy, dz; for (i = 0; i < 4; i++) { state = ip->x5D4_hitboxes[i].hit.state; hit = &ip->x5D4_hitboxes[i].hit; if (state != HitCapsule_Disabled && state != HitCapsule_Enabled && !hit->x43_b2 && hit->element != 0xB && - !lbColl_8000ACFC(fp, hit)) + !lbColl_8000ACFC(fp, hit) && + (dx = hit->x4C.x - hit->x58.x, dy = hit->x4C.y - hit->x58.y, + dz = hit->x4C.z - hit->x58.z, + sp2C.x = dx * count + hit->x4C.x, + sp2C.y = dy * count + hit->x4C.y, + sp2C.z = dz * count + hit->x4C.z, + lbColl_80006094(&hit->x4C, &sp2C, arg2, &dst, &sp44, &sp50, + hit->scale, arg3))) { - f32 dx = hit->x4C.x - hit->x58.x; - f32 dy = hit->x4C.y - hit->x58.y; - f32 dz = hit->x4C.z - hit->x58.z; - sp2C.x = dx * count + hit->x4C.x; - sp2C.y = dy * count + hit->x4C.y; - sp2C.z = dz * count + hit->x4C.z; - if (lbColl_80006094(&hit->x4C, &sp2C, arg2, &dst, &sp44, &sp50, - hit->scale, arg3)) - { - result = true; - } else { - result = false; - } + result = true; } else { result = false; } diff --git a/src/melee/ft/ftdynamics.c b/src/melee/ft/ftdynamics.c index 66ce2e53ca..1081e98439 100644 --- a/src/melee/ft/ftdynamics.c +++ b/src/melee/ft/ftdynamics.c @@ -458,6 +458,8 @@ static inline bool inlineA0(Fighter* fp) void ftCo_8009DC54(Fighter* fp) { + DynamicsDesc* desc; + ssize_t i; ssize_t idx; ftData* data = fp->ft_data; if (fp->x619_costume_id == 2) { @@ -472,11 +474,12 @@ void ftCo_8009DC54(Fighter* fp) "fighter dynamics num over!\n"); { ssize_t bone_idx = idx * 2 + 1; - BoneDynamicsDesc* dyn = fp->dynamic_bone_sets; - ssize_t i = 0; + ssize_t dyn_idx = 0; + i = 0; do { HSD_JObj* cur = fp->fv.kb.hat.jobj; ftDynamics* dynamics = data->x2C; + ArticleDynamicBones* bones = dynamics->ftDynamicBones; ssize_t j; for (j = 0; j < @@ -493,18 +496,17 @@ void ftCo_8009DC54(Fighter* fp) cur = cur->next; } { - DynamicsDesc* desc = &fp->dynamic_bone_sets[i + 1].dyn_desc; - lb_8000FD48( - cur, desc, - data->x2C->ftDynamicBones->array[bone_idx].dyn_desc.count); - dyn[1].bone_id = FtPart_TopN; + desc = &fp->dynamic_bone_sets[i + 1].dyn_desc; + lb_8000FD48(cur, desc, + bones->array[bone_idx].dyn_desc.count); + fp->dynamic_bone_sets[dyn_idx + 1].bone_id = FtPart_TopN; lb_80011710( &data->x2C->ftDynamicBones->array[bone_idx].dyn_desc, desc); } i++; bone_idx++; - dyn++; + dyn_idx++; } while (i < 2); } } @@ -815,53 +817,53 @@ void ftCo_8009E7B4(Fighter* fp, u8 (*arg1)[2]) } } } - } else if (fp->x594_b4) { - FigaTree*** dyn; - FigaTree** tree; - u8 blend_slot = arg1[0][1]; - dyn = fp->ft_data->x2C->x10; - if (dyn == NULL) { - s32 i; - for (i = 0; i < fp->dynamics_num; i++) { - ftCo_8009CB40(fp, i, 0, NULL); - } - return; - } - tree = dyn[blend_slot]; - if (tree == NULL) { - s32 i; - for (i = 0; i < fp->dynamics_num; i++) { - ftCo_8009CB40(fp, i, 0, NULL); - } - return; - } - { - s32 i; - for (i = 0; i < fp->dynamics_num; i++) { - ftCo_8009CB40(fp, i, 1, tree[i]); - } - } - return; } else { s32 i; - if (fp->x594_b3) { - if (fp->kind != FTKIND_KIRBY) { - if (fp->kind == FTKIND_PURIN) { - ftCo_8009CB40(fp, 0, 0, NULL); - return; + if (fp->x594_b4) { + FigaTree*** dyn; + FigaTree** tree; + u8 blend_slot = arg1[0][1]; + dyn = fp->ft_data->x2C->x10; + if (dyn == NULL) { + for (i = 0; i < fp->dynamics_num; i++) { + ftCo_8009CB40(fp, i, 0, NULL); } + return; + } + tree = dyn[blend_slot]; + if (tree == NULL) { for (i = 0; i < fp->dynamics_num; i++) { ftCo_8009CB40(fp, i, 0, NULL); } + return; + } + { + s32 j; + for (j = 0; j < fp->dynamics_num; j++) { + ftCo_8009CB40(fp, j, 1, tree[j]); + } } + return; } else { - if (fp->kind != FTKIND_KIRBY) { - if (fp->kind == FTKIND_PURIN) { - ftCo_8009CB40(fp, 0, 1, NULL); - return; + if (fp->x594_b3) { + if (fp->kind != FTKIND_KIRBY) { + if (fp->kind == FTKIND_PURIN) { + ftCo_8009CB40(fp, 0, 0, NULL); + return; + } + for (i = 0; i < fp->dynamics_num; i++) { + ftCo_8009CB40(fp, i, 0, NULL); + } } - for (i = 0; i < fp->dynamics_num; i++) { - ftCo_8009CB40(fp, i, 1, NULL); + } else { + if (fp->kind != FTKIND_KIRBY) { + if (fp->kind == FTKIND_PURIN) { + ftCo_8009CB40(fp, 0, 1, NULL); + return; + } + for (i = 0; i < fp->dynamics_num; i++) { + ftCo_8009CB40(fp, i, 1, NULL); + } } } } diff --git a/src/melee/gm/gm_1601.c b/src/melee/gm/gm_1601.c index 1ce98a2c05..378a273d59 100644 --- a/src/melee/gm/gm_1601.c +++ b/src/melee/gm/gm_1601.c @@ -511,42 +511,42 @@ bool gm_80160474(CharacterKind ckind, GameModeKind scene) char* gm_801604DC(CharacterKind ckind, GameModeKind scene) { - s16 var_r3; + s32 trophy_id; switch (scene) { case GM_CLASSIC_GOVER: case GM_CLASSIC: - var_r3 = lbl_803B7978[ckind]; + trophy_id = lbl_803B7978[ckind]; break; case GM_ADVENTURE_GOVER: case GM_ADVENTURE: - var_r3 = lbl_803B79BC[ckind]; + trophy_id = lbl_803B79BC[ckind]; break; default: - var_r3 = lbl_803B7A00[ckind]; + trophy_id = lbl_803B7A00[ckind]; break; } - return Toy_8030813C(var_r3, scene) + 4; + return Toy_8030813C(trophy_id, scene) + 4; } char* gm_80160564(CharacterKind ckind, GameModeKind scene) { - s16 var_r3; + s32 toy_id; switch (scene) { case GM_CLASSIC_GOVER: case GM_CLASSIC: - var_r3 = lbl_803B7978[ckind]; + toy_id = lbl_803B7978[ckind]; break; case GM_ADVENTURE_GOVER: case GM_ADVENTURE: - var_r3 = lbl_803B79BC[ckind]; + toy_id = lbl_803B79BC[ckind]; break; default: - var_r3 = lbl_803B7A00[ckind]; + toy_id = lbl_803B7A00[ckind]; break; } - return Toy_8030813C(var_r3, scene) + 0x24; + return Toy_8030813C(toy_id, scene) + 0x24; } u8 fn_801605EC(s32 arg0) @@ -784,16 +784,22 @@ const char* gm_80160A60(int arg0) return NULL; } +static inline void gm_80160B40_init_text(HSD_Text* text, HSD_Text** tmp_text) +{ + *tmp_text = text; + if (lbLang_IsSavedLanguageUS()) { + text->default_kerning = 1; + } +} + void gm_80160B40(HSD_Text* text, u8 ckind, u8 arg2) { - HSD_Text* tmp_text = text; u8 tmp_ckind = ckind; + HSD_Text* tmp_text; f32 var_f31; const char* str; - if (lbLang_IsSavedLanguageUS()) { - tmp_text->default_kerning = 1; - } + gm_80160B40_init_text(text, &tmp_text); str = arg2 ? fn_801609E0(tmp_ckind) : gm_80160980(tmp_ckind); if (lbLang_IsSavedLanguageUS()) { bool tmp = arg2 && lbl_803D50E4[tmp_ckind] != NULL; @@ -806,40 +812,47 @@ void gm_80160B40(HSD_Text* text, u8 ckind, u8 arg2) tmp_text->font_size.x *= var_f31; } -void gm_80160C90(HSD_Text* text, u8 fighter_id, bool arg2) +void gm_80160C90(HSD_Text* text, u8 fighter_id, u8 arg2) { - f32 name_scale; - bool use_alt_name; + HSD_Text* tmp_text = text; + u8 tmp_ckind = fighter_id; const char* str; + f32 size; + bool use_alt_name; if (lbLang_IsSavedLanguageUS() != 0) { text->default_kerning = 1; } - str = ((u8) arg2 != 0) ? fn_801609E0(fighter_id) : gm_80160980(fighter_id); + str = arg2 ? fn_801609E0(tmp_ckind) : gm_80160980(tmp_ckind); + if (lbLang_IsSavedLanguageUS() != 0) { + f32 temp; use_alt_name = false; - if ((u8) arg2 != 0 && lbl_803D50E4[fighter_id] != NULL) { + if (arg2 && lbl_803D50E4[tmp_ckind] != NULL) { use_alt_name = true; } if (use_alt_name) { - name_scale = lbl_803B7784[fighter_id]; + temp = lbl_803B7784[tmp_ckind]; } else { - name_scale = lbl_803B767C[fighter_id]; + temp = lbl_803B767C[tmp_ckind]; } + size = temp; } else { + f32 temp; use_alt_name = false; - if ((u8) arg2 != 0 && lbl_803D5060[fighter_id] != NULL) { + if (arg2 && lbl_803D5060[tmp_ckind] != NULL) { use_alt_name = true; } if (use_alt_name) { - name_scale = lbl_803B7700[fighter_id]; + temp = lbl_803B7700[tmp_ckind]; } else { - name_scale = lbl_803B75F8[fighter_id]; + temp = lbl_803B75F8[tmp_ckind]; } + size = temp; } HSD_SisLib_803A7548( - text, HSD_SisLib_803A6B98(text, 0.0F, 0.0F, str, use_alt_name), - name_scale, 1.0F); + tmp_text, HSD_SisLib_803A6B98(tmp_text, 0.0F, 0.0F, str, use_alt_name), + size, 1.0F); } void fn_80160DE8(HSD_JObj* arg0, u8 arg1, s32 arg2, u8 arg3, f32 farg0, @@ -927,14 +940,13 @@ s32 fn_80161004(MatchEnd* match_end) s32 fn_80161154(MatchEnd* arg0) { - u8 operand_pad[4]; - u8 spC[4]; - MatchPlayerData* var_r31; + u8 spC[12]; + MatchPlayerData* best_player; s32 idx; s32 cnt; MatchPlayerData* player; s32 i; - s32 var_r3 = fn_80161004(arg0); + s32 result = fn_80161004(arg0); idx = 4; cnt = 0; @@ -942,7 +954,7 @@ s32 fn_80161154(MatchEnd* arg0) for (i = 0; i < 4; i++) { player = &arg0->player_standings[i]; if (player->slot_type != 3 && - arg0->team_standings[player->team].is_big_loser == var_r3) + arg0->team_standings[player->team].is_big_loser == result) { spC[i] = 1; cnt = 1; @@ -954,7 +966,7 @@ s32 fn_80161154(MatchEnd* arg0) } else { for (i = 0; i < 4; i++) { player = &arg0->player_standings[i]; - if (player->slot_type != 3 && player->is_big_loser == var_r3) { + if (player->slot_type != 3 && player->is_big_loser == result) { if (idx != 4) { cnt = 1; } else { @@ -973,20 +985,21 @@ s32 fn_80161154(MatchEnd* arg0) idx = 4; for (i = 0; i < 4; i++) { if (spC[i]) { - player = &arg0->player_standings[i]; - if (idx == 4 || - (u32) arg0->player_standings[idx].x20 > (u32) player->x20) + if (idx == 4) { + idx = i; + } else if ((u32) arg0->player_standings[idx].x20 > + (u32) arg0->player_standings[i].x20) { idx = i; } - var_r31 = &arg0->player_standings[idx]; + best_player = &arg0->player_standings[idx]; } } cnt = 0; for (i = 0; i < 4; i++) { if (spC[i] && idx != i) { player = &arg0->player_standings[i]; - if ((u32) player->x20 == (u32) var_r31->x20) { + if ((u32) player->x20 == (u32) best_player->x20) { cnt += 1; } else { spC[i] = 0; @@ -1000,20 +1013,21 @@ s32 fn_80161154(MatchEnd* arg0) idx = 4; for (i = 0; i < 4; i++) { if (spC[i]) { - player = &arg0->player_standings[i]; - if (idx == 4 || - (u32) arg0->player_standings[idx].x24 < (u32) player->x24) + if (idx == 4) { + idx = i; + } else if ((u32) arg0->player_standings[idx].x24 < + (u32) arg0->player_standings[i].x24) { idx = i; } - var_r31 = &arg0->player_standings[idx]; + best_player = &arg0->player_standings[idx]; } } cnt = 0; for (i = 0; i < 4; i++) { if (spC[i] && idx != i) { player = &arg0->player_standings[i]; - if ((u32) player->x24 == (u32) var_r31->x24) { + if ((u32) player->x24 == (u32) best_player->x24) { cnt += 1; } else { spC[i] = 0; @@ -1027,18 +1041,21 @@ s32 fn_80161154(MatchEnd* arg0) idx = 4; for (i = 0; i < 4; i++) { if (spC[i]) { - player = &arg0->player_standings[i]; - if (idx == 4 || arg0->player_standings[idx].x44 > player->x44) { + if (idx == 4) { + idx = i; + } else if (arg0->player_standings[idx].x44 > + arg0->player_standings[i].x44) + { idx = i; } - var_r31 = &arg0->player_standings[idx]; + best_player = &arg0->player_standings[idx]; } } cnt = 0; for (i = 0; i < 4; i++) { if (spC[i] && idx != i) { player = &arg0->player_standings[i]; - if (player->x44 == var_r31->x44) { + if (player->x44 == best_player->x44) { cnt += 1; } else { spC[i] = 0; @@ -1052,18 +1069,21 @@ s32 fn_80161154(MatchEnd* arg0) idx = 4; for (i = 0; i < 4; i++) { if (spC[i]) { - player = &arg0->player_standings[i]; - if (idx == 4 || arg0->player_standings[idx].x50 < player->x50) { + if (idx == 4) { + idx = i; + } else if ((u32) arg0->player_standings[idx].x50 < + (u32) arg0->player_standings[i].x50) + { idx = i; } - var_r31 = &arg0->player_standings[idx]; + best_player = &arg0->player_standings[idx]; } } cnt = 0; for (i = 0; i < 4; i++) { if (spC[i] && idx != i) { player = &arg0->player_standings[i]; - if (player->x50 == var_r31->x50) { + if ((u32) player->x50 == (u32) best_player->x50) { cnt += 1; } else { spC[i] = 0; @@ -1073,19 +1093,15 @@ s32 fn_80161154(MatchEnd* arg0) if (cnt == 0) { return idx; } - if (spC[0]) { - return 0; - } - if (spC[1]) { - return 1; - } - if (spC[2]) { - return 2; - } - if (spC[3]) { - var_r3 = 3; + { + s32 j; + for (j = 0; j < 4; j++) { + if (spC[j]) { + return j; + } + } + return result; } - return var_r3; } struct gm_stats { @@ -1117,9 +1133,9 @@ void fn_80161C90(MatchEnd* arg0, int arg1, u16* arg2) struct gm_stats* s = (struct gm_stats*) arg2; u32 count; s32 flag; + s32 i; PAD_STACK(8); - s->unk0 = (s->unk0 + p->self_destructs > 0xFFFF) ? 0xFFFF : s->unk0 + p->self_destructs; @@ -1137,13 +1153,15 @@ void fn_80161C90(MatchEnd* arg0, int arg1, u16* arg2) s->unk18 = p->x4C; } s->unk1A = (s->unk1A + 1 > 0xFFFF) ? 0xFFFF : s->unk1A + 1; - if (arg1 == fn_80165548(arg0, fn_80165418(arg0), fn_801654A0(arg0))) { - flag = 1; - } else { - flag = 0; - } - if (flag != 0) { - s->unk1C = (s->unk1C + 1 > 0xFFFF) ? 0xFFFF : s->unk1C + 1; + { + if (arg1 == fn_80165548(arg0, fn_80165418(arg0), fn_801654A0(arg0))) { + flag = 1; + } else { + flag = 0; + } + if (flag != 0) { + s->unk1C = (s->unk1C + 1 > 0xFFFF) ? 0xFFFF : s->unk1C + 1; + } } if (arg1 == fn_80161154(arg0)) { flag = 1; @@ -1157,17 +1175,10 @@ void fn_80161C90(MatchEnd* arg0, int arg1, u16* arg2) ? 0xFFFFFFFFU : s->unk20 + arg0->frame_count / 60; count = 0; - if (arg0->player_standings[0].slot_type != 3) { - count = 1; - } - if (arg0->player_standings[1].slot_type != 3) { - count += 1; - } - if (arg0->player_standings[2].slot_type != 3) { - count += 1; - } - if (arg0->player_standings[3].slot_type != 3) { - count += 1; + for (i = 0; i < 4; i++) { + if (arg0->player_standings[i].slot_type != 3) { + count += 1; + } } count = s->unk24 + count; if (count > 0xFFFF) { @@ -1233,47 +1244,51 @@ void fn_80162068(MatchEnd* match_end) static inline void fn_80162170_inner(MatchEnd* arg0) { + MatchPlayerData* p; s32 i; s32 j; - MatchPlayerData* p; + MatchEnd* cur; MatchPlayerData* q; s32 play_time; - for (i = 0; i < 4; i++) { - p = &arg0->player_standings[i]; - if (p->slot_type != 3) { - if (p->x4 != 0x78) { - struct NameTagData* nt = GetPersistentNameData(p->x4); - for (j = 0; j < 4; j++) { - q = &arg0->player_standings[j]; - if (i != j && q->slot_type != 3) { - u8 ock = q->x4; - if (ock != 0x78) { - s32 v = p->kills[j] + nt->vs_kos[ock]; - if (v > 0xFFFF) { - v = 0xFFFF; - } - nt->vs_kos[ock] = v; + for (i = 0, cur = arg0; i < 4; + i++, cur = (MatchEnd*) ((MatchPlayerData*) cur + 1)) + { + p = cur->player_standings; + if (p->slot_type == 3) { + continue; + } + if (p->x4 == 0x78) { + continue; + } + { + struct NameTagData* nt = GetPersistentNameData(p->x4); + for (j = 0; j < 4; j++) { + q = &arg0->player_standings[j]; + if (i != j && q->slot_type != 3) { + u8 ock = q->x4; + if (ock != 0x78) { + s32 v = p->kills[j] + nt->vs_kos[ock]; + if (v > 0xFFFF) { + v = 0xFFFF; } + nt->vs_kos[ock] = v; } } - { - { - u32 sum = nt->play_time_by_fighter[gm_80164024( + } + { + u32 sum = + nt->play_time_by_fighter[gm_80164024(p->character_kind)] + + arg0->frame_count / 60; + play_time = ((u32) sum > (u32) -1) + ? -1 + : nt->play_time_by_fighter[gm_80164024( p->character_kind)] + - arg0->frame_count / 60; - play_time = -1; - if ((u32) sum <= (u32) play_time) { - play_time = nt->play_time_by_fighter[gm_80164024( - p->character_kind)] + - arg0->frame_count / 60; - } - } - nt->play_time_by_fighter[gm_80164024(p->character_kind)] = - play_time; - } - fn_80161C90(arg0, i, &nt->sd_count); + arg0->frame_count / 60; + nt->play_time_by_fighter[gm_80164024(p->character_kind)] = + play_time; } + fn_80161C90(arg0, i, &nt->sd_count); } } } @@ -1319,44 +1334,47 @@ void gm_801623FC(int arg0) s32 gm_8016247C(s32 arg0) { - u32 var_r4; - u32 var_r3; - u32 var_r29; - u32* temp_r31; - u32* temp_r5; - u32* temp_r30_2; - u32* temp_r3; - s32 temp_r29 = *gmMainLib_8015CCF0(); - u32* temp_r30 = gmMainLib_8015CCFC(); + u32 total; + u32 session_total; + u32 capped_total; + u32* high_score_ptr; + u32* session_high_score_ptr; + u32* current_score_ptr; + u32* session_high_score_ptr2; + s32 current_score = *gmMainLib_8015CCF0(); + u32* high_score_ptr2 = gmMainLib_8015CCFC(); - temp_r5 = &gmMainLib_8015EDBC()->x14; + session_high_score_ptr = &gmMainLib_8015EDBC()->x14; - var_r4 = (*temp_r30 + arg0 > -1U) ? -1U : *temp_r30 + arg0; - *temp_r30 = var_r4; + total = ((*high_score_ptr2 + arg0) > (u32) -1) ? (u32) -1 + : *high_score_ptr2 + arg0; + *high_score_ptr2 = total; - var_r3 = (*temp_r5 + arg0 > -1U) ? -1U : *temp_r5 + arg0; - *temp_r5 = var_r3; + session_total = ((*session_high_score_ptr + arg0) > (u32) -1) + ? (u32) -1 + : *session_high_score_ptr + arg0; + *session_high_score_ptr = session_total; - arg0 = temp_r29 + arg0; + arg0 = current_score + arg0; if ((u32) arg0 > 0x270FU) { arg0 = 0x270FU; } - var_r29 = arg0; + capped_total = arg0; - temp_r30_2 = gmMainLib_8015CCF0(); - temp_r31 = gmMainLib_8015CCFC(); - temp_r3 = &gmMainLib_8015EDBC()->x14; + current_score_ptr = gmMainLib_8015CCF0(); + high_score_ptr = gmMainLib_8015CCFC(); + session_high_score_ptr2 = &gmMainLib_8015EDBC()->x14; - if ((u32) arg0 > (u32) *temp_r31) { - *temp_r31 = arg0; + if ((u32) arg0 > (u32) *high_score_ptr) { + *high_score_ptr = arg0; } - if ((u32) arg0 > (u32) *temp_r3) { - *temp_r3 = arg0; + if ((u32) arg0 > (u32) *session_high_score_ptr2) { + *session_high_score_ptr2 = arg0; } if ((u32) arg0 > 0x270FU) { - var_r29 = 0x270FU; + capped_total = 0x270FU; } - *temp_r30_2 = var_r29; + *current_score_ptr = capped_total; return arg0; } @@ -1395,7 +1413,7 @@ void gm_8016260C(u8 arg0, u8 arg1) if ((u8) (arg1 - 7) <= 1) { u32* p = gmMainLib_GetMatchResetCounter(); - *p = MIN(*p + 1, 0xFFFFFFFFU); + *p = (*p + 1 > 0xFFFFFFFFU) ? 0xFFFFFFFFU : *p + 1; return; } if (gm_801A4310() == 0x1F) { @@ -1412,7 +1430,7 @@ void gm_8016260C(u8 arg0, u8 arg1) counter = gmMainLib_GetCoinMatchTotal(); { struct gmm_retval_EDBC* q = gmMainLib_8015EDBC(); - q->x4 = MIN(q->x4 + 1, 0xFFFFFFFFU); + q->x4 = (q->x4 + 1 > 0xFFFFFFFFU) ? 0xFFFFFFFFU : q->x4 + 1; } break; case 3: @@ -1420,18 +1438,20 @@ void gm_8016260C(u8 arg0, u8 arg1) break; } } - *counter = MIN(*counter + 1, 0xFFFFFFFFU); + *counter = (*counter + 1 > 0xFFFFFFFFU) ? 0xFFFFFFFFU : *counter + 1; { struct gmm_retval_ED98* a = gmMainLib_8015ED98(); - a->x0 = MIN(a->x0 + 1, 0xFFFFFFFFU); + a->x0 = (a->x0 + 1 > 0xFFFFFFFFU) ? 0xFFFFFFFFU : a->x0 + 1; } { struct gmm_retval_EDB0* b = gmMainLib_8015EDB0(); - b->x0 = MIN((u32) b->x0 + 1, 0xFFFFFFFFU); + b->x0 = + ((u32) b->x0 + 1 > 0xFFFFFFFFU) ? 0xFFFFFFFFU : (u32) b->x0 + 1; } { struct gmm_retval_EDBC* c = gmMainLib_8015EDBC(); - c->x0 = MIN((u32) c->x0 + 1, 0xFFFFFFFFU); + c->x0 = + ((u32) c->x0 + 1 > 0xFFFFFFFFU) ? 0xFFFFFFFFU : (u32) c->x0 + 1; } } @@ -2174,12 +2194,12 @@ void fn_801640B0(u64* item_mask) float fn_8016419C(u8 arg0) { - return lbl_803B7930[arg0 - 1].x; + return gm_HandicapDamageRatios[arg0 - 1].x; } float fn_801641B4(u8 arg0) { - return lbl_803B7930[arg0 - 1].y; + return gm_HandicapDamageRatios[arg0 - 1].y; } u16 gm_801641CC(u8 arg0) @@ -2424,9 +2444,13 @@ void gm_80164910(int arg0) void gm_80164A0C(u8 arg0) { - u16* unlockable_character_bitfield = gmMainLib_8015ED8C(); - s32 tmp_p52845 = lbl_803B78A4[arg0]; - u8 idx = fn_801605EC(tmp_p52845); + u16* unlockable_character_bitfield; + u8 idx; + u8 internal_id; + + unlockable_character_bitfield = gmMainLib_8015ED8C(); + internal_id = lbl_803B78A4[arg0]; + idx = fn_801605EC(internal_id); if (idx != NUM_UNLOCKABLE_CHARACTERS) { *unlockable_character_bitfield &= (u16) ~(1ULL << idx); } @@ -2455,137 +2479,80 @@ static inline bool fn_80164B48_check(u8 idx, u16* ptr) return false; } +static inline u8 fn_80164B48_lookup(s32 t, const u8* es, const u8* base) +{ + s32 i; + + for (i = 0; i < 0xB; i++) { + if (t == (s32) es[1]) { + return (base + i * 6)[0x2D0]; + } + es += 6; + } + return 0xB; +} + +static inline u8 fn_80164B48_lookup_last(s32 t, const u8** es, const u8* base) +{ + s32 i; + + for (i = 0; i < 0xB; i++) { + if (t == (s32) (*es)[1]) { + return (base + i * 6)[0x2D0]; + } + *es += 6; + } + return 0xB; +} + bool fn_80164B48(void) { const u8* base = (const u8*) lbl_803B75F8; - s32 t; u8 idx; u16* ptr; const u8* es_base; s32 ok = 0; - PAD_STACK(16); + PAD_STACK(8); ptr = gmMainLib_8015ED8C(); - t = base[0x2C2]; es_base = base + 0x2D0; - idx = 0xB; - { - s32 i; - const u8* es; - - es = es_base; - for (i = 0; i < 0xB; i++) { - if (t == (s32) es[1]) { - idx = (base + i * 6)[0x2D0]; - break; - } - es += 6; - } - } + idx = fn_80164B48_lookup(base[0x2C2], es_base, base); ok = fn_80164B48_check(idx, ptr); if (ok == 0) { return 0; } ptr = gmMainLib_8015ED8C(); - t = base[0x2C5]; - idx = 0xB; - { - s32 i; - const u8* es; - - es = es_base; - for (i = 0; i < 0xB; i++) { - if (t == (s32) es[1]) { - idx = (base + i * 6)[0x2D0]; - break; - } - es += 6; - } - } + idx = fn_80164B48_lookup(base[0x2C5], es_base, base); ok = fn_80164B48_check(idx, ptr); if (ok == 0) { return 0; } ptr = gmMainLib_8015ED8C(); - t = base[0x2C1]; - idx = 0xB; - { - s32 i; - const u8* es; - - es = es_base; - for (i = 0; i < 0xB; i++) { - if (t == (s32) es[1]) { - idx = (base + i * 6)[0x2D0]; - break; - } - es += 6; - } - } + idx = fn_80164B48_lookup(base[0x2C1], es_base, base); ok = fn_80164B48_check(idx, ptr); if (ok == 0) { return 0; } ptr = gmMainLib_8015ED8C(); - t = base[0x2C0]; - idx = 0xB; - { - s32 i; - const u8* es; - - es = es_base; - for (i = 0; i < 0xB; i++) { - if (t == (s32) es[1]) { - idx = (base + i * 6)[0x2D0]; - break; - } - es += 6; - } - } + idx = fn_80164B48_lookup(base[0x2C0], es_base, base); ok = fn_80164B48_check(idx, ptr); if (ok == 0) { return 0; } ptr = gmMainLib_8015ED8C(); - t = base[0x2C4]; - idx = 0xB; - { - s32 i; - const u8* es; - - es = es_base; - for (i = 0; i < 0xB; i++) { - if (t == (s32) es[1]) { - idx = (base + i * 6)[0x2D0]; - break; - } - es += 6; - } - } + idx = fn_80164B48_lookup(base[0x2C4], es_base, base); ok = fn_80164B48_check(idx, ptr); if (ok == 0) { return 0; } ptr = gmMainLib_8015ED8C(); - t = base[0x2C3]; - idx = 0xB; - { - s32 i; - - for (i = 0; i < 0xB; i++) { - if (t == (s32) es_base[1]) { - idx = (base + i * 6)[0x2D0]; - break; - } - es_base += 6; - } - } + idx = fn_80164B48_lookup_last(base[0x2C3], &es_base, base); ok = fn_80164B48_check(idx, ptr); if (ok == 0) { return 0; @@ -2683,7 +2650,6 @@ void fn_801652B0(s32 arg0, s32 arg1) void* fn_801652D8(void) { - u32 val; s32 idx; HSD_VIInfo* vi = &HSD_VIData; PerfLabelLine* lines = &lbl_8046B378.line0; @@ -2695,10 +2661,7 @@ void* fn_801652D8(void) lines[0].next = &lines[1]; - val = gm_801A4BB8(); - - idx = 1; - sprintf(lines[idx].text, "\\ce0e0ff%5d", (int) val); + sprintf(lines[idx = 1].text, "\\ce0e0ff%5d", (int) gm_801A4BB8()); lines[1].next = &lines[2]; lines[1].next = NULL; @@ -2784,7 +2747,7 @@ u8 fn_80165548(MatchEnd* me, s8 arg1, s32 team) } if (result >= 0) { ret += result; - return ret; + break; } } } @@ -2833,88 +2796,80 @@ s32 fn_8016588C(lbl_8046B6A0_24C_t* arg0, s32 arg1) { s32 v; s32 lim; + s32 result; + + PAD_STACK(0x18); if (gm_801A4310() == 0x1F) { if (arg0->x58[arg1].x28 != 0) { - v = (u8) (arg0->x58[arg1].x28 / 60 + 0xFF000001); + v = arg0->x58[arg1].x28 / 60 + 0xFF000001; } else { v = arg0->x58[arg1].x9; } + lim = (1 << 24) - 1; + result = v; + if (lim < 0) { + lim = -lim; + } + if (v > lim) { + result = lim; + } else if (v < -lim) { + result = -lim; + } + } else if (arg0->x5 == 2) { + result = ((MatchPlayerData*) arg0->x58)[arg1].x1C; + lim = (1 << 24) - 1; + if (lim < 0) { + lim = -lim; + } + if (result > lim) { + result = lim; + } else if (result < -lim) { + result = -lim; + } + } else if (arg0->x5 == 1) { + if ((s8) arg0->x58[arg1].x8 != 0) { + result = (s8) arg0->x58[arg1].x8; + } else { + result = arg0->x58[arg1].x28 / 60 + 0xFF000001; + } + lim = (1 << 24) - 1; + if (lim < 0) { + lim = -lim; + } + if (result > lim) { + result = lim; + } else if (result < -lim) { + result = -lim; + } + } else if (arg0->x5 == 3) { + pl_80039450(arg1); + result = fn_8016FFD4(arg0, 2, (u8) arg1); + lim = (1 << 24) - 1; + if (lim < 0) { + lim = -lim; + } + if (result > lim) { + result = lim; + } else if (result < -lim) { + result = -lim; + } } else { - switch (arg0->x5) { - case 2: - v = arg0->x58[arg1].x1C; - lim = (1 << 24) - 1; - if (lim < 0) { - lim = -lim; - } - if (v > lim) { - return lim; - } - if (v < -lim) { - return -lim; - } - break; - case 1: - if ((s8) arg0->x58[arg1].x8 != 0) { - v = (u8) (s8) arg0->x58[arg1].x8; - } else { - v = (u8) (arg0->x58[arg1].x28 / 60 + 0xFF000001); - } - lim = (1 << 24) - 1; - if (lim < 0) { - lim = -lim; - } - if (v > lim) { - return lim; - } - if (v < -lim) { - return -lim; - } - break; - case 3: - pl_80039450(arg1); - v = (u8) fn_8016FFD4(arg0, 2, (u8) arg1); - lim = (1 << 24) - 1; - if (lim < 0) { - lim = -lim; - } - if (v > lim) { - return lim; - } - if (v < -lim) { - return -lim; - } - break; - default: { - u16 a = arg0->x58[arg1].xA; - v = (u8) ((arg0->x58[arg1].x20 - (arg0->x58[arg1].x24 - a)) + - a * (s8) arg0->xC); - break; - lim = (1 << 24) - 1; - if (lim < 0) { - lim = -lim; - } - if (v > lim) { - return lim; - } - if (v < -lim) { - return -lim; - } + u16 a = arg0->x58[arg1].xA; + result = a * (s8) arg0->xC; + result += arg0->x58[arg1].x20 - (arg0->x58[arg1].x24 - a); + lim = (1 << 24) - 1; + if (lim < 0) { + lim = -lim; } + if (result > lim) { + result = lim; + } else if (result < -lim) { + result = -lim; } } - lim = (1 << 24) - 1; - if (lim < 0) { - lim = -lim; - } - if (v > lim) { - return lim; - } - if (v < -lim) { - return -lim; - } - return v; + + return result; } struct fn_80165AC0_loser_bits { @@ -3025,29 +2980,28 @@ void fn_80165E7C(MatchEnd* arg0) s32 fn_80165FA4(MatchEnd* arg0) { + s32 i; s32 max_loser; s32 count; - s32 i; s32 j; - struct MatchTeamData* t; max_loser = 0; for (i = 0; i < 5; i++) { - t = &arg0->team_standings[i]; - if (t->active != 0) { + if (arg0->team_standings[i].active != 0) { for (j = 0; j < 5; j++) { - if (j != i && arg0->team_standings[j].active != 0 && - (s32) t->score < (s32) arg0->team_standings[j].score) + if (i != j && arg0->team_standings[j].active != 0 && + (s32) arg0->team_standings[i].score < + (s32) arg0->team_standings[j].score) { - t->is_big_loser += 1; + arg0->team_standings[i].is_big_loser += 1; } } - if (max_loser < (s32) t->is_big_loser) { - max_loser = t->is_big_loser; + if (max_loser < (s32) arg0->team_standings[i].is_big_loser) { + max_loser = arg0->team_standings[i].is_big_loser; } } } - arg0->loser = (arg0->loser & ~0xF) | (max_loser & 0xF); + ((struct fn_80165AC0_loser_bits*) &arg0->loser)->lo = max_loser; count = 0; for (j = 0; j < 5; j++) { if (arg0->team_standings[j].active != 0 && @@ -3237,10 +3191,10 @@ float fn_80166A8C(register Vec3* src, register Vec3* dst) s32 gm_80166A98(MatchEnd* arg0, s32 arg1, s8 arg2, u8 arg3, s8 arg4, u8 arg5, s8 arg6, u8 arg7, u8 arg_sp8, u8 arg_spC) { - s32 score0; - s32 score1; - s32 score2; - s32 score3; + s32 score0 = 0xA - arg3; + s32 score1 = 0xA - arg5; + s32 score2 = 0xA - arg7; + s32 score3 = 0xA - arg_spC; u32 i; memzero(arg0, 0x227C); @@ -3249,13 +3203,9 @@ s32 gm_80166A98(MatchEnd* arg0, s32 arg1, s8 arg2, u8 arg3, s8 arg4, u8 arg5, arg0->x5 = 0; arg0->is_teams = 0; - score0 = 0xA - arg3; arg0->player_standings[0].character_kind = arg2; - score1 = 0xA - arg5; arg0->player_standings[1].character_kind = arg4; - score2 = 0xA - arg7; arg0->player_standings[2].character_kind = arg6; - score3 = 0xA - arg_spC; arg0->player_standings[3].character_kind = arg_sp8; // Apply player color to all 4 players? @@ -3265,8 +3215,8 @@ s32 gm_80166A98(MatchEnd* arg0, s32 arg1, s8 arg2, u8 arg3, s8 arg4, u8 arg5, arg0->player_standings[0].score = score0; arg0->player_standings[1].score = score1; - arg0->player_standings[2].score = score2; - arg0->player_standings[3].score = score3; + arg0->player_standings[2].score = 0xA - arg7; + arg0->player_standings[3].score = 0xA - arg_spC; arg0->player_standings[0].x30 = score0; arg0->player_standings[1].x30 = score1; arg0->player_standings[2].x30 = score2; @@ -3557,42 +3507,78 @@ struct lbl_803B7A44_t { extern struct lbl_803B7A44_t lbl_803B7A44; +struct MatchInfoStride_80167638 { + u8 bytes[0xE]; +}; + s32 fn_80167638(s32 arg0, Vec3* arg1, Vec3* arg2) { + UNUSED u8 pad[8]; struct lbl_803B7A44_t sp; - lbl_8046B6A0_t* info; s8 chr; + s32 ret = arg0; + Vec3* pos = arg1; + Vec3* offset = arg2; + lbl_8046B6A0_t* info; + struct MatchInfoStride_80167638* stride; s32 idx; - s32 i; + u8 x8; - PAD_STACK(8); + PAD_STACK(4); info = gm_8016AE44(); - idx = 0; - for (i = 0; i < ARRAY_SIZE(info->FighterMatchInfo); i++) { - if (info->FighterMatchInfo[i].x8 == 0) { - idx = i; - break; + if (info->FighterMatchInfo[0].x8 == 0) { + idx = 0; + } else { + stride = (struct MatchInfoStride_80167638*) info; + info = (lbl_8046B6A0_t*) ++stride; + if (info->FighterMatchInfo[0].x8 == 0) { + idx = 1; + } else { + x8 = info->FighterMatchInfo[1].x8; + stride = (struct MatchInfoStride_80167638*) info; + info = (lbl_8046B6A0_t*) ++stride; + if (x8 == 0) { + idx = 2; + } else { + x8 = info->FighterMatchInfo[1].x8; + stride = (struct MatchInfoStride_80167638*) info; + info = (lbl_8046B6A0_t*) ++stride; + if (x8 == 0) { + idx = 3; + } else { + x8 = info->FighterMatchInfo[1].x8; + stride = (struct MatchInfoStride_80167638*) info; + info = (lbl_8046B6A0_t*) ++stride; + if (x8 == 0) { + idx = 4; + } else if (info->FighterMatchInfo[1].x8 == 0) { + idx = 5; + } else { + idx = 0; + } + } + } } } - chr = Player_GetPlayerCharacter(arg0); + chr = Player_GetPlayerCharacter(ret); if (stage_info.unk8C.b4) { - Stage_80224E38(arg1, arg0); - arg2->z = 0.0f; - arg2->y = 0.0f; - arg2->x = 0.0f; + Stage_80224E38(pos, ret); + offset->z = 0.0f; + offset->y = 0.0f; + offset->x = 0.0f; } else { - arg0 = 0; - Stage_80224E38(arg1, 0); + ret = 0; + Stage_80224E38(pos, 0); sp = lbl_803B7A44; - arg2->x = 16.0f * (&sp.x0)[idx]; - arg2->z = 0.0f; - arg2->y = 0.0f; + offset->x = 16.0f * (&sp.x0)[idx]; + offset->z = 0.0f; + offset->y = 0.0f; info = gm_8016AE44(); info->FighterMatchInfo[idx].x8 = 0x90; info->FighterMatchInfo[idx].x9 = chr; } - return arg0; + return ret; } void gm_801677C0(struct gm_801677C0_s* arg0) @@ -3719,7 +3705,7 @@ void gm_80167BC8(VsModeData* vs_data) struct gmm_x1CB0* prefs; s32 i; s8* handicap; - PAD_STACK(56); + PAD_STACK(72); rules = gmMainLib_8015CC34(); prefs = gmMainLib_8015CC58(); @@ -3769,23 +3755,26 @@ void gm_80167BC8(VsModeData* vs_data) handicap = gmMainLib_8015CE44(i, (s32) vs_data->data.players[i].xA); if (handicap != NULL) { - vs_data->data.players[i].handicap = - *handicap; ///< @todo :: fix these to actually get the - ///< offensive and - // defensive ratios just not sure how to setup the structs - vs_data->data.players[i].x18 = lbl_803B7930[(u8) *handicap].x; - vs_data->data.players[i].x1C = lbl_803B7930[(u8) *handicap].y; + vs_data->data.players[i].handicap = *handicap; + vs_data->data.players[i].x18 = + gm_HandicapDamageRatios[(u8) *handicap - 1].x; + vs_data->data.players[i].x1C = + gm_HandicapDamageRatios[(u8) *handicap - 1].y; } else { vs_data->data.players[i].handicap = 5; - vs_data->data.players[i].x18 = 0.61f; - vs_data->data.players[i].x1C = 1.6393442f; + vs_data->data.players[i].x18 = gm_HandicapDamageRatios[4].x; + vs_data->data.players[i].x1C = gm_HandicapDamageRatios[4].y; } break; case 2: vs_data->data.players[i].x18 = - lbl_803B7930[(u8) vs_data->data.players[i].handicap].x; + gm_HandicapDamageRatios + [(u8) vs_data->data.players[i].handicap - 1] + .x; vs_data->data.players[i].x1C = - lbl_803B7930[(u8) vs_data->data.players[i].handicap].y; + gm_HandicapDamageRatios + [(u8) vs_data->data.players[i].handicap - 1] + .y; break; } } @@ -3793,43 +3782,19 @@ void gm_80167BC8(VsModeData* vs_data) vs_data->data.rules.x1_7 = (rules->friendly_fire & 1); vs_data->data.rules.x30 = 0.1f * rules->damage_ratio; vs_data->data.rules.xB = (s8) prefs->item_freq; - prefs = gmMainLib_8015CC58(); ///< @todo :: some weird item copy thing that - ///< needs to be fixed + prefs = gmMainLib_8015CC58(); i = 0; do { - if ((s32) lbl_803B7844[i] != 0x23) { - // prefs->item_mask = vs_data->data.rules.x20; - if ((prefs->item_mask & (1LL << i))) { - vs_data->data.rules.x20 |= (1LL << prefs->item_mask); + u8 item = lbl_803B7844[(u8) i]; + if ((s32) item != 0x23) { + if (prefs->item_mask & (1LL << i)) { + vs_data->data.rules.x20 |= 1LL << item; } else { - vs_data->data.rules.x20 &= ~(1LL << prefs->item_mask); + vs_data->data.rules.x20 &= ~(1LL << item); } } + i++; } while (i < 0x20); - // this is what decomp.py spits out - // temp_r31 = gmMainLib_8015CC58(); - // var_r28_2 = 0; - // do { - // if ((s32) lbl_803B75F8.pad_x24C[var_r28_2] != 0x23) { - // __shl2i(); - // if ((((temp_r31->unkC & M2C_ERROR(/* Read from unset register - // $r4 */)) ^ 0) | ((temp_r31->unk8 & M2C_ERROR(/* Read from unset - // register $r3 */)) ^ 0)) != 0) { - // __shl2i(); - // arg0->unk2C = (s32) (arg0->unk2C | M2C_ERROR(/* Read from - // unset register $r4 */)); arg0->unk28 = (s32) (arg0->unk28 | - // M2C_ERROR(/* Read from unset register $r3 */)); - // } else { - // __shl2i(); - // arg0->unk2C = (s32) (arg0->unk2C & ~(M2C_ERROR(/* Read from - // unset register $r4 */) | M2C_ERROR(/* Read from unset - // register $r4 */))); arg0->unk28 = (s32) (arg0->unk28 & - // ~(M2C_ERROR(/* Read from unset register $r3 */) | - // M2C_ERROR(/* Read from unset register $r3 */))); - // } - // } - // var_r28_2 += 1; - // } while (var_r28_2 < 0x20); switch (gmMainLib_8015ED30()) { case 1: @@ -4277,8 +4242,6 @@ s32 fn_80169000(void* arg0, void* arg1) u8* hb = (u8*) arg1; s32 count; s32 i; - u8* cur; - u8 v; UNUSED u8 pad[16]; count = 0; @@ -4293,23 +4256,29 @@ s32 fn_80169000(void* arg0, void* arg1) p += 0xA8; } - cur = &handicaps[positions[0]]; - v = *cur; - if (v >= 2 && handicaps[positions[count - 1]] <= 8) { - *cur = v - 1; + if (handicaps[positions[0]] >= 2 && handicaps[positions[count - 1]] <= 8) { + handicaps[positions[0]] -= 1; handicaps[positions[count - 1]] += 1; - } else if (v == 1 && handicaps[positions[count - 1]] <= 7) { - handicaps[positions[count - 1]] += 2; - } else if (v >= 3 && handicaps[positions[count - 1]] == 9) { - *cur -= 2; + } else if (handicaps[positions[0]] == 1 && + handicaps[positions[count - 1]] <= 7) + { + handicaps[positions[count - 1]] = handicaps[positions[count - 1]] + 2; + } else if (handicaps[positions[0]] >= 3 && + handicaps[positions[count - 1]] == 9) + { + handicaps[positions[0]] -= 2; } else if (count >= 3) { - if (v == 1 && handicaps[positions[count - 1]] == 8) { + if (handicaps[positions[0]] == 1 && + handicaps[positions[count - 1]] == 8) + { handicaps[positions[count - 1]] += 1; if (handicaps[positions[1]] >= 2) { handicaps[positions[1]] -= 1; } - } else if (v == 2 && handicaps[positions[count - 1]] == 9) { - *cur -= 1; + } else if (handicaps[positions[0]] == 2 && + handicaps[positions[count - 1]] == 9) + { + handicaps[positions[0]] -= 1; if (handicaps[positions[1]] >= 2) { handicaps[positions[1]] -= 1; } @@ -4494,46 +4463,61 @@ void fn_80169574(ssize_t size, s8* buf) buf[size] = -2; } +static inline s8* fn_801695BC_rand_color(s32 ncolors, s8* colors) +{ + return &colors[HSD_Randi(ncolors)]; +} + +static inline s32 fn_801695BC_get_color(s32 i, u8* colors) +{ + return (s8) colors[i]; +} + s32 fn_801695BC(u8 arg0, u8 arg1, u8 arg2, u8* arg3, u8* arg4) { - u8 colors[12]; - u8 ncolors; - s32 ncolors_s32; + s32 tmp2; + s8 tmp; s32 i; + s32 ncolors_s32; s32 color_i; - u8 tmp; + u8 ncolors; + s8 colors[6]; ncolors = gm_80169238_noinline(arg0); if ((s8) arg0 != 0x21) { ncolors_s32 = ncolors; - for (i = 0; i < ncolors_s32; i++) { + for (i = 0; i < ncolors; i++) { colors[i] = (s8) i; } if ((s8) arg1 == (s8) arg0) { - colors[(s8) arg2] = 0xFF; + colors[(s8) arg2] = -1; } for (i = 0; i < ncolors_s32; i++) { - u8* other = &colors[HSD_Randi(ncolors_s32)]; + s8* other = fn_801695BC_rand_color(ncolors_s32, colors); tmp = *other; *other = colors[i]; colors[i] = tmp; } color_i = 0; - for (i = 0; (s8) arg4[i] != -2; i++) { - if ((s8) arg0 == (s8) arg3[i]) { - if ((s8) colors[color_i % ncolors_s32] == -1) { + { + u8* p = arg3; + for (i = 0; (s8) arg4[i] != -2; i++) { + if ((s8) arg0 == (s8) *p) { + if (colors[color_i % ncolors_s32] == -1) { + color_i += 1; + } + arg4[i] = colors[color_i % ncolors_s32]; color_i += 1; } - arg4[i] = colors[color_i % ncolors_s32]; - color_i += 1; + p++; } } for (i = 1; (s8) arg4[i] != -2; i++) { if ((s8) arg0 == (s8) arg3[i] && (s8) arg0 == (s8) arg3[i - 1]) { if (HSD_Randi(2) != 0) { - tmp = arg4[i]; + tmp2 = fn_801695BC_get_color(i, arg4); arg4[i] = arg4[i - 1]; - arg4[i - 1] = tmp; + arg4[i - 1] = tmp2; } } } @@ -4639,11 +4623,13 @@ long fn_80169A84(u8 arg0, s8* arg1, s8* arg2) s8* src; u8 tmp; s8 result; - switch (arg0) { case 1: i = 0; - list = lbl_8046B488.x1C0; + { + s8* list_start = lbl_8046B488.x1C0; + list = list_start; + } p = list; do { if (i != 4 && gm_80164840_noinline((u8) i) != 0) { @@ -4659,29 +4645,23 @@ long fn_80169A84(u8 arg0, s8* arg1, s8* arg2) p = list; do { s8* q; - q = &lbl_8046B488.x1C0[HSD_Randi(0x1B)]; - tmp = *q; + q = &lbl_8046B488.x0 + HSD_Randi(0x1B); + tmp = q[0x1C0]; i += 1; - *q = (u8) *p; + q[0x1C0] = (u8) *p; *p = tmp; p += 1; } while (i < 0x1A); count = 0; - for (i = 0; i < 0xD; i++) { - if ((s8) list[0] != -1) { + for (i = 0; i < 0x1A; i++) { + if ((s8) *list != -1) { count += 1; if (count > 0x10) { - list[0] = -1; + *list = -1; } } - if ((s8) list[1] != -1) { - count += 1; - if (count > 0x10) { - list[1] = -1; - } - } - list += 2; + list++; } dst = arg1; @@ -4691,8 +4671,8 @@ long fn_80169A84(u8 arg0, s8* arg1, s8* arg2) while ((s8) lbl_8046B488.x1C0[i] == -1) { i = (i + 1) % 27; } - result = - Player_800325C8((CharacterKind) (s8) lbl_8046B488.x1C0[i], 0); + result = Player_800325C8( + (CharacterKind) (s8) lbl_8046B488.x1C0[i], 0); *dst = result; i += 1; src += 1; @@ -4713,17 +4693,16 @@ long fn_80169A84(u8 arg0, s8* arg1, s8* arg2) void fn_80169C54(s8 arg0, s8 arg1) { - s32* bp; struct lbl_8046B488_t* st; + s32* bp; s8* pc; s8* cp; s32 buf[7]; s32 n; - s32 count; s32 j; s32 k; s32 p; - s8 ch; + s32 ch; PAD_STACK(8); @@ -4741,6 +4720,7 @@ void fn_80169C54(s8 arg0, s8 arg1) for (j = 0; j < 3; j++) { if ((s32) *pc == 4) { if (st->xB == 0) { + s32 count; count = gm_80169238_noinline(4U); for (k = 0; k < count; k++) { bp[k] = k; @@ -4764,7 +4744,7 @@ void fn_80169C54(s8 arg0, s8 arg1) cp = (s8*) st; do { ch = *cp; - if (ch != 0x21 && ch != 4) { + if (0x21 != ch && ch != 4) { p = Player_800325C8((CharacterKind) ch, 0); if ((p != -1) && (p != 4)) { for (k = 0; k < n; k++) { @@ -4798,6 +4778,23 @@ void fn_80169C54(s8 arg0, s8 arg1) } } +static inline void fn_80169F50_inline(s32 arg1, struct lbl_8046B488_t* gp, + int temp_arg0) +{ + s32 i; + if (temp_arg0 == 4 && gp->xE != 0) { + for (i = 0; gp->x20[i] != -2; i++) { + if (gp->x20[i] == -1) { + continue; + } + if (gp->x124[i] == -1) { + continue; + } + Player_80031DA8(gp->x124[i], arg1); + } + } +} + void fn_80169F50(s8 arg0, s8 arg1) { struct lbl_8046B488_t* gp = &lbl_8046B488; @@ -4836,17 +4833,7 @@ void fn_80169F50(s8 arg0, s8 arg1) } } - if (temp_arg0 == 4 && gp->xE != 0) { - for (i = 0; gp->x20[i] != -2; i++) { - if (gp->x20[i] == -1) { - continue; - } - if (gp->x124[i] == -1) { - continue; - } - Player_80031DA8(gp->x124[i], arg1); - } - } + fn_80169F50_inline(arg1, gp, temp_arg0); } void fn_8016A09C(void) @@ -4957,23 +4944,36 @@ gm_8016A404_event_player_init_cb(struct lbl_8046B488_t* gp) return &state->event_player_init_cb; } -static inline u8 gm_8016A22C_kind(struct lbl_8046B488_t* gp, int idx) +struct gm_8016A22C_kinds { + u8 kind[3]; +}; + +struct gm_8016A22C_buffers { + /* 0x000 */ char pad_0[0x20]; + /* 0x020 */ u8 x20[0xA2 - 0x20]; + /* 0x0A2 */ u8 xA2[0x124 - 0xA2]; +}; + +static inline struct gm_8016A22C_kinds* +gm_8016A22C_kind_array(struct lbl_8046B488_t* gp) { - switch (idx) { - case 0: - return gp->x0; - case 1: - return gp->x1; - } - return gp->x2; + return (struct gm_8016A22C_kinds*) gp; +} + +static inline struct gm_8016A22C_buffers* +gm_8016A22C_buffers(struct lbl_8046B488_t* gp) +{ + return (struct gm_8016A22C_buffers*) gp; } s32 gm_8016A22C(s8 k0, s8 k1, s8 k2, u8 a3, u8 a4, int a5, int mode, int a7, u8 color, u8 p87, u8 p8b, int x6, int x7, int x9, int xA, int flag2, int flag1, f32 f1, f32 f2) { - u8* kinds; int i; + struct gm_8016A22C_kinds* kinds; + struct gm_8016A22C_buffers* bufs; + u8 x7_tmp; memzero(&lbl_8046B488, 0x1C0); @@ -4985,6 +4985,10 @@ s32 gm_8016A22C(s8 k0, s8 k1, s8 k2, u8 a3, u8 a4, int a5, int mode, int a7, lbl_8046B488.x4 = a4; lbl_8046B488.x5 = (u8) a5; + lbl_8046B488.x1AC = p87; + lbl_8046B488.x1AD = 0x21; + lbl_8046B488.x1B2 = p8b; + lbl_8046B488.x6 = (u8) x6; lbl_8046B488.x7 = (u8) x7; lbl_8046B488.x8 = (u8) x7; @@ -5010,35 +5014,39 @@ s32 gm_8016A22C(s8 k0, s8 k1, s8 k2, u8 a3, u8 a4, int a5, int mode, int a7, lbl_8046B488.xC = a3; - lbl_8046B488.x1AC = p87; - lbl_8046B488.x1AD = 0x21; - lbl_8046B488.x1B2 = p8b; - - memzero(lbl_8046B488.x20, lbl_8046B488.x7); - lbl_8046B488.x20[lbl_8046B488.x7] = (s8) -2; + x7_tmp = lbl_8046B488.x7; + memzero(lbl_8046B488.x20, x7_tmp); + { + s8* p = &lbl_8046B488.x20[x7_tmp]; + *p = -2; + } - fn_80169900_noinline(lbl_8046B488.xD, &lbl_8046B488, lbl_8046B488.xA2, - lbl_8046B488.x20); + { + struct lbl_8046B488_t* tmp = &lbl_8046B488; + fn_80169900_noinline(lbl_8046B488.xD, tmp, lbl_8046B488.xA2, + lbl_8046B488.x20); + } - kinds = (u8*) &lbl_8046B488.x0; + kinds = gm_8016A22C_kind_array(&lbl_8046B488); + bufs = gm_8016A22C_buffers(&lbl_8046B488); switch (lbl_8046B488.xB) { case 0: for (i = 0; i < 3; i++) { - fn_801695BC_noinline(kinds[i], p87, p8b, (u8*) lbl_8046B488.xA2, - (u8*) lbl_8046B488.x20); + fn_801695BC_noinline(kinds->kind[i], p87, p8b, bufs->xA2, + bufs->x20); } break; - case 1: + case 1: { + u8 c = lbl_8046B488.xC; for (i = 0; i < 3; i++) { - fn_801697FC_noinline( - kinds[i], lbl_8046B488.xC, p87, p8b, - lbl_8046B488 - .x20); // This was being inlined, hence the no-inline + fn_801697FC_noinline(kinds->kind[i], c, p87, p8b, + lbl_8046B488.x20); } break; } + } return fn_80169A84(lbl_8046B488.xE, lbl_8046B488.x124, lbl_8046B488.x20); } @@ -5083,23 +5091,22 @@ void fn_8016A488(s32 arg0) void fn_8016A4C8(void) { - Vec3 spawn_pos; + s8 chr; f32 facing_dir; s32 spawn_enabled; - s32 active_slot; s32 cpu_type; s32 cpu_type_roll; - s32 matching_slot; + s8 controller_index; s32 spawn_slot; s32 has_active_spawn; - s8 chr; + Vec3 spawn_pos; s8 cos; - s8 controller_index; + s32 matching_slot; struct lbl_8046B488_t* gp; u8* spawn_state; u8* event_flags; - PAD_STACK(0xD4); + PAD_STACK(0xBC); gp = &lbl_8046B488; event_flags = (u8*) gp + 0x10; @@ -5155,7 +5162,10 @@ void fn_8016A4C8(void) } } Player_SetControllerIndex(spawn_slot, controller_index); - Player_SetMoreFlagsBit6(spawn_slot, gp->xF); + { + u8 more_flags = gp->xF; + Player_SetMoreFlagsBit6(spawn_slot, more_flags); + } Player_SetMoreFlagsBit1(spawn_slot, 0U); if (spawn_pos.x >= 0.0f) { facing_dir = -1.0f; @@ -5167,7 +5177,11 @@ void fn_8016A4C8(void) Player_SetPlayerId(spawn_slot, spawn_slot); Player_SetFlagsBit0(spawn_slot, 0); Player_SetNametagSlotID(spawn_slot, 0x78); - Player_SetPlayerAndEntityCpuLevel(spawn_slot, (s32) gp->x6); + { + u8 cpu_level = gp->x6; + Player_SetPlayerAndEntityCpuLevel(spawn_slot, + (s32) cpu_level); + } cpu_type = 0x17; if ((s32) gp->x7 != 1) { cpu_type_roll = HSD_Randi(4); @@ -5197,7 +5211,10 @@ void fn_8016A4C8(void) Player_SetFlagsBit6(spawn_slot, (*event_flags >> 2U) & 1); Player_SetModelScale(spawn_slot, gp->x1C); Player_SetAttackRatio(spawn_slot, gp->x14); - Player_SetDefenseRatio(spawn_slot, gp->x18); + { + f32 defense_ratio = gp->x18; + Player_SetDefenseRatio(spawn_slot, defense_ratio); + } if ((s32) gp->x8 > 1) { Player_SetMoreFlagsBit5(spawn_slot, 1U); } else { @@ -5222,6 +5239,7 @@ void fn_8016A4C8(void) } } if ((s32) gp->x7 == 0) { + s32 active_slot; active_slot = 0; scan_active_spawn: if (Player_GetPlayerSlotType(active_slot) != Gm_PKind_NA && @@ -5311,11 +5329,11 @@ int gm_8016A9E8(u8 arg0, s8 arg1) bool gm_8016AC44(s8 ckind, s8 costume_id) { - struct lbl_8046B668_t* ptr = &lbl_8046B668; s32 idx; s32 i; if ((gm_8016AE50()->x58 != NULL ? 1 : 0) == 1) { + struct lbl_8046B668_t* ptr = &lbl_8046B668; idx = -1; for (i = 0; i < 27; i++) { if (ptr->arr2[i] == -2) { diff --git a/src/melee/gm/gm_1601.dox b/src/melee/gm/gm_1601.dox index 4c58430ac8..1a89ef9a39 100644 --- a/src/melee/gm/gm_1601.dox +++ b/src/melee/gm/gm_1601.dox @@ -49,7 +49,7 @@ struct lbl_8046B488_t; /* 1609E0 */ const char* fn_801609E0(u8 ckind); /* 160A60 */ const char* gm_80160A60(int); /* 160B40 */ UNK_RET gm_80160B40(HSD_Text*, u8, u8); -/* 160C90 */ void gm_80160C90(HSD_Text* text, u8 fighter_id, bool arg2); +/* 160C90 */ void gm_80160C90(HSD_Text* text, u8 fighter_id, u8 arg2); /* 160DE8 */ void fn_80160DE8(HSD_JObj*, u8, s32, u8, f32, f32); /* 160F58 */ float fn_80160F58(u8 ckind); /* 161004 */ s32 fn_80161004(MatchEnd*); diff --git a/src/melee/gm/gm_1601.h b/src/melee/gm/gm_1601.h index 0892c22f3f..5afb45b69a 100644 --- a/src/melee/gm/gm_1601.h +++ b/src/melee/gm/gm_1601.h @@ -32,7 +32,7 @@ /* 1609E0 */ const char* fn_801609E0(u8 ckind); /* 160A60 */ const char* gm_80160A60(int); /* 160B40 */ UNK_RET gm_80160B40(HSD_Text*, u8, u8); -/* 160C90 */ void gm_80160C90(HSD_Text* text, u8 fighter_id, bool arg2); +/* 160C90 */ void gm_80160C90(HSD_Text* text, u8 fighter_id, u8 arg2); /* 160DE8 */ void fn_80160DE8(HSD_JObj*, u8, s32, u8, f32, f32); /* 160F58 */ float fn_80160F58(u8 ckind); /* 161004 */ s32 fn_80161004(MatchEnd*); diff --git a/src/melee/gm/gm_1601.static.h b/src/melee/gm/gm_1601.static.h index 6a4da0126e..8b6becad8e 100644 --- a/src/melee/gm/gm_1601.static.h +++ b/src/melee/gm/gm_1601.static.h @@ -189,7 +189,7 @@ static const u8 lbl_803B790C[0xB][3] = { { 0x09, 0x1D, 0x14 }, { 0x0A, 0x1E, 0x15 }, }; -/* 3B7930 */ static Vec2 const lbl_803B7930[] = { +/* 3B7930 */ static Vec2 const gm_HandicapDamageRatios[] = { 0.35, 2.857143, 0.4, 2.5, 0.46, 2.173913, 0.53, 1.8867925, 0.61, 1.6393442, 0.7, 1.4285715, 0.8, 1.25, 0.93, 1.0752689, 1.07, 0.9345794, diff --git a/src/melee/gm/gm_16AE.c b/src/melee/gm/gm_16AE.c index 146039f1d3..f158a2f2b7 100644 --- a/src/melee/gm/gm_16AE.c +++ b/src/melee/gm/gm_16AE.c @@ -1319,8 +1319,7 @@ void fn_8016CFE0(void) int tmp_btns; s64 no_contest_buttons; int unpauser_slot; - u8 operand_pad[8]; - PAD_STACK(0x10); + PAD_STACK(0x18); fn_8016CFE0_inline(); @@ -1339,13 +1338,10 @@ void fn_8016CFE0(void) u64 buttons = gm_GetButtonsTriggered(tmp->pauser); if ((no_contest_buttons & buttons) != 0) { buttons = gm_GetButtonsPressed(tmp->pauser); - { - u64 tmp_p29927 = no_contest_buttons & buttons; - if ((tmp_p29927) == no_contest_buttons) { - fn_8016CF4C_dontinline(unpauser_slot, - OUTCOME_NO_CONTEST); - return; - } + if ((no_contest_buttons & buttons) == no_contest_buttons) { + fn_8016CF4C_dontinline(unpauser_slot, + OUTCOME_NO_CONTEST); + return; } } } @@ -1853,8 +1849,7 @@ void fn_8016E2BC(void) float var_f1_2; bool var_r0; int i; - bool is_teams; - PAD_STACK(0xC); + PAD_STACK(0x10); Player_80036DA4(); if (tmp->is_singleplayer == 1) { @@ -1872,10 +1867,12 @@ void fn_8016E2BC(void) } } Player_80032768(0, &sp24); - is_teams = tmp->x24C8.is_teams == true; - Player_SetUnk45(0, fn_80160840(gm_80160854( - Player_GetPlayerId(0), Player_GetTeam(0), - is_teams, Player_GetPlayerSlotType(0)))); + { + bool is_teams = tmp->x24C8.is_teams == true; + Player_SetUnk45(0, fn_80160840(gm_80160854( + Player_GetPlayerId(0), Player_GetTeam(0), + is_teams, Player_GetPlayerSlotType(0)))); + } Player_80031AD0(0); if (tmp->FighterMatchInfo[0].x4_b4) { lbAudioAx_800237A8(0x41F4E, 0x7F, 0x40); @@ -1900,13 +1897,15 @@ void fn_8016E2BC(void) } } Player_80032768(i, &sp18); - is_teams = tmp->x24C8.is_teams == true; - Player_SetUnk45( - i, fn_80160840(gm_80160854(Player_GetPlayerId(i), - Player_GetTeam(i), is_teams, - Player_GetPlayerSlotType(i)))); + { + bool is_teams = tmp->x24C8.is_teams == true; + Player_SetUnk45( + i, fn_80160840(gm_80160854(Player_GetPlayerId(i), + Player_GetTeam(i), is_teams, + Player_GetPlayerSlotType(i)))); + } Player_80031AD0(i); - if (tmp->FighterMatchInfo[i].x4_b4) { + if (lbl_8046B6A0.FighterMatchInfo[i].x4_b4) { lbAudioAx_800237A8(0x41F4E, 0x7F, 0x40); } } diff --git a/src/melee/gm/gm_16F1.c b/src/melee/gm/gm_16F1.c index fa7448f630..9e102a2d65 100644 --- a/src/melee/gm/gm_16F1.c +++ b/src/melee/gm/gm_16F1.c @@ -149,15 +149,34 @@ void fn_8016F344(struct lbl_8046B6A0_24C_t* arg0) } } +/// Same table lookup as #gm_8016F208, but with a u16 result. +/// fn_8016F39C passes the looked-up id straight to HSD_SisLib_803A6368 and +/// the original code keeps it in a u16: the u16 -> int promotion is emitted +/// during argument setup (clrlwi after the arg0[count] load). Reusing the +/// int-returning gm_8016F208 (or changing its return type) instead moves or +/// drops that zero-extension and regresses gm_8016F208/fn_8016F280. +static inline u16 fn_8016F39C_GetSisTextId(int kind) +{ + struct lbl_803D5A4C_t* curr = lbl_803D5A4C; + while (curr->kind != kind) { + if (curr->kind == 0x29A) { + return 0; + } + curr++; + } + if (curr->x2 == 0xDE && lbLang_IsSettingUS()) { + return 0x102; + } + return curr->x2; +} + int fn_8016F39C(HSD_Text** arg0, void* arg1, u8 arg2, u16 arg3, u8 arg4, u8 arg5) { - struct lbl_803D5A4C_t* curr; int idx; int count = 0; int matched; u8 flags; - u16 item_id; if (arg3 >= 0x101U) { return -1; @@ -183,22 +202,7 @@ int fn_8016F39C(HSD_Text** arg0, void* arg1, u8 arg2, u16 arg3, u8 arg4, } if (matched != 0) { - curr = lbl_803D5A4C; - item_id = 0; - while (curr->kind != idx) { - if (curr->kind == 0x29A) { - break; - } - curr++; - } - if (curr->kind == idx) { - if ((u16) curr->x2 == 0xDE && lbLang_IsSettingUS() != 0) { - item_id = 0x102; - } else { - item_id = curr->x2; - } - } - HSD_SisLib_803A6368(arg0[count], item_id); + HSD_SisLib_803A6368(arg0[count], fn_8016F39C_GetSisTextId(idx)); count++; if (count == (int) arg2) { break; @@ -397,7 +401,8 @@ int fn_8016FAD4(struct lbl_8046B6A0_24C_t* rules, int kind, int flags, if (pr == 0) { return lbl_803D5648[entry->x2 - 2] * 2; } - if (pr == rankings[6]) { + i = (x58[1].x0 != 3) && pr == rankings[6]; + if (i || pr == rankings[6]) { return lbl_803D5648[entry->x2 - 2] / 2; } } @@ -436,13 +441,13 @@ int fn_8016FFD4(struct lbl_8046B6A0_24C_t* arg0, int arg1, u8 arg2) for (i = 0; (u32) i < 0x101U; i++) { if ((s16) lbl_803D5A4C[i].kind < 0xD7) { - if ((u8) arg1 & (u8) fn_8016F180(i) && + if ((arg1 & 0xFF) & (u8) fn_8016F180(i) && pl_80039418((u8) arg2, i) != 0) { count += fn_8016FAD4(arg0, i, arg1, arg2); } } else { - if ((u8) arg1 & (u8) fn_8016F180(i)) { + if ((arg1 & 0xFF) & (u8) fn_8016F180(i)) { if ((unsigned) fn_801701C0(arg0, (u8) arg2, i) != 0) { count += fn_8016FAD4(arg0, i, arg1, arg2); } @@ -491,16 +496,10 @@ int fn_801701C0(void* arg0, int arg1, int arg2) u8* flags = rules->pad3F0; struct lbl_8046B6A0_24C_58_t* x58 = rules->x58; s32 scores[6]; - u8 rankings[7]; + u8 rankings[7] = { 0 }; - { - u8 is_teams = (u8) lbl_804D65A0; - *(s32*) &rankings[0] = lbl_804DA2F0; - *(u16*) &rankings[4] = lbl_804DA2F4; - rankings[6] = lbl_804DA2F6; - if (is_teams != 0) { - return 0; - } + if (lbl_804D65A0 != 0) { + return 0; } if (rules == NULL || x58 == NULL) { return 0; @@ -637,9 +636,9 @@ int fn_801701C0(void* arg0, int arg1, int arg2) s32* p = base; for (i = j; i > 0; i--) { if (p[0] < p[1]) { - s32 tmp = p[0]; - p[0] = p[1]; - p[1] = tmp; + s32 tmp = p[1]; + p[1] = p[0]; + p[0] = tmp; } p++; } @@ -699,9 +698,9 @@ int fn_801701C0(void* arg0, int arg1, int arg2) s32* p = base; for (i = j; i > 0; i--) { if (p[0] < p[1]) { - s32 tmp = p[0]; - p[0] = p[1]; - p[1] = tmp; + s32 tmp = p[1]; + p[1] = p[0]; + p[0] = tmp; } p++; } @@ -762,9 +761,9 @@ int fn_801701C0(void* arg0, int arg1, int arg2) s32* p = base; for (i = j; i > 0; i--) { if (p[0] < p[1]) { - s32 tmp = p[0]; - p[0] = p[1]; - p[1] = tmp; + s32 tmp = p[1]; + p[1] = p[0]; + p[0] = tmp; } p++; } @@ -827,9 +826,9 @@ int fn_801701C0(void* arg0, int arg1, int arg2) s32* p = base; for (i = j; i > 0; i--) { if (p[0] < p[1]) { - s32 tmp = p[0]; - p[0] = p[1]; - p[1] = tmp; + s32 tmp = p[1]; + p[1] = p[0]; + p[0] = tmp; } p++; } @@ -1016,9 +1015,9 @@ int fn_801701C0(void* arg0, int arg1, int arg2) f32* p = base; for (i = j; i > 0; i--) { if (p[0] < p[1]) { - f32 tmp = p[0]; - p[0] = p[1]; - p[1] = tmp; + f32 tmp = p[1]; + p[1] = p[0]; + p[0] = tmp; } p++; } @@ -1073,8 +1072,8 @@ int fn_801701C0(void* arg0, int arg1, int arg2) p++; } } - if (!(x58[arg1].x3 & 1) && rankings[arg1] == 0 && - x58[arg1].x20 == 0) + if (!((*(struct lbl_8046B6A0_24C_58_t(*)[6]) x58)[arg1].x3 & 1) && + rankings[arg1] == 0 && x58[arg1].x20 == 0) { return 1; } @@ -1096,13 +1095,17 @@ int fn_801701C0(void* arg0, int arg1, int arg2) p++; } } - if (!(x58[arg1].x3 & 1) && x58[arg1].x5 == 0 && - x58[arg1].x20 == 0) + if (!((*(struct lbl_8046B6A0_24C_58_t(*)[6]) x58)[arg1].x3 & + 1) && + x58[arg1].x5 == 0 && x58[arg1].x20 == 0) { return 1; } } else { - if (!(x58[arg1].x3 & 1) && x58[arg1].x20 == 0) { + if (!((*(struct lbl_8046B6A0_24C_58_t(*)[6]) x58)[arg1].x3 & + 1) && + x58[arg1].x20 == 0) + { return 1; } } @@ -1149,9 +1152,9 @@ int fn_801701C0(void* arg0, int arg1, int arg2) u32* p = vals; for (i = j; (u32) i > 0; i--) { if (p[0] > p[1]) { - u32 tmp = p[0]; - p[0] = p[1]; - p[1] = tmp; + u32 tmp = p[1]; + p[1] = p[0]; + p[0] = tmp; } p++; } @@ -1194,9 +1197,9 @@ int fn_801701C0(void* arg0, int arg1, int arg2) u32* p = vals; for (i = j; (u32) i > 0; i--) { if (p[0] < p[1]) { - u32 tmp = p[0]; - p[0] = p[1]; - p[1] = tmp; + u32 tmp = p[1]; + p[1] = p[0]; + p[0] = tmp; } p++; } @@ -1315,26 +1318,21 @@ int fn_80171BA4(void* arg0) player++; } while (player < 6); - player = 0; - do { + for (player = 0; player < 6; player++) { result = Player_GetPlayerSlotType(player); if (result != Gm_PKind_NA) { - j = 0; - do { + for (j = 0; j < 6; j++) { if (Player_GetPlayerSlotType(j) != Gm_PKind_NA && player != j && scores[player] < scores[j]) { lbl_804D65A8[player] += 1; } - j++; - } while (j < 6); - result = lbl_804D65A8[player]; - if (lbl_804D65B0 < result) { + } + if (lbl_804D65B0 < (result = lbl_804D65A8[player])) { lbl_804D65B0 = result; } } - player++; - } while (player < 6); + } return result; } diff --git a/src/melee/gm/gm_1832.c b/src/melee/gm/gm_1832.c index 4bc01f8b8c..7b84d0e283 100644 --- a/src/melee/gm/gm_1832.c +++ b/src/melee/gm/gm_1832.c @@ -78,24 +78,9 @@ static struct { u8 xE1; u8 xE2; u8 xE3; - int xE4; ///< related to model scale - int xE8; ///< game type - u8 xEC; - u8 xED; - u8 xEE; ///< roadmap (IrRdMap) progress - u8 xEF; ///< left char amt - u8 xF0; ///< right char amt - u8 xF1[3]; ///< left char ids - u8 xF4[3]; ///< right char ids - u8 xF7[3]; ///< left costumes - u8 xFA[3]; ///< right costumes - u8 xFD[3]; ///< left metal flags - u8 x100[3]; ///< right metal flags - u8 pad_103; - u8 pad_104[0x54]; } lbl_804735E8; -typedef struct gm_1832_8047368C_t { +static struct gm_1832_8047368C_t { /* 0x00 */ s32 model_scale_kind; /* 0x04 */ s32 game_type; /* 0x08 */ u8 xEC; @@ -110,10 +95,8 @@ typedef struct gm_1832_8047368C_t { /* 0x19 */ u8 xFD[3]; /* 0x1C */ u8 x100[3]; /* 0x1F */ u8 pad_1F[5]; -} gm_1832_8047368C_t; -STATIC_ASSERT(sizeof(gm_1832_8047368C_t) == 0x24); - -extern gm_1832_8047368C_t lbl_8047368C; +} lbl_8047368C; +STATIC_ASSERT(sizeof(struct gm_1832_8047368C_t) == 0x24); static HSD_Archive* lbl_804D65F4; static HSD_Archive* lbl_804D65F8; @@ -250,41 +233,41 @@ void fn_8018325C(HSD_GObj* arg0, int arg1) break; } - if (lbl_804735E8.xE4 == 2) { + if (lbl_8047368C.model_scale_kind == 2) { HSD_JObjAddTranslationX( - jobj, lbl_804D6604->x6A8[lbl_804735E8.xF1[arg1]].x00 - - lbl_804D6604->x630[lbl_804735E8.xEF].vals[arg1]); + jobj, lbl_804D6604->x6A8[lbl_8047368C.xF1[arg1]].x00 - + lbl_804D6604->x630[lbl_8047368C.xEF].vals[arg1]); HSD_JObjAddTranslationY( - jobj, lbl_804D6604->x6A8[lbl_804735E8.xF1[arg1]].x04 + - lbl_804D6604->x654[lbl_804735E8.xEF].vals[arg1]); + jobj, lbl_804D6604->x6A8[lbl_8047368C.xF1[arg1]].x04 + + lbl_804D6604->x654[lbl_8047368C.xEF].vals[arg1]); HSD_JObjSetScaleX(jobj, - lbl_804D6604->x6A8[lbl_804735E8.xF1[arg1]].x08.x * - lbl_804D6604->x678[lbl_804735E8.xEF].vals[arg1]); + lbl_804D6604->x6A8[lbl_8047368C.xF1[arg1]].x08.x * + lbl_804D6604->x678[lbl_8047368C.xEF].vals[arg1]); HSD_JObjSetScaleY(jobj, - lbl_804D6604->x6A8[lbl_804735E8.xF1[arg1]].x08.y * - lbl_804D6604->x678[lbl_804735E8.xEF].vals[arg1]); + lbl_804D6604->x6A8[lbl_8047368C.xF1[arg1]].x08.y * + lbl_804D6604->x678[lbl_8047368C.xEF].vals[arg1]); HSD_JObjSetScaleZ(jobj, - lbl_804D6604->x6A8[lbl_804735E8.xF1[arg1]].x08.z * - lbl_804D6604->x678[lbl_804735E8.xEF].vals[arg1]); + lbl_804D6604->x6A8[lbl_8047368C.xF1[arg1]].x08.z * + lbl_804D6604->x678[lbl_8047368C.xEF].vals[arg1]); } else { HSD_JObjAddTranslationX( - jobj, lbl_804D6604->x6C[lbl_804735E8.xF1[arg1]].x00 - - lbl_804D6604->x00[lbl_804735E8.xEF - 1].vals[arg1]); + jobj, lbl_804D6604->x6C[lbl_8047368C.xF1[arg1]].x00 - + lbl_804D6604->x00[lbl_8047368C.xEF - 1].vals[arg1]); HSD_JObjAddTranslationY( - jobj, lbl_804D6604->x6C[lbl_804735E8.xF1[arg1]].x04 + - lbl_804D6604->x18[lbl_804735E8.xEF].vals[arg1]); + jobj, lbl_804D6604->x6C[lbl_8047368C.xF1[arg1]].x04 + + lbl_804D6604->x18[lbl_8047368C.xEF].vals[arg1]); HSD_JObjSetScaleX(jobj, - lbl_804D6604->x6C[lbl_804735E8.xF1[arg1]].x08.x * - lbl_804D6604->x3C[lbl_804735E8.xEF].vals[arg1]); + lbl_804D6604->x6C[lbl_8047368C.xF1[arg1]].x08.x * + lbl_804D6604->x3C[lbl_8047368C.xEF].vals[arg1]); HSD_JObjSetScaleY(jobj, - lbl_804D6604->x6C[lbl_804735E8.xF1[arg1]].x08.y * - lbl_804D6604->x3C[lbl_804735E8.xEF].vals[arg1]); + lbl_804D6604->x6C[lbl_8047368C.xF1[arg1]].x08.y * + lbl_804D6604->x3C[lbl_8047368C.xEF].vals[arg1]); HSD_JObjSetScaleZ(jobj, - lbl_804D6604->x6C[lbl_804735E8.xF1[arg1]].x08.z * - lbl_804D6604->x3C[lbl_804735E8.xEF].vals[arg1]); + lbl_804D6604->x6C[lbl_8047368C.xF1[arg1]].x08.z * + lbl_804D6604->x3C[lbl_8047368C.xEF].vals[arg1]); } for (i = 0; i < 6; i++) { @@ -304,33 +287,32 @@ void fn_8018325C(HSD_GObj* arg0, int arg1) void fn_80184138(HSD_GObj* arg0, int arg1) { - u8 _padA[8]; Vec3 pos; - Vec3 scale; HSD_JObj* jobj = arg0->hsd_obj; HSD_JObj* src = lbl_804735A8.x4[1]; - int kind; f32 scl, xoff, yoff; + HSD_JObj* jobj2; int i; + PAD_STACK(16); + HSD_JObjGetTranslation(src, &pos); HSD_JObjSetTranslate(jobj, &pos); - kind = lbl_804735E8.xE4; - if (kind == 2) { - scl = lbl_804D6604->x37C[lbl_804735E8.xF4[arg1]].x08; + if (lbl_8047368C.model_scale_kind == 2) { + scl = lbl_804D6604->x37C[lbl_8047368C.xF4[arg1]].x08; } else { scl = 1.0f; } - if (kind == 2) { - xoff = lbl_804D6604->x37C[lbl_804735E8.xF4[arg1]].x00; + if (lbl_8047368C.model_scale_kind == 2) { + xoff = lbl_804D6604->x37C[lbl_8047368C.xF4[arg1]].x00; } else { xoff = 0.0f; } - if (kind == 2) { - yoff = lbl_804D6604->x37C[lbl_804735E8.xF4[arg1]].x04; + if (lbl_8047368C.model_scale_kind == 2) { + yoff = lbl_804D6604->x37C[lbl_8047368C.xF4[arg1]].x04; } else { yoff = 0.0f; } @@ -340,37 +322,38 @@ void fn_80184138(HSD_GObj* arg0, int arg1) } HSD_JObjAddTranslationX( - jobj, xoff + (-lbl_804D6604->x6C[lbl_804735E8.xF4[arg1]].x00 + - lbl_804D6604->x00[lbl_804735E8.xF0 - 1].vals[arg1])); + jobj, xoff + (-lbl_804D6604->x6C[lbl_8047368C.xF4[arg1]].x00 + + lbl_804D6604->x00[lbl_8047368C.xF0 - 1].vals[arg1])); HSD_JObjAddTranslationY( - jobj, yoff + (lbl_804D6604->x6C[lbl_804735E8.xF4[arg1]].x04 + - lbl_804D6604->x18[lbl_804735E8.xF0].vals[arg1])); + jobj, yoff + (lbl_804D6604->x6C[lbl_8047368C.xF4[arg1]].x04 + + lbl_804D6604->x18[lbl_8047368C.xF0].vals[arg1])); - if (kind == 2) { + if (lbl_8047368C.model_scale_kind == 2) { HSD_JObjSetScaleX( - jobj, lbl_804D6604->x6C[lbl_804735E8.xF4[arg1]].x08.x * scl); + jobj, lbl_804D6604->x6C[lbl_8047368C.xF4[arg1]].x08.x * scl); HSD_JObjSetScaleY( - jobj, lbl_804D6604->x6C[lbl_804735E8.xF4[arg1]].x08.y * scl); + jobj, lbl_804D6604->x6C[lbl_8047368C.xF4[arg1]].x08.y * scl); HSD_JObjSetScaleZ( - jobj, lbl_804D6604->x6C[lbl_804735E8.xF4[arg1]].x08.z * scl); + jobj, lbl_804D6604->x6C[lbl_8047368C.xF4[arg1]].x08.z * scl); } else { HSD_JObjSetScaleX(jobj, - lbl_804D6604->x6C[lbl_804735E8.xF4[arg1]].x08.x * - lbl_804D6604->x3C[lbl_804735E8.xF0].vals[arg1]); + lbl_804D6604->x6C[lbl_8047368C.xF4[arg1]].x08.x * + lbl_804D6604->x3C[lbl_8047368C.xF0].vals[arg1]); HSD_JObjSetScaleY(jobj, - lbl_804D6604->x6C[lbl_804735E8.xF4[arg1]].x08.y * - lbl_804D6604->x3C[lbl_804735E8.xF0].vals[arg1]); + lbl_804D6604->x6C[lbl_8047368C.xF4[arg1]].x08.y * + lbl_804D6604->x3C[lbl_8047368C.xF0].vals[arg1]); HSD_JObjSetScaleZ(jobj, - lbl_804D6604->x6C[lbl_804735E8.xF4[arg1]].x08.z * - lbl_804D6604->x3C[lbl_804735E8.xF0].vals[arg1]); + lbl_804D6604->x6C[lbl_8047368C.xF4[arg1]].x08.z * + lbl_804D6604->x3C[lbl_8047368C.xF0].vals[arg1]); } for (i = 0; i < 6; i++) { if (Player_GetEntity(i) == arg0) { HSD_GObj* entity2 = Player_GetEntityAtIndex(i, 1); if (entity2 != NULL) { - HSD_JObj* jobj2 = entity2->hsd_obj; + Vec3 scale; + jobj2 = entity2->hsd_obj; HSD_JObjGetTranslation(jobj, &pos); HSD_JObjSetTranslate(jobj2, &pos); HSD_JObjGetScale(jobj, &scale); @@ -421,12 +404,12 @@ static const char* const lbl_803B7C58[] = { "IrAls", "IrEzTarg", "IrEzTuki", void fn_80184AB8(HSD_GObj* arg0) { HSD_JObj* sp110; - u8 operand_pad[4]; char sp10[0x100]; HSD_JObj* jobj; s32 i; - char* name; - s32 k; + const char* name; + + PAD_STACK(4); jobj = arg0->hsd_obj; HSD_JObjAnimAll(jobj); @@ -438,11 +421,11 @@ void fn_80184AB8(HSD_GObj* arg0) return; } - if ((s32) lbl_804735E8.xE4 != 3) { - if ((u8) lbl_804735E8.xEE < 0xAU) { + if ((s32) lbl_8047368C.model_scale_kind != 3) { + if ((u8) lbl_8047368C.xEE < 0xAU) { lb_80011E24(jobj, &sp110, 0x12, -1); HSD_TObjReqAnimAll(sp110->u.dobj->mobj->tobj, - (f32) (lbl_804735E8.xEE % 10)); + (f32) (lbl_8047368C.xEE % 10)); HSD_AObjSetRate(sp110->u.dobj->mobj->tobj->aobj, 0.0f); lb_80011E24(jobj, &sp110, 0x13, -1); HSD_TObjReqAnimAll(sp110->u.dobj->mobj->tobj, 10.0f); @@ -450,11 +433,11 @@ void fn_80184AB8(HSD_GObj* arg0) } else { lb_80011E24(jobj, &sp110, 0x12, -1); HSD_TObjReqAnimAll(sp110->u.dobj->mobj->tobj, - (f32) (lbl_804735E8.xEE / 10)); + (f32) (lbl_8047368C.xEE / 10)); HSD_AObjSetRate(sp110->u.dobj->mobj->tobj->aobj, 0.0f); lb_80011E24(jobj, &sp110, 0x13, -1); HSD_TObjReqAnimAll(sp110->u.dobj->mobj->tobj, - (f32) (lbl_804735E8.xEE % 10)); + (f32) (lbl_8047368C.xEE % 10)); HSD_AObjSetRate(sp110->u.dobj->mobj->tobj->aobj, 0.0f); } @@ -465,15 +448,17 @@ void fn_80184AB8(HSD_GObj* arg0) case 0x2D: break; case 0x46: - if ((s32) lbl_804735E8.xE4 == 4 || (s32) lbl_804735E8.xE4 == 1) { + if ((s32) lbl_8047368C.model_scale_kind == 4 || + (s32) lbl_8047368C.model_scale_kind == 1) + { lbl_804D6608 = lbAudioAx_800237A8(0x7C863, 0x7F, 0x40); return; } - if ((s32) lbl_804735E8.xE4 == 2) { + if ((s32) lbl_8047368C.model_scale_kind == 2) { lbl_804D6608 = lbAudioAx_800237A8(0x7C837, 0x7F, 0x40); return; } - if ((u8) lbl_804735E8.x100[0] != 0) { + if ((u8) lbl_8047368C.x100[0] != 0) { lbl_804D6608 = lbAudioAx_800237A8(0x7C847, 0x7F, 0x40); return; } @@ -482,73 +467,64 @@ void fn_80184AB8(HSD_GObj* arg0) if ((s32) lbl_804D6608 != -1) { lbAudioAx_800236B8(lbl_804D6608); } - gm_80168C5C((u32) lbl_804735E8.xF4[0]); + gm_80168C5C((u32) lbl_8047368C.xF4[0]); return; case 0x5: - for (i = 0; i < (s32) lbl_804735E8.xEF; i++) { - if (i != 0 || (u8) lbl_804735E8.xED == 0x78) { - fn_80160DE8(lbl_804735A8.x4[7 + i], lbl_804735E8.xF1[i], 0, - 0, lbl_804D6604->x57C[lbl_804735E8.xEF].x18[i], - lbl_804D6604->x57C[lbl_804735E8.xEF].x24[i]); + for (i = 0; i < (s32) lbl_8047368C.xEF; i++) { + if (i != 0 || (u8) lbl_8047368C.xED == 0x78) { + fn_80160DE8(lbl_804735A8.x4[7 + i], lbl_8047368C.xF1[i], 0, + 0, lbl_804D6604->x57C[lbl_8047368C.xEF].x18[i], + lbl_804D6604->x57C[lbl_8047368C.xEF].x24[i]); } else { - name = GetNameText((s32) lbl_804735E8.xED); HSD_SisLib_803A70A0((HSD_Text*) lbl_804735A8.x4[7 + i], 0, - name); + GetNameText((s32) lbl_8047368C.xED)); HSD_SisLib_803A7548((HSD_Text*) lbl_804735A8.x4[7 + i], 0, 1.0f, 1.0f); } } return; case 0x6: - if ((s32) lbl_804735E8.xE4 == 4) { - k = 0; - name = (char*) gm_80160980(lbl_804735E8.xF4[0]); + if ((s32) lbl_8047368C.model_scale_kind == 4) { + i = 0; + name = gm_80160980(lbl_8047368C.xF4[0]); if (lbLang_IsSavedLanguageUS()) { { char* src = lbl_803D9414; while (*src != 0) { - sp10[k] = *src; - src++; - k++; + sp10[i++] = *src++; } } - sp10[k] = ' '; - k++; + sp10[i] = ' '; + i++; while (*name != 0) { - sp10[k] = *name; - name++; - k++; + sp10[i++] = *name++; } - sp10[k] = 0; + sp10[i] = 0; } else { { char* src2 = lbl_804D40A0; while (*name != 0) { - sp10[k] = *name; - name++; - k++; + sp10[i++] = *name++; } - sp10[k] = ' '; - k++; + sp10[i] = ' '; + i++; while (*src2 != 0) { - sp10[k] = *src2; - src2++; - k++; + sp10[i++] = *src2++; } - sp10[k] = 0; + sp10[i] = 0; } } HSD_SisLib_803A70A0((HSD_Text*) lbl_804735A8.x4[10], 0, sp10); HSD_SisLib_803A7548((HSD_Text*) lbl_804735A8.x4[10], 0, 0.8f * (lbl_804D6604->x57C[1].x18[0] * - fn_80160F58(lbl_804735E8.xF4[0])), + fn_80160F58(lbl_8047368C.xF4[0])), lbl_804D6604->x57C[1].x24[0]); return; } - for (i = 0; i < (s32) lbl_804735E8.xF0; i++) { - fn_80160DE8(lbl_804735A8.x4[10 + i], lbl_804735E8.xF4[i], 0, 1, - lbl_804D6604->x57C[lbl_804735E8.xF0].x18[i], - lbl_804D6604->x57C[lbl_804735E8.xF0].x24[i]); + for (i = 0; i < (s32) lbl_8047368C.xF0; i++) { + fn_80160DE8(lbl_804735A8.x4[10 + i], lbl_8047368C.xF4[i], 0, 1, + lbl_804D6604->x57C[lbl_8047368C.xF0].x18[i], + lbl_804D6604->x57C[lbl_8047368C.xF0].x24[i]); } break; } @@ -570,14 +546,16 @@ void fn_8018504C(void) } HSD_JObjReqAnimAll( lbl_804735A8.x4[5], - (f32) (lbl_804735A8.x3C + ((lbl_804735E8.xEE * 0x32) - new_var))); + (f32) (lbl_804735A8.x3C + ((lbl_8047368C.xEE * 0x32) - new_var))); HSD_JObjAnimAll(lbl_804735A8.x4[5]); HSD_JObjReqAnimAll( lbl_804735A8.x4[4], - (f32) (lbl_804735A8.x3A + ((lbl_804735E8.xEE * 0x32) - new_var))); + (f32) (lbl_804735A8.x3A + ((lbl_8047368C.xEE * 0x32) - new_var))); HSD_JObjAnimAll(lbl_804735A8.x4[4]); - if (((u16) lbl_804735A8.x38 == 0x2D) && ((s32) lbl_804735E8.xE4 == 3)) { - switch ((s32) lbl_804735E8.xE8) { + if (((u16) lbl_804735A8.x38 == 0x2D) && + ((s32) lbl_8047368C.model_scale_kind == 3)) + { + switch ((s32) lbl_8047368C.game_type) { case 1: lbAudioAx_800237A8(0x7C864, 0x7F, 0x40); return; @@ -622,21 +600,21 @@ s32 fn_801851C0(void) for (i = 0; i < (s32) lbl_804735E8.xE0; i++) { ClassicCharData* data = (ClassicCharData*) lbl_803D9248; result = i + 1; - Player_SetPlayerCharacter(result, (CharacterKind) lbl_804735E8.xF4[0]); + Player_SetPlayerCharacter(result, (CharacterKind) lbl_8047368C.xF4[0]); Player_SetPlayerId(result, 0); Player_SetSlottype(result, Gm_PKind_Demo); Player_SetFacingDirection(result, 0.0f); Player_SetCostumeId(result, i); - pos = data->offset[lbl_804735E8.xF4[0]]; + pos = data->offset[lbl_8047368C.xF4[0]]; Player_80032768(result, &pos); - if ((u8) lbl_804735E8.xF4[0] == 0xE) { + if ((u8) lbl_8047368C.xF4[0] == 0xE) { pos.x += data->samus_extra.x; pos.y += data->samus_extra.y; pos.z += data->samus_extra.z; Player_80032828(result, 1, &pos); } - Player_SetModelScale(result, data->scale[lbl_804735E8.xF4[0]]); - Player_SetFlagsBit5(result, lbl_804735E8.x100[0]); + Player_SetModelScale(result, data->scale[lbl_8047368C.xF4[0]]); + Player_SetFlagsBit5(result, lbl_8047368C.x100[0]); Player_80037054(result, 6); } @@ -781,7 +759,9 @@ void fn_8018575C(HSD_GObj* gobj) void fn_801857C4(HSD_GObj* arg0) { HSD_SObjDesc2 desc; + UNUSED u8 pad_b[8]; Vec3 pos_copy; + UNUSED u8 pad_a[8]; Vec3 pos; HSD_SObj* sobj; u64 num_cols; @@ -791,8 +771,6 @@ void fn_801857C4(HSD_GObj* arg0) u32 delay; s32 i; - PAD_STACK(0x10); - if (lbl_804735E8.xE1 != 0) { HSD_GObjPLink_80390228(lbl_804D65F0); img_idx = (u8*) lbl_804735E8.x40; @@ -842,11 +820,14 @@ void fn_801859C8(HSD_GObj* gobj) s32 fn_80185A0C(void) { - HSD_GObj* gobj; + HSD_ImageDesc* img; + u8* count_ptr; + u8* img_idx; HSD_GObj* gobj2; + HSD_GObj* gobj; HSD_GObj* gobj3; + HSD_CObj* cobj; HSD_GObjProc* proc; - HSD_ImageDesc *img, *img2; s32 i, v; u8 count; @@ -864,39 +845,36 @@ s32 fn_80185A0C(void) proc = HSD_GObj_SetupProc(gobj2, fn_801859C8, 0); proc->flags_3 = HSD_GObj_804D783C; - count = gm_80169238(lbl_804735E8.xF4[0]); - if ((s32) count > 3) { - count = 3; - } - lbl_804735E8.xE0 = count; + count = gm_80169238(lbl_8047368C.xF4[0]); + lbl_804735E8.xE0 = (s32) count > 3 ? 3 : count; - img = lbl_804735E8.x40; - img2 = lbl_804735E8.x88; + img_idx = lbl_804735E8.xD0 - 0x90; lbl_804735E8.xDC = gobj2; + count_ptr = &lbl_804735E8.xE0; + img = lbl_804735E8.x40; lbl_804735E8.xE1 = 0; - for (i = 0; i < (s32) lbl_804735E8.xE0; i++) { + for (i = 0; i < (s32) *count_ptr; i++) { img->image_ptr = NULL; lb_800121FC(img, 0x17C, 0x190, GX_TF_RGB5A3, 0); - img2[0].image_ptr = NULL; - lb_800121FC(&img2[0], 0x17C, 0x190, GX_TF_Z24X8, 0); + img[3].image_ptr = NULL; + lb_800121FC(&img[3], 0x17C, 0x190, GX_TF_Z24X8, 0); img++; } - for (v = 0; v < 10; v++) { - if ((v / (s32) lbl_804735E8.xE0) % 2 != 0) { - lbl_804735E8.xD0[v] = - (u8) ((lbl_804735E8.xE0 - 1) - (v % (s32) lbl_804735E8.xE0)); + for (v = 0; v < 10; v++, img_idx++) { + if ((v / (s32) *count_ptr) % 2 != 0) { + img_idx[0x90] = (u8) ((*count_ptr - 1) - (v % (s32) *count_ptr)); } else { - lbl_804735E8.xD0[v] = (u8) (v % (s32) lbl_804735E8.xE0); + img_idx[0x90] = (u8) (v % (s32) *count_ptr); } } HSD_GObj_SetupProc(GObj_Create(0x13, 1, 0), fn_801857C4, 0); gobj3 = GObj_Create(0x13, 0x14, 0); - HSD_GObjObject_80390A70(gobj3, HSD_GObj_804D784B, - HSD_CObjLoadDesc(lbl_804D6600->cameras->desc)); + cobj = HSD_CObjLoadDesc(lbl_804D6600->cameras->desc); + HSD_GObjObject_80390A70(gobj3, HSD_GObj_804D784B, cobj); GObj_SetupGXLinkMax(gobj3, (GObj_RenderFunc) (Event) fn_801852FC, 0); gobj3->gxlink_prios = 0x61; lbl_804D65F0 = gobj3; @@ -906,32 +884,25 @@ s32 fn_80185A0C(void) void fn_80185D64(void) { int i; - u8* ptr; + u8 chr; ftDemo_ObjAllocInit(); Player_InitAllPlayers(); - /// @todo fix pointer arithmetic - /// is this indicative of an inner struct starting at xE4? - ptr = (u8*) &lbl_804735E8.xE4; - for (i = 0; i < lbl_804735E8.xEF; i++) { - /// how do i access this sanely? - // its clearly iterating through xF1 - u8 chr = ptr[0x0D]; + for (i = 0; i < lbl_8047368C.xEF; i++) { + chr = lbl_8047368C.xF1[i]; if (chr != CHKIND_MAX) { Player_80036E20(chr, lbl_804D65F4, 1); } - ptr++; } - ptr = (u8*) &lbl_804735E8.xE4; - for (i = 0; i < lbl_804735E8.xF0; i++) { - if (ptr[0x10] == CKIND_GKOOPS) { - ptr[0x10] = CKIND_KOOPA; + for (i = 0; i < lbl_8047368C.xF0; i++) { + if (lbl_8047368C.xF4[i] == CKIND_GKOOPS) { + lbl_8047368C.xF4[i] = CKIND_KOOPA; } - if (ptr[0x10] != CHKIND_MAX) { - Player_80036E20(ptr[0x10], lbl_804D65F4, 1); + chr = lbl_8047368C.xF4[i]; + if (chr != CHKIND_MAX) { + Player_80036E20(chr, lbl_804D65F4, 1); } - ptr++; } } @@ -965,26 +936,26 @@ s32 fn_80185E34(void) void fn_80185F5C(s32 arg0) { ClassicProcArray local; - int i; - int player_slot = 0; + int i = 0; local = lbl_803B7C40; - for (i = 0; i < lbl_804735E8.xF0; i++) { - if (lbl_804735E8.xF4[i] != 0x21) { - Player_80036CF0(player_slot); - Player_SetPlayerCharacter(player_slot, - (CharacterKind) lbl_804735E8.xF4[i]); - Player_SetCostumeId(player_slot, (s32) lbl_804735E8.xFA[i]); - Player_SetPlayerId(player_slot, 0); - Player_SetSlottype(player_slot, Gm_PKind_Demo); - Player_SetFacingDirection(player_slot, 0.0f); - Player_SetModelScale(player_slot, 1.0f); - Player_SetFlagsBit5(player_slot, lbl_804735E8.x100[i]); - Player_80036F34(player_slot, 6); - HSD_GObj_SetupProc(Player_GetEntity(player_slot), - (HSD_GObjEvent) (Event) local.v[i], 0x16); - player_slot++; + while (i < lbl_8047368C.xF0) { + if (lbl_8047368C.xF1[i] != 0x21) { + Player_80036CF0(arg0); + Player_SetPlayerCharacter(arg0, + (CharacterKind) lbl_8047368C.xF4[i]); + Player_SetCostumeId(arg0, (s32) lbl_8047368C.xFA[i]); + Player_SetPlayerId(arg0, 0); + Player_SetSlottype(arg0, Gm_PKind_Demo); + Player_SetFacingDirection(arg0, 0.0f); + Player_SetModelScale(arg0, 1.0f); + Player_SetFlagsBit5(arg0, lbl_8047368C.x100[i]); + Player_80036F34(arg0, 6); + HSD_GObj_SetupProc(Player_GetEntity(arg0), + (HSD_GObjEvent) (Event) local.v[i + 3], 0x16); + arg0++; } + i++; } } @@ -1027,7 +998,7 @@ void fn_801861B8(void) HSD_SisLib_803A611C(0, NULL, 9, 0x14, 0, 0xE, 0, 0x12); HSD_SisLib_803A62A0(0, "SdIntro.dat", "SIS_IntroData"); - for (i = 0; i < (s32) lbl_804735E8.xEF; i++) { + for (i = 0; i < (s32) lbl_8047368C.xEF; i++) { lbl_804735A8.x4[7 + i] = (HSD_JObj*) HSD_SisLib_803A6754(0, 0); ((HSD_Text*) lbl_804735A8.x4[7 + i])->default_kerning = 1; text = (HSD_Text*) lbl_804735A8.x4[7 + i]; @@ -1035,21 +1006,21 @@ void fn_801861B8(void) text->font_size.y = 1.0f; ((HSD_Text*) lbl_804735A8.x4[7 + i])->default_alignment = 1; HSD_SisLib_803A6B98((HSD_Text*) lbl_804735A8.x4[7 + i], - lbl_804D6604->x57C[lbl_804735E8.xEF].x00[i], - lbl_804D6604->x57C[lbl_804735E8.xEF].x0C[i], " "); + lbl_804D6604->x57C[lbl_8047368C.xEF].x00[i], + lbl_804D6604->x57C[lbl_8047368C.xEF].x0C[i], " "); HSD_SisLib_803A7548((HSD_Text*) lbl_804735A8.x4[7 + i], 0, - lbl_804D6604->x57C[lbl_804735E8.xEF].x18[i], - lbl_804D6604->x57C[lbl_804735E8.xEF].x24[i]); + lbl_804D6604->x57C[lbl_8047368C.xEF].x18[i], + lbl_804D6604->x57C[lbl_8047368C.xEF].x24[i]); } - for (i = 0; i < (s32) lbl_804735E8.xF0; i++) { + for (i = 0; i < (s32) lbl_8047368C.xF0; i++) { lbl_804735A8.x4[10 + i] = (HSD_JObj*) HSD_SisLib_803A6754(0, 0); ((HSD_Text*) lbl_804735A8.x4[10 + i])->default_kerning = 1; text = (HSD_Text*) lbl_804735A8.x4[10 + i]; text->font_size.x = 1.0f; text->font_size.y = 1.0f; ((HSD_Text*) lbl_804735A8.x4[10 + i])->default_alignment = 1; - if ((s32) lbl_804735E8.xE4 == 4) { + if ((s32) lbl_8047368C.model_scale_kind == 4) { HSD_SisLib_803A6B98((HSD_Text*) lbl_804735A8.x4[10 + i], 340.0f + lbl_804D6604->x57C[1].x00[0], lbl_804D6604->x57C[1].x0C[0], " "); @@ -1060,12 +1031,12 @@ void fn_801861B8(void) } HSD_SisLib_803A6B98((HSD_Text*) lbl_804735A8.x4[10 + i], 340.0f + - lbl_804D6604->x57C[lbl_804735E8.xF0].x00[i], - lbl_804D6604->x57C[lbl_804735E8.xF0].x0C[i], " "); + lbl_804D6604->x57C[lbl_8047368C.xF0].x00[i], + lbl_804D6604->x57C[lbl_8047368C.xF0].x0C[i], " "); HSD_SisLib_803A7548((HSD_Text*) lbl_804735A8.x4[10 + i], 0, 340.0f + - lbl_804D6604->x57C[lbl_804735E8.xF0].x18[i], - lbl_804D6604->x57C[lbl_804735E8.xF0].x24[i]); + lbl_804D6604->x57C[lbl_8047368C.xF0].x18[i], + lbl_804D6604->x57C[lbl_8047368C.xF0].x24[i]); } } @@ -1081,7 +1052,7 @@ void fn_80186400(void) gm_8016895C(jobj, lbl_804D65FC->models[0], 0); HSD_JObjReqAnimAll(jobj, 0.0F); HSD_JObjAnimAll(jobj); - if (lbl_804735E8.xE4 != 3) { + if (lbl_8047368C.model_scale_kind != 3) { lb_80011E24(jobj, &lbl_804735A8.x4[0], 4, -1); lb_80011E24(jobj, &lbl_804735A8.x4[1], 5, -1); lb_80011E24(jobj, &lbl_804735A8.x4[2], 0x3A, -1); @@ -1102,9 +1073,8 @@ void fn_80186634(void* arg0) HSD_GObj* gobj3; HSD_JObj* jobj; HSD_GObj* gobj4; - u8 operand_pad[8]; const char* names[4]; - PAD_STACK(8); + PAD_STACK(16); lbArchive_80016DBC("GmIntEz.dat", &lbl_804D6604, "gmIntroEasyTable", 0); Camera_80028B9C(0xC); @@ -1122,8 +1092,9 @@ void fn_80186634(void* arg0) names[1] = lbl_803B7C58[1]; names[2] = lbl_803B7C58[2]; names[3] = lbl_803B7C58[3]; - lbl_804D65F4 = lbArchive_80016DBC(names[lbl_804735E8.xE8], &lbl_804D65FC, - "ScItrAllstar_scene_data", 0); + lbl_804D65F4 = + lbArchive_80016DBC(names[lbl_8047368C.game_type], &lbl_804D65FC, + "ScItrAllstar_scene_data", 0); lbl_804D65F8 = lbArchive_80016DBC(lbl_804D40B0, &lbl_804D6600, "ScItrAllstar_scene_data", 0); @@ -1132,11 +1103,11 @@ void fn_80186634(void* arg0) lb_80011AC4(lbl_804D65FC->lights)); GObj_SetupGXLink(gobj, HSD_GObj_LObjCallback, 0, 0); - if ((s32) lbl_804735E8.xE4 != 3) { - lbl_804735E8.xE8 = 0; + if ((s32) lbl_8047368C.model_scale_kind != 3) { + lbl_8047368C.game_type = 0; } - switch ((s32) lbl_804735E8.xE4) { + switch ((s32) lbl_8047368C.model_scale_kind) { case 3: gobj2 = GObj_Create(0x13, 0x14, 0); cobj1 = HSD_CObjLoadDesc(lbl_804D65FC->cameras[0].desc); @@ -1146,7 +1117,7 @@ void fn_80186634(void* arg0) gobj2->gxlink_prios = 0x801; gobj3 = GObj_Create(0x13, 0x15, 0); HSD_GObjObject_80390A70(gobj3, HSD_GObj_804D784B, cobj2); - if ((s32) lbl_804735E8.xE4 == 4) { + if ((s32) lbl_8047368C.model_scale_kind == 4) { GObj_SetupGXLinkMax(gobj3, (GObj_RenderFunc) (Event) fn_8018569C, 8); } else { @@ -1160,7 +1131,7 @@ void fn_80186634(void* arg0) GObj_SetupGXLink(gobj4, HSD_GObj_JObjCallback, 0xC, 0); HSD_GObj_SetupProc(gobj4, (HSD_GObjEvent) (Event) fn_8018504C, 0x11); gm_8016895C(jobj, lbl_804D6600->models[0], 0); - HSD_JObjReqAnimAll(jobj, (f32) ((lbl_804735E8.xEE - 1) * 0x32)); + HSD_JObjReqAnimAll(jobj, (f32) ((lbl_8047368C.xEE - 1) * 0x32)); HSD_JObjAnimAll(jobj); lb_80011E24(jobj, &lbl_804735A8.x4[4], 0xE, -1); lb_80011E24(jobj, &lbl_804735A8.x4[5], 1, -1); @@ -1170,7 +1141,9 @@ void fn_80186634(void* arg0) GObj_SetupGXLink(gobj, HSD_GObj_FogCallback, 0xB, 0); fn_80186080(); break; - default: + case 0: + case 1: + case 2: gobj2 = GObj_Create(0x13, 0x14, 0); cobj1 = HSD_CObjLoadDesc(lbl_804D65FC->cameras[0].desc); cobj2 = HSD_CObjLoadDesc(lbl_804D6600->cameras[0].desc); @@ -1179,7 +1152,7 @@ void fn_80186634(void* arg0) gobj2->gxlink_prios = 0x801; gobj3 = GObj_Create(0x13, 0x15, 0); HSD_GObjObject_80390A70(gobj3, HSD_GObj_804D784B, cobj2); - if ((s32) lbl_804735E8.xE4 == 4) { + if ((s32) lbl_8047368C.model_scale_kind == 4) { GObj_SetupGXLinkMax(gobj3, (GObj_RenderFunc) (Event) fn_8018569C, 8); } else { @@ -1193,7 +1166,7 @@ void fn_80186634(void* arg0) GObj_SetupGXLink(gobj4, HSD_GObj_JObjCallback, 0xC, 0); HSD_GObj_SetupProc(gobj4, (HSD_GObjEvent) (Event) fn_8018504C, 0x11); gm_8016895C(jobj, lbl_804D6600->models[0], 0); - HSD_JObjReqAnimAll(jobj, (f32) ((lbl_804735E8.xEE - 1) * 0x32)); + HSD_JObjReqAnimAll(jobj, (f32) ((lbl_8047368C.xEE - 1) * 0x32)); HSD_JObjAnimAll(jobj); lb_80011E24(jobj, &lbl_804735A8.x4[4], 0xE, -1); lb_80011E24(jobj, &lbl_804735A8.x4[5], 1, -1); @@ -1214,7 +1187,7 @@ void fn_80186634(void* arg0) gobj2->gxlink_prios = 0x801; gobj3 = GObj_Create(0x13, 0x15, 0); HSD_GObjObject_80390A70(gobj3, HSD_GObj_804D784B, cobj2); - if ((s32) lbl_804735E8.xE4 == 4) { + if ((s32) lbl_8047368C.model_scale_kind == 4) { GObj_SetupGXLinkMax(gobj3, (GObj_RenderFunc) (Event) fn_8018569C, 8); } else { @@ -1228,7 +1201,7 @@ void fn_80186634(void* arg0) GObj_SetupGXLink(gobj4, HSD_GObj_JObjCallback, 0xC, 0); HSD_GObj_SetupProc(gobj4, (HSD_GObjEvent) (Event) fn_8018504C, 0x11); gm_8016895C(jobj, lbl_804D6600->models[0], 0); - HSD_JObjReqAnimAll(jobj, (f32) ((lbl_804735E8.xEE - 1) * 0x32)); + HSD_JObjReqAnimAll(jobj, (f32) ((lbl_8047368C.xEE - 1) * 0x32)); HSD_JObjAnimAll(jobj); lb_80011E24(jobj, &lbl_804735A8.x4[4], 0xE, -1); lb_80011E24(jobj, &lbl_804735A8.x4[5], 1, -1); @@ -1258,7 +1231,7 @@ static struct enterdata { int x0, x4; } lbl_804D6618; -static struct { +static struct ClassicIntroSceneData { int x0, x4; HSD_JObj* x8; HSD_JObj* xC; @@ -1295,23 +1268,24 @@ void gm_80186E30_OnEnter(void* arg0_) lbl_804735A8.x38 = 0; lbl_804735A8.x3A = 0; lbl_804735A8.x3C = 0; - *(ClassicModeEnterData*) &lbl_804735E8.xE4 = *arg0; + *(ClassicModeEnterData*) &lbl_8047368C.model_scale_kind = *arg0; fn_80186634(arg0_); lbl_804D6608 = -1; - gm_80167858((int) (s8) lbl_804735E8.xEC, lbl_804735E8.xED, 0xB, 0x2D); + gm_80167858((int) (s8) lbl_8047368C.xEC, lbl_8047368C.xED, 0xB, 0x2D); gm_80168F88(); } void fn_80186EFC(HSD_GObj* gobj) { HSD_JObj* jobj = GET_JOBJ(gobj); + struct ClassicIntroSceneData* data = &lbl_804736B0; PAD_STACK(8); - HSD_JObjReqAnimAll(lbl_804736B0.xC, 0.0F); + HSD_JObjReqAnimAll(data->xC, 0.0f); HSD_JObjAnimAll(jobj); if (lbl_804736B0.x4 < 0x8C) { lbl_804736B0.x4++; } else { - lbl_804736B0.x0 = 1; + data->x0 = 1; } } @@ -1521,7 +1495,7 @@ void gm_801877A8_OnEnter(void* arg0_) } #pragma pop -static struct { +static struct gm_1832_804736C0_t { DynamicModelDesc*** x0; HSD_CameraAnim** x4; HSD_GObj* x8; @@ -1539,26 +1513,30 @@ static struct { u8 state2 : 2; } x37; u8 x38; + u8 pad_39[7]; } lbl_804736C0; +STATIC_ASSERT(sizeof(struct gm_1832_804736C0_t) == 0x40); +typedef struct gm_1832_804736C0_t gm_1832_804736C0_t; void fn_80187910(HSD_GObj* arg0) { Vec3 sp10; + gm_1832_804736C0_t* data; HSD_CObj* cobj; s32 frame; f32 scale; PAD_STACK(4); + data = &lbl_804736C0; cobj = arg0->hsd_obj; - if (gm_GetButtonsTriggered(lbl_804736C0.x38) & PAD_BUTTON_A) { - lbl_804736C0.x37.frame_counter = - (s32) cobj->eyepos->aobj->curr_frame / 300; - if (++lbl_804736C0.x37.frame_counter >= 8U) { - lbl_804736C0.x37.frame_counter = 0; + if (gm_GetButtonsTriggered(data->x38) & PAD_BUTTON_A) { + data->x37.frame_counter = (s32) cobj->eyepos->aobj->curr_frame / 300; + if (++data->x37.frame_counter >= 8U) { + data->x37.frame_counter = 0; } - frame = lbl_804736C0.x37.frame_counter * 0x12C; + frame = data->x37.frame_counter * 0x12C; HSD_CObjRemoveAnim(cobj); - HSD_CObjAddAnim(cobj, *(HSD_CameraAnim**) lbl_804736C0.x4[1]); + HSD_CObjAddAnim(cobj, *(HSD_CameraAnim**) data->x4[1]); HSD_CObjReqAnim(cobj, (f32) frame); } HSD_CObjAnim(cobj); @@ -1586,54 +1564,53 @@ typedef struct { u8 b7 : 1, b6 : 1, b5 : 1, b4 : 1, b3 : 1, b2 : 1, b1 : 1, b0 : 1; } u8_bits; +static inline void fn_80187AB4_LoadAnim(HSD_JObj* jobj, + gm_1832_804736C0_t* data) +{ + DynamicModelDesc* desc = (*data->x0)[11 - data->x36.stage_index]; + int anim_state; + + if (desc->anims != NULL) { + anim_state = data->x37.anim_state; + if (desc->anims[anim_state] != NULL) { + lb_8000C0E8(jobj, anim_state, desc); + HSD_JObjReqAnimAll(jobj, 0.0f); + HSD_JObjAnimAll(jobj); + } + } +} + void fn_80187AB4(HSD_GObj* gobj) { + gm_1832_804736C0_t* data = &lbl_804736C0; HSD_JObj* jobj = GET_JOBJ(gobj); - int state = lbl_804736C0.x37.anim_state; - DynamicModelDesc* desc; - int anim_state; - PAD_STACK(8); + int state = data->x37.anim_state; + PAD_STACK(16); switch (state) { case 0: if (lb_8000B09C(jobj) == 0) { - lbl_804736C0.x37.anim_state = 1; - desc = (*lbl_804736C0.x0)[11 - lbl_804736C0.x36.stage_index]; - if (desc->anims != NULL) { - anim_state = lbl_804736C0.x37.anim_state; - if (desc->anims[anim_state] != NULL) { - lb_8000C0E8(jobj, anim_state, desc); - HSD_JObjReqAnimAll(jobj, 0.0f); - HSD_JObjAnimAll(jobj); - } - } - lbl_804736C0.x34 = 0x960; + data->x37.anim_state = 1; + fn_80187AB4_LoadAnim(jobj, data); + data->x34 = 0x960; } break; case 1: - if ((u32) lbl_804736C0.x36.active == 1U) { - lbl_804736C0.x36.flash = 1; + if ((u32) data->x36.active == 1U) { + data->x36.flash = 1; } - if (lbl_804736C0.x36.flash) { - lbl_804736C0.x37.anim_state = 2; - lbl_804736C0.x36.done = 1; + if (data->x36.flash) { + data->x37.anim_state = 2; + data->x36.done = 1; lbBgFlash_8002063C(1); } if (lb_8000B09C(jobj) == 0) { - desc = (*lbl_804736C0.x0)[11 - lbl_804736C0.x36.stage_index]; - if (desc->anims != NULL) { - anim_state = lbl_804736C0.x37.anim_state; - if (desc->anims[anim_state] != NULL) { - lb_8000C0E8(jobj, anim_state, desc); - HSD_JObjReqAnimAll(jobj, 0.0f); - HSD_JObjAnimAll(jobj); - } - } + fn_80187AB4_LoadAnim(jobj, data); } break; case 2: if (lb_8000B09C(jobj) == 0) { - lbl_804736C0.x36.done = 1; + data->x36.done = 1; HSD_GObjPLink_80390228(gobj); } break; @@ -1650,17 +1627,18 @@ void fn_80187C9C(HSD_GObj* gobj, int arg1) void fn_80187CF4(HSD_GObj* gobj) { - HSD_JObj* jobj = gobj->user_data; - int state = lbl_804736C0.x37.state2; + gm_1832_804736C0_t* data = &lbl_804736C0; + HSD_JObj* jobj = gobj->hsd_obj; + int state = data->x37.state2; DynamicModelDesc* desc; int anim_state; switch (state) { case 0: if (lb_8000B09C(jobj) == 0) { - lbl_804736C0.x37.state2 = 1; - anim_state = lbl_804736C0.x37.state2; - desc = (*lbl_804736C0.x0)[12]; + data->x37.state2 = 1; + anim_state = data->x37.state2; + desc = (*data->x0)[12]; if (desc->anims[anim_state] != NULL) { lb_8000C0E8(jobj, anim_state, desc); HSD_JObjReqAnimAll(jobj, 0.0f); @@ -1670,9 +1648,9 @@ void fn_80187CF4(HSD_GObj* gobj) break; case 1: if (lb_8000B09C(jobj) == 0) { - lbl_804736C0.x37.state2 = 2; - anim_state = lbl_804736C0.x37.state2; - desc = (*lbl_804736C0.x0)[12]; + data->x37.state2 = 2; + anim_state = data->x37.state2; + desc = (*data->x0)[12]; if (desc->anims[anim_state] != NULL) { lb_8000C0E8(jobj, anim_state, desc); HSD_JObjReqAnimAll(jobj, 0.0f); @@ -1681,20 +1659,20 @@ void fn_80187CF4(HSD_GObj* gobj) } break; case 2: - if (gm_GetButtonsTriggered(lbl_804736C0.x38) & PAD_BUTTON_START) { + if (gm_GetButtonsTriggered(data->x38) & PAD_BUTTON_START) { lbAudioAx_80024030(1); - lbl_804736C0.x36.active = 1; - lbl_804736C0.x37.state2 = 3; - anim_state = lbl_804736C0.x37.state2; - desc = (*lbl_804736C0.x0)[12]; + data->x36.active = 1; + data->x37.state2 = 3; + anim_state = data->x37.state2; + desc = (*data->x0)[12]; if (desc->anims[anim_state] != NULL) { lb_8000C0E8(jobj, anim_state, desc); HSD_JObjReqAnimAll(jobj, 0.0f); HSD_JObjAnimAll(jobj); } } else if (lb_8000B09C(jobj) == 0) { - anim_state = lbl_804736C0.x37.state2; - desc = (*lbl_804736C0.x0)[12]; + anim_state = data->x37.state2; + desc = (*data->x0)[12]; if (desc->anims[anim_state] != NULL) { lb_8000C0E8(jobj, anim_state, desc); HSD_JObjReqAnimAll(jobj, 0.0f); @@ -1708,7 +1686,7 @@ void fn_80187CF4(HSD_GObj* gobj) } break; } - HSD_JObjAnimAll(gobj->user_data); + HSD_JObjAnimAll(gobj->hsd_obj); } static char lbl_804D4138[] = "IrNml"; @@ -1776,16 +1754,6 @@ void gm_80187F48_OnEnter(void* arg0_) { u8* arg0 = arg0_; u8 stage_index; - HSD_GObj* cam_gobj; - HSD_CObj* cobj; - HSD_GObj* gobj2; - HSD_GObj* gobj3; - HSD_GObj* gobj4; - HSD_GObj* gobj5; - HSD_JObj* jobj; - HSD_JObj* jobj2; - DynamicModelDesc* desc; - int anim_idx; PAD_STACK(24); lbl_804736C0.x38 = arg0[0]; @@ -1802,12 +1770,13 @@ void gm_80187F48_OnEnter(void* arg0_) Player_InitAllPlayers(); lbBgFlash_800209F4(); + stage_index = arg0[1]; lbl_804736C0.x37.anim_state = 0; lbl_804736C0.x37.frame_counter = 0; lbl_804736C0.x34 = 0; lbl_804736C0.x36.done = 0; lbl_804736C0.x36.flash = 0; - lbl_804736C0.x36.stage_index = arg0[1]; + lbl_804736C0.x36.stage_index = stage_index; lbl_804736C0.x37.state2 = 0; lbl_804736C0.x36.active = 0; @@ -1820,68 +1789,82 @@ void gm_80187F48_OnEnter(void* arg0_) { u64 ret = lbAudioAx_80026E84(Player_GetPlayerCharacter(0)); lbAudioAx_8002702C((s32) lbl_803D9750[stage_index + 12], - ret | *(u64*) &lbl_803D9750[stage_index * 2 + 24]); + ret | ((u64*) &lbl_803D9750[24])[stage_index]); } lbAudioAx_80027168(); lbAudioAx_80027648(); - cam_gobj = GObj_Create(0x13, 0x14, 0); - lbl_804736C0.x8 = cam_gobj; - cobj = HSD_CObjLoadDesc((HSD_CObjDesc*) *lbl_804736C0.x4); - HSD_GObjObject_80390A70(cam_gobj, HSD_GObj_804D784B, cobj); - GObj_SetupGXLinkMax(cam_gobj, (void*) Camera_800304E0, 8); - HSD_GObj_SetupProc(cam_gobj, fn_80187910, 0); - HSD_CObjAddAnim(cobj, *(HSD_CameraAnim**) lbl_804736C0.x4[1]); - HSD_CObjReqAnim(cobj, 0.0f); - - gobj2 = GObj_Create(0x13, 0x14, 0); - HSD_GObjObject_80390A70( - gobj2, HSD_GObj_804D784B, - HSD_CObjLoadDesc(((SceneDesc*) lbl_804736C0.x0)->cameras[0].desc)); - GObj_SetupGXLinkMax(gobj2, HSD_GObj_803910D8, 8); - gobj2->gxlink_prios = 0xC00; - - gobj3 = GObj_Create(0xB, 3, 0); - HSD_GObjObject_80390A70( - gobj3, HSD_GObj_804D784A, - lb_80011AC4(((SceneDesc*) lbl_804736C0.x0)->lights)); - GObj_SetupGXLink(gobj3, HSD_GObj_LObjCallback, 0xA, 0); - - gobj4 = GObj_Create(0xE, 0xF, 0); - jobj = HSD_JObjLoadJoint( - (*lbl_804736C0.x0)[11 - lbl_804736C0.x36.stage_index]->joint); - lb_80011C18(jobj, 0x08000000); - HSD_GObjObject_80390A70(gobj4, HSD_GObj_804D7849, jobj); - GObj_SetupGXLink(gobj4, fn_80187C9C, 0xB, 0xB); - - desc = (*lbl_804736C0.x0)[11 - lbl_804736C0.x36.stage_index]; - if (desc->anims != NULL) { - anim_idx = lbl_804736C0.x37.anim_state; + { + HSD_GObj* cam_gobj = GObj_Create(0x13, 0x14, 0); + HSD_CObj* cobj; + lbl_804736C0.x8 = cam_gobj; + cobj = HSD_CObjLoadDesc((HSD_CObjDesc*) *lbl_804736C0.x4); + HSD_GObjObject_80390A70(cam_gobj, HSD_GObj_804D784B, cobj); + GObj_SetupGXLinkMax(cam_gobj, + (GObj_RenderFunc) (Event) Camera_800304E0, 8); + HSD_GObj_SetupProc(cam_gobj, fn_80187910, 0); + HSD_CObjAddAnim(cobj, *(HSD_CameraAnim**) lbl_804736C0.x4[1]); + HSD_CObjReqAnim(cobj, 0.0f); + } + + { + HSD_GObj* gobj = GObj_Create(0x13, 0x14, 0); + HSD_CObj* cobj = + HSD_CObjLoadDesc(((SceneDesc*) lbl_804736C0.x0)->cameras[0].desc); + HSD_GObjObject_80390A70(gobj, HSD_GObj_804D784B, cobj); + GObj_SetupGXLinkMax(gobj, HSD_GObj_803910D8, 8); + gobj->gxlink_prios = 0xC00; + } + + { + HSD_GObj* gobj = GObj_Create(0xB, 3, 0); + HSD_LObj* lobj = lb_80011AC4(((SceneDesc*) lbl_804736C0.x0)->lights); + HSD_GObjObject_80390A70(gobj, HSD_GObj_804D784A, lobj); + GObj_SetupGXLink(gobj, HSD_GObj_LObjCallback, 0xA, 0); + } + + { + HSD_GObj* gobj = GObj_Create(0xE, 0xF, 0); + HSD_JObj* jobj = HSD_JObjLoadJoint( + (*lbl_804736C0.x0)[11 - lbl_804736C0.x36.stage_index]->joint); + DynamicModelDesc* desc; + lb_80011C18(jobj, 0x08000000); + HSD_GObjObject_80390A70(gobj, HSD_GObj_804D7849, jobj); + GObj_SetupGXLink(gobj, fn_80187C9C, 0xB, 0xB); + + desc = (*lbl_804736C0.x0)[11 - lbl_804736C0.x36.stage_index]; + if (desc->anims != NULL) { + int anim_idx = lbl_804736C0.x37.anim_state; + if (desc->anims[anim_idx] != NULL) { + lb_8000C0E8(jobj, anim_idx, desc); + HSD_JObjReqAnimAll(jobj, 0.0f); + HSD_JObjAnimAll(jobj); + } + } + HSD_GObj_SetupProc(gobj, fn_80187AB4, 0); + } + + { + HSD_GObj* gobj = GObj_Create(0xE, 0xF, 0); + HSD_JObj* jobj = HSD_JObjLoadJoint((*lbl_804736C0.x0)[12]->joint); + int anim_idx; + DynamicModelDesc* desc; + lb_80011C18(jobj, 0x08000000); + HSD_GObjObject_80390A70(gobj, HSD_GObj_804D7849, jobj); + GObj_SetupGXLink(gobj, fn_80187C9C, 0xB, 0xB); + + anim_idx = lbl_804736C0.x37.state2; + desc = (*lbl_804736C0.x0)[12]; if (desc->anims[anim_idx] != NULL) { lb_8000C0E8(jobj, anim_idx, desc); HSD_JObjReqAnimAll(jobj, 0.0f); HSD_JObjAnimAll(jobj); } - } - HSD_GObj_SetupProc(gobj4, fn_80187AB4, 0); - gobj5 = GObj_Create(0xE, 0xF, 0); - jobj2 = HSD_JObjLoadJoint((*lbl_804736C0.x0)[12]->joint); - lb_80011C18(jobj2, 0x08000000); - HSD_GObjObject_80390A70(gobj5, HSD_GObj_804D7849, jobj2); - GObj_SetupGXLink(gobj5, fn_80187C9C, 0xB, 0xB); - - anim_idx = lbl_804736C0.x37.state2; - desc = (*lbl_804736C0.x0)[12]; - if (desc->anims[anim_idx] != NULL) { - lb_8000C0E8(jobj2, anim_idx, desc); - HSD_JObjReqAnimAll(jobj2, 0.0f); - HSD_JObjAnimAll(jobj2); + HSD_JObjReqAnimAll(jobj, 0.0f); + HSD_JObjAnimAll(jobj); + HSD_GObj_SetupProc(gobj, fn_80187CF4, 0); } - - HSD_JObjReqAnimAll(jobj2, 0.0f); - HSD_JObjAnimAll(jobj2); - HSD_GObj_SetupProc(gobj5, fn_80187CF4, 0); lbAudioAx_80023F28(0x2E); } @@ -1970,14 +1953,15 @@ int fn_8018846C(void) inline int fn_801884F8_inline(void) { int result; + TrainingModeState* state = &lbl_80473700; result = pl_80041300(0); if (result != 0) { - lbl_80473700.result_cache[0] = result; - lbl_80473700.result_cache[1] = 1; + state->result_cache[0] = result; + state->result_cache[1] = 1; } - if (lbl_80473700.result_cache[1] != 0) { - result = lbl_80473700.result_cache[0]; + if (state->result_cache[1] != 0) { + result = state->result_cache[0]; } return result; } @@ -1985,33 +1969,35 @@ inline int fn_801884F8_inline(void) int fn_801884F8(void) { int result; + TrainingModeState* state = &lbl_80473700; result = pl_80041300(0); if (result != 0) { - lbl_80473700.result_cache[0] = result; - lbl_80473700.result_cache[1] = 1; + state->result_cache[0] = result; + state->result_cache[1] = 1; } - if (lbl_80473700.result_cache[1] != 0) { - result = lbl_80473700.result_cache[0]; + if (state->result_cache[1] != 0) { + result = state->result_cache[0]; } return result; } void fn_80188550(int arg0) { - int current = lbl_80473700.count; + TrainingModeState* state = &lbl_80473700; + int current = state->count; int j; int to_remove; if (arg0 != current) { - if (arg0 > lbl_80473700.count) { + if (arg0 > state->count) { PlayerInitData* player; int i; int skip; int remaining; - skip = lbl_80473700.count; - player = lbl_80473700.players; + skip = state->count; + player = state->players; remaining = arg0 - current; i = 0; j = 0; @@ -2049,7 +2035,7 @@ void fn_80188550(int arg0) } } } - lbl_80473700.count = arg0; + state->count = arg0; } } @@ -2113,7 +2099,8 @@ void fn_80188738(HSD_JObj* arg0) jobjs[0] = (jobjs[1] == NULL) ? NULL : jobjs[1]->next; if ((val / 100) != 0) { - HSD_JObjReqAnimAll(jobjs[0], (f32) (val / 100)); + int temp = val; + HSD_JObjReqAnimAll(jobjs[0], (f32) (temp / 100)); } else { HSD_JObjReqAnimAll(jobjs[0], 10.0f); } @@ -2153,7 +2140,8 @@ void fn_80188910(HSD_JObj* arg0) jobjs[0] = (jobjs[1] == NULL) ? NULL : jobjs[1]->next; if ((val / 100) != 0) { - HSD_JObjReqAnimAll(jobjs[0], (f32) (val / 100)); + int temp = val; + HSD_JObjReqAnimAll(jobjs[0], (f32) (temp / 100)); } else { HSD_JObjReqAnimAll(jobjs[0], 10.0f); } @@ -2182,10 +2170,20 @@ static int fn_801884F8_noinline_2(void) void fn_80188B3C(HSD_JObj* arg0) { HSD_JObj* jobjs[3]; + TrainingModeState* state = &lbl_80473700; int i; int val; - if (fn_801884F8_inline() > 999) { + val = pl_80041300(0); + if (val != 0) { + state->result_cache[0] = val; + state->result_cache[1] = 1; + } + if (state->result_cache[1] != 0) { + val = state->result_cache[0]; + } + + if (val > 999) { val = 999; } else { val = fn_801884F8_noinline_2(); @@ -2251,9 +2249,11 @@ void fn_80188EE8(HSD_GObj* gobj) TrainingModeState* state = &lbl_80473700; CssSubStruct* sub = &state->css; HSD_JObj* jobj; + HSD_JObj* cursor_jobj; HSD_Text* text; s32 val; s32* menu_values; + TrainingItemEntry* item_table; PAD_STACK(8); @@ -2277,9 +2277,9 @@ void fn_80188EE8(HSD_GObj* gobj) HSD_JObjReqAnimAll(sub->jobjs[1], (f32) (u32) sub->anim_frames[1]); HSD_JObjAnimAll(sub->jobjs[1]); - jobj = sub->jobjs[1]; sub->text->pos_x = - (12.0f * (9.798828f + HSD_JObjGetTranslationX(jobj))) + 50.0f; + (12.0f * (9.798828f + HSD_JObjGetTranslationX(jobj = sub->jobjs[1]))) + + 50.0f; sub->text->pos_y = 150.0f; fn_80188738(sub->jobjs[9]); @@ -2308,7 +2308,8 @@ void fn_80188EE8(HSD_GObj* gobj) if (lbLang_IsSettingUS() != 0 && val == 0x13) { HSD_SisLib_803A6368(text, 0x17); } else { - HSD_SisLib_803A6368(text, (s32) TrainingItemTable_GetTextId(val)); + item_table = TrainingItemTable_Get(); + HSD_SisLib_803A6368(text, (s32) item_table[val].text_id); } jobj = sub->jobjs[32]; @@ -2324,15 +2325,20 @@ void fn_80188EE8(HSD_GObj* gobj) HSD_JObjSetFlags(sub->jobjs[25], JOBJ_HIDDEN); val = state->css.menu_values[6]; - jobj = sub->jobjs[26]; + cursor_jobj = sub->jobjs[26]; if (val == 2 && state->mode == 3) { val = 3; } - HSD_JObjReqAnimAll(jobj, (f32) val); - HSD_JObjAnimAll(jobj); + HSD_JObjReqAnimAll(cursor_jobj, (f32) val); + HSD_JObjAnimAll(cursor_jobj); } #pragma dont_inline off +static inline u32 gm_801891F4_GetTickRate(void) +{ + return *(u32*) 0x800000F8 >> 2; +} + void fn_801891F4(void) { CssSubStruct* sub; @@ -2588,7 +2594,7 @@ void fn_801891F4(void) sub->anim_frames[22] = 0x14; lb_80019880(__cvt_dbl_usll( (f64) (0.016666668f / ((f32*) speeds.v)[sub->menu_values[0]] * - (f32) (*(u32*) 0x800000F8 >> 2)))); + (f32) gm_801891F4_GetTickRate()))); fn_80188550(sub->menu_values[2] + 1); @@ -2680,7 +2686,6 @@ s32 fn_80189B88(void) sub->menu_values[5] = 0; sub->menu_values[6] = 0; sub->menu_values[0] = 2; - return 0; } TrainingModeState* gm_80189CDC(StartMeleeData* arg0) @@ -2695,14 +2700,13 @@ TrainingModeState* gm_80189CDC(StartMeleeData* arg0) arg0->rules.x5_0 = 1; for (i = 0; i < 4; i++) { - state->css.saved_players[i] = arg0->players[i]; - state->players[i] = state->css.saved_players[i]; + state->players[i] = state->css.saved_players[i] = arg0->players[i]; } state->mode = (s32) (arg0->players[0].slot - 1); state->count = 1; - for (i = 0; i < 27; i++) { + for (i = 0; 0x1B > i; i++) { state->char_data[i] = 0; } } diff --git a/src/melee/gm/gm_19EF.c b/src/melee/gm/gm_19EF.c index 7fdea344a4..4a7cf46421 100644 --- a/src/melee/gm/gm_19EF.c +++ b/src/melee/gm/gm_19EF.c @@ -180,6 +180,18 @@ static void fn_8019F1D0(void) HSD_SisLib_803A6B98(lbl_80479A98.x24, 240.0f, 176.0f, sp8); } +static inline void AnimMObj(HSD_MObj* mobj, f32 frame) +{ + HSD_MObjReqAnim(mobj, frame); + HSD_MObjAnim(mobj); +} + +static inline void AnimJObj(HSD_JObj* jobj, f32 frame) +{ + HSD_JObjReqAnimAll(jobj, frame); + HSD_JObjAnimAll(jobj); +} + static void fn_8019F2D4(u32 arg0) { if (lbl_804D66C8.x4 == 0xA) { @@ -189,46 +201,26 @@ static void fn_8019F2D4(u32 arg0) gm_80167858((s8) lbl_80479A98.x15, lbl_80479A98.x16, 0xD, 0x14); } if ((u8) lbl_80479A98.x0 == 0) { - HSD_JObj* jobj; - HSD_MObj* mobj; - if (lbl_804D66C8.x4 < 0x50) { lbl_804D66C8.x4++; } else { lbl_80479A98.x0 = 1; } lbl_804D66C0.x4 = lbl_804D66C8.x4; - jobj = lbl_804D66C8.x0; - HSD_JObjReqAnimAll(jobj, (f32) lbl_804D66C8.x4); - HSD_JObjAnimAll(jobj); - jobj = lbl_804D66C0.x0; - HSD_JObjReqAnimAll(jobj, (f32) lbl_804D66C0.x4); - HSD_JObjAnimAll(jobj); - mobj = lbl_804D66C8.x0->u.dobj->mobj; - HSD_MObjReqAnim(mobj, 0.0f); - HSD_MObjAnim(mobj); - mobj = lbl_804D66C0.x0->u.dobj->mobj; - HSD_MObjReqAnim(mobj, 1.0f); - HSD_MObjAnim(mobj); + AnimJObj(lbl_804D66C8.x0, (f32) lbl_804D66C8.x4); + AnimJObj(lbl_804D66C0.x0, (f32) lbl_804D66C0.x4); + AnimMObj(lbl_804D66C8.x0->u.dobj->mobj, 0.0f); + AnimMObj(lbl_804D66C0.x0->u.dobj->mobj, 1.0f); return; } else if ((u8) lbl_80479A98.x0 == 1) { HSD_JObj* jobj; - HSD_MObj* mobj; if ((u8) lbl_80479A98.x14 != 0) { - mobj = lbl_804D66C8.x0->u.dobj->mobj; - HSD_MObjReqAnim(mobj, 0.0f); - HSD_MObjAnim(mobj); - mobj = lbl_804D66C0.x0->u.dobj->mobj; - HSD_MObjReqAnim(mobj, 1.0f); - HSD_MObjAnim(mobj); + AnimMObj(lbl_804D66C8.x0->u.dobj->mobj, 0.0f); + AnimMObj(lbl_804D66C0.x0->u.dobj->mobj, 1.0f); } else { - mobj = lbl_804D66C8.x0->u.dobj->mobj; - HSD_MObjReqAnim(mobj, 1.0f); - HSD_MObjAnim(mobj); - mobj = lbl_804D66C0.x0->u.dobj->mobj; - HSD_MObjReqAnim(mobj, 0.0f); - HSD_MObjAnim(mobj); + AnimMObj(lbl_804D66C8.x0->u.dobj->mobj, 1.0f); + AnimMObj(lbl_804D66C0.x0->u.dobj->mobj, 0.0f); } if (arg0 & 0x1100) { if ((u8) lbl_80479A98.x14 != 0) { @@ -264,15 +256,8 @@ static void fn_8019F2D4(u32 arg0) return; } } else if ((u8) lbl_80479A98.x0 == 8) { - HSD_JObj* jobj; - HSD_MObj* mobj; - - jobj = lbl_804D66C0.x0; - HSD_JObjReqAnimAll(jobj, (f32) lbl_804D66C8.x4); - HSD_JObjAnimAll(jobj); - jobj = lbl_804D66C8.x0; - HSD_JObjReqAnimAll(jobj, (f32) lbl_804D66C8.x4); - HSD_JObjAnimAll(jobj); + AnimJObj(lbl_804D66C0.x0, (f32) lbl_804D66C8.x4); + AnimJObj(lbl_804D66C8.x0, (f32) lbl_804D66C8.x4); if (lbl_804D66C8.x4 < lbl_804D66C0.x4) { lbl_804D66C8.x4++; } else if ((u8) lbl_80479A98.x14 != 0) { @@ -282,14 +267,10 @@ static void fn_8019F2D4(u32 arg0) lbl_80479A98.x0 = 0xA; } if ((u8) lbl_80479A98.x14 != 0) { - mobj = lbl_804D66C0.x0->u.dobj->mobj; - HSD_MObjReqAnim(mobj, 2.0f); - HSD_MObjAnim(mobj); + AnimMObj(lbl_804D66C0.x0->u.dobj->mobj, 2.0f); return; } - mobj = lbl_804D66C8.x0->u.dobj->mobj; - HSD_MObjReqAnim(mobj, 2.0f); - HSD_MObjAnim(mobj); + AnimMObj(lbl_804D66C8.x0->u.dobj->mobj, 2.0f); } } @@ -380,6 +361,25 @@ static inline s32 fn_8019F9C4_GetCharIdx(CharacterKind arg0) } } +static inline void fn_8019F9C4_LoadArchives(CharacterKind arg0) +{ + lbl_804D6698 = lbArchive_80016DBC("GmGover.dat", &lbl_804D669C, + "ScGamRegGover_scene_data", 0); + lbArchive_80016DBC("GmGoCoin.dat", &lbl_804D66A0, + "ScGamRegGover_scene_data", 0); + Toy_803124BC(); + Toy_803102D0(); + { + u8 game_mode = gm_801A4310(); + char* model_name = gm_80160564(arg0, game_mode); + char* scene_name = gm_801604DC(arg0, game_mode); + lbArchive_LoadSymbols(scene_name, &lbl_804D66AC, model_name, 0); + lbArchive_LoadSymbols("GmGoAnim.dat", &lbl_804D66A4, + "ScGamRegGover_scene_data", 0); + lbArchive_LoadSymbols("GmRgStnd.dat", &lbl_804D66A8, "standScene", 0); + } +} + void fn_8019F9C4(u32 arg0) { HSD_CObj* cobj; @@ -399,21 +399,7 @@ void fn_8019F9C4(u32 arg0) char_idx = fn_8019F9C4_GetCharIdx(arg0); arg0 = (char_idx == -1) ? 8 : arg0; fn_80168F7C(); - lbl_804D6698 = lbArchive_80016DBC("GmGover.dat", &lbl_804D669C, - "ScGamRegGover_scene_data", 0); - lbArchive_80016DBC("GmGoCoin.dat", &lbl_804D66A0, - "ScGamRegGover_scene_data", 0); - Toy_803124BC(); - Toy_803102D0(); - { - u8 game_mode = gm_801A4310(); - char* model_name = gm_80160564(arg0, game_mode); - char* scene_name = gm_801604DC(arg0, game_mode); - lbArchive_LoadSymbols(scene_name, &lbl_804D66AC, model_name, 0); - lbArchive_LoadSymbols("GmGoAnim.dat", &lbl_804D66A4, - "ScGamRegGover_scene_data", 0); - lbArchive_LoadSymbols("GmRgStnd.dat", &lbl_804D66A8, "standScene", 0); - } + fn_8019F9C4_LoadArchives(arg0); cobj = HSD_CObjLoadDesc(lbl_804D669C->cameras->desc); cam_gobj = GObj_Create(0x13, 0x14, 0); HSD_GObjObject_80390A70(cam_gobj, HSD_GObj_804D784B, cobj); diff --git a/src/melee/gm/gm_1A7A.c b/src/melee/gm/gm_1A7A.c index dbde87d41f..4ce0776e26 100644 --- a/src/melee/gm/gm_1A7A.c +++ b/src/melee/gm/gm_1A7A.c @@ -54,9 +54,8 @@ void gm_801A7B00(void) HSD_CObj* cobj; HSD_LObj* lobj; HSD_GObj* gobj; - HSD_GObj* cam_gobj; HSD_JObj* jobj; - HSD_JObj* child; + HSD_JObj* char_jobj; HSD_JObj* target; s32 char_idx; f32 val; @@ -70,16 +69,16 @@ void gm_801A7B00(void) GObj_SetupGXLink(gobj, HSD_GObj_LObjCallback, 0, 0); // Camera GObj - cam_gobj = GObj_Create(0x13, 0x14, 0); + gobj = GObj_Create(0x13, 0x14, 0); cobj = lb_80013B14((HSD_CameraDescPerspective*) gm_804D67A8->cameras[0].desc); - HSD_GObjObject_80390A70(cam_gobj, HSD_GObj_804D784B, cobj); - GObj_SetupGXLinkMax(cam_gobj, HSD_GObj_803910D8, 8); - cam_gobj->gxlink_prios = 0x801; + HSD_GObjObject_80390A70(gobj, HSD_GObj_804D784B, cobj); + GObj_SetupGXLinkMax(gobj, HSD_GObj_803910D8, 8); + gobj->gxlink_prios = 0x801; HSD_CObjAddAnim(cobj, gm_804D67A8->cameras[0].anims[0]); HSD_CObjReqAnim(cobj, 0.0f); HSD_CObjAnim(cobj); - HSD_GObj_SetupProc(cam_gobj, fn_801A7A8C, 0); + HSD_GObj_SetupProc(gobj, fn_801A7A8C, 0); // Main JObj GObj gobj = GObj_Create(0xE, 0xF, 0); @@ -97,29 +96,29 @@ void gm_801A7B00(void) // Character display GObj gobj = GObj_Create(0xE, 0xF, 0); gm_804D67B4 = gobj; - jobj = HSD_JObjLoadJoint(gm_804D67AC->models[0]->joint); - HSD_GObjObject_80390A70(gobj, HSD_GObj_804D7849, jobj); + char_jobj = HSD_JObjLoadJoint(gm_804D67AC->models[0]->joint); + HSD_GObjObject_80390A70(gobj, HSD_GObj_804D7849, char_jobj); GObj_SetupGXLink(gobj, HSD_GObj_JObjCallback, 0xB, 0); char_idx = gm_801A659C(gm_801BEFB0()); - child = jobj == NULL ? NULL : jobj->child; + char_jobj = char_jobj == NULL ? NULL : char_jobj->child; val = -Toy_803060BC(char_idx, 0); - HSD_JObjSetTranslateXWithMtxDirty(child, val); + HSD_JObjSetTranslateXWithMtxDirty(char_jobj, val); val = -Toy_803060BC(char_idx, 1); - HSD_JObjSetTranslateYWithMtxDirty(child, val); + HSD_JObjSetTranslateYWithMtxDirty(char_jobj, val); val = -Toy_803060BC(char_idx, 2); - HSD_JObjSetTranslateZWithMtxDirty(child, val); + HSD_JObjSetTranslateZWithMtxDirty(char_jobj, val); val = -(0.017453292f * Toy_803060BC(char_idx, 5)); - HSD_JObjSetRotationYWithMtxDirty(child, val); + HSD_JObjSetRotationYWithMtxDirty(char_jobj, val); scale = 1.0f / Toy_803060BC(char_idx, 3); val = Toy_803060BC(char_idx, 4); scale = val * scale; - HSD_JObjSetScaleXWithMtxDirty(child, scale); - HSD_JObjSetScaleYWithMtxDirty(child, scale); - HSD_JObjSetScaleZWithMtxDirty(child, scale); + HSD_JObjSetScaleXWithMtxDirty(char_jobj, scale); + HSD_JObjSetScaleYWithMtxDirty(char_jobj, scale); + HSD_JObjSetScaleZWithMtxDirty(char_jobj, scale); HSD_GObj_SetupProc(gobj, fn_801A7A68, 0x17); diff --git a/src/melee/gm/gm_1A9B.c b/src/melee/gm/gm_1A9B.c new file mode 100644 index 0000000000..45dcfcc11b --- /dev/null +++ b/src/melee/gm/gm_1A9B.c @@ -0,0 +1,178 @@ +/// @file gm_1A9B.c +/// Game-over "Regend" ending THP playback scene (OnEnter/OnFrame pair). +/// +/// This TU is split from gmregenddisp.c: the retail object anchors the THP +/// table loads in gm_801A9B30_OnEnter at the first table literal +/// (gm_803DB640, displacements 0x278/0x5B4/0x8D0), i.e. at this TU's own +/// .data+0. MWCC 1.2.5n always places its merged-data anchor (..data.N) at +/// the object's .data start, so these tables cannot share a TU with the +/// string literals at 0x803DB458-0x803DB640 (which belong to gmregenddisp.c, +/// whose functions anchor at 0x803DB458). Splitting here reproduces the +/// retail anchor exactly; keeping the tables in gmregenddisp.c compiles the +/// same instructions with displacements 0x460/0x79C/0xAB8 instead. +#include "gm_1A7A.h" + +#include "gm/forward.h" + +#include "dolphin/pad.h" + +#include "gm/gm_1A36.h" +#include "gm/gm_1A3F.h" +#include "gm/gm_1BA8.h" +#include "gm/gmregclear.h" +#include "gm/gmregtyfall.h" +#include "lb/lbaudio_ax.h" +#include "lb/lbbgflash.h" +#include "lb/lbmthp.h" + +#include +#include +#include +#include + +static u8 gmRegend_InputDelayTimer; +static u8 gmRegend_ExitTimer; + +static char* gmRegend_SimpleThpFiles[] = { + "GmRegendSimpleCaptain.thp", "GmRegendSimpleDonkey.thp", + "GmRegendSimpleFox.thp", "GmRegendSimpleGamewatch.thp", + "GmRegendSimpleKirby.thp", "GmRegendSimpleKoopa.thp", + "GmRegendSimpleLink.thp", "GmRegendSimpleLuigi.thp", + "GmRegendSimpleMario.thp", "GmRegendSimpleMarth.thp", + "GmRegendSimpleMewtwo.thp", "GmRegendSimpleNess.thp", + "GmRegendSimplePeach.thp", "GmRegendSimplePikachu.thp", + "GmRegendSimplePoponana.thp", "GmRegendSimplePurin.thp", + "GmRegendSimpleSamus.thp", "GmRegendSimpleYoshi.thp", + "GmRegendSimpleZeldaseak.thp", "GmRegendSimpleZeldaseak.thp", + "GmRegendSimpleFalco.thp", "GmRegendSimpleClink.thp", + "GmRegendSimpleDrmario.thp", "GmRegendSimpleRoy.thp", + "GmRegendSimplePichu.thp", "GmRegendSimpleGanon.thp", +}; + +static char* gmRegend_AdventureThpFiles[] = { + "GmRegendAdventureCaptain.thp", "GmRegendAdventureDonkey.thp", + "GmRegendAdventureFox.thp", "GmRegendAdventureGamewatch.thp", + "GmRegendAdventureKirby.thp", "GmRegendAdventureKoopa.thp", + "GmRegendAdventureLink.thp", "GmRegendAdventureLuigi.thp", + "GmRegendAdventureMario.thp", "GmRegendAdventureMarth.thp", + "GmRegendAdventureMewtwo.thp", "GmRegendAdventureNess.thp", + "GmRegendAdventurePeach.thp", "GmRegendAdventurePikachu.thp", + "GmRegendAdventurePoponana.thp", "GmRegendAdventurePurin.thp", + "GmRegendAdventureSamus.thp", "GmRegendAdventureYoshi.thp", + "GmRegendAdventureZeldaseak.thp", "GmRegendAdventureZeldaseak.thp", + "GmRegendAdventureFalco.thp", "GmRegendAdventureClink.thp", + "GmRegendAdventureDrmario.thp", "GmRegendAdventureRoy.thp", + "GmRegendAdventurePichu.thp", "GmRegendAdventureGanon.thp", +}; + +static char* gmRegend_AllstarThpFiles[] = { + "GmRegendAllstarCaptain.thp", "GmRegendAllstarDonkey.thp", + "GmRegendAllstarFox.thp", "GmRegendAllstarGamewatch.thp", + "GmRegendAllstarKirby.thp", "GmRegendAllstarKoopa.thp", + "GmRegendAllstarLink.thp", "GmRegendAllstarLuigi.thp", + "GmRegendAllstarMario.thp", "GmRegendAllstarMarth.thp", + "GmRegendAllstarMewtwo.thp", "GmRegendAllstarNess.thp", + "GmRegendAllstarPeach.thp", "GmRegendAllstarPikachu.thp", + "GmRegendAllstarPoponana.thp", "GmRegendAllstarPurin.thp", + "GmRegendAllstarSamus.thp", "GmRegendAllstarYoshi.thp", + "GmRegendAllstarZeldaseak.thp", "GmRegendAllstarZeldaseak.thp", + "GmRegendAllstarFalco.thp", "GmRegendAllstarClink.thp", + "GmRegendAllstarDrmario.thp", "GmRegendAllstarRoy.thp", + "GmRegendAllstarPichu.thp", "GmRegendAllstarGanon.thp", +}; + +void gm_801A9B30_OnEnter(UNK_T unused) +{ + struct { + int x0; + int x4; + int x8; + int xC; + float x10; + float x14; + u8 pad[0x40 - 0x18]; + u32 x40; + }* thp_disp; + s32 ckind; + HSD_GObj* gobj; + HSD_GObj* sobj_gobj; + const char* thpfile; + s32 level; + int gover_kind; + + gmRegend_InputDelayTimer = 0x1E; + gmRegend_ExitTimer = 0; + sobj_gobj = GObj_Create(0x13, 0x14, 0); + HSD_SObjLib_803A55DC(sobj_gobj, 0x280, 0x1E0, 8); + sobj_gobj->gxlink_prios = 0x800; + lbAudioAx_80026F2C(0x12); + lbAudioAx_8002702C(2, 0x10); + lbAudioAx_80027168(); + lbAudioAx_80027648(); + lbBgFlash_800209F4(); + gobj = GObj_Create(0xE, 0xF, 0); + HSD_GObjObject_80390A70(gobj, HSD_SObjLib_804D7960, NULL); + GObj_SetupGXLink(gobj, lbMthp8001F928, 0xB, 0); + ckind = gm_801BEFB0(); + gover_kind = gm_801A4310(); + if (gover_kind == GM_DEBUG_GOVER) { + gover_kind = gm_801BF050(); + } + switch (gover_kind) { + case GM_CLASSIC_GOVER: + thpfile = gmRegend_SimpleThpFiles[ckind]; + break; + case GM_ADVENTURE_GOVER: + thpfile = gmRegend_AdventureThpFiles[ckind]; + break; + default: + thpfile = gmRegend_AllstarThpFiles[ckind]; + break; + } + lbMthp8001FAA0(thpfile, 0x230, 0x1A0); + thp_disp = lbMthp8001F890(gobj); + thp_disp->x10 = 320.0F; + thp_disp->x14 = 240.0F; + thp_disp->x40 |= 2; + switch (gm_801A4310()) { + case GM_CLASSIC_GOVER: + level = gm_8017DFF4(1); + break; + case GM_ADVENTURE_GOVER: + level = gm_8017DFF4(0); + break; + default: + level = gm_8017DFF4(2); + break; + } + if (level == 4) { + lbAudioAx_800237A8(0x9C45, 0x7F, 0x40); + } else { + lbAudioAx_800237A8(0x9C41, 0x7F, 0x40); + } +} + +void gm_801A9D0C_OnFrame(void) +{ + if (gmRegend_InputDelayTimer != 0) { + gmRegend_InputDelayTimer--; + } else if (gmRegend_ExitTimer != 0) { + gmRegend_ExitTimer--; + if (gmRegend_ExitTimer == 0) { + if (gm_801A4310() == GM_DEBUG_GOVER) { + gm_801A6630(6); + } else { + gm_801A6630(1); + } + } + } else { + if (gm_GetButtonsTriggered(gm_801BF010()) & + (PAD_BUTTON_A | PAD_BUTTON_START)) + { + lbBgFlash_8002063C(0x3C); + gmRegend_ExitTimer = 0x3C; + lbAudioAx_80023694(); + lbAudioAx_80024030(1); + } + } +} diff --git a/src/melee/gm/gm_1B14.c b/src/melee/gm/gm_1B14.c index ace7594bd6..932d45404b 100644 --- a/src/melee/gm/gm_1B14.c +++ b/src/melee/gm/gm_1B14.c @@ -470,16 +470,17 @@ void gm_801B1834(GameScene* arg0) void gm_801B18D4(GameScene* arg0) { StartMeleeData* smd; + StartMeleeData* src = &gm_804876D8; s32 i; smd = gm_801A427C(arg0); for (i = 0; i < 4; i++) { - smd->players[i] = gm_804876D8.players[i]; + smd->players[i] = src->players[i]; } /// @todo :: figure out how to call this not inlined - gm_801B0474(smd, &gm_80487810.match_end); + gm_801B0474(smd, &((MatchExitInfo*) (src + 1))->match_end); } #pragma dont_inline reset @@ -553,7 +554,6 @@ void gm_801B1C24(GameScene* arg0) VsModeData* vs = &gmMainLib_804D3EE0->unk_D10; CSSData* css = gm_801A4284(arg0); s32 i; - u64 mask; struct GameCache* cache; s32 j; PAD_STACK(0x10); @@ -586,11 +586,11 @@ void gm_801B1C24(GameScene* arg0) vs->data.players[2].slot = 0; vs->data.players[3].slot = 0; } else { - j = 1; + s32 k = 1; for (i = 0; i < 4; i++) { if (gm_804D68C0 != i) { - vs->data.players[j].slot = i + 1; - j++; + vs->data.players[k].slot = i + 1; + k++; } } } @@ -600,13 +600,17 @@ void gm_801B1C24(GameScene* arg0) cache->entries[3].char_id = (s8) vs->data.players[3].c_kind; cache->entries[3].color = vs->data.players[3].color; lbDvd_80018254(); - mask = 0; - for (i = 0; i < 4; i++) { - mask |= lbAudioAx_80026E84(vs->data.players[i].c_kind); + { + u64 mask; + s32 k; + mask = 0; + for (k = 0; k < 4; k++) { + mask |= lbAudioAx_80026E84(vs->data.players[k].c_kind); + } + lbAudioAx_80026F2C(0x14); + lbAudioAx_8002702C(4, mask); + lbAudioAx_80027168(); } - lbAudioAx_80026F2C(0x14); - lbAudioAx_8002702C(4, mask); - lbAudioAx_80027168(); } void gm_801B1EB8(GameScene* arg0) diff --git a/src/melee/gm/gm_1BA8.c b/src/melee/gm/gm_1BA8.c index 049d63d646..98b3c78381 100644 --- a/src/melee/gm/gm_1BA8.c +++ b/src/melee/gm/gm_1BA8.c @@ -2,7 +2,11 @@ #include "gm_1BA8.static.h" +#define gm_801732D8 gm_801732D8_wide +#define gm_8017335C gm_8017335C_wide #include "gm_unsplit.h" +#undef gm_801732D8 +#undef gm_8017335C #include "vi/vi1201v1.h" @@ -15,6 +19,8 @@ #include #include #include +#include +#include #include #include #include @@ -81,6 +87,9 @@ GameScene gm_803DF618_Scenes[] = { extern u8 gm_804D68F8; extern u8 gm_804D68F9; +u8 gm_801732D8(u8); +u16 gm_8017335C(void); + void gm_801BA8FC(void) { lbArchive_LoadSymbols("GmEvent.dat", &gm_804D6900, @@ -219,29 +228,28 @@ s32 gm_801BAC9C(GameScene* arg0, s32 arg1) StartMeleeData* data = gm_801A427C(arg0); s32 i; s32 found; - s32 k; s32 count = 0; + s32 k; struct gm_event_char_list* src = (struct gm_event_char_list*) (*gm_804D6900)[ev->unk_535]->x4; PAD_STACK(8); for (i = 0; i < 0x21; i++) { - u8 c = src->c_kind[i]; + u8* ptr = &src->c_kind[i]; + u8 c = *ptr; if ((s32) c == 0x21) { break; } - { - found = 0; - for (k = 0; k < arg1; k++) { - if (data->players[k].c_kind == (s8) c) { - found++; - } - } - if (found == 0) { - chars[count] = c; - count++; + found = 0; + for (k = 0; k < arg1; k++) { + if (data->players[k].c_kind == (s8) *ptr) { + found++; } } + if (found == 0) { + chars[count] = c; + count++; + } } return chars[HSD_Randi(count)]; } @@ -276,8 +284,7 @@ struct gm_evinit { /* 0x06 */ u16 unk6; /* 0x08 */ u32 unk8; /* 0x0C */ u8 padC[4]; - /* 0x10 */ u32 x10; - /* 0x14 */ s32 unk14; + /* 0x10 */ u64 x10; /* 0x18 */ s32 x18; /* 0x1C */ f32 x1C; /* 0x20 */ f32 unk20; @@ -336,21 +343,18 @@ void gm_801BAD70(GameScene* arg0) StartMeleeData* md = gm_801A427C(arg0); u8* r3b = (u8*) md; u8 level = ev->unk_535; - gm_803DF94C_t** event_info = gm_803DF94C; - struct gm_804D6900_t** levels; - struct gm_804D6900_t** lvlpp; - struct gm_evlevel* level_info; s32 player_idx; s32 player_init_off; - s32 spawn_off; - PAD_STACK(0x20); + struct gm_804D6900_t** levels; + gm_803DF94C_t** event_info = gm_803DF94C; + struct gm_804D6900_t** lvlpp; + PAD_STACK(0x18); lbArchive_LoadSymbols("GmEvent.dat", &gm_804D6900, "sqEventInitDataLevelTbl", 0); levels = gm_804D6900[0]; gm_80167A64(&md->rules); lvlpp = &levels[level]; - level_info = (struct gm_evlevel*) *lvlpp; md->rules.x0_0 = (*lvlpp)->x8->x0_0; md->rules.x0_3 = (*lvlpp)->x8->x0_3; md->rules.x0_6 = (*lvlpp)->x8->x0_6; @@ -391,12 +395,7 @@ void gm_801BAD70(GameScene* arg0) md->rules.x10 = ((struct gm_evinit*) (*lvlpp)->x8)->unk8; md->rules.x14 = 0; md->rules.x18 = 0; - { - struct gm_evinit* init = (struct gm_evinit*) (*lvlpp)->x8; - u32 x10 = init->x10; - *(s32*) (r3b + 0x24) = init->unk14; - *(u32*) (r3b + 0x20) = x10; - } + md->rules.x20 = ((struct gm_evinit*) (*lvlpp)->x8)->x10; md->rules.x28 = ((struct gm_evinit*) (*lvlpp)->x8)->x18; md->rules.x30 = ((struct gm_evinit*) (*lvlpp)->x8)->x1C; md->rules.x34 = ((struct gm_evinit*) (*lvlpp)->x8)->unk20; @@ -410,11 +409,11 @@ void gm_801BAD70(GameScene* arg0) if (((struct gm_evinit*) (*lvlpp)->x8)->unk24 != 1.0f) { ev->x1C = ((struct gm_evinit*) (*lvlpp)->x8)->unk24; } - if (level_info->kind == 2) { + if (((struct gm_evlevel*) *lvlpp)->kind == 2) { struct gm_evstage_list* stage_list; u16 stage; ev->xB_4 = 1; - stage_list = level_info->x10; + stage_list = ((struct gm_evlevel*) *lvlpp)->x10; stage = stage_list->stage[ev->x20]; md->rules.xE = stage; ev->x48 = (InternalStageId) stage; @@ -429,22 +428,22 @@ void gm_801BAD70(GameScene* arg0) player_idx = 0; player_init_off = 0; r3b[0x85] = 3; - spawn_off = 0; r3b[0xA9] = 3; r3b[0xCD] = 3; r3b[0xF1] = 3; r3b[0x115] = 3; - while (player_idx < (s32) ((level_info->flags >> 5) & 7)) { - gm_801BAB40_src* init = level_info->player_init[player_idx]; - while (init == NULL) { + while (player_idx < + (s32) ((((struct gm_evlevel*) *lvlpp)->flags >> 5) & 7)) + { + while (((struct gm_evlevel*) *lvlpp)->player_init[player_idx] == NULL) + { player_idx += 1; player_init_off += 0x24; - spawn_off += 4; - init = level_info->player_init[player_idx]; } - gm_801BAB40((PlayerInitData*) (r3b + player_init_off + 0x60), - (int) init); + gm_801BAB40( + (PlayerInitData*) (r3b + player_init_off + 0x60), + (int) ((struct gm_evlevel*) *lvlpp)->player_init[player_idx]); if (player_idx == 0) { gm_801B05F4((PlayerInitData*) (r3b + 0x60), ev->x6); ev->x7 = r3b[0x69]; @@ -463,14 +462,18 @@ void gm_801BAD70(GameScene* arg0) ev->x1 = c; ev->x50[0] = c; } - r3b[0x6C] = (r3b[0x6C] & ~0x80) | - ((gm_801677F8(ev->x6, r3b[0x6A]) << 7) & 0x80); + md->players[0].xC_b0 = gm_801677F8(ev->x6, r3b[0x6A]); } else { - if (init->team == 0) { + if (((struct gm_evlevel*) *lvlpp)->player_init[player_idx]->team == + 0) + { r3b[player_init_off + 0x69] = r3b[0x69]; ((PlayerInitData*) (r3b + player_init_off + 0x60))->xD_b1 = 1; } - if ((s8) init->c_kind == 0x21) { + if ((s8) ((struct gm_evlevel*) *lvlpp) + ->player_init[player_idx] + ->c_kind == 0x21) + { s8* t = &ev->x8 + player_idx - 1; s8 v = *t; if (v == -1) { @@ -512,16 +515,15 @@ void gm_801BAD70(GameScene* arg0) } player_idx += 1; player_init_off += 0x24; - spawn_off += 4; } - if (level_info->kind == 2) { + if (((struct gm_evlevel*) *lvlpp)->kind == 2) { if (ev->x20 > 0) { r3b[0x62] = (s8) ev->x24; - *(s16*) (r3b + 0x70) = (s16) ev->x28; + *(u16*) (r3b + 0x70) = ev->x28; ((PlayerInitData*) (r3b + 0x60))->xC_b1 = 0; { - u8 c = ev->x38; + s8 c = ev->x38; if (c != 0x21) { r3b[0x60] = c; ev->x0 = c; @@ -530,7 +532,8 @@ void gm_801BAD70(GameScene* arg0) } } { - struct gm_evspawn_table* spawn_table = level_info->x10; + struct gm_evspawn_table* spawn_table = + ((struct gm_evlevel*) *lvlpp)->x10; gm_801BAB40((PlayerInitData*) (r3b + 0x84), (int) spawn_table->entries[ev->x20]); } @@ -580,43 +583,48 @@ void gm_801BAD70(GameScene* arg0) md->players[1].xD_b2 = 1; md->players[2].xD_b2 = 1; } - if (level_info->kind == 1) { - struct gm_evbonus* bonus = level_info->xC; - int var_r9; + if (((struct gm_evlevel*) *lvlpp)->kind == 1) { + int x5_flag; s8 k; s32 sp8; ev->xB_3 = 1; - if (bonus->x5 == 1) { - var_r9 = 1; - if ((s8) ev->x0 == bonus->c_kind) { - u8 c; - if ((u8) ev->x1 == (c = bonus->color)) { - if (c <= 2) { - c = c + 1; - } else { - c = 0; + { + struct gm_evbonus* bonus = ((struct gm_evlevel*) *lvlpp)->xC; + if (bonus->x5 == 1) { + x5_flag = 1; + if ((s8) ev->x0 == bonus->c_kind) { + u8 c; + if ((u8) ev->x1 == (c = bonus->color)) { + if (c <= 2) { + c = c + 1; + } else { + c = 0; + } + ev->x50[1] = c; } - ev->x50[1] = c; } + } else { + x5_flag = 0; } - } else { - var_r9 = 0; - } - k = bonus->c_kind; - sp8 = (k == 4) ? bonus->x17 : 0; - gm_8016A22C(k, 0x21, 0x21, ev->x50[1], 0, 0, var_r9, 0, sp8, ev->x0, - ev->x1, bonus->x1, bonus->x2, bonus->x3, bonus->x4, 0, 1, - bonus->x8, bonus->xC); - gm_8016A414(bonus->x10); + } + { + struct gm_evbonus* bonus = ((struct gm_evlevel*) *lvlpp)->xC; + k = bonus->c_kind; + sp8 = (k == 4) ? bonus->x17 : 0; + gm_8016A22C(k, 0x21, 0x21, ev->x50[1], 0, 0, x5_flag, 0, sp8, + ev->x0, ev->x1, bonus->x1, bonus->x2, bonus->x3, + bonus->x4, 0, 1, bonus->x8, bonus->xC); + } + gm_8016A414(((struct gm_evlevel*) *lvlpp)->xC->x10); gm_8016A21C(&md->rules); - if ((bonus->flags >> 7) & 1) { + if ((((struct gm_evlevel*) *lvlpp)->xC->flags >> 7) & 1) { gm_8016A434(); } if (event_info[level]->x4 != NULL) { gm_8016A404((s32) event_info[level]->x4); } - if (bonus->x15 != 0) { - gm_8016A424((s8) bonus->x15); + if (((struct gm_evlevel*) *lvlpp)->xC->x15 != 0) { + gm_8016A424((s8) ((struct gm_evlevel*) *lvlpp)->xC->x15); } } { @@ -742,8 +750,8 @@ void gm_801BB758(GameScene* arg0) gmMainLib_8015CF84(); } if (ev->xB_1) { - int sid = gm_8017335C(); - if ((u16) sid != 0x148) { + u16 sid = gm_8017335C(); + if (sid != 0x148) { gm_80164504(sid); } } @@ -813,17 +821,14 @@ void gm_801BBA60_OnInit(void) s32 gm_801BBB64(void) { struct gm_804D6900_t** pp; - struct EventData* ev; - struct gm_804D6900_t** tbl; - s32 idx; + struct EventData* ev = &gmMainLib_804D3EE0->unk_530; + struct gm_804D6900_t** tbl = gm_804D6900[0]; + u8 idx = gmMainLib_804D3EE0->unk_530.unk_535; s8* player_init; void* event_entry; struct gm_804D6900_x4_t* x4; - s32 result; + int i; - ev = &gmMainLib_804D3EE0->unk_530; - tbl = gm_804D6900[0]; - idx = gmMainLib_804D3EE0->unk_530.unk_535; if (*tbl[idx]->x14 != 0x21) { ev->x44 = 0; } else { @@ -831,37 +836,15 @@ s32 gm_801BBB64(void) } pp = &tbl[idx]; ev->x48 = (InternalStageId) * (u16*) ((u8*) (*pp)->x8 + 6); - player_init = (*pp)->x14; - if (player_init != NULL) { - ev->x4C[0] = *(u8*) player_init; - ev->x50[0] = ((u8*) (*pp)->x14)[3]; - } else { - ev->x4C[0] = 0x21; - ev->x50[0] = 0; - } - player_init = (*pp)->x18; - if (player_init != NULL) { - ev->x4C[1] = *(u8*) player_init; - ev->x50[1] = ((u8*) (*pp)->x18)[3]; - } else { - ev->x4C[1] = 0x21; - ev->x50[1] = 0; - } - player_init = *(s8**) ((u8*) *pp + 0x1C); - if (player_init != NULL) { - ev->x4C[2] = *player_init; - ev->x50[2] = ((u8*) *(s8**) ((u8*) *pp + 0x1C))[3]; - } else { - ev->x4C[2] = 0x21; - ev->x50[2] = 0; - } - player_init = *(s8**) ((u8*) *pp + 0x20); - if (player_init != NULL) { - ev->x4C[3] = *player_init; - ev->x50[3] = ((u8*) *(s8**) ((u8*) *pp + 0x20))[3]; - } else { - ev->x4C[3] = 0x21; - ev->x50[3] = 0; + for (i = 0; i < 4; i++) { + player_init = (&(*pp)->x14)[i]; + if (player_init != NULL) { + ev->x4C[i] = *player_init; + ev->x50[i] = (&(*pp)->x14)[i][3]; + } else { + ev->x4C[i] = 0x21; + ev->x50[i] = 0; + } } if (*(u8*) *pp == 1) { ev->x4C[1] = (s8) (*pp)->xC->unk0[0]; @@ -870,7 +853,7 @@ s32 gm_801BBB64(void) } else { ev->x50[1] = 0xFF; } - if (((u8*) (*pp)->xC)[0x17] == 1) { + if ((s32) ((struct gm_evbonus*) (*pp)->xC)->x17 == 1) { ev->x45 = 1; } else { ev->x45 = 0; @@ -879,7 +862,6 @@ s32 gm_801BBB64(void) ev->x45 = 0; } - result = idx; switch (idx) { case 9: case 19: @@ -925,18 +907,16 @@ s32 gm_801BBB64(void) ev->x50[2] = ((u8*) event_entry)[3]; return (s32) event_entry; } - return result; + break; case 43: x4 = (*pp)->x4; event_entry = (void*) x4->x4; ev->x4C[2] = *(s8*) event_entry; event_entry = (void*) x4->x4; ev->x50[2] = ((u8*) event_entry)[3]; - result = (s32) event_entry; - /* fallthrough */ - default: - return result; + return (s32) event_entry; } + return idx; } void gm_801BBEA8_OnLoad(void) @@ -991,6 +971,28 @@ void fn_801BBFE8(void) gm_801BC00C(); } +typedef struct gmEventLevelData { + u8 count; + u8 pad_x1[0xF]; + gm_801BAB40_src* entries[1]; +} gmEventLevelData; + +static inline void gm_801BC00C_inline(gm_801BAB40_src* event_entry) +{ + u8 ckind = event_entry->c_kind; + u8 costume = event_entry->color; + struct EventData* ev2 = &gmMainLib_804D3EE0->unk_530; + + if ((s8) ev2->x0 == (s8) ckind && (u8) ev2->x1 == costume) { + if (costume <= 2) { + costume += 1; + } else { + costume = 0; + } + } + gm_8016A9E8(ckind, (s8) costume); +} + s32 gm_801BC00C(void) { struct gm_804D6900_t** event_levels; @@ -1004,7 +1006,7 @@ s32 gm_801BC00C(void) s32 i; s32 entry_offset; s8 chr; - PAD_STACK(0x40); + PAD_STACK(0x38); gmMainLib_804D3EE0->unk_530.xB_1 = 0; ev->x10 = 0; @@ -1082,100 +1084,28 @@ s32 gm_801BC00C(void) case 39: case 48: for (i = ev->x20, entry_offset = i * 4; - i < (s32) * (u8*) event_levels[idx]->x10; i++, entry_offset += 4) + i < ((gmEventLevelData*) event_levels[idx]->x10)->count; + entry_offset += 4, i++) { event_entry = *(void**) ((u8*) event_levels[idx]->x10 + entry_offset + 0x10); - ckind = *(u8*) event_entry; - (void) ckind; - costume = *((u8*) event_entry + 3); - { - struct EventData* ev2 = &gmMainLib_804D3EE0->unk_530; - if ((s8) ev2->x0 == (s8) ckind && (u8) ev2->x1 == costume) { - if (costume <= 2) { - costume += 1; - } else { - costume = 0; - } - } - } - gm_8016A9E8(ckind, (s8) costume); + gm_801BC00C_inline(event_entry); } break; case 35: if (ev->x20 == 0) { event_entry = ((void**) ((u8*) event_levels[idx]->x10 + 0x10))[0]; - ckind = *(u8*) event_entry; - costume = *((u8*) event_entry + 3); - { - struct EventData* ev2 = &gmMainLib_804D3EE0->unk_530; - if ((s8) ev2->x0 == (s8) ckind && (u8) ev2->x1 == costume) { - if (costume <= 2) { - costume += 1; - } else { - costume = 0; - } - } - } - gm_8016A9E8(ckind, (s8) costume); + gm_801BC00C_inline(event_entry); event_entry = ((void**) ((u8*) event_levels[idx]->x10 + 0x10))[2]; - ckind = *(u8*) event_entry; - costume = *((u8*) event_entry + 3); - { - struct EventData* ev2 = &gmMainLib_804D3EE0->unk_530; - if ((s8) ev2->x0 == (s8) ckind && (u8) ev2->x1 == costume) { - if (costume <= 2) { - costume += 1; - } else { - costume = 0; - } - } - } - gm_8016A9E8(ckind, (s8) costume); + gm_801BC00C_inline(event_entry); event_entry = ((void**) ((u8*) event_levels[idx]->x10 + 0x10))[3]; - ckind = *(u8*) event_entry; - costume = *((u8*) event_entry + 3); - { - struct EventData* ev2 = &gmMainLib_804D3EE0->unk_530; - if ((s8) ev2->x0 == (s8) ckind && (u8) ev2->x1 == costume) { - if (costume <= 2) { - costume += 1; - } else { - costume = 0; - } - } - } - gm_8016A9E8(ckind, (s8) costume); + gm_801BC00C_inline(event_entry); } if (ev->x20 <= 1) { event_entry = ((void**) ((u8*) event_levels[idx]->x10 + 0x10))[1]; - ckind = *(u8*) event_entry; - costume = *((u8*) event_entry + 3); - { - struct EventData* ev2 = &gmMainLib_804D3EE0->unk_530; - if ((s8) ev2->x0 == (s8) ckind && (u8) ev2->x1 == costume) { - if (costume <= 2) { - costume += 1; - } else { - costume = 0; - } - } - } - gm_8016A9E8(ckind, (s8) costume); + gm_801BC00C_inline(event_entry); event_entry = ((void**) ((u8*) event_levels[idx]->x10 + 0x10))[4]; - ckind = *(u8*) event_entry; - costume = *((u8*) event_entry + 3); - { - struct EventData* ev2 = &gmMainLib_804D3EE0->unk_530; - if ((s8) ev2->x0 == (s8) ckind && (u8) ev2->x1 == costume) { - if (costume <= 2) { - costume += 1; - } else { - costume = 0; - } - } - } - gm_8016A9E8(ckind, (s8) costume); + gm_801BC00C_inline(event_entry); } break; } @@ -1979,6 +1909,16 @@ void gm_801BCAF0(HSD_GObj* gobj) } } +/// Accessor for the event data block inside gmMainLib_804D3EE0. +/// gm_801BCC9C needs this inline (instead of taking the address directly +/// in its trailing block) so the compiler rematerializes the pointer in +/// the order the reference object shows; with the direct expression the +/// tail of the function schedules one load early and stays at 99.65%. +static inline struct EventData* gm_GetEventData(void) +{ + return &gmMainLib_804D3EE0->unk_530; +} + void gm_801BCC9C(HSD_GObj* arg0) { struct gm_804D6900_t** temp_r29 = gm_804D6900[0]; @@ -1992,7 +1932,7 @@ void gm_801BCC9C(HSD_GObj* arg0) u8 costume; lbl_8046B6A0_t* mi; s32 var_r0; - PAD_STACK(0x40); + PAD_STACK(0x38); if (gmMainLib_804D3EE0->unk_530.xB_2) { ev->x10 -= 1; @@ -2004,9 +1944,9 @@ void gm_801BCC9C(HSD_GObj* arg0) } if (Player_GetStocks(1) <= 0) { entry = &temp_r29[idx]; - ev2 = &gmMainLib_804D3EE0->unk_530; inner = (u8*) (*entry)->x10; cd = ((struct gm_evspawn**) (inner + 0x10))[ev->x20]; + ev2 = &gmMainLib_804D3EE0->unk_530; costume = cd->unk3; if ((s8) ev2->x0 == cd->unk0 && (u8) ev2->x1 == costume) { if (costume <= 2) { @@ -2046,9 +1986,9 @@ void gm_801BCC9C(HSD_GObj* arg0) return; } { - struct EventData* temp_r31 = &gmMainLib_804D3EE0->unk_530; + struct EventData* ev3 = gm_GetEventData(); mi = gm_8016AE38(); - if (temp_r31->xB_0) { + if (ev3->xB_0) { var_r0 = 0; } else if (((*(u8*) &mi->x24C8 >> 1U) & 1) && gm_8016AEEC() == 0 && gm_8016AEFC() == 0x3B) @@ -2695,9 +2635,9 @@ void gm_801BDE94(HSD_GObj* arg0) break; case 2: if (Player_GetStocks(3) <= 0) { - struct EventData* ev2 = &gmMainLib_804D3EE0->unk_530; struct gm_evspawn* sp = ((struct gm_evx10*) tbl[level]->x10)->unk1C; + struct EventData* ev2 = &gmMainLib_804D3EE0->unk_530; u8 color = sp->unk3; if ((s8) ev2->x0 == sp->unk0 && (u8) ev2->x1 == color) { if (color <= 2) { @@ -2735,9 +2675,9 @@ void gm_801BDE94(HSD_GObj* arg0) break; case 1: if (Player_GetStocks(2) <= 0) { - struct EventData* ev2 = &gmMainLib_804D3EE0->unk_530; struct gm_evspawn* sp = ((struct gm_evx10*) tbl[level]->x10)->unk20; + struct EventData* ev2 = &gmMainLib_804D3EE0->unk_530; u8 color = sp->unk3; if ((s8) ev2->x0 == sp->unk0 && (u8) ev2->x1 == color) { if (color <= 2) { @@ -3357,8 +3297,6 @@ void gm_801BF128(void) s32 b; s32 pick; s32 dup; - s32 prev; - u8 cur_id; PAD_STACK(0x38); count = 0; @@ -3402,13 +3340,17 @@ void gm_801BF128(void) c += 1; ((u8*) gmMainLib_804D3EE0)[j + 2] += 1; } while (c < 4); + count = 0; gm_801BF6C8(HSD_Randi(4)); - do { - gm_801BF6E8(HSD_Randi(4)); - prev = gm_801BF6F8(); - } while (gm_801BF6D8() == prev); + { + s32 prev; + do { + gm_801BF6E8(HSD_Randi(4)); + prev = gm_801BF6F8(); + } while (gm_801BF6D8() == prev); + } - c = (count = 0); + c = 0; do { if (gm_80164430(gm_801641CC(c)) != 0) { stage_pool[count] = c; @@ -3429,10 +3371,13 @@ void gm_801BF128(void) } } } - do { - pick = stage_pool[HSD_Randi(8)]; - cur_id = gm_801BF694(); - } while ((s32) gm_801641CC((u8) pick) == (s32) cur_id); + { + u32 cur_id; + do { + pick = stage_pool[HSD_Randi(8)]; + cur_id = gm_801BF694(); + } while ((s32) gm_801641CC((u8) pick) == (s32) cur_id); + } gm_801BF684(gm_801641CC((u8) pick)); ((u8*) gmMainLib_804D3EE0)[pick + 0x1C] += 1; gm_801BF6A8(HSD_Randi(4)); @@ -3471,43 +3416,52 @@ void gm_801BF3F8(void) void gm_801BF4DC(GameScene* arg0) { - StartMeleeData* temp_r31; + StartMeleeData* md; VsModeData* temp_r30; int i; temp_r30 = &gmMainLib_804D3EE0->unk_1710; - temp_r31 = gm_801A427C(arg0); + md = gm_801A427C(arg0); gm_80167BC8(temp_r30); - gm_8016F088(temp_r31); + gm_8016F088(md); gm_80168FC4(); - gm_80167A64(&temp_r31->rules); - - temp_r31->rules.x0_0 = gm_801BF6B8(); - temp_r31->rules.x0_6 = false; - temp_r31->rules.x10 = 0; - temp_r31->rules.x1_0 = false; - temp_r31->rules.x1_2 = true; - temp_r31->rules.x1_3 = true; - temp_r31->rules.disable_pausing = true; - temp_r31->rules.x7 = 0; - temp_r31->rules.x44 = gm_80183218; - temp_r31->rules.x34 = 1.0F; - temp_r31->rules.xE = (u16) gm_801BF694(); - gm_80167A14(temp_r31->players); + gm_80167A64(&md->rules); + + md->rules.x0_0 = gm_801BF6B8(); + md->rules.x0_6 = false; + md->rules.x10 = 0; + md->rules.x1_0 = false; + md->rules.x1_2 = true; + md->rules.x1_3 = true; + md->rules.disable_pausing = true; + md->rules.x7 = 0; + md->rules.x44 = gm_80183218; + md->rules.x34 = gm_DefaultGameSpeed; + md->rules.xE = (u16) gm_801BF694(); + gm_80167A14(md->players); for (i = 0; i < 4; i++) { CharacterKind kind = gm_801BF648(i); - temp_r31->players[i].c_kind = kind; - temp_r31->players[i].color = gm_801BF670(i); - temp_r31->players[i].slot_type = Gm_PKind_Cpu; - temp_r31->players[i].cpu_level = 9; - temp_r31->players[i].xE = 4; - temp_r31->players[i].xC_b1 = false; - if (temp_r31->rules.x0_0 == 1) { - temp_r31->players[i].stocks = 0x63; - } - } -} + md->players[i].c_kind = kind; + md->players[i].color = gm_801BF670(i); + md->players[i].slot_type = Gm_PKind_Cpu; + md->players[i].cpu_level = 9; + md->players[i].xE = 4; + md->players[i].xC_b1 = false; + if (md->rules.x0_0 == 1) { + md->players[i].stocks = 0x63; + } + } +} + +/// Default game speed (StartMeleeRules::x34) used by gm_801BF4DC. +/// The reference object keeps this 1.0F as a distinct .sdata2 object at +/// 0x804DAC88 (annotated scope:global in symbols.txt), separate from the +/// pooled 1.0F literal at 0x804DAC78: literal pooling dedupes plain +/// literals, so only a const object reproduces the second entry. It is +/// declared in gm_1BA8.h and defined after its user so the load is not +/// constant-folded back into the literal pool. +const f32 gm_DefaultGameSpeed = 1.0F; void gm_801BF634(s32 arg0, s8 character_kind) { diff --git a/src/melee/gm/gm_1BA8.h b/src/melee/gm/gm_1BA8.h index 8fcb1b78eb..2d6b9c2dca 100644 --- a/src/melee/gm/gm_1BA8.h +++ b/src/melee/gm/gm_1BA8.h @@ -110,5 +110,6 @@ /* 1BF920 */ void gm_801BF920(GameScene*); /* 3DDBE0 */ extern GameScene gm_CameraModeScenes[5]; /* 3DF94C */ extern gm_803DF94C_t* gm_803DF94C[]; +/* 4DAC88 */ extern const f32 gm_DefaultGameSpeed; #endif diff --git a/src/melee/gm/gmallstar.c b/src/melee/gm/gmallstar.c index 1faa5bfe6f..2dd8671ee8 100644 --- a/src/melee/gm/gmallstar.c +++ b/src/melee/gm/gmallstar.c @@ -385,14 +385,15 @@ void gm_801B5324(UnkAllstarData* arg0, u8 arg1) u8 colors[3]; s8* chars_ptr; u8* base; - s32 is_last_round; + s32 count; gm_803DEBE8_t* opp_data; s32 count_processed; - s32 count; + s32 is_last_round; struct GameCache* gc; s32 slot_idx; - u64 audio; + u8* colors_ptr; s32 i; + u64 audio; PAD_STACK(8); base = (u8*) gm_803DE930_Scenes; @@ -413,8 +414,9 @@ void gm_801B5324(UnkAllstarData* arg0, u8 arg1) chars[count_processed] = opp_data[count_processed].x3; } + colors_ptr = colors; { - u8* cp = colors; + u8* cp = colors_ptr; for (i = 0; i < 3; i++) { *cp = arg0->x54(arg1, arg0->x0.cpu_level, (u8) i); cp++; @@ -422,39 +424,36 @@ void gm_801B5324(UnkAllstarData* arg0, u8 arg1) } gmRegSetupEnemyColorTable(arg0->x0.ckind, arg0->x0.color, chars_ptr, - colors); + colors_ptr); if ((s32) arg1 == 0xC) { chars_ptr[0] = 3; - colors[0] = 0; + colors_ptr[0] = 0; is_last_round = 1; chars_ptr[1] = 3; - colors[1] = 0; + colors_ptr[1] = 0; chars_ptr[2] = 3; - colors[2] = 0; + colors_ptr[2] = 0; } gc = &lbDvd_8001822C()->game_cache; - slot_idx = 1; lbDvd_80018C6C(); + slot_idx = 1; gc->entries[0].char_id = (s32) (s8) arg0->x0.ckind; gc->entries[0].color = arg0->x0.color; lbDvd_80018254(); lbDvd_80018C2C(0xC7); lbDvd_80017700(4); - { - s32 idx = slot_idx; - for (i = 0; i < 3; i++) { - if ((s8) chars_ptr[i] != 0x21) { - gc->entries[idx].char_id = chars_ptr[i]; - if (is_last_round != 0) { - gc->entries[idx].color = 0xFF; - } else { - gc->entries[idx].color = colors[i]; - } - idx++; + for (i = 0; i < 3; i++) { + if (chars[i] != 0x21) { + gc->entries[slot_idx].char_id = chars[i]; + if (is_last_round != 0) { + gc->entries[slot_idx].color = 0xFF; + } else { + gc->entries[slot_idx].color = colors[i]; } + slot_idx++; } } @@ -588,6 +587,18 @@ void fn_801B5AA8(int arg0) lbBgFlash_8002063C(0x78); } +static inline void gmAllStarPreloadRemainingFighters(int round) +{ + s32 end_idx = (s32) gm_803DEC4C[round + 1].start; + gm_803DEBE8_t* opp = &gm_803DEBE8[end_idx]; + + while (end_idx < 0x19) { + gm_8016A998((s8) opp->x3, 0); + opp++; + end_idx++; + } +} + void gm_801B5ACC(GameScene* arg0) { u8 operand_pad[8]; @@ -629,7 +640,10 @@ void gm_801B5ACC(GameScene* arg0) data->players[0].xD_b2 = 1; data->rules.x7 = 9; - round = gm_8017BE84(arg0->idx); + { + u16 temp = gm_8017BE84(arg0->idx); + round = temp; + } { AllstarRoundInfo* ri = &gm_803DEC4C[round]; @@ -662,15 +676,7 @@ void gm_801B5ACC(GameScene* arg0) gm_8016F088(data); gm_8016A92C(&data->rules); - { - s32 end_idx = (s32) gm_803DEC4C[round + 1].start; - gm_803DEBE8_t* opp = &gm_803DEBE8[end_idx]; - while (end_idx < 0x19) { - gm_8016A998((s8) opp->x3, 0); - opp++; - end_idx++; - } - } + gmAllStarPreloadRemainingFighters(round); gm_801B5324(allstar, round + 1); data->rules.x50 = (void (*)(u8))(Event) fn_801B5AA8; @@ -750,7 +756,7 @@ void gm_801B60A4_OnLoad(void) gm_803DEBE8_t* var_r30; int temp; gm_803DEBE8_t tmp; - PAD_STACK(16); + PAD_STACK(12); data = &gm_80473A18; gmMainLib_8015CDE0(); @@ -790,42 +796,12 @@ void gm_801B60A4_OnLoad(void) } data->x74 = 0; + data->x9C = 0; { - UnkAllstarData* p = &gm_80473A18; - int i = 0x18; - data->x9C = 0; + int i; temp = 0x21; - p->x76[0] = temp; - p->x76[1] = temp; - p->x76[2] = temp; - p->x76[3] = temp; - p->x76[4] = temp; - p->x76[5] = temp; - p->x76[6] = temp; - p->x76[7] = temp; - p->x76[8] = temp; - p->x76[9] = temp; - p->x76[0xA] = temp; - p->x76[0xB] = temp; - p->x76[0xC] = temp; - p->x76[0xD] = temp; - p->x76[0xE] = temp; - p->x76[0xF] = temp; - p->x76[0x10] = temp; - p->x76[0x11] = temp; - p->x76[0x12] = temp; - p->x76[0x13] = temp; - p->x76[0x14] = temp; - p->x76[0x15] = temp; - p->x76[0x16] = temp; - p->x76[0x17] = temp; - - if (i < 0x1A) { - u8* q = ((u8*) p) + i; - i = 0x1A - i; - do { - *(q++ + 0x76) = temp; - } while (--i != 0); + for (i = 0; i < 0x1A; i++) { + gm_80473A18.x76[i] = temp; } } diff --git a/src/melee/gm/gmcamera.c b/src/melee/gm/gmcamera.c index 3195939326..bd22b81f30 100644 --- a/src/melee/gm/gmcamera.c +++ b/src/melee/gm/gmcamera.c @@ -54,22 +54,7 @@ typedef struct _SisLibUnkStruct { /// @todo #HSD_SisLib_804D1124 is of type #SIS. /// extern SisLibUnkStruct HSD_SisLib_804D1124; -f32 gmCamera_803DA630[12] = { - 0.6f, 0.6f, 40.0f, 416.0f, 0.6f, 0.6f, - 340.0f, 416.0f, 0.6f, 0.6f, 40.0f, 44.0f, -}; - -gmCameraUnkFuncTable gmCamera_803DA6B4[9] = { - { { 1, 0, 0 }, gmCamera_801A26C0, gmCamera_801A2798 }, - { { 0, 0, 4 }, gmCamera_801A2800, gmCamera_801A28AC }, - { { 0, 0, 2 }, gmCamera_801A292C, gmCamera_801A2AAC }, - { { 0, 0, 0x54 }, NULL, gmCamera_801A2BB0 }, - { { 0, 0, 0x34 }, NULL, gmCamera_801A2BB0 }, - { { 0, 0, 0x94 }, NULL, gmCamera_801A2BB0 }, - { { 0, 0, 0x1204 }, gmCamera_801A2BF0, gmCamera_801A2D44 }, - { { 0, 0, 0x1604 }, gmCamera_801A2FBC, gmCamera_801A2FFC }, - { { 0, 0, 0x1A14 }, NULL, gmCamera_801A2BB0 }, -}; +extern f32 gmCamera_803DA630[12]; u8* gmCamera_801A2224(u8* arg0, u32 arg1) { @@ -114,83 +99,80 @@ u8* gmCamera_801A2224(u8* arg0, u32 arg1) HSD_Text* gmCamera_801A2334(s32 arg0, f32 arg1, f32 arg2, f32 arg3, f32 arg4) { HSD_Text* text; - gmCameraUnkStruct* gcus = &gmCamera_80479BC8.gcus; - s32 temp_r4; - s32 temp_r6; - s32 var_r0; - s32 var_r30; - s32 var_r5; - u32 temp_r0; - u32* temp_r27; - u8* temp_r3; - gmCameraUnkStruct2* temp_r5; - - text = HSD_SisLib_803A5ACC(3, (s32) gcus->x54, arg1, arg2, 0.0f, 640.0f, - 32.0f); + union _gmCameraUnkUnion* gcu = &gmCamera_80479BC8; + s32 blocks; + s32 result; + s32 group; + s32 label; + u32 status; + u32* blocks_ptr; + u8* digits; + + text = HSD_SisLib_803A5ACC(3, (s32) gcu->gcus.x54, arg1, arg2, 0.0f, + 640.0f, 32.0f); text->font_size.x = arg3; text->font_size.y = arg4; text->default_kerning = 1; if (arg0 == 0) { - var_r30 = 6; - temp_r3 = HSD_SisLib_803A6530(3, 6, 8); + group = 6; + digits = HSD_SisLib_803A6530(3, 6, 8); } else { - var_r30 = 7; - temp_r3 = HSD_SisLib_803A6530(3, 7, 9); - } - temp_r6 = arg0 * 0x10; - temp_r5 = (gmCameraUnkStruct2*) ((int) gcus + temp_r6); - temp_r0 = temp_r5->x24; - (void) temp_r0; - switch (temp_r0) { + group = 7; + digits = HSD_SisLib_803A6530(3, 7, 9); + } + status = gcu->gcus4.x24[arg0].x0; + (void) status; + switch (status) { case 0: - if ((s32) temp_r5->x2C == 0) { - temp_r5->x30 = 3; - HSD_SisLib_803A660C(3, var_r30, 0xC); + if ((s32) gcu->gcus4.x24[arg0].x8 == 0) { + gcu->gcus4.x24[arg0].xC = 3; + HSD_SisLib_803A660C(3, group, 0xC); } else { - temp_r27 = &(temp_r5->x28); - temp_r4 = temp_r5->x28; - if (temp_r4 == 0) { - temp_r5->x30 = 2; - HSD_SisLib_803A660C(3, var_r30, 0xC); + gmCameraUnkStruct4* entries = gcu->gcus4.x24; + blocks_ptr = &entries[arg0].x4; + blocks = *blocks_ptr; + if (blocks == 0) { + gcu->gcus4.x24[arg0].xC = 2; + HSD_SisLib_803A660C(3, group, 0xC); } else { - if (temp_r4 >= (s32) gcus->x20) { + if (blocks >= (s32) gcu->gcus.x20) { if (arg0 != 0) { - var_r0 = 0; + result = 0; } else { - var_r0 = 1; + result = 1; } } else { - var_r0 = 2; + result = 2; } - temp_r5->x30 = var_r0; - gmCamera_801A2224(temp_r3, *temp_r27); - if ((s32) *temp_r27 != 1) { - var_r5 = 0xB; + gcu->gcus4.x24[arg0].xC = result; + gmCamera_801A2224(digits, *blocks_ptr); + if ((s32) *blocks_ptr != 1) { + label = 0xB; } else { - var_r5 = 0xA; + label = 0xA; } - HSD_SisLib_803A660C(3, var_r30, var_r5); + HSD_SisLib_803A660C(3, group, label); } } break; case 15: - temp_r5->x30 = 5; - HSD_SisLib_803A660C(3, var_r30, 0x10); + gcu->gcus4.x24[arg0].xC = 5; + HSD_SisLib_803A660C(3, group, 0x10); break; case 9: - temp_r5->x30 = 4; - HSD_SisLib_803A660C(3, var_r30, 0xD); + gcu->gcus4.x24[arg0].xC = 4; + HSD_SisLib_803A660C(3, group, 0xD); break; case 12: - temp_r5->x30 = 4; - HSD_SisLib_803A660C(3, var_r30, 0xE); + gcu->gcus4.x24[arg0].xC = 4; + HSD_SisLib_803A660C(3, group, 0xE); break; default: - temp_r5->x30 = 4; - HSD_SisLib_803A660C(3, var_r30, 0xF); + gcu->gcus4.x24[arg0].xC = 4; + HSD_SisLib_803A660C(3, group, 0xF); break; } - HSD_SisLib_803A6368(text, var_r30); + HSD_SisLib_803A6368(text, group); return text; } @@ -201,7 +183,9 @@ void gmCamera_801A253C(s32* arg0, s32* arg1) s32* x30 = &gcus->x30; s32* x40 = &gcus->x40; s32* x44; - s32 result = MIN(*x40, *x30); + s32* min_a = x30; + s32* min_b = x40; + s32 result = MIN(*min_a, *min_b); gcus->x44 = result; x44 = &gcus->x44; @@ -255,6 +239,22 @@ void gmCamera_801A2650(void) HSD_SisLib_803A611C(3, 0, 9, 13, 0, 14, 0, 11); } +gmCameraUnkFuncTable gmCamera_803DA6B4[9] = { + { { 1, 0, 0 }, gmCamera_801A26C0, gmCamera_801A2798 }, + { { 0, 0, 4 }, gmCamera_801A2800, gmCamera_801A28AC }, + { { 0, 0, 2 }, gmCamera_801A292C, gmCamera_801A2AAC }, + { { 0, 0, 0x54 }, NULL, gmCamera_801A2BB0 }, + { { 0, 0, 0x34 }, NULL, gmCamera_801A2BB0 }, + { { 0, 0, 0x94 }, NULL, gmCamera_801A2BB0 }, + { { 0, 0, 0x1204 }, gmCamera_801A2BF0, gmCamera_801A2D44 }, + { { 0, 0, 0x1604 }, gmCamera_801A2FBC, gmCamera_801A2FFC }, + { { 0, 0, 0x1A14 }, NULL, gmCamera_801A2BB0 }, +}; + +DATA char lbl_803DA720[8] = { 'I', 'f', 'C', 'a', 'm', 'e', 'r', 'a' }; +char lbl_803DA728[0x30] = + "Info_Top_model_set\0\0IfCamera_Top_model_set"; + static void gmCamera_801A2650_noinline(void); static void gmCamera_801A2650_noinline(void) { @@ -278,6 +278,7 @@ void gmCamera_801A26C0(void) lbl_8046B6A0_t* temp_r31; gmCameraUnkStruct* unk; s32 i; + s32 zero; PAD_STACK(4); temp_r31 = gm_8016AE38(); @@ -295,9 +296,11 @@ void gmCamera_801A26C0(void) } unk = &gmCamera_80479BC8.gcus; if (unk->x48[0] != NULL) { - for (i = 0; i < 3; i++) { + i = 0; + zero = i; + for (; i < 3; i++) { HSD_SisLib_803A5CC4(unk->x48[i]); - unk->x48[i] = NULL; + unk->x48[i] = (HSD_Text*) zero; } } } @@ -344,7 +347,7 @@ void gmCamera_801A28AC(void) void* temp_r4 = cmSnap_80031618(); gmCamera_80479BC8.gcus.x1C = temp_r4; if (temp_r4) { - if (lbSnap_8001DC0C((int) gmCamera_80479BC8.gcus.x1C) != 0) { + if (lbSnap_8001DC0C(gmCamera_80479BC8.gcus.x1C) != 0) { gmCamera_80479BC8.gcus.x20 = lbSnap_8001DF20(); gmCamera_801A3048(2); } else { @@ -357,42 +360,47 @@ void gmCamera_801A28AC(void) void gmCamera_801A292C(void) { HSD_Text* text; - gmCameraUnkStruct* unk = &gmCamera_80479BC8.gcus; - HSD_Text** texts = unk->x48; - gmCameraUnkStruct4Ptrs* snaps = (gmCameraUnkStruct4Ptrs*) unk; - f32* tbl = gmCamera_803DA630; s32 i; f32 new_var; - PAD_STACK(4); + union { + gmCameraUnkStruct* gcus; + gmCameraUnkStruct4Ptrs* gcus4; + } unk; + HSD_Text** texts; + f32* tbl = gmCamera_803DA630; + PAD_STACK(8); - if (unk->x48[0] != NULL) { + unk.gcus = &gmCamera_80479BC8.gcus; + texts = unk.gcus->x48; + + if (unk.gcus->x48[0] != NULL) { for (i = 0; i < 3; i++) { - HSD_SisLib_803A5CC4(unk->x48[i]); - unk->x48[i] = NULL; + HSD_SisLib_803A5CC4(unk.gcus->x48[i]); + unk.gcus->x48[i] = NULL; } } for (i = 0; i < 2; i++) { - snaps->x24[i].x0 = lbSnap_8001D40C(i); - if (!snaps->x24[i].x0) { - snaps->x24[i].x4 = lbSnap_8001D3B0(i); - snaps->x24[i].x8 = lbSnap_8001D3CC(i); + unk.gcus4->x24[i].x0 = lbSnap_8001D40C(i); + if (!unk.gcus4->x24[i].x0) { + unk.gcus4->x24[i].x4 = lbSnap_8001D3B0(i); + unk.gcus4->x24[i].x8 = lbSnap_8001D3CC(i); } } - text = HSD_SisLib_803A5ACC(3, (s32) unk->x54, tbl[10], tbl[11], 0.0f, + text = HSD_SisLib_803A5ACC(3, (s32) unk.gcus->x54, tbl[10], tbl[11], 0.0f, 640.0f, 32.0f); new_var = tbl[9]; text->font_size.x = tbl[8]; text->font_size.y = new_var; text->default_kerning = 1; - gmCamera_801A2224(HSD_SisLib_803A6530(3, 3, 4), unk->x20); + gmCamera_801A2224(HSD_SisLib_803A6530(3, 3, 4), unk.gcus->x20); HSD_SisLib_803A660C(3, 3, 5); HSD_SisLib_803A6368(text, 3); - unk->x48[2] = text; + unk.gcus->x48[2] = text; texts[0] = gmCamera_801A2334(0, tbl[2], tbl[3], tbl[0], tbl[1]); - unk->x48[1] = gmCamera_801A2334(1, tbl[6], tbl[7], tbl[4], tbl[5]); - unk->x44 = MIN(unk->x30, unk->x40); + unk.gcus->x48[1] = gmCamera_801A2334(1, tbl[6], tbl[7], tbl[4], tbl[5]); + unk.gcus->x44 = MIN(unk.gcus->x30, unk.gcus->x40); } void gmCamera_801A2AAC(void) @@ -457,7 +465,7 @@ void gmCamera_801A2BF0(void) HSD_JObj** px8; u32* px18; f32 var_f1; - f32 var_f31; + f32 translate_x; gmCameraUnkStruct* gcus = &gmCamera_80479BC8.gcus; px8 = &gcus->x8; @@ -474,8 +482,44 @@ void gmCamera_801A2BF0(void) px18 = &gcus->x18; *px18 = 0; lb_80011E24(*px8, &jobj_b, 0xC, -1); - var_f31 = gmCamera_801A2BF0_get_translate_x(px18); - HSD_JObjSetTranslateX(jobj_b, var_f31); + translate_x = gmCamera_801A2BF0_get_translate_x(px18); + HSD_JObjSetTranslateX(jobj_b, translate_x); +} + +static inline void gmCamera_801A2D44_update_selection(HSD_JObj** jobj_b, + HSD_JObj** jobj) +{ + gmCameraUnkStruct* gcus = &gmCamera_80479BC8.gcus; + u32* px18; + f32 translate_x; + + if (HSD_PadCopyStatus[3].trigger & 0x40001) { + if ((s32) *(px18 = &gcus->x18) != 0) { + lbAudioAx_80024030(2); + *px18 = 0; + lb_80011E24(gcus->x8, &(*jobj), 0xC, -1); + if ((s32) *px18 != 0) { + translate_x = 5.0f; + } else { + translate_x = -5.0f; + } + HSD_JObjSetTranslateX(*jobj, translate_x); + return; + } + } + if (HSD_PadCopyStatus[3].trigger & 0x80002) { + if ((s32) *(px18 = &gcus->x18) != 1) { + lbAudioAx_80024030(2); + *px18 = 1; + lb_80011E24(gcus->x8, &(*jobj_b), 0xC, -1); + if ((s32) *px18 != 0) { + translate_x = 5.0f; + } else { + translate_x = -5.0f; + } + HSD_JObjSetTranslateX(*jobj_b, translate_x); + } + } } void gmCamera_801A2D44(void) @@ -483,9 +527,7 @@ void gmCamera_801A2D44(void) gmCameraUnkStruct* gcus = &gmCamera_80479BC8.gcus; HSD_JObj* jobj; HSD_JObj* jobj_b; - u32* px18; - f32 var_f31; - PAD_STACK(24); + PAD_STACK(16); if ((lbSnap_8001D338(0) != 0) || (lbSnap_8001D338(1) != 0)) { gmCamera_801A3048(2); @@ -506,28 +548,7 @@ void gmCamera_801A2D44(void) gmCamera_801A3048(0); return; } - px18 = &gcus->x18; - if ((HSD_PadCopyStatus[3].trigger & 0x40001) && (s32) *px18 != 0) { - lbAudioAx_80024030(2); - *px18 = 0; - lb_80011E24(gcus->x8, &jobj, 0xC, -1); - if ((s32) *px18 != 0) { - var_f31 = 5.0f; - } else { - var_f31 = -5.0f; - } - HSD_JObjSetTranslateX(jobj, var_f31); - } else if ((HSD_PadCopyStatus[3].trigger & 0x80002) && (s32) *px18 != 1) { - lbAudioAx_80024030(2); - *px18 = 1; - lb_80011E24(gcus->x8, &jobj_b, 0xC, -1); - if ((s32) *px18 != 0) { - var_f31 = 5.0f; - } else { - var_f31 = -5.0f; - } - HSD_JObjSetTranslateX(jobj_b, var_f31); - } + gmCamera_801A2D44_update_selection(&jobj_b, &jobj); } void gmCamera_801A2FBC(void) @@ -598,45 +619,46 @@ void fn_801A31D8(HSD_GObj* gobj) HSD_JObjAnimAll(gobj->hsd_obj); } +static inline HSD_JObj* gmCamera_SetJObj(HSD_JObj** dst, HSD_JObj* jobj) +{ + *dst = jobj; + return jobj; +} + void gmCamera_801A31FC(void) { - HSD_GObj* gobj_a; - HSD_GObj* gobj_b; - HSD_JObj* jobj_a; + gmCameraUnkFuncTable* entry; HSD_JObj* jobj_b; HSD_Joint** joint_a; DynamicModelDesc* mdl_b; - void (*cb)(void); + HSD_GObj* gobj_a; gmCameraUnkStruct* gcus = &gmCamera_80479BC8.gcus; - PAD_STACK(24); + PAD_STACK(8); cmSnap_800316B4(); gcus->x14 = 1; gcus->xC = 0; - cb = gmCamera_803DA6B4[gcus->xC].x4; - if (cb != NULL) { - cb(); + entry = &gmCamera_803DA6B4[gcus->xC]; + if (entry->x4 != NULL) { + entry->x4(); } gcus->ifvscam = lbArchive_LoadArchive("IfVsCam"); - joint_a = HSD_ArchiveGetPublicAddress(gcus->ifvscam, - "IfCameraInfo_Top_model_set"); + joint_a = HSD_ArchiveGetPublicAddress(gcus->ifvscam, lbl_803DA720); + gobj_a = GObj_Create(0xE, 0x10, 0); + HSD_GObjObject_80390A70( + gobj_a, HSD_GObj_804D7849, + gmCamera_SetJObj(&gcus->x4, HSD_JObjLoadJoint(*joint_a))); + GObj_SetupGXLink(gobj_a, HSD_GObj_JObjCallback, 0xB, 0); + mdl_b = HSD_ArchiveGetPublicAddress(gcus->ifvscam, &lbl_803DA728[0x14]); gobj_a = GObj_Create(0xE, 0x10, 0); - jobj_a = HSD_JObjLoadJoint(*joint_a); - gcus->x4 = jobj_a; - HSD_GObjObject_80390A70(gobj_a, HSD_GObj_804D7849, jobj_a); + jobj_b = gmCamera_SetJObj(&gcus->x8, HSD_JObjLoadJoint(mdl_b->joint)); + HSD_GObjObject_80390A70(gobj_a, HSD_GObj_804D7849, jobj_b); GObj_SetupGXLink(gobj_a, HSD_GObj_JObjCallback, 0xB, 0); - mdl_b = - HSD_ArchiveGetPublicAddress(gcus->ifvscam, "IfCamera_Top_model_set"); - gobj_b = GObj_Create(0xE, 0x10, 0); - jobj_b = HSD_JObjLoadJoint(mdl_b->joint); - gcus->x8 = jobj_b; - HSD_GObjObject_80390A70(gobj_b, HSD_GObj_804D7849, jobj_b); - GObj_SetupGXLink(gobj_b, HSD_GObj_JObjCallback, 0xB, 0); gm_8016895C(jobj_b, mdl_b, 0); HSD_JObjReqAnimAll(jobj_b, 0.0f); HSD_JObjAnimAll(jobj_b); HSD_JObjSetFlagsAll(jobj_b, JOBJ_HIDDEN); - HSD_GObj_SetupProc(gobj_b, fn_801A31D8, 0); + HSD_GObj_SetupProc(gobj_a, fn_801A31D8, 0); gcus->x20 = 2; HSD_SisLib_803A62A0(3, "SdVsCam", "SIS_VsCameraData"); gcus->x54 = HSD_SisLib_803A611C(3, NULL, 9, 0xD, 0, 0xE, 0, 0xB); @@ -645,6 +667,11 @@ void gmCamera_801A31FC(void) gcus->x48[2] = NULL; } +f32 gmCamera_803DA630[12] ATTRIBUTE_ALIGN(8) = { + 0.6f, 0.6f, 40.0f, 416.0f, 0.6f, 0.6f, + 340.0f, 416.0f, 0.6f, 0.6f, 40.0f, 44.0f, +}; + void gmCamera_801A33BC(void) { HSD_Text* text; diff --git a/src/melee/gm/gmcamera.static.h b/src/melee/gm/gmcamera.static.h index ce6350d1cd..8c6d62dd6e 100644 --- a/src/melee/gm/gmcamera.static.h +++ b/src/melee/gm/gmcamera.static.h @@ -4,7 +4,7 @@ #include "gm/types.h" static struct CameraVsData gmCamera_80479C20; -static f32 gmCamera_803DA758[12] = { +f32 gmCamera_803DA758[12] = { 0.7f, 0.7f, 168.0f, 160.0f, 0.7f, 0.7f, 168.0f, 192.0f, 0.7f, 0.7f, 0.0f, 256.0f, }; diff --git a/src/melee/gm/gmclassic.c b/src/melee/gm/gmclassic.c index 0f4d693f7c..0ac6d4abf2 100644 --- a/src/melee/gm/gmclassic.c +++ b/src/melee/gm/gmclassic.c @@ -19,7 +19,10 @@ extern UNK_T gmClassic_804D68D0; typedef struct gmClassicMatchup { /* 0x00 */ u16 x00; - /* 0x02 */ s8 x02[3]; + /* 0x02 */ union { + s8 x02[3]; + u8 x02_u8[3]; + }; /* 0x05 */ u8 x05; } gmClassicMatchup; STATIC_ASSERT(sizeof(gmClassicMatchup) == 6); @@ -386,7 +389,7 @@ static inline void gmClassic_InitMatchupOrder(const gmClassicMatchup* matchups, s32 count; s32 i; - for (count = 0; matchups[count].x00 != 0x148; count++) { + for (count = 0; matchups->x00 != 0x148; matchups++, count++) { } for (i = 0; i < count; i++) { @@ -404,17 +407,17 @@ static inline void gmClassic_InitMatchupOrder(const gmClassicMatchup* matchups, static gmClassicMatchup* gmClassic_801B2BA4(gmClassicMatchup* arg0, u8* arg1, gm_803DDEC8Struct* arg2) { - gmClassicMatchup* result; - gmClassicMatchup* entry; - gm_803DDEC8Struct* temp; - u8* order; s32 outer; - s8 target_char; - int cur_char; - s32 j; s32 k; + s32 j; + gm_803DDEC8Struct* temp; s32 count; - s32 stage1; + gmClassicMatchup* entry; + gmClassicMatchup* result; + gmClassicMatchup* count_entry; + s32 cur_char; + s32 target_char; + u8* order; result = NULL; target_char = (s8) gmMainLib_8015CDC8()->c_kind; @@ -450,8 +453,8 @@ static gmClassicMatchup* gmClassic_801B2BA4(gmClassicMatchup* arg0, u8* arg1, for (temp = arg2; temp->x0 != 0xD; temp++) { if (temp->xC != NULL) { - stage1 = Stage_8022519C((InternalStageId) entry->x00); - if (Stage_8022519C((InternalStageId) temp->xC->x00) == stage1) + if (Stage_8022519C((InternalStageId) temp->xC->x00) == + Stage_8022519C((InternalStageId) entry->x00)) { result = entry; goto next; @@ -467,7 +470,9 @@ static gmClassicMatchup* gmClassic_801B2BA4(gmClassicMatchup* arg0, u8* arg1, order++; check: count = 0; - while (arg0[count].x00 != 0x148) { + count_entry = arg0; + while (count_entry->x00 != 0x148) { + count_entry++; count++; } if (outer < count) { @@ -577,10 +582,10 @@ static gm_803DDEC8Struct* gmClassic_801B2D54(gm_803DDEC8Struct* arg0) void gmClassic_OnLoad(void) { UnkAllstarData* data; - gmClassicSceneData* scene_data = (gmClassicSceneData*) gm_803DDC58_Scenes; + s32 i; gmClassic_80490880Data* o = &gmClassic_80490880; gm_803DDEC8Struct* entry; - s32 i; + gmClassicSceneData* scene_data = (gmClassicSceneData*) gm_803DDC58_Scenes; PAD_STACK(32); for (entry = scene_data->matchups.x00; entry->x0 != 0x0D; entry++) { @@ -589,8 +594,7 @@ void gmClassic_OnLoad(void) gmClassic_InitMatchupOrder(scene_data->matchups.x2B0, gmClassic_80490880.x80); - gmClassic_InitMatchupOrder(scene_data->matchups.x26C, - gmClassic_80490880.x74); + gmClassic_InitMatchupOrder(scene_data->matchups.x26C, o->x74); gmClassic_InitMatchupOrder(scene_data->matchups.x1B8, gmClassic_80490880.x54); gmClassic_InitMatchupOrder(scene_data->matchups.x0CC, @@ -641,15 +645,14 @@ void gmClassic_801B3500(GameScene* arg0) { gmClassicIntroData* sd; gm_803DDEC8Struct* entry; - UnkAllstarData* ad; - int enemy_count; int ally_count; int i; + UnkAllstarData* ad; + int enemy_count; struct GameCache* gc; int count; u64 audio; s8 ckind; - PreloadCacheSceneEntry* ep; sd = gm_801A427C(arg0); entry = &gmClassic_803DDEC8.x00[(u8) gm_8017BE84(arg0->idx)]; @@ -682,9 +685,6 @@ void gmClassic_801B3500(GameScene* arg0) case 3: sd->x04 = 3; break; - default: - sd->x04 = 0; - break; } } else { sd->x04 = 0; @@ -707,31 +707,37 @@ void gmClassic_801B3500(GameScene* arg0) } sd->x0C = enemy_count; - ally_count = 1; - ckind = ad->x0.ckind; - if (ckind == 0x12 && ad->x0.xC.x12 != 0) { - sd->x0D[0] = 0x13; - } else { - sd->x0D[0] = ckind; - } - sd->x13[0] = ad->x0.color; - - gm_8017DB88(ad->x0.xC.x24, entry->x1, ad->x0.cpu_level, - (u8) gm_8017BE84(arg0->idx), sd->x10, sd->x0D[0], - (u8 (*)(s32, s32, u8))(Event) ad->x58, - (u8 (*)(s32, s32, u8))(Event) ad->x5C, - (u8 (*)(s32, s32, u8))(Event) ad->x60, - (f32 (*)(s32, s32))(Event) ad->x6C, - (f32 (*)(s32, s32))(Event) ad->x70); - - for (i = 1; i < 3; i++) { - sd->x0D[i] = gm_8017DB6C((gm_8017DB6C_arg0_t*) ad->x0.xC.x24, i - 1); - sd->x13[i] = gm_8017DB78((gm_8017DB6C_arg0_t*) ad->x0.xC.x24, i - 1); - if (sd->x0D[i] != 0x21) { - ally_count++; + { + int j; + + ally_count = 1; + ckind = ad->x0.ckind; + if (ckind == 0x12 && ad->x0.xC.x12 != 0) { + sd->x0D[0] = 0x13; + } else { + sd->x0D[0] = ckind; + } + sd->x13[0] = ad->x0.color; + + gm_8017DB88(ad->x0.xC.x24, entry->x1, ad->x0.cpu_level, + (u8) gm_8017BE84(arg0->idx), entry->xC->x02_u8, sd->x0D[0], + (u8 (*)(s32, s32, u8))(Event) ad->x58, + (u8 (*)(s32, s32, u8))(Event) ad->x5C, + (u8 (*)(s32, s32, u8))(Event) ad->x60, + (f32 (*)(s32, s32))(Event) ad->x6C, + (f32 (*)(s32, s32))(Event) ad->x70); + + for (j = 1; j < 3; j++) { + sd->x0D[j] = + gm_8017DB6C((gm_8017DB6C_arg0_t*) ad->x0.xC.x24, j - 1); + sd->x13[j] = + gm_8017DB78((gm_8017DB6C_arg0_t*) ad->x0.xC.x24, j - 1); + if (sd->x0D[j] != 0x21) { + ally_count++; + } } + sd->x0B = ally_count; } - sd->x0B = ally_count; sd->x09 = ad->x0.x4; gc = &lbDvd_8001822C()->game_cache; @@ -743,74 +749,25 @@ void gmClassic_801B3500(GameScene* arg0) lbDvd_80018C2C(0xC7); lbDvd_80017700(4); - { - s8 echar; - - ep = &gc->entries[count]; - - echar = entry->xC->x02[0]; - if (echar != 0x21) { - ep->char_id = echar; - if (entry->x1 & 8) { - ep->color = 0xFF; - } else { - ep->color = sd->x16[0]; - } - count++; - ep++; - } - - echar = entry->xC->x02[1]; - if (echar != 0x21) { - ep->char_id = echar; - if (entry->x1 & 8) { - ep->color = 0xFF; - } else { - ep->color = sd->x16[1]; - } - count++; - ep++; - } - - echar = entry->xC->x02[2]; + for (i = 0; i < 3; i++) { + s8 echar = entry->xC->x02[i]; if (echar != 0x21) { - ep->char_id = echar; + gc->entries[count].char_id = echar; if (entry->x1 & 8) { - ep->color = 0xFF; + gc->entries[count].color = 0xFF; } else { - ep->color = sd->x16[2]; + gc->entries[count].color = sd->x16[i]; } count++; } } - { - s8 achar; - Unk1PData_x24* ap; - - ep = &gc->entries[count]; - ap = ad->x0.xC.x24; - - achar = ap->ckind; - if (achar != 0x21) { - ep->char_id = achar; - ep->color = ap->x1; - ep++; - } - ap++; - - achar = ap->ckind; - if (achar != 0x21) { - ep->char_id = achar; - ep->color = ap->x1; - ep++; - } - ap++; - - achar = ap->ckind; + for (i = 0; i < 3; i++) { + s8 achar = ad->x0.xC.x24[i].ckind; if (achar != 0x21) { - ep->char_id = achar; - ep->color = ap->x1; + gc->entries[count].char_id = achar; + gc->entries[count].color = ad->x0.xC.x24[i].x1; + count++; } } @@ -828,19 +785,27 @@ void gmClassic_801B3500(GameScene* arg0) audio = lbAudioAx_80026E84(ad->x0.ckind); - for (i = 0; i < 3; i++) { - s8 achar = ad->x0.xC.x24[i].ckind; - if (achar != 0x21) { - audio |= lbAudioAx_80026E84(achar); + { + int j; + + for (j = 0; j < 3; j++) { + s8 achar = ad->x0.xC.x24[j].ckind; + if (achar != 0x21) { + audio |= lbAudioAx_80026E84(achar); + } } } - for (i = 0; i < 3; i++) { - s8 echar = entry->xC->x02[i]; - if (echar != 0x21) { - audio |= lbAudioAx_80026E84(echar); - if (entry->xC->x02[i] == 4) { - audio |= ((u64) 2 << 32) | 0x4000; + { + int j; + + for (j = 0; j < 3; j++) { + int echar = entry->xC->x02[j]; + if ((s8) echar != 0x21) { + audio |= lbAudioAx_80026E84((s8) echar); + if (entry->xC->x02[j] == 4) { + audio |= ((u64) 2 << 32) | 0x4000; + } } } } diff --git a/src/melee/gm/gmmain_lib.c b/src/melee/gm/gmmain_lib.c index d7ac399820..439aac5d3a 100644 --- a/src/melee/gm/gmmain_lib.c +++ b/src/melee/gm/gmmain_lib.c @@ -844,8 +844,12 @@ s32 gmMainLib_8015DBF4(s32 arg0) ADJ_NAMETAG_PRELOADED(config->x4); ADJ_NAMETAG_78(gmMainLib_804D3EE0->unk_522.x4); ADJ_NAMETAG_78(gmMainLib_804D3EE0->unk_528.x4); - ADJ_NAMETAG_STANDALONE_PAIR(*((u8*) config + 0x18), - *((u8*) config + 0x18)); + val = config[4].c_kind; + if (val == (u8) arg0) { + config[4].c_kind = 0x78; + } else if (val > (u8) arg0 && val != 0x78) { + config[4].c_kind = val - 1; + } ADJ_NAMETAG_78(gmMainLib_804D3EE0->unk_530.unk_584.unk_586); ADJ_VMD_SINGLE(&gm_80497618); @@ -904,25 +908,18 @@ s32 gmMainLib_8015DBF4(s32 arg0) void gmMainLib_8015EA80(void) { s32 i; + s32 j; + s8* base = gmMainLib_804D3EE0->unk_530.unk_588; + gmMainLib_8015CDEC(); for (i = 0; i < 6; i++) { - s8* ptr = gmMainLib_8015CE44(i, 0x78); - if (ptr != NULL) { - *ptr = 5; + for (j = 0; j < 6; j++) { + base[0x78 + i * 0x140 + j * 0x24] = 9; } } - { - char* base = (char*) gmMainLib_804D3EE0 + 0x588; - s32 j; - for (i = 0; i < 6; i++) { - for (j = 0; j < 6; j++) { - base[0x78 + i * 0x140 + j * 0x24] = 9; - } - } - for (i = 7; i < 13; i++) { - for (j = 0; j < 6; j++) { - base[0x78 + i * 0x140 + j * 0x24] = 9; - } + for (i = 7; i < 13; i++) { + for (j = 0; j < 6; j++) { + base[0x78 + i * 0x140 + j * 0x24] = 9; } } } @@ -1129,25 +1126,33 @@ void InitializePersistentNameData(s32 arg0) data->x1A2 = 5; } -void gmMainLib_8015F150(void) +static inline struct FighterData* +GetPersistentFighterDataBase(struct gmm_x1868* data) { - s32 i; + return data->x1F2C; +} - PAD_STACK(8); +static inline void ResetPersistentFighterData(void) +{ + s32 i; for (i = 0; i < 0x19; i++) { int j = 0; - struct FighterData* base = gmMainLib_804D3EE0->thing.x1F2C; - for (; j < 0x19; j++) { + struct FighterData* base = + GetPersistentFighterDataBase(&gmMainLib_804D3EE0->thing); + for (; 0x19 > j; j++) { base[(u8) i].fighter_kos[j] = 0; } gmMainLib_8015EF30( - (struct gmMainLib_8015EF30_s*) &gmMainLib_804D3EE0->thing - .x1F2C[(u8) i] - .sd_count); + (struct gmMainLib_8015EF30_s*) &base[(u8) i].sd_count); } } +void gmMainLib_8015F150(void) +{ + ResetPersistentFighterData(); +} + void gmMainLib_8015F260(void) { s32 i; @@ -1260,13 +1265,14 @@ void gmMainLib_8015F600(int arg0, int arg1) s32 j = 0; do { s32 i; + u8 slot = j; struct FighterData* fdata = gmMainLib_804D3EE0->thing.x1F2C; for (i = 0; 25 > i; i++) { - fdata[(u8) j].fighter_kos[i] = 0; + fdata[slot].fighter_kos[i] = 0; } gmMainLib_8015EF30( (struct gmMainLib_8015EF30_s*) &gmMainLib_804D3EE0->thing - .x1F2C[(u8) j] + .x1F2C[slot] .sd_count); j++; } while (j < 25); @@ -1315,7 +1321,7 @@ void gmMainLib_8015F600(int arg0, int arg1) bank = gmMainLib_804D3EE0->thing.x2FF8; data = &bank[(u8) idx / 19].inner[(u8) idx % 19]; - for (i = 0; i < 120; i++) { + for (i = 0; 120 > i; i++) { data->vs_kos[i] = 0; } gmMainLib_8015EF30((struct gmMainLib_8015EF30_s*) &data->sd_count); diff --git a/src/melee/gm/gmregclear.c b/src/melee/gm/gmregclear.c index 33fd810f65..acdc08a3e7 100644 --- a/src/melee/gm/gmregclear.c +++ b/src/melee/gm/gmregclear.c @@ -1,6 +1,5 @@ #include "gmregclear.h" -#include "gm_unsplit.h" #include "platform.h" #include "baselib/forward.h" @@ -32,11 +31,25 @@ #include #include #include +#include +#include +#include +#include +#include +#include #include +#include +#include +#include +#include +#include #include +#include +#include #include #include #include +#include #include #include #include @@ -650,36 +663,81 @@ u8 gm_8017CD94(UnkAdventureData* arg0, int arg1, int arg2, int arg3) return 0; } +static inline s32 gm_8017CE34_CountEnemies(s8* arg0) +{ + s32 count = 0; + + if ((s32) (u8) arg0[0] != 0x21) { + count = 1; + } + { + s8* p = &arg0[1]; + if ((s32) *p != 0x21) { + count += 1; + } + if ((s32) p[1] != 0x21) { + count += 1; + } + } + return count; +} + +static inline void gm_8017CE34_SetupColors(UnkAdventureData* arg1, + s32 count, s8* arg2, u8* colors) +{ + s32 color_idx; + + { + u8* out_color = colors; + s8* kind_iter = arg2; + for (color_idx = 0; color_idx < 3; color_idx++) { + u8 kind = (u8) *kind_iter; + u8 num_colors = gm_80169238(kind); + u8 color_id; + if (arg1->x54 != NULL) { + u8 requested_color; + requested_color = + arg1->x54((u8) count, arg1->x0.cpu_level, + (u8) color_idx); + if (num_colors != 0) { + color_id = requested_color % num_colors; + } else { + color_id = 0; + } + } else { + color_id = 0; + } + *out_color = color_id; + out_color += 1; + kind_iter += 1; + } + } +} + s32 gm_8017CE34(StartMeleeData* arg0, UnkAdventureData* arg1, s8* arg2, u8 arg3, u8 arg4, u8 arg5, s32 arg6, InternalStageId arg7, s32 count, s32 arg9) { u8 colors[3]; - s32 var_r20; u8 enemy_level; + s32 boss_count; u8 enemy_cpu_type; s32 player_idx; - s32 var_r4; - u8 var_r6; - s32 var_r4_2; - u8 var_r3; - s32 color_idx; - s32 enemy_idx; - s8* enemy_kind; - u8 player_kind; - s32 player_offset; f32 attack_ratio; + u8 player_stocks; + s32 player_ckind; + u8 flags; + s8* enemy_kind; f32 defense_ratio; - u8* color_iter; + u8 enemy_ckind; + s32 enemy_count; + s32 enemy_idx; s32 sp8; - typedef struct StartMeleePlayerCursor { - char pad[0x60]; - PlayerInitData player; - } StartMeleePlayerCursor; + u8* color_iter; - PAD_STACK(24); + PAD_STACK(16); - var_r20 = 0; + boss_count = 0; enemy_level = 0; enemy_cpu_type = 0; arg1->x0.xC.xC = 1; @@ -717,22 +775,10 @@ s32 gm_8017CE34(StartMeleeData* arg0, UnkAdventureData* arg1, s8* arg2, arg0->rules.xE = (u16) arg7; arg0->rules.xB = arg1->x48((u8) count, arg1->x0.cpu_level); - var_r4 = 0; arg0->rules.x20 = (u64) -1; - if ((s32) (u8) arg2[0] != 0x21) { - var_r4 = 1; - } - { - s8* p = &arg2[1]; - if ((s32) *p != 0x21) { - var_r4 += 1; - } - if ((s32) p[1] != 0x21) { - var_r4 += 1; - } - } - if (var_r4 == 0) { + enemy_count = gm_8017CE34_CountEnemies(arg2); + if (enemy_count == 0) { arg0->rules.x5_1 = 1; } if (arg1->x0.x8 & 1) { @@ -765,21 +811,21 @@ s32 gm_8017CE34(StartMeleeData* arg0, UnkAdventureData* arg1, s8* arg2, } if ((arg1->x0.x8 & 0x80) != 0) { - var_r6 = 1; + player_stocks = 1; } else { - var_r6 = arg1->x0.stocks; + player_stocks = arg1->x0.stocks; } - var_r4_2 = (u8) arg1->x0.ckind; - if ((var_r4_2 == 0x12) && ((u8) arg1->x0.xC.x12 != 0)) { - var_r4_2 = 0x13; + player_ckind = (u8) arg1->x0.ckind; + if ((player_ckind == 0x12) && ((u8) arg1->x0.xC.x12 != 0)) { + player_ckind = 0x13; } else if (((arg1->x0.x8 & 0x80) != 0) && ((u8) arg1->x0.x9 == 1) && - ((s8) var_r4_2 == 0xE)) + ((s8) player_ckind == 0xE)) { - var_r4_2 = 0x20; + player_ckind = 0x20; } - gm_801B0620(arg0->players, var_r4_2, arg1->x0.color, var_r6, + gm_801B0620(arg0->players, player_ckind, arg1->x0.color, player_stocks, arg1->x0.slot); arg0->players[0].xA = arg1->x0.x4; arg0->players[0].spawn_dir = (s8) arg1->x0.xA; @@ -802,92 +848,65 @@ s32 gm_8017CE34(StartMeleeData* arg0, UnkAdventureData* arg1, s8* arg2, attack_ratio = arg1->x64((u8) count, arg1->x0.cpu_level); defense_ratio = arg1->x68((u8) count, arg1->x0.cpu_level); + gm_8017CE34_SetupColors(arg1, count, arg2, colors); color_iter = colors; - { - u8* out_color = color_iter; - s8* kind_iter = arg2; - for (color_idx = 0; color_idx < 3; color_idx++) { - u8 num_colors = gm_80169238((u8) *kind_iter); - u8 color_id; - if (arg1->x54 != NULL) { - u8 requested_color; - requested_color = - arg1->x54((u8) count, arg1->x0.cpu_level, (u8) color_idx); - if (num_colors != 0) { - color_id = requested_color % num_colors; - } else { - color_id = 0; - } - } else { - color_id = 0; - } - *out_color = color_id; - out_color += 1; - kind_iter += 1; - } - } { s32 temp_r3_4 = arg1->x0.x8 & 8; if ((temp_r3_4 != 0) && ((u8) arg1->x0.xC.x11 == 0)) { s32 base_enemy_count; s32 event_enemy_count; - s32 var_r24_2; - s32 var_r25_2; - u8 temp_r4; + s32 special_stage; + s32 special_enemy_mode; + u8 first_enemy; u32 stage_flags; - base_enemy_count = 0; - if ((s32) (u8) arg2[0] != 0x21) { - base_enemy_count = 1; - } - { - s8* p = &arg2[1]; - if ((s32) *p != 0x21) { - base_enemy_count += 1; - } - if ((s32) p[1] != 0x21) { - base_enemy_count += 1; - } - } + base_enemy_count = gm_8017CE34_CountEnemies(arg2); arg1->x0.xC.xC = 3; event_enemy_count = base_enemy_count; - var_r24_2 = 0; - var_r25_2 = 0; - sp8 = 0; + special_stage = 0; + special_enemy_mode = 0; if (arg1->x4C != NULL) { enemy_level = arg1->x4C((u8) count, arg1->x0.cpu_level, 0U); } - temp_r4 = (u8) arg2[0]; - if ((s8) temp_r4 != 4) { - if ((u8) (temp_r4 - 0x1B) <= 1U) { + sp8 = arg6; + first_enemy = (u8) arg2[0]; + if ((s8) first_enemy != 4) { + if ((u8) (first_enemy - 0x1B) <= 1U) { arg0->rules.x0_3 = 6; event_enemy_count = 5; colors[0] = 0; - var_r24_2 = 1; - var_r25_2 = 1; - } else if (((s8) temp_r4 == 0xD) && + special_stage = 1; + special_enemy_mode = 1; + } else if (((s8) first_enemy == 0xD) && (((s32) arg2[1] != 0xD) || ((s32) arg2[2] != 0xD))) { - var_r25_2 = 2; + special_enemy_mode = 2; } } - stage_flags = Ground_801C5AD0(Stage_8022519C(arg7)); + { + s32 stage_id = Stage_8022519C(arg7); + stage_flags = Ground_801C5AD0(stage_id); + } - gm_8016A22C((s8) (u8) arg2[0], (s8) arg2[1], (s8) arg2[2], - colors[0], colors[1], (s32) colors[2], var_r24_2, - var_r25_2, sp8, (u8) arg1->x0.ckind, arg1->x0.color, - (s32) enemy_level, (s32) arg3, event_enemy_count, - (s32) stage_flags, (s32) arg5, (s32) arg4, - attack_ratio, defense_ratio); + { + u8 player_ckind = (u8) arg1->x0.ckind; + gm_8016A22C((s8) (u8) arg2[0], (s8) arg2[1], (s8) arg2[2], + colors[0], colors[1], (s32) colors[2], + special_stage, special_enemy_mode, sp8, + player_ckind, arg1->x0.color, (s32) enemy_level, + (s32) arg3, event_enemy_count, (s32) stage_flags, + (s32) arg5, (s32) arg4, attack_ratio, + defense_ratio); + } gm_8016A21C(&arg0->rules); arg1->x0.xC.x11 = 0; if (arg1->x0.x8 & 4) { fn_8016A450(); } - if ((u8) var_r25_2 == 1) { + if ((u8) special_enemy_mode == 1) { fn_8016A46C(); arg0->players[0].xC_b5 = 1; } @@ -900,11 +919,9 @@ s32 gm_8017CE34(StartMeleeData* arg0, UnkAdventureData* arg1, s8* arg2, gmRegSetupEnemyColorTable((s8) (u8) arg1->x0.ckind, arg1->x0.color, arg2, colors); - player_offset = player_idx * 0x24; enemy_idx = 0; for (;;) { enemy_kind = &arg2[enemy_idx]; - (void) enemy_kind; if ((s32) (u8) enemy_kind[0] != 0x21) { if (arg1->x0.x8 & 8) { if (arg1->x4C != NULL) { @@ -926,60 +943,53 @@ s32 gm_8017CE34(StartMeleeData* arg0, UnkAdventureData* arg1, s8* arg2, arg1->x50((u8) count, arg1->x0.cpu_level, enemy_idx); } } - { - StartMeleePlayerCursor* player_slot = - (StartMeleePlayerCursor*) ((u8*) arg0 + player_offset); - gm_8016795C(&player_slot->player); - player_slot->player.slot_type = 1; - player_slot->player.c_kind = (s8) (u8) enemy_kind[0]; - player_slot->player.stocks = 1; - player_slot->player.cpu_level = enemy_level; - player_slot->player.xE = enemy_cpu_type; - player_slot->player.x18 = attack_ratio; - player_slot->player.x1C = defense_ratio; - player_slot->player.color = *color_iter; - if (arg1->x0.x8 & 2) { - player_slot->player.x20 = 2.0f; - player_slot->player.xB = 2; - } else { - player_slot->player.x20 = 1.0f; - player_slot->player.xB = 0; - } - if (arg1->x0.x8 & 4) { - player_slot->player.xC_b2 = 1; - player_slot->player.xE = 0x1B; - } - if ((s32) player_slot->player.c_kind == 0x1D) { - player_slot->player.xC_b1 = 0; - } - player_kind = (u8) player_slot->player.c_kind; - if (((s8) player_kind == 0x1A) || ((s8) player_kind == 0x1E)) { - player_slot->player.xC_b7 = 1; - player_slot->player.hp = 0x12C; - player_slot->player.xD_b2 = 1; - player_slot->player.xD_b0 = 1; - player_slot->player.xD_b2 = 1; - player_slot->player.spawn_dir = -1; - if ((s32) player_slot->player.c_kind == 0x1E) { - player_slot->player.slot_type = 3; - } - var_r20 += 1; - } - if ((u8) arg0->rules.is_teams == 1) { - player_slot->player.team = 4; + gm_8016795C(&arg0->players[player_idx]); + arg0->players[player_idx].slot_type = 1; + arg0->players[player_idx].c_kind = (s8) (u8) enemy_kind[0]; + arg0->players[player_idx].stocks = 1; + arg0->players[player_idx].cpu_level = enemy_level; + arg0->players[player_idx].xE = enemy_cpu_type; + arg0->players[player_idx].x18 = attack_ratio; + arg0->players[player_idx].x1C = defense_ratio; + arg0->players[player_idx].color = *color_iter; + if (arg1->x0.x8 & 2) { + arg0->players[player_idx].x20 = 2.0f; + arg0->players[player_idx].xB = 2; + } else { + arg0->players[player_idx].x20 = 1.0f; + arg0->players[player_idx].xB = 0; + } + if (arg1->x0.x8 & 4) { + arg0->players[player_idx].xC_b2 = 1; + arg0->players[player_idx].xE = 0x1B; + } + if ((s32) arg0->players[player_idx].c_kind == 0x1D) { + arg0->players[player_idx].xC_b1 = 0; + } + enemy_ckind = (u8) arg0->players[player_idx].c_kind; + if (((s8) enemy_ckind == 0x1A) || ((s8) enemy_ckind == 0x1E)) { + arg0->players[player_idx].xC_b7 = 1; + arg0->players[player_idx].hp = 0x12C; + arg0->players[player_idx].xD_b2 = 1; + arg0->players[player_idx].xD_b0 = 1; + arg0->players[player_idx].xD_b2 = 1; + arg0->players[player_idx].spawn_dir = -1; + if ((s32) arg0->players[player_idx].c_kind == 0x1E) { + arg0->players[player_idx].slot_type = 3; } + boss_count += 1; + } + if ((u8) arg0->rules.is_teams == 1) { + arg0->players[player_idx].team = 4; } player_idx += 1; - player_offset += 0x24; if (player_idx >= 6) { break; } } else { if (((s32) enemy_idx == 0) && ((s32) enemy_kind[1] == 0x1A)) { - ((StartMeleePlayerCursor*) ((u8*) arg0 + player_offset)) - ->player.slot_type = 3; + arg0->players[player_idx].slot_type = 3; player_idx += 1; - player_offset += 0x24; } } enemy_idx += 1; @@ -996,17 +1006,17 @@ s32 gm_8017CE34(StartMeleeData* arg0, UnkAdventureData* arg1, s8* arg2, } } - var_r3 = arg1->x0.x8; - if (var_r3 & 0x40) { + flags = arg1->x0.x8; + if (flags & 0x40) { arg1->x0.xC.xC = 7; - } else if (var_r3 & 1) { - if ((var_r3 & 8) && (arg3 > 1U)) { + } else if (flags & 1) { + if ((flags & 8) && (arg3 > 1U)) { arg1->x0.xC.xC = 4; } else { arg1->x0.xC.xC = 2; } } - if (var_r20 != 0) { + if (boss_count != 0) { arg0->rules.x1_2 = 1; arg0->rules.x1_3 = 1; arg0->rules.x1_4 = 1; @@ -1019,7 +1029,7 @@ s32 gm_8017CE34(StartMeleeData* arg0, UnkAdventureData* arg1, s8* arg2, if (arg7 == 0x49) { arg1->x0.xC.xC = 8; } - return (s32) var_r3; + return (s32) flags; } bool gm_8017D7AC(MatchExitInfo* arg0, Unk1PData* arg1, u8 arg2) @@ -1092,18 +1102,18 @@ bool gm_8017D7AC(MatchExitInfo* arg0, Unk1PData* arg1, u8 arg2) s32 fn_8017D9C0(u8* arg0, u8* arg1) { - s32 len; - s32 i; + u8* base; u8* p; + s32 i; + s32 j; u8 temp; u8* dst; u8 ch; - s32 var_r0; - s32 var_r0_2; - u8* base; + s32 excluded_idx; + s32 rejected_idx; + s32 len; - base = lbl_803D79F0; - p = base; + p = base = lbl_803D79F0; len = 0; while ((s32) *p != 0x21) { p++; @@ -1111,7 +1121,7 @@ s32 fn_8017D9C0(u8* arg0, u8* arg1) } p = base; - for (i = 0; i < len; i++) { + for (j = 0; j < len; j++) { temp = *p; dst = &base[HSD_Randi(len)]; *p = *dst; @@ -1123,28 +1133,20 @@ s32 fn_8017D9C0(u8* arg0, u8* arg1) for (i = 0; i < len; i++) { if (gm_80164840(*p) != 0) { ch = *p; - if ((s8) ch == (s8) arg0[0]) { - var_r0 = -1; - } else if ((s8) ch == (s8) arg0[1]) { - var_r0 = -1; - } else if ((s8) ch == (s8) arg0[2]) { - var_r0 = -1; - } else if ((s8) ch == (s8) arg0[3]) { - var_r0 = -1; - } else { - var_r0 = 4; - } - if (var_r0 != -1) { - if ((s8) ch == (s8) arg1[0]) { - var_r0_2 = -1; - } else if ((s8) ch == (s8) arg1[1]) { - var_r0_2 = -1; - } else if ((s8) ch == (s8) arg1[2]) { - var_r0_2 = -1; - } else { - var_r0_2 = 3; + for (excluded_idx = 0; excluded_idx < 4; excluded_idx++) { + if ((s8) ch == (s8) arg0[excluded_idx]) { + excluded_idx = -1; + break; + } + } + if (excluded_idx != -1) { + for (rejected_idx = 0; rejected_idx < 3; rejected_idx++) { + if ((s8) ch == (s8) arg1[rejected_idx]) { + rejected_idx = -1; + break; + } } - if (var_r0_2 != -1) { + if (rejected_idx != -1) { return (s32) base[i]; } } @@ -1180,16 +1182,16 @@ s32 gm_8017DB88(void* arg0, u8 arg1, s32 arg2, s32 arg3, u8* arg4, u8 arg5, f32 (*arg10)(s32, s32)) { u8 chars[4]; - s32 count; - s32 i; - u8 val; + s32 val; f32 fval; - count = fn_8017DE54(arg1, arg4); { - RegClearCharEntry* out; u8* p; + RegClearCharEntry* out; + s32 i; + s32 count; + count = fn_8017DE54(arg1, arg4); chars[1] = 0x21; out = arg0; chars[2] = 0x21; @@ -1233,11 +1235,11 @@ s32 gm_8017DB88(void* arg0, u8 arg1, s32 arg2, s32 arg3, u8* arg4, u8 arg5, p++; out++; } + for (; i < 3; i++) { + ((RegClearCharEntry*) arg0)[i].x0 = 0x21; + } + return count; } - for (; i < 3; i++) { - ((RegClearCharEntry*) arg0)[i].x0 = 0x21; - } - return count; } s32 fn_8017DD7C(PlayerInitData* arg0, Unk1PData_x24* arg1, u8 arg2) @@ -1916,6 +1918,13 @@ int fn_8017F294(void) return lbl_80472D28.x104; } +static const char* const gmRegClear_ErrorMessages[] = { + "Error : Cannot open archive file (File Name : %s).", + "Error : gobj don\'t get (gmRegClearAddModel)\n", + "gmregclear.c", + "Error : jobj don\'t get (gmRegClearAddModel)\n", +}; + s32 fn_8017F2A4(HSD_Text** arg0, f32 farg0, f32 farg1) { HSD_Text* text; @@ -2556,6 +2565,40 @@ s32 fn_801803FC(void* arg0) PAD_STACK(4); } +static inline void fn_80180630_CheckArchive(HSD_Archive* archive, void* sp38) +{ + struct lbl_80472D28_t* state = &lbl_80472D28; + state->x48 = archive; + if (sp38 == NULL) { + OSReport("Error : Cannot open archive file (File Name : %s).", + "GmRegClr"); + } +} + +static inline HSD_GObj* fn_80180630_CreateCameraGObj(void) +{ + return GObj_Create(0xEU, 0xEU, 0U); +} + +static inline void* fn_80180630_LoadLightList(struct lbl_80472D28_t* state) +{ + return lb_80011AC4(state->x5C); +} + +static inline void +fn_80180630_CreateLightAndCamera(struct lbl_80472D28_t* state, + HSD_GObj** cam_gobj) +{ + HSD_GObj* light_gobj; + + light_gobj = GObj_Create(0xBU, 3U, 0U); + HSD_GObjObject_80390A70(light_gobj, (u8) HSD_GObj_804D784A, + fn_80180630_LoadLightList(state)); + GObj_SetupGXLink(light_gobj, HSD_GObj_LObjCallback, 0xAU, 0U); + + *cam_gobj = fn_80180630_CreateCameraGObj(); +} + void fn_80180630(int arg0, int arg1, int arg2, bool arg3, lbl_8046B6A0_24C_t* arg4) { @@ -2566,20 +2609,18 @@ void fn_80180630(int arg0, int arg1, int arg2, bool arg3, s32 sp58; void* sp38; HSD_Archive* archive; - HSD_GObj* light_gobj; HSD_GObj* cam_gobj; lbl_8046B6A0_t* temp; s32 total; s32 var_r4; - s32 var_r27; + s32 special_score; s32 var_r3; - u16 var_r28; + u16 coins; u8 mask; u8 var_r0; - u8 operand_pad[8]; - var_r27 = 0; - var_r28 = arg4->x58[0].xE; + special_score = 0; + coins = arg4->x58[0].xE; memzero(state, 0x120); state->xD4 = -1; state->xD8 = 0; @@ -2609,8 +2650,8 @@ void fn_80180630(int arg0, int arg1, int arg2, bool arg3, state->x118 = 1; if ((u8) temp->match_result == OUTCOME_UNK_1P_BONUS_STAGE_END) { grPushOn_80219204(Ground_801C1DD4(), (int*) &sp5C, (int*) &sp58); - var_r27 = sp5C; - var_r28 = (u16) sp58; + special_score = sp5C; + coins = (u16) sp58; state->x108 = 0x1F4; } break; @@ -2619,7 +2660,10 @@ void fn_80180630(int arg0, int arg1, int arg2, bool arg3, break; } - fn_8016F344(gm_8016B774()); + { + struct lbl_8046B6A0_24C_t* tmp = gm_8016B774(); + fn_8016F344(tmp); + } if (state->x11A == 0 && state->x118 == 0 && state->x119 == 0 && (mask = fn_8017F008(), fn_8016F9A8(gm_8016B774(), 0, mask, 0) != 0)) @@ -2645,7 +2689,7 @@ void fn_80180630(int arg0, int arg1, int arg2, bool arg3, state->xE8 = fn_8017F1B8(); } - state->xF0 = state->xDC + (state->xD0 + var_r27 + state->xE8); + state->xF0 = state->xDC + (state->xE8 + state->xD0 + special_score); state->xFC = arg0 + arg1; state->xCC = arg1; @@ -2664,16 +2708,11 @@ void fn_80180630(int arg0, int arg1, int arg2, bool arg3, state->x48 = archive; if (sp38 == NULL) { OSReport("Error : Cannot open archive file (File Name : %s).", - "GmRegClr", archive); + "GmRegClr"); } fn_80168A6C(sp38, &state->x4C, 0); - light_gobj = GObj_Create(0xBU, 3U, 0U); - HSD_GObjObject_80390A70(light_gobj, (u8) HSD_GObj_804D784A, - lb_80011AC4(state->x5C)); - GObj_SetupGXLink(light_gobj, HSD_GObj_LObjCallback, 0xAU, 0U); - - cam_gobj = GObj_Create(0xEU, 0xEU, 0U); + fn_80180630_CreateLightAndCamera(state, &cam_gobj); HSD_GObjObject_80390A70(cam_gobj, HSD_GObj_804D784B, HSD_CObjLoadDesc(state->x60)); GObj_SetupGXLinkMax(cam_gobj, HSD_GObj_803910D8, 8U); @@ -2704,17 +2743,17 @@ void fn_80180630(int arg0, int arg1, int arg2, bool arg3, lb_800138D8(state->x2C, 1); lb_800138CC(state->x2C, fn_8017FE54); - if (gm_8016AE50()->x1_1 && var_r28 != 0) { + if (gm_8016AE50()->x1_1 && coins != 0) { if (state->x118 == 0) { - un_802FF128(0x5A, 0x1AE, (s32) var_r28, 5); + un_802FF128(0x5A, 0x1AE, (s32) coins, 5); } else { - un_802FF128(0x86, 0xC8, (s32) var_r28, 5); + un_802FF128(0x86, 0xC8, (s32) coins, 5); } } - arg4->x58[0].xE = var_r28; + arg4->x58[0].xE = coins; fn_8017F2A4(&state->x84, 264.0f, 211.0f); - PAD_STACK(0x30); + PAD_STACK(0x38); } int fn_80180AC0(void) @@ -2772,75 +2811,82 @@ void fn_80180C60(HSD_GObj* gobj) typedef struct { u8 b76 : 2, b54 : 2, b32 : 2, b10 : 2; } x0_2bits; - HSD_JObj* jobj = gobj->hsd_obj; + typedef struct fn_80180C60_state { + struct lbl_80472E48_t e48; + s32 ec8[4]; + } fn_80180C60_state; + fn_80180C60_state* state = (fn_80180C60_state*) &lbl_80472E48; + s32 d; + s32* max_dist; s32 dist; s32 disp; - s32 d; + HSD_JObj* jobj; u32 b76; - dist = (s32) (0.1f * Ground_801C57F0()); + dist = (s32) (0.1f * Ground_801C57F0(0)); + jobj = gobj->hsd_obj; if (dist < 0) { dist = 0; } - lbl_80472EC8[0] = dist; - b76 = ((u8) lbl_80472E48.x0 >> 6) & 3; + state->ec8[0] = dist; + b76 = ((x0_2bits*) &state->e48.x0)->b76; - if (b76 != 0 && (((u8) lbl_80472E48.x0 >> 4) & 3)) { + if (b76 != 0 && ((x0_2bits*) &state->e48.x0)->b54) { ifTime_HideTimers(); - if (lbl_80472EC8[0] == lbl_80472EC8[1]) { - lbl_80472EC8[3] = lbl_80472EC8[3] + 1; + if (state->ec8[0] == state->ec8[1]) { + state->ec8[3] = state->ec8[3] + 1; } else { - lbl_80472EC8[3] = 0; + state->ec8[3] = 0; } - if (lbl_80472EC8[3] > 0x3C) { - ((x0_2bits*) &lbl_80472E48.x0)->b32 = 1; - if (dist == 0 && !(lbl_80472E48.x0 & 3)) { - ((x0_2bits*) &lbl_80472E48.x0)->b10 = 1; + if (state->ec8[3] > 0x3C) { + ((x0_2bits*) &state->e48.x0)->b32 = 1; + if (dist == 0 && !(state->e48.x0 & 3)) { + ((x0_2bits*) &state->e48.x0)->b10 = 1; } } } else { if (b76 != 0) { ifTime_HideTimers(); - if (lbl_80472EC8[0] == lbl_80472EC8[1]) { - lbl_80472EC8[3] = lbl_80472EC8[3] + 1; + if (state->ec8[0] == state->ec8[1]) { + state->ec8[3] = state->ec8[3] + 1; } else { - lbl_80472EC8[3] = 0; + state->ec8[3] = 0; } - if (lbl_80472EC8[3] > 0x78) { - ((x0_2bits*) &lbl_80472E48.x0)->b32 = 1; - if (!(lbl_80472E48.x0 & 3)) { - ((x0_2bits*) &lbl_80472E48.x0)->b10 = 1; + if (state->ec8[3] > 0x78) { + ((x0_2bits*) &state->e48.x0)->b32 = 1; + if (!(state->e48.x0 & 3)) { + ((x0_2bits*) &state->e48.x0)->b10 = 1; } } } else if (gm_8016AEEC() == 0 && gm_8016AEFC() == 0x3B) { - ((x0_2bits*) &lbl_80472E48.x0)->b76 = 1; + ((x0_2bits*) &state->e48.x0)->b76 = 1; ifTime_HideTimers(); Player_80031790(0); } if (Ground_801C1DC0() != 0) { - if (!(((u8) lbl_80472E48.x0 >> 6) & 3)) { - ((x0_2bits*) &lbl_80472E48.x0)->b76 = 1; + if (!(((u8) state->e48.x0 >> 6) & 3)) { + ((x0_2bits*) &state->e48.x0)->b76 = 1; ifTime_HideTimers(); Player_80031790(0); } - if (!(((u8) lbl_80472E48.x0 >> 4) & 3)) { - ((x0_2bits*) &lbl_80472E48.x0)->b54 = 1; + if (!(((u8) state->e48.x0 >> 4) & 3)) { + ((x0_2bits*) &state->e48.x0)->b54 = 1; Player_80031790(0); } - lbl_80472EC8[3] = 0; + state->ec8[3] = 0; } } - if (!(((u8) lbl_80472E48.x0 >> 2) & 3)) { + if (!(((u8) state->e48.x0 >> 2) & 3)) { HSD_JObjReqAnimAll(jobj, 0.0f); - } else if (lbl_80472E48.x0 & 3) { + } else if (state->e48.x0 & 3) { HSD_JObjSetFlagsAll(jobj, JOBJ_HIDDEN); - } else if (dist > lbl_80472E48.x14[gm_80164024((u8) lbl_80472E48.unk_4)]) { + } else if (dist > state->e48.x14[gm_80164024((u8) state->e48.unk_4)]) { if (lbl_804D65D4 == 0) { lbAudioAx_800237A8(0x9C40, 0x7F, 0x40); lbAudioAx_800237A8(0x144, 0x7F, 0x40); - gm_80167858((s32) (s8) lbl_80472E48.x10, + gm_80167858((s32) (s8) state->e48.x10, (s32) Player_GetNametagSlotID(0), 0xD, 0x5A); lbl_804D65D4 = 1; } @@ -2849,12 +2895,11 @@ void fn_80180C60(HSD_GObj* gobj) JOBJ_HIDDEN); } - if (lbLang_IsSavedLanguageUS() != 0) { - disp = (s32) ((f64) (f32) dist / 0.304788); - } else { - disp = dist; - } - if (disp > 0x1869F) { + d = lbLang_IsSavedLanguageUS() != 0 + ? (s32) ((f64) (f32) dist / 0.304788) + : dist; + disp = d; + if (d > 0x1869F) { disp = 0x1869F; } @@ -2913,9 +2958,10 @@ void fn_80180C60(HSD_GObj* gobj) } HSD_JObjAnimAll(jobj); - lbl_80472EC8[1] = lbl_80472EC8[0]; - if (lbl_80472EC8[0] > lbl_80472EC8[2] + 0xA) { - lbl_80472EC8[2] = lbl_80472EC8[0]; + state->ec8[1] = state->ec8[0]; + max_dist = &state->ec8[2]; + if (state->ec8[0] > *max_dist + 0xA) { + *max_dist = state->ec8[0]; lbAudioAx_80023870(0xBB, 0x7F, 0x40, 0x8A); } } @@ -2927,6 +2973,14 @@ void fn_80181598(void) typedef struct { u8 b76 : 2, b54 : 2, b32 : 2, b10 : 2; } x0_2bits; + typedef struct { + struct lbl_80472E48_t x0; + int x80[4]; + } lbl_80472E48_with_ec8; + lbl_80472E48_with_ec8* state = (lbl_80472E48_with_ec8*) &lbl_80472E48; + s32* unk_4; + s32 val; + s32 idx; u32 mode; PAD_STACK(0x20); @@ -2935,37 +2989,40 @@ void fn_80181598(void) return; } - mode = lbl_80472E48.x0 & 3; + mode = state->x0.x0 & 3; if (mode != 0) { if (mode == 1) { lbAudioAx_800237A8(0xC0, 0x7F, 0x40); lbAudioAx_800237A8(0x148, 0x7F, 0x40); - ((x0_2bits*) &lbl_80472E48.x0)->b10 = 2; + ((x0_2bits*) &state->x0.x0)->b10 = 2; } lbl_804D65D8 += 1; if (lbl_804D65D8 >= 0xF0 || (lbl_804D65D8 > 0x3C && - (HSD_PadCopyStatus[lbl_80472E48.x10].trigger & 0x100))) + (HSD_PadCopyStatus[state->x0.x10].trigger & 0x100))) { gm_8016B328(); return; } } - if (((lbl_80472E48.x0 >> 2) & 3) != 0 && - ((mode = lbl_80472E48.x0 & 3, mode == 0) || mode == 3)) + if (((state->x0.x0 >> 2) & 3) != 0 && + ((mode = state->x0.x0 & 3, mode == 0) || mode == 3)) { - lbl_80472E48.xC += 1; - if (lbl_80472E48.xC > 0x3C && - (lbl_80472E48.xC >= 0xF0 || - (HSD_PadCopyStatus[lbl_80472E48.x10].trigger & 0x100))) + state->x0.xC += 1; + if (state->x0.xC > 0x3C && + (state->x0.xC >= 0xF0 || + (HSD_PadCopyStatus[state->x0.x10].trigger & 0x100))) { - if (lbl_80472EC8[0] > - lbl_80472E48.x14[gm_80164024((u8) lbl_80472E48.unk_4)]) - { - lbl_80472E48.x14[gm_80164024((u8) lbl_80472E48.unk_4)] = - lbl_80472EC8[0]; + unk_4 = &state->x0.unk_4; + idx = gm_80164024((u8) *unk_4); + val = state->x80[0]; + idx = (u8) idx << 2; + state = (lbl_80472E48_with_ec8*) state->x0.x14; + if (val > *(s32*) ((unsigned char*) state + idx)) { + *(s32*) ((unsigned char*) state + + (gm_80164024((u8) *unk_4) << 2)) = val; } gm_8016B328(); } @@ -2982,19 +3039,24 @@ void fn_80181708(void) typedef struct { u8 b76 : 2, b54 : 2, b32 : 2, b10 : 2; } x0_2bits; + typedef struct { + struct lbl_80472E48_t x0; + int x80[4]; + } lbl_80472E48_with_ec8; HSD_JObj* jobj; HSD_GObj* gobj; - - lbl_80472EC8[0] = 0; - lbl_80472EC8[1] = 0; - lbl_80472EC8[2] = 0; - lbl_80472EC8[3] = 0; - ((x0_2bits*) &lbl_80472E48.x0)->b76 = 0; - ((x0_2bits*) &lbl_80472E48.x0)->b54 = 0; - ((x0_2bits*) &lbl_80472E48.x0)->b32 = 0; - ((x0_2bits*) &lbl_80472E48.x0)->b10 = 0; - lbl_80472E48.xC = 0; - lbl_80472E48.x10 = (s8) Player_GetPlayerId(0); + lbl_80472E48_with_ec8* state = (lbl_80472E48_with_ec8*) &lbl_80472E48; + + state->x80[0] = 0; + state->x80[1] = 0; + state->x80[2] = 0; + state->x80[3] = 0; + ((x0_2bits*) &state->x0.x0)->b76 = 0; + ((x0_2bits*) &state->x0.x0)->b54 = 0; + ((x0_2bits*) &state->x0.x0)->b32 = 0; + ((x0_2bits*) &state->x0.x0)->b10 = 0; + state->x0.xC = 0; + state->x0.x10 = (s8) Player_GetPlayerId(0); lbl_804D65D4 = 0; lbl_804D65D8 = 0; @@ -3031,15 +3093,32 @@ void fn_80181708(void) gm_80168F88(); } +/// Archive/symbol name strings owned by this TU at 0x803D8CD8..0x803D8D04. +/// The reference code in gm_80181998 addresses all three strings off the +/// first string's symbol (base+0x0 / base+0xC / base+0x24), so the calls +/// below reference gmRegClear_ArchiveNoContinue (declared in gmregclear.h) +/// plus the fixed offsets of the two strings that follow it in the binary. +/// Two details are load-bearing for the reference encoding: the definitions +/// must FOLLOW this function (defining the data before use makes MWCC anchor +/// at the section base instead of the symbol), and the third argument of the +/// first call must be an integer expression (spelling both +/// "ScInfCnt_scene_models" arguments as the same pointer expression makes +/// MWCC CSE the address into a saved register; the reference recomputes it). void gm_80181998(void) { - lbl_804D65C8 = lbArchive_80016DBC("IfHrNoCn", &lbl_804D65CC, - "ScInfCnt_scene_models", 0); - lbl_804D65C8 = lbArchive_80016DBC("IfHrReco", &lbl_804D65D0, - "ScInfCnt_scene_models", 0); + lbl_804D65C8 = + lbArchive_80016DBC(gmRegClear_ArchiveNoContinue, &lbl_804D65CC, + (u32) gmRegClear_ArchiveNoContinue + 0xC, 0); + lbl_804D65C8 = + lbArchive_80016DBC(gmRegClear_ArchiveNoContinue + 0x24, &lbl_804D65D0, + gmRegClear_ArchiveNoContinue + 0xC, 0); fn_80181708(); } +char gmRegClear_ArchiveNoContinue[] = "IfHrNoCn"; +char gmRegClear_SceneModelsSymbol[] = "ScInfCnt_scene_models"; +char gmRegClear_ArchiveRecord[] = "IfHrReco"; + void gm_80181A00(s32 arg0, s32 arg1) { lbl_80472E48.unk_4 = arg0; @@ -3175,27 +3254,36 @@ int fn_80181BFC(int* arg0) } #pragma dont_inline reset +static inline s32 fn_80181C80_CountPlayers(volatile s32* out) +{ + s32 i; + s32 count = 0; + + for (i = 1; i < 6; i++) { + if (Player_GetFalls(i) == 0 && + Player_GetPlayerSlotType(i) != Gm_PKind_NA) + { + count++; + } else { + *out = i; + } + } + return count; +} + s32 fn_80181C80(s32 arg0) { lbl_80472ED8_t* data = &lbl_80472ED8; - s32 var_r29; - s32 var_r30; + s32 count; volatile s32 sp38; volatile s32 sp3C; PlayerInitData sp10; gm_801A4310(); - for (var_r29 = 1, var_r30 = 0, sp10 = data->xC; var_r29 < 6; var_r29++) { - if (Player_GetFalls(var_r29) == 0 && - Player_GetPlayerSlotType(var_r29) != Gm_PKind_NA) - { - var_r30++; - } else { - sp38 = var_r29; - } - } + sp10 = data->xC; + count = fn_80181C80_CountPlayers(&sp38); - if ((s32) data->x54[arg0].x4 > var_r30 && data->x8 > 0x5A) { + if ((data->x54 + arg0)->x4 > count && data->x8 > 0x5A) { if (Player_GetPlayerSlotType(sp38) != Gm_PKind_NA) { Player_SetFalls(sp38, 0); Player_SetSuicideCount(sp38, 0); @@ -3211,19 +3299,21 @@ s32 fn_80181C80(s32 arg0) gm_8016EDDC(sp38, &sp10); Player_SetNametagSlotID(sp38, 0x78); un_802FD28C(sp38); - data->x0 += 1; + return data->x0++; } - PAD_STACK(4); +} + +static inline s32 fn_80181E18_ComputeRemaining100(s32 count) +{ + return 0x64 - (count + lbl_80472ED8.x4); } void fn_80181E18(void) { s32 mode; - s32 var_r29; - s32 next; - s32 temp; - s32 count; s32 i; + s32 next; + s32 entry_idx; mode = gm_801A4310(); @@ -3231,59 +3321,64 @@ void fn_80181E18(void) lbl_80472ED8.x8 += 1; } - if (mode < 0x25) { - if (mode < 0x23) { - if (mode < 0x21) { - } else { - Player_GetFalls(0); - } - } else if (gm_8016AEEC() == 0 && gm_8016AEFC() == 0x3B) { - lbl_80472ED8.x6BC = 1; + switch (mode) { + case 0x21: + case 0x22: + Player_GetFalls(0); + break; + case 0x23: + case 0x24: + if (gm_8016AEEC() == 0 && gm_8016AEFC() == 0x3B) { + lbl_80473594.x0 = 1; gm_8016B33C(7); gm_8016B328(); } - } else if (mode < 0x27) { + break; + case 0x25: + case 0x26: if (Player_GetFalls(0) != 0) { gm_8016B33C(5); gm_8016B328(); } + break; } - for (var_r29 = 0; var_r29 < 101; var_r29++) { - if (lbl_80472ED8.x54[var_r29].x0 == -2) { + for (entry_idx = 0; entry_idx < 101; entry_idx++) { + s32 temp; + if (lbl_80472ED8.x54[entry_idx].x0 == -2) { continue; } - if (lbl_80472ED8.x6C4 < 0x23) { - if (lbl_80472ED8.x6C4 < 0x21) { - } else { - lbl_80472ED8.x6C0 = gm_8016AEDC(); - } + switch (lbl_80473594.x8) { + case 0x21: + case 0x22: + lbl_80473594.x4 = gm_8016AEDC(); + break; } - temp = var_r29 - fn_80181BFC(NULL); + temp = entry_idx - fn_80181BFC(NULL); if (temp < 0) { temp = 0; } - lbl_80472ED8.x6BE = (s16) (temp + lbl_80472ED8.x4); + lbl_80473594.x2 = (s16) (temp + lbl_80472ED8.x4); switch (mode) { case 0x21: - temp = var_r29 - fn_80181BFC(NULL); + temp = entry_idx - fn_80181BFC(NULL); if (temp < 0) { temp = 0; } ifStock_802FA2D0(0xA - (temp + lbl_80472ED8.x4)); break; case 0x22: - temp = var_r29 - fn_80181BFC(NULL); + temp = entry_idx - fn_80181BFC(NULL); if (temp < 0) { temp = 0; } - ifStock_802FA2D0(0x64 - (temp + lbl_80472ED8.x4)); + ifStock_802FA2D0(fn_80181E18_ComputeRemaining100(temp)); break; default: - temp = var_r29 - fn_80181BFC(NULL); + temp = entry_idx - fn_80181BFC(NULL); if (temp < 0) { temp = 0; } @@ -3291,14 +3386,15 @@ void fn_80181E18(void) break; } - next = lbl_80472ED8.x54[var_r29].x0; + next = lbl_80472ED8.x54[entry_idx].x0; if (next == -1) { - fn_80181C80(var_r29); + fn_80181C80(entry_idx); return; } if (next == 0x3E7) { + s32 count; count = 0; for (i = 1; i < 6; i++) { if (Player_GetFalls(i) == 0 && @@ -3308,20 +3404,18 @@ void fn_80181E18(void) } } if (count == 0) { - lbl_80472ED8.x6BC = 1; + lbl_80473594.x0 = 1; gm_8016B33C(7); gm_8016B328(); } } else { - if (next < var_r29) { - s32 k; - for (k = next; k < var_r29; k++) { - lbl_80472ED8.x54[k].x0 = -1; - lbl_80472ED8.x4 += 1; - } + s32 k; + for (k = next; k < entry_idx; k++) { + lbl_80472ED8.x54[k].x0 = -1; + lbl_80472ED8.x4 += 1; } - fn_80181C80(lbl_80472ED8.x54[var_r29].x0); - temp = var_r29 - fn_80181BFC(NULL); + fn_80181C80(lbl_80472ED8.x54[entry_idx].x0); + temp = entry_idx - fn_80181BFC(NULL); if (temp < 0) { temp = 0; } @@ -3343,7 +3437,11 @@ void gm_80182174(void) RegClearSpawnEntry** spawn_table_25; RegClearSpawnEntry** spawn_table_26; s32 mode; + const void* raw; + const char* base; + raw = lbl_803D8D08; + base = raw; mode = gm_801A4310(); spawn_table_25 = &lbl_80472ED8.x6B4; spawn_table_22 = &lbl_80472ED8.x6A8; @@ -3352,11 +3450,11 @@ void gm_80182174(void) spawn_table_24 = &lbl_80472ED8.x6B0; lbArchive_80016DBC( - "GmKumite.dat", &lbl_80472ED8.x6A4, "gmKumiteSystemTable10man", - spawn_table_22, "gmKumiteSystemTable100man", spawn_table_23, - "gmKumiteSystemTable10min", spawn_table_24, "gmKumiteSystemTable60min", - spawn_table_25, "gmKumiteSystemTableEndless", spawn_table_26, - "gmKumiteSystemTableMercilessly", 0); + base + 0x480, &lbl_80472ED8.x6A4, base + 0x490, + spawn_table_22, base + 0x4AC, spawn_table_23, + base + 0x4C8, spawn_table_24, base + 0x4E4, + spawn_table_25, base + 0x500, spawn_table_26, + base + 0x51C, 0); lbl_80472ED8.x0 = 0; lbl_80472ED8.x4 = 0; @@ -3485,7 +3583,6 @@ void gm_80182174(void) HSD_GObj_SetupProc(GObj_Create(0xFU, 0x11U, 0U), (HSD_GObjEvent) fn_80181E18, 0x15U); gm_80168F88(); - PAD_STACK(8); } bool gm_80182510(void) @@ -3502,13 +3599,28 @@ bool gm_80182510(void) return false; } +/// Original addresses these fields relative to #lbl_80472ED8 (reference +/// relocations are lbl_80472ED8+0x6BC..+0x6C8): lbl_80473594 overlays +/// lbl_80472ED8+0x6BC (0x80472ED8 + 0x6BC == 0x80473594), and gm_80182578 +/// below already reads the same storage via lbl_80472ED8.x6BC..x6C8. void gm_80182554(int arg0, int arg1) { - lbl_80473594.xC = arg0; - lbl_80473594.x8 = arg1; - lbl_80473594.x0 = 0; - lbl_80473594.x4 = 0; - lbl_80473594.x2 = 0; + typedef struct { + u8 pad_0[0x6BC]; + u8 x6BC; + u8 pad_6BD; + u16 x6BE; + int x6C0; + int x6C4; + int x6C8; + } regclear_record_state; + regclear_record_state* s = (regclear_record_state*) &lbl_80472ED8; + + s->x6C8 = arg0; + s->x6C4 = arg1; + s->x6BC = 0; + s->x6C0 = 0; + s->x6BE = 0; } typedef struct { @@ -3517,6 +3629,11 @@ typedef struct { /* 0x88 */ u16 times[28]; } RecordBlock; /* 0xC0 */ +static inline u16 gm_80182578_GetTime(void) +{ + return lbl_80472ED8.x6BE; +} + s32 gm_80182578(void) { RecordBlock* blocks = (RecordBlock*) lbl_803D8D08; @@ -3573,115 +3690,114 @@ s32 gm_80182578(void) break; } - if (mode < 0x25) { - if (mode < 0x23) { - if (mode < 0x21) { - return mode; - } - if (mode == 0x21) { - mode = gmMainLib_8015D6BC(gm_80164024((u8) idx)); - } else { - mode = gmMainLib_8015D710(gm_80164024((u8) idx)); - } - if ((u8) lbl_80472ED8.x6BC != 0) { - u32 score_store = (u32) lbl_80472ED8.x6C0; - if (score_store < score_val) { - int m = lbl_80472ED8.x6C4; - int i = lbl_80472ED8.x6C8; - switch (m) { - case 33: - blocks[0].icons[i] = (u8) lbl_80472ED8.x6BC; - break; - case 34: - blocks[1].icons[i] = (u8) lbl_80472ED8.x6BC; - break; - case 35: - blocks[2].icons[i] = (u8) lbl_80472ED8.x6BC; - break; - case 36: - blocks[3].icons[i] = (u8) lbl_80472ED8.x6BC; - break; - case 37: - blocks[4].icons[i] = (u8) lbl_80472ED8.x6BC; - break; - case 38: - blocks[5].icons[i] = (u8) lbl_80472ED8.x6BC; - break; - } - switch (m) { - case 33: - blocks[0].scores[i] = score_store; - break; - case 34: - blocks[1].scores[i] = score_store; - break; - case 35: - blocks[2].scores[i] = score_store; - break; - case 36: - blocks[3].scores[i] = score_store; - break; - case 37: - blocks[4].scores[i] = score_store; - break; - case 38: - blocks[5].scores[i] = score_store; - break; - } - { - u16 time_store = lbl_80472ED8.x6BE; - switch (m) { - case 33: - blocks[0].times[i] = time_store; - break; - case 34: - blocks[1].times[i] = time_store; - break; - case 35: - blocks[2].times[i] = time_store; - break; - case 36: - blocks[3].times[i] = time_store; - break; - case 37: - blocks[4].times[i] = time_store; - break; - case 38: - blocks[5].times[i] = time_store; - break; - } - } - } - return mode; - } - if ((s32) lbl_80472ED8.x6BE > (s32) time_val && mode == 0) { + switch (mode) { + case 0x21: + case 0x22: + if (mode == 0x21) { + mode = gmMainLib_8015D6BC(gm_80164024((u8) idx)); + } else { + mode = gmMainLib_8015D710(gm_80164024((u8) idx)); + } + if ((u8) lbl_80472ED8.x6BC != 0) { + u32 score_store = (u32) lbl_80472ED8.x6C0; + if (score_store < score_val) { int m = lbl_80472ED8.x6C4; int i = lbl_80472ED8.x6C8; switch (m) { case 33: - blocks[0].times[i] = (u16) lbl_80472ED8.x6BE; + blocks[0].icons[i] = (u8) lbl_80472ED8.x6BC; break; case 34: - blocks[1].times[i] = (u16) lbl_80472ED8.x6BE; + blocks[1].icons[i] = (u8) lbl_80472ED8.x6BC; break; case 35: - blocks[2].times[i] = (u16) lbl_80472ED8.x6BE; + blocks[2].icons[i] = (u8) lbl_80472ED8.x6BC; break; case 36: - blocks[3].times[i] = (u16) lbl_80472ED8.x6BE; + blocks[3].icons[i] = (u8) lbl_80472ED8.x6BC; break; case 37: - blocks[4].times[i] = (u16) lbl_80472ED8.x6BE; + blocks[4].icons[i] = (u8) lbl_80472ED8.x6BC; break; case 38: - blocks[5].times[i] = (u16) lbl_80472ED8.x6BE; + blocks[5].icons[i] = (u8) lbl_80472ED8.x6BC; + break; + } + switch (m) { + case 33: + blocks[0].scores[i] = score_store; + break; + case 34: + blocks[1].scores[i] = score_store; + break; + case 35: + blocks[2].scores[i] = score_store; + break; + case 36: + blocks[3].scores[i] = score_store; break; + case 37: + blocks[4].scores[i] = score_store; + break; + case 38: + blocks[5].scores[i] = score_store; + break; + } + { + u16 time_store = lbl_80472ED8.x6BE; + switch (m) { + case 33: + blocks[0].times[i] = time_store; + break; + case 34: + blocks[1].times[i] = time_store; + break; + case 35: + blocks[2].times[i] = time_store; + break; + case 36: + blocks[3].times[i] = time_store; + break; + case 37: + blocks[4].times[i] = time_store; + break; + case 38: + blocks[5].times[i] = time_store; + break; + } } } return mode; } + if ((s32) lbl_80472ED8.x6BE > (s32) time_val && mode == 0) { + int m = lbl_80472ED8.x6C4; + int i = lbl_80472ED8.x6C8; + switch (m) { + case 33: + blocks[0].times[i] = (u16) lbl_80472ED8.x6BE; + break; + case 34: + blocks[1].times[i] = (u16) lbl_80472ED8.x6BE; + break; + case 35: + blocks[2].times[i] = (u16) lbl_80472ED8.x6BE; + break; + case 36: + blocks[3].times[i] = (u16) lbl_80472ED8.x6BE; + break; + case 37: + blocks[4].times[i] = (u16) lbl_80472ED8.x6BE; + break; + case 38: + blocks[5].times[i] = (u16) lbl_80472ED8.x6BE; + break; + } + } + break; + case 0x23: + case 0x24: if ((u8) lbl_80472ED8.x6BC != 0) { - u16 time_store = lbl_80472ED8.x6BE; + u16 time_store = gm_80182578_GetTime(); if ((s32) time_store > (s32) time_val) { switch (mode) { case 33: @@ -3725,8 +3841,9 @@ s32 gm_80182578(void) } } } - return mode; - } else if (mode < 0x27) { + break; + case 0x25: + case 0x26: if ((s32) lbl_80472ED8.x6BE > (s32) time_val) { switch (mode) { case 33: @@ -3749,8 +3866,9 @@ s32 gm_80182578(void) break; } } - return mode; + break; } + return mode; PAD_STACK(0x48); } @@ -3760,9 +3878,8 @@ static inline RecordBlock* fn_80182B5C_GetRecordBlocks(void) return (RecordBlock*) lbl_803D8D08; } -static inline u32 fn_80182B5C_GetScore(void) +static inline u32 fn_80182B5C_GetScore(RecordBlock* blocks) { - RecordBlock* blocks = (RecordBlock*) lbl_803D8D08; int idx = lbl_80472ED8.x6C8; int mode = lbl_80472ED8.x6C4; @@ -3784,9 +3901,8 @@ static inline u32 fn_80182B5C_GetScore(void) } } -static inline int fn_80182B5C_GetTime(void) +static inline int fn_80182B5C_GetTime(RecordBlock* blocks) { - RecordBlock* blocks = fn_80182B5C_GetRecordBlocks(); int idx = lbl_80472ED8.x6C8; int mode = lbl_80472ED8.x6C4; @@ -3811,48 +3927,46 @@ static inline int fn_80182B5C_GetTime(void) void fn_80182B5C(void) { RecordBlock* blocks = fn_80182B5C_GetRecordBlocks(); - int var_r6; + int time; int idx = lbl_80472ED8.x6C8; - u32 var_r30; + u32 score; int mode = lbl_80472ED8.x6C4; - var_r6 = fn_80182B5C_GetTime(); - - var_r30 = fn_80182B5C_GetScore(); + time = fn_80182B5C_GetTime(blocks); + score = fn_80182B5C_GetScore(blocks); switch (mode) { - case 33: - gmMainLib_8015D6BC(gm_80164024((u8) idx)); - goto func; - case 34: - gmMainLib_8015D710(gm_80164024((u8) idx)); - func: + case 0x21: + case 0x22: + if (mode == 0x21) { + gmMainLib_8015D6BC(gm_80164024((u8) idx)); + } else { + gmMainLib_8015D710(gm_80164024((u8) idx)); + } if (lbl_80472ED8.x6BC != 0) { - if ((u32) lbl_80472ED8.x6C0 < var_r30) { + if ((u32) lbl_80472ED8.x6C0 < score) { gm_8016B350(0x9C40); gm_8016B364(0x144); gm_80167858((s32) lbl_80472ED8.x6CC, (s32) lbl_80472ED8.x6CD, 0xD, 0x5A); - return; } } else { gm_8016B364(0x148); gm_8016B378(0x28); - return; } break; - case 35: - case 36: - if (lbl_80472ED8.x6BC != 0 && (s32) lbl_80472ED8.x6BE > var_r6) { + case 0x23: + case 0x24: + if (lbl_80472ED8.x6BC != 0 && (s32) lbl_80472ED8.x6BE > time) { gm_8016B350(0x9C40); gm_8016B364(0x144); gm_80167858((s32) lbl_80472ED8.x6CC, (s32) lbl_80472ED8.x6CD, 0xD, 0x5A); } break; - case 37: - case 38: - if ((s32) lbl_80472ED8.x6BE > var_r6) { + case 0x25: + case 0x26: + if ((s32) lbl_80472ED8.x6BE > time) { gm_8016B350(0x9C40); gm_8016B364(0x144); gm_80167858((s32) lbl_80472ED8.x6CC, (s32) lbl_80472ED8.x6CD, 0xD, @@ -3860,7 +3974,6 @@ void fn_80182B5C(void) } break; } - PAD_STACK(24); } static UnkMultimanData lbl_804D65E0; diff --git a/src/melee/gm/gmregclear.h b/src/melee/gm/gmregclear.h index b4d447c860..f1436a2b93 100644 --- a/src/melee/gm/gmregclear.h +++ b/src/melee/gm/gmregclear.h @@ -10,6 +10,8 @@ #include #include +/* 3D8CD8 */ extern char gmRegClear_ArchiveNoContinue[]; + /* 17C0C8 */ void fn_8017C0C8(void); /* 17C1A4 */ void fn_8017C1A4(HSD_GObj*); /* 17C71C */ void fn_8017C71C(void); diff --git a/src/melee/gm/gmregenddisp.c b/src/melee/gm/gmregenddisp.c index 1349632f3e..41e9be3417 100644 --- a/src/melee/gm/gmregenddisp.c +++ b/src/melee/gm/gmregenddisp.c @@ -262,6 +262,21 @@ void gm_801A8D54(s32* arg0) } } +static inline s32 gm_801A9094_get_entry(s32* entries, s32 i) +{ + return entries[i]; +} + +static inline HSD_Joint* gm_801A9094_get_bg(void) +{ + return HSD_ArchiveGetPublicAddress(gm_804D679C, "ToyDspStand_Top_joint"); +} + +static inline HSD_GObj* gm_801A9094_create_gobj(void) +{ + return GObj_Create(0xE, 0xF, 0); +} + void gm_801A9094(void) { s32 sp8C[0x1A]; @@ -279,15 +294,14 @@ void gm_801A9094(void) i = 0x19; do { if (sp8C[i] != 0x1A) { - dsp = tyDisplay_8031B9DC(gm_801A659C(sp8C[i])); + dsp = tyDisplay_8031B9DC( + gm_801A659C(gm_801A9094_get_entry(sp8C, i))); joint = HSD_ArchiveGetPublicAddress( gm_804D679C, (const char*) tyDisplay_8031BB34((s8) dsp->x04)); matanim = HSD_ArchiveGetPublicAddress( gm_804D679C, tyDisplay_8031BB94((s8) dsp->x04)); - bg_joint = HSD_ArchiveGetPublicAddress(gm_804D679C, - "ToyDspStand_Top_joint"); - gobj = GObj_Create(0xE, 0xF, 0); - gm_80480A00[sp8C[i]] = gobj; + bg_joint = gm_801A9094_get_bg(); + gm_80480A00[sp8C[i]] = gobj = gm_801A9094_create_gobj(); root = HSD_JObjAlloc(); HSD_GObjObject_80390A70(gobj, HSD_GObj_804D7849, root); GObj_SetupGXLink(gobj, HSD_GObj_JObjCallback, 0xB, 0); @@ -361,17 +375,9 @@ void gm_801A8114_inline(HSD_JObj* arg0, int arg1) gm_801A8114(arg0, arg1); } -void gm_801A9630(void) +static inline void gm_801A9630_init(void) { int i; - HSD_CObj* cobj; - HSD_Fog* fog; - HSD_GObj* cam_gobj; - HSD_GObj* gobj; - HSD_JObj* jobj; - HSD_JObj* child; - HSD_JObj* target; - HSD_LObj* lobj; PAD_STACK(8); for (i = 0; i < 0x1A; i++) { @@ -388,8 +394,13 @@ void gm_801A9630(void) gm_80480AD0[i] = 0; } } +} + +static inline void gm_801A9630_fog(void) +{ + HSD_GObj* gobj; + HSD_Fog* fog; - // Fog GObj gobj = GObj_Create(0xE, 3, 0); fog = HSD_FogLoadDesc(gm_804D67A4->fogs->desc); HSD_GObjObject_80390A70(gobj, (u8) HSD_GObj_804D7848, fog); @@ -398,8 +409,13 @@ void gm_801A9630(void) HSD_FogReqAnim(fog, 0.0f); HSD_FogInterpretAnim(fog); HSD_GObj_SetupProc(gobj, fn_801A7FB4, 0x17); +} + +static inline void gm_801A9630_light(void) +{ + HSD_GObj* gobj; + HSD_LObj* lobj; - // Light GObj gobj = GObj_Create(0xB, 3, 0); lobj = lb_80011AC4(gm_804D67A4->lights); HSD_GObjObject_80390A70(gobj, (u8) HSD_GObj_804D784A, lobj); @@ -408,6 +424,25 @@ void gm_801A9630(void) HSD_LObjReqAnimAll(lobj, 0.0f); HSD_LObjAnimAll(lobj); HSD_GObj_SetupProc(gobj, fn_801A80CC, 0x17); +} + +void gm_801A9630(void) +{ + int i; + HSD_CObj* cobj; + HSD_GObj* cam_gobj; + HSD_GObj* gobj; + HSD_JObj* jobj; + HSD_JObj* child; + HSD_JObj* target; + + gm_801A9630_init(); + + // Fog GObj + gm_801A9630_fog(); + + // Light GObj + gm_801A9630_light(); // Camera GObj cam_gobj = GObj_Create(0x13, 0x14, 0); @@ -436,7 +471,10 @@ void gm_801A9630(void) // Background JObj GObj 2 gobj = GObj_Create(0xE, 0xF, 0); gm_804D67BC = gobj; - jobj = HSD_JObjLoadJoint(gm_804D67AC->models[0]->joint); + { + HSD_JObj* tmp = HSD_JObjLoadJoint(gm_804D67AC->models[0]->joint); + jobj = tmp; + } HSD_GObjObject_80390A70(gobj, HSD_GObj_804D7849, jobj); GObj_SetupGXLink(gobj, HSD_GObj_JObjCallback, 0xB, 0); gm_8016895C(jobj, gm_804D67A4->models[0], 0); @@ -469,150 +507,3 @@ void gm_801A9630(void) lb_8000C290(jobj, target); HSD_GObj_SetupProc(gobj, fn_801A80F0, 0x17); } - -static u8 gm_804D67C8; -static u8 gm_804D67C9; - -char* gm_803DB8B8[] = { - "GmRegendSimpleCaptain.thp", "GmRegendSimpleDonkey.thp", - "GmRegendSimpleFox.thp", "GmRegendSimpleGamewatch.thp", - "GmRegendSimpleKirby.thp", "GmRegendSimpleKoopa.thp", - "GmRegendSimpleLink.thp", "GmRegendSimpleLuigi.thp", - "GmRegendSimpleMario.thp", "GmRegendSimpleMarth.thp", - "GmRegendSimpleMewtwo.thp", "GmRegendSimpleNess.thp", - "GmRegendSimplePeach.thp", "GmRegendSimplePikachu.thp", - "GmRegendSimplePoponana.thp", "GmRegendSimplePurin.thp", - "GmRegendSimpleSamus.thp", "GmRegendSimpleYoshi.thp", - "GmRegendSimpleZeldaseak.thp", "GmRegendSimpleZeldaseak.thp", - "GmRegendSimpleFalco.thp", "GmRegendSimpleClink.thp", - "GmRegendSimpleDrmario.thp", "GmRegendSimpleRoy.thp", - "GmRegendSimplePichu.thp", "GmRegendSimpleGanon.thp", -}; - -char* gm_803DBBF4[] = { - "GmRegendAdventureCaptain.thp", "GmRegendAdventureDonkey.thp", - "GmRegendAdventureFox.thp", "GmRegendAdventureGamewatch.thp", - "GmRegendAdventureKirby.thp", "GmRegendAdventureKoopa.thp", - "GmRegendAdventureLink.thp", "GmRegendAdventureLuigi.thp", - "GmRegendAdventureMario.thp", "GmRegendAdventureMarth.thp", - "GmRegendAdventureMewtwo.thp", "GmRegendAdventureNess.thp", - "GmRegendAdventurePeach.thp", "GmRegendAdventurePikachu.thp", - "GmRegendAdventurePoponana.thp", "GmRegendAdventurePurin.thp", - "GmRegendAdventureSamus.thp", "GmRegendAdventureYoshi.thp", - "GmRegendAdventureZeldaseak.thp", "GmRegendAdventureZeldaseak.thp", - "GmRegendAdventureFalco.thp", "GmRegendAdventureClink.thp", - "GmRegendAdventureDrmario.thp", "GmRegendAdventureRoy.thp", - "GmRegendAdventurePichu.thp", "GmRegendAdventureGanon.thp", -}; - -char* gm_803DBF10[] = { - "GmRegendAllstarCaptain.thp", "GmRegendAllstarDonkey.thp", - "GmRegendAllstarFox.thp", "GmRegendAllstarGamewatch.thp", - "GmRegendAllstarKirby.thp", "GmRegendAllstarKoopa.thp", - "GmRegendAllstarLink.thp", "GmRegendAllstarLuigi.thp", - "GmRegendAllstarMario.thp", "GmRegendAllstarMarth.thp", - "GmRegendAllstarMewtwo.thp", "GmRegendAllstarNess.thp", - "GmRegendAllstarPeach.thp", "GmRegendAllstarPikachu.thp", - "GmRegendAllstarPoponana.thp", "GmRegendAllstarPurin.thp", - "GmRegendAllstarSamus.thp", "GmRegendAllstarYoshi.thp", - "GmRegendAllstarZeldaseak.thp", "GmRegendAllstarZeldaseak.thp", - "GmRegendAllstarFalco.thp", "GmRegendAllstarClink.thp", - "GmRegendAllstarDrmario.thp", "GmRegendAllstarRoy.thp", - "GmRegendAllstarPichu.thp", "GmRegendAllstarGanon.thp", -}; - -void gm_801A9B30_OnEnter(UNK_T unused) -{ - struct { - int x0; - int x4; - int x8; - int xC; - float x10; - float x14; - u8 pad[0x40 - 0x18]; - u32 x40; - }* temp_r3_3; - s32 temp_r31; - HSD_GObj* gobj; - HSD_GObj* temp_r29; - const char* thpfile; - s32 var_r3_3; - int var_r3; - - gm_804D67C8 = 0x1E; - gm_804D67C9 = 0; - temp_r29 = GObj_Create(0x13, 0x14, 0); - HSD_SObjLib_803A55DC(temp_r29, 0x280, 0x1E0, 8); - temp_r29->gxlink_prios = 0x800; - lbAudioAx_80026F2C(0x12); - lbAudioAx_8002702C(2, 0x10); - lbAudioAx_80027168(); - lbAudioAx_80027648(); - lbBgFlash_800209F4(); - gobj = GObj_Create(0xE, 0xF, 0); - HSD_GObjObject_80390A70(gobj, HSD_SObjLib_804D7960, NULL); - GObj_SetupGXLink(gobj, lbMthp8001F928, 0xB, 0); - temp_r31 = gm_801BEFB0(); - var_r3 = gm_801A4310(); - if (var_r3 == GM_DEBUG_GOVER) { - var_r3 = gm_801BF050(); - } - switch (var_r3) { - case GM_CLASSIC_GOVER: - thpfile = gm_803DB8B8[temp_r31]; - break; - case GM_ADVENTURE_GOVER: - thpfile = gm_803DBBF4[temp_r31]; - break; - default: - thpfile = gm_803DBF10[temp_r31]; - break; - } - lbMthp8001FAA0(thpfile, 0x230, 0x1A0); - temp_r3_3 = lbMthp8001F890(gobj); - temp_r3_3->x10 = 320.0F; - temp_r3_3->x14 = 240.0F; - temp_r3_3->x40 |= 2; - switch (gm_801A4310()) { - case GM_CLASSIC_GOVER: - var_r3_3 = gm_8017DFF4(1); - break; - case GM_ADVENTURE_GOVER: - var_r3_3 = gm_8017DFF4(0); - break; - default: - var_r3_3 = gm_8017DFF4(2); - break; - } - if (var_r3_3 == 4) { - lbAudioAx_800237A8(0x9C45, 0x7F, 0x40); - } else { - lbAudioAx_800237A8(0x9C41, 0x7F, 0x40); - } -} - -void gm_801A9D0C_OnFrame(void) -{ - if (gm_804D67C8 != 0) { - gm_804D67C8--; - } else if (gm_804D67C9 != 0) { - gm_804D67C9--; - if (gm_804D67C9 == 0) { - if (gm_801A4310() == GM_DEBUG_GOVER) { - gm_801A6630(6); - } else { - gm_801A6630(1); - } - } - } else { - if (gm_GetButtonsTriggered(gm_801BF010()) & - (PAD_BUTTON_A | PAD_BUTTON_START)) - { - lbBgFlash_8002063C(0x3C); - gm_804D67C9 = 0x3C; - lbAudioAx_80023694(); - lbAudioAx_80024030(1); - } - } -} diff --git a/src/melee/gm/gmregtyfall.c b/src/melee/gm/gmregtyfall.c index 5b333d6e24..b1f97e6793 100644 --- a/src/melee/gm/gmregtyfall.c +++ b/src/melee/gm/gmregtyfall.c @@ -396,6 +396,16 @@ void gm_801A6EE4(void) } } +static inline void gm_801A7070_InitTextures(void) +{ + int i; + + for (i = 0; i < 2; i++) { + gm_804809D0[i].image_ptr = NULL; + lb_800121FC(&gm_804809D0[i], 0x1EA, 0x1E0, 5, 0); + } +} + void gm_801A7070_OnEnter(void* unused) { s32 temp_r29; @@ -422,7 +432,6 @@ void gm_801A7070_OnEnter(void* unused) f32 temp_f31_8; HSD_JObj* temp_r3_8; - int i; HSD_GObj* gobj; HSD_LObj* lobj; PAD_STACK(108); @@ -467,10 +476,7 @@ void gm_801A7070_OnEnter(void* unused) GObj_SetupGXLinkMax(temp_r27_3, HSD_SObjLib_803A54EC, 9); temp_r27_3->gxlink_prios = 0x200; - for (i = 0; i < 2; i++) { - gm_804809D0[i].image_ptr = NULL; - lb_800121FC(&gm_804809D0[i], 0x1EA, 0x1E0, 5, 0); - } + gm_801A7070_InitTextures(); temp_r3 = GObj_Create(0xE, 0xD, 0); gm_804D677C = temp_r3; diff --git a/src/melee/gm/gmresult.c b/src/melee/gm/gmresult.c index 3447023e75..68530cae83 100644 --- a/src/melee/gm/gmresult.c +++ b/src/melee/gm/gmresult.c @@ -1,6 +1,28 @@ +#define fn_80174468(a, b, c, d, e, f) \ + fn_80174468(s32 slot, HSD_Text* text1, HSD_Text* text2, HSD_Text* text3, \ + struct StatsList* list, s32 entry_idx) #include "gmresult.h" +#undef fn_80174468 -#include "gm/gmresult.static.h" +#include "gm/types.h" + +#define GMRESULT_CAT(a, b) a##b +#define GMRESULT_LBL(addr) GMRESULT_CAT(lbl_, addr) +#define GMRESULT_STATIC_OBJECT(type, name) static type name +#define GMRESULT_STATIC_U32_PAIR(name, a, b) static u32 name[2] = { a, b } +#define GMRESULT_GLOBAL_U32(name, value) u32 name = value +#define GMRESULT_STATIC_STR(name, value) static char name[] = value +#define GMRESULT_STATS_TABLE(name) static StatsEntry name[] + +GMRESULT_STATIC_OBJECT(struct ResultsData, GMRESULT_LBL(8046DBE8)); +GMRESULT_STATIC_U32_PAIR(GMRESULT_LBL(804D3F8C), 0x817C817C, 0x817C0000); +GMRESULT_GLOBAL_U32(GMRESULT_LBL(804D3FA0), 0x817C0000); +GMRESULT_GLOBAL_U32(GMRESULT_LBL(804D3FA4), 0x817B0000); +union { + u32 words[2]; + char text[8]; +} GMRESULT_LBL(804D3FA8) = { { 0x817C8146, 0x817C0000 } }; +GMRESULT_STATIC_STR(GMRESULT_LBL(804D3FB0), "0"); #include "gm_unsplit.h" #include "gmresultplayer.h" @@ -92,8 +114,8 @@ typedef struct StatsEntry { /* 0x00 */ s16 value; /* 0x02 */ u8 pad_2[2]; /* 0x04 */ s32 (*check)(s32); - /* 0x08 */ u32 (*get)(s32); - /* 0x0C */ u8 pad_C[4]; + /* 0x08 */ const char* (*get)(int); + /* 0x0C */ void* xC; } StatsEntry; typedef struct StatsList { @@ -225,12 +247,10 @@ static s32 find_nth_nonzero(u8* arr, s32 n) return i; } -void fn_80174468(u8 slot, HSD_Text* text1, HSD_Text* text2, HSD_Text* text3, +void fn_80174468(s32 slot, HSD_Text* text1, HSD_Text* text2, HSD_Text* text3, StatsList* list, s32 entry_idx) { - ResultsData* data = &lbl_8046DBE8; StatsEntry* entry; - MatchEnd* me; s32 label_id; s32 value_id; s32 result; @@ -245,12 +265,11 @@ void fn_80174468(u8 slot, HSD_Text* text1, HSD_Text* text2, HSD_Text* text3, /* Float constants preloaded into registers */ f32 const_zero = 0.0F; f32 const_neg30 = -30.0F; - PAD_STACK(8); + PAD_STACK(4); label_id = -1; value_id = -1; entry = &list->entries[entry_idx]; - me = data->x94; if (list->mode != 2) { if (entry->value >= 0) { @@ -259,81 +278,14 @@ void fn_80174468(u8 slot, HSD_Text* text1, HSD_Text* text2, HSD_Text* text3, } else { /// Mode 2: special handling for pairs if ((entry_idx & 1) == 1 && entry_idx < list->count) { - /* Inlined 8x unrolled find_nth_nonzero */ - loop_n = entry_idx / 2; - loop_outer = 32; - loop_i = 0; - loop_n++; + MatchEnd* me = lbl_8046DBE8.x94; + loop_n = entry_idx / 2 + 1; loop_ptr = me->x44C[slot].x0; - (void) loop_ptr; - do { - loop_val = *loop_ptr; - if (loop_val != 0) { - loop_n--; - if (loop_n == 0) { - goto found1; - } - } - loop_val = *++loop_ptr; - loop_i++; - if (loop_val != 0) { - loop_n--; - if (loop_n == 0) { - goto found1; - } - } - loop_val = *++loop_ptr; - loop_i++; - if (loop_val != 0) { - loop_n--; - if (loop_n == 0) { - goto found1; - } - } - loop_val = *++loop_ptr; - loop_i++; - if (loop_val != 0) { - loop_n--; - if (loop_n == 0) { - goto found1; - } - } - loop_val = *++loop_ptr; - loop_i++; - if (loop_val != 0) { - loop_n--; - if (loop_n == 0) { - goto found1; - } - } - loop_val = *++loop_ptr; - loop_i++; - if (loop_val != 0) { - loop_n--; - if (loop_n == 0) { - goto found1; - } - } - loop_val = *++loop_ptr; - loop_i++; - if (loop_val != 0) { - loop_n--; - if (loop_n == 0) { - goto found1; - } - } - loop_val = *++loop_ptr; - loop_i++; - if (loop_val != 0) { - loop_n--; - if (loop_n == 0) { - goto found1; - } + for (loop_i = 0; loop_i < 256; loop_i++, loop_ptr++) { + if (*loop_ptr != 0 && --loop_n == 0) { + break; } - loop_ptr++; - loop_i++; - } while (--loop_outer); - found1: + } idx = fn_8016F1F0(loop_i); HSD_SisLib_803A6368(text1, (u16) fn_8016F280(idx) + 60); } @@ -341,7 +293,7 @@ void fn_80174468(u8 slot, HSD_Text* text1, HSD_Text* text2, HSD_Text* text3, if (list->mode == 2 || entry->check != NULL) { if (list->mode != 2) { - result = ((s32 (*)(u8))(Event) entry->check)(slot); + result = ((s32 (*)(s32))(Event) entry->check)(slot); if (result < 0) { value_id = HSD_SisLib_803A6B98(text3, const_zero, const_neg30, "%s", &lbl_804D3F8C); @@ -352,80 +304,14 @@ void fn_80174468(u8 slot, HSD_Text* text1, HSD_Text* text2, HSD_Text* text3, } else if ((entry_idx & 1) == 0) { idx = (entry_idx / 2) - 1; if (idx >= 0) { - /* Inlined 8x unrolled find_nth_nonzero */ - loop_n = idx; - loop_outer = 32; - loop_i = 0; - loop_n++; + MatchEnd* me = lbl_8046DBE8.x94; + loop_n = idx + 1; loop_ptr = me->x44C[slot].x0; - do { - loop_val = *loop_ptr; - if (loop_val != 0) { - loop_n--; - if (loop_n == 0) { - goto found2; - } - } - loop_val = *++loop_ptr; - loop_i++; - if (loop_val != 0) { - loop_n--; - if (loop_n == 0) { - goto found2; - } - } - loop_val = *++loop_ptr; - loop_i++; - if (loop_val != 0) { - loop_n--; - if (loop_n == 0) { - goto found2; - } - } - loop_val = *++loop_ptr; - loop_i++; - if (loop_val != 0) { - loop_n--; - if (loop_n == 0) { - goto found2; - } - } - loop_val = *++loop_ptr; - loop_i++; - if (loop_val != 0) { - loop_n--; - if (loop_n == 0) { - goto found2; - } - } - loop_val = *++loop_ptr; - loop_i++; - if (loop_val != 0) { - loop_n--; - if (loop_n == 0) { - goto found2; - } + for (loop_i = 0; loop_i < 256; loop_i++, loop_ptr++) { + if (*loop_ptr != 0 && --loop_n == 0) { + break; } - loop_val = *++loop_ptr; - loop_i++; - if (loop_val != 0) { - loop_n--; - if (loop_n == 0) { - goto found2; - } - } - loop_val = *++loop_ptr; - loop_i++; - if (loop_val != 0) { - loop_n--; - if (loop_n == 0) { - goto found2; - } - } - loop_ptr++; - loop_i++; - } while (--loop_outer); - found2: + } stat_value = *(s32*) &me->x44C[slot].x0[loop_i * 4 + 0x104]; if (stat_value < 0) { value_id = HSD_SisLib_803A6B98(text3, const_zero, @@ -444,14 +330,14 @@ void fn_80174468(u8 slot, HSD_Text* text1, HSD_Text* text2, HSD_Text* text3, if (entry->get != NULL) { label_id = HSD_SisLib_803A6B98( text2, const_zero, const_neg30, "%s", - ((u8 * (*) (u8))(Event) entry->get)(slot)); + ((u8 * (*) (s32))(Event) entry->get)(slot)); } } } else if (list->mode != 2) { if (entry->get != NULL) { label_id = HSD_SisLib_803A6B98(text2, const_zero, const_neg30, "%s", - ((u8 * (*) (u8))(Event) entry->get)(slot)); + ((u8 * (*) (s32))(Event) entry->get)(slot)); } } @@ -535,13 +421,11 @@ s32 fn_80174A60(StatsList* list, s32 slot) { s32 i; s32 count; - StatsEntry* entry; count = 0; if (list->mode != 2) { for (i = 0; i < list->count; i++) { - entry = &list->entries[i]; - if (fn_801743C4(slot, entry)) { + if (fn_801743C4(slot, &list->entries[i])) { count++; } } @@ -552,45 +436,157 @@ s32 fn_80174A60(StatsList* list, s32 slot) } /// Static data for stats lists +GMRESULT_STATIC_STR(GMRESULT_LBL(804D3F68), "P"); +GMRESULT_STATIC_STR(GMRESULT_LBL(804D3F6C), "%"); +GMRESULT_STATIC_STR(GMRESULT_LBL(804D3F70), "GmRst"); +GMRESULT_STATIC_STR(GMRESULT_LBL(804D3F78), "pnlsce"); +GMRESULT_STATIC_STR(GMRESULT_LBL(804D3F80), "flmsce"); + +GMRESULT_STATS_TABLE(GMRESULT_LBL(803D6488)) = { + { 0x08, { 0 }, NULL, NULL, NULL }, + { 0x08, { 0 }, NULL, NULL, NULL }, + { -1, { 0 }, fn_8017AE70, fn_8017BB94, GMRESULT_LBL(804D3F68) }, + { -1, { 0 }, fn_8017AED8, fn_8017BC50, NULL }, + { -1, { 0 }, fn_8017AF40, fn_8017BD0C, NULL }, + { -1, { 0 }, fn_8017AFA8, fn_8017BDC8, NULL }, + { 0x09, { 0 }, NULL, NULL, NULL }, + { -1, { 0 }, fn_8017B07C, fn_8017BB94, GMRESULT_LBL(804D3F6C) }, + { -1, { 0 }, fn_8017B0E4, fn_8017BC50, NULL }, + { -1, { 0 }, fn_8017B14C, fn_8017BD0C, NULL }, + { -1, { 0 }, fn_8017B1B4, fn_8017BDC8, NULL }, + { 0x0C, { 0 }, fn_8017B21C, NULL, NULL }, + { 0x0C, { 0 }, NULL, NULL, NULL }, +}; + +GMRESULT_STATS_TABLE(GMRESULT_LBL(803D6558)) = { + { 0x0A, { 0 }, NULL, NULL, NULL }, + { 0x0A, { 0 }, NULL, NULL, NULL }, + { 0x0B, { 0 }, fn_8017AE0C, NULL, NULL }, + { 0x0E, { 0 }, NULL, NULL, NULL }, + { 0x0F, { 0 }, fn_8017B010, NULL, NULL }, + { 0x0C, { 0 }, NULL, NULL, NULL }, + { 0x0D, { 0 }, fn_8017B21C, NULL, NULL }, + { 0x10, { 0 }, NULL, NULL, NULL }, + { 0x11, { 0 }, fn_8017B280, NULL, NULL }, + { 0x12, { 0 }, NULL, NULL, NULL }, + { 0x13, { 0 }, fn_8017B2E4, NULL, NULL }, + { 0x14, { 0 }, NULL, NULL, NULL }, + { 0x15, { 0 }, fn_8017B348, NULL, NULL }, + { 0x16, { 0 }, NULL, NULL, NULL }, + { 0x17, { 0 }, fn_8017B3AC, NULL, NULL }, + { 0x18, { 0 }, NULL, NULL, NULL }, + { 0x19, { 0 }, fn_8017B410, NULL, NULL }, + { 0x1A, { 0 }, NULL, NULL, NULL }, + { 0x1B, { 0 }, fn_8017B4D0, NULL, NULL }, + { 0x1C, { 0 }, NULL, NULL, NULL }, + { 0x1D, { 0 }, fn_8017B534, NULL, NULL }, + { 0x1E, { 0 }, NULL, NULL, NULL }, + { 0x1F, { 0 }, fn_8017B598, NULL, NULL }, + { 0x20, { 0 }, NULL, NULL, NULL }, + { 0x21, { 0 }, fn_8017B5FC, NULL, NULL }, + { 0x22, { 0 }, NULL, NULL, NULL }, + { 0x23, { 0 }, fn_8017B660, NULL, NULL }, + { 0x24, { 0 }, NULL, NULL, NULL }, + { 0x25, { 0 }, fn_8017B6C4, NULL, NULL }, + { 0x26, { 0 }, NULL, NULL, NULL }, + { 0x27, { 0 }, fn_8017B728, NULL, NULL }, + { 0x28, { 0 }, NULL, NULL, NULL }, + { 0x29, { 0 }, fn_8017B78C, NULL, NULL }, + { 0x2A, { 0 }, NULL, NULL, NULL }, + { 0x2B, { 0 }, fn_8017B7F0, NULL, NULL }, + { 0x2C, { 0 }, NULL, NULL, NULL }, + { 0x2D, { 0 }, fn_8017B854, NULL, NULL }, + { 0x2E, { 0 }, NULL, NULL, NULL }, + { 0x2F, { 0 }, fn_8017B8B8, NULL, NULL }, + { 0x30, { 0 }, NULL, NULL, NULL }, + { 0x31, { 0 }, fn_8017B91C, NULL, NULL }, + { 0x32, { 0 }, NULL, NULL, NULL }, + { 0x33, { 0 }, fn_8017B9F4, NULL, NULL }, + { 0x34, { 0 }, NULL, NULL, NULL }, + { 0x35, { 0 }, (s32 (*)(s32)) fn_8017BACC, NULL, NULL }, + { 0x36, { 0 }, NULL, NULL, NULL }, + { 0x37, { 0 }, (s32 (*)(s32)) fn_8017BB30, NULL, NULL }, + { 0x36, { 0 }, NULL, NULL, NULL }, +}; + +GMRESULT_STATS_TABLE(GMRESULT_LBL(803D6858)) = { + { 0x08, { 0 }, NULL, NULL, NULL }, + { 0x08, { 0 }, NULL, NULL, NULL }, +}; + static StatsList lbl_803D6878[] = { - { 0, 0x0D, NULL }, - { 1, 0x30, NULL }, - { 2, 0x02, NULL }, - { 3, 0x00, NULL }, + { 0, 0x0D, { 0 }, GMRESULT_LBL(803D6488) }, + { 1, 0x30, { 0 }, GMRESULT_LBL(803D6558) }, + { 2, 0x02, { 0 }, GMRESULT_LBL(803D6858) }, + { 3, 0x00, { 0 }, NULL }, }; -void fn_80174B4C(ResultsData* data, s32 slot) +GMRESULT_STATIC_STR(GMRESULT_LBL(803D6898), + "Error : Cannot read archive file (File Name : %s)."); +GMRESULT_STATIC_STR(GMRESULT_LBL(803D68CC), "%d\x81\x46%02d"); +GMRESULT_STATIC_STR(GMRESULT_LBL(803D68D8), "SdRst.usd"); +GMRESULT_STATIC_STR(GMRESULT_LBL(803D68E4), "SIS_ResultData"); +GMRESULT_STATIC_STR(GMRESULT_LBL(803D68F4), "SdRst.dat"); +GMRESULT_STATIC_STR(GMRESULT_LBL(803D6900), + "Error : gobj dont't get (gmResultAddPanelCamera)\n"); +GMRESULT_STATIC_STR(GMRESULT_LBL(803D6934), "gmresult.c"); +GMRESULT_STATIC_STR(GMRESULT_LBL(803D6940), + "Error : cobj dont't get (gmResultAddPanelCamera)\n"); +GMRESULT_STATIC_STR(GMRESULT_LBL(803D6974), + "Error : gobj dont't get (gmResultAddLight)\n"); +GMRESULT_STATIC_STR(GMRESULT_LBL(803D69A0), + "Error : lobj dont't get (gmResultAddLight)\n"); +GMRESULT_STATIC_STR(GMRESULT_LBL(803D69CC), + "Error : gobj dont't get (gmResultAddModel)\n"); +GMRESULT_STATIC_STR(GMRESULT_LBL(803D69F8), "translate"); + +static inline void fn_80174B4C_blk14829(ResultsData* data, s32 slot, + struct ResultsPlayerData** pdata, + StatsList** list) { - struct ResultsPlayerData* pdata; - StatsList* list; s32 i; - s32 entry_idx; - s32 entry_offset; - s32 count; - s32 visible_count; - Vec3 pos; - f32 offset; - s32 start_entry; PAD_STACK(56); - pdata = &data->player_data[slot]; - list = lbl_803D6878; + (*pdata) = &data->player_data[slot]; + (*list) = lbl_803D6878; /// Clear existing stats text for (i = 0; i < 10; i++) { - if (pdata->stats_text[0][i] != NULL) { - HSD_SisLib_803A5CC4(pdata->stats_text[0][i]); - pdata->stats_text[0][i] = NULL; + if ((*pdata)->stats_text[0][i] != NULL) { + HSD_SisLib_803A5CC4((*pdata)->stats_text[0][i]); + (*pdata)->stats_text[0][i] = NULL; } - if (pdata->stats_text[1][i] != NULL) { - HSD_SisLib_803A5CC4(pdata->stats_text[1][i]); - pdata->stats_text[1][i] = NULL; + if ((*pdata)->stats_text[1][i] != NULL) { + HSD_SisLib_803A5CC4((*pdata)->stats_text[1][i]); + (*pdata)->stats_text[1][i] = NULL; } - if (pdata->stats_text[2][i] != NULL) { - HSD_SisLib_803A5CC4(pdata->stats_text[2][i]); - pdata->stats_text[2][i] = NULL; + if ((*pdata)->stats_text[2][i] != NULL) { + HSD_SisLib_803A5CC4((*pdata)->stats_text[2][i]); + (*pdata)->stats_text[2][i] = NULL; } } +} + +void fn_80174B4C(ResultsData* data, s32 slot) +{ + struct ResultsPlayerData* pdata; + StatsList* list; + StatsList* list_base; + s32 i; + u8 pad[8]; + Vec3 pos; + s32 entry_offset; + s32 count; + s32 visible_count; + HSD_Text* text; + s32 entry_idx; + f32 offset; + s32 start_entry; + void (*render_callback)(void*); + PAD_STACK(40); + + fn_80174B4C_blk14829(data, slot, &pdata, &list_base); + list = list_base; /// Look up stats list if ((s32) pdata->page != 2) { @@ -638,6 +634,7 @@ void fn_80174B4C(ResultsData* data, s32 slot) } /// Create text objects for visible entries + render_callback = (void (*)(void*))(Event) fn_801749B8; entry_idx = start_entry; while (count < 10) { if (list->count <= entry_idx + 1) { @@ -653,26 +650,30 @@ void fn_80174B4C(ResultsData* data, s32 slot) pdata->stats_text[0][count] = HSD_SisLib_803A5ACC(0, 0, pos.x, -pos.y, pos.z, 11.0F, 10.0F); - pdata->stats_text[0][count]->default_fitting = 1; - pdata->stats_text[0][count]->x34.x = 0.05F; - pdata->stats_text[0][count]->x34.y = 0.0546875F; - pdata->stats_text[0][count]->render_callback = - (void (*)(void*)) fn_801749B8; + text = pdata->stats_text[0][count]; + text->default_fitting = 1; + text = pdata->stats_text[0][count]; + text->x34.x = 0.05F; + text->x34.y = 0.0546875F; + text = pdata->stats_text[0][count]; + text->render_callback = render_callback; pdata->stats_text[1][count] = HSD_SisLib_803A6754(0, 0); - pdata->stats_text[1][count]->pos_x = pos.x; - pdata->stats_text[1][count]->pos_y = -pos.y; - pdata->stats_text[1][count]->pos_z = pos.z; - pdata->stats_text[1][count]->render_callback = - (void (*)(void*)) fn_801749B8; + text = pdata->stats_text[1][count]; + text->pos_x = pos.x; + text->pos_y = -pos.y; + text->pos_z = pos.z; + text = pdata->stats_text[1][count]; + text->render_callback = render_callback; pdata->stats_text[2][count] = HSD_SisLib_803A6754(0, 0); - pdata->stats_text[2][count]->pos_x = 11.0F + pos.x; - pdata->stats_text[2][count]->pos_y = -pos.y; - pdata->stats_text[2][count]->pos_z = pos.z; - pdata->stats_text[2][count]->render_callback = - (void (*)(void*)) fn_801749B8; - pdata->stats_text[2][count]->default_alignment = 2; + text = pdata->stats_text[2][count]; + text->pos_x = 11.0F + pos.x; + text->pos_y = -pos.y; + text->pos_z = pos.z; + text = pdata->stats_text[2][count]; + text->render_callback = render_callback; + text->default_alignment = 2; pos.y -= 1.75F; fn_80174468(slot, pdata->stats_text[0][count], @@ -942,89 +943,62 @@ void fn_801756E0(s32 slot) void fn_80175880(s32 slot) { MatchEnd* me; - u32 new_var2; - s32 var_r30; - u8 winner; - GXColor sp10; - GXColor spC; - GXColor* new_var; - s32 skip; + s32 line_num; u32 seconds; u32 minutes; + u32 display_seconds; + GXColor color; + GXColor color_copy; + GXColor* color_p; me = lbl_8046DBE8.x94; - sp10 = fn_8017507C(slot); - if (me->player_standings[slot].slot_type == Gm_PKind_NA) { - goto grey_out; - } - - winner = lbl_8046DBE8.x6; - if (winner == slot) { - goto show_normal; - } - - if (me->is_teams == 1) { - if (me->team_standings[me->player_standings[slot].team].is_big_loser == - 0) + color = fn_8017507C(slot); + if (me->player_standings[slot].slot_type != Gm_PKind_NA) { + if (lbl_8046DBE8.x6 == slot || + (me->is_teams == 1 && + me->team_standings[me->player_standings[slot].team] + .is_big_loser == 0 && + ((s8) me->player_standings[slot].stocks > 0 || + (me->player_standings[slot].x28 == me->frame_count && + (s8) me->player_standings[lbl_8046DBE8.x6].stocks == 0))) || + (gm_801743A4(me->result) && + ((s8) me->player_standings[slot].stocks > 0 || + me->player_standings[slot].score == + me->player_standings[lbl_8046DBE8.x6].score))) { - if ((s8) me->player_standings[slot].stocks > 0) { - goto show_normal; - } - if (me->player_standings[slot].x28 == me->frame_count) { - if ((s8) me->player_standings[winner].stocks == 0) { - goto show_normal; - } + line_num = + HSD_SisLib_803A6B98(lbl_8046DBE8.player_data[slot].ko_time, + 0.0F, -30.0F, lbl_804D3FA8.text); + } else { + seconds = me->player_standings[slot].x28 / 60; + display_seconds = seconds; + if (seconds > 5999) { + display_seconds = 5999; } + minutes = display_seconds / 60; + line_num = HSD_SisLib_803A6B98( + lbl_8046DBE8.player_data[slot].ko_time, 0.0F, -30.0F, + lbl_803D68CC, minutes, display_seconds % 60); } - } - - if (me->result == 7 || me->result == 8) { - skip = 1; } else { - skip = 0; - } - - if (skip != 0) { - if ((s8) me->player_standings[slot].stocks > 0) { - goto show_normal; - } - if (me->player_standings[slot].score == - me->player_standings[winner].score) - { - goto show_normal; - } - } - - seconds = me->player_standings[slot].x28 / 60; - if (seconds > 5999) { - seconds = 5999; - } - minutes = seconds / 60; - new_var2 = minutes * 60; - var_r30 = - HSD_SisLib_803A6B98(lbl_8046DBE8.player_data[slot].ko_time, 0.0F, - -30.0F, "%02d:%02d", minutes, seconds - new_var2); - goto end_common; - -show_normal: - var_r30 = HSD_SisLib_803A6B98(lbl_8046DBE8.player_data[slot].ko_time, 0.0F, - -30.0F, NULL); - goto end_common; - -grey_out: - sp10.r = 0xA0; - sp10.g = 0xA0; - sp10.b = 0xA0; - var_r30 = HSD_SisLib_803A6B98(lbl_8046DBE8.player_data[slot].ko_time, 0.0F, - -30.0F, NULL, 0); + color.r = 0xA0; + color.g = 0xA0; + color.b = 0xA0; + line_num = HSD_SisLib_803A6B98(lbl_8046DBE8.player_data[slot].ko_time, + 0.0F, -30.0F, "%s", &lbl_804D3FA0); + } + + HSD_SisLib_803A7548(lbl_8046DBE8.player_data[slot].ko_time, line_num, + 0.11F, 0.08F); + color_copy = color; + color_p = &color_copy; + HSD_SisLib_803A74F0(lbl_8046DBE8.player_data[slot].ko_time, line_num, + color_p); +} -end_common: - HSD_SisLib_803A7548(lbl_8046DBE8.player_data[slot].ko_time, var_r30, 0.11f, - 0.08F); - spC = sp10; - new_var = &spC; - HSD_SisLib_803A74F0(lbl_8046DBE8.player_data[slot].ko_time, var_r30, - new_var); +static inline MatchEnd* fn_80175A94_get_match_end(void) +{ + return lbl_8046DBE8.x94; } void fn_80175A94(s32 slot, Vec3* position) @@ -1064,7 +1038,7 @@ void fn_80175A94(s32 slot, Vec3* position) GXColor sp18; GXColor sp14; PAD_STACK(4); - me = lbl_8046DBE8.x94; + me = fn_80175A94_get_match_end(); sp14 = fn_8017507C(slot); if (me->player_standings[slot].slot_type != 3) { var_r29 = HSD_SisLib_803A6B98(new_var->player_data[slot].ko_time, @@ -1501,6 +1475,9 @@ void fn_80175DC8(HSD_GObj* gobj) } } +#undef __FILE__ +#define __FILE__ GMRESULT_LBL(803D6934) + void fn_80176A6C(void) { HSD_GObj* gobj; @@ -1508,14 +1485,14 @@ void fn_80176A6C(void) gobj = GObj_Create(0x13U, 0x14U, 0U); if (gobj == NULL) { - OSReport("Error : gobj dont\'t get (gmResultAddPanelCamera)\n"); - HSD_ASSERT(0x662, 0); + (OSReport)(GMRESULT_LBL(803D6900)); + HSD_ASSERTMSG(0x662, 0, GMRESULT_LBL(804D3FB0)); } cobj = HSD_CObjLoadDesc(lbl_8046DBE8.pnlsce->cameras->desc); if (cobj == NULL) { - OSReport("Error : cobj dont\'t get (gmResultAddPanelCamera)\n"); - HSD_ASSERT(0x668, 0); + (OSReport)(GMRESULT_LBL(803D6940)); + HSD_ASSERTMSG(0x668, 0, GMRESULT_LBL(804D3FB0)); } HSD_GObjObject_80390A70(gobj, HSD_GObj_804D784B, cobj); @@ -1528,9 +1505,9 @@ void fn_80176A6C(void) HSD_SisLib_803A611C(0, gobj, 9U, 0xDU, 0U, 0xEU, 0U, 0x13U); if (lbLang_IsSavedLanguageUS() != 0) { - HSD_SisLib_803A62A0(0, "SdRst.usd", "SIS_ResultData"); + HSD_SisLib_803A62A0(0, GMRESULT_LBL(803D68D8), GMRESULT_LBL(803D68E4)); } else { - HSD_SisLib_803A62A0(0, "SdRst.dat", "SIS_ResultData"); + HSD_SisLib_803A62A0(0, GMRESULT_LBL(803D68F4), GMRESULT_LBL(803D68E4)); } lbl_8046DBE8.cobj = cobj; } @@ -1588,32 +1565,35 @@ void fn_80176D3C(Vec3* positions) { ResultsData* data = &lbl_8046DBE8; MatchEnd* me; + MatchEnd* me_iter; Vec3* pos; - MatchPlayerData* p; + u8 _[8]; DynamicModelDesc* models[3]; - HSD_JObj* jobj; - HSD_GObj* gobj; s32 winner; + DynamicModelDesc** model; s32 i; PAD_STACK(8); me = data->x94; pos = positions; - p = me->player_standings; + if (me && me) { + } + me_iter = data->x94; models[0] = data->flmsce->models[3]; models[1] = data->flmsce->models[2]; models[2] = data->flmsce->models[1]; i = 0; do { - if (p->slot_type == Gm_PKind_NA) { + if (me_iter->player_standings[0].slot_type == Gm_PKind_NA) { goto loop_end; } if (me->is_teams == 0) { - winner = p->is_big_loser; + winner = me_iter->player_standings[0].is_big_loser; } else { - winner = me->team_standings[p->team].is_big_loser; + winner = me->team_standings[me_iter->player_standings[0].team] + .is_big_loser; } if (winner > 3) { @@ -1626,22 +1606,27 @@ void fn_80176D3C(Vec3* positions) goto loop_end; } - gobj = GObj_Create(14, 15, 0); - jobj = HSD_JObjLoadJoint(models[winner - 1]->joint); - HSD_GObjObject_80390A70(gobj, HSD_GObj_804D7849, jobj); - GObj_SetupGXLink(gobj, HSD_GObj_JObjCallback, 11, 0); + { + HSD_GObj* gobj; + HSD_JObj* jobj; + gobj = GObj_Create(14, 15, 0); + model = &models[winner] - 1; + jobj = HSD_JObjLoadJoint((*model)->joint); + HSD_GObjObject_80390A70(gobj, HSD_GObj_804D7849, jobj); + GObj_SetupGXLink(gobj, HSD_GObj_JObjCallback, 11, 0); - HSD_JObjSetTranslate(jobj, pos); + HSD_JObjSetTranslate(jobj, pos); - gm_8016895C(jobj, models[winner - 1], 0); - HSD_JObjReqAnimAll(jobj, 0.0F); - HSD_JObjAnimAll(jobj); - HSD_GObj_SetupProc(gobj, fn_80176D18, 1); - fn_80179F6C(i, (int) gobj); + gm_8016895C(jobj, *model, 0); + HSD_JObjReqAnimAll(jobj, 0.0F); + HSD_JObjAnimAll(jobj); + HSD_GObj_SetupProc(gobj, fn_80176D18, 1); + fn_80179F6C(i, (int) gobj); + } loop_end: i++; - p++; + me_iter = (MatchEnd*) ((MatchPlayerData*) me_iter + 1); pos++; } while (i < 4); } @@ -1705,75 +1690,91 @@ void fn_80176F60(void) void fn_801771C0(ResultsData* data) { MatchEnd* me; - MatchPlayerData* p; - MatchPlayerData* q; - s32 result; s32 i; + s32 result; s32 j; - u8 our_team; me = data->x94; data->x4 = fn_80165418(me); data->x5 = fn_801654A0(me); - if (me->is_teams != 1) { + if (me->is_teams == 1) { + for (i = 0; i < 4; i++) { + if (me->player_standings[i].slot_type != Gm_PKind_NA && + me->player_standings[i].team == data->x5) + { + result = i; + for (j = 0; j < 4; j++) { + if (me->player_standings[j].slot_type != Gm_PKind_NA && + me->player_standings[j].team == data->x5 && i != j && + me->player_standings[i].is_small_loser > + me->player_standings[j].is_small_loser) + { + result = -1; + break; + } + } + if (result >= 0) { + data->x6 = result; + break; + } + } + } + } else { data->x6 = data->x4; - return; } +} - p = me->player_standings; - i = 0; - do { - if (p->slot_type == Gm_PKind_NA) { - goto next_iter; - } - our_team = data->x5; - if (p->team != our_team) { - goto next_iter; - } +extern HSD_Archive* lbl_804D65B8; - result = i; - q = me->player_standings; - for (j = 0; j < 4; j++, q++) { - if (q->slot_type == Gm_PKind_NA) { - continue; - } - if (q->team != our_team) { - continue; - } - if (i == j) { - continue; - } - if (p->is_small_loser > q->is_small_loser) { - result = -1; - break; - } - } +#undef __FILE__ +#define __FILE__ GMRESULT_LBL(803D6934) - if (result >= 0) { - data->x6 = result; - return; - } +static inline void gmResultLoadArchive(ResultsData* data) +{ + lbl_804D65B8 = lbArchive_80016DBC(GMRESULT_LBL(804D3F70), &data->pnlsce, + GMRESULT_LBL(804D3F78), &data->flmsce, + GMRESULT_LBL(804D3F80), 0); + if (data->pnlsce == NULL) { + (OSReport)(GMRESULT_LBL(803D6898), GMRESULT_LBL(804D3F70)); + } + if (data->flmsce == NULL) { + (OSReport)(GMRESULT_LBL(803D6898), GMRESULT_LBL(804D3F70)); + } +} - next_iter: - p++; - i++; - } while (i < 4); +static inline void gmResultReportLightGObj(void) +{ + (OSReport)(GMRESULT_LBL(803D6974)); + HSD_ASSERTMSG(0x68C, 0, GMRESULT_LBL(804D3FB0)); } -extern HSD_Archive* lbl_804D65B8; +static inline void gmResultReportLightLObj(void) +{ + (OSReport)(GMRESULT_LBL(803D69A0)); + HSD_ASSERTMSG(0x68F, 0, GMRESULT_LBL(804D3FB0)); +} + +static inline void gmResultReportModelGObj(void) +{ + (OSReport)(GMRESULT_LBL(803D69CC)); + HSD_ASSERTMSG(0x6A2, 0, GMRESULT_LBL(804D3FB0)); +} void gm_80177368_OnEnter(void* arg0_) { ResultsMatchInfo* arg0 = arg0_; - HSD_LObj* temp_r3_3; - HSD_GObj* temp_r3_2; - HSD_GObj* temp_r3_4; - MatchEnd* temp_r29; + HSD_GObj* light_gobj; + HSD_LObj* lobj; + HSD_GObj* model_gobj; + MatchEnd* match_end; ResultsData* data = &lbl_8046DBE8; int i; + ResultsStatsInfo* info; + MatchEnd* me_iter; + ResultsData* data_iter; - PAD_STACK(0x20); + PAD_STACK(0x28); memzero(&lbl_8046DBE8, 0x5A8); lbl_8046DBE8.x1 = 0; @@ -1782,12 +1783,12 @@ void gm_80177368_OnEnter(void* arg0_) lbl_8046DBE8.x0_4 = arg0->x0_0; lbl_8046DBE8.x0_5 = arg0->x0_1; - temp_r29 = lbl_8046DBE8.x94; + match_end = lbl_8046DBE8.x94; if (gm_801743A4(lbl_8046DBE8.x94->result)) { lbl_8046DBE8.num_pages = 2; } else { lbl_8046DBE8.num_pages = 3; - if (temp_r29->x5 == 3) { + if (match_end->x5 == 3) { lbl_8046DBE8.player_data[0].page = 2; lbl_8046DBE8.player_data[1].page = 2; lbl_8046DBE8.player_data[2].page = 2; @@ -1795,71 +1796,65 @@ void gm_80177368_OnEnter(void* arg0_) } } if (fn_801701B8() == 0) { - for (i = 0; i < 4; i++) { - lbl_8046E190[i].x0 = 2; - lbl_8046E190[i].x1 = fn_80174284_noinline(i) * 2 + 2; + info = lbl_8046E190; + for (i = 0; i < 4; i++, info++) { + info->x0 = 2; + info->x1 = fn_80174284_noinline(i) * 2 + 2; } } else { - for (i = 0; i < 4; i++) { - lbl_8046E190[i].x0 = 2; - lbl_8046E190[i].x1 = 0; + info = lbl_8046E190; + for (i = 0; i < 4; i++, info++) { + info->x0 = 2; + info->x1 = 0; } } fn_801771C0(&lbl_8046DBE8); - if (temp_r29->player_standings[data->x6].slot_type == Gm_PKind_Human) { - if (!gm_801743A4(temp_r29->result) && - temp_r29->player_standings[data->x6].x3_6) + if (match_end->player_standings[data->x6].slot_type == Gm_PKind_Human) { + if (!gm_801743A4(match_end->result) && + match_end->player_standings[data->x6].x3_6) { lb_80014574(data->x6, 3, 0x20, 0); } } un_802FF1B4(); - lbl_804D65B8 = lbArchive_80016DBC("GmRst", &data->pnlsce, "pnlsce", - &data->flmsce, "flmsce", 0); - if (data->pnlsce == NULL) { - OSReport("Error : Cannot read archive file (File Name : %s).", - "GmRst"); - } - if (data->flmsce == NULL) { - OSReport("Error : Cannot read archive file (File Name : %s).", - "GmRst"); - } + gmResultLoadArchive(data); fn_80176A6C(); - temp_r3_2 = GObj_Create(0xB, 3, 0); - if (temp_r3_2 == NULL) { - OSReport("Error : gobj dont't get (gmResultAddLight)\n"); - HSD_ASSERT(0x68C, 0); - } - temp_r3_3 = lb_80011AC4(data->pnlsce->lights); - if (temp_r3_3 == NULL) { - OSReport("Error : lobj dont't get (gmResultAddLight)\n"); - HSD_ASSERT(0x68F, 0); - } - HSD_GObjObject_80390A70(temp_r3_2, (u8) HSD_GObj_804D784A, temp_r3_3); - GObj_SetupGXLink(temp_r3_2, HSD_GObj_LObjCallback, 0xA, 0); - temp_r3_4 = GObj_Create(0xE, 0xF, 0); - data->x18 = temp_r3_4; - if (temp_r3_4 == NULL) { - OSReport("Error : gobj dont't get (gmResultAddModel)\n"); - HSD_ASSERT(0x6A2, 0); - } - HSD_GObj_SetupProc(temp_r3_4, fn_80179350, 0); + light_gobj = GObj_Create(0xB, 3, 0); + if (light_gobj == NULL) { + gmResultReportLightGObj(); + } + lobj = lb_80011AC4(data->pnlsce->lights); + if (lobj == NULL) { + gmResultReportLightLObj(); + } + HSD_GObjObject_80390A70(light_gobj, (u8) HSD_GObj_804D784A, lobj); + GObj_SetupGXLink(light_gobj, HSD_GObj_LObjCallback, 0xA, 0); + model_gobj = GObj_Create(0xE, 0xF, 0); + data->x18 = model_gobj; + if (model_gobj == NULL) { + gmResultReportModelGObj(); + } + HSD_GObj_SetupProc(model_gobj, fn_80179350, 0); fn_80176F60(); fn_8017AA78(&arg0->x1); fn_8017A004(); - if (!gm_801743A4(temp_r29->result)) { + if (!gm_801743A4(match_end->result)) { lbAudioAx_80023F28( - fn_80160400(temp_r29->player_standings[data->x6].character_kind)); + fn_80160400(match_end->player_standings[data->x6].character_kind)); } + me_iter = match_end; + data_iter = data; for (i = 0; i < 4; i++) { - if (temp_r29->player_standings[i].slot_type != Gm_PKind_NA) { + if (me_iter->player_standings[0].slot_type != Gm_PKind_NA) { fn_8017A9B4(i); - data->player_data[i].fighter_gobj = - fn_8017A67C(temp_r29->player_standings[i].character_kind, - temp_r29->player_standings[i].x3, i); - data->player_data[i].camera = fn_8017A318(i); + data_iter->player_data[0].fighter_gobj = + fn_8017A67C(me_iter->player_standings[0].character_kind, + me_iter->player_standings[0].x3, i); + data_iter->player_data[0].camera = fn_8017A318(i); } + me_iter = (MatchEnd*) ((MatchPlayerData*) me_iter + 1); + data_iter = (ResultsData*) ((struct ResultsPlayerData*) data_iter + 1); } } diff --git a/src/melee/gm/gmresultplayer.c b/src/melee/gm/gmresultplayer.c index 2fc33b913f..70ca4d2b92 100644 --- a/src/melee/gm/gmresultplayer.c +++ b/src/melee/gm/gmresultplayer.c @@ -88,9 +88,8 @@ typedef struct { typedef struct { /* 0x000 */ u8 pad[0x10]; /* 0x010 */ CameraKindParams kind[(0x6D0 - 0x10) / 0x30]; - /* 0x6D0 */ f32 slot_x_off[4]; - /* 0x6E0 */ f32 slot_y_off[4]; - /* 0x6F0 */ u8 pad_6F0[0xF08 - 0x6F0]; + /* 0x6D0 */ f32 slot_off[(0xF00 - 0x6D0) / 0x30][3][4]; + /* 0xF00 */ u8 pad_F00[0xF08 - 0xF00]; /* 0xF08 */ HSD_CObjDesc cobj_desc; } CameraKindData; @@ -274,11 +273,14 @@ static const float scroll_speed = 0.2F; static inline bool scrollDown(int slot, float amount) { int scroll_max; + // Preserve the original register move for the nested call. + int arg = slot; ResultsData* data = &lbl_8046DBE8; amount *= scroll_speed; scroll_max = fn_80174A60(fn_801748EC(&lbl_803D6878, - data->player_data[slot].page, slot), + data->player_data[slot].page, + slot | arg), slot) - 10; if (data->player_data[slot].scroll_offset < scroll_max) { @@ -323,11 +325,13 @@ bool fn_80177B7C(int slot) { float stick_y = HSD_PadCopyStatus[(u8) slot].nml_stickY; + float abs_stick_y = stick_y; u32 trigger; bool result = false; - PAD_STACK(8); + PAD_STACK(16); - if (fabsf_bitwise(stick_y) < scroll_deadzone) { + *(u32*) &abs_stick_y &= ~0x80000000; + if (abs_stick_y < scroll_deadzone) { stick_y = 0; } trigger = HSD_PadCopyStatus[(u8) slot].trigger; @@ -1121,6 +1125,22 @@ int fn_80179854(void) extern s32 ftLib_800876B4(HSD_GObj*); +static inline HSD_ImageDesc* get_player_img2(int slot, + ResultsDisplayData* disp) +{ + return &disp->player_img2[slot]; +} + +static inline int get_big_loser(int slot, MatchEnd* match_end) +{ + return match_end->player_standings[slot].is_big_loser; +} + +static inline HSD_JObj** get_result_jobjs(ResultsDisplayData* disp) +{ + return disp->jobjs; +} + void fn_80179990(HSD_GObj* arg0, int arg1, int arg2) { ResultsDisplayData* disp = &lbl_8046E1B0; @@ -1135,19 +1155,18 @@ void fn_80179990(HSD_GObj* arg0, int arg1, int arg2) cobj = (HSD_CObj*) arg0->hsd_obj; - lookup = - match_end->is_teams == 0 - ? match_end->player_standings[arg2].is_big_loser - : match_end->team_standings[match_end->player_standings[arg2].team] - .is_big_loser; + if (match_end->is_teams == 0) { + lookup = get_big_loser(arg2, match_end); + } else { + lookup = + match_end->team_standings[match_end->player_standings[arg2].team] + .is_big_loser; + } + cobj = (HSD_CObj*) arg0->hsd_obj; if (lookup != 0) { HSD_JObj* root = (HSD_JObj*) disp->gobjs[arg2]->hsd_obj; - if (root == NULL) { - child_jobj = NULL; - } else { - child_jobj = root->child; - } + child_jobj = root == NULL ? NULL : root->child; } if (HSD_CObjSetCurrent(cobj)) { @@ -1163,7 +1182,8 @@ void fn_80179990(HSD_GObj* arg0, int arg1, int arg2) Camera_800313E0(arg0, 0); { - HSD_ImageDesc* desc = &disp->player_img2[arg2]; + HSD_ImageDesc* image_desc = disp->player_img2; + HSD_ImageDesc* desc = &image_desc[arg2]; HSD_ImageDescCopyFromEFB( desc, @@ -1216,7 +1236,7 @@ void fn_80179990(HSD_GObj* arg0, int arg1, int arg2) Camera_800313E0(arg0, 0); { - HSD_ImageDesc* desc = &disp->player_img2[arg2]; + HSD_ImageDesc* desc = get_player_img2(arg2, disp); HSD_ImageDescCopyFromEFB( desc, @@ -1239,7 +1259,7 @@ void fn_80179990(HSD_GObj* arg0, int arg1, int arg2) disp->state.player_flags[arg2] = 1; { - HSD_JObj* jobj2 = disp->jobjs[arg2]; + HSD_JObj* jobj2 = get_result_jobjs(disp)[arg2]; jobj2->u.dobj->next->mobj->tobj->imagedesc = desc; } } @@ -1397,7 +1417,7 @@ void fn_8017A078(s32 arg0) HSD_GObj* fn_8017A318(s32 arg0) { - ResultsPlayerConfig* config = &lbl_803B7B68; + u32* config = (u32*) &lbl_803B7B68; CameraKindData* data = &lbl_803D6A08; ResultsDisplayData* disp = &lbl_8046E1B0; MatchEnd* match_end = &disp->state.match_end; @@ -1421,9 +1441,9 @@ HSD_GObj* fn_8017A318(s32 arg0) scissor[0] = lbl_804DA3F0; scissor[1] = lbl_804DA3F4; - eye = config->x4C; - interest = config->x58; - callbacks = config->x64; + eye = ((ResultsPlayerConfig*) config)->x4C; + interest = ((ResultsPlayerConfig*) config)->x58; + callbacks = ((ResultsPlayerConfig*) config)->x64; if (match_end->is_teams == 0) { slot = match_end->player_standings[arg0].is_big_loser; } else { @@ -1467,11 +1487,11 @@ HSD_GObj* fn_8017A318(s32 arg0) f32 x_off, y_off; interest.x = interest_x; - x_off = data->slot_x_off[slot]; + x_off = data->slot_off[kind_data][0][slot]; eye.x += x_off; interest.x += x_off; - y_off = data->slot_y_off[slot]; + y_off = data->slot_off[kind_data][1][slot]; eye.y += y_off; interest.y += y_off; } @@ -1517,11 +1537,11 @@ Fighter_GObj* fn_8017A67C(CharacterKind kind, int arg1, int arg2) } if (gm_80160438(kind) != NULL) { - f32 cz, cy, cx; + Vec3 pos; + Vec3 pos2; + f32 sp[4]; PAD_STACK(0xC); - *(s32*) &cx = *(s32*) &config->x74; - *(s32*) &cy = *(s32*) &config->x78; - *(s32*) &cz = *(s32*) &config->x7C; + pos = *(Vec3*) &config->x74; if ((u32) (kind - 0x12) <= 1U) { if ((int) (s8) match_end->player_standings[arg2].character_id == 7) @@ -1570,22 +1590,15 @@ Fighter_GObj* fn_8017A67C(CharacterKind kind, int arg1, int arg2) } if (slot_type == 0) { - f32 px, py, pz; - *(s32*) &px = *(s32*) &config->x80; - *(s32*) &py = *(s32*) &config->x84; - *(s32*) &pz = *(s32*) &config->x88; - py = 100.0f * (f32) (arg2 + 1); - Player_80032A04(arg2, (Vec3*) &px); + pos2 = *(Vec3*) &config->x80; + pos2.y = 100.0f * (f32) (arg2 + 1); + Player_80032A04(arg2, &pos2); Player_SetScale(arg2, 1.8f * lbl_803D7058[kind]); Player_80036F34(arg2, variant); } else { - f32 sp[4]; int var_idx; f32 scale; - *(s32*) &sp[0] = *(s32*) &config->x8C; - *(s32*) &sp[1] = *(s32*) &config->x90; - *(s32*) &sp[2] = *(s32*) &config->x94; - *(s32*) &sp[3] = *(s32*) &config->x98; + *(Vec4*) sp = *(Vec4*) &config->x8C; if (variant <= 2) { var_idx = variant; } else { @@ -1596,8 +1609,8 @@ Fighter_GObj* fn_8017A67C(CharacterKind kind, int arg1, int arg2) Player_SetScale( arg2, scale * (sp[slot_type] * (20.0f / Player_800360D8(arg2)))); - cy = 100.0f * (f32) (arg2 + 1); - Player_80032A04(arg2, (Vec3*) &cx); + pos.y = 100.0f * (f32) (arg2 + 1); + Player_80032A04(arg2, &pos); } disp->state.variant[arg2] = (u8) variant; @@ -1695,6 +1708,7 @@ void fn_8017AA78(u8* arg0) a = lbl_804D3FD0; (void) a; b = lbl_804D3FD4; + (void) b; state->dim_w1[0] = a; state->dim_w1[1] = b; a = lbl_804D3FD8; diff --git a/src/melee/gm/gmstaffroll.c b/src/melee/gm/gmstaffroll.c index cefe8d617f..262b601e4a 100644 --- a/src/melee/gm/gmstaffroll.c +++ b/src/melee/gm/gmstaffroll.c @@ -95,8 +95,28 @@ typedef struct { /* 0x13 */ u8 pad_13; } StaffEntryData; +typedef struct { + /* 0x00 */ f32 x_positions[4]; + /* 0x10 */ struct { + s32 frame; + s32 sfx; + } sfx_cues[44]; + /* 0x170 */ u8 pad_170[8]; +} StaffRollExtraData; +STATIC_ASSERT(sizeof(StaffRollExtraData) == 0x178); + +typedef struct StaffRollPtclNode { + /* 0x00 */ struct StaffRollPtclNode* x0; + /* 0x04 */ union { + struct StaffRollPtclNode* ptr; + s32 color; + } x4; + /* 0x08 */ struct StaffRollPtclNode* x8; + /* 0x0C */ struct StaffRollPtclNode* xC; +} StaffRollPtclNode; + /* 3DBFD8 */ static StaffEntryData gm_803DBFD8[198] = { 0 }; -static u8 gm_803DBFD8_pad[0x178] = { 0 }; +static StaffRollExtraData gm_803DBFD8_extra = { 0 }; /* 3DD0C8 */ static HSD_WObjDesc gm_803DD0C8 = { NULL, @@ -283,7 +303,7 @@ void fn_801AAB74(HSD_GObj* gobj) int staff_idx; int i; SortBufEntry bsort_temp; - PAD_STACK(0x24); + PAD_STACK(0x20); if (gm_804D6818 == 0) { for (i = 0; i < gm_804D681C; i++) { @@ -445,11 +465,11 @@ typedef struct StaffRollPoints { void fn_801AB200(HSD_GObj* gobj) { - HSD_JObj* hover_jobj; + HSD_JObj* jobj_pair[2]; HSD_JObj* cursor_jobj; HSD_JObj* temp_jobj; u8 operand_pad[4]; - HSD_JObj* jobj_pair[2]; + HSD_JObj* hover_jobj; Vec3 xform_result; f32 proj[8]; s32 tally_color; @@ -466,8 +486,7 @@ void fn_801AB200(HSD_GObj* gobj) s32 adj_val; f32 vel_x, vel_y; f32 sq_x, sq_y; - f32 cursor_vy; - void* p; + StaffRollPtclNode* p; int entry_idx; int broke; s32 base_page; @@ -485,11 +504,10 @@ void fn_801AB200(HSD_GObj* gobj) HSD_JObj* child_jobj; f32 fov_scale; f32 half_size; - Vec3* corners; f32 highlight_val; f32 offset1, offset2; HSD_Text* tally_text; - PAD_STACK(88); + PAD_STACK(80); lb_80011E24(root, &cursor_jobj, 7, -1); @@ -514,24 +532,21 @@ void fn_801AB200(HSD_GObj* gobj) adj_val = 0; } - sq_x = vel_x * vel_x + 6400.0f; - (void) sq_x; vel_y = (f32) adj_val; - sq_x = sqrtf(sq_x); - vel_x = vel_x * 0.00038461538f * sq_x; - sq_y = vel_y * vel_y + 6400.0f; - sq_y = sqrtf(sq_y); - - cursor_vy = vel_y * (0.00038461538f * sq_y); - if (cursor_vy < -2.6f) { - cursor_vy = -2.6f; + sq_x = sqrtf(vel_x * vel_x + 6400.0f); + vel_x *= 0.00038461538f * sq_x; + sq_y = sqrtf(vel_y * vel_y + 6400.0f); + + vel_y *= 0.00038461538f * sq_y; + if (vel_y < -2.6f) { + vel_y = -2.6f; } - if (cursor_vy > 2.6f) { - cursor_vy = 2.6f; + if (vel_y > 2.6f) { + vel_y = 2.6f; } gm_804D6804.x0 = vel_x; - gm_804D6804.x4 = cursor_vy; + gm_804D6804.x4 = vel_y; HSD_JObjSetTranslateX(cursor_jobj, gm_804D6804.x0); HSD_JObjSetTranslateY(cursor_jobj, gm_804D6804.x4); @@ -541,31 +556,30 @@ void fn_801AB200(HSD_GObj* gobj) entry_idx = staffInfoSortBuf[i].index; if (staffInfo[entry_idx].x8 < 1) { if (entry_idx < 7) { - lb_80011E24( - gm_804D682C, &ptcl_jobj, - *(s32*) ((u8*) gm_803DBFD8 + entry_idx * 4 + 0x11F0), -1); + lb_80011E24(gm_804D682C, &ptcl_jobj, + gm_803DD1C8.particles[entry_idx], -1); if (entry_idx == 0) { - p = ptcl_jobj->u.ptcl; + p = (StaffRollPtclNode*) ptcl_jobj->u.ptcl; tally_color = *(s32*) &gm_804D42C4; - p = *(void**) ((u8*) p + 4); - p = *(void**) ((u8*) p + 4); - p = *(void**) ((u8*) p + 4); - p = *(void**) ((u8*) p + 8); - p = *(void**) ((u8*) p + 0xC); - *(s32*) ((u8*) p + 4) = tally_color; + p = p->x4.ptr; + p = p->x4.ptr; + p = p->x4.ptr; + p = p->x8; + p = p->xC; + p->x4.color = tally_color; } else if ((unsigned) (entry_idx - 2) <= 1u) { - p = ptcl_jobj->u.ptcl; + p = (StaffRollPtclNode*) ptcl_jobj->u.ptcl; tally_color = *(s32*) &gm_804D42C4; - p = *(void**) ((u8*) p + 4); - p = *(void**) ((u8*) p + 8); - p = *(void**) ((u8*) p + 0xC); - *(s32*) ((u8*) p + 4) = tally_color; + p = p->x4.ptr; + p = p->x8; + p = p->xC; + p->x4.color = tally_color; } else { - p = ptcl_jobj->u.ptcl; + p = (StaffRollPtclNode*) ptcl_jobj->u.ptcl; tally_color = *(s32*) &gm_804D42C4; - p = *(void**) ((u8*) p + 8); - p = *(void**) ((u8*) p + 0xC); - *(s32*) ((u8*) p + 4) = tally_color; + p = p->x8; + p = p->xC; + p->x4.color = tally_color; } } else { staffInfo[entry_idx].win[0]->active_color = gm_804D42C4; @@ -583,23 +597,21 @@ void fn_801AB200(HSD_GObj* gobj) if (gm_804D6814 < 0x1285) { for (i = 0; i < gm_804D6800; i++) { - SortBufEntry* sort_entry = &staffInfoSortBuf[i]; - if (sort_entry->mtx[2][3] < -1.0f) { - entry_idx = sort_entry->index; + if (staffInfoSortBuf[i].mtx[2][3] < -1.0f) { + entry_idx = staffInfoSortBuf[i].index; if (entry_idx != 0xB7 && entry_idx < 0xC0) { - hover_jobj = sort_entry->jobj; + hover_jobj = staffInfoSortBuf[i].jobj; half_size = 0.16875f * (f32) gm_803DBFD8[entry_idx] .x11[lbLang_IsSavedLanguageUS()]; - corners = (Vec3*) ((u8*) gm_803DBFD8 + 0x120C); - corners[1].x = -half_size; - corners[0].x = -half_size; - corners[3].x = half_size; - corners[2].x = half_size; + gm_803DD1C8.corners[1].x = -half_size; + gm_803DD1C8.corners[0].x = -half_size; + gm_803DD1C8.corners[3].x = half_size; + gm_803DD1C8.corners[2].x = half_size; broke = 0; for (j = 0; j < 4; j++) { - PSMTXMultVec(sort_entry->mtx, &corners[j], - &xform_result); + PSMTXMultVec(staffInfoSortBuf[i].mtx, + &gm_803DD1C8.corners[j], &xform_result); if (xform_result.z >= -1.0f) { broke = 1; break; @@ -623,31 +635,33 @@ void fn_801AB200(HSD_GObj* gobj) if (staffInfo[entry_idx].x8 < 1) { if (entry_idx < 7) { lb_80011E24(gm_804D682C, &ptcl_jobj2, - *(s32*) ((u8*) gm_803DBFD8 + - entry_idx * 4 + 0x11F0), + gm_803DD1C8.particles[entry_idx], -1); if (entry_idx == 0) { - p = ptcl_jobj2->u.ptcl; + p = (StaffRollPtclNode*) + ptcl_jobj2->u.ptcl; tally_color = *(s32*) &gm_804D42CC; - p = *(void**) ((u8*) p + 4); - p = *(void**) ((u8*) p + 4); - p = *(void**) ((u8*) p + 4); - p = *(void**) ((u8*) p + 8); - p = *(void**) ((u8*) p + 0xC); - *(s32*) ((u8*) p + 4) = tally_color; + p = p->x4.ptr; + p = p->x4.ptr; + p = p->x4.ptr; + p = p->x8; + p = p->xC; + p->x4.color = tally_color; } else if ((unsigned) (entry_idx - 2) <= 1u) { - p = ptcl_jobj2->u.ptcl; + p = (StaffRollPtclNode*) + ptcl_jobj2->u.ptcl; tally_color = *(s32*) &gm_804D42CC; - p = *(void**) ((u8*) p + 4); - p = *(void**) ((u8*) p + 8); - p = *(void**) ((u8*) p + 0xC); - *(s32*) ((u8*) p + 4) = tally_color; + p = p->x4.ptr; + p = p->x8; + p = p->xC; + p->x4.color = tally_color; } else { - p = ptcl_jobj2->u.ptcl; + p = (StaffRollPtclNode*) + ptcl_jobj2->u.ptcl; tally_color = *(s32*) &gm_804D42CC; - p = *(void**) ((u8*) p + 8); - p = *(void**) ((u8*) p + 0xC); - *(s32*) ((u8*) p + 4) = tally_color; + p = p->x8; + p = p->xC; + p->x4.color = tally_color; } } else { staffInfo[entry_idx].win[0]->active_color = @@ -714,7 +728,7 @@ void fn_801AB200(HSD_GObj* gobj) gm_804D6810 = entry_data->x0; if (j == 0) { - x_pos = ((f32*) ((u8*) gm_803DBFD8 + 0xF78))[gm_804D6810]; + x_pos = gm_803DBFD8_extra.x_positions[gm_804D6810]; gm_80480D58[0] = HSD_SisLib_803A5ACC( 0, 0, 1.45f + x_pos, 0.86f, 0.0f, 0.0f, 100.0f); } else if (j == 1) { @@ -728,12 +742,12 @@ void fn_801AB200(HSD_GObj* gobj) } else { offset2 = 0.0f; } - x_pos = ((f32*) ((u8*) gm_803DBFD8 + 0xF78))[gm_804D6810]; + x_pos = gm_803DBFD8_extra.x_positions[gm_804D6810]; gm_80480D58[1] = HSD_SisLib_803A5ACC( 0, 0, offset2 + (3.0f + x_pos + offset1), 0.86f, 0.0f, 0.0f, 100.0f); } else { - x_pos = ((f32*) ((u8*) gm_803DBFD8 + 0xF78))[gm_804D6810]; + x_pos = gm_803DBFD8_extra.x_positions[gm_804D6810]; text_arr[j] = HSD_SisLib_803A5ACC( 0, 0, 1.45f + x_pos, (0.19f * (f32) j) + 0.67f, 0.0f, 0.0f, 100.0f); @@ -807,31 +821,29 @@ void fn_801AB200(HSD_GObj* gobj) if (staffInfo[selected].x8 >= 1) { if (selected < 7) { lb_80011E24(gm_804D682C, &ptcl_jobj3, - *(s32*) ((u8*) gm_803DBFD8 + selected * 4 + - 0x11F0), - -1); + gm_803DD1C8.particles[selected], -1); if (selected == 0) { - p = ptcl_jobj3->u.ptcl; + p = (StaffRollPtclNode*) ptcl_jobj3->u.ptcl; tally_color = *(s32*) &gm_804D42C8; - p = *(void**) ((u8*) p + 4); - p = *(void**) ((u8*) p + 4); - p = *(void**) ((u8*) p + 4); - p = *(void**) ((u8*) p + 8); - p = *(void**) ((u8*) p + 0xC); - *(s32*) ((u8*) p + 4) = tally_color; + p = p->x4.ptr; + p = p->x4.ptr; + p = p->x4.ptr; + p = p->x8; + p = p->xC; + p->x4.color = tally_color; } else if ((unsigned) (selected - 2) <= 1u) { - p = ptcl_jobj3->u.ptcl; + p = (StaffRollPtclNode*) ptcl_jobj3->u.ptcl; tally_color = *(s32*) &gm_804D42C8; - p = *(void**) ((u8*) p + 4); - p = *(void**) ((u8*) p + 8); - p = *(void**) ((u8*) p + 0xC); - *(s32*) ((u8*) p + 4) = tally_color; + p = p->x4.ptr; + p = p->x8; + p = p->xC; + p->x4.color = tally_color; } else { - p = ptcl_jobj3->u.ptcl; + p = (StaffRollPtclNode*) ptcl_jobj3->u.ptcl; tally_color = *(s32*) &gm_804D42C8; - p = *(void**) ((u8*) p + 8); - p = *(void**) ((u8*) p + 0xC); - *(s32*) ((u8*) p + 4) = tally_color; + p = p->x8; + p = p->xC; + p->x4.color = tally_color; } } else { staffInfo[selected].win[0]->active_color = gm_804D42C8; @@ -894,9 +906,8 @@ void fn_801AB200(HSD_GObj* gobj) } } - line_num = HSD_SisLib_803A6B98( - gm_804D680C, 0.0f, 0.0f, (char*) ((u8*) gm_803DBFD8 + 0x1264), - tally_count); + line_num = HSD_SisLib_803A6B98(gm_804D680C, 0.0f, 0.0f, + "%d \x82g\x82h\x82s", tally_count); HSD_SisLib_803A74F0(gm_804D680C, line_num, (GXColor*) &tally_color2); @@ -924,7 +935,7 @@ void fn_801AB200(HSD_GObj* gobj) } HSD_JObjSetTranslateX(jobj_pair[0], - ((f32*) ((u8*) gm_803DBFD8 + 0xF78))[gm_804D6810]); + gm_803DBFD8_extra.x_positions[gm_804D6810]); if (button == 0x1000) { if (gm_804D681C == 1) { @@ -969,9 +980,9 @@ void fn_801AB200(HSD_GObj* gobj) gm_804D6820 = 0x3C; } - if (gm_804D6814 >= *(s32*) ((u8*) gm_803DBFD8 + gm_804D684C * 8 + 0xF88)) { - lbAudioAx_800237A8( - *(s32*) ((u8*) gm_803DBFD8 + gm_804D684C * 8 + 0xF8C), 0x7F, 0x40); + if (gm_804D6814 >= gm_803DBFD8_extra.sfx_cues[gm_804D684C].frame) { + lbAudioAx_800237A8(gm_803DBFD8_extra.sfx_cues[gm_804D684C].sfx, 0x7F, + 0x40); gm_804D684C += 1; } } @@ -987,10 +998,6 @@ void fn_801AC67C(HSD_GObj* gobj) } } -/* 3DD23C */ static char gm_803DD23C[] = { - 0x25, 0x64, 0x20, 0x82, 0x67, 0x82, 0x68, 0x82, 0x73, 0, -}; - void gm_801AC6D8_OnEnter(void* unused) { HSD_JObj* jobj_arr[2]; @@ -999,6 +1006,7 @@ void gm_801AC6D8_OnEnter(void* unused) int const gx_link = 11; int i; HSD_GObj* gobj; + HSD_GObj* final_gobj; PAD_STACK(0x10); efLib_Init(); @@ -1006,7 +1014,7 @@ void gm_801AC6D8_OnEnter(void* unused) staffInfo = HSD_MemAlloc(sizeof(struct staffInfo_t)); staffInfoSortBuf = HSD_MemAlloc(sizeof(struct staffInfoSortBuf_t)); HSD_SisLib_803A62A0(0, "SdStRoll.dat", "SIS_StRollData"); - HSD_SisLib_803A611C(0, (void*) -1, 9, 13, 0, 18, 0, 19); + HSD_SisLib_803A611C(0, (HSD_GObj*) -1, 9, 13, 0, 18, 0, 19); lbAudioAx_80026F2C(28); lbAudioAx_8002702C(16, 0x4000000000000ULL); lbAudioAx_80027168(); @@ -1092,15 +1100,15 @@ void gm_801AC6D8_OnEnter(void* unused) HSD_GObj_SetupProc(gobj, fn_801AAB74, 1); } { - HSD_GObj* gobj = GObj_Create(14, 15, 0); + final_gobj = GObj_Create(14, 15, 0); jobj = HSD_JObjLoadJoint(gm_804D6840->models[0]->joint); - HSD_GObjObject_80390A70(gobj, HSD_GObj_804D7849, jobj); - GObj_SetupGXLink(gobj, HSD_GObj_JObjCallback, gx_link, 0); + HSD_GObjObject_80390A70(final_gobj, HSD_GObj_804D7849, jobj); + GObj_SetupGXLink(final_gobj, HSD_GObj_JObjCallback, gx_link, 0); gm_8016895C(jobj, gm_804D6840->models[0], 0); lb_80011E24(jobj, jobj_arr, ARRAY_SIZE(jobj_arr), 20, -1); HSD_JObjReqAnimAll(jobj_arr[0], 0.0F); HSD_JObjReqAnimAll(jobj_arr[1], 0.0F); - HSD_GObj_SetupProc(gobj, fn_801AB200, 13); + HSD_GObj_SetupProc(final_gobj, fn_801AB200, 13); } lbAudioAx_80027648(); { diff --git a/src/melee/gm/gmtou_0.c b/src/melee/gm/gmtou_0.c index 4e7a425c42..a6e1803a61 100644 --- a/src/melee/gm/gmtou_0.c +++ b/src/melee/gm/gmtou_0.c @@ -36,6 +36,75 @@ #include #include +static void sdata2_order(void) +{ + (void) 4.5f; + (void) 130.0f; + (void) -278.0f; + (void) 255.0f; + (void) 0.0f; + (void) 537.0f; + (void) 149.0f; + (void) 409.0f; + (void) 47.0f; + (void) 143.0f; + (void) 183.0f; + (void) 48.5999985f; + (void) 514.0f; + (void) 87.0f; + (void) S32_TO_F32; + (void) U32_TO_F32; + (void) 1.0f; + (void) 16.0f; + (void) 6.0f; + (void) 5.0f; + (void) 25.0f; + (void) 666.0f; + (void) 12.8000078f; + (void) 2.62000084f; + (void) 0.100000001f; + (void) 201.0f; + (void) 200.0f; + (void) 0.899999976f; + (void) -1.79999995f; + (void) 7.18999958f; + (void) 2.70000005f; + (void) 2.29999995f; + (void) 0.300000012f; + (void) 11.5f; + (void) 3.5f; + (void) -12.3000011f; + (void) 0.649999976f; + (void) 0.660000026f; + (void) -3.0f; + (void) 4.5000062f; + (void) 0.200000003f; + (void) -1.0f; + (void) 10.0999928f; + (void) 28195.498f; + (void) 124.5f; + (void) 45.0f; + (void) 391.0f; + (void) 30.0f; + (void) 393.0f; + (void) 221.699997f; + (void) 360.0f; + (void) 40.0f; + (void) 160.0f; + (void) 48.0f; + (void) 123.0f; + (void) 113.0f; + (void) 35.7000008f; + (void) 343.0f; + (void) 0.5f; + (void) 0.579999983f; + (void) 0.550000012f; + (void) 0.850000024f; + (void) 1.35000002f; + (void) -19.5f; + (void) 13.0f; +} + /* 4D664C */ extern SceneDesc* lbl_804D664C; /* 4DA704 */ extern f32 lbl_804DA704; // 48.6f /* 4DA708 */ extern f32 lbl_804DA708; // 514.0f @@ -61,6 +130,7 @@ typedef void (*lbl_803D9FD8_fn)(s32*, u32, u32); void fn_80190ABC(int mode) { + struct Lbl804799B8_t* state = &lbl_804799B8; u8* table = (u8*) &lbl_803D9F80; TmData* tm; s32 cur_opt; @@ -77,17 +147,17 @@ void fn_80190ABC(int mode) switch (mode) { case 0: { - s32 flag = !!gm_804771C4.match_type; - HSD_SisLib_803A6368(tm->x4E0, *(u16*) (table + opt * 4 + flag * 2)); + HSD_SisLib_803A6368(tm->x4E0, *(u16*) (table + opt * 4 + + !!gm_804771C4.match_type * 2)); break; } - case 1: { - s32 flag = !!gm_804771C4.match_type; - HSD_SisLib_803A6368(tm->x4E8[opt], - *(u16*) (table + opt * 4 + flag * 2 + 0x1C)); + case 2: { + HSD_SisLib_803A6368( + tm->x4E8[opt], + *(u16*) (table + opt * 4 + !!gm_804771C4.match_type * 2 + 0x1C)); break; } - case 2: { + case 3: { s32 display_val; if (opt == 2 && gm_804771C4.match_type == 0) { s32 val = (&tm->match_type)[opt]; @@ -112,12 +182,11 @@ void fn_80190ABC(int mode) } else { display_val = *(u16*) (table + opt * 2 + 0x34) + (&tm->match_type)[opt]; - (void) display_val; } HSD_SisLib_803A6368(tm->x500[opt], display_val); break; } - case 3: { + case 1: { s32 display_val = lbl_803D9D20.x0[tm->entrants] + 0xB0 - tm->hmn_cpu_count; HSD_SisLib_803A6368(tm->x4E4, display_val); @@ -125,52 +194,43 @@ void fn_80190ABC(int mode) } case 4: { HSD_SisLib_803A7664(tm->x518[0]); - { - f32 f_col_mul = 149.0f; - f32 f_col_add = 537.0f; - f32 f_row_mul = 47.0f; - f32 f_row_add = 409.0f; - for (i = 0; i < 0x24; i++) { - s32 col = i % 4; - s32 row = i / 4; - f32 pos_x = f_col_mul * (f32) col + f_col_add; - f32 pos_y = f_row_mul * (f32) row + f_row_add; - fn_8018ECA8(i + lbl_804799B8.x6 * 4, 0xFF, 0, pos_x, pos_y, 0); - } + for (i = 0; i < 0x24; i++) { + fn_8018ECA8(i + state->x6 * 4, 0xFF, 0, + 149.0f * (f32) (i % 4) + 537.0f, + 47.0f * (f32) (i / 4) + 409.0f, 0); } break; } - case 5: { + case 6: { + u8* start = &state->x3; HSD_SisLib_803A7664(tm->x518[1]); HSD_SisLib_803A7664(tm->x518[2]); - { - f32 f_mul = lbl_804DA704; - f32 f_add = lbl_804DA700; - for (i = 0; i < 12; i++) { - s32 idx = lbl_804799B8.x3 + i; - if (idx > lbl_804799B8.x4) { - continue; - } - { - f32 pos_y = f_mul * (f32) i + f_add; - fn_8018ECA8(tm->x37[idx].x9, tm->x37[idx].x0, 1, - lbl_804DA6FC, pos_y, 2); - idx = lbl_804799B8.x3 + i; - fn_8018ECA8(tm->x37[idx].x9, tm->x37[idx].x0, 1, - lbl_804DA6FC, pos_y, 2); - } + for (i = 0; i < 12; i++) { + s32 idx = *start + i; + if (idx > state->x4) { + continue; + } + { + f32 pos_y = lbl_804DA704 * (f32) i + lbl_804DA700; + fn_8018ECA8(tm->x37[idx].x9, tm->x37[idx].x0, 1, lbl_804DA6FC, + pos_y, 2); + idx = *start + i; + fn_8018ECA8(tm->x37[idx].x9, tm->x37[idx].x0, 1, lbl_804DA6FC, + pos_y, 2); } } break; } - case 6: { + case 5: { s32 idx; + u8* x2 = &state->x2; + u8* x3 = &state->x3; HSD_SisLib_803A7664(tm->x524[0]); HSD_SisLib_803A7664(tm->x524[1]); - idx = lbl_804799B8.x2 + lbl_804799B8.x3; + idx = *x2 + *x3; fn_8018ECA8(tm->x37[idx].x9, tm->x37[idx].x0, 3, lbl_804DA708, lbl_804DA70C, 4); - idx = lbl_804799B8.x2 + lbl_804799B8.x3; + idx = *x2 + *x3; fn_8018ECA8(tm->x37[idx].x9, tm->x37[idx].x0, 3, lbl_804DA708, lbl_804DA70C, 4); break; @@ -263,21 +323,22 @@ void fn_801910E0(HSD_GObj* gobj) void fn_80191154(HSD_GObj* gobj) { + u8* base_ptr; TmData* tm; HSD_JObj* jobj; u8* xE_ptr; + u8 val; + base_ptr = &lbl_804799B8.x0; tm = gm_8018F634(); jobj = gobj->hsd_obj; if (tm->cur_option < 9) { - xE_ptr = &lbl_804799B8.xE; - if (*xE_ptr > 0x27U) { + if ((u8) *(xE_ptr = base_ptr + 0xE) > 0x27U) { *xE_ptr = 0xA; } } else { - xE_ptr = &lbl_804799B8.xE; - if (lbl_804799B8.xE == 0x31) { + if ((u8) *(xE_ptr = base_ptr + 0xE) == 0x31) { fn_80190ABC(6); fn_80190ABC(5); tm->cur_option = 0xA; @@ -286,9 +347,9 @@ void fn_80191154(HSD_GObj* gobj) *xE_ptr = 0x32; } } - xE_ptr = &lbl_804799B8.xE; - fn_8019044C(jobj, (float) lbl_804799B8.xE); - (*xE_ptr)++; + val = *(base_ptr += 0xE); + fn_8019044C(jobj, (f32) val); + *base_ptr = *base_ptr + 1; } static inline u8 fn_80191240_dec_flash_timer(void) @@ -413,7 +474,7 @@ void fn_801913BC(HSD_GObj* gobj) tm->x500[idx]->hidden = 1; } - if (tm->cur_option >= 3 && tm->match_type == 0) { + if (tm->cur_option >= 3 && gm_804771C4.match_type == 0) { tm->x4E4->hidden = 0; } else { tm->x4E4->hidden = 1; @@ -421,8 +482,8 @@ void fn_801913BC(HSD_GObj* gobj) cur = tm->cur_option; if ((s32) idx == cur) { - counter_ptr = &(&lbl_804799B8.x0)[0x10 + idx]; - if (*counter_ptr >= 0x14U) { + counter_ptr = &lbl_804799B8.x0 + idx; + if (*(counter_ptr += 0x10) >= 0x14U) { *counter_ptr = 0xA; } fn_8019044C(jobj, (f32) *counter_ptr); @@ -490,10 +551,10 @@ void fn_80191678(HSD_GObj* gobj) HSD_JObjSetFlagsAll(jobj, JOBJ_HIDDEN); } -/// @todo Currently 99.84% match - remaining mismatch is stack slot placement /// Updates menu option selection animation. void fn_8019175C(HSD_GObj* gobj) { + UNUSED u8 pad[8]; HSD_JObj* jobjs[3]; HSD_JObj* first_child; HSD_JObj* option_a; @@ -507,7 +568,7 @@ void fn_8019175C(HSD_GObj* gobj) tm = gm_8018F634(); fn_8018F62C(gobj); - root_jobj = GET_JOBJ(gobj); + root_jobj = gobj->hsd_obj; jobj = root_jobj; if (tm->cur_option >= 9) { @@ -794,19 +855,28 @@ void fn_80191E9C(HSD_GObj* gobj) fn_8019044C(jobj, (f32) tm->x37[idx].x2); } +static inline int fn_80191FD4_is_selected(u32 hud, s32 slot, TmData* tm) +{ + return (s32) tm->x37[slot].x3 == hud; +} + void fn_80191FD4(HSD_GObj* gobj) { TmData* tm; HSD_JObj* jobj; HSD_JObj* child; HSD_JObj* sibling; - u32 idx; s32 slot; + u32 idx; enum CSSIconHud hud; + struct Lbl804799B8_t* state; + u8* x3_ptr; + u8* x2_ptr; + state = &lbl_804799B8; tm = gm_8018F634(); - jobj = gobj->hsd_obj; idx = fn_8018F62C(gobj); + jobj = gobj->hsd_obj; if ((s32) tm->cur_option <= 9) { HSD_JObjSetFlagsAll(jobj, JOBJ_HIDDEN); @@ -828,30 +898,29 @@ void fn_80191FD4(HSD_GObj* gobj) } else { sibling = child->next; } - slot = lbl_804799B8.x2 + lbl_804799B8.x3; + x2_ptr = &state->x2; + x3_ptr = &state->x3; + slot = *x2_ptr + *x3_ptr; - if ((u8) tm->x37[slot].x4 != 0) { + if ((u8) tm->x37[slot].x5 != 0) { fn_8019044C(sibling, 201.0f); return; } - fn_8019044C(sibling, fn_8018F71C((s32) tm->x37[slot].x2, - (s32) tm->x37[slot].x6)); + fn_8019044C(sibling, fn_8018F71C((s32) tm->x37[slot].x3, + (s32) tm->x37[slot].x7)); + if (lbl_803D9D20.x72[tm->x37[*x2_ptr + *x3_ptr].x3] != 0) { + HSD_JObjClearFlagsAll(sibling, JOBJ_HIDDEN); + return; + } + if (fn_8018F3D0(fn_8018F310(fn_8018F6FC( + (enum CSSIconHud) tm->x37[*x2_ptr + *x3_ptr].x3))) == 1) { - u8 chr = tm->x37[lbl_804799B8.x2 + lbl_804799B8.x3].x2; - if (lbl_803D9D20.x72[chr] != 0) { - HSD_JObjClearFlagsAll(sibling, JOBJ_HIDDEN); - return; - } - if (fn_8018F3D0(fn_8018F310(fn_8018F6FC((enum CSSIconHud) chr))) == - 1) - { - fn_8019044C(sibling, 200.0f); - return; - } - HSD_JObjSetFlagsAll(sibling, JOBJ_HIDDEN); + fn_8019044C(sibling, 200.0f); return; } + HSD_JObjSetFlagsAll(sibling, JOBJ_HIDDEN); + return; } if ((s32) tm->cur_option != 0xB) { @@ -867,9 +936,11 @@ void fn_80191FD4(HSD_GObj* gobj) } hud = fn_8018F6DC(fn_8018F3BC((s32) idx)); - slot = lbl_804799B8.x2 + lbl_804799B8.x3; - if ((s32) tm->x37[slot].x2 == hud) { - fn_8019044C(child, (f32) (lbl_804799B8.xA + 0xA)); + x2_ptr = &state->x2; + x3_ptr = &state->x3; + slot = *x2_ptr + *x3_ptr; + if (fn_80191FD4_is_selected(hud, slot, tm)) { + fn_8019044C(child, (f32) (state->xA + 0xA)); } else { hud = fn_8018F6DC(fn_8018F3BC((s32) idx)); { @@ -898,10 +969,11 @@ void fn_80191FD4(HSD_GObj* gobj) hud = fn_8018F6DC(fn_8018F3BC((s32) idx)); if (lbl_803D9D20.x72[hud] != 0) { - slot = lbl_804799B8.x2 + lbl_804799B8.x3; - if ((s32) tm->x37[slot].x2 == fn_8018F6DC(fn_8018F3BC((s32) idx))) { - fn_8019044C(sibling, (f32) ((tm->x37[slot].x6 * 0x1E) + - fn_8018F6DC(fn_8018F3BC((s32) idx)))); + slot = *x2_ptr + *x3_ptr; + if ((s32) tm->x37[slot].x3 == fn_8018F6DC(fn_8018F3BC((s32) idx))) { + fn_8019044C(sibling, + (f32) ((tm->x37[*x2_ptr + *x3_ptr].x7 * 0x1E) + + fn_8018F6DC(fn_8018F3BC((s32) idx)))); return; } fn_8019044C(sibling, (f32) fn_8018F6DC(fn_8018F3BC((s32) idx))); @@ -948,18 +1020,23 @@ void fn_8019237C(HSD_GObj* gobj) lbl_804DA734); } -/// @todo Currently 92.46% match - permuter couldn't improve +static inline HSD_JObj* fn_8019249C_get_jobj(HSD_GObj* gobj) +{ + return gobj->hsd_obj; +} + void fn_8019249C(HSD_GObj* gobj) { TmData* tmdata; HSD_JObj* jobj; HSD_JObj* child; HSD_JObj* child2; + HSD_JObj* child3; int cur_option; tmdata = gm_8018F634(); cur_option = tmdata->cur_option; - jobj = gobj->hsd_obj; + jobj = fn_8019249C_get_jobj(gobj); if (cur_option <= 9) { HSD_JObjSetFlagsAll(jobj, JOBJ_HIDDEN); @@ -980,14 +1057,17 @@ void fn_8019249C(HSD_GObj* gobj) child = HSD_JObjGetNext(child); child = HSD_JObjGetNext(child); child = HSD_JObjGetNext(child); + HSD_JObjGetNext(child); child2 = HSD_JObjGetNext(child); child2 = HSD_JObjGetNext(child2); child2 = HSD_JObjGetNext(child2); if (child2 == NULL) { - child2 = NULL; + child3 = NULL; } else { - child2 = child2->next; + child3 = child2->next; } + child2 = child3; + HSD_JObjGetNext(child2); if (cur_option == 0xD) { fn_8019044C(child, 0.0F); @@ -1022,22 +1102,23 @@ void fn_80192690(HSD_GObj* gobj) #pragma pop /// @todo Currently 98.3% match - remaining mismatch is instruction scheduling +static inline HSD_JObj* fn_80192758_get_jobj(HSD_GObj* gobj, + struct Lbl804799B8_t* data) +{ + return gobj->hsd_obj; +} + void fn_80192758(HSD_GObj* gobj) { TmData* tmdata; - u8 val; - u8* data; - u8* data3; - u8* data2; - HSD_JObj* child; HSD_JObj* jobj; + struct Lbl804799B8_t* data; + HSD_JObj* child; + u8 val; - data = (u8*) &lbl_804799B8; + data = &lbl_804799B8; tmdata = gm_8018F634(); - { - HSD_JObj* tmp_p26447 = gobj->hsd_obj; - jobj = tmp_p26447; - } + jobj = fn_80192758_get_jobj(gobj, data); if (tmdata->cur_option <= 9) { HSD_JObjSetFlagsAll(jobj, JOBJ_HIDDEN); @@ -1046,16 +1127,15 @@ void fn_80192758(HSD_GObj* gobj) HSD_JObjClearFlagsAll(jobj, JOBJ_HIDDEN); - if (data[0] == 0) { + if (data->x0 == 0) { HSD_JObjSetFlagsAll(jobj, JOBJ_HIDDEN); return; } - data2 = data + 2; - data3 = data + 3; - fn_8019044C(jobj, (float) tmdata->x37[data2[0] + data3[0]].x2); + fn_8019044C(jobj, + (float) tmdata->x37[lbl_804799B8.x2 + lbl_804799B8.x3].x2); - if (data[1] != 0) { + if (data->x1 != 0) { if (jobj == NULL) { child = NULL; } else { @@ -1067,7 +1147,7 @@ void fn_80192758(HSD_GObj* gobj) child = (child == NULL) ? NULL : child->next; HSD_JObjClearFlags(child, JOBJ_HIDDEN); - val = tmdata->x37[data2[0] + data3[0]].x2; + val = tmdata->x37[lbl_804799B8.x2 + lbl_804799B8.x3].x2; if (val == 9) { child = (jobj == NULL) ? NULL : jobj->child; HSD_JObjSetFlags(child, JOBJ_HIDDEN); @@ -1095,10 +1175,11 @@ extern s32 lbl_804D665C; #pragma inline_depth(0) s32 fn_80192938(void) { - TmData* tm; + struct Lbl804799B8_t* state = &lbl_804799B8; s32 i; - s32 j; + TmData* tm; s32 start; + s32 j; s32 a, b; u8 tmp; u8 handicap; @@ -1119,23 +1200,23 @@ s32 fn_80192938(void) } for (i = 0; i < 0x40; i++) { - tm->x37[i].x4 = 0; - tm->x37[i].xB = (u8) i; + tm->x37[i].x5 = 0; + tm->x37[i].xD = (u8) i; if ((u8) gmMainLib_8015CC34()->handicap == 1) { if ((s32) gm_804771C4.match_type == 0) { gmMainLib_8015CC34()->handicap = 0; - tm->x37[i].x1 = 9; + tm->x37[i].x2 = 9; } else { - tm->x37[i].x1 = 5; + tm->x37[i].x2 = 5; } } else { - tm->x37[i].x1 = 9; + tm->x37[i].x2 = 9; } - tm->x37[i].x2 = fn_8018F410(); - tm->x37[i].x6 = HSD_Randi( - (s32) gm_80169238(fn_8018F6FC((enum CSSIconHud) tm->x37[i].x2))); + tm->x37[i].x3 = fn_8018F410(); + tm->x37[i].x7 = HSD_Randi( + (s32) gm_80169238(fn_8018F6FC((enum CSSIconHud) tm->x37[i].x3))); if (i < (s32) tm->x2E) { ((u8*) &tm->x37[i])[-1] = 1; @@ -1148,9 +1229,9 @@ s32 fn_80192938(void) if (((s32) gm_804771C4.match_type == 0) && ((s32) tm->cpu_level == 0)) { - tm->x37[i].x0 = HSD_Randi(9) + 1; + tm->x37[i].x1 = HSD_Randi(9) + 1; } else { - tm->x37[i].x0 = (u8) tm->cpu_level; + tm->x37[i].x1 = (u8) tm->cpu_level; } } } else { @@ -1173,23 +1254,23 @@ s32 fn_80192938(void) for (j = 0; j < 0x3E8; j++) { a = start + HSD_Randi(tm->x2E - start); b = start + HSD_Randi(tm->x2E - start); - tmp = tm->x37[a].xB; - tm->x37[a].xB = tm->x37[b].xB; - tm->x37[b].xB = tmp; + tmp = tm->x37[a].xD; + tm->x37[a].xD = tm->x37[b].xD; + tm->x37[b].xD = tmp; } } - lbl_804799B8.x2 = 0; - lbl_804799B8.x3 = 0; - lbl_804799B8.x4 = 0xB; - lbl_804799B8.x5 = 0; - lbl_804799B8.x6 = 0; + state->x2 = 0; + state->x3 = 0; + state->x4 = 0xB; + state->x5 = 0; + state->x6 = 0; handicap = gmMainLib_8015CC34()->handicap; - lbl_804799B8.x0 = handicap; + state->x0 = handicap; tm->x24 = 0; tm->pad_x34[0] = 0xFF; tm->x33 = 0xFF; - return (s32) handicap; + return handicap & 0xFF; } #pragma pop @@ -1405,8 +1486,12 @@ void fn_801935B8(void) TmData* tm; HSD_GObj* gobj; HSD_Fog* fog; + struct Lbl804799B8_t* state; + TmSettingTable* table; s32 i; + state = &lbl_804799B8; + table = &lbl_803D9F80; tm = gm_8018F634(); fn_8018FBE0(0, 0, 0, 5, 5, 0x3e7, 3); fn_801902F0((s32) fn_80190174(lbl_804D664C->cameras->desc)); @@ -1422,19 +1507,19 @@ void fn_801935B8(void) GObj_SetupGXLink(gobj, HSD_GObj_FogCallback, 0, 0); lbl_804D6658 = 0; - lbl_804799B8.xC_counter = 0; - lbl_804799B8.xE = 0; - lbl_804799B8.xF = 0; - lbl_804799B8.pad2[12] = 0; + state->xC_counter = 0; + state->xE = 0; + state->xF = 0; + state->pad2[12] = 0; for (i = 0; i < 6; i++) { - lbl_804799B8.pad2[i] = 0xa; - lbl_804799B8.pad2[i + 6] = 0; - (&tm->match_type)[i] = ((u8*) &lbl_803D9F80)[0x40 + i * 2]; + state->pad2[i] = 0xa; + state->pad2[i + 6] = 0; + (&tm->match_type)[i] = table->min[i][0]; } - lbl_804799B8.x1 = 0; - lbl_804799B8.x0 = gmMainLib_8015CC34()->handicap; + state->x1 = 0; + state->x0 = gmMainLib_8015CC34()->handicap; tm->x32 = 0; for (i = 0; i < 25; i++) { @@ -1449,33 +1534,30 @@ void fn_801937C4(s32* arg0, u32 arg1, u32 arg2) s32 idx; s32* ptr; s32 val; - u8* entry; + TmData* global; + table = lbl_803D9F80.pad_0; if (arg1 & 0x40001) { lbAudioAx_80024030(2); lbl_804799B8.x7 = 5; - table = (u8*) &lbl_803D9F80; idx = arg0[0]; - entry = table + (idx << 1) + (gm_804771C4.match_type != 0); ptr = arg0 + idx; val = *++ptr; - if (val > (s32) entry[0x40]) { + if (val > (s32) table[(idx << 1) + !!gm_804771C4.match_type + 0x40]) { *ptr = val - 1; } else { - *ptr = (s32) entry[0x4C]; + *ptr = (s32) table[(idx << 1) + !!gm_804771C4.match_type + 0x4C]; } } else if (arg1 & 0x80002) { lbAudioAx_80024030(2); lbl_804799B8.x8 = 5; - table = (u8*) &lbl_803D9F80; idx = arg0[0]; - entry = table + (idx << 1) + (gm_804771C4.match_type != 0); ptr = arg0 + idx; val = *++ptr; - if (val < (s32) entry[0x4C]) { + if (val < (s32) table[(idx << 1) + !!gm_804771C4.match_type + 0x4C]) { *ptr = val + 1; } else { - *ptr = (s32) entry[0x40]; + *ptr = (s32) table[(idx << 1) + !!gm_804771C4.match_type + 0x40]; } } @@ -1488,24 +1570,19 @@ void fn_801937C4(s32* arg0, u32 arg1, u32 arg2) } if (arg2 & 0x100) { - u32 remaining; u8* tp; s32* dp; lbAudioAx_80024030(1); - table = (u8*) &lbl_803D9F80; - (void) table; idx = arg0[0]; + global = &gm_804771C4; arg0[0] = idx + 1; idx = arg0[0]; tp = table + (idx << 1); dp = arg0 + idx; - remaining = 6 - idx; - if (idx < 6) { - for (; remaining > 0; remaining--) { - *++dp = tp[(gm_804771C4.match_type != 0) + 0x40]; - tp += 2; - } + for (; idx < 6; idx++) { + *++dp = tp[(global->match_type != 0) + 0x40]; + tp += 2; } if (gm_804771C4.match_type == 0) { if (fn_8018F808() < 2) { @@ -1549,6 +1626,11 @@ static inline u8 TmSettingTable_GetMax(s32 idx, int match_type) return table->max[idx][match_type != 0]; } +static inline s32 TmSetting_GetNextValue(s32* ptr) +{ + return *++ptr; +} + void fn_80193B58(s32* arg0, u32 arg1, u32 arg2) { struct Lbl804799B8_t* state = &lbl_804799B8; @@ -1581,7 +1663,7 @@ void fn_80193B58(s32* arg0, u32 arg1, u32 arg2) idx = arg0[0]; ptr = arg0 + idx; (void) ptr; - val = *++ptr; + val = TmSetting_GetNextValue(ptr); if (val > (s32) TmSettingTable_GetMin(idx, *mt)) { *ptr = val - 1; lbAudioAx_80024030(2); @@ -1712,68 +1794,70 @@ void fn_80193B58(s32* arg0, u32 arg1, u32 arg2) void fn_80193FCC(s32* arg0, u32 arg1, u32 arg2) { + struct Lbl804799B8_t* state = &lbl_804799B8; u8* table = (u8*) &lbl_803D9F80; s32 idx; s32* ptr; s32 val; u8* entry; s32 clamp_val; + s32 clamp_expr; int* mt = &gm_804771C4.match_type; TmData* tm; - u8 operand_pad[4]; if (*mt != 0) { lbl_804D665C = fn_8018F808(); } if (*mt != 0) { - if (fn_8018F808() < 2) { - clamp_val = 2; - } else { - clamp_val = fn_8018F808(); - } + clamp_expr = MAX(2, fn_8018F808()); + clamp_val = clamp_expr; idx = arg0[0]; ptr = arg0 + idx; val = *++ptr; - if (val > clamp_val) { - *ptr = clamp_val; + if (val > clamp_expr) { + *ptr = clamp_expr; fn_80190ABC(3); } } if (arg1 & 0x40001) { if (*mt != 0) { + u8* min_entry = table + 0x40; idx = arg0[0]; - entry = table + (idx << 1) + (*mt != 0); ptr = arg0 + idx; - (void) ptr; - val = *++ptr; - if (val > (s32) entry[0x40]) { + { + s32 next = *++ptr; + val = next; + } + clamp_expr = idx << 1; + if (val > (s32) min_entry[clamp_expr + (*mt != 0)]) { *ptr = val - 1; lbAudioAx_80024030(2); - lbl_804799B8.x7 = 5; + state->x7 = 5; } else { - s32 max_plus1 = (s32) entry[0x4C] + 1; + s32 max_plus1 = + (s32) table[clamp_expr + (*mt != 0) + 0x4C] + 1; if (clamp_val < max_plus1) { *ptr = clamp_val; } else { *ptr = max_plus1; } idx = arg0[0]; - entry = table + (idx << 1) + (*mt != 0); val = arg0[idx + 1]; - if (val != (s32) entry[0x40]) { + clamp_expr = (*mt != 0); + if (val != (s32) min_entry[(idx << 1) + clamp_expr]) { lbAudioAx_80024030(2); - lbl_804799B8.x7 = 5; + state->x7 = 5; } } } else { lbAudioAx_80024030(2); - lbl_804799B8.x7 = 5; + state->x7 = 5; idx = arg0[0]; - entry = table + (idx << 1) + (*mt != 0); ptr = arg0 + idx; val = *++ptr; + entry = table + (idx << 1) + (*mt != 0); if (val > (s32) entry[0x40]) { *ptr = val - 1; } else { @@ -1810,41 +1894,41 @@ void fn_80193FCC(s32* arg0, u32 arg1, u32 arg2) } } else if (arg1 & 0x80002) { if (*mt != 0) { + u8* max_entry = table + 0x4C; idx = arg0[0]; - entry = table + (idx << 1) + (*mt != 0); ptr = arg0 + idx; val = *++ptr; - if (val < (s32) entry[0x4C] + 1) { + clamp_expr = (idx << 1) + (*mt != 0); + if (val < (s32) max_entry[clamp_expr] + 1) { if (val + 1 <= clamp_val && val + 1 < arg0[2]) { *ptr = val + 1; lbAudioAx_80024030(2); - lbl_804799B8.x8 = 5; + state->x8 = 5; goto after_right; } - *ptr = (s32) entry[0x40]; + *ptr = (s32) table[clamp_expr + 0x40]; idx = arg0[0]; val = arg0[idx + 1]; if (val != clamp_val) { lbAudioAx_80024030(2); - lbl_804799B8.x8 = 5; + state->x8 = 5; } } else { - *ptr = (s32) entry[0x40]; + *ptr = (s32) table[clamp_expr + 0x40]; idx = arg0[0]; - entry = table + (idx << 1) + (*mt != 0); val = arg0[idx + 1]; - if (val != (s32) entry[0x4C] + 1) { + if (val != (s32) max_entry[(idx << 1) + (*mt != 0)] + 1) { lbAudioAx_80024030(2); - lbl_804799B8.x8 = 5; + state->x8 = 5; } } } else { lbAudioAx_80024030(2); - lbl_804799B8.x8 = 5; + state->x8 = 5; idx = arg0[0]; - entry = table + (idx << 1) + (*mt != 0); ptr = arg0 + idx; val = *++ptr; + entry = table + (idx << 1) + (*mt != 0); if (val < (s32) entry[0x4C]) { if (*mt != 0) { if (val == arg0[2] - 1) { @@ -1955,6 +2039,11 @@ void fn_80193FCC(s32* arg0, u32 arg1, u32 arg2) } } +static inline s32 fn_80194658_get_value(s32* ptr) +{ + return *++ptr; +} + void fn_80194658(s32* arg0, u32 arg1, u32 arg2) { u8* table; @@ -1970,9 +2059,10 @@ void fn_80194658(s32* arg0, u32 arg1, u32 arg2) dir = gm_804771C4.match_type; ptr = arg0 + idx; - val = *(++ptr); + val = fn_80194658_get_value(ptr); + ptr = arg0 + idx + 1; - if (dir == 0) { + if (0 == dir) { if (lbl_804D665C < 2) { if (arg1 & 0x40001) { *ptr = (val != 0) ? 0 : 1; @@ -2065,44 +2155,39 @@ void fn_80194658(s32* arg0, u32 arg1, u32 arg2) } } -/// @todo Currently 93.36% match - remaining mismatch is register allocation +/// Handles tournament rules menu input. void fn_801949B4(s32* arg0, u32 arg1, u32 arg2) { - u8* table; + TmSettingTable* table = &lbl_803D9F80; s32 idx; s32* ptr; s32 val; - u8* entry; if (arg1 & 0x40001) { lbAudioAx_80024030(2); lbl_804799B8.x7 = 5; - table = (u8*) &lbl_803D9F80; - idx = *arg0; - ptr = &arg0[idx + 1]; - entry = table + (idx << 1) + (gm_804771C4.match_type != 0); - val = *ptr; + idx = arg0[0]; + ptr = arg0 + idx; + val = *++ptr; - if (val > (s32) entry[0x40]) { + if (val > (s32) table->min[idx][!!gm_804771C4.match_type]) { *ptr = val - 1; } else { - *ptr = (s32) entry[0x4C]; + *ptr = (s32) table->max[idx][!!gm_804771C4.match_type]; } } else if (arg1 & 0x80002) { lbAudioAx_80024030(2); lbl_804799B8.x8 = 5; - table = (u8*) &lbl_803D9F80; - idx = *arg0; - ptr = &arg0[idx + 1]; - entry = table + (idx << 1) + (gm_804771C4.match_type != 0); - val = *ptr; + idx = arg0[0]; + ptr = arg0 + idx; + val = *++ptr; - if (val < (s32) entry[0x4C]) { + if (val < (s32) table->max[idx][!!gm_804771C4.match_type]) { *ptr = val + 1; } else { - *ptr = (s32) entry[0x40]; + *ptr = (s32) table->min[idx][!!gm_804771C4.match_type]; } } @@ -2137,21 +2222,13 @@ void fn_801949B4(s32* arg0, u32 arg1, u32 arg2) } } -/// @todo Currently 84.75% match - needs register allocation fix void fn_80194BC4(s32* arg0, u32 arg1, u32 arg2) { - int* match_type_ptr; - s16* data_ptr; - s32 option; + int* match_type_ptr = &gm_804771C4.match_type; + TmSettingTable* table = &lbl_803D9F80; s32 value; s32* arr_ptr; - s16* opt_ptr; - u8* lookup_ptr; - int match_type; - s32 opt_x4, opt_x2; - - data_ptr = (s16*) &lbl_803D9F80; - match_type_ptr = &gm_804771C4.match_type; + s32 option; if (*match_type_ptr != 0) { return; @@ -2160,34 +2237,26 @@ void fn_80194BC4(s32* arg0, u32 arg1, u32 arg2) if (arg1 & 0x40001) { lbAudioAx_80024030(2); lbl_804799B8.x7 = 5; - match_type = *match_type_ptr; - option = *arg0; - opt_x4 = option << 2; - opt_x2 = option << 1; - arr_ptr = (s32*) ((u8*) arg0 + opt_x4); - opt_ptr = (s16*) ((u8*) data_ptr + opt_x2); - value = *(++arr_ptr); - lookup_ptr = (u8*) opt_ptr + !!match_type; - if (value > lookup_ptr[0x40]) { + option = arg0[0]; + arr_ptr = arg0 + option; + value = *++arr_ptr; + + if (value > (s32) table->min[option][!!*match_type_ptr]) { *arr_ptr = value - 1; } else { - *arr_ptr = lookup_ptr[0x4C]; + *arr_ptr = (s32) table->max[option][!!*match_type_ptr]; } } else if (arg1 & 0x80002) { lbAudioAx_80024030(2); lbl_804799B8.x8 = 5; - match_type = *match_type_ptr; - option = *arg0; - opt_x4 = option << 2; - opt_x2 = option << 1; - arr_ptr = (s32*) ((u8*) arg0 + opt_x4); - opt_ptr = (s16*) ((u8*) data_ptr + opt_x2); - value = *(++arr_ptr); - lookup_ptr = (u8*) opt_ptr + !!match_type; - if (value < lookup_ptr[0x4C]) { + option = arg0[0]; + arr_ptr = arg0 + option; + value = *++arr_ptr; + + if (value < (s32) table->max[option][!!*match_type_ptr]) { *arr_ptr = value + 1; } else { - *arr_ptr = lookup_ptr[0x40]; + *arr_ptr = (s32) table->min[option][!!*match_type_ptr]; } } @@ -2300,120 +2369,135 @@ typedef struct TmData_80194F30 { /// Handles tournament settings menu input (entrant configuration). void fn_80194F30(s32* state_ptr, u32 buttons, u32 trigger) { + struct Lbl804799B8_t* state = &lbl_804799B8; TmData* tm = (TmData*) state_ptr; TmData_80194F30* tm_alt = (TmData_80194F30*) state_ptr; s32 idx; if (trigger & 0x1000) { lbAudioAx_80024030(1); - lbl_804D6654 = tm->cur_option; - tm->cur_option = 0x11; + lbl_804D6654 = *state_ptr; + *state_ptr = 0x11; return; } if (buttons & 0x40001) { - switch (tm->cur_option) { + switch (*state_ptr) { case 12: lbAudioAx_80024030(2); - tm->cur_option = 0xA; + *state_ptr = 0xA; break; case 16: lbAudioAx_80024030(2); - tm->cur_option = 0xC; - lbl_804799B8.x1 = 0; + *state_ptr = 0xC; + state->x1 = 0; break; } } else if (buttons & 0x80002) { - switch (tm->cur_option) { + switch (*state_ptr) { case 11: break; case 10: lbAudioAx_80024030(2); - tm->cur_option = 0xC; + *state_ptr = 0xC; break; case 12: - if (lbl_804799B8.x0 != 0) { + if (state->x0 != 0) { lbAudioAx_80024030(2); - tm->cur_option = 0x10; + *state_ptr = 0x10; } break; } } else if (buttons & 0x10008) { - if (tm->cur_option != 0x10 || lbl_804799B8.x1 == 0) { - if (lbl_804799B8.x2 != 0) { - lbAudioAx_80024030(2); - lbl_804799B8.x2 -= 1; - fn_80190ABC(5); - } else if (lbl_804799B8.x3 != 0) { + if (*state_ptr != 0x10 || state->x1 == 0) { + u8* pos_ptr; + if (*(pos_ptr = &state->x2) != 0) { lbAudioAx_80024030(2); - lbl_804799B8.x3 -= 1; - lbl_804799B8.x4 -= 1; + *pos_ptr -= 1; fn_80190ABC(5); - fn_80190ABC(6); + } else { + if (*(pos_ptr = &state->x3) != 0) { + lbAudioAx_80024030(2); + *pos_ptr -= 1; + state->x4 -= 1; + fn_80190ABC(5); + fn_80190ABC(6); + } } } else { - idx = lbl_804799B8.x2 + lbl_804799B8.x3; + u8* pos_ptr; + u8* scroll_ptr; + idx = *(scroll_ptr = &state->x2) + *(pos_ptr = &state->x3); if (tm->x37[idx].x2 > 1) { lbAudioAx_80024030(2); - idx = lbl_804799B8.x2 + lbl_804799B8.x3; + idx = *scroll_ptr + *pos_ptr; tm->x37[idx].x2 -= 1; } } } else if (buttons & 0x20004) { - if (tm->cur_option != 0x10 || lbl_804799B8.x1 == 0) { - if (lbl_804799B8.x2 < 0xB) { - if (lbl_804799B8.x2 + lbl_804799B8.x3 < tm->x2E - 1) { + if (*state_ptr != 0x10 || state->x1 == 0) { + u8* pos_ptr; + u8* scroll_ptr; + u8 pos = *(scroll_ptr = &state->x2); + if (pos < 0xB) { + if (pos + state->x3 < tm->x2E - 1) { lbAudioAx_80024030(2); - lbl_804799B8.x2 += 1; + *scroll_ptr += 1; fn_80190ABC(5); } - } else if (lbl_804799B8.x2 + lbl_804799B8.x3 < tm->x2E - 1) { - lbAudioAx_80024030(2); - lbl_804799B8.x3 += 1; - lbl_804799B8.x4 += 1; - fn_80190ABC(5); - fn_80190ABC(6); + } else { + if (pos + *(pos_ptr = &state->x3) < tm->x2E - 1) { + lbAudioAx_80024030(2); + *pos_ptr += 1; + state->x4 += 1; + fn_80190ABC(5); + fn_80190ABC(6); + } } } else { - idx = lbl_804799B8.x2 + lbl_804799B8.x3; + u8* pos_ptr; + u8* scroll_ptr; + idx = *(scroll_ptr = &state->x2) + *(pos_ptr = &state->x3); if (tm->x37[idx].x2 < 9) { lbAudioAx_80024030(2); - idx = lbl_804799B8.x2 + lbl_804799B8.x3; + idx = *scroll_ptr + *pos_ptr; tm->x37[idx].x2 += 1; } } } if (trigger & 0x100) { - switch (tm->cur_option) { + switch (*state_ptr) { case 12: case 10: lbAudioAx_80024030(1); - idx = lbl_804799B8.x2 + lbl_804799B8.x3; + idx = state->x2 + state->x3; tm->x37[idx].x4 = tm->x37[idx].x3; - idx = lbl_804799B8.x2 + lbl_804799B8.x3; + idx = state->x2 + state->x3; tm->x37[idx].x8 = tm->x37[idx].x7; - idx = lbl_804799B8.x2 + lbl_804799B8.x3; + idx = state->x2 + state->x3; tm_alt->x37[idx].xB = tm->x37[idx].x9; - idx = lbl_804799B8.x2 + lbl_804799B8.x3; + idx = state->x2 + state->x3; tm->x37[idx].x6 = tm->x37[idx].x5; - tm->cur_option += 1; + *state_ptr += 1; return; case 16: - if (lbl_804799B8.x0 != 1) { - if (lbl_804799B8.x1 != 1) { + if (state->x0 != 1) { + u8* flag_ptr; + if (*(flag_ptr = &state->x1) != 1) { lbAudioAx_80024030(1); } - lbl_804799B8.x1 = 1; + *flag_ptr = 1; return; } break; } } else if (trigger & 0x200) { + u8* flag_ptr; lbAudioAx_80024030(0); - if (tm->cur_option != 0x10 || lbl_804799B8.x1 == 0) { - tm->cur_option = 6; - lbl_804799B8.xE = 0; + if (*state_ptr != 0x10 || *(flag_ptr = &state->x1) == 0) { + *state_ptr = 6; + state->xE = 0; if (gm_804771C4.match_type == 0) { TmData* tmdata = gm_8018F634(); fn_8018EC7C(); @@ -2422,23 +2506,33 @@ void fn_80194F30(s32* state_ptr, u32 buttons, u32 trigger) fn_80190520(-278.0f, 255.0f, 0.0f); } } else { - lbl_804799B8.x1 = 0; + *flag_ptr = 0; } } } /// Handles character selection input for tournament bracket. +static inline s32 fn_801953C8_GetPreviousPosition(s32 offset, s32 position) +{ + return position - offset; +} + +static inline s32 fn_801953C8_GetPlayerIndex(void) +{ + return lbl_804799B8.x2 + lbl_804799B8.x3; +} + void fn_801953C8(s32* state_ptr, u32 buttons, u32 trigger) { TmData* tm = (TmData*) state_ptr; s32 idx; s32 cur_pos; - s32 candidate; + s32 i; s32 group; + s32 candidate; s32 step; s32 adj; s32 occupied; - s32 i; idx = lbl_804799B8.x2 + lbl_804799B8.x3; cur_pos = fn_8018F310(fn_8018F6FC(tm->x37[idx].x3)); @@ -2459,8 +2553,9 @@ void fn_801953C8(s32* state_ptr, u32 buttons, u32 trigger) if (buttons & 0x40001) { group = (cur_pos / 5) * 5; for (i = 1; i < 5; i++) { - candidate = cur_pos - i; - if (candidate < group) { + step = fn_801953C8_GetPreviousPosition(i, cur_pos); + candidate = step; + if (step < group) { candidate += 5; } adj = fn_8018F6DC(fn_8018F3BC(candidate)); @@ -2486,9 +2581,9 @@ void fn_801953C8(s32* state_ptr, u32 buttons, u32 trigger) } else if (buttons & 0x80002) { group = ((cur_pos / 5) + 1) * 5; for (i = 1; i < 5; i++) { - candidate = cur_pos + i; - (void) candidate; - if (candidate >= group) { + step = cur_pos + i; + candidate = step; + if (step >= group) { candidate -= 5; } adj = fn_8018F6DC(fn_8018F3BC(candidate)); @@ -2512,10 +2607,13 @@ void fn_801953C8(s32* state_ptr, u32 buttons, u32 trigger) } } } else if (buttons & 0x10008) { + s32 temp; + step = 5; for (i = 1; i < 5; i++) { - candidate = cur_pos - step; - if (candidate < 0) { + temp = cur_pos - step; + candidate = temp; + if (temp < 0) { candidate += 25; } adj = fn_8018F6DC(fn_8018F3BC(candidate)); @@ -2543,7 +2641,7 @@ void fn_801953C8(s32* state_ptr, u32 buttons, u32 trigger) step = cur_pos + 5; for (i = 1; i < 5; i++) { candidate = step; - if (candidate >= 25) { + if (25 <= candidate) { candidate -= 25; } adj = fn_8018F6DC(fn_8018F3BC(candidate)); @@ -2591,7 +2689,7 @@ void fn_801953C8(s32* state_ptr, u32 buttons, u32 trigger) } lbAudioAx_80024030(1); *state_ptr -= 1; - idx = lbl_804799B8.x2 + lbl_804799B8.x3; + idx = fn_801953C8_GetPlayerIndex(); if (tm->x37[idx].x5 != 0) { tm->x37[idx].x5 = 0; } @@ -2608,7 +2706,7 @@ void fn_801953C8(s32* state_ptr, u32 buttons, u32 trigger) idx = lbl_804799B8.x2 + lbl_804799B8.x3; adj = (u8) gm_80169238((u8) fn_8018F6FC(tm->x37[idx].x3)); idx = lbl_804799B8.x2 + lbl_804799B8.x3; - if ((s32) tm->x37[idx].x7 < adj - 1) { + if (adj - 1 > (s32) tm->x37[idx].x7) { lbAudioAx_80024030(2); idx = lbl_804799B8.x2 + lbl_804799B8.x3; tm->x37[idx].x7++; @@ -2623,10 +2721,17 @@ void fn_801953C8(s32* state_ptr, u32 buttons, u32 trigger) } } -/// @todo Currently 93.5% match - permuter couldn't improve /// Handles name entry/selection input for tournament mode. void fn_80195AF0(s32* state_ptr, u32 buttons, u32 trigger) { + struct Lbl804799B8_t* menu = &lbl_804799B8; + TmData_80194F30* tm_alt; + s32 idx; + u8* x6; + u8* x3; + u8* x2; + u8* x5; + if (trigger & 0x1000) { lbl_804D6654 = *state_ptr; *state_ptr = 0x11; @@ -2644,12 +2749,9 @@ void fn_80195AF0(s32* state_ptr, u32 buttons, u32 trigger) } if (trigger & 0x100) { - TmData_80194F30* tm_alt; - s32 idx; - lbAudioAx_80024030(1); tm_alt = (TmData_80194F30*) state_ptr; - idx = lbl_804799B8.x2 + lbl_804799B8.x3; + idx = *(x2 = &menu->x2) + *(x3 = &menu->x3); tm_alt->x37[idx].xB = tm_alt->x37[idx].x9; switch (*state_ptr) { case 0xD: @@ -2663,21 +2765,20 @@ void fn_80195AF0(s32* state_ptr, u32 buttons, u32 trigger) } return; case 0xE: - if (GetNameText(lbl_804799B8.x5 + (lbl_804799B8.x6 * 4)) != NULL) { - idx = lbl_804799B8.x2 + lbl_804799B8.x3; - tm_alt->x37[idx].x9 = lbl_804799B8.x5 + (lbl_804799B8.x6 * 4); + x6 = &menu->x6; + x5 = &menu->x5; + if (GetNameText(*x5 + (*x6 * 4)) != NULL) { + idx = *x2 + *x3; + tm_alt->x37[idx].x9 = *x5 + (*x6 * 4); } *state_ptr = 0xF; fn_80190ABC(4); return; } } else if (trigger & 0x200) { - TmData_80194F30* tm_alt; - s32 idx; - lbAudioAx_80024030(0); tm_alt = (TmData_80194F30*) state_ptr; - idx = lbl_804799B8.x2 + lbl_804799B8.x3; + idx = menu->x2 + menu->x3; tm_alt->x37[idx].x9 = tm_alt->x37[idx].xB; fn_80190ABC(5); fn_80190ABC(6); @@ -2687,19 +2788,18 @@ void fn_80195AF0(s32* state_ptr, u32 buttons, u32 trigger) void fn_80195CCC(s32* arg, u32 buttons, u32 trigger) { + u8* menu = &lbl_804799B8.x0; TmData_80194F30* tm_alt = (TmData_80194F30*) arg; - s32 selected; s32 slot; + s32 selected; TmData* tm; u8 count; s32 i; s32 unique; - PAD_STACK(16); - if (buttons & 0x40001) { lbAudioAx_80024030(2); - if ((lbl_804799B8.x5 % 4) != 0) { + if ((menu[5] % 4) != 0) { lbl_804799B8.x5 -= 1; slot = lbl_804799B8.x2 + lbl_804799B8.x3; tm_alt->x37[slot].x9 = lbl_804799B8.x5 + (lbl_804799B8.x6 * 4); @@ -2787,7 +2887,7 @@ void fn_80195CCC(s32* arg, u32 buttons, u32 trigger) if (trigger & 0x200) { lbAudioAx_80024030(0); - slot = lbl_804799B8.x2 + lbl_804799B8.x3; + slot = menu[2] + menu[3]; tm_alt->x37[slot].x9 = tm_alt->x37[slot].xB; fn_80190ABC(5); fn_80190ABC(6); @@ -2899,21 +2999,25 @@ void gm_8019628C_OnFrame(void) void gm_801963B4_OnEnter(void* arg0) { const char* filename; + union { + u8* bytes; + char* text; + } data; + data.bytes = lbl_803D9F80.pad_0; lbAudioAx_80026F2C(0x12); lbAudioAx_8002702C(2, 8); lbAudioAx_80027168(); lbAudioAx_80027648(); - lbl_804D6640 = lbArchive_80016DBC("GmTou1p", &lbl_804D664C, - "ScGamTour_scene_data", 0); - lbl_804D6644 = lbArchive_80016DBC("GmTou2p", &lbl_804D6650, - "ScGamTour_scene_data", 0); - lbl_804D6648 = lbArchive_LoadArchive("MnExtAll"); - filename = "TmBox.dat"; + lbl_804D6640 = + lbArchive_80016DBC("GmTou1p", &lbl_804D664C, data.text + 0xC0, 0); + lbl_804D6644 = + lbArchive_80016DBC("GmTou2p", &lbl_804D6650, data.text + 0xC0, 0); + lbl_804D6648 = lbArchive_LoadArchive(data.text + 0xD8); + filename = data.text + 0xE4; lbl_804D6638 = lbArchive_80016DBC( - filename, &lbl_804771B8.box2, "tournament_box2_array", - &lbl_804771B8.box3, "tournament_box3_array", &lbl_804771B8.box4, - "tournament_box4_array", 0); - HSD_SisLib_803A62A0(0, fn_8018F5F0(), "SIS_TournamentData"); + filename, &lbl_804771B8.box2, data.text + 0xF0, &lbl_804771B8.box3, + data.text + 0x108, &lbl_804771B8.box4, data.text + 0x120, 0); + HSD_SisLib_803A62A0(0, fn_8018F5F0(), data.text + 0x138); fn_801935B8(); lbAudioAx_800237A8(0x7539, 0x7F, 0x40); lbAudioAx_80023F28(gmMainLib_8015ECB0()); diff --git a/src/melee/gm/gmtou_1.c b/src/melee/gm/gmtou_1.c index 80cc74ab42..ff185c0e3c 100644 --- a/src/melee/gm/gmtou_1.c +++ b/src/melee/gm/gmtou_1.c @@ -1531,6 +1531,15 @@ void fn_80198EBC(void) (void (*)(HSD_GObj*)) fn_80198584, lbl_804DA808); } +typedef struct TmMatchEndPlayerWindow { + u8 pad_0[0x58]; + u8 slot_type; + u8 pad_59[0x5E - 0x59]; + u8 is_small_loser; + u8 pad_5F[0xA8 - 0x5F]; +} TmMatchEndPlayerWindow; +STATIC_ASSERT(sizeof(TmMatchEndPlayerWindow) == 0xA8); + void fn_80199AF0(void) { TmData* td1; @@ -1671,7 +1680,7 @@ void fn_8019A158(void) s32 counter; u8* me; u8* cursor; - PAD_STACK(16); + PAD_STACK(32); td1 = gm_8018F634(); lbl_804799D8.x48 = (u8*) &gm_80477738; @@ -1733,7 +1742,6 @@ void fn_8019A158(void) } } else if (td1->x2D == 1) { BracketEntry* bracket = &lbl_80473AB8[bracket_idx]; - cursor = (u8*) bracket; if (bracket->x4E == 3) { bracket->x4C = 3; @@ -1750,63 +1758,48 @@ void fn_8019A158(void) } } - { - u8 check = bracket->x7A; - cursor += 0x2C; - if (check == 3) { - cursor[0x4C] = 3; - } else { - me = lbl_804799D8.x48; - me += 0xA8; - { - u8 v = me[0x5E]; - me[0x5D] = v; - cursor[0x4C] = v; - } - me = lbl_804799D8.x48; - if (me[0x106] == 0) { - slot = 1; - } + if (bracket->x7A == 3) { + bracket->x78 = 3; + } else { + me = lbl_804799D8.x48 + 0xA8; + { + u8 v = me[0x5E]; + me[0x5D] = v; + bracket->x78 = v; + } + me = lbl_804799D8.x48; + if (me[0x106] == 0) { + slot = 1; } } - { - u8 check = cursor[0x7A]; - cursor += 0x2C; - if (check == 3) { - cursor[0x4C] = 3; - } else { - me = lbl_804799D8.x48; - me += 0x150; - { - u8 v = me[0x5E]; - me[0x5D] = v; - cursor[0x4C] = v; - } - me = lbl_804799D8.x48; - if (me[0x1AE] == 0) { - slot = 2; - } + if (bracket->xA6 == 3) { + bracket->xA4 = 3; + } else { + me = lbl_804799D8.x48 + 0x150; + { + u8 v = me[0x5E]; + me[0x5D] = v; + bracket->xA4 = v; + } + me = lbl_804799D8.x48; + if (me[0x1AE] == 0) { + slot = 2; } } - { - u8 check = cursor[0x7A]; - cursor += 0x2C; - if (check == 3) { - cursor[0x4C] = 3; - } else { - me = lbl_804799D8.x48; - me += 0x1F8; - { - u8 v = me[0x5E]; - me[0x5D] = v; - cursor[0x4C] = v; - } - me = lbl_804799D8.x48; - if (me[0x256] == 0) { - slot = 3; - } + if (bracket->xD2 == 3) { + bracket->xD0 = 3; + } else { + me = lbl_804799D8.x48 + 0x1F8; + { + u8 v = me[0x5E]; + me[0x5D] = v; + bracket->xD0 = v; + } + me = lbl_804799D8.x48; + if (me[0x256] == 0) { + slot = 3; } } } else { @@ -1820,34 +1813,25 @@ void fn_8019A158(void) counter = 1; } - cursor = (u8*) bracket + 0x2C; if (bracket->x7A == 3) { - cursor[0x4C] = 4; + bracket->x78 = 4; } else { - cursor[0x4C] = counter; + bracket->x78 = counter; counter++; } - { - u8 check = cursor[0x7A]; - cursor += 0x2C; - if (check == 3) { - cursor[0x4C] = 4; - } else { - cursor[0x4C] = counter; - counter++; - } + if (bracket->xA6 == 3) { + bracket->xA4 = 4; + } else { + bracket->xA4 = counter; + counter++; } - { - u8 check = cursor[0x7A]; - cursor += 0x2C; - if (check == 3) { - cursor[0x4C] = 4; - } else { - cursor[0x4C] = counter; - counter++; - } + if (bracket->xD2 == 3) { + bracket->xD0 = 4; + } else { + bracket->xD0 = counter; + counter++; } switch (counter) { @@ -1871,21 +1855,20 @@ void fn_8019A158(void) } me = lbl_804799D8.x48; - cursor = (u8*) &lbl_80473AB8[bracket_idx]; { - u8 v = cursor[0x4C]; + u8 v = bracket->x4C; me[0x5D] = v; me = lbl_804799D8.x48; me[0x5E] = v; - v = cursor[0x78]; + v = bracket->x78; me[0x105] = v; me = lbl_804799D8.x48; me[0x106] = v; - v = cursor[0xA4]; + v = bracket->xA4; me[0x1AD] = v; me = lbl_804799D8.x48; me[0x1AE] = v; - v = cursor[0xD0]; + v = bracket->xD0; me[0x255] = v; me = lbl_804799D8.x48; me[0x256] = v; @@ -1897,14 +1880,10 @@ void fn_8019A158(void) if (bracket->x78 == 0) { slot = 1; } - cursor = (u8*) bracket + 0x2C; - if (cursor[0x78] == 0) { - cursor += 0x2C; + if (bracket->xA4 == 0) { slot = 2; - } else { - cursor += 0x2C; } - if (cursor[0x78] == 0) { + if (bracket->xD0 == 0) { slot = 3; } } @@ -1990,11 +1969,12 @@ void gm_8019A828(void) gm_8018F634()->cur_option = 0x1B; } -/// @todo 99.86%: all instruction shapes and callee-saved registers match; -/// two scratch-register tie-breaks remain (the ready loop's err/state temps -/// trade r7/r3, and the bracket-entry fill's address/value temps trade -/// r0/r4). Decl orders, block-scope promotion, split counters, and comma -/// expressions all compile to identical instructions with the same colors. +static inline u8 get_pad_error(s32 i) +{ + return (u8) HSD_PadMasterStatus[(u8) i].err; +} + +/// @todo The bracket-entry fill's address/value temps trade r0/r4. void fn_8019A86C(TmData* tm, u32 arg1, u32 arg2) { s32 ready_count = 0; @@ -2053,7 +2033,7 @@ void fn_8019A86C(TmData* tm, u32 arg1, u32 arg2) if (tm->x4B8[i].x0 == 1) { ready_count += 1; } else { - u8 err = (u8) HSD_PadMasterStatus[(u8) i].err; + u8 err = get_pad_error(i); if ((s8) err != 0) { pad_err = 1; } @@ -2258,6 +2238,13 @@ void fn_8019A86C(TmData* tm, u32 arg1, u32 arg2) } extern u8 lbl_804D6680[8]; + +typedef struct TimerFmt { + s32 d[5]; +} TimerFmt; +typedef char* TextPtr; +typedef u8* BytePtr; + extern u8 lbl_803B7D04[20]; /// Tournament match timer display/audio state machine. @@ -2441,9 +2428,9 @@ void gm_8019B2DC_OnFrame(void) /// Transitions to results screen after a tournament match. /// Ranks players, preloads stage/character data, and starts audio. -/// @todo ~99% — all 278 instructions/shapes match; residual is a pure -/// callee-saved register rotation (rank/match colored r28/r27 vs target -/// r29/r28, and the char/costume fill loop's two walkers swapped r28<->r29). +/// @todo 99.56% — all instruction shapes match; residual is a pure +/// two-register callee-saved swap: rank colors r28 vs the target's r29, +/// and the char/costume fill loop's two walkers trade r28<->r29 with it. void fn_8019B458(s32* arg0) { struct Preload { @@ -2454,6 +2441,8 @@ void fn_8019B458(s32* arg0) TmData* tm = (TmData*) arg0; struct Lbl804799D8_t* d8 = &lbl_804799D8; s32 rank; + s32 match; + TmData* td2; s32 i; s32 j; s32 x24; @@ -2482,9 +2471,6 @@ void fn_8019B458(s32* arg0) tm->x33 = rank; { - s32 match; - TmData* td2; - match = fn_80196CF8(); td2 = gm_8018F634(); fn_80198D18(); diff --git a/src/melee/gm/gmtou_2.c b/src/melee/gm/gmtou_2.c index 9b65fe31e6..2b6a60b630 100644 --- a/src/melee/gm/gmtou_2.c +++ b/src/melee/gm/gmtou_2.c @@ -42,6 +42,60 @@ #include #include +static void sdata2_order(void) +{ + (void) -19.5f; + (void) 13.0f; + (void) 6.5f; + (void) 19.5f; + (void) 2.0f; + (void) S32_TO_F32; + (void) 10000.0f; + (void) 0.0f; + (void) U32_TO_F32; + (void) 1.0f; + (void) 4.5f; + (void) 3.0f; + (void) 666.0f; + (void) 201.0f; + (void) 0.300000012f; + (void) 10.1000004f; + (void) 0.00999999978f; + (void) 5.99999714f; + (void) 21.5f; + (void) 0.400000006f; + (void) 0.200000003f; + (void) -6.0f; + (void) 10.0f; + (void) -197.0f; + (void) 15.0f; + (void) 6.0f; + (void) -152.0f; + (void) 17.0f; + (void) -172.0f; + (void) -2.5f; + (void) 73.0f; + (void) 152.0f; + (void) 240.0f; + (void) 270.0f; + (void) 480.0f; + (void) 0.99000001f; + (void) 320.0f; + (void) 261.0f; + (void) -11.0f; + (void) 2.799999f; + (void) 4.30000019f; + (void) 0.00100000005f; + (void) 4.0f; + (void) -2.0f; + (void) 0.100000001f; + (void) 0.349999994f; + (void) 0.600000024f; + (void) 0.0549449995f; + (void) 0.0799999982f; + (void) 0.0f; +} + /* 4D6688 */ extern HSD_Archive* lbl_804D6688; /* 3DA3D0 */ extern char lbl_803DA3D0[]; /* 3B7D3C */ extern s32 lbl_803B7D3C[4]; @@ -49,7 +103,6 @@ /* 4D6690 */ extern SceneDesc* lbl_804D6690; /* 4D668C */ extern HSD_Archive* lbl_804D668C; /* 4D6694 */ extern SceneDesc* lbl_804D6694; -/* 3B7D18 */ extern s32 lbl_803B7D18[9]; struct lbl_803DA2E0_t lbl_803DA2E0 = { { @@ -134,26 +187,23 @@ void fn_8019BF8C(HSD_GObj* gobj) void fn_8019C048(HSD_GObj* gobj) { + TmAnimFrameTable table; TmData* tmd; HSD_JObj* jobj; s32 idx; f32 x; - s32 table[9]; - PAD_STACK(8); + u8 players; + u8 state; + u8 start_frame, cur_frame, end_frame, loop_flag; tmd = gm_8018F634(); idx = fn_8018F62C(gobj); - jobj = gobj->hsd_obj; - - table[0] = lbl_803B7D18[0]; - table[1] = lbl_803B7D18[1]; - table[2] = lbl_803B7D18[2]; - table[3] = lbl_803B7D18[3]; - table[4] = lbl_803B7D18[4]; - table[5] = lbl_803B7D18[5]; - table[6] = lbl_803B7D18[6]; - table[7] = lbl_803B7D18[7]; - table[8] = lbl_803B7D18[8]; + { + HSD_JObj* jobj_tmp = gobj->hsd_obj; + jobj = jobj_tmp; + } + + table = lbl_803B7D18; if ((s8) (u8) HSD_PadMasterStatus[(u8) idx].err != 0) { HSD_JObjSetFlagsAll(jobj, JOBJ_HIDDEN); @@ -169,25 +219,22 @@ void fn_8019C048(HSD_GObj* gobj) HSD_SisLib_803A7548(tmd->x524[2], (s32) idx, 1.0f, 1.0f); } - { - u8 players = tmd->x30; - if ((s32) players == 4) { - x = (13.0f * (f32) idx) + -19.5f; - } else if ((s32) players == 3) { - x = 6.5f + ((13.0f * (f32) idx) - 19.5f); - } else { - x = 6.5f + ((13.0f * (2.0f * (f32) idx)) - 19.5f); - } + players = tmd->x30; + if ((s32) players == 4) { + x = (13.0f * (f32) idx) + -19.5f; + } else if ((s32) players == 3) { + x = 6.5f + ((13.0f * (f32) idx) - 19.5f); + } else { + x = 6.5f + ((13.0f * (2.0f * (f32) idx)) - 19.5f); } HSD_JObjSetTranslateX(jobj, x); tmd->x524[2]->hidden = 0; - lbl_80479A58.x1D[idx].a = ((u16*) table)[lbl_80479A58.x1D[idx].x0 * 3 + 0]; - lbl_80479A58.x1D[idx].c = ((u16*) table)[lbl_80479A58.x1D[idx].x0 * 3 + 1]; - lbl_80479A58.x1D[idx].x2 = - ((u16*) table)[lbl_80479A58.x1D[idx].x0 * 3 + 2]; + lbl_80479A58.x1D[idx].a = table.states[lbl_80479A58.x1D[idx].x0].start; + lbl_80479A58.x1D[idx].c = table.states[lbl_80479A58.x1D[idx].x0].end; + lbl_80479A58.x1D[idx].x2 = table.states[lbl_80479A58.x1D[idx].x0].loop; if (lbl_80479A58.x1D[idx].b < lbl_80479A58.x1D[idx].a) { lbl_80479A58.x1D[idx].b = lbl_80479A58.x1D[idx].a; @@ -204,14 +251,16 @@ void fn_8019C048(HSD_GObj* gobj) } } - if (lbl_80479A58.x1D[idx].x0 == 0 && lbl_80479A58.x38[idx] == 6) { + state = lbl_80479A58.x1D[idx].x0; + if (state == 0 && lbl_80479A58.x38[idx] == 6) { if (lbl_80479A58.x1D[idx].x1 != 0 && (u8) tmd->x4B8[idx].x0 != 0) { lbl_80479A58.x1D[idx].x0 = 1; lbl_80479A58.x1D[idx].x1 = 0; } } - if (lbl_80479A58.x1D[idx].x0 == 1) { + state = lbl_80479A58.x1D[idx].x0; + if (state == 1) { if (lbl_80479A58.x1D[idx].x1 != 0) { lbl_80479A58.x1D[idx].x0 = 2; lbl_80479A58.x1D[idx].x1 = 0; @@ -507,9 +556,9 @@ void fn_8019D074(HSD_GObj* gobj) void fn_8019D1BC(void) { + HSD_JObj* jobj; TmData* tmd; HSD_GObj* gobj; - HSD_JObj* jobj; HSD_JObj* c; s32 i; f32 pos; @@ -733,6 +782,32 @@ void fn_8019DD60(void) } } +static inline s32 get_match_player_index(s32 player) +{ + TmData* tmd = gm_8018F634(); + s32 i; + + for (i = 0; i < (s32) tmd->x2E; i++) { + if (player == (s32) tmd->x37[i].xE) { + return i; + } + } + return 0; +} + +static inline s32 get_match_player_index_xF(s32 player) +{ + TmData* tmd = gm_8018F634(); + s32 i; + + for (i = 0; i < (s32) tmd->x2E; i++) { + if (player == (s32) tmd->x37[i].xF) { + return i; + } + } + return 0; +} + void gm_8019DF8C_OnFrame(void) { TmVsData vsdata; @@ -797,15 +872,7 @@ void gm_8019DF8C_OnFrame(void) u8 status = lbl_80479A58.x1D[i].x0; if (status != 2 && status != 1) { if ((fn_8018F6A8(i) & 0x40) && (fn_8018F6A8(i) & 0x20)) { - TmData* p = gm_8018F634(); - for (j = 0; j < (s32) p->x2E; j++) { - if (i != (s32) p->x37[j].xE) { - continue; - } - goto lr_found; - } - j = 0; - lr_found: + j = get_match_player_index(i); tmd->x37[j].x5 = 1; tmd->x4B8[i].x2 = 1; } @@ -814,18 +881,7 @@ void gm_8019DF8C_OnFrame(void) u8 chr; lbAudioAx_80024030(2); - { - TmData* p = gm_8018F634(); - for (j = 0; j < (s32) p->x2E; j++) { - if (i != (s32) p->x37[j].xE) { - continue; - } - goto left_found1; - } - j = 0; - left_found1:; - } - + j = get_match_player_index(i); tmd->x37[j].x5 = 0; tmd->x4B8[i].x2 = 0; @@ -840,30 +896,10 @@ void gm_8019DF8C_OnFrame(void) 0); tmd->x4B8[i].x1 = chr; - { - TmData* p = gm_8018F634(); - for (j = 0; j < (s32) p->x2E; j++) { - if (i != (s32) p->x37[j].xE) { - continue; - } - goto left_found2; - } - j = 0; - left_found2:; - } + j = get_match_player_index(i); tmd->x37[j].x3 = tmd->x4B8[i].x1; - { - TmData* p = gm_8018F634(); - for (j = 0; j < (s32) p->x2E; j++) { - if (i != (s32) p->x37[j].xE) { - continue; - } - goto left_found3; - } - j = 0; - left_found3:; - } + j = get_match_player_index(i); tmd->x4B8[i].x3 = 0; tmd->x37[j].x7 = 0; @@ -871,18 +907,7 @@ void gm_8019DF8C_OnFrame(void) u8 chr; lbAudioAx_80024030(2); - { - TmData* p = gm_8018F634(); - for (j = 0; j < (s32) p->x2E; j++) { - if (i != (s32) p->x37[j].xE) { - continue; - } - goto right_found1; - } - j = 0; - right_found1:; - } - + j = get_match_player_index(i); tmd->x37[j].x5 = 0; tmd->x4B8[i].x2 = 0; @@ -897,30 +922,10 @@ void gm_8019DF8C_OnFrame(void) 0); tmd->x4B8[i].x1 = chr; - { - TmData* p = gm_8018F634(); - for (j = 0; j < (s32) p->x2E; j++) { - if (i != (s32) p->x37[j].xE) { - continue; - } - goto right_found2; - } - j = 0; - right_found2:; - } + j = get_match_player_index(i); tmd->x37[j].x3 = tmd->x4B8[i].x1; - { - TmData* p = gm_8018F634(); - for (j = 0; j < (s32) p->x2E; j++) { - if (i != (s32) p->x37[j].xE) { - continue; - } - goto right_found3; - } - j = 0; - right_found3:; - } + j = get_match_player_index(i); tmd->x4B8[i].x3 = 0; tmd->x37[j].x7 = 0; } @@ -957,17 +962,7 @@ void gm_8019DF8C_OnFrame(void) tmd->x4B8[i].x3 += 1; } - { - TmData* p = gm_8018F634(); - for (j = 0; j < (s32) p->x2E; j++) { - if (i != (s32) p->x37[j].xE) { - continue; - } - goto down_found; - } - j = 0; - down_found:; - } + j = get_match_player_index(i); tmd->x37[j].x7 = tmd->x4B8[i].x3; } else if (buttons & 0x800) { @@ -977,17 +972,7 @@ void gm_8019DF8C_OnFrame(void) tmd->x4B8[i].x3 = color - 1; } - { - TmData* p = gm_8018F634(); - for (j = 0; j < (s32) p->x2E; j++) { - if (i != (s32) p->x37[j].xE) { - continue; - } - goto up_found; - } - j = 0; - up_found:; - } + j = get_match_player_index(i); tmd->x37[j].x7 = tmd->x4B8[i].x3; } } @@ -1021,8 +1006,10 @@ void gm_8019E634(void) s32 results[4]; TmData* tmd; s32 hmn_cpu; - s32 i, j; + MatchEnd* match_end; + s32* results_base; u64 audio_mask; + s32 i, j; tmd = gm_8018F634(); hmn_cpu = tmd->hmn_cpu_count; @@ -1033,19 +1020,26 @@ void gm_8019E634(void) indices[3] = lbl_803B7D3C[3]; /* Get match results per player */ - for (i = 0; i < (s32) tmd->x30; i++) { - results[i] = fn_80166CBC(&gm_80477738, i); + match_end = &gm_80477738; + results_base = results; + { + s32* result_ptr; + for (result_ptr = results_base, i = 0; i < (s32) tmd->x30; + result_ptr++, i++) + { + *result_ptr = fn_80166CBC(match_end, i); + } } /* Bubble sort results, keeping indices in parallel */ for (i = 0; i < (s32) (tmd->x30 - 1); i++) { for (j = 0; j < (s32) ((tmd->x30 - 1) - i); j++) { - if (results[j] > results[j + 1]) { - s32 tr = results[j]; + if (results_base[j] > results_base[j + 1]) { + s32 tr = results_base[j]; s32 ti = indices[j]; - results[j] = results[j + 1]; + results_base[j] = results_base[j + 1]; indices[j] = indices[j + 1]; - results[j + 1] = tr; + results_base[j + 1] = tr; indices[j + 1] = ti; } } @@ -1053,25 +1047,20 @@ void gm_8019E634(void) /* Handicap adjustment */ if ((u8) gmMainLib_8015CC34()->handicap == 1) { - u32 hbuf_init; + union { + u32 word; + u8 bytes[4]; + } hbuf_data; u8* hbuf; - hbuf_init = lbl_804DA948; - hbuf = (u8*) &hbuf_init; + hbuf_data.word = *(u32*) &lbl_804DA948; + hbuf = hbuf_data.bytes; /* Read handicap from x37 entries */ for (i = 0; i < 4; i++) { if (i < (s32) tmd->x30) { - s32 id = results[i]; - TmData* p = gm_8018F634(); - for (j = 0; j < (s32) p->x2E; j++) { - if (id != (s32) p->x37[j].xF) { - } else { - goto found1; - } - } - j = 0; - found1: + s32 id = results_base[i]; + j = get_match_player_index_xF(id); hbuf[i] = (u8) tmd->x37[j].x2; } } @@ -1081,16 +1070,8 @@ void gm_8019E634(void) /* Write back adjusted handicap */ for (i = 0; i < 4; i++) { if (i < (s32) tmd->x30) { - s32 id = results[i]; - TmData* p = gm_8018F634(); - for (j = 0; j < (s32) p->x2E; j++) { - if (id != (s32) p->x37[j].xF) { - } else { - goto found2; - } - } - j = 0; - found2: + s32 id = results_base[i]; + j = get_match_player_index_xF(id); tmd->x37[j].x2 = hbuf[i]; } } @@ -1101,140 +1082,53 @@ void gm_8019E634(void) /* Team mode */ for (i = 0; i < hmn_cpu; i++) { s32 id = indices[i]; - TmData* p = gm_8018F634(); - for (j = 0; j < (s32) p->x2E; j++) { - if (id != (s32) p->x37[j].xF) { - } else { - goto found3; - } - } - j = 0; - found3: + j = get_match_player_index_xF(id); tmd->x37[j].xE = (tmd->x2E - 1) - i; - id = tmd->x30 + i; - p = gm_8018F634(); - for (j = 0; j < (s32) p->x2E; j++) { - if (id != (s32) p->x37[j].xF) { - } else { - goto found4; - } + { + s32 next_id = tmd->x30 + i; + id = next_id; } - j = 0; - found4: + j = get_match_player_index_xF(id); tmd->x37[j].xE = indices[i]; } } else { /* FFA mode */ for (i = 0; i < hmn_cpu; i++) { s32 id = indices[(tmd->x30 - 1) - i]; - TmData* p = gm_8018F634(); - for (j = 0; j < (s32) p->x2E; j++) { - if (id != (s32) p->x37[j].xF) { - } else { - goto found5; - } - } - j = 0; - found5: + j = get_match_player_index_xF(id); tmd->x37[j].xE = (tmd->x2E - 1) - i; id = tmd->x30 + i; - p = gm_8018F634(); - for (j = 0; j < (s32) p->x2E; j++) { - if (id != (s32) p->x37[j].xF) { - } else { - goto found6; - } - } - j = 0; - found6: + j = get_match_player_index_xF(id); tmd->x37[j].xE = indices[(tmd->x30 - 1) - i]; } } /* Adjust remaining bracket positions */ for (i = tmd->x30 + hmn_cpu; i < (s32) tmd->x2E; i++) { - TmData* p = gm_8018F634(); - for (j = 0; j < (s32) p->x2E; j++) { - if (i != (s32) p->x37[j].xF) { - } else { - goto found7; - } - } - j = 0; - found7: + j = get_match_player_index_xF(i); tmd->x37[j].xE -= hmn_cpu; } /* Copy x37 data to x4B8 */ for (i = 0; i < (s32) tmd->x30; i++) { - TmData* p; - - p = gm_8018F634(); - for (j = 0; j < (s32) p->x2E; j++) { - if (i != (s32) p->x37[j].xE) { - } else { - goto found8; - } - } - j = 0; - found8: + j = get_match_player_index(i); tmd->x4B8[i].x6 = tmd->x37[j].x9; - p = gm_8018F634(); - for (j = 0; j < (s32) p->x2E; j++) { - if (i != (s32) p->x37[j].xE) { - } else { - goto found9; - } - } - j = 0; - found9: + j = get_match_player_index(i); tmd->x4B8[i].x5 = tmd->x37[j].x2; - p = gm_8018F634(); - for (j = 0; j < (s32) p->x2E; j++) { - if (i != (s32) p->x37[j].xE) { - } else { - goto found10; - } - } - j = 0; - found10: + j = get_match_player_index(i); tmd->x4B8[i].x1 = tmd->x37[j].x3; - p = gm_8018F634(); - for (j = 0; j < (s32) p->x2E; j++) { - if (i != (s32) p->x37[j].xE) { - } else { - goto found11; - } - } - j = 0; - found11: + j = get_match_player_index(i); tmd->x4B8[i].x0 = tmd->x37[j].x0; - p = gm_8018F634(); - for (j = 0; j < (s32) p->x2E; j++) { - if (i != (s32) p->x37[j].xE) { - } else { - goto found12; - } - } - j = 0; - found12: + j = get_match_player_index(i); tmd->x4B8[i].x3 = tmd->x37[j].x7; - p = gm_8018F634(); - for (j = 0; j < (s32) p->x2E; j++) { - if (i != (s32) p->x37[j].xE) { - } else { - goto found13; - } - } - j = 0; - found13: + j = get_match_player_index(i); tmd->x4B8[i].x2 = tmd->x37[j].x5; } diff --git a/src/melee/gm/gmtoulib.c b/src/melee/gm/gmtoulib.c index b55a4b96fe..e4342d70de 100644 --- a/src/melee/gm/gmtoulib.c +++ b/src/melee/gm/gmtoulib.c @@ -105,11 +105,27 @@ static inline BracketEntrySlot* BracketEntry_GetSlot(BracketEntry* entry, return &((BracketEntrySlot*) &entry->x2C)[slot_idx]; } +typedef struct BracketData { + /* 0x0000 */ BracketEntry entries[64]; + /* 0x3700 */ BracketSrcEntry* srcs[3]; +} BracketData; + +typedef struct BracketSrcPtr { + BracketSrcEntry* ptr; +} BracketSrcPtr; + +static inline BracketSrcEntry* BracketData_GetSrc(BracketEntry* entries, + s32 region) +{ + return ((BracketData*) ((BracketSrcPtr*) entries + region))->srcs[0]; +} + void fn_8018A514(int count, float val) { - BracketEntry* entries = lbl_80473AB8; s32 region; + BracketEntry* entries; BracketSrcEntry* src; + BracketSrcPtr* srcs; int i; s32 n; @@ -121,7 +137,8 @@ void fn_8018A514(int count, float val) region = 1; } - src = ((BracketSrcEntry**) ((u8*) entries + 0x3700))[region]; + srcs = (BracketSrcPtr*) ((BracketData*) lbl_80473AB8)->srcs; + src = srcs[region].ptr; if (count < 9) { for (i = 0; i < count; i++) { @@ -139,6 +156,7 @@ void fn_8018A514(int count, float val) n = lbl_803D9D20.x0[count + 0x20]; + entries = lbl_80473AB8; for (i = 0; i < n; i++) { entries[i].x0 = src->x0; entries[i].x1 = src->x1; @@ -226,10 +244,12 @@ void fn_8018AA74(HSD_JObj* jobj, s32 entry_idx, s32 slot_idx) BracketEntry* entries = lbl_80473AB8; BracketEntry* entry; u8* sub; + s32 entry_offset; + s32 slot_offset; s32* p34; - s32* p3C; - s32* p44; s32* p38; + s32* p44; + s32* p3C; s32* p40; s32* p48; u8* px3; @@ -237,8 +257,13 @@ void fn_8018AA74(HSD_JObj* jobj, s32 entry_idx, s32 slot_idx) TmData* tm = gm_8018F634(); - entry = &entries[entry_idx]; - sub = (u8*) entry + slot_idx * (s32) 0x2C; + entry_offset = entry_idx * 0xDC; + slot_offset = slot_idx * 0x2C; + { + u8* bytes = &entries->x0; + entry = (BracketEntry*) (bytes + entry_offset); + } + sub = slot_offset + &entries->x0 + entry_offset; p34 = (s32*) (sub + 0x34); p3C = (s32*) (sub + 0x3C); @@ -465,6 +490,11 @@ void fn_8018AA74(HSD_JObj* jobj, s32 entry_idx, s32 slot_idx) HSD_JObjSetTranslateY(jobj, -(f32) *p48); } +static inline f32* GetBracketCamY(f32* cam) +{ + return &cam[1]; +} + void fn_8018B090(HSD_GObj* arg0) { TmData* tm = gm_8018F634(); @@ -567,7 +597,7 @@ void fn_8018B090(HSD_GObj* arg0) } else { mn_8022F410(&cam[0], &cam[3], cam[6]); } - if (mn_8022F410(&cam[1], &cam[4], cam[7]) < 0) { + if (mn_8022F410(GetBracketCamY(cam), &cam[4], cam[7]) < 0) { mn_8022F410(&cam[1], &cam[4], cam[7]); } else { mn_8022F410(&cam[1], &cam[4], cam[7]); @@ -764,9 +794,10 @@ void fn_8018B090(HSD_GObj* arg0) } if (var_r24 == 4) { u8* w = bb + lbl_804D6634 * 0x2C; - u8* e = (u8*) &lbl_803D9D20 + tm->entrants * 4; - *(s32*) (w + 0x3C) = *(s32*) (e + 0xFC); - *(s32*) (w + 0x40) = *(s32*) (e + 0xFE); + *(s32*) (w + 0x3C) = + *(s16*) &lbl_803D9D20.x0[tm->entrants * 4 + 0xFC]; + *(s32*) (w + 0x40) = + *(s16*) &lbl_803D9D20.x0[tm->entrants * 4 + 0xFE]; tm->cur_option = 0x22; return; } @@ -938,7 +969,6 @@ void fn_8018C8D4(void* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4, s32 arg5, BracketEntry* data = (BracketEntry*) arg0; f32 thickness; f32 neg_thickness; - f32 total_width; s32 half, center, right; s32 half_h, third_h; s32 mid_y, bot_y, two_third_y; @@ -953,74 +983,122 @@ void fn_8018C8D4(void* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4, s32 arg5, switch ((s32) data->x4) { case 0: c1 = c0; - DrawRectangle((f32) arg1, (f32) arg2, thickness, (f32) arg4, &c1); + { + GXColor* color = &c1; + DrawRectangle((f32) arg1, (f32) arg2, thickness, (f32) arg4, + color); + } if (data->x20.g == 0) { c2 = data->x20; - DrawRectangle((f32) arg1, (f32) arg2, thickness, (f32) arg4, &c2); + { + GXColor* color = &c2; + DrawRectangle((f32) arg1, (f32) arg2, thickness, (f32) arg4, + color); + } } return; case 1: c3 = c0; - DrawRectangle((f32) arg1, (f32) arg2, thickness, (f32) arg4, &c3); + { + GXColor* color = &c3; + DrawRectangle((f32) arg1, (f32) arg2, thickness, (f32) arg4, + color); + } if (data->x20.g == 0) { if (data->x4C == 0) { half_h = arg4 / 2; c4 = data->x20; - DrawRectangle((f32) arg1, (f32) (arg2 + half_h), thickness, - (f32) half_h, &c4); + { + GXColor* color = &c4; + DrawRectangle((f32) arg1, (f32) (arg2 + half_h), thickness, + (f32) half_h, color); + } return; } c5 = data->x20; - DrawRectangle((f32) arg1, (f32) arg2, thickness, (f32) (arg4 / 2), - &c5); + { + GXColor* color = &c5; + DrawRectangle((f32) arg1, (f32) arg2, thickness, + (f32) (arg4 / 2), color); + } } break; case 2: half = arg3 / 2; - (void) half; center = arg1 + half; half_h = arg4 / 2; c6 = c0; - DrawRectangle((f32) center, (f32) arg2, thickness, (f32) half_h, &c6); + { + GXColor* color = &c6; + DrawRectangle((f32) center, (f32) arg2, thickness, (f32) half_h, + color); + } neg_thickness = -thickness; mid_y = arg2 + half_h; c7 = c0; - DrawRectangle((f32) (arg1 + 0x2B), (f32) mid_y, - ((f32) arg3 + thickness) - 43.0, neg_thickness, &c7); + { + GXColor* color = &c7; + DrawRectangle((f32) (arg1 + 0x2B), (f32) mid_y, + ((f32) arg3 + thickness) - 43.0f, neg_thickness, + color); + } c8 = c0; - DrawRectangle((f32) (arg1 + 0x2B), (f32) mid_y, thickness, - (f32) half_h, &c8); + { + GXColor* color = &c8; + DrawRectangle((f32) (arg1 + 0x2B), (f32) mid_y, thickness, + (f32) half_h, color); + } right = arg1 + arg3; c9 = c0; - DrawRectangle((f32) right, (f32) mid_y, thickness, (f32) half_h, &c9); + { + GXColor* color = &c9; + DrawRectangle((f32) right, (f32) mid_y, thickness, (f32) half_h, + color); + } if (data->x20.g == 0) { if (data->x4C == 0) { c10 = data->x20; - DrawRectangle((f32) (arg1 + 0x2B), (f32) mid_y, thickness, - (f32) half_h, &c10); + { + GXColor* color = &c10; + DrawRectangle((f32) (arg1 + 0x2B), (f32) mid_y, thickness, + (f32) half_h, color); + } c11 = data->x20; - DrawRectangle((f32) (arg1 + 0x2B), (f32) mid_y, - (f32) (half - 0x2B), neg_thickness, &c11); + { + GXColor* color = &c11; + DrawRectangle((f32) (arg1 + 0x2B), (f32) mid_y, + (f32) (half - 0x2B), neg_thickness, color); + } return; } if (data->x78 == 0) { c12 = data->x20; - DrawRectangle((f32) right, (f32) mid_y, thickness, - (f32) half_h, &c12); + { + GXColor* color = &c12; + DrawRectangle((f32) right, (f32) mid_y, thickness, + (f32) half_h, color); + } c13 = data->x20; - DrawRectangle((f32) center, (f32) mid_y, - (f32) half + thickness, neg_thickness, &c13); + { + GXColor* color = &c13; + DrawRectangle((f32) center, (f32) mid_y, + (f32) half + thickness, neg_thickness, + color); + } return; } c14 = data->x20; - DrawRectangle((f32) center, (f32) arg2, thickness, (f32) half_h, - &c14); + { + GXColor* color = &c14; + DrawRectangle((f32) center, (f32) arg2, thickness, + (f32) half_h, color); + } } break; @@ -1031,82 +1109,147 @@ void fn_8018C8D4(void* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4, s32 arg5, mid_y = arg2 + third_h; c15 = c0; - DrawRectangle((f32) center, (f32) mid_y, thickness, - (f32) (third_h - 2), &c15); + { + GXColor* color = &c15; + { + f32 tmp_p34770 = (f32) center; + DrawRectangle(tmp_p34770, (f32) mid_y, thickness, + (f32) (third_h - 2), color); + } + } c16 = c0; - DrawRectangle((f32) arg1, (f32) arg2, thickness, (f32) third_h, &c16); + { + GXColor* color = &c16; + DrawRectangle((f32) arg1, (f32) arg2, thickness, (f32) third_h, + color); + } right = arg1 + arg3; c17 = c0; - DrawRectangle((f32) right, (f32) arg2, thickness, (f32) third_h, &c17); + { + GXColor* color = &c17; + DrawRectangle((f32) right, (f32) arg2, thickness, (f32) third_h, + color); + } bot_y = (arg2 + arg4) - third_h; c18 = c0; - DrawRectangle((f32) arg1, (f32) bot_y, thickness, (f32) third_h, &c18); + { + GXColor* color = &c18; + DrawRectangle((f32) arg1, (f32) bot_y, thickness, (f32) third_h, + color); + } c19 = c0; - DrawRectangle((f32) right, (f32) bot_y, thickness, (f32) third_h, - &c19); + { + GXColor* color = &c19; + DrawRectangle((f32) right, (f32) bot_y, thickness, (f32) third_h, + color); + } neg_thickness = -thickness; - total_width = (f32) arg3 + thickness; c20 = c0; - DrawRectangle((f32) arg1, (f32) mid_y, total_width, neg_thickness, - &c20); + { + GXColor* color = &c20; + DrawRectangle((f32) arg1, (f32) mid_y, (f32) arg3 + thickness, + neg_thickness, color); + } c21 = c0; - DrawRectangle((f32) arg1, (f32) bot_y, total_width, neg_thickness, - &c21); + { + GXColor* color = &c21; + DrawRectangle((f32) arg1, (f32) bot_y, (f32) arg3 + thickness, + neg_thickness, color); + } if (data->x20.g == 0) { if (data->x4C == 0) { two_third_y = arg2 + ((arg4 * 2) / 3); c22 = data->x20; - DrawRectangle((f32) arg1, (f32) two_third_y, thickness, - (f32) third_h, &c22); + { + GXColor* color = &c22; + DrawRectangle((f32) arg1, (f32) two_third_y, thickness, + (f32) third_h, color); + } c23 = data->x20; - DrawRectangle((f32) arg1, (f32) two_third_y, (f32) half, - neg_thickness, &c23); + { + GXColor* color = &c23; + DrawRectangle((f32) arg1, (f32) two_third_y, (f32) half, + neg_thickness, color); + } c24 = data->x20; - DrawRectangle((f32) center, (f32) (arg2 + (arg4 / 2)), - thickness, (f32) ((arg4 / 6) - 1), &c24); + { + GXColor* color = &c24; + DrawRectangle((f32) center, (f32) (arg2 + (arg4 / 2)), + thickness, (f32) ((arg4 / 6) - 1), color); + } return; } if (data->x78 == 0) { two_third_y = arg2 + ((arg4 * 2) / 3); c25 = data->x20; - DrawRectangle((f32) right, (f32) two_third_y, thickness, - (f32) third_h, &c25); + { + GXColor* color = &c25; + { + f32 tmp_p37232 = (f32) two_third_y; + DrawRectangle((f32) right, tmp_p37232, thickness, + (f32) third_h, color); + } + } c26 = data->x20; - DrawRectangle((f32) center, (f32) two_third_y, (f32) half, - neg_thickness, &c26); + { + GXColor* color = &c26; + DrawRectangle((f32) center, (f32) two_third_y, (f32) half, + neg_thickness, color); + } c27 = data->x20; - DrawRectangle((f32) center, (f32) (arg2 + (arg4 / 2)), - thickness, (f32) ((arg4 / 6) - 1), &c27); + { + GXColor* color = &c27; + DrawRectangle((f32) center, (f32) (arg2 + (arg4 / 2)), + thickness, (f32) ((arg4 / 6) - 1), color); + } return; } if (data->xA4 == 0) { c28 = data->x20; - DrawRectangle((f32) arg1, (f32) arg2, thickness, (f32) third_h, - &c28); + { + GXColor* color = &c28; + DrawRectangle((f32) arg1, (f32) arg2, thickness, + (f32) third_h, color); + } c29 = data->x20; - DrawRectangle((f32) arg1, (f32) mid_y, (f32) half, - neg_thickness, &c29); + { + GXColor* color = &c29; + DrawRectangle((f32) arg1, (f32) mid_y, (f32) half, + neg_thickness, color); + } c30 = data->x20; - DrawRectangle((f32) center, (f32) mid_y, thickness, - (f32) ((arg4 / 6) - 1), &c30); + { + GXColor* color = &c30; + DrawRectangle((f32) center, (f32) mid_y, thickness, + (f32) ((arg4 / 6) - 1), color); + } return; } c31 = data->x20; - DrawRectangle((f32) right, (f32) arg2, thickness, (f32) third_h, - &c31); + { + GXColor* color = &c31; + DrawRectangle((f32) right, (f32) arg2, thickness, + (f32) third_h, color); + } c32 = data->x20; - DrawRectangle((f32) center, (f32) mid_y, (f32) half, neg_thickness, - &c32); + { + GXColor* color = &c32; + DrawRectangle((f32) center, (f32) mid_y, (f32) half, + neg_thickness, color); + } c33 = data->x20; - DrawRectangle((f32) center, (f32) mid_y, thickness, - (f32) ((arg4 / 6) - 1), &c33); + { + GXColor* color = &c33; + DrawRectangle((f32) center, (f32) mid_y, thickness, + (f32) ((arg4 / 6) - 1), color); + } } break; } @@ -1125,10 +1268,9 @@ void fn_8018D50C(void* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4, s32 arg5, s32 right; s32 bottom; GXColor c0, c1, c2, c3, c4, c5, c6, c7, c8, c9; - GXColor c10, c11, c12, c13, c14, c15, c16, c17, c18, c19, c20; + GXColor c10, c11, c12, c13, c14, c15, c16, c17, c18; tm = gm_8018F634(); - c20 = lbl_804DA684; c0 = lbl_804DA684; thickness = data->x1C; c1 = lbl_804DA684; @@ -1137,7 +1279,7 @@ void fn_8018D50C(void* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4, s32 arg5, DrawRectangle((f32) arg1, (f32) arg2, thickness, (f32) arg4, color); } - right = arg3 + arg1; + right = arg1 + arg3; c2 = c0; { GXColor* color = &c2; @@ -1274,9 +1416,9 @@ void fn_8018D50C(void* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4, s32 arg5, color); } if (data->x20.g == 0 && data->x4C != 0) { - c19 = data->x20; + c17 = data->x20; DrawRectangle((f32) right, (f32) bottom, thickness, -30.0f, - &c19); + &c17); } } } @@ -1285,57 +1427,76 @@ void fn_8018D50C(void* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4, s32 arg5, static GXColor const col = { 0xFF, 0xFF, 0x00, 0xFF }; +static inline int fn_8018DC18_inline0(BracketEntry* data) +{ + return data->x20.g; +} + void fn_8018DC18(void* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4, s32 arg5, s32 arg6, f32 farg0) { // TODO: Make arg0 BracketEntry (forward.h? idk how that works) - BracketEntry* data = (BracketEntry*) arg0; f32 thickness; f32 neg_thickness; s32 right; s32 half; s32 center; - GXColor c0, c1, c2, c3, c4, c5, c6, c7, c8; + GXColor c0, c1, c2, c3, c4, c5, c6, c7; - c8 = col; - thickness = data->x1C; - c1 = col; - DrawRectangle((f32) arg1, (f32) arg2, thickness, (f32) arg4, &c1); + c0 = col; + thickness = ((BracketEntry*) arg0)->x1C; + c1 = c0; + { + GXColor* color = &c1; + DrawRectangle((f32) arg1, (f32) arg2, thickness, (f32) arg4, color); + } right = arg1 + arg3; - c2 = c8; - DrawRectangle((f32) right, (f32) arg2, thickness, (f32) arg4, &c2); + c2 = c0; + { + GXColor* color = &c2; + DrawRectangle((f32) right, (f32) arg2, thickness, (f32) arg4, color); + } half = arg3 / 2; center = arg1 + half; - c3 = c8; - DrawRectangle((f32) center, (f32) arg2, thickness, (f32) arg4, &c3); + c3 = c0; + { + GXColor* color = &c3; + DrawRectangle((f32) center, (f32) arg2, thickness, (f32) arg4, color); + } neg_thickness = -thickness; - c4 = c8; - DrawRectangle((f32) arg1, (f32) arg5, (f32) arg3 + thickness, - neg_thickness, &c4); + c4 = c0; + { + GXColor* color = &c4; + DrawRectangle((f32) arg1, (f32) arg5, (f32) arg3 + thickness, + neg_thickness, color); + } - if (data->x20.g == 0) { - if (data->x4C == 0) { - c5 = data->x20; + if (!fn_8018DC18_inline0(arg0)) { + if (((BracketEntry*) arg0)->x4C == 0) { + c5 = ((BracketEntry*) arg0)->x20; DrawRectangle((f32) arg1, (f32) arg2, thickness, (f32) arg4, &c5); - c6 = data->x20; + c6 = ((BracketEntry*) arg0)->x20; DrawRectangle((f32) arg1, (f32) arg5, (f32) half + thickness, neg_thickness, &c6); return; } - if (data->x78 == 0) { - c7 = data->x20; - DrawRectangle((f32) center, (f32) arg2, thickness, (f32) arg4, - &c7); + if (((BracketEntry*) arg0)->x78 == 0) { + c7 = ((BracketEntry*) arg0)->x20; + { + GXColor* color = &c7; + DrawRectangle((f32) center, (f32) arg2, thickness, (f32) arg4, + color); + } return; } - c0 = data->x20; - DrawRectangle((f32) right, (f32) arg2, thickness, (f32) arg4, &c0); - c8 = data->x20; + c7 = ((BracketEntry*) arg0)->x20; + DrawRectangle((f32) right, (f32) arg2, thickness, (f32) arg4, &c7); + c7 = ((BracketEntry*) arg0)->x20; DrawRectangle((f32) center, (f32) arg5, (f32) half + thickness, - neg_thickness, &c8); + neg_thickness, &c7); } } @@ -1344,91 +1505,105 @@ static const GXColor lbl_804DA69C = { 255, 255, 0, 255 }; void fn_8018DF68(void* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4, s32 arg5, s32 arg6, f32 farg0) { - BracketEntry* data = (BracketEntry*) arg0; - GXColor sp58; - GXColor sp54; - GXColor sp50; - GXColor sp4C; - GXColor sp48; - GXColor sp44; - GXColor sp40; - GXColor sp3C; - GXColor sp38; - GXColor sp34; - GXColor sp30; - GXColor sp2C; - GXColor sp28; - GXColor sp24; - GXColor sp20; - f32 thickness; + GXColor right_color; + GXColor first_color; + GXColor line_color; + GXColor left_third_color; + GXColor right_third_color; + GXColor slot0_horizontal_color; + GXColor slot0_vertical_color; + GXColor horizontal_color; + GXColor slot3_vertical_color; + GXColor slot3_horizontal_color; f32 neg_thickness; + f32 thickness; s32 right; s32 third; s32 left_third; s32 right_third; s32 half; - sp20 = lbl_804DA69C; - sp58 = sp20; - thickness = data->x1C; - sp54 = sp20; - DrawRectangle((f32) arg1, (f32) arg2, thickness, (f32) arg4, &sp54); + line_color = lbl_804DA69C; + thickness = ((BracketEntry*) arg0)->x1C; + first_color = line_color; + DrawRectangle((f32) arg1, (f32) arg2, thickness, (f32) arg4, &first_color); right = arg1 + arg3; - sp50 = sp58; - DrawRectangle((f32) right, (f32) arg2, thickness, (f32) arg4, &sp50); + right_color = line_color; + { + GXColor* color = &right_color; + DrawRectangle((f32) right, (f32) arg2, thickness, (f32) arg4, color); + } third = arg3 / 3; left_third = arg1 + third; - sp4C = sp58; - DrawRectangle((f32) left_third, (f32) arg2, thickness, (f32) arg4, &sp4C); + left_third_color = line_color; + { + f32 x = (f32) left_third; + DrawRectangle(x, (f32) arg2, thickness, (f32) arg4, &left_third_color); + } right_third = right - third; - sp48 = sp58; - DrawRectangle((f32) right_third, (f32) arg2, thickness, (f32) arg4, &sp48); + right_third_color = line_color; + DrawRectangle((f32) right_third, (f32) arg2, thickness, (f32) arg4, + &right_third_color); neg_thickness = -thickness; - sp44 = sp58; + horizontal_color = line_color; DrawRectangle((f32) arg1, (f32) arg5, (f32) arg3 + thickness, - neg_thickness, &sp44); + neg_thickness, &horizontal_color); - if (data->x20.g == 0) { - if (data->x4C == 0) { - sp40 = data->x20; + if (((BracketEntry*) arg0)->x20.g == 0) { + if (((BracketEntry*) arg0)->x4C == 0) { + slot0_vertical_color = ((BracketEntry*) arg0)->x20; DrawRectangle((f32) arg1, (f32) arg2, thickness, (f32) arg4, - &sp40); - sp3C = data->x20; + &slot0_vertical_color); + slot0_horizontal_color = ((BracketEntry*) arg0)->x20; DrawRectangle((f32) arg1, (f32) arg5, (f32) (arg3 / 2) + thickness, - neg_thickness, &sp3C); + neg_thickness, &slot0_horizontal_color); return; } - if (data->x78 == 0) { - sp38 = data->x20; + if (((BracketEntry*) arg0)->x78 == 0) { + GXColor slot1_vertical_color; + GXColor slot1_horizontal_color; + slot1_vertical_color = ((BracketEntry*) arg0)->x20; DrawRectangle((f32) left_third, (f32) arg2, thickness, (f32) arg4, - &sp38); - sp34 = data->x20; - DrawRectangle((f32) left_third, (f32) arg5, - ((f32) (arg3 / 2) + thickness) - (f32) third, - neg_thickness, &sp34); + &slot1_vertical_color); + slot1_horizontal_color = ((BracketEntry*) arg0)->x20; + { + GXColor* color = &slot1_horizontal_color; + DrawRectangle((f32) left_third, (f32) arg5, + ((f32) (arg3 / 2) + thickness) - (f32) third, + neg_thickness, color); + } return; } - if (data->xA4 == 0) { - sp30 = data->x20; + if (((BracketEntry*) arg0)->xA4 == 0) { + GXColor slot2_horizontal_color; + GXColor slot2_vertical_color; + slot2_vertical_color = ((BracketEntry*) arg0)->x20; DrawRectangle((f32) right_third, (f32) arg2, thickness, (f32) arg4, - &sp30); + &slot2_vertical_color); half = arg3 / 2; - sp2C = data->x20; - DrawRectangle((f32) (arg1 + half), (f32) arg5, - ((f32) half + thickness) - (f32) third, - neg_thickness, &sp2C); + slot2_horizontal_color = ((BracketEntry*) arg0)->x20; + { + f32 y = (f32) arg5; + DrawRectangle((f32) (arg1 + half), y, + ((f32) half + thickness) - (f32) third, + neg_thickness, &slot2_horizontal_color); + } return; } - sp28 = data->x20; - DrawRectangle((f32) right, (f32) arg2, thickness, (f32) arg4, &sp28); + slot3_vertical_color = ((BracketEntry*) arg0)->x20; + DrawRectangle((f32) right, (f32) arg2, thickness, (f32) arg4, + &slot3_vertical_color); half = arg3 / 2; - sp24 = data->x20; - DrawRectangle((f32) (arg1 + half), (f32) arg5, (f32) half + thickness, - neg_thickness, &sp24); + slot3_horizontal_color = ((BracketEntry*) arg0)->x20; + { + f32 y = (f32) arg5; + DrawRectangle((f32) (arg1 + half), y, (f32) half + thickness, + neg_thickness, &slot3_horizontal_color); + } } } @@ -1517,8 +1692,10 @@ void fn_8018E618(int arg0, f32 farg0, int arg1) HSD_CObj* cobj = HSD_CObjLoadDesc((HSD_CObjDesc*) &cam); CObjData* cobj_data = (CObjData*) lbl_803D9DAC; cobj_data->cobj_data.cobj = cobj; - HSD_GObjObject_80390A70(gobj, HSD_GObj_804D784B, - cobj_data->cobj_data.cobj); + { + HSD_CObj** cobj_ptr = &cobj_data->cobj_data.cobj; + HSD_GObjObject_80390A70(gobj, HSD_GObj_804D784B, *cobj_ptr); + } } GObj_SetupGXLinkMax(gobj, HSD_GObj_803910D8, 1); ((u32*) &gobj->gxlink_prios)[1] = 0x10; @@ -1862,20 +2039,16 @@ int fn_8018F3D0(int arg0) int fn_8018F410(void) { - int temp_r3; - int* temp_r30; - int* temp_r29; + int char_id; - temp_r30 = &lbl_803D9F0C.x8; - temp_r29 = &lbl_803D9F0C.x4; do { - temp_r3 = HSD_Randi(0x19); - } while (lbl_803D9D20.x72[temp_r3] == 0 || lbl_803D9F0C.x0 == temp_r3 || - *temp_r29 == temp_r3 || *temp_r30 == temp_r3); - *temp_r30 = *temp_r29; - *temp_r29 = lbl_803D9F0C.x0; - lbl_803D9F0C.x0 = temp_r3; - return temp_r3; + char_id = HSD_Randi(0x19); + } while (lbl_803D9D20.x72[char_id] == 0 || lbl_803D9F0C.x0 == char_id || + lbl_803D9F0C.x4 == char_id || lbl_803D9F0C.x8 == char_id); + lbl_803D9F0C.x8 = lbl_803D9F0C.x4; + lbl_803D9F0C.x4 = lbl_803D9F0C.x0; + lbl_803D9F0C.x0 = char_id; + return char_id; } /// #fn_8018F410 @@ -1884,14 +2057,14 @@ int fn_8018F410(void) #pragma auto_inline off int fn_8018F4A0(void) { - int temp_r3 = mnStageSel_8025BBD4(); - if (!gm_80164430(temp_r3)) { + int stage_id = mnStageSel_8025BBD4(); + if (!gm_80164430(stage_id)) { printf("This is impossible stage num from mnSelStageRandom() -> stage " "%d \n", - temp_r3); + stage_id); __assert("gmtoulib.c", 0x53D, "0"); } - return temp_r3; + return stage_id; } #pragma pop @@ -2083,7 +2256,7 @@ void fn_8018F888(void) lbl_80473AB8[i].x20.g = 0; - if (gm_804771C4.x33 != 5) { + if (gm_804771C4.x37[0].x8 != 5) { return; } @@ -2093,6 +2266,17 @@ void fn_8018F888(void) } #pragma pop +static inline int fn_8018FA24_inline0(int char_kind) +{ + if (char_kind < 0x13) { + return char_kind; + } + if (char_kind == 0x1D) { + return 5; + } + return char_kind + 1; +} + void fn_8018FA24(void) { u8* ptr; @@ -2102,7 +2286,6 @@ void fn_8018FA24(void) s32 player_count; s32 i; BracketEntry* entry; - s32 char_kind; PAD_STACK(8); @@ -2126,21 +2309,12 @@ void fn_8018FA24(void) dst[0x4BC] = ptr[0x51]; dst[0x4BD] = ptr[0x52]; dst[0x4B9] = ptr[0x4D]; - char_kind = dst[0x4B9]; - if (char_kind >= 0x13) { - if (char_kind == 0x1D) { - char_kind = 5; - } else { - char_kind += 1; - } - } - Player_SetPlayerCharacter(player_idx, char_kind); + Player_SetPlayerCharacter(player_idx, fn_8018FA24_inline0(dst[0x4B9])); dst[0x4B8] = ptr[0x4E]; - char_kind = dst[0x4B8]; - if ((u32) char_kind != 3) { + if (dst[0x4B8] != 3) { player_count += 1; } - Player_SetSlottype(player_idx, char_kind); + Player_SetSlottype(player_idx, dst[0x4B8]); dst[0x4BB] = ptr[0x4F]; Player_SetCostumeId(player_idx, dst[0x4BB]); dst[0x4BC] = ptr[0x51]; @@ -2356,10 +2530,10 @@ static inline int gm_801905F0_inline0(int c_kind) void gm_801905F0(StartMeleeData* arg0) { - int i; u8 _padA[8]; + int i; TmData* tm = &gm_804771C4; - GameRules* temp_r31 = gmMainLib_8015CC34(); + GameRules* rules = gmMainLib_8015CC34(); TmVsData sp18; gm_80168FC4(); @@ -2367,26 +2541,26 @@ void gm_801905F0(StartMeleeData* arg0) arg0->rules.is_teams = false; arg0->rules.xE = tm->x28; fn_801640B0(&arg0->rules.x20); - arg0->rules.x0_0 = temp_r31->mode; - if (temp_r31->mode != 1) { + arg0->rules.x0_0 = rules->mode; + if (rules->mode != 1) { arg0->rules.x0_6 = true; - } else if (temp_r31->stock_time_limit != 0) { + } else if (rules->stock_time_limit != 0) { arg0->rules.x0_6 = true; } else { arg0->rules.x0_6 = false; } if (arg0->rules.x0_6) { - if (temp_r31->mode != 1) { - if (temp_r31->time_limit == 0) { + if (rules->mode != 1) { + if (rules->time_limit == 0) { arg0->rules.x10 = 99 * 60; } else { - arg0->rules.x10 = temp_r31->time_limit * 60; + arg0->rules.x10 = rules->time_limit * 60; } } else { - if (temp_r31->stock_time_limit == 0) { + if (rules->stock_time_limit == 0) { arg0->rules.x10 = 99 * 60; } else { - arg0->rules.x10 = temp_r31->stock_time_limit * 60; + arg0->rules.x10 = rules->stock_time_limit * 60; } } } @@ -2400,7 +2574,7 @@ void gm_801905F0(StartMeleeData* arg0) arg0->rules.x2_2 = false; arg0->rules.x18 = 0; arg0->rules.x34 = 1.0f; - arg0->rules.x30 = fn_801653E8(temp_r31->damage_ratio); + arg0->rules.x30 = fn_801653E8(rules->damage_ratio); arg0->rules.x3_4 = false; arg0->rules.x3_5 = false; arg0->rules.x3_2 = false; @@ -2416,12 +2590,12 @@ void gm_801905F0(StartMeleeData* arg0) arg0->rules.xC = -2; break; } - if (temp_r31->pause != 0) { + if (rules->pause != 0) { arg0->rules.disable_pausing = false; } else { arg0->rules.disable_pausing = true; } - if (temp_r31->score_display != 0 && !arg0->rules.x0_0) { + if (rules->score_display != 0 && !arg0->rules.x0_0) { arg0->rules.x3_0 = true; } else { arg0->rules.x3_0 = false; @@ -2441,7 +2615,7 @@ void gm_801905F0(StartMeleeData* arg0) arg0->players[i].color = tm->x4B8[i].x3; } arg0->players[i].slot_type = tm->x4B8[i].x0; - arg0->players[i].stocks = temp_r31->stock_count; + arg0->players[i].stocks = rules->stock_count; arg0->players[i].sub_color = 0; arg0->players[i].team = 0xFF; arg0->players[i].xC_b0 = gm_801677F8(i, arg0->players[i].xA); diff --git a/src/melee/gm/gmtoulib.h b/src/melee/gm/gmtoulib.h index 21e35fc192..b319628d3d 100644 --- a/src/melee/gm/gmtoulib.h +++ b/src/melee/gm/gmtoulib.h @@ -173,5 +173,6 @@ /* 4771B8 */ extern struct TmBoxArrays lbl_804771B8; /* 3D9F80 */ extern struct TmSettingTable lbl_803D9F80; /* 3D9D20 */ extern struct lbl_803D9D20_t lbl_803D9D20; +/* 3B7D18 */ extern union TmAnimFrameTable lbl_803B7D18; #endif diff --git a/src/melee/gm/types.h b/src/melee/gm/types.h index 90e44963c4..26a312ed35 100644 --- a/src/melee/gm/types.h +++ b/src/melee/gm/types.h @@ -1237,6 +1237,21 @@ STATIC_ASSERT(offsetof(struct TmSettingTable, min) == 0x40); STATIC_ASSERT(offsetof(struct TmSettingTable, max) == 0x4C); STATIC_ASSERT(sizeof(struct TmSettingTable) == 0x58); +/// Start/end/loop anim frame triplet for one tournament model anim state. +typedef struct TmAnimFrames { + /* 0x0 */ u16 start; + /* 0x2 */ u16 end; + /* 0x4 */ u16 loop; +} TmAnimFrames; +STATIC_ASSERT(sizeof(struct TmAnimFrames) == 0x6); + +/// Table of anim frame triplets (raw s32 words in ROM), see fn_8019C048. +typedef union TmAnimFrameTable { + s32 words[9]; + TmAnimFrames states[6]; +} TmAnimFrameTable; +STATIC_ASSERT(sizeof(union TmAnimFrameTable) == 0x24); + typedef struct BracketEntry { /* 0x00 */ u8 x0; /* 0x01 */ u8 x1; diff --git a/src/melee/gr/granime.c b/src/melee/gr/granime.c index 15754a317f..ef9dc1ba4d 100644 --- a/src/melee/gr/granime.c +++ b/src/melee/gr/granime.c @@ -286,6 +286,11 @@ static inline HSD_AObj* grAnime_801C69FC_noinline(HSD_AObj* aobj) return grAnime_801C69FC_inner(aobj); } +static inline HSD_AObj* grAnime_GetAObj(HSD_JObj* jobj) +{ + return jobj->aobj; +} + void grAnime_801C6A54(HSD_JObj* jobj, HSD_AnimJoint* animjoint, HSD_MatAnimJoint* matanimjoint, HSD_ShapeAnimJoint* shapeanimjoint) @@ -299,7 +304,7 @@ void grAnime_801C6A54(HSD_JObj* jobj, HSD_AnimJoint* animjoint, HSD_AObjRemove(jobj->aobj); } jobj->aobj = HSD_AObjLoadDesc(animjoint->aobjdesc); - grAnime_801C69FC(jobj->aobj); + grAnime_801C69FC(grAnime_GetAObj(jobj)); } grAnime_801C6960(jobj->robj, animjoint->robj_anim); } @@ -677,8 +682,7 @@ void grAnime_801C7228(HSD_JObj* obj, int flags, void* func, u32 type, if ((flags & 4) && dobj->aobj != NULL) { grAnime_801C6F50(dobj->aobj, dobj, 3, func, type, param); } - mobj = dobj->mobj; - if (mobj != NULL) { + if ((mobj = dobj->mobj) != NULL) { if ((flags & 0x80) && mobj->aobj != NULL) { grAnime_801C6F50(mobj->aobj, mobj, 8, func, type, param); } diff --git a/src/melee/gr/grbigblue.c b/src/melee/gr/grbigblue.c index c365189ab9..88ba1e46ba 100644 --- a/src/melee/gr/grbigblue.c +++ b/src/melee/gr/grbigblue.c @@ -34,6 +34,68 @@ #include #include +static void sdata2_order(void) +{ + (void) 1.0f; + (void) 0.0f; + (void) 1.04719758f; + (void) -100000.0f; + (void) 100000.0f; + (void) 1.57079637f; + (void) 10.0f; + (void) 500.0f; + (void) -3.40282347e+38f; + (void) 80.0f; + (void) 2.0f; + (void) 25.0f; + (void) 0.0174532924f; + (void) 57.2957802f; + (void) 30.0f; + (void) 0.52359879f; + (void) -30.0f; + (void) -0.52359879f; + (void) 65.0f; + (void) 1.13446403f; + (void) -65.0f; + (void) -1.13446403f; + (void) 20.0f; + (void) 16.5f; + (void) 0.5f; + (void) 50.0f; + (void) S32_TO_F32; + (void) 1000.0f; + (void) 0.5; + (void) 3.0; + (void) 8.0f; + (void) 5.0f; + (void) -50.0f; + (void) 60.0f; + (void) 140.0f; + (void) 68.0f; + (void) 52.0f; + (void) 4.0f; + (void) 0.100000001f; + (void) -1.0f; + (void) 3.40282347e+38f; + (void) -1000.0f; + (void) 0.25f; + (void) -700.0f; + (void) 0.17453292f; + (void) -300.0f; + (void) -2.79252672f; + (void) 120.0f; + (void) 3.0f; + (void) 0.00349065848f; + (void) 3.1415926535897931; + (void) 6.2831853071795862; + (void) -3.1415926535897931; + (void) 0.600000024f; + (void) -0.5f; + (void) -2000.0f; + (void) 0.0166666675f; + (void) -10.0f; +} + #define M_TAU 6.283185307179586 extern ItemKind grBb_803B8120[5]; @@ -61,6 +123,11 @@ typedef struct grBb_Data803E2EB8 { u32 x58[4]; } grBb_Data803E2EB8; +typedef struct grBb_GroundStateFlag { + u8 pad_0[0xCC]; + s32 xCC; +} grBb_GroundStateFlag; + u16 grBb_803E2938[] = { 0x0024, 0x0022, 0x000A, 0x0025, 0x0022, 0x000A, 0x0026, 0x0022, 0x0007, 0x0027, 0x0022, 0x0007, 0x0028, 0x0022, 0x0007, 0x0029, 0x0022, 0x000E, @@ -419,13 +486,13 @@ static s16 lbl_803E2DFC[] = { void grBigBlue_801E6364(Ground_GObj* gobj) { - Ground* gp = GET_GROUND(gobj); - HSD_JObj* child; - HSD_JObj* next; - HSD_JObj* cur; - s32 i; HSD_JObj* jobj = gobj->hsd_obj; HSD_GObj* car_gobj; + HSD_JObj* cur; + HSD_JObj* next; + HSD_JObj* child; + Ground* gp = GET_GROUND(gobj); + s32 i; Vec3 scale; f32 trans_x; f32 scale_base; @@ -451,8 +518,13 @@ void grBigBlue_801E6364(Ground_GObj* gobj) HSD_ASSERT(783, car_gobj); grFZeroCar_801CAFBC(car_gobj, grBb_803E2D84, 30, 1); + cur = car_gobj->hsd_obj; i = 0; - cur = HSD_JObjGetChild(car_gobj->hsd_obj); + if (cur == NULL) { + cur = NULL; + } else { + cur = cur->child; + } rot_y = grBb_804DB304; scale_base = grBb_804DB2F0; trans_x = grBb_804DB308; @@ -489,8 +561,8 @@ void grBigBlue_801E6364(Ground_GObj* gobj) grBigBlue_801EC6C0(gobj); { - s32 max_val; s32 min_val; + s32 max_val; if ((max_val = grBb_804D69C8->x10) > (min_val = grBb_804D69C8->x14)) { s32 range = max_val - min_val; @@ -581,8 +653,8 @@ bool grBigBlue_801E6C58(Ground_GObj* arg) void grBigBlue_801E6C60(Ground_GObj* gobj) { s32 i; + Vec3 pos; Ground* gp = GET_GROUND(gobj); - Ground* base = gp; i = 0; do { @@ -595,7 +667,7 @@ void grBigBlue_801E6C60(Ground_GObj* gobj) if ((int) grBigBlue_801E89DC(0) != 0) { s32 range = grBb_804D69C8->x8C; s32 rand_val; - Vec3 pos; + Vec3* pos_ptr; if (range != 0) { rand_val = HSD_Randi(range); @@ -605,8 +677,9 @@ void grBigBlue_801E6C60(Ground_GObj* gobj) gp->gv.bigblue.data[i].x4 = grBb_804D69C8->x88 + rand_val; HSD_JObjGetTranslation(jobj, &pos); + pos_ptr = &pos; - gp->gv.bigblue.data[i].x38 = pos; + gp->gv.bigblue.data[i].x38 = *pos_ptr; gp->gv.bigblue.data[i].x44.z = 0.0f; gp->gv.bigblue.data[i].x44.y = 0.0f; gp->gv.bigblue.data[i].x44.x = 0.0f; @@ -621,9 +694,9 @@ void grBigBlue_801E6C60(Ground_GObj* gobj) if ((int) grBigBlue_801E89DC(0) == 0) { gp->gv.bigblue.data[i].x1 = 0; } else { - case 2: + case 2: { + Ground* base = gp; if (gp->gv.bigblue.data[i].x4 <= 0) { - Vec3 pos; Vec3 neg_pos; f32 right_y, left_y; s32 found; @@ -820,19 +893,18 @@ void grBigBlue_801E6C60(Ground_GObj* gobj) gp->gv.bigblue.data[i].x4 -= 1; } } + } break; } - break; case 3: { - Vec3 cur_pos; f32 surface_y; Point3d normal; Vec3 euler; Vec3 fwd, back; f32 speed_val; - HSD_JObjGetTranslation(jobj, &cur_pos); - surface_y = grBigBlue_801EC58C(&cur_pos, &normal, 500.0f); + HSD_JObjGetTranslation(jobj, &pos); + surface_y = grBigBlue_801EC58C(&pos, &normal, 500.0f); if (surface_y == -F32_MAX) { normal.z = 0.0f; *(f32*) &normal = 0.0f; @@ -851,8 +923,11 @@ void grBigBlue_801E6C60(Ground_GObj* gobj) fwd.x = speed_val; fwd.z = 0.0f; fwd.y = 0.0f; - lbVector_ApplyEulerRotation(&fwd, &euler); - lbVector_Add(&fwd, &cur_pos); + { + Vec3* fwd_ptr = &fwd; + lbVector_ApplyEulerRotation(fwd_ptr, &euler); + } + lbVector_Add(&fwd, &pos); { Vec3 speeds2; @@ -865,15 +940,14 @@ void grBigBlue_801E6C60(Ground_GObj* gobj) back.z = 0.0f; back.y = 0.0f; lbVector_ApplyEulerRotation(&back, &euler); - lbVector_Add(&back, &cur_pos); + lbVector_Add(&back, &pos); { s32 sub_state = gp->gv.bigblue.data[i].x2C; - s32 phase = gp->gv.bigblue.data[i].x34; - if (sub_state == 0 || phase == 3) { + if (sub_state == 0 || gp->gv.bigblue.data[i].x34 == 3) { if (gp->gv.bigblue.data[i].x30 == 0 && sub_state != 0) { - gp->gv.bigblue.data[i].xC.y = cur_pos.y; + gp->gv.bigblue.data[i].xC.y = pos.y; gp->gv.bigblue.data[i].x4 = grBb_804D69C8->xB0; gp->gv.bigblue.data[i].x34 = 1; } @@ -911,7 +985,7 @@ void grBigBlue_801E6C60(Ground_GObj* gobj) s32 dir_val; if (gp->gv.bigblue.data[i].x30 == 0) { - gp->gv.bigblue.data[i].xC.y = cur_pos.y; + gp->gv.bigblue.data[i].xC.y = pos.y; gp->gv.bigblue.data[i].x4 = grBb_804D69C8->xB0; gp->gv.bigblue.data[i].x34 = 1; } @@ -928,8 +1002,8 @@ void grBigBlue_801E6C60(Ground_GObj* gobj) } gp->gv.bigblue.data[i].x18.y = (f32) dir_val; - if (phase == 2) { - cur_pos.y += gp->gv.bigblue.data[i].x44.y; + if (gp->gv.bigblue.data[i].x34 == 2) { + pos.y += gp->gv.bigblue.data[i].x44.y; gp->gv.bigblue.data[i].xC.x = euler.x; { if (HSD_JObjGetRotationZ(jobj) < @@ -960,19 +1034,19 @@ void grBigBlue_801E6C60(Ground_GObj* gobj) } } } - if (cur_pos.y >= gp->gv.bigblue.data[i].xC.y) { + if (pos.y >= gp->gv.bigblue.data[i].xC.y) { gp->gv.bigblue.data[i].x44.y = 0.0f; gp->gv.bigblue.data[i].x18.z = 0.0f; gp->gv.bigblue.data[i].x18.y = 0.0f; - gp->gv.bigblue.data[i].x34 = 4; + gp->gv.bigblue.data[i].x34 = 3; } } else if (gp->gv.bigblue.data[i].x4 <= 0) { gp->gv.bigblue.data[i].x44.y = grBb_804D69C8->xAC; gp->gv.bigblue.data[i].x4 = grBb_804D69C8->xB4; - gp->gv.bigblue.data[i].x34 = 3; + gp->gv.bigblue.data[i].x34 = 2; } else { - f32 prev_x = gp->gv.bigblue.data[i].x24; f32 prev_y = gp->gv.bigblue.data[i].x28; + f32 prev_x = gp->gv.bigblue.data[i].x24; if (prev_x < prev_y) { gp->gv.bigblue.data[i].x18.z = @@ -983,7 +1057,7 @@ void grBigBlue_801E6C60(Ground_GObj* gobj) gp->gv.bigblue.data[i].x18.z = grBb_804D69C8->xA4; } - cur_pos.y -= grBb_804D69C8->xA8; + pos.y -= grBb_804D69C8->xA8; } else { gp->gv.bigblue.data[i].x18.z = -grBb_804D69C8->xA0 * (prev_x - prev_y); @@ -993,7 +1067,7 @@ void grBigBlue_801E6C60(Ground_GObj* gobj) gp->gv.bigblue.data[i].x18.z = -grBb_804D69C8->xA4; } - cur_pos.y += grBb_804D69C8->xA8; + pos.y += grBb_804D69C8->xA8; } { f32 delta = @@ -1003,7 +1077,7 @@ void grBigBlue_801E6C60(Ground_GObj* gobj) { f32 angle_deg = 57.29578f * HSD_JObjGetRotationZ(jobj); - if (cur_pos.y < (surface_y + grBb_804D69C8->x90)) { + if (pos.y < (surface_y + grBb_804D69C8->x90)) { if (angle_deg > 30.0f) { HSD_JObjSetRotationZ(jobj, 0.5235988f); } @@ -1043,17 +1117,17 @@ void grBigBlue_801E6C60(Ground_GObj* gobj) { Vec3 speeds4; f32 speed_off4; - f32 left_x = cur_pos.x - (20.0f + speed3); + f32 left_x = pos.x - (20.0f + speed3); f32 right_x; speeds4 = grBb_803B8114; speed_off4 = ((f32*) &speeds4)[(s8) idx] * Ground_801C0498(); - right_x = cur_pos.x + (20.0f + speed_off4); + right_x = pos.x + (20.0f + speed_off4); target_y = grBigBlue_801E8B84(cam_top, cam_bot, left_x, right_x); } - probe_pos = cur_pos; + probe_pos = pos; probe_y = grBigBlue_801EC58C(&probe_pos, NULL, 500.0f); { @@ -1063,12 +1137,10 @@ void grBigBlue_801E6C60(Ground_GObj* gobj) speed_off5 = ((f32*) &speeds5)[(s8) idx] * Ground_801C0498(); coll_result = grBigBlue_801EACE8( - jobj, &cur_pos, &coll_y, 10.0f + speed_off5, 16.5f); + jobj, &pos, &coll_y, 10.0f + speed_off5, 16.5f); } - if (coll_result == 0 || - (coll_result == 1 && cur_pos.y < coll_y)) - { + if (coll_result == 0 || (coll_result == 1 && pos.y < coll_y)) { if (target_y <= probe_y) { if (probe_y == -F32_MAX) { gp->gv.bigblue.data[i].xC.z = fwd.y; @@ -1081,39 +1153,37 @@ void grBigBlue_801E6C60(Ground_GObj* gobj) target_y + gp->gv.bigblue.data[i].x8; } } else if (coll_result == 1) { - gp->gv.bigblue.data[i].xC.z = - cur_pos.y + (cur_pos.y - coll_y); + gp->gv.bigblue.data[i].xC.z = pos.y + (pos.y - coll_y); } target_y = gp->gv.bigblue.data[i].xC.z; - y_diff = cur_pos.y - target_y; - (void) y_diff; + y_diff = pos.y - target_y; if (y_diff < 0.0f) { y_diff = -y_diff; } if (y_diff < 0.5f) { y_vel = 0.0f; - } else if (cur_pos.y < target_y) { - y_vel = (target_y - cur_pos.y) / grBb_804D69C8->xBC; + } else if (pos.y < target_y) { + y_vel = (target_y - pos.y) / grBb_804D69C8->xBC; if (y_vel > grBb_804D69C8->xC0) { y_vel = grBb_804D69C8->xC0; } } else { - y_vel = (target_y - cur_pos.y) / grBb_804D69C8->xC4; + y_vel = (target_y - pos.y) / grBb_804D69C8->xC4; if (y_vel < -grBb_804D69C8->xC8) { y_vel = -grBb_804D69C8->xC8; } } - cur_pos.y += y_vel; + pos.y += y_vel; } { f32 x_vel = gp->gv.bigblue.data[i].x44.x; HSD_JObjAddTranslationX(jobj, x_vel); } - HSD_JObjSetTranslateY(jobj, cur_pos.y); + HSD_JObjSetTranslateY(jobj, pos.y); - gp->gv.bigblue.data[i].x38 = cur_pos; + gp->gv.bigblue.data[i].x38 = pos; gp->gv.bigblue.data[i].x30 = gp->gv.bigblue.data[i].x2C; gp->gv.bigblue.data[i].x2C = 0; gp->gv.bigblue.data[i].x28 = 0.0f; @@ -1298,19 +1368,19 @@ void* grBigBlue_801E89DC(int arg) /// add+lwz/stw (addressing mode difference), candPtr init missing slwi+add void grBigBlue_801E8A1C(int idx) { - u8* gp = (u8*) GET_GROUND(Ground_801C2BA4(32)); - HSD_JObj* platform = *(HSD_JObj**) (gp + idx * 4 + 0xD4); + Ground* gp = GET_GROUND(Ground_801C2BA4(32)); + BobOmbRain spawn; ItemKind* candPtr; ItemKind* validPtr; int i; - int validCount = 0; - BobOmbRain spawn; + int validCount; ItemKind candidates[5]; ItemKind valid[5]; + HSD_JObj* platform = gp->gv.bigblue.xD4[idx]; + i = validCount = 0; candidates[0] = grBb_803B8120[0]; candidates[1] = grBb_803B8120[1]; - i = 0; candPtr = candidates + i; candidates[2] = grBb_803B8120[2]; candidates[3] = grBb_803B8120[3]; @@ -1341,7 +1411,7 @@ void grBigBlue_801E8A1C(int idx) } spawn.x1C.b0 = 1; - *(HSD_GObj**) (gp + idx * 0x54 + 0x134) = it_8026BE84(&spawn); + gp->gv.bigblue.data[idx].x50 = (s32) it_8026BE84(&spawn); } } @@ -1357,30 +1427,79 @@ static f32 grBigBlue_801E8B84_noinline_2(f32 right, f32 left, f32 bottom, return grBigBlue_801E8B84_noinline_1(right, left, bottom, top); } -/// @todo Currently 94.71% match - needs pointer advancement and i variable f32 grBigBlue_801E8B84(f32 right, f32 left, f32 bottom, f32 top) { Ground* gp = Ground_801C2BA4(33)->user_data; - int i = 0; + u8 state; + s32 i = 0; f32 result = grBb_804DB310; - u8 operand_pad[4]; + PAD_STACK(8); - for (i = 0; i < 4; i++) { - if ((unsigned) (gp->gv.bigblue.car.lanes[i].state >> 2 & 0x3F) != 1U) { - if (gp->gv.bigblue.car.lanes[i].pos.y < right && - gp->gv.bigblue.car.lanes[i].pos.y > left) + if ((unsigned) (gp->gv.bigblue.car.lanes[i].state >> 2 & 0x3F) != 1U) { + if (gp->gv.bigblue.car.lanes[i].pos.y < right && + gp->gv.bigblue.car.lanes[i].pos.y > left) + { + if (gp->gv.bigblue.car.lanes[i].pos.x < top && + gp->gv.bigblue.car.lanes[i].pos.x > bottom) { - if (gp->gv.bigblue.car.lanes[i].pos.x < top && - gp->gv.bigblue.car.lanes[i].pos.x > bottom) - { - if (gp->gv.bigblue.car.lanes[i].pos.y > result) { - result = gp->gv.bigblue.car.lanes[i].pos.y; - } + if (gp->gv.bigblue.car.lanes[i].pos.y > result) { + result = gp->gv.bigblue.car.lanes[i].pos.y; + } + } + } + } + + state = gp->gv.bigblue.car.lanes[i + 1].state; + gp = (Ground*) &gp->x20[8]; + if ((unsigned) (state >> 2 & 0x3F) != 1U) { + if (gp->gv.bigblue.car.lanes[0].pos.y < right && + gp->gv.bigblue.car.lanes[0].pos.y > left) + { + if (gp->gv.bigblue.car.lanes[0].pos.x < top && + gp->gv.bigblue.car.lanes[0].pos.x > bottom) + { + if (gp->gv.bigblue.car.lanes[0].pos.y > result) { + result = gp->gv.bigblue.car.lanes[0].pos.y; + i = 1; } } } } + state = gp->gv.bigblue.car.lanes[1].state; + gp = (Ground*) &gp->x20[8]; + if ((unsigned) (state >> 2 & 0x3F) != 1U) { + if (gp->gv.bigblue.car.lanes[0].pos.y < right && + gp->gv.bigblue.car.lanes[0].pos.y > left) + { + if (gp->gv.bigblue.car.lanes[0].pos.x < top && + gp->gv.bigblue.car.lanes[0].pos.x > bottom) + { + if (gp->gv.bigblue.car.lanes[0].pos.y > result) { + result = gp->gv.bigblue.car.lanes[0].pos.y; + } + } + } + } + + state = gp->gv.bigblue.car.lanes[1].state; + gp = (Ground*) &gp->x20[8]; + if ((unsigned) (state >> 2 & 0x3F) != 1U) { + if (gp->gv.bigblue.car.lanes[0].pos.y < right && + gp->gv.bigblue.car.lanes[0].pos.y > left) + { + if (gp->gv.bigblue.car.lanes[0].pos.x < top && + gp->gv.bigblue.car.lanes[0].pos.x > bottom) + { + if (gp->gv.bigblue.car.lanes[0].pos.y > result) { + result = gp->gv.bigblue.car.lanes[0].pos.y; + } + } + } + } + + (void) (i != 0); + return result; } @@ -1478,12 +1597,11 @@ void grBigBlue_801E93D8(Ground_GObj* gobj) Vec3 back; Vec3 normal; Vec3 euler; - s32 _pad_9C; Vec3 check_pos; - Ground* gp = gobj->user_data; HSD_JObj* jobj = GET_JOBJ(gobj); + Ground* gp = gobj->user_data; u8* bp = (u8*) gp; - PAD_STACK(76); + PAD_STACK(68); HSD_JObjGetTranslation2(jobj, &pos); @@ -1509,224 +1627,228 @@ void grBigBlue_801E93D8(Ground_GObj* gobj) lbVector_ApplyEulerRotation(&back, &euler); lbVector_Add(&back, &pos); - switch ((s8) bp[0xC4]) { - case 0: { - if (*(s32*) ((u8*) Ground_801C2BA4(32)->user_data + 0xCC) != 0) { - volatile u32 cars_avail = 0; - u8* mgp = (u8*) Ground_801C2BA4(32)->user_data; - s32 count = 0; + { + s8 state = (s8) bp[0xC4]; - if ((s8) mgp[0xE5] != 0) { - count = 1; - if (cars_avail != 0U) { - cars_avail = *(u32*) (mgp + ((s8) mgp[0xE4] * 4) + 0xD4); - } - } + if (state == 0) { + if (((grBb_GroundStateFlag*) Ground_801C2BA4(32)->user_data) + ->xCC != 0) { - u8* p = mgp + 0x54; - if ((s8) mgp[0x139] != 0) { - count++; + volatile u32 cars_avail = 0; + u8* mgp = (u8*) Ground_801C2BA4(32)->user_data; + s32 count = 0; + + if ((s8) mgp[0xE5] != 0) { + count = 1; if (cars_avail != 0U) { - cars_avail = *(u32*) (mgp + ((s8) p[0xE4] * 4) + 0xD4); + cars_avail = + *(u32*) (mgp + ((s8) mgp[0xE4] * 4) + 0xD4); } } - if ((s8) p[0x139] != 0) { - if (cars_avail != 0U) { + { + u8* p = mgp + 0x54; + if ((s8) mgp[0x139] != 0) { + count++; + if (cars_avail != 0U) { + cars_avail = + *(u32*) (mgp + ((s8) p[0xE4] * 4) + 0xD4); + } + } + if ((s8) p[0x139] != 0) { + if (cars_avail != 0U) { + } + count++; } - count++; } - } - if (count <= 1) { - f32 height; - - memzero(&pos, 0xC); - pos.x = Stage_GetBlastZoneLeftOffset() - 50.0f; - height = grBigBlue_801EC58C(&pos, NULL, 500.0f); - if (height != -3.4028235e38f) { - f32 speed; - s32 collided; - - pos.y = height + grBb_804D69C8->xCC; - speed = 140.0f * Ground_801C0498(); - collided = grBigBlue_801E8794( - jobj, &pos, 1, 2.0f * (60.0f * Ground_801C0498()), - speed); - if (collided == 0) { - collided = grBigBlue_801EAB50( - &pos, 1, 2.0f * (60.0f * Ground_801C0498()), - 25.0f); - } - if (collided == 0) { - f32 cam_right = Stage_GetCamBoundsRightOffset(); - f32 cam_left = Stage_GetCamBoundsLeftOffset(); - f32 cam_bot = Stage_GetCamBoundsBottomOffset(); - if (pos.y <= grBigBlue_801E8B84_noinline( - Stage_GetCamBoundsTopOffset(), - cam_bot, cam_left, cam_right)) - { - collided = 1; + if (count <= 1) { + f32 height; + + memzero(&pos, 0xC); + pos.x = Stage_GetBlastZoneLeftOffset() - 50.0f; + height = grBigBlue_801EC58C(&pos, NULL, 500.0f); + if (height != -3.4028235e38f) { + f32 speed; + s32 collided; + + pos.y = height + grBb_804D69C8->xCC; + speed = 140.0f * Ground_801C0498(); + collided = grBigBlue_801E8794( + jobj, &pos, 1, 2.0f * (60.0f * Ground_801C0498()), + speed); + if (collided == 0) { + collided = grBigBlue_801EAB50( + &pos, 1, 2.0f * (60.0f * Ground_801C0498()), + 25.0f); } + if (collided == 0) { + f32 cam_right = Stage_GetCamBoundsRightOffset(); + f32 cam_left = Stage_GetCamBoundsLeftOffset(); + f32 cam_bot = Stage_GetCamBoundsBottomOffset(); + if (pos.y <= grBigBlue_801E8B84_noinline( + Stage_GetCamBoundsTopOffset(), + cam_bot, cam_left, cam_right)) + { + collided = 1; + } + } + if (collided != 0) { + pos.y = 30.0f + Stage_GetCamBoundsTopOffset(); + } + if (pos.y == -3.4028235e38f) { + OSReport("*** Not Set Position!(FFlyer)\n"); + HSD_ASSERT(1739, 0); + } + HSD_JObjSetTranslate(jobj, &pos); + *(f32*) (bp + 0xD0) = pos.y; + *(f32*) (bp + 0xD8) = grBb_804D69C8->xD0; + HSD_JObjClearFlagsAll(jobj, JOBJ_HIDDEN); + bp[0xC4] = 1; } - if (collided != 0) { - pos.y = 30.0f + Stage_GetCamBoundsTopOffset(); - } - if (pos.y == -3.4028235e38f) { - OSReport("*** Not Set Position!(FFlyer)\n"); - HSD_ASSERT(1739, 0); - } - HSD_JObjSetTranslate(jobj, &pos); - *(f32*) (bp + 0xD0) = pos.y; - *(f32*) (bp + 0xD8) = grBb_804D69C8->xD0; - HSD_JObjClearFlagsAll(jobj, JOBJ_HIDDEN); - bp[0xC4] = 1; } } - } - break; - } - case 1: - if (pos.x > 0.0f) { - *(f32*) (bp + 0xD8) = 0.0f; - *(s32*) (bp + 0xC8) = (s32) grBb_804D69C8->xD8; - bp[0xC4] = 2; } else { - f32 speed2 = 140.0f * Ground_801C0498(); - if (grBigBlue_801E8794(jobj, &pos, 1, - (60.0f * Ground_801C0498()) + 30.0f, - speed2) != 0 || - grBigBlue_801EAB50(&pos, 1, - (60.0f * Ground_801C0498()) + 30.0f, - 140.0f * Ground_801C0498()) != 0) - { - *(f32*) (bp + 0xD8) = 0.0f; - } else { - *(f32*) (bp + 0xD8) = grBb_804D69C8->xD0; + switch (state) { + case 1: + if (pos.x > 0.0f) { + *(f32*) (bp + 0xD8) = 0.0f; + *(s32*) (bp + 0xC8) = (s32) grBb_804D69C8->xD8; + bp[0xC4] = 2; + } else { + f32 speed2 = 140.0f * Ground_801C0498(); + if (grBigBlue_801E8794(jobj, &pos, 1, + (60.0f * Ground_801C0498()) + 30.0f, + speed2) != 0 || + grBigBlue_801EAB50(&pos, 1, + (60.0f * Ground_801C0498()) + 30.0f, + 140.0f * Ground_801C0498()) != 0) + { + *(f32*) (bp + 0xD8) = 0.0f; + } else { + *(f32*) (bp + 0xD8) = grBb_804D69C8->xD0; + } + } + break; + case 2: { + s32 timer = *(s32*) (bp + 0xC8); + if (timer <= 0) { + u8* mgp = (u8*) Ground_801C2BA4(32)->user_data; + s32 ctr = 3; + s32 idx = 0; + u8* p = mgp; + + *(f32*) (bp + 0xD8) = grBb_804D69C8->xD0; + bp[0xC4] = 3; + + while (ctr != 0) { + if ((s8) p[0xE5] == 0) { + u8* slot = mgp + (idx * 0x54); + slot[0xE5] = 2; + *(s32*) (slot + 0xE8) = 0; + break; + } + p += 0x54; + idx++; + ctr--; + } + } else { + *(s32*) (bp + 0xC8) = timer - 1; + } + break; } - } - goto block_76; - case 2: { - s32 timer = *(s32*) (bp + 0xC8); - if (timer <= 0) { - u8* mgp = (u8*) Ground_801C2BA4(32)->user_data; - s32 ctr = 3; - s32 idx = 0; - u8* p = mgp; - - *(f32*) (bp + 0xD8) = grBb_804D69C8->xD0; - bp[0xC4] = 3; - - route_loop: - if ((s8) p[0xE5] == 0) { - u8* slot = mgp + (idx * 0x54); - slot[0xE5] = 2; - *(s32*) (slot + 0xE8) = 0; - } else { - p += 0x54; - idx++; - ctr--; - if (ctr != 0) { - goto route_loop; + case 3: + if (pos.x > (50.0f + Stage_GetBlastZoneRightOffset())) { + HSD_JObjSetFlagsAll(jobj, JOBJ_HIDDEN); + *(f32*) (bp + 0xD8) = 0.0f; + *(s32*) ((u8*) Ground_801C2BA4(32)->user_data + 0xCC) = 0; + { + u8* mgp2 = (u8*) Ground_801C2BA4(32)->user_data; + if (jobj != NULL) { + *(u32*) (mgp2 + 0xE0) = (u32) jobj; + } + *(s32*) (mgp2 + 0xC8) = 1; + } + *(f32*) (bp + 0xCC) = 0.0f; + HSD_JObjSetRotationZ(jobj, 0.0f); + bp[0xC4] = 0; } + break; } - } else { - *(s32*) (bp + 0xC8) = timer - 1; - } - goto block_76; - } - case 3: - if (pos.x > (50.0f + Stage_GetBlastZoneRightOffset())) { - HSD_JObjSetFlagsAll(jobj, JOBJ_HIDDEN); - *(f32*) (bp + 0xD8) = 0.0f; - *(s32*) ((u8*) Ground_801C2BA4(32)->user_data + 0xCC) = 0; { - u8* mgp2 = (u8*) Ground_801C2BA4(32)->user_data; - if (jobj != NULL) { - *(u32*) (mgp2 + 0xE0) = (u32) jobj; + f32 target_z; + f32 cur_z; + f32 delta; + f32 target_y; + f32 diff_y; + f32 vy; + f32 bound_y; + f32 check_h; + + target_z = euler.z; + *(f32*) (bp + 0xCC) = target_z; + cur_z = HSD_JObjGetRotationZ(jobj); + if (cur_z < *(f32*) (bp + 0xCC)) { + delta = 0.017453292f * (grBb_804D69C8->xD4 * + (*(f32*) (bp + 0xCC) - cur_z)); + HSD_JObjAddRotationZ(jobj, delta); + if (HSD_JObjGetRotationZ(jobj) >= *(f32*) (bp + 0xCC)) { + HSD_JObjSetRotationZ(jobj, *(f32*) (bp + 0xCC)); + } + } else { + delta = + 0.017453292f * + (grBb_804D69C8->xD4 * + (*(f32*) (bp + 0xCC) - HSD_JObjGetRotationZ(jobj))); + HSD_JObjAddRotationZ(jobj, delta); + if (HSD_JObjGetRotationZ(jobj) <= *(f32*) (bp + 0xCC)) { + HSD_JObjSetRotationZ(jobj, *(f32*) (bp + 0xCC)); + } } - *(s32*) (mgp2 + 0xC8) = 1; - } - *(f32*) (bp + 0xCC) = 0.0f; - HSD_JObjSetRotationZ(jobj, 0.0f); - bp[0xC4] = 0; - } - goto block_76; - default: - block_76: { - f32 target_z; - f32 cur_z; - f32 delta; - f32 target_y; - f32 diff_y; - f32 vy; - f32 bound_y; - f32 check_h; - - target_z = euler.z; - *(f32*) (bp + 0xCC) = target_z; - cur_z = HSD_JObjGetRotationZ(jobj); - if (cur_z < *(f32*) (bp + 0xCC)) { - delta = 0.017453292f * - (grBb_804D69C8->xD4 * (*(f32*) (bp + 0xCC) - cur_z)); - HSD_JObjAddRotationZ(jobj, delta); - if (HSD_JObjGetRotationZ(jobj) >= *(f32*) (bp + 0xCC)) { - HSD_JObjSetRotationZ(jobj, *(f32*) (bp + 0xCC)); - } - } else { - delta = 0.017453292f * - (grBb_804D69C8->xD4 * - (*(f32*) (bp + 0xCC) - HSD_JObjGetRotationZ(jobj))); - HSD_JObjAddRotationZ(jobj, delta); - if (HSD_JObjGetRotationZ(jobj) <= *(f32*) (bp + 0xCC)) { - HSD_JObjSetRotationZ(jobj, *(f32*) (bp + 0xCC)); - } - } - { - f32 cam_right2 = Stage_GetCamBoundsRightOffset(); - f32 cam_left2 = Stage_GetCamBoundsLeftOffset(); - f32 cam_bot2 = Stage_GetCamBoundsBottomOffset(); - bound_y = - grBigBlue_801E8B84_noinline_2(Stage_GetCamBoundsTopOffset(), - cam_bot2, cam_left2, cam_right2); - } - check_pos = pos; - check_h = grBigBlue_801EC58C(&check_pos, NULL, 500.0f); - if (bound_y <= check_h) { - if (check_h == -3.4028235e38f) { - *(f32*) (bp + 0xD0) = fwd.y; - } else { - *(f32*) (bp + 0xD0) = check_h + grBb_804D69C8->xCC; - } - } else { - *(f32*) (bp + 0xD0) = bound_y + grBb_804D69C8->xCC; - } + { + f32 cam_right2 = Stage_GetCamBoundsRightOffset(); + f32 cam_left2 = Stage_GetCamBoundsLeftOffset(); + f32 cam_bot2 = Stage_GetCamBoundsBottomOffset(); + bound_y = grBigBlue_801E8B84_noinline_2( + Stage_GetCamBoundsTopOffset(), cam_bot2, cam_left2, + cam_right2); + } + check_pos = pos; + check_h = grBigBlue_801EC58C(&check_pos, NULL, 500.0f); + if (bound_y <= check_h) { + if (check_h == -3.4028235e38f) { + *(f32*) (bp + 0xD0) = fwd.y; + } else { + *(f32*) (bp + 0xD0) = check_h + grBb_804D69C8->xCC; + } + } else { + *(f32*) (bp + 0xD0) = bound_y + grBb_804D69C8->xCC; + } - target_y = *(f32*) (bp + 0xD0); - (void) target_y; - diff_y = pos.y - target_y; - if (diff_y < 0.0f) { - diff_y = -diff_y; - } - if (diff_y < 0.5f) { - vy = 0.0f; - } else if (pos.y < target_y) { - vy = (target_y - pos.y) / grBb_804D69C8->xE4; - if (vy > grBb_804D69C8->xE8) { - vy = grBb_804D69C8->xE8; - } - } else { - vy = (target_y - pos.y) / grBb_804D69C8->xEC; - if (vy < -grBb_804D69C8->xF0) { - vy = -grBb_804D69C8->xF0; + target_y = *(f32*) (bp + 0xD0); + diff_y = pos.y - target_y; + if (diff_y < 0.0f) { + diff_y = -diff_y; + } + if (diff_y < 0.5f) { + vy = 0.0f; + } else if (pos.y < target_y) { + vy = (target_y - pos.y) / grBb_804D69C8->xE4; + if (vy > grBb_804D69C8->xE8) { + vy = grBb_804D69C8->xE8; + } + } else { + vy = (target_y - pos.y) / grBb_804D69C8->xEC; + if (vy < -grBb_804D69C8->xF0) { + vy = -grBb_804D69C8->xF0; + } + } + pos.y += vy; + + HSD_JObjAddTranslationX(jobj, *(f32*) (bp + 0xD8)); + HSD_JObjSetTranslateY(jobj, pos.y); } } - pos.y += vy; - - HSD_JObjAddTranslationX(jobj, *(f32*) (bp + 0xD8)); - HSD_JObjSetTranslateY(jobj, pos.y); - break; - } } Ground_801C2FE0(gobj); } @@ -1776,7 +1898,7 @@ void grBigBlue_801EA05C(Ground_GObj* gobj) f32 y_check; Vec3 euler; Vec3 pos2; - PAD_STACK(0x14); + PAD_STACK(8); HSD_JObjGetTranslation2(jobj, &pos); @@ -1994,8 +2116,8 @@ void grBigBlue_801EA05C(Ground_GObj* gobj) speed_range = (grBb_804D69C8->x100 - grBb_804D69C8->xFC) / 0.1f; - speed = randi(speed_range) * 0.1f; - (void) speed; + speed = (f32) randi(speed_range); + speed *= 0.1f; if (speed == 0.0f) { speed = grBb_804D69C8->xFC; } @@ -2021,7 +2143,8 @@ void grBigBlue_801EA05C(Ground_GObj* gobj) speed_range = (grBb_804D69C8->x108 - grBb_804D69C8->x104) / 0.1f; - speed = randi(speed_range) * 0.1f; + speed = (f32) randi(speed_range); + speed *= 0.1f; if (speed == 0.0f) { speed = grBb_804D69C8->x104; } @@ -2255,22 +2378,21 @@ void grBigBlue_801EB004(Ground_GObj* gobj) u8 lo : 4; } grBb_InitNibbleBits; HSD_JObj* jobj = GET_JOBJ(gobj); - Ground* gp = (Ground*) gobj->user_data; + HSD_JObj* child; + Ground* gp = GET_GROUND(gobj); Vec3 pos; - Vec3 scale; Vec3 diff; Vec3 start_pos; Vec3 end_pos; - HSD_JObj* child; u32 i; grBb_TrackEntry* entry; HSD_JObjSetFlagsAll(jobj, JOBJ_HIDDEN); - scale.x = scale.y = scale.z = 1.0F; - HSD_JObjSetScale(jobj, &scale); + pos.x = pos.y = pos.z = 1.0F; + HSD_JObjSetScale(jobj, &pos); - scale.x = scale.y = scale.z = Ground_801C0498(); + pos.x = pos.y = pos.z = Ground_801C0498(); entry = grBb_TrackEntries; for (i = 0; i < 12; i++, entry++) { @@ -2293,13 +2415,15 @@ void grBigBlue_801EB004(Ground_GObj* gobj) goto assert_block; } - HSD_JObjSetScale(child, &scale); + HSD_JObjSetScale(child, &pos); lb_8000B1CC(start_jobj, NULL, &start_pos); lb_8000B1CC(end_jobj, NULL, &end_pos); lbVector_Diff(&end_pos, &start_pos, &diff); - entry->delta = diff; + entry->delta.x = diff.x; + entry->delta.y = diff.y; + entry->delta.z = diff.z; continue; assert_block: @@ -2347,7 +2471,7 @@ void grBigBlue_801EB004(Ground_GObj* gobj) } { - u32 idx2 = *(s8*) ((u8*) gp + 0xC6) & 0x7F; + u32 idx2 = gp->gv.bigblue.x1 & 0x7F; HSD_JObj* next = Ground_801C3FA4(gobj, grBb_TrackEntries[idx2].jobj_index); u32 active_idx; @@ -2363,8 +2487,6 @@ void grBigBlue_801EB004(Ground_GObj* gobj) } } -/// @todo Currently partial match - needs register allocation and -/// bitfield rlwimi fixes. void grBigBlue_801EB4AC(Ground_GObj* gobj) { typedef struct grBb_B4C4HalfBits { @@ -2386,11 +2508,11 @@ void grBigBlue_801EB4AC(Ground_GObj* gobj) u8 lo : 4; } grBb_B4C7Nibbles; u8* gp = (u8*) GET_GROUND(gobj); - s32 count = 0; - HSD_JObj* jobj; grBb_TrackEntry* entry; + HSD_JObj* new_jobj; + HSD_JObj* jobj; + s32 count = 0; Vec3 sp_pos; - f32 vel_threshold; f32 delta_threshold; s32 random_lane; @@ -2450,7 +2572,6 @@ void grBigBlue_801EB4AC(Ground_GObj* gobj) } /* Random lane selection loop */ - vel_threshold = -700.0F; delta_threshold = 0.0F; for (;;) { @@ -2463,7 +2584,7 @@ void grBigBlue_801EB4AC(Ground_GObj* gobj) /* If lane 11: check velocity requirement */ if (random_lane == 11) { - if (*(f32*) (gp + 0xCC) < vel_threshold) { + if (*(f32*) (gp + 0xCC) < -700.0F) { continue; } } @@ -2513,14 +2634,12 @@ void grBigBlue_801EB4AC(Ground_GObj* gobj) /* Store new lane index into gp+0xC6 */ ((grBb_B4C6Lo7Bits*) (gp + 0xC6))->lane = random_lane; - HSD_ASSERT(979, jobj); - - /* Save current jobj translate (struct copy generates lwz/stw) */ - sp_pos = jobj->translate; + /* Save current jobj translate */ + HSD_JObjGetTranslation2(jobj, &sp_pos); /* Get new lane jobj and unhide */ - jobj = Ground_801C3FA4(gobj, entry->jobj_index); - HSD_JObjClearFlagsAll(jobj, JOBJ_HIDDEN); + new_jobj = Ground_801C3FA4(gobj, entry->jobj_index); + HSD_JObjClearFlagsAll(new_jobj, JOBJ_HIDDEN); /* Add current lane deltas (re-extract lane each time, no CSE) */ sp_pos.x += grBb_TrackEntries[(*(u32*) (gp + 0xC4) >> 15) & 0x7F].delta.x; @@ -2528,7 +2647,7 @@ void grBigBlue_801EB4AC(Ground_GObj* gobj) sp_pos.z += grBb_TrackEntries[(*(u32*) (gp + 0xC4) >> 15) & 0x7F].delta.z; /* Set translate on new jobj (inline expands assert + dirty) */ - HSD_JObjSetTranslate(jobj, &sp_pos); + HSD_JObjSetTranslate(new_jobj, &sp_pos); /* If lane 11: activate joints and reset bitfield */ if (random_lane == 11) { @@ -2632,8 +2751,8 @@ u32 lbl_803E3010[] = { void grBigBlue_801EBAF8(Ground_GObj* gobj) { - u8* gp = (u8*) GET_GROUND(gobj); - HSD_JObj* jobj = gobj->hsd_obj; + u8* gp; + HSD_JObj* jobj; u8 pad[8]; Vec3 bone_pos; Vec3 vel; @@ -2641,21 +2760,27 @@ void grBigBlue_801EBAF8(Ground_GObj* gobj) Vec3 center; Vec3 normal_out; Vec3 target; + f32 drift_speed; f32 target_y; f32 rot_z; f32 angular_vel; + HSD_JObj* car_jobj; grBb_TrackEntry* entry; PAD_STACK(8); + PAD_STACK(4); + + jobj = gobj->hsd_obj; + gp = gobj->user_data; - center.x = 0.0F; center.z = 0.0F; + center.x = 0.0F; center.y = grBb_804D69C8->x0 * Ground_801C0498(); prev = *(Vec3*) (gp + 0xC8); entry = &grBb_TrackEntries[((*(u32*) (gp + 0xC4)) >> 15) & 0x7F]; - lb_8000B1CC(Ground_801C3FA4(gobj, entry->start_index), NULL, &bone_pos); + lb_8000B1CC(Ground_801C3FA4(gobj, entry->end_index), NULL, &bone_pos); { f32 angle = *(f32*) (gp + 0xF8); @@ -2702,13 +2827,11 @@ void grBigBlue_801EBAF8(Ground_GObj* gobj) mpLib_80057BC0(0x30); mpLib_80057BC0(0x30); ((grBb_NibbleBits*) (gp + 0xC7))->hi = 2; - } else if (state == 2) { - if (*(f32*) (gp + 0xF8) < -0.5235988F) { - mpJointListAdd(0x2C); - mpJointListAdd(0x2D); - mpJointListAdd(0x2E); - ((grBb_NibbleBits*) (gp + 0xC7))->hi = 3; - } + } else if (state == 2 && *(f32*) (gp + 0xF8) < -0.5235988F) { + mpJointListAdd(0x2C); + mpJointListAdd(0x2D); + mpJointListAdd(0x2E); + ((grBb_NibbleBits*) (gp + 0xC7))->hi = 3; } else if (state == 3) { if (*(f32*) (gp + 0xF8) < -2.7925267F) { mpLib_80057BC0(0x29); @@ -2730,7 +2853,7 @@ void grBigBlue_801EBAF8(Ground_GObj* gobj) 120.0F * Ground_801C0498()); } - if (target_y != grBb_804DB310 && + if (grBb_804DB310 != target_y && (!((grBb_ByteBits*) (gp + 0xC4))->b1 || target_y > center.y)) { f32 max_steer = grBb_804D69C8->x70; @@ -2757,14 +2880,15 @@ void grBigBlue_801EBAF8(Ground_GObj* gobj) if (!((grBb_ByteBits*) (gp + 0xC4))->b1) { lbVector_Diff((Vec3*) (gp + 0xD4), (Vec3*) (gp + 0xC8), (Vec3*) (gp + 0xE0)); + drift_speed = grBb_804D69C8->x7C * Ground_801C0498(); { - f32 speed = grBb_804D69C8->x7C * Ground_801C0498(); - *(f32*) (gp + 0xEC) = sinf(*(f32*) (gp + 0xF8)) * speed; + f32 s = sinf(*(f32*) (gp + 0xF8)); + *(f32*) (gp + 0xEC) = s * drift_speed; } ((grBb_ByteBits*) (gp + 0xC4))->b1 = 1; } - if (target_y != grBb_804DB310) { + if (grBb_804DB310 != target_y) { *(f32*) (gp + 0xEC) = -(3.0F * (grBb_804D69C8->x78 * Ground_801C0498()) - *(f32*) (gp + 0xEC)); @@ -2801,9 +2925,9 @@ void grBigBlue_801EBAF8(Ground_GObj* gobj) if (angular_vel != 0.0F) { f32 s = sinf(angular_vel); f32 c = (f32) cosf(angular_vel); - f32 new_y = (f32) ((f64) vel.x * (f64) s + (f64) vel.y * (f64) c); + f64 new_y = (f64) vel.x * (f64) s + (f64) vel.y * (f64) c; vel.x = (f32) ((f64) vel.x * (f64) c - (f64) vel.y * (f64) s); - vel.y = new_y; + vel.y = (f32) new_y; } lbVector_Add(&vel, ¢er); @@ -2827,7 +2951,9 @@ void grBigBlue_801EBAF8(Ground_GObj* gobj) if (rot > M_PI) { *(f32*) (gp + 0xF8) = (f32) ((f64) rot - M_TAU); } else if (rot < -M_PI) { - *(f32*) (gp + 0xF8) = (f32) ((f64) rot + M_TAU); + f64 wrapped = rot; + wrapped += M_TAU; + *(f32*) (gp + 0xF8) = (f32) wrapped; } } @@ -2835,8 +2961,8 @@ void grBigBlue_801EBAF8(Ground_GObj* gobj) -(grBb_804D69C8->x6C * Ground_801C0498() - *(f32*) (gp + 0xC8)); { - f32 lat_adj = 0.6F * (entry->delta.z / entry->delta.x) * - (grBb_804D69C8->x6C * Ground_801C0498()); + f32 lat_adj = (entry->delta.z / entry->delta.x) * + (grBb_804D69C8->x6C * Ground_801C0498()) * 0.6F; if (bone_pos.z > lat_adj) { *(f32*) (gp + 0xD0) = *(f32*) (gp + 0xD0) - lat_adj; @@ -2860,17 +2986,18 @@ void grBigBlue_801EBAF8(Ground_GObj* gobj) { HSD_GObj* car = Ground_801C2BA4(2); - if (car != NULL) { - HSD_JObjSetTranslate(car->hsd_obj, &vel); - HSD_JObjSetRotationZ(car->hsd_obj, *(f32*) (gp + 0xF8)); + HSD_JObj* car_jobj; + if (car != NULL && (car_jobj = car->hsd_obj) != NULL) { + HSD_JObjSetTranslate(car_jobj, &vel); + HSD_JObjSetRotationZ(car_jobj, *(f32*) (gp + 0xF8)); } } { HSD_GObj* car = Ground_801C2BA4(1); - if (car != NULL) { - HSD_JObjSetTranslate(car->hsd_obj, &vel); - HSD_JObjSetRotationZ(car->hsd_obj, *(f32*) (gp + 0xF8)); + if (car != NULL && (car_jobj = car->hsd_obj) != NULL) { + HSD_JObjSetTranslate(car_jobj, &vel); + HSD_JObjSetRotationZ(car_jobj, *(f32*) (gp + 0xF8)); } } @@ -2919,10 +3046,13 @@ f32 grBigBlue_801EC58C(Vec3* pos, Vec3* normal_out, f32 half_height) #pragma fp_contract on void grBigBlue_801EC6C0(Ground_GObj* gobj) { + typedef struct grBb_StateBits { + u8 state : 6; + u8 pad0 : 2; + } grBb_StateBits; Ground* gp = gobj->user_data; s32 i; s32 line_idx; - s32 idx; s32 k; u8* car; grBb_YakumonoParams* params; @@ -2931,10 +3061,11 @@ void grBigBlue_801EC6C0(Ground_GObj* gobj) s32 lo; s32 hi; HSD_JObj* jobj; + PAD_STACK(8); for (i = 0; i < 30; i++) { u8 val; - mpJointSetCb1(*(s16*) ((u8*) grBb_803E2938 + 0x4C4 + i * 2), gp, + mpJointSetCb1(lbl_803E2DFC[i], gp, (mpLib_Callback) fn_801EF60C); HSD_JObjSetFlagsAll(((HSD_JObj**) gp->gv.bigblue.xC8)[i], JOBJ_HIDDEN); val = HSD_Randi(2) ? 0 : 2; @@ -2950,7 +3081,7 @@ void grBigBlue_801EC6C0(Ground_GObj* gobj) car = (u8*) gp; for (k = 0; k < 4; k++, car += 0x40) { if (k < grBb_804D69C8->x18) { - car[0xD4] = (car[0xD4] & ~0xFC) | (4 << 2); + ((grBb_StateBits*) (car + 0xD4))->state = 4; do { line_idx = HSD_Randi(30); @@ -2978,8 +3109,7 @@ void grBigBlue_801EC6C0(Ground_GObj* gobj) *(u16*) (car + 0xD4) = hw; } - idx = 0; - car[0xD4] = (car[0xD4] & ~0x02) | (idx << 1); + ((grBb_ByteBits*) (car + 0xD4))->b6 = 0; params = grBb_804D69C8; scale = Ground_801C0498(); @@ -3032,22 +3162,18 @@ void grBigBlue_801EC6C0(Ground_GObj* gobj) if (diff != 0) { lo = hi + HSD_Randi(diff); } else { - lo = hi + idx; + lo = hi; } } else if (lo < hi) { s32 diff = hi - lo; if (diff != 0) { lo = lo + HSD_Randi(diff); - } else { - lo = lo + idx; } } *(s32*) (car + 0xF0) = lo; { - Ground_801C5440( - gp, k, - ((u32*) ((u8*) grBb_803E2938 + 0x6D8))[HSD_Randi(4)]); + Ground_801C5440(gp, k, lbl_803E3010[HSD_Randi(4)]); } *(f32*) (car + 0xEC) = 1.0F; @@ -3056,13 +3182,12 @@ void grBigBlue_801EC6C0(Ground_GObj* gobj) JOBJ_HIDDEN); jobj = ((HSD_JObj**) gp->gv.bigblue.xC8)[line_idx]; - (void) jobj; HSD_JObjSetTranslate(jobj, (Vec3*) (car + 0xE0)); ((u8*) gp->gv.bigblue.xCC)[line_idx] = 1; } else { - car[0xD4] = (car[0xD4] & ~0xFC) | (1 << 2); + ((grBb_StateBits*) (car + 0xD4))->state = 1; } } } @@ -3194,13 +3319,14 @@ void grBigBlue_801ECB50(Ground_GObj* gobj) } st = (car_p[0x114] >> 2) & 0x3F; + car_p += 0x40; car_idx++; if (st == 10) { found_ten = 1; goto car_done; } if (st != 1 && st != 7 && st != 8) { - dist = *(f32*) (car_p + 0x120); + dist = *(f32*) (car_p + 0xE0); if (dist < 0.0f) { dist = -dist; } @@ -3215,7 +3341,7 @@ void grBigBlue_801ECB50(Ground_GObj* gobj) } } ctr--; - car_p += 0x80; + car_p += 0x40; car_idx++; if (ctr != 0) { goto car_loop; @@ -3445,6 +3571,7 @@ void grBigBlue_801ECB50(Ground_GObj* gobj) void grBigBlue_801ED694(Ground_GObj* gobj, s32 lane) { u8* gp = (u8*) gobj->user_data; + s32 offset; u8* lane_gp; HSD_JObj* jobj; u8* lane_flags; @@ -3470,7 +3597,8 @@ void grBigBlue_801ED694(Ground_GObj* gobj, s32 lane) } /* Setup per-lane data */ - lane_gp = gp + (lane << 6); + offset = lane << 6; + lane_gp = gp + offset; lane_flags = lane_gp + 0xD4; { @@ -3505,25 +3633,18 @@ void grBigBlue_801ED694(Ground_GObj* gobj, s32 lane) } /* Compute ranking-based target */ - { - f32 scale = Ground_801C0498(); - s32 total = grBb_804D69C8->x1C; - rank_factor = (f32) (behind + 1) * - ((f32) (active + 1) * scale / (f32) total); - } - - { - f32 scale = Ground_801C0498(); - s32 total = grBb_804D69C8->x1C; - target = 0.5F * (-(f32) total * scale) + rank_factor; - } + rank_factor = + (f32) (behind + 1) * ((f32) grBb_804D69C8->x1C * + Ground_801C0498() / (f32) (active + 1)); + target = 0.5F * -((f32) grBb_804D69C8->x1C * Ground_801C0498()) + + rank_factor; } else { target = *(f32*) (lane_gp + 0xD8); } /* Convergence step for position index */ { - f32* current_p = (f32*) (lane_gp + 0xD8); + f32* current_p = (f32*) (gp + offset + 0xD8); f32 current = *current_p; f32 diff = target - current; @@ -3539,26 +3660,19 @@ void grBigBlue_801ED694(Ground_GObj* gobj, s32 lane) /* Velocity update: vel += accel */ { - f32* vel_p = (f32*) (lane_gp + 0xFC); + f32* vel_p = (f32*) (gp + offset + 0xFC); - *vel_p += *(f32*) (lane_gp + 0x100); + *vel_p += *(f32*) (gp + offset + 0x100); /* Clamp velocity to +-max_speed*scale */ { - f32 scale = Ground_801C0498(); - f32 vel = *vel_p; - f32 max_spd = grBb_804D69C8->x24; - - if (vel > max_spd * scale) { - f32 s2 = Ground_801C0498(); - *vel_p = grBb_804D69C8->x24 * s2; + if (*vel_p > grBb_804D69C8->x24 * Ground_801C0498()) { + *vel_p = grBb_804D69C8->x24 * Ground_801C0498(); } else { - f32 s2 = Ground_801C0498(); - f32 lim = grBb_804D69C8->x24 * s2; + f32 lim = grBb_804D69C8->x24 * Ground_801C0498(); - if (vel < -lim) { - f32 s3 = Ground_801C0498(); - *vel_p = -(grBb_804D69C8->x24 * s3); + if (*vel_p < -lim) { + *vel_p = -(grBb_804D69C8->x24 * Ground_801C0498()); } } } @@ -3574,22 +3688,18 @@ void grBigBlue_801ED694(Ground_GObj* gobj, s32 lane) /* Height/bounce simulation */ if (!((lane_gp[0xD4] >> 1) & 1)) { - f32 scale = Ground_801C0498(); - f32 grav = grBb_804D69C8->x48; - - *(f32*) (lane_gp + 0xF4) += grav * scale; + *(f32*) (lane_gp + 0xF4) += grBb_804D69C8->x48 * Ground_801C0498(); *(f32*) (lane_gp + 0xF8) += *(f32*) (lane_gp + 0xF4); if (*(f32*) (lane_gp + 0xF8) > 0.0F) { *(f32*) (lane_gp + 0xF8) = 0.0F; *(f32*) (lane_gp + 0xF4) = 0.0F; } else { - f32 s2 = Ground_801C0498(); - f32 blim = grBb_804D69C8->x4C; - - if (*(f32*) (lane_gp + 0xF8) < -(blim * s2)) { - f32 s3 = Ground_801C0498(); - *(f32*) (lane_gp + 0xF8) = -(grBb_804D69C8->x4C * s3); + if (*(f32*) (lane_gp + 0xF8) < + -(grBb_804D69C8->x4C * Ground_801C0498())) + { + *(f32*) (lane_gp + 0xF8) = + -(grBb_804D69C8->x4C * Ground_801C0498()); } } } else { @@ -3642,29 +3752,19 @@ void grBigBlue_801ED694(Ground_GObj* gobj, s32 lane) } /* Heading target interpolation */ - { - f32 ht = *(f32*) (lane_gp + 0x108); - f32 interp = grBb_804D69C8->x3C; - ht += interp * (heading_val - ht); - *(f32*) (lane_gp + 0x108) = ht; - } + *(f32*) (lane_gp + 0x108) = + grBb_804D69C8->x3C * (heading_val - *(f32*) (lane_gp + 0x108)) + + *(f32*) (lane_gp + 0x108); /* Rotation angle update */ - { - f32 rotation; - f32 ang_accel = grBb_804D69C8->x40; - - *(f32*) (lane_gp + 0x104) += (f32) 0.017453292F * ang_accel; - rotation = *(f32*) (lane_gp + 0x104); - - if (rotation > M_TAU) { - rotation = (f32) (rotation - M_TAU); - *(f32*) (lane_gp + 0x104) = rotation; - } - - heading_osc = *(f32*) (lane_gp + 0x108) * sinf(rotation); + *(f32*) (lane_gp + 0x104) += 0.017453292F * grBb_804D69C8->x40; + if (*(f32*) (lane_gp + 0x104) > M_TAU) { + *(f32*) (lane_gp + 0x104) = + (f32) ((f64) * (f32*) (lane_gp + 0x104) - M_TAU); } + heading_osc = *(f32*) (lane_gp + 0x108) * sinf(*(f32*) (lane_gp + 0x104)); + /* Compute ground reference level */ { f32 scale = Ground_801C0498(); @@ -3681,24 +3781,23 @@ void grBigBlue_801ED694(Ground_GObj* gobj, s32 lane) ground_y = grBigBlue_801EC58C((Vec3*) (lane_gp + 0xE0), &sp_vec, (f32) 500.0f); - if (0.0F != ground_y && ground_y > rank_factor) { + if (-F32_MAX != ground_y && ground_y > rank_factor) { if (*(f32*) (lane_gp + 0x10C) < 0.0F) { - u8 byte = lane_gp[0xD4]; - lane_gp[0xD4] = (byte & ~0x02); + ((grBb_ByteBits*) (lane_gp + 0xD4))->b6 = 0; /* goto required for match: skip collision/grounding, * jump to rotation convergence */ goto heading_converge; } } - if (0.0F != ground_y) { - f32 s = Ground_801C0498(); - f32 decay = grBb_804D69C8->x80; - *(f32*) (lane_gp + 0x10C) -= 3.0F * decay * s; + if (-F32_MAX != ground_y) { + *(f32*) (lane_gp + 0x10C) = + -(3.0F * (grBb_804D69C8->x80 * Ground_801C0498()) - + *(f32*) (lane_gp + 0x10C)); } else { - f32 s = Ground_801C0498(); - f32 decay = grBb_804D69C8->x80; - *(f32*) (lane_gp + 0x10C) -= decay * s; + *(f32*) (lane_gp + 0x10C) = + -(grBb_804D69C8->x80 * Ground_801C0498() - + *(f32*) (lane_gp + 0x10C)); } /* Lateral position += angular velocity */ @@ -3721,32 +3820,27 @@ void grBigBlue_801ED694(Ground_GObj* gobj, s32 lane) ground_y = grBigBlue_801EC58C((Vec3*) (lane_gp + 0xE0), &sp_vec, 20.0F * s); - if (0.0F != ground_y) { - f32 s2 = Ground_801C0498(); - f32 drag = grBb_804D69C8->x2C; - f32 base_y = drag * s2 + ground_y; + if (-F32_MAX != ground_y) { *(f32*) (lane_gp + 0xE4) = - heading_osc + *(f32*) (lane_gp + 0xF8) + base_y; + heading_osc + + (*(f32*) (lane_gp + 0xF8) + + (grBb_804D69C8->x2C * Ground_801C0498() + ground_y)); } else { - lane_gp[0xD4] = (lane_gp[0xD4] & ~0x02) | 0x02; - { - f32 s2 = Ground_801C0498(); - rank_factor = grBb_804D69C8->x84 * s2; - } + ((grBb_ByteBits*) (lane_gp + 0xD4))->b6 = 1; + rank_factor = grBb_804D69C8->x84 * Ground_801C0498(); *(f32*) (lane_gp + 0x10C) = sinf(f31_rot) * rank_factor; } } heading_converge: /* Update rotation: smooth toward target angle */ - if (0.0F != ground_y && !((lane_gp[0xD4] >> 1) & 1)) { + if (-F32_MAX != ground_y && !((lane_gp[0xD4] >> 1) & 1)) { f32 angle = atan2f(-sp_vec.x, sp_vec.y); f32 smooth = grBb_804D69C8->x50; f31_rot += smooth * (angle - f31_rot); } else { - f32 target_angle = (f32) 0.017453292F * grBb_804D69C8->x58; f32 damp = grBb_804D69C8->x54; - f31_rot += damp * (target_angle - f31_rot); + f31_rot += damp * (0.017453292F * grBb_804D69C8->x58 - f31_rot); } /* Update jobj transform */ @@ -3762,13 +3856,12 @@ s32 grBigBlue_801EDF44(Ground_GObj* gobj, s32 index) u8* gp; s32 result; s32 offset; - PAD_STACK(8); offset = index << 6; result = 0; gp = (u8*) gobj->user_data; - switch ((gp[offset + 0xD4] >> 2) & 0x3F) { + switch ((*(volatile u8*) (gp + offset + 0xD4) >> 2) & 0x3F) { case 1: break; case 9: @@ -3831,15 +3924,16 @@ s32 grBigBlue_801EDF44(Ground_GObj* gobj, s32 index) break; case 3: { u8* p = gp; + s32 i; s32 right_cnt = 0; s32 left_cnt = 0; s32 right_10 = 0; s32 left_10 = 0; - for (j = 0; j < 4; j++, p += 0x40) { + for (i = 0; i < 4; p += 0x40, i++) { u32 st; - if (j == index) { + if (i == index) { continue; } @@ -3940,7 +4034,7 @@ s32 grBigBlue_801EE398(Ground_GObj* gobj, s32 arg1, s32 arg2) s32 result = 0; Ground* gp = gobj->user_data; Vec3 pos; - PAD_STACK(12); + PAD_STACK(4); switch (arg2) { case 1: { @@ -3959,15 +4053,12 @@ s32 grBigBlue_801EE398(Ground_GObj* gobj, s32 arg1, s32 arg2) ((u8*) gp->gv.bigblue.xCC)[(*(u16*) car_d4 >> 4) & 0x1F] = 2; } { - register s32 st_val; - register u8 byte; - st_val = arg2; - byte = *car_d4; -#ifdef MWERKS_GEKKO - asm { rlwimi byte, st_val, 2, 24, 29 } -#endif + typedef struct grBb_StateBits { + u8 state : 6; + u8 pad0 : 2; + } grBb_StateBits; result = 1; - *car_d4 = byte; + ((grBb_StateBits*) car_d4)->state = arg2; } break; } @@ -3979,16 +4070,13 @@ s32 grBigBlue_801EE398(Ground_GObj* gobj, s32 arg1, s32 arg2) *(s32*) (base + 0xF0) = 0x14; } { - s32 d4_off = offset + 0xD4; - register s32 st_val; - register u8 byte; - st_val = arg2; + typedef struct grBb_StateBits { + u8 state : 6; + u8 pad0 : 2; + } grBb_StateBits; result = 1; - byte = ((u8*) gp)[d4_off]; -#ifdef MWERKS_GEKKO - asm { rlwimi byte, st_val, 2, 24, 29 } -#endif - ((u8*) gp)[d4_off] = byte; + ((grBb_StateBits*) &gp->gv.bigblue.car.lanes[arg1].state)->state = + arg2; } break; } @@ -4027,16 +4115,13 @@ s32 grBigBlue_801EE398(Ground_GObj* gobj, s32 arg1, s32 arg2) *(s32*) (base + 0xF0) = lo; } { - s32 d4_off = offset + 0xD4; - register s32 st_val; - register u8 byte; - st_val = arg2; + typedef struct grBb_StateBits { + u8 state : 6; + u8 pad0 : 2; + } grBb_StateBits; result = 1; - byte = ((u8*) gp)[d4_off]; -#ifdef MWERKS_GEKKO - asm { rlwimi byte, st_val, 2, 24, 29 } -#endif - ((u8*) gp)[d4_off] = byte; + ((grBb_StateBits*) &gp->gv.bigblue.car.lanes[arg1].state) + ->state = arg2; } } break; @@ -4087,20 +4172,17 @@ s32 grBigBlue_801EE398(Ground_GObj* gobj, s32 arg1, s32 arg2) car = (u8*) gp + offset; { - register s32 slot_val; - register u16 hw; - slot_val = slot; - hw = *(u16*) (car + 0xD4); -#ifdef MWERKS_GEKKO - asm { rlwimi hw, slot_val, 4, 23, 27 } -#endif + typedef struct grBb_SlotBits { + u16 pad0 : 7; + u16 slot : 5; + u16 pad1 : 4; + } grBb_SlotBits; + ((grBb_SlotBits*) (car + 0xD4))->slot = slot; dir = 0; - *(u16*) (car + 0xD4) = hw; } car_d4 = car + 0xD4; car_e0 = (Vec3*) (car + 0xE0); - car_ec = (f32*) (car + 0xEC); { register s32 dir_val; @@ -4155,6 +4237,7 @@ s32 grBigBlue_801EE398(Ground_GObj* gobj, s32 arg1, s32 arg2) *(s32*) (car + 0xF0) = lo; } + car_ec = (f32*) (car_e0 + 1); ((u8*) gp->gv.bigblue.xCC)[slot] = 1; *car_ec = 0.0f; @@ -4175,15 +4258,12 @@ s32 grBigBlue_801EE398(Ground_GObj* gobj, s32 arg1, s32 arg2) } { - register s32 st_val; - register u8 byte; - st_val = arg2; - byte = *car_d4; -#ifdef MWERKS_GEKKO - asm { rlwimi byte, st_val, 2, 24, 29 } -#endif + typedef struct grBb_StateBits { + u8 state : 6; + u8 pad0 : 2; + } grBb_StateBits; result = 1; - *car_d4 = byte; + ((grBb_StateBits*) car_d4)->state = arg2; } } } @@ -4236,20 +4316,17 @@ s32 grBigBlue_801EE398(Ground_GObj* gobj, s32 arg1, s32 arg2) car = (u8*) gp + offset; { - register s32 slot_val; - register u16 hw; - slot_val = slot; - hw = *(u16*) (car + 0xD4); -#ifdef MWERKS_GEKKO - asm { rlwimi hw, slot_val, 4, 23, 27 } -#endif + typedef struct grBb_SlotBits { + u16 pad0 : 7; + u16 slot : 5; + u16 pad1 : 4; + } grBb_SlotBits; + ((grBb_SlotBits*) (car + 0xD4))->slot = slot; dir = 0; - *(u16*) (car + 0xD4) = hw; } car_d4 = car + 0xD4; car_e0 = (Vec3*) (car + 0xE0); - car_ec = (f32*) (car + 0xEC); { register s32 dir_val; @@ -4304,6 +4381,7 @@ s32 grBigBlue_801EE398(Ground_GObj* gobj, s32 arg1, s32 arg2) *(s32*) (car + 0xF0) = lo; } + car_ec = (f32*) (car_e0 + 1); ((u8*) gp->gv.bigblue.xCC)[slot] = 1; *car_ec = 0.0f; @@ -4324,15 +4402,12 @@ s32 grBigBlue_801EE398(Ground_GObj* gobj, s32 arg1, s32 arg2) } { - register s32 st_val; - register u8 byte; - st_val = arg2; - byte = *car_d4; -#ifdef MWERKS_GEKKO - asm { rlwimi byte, st_val, 2, 24, 29 } -#endif + typedef struct grBb_StateBits { + u8 state : 6; + u8 pad0 : 2; + } grBb_StateBits; result = 1; - *car_d4 = byte; + ((grBb_StateBits*) car_d4)->state = arg2; } } } @@ -4347,30 +4422,24 @@ s32 grBigBlue_801EE398(Ground_GObj* gobj, s32 arg1, s32 arg2) *(s32*) (base + 0xF0) = 0x3E8; } { - s32 d4_off = offset + 0xD4; - register s32 st_val; - register u8 byte; - st_val = arg2; + typedef struct grBb_StateBits { + u8 state : 6; + u8 pad0 : 2; + } grBb_StateBits; result = 1; - byte = ((u8*) gp)[d4_off]; -#ifdef MWERKS_GEKKO - asm { rlwimi byte, st_val, 2, 24, 29 } -#endif - ((u8*) gp)[d4_off] = byte; + ((grBb_StateBits*) &gp->gv.bigblue.car.lanes[arg1].state)->state = + arg2; } break; } case 9: { - s32 d4_off = (arg1 << 6) + 0xD4; - register s32 st_val; - register u8 byte; - st_val = arg2; - byte = ((u8*) gp)[d4_off]; -#ifdef MWERKS_GEKKO - asm { rlwimi byte, st_val, 2, 24, 29 } -#endif - ((u8*) gp)[d4_off] = byte; + typedef struct grBb_StateBits { + u8 state : 6; + u8 pad0 : 2; + } grBb_StateBits; + ((grBb_StateBits*) &gp->gv.bigblue.car.lanes[arg1].state)->state = + arg2; break; } } @@ -4392,7 +4461,7 @@ bool grBigBlue_801EEF00(Ground_GObj* gobj, s32 index) offset = index << 6; gp = (u8*) gobj->user_data; - switch ((gp[offset + 0xD4] >> 2) & 0x3F) { + switch ((*(volatile u8*) (gp + offset + 0xD4) >> 2) & 0x3F) { case 1: return 0; diff --git a/src/melee/gr/grbigblueroute.c b/src/melee/gr/grbigblueroute.c index 2b507ef749..10cf5098f8 100644 --- a/src/melee/gr/grbigblueroute.c +++ b/src/melee/gr/grbigblueroute.c @@ -534,22 +534,13 @@ s32 grBigBlueRoute_8020C530(Ground_GObj* arg0) HSD_ASSERT(0X2E5, 0); } -/// @todo Currently 92.06% match - register allocation (gp in r30 vs r31) -/// and addressing-mode choices for RouteEntry stores. -void grBigBlueRoute_8020C85C(Ground_GObj* gobj) +/// @todo Register allocation and addressing-mode choices for RouteEntry +/// stores. +static inline void grBigBlueRoute_SpawnRoute(Ground* gp, Ground_GObj* gobj) { - Ground* gp = GET_GROUND(gobj); s32 route_idx; PAD_STACK(8); - if (!((f32) gp->u.car.x108 < 1.0f + grBb_Route_804D6A68->x40)) { - return; - } - - if (gp->u.car.x10A-- >= 0) { - return; - } - if (gp->u.car.x108 == 0) { route_idx = 30; ((RouteEntry*) gp->u.car.car_info)[30].flags.b1 = 1; @@ -587,13 +578,13 @@ void grBigBlueRoute_8020C85C(Ground_GObj* gobj) (&((RouteEntry*) gp->u.car.car_info)[route_idx])->flags.b2_5 = 1; re = &((RouteEntry*) gp->u.car.car_info)[route_idx]; - re->x4 = 0.0F; + re->x4 = 1.0F; re = &((RouteEntry*) gp->u.car.car_info)[route_idx]; re->x8 = grBb_Route_804D6A68->x20; re = &((RouteEntry*) gp->u.car.car_info)[route_idx]; - re->xC = 0.0F; + re->xC = 0.5F; { f32 rand = HSD_Randf(); @@ -664,6 +655,26 @@ void grBigBlueRoute_8020C85C(Ground_GObj* gobj) gp->u.car.x108++; } +static inline int grBigBlueRoute_DelayRoute(Ground* gp) +{ + return gp->u.car.x10A-- >= 0; +} + +void grBigBlueRoute_8020C85C(Ground_GObj* gobj) +{ + Ground* gp = GET_GROUND(gobj); + + if (!((f32) gp->u.car.x108 < 1.0f + grBb_Route_804D6A68->x40)) { + return; + } + + if (grBigBlueRoute_DelayRoute(gp)) { + return; + } + + grBigBlueRoute_SpawnRoute(gp, gobj); +} + static const Vec3 grBb_Route_803B83E0 = { 0.0f, 1.0f, 0.0f }; /// @todo Currently 89.41% match - SYSTEMIC: float-constant hoisting order and @@ -679,7 +690,7 @@ void grBigBlueRoute_8020CD20(Ground_GObj* gobj) Vec3 pos; Vec3 rot; Vec3 fighter_pos; - PAD_STACK(0x3C); + PAD_STACK(0x2C); fighter = Ground_801C57A4(); if (fighter != NULL) { @@ -885,6 +896,7 @@ void grBigBlueRoute_8020CD20(Ground_GObj* gobj) Vec3 p1; Vec3 road_tan; Vec3 road; + Vec3 air_rot; prog = (RE_ENTRY->x14 - RE_ENTRY->x24) / (1.0f - RE_ENTRY->x24); @@ -900,7 +912,7 @@ void grBigBlueRoute_8020CD20(Ground_GObj* gobj) PSVECCrossProduct(&tangent, &side, &up); grBigBlueRoute_8020DD64(&up); Ground_801C5AEC(&orient, &tangent, &side, &up); - rot = orient; + air_rot = orient; { f32 s = 45.0f * Ground_801C0498(); up.x *= s; @@ -925,6 +937,7 @@ void grBigBlueRoute_8020CD20(Ground_GObj* gobj) pos.y *= prog; pos.z *= prog; lbVector_Add(&pos, &air); + rot = air_rot; if (RE_ENTRY->x14 == 1.0f) { RE_ENTRY->flags.b2_5 = 0; diff --git a/src/melee/gr/grcastle.c b/src/melee/gr/grcastle.c index d9c8739334..7c17fa121a 100644 --- a/src/melee/gr/grcastle.c +++ b/src/melee/gr/grcastle.c @@ -225,15 +225,36 @@ static const grCastle_TargetTable grCs_803B7EFC = { { { 6, 5 }, } }; -static const unkCastleCallback grCs_803B7F28[5] = { - grCastle_801D0550, grCastle_801D059C, grCastle_801D05E8, - grCastle_801D0634, grCastle_801D0680, -}; +typedef struct grCastle_CallbackTable { + unkCastleCallback callbacks[5]; +} grCastle_CallbackTable; + +typedef struct grCastle_CallbackTable2 { + unkCastleCallback2 callbacks[5]; +} grCastle_CallbackTable2; + +/// Per-object damage-received callbacks, dispatched through the yaku item's +/// x18 slot (it_802E6AEC -> it_2E6A_Logic117_DmgReceived). Wrapped in a +/// struct so grCastle_801CFBD4 copies them with a struct assignment, which +/// reproduces the original inline block-copy codegen (exact match; verified +/// no regression in any other symbol of this unit). +static const grCastle_CallbackTable grCastle_DmgReceivedCallbacks = { { + grCastle_801D0550, + grCastle_801D059C, + grCastle_801D05E8, + grCastle_801D0634, + grCastle_801D0680, +} }; -static const unkCastleCallback2 grCs_803B7F3C[5] = { - grCastle_801D06CC, grCastle_801D0744, grCastle_801D07BC, - grCastle_801D0834, grCastle_801D08AC, -}; +/// Per-object touched callbacks, dispatched through the yaku item's x1C slot +/// (it_802E6AEC -> it_802E7054 with item->toucher). +static const grCastle_CallbackTable2 grCastle_TouchedCallbacks = { { + grCastle_801D06CC, + grCastle_801D0744, + grCastle_801D07BC, + grCastle_801D0834, + grCastle_801D08AC, +} }; typedef struct grCastle_YOffsets { f32 v[6]; @@ -539,6 +560,7 @@ bool grCastle_801CDC3C(Ground_GObj* gobj) void grCastle_801CDC44(Ground_GObj* gobj) { + f32 move_speed; Ground* gp = GET_GROUND(gobj); s32 i = 0; PAD_STACK(8); @@ -572,21 +594,19 @@ void grCastle_801CDC44(Ground_GObj* gobj) case 2: { f32 wind = gp->gv.castle8.plat[0].wind; if (wind > 0.0f) { - f32 speed_cap = grCs_804D6970->x28; - f32 speed; f32 max_val; f32 cur; - speed = wind * grCs_804D6970->x20 + grCs_804D6970->x24; - if (speed > speed_cap) { - speed = speed_cap; + move_speed = wind * grCs_804D6970->x20 + grCs_804D6970->x24; + if (move_speed > grCs_804D6970->x28) { + move_speed = grCs_804D6970->x28; } max_val = grCs_804D6970->x10; cur = gp->gv.castle8.plat[0].pos; - if ((max_val - cur) < speed) { + if ((max_val - cur) < move_speed) { gp->gv.castle8.plat[0].pos = max_val; } else { - gp->gv.castle8.plat[0].pos = cur + speed; + gp->gv.castle8.plat[0].pos = cur + move_speed; } HSD_JObjSetTranslateY(gp->gv.castle8.plat[0].jobj, gp->gv.castle8.plat[0].pos); @@ -602,22 +622,16 @@ void grCastle_801CDC44(Ground_GObj* gobj) gp->gv.castle8.plat[0].timer = 0; gp->gv.castle8.plat[0].state = 0; } else { - f32 speed_cap = grCs_804D6970->x34; - f32 speed; - f32 cur; - f32 min_val; - - speed = wind * grCs_804D6970->x2C + grCs_804D6970->x30; - if (speed > speed_cap) { - speed = speed_cap; + move_speed = wind * grCs_804D6970->x2C + grCs_804D6970->x30; + if (move_speed > grCs_804D6970->x34) { + move_speed = grCs_804D6970->x34; } - cur = gp->gv.castle8.plat[0].pos; - min_val = grCs_804D6970->x14; - (void) min_val; - if ((cur - min_val) < speed) { - gp->gv.castle8.plat[0].pos = min_val; + if ((gp->gv.castle8.plat[0].pos - grCs_804D6970->x14) < + move_speed) + { + gp->gv.castle8.plat[0].pos = grCs_804D6970->x14; } else { - gp->gv.castle8.plat[0].pos = cur - speed; + gp->gv.castle8.plat[0].pos -= move_speed; } HSD_JObjSetTranslateY(gp->gv.castle8.plat[0].jobj, gp->gv.castle8.plat[0].pos); @@ -815,7 +829,7 @@ void grCastle_801CE3AC(Ground_GObj* gobj) Vec3 pos; Vec3 offset; - jobj = GET_JOBJ(gp->gv.castle5.xCC); + jobj = HSD_GObjGetHSDObj(gp->gv.castle5.xCC); rot = grCs_803B7EB8; offset.z = 0.0f; @@ -1276,6 +1290,7 @@ bool grCastle_801CF300(Ground_GObj* gobj) void grCastle_801CF308(Ground_GObj* gobj) { s32 var_r6 = 0; + Ground* user_data = (Ground*) gobj->user_data; Ground* gp = (Ground*) gobj->user_data; HSD_JObj* jobj = (HSD_JObj*) gobj->hsd_obj; grCastle_BlinkTable tbl = grCs_803B7EC8; @@ -1285,7 +1300,7 @@ void grCastle_801CF308(Ground_GObj* gobj) Quaternion quat; PAD_STACK(32); - switch (gp->gv.castle5.xC4) { + switch (user_data->gv.castle5.xC4) { case 1: gp->gv.castle.xC8 = -1; gp->gv.castle11.xCA = 0; @@ -1369,6 +1384,12 @@ void grCastle_801CF308(Ground_GObj* gobj) } } +/// Preserve the original .sdata2 placement of the double-precision 0.5. +static void grCastle_ForceSdata2Order(void) +{ + (void) 0.5; +} + void grCastle_801CF74C(Ground_GObj* gobj) {} void grCastle_801CF750(Ground* gp, s32 arg1, CollData* cd, s32 arg3, @@ -1406,10 +1427,8 @@ void grCastle_801CF7B0(Ground_GObj* gobj) : x2; } -HSD_JObj* grCastle_801CF868(Ground_GObj* gobj) +static inline void grCastle_UpdateSatellite(Ground* gp) { - Ground* gp = GET_GROUND(gobj); - if ((gp->gv.castle12.xC4[0] != 0 || gp->gv.castle12.xC4[1] != 0 || gp->gv.castle12.xC4[2] != 0) && (gp->gv.castle12.xD0 == -1 || @@ -1424,8 +1443,8 @@ HSD_JObj* grCastle_801CF868(Ground_GObj* gobj) s16 timer = gp->gv.castle12.xD2; gp->gv.castle12.xD2 = timer - 1; if ((s16) gp->gv.castle12.xD2 < 0) { - s16 base = grCs_804D6970->x2; - s16 range_end = grCs_804D6970->x0; + s32 base = grCs_804D6970->x2; + s32 range_end = grCs_804D6970->x0; if (base > range_end) { s32 diff = base - range_end; @@ -1504,6 +1523,13 @@ HSD_JObj* grCastle_801CF868(Ground_GObj* gobj) } } +HSD_JObj* grCastle_801CF868(Ground_GObj* gobj) +{ + Ground* gp = GET_GROUND(gobj); + PAD_STACK(48); + grCastle_UpdateSatellite(gp); +} + void fn_801CFAFC(Item_GObj* item, Ground* gp, Vec3* pos, HSD_GObj* gobj) { PAD_STACK(4); @@ -1526,17 +1552,16 @@ s32 grCastle_801CFBD4(Ground_GObj* gobj, s32 arg1) s32 i = 0; s32 result = 1; Ground* gp = (Ground*) gobj->user_data; - unkCastleCallback cb1[5]; - unkCastleCallback2 cb2[5]; + grCastle_CallbackTable cb1; + grCastle_CallbackTable2 cb2; Vec3 pos; Vec3 target_pos; - const unkCastleCallback* cb1_src = grCs_803B7F28; - const unkCastleCallback2* cb2_src = grCs_803B7F3C; - PAD_STACK(12); + f32 newScale; + PAD_STACK(4); - do { - HSD_JObj* jobj = gp->gv.castle10.jobjs[i]; - if (jobj != NULL) { + for (; i < 5; i++) { + HSD_JObj* jobj; + if ((jobj = gp->gv.castle10.jobjs[i]) != NULL) { HSD_JObj* eff_a = gp->gv.castle10.effect_a[i]; HSD_JObj* eff_b = gp->gv.castle10.effect_b[i]; @@ -1579,7 +1604,6 @@ s32 grCastle_801CFBD4(Ground_GObj* gobj, s32 arg1) gp->gv.castle10.idx[i] = 0; } else { HSD_JObj* target; - f32 newScale; if (eff_a != NULL && eff_b != NULL) { if (HSD_JObjGetFlags(eff_a) & 0x10) { @@ -1591,8 +1615,7 @@ s32 grCastle_801CFBD4(Ground_GObj* gobj, s32 arg1) target = jobj; } - newScale = HSD_JObjGetScaleY(target); - if (newScale < 1.0f) { + if ((newScale = HSD_JObjGetScaleY(target)) < 1.0f) { newScale += grCs_804D6970->x48; if (newScale >= 1.0f) { newScale = 1.0f; @@ -1600,24 +1623,17 @@ s32 grCastle_801CFBD4(Ground_GObj* gobj, s32 arg1) if (eff_a != NULL && !(HSD_JObjGetFlags(eff_a) & 0x10)) { - cb1[0] = cb1_src[0]; - cb1[1] = cb1_src[1]; - cb1[2] = cb1_src[2]; - cb1[3] = cb1_src[3]; - cb1[4] = cb1_src[4]; - cb2[0] = cb2_src[0]; - cb2[1] = cb2_src[1]; - cb2[2] = cb2_src[2]; - cb2[3] = cb2_src[3]; - cb2[4] = cb2_src[4]; + cb1 = grCastle_DmgReceivedCallbacks; + cb2 = grCastle_TouchedCallbacks; gp->gv.castle10.x10C[i] = (u32) grMaterial_801C8CFC( 0, 2, gp, target, NULL, (void (*)(Item_GObj*, Ground*, Vec3*, - HSD_GObj*, - f32))(Event) cb1[i], + HSD_GObj*, f32))( + Event) cb1.callbacks[i], (void (*)(Item_GObj*, Ground*, - HSD_GObj*))(Event) cb2[i]); + HSD_GObj*))( + Event) cb2.callbacks[i]); grMaterial_801C8DE0( (Item_GObj*) gp->gv.castle10.x10C[i], 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 8.0f); @@ -1632,7 +1648,6 @@ s32 grCastle_801CFBD4(Ground_GObj* gobj, s32 arg1) } else { if (!(HSD_JObjGetFlags(jobj) & 0x10)) { HSD_JObj* target; - f32 newScale; if (eff_a != NULL && eff_b != NULL) { if (HSD_JObjGetFlags(eff_a) & 0x10) { @@ -1644,8 +1659,7 @@ s32 grCastle_801CFBD4(Ground_GObj* gobj, s32 arg1) target = jobj; } - newScale = HSD_JObjGetScaleY(target); - if (newScale > 0.0001f) { + if ((newScale = HSD_JObjGetScaleY(target)) > 0.0001f) { newScale -= grCs_804D6970->x4C; if (newScale <= 0.0001f) { newScale = 0.0001f; @@ -1664,8 +1678,7 @@ s32 grCastle_801CFBD4(Ground_GObj* gobj, s32 arg1) mpLib_80057BC0(gp->gv.castle10.x120[i]); } } - i++; - } while (i < 5); + } return result; } @@ -1983,10 +1996,10 @@ void grCastle_801D0D84(HSD_JObj* jobj) } } - if (rot.y > 3.1415926535897931) { - rot.y = (f32) ((f64) rot.y - 6.2831853071795862); - } else if (rot.y < -3.1415926535897931) { - rot.y += 6.2831853071795862; + if (rot.y > 3.1415926292538643) { + rot.y = (f32) ((f64) rot.y - 6.2831852585077286); + } else if (rot.y < -3.1415926292538643) { + rot.y += 6.2831852585077286; } HSD_JObjSetRotation(jobj, &rot); diff --git a/src/melee/gr/grcorneria.c b/src/melee/gr/grcorneria.c index c8f9d74a54..a86184178b 100644 --- a/src/melee/gr/grcorneria.c +++ b/src/melee/gr/grcorneria.c @@ -250,6 +250,37 @@ typedef struct { int data[3]; } grCn_Entry; +typedef struct grCn_Data { + /* 0x000 */ u8 pad0[0x30]; + /* 0x030 */ HSD_GObj* arwing_gobj[3]; + /* 0x03C */ s32 arwing_type[3]; + /* 0x048 */ s32 arwing_group[3]; + /* 0x054 */ u8 pad1[0x1F0]; + /* 0x244 */ f32 cannon_x; + /* 0x248 */ f32 cannon_y; + /* 0x24C */ u8 pad2[0x34]; + /* 0x280 */ Vec3 effect_pos; + /* 0x28C */ u8 pad3[0x6C]; + /* 0x2F8 */ s32 anim_ids[14]; + /* 0x330 */ Vec3 positions[14]; + /* 0x3D8 */ union { + s32 x3D8[27]; + struct { + s32 pad3D8[5]; + char jobj_use_quaternion_assert[0x28]; + } literals; + }; + /* 0x444 */ s32 x444[5]; + /* 0x458 */ s32 x458[8]; + /* 0x478 */ s32 x478[3]; + /* 0x484 */ u8 pad5a[0x34]; + /* 0x4B8 */ struct { + s16 joint0; + s16 joint1; + } dialog_joints[5]; + /* 0x4CC */ grCn_Entry entries[][5]; +} grCn_Data; + void grCorneria_801DCCFC(void) { s32 stage; @@ -408,7 +439,7 @@ void grCorneria_801DCE1C(void) int i; for (i = 0; i < 3; i++) { - if (count == i) { + if (i == count) { continue; } switch (grCn_803E1D68.arwing_type[i]) { @@ -1189,17 +1220,17 @@ void grCorneria_801DED50(Ground_GObj* gobj) Ground* gp = GET_GROUND(gobj); HSD_JObj* jobj = GET_JOBJ(gobj); Vec3 pos = grCn_803B80B4; - PAD_STACK(8); + grCn_Data* data = (grCn_Data*) grCn_803E1D38; if (grCn_804D69AC) { return; } - if (grCn_803E1D68.arwing_gobj[gp->gv.corneria2.xC8] != NULL) { - if (grCn_803E1D68.arwing_group[gp->gv.corneria2.xC8] == 4) { + if (data->arwing_gobj[gp->gv.corneria2.xC8] != NULL) { + if (data->arwing_group[gp->gv.corneria2.xC8] == 4) { HSD_JObjSetRotationZ(Ground_801C3FA4(gobj, 1), 0.0f); } - switch (grCn_803E1D68.arwing_type[gp->gv.corneria2.xC8]) { + switch (data->arwing_type[gp->gv.corneria2.xC8]) { case 0: case 1: case 2: @@ -1219,8 +1250,7 @@ void grCorneria_801DED50(Ground_GObj* gobj) gp->gv.corneria2.xF4 = new_state; grAnime_801C8098( gobj, - grCn_803E214C[grCn_803E1D68 - .arwing_group[gp->gv.corneria2.xC8]], + grCn_803E214C[data->arwing_group[gp->gv.corneria2.xC8]], 7, (&grCn_803E21B0[gp->gv.corneria2.xF4])[get_grp_off( gobj)], @@ -1228,8 +1258,9 @@ void grCorneria_801DED50(Ground_GObj* gobj) } else { HSD_JObjSetRotationZ( Ground_801C3FA4( - gobj, grCn_803E21B0[grCn_803E1D68.arwing_group - [gp->gv.corneria2.xC8]]), + gobj, + grCn_803E21B0[data->arwing_group + [gp->gv.corneria2.xC8]]), 0.0f); } gp->gv.corneria2.xF8 -= 1; @@ -1245,15 +1276,14 @@ void grCorneria_801DED50(Ground_GObj* gobj) break; } { - HSD_GObj* arwing = - grCn_803E1D68.arwing_gobj[gp->gv.corneria2.xC8]; + HSD_GObj* arwing = data->arwing_gobj[gp->gv.corneria2.xC8]; if (arwing != NULL) { Ground* arwing_gp = GET_GROUND(arwing); Ground* ship_gp = GET_GROUND(Ground_801C2BA4(3)); Vec3 sp64; lb_8000B1CC(Ground_801C3FA4(arwing, 4), NULL, &sp64); { - int* types = grCn_803E1D68.arwing_type; + s32* types = data->arwing_type; int atype = types[arwing_gp->gv.corneria2.xC8]; pos.x = ship_gp->gv.corneria.offset_x + (-sp64.z + lbl_803E2068[atype].x); @@ -1273,8 +1303,8 @@ void grCorneria_801DED50(Ground_GObj* gobj) lb_8000B1CC( Ground_801C3FA4( gobj, - grCn_803E21B0[grCn_803E1D68 - .arwing_group[gp->gv.corneria2.xC8]]), + grCn_803E21B0[data->arwing_group + [gp->gv.corneria2.xC8]]), NULL, &pos); { f32 rot_z; @@ -1290,8 +1320,8 @@ void grCorneria_801DED50(Ground_GObj* gobj) } rot_z = HSD_JObjGetRotationZ(Ground_801C3FA4( gobj, - grCn_803E21B0[grCn_803E1D68 - .arwing_group[gp->gv.corneria2.xC8]])); + grCn_803E21B0[data->arwing_group + [gp->gv.corneria2.xC8]])); angle = rot_z; { HSD_GObj* item = gp->gv.corneria2.xDC; @@ -1379,7 +1409,7 @@ void grCorneria_801DED50(Ground_GObj* gobj) } { HSD_GObj* arwing; - if ((arwing = grCn_803E1D68.arwing_gobj[gp->gv.corneria2.xC8])) + if ((arwing = data->arwing_gobj[gp->gv.corneria2.xC8])) { Ground* arwing_gp = GET_GROUND(arwing); Ground* ship_gp = GET_GROUND(Ground_801C2BA4(3)); @@ -1387,8 +1417,7 @@ void grCorneria_801DED50(Ground_GObj* gobj) lb_8000B1CC(Ground_801C3FA4(arwing, 4), NULL, &sp48); { s32 atype = - grCn_803E1D68 - .arwing_type[arwing_gp->gv.corneria2.xC8]; + data->arwing_type[arwing_gp->gv.corneria2.xC8]; pos.x = ship_gp->gv.corneria.offset_x + (-sp48.z + lbl_803E2068[atype].x); pos.y = sp48.y + lbl_803E2068[atype].y; @@ -1422,7 +1451,7 @@ void grCorneria_801DED50(Ground_GObj* gobj) { s32 grp_off = -1; { - int* groups = grCn_803E1D68.arwing_group; + s32* groups = data->arwing_group; int g = groups[GET_GROUND(gobj)->gv.corneria2.xC8]; switch (g) { case 0: @@ -2134,12 +2163,28 @@ void fn_801E12D4(Item_GObj* gobj, Ground* gr, Vec3* pos, HSD_GObj* arg3, } } +static inline f32 grCn_GetX1C(void) +{ + return grCn_804D69A0->x1C; +} + +static inline HSD_JObj* grCn_GetCannonJObj2(Ground_GObj* gobj) +{ + return Ground_801C3FA4(gobj, 2); +} + +#define grCn_803E1D38 (*(grCn_Data*) grCn_803E1D38) + void grCorneria_801E1348(Ground_GObj* gobj) { Vec3 sp40; + u8 unused[8]; + Vec3 sp2C; + Vec3 sp20; Ground* gp = GET_GROUND(gobj); + grCn_Data* data = &grCn_803E1D38; - PAD_STACK(8); + PAD_STACK(12); switch (gp->gv.corneria.x108) { case 0: @@ -2150,36 +2195,40 @@ void grCorneria_801E1348(Ground_GObj* gobj) gp->gv.corneria.x10C = grCn_804D69A0->x28; Ground_801C53EC(0x55739); } else { - int imax; - int imin = grCn_804D69A0->x30; + s32 imax; + s32 imin = grCn_804D69A0->x30; imax = grCn_804D69A0->x34; if (imax > imin) { - imax = imin + randi(imax - imin); + s32 range = imax - imin; + imax = imin + (range != 0 ? HSD_Randi(range) : 0); } else if (imax < imin) { - imax += randi(imin - imax); + s32 range = imin - imax; + imax += (range != 0 ? HSD_Randi(range) : 0); } gp->gv.corneria.x119 = 1; gp->gv.corneria.x118 = imax; gp->gv.corneria.x10C = grCn_804D69A0->x2C; Ground_801C53EC(0x5573A); } - sp40.x = grCn_803E1FAC[1].x; - sp40.y = grCn_803E1FAC[1].y; - sp40.z = grCn_803E1FAC[1].z; + sp40.x = data->effect_pos.x; + sp40.y = data->effect_pos.y; + sp40.z = data->effect_pos.z; grLib_801C9808(0xBC, 0, Ground_801C3FA4(gobj, 2)); grLib_801C9808(0xBC, 0, Ground_801C3FA4(gobj, 3)); - Item_80268E5C(gp->gv.corneria.left_cannon, 2, ITEM_ANIM_UPDATE); - Item_80268E5C(gp->gv.corneria.right_cannon, 2, ITEM_ANIM_UPDATE); - grMaterial_801C8E28(gp->gv.corneria.left_cannon); - grMaterial_801C8E28(gp->gv.corneria.right_cannon); + Item_80268E5C((HSD_GObj*) gp->gv.corneria.left_cannon, 2, + ITEM_ANIM_UPDATE); + Item_80268E5C((HSD_GObj*) gp->gv.corneria.right_cannon, 2, + ITEM_ANIM_UPDATE); + grMaterial_801C8E28((HSD_GObj*) gp->gv.corneria.left_cannon); + grMaterial_801C8E28((HSD_GObj*) gp->gv.corneria.right_cannon); gp->gv.corneria.x108 = 1; - } else { - gp->gv.corneria.x110 -= 1; + return; } - break; + gp->gv.corneria.x110 -= 1; + return; case 1: if (gp->gv.corneria.x10C == 0) { - hsd_8039D580(Ground_801C3FA4(gobj, 2)); + hsd_8039D580(grCn_GetCannonJObj2(gobj)); hsd_8039D580(Ground_801C3FA4(gobj, 3)); Item_80268E5C((HSD_GObj*) gp->gv.corneria.left_cannon, 0, ITEM_ANIM_UPDATE); @@ -2187,46 +2236,48 @@ void grCorneria_801E1348(Ground_GObj* gobj) ITEM_ANIM_UPDATE); gp->gv.corneria.x10C = grCn_804D69A0->x20; gp->gv.corneria.x108 = 2; - } else { - gp->gv.corneria.x10C -= 1; + return; } - break; + gp->gv.corneria.x10C -= 1; + return; case 2: { - bool found = false; - Vec3 sp2C; + int found = 0; lb_8000B1CC(Ground_801C3FA4(gobj, 2), NULL, &sp2C); { HSD_GObj* fighter = HSD_GObj_Entities->fighters; while (fighter != NULL) { - Vec3 sp20; - PAD_STACK(0x10); + f32 dy; ftLib_80086644(fighter, &sp20); - if (ABS(sp2C.y - sp20.y) <= 10.0f) { - found = true; + dy = sp2C.y - sp20.y; + if (dy < 0.0f) { + dy = -dy; + } + if (dy <= 10.0f) { + found = 1; break; } fighter = fighter->next; } } - if (found) { + if (found != 0) { gp->gv.corneria.x10C = 0; } if (gp->gv.corneria.x10C == 0) { gp->gv.corneria.x108 = 3; grMaterial_801C8E08((Item_GObj*) gp->gv.corneria.left_cannon); grMaterial_801C8E08((Item_GObj*) gp->gv.corneria.right_cannon); - } else { - gp->gv.corneria.x10C -= 1; + return; } - break; + gp->gv.corneria.x10C -= 1; + return; } case 3: if (gp->gv.corneria.x118 != 0) { if (gp->gv.corneria.x110 == 0) { HSD_JObj* cannon; - int side = gp->gv.corneria.x11A; - sp40.x = 20.0f + grCn_803E1F70[1].x; - sp40.y = 2.0f + grCn_803E1F70[1].y; + s32 side = gp->gv.corneria.x11A; + sp40.x = 20.0f + data->cannon_x; + sp40.y = 2.0f + data->cannon_y; if (side != 0) { sp40.z = 9.0f; cannon = Ground_801C3FA4(gobj, 2); @@ -2240,43 +2291,59 @@ void grCorneria_801E1348(Ground_GObj* gobj) gp->gv.corneria.x11A ^= 1; gp->gv.corneria.x110 = 0xA; gp->gv.corneria.x118 -= 1; - } else { - gp->gv.corneria.x110 -= 1; + return; } - } else { + gp->gv.corneria.x110 -= 1; + return; + } + { + s32 rand_range = grCn_804D69A0->x18; + s32 range = grCn_804D69A0->x18; gp->gv.corneria.x110 = - grCn_804D69A0->x1C + randi(grCn_804D69A0->x18); - gp->gv.corneria.x10C = 0; - gp->gv.corneria.x108 = 0; + (s32) (grCn_GetX1C() + + (range != 0 ? HSD_Randi(rand_range) : 0)); } - break; + gp->gv.corneria.x10C = 0; + gp->gv.corneria.x108 = 0; + return; case 4: grLib_801C9808(0xE3, 0, Ground_801C3FA4(gobj, 2)); grLib_801C9808(0xE3, 0, Ground_801C3FA4(gobj, 3)); - sp40.x = grCn_803E1FAC[1].x; - sp40.y = grCn_803E1FAC[1].y; - sp40.z = grCn_803E1FAC[1].z; + sp40.x = data->effect_pos.x; + sp40.y = data->effect_pos.y; + sp40.z = data->effect_pos.z; Camera_80030E44(4, &sp40); Ground_801C53EC(0x76); HSD_JObjSetFlags(Ground_801C3FA4(gobj, 6), JOBJ_HIDDEN); HSD_JObjClearFlags(Ground_801C3FA4(gobj, 5), JOBJ_HIDDEN); mpLib_80057BC0(4); gp->gv.corneria.x108 = 5; - break; + return; case 5: - break; + return; } } +#undef grCn_803E1D38 + void grCorneria_801E1878(Ground_GObj* gobj) { Ground* gr = GET_GROUND(gobj); - HSD_JObj* jobj = GET_JOBJ(gobj); - HSD_JObj* target_jobj = GET_JOBJ(gr->gv.corneria.x128); - Vec3 pos; + HSD_JObj* jobj = gobj->hsd_obj; + HSD_JObj* tmp = gr->gv.corneria.x128->hsd_obj; + HSD_JObj* target_jobj = tmp; - HSD_JObjGetTranslation(jobj, &pos); - HSD_JObjSetTranslate(target_jobj, &pos); + /// @remarks Splitting the pad around a scoped @c pos places the vector + /// at sp+0x18 as in the target; a function-scope @c pos with a single + /// PAD_STACK(16) leaves it at sp+0x24 (six reg-save/load instructions + /// arg-mismatch, 99.90%). + PAD_STACK(8); + { + Vec3 pos; + HSD_JObjGetTranslation(jobj, &pos); + HSD_JObjSetTranslate(target_jobj, &pos); + } + PAD_STACK(8); Ground_801C39C0(); Ground_801C3BB4(); @@ -2531,34 +2598,40 @@ s32 grCorneria_801E2598(u32 arg0, u32 arg1) return val != 0; } +#define grCn_803E1D38 (*(grCn_Data*) grCn_803E1D38) + void grCorneria_801E25C4(HSD_GObj* gobj, void* gv, int line, int arg3, int arg4) { struct grSmashTaunt_GroundVars* v = gv; - int i; - s16 joint0; s16 joint1; + s16 joint0; + int i; + s16* joints; PAD_STACK(8); v->line = line; v->sis_data_idx = arg3; v->sound_id = arg4; - joint0 = grCn_803E21F0[v->line][0]; - joint1 = grCn_803E21F0[v->line][1]; - for (i = 0; i < 5; i++) { + joint0 = grCn_803E1D38.dialog_joints[v->line].joint0; + joint1 = grCn_803E1D38.dialog_joints[v->line].joint1; + joints = &grCn_803E1D38.dialog_joints[i = 0].joint0; + do { if (i != 0 && v->line != i) { - HSD_JObj* j0 = Ground_801C3FA4(gobj, grCn_803E21F0[i][0]); + HSD_JObj* j0 = Ground_801C3FA4(gobj, joints[0]); if (j0 != NULL) { HSD_JObjSetFlagsAll(j0, JOBJ_HIDDEN); } { - HSD_JObj* j1 = Ground_801C3FA4(gobj, grCn_803E21F0[i][1]); + HSD_JObj* j1 = Ground_801C3FA4(gobj, joints[1]); if (j1 != NULL) { HSD_JObjSetFlagsAll(j1, JOBJ_HIDDEN); } } } - } + i++; + joints += 2; + } while (i < 5); v->jobj0 = Ground_801C3FA4(gobj, joint0); v->jobj1 = Ground_801C3FA4(gobj, joint1); v->jobj2 = Ground_801C3FA4(gobj, 5); @@ -2567,12 +2640,14 @@ void grCorneria_801E25C4(HSD_GObj* gobj, void* gv, int line, int arg3, v->joint_idx2 = 5; v->state = 0; v->timer = 0xA; - grAnime_801C8098(gobj, joint0, 7, 0, 0.0f, 1.0f); grAnime_801C8098(gobj, joint1, 7, 0, 0.0f, 1.0f); + grAnime_801C8098(gobj, joint0, 7, 0, 0.0f, 1.0f); grAnime_801C8098(gobj, 5, 7, 0, 0.0f, 1.0f); - HSD_JObjAnimAll(GET_JOBJ(gobj)); + HSD_JObjAnimAll(gobj->hsd_obj); } +#undef grCn_803E1D38 + void grCorneria_801E2738(HSD_GObj* gobj, void* ptr, u32 idx1, u32 idx2) { grCorneria_801E25C4(gobj, ptr, grCn_803E2204[idx1][idx2].data[0], diff --git a/src/melee/gr/grflatzone.c b/src/melee/gr/grflatzone.c index 8de35c62ed..577ee148c3 100644 --- a/src/melee/gr/grflatzone.c +++ b/src/melee/gr/grflatzone.c @@ -350,7 +350,7 @@ void grFlatzone_802176BC(Ground_GObj* gobj) gp->gv.flatzone.xD4 = grFz_804D6AB0->unk20; if (gp->gv.flatzone2.xC8 == 1.0f) { pos.x = grFz_804D6AB0->unk24; - gp->gv.flatzone.xD4 = (s32) ((f32) gp->gv.flatzone.xD4 * 0.5f); + gp->gv.flatzone.xD4 = (s32) ((f32) gp->gv.flatzone.xD4 / 2.0f); } else { pos.x = grFz_804D6AB0->unk28; { @@ -562,25 +562,21 @@ static s16 grFz_803E7A68[] = { 0x0000, 0x0001, 0x0002, 0xFFFF, 0xFFFF, 0x0003, void grFlatzone_802174EC(Ground_GObj* gobj) { s16 row_entry; - s16 anim_timer; Ground* gp = GET_GROUND(gobj); if (((u8) gp->gv.pad_0[0] == 0) && ((u8) gp->gv.pad_0[3] != 8) && ((u8) gp->gv.pad_0[5] != 0)) { - anim_timer = gp->gv.flatzone.xCC; - gp->gv.flatzone.xCC = anim_timer - 1; - if (anim_timer < 0) { - s16* tbl = grFz_803E7A68; + if (gp->gv.flatzone.xCC-- < 0) { gp->gv.pad_0[6] = gp->gv.pad_0[5]; while (1) { - s32 next_anim = HSD_Randi(4) + 1; + u32 next_anim = HSD_Randi(4) + 1; gp->gv.pad_0[5] = next_anim; if ((u8) gp->gv.pad_0[6] == (u8) next_anim) { continue; } - row_entry = - tbl[(u8) gp->gv.pad_0[3] * 10 + (u8) gp->gv.pad_0[5]]; + row_entry = ((s16(*)[5]) grFz_803E7A68) + [(u8) gp->gv.pad_0[3]][(u8) gp->gv.pad_0[5]]; if (row_entry != -1) { break; } @@ -655,11 +651,14 @@ void grFlatzone_80217EF0(Ground_GObj* gobj) } if ((s32) gp->gv.unk.xC8 > 0) { if ((gp->gv.unk.xC8 % grFz_804D6AB0->unk14) == 0) { - f32 spawn_x; Vec3 pos; - spawn_left = grFz_804D6AB0->unk1C; - spawn_x = HSD_Randf() * (f32) (grFz_804D6AB0->unk18 - spawn_left); - pos.x = spawn_x - (f32) -spawn_left; + { + f32 spawn_x = HSD_Randf(); + spawn_left = grFz_804D6AB0->unk1C; + spawn_x *= (f32) (grFz_804D6AB0->unk18 - spawn_left); + spawn_x -= (f32) -spawn_left; + pos.x = spawn_x; + } pos.y = Stage_GetBlastZoneTopOffset() - 5.0f; pos.z = 0.0f; item_kind = HSD_Randi(5); @@ -691,7 +690,6 @@ void grFlatzone_8021805C(Ground_GObj* gobj) void grFlatzone_80218060(s32 arg0) { - s16* tbl = grFz_803E7A68; HSD_GObj* gobj; Ground* gp; PAD_STACK(8); @@ -713,20 +711,22 @@ void grFlatzone_80218060(s32 arg0) if (v == (u8) gp->gv.pad_0[4]) { goto loop_4; } - } while (tbl[v * 5 + 1] == -1); + } while (((s16(*)[5]) grFz_803E7A68)[v][1] == -1); do { { s32 randi = HSD_Randi(4); v = randi + 1; } - } while (tbl[gp->gv.flatzone.xC7 * 5 + - (u8) (gp->gv.pad_0[5] = v)] == -1); + } while (((s16(*)[5]) grFz_803E7A68)[gp->gv.flatzone.xC7] + [(u8) (gp->gv.pad_0[5] = + v)] == -1); } gp->gv.pad_0[6] = 0; gp->gv.flatzone.xCC = (s16) rand_int(grFz_804D6AB0->unkC, grFz_804D6AB0->unk8); gp->gv.flatzone.xC5 = - (u8) tbl[gp->gv.flatzone.xC7 * 5 + (u8) gp->gv.pad_0[5]]; + (u8) ((s16(*)[5]) grFz_803E7A68)[gp->gv.flatzone.xC7] + [(u8) gp->gv.pad_0[5]]; grAnime_801C8138(gobj, gp->map_id, (s32) gp->gv.flatzone.xC5); } } diff --git a/src/melee/gr/grfourside.c b/src/melee/gr/grfourside.c index 44938e0ab0..ddc62dd535 100644 --- a/src/melee/gr/grfourside.c +++ b/src/melee/gr/grfourside.c @@ -270,28 +270,26 @@ bool grFourside_801F326C(Ground_GObj* arg) return false; } -/// #grFourside_801F3274 -void grFourside_801F3274(Ground_GObj* gobj) +static inline void grFourside_UpdateCrane(Ground* gp, HSD_GObj* hsd_gobj) { - Ground* gp = GET_GROUND(gobj); - HSD_JObj* jobj = gobj->hsd_obj; - HSD_JObj* crane_iron = Ground_801C3FA4(gobj, 4); float fVar1; + s32 rand_max2; + s32 rand_max; float temp_fVar1; - PAD_STACK(0x1C); + PAD_STACK(0x14); // Ground_801C2ED0(jobj,gp->map_id); // grAnime_801C7FF8(gobj,0,7,0,0.0f,0.0f); switch (gp->gv.foursideCrane.x0) { case 0: if (gp->gv.foursideCrane.x4 <= 0) { if (gp->gv.foursideCrane.x1.b0 == 0u) { - grAnime_801C7B24(gobj, 0, 7, 0.0f); - grAnime_801C7A04(gobj, 0, 7, 1.0f); + grAnime_801C7B24(hsd_gobj, 0, 7, 0.0f); + grAnime_801C7A04(hsd_gobj, 0, 7, 1.0f); gp->gv.foursideCrane.x4 = 0; gp->gv.foursideCrane.x0 = 1; } else { - grAnime_801C7B24(gobj, 0, 7, 400.0f); - grAnime_801C7A04(gobj, 0, 7, 1.0f); + grAnime_801C7B24(hsd_gobj, 0, 7, 400.0f); + grAnime_801C7A04(hsd_gobj, 0, 7, 1.0f); gp->gv.foursideCrane.x4 = 0; gp->gv.foursideCrane.x0 = 2; } @@ -301,7 +299,7 @@ void grFourside_801F3274(Ground_GObj* gobj) break; case 1: if (gp->gv.foursideCrane.x4 >= 300) { - grAnime_801C7A04(gobj, 0, 7, 0.0); + grAnime_801C7A04(hsd_gobj, 0, 7, 0.0); gp->gv.foursideCrane.x1.b0 = 1; gp->gv.foursideCrane.x0 = 3; } else { @@ -310,7 +308,7 @@ void grFourside_801F3274(Ground_GObj* gobj) break; case 2: if (gp->gv.foursideCrane.x4 >= 300) { - grAnime_801C7A04(gobj, 0, 7, 0.0); + grAnime_801C7A04(hsd_gobj, 0, 7, 0.0); gp->gv.foursideCrane.x1.b0 = 0; gp->gv.foursideCrane.x0 = 3; } else { @@ -334,10 +332,15 @@ void grFourside_801F3274(Ground_GObj* gobj) if (fVar1 < 0.0f) { fVar1 = -fVar1; } + rand_max2 = (s32) fVar1; + rand_max = (s32) fVar1; + fVar1 = rand_max != 0 ? HSD_Randi(rand_max2) : 0; temp_fVar1 = grFs_804D69D8->crane_iron_down_min; + if (temp_fVar1 < 0.0f) { + temp_fVar1 = -temp_fVar1; + } gp->gv.foursideCrane.x10 = - gp->gv.foursideCrane.x10 - - (((s32) fVar1 != 0 ? HSD_Randi(fVar1) : 0) + temp_fVar1); + gp->gv.foursideCrane.x10 - (fVar1 + temp_fVar1); gp->gv.foursideCrane.x1.b1 = 1; OSReport("pos = %f : tgrpos = %f\n", gp->gv.foursideCrane.xC, gp->gv.foursideCrane.x10); @@ -348,10 +351,15 @@ void grFourside_801F3274(Ground_GObj* gobj) if (fVar1 < 0.0f) { fVar1 = -fVar1; } - temp_fVar1 = grFs_804D69D8->crane_iron_down_min; + rand_max2 = (s32) fVar1; + rand_max = (s32) fVar1; + fVar1 = rand_max != 0 ? HSD_Randi(rand_max2) : 0; + temp_fVar1 = grFs_804D69D8->crane_iron_up_min; + if (temp_fVar1 < 0.0f) { + temp_fVar1 = -temp_fVar1; + } gp->gv.foursideCrane.x10 = - gp->gv.foursideCrane.x10 + - ((s32) fVar1 != 0 ? HSD_Randi(fVar1) : 0) + temp_fVar1; + gp->gv.foursideCrane.x10 + (fVar1 + temp_fVar1); gp->gv.foursideCrane.x1.b1 = 0; OSReport("pos = %f : tgrpos = %f\n", gp->gv.foursideCrane.xC, gp->gv.foursideCrane.x10); @@ -383,13 +391,13 @@ void grFourside_801F3274(Ground_GObj* gobj) } break; case 7: - fVar1 = gp->gv.foursideCrane.x1C; - if (fVar1 < 0.0f) { - temp_fVar1 = -fVar1; + temp_fVar1 = gp->gv.foursideCrane.x1C; + if (temp_fVar1 < 0.0f) { + fVar1 = -temp_fVar1; } else { - temp_fVar1 = fVar1; + fVar1 = temp_fVar1; } - if (temp_fVar1 > gp->gv.foursideCrane.x14) { + if (fVar1 > gp->gv.foursideCrane.x14) { gp->gv.foursideCrane.xC = gp->gv.foursideCrane.x10; gp->gv.foursideCrane.x4 = grFs_804D69D8->crane_wait + @@ -398,7 +406,7 @@ void grFourside_801F3274(Ground_GObj* gobj) : 0); gp->gv.foursideCrane.x0 = 0; } else { - gp->gv.foursideCrane.x18 += fVar1; + gp->gv.foursideCrane.x18 += temp_fVar1; gp->gv.foursideCrane.xC += gp->gv.foursideCrane.x18; if ((gp->gv.foursideCrane.x1C < 0.0f) && (gp->gv.foursideCrane.xC < gp->gv.foursideCrane.x10)) @@ -413,8 +421,32 @@ void grFourside_801F3274(Ground_GObj* gobj) } break; } - HSD_JObjSetTranslateY(crane_iron, gp->gv.foursideCrane.xC); - Ground_801C2FE0(gobj); +} + +static inline float grFourside_GetCraneY(Ground* gp) +{ + return gp->gv.foursideCrane.xC; +} + +static inline HSD_JObj* grFourside_GetCraneIron(HSD_GObj* gobj) +{ + return Ground_801C3FA4(gobj, 4); +} + +/// #grFourside_801F3274 +void grFourside_801F3274(Ground_GObj* gobj) +{ + Ground* gp = GET_GROUND(gobj); + HSD_GObj* hsd_gobj = gobj; + HSD_JObj* crane_iron = grFourside_GetCraneIron(hsd_gobj); + float fVar1; + float temp_fVar1; + s32 rand_max; + s32 rand_max2; + + grFourside_UpdateCrane(gp, hsd_gobj); + HSD_JObjSetTranslateY(crane_iron, grFourside_GetCraneY(gp)); + Ground_801C2FE0(hsd_gobj); } void grFourside_801F37F8(Ground_GObj* arg) {} diff --git a/src/melee/gr/grgreens.c b/src/melee/gr/grgreens.c index e698e9c8b3..1d4657bc54 100644 --- a/src/melee/gr/grgreens.c +++ b/src/melee/gr/grgreens.c @@ -34,6 +34,10 @@ #include #define Gr_Greens_Block_Status_None 0 +/// "Colum" (sic): the retail assert strings at 0x803E7908/0x803E7924 spell +/// "ixgv.greens.x4[i * 6 + j]; + return &((Vec(*)[6]) gp->gv.greens.x4)[i][j]; } void grGreens_80213458(bool arg) @@ -438,12 +434,24 @@ bool fn_80213B1C(Ground_GObj* ground_gobj, Fighter_GObj* fighter_gobj, return false; } +static inline int get_whispy_dir(Ground_GObj* gobj, Vec3* pos) +{ + HSD_JObj* jobj = gobj->hsd_obj; + HSD_JObjGetTranslation(jobj, pos); + return ftLib_800864A8(pos, NULL) == 1.0f ? 1 : 0; +} + void grGreens_80213C10(Ground_GObj* gobj) { Ground_GObj* bg_gobj = Ground_801C2BA4(4); Ground* gp = GET_GROUND(gobj); Ground* bg_gp = GET_GROUND(bg_gobj); - PAD_STACK(0x50); + UNUSED u8 pad0[0x18]; + Vec3 apple_pos; + Vec3 pos; + UNUSED u32 pad1; + Vec3 pos2; + PAD_STACK(0xC); gp->gv.greens2.x18 = 0; if (grGr_804D6AAC != 0) { @@ -492,7 +500,6 @@ void grGreens_80213C10(Ground_GObj* gobj) case 1: if (gp->gv.greens2.x10 != 0) { HSD_JObj* jobj; - Vec3 pos; int dir; gp->gv.greens2.x10 = 0; @@ -595,33 +602,13 @@ void grGreens_80213C10(Ground_GObj* gobj) Camera_80030E44(1, NULL); gp->gv.greens2.x18 = gp->gv.greens2.x14 + 1; if (grAnime_801C84A4(gobj, 0, 7) != 0) { - int wind_done; - HSD_JObj* jobj; - int new_dir; int wind_dir; gp->gv.greens2.xC++; - wind_done = 0; - if ((float) gp->gv.greens2.xC > grGr_params->x54) { - return; - } - - if ((float) gp->gv.greens2.xC > grGr_params->x58) { - Vec3 pos; - - jobj = gobj->hsd_obj; - HSD_JObjGetTranslation(jobj, &pos); - if (ftLib_800864A8(&pos, NULL) == 1.0f) { - new_dir = 1; - } else { - new_dir = 0; - } - if (gp->gv.greens2.x14 != new_dir) { - wind_done = 1; - } - } - - if (wind_done) { + if ((float) gp->gv.greens2.xC > grGr_params->x54 || + ((float) gp->gv.greens2.xC > grGr_params->x58 && + gp->gv.greens2.x14 != get_whispy_dir(gobj, &pos2))) + { gp->gv.greens2.x8++; gp->gv.greens2.xC = 0; grAnime_801C8138( @@ -693,20 +680,20 @@ void grGreens_80213C10(Ground_GObj* gobj) ((gp->gv.greens2.xC - grGr_params->x64) % grGr_params->x68) == 0) { - Vec3 pos; float rand; float sign; float diff; rand = HSD_Randf(); sign = gp->gv.greens2.x24 == 0 ? -1.0f : 1.0f; - pos.x = sign * (40.0f * rand); + apple_pos.x = sign * (40.0f * rand); rand = HSD_Randf(); diff = grGr_params->x70 - grGr_params->x6C; - pos.y = (diff * rand) + grGr_params->x6C; - pos.z = -40.0f; + apple_pos.y = (diff * rand) + grGr_params->x6C; + apple_pos.z = -40.0f; lbAudioAx_800237A8(0x68FB3, 0x7F, 0x40); - it_802EE200(gobj, &pos, grGr_params->x74, grGr_params->x78); + it_802EE200(gobj, &apple_pos, grGr_params->x74, + grGr_params->x78); gp->gv.greens2.x20--; gp->gv.greens2.x24 = (gp->gv.greens2.x24 + 1) & 1; } @@ -717,6 +704,24 @@ void grGreens_80213C10(Ground_GObj* gobj) } } +/* These tables live at 0x803E7840/0x803E787C, after grGreens_80213C10's + * switch jumptable (0x803E7824): MWCC emits .data in definition/creation + * order, so they are defined after that function on purpose. */ + +/// JObj indices of the 30 breakable blocks (passed to Ground_801C3FA4). +static s16 grGr_blockJObjIds[Gr_Greens_Block_Max] = { + 5, 6, 7, 8, 9, 0xA, 0xB, 0xC, 0xD, 0xE, + 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, + 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, +}; + +/// Map joint IDs of the 30 breakable blocks (passed to mpJointSetCb2). +static s16 grGr_blockMapJointIds[Gr_Greens_Block_Max] = { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 0xA, 0xB, 0xC, 0xD, 0xE, 0xF, 0x10, 0x11, 0x12, 0x13, + 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, +}; + void grGreens_80214654(Ground_GObj* arg) { return; @@ -782,7 +787,6 @@ void grGreens_80214804(Ground_GObj* gobj) void grGreens_8021483C(Ground_GObj* gobj) { - Ground* gp = GET_GROUND(gobj); Vec vec; float left_max = -3.4028235e38f; float left_min = 3.4028235e38f; @@ -792,11 +796,13 @@ void grGreens_8021483C(Ground_GObj* gobj) float right_top = -3.4028235e38f; float right_min = 3.4028235e38f; float right_bottom = 3.4028235e38f; + Ground* gp = GET_GROUND(gobj); int i; float y; + PAD_STACK(4); for (i = 0; i < 30; i++) { - HSD_JObj* jobj = Ground_801C3FA4(gobj, grGr_803E7840[i]); + HSD_JObj* jobj = Ground_801C3FA4(gobj, grGr_blockJObjIds[i]); HSD_ASSERT(1014, jobj); lb_8000B1CC(jobj, NULL, &vec); @@ -828,33 +834,48 @@ void grGreens_8021483C(Ground_GObj* gobj) } } } - left_max = (left_max - left_min) * 0.5f; - for (i = 0; i < 5; i++) { - y = ((left_top - left_bottom) * 0.25f * i) + left_bottom; - - getVec(gp, i, 0)->x = (left_max * 0.0) + left_min; - getVec(gp, i, 0)->y = y; - getVec(gp, i, 0)->z = 0.0f; - getVec(gp, i, 1)->x = (left_max * 1.0f) + left_min; - getVec(gp, i, 1)->y = y; - getVec(gp, i, 1)->z = 0.0f; - getVec(gp, i, 2)->x = (left_max * 2.0f) + left_min; - getVec(gp, i, 2)->y = y; - getVec(gp, i, 2)->z = 0.0f; - } - right_max = (right_max - right_min) * 0.5f; - for (i = 0; i < 5; i++) { - y = ((right_top - right_bottom) * 0.25f * i) + right_bottom; - - getVec(gp, i, 3)->x = (right_max * 0.0f) + right_min; - getVec(gp, i, 3)->y = y; - getVec(gp, i, 3)->z = 0.0f; - getVec(gp, i, 4)->x = (right_max * 1.0f) + right_min; - getVec(gp, i, 4)->y = y; - getVec(gp, i, 4)->z = 0.0f; - getVec(gp, i, 5)->x = (right_max * 2.0f) + right_min; - getVec(gp, i, 5)->y = y; - getVec(gp, i, 5)->z = 0.0f; + { + float x0; + float x1; + float x2; + + x0 = 0.0f; + x1 = 1.0f; + x2 = 2.0f; + left_max = (left_max - left_min) * 0.5f; + for (i = 0; i < 5; i++) { + y = ((left_top - left_bottom) * 0.25f * i) + left_bottom; + + ((Vec(*)[6]) gp->gv.greens.x4)[i][0].x = + (left_max * x0) + left_min; + ((Vec(*)[6]) gp->gv.greens.x4)[i][0].y = y; + ((Vec(*)[6]) gp->gv.greens.x4)[i][0].z = 0.0f; + ((Vec(*)[6]) gp->gv.greens.x4)[i][1].x = + (left_max * x1) + left_min; + ((Vec(*)[6]) gp->gv.greens.x4)[i][1].y = y; + ((Vec(*)[6]) gp->gv.greens.x4)[i][1].z = 0.0f; + ((Vec(*)[6]) gp->gv.greens.x4)[i][2].x = + (left_max * x2) + left_min; + ((Vec(*)[6]) gp->gv.greens.x4)[i][2].y = y; + ((Vec(*)[6]) gp->gv.greens.x4)[i][2].z = 0.0f; + } + right_max = (right_max - right_min) * 0.5f; + for (i = 0; i < 5; i++) { + y = ((right_top - right_bottom) * 0.25f * i) + right_bottom; + + ((Vec(*)[6]) gp->gv.greens.x4)[i][3].x = + (right_max * x0) + right_min; + ((Vec(*)[6]) gp->gv.greens.x4)[i][3].y = y; + ((Vec(*)[6]) gp->gv.greens.x4)[i][3].z = 0.0f; + ((Vec(*)[6]) gp->gv.greens.x4)[i][4].x = + (right_max * x1) + right_min; + ((Vec(*)[6]) gp->gv.greens.x4)[i][4].y = y; + ((Vec(*)[6]) gp->gv.greens.x4)[i][4].z = 0.0f; + ((Vec(*)[6]) gp->gv.greens.x4)[i][5].x = + (right_max * x2) + right_min; + ((Vec(*)[6]) gp->gv.greens.x4)[i][5].y = y; + ((Vec(*)[6]) gp->gv.greens.x4)[i][5].z = 0.0f; + } } } @@ -907,10 +928,10 @@ void grGreens_80214FA8(Ground_GObj* gobj) Ground* gp = GET_GROUND(gobj); for (i = 0; i < 30; i++) { - mpJointSetCb2(grGr_803E787C[i], gp, fn_80216DE4); + mpJointSetCb2(grGr_blockMapJointIds[i], gp, fn_80216DE4); } for (j = 0; j < 30; j++) { - HSD_JObj* jobj = Ground_801C3FA4(gobj, grGr_803E7840[j]); + HSD_JObj* jobj = Ground_801C3FA4(gobj, grGr_blockJObjIds[j]); if (jobj != NULL) { HSD_JObjSetFlags(jobj, JOBJ_HIDDEN); } else { @@ -931,50 +952,63 @@ void grGreens_80214FA8(Ground_GObj* gobj) void grGreens_802150C4(Ground_GObj* gobj, int arg1, int arg2) { - Ground* gp = GET_GROUND(gobj); - - if (arg2 > 0 && arg1 > 0 && getBlock(gp, arg2 - 1, arg1 - 1)->status == 3) - { - if (getBlock(gp, arg2 - 1, arg1)->status == 3) { - mpLib_800581DC(getBlock(gp, arg2 - 1, arg1 - 1)->x18, - getBlock(gp, arg2 - 1, arg1)->x18); - } else if (getBlock(gp, arg2, arg1 - 1)->status == 3) { - mpLib_800581DC(getBlock(gp, arg2 - 1, arg1 - 1)->x18, - getBlock(gp, arg2, arg1 - 1)->x18); + struct grGreens_BlockVars (*blocks)[6] = + (struct grGreens_BlockVars(*)[6]) GET_GROUND(gobj)->gv.greens.x8_blocks; +#define BLOCK(i, j) blocks[i][j] + + if (arg2 > 0 && arg1 > 0 && BLOCK(arg2 - 1, arg1 - 1).status == 3) { + if (BLOCK(arg2 - 1, arg1).status == 3) { + mpLib_800581DC(BLOCK(arg2 - 1, arg1 - 1).x18, + BLOCK(arg2 - 1, arg1).x18); + } else if (BLOCK(arg2, arg1 - 1).status == 3) { + mpLib_800581DC(BLOCK(arg2 - 1, arg1 - 1).x18, + BLOCK(arg2, arg1 - 1).x18); } } - if (arg2 < 4 && arg1 > 0 && getBlock(gp, arg2 + 1, arg1 - 1)->status == 3) - { - if (getBlock(gp, arg2 + 1, arg1)->status == 3) { - mpLib_800581DC(getBlock(gp, arg2 + 1, arg1 - 1)->x18, - getBlock(gp, arg2 + 1, arg1)->x18); - } else if (getBlock(gp, arg2, arg1 - 1)->status == 3) { - mpLib_800581DC(getBlock(gp, arg2 + 1, arg1 - 1)->x18, - getBlock(gp, arg2, arg1 - 1)->x18); + if (arg2 < 4 && arg1 > 0 && BLOCK(arg2 + 1, arg1 - 1).status == 3) { + if (BLOCK(arg2 + 1, arg1).status == 3) { + mpLib_800581DC(BLOCK(arg2 + 1, arg1 - 1).x18, + BLOCK(arg2 + 1, arg1).x18); + } else if (BLOCK(arg2, arg1 - 1).status == 3) { + mpLib_800581DC(BLOCK(arg2 + 1, arg1 - 1).x18, + BLOCK(arg2, arg1 - 1).x18); } } - if (arg2 > 0 && arg1 < 5 && getBlock(gp, arg2 - 1, arg1 + 1)->status == 3) - { - if (getBlock(gp, arg2 - 1, arg1)->status == 3) { - mpLib_800581DC(getBlock(gp, arg2 - 1, arg1 + 1)->x18, - getBlock(gp, arg2 - 1, arg1)->x18); - } else if (getBlock(gp, arg2, arg1 + 1)->status == 3) { - mpLib_800581DC(getBlock(gp, arg2 - 1, arg1 + 1)->x18, - getBlock(gp, arg2, arg1 + 1)->x18); + if (arg2 > 0 && arg1 < 5 && BLOCK(arg2 - 1, arg1 + 1).status == 3) { + if (BLOCK(arg2 - 1, arg1).status == 3) { + mpLib_800581DC(BLOCK(arg2 - 1, arg1 + 1).x18, + BLOCK(arg2 - 1, arg1).x18); + } else if (BLOCK(arg2, arg1 + 1).status == 3) { + mpLib_800581DC(BLOCK(arg2 - 1, arg1 + 1).x18, + BLOCK(arg2, arg1 + 1).x18); } } - if (arg2 < 4 && arg1 < 5 && getBlock(gp, arg2 + 1, arg1 + 1)->status == 3) - { - if (getBlock(gp, arg2 + 1, arg1)->status == 3) { - mpLib_800581DC(getBlock(gp, arg2 + 1, arg1 + 1)->x18, - getBlock(gp, arg2 + 1, arg1)->x18); + if (arg2 < 4 && arg1 < 5 && BLOCK(arg2 + 1, arg1 + 1).status == 3) { + if (BLOCK(arg2 + 1, arg1).status == 3) { + mpLib_800581DC(BLOCK(arg2 + 1, arg1 + 1).x18, + BLOCK(arg2 + 1, arg1).x18); return; } - if (getBlock(gp, arg2, arg1 + 1)->status == 3) { - mpLib_800581DC(getBlock(gp, arg2 + 1, arg1 + 1)->x18, - getBlock(gp, arg2, arg1 + 1)->x18); + if (BLOCK(arg2, arg1 - 1).status == 3) { + mpLib_800581DC(BLOCK(arg2 + 1, arg1 + 1).x18, + BLOCK(arg2, arg1 + 1).x18); } } +#undef BLOCK +} + +static inline void get_block_material_params(int block_type, float* duration, + float* scale) +{ + int value; + + if (block_type == 2) { + value = grGr_params->x28; + } else { + value = grGr_params->x24; + } + *duration = value * Ground_801C0498(); + *scale = 5.0f * Ground_801C0498(); } void grGreens_80215358(Ground_GObj* gobj, int col, int row, int arg3, int arg4) @@ -984,18 +1018,17 @@ void grGreens_80215358(Ground_GObj* gobj, int col, int row, int arg3, int arg4) unsigned char arr[30]; int m; int n; - int num; - int type; Ground_GObj* block_gobj; - HSD_JObj* jobj; Item_GObj* item_gobj; - int x24_or_x28; + HSD_JObj* jobj; + int type; + int num; float grMaterial_801C8DE0_paramA; float grMaterial_801C8DE0_paramB; Vec vec; float f; PAD_STACK(0x10); - HSD_ASSERT(1305, block->status == Gr_Greens_Block_Status_None); + HSD_ASSERT(1305, block->status==Gr_Greens_Block_Status_None); for (n = 0; n < 30; n++) { arr[n] = 0; } @@ -1011,7 +1044,7 @@ void grGreens_80215358(Ground_GObj* gobj, int col, int row, int arg3, int arg4) break; } } - HSD_ASSERT(1316, num < Gr_Greens_Block_Max); + HSD_ASSERT(1316, numx28; - } else { - x24_or_x28 = grGr_params->x24; - } - grMaterial_801C8DE0_paramB = x24_or_x28 * Ground_801C0498(); - grMaterial_801C8DE0_paramA = 5.0f * Ground_801C0498(); + get_block_material_params(arg3, &grMaterial_801C8DE0_paramB, + &grMaterial_801C8DE0_paramA); grMaterial_801C8DE0(item_gobj, 0.0f, grMaterial_801C8DE0_paramA, 0.0f, 0.0f, grMaterial_801C8DE0_paramA, 0.0f, grMaterial_801C8DE0_paramB); @@ -1048,7 +1076,7 @@ void grGreens_80215358(Ground_GObj* gobj, int col, int row, int arg3, int arg4) block->xC = block_gobj; block->x10 = item_gobj; block->x14 = jobj; - block->x18 = Ground_801C32D4(6, grGr_803E7840[num]); + block->x18 = Ground_801C32D4(6, grGr_blockJObjIds[num]); block->x1C = 0; block->x1_4 = 0; block->x1_7 = 0; @@ -1077,26 +1105,28 @@ void fn_802159B4(Item_GObj* item_gobj, Ground* gp) void grGreens_802159B8(Ground* gp, int i, int j, int value) { - HSD_GObj* gobj = getBlock(gp, j, i)->x10; + HSD_GObj* gobj = gp->gv.greens.x8_blocks[j * 6 + i].x10; Vec vec; float f; + UNUSED u8 pad[0x10]; - if (gobj != NULL && !getBlock(gp, j, i)->x1_7) { - getBlock(gp, j, i)->x1_7 = 1; + if (gobj != NULL && !gp->gv.greens.x8_blocks[j * 6 + i].x1_7) { + gp->gv.greens.x8_blocks[j * 6 + i].x1_7 = 1; grMaterial_801C8E28(gobj); - getBlock(gp, j, i)->x1C = value; + gp->gv.greens.x8_blocks[j * 6 + i].x1C = value; - if (getBlock(gp, j, i)->x1_1) { - HSD_JObjSetFlagsAll(getBlock(gp, j, i)->xC->hsd_obj, JOBJ_HIDDEN); + if (gp->gv.greens.x8_blocks[j * 6 + i].x1_1) { + HSD_JObjSetFlagsAll(gp->gv.greens.x8_blocks[j * 6 + i].xC->hsd_obj, + JOBJ_HIDDEN); grMaterial_801C8D98(gobj, 1); it_80275414(gobj); - getBlock(gp, j, i)->x1_2 = 1; + gp->gv.greens.x8_blocks[j * 6 + i].x1_2 = 1; HSD_JObjGetTranslation(gobj->hsd_obj, &vec); vec.y += 5.0f * Ground_801C0498(); efSync_Spawn(1039, gobj, &vec); } else { f = 0.0f; - getBlock(gp, j, i)->x1_3 = 1; + gp->gv.greens.x8_blocks[j * 6 + i].x1_3 = 1; Camera_80030E44(2, NULL); HSD_JObjGetTranslation(gobj->hsd_obj, &vec); vec.y += 5.0f * Ground_801C0498(); @@ -1106,14 +1136,11 @@ void grGreens_802159B8(Ground* gp, int i, int j, int value) } } -void fn_80215B84(Item_GObj* item_gobj, Ground* gp, Vec* arg2, HSD_GObj* gobj, - float arg4) +static inline bool find_block(Ground* gp, Item_GObj* item_gobj, int* row, + int* col) { int i; int j; - int row = -1; - int col = 0; - u8 operand_pad[4]; for (i = 0; i < 5; i++) { for (j = 0; j < 6; j++) { @@ -1122,15 +1149,27 @@ void fn_80215B84(Item_GObj* item_gobj, Ground* gp, Vec* arg2, HSD_GObj* gobj, if (block->status != Gr_Greens_Block_Status_None && block->x10 == item_gobj) { - row = i; - col = j; - i = 5; - break; + *row = i; + *col = j; + return true; } } } - HSD_ASSERT(1465, row != -1); - grGreens_802159B8(gp, col, row, (s32) gobj); + return false; +} + +void fn_80215B84(Item_GObj* item_gobj, Ground* gp, Vec* arg2, HSD_GObj* gobj, + float arg4) +{ + Ground* ground = gp; + int col = -1; + int row; + HSD_GObj* hit = gobj; + + if (!find_block(ground, item_gobj, &row, &col)) { + HSD_ASSERT(1465, 0); + } + grGreens_802159B8(ground, col, row, (s32) hit); } void fn_80215D50(Item_GObj* item_gobj, Ground* gp, HSD_GObj* gobj) @@ -1138,24 +1177,27 @@ void fn_80215D50(Item_GObj* item_gobj, Ground* gp, HSD_GObj* gobj) return; } +#define BLOCK(gp, i, j) \ + (((struct grGreens_BlockVars(*)[6])(gp)->gv.greens.x8_blocks)[i][j]) + s32 grGreens_80215D54(Ground_GObj* gobj, int arg1, int arg2) { Ground* gp = GET_GROUND(gobj); int row; for (row = 1; row < 5; row++) { - if ((getBlock(gp, row, arg1)->status == 1 || - getBlock(gp, row, arg1)->status == 2) && - getBlock(gp, row - 1, arg1)->status == 0) + if ((BLOCK(gp, row, arg1).status == 1 || + BLOCK(gp, row, arg1).status == 2) && + BLOCK(gp, row - 1, arg1).status == 0) { int r; for (r = row; r < 5; r++) { - struct grGreens_BlockVars temp = *getBlock(gp, r, arg1); - *getBlock(gp, r, arg1) = *getBlock(gp, r - 1, arg1); - *getBlock(gp, r - 1, arg1) = temp; + struct grGreens_BlockVars temp = BLOCK(gp, r, arg1); + BLOCK(gp, r, arg1) = *(&BLOCK(gp, r, arg1) - 6); + *(&BLOCK(gp, r, arg1) - 6) = temp; } - if (getBlock(gp, row - 1, arg1)->status == 2) { - getBlock(gp, row - 1, arg1)->status |= 0x10; + if (BLOCK(gp, row - 1, arg1).status == 2) { + BLOCK(gp, row - 1, arg1).status = 1; } row = 0; } @@ -1163,126 +1205,142 @@ s32 grGreens_80215D54(Ground_GObj* gobj, int arg1, int arg2) return (s32) gobj; } +#undef BLOCK + void grGreens_80215ED8(Ground_GObj* gobj, int col, int row) { Ground* gp = GET_GROUND(gobj); - struct grGreens_BlockVars* block = getBlock(gp, row, col); Vec pos; float scale; - if (block->status == Gr_Greens_Block_Status_None || block->x1_3) { + if (getBlock(gp, row, col)->status == Gr_Greens_Block_Status_None) { + return; + } + if (getBlock(gp, row, col)->x1_3) { return; } - if (block->x1_2) { - if (grMaterial_801C8E48(block->x10) != 0) { - block->x1_3 = 1; + if (getBlock(gp, row, col)->x1_2) { + if (grMaterial_801C8E48(getBlock(gp, row, col)->x10) != 0) { + getBlock(gp, row, col)->x1_3 = 1; } return; } - switch (block->status) { + switch (getBlock(gp, row, col)->status) { case 2: return; case 1: - if (block->x1_4) { - block->x4 = 0.0f; - block->x1_4 = 0; + if (getBlock(gp, row, col)->x1_4) { + getBlock(gp, row, col)->x4 = 0.0f; + getBlock(gp, row, col)->x1_4 = 0; grGreens_802159B8(gp, col, row, 0); } else { - block->x4 += grGr_params->x30; - if (block->x4 > grGr_params->x2C) { - block->x4 = grGr_params->x2C; + getBlock(gp, row, col)->x4 += grGr_params->x30; + if (getBlock(gp, row, col)->x4 > grGr_params->x2C) { + getBlock(gp, row, col)->x4 = grGr_params->x2C; } - block->x8 -= block->x4; + getBlock(gp, row, col)->x8 -= getBlock(gp, row, col)->x4; if (row > 0) { struct grGreens_BlockVars* below = getBlock(gp, row - 1, col); if (below->status == 1 || below->status == 2) { - float spacing = - getVec(gp, row, col)->y - getVec(gp, row - 1, col)->y; + Vec* prev_pos = getVec(gp, row - 1, col); + float spacing = getVec(gp, row, col)->y - prev_pos->y; - if (block->x8 - below->x8 < spacing) { - block->status = 2; - block->x8 = spacing + below->x8; + if (getBlock(gp, row, col)->x8 - below->x8 < spacing) { + getBlock(gp, row, col)->status = 2; + getBlock(gp, row, col)->x8 = spacing + below->x8; } } } } - if (block->x8 < getVec(gp, row, col)->y) { + if (getBlock(gp, row, col)->x8 < getVec(gp, row, col)->y) { int next_row; - block->x8 = getVec(gp, row, col)->y; - block->status = 3; - block->x1_5 = 1; + { + struct grGreens_BlockVars* block = getBlock(gp, row, col); + block->x8 = getVec(gp, row, col)->y; + } + getBlock(gp, row, col)->status = 3; + getBlock(gp, row, col)->x1_5 = 1; for (next_row = row + 1; next_row < 5; next_row++) { - struct grGreens_BlockVars* next = getBlock(gp, next_row, col); - - if (next->status != 2) { + if (getBlock(gp, next_row, col)->status != 2) { break; } - next->x8 = getVec(gp, next_row, col)->y; - next->status = 3; - next->x1_5 = 1; + getBlock(gp, next_row, col)->x8 = getVec(gp, next_row, col)->y; + getBlock(gp, next_row, col)->status = 3; + getBlock(gp, next_row, col)->x1_5 = 1; pos.x = getVec(gp, next_row, col)->x; - pos.y = next->x8; + pos.y = getBlock(gp, next_row, col)->x8; pos.z = 0.0f; - HSD_JObjSetTranslate(next->xC->hsd_obj, &pos); + HSD_JObjSetTranslate(getBlock(gp, next_row, col)->xC->hsd_obj, + &pos); scale = 1.0f / Ground_801C0498(); pos.x *= scale; pos.y *= scale; pos.z *= scale; - HSD_JObjSetTranslate(next->x14, &pos); + HSD_JObjSetTranslate(getBlock(gp, next_row, col)->x14, &pos); } } else { int next_row; for (next_row = row + 1; next_row < 5; next_row++) { - struct grGreens_BlockVars* next = getBlock(gp, next_row, col); - - if (next->status != 2) { + if (getBlock(gp, next_row, col)->status != 2) { break; } - next->x8 = getVec(gp, next_row, col)->y - - getVec(gp, next_row - 1, col)->y + - getBlock(gp, next_row - 1, col)->x8; + { + struct grGreens_BlockVars* next = + getBlock(gp, next_row, col); + struct grGreens_BlockVars* prev = + getBlock(gp, next_row - 1, col); + float y = getVec(gp, next_row, col)->y; + next->x8 = + y - getVec(gp, next_row - 1, col)->y + prev->x8; + } pos.x = getVec(gp, next_row, col)->x; - pos.y = next->x8; + pos.y = getBlock(gp, next_row, col)->x8; pos.z = 0.0f; - HSD_JObjSetTranslate(next->xC->hsd_obj, &pos); + HSD_JObjSetTranslate(getBlock(gp, next_row, col)->xC->hsd_obj, + &pos); scale = 1.0f / Ground_801C0498(); pos.x *= scale; pos.y *= scale; pos.z *= scale; - HSD_JObjSetTranslate(next->x14, &pos); + HSD_JObjSetTranslate(getBlock(gp, next_row, col)->x14, &pos); } } break; } pos.x = getVec(gp, row, col)->x; - pos.y = block->x8; + pos.y = getBlock(gp, row, col)->x8; pos.z = 0.0f; - HSD_JObjSetTranslate(block->xC->hsd_obj, &pos); + HSD_JObjSetTranslate(getBlock(gp, row, col)->xC->hsd_obj, &pos); scale = 1.0f / Ground_801C0498(); pos.x *= scale; pos.y *= scale; pos.z *= scale; - HSD_JObjSetTranslate(block->x14, &pos); + HSD_JObjSetTranslate(getBlock(gp, row, col)->x14, &pos); } void grGreens_802166C4(Ground_GObj* gobj) { Ground* gp = GET_GROUND(gobj); - int row; + u8 weights[6]; int col; + int row; + int cleanup_row; + int cleanup_col; + PAD_STACK(8); if (gp->gv.greens.xC-- < 0) { - u8 weights[6]; - bool left_has_nonzero; - bool right_has_nonzero; - int choice = -1; + int ix = -1; + u8* weights_base = weights; + u8* wp = weights_base; + int left_has_zero = 0; + int right_has_zero = 0; for (col = 0; col < 6; col++) { weights[col] = grGr_params->x1C; @@ -1312,90 +1370,104 @@ void grGreens_802166C4(Ground_GObj* gobj) } } - left_has_nonzero = - weights[0] != 0 || weights[1] != 0 || weights[2] != 0; - right_has_nonzero = - weights[3] != 0 || weights[4] != 0 || weights[5] != 0; + for (row = 0; row < 3; row++, wp++) { + if (wp[0] == 0) { + left_has_zero = 1; + } + if (wp[3] == 0) { + right_has_zero = 1; + } + } - if (left_has_nonzero) { + wp = weights_base; + if (left_has_zero == 0) { int total; int pick; - if (right_has_nonzero) { - total = weights[0] + weights[1] + weights[2] + weights[3] + - weights[4] + weights[5]; + if (right_has_zero == 0) { + total = wp[0] + wp[1]; + total += wp[2]; + total += wp[3]; + total += wp[4]; + total += wp[5]; pick = total != 0 ? HSD_Randi(total) : 0; - choice = 0; - pick -= weights[0]; + ix = 0; + pick -= *wp; if (pick >= 0) { - choice = 1; - pick -= weights[1]; + ix = 1; + pick -= *++wp; if (pick >= 0) { - choice = 2; - pick -= weights[2]; + ix = 2; + pick -= *++wp; if (pick >= 0) { - choice = 3; - pick -= weights[3]; + ix = 3; + pick -= *++wp; if (pick >= 0) { - choice = 4; - pick -= weights[4]; + ix = 4; + pick -= *++wp; if (pick >= 0) { - choice = 5; - pick -= weights[5]; + ix = 5; + pick -= *++wp; if (pick >= 0) { - choice = 6; + ix = 6; } } } } } } - HSD_ASSERT(1693, choice < 6); + HSD_ASSERT(1693, ix= 0) { - choice = 1; - pick -= weights[1]; + ix = 1; + pick -= *++wp; if (pick >= 0) { - choice = 2; - pick -= weights[2]; + ix = 2; + pick -= *++wp; if (pick >= 0) { - choice = 3; + ix = 3; } } } - HSD_ASSERT(1702, choice < 3); + HSD_ASSERT(1702, ix= 0) { - choice = 4; - pick -= weights[4]; + wp = weights_base; + ix = 4; + pick -= *++wp; if (pick >= 0) { - choice = 5; - pick -= weights[5]; + ix = 5; + pick -= wp[1]; if (pick >= 0) { - choice = 6; + ix = 6; } } } - HSD_ASSERT(1711, choice < 6); + HSD_ASSERT(1711, ix 0) { - if (getBlock(gp, spawn_row - 1, choice)->status != + if (getBlock(gp, spawn_row - 1, ix)->status != Gr_Greens_Block_Status_None) { break; @@ -1404,66 +1476,125 @@ void grGreens_802166C4(Ground_GObj* gobj) } type_roll = grGr_params->x20 != 0 ? HSD_Randi(grGr_params->x20) : 0; - type = type_roll != 0 ? 1 : 2; - grGreens_80215358(gobj, choice, spawn_row, type, 1); + if (type_roll != 0) { + type = 1; + } else { + type = 2; + } + grGreens_80215358(gobj, ix, spawn_row, type, 1); } gp->gv.greens.xC = randrange(grGr_params->x0_blockTimerMin, grGr_params->x4_blockTimerMax); } - for (row = 0; row < 5; row++) { - for (col = 0; col < 6; col++) { - grGreens_80215ED8(gobj, col, row); + for (col = 0; col < 5; col++) { + for (row = 0; row < 6; row++) { + grGreens_80215ED8(gobj, row, col); } } -restart_cleanup: - for (row = 0; row < 5; row++) { - for (col = 0; col < 6; col++) { - struct grGreens_BlockVars* block = getBlock(gp, row, col); - - if (block->x1_3) { - block->x1_3 = 0; - block->x1_6 = 1; - block->status = Gr_Greens_Block_Status_None; - Ground_801C4A08(block->xC); - grMaterial_801C8CDC(block->x10); - HSD_JObjSetFlags(block->x14, JOBJ_HIDDEN); - grGreens_80215D54(gobj, col, row); - goto restart_cleanup; + for (cleanup_row = 0; cleanup_row < 5; cleanup_row++) { + for (cleanup_col = 0; cleanup_col < 6; cleanup_col++) { + if (((struct grGreens_BlockVars(*)[6]) + gp->gv.greens.x8_blocks)[cleanup_row][cleanup_col] + .x1_3) + { + ((struct grGreens_BlockVars(*)[6]) + gp->gv.greens.x8_blocks)[cleanup_row][cleanup_col] + .x1_3 = 0; + ((struct grGreens_BlockVars(*)[6]) + gp->gv.greens.x8_blocks)[cleanup_row][cleanup_col] + .x1_6 = 1; + ((struct grGreens_BlockVars(*)[6]) + gp->gv.greens.x8_blocks)[cleanup_row][cleanup_col] + .status = Gr_Greens_Block_Status_None; + Ground_801C4A08( + ((struct grGreens_BlockVars(*)[6]) + gp->gv.greens.x8_blocks)[cleanup_row][cleanup_col] + .xC); + grMaterial_801C8CDC( + ((struct grGreens_BlockVars(*)[6]) + gp->gv.greens.x8_blocks)[cleanup_row][cleanup_col] + .x10); + HSD_JObjSetFlags( + ((struct grGreens_BlockVars(*)[6]) + gp->gv.greens.x8_blocks)[cleanup_row][cleanup_col] + .x14, + JOBJ_HIDDEN); + grGreens_80215D54(gobj, cleanup_col, cleanup_row); + cleanup_row = -1; + cleanup_col = 6; } } } } +static inline int getBlockX18(Ground* gp, int i, int j) +{ + return getBlock(gp, i, j)->x18; +} + void grGreens_80216C20(Ground_GObj* gobj) { + int j; Ground* gp = GET_GROUND(gobj); int i; - int j; for (i = 0; i < 5; i++) { for (j = 0; j < 6; j++) { - struct grGreens_BlockVars* block = getBlock(gp, i, j); - - if (block->x1_6) { - if (i > 0 && getBlock(gp, i - 1, j)->status == 3) { - mpLib_800581DC(block->x18, getBlock(gp, i - 1, j)->x18); + if (((struct grGreens_BlockVars(*)[6]) + gp->gv.greens.x8_blocks)[i][j] + .x1_5) + { + Ground* gp2 = GET_GROUND(gobj); + int x18 = ((struct grGreens_BlockVars(*)[6]) + gp2->gv.greens.x8_blocks)[i][j] + .x18; + + if (i > 0 && ((struct grGreens_BlockVars(*)[6]) + gp2->gv.greens.x8_blocks)[i - 1][j] + .status == 3) + { + mpLib_800581DC(x18, ((struct grGreens_BlockVars(*)[6]) gp2 + ->gv.greens.x8_blocks)[i - 1][j] + .x18); } - if (j > 0 && getBlock(gp, i, j - 1)->status == 3) { - mpLib_800581DC(block->x18, getBlock(gp, i, j - 1)->x18); + if (j > 0 && ((struct grGreens_BlockVars(*)[6]) + gp2->gv.greens.x8_blocks)[i][j - 1] + .status == 3) + { + mpLib_800581DC(x18, ((struct grGreens_BlockVars(*)[6]) gp2 + ->gv.greens.x8_blocks)[i][j - 1] + .x18); } - if (i < 4 && getBlock(gp, i + 1, j)->status == 3) { - mpLib_800581DC(block->x18, getBlock(gp, i + 1, j)->x18); + if (i < 4 && ((struct grGreens_BlockVars(*)[6]) + gp2->gv.greens.x8_blocks)[i + 1][j] + .status == 3) + { + mpLib_800581DC(x18, ((struct grGreens_BlockVars(*)[6]) gp2 + ->gv.greens.x8_blocks)[i + 1][j] + .x18); } - if (j < 5 && getBlock(gp, i, j + 1)->status == 3) { - mpLib_800581DC(block->x18, getBlock(gp, i, j + 1)->x18); + if (j < 5 && ((struct grGreens_BlockVars(*)[6]) + gp2->gv.greens.x8_blocks)[i][j + 1] + .status == 3) + { + mpLib_800581DC(x18, ((struct grGreens_BlockVars(*)[6]) gp2 + ->gv.greens.x8_blocks)[i][j + 1] + .x18); } - block->x1_6 = 0; - } else if (block->x1_7) { + ((struct grGreens_BlockVars(*)[6]) + gp->gv.greens.x8_blocks)[i][j] + .x1_5 = 0; + } else if (((struct grGreens_BlockVars(*)[6]) + gp->gv.greens.x8_blocks)[i][j] + .x1_6) + { grGreens_802150C4(gobj, j, i); - block->x1_7 = 0; + ((struct grGreens_BlockVars(*)[6]) + gp->gv.greens.x8_blocks)[i][j] + .x1_6 = 0; } } } diff --git a/src/melee/gr/grhomerun.c b/src/melee/gr/grhomerun.c index f337dce449..a87da88389 100644 --- a/src/melee/gr/grhomerun.c +++ b/src/melee/gr/grhomerun.c @@ -217,43 +217,43 @@ void grHomeRun_8021CB20(Ground_GObj* gobj) }; Ground* gp = GET_GROUND(gobj); - grHomeRun_MainGroundVars* vars = - (grHomeRun_MainGroundVars*) &gp->gv.homerun; HSD_JObj* jobj = GET_JOBJ(gobj); + HSD_JObj* jobj2 = jobj; UnkArchiveStruct* archive; HSD_CObj* cobj; - s16 i; + s32 i; f32 gobjs_num; - HSD_GObj** gobjs; - HSD_GObj** jobjs; - PAD_STACK(24); + PAD_STACK(16); - Ground_801C2ED0(jobj, gp->map_id); + Ground_801C2ED0(jobj2, gp->map_id); - vars->gobjs = HSD_MemAlloc(0x100); - HSD_ASSERT(0x17A, vars->gobjs); - gobjs = vars->gobjs; + ((grHomeRun_MainGroundVars*) &gp->gv.homerun)->gobjs = HSD_MemAlloc(0x100); + HSD_ASSERT(0x17A, + ((grHomeRun_MainGroundVars*) &gp->gv.homerun)->gobjs); - vars->jobj_gobjs = HSD_MemAlloc(0x40); - HSD_ASSERT(0x17B, vars->jobj_gobjs); - jobjs = vars->jobj_gobjs; + ((grHomeRun_MainGroundVars*) &gp->gv.homerun)->jobj_gobjs = + HSD_MemAlloc(0x40); + HSD_ASSERT(0x17B, + ((grHomeRun_MainGroundVars*) &gp->gv.homerun)->jobj_gobjs); - HSD_JObjSetScaleX(jobj, grHr_804D6AE4 * HSD_JObjGetScaleX(jobj)); - HSD_JObjSetScaleY(jobj, grHr_804D6AE4 * HSD_JObjGetScaleY(jobj)); - HSD_JObjSetScaleZ(jobj, grHr_804D6AE4 * HSD_JObjGetScaleZ(jobj)); + HSD_JObjSetScaleX(jobj2, grHr_804D6AE4 * HSD_JObjGetScaleX(jobj)); + HSD_JObjSetScaleY(jobj2, grHr_804D6AE4 * HSD_JObjGetScaleY(jobj)); + HSD_JObjSetScaleZ(jobj2, grHr_804D6AE4 * HSD_JObjGetScaleZ(jobj)); *(u8*) &gp->x10_flags |= 4; grAnime_801C8138(gobj, gp->map_id, false); mpJointSetCb1(0, gp, (mpLib_Callback) fn_8021E994); archive = grDatFiles_801C6324(); - vars->xD4 = GObj_Create(0x11, 0x13, 0); + gp->gv.unk.xD4 = (intptr_t) GObj_Create(0x11, 0x13, 0); cobj = lb_80013B14(&cobj_desc); HSD_CObjSetPerspective(cobj, 30.0F, 1.4F); - HSD_GObjObject_80390A70(vars->xD4, HSD_GObj_804D784B, cobj); - GObj_SetupGXLinkMax(vars->xD4, (GObj_RenderFunc) (Event) fn_8021EB10, 7); - vars->xD4->gxlink_prios = 2; - HSD_SisLib_803A611C(1, vars->xD4, 9, 0xD, 0, 1, 0, 7); + HSD_GObjObject_80390A70((HSD_GObj*) gp->gv.unk.xD4, HSD_GObj_804D784B, + cobj); + GObj_SetupGXLinkMax((HSD_GObj*) gp->gv.unk.xD4, + (GObj_RenderFunc) (Event) fn_8021EB10, 7); + ((HSD_GObj*) gp->gv.unk.xD4)->gxlink_prios = 2; + HSD_SisLib_803A611C(1, (HSD_GObj*) gp->gv.unk.xD4, 9, 0xD, 0, 1, 0, 7); HSD_SisLib_804D1124[1] = HSD_ArchiveGetPublicAddress(archive->unk0, "SIS_GrHomerunData"); gobjs_num = 2.0F * (1.0F + (2400.0F / (160.0F * Ground_801C0498()))); @@ -261,17 +261,19 @@ void grHomeRun_8021CB20(Ground_GObj* gobj) for (i = 0; (f32) i < 1.0F + (2400.0F / (160.0F * Ground_801C0498())); i++) { - gobjs[i] = grHomeRun_8021E500(i); + ((grHomeRun_MainGroundVars*) &gp->gv.homerun)->gobjs[i] = + grHomeRun_8021E500(i); } for (; i < 64; i++) { - gobjs[i] = NULL; + ((grHomeRun_MainGroundVars*) &gp->gv.homerun)->gobjs[i] = NULL; } for (i = 0; i < 16; i++) { HSD_JObj* child; HSD_GObj* gobj; - jobjs[i] = grHomeRun_8021C82C_noinline(4); - gobj = jobjs[i]; + ((grHomeRun_MainGroundVars*) &gp->gv.homerun)->jobj_gobjs[i] = + grHomeRun_8021C82C_noinline(4); + gobj = ((grHomeRun_MainGroundVars*) &gp->gv.homerun)->jobj_gobjs[i]; HSD_ASSERT(0x1AB, gobj); jobj = GET_JOBJ(gobj); @@ -291,7 +293,7 @@ void grHomeRun_8021CB20(Ground_GObj* gobj) { HSD_GObj* rear_gobj = grHomeRun_8021C82C_noinline(3); HSD_ASSERT(0x1BA, rear_gobj); - vars->rear_gobj = rear_gobj; + ((grHomeRun_MainGroundVars*) &gp->gv.homerun)->rear_gobj = rear_gobj; jobj = GET_JOBJ(rear_gobj); HSD_ASSERT(0x1BB, jobj); } @@ -300,7 +302,7 @@ void grHomeRun_8021CB20(Ground_GObj* gobj) { HSD_GObj* rear2_gobj = grHomeRun_8021C82C_noinline(3); HSD_ASSERT(0x1BD, rear2_gobj); - vars->rear2_gobj = rear2_gobj; + ((grHomeRun_MainGroundVars*) &gp->gv.homerun)->rear2_gobj = rear2_gobj; jobj = GET_JOBJ(rear2_gobj); HSD_ASSERT(0x1BE, jobj); } @@ -310,7 +312,7 @@ void grHomeRun_8021CB20(Ground_GObj* gobj) { HSD_GObj* rear3_gobj = grHomeRun_8021C82C_noinline(3); HSD_ASSERT(0x1C0, rear3_gobj); - vars->rear3_gobj = rear3_gobj; + ((grHomeRun_MainGroundVars*) &gp->gv.homerun)->rear3_gobj = rear3_gobj; jobj = GET_JOBJ(rear3_gobj); HSD_ASSERT(0x1C1, jobj); } @@ -320,16 +322,17 @@ void grHomeRun_8021CB20(Ground_GObj* gobj) { HSD_GObj* rear4_gobj = grHomeRun_8021C82C_noinline(3); HSD_ASSERT(0x1C3, rear4_gobj); - vars->rear4_gobj = rear4_gobj; + ((grHomeRun_MainGroundVars*) &gp->gv.homerun)->rear4_gobj = rear4_gobj; jobj = GET_JOBJ(rear4_gobj); HSD_ASSERT(0x1C4, jobj); } HSD_JObjSetTranslateX(jobj, 1.5F * (2150.99F * Ground_801C0498())); - vars->xCC = NULL; - vars->xD0 = Ground_801C3FA4(gobj, 1); - vars->xE8_flags.b0 = 0; + ((grHomeRun_MainGroundVars*) &gp->gv.homerun)->xCC = NULL; + ((grHomeRun_MainGroundVars*) &gp->gv.homerun)->xD0 = + Ground_801C3FA4(gobj, 1); + ((grHomeRun_MainGroundVars*) &gp->gv.homerun)->xE8_flags.b0 = 0; } bool grHomeRun_8021D678(Ground_GObj* arg) @@ -339,6 +342,7 @@ bool grHomeRun_8021D678(Ground_GObj* arg) void grHomeRun_8021D680(Ground_GObj* gobj) { + Vec3 cam_interest; Vec3 pos0; CmSubject* subject; Ground* gp; @@ -357,7 +361,6 @@ void grHomeRun_8021D680(Ground_GObj* gobj) gp = GET_GROUND(gobj); gobj2 = Ground_801C57A4(); if (gobj2 != NULL) { - Vec3 cam_interest; ftLib_80086644(gobj2, &pos0); subject = ftLib_80086B74(gobj2); if (subject != NULL) { @@ -415,14 +418,11 @@ void grHomeRun_8021D680(Ground_GObj* gobj) x1 = (s32) (1.0F + ((2400.0F + cam_interest.x) / (160.0F * Ground_801C0498()))); - gp2 = GET_GROUND( - ((grHomeRun_MainGroundVars*) &gp->gv.homerun)->gobjs[0]); + gobj2 = + ((grHomeRun_MainGroundVars*) &gp->gv.homerun)->gobjs[0]; + gp2 = GET_GROUND(gobj2); if (gp2->gv.homerun.xC4 < x0) { - { - HSD_GObj* first_gobj = - ((grHomeRun_MainGroundVars*) &gp->gv.homerun)->gobjs[0]; - Ground_801C4A08(first_gobj); - } + Ground_801C4A08(gobj2); for (i = 0; i < 63; i++) { ((grHomeRun_MainGroundVars*) &gp->gv.homerun)->gobjs[i] = ((grHomeRun_MainGroundVars*) &gp->gv.homerun) @@ -772,6 +772,7 @@ void grHomeRun_8021E4FC(Ground_GObj* arg) {} HSD_GObj* grHomeRun_8021E500(s16 arg0) { + s32 arg = arg0; HSD_JObj* jobj; s32 gobj_id; HSD_GObj* gobj; @@ -780,27 +781,27 @@ HSD_GObj* grHomeRun_8021E500(s16 arg0) s32 idx; f32 offset; - idx = (arg0 / grHr_804D6ADC) % 4; + idx = (arg / grHr_804D6ADC) % 4; if (idx == 0) { - if (grHr_804D6ADC - 1 != arg0 % grHr_804D6ADC) { + if (grHr_804D6ADC - 1 != arg % grHr_804D6ADC) { gobj_id = 4; } else { gobj_id = 5; } } else if (idx == 1) { - if (grHr_804D6ADC - 1 != arg0 % grHr_804D6ADC) { + if (grHr_804D6ADC - 1 != arg % grHr_804D6ADC) { gobj_id = 1; } else { gobj_id = 2; } } else if (idx == 2) { - if (grHr_804D6ADC - 1 != arg0 % grHr_804D6ADC) { + if (grHr_804D6ADC - 1 != arg % grHr_804D6ADC) { gobj_id = 6; } else { gobj_id = 7; } } else if (idx == 3) { - if (grHr_804D6ADC - 1 != arg0 % grHr_804D6ADC) { + if (grHr_804D6ADC - 1 != arg % grHr_804D6ADC) { gobj_id = 8; } else { gobj_id = 9; @@ -824,14 +825,14 @@ HSD_GObj* grHomeRun_8021E500(s16 arg0) child = HSD_JObjGetChild(jobj); HSD_JObjSetTranslateX(child, 0.0F); - offset = grHr_804D6AE4 * ((f32) arg0 * (160.0F * Ground_801C0498())); + offset = grHr_804D6AE4 * ((f32) arg * (160.0F * Ground_801C0498())); gp->gv.homerun.xD0 = (160.0F * (grHr_804D6AE4 * Ground_801C0498())) + offset; HSD_JObjSetTranslateX(jobj, gp->gv.homerun.xD0); gp->gv.homerun.xC6 = - (s16) ((s32) grHr_804D6AE0 * ((arg0 + 1) / grHr_804D6ADC)); - gp->gv.homerun.xC4 = arg0; + (s16) ((s32) grHr_804D6AE0 * ((arg + 1) / grHr_804D6ADC)); + gp->gv.homerun.xC4 = arg; return gobj; } diff --git a/src/melee/gr/gricemt.c b/src/melee/gr/gricemt.c index 8c42647458..ab2df38a49 100644 --- a/src/melee/gr/gricemt.c +++ b/src/melee/gr/gricemt.c @@ -1155,48 +1155,46 @@ void grIceMt_801F8CDC(Ground_GObj* gobj, s16* joint_indices, int block_num, s32 fn_801F8E58(Ground_GObj* arg0, s32* out) { s32 list[12]; - s32 max; + typedef struct IceMtTimerCursor { + s16 pad[0x6E]; + s16 xDC; + } IceMtTimerCursor; + s32 a; + IceMtTimerCursor* timer; + s32* p; s32 i; - s32 pick; + s32 max; s32 chosen; - Ground* gp; - s16 a; - s16 b; + IceMtTimerCursor* timer_base; + s32 b; s32 d; - max = 0; - gp = arg0->user_data; - - { - Ground* g = gp; - s32* p = &list[max]; - for (i = 0; i < 12; i++) { - if (g->gv.icemt.xDC == 0 && (Stage_80225194() != 0xD4 || i >= 4)) { - *p = i; - p++; - max++; - } - g = (Ground*) ((u8*) g + 2); + p = &list[max = 0]; + timer = arg0->user_data; + timer_base = timer; + for (i = 0; i < 12; i++) { + if (timer->xDC == 0 && (Stage_80225194() != 0xD4 || i >= 4)) { + *p = i; + p++; + max++; } + timer = (IceMtTimerCursor*) ((s16*) timer + 1); } HSD_ASSERT(0x81D, max); - pick = max != 0 ? HSD_Randi(max) : 0; - chosen = list[pick]; + chosen = list[max != 0 ? HSD_Randi(max) : 0]; - { - Ground* g = gp; - for (i = 0; i < 12; i++) { - if (g->gv.icemt.xDC > 0) { - g->gv.icemt.xDC--; - } - g = (Ground*) ((u8*) g + 2); + timer = timer_base; + for (i = 0; i < 12; i++) { + if (timer->xDC > 0) { + timer->xDC--; } + timer = (IceMtTimerCursor*) ((s16*) timer + 1); } - (&gp->gv.icemt.xDC)[chosen] = *(s16*) ((u8*) grIm_804D69F4 + 2); - a = *(s16*) ((u8*) grIm_804D69F4 + 0x36); - b = *(s16*) ((u8*) grIm_804D69F4 + 0x38); + (&timer_base->xDC)[chosen] = ((s16*) grIm_804D69F4)[1]; + a = ((s16*) grIm_804D69F4)[0x36 / 2]; + b = ((s16*) grIm_804D69F4)[0x38 / 2]; if (a > b) { d = a - b; a = b + (d != 0 ? HSD_Randi(d) : 0); @@ -1772,12 +1770,17 @@ int grIceMt_801FA500(HSD_GObj* arg0, HSD_JObj* arg1) } else if (HSD_JObjGetNext(jobj) != NULL) { jobj = HSD_JObjGetNext(jobj); } else { - while (HSD_JObjGetParent(jobj) != NULL && - HSD_JObjGetNext(HSD_JObjGetParent(jobj)) == NULL) - { + while (true) { + if (HSD_JObjGetParent(jobj) == NULL) { + jobj = NULL; + break; + } + if (HSD_JObjGetNext(HSD_JObjGetParent(jobj)) != NULL) { + jobj = HSD_JObjGetNext(HSD_JObjGetParent(jobj)); + break; + } jobj = HSD_JObjGetParent(jobj); } - jobj = HSD_JObjGetNext(HSD_JObjGetParent(jobj)); } count++; } diff --git a/src/melee/gr/grinishie1.c b/src/melee/gr/grinishie1.c index 15d7e59944..6be67d23dc 100644 --- a/src/melee/gr/grinishie1.c +++ b/src/melee/gr/grinishie1.c @@ -16,6 +16,7 @@ #include "gr/grzakogenerator.h" #include "gr/inlines.h" #include "gr/stage.h" +#include "gr/types.h" #include "it/inlines.h" #include "it/it_266F.h" #include "it/it_26B1.h" @@ -35,8 +36,27 @@ #include +static void sdata2_order(void) +{ + (void) 1.0f; + (void) 4000.0f; + (void) 0.0f; + (void) -1.0f; + (void) 6.0f; + (void) 1.20000005f; + (void) 5.0; + (void) -1.20000005f; + (void) 0.0; + (void) 15.0f; + (void) 5.0f; + (void) 0.69999999999999996; + (void) 100000.0f; + (void) -30.0f; + (void) S32_TO_F32; +} + #define invalid_state(line) \ - OSReport("%s:%d: oioi..\n", "i!=HATENA_APPEAR_CHECKLOOP", line); \ + OSReport("%s:%d: oioi..\n", "grinishie1.c", line); \ while (true) { \ } @@ -62,12 +82,11 @@ static inline s32 randi_between_f32(f32 min_f, f32 max_f) s32 max = max_f; if (max > min) { - return min + test_random(max - min); - } else if (min > max) { - return max + test_random(min - max); - } else { - return min; + max = min + test_random(max - min); + } else if (max < min) { + max += test_random(min - max); } + return max; } static inline f32 fabsf_inline(f32 x) @@ -84,6 +103,9 @@ static inline f32 fclamp0(f32 x) return ret; } +#define INISHIE1_XC6(gp) ((s16*) &(gp)->gv.inishie1.xC4)[1] +#define INISHIE1_XC8(gp) ((s16*) &(gp)->gv.inishie1.xC4)[2] + typedef struct { f32 unk0; f32 unk4; @@ -93,8 +115,9 @@ typedef struct { s16 unk14; s16 unk16; u16 unk18; - u16 unk1A; - u32 unk1C; + s16 unk1A; + s16 unk1C; + s16 unk1E; f32 unk20; f32 unk24; f32 unk28; @@ -106,7 +129,9 @@ typedef struct { } grInishie1_stuff; grInishie1_stuff* grI1_804D69F8; -Vec3 grI1_803B8268; + +/// initial velocity for items spawned from hatena blocks +const Vec3 grInishie1_HatenaItemSpawnVel = { 0.0f, 5.0f, 0.0f }; #define DOBJ_LOOP(jobj) \ { \ @@ -198,7 +223,7 @@ struct block_table_struct { s16 jobj_idx; }; -struct block_table_struct block_idx_table[BLOCK_COUNT]; +extern struct block_table_struct block_idx_table[BLOCK_COUNT]; void grInishie1_801FA90C(void) { @@ -260,6 +285,13 @@ HSD_GObj* grInishie1_801FA9B4(s32 arg0) return gobj; } +struct block_table_struct block_idx_table[BLOCK_COUNT] = { + { 13, 3 }, { 14, 14 }, { 15, 15 }, { 16, 16 }, { 17, 17 }, + { 18, 18 }, { 19, 19 }, { 11, 20 }, { 12, 21 }, { 1, 4 }, + { 2, 5 }, { 3, 6 }, { 4, 7 }, { 5, 8 }, { 6, 9 }, + { 7, 10 }, { 8, 11 }, { 9, 12 }, { 10, 13 }, +}; + void grInishie1_801FAAA0(Ground_GObj* gobj) { Ground* gp = GET_GROUND(gobj); @@ -337,20 +369,18 @@ bool grInishie1_801FAC50(Ground_GObj* gobj) void grInishie1_801FAC58(Ground_GObj* gobj) { + Ground* gp = GET_GROUND(gobj); + HSD_JObj* jobj = GET_JOBJ(gobj); + HSD_JObj* jobj2 = jobj; Vec3 vec; - Ground* gp; - HSD_JObj* jobj; - - jobj = GET_JOBJ(gobj); - gp = GET_GROUND(gobj); - if (gp && jobj) { + if (gp && jobj2) { if (gp->gv.inishie12.xCC == 0) { if (gp->gv.inishie12.xC8 > 0) { if (gp->gv.inishie12.xC8 & 1) { - HSD_JObjClearFlagsAll(jobj, JOBJ_HIDDEN); + HSD_JObjClearFlagsAll(jobj2, JOBJ_HIDDEN); } else { - HSD_JObjSetFlagsAll(jobj, JOBJ_HIDDEN); + HSD_JObjSetFlagsAll(jobj2, JOBJ_HIDDEN); } gp->gv.inishie12.xC8 -= 1; } @@ -358,7 +388,7 @@ void grInishie1_801FAC58(Ground_GObj* gobj) if (gp->gv.inishie12.xC4 != NULL) { lb_8000B1CC(gp->gv.inishie12.xC4, NULL, &vec); - HSD_JObjSetTranslate(jobj, &vec); + HSD_JObjSetTranslate(jobj2, &vec); } } } @@ -367,27 +397,62 @@ void grInishie1_801FAD80(Ground_GObj* gobj) {} void grInishie1_801FAD84(HSD_GObj* gobj) { - Ground* gp = gobj->user_data; - struct grInishie1_GroundVars* vars = &gp->gv.inishie1; + /// @todo same layout as #grInishie1_801FB3F0_Vars; the shared + /// grInishie1_GroundVars/grInishie1_Block structs are likely wrong + /// (xC4 should be u16, block x4 is s16 and x10 is an f32) + typedef struct grInishie1_InitBlock { + s16 status; + s16 x2; + s16 x4; + s16 x6; + f32 x8; + f32 xC; + f32 x10; + HSD_JObj* jobj; + HSD_GObj* hatena_gobj; + Item_GObj* item_gobj; + s16 x20; + s16 x22; + } grInishie1_InitBlock; + typedef struct grInishie1_InitGround { + u8 pad[0xC4]; + u16 xC4; + s16 xC6; + s16 xC8; + s16 xCA; + s16 xCC; + s16 xCE; + s32 xD0; + s32 xD4; + s32 xD8; + grInishie1_InitBlock* blocks; + } grInishie1_InitGround; + HSD_JObj* jobj; + struct block_table_struct* block_table; + u32 j; int i; + s32 value; + grInishie1_InitGround* gp = gobj->user_data; + PAD_STACK(8); - vars->blocks = (grInishie1_Block*) HSD_MemAlloc(sizeof(grInishie1_Block) * - BLOCK_COUNT); + gp->blocks = (grInishie1_InitBlock*) HSD_MemAlloc( + sizeof(grInishie1_InitBlock) * BLOCK_COUNT); - i = 0; - while (i < BLOCK_COUNT) { - s16 value; - int j; - HSD_JObj* jobj; + block_table = block_idx_table; - if (i < 0 || i > BLOCK_COUNT) { + i = 0; + while ((u32) i < BLOCK_COUNT) { + if (i < 0 || (u32) i >= BLOCK_COUNT) { invalid_state(0x1F9); } - value = block_idx_table[i].idx; + { + s16 check = block_table[i].idx; + value = check; - for (j = 0; j < BLOCK_COUNT; j++) { - if (value == block_idx_table[j].idx) { - break; + for (j = 0; j < BLOCK_COUNT; j++) { + if (check == block_table[j].idx) { + break; + } } } @@ -400,23 +465,21 @@ void grInishie1_801FAD84(HSD_GObj* gobj) invalid_state(0x21D); } - vars->blocks[i].x2 = 2; - vars->blocks[i].x4 = 0; - vars->blocks[i].jobj2 = jobj; - vars->blocks[i].hatena_gobj = NULL; - vars->blocks[i].x8 = HSD_JObjGetTranslationY(jobj); - vars->blocks[i].xC = 0.0f; - vars->blocks[i].jobj = jobj; - mpJointSetCb2((s32) value, gp, (mpLib_Callback) fn_801FBEB8); - vars->blocks[i].status = 0; + gp->blocks[i].x2 = 2; + gp->blocks[i].x4 = 0; + gp->blocks[i].jobj = jobj; + gp->blocks[i].hatena_gobj = NULL; + gp->blocks[i].x8 = HSD_JObjGetTranslationY(jobj); + gp->blocks[i].xC = 0.0f; + gp->blocks[i].x10 = 0.0f; + mpJointSetCb2(value, (Ground*) gp, (mpLib_Callback) fn_801FBEB8); + gp->blocks[i].status = 0; i++; } - for (i = 0; i < BLOCK_COUNT; i++) { - grInishie1_Block* slot = &vars->blocks[i]; - - HSD_GObj* new_gobj = - grMaterial_801C8CFC(8, 0, gp, slot->jobj, NULL, fn_801FBF6C, NULL); + for (i = 0; (u32) i < BLOCK_COUNT; i++) { + HSD_GObj* new_gobj = grMaterial_801C8CFC( + 8, 0, (Ground*) gp, gp->blocks[i].jobj, NULL, fn_801FBF6C, NULL); if (new_gobj != NULL) { grMaterial_801C8DE0(new_gobj, 0.0f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f, @@ -425,13 +488,11 @@ void grInishie1_801FAD84(HSD_GObj* gobj) grMaterial_801C8E68(new_gobj, 0); } - slot->item_gobj = new_gobj; + gp->blocks[i].item_gobj = new_gobj; } if (gm_8016AE80() != -1 && gm_8016B238() == 0) { int item_kind = It_Common_Start; - // maybe it_8026D324 returns how many of x item there is or - // how many have spawned? do { if (it_8026D324(item_kind) != 0) { break; @@ -440,39 +501,30 @@ void grInishie1_801FAD84(HSD_GObj* gobj) } while (item_kind < It_Common_End); if (item_kind != It_Common_End) { - grInishie1_Block* slot1; - grInishie1_Block* slot2; - s16 index1 = HSD_Randi(BLOCK_COUNT); - s16 index2; + s32 index1 = HSD_Randi(BLOCK_COUNT); + s32 index2; + s32 index1_copy = index1; + s32 index2_copy; do { index2 = HSD_Randi(BLOCK_COUNT); - } while (index2 == index1); - - slot1 = &vars->blocks[index1]; - slot2 = &vars->blocks[index2]; + } while (index1 == (index2_copy = index2)); - slot1->status = 1; - grInishie1_801FBAA0(gobj, index1); - if (slot1->hatena_gobj != NULL) { - Ground* hatena_gp = GET_GROUND(slot1->hatena_gobj); - hatena_gp->gv.inishie12.xCC = 1; - } + gp->blocks[index1].status = 1; + grInishie1_801FBAA0(gobj, index1_copy); + GET_GROUND(gp->blocks[index1].hatena_gobj)->gv.inishie12.xCC = 1; - slot2->status = 2; - grInishie1_801FBAA0(gobj, index2); - if (slot2->hatena_gobj != NULL) { - Ground* hatena_gp = GET_GROUND(slot2->hatena_gobj); - hatena_gp->gv.inishie12.xCC = 1; - } + gp->blocks[index2].status = 2; + grInishie1_801FBAA0(gobj, index2_copy); + GET_GROUND(gp->blocks[index2].hatena_gobj)->gv.inishie12.xCC = 1; } } - vars->xC6 = 0; - vars->xC8 = 0; - vars->xCA = -1; - vars->xCC = -1; - vars->xD8 = 0; + gp->xC6 = 0; + gp->xC8 = 0; + gp->xCA = -1; + gp->xCC = -1; + gp->xD8 = 0; } void grInishie1_801FB0AC(HSD_GObj* gobj, u32 index) @@ -483,14 +535,14 @@ void grInishie1_801FB0AC(HSD_GObj* gobj, u32 index) gp->gv.inishie1.blocks[index].status = 0; grInishie1_801FBC4C(gobj, index); - gp->gv.inishie1.xC6 = + INISHIE1_XC6(gp) = randi_between_f32(grI1_804D69F8->unk0, grI1_804D69F8->unk4); } else if (gp->gv.inishie1.blocks[index].status == 2) { grInishie1_801FBA34(gobj, gp->gv.inishie1.blocks[index].jobj2); gp->gv.inishie1.blocks[index].status = 0; grInishie1_801FBC4C(gobj, index); - gp->gv.inishie1.xC8 = + INISHIE1_XC8(gp) = randi_between_f32(grI1_804D69F8->unk8, grI1_804D69F8->unkC); } else if (gp->gv.inishie1.blocks[index].status == 3) { grInishie1_801FBA34(gobj, gp->gv.inishie1.blocks[index].jobj2); @@ -505,10 +557,10 @@ void grInishie1_801FB0AC(HSD_GObj* gobj, u32 index) } } if (i == 0x13) { - gp->gv.inishie1.xC6 = randi_between_f32(grI1_804D69F8->unk0, - grI1_804D69F8->unk4); - gp->gv.inishie1.xC8 = randi_between_f32(grI1_804D69F8->unk8, - grI1_804D69F8->unkC); + INISHIE1_XC6(gp) = randi_between_f32(grI1_804D69F8->unk0, + grI1_804D69F8->unk4); + INISHIE1_XC8(gp) = randi_between_f32(grI1_804D69F8->unk8, + grI1_804D69F8->unkC); } } @@ -520,118 +572,115 @@ void grInishie1_801FB0AC(HSD_GObj* gobj, u32 index) } } +enum { + HATENA_APPEAR_CHECKLOOP = 0x14 +}; + #define HATENA_APPEAR_CHECKLOOP(countdown, last_index, status_val, line) \ if (countdown > 0) { \ countdown--; \ if (countdown == 0) { \ - int attempts = 0; \ + int i = 0; \ s32 index; \ \ do { \ index = HSD_Randi(0x13); \ - if (index != last_index && \ - gp->gv.inishie1.blocks[index].status == 0) \ - { \ + if (index != last_index && vars->blocks[index].x0 == 0) { \ break; \ } \ - attempts++; \ - } while (attempts < 0x14); \ + i++; \ + } while (i < HATENA_APPEAR_CHECKLOOP); \ \ - if (attempts == 0x14) { \ - HSD_ASSERTMSG(line, false, "%s:%d: oioi..\n"); \ - } \ + HSD_ASSERT(line, i!=HATENA_APPEAR_CHECKLOOP); \ \ last_index = index; \ - gp->gv.inishie1.blocks[index].status = status_val; \ + vars->blocks[index].x0 = status_val; \ grInishie1_801FBAA0(gobj, index); \ - gp->gv.inishie1.blocks[index].x20 = 0; \ + vars->blocks[index].x20 = 0; \ } \ } -void grInishie1_801FB3F0(HSD_GObj* gobj) +typedef struct grInishie1_801FB3F0_Block { + s16 x0; + s16 x2; + s16 x4; + s16 x6; + f32 x8; + f32 xC; + f32 x10; + HSD_JObj* jobj; + HSD_GObj* hatena_gobj; + Item_GObj* item_gobj; + s16 x20; + s16 x22; +} grInishie1_801FB3F0_Block; + +typedef struct grInishie1_801FB3F0_Vars { + u8 pad0[0xC6]; + s16 xC6; + s16 xC8; + s16 xCA; + s16 xCC; + u8 padCE[0xD8 - 0xCE]; + s32 xD8; + grInishie1_801FB3F0_Block* blocks; +} grInishie1_801FB3F0_Vars; + +static inline void +grInishie1_801FB3F0_update_blocks(HSD_GObj* gobj, + grInishie1_801FB3F0_Vars* vars, Vec3* pos) { - Ground* gp = gobj->user_data; u32 i; - PAD_STACK(64); - - if (gp->gv.inishie1.xD8 > 0) { - gp->gv.inishie1.xD8--; - } - - if (gp->gv.inishie1.xD8 == 0 && - ((gp->gv.inishie1.xC6 == 1 && gp->gv.inishie1.xC8 > 0 && - gp->gv.inishie1.xC8 < grI1_804D69F8->unk14) || - (gp->gv.inishie1.xC8 == 1 && gp->gv.inishie1.xC6 > 0 && - gp->gv.inishie1.xC6 < grI1_804D69F8->unk14))) - { - gp->gv.inishie1.xC8 = 0; - gp->gv.inishie1.xC6 = 0; - - // this is likely the rare case mentioned on smashwiki - // where every block will become a hatena block - for (i = 0; i < 0x13; ++i) { - gp->gv.inishie1.blocks[i].status = 3; - grInishie1_801FBAA0(gobj, i); - gp->gv.inishie1.blocks[i].x20 = 0; - } - } else { - HATENA_APPEAR_CHECKLOOP(gp->gv.inishie1.xC6, gp->gv.inishie1.xCA, 1, - 0x2D0U); - HATENA_APPEAR_CHECKLOOP(gp->gv.inishie1.xC8, gp->gv.inishie1.xCC, 2, - 0x2EBU); - } for (i = 0; i < 0x13; ++i) { - grInishie1_Block* slot = &gp->gv.inishie1.blocks[i]; - - switch (slot->status) { + switch (vars->blocks[i].x2) { case 2: - if (slot->x4 > 0) { - slot->x4--; + if (vars->blocks[i].x4 != 0) { + vars->blocks[i].x4--; } break; case 3: - slot->xC = 1.2f; + vars->blocks[i].x10 = 1.2f; grInishie1_801FB0AC(gobj, i); - slot->status = 4; + vars->blocks[i].x2 = 4; // fallthrough case 4: - slot->x8 += slot->xC; - - if (slot->x8 > 5.0f) { - slot->xC = -1.2f; - } else if (slot->x8 < 0.0) { - slot->x8 = 0.0f; - slot->status = 2; - slot->x4 = 10; + vars->blocks[i].xC += vars->blocks[i].x10; + + if (vars->blocks[i].xC > 5.0) { + vars->blocks[i].x10 = -1.2f; + } else if (vars->blocks[i].xC < 0.0) { + vars->blocks[i].xC = 0.0f; + vars->blocks[i].x2 = 2; + vars->blocks[i].x4 = 10; } // the blocks appear to not move at all, so not // sure what this is - if (slot->jobj != NULL) { - HSD_JObjSetTranslateY(slot->jobj, slot->x8); + { + f32 y = vars->blocks[i].x8 + vars->blocks[i].xC; + HSD_JObjSetTranslateY(vars->blocks[i].jobj, y); } break; case 0: - if (slot->x20 > 0) { - slot->x20--; + if (vars->blocks[i].x20 != 0) { + vars->blocks[i].x20--; } else { - Vec3 pos; - lb_8000B1CC(slot->jobj, NULL, &pos); - if (!grLib_801C9EE8(&pos, 15.0f)) { - DOBJ_LOOP(slot->jobj); - HSD_JObjClearFlagsAll(slot->jobj, JOBJ_HIDDEN); - grMaterial_801C8E08(slot->item_gobj); - slot->status = 1; - slot->x22 = grI1_804D69F8->unk18; + lb_8000B1CC(vars->blocks[i].jobj, NULL, pos); + if (!grLib_801C9EE8(pos, 15.0f)) { + DOBJ_CLEAR_LOOP(vars->blocks[i].jobj); + HSD_JObjClearFlagsAll(vars->blocks[i].jobj, JOBJ_HIDDEN); + grMaterial_801C8E08(vars->blocks[i].item_gobj); + vars->blocks[i].x2 = 1; + vars->blocks[i].x22 = grI1_804D69F8->unk18; } } - if (slot->hatena_gobj != NULL) { - HSD_JObj* sub_jobj = slot->hatena_gobj->hsd_obj; + if (vars->blocks[i].hatena_gobj != NULL) { + HSD_JObj* sub_jobj = vars->blocks[i].hatena_gobj->hsd_obj; if (!(HSD_JObjGetFlags(sub_jobj) & 0x10)) { HSD_JObjSetFlagsAll(sub_jobj, JOBJ_HIDDEN); } @@ -641,36 +690,70 @@ void grInishie1_801FB3F0(HSD_GObj* gobj) /* probably sets the flickering for blocks when they spawn */ - if (slot->x22 > 0) { - HSD_JObjGetDObj(slot->jobj); - if (slot->hatena_gobj != NULL) { - HSD_JObj* target = slot->hatena_gobj->hsd_obj; + if (vars->blocks[i].x22 > 0) { + HSD_JObjGetDObj(vars->blocks[i].jobj); + if (vars->blocks[i].hatena_gobj != NULL) { + HSD_JObj* target = vars->blocks[i].hatena_gobj->hsd_obj; - if (slot->x22 & 1) { + if (vars->blocks[i].x22 & 1) { HSD_JObjClearFlagsAll(target, JOBJ_HIDDEN); } else { HSD_JObjSetFlagsAll(target, JOBJ_HIDDEN); } - DOBJ_LOOP(slot->jobj); + DOBJ_CLEAR_LOOP(vars->blocks[i].jobj); } else { - if (slot->x22 & 1) { - DOBJ_LOOP(slot->jobj); + if (vars->blocks[i].x22 & 1) { + DOBJ_CLEAR_LOOP(vars->blocks[i].jobj); } else { - DOBJ_LOOP(slot->jobj); + DOBJ_LOOP(vars->blocks[i].jobj); } } - slot->x22--; + vars->blocks[i].x22--; } else { - slot->status = 2; - slot->x4 = 0; + vars->blocks[i].x2 = 2; + vars->blocks[i].x4 = 0; } break; } } } +void grInishie1_801FB3F0(HSD_GObj* gobj) +{ + grInishie1_801FB3F0_Vars* vars = gobj->user_data; + u32 i; + Vec3 pos; + PAD_STACK(52); + + if (vars->xD8 > 0) { + vars->xD8--; + } + + if (vars->xD8 == 0 && ((vars->xC6 == 1 && vars->xC8 > 0 && + vars->xC8 < grI1_804D69F8->unk14) || + (vars->xC8 == 1 && vars->xC6 > 0 && + vars->xC6 < grI1_804D69F8->unk14))) + { + vars->xC8 = 0; + vars->xC6 = 0; + + // this is likely the rare case mentioned on smashwiki + // where every block will become a hatena block + for (i = 0; i < 0x13; ++i) { + vars->blocks[i].x0 = 3; + grInishie1_801FBAA0(gobj, i); + vars->blocks[i].x20 = 0; + } + } else { + HATENA_APPEAR_CHECKLOOP(vars->xC6, vars->xCA, 1, 0x2D0U); + HATENA_APPEAR_CHECKLOOP(vars->xC8, vars->xCC, 2, 0x2EBU); + } + + grInishie1_801FB3F0_update_blocks(gobj, vars, &pos); +} + /// gives item from hatena block upwards velocity, maybe handles spawning it as /// well void grInishie1_801FBA34(HSD_GObj* gobj, HSD_JObj* jobj) @@ -678,7 +761,7 @@ void grInishie1_801FBA34(HSD_GObj* gobj, HSD_JObj* jobj) Vec3 sp1C; Vec3 vec; lb_8000B1CC(jobj, NULL, &sp1C); - vec = grI1_803B8268; + vec = grInishie1_HatenaItemSpawnVel; sp1C.y += 5.0f; it_8026F7C8(&sp1C, &vec, 0); } @@ -688,33 +771,34 @@ void grInishie1_801FBAA0(HSD_GObj* gobj, s32 index) { HSD_JObj* hatena_jobj; Vec3 position; - Ground* hatena_gp; Ground* gp = gobj->user_data; - struct grInishie1_GroundVars* vars = &gp->gv.inishie1; - struct grInishie1_Block* slot = &vars->blocks[index]; - + Ground* hatena_gp; HSD_GObj* hatena = grInishie1_801FA9B4(2); - if (hatena == NULL) { - return; - } + PAD_STACK(8); - HSD_ASSERTMSG(0x39E, !slot->hatena_gobj, - "!mapgp->u.map.block[ix].hatena_gobj"); + if (hatena != NULL) { + hatena_gp = hatena->user_data; + HSD_ASSERTMSG( + 0x39E, !gp->gv.inishie1.blocks[index].hatena_gobj, + "!mapgp->u.map.block[ix].hatena_gobj"); - slot->hatena_gobj = hatena; + gp->gv.inishie1.blocks[index].hatena_gobj = hatena; - hatena_jobj = hatena->hsd_obj; - lb_8000B1CC(slot->jobj, NULL, &position); - HSD_JObjSetTranslate(hatena_jobj, &position); + hatena_jobj = hatena->hsd_obj; + lb_8000B1CC(gp->gv.inishie1.blocks[index].jobj2, NULL, &position); + HSD_JObjSetTranslate(hatena_jobj, &position); - hatena_gp = hatena->user_data; - hatena_gp->gv.inishie13.xC4 = slot->jobj; + hatena_gp->gv.inishie13.xC4 = + gp->gv.inishie1.blocks[index].jobj2; - if (slot->status == 0 || slot->status == 1) { - hatena_gp->gv.inishie13.xCC = 1; - } + if (gp->gv.inishie1.blocks[index].x2 == 0 || + gp->gv.inishie1.blocks[index].x2 == 1) + { + hatena_gp->gv.inishie13.xCC = 1; + } - DOBJ_LOOP(slot->jobj); + DOBJ_LOOP(gp->gv.inishie1.blocks[index].jobj2); + } } void grInishie1_801FBC4C(HSD_GObj* gobj, u32 index) @@ -726,36 +810,44 @@ void grInishie1_801FBC4C(HSD_GObj* gobj, u32 index) gp->gv.inishie1.blocks[index].hatena_gobj = NULL; } +static inline Ground* GET_GROUND2(HSD_GObj* gobj) +{ + return gobj->user_data; +} + void grInishie1_801FBCEC(HSD_GObj* gobj, u32 index) { - Ground* gp = gobj->user_data; + Ground* gp = GET_GROUND2(gobj); Vec3 effect_pos; - Vec3 item_spawn_offset; - gp->gv.inishie1.blocks[index].status = 0; + gp->gv.inishie1.blocks[index].x2 = 0; gp->gv.inishie1.blocks[index].x20 = randi_between(grI1_804D69F8->unk1A, grI1_804D69F8->unk1C); - HSD_DObjSetFlags(HSD_JObjGetDObj(gp->gv.inishie1.blocks[index].jobj), 1U); + HSD_DObjSetFlags(HSD_JObjGetDObj(gp->gv.inishie1.blocks[index].jobj2), 1U); grMaterial_801C8E28(gp->gv.inishie1.blocks[index].item_gobj); - if (gp->gv.inishie1.blocks[index].status == 1 || - gp->gv.inishie1.blocks[index].status == 2 || - gp->gv.inishie1.blocks[index].status == 3) { - Ground_801C4A08(gp->gv.inishie1.blocks[index].hatena_gobj); - gp->gv.inishie1.blocks[index].hatena_gobj = NULL; + s16 status = gp->gv.inishie1.blocks[index].status; + if (status == 1 || (u16) (status - 2) <= 1U) { + Vec3 item_spawn_offset; + Vec3 item_vel; + + Ground_801C4A08(gp->gv.inishie1.blocks[index].hatena_gobj); + gp->gv.inishie1.blocks[index].hatena_gobj = NULL; - lb_8000B1CC(gp->gv.inishie1.blocks[index].jobj, NULL, - &item_spawn_offset); + lb_8000B1CC(gp->gv.inishie1.blocks[index].jobj2, NULL, + &item_spawn_offset); - item_spawn_offset.y += 5.0; + item_vel = grInishie1_HatenaItemSpawnVel; + item_spawn_offset.y += 5.0f; - it_8026F7C8(&item_spawn_offset, &grI1_803B8268, 0); + it_8026F7C8(&item_spawn_offset, &item_vel, 0); + } } - HSD_JObjSetFlagsAll(gp->gv.inishie1.blocks[index].jobj, JOBJ_HIDDEN); + HSD_JObjSetFlagsAll(gp->gv.inishie1.blocks[index].jobj2, JOBJ_HIDDEN); it_8026B294(gp->gv.inishie1.blocks[index].item_gobj, &effect_pos); @@ -837,11 +929,19 @@ void grInishie1_801FC110(HSD_GObj* gobj) gp->gv.inishie1.xE0 = 100000.0f; } - dist_lo = fclamp0(gp->gv.inishie1.xE0 - grI1_804D69F8->unk2C[1].y); - dist_hi = fclamp0(gp->gv.inishie1.xE4 - grI1_804D69F8->unk2C[1].y); + dist_lo = gp->gv.inishie1.xE0 - grI1_804D69F8->unk2C[1].y; + if (dist_lo < 0.0f) { + dist_lo = 0.0f; + } + dist_hi = gp->gv.inishie1.xE4 - grI1_804D69F8->unk2C[1].y; + if (dist_hi < 0.0f) { + dist_hi = 0.0f; + } if (dist_lo == 0.0f && dist_hi == 0.0f) { - if (fabsf_inline(gp->gv.inishie1.xF0) > 0.0f) { + if ((gp->gv.inishie1.xF0 < 0.0f ? -gp->gv.inishie1.xF0 + : gp->gv.inishie1.xF0) > 0.0f) + { if (gp->gv.inishie1.xF0 < 0.0f) { gp->gv.inishie1.xF0 += grI1_804D69F8->unk2C[1].x; if (gp->gv.inishie1.xF0 > 0.0f) { @@ -858,19 +958,16 @@ void grInishie1_801FC110(HSD_GObj* gobj) gp->gv.inishie1.xF4 = 0.0f; } else { f32 accel = dist_hi - dist_lo; - f32 max_speed; gp->gv.inishie1.xF4 = accel * grI1_804D69F8->unk24 + gp->gv.inishie1.xF4; - max_speed = grI1_804D69F8->unk28; - if (gp->gv.inishie1.xF4 > max_speed) { - gp->gv.inishie1.xF4 = max_speed; - } else if (gp->gv.inishie1.xF4 < -max_speed) { - gp->gv.inishie1.xF4 = -max_speed; + if (gp->gv.inishie1.xF4 > grI1_804D69F8->unk28) { + gp->gv.inishie1.xF4 = grI1_804D69F8->unk28; + } else if (gp->gv.inishie1.xF4 < -grI1_804D69F8->unk28) { + gp->gv.inishie1.xF4 = -grI1_804D69F8->unk28; } - if (dist_lo != 0.0f && dist_hi != 0.0f && gp->gv.inishie1.xF4 != 0.0f) - { + if (dist_lo && dist_hi && gp->gv.inishie1.xF4) { gp->gv.inishie1.xF4 *= grI1_804D69F8->unk2C[0].x; } else { gp->gv.inishie1.xF4 *= grI1_804D69F8->unk2C[0].y; @@ -893,7 +990,11 @@ void grInishie1_801FC110(HSD_GObj* gobj) { if (fabsf_inline(gp->gv.inishie1.xF0) > grI1_804D69F8->unk20) { - gp->gv.inishie1.xF0 = fabsf_inline(gp->gv.inishie1.xF0); + if (gp->gv.inishie1.xF0 < 0.0f) { + gp->gv.inishie1.xF0 = -grI1_804D69F8->unk20; + } else { + gp->gv.inishie1.xF0 = grI1_804D69F8->unk20; + } gp->gv.inishie1.xEE = 1; gp->gv.inishie1.xF4 = 0.0f; } @@ -915,13 +1016,13 @@ static inline s32 get_block_id(s32 block_id) int i = BLOCK_COUNT; s32 idx = 0; while (i != 0) { - if (block_id == block_idx_table[i].idx) { + if (block_id == block_idx_table[idx].idx) { return idx; } idx += 1; i -= 1; } - invalid_state(0x1F9); + invalid_state(0x1F0); return idx; } diff --git a/src/melee/gr/grkinokoroute.c b/src/melee/gr/grkinokoroute.c index 43f8382f7b..8cceec1c31 100644 --- a/src/melee/gr/grkinokoroute.c +++ b/src/melee/gr/grkinokoroute.c @@ -226,13 +226,17 @@ bool grKinokoRoute_802078E8(Ground_GObj* arg) void grKinokoRoute_802078F0(Ground_GObj* gobj) { - u8 pad_stack[8]; s32 i; + union { + Ground* gp; + struct grKinokoRoute_GroundVars_Entry* entry; + } cursor; Vec3 pos; - Ground* gp = gobj->user_data; HSD_GObj* fighter; f32 scale; + cursor.gp = gobj->user_data; + fighter = Ground_801C57A4(); if (fighter != NULL) { ftLib_80086644(fighter, &pos); @@ -247,14 +251,14 @@ void grKinokoRoute_802078F0(Ground_GObj* gobj) scale = 1.0f; } - for (i = 0; i < 4; i++) { - if (gp->gv.kinokoroute.entries[i].jobj != NULL) { + for (i = 0; i < 4; i++, cursor.entry++) { + if (cursor.gp->gv.kinokoroute.entries[0].jobj != NULL) { HSD_JObjSetTranslateX( - gp->gv.kinokoroute.entries[i].jobj, - scale * (gp->gv.kinokoroute.entries[i].pos.x + pos.x)); + cursor.gp->gv.kinokoroute.entries[0].jobj, + scale * (cursor.gp->gv.kinokoroute.entries[0].pos.x + pos.x)); HSD_JObjSetTranslateY( - gp->gv.kinokoroute.entries[i].jobj, - scale * (gp->gv.kinokoroute.entries[i].pos.y + pos.y)); + cursor.gp->gv.kinokoroute.entries[0].jobj, + scale * (cursor.gp->gv.kinokoroute.entries[0].pos.y + pos.y)); } } } diff --git a/src/melee/gr/grkongo.c b/src/melee/gr/grkongo.c index f3daaa56e8..0fce6b2a82 100644 --- a/src/melee/gr/grkongo.c +++ b/src/melee/gr/grkongo.c @@ -311,7 +311,6 @@ void grKongo_801D577C(Ground_GObj* arg0) Ground* gp = arg0->user_data; HSD_JObj* jobj = Ground_801C3FA4(arg0, 1); Vec3 vec; - lbColl_80008D30_arg1 hit; f32 limit_angle; f32 angle_delta; @@ -332,21 +331,15 @@ void grKongo_801D577C(Ground_GObj* arg0) if (angle_delta < 0.0f) { angle_delta += M_TAU; } - if (!(angle_delta < limit_angle)) { - f32 abs_vel; - abs_vel = gp->gv.kongo3.xE0; - if (abs_vel < 0.0f) { - abs_vel = -abs_vel; - } - if (!(angle_delta < abs_vel)) { - if ((s16) gp->gv.kongo3.xC4 == 2) { - gp->gv.kongo3.xC4 = 3; - } - break; + if (angle_delta < limit_angle || angle_delta < ABS(gp->gv.kongo3.xE0)) + { + if ((s16) gp->gv.kongo3.xC4 == 3) { + gp->gv.kongo3.xC4 = 0; } + break; } - if ((s16) gp->gv.kongo3.xC4 == 3) { - gp->gv.kongo3.xC4 = 0; + if ((s16) gp->gv.kongo3.xC4 == 2) { + gp->gv.kongo3.xC4 = 3; } break; } @@ -366,8 +359,8 @@ void grKongo_801D577C(Ground_GObj* arg0) spin_step = -DegToRad(grKg_804D6980->unk34); } gp->gv.kongo3.xDC = spin_step; - gp->gv.kongo2.xCC = - random_adder_f(grKg_804D6980->unk3C, grKg_804D6980->unk40); + gp->gv.kongo2.xCC = rand_range((s32) grKg_804D6980->unk40, + (s32) grKg_804D6980->unk3C); } break; case 1: @@ -379,15 +372,19 @@ void grKongo_801D577C(Ground_GObj* arg0) gp->gv.kongo2.xCC = val2 - 1; if (val2 < 0) { gp->gv.kongo3.xC4 = 2; - gp->gv.kongo2.xCC = - random_adder_f(grKg_804D6980->unk2C, grKg_804D6980->unk30); + gp->gv.kongo2.xCC = rand_range((s32) grKg_804D6980->unk30, + (s32) grKg_804D6980->unk2C); gp->gv.kongo3.xD4 = grKongo_801D8314(); } } break; } gp->gv.kongo3.xD8 += gp->gv.kongo3.xE0; - tau_range(&gp->gv.kongo3.xD8); + if (gp->gv.kongo3.xD8 > M_TAU) { + gp->gv.kongo3.xD8 -= M_TAU; + } else if (gp->gv.kongo3.xD8 < -M_TAU) { + gp->gv.kongo3.xD8 += M_TAU; + } HSD_JObjSetRotationZ(jobj, gp->gv.kongo.xD8); lb_8000B1CC(jobj, NULL, &vec); Ground_801C4D70(arg0, &vec, gp->gv.kongo3.xD8); @@ -404,7 +401,7 @@ void grKongo_801D577C(Ground_GObj* arg0) if (gp->gv.kongo2.xE8 > grKg_804D6980->unk60) { gp->gv.kongo2.xE8 = grKg_804D6980->unk60; gp->gv.kongo2.xCE = - random_adder(grKg_804D6980->unk68, grKg_804D6980->unk64); + rand_range(grKg_804D6980->unk68, grKg_804D6980->unk64); gp->gv.kongo3.xC8 = 2; } break; @@ -419,8 +416,8 @@ void grKongo_801D577C(Ground_GObj* arg0) gp->gv.kongo2.xE8 -= grKg_804D6980->unk5C; if (gp->gv.kongo2.xE8 < 0.0f) { gp->gv.kongo2.xE8 = 0.0f; - gp->gv.kongo2.xCE = random_adder(*(s32*) &grKg_804D6980->unk58, - *(s32*) &grKg_804D6980->unk54); + gp->gv.kongo2.xCE = rand_range(*(s32*) &grKg_804D6980->unk58, + *(s32*) &grKg_804D6980->unk54); gp->gv.kongo3.xC8 = 0; } break; @@ -441,28 +438,22 @@ void grKongo_801D577C(Ground_GObj* arg0) gp->gv.kongo3.xC6 = 1; Ground_801C5440(gp, 0, 0x129U); grMaterial_801C9604(arg0, grKg_804D6980->unk84, 0); - return; } return; } - case 1: { - s16 val2; + case 1: if (gp->gv.kongo.u.taru.keep == NULL) { gp->gv.kongo3.xC6 = 0; - goto block_124; - } - val2 = gp->gv.kongo3.xCA; - gp->gv.kongo3.xCA = val2 - 1; - if (val2 >= 0) { - break; + } else { + if (gp->gv.kongo3.xCA-- >= 0) { + break; + } + gp->gv.kongo3.xC6 = 2; } - gp->gv.kongo3.xC6 = 2; - } case 2: { /* switch 2 */ f32 angle; HSD_GObj* kept_gobj; - block_124:; - hit = grKg_803B7FB0; + lbColl_80008D30_arg1 hit = grKg_803B7FB0; hit.state = 1; hit.damage = *(u32*) &grKg_804D6980->unk6C; hit.kb_angle = *(u32*) &grKg_804D6980->unk70; @@ -638,7 +629,7 @@ void grKongo_801D828C(HSD_GObj* gobj) if (gp->gv.kongo3.xC6 != 1) { return; } - HSD_ASSERT(1719, gp->gv.kongo.u.taru.keep); + HSD_ASSERTMSG(1719, gp->gv.kongo.u.taru.keep, "gp->u.taru.keep"); if (((u8*) gp->gv.kongo.u.taru.keep)[2] == 8) { gp->gv.kongo3.xC6 = 0; gp->gv.kongo.u.taru.keep = NULL; @@ -685,41 +676,22 @@ void grKongo_801D6518(Ground_GObj* arg) return; } -typedef struct grKg_801D651C_pair { - s32 a; - s32 b; -} grKg_801D651C_pair; - -typedef struct grKg_801D651C_pair_list { - grKg_801D651C_pair pairs[3]; - s32 terminator; -} grKg_801D651C_pair_list; - -static const grKg_801D651C_pair_list grKg_803B7FD4 = { - { - { 7, 4 }, - { 8, 5 }, - { 9, 6 }, - }, - 0, -}; - void grKongo_801D651C(Ground_GObj* gobj) { Ground* gp; HSD_JObj* jobj; Vec3 sp2C; - grKg_801D651C_pair list[3]; + grKg_SplineChoice list[3]; int i; PAD_STACK(8); gp = gobj->user_data; jobj = gobj->hsd_obj; - list[0] = grKg_803B7FD4.pairs[0]; - list[1] = grKg_803B7FD4.pairs[1]; - list[2] = grKg_803B7FD4.pairs[2]; + list[0] = grKg_SplineChoices.pairs[0]; + list[1] = grKg_SplineChoices.pairs[1]; + list[2] = grKg_SplineChoices.pairs[2]; i = HSD_Randi(3); - gp->gv.kongo2.xC4 = Ground_801C247C(list[i].a, list[i].b); + gp->gv.kongo2.xC4 = Ground_801C247C(list[i].file, list[i].spline); gp->gv.kongo2.xC8 = grKg_804DAFA0; gp->gv.kongo2.xD0 = grKg_804DAFA0; gp->gv.kongo.xCC = grKg_804DAFA0; @@ -729,6 +701,25 @@ void grKongo_801D651C(Ground_GObj* gobj) HSD_JObjSetTranslate(jobj, &sp2C); } +/// Args for #Ground_801C247C: a dat file index and the index of the +/// spline to take from that file's spline table. +/// +/// Defined after #grKongo_801D651C (declared in grkongo.static.h) to +/// match: at the reference's code for that function, the compiler +/// addresses this object through the symbol itself rather than a +/// .rodata section anchor, which MWCC only produces when the object +/// is not yet defined at the point of use. Verified against the +/// section-anchored form (lwz offsets 0x24..0x38 off the .rodata +/// base) produced when the definition precedes the function. +const grKg_SplineChoiceList grKg_SplineChoices = { + { + { 7, 4 }, + { 8, 5 }, + { 9, 6 }, + }, + 0, +}; + bool grKongo_801D6660(Ground_GObj* arg) { return 0; @@ -998,7 +989,6 @@ void grKongo_801D6AFC(void) var_ctr_4 -= 1; } while (var_ctr_4 != 0); } - deltas = sp8; { s32 var_ctr_5 = 3; _struct_grKg_803E188C_0x18* var_r3_5 = grKg_803E188C; @@ -1013,6 +1003,7 @@ void grKongo_801D6AFC(void) var_ctr_5 -= 1; } while (var_ctr_5 != 0); } + deltas = sp8; { s32 var_ctr_6 = 3; f32* delta_init = deltas; @@ -1450,9 +1441,9 @@ void grKongo_801D77E0(HSD_GObj* gobj, s32 arg1) { Ground* gp = gobj->user_data; s32 i; - f32 v; f32 limit; f32 step; + PAD_STACK(8); if (arg1 != 0) { gp->gv.kongo.xC4 = 0.0f; @@ -1466,36 +1457,33 @@ void grKongo_801D77E0(HSD_GObj* gobj, s32 arg1) if (q->gv.kongo.xC8 > 0.0f) { step = 0.017453292f * grKg_804D6980->unkB4; } else { - step = 0.017453292f * grKg_804D6980->unkB4 * 0.5f; + step = (0.017453292f * grKg_804D6980->unkB4) / 2.0f; } q->gv.kongo.xC8 -= step; } else if (q->gv.kongo.xC4 < 0.0f) { if (q->gv.kongo.xC8 < 0.0f) { step = 0.017453292f * grKg_804D6980->unkB4; } else { - step = 0.017453292f * grKg_804D6980->unkB4 * 0.5f; + step = (0.017453292f * grKg_804D6980->unkB4) / 2.0f; } q->gv.kongo.xC8 += step; } q->gv.kongo.xC4 += q->gv.kongo.xC8; - v = q->gv.kongo.xC4; limit = 0.017453292f * (grKg_804D6980->unkB8 - 0.017453292f * grKg_804D6980->unkAC); - if (v > limit) { + if (q->gv.kongo.xC4 > limit) { q->gv.kongo.xC4 = limit; q->gv.kongo.xC8 = 0.0f; - } else if (v < -limit) { + } else if (q->gv.kongo.xC4 < -limit) { q->gv.kongo.xC4 = -limit; q->gv.kongo.xC8 = 0.0f; - } else { - f32 av = (v < 0.0f) ? -v : v; - if (av < 0.017453292f * grKg_804D6980->unkB4) { - f32 av2 = (q->gv.kongo.xC8 < 0.0f) ? -q->gv.kongo.xC8 - : q->gv.kongo.xC8; - if (av2 < 0.017453292f * grKg_804D6980->unkB4) { - q->gv.kongo.xC4 = 0.0f; - q->gv.kongo.xC8 = 0.0f; - } + } else if (ABS(q->gv.kongo.xC4) < + 0.017453292f * grKg_804D6980->unkB4) + { + if (ABS(q->gv.kongo.xC8) < 0.017453292f * grKg_804D6980->unkB4) + { + q->gv.kongo.xC4 = 0.0f; + q->gv.kongo.xC8 = 0.0f; } } q = (Ground*) ((u8*) q + 0x10); diff --git a/src/melee/gr/grkongo.static.h b/src/melee/gr/grkongo.static.h index 2bc83468dc..280dced31b 100644 --- a/src/melee/gr/grkongo.static.h +++ b/src/melee/gr/grkongo.static.h @@ -18,6 +18,20 @@ extern S16Vec3 grKg_803E16E0[6]; extern StageCallbacks grKg_803E1704[12]; +/// A dat file index and the index of a spline within that file's +/// spline table, as taken by #Ground_801C247C. +typedef struct grKg_SplineChoice { + s32 file; + s32 spline; +} grKg_SplineChoice; + +typedef struct grKg_SplineChoiceList { + grKg_SplineChoice pairs[3]; + s32 terminator; +} grKg_SplineChoiceList; + +extern const grKg_SplineChoiceList grKg_SplineChoices; + static struct { f32 unk0; f32 unk4; diff --git a/src/melee/gr/grmaterial.c b/src/melee/gr/grmaterial.c index 51b0afe2b4..d8efe84e1a 100644 --- a/src/melee/gr/grmaterial.c +++ b/src/melee/gr/grmaterial.c @@ -290,11 +290,14 @@ void grMaterial_801C8E74(void) static void fn_801C8EF8(HSD_MObj* mobj, u32 rendermode) { - HSD_TECnst sp_cnst; - HSD_TevDesc sp_tevdesc; + HSD_TObj* tobj; + u8 pad1[0xC]; GXColor sp114; + HSD_TevDesc sp_tevdesc; + u8 pad2[0x54]; + HSD_TECnst sp_cnst; + u8 pad3[0x10]; Ground* gp; - HSD_TObj* tobj; HSD_TObj** cur_tobj; s32 reg1_lt4_for_kcsel; s32 temp; @@ -303,8 +306,6 @@ static void fn_801C8EF8(HSD_MObj* mobj, u32 rendermode) s32 reg1_lt4; s32 reg1; u32 mobj_rendermode; - char* base = (char*) &grMaterial_803E0A20; - PAD_STACK(0x74); HSD_StateInitTev(); mobj_rendermode = mobj->rendermode; @@ -337,8 +338,8 @@ static void fn_801C8EF8(HSD_MObj* mobj, u32 rendermode) gp = HSD_GObj_804D7814->user_data; (void) gp; if (grMaterial_GetOverlay(gp)->x7C_color_enable || gp->x10_flags.b6) { - sp_cnst = *(HSD_TECnst*) (base + 0xC4); - sp_tevdesc = *(HSD_TevDesc*) (base + 0x50); + sp_cnst = grMaterial_803E0A20.texp_tmpl; + sp_tevdesc = grMaterial_803E0A20.tevdesc_tmpl; sp_tevdesc.stage = HSD_StateAssignTev(); if (grMaterial_GetOverlay(gp)->x7C_color_enable) { reg1 = lbGetFreeColorRegister(0, mobj, NULL); diff --git a/src/melee/gr/grmutecity.c b/src/melee/gr/grmutecity.c index 3bd8a374af..17c9032978 100644 --- a/src/melee/gr/grmutecity.c +++ b/src/melee/gr/grmutecity.c @@ -1239,20 +1239,16 @@ void grMuteCity_801F106C(s32 i) void grMuteCity_801F1328(void) { - s32 offset; s32* arr = grMc_8049F440; - s32* p; int i; int j; - for (offset = 4, i = 1; i < 30; i++, offset += 4) { - p = (s32*) ((u32) arr + offset); + for (i = 1; i < 30; i++) { for (j = i; j >= 0; j--) { - s32 temp = p[0]; - s32 prev = p[-1]; - if (grMc_8049F4B8[temp].x0 > grMc_8049F4B8[prev].x0) { - p[0] = prev; - *--p = temp; + s32 temp = arr[j]; + if (grMc_8049F4B8[arr[j]].x0 > grMc_8049F4B8[arr[j - 1]].x0) { + arr[j] = arr[j - 1]; + arr[j - 1] = temp; } else { break; } @@ -1296,16 +1292,16 @@ void grMuteCity_801F1328(void) grMc_8049F4B8[arr[idx]].x20 |= 1; { + f32 dz = + grMc_8049F4B8[arr[i]].x1C - grMc_8049F4B8[arr[idx]].x1C; f32 dx = grMc_8049F4B8[arr[i]].x14 - grMc_8049F4B8[arr[idx]].x14; f32 dy = grMc_8049F4B8[arr[i]].x18 - grMc_8049F4B8[arr[idx]].x18; - f32 dz = - grMc_8049F4B8[arr[i]].x1C - grMc_8049F4B8[arr[idx]].x1C; + f32 dz2 = dz * dz; f32 dx2 = dx * dx; f32 dy2 = dy * dy; - f32 dz2 = dz * dz; - if ((dz2 + (dx2 + dy2)) < 900.0f) { + if ((dz2 + (dy2 + dx2)) < 900.0f) { grMc_8049F4B8[arr[i]].x20 |= 8; grMc_8049F4B8[arr[idx]].x20 |= 8; } @@ -1511,11 +1507,7 @@ void grMuteCity_801F1A34(HSD_GObj* arg0, Ground_GObj* arg1) track_mid = 0.5f * (gp->gv.mutecity.xD4 + gp->gv.mutecity.xD8); Camera_GetTransformPosition(&spE8); - if (car_jobj == NULL) { - jobj = NULL; - } else { - jobj = car_jobj->child; - } + jobj = car_jobj == NULL ? NULL : car_jobj->child; { s32 timer = car_gp->gv.mutecity.xC4; @@ -1819,11 +1811,7 @@ void grMuteCity_801F1A34(HSD_GObj* arg0, Ground_GObj* arg1) car++; car_idx += 1; - if (jobj == NULL) { - jobj = NULL; - } else { - jobj = jobj->next; - } + jobj = jobj == NULL ? NULL : jobj->next; } while (car_idx < 0x1E); } @@ -1841,14 +1829,18 @@ DynamicModelDesc* grMuteCity_801F28A8(void) return NULL; } +typedef struct grMc_StackPadArg { + u32 x[4]; +} grMc_StackPadArg; + +static inline void grMc_StackPad(grMc_StackPadArg arg) {} + void grMuteCity_801F290C(Ground_GObj* gobj) { Ground* gp = GET_GROUND(gobj); HSD_GObj* lgobj; s32 i; HSD_LObj* lobj; - PAD_STACK(16); - if (grLib_801C96E8(gobj) != 0) { if (gp->gv.mutecity2.xC4_flags.b0) { lgobj = HSD_GObj_Entities->xC; @@ -1910,6 +1902,7 @@ void grMuteCity_801F290C(Ground_GObj* gobj) } gp->gv.mutecity2.xC4_flags.b0 = 1; } + grMc_StackPad(*(grMc_StackPadArg*) gp->gv.mutecity2.saved_colors); } void grMuteCity_801F2AB0(s32 arg0, HSD_JObj* arg1) diff --git a/src/melee/gr/groldpupupu.c b/src/melee/gr/groldpupupu.c index 9038822798..903bd4d02d 100644 --- a/src/melee/gr/groldpupupu.c +++ b/src/melee/gr/groldpupupu.c @@ -324,6 +324,7 @@ void grOldPupupu_80210D10(Ground_GObj* gobj) Ground* gp; f32 direction; f32 y; + f32 z; f32 x; f32 step; s16 timer; @@ -367,6 +368,7 @@ void grOldPupupu_80210D10(Ground_GObj* gobj) y = direction * (((f32) grOp_804D6A98->x4 * ((2.0F * rand) - 1.0F)) + 20.0F); } + z = -150.0F * direction; for (i = 0; i < count; i++) { HSD_GObj* spawn; spawn = grOldPupupu_802108B4_noinline(2); @@ -376,7 +378,7 @@ void grOldPupupu_80210D10(Ground_GObj* gobj) HSD_ASSERT(0x216, jobj); HSD_JObjSetTranslateX(jobj, direction * x); HSD_JObjSetTranslateY(jobj, y); - HSD_JObjSetTranslateZ(jobj, -150.0F * direction); + HSD_JObjSetTranslateZ(jobj, z); grAnime_801C7FF8(spawn, 0, 7, 0, 40.0F * (f32) i, 1.0F); HSD_JObjClearFlagsAll( Ground_801C3FA4(spawn, grOp_803E67B0[index].x2), @@ -524,9 +526,9 @@ bool fn_802112F4(Ground_GObj* gobj, HSD_GObj* fighter_gobj, Vec3* vel) void grOldPupupu_802113E0(Ground_GObj* gobj) { Ground* gp = gobj->user_data; - PAD_STACK(176); + PAD_STACK(160); - if (grOp_804D6A9C == 0) { + if ((int) grOp_804D6A9C == 0) { gp->gv.oldpupupu.xE0 += 1; gp->gv.oldpupupu.xDC = 0; @@ -538,7 +540,7 @@ void grOldPupupu_802113E0(Ground_GObj* gobj) gp->gv.oldpupupu.xD4 = 0; gp->gv.oldpupupu.xCC = 0; gp->gv.oldpupupu.xD0 = - rand_range(grOp_804D6A98->xC, grOp_804D6A98->x8); + randrange(grOp_804D6A98->xC, grOp_804D6A98->x8); grAnime_801C8138( gobj, gp->map_id, grOp_804D48C8[gp->gv.oldpupupu.xCC][gp->gv.oldpupupu.xD8]); @@ -549,8 +551,8 @@ void grOldPupupu_802113E0(Ground_GObj* gobj) other_gp->gv.oldpupupu.xCC = 0; other_gp->gv.oldpupupu.xD4 = gp->gv.oldpupupu.xD8; other_gp->gv.oldpupupu.xD0 = 1; - gp->gv.oldpupupu.xCC = rand_range((s32) grOp_804D6A98->x30, - (s32) grOp_804D6A98->x2C); + gp->gv.oldpupupu.xCC = randrange((s32) grOp_804D6A98->x30, + (s32) grOp_804D6A98->x2C); } gp->gv.oldpupupu.xD0 -= 1; @@ -565,9 +567,10 @@ void grOldPupupu_802113E0(Ground_GObj* gobj) grOp_804D48C8[gp->gv.oldpupupu.xCC] [gp->gv.oldpupupu.xD8]); gp->gv.oldpupupu.xCC = - rand_range((s32) grOp_804D6A98->x30, - (s32) grOp_804D6A98->x2C); + randrange((s32) grOp_804D6A98->x30, + (s32) grOp_804D6A98->x2C); } + gp = gobj->user_data; other_gp = Ground_801C2BA4(1)->user_data; other_gp->gv.oldpupupu.xC4 = gp->gv.oldpupupu.xC4; other_gp->gv.oldpupupu.xC8 = gp->gv.oldpupupu.xC8; @@ -580,6 +583,7 @@ void grOldPupupu_802113E0(Ground_GObj* gobj) { Ground* other_gp; + gp = gobj->user_data; gp->gv.oldpupupu.xC4 += 1; if (gp->gv.oldpupupu.xC4 >= 3) { gp->gv.oldpupupu.xC4 = 0; @@ -618,6 +622,7 @@ void grOldPupupu_802113E0(Ground_GObj* gobj) grAnime_801C8138(gobj, gp->map_id, grOp_804D48D0[gp->gv.oldpupupu.xCC] [gp->gv.oldpupupu.xD8]); + gp = gobj->user_data; gp->gv.oldpupupu.xC4 += 1; if (gp->gv.oldpupupu.xC4 >= 3) { gp->gv.oldpupupu.xC4 = 0; @@ -630,6 +635,7 @@ void grOldPupupu_802113E0(Ground_GObj* gobj) other_gp->gv.oldpupupu.xCC = 0; other_gp->gv.oldpupupu.xD4 = gp->gv.oldpupupu.xD8; other_gp->gv.oldpupupu.xD0 = 1; + gp = gobj->user_data; other_gp = Ground_801C2BA4(1)->user_data; other_gp->gv.oldpupupu.xC4 = gp->gv.oldpupupu.xC4; other_gp->gv.oldpupupu.xC8 = gp->gv.oldpupupu.xC8; @@ -644,6 +650,7 @@ void grOldPupupu_802113E0(Ground_GObj* gobj) grAnime_801C8138(gobj, gp->map_id, grOp_804D48D8[gp->gv.oldpupupu.xCC] [gp->gv.oldpupupu.xD8]); + gp = gobj->user_data; other_gp = Ground_801C2BA4(1)->user_data; other_gp->gv.oldpupupu.xC4 = gp->gv.oldpupupu.xC4; other_gp->gv.oldpupupu.xC8 = gp->gv.oldpupupu.xC8; @@ -657,6 +664,7 @@ void grOldPupupu_802113E0(Ground_GObj* gobj) { Ground* other_gp; + gp = gobj->user_data; gp->gv.oldpupupu.xC4 += 1; if (gp->gv.oldpupupu.xC4 >= 3) { gp->gv.oldpupupu.xC4 = 0; @@ -683,6 +691,7 @@ void grOldPupupu_802113E0(Ground_GObj* gobj) grAnime_801C8138( gobj, gp->map_id, grOp_804D48D0[gp->gv.oldpupupu.xCC][gp->gv.oldpupupu.xD8]); + gp = gobj->user_data; other_gp = Ground_801C2BA4(1)->user_data; other_gp->gv.oldpupupu.xC4 = gp->gv.oldpupupu.xC4; other_gp->gv.oldpupupu.xC8 = gp->gv.oldpupupu.xC8; @@ -705,15 +714,17 @@ void grOldPupupu_802113E0(Ground_GObj* gobj) gp->gv.oldpupupu.xDC = gp->gv.oldpupupu.xD8 + 1; if ((gp->gv.oldpupupu.xD0 % 10) == 0) { if (gp->gv.oldpupupu.xD8 == 0) { - lb_80011A50(&grOp_803E67E4[0], 0xF, 0.5F, 0.0F, - 0.0F, grOp_804D6A98->x20, - grOp_804D6A98->x24, grOp_804D6A98->x1C, - grOp_804D6A98->x28); + lb_80011A50( + &grOp_803E67E4[gp->gv.oldpupupu.xD8], 0xF, + 0.5F, 0.0F, 0.0F, grOp_804D6A98->x20, + grOp_804D6A98->x24, grOp_804D6A98->x1C, + grOp_804D6A98->x28); } else { - lb_80011A50(&grOp_803E67E4[1], 0xF, 0.5F, 0.0F, - 0.0F, grOp_804D6A98->x14, - grOp_804D6A98->x24, grOp_804D6A98->x18, - grOp_804D6A98->x28); + lb_80011A50( + &grOp_803E67E4[gp->gv.oldpupupu.xD8], 0xF, + 0.5F, 0.0F, 0.0F, grOp_804D6A98->x14, + grOp_804D6A98->x24, grOp_804D6A98->x18, + grOp_804D6A98->x28); } return; } @@ -721,6 +732,7 @@ void grOldPupupu_802113E0(Ground_GObj* gobj) } else { Ground* other_gp; + gp = gobj->user_data; gp->gv.oldpupupu.xC4 += 1; if (gp->gv.oldpupupu.xC4 >= 3) { gp->gv.oldpupupu.xC4 = 0; diff --git a/src/melee/gr/gronett.c b/src/melee/gr/gronett.c index 054c8dcfed..26d9ea6d9c 100644 --- a/src/melee/gr/gronett.c +++ b/src/melee/gr/gronett.c @@ -473,13 +473,19 @@ bool grOnett_801E43D8(Ground_GObj* gobj) return false; } +static inline f32 grOnett_GetRandomCarSpeed(void) +{ + return grOt_804D69C0->x58 * HSD_Randf(); +} + void grOnett_801E43E0(Ground_GObj* gobj) { Ground* gp = GET_GROUND(gobj); s8 saved_car = gp->gv.onettcar.curr_car; Vec3 pos = { 0.0f, 0.0f, 0.0f }; + u8 pad[4]; f32 cam_x, cam_y, cam_z; - PAD_STACK(36); + PAD_STACK(32); if (!gp->gv.onettcar.x0_b0) { HSD_JObj* car_jobj; @@ -492,18 +498,17 @@ void grOnett_801E43E0(Ground_GObj* gobj) switch ((s8) gp->gv.onettcar.state_a) { case 0: { - s8 old_car = gp->gv.onettcar.curr_car; - HSD_JObj* new_jobj; + u8 old_car = gp->gv.onettcar.curr_car; while (gp->gv.onettcar.curr_car == old_car || gp->gv.onettcar.curr_car == gp->gv.onettcar.next_car) { gp->gv.onettcar.curr_car = HSD_Randi(4); } - new_jobj = gp->gv.onettcar.car_jobjs[gp->gv.onettcar.curr_car]; - HSD_JObjSetTranslateX(new_jobj, 726.0f); - HSD_JObjSetTranslateZ(new_jobj, 30.0f); - HSD_JObjSetRotationY(new_jobj->child, 0.0f); + car_jobj = gp->gv.onettcar.car_jobjs[gp->gv.onettcar.curr_car]; + HSD_JObjSetTranslateX(car_jobj, 726.0f); + HSD_JObjSetTranslateZ(car_jobj, 30.0f); + HSD_JObjSetRotationY(car_jobj->child, 0.0f); gp->gv.onettcar.state_a = 1; gp->gv.onettcar.x108 = grOt_804D69C0->x44; Ground_801C5784(0); @@ -514,10 +519,13 @@ void grOnett_801E43E0(Ground_GObj* gobj) if (t != 0) { gp->gv.onettcar.x108 = t - 1; } else { - s8 car = gp->gv.onettcar.curr_car; + s32 car = gp->gv.onettcar.curr_car; gp->gv.onettcar.x108 = grOt_804D69C0->x48; - gp->gv.onettcar.car_speed = - grOt_804D69C0->x58 * HSD_Randf() + grOt_804D69C0->x54; + { + f32 rand = HSD_Randf(); + gp->gv.onettcar.car_speed = + grOt_804D69C0->x58 * rand + grOt_804D69C0->x54; + } if (gp->gv.onettcar.car_speed > 0.0f) { gp->gv.onettcar.car_speed *= -1.0f; } @@ -645,18 +653,16 @@ void grOnett_801E43E0(Ground_GObj* gobj) switch (state_b) { case 0: { - HSD_JObj* new_jobj; while (gp->gv.onettcar.next_car == next || gp->gv.onettcar.next_car == gp->gv.onettcar.curr_car) { gp->gv.onettcar.next_car = HSD_Randi(4); } - new_jobj = gp->gv.onettcar.car_jobjs[gp->gv.onettcar.next_car]; - (void) new_jobj; - HSD_JObjSetTranslateX(new_jobj, -642.0f); - HSD_JObjSetTranslateZ(new_jobj, 56.0f); - HSD_JObjSetRotationY(new_jobj->child, M_PI); + b_jobj = gp->gv.onettcar.car_jobjs[gp->gv.onettcar.next_car]; + HSD_JObjSetTranslateX(b_jobj, -642.0f); + HSD_JObjSetTranslateZ(b_jobj, 56.0f); + HSD_JObjSetRotationY(b_jobj->child, M_PI); gp->gv.onettcar.state_b = 1; gp->gv.onettcar.timer_b = grOt_804D69C0->x44; return; @@ -669,7 +675,7 @@ void grOnett_801E43E0(Ground_GObj* gobj) } gp->gv.onettcar.timer_b = grOt_804D69C0->x48; gp->gv.onettcar.speed_b = - grOt_804D69C0->x58 * HSD_Randf() + grOt_804D69C0->x54; + grOnett_GetRandomCarSpeed() + grOt_804D69C0->x54; gp->gv.onettcar.state_b = 2; return; } @@ -779,16 +785,11 @@ void grOnett_801E5214(Ground_GObj* gobj) disp = gp->gv.onett.awnings[i].accumulator; error = disp - gp->gv.onett.awnings[i].velocity; - vel = gp->gv.onett.awnings[i].velocity; force = gp->gv.onett.awnings[i].initial; spring = grOt_804D69C0->spring_constant; force += spring; - if (error < 0.0f) { - abs_ratio = -error; - } else { - abs_ratio = error; - } + abs_ratio = ABS(error); abs_ratio /= grOt_804D69C0->max_displacement; if (error < 0.0) { @@ -797,7 +798,8 @@ void grOnett_801E5214(Ground_GObj* gobj) force = grOt_804D69C0->spring_force * abs_ratio + force; } - force = (force - spring) * (1.0f - grOt_804D69C0->damping); + force -= spring; + force *= 1.0f - grOt_804D69C0->damping; if (force > grOt_804D69C0->max_velocity) { force = grOt_804D69C0->max_velocity; @@ -805,6 +807,7 @@ void grOnett_801E5214(Ground_GObj* gobj) force = -grOt_804D69C0->max_velocity; } + vel = gp->gv.onett.awnings[i].velocity; if ((ABS(vel - disp) < grOt_804D69C0->pos_threshold) && (ABS(force) < grOt_804D69C0->vel_threshold)) { diff --git a/src/melee/gr/ground.c b/src/melee/gr/ground.c index 06eccb0440..f2d7e54c3c 100644 --- a/src/melee/gr/ground.c +++ b/src/melee/gr/ground.c @@ -80,7 +80,7 @@ /* 1C1E94 */ static void Ground_801C1E94(void); /* 1C20E0 */ LightList** Ground_801C20E0(UnkArchiveStruct*, LightList**); /* 1C24F8 */ static bool Ground_801C24F8(s32, u32, s32*); -/* 1C28CC */ void Ground_801C28CC(void*, s32); +/* 1C28CC */ void Ground_801C28CC(s32*, s32); /* 1C2BBC */ static void Ground_801C2BBC(HSD_GObj*, s32); /* 1C2BD4 */ static void Ground_801C2BD4(void*); /* 1C34AC */ void Ground_801C34AC(s32, HSD_JObj*, struct HSD_Joint*); @@ -109,7 +109,7 @@ extern StageData Ground_803DFEA8, grTe_803E5764, grCs_803E11A4, grRc_803E4ECC, grKg_803E1800, grGd_803E52E0, grGb_803E3F6C, grSh_803E5130, grZe_803E1B2C, grKr_803E4D0C, grSt_803E274C, grYt_803E51CC, grIz_803E0E5C, grGr_803E76D0, - grCn_803E1F08, grVe_803E54CC, grPs_803E1334, grPu_803E6A3C, grMc_803E33DC, + grCn_803E1F08, grVe_StageData, grPs_803E1334, grPu_803E6A3C, grMc_803E33DC, grBb_803E2D20, grOt_803E2858, grFs_803E3D94, grIm_803E4800, grI1_803E4950, grI2_803E4C00, grFz_803E7A00, grOp_803E6748, grOy_803E650C, grOk_803E65E8, grNKr_803E584C, grSh_Route_803E5988, grZe_Route_803E5E0C, @@ -130,7 +130,7 @@ static StageData* Ground_803DFEDC[] = { &grGb_803E3F6C, &grSh_803E5130, &grZe_803E1B2C, &grKr_803E4D0C, &grSt_803E274C, &grYt_803E51CC, &grIz_803E0E5C, &grGr_803E76D0, &grCn_803E1F08, - &grVe_803E54CC, &grPs_803E1334, &grPu_803E6A3C, + &grVe_StageData, &grPs_803E1334, &grPu_803E6A3C, &grMc_803E33DC, &grBb_803E2D20, &grOt_803E2858, &grFs_803E3D94, &grIm_803E4800, NULL, &grI1_803E4950, &grI2_803E4C00, NULL, @@ -1163,18 +1163,41 @@ typedef struct LightOverrideEntry { /* 0x5 */ u8 _pad[3]; } LightOverrideEntry; +static inline HSD_LightDesc* get_light_desc_inline(LightList** list) +{ + return *(HSD_LightDesc**) *list; +} + +static inline bool find_light_override(UnkArchiveStruct* archive, + HSD_LightDesc* desc, bool* b6, bool* b7, + bool* b5) +{ + UnkStageDat* dat = archive->unk4; + s32 count = dat->unk1C; + s32 i; + + if (count != 0) { + for (i = 0; i < count; i++) { + LightOverrideEntry* arr = dat->unk18; + if (arr[i].desc == desc) { + *b6 = arr[i].b; + *b7 = arr[i].a; + *b5 = arr[i].c; + return true; + } + } + } + return false; +} + LightList** Ground_801C20E0(UnkArchiveStruct* archive, LightList** lightset) { LightList** out; LightList** clean; - LightOverrideEntry* arr; - UnkStageDat* dat; HSD_LightDesc* desc; - s32 count; - s32 i; bool found; LightList** walker; - s32 b6, b7, b5; + bool b6, b7, b5; bool matched; HSD_ASSERT(1907, lightset); @@ -1183,23 +1206,8 @@ LightList** Ground_801C20E0(UnkArchiveStruct* archive, LightList** lightset) walker = lightset; matched = 0; while (*walker != NULL) { - dat = archive->unk4; desc = (*walker)->desc; - count = dat->unk1C; - if (count != 0) { - for (i = 0; i < count; i++) { - arr = dat->unk18; - if (arr[i].desc == desc) { - found = true; - b6 = arr[i].b; - b7 = arr[i].a; - b5 = arr[i].c; - goto search1_done; - } - } - } - found = false; - search1_done: + found = find_light_override(archive, desc, &b6, &b7, &b5); if (found != 0 && (b6 != 0 || b7 != 0 || b5 != 0)) { matched = 1; break; @@ -1213,36 +1221,26 @@ LightList** Ground_801C20E0(UnkArchiveStruct* archive, LightList** lightset) out = lightset; while (*out != NULL) { - desc = *(HSD_LightDesc**) *out; - if (desc->flags & 3) { - dat = archive->unk4; - (void) dat; - count = dat->unk1C; - if (count != 0) { - for (i = 0; i < count; i++) { - arr = dat->unk18; - if (arr[i].desc == desc) { - found = true; - b6 = arr[i].b; - b7 = arr[i].a; - b5 = arr[i].c; - goto search2_done; - } - } - } - found = false; - search2_done: + u16* flags; + desc = get_light_desc_inline(out); + flags = &desc->flags; + if (*flags & 3) { + found = find_light_override(archive, desc, &b6, &b7, &b5); if (found == 0 || (b6 == 0 && b7 == 0 && b5 == 0)) { clean = out; - while ((clean[0] = clean[1]) != NULL) { + do { + clean[0] = clean[1]; + if (clean[0] == NULL) { + break; + } clean++; - } + } while (true); out--; } else { if (b6) { - desc->flags |= 4; + *flags |= 4; } else { - desc->flags &= ~4; + *flags &= ~4; } if (b7) { (*(HSD_LightDesc**) *out)->flags |= 8; @@ -1454,48 +1452,31 @@ static char msg1[] = " check StageParam.csv or StageItem.csv, stdata.c\n"; static char msg2[] = " stageid=%d\n"; -void Ground_801C28CC(void* arg0, s32 arg1) +static inline void reportStageParams(s32 count) +{ + s32 i; + + OSReport(msg1); + { + UnkBgmStruct* p = stage_info.param->xB0; + for (i = 0; i < count; i++, p++) { + OSReport(msg2, p->x0); + } + } +} + +void Ground_801C28CC(s32* arg0, s32 arg1) { UnkBgmStruct* bgm = stage_info.param->xB0; s32 count = stage_info.param->xB4; s32 i; - PAD_STACK(16); - for (i = 0; i < count; i++) { if (bgm->x0 == arg1) { - UnkBgmStruct* b = bgm; - s32* out = (s32*) arg0; - s32 k; - s32 n = 0; - for (k = 0; k < 4; k++) { - out[0] = *(s16*) ((u8*) stage_info.param + n + 0x6A) * - *(s16*) ((u8*) b + 0x1A); - out[1] = *(s16*) ((u8*) stage_info.param + n + 0x6C) * - *(s16*) ((u8*) b + 0x1C); - out[2] = *(s16*) ((u8*) stage_info.param + n + 0x6E) * - *(s16*) ((u8*) b + 0x1E); - out[3] = *(s16*) ((u8*) stage_info.param + n + 0x70) * - *(s16*) ((u8*) b + 0x20); - out[4] = *(s16*) ((u8*) stage_info.param + n + 0x72) * - *(s16*) ((u8*) b + 0x22); - out[5] = *(s16*) ((u8*) stage_info.param + n + 0x74) * - *(s16*) ((u8*) b + 0x24); - out[6] = *(s16*) ((u8*) stage_info.param + n + 0x76) * - *(s16*) ((u8*) b + 0x26); - out[7] = *(s16*) ((u8*) stage_info.param + n + 0x78) * - *(s16*) ((u8*) b + 0x28); - b = (UnkBgmStruct*) ((u8*) b + 0x10); - out += 8; - n += 0x10; - } - if ((n >> 1) < 0x23) { - s16* bp = (s16*) ((u8*) b + 0x1A); - do { - *out++ = - *(s16*) ((u8*) stage_info.param + n + 0x6A) * *bp++; - n += 2; - } while ((n >> 1) < 0x23); + s32 j; + for (j = 0; 0x23 > j; j++) { + arg0[j] = ((s16*) stage_info.param)[0x35 + j] * + ((s16*) bgm)[0xD + j]; } return; } @@ -1503,14 +1484,7 @@ void Ground_801C28CC(void* arg0, s32 arg1) } OSReport(msg0, __FILE__, 0x906, stage_info.internal_stage_id, arg1, count); - OSReport(msg1); - { - UnkBgmStruct* p = stage_info.param->xB0; - for (i = 0; i < count; i++) { - OSReport(msg2, p->x0); - p++; - } - } + reportStageParams(count); while (1) { } } @@ -1893,10 +1867,10 @@ u32 unknown[] = { void Ground_801C34AC(s32 map_id, HSD_JObj* root, struct HSD_Joint* joint) { HSD_JObj* jobj; - StageInfo* stageinfo; UnkStageDat* stage_dat; UnkArchiveStruct* archive; int entry_count; + int i; struct { void* joint; s16* pairs; @@ -1905,9 +1879,7 @@ void Ground_801C34AC(s32 map_id, HSD_JObj* root, struct HSD_Joint* joint) int count; s16* pair; int prev_index; - int jobj_index; int target; - int i; int j; jobj = root; @@ -1926,31 +1898,31 @@ void Ground_801C34AC(s32 map_id, HSD_JObj* root, struct HSD_Joint* joint) if (entry_count == 0) { return; } + i = 0; entry = stage_dat->unk0; - for (i = 0; i < entry_count; i++, entry++) { - if (entry->joint == joint) { - break; + while (1) { + if (i < entry_count) { + if (entry->joint == joint) { + break; + } + } else { + return; } - } - if (i >= entry_count) { - return; + entry++; + i++; } count = entry->pair_count; - stageinfo = &stage_info; pair = entry->pairs; - if (count <= 0) { - return; - } for (j = count; j > 0; j--) { target = pair[0]; if (prev_index > target || prev_index == -1) { jobj = root; - jobj_index = 0; + i = 0; } else { - jobj_index = prev_index; + i = prev_index; } while (jobj != NULL) { - if (jobj_index == target) { + if (i == target) { break; } if (!(jobj->flags & JOBJ_INSTANCE) && @@ -1972,17 +1944,16 @@ void Ground_801C34AC(s32 map_id, HSD_JObj* root, struct HSD_Joint* joint) jobj = HSD_JObjGetParent(jobj); } } - jobj_index++; + i++; } - prev_index = jobj_index; - stageinfo->x280[pair[1]] = jobj; + prev_index = i; + stage_info.x280[pair[1]] = jobj; pair += 2; } } void Ground_801C36F4(int map_id, HSD_JObj* root, UNK_T joint) { - HSD_JObj* parent; HSD_JObj* jobj; UnkStageDat* stage_dat; UnkArchiveStruct* archive; @@ -2026,8 +1997,8 @@ void Ground_801C36F4(int map_id, HSD_JObj* root, UNK_T joint) jobj = stage_info.x280[i]; (void) jobj; if (jobj != NULL) { - while ((parent = jobj->parent) != NULL) { - jobj = parent; + while (jobj->parent != NULL) { + jobj = jobj->parent; } if (jobj == root) { stage_info.x280[i] = NULL; @@ -3188,7 +3159,7 @@ HSD_GObj* Ground_801C57C8(void) return Player_GetEntityAtIndex(0, 1); } -f32 Ground_801C57F0(void) +f32 Ground_801C57F0(s32 arg0) { return stage_info.x6E0; } diff --git a/src/melee/gr/ground.h b/src/melee/gr/ground.h index 11fc4a7a84..f0479f5c75 100644 --- a/src/melee/gr/ground.h +++ b/src/melee/gr/ground.h @@ -144,7 +144,7 @@ /* 1C5794 */ s32 Ground_801C5794(void); /* 1C57A4 */ HSD_GObj* Ground_801C57A4(void); /* 1C57C8 */ HSD_GObj* Ground_801C57C8(void); -/* 1C57F0 */ f32 Ground_801C57F0(void); +/* 1C57F0 */ f32 Ground_801C57F0(s32 arg0); /* 1C5800 */ void Ground_EnableMatchCamera(void); /* 1C5840 */ s32 Ground_801C5840(void); /* 1C58E0 */ Item_GObj* Ground_801C58E0(s32, s32); diff --git a/src/melee/gr/grpstadium.c b/src/melee/gr/grpstadium.c index 5befb3a09e..373f431158 100644 --- a/src/melee/gr/grpstadium.c +++ b/src/melee/gr/grpstadium.c @@ -2002,7 +2002,7 @@ void grStadium_801D435C(Ground_GObj* arg0) int i; cur = lbl_803E1630; for (i = 0; i < ARRAY_SIZE(lbl_803E1630); i++) { - gp->u.stadium.xD4 += cur++->scalar; + gp->u.stadium.xD4 = cur++->scalar + gp->u.stadium.xD4; } } var_r28 = 0; diff --git a/src/melee/gr/grpura.c b/src/melee/gr/grpura.c index 3041c18d5f..127f450a2e 100644 --- a/src/melee/gr/grpura.c +++ b/src/melee/gr/grpura.c @@ -261,8 +261,8 @@ void grPura_802120E0(Ground_GObj* arg0) spilC = grPu_803E6AA0[gp->gv.pura.xC6]; sp18 = grPu_803E6AA0[gp->gv.pura.xC4]; cur = gp->gv.pura.xC8; - gp->gv.pura.xC8 = cur + 1; t = (f32) cur / 3600.0f; + gp->gv.pura.xC8 = cur + 1; sp18.r = (s8) (t * (f32) ((u8) spilC.r - (u8) sp18.r) + (f32) (u8) sp18.r); sp18.g = @@ -394,50 +394,61 @@ void grPura_802125F0(HSD_GObj* arg0) } } -void grPura_80212CD4(HSD_GObj* arg0) +static inline void grPura_80212CD4_inline(Ground* gp, HSD_JObj* jobj, + HSD_JObj** node) { - Ground* gp = arg0->user_data; - Ground* gp2 = gp; - HSD_JObj* jobj = arg0->hsd_obj; u32 i; - HSD_JObj* node; - Vec3 subject_pos; for (i = 0; i < 25; i++) { gp->gv.pura3.xC4[i] = NULL; gp->gv.pura3.x128[i] = NULL; } - if (jobj == NULL) { - node = NULL; + *node = NULL; } else { - node = jobj->child; + *node = jobj->child; } +} + +void grPura_80212CD4(HSD_GObj* arg0) +{ + Ground* gp = arg0->user_data; + Ground* gp2 = gp; + HSD_JObj* jobj = arg0->hsd_obj; + s32 j; + HSD_JObj* node; + Vec3 subject_pos; + + grPura_80212CD4_inline(gp, jobj, &node); + if (node != NULL) { if (node == NULL) { node = NULL; } else { node = node->child; } - for (i = 0; i < 25; i++) { + for (j = 0; j < 25; j++) { if (node == NULL) { return; } - if ((gp->gv.pura3.x128[i] = Camera_80029020()) != NULL) { - gp->gv.pura3.xC4[i] = node; - lb_8000B1CC(gp2->gv.pura3.xC4[i], NULL, &subject_pos); - gp->gv.pura3.x128[i]->x10 = subject_pos; + if ((gp->gv.pura3.x128[j] = Camera_80029020()) != NULL) { + gp->gv.pura3.xC4[j] = node; + { + HSD_JObj** nodes = gp2->gv.pura3.xC4; + lb_8000B1CC(nodes[j], NULL, &subject_pos); + } + gp->gv.pura3.x128[j]->x10 = subject_pos; if (HSD_JObjGetFlags(node) & 0x10) { - gp->gv.pura3.x128[i]->x8 = 1; + gp->gv.pura3.x128[j]->x8 = 1; } else { - gp->gv.pura3.x128[i]->x8 = 0; + gp->gv.pura3.x128[j]->x8 = 0; } - gp->gv.pura3.x128[i]->x48.x = 30.0f; - gp->gv.pura3.x128[i]->x48.y = -30.0f; - gp->gv.pura3.x128[i]->x40.x = -30.0f; - gp->gv.pura3.x128[i]->x40.y = 30.0f; + gp->gv.pura3.x128[j]->x48.x = 30.0f; + gp->gv.pura3.x128[j]->x48.y = -30.0f; + gp->gv.pura3.x128[j]->x40.x = -30.0f; + gp->gv.pura3.x128[j]->x40.y = 30.0f; { - CmSubject* subject = gp->gv.pura3.x128[i]; + CmSubject* subject = gp->gv.pura3.x128[j]; subject->x2C = subject->x40; subject->x34 = subject->x48; } diff --git a/src/melee/gr/grpushon.c b/src/melee/gr/grpushon.c index 021df06497..9ccd978b4d 100644 --- a/src/melee/gr/grpushon.c +++ b/src/melee/gr/grpushon.c @@ -21,6 +21,7 @@ #include "lb/lbvector.h" #include "lb/types.h" #include "mp/mplib.h" +#include "MSL/math.h" #include "sysdolphin/baselib/lobj.h" #include @@ -416,7 +417,6 @@ void grPushOn_802190D0(HSD_GObj* gobj) f32 scale = Ground_801C0498(); struct grPushOn_LightConfig* entry; Vec3 pos; - GXColor color; HSD_LObj* lobj; u32 i; @@ -425,7 +425,8 @@ void grPushOn_802190D0(HSD_GObj* gobj) i = 0; while (i < 9 && lobj != NULL) { - HSD_ASSERTMSG(698, (lobj->flags & LOBJ_TYPE_MASK) == LOBJ_POINT, + GXColor color; + HSD_ASSERTMSG(698, (u32) (lobj->flags & LOBJ_TYPE_MASK) == LOBJ_POINT, "HSD_LObjGetType(lobj)==LOBJ_POINT"); lobj->flags = LOBJ_POINT | LOBJ_DIFFUSE; color = entry->color; @@ -480,161 +481,178 @@ int grPushOn_80219230(int arg0) HSD_ASSERT(861, 0); } -void grPushOn_80218888(Ground_GObj* arg0) +void grPushOn_80218888(Ground_GObj* gobj) { - Vec3 sp10C; - Vec3 sp100; - s32 light_order[20]; - f32 light_distances[20]; - Vec3 sp54; - Vec3 sp48; - Vec3 sp3C; - GXColor sp38; - Vec3 sp2C; - Ground* gp = arg0->user_data; - HSD_GObj* fighter; + HSD_GObj* player; + Vec3 player_pos; + Vec3 light_pos; + s32 sorted[20]; + f32 distances[20]; + Vec3 pos1; + Vec3 pos2; + Vec3 dir; + GXColor color; + Vec3 temp_pos; + Ground* gp; + s32 count; s32 i; s32 j; - PAD_STACK(0x14); - - fighter = Ground_801C57A4(); - if (fighter != NULL) { - ftLib_80086644(fighter, &sp10C); + s32 best; + f32 min_dist; + f32 ref_dist; + f32 weight; + f32 dx; + f32 dy; + f32 dist_sq; + GET_GROUND(0); + GET_GROUND(0); + + gp = GET_GROUND(gobj); + player = Ground_801C57A4(); + if (player != NULL) { + ftLib_80086644(player, &player_pos); } else { - sp10C.z = 0.0f; - sp10C.y = 0.0f; - sp10C.x = 0.0f; + player_pos.z = 0.0f; + player_pos.y = 0.0f; + player_pos.x = 0.0f; } - if (gp->u.pushon.gobj != NULL) { - for (i = 0; i < gp->u.pushon.count; i++) { + if (gp->u.pushon.gobj != 0) { + i = 0; + while (i < (s32) gp->u.pushon.count) { HSD_LObj* lobj = gp->u.pushon.lobjs[i]; s32 type = lobj->flags & 3; + if (type == 0) { - light_distances[i] = -100.0f; - } else if ((u32) (type - 1) <= 1) { - f32 dx; - f32 dy; - f32 d2; - HSD_LObjGetPosition(lobj, &sp54); - dx = sp10C.x - sp54.x; - dy = sp10C.y - sp54.y; - dx *= dx; - d2 = dy * dy; - light_distances[i] = sqrtf(dx + d2); - } else if (type == 3) { - f32 dx; - HSD_LObjGetPosition(lobj, &sp48); - dx = sp10C.x - sp48.x; - if (dx < 0.0f) { - dx = -dx; + distances[i] = -100.0f; + } else if (type == 1 || type == 2) { + HSD_LObjGetPosition(lobj, &pos1); + dx = player_pos.x - pos1.x; + dy = player_pos.y - pos1.y; + { + f32 dx2 = dx * dx; + f32 dy2 = dy * dy; + distances[i] = sqrtf(dx2 + dy2); } - light_distances[i] = dx; + } else if (type == 3) { + HSD_LObjGetPosition(lobj, &pos2); + distances[i] = ABS(player_pos.x - pos2.x); } else { HSD_ASSERT(0x1C5, 0); } - if (light_distances[i] < 10.0f) { - light_distances[i] = 10.0f; + + if (distances[i] < 10.0f) { + distances[i] = 10.0f; } - light_order[i] = i; + sorted[i] = i; + i += 1; } - for (i = 0; i < gp->u.pushon.count; i++) { - f32 best = 3.4028235e38f; - s32 best_j = 0; - s32 tmp; - for (j = i; j < gp->u.pushon.count; j++) { - f32 d = light_distances[light_order[j]]; - if (best > d) { - best_j = j; - best = d; + /* Selection sort by distance */ + for (i = 0; i < (int) gp->u.pushon.count; i++) { + count = gp->u.pushon.count; + min_dist = 3.4028235e38f; + best = 0; + for (j = i; j < count; j++) { + if (min_dist > distances[sorted[j]]) { + best = j; + min_dist = distances[sorted[j]]; } } - tmp = light_order[i]; - light_order[i] = light_order[best_j]; - light_order[best_j] = tmp; + { + s32 tmp = sorted[i]; + sorted[i] = sorted[best]; + sorted[best] = tmp; + } } - for (i = 0; i < gp->u.pushon.count; i++) { + /* Enable first 5 lights, disable rest */ + for (i = 0; i < (int) gp->u.pushon.count; i++) { if (i < 5) { - HSD_LObjClearFlags(gp->u.pushon.lobjs[light_order[i]], 0x20); + HSD_LObjClearFlags(gp->u.pushon.lobjs[sorted[i]], 0x20); } else { - HSD_LObjSetFlags(gp->u.pushon.lobjs[light_order[i]], 0x20); + HSD_LObjSetFlags(gp->u.pushon.lobjs[sorted[i]], 0x20); } } - { - f32 mindist; - f32 sumsq; - sp3C = grPushOn_803B844C; - mindist = light_distances[light_order[1]]; - for (i = 1; i < gp->u.pushon.count; i++) { - if (HSD_LObjGetPosition(gp->u.pushon.lobjs[light_order[i]], - &sp100) != 0) - { - f32 w = mindist / light_distances[light_order[i]]; - lbVector_Sub(&sp100, &sp10C); - if (sp100.y < 100.0f) { - if (sp100.y < 0.0f) { - w = 0.0f; - } else { - w *= sp100.y / 100.0f; - } + /* Compute weighted direction */ + dir = grPushOn_803B844C; + ref_dist = distances[sorted[1]]; + + for (i = 1; i < (int) gp->u.pushon.count; i++) { + if (HSD_LObjGetPosition(gp->u.pushon.lobjs[sorted[i]], + &light_pos) != 0) + { + weight = ref_dist / distances[sorted[i]]; + lbVector_Sub(&light_pos, &player_pos); + if (light_pos.y < 100.0f) { + if (light_pos.y < 0.0f) { + weight = 0.0f; + } else { + weight *= light_pos.y / 100.0f; } - lbVector_Normalize(&sp100); - sp100.x *= w; - sp100.y *= w; - sp100.z *= w; - lbVector_Add(&sp3C, &sp100); } + lbVector_Normalize(&light_pos); + light_pos.x *= weight; + light_pos.y *= weight; + light_pos.z *= weight; + lbVector_Add(&dir, &light_pos); } - sumsq = sqrtf(sumsq = (sp3C.z * sp3C.z) + - ((sp3C.x * sp3C.x) + (sp3C.y * sp3C.y))); - if (sumsq < 0.01f) { - sp3C.y = 100.0f; - } - lbVector_Normalize(&sp3C); - sp3C.x *= 20.0f; - sp3C.y *= 20.0f; - sp3C.z *= 20.0f; - lbVector_Add(&sp3C, &sp10C); - HSD_LObjSetPosition(gp->u.pushon.point_light, &sp3C); - HSD_LObjSetInterest(gp->u.pushon.point_light, &sp10C); - HSD_LObjSetFlags(gp->u.pushon.point_light, 0x400); + } - { - f32 diff = light_distances[light_order[2]] - - light_distances[light_order[1]]; - HSD_LObjGetColor(gp->u.pushon.lobjs[light_order[1]], &sp38); - if (diff < 50.0f) { - f32 t = diff / 50.0f; - sp38.r = (s8) ((f32) (u8) sp38.r * t); - sp38.g = (u8) (s32) ((f32) sp38.g * t); - sp38.b = (u8) (s32) ((f32) sp38.b * t); - } - HSD_LObjSetColor(gp->u.pushon.spot_light, sp38); - if (HSD_LObjGetPosition(gp->u.pushon.lobjs[light_order[1]], - &sp2C) == 0) - { - sp2C.z = 0.0f; - sp2C.y = 0.0f; - sp2C.x = 0.0f; - } - HSD_LObjSetPosition(gp->u.pushon.spot_light, &sp2C); - if (HSD_LObjGetInterest(gp->u.pushon.lobjs[light_order[1]], - &sp2C) == 0) - { - sp2C.z = 0.0f; - sp2C.y = 0.0f; - sp2C.x = 0.0f; - } - HSD_LObjSetInterest(gp->u.pushon.spot_light, &sp2C); - gp->u.pushon.spot_light->flags = - gp->u.pushon.lobjs[light_order[1]]->flags; - gp->u.pushon.spot_light->flags &= ~4; - gp->u.pushon.spot_light->flags |= 8; + /* Compute magnitude and normalize direction */ + dist_sq = sqrtf(dir.z * dir.z + (dir.x * dir.x + dir.y * dir.y)); + if (dist_sq < 0.01f) { + dir.y = 100.0f; + } + lbVector_Normalize(&dir); + dir.x *= 20.0f; + dir.y *= 20.0f; + dir.z *= 20.0f; + lbVector_Add(&dir, &player_pos); + + /* Set spotlight */ + HSD_LObjSetPosition(gp->u.pushon.point_light, &dir); + HSD_LObjSetInterest(gp->u.pushon.point_light, &player_pos); + HSD_LObjSetFlags(gp->u.pushon.point_light, 0x400); + + /* Color from 2nd nearest */ + { + f32 dist_diff; + PAD_STACK(4); + dist_diff = distances[sorted[2]] - distances[sorted[1]]; + HSD_LObjGetColor(gp->u.pushon.lobjs[sorted[1]], &color); + if (distances[sorted[2]] - distances[sorted[1]] < 50.0f) { + f32 ratio = dist_diff / 50.0f; + color.r = color.r * ratio; + color.g = color.g * ratio; + color.b = color.b * ratio; } } + HSD_LObjSetColor(gp->u.pushon.spot_light, color); + + /* Copy position from 2nd nearest */ + if (HSD_LObjGetPosition(gp->u.pushon.lobjs[sorted[1]], &temp_pos) == 0) + { + temp_pos.z = 0.0f; + temp_pos.y = 0.0f; + temp_pos.x = 0.0f; + } + HSD_LObjSetPosition(gp->u.pushon.spot_light, &temp_pos); + + /* Copy interest from 2nd nearest */ + if (HSD_LObjGetInterest(gp->u.pushon.lobjs[sorted[1]], &temp_pos) == 0) + { + temp_pos.z = 0.0f; + temp_pos.y = 0.0f; + temp_pos.x = 0.0f; + } + HSD_LObjSetInterest(gp->u.pushon.spot_light, &temp_pos); + + /* Copy and modify flags */ + gp->u.pushon.spot_light->flags = gp->u.pushon.lobjs[sorted[1]]->flags; + gp->u.pushon.spot_light->flags &= ~4; + gp->u.pushon.spot_light->flags |= 8; } } diff --git a/src/melee/gr/grshrineroute.c b/src/melee/gr/grshrineroute.c index d71b1ca99b..7d308aa223 100644 --- a/src/melee/gr/grshrineroute.c +++ b/src/melee/gr/grshrineroute.c @@ -779,6 +779,11 @@ bool grShrineRoute_80209BE4(Ground_GObj* arg) return false; } +inline f32 grShrineRoute_8020A8A4_rand(void) +{ + return HSD_Randf(); +} + void grShrineRoute_80209BEC(Ground_GObj* gobj) { Ground* gp = GET_GROUND(gobj); @@ -1096,11 +1101,6 @@ void grShrineRoute_8020A89C(Ground_GObj* arg) {} void grShrineRoute_8020A8A0(Ground_GObj* arg) {} -inline f32 grShrineRoute_8020A8A4_rand(void) -{ - return HSD_Randf(); -} - void grShrineRoute_8020A8A4(Ground_GObj* gobj) { Ground* gp = gobj->user_data; @@ -1266,8 +1266,8 @@ s32 grShrineRoute_8020AE08(HSD_GObj* gobj, HSD_GObj* player_gobj, s32* out) void grShrineRoute_8020AF38(HSD_GObj* gobj, s32 arg1) { Ground* gp = GET_GROUND(gobj); - HSD_GObj* pgobj; HSD_GObj** symbolp; + HSD_GObj* pgobj; HSD_JObj* jobj; f32 scale; s32 ix = arg1 - 0xBD; @@ -1276,10 +1276,10 @@ void grShrineRoute_8020AF38(HSD_GObj* gobj, s32 arg1) pgobj = Ground_801C57A4(); if (gp->gv.shrineroute.symbols[ix] != NULL) { - symbolp = gp->gv.shrineroute.symbols + ix; + symbolp = gp->gv.shrineroute.symbols; + symbolp += ix; scale = 0.7f; - if (((Ground*) gp->gv.shrineroute.symbols[ix]->user_data)->map_id == 1) - { + if (((Ground*) (*symbolp)->user_data)->map_id == 1) { scale *= grSh_Route_804D6A58->x14; } else { scale *= grSh_Route_804D6A58->x18; diff --git a/src/melee/gr/grvenom.c b/src/melee/gr/grvenom.c index a11d5a67f5..1cc5ff2ea0 100644 --- a/src/melee/gr/grvenom.c +++ b/src/melee/gr/grvenom.c @@ -25,6 +25,61 @@ #include #include #include +#include "MSL/math.h" + +static void sdata2_order(void) +{ + (void) -1.0f; + (void) 1.0f; + (void) 0.0f; + (void) 1.04719758f; + (void) -100000.0f; + (void) 10000.0f; + (void) 100000.0f; + (void) 1000.0f; + (void) -60000.0f; + (void) 0.0; + (void) 1033.0f; + (void) 1086.0f; + (void) 1185.0f; + (void) 1238.0f; + (void) 1063.0f; + (void) 1116.0f; + (void) 1215.0f; + (void) 1268.0f; + (void) 2460.0f; + (void) 6440.0f; + (void) 9330.0f; + (void) 2747.0f; + (void) 3030.0f; + (void) 3393.0f; + (void) 3727.0f; + (void) 6880.0f; + (void) 9600.0f; + (void) 9835.0f; + (void) 4070.0f; + (void) 7220.0f; + (void) 4200.0f; + (void) 3800.0f; + (void) 4400.0f; + (void) 6100.0f; + (void) 7210.0f; + (void) 6810.0f; + (void) 7410.0f; + (void) 9200.0f; + (void) 0.0f; + (void) -0.134765625f; + (void) 1.45533512e+28f; + (void) 1.6866933e+28f; + (void) 50.0f; + (void) 6.2831853071795862; + (void) -3.1415926535897931; + (void) 3.1415926535897931; + (void) 20.0f; + (void) -100.0f; + (void) -2000.0f; + (void) 5.0f; +} /// Forward declaration of grVe_Data for use by multiple functions /// @todo This struct should be defined in gr/types.h or a proper header @@ -38,7 +93,148 @@ typedef struct grVe_Data { char x2BC[0x30]; } grVe_Data; -extern grVe_Data grVe_803E5348; +/// Collision link points consumed via #StageData.x2C (see +/// #Ground_801C2FE0): each entry is (coll line, map id, unused). +/// Data ownership: retail .data of this TU starts here (0x803E5348); +/// tail entries are the zero padding observed in the reference object. +static S16Vec3 grVe_CollLinks[9] = { + { 0, 5, 0 }, { 1, 5, 0 }, { 2, 9, 0 }, { 4, 10, 0 }, { 3, 13, 0 }, +}; + +/// Per-Arwing group indices into #grVe_ArwingJoints (cf. Corneria's +/// grCn_803E1D68.arwing_group). +static int grVe_ArwingGroups[3] = { 0 }; + +StageCallbacks grVe_Callbacks[16] = { + { + grVenom_80203F98, + grVenom_80203FC4, + grVenom_80203FCC, + grVenom_80203FD0, + 0, + }, + { + grVenom_80206B94, + grVenom_80206BBC, + grVenom_80206BC4, + grVenom_80206BEC, + 0x20000000, + }, + { + grVenom_80204F20, + grVenom_802052D8, + grVenom_802053B0, + grVenom_802056AC, + 0, + }, + { + grVenom_80205AD4, + grVenom_80205DF0, + grVenom_80205F30, + grVenom_80206870, + 0, + }, + { + grVenom_80203FD4, + grVenom_802040A4, + grVenom_802040AC, + grVenom_802040B0, + 0, + }, + { + grVenom_802040F0, + grVenom_8020427C, + grVenom_80204284, + grVenom_80204424, + 0xC0000000, + }, + { + grVenom_80206874, + grVenom_80206B68, + grVenom_80206B70, + grVenom_80206B90, + 0, + }, + { + grVenom_80204428, + grVenom_80204544, + grVenom_8020454C, + grVenom_80204B84, + 0, + }, + { + grVenom_80204CE0, + grVenom_80204CE4, + grVenom_80204CEC, + grVenom_80204DB0, + 0, + }, + { + grVenom_80204DD4, + grVenom_80204EF4, + grVenom_80204EFC, + grVenom_80204F1C, + 0, + }, + { + grVenom_802056B0, + grVenom_80205750, + grVenom_80205758, + grVenom_80205AD0, + 0, + }, + { + grVenom_802056B0, + grVenom_80205750, + grVenom_80205758, + grVenom_80205AD0, + 0, + }, + { + grVenom_802056B0, + grVenom_80205750, + grVenom_80205758, + grVenom_80205AD0, + 0, + }, + { + grVenom_802056B0, + grVenom_80205750, + grVenom_80205758, + grVenom_80205AD0, + 0, + }, + { + grVenom_802056B0, + grVenom_80205750, + grVenom_80205758, + grVenom_80205AD0, + 0, + }, + { + grVenom_802056B0, + grVenom_80205750, + grVenom_80205758, + grVenom_80205AD0, + 0, + }, +}; + +StageData grVe_StageData = { + VENOM, + grVe_Callbacks, + "/GrVe", + grVenom_80203B18, + grVenom_80203B14, + grVenom_80203DD0, + grVenom_80203E80, + grVenom_80203EA4, + grVenom_80206D74, + grVenom_80206D7C, + 0x00000001, + grVe_CollLinks, + 5, +}; /// @todo Move these local structs to proper headers typedef struct grVe_ExtData { @@ -46,9 +242,11 @@ typedef struct grVe_ExtData { void* x20[3]; s32 x2C[3]; s32 x38[3]; + char pad44[0x338 - 0x44]; + s32 x338[5]; } grVe_ExtData; -#define VE_DATA ((grVe_ExtData*) &grVe_803E5348) +#define VE_DATA ((grVe_ExtData*) &grVe_CollLinks) typedef struct grVe_TimingData { f32 x0; @@ -81,6 +279,11 @@ typedef struct grVe_GroundData { /// grVenom_8020362C +static inline s32* grVe_GetArwingTypes(grVe_ExtData* ext) +{ + return ext->x2C; +} + void grVenom_8020362C(void) { grVe_ExtData* ext = VE_DATA; @@ -88,7 +291,7 @@ void grVenom_8020362C(void) s32 j; s32 idx; s32 spawn; - u32 ground_flags; + u8 ground_flags; s32 i; s32 group_b; s32 mode; @@ -131,35 +334,33 @@ void grVenom_8020362C(void) combined = group_b | group_a; if (combined != 2) { if (combined < 2) { - if (combined == 0) { - { - s32* x2c_base = ext->x2C; - x2c_ptr = &x2c_base[0]; - } - idx = ext->x2C[0]; - while (idx == *x2c_ptr) { - idx = HSD_Randi(0xB) + 1; - } - x38_ptr = &ext->x38[0]; - if (ext->x38[0] == 4) { - mode = 1; - } else { - mode = - (HSD_Randf() > grVe_804D6A30->x10) ? 1 : 4; - } - grVe_804D6A34 = 0; - *x2c_ptr = idx; - *x38_ptr = mode; - ext->x20[grVe_804D6A34] = grVenom_80203EAC(2); - } else { + if (combined != 0) { return; } + { + s32* x2c_base = grVe_GetArwingTypes(ext); + x2c_ptr = &x2c_base[0]; + } + idx = *x2c_ptr; + while (idx == *x2c_ptr) { + idx = HSD_Randi(0xB) + 1; + } + x38_ptr = &ext->x38[0]; + if (*x38_ptr == 4) { + mode = 1; + } else { + mode = (HSD_Randf() > grVe_804D6A30->x10) ? 1 : 4; + } + grVe_804D6A34 = 0; + *x2c_ptr = idx; + *x38_ptr = mode; + ext->x20[grVe_804D6A34] = grVenom_80203EAC(2); return; } return; } x2c_ptr = &ext->x2C[0]; - idx = ext->x2C[0]; + idx = *x2c_ptr; while (idx == *x2c_ptr) { idx = HSD_Randi(4) + 1; } @@ -167,7 +368,7 @@ void grVenom_8020362C(void) s32* x38_base = &ext->x38[0]; x38_ptr = x38_base; } - if (ext->x38[0] == 4) { + if (*x38_ptr == 4) { mode = 1; } else if (HSD_Randf() > grVe_804D6A30->x10) { mode = 1; @@ -225,12 +426,17 @@ void grVenom_8020362C(void) if (grVe_804D6A38 <= 0) { has_active = 0; x2c_ptr = &ext->x2C[0]; - x20_ptr = &ext->x20[0]; for (j = 0; j < 3; j++) { if (j != i) { - if (x2c_ptr[j] < 8) { - if (x2c_ptr[j] < 1) { - } else if (x20_ptr[j] != NULL) { + switch (x2c_ptr[j]) { + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + if (x20_ptr[j] != NULL) { has_active = 1; } } @@ -316,7 +522,7 @@ void grVenom_80203B18(void) HSD_LObj* next; PAD_STACK(0xC); - data = (s32*) &grVe_803E5348; + data = (s32*) &grVe_CollLinks; grVe_804D6A30 = Ground_801C49F8(); grVenom_80203EAC(4); stage_info.unk8C.b4 = 0; @@ -441,7 +647,7 @@ Ground_GObj* grVenom_80203EAC(int gobj_id) { Ground_GObj* gobj; Ground* gp; - grVe_Data* base = &grVe_803E5348; + grVe_Data* base = (grVe_Data*) &grVe_CollLinks; StageCallbacks* callbacks = &((StageCallbacks*) ((char*) base + 0x44))[gobj_id]; @@ -462,12 +668,22 @@ Ground_GObj* grVenom_80203EAC(int gobj_id) HSD_GObj_SetupProc(gobj, callbacks->callback2, 4); } } else { - OSReport(&base->x1B8_file[0], &base->x1DC_func[0], 0x23B, gobj_id); + OSReport("%s:%d: couldn t get gobj(id=%d)\n", "grvenom.c", 0x23B, + gobj_id); } return gobj; } +/// Per-state map animation ids, read via the stage data base pointer +/// (`base[state + 0x7A]`, see #grVenom_802053B0); trailing entries are +/// the zero/3/6 words observed in the reference object. +static int grVe_AnimIds[53] = { + -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 6, +}; + void grVenom_80203F98(Ground_GObj* gobj) { Ground* gp = GET_GROUND(gobj); @@ -680,154 +896,180 @@ extern f32 grVe_804DB7B4; // 7220 void grVenom_8020454C(Ground_GObj* gobj) { - Vec3 sp1C; - s32 visible; - Ground* gp; - s32 i; - Ground* gp_save; - HSD_GObj* lgobj; - HSD_LObj* lobj; - HSD_LObj* next; - f32 frame; - f32 hi; - f32 lo; - PAD_STACK(8); + PAD_STACK(4); + { + Vec3 sp1C; + s32 visible; + Ground* gp; + s32 i; + Ground* gp_save; + HSD_GObj* lgobj; + HSD_LObj* lobj; + HSD_LObj* next; + f32 frame; + f32 hi; + f32 lo; + PAD_STACK(4); - i = 0; - gp_save = (gp = GET_GROUND(gobj)); - lo = grVe_804DB754; - hi = grVe_804DB758; - - do { - if (gp->gv.venom2.xC4 != NULL) { - lb_8000B1CC(gp->gv.venom2.xC4, NULL, &sp1C); - visible = 1; - if (!(sp1C.z < lo) && !(sp1C.z > hi)) { - visible = 0; - } - if (HSD_JObjGetFlags(gp->gv.venom2.xC4) & 0x10) { - if (visible != 0) { - HSD_JObjClearFlagsAll(gp->gv.venom2.xC4, JOBJ_HIDDEN); + i = 0; + gp_save = (gp = GET_GROUND(gobj)); + lo = grVe_804DB754; + hi = grVe_804DB758; + + do { + if (gp->gv.venom2.xC4 != NULL) { + lb_8000B1CC(gp->gv.venom2.xC4, NULL, &sp1C); + visible = 1; + if (!(sp1C.z < lo) && !(sp1C.z > hi)) { + visible = 0; } - } else if (visible == 0) { - HSD_JObjSetFlagsAll(gp->gv.venom2.xC4, JOBJ_HIDDEN); - } - } - i++; - gp = (Ground*) ((char*) gp + 4); - } while (i < 7); - gp = gp_save; - - if (grAnime_801C84A4((HSD_GObj*) gobj, 0, 7)) { - lgobj = Ground_801C498C(); - if (lgobj != NULL) { - if ((lobj = lgobj->hsd_obj) != NULL) { - while (lobj != NULL) { - if (lobj->aobj != NULL) { - HSD_AObjReqAnim(lobj->aobj, grVe_804DB740); + if (HSD_JObjGetFlags(gp->gv.venom2.xC4) & 0x10) { + if (visible != 0) { + HSD_JObjClearFlagsAll(gp->gv.venom2.xC4, JOBJ_HIDDEN); } - if (lobj->position != NULL) { - HSD_ForeachAnim(lobj->position, WOBJ_TYPE, - ALL_TYPE_MASK, HSD_AObjReqAnim, - AOBJ_ARG_AF, grVe_804DB760); - } - if (lobj->interest != NULL) { - HSD_ForeachAnim(lobj->interest, WOBJ_TYPE, - ALL_TYPE_MASK, HSD_AObjReqAnim, - AOBJ_ARG_AF, grVe_804DB760); - } - if (lobj == NULL) { - next = NULL; - } else { - next = lobj->next; + } else if (visible == 0) { + HSD_JObjSetFlagsAll(gp->gv.venom2.xC4, JOBJ_HIDDEN); + } + } + i++; + gp = (Ground*) ((char*) gp + 4); + } while (i < 7); + gp = gp_save; + + if (grAnime_801C84A4((HSD_GObj*) gobj, 0, 7)) { + lgobj = Ground_801C498C(); + if (lgobj != NULL) { + if ((lobj = lgobj->hsd_obj) != NULL) { + while (lobj != NULL) { + if (lobj->aobj != NULL) { + HSD_AObjReqAnim(lobj->aobj, grVe_804DB740); + } + if (lobj->position != NULL) { + HSD_ForeachAnim(lobj->position, WOBJ_TYPE, + ALL_TYPE_MASK, HSD_AObjReqAnim, + AOBJ_ARG_AF, grVe_804DB760); + } + if (lobj->interest != NULL) { + HSD_ForeachAnim(lobj->interest, WOBJ_TYPE, + ALL_TYPE_MASK, HSD_AObjReqAnim, + AOBJ_ARG_AF, grVe_804DB760); + } + if (lobj == NULL) { + next = NULL; + } else { + next = lobj->next; + } + lobj = next; } - lobj = next; } } } - } - { - HSD_AObj* a = grAnime_801C8318((HSD_GObj*) gobj, 0, 7); - if (a != NULL) { - frame = HSD_AObjGetCurrFrame(a); - if ((gp->gv.venom.xE4 < grVe_804DB768 && grVe_804DB768 <= frame) || - (gp->gv.venom.xE4 < grVe_804DB76C && grVe_804DB76C <= frame) || - (gp->gv.venom.xE4 < grVe_804DB770 && grVe_804DB770 <= frame) || - (gp->gv.venom.xE4 < grVe_804DB774 && grVe_804DB774 <= frame)) - { - Ground_801C53EC(0x6B6C5); - } - if ((gp->gv.venom.xE4 < grVe_804DB778 && grVe_804DB778 <= frame) || - (gp->gv.venom.xE4 < grVe_804DB77C && grVe_804DB77C <= frame) || - (gp->gv.venom.xE4 < grVe_804DB780 && grVe_804DB780 <= frame) || - (gp->gv.venom.xE4 < grVe_804DB784 && grVe_804DB784 <= frame)) - { - Ground_801C53EC(0x6B6C6); - } - if ((gp->gv.venom.xE4 < grVe_804DB788 && grVe_804DB788 <= frame) || - (gp->gv.venom.xE4 < grVe_804DB78C && grVe_804DB78C <= frame) || - (gp->gv.venom.xE4 < grVe_804DB790 && grVe_804DB790 <= frame)) - { - gp->gv.venom2.xE0_state.b6 = 1; - } - if ((gp->gv.venom.xE4 < grVe_804DB788 && grVe_804DB788 <= frame) || - (gp->gv.venom.xE4 < grVe_804DB794 && grVe_804DB794 <= frame) || - (gp->gv.venom.xE4 < grVe_804DB798 && grVe_804DB798 <= frame) || - (gp->gv.venom.xE4 < grVe_804DB79C && grVe_804DB79C <= frame) || - (gp->gv.venom.xE4 < grVe_804DB7A0 && grVe_804DB7A0 <= frame) || - (gp->gv.venom.xE4 < grVe_804DB78C && grVe_804DB78C <= frame) || - (gp->gv.venom.xE4 < grVe_804DB7A4 && grVe_804DB7A4 <= frame) || - (gp->gv.venom.xE4 < grVe_804DB790 && grVe_804DB790 <= frame) || - (gp->gv.venom.xE4 < grVe_804DB7A8 && grVe_804DB7A8 <= frame) || - (gp->gv.venom.xE4 < grVe_804DB7AC && grVe_804DB7AC <= frame)) - { - Ground_801C53EC(0x6B6C7); - } - if ((gp->gv.venom.xE4 < grVe_804DB7B0 && grVe_804DB7B0 <= frame) || - (gp->gv.venom.xE4 < grVe_804DB7B4 && grVe_804DB7B4 <= frame) || - (gp->gv.venom.xE4 > frame)) - { - gp->gv.venom2.xE0_state.b6 = 0; - } - if (gp->gv.venom.xE4 < 4200 && 4200 <= frame) { - gp->gv.venom2.xE0_state.b0 = 1; - } - if (gp->gv.venom.xE4 < 3800 && 3800 <= frame) { - gp->gv.venom2.xE0_state.b1 = 1; - } - if (gp->gv.venom.xE4 < 4400 && 4400 <= frame) { - Ground_801C5440(gp, 0, 0x6B6C4); - gp->gv.venom2.xE0_state.b2 = 1; - mpJointListAdd(2); - } - if (gp->gv.venom.xE4 < 6100 && 6100 <= frame) { - Ground_801C5440(gp, 0, 0x6B6C3); - gp->gv.venom2.xE0_state.b0 = 0; - gp->gv.venom2.xE0_state.b1 = 0; - gp->gv.venom2.xE0_state.b2 = 0; - mpLib_80057BC0(2); - } - if (gp->gv.venom.xE4 < 7210 && 7210 <= frame) { - gp->gv.venom2.xE0_state.b3 = 1; - } - if (gp->gv.venom.xE4 < 6810 && 6810 <= frame) { - gp->gv.venom2.xE0_state.b4 = 1; - } - if (gp->gv.venom.xE4 < 7410 && 7410 <= frame) { - gp->gv.venom2.xE0_state.b5 = 1; - } - if (gp->gv.venom.xE4 < 9200 && 9200 <= frame) { - gp->gv.venom2.xE0_state.b3 = 0; - gp->gv.venom2.xE0_state.b4 = 0; - gp->gv.venom2.xE0_state.b5 = 0; + { + HSD_AObj* a = grAnime_801C8318((HSD_GObj*) gobj, 0, 7); + if (a != NULL) { + frame = HSD_AObjGetCurrFrame(a); + if ((gp->gv.venom.xE4 < grVe_804DB768 && + grVe_804DB768 <= frame) || + (gp->gv.venom.xE4 < grVe_804DB76C && + grVe_804DB76C <= frame) || + (gp->gv.venom.xE4 < grVe_804DB770 && + grVe_804DB770 <= frame) || + (gp->gv.venom.xE4 < grVe_804DB774 && + grVe_804DB774 <= frame)) + { + Ground_801C53EC(0x6B6C5); + } + if ((gp->gv.venom.xE4 < grVe_804DB778 && + grVe_804DB778 <= frame) || + (gp->gv.venom.xE4 < grVe_804DB77C && + grVe_804DB77C <= frame) || + (gp->gv.venom.xE4 < grVe_804DB780 && + grVe_804DB780 <= frame) || + (gp->gv.venom.xE4 < grVe_804DB784 && + grVe_804DB784 <= frame)) + { + Ground_801C53EC(0x6B6C6); + } + if ((gp->gv.venom.xE4 < grVe_804DB788 && + grVe_804DB788 <= frame) || + (gp->gv.venom.xE4 < grVe_804DB78C && + grVe_804DB78C <= frame) || + (gp->gv.venom.xE4 < grVe_804DB790 && + grVe_804DB790 <= frame)) + { + gp->gv.venom2.xE0_state.b6 = 1; + } + if ((gp->gv.venom.xE4 < grVe_804DB788 && + grVe_804DB788 <= frame) || + (gp->gv.venom.xE4 < grVe_804DB794 && + grVe_804DB794 <= frame) || + (gp->gv.venom.xE4 < grVe_804DB798 && + grVe_804DB798 <= frame) || + (gp->gv.venom.xE4 < grVe_804DB79C && + grVe_804DB79C <= frame) || + (gp->gv.venom.xE4 < grVe_804DB7A0 && + grVe_804DB7A0 <= frame) || + (gp->gv.venom.xE4 < grVe_804DB78C && + grVe_804DB78C <= frame) || + (gp->gv.venom.xE4 < grVe_804DB7A4 && + grVe_804DB7A4 <= frame) || + (gp->gv.venom.xE4 < grVe_804DB790 && + grVe_804DB790 <= frame) || + (gp->gv.venom.xE4 < grVe_804DB7A8 && + grVe_804DB7A8 <= frame) || + (gp->gv.venom.xE4 < grVe_804DB7AC && + grVe_804DB7AC <= frame)) + { + Ground_801C53EC(0x6B6C7); + } + if ((gp->gv.venom.xE4 < grVe_804DB7B0 && + grVe_804DB7B0 <= frame) || + (gp->gv.venom.xE4 < grVe_804DB7B4 && + grVe_804DB7B4 <= frame) || + (gp->gv.venom.xE4 > frame)) + { + gp->gv.venom2.xE0_state.b6 = 0; + } + if (gp->gv.venom.xE4 < 4200 && 4200 <= frame) { + gp->gv.venom2.xE0_state.b0 = 1; + } + if (gp->gv.venom.xE4 < 3800 && 3800 <= frame) { + gp->gv.venom2.xE0_state.b1 = 1; + } + if (gp->gv.venom.xE4 < 4400 && 4400 <= frame) { + Ground_801C5440(gp, 0, 0x6B6C4); + gp->gv.venom2.xE0_state.b2 = 1; + mpJointListAdd(2); + } + if (gp->gv.venom.xE4 < 6100 && 6100 <= frame) { + Ground_801C5440(gp, 0, 0x6B6C3); + gp->gv.venom2.xE0_state.b0 = 0; + gp->gv.venom2.xE0_state.b1 = 0; + gp->gv.venom2.xE0_state.b2 = 0; + mpLib_80057BC0(2); + } + if (gp->gv.venom.xE4 < 7210 && 7210 <= frame) { + gp->gv.venom2.xE0_state.b3 = 1; + } + if (gp->gv.venom.xE4 < 6810 && 6810 <= frame) { + gp->gv.venom2.xE0_state.b4 = 1; + } + if (gp->gv.venom.xE4 < 7410 && 7410 <= frame) { + gp->gv.venom2.xE0_state.b5 = 1; + } + if (gp->gv.venom.xE4 < 9200 && 9200 <= frame) { + gp->gv.venom2.xE0_state.b3 = 0; + gp->gv.venom2.xE0_state.b4 = 0; + gp->gv.venom2.xE0_state.b5 = 0; + } + gp->gv.venom.xE4 = frame; } - gp->gv.venom.xE4 = frame; } - } - lbAudioAx_80024D78(!gp->gv.venom2.xE0_state.b2 ? 1 : 2); - grVenom_80204B88(gobj); + lbAudioAx_80024D78(!gp->gv.venom2.xE0_state.b2 ? 1 : 2); + grVenom_80204B88(gobj); + } } void grVenom_80204B84(Ground_GObj* arg) {} @@ -951,16 +1193,21 @@ bool grVenom_80204EF4(Ground_GObj* arg) return false; } -bool grVenom_80204EFC(Ground_GObj* arg) +void grVenom_80204EFC(Ground_GObj* arg) { - return Ground_801C2FE0(arg); + Ground_801C2FE0(arg); } void grVenom_80204F1C(Ground_GObj* arg) {} +/// Error message read through the stage data base pointer in +/// #grVenom_80204F20 (`base + 0x2BC`); sits between #grVe_AnimIds and +/// the TU's pooled assert strings in the reference object. +static char grVe_UserDataErrorMsg[] = "arwin:user data error\n"; + void grVenom_80204F20(Ground_GObj* arg0) { - s32* base = (s32*) &grVe_803E5348; + s32* base = (s32*) &grVe_CollLinks; Ground* gp = arg0->user_data; HSD_JObj* jobj = arg0->hsd_obj; u32 idx = grVe_804D6A34; @@ -1037,7 +1284,7 @@ void grVenom_802052E0(Ground_GObj* gobj, Vec3* pos) { u8* new_var2; Vec3 jobj_pos; - s32* spawn_table = (s32*) &grVe_803E5348; + s32* spawn_table = (s32*) &grVe_CollLinks; Ground* gp; HSD_JObj* jobj; s32* new_var; @@ -1068,9 +1315,6 @@ void grVenom_802052E0(Ground_GObj* gobj, Vec3* pos) } /// grVenom_802053B0 -/// @todo Currently 99.95% match - data relocation ownership remains - -extern f32 grVe_804DB740; void grVenom_802053B0(Ground_GObj* gobj) { @@ -1085,7 +1329,7 @@ void grVenom_802053B0(Ground_GObj* gobj) PAD_STACK(0x10); gp = gobj->user_data; - base = (s32*) &grVe_803E5348; + base = (s32*) &grVe_CollLinks; jobj = gobj->hsd_obj; ptr = base + gp->gv.venom.xC8; @@ -1124,20 +1368,20 @@ void grVenom_802053B0(Ground_GObj* gobj) break; case 1: if (grVenom_80205E84(&sp28) == 0) { - gp->gv.venom.xD8 = 2; + *(s32*) &gp->gv.venom.xD8 = 2; } break; case 2: if (grVenom_80205E84(&sp28) == 1) { lbAudioAx_800237A8(0x6B6C2, 0x7F, 0x40); - gp->gv.venom.xD8 = 3; + *(s32*) &gp->gv.venom.xD8 = 3; } break; } goto type_done; far_type: - HSD_JObjSetRotationY(jobj, grVe_804DB740); + HSD_JObjSetRotationY(jobj, 0.0F); gp2 = gobj->user_data; grVenom_802052E0(gobj, &sp1C); @@ -1151,13 +1395,13 @@ void grVenom_802053B0(Ground_GObj* gobj) break; case 1: if (grVenom_80205E84(&sp1C) == 0) { - gp2->gv.venom.xD8 = 2; + *(s32*) &gp2->gv.venom.xD8 = 2; } break; case 2: if (grVenom_80205E84(&sp1C) == 1) { lbAudioAx_800237A8(0x6B6C2, 0x7F, 0x40); - gp2->gv.venom.xD8 = 3; + *(s32*) &gp2->gv.venom.xD8 = 3; } break; } @@ -1174,10 +1418,17 @@ void grVenom_802053B0(Ground_GObj* gobj) void grVenom_802056AC(Ground_GObj* arg) {} +/// Per-state animation ids (cf. Corneria's grCn_803E214C). +static int grVe_StateAnims[10] = { -1, -1, 1, 0, 2, 2, 4, 4, 5, 5 }; + +/// Per-group map animation ids (cf. Corneria's grCn_803E217C). +static int grVe_MapAnims[5] = { 0x0A, 0x0A, 0x0B, 0x0C, 0x0D }; + +/// Joint id per Arwing group (cf. Corneria's grCn_803E2190). +static int grVe_ArwingJoints[5] = { 4, 4, 4, 4, 3 }; + /// grVenom_802056B0 -extern int grVe_803E5380[]; -extern int grVe_803E5680[]; extern u32 grVe_804D6A34; void grVenom_802056B0(Ground_GObj* gobj) @@ -1191,8 +1442,8 @@ void grVenom_802056B0(Ground_GObj* gobj) Ground_801C2ED0(jobj, gp->map_id); gp->gv.venom.xC8 = grVe_804D6A34; - joint_idx = grVe_803E5380; - joints = grVe_803E5680; + joint_idx = grVe_ArwingGroups; + joints = grVe_ArwingJoints; gp->gv.venom.xD0 = 0; gp->gv.venom.xDC = 0.0F; gp->gv.venom.xE8 = 0.0F; @@ -1219,20 +1470,13 @@ extern f64 grVe_804DB800; void grVenom_80205758(Ground_GObj* gobj) { - Ground* gp = gobj->user_data; - s32* base = (s32*) &grVe_803E5348; - HSD_JObj* jobj = gobj->hsd_obj; - s32* entry = base + gp->gv.venom.xC8; - f32 v; - f32 scale; - PAD_STACK(8); + grVe_ExtData* data = VE_DATA; + Ground* gp = GET_GROUND(gobj); + HSD_JObj* jobj = GET_JOBJ(gobj); - if ((u32) entry[8] != 0U) { - v = gp->gv.venom.xE8; - if (v < 0.0F) { - v = -v; - } - if (v < grVe_804DB7E8) { + if (data->x20[gp->gv.venom.xC8] != NULL) { + f32 angle = ABS(gp->gv.venom.xE8); + if (angle < grVe_804DB7E8) { gp->gv.venom.xE8 = 0.0F; while (gp->gv.venom.xDC < grVe_804DB7F8) { gp->gv.venom.xDC += grVe_804DB7F0; @@ -1240,11 +1484,7 @@ void grVenom_80205758(Ground_GObj* gobj) while (gp->gv.venom.xDC > grVe_804DB800) { gp->gv.venom.xDC -= grVe_804DB7F0; } - v = gp->gv.venom.xDC; - if (v < 0.0F) { - v = -v; - } - if (v < grVe_804DB744) { + if (ABS(gp->gv.venom.xDC) < grVe_804DB744) { HSD_JObjClearFlagsAll(jobj, JOBJ_HIDDEN); } else { HSD_JObjSetFlagsAll(jobj, JOBJ_HIDDEN); @@ -1252,113 +1492,95 @@ void grVenom_80205758(Ground_GObj* gobj) } else { HSD_JObjSetFlagsAll(jobj, JOBJ_HIDDEN); } - HSD_JObjSetTranslate(jobj, (Vec3*) &gp->gv.venom.xE0); - - scale = Ground_801C0498(); - HSD_JObjSetScaleX(jobj, scale * grVe_804D6A30->x34); - HSD_JObjSetScaleY(jobj, scale * grVe_804D6A30->x34); - HSD_JObjSetScaleZ(jobj, scale * grVe_804D6A30->x34); - + { + f32 scale = Ground_801C0498(); + { + f32 s = scale * grVe_804D6A30->x34; + HSD_JObjSetScaleX(jobj, s); + } + { + f32 s = scale * grVe_804D6A30->x34; + HSD_JObjSetScaleY(jobj, s); + } + { + f32 s = scale * grVe_804D6A30->x34; + HSD_JObjSetScaleZ(jobj, s); + } + } Ground_801C2FE0(gobj); } else { - mpLib_80057BC0(base[entry[14] + 0xCE]); + mpLib_80057BC0(data->x338[data->x38[gp->gv.venom.xC8]]); Ground_801C4A08(gobj); } } +/// Per-group animation flags (cf. Corneria's grCn_803E21B0); the +/// trailing zero word is present in the reference object. +static int grVe_AnimFlags[6] = { 1, 1, 1, 1, 1, 0 }; + void grVenom_80205AD0(Ground_GObj* arg) {} /// grVenom_80205AD4 -/// @todo Currently 98.62% match - needs register allocation fixes void grVenom_80205AD4(Ground_GObj* gobj) { - s32 zero; - s32* base; - Ground* gp; - HSD_JObj* jobj; + s32* data = (s32*) &grVe_CollLinks; + Ground* gp = gobj->user_data; + HSD_JObj* jobj = GET_JOBJ(gobj); f32 scale; - s32* data; - s32 type; - Ground_GObj* other; - Ground* other_gp; - HSD_JObj* jobj2; - grVe_TimingData* attr; - zero = 0; - gp = gobj->user_data; - jobj = gobj->hsd_obj; - base = (s32*) &grVe_803E5348; scale = Ground_801C0498(); - gp->gv.venom.xC8 = grVe_804D6A34; - *(s32*) &gp->gv.venom.xEC = zero; - *(s32*) &gp->gv.venom.xE8 = zero; - *(s32*) &gp->gv.venom.xE4 = zero; - *(s32*) &gp->gv.venom.xE0 = zero; - + *(s32*) &gp->gv.venom.xEC = 0; + *(s32*) &gp->gv.venom.xE8 = 0; + *(s32*) &gp->gv.venom.xE4 = 0; + *(s32*) &gp->gv.venom.xE0 = 0; grAnime_801C7FF8(gobj, 7, 7, 0, 0.0F, 1.0F); grAnime_801C7FF8(gobj, 8, 7, 0, 0.0F, 1.0F); grAnime_801C8098(gobj, 2, 7, 3, 0.0F, 1.0F); - data = base + gp->gv.venom.xC8; - type = data[11]; - - if (type < 8) { - if (type >= 1) { - goto venom_80205AD4_spawn; + switch (data[gp->gv.venom.xC8 + 11]) { + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: { + HSD_GObj* other = + grVenom_80203EAC(data[data[gp->gv.venom.xC8 + 14] + 0xC9]); + gp->gv.venom.linked_gobj = other; + if (other != NULL) { + Ground* other_gp = GET_GROUND(gp->gv.venom.linked_gobj); + if (other_gp != NULL) { + other_gp->gv.venom.xC8 = gp->gv.venom.xC8; + } } - goto venom_80205AD4_default; - } - if (type >= 0xC) { - goto venom_80205AD4_default; + break; } - goto venom_80205AD4_link; - -venom_80205AD4_spawn: { - s32 idx = data[14]; - s32* data2 = base + idx; - other = (Ground_GObj*) grVenom_80203EAC(data2[0xC9]); - gp->gv.venom.linked_gobj = other; - if (other != NULL) { - other = gp->gv.venom.linked_gobj; - other_gp = other->user_data; - if (other_gp != NULL) { - other_gp->gv.venom.xC8 = gp->gv.venom.xC8; - } + case 8: + case 9: + case 10: + case 11: + lb_8000C2F8( + Ground_801C3FA4(gobj, 0), + Ground_801C3FA4((HSD_GObj*) data[gp->gv.venom.xC8 + 8], 5)); + gp->gv.venom.linked_gobj = NULL; + break; + default: + *(s32*) &gp->gv.venom.xE0 = -1; + *(s32*) &gp->gv.venom.xE4 = -1; + break; } - goto venom_80205AD4_done; -} - -venom_80205AD4_link: - jobj2 = Ground_801C3FA4((HSD_GObj*) data[8], 5); - lb_8000C2F8(Ground_801C3FA4(gobj, 0), jobj2); - gp->gv.venom.linked_gobj = NULL; - goto venom_80205AD4_done; - -venom_80205AD4_default: - *(s32*) &gp->gv.venom.xE0 = -1; - *(s32*) &gp->gv.venom.xE4 = -1; - -venom_80205AD4_done: - - attr = grVe_804D6A30; - HSD_JObjSetScaleX(jobj, scale * attr->x34); - - attr = grVe_804D6A30; - HSD_JObjSetScaleY(jobj, scale * attr->x34); - - attr = grVe_804D6A30; - HSD_JObjSetScaleZ(jobj, scale * attr->x34); - + HSD_JObjSetScaleX(jobj, scale * grVe_804D6A30->x34); + HSD_JObjSetScaleY(jobj, scale * grVe_804D6A30->x34); + HSD_JObjSetScaleZ(jobj, scale * grVe_804D6A30->x34); gp->gv.venom.xC4_flags.b0 = false; - *(s32*) &gp->gv.venom.xD4 = zero; - gp->gv.venom.xF0 = zero; - gp->gv.venom.xF4 = zero; - - attr = grVe_804D6A30; - gp->gv.venom.xF8 = (s32) attr->x2C; - gp->gv.venom.xFC = zero; + *(s32*) &gp->gv.venom.xD4 = 0; + gp->gv.venom.xF0 = 0; + gp->gv.venom.xF4 = 0; + gp->gv.venom.xF8 = (s32) grVe_804D6A30->x2C; + gp->gv.venom.xFC = 0; gp->gv.venom.x100 = HSD_Randi(2); } @@ -1416,7 +1638,6 @@ extern Vec3 grVe_803B82DC; void grVenom_80205F30(Ground_GObj* gobj) { - u8 padA0[8]; Vec3 sp94; Vec3 sp88; u8 pad70[0x18]; @@ -1437,12 +1658,12 @@ void grVenom_80205F30(Ground_GObj* gobj) s32 type_idx; HSD_JObj* helper; - base = (s32*) &grVe_803E5348; + base = (s32*) &grVe_CollLinks; gp = gobj->user_data; jobj = gobj->hsd_obj; sp94 = grVe_803B82D0; sp88 = grVe_803B82DC; - PAD_STACK(0x28); + PAD_STACK(0x20); if (grVe_804D6A3C != 0) { return; @@ -1456,7 +1677,14 @@ void grVenom_80205F30(Ground_GObj* gobj) } state = base[gp->gv.venom.xC8 + 11]; - if (state >= 1 && state < 8) { + switch (state) { + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: HSD_JObjSetRotationY(jobj, 0.0F); { @@ -1559,7 +1787,11 @@ void grVenom_80205F30(Ground_GObj* gobj) } } } - } else if (state >= 8 && state < 0xC) { + break; + case 8: + case 9: + case 10: + case 11: if (!(gp->gv.venom.xF0 & 7) && HSD_Randi(8) == 0) { gp->gv.venom.xFC = 0; type_idx = base[gp->gv.venom.xC8 + 11]; @@ -1665,6 +1897,7 @@ void grVenom_80205F30(Ground_GObj* gobj) 0); } } + break; } gp->gv.venom.xF0 = gp->gv.venom.xF0 + 1; @@ -1693,7 +1926,7 @@ void grVenom_80206870(Ground_GObj* arg) {} /// @todo Currently 99.60% match - needs register allocation fixes void grVenom_80206874(Ground_GObj* gobj) { - s32* data = (s32*) &grVe_803E5348; + s32* data = (s32*) &grVe_CollLinks; Ground* gp = gobj->user_data; HSD_JObj* jobj = gobj->hsd_obj; f32 scale; @@ -1858,7 +2091,7 @@ DynamicsDesc* grVenom_80206D74(enum_t arg) return false; } -bool grVenom_80206D7C(Vec3* pos, s32 arg1, HSD_JObj* arg2) +bool grVenom_80206D7C(Vec3* pos, int arg1, HSD_JObj* arg2) { Vec3 sp20; Vec3 sp14; diff --git a/src/melee/gr/grvenom.h b/src/melee/gr/grvenom.h index 329a0d2878..0ec7118193 100644 --- a/src/melee/gr/grvenom.h +++ b/src/melee/gr/grvenom.h @@ -36,7 +36,7 @@ /* 204DB0 */ void grVenom_80204DB0(Ground_GObj*); /* 204DD4 */ void grVenom_80204DD4(Ground_GObj*); /* 204EF4 */ bool grVenom_80204EF4(Ground_GObj*); -/* 204EFC */ bool grVenom_80204EFC(Ground_GObj*); +/* 204EFC */ void grVenom_80204EFC(Ground_GObj*); /* 204F1C */ void grVenom_80204F1C(Ground_GObj*); /* 204F20 */ void grVenom_80204F20(Ground_GObj*); /* 2052D8 */ bool grVenom_802052D8(Ground_GObj*); @@ -65,6 +65,6 @@ /* 206CB0 */ void grVenom_80206CB0(s32); /* 206D10 */ s32 grVenom_80206D10(s32); /* 206D74 */ DynamicsDesc* grVenom_80206D74(enum_t); -/* 206D7C */ bool grVenom_80206D7C(Vec3*, s32, HSD_JObj*); +/* 206D7C */ bool grVenom_80206D7C(Vec3*, int, HSD_JObj*); #endif diff --git a/src/melee/gr/gryorster.c b/src/melee/gr/gryorster.c index 2ca7712e01..f91e4b7fdc 100644 --- a/src/melee/gr/gryorster.c +++ b/src/melee/gr/gryorster.c @@ -181,48 +181,62 @@ void grYorster_80202254(Ground_GObj* gobj) void grYorster_802022A0(HSD_GObj* gobj) {} -void grYorster_802022A4(HSD_GObj* gobj) +static inline void grYorster_InitTrackElements(Ground* gp, HSD_GObj* gobj) { s32 joints[9] = { 0xA, 0xB, 0xC, 0xD, 0xE, 0xF, 0x10, 0x11, 0x12 }; - Ground* temp_r28; int i; - temp_r28 = gobj->user_data; for (i = 0; i < 9; i++) { - temp_r28->gv.yorster.elements[i].x00 = (s8) i; - temp_r28->gv.yorster.elements[i].x01 = 0; - temp_r28->gv.yorster.elements[i].x04 = 0.0f; - temp_r28->gv.yorster.elements[i].x08 = 0.0f; - temp_r28->gv.yorster.elements[i].x14 = joints[i]; - temp_r28->gv.yorster.elements[i].x18 = - Ground_801C3FA4(gobj, joints[i]); - temp_r28->gv.yorster.elements[i].x1C = grMaterial_801C8CFC( - 0, 0, temp_r28, temp_r28->gv.yorster.elements[i].x18, NULL, - grYorster_80202428, NULL); - grMaterial_801C8E68(temp_r28->gv.yorster.elements[i].x1C, GA_Ground); - mpJointSetCb2(Ground_801C32D4(temp_r28->map_id, - temp_r28->gv.yorster.elements[i].x14), - temp_r28, grYorster_802024F0); - grMaterial_801C8DE0(temp_r28->gv.yorster.elements[i].x1C, 0.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 0.0f, 5.0f); - grMaterial_801C8E08(temp_r28->gv.yorster.elements[i].x1C); - grAnime_801C7FF8(gobj, temp_r28->gv.yorster.elements[i].x14, 7, 1, - 0.0f, 0.0f); + gp->gv.yorster.elements[i].x00 = (s8) i; + gp->gv.yorster.elements[i].x01 = 0; + gp->gv.yorster.elements[i].x04 = 0.0f; + gp->gv.yorster.elements[i].x08 = 0.0f; + gp->gv.yorster.elements[i].x14 = joints[i]; + gp->gv.yorster.elements[i].x18 = Ground_801C3FA4(gobj, joints[i]); + gp->gv.yorster.elements[i].x1C = + grMaterial_801C8CFC(0, 0, gp, gp->gv.yorster.elements[i].x18, NULL, + grYorster_80202428, NULL); + grMaterial_801C8E68(gp->gv.yorster.elements[i].x1C, GA_Ground); + mpJointSetCb2( + Ground_801C32D4(gp->map_id, gp->gv.yorster.elements[i].x14), gp, + grYorster_802024F0); + grMaterial_801C8DE0(gp->gv.yorster.elements[i].x1C, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 5.0f); + { + HSD_GObj* material_gobj = gp->gv.yorster.elements[i].x1C; + grMaterial_801C8E08(material_gobj); + } + grAnime_801C7FF8(gobj, gp->gv.yorster.elements[i].x14, 7, 1, 0.0f, + 0.0f); } } +static inline void grYorster_GetGround(HSD_GObj* gobj, Ground** gp) +{ + *gp = gobj->user_data; +} + +void grYorster_802022A4(HSD_GObj* gobj) +{ + Ground* gp; + + grYorster_GetGround(gobj, &gp); + grYorster_InitTrackElements(gp, gobj); +} + void grYorster_80202428(HSD_GObj* item_gobj, Ground* gp, Vec3* pos, HSD_GObj* fighter_gobj, f32 value) { + Ground* gp2 = (Ground*) ((s32) gp + 0); int i; if (ftLib_80086960(fighter_gobj)) { - ftLib_80086A4C(fighter_gobj, grYt_804D6A20.x0->x14); + ftLib_80086A4C(fighter_gobj, (f32) grYt_804D6A20.x0->x14); } for (i = 0; i < 9; i++) { - if (item_gobj == gp->gv.yorster.elements[i].x1C) { - gp->gv.yorster.elements[i].x04 += value; + if (item_gobj == gp2->gv.yorster.elements[i].x1C) { + gp2->gv.yorster.elements[i].x04 += value; break; } } @@ -275,9 +289,11 @@ void grYorster_802024F0(Ground* gp, s32 joint_id, CollData* coll_data, void grYorster_8020266C(HSD_GObj* gobj) { - Ground* gp = gobj->user_data; - Ground* gp2 = gp; + Ground* gp; + Ground* gp2; s32 i; + + gp2 = gp = gobj->user_data; PAD_STACK(8); for (i = 0; i < 9; i++) { @@ -361,10 +377,12 @@ void grYorster_8020266C(HSD_GObj* gobj) gp->gv.yorster.elements[i].x0C--; } break; - case 3: + case 3: { + Vec3 pos; + Vec3 unused; + if (gp->gv.yorster.elements[i].x0C >= 0x143) { - Vec3 pos; - HSD_JObjGetTranslation(gp2->gv.yorster.elements[i].x18, &pos); + HSD_JObjGetTranslation(gp->gv.yorster.elements[i].x18, &pos); if (grLib_801C9EE8(&pos, 10.0f * Ground_801C0498() - 2.0f)) { grAnime_801C7FF8(gobj, gp2->gv.yorster.elements[i].x14, 7, @@ -391,11 +409,10 @@ void grYorster_8020266C(HSD_GObj* gobj) 0 || gp->gv.yorster.elements[i].x0C >= 0x19) { - Vec3 pos; - gp->gv.yorster.elements[i].x0C = 0; - HSD_JObjGetTranslation(gp2->gv.yorster.elements[i].x18, &pos); - if (!grLib_801C9EE8(&pos, 10.0f * Ground_801C0498() * 0.5f)) { + HSD_JObjGetTranslation(gp->gv.yorster.elements[i].x18, &pos); + if (!grLib_801C9EE8(&pos, (10.0f * Ground_801C0498()) / 2.0f)) + { grAnime_801C7FF8(gobj, gp2->gv.yorster.elements[i].x14, 7, 1, 0.0f, 1.0f); mpJointListAdd(joint); @@ -408,6 +425,7 @@ void grYorster_8020266C(HSD_GObj* gobj) gp->gv.yorster.elements[i].x0C++; } break; + } default: break; } diff --git a/src/melee/gr/grzakogenerator.c b/src/melee/gr/grzakogenerator.c index 17c55c72e4..998f237fd8 100644 --- a/src/melee/gr/grzakogenerator.c +++ b/src/melee/gr/grzakogenerator.c @@ -259,7 +259,7 @@ void grZakoGenerator_801CAC14(HSD_GObj* gobj) if (kind == 0x9F) { grZakoGenerator_Entry* sentinel = &lbl_8049F030.x4->sentinel; - if (sentinel->x4 == gobj) { + if (sentinel != NULL && sentinel->x4 == gobj) { sentinel->x4 = NULL; } } else { @@ -279,11 +279,12 @@ void grZakoGenerator_801CACB8(Item_GObj* gobj) it_8027CE18(gobj); if (kind == 0x9F) { - grZakoGenerator_Data* data = lbl_8049F030.x4; + grZakoGenerator_Data** data_p = &lbl_8049F030.x4; + grZakoGenerator_Data* volatile data = *data_p; grZakoGenerator_Entry* sentinel = &data->sentinel; if (sentinel->x4 == gobj) { sentinel->x0 = -1; - data->sentinel.x4 = NULL; + (*data_p)->sentinel.x4 = NULL; } } else { s32 idx = ip->xDD4_itemVar.zako.idx; @@ -330,11 +331,16 @@ HSD_GObj* grZakoGenerator_801CAE04(grZakoGenerator_SpawnDesc* arg0) void grZakoGenerator_801CAEB0(int arg0, int arg1) { - s16 val = arg1; - if (lbl_8049F030.x4->sentinel.x0 == -1) { - lbl_8049F030.x4->sentinel.x0 = val; - lbl_8049F030.x4->sentinel.x8 = arg0; - lbl_8049F030.x4->sentinel.x4 = NULL; + grZakoGenerator_Data** data_p = &lbl_8049F030.x4; + s16 val; + grZakoGenerator_Entry* sentinel = &(*data_p)->sentinel; + arg1 = (s16) arg1; + val = arg1; + + if (sentinel->x0 == -1) { + sentinel->x0 = val; + sentinel->x8 = arg0; + (*data_p)->sentinel.x4 = NULL; } } diff --git a/src/melee/gr/grzebes.c b/src/melee/gr/grzebes.c index e397588aef..c6ce4be738 100644 --- a/src/melee/gr/grzebes.c +++ b/src/melee/gr/grzebes.c @@ -140,17 +140,32 @@ typedef struct grZe_BubbleEntry { /* 0x1C */ f32 x1C; /* 0x20 */ HSD_GObj* x20_gobj; } grZe_BubbleEntry; -; + +typedef struct grZe_BubbleSpawnPos { + /* 0x00 */ f32 pad_00[5]; + /* 0x14 */ f32 x14_x; + /* 0x18 */ f32 x18_y; + /* 0x1C */ f32 pad_1C[2]; +} grZe_BubbleSpawnPos; /* 8049F140 */ static Vec3 grZe_8049F140[2]; /* 8049F158 */ static Vec3 grZe_8049F158[2]; /* 8049F170 */ static grZe_BubbleEntry grZe_8049F170[20]; +typedef struct grZe_BubbleScales { + f32 values[7]; +} grZe_BubbleScales; + typedef struct grZe_BubbleConfig { - f32 x0_scales[7]; + grZe_BubbleScales x0_scales; Vec3 x4_positions[4]; } grZe_BubbleConfig; +typedef struct grZe_BubbleState { + Vec3 positions[4]; + grZe_BubbleEntry bubbles[20]; +} grZe_BubbleState; + typedef struct grZe_AcidState { /* +00 */ u8 x00_state; /* +01 */ u8 x01_next; @@ -379,10 +394,13 @@ void grZebes_801D881C(HSD_GObj* gobj) Vec3 sp1C; f32 sp18; f32 sp14; + HSD_GObj* secondary_gobj; + s32 popped; Ground* gp = GET_GROUND(gobj); - HSD_GObj* secondary_gobj = (HSD_GObj*) gp->gv.zebes5.xF0; - s32 result = grZebes_801DA528(gobj, &gp->gv.zebes5.xC8, 1, 2); - PAD_STACK(8); + s32 result; + secondary_gobj = (HSD_GObj*) gp->gv.zebes5.xF0; + result = grZebes_801DA528(gobj, &gp->gv.zebes5.xC8, 1, 2); + PAD_STACK(16); if ((s32) gp->gv.zebes5.xEC != result) { gp->gv.zebes5.xEC = result; @@ -396,21 +414,21 @@ void grZebes_801D881C(HSD_GObj* gobj) } { - s16 timer = (s16) gp->gv.zebes5.xF8; - gp->gv.zebes5.xF8 = (s16) (timer - 1); + s16 timer = *(s16*) &gp->gv.zebes5.xF8; + *(s16*) &gp->gv.zebes5.xF8 = timer - 1; if (timer < 0) { grZebes_801DAA08(); { f32 rand = HSD_Randf(); f32 base = grZe_804D6990->x08; f32 diff = grZe_804D6990->x0C - base; - gp->gv.zebes5.xF8 = (s16) (diff * rand + base); + *(s16*) &gp->gv.zebes5.xF8 = diff * rand + base; } } } { - s32 popped = grZebes_801DB3CC(gobj); + popped = grZebes_801DB3CC(gobj); grZebes_801DC260(); grZebes_801DBB60((HSD_GObj*) gp->gv.zebes5.x100); grZebes_801DC408(gobj); @@ -456,24 +474,26 @@ void grZebes_801D881C(HSD_GObj* gobj) gp->gv.zebes5.xF6 = (s16) (gp->gv.zebes5.xF6 + 1); divisor = grZe_804D6990->x10; eq_counter = gp->gv.zebes5.xF6; - (void) eq_counter; - spawn_phase = eq_counter / divisor; if (eq_counter % divisor == 0) { - s32 mirror = 6 - spawn_phase; + s32 mirror; + spawn_phase = eq_counter / divisor; + mirror = 6 - spawn_phase; if (spawn_phase < mirror) { - f32 scale_min = grZe_804D6990->x58; - u8* base = (u8*) grZe_8049F140 + spawn_phase * 0x24; f32 rand = HSD_Randf(); - grZebes_801DAE70(spawn_phase, 4, *(f32*) (base + 0x14), - *(f32*) (base + 0x18), + f32 scale_min = grZe_804D6990->x58; + grZe_BubbleSpawnPos* pos = + (grZe_BubbleSpawnPos*) grZe_8049F140; + grZebes_801DAE70(spawn_phase, 4, pos[spawn_phase].x14_x, + pos[spawn_phase].x18_y, (grZe_804D6990->x5C - scale_min) * rand + scale_min); } if (spawn_phase <= mirror) { - u8* base2 = (u8*) grZe_8049F140 + mirror * 0x24; f32 rand2 = HSD_Randf(); - grZebes_801DAE70(mirror, 4, *(f32*) (base2 + 0x5C), - *(f32*) (base2 + 0x60), + grZe_BubbleSpawnPos* pos = + (grZe_BubbleSpawnPos*) grZe_8049F140; + grZebes_801DAE70(mirror, 4, pos[mirror + 2].x14_x, + pos[mirror + 2].x18_y, (f32) (0.5 * rand2 + 1.0)); } } @@ -581,7 +601,7 @@ void grZebes_801D881C(HSD_GObj* gobj) for (i = 0; i < 5; i++) { if (i != 0) { f32 limit = col_heights[i + 1] - colWidth; - if (col_heights[i] < limit) { + if (limit > col_heights[i]) { col_heights[i] = limit; } } @@ -605,7 +625,7 @@ void grZebes_801D881C(HSD_GObj* gobj) } Ground_801C4368(&sp18, &sp14); - grZakoGenerator_801CA43C((void*) gp->gv.zebes5.xFC, + grZakoGenerator_801CA43C((grZakoGenerator_Config*) gp->gv.zebes5.xFC, Ground_801C3FA4(gobj, 0xE), sp18); Ground_801C2FE0((Ground_GObj*) gobj); lb_800115F4(); @@ -884,7 +904,7 @@ void grZebes_801D99E0(HSD_GObj* gobj) diff = gp->gv.zebes5.xD4; diff -= gp->gv.zebes5.xD8; - if (diff < 0.0f) { + if (0.0f > diff) { diff = -diff; } @@ -942,19 +962,16 @@ void grZebes_801D99E0(HSD_GObj* gobj) { gp->gv.zebes5.xC8 = 4; } else { - gp->gv.zebes5.xD0 = gp->gv.zebes5.xD0 + accel; + gp->gv.zebes5.xD0 += accel; if (gp->gv.zebes5.xD0 > gp->gv.zebes5.xCC) { gp->gv.zebes5.xD0 = gp->gv.zebes5.xCC; } } - { - f32 cur = gp->gv.zebes5.xD8; - if (gp->gv.zebes5.xD4 > cur) { - gp->gv.zebes5.xD8 = cur + gp->gv.zebes5.xD0; - } else { - gp->gv.zebes5.xD8 = cur - gp->gv.zebes5.xD0; - } + if (gp->gv.zebes5.xD4 > gp->gv.zebes5.xD8) { + gp->gv.zebes5.xD8 += gp->gv.zebes5.xD0; + } else { + gp->gv.zebes5.xD8 -= gp->gv.zebes5.xD0; } break; } @@ -985,12 +1002,11 @@ void grZebes_801D99E0(HSD_GObj* gobj) gp->gv.zebes5.xC4 = (s16) (gp->gv.zebes5.xC4 + 1); { s16 idx = gp->gv.zebes5.xC4; - if (idx == 0x1E) { - gp->gv.zebes5.xC4 = 0; - } else if (grZe_804D6990->xA0_entries[idx].x0_base == 0 && - grZe_804D6990->xA0_entries[idx].x2_delay_min == 0 && - grZe_804D6990->xA0_entries[idx].x4_delay_max == 0 && - grZe_804D6990->xA0_entries[idx].x6_level == 0) + if (idx == 0x1E || + (grZe_804D6990->xA0_entries[idx].x0_base == 0 && + grZe_804D6990->xA0_entries[idx].x2_delay_min == 0 && + grZe_804D6990->xA0_entries[idx].x4_delay_max == 0 && + grZe_804D6990->xA0_entries[idx].x6_level == 0)) { gp->gv.zebes5.xC4 = 0; } @@ -1017,14 +1033,13 @@ void grZebes_801D99E0(HSD_GObj* gobj) delay_max); } - state4_update_pos: { - f32 cur = gp->gv.zebes5.xD8; - if (gp->gv.zebes5.xD4 > cur) { - gp->gv.zebes5.xD8 = cur + gp->gv.zebes5.xD0; + state4_update_pos: + if (gp->gv.zebes5.xD4 > gp->gv.zebes5.xD8) { + gp->gv.zebes5.xD8 += gp->gv.zebes5.xD0; } else { - gp->gv.zebes5.xD8 = cur - gp->gv.zebes5.xD0; + gp->gv.zebes5.xD8 -= gp->gv.zebes5.xD0; } - } break; + break; } } @@ -1093,7 +1108,7 @@ void grZebes_801D9F84(Ground_GObj* gobj) void grZebes_801DA0C0(Ground_GObj* arg) {} const grZe_BubbleConfig grZe_803B8044 = { - { 1.0f, 1.1f, 1.0f, 1.2f, 1.1f, 1.0f, 1.0f }, + { { 1.0f, 1.1f, 1.0f, 1.2f, 1.1f, 1.0f, 1.0f } }, { { 7.59f, 2.5f, 0.0f }, { 24.05f, 2.2f, 0.0f }, @@ -1153,14 +1168,13 @@ void grZebes_801DA0C4(f32 level) } } -static inline void grZebes_801DA254_inline1(HSD_LObj* lobj, GXColor color) -{ - HSD_LObjSetColor(lobj, color); -} +static inline void grZebes_801DA254_inline1(GXColor color) {} -static inline void grZebes_801DA254_inline2(HSD_LObj* lobj, GXColor color) +static inline void grZebes_801DA254_inline2(HSD_LObj* lobj, GXColor* color) { - grZebes_801DA254_inline1(lobj, color); + grZebes_801DA254_inline1(*color); + grZebes_801DA254_inline1(*color); + HSD_LObjSetColor(lobj, *color); } void grZebes_801DA254(Ground_GObj* gobj, f32 level) @@ -1194,7 +1208,7 @@ void grZebes_801DA254(Ground_GObj* gobj, f32 level) result.g = (u8) (t * (f32) (c1.g - c2.g) + (f32) c2.g); result.b = (u8) (t * (f32) (c1.b - c2.b) + (f32) c2.b); result.a = 0xFF; - grZebes_801DA254_inline2(lobj, result); + grZebes_801DA254_inline2(lobj, &result); } } @@ -1485,27 +1499,26 @@ void fn_801DAC90(Item_GObj* arg0, Ground* arg1, Vec3* arg2, HSD_GObj* arg3, void grZebes_801DAE70(s32 arg0, u8 arg1, f32 x, f32 y, f32 scale) { - grZe_BubbleEntry* entry = &grZe_8049F170[arg0]; - PAD_STACK(0x10); - if (entry->x00_active == 0) { - if (entry->x20_gobj == NULL) { + if (grZe_8049F170[arg0].x00_active == 0) { + if (grZe_8049F170[arg0].x20_gobj == NULL) { Ground_GObj* gobj; - entry->x08_x = x; - entry->x0C_y = y; - entry->x10 = 0.0f; - entry->x14 = 0.0f; - entry->x1C = scale; - entry->x18_size = scale; + grZe_8049F170[arg0].x08_x = x; + grZe_8049F170[arg0].x0C_y = y; + grZe_8049F170[arg0].x10 = 0.0f; + grZe_8049F170[arg0].x14 = 0.0f; + grZe_8049F170[arg0].x1C = scale; + grZe_8049F170[arg0].x18_size = scale; if (arg0 == 0 || arg0 == 6) { gobj = NULL; } else { gobj = grZebes_801D8558(3); if (gobj != NULL) { - HSD_JObj* jobj = GET_JOBJ(gobj); Ground* gp = GET_GROUND(gobj); + HSD_JObj* jobj = GET_JOBJ(gobj); Vec3 pos; + u8 _[4]; pos.x = x; pos.y = y; @@ -1522,8 +1535,8 @@ void grZebes_801DAE70(s32 arg0, u8 arg1, f32 x, f32 y, f32 scale) } } - entry->x00_active = arg1; - entry->x20_gobj = (HSD_GObj*) gobj; + grZe_8049F170[arg0].x00_active = arg1; + grZe_8049F170[arg0].x20_gobj = (HSD_GObj*) gobj; grZe_8049F170[arg0].x04 = NULL; } } @@ -1531,15 +1544,19 @@ void grZebes_801DAE70(s32 arg0, u8 arg1, f32 x, f32 y, f32 scale) s32 grZebes_801DB088(Ground* gp, s32 arg1) { - u8 _[0x48]; - grZe_BubbleEntry* entry = &grZe_8049F170[arg1]; + u8 _[0x38]; s32 result = 0; + grZe_BubbleEntry* entry = &grZe_8049F170[arg1]; + HSD_GObj** gobjp = &grZe_8049F170[arg1].x20_gobj; + HSD_JObj** jobjp = &grZe_8049F170[arg1].x04; + f32* targetp = &grZe_8049F170[arg1].x1C; + f32* sizep = &grZe_8049F170[arg1].x18_size; Item_GObj* mat; Ground* bgp; if (entry->x00_active != 0) { - if (entry->x20_gobj != NULL) { - bgp = GET_GROUND(entry->x20_gobj); + if (*gobjp != NULL) { + bgp = GET_GROUND(*gobjp); if (bgp != NULL) { mat = bgp->gv.zebes3.xC4; @@ -1554,26 +1571,24 @@ s32 grZebes_801DB088(Ground* gp, s32 arg1) { f32 speed = grZe_804D6990->x68; - f32 target = entry->x1C; - f32 current = entry->x18_size; + f32 target = *targetp; + f32 current = *sizep; f32 diff = target - current; if (diff > speed) { - entry->x18_size = current + speed; + *sizep = current + speed; } else if (diff < -speed) { - entry->x18_size = current - speed; + *sizep = current - speed; } else { - entry->x18_size = target; + *sizep = target; } } - if (entry->x04 != NULL && - grAnime_801C83D0(entry->x20_gobj, 0, 7) != 0) - { - HSD_JObjRemoveAll(entry->x04); - entry->x04 = NULL; + if (*jobjp != NULL && grAnime_801C83D0(*gobjp, 0, 7) != 0) { + HSD_JObjRemoveAll(*jobjp); + *jobjp = NULL; { - HSD_JObj* jobj = (HSD_JObj*) entry->x20_gobj->hsd_obj; + HSD_JObj* jobj = (HSD_JObj*) (*gobjp)->hsd_obj; if (jobj != NULL) { HSD_JObjClearFlagsAll(jobj, JOBJ_HIDDEN); } @@ -1645,10 +1660,10 @@ s32 grZebes_801DB088(Ground* gp, s32 arg1) if (best_idx != -1) { grZe_BubbleEntry* src = &grZe_8049F170[best_idx]; entry->x00_active = src->x00_active; - entry->x04 = src->x04; - entry->x18_size = src->x18_size; - entry->x1C = src->x1C; - entry->x20_gobj = src->x20_gobj; + *jobjp = src->x04; + *sizep = src->x18_size; + *targetp = src->x1C; + *gobjp = src->x20_gobj; src->x00_active = 0; src->x20_gobj = NULL; } else { @@ -1673,29 +1688,43 @@ s32 grZebes_801DB088(Ground* gp, s32 arg1) return result; } +static inline f32 grZebes_801DB3CC_sqrt(f32 x) +{ + f32 y; + f64 guess = __frsqrte((f64) x); + guess = 0.5 * guess * (3.0 - guess * guess * x); + guess = 0.5 * guess * (3.0 - guess * guess * x); + guess = 0.5 * guess * (3.0 - guess * guess * x); + y = (f32) (x * guess); + return y; +} + +static inline f32 grZebes_801DB3CC_dist2(f32 dy, f32 dx) +{ + return dx * dx + dy * dy; +} + s32 grZebes_801DB3CC(HSD_GObj* gobj) { grZe_BubbleEntry* base = grZe_8049F170; s32 popped = 0; int i; grZe_BubbleEntry* ptr; - PAD_STACK(8); ptr = base; for (i = 0; i < 20; i++, ptr++) { - if (ptr->x00_active != 0) { - if (grZebes_801DB088((Ground*) gobj, i) != 0) { - popped = 1; - } + if (ptr->x00_active != 0 && grZebes_801DB088((Ground*) gobj, i) != 0) { + popped = 1; } } { grZe_YakumonoParam* yaku = grZe_804D6990; - for (i = 0; i < 20; i++) { - if (base[i].x00_active != 0) { - base[i].x10 = 0.0f; - base[i].x14 = -yaku->x84; + int j; + for (j = 0; j < 20; j++) { + if (base[j].x00_active != 0) { + base[j].x10 = 0.0f; + base[j].x14 = -yaku->x84; } } } @@ -1715,9 +1744,9 @@ s32 grZebes_801DB3CC(HSD_GObj* gobj) if (left->x00_active != 0) { f32 dy = left->x0C_y - cur->x0C_y; f32 dx = left->x08_x - cur->x08_x; - f32 dist = dx * dx + dy * dy; + f32 dist = grZebes_801DB3CC_dist2(dy, dx); if (dist > zero) { - dist = sqrtf(dist); + dist = grZebes_801DB3CC_sqrt(dist); } { f32 col_r = grZe_804D6990->x74; @@ -1742,7 +1771,7 @@ s32 grZebes_801DB3CC(HSD_GObj* gobj) f32 dx2 = right->x08_x - cur->x08_x; f32 dist2 = dx2 * dx2 + dy2 * dy2; if (dist2 > zero) { - dist2 = sqrtf(dist2); + dist2 = grZebes_801DB3CC_sqrt(dist2); } { f32 col_r2 = grZe_804D6990->x74; @@ -1785,12 +1814,10 @@ s32 grZebes_801DB3CC(HSD_GObj* gobj) if (eb->x00_active != 0) { f32 dy = eb->x0C_y - ea->x0C_y; f32 dx = eb->x08_x - ea->x08_x; - f32 dist_sq = dx * dx + dy * dy; - f32 dist; + f32 dist_sq = grZebes_801DB3CC_dist2(dy, dx); + f32 dist = dist_sq; if (dist_sq > 0.0f) { - dist = sqrtf(dist_sq); - } else { - dist = dist_sq; + dist = grZebes_801DB3CC_sqrt(dist_sq); } { f32 effective_dist = dist; @@ -1860,7 +1887,6 @@ s32 grZebes_801DB3CC(HSD_GObj* gobj) { int k; - grZe_BubbleEntry* p = base; f32 left_anchor_x = grZe_8049F158[0].x; f32 left_anchor_y = grZe_8049F158[0].y; f32 right_anchor_x = grZe_8049F158[1].x; @@ -1869,23 +1895,23 @@ s32 grZebes_801DB3CC(HSD_GObj* gobj) f32 left_bound_x = grZe_8049F140[0].x; f32 right_bound_y = grZe_8049F140[1].y; f32 right_bound_x = grZe_8049F140[1].x; - for (k = 0; k < 20; k++, p++) { - if (p->x00_active != 0) { + for (k = 0; k < 20; base++, k++) { + if (base->x00_active != 0) { if (k == 0) { - p->x10 = 0.0f; - p->x14 = 0.0f; - p->x08_x = left_anchor_x; - p->x0C_y = left_anchor_y; + base->x10 = 0.0f; + base->x14 = 0.0f; + base->x08_x = left_anchor_x; + base->x0C_y = left_anchor_y; } else if (k == 6) { - p->x10 = 0.0f; - p->x14 = 0.0f; - p->x08_x = right_anchor_x; - p->x0C_y = right_anchor_y; + base->x10 = 0.0f; + base->x14 = 0.0f; + base->x08_x = right_anchor_x; + base->x0C_y = right_anchor_y; } else { - f32 old_y = p->x0C_y; - f32 old_x = p->x08_x; - f32 new_y = old_y + p->x14; - f32 new_x = old_x + p->x10; + f32 old_y = base->x0C_y; + f32 old_x = base->x08_x; + f32 new_y = old_y + base->x14; + f32 new_x = old_x + base->x10; if (new_y < left_bound_y && new_x < left_bound_x) { if (old_y >= left_bound_y) { new_y = left_bound_y; @@ -1900,24 +1926,24 @@ s32 grZebes_801DB3CC(HSD_GObj* gobj) new_x = right_bound_x; } } - p->x08_x = new_x; - p->x0C_y = new_y; + base->x08_x = new_x; + base->x0C_y = new_y; { - f32 vx = p->x10; + f32 vx = base->x10; f32 max_v = grZe_804D6990->x88; if (vx > max_v) { - p->x10 = max_v; + base->x10 = max_v; } else if (vx < -max_v) { - p->x10 = -max_v; + base->x10 = -max_v; } } { - f32 vy = p->x14; + f32 vy = base->x14; f32 max_v = grZe_804D6990->x88; if (vy > max_v) { - p->x14 = max_v; + base->x14 = max_v; } else if (vy < -max_v) { - p->x14 = -max_v; + base->x14 = -max_v; } } } @@ -1931,17 +1957,18 @@ s32 grZebes_801DB3CC(HSD_GObj* gobj) s32 grZebes_801DBB60(HSD_GObj* yaku) { s32 last_idx; - grZe_BubbleEntry* bubbles = grZe_8049F170; + grZe_BubbleState* state = (grZe_BubbleState*) grZe_8049F140; + grZe_BubbleEntry* bubbles = state->bubbles; s32 count = 0; f32 max_dist_sq = -1.0f; + grZe_BubbleEntry* ej; HSD_ASSERT(0x898, yaku); { - grZe_BubbleEntry* p = bubbles; int i; - for (i = 0; i < 20; i++, p++) { - if (p->x00_active == 1 && i != 0 && i != 6) { + for (i = 0; i < 20; i++) { + if (bubbles[i].x00_active == 1 && i != 0 && i != 6) { count++; last_idx = i; if (count > 2) { @@ -1980,7 +2007,7 @@ s32 grZebes_801DBB60(HSD_GObj* yaku) f32 ei_x = ei->x08_x; f32 ei_size = ei->x18_size; s32 rem = 20 - j; - grZe_BubbleEntry* ej = &bubbles[j]; + ej = &bubbles[j]; if (j < 20) { for (; rem != 0; ej++, j++, rem--) { if (ej->x00_active == 1 && j != 0 && j != 6) { @@ -2223,14 +2250,11 @@ void grZebes_801DC408(Ground_GObj* gobj) void grZebes_801DC744(s32 arg0, u8 arg1) { - f32 scales[7]; + grZe_BubbleScales scales; Vec3* base = grZe_8049F140; s32 i; - for (i = 0; i < 7; i++) { - scales[i] = grZe_803B8044.x0_scales[i]; - } - + scales = grZe_803B8044.x0_scales; if (arg0 & 1) { f32 x_start = base[2].x; f32 y_start = base[2].y; @@ -2239,7 +2263,7 @@ void grZebes_801DC744(s32 arg0, u8 arg1) for (i = 0; i < 7; i++) { grZebes_801DAE70(i, arg1, x_step * (f32) i + x_start, - y_step * (f32) i + y_start, scales[i]); + y_step * (f32) i + y_start, scales.values[i]); } } @@ -2250,35 +2274,36 @@ void grZebes_801DC744(s32 arg0, u8 arg1) f32 x_base = p_x + bubble_r; f32 x_range = (base[1].x - p_x) - 2.0f * bubble_r; f32 y_range = base[1].y - y_min; - f64 mid_x = 0.5 * x_range + x_base; - f64 lo_x, hi_x, lo_y, hi_y, near_max_y, max_y; - grZebes_801DAE70(7, arg1, (f32) mid_x, (f32) (0.5 * y_range + y_min), - 1.0f); + grZebes_801DAE70(7, arg1, (f32) (0.5 * x_range + x_base), + (f32) (0.5 * y_range + y_min), 1.0f); - hi_y = 0.8 * y_range + y_min; - grZebes_801DAE70(8, arg1, (f32) (0.2 * x_range + x_base), (f32) hi_y, - 1.2f); + grZebes_801DAE70(8, arg1, (f32) (0.2 * x_range + x_base), + (f32) (0.8 * y_range + y_min), 1.2f); - hi_x = 0.8 * x_range + x_base; - lo_y = 0.2 * y_range + y_min; - grZebes_801DAE70(9, arg1, (f32) hi_x, (f32) lo_y, 1.1f); + grZebes_801DAE70(9, arg1, (f32) (0.8 * x_range + x_base), + (f32) (0.2 * y_range + y_min), 1.1f); - grZebes_801DAE70(10, arg1, (f32) hi_x, (f32) hi_y, 1.1f); + { + f64 hi_x = 0.8 * x_range + x_base; + grZebes_801DAE70(10, arg1, (f32) hi_x, + (f32) (0.8 * y_range + y_min), 1.1f); + } - grZebes_801DAE70(11, arg1, (f32) mid_x, (f32) lo_y, 1.2f); + grZebes_801DAE70(11, arg1, (f32) (0.5 * x_range + x_base), + (f32) (0.2 * y_range + y_min), 1.2f); - near_max_y = 0.9 * y_range + y_min; - grZebes_801DAE70(12, arg1, (f32) mid_x, (f32) near_max_y, 1.3f); + grZebes_801DAE70(12, arg1, (f32) (0.5 * x_range + x_base), + (f32) (0.9 * y_range + y_min), 1.3f); - grZebes_801DAE70(13, arg1, (f32) mid_x, (f32) near_max_y, 1.3f); + grZebes_801DAE70(13, arg1, (f32) (0.5 * x_range + x_base), + (f32) (0.9 * y_range + y_min), 1.3f); - max_y = (f64) y_min + (f64) y_range; - grZebes_801DAE70(14, arg1, (f32) (0.6 * x_range + x_base), (f32) max_y, - 1.1f); + grZebes_801DAE70(14, arg1, (f32) (0.6 * x_range + x_base), + (f32) ((f64) y_min + (f64) y_range), 1.1f); - grZebes_801DAE70(15, arg1, (f32) (0.2 * x_range + x_base), (f32) max_y, - 1.0f); + grZebes_801DAE70(15, arg1, (f32) (0.2 * x_range + x_base), + (f32) ((f64) y_min + (f64) y_range), 1.0f); } } diff --git a/src/melee/if/forward.h b/src/melee/if/forward.h index 411ff9a14b..0aa18d2194 100644 --- a/src/melee/if/forward.h +++ b/src/melee/if/forward.h @@ -9,6 +9,7 @@ typedef struct HudIndex HudIndex; typedef struct IfDamageState IfDamageState; typedef struct ifMagnify ifMagnify; typedef struct Placeholder_8016AE50_flags Placeholder_8016AE50_flags; +typedef struct ScInfCntModels ScInfCntModels; typedef struct Thing_803F9628 Thing_803F9628; typedef struct UnknownClassTypeE UnknownClassTypeE; typedef struct un_80301C64_t un_80301C64_t; diff --git a/src/melee/if/if_2F72.c b/src/melee/if/if_2F72.c index 6cfedf6354..406f654aeb 100644 --- a/src/melee/if/if_2F72.c +++ b/src/melee/if/if_2F72.c @@ -58,7 +58,7 @@ s32 fn_802F7288(HSD_GObj* gobj, Element_803F9628* entry) void if_802F73C4(HSD_GObj* gobj) { - Element_803F9628* const entries = ifStatus_803F9628; + Element_803F9628* const entries = ifStatus_ScInfCntModels.elements; Element_803F9628* entry; s32 i; Element_803F9628* curr; @@ -94,7 +94,7 @@ void if_802F73C4(HSD_GObj* gobj) void if_802F74D0(HSD_GObj* gobj) { - Element_803F9628* const entries = ifStatus_803F9628; + Element_803F9628* const entries = ifStatus_ScInfCntModels.elements; Element_803F9628* entry; s32 i; Element_803F9628* curr; @@ -226,6 +226,7 @@ HSD_GObj* fn_802F77F8(HSD_GObj* gobj, u8 slot, s32 arg2) { void** base = lbl_804A1340; HSD_JObj* jobj; + DynamicModelDesc* model; Vec3* pos; if (base[0] == NULL) { @@ -242,7 +243,8 @@ HSD_GObj* fn_802F77F8(HSD_GObj* gobj, u8 slot, s32 arg2) if (jobj != NULL) { HSD_GObjObject_80390A70(gobj, HSD_GObj_804D7849, jobj); GObj_SetupGXLink(gobj, fn_802F770C, 11, 0); - gm_8016895C(jobj, *(DynamicModelDesc**) base[0], (u8) arg2); + model = *(DynamicModelDesc**) base[0]; + gm_8016895C(jobj, model, arg2 & 0xFF); HSD_JObjReqAnimAll(jobj, 0.0f); HSD_JObjAnimAll(jobj); @@ -262,42 +264,43 @@ void fn_802F7994(HSD_GObj* gobj) HSD_JObj* jobj; void** base = lbl_804A1340; void** ptr; + void** ptr2; + void** ptr4; void** entry; s32 slot; s32 idx; - void* cmp; + void* temp; f32 frame; + PAD_STACK(8); jobj = gobj->hsd_obj; frame = lbGetJObjCurrFrame(jobj); - if (base[1] == gobj) { + ptr = base; + if (ptr[1] == gobj) { slot = 0; } else { - ptr = base; - ptr += 2; - cmp = ptr[1]; - if (cmp == gobj) { + if ((temp = (ptr += 2)[1]) == gobj) { slot = 1; } else { - cmp = ptr[3]; - (void) cmp; - ptr += 2; - if (cmp == gobj) { + ptr2 = ptr; + temp = ptr2[3]; + ptr4 = ptr2 + 2; + if (temp == gobj) { slot = 2; } else { - cmp = ptr[3]; - ptr += 2; - if (cmp == gobj) { + temp = ptr4[3]; + ptr = ptr4 + 2; + if (temp == gobj) { slot = 3; } else { - cmp = ptr[3]; - ptr += 2; - if (cmp == gobj) { + temp = ptr[3]; + ptr2 = ptr + 2; + if (temp == gobj) { slot = 4; } else { - cmp = ptr[3]; - if (cmp == gobj) { + temp = ptr2[3]; + if (temp == gobj) { slot = 5; } else { slot = -1; @@ -312,7 +315,7 @@ void fn_802F7994(HSD_GObj* gobj) if (frame > 12.0f && base[slot * 2 + 2] == NULL) { idx = (u8) slot << 1; entry = base + idx; - base[idx + 2] = fn_802F77F8(*++entry, (u8) slot, 1); + base[idx + 2] = fn_802F77F8(*(entry += 2), (u8) slot, 1); if (base[idx + 2] != NULL) { HSD_GObj_SetupProc(*entry, (HSD_GObjEvent) fn_802F7670, 0x11); } @@ -328,28 +331,33 @@ void fn_802F7994(HSD_GObj* gobj) void if_802F7AF8(s32 slot) { - s32 idx; + void** base; + s32 slot2; + u32 idx; void** entry; - void** base1; - void** base = lbl_804A1340; - s32 slot2 = Player_80036428(slot); + void** dst; + void** dst2; HSD_GObj* result; - idx = slot << 1; - entry = base + idx; - result = fn_802F77F8(*++entry, (u8) slot, 1); - base1 = &base[1]; - base1[idx] = result; - if (base1[idx] != NULL) { + base = lbl_804A1340; + slot2 = Player_80036428(slot); + + idx = (slot << 3) & 0x7F8; + entry = base; + entry += idx >> 2; + *(dst2 = (dst = &base[1]) + (idx >> 2)) = + fn_802F77F8(*++entry, (u8) slot, 1); + if (*dst2 != NULL) { HSD_GObj_SetupProc(*entry, (HSD_GObjEvent) fn_802F75D4, 0x11); } - idx = (u8) slot2 << 1; - entry = base + idx; - result = fn_802F77F8(*++entry, (u8) slot2, 2); - base1[idx] = result; - if (base1[idx] != NULL) { - HSD_GObj_SetupProc(*entry, (HSD_GObjEvent) fn_802F75D4, 0x11); + idx = (slot2 << 3) & 0x7F8; + base += idx >> 2; + result = fn_802F77F8(*++base, (u8) slot2, 2); + dst2 = dst + (idx >> 2); + *dst2 = result; + if (*dst2 != NULL) { + HSD_GObj_SetupProc(*base, (HSD_GObjEvent) fn_802F75D4, 0x11); } } @@ -401,6 +409,31 @@ void if_802F7C30(s32 slot) } } +static inline void if_802F7D08_other(s32 slot, s32 ret, void*** base) +{ + s32 idx; + void** entry; + HSD_GObj* result; + + if (ret == -1) { + idx = (u8) slot << 1; + entry = *base + idx; + result = fn_802F77F8(*++entry, (u8) slot, 1); + (*base)[idx + 1] = result; + if ((*base)[idx + 1] != NULL) { + HSD_GObj_SetupProc(*entry, (HSD_GObjEvent) fn_802F7994, 0x11); + } + } else { + idx = (u8) slot << 1; + entry = *base + idx; + result = fn_802F77F8(*++entry, (u8) slot, 1); + (*base)[idx + 1] = result; + if ((*base)[idx + 1] != NULL) { + HSD_GObj_SetupProc(*entry, (HSD_GObjEvent) fn_802F75D4, 0x11); + } + } +} + void if_802F7D08(s32 slot) { void** base = lbl_804A1340; @@ -408,7 +441,6 @@ void if_802F7D08(s32 slot) void** entry; s32 ret = gm_8016AEC8(); HSD_GObj* result; - PAD_STACK(8); if (ret == -2) { idx = (u8) slot << 1; @@ -418,22 +450,8 @@ void if_802F7D08(s32 slot) if (base[idx + 1] != NULL) { HSD_GObj_SetupProc(*entry, (HSD_GObjEvent) fn_802F7994, 0x11); } - } else if (ret == -1) { - idx = (u8) slot << 1; - entry = base + idx; - result = fn_802F77F8(*++entry, (u8) slot, 1); - base[idx + 1] = result; - if (base[idx + 1] != NULL) { - HSD_GObj_SetupProc(*entry, (HSD_GObjEvent) fn_802F7994, 0x11); - } } else { - idx = (u8) slot << 1; - entry = base + idx; - result = fn_802F77F8(*++entry, (u8) slot, 1); - base[idx + 1] = result; - if (base[idx + 1] != NULL) { - HSD_GObj_SetupProc(*entry, (HSD_GObjEvent) fn_802F75D4, 0x11); - } + if_802F7D08_other(slot, ret, &base); } } diff --git a/src/melee/if/ifcoget.c b/src/melee/if/ifcoget.c index aaeb88e0a1..2c868d29f8 100644 --- a/src/melee/if/ifcoget.c +++ b/src/melee/if/ifcoget.c @@ -181,22 +181,31 @@ static inline int fn_802FF218_inline(HSD_GObj* arg0) void fn_802FF218(HSD_GObj* arg0) { int y; + int s; + struct un_804A1F58_x8_t* thing; PAD_STACK(32); y = fn_802FF218_inline(arg0); if (y >= 0) { - struct un_804A1F58_x8_t* thing = &un_804A1F58.x8[y]; + { + struct un_804A1F58_x8_t* cur = &un_804A1F58.x8[y]; + thing = cur; + } if (thing->x10 == 1) { HSD_SisLib_803A70A0(thing->x4, thing->x8, " "); - } else { - int s; + return; + } + { gm_8016B774(); s = gm_8016C658(y); if (s > 9999) { s = 9999; } - if (thing->xC != s) { - HSD_SisLib_803A70A0(thing->x4, thing->x8, "%d", s); - thing->xC = s; + { + int s2 = s; + if (thing->xC != s2) { + HSD_SisLib_803A70A0(thing->x4, thing->x8, "%d", s2); + thing->xC = s2; + } } } } diff --git a/src/melee/if/ifmagnify.c b/src/melee/if/ifmagnify.c index bf66eb4d96..96346e3a0e 100644 --- a/src/melee/if/ifmagnify.c +++ b/src/melee/if/ifmagnify.c @@ -4,7 +4,6 @@ #include "cm/camera.h" #include "ft/ftdrawcommon.h" #include "ft/ftlib.h" -#include "gm/gm_1601.h" #include "gm/gm_16AE.h" #include "gm/types.h" #include "gr/ground.h" @@ -31,6 +30,9 @@ #include #include +u32 gm_80160854(u8, u8, u8, u8); +GXColor gm_80160968(u32); + /* 3F97E8 */ extern HSD_CameraDescPerspective ifMagnify_803F97E8; static char ifMagnify_803F988C[] = "!(jobj->flags & JOBJ_USE_QUATERNION)"; static char ifMagnify_804D57F0[] = "jobj.h"; @@ -156,21 +158,24 @@ ifMagnifyPlayer* ifMagnify_802FB73C(ifMagnifyPlayer* arg0, Vec2* arg1, void ifMagnify_802FB8C0(HSD_GObj* arg0, s32 arg1) { - Vec2 pos; S32Vec2 screen_pos; Vec2 out; + Vec2 pos; Vec3 translate; GXColor color; GXColor color_copy; + GXColor* color_ptr; HSD_GObj* fighter_gobj; ifMagnifyPlayer* player; s32 slot; bool is_colored; bool should_display; - u8 arrow_kind; + s32 arrow_kind; u8 slot_type; u8 teams_enabled; - u8 operand_pad[20]; + u8 operand_pad[12]; + + PAD_STACK(8); if (arg1 != 0) { return; @@ -206,16 +211,17 @@ void ifMagnify_802FB8C0(HSD_GObj* arg0, s32 arg1) if ((player->state.unk == 4) || (player->state.unk == 2)) { slot_type = Player_GetPlayerSlotType(slot); teams_enabled = gm_8016B168(); - color = - gm_80160968(gm_80160854((u8) slot, Player_GetTeam(slot), - teams_enabled, slot_type)); + color = gm_80160968( + (u8) gm_80160854((u8) slot, Player_GetTeam(slot), + teams_enabled, slot_type)); + color_ptr = &color_copy; color_copy = color; if (player->state.unk == 2) { arrow_kind = 1; } else { arrow_kind = 2; } - un_802FD928((u8) slot, arrow_kind, &color_copy); + un_802FD928((u8) slot, arrow_kind, color_ptr); is_colored = true; } } @@ -227,17 +233,18 @@ void ifMagnify_802FB8C0(HSD_GObj* arg0, s32 arg1) void ifMagnify_802FBBDC(HSD_GObj* arg0) { - f32 right; + int i; + f32 mix2; + int j; ifMagnify* magnify; HSD_CObj* cobj; - HSD_GObj* fighter_gobj; + u8* color_ids; ifMagnifyPlayer* player; f32 top; f32 bottom; f32 left; - Vec3 interest_pos; - GXColor colors[4]; - Vec3 world_pos; + HSD_GObj* fighter_gobj; + bool should_display; f32 x_blend; f32 y_blend; f32 x_inv; @@ -247,13 +254,11 @@ void ifMagnify_802FBBDC(HSD_GObj* arg0) f32 y_class; f32 mix0; f32 mix1; - f32 mix2; f32 mix3; GXColor result; - int i; - int j; - u8* color_ids; - bool should_display; + f32 right; + Vec3 interest_pos; + GXColor colors[4]; bool is_outside; magnify = &ifMagnify_804A1DE0; @@ -277,6 +282,7 @@ void ifMagnify_802FBBDC(HSD_GObj* arg0) } for (i = 0; i < 6; i++) { + Vec3 world_pos; player = &magnify->player[i]; fighter_gobj = Player_GetEntity(i); if (player->state.ignore_offscreen || fighter_gobj == NULL || @@ -468,8 +474,10 @@ void ifMagnify_802FC3C0(s32 slot) (ifMagnifyImageDescCopy*) &ifMagnify_804A1DE0; copy_base->image_descs[slot] = *ifMagnify_804A1DE0.player[0].idesc; - player->idesc = &((ifMagnifyImageDescBase*) &ifMagnify_804A1DE0) - ->image_descs[slot - 1]; + copy_base = + (ifMagnifyImageDescCopy*) ((ifMagnifyImageDescBase*) &ifMagnify_804A1DE0) + ->image_descs; + player->idesc = &((HSD_ImageDesc*) copy_base)[slot - 1]; player->idesc->image_ptr = HSD_MemAlloc( (GXGetTexBufferSize(player->idesc->width, player->idesc->height, player->idesc->format, 0, 0) + @@ -538,13 +546,18 @@ void ifMagnify_802FC618(void) void ifMagnify_802FC750(void) { - ifMagnify* base = &ifMagnify_804A1DE0; + ifMagnify* base; + ifMagnify* cur; + s32 offset; HSD_GObj** gobj_ptr; s32 i; - for (i = 0; i < 6; i++) { - if (*(HSD_GObj**) ((u8*) base + (i << 4) + 0x14) != NULL) { - gobj_ptr = (HSD_GObj**) ((u32) base + (i << 4) + 0x14); + base = &ifMagnify_804A1DE0; + for (cur = base, offset = (i = 0), offset <<= 4; i < 6; + i += 1, cur = (ifMagnify*) ((u32) cur + 0x10), offset += 0x10) + { + if (cur->player[0].gobj != NULL) { + gobj_ptr = (HSD_GObj**) ((u32) base + offset + 0x14); HSD_GObjPLink_80390228(*gobj_ptr); *gobj_ptr = NULL; } diff --git a/src/melee/if/ifprize.c b/src/melee/if/ifprize.c index a08cd3af1a..44a1aad71a 100644 --- a/src/melee/if/ifprize.c +++ b/src/melee/if/ifprize.c @@ -248,29 +248,39 @@ static void setArchive(void) } } +static inline void un_802FE918_update_x3(unsigned char* x3_ptr, int* r) +{ + int old_x3; + int k; + int new_x3; + + old_x3 = *x3_ptr; + for (k = 0; k < 3; k++) { + if (k == old_x3) { + (*r)++; + } else if (*r == k) { + new_x3 = *r; + break; + } + } + *x3_ptr = new_x3; +} + void un_802FE918(int a, int b, int c) { struct un_803F9B30* x; - int new_x3; + unsigned char* x3_ptr; int r; - int k; int i; char sp1C[0x104]; HSD_Text** text; datetime sp14; lbAudioAx_800236DC(); - lbAudioAx_80023F28(un_803F9D48.x30[un_803F9D48.x3]); + x3_ptr = &un_803F9D48.x3; + lbAudioAx_80023F28(un_803F9D48.x30[*x3_ptr]); r = HSD_Randi(2); - for (k = 0; k < 3; k++) { - if (un_803F9D48.x3 == k) { - r++; - } else if (r == k) { - new_x3 = r; - break; - } - } - un_803F9D48.x3 = new_x3; + un_802FE918_update_x3(x3_ptr, &r); gmMainLib_8015D8B0(a); for (x = &un_803F9B30[0]; x->x0 != 66; x++) { if (x->x0 == a) { @@ -282,12 +292,13 @@ void un_802FE918(int a, int b, int c) found: un_803F9D48.x4 = i; if (a == 0x3E) { - unsigned short v_x8; + unsigned short v_x6; un_802FE3F8(a, 2, (short*) &un_803F9D48.x6, (short*) &un_803F9D48.x8); - v_x8 = un_803F9D48.x8; - HSD_SisLib_803A6530(2, 0x4A, un_803F9D48.x6); + v_x6 = un_803F9D48.x6; + r = un_803F9D48.x8; + HSD_SisLib_803A6530(2, 0x4A, v_x6); HSD_SisLib_803A660C(2, 0x4A, Toy_803063D4(b, 0x4E, 0x174)); - HSD_SisLib_803A660C(2, 0x4A, v_x8); + HSD_SisLib_803A660C(2, 0x4A, r); HSD_SisLib_803A6368(un_803F9D48.x20, 0x4A); } else { un_802FE3F8(a, 2, (short*) &un_803F9D48.x6, NULL); diff --git a/src/melee/if/ifstatus.c b/src/melee/if/ifstatus.c index 0c7fd8e5f3..ff2087a449 100644 --- a/src/melee/if/ifstatus.c +++ b/src/melee/if/ifstatus.c @@ -54,15 +54,27 @@ typedef struct UnkX { /* 2F491C */ static void ifStatus_PercentOnDeathAnimationThink(UnkX* value, s32, s32); -/* 3F9628 */ Element_803F9628 ifStatus_803F9628[8] = { - { NULL, 0, if_802F74D0, 0x7C860U, 8, 0, { 0 }, 0, NULL, NULL, 0, 0 }, - { NULL, 0, if_802F73C4, 0xC351U, 0, 0, { 0 }, 0, NULL, NULL, 0, 0 }, - { NULL, 0, if_802F74D0, 0x7C85EU, 0, 0, { 0 }, 0, NULL, NULL, 0, 0 }, - { NULL, 0, if_802F73C4, 0x7C85DU, 0, 0, { 0 }, 0, NULL, NULL, 0, 0 }, - { NULL, 0, if_802F73C4, 0x7C857U, 10, 0, { 0 }, 0, NULL, NULL, 0, 0 }, - { NULL, 0, if_802F74D0, 0x7C855U, 8, 0, { 0 }, 0, NULL, NULL, 0, 0 }, - { NULL, 0, if_802F74D0, 0x9C48U, 0, 0, { 0 }, 0, NULL, NULL, 0, 0 }, - { NULL, 0, if_802F74D0, 0x9C46U, 0, 0, { 0 }, 0, NULL, NULL, 0, 0 }, +/// The "ScInfCnt_scene_models" archive section name is a trailing member of +/// this object rather than a call-site literal. Evidence: ifStatus_802F7134 +/// at 802F719C addresses the string as base+0x140 through the one lis/addi +/// relocation it uses for the element stores (base+0x00..0x13C); MWCC only +/// folds data accesses onto a single symbol-relocated base when they belong +/// to one object (separate objects/literals compile to a `...data.0` +/// section-relative base, which mismatches). The object extent also spans +/// the full .data gap 0x803F9628..0x803F9780 (0x140 elements + 0x16 string +/// + 2 pad = sizeof(ScInfCntModels)). +/* 3F9628 */ ScInfCntModels ifStatus_ScInfCntModels = { + { + { NULL, 0, if_802F74D0, 0x7C860U, 8, 0, { 0 }, 0, NULL, NULL, 0, 0 }, + { NULL, 0, if_802F73C4, 0xC351U, 0, 0, { 0 }, 0, NULL, NULL, 0, 0 }, + { NULL, 0, if_802F74D0, 0x7C85EU, 0, 0, { 0 }, 0, NULL, NULL, 0, 0 }, + { NULL, 0, if_802F73C4, 0x7C85DU, 0, 0, { 0 }, 0, NULL, NULL, 0, 0 }, + { NULL, 0, if_802F73C4, 0x7C857U, 10, 0, { 0 }, 0, NULL, NULL, 0, 0 }, + { NULL, 0, if_802F74D0, 0x7C855U, 8, 0, { 0 }, 0, NULL, NULL, 0, 0 }, + { NULL, 0, if_802F74D0, 0x9C48U, 0, 0, { 0 }, 0, NULL, NULL, 0, 0 }, + { NULL, 0, if_802F74D0, 0x9C46U, 0, 0, { 0 }, 0, NULL, NULL, 0, 0 }, + }, + "ScInfCnt_scene_models", }; /* 4D6D60 */ static u8 ifStatus_804D6D60; /* 4D6D61 */ static s8 ifStatus_804D6D61; @@ -432,6 +444,8 @@ void ifStatus_802F4EDC(HSD_GObj* gobj) /* Update colors when damage changes */ if ((s16) state->old_damage != (s16) state->damage_percent) { if (Player_GetMoreFlagsBit2((s8) state->player_slot)) { + GXColor temp_color; + /* Stamina mode: 0-100% range */ clamped_damage = state->damage_percent; if (clamped_damage > 100) { @@ -440,17 +454,20 @@ void ifStatus_802F4EDC(HSD_GObj* gobj) clamped_damage = 0; } factor = 1.0F - ((f32) clamped_damage / 100.0F); - color.r = (s8) (factor * (f32) ((&ifStatus_804D57AC)[0] - - (&ifStatus_804D57A8)[0]) + - (f32) (&ifStatus_804D57A8)[0]); - color.g = (s8) (factor * (f32) ((&ifStatus_804D57AC)[1] - - (&ifStatus_804D57A8)[1]) + - (f32) (&ifStatus_804D57A8)[1]); - color.b = (s8) (factor * (f32) ((&ifStatus_804D57AC)[2] - - (&ifStatus_804D57A8)[2]) + - (f32) (&ifStatus_804D57A8)[2]); - color.a = 255; + temp_color.r = (s8) (factor * (f32) ((&ifStatus_804D57AC)[0] - + (&ifStatus_804D57A8)[0]) + + (f32) (&ifStatus_804D57A8)[0]); + temp_color.g = (s8) (factor * (f32) ((&ifStatus_804D57AC)[1] - + (&ifStatus_804D57A8)[1]) + + (f32) (&ifStatus_804D57A8)[1]); + temp_color.b = (s8) (factor * (f32) ((&ifStatus_804D57AC)[2] - + (&ifStatus_804D57A8)[2]) + + (f32) (&ifStatus_804D57A8)[2]); + temp_color.a = 255; + color = temp_color; } else { + GXColor temp_color; + /* Normal mode: 0-300% range */ clamped_damage = state->damage_percent; if (clamped_damage > 300) { @@ -459,16 +476,17 @@ void ifStatus_802F4EDC(HSD_GObj* gobj) clamped_damage = 0; } factor = (f32) clamped_damage / 300.0F; - color.r = (s8) (factor * (f32) ((&ifStatus_804D57AC)[0] - - (&ifStatus_804D57A8)[0]) + - (f32) (&ifStatus_804D57A8)[0]); - color.g = (s8) (factor * (f32) ((&ifStatus_804D57AC)[1] - - (&ifStatus_804D57A8)[1]) + - (f32) (&ifStatus_804D57A8)[1]); - color.b = (s8) (factor * (f32) ((&ifStatus_804D57AC)[2] - - (&ifStatus_804D57A8)[2]) + - (f32) (&ifStatus_804D57A8)[2]); - color.a = 255; + temp_color.r = (s8) (factor * (f32) ((&ifStatus_804D57AC)[0] - + (&ifStatus_804D57A8)[0]) + + (f32) (&ifStatus_804D57A8)[0]); + temp_color.g = (s8) (factor * (f32) ((&ifStatus_804D57AC)[1] - + (&ifStatus_804D57A8)[1]) + + (f32) (&ifStatus_804D57A8)[1]); + temp_color.b = (s8) (factor * (f32) ((&ifStatus_804D57AC)[2] - + (&ifStatus_804D57A8)[2]) + + (f32) (&ifStatus_804D57A8)[2]); + temp_color.a = 255; + color = temp_color; } /* Apply color to all digit materials */ @@ -680,19 +698,41 @@ void ifStatus_802F5E50(HSD_GObj* gobj, s32 arg1) } } -void ifStatus_802F5EC0(IfDamageState* state, s32 player_idx) +/// Loads the HUD parent joint through @p hud rather than a call-site member +/// load. Evidence: with the member load at the call site the compiler +/// assigns jobj to r27 and state to r29; retail keeps state in r28 and the +/// loaded joint in r31 (objdiff rows 0x0..0x84 of ifStatus_802F5EC0). The +/// inline argument copy reproduces retail's register assignment; codegen is +/// otherwise identical (same lwz/bl sequence). +static inline HSD_JObj* ifStatus_LoadHUDJoint(HudIndex* hud) +{ + return HSD_JObjLoadJoint(hud->unk258); +} + +/// Converts the HUD joint for the ifStatus_802F6194 walk. Evidence: retail +/// copies jobj through a scratch register before the call inside the loop +/// (addi r27, r30, 0x0 / addi r3, r27, 0x0 at 0x190..0x1A0) where a direct +/// cast argument compiles to a single addi r3, r30, 0x0; the inline return +/// temp reproduces the extra register copy. No code is generated beyond the +/// register moves retail shows. +static inline HSD_GObj* ifStatus_JObjAsGObj(HSD_JObj* jobj) +{ + return (HSD_GObj*) jobj; +} + +HSD_GObj* ifStatus_802F5EC0(IfDamageState* state, s32 player_idx) { HSD_GObj* gobj; HSD_MatAnimJoint** anim_base; HSD_JObj* jobj; Vec3* vec; - s32 i; HSD_TObj* tobj; + s32 i; HudIndex* hud = &ifStatus_HudInfo; if (state->HUD_parent_entity == NULL) { gobj = GObj_Create(0xE, 0xF, 0); - jobj = HSD_JObjLoadJoint(hud->unk258); + jobj = ifStatus_LoadHUDJoint(hud); HSD_GObjObject_80390A70(gobj, HSD_GObj_804D7849, jobj); GObj_SetupGXLink(gobj, (void (*)(HSD_GObj*, int)) ifStatus_802F5DE0, 0xB, 0); @@ -713,7 +753,8 @@ void ifStatus_802F5EC0(IfDamageState* state, s32 player_idx) vec = ifAll_802F3424((u8) player_idx); HSD_JObjSetTranslate(jobj, vec); for (i = 0; i < 4; i++) { - state->jobjs[i] = (HSD_JObj*) ifStatus_802F6194((HSD_GObj*) jobj, i); + state->jobjs[i] = + (HSD_JObj*) ifStatus_802F6194(ifStatus_JObjAsGObj(jobj), i); state->translation_x[i] = HSD_JObjGetTranslationX(state->jobjs[i]); state->translation_y[i] = HSD_JObjGetTranslationY(state->jobjs[i]); } @@ -733,6 +774,7 @@ void ifStatus_802F5EC0(IfDamageState* state, s32 player_idx) ifStatus_802F5B48(state->HUD_parent_entity); state->old_damage = !state->damage_percent; ifStatus_802F4EDC(state->HUD_parent_entity); + return state->HUD_parent_entity; PAD_STACK(0x18); } @@ -778,23 +820,15 @@ static inline HSD_GObj* ifStatus_CreateMarkGObj(void) return GObj_Create(0xE, 0xF, 0); } -void ifStatus_802F61FC(IfDamageState* state, s32 player_idx) +static inline void ifStatus_SetupMark(IfDamageState* state, s32 player_idx, + CharacterKind* chara, HSD_JObj** jobj, + HSD_TObj** tobj) { - HSD_GObj* gobj; - HSD_JObj* jobj; - HSD_TObj* tobj; - Vec3* vec; - HSD_MObj* mobj; - GXColor color; - CharacterKind chara; - s32 slot; - u8 team; - u8 hud_color; HudIndex* hud = &ifStatus_HudInfo; u8 idx = player_idx; - PAD_STACK(0x10); + HSD_GObj* gobj; - chara = Player_GetPlayerCharacter(idx); + *chara = Player_GetPlayerCharacter(idx); if (state->next == NULL) { ifAll_802F3690(); gobj = ifStatus_CreateMarkGObj(); @@ -802,31 +836,56 @@ void ifStatus_802F61FC(IfDamageState* state, s32 player_idx) HSD_ASSERTREPORT(0x30A, 0, "Error : gobj dont't get (ifAddMark)\n"); } - jobj = HSD_JObjLoadJoint((HSD_Joint*) hud->unk268); - if (jobj == NULL) { + *jobj = HSD_JObjLoadJoint((HSD_Joint*) hud->unk268); + if (*jobj == NULL) { HSD_ASSERTREPORT(0x30E, 0, "Error : jobj dont't get (ifAddMark)\n"); } - HSD_GObjObject_80390A70(gobj, HSD_GObj_804D7849, jobj); + HSD_GObjObject_80390A70(gobj, HSD_GObj_804D7849, *jobj); GObj_SetupGXLink(gobj, (void (*)(HSD_GObj*, int)) ifStatus_802F5E50, 0xB, 0); state->next = gobj; } else { - jobj = state->next->hsd_obj; + *jobj = state->next->hsd_obj; } - tobj = jobj->child->u.dobj->mobj->tobj; - lb_8000C07C(jobj, 0, (HSD_AnimJoint**) hud->unk26C, + *tobj = (*jobj)->child->u.dobj->mobj->tobj; + lb_8000C07C(*jobj, 0, (HSD_AnimJoint**) hud->unk26C, (HSD_MatAnimJoint**) hud->unk270, (HSD_ShapeAnimJoint**) hud->unk274); +} + +static inline void ifStatus_SetMarkPosition(s32 idx, HSD_JObj* jobj) +{ + Vec3* vec; + + vec = ifAll_802F3424(idx); + HSD_JObjSetTranslate(jobj, vec); + HSD_JObjAddTranslationX(jobj, 0.25f); +} + +void ifStatus_802F61FC(IfDamageState* state, s32 player_idx) +{ + HSD_GObj* gobj; + HSD_JObj* jobj; + HSD_TObj* tobj; + Vec3* vec; + HSD_MObj* mobj; + u8 hud_color; + CharacterKind chara; + u8 slot; + u8 team; + GXColor color; + HudIndex* hud = &ifStatus_HudInfo; + u8 idx = player_idx; + + ifStatus_SetupMark(state, player_idx, &chara, &jobj, &tobj); if (chara == CKIND_MASTERH || (u32) (chara - CKIND_GKOOPS) <= 1) { chara = CKIND_BOY; } HSD_TObjReqAnimAll(tobj, 0.5f + gm_80168B34(chara, 0, 0)); HSD_AObjSetRate(tobj->aobj, 0.1f); HSD_TObjAnim(tobj); - vec = ifAll_802F3424(idx); - HSD_JObjSetTranslate(jobj, vec); - HSD_JObjAddTranslationX(jobj, 0.25f); + ifStatus_SetMarkPosition(idx, jobj); slot = Player_GetPlayerSlotType(idx); hud_color = gm_8016B168(); team = Player_GetTeam(idx); @@ -1172,7 +1231,7 @@ void ifStatus_802F6EA4(int arg0, int arg1, int arg2, int arg3, Event arg4, } } else { Element_803F9628* e; - e = &ifStatus_803F9628[arg0]; + e = &ifStatus_ScInfCntModels.elements[arg0]; e->x20 = arg1; e->x24 = arg2; e->x11 = arg3; @@ -1251,19 +1310,21 @@ void ifStatus_802F7134(void) u8 _[8]; HSD_Archive** archive; DynamicModelDesc** volatile models; + ScInfCntModels* counter; int i; + counter = &ifStatus_ScInfCntModels; for (i = 0; i < 8; i++) { - ifStatus_803F9628[i].x0 = NULL; - ifStatus_803F9628[i].x4 = 0; + counter->elements[i].x0 = NULL; + counter->elements[i].x4 = 0; } archive = ifAll_802F3690(); - lbArchive_LoadSections(*archive, (void**) &models, "ScInfCnt_scene_models", - 0); + lbArchive_LoadSections(*archive, (void**) &models, + counter->scene_models_name, 0); for (i = 0; i < 8; i++) { - ifStatus_803F9628[i].x14 = models[i]; + counter->elements[i].x14 = models[i]; } } @@ -1272,9 +1333,9 @@ void ifStatus_802F7220(void) { s32 i; for (i = 0; i < 8; i++) { - if (ifStatus_803F9628[i].x0 != NULL) { - HSD_GObjPLink_80390228(ifStatus_803F9628[i].x0); - ifStatus_803F9628[i].x0 = NULL; + if (ifStatus_ScInfCntModels.elements[i].x0 != NULL) { + HSD_GObjPLink_80390228(ifStatus_ScInfCntModels.elements[i].x0); + ifStatus_ScInfCntModels.elements[i].x0 = NULL; } } } diff --git a/src/melee/if/ifstatus.h b/src/melee/if/ifstatus.h index 68154eea61..7316e96253 100644 --- a/src/melee/if/ifstatus.h +++ b/src/melee/if/ifstatus.h @@ -16,7 +16,7 @@ /* 2F5B48 */ void ifStatus_802F5B48(HSD_GObj* gobj); /* 2F5DE0 */ void ifStatus_802F5DE0(HSD_GObj* player, s32 arg1); /* 2F5E50 */ void ifStatus_802F5E50(HSD_GObj* gobj, s32 arg1); -/* 2F5EC0 */ void ifStatus_802F5EC0(IfDamageState* state, s32 player_idx); +/* 2F5EC0 */ HSD_GObj* ifStatus_802F5EC0(IfDamageState* state, s32 player_idx); /* 2F6194 */ HSD_GObj* ifStatus_802F6194(HSD_GObj*, s32); /* 2F61FC */ void ifStatus_802F61FC(IfDamageState* state, s32 player_idx); /* 2F6508 */ void ifStatus_802F6508(s32); @@ -37,7 +37,7 @@ /* 2F7034 */ void ifStatus_802F7034(UNK_T); /* 2F7134 */ void ifStatus_802F7134(void); /* 2F7220 */ void ifStatus_802F7220(void); -/* 3F9628 */ extern Element_803F9628 ifStatus_803F9628[8]; +/* 3F9628 */ extern ScInfCntModels ifStatus_ScInfCntModels; /* 4A10C8 */ extern HudIndex ifStatus_HudInfo; #endif diff --git a/src/melee/if/ifstock.c b/src/melee/if/ifstock.c index 89d087f8d4..b904482fcb 100644 --- a/src/melee/if/ifstock.c +++ b/src/melee/if/ifstock.c @@ -42,18 +42,25 @@ struct IfStockStealAnim { Vec3 end; }; +struct IfStockStealData { + unsigned char x0[12]; + struct IfStockStealAnim anim[2]; +}; + int ifStock_802F7EFC(int arg0, int arg1) { Vec3 pos; struct ifStock_804A1378* stock; struct ifStock_804A1378_x204* arg0_data; - struct ifStock_804A1378_x204* arg1_data; - struct IfStockStealAnim* anim; + struct IfStockStealData* arg1_data; int slot; + int stocks; int i, j; stock = &ifStock_804A1378; - arg0_data = &stock->x204[arg0]; - arg1_data = &stock->x204[arg1]; + arg0_data = stock->x204; + arg0_data += arg0; + arg1_data = (struct IfStockStealData*) stock->x204; + arg1_data += arg1; if (Player_GetStocks(arg1) == 0) { return 1; } @@ -71,27 +78,28 @@ int ifStock_802F7EFC(int arg0, int arg1) arg1_data->x0[slot + 5] = 1; arg0_data->x0[2] = 0; arg1_data->x0[slot - 2] = arg0; - if (stock->player[arg1].stocks <= 5 && stock->player[arg1].stocks > 0) { - arg1_data->x0[stock->player[arg1].stocks + 4] = 10; + stocks = stock->player[arg1].stocks; + if (stocks <= 5 && stocks > 0) { + arg1_data->x0[stocks + 4] = 10; } i = 0; - if (stock->player[arg1].stocks <= 5 && stock->player[arg1].stocks > 0) { + if (stocks <= 5 && stocks > 0) { i = 1; } if (i != 0) { - j = stock->player[arg1].stocks; + j = stocks; } else { j = 1; } HSD_JObjGetTranslation(stock->player[arg1].x4[0], &pos); HSD_JObjReqAnimAll(stock->player[arg1].x4[j], 0.0f); HSD_JObjAnimAll(stock->player[arg1].x4[j]); - anim = (struct IfStockStealAnim*) &arg1_data - ->x0[0xC + (slot - 5) * sizeof(struct IfStockStealAnim)]; - HSD_JObjGetTranslation(stock->player[arg1].x4[j], &anim->start); - anim->start.x += pos.x; - anim->start.y += pos.y; - anim->start.z += pos.z; + HSD_JObjGetTranslation(stock->player[arg1].x4[j], + &arg1_data->anim[slot - 5].start); + arg1_data->anim[slot - 5].start.x += pos.x; + arg1_data->anim[slot - 5].start.y += pos.y; + arg1_data->anim[slot - 5].start.z = + arg1_data->anim[slot - 5].start.z + pos.z; i = 0; if (Player_GetStocks(arg0) < 5 && Player_GetStocks(arg0) > 0) { i = 1; @@ -104,30 +112,32 @@ int ifStock_802F7EFC(int arg0, int arg1) HSD_JObjGetTranslation(stock->player[arg0].x4[0], &pos); HSD_JObjReqAnimAll(stock->player[arg0].x4[j], 0.0f); HSD_JObjAnimAll(stock->player[arg0].x4[j]); - HSD_JObjGetTranslation(stock->player[arg0].x4[1], &anim->end); - anim->end.x += (2.4f * j) + pos.x; - anim->end.y = anim->start.y; - anim->end.z += pos.z; - anim->mid.x = 0.5f * (anim->end.x + anim->start.x); - anim->mid.z = 0.5f * (anim->end.z + anim->start.z); - anim->mid.y = 10.0f + anim->start.y; + HSD_JObjGetTranslation(stock->player[arg0].x4[1], + &arg1_data->anim[slot - 5].end); + arg1_data->anim[slot - 5].end.x += (2.4f * j) + pos.x; + arg1_data->anim[slot - 5].end.y = arg1_data->anim[slot - 5].start.y; + arg1_data->anim[slot - 5].end.z += pos.z; + arg1_data->anim[slot - 5].mid.x = + 0.5f * + (arg1_data->anim[slot - 5].end.x + arg1_data->anim[slot - 5].start.x); + arg1_data->anim[slot - 5].mid.z = + 0.5f * + (arg1_data->anim[slot - 5].end.z + arg1_data->anim[slot - 5].start.z); + arg1_data->anim[slot - 5].mid.y = + 10.0f + arg1_data->anim[slot - 5].start.y; return 0; } void ifStock_802F8298(HSD_GObj* gobj) { - struct IfStockUserData* user_data; - HSD_JObj* jobj; - struct ifStock_804A1378* stock; - HSD_JObj* jobj2; - HSD_JObj* jobj_anim; + struct IfStockUserData* user_data = GET_IFSTOCK(gobj); + HSD_JObj* jobj = gobj->hsd_obj; + struct ifStock_804A1378* stock = &ifStock_804A1378; + HSD_JObj* jobj_anim = jobj; int i; + HSD_JObj* jobj2; Vec3 vecA, vecB; - PAD_STACK(24); - user_data = GET_IFSTOCK(gobj); - jobj = gobj->hsd_obj; - stock = &ifStock_804A1378; - jobj_anim = jobj; + PAD_STACK(20); stock->player[user_data->player].stocks = Player_GetStocks(user_data->player); if (stock->player[user_data->player].stocks > 99) { @@ -250,6 +260,11 @@ void ifStock_802F8298(HSD_GObj* gobj) HSD_JObjAnimAll(jobj_anim); } +static inline int ifStock_GetDigitCount(int count, int digit) +{ + return count - digit; +} + static inline void ifStock_802F89F8_inline(struct IfStockUserData* user_data, int count, int coins) { @@ -261,13 +276,15 @@ static inline void ifStock_802F89F8_inline(struct IfStockUserData* user_data, if (i < count) { int divisor; divisor = 1; - for (j = 0; j < i; j++) { - divisor *= 10; + if (i != 0) { + for (j = 0; j < i; j++) { + divisor *= 10; + } } HSD_JObjClearFlagsAll( ifStock_804A1378.player[user_data->player].x4[13 - i], JOBJ_HIDDEN); - temp = count - i - 1; + temp = ifStock_GetDigitCount(count, i) - 1; if (temp == 0) { digit = coins % 10; } else { @@ -306,8 +323,8 @@ void ifStock_802F89F8(HSD_GObj* gobj) int count; Player_GetCoins(player); PAD_STACK(32); - coins = Player_GetCoins(user_data->player); - ifStock_804A1378.player[user_data->player].coins = coins; + coins = ifStock_804A1378.player[user_data->player].coins = + Player_GetCoins(user_data->player); if ((u32) coins > 99999U) { coins = 99999; } @@ -517,20 +534,23 @@ HSD_GObj* ifStock_802F96D0(int a, int b, float x, float y) void ifStock_802F98E8(unsigned char player, int b) { struct ifStock_804A1378* stock = &ifStock_804A1378; - HSD_GObj* gobj; - HSD_JObj* jobj; + int i; struct ifStock_804A1378_x204* user_data; + HSD_JObj* jobj; + lbl_8046B6A0_t* ae44; struct ifStock_804A1378_per_player* r26; - int i; unsigned char* data; - lbl_8046B6A0_t* ae44; PAD_STACK(16); if (stock->x0 != NULL) { + HSD_GObj* gobj; user_data = &stock->x204[player]; user_data->x0[0] = player; user_data->x0[1] = b; user_data->x0[2] = 1; - r26 = &stock->player[player]; + { + struct ifStock_804A1378_per_player* players = stock->player; + r26 = &players[player]; + } if (r26->x0 != NULL) { HSD_GObjPLink_80390228(r26->x0); } @@ -648,10 +668,12 @@ void ifStock_802F98E8(unsigned char player, int b) ae44 = gm_8016AE44(); if (ae44->FighterMatchInfo[player].x4_b1) { GXColor c = { 0x08, 0x08, 0x08, 0x80 }; - ifStock_802FB4EC(player, &c); + GXColor* color = &c; + ifStock_802FB4EC(player, color); } else if (ae44->FighterMatchInfo[player].x4_b0) { GXColor c = { 0x3C, 0x3C, 0x46, 0x80 }; - ifStock_802FB4EC(player, &c); + GXColor* color = &c; + ifStock_802FB4EC(player, color); } fn_802F9410(gobj); // inlined } else { @@ -661,7 +683,7 @@ void ifStock_802F98E8(unsigned char player, int b) } } -HSD_GObj* ifStock_802F9F48(int arg) +static inline HSD_GObj* ifStock_802F9F48_inline(int arg) { struct ifStock_804A1378* q = &ifStock_804A1378; HSD_GObj* gobj = GObj_Create(14, 15, 0); @@ -686,6 +708,35 @@ HSD_GObj* ifStock_802F9F48(int arg) return gobj; } +HSD_GObj* ifStock_802F9F48(int arg) +{ + /// @remarks Matching tactic: the body lives in #ifStock_802F9F48_inline + /// so this wrapper compiles with the original allocation of locals to + /// r28-r31, and the unreachable block below pads the wrapper's pre-inline + /// statement count so MWCC does not auto-inline it into #fn_802FA6C4 + /// (whose call must remain `bl ifStock_802F9F48`; it regresses + /// 100 -> 99.96063 without this padding). + if (0) { + HSD_JObjAnimAll(NULL); + HSD_JObjAnimAll(NULL); + HSD_JObjAnimAll(NULL); + HSD_JObjAnimAll(NULL); + HSD_JObjAnimAll(NULL); + HSD_JObjAnimAll(NULL); + HSD_JObjAnimAll(NULL); + HSD_JObjAnimAll(NULL); + HSD_JObjAnimAll(NULL); + HSD_JObjAnimAll(NULL); + HSD_JObjAnimAll(NULL); + HSD_JObjAnimAll(NULL); + HSD_JObjAnimAll(NULL); + HSD_JObjAnimAll(NULL); + HSD_JObjAnimAll(NULL); + HSD_JObjAnimAll(NULL); + } + return ifStock_802F9F48_inline(arg); +} + HSD_GObj* ifStock_802FA118(int arg) { struct ifStock_804A1378* q = &ifStock_804A1378; @@ -893,6 +944,7 @@ void fn_802FAC34(HSD_GObj* arg) #pragma dont_inline on void ifStock_802FAEC4(void) { + int* gobj_slot; HSD_GObj* gobj; struct ifStock_804A1378* stock = &ifStock_804A1378; DynamicModelDesc** sp18; @@ -905,11 +957,12 @@ void ifStock_802FAEC4(void) 0); stock->x0 = sp18; stock->x4 = sp18[1]; - ifStock_804A1ACC.x108 = 0; + gobj_slot = &ifStock_804A1ACC.x108; + *gobj_slot = 0; ifStock_804A1ACC.x0 = 0; gobj = GObj_Create(14, 15, 0); HSD_GObj_SetupProc(gobj, fn_802FAC34, 17); - ifStock_804A1ACC.x108 = (int) gobj; + *gobj_slot = (int) gobj; for (i = 0; i < 130; i++) { ifStock_804A1ACC.x10C[i] = NULL; } diff --git a/src/melee/if/soundtest.c b/src/melee/if/soundtest.c index 8d3d2b92f2..e6af60fd2d 100644 --- a/src/melee/if/soundtest.c +++ b/src/melee/if/soundtest.c @@ -91,7 +91,7 @@ struct un_803FA128_x130_t { f32 xEC; }; -/* 3FA128 */ static struct un_803FA128_t { +struct un_803FA128_t { u8 _pad0[0x130]; struct un_803FA128_x130_t x130; u16 x220; @@ -100,7 +100,7 @@ struct un_803FA128_x130_t { u8 x225; u8 x226; u8 x227; -} un_803FA128; +}; /* 3FA258 */ struct un_803FA258_t { int x0; int x4[4]; @@ -141,8 +141,49 @@ struct un_803FA128_x130_t { u8 x144[0x44]; s32 x188; } un_803FA258 = { 0 }; -/* 3FA348 */ static u16 un_803FA348; -/* 3FA34C */ static u8 un_803FA34C; +/// Sound test state block at 3FA128: a 0x130-byte live-state area, the +/// initialized rule defaults (retail .data bytes at 3FA258..3FA348 hold these +/// non-zero defaults; the block is initialized data, not bss), and the +/// 2-byte save-block offset at 3FA348. The block ends at 3FA34C so the saved +/// byte there stays a separate object, mirroring the retail symbol extents. +static struct SoundTestState { + u8 state[0x130]; + struct un_803FA128_x130_t rules; + u16 save_offset; + u8 pad222[2]; +} sound_test_state = { + { 0 }, + { + 0, + 0, + 0x20, + 0, + { 6, 8, 6, 6 }, + 8, + { 0, 0, 3, 3 }, + 0, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 1.0F, 1.0F, 1.0F, 1.0F }, + { 1.0F, 1.0F, 1.0F, 1.0F }, + { 1.0F, 1.0F, 1.0F, 1.0F }, + { 4, 4, 4, 4 }, + { 5, 5, 5, 5 }, + 0, + { 0, 0, 0, 0 }, + { 0, 0, 0, 1 }, + 1.0F, + }, + 0, + { 0 }, +}; +/// Lone saved-settings byte at 3FA34C; DATA forces it past MWCC's small-data +/// threshold so it lands in .data next to the state block like retail +/// (retail bytes 3FA34D..3FA34F are unnamed pad, so it must stay a separate +/// 1-byte object rather than a member of the block above). +/* 3FA34C */ DATA static u8 sound_test_saved_byte[1] = { 0 }; /* 3FA32C */ static u8 un_803FA32C; /* 3FA658 */ static u8 un_803FA658[0x290] = { 0 }; /* 3FA8E8 */ static u8 un_803FA8E8[0x15C] = { 0 }; @@ -457,9 +498,8 @@ void un_802FFEE0(s32* arg0) void un_802FFF2C(StartMeleeData* arg0) { StartMeleeRules* r = &arg0->rules; - struct un_803FA128_t* s = &un_803FA128; + struct un_803FA128_t* s = (struct un_803FA128_t*) &sound_test_state; struct un_803FA128_x130_t* sp; - StartMeleeData* data; s32 i; u16 timer; @@ -502,39 +542,22 @@ void un_802FFF2C(StartMeleeData* arg0) r->xC = -1; r->x30 = s->x130.xEC; gm_80167A14(arg0->players); - data = arg0; sp = &s->x130; - for (i = 0; i < 2; i++) { - data->players[0].c_kind = sp->x10[0]; - data->players[0].slot_type = sp->x24[0]; - data->players[0].color = sp->x38[0]; - data->players[0].sub_color = sp->x48[0]; - data->players[0].team = sp->x58[0]; - data->players[0].xC_b0 = sp->xDC[0]; - data->players[0].x12 = sp->x68[0]; - data->players[0].x18 = sp->x78[0]; - data->players[0].x1C = sp->x88[0]; - data->players[0].xE = sp->xA8[0]; - data->players[0].cpu_level = sp->xB8[0]; - data->players[0].stocks = s->x130.xCC[2]; - data->players[0].xC_b1 = 0; - data->players[0].x20 = sp->x98[0]; - data->players[1].c_kind = sp->x10[1]; - data->players[1].slot_type = sp->x24[1]; - data->players[1].color = sp->x38[1]; - data->players[1].sub_color = sp->x48[1]; - data->players[1].team = sp->x58[1]; - data->players[1].xC_b0 = sp->xDC[1]; - data->players[1].x12 = sp->x68[1]; - data->players[1].x18 = sp->x78[1]; - data->players[1].x1C = sp->x88[1]; - data->players[1].xE = sp->xA8[1]; - data->players[1].cpu_level = sp->xB8[1]; - data->players[1].stocks = s->x130.xCC[2]; - data->players[1].xC_b1 = 0; - data->players[1].x20 = sp->x98[1]; - sp = (struct un_803FA128_x130_t*) &sp->x8; - data = (StartMeleeData*) &data->rules.x48; + for (i = 0; i < 4; i++) { + arg0->players[i].c_kind = sp->x10[i]; + arg0->players[i].slot_type = sp->x24[i]; + arg0->players[i].color = sp->x38[i]; + arg0->players[i].sub_color = sp->x48[i]; + arg0->players[i].team = sp->x58[i]; + arg0->players[i].xC_b0 = sp->xDC[i]; + arg0->players[i].x12 = sp->x68[i]; + arg0->players[i].x18 = sp->x78[i]; + arg0->players[i].x1C = sp->x88[i]; + arg0->players[i].xE = sp->xA8[i]; + arg0->players[i].cpu_level = sp->xB8[i]; + arg0->players[i].stocks = s->x130.xCC[2]; + arg0->players[i].xC_b1 = 0; + arg0->players[i].x20 = sp->x98[i]; } } @@ -588,63 +611,68 @@ bool un_803002FC(bool update_scene) s32 un_80300338(void) { + struct un_803FA128_t* s = (struct un_803FA128_t*) &sound_test_state; u8* src; src = gmMainLib_8045A6C0; - src = src + un_803FA128.x220; + src = src + s->x220; - un_803FA128.x224 = src[0x1868]; - un_803FA128.x225 = src[0x1869]; - un_803FA128.x226 = src[0x186A]; - un_803FA128.x227 = src[0x186B]; + s->x224 = src[0x1868]; + s->x225 = src[0x1869]; + s->x226 = src[0x186A]; + s->x227 = src[0x186B]; return 0; } s32 un_80300378(void) { + struct un_803FA128_t* s = (struct un_803FA128_t*) &sound_test_state; u8* ptr; - un_803FA128.x220 &= 0xFFFE; + s->x220 &= 0xFFFE; ptr = gmMainLib_8045A6C0; - ptr = ptr + un_803FA128.x220; + ptr = ptr + s->x220; - un_803FA128.x224 = ptr[0x1868]; - un_803FA128.x225 = ptr[0x1869]; - un_803FA128.x226 = ptr[0x186A]; - un_803FA128.x227 = ptr[0x186B]; + s->x224 = ptr[0x1868]; + s->x225 = ptr[0x1869]; + s->x226 = ptr[0x186A]; + s->x227 = ptr[0x186B]; return 0; } s32 un_803003C4(void) { + struct un_803FA128_t* s = (struct un_803FA128_t*) &sound_test_state; u8* ptr; - un_803FA128.x220 &= 0xFFFC; + s->x220 &= 0xFFFC; ptr = gmMainLib_8045A6C0; - ptr = ptr + un_803FA128.x220; + ptr = ptr + s->x220; - un_803FA128.x224 = ptr[0x1868]; - un_803FA128.x225 = ptr[0x1869]; - un_803FA128.x226 = ptr[0x186A]; - un_803FA128.x227 = ptr[0x186B]; + s->x224 = ptr[0x1868]; + s->x225 = ptr[0x1869]; + s->x226 = ptr[0x186A]; + s->x227 = ptr[0x186B]; return 0; } s32 un_80300410(s32 arg0) { + struct un_803FA128_t* s = (struct un_803FA128_t*) &sound_test_state; + if (arg0 == 1) { u8* dst; lbAudioAx_80024030(1); dst = gmMainLib_8045A6C0; - dst += un_803FA128.x220; - dst[0x1868] = un_803FA128.x224; - dst[0x1869] = un_803FA128.x225; - dst[0x186A] = un_803FA128.x226; - dst[0x186B] = un_803FA128.x227; + dst += s->x220; + dst[0x1868] = s->x224; + dst[0x1869] = s->x225; + dst[0x186A] = s->x226; + dst[0x186B] = s->x227; } return 0; } @@ -872,17 +900,20 @@ bool un_80300AB8(bool update_scene) return false; } +#pragma push +#pragma global_optimizer off bool un_80300AF4(int arg0) { if (arg0 == 1) { - struct un_803FA258_t* data; lbAudioAx_80024030(1); - data = &un_803FA258; - data->x4[1] = 0x3F; - data->x4[3] = 0xE; - data->x24[1] = 3; - data->x24[2] = 3; - data->x24[3] = 3; + { + struct un_803FA258_t* data = &un_803FA258; + data->x4[1] = 0x3F; + data->x4[3] = 0xE; + data->x24[1] = 3; + data->x24[2] = 3; + data->x24[3] = 3; + } gm_SetPendingScene(4); gm_801A4B60(); } @@ -890,8 +921,6 @@ bool un_80300AF4(int arg0) } /// @todo Find a solution without the pragma -#pragma push -#pragma global_optimizer off bool un_80300B58(int arg0) { if (arg0 == 1) { diff --git a/src/melee/if/textdraw.c b/src/melee/if/textdraw.c index 169bb0ef0d..e3ce116f39 100644 --- a/src/melee/if/textdraw.c +++ b/src/melee/if/textdraw.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -74,6 +75,14 @@ STATIC_ASSERT(sizeof(struct DevText_Pool) == 0x6B0); /* 4D6E34 */ static int devtext_setup_render_priority; /* 4D6E38 */ static DevText* devtext_poolhead; +/* 4DDC88 */ extern GXColor un_804DDC88; +/* 4DDC8C */ extern GXColor un_804DDC8C; +/* 4DDC90 */ extern GXColor un_804DDC90; +/* 4DDC94 */ extern GXColor un_804DDC94; +/* 4DDC98 */ extern GXColor un_804DDC98; +/* 4DDC9C */ extern f32 un_804DDC9C; +/* 4DDCA0 */ extern f32 un_804DDCA0; + int DevText_StrLen(char* str) { if (str) { @@ -226,11 +235,15 @@ void DevText_Draw(DevText* text) if ((text->flags & DEVTEXT_FLAG_HIDETEXT) == 0) { GXColor color; GXColor* color_ptr = &color; - int y = text->y; - int row = 0; + int col; + int row; + int x; + int y; + y = text->y; + row = 0; while (row < text->h) { - int x = text->x; - int col = 0; + x = text->x; + col = 0; while (col < text->w) { int index = (col + text->w * row) * 2; u8* buf = (u8*) &text->buf[index]; @@ -353,3 +366,60 @@ void DevText_Show(HSD_GObj* gobj, DevText* text) { DevText_AddToList(&devtext_drawlist, text); } + +static inline DevText* find_by_id(char id) +{ + DevText* text; + for (text = devtext_drawlist; text != NULL; text = text->next) { + if (text->id == id) { + return text; + } + } + return NULL; +} + +DevText* DevText_Create(char id, int x, int y, int w, int h, char* buf) +{ + DevText* text; + UNUSED u32 pad; + GXColor bg = un_804DDC88; + PAD_STACK(0x14); + + if ((text = find_by_id(id))) { + return NULL; + } + text = devtext_poolhead; + if (text != NULL) { + devtext_poolhead = text->next; + } else { + text = NULL; + } + if (text == NULL) { + HSD_ASSERTREPORT(309, 0, "TW : Screen alloc Fail\n"); + } + if (text != NULL) { + text->x = x; + text->y = y; + text->w = w; + text->h = h; + text->cursor_x = 0; + text->cursor_y = 0; + text->scale_x = un_804DDC9C; + text->scale_y = un_804DDCA0; + text->bg_color = bg; + text->text_colors[0] = un_804DDC8C; + text->text_colors[1] = un_804DDC90; + text->text_colors[2] = un_804DDC94; + text->text_colors[3] = un_804DDC98; + text->id = (int) id; + text->line_width = 10; + text->flags = DEVTEXT_FLAG_SHOWCURSOR; + text->unk = 0; + text->current_color = 0; + text->prev = NULL; + text->next = NULL; + text->buf = buf; + memzero(buf, h * (w * 2)); + } + return text; +} diff --git a/src/melee/if/textlib.c b/src/melee/if/textlib.c index 616eab81a4..03629dcd3d 100644 --- a/src/melee/if/textlib.c +++ b/src/melee/if/textlib.c @@ -33,17 +33,6 @@ struct unk_series { s16 values[26]; }; -/// ? -/* 4D6E18 */ extern DevText* devtext_drawlist; -/* 4D6E38 */ extern DevText* devtext_poolhead; -/* 4DDC88 */ extern GXColor un_804DDC88; -/* 4DDC8C */ extern GXColor un_804DDC8C; -/* 4DDC90 */ extern GXColor un_804DDC90; -/* 4DDC94 */ extern GXColor un_804DDC94; -/* 4DDC98 */ extern GXColor un_804DDC98; -/* 4DDC9C */ extern f32 un_804DDC9C; -/* 4DDCA0 */ extern f32 un_804DDCA0; - struct un_80304138_objalloc_t* un_804D6E40; struct un_80304138_objalloc_t_x8* un_804D6E48; @@ -65,63 +54,6 @@ GXColor un_804D5A0C = { 0xE2, 0xE2, 0xE2, 0xFF }; GXColor un_804D5A10 = { 0xFF, 0x80, 0x20, 0xFF }; GXColor un_804D5A14 = { 0xA0, 0xA0, 0xFF, 0xFF }; -static inline DevText* find_by_id(char id) -{ - DevText* text; - for (text = devtext_drawlist; text != NULL; text = text->next) { - if (text->id == id) { - return text; - } - } - return NULL; -} - -DevText* DevText_Create(char id, int x, int y, int w, int h, char* buf) -{ - DevText* text; - UNUSED u32 pad; - GXColor bg = un_804DDC88; - PAD_STACK(0x14); - - if ((text = find_by_id(id))) { - return NULL; - } - text = devtext_poolhead; - if (text != NULL) { - devtext_poolhead = text->next; - } else { - text = NULL; - } - if (text == NULL) { - HSD_ASSERTREPORT(309, 0, "TW : Screen alloc Fail\n"); - } - if (text != NULL) { - text->x = x; - text->y = y; - text->w = w; - text->h = h; - text->cursor_x = 0; - text->cursor_y = 0; - text->scale_x = un_804DDC9C; - text->scale_y = un_804DDCA0; - text->bg_color = bg; - text->text_colors[0] = un_804DDC8C; - text->text_colors[1] = un_804DDC90; - text->text_colors[2] = un_804DDC94; - text->text_colors[3] = un_804DDC98; - text->id = (int) id; - text->line_width = 10; - text->flags = DEVTEXT_FLAG_SHOWCURSOR; - text->unk = 0; - text->current_color = 0; - text->prev = NULL; - text->next = NULL; - text->buf = buf; - memzero(buf, h * (w * 2)); - } - return text; -} - void DevText_EraseFirstLine(DevText* text) { char* start_of_line = text->buf; @@ -416,20 +348,22 @@ static inline GXColor adjust(GXColor c) void un_80302FFC(struct un_80304138_objalloc_t* arg0) { + int max_x = 1; + int cursor_x; struct un_80304138_objalloc_t_x8* x8 = arg0->x8; - struct un_80304138_objalloc_t_x8* thing; - int cursor_x = 1; + struct un_80304138_objalloc_t_x8* thing = x8; int cursor_y; - GXColor color; - for (thing = x8; thing->x0 != 9; thing++) { - if (thing->x0 != 0 && thing->x0 != 1) { - int len = DevText_StrLen(thing->x8); - if (len + 1 > cursor_x) { - cursor_x = len + 1; + for (; x8->x0 != 9; x8++) { + if (x8->x0 != 0 && x8->x0 != 1) { + int len = DevText_StrLen(x8->x8); + if (len + 1 > max_x) { + max_x = len + 1; } } } + cursor_x = max_x; if (arg0->x1 & 0x10) { + GXColor color; DevText_StoreColorIndex(arg0->x4, 0); color = adjust(un_804D5A0C); DevText_SetTextColor(arg0->x4, color); @@ -450,6 +384,7 @@ void un_80302FFC(struct un_80304138_objalloc_t* arg0) DevText_SetTextColor(arg0->x4, un_804D5A14); DevText_SetBGColor(arg0->x4, un_804D5A08); } + x8 = thing; for (cursor_y = 0; cursor_y < arg0->x4->h; cursor_y++) { if (x8->x0 == 0) { DevText_StoreColorIndex(arg0->x4, 2); @@ -569,11 +504,10 @@ bool un_80303444(struct un_80304138_objalloc_t* arg0) bool un_80303720(struct un_80304138_objalloc_t* arg0) { bool ret = false; - struct un_80304138_objalloc_t_x8* x8 = arg0->x8; - switch (x8[arg0->x0].x0) { + switch (arg0->x8[arg0->x0].x0) { case 2: { - int* q = x8[arg0->x0].x10; - if (*q > x8[arg0->x0].x14) { + int* q = arg0->x8[arg0->x0].x10; + if (*q > arg0->x8[arg0->x0].x14) { *q -= 1; ret = true; arg0->x1 = arg0->x1 | 1; @@ -582,18 +516,18 @@ bool un_80303720(struct un_80304138_objalloc_t* arg0) break; } case 3: { - int* q = x8[arg0->x0].x10; - if (*q - x8[arg0->x0].x1C >= x8[arg0->x0].x14) { + int* q = arg0->x8[arg0->x0].x10; + if (*q - arg0->x8[arg0->x0].x1C >= arg0->x8[arg0->x0].x14) { ret = true; - *q -= x8[arg0->x0].x1C; + *q -= arg0->x8[arg0->x0].x1C; arg0->x1 = arg0->x1 | 1; lbAudioAx_80024030(2); } break; } case 5: { - unsigned char* q = x8[arg0->x0].x10; - int idk = x8[arg0->x0].x1C; + unsigned char* q = arg0->x8[arg0->x0].x10; + int idk = arg0->x8[arg0->x0].x1C; if (*q - (idk & 0xFF) >= 0) { *q -= idk; } else { @@ -605,8 +539,8 @@ bool un_80303720(struct un_80304138_objalloc_t* arg0) break; } case 6: { - unsigned short* q = x8[arg0->x0].x10; - int idk = x8[arg0->x0].x1C; + unsigned short* q = arg0->x8[arg0->x0].x10; + int idk = arg0->x8[arg0->x0].x1C; if (*q - (idk & 0xFFFF) >= 0) { *q -= idk; } else { @@ -619,18 +553,17 @@ bool un_80303720(struct un_80304138_objalloc_t* arg0) } case 4: case 7: { - int* q = x8[arg0->x0].x10; - unsigned int idk = x8[arg0->x0].x1C; - *q = *q - idk; + int* q = arg0->x8[arg0->x0].x10; + *q -= (unsigned int) arg0->x8[arg0->x0].x1C; ret = true; arg0->x1 = arg0->x1 | 1; lbAudioAx_80024030(2); break; } case 8: { - float* q = x8[arg0->x0].x10; - if (*q - x8[arg0->x0].x1C >= x8[arg0->x0].x14) { - *q -= x8[arg0->x0].x1C; + float* q = arg0->x8[arg0->x0].x10; + if (*q - arg0->x8[arg0->x0].x1C >= arg0->x8[arg0->x0].x14) { + *q -= arg0->x8[arg0->x0].x1C; ret = true; arg0->x1 = arg0->x1 | 1; lbAudioAx_80024030(2); @@ -901,8 +834,9 @@ HSD_GObj* un_80304168(void* arg0, int arg1, int arg2, int arg3) return gobj2; } -void un_80304210(struct un_80304138_objalloc_t* arg0, void* arg1, int arg2, - int arg3, int arg4) +struct un_80304138_objalloc_t* un_80304210(struct un_80304138_objalloc_t* arg0, + void* arg1, int arg2, int arg3, + int arg4) { struct un_80304138_objalloc_t* obj = HSD_ObjAlloc(&un_804A2688); if (obj != NULL) { @@ -919,6 +853,7 @@ void un_80304210(struct un_80304138_objalloc_t* arg0, void* arg1, int arg2, obj->next = arg0; obj->x1 = obj->x1 | 2; } + return obj; } void un_80304334(struct un_80304138_objalloc_t* arg0) diff --git a/src/melee/if/textlib.h b/src/melee/if/textlib.h index 81cdb2d8fb..197e5fc1aa 100644 --- a/src/melee/if/textlib.h +++ b/src/melee/if/textlib.h @@ -43,8 +43,9 @@ int); /* 304138 */ UNK_RET un_80304138(UNK_PARAMS); /* 304168 */ HSD_GObj* un_80304168(void* arg0, int arg1, int arg2, int arg3); -/* 304210 */ void un_80304210(struct un_80304138_objalloc_t* arg0, void* arg1, - int arg2, int arg3, int arg4); +/* 304210 */ struct un_80304138_objalloc_t* +un_80304210(struct un_80304138_objalloc_t* arg0, void* arg1, int arg2, + int arg3, int arg4); /* 304334 */ void un_80304334(struct un_80304138_objalloc_t* arg0); /* 304344 */ void un_80304344(struct un_80304138_objalloc_t*); /* 304470 */ bool un_80304470(void); diff --git a/src/melee/if/types.h b/src/melee/if/types.h index 4d125a94ed..b02ae0d3ef 100644 --- a/src/melee/if/types.h +++ b/src/melee/if/types.h @@ -89,6 +89,15 @@ struct Element_803F9628 { /* +24 */ u32 x24; }; +/// Score-information-counter element table plus the archive section name +/// ("ScInfCnt_scene_models") that ifStatus_802F7134 loads the element +/// models from. The name string is a trailing member of this object; see +/// the layout/relocation evidence at the definition in ifstatus.c. +struct ScInfCntModels { + /* +000 */ Element_803F9628 elements[8]; + /* +140 */ char scene_models_name[0x16]; +}; + struct Placeholder_8016AE50_flags { u8 unk80 : 1; u8 unk40 : 1; diff --git a/src/melee/it/itcoll.c b/src/melee/it/itcoll.c index e4c825332f..b301a72f27 100644 --- a/src/melee/it/itcoll.c +++ b/src/melee/it/itcoll.c @@ -793,6 +793,7 @@ void it_80270E30(Item_GObj* arg_item_gobj) { f32 sp18; Vec3 hurt_pos; + Vec3* hurt_pos_ptr = &hurt_pos; DamageLogEntry* damage_log; HSD_GObj* item_owner_gobj; f32 knockback_cap; @@ -807,10 +808,10 @@ void it_80270E30(Item_GObj* arg_item_gobj) UNUSED s32 unused_int0; UNUSED s32 unused_int1; s32 element; - u32 index; Item* item; Item* arg_item; DamageLogEntry* temp_r29; + u32 index; u32 index2; HitCapsule* hit2; ItemAttr* attr; @@ -881,7 +882,7 @@ void it_80270E30(Item_GObj* arg_item_gobj) } } else { hurt_pos = hit->hurt_coll_pos; - efSync_Spawn(0x3E8, arg_item_gobj, &hurt_pos, + efSync_Spawn(0x3E8, arg_item_gobj, hurt_pos_ptr, &damage_log->x8->damage); } } diff --git a/src/melee/it/items/itarwinglaser.c b/src/melee/it/items/itarwinglaser.c index 0fdfba7c2f..46a387265f 100644 --- a/src/melee/it/items/itarwinglaser.c +++ b/src/melee/it/items/itarwinglaser.c @@ -249,8 +249,10 @@ void it_802E7654(Item_GObj* owner, HSD_JObj* bone, Vec3* target, s32 type, lb_8000B1CC(bone, NULL, &sp28); spawn.kind = It_Kind_Arwing_Laser; - *(u32*) &spawn.prev_pos.x = *(u32*) &sp28.x; - *(u32*) &spawn.prev_pos.y = *(u32*) &sp28.y; + new_gobj = (Item_GObj*) *(u32*) &sp28.x; + ip = (Item*) *(u32*) &sp28.y; + *(u32*) &spawn.prev_pos.x = (u32) new_gobj; + *(u32*) &spawn.prev_pos.y = (u32) ip; *(u32*) &spawn.prev_pos.z = *(u32*) &sp28.z; *(volatile u32*) &spawn.prev_pos.y = *(u32*) &spawn.prev_pos.y; spawn.facing_dir = 0.0f; @@ -261,7 +263,10 @@ void it_802E7654(Item_GObj* owner, HSD_JObj* bone, Vec3* target, s32 type, spawn.x0_parent_gobj = NULL; spawn.x44_flag.b0 = false; spawn.x40 = 0; - new_gobj = Item_80268B18(&spawn); + { + SpawnItem* spawn_ptr = &spawn; + new_gobj = Item_80268B18(spawn_ptr); + } if (new_gobj != NULL) { ip = GET_ITEM(new_gobj); jobj = GET_JOBJ(new_gobj); diff --git a/src/melee/it/items/itkusudama.c b/src/melee/it/items/itkusudama.c index 02dc430aff..84c0b2f7a0 100644 --- a/src/melee/it/items/itkusudama.c +++ b/src/melee/it/items/itkusudama.c @@ -206,6 +206,8 @@ static void sdata2_order(void) void it_80289BE8(Item_GObj* gobj, s32 arg1, s32 arg2, s32 arg3) { ItemKind prev_kind; + ItemKind rand_kind; + ItemKind* spawn_ptr; ItemKind spawned[15]; Vec3 pos; Vec3 vel; @@ -268,12 +270,12 @@ void it_80289BE8(Item_GObj* gobj, s32 arg1, s32 arg2, s32 arg3) } } { - ItemKind* spawn_ptr = &spawned[i]; - for (; i < count; i++, spawn_ptr++) { - ItemKind rand_kind = it_8026F3AC(); + spawn_ptr = &spawned[i]; + for (; i < count; spawn_ptr++, i++) { Vec3 vel; Vec3 pos; PAD_STACK(8); + rand_kind = it_8026F3AC(); if (rand_kind != -1) { Item_GObj* spawned_gobj; it_80289BE8_inline(gobj, 1.2f, &pos, &vel); @@ -310,7 +312,7 @@ void it_80289BE8(Item_GObj* gobj, s32 arg1, s32 arg2, s32 arg3) count = HSD_Randi(2); count += 3; for (i = 0; i < count; i++) { - ItemKind rand_kind = it_8026F3AC(); + rand_kind = it_8026F3AC(); if (rand_kind != -1) { Item_GObj* spawned_gobj; it_80289BE8_inline(gobj, 1.2f, &pos, &vel); diff --git a/src/melee/it/items/itlinkbomb.c b/src/melee/it/items/itlinkbomb.c index 44f1408afb..3bfab55e14 100644 --- a/src/melee/it/items/itlinkbomb.c +++ b/src/melee/it/items/itlinkbomb.c @@ -400,20 +400,41 @@ static inline void itLinkbomb_UnkMotion3_Anim_inline2(HSD_GObj* gobj) it_8029DB5C(gobj); } -bool itLinkbomb_UnkMotion3_Anim(Item_GObj* gobj) +static inline void itLinkbomb_UnkMotion3_Anim_blk10932r( + Item_GObj* gobj, itLinkBombAttributes* attrs) { - Item* ip = GET_ITEM(gobj); - itLinkBombAttributes* attrs = ip->xC4_article_data->x4_specialAttributes; - PAD_STACK(12); + Item* ip; + Article* article; if (!it_80272C6C(gobj)) { it_8029EC34(gobj); } + ip = GET_ITEM(gobj); // permuterslop + if (article != NULL) { + } if (attrs != NULL) { } if (ip != NULL) { } itLinkbomb_UnkMotion3_Anim_inline2(gobj); +} + +static inline Article* itLinkbomb_UnkMotion3_Anim_pi10865(Item* ip) +{ + return ip->xC4_article_data; +} + +static inline void itLinkbomb_UnkMotion3_Anim_blk10913(void) +{ + PAD_STACK(12); +} + +bool itLinkbomb_UnkMotion3_Anim(Item_GObj* gobj) +{ + itLinkBombAttributes* attrs = + GET_ITEM(gobj)->xC4_article_data->x4_specialAttributes; + itLinkbomb_UnkMotion3_Anim_blk10913(); + itLinkbomb_UnkMotion3_Anim_blk10932r(gobj, attrs); return false; } diff --git a/src/melee/it/items/itlinkhookshot.c b/src/melee/it/items/itlinkhookshot.c index 7b5c14b7fa..7efa43b4c2 100644 --- a/src/melee/it/items/itlinkhookshot.c +++ b/src/melee/it/items/itlinkhookshot.c @@ -58,6 +58,12 @@ ItemStateTable it_803F6998[] = { { f32 it_804D6D48; +/// @todo .sdata2 order hack +static void sdata2_order(void) +{ + (void) 0.0F; +} + void it_802A2418(Item_GObj* obj) { Item* item = GET_ITEM(obj); @@ -118,19 +124,19 @@ static bool inline link_fighter_compare(Fighter* fp) } } -static inline void it_802A2568_inline(ItemLink* temp_r3_3, HSD_JObj* arg1, - HSD_GObj* temp_r3_2, Vec3* pos) +static inline void it_802A2568_inline(ItemLink* link, HSD_JObj* jobj, + HSD_GObj* gobj, Vec3* pos) { - temp_r3_3->jobj = arg1; - temp_r3_3->gobj = temp_r3_2; - temp_r3_3->vel = *pos; - temp_r3_3->pos = *pos; - temp_r3_3->x2C_b0 = 1; - temp_r3_3->x2C_b1 = 1; - temp_r3_3->x2C_b2 = 1; - // it_802A43B8(temp_r3_3); - temp_r3_3->coll_data.cur_pos = temp_r3_3->pos; - temp_r3_3->coll_data.last_pos = temp_r3_3->coll_data.cur_pos; + link->jobj = jobj; + link->gobj = gobj; + link->vel = *pos; + link->pos = *pos; + link->x2C_b0 = 0; + link->x2C_b1 = 0; + link->x2C_b2 = 0; + // it_802A43B8(link); + link->coll_data.cur_pos = link->pos; + link->coll_data.last_pos = link->coll_data.cur_pos; } static inline HSD_JObj* it_link_get_joint(Item* arg0, s32 var_r31) @@ -187,12 +193,12 @@ HSD_JObj* it_802A2568(Item* arg0, HSD_JObj* arg1, s32 arg2, f32 arg8) CollData* first_coll; CollData* last_coll; CollData* link_coll; - HSD_GObj* link_gobj; + s32 link_idx; ItemLink* link; + HSD_GObj* link_gobj; ItemLink* prev_link; ItemLink* first_link; ItemLink* last_link; - s32 link_idx; itLinkHookshotAttributes* attr; HSD_JObj* last_jobj; Vec3 pos; @@ -205,7 +211,7 @@ HSD_JObj* it_802A2568(Item* arg0, HSD_JObj* arg1, s32 arg2, f32 arg8) prev_link = NULL; link_idx = 0; - while (!(link_idx >= attr->x2C)) { + while (link_idx < attr->x2C) { link_gobj = GObj_Create(HSD_GOBJ_CLASS_ITEMLINK, 0xAU, 0U); if (link_gobj == NULL) { while (prev_link != NULL) { @@ -221,17 +227,7 @@ HSD_JObj* it_802A2568(Item* arg0, HSD_JObj* arg1, s32 arg2, f32 arg8) first_coll = &link->coll_data; first_link = link; - // it_802A2568_inline(link, arg1, link_gobj, &pos); - link->jobj = arg1; - link->gobj = link_gobj; - link->vel = pos; - link->pos = pos; - link->x2C_b0 = 0; - link->x2C_b1 = 0; - link->x2C_b2 = 0; - // it_802A43B8(link); - link->coll_data.cur_pos = link->pos; - link->coll_data.last_pos = link->coll_data.cur_pos; + it_802A2568_inline(link, arg1, link_gobj, &pos); mpColl_80041EE4(first_coll); first_coll->x34_flags.b1234 = 5; @@ -247,16 +243,7 @@ HSD_JObj* it_802A2568(Item* arg0, HSD_JObj* arg1, s32 arg2, f32 arg8) last_link = link; link->next = prev_link; - link->jobj = arg1; - link->gobj = link_gobj; - link->vel = pos; - link->pos = pos; - link->x2C_b0 = 0; - link->x2C_b1 = 0; - link->x2C_b2 = 0; - // it_802A43B8(link); - link->coll_data.cur_pos = link->pos; - link->coll_data.last_pos = link->coll_data.cur_pos; + it_802A2568_inline(link, arg1, link_gobj, &pos); mpColl_80041EE4(last_coll); last_coll->x34_flags.b1234 = 5; @@ -270,17 +257,7 @@ HSD_JObj* it_802A2568(Item* arg0, HSD_JObj* arg1, s32 arg2, f32 arg8) link_coll = &link->coll_data; link->next = prev_link; - // it_802A2568_inline(link, arg1, link_gobj, &pos); - link->jobj = arg1; - link->gobj = link_gobj; - link->vel = pos; - link->pos = pos; - link->x2C_b0 = 0; - link->x2C_b1 = 0; - link->x2C_b2 = 0; - // it_802A43B8(link); - link->coll_data.cur_pos = link->pos; - link->coll_data.last_pos = link->coll_data.cur_pos; + it_802A2568_inline(link, arg1, link_gobj, &pos); mpColl_80041EE4(link_coll); link_coll->x34_flags.b1234 = 5; @@ -578,9 +555,9 @@ static void fn_802A3110(HSD_GObj* arg0) ItemLink* item_link; Fighter* fp; - fp = item->owner->user_data; attr = item->xC4_article_data->x4_specialAttributes; - (void) attr; + fp = item->owner->user_data; + (void) fp; item_link = item->xDD4_itemVar.linkhookshot.x0; fn_802A3110_inline(item_link, &vec); @@ -610,9 +587,9 @@ void it_802A3254(Item_GObj* arg0) Fighter* fp; u8 _padB[4]; - fp = item->owner->user_data; attr = item->xC4_article_data->x4_specialAttributes; - (void) attr; + fp = item->owner->user_data; + (void) fp; item_link = item->xDD4_itemVar.linkhookshot.x4; it_802A2EE4_inline_alt(item_link, &pos); @@ -728,16 +705,19 @@ static inline bool it_802A3630_inline(Item* item, Vec3* cur_pos, Vec3* pos) void it_802A3630(Item_GObj* arg0) { - Vec3 pos; Item* item = GET_ITEM(arg0); itLinkHookshotAttributes* attr = item->xC4_article_data->x4_specialAttributes; Fighter* fp = item->owner->user_data; ItemLink* item_link = item->xDD4_itemVar.linkhookshot.x4; + Vec3 pos; + Fighter* fp2; + PAD_STACK(4); - it_802A2EE4_inline_alt(item->xDD4_itemVar.linkhookshot.x4, &pos); + fp2 = fp; + it_802A2EE4_inline_alt(item_link, &pos); - if (it_802A3630_inline(item, &fp->cur_pos, &pos) != 0) { + if (it_802A3630_inline(item, &fp2->cur_pos, &pos) != 0) { ftCo_80090780(item->owner); it_802A2B10(arg0); return; @@ -745,15 +725,15 @@ void it_802A3630(Item_GObj* arg0) if (it_802A5AE0(item->xDD4_itemVar.linkhookshot.x0, &pos, attr) != 0) { it_802A7A04(arg0); - it_802A7168(item, &pos, fp->x34_scale.y); + it_802A7168(item, &pos, fp2->x34_scale.y); return; } - it_802A7384(item, &pos, fp->x34_scale.y); - if (fp->ground_or_air != 1) { + it_802A7384(item, &pos, fp2->x34_scale.y); + if (fp2->ground_or_air != 1) { it_802A77DC(arg0); return; } - if (fp->input.x668 & HSD_PAD_A) { + if (fp2->input.x668 & HSD_PAD_A) { it_802A79A0(arg0); } } @@ -769,42 +749,45 @@ void it_802A3828(Item_GObj* gobj) Item* item = GET_ITEM(gobj); itLinkHookshotAttributes* attr = item->xC4_article_data->x4_specialAttributes; + ItemLink* item_link; Fighter* fp = GET_FIGHTER(item->owner); - ItemLink* item_link = item->xDD4_itemVar.linkhookshot.x4; - ftLk_DatAttrs* lk_attr = fp->dat_attrs; + Fighter* fp2; Vec3 pos; + ftLk_DatAttrs* lk_attr; u8 _padA[16]; Mtx m; - u8 _padB[4]; - f32 temp_f31; - f32 temp_f30; + f32 x_offset; + f32 y_offset; + lk_attr = fp->dat_attrs; + item_link = item->xDD4_itemVar.linkhookshot.x4; + fp2 = fp; it_802A2EE4_inline((MtxPtr) &m, item_link, &pos); - temp_f31 = fp->cur_pos.x - pos.x; - temp_f30 = fp->cur_pos.y - pos.y; + x_offset = fp2->cur_pos.x - pos.x; + y_offset = fp2->cur_pos.y - pos.y; if (it_802A5FE0(item->xDD4_itemVar.linkhookshot.x4, item->xDD4_itemVar.linkhookshot.x0, &pos, attr, attr->x40) != 0) { - fp->cur_pos.x = pos.x + temp_f31; - fp->cur_pos.y = pos.y + temp_f30; + fp2->cur_pos.x = pos.x + x_offset; + fp2->cur_pos.y = pos.y + y_offset; if ((ftCo_800C3A14(item->owner) != 0) && (ft_80082E3C(item->owner) == NULL)) { ftCliffCommon_80081370(item->owner); } else { - fp->self_vel.x = 0.0f; + fp2->self_vel.x = 0.0f; ftCo_8009B390(item->owner, lk_attr->xB4); } it_802A2B10(gobj); - } else { - fp->cur_pos.x = pos.x + temp_f31; - fp->cur_pos.y = pos.y + temp_f30; - it_802A7384(item, &pos, fp->x34_scale.y); - if (fp->ground_or_air != 1) { - it_802A77DC(gobj); - } + return; + } + fp2->cur_pos.x = pos.x + x_offset; + fp2->cur_pos.y = pos.y + y_offset; + it_802A7384(item, &pos, fp2->x34_scale.y); + if (fp2->ground_or_air != 1) { + it_802A77DC(gobj); } } @@ -1358,27 +1341,29 @@ s32 it_802A5320(ItemLink* link_0, Vec3* arg1, itLinkHookshotAttributes* attr, Fighter* fp) { ItemLink* link_1; + ItemLink* cur; f32 len; Vec3 vec; Vec3 pos; - s32 temp_r30; + s32 wall_flags; int var_r29; + cur = link_0; link_1 = link_0->next; - link_0->vel.y -= attr->x3C; - if (link_0->vel.x > attr->x48) { - link_0->vel.x = link_0->vel.x - attr->x48; - } else if (link_0->vel.x < -attr->x48) { - link_0->vel.x = link_0->vel.x + attr->x48; + cur->vel.y -= attr->x3C; + if (cur->vel.x > attr->x48) { + cur->vel.x = cur->vel.x - attr->x48; + } else if (cur->vel.x < -attr->x48) { + cur->vel.x = cur->vel.x + attr->x48; } else { - link_0->vel.x = 0.0f; + cur->vel.x = 0.0f; } - link_0->pos.x += link_0->vel.x; - link_0->pos.y += link_0->vel.y; - link_0->pos.z += link_0->vel.z; - temp_r30 = it_802A40D0(link_0, attr->x30) & Collide_WallMask; + cur->pos.x += cur->vel.x; + cur->pos.y += cur->vel.y; + cur->pos.z += cur->vel.z; + wall_flags = it_802A40D0(cur, attr->x30) & Collide_WallMask; var_r29 = 0; while (link_1 != NULL) { @@ -1388,24 +1373,25 @@ s32 it_802A5320(ItemLink* link_0, Vec3* arg1, itLinkHookshotAttributes* attr, link_1->pos.y += link_1->vel.y; link_1->pos.z += link_1->vel.z; if (var_r29 == (s32) ((s32) attr->x2C / 2)) { - it_802A3E50(link_1, fp->kind, attr->x30); + f32 width = attr->x30; + it_802A3E50(link_1, fp->kind, width); } else { it_802A40D0(link_1, attr->x30); } - len = it_802A3C98(&link_1->pos, &link_0->pos, &vec); + len = it_802A3C98(&link_1->pos, &cur->pos, &vec); if (len > attr->x30) { - link_1->pos.x = (vec.x * attr->x30) + link_0->pos.x; - link_1->pos.y = (vec.y * attr->x30) + link_0->pos.y; - link_1->pos.z = (vec.z * attr->x30) + link_0->pos.z; + link_1->pos.x = (vec.x * attr->x30) + cur->pos.x; + link_1->pos.y = (vec.y * attr->x30) + cur->pos.y; + link_1->pos.z = (vec.z * attr->x30) + cur->pos.z; } link_1->coll_data.last_pos = link_1->coll_data.cur_pos; link_1->coll_data.cur_pos = link_1->pos; } else { - len = it_802A3C98(arg1, &link_0->pos, &vec); + len = it_802A3C98(arg1, &cur->pos, &vec); if (len > attr->x30) { - link_1->pos.x = (vec.x * attr->x30) + link_0->pos.x; - link_1->pos.y = (vec.y * attr->x30) + link_0->pos.y; - link_1->pos.z = (vec.z * attr->x30) + link_0->pos.z; + link_1->pos.x = (vec.x * attr->x30) + cur->pos.x; + link_1->pos.y = (vec.y * attr->x30) + cur->pos.y; + link_1->pos.z = (vec.z * attr->x30) + cur->pos.z; link_1->x2C_b0 = 1; link_1->coll_data.cur_pos = link_1->pos; link_1->coll_data.last_pos = link_1->coll_data.cur_pos; @@ -1414,18 +1400,17 @@ s32 it_802A5320(ItemLink* link_0, Vec3* arg1, itLinkHookshotAttributes* attr, link_1->x2C_b0 = 1; link_1->coll_data.cur_pos = link_1->pos; link_1->coll_data.last_pos = link_1->coll_data.cur_pos; - if (temp_r30 != 0) { + if (wall_flags != 0) { return 1; } return 0; } - break; } - link_0 = link_1; + cur = link_1; link_1 = link_1->next; var_r29 += 1; } - it_802A44CC(link_0, arg1, attr, attr->x30); + it_802A44CC(cur, arg1, attr, attr->x30); return 2; } @@ -1507,20 +1492,21 @@ void it_802A5770(ItemLink* link_0, Vec3* arg1, itLinkHookshotAttributes* arg2, s32 it_802A5AE0(ItemLink* link_0, Vec3* arg1, itLinkHookshotAttributes* arg2) { - ItemLink* cur = link_0; + ItemLink* cur; ItemLink* link_1; f32 len; - f32 test[2]; Vec3 vec; Vec3 sp30; + UNUSED f32 pad; if (mpLib_80054ED8(link_0->x1CC) != 0) { - mpGetSpeed(cur->x1CC, &cur->pos, &sp30); - cur->pos.x += sp30.x; - cur->pos.y += sp30.y; - cur->pos.z += sp30.z; + mpGetSpeed(link_0->x1CC, &link_0->pos, &sp30); + link_0->pos.x += sp30.x; + link_0->pos.y += sp30.y; + link_0->pos.z += sp30.z; } + cur = link_0; link_1 = cur->next; while (link_1 != NULL) { if (link_1->x2C_b0) { @@ -1736,8 +1722,8 @@ void it_802A6474(ItemLink* link_0, ItemLink* link_1, Vec3* pos, segment_dx -= cur_link->pos.x; segment_dz = next_link->pos.z; segment_dz -= cur_link->pos.z; - segment_len = segment_dy * segment_dy; - segment_len = (segment_dx * segment_dx) + segment_len; + segment_len = + (segment_dx * segment_dx) + (segment_dy * segment_dy); segment_len = (segment_dz * segment_dz) + segment_len; if (segment_len > 0.0f) { segment_len_tmp = my_sqrt(segment_len); @@ -1768,8 +1754,7 @@ void it_802A6474(ItemLink* link_0, ItemLink* link_1, Vec3* pos, target_dx = pos->x; target_dx -= cur_link->pos.x; target_dz = pos->z - cur_link->pos.z; - target_len = target_dy * target_dy; - target_len = (target_dx * target_dx) + target_len; + target_len = (target_dx * target_dx) + (target_dy * target_dy); target_len = (target_dz * target_dz) + target_len; if (target_len > 0.0f) { target_len_tmp = my_sqrt(target_len); @@ -1786,7 +1771,7 @@ void it_802A6474(ItemLink* link_0, ItemLink* link_1, Vec3* pos, target_dz *= inv_target_len; if (target_len > max_len) { pos->x = (target_dx * max_len) + cur_link->pos.x; - pos->y = (target_dy * attrs->x30) + cur_link->pos.y; + pos->y = (attrs->x30 * target_dy) + cur_link->pos.y; pos->z = (target_dz * attrs->x30) + cur_link->pos.z; } } @@ -1848,13 +1833,23 @@ void it_802A6944(Item* item, f32 scl) HSD_JObjSetMtxDirty(jobj); } +static inline void it_802A6A78_get_next(ItemLink* link_0, ItemLink** link_1) +{ + *link_1 = link_0->next; +} + +static inline Vec3* it_802A6A78_get_pos(ItemLink* link_0) +{ + return &link_0->pos; +} + bool it_802A6A78(ItemLink* link_0, Vec3* arg1, itLinkHookshotAttributes* arg2, Fighter* arg3) { - ItemLink* link_1; ftLk_DatAttrs* lk_attr; - Vec3 vec; + ItemLink* link_1; f64 len; + Vec3 vec; f32 inv; lk_attr = arg3->ft_data->ext_attr; @@ -1872,10 +1867,11 @@ bool it_802A6A78(ItemLink* link_0, Vec3* arg1, itLinkHookshotAttributes* arg2, } } - link_1 = link_0->next; + it_802A6A78_get_next(link_0, &link_1); while (link_1 != NULL) { if (link_1->x2C_b0) { - len = it_802A6A78_normalize_diff(&link_1->pos, &link_0->pos, &vec); + len = it_802A6A78_normalize_diff( + &link_1->pos, it_802A6A78_get_pos(link_0), &vec); if (len > arg2->x30) { link_1->pos.x = (vec.x * arg2->x30) + link_0->pos.x; link_1->pos.y = (vec.y * arg2->x30) + link_0->pos.y; diff --git a/src/melee/it/items/itsamusgrapple.c b/src/melee/it/items/itsamusgrapple.c index 24a8e888ba..8d8742c96b 100644 --- a/src/melee/it/items/itsamusgrapple.c +++ b/src/melee/it/items/itsamusgrapple.c @@ -78,6 +78,11 @@ static inline f32 samus_grapple_calc_grav(f32 vel_y) } } +static inline Vec3* samus_grapple_vec2_as_vec3(void* pos) +{ + return pos; +} + static inline void samus_grapple_setup_pos(ItemLink* link, Vec3* pos, Mtx m) { PSMTXIdentity(m); @@ -302,15 +307,21 @@ HSD_JObj* it_802B75FC(Item* ip, HSD_JObj* jobj_arg, s32 arg2, f32 scale) f32 coeff; f32 temp; HSD_JObj* result; - ItemLink* prev_link; + itSamusGrappleAttributes* attrs2; ItemLink* head_link; ItemLink* tail_link; + ItemLink* link; + HSD_GObj* link_gobj; + itSamusGrappleAttributes* attrs; + ItemLink* prev_link; + HSD_JObj* tail_jobj; s32 i; - itSamusGrappleAttributes* attrs = - ip->xC4_article_data->x4_specialAttributes; - Vec3 zero_vel = it_803B8674; + Vec3 zero_vel; PAD_STACK(4); + attrs = ip->xC4_article_data->x4_specialAttributes; + zero_vel = it_803B8674; + if (arg2 != 0) { coeff = attrs->x60; } else { @@ -342,8 +353,7 @@ HSD_JObj* it_802B75FC(Item* ip, HSD_JObj* jobj_arg, s32 arg2, f32 scale) prev_link = NULL; for (i = 0; i < attrs->x34; i++) { - HSD_GObj* link_gobj = GObj_Create(7, 0xA, 0); - ItemLink* link; + link_gobj = GObj_Create(7, 0xA, 0); if (link_gobj == NULL) { while (prev_link != NULL) { HSD_GObjPLink_80390228(prev_link->gobj); @@ -362,8 +372,6 @@ HSD_JObj* it_802B75FC(Item* ip, HSD_JObj* jobj_arg, s32 arg2, f32 scale) it_802B75FC_inline(link, &zero_vel, 1.0f); it_802B743C(link_gobj, ip, 0); } else if (i == attrs->x34 - 1) { - itSamusGrappleAttributes* attrs2; - HSD_JObj* tail_jobj; prev_link->prev = link; link->prev = NULL; tail_link = link; @@ -578,12 +586,13 @@ void fn_802B805C(Item_GObj* gobj) itSamusGrappleAttributes* attrs; ItemLink* link; Fighter* fp; - Vec3 pos; + Vec2 pos; Vec3 normal; Vec3 pos2; u8 _padA[4]; Mtx m; - PAD_STACK(28); + u8 _padB[4]; + PAD_STACK(24); owner = ip->owner; attrs = ip->xC4_article_data->x4_specialAttributes; @@ -597,9 +606,10 @@ void fn_802B805C(Item_GObj* gobj) return; } - samus_grapple_setup_pos(link, &pos, m); + samus_grapple_setup_pos(link, samus_grapple_vec2_as_vec3(&pos), m); - switch (it_802B9328(link, &pos, attrs, ip->owner->user_data)) { + switch (it_802B9328(link, samus_grapple_vec2_as_vec3(&pos), attrs, + ip->owner->user_data)) { case 1: if (fp->motion_id == 0x165) { ftCo_800C3CC0(ip->owner); @@ -634,7 +644,7 @@ void fn_802B805C(Item_GObj* gobj) ftCommon_8007E2F4(fp, 0); break; } - it_802A7168(ip, &pos, fp->x34_scale.y); + it_802A7168(ip, samus_grapple_vec2_as_vec3(&pos), fp->x34_scale.y); samus_grapple_anim(gobj); } diff --git a/src/melee/it/itspawn.c b/src/melee/it/itspawn.c index 0329305f5a..fdcf699293 100644 --- a/src/melee/it/itspawn.c +++ b/src/melee/it/itspawn.c @@ -18,6 +18,14 @@ extern u64 __shr2u(u32, u32, s32); +/// @todo .sdata2 order hack +static void sdata2_order(void) +{ + (void) 4503601774854144.0; + (void) 0.0F; + (void) 0.99F; +} + void it_8026C47C(struct it_8026C47C_arg0_t* arg_struct) { u32 it_kind; @@ -50,6 +58,11 @@ void it_8026C47C(struct it_8026C47C_arg0_t* arg_struct) } } +typedef struct it_8026C530_Weights { + u16 x0; + u16 x2; +} it_8026C530_Weights; + static inline s32 it_8026C530_pi1317(s32 arg3) { return arg3 - 1; @@ -57,49 +70,50 @@ static inline s32 it_8026C530_pi1317(s32 arg3) s32 it_8026C530(s32 arg0, ItemPickTable* arg1, s32 arg2, s32 arg3) { s32 last; - s32 var_r5; - u16* temp_r10; + s32 lower; + u16* weights; s32 mid; - s32 temp_r6; - s32 temp_r7; - u16* temp_r9; + s32 left_mid; + s32 right_mid; + u16* next_weights; - var_r5 = arg2; + lower = arg2; last = it_8026C530_pi1317(arg3); - if (var_r5 == last) { - return var_r5; + if (lower == last) { + return lower; } - temp_r10 = arg1->xC; - mid = (var_r5 + arg3) / 2; - if (temp_r10[mid] > arg0) { - if (var_r5 == (mid - 1)) { + weights = arg1->xC; + mid = (lower + arg3) / 2; + if (weights[mid] > arg0) { + if (lower == (mid - 1)) { + lower = arg2; } else { - temp_r6 = (var_r5 + mid) / 2; - if (temp_r10[temp_r6] > arg0) { - var_r5 = it_8026C530(arg0, arg1, var_r5, temp_r6); - } else if (temp_r10[temp_r6 + 1] > arg0) { - var_r5 = temp_r6; + left_mid = (lower + mid) / 2; + if (weights[left_mid] > arg0) { + lower = it_8026C530(arg0, arg1, lower, left_mid); + } else if (weights[left_mid + 1] > arg0) { + lower = left_mid; } else { - var_r5 = it_8026C530(arg0, arg1, temp_r6, mid); + lower = it_8026C530(arg0, arg1, left_mid, mid); } } - return var_r5; + return lower; } - temp_r9 = (u16*) ((u8*) temp_r10 + 2); - if (temp_r9[mid] > arg0) { + next_weights = &((it_8026C530_Weights*) weights)->x2; + if (next_weights[mid] > arg0) { return mid; } if (mid == last) { return mid; } - temp_r7 = (mid + arg3) / 2; - if (temp_r10[temp_r7] > arg0) { - return it_8026C530(arg0, arg1, mid, temp_r7); + right_mid = (mid + arg3) / 2; + if (weights[right_mid] > arg0) { + return it_8026C530(arg0, arg1, mid, right_mid); } - if (temp_r9[temp_r7] > arg0) { - return temp_r7; + if (next_weights[right_mid] > arg0) { + return right_mid; } - return it_8026C530(arg0, arg1, temp_r7, arg3); + return it_8026C530(arg0, arg1, right_mid, arg3); } /// argument is definitely size 0x10 @@ -150,7 +164,8 @@ ItemKind it_8026C75C(ItemPickTable* arg_struct) bool chk1; u16 var_r30; u8 temp_r4; - ItemKind kind; + s32 selected; + s32 result; PAD_STACK(16); chk1 = false; @@ -176,48 +191,48 @@ ItemKind it_8026C75C(ItemPickTable* arg_struct) arg_struct->x0 -= 1; } } - kind = arg_struct->x4[it_8026C530(HSD_Randi(arg_struct->x8), arg_struct, 0, - arg_struct->x0)]; + selected = arg_struct->x4[it_8026C530(HSD_Randi(arg_struct->x8), + arg_struct, 0, arg_struct->x0)]; + result = selected; if (chk1 && chk2) { arg_struct->x8 = var_r30; arg_struct->x0 += 1; - if (kind == It_Kind_M_Ball) { - kind = -1; + if (selected == It_Kind_M_Ball) { + result = -1; } } - return kind; + return result; } -void fn_8026C88C(HSD_GObj* gobj) +static inline void it_8026C88C_inline(RandomItemSpawner* alloc, + SpawnItem* spawn) { - RandomItemSpawner* alloc = &it_804A0E30; - s32* alloc_x0 = &alloc->x0; + Vec3* pos; + s32 chk; Item_GObj* spawn_gobj; - SpawnItem spawn; - bool chk; - if (db_AreItemSpawnsEnabled() != 0U) { alloc->x0--; if ((s32) alloc->x0 == 0) { - spawn.kind = it_8026C75C(&alloc->x4); - if ((s32) spawn.kind != -1) { - if (it_8026CB3C(&spawn.prev_pos)) { - spawn.pos = spawn.prev_pos; - spawn.facing_dir = it_8026B684(&spawn.prev_pos); - spawn.x3C_damage = 0; - spawn.vel.x = spawn.vel.y = spawn.vel.z = 0.0F; - spawn.x0_parent_gobj = NULL; - spawn.x4_parent_gobj2 = spawn.x0_parent_gobj; - spawn.x44_flag.b0 = 1; - spawn.x40 = 0; - chk = true; + spawn->kind = it_8026C75C(&alloc->x4); + if ((s32) spawn->kind != -1) { + pos = &spawn->prev_pos; + if (it_8026CB3C(pos)) { + spawn->pos = *pos; + spawn->facing_dir = it_8026B684(pos); + chk = 1; + spawn->x3C_damage = 0; + spawn->vel.x = spawn->vel.y = spawn->vel.z = 0.0F; + spawn->x0_parent_gobj = NULL; + spawn->x4_parent_gobj2 = spawn->x0_parent_gobj; + spawn->x44_flag.b0 = chk; + spawn->x40 = 0; } else { chk = false; } if (chk) { - spawn_gobj = Item_80268B18(&spawn); + spawn_gobj = Item_80268B18(spawn); if (spawn_gobj != NULL) { - efSync_Spawn(0x420, spawn_gobj, &spawn.prev_pos); + efSync_Spawn(0x420, spawn_gobj, pos); it_80274ED8(); } } @@ -225,13 +240,26 @@ void fn_8026C88C(HSD_GObj* gobj) { s32* range = &it_804D6D28->xFC[gm_8016AE80() * 2]; f32 randf = HSD_Randf(); - *alloc_x0 = (range[1] - range[0]) * randf + range[0]; - *alloc_x0 *= Ground_801C2AE8(Stage_80225194()); + f32 diff = range[1] - range[0]; + alloc->x0 = diff * randf + range[0]; + alloc->x0 *= Ground_801C2AE8(Stage_80225194()); } } } } +void fn_8026C88C(void) +{ + UNUSED u64 pad; + SpawnItem spawn; + RandomItemSpawner* alloc; + + alloc = &it_804A0E30; + it_8026C88C_inline( + alloc, + &spawn); +} + #pragma push #pragma dont_inline on void it_8026CA4C(ItemPickTable* alloc, s32* arg1, u64 arg2, s32 arg3, f32 arg4) @@ -297,10 +325,9 @@ void it_8026CB9C(s32* counts, u64 mask, f32 weight) *(item_kinds = &spawner->x4.x4) = HSD_MemAlloc(cnt * 4); *(weights = &spawner->x4.xC) = HSD_MemAlloc(cnt * 4); - cnt2 = 0; - p2 = counts; + idx = (cnt2 = 0); mask = backup; - idx = cnt2; + p2 = counts; it_kind2 = 0; cumulative = 0; while (it_kind2 < It_Kind_L_Gun_Ray) { @@ -325,14 +352,15 @@ void it_8026CD50(s32* counts, u64 mask, f32 weight) ItemPickTable monster; } ItemSpawnTables; ItemSpawnTables* tables = (ItemSpawnTables*) &it_804A0E30; - u16** weights; - u8** item_kinds; s32* p; s32 cnt; ItemKind it_kind; ItemKind it_kind2; s32 cnt2; s32* p2; + u8** item_kinds; + s32 idx; + u16** weights; s32 cumulative; u64 backup; @@ -352,16 +380,17 @@ void it_8026CD50(s32* counts, u64 mask, f32 weight) *(item_kinds = &tables->common.x4) = HSD_MemAlloc(cnt * 4); *(weights = &tables->common.xC) = HSD_MemAlloc(cnt * 4); + idx = (cnt2 = 0); mask = backup; p2 = counts + It_Kind_BombHei; - cumulative = (cnt2 = 0); - cnt2 = 0; + cumulative = 0; it_kind2 = It_Kind_BombHei; while (it_kind2 < It_Kind_L_Gun_Ray) { if ((mask & 1) && *p2 != 0) { (*item_kinds)[cnt2] = it_kind2; - (*weights)[cnt2] = cumulative; + (*weights)[idx] = cumulative; cnt2++; + idx++; cumulative = (cumulative + ((weight * *p2) + 0.99f)); } p2++; @@ -401,7 +430,10 @@ void it_8026CF04(void) xC_loc = &tables->monster.xC; item_common = it_804D6D28; idx = i = 0; - counts = &item_common->x128[i]; + { + s32* monster_counts = &item_common->x128[i]; + counts = monster_counts; + } (void) counts; cumulative = 0; for (; i < 4; i++, idx++) { @@ -421,13 +453,18 @@ void it_8026D018(void) } ItemSpawnTables; ItemSpawnTables* tables = (ItemSpawnTables*) &it_804A0E30; bool chk; + u64 stage_mask; + s32* stage_info; + bool chk2; + f32 weight; + u64* stage_mask_ptr; if (!gm_8016B238() && (gm_8016AE80() != -1)) { - tables->alloc.x18 = gm_8016AEA4(); + *(stage_mask_ptr = &tables->alloc.x18) = gm_8016AEA4(); { - u64 stage_mask = tables->alloc.x18; - s32* stage_info = Ground_801C2AD8(); - bool chk2 = gm_8016AE80(); - f32 weight = gm_8016AE94(); + stage_mask = *stage_mask_ptr; + stage_info = Ground_801C2AD8(); + chk2 = gm_8016AE80(); + weight = gm_8016AE94(); if ((stage_mask == 0) || (stage_info == NULL) || (chk2 == -1)) { chk = false; } else { @@ -441,7 +478,7 @@ void it_8026D018(void) } if (chk) { { - u64 stage_mask = tables->alloc.x18; + u64 stage_mask = *stage_mask_ptr; s32* stage_info = Ground_801C2AD8(); f32 weight = gm_8016AE94(); if ((stage_mask != 0) && (stage_info != NULL)) { @@ -454,7 +491,8 @@ void it_8026D018(void) } } it_8026CF04(); - HSD_GObj_SetupProc(GObj_Create(5U, 7U, 0U), fn_8026C88C, 0U); + HSD_GObj_SetupProc(GObj_Create(5U, 7U, 0U), + (HSD_GObjEvent) fn_8026C88C, 0U); { s32* range = &it_804D6D28->xFC[gm_8016AE80() * 2]; f32 randf = HSD_Randf(); diff --git a/src/melee/it/itspawn.h b/src/melee/it/itspawn.h index eb7dd9d578..846a99093d 100644 --- a/src/melee/it/itspawn.h +++ b/src/melee/it/itspawn.h @@ -14,7 +14,7 @@ /* 26C65C */ int it_8026C65C(ItemPickTable*); /* 26C704 */ bool it_8026C704(void); /* 26C75C */ ItemKind it_8026C75C(ItemPickTable*); -/* 26C88C */ void fn_8026C88C(HSD_GObj*); +/* 26C88C */ void fn_8026C88C(void); /* 26CA4C */ void it_8026CA4C(ItemPickTable*, s32*, u64, s32, f32); /* 26CB3C */ bool it_8026CB3C(Vec3*); /* 26CB9C */ void it_8026CB9C(s32*, u64, f32); diff --git a/src/melee/lb/lb_0195.c b/src/melee/lb/lb_0195.c index 23c44903d3..c2cbcc60bc 100644 --- a/src/melee/lb/lb_0195.c +++ b/src/melee/lb/lb_0195.c @@ -64,6 +64,7 @@ void fn_800195FC(void) void lb_80019628(void) { + int i; OSTime period; OSTime new_val = lb_804329F0.x38; @@ -80,12 +81,10 @@ void lb_80019628(void) period = (OSTime) (f32) (u32) OS_TIMER_CLOCK; - if (lb_804329F0.x0[0].x0 < period) { - period = lb_804329F0.x0[0].x0; - } - - if (lb_804329F0.x0[1].x0 < period) { - period = lb_804329F0.x0[1].x0; + for (i = 0; i < 2; i++) { + if (lb_804329F0.x0[i].x0 < period) { + period = lb_804329F0.x0[i].x0; + } } if (period >= (OSTime) (f64) (0.016666668f * (f32) (u32) OS_TIMER_CLOCK)) { diff --git a/src/melee/lb/lbarq.c b/src/melee/lb/lbarq.c index 576d5a9711..1b1099e690 100644 --- a/src/melee/lb/lbarq.c +++ b/src/melee/lb/lbarq.c @@ -20,12 +20,16 @@ void lbArq_80014AC4(lbArqHandle* handle) lbArqNode* node = handle->node; lbArqNode** prev; lbArqNode** tail; + uintptr_t offset; BOOL intr; intr = OSDisableInterrupts(); /* Remove from current list (indexed by state) */ - prev = &global->list[node->state]; + offset = node->state * 4; + offset += 0x1E0; + offset += (uintptr_t) global; + prev = (lbArqNode**) offset; while (*prev != node) { prev = &(*prev)->next; } @@ -75,8 +79,8 @@ void lbArq_80014BD0(u32 source, void* dest, size_t length, lbArqNode* rp; lbArqNode* tmp; lbArqNode** tail; - lbArqNode** free_head; BOOL intr; + lbArqNode** free_head; PAD_STACK(16); DCInvalidateRange(dest, length); diff --git a/src/melee/lb/lbaudio_ax.c b/src/melee/lb/lbaudio_ax.c index 02e279d6af..f804da0463 100644 --- a/src/melee/lb/lbaudio_ax.c +++ b/src/melee/lb/lbaudio_ax.c @@ -91,66 +91,70 @@ int lbAudioAx_80023220(int idx) void fn_80023254(s32 arg0) { int local_arr[0x38]; - int* arr_b44; - int* local_ptr; - s8(*arr_5d0)[4]; - int (*arr_4e4)[2]; + int* list = lbl_80433B44; + int* init; + int* used; + s8* type; + int* priority; int count; - int j; - int n; - int* shift_ptr; + int index; + int* shift; int i; char* base; - arr_b44 = lbl_80433B44; - for (i = 0; i < 0x38; i++) { - arr_b44[i] = 0x37; - local_arr[i] = 0; - } + PAD_STACK(8); - arr_b44 = lbl_80433B44; + init = lbl_80433B44; + used = local_arr; base = lbl_803BB300; - - for (count = 0; count <= 0x37; count++) { - local_ptr = local_arr; - arr_5d0 = (s8(*)[4])(base + 0x2D0); - arr_4e4 = (int (*)[2])(base + 0x11E4); - j = 0; - + count = 0; + for (i = 0; i < 7; i++, init += 8, used += 8) { + init[0] = 0x37; + used[0] = 0; + init[1] = 0x37; + used[1] = 0; + init[2] = 0x37; + used[2] = 0; + init[3] = 0x37; + used[3] = 0; + init[4] = 0x37; + used[4] = 0; + init[5] = 0x37; + used[5] = 0; + init[6] = 0x37; + used[6] = 0; + init[7] = 0x37; + used[7] = 0; + } + + do { + used = local_arr; + type = (s8*) (base + 0x2D0); + priority = (int*) (base + 0x11E4); + index = 0; do { - if (arg0 != (s8) (*arr_5d0)[0]) { - goto next; - } - if (*local_ptr != 0) { - goto next; - } - - if ((u32) ((int (*)[2])(base + 0x11E4))[*arr_b44][0] >= - (u32) (*arr_4e4)[0]) + if (arg0 == (s8) *type && *used == 0 && + (u32) ((int (*)[2])(base + 0x11E4))[*list][0] < + (u32) *priority) { - goto next; - } - - if (count < 0x37) { - shift_ptr = &lbl_80433B44[0x37]; - for (n = 0x37 - count; n != 0; n--) { - shift_ptr[0] = shift_ptr[-1]; - shift_ptr--; + shift = &lbl_80433B44[0x37]; + if (count < 0x37) { + for (i = count; i < 0x37; i++) { + shift[0] = shift[-1]; + shift--; + } } - } - - *arr_b44 = j; - *local_ptr = 1; - - next: - j++; - arr_5d0++; - local_ptr++; - arr_4e4++; - } while (j <= 0x37); - - arr_b44++; - } + *list = index; + *used = 1; + } + index++; + type += 4; + used++; + priority += 2; + } while (index <= 0x37); + count++; + list++; + } while (count <= 0x37); } static inline int lbAudioAx_800233EC_inline(s32 arg0, char* base) @@ -175,60 +179,55 @@ s32 lbAudioAx_800233EC(s32 arg0) if (fn_80026E58(0x21) == 1) { slot = lbAudioAx_800233EC_inline(arg0, base); - - if (slot != 0xD) { - if (slot < 0xD) { - if (slot < 0xC) { - if (slot >= 6) { - goto table_1; + do { + if (slot != 0xD) { + if (slot < 0xD) { + if (slot < 0xC) { + if (slot >= 6) { + } else { + break; + } + } else { + break; + } + } else if (slot < 0x20) { + if (slot >= 0xF) { + } else { + break; } - goto ret; - } - goto ret; - } else if (slot < 0x20) { - if (slot >= 0xF) { } else { - goto ret; + break; } - goto table_1; - } else { - goto ret; } - } - table_1: - - { - int* p = (int*) (base + 0x13A4); - int i; - for (i = 0; i < 0x4A; p += 2, i++) { - if (arg0 == *p) { - return *(int*) (base + (i << 3) + 0x13A8); + { + int* p = (int*) (base + 0x13A4); + int i; + for (i = 0; i < 0x4A; p += 2, i++) { + if (arg0 == *p) { + return ((int (*)[2])(base + 0x13A4))[i][1]; + } + } } - } - } - goto ret; - } - - slot = lbAudioAx_800233EC_inline(arg0, base); - - if (slot == 0x21) { + } while (0); } else { - goto ret; - } - goto table_2; -table_2: - -{ - int* p = (int*) (base + 0x13A4); - int i; - for (i = 0; i < 0x4A; p += 2, i++) { - if (arg0 == p[1]) { - return *(int*) (base + (i << 3) + 0x13A4); - } + slot = lbAudioAx_800233EC_inline(arg0, base); + do { + if (slot == 0x21) { + } else { + break; + } + { + int* p = (int*) (base + 0x13A4); + int i; + for (i = 0; i < 0x4A; p += 2, i++) { + if (arg0 == p[1]) { + return ((int (*)[2])(base + 0x13A4))[i][0]; + } + } + } + } while (0); } -} -ret: return arg0; } @@ -1683,11 +1682,9 @@ bool fn_80025CBC(HSD_GObj* gobj) } // TODO: This is 100% permute-able -bool fn_80025E38(HSD_GObj* gobj) +static inline void fn_80025E38_inline(HSD_GObj* gobj) { lbAudioAx_UserData* ud; - s32 end_val; - s32 start_val; f32 diff; f32 ratio; @@ -1695,29 +1692,31 @@ bool fn_80025E38(HSD_GObj* gobj) ud = gobj->user_data; if (ud != NULL) { if (ud->current_frame <= ud->end_frame) { - start_val = ud->start_val; - end_val = ud->end_val; - - if (end_val > start_val) { - diff = (f32) end_val - (f32) start_val; + if (ud->start_val < ud->end_val) { + diff = (f32) ud->end_val - (f32) ud->start_val; if (diff < 0.0f) { diff = -diff; } ratio = (f32) ud->current_frame / (f32) ud->end_frame; - ud->x20 = start_val + (s32) (ratio * diff); + ud->x20 = ud->start_val + (s32) (ratio * diff); } else { - diff = (f32) end_val - (f32) start_val; + diff = (f32) ud->end_val - (f32) ud->start_val; if (diff < 0.0f) { diff = -diff; } ratio = (f32) ud->current_frame / (f32) ud->end_frame; - ud->x20 = end_val - (s32) (ratio * diff); + ud->x20 = ud->end_val - (s32) (ratio * diff); } } else { ud->x20 = 0x7F; } } } +} + +bool fn_80025E38(HSD_GObj* gobj) +{ + fn_80025E38_inline(gobj); return false; } @@ -1803,19 +1802,16 @@ void fn_80025FAC(HSD_GObj* gobj, void* userdata, void* params) } } - { - s32 type = ud->xC; - if (type == 9) { - goto case9; - } - if (type >= 9) { - goto done; - } - if (type >= 0) { - goto normal; - } - goto done; - normal: + switch (ud->xC) { + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + case 8: if (ud->current_frame < 0) { ud->current_frame = 0; } @@ -1832,8 +1828,8 @@ void fn_80025FAC(HSD_GObj* gobj, void* userdata, void* params) ud->voice_id = lbAudioAx_80023870(ud->x14, ud->x20, ud->x2C.pan, group); } - goto done; - case9: + break; + case 9: if (ud->current_frame < 0) { ud->current_frame = 0; } @@ -1841,7 +1837,7 @@ void fn_80025FAC(HSD_GObj* gobj, void* userdata, void* params) ud->end_frame = 0; } ud->voice_id = sp->x28; - done:; + break; } } } @@ -2058,10 +2054,8 @@ s32 fn_80026650(void) return -1; } -#pragma global_optimizer off void fn_800267B0(void) { - lbAudioAx_PoolAlloc* st = &lbl_80433710; int* arr_274; s8(*arr_5d0)[4]; int* arr_194; @@ -2114,7 +2108,6 @@ void fn_800267B0(void) HSD_SynthSFXBankDeflag(2); HSD_SynthSFXBankDeflagSync(); } -#pragma global_optimizer on void fn_800268B4(void) { @@ -2162,28 +2155,19 @@ void fn_800268B4(void) void fn_800269AC(void) { - s8(*types)[4]; - int* avail2; - int* avail; - s8(*types2)[4]; - int* handles2; - int* handles; int i; int total, k, j, s, m; PAD_STACK(8); if (HSD_SynthSFXGetPendingLoadCount() != 0) { - int* handles2; - types = types2 = s32_arr_803BB5D0; - handles = handles2 = lbl_80433A64; - avail = avail2 = lbl_80433984; - for (i = 0; i < 0x37; i++) { - if ((*types2)[1] != 5 && *handles2 != -1 && *avail2 == -1) { + if (s32_arr_803BB5D0[i][1] != 5 && + lbl_80433A64[i] != -1 && lbl_80433984[i] == -1) + { int retry; for (retry = 0; retry < 0x40; retry++) { - if (HSD_SynthSFXCancelLoad(*handles2) == 1) { + if (HSD_SynthSFXCancelLoad(lbl_80433A64[i]) == 1) { break; } total = 0; @@ -2197,25 +2181,19 @@ void fn_800269AC(void) } } } - *handles2 = -1; - *avail2 = -1; + lbl_80433A64[i] = -1; + lbl_80433984[i] = -1; } - types2++; - handles2++; - avail2++; } if (HSD_SynthSFXGetPendingLoadCount() != 0) { HSD_SynthSFXWaitForLoadCompletion(lb_800195D0); HSD_SynthSFXUnloadBank(2); for (i = 0; i < 0x37; i++) { - if ((*types)[1] != 5) { - *avail = -1; - *handles = -1; + if (s32_arr_803BB5D0[i][1] != 5) { + lbl_80433984[i] = -1; + lbl_80433A64[i] = -1; } - types++; - avail++; - handles++; } } } @@ -2224,7 +2202,6 @@ void fn_800269AC(void) s32 fn_80026C04(s32 arg0) { char* base = lbl_803BB300; - lbAudioAx_PoolAlloc* st = &lbl_80433710; s32 priority; s32 slot; @@ -2235,8 +2212,7 @@ s32 fn_80026C04(s32 arg0) if (arg0 == *arr_354) { lbl_80433984[i] = 1; { - char* ptr = base + (i << 3); - s32 offset = *(s32*) (ptr + 0x11E4); + s32 offset = ((s32(*)[2])(base + 0x11E4))[i][0]; lbl_804D644C -= offset; lbl_804D6450 -= offset; lbl_804D6448 += offset; @@ -2379,7 +2355,7 @@ void lbAudioAx_80027168(void) { char* base = lbl_803BB300; lbAudioAx_PoolAlloc* st = &lbl_80433710; - volatile s32 count; + s32 count; int i; { @@ -2392,7 +2368,6 @@ void lbAudioAx_80027168(void) } } - count = 0; { s8(*arr5d0)[4] = (s8(*)[4])(base + 0x2D0); int* arr_b4 = lbl_804337C4; @@ -2457,41 +2432,33 @@ s32 fn_80027488(void) } #pragma dont_inline reset -void lbAudioAx_80027648(void) +static inline s32 fn_80027488_inline(void) { int i; - s32 result; - u8 operand_pad[4]; - goto check; -loop: - HSD_SynthSFXWaitForLoadCompletion(lb_800195D0); - -check: { - int* q = lbl_80433984; - int* p = lbl_804338A4; - for (i = 0; i < 55; p++, q++, i++) { - if (*p == 1 && *q == -1) { - result = 1; - goto end; + for (i = 0; i < 55; i++) { + if (lbl_804338A4[i] == 1 && lbl_80433984[i] == -1) { + return 1; } } -} for (i = 0; i < 55; i++) { if (lbl_804338A4[i] == 1 && lbl_80433984[i] == 1) { lbl_80433984[i] = 2; } } - result = 0; -end: - if (result == 1) { - goto loop; + return 0; +} + +void lbAudioAx_80027648(void) +{ + while (fn_80027488_inline() == 1) { + HSD_SynthSFXWaitForLoadCompletion(lb_800195D0); } } -s32 lbAudioAx_8002785C(void) +void lbAudioAx_8002785C(void) { u64 result = 0; int i; @@ -2537,16 +2504,36 @@ s32 lbAudioAx_8002785C(void) } } +typedef struct PoolAllocFull { + u8 x0[0xB4]; + int xB4[56]; + int x194[56]; + int x274[56]; + int x354[56]; +} PoolAllocFull; + +typedef struct AudioDataFull { + u8 x0[0xA00]; + char* xA00; + u8 xA04[0xC4]; + char* xAC8; + u8 xACC[8]; + char* xAD4; +} AudioDataFull; + void lbAudioAx_80027AB0(s32 arg0) { + char* base = lbl_803BB300; + char* path; + int* status; s32 lang; if (lbLang_IsSavedLanguageUS()) { - lbAudioAx_SetAudioPath(lbl_803BB340, true); + strcpy(base + 0x40, base + 0x1790); lbl_804D38D0 = 10; lang = 1; } else { - lbAudioAx_SetAudioPath(lbl_803BB340, false); + strcpy(base + 0x40, base + 0x179C); lbl_804D38D0 = 7; lang = 0; } @@ -2556,18 +2543,19 @@ void lbAudioAx_80027AB0(s32 arg0) if (lbl_804D3878 != lang) { lbl_804D3878 = lang; AXDriver_8038DCFC(); - strcpy(&lbl_803BB340[lbl_804D38D0], "smash2.sem"); - AXDriver_8038DA70(lbl_803BB340, lb_800195D0); + path = base + lbl_804D38D0; + strcpy(path + 0x40, base + 0x17A8); + AXDriver_8038DA70(base + 0x40, lb_800195D0); if (arg0 != 0x83D61) { lbAudioAx_800237A8(arg0, 0x7F, 0x40); } { - int* a = lbl_80433A64; - int* b = lbl_804337C4; - int* c = lbl_804338A4; - int* d = lbl_80433984; + int* a = ((PoolAllocFull*) &lbl_80433710)->x354; + int* b = ((PoolAllocFull*) &lbl_80433710)->xB4; + int* c = ((PoolAllocFull*) &lbl_80433710)->x194; + int* d = ((PoolAllocFull*) &lbl_80433710)->x274; int idx; for (idx = 0; idx < 55; a++, b++, c++, d++, idx++) { if (idx != 0) { @@ -2582,28 +2570,34 @@ void lbAudioAx_80027AB0(s32 arg0) HSD_SynthSFXUnloadBank(1); HSD_SynthSFXUnloadBank(2); - if (lbl_80433984[0x33] < 1) { - strcpy(&lbl_803BB340[lbl_804D38D0], - *(char**) (lbl_803BB300 + 0xAC8)); - lbl_80433A64[0x33] = HSD_SynthSFXLoad(lbl_803BB340, 1, 0, 0); + status = &((PoolAllocFull*) &lbl_80433710)->x274[0x33]; + if (*status < 1) { + path = base + lbl_804D38D0; + strcpy(path + 0x40, ((AudioDataFull*) base)->xAC8); + ((PoolAllocFull*) &lbl_80433710)->x354[0x33] = + HSD_SynthSFXLoad(base + 0x40, 1, 0, 0); HSD_SynthSFXWaitForLoadCompletion(lb_800195D0); - lbl_80433984[0x33] = 2; + *status = 2; } - if (lbl_80433984[1] < 1) { - strcpy(&lbl_803BB340[lbl_804D38D0], - *(char**) (lbl_803BB300 + 0xA00)); - lbl_80433A64[1] = HSD_SynthSFXLoad(lbl_803BB340, 1, 0, 0); + status = &((PoolAllocFull*) &lbl_80433710)->x274[1]; + if (*status < 1) { + path = base + lbl_804D38D0; + strcpy(path + 0x40, ((AudioDataFull*) base)->xA00); + ((PoolAllocFull*) &lbl_80433710)->x354[1] = + HSD_SynthSFXLoad(base + 0x40, 1, 0, 0); HSD_SynthSFXWaitForLoadCompletion(lb_800195D0); - lbl_80433984[1] = 2; + *status = 2; } - if (lbl_80433984[0x36] < 1) { - strcpy(&lbl_803BB340[lbl_804D38D0], - *(char**) (lbl_803BB300 + 0xAD4)); - lbl_80433A64[0x36] = HSD_SynthSFXLoad(lbl_803BB340, 1, 0, 0); + status = &((PoolAllocFull*) &lbl_80433710)->x274[0x36]; + if (*status < 1) { + path = base + lbl_804D38D0; + strcpy(path + 0x40, ((AudioDataFull*) base)->xAD4); + ((PoolAllocFull*) &lbl_80433710)->x354[0x36] = + HSD_SynthSFXLoad(base + 0x40, 1, 0, 0); HSD_SynthSFXWaitForLoadCompletion(lb_800195D0); - lbl_80433984[0x36] = 2; + *status = 2; } } } @@ -2618,6 +2612,29 @@ void lbAudioAx_80027DBC(void) fn_800269AC(); } +static inline int lbAudioAx_OtherVoiceVolume(int voice, int carry) +{ + return voice == -1 ? carry : 0x7F; +} + +static inline void lbAudioAx_80027DF8_inline(void) +{ + if (lbl_804D640C == 0) { + s32 i; + s32* t = lbl_80433710.x70; + s32* sl = lbl_80433710.x2C; + for (i = 0; i < 16; i++) { + if (t[i] > 0) { + (t[i])--; + } + if (t[i] <= 0) { + sl[i] = 0x83D60; + t[i] = 0; + } + } + } +} + void lbAudioAx_80027DF8(void) { s32 carry; @@ -2662,12 +2679,8 @@ void lbAudioAx_80027DF8(void) carry = 0; lbl_804D6428 = carry; lbl_804D38F0 = -1; - if (lbl_804D38F4 == -1) { - lbl_804D642C = carry; - } else { - carry = 0x7F; - lbl_804D642C = carry; - } + carry = lbAudioAx_OtherVoiceVolume(lbl_804D38F4, carry); + lbl_804D642C = carry; } } @@ -2695,14 +2708,10 @@ void lbAudioAx_80027DF8(void) fn_80023750(0x83D60, lbl_804D642C, 0x40, 6, 4); { carry = 0; - lbl_804D642C = 0; + lbl_804D642C = carry; lbl_804D38F4 = -1; - if (lbl_804D38F0 == -1) { - lbl_804D6428 = carry; - } else { - carry = 0x7F; - lbl_804D6428 = carry; - } + carry = lbAudioAx_OtherVoiceVolume(lbl_804D38F0, carry); + lbl_804D6428 = carry; } } @@ -2730,20 +2739,7 @@ void lbAudioAx_80027DF8(void) return; } - if (lbl_804D640C == 0) { - s32 i; - s32* t = lbl_80433710.x70; - s32* sl = lbl_80433710.x2C; - for (i = 0; i < 16; i++) { - if (t[i] > 0) { - (t[i])--; - } - if (t[i] <= 0) { - sl[i] = 0x83D60; - t[i] = 0; - } - } - } + lbAudioAx_80027DF8_inline(); } void lbAudioAx_8002835C(void) @@ -2751,50 +2747,55 @@ void lbAudioAx_8002835C(void) HSD_ObjAllocInit(&lbl_80433710.alloc, 0x48, 4); } +typedef struct lbAudioAx_PoolAllocFull { + HSD_ObjAllocData alloc; + s32 x2C[17]; + s32 x70[17]; + int xB4[0x38]; + int x194[0x38]; + int x274[0x38]; + int x354[0x38]; + int x434[0x38]; + u32 x514[0x10]; + u8 x554[0xD400]; + u8 xD954[0x11C00]; +} lbAudioAx_PoolAllocFull; + void lbAudioAx_8002838C(void) { struct AXFX_REVERBSTD rvbStd; struct AXFX_DELAY delay; - lbAudioAx_PoolAlloc* st = &lbl_80433710; + lbAudioAx_PoolAllocFull* st = (lbAudioAx_PoolAllocFull*) &lbl_80433710; + int (*offsets)[2] = offsets_arr_803BC4E4; int* p1; int* p2; int* p3; int* p4; int i; - char* ptr; - ARInit((u32*) &lbl_80433B44[0x38], 0x10); + ARInit(st->x514, 0x10); ARQInit(); AIInit(NULL); - PAD_STACK(8); + PAD_STACK(4); - lbl_804D643C = *(int*) (lbl_803BB300 + 0x11E4); - lbl_804D6440 = *(int*) (lbl_803BB300 + 0x137C); - lbl_804D6440 += *(int*) (lbl_803BB300 + 0x11EC); - lbl_804D6440 += *(int*) (lbl_803BB300 + 0x1394); + lbl_804D643C = offsets[0][0]; + lbl_804D6440 = offsets[0x33][0]; + lbl_804D6440 += offsets[1][0]; + lbl_804D6440 += offsets[0x36][0]; fn_80023254(3); - ptr = lbl_803BB300 + ((*(volatile int*) ((char*) lbl_80433B44)) << 3); - lbl_804D6444 = *(int*) (ptr + 0x11E4); + lbl_804D6444 = offsets[st->x434[0]][0]; fn_80023254(4); - ptr = lbl_803BB300 + ((*(volatile int*) ((char*) lbl_80433B44)) << 3); - lbl_804D6444 += *(int*) (ptr + 0x11E4); - ptr = - lbl_803BB300 + ((*(volatile int*) ((char*) lbl_80433B44 + 0x4)) << 3); - lbl_804D6444 += *(int*) (ptr + 0x11E4); - ptr = - lbl_803BB300 + ((*(volatile int*) ((char*) lbl_80433B44 + 0x8)) << 3); - lbl_804D6444 += *(int*) (ptr + 0x11E4); - ptr = - lbl_803BB300 + ((*(volatile int*) ((char*) lbl_80433B44 + 0xC)) << 3); - lbl_804D6444 += *(int*) (ptr + 0x11E4); + lbl_804D6444 += offsets[st->x434[0]][0]; + lbl_804D6444 += offsets[st->x434[1]][0]; + lbl_804D6444 += offsets[st->x434[2]][0]; + lbl_804D6444 += offsets[st->x434[3]][0]; fn_80023254(5); - ptr = lbl_803BB300 + ((*(volatile int*) ((char*) lbl_80433B44)) << 3); - lbl_804D6444 += *(int*) (ptr + 0x11E4); + lbl_804D6444 += offsets[st->x434[0]][0]; - lbl_804D6438 = lbl_804D643C + (lbl_804D6440 + lbl_804D6444); + lbl_804D6438 = lbl_804D643C + lbl_804D6440 + lbl_804D6444; lbl_804D3870 = lbl_804D6438; AXDriver_8038E498(0x40, 0, 0x40, lbl_804D3870); @@ -2803,24 +2804,22 @@ void lbAudioAx_8002838C(void) rvbStd.time = 1.88f; HSD_ASSERT(0xF6E, HSD_AudioGetAuxHeapSize(2, &rvbStd) < 53*1024); - AXDriver_8038E30C(0, 2, &rvbStd, (u8*) ((char*) lbl_80433B44 + 0x120), - 0xD400); + AXDriver_8038E30C(0, 2, &rvbStd, st->x554, 0xD400); AXDriver_8038E37C(AXDRIVER_AUX_DELAY, &delay); HSD_ASSERTMSG(0xF72, HSD_AudioGetAuxHeapSize(2, &delay) < 71 * 1024, "HSD_AudioGetAuxHeapSize(2, &delay) < 71*1024"); - AXDriver_8038E30C(1, 4, &delay, (u8*) ((char*) lbl_80433B44 + 0xD520), - 0x11C00); + AXDriver_8038E30C(1, 4, &delay, st->xD954, 0x11C00); HSD_SynthSFXAllocateBank(lbl_804D643C); HSD_SynthSFXAllocateBank(lbl_804D6440); HSD_SynthSFXAllocateBank(lbl_804D6444); - p1 = lbl_804337C4; - p2 = lbl_804338A4; - p3 = lbl_80433984; - p4 = lbl_80433A64; + p1 = st->xB4; + p2 = st->x194; + p3 = st->x274; + p4 = st->x354; for (i = 0; i < 7; i++) { p1[0] = -1; p2[0] = -1; @@ -2963,9 +2962,9 @@ s32 lbAudioAx_80028690(void) { int i; - for (i = 0; i < 17; i++) { - lbl_80433710.x2C[i] = 0x83D60; - lbl_80433710.x70[i] = 0; + for (i = 0; i <= 16; i++) { + ((s32(*)[17]) & st->x2C)[0][i] = 0x83D60; + ((s32(*)[17]) & st->x2C)[1][i] = 0; } } diff --git a/src/melee/lb/lbaudio_ax.h b/src/melee/lb/lbaudio_ax.h index df9fc056af..07b69a67cb 100644 --- a/src/melee/lb/lbaudio_ax.h +++ b/src/melee/lb/lbaudio_ax.h @@ -96,7 +96,7 @@ /* 027168 */ void lbAudioAx_80027168(void); /* 027488 */ s32 fn_80027488(void); /* 027648 */ void lbAudioAx_80027648(void); -/* 02785C */ s32 lbAudioAx_8002785C(void); +/* 02785C */ void lbAudioAx_8002785C(void); /* 027AB0 */ void lbAudioAx_80027AB0(s32); /* 027DBC */ void lbAudioAx_80027DBC(void); /* 027DF8 */ void lbAudioAx_80027DF8(void); diff --git a/src/melee/lb/lbbgflash.c b/src/melee/lb/lbbgflash.c index 28bdcebd8f..c74b594dc3 100644 --- a/src/melee/lb/lbbgflash.c +++ b/src/melee/lb/lbbgflash.c @@ -77,21 +77,22 @@ void fn_8001FC08(void) // When I try it just stays a loop in the asm BgFlashData* data = &lbl_80433658; f32 val; + f32 cur_val; + f32* cur; + u8 target; if (data->x20[0] > 0.0f) { - u8 target = data->x8.r; - f32* cur = &data->x10[0]; - val = *cur + data->x20[0]; - if (val < (f32) target) { + cur_val = *(cur = &data->x10[0]); + val = cur_val + data->x20[0]; + if (val < (f32) (target = data->x8.r)) { *cur = val; } else { *cur = (f32) target; } } else { - u8 target = data->x8.r; - f32* cur = &data->x10[0]; - val = *cur + data->x20[0]; - if (val > (f32) target) { + cur_val = *(cur = &data->x10[0]); + val = cur_val + data->x20[0]; + if (val > (f32) (target = data->x8.r)) { *cur = val; } else { *cur = (f32) target; @@ -99,19 +100,17 @@ void fn_8001FC08(void) } if (data->x20[1] > 0.0f) { - u8 target = data->x8.g; - f32* cur = &data->x10[1]; - val = *cur + data->x20[1]; - if (val < (f32) target) { + cur_val = *(cur = &data->x10[1]); + val = cur_val + data->x20[1]; + if (val < (f32) (target = data->x8.g)) { *cur = val; } else { *cur = (f32) target; } } else { - u8 target = data->x8.g; - f32* cur = &data->x10[1]; - val = *cur + data->x20[1]; - if (val > (f32) target) { + cur_val = *(cur = &data->x10[1]); + val = cur_val + data->x20[1]; + if (val > (f32) (target = data->x8.g)) { *cur = val; } else { *cur = (f32) target; @@ -119,19 +118,17 @@ void fn_8001FC08(void) } if (data->x20[2] > 0.0f) { - u8 target = data->x8.b; - f32* cur = &data->x10[2]; - val = *cur + data->x20[2]; - if (val < (f32) target) { + cur_val = *(cur = &data->x10[2]); + val = cur_val + data->x20[2]; + if (val < (f32) (target = data->x8.b)) { *cur = val; } else { *cur = (f32) target; } } else { - u8 target = data->x8.b; - f32* cur = &data->x10[2]; - val = *cur + data->x20[2]; - if (val > (f32) target) { + cur_val = *(cur = &data->x10[2]); + val = cur_val + data->x20[2]; + if (val > (f32) (target = data->x8.b)) { *cur = val; } else { *cur = (f32) target; @@ -139,19 +136,17 @@ void fn_8001FC08(void) } if (data->x20[3] > 0.0f) { - u8 target = data->x8.a; - f32* cur = &data->x10[3]; - val = *cur + data->x20[3]; - if (val < (f32) target) { + cur_val = *(cur = &data->x10[3]); + val = cur_val + data->x20[3]; + if (val < (f32) (target = data->x8.a)) { *cur = val; } else { *cur = (f32) target; } } else { - u8 target = data->x8.a; - f32* cur = &data->x10[3]; - val = *cur + data->x20[3]; - if (val > (f32) target) { + cur_val = *(cur = &data->x10[3]); + val = cur_val + data->x20[3]; + if (val > (f32) (target = data->x8.a)) { *cur = val; } else { *cur = (f32) target; @@ -258,12 +253,12 @@ void fn_8001FEC4(HSD_GObj* gobj, s32 code) s32* pY; s32 y2; - for (pY = &data->x38, y2 = data->x38; y2 <= 0x1E0; y2 += data->x32) + for (y2 = *(pY = &data->x38); y2 <= 0x1E0; y2 += data->x32) { if (y2 == *pY) { - s32 x34; - u8 strip_h; s32 right; + u8 strip_h; + s32 x34; s32 neg_y; s32 xr; s32 neg_yh; @@ -274,7 +269,7 @@ void fn_8001FEC4(HSD_GObj* gobj, s32 code) right -= x34; GXBegin(GX_QUADS, GX_VTXFMT0, 4); neg_y = -y2; - xr = right + x34; + xr = x34 + right; neg_yh = -(y2 + strip_h); GXPosition2f32((f32) x34, (f32) neg_y); GXColor4u8(0, 0, 0, 0xFF); @@ -508,7 +503,7 @@ void fn_80020AEC(HSD_JObj* jobj, Mtx out) Mtx tmp; Vec3 col; volatile f32 scale_mag; - u8 _[16]; + u8 _[4]; if (jobj == NULL) { parent = NULL; @@ -577,12 +572,10 @@ void fn_80020AEC(HSD_JObj* jobj, Mtx out) } else { grandpar = cur->parent; } - HSD_JObjGetMtxPtr(cur); - HSD_JObjGetMtxPtr(grandpar); - HSD_MtxInverseConcat(grandpar->mtx, cur->mtx, tmp); + HSD_MtxInverseConcat(HSD_JObjGetMtxPtr(grandpar), + HSD_JObjGetMtxPtr(cur), tmp); } else { - HSD_JObjGetMtxPtr(cur); - PSMTXCopy(cur->mtx, tmp); + PSMTXCopy(HSD_JObjGetMtxPtr(cur), tmp); } for (i = 0; i < 3; i++) { @@ -620,16 +613,13 @@ void lbBgFlash_80020E38(HSD_JObj* jobj, Vec3* dir, f32 max_angle, Mtx resultMtx; volatile f32 tmp; f32 z_col_z; - f32 dx = dir->x; - f32 dy = dir->y; - f32 dz = dir->z; - f32 mag_sq; f32 angle; f32 z_col_y; f32 z_col_x; - f32 dx2 = dx * dx; - f32 dy2 = dy * dy; - dz2 = dz * dz; + f32 mag_sq; + f32 dx2 = dir->x * dir->x; + f32 dy2 = dir->y * dir->y; + dz2 = dir->z * dir->z; (void) dz2; if (dx2 + dy2 + dz2 == 0.0f) { return; @@ -640,8 +630,9 @@ void lbBgFlash_80020E38(HSD_JObj* jobj, Vec3* dir, f32 max_angle, z_col_y = jobj->mtx[1][2]; z_col_x = jobj->mtx[0][2]; z_col_z = jobj->mtx[2][2]; - mag_sq = z_col_x * z_col_x + z_col_y * z_col_y; - mag_sq = z_col_z * z_col_z + mag_sq; + z_col_x = SQ(z_col_x) + SQ(z_col_y); + mag_sq = z_col_x; + mag_sq = SQ(z_col_z) + mag_sq; if (mag_sq > 0.0f) { f64 e = __frsqrte(mag_sq); e = 0.5 * e * -(((f64) mag_sq * (e * e)) - 3.0); @@ -757,8 +748,8 @@ void lbBgFlash_80021410(void* arg0) f32 acos2; f64 rem; f32 dx; - f32 dy; f32 dz; + f32 dy; Vec3* pDiff; PAD_STACK(16); @@ -847,13 +838,16 @@ void lbBgFlash_80021410(void* arg0) dx *= dx; dy *= dy; dz *= dz; - if ((len_bc = dz + (dx + dy)) > 0.0f) { - f64 e = __frsqrte(len_bc); - e = 0.5 * e * -(((f64) len_bc * (e * e)) - 3.0); - e = 0.5 * e * -(((f64) len_bc * (e * e)) - 3.0); - e = 0.5 * e * -(((f64) len_bc * (e * e)) - 3.0); - len_bc_mag = (f32) ((f64) len_bc * e); - len_bc = len_bc_mag; + { + int positive = (len_bc = dz + (dx + dy)) > 0.0f; + if (positive) { + f64 e = __frsqrte(len_bc); + e = 0.5 * e * -(((f64) len_bc * (e * e)) - 3.0); + e = 0.5 * e * -(((f64) len_bc * (e * e)) - 3.0); + e = 0.5 * e * -(((f64) len_bc * (e * e)) - 3.0); + len_bc_mag = (f32) ((f64) len_bc * e); + len_bc = len_bc_mag; + } } data->len0 = len_bc; diff --git a/src/melee/lb/lbcardnew.c b/src/melee/lb/lbcardnew.c index 36cdc6db1c..5804f63347 100644 --- a/src/melee/lb/lbcardnew.c +++ b/src/melee/lb/lbcardnew.c @@ -670,17 +670,12 @@ int lb_8001B14C(void) node++; } } - { - struct SnapshotNode** copy_scan; - int j; - - copy_scan = &head; - for (j = 0; j < count; j++) { - lb_80432A68.snapshot_entries[j].time = (*copy_scan)->time; - lb_80432A68.snapshot_entries[j].file_no = (*copy_scan)->file_no; - lb_80432A68.snapshot_entries[j].blocks = (*copy_scan)->blocks; - copy_scan = &(*copy_scan)->next; - } + scan = &head; + for (file_no = 0; file_no < count; file_no++) { + lb_80432A68.snapshot_entries[file_no].time = (*scan)->time; + lb_80432A68.snapshot_entries[file_no].file_no = (*scan)->file_no; + lb_80432A68.snapshot_entries[file_no].blocks = (*scan)->blocks; + scan = &(*scan)->next; } for (i = count; i < 0x7F; i++) { lb_80432A68.snapshot_entries[i].file_no = -1; diff --git a/src/melee/lb/lbcollision.c b/src/melee/lb/lbcollision.c index bb238b57e2..aed6141e57 100644 --- a/src/melee/lb/lbcollision.c +++ b/src/melee/lb/lbcollision.c @@ -332,12 +332,11 @@ bool lbColl_80006094(Vec3* arg0, Vec3* arg1, Vec3* arg2, Vec3* arg3, { u8 operand_pad[8]; { - Vec3 vec4; Vec3 arg4_offset; Vec3 arg5_offset; float temp_f1; float unk_sum = arg6 + arg7; - vec4 = *arg0; + Vec3 vec4 = *arg0; (void) vec4; arg4_offset = vec4; { @@ -463,19 +462,20 @@ bool lbColl_80006094(Vec3* arg0, Vec3* arg1, Vec3* arg2, Vec3* arg3, float d2_x = arg3_x - arg5_offset.x; float arg3_z = arg3->z; float d2_z = arg3_z - arg5_offset.z; - float d1_dot_d2 = d1_z * d2_z + d1_x * d2_x + d1_y * d2_y; + float d1_dot_d2 = d1_x * d2_x + d1_z * d2_z + d1_y * d2_y; float d2_z_sq = d2_z * d2_z; float d2_len_sq = d2_z_sq + d2_x * d2_x + d2_y * d2_y; float offset_delta_x = arg4_offset.x - arg5_offset.x; float d1_len_sq = (d1_z * d1_z) + ((d1_x * d1_x) + (d1_y * d1_y)); float offset_delta_z = arg4_offset.z - arg5_offset.z; - float d2_dot_offset_delta = d2_z * offset_delta_z + - d2_x * offset_delta_x + - d2_y * offset_delta_y; + float d2_y_offset = d2_y * offset_delta_y; + float d2_dot_offset_delta = + d2_z * offset_delta_z + d2_x * offset_delta_x + d2_y_offset; float d1_dot_offset_delta = (d1_z * offset_delta_z) + d1_x * offset_delta_x + d1_y * offset_delta_y; - float denom = d1_len_sq * d2_len_sq - d1_dot_d2 * d1_dot_d2; + float len_product = d1_len_sq * d2_len_sq; + float denom = len_product - d1_dot_d2 * d1_dot_d2; { float arg5_scl; @@ -655,14 +655,19 @@ bool lbColl_80006094(Vec3* arg0, Vec3* arg1, Vec3* arg2, Vec3* arg3, } } +static inline float lbColl_Dot2(float ay, float by, float bx, float ax) +{ + return ax * bx + by * ay; +} + bool lbColl_800067F8(Vec3* a, Vec3* b, Vec3* c, Vec3* d, Vec3* e, Vec3* f, float p, float q, float r) { Vec3 a1; float sum_pq = p + q; + Vec3 a0; u8 operand_pad[12]; - Vec3 a0; PAD_STACK(72); a0 = *a; @@ -711,7 +716,8 @@ bool lbColl_800067F8(Vec3* a, Vec3* b, Vec3* c, Vec3* d, Vec3* e, Vec3* f, } { - float b_y = b->y; + float loaded_b_y = b->y; + float b_y = loaded_b_y; if (a1.y > b_y) { { float y; @@ -753,7 +759,8 @@ bool lbColl_800067F8(Vec3* a, Vec3* b, Vec3* c, Vec3* d, Vec3* e, Vec3* f, float diff_dc_x = d_x - c1.x; float dot2_diff_ba_dc = - diff_ba_x * diff_dc_x + diff_ba_y * diff_dc_y; + lbColl_Dot2(diff_ba_y, diff_dc_y, diff_dc_x, + diff_ba_x); float sqdist2_dc = diff_dc_x * diff_dc_x + diff_dc_y * diff_dc_y; @@ -773,7 +780,6 @@ bool lbColl_800067F8(Vec3* a, Vec3* b, Vec3* c, Vec3* d, Vec3* e, Vec3* f, { float scl_e; float scl_f; - float out0; float out1; if (approximatelyZero(sqdist2_dc)) { if (approximatelyZero(sqdist2_ba)) { @@ -911,6 +917,7 @@ bool lbColl_800067F8(Vec3* a, Vec3* b, Vec3* c, Vec3* d, Vec3* e, Vec3* f, (scl_f > lbColl_804D7A00) || (scl_f < lbColl_804D7A10)) { + float out0; float result0; float temp_scl_e; { @@ -996,16 +1003,17 @@ bool lbColl_80006E58(Vec3* hit_start, Vec3* hit_end, Vec3* hurt_start, float* out_overlap, float hit_radius, float hurt_radius, float broadphase_scale) { - float hurt_len_sq; + float hit_end_min_z; float closest_delta_x; float hit_start_mid_x; float local_delta_x; float hurt_mid_z; Vec3 hit_start_copy; + u8 operand_pad[4]; Vec3 hurt_start_copy; Vec3 hit_delta; - Mtx inv_hurt_mtx; - float candidate_hit_param; + float start_delta_z; + float hit_start_dot; float scaled_hurt_radius; float hurt_mid_x; float hurt_mid_y; @@ -1025,7 +1033,7 @@ bool lbColl_80006E58(Vec3* hit_start, Vec3* hit_end, Vec3* hurt_start, float local_delta_y; float start_delta_x; float start_delta_y; - float start_delta_z; + Mtx inv_hurt_mtx; float hurt_delta_x; float hit_start_max_x; float hit_end_min_x; @@ -1041,9 +1049,9 @@ bool lbColl_80006E58(Vec3* hit_start, Vec3* hit_end, Vec3* hurt_start, float hit_end_min_y; float hit_start_min_y; float hit_end_max_y; - float hit_end_min_z; + float hurt_len_sq; float hit_end_max_z; - float hit_start_dot; + float candidate_hit_param; float hit_end_x; float hit_len_sq; float hit_end_mid_x; @@ -1053,14 +1061,14 @@ bool lbColl_80006E58(Vec3* hit_start, Vec3* hit_end, Vec3* hurt_start, float hurt_end_x; float hit_end_z; float hurt_end_y; - float hurt_end_z; + float segment_dot; float hit_param; float local_dist; float hurt_param; float hurt_param_from_hit_start; float hurt_param_from_hit_end; float closest_dist; - float segment_dot; + float hurt_end_z; f64 local_rsqrt_estimate; f64 local_rsqrt_step1; f64 local_rsqrt_step2; @@ -1363,8 +1371,8 @@ bool lbColl_80006E58(Vec3* hit_start, Vec3* hit_end, Vec3* hurt_start, closest_delta_x = hit_closest->x - hurt_closest->x; closest_delta_z = hit_closest->z - hurt_closest->z; closest_dist_sq = (closest_delta_z * closest_delta_z) + - ((closest_delta_x * closest_delta_x) + - (closest_delta_y * closest_delta_y)); + ((closest_delta_y * closest_delta_y) + + (closest_delta_x * closest_delta_x)); if (closest_dist_sq > lbColl_804D79F8) { volatile float sp38; @@ -1402,8 +1410,8 @@ bool lbColl_80006E58(Vec3* hit_start, Vec3* hit_end, Vec3* hurt_start, HSD_MtxInverse(hurt_mtx, inv_hurt_mtx); PSMTXMultVec(inv_hurt_mtx, hit_closest, &hit_start_copy); PSMTXMultVec(inv_hurt_mtx, hurt_closest, &hit_delta); - local_delta_y = hit_start_copy.y - hit_delta.y; local_delta_x = hit_start_copy.x - hit_delta.x; + local_delta_y = hit_start_copy.y - hit_delta.y; local_delta_z = hit_start_copy.z - hit_delta.z; local_dist_sq = (local_delta_z * local_delta_z) + @@ -1432,8 +1440,8 @@ bool lbColl_80006E58(Vec3* hit_start, Vec3* hit_end, Vec3* hurt_start, scaled_hurt_radius = (hurt_radius * closest_dist) / local_dist; contact_lerp = scaled_hurt_radius / closest_dist; allowed_distance = hit_radius + scaled_hurt_radius; - hurt_closest_x = hurt_closest->x; *out_overlap = allowed_distance - closest_dist; + hurt_closest_x = hurt_closest->x; out_contact_pos->x = (contact_lerp * (hit_closest->x - hurt_closest_x)) + hurt_closest_x; hurt_closest_y = hurt_closest->y; diff --git a/src/melee/lb/lbdvd.c b/src/melee/lb/lbdvd.c index 2085bb0fc0..de11f34e3f 100644 --- a/src/melee/lb/lbdvd.c +++ b/src/melee/lb/lbdvd.c @@ -462,13 +462,25 @@ void lbDvd_8001823C(void) preloadCache.new_scene.mode_scene_changes + 1; } -void lbDvd_80018254(void) +static inline void inline_preload_entries(bool* enabled) { - bool enabled; PreloadEntry* entry; int i; - PAD_STACK(0x18); + *enabled = OSDisableInterrupts(); + for (i = 0; i < (signed) ARRAY_SIZE(preloadCache.entries); i++) { + entry = &preloadCache.entries[i]; + if (entry->state != 0) { + if (entry->load_score > 0) { + entry->load_score *= -1; + } + } + } +} + +void lbDvd_80018254(void) +{ + bool enabled; if (memcmp(&preloadCache.new_scene, &preloadCache.scene, sizeof(PreloadCacheScene)) == 0) @@ -477,16 +489,9 @@ void lbDvd_80018254(void) } preloadCache.new_scene = preloadCache.scene; - enabled = OSDisableInterrupts(); + inline_preload_entries(&enabled); - for (i = 0; i < (signed) ARRAY_SIZE(preloadCache.entries); i++) { - entry = &preloadCache.entries[i]; - if (entry->state != 0) { - if (entry->load_score > 0) { - entry->load_score *= -1; - } - } - } + PAD_STACK(0x18); switch (preloadCache.persistent_heaps) { case 0: diff --git a/src/melee/lb/lbmemory.c b/src/melee/lb/lbmemory.c index 416ba0207f..861a1a73fa 100644 --- a/src/melee/lb/lbmemory.c +++ b/src/melee/lb/lbmemory.c @@ -268,14 +268,14 @@ u32 lbMemory_8001529C(Handle* h, void* arg1, u32 arg2) void lbMemory_80015320(int arg0, Handle* handle, int arg2, int cancelflag) { - struct Allocator* alloc; - struct LBMgr* mgr; int enabled; - void** currentp; u32 size; - u32 current; u32 old; + void** currentp; Handle* next; + struct LBMgr* mgr; + struct Allocator* alloc; + u32 current; alloc = &g_alloc; currentp = &alloc->x6E4; @@ -288,12 +288,14 @@ void lbMemory_80015320(int arg0, Handle* handle, int arg2, int cancelflag) if (handle != NULL) { if ((old = (u32) handle->x4_lo) != current) { handle->x4_lo = (void*) current; + arg0 = old; *currentp = (void*) ((u32) handle->x4_lo + (u32) handle->x8_hi); if ((u32) handle->x4_lo < 0x80000000U) { HSD_DevComRequest( - 0, old, current, ((u32) handle->x8_hi + 0x1F) & 0xFFFFFFE0, - 0x1B, 1, (HSD_DevComCallback) (Event) lbMemory_80015320, + 0, arg0, current, + ((u32) handle->x8_hi + 0x1F) & 0xFFFFFFE0, 0x1B, 1, + (HSD_DevComCallback) (Event) lbMemory_80015320, handle->x0_next); return; } else { diff --git a/src/melee/lb/lbmthp.c b/src/melee/lb/lbmthp.c index f16eb44f0d..90aace4844 100644 --- a/src/melee/lb/lbmthp.c +++ b/src/melee/lb/lbmthp.c @@ -204,14 +204,13 @@ void fn_8001ECF4(THPDecComp* data, void* buf) u32 var_r25; u32 var_r24; u8* csizep; - PAD_STACK(8); width = data->width; height = data->height; - data->frame_buffers = (u32*) buf; y_size = width * height; + data->frame_buffers = (u32*) buf; count = data->unk_104; data->unk_64 = 0; - uv_size = y_size >> 2U; + uv_size = (width * height) >> 2U; var_r29 = (u8*) buf + (((count * 4) + 0x1F) & 0xFFFFFFE0); if (((s32) data->unk_6C != 0) && ((s32) data->unk_11C != 0)) { var_r24 = data->first_frame_size; @@ -384,20 +383,18 @@ static inline u32 lbMthp_GetFrame(u32** rate_table, u32 counter) u32* rate_ptr = *rate_table; u32 frame = 0; u32 count; - u32 ticks; u32 total; if (rate_ptr != NULL) { for (;; rate_ptr += 2) { count = rate_ptr[0]; - ticks = rate_ptr[1]; - total = ticks * count; + total = count * rate_ptr[1]; if (counter >= total) { frame += count; counter -= total; continue; } else { - frame += counter / ticks; + frame += counter / rate_ptr[1]; break; } } @@ -408,14 +405,26 @@ static inline u32 lbMthp_GetFrame(u32** rate_table, u32 counter) return frame; } +static inline void lbMthp_GetPlayer(struct lbl_804333E0_t** streamPlayer, + u32*** rate_table) +{ + *streamPlayer = &MoviePlayer; + *rate_table = &(*streamPlayer)->rate_table; +} + +static inline THPDecComp* lbMthp_GetDecoder( + struct lbl_804333E0_t* streamPlayer) +{ + return (THPDecComp*) streamPlayer; +} + void fn_8001F2A4(OSAlarm* alarm, OSContext* context) { struct lbl_804333E0_t* streamPlayer; u32** rate_table; u32 frame; - streamPlayer = &MoviePlayer; - rate_table = &streamPlayer->rate_table; + lbMthp_GetPlayer(&streamPlayer, &rate_table); frame = lbMthp_GetFrame(rate_table, streamPlayer->unk_80); @@ -437,7 +446,7 @@ void fn_8001F2A4(OSAlarm* alarm, OSContext* context) frame = lbMthp_GetFrame(rate_table, streamPlayer->unk_80); if ((u32) streamPlayer->unk_78 != frame) { - fn_8001F06C((THPDecComp*) streamPlayer); + fn_8001F06C(lbMthp_GetDecoder(streamPlayer)); } } @@ -445,6 +454,8 @@ void lbMthp_8001F410(const char* filename, u32* rate_table, void* buf, size_t heap_size, int loop) { size_t memoryRequired; + OSTime start; + OSTime period; HSD_ASSERT(833, !MoviePlayer.power); MoviePlayer.power = 1; @@ -463,9 +474,12 @@ void lbMthp_8001F410(const char* filename, u32* rate_table, void* buf, MoviePlayer.unk_144 = 0; MoviePlayer.unk_148 = 1; OSCreateAlarm(&MoviePlayer.alarm); + period = __cvt_dbl_usll(OSSecondsToTicks(1.0f / 60)); + start = __cvt_dbl_usll(OSSecondsToTicks(1.0f / 60)); OSSetPeriodicAlarm( - &MoviePlayer.alarm, __cvt_dbl_usll(OSSecondsToTicks(1.0f / 60)), - __cvt_dbl_usll(OSSecondsToTicks(1.0f / 60)), fn_8001F2A4); + (OSAlarm*) ((uintptr_t) &MoviePlayer + + offsetof(struct lbl_804333E0_t, alarm)), + start, period, fn_8001F2A4); } void lbMthp_8001F578(void) diff --git a/src/melee/lb/lbrefract.c b/src/melee/lb/lbrefract.c index f2fd625bec..0e058e7bc1 100644 --- a/src/melee/lb/lbrefract.c +++ b/src/melee/lb/lbrefract.c @@ -119,9 +119,8 @@ void lbRefract_80021CE8(void* arg0, s32 arg1) f32 dist; f32 param0; f32* params; - volatile f32 sp18; - PAD_STACK(20); + PAD_STACK(12); param_idx = arg1 * 2; x_step = 2.0f / (f32) (u32) (cb->width - 1); @@ -133,13 +132,17 @@ void lbRefract_80021CE8(void* arg0, s32 arg1) x = -1.0f; for (row = 0; row < (u32) cb->width; row++) { if ((dist_sq = x * x + y_sq) > 0.0f) { + f32 sqrt_dist; + f32* sqrt_dist_ptr = &sqrt_dist; f64 est = __frsqrte((f64) dist_sq); + PAD_STACK(4); est = 0.5 * est * -(((f64) dist_sq * (est * est)) - 3.0); est = 0.5 * est * -(((f64) dist_sq * (est * est)) - 3.0); - sp18 = (f32) ((f64) dist_sq * - (0.5 * est * - -(((f64) dist_sq * (est * est)) - 3.0))); - dist_sq = sp18; + *sqrt_dist_ptr = + (f32) ((f64) dist_sq * + (0.5 * est * + -(((f64) dist_sq * (est * est)) - 3.0))); + dist_sq = *sqrt_dist_ptr; } dist = dist_sq; if (dist_sq > 1.0f) { @@ -170,8 +173,8 @@ void lbRefract_80021CE8(void* arg0, s32 arg1) } ((void (*)(lbRefract_CallbackData*, s32, s32, s32, s32, u32, u32)) cb->callback0)( - cb, row, col, 0, 0, (u32) (127.0f * (y * param0) + 128.0f), - (u32) (127.0f * (x * param0) + 128.0f)); + cb, row, col, 0, 0, (u32) (127.0f * (x * param0) + 128.0f), + (u32) (127.0f * (y * param0) + 128.0f)); x += x_step; } y += y_step; @@ -362,12 +365,12 @@ s32 lbRefract_8002219C(lbRefract_CallbackData* data, s32 buffer, s32 format, void lbRefract_800222A4(void) { lbRefract_CallbackData cb; - void* buf; + struct lbRefract_DataLayout* data = &lbl_803BB0B0; u32 i; + void* buf; lbl_804336D0.refractionUserCount = 0; - lbArchive_LoadSymbols(lbl_803BB0B0.filename, &skip8_804D63E8, - lbl_803BB0B0.symbol, 0); + lbArchive_LoadSymbols(data->filename, &skip8_804D63E8, data->symbol, 0); { s32 buf_size = GXGetTexBufferSize(0x140, 0xF0, 4, 0, 0); lbl_804336D0.image_ptr = HSD_MemAlloc(buf_size); @@ -383,22 +386,22 @@ void lbRefract_800222A4(void) { HSD_ImageDesc* dst = &lbl_804336D0.unk_8[i]; - *dst = lbl_803BB0B0.imagedesc0; + *dst = data->imagedesc0; } - lbl_803BB0B0.tobj1.imagedesc = &lbl_804336D0.unk_8[i]; + data->tobj1.imagedesc = &lbl_804336D0.unk_8[i]; - lbl_804336D0.unk_C[i] = HSD_TObjLoadDesc(&lbl_803BB0B0.tobj1); + lbl_804336D0.unk_C[i] = HSD_TObjLoadDesc(&data->tobj1); - lbl_803BB0B0.imagedesc0.image_ptr = (void*) lbl_804336D0.image_ptr; - lbl_803BB0B0.imagedesc0.format = 4; - lbl_803BB0B0.imagedesc0.width = 0x140; - lbl_803BB0B0.imagedesc0.height = 0xF0; + data->imagedesc0.image_ptr = lbl_804336D0.image_ptr; + data->imagedesc0.format = 4; + data->imagedesc0.width = 0x140; + data->imagedesc0.height = 0xF0; - lbl_804336D0.unk_8[i].image_ptr = buf; - lbl_804336D0.unk_8[i].format = 3; - lbl_804336D0.unk_8[i].width = 0x20; - lbl_804336D0.unk_8[i].height = 0x20; + lbl_804336D0.unk_8[(s32) i].image_ptr = buf; + lbl_804336D0.unk_8[(s32) i].format = 3; + lbl_804336D0.unk_8[(s32) i].width = 0x20; + lbl_804336D0.unk_8[(s32) i].height = 0x20; } } @@ -463,17 +466,57 @@ static void lbRefract_DObjDispReset(HSD_DObj* dobj, Mtx vmtx, Mtx pmtx, HSD_StateInvalidate(-1); } +/* Initializer values mirror the retail .data image of this block + * (803BB0B0..803BB2F8): texture/half matrices, the two image descriptors + * (RGB565 640x240 source, IA8 32x32 tiles), their shared LOD settings, and + * the TObj pair chained tobj1 -> tobj0, plus the LbRf.dat archive names. */ struct lbRefract_DataLayout lbl_803BB0B0 = { - { { 0 } }, - { 0 }, - { 0 }, - { 0 }, - { 0 }, - { 0 }, - { 0 }, - { 0 }, - "", - "", + { { 0.5F, 0.0F, 0.0F, 0.5F }, + { 0.0F, -0.5F, 0.0F, 0.5F }, + { 0.0F, 0.0F, 0.0F, 1.0F } }, + { -0.5F, 0.0F, 0.0F, 0.0F, -0.5F, 0.0F }, + { NULL, 0, 0, 4, 0, 0.0F, 0.0F }, + { 1, 0.0F, 1, 1, 0 }, + { NULL, + NULL, + 0, + 0, + { 0.0F, 0.0F, 0.0F }, + { 1.0F, 1.0F, 1.0F }, + { 0.0F, 0.0F, 0.0F }, + 0, + 0, + 1, + 1, + 0x83, + 1.0F, + 1, + &lbl_803BB0B0.imagedesc0, + NULL, + &lbl_803BB0B0.lod0, + NULL }, + { NULL, 0, 0, 3, 0, 0.0F, 0.0F }, + { 1, 0.0F, 1, 1, 0 }, + { NULL, + &lbl_803BB0B0.tobj0, + 1, + 1, + { 0.0F, 0.0F, 0.0F }, + { 1.0F, 1.0F, 1.0F }, + { 0.0F, 0.0F, 0.0F }, + 0, + 0, + 1, + 1, + 0x81, + 1.0F, + 1, + &lbl_803BB0B0.imagedesc1, + NULL, + &lbl_803BB0B0.lod1, + NULL }, + "LbRf.dat", + "lbRefData", { fn_80022650 }, { fn_80022940 }, "refract_class_library", @@ -509,9 +552,9 @@ s32 lbRefract_PObjLoad(HSD_PObj* pobj, HSD_PObjDesc* desc) } verts = pobj->verts; - last_offset = -1; - pnmtx_offset = -1; stride = 0; + pnmtx_offset = -1; + last_offset = -1; while (verts != NULL && (attr = verts->attr) != GX_VA_NULL) { if (attr < GX_VA_CLR0) { @@ -602,55 +645,12 @@ s32 lbRefract_PObjLoad(HSD_PObj* pobj, HSD_PObjDesc* desc) ptr = display + offset; hi = ptr[0]; - copied = 0; - count = ptr[1]; + count = (hi << 8) | ptr[1]; offset += 2; - count = (count & ~0xFF00) | (hi << 8); - - if (count > 0) { - s32 n = count - 8; - - if (count > 8) { - u32 iters = (u32) (n + 7) >> 3U; - - if (n > 0) { - do { - dst[offset] = src[offset]; - offset += stride; - dst[offset] = src[offset]; - offset += stride; - dst[offset] = src[offset]; - offset += stride; - dst[offset] = src[offset]; - offset += stride; - dst[offset] = src[offset]; - offset += stride; - dst[offset] = src[offset]; - offset += stride; - dst[offset] = src[offset]; - offset += stride; - dst[offset] = src[offset]; - offset += stride; - copied += 8; - } while (--iters != 0); - } - } - { - u8* sp = src + offset; - u8* dp = dst + offset; - - if (copied < count) { - s32 remaining = count - copied; - - do { - *dp = *sp; - sp += stride; - offset += stride; - dp += stride; - } while (--remaining != 0); - } - } + for (copied = 0; copied < count; copied++) { + dst[offset] = src[offset]; + offset += stride; } } diff --git a/src/melee/lb/lbshadow.c b/src/melee/lb/lbshadow.c index 2daa4ec171..9ea7817fd2 100644 --- a/src/melee/lb/lbshadow.c +++ b/src/melee/lb/lbshadow.c @@ -29,6 +29,8 @@ void lbShadow_8000E9F0(Vec3* p, HSD_Spline* spline, f32 u) f32 t; f32 orig_u; + PAD_STACK(8); + if (u < 0.0F || u > 1.0F) { return; } @@ -54,8 +56,8 @@ void lbShadow_8000E9F0(Vec3* p, HSD_Spline* spline, f32 u) t2 = 3.0F * (t * t); bez1 = 1.0F - (4.0F * t); u_1 = t - 1.0F; - bez1 = 3.0F * (bez1 + t2); bez0 = -3.0F * u_1 * u_1; + bez1 = 3.0F * (bez1 + t2); bez2 = 3.0F * ((2.0F * t) - t2); p->x = (cp[3].x * t2) + ((cp[2].x * bez2) + ((cp[0].x * bez0) + (cp[1].x * bez1))); @@ -66,20 +68,17 @@ void lbShadow_8000E9F0(Vec3* p, HSD_Spline* spline, f32 u) return; } case 2: { - f32 u2, u_1, half, b1, b0, b2, b3; + f32 b3, b2, b1, b0, half, u_1, u2; cp = &spline->cv[idx]; u2 = t * t; u_1 = 1.0F - t; half = 0.5F; - b1 = half * ((3.0F * u2) - (4.0F * t)); { f32 b0_tmp = u_1 * (-half * u_1); b0 = b0_tmp; } - { - f32 b2_tmp = half * (1.0F + ((-3.0F * u2) + (2.0F * t))); - b2 = b2_tmp; - } + b1 = half * ((3.0F * u2) - (4.0F * t)); + b2 = half * (1.0F + ((-3.0F * u2) + (2.0F * t))); b3 = half * u2; p->x = (cp[3].x * b3) + ((cp[2].x * b2) + ((cp[0].x * b0) + (cp[1].x * b1))); @@ -90,22 +89,19 @@ void lbShadow_8000E9F0(Vec3* p, HSD_Spline* spline, f32 u) return; } case 3: { - f32 tension = spline->tension; f32 u2 = t * t; + f32 tension = spline->tension; f32 car1, car0, car3, car2; cp = &spline->cv[idx]; - car1 = (3.0F * (2.0F - tension) * u2) + (2.0F * (tension - 3.0F) * t); car0 = tension * (((-3.0F * u2) + (4.0F * t)) - 1.0F); - car3 = tension * ((3.0F * u2) - (2.0F * t)); + car1 = (3.0F * (2.0F - tension) * u2) + (2.0F * (tension - 3.0F) * t); car2 = tension + ((3.0F * (tension - 2.0F) * u2) + (2.0F * -((2.0F * tension) - 3.0F) * t)); + car3 = tension * ((3.0F * u2) - (2.0F * t)); p->x = (cp[3].x * car3) + ((cp[2].x * car2) + ((cp[0].x * car0) + (cp[1].x * car1))); - { - f32 car0_y = cp[0].y * car0; - p->y = (cp[3].y * car3) + - ((cp[2].y * car2) + ((car0_y) + (cp[1].y * car1))); - } + p->y = (cp[3].y * car3) + + ((cp[2].y * car2) + ((cp[0].y * car0) + (cp[1].y * car1))); p->z = (cp[3].z * car3) + ((cp[2].z * car2) + ((cp[0].z * car0) + (cp[1].z * car1))); break; diff --git a/src/melee/lb/lbsnap.c b/src/melee/lb/lbsnap.c index c00a6a8408..4155d8264a 100644 --- a/src/melee/lb/lbsnap.c +++ b/src/melee/lb/lbsnap.c @@ -176,9 +176,12 @@ int lbSnap_8001D7B0(int chan, int index, int jndex) #define RGB565_MASK_G (0x07E0) #define RGB565_MASK_B (0x001F) -#define RGB565_TO_RGB5A3(x) \ - (((x) & RGB5A3_MASK_B) | (((x) >> 1) & (RGB5A3_MASK_R | RGB5A3_MASK_G)) | \ - RGB5A3_MASK_A) +static inline u16 RGB565_TO_RGB5A3(u16 pixel) +{ + u16 result = pixel & RGB5A3_MASK_B; + result |= (pixel >> 1) & (RGB5A3_MASK_R | RGB5A3_MASK_G); + return result | RGB5A3_MASK_A; +} static inline int lbSnap_GetTiledRGBOffset(int x, int y, int tile_stride) { @@ -201,12 +204,11 @@ static inline int lbSnap_GetTiledColumn(int x) return (x / 4) * 24; } -void lbSnap_8001DA5C(int arg0) +void lbSnap_8001DA5C(u8* arg0) { u8* dst = lbSnap_GetMemSnapIconData(); int dst_x; int ctr; - PAD_STACK(8); for (dst_x = 0; dst_x < 32; dst_x++) { int src_x = (dst_x * 204 / 32) + 138; @@ -216,13 +218,13 @@ void lbSnap_8001DA5C(int arg0) int src_y_accum = 0; u16 pixel; for (ctr = 0; ctr < 32; ctr++) { - pixel = *(u16*) &((u8*) arg0)[lbSnap_GetTiledRGBOffset( + pixel = *(u16*) &arg0[lbSnap_GetTiledRGBOffset( src_x, src_y_accum / 64 + 96, 160)]; *(u16*) &dst_col[lbSnap_GetTiledYOff(tile_column, dst_y + 16)] = RGB565_TO_RGB5A3(pixel); src_y_accum += 448; - pixel = *(u16*) &((u8*) arg0)[lbSnap_GetTiledRGBOffset( + pixel = *(u16*) &arg0[lbSnap_GetTiledRGBOffset( src_x, src_y_accum / 64 + 96, 160)]; *(u16*) &dst_col[lbSnap_GetTiledYOff(tile_column, dst_y + 17)] = RGB565_TO_RGB5A3(pixel); @@ -233,7 +235,7 @@ void lbSnap_8001DA5C(int arg0) } } -int lbSnap_8001DC0C(int arg0) +int lbSnap_8001DC0C(u8* arg0) { OSTime ticks; u32 seconds; @@ -252,7 +254,7 @@ int lbSnap_8001DC0C(int arg0) hsd_803B5C2C(lbSnap_80433380.x0->x8); lbSnap_80433380.x0->xC = hsd_803B51C8(arg0, lbSnap_80433380.x0->x4, lbSnap_80433380.x0->x6, - lbSnap_80433380.x0->x38, 256000); + (u8*) lbSnap_80433380.x0->x38, 256000); if (lbSnap_80433380.x0->xC != 0) { ret = 1; } diff --git a/src/melee/lb/lbsnap.h b/src/melee/lb/lbsnap.h index 270f027c5b..490a390da8 100644 --- a/src/melee/lb/lbsnap.h +++ b/src/melee/lb/lbsnap.h @@ -17,8 +17,8 @@ /* 01D4A4 */ void lbSnap_8001D4A4(int, char*); /* 01D5FC */ int lbSnap_8001D5FC(int, int); /* 01D7B0 */ int lbSnap_8001D7B0(int, int, int); -/* 01DA5C */ void lbSnap_8001DA5C(int); -/* 01DC0C */ int lbSnap_8001DC0C(int); +/* 01DA5C */ void lbSnap_8001DA5C(u8*); +/* 01DC0C */ int lbSnap_8001DC0C(u8*); /* 01DE8C */ int lbSnap_8001DE8C(void*); /* 01DF20 */ int lbSnap_8001DF20(void); /* 01DF6C */ int lbSnap_8001DF6C(int); diff --git a/src/melee/lb/lbspdisplay.c b/src/melee/lb/lbspdisplay.c index 4b44fa75a2..53634c4c59 100644 --- a/src/melee/lb/lbspdisplay.c +++ b/src/melee/lb/lbspdisplay.c @@ -379,11 +379,13 @@ void lb_8001044C(DynamicsDesc* desc, void* colliders_raw, int num_colliders, float pos_y, bool use_floor_fn, Fighter_Part part, int first_active, bool ground_check) { - u8 _padA[152]; - Mtx parent_mtx, temp_mtx, bone_mtx, constrained_mtx, trans_mtx, scale_mtx; + HSD_JObj* parent_jobj; + Mtx parent_mtx, temp_mtx; Vec3 natural_dir, current_dir, link_dir; + Mtx bone_mtx, constrained_mtx, trans_mtx, scale_mtx; + u8 _padA[164]; Vec3 cross_vec, local_axis; - Vec3 gnd_norm; + s32 idx; Quaternion angle_quat, euler_quat, result_quat; Quaternion euler_angles; Vec3 collision_point; @@ -399,11 +401,9 @@ void lb_8001044C(DynamicsDesc* desc, void* colliders_raw, int num_colliders, struct DynamicsData* cur; HSD_JObj* jobj; - HSD_JObj* parent_jobj; struct lb_Collider* collider; s32 on_ground; - s32 idx; - s32 skip_count; + Vec3 gnd_norm; if ((u8) lb_804D63B8 != 0) { return; @@ -422,27 +422,12 @@ void lb_8001044C(DynamicsDesc* desc, void* colliders_raw, int num_colliders, on_ground = 0; idx = 0; - skip_count = 0; - - if ((s32) part > 0) { - s32 rem8 = (s32) part - 8; - if ((s32) part > 8) { - s32 n = (u32) (rem8 + 7) >> 3; - if (rem8 > 0) { - do { - cur = cur->next->next->next->next->next->next->next->next; - idx += 8; - skip_count += 8; - } while (--n); - } - } - if (skip_count < (s32) part) { - s32 rem = (s32) part - skip_count; - do { - cur = cur->next; - idx++; - skip_count++; - } while (--rem); + + { + s32 i; + for (i = 0; i < (s32) part; i++) { + cur = cur->next; + idx++; } } @@ -778,17 +763,18 @@ void lb_8001044C(DynamicsDesc* desc, void* colliders_raw, int num_colliders, if (height_diff < 0.0f) { height_diff = -height_diff; } - horiz_sq = -(height_diff * height_diff - - bone_len * bone_len); + { + f32 tmp_p27864 = + -(height_diff * height_diff - + bone_len * bone_len); + horiz_sq = tmp_p27864; + } if (horiz_sq > 0.0f) { horiz_sq = sqrtf(horiz_sq); } { f32 ground_angle = - atan2f(horiz_sq, height_diff); - if (ground_angle < 0.0f) { - ground_angle = -ground_angle; - } + ABS(atan2f(horiz_sq, height_diff)); PSVECCrossProduct(&gnd_norm, &link_dir, &floor_cross2); lbVector_Normalize(&floor_cross2); @@ -881,15 +867,15 @@ void lb_8001044C(DynamicsDesc* desc, void* colliders_raw, int num_colliders, s32 axis = cur->desc.lb_unk0.unk_54; if (axis == -1) { f32 rot_z = HSD_JObjGetRotationZ(jobj); - rot_z *= 0.9f; + rot_z = rot_z * 0.9f; HSD_JObjSetRotationZ(jobj, rot_z); } else if (axis == 0) { f32 rot_x = HSD_JObjGetRotationX(jobj); - rot_x *= 0.9f; + rot_x = rot_x * 0.9f; HSD_JObjSetRotationX(jobj, rot_x); } else { f32 rot_y = HSD_JObjGetRotationY(jobj); - rot_y *= 0.9f; + rot_y = rot_y * 0.9f; HSD_JObjSetRotationY(jobj, rot_y); } } @@ -1122,6 +1108,7 @@ void lb_80011B74(HSD_DObj* dobj, u32 flags) void lb_80011C18(HSD_JObj* jobj, u32 flags) { HSD_JObj* cur; + PAD_STACK(8); cur = jobj->child; if (cur != NULL) { @@ -1156,8 +1143,10 @@ void lb_80011C18(HSD_JObj* jobj, u32 flags) if (checkJObjFlags(jobj)) { HSD_DObj* dobj = jobj->u.dobj; if (dobj != NULL) { - if (dobj->next != NULL) { - lb_80011B74(dobj->next, flags); + HSD_DObj* next = dobj->next; + dobj = jobj->u.dobj; + if (next != NULL) { + lb_80011B74(next, flags); } dobj->mobj->rendermode |= flags; } @@ -1487,11 +1476,14 @@ void lb_8001285C(HSD_ImageDesc* image_desc, GXTexObj* tex_obj) GX_LO_CLEAR); } +static inline void consume_color(GXColor color) +{ +} + void lb_80012994(HSD_ImageDesc* img, u8 alpha, u8 blur_size, f32 x, f32 y, f32 scale_x, f32 scale_y, f32 color_factor) { GXTexObj tex; - GXColor color; u16 w = img->width; u16 h = img->height; f32 y_p1, x_p1, y_m1, x_m1; @@ -1500,18 +1492,22 @@ void lb_80012994(HSD_ImageDesc* img, u8 alpha, u8 blur_size, f32 x, f32 y, f32 off2 = 2.0f * off1; lb_800122F0(img, &tex, color_factor); - PAD_STACK(88); + PAD_STACK(8); + +#define color_slot(i) (((GXColor*) &tex)[i]) - color.a = alpha; - GXSetTevColor(GX_TEVREG0, color); + color_slot(-4).a = alpha; + GXSetTevColor(GX_TEVREG0, color_slot(-4)); + consume_color(color_slot(-4)); GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_TEXA, GX_CA_ZERO, GX_CA_A0, GX_CA_ZERO); GXSetTevAlphaOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, 1, GX_TEVPREV); lb_8001271C(&tex, x, y, (f32) w, (f32) h, scale_x, scale_y); - color.a = 0x7F; - GXSetTevColor(GX_TEVREG0, color); + color_slot(-6).a = 0x7F; + GXSetTevColor(GX_TEVREG0, color_slot(-6)); + consume_color(color_slot(-6)); GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_TEXA, GX_CA_ZERO, GX_CA_A0, GX_CA_ZERO); GXSetTevAlphaOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, 1, @@ -1519,8 +1515,9 @@ void lb_80012994(HSD_ImageDesc* img, u8 alpha, u8 blur_size, f32 x, f32 y, x_p1 = x + off1; lb_8001271C(&tex, x_p1, y, (f32) w, (f32) h, scale_x, scale_y); - color.a = 0xA9; - GXSetTevColor(GX_TEVREG0, color); + color_slot(-8).a = 0xA9; + GXSetTevColor(GX_TEVREG0, color_slot(-8)); + consume_color(color_slot(-8)); GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_TEXA, GX_CA_ZERO, GX_CA_A0, GX_CA_ZERO); GXSetTevAlphaOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, 1, @@ -1528,8 +1525,9 @@ void lb_80012994(HSD_ImageDesc* img, u8 alpha, u8 blur_size, f32 x, f32 y, x_m1 = x - off1; lb_8001271C(&tex, x_m1, y, (f32) w, (f32) h, scale_x, scale_y); - color.a = 0xBF; - GXSetTevColor(GX_TEVREG0, color); + color_slot(-10).a = 0xBF; + GXSetTevColor(GX_TEVREG0, color_slot(-10)); + consume_color(color_slot(-10)); GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_TEXA, GX_CA_ZERO, GX_CA_A0, GX_CA_ZERO); GXSetTevAlphaOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, 1, @@ -1537,8 +1535,9 @@ void lb_80012994(HSD_ImageDesc* img, u8 alpha, u8 blur_size, f32 x, f32 y, y_p1 = y + off1; lb_8001271C(&tex, x, y_p1, (f32) w, (f32) h, scale_x, scale_y); - color.a = 0xCC; - GXSetTevColor(GX_TEVREG0, color); + color_slot(-12).a = 0xCC; + GXSetTevColor(GX_TEVREG0, color_slot(-12)); + consume_color(color_slot(-12)); GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_TEXA, GX_CA_ZERO, GX_CA_A0, GX_CA_ZERO); GXSetTevAlphaOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, 1, @@ -1546,40 +1545,45 @@ void lb_80012994(HSD_ImageDesc* img, u8 alpha, u8 blur_size, f32 x, f32 y, y_m1 = y - off1; lb_8001271C(&tex, x, y_m1, (f32) w, (f32) h, scale_x, scale_y); - color.a = 0xD4; - GXSetTevColor(GX_TEVREG0, color); + color_slot(-14).a = 0xD4; + GXSetTevColor(GX_TEVREG0, color_slot(-14)); + consume_color(color_slot(-14)); GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_TEXA, GX_CA_ZERO, GX_CA_A0, GX_CA_ZERO); GXSetTevAlphaOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, 1, GX_TEVPREV); lb_8001271C(&tex, x_p1, y_p1, (f32) w, (f32) h, scale_x, scale_y); - color.a = 0xDA; - GXSetTevColor(GX_TEVREG0, color); + color_slot(-16).a = 0xDA; + GXSetTevColor(GX_TEVREG0, color_slot(-16)); + consume_color(color_slot(-16)); GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_TEXA, GX_CA_ZERO, GX_CA_A0, GX_CA_ZERO); GXSetTevAlphaOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, 1, GX_TEVPREV); lb_8001271C(&tex, x_m1, y_m1, (f32) w, (f32) h, scale_x, scale_y); - color.a = 0xDF; - GXSetTevColor(GX_TEVREG0, color); + color_slot(-18).a = 0xDF; + GXSetTevColor(GX_TEVREG0, color_slot(-18)); + consume_color(color_slot(-18)); GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_TEXA, GX_CA_ZERO, GX_CA_A0, GX_CA_ZERO); GXSetTevAlphaOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, 1, GX_TEVPREV); lb_8001271C(&tex, x_p1, y_m1, (f32) w, (f32) h, scale_x, scale_y); - color.a = 0xE2; - GXSetTevColor(GX_TEVREG0, color); + color_slot(-20).a = 0xE2; + GXSetTevColor(GX_TEVREG0, color_slot(-20)); + consume_color(color_slot(-20)); GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_TEXA, GX_CA_ZERO, GX_CA_A0, GX_CA_ZERO); GXSetTevAlphaOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, 1, GX_TEVPREV); lb_8001271C(&tex, x_m1, y_p1, (f32) w, (f32) h, scale_x, scale_y); - color.a = 0xE5; - GXSetTevColor(GX_TEVREG0, color); + color_slot(-22).a = 0xE5; + GXSetTevColor(GX_TEVREG0, color_slot(-22)); + consume_color(color_slot(-22)); GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_TEXA, GX_CA_ZERO, GX_CA_A0, GX_CA_ZERO); GXSetTevAlphaOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, 1, @@ -1587,8 +1591,9 @@ void lb_80012994(HSD_ImageDesc* img, u8 alpha, u8 blur_size, f32 x, f32 y, x_p2 = x + off2; lb_8001271C(&tex, x_p2, y, (f32) w, (f32) h, scale_x, scale_y); - color.a = 0xE7; - GXSetTevColor(GX_TEVREG0, color); + color_slot(-24).a = 0xE7; + GXSetTevColor(GX_TEVREG0, color_slot(-24)); + consume_color(color_slot(-24)); GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_TEXA, GX_CA_ZERO, GX_CA_A0, GX_CA_ZERO); GXSetTevAlphaOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, 1, @@ -1596,40 +1601,45 @@ void lb_80012994(HSD_ImageDesc* img, u8 alpha, u8 blur_size, f32 x, f32 y, x_m2 = x - off2; lb_8001271C(&tex, x_m2, y, (f32) w, (f32) h, scale_x, scale_y); - color.a = 0xE9; - GXSetTevColor(GX_TEVREG0, color); + color_slot(-26).a = 0xE9; + GXSetTevColor(GX_TEVREG0, color_slot(-26)); + consume_color(color_slot(-26)); GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_TEXA, GX_CA_ZERO, GX_CA_A0, GX_CA_ZERO); GXSetTevAlphaOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, 1, GX_TEVPREV); lb_8001271C(&tex, x_p2, y_p1, (f32) w, (f32) h, scale_x, scale_y); - color.a = 0xEB; - GXSetTevColor(GX_TEVREG0, color); + color_slot(-28).a = 0xEB; + GXSetTevColor(GX_TEVREG0, color_slot(-28)); + consume_color(color_slot(-28)); GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_TEXA, GX_CA_ZERO, GX_CA_A0, GX_CA_ZERO); GXSetTevAlphaOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, 1, GX_TEVPREV); lb_8001271C(&tex, x_m2, y_p1, (f32) w, (f32) h, scale_x, scale_y); - color.a = 0xEC; - GXSetTevColor(GX_TEVREG0, color); + color_slot(-30).a = 0xEC; + GXSetTevColor(GX_TEVREG0, color_slot(-30)); + consume_color(color_slot(-30)); GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_TEXA, GX_CA_ZERO, GX_CA_A0, GX_CA_ZERO); GXSetTevAlphaOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, 1, GX_TEVPREV); lb_8001271C(&tex, x_p2, y_m1, (f32) w, (f32) h, scale_x, scale_y); - color.a = 0xEE; - GXSetTevColor(GX_TEVREG0, color); + color_slot(-32).a = 0xEE; + GXSetTevColor(GX_TEVREG0, color_slot(-32)); + consume_color(color_slot(-32)); GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_TEXA, GX_CA_ZERO, GX_CA_A0, GX_CA_ZERO); GXSetTevAlphaOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, 1, GX_TEVPREV); lb_8001271C(&tex, x_m2, y_m1, (f32) w, (f32) h, scale_x, scale_y); - color.a = 0xEF; - GXSetTevColor(GX_TEVREG0, color); + color_slot(-34).a = 0xEF; + GXSetTevColor(GX_TEVREG0, color_slot(-34)); + consume_color(color_slot(-34)); GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_TEXA, GX_CA_ZERO, GX_CA_A0, GX_CA_ZERO); GXSetTevAlphaOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, 1, @@ -1637,8 +1647,9 @@ void lb_80012994(HSD_ImageDesc* img, u8 alpha, u8 blur_size, f32 x, f32 y, y_p2 = y + off2; lb_8001271C(&tex, x, y_p2, (f32) w, (f32) h, scale_x, scale_y); - color.a = 0xF0; - GXSetTevColor(GX_TEVREG0, color); + color_slot(-36).a = 0xF0; + GXSetTevColor(GX_TEVREG0, color_slot(-36)); + consume_color(color_slot(-36)); GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_TEXA, GX_CA_ZERO, GX_CA_A0, GX_CA_ZERO); GXSetTevAlphaOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, 1, @@ -1646,32 +1657,36 @@ void lb_80012994(HSD_ImageDesc* img, u8 alpha, u8 blur_size, f32 x, f32 y, y_m2 = y - off2; lb_8001271C(&tex, x, y_m2, (f32) w, (f32) h, scale_x, scale_y); - color.a = 0xF0; - GXSetTevColor(GX_TEVREG0, color); + color_slot(-38).a = 0xF0; + GXSetTevColor(GX_TEVREG0, color_slot(-38)); + consume_color(color_slot(-38)); GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_TEXA, GX_CA_ZERO, GX_CA_A0, GX_CA_ZERO); GXSetTevAlphaOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, 1, GX_TEVPREV); lb_8001271C(&tex, x_p1, y_p2, (f32) w, (f32) h, scale_x, scale_y); - color.a = 0xF1; - GXSetTevColor(GX_TEVREG0, color); + color_slot(-40).a = 0xF1; + GXSetTevColor(GX_TEVREG0, color_slot(-40)); + consume_color(color_slot(-40)); GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_TEXA, GX_CA_ZERO, GX_CA_A0, GX_CA_ZERO); GXSetTevAlphaOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, 1, GX_TEVPREV); lb_8001271C(&tex, x_p1, y_m2, (f32) w, (f32) h, scale_x, scale_y); - color.a = 0xF2; - GXSetTevColor(GX_TEVREG0, color); + color_slot(-42).a = 0xF2; + GXSetTevColor(GX_TEVREG0, color_slot(-42)); + consume_color(color_slot(-42)); GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_TEXA, GX_CA_ZERO, GX_CA_A0, GX_CA_ZERO); GXSetTevAlphaOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, 1, GX_TEVPREV); lb_8001271C(&tex, x_m1, y_p2, (f32) w, (f32) h, scale_x, scale_y); - color.a = 0xF2; - GXSetTevColor(GX_TEVREG0, color); + color_slot(-44).a = 0xF2; + GXSetTevColor(GX_TEVREG0, color_slot(-44)); + consume_color(color_slot(-44)); GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_TEXA, GX_CA_ZERO, GX_CA_A0, GX_CA_ZERO); GXSetTevAlphaOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, 1, @@ -1679,6 +1694,8 @@ void lb_80012994(HSD_ImageDesc* img, u8 alpha, u8 blur_size, f32 x, f32 y, lb_8001271C(&tex, x_m1, y_m2, (f32) w, (f32) h, scale_x, scale_y); HSD_StateInvalidate(2); + +#undef color_slot } static struct { u8 pad_0[0x28]; @@ -1693,7 +1710,7 @@ void fn_80013614(HSD_GObj* gobj) Mtx view_mtx; Mtx view_mtx2; GXTexObj tex_obj; - PAD_STACK(12); + PAD_STACK(4); if (data->x18 != NULL) { data->x18(gobj); @@ -1770,6 +1787,7 @@ void fn_80013614(HSD_GObj* gobj) { GXColor color; + PAD_STACK(8); color.a = x10; GXSetTevColor(GX_TEVREG0, color); GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_TEXA, GX_CA_ZERO, GX_CA_A0, @@ -2162,6 +2180,14 @@ bool lb_80014638(struct lb_80014638_arg0_t* arg0, return true; } +/// Initializers evidenced by retail .sdata bytes at 804D3760..804D3773 +/// (FFFFFFFF 000000FF FF0000FF FF000040 FFFF00FF). +/* 4D3760 */ GXColor lb_ColorWhite = { 255, 255, 255, 255 }; +/* 4D3764 */ GXColor lb_ColorBlack = { 0, 0, 0, 255 }; +/* 4D3768 */ static GXColor red = { 255, 0, 0, 255 }; +/* 4D376C */ static GXColor translucent_red = { 255, 0, 0, 64 }; +/* 4D3770 */ static GXColor yellow = { 255, 255, 0, 255 }; + bool lb_80014770(Vec3* arg0, int arg1) { if ((u32) arg1 == 2U) { @@ -2202,13 +2228,13 @@ bool lb_80014770(Vec3* arg0, int arg1) if (arg0[1].z > arg0[0].z) { near_pt = &arg0[1]; far_pt = &arg0[0]; - near_clr = &lb_804D3768; - far_clr = &lb_804D376C; + near_clr = &red; + far_clr = &translucent_red; } else { near_pt = &arg0[0]; far_pt = &arg0[1]; - near_clr = &lb_804D376C; - far_clr = &lb_804D3768; + near_clr = &translucent_red; + far_clr = &red; } GXPosition3f32(near_pt->y, near_pt->z, 0.0f); diff --git a/src/melee/lb/lbspdisplay.h b/src/melee/lb/lbspdisplay.h index 0ea8b1265d..d25f9e2966 100644 --- a/src/melee/lb/lbspdisplay.h +++ b/src/melee/lb/lbspdisplay.h @@ -75,7 +75,7 @@ lb_800122C8(HSD_ImageDesc* image_desc, u16 origx, u16 origy, struct lb_80014638_arg1_t*); /* 014770 */ bool lb_80014770(Vec3*, int); /* 0149E0 */ bool lb_800149E0(Mtx, u32); -/* 4D3760 */ extern GXColor lb_804D3760; -/* 4D3764 */ extern GXColor lb_804D3764; +/* 4D3760 */ extern GXColor lb_ColorWhite; +/* 4D3764 */ extern GXColor lb_ColorBlack; #endif diff --git a/src/melee/lb/lbspdisplay.static.h b/src/melee/lb/lbspdisplay.static.h index dc42204e2c..b8ddaa4fdf 100644 --- a/src/melee/lb/lbspdisplay.static.h +++ b/src/melee/lb/lbspdisplay.static.h @@ -39,9 +39,6 @@ struct CameraBlurData { /* 013BE4 */ static bool lb_80013BE4(ColorOverlay* arg); /* 013FF0 */ static bool lb_80013FF0(ColorOverlay* arg); /* 014234 */ static bool lb_80014234(ColorOverlay* arg); -/* 4D3768 */ static GXColor lb_804D3768; -/* 4D376C */ static GXColor lb_804D376C; -/* 4D3770 */ static GXColor yellow; /* 4D63A0 */ static struct lb_804D63A0_t* lb_804D63A0; /* 4D63A4 */ static struct DynamicsData* cur_data; /* 4D63A8 */ static struct lb_804D63A8_t* lb_804D63A8; diff --git a/src/melee/mn/mncharsel.c b/src/melee/mn/mncharsel.c index d633c9a08f..2a9b8f7a5b 100644 --- a/src/melee/mn/mncharsel.c +++ b/src/melee/mn/mncharsel.c @@ -384,8 +384,9 @@ void mnCharSel_8025C020(int arg0) HSD_SisLib_803A70A0(mnCharSel_804D6CE4, 0, "%d 人抜き", gm_Get3MinMultimanTotalHighscore()); } else { + int total_highscore = gm_Get3MinMultimanTotalHighscore(); HSD_SisLib_803A70A0(mnCharSel_804D6CE4, 0, "%d KOs", - gm_Get3MinMultimanTotalHighscore()); + total_highscore); } break; case STADIUM_15_MIN_MELEE: @@ -705,7 +706,6 @@ void mnCharSel_8025DB34(u8 arg0) u8 var_r5; u8 var_r23; int num_doors; - int j; int found; f32 var_f1; @@ -735,34 +735,41 @@ void mnCharSel_8025DB34(u8 arg0) /* Costume duplicate check */ { u8 new_icon = mnCharSel_803F0DFC.doors[arg0].sel_icon; - if (new_icon != mnCharSel_803F0DFC.doors[arg0].sel_icon_prev) { - mnCharSel_803F0DFC.doors[arg0].sel_icon_prev = new_icon; - costume_var = 0; - for (;;) { - mnCharSel_803F0DFC.doors[arg0].costume = costume_var; - if ((u8) mnCharSel_804D6CB0->match_type == 0x17) { - num_doors = 2; - } else { - num_doors = mnCharSel_804D6CF5; - } - found = 0; - for (j = 0; j < num_doors; j++) { - if ((int) arg0 != j && - mnCharSel_803F0DFC.doors[j].p_kind != 3 && - mnCharSel_803F0DFC.doors[j].sel_icon < 0x19U && - mnCharSel_803F0DFC.doors[j].sel_icon == - mnCharSel_803F0DFC.doors[arg0].sel_icon && - mnCharSel_803F0DFC.doors[arg0].costume == - mnCharSel_803F0DFC.doors[j].costume) + u8* prev_icon_ptr = &mnCharSel_803F0DFC.doors[arg0].sel_icon_prev; + if (*prev_icon_ptr != new_icon) { + *prev_icon_ptr = new_icon; + { + CSSData* css = mnCharSel_804D6CB0; + u8 door_count = mnCharSel_804D6CF5; + CSSDoor* door2 = &mnCharSel_803F0DFC.doors[arg0]; + costume_var = 0; + for (;;) { + mnCharSel_803F0DFC.doors[arg0].costume = costume_var; + if ((u8) css->match_type == 0x17) { + num_doors = 2; + } else { + num_doors = door_count; + } + found = 0; { - found = 1; + int j; + for (j = 0; j < num_doors; j++) { + CSSDoor* cur_door = &mnCharSel_803F0DFC.doors[j]; + if ((int) arg0 != j && cur_door->p_kind != 3 && + cur_door->sel_icon < 0x19U && + cur_door->sel_icon == door2->sel_icon && + door2->costume == cur_door->costume) + { + found = 1; + break; + } + } + } + if (found == 0) { break; } + costume_var += 1; } - if (found == 0) { - break; - } - costume_var += 1; } if ((u8) mnCharSel_804D6CF6 != 3 && (u8) mnCharSel_804D6CF6 != 4) { lbAudioAx_80024030(2); @@ -1278,8 +1285,7 @@ static struct CSSCharModel { void fn_8025F0E0(HSD_GObj* gobj) { HSD_JObj* jobj = GET_JOBJ(gobj); - void* sp5C; - void* sp60; + struct CSSCursorData*(*sp58)[4]; HSD_JObj* sp54; HSD_JObj* sp4C; HSD_JObj* sp48; @@ -1289,14 +1295,11 @@ void fn_8025F0E0(HSD_GObj* gobj) HSD_JObj* sp38; HSD_JObj* sp34; HSD_JObj* sp30; - HSD_JObj* sp2C; CSSDoor* doors; GameRules* rules; HSD_DObj* dobj; HSD_MObj* mobj; - void* sp58; int i; - int door_offset; u8 timer; s32 val; int anim; @@ -1343,10 +1346,7 @@ void fn_8025F0E0(HSD_GObj* gobj) if ((u8) mnCharSel_804D6CF5 == 4) { doors = mnCharSel_803F0DFC.doors; - sp5C = HSD_AObjReqAnim; - sp60 = HSD_AObjStopAnim; i = 0; - door_offset = i * 0x24; while (i < (s32) mnCharSel_804D6CF5) { timer = doors->dooranim_timer; if (timer != 0) { @@ -1373,9 +1373,12 @@ void fn_8025F0E0(HSD_GObj* gobj) } else { anim = 0x1E; } - fval = (f32) anim; - lb_80011E24(mnCharSel_804D6CC0, &sp44, - doors->slidername_joint, -1); + { + u8 slidername_joint = doors->slidername_joint; + fval = (f32) anim; + lb_80011E24(mnCharSel_804D6CC0, &sp44, + slidername_joint, -1); + } HSD_ForeachAnim(sp44, JOBJ_TYPE, ALL_TYPE_MASK, HSD_AObjReqAnim, AOBJ_ARG_AF, fval); @@ -1390,9 +1393,12 @@ void fn_8025F0E0(HSD_GObj* gobj) } else { anim = 0x14; } - fval = (f32) anim; - lb_80011E24(mnCharSel_804D6CC0, &sp40, - doors->slidername_joint, -1); + { + u8 slidername_joint = doors->slidername_joint; + fval = (f32) anim; + lb_80011E24(mnCharSel_804D6CC0, &sp40, + slidername_joint, -1); + } HSD_ForeachAnim(sp40, JOBJ_TYPE, ALL_TYPE_MASK, HSD_AObjReqAnim, AOBJ_ARG_AF, fval); @@ -1408,17 +1414,21 @@ void fn_8025F0E0(HSD_GObj* gobj) (u8) i, mnCharSel_804D6CB0->data.data.players[i].xA); } else { - val = mnCharSel_804D6CB0->data.data.players[i] + val = (u8) mnCharSel_804D6CB0->data.data.players[i] .handicap; } { f32 val_f; - if (val == 0) { + if (val != 0) { + } else { val = 1; } - val_f = (f32) val; - lb_80011E24(mnCharSel_804D6CC0, &sp3C, - doors->cpuslider_joint, -1); + { + u8 cpuslider_joint = doors->cpuslider_joint; + val_f = (f32) val; + lb_80011E24(mnCharSel_804D6CC0, &sp3C, + cpuslider_joint, -1); + } HSD_ForeachAnim(sp3C, JOBJ_TYPE, TOBJ_MASK, HSD_AObjReqAnim, AOBJ_ARG_AF, val_f); @@ -1427,10 +1437,14 @@ void fn_8025F0E0(HSD_GObj* gobj) HSD_ForeachAnim(sp3C, JOBJ_TYPE, TOBJ_MASK, HSD_AObjStopAnim, AOBJ_ARG_AOV, 0, 0); - fval = (f32) mnCharSel_804D6CB0->data.data.players[i] - .cpu_level; - lb_80011E24(mnCharSel_804D6CC0, &sp38, - doors->cpuslider2_joint, -1); + { + u8 cpuslider2_joint = doors->cpuslider2_joint; + fval = + (f32) mnCharSel_804D6CB0->data.data.players[i] + .cpu_level; + lb_80011E24(mnCharSel_804D6CC0, &sp38, + cpuslider2_joint, -1); + } HSD_ForeachAnim(sp38, JOBJ_TYPE, TOBJ_MASK, HSD_AObjReqAnim, AOBJ_ARG_AF, fval); HSD_JObjAnimAll(sp38); @@ -1438,44 +1452,53 @@ void fn_8025F0E0(HSD_GObj* gobj) HSD_AObjStopAnim, AOBJ_ARG_AOV, 0, 0); } else { if ((u8) doors->p_kind == 1) { + u8 slidername_joint = doors->slidername_joint; lb_80011E24(mnCharSel_804D6CC0, &sp34, - doors->slidername_joint, -1); + slidername_joint, -1); HSD_ForeachAnim(sp34, JOBJ_TYPE, ALL_TYPE_MASK, - sp5C, AOBJ_ARG_AF, 50.0f); + HSD_AObjReqAnim, AOBJ_ARG_AF, + 50.0f); HSD_JObjAnimAll(sp34); HSD_ForeachAnim(sp34, JOBJ_TYPE, ALL_TYPE_MASK, - sp60, AOBJ_ARG_AOV, 0, 0); + HSD_AObjStopAnim, AOBJ_ARG_AOV, 0, + 0); } else { + u8 slidername_joint = doors->slidername_joint; lb_80011E24(mnCharSel_804D6CC0, &sp30, - doors->slidername_joint, -1); + slidername_joint, -1); HSD_ForeachAnim(sp30, JOBJ_TYPE, ALL_TYPE_MASK, - sp5C, AOBJ_ARG_AF, 40.0f); + HSD_AObjReqAnim, AOBJ_ARG_AF, + 40.0f); HSD_JObjAnimAll(sp30); HSD_ForeachAnim(sp30, JOBJ_TYPE, ALL_TYPE_MASK, - sp60, AOBJ_ARG_AOV, 0, 0); + HSD_AObjStopAnim, AOBJ_ARG_AOV, 0, + 0); } - fval = (f32) mnCharSel_804D6CB0->data.data.players[i] - .cpu_level; - lb_80011E24(mnCharSel_804D6CC0, &sp2C, - doors->cpuslider_joint, -1); - HSD_ForeachAnim(sp2C, JOBJ_TYPE, TOBJ_MASK, sp5C, - AOBJ_ARG_AF, fval); - HSD_JObjAnimAll(sp2C); - HSD_ForeachAnim(sp2C, JOBJ_TYPE, TOBJ_MASK, sp60, - AOBJ_ARG_AOV, 0, 0); + { + u8 cpuslider_joint = doors->cpuslider_joint; + fval = + (f32) mnCharSel_804D6CB0->data.data.players[i] + .cpu_level; + lb_80011E24(mnCharSel_804D6CC0, &sp30, + cpuslider_joint, -1); + } + HSD_ForeachAnim(sp30, JOBJ_TYPE, TOBJ_MASK, + HSD_AObjReqAnim, AOBJ_ARG_AF, fval); + HSD_JObjAnimAll(sp30); + HSD_ForeachAnim(sp30, JOBJ_TYPE, TOBJ_MASK, + HSD_AObjStopAnim, AOBJ_ARG_AOV, 0, 0); } } } doors++; - door_offset += 0x24; i += 1; } } else { if (mnCharSel_803F0DFC.scroll_flag != 0) { if (mnCharSel_803F0DFC.xcd != mnCharSel_803F0DFC.xce) { if (mnCharSel_803F0DFC.xcd < mnCharSel_803F0DFC.xce) { - mnCharSel_803F0DFC.xcf = mnCharSel_803F0DFC.xcf + 31.0f; + mnCharSel_803F0DFC.xcf += 31.0f; if (mnCharSel_803F0DFC.xcf >= -(248.0f * (f32) mnCharSel_803F0DFC.xcd - 124.0f)) { @@ -1577,7 +1600,7 @@ void fn_8025F0E0(HSD_GObj* gobj) } } HSD_JObjAnimAll(jobj); - PAD_STACK(40); + PAD_STACK(32); } void fn_8025FAC0(HSD_GObj* gobj) @@ -1605,7 +1628,7 @@ static inline bool isDuplicateCostume(int door) { int num_doors; int j; - CSSDoor* temp_r30 = &mnCharSel_803F0DFC.doors[door]; + CSSDoor* base_door = &mnCharSel_803F0DFC.doors[door]; if (mnCharSel_804D6CB0->match_type == TRAINING_MODE) { num_doors = 2; @@ -1614,10 +1637,36 @@ static inline bool isDuplicateCostume(int door) } for (j = 0; j < num_doors; j++) { - CSSDoor* var_r5 = &mnCharSel_803F0DFC.doors[j]; - if (door != j && var_r5->p_kind != 3 && var_r5->sel_icon < 0x19 && - var_r5->sel_icon == temp_r30->sel_icon && - temp_r30->costume == var_r5->costume) + CSSDoor* other_door = &mnCharSel_803F0DFC.doors[j]; + if (door != j && other_door->p_kind != 3 && + other_door->sel_icon < 0x19 && + other_door->sel_icon == base_door->sel_icon && + base_door->costume == other_door->costume) + { + return true; + } + } + return false; +} + +static inline bool isDuplicateCostume2(int door, CSSData* css, u8 door_count) +{ + int num_doors; + int j; + CSSDoor* base_door = &mnCharSel_803F0DFC.doors[door]; + + if (css->match_type == TRAINING_MODE) { + num_doors = 2; + } else { + num_doors = door_count; + } + + for (j = 0; j < num_doors; j++) { + CSSDoor* other_door = &mnCharSel_803F0DFC.doors[j]; + if (door != j && other_door->p_kind != 3 && + other_door->sel_icon < 0x19 && + other_door->sel_icon == base_door->sel_icon && + base_door->costume == other_door->costume) { return true; } @@ -1629,13 +1678,17 @@ void mnCharSel_8025FB50(u8 door, s32 arg1) { HSD_JObj* sp18; s32 icon_idx; + s32 icon_offset; int player; - CSSIcon* icons = (CSSIcon*) (&mnCharSel_803F0A48 + 1); - PAD_STACK(8); + CSSAllData* all_data = (CSSAllData*) &mnCharSel_803F0A48; + u8* char_kinds; + CSSIcon* icon; do { - icon_idx = HSD_Randi(0x19); - } while (icons[icon_idx].state == 0); + s32 temp = HSD_Randi(0x19); + icon_idx = temp; + icon_offset = icon_idx * sizeof(CSSIcon); + } while ((icon = &all_data->icons[icon_idx])->state == 0); if (mnCharSel_804D6CF5 == 1) { if (door != 0) { @@ -1647,17 +1700,20 @@ void mnCharSel_8025FB50(u8 door, s32 arg1) player = door; } + char_kinds = &all_data->icons[0].char_kind; mnCharSel_804D6CB0->data.data.players[player].c_kind = - icons[icon_idx].char_kind; + char_kinds[icon_offset]; mnCharSel_803F0DFC.doors[door].sel_icon = (u8) icon_idx; if (mnCharSel_803F0DFC.doors[door].sel_icon != mnCharSel_803F0DFC.doors[door].sel_icon_prev) { + CSSData* css = mnCharSel_804D6CB0; + u8 door_count = mnCharSel_804D6CF5; u8 costume = 0; while (1) { mnCharSel_803F0DFC.doors[door].costume = costume; - if (!isDuplicateCostume(door)) { + if (!isDuplicateCostume2(door, css, door_count)) { break; } costume++; @@ -1665,8 +1721,8 @@ void mnCharSel_8025FB50(u8 door, s32 arg1) } mnCharSel_804A0BD0[door]->x5 = 0; - mnCharSel_804A0BD0[door]->x8 = 3.4f + icons[icon_idx].bound_l; - mnCharSel_804A0BD0[door]->xC = -3.0f + icons[icon_idx].bound_u; + mnCharSel_804A0BD0[door]->x8 = 3.4f + all_data->icons[icon_idx].bound_l; + mnCharSel_804A0BD0[door]->xC = -3.0f + all_data->icons[icon_idx].bound_u; if (arg1 != 0) { mnCharSel_804A0BD0[door]->x10 = mnCharSel_804A0BD0[door]->x8; mnCharSel_804A0BD0[door]->x14 = mnCharSel_804A0BD0[door]->xC; @@ -1675,21 +1731,21 @@ void mnCharSel_8025FB50(u8 door, s32 arg1) mnCharSel_804A0BC0[mnCharSel_804D6CF5 - 1]->gobj); if (mnCharSel_804D6CF5 == 1) { - lb_80011E24(mnCharSel_804D6CC0, &sp18, icons[icon_idx].joint_id_1p, - -1); + lb_80011E24(mnCharSel_804D6CC0, &sp18, + all_data->icons[icon_idx].joint_id_1p, -1); } else { - lb_80011E24(mnCharSel_804D6CC0, &sp18, icons[icon_idx].joint_id_vs, - -1); + lb_80011E24(mnCharSel_804D6CC0, &sp18, + all_data->icons[icon_idx].joint_id_vs, -1); } HSD_ForeachAnim(sp18, JOBJ_TYPE, TOBJ_MASK, HSD_AObjReqAnim, AOBJ_ARG_AF, 10.0); - icons[icon_idx].anim_timer = 0xC; + all_data->icons[icon_idx].anim_timer = 0xC; { u8 sel = mnCharSel_803F0DFC.doors[door].sel_icon; - lbAudioAx_80023870(icons[sel].sfx, 0x7F, 0x40, sel + 0x8A); - gm_80168C5C((u32) icons[sel].char_kind); + lbAudioAx_80023870(all_data->icons[sel].sfx, 0x7F, 0x40, sel + 0x8A); + gm_80168C5C((u32) char_kinds[sel * sizeof(CSSIcon)]); } } @@ -1699,9 +1755,9 @@ s32 mnCharSel_8025FDEC(u8 door) HSD_JObj* sp10; int player; s8 c_kind; - int icon_idx; CSSData* css; struct CSSCharModel** model_ptr; + int icon_idx; CSSAllData* all_data = (CSSAllData*) &mnCharSel_803F0A48; if (mnCharSel_804D6CF5 == 1) { @@ -1760,15 +1816,19 @@ s32 mnCharSel_8025FDEC(u8 door) all_data->icons[icon_idx].anim_timer = 0xC; - if (mnCharSel_8025DAA0(door)) { - s8 costume = 0; - do { - mnCharSel_803F0DFC.doors[door].costume = costume; - if (!mnCharSel_8025DAA0(door)) { - break; - } - costume++; - } while (1); + { + int door_idx = door; + if (mnCharSel_8025DAA0(door_idx)) { + s8 costume = 0; + CSSDoor* selected_door = &mnCharSel_803F0DFC.doors[door_idx]; + do { + selected_door->costume = costume; + if (!mnCharSel_8025DAA0(door_idx)) { + break; + } + costume++; + } while (1); + } } if (mnCharSel_804D6CF6 != 3 && mnCharSel_804D6CF6 != 4) { @@ -1830,10 +1890,10 @@ void mnCharSel_CursorThink(HSD_GObj* gobj) HSD_JObj* sp3C; HSD_JObj* jobj = GET_JOBJ(gobj); struct CSSCursorData* cursor = gobj->user_data; - int n_doors; f32 stick_x; f32 stick_y; u32 trigger; + int n_doors; u32 buttons; f32 dx; f32 dy; @@ -1850,9 +1910,11 @@ void mnCharSel_CursorThink(HSD_GObj* gobj) cursor->x8 = 0; if ((u8) mnCharSel_804D6CF5 == 1) { - u8 port = mnCharSel_804D6CF0; - stick_y = (f32) (s8) (u8) HSD_PadCopyStatus[port].stickY; - stick_x = (f32) (s8) (u8) HSD_PadCopyStatus[port].stickX; + int port = mnCharSel_804D6CF0; + stick_y = + (f32) (s8) (u8) HSD_PadCopyStatus[(u8) port].stickY; + stick_x = + (f32) (s8) (u8) HSD_PadCopyStatus[(u8) port].stickX; mag_sq = (stick_x * stick_x) + (stick_y * stick_y); trigger = HSD_PadCopyStatus[port].trigger; buttons = HSD_PadCopyStatus[port].button; @@ -1880,9 +1942,11 @@ void mnCharSel_CursorThink(HSD_GObj* gobj) cursor->xA = 0; } } else { - u8 port = cursor->x4; - stick_y = (f32) (s8) (u8) HSD_PadCopyStatus[port].stickY; - stick_x = (f32) (s8) (u8) HSD_PadCopyStatus[port].stickX; + int port = cursor->x4; + stick_y = + (f32) (s8) (u8) HSD_PadCopyStatus[(u8) port].stickY; + stick_x = + (f32) (s8) (u8) HSD_PadCopyStatus[(u8) port].stickX; mag_sq = (stick_x * stick_x) + (stick_y * stick_y); trigger = HSD_PadCopyStatus[port].trigger; buttons = HSD_PadCopyStatus[port].button; @@ -2565,7 +2629,8 @@ void mnCharSel_CursorThink(HSD_GObj* gobj) { struct CSSCursorData* other = mnCharSel_804A0BC0[loop_i]; - if ((u8) other->x5 == 1 && + int other_state = (u8) other->x5; + if (other_state == 1 && mnCharSel_8025FDEC((u8) loop_i) == 0) { mnCharSel_8025DB34((u8) loop_i); @@ -2876,13 +2941,11 @@ void mnCharSel_CursorThink(HSD_GObj* gobj) sp98, NULL, (Point3d*) &sp88); { - f32 hdx_val = + f32 hdx = cursor ->x10 - (1.7f + sp88.y); - f32 hdx = - hdx_val; f32 hdy = cursor ->xC - @@ -3324,7 +3387,8 @@ void fn_80262648(HSD_GObj* gobj) } while (dx == 0.0f); do { - dy = (0.1f * (HSD_Randf() - 0.5f)) + + f32 rand = HSD_Randf(); + dy = (0.1f * (rand - 0.5f)) + (model->xC - (*bdp)->xC); } while (dy == 0.0f); @@ -3622,17 +3686,17 @@ static GXColor mnCharSel_804DC564 = { 100, 100, 100, 255 }; void fn_802633B0(HSD_GObj* gobj) { - HSD_JObj* sp84; - HSD_JObj* sp80; - GXColor sp78; - GXColor sp74; - HSD_JObj* sp70; - Vec3 sp64; - GXColor sp60; - GXColor sp5C; - GXColor sp58; - GXColor sp54; - HSD_JObj* sp30; + HSD_JObj* arrow_jobj; + HSD_JObj* list_jobj; + GXColor white; + GXColor gray; + HSD_JObj* list_origin_jobj; + Point3d list_origin; + GXColor gray_copy; + GXColor row_color; + GXColor used_row_color; + GXColor white_copy; + HSD_JObj* handicap_slider_jobj; CSSTagData* tag; int port; s32 num_entries; @@ -3641,12 +3705,13 @@ void fn_802633B0(HSD_GObj* gobj) s32 row; u8 match_type; s32 val; - f32 temp_f0; + f32 cursor_row; f32 vel; f32 scroll_pos; f32 new_pos; s32 page; s32 new_page; + s32 row_idx; tag = gobj->user_data; port = tag->port; @@ -3659,8 +3724,8 @@ void fn_802633B0(HSD_GObj* gobj) } } - sp78 = mnCharSel_804DC560; - sp74 = mnCharSel_804DC564; + white = mnCharSel_804DC560; + gray = mnCharSel_804DC564; num_entries = tag->next_tag; if (num_entries > 0x78U) { @@ -3670,10 +3735,11 @@ void fn_802633B0(HSD_GObj* gobj) } if ((u8) mnCharSel_804D6CF5 == 1) { - lb_80011E24(mnCharSel_804D6CC0, &sp84, mnCharSel_803F0DFC.xc4, -1); + lb_80011E24(mnCharSel_804D6CC0, &list_jobj, mnCharSel_803F0DFC.xc4, + -1); trigger = HSD_PadCopyStatus[(u8) mnCharSel_804D6CF0].trigger; } else { - lb_80011E24(mnCharSel_804D6CC0, &sp84, + lb_80011E24(mnCharSel_804D6CC0, &list_jobj, mnCharSel_803F0DFC.tags[tag->port].x4, -1); trigger = HSD_PadCopyStatus[tag->port].trigger; } @@ -3698,9 +3764,9 @@ void fn_802633B0(HSD_GObj* gobj) HSD_SisLib_803A70A0((HSD_Text*) tag->name_ls, 0, (char*) ((u8*) &mnCharSel_803F0A48 + 0x5B8)); } - sp60 = sp74; - HSD_SisLib_803A74F0((HSD_Text*) tag->text, 0, &sp60); - HSD_ForeachAnim(sp84, JOBJ_TYPE, ALL_TYPE_MASK, HSD_AObjReqAnim, + gray_copy = gray; + HSD_SisLib_803A74F0((HSD_Text*) tag->text, 0, &gray_copy); + HSD_ForeachAnim(list_jobj, JOBJ_TYPE, ALL_TYPE_MASK, HSD_AObjReqAnim, AOBJ_ARG_AF, 0.0f); tag->state = 2; tag->timer = 0; @@ -3712,8 +3778,8 @@ void fn_802633B0(HSD_GObj* gobj) t = tag->timer + 1; tag->timer = t; if (t > 0xAU) { - HSD_ForeachAnim(sp84, JOBJ_TYPE, ALL_TYPE_MASK, HSD_AObjStopAnim, - AOBJ_ARG_AOV, 0, 0); + HSD_ForeachAnim(list_jobj, JOBJ_TYPE, ALL_TYPE_MASK, + HSD_AObjStopAnim, AOBJ_ARG_AOV, 0, 0); ((HSD_Text*) tag->name_ls)->hidden = 0; tag->state = 3; } @@ -3741,9 +3807,9 @@ void fn_802633B0(HSD_GObj* gobj) tag->x8 = 0.0f; } if ((u8) tag->next_tag > 7U) { - temp_f0 = -32.0f * (f32) num_entries; - if (tag->x8 < temp_f0) { - tag->x8 = temp_f0; + cursor_row = -32.0f * (f32) num_entries; + if (tag->x8 < cursor_row) { + tag->x8 = cursor_row; } } else { tag->x8 = 0.0f; @@ -3760,34 +3826,36 @@ void fn_802633B0(HSD_GObj* gobj) } if ((u8) mnCharSel_804D6CF5 == 1) { - lb_80011E24(mnCharSel_804D6CC0, &sp80, mnCharSel_803F0DFC.xc7, -1); + lb_80011E24(mnCharSel_804D6CC0, &arrow_jobj, + mnCharSel_803F0DFC.xc7, -1); } else { - lb_80011E24(mnCharSel_804D6CC0, &sp80, + lb_80011E24(mnCharSel_804D6CC0, &arrow_jobj, mnCharSel_803F0DFC.tags[tag->port].x7, -1); } if (tag->x8 == 0.0f) { - HSD_JObjSetFlags(sp80, JOBJ_HIDDEN); + HSD_JObjSetFlags(arrow_jobj, JOBJ_HIDDEN); } else { - HSD_JObjClearFlags(sp80, JOBJ_HIDDEN); + HSD_JObjClearFlags(arrow_jobj, JOBJ_HIDDEN); } if ((u8) mnCharSel_804D6CF5 == 1) { - lb_80011E24(mnCharSel_804D6CC0, &sp80, mnCharSel_803F0DFC.xc8, -1); + lb_80011E24(mnCharSel_804D6CC0, &arrow_jobj, + mnCharSel_803F0DFC.xc8, -1); } else { - lb_80011E24(mnCharSel_804D6CC0, &sp80, + lb_80011E24(mnCharSel_804D6CC0, &arrow_jobj, mnCharSel_803F0DFC.tags[tag->port].kostar_text_joint, -1); } if ((u8) tag->next_tag > 7U) { if (tag->x8 == (-32.0f * (f32) num_entries)) { - HSD_JObjSetFlags(sp80, JOBJ_HIDDEN); + HSD_JObjSetFlags(arrow_jobj, JOBJ_HIDDEN); } else { - HSD_JObjClearFlags(sp80, JOBJ_HIDDEN); + HSD_JObjClearFlags(arrow_jobj, JOBJ_HIDDEN); } } else { - HSD_JObjSetFlags(sp80, JOBJ_HIDDEN); + HSD_JObjSetFlags(arrow_jobj, JOBJ_HIDDEN); } HSD_SisLib_803A746C((HSD_Text*) tag->name_ls, 0, 0.0f, tag->x8); @@ -3797,9 +3865,8 @@ void fn_802633B0(HSD_GObj* gobj) s32 j; s32 trunc; s32 page_off; - s32 row_idx; - GXColor* name_color = &sp5C; - GXColor* used_name_color = &sp58; + GXColor* name_color = &row_color; + GXColor* used_name_color = &used_row_color; j = 0; page_off = ((s32) tag->x8 / 32) + 1; do { @@ -3807,10 +3874,9 @@ void fn_802633B0(HSD_GObj* gobj) if (row_idx < 0) { HSD_SisLib_803A70A0((HSD_Text*) tag->name_ls, j + 2, NULL); } else { - char* name; - name = GetNameText((s32) (u8) row_idx); - HSD_SisLib_803A70A0((HSD_Text*) tag->name_ls, j + 2, name); - sp5C = sp78; + HSD_SisLib_803A70A0((HSD_Text*) tag->name_ls, j + 2, + GetNameText((s32) (u8) row_idx)); + row_color = white; HSD_SisLib_803A74F0((HSD_Text*) tag->name_ls, j + 2, name_color); { @@ -3822,7 +3888,7 @@ void fn_802633B0(HSD_GObj* gobj) (s32) ddata->data.data.players[p2].xA == row_idx) { - sp58 = sp74; + used_row_color = gray; HSD_SisLib_803A74F0((HSD_Text*) tag->name_ls, j + 2, used_name_color); break; @@ -3841,20 +3907,19 @@ void fn_802633B0(HSD_GObj* gobj) if (trigger & 0x100) { if ((u8) mnCharSel_804D6CF5 == 1) { - lb_80011E24(mnCharSel_804D6CC0, &sp70, + lb_80011E24(mnCharSel_804D6CC0, &list_origin_jobj, mnCharSel_803F0DFC.name_list_joint, -1); } else { - lb_80011E24(mnCharSel_804D6CC0, &sp70, + lb_80011E24(mnCharSel_804D6CC0, &list_origin_jobj, mnCharSel_803F0DFC.tags[tag->port].list_joint, -1); } - lb_8000B1CC(sp70, NULL, &sp64); - row = (s32) (0.5f * (0.8f + - (sp64.y - ((struct CSSCharModel*) - mnCharSel_804A0BC0[tag->port]) - ->x10)) - - (tag->x8 * 0.03125f)); - - if (row == 0) { + lb_8000B1CC(list_origin_jobj, NULL, &list_origin); + cursor_row = 0.5f * (0.8f + (list_origin.y - + mnCharSel_804A0BC0[tag->port]->x10)) - + (tag->x8 * 0.03125f); + row = (s32) cursor_row; + + if ((s32) cursor_row == 0) { if (lbLang_IsSavedLanguageUS() != 0 && (u8) mnCharSel_803F0DFC.doors[tag->port].sel_icon == 0x16) { @@ -3912,17 +3977,17 @@ void fn_802633B0(HSD_GObj* gobj) } mnCharSel_804D6CF6 = 4; { - struct CSSCharModel** model_ptr; + struct CSSCursorData** cursor_ptr; s32 k; - model_ptr = (struct CSSCharModel**) mnCharSel_804A0BC0; + cursor_ptr = mnCharSel_804A0BC0; for (k = 0; k < (s32) mnCharSel_804D6CF5; k++) { - if (((u8) (*model_ptr)->x5 == 1) && + if (((u8) (*cursor_ptr)->x5 == 1) && (mnCharSel_8025FDEC((u8) k) == 0)) { mnCharSel_8025DB34((u8) k); - (*model_ptr)->x5 = 2; + (*cursor_ptr)->x5 = 2; } - model_ptr += 1; + cursor_ptr += 1; } } return; @@ -3943,10 +4008,8 @@ void fn_802633B0(HSD_GObj* gobj) } } { - char* name_str; - name_str = GetNameText(row - 1); HSD_SisLib_803A70A0((HSD_Text*) tag->text, 0, - name_str); + GetNameText(row - 1)); ((HSD_Text*) tag->text)->default_kerning = 0; ((HSD_Text*) tag->text)->hidden = 0; { @@ -3992,7 +4055,7 @@ void fn_802633B0(HSD_GObj* gobj) break; case 4: - HSD_ForeachAnim(sp84, JOBJ_TYPE, ALL_TYPE_MASK, HSD_AObjReqAnim, + HSD_ForeachAnim(list_jobj, JOBJ_TYPE, ALL_TYPE_MASK, HSD_AObjReqAnim, AOBJ_ARG_AF, 20.0f); ((HSD_Text*) tag->name_ls)->hidden = 1; if ((u8) gmMainLib_8015CC34()->handicap != 0 && @@ -4000,7 +4063,7 @@ void fn_802633B0(HSD_GObj* gobj) { { u8 port2; - u8 hval; + s32 hval; f32 hval_f; port2 = tag->port; if ((u8) gmMainLib_8015CC34()->handicap == 1) { @@ -4016,18 +4079,18 @@ void fn_802633B0(HSD_GObj* gobj) hval = 1; } hval_f = (f32) hval; - lb_80011E24(mnCharSel_804D6CC0, &sp30, + lb_80011E24(mnCharSel_804D6CC0, &handicap_slider_jobj, mnCharSel_803F0DFC.doors[port].cpuslider_joint, -1); - HSD_ForeachAnim(sp30, JOBJ_TYPE, TOBJ_MASK, HSD_AObjReqAnim, - AOBJ_ARG_AF, hval_f); - HSD_JObjAnimAll(sp30); - HSD_ForeachAnim(sp30, JOBJ_TYPE, TOBJ_MASK, HSD_AObjStopAnim, - AOBJ_ARG_AOV, 0, 0); - sp84 = sp30; + HSD_ForeachAnim(handicap_slider_jobj, JOBJ_TYPE, TOBJ_MASK, + HSD_AObjReqAnim, AOBJ_ARG_AF, hval_f); + HSD_JObjAnimAll(handicap_slider_jobj); + HSD_ForeachAnim(handicap_slider_jobj, JOBJ_TYPE, TOBJ_MASK, + HSD_AObjStopAnim, AOBJ_ARG_AOV, 0, 0); + list_jobj = handicap_slider_jobj; { u8 port3; - u8 hval2; + s32 hval2; f32 hval_f; port3 = tag->port; if ((u8) gmMainLib_8015CC34()->handicap == 1) { @@ -4044,7 +4107,7 @@ void fn_802633B0(HSD_GObj* gobj) hval2 = 1; } hval_f = 1.25f * (f32) (hval2 - 1); - HSD_JObjSetTranslateX(sp84, hval_f); + HSD_JObjSetTranslateX(list_jobj, hval_f); } } } @@ -4058,14 +4121,14 @@ void fn_802633B0(HSD_GObj* gobj) tag->timer = t2; if (t2 > 0xAU) { mnCharSel_8025D1C4((s32) tag->port, 2); - sp54 = sp78; - HSD_SisLib_803A74F0((HSD_Text*) tag->text, 0, &sp54); + white_copy = white; + HSD_SisLib_803A74F0((HSD_Text*) tag->text, 0, &white_copy); tag->state = 0; } break; } } - PAD_STACK(72); + PAD_STACK(64); } void mnCharSel_80264070(void) @@ -4492,31 +4555,30 @@ s32 mnCharSel_802640A0(void) } } lb_8000B1CC(sp108, NULL, &spEC); - text = HSD_SisLib_803A6754(0, ctx); - td->name_ls = (TextGlyphTexture*) text; - text->default_fitting = 1; - text->box_size_x = 154.0f; - text->box_size_y = 256.0f; - text->pos_x = spEC.x - 0.6f; - text->pos_y = (0.8f - spEC.y) - 1.0f; - text->pos_z = spEC.z; - text->font_size.x = 0.065f; - text->font_size.y = 0.065f; - text->x4E = 1; - text->hidden = 1; - HSD_SisLib_803A6B98(text, 0.0f, 0.0f, + td->name_ls = (TextGlyphTexture*) HSD_SisLib_803A6754(0, ctx); + ((HSD_Text*) td->name_ls)->default_fitting = 1; + ((HSD_Text*) td->name_ls)->box_size_x = 154.0f; + ((HSD_Text*) td->name_ls)->box_size_y = 256.0f; + ((HSD_Text*) td->name_ls)->pos_x = spEC.x - 0.6f; + ((HSD_Text*) td->name_ls)->pos_y = (0.8f - spEC.y) - 1.0f; + ((HSD_Text*) td->name_ls)->pos_z = spEC.z; + ((HSD_Text*) td->name_ls)->font_size.x = 0.065f; + ((HSD_Text*) td->name_ls)->font_size.y = 0.065f; + ((HSD_Text*) td->name_ls)->x4E = 1; + ((HSD_Text*) td->name_ls)->hidden = 1; + HSD_SisLib_803A6B98((HSD_Text*) td->name_ls, 0.0f, 0.0f, "\x81\x45\x81\x45\x81\x45\x81\x45\x81\x45\x81\x45" "\x81\x45\x81\x45\x81\x45\x81\x45\x81\x45"); color = spE8; - HSD_SisLib_803A74F0(text, 0, &color); - HSD_SisLib_803A6B98(text, 0.0f, 0.0f, + HSD_SisLib_803A74F0((HSD_Text*) td->name_ls, 0, &color); + HSD_SisLib_803A6B98((HSD_Text*) td->name_ls, 0.0f, 0.0f, "\x82\x6d\x82\x60\x82\x6c\x82\x64\x20\x82\x64\x82" "\x6d\x82\x73\x82\x71\x82\x78"); color = spE8; - HSD_SisLib_803A74F0(text, 1, &color); + HSD_SisLib_803A74F0((HSD_Text*) td->name_ls, 1, &color); found = 0; do { - HSD_SisLib_803A6B98(text, 10.0f, 0.0f, + HSD_SisLib_803A6B98((HSD_Text*) td->name_ls, 10.0f, 0.0f, "\x81\x45\x81\x45\x81\x45\x81\x45"); found++; } while (found < 9); diff --git a/src/melee/mn/mncount.c b/src/melee/mn/mncount.c index 27a9f831b6..c6a835a184 100644 --- a/src/melee/mn/mncount.c +++ b/src/melee/mn/mncount.c @@ -531,46 +531,53 @@ unsigned int mnCount_GetRowValue_Number(int row) void mnCount_CreateRow(HSD_GObj* gobj, int visible_row, mnCount_row data_row) { MnCountData* userdata = GET_MNCOUNT(gobj); + HSD_Text** label_text; HSD_Text* text; - unsigned int row_value; int row_value_2; + HSD_Text** value_text; + HSD_Text** tmp_p14730; + HSD_Text** tmp_p14708; + HSD_Text** tmp_p15235; float y; - char buf2[8]; static GXColor text_color = { 0xAA, 0xAA, 0xAA, 0xFF }; - if (userdata->labels[visible_row] != NULL) { + tmp_p14730 = userdata->labels; + tmp_p14708 = tmp_p14730 + visible_row; + label_text = tmp_p14708; + if (*label_text != NULL) { HSD_SisLib_803A5CC4(userdata->labels[visible_row]); - userdata->labels[visible_row] = NULL; + *label_text = NULL; } - y = (1.4f * visible_row) + -6.4f; - text = HSD_SisLib_803A5ACC(0, 1, -13.0f, y, 17.0f, 500.0f, 38.38772f); - userdata->labels[visible_row] = text; + text = HSD_SisLib_803A5ACC(0, 1, -13.0f, + y = (1.4f * visible_row) + -6.4f, 17.0f, + 500.0f, 38.38772f); + *label_text = text; text->font_size.x = 0.03f; text->font_size.y = 0.03f; text->text_color = text_color; HSD_SisLib_803A6368(text, mnCount_sis_idx[data_row]); - if (userdata->values[visible_row] != NULL) { - { - HSD_Text* volatile value_text = userdata->values[visible_row]; - HSD_SisLib_803A5CC4(value_text); - } - userdata->values[visible_row] = NULL; + tmp_p15235 = userdata->values; + value_text = tmp_p15235 + visible_row; + if (*value_text != NULL) { + HSD_SisLib_803A5CC4(userdata->values[visible_row]); + *value_text = NULL; } text = HSD_SisLib_803A6754(0, 1); - userdata->values[visible_row] = text; + *value_text = text; text->pos_x = 13.0f; text->pos_y = y; text->pos_z = 17.0f; text->text_color = mn_804D4B64; text->default_alignment = 2; if (inline_is_row_time(data_row)) { - char buf1[8]; + unsigned int row_value; + char buf[4]; text->font_size.x = 0.03f; text->font_size.y = 0.03f; row_value = mnCount_GetRowValue_Number(data_row); - mn_8022EA78(buf1, 2, row_value / 60 / 60); - mn_8022EA78(buf2, 2, row_value / 60 % 60); + mn_8022EA78(buf, 2, row_value / 60 / 60); + mn_8022EA78(&buf[-4], 2, row_value / 60 % 60); HSD_SisLib_803A6B98(text, 0.0f, 0.0f, "%u:%s", row_value / 60 / 60, - buf2); + *(char (*)[4]) &buf - 4); } else if (inline_is_row_char(data_row)) { text->font_size.x = 0.03f; text->font_size.y = 0.03f; @@ -718,10 +725,12 @@ void fn_802514D8(HSD_GObj* gobj) void fn_80251640(HSD_GObj* gobj) { HSD_GObjProc* proc; + HSD_Text* value_null; + MnCountData* userdata = GET_MNCOUNT(gobj); + StaticModelDesc* md; + MnCountData* userdata3; int i; HSD_JObj* jobj; - StaticModelDesc* md; - MnCountData* userdata = GET_MNCOUNT(gobj); PAD_STACK(24); if (mn_804A04F0.cur_menu != MENU_KIND_RECORDS_MISC) { @@ -729,22 +738,26 @@ void fn_80251640(HSD_GObj* gobj) proc = HSD_GObj_SetupProc(gobj, fn_802514B8, 0); proc->flags_3 = HSD_GObj_804D783C; { + HSD_Text* label_null; // inline_free_text MnCountData* userdata2 = GET_MNCOUNT(gobj); - MnCountData* userdata3 = userdata2; - int i; + userdata3 = userdata2; - for (i = 0; i < MNCOUNT_VISIBLE_ROWS; i++) { + i = 0; + label_null = (HSD_Text*) i; + value_null = (HSD_Text*) i; + do { if (userdata2->labels[i] != NULL) { HSD_SisLib_803A5CC4(userdata3->labels[i]); - userdata2->labels[i] = NULL; + userdata2->labels[i] = label_null; } if (userdata2->values[i] != NULL) { HSD_SisLib_803A5CC4(userdata3->values[i]); - userdata2->values[i] = NULL; + userdata2->values[i] = value_null; } - } + i += 1; + } while (i < MNCOUNT_VISIBLE_ROWS); HSD_SisLib_803A5CC4(userdata->title); } @@ -789,10 +802,17 @@ static void mnCount_InitUserData_noinline(MnCountData* userdata) mnCount_InitUserData(userdata); } +static inline void mnCount_InitGObjUserData(HSD_GObj* gobj) +{ + MnCountData* userdata = HSD_MemAlloc(sizeof(MnCountData)); + HSD_ASSERTREPORT(0x512, userdata, "Can't get user_data.\n"); + mnCount_InitUserData_noinline(userdata); + GObj_InitUserData(gobj, 0, HSD_Free, userdata); +} + void mnCount_Create(void) { HSD_GObj* gobj; - MnCountData* userdata; HSD_GObjProc* proc; mn_804D6BC8.cooldown = 5; @@ -809,10 +829,7 @@ void mnCount_Create(void) gobj = GObj_Create(6, 7, 0x80); menu_gobj = gobj; - userdata = HSD_MemAlloc(sizeof(MnCountData)); - HSD_ASSERTREPORT(0x512, userdata, "Can't get user_data.\n"); - mnCount_InitUserData_noinline(userdata); - GObj_InitUserData(gobj, 0, HSD_Free, userdata); + mnCount_InitGObjUserData(gobj); proc = HSD_GObj_SetupProc(gobj, fn_80251640, 0); proc->flags_3 = HSD_GObj_804D783C; diff --git a/src/melee/mn/mndatadel.c b/src/melee/mn/mndatadel.c index ee082e4d98..48ea1c24f8 100644 --- a/src/melee/mn/mndatadel.c +++ b/src/melee/mn/mndatadel.c @@ -163,31 +163,25 @@ static inline struct WarnCmnData* mnDataDel_GetWarnData(void) } /// @brief animates the warning modal -void fn_8024ECCC(HSD_GObj* arg0) +static inline void mnDataDel_AnimateWarning(HSD_JObj* root, HSD_GObj* gobj, + struct WarnCmnData* data, + HSD_JObj** panel, + HSD_JObj** exclaim) { - HSD_JObj* panel; - struct WarnCmnData* data; - HSD_JObj* root; - HSD_JObj* exclaim; - HSD_JObj* cursor_no; - HSD_JObj* cursor_yes; - u8 _pad[10]; f32 curr_frame; - HSD_Text* text; s32 sis_id; - PAD_STACK(16); + HSD_Text* text; + u8 cursor_idx; + lb_80011E24(root, panel, WARN_JOINT_PANEL, -1); - root = GET_JOBJ(arg0); - data = mnDataDel_GetWarnData(); - lb_80011E24(root, &panel, WARN_JOINT_PANEL, -1); if (data->visible != 0) { curr_frame = mn_8022F298(root); if ((mnDataDel_803EF8A0.start_frame <= curr_frame) && (curr_frame < mnDataDel_803EF8A0.end_frame)) { - curr_frame = mn_8022EFD8(panel, &mnDataDel_803EF8A0); - lb_80011E24(root, &exclaim, WARN_JOINT_EXCLAIM, -1); - mn_8022EFD8(exclaim, &mnDataDel_803EF8A0); + curr_frame = mn_8022EFD8(*panel, &mnDataDel_803EF8A0); + lb_80011E24(root, exclaim, WARN_JOINT_EXCLAIM, -1); + mn_8022EFD8(*exclaim, &mnDataDel_803EF8A0); if (curr_frame >= mnDataDel_803EF8A0.end_frame) { u8 visible = data->visible; if (mnDataDel_804D6C6C != NULL) { @@ -208,26 +202,50 @@ void fn_8024ECCC(HSD_GObj* arg0) HSD_SisLib_803A6368(text, sis_id); } } else { - u8 cursor_idx = data->cursor_idx; - lb_80011E24(root, &cursor_yes, WARN_JOINT_CURSOR_YES, -1); - lb_80011E24(root, &cursor_no, WARN_JOINT_CURSOR_NO, -1); + union { + struct { + u8 pad[12]; + HSD_JObj* yes; + HSD_JObj* no; + } fields; + HSD_JObj* slots[5]; + } cursor; + cursor_idx = data->cursor_idx; + lb_80011E24(root, &cursor.slots[3], WARN_JOINT_CURSOR_YES, -1); + lb_80011E24(root, &cursor.slots[4], WARN_JOINT_CURSOR_NO, -1); if ((s32) cursor_idx != 0) { - HSD_JObjReqAnimAll(cursor_yes, 1.0f); - HSD_JObjReqAnimAll(cursor_no, 0.0f); + HSD_JObjReqAnimAll(cursor.fields.yes, 1.0f); + HSD_JObjReqAnimAll(cursor.fields.no, 0.0f); } else { - HSD_JObjReqAnimAll(cursor_yes, 0.0f); - HSD_JObjReqAnimAll(cursor_no, 1.0f); + HSD_JObjReqAnimAll(cursor.fields.yes, 0.0f); + HSD_JObjReqAnimAll(cursor.fields.no, 1.0f); } - HSD_JObjAnimAll(cursor_yes); - HSD_JObjAnimAll(cursor_no); + HSD_JObjAnimAll(cursor.fields.yes); + HSD_JObjAnimAll(cursor.fields.no); } } else { HSD_SisLib_803A5CC4(mnDataDel_804D6C6C); mnDataDel_804D6C6C = NULL; - HSD_GObjPLink_80390228(arg0); + HSD_GObjPLink_80390228(gobj); } } +void fn_8024ECCC(HSD_GObj* arg0) +{ + HSD_JObj* panel; + HSD_JObj* exclaim; + struct WarnCmnData* data; + HSD_JObj* root; + f32 curr_frame; + HSD_Text* text; + s32 sis_id; + PAD_STACK(4); + + root = GET_JOBJ(arg0); + data = mnDataDel_GetWarnData(); + mnDataDel_AnimateWarning(root, arg0, data, &panel, &exclaim); +} + /// @brief creates the warning modal void mnDataDel_8024EEC0(void) { @@ -236,7 +254,7 @@ void mnDataDel_8024EEC0(void) HSD_JObj* cursor_no; HSD_GObj* wrn_modal; HSD_JObj* root; - u8 cursor; + s32 cursor; StaticModelDesc* assets; struct WarnCmnData* data; PAD_STACK(8); @@ -257,7 +275,7 @@ void mnDataDel_8024EEC0(void) HSD_JObjSetFlagsAll(child, JOBJ_HIDDEN); lb_80011E24(root, &child, WARN_JOINT_PROGRESS_BAR, -1); HSD_JObjSetFlagsAll(child, JOBJ_HIDDEN); - cursor = data->cursor_idx; + cursor = data->cursor_idx & 0xFF; { HSD_JObj* no; HSD_JObj* yes; @@ -323,15 +341,26 @@ void fn_8024F1D4(HSD_GObj* gobj) } } +static inline struct mn_80231634_t* +mnDataDel_GetMenuJObj(struct MnDataDelGObjUserData* data, int idx) +{ + return (struct mn_80231634_t*) data->x10[mnDataDel_803EF8AC[idx]]; +} + void fn_8024F318(HSD_GObj* gobj) { + u8 _pad0[0x2C]; HSD_JObj* sp68; + u32 _pad1; HSD_JObj* sp60; + u32 _pad2; HSD_JObj* sp58; + u32 _pad3; HSD_JObj* sp50; HSD_GObjProc* proc; HSD_GObj* temp_gobj; HSD_Text* text; + f32 tmp2; f32 frame; s32 temp_ret; s32 sis_id; @@ -339,7 +368,7 @@ void fn_8024F318(HSD_GObj* gobj) u8 cursor; struct MnDataDelGObjUserData* user_data; struct MnDataDelGObjUserData* case_user_data; - PAD_STACK(0x78); + PAD_STACK(0x30); temp_gobj = gobj; user_data = mnDataDel_804D6C68->user_data; @@ -387,14 +416,15 @@ void fn_8024F318(HSD_GObj* gobj) switch ((s32) cursor) { case 0: { case_user_data = mnDataDel_804D6C68->user_data; - temp_ret = mn_80231634((struct mn_80231634_t*) case_user_data - ->x10[mnDataDel_803EF8AC[0]]); + temp_ret = + mn_80231634(mnDataDel_GetMenuJObj(case_user_data, 0)); lb_80011E24((HSD_JObj*) temp_ret, &sp68, 1, -1); - frame = mn_8022F298(sp68); - HSD_JObjReqAnimAll(sp68, 1.0f); + frame = mnDataDel_8024E940_inline(sp68); + HSD_JObjReqAnimAll(sp68, (0, 1.0f)); mn_8022F3D8(sp68, 0xFFU, MOBJ_MASK); + tmp2 = frame; HSD_JObjAnimAll(sp68); - HSD_JObjReqAnimAll(sp68, frame); + HSD_JObjReqAnimAll(sp68, tmp2); mn_8022F3D8(sp68, 0xFFU, (enum _HSD_TypeMask) 0x480); HSD_JObjAnimAll(sp68); case_user_data->x3[0] = 1; @@ -410,14 +440,15 @@ void fn_8024F318(HSD_GObj* gobj) break; case 2: { case_user_data = mnDataDel_804D6C68->user_data; - temp_ret = mn_80231634((struct mn_80231634_t*) case_user_data - ->x10[mnDataDel_803EF8AC[2]]); + temp_ret = + mn_80231634(mnDataDel_GetMenuJObj(case_user_data, 2)); lb_80011E24((HSD_JObj*) temp_ret, &sp60, 1, -1); - frame = mn_8022F298(sp60); - HSD_JObjReqAnimAll(sp60, 1.0f); + frame = mnDataDel_8024E940_inline(sp60); + HSD_JObjReqAnimAll(sp60, (0, 1.0f)); mn_8022F3D8(sp60, 0xFFU, MOBJ_MASK); + tmp2 = frame; HSD_JObjAnimAll(sp60); - HSD_JObjReqAnimAll(sp60, frame); + HSD_JObjReqAnimAll(sp60, tmp2); mn_8022F3D8(sp60, 0xFFU, (enum _HSD_TypeMask) 0x480); HSD_JObjAnimAll(sp60); case_user_data->x3[2] = 1; @@ -428,14 +459,15 @@ void fn_8024F318(HSD_GObj* gobj) } case 3: { case_user_data = mnDataDel_804D6C68->user_data; - temp_ret = mn_80231634((struct mn_80231634_t*) case_user_data - ->x10[mnDataDel_803EF8AC[3]]); + temp_ret = + mn_80231634(mnDataDel_GetMenuJObj(case_user_data, 3)); lb_80011E24((HSD_JObj*) temp_ret, &sp58, 1, -1); - frame = mn_8022F298(sp58); - HSD_JObjReqAnimAll(sp58, 1.0f); + frame = mnDataDel_8024E940_inline(sp58); + HSD_JObjReqAnimAll(sp58, (0, 1.0f)); mn_8022F3D8(sp58, 0xFFU, MOBJ_MASK); + tmp2 = frame; HSD_JObjAnimAll(sp58); - HSD_JObjReqAnimAll(sp58, frame); + HSD_JObjReqAnimAll(sp58, tmp2); mn_8022F3D8(sp58, 0xFFU, (enum _HSD_TypeMask) 0x480); HSD_JObjAnimAll(sp58); case_user_data->x3[3] = 1; @@ -447,14 +479,15 @@ void fn_8024F318(HSD_GObj* gobj) } case 4: { case_user_data = mnDataDel_804D6C68->user_data; - temp_ret = mn_80231634((struct mn_80231634_t*) case_user_data - ->x10[mnDataDel_803EF8AC[4]]); + temp_ret = + mn_80231634(mnDataDel_GetMenuJObj(case_user_data, 4)); lb_80011E24((HSD_JObj*) temp_ret, &sp50, 1, -1); - frame = mn_8022F298(sp50); - HSD_JObjReqAnimAll(sp50, 1.0f); + frame = mnDataDel_8024E940_inline(sp50); + HSD_JObjReqAnimAll(sp50, (0, 1.0f)); mn_8022F3D8(sp50, 0xFFU, MOBJ_MASK); + tmp2 = frame; HSD_JObjAnimAll(sp50); - HSD_JObjReqAnimAll(sp50, frame); + HSD_JObjReqAnimAll(sp50, tmp2); mn_8022F3D8(sp50, 0xFFU, (enum _HSD_TypeMask) 0x480); HSD_JObjAnimAll(sp50); case_user_data->x3[4] = 1; @@ -495,6 +528,47 @@ void fn_8024F318(HSD_GObj* gobj) } } +static inline void fn_8024F840_inline(u64 buttons, + struct MnDataDelGObjUserData** user_data) +{ + HSD_JObj* joint; + HSD_Text* text; + u16 sis_id; + u8 cursor; + struct MnDataDelGObjUserData* temp_user_data; + + if (buttons & 2) { + lbAudioAx_80024030(2); + temp_user_data = mnDataDel_804D6C68->user_data; + joint = (HSD_JObj*) mn_80231634( + (struct mn_80231634_t*) + temp_user_data->x10[mnDataDel_803EF8AC[(*user_data)->x0]]); + mnDataDel_8024EBC8(joint, (*user_data)->x0, 0U, 0U); + cursor = (*user_data)->x0; + if (cursor == 5) { + (*user_data)->x0 = 0U; + } else { + (*user_data)->x0 = cursor + 1; + } + temp_user_data = mnDataDel_804D6C68->user_data; + joint = (HSD_JObj*) mn_80231634( + (struct mn_80231634_t*) + temp_user_data->x10[mnDataDel_803EF8AC[(*user_data)->x0]]); + mnDataDel_8024EBC8(joint, (*user_data)->x0, 1U, 0U); + *user_data = mnDataDel_804D6C68->user_data; + if ((*user_data)->xC != NULL) { + HSD_SisLib_803A5CC4((*user_data)->xC); + } + sis_id = mnDataDel_803EF8C8[(*user_data)->x0]; + text = HSD_SisLib_803A5ACC(0, 0, -9.5f, 9.1f, 17.0f, 364.68332f, + 38.38772f); + (*user_data)->xC = text; + text->font_size.x = 0.0521f; + text->font_size.y = 0.0521f; + HSD_SisLib_803A6368(text, (s32) sis_id); + } +} + void fn_8024F840(HSD_GObj* gobj) { s32 zero; @@ -506,7 +580,7 @@ void fn_8024F840(HSD_GObj* gobj) u8 cursor; struct MnDataDelGObjUserData* user_data; struct MnDataDelGObjUserData* temp_user_data; - PAD_STACK(0x38); + PAD_STACK(0x28); user_data = mnDataDel_804D6C68->user_data; if (mn_804D6BC8.cooldown != 0) { @@ -515,9 +589,8 @@ void fn_8024F840(HSD_GObj* gobj) mn_804D6BC8.x4 = 0; return; } - buttons = mn_80229624(4U); + buttons = Menu_GetAllInputs(); zero = 0; - mn_804A04F0.buttons = buttons; if (buttons & 0x20) { lbAudioAx_80024030(0); mn_804A04F0.entering_menu = zero; @@ -566,36 +639,7 @@ void fn_8024F840(HSD_GObj* gobj) HSD_SisLib_803A6368(text, (s32) sis_id); return; } - if (buttons & 2) { - lbAudioAx_80024030(2); - temp_user_data = mnDataDel_804D6C68->user_data; - joint = (HSD_JObj*) mn_80231634( - (struct mn_80231634_t*) - temp_user_data->x10[mnDataDel_803EF8AC[user_data->x0]]); - mnDataDel_8024EBC8(joint, user_data->x0, 0U, 0U); - cursor = user_data->x0; - if (cursor == 5) { - user_data->x0 = 0U; - } else { - user_data->x0 = cursor + 1; - } - temp_user_data = mnDataDel_804D6C68->user_data; - joint = (HSD_JObj*) mn_80231634( - (struct mn_80231634_t*) - temp_user_data->x10[mnDataDel_803EF8AC[user_data->x0]]); - mnDataDel_8024EBC8(joint, user_data->x0, 1U, 0U); - user_data = mnDataDel_804D6C68->user_data; - if (user_data->xC != NULL) { - HSD_SisLib_803A5CC4(user_data->xC); - } - sis_id = mnDataDel_803EF8C8[user_data->x0]; - text = HSD_SisLib_803A5ACC(0, 0, -9.5f, 9.1f, 17.0f, 364.68332f, - 38.38772f); - user_data->xC = text; - text->font_size.x = 0.0521f; - text->font_size.y = 0.0521f; - HSD_SisLib_803A6368(text, (s32) sis_id); - } + fn_8024F840_inline(buttons, &user_data); } void fn_8024FBA4(HSD_GObj* gobj) @@ -657,10 +701,20 @@ void fn_8024FC48(HSD_GObj* gobj) } } +static inline void +mnDataDel_AnimateMenuItems(struct MnDataDelGObjUserData* user_data) +{ + s32 i; + + for (i = 0; i < 6; i++) { + mn_8022EE84(user_data->x10[mnDataDel_803EF8AC[i]], + &mnDataDel_803EF870.x0, (enum _HSD_TypeMask) 0x480); + } +} + void fn_8024FD40(HSD_GObj* gobj) { f32 frame; - s32 i; struct MnDataDelGObjUserData* user_data; HSD_GObjProc* proc; HSD_JObj* jobj; @@ -677,10 +731,7 @@ void fn_8024FD40(HSD_GObj* gobj) } frame = mn_8022EE84(jobj, &mnDataDel_803EF870.x0, (enum _HSD_TypeMask) 0x480); - for (i = 0; i < 6; i++) { - mn_8022EE84(user_data->x10[mnDataDel_803EF8AC[i]], - &mnDataDel_803EF870.x0, (enum _HSD_TypeMask) 0x480); - } + mnDataDel_AnimateMenuItems(user_data); if (frame == mnDataDel_803EF870.x0.end_frame) { HSD_GObjProc_8038FE24(HSD_GObj_804D7838); proc = HSD_GObj_SetupProc(gobj, fn_8024FC48, 0); @@ -695,13 +746,13 @@ void mnDataDel_8024FE4C(u8 arg0) HSD_GObjProc* proc; HSD_JObj* root; HSD_JObj* joint; + u16 sis_id; u8 is_enabled; HSD_JObj* jobj; HSD_Text* text; f32 frame; s32 enabled; s32 i; - u16 sis_id; StaticModelDesc* assets; struct MnDataDelGObjUserData* user_data; PAD_STACK(0x14); diff --git a/src/melee/mn/mndiagram.c b/src/melee/mn/mndiagram.c index 0ae5a83efe..a6c6f7177d 100644 --- a/src/melee/mn/mndiagram.c +++ b/src/melee/mn/mndiagram.c @@ -1248,7 +1248,7 @@ void mnDiagram_InputProc(HSD_GObj* gobj) return; } i = (u8) data->fighter_cursor_pos; - col = (u8) mn_804A04F0.hovered_selection; + col = mn_804A04F0.hovered_selection; ptr = sorted + i; goto fc_test; fc_outer: diff --git a/src/melee/mn/mndiagram2.c b/src/melee/mn/mndiagram2.c index 939962b5a2..f45439ca59 100644 --- a/src/melee/mn/mndiagram2.c +++ b/src/melee/mn/mndiagram2.c @@ -607,6 +607,11 @@ int mnDiagram2_GetStatValue(int is_name_mode, u8 stat_type, u8 entity_idx) /// @param stat_type Stat category index (0-23) /// @param row_idx Row position (0-9, 10 visible rows) /// @param entity_idx Fighter or Name index for stat lookup +static inline u16* mnDiagram2_GetStatRowEntry(int stat_type, char* base) +{ + return (u16*) (base + ((stat_type << 1) & 0x1FE)); +} + void mnDiagram2_CreateStatRow(HSD_GObj* gobj, u8 is_name_mode, u8 stat_type, u8 row_idx, u8 entity_idx) { @@ -636,7 +641,7 @@ void mnDiagram2_CreateStatRow(HSD_GObj* gobj, u8 is_name_mode, u8 stat_type, lb_8000B1CC(data->row0_ref, (Vec3*) (base + 0xC), &sp20); { - u32 r22 = (u8) row_idx; + u32 r22 = row_idx; f32 ny = -sp20.y; f32 temp_f31 = -f30 * (f32) r22; text = HSD_SisLib_803A5ACC(0, 1, sp20.x, ny + temp_f31, sp20.z, @@ -645,7 +650,7 @@ void mnDiagram2_CreateStatRow(HSD_GObj* gobj, u8 is_name_mode, u8 stat_type, { data->row_labels[row_idx] = text; - table = (u16*) (base + ((stat_type << 1) & 0x1FE)); + table = mnDiagram2_GetStatRowEntry(stat_type, base); { HSD_SisLib_803A6368(text, table[0x18]); @@ -998,11 +1003,11 @@ void mnDiagram2_Create(int arg0) HSD_GObj* gobj; Diagram2* new_var; int j; - u32 is_name; + int threshold; u8 entity_idx; int scroll; int i; - int threshold; + u32 is_name; HSD_JObj* jobj; int offset; Diagram2* user_data2; diff --git a/src/melee/mn/mndiagram3.c b/src/melee/mn/mndiagram3.c index bb1c88f0ff..eb41f5e762 100644 --- a/src/melee/mn/mndiagram3.c +++ b/src/melee/mn/mndiagram3.c @@ -24,6 +24,13 @@ #include #include +typedef struct mnDiagram3_SortEntry { + u8 name; + char pad[7]; + s32 x8; + s32 xC; +} mnDiagram3_SortEntry; + void mnDiagram3_PopulateRankings(HSD_GObj* gobj) { Vec3 sp6C; @@ -60,7 +67,8 @@ void mnDiagram3_PopulateRankings(HSD_GObj* gobj) limit = (data->is_name_mode != 0) ? 0x18 : 0x15; { - int val = scroll + offset; + int idx = scroll + offset; + int val = idx; if (val >= limit) { val = val - limit; } else { @@ -148,12 +156,11 @@ void mnDiagram3_PopulateRankings(HSD_GObj* gobj) value_text->text_color = mn_804D4B64; } - if (mnDiagram2_IsIconOnlyStat(stat_type)) { - mnDiagram2_GetAggregatedFighterRank(sp48, stat_type, - (u8) i); - if (sp48[0] == 0x19) { - goto next; - } + if (mnDiagram2_IsIconOnlyStat(stat_type) && + (mnDiagram2_GetAggregatedFighterRank(sp48, stat_type, + (u8) i), + sp48[0] != 0x19)) + { mnDiagram2_GetAggregatedFighterRank(sp38, stat_type, (u8) i); icon = mnDiagram_CreateFighterIcon(sp38[0], 0); @@ -166,7 +173,7 @@ void mnDiagram3_PopulateRankings(HSD_GObj* gobj) ii); } { - int val = M2C_FIELD(sp28, int*, 0xC); + int val = ((mnDiagram3_SortEntry*) sp28)->xC; mnDiagram_FormatDecimalNumber((char*) sp58, val, 0); } { @@ -675,7 +682,10 @@ void mnDiagram3_HandleInput(HSD_GObj* gobj) data->row_labels[i] = t; i_u8 = i; limit = (data->is_name_mode != 0) ? 0x18 : 0x15; - v = base_idx_u8 + i_u8; + { + int tmp = base_idx_u8 + i_u8; + v = tmp; + } if (v >= limit) { v = v - limit; } else { @@ -753,8 +763,10 @@ void mnDiagram3_HandleInput(HSD_GObj* gobj) data->row_labels[i] = t; i_u8 = i; limit = (data->is_name_mode != 0) ? 0x18 : 0x15; - v = base_idx_u8 + i_u8; - (void) v; + { + int tmp = base_idx_u8 + i_u8; + v = tmp; + } if (v >= limit) { v = v - limit; } else { @@ -832,8 +844,10 @@ void mnDiagram3_HandleInput(HSD_GObj* gobj) data->row_labels[i] = t; i_u8 = i; limit = (data->is_name_mode != 0) ? 0x18 : 0x15; - v = base_idx_u8; - v += i_u8; + { + int tmp = base_idx_u8 + i_u8; + v = tmp; + } if (v >= limit) { v = v - limit; } else { diff --git a/src/melee/mn/mnevent.c b/src/melee/mn/mnevent.c index 7f31119a74..e312d8f9dd 100644 --- a/src/melee/mn/mnevent.c +++ b/src/melee/mn/mnevent.c @@ -117,8 +117,8 @@ static char mnEvent_804D5044[4] = { 0x81, 0x7C, 0, 0 }; void mnEvent_8024D15C(s32 idx, s32 event_id) { - HSD_JObj* jobj_0A; HSD_JObj* jobj_0C; + HSD_JObj* jobj_0A; Vec3 pos; Vec3 icon_pos; HSD_JObj* jobj_0C_2; @@ -127,13 +127,14 @@ void mnEvent_8024D15C(s32 idx, s32 event_id) HSD_Text** text_slot; HSD_Text** icon_slot; HSD_JObj* icon_jobj; + void** assets; HSD_Text* text; HSD_Text* icon_text; f32 spacing; HSD_JObj* jobj_0A_2; s32 is_unlocked; HSD_JObj* tree; - PAD_STACK(0x40); + PAD_STACK(0x38); tree = mnEvent_804D6C60->hsd_obj; data = mnEvent_804D6C60->user_data; @@ -155,6 +156,7 @@ void mnEvent_8024D15C(s32 idx, s32 event_id) if (is_unlocked != 0) { HSD_GObj* icon_gobj; tree = mnEvent_804D6C60->hsd_obj; + assets = mnEvent_804A08F8; lb_80011E24(tree, &jobj_0A_2, 0xA, -1); lb_80011E24(tree, &jobj_0C_2, 0xC, -1); icon_spacing = HSD_JObjGetTranslationY(jobj_0A_2); @@ -163,14 +165,17 @@ void mnEvent_8024D15C(s32 idx, s32 event_id) icon_pos.y = icon_pos.y + (f32) idx * icon_spacing; icon_gobj = GObj_Create(6, 7, 0x80); - icon_jobj = HSD_JObjLoadJoint((HSD_Joint*) mnEvent_804A0908); + icon_jobj = HSD_JObjLoadJoint((HSD_Joint*) assets[4]); HSD_GObjObject_80390A70(icon_gobj, HSD_GObj_804D7849, icon_jobj); GObj_SetupGXLink(icon_gobj, HSD_GObj_JObjCallback, 4, 0x80); mnEvent_8024D4E0(icon_jobj, &icon_pos); data->gobjs[idx] = icon_gobj; } - text_slot = &data->texts[idx]; + { + HSD_Text** texts = data->texts; + text_slot = &texts[idx]; + } (void) text_slot; if (*text_slot != NULL) { HSD_SisLib_803A5CC4(data->texts[idx]); @@ -196,8 +201,10 @@ void mnEvent_8024D15C(s32 idx, s32 event_id) *icon_slot = icon_text; icon_text->font_size.x = 0.035f; icon_text->font_size.y = 0.035f; - HSD_SisLib_803A6368(icon_text, - ((gm_801BEBA8((u8) event_id) * 2) & 0x1FE) + 0x154); + { + s32 sis_id = ((gm_801BEBA8((u8) event_id) * 2) & 0x1FE) + 0x154; + HSD_SisLib_803A6368(icon_text, sis_id); + } } void mnEvent_8024D4E0(HSD_JObj* jobj, Vec3* translate) @@ -345,14 +352,73 @@ void fn_8024E34C(HSD_GObj* gobj) } } -void mnEvent_8024E524(s32 event_idx) +static inline u8 mnEvent_8024E524_inline(HSD_GObjProc* proc, + MnEventData* user_data) { - HSD_GObj* event_gobj; s32 first_event; s32 i; + + proc->flags_3 = HSD_GObj_804D783C; + first_event = user_data->first_event; + for (i = 0; i < 9; i++) { + mnEvent_8024D15C(i, first_event + i); + } + return gm_801BEBA8((u32) (user_data->first_event + user_data->page) & + 0xFF); +} + +static inline u8 mnEvent_RefreshList(MnEventData* data) +{ + s32 first_event; + s32 i; + + first_event = data->first_event; + for (i = 0; i < 9; i++) { + mnEvent_8024D15C(i, first_event + i); + } + return gm_801BEBA8((u32) (data->first_event + data->page) & 0xFF); +} + +static inline void mnEvent_SetPage(MnEventData* data) +{ + HSD_JObj* jobj_0C; + HSD_JObj* jobj_0A; + HSD_JObj* jobj_0B; u8 page; + HSD_JObj* tree; + f32 y_a; + f32 y_b; + + tree = mnEvent_804D6C60->hsd_obj; + page = data->page; + lb_80011E24(tree, &jobj_0A, 0xA, -1); + lb_80011E24(tree, &jobj_0C, 0xC, -1); + y_a = HSD_JObjGetTranslationY(jobj_0A); + y_b = HSD_JObjGetTranslationY(jobj_0C); + lb_80011E24(tree, &jobj_0B, 0xB, -1); + HSD_JObjSetTranslateY(jobj_0B, (f32) page * (y_b - y_a)); +} + +static inline void mnEvent_8024E524_inline_2(u8 event, HSD_JObj** jobj) +{ + HSD_GObj* event_gobj; s32 event_id; - u8 event; + + event_gobj = mnEvent_804D6C60; + event_id = event; + mnEvent_8024D0CC(event_gobj, (s8) gm_801BEBF8(event_id & 0xFF)); + mnEvent_8024D7E0(event_gobj, event); + mnEvent_8024D5B0(event_gobj, event_id); + lb_80011E24(event_gobj->hsd_obj, jobj, 9, -1); + HSD_JObjReqAnimAll( + *jobj, (f32) (u8) gm_801BEB8C(gm_801BEBC0(event_id & 0xFF) & 0xFF)); + HSD_JObjAnimAll(*jobj); + mnEvent_8024D014(event_gobj); +} + +void mnEvent_8024E524(s32 event_idx) +{ + u8 page; HSD_JObj* jobj_0B; HSD_JObj* jobj_0C; HSD_JObj* jobj_0A; @@ -361,6 +427,7 @@ void mnEvent_8024E524(s32 event_idx) HSD_GObjProc* proc; HSD_JObj* tree; MnEventData* user_data; + u8 event; void** assets; f32 y_a; f32 y_b; @@ -393,43 +460,18 @@ void mnEvent_8024E524(s32 event_idx) HSD_JObjSetTranslateY(jobj_0B, y); proc = HSD_GObj_SetupProc(gobj, fn_8024E34C, 0); - proc->flags_3 = HSD_GObj_804D783C; - first_event = user_data->first_event; - for (i = 0; i < 9; i++) { - mnEvent_8024D15C(i, first_event + i); - } - - event = - gm_801BEBA8((u32) (user_data->first_event + user_data->page) & 0xFF); - event_gobj = mnEvent_804D6C60; - event_id = event; - mnEvent_8024D0CC(event_gobj, (s8) gm_801BEBF8(event_id & 0xFF)); - mnEvent_8024D7E0(event_gobj, event); - mnEvent_8024D5B0(event_gobj, event_id); - lb_80011E24(event_gobj->hsd_obj, &jobj_09, 9, -1); - HSD_JObjReqAnimAll( - jobj_09, (f32) (u8) gm_801BEB8C(gm_801BEBC0(event_id & 0xFF) & 0xFF)); - HSD_JObjAnimAll(jobj_09); - mnEvent_8024D014(event_gobj); + event = mnEvent_8024E524_inline(proc, user_data); + mnEvent_8024E524_inline_2(event, &jobj_09); } void fn_8024D864(HSD_GObj* gobj) { - HSD_JObj* jobj_0C; - HSD_JObj* jobj_0A; - HSD_JObj* jobj_0B; - HSD_JObj* jobj_09; MnEventData* data; - HSD_GObj* event_gobj; u64 inputs; - s32 i; - s32 first_event; s32 selected_event; - s32 page; + u8 page; u8 event; - f32 y_a; - f32 y_b; - PAD_STACK(0x78); + PAD_STACK(0x48); if (mn_804D6BC8.cooldown != 0) { mn_804D6BC8.cooldown -= 1; @@ -476,21 +518,11 @@ void fn_8024D864(HSD_GObj* gobj) } else { data->first_event = max_events; } - first_event = data->first_event; - for (i = 0; i < 9; i++) { - mnEvent_8024D15C(i, first_event + i); + event = mnEvent_RefreshList(data); + { + HSD_JObj* selection_jobj; + mnEvent_8024E524_inline_2(event, &selection_jobj); } - selected_event = data->first_event + data->page; - event = gm_801BEBA8((u8) selected_event); - event_gobj = mnEvent_804D6C60; - mnEvent_8024D0CC(event_gobj, (s8) gm_801BEBF8(event)); - mnEvent_8024D7E0(event_gobj, event); - mnEvent_8024D5B0(event_gobj, event); - lb_80011E24(event_gobj->hsd_obj, &jobj_09, 9, -1); - HSD_JObjReqAnimAll(jobj_09, - (f32) (u8) gm_801BEB8C(gm_801BEBC0(event))); - HSD_JObjAnimAll(jobj_09); - mnEvent_8024D014(event_gobj); } } else if (inputs & MenuInput_YButton) { if (data->first_event - 9 >= 0 || data->first_event != 0) { @@ -500,106 +532,57 @@ void fn_8024D864(HSD_GObj* gobj) } else { data->first_event = 0; } - first_event = data->first_event; - for (i = 0; i < 9; i++) { - mnEvent_8024D15C(i, first_event + i); + event = mnEvent_RefreshList(data); + { + HSD_JObj* selection_jobj; + mnEvent_8024E524_inline_2(event, &selection_jobj); } - selected_event = data->first_event + data->page; - event = gm_801BEBA8((u8) selected_event); - event_gobj = mnEvent_804D6C60; - mnEvent_8024D0CC(event_gobj, (s8) gm_801BEBF8(event)); - mnEvent_8024D7E0(event_gobj, event); - mnEvent_8024D5B0(event_gobj, event); - lb_80011E24(event_gobj->hsd_obj, &jobj_09, 9, -1); - HSD_JObjReqAnimAll(jobj_09, (f32) gm_801BEB8C(gm_801BEBC0(event))); - HSD_JObjAnimAll(jobj_09); - mnEvent_8024D014(event_gobj); } } else if (inputs & MenuInput_Up) { page = data->page; if (page != 0) { lbAudioAx_80024030(2); data->page -= 1; - lb_80011E24(mnEvent_804D6C60->hsd_obj, &jobj_0A, 0xA, -1); - lb_80011E24(mnEvent_804D6C60->hsd_obj, &jobj_0C, 0xC, -1); - y_a = HSD_JObjGetTranslationY(jobj_0A); - y_b = HSD_JObjGetTranslationY(jobj_0C); - lb_80011E24(mnEvent_804D6C60->hsd_obj, &jobj_0B, 0xB, -1); - HSD_JObjSetTranslateY(jobj_0B, (f32) data->page * (y_b - y_a)); + mnEvent_SetPage(data); selected_event = data->first_event + data->page; event = gm_801BEBA8((u8) selected_event); - event_gobj = mnEvent_804D6C60; - mnEvent_8024D0CC(event_gobj, (s8) gm_801BEBF8(event)); - mnEvent_8024D7E0(event_gobj, event); - mnEvent_8024D5B0(event_gobj, event); - lb_80011E24(event_gobj->hsd_obj, &jobj_09, 9, -1); - HSD_JObjReqAnimAll(jobj_09, - (f32) (u8) gm_801BEB8C(gm_801BEBC0(event))); - HSD_JObjAnimAll(jobj_09); - mnEvent_8024D014(event_gobj); + { + HSD_JObj* selection_jobj; + mnEvent_8024E524_inline_2(event, &selection_jobj); + } return; } if (data->first_event != 0) { lbAudioAx_80024030(2); data->first_event -= 1; - first_event = data->first_event; - for (i = 0; i < 9; i++) { - mnEvent_8024D15C(i, first_event + i); + event = mnEvent_RefreshList(data); + { + HSD_JObj* selection_jobj; + mnEvent_8024E524_inline_2(event, &selection_jobj); } - selected_event = data->first_event + data->page; - event = gm_801BEBA8((u8) selected_event); - event_gobj = mnEvent_804D6C60; - mnEvent_8024D0CC(event_gobj, (s8) gm_801BEBF8(event)); - mnEvent_8024D7E0(event_gobj, event); - mnEvent_8024D5B0(event_gobj, event); - lb_80011E24(event_gobj->hsd_obj, &jobj_09, 9, -1); - HSD_JObjReqAnimAll(jobj_09, - (f32) (u8) gm_801BEB8C(gm_801BEBC0(event))); - HSD_JObjAnimAll(jobj_09); - mnEvent_8024D014(event_gobj); } } else if (inputs & MenuInput_Down) { page = data->page; if (page < 8) { lbAudioAx_80024030(2); data->page += 1; - lb_80011E24(mnEvent_804D6C60->hsd_obj, &jobj_0A, 0xA, -1); - lb_80011E24(mnEvent_804D6C60->hsd_obj, &jobj_0C, 0xC, -1); - y_a = HSD_JObjGetTranslationY(jobj_0A); - y_b = HSD_JObjGetTranslationY(jobj_0C); - lb_80011E24(mnEvent_804D6C60->hsd_obj, &jobj_0B, 0xB, -1); - HSD_JObjSetTranslateY(jobj_0B, (f32) data->page * (y_b - y_a)); + mnEvent_SetPage(data); selected_event = data->first_event + data->page; event = gm_801BEBA8((u8) selected_event); - event_gobj = mnEvent_804D6C60; - mnEvent_8024D0CC(event_gobj, (s8) gm_801BEBF8(event)); - mnEvent_8024D7E0(event_gobj, event); - mnEvent_8024D5B0(event_gobj, event); - lb_80011E24(event_gobj->hsd_obj, &jobj_09, 9, -1); - HSD_JObjReqAnimAll(jobj_09, - (f32) (u8) gm_801BEB8C(gm_801BEBC0(event))); - HSD_JObjAnimAll(jobj_09); - mnEvent_8024D014(event_gobj); + { + HSD_JObj* selection_jobj; + mnEvent_8024E524_inline_2(event, &selection_jobj); + } return; } if (data->first_event < mnEvent_8024CE74()) { lbAudioAx_80024030(2); data->first_event += 1; - first_event = data->first_event; - for (i = 0; i < 9; i++) { - mnEvent_8024D15C(i, first_event + i); + event = mnEvent_RefreshList(data); + { + HSD_JObj* selection_jobj; + mnEvent_8024E524_inline_2(event, &selection_jobj); } - selected_event = data->first_event + data->page; - event = gm_801BEBA8((u8) selected_event); - event_gobj = mnEvent_804D6C60; - mnEvent_8024D0CC(event_gobj, (s8) gm_801BEBF8(event)); - mnEvent_8024D7E0(event_gobj, event); - mnEvent_8024D5B0(event_gobj, event); - lb_80011E24(event_gobj->hsd_obj, &jobj_09, 9, -1); - HSD_JObjReqAnimAll(jobj_09, - (f32) (u8) gm_801BEB8C(gm_801BEBC0(event))); - HSD_JObjAnimAll(jobj_09); - mnEvent_8024D014(event_gobj); } } } diff --git a/src/melee/mn/mninfo.c b/src/melee/mn/mninfo.c index 7c6becbf85..b4d8972fa9 100644 --- a/src/melee/mn/mninfo.c +++ b/src/melee/mn/mninfo.c @@ -239,12 +239,13 @@ void fn_80251FE4(void) MenuInfo_GObj* gobj; MnInfoData* data; u64 buttons; - s32 i; s32 count; - u8* trophy; + s32 i; + s32 j; + MnInfoTextCursor* right; MnInfoTextCursor* cursor_base; MnInfoTextCursor* left; - MnInfoTextCursor* right; + u8* trophy; PAD_STACK(0x20); data = mnInfo_804D6C78->user_data; @@ -265,10 +266,10 @@ void fn_80251FE4(void) if (data->scroll_idx != 0) { data->scroll_idx -= 1; lbAudioAx_80024030(2); - i = 0; + j = 0; cursor_base = mnInfo_804D6C78->user_data; left = cursor_base; - right = (MnInfoTextCursor*) &((HSD_Text**) cursor_base)[i]; + right = (MnInfoTextCursor*) &((HSD_Text**) cursor_base)[j]; do { if (left->left != NULL) { HSD_SisLib_803A5CC4(right->left); @@ -278,10 +279,10 @@ void fn_80251FE4(void) HSD_SisLib_803A5CC4(right->right); left->right = NULL; } - i++; + j++; left = (MnInfoTextCursor*) ((u8*) left + 4); right = (MnInfoTextCursor*) ((u8*) right + 4); - } while (i < 4); + } while (j < 4); gobj = mnInfo_804D6C78; trophy = &mnInfo_804A0968[data->scroll_idx]; for (i = 0; i < 4; i++) { @@ -296,18 +297,18 @@ void fn_80251FE4(void) } } else if (buttons & MenuInput_Down) { count = 0; - for (i = 0; i < 0x42; i++) { - if (mnInfo_80251A08(i) != 0) { + for (j = 0; j < 0x42; j++) { + if (mnInfo_80251A08(j) != 0) { count++; } } if ((data->scroll_idx + 4) < count) { lbAudioAx_80024030(2); data->scroll_idx += 1; - i = 0; + j = 0; cursor_base = mnInfo_804D6C78->user_data; left = cursor_base; - right = (MnInfoTextCursor*) &((HSD_Text**) cursor_base)[i]; + right = (MnInfoTextCursor*) &((HSD_Text**) cursor_base)[j]; do { if (left->left != NULL) { HSD_SisLib_803A5CC4(right->left); @@ -317,10 +318,10 @@ void fn_80251FE4(void) HSD_SisLib_803A5CC4(right->right); left->right = NULL; } - i++; + j++; left = (MnInfoTextCursor*) ((u8*) left + 4); right = (MnInfoTextCursor*) ((u8*) right + 4); - } while (i < 4); + } while (j < 4); gobj = mnInfo_804D6C78; trophy = &mnInfo_804A0968[data->scroll_idx]; for (i = 0; i < 4; i++) { @@ -371,88 +372,112 @@ void fn_802523B8(HSD_GObj* gobj) HSD_GObjPLink_80390228(gobj); } -void fn_802523D8(HSD_GObj* gobj) +static inline void fn_802523D8_inline(MnInfoData* data, HSD_GObj* gobj, + HSD_JObj** child) { - HSD_JObj* sp1C; HSD_GObjProc* proc; - s32 i; HSD_JObj* jobj; - MnInfoData* data; - MnInfoTextCursor* cursor_base; - MnInfoTextCursor* read_cursor; - MnInfoTextCursor* write_cursor; - HSD_Text* zero_left; - HSD_Text* zero_right; - PAD_STACK(16); + PAD_STACK(20); - data = gobj->user_data; if (mn_804A04F0.cur_menu != MENU_KIND_DATA_SPECIAL) { HSD_GObjProc_8038FE24(HSD_GObj_804D7838); proc = HSD_GObj_SetupProc(gobj, fn_802523B8, 0); - i = 0; proc->flags_3 = HSD_GObj_804D783C; - cursor_base = gobj->user_data; - write_cursor = cursor_base; - zero_left = (HSD_Text*) i; - zero_right = (HSD_Text*) i; - read_cursor = (MnInfoTextCursor*) &((HSD_Text**) cursor_base)[i]; - do { - if (write_cursor->left != NULL) { - HSD_SisLib_803A5CC4(read_cursor->left); - write_cursor->left = zero_left; - } - if (write_cursor->right != NULL) { - HSD_SisLib_803A5CC4(read_cursor->right); - write_cursor->right = zero_right; + { + MnInfoData* data2 = gobj->user_data; + MnInfoData* data3 = data2; + s32 i; + HSD_Text* left_null = NULL; + HSD_Text* right_null = NULL; + + for (i = 0; i < 4; i++) { + if (data2->left_column[i] != NULL) { + HSD_SisLib_803A5CC4(data3->left_column[i]); + data2->left_column[i] = left_null; + } + if (data2->right_column[i] != NULL) { + HSD_SisLib_803A5CC4(data3->right_column[i]); + data2->right_column[i] = right_null; + } } - i += 1; - write_cursor = (MnInfoTextCursor*) &((HSD_Text**) write_cursor)[1]; - read_cursor = (MnInfoTextCursor*) &((HSD_Text**) read_cursor)[1]; - } while (i < 4); - HSD_SisLib_803A5CC4(data->description); - return; - } - jobj = gobj->hsd_obj; - lb_80011E24(jobj, &sp1C, 2, -1); - if (data->scroll_idx != 0) { - HSD_JObjClearFlagsAll(sp1C, JOBJ_HIDDEN); + HSD_SisLib_803A5CC4(data->description); + } } else { - HSD_JObjSetFlagsAll(sp1C, JOBJ_HIDDEN); + jobj = gobj->hsd_obj; + lb_80011E24(jobj, child, 2, -1); + if (data->scroll_idx != 0) { + HSD_JObjClearFlagsAll(*child, JOBJ_HIDDEN); + } else { + HSD_JObjSetFlagsAll(*child, JOBJ_HIDDEN); + } + lb_80011E24(jobj, child, 1, -1); + if ((data->scroll_idx + 4) < mnInfo_80251AA4()) { + HSD_JObjClearFlagsAll(*child, JOBJ_HIDDEN); + } else { + HSD_JObjSetFlagsAll(*child, JOBJ_HIDDEN); + } + mn_8022ED6C(jobj, (AnimLoopSettings*) mnInfo_803EFC08); } - lb_80011E24(jobj, &sp1C, 1, -1); - if ((data->scroll_idx + 4) < mnInfo_80251AA4()) { - HSD_JObjClearFlagsAll(sp1C, JOBJ_HIDDEN); - } else { - HSD_JObjSetFlagsAll(sp1C, JOBJ_HIDDEN); +} + +void fn_802523D8(HSD_GObj* gobj) +{ + UNUSED u8 frame_pad[8]; + HSD_JObj* child; + MnInfoData* data = gobj->user_data; + PAD_STACK(8); + fn_802523D8_inline(data, gobj, &child); +} + +static inline void mnInfo_80252548_StopCurrentProc(void) +{ + HSD_GObjProc_8038FE24(HSD_GObj_804D7838); +} + +static inline void mnInfo_80252548_InitRowsAndObject(HSD_GObj* gobj, + HSD_JObj** jobj) +{ + u8* trophy; + s32 i; + u8 id; + + trophy = mnInfo_804A0968; + for (i = 0; i < 4; i++) { + if (mnInfo_80251A08(*trophy) != 0) { + id = *trophy; + mnInfo_80251D58((MenuInfo_GObj*) gobj, i, id, + *gmMainLib_8015D804(id)); + mnInfo_80251F04((MenuInfo_GObj*) gobj, i, id); + } + trophy++; } - mn_8022ED6C(jobj, (AnimLoopSettings*) mnInfo_803EFC08); + *jobj = HSD_JObjLoadJoint(mnInfo_804A0958.joint); + HSD_GObjObject_80390A70(gobj, HSD_GObj_804D7849, *jobj); } void fn_80252548(HSD_GObj* gobj) { - MnInfoData* data; HSD_GObjProc* proc; - HSD_JObj* jobj; - s32 i; + HSD_Text* zero_left; + u8 id; u8* trophy; - MnInfoTextCursor* cursor_base; - MnInfoTextCursor* read_cursor; + MnInfoData* data = gobj->user_data; MnInfoTextCursor* write_cursor; - HSD_Text* zero_left; - HSD_Text* zero_right; - PAD_STACK(24); + s32 i; + HSD_JObj* jobj; + PAD_STACK(16); - data = gobj->user_data; if (mn_804A04F0.cur_menu != MENU_KIND_DATA_SPECIAL) { + HSD_Text* zero_right; + MnInfoTextCursor* read_cursor; HSD_GObjProc_8038FE24(HSD_GObj_804D7838); proc = HSD_GObj_SetupProc(gobj, fn_802523B8, 0); i = 0; proc->flags_3 = HSD_GObj_804D783C; - cursor_base = gobj->user_data; - write_cursor = cursor_base; + write_cursor = gobj->user_data; + read_cursor = (MnInfoTextCursor*) &((HSD_Text**) write_cursor)[i]; zero_left = (HSD_Text*) i; zero_right = (HSD_Text*) i; - read_cursor = (MnInfoTextCursor*) &((HSD_Text**) cursor_base)[i]; do { if (write_cursor->left != NULL) { HSD_SisLib_803A5CC4(read_cursor->left); @@ -473,26 +498,14 @@ void fn_80252548(HSD_GObj* gobj) data->anim_timer--; return; } - trophy = mnInfo_804A0968; - for (i = 0; i < 4; i++) { - if (mnInfo_80251A08(*trophy) != 0) { - u8 id = *trophy; - - mnInfo_80251D58((MenuInfo_GObj*) gobj, i, id, - *gmMainLib_8015D804(id)); - mnInfo_80251F04((MenuInfo_GObj*) gobj, i, id); - } - trophy++; - } - jobj = HSD_JObjLoadJoint(mnInfo_804A0958.joint); - HSD_GObjObject_80390A70(gobj, HSD_GObj_804D7849, jobj); + mnInfo_80252548_InitRowsAndObject(gobj, &jobj); GObj_SetupGXLink(gobj, HSD_GObj_JObjCallback, 4, 0x80); HSD_JObjAddAnimAll(jobj, mnInfo_804A0958.animjoint, mnInfo_804A0958.matanim_joint, mnInfo_804A0958.shapeanim_joint); HSD_JObjReqAnimAll(jobj, 0.0f); mnInfo_802522B8(gobj); - HSD_GObjProc_8038FE24(HSD_GObj_804D7838); + mnInfo_80252548_StopCurrentProc(); proc = HSD_GObj_SetupProc(gobj, fn_802523D8, 0); proc->flags_3 = HSD_GObj_804D783C; } @@ -519,12 +532,9 @@ void mnInfo_80252720(MnInfoData* data) s32 mnInfo_80252758(void) { - s32 spC; - void* sp8; MnInfoData* data; MnInfoDataLayout* layout; MnInfoData* user_data; - MnInfoData* temp_ret; HSD_GObj* menu_gobj; HSD_GObjProc* proc; HSD_GObjProc* menu_proc; @@ -536,22 +546,19 @@ s32 mnInfo_80252758(void) mn_804A04F0.prev_menu = mn_804A04F0.cur_menu; mn_804A04F0.cur_menu = 0x1D; mn_804A04F0.hovered_selection = 0; - sp8 = layout->top_shapeanim_joint; - spC = 0; lbArchive_LoadSections( mn_804D6BB8, (void**) &mnInfo_804A0958.joint, layout->top_joint, &mnInfo_804A0958.animjoint, layout->top_animjoint, &mnInfo_804A0958.matanim_joint, layout->top_matanim_joint, - &mnInfo_804A0958.shapeanim_joint, sp8, spC); + &mnInfo_804A0958.shapeanim_joint, layout->top_shapeanim_joint, 0); mnInfo_80251AFC(); menu_gobj = GObj_Create(6, 7, 0x80); mnInfo_804D6C78 = menu_gobj; - temp_ret = HSD_MemAlloc(sizeof(MnInfoData)); - user_data = temp_ret; + user_data = HSD_MemAlloc(sizeof(MnInfoData)); HSD_ASSERTREPORT(0x267, user_data, "Can't get user_data.\n"); mnInfo_80252720(user_data); GObj_InitUserData(menu_gobj, 0, HSD_Free, user_data); diff --git a/src/melee/mn/mnitemsw.c b/src/melee/mn/mnitemsw.c index 5df736398f..3fbbc5f9d1 100644 --- a/src/melee/mn/mnitemsw.c +++ b/src/melee/mn/mnitemsw.c @@ -205,25 +205,23 @@ void mnItemSw_80233B68(MnItemSwData* arg0, u32 arg1) void fn_80233E10(HSD_GObj* gobj) { + MnItemSwData* data; u8* order; u32 buttons; s32 i; - MnItemSwData* data; PAD_STACK(0x20); data = (MnItemSwData*) mnItemSw_804D6BE8->user_data; - buttons = mn_80229624(4); - mn_804A04F0.buttons = buttons; + buttons = mn_804A04F0.buttons = mn_80229624(4U); i = 0; if (buttons & MenuInput_Back) { sfxBack(); mn_804A04F0.entering_menu = 0; - order = mnItemSw_803ED340.item_order; data = (MnItemSwData*) mnItemSw_804D6BE8->user_data; - for (i = 0; i < 0x1F; i++, order++) { - mn_8022E978(*order, data->items[i]); + for (i = 0; i < 0x1F; i++) { + mn_8022E978(mnItemSw_803ED340.item_order[i], data->items[i]); } gmMainLib_8015CC58()->item_freq = data->x21 - 1; lb_8001CE00(); @@ -263,23 +261,25 @@ void fn_80233E10(HSD_GObj* gobj) } else if (buttons & MenuInput_StartButton) { sfxForward(); switch ((s32) gm_801A4310()) { - case 1: - order = mnItemSw_803ED340.item_order; - data = (MnItemSwData*) mnItemSw_804D6BE8->user_data; - for (i = 0; i < 0x1F; i++, order++) { - mn_8022E978(*order, data->items[i]); + case 1: { + u8* order2 = mnItemSw_803ED340.item_order; + MnItemSwData* data2 = (MnItemSwData*) mnItemSw_804D6BE8->user_data; + for (i = 0; i < 0x1F; i++, order2++) { + mn_8022E978(*order2, data2->items[i]); } - gmMainLib_8015CC58()->item_freq = data->x21 - 1; + gmMainLib_8015CC58()->item_freq = data2->x21 - 1; + } lb_8001CE00(); mn_80229860(2); return; - default: - order = mnItemSw_803ED340.item_order; - data = (MnItemSwData*) mnItemSw_804D6BE8->user_data; - for (i = 0; i < 0x1F; i++, order++) { - mn_8022E978(*order, data->items[i]); + default: { + u8* order2 = mnItemSw_803ED340.item_order; + MnItemSwData* data2 = (MnItemSwData*) mnItemSw_804D6BE8->user_data; + for (i = 0; i < 0x1F; i++, order2++) { + mn_8022E978(*order2, data2->items[i]); } - gmMainLib_8015CC58()->item_freq = data->x21 - 1; + gmMainLib_8015CC58()->item_freq = data2->x21 - 1; + } lb_8001CE00(); mn_8022F4CC(); return; @@ -665,9 +665,9 @@ void fn_80234C24(HSD_GObj* gobj) if (((u16) mn_804A04F0.hovered_selection == 0x1F) || ((u16) mn_804A04F0.hovered_selection == 0x20)) { - u8* order = mnItemSw_803ED340.item_order; - s32 i = 0; MnItemSwData* dat; + s32 i = 0; + u8* order = mnItemSw_803ED340.item_order; data->x21 = (u8) mn_804A04F0.confirmed_selection; dat = (MnItemSwData*) gobj->user_data; @@ -724,15 +724,17 @@ HSD_JObj* mnItemSw_80235020(u8 arg0, MnItemSwData* arg1) HSD_GObj* mnItemSw_802351A0(s32 arg0) { - struct StaticModelDesc* mdl = &MenMainConIs_Top; - struct MnItemSwTable* tbl = &mnItemSw_803ED340; HSD_GObj* gobj; HSD_JObj* jobj; + HSD_JObj* item_jobj; MnItemSwData* user_data; - s32 i; + struct StaticModelDesc* mdl = &MenMainConIs_Top; + struct MnItemSwTable* tbl = &mnItemSw_803ED340; f32 y_spacing; - u8 cursor; + u8* order; HSD_JObj* cjobj; + s32 i; + u8 cursor; gobj = GObj_Create(6, 7, 0x80); mnItemSw_804D6BE8 = gobj; @@ -755,11 +757,9 @@ HSD_GObj* mnItemSw_802351A0(s32 arg0) user_data->menu_kind = mn_804A04F0.cur_menu; user_data->cursor = (u8) mn_804A04F0.hovered_selection; - { - u8* order = tbl->item_order; - for (i = 0; (u8) i < 0x1F; order++, i++) { - user_data->items[(u8) i] = gm_8016403C(*order); - } + order = tbl->item_order; + for (i = 0; (u8) i < 0x1F; order++, i++) { + user_data->items[(u8) i] = gm_8016403C(*order); } user_data->x21 = gmMainLib_8015CC58()->item_freq + 1; @@ -781,7 +781,7 @@ HSD_GObj* mnItemSw_802351A0(s32 arg0) HSD_JObjGetTranslationY(user_data->jobjs[4]); for (i = 0; i < 0x1F; i++) { - HSD_JObj* item_jobj = mnItemSw_80235020((u8) i, user_data); + item_jobj = mnItemSw_80235020((u8) i, user_data); if (i < 0x10) { HSD_JObjAddChild(user_data->jobjs[4], item_jobj); HSD_JObjAddTranslationY(item_jobj, y_spacing * (f32) i); diff --git a/src/melee/mn/mnmain.c b/src/melee/mn/mnmain.c index deb38f73d2..3c70c606ef 100644 --- a/src/melee/mn/mnmain.c +++ b/src/melee/mn/mnmain.c @@ -1395,8 +1395,7 @@ HSD_GObj* mn_8022B3A0(u8 state) HSD_JObj* sp48[12]; HSD_JObj* sp2C[7]; StaticModelDesc* top = &MenMainConTop_Top; - HSD_GObj* gobj; - HSD_JObj* cursor_jobj; + MenuKind menu_kind; int temp_r31; HSD_JObj* temp_r16_2; u8 hovered_selection; @@ -1405,11 +1404,10 @@ HSD_GObj* mn_8022B3A0(u8 state) AnimLoopSettings* var_r4_3; u8 option_count; u8 cur_menu; - MenuKind menu_kind; + HSD_GObj* gobj; MainMenuData* user_data; AnimLoopSettings* anim_loop; int i; - HSD_JObj* jobj; AnimLoopSettings* tmp; u8 var_r17; u32 var_r17_int; @@ -1468,6 +1466,8 @@ HSD_GObj* mn_8022B3A0(u8 state) for (i = 0; i < option_count; i++) { StaticModelDesc* top = &MenMainCursor_Top; if (mn_80229938(mn_804A04F0.cur_menu, i) != 0) { + HSD_JObj* jobj; + HSD_JObj* cursor_jobj; menu_kind = mn_804A04F0.cur_menu; var_r16_2 = mn_80229A04(menu_kind, i); HSD_JObjReqAnim(sp48[var_r16_2], var_r17_int); @@ -1482,8 +1482,12 @@ HSD_GObj* mn_8022B3A0(u8 state) jobj = sp2C[1]; HSD_JObjReqAnimAll(jobj, hovered_selection == i); HSD_JObjAnimAll(jobj); - HSD_JObjReqAnim( - jobj, mn_803EB6B0[mn_804A04F0.cur_menu].start_frame + 2 * i); + { + float offset = 2 * i; + float start_frame = + mn_803EB6B0[mn_804A04F0.cur_menu].start_frame; + HSD_JObjReqAnim(jobj, start_frame + offset); + } mn_8022F3D8(jobj, 0xC, TOBJ_MASK); mn_8022F3D8(jobj, 0xD, TOBJ_MASK); mn_8022F3D8(jobj, 0xE, TOBJ_MASK); diff --git a/src/melee/mn/mnmainrule.c b/src/melee/mn/mnmainrule.c index 75a522eb95..740c20fb47 100644 --- a/src/melee/mn/mnmainrule.c +++ b/src/melee/mn/mnmainrule.c @@ -143,7 +143,13 @@ struct mn_803EC818_t mn_803EC818[7] = { f32 mn_804D4B88 = 4.0F; f32 lbl_804D4B8C = 5.0F; f32 mn_804D4B90 = 1.0F; -u8 mn_804D4B94[4] = { 1, 0x63, 0x2B, 0 }; +/// Stock count {min, max} for the Stock Match rule item (1-99). Retail +/// .sdata has two objects here (0x804D4B94 size 0x2 and 0x804D4B96 size +/// 0x1 per symbols.txt), not one 4-byte blob. +u8 mn_StockCountLimits[2] = { 1, 0x63 }; + +/// SIS text id for the rule value label when Mode is Stock Match. +u8 mn_StockCountTextId = 0x2B; extern f32 mn_804D6BD8; extern u8* mn_804DBDFC; @@ -295,7 +301,7 @@ void fn_8022F538(HSD_GObj* arg0) return; } mn_804A04F0.confirmed_selection = - ((u8*) data)[mn_804A04F0.hovered_selection + 2]; + (&data->x2)[mn_804A04F0.hovered_selection]; return; } if ((buttons & 2) != 0) { @@ -318,17 +324,18 @@ void fn_8022F538(HSD_GObj* arg0) return; } mn_804A04F0.confirmed_selection = - ((u8*) data)[mn_804A04F0.hovered_selection + 2]; + (&data->x2)[mn_804A04F0.hovered_selection]; return; } - if (mn_804A04F0.hovered_selection == 5 || - mn_804A04F0.hovered_selection == 6) - { + if (mn_804A04F0.hovered_selection == 5) { + return; + } + if (mn_804A04F0.hovered_selection == 6) { return; } if (mn_804A04F0.hovered_selection == 1 && data->x2 == 1) { - limits = mn_804D4B94; + limits = mn_StockCountLimits; } else { limits = mn_803EC7DC[mn_804A04F0.hovered_selection]; } @@ -460,11 +467,11 @@ void mn_8022FD18(u8 arg0) HSD_JObj** jobjs; HSD_JObj* jobj; struct mn_8022FB88_arg1_t* data; - s32 i; u8* ptr0; u8* ptr1; u8* ptr2; u8* ptr3; + s32 i; struct mn_8022FB88_arg1_t* data2; u8 val; @@ -518,7 +525,6 @@ void mn_8022FD18(u8 arg0) void mn_8022FEC8(HSD_GObj* arg0, HSD_JObj* arg1, u8 arg2, u8 arg3) { struct mn_8022FB88_arg1_t* data; - HSD_JObj* digit_jobj; HSD_JObj* tens_jobj; HSD_JObj* ones_jobj; f32* frame; @@ -526,10 +532,11 @@ void mn_8022FEC8(HSD_GObj* arg0, HSD_JObj* arg1, u8 arg2, u8 arg3) struct mn_8022FEC8_jobj_ref_t* tens_ref; struct mn_8022FEC8_jobj_ref_t* ones_ref; u8* base; + HSD_JObj* digit_jobj; PAD_STACK(0x18); - data = arg0->user_data; + data = HSD_GObjGetUserData(arg0); base = mn_803EC600; switch ((s32) arg2) { case 1: @@ -576,7 +583,8 @@ void mn_8022FEC8(HSD_GObj* arg0, HSD_JObj* arg1, u8 arg2, u8 arg3) frame = NULL; if ((mn_804A04F0.buttons & 4) != 0) { if (arg2 == 0 || arg2 == 2 || arg2 == 4) { - frame = (f32*) (base + 0x170 + + u8* frame_base = base + 0x170; + frame = (f32*) (frame_base + (0xC * (base[0x1DD + (arg2 << 1)] - arg3))); } HSD_JObjReqAnimAll(arg1, *frame); @@ -632,7 +640,6 @@ void mn_80230198(HSD_GObj* gobj, HSD_JObj* jobj, u8 mode) } extern MenuKindData mn_803EB6B0[]; -extern u8 mn_804D4B96; extern struct mn_803EC818_t mn_803EC818[]; extern f32 mn_804DBE18; extern f32 mn_804DBE1C; @@ -644,24 +651,21 @@ extern s32 mn_804D6BD4; void mn_80230274(HSD_GObj* arg0, int arg1, int arg2) { - HSD_JObj* option_roots[8]; + HSD_JObj* option_roots[7]; HSD_JObj* roots[17]; - u16 indices[19]; + u16 indices[17]; u8* base; struct mn_802307F8_t* data; u8* data8; u8 count; - u8 selected; - u8 hovered; s32 i; s32 j; s32 visible; s32 valid; u16* idx; AnimLoopSettings* settings; - HSD_JObj* jobj; - PAD_STACK(0x28); + PAD_STACK(0x20); base = mn_803EC600; count = mn_803EB6B0[13].selection_count; @@ -683,12 +687,8 @@ void mn_80230274(HSD_GObj* arg0, int arg1, int arg2) indices[13] = 13; indices[14] = 14; indices[15] = 15; - i = 16; - idx = &indices[i]; - while (i < 0x11) { - *idx = i; - idx++; - i++; + for (i = 16; i < 17; i++) { + indices[i] = i; } for (i = 0; i < count; i++) { @@ -720,26 +720,25 @@ void mn_80230274(HSD_GObj* arg0, int arg1, int arg2) } if (arg1 != 0) { - selected = data->x1; + u8 selected = data->x1; + u8 hovered; lb_8001204C(option_roots[selected], roots, indices, 0x11); HSD_JObjSetFlagsAll(roots[16], JOBJ_HIDDEN); HSD_JObjSetFlagsAll(roots[13], JOBJ_HIDDEN); - jobj = roots[2]; if ((u8) (selected - 5) <= 1) { - HSD_JObjReqAnimAll(jobj, *(f32*) (base + 0x78)); + HSD_JObjReqAnimAll(roots[2], *(f32*) (base + 0x78)); } else { - HSD_JObjReqAnimAll(jobj, *(f32*) (base + 0x60)); + HSD_JObjReqAnimAll(roots[2], *(f32*) (base + 0x60)); } - HSD_JObjAnimAll(jobj); - jobj = roots[7]; + HSD_JObjAnimAll(roots[2]); if (selected == 1 && ((struct mn_8022FB88_arg1_t*) mn_804D6BD0->user_data)->x2 == 1) { - HSD_JObjReqAnim(jobj, mn_804D4B88); + HSD_JObjReqAnim(roots[7], mn_804D4B88); } else { - HSD_JObjReqAnim(jobj, *(f32*) (base + 0x10 + selected * 8)); + HSD_JObjReqAnim(roots[7], *(f32*) (base + 0x10 + selected * 8)); } - HSD_JObjAnim(jobj); + HSD_JObjAnim(roots[7]); HSD_JObjSetFlagsAll(roots[8], JOBJ_HIDDEN); hovered = mn_804A04F0.hovered_selection; @@ -832,7 +831,7 @@ void mn_802307F8(struct mn_802307F8_t* arg0, s32 arg1, s32 arg2) arg0->text = NULL; } if ((arg1 == 1) && ((u8) arg0->x2 == 1)) { - text_id = mn_804D4B96; + text_id = mn_StockCountTextId; } else if ((arg1 == 1) || (arg1 == 3) || ((u32) (arg1 - 5) <= 1U)) { text_id = mn_803EC818[arg1].x0; } else { @@ -1050,17 +1049,17 @@ s32 mn_80230D18(struct mn_802307F8_t* arg0, HSD_JObj* arg1, s8 arg2) HSD_GObj* mn_80230E38(int arg0) { - HSD_GObj* gobj; - HSD_JObj* jobj; + u8 operand_pad[4]; u16 indices[17]; HSD_JObj* roots[17]; + HSD_GObj* gobj; + HSD_JObj* jobj; StaticModelDesc** descs; AnimLoopSettings* settings; struct mn_802307F8_t* user_data; HSD_JObj* parent; u16* count_ptr; f32* cursor_frames; - u16* idx; u8* data8; u8* data_curr; u8* p; @@ -1073,32 +1072,13 @@ HSD_GObj* mn_80230E38(int arg0) s32 valid; s32 total_visible; - PAD_STACK(0x40); + PAD_STACK(0x38); mode = arg0; hovered = mn_804A04F0.hovered_selection; count = mn_803EB6B0[13].selection_count; - indices[0] = 0; - indices[1] = 1; - indices[2] = 2; - indices[3] = 3; - indices[4] = 4; - indices[5] = 5; - indices[6] = 6; - indices[7] = 7; - indices[8] = 8; - indices[9] = 9; - indices[10] = 10; - indices[11] = 11; - indices[12] = 12; - indices[13] = 13; - indices[14] = 14; - indices[15] = 15; - i = 16; - idx = &indices[i]; - while (i < 0x11) { - *idx = i; - idx++; - i++; + + for (i = 0; i < 17; i++) { + indices[i] = i; } gobj = GObj_Create(6, 7, 0x80); @@ -1221,9 +1201,12 @@ HSD_GObj* mn_80230E38(int arg0) if ((u32) (i - 5) > 1U) { jobj = HSD_JObjLoadJoint((*descs)->joint); - HSD_JObjAddAnimAll(jobj, (*descs)->animjoint, - (*descs)->matanim_joint, - (*descs)->shapeanim_joint); + { + HSD_MatAnimJoint* matanim_joint = (*descs)->matanim_joint; + HSD_JObjAddAnimAll(jobj, (*descs)->animjoint, + matanim_joint, + (*descs)->shapeanim_joint); + } HSD_JObjReqAnimAll(jobj, mn_804DBE00); HSD_JObjAnimAll(jobj); for (j = 0; j < *count_ptr; j++) { diff --git a/src/melee/mn/mnname.c b/src/melee/mn/mnname.c index 4af397f4fc..f45c39918b 100644 --- a/src/melee/mn/mnname.c +++ b/src/melee/mn/mnname.c @@ -51,6 +51,11 @@ typedef struct { HSD_ShapeAnimJoint* shapeanim_joint; } MnNameArchive; +typedef struct { + u8 cur_menu; + u8 prev_selection; +} MnNameUserDataState; + extern MnNameArchive mnName_804A06C0; extern MnNameArchive mnName_804A06D0; extern MnNameArchive mnName_804A06E0; @@ -162,18 +167,22 @@ s32 CompareNameStrings(char* str1, char* str2) return 2; } - if (mnName_StringTerminator == str2[i]) { - if (checkStringRest(&str1[i])) { - return 0; + { + char ch2 = str2[i]; + + if (mnName_StringTerminator == ch2) { + if (checkStringRest(&str1[i])) { + return 0; + } + return 1; } - return 1; - } - if ((u8) *p1 > (u8) str2[i]) { - return 1; - } - if ((u8) *p1 < (u8) str2[i]) { - return 2; + if ((u8) *p1 > (u8) ch2) { + return 1; + } + if ((u8) *p1 < (u8) ch2) { + return 2; + } } } } @@ -263,59 +272,42 @@ void CreateNameAtIndex(s32 slot) s32 mnName_SortNames(HSD_GObj* arg0) { - u8* order = mnName_NameDisplayOrder; - MnName_GObj* data = (MnName_GObj*) arg0->user_data; s32 result; + u8* pj; + u8 idx2; + char* name2; + u8* pi; + s32 i; + u8 idx1; + + arg0 = arg0->user_data; PAD_STACK(8); - if ((u8) data->gobj.p_priority == 0) { + if (arg0->p_priority == 0) { s32 i; - for (i = 0; i < 0x78; i++) { - order[i] = (u8) i; + for (i = 0; 0x78 > i; i++) { + mnName_NameDisplayOrder[i] = (u8) i; } - return i; + return; } { - s32 i; - u8* pi = mnName_NameDisplayOrder; - i = 0; + pi = mnName_NameDisplayOrder; do { - s32 j = i + 1; - u8* pj = &mnName_NameDisplayOrder[i] + 1; + s32 j; + j = i + 1; + pj = &mnName_NameDisplayOrder[i] + 1; while (j < 0x78) { - u8 idx1 = *pi; - u8 idx2 = *pj; - char* name1 = - (char*) GetPersistentNameData((s32) idx1) + 0x198; - char* name2 = - (char*) GetPersistentNameData((s32) idx2) + 0x198; - s32 e1, e2; - - if ((s8) mnName_StringTerminator == - (s8) GetPersistentNameData((s32) idx1)->namedata[0]) + char* name1; + idx1 = *pi; + idx2 = *pj; + name1 = GetPersistentNameData((s32) idx1)->namedata; + name2 = GetPersistentNameData((s32) idx2)->namedata; { - e1 = 0; - } else { - e1 = 1; - } - if (e1 != 0) { - if ((s8) mnName_StringTerminator == - (s8) GetPersistentNameData((s32) idx2)->namedata[0]) - { - e2 = 0; - } else { - e2 = 1; - } - if (e2 != 0) { - result = CompareNameStrings(name1, name2); - } else { - goto block_15; - } - } else { - block_15: + bool e1, e2; + if ((s8) mnName_StringTerminator == (s8) GetPersistentNameData((s32) idx1)->namedata[0]) { @@ -323,7 +315,7 @@ s32 mnName_SortNames(HSD_GObj* arg0) } else { e1 = 1; } - if (e1 == 0) { + if (e1 != 0) { if ((s8) mnName_StringTerminator == (s8) GetPersistentNameData((s32) idx2) ->namedata[0]) @@ -332,13 +324,13 @@ s32 mnName_SortNames(HSD_GObj* arg0) } else { e2 = 1; } - if (e2 == 0) { - result = 0; + if (e2 != 0) { + result = CompareNameStrings(name1, name2); } else { - goto block_24; + goto block_15; } } else { - block_24: + block_15: if ((s8) mnName_StringTerminator == (s8) GetPersistentNameData((s32) idx1) ->namedata[0]) @@ -348,9 +340,34 @@ s32 mnName_SortNames(HSD_GObj* arg0) e1 = 1; } if (e1 == 0) { - result = 1; + if ((s8) mnName_StringTerminator == + (s8) GetPersistentNameData((s32) idx2) + ->namedata[0]) + { + e2 = 0; + } else { + e2 = 1; + } + if (e2 == 0) { + result = 0; + } else { + goto block_24; + } } else { - result = 2; + block_24: + if ((s8) mnName_StringTerminator == + (s8) GetPersistentNameData((s32) idx1) + ->namedata[0]) + { + e1 = 0; + } else { + e1 = 1; + } + if (e1 == 0) { + result = 1; + } else { + result = 2; + } } } } @@ -519,7 +536,7 @@ void mnName_MainInput(HSD_GObj* arg0) { MnName_GObj* gobj2 = (MnName_GObj*) mnName_804D6BF8->user_data; u32 buttons = mn_80229624(4U); - s32 isFull = 0; + s32 isFull; PAD_STACK(0x20); mn_804A04F0.buttons = buttons; @@ -540,14 +557,11 @@ void mnName_MainInput(HSD_GObj* arg0) mn_804D6BC8.cooldown = 5; switch ((s32) mn_804A04F0.hovered_selection) { case 24: - if (GetNameCount_noinline() < 0x78) { - } else { - isFull = 1; - } + isFull = GetNameCount_noinline() < 0x78 ? 0 : 1; if (isFull == 0) { s32 isValid; - u8 count; s32 i; + u8 count; lbAudioAx_80024030(1); mnName_80239878(1U, (HSD_GObj*) gobj2); mnName_80238A04((HSD_GObj*) gobj2, 0x18U, 1U); @@ -575,6 +589,7 @@ void mnName_MainInput(HSD_GObj* arg0) case 25: if (mnName_GetPageCount() != 0) { lbAudioAx_80024030(1); + isFull = 0; if ((u8) gobj2->gobj.p_priority == 0) { isFull = 1; } @@ -598,15 +613,18 @@ void mnName_MainInput(HSD_GObj* arg0) default: if ((u16) mn_804A04F0.hovered_selection < 0x18U) { s32 isValid; - s32 sel = (u8) mn_804A04F0.hovered_selection; + s32 colCount; + u8 sel = (u8) mn_804A04F0.hovered_selection; s32 col = ((HSD_GObj*) mnName_804D6BF8->user_data)->gx_link + - (mn_804A04F0.hovered_selection / 6); - s32 colCount = mnName_GetColumnCount(); + (sel / 6); u8 nameIdx; + s32 idx; + colCount = mnName_GetColumnCount(); if (colCount > 4 && col >= colCount) { col -= colCount; } - nameIdx = mnName_NameDisplayOrder[col * 6 + (sel % 6)]; + idx = (sel % 6) + (col * 6); + nameIdx = mnName_NameDisplayOrder[idx]; if ((s8) mnName_StringTerminator == (s8) GetPersistentNameData((s32) nameIdx)->namedata[0]) { @@ -923,13 +941,13 @@ inline f32 mnName_80238C34_inline(HSD_JObj* jobj) void mnName_80238C34(HSD_GObj* arg0, u8 arg1, u8 arg2) { - AnimLoopSettings* base = mnName_803ED538; AnimLoopSettings** tableBase = mnName_803B8510; + AnimLoopSettings* base = mnName_803ED538; MnName_GObj* data = (MnName_GObj*) arg0->user_data; AnimLoopSettings* found; if (arg1 != 0) { - u8 prev = (u8) data->gobj.classifier; + u32 prev = ((MnNameUserDataState*) data)->prev_selection; if (prev != 0x1A || (u16) mn_804A04F0.hovered_selection >= 0x18U) { mnName_80238AE0((HSD_GObj*) data, prev, 0); } @@ -1137,7 +1155,6 @@ void mnName_80239A24(HSD_GObj* gobj) { Vec3 sp6C; GXColor sp60; - s32 i; HSD_JObj* jobj; HSD_JObj* ref_jobj; HSD_JObj* ref_jobj2; @@ -1150,6 +1167,7 @@ void mnName_80239A24(HSD_GObj* gobj) f32 row_height; f32 text_col_width; f32 text_row_height; + s32 i; MnNameArchive* archive = &mnName_804A06C0; MenuFlow* flow = &mn_804A04F0; MnName_GObj* data = (MnName_GObj*) gobj; diff --git a/src/melee/mn/mnnamenew.c b/src/melee/mn/mnnamenew.c index 5877d206af..b751cc2c66 100644 --- a/src/melee/mn/mnnamenew.c +++ b/src/melee/mn/mnnamenew.c @@ -1,5 +1,7 @@ #include "mnnamenew.h" +#include "mnnamenew.static.h" + #include "baselib/debug.h" #include "dolphin/gx/GXStruct.h" #include "gm/gm_1A3F.h" @@ -30,6 +32,30 @@ #include typedef char* GlyphRow[4]; +/// Glyph strings in the keyboard tables are read through +/// mnNameNew_NullCharacter, which this translation unit declares +/// volatile, so the tables store pointers to volatile characters. +typedef volatile char GlyphChar; + +/// Maps keyboard cursor positions to jobj indices and glyph strings. +/// Mirrors the key_jobj_ids/x34/xFC/character_bytes fields of +/// MnNameNewDataLayout (data object at 0x803EDA7C). +typedef struct MnNameNewKeyMap { + u16 key_jobj_ids[8]; + GlyphChar* x34[50]; + GlyphChar* xFC[50]; + GlyphChar* character_bytes[50]; +} MnNameNewKeyMap; + +/// Lowercase/uppercase glyph variant rows for each key. Mirrors the +/// lower_glyphs/upper_glyphs/x8CC fields of MnNameNewDataLayout (data +/// object at 0x803EDCE4). +typedef struct MnNameNewGlyphTable { + GlyphChar* lower_glyphs[50][4]; + GlyphChar* upper_glyphs[50][4]; + Vec3 x8CC; +} MnNameNewGlyphTable; + typedef struct MnNameNewDataLayout { AnimLoopSettings anim[3]; u16 key_jobj_ids[8]; @@ -55,14 +81,12 @@ extern u8 mn_804D6BB4; extern u8 mn_804D6BB5; extern u8 mnNameNew_804D4F7C[4]; extern char mnNameNew_SpaceCharacter[2]; -extern GlyphRow mnNameNew_803EDCE4[]; extern void* mnNameNew_804A06F0[]; extern void* mnNameNew_804A0700[]; extern void* mnNameNew_804A0710[]; extern void* mnNameNew_804A0720[]; extern HSD_GObj* mnNameNew_804D6C08; -extern u16 mnNameNew_803EDA7C[]; extern StaticModelDesc MenMainBack_Top; extern StaticModelDesc MenMainPanel_Top; extern HSD_CObjDesc* MenMain_cam; @@ -75,11 +99,259 @@ static AnimLoopSettings mnNameNew_803EDA58[3] = { { 0.0f, 10.0f, -0.1f }, }; -extern char** mnNameNew_803EDA8C; -extern char** mnNameNew_803EDB54; -extern char** mnNameNew_803EDC1C; -extern GlyphRow* mnNameNew_803EE004; -extern Vec3 mnNameNew_803EE324; +/// Contents restored from the target unit's .data section (symbols.txt: +/// mnNameNew_KeyMap at 0x803EDA7C size 0x268, mnNameNew_GlyphTable at +/// 0x803EDCE4 size 0x64C); see build/GALE01/asm/melee/mn/mnnamenew.s. +static MnNameNewKeyMap mnNameNew_KeyMap = { + { 3, 10, 11, 7, 9, 8, 5, 5 }, + { mnNameNew_804D4C14, mnNameNew_804D4C18, mnNameNew_804D4C1C, + mnNameNew_804D4C20, mnNameNew_804D4C24, mnNameNew_804D4C28, + mnNameNew_804D4C2C, mnNameNew_804D4C30, mnNameNew_804D4C34, + mnNameNew_804D4C38, mnNameNew_804D4C3C, mnNameNew_804D4C40, + mnNameNew_804D4C44, mnNameNew_804D4C48, mnNameNew_804D4C4C, + mnNameNew_804D4C50, mnNameNew_804D4C54, mnNameNew_804D4C58, + mnNameNew_804D4C5C, mnNameNew_804D4C60, mnNameNew_804D4C64, + mnNameNew_804D4C68, mnNameNew_804D4C6C, mnNameNew_804D4C70, + mnNameNew_804D4C74, mnNameNew_804D4C78, mnNameNew_804D4C7C, + mnNameNew_804D4C80, mnNameNew_804D4C84, mnNameNew_804D4C88, + mnNameNew_804D4C8C, mnNameNew_804D4C90, mnNameNew_804D4C94, + mnNameNew_804D4C98, mnNameNew_804D4C9C, mnNameNew_804D4CA0, + mnNameNew_804D4CA4, mnNameNew_804D4CA8, mnNameNew_SpaceCharacter, + mnNameNew_SpaceCharacter, mnNameNew_804D4CB0, mnNameNew_804D4CB4, + mnNameNew_804D4CB8, mnNameNew_804D4CBC, mnNameNew_804D4CC0, + mnNameNew_804D4CC4, mnNameNew_804D4CC8, mnNameNew_804D4CCC, + mnNameNew_804D4CD0, mnNameNew_804D4CD4 }, + { mnNameNew_804D4CD8, mnNameNew_804D4CDC, mnNameNew_804D4CE0, + mnNameNew_804D4CE4, mnNameNew_804D4CE8, mnNameNew_804D4CEC, + mnNameNew_804D4CF0, mnNameNew_804D4CF4, mnNameNew_804D4CF8, + mnNameNew_804D4CFC, mnNameNew_804D4D00, mnNameNew_804D4D04, + mnNameNew_804D4D08, mnNameNew_804D4D0C, mnNameNew_804D4D10, + mnNameNew_804D4D14, mnNameNew_804D4D18, mnNameNew_804D4D1C, + mnNameNew_804D4D20, mnNameNew_804D4D24, mnNameNew_804D4D28, + mnNameNew_804D4D2C, mnNameNew_804D4D30, mnNameNew_804D4D34, + mnNameNew_804D4D38, mnNameNew_804D4D3C, mnNameNew_804D4D40, + mnNameNew_804D4D44, mnNameNew_804D4D48, mnNameNew_804D4D4C, + mnNameNew_804D4D50, mnNameNew_804D4D54, mnNameNew_804D4D58, + mnNameNew_804D4D5C, mnNameNew_804D4D60, mnNameNew_804D4D64, + mnNameNew_804D4D68, mnNameNew_804D4D6C, mnNameNew_SpaceCharacter, + mnNameNew_SpaceCharacter, mnNameNew_804D4D70, mnNameNew_804D4D74, + mnNameNew_804D4D78, mnNameNew_804D4D7C, mnNameNew_804D4D80, + mnNameNew_804D4D84, mnNameNew_804D4D88, mnNameNew_804D4D8C, + mnNameNew_804D4CD0, mnNameNew_804D4CD4 }, + { mnNameNew_804D4D90, mnNameNew_804D4D94, + mnNameNew_SpaceCharacter, mnNameNew_804D4D98, + mnNameNew_804D4D9C, mnNameNew_804D4DA0, + mnNameNew_804D4DA4, mnNameNew_SpaceCharacter, + mnNameNew_804D4DA8, mnNameNew_804D4DAC, + mnNameNew_804D4DB0, mnNameNew_804D4DB4, + mnNameNew_SpaceCharacter, mnNameNew_804D4DB8, + mnNameNew_804D4DBC, mnNameNew_804D4DC0, + mnNameNew_804D4DC4, mnNameNew_SpaceCharacter, + mnNameNew_804D4DC8, mnNameNew_804D4DCC, + mnNameNew_804D4DD0, mnNameNew_804D4DD4, + mnNameNew_804D4DD8, mnNameNew_804D4DDC, + mnNameNew_804D4DE0, mnNameNew_804D4DE4, + mnNameNew_804D4DE8, mnNameNew_804D4DEC, + mnNameNew_804D4DF0, mnNameNew_804D4DF4, + mnNameNew_804D4DF8, mnNameNew_804D4DFC, + mnNameNew_804D4E00, mnNameNew_804D4E04, + mnNameNew_804D4E08, mnNameNew_804D4E0C, + mnNameNew_804D4E10, mnNameNew_804D4E14, + mnNameNew_804D4E18, mnNameNew_804D4E1C, + mnNameNew_804D4E20, mnNameNew_804D4E24, + mnNameNew_804D4E28, mnNameNew_804D4E2C, + mnNameNew_804D4E30, mnNameNew_804D4E34, + mnNameNew_804D4E38, mnNameNew_804D4E3C, + mnNameNew_804D4E40, mnNameNew_804D4E44 }, +}; + +static MnNameNewGlyphTable mnNameNew_GlyphTable = { + { + { mnNameNew_804D4C14, mnNameNew_804D4E48, &mnNameNew_NullCharacter, + NULL }, + { mnNameNew_804D4C18, mnNameNew_804D4E50, &mnNameNew_NullCharacter, + NULL }, + { mnNameNew_804D4C1C, mnNameNew_804D4E54, &mnNameNew_NullCharacter, + NULL }, + { mnNameNew_804D4C20, mnNameNew_804D4E58, &mnNameNew_NullCharacter, + NULL }, + { mnNameNew_804D4C24, mnNameNew_804D4E5C, &mnNameNew_NullCharacter, + NULL }, + { mnNameNew_804D4C28, mnNameNew_804D4E60, &mnNameNew_NullCharacter, + NULL }, + { mnNameNew_804D4C2C, mnNameNew_804D4E64, &mnNameNew_NullCharacter, + NULL }, + { mnNameNew_804D4C30, mnNameNew_804D4E68, &mnNameNew_NullCharacter, + NULL }, + { mnNameNew_804D4C34, mnNameNew_804D4E6C, &mnNameNew_NullCharacter, + NULL }, + { mnNameNew_804D4C38, mnNameNew_804D4E70, &mnNameNew_NullCharacter, + NULL }, + { mnNameNew_804D4C3C, mnNameNew_804D4E74, &mnNameNew_NullCharacter, + NULL }, + { mnNameNew_804D4C40, mnNameNew_804D4E78, &mnNameNew_NullCharacter, + NULL }, + { mnNameNew_804D4C44, mnNameNew_804D4E7C, &mnNameNew_NullCharacter, + NULL }, + { mnNameNew_804D4C48, mnNameNew_804D4E80, &mnNameNew_NullCharacter, + NULL }, + { mnNameNew_804D4C4C, mnNameNew_804D4E84, &mnNameNew_NullCharacter, + NULL }, + { mnNameNew_804D4C50, mnNameNew_804D4E88, &mnNameNew_NullCharacter, + NULL }, + { mnNameNew_804D4C54, mnNameNew_804D4E8C, &mnNameNew_NullCharacter, + NULL }, + { mnNameNew_804D4C58, mnNameNew_804D4E90, mnNameNew_804D4E94, + &mnNameNew_NullCharacter }, + { mnNameNew_804D4C5C, mnNameNew_804D4E98, &mnNameNew_NullCharacter, + NULL }, + { mnNameNew_804D4C60, mnNameNew_804D4E9C, &mnNameNew_NullCharacter, + NULL }, + { mnNameNew_804D4C64, &mnNameNew_NullCharacter, + &mnNameNew_NullCharacter, NULL }, + { mnNameNew_804D4C68, &mnNameNew_NullCharacter, + &mnNameNew_NullCharacter, NULL }, + { mnNameNew_804D4C6C, &mnNameNew_NullCharacter, + &mnNameNew_NullCharacter, NULL }, + { mnNameNew_804D4C70, &mnNameNew_NullCharacter, + &mnNameNew_NullCharacter, NULL }, + { mnNameNew_804D4C74, &mnNameNew_NullCharacter, + &mnNameNew_NullCharacter, NULL }, + { mnNameNew_804D4C78, mnNameNew_804D4EA0, mnNameNew_804D4EA4, + &mnNameNew_NullCharacter }, + { mnNameNew_804D4C7C, mnNameNew_804D4EA8, mnNameNew_804D4EAC, + &mnNameNew_NullCharacter }, + { mnNameNew_804D4C80, mnNameNew_804D4EB0, mnNameNew_804D4EB4, + &mnNameNew_NullCharacter }, + { mnNameNew_804D4C84, mnNameNew_804D4EB8, mnNameNew_804D4EBC, + &mnNameNew_NullCharacter }, + { mnNameNew_804D4C88, mnNameNew_804D4EC0, mnNameNew_804D4EC4, + &mnNameNew_NullCharacter }, + { mnNameNew_804D4C8C, &mnNameNew_NullCharacter, + &mnNameNew_NullCharacter, NULL }, + { mnNameNew_804D4C90, &mnNameNew_NullCharacter, + &mnNameNew_NullCharacter, NULL }, + { mnNameNew_804D4C94, &mnNameNew_NullCharacter, + &mnNameNew_NullCharacter, NULL }, + { mnNameNew_804D4C98, &mnNameNew_NullCharacter, + &mnNameNew_NullCharacter, NULL }, + { mnNameNew_804D4C9C, &mnNameNew_NullCharacter, + &mnNameNew_NullCharacter, NULL }, + { mnNameNew_804D4CA0, mnNameNew_804D4EC8, &mnNameNew_NullCharacter, + NULL }, + { mnNameNew_804D4CA4, mnNameNew_804D4ECC, &mnNameNew_NullCharacter, + NULL }, + { mnNameNew_804D4CA8, mnNameNew_804D4ED0, &mnNameNew_NullCharacter, + NULL }, + { mnNameNew_SpaceCharacter, mnNameNew_804D4ED4, + &mnNameNew_NullCharacter, NULL }, + { mnNameNew_SpaceCharacter, mnNameNew_804D4ED4, + &mnNameNew_NullCharacter, NULL }, + { mnNameNew_804D4CB0, &mnNameNew_NullCharacter, NULL, NULL }, + { mnNameNew_804D4CB4, &mnNameNew_NullCharacter, NULL, NULL }, + { mnNameNew_804D4CB8, &mnNameNew_NullCharacter, NULL, NULL }, + { mnNameNew_804D4CBC, &mnNameNew_NullCharacter, NULL, NULL }, + { mnNameNew_804D4CC0, &mnNameNew_NullCharacter, NULL, NULL }, + { mnNameNew_804D4CC4, &mnNameNew_NullCharacter, NULL, NULL }, + { mnNameNew_804D4CC8, &mnNameNew_NullCharacter, NULL, NULL }, + { mnNameNew_804D4CCC, &mnNameNew_NullCharacter, NULL, NULL }, + { mnNameNew_804D4CD0, &mnNameNew_NullCharacter, NULL, NULL }, + { mnNameNew_804D4CD4, &mnNameNew_NullCharacter, NULL, NULL }, + }, + { + { mnNameNew_804D4CD8, mnNameNew_804D4ED8, &mnNameNew_NullCharacter, + NULL }, + { mnNameNew_804D4CDC, mnNameNew_804D4EDC, &mnNameNew_NullCharacter, + NULL }, + { mnNameNew_804D4CE0, mnNameNew_804D4EE0, &mnNameNew_NullCharacter, + NULL }, + { mnNameNew_804D4CE4, mnNameNew_804D4EE4, &mnNameNew_NullCharacter, + NULL }, + { mnNameNew_804D4CE8, mnNameNew_804D4EE8, &mnNameNew_NullCharacter, + NULL }, + { mnNameNew_804D4CEC, mnNameNew_804D4EEC, &mnNameNew_NullCharacter, + NULL }, + { mnNameNew_804D4CF0, mnNameNew_804D4EF0, &mnNameNew_NullCharacter, + NULL }, + { mnNameNew_804D4CF4, mnNameNew_804D4EF4, &mnNameNew_NullCharacter, + NULL }, + { mnNameNew_804D4CF8, mnNameNew_804D4EF8, &mnNameNew_NullCharacter, + NULL }, + { mnNameNew_804D4CFC, mnNameNew_804D4EFC, &mnNameNew_NullCharacter, + NULL }, + { mnNameNew_804D4D00, mnNameNew_804D4F00, &mnNameNew_NullCharacter, + NULL }, + { mnNameNew_804D4D04, mnNameNew_804D4F04, &mnNameNew_NullCharacter, + NULL }, + { mnNameNew_804D4D08, mnNameNew_804D4F08, &mnNameNew_NullCharacter, + NULL }, + { mnNameNew_804D4D0C, mnNameNew_804D4F0C, &mnNameNew_NullCharacter, + NULL }, + { mnNameNew_804D4D10, mnNameNew_804D4F10, &mnNameNew_NullCharacter, + NULL }, + { mnNameNew_804D4D14, mnNameNew_804D4F14, &mnNameNew_NullCharacter, + NULL }, + { mnNameNew_804D4D18, mnNameNew_804D4F18, &mnNameNew_NullCharacter, + NULL }, + { mnNameNew_804D4D1C, mnNameNew_804D4F1C, mnNameNew_804D4F20, + &mnNameNew_NullCharacter }, + { mnNameNew_804D4D20, mnNameNew_804D4F24, &mnNameNew_NullCharacter, + NULL }, + { mnNameNew_804D4D24, mnNameNew_804D4F28, &mnNameNew_NullCharacter, + NULL }, + { mnNameNew_804D4D28, &mnNameNew_NullCharacter, + &mnNameNew_NullCharacter, NULL }, + { mnNameNew_804D4D2C, &mnNameNew_NullCharacter, + &mnNameNew_NullCharacter, NULL }, + { mnNameNew_804D4D30, &mnNameNew_NullCharacter, + &mnNameNew_NullCharacter, NULL }, + { mnNameNew_804D4D34, &mnNameNew_NullCharacter, + &mnNameNew_NullCharacter, NULL }, + { mnNameNew_804D4D38, &mnNameNew_NullCharacter, + &mnNameNew_NullCharacter, NULL }, + { mnNameNew_804D4D3C, mnNameNew_804D4F2C, mnNameNew_804D4F30, + &mnNameNew_NullCharacter }, + { mnNameNew_804D4D40, mnNameNew_804D4F34, mnNameNew_804D4F38, + &mnNameNew_NullCharacter }, + { mnNameNew_804D4D44, mnNameNew_804D4F3C, mnNameNew_804D4F40, + &mnNameNew_NullCharacter }, + { mnNameNew_804D4D48, mnNameNew_804D4F44, mnNameNew_804D4F48, + &mnNameNew_NullCharacter }, + { mnNameNew_804D4D4C, mnNameNew_804D4F4C, mnNameNew_804D4F50, + &mnNameNew_NullCharacter }, + { mnNameNew_804D4D50, &mnNameNew_NullCharacter, + &mnNameNew_NullCharacter, NULL }, + { mnNameNew_804D4D54, &mnNameNew_NullCharacter, + &mnNameNew_NullCharacter, NULL }, + { mnNameNew_804D4D58, &mnNameNew_NullCharacter, + &mnNameNew_NullCharacter, NULL }, + { mnNameNew_804D4D5C, &mnNameNew_NullCharacter, + &mnNameNew_NullCharacter, NULL }, + { mnNameNew_804D4D60, &mnNameNew_NullCharacter, + &mnNameNew_NullCharacter, NULL }, + { mnNameNew_804D4D64, mnNameNew_804D4F54, &mnNameNew_NullCharacter, + NULL }, + { mnNameNew_804D4D68, mnNameNew_804D4F58, &mnNameNew_NullCharacter, + NULL }, + { mnNameNew_804D4D6C, mnNameNew_804D4F5C, &mnNameNew_NullCharacter, + NULL }, + { mnNameNew_SpaceCharacter, mnNameNew_804D4ED4, + &mnNameNew_NullCharacter, NULL }, + { mnNameNew_SpaceCharacter, mnNameNew_804D4ED4, + &mnNameNew_NullCharacter, NULL }, + { mnNameNew_804D4D70, &mnNameNew_NullCharacter, NULL, NULL }, + { mnNameNew_804D4D74, &mnNameNew_NullCharacter, NULL, NULL }, + { mnNameNew_804D4D78, &mnNameNew_NullCharacter, NULL, NULL }, + { mnNameNew_804D4D7C, &mnNameNew_NullCharacter, NULL, NULL }, + { mnNameNew_804D4D80, &mnNameNew_NullCharacter, NULL, NULL }, + { mnNameNew_804D4D84, &mnNameNew_NullCharacter, NULL, NULL }, + { mnNameNew_804D4D88, &mnNameNew_NullCharacter, NULL, NULL }, + { mnNameNew_804D4D8C, &mnNameNew_NullCharacter, NULL, NULL }, + { mnNameNew_804D4F60, &mnNameNew_NullCharacter, NULL, NULL }, + { mnNameNew_804D4F64, &mnNameNew_NullCharacter, NULL, NULL }, + }, + { -0.8f, 0.4f, 0.0f }, +}; static Vec3 mnNameNew_803EE330 = { -0.7f, 0.7f, 0.0f }; @@ -202,26 +474,29 @@ extern const GXColor mnNameNew_804DBF48; s32 mnNameNew_KeySetup(NameNewEntry* arg0, u8 arg1) { - HSD_JObj* key_jobj; - HSD_JObj* ref1; - HSD_JObj* ref2; - HSD_Text* text; Vec3 sp50; GXColor sp4C; GXColor sp48; GXColor sp44; + MnNameNewDataLayout* layout; + HSD_JObj* key_jobj; + HSD_Text* text; + HSD_JObj* ref1; + HSD_JObj* ref2; char** str_table; f32 x_range; f32 y_range; + f32 pos_x; + f32 pos_y; + f32 pos_z; f32 base_x; f32 base_y; f32 font_x; f32 col_x; s32 i; GXColor* color_ptr; - MnNameNewDataLayout* layout; - FORCE_PAD_STACK(20); + FORCE_PAD_STACK(16); layout = (MnNameNewDataLayout*) mnNameNew_803EDA58; sp4C = mnNameNew_804DBF44; @@ -242,47 +517,75 @@ s32 mnNameNew_KeySetup(NameNewEntry* arg0, u8 arg1) break; } - text = arg0->key_text; - (void) text; - if (text != NULL) { - HSD_SisLib_803A5CC4(text); + if (arg0->key_text != NULL) { + HSD_SisLib_803A5CC4(arg0->key_text); } text = HSD_SisLib_803A6754(0, (s32) mn_804D6BB5); arg0->key_text = text; - key_jobj = HSD_JObjGetChild(arg0->jobjs[16]); + key_jobj = arg0->jobjs[16]; + if (key_jobj == NULL) { + key_jobj = NULL; + } else { + key_jobj = key_jobj->child; + } for (i = 0; i < 50; i++) { if (i == 0x2D) { break; } - key_jobj = HSD_JObjGetNext(key_jobj); + if (key_jobj == NULL) { + key_jobj = NULL; + } else { + key_jobj = key_jobj->next; + } } - lb_8000B1CC(key_jobj, &mnNameNew_803EE324, &sp50); - text->pos_x = sp50.x; - text->pos_y = -sp50.y; - text->pos_z = sp50.z; + lb_8000B1CC(key_jobj, &layout->x8CC, &sp50); + pos_x = sp50.x; + pos_y = -sp50.y; + pos_z = sp50.z; + text->pos_x = pos_x; + text->pos_y = pos_y; + text->pos_z = pos_z; text->font_size.x = 0.03f; text->font_size.y = 0.04f; text->text_color = mnNameNew_804D4F6C; - ref1 = HSD_JObjGetChild(arg0->jobjs[16]); + ref1 = arg0->jobjs[16]; + if (ref1 == NULL) { + ref1 = NULL; + } else { + ref1 = ref1->child; + } for (i = 0; i < 50; i++) { if (i == 0x28) { break; } - ref1 = HSD_JObjGetNext(ref1); + if (ref1 == NULL) { + ref1 = NULL; + } else { + ref1 = ref1->next; + } } base_x = HSD_JObjGetTranslationX(key_jobj); x_range = HSD_JObjGetTranslationX(ref1) - base_x; - ref2 = HSD_JObjGetChild(arg0->jobjs[16]); + ref2 = arg0->jobjs[16]; + if (ref2 == NULL) { + ref2 = NULL; + } else { + ref2 = ref2->child; + } for (i = 0; i < 50; i++) { if (i == 0x2E) { break; } - ref2 = HSD_JObjGetNext(ref2); + if (ref2 == NULL) { + ref2 = NULL; + } else { + ref2 = ref2->next; + } } base_y = HSD_JObjGetTranslationY(key_jobj); @@ -491,37 +794,45 @@ bool NameContainsOnlySpaces(void) inline void CopyCurrentNameToNametag(struct NameTagData* nametag) { - u8* text; s32 idx; - u8* ptr; + u8* text; u8 ch; + s8 null_ch; text = (u8*) mnNameNew_CurrentNameText; + null_ch = (s8) mnNameNew_NullCharacter; idx = 0; - if ((s8) mnNameNew_NullCharacter != (s8) *text) { + if (null_ch != (s8) *text) { + u8* ptr; ptr = text; - while ((s8) mnNameNew_NullCharacter != (s8) (ch = *ptr)) { + while ((null_ch = (s8) mnNameNew_NullCharacter) != (s8) (ch = *ptr)) { nametag->namedata[idx] = (s8) ch; idx += 1; ptr += 1; } - if ((s8) ch != (s8) * (text += 3)) { + if (null_ch != (s8) * (text += 3)) { ptr = text; - while ((s8) mnNameNew_NullCharacter != (s8) (ch = *ptr)) { + while ((null_ch = (s8) mnNameNew_NullCharacter) != + (s8) (ch = *ptr)) + { nametag->namedata[idx] = (s8) ch; idx += 1; ptr += 1; } - if ((s8) ch != (s8) * (text += 3)) { + if (null_ch != (s8) * (text += 3)) { ptr = text; - while ((s8) mnNameNew_NullCharacter != (s8) (ch = *ptr)) { + while ((null_ch = (s8) mnNameNew_NullCharacter) != + (s8) (ch = *ptr)) + { nametag->namedata[idx] = (s8) ch; idx += 1; ptr += 1; } - if ((s8) ch != (s8) * (text += 3)) { + if (null_ch != (s8) * (text += 3)) { ptr = text; - while ((s8) mnNameNew_NullCharacter != (s8) (ch = *ptr)) { + while ((null_ch = (s8) mnNameNew_NullCharacter) != + (s8) (ch = *ptr)) + { nametag->namedata[idx] = (s8) ch; idx += 1; ptr += 1; @@ -610,7 +921,7 @@ void mnNameNew_GlyphVariantInput(void) u16 old_hover; u8 old_sel; u8 cur_pos; - char** table; + GlyphChar** table; s32 total; s8 null_ch; @@ -657,7 +968,7 @@ void mnNameNew_GlyphVariantInput(void) return; } null_ch = (s8) mnNameNew_NullCharacter; - table = (char**) &mnNameNew_803EDCE4[data->x1]; + table = mnNameNew_GlyphTable.lower_glyphs[data->x1]; while (null_ch != (s8) * *table) { table++; count++; @@ -711,7 +1022,7 @@ void mnNameNew_MainInput(HSD_GObj* arg0) s32 key_off; u8* key_char; s8 null_char; - u8* src; + char* src; u8* dest; s32 len; u8 cursor; @@ -720,7 +1031,10 @@ void mnNameNew_MainInput(HSD_GObj* arg0) PAD_STACK(12); name_text = mnNameNew_CurrentNameText; - data = ((HSD_GObj*) mnNameNew_804D6C08)->user_data; + { + NameNewEntry* entry = ((HSD_GObj*) mnNameNew_804D6C08)->user_data; + data = entry; + } layout = (MnNameNewDataLayout*) mnNameNew_803EDA58; if (data->variant_gobj != NULL) { @@ -893,40 +1207,41 @@ void mnNameNew_MainInput(HSD_GObj* arg0) len = 0; { - char* src_base = name_text; - u8* dest_base = dest; - char* src_iter = src_base; - u8* dest_iter = dest_base; + char* src_iter; + u8* dest_iter; + src = name_text; + src_iter = src; + dest_iter = dest; for (; (s8) mnNameNew_NullCharacter != (s8) *src_iter; - src_iter++, dest_iter++, dest_base++, len++) + dest_iter++, dest++, len++, src_iter++) { *dest_iter = *src_iter; } - src_base += 3; - src_iter = src_base; - dest_iter = dest_base; + src += 3; + src_iter = src; + dest_iter = dest; for (; (s8) mnNameNew_NullCharacter != (s8) *src_iter; - src_iter++, dest_iter++, dest_base++, len++) + dest_iter++, dest++, len++, src_iter++) { *dest_iter = *src_iter; } - src_base += 3; - src_iter = src_base; - dest_iter = dest_base; + src += 3; + src_iter = src; + dest_iter = dest; for (; (s8) mnNameNew_NullCharacter != (s8) *src_iter; - src_iter++, dest_iter++, dest_base++, len++) + dest_iter++, dest++, len++, src_iter++) { *dest_iter = *src_iter; } - src_base += 3; - src_iter = src_base; - dest_iter = dest_base; + src += 3; + src_iter = src; + dest_iter = dest; for (; (s8) mnNameNew_NullCharacter != (s8) *src_iter; - src_iter++, dest_iter++, dest_base++, len++) + dest_iter++, dest++, len++, src_iter++) { *dest_iter = *src_iter; } @@ -949,7 +1264,10 @@ void mnNameNew_MainInput(HSD_GObj* arg0) } if (n != 0) { lbAudioAx_80024030(1); - CreateNameAtIndex((s32) data->name_index); + { + u8 name_index = data->name_index; + CreateNameAtIndex((s32) name_index); + } WriteCharactersForNameAtIndex(data->name_index, (s32) mn_802295AC()); mnNameNew_8023B224(1U); @@ -968,40 +1286,41 @@ void mnNameNew_MainInput(HSD_GObj* arg0) len = 0; { - char* src_base = name_text; - u8* dest_base = dest; - char* src_iter = src_base; - u8* dest_iter = dest_base; + char* src_iter; + u8* dest_iter; + src = name_text; + src_iter = src; + dest_iter = dest; for (; (s8) mnNameNew_NullCharacter != (s8) *src_iter; - src_iter++, dest_iter++, dest_base++, len++) + dest_iter++, dest++, len++, src_iter++) { *dest_iter = *src_iter; } - src_base += 3; - src_iter = src_base; - dest_iter = dest_base; + src += 3; + src_iter = src; + dest_iter = dest; for (; (s8) mnNameNew_NullCharacter != (s8) *src_iter; - src_iter++, dest_iter++, dest_base++, len++) + dest_iter++, dest++, len++, src_iter++) { *dest_iter = *src_iter; } - src_base += 3; - src_iter = src_base; - dest_iter = dest_base; + src += 3; + src_iter = src; + dest_iter = dest; for (; (s8) mnNameNew_NullCharacter != (s8) *src_iter; - src_iter++, dest_iter++, dest_base++, len++) + dest_iter++, dest++, len++, src_iter++) { *dest_iter = *src_iter; } - src_base += 3; - src_iter = src_base; - dest_iter = dest_base; + src += 3; + src_iter = src; + dest_iter = dest; for (; (s8) mnNameNew_NullCharacter != (s8) *src_iter; - src_iter++, dest_iter++, dest_base++, len++) + dest_iter++, dest++, len++, src_iter++) { *dest_iter = *src_iter; } @@ -1107,45 +1426,16 @@ void mnNameNew_MainInput(HSD_GObj* arg0) } #pragma pop -static char mnNameNew_803EE35C[] = "Can't get user_data.\n"; -static char mnNameNew_803EE374[] = "mnnamenew.c"; -static char mnNameNew_803EE380[] = "user_data"; -static char mnNameNew_803EE38C[] = "MenMainBack_Top_joint"; -static char mnNameNew_803EE3A4[] = "MenMainBack_Top_animjoint"; -static char mnNameNew_803EE3C0[] = "MenMainBack_Top_matanim_joint"; -static char mnNameNew_803EE3E0[] = "MenMainBack_Top_shapeanim_joint"; -static char mnNameNew_803EE400[] = "ScMenMain_cam_int1_camera"; -static char mnNameNew_803EE41C[] = "ScMenMain_scene_lights"; -static char mnNameNew_803EE434[] = "ScMenMain_fog"; -static char mnNameNew_803EE444[] = "MenMainPanel_Top_joint"; -static char mnNameNew_803EE45C[] = "MenMainPanel_Top_animjoint"; -static char mnNameNew_803EE478[] = "MenMainPanel_Top_matanim_joint"; -static char mnNameNew_803EE498[] = "MenMainPanel_Top_shapeanim_joint"; -static char mnNameNew_803EE4BC[] = "MenMainConEtNw_Top_joint"; -static char mnNameNew_803EE4D8[] = "MenMainConEtNw_Top_animjoint"; -static char mnNameNew_803EE4F8[] = "MenMainConEtNw_Top_matanim_joint"; -static char mnNameNew_803EE51C[] = "MenMainConEtNw_Top_shapeanim_joint"; -static char mnNameNew_803EE540[] = "MenMainBaseEtNw_Top_joint"; -static char mnNameNew_803EE55C[] = "MenMainBaseEtNw_Top_animjoint"; -static char mnNameNew_803EE57C[] = "MenMainBaseEtNw_Top_matanim_joint"; -static char mnNameNew_803EE5A0[] = "MenMainBaseEtNw_Top_shapeanim_joint"; -static char mnNameNew_803EE5C4[] = "MenMainSubEtNw_Top_joint"; -static char mnNameNew_803EE5E0[] = "MenMainSubEtNw_Top_animjoint"; -static char mnNameNew_803EE600[] = "MenMainSubEtNw_Top_matanim_joint"; -static char mnNameNew_803EE624[] = "MenMainSubEtNw_Top_shapeanim_joint"; -static char mnNameNew_803EE648[] = "MenMainSbaseEtNw_Top_joint"; -static char mnNameNew_803EE664[] = "MenMainSbaseEtNw_Top_animjoint"; -static char mnNameNew_803EE684[] = "MenMainSbaseEtNw_Top_matanim_joint"; -static char mnNameNew_803EE6A8[] = "MenMainSbaseEtNw_Top_shapeanim_joint"; -static char mnNameNew_803EE6D0[] = "mnNameAutoNameUs"; -static char mnNameNew_803EE6E4[] = "mnNameRefuseNameUs"; -static char mnNameNew_803EE6F8[] = "mnNameAutoName"; -static char mnNameNew_803EE708[] = "mnNameRefuseName"; +static inline NameNewEntry* mnNameNew_GetEntryData(void) +{ + return mnNameNew_804D6C08->user_data; +} void mnNameNew_8023CE4C(void) { Vec3 sp24; GXColor name_char_color; + GXColor* name_char_color_ptr; NameNewEntry* data; HSD_JObj* jobj_a; HSD_JObj* jobj_b; @@ -1153,14 +1443,13 @@ void mnNameNew_8023CE4C(void) float y_minus; f32 char_spacing; f32 first_x; - GXColor* name_char_color_ptr; - char* name_ptr; s32 i; HSD_Text* text; + f32 z; PAD_STACK(4); - data = ((HSD_GObj*) mnNameNew_804D6C08)->user_data; + data = mnNameNew_GetEntryData(); jobj_a = data->jobjs[14]; jobj_b = data->jobjs[15]; first_x = HSD_JObjGetTranslationX(jobj_a); @@ -1170,25 +1459,26 @@ void mnNameNew_8023CE4C(void) } text = HSD_SisLib_803A6754(0, mn_804D6BB5); lb_8000B1CC(jobj_a, &mnNameNew_803EE330, &sp24); - name_ptr = mnNameNew_CurrentNameText; y_minus = -sp24.y; + z = sp24.z; name_char_color_ptr = &name_char_color; text->pos_x = sp24.x; i = 0; text->pos_y = y_minus; - text->pos_z = sp24.z; + text->pos_z = z; text->font_size.x = 0.04f; text->font_size.y = 0.05f; text->text_color = mnNameNew_804D4F6C; for (; i < 4; i++) { - if ((s8) mnNameNew_NullCharacter == (s8) *name_ptr) { + if ((s8) mnNameNew_NullCharacter == + (s8) mnNameNew_CurrentNameText[i * 3]) + { break; } HSD_SisLib_803A6B98(text, (char_spacing * (f32) i) / text->font_size.x, - 0.0f, name_ptr); + 0.0f, &mnNameNew_CurrentNameText[i * 3]); name_char_color = mnNameNew_804D4F78; HSD_SisLib_803A74F0(text, i, name_char_color_ptr); - name_ptr += 3; } data->name_disp_text = text; } @@ -1264,8 +1554,6 @@ void fn_8023D0F8(void* arg0) s32 mnNameNew_8023D130(GlyphVariantEntry* arg0, u8 arg1, u8 arg2, s32 arg3) { - Vec3 sp30; - GXColor sp2C; HSD_JObj* jobj14; HSD_JObj* jobj1C; HSD_JObj* jobj18; @@ -1282,18 +1570,20 @@ s32 mnNameNew_8023D130(GlyphVariantEntry* arg0, u8 arg1, u8 arg2, s32 arg3) f32 pos_z; char** table_upper; char** table_lower; - GXColor* sp2C_ptr; + GXColor* glyph_color_ptr; MnNameNewDataLayout* layout; + Vec3 text_pos; + GXColor glyph_color; layout = (MnNameNewDataLayout*) mnNameNew_803EDA58; text = HSD_SisLib_803A6754(0, (s32) mn_804D6BB4); jobj14 = arg0->jobjs[4]; jobj18 = arg0->jobjs[5]; jobj1C = arg0->jobjs[6]; - lb_8000B1CC(jobj14, &layout->x8CC, &sp30); - pos_x = sp30.x; - pos_y = -sp30.y; - pos_z = sp30.z; + lb_8000B1CC(jobj14, &layout->x8CC, &text_pos); + pos_x = text_pos.x; + pos_y = -text_pos.y; + pos_z = text_pos.z; text->pos_x = pos_x; text->pos_y = pos_y; text->pos_z = pos_z; @@ -1332,9 +1622,9 @@ s32 mnNameNew_8023D130(GlyphVariantEntry* arg0, u8 arg1, u8 arg2, s32 arg3) } else { color_ptr = &mnNameNew_804D4F74; } - sp2C = *color_ptr; - sp2C_ptr = &sp2C; - HSD_SisLib_803A74F0(text, i, sp2C_ptr); + glyph_color = *color_ptr; + glyph_color_ptr = &glyph_color; + HSD_SisLib_803A74F0(text, i, glyph_color_ptr); } arg0->text = text; return (s32) text; @@ -1342,6 +1632,17 @@ s32 mnNameNew_8023D130(GlyphVariantEntry* arg0, u8 arg1, u8 arg2, s32 arg3) extern const Vec3 mnNameNew_803B8528; +static inline void +mnNameNew_GlyphVariantSetup_InitJobjs(GlyphVariantEntry* user_data, + HSD_JObj* jobj) +{ + s32 i; + + for (i = 0; i < 7; i++) { + lb_80011E24(jobj, &user_data->jobjs[i], i, -1); + } +} + s32 mnNameNew_GlyphVariantSetup(NameNewEntry* arg0, u16 arg1, u8 arg2) { f32 base_y; @@ -1379,10 +1680,7 @@ s32 mnNameNew_GlyphVariantSetup(NameNewEntry* arg0, u16 arg1, u8 arg2) GObj_InitUserData(gobj, 0U, fn_8023D0F8, user_data); user_data->selection = mn_804A04F0.confirmed_selection; - i = 0; - for (; i < 7; i++) { - lb_80011E24(jobj, &user_data->jobjs[i], i, -1); - } + mnNameNew_GlyphVariantSetup_InitJobjs(user_data, jobj); sp2C = mnNameNew_803B8528; @@ -1391,10 +1689,14 @@ s32 mnNameNew_GlyphVariantSetup(NameNewEntry* arg0, u16 arg1, u8 arg2) } else { key_jobj = HSD_JObjGetChild(arg0->jobjs[16]); for (i = 0; i < 50; i++) { - if ((s32) arg2 == i) { + if (i == (s32) arg2) { break; } - key_jobj = HSD_JObjGetNext(key_jobj); + if (key_jobj == NULL) { + key_jobj = NULL; + } else { + key_jobj = key_jobj->next; + } } } @@ -1416,7 +1718,7 @@ s32 mnNameNew_GlyphVariantSetup(NameNewEntry* arg0, u16 arg1, u8 arg2) variant = HSD_JObjLoadJoint(variant_desc[0]); HSD_JObjAddAnimAll(variant, variant_desc[1], variant_desc[2], variant_desc[3]); - HSD_JObjReqAnimAll(variant, (f32) (i == user_data->selection)); + HSD_JObjReqAnimAll(variant, (f32) (user_data->selection == i)); HSD_JObjAnimAll(variant); HSD_JObjSetTranslateX(variant, dx * (f32) (i / 2)); HSD_JObjSetTranslateY(variant, dy * (f32) (i % 2)); @@ -1427,6 +1729,11 @@ s32 mnNameNew_GlyphVariantSetup(NameNewEntry* arg0, u16 arg1, u8 arg2) return (s32) gobj; } +static inline f32* fn_8023DAEC_inline_end_frame(MnNameNewDataLayout* layout) +{ + return &layout->anim[1].end_frame; +} + s32 mnNameNew_8023DA08(NameNewEntry* arg0) { AnimLoopSettings* anim; @@ -1467,7 +1774,7 @@ void fn_8023DAEC(HSD_GObj* arg0) data = arg0->user_data; layout = (MnNameNewDataLayout*) mnNameNew_803EDA58; - end_frame = &layout->anim[1].end_frame; + end_frame = fn_8023DAEC_inline_end_frame(layout); if (data->key_text != NULL) { HSD_SisLib_803A5CC4(data->key_text); data->key_text = NULL; @@ -1534,7 +1841,7 @@ void fn_8023DBE8(HSD_GObj* arg0) if ((s32) cursor != (s32) mn_804A04F0.hovered_selection) { if (cursor >= 0x32U && cursor < 0x3AU) { - jobj = data->jobjs[mnNameNew_803EDA7C[cursor - 0x32]]; + jobj = data->jobjs[mnNameNew_KeyMap.key_jobj_ids[cursor - 0x32]]; } else { parent = data->jobjs[16]; if (parent == NULL) { @@ -1564,7 +1871,7 @@ void fn_8023DBE8(HSD_GObj* arg0) sel = (u8) mn_804A04F0.hovered_selection; if (sel >= 0x32U && sel < 0x3AU) { - jobj = data->jobjs[mnNameNew_803EDA7C[sel - 0x32]]; + jobj = data->jobjs[mnNameNew_KeyMap.key_jobj_ids[sel - 0x32]]; } else { parent = data->jobjs[16]; if (parent == NULL) { @@ -1596,9 +1903,10 @@ void fn_8023DBE8(HSD_GObj* arg0) mnNameNew_8023B0F8(arg0, data->x1); } - frame = mn_8022F298(data->jobjs[13]); - cursor = data->cursor_pos; - if (frame != (mnNameNew_804D4C10 + (f32) cursor)) { + if ((mnNameNew_804D4C10 + (f32) data->cursor_pos) != + mn_8022F298(data->jobjs[13])) + { + cursor = data->cursor_pos; jobj = ((NameNewEntry*) arg0->user_data)->jobjs[13]; HSD_JObjReqAnimAll(jobj, mnNameNew_804D4C10 + (f32) cursor); HSD_JObjAnimAll(jobj); diff --git a/src/melee/mn/mnnamenew.static.h b/src/melee/mn/mnnamenew.static.h new file mode 100644 index 0000000000..c8879830f7 --- /dev/null +++ b/src/melee/mn/mnnamenew.static.h @@ -0,0 +1,221 @@ +#ifndef __GALE01_23B0F8_STATIC +#define __GALE01_23B0F8_STATIC + +#include "mnnamenew.h" // IWYU pragma: export + +/// Two-byte Shift-JIS glyph strings for the name-entry keyboard +/// (.sdata block owned by this translation unit; see symbols.txt +/// 0x804D4C14..0x804D4F78). +/* 4D4C14 */ extern char mnNameNew_804D4C14[]; +/* 4D4C18 */ extern char mnNameNew_804D4C18[]; +/* 4D4C1C */ extern char mnNameNew_804D4C1C[]; +/* 4D4C20 */ extern char mnNameNew_804D4C20[]; +/* 4D4C24 */ extern char mnNameNew_804D4C24[]; +/* 4D4C28 */ extern char mnNameNew_804D4C28[]; +/* 4D4C2C */ extern char mnNameNew_804D4C2C[]; +/* 4D4C30 */ extern char mnNameNew_804D4C30[]; +/* 4D4C34 */ extern char mnNameNew_804D4C34[]; +/* 4D4C38 */ extern char mnNameNew_804D4C38[]; +/* 4D4C3C */ extern char mnNameNew_804D4C3C[]; +/* 4D4C40 */ extern char mnNameNew_804D4C40[]; +/* 4D4C44 */ extern char mnNameNew_804D4C44[]; +/* 4D4C48 */ extern char mnNameNew_804D4C48[]; +/* 4D4C4C */ extern char mnNameNew_804D4C4C[]; +/* 4D4C50 */ extern char mnNameNew_804D4C50[]; +/* 4D4C54 */ extern char mnNameNew_804D4C54[]; +/* 4D4C58 */ extern char mnNameNew_804D4C58[]; +/* 4D4C5C */ extern char mnNameNew_804D4C5C[]; +/* 4D4C60 */ extern char mnNameNew_804D4C60[]; +/* 4D4C64 */ extern char mnNameNew_804D4C64[]; +/* 4D4C68 */ extern char mnNameNew_804D4C68[]; +/* 4D4C6C */ extern char mnNameNew_804D4C6C[]; +/* 4D4C70 */ extern char mnNameNew_804D4C70[]; +/* 4D4C74 */ extern char mnNameNew_804D4C74[]; +/* 4D4C78 */ extern char mnNameNew_804D4C78[]; +/* 4D4C7C */ extern char mnNameNew_804D4C7C[]; +/* 4D4C80 */ extern char mnNameNew_804D4C80[]; +/* 4D4C84 */ extern char mnNameNew_804D4C84[]; +/* 4D4C88 */ extern char mnNameNew_804D4C88[]; +/* 4D4C8C */ extern char mnNameNew_804D4C8C[]; +/* 4D4C90 */ extern char mnNameNew_804D4C90[]; +/* 4D4C94 */ extern char mnNameNew_804D4C94[]; +/* 4D4C98 */ extern char mnNameNew_804D4C98[]; +/* 4D4C9C */ extern char mnNameNew_804D4C9C[]; +/* 4D4CA0 */ extern char mnNameNew_804D4CA0[]; +/* 4D4CA4 */ extern char mnNameNew_804D4CA4[]; +/* 4D4CA8 */ extern char mnNameNew_804D4CA8[]; +/* 4D4CB0 */ extern char mnNameNew_804D4CB0[]; +/* 4D4CB4 */ extern char mnNameNew_804D4CB4[]; +/* 4D4CB8 */ extern char mnNameNew_804D4CB8[]; +/* 4D4CBC */ extern char mnNameNew_804D4CBC[]; +/* 4D4CC0 */ extern char mnNameNew_804D4CC0[]; +/* 4D4CC4 */ extern char mnNameNew_804D4CC4[]; +/* 4D4CC8 */ extern char mnNameNew_804D4CC8[]; +/* 4D4CCC */ extern char mnNameNew_804D4CCC[]; +/* 4D4CD0 */ extern char mnNameNew_804D4CD0[]; +/* 4D4CD4 */ extern char mnNameNew_804D4CD4[]; +/* 4D4CD8 */ extern char mnNameNew_804D4CD8[]; +/* 4D4CDC */ extern char mnNameNew_804D4CDC[]; +/* 4D4CE0 */ extern char mnNameNew_804D4CE0[]; +/* 4D4CE4 */ extern char mnNameNew_804D4CE4[]; +/* 4D4CE8 */ extern char mnNameNew_804D4CE8[]; +/* 4D4CEC */ extern char mnNameNew_804D4CEC[]; +/* 4D4CF0 */ extern char mnNameNew_804D4CF0[]; +/* 4D4CF4 */ extern char mnNameNew_804D4CF4[]; +/* 4D4CF8 */ extern char mnNameNew_804D4CF8[]; +/* 4D4CFC */ extern char mnNameNew_804D4CFC[]; +/* 4D4D00 */ extern char mnNameNew_804D4D00[]; +/* 4D4D04 */ extern char mnNameNew_804D4D04[]; +/* 4D4D08 */ extern char mnNameNew_804D4D08[]; +/* 4D4D0C */ extern char mnNameNew_804D4D0C[]; +/* 4D4D10 */ extern char mnNameNew_804D4D10[]; +/* 4D4D14 */ extern char mnNameNew_804D4D14[]; +/* 4D4D18 */ extern char mnNameNew_804D4D18[]; +/* 4D4D1C */ extern char mnNameNew_804D4D1C[]; +/* 4D4D20 */ extern char mnNameNew_804D4D20[]; +/* 4D4D24 */ extern char mnNameNew_804D4D24[]; +/* 4D4D28 */ extern char mnNameNew_804D4D28[]; +/* 4D4D2C */ extern char mnNameNew_804D4D2C[]; +/* 4D4D30 */ extern char mnNameNew_804D4D30[]; +/* 4D4D34 */ extern char mnNameNew_804D4D34[]; +/* 4D4D38 */ extern char mnNameNew_804D4D38[]; +/* 4D4D3C */ extern char mnNameNew_804D4D3C[]; +/* 4D4D40 */ extern char mnNameNew_804D4D40[]; +/* 4D4D44 */ extern char mnNameNew_804D4D44[]; +/* 4D4D48 */ extern char mnNameNew_804D4D48[]; +/* 4D4D4C */ extern char mnNameNew_804D4D4C[]; +/* 4D4D50 */ extern char mnNameNew_804D4D50[]; +/* 4D4D54 */ extern char mnNameNew_804D4D54[]; +/* 4D4D58 */ extern char mnNameNew_804D4D58[]; +/* 4D4D5C */ extern char mnNameNew_804D4D5C[]; +/* 4D4D60 */ extern char mnNameNew_804D4D60[]; +/* 4D4D64 */ extern char mnNameNew_804D4D64[]; +/* 4D4D68 */ extern char mnNameNew_804D4D68[]; +/* 4D4D6C */ extern char mnNameNew_804D4D6C[]; +/* 4D4D70 */ extern char mnNameNew_804D4D70[]; +/* 4D4D74 */ extern char mnNameNew_804D4D74[]; +/* 4D4D78 */ extern char mnNameNew_804D4D78[]; +/* 4D4D7C */ extern char mnNameNew_804D4D7C[]; +/* 4D4D80 */ extern char mnNameNew_804D4D80[]; +/* 4D4D84 */ extern char mnNameNew_804D4D84[]; +/* 4D4D88 */ extern char mnNameNew_804D4D88[]; +/* 4D4D8C */ extern char mnNameNew_804D4D8C[]; +/* 4D4D90 */ extern char mnNameNew_804D4D90[]; +/* 4D4D94 */ extern char mnNameNew_804D4D94[]; +/* 4D4D98 */ extern char mnNameNew_804D4D98[]; +/* 4D4D9C */ extern char mnNameNew_804D4D9C[]; +/* 4D4DA0 */ extern char mnNameNew_804D4DA0[]; +/* 4D4DA4 */ extern char mnNameNew_804D4DA4[]; +/* 4D4DA8 */ extern char mnNameNew_804D4DA8[]; +/* 4D4DAC */ extern char mnNameNew_804D4DAC[]; +/* 4D4DB0 */ extern char mnNameNew_804D4DB0[]; +/* 4D4DB4 */ extern char mnNameNew_804D4DB4[]; +/* 4D4DB8 */ extern char mnNameNew_804D4DB8[]; +/* 4D4DBC */ extern char mnNameNew_804D4DBC[]; +/* 4D4DC0 */ extern char mnNameNew_804D4DC0[]; +/* 4D4DC4 */ extern char mnNameNew_804D4DC4[]; +/* 4D4DC8 */ extern char mnNameNew_804D4DC8[]; +/* 4D4DCC */ extern char mnNameNew_804D4DCC[]; +/* 4D4DD0 */ extern char mnNameNew_804D4DD0[]; +/* 4D4DD4 */ extern char mnNameNew_804D4DD4[]; +/* 4D4DD8 */ extern char mnNameNew_804D4DD8[]; +/* 4D4DDC */ extern char mnNameNew_804D4DDC[]; +/* 4D4DE0 */ extern char mnNameNew_804D4DE0[]; +/* 4D4DE4 */ extern char mnNameNew_804D4DE4[]; +/* 4D4DE8 */ extern char mnNameNew_804D4DE8[]; +/* 4D4DEC */ extern char mnNameNew_804D4DEC[]; +/* 4D4DF0 */ extern char mnNameNew_804D4DF0[]; +/* 4D4DF4 */ extern char mnNameNew_804D4DF4[]; +/* 4D4DF8 */ extern char mnNameNew_804D4DF8[]; +/* 4D4DFC */ extern char mnNameNew_804D4DFC[]; +/* 4D4E00 */ extern char mnNameNew_804D4E00[]; +/* 4D4E04 */ extern char mnNameNew_804D4E04[]; +/* 4D4E08 */ extern char mnNameNew_804D4E08[]; +/* 4D4E0C */ extern char mnNameNew_804D4E0C[]; +/* 4D4E10 */ extern char mnNameNew_804D4E10[]; +/* 4D4E14 */ extern char mnNameNew_804D4E14[]; +/* 4D4E18 */ extern char mnNameNew_804D4E18[]; +/* 4D4E1C */ extern char mnNameNew_804D4E1C[]; +/* 4D4E20 */ extern char mnNameNew_804D4E20[]; +/* 4D4E24 */ extern char mnNameNew_804D4E24[]; +/* 4D4E28 */ extern char mnNameNew_804D4E28[]; +/* 4D4E2C */ extern char mnNameNew_804D4E2C[]; +/* 4D4E30 */ extern char mnNameNew_804D4E30[]; +/* 4D4E34 */ extern char mnNameNew_804D4E34[]; +/* 4D4E38 */ extern char mnNameNew_804D4E38[]; +/* 4D4E3C */ extern char mnNameNew_804D4E3C[]; +/* 4D4E40 */ extern char mnNameNew_804D4E40[]; +/* 4D4E44 */ extern char mnNameNew_804D4E44[]; +/* 4D4E48 */ extern char mnNameNew_804D4E48[]; +/* 4D4E50 */ extern char mnNameNew_804D4E50[]; +/* 4D4E54 */ extern char mnNameNew_804D4E54[]; +/* 4D4E58 */ extern char mnNameNew_804D4E58[]; +/* 4D4E5C */ extern char mnNameNew_804D4E5C[]; +/* 4D4E60 */ extern char mnNameNew_804D4E60[]; +/* 4D4E64 */ extern char mnNameNew_804D4E64[]; +/* 4D4E68 */ extern char mnNameNew_804D4E68[]; +/* 4D4E6C */ extern char mnNameNew_804D4E6C[]; +/* 4D4E70 */ extern char mnNameNew_804D4E70[]; +/* 4D4E74 */ extern char mnNameNew_804D4E74[]; +/* 4D4E78 */ extern char mnNameNew_804D4E78[]; +/* 4D4E7C */ extern char mnNameNew_804D4E7C[]; +/* 4D4E80 */ extern char mnNameNew_804D4E80[]; +/* 4D4E84 */ extern char mnNameNew_804D4E84[]; +/* 4D4E88 */ extern char mnNameNew_804D4E88[]; +/* 4D4E8C */ extern char mnNameNew_804D4E8C[]; +/* 4D4E90 */ extern char mnNameNew_804D4E90[]; +/* 4D4E94 */ extern char mnNameNew_804D4E94[]; +/* 4D4E98 */ extern char mnNameNew_804D4E98[]; +/* 4D4E9C */ extern char mnNameNew_804D4E9C[]; +/* 4D4EA0 */ extern char mnNameNew_804D4EA0[]; +/* 4D4EA4 */ extern char mnNameNew_804D4EA4[]; +/* 4D4EA8 */ extern char mnNameNew_804D4EA8[]; +/* 4D4EAC */ extern char mnNameNew_804D4EAC[]; +/* 4D4EB0 */ extern char mnNameNew_804D4EB0[]; +/* 4D4EB4 */ extern char mnNameNew_804D4EB4[]; +/* 4D4EB8 */ extern char mnNameNew_804D4EB8[]; +/* 4D4EBC */ extern char mnNameNew_804D4EBC[]; +/* 4D4EC0 */ extern char mnNameNew_804D4EC0[]; +/* 4D4EC4 */ extern char mnNameNew_804D4EC4[]; +/* 4D4EC8 */ extern char mnNameNew_804D4EC8[]; +/* 4D4ECC */ extern char mnNameNew_804D4ECC[]; +/* 4D4ED0 */ extern char mnNameNew_804D4ED0[]; +/* 4D4ED4 */ extern char mnNameNew_804D4ED4[]; +/* 4D4ED8 */ extern char mnNameNew_804D4ED8[]; +/* 4D4EDC */ extern char mnNameNew_804D4EDC[]; +/* 4D4EE0 */ extern char mnNameNew_804D4EE0[]; +/* 4D4EE4 */ extern char mnNameNew_804D4EE4[]; +/* 4D4EE8 */ extern char mnNameNew_804D4EE8[]; +/* 4D4EEC */ extern char mnNameNew_804D4EEC[]; +/* 4D4EF0 */ extern char mnNameNew_804D4EF0[]; +/* 4D4EF4 */ extern char mnNameNew_804D4EF4[]; +/* 4D4EF8 */ extern char mnNameNew_804D4EF8[]; +/* 4D4EFC */ extern char mnNameNew_804D4EFC[]; +/* 4D4F00 */ extern char mnNameNew_804D4F00[]; +/* 4D4F04 */ extern char mnNameNew_804D4F04[]; +/* 4D4F08 */ extern char mnNameNew_804D4F08[]; +/* 4D4F0C */ extern char mnNameNew_804D4F0C[]; +/* 4D4F10 */ extern char mnNameNew_804D4F10[]; +/* 4D4F14 */ extern char mnNameNew_804D4F14[]; +/* 4D4F18 */ extern char mnNameNew_804D4F18[]; +/* 4D4F1C */ extern char mnNameNew_804D4F1C[]; +/* 4D4F20 */ extern char mnNameNew_804D4F20[]; +/* 4D4F24 */ extern char mnNameNew_804D4F24[]; +/* 4D4F28 */ extern char mnNameNew_804D4F28[]; +/* 4D4F2C */ extern char mnNameNew_804D4F2C[]; +/* 4D4F30 */ extern char mnNameNew_804D4F30[]; +/* 4D4F34 */ extern char mnNameNew_804D4F34[]; +/* 4D4F38 */ extern char mnNameNew_804D4F38[]; +/* 4D4F3C */ extern char mnNameNew_804D4F3C[]; +/* 4D4F40 */ extern char mnNameNew_804D4F40[]; +/* 4D4F44 */ extern char mnNameNew_804D4F44[]; +/* 4D4F48 */ extern char mnNameNew_804D4F48[]; +/* 4D4F4C */ extern char mnNameNew_804D4F4C[]; +/* 4D4F50 */ extern char mnNameNew_804D4F50[]; +/* 4D4F54 */ extern char mnNameNew_804D4F54[]; +/* 4D4F58 */ extern char mnNameNew_804D4F58[]; +/* 4D4F5C */ extern char mnNameNew_804D4F5C[]; +/* 4D4F60 */ extern char mnNameNew_804D4F60[]; +/* 4D4F64 */ extern char mnNameNew_804D4F64[]; + +#endif diff --git a/src/melee/mn/mnruleplus.c b/src/melee/mn/mnruleplus.c index 79e2f74072..4a4fbf45fa 100644 --- a/src/melee/mn/mnruleplus.c +++ b/src/melee/mn/mnruleplus.c @@ -1,5 +1,3 @@ -#include "mnruleplus.h" - #include "placeholder.h" #include "platform.h" @@ -24,8 +22,11 @@ #include "mn/mnmain.h" #include "mn/mnmainrule.h" #include "mn/mnstagesw.h" +#include "mn/types.h" #include "sc/types.h" +#include + #include extern StaticModelDesc MenMainConRl_Top; @@ -39,6 +40,38 @@ extern MenuKindData mn_803EB6B0[]; extern HSD_GObj* mn_804D6BE0; extern f32 mn_804D6BE4; +typedef struct _MenuRulesPlusData { + MenuKind8 menu_kind; + u8 hovered_selection; + union { + struct { + u8 time_limit; + u8 friendly_fire; + u8 pause; + u8 score; + u8 sd_penalty; + }; + u8 values[5]; + } rule_values; + u8 x7; + MenuState8 state; + HSD_JObj* xC[10]; + HSD_JObj* x34[6][7]; + HSD_Text* description; +} MenuRulesPlusData; + +typedef struct mn_803ED1D0_t { + u16 x0[7]; + u16 xE[6]; + float text_start_frames[12]; + AnimLoopSettings x4C; + AnimLoopSettings x58; + AnimLoopSettings x64[2]; + AnimLoopSettings x7C[2]; + AnimLoopSettings x94; +} mn_803ED1D0_t; +STATIC_ASSERT(sizeof(mn_803ED1D0_t) == 0xA0); + mn_803ED1D0_t mn_803ED1D0 = { { 3, 4, 5, 6, 7, 8, 9 }, { 7, 2, 2, 2, 2, 0 }, @@ -85,7 +118,10 @@ typedef union { u8 idx[4]; } JObjIndices; -f32 mn_804D4B98 = 1.0f; +/// Anim frame requested for the time-limit value jobj when the time limit +/// is disabled. Retail mn_802324E4 loads this TU-owned .sdata variable +/// (see symbols.txt) instead of materializing an .sdata2 constant. +f32 mnRulePlus_TimeLimitOffFrame = 1.0f; volatile const f64 mn_804DBE38 = 4503599627370496.0; const JObjIndices mn_804DBE40 = { 0x02030506 }; volatile f32 mn_804DBE44 = 0.0f; @@ -284,22 +320,34 @@ static inline void mnRulePlus_AnimZeros(HSD_JObj** jobjs) void mn_802324E4(u8 time_limit, MenuRulesPlusData* data) { + s32 i; JObjIndices local_indices; HSD_JObj** jobjs; - s32 i; jobjs = data->x34[0]; local_indices = mn_804DBE40; if (time_limit == 0) { - for (i = 0; i < 4; i++) { - HSD_JObjSetFlagsAll(jobjs[local_indices.idx[i]], JOBJ_HIDDEN); + i = 0; + while (1) { + u8 idx = local_indices.idx[i]; + HSD_JObjSetFlagsAll(jobjs[idx], JOBJ_HIDDEN); + i++; + if (i >= 4) { + break; + } } - HSD_JObjReqAnimAll(jobjs[4], 1.0f); + HSD_JObjReqAnimAll(jobjs[4], mnRulePlus_TimeLimitOffFrame); HSD_JObjAnimAll(jobjs[4]); return; } - for (i = 0; i < 4; i++) { - HSD_JObjClearFlagsAll(jobjs[local_indices.idx[i]], JOBJ_HIDDEN); + i = 0; + while (1) { + u8 idx = local_indices.idx[i]; + HSD_JObjClearFlagsAll(jobjs[idx], JOBJ_HIDDEN); + i++; + if (i >= 4) { + break; + } } HSD_JObjReqAnimAll(jobjs[4], mn_804D6BE4); HSD_JObjAnimAll(jobjs[4]); @@ -359,13 +407,16 @@ void mn_802327A4(HSD_GObj* gobj, u32 arg1, u32 arg2) HSD_JObj* option_roots[6]; HSD_JObj* jobj_parts[17]; u16 jobj_map[17]; - MenuRulesPlusData* data = gobj->user_data; + mn_803ED1D0_t* rule_data = &mn_803ED1D0; u8 num_options = mn_803EB6B0[15].selection_count; + MenuRulesPlusData* data = gobj->user_data; s32 i, j, vis_count; s32 visible; HSD_JObj** root_ptr; + u16* map_ptr; + u16 map_idx; u16 selected; - PAD_STACK(12); + PAD_STACK(8); jobj_map[0] = 0; jobj_map[1] = 1; @@ -383,8 +434,12 @@ void mn_802327A4(HSD_GObj* gobj, u32 arg1, u32 arg2) jobj_map[13] = 13; jobj_map[14] = 14; jobj_map[15] = 15; - for (i = 16; i < 17; i++) { - jobj_map[i] = (u16) i; + map_idx = 16; + map_ptr = &jobj_map[16]; + while (map_idx < 17) { + *map_ptr = map_idx; + map_ptr++; + map_idx++; } root_ptr = option_roots; @@ -417,7 +472,7 @@ void mn_802327A4(HSD_GObj* gobj, u32 arg1, u32 arg2) j++; } { - HSD_JObj* root = data->xC[mn_803ED1D0.x0[vis_count]]; + HSD_JObj* root = data->xC[rule_data->x0[vis_count]]; HSD_JObj* child; if (root == NULL) { child = NULL; @@ -440,15 +495,15 @@ void mn_802327A4(HSD_GObj* gobj, u32 arg1, u32 arg2) { HSD_JObj* part = jobj_parts[2]; if (old_sel == 5) { - HSD_JObjReqAnimAll(part, mn_803ED1D0.x7C[0].start_frame); + HSD_JObjReqAnimAll(part, rule_data->x7C[0].start_frame); } else { - HSD_JObjReqAnimAll(part, mn_803ED1D0.x64[0].start_frame); + HSD_JObjReqAnimAll(part, rule_data->x64[0].start_frame); } HSD_JObjAnimAll(part); } { HSD_JObj* part = jobj_parts[7]; - HSD_JObjReqAnim(part, mn_803ED1D0.text_start_frames[old_sel * 2]); + HSD_JObjReqAnim(part, rule_data->text_start_frames[old_sel * 2]); HSD_JObjAnim(part); } HSD_JObjSetFlagsAll(jobj_parts[8], JOBJ_HIDDEN); @@ -458,60 +513,63 @@ void mn_802327A4(HSD_GObj* gobj, u32 arg1, u32 arg2) { HSD_JObj* part = jobj_parts[16]; HSD_JObjClearFlagsAll(part, JOBJ_HIDDEN); - HSD_JObjReqAnimAll(part, mn_803ED1D0.x4C.start_frame); + HSD_JObjReqAnimAll(part, rule_data->x4C.start_frame); } if (new_sel != 5) { HSD_JObj* part = jobj_parts[13]; HSD_JObjClearFlagsAll(part, JOBJ_HIDDEN); - HSD_JObjReqAnimAll(part, mn_803ED1D0.x58.start_frame); + HSD_JObjReqAnimAll(part, rule_data->x58.start_frame); part = jobj_parts[2]; - HSD_JObjReqAnimAll(part, mn_803ED1D0.x64[1].start_frame); + HSD_JObjReqAnimAll(part, rule_data->x64[1].start_frame); HSD_JObjAnimAll(part); } else { HSD_JObj* part = jobj_parts[2]; - HSD_JObjReqAnimAll(part, mn_803ED1D0.x7C[1].start_frame); + HSD_JObjReqAnimAll(part, rule_data->x7C[1].start_frame); HSD_JObjAnimAll(part); } { HSD_JObj* part = jobj_parts[7]; HSD_JObjReqAnim(part, - mn_803ED1D0.text_start_frames[new_sel * 2 + 1]); + rule_data->text_start_frames[new_sel * 2 + 1]); HSD_JObjAnim(part); } if (new_sel == 5) { HSD_JObj* part = jobj_parts[8]; HSD_JObjClearFlagsAll(part, JOBJ_HIDDEN); - HSD_JObjReqAnimAll(part, mn_803ED1D0.x94.start_frame); + HSD_JObjReqAnimAll(part, rule_data->x94.start_frame); HSD_JObjAnimAll(part); } } if ((s32) arg2 != 0) { - u16 hovered = mn_804A04F0.hovered_selection; - u8 hovered_u8 = hovered; - u8 confirmed = mn_804A04F0.confirmed_selection; - HSD_JObj* tree = data->x34[hovered][0]; - if ((s32) hovered_u8 != 5 && (s32) hovered_u8 < 5) { - if ((s32) hovered_u8 != 0) { - if ((s32) hovered_u8 < 0) { - } else { - if ((mn_804A04F0.buttons & 4) != 0) { - HSD_JObjReqAnimAll( - tree, mn_803ED294[mn_803ED2E8.stat[hovered][1] - - confirmed] - .start_frame); - } else if (confirmed == 0) { - HSD_JObjReqAnimAll( - tree, mn_803ED270[mn_803ED2E8.stat[hovered][1]] - .start_frame); - } else { - HSD_JObjReqAnimAll( - tree, mn_803ED270[confirmed - 1].start_frame); + u16 hovered; + hovered = mn_804A04F0.hovered_selection; + { + u8 hovered_u8 = hovered; + u8 confirmed = mn_804A04F0.confirmed_selection; + HSD_JObj* tree = data->x34[hovered][0]; + if ((s32) hovered_u8 != 5 && (s32) hovered_u8 < 5) { + switch ((s32) hovered_u8) { + case 0: { + MenuRulesPlusData* data2 = + (MenuRulesPlusData*) gobj->user_data; + mn_802324E4(confirmed, data2); + } break; + default: + if ((s32) hovered_u8 >= 0) { + if (mn_804A04F0.buttons & 4) { + HSD_JObjReqAnimAll( + tree, mn_80232458(hovered_u8, confirmed, 0) + ->start_frame); + } else { + HSD_JObjReqAnimAll( + tree, mn_80232458(hovered_u8, confirmed, 1) + ->start_frame); + } + HSD_JObjAnimAll(tree); } - HSD_JObjAnimAll(tree); + break; } - } else { - mn_802324E4(confirmed, (MenuRulesPlusData*) gobj->user_data); } } } @@ -546,18 +604,19 @@ void mn_802327A4(HSD_GObj* gobj, u32 arg1, u32 arg2) AnimLoopSettings* als; lb_8001204C(*root_ptr, jobj_parts, jobj_map, 17); if (i == (s32) (u8) selected) { - mn_8022ED6C(jobj_parts[16], &mn_803ED1D0.x4C); + mn_8022ED6C(jobj_parts[16], &rule_data->x4C); } if (i == (s32) (u8) selected && i != 5) { - mn_8022ED6C(jobj_parts[13], &mn_803ED1D0.x58); + mn_8022ED6C(jobj_parts[13], &rule_data->x58); } if (i == 5) { - als = &mn_803ED1D0.x7C[i == (s32) (u8) selected]; + AnimLoopSettings* tmp = rule_data->x7C; + als = &tmp[i == (s32) (u8) selected]; } else { - als = &mn_803ED1D0.x64[i == (s32) (u8) selected]; + als = &rule_data->x64[i == (s32) (u8) selected]; } mn_8022ED6C(jobj_parts[2], als); - mn_8022ED6C(jobj_parts[8], &mn_803ED1D0.x94); + mn_8022ED6C(jobj_parts[8], &rule_data->x94); mn_80232660(gobj, data->x34[i][0], (u8) i); } root_ptr++; @@ -752,12 +811,12 @@ HSD_GObj* mn_80233218(MenuState state) s32 vis_before; s32 vis_total; s32 visible; - HSD_JObj* root_jobj; + AnimLoopSettings* als; HSD_JObj* option_jobj; HSD_JObj* cursor_jobj; HSD_JObj* value_jobj; StaticModelDesc* desc; - AnimLoopSettings* als; + HSD_JObj* root_jobj; f32* frame_ptr; u16* sub_count_ptr; GameRules* rules; @@ -766,19 +825,19 @@ HSD_GObj* mn_80233218(MenuState state) selected = (u8) mn_804A04F0.hovered_selection; num_options = mn_803EB6B0[15].selection_count; - for (i = 0; i < 17; i++) { + for (i = 0; 17 > i; i++) { jobj_map[i] = (u16) i; } + desc = &MenMainConRl_Top; gobj = GObj_Create(6, 7, 0x80); mn_804D6BE0 = gobj; - root_jobj = HSD_JObjLoadJoint(MenMainConRl_Top.joint); + root_jobj = HSD_JObjLoadJoint(desc->joint); HSD_GObjObject_80390A70(gobj, HSD_GObj_804D7849, root_jobj); GObj_SetupGXLink(gobj, HSD_GObj_JObjCallback, 4, 0x80); HSD_GObj_SetupProc(gobj, fn_80232F44, 0); - HSD_JObjAddAnimAll(root_jobj, MenMainConRl_Top.animjoint, - MenMainConRl_Top.matanim_joint, - MenMainConRl_Top.shapeanim_joint); + HSD_JObjAddAnimAll(root_jobj, desc->animjoint, desc->matanim_joint, + desc->shapeanim_joint); HSD_JObjReqAnimAll(root_jobj, 0.0f); HSD_JObjAnimAll(root_jobj); @@ -888,7 +947,7 @@ HSD_GObj* mn_80233218(MenuState state) } if (i == 5) { - als = &mn_803ED1D0.x7C[selected == i]; + als = &mn_803ED1D0.x7C[i == selected]; (void) als; } else { als = &mn_803ED1D0.x64[selected == i]; diff --git a/src/melee/mn/mnsnap.c b/src/melee/mn/mnsnap.c index 3b69c2db8a..be117e64fc 100644 --- a/src/melee/mn/mnsnap.c +++ b/src/melee/mn/mnsnap.c @@ -107,11 +107,6 @@ typedef struct mnSnap_State { /* 0x17C */ void* blank_img; } mnSnap_State; -typedef struct mnSnap_ThumbImageSlot { - u8 pad[0x180]; - void* image; -} mnSnap_ThumbImageSlot; - static mnSnap_State mnSnap_804A0A10; static void* mnSnap_thumb_imgs[4]; @@ -122,22 +117,27 @@ void mnSnap_80253184(void) { s32* p50; mnSnap_State* snap = &mnSnap_804A0A10; - s32* p4F; s32* p52; + s32* p4F; s32* p57; - s32* flags; p4F = &snap->cur_page; - p52 = &snap->load_idx; + { + s32* load_idx = &snap->load_idx; + p52 = load_idx; + } p50 = &snap->active_slot; - flags = &snap->thumb_loaded[0]; - snap->card_result = lbSnap_8001E058(*p50, *p52 + (*p4F * 4)); + { + s32 index = *p52 + (*p4F * 4); + snap->card_result = lbSnap_8001E058(*p50, index); + } p57 = &snap->card_result; if (*p57 == 8) { mnSnap_80254298(); return; } if (*p57 != 11) { + s32* flags = &mnSnap_804A0A10.thumb_loaded[0]; s32* p51; flags[*p52] = 1; @@ -164,6 +164,32 @@ void mnSnap_80253184(void) /// @todo The HSD_ASSERT chain (lines 193-199) is an inline from tobj.h. /// Polls card read result and updates thumbnail display. +static inline s32* mnSnap_GetLoadIdx(mnSnap_State* snap) +{ + return &snap->load_idx; +} + +static inline void* mnSnap_GetThumbImage(s32* load_idx) +{ + return mnSnap_thumb_imgs[*load_idx % 4]; +} + +static inline HSD_DObj* mnSnap_GetDObj(HSD_JObj* jobj) +{ + return jobj->u.dobj; +} + +static inline HSD_JObj* mnSnap_GetThumbJObj(s32* load_idx, + mnSnap_State* snap) +{ + return snap->thumb_jobjs[*load_idx]; +} + +static inline HSD_ImageDesc* mnSnap_GetImageDesc(HSD_JObj* jobj) +{ + return jobj->u.dobj->next->next->mobj->tobj->imagedesc; +} + static void mnSnap_8025329C(void) { mnSnap_State* snap = &mnSnap_804A0A10; @@ -178,17 +204,13 @@ static void mnSnap_8025329C(void) return; } if (result == 0) { - void* img; HSD_JObj* jobj; - mnSnap_ThumbImageSlot* img_slot; + void* img; - p52 = &snap->load_idx; - img_slot = - (mnSnap_ThumbImageSlot*) ((u32) snap + (snap->load_idx % 4) * 4); - if (lbSnap_8001DE8C(img_slot->image) == 1) { - img_slot = (mnSnap_ThumbImageSlot*) ((u32) snap + (*p52 % 4) * 4); - jobj = snap->thumb_jobjs[*p52]; - img = img_slot->image; + p52 = mnSnap_GetLoadIdx(snap); + if (lbSnap_8001DE8C(mnSnap_thumb_imgs[snap->load_idx % 4]) == 1) { + img = mnSnap_GetThumbImage(p52); + jobj = mnSnap_GetThumbJObj(p52, snap); HSD_ASSERT(193, jobj); HSD_ASSERT(194, jobj->u.dobj); HSD_ASSERT(195, jobj->u.dobj->next); @@ -196,9 +218,10 @@ static void mnSnap_8025329C(void) HSD_ASSERT(197, jobj->u.dobj->next->next->mobj); HSD_ASSERT(198, jobj->u.dobj->next->next->mobj->tobj); HSD_ASSERT(199, jobj->u.dobj->next->next->mobj->tobj->imagedesc); - jobj->u.dobj->next->next->mobj->tobj->imagedesc->image_ptr = img; + mnSnap_GetImageDesc(jobj)->image_ptr = img; jobj->u.dobj->next->next->mobj->tobj->imagedesc->width = 0x280; - jobj->u.dobj->next->next->mobj->tobj->imagedesc->height = 0x1E0; + mnSnap_GetDObj(jobj)->next->next->mobj->tobj->imagedesc->height = + 0x1E0; } else { flags = &snap->thumb_loaded[0]; flags[*p52 % 4] = 1; @@ -276,18 +299,21 @@ void mnSnap_80253640(s32 page) p48 = &snap->photo_count[0]; p4F = &snap->cur_page; p50 = &snap->active_slot; + (void) p48; *p4F = page; count = p48[*p50] - (page * 4); if (count > 4) { count = 4; } p51 = &snap->pending_loads; + (void) p51; *p51 = count; i = 0; p52 = &snap->load_idx; (void) p52; *p52 = 0; p58 = &snap->thumb_loaded[0]; + (void) p58; *p58 = 0; snap->thumb_loaded[1] = 0; snap->thumb_loaded[2] = 0; @@ -365,6 +391,7 @@ void mnSnap_80253964(void) } for (i = 0; i < 2; i++) { + (void) mnSnap_804A0A10.card_status[i]; HSD_SisLib_803A7664(mnSnap_804A0A10.count_texts[i]); if (mnSnap_804A0A10.state >= 4 && mnSnap_804A0A10.card_status[i] == 1) { @@ -373,22 +400,18 @@ void mnSnap_80253964(void) } } - { - HSD_Text** p = &mnSnap_804A0A10.page_text; - HSD_SisLib_803A7664(*p); - if (mnSnap_804A0A10.state >= 4) { - HSD_SisLib_803A6B98(*p, 0.0F, 0.0F, "%d", page + 1); - } + HSD_SisLib_803A7664(mnSnap_804A0A10.page_text); + if (mnSnap_804A0A10.state >= 4) { + HSD_SisLib_803A6B98(mnSnap_804A0A10.page_text, 0.0F, 0.0F, "%d", + page + 1); + } - p = &mnSnap_804A0A10.total_text; - HSD_SisLib_803A7664(*p); - if (mnSnap_804A0A10.state >= 4) { - HSD_SisLib_803A6B98( - *p, 0.0F, 0.0F, "%d", - (mnSnap_804A0A10.photo_count[mnSnap_804A0A10.active_slot] + - 3) / - 4); - } + HSD_SisLib_803A7664(mnSnap_804A0A10.total_text); + if (mnSnap_804A0A10.state >= 4) { + HSD_SisLib_803A6B98( + mnSnap_804A0A10.total_text, 0.0F, 0.0F, "%d", + (mnSnap_804A0A10.photo_count[mnSnap_804A0A10.active_slot] + 3) / + 4); } } @@ -587,8 +610,8 @@ void mnSnap_80254014(void) /// Configures the Yes/No dialog button positions based on language setting. void mnSnap_8025409C(s32 dlg_type) { - HSD_JObj* right; HSD_JObj* left; + HSD_JObj* right; s32* p5E; HSD_JObj** p38; HSD_JObj** p39; @@ -608,6 +631,16 @@ void mnSnap_8025409C(s32 dlg_type) p5E = &mnSnap_804A0A10.btn_idx; *p5E = 0; + /// @remark Matching tactic: the self-assign keeps p5E live so MWCC + /// re-uses its register instead of rematerializing the address below. +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wself-assign" +#endif + p5E = p5E; +#ifdef __clang__ +#pragma clang diagnostic pop +#endif if (dlg_type == 1) { left = *p38; @@ -701,8 +734,8 @@ void mnSnap_80254298(void) { /* walk strides through card_status (s16 at byte 0x128) */ - s16* walk = (s16*) snap; s32 byte_off = 4; + s16* walk = (s16*) snap; for (i = 0; i < 2; i++, byte_off += 8, walk++) { if (walk[0x94] != 0) { /* snap->card_status[i] */ @@ -799,6 +832,7 @@ void fn_802545C4(void) u64 buttons; s32 state; s32 byte_off; + s32 byte_off2; s32 i; s32 result; s32 slot; @@ -810,8 +844,8 @@ void fn_802545C4(void) PAD_STACK(320); buttons = (mn_804A04F0.buttons = mn_80229624(4)); HSD_JObjAnimAll(mnSnap_804A0A10.select_jobj); - jobj = mnSnap_804A0A10.move_jobj; - HSD_JObjAnimAll(jobj); + jobj2 = mnSnap_804A0A10.move_jobj; + HSD_JObjAnimAll(jobj2); state = mnSnap_804A0A10.state; if (state >= 4) { if (((u32) (state - 15)) > 1) { @@ -1098,8 +1132,8 @@ void fn_802545C4(void) { lbAudioAx_80024030(2); mnSnap_804A0A10.active_slot = 0; - byte_off = 4; - for (i = 0; i < 2; i++, byte_off += 8) { + byte_off2 = 4; + for (i = 0; i < 2; i++, byte_off2 += 8) { if (mnSnap_804A0A10.card_status[i] != 0) { if (mnSnap_804A0A10.active_slot == i) { t = 1.0F; @@ -1108,18 +1142,18 @@ void fn_802545C4(void) } HSD_JObjReqAnimAll( *((HSD_JObj**) ((((u32) (&mnSnap_804A0A10)) + - byte_off) + + byte_off2) + 0x98)), t); } else { HSD_JObjReqAnimAll( *((HSD_JObj**) ((((u32) (&mnSnap_804A0A10)) + - byte_off) + + byte_off2) + 0x98)), 2.0F); } HSD_JObjAnimAll(*( - (HSD_JObj**) ((((u32) (&mnSnap_804A0A10)) + byte_off) + + (HSD_JObj**) ((((u32) (&mnSnap_804A0A10)) + byte_off2) + 0x98))); } @@ -2403,13 +2437,12 @@ void mnSnap_80257F24(void) { mnSnap_State* snap = &mnSnap_804A0A10; s32 zero = 0; - HSD_GObj* gobj; HSD_JObj* jobj; + HSD_GObj* gobj; HSD_JObj* jobj2; HSD_JObj* pos_start; HSD_JObj* pos_end; HSD_JObj** move_jobj_ptr; - HSD_JObj** slot_jobj_ptr; HSD_JObj** thumb_root_ptr; HSD_GObjProc* proc; HSD_Text* text; @@ -2447,7 +2480,10 @@ void mnSnap_80257F24(void) snap->state = zero; snap->timer = 6; snap->photo_count[0] = zero; - snap->photo_count[1] = zero; + { + s32* photo_count = snap->photo_count; + photo_count[1] = zero; + } snap->card_status[0] = zero; snap->card_status[1] = zero; @@ -2507,7 +2543,6 @@ void mnSnap_80257F24(void) lb_80011E24(jobj, (HSD_JObj**) &snap->thumb_jobjs[0], 8, 9, 0xA, 0xB, 0xC, 0xD, 6, 2, 1, -1); - slot_jobj_ptr = &snap->slot_a_jobj; snap->blank_img = *(void**) (snap->slot_a_jobj)->u.dobj->mobj->tobj->imagedesc; @@ -2538,7 +2573,7 @@ void mnSnap_80257F24(void) (HSD_ShapeAnimJoint*) *arrows_shapeanim); HSD_JObjReqAnimAll(jobj, 0.0F); HSD_JObjAnimAll(jobj); - lb_80011E24(jobj, slot_jobj_ptr, 1, 2, 3, 4, -1); + lb_80011E24(jobj, &snap->slot_a_jobj, 1, 2, 3, 4, -1); /* Cursor GObj */ gobj = GObj_Create(6, 7, 0x80); diff --git a/src/melee/mn/mnsound.c b/src/melee/mn/mnsound.c index 53964972bf..787297bbb6 100644 --- a/src/melee/mn/mnsound.c +++ b/src/melee/mn/mnsound.c @@ -54,24 +54,26 @@ static void mnSound_VolumeAnim(HSD_JObj* jobj, s32 sound_music_mix, static void mnSound_ChannelAnim(HSD_JObj* jobj, s32 channel) { - HSD_JObj* jobj_anim[3]; + HSD_JObj* jobj_anim_1; f32 right_frame, left_frame; - lb_80011E24(jobj, &jobj_anim[0], 8, -1); - lb_80011E24(jobj, &jobj_anim[1], 10, -1); - lb_80011E24(jobj, &jobj_anim[2], 9, -1); - left_frame = mn_8022F298(jobj_anim[1]); - right_frame = mn_8022F298(jobj_anim[2]); + HSD_JObj* jobj_anim_2; + HSD_JObj* jobj_anim_0; + lb_80011E24(jobj, &jobj_anim_0, 8, -1); + lb_80011E24(jobj, &jobj_anim_1, 10, -1); + lb_80011E24(jobj, &jobj_anim_2, 9, -1); + left_frame = mn_8022F298(jobj_anim_1); + right_frame = mn_8022F298(jobj_anim_2); - HSD_JObjReqAnimAll(jobj_anim[0], channel); - HSD_JObjAnimAll(jobj_anim[0]); + HSD_JObjReqAnimAll(jobj_anim_0, channel); + HSD_JObjAnimAll(jobj_anim_0); - HSD_JObjReqAnimAll(jobj_anim[1], left_frame); - mn_8022F3D8(jobj_anim[1], 0xFFU, MOBJ_MASK); - HSD_JObjAnimAll(jobj_anim[1]); + HSD_JObjReqAnimAll(jobj_anim_1, left_frame); + mn_8022F3D8(jobj_anim_1, 0xFFU, MOBJ_MASK); + HSD_JObjAnimAll(jobj_anim_1); - HSD_JObjReqAnimAll(jobj_anim[2], right_frame); - mn_8022F3D8(jobj_anim[2], 0xFFU, MOBJ_MASK); - HSD_JObjAnimAll(jobj_anim[2]); + HSD_JObjReqAnimAll(jobj_anim_2, right_frame); + mn_8022F3D8(jobj_anim_2, 0xFFU, MOBJ_MASK); + HSD_JObjAnimAll(jobj_anim_2); } static inline void mnSound_InitCenterText(Menu* menu, s32 val) @@ -84,11 +86,26 @@ static inline void mnSound_InitCenterText(Menu* menu, s32 val) HSD_SisLib_803A6368(text, val); } -void mnSound_802492CC(HSD_GObj* gobj) +static inline void mnSound_UpdateCenterText(void) { Menu* menu = GET_MENU(mnSound_804D6C30); + s32 text_id; + if (menu->text != NULL) { + HSD_SisLib_803A5CC4(menu->text); + } + if (menu->unk2 == 0) { + text_id = 0xBB; + } else { + text_id = 0xBC; + } + mnSound_InitCenterText(menu, text_id); +} + +void mnSound_802492CC(HSD_GObj* gobj) +{ u64 events; - PAD_STACK(8); + u8 mix; + Menu* menu = GET_MENU(mnSound_804D6C30); if (mn_804D6BC8.cooldown != 0) { Menu_DecrementAnimTimer(); return; @@ -110,19 +127,7 @@ void mnSound_802492CC(HSD_GObj* gobj) } else { menu->unk2 = 0; } - { - Menu* menu = GET_MENU(mnSound_804D6C30); - s32 text_id; - if (menu->text != NULL) { - HSD_SisLib_803A5CC4(menu->text); - } - if (menu->unk2 == 0) { - text_id = 0xBB; - } else { - text_id = 0xBC; - } - mnSound_InitCenterText(menu, text_id); - } + mnSound_UpdateCenterText(); return; } if (events & MenuInput_Left) { @@ -135,12 +140,11 @@ void mnSound_802492CC(HSD_GObj* gobj) lbAudioAx_80024C08(menu->unk1); } } else if ((s8) menu->unk3 > -100) { - u8 mix; // move towards sounds lbAudioAx_80024030(2); menu->unk3 -= 5; mix = menu->unk3; - mnSound_VolumeAnim(GET_JOBJ(mnSound_804D6C30), mix, 15); + mnSound_VolumeAnim(GET_JOBJ(mnSound_804D6C30), mix, 5); gm_801602C0(mix); gmMainLib_8015ED80(GET_MENU(mnSound_804D6C30)->unk3); } @@ -154,21 +158,52 @@ void mnSound_802492CC(HSD_GObj* gobj) lbAudioAx_80024C08(menu->unk1); } } else if ((s8) menu->unk3 < 100) { - u8 mix; // move towards music lbAudioAx_80024030(2); menu->unk3 += 5; mix = menu->unk3; - mnSound_VolumeAnim(GET_JOBJ(mnSound_804D6C30), mix, 18); + mnSound_VolumeAnim(GET_JOBJ(mnSound_804D6C30), mix, 6); gm_801602C0(mix); gmMainLib_8015ED80(GET_MENU(mnSound_804D6C30)->unk3); } } } +static inline void mnSound_80249A1C_OnSoundSelected(HSD_GObj* gobj, + HSD_JObj** jobj_out) +{ + AnimLoopSettings* anim = mnSound_803EEED8; + Menu* menu = GET_MENU(gobj); + HSD_JObj* jobj = GET_JOBJ(gobj); + if ((u8) menu->unk2 == 0) { + if ((u8) menu->unk1 == 0) { + lb_80011E24(jobj, jobj_out, 0xA, -1); + } else { + lb_80011E24(jobj, jobj_out, 9, -1); + } + mn_8022EC18(*jobj_out, anim, 0x80); + } +} + +static inline void +mnSound_80249A1C_ChooseVolumeAnim(HSD_JObj* jobj, AnimLoopSettings* settings) +{ + AnimLoopSettings* anim = mnSound_803EEED8; + f32 cursor_frame = mn_8022F298(jobj); + if ((anim[5].start_frame <= cursor_frame) && + (cursor_frame <= anim[5].end_frame)) + { + *settings = anim[5]; + } else { + *settings = anim[6]; + } +} + void fn_80249A1C(HSD_GObj* arg0) { + AnimLoopSettings* anim = mnSound_803EEED8; Menu* menu = GET_MENU(arg0); + HSD_JObj* jobj = arg0->hsd_obj; HSD_JObj* sp40; HSD_JObj* sp3C; UNUSED u8 pad38[4]; @@ -176,11 +211,8 @@ void fn_80249A1C(HSD_GObj* arg0) AnimLoopSettings sp28; UNUSED u8 pad24[4]; HSD_JObj* sp20; - f32 cursor_frame; u8 temp_r4; - AnimLoopSettings* anim = mnSound_803EEED8; - HSD_JObj* jobj = arg0->hsd_obj; - PAD_STACK(16); + PAD_STACK(8); if ((u8) mn_804A04F0.cur_menu != 0x14) { HSD_GObjPLink_80390228(arg0); HSD_SisLib_803A5CC4(menu->text); @@ -196,23 +228,9 @@ void fn_80249A1C(HSD_GObj* arg0) HSD_JObjClearFlagsAll(jobj, JOBJ_HIDDEN); return; } - if ((u8) menu->unk2 == 0) { - if ((u8) menu->unk1 == 0) { - lb_80011E24(jobj, &sp34, 0xA, -1); - } else { - lb_80011E24(jobj, &sp34, 9, -1); - } - mn_8022EC18(sp34, anim, 0x80); - } + mnSound_80249A1C_OnSoundSelected(arg0, &sp34); lb_80011E24((HSD_JObj*) arg0->hsd_obj, &sp20, 6, -1); - cursor_frame = mn_8022F298(sp20); - if ((anim[5].start_frame <= cursor_frame) && - (cursor_frame <= anim[5].end_frame)) - { - sp28 = anim[5]; - } else { - sp28 = anim[6]; - } + mnSound_80249A1C_ChooseVolumeAnim(sp20, &sp28); mn_8022ED6C(sp20, &sp28); lb_80011E24(jobj, &sp40, 0xE, -1); { @@ -228,18 +246,19 @@ void fn_80249A1C(HSD_GObj* arg0) void mnSound_80249C08(int unused) { + StaticModelDesc* model = &mnSound_804A08A8; + AnimLoopSettings* anims = mnSound_803EEED8; HSD_GObj* gobj = GObj_Create(HSD_GOBJ_CLASS_ITEM, 7U, 0x80U); HSD_JObj* jobj; Menu* user_data; HSD_GObjProc* proc; PAD_STACK(24); mnSound_804D6C30 = gobj; - jobj = HSD_JObjLoadJoint(mnSound_804A08A8.joint); + jobj = HSD_JObjLoadJoint(model->joint); HSD_GObjObject_80390A70((HSD_GObj*) gobj, (u8) HSD_GObj_804D7849, jobj); GObj_SetupGXLink((HSD_GObj*) gobj, HSD_GObj_JObjCallback, 4U, 0x80); - HSD_JObjAddAnimAll(jobj, mnSound_804A08A8.animjoint, - mnSound_804A08A8.matanim_joint, - mnSound_804A08A8.shapeanim_joint); + HSD_JObjAddAnimAll(jobj, model->animjoint, model->matanim_joint, + model->shapeanim_joint); HSD_JObjReqAnimAll(jobj, 0.0F); { Menu* alloc = HSD_MemAlloc(8); @@ -275,7 +294,7 @@ void mnSound_80249C08(int unused) { HSD_JObj* sp5C; lb_80011E24(jobj, &sp5C, 6, -1); - HSD_JObjReqAnimAll(sp5C, mnSound_803EEED8[5].end_frame); + HSD_JObjReqAnimAll(sp5C, anims[5].end_frame); HSD_JObjAnimAll(sp5C); } @@ -287,12 +306,11 @@ void mnSound_80249C08(int unused) gm_801602C0(user_data->unk3); lb_80011E24(jobj, &sp64, 0xE, -1); { - AnimLoopSettings* anim = &mnSound_803EEED8[user_data->unk2]; + AnimLoopSettings* anim = &anims[user_data->unk2]; mn_8022ED6C(sp64, anim + 1); } lb_80011E24(jobj, &sp60, 0xB, -1); - HSD_JObjReqAnimAll(sp60, - mnSound_803EEED8[user_data->unk1 + 3].end_frame); + HSD_JObjReqAnimAll(sp60, anims[user_data->unk1 + 3].end_frame); HSD_JObjAnimAll(sp60); HSD_JObjSetFlagsAll(jobj, JOBJ_HIDDEN); } diff --git a/src/melee/mn/mnsoundtest.c b/src/melee/mn/mnsoundtest.c index 944babd73d..31080146d9 100644 --- a/src/melee/mn/mnsoundtest.c +++ b/src/melee/mn/mnsoundtest.c @@ -500,7 +500,6 @@ void fn_8024B2B0(HSD_GObj* arg0) } inputs = mn_80229624(4U); mn_804A04F0.buttons = inputs; - mn_804A04F0.entering_menu = 0; if (inputs & MenuInput_Back) { mn_804A04F0.entering_menu = 0; mn_80229894(5, 2U, 3); @@ -515,8 +514,9 @@ void fn_8024B2B0(HSD_GObj* arg0) state = 1; } user_data->unk0 = state; + state = user_data->unk0; gobj = mnSoundTest_804D6C40; - mnSoundTest_8024ABF8(gobj, (u8) (-(s32) state == 0)); + mnSoundTest_8024ABF8(gobj, state == 0); mnSoundTest_8024AD58(gobj, state); return; } diff --git a/src/melee/mn/mnstagesw.c b/src/melee/mn/mnstagesw.c index 9714b10044..fc7a4ba837 100644 --- a/src/melee/mn/mnstagesw.c +++ b/src/melee/mn/mnstagesw.c @@ -149,22 +149,23 @@ static void mnStageSw_802359C8(MnStageSwData* data) static s32 mnStageSw_80235C58(u8 arg0) { - s32 low; - s32 found; - s32 i; + u8 upper_u8; + s32 next; + s32 upper; s32 idx; - u8 high; s32 curr; - s32 next; u8 end; + u8 lower; u8 start; + s32 found; + s32 i; if (arg0 < 15) { - low = 0; - high = 14; + lower = 0; + upper = 14; } else { - low = 15; - high = 28; + lower = 15; + upper = 28; } if (arg0 < 15) { start = 0; @@ -198,18 +199,19 @@ static s32 mnStageSw_80235C58(u8 arg0) idx = arg0; i = 1; - next = idx + 1; curr = idx + 1; + next = idx + 1; + upper_u8 = upper; while (true) { s32 temp = idx - i; s32 prev = temp; - if (low <= prev && + if (lower <= prev && gm_80164430(gm_801641CC(mnStageSw_803ED4C4[(u8) prev])) != 0) { return prev; } - if (next <= high && + if (next <= upper_u8 && gm_80164430(gm_801641CC(mnStageSw_803ED4C4[(u8) curr])) != 0) { return idx + i; @@ -293,11 +295,7 @@ static void fn_80235F80(HSD_GObj* gobj) u8* user_data; user_data = mnStageSw_804D6BF0->user_data; - { - u32 tmp = mn_80229624(4U); - mn_804A04F0.buttons = tmp; - buttons = tmp; - } + buttons = mn_804A04F0.buttons = mn_80229624(4U); count = 0; PAD_STACK(0x28); if (buttons & 0x20) { @@ -315,7 +313,7 @@ static void fn_80235F80(HSD_GObj* gobj) if (mn_804A04F0.hovered_selection < NUM_STAGES) { if (mn_804A04F0.confirmed_selection != 0) { user_data = mnStageSw_804D6BF0->user_data; - for (i = count; i < NUM_STAGES; i++) { + for (i = 0; i < NUM_STAGES; i++) { if (user_data[i + 2] != 0) { count++; } @@ -463,14 +461,17 @@ static void mnStageSw_80236548(HSD_GObj* gobj, u8 arg1, u8 arg2) HSD_JObjClearFlagsAll(cursor_jobj, JOBJ_HIDDEN); delta_y = HSD_JObjGetTranslationY(data->x30) - HSD_JObjGetTranslationY(data->x2C); + (void) delta_y; if (sel < 15) { x = HSD_JObjGetTranslationX(data->x2C); + (void) x; HSD_JObjSetTranslateX(cursor_jobj, x); HSD_JObjSetTranslateY(cursor_jobj, delta_y * (f32) sel + HSD_JObjGetTranslationY(data->x2C)); } else { x = HSD_JObjGetTranslationX(data->x34); + (void) x; HSD_JObjSetTranslateX(cursor_jobj, x); HSD_JObjSetTranslateY(cursor_jobj, delta_y * (f32) (sel - 15) + @@ -502,24 +503,25 @@ static void mnStageSw_80236548(HSD_GObj* gobj, u8 arg1, u8 arg2) #pragma inline_depth(0) static void fn_80236998(HSD_GObj* gobj) { - u64 pad2; - HSD_JObj* child; HSD_JObj* jobj; MnStageSwData* data; AnimLoopSettings* anims; s32 changed_menu; s32 changed_hovered; u64 pad3; + HSD_JObj* child; s32 changed_confirmed; u8 state; changed_menu = 0; changed_hovered = 0; changed_confirmed = 0; - data = gobj->user_data; + { + MnStageSwData* user_data = gobj->user_data; + data = user_data; + } state = data->x1F; PAD_STACK(4); - (void) pad2; if ((state == 0 || state == 1 || state == 3) && data->x0 != (u8) mn_804A04F0.cur_menu) { @@ -606,9 +608,8 @@ static void fn_80236998(HSD_GObj* gobj) return; } } - } else { - HSD_JObjAnim(jobj); } + HSD_JObjAnim(jobj); } state = data->x1F; @@ -637,18 +638,47 @@ static void fn_80236998(HSD_GObj* gobj) } #pragma pop +static inline void mnStageSw_SetCursorPosition(MnStageSwData* user_data) +{ + u8 hovered; + f32 y_spacing; + HSD_JObj* cursor; + + HSD_JObjSetFlagsAll(user_data->x34, JOBJ_HIDDEN); + cursor = user_data->x28; + hovered = user_data->x1; + HSD_JObjClearFlagsAll(cursor, JOBJ_HIDDEN); + y_spacing = HSD_JObjGetTranslationY(user_data->x30) - + HSD_JObjGetTranslationY(user_data->x2C); + if (hovered < 15) { + HSD_JObjSetTranslateX(cursor, + HSD_JObjGetTranslationX(user_data->x2C)); + HSD_JObjSetTranslateY(cursor, + y_spacing * (f32) hovered + + HSD_JObjGetTranslationY(user_data->x2C)); + } else { + HSD_JObjSetTranslateX(cursor, + HSD_JObjGetTranslationX(user_data->x34)); + HSD_JObjSetTranslateY(cursor, + y_spacing * (f32) (hovered - 15) + + HSD_JObjGetTranslationY(user_data->x2C)); + } + HSD_JObjSetFlagsAll(user_data->x28, JOBJ_HIDDEN); +} + static HSD_GObj* mnStageSw_80236CBC(s8 arg0) { - AnimLoopSettings* anims = mnStageSw_803ED488; - struct StaticModelDesc* mdl = &MenMainConSs_Top; HSD_GObj* gobj; HSD_JObj* jobj; HSD_JObj* sp48; MnStageSwData* user_data; + AnimLoopSettings* anims = mnStageSw_803ED488; + struct StaticModelDesc* mdl = &MenMainConSs_Top; f32 y_spacing; u8 hovered; HSD_JObj* cursor_anim_jobj; s32 i; + u8* stage_ids; gobj = GObj_Create(6, 7, 0x80); mnStageSw_804D6BF0 = gobj; @@ -667,22 +697,18 @@ static HSD_GObj* mnStageSw_80236CBC(s8 arg0) HSD_ASSERTREPORT(0x397, user_data, "Can't get user_data.\n"); GObj_InitUserData(gobj, 0, HSD_Free, user_data); + i = 0; user_data->x0 = mn_804A04F0.cur_menu; - { - u8 idx = 0; - - user_data->x1 = (u8) mn_804A04F0.hovered_selection; - user_data->x1F = arg0; - for (; idx < NUM_STAGES; idx++) { - u8 stage_id = mnStageSw_803ED4C4[idx]; - - if (gm_80164430(gm_801641CC(stage_id)) != 0) { - user_data->x2[idx] = - ((1 << stage_id) & gmMainLib_8015CC58()->stage_mask) != 0; - } else { - user_data->x2[idx] = 0; - } + user_data->x1 = (u8) mn_804A04F0.hovered_selection; + user_data->x1F = arg0; + stage_ids = mnStageSw_803ED4C4; + for (; (u8) i < NUM_STAGES; i++) { + if (gm_80164430(gm_801641CC(mnStageSw_803ED4C4[(u8) i])) != 0) { + user_data->x2[(u8) i] = gm_80164250(*stage_ids); + } else { + user_data->x2[(u8) i] = 0; } + stage_ids++; } for (i = 0; i < 6; i++) { @@ -708,7 +734,7 @@ static HSD_GObj* mnStageSw_80236CBC(s8 arg0) HSD_JObjReqAnimAll(cursor_anim_jobj, mnStageSw_804D4BB8[enabled]); HSD_JObjAnimAll(cursor_anim_jobj); lb_80011E24(cursor_jobj, &sp48, 3, -1); - if (idx == hovered) { + if (hovered == idx) { HSD_JObjReqAnimAll(sp48, anims[0].start_frame); HSD_JObjAnimAll(sp48); } else { @@ -728,32 +754,7 @@ static HSD_GObj* mnStageSw_80236CBC(s8 arg0) HSD_JObjSetFlagsAll(user_data->x2C, JOBJ_HIDDEN); - { - u8 hovered; - f32 y_spacing; - HSD_JObj* cursor; - - HSD_JObjSetFlagsAll(user_data->x34, JOBJ_HIDDEN); - cursor = user_data->x28; - hovered = user_data->x1; - HSD_JObjClearFlagsAll(cursor, JOBJ_HIDDEN); - y_spacing = HSD_JObjGetTranslationY(user_data->x30) - - HSD_JObjGetTranslationY(user_data->x2C); - if (hovered < 15) { - HSD_JObjSetTranslateX(cursor, - HSD_JObjGetTranslationX(user_data->x2C)); - HSD_JObjSetTranslateY(cursor, - y_spacing * (f32) hovered + - HSD_JObjGetTranslationY(user_data->x2C)); - } else { - HSD_JObjSetTranslateX(cursor, - HSD_JObjGetTranslationX(user_data->x34)); - HSD_JObjSetTranslateY(cursor, - y_spacing * (f32) (hovered - 15) + - HSD_JObjGetTranslationY(user_data->x2C)); - } - } - HSD_JObjSetFlagsAll(user_data->x28, JOBJ_HIDDEN); + mnStageSw_SetCursorPosition(user_data); return gobj; } diff --git a/src/melee/mn/mnvibration.c b/src/melee/mn/mnvibration.c index 8e3a45462f..2485296c10 100644 --- a/src/melee/mn/mnvibration.c +++ b/src/melee/mn/mnvibration.c @@ -225,6 +225,11 @@ HSD_JObj* mnVibration_GetNameRowJObj(s32 count) } #pragma pop +static inline f32 mnVibration_GetCursorYSpacing(f32 base_y, HSD_JObj* jobj) +{ + return mnVibration_JObjGetTranslationY(jobj) - base_y; +} + void mnVibration_HandleInput(HSD_GObj* gobj) { HSD_JObj* cursor_jobj; @@ -411,7 +416,7 @@ void mnVibration_HandleInput(HSD_GObj* gobj) if (inputs_repeat & (0x10LL << 32)) { cursor_row = data->x0[1]; if (cursor_row != 0) { - u8 name_row = cursor_row - 1; + s32 name_row = cursor_row - 1; name_idx = mnVibration_GetNameSlot(data, name_row); if (name_idx != 0xFF) { MnVibrationData* data2; @@ -431,7 +436,7 @@ void mnVibration_HandleInput(HSD_GObj* gobj) cursor_row = data->x0[1]; base_y = HSD_JObjGetTranslationY(jobj17); jobj18 = data2->jobjs[18]; - spacing = HSD_JObjGetTranslationY(jobj18) - base_y; + spacing = mnVibration_GetCursorYSpacing(base_y, jobj18); temp_x = HSD_JObjGetTranslationX(jobj17); HSD_JObjSetTranslateX(cursor_jobj, temp_x); jobj17 = data2->jobjs[17]; @@ -803,11 +808,6 @@ void mnVibration_Think(HSD_GObj* gobj) } while ((s32) port_idx < 4); } -static inline f32 mnVibration_GetCursorYSpacing(f32 base_y, HSD_JObj* jobj) -{ - return mnVibration_JObjGetTranslationY(jobj) - base_y; -} - void mnVibration_IntroProc(HSD_GObj* arg0) { MnVibrationData* data; diff --git a/src/melee/mp/mpisland.c b/src/melee/mp/mpisland.c index 2bc69377ef..6f0a57ff60 100644 --- a/src/melee/mp/mpisland.c +++ b/src/melee/mp/mpisland.c @@ -420,16 +420,22 @@ void mpIsland_8005AE1C(mp_UnkStruct0** arg0, mp_UnkStruct0** arg1, int arg2, *arg1 = prev_a; } +static inline MapJoint* mpIsland_GetJointInner(CollJoint* joints) +{ + return joints->inner; +} + void mpIsland_8005B004(mp_UnkStruct0** arg0, mp_UnkStruct0** arg1, int arg2, int arg3, int arg4, int arg5, bool arg6) { mp_UnkStruct0* cur; - float z_val; + CollLine* lines; + u8 pad[12]; u8 visited[0x600]; mp_UnkStruct0* next; mp_UnkStruct0* prev; mp_UnkStruct0* mpisp; - CollLine* lines; + float z_val; CollVtx* vtx; CollJoint* joints; MapJoint* inner; @@ -443,7 +449,6 @@ void mpIsland_8005B004(mp_UnkStruct0** arg0, mp_UnkStruct0** arg1, int arg2, float min_x; float max_x; int i; - PAD_STACK(16); type_flag = arg3 | 0x10; prev = NULL; @@ -468,7 +473,7 @@ void mpIsland_8005B004(mp_UnkStruct0** arg0, mp_UnkStruct0** arg1, int arg2, joints = &joints[arg2]; lines = mpGetGroundCollLine(); vtx = mpGetGroundCollVtx(); - inner = joints->inner; + inner = mpIsland_GetJointInner(joints); z_val = mpIsland_804D8158; end_total = inner->dynamic_start + inner->dynamic_count; @@ -543,9 +548,7 @@ void mpIsland_8005B004(mp_UnkStruct0** arg0, mp_UnkStruct0** arg1, int arg2, } while (i != link); } - mpisp = *arg1; - (void) mpisp; - if (mpisp != NULL) { + if ((mpisp = *arg1) != NULL) { *arg1 = mpisp->next; } else { mpisp = HSD_MemAlloc(0x2C); diff --git a/src/melee/mp/mplib.c b/src/melee/mp/mplib.c index 4588d3d2b9..04b08a5ccb 100644 --- a/src/melee/mp/mplib.c +++ b/src/melee/mp/mplib.c @@ -1,5 +1,3 @@ -#include "mplib.h" - #include "mpisland.h" #include "placeholder.h" #include "platform.h" @@ -45,6 +43,13 @@ #include #include +bool mpCheckedBounding(void); +void mpBoundingCheck(float left, float bottom, float right, float top); +void mpBoundingCheck2(float x0, float y0, float x1, float y1); +void mpBoundingCheck3(float x0, float y0, float x1, float y1, float x2, + float y2, float x3, float y3); +void mpUncheckBounding(void); + #define LINEID_CHECK(line, line_id) \ do { \ if ((line_id) == -1 || (line_id) >= mpLib_804D64B4->line_count) \ @@ -1545,17 +1550,23 @@ bool mpLineIntersectionH(float* int_x, float* int_y, float a0x, float a0y, return true; } +static inline CollLine* mpLineGetCollLine(int line_id) +{ + return &groundCollLine[line_id]; +} + void mpLib_8004ED5C(int line_id, float* x0_out, float* y0_out, float* x1_out, float* y1_out) { bool calculated_distance = false; - MapLine* line_r11 = groundCollLine[line_id].x0; + CollLine* line = mpLineGetCollLine(line_id); + MapLine* line_r11 = line->x0; float x0_f0 = groundCollVtx[line_r11->v0_idx].pos.x; float y0_f1 = groundCollVtx[line_r11->v0_idx].pos.y; float x1_f2 = groundCollVtx[line_r11->v1_idx].pos.x; float y1_f3 = groundCollVtx[line_r11->v1_idx].pos.y; - float distance = 0.0F; + float distance; PAD_STACK(8); if (mpLineGetPrev(line_id) != -1) { @@ -3569,7 +3580,7 @@ bool mpCheckAll(Vec3* pos_out, int* line_id_out, u32* flags_out, normal_out, 0xF, joint_id_skip, joint_id_only); } -static inline int mpLineGetNextCheckInline(MapLine* line, int result) +static inline int mpLineGetNextCheckInline(MapLine* line, s16 result) { if (result != -1) { u32 flags = groundCollLine[result].flags; @@ -3587,7 +3598,7 @@ static inline int mpLineGetNextCheckInline(MapLine* line, int result) return line->next_id0; } -static inline int mpLineGetPrevCheckInline(MapLine* line, int result) +static inline int mpLineGetPrevCheckInline(MapLine* line, s16 result) { if (result != -1) { u32 flags = groundCollLine[result].flags; @@ -3605,7 +3616,7 @@ static inline int mpLineGetPrevCheckInline(MapLine* line, int result) return line->prev_id0; } -static inline int mpLineGetPrevCheckInlineVtx(MapLine* line, int result, +static inline int mpLineGetPrevCheckInlineVtx(MapLine* line, s16 result, CollVtx* vtx) { if (result != -1) { @@ -3679,14 +3690,13 @@ int mpLinePrevNonFloor(int line_id) LINEID_CHECK(4148, line_id); line = groundCollLine[line_id].x0; - new_id = line->prev_id1; - new_id = mpLineGetPrevCheckInline(line, new_id); + new_id = mpLineGetPrevCheckInline(line, line->prev_id1); while (new_id != -1 && new_id != line_id && groundCollLine[new_id].flags & CollLine_Floor) { line = groundCollLine[new_id].x0; new_id = line->prev_id1; - new_id = mpLineGetPrevCheckInline(line, new_id); + new_id = mpLineGetPrevCheckInlineVtx(line, new_id, groundCollVtx); } valid_id = false; if ((new_id != -1) && (new_id != line_id)) { @@ -3701,19 +3711,17 @@ int mpLinePrevNonFloor(int line_id) int mpLinePrevNonCeiling(int line_id) { MapLine* line; - CollVtx* vtx; int new_id; bool valid_id; LINEID_CHECK(4157, line_id); line = groundCollLine[line_id].x0; new_id = mpLineGetPrevCheckInline(line, line->prev_id1); - vtx = groundCollVtx; while (new_id != -1 && new_id != line_id && groundCollLine[new_id].flags & CollLine_Ceiling) { line = groundCollLine[new_id].x0; new_id = line->prev_id1; - new_id = mpLineGetPrevCheckInlineVtx(line, new_id, vtx); + new_id = mpLineGetPrevCheckInlineVtx(line, new_id, groundCollVtx); } valid_id = false; if ((new_id != -1) && (new_id != line_id)) { @@ -3727,19 +3735,19 @@ int mpLinePrevNonCeiling(int line_id) int mpLineNextNonCeiling(int line_id) { + MapLine* first_line; MapLine* line; int new_id; bool valid_id; LINEID_CHECK(4166, line_id); - line = groundCollLine[line_id].x0; - new_id = line->next_id1; - new_id = mpLineGetNextCheckInline(line, new_id); + first_line = groundCollLine[line_id].x0; + new_id = mpLineGetNextCheckInline(first_line, first_line->next_id1); while (new_id != -1 && new_id != line_id && groundCollLine[new_id].flags & CollLine_Ceiling) { line = groundCollLine[new_id].x0; new_id = line->next_id1; - new_id = mpLineGetNextCheckInline(line, new_id); + new_id = mpLineGetNextCheckInlineVtx(line, new_id, groundCollVtx); } valid_id = false; if (new_id != -1 && new_id != line_id) { @@ -3753,19 +3761,20 @@ int mpLineNextNonCeiling(int line_id) int mpLineNextNonLeftWall(int line_id) { + MapLine* first_line; MapLine* line; int new_id; bool valid_id; LINEID_CHECK(4175, line_id); - line = groundCollLine[line_id].x0; - new_id = mpLineGetNextCheckInline(line, line->next_id1); + first_line = groundCollLine[line_id].x0; + new_id = mpLineGetNextCheckInline(first_line, first_line->next_id1); while (new_id != -1 && new_id != line_id && groundCollLine[new_id].flags & CollLine_LeftWall) { line = groundCollLine[new_id].x0; new_id = line->next_id1; - new_id = mpLineGetNextCheckInline(line, new_id); + new_id = mpLineGetNextCheckInlineVtx(line, new_id, groundCollVtx); } valid_id = false; if ((new_id != -1) && (new_id != line_id)) { @@ -3780,19 +3789,17 @@ int mpLineNextNonLeftWall(int line_id) int mpLinePrevNonLeftWall(int line_id) { MapLine* line; - CollVtx* vtx; int new_id; bool valid_id; LINEID_CHECK(4184, line_id); line = groundCollLine[line_id].x0; new_id = mpLineGetPrevCheckInline(line, line->prev_id1); - vtx = groundCollVtx; while (new_id != -1 && new_id != line_id && - !!(groundCollLine[new_id].flags & CollLine_LeftWall)) + groundCollLine[new_id].flags & CollLine_LeftWall) { line = groundCollLine[new_id].x0; new_id = line->prev_id1; - new_id = mpLineGetPrevCheckInlineVtx(line, new_id, vtx); + new_id = mpLineGetPrevCheckInline(line, new_id); } valid_id = false; if ((new_id != -1) && (new_id != line_id)) { @@ -3807,19 +3814,17 @@ int mpLinePrevNonLeftWall(int line_id) int mpLinePrevNonRightWall(int line_id) { MapLine* line; - CollVtx* vtx; int new_id; bool valid_id; LINEID_CHECK(4193, line_id); line = groundCollLine[line_id].x0; new_id = mpLineGetPrevCheckInline(line, line->prev_id1); - vtx = groundCollVtx; while (new_id != -1 && new_id != line_id && groundCollLine[new_id].flags & CollLine_RightWall) { line = groundCollLine[new_id].x0; new_id = line->prev_id1; - new_id = mpLineGetPrevCheckInlineVtx(line, new_id, vtx); + new_id = mpLineGetPrevCheckInline(line, new_id); } valid_id = false; if (new_id != -1 && new_id != line_id) { @@ -3887,9 +3892,47 @@ int mpLib_80053448_Floor(int line_id) static inline int mpLineGetNextInline(int line_id) { - MapLine* line = groundCollLine[line_id].x0; - int result = line->next_id1; + s32 result = groundCollLine[line_id].x0->next_id1; + + if (result != -1) { + u32 flags = groundCollLine[result].flags; + + if ((flags & LINE_FLAG_ENABLED) && !(flags & LINE_FLAG_HIDDEN)) { + CollVtx* v1 = &groundCollVtx[groundCollLine[line_id].x0->v1_idx]; + CollVtx* v0 = &groundCollVtx[groundCollLine[result].x0->v0_idx]; + + if (SQ(v1->pos.x - v0->pos.x) + SQ(v1->pos.y - v0->pos.y) < 4.0) { + return result; + } + } + } + + return groundCollLine[line_id].x0->next_id0; +} + +static inline int mpLineGetNextFloorInline(int line_id) +{ + MapLine* line; + int result = (line = groundCollLine[line_id].x0)->next_id1; + + if (result != -1) { + u32 flags = groundCollLine[result].flags; + if ((flags & LINE_FLAG_ENABLED) && !(flags & LINE_FLAG_HIDDEN)) { + CollVtx* v1 = &groundCollVtx[line->v1_idx]; + CollVtx* v0 = &groundCollVtx[groundCollLine[result].x0->v0_idx]; + + if (SQ(v1->pos.x - v0->pos.x) + SQ(v1->pos.y - v0->pos.y) < 4.0) { + return result; + } + } + } + + return line->next_id0; +} + +static inline int mpLineGetNextCheckInline2(int result, MapLine* line) +{ if (result != -1) { u32 flags = groundCollLine[result].flags; @@ -3908,37 +3951,83 @@ static inline int mpLineGetNextInline(int line_id) int mpLib_800534FC_Floor(int line_id) { + MapLine* line; int new_id; + int result; LINEID_CHECK(4272, line_id); - new_id = mpLineGetNextInline(line_id); + new_id = mpLineGetNextFloorInline(line_id); while (new_id != -1) { if (!(groundCollLine[new_id].flags & CollLine_Floor)) { new_id = -1; } else if (new_id != groundCollLine[line_id].x0->next_id1) { line_id = new_id; - new_id = mpLineGetNextInline(new_id); + new_id = mpLineGetNextCheckInline2( + (line = groundCollLine[new_id].x0)->next_id1, line); continue; } break; } if (new_id != -1) { - return new_id; + result = new_id; + } else { + result = -1; } - return -1; + return result; +} + +static inline int mpLineGetPrevInline(int line_id) +{ + MapLine* line; + int result = (line = groundCollLine[line_id].x0)->prev_id1; + + if (result != -1) { + u32 flags = groundCollLine[result].flags; + + if ((flags & LINE_FLAG_ENABLED) && !(flags & LINE_FLAG_HIDDEN)) { + CollVtx* v0 = &groundCollVtx[line->v0_idx]; + CollVtx* v1 = &groundCollVtx[groundCollLine[result].x0->v1_idx]; + + if (SQ(v0->pos.x - v1->pos.x) + SQ(v0->pos.y - v1->pos.y) < 4.0) { + return result; + } + } + } + + return line->prev_id0; +} + +static inline int mpLineGetPrevCheckInline2(int result, MapLine* line) +{ + if (result != -1) { + u32 flags = groundCollLine[result].flags; + + if ((flags & LINE_FLAG_ENABLED) && !(flags & LINE_FLAG_HIDDEN)) { + CollVtx* v0 = &groundCollVtx[line->v0_idx]; + CollVtx* v1 = &groundCollVtx[groundCollLine[result].x0->v1_idx]; + + if (SQ(v0->pos.x - v1->pos.x) + SQ(v0->pos.y - v1->pos.y) < 4.0) { + return result; + } + } + } + + return line->prev_id0; } int mpLib_800536CC_Floor(int line_id) { + MapLine* line; int new_id; int result; LINEID_CHECK(4293, line_id); - new_id = mpLineGetPrev(line_id); + new_id = mpLineGetPrevInline(line_id); while (new_id != -1) { if (!(groundCollLine[new_id].flags & CollLine_Floor)) { new_id = -1; } else if (new_id != groundCollLine[line_id].x0->prev_id1) { line_id = new_id; - new_id = mpLineGetPrev(new_id); + new_id = mpLineGetPrevCheckInline2( + (line = groundCollLine[new_id].x0)->prev_id1, line); continue; } break; @@ -3981,23 +4070,28 @@ int mpLib_80053950_Ceiling(int line_id) int mpLib_80053A04_Ceiling(int line_id) { + MapLine* line; + int result; int new_id; LINEID_CHECK(4334, line_id); - new_id = mpLineGetPrev(line_id); + new_id = mpLineGetPrevInline(line_id); while (new_id != -1) { if (!(groundCollLine[new_id].flags & CollLine_Ceiling)) { new_id = -1; } else if (new_id != groundCollLine[line_id].x0->prev_id1) { line_id = new_id; - new_id = mpLineGetPrev(new_id); + new_id = mpLineGetPrevCheckInline2( + (line = groundCollLine[new_id].x0)->prev_id1, line); continue; } break; } if (new_id != -1) { - return new_id; + result = new_id; + } else { + result = -1; } - return -1; + return result; } int mpLib_80053BD4_Ceiling(int line_id) @@ -4005,13 +4099,13 @@ int mpLib_80053BD4_Ceiling(int line_id) int result; int new_id; LINEID_CHECK(4355, line_id); - new_id = mpLineGetNext(line_id); + new_id = mpLineGetNextInline(line_id); while (new_id != -1) { if (!(groundCollLine[new_id].flags & CollLine_Ceiling)) { new_id = -1; } else if (new_id != groundCollLine[line_id].x0->next_id1) { line_id = new_id; - new_id = mpLineGetNext(new_id); + new_id = mpLineGetNextInline(new_id); continue; } break; @@ -4026,26 +4120,25 @@ int mpLib_80053BD4_Ceiling(int line_id) void mpLib_80053DA4_Floor(int line_id, Vec3* pos_out) { - int r29 = line_id; - s16 r5; - CollVtx* temp_r3; + s16 next_id; + CollVtx* vtx; - LINEID_CHECK(4428, r29); + LINEID_CHECK(4428, line_id); goto skip; loop: - r29 = r5; + line_id = next_id; skip: - r5 = groundCollLine[r29].x0->next_id0; - if (r5 != -1 && (groundCollLine[r5].flags & CollLine_Floor)) { + next_id = groundCollLine[line_id].x0->next_id0; + if (next_id != -1 && (groundCollLine[next_id].flags & CollLine_Floor)) { goto loop; } - LINEID_CHECK(4433, r29); + LINEID_CHECK(4433, line_id); - temp_r3 = &groundCollVtx[groundCollLine[r29].x0->v1_idx]; - pos_out->x = temp_r3->pos.x; - pos_out->y = temp_r3->pos.y; + vtx = &groundCollVtx[groundCollLine[line_id].x0->v1_idx]; + pos_out->x = vtx->pos.x; + pos_out->y = vtx->pos.y; pos_out->z = 0.0F; } @@ -4073,29 +4166,37 @@ void mpLib_80053ECC_Floor(int line_id, Vec* vec) vec->z = 0.0F; } +static inline u32 mpLineGetKindInline(int line_id) +{ + return groundCollLine[line_id].flags & LINE_FLAG_KIND; +} + void mpFloorGetRight(int line_id, Vec3* pos_out) { u32 kind; int new_id; - PAD_STACK(8); + int line_offset; LINEID_CHECK(4465, line_id); new_id = line_id; - kind = groundCollLine[line_id].flags & LINE_FLAG_KIND; - while (true) { - int good_id = new_id; - new_id = mpLineGetNext(new_id); + kind = mpLineGetKindInline(line_id); + do { + MapLine* line; + line_offset = new_id * sizeof(CollLine); + line = ((CollLine*) (line_offset + (int) groundCollLine))->x0; + new_id = line->next_id1; + new_id = mpLineGetNextCheckInline(line, new_id); + } while (new_id != -1 && + kind == (groundCollLine[new_id].flags & LINE_FLAG_KIND)); - if (new_id == -1 || - kind != (groundCollLine[new_id].flags & LINE_FLAG_KIND)) - { - CollVtx* vtx = &groundCollVtx[groundCollLine[good_id].x0->v1_idx]; - pos_out->x = vtx->pos.x; - pos_out->y = vtx->pos.y; - pos_out->z = 0.0F; - return; - } + { + CollVtx* vtx = + &groundCollVtx[((CollLine*) (line_offset + (int) groundCollLine)) + ->x0->v1_idx]; + pos_out->x = vtx->pos.x; + pos_out->y = vtx->pos.y; + pos_out->z = 0.0F; } } @@ -4103,6 +4204,7 @@ void mpFloorGetLeft(int line_id, Vec3* pos_out) { u32 kind; int new_id; + int line_offset; PAD_STACK(8); LINEID_CHECK(4474, line_id); @@ -4110,44 +4212,51 @@ void mpFloorGetLeft(int line_id, Vec3* pos_out) new_id = line_id; kind = groundCollLine[line_id].flags & LINE_FLAG_KIND; while (true) { - int good_id = new_id; + line_offset = new_id * sizeof(CollLine); new_id = mpLineGetPrev(new_id); - if (new_id == -1 || kind != (groundCollLine[new_id].flags & LINE_FLAG_KIND)) { - CollVtx* vtx = &groundCollVtx[groundCollLine[good_id].x0->v0_idx]; - pos_out->x = vtx->pos.x; - pos_out->y = vtx->pos.y; - pos_out->z = 0.0F; - return; + break; } } + + { + CollVtx* vtx = + &groundCollVtx[groundCollLine[line_offset / sizeof(CollLine)] + .x0->v0_idx]; + pos_out->x = vtx->pos.x; + pos_out->y = vtx->pos.y; + pos_out->z = 0.0F; + } } void mpCeilingGetRight(int line_id, Vec3* pos_out) { u32 kind; int new_id; - PAD_STACK(8); + int line_offset; LINEID_CHECK(4483, line_id); new_id = line_id; - kind = groundCollLine[line_id].flags & LINE_FLAG_KIND; - while (true) { - int good_id = new_id; - new_id = mpLineGetPrev(new_id); + kind = mpLineGetKindInline(line_id); + do { + MapLine* line; + line_offset = new_id * sizeof(CollLine); + line = ((CollLine*) (line_offset + (int) groundCollLine))->x0; + new_id = line->prev_id1; + new_id = mpLineGetPrevCheckInline(line, new_id); + } while (new_id != -1 && + !(kind != (groundCollLine[new_id].flags & LINE_FLAG_KIND))); - if (new_id == -1 || - kind != (groundCollLine[new_id].flags & LINE_FLAG_KIND)) - { - CollVtx* vtx = &groundCollVtx[groundCollLine[good_id].x0->v0_idx]; - pos_out->x = vtx->pos.x; - pos_out->y = vtx->pos.y; - pos_out->z = 0.0F; - return; - } + { + CollVtx* vtx = + &groundCollVtx[groundCollLine[line_offset / sizeof(CollLine)] + .x0->v0_idx]; + pos_out->x = vtx->pos.x; + pos_out->y = vtx->pos.y; + pos_out->z = 0.0F; } } @@ -4155,33 +4264,30 @@ void mpCeilingGetLeft(int line_id, Vec3* pos_out) { u32 kind; int new_id; - PAD_STACK(8); + int line_offset; LINEID_CHECK(4492, line_id); + if (line_id != -1) { + } new_id = line_id; - kind = groundCollLine[line_id].flags & LINE_FLAG_KIND; - while (true) { - int good_id = new_id; + kind = mpLineGetKindInline(line_id); + do { + line_offset = new_id * sizeof(CollLine); new_id = mpLineGetNext(new_id); + } while (new_id != -1 && + !(kind != (groundCollLine[new_id].flags & LINE_FLAG_KIND))); - if (new_id == -1 || - kind != (groundCollLine[new_id].flags & LINE_FLAG_KIND)) - { - CollVtx* vtx = &groundCollVtx[groundCollLine[good_id].x0->v1_idx]; - pos_out->x = vtx->pos.x; - pos_out->y = vtx->pos.y; - pos_out->z = 0.0F; - return; - } + { + CollVtx* vtx = + &groundCollVtx[groundCollLine[line_offset / sizeof(CollLine)] + .x0->v1_idx]; + pos_out->x = vtx->pos.x; + pos_out->y = vtx->pos.y; + pos_out->z = 0.0F; } } -static inline u32 mpLineGetKindInline(int line_id) -{ - return groundCollLine[line_id].flags & LINE_FLAG_KIND; -} - void mpLeftWallGetTop(int line_id, Vec3* pos_out) { u32 kind; @@ -4190,6 +4296,8 @@ void mpLeftWallGetTop(int line_id, Vec3* pos_out) LINEID_CHECK(4501, line_id); + if (line_id != -1) { + } new_id = line_id; kind = mpLineGetKindInline(line_id); do { @@ -4200,8 +4308,8 @@ void mpLeftWallGetTop(int line_id, Vec3* pos_out) { CollVtx* vtx = - &groundCollVtx[((CollLine*) ((u8*) groundCollLine + line_offset)) - ->x0->v1_idx]; + &groundCollVtx[groundCollLine[line_offset / sizeof(CollLine)] + .x0->v1_idx]; pos_out->x = vtx->pos.x; pos_out->y = vtx->pos.y; pos_out->z = 0.0F; @@ -4211,23 +4319,26 @@ void mpLeftWallGetTop(int line_id, Vec3* pos_out) void mpLeftWallGetBottom(int line_id, Vec3* pos_out) { u32 kind; - int new_id; int line_offset; + int new_id; LINEID_CHECK(4510, line_id); - new_id = line_id; kind = mpLineGetKindInline(line_id); + new_id = line_id; do { + MapLine* line; line_offset = new_id * sizeof(CollLine); - new_id = mpLineGetPrev(new_id); + line = ((CollLine*) (line_offset + (int) groundCollLine))->x0; + new_id = line->prev_id1; + new_id = mpLineGetPrevCheckInline(line, new_id); } while (new_id != -1 && - kind == (groundCollLine[new_id].flags & LINE_FLAG_KIND)); + !(kind != (groundCollLine[new_id].flags & LINE_FLAG_KIND))); { CollVtx* vtx = - &groundCollVtx[groundCollLine[line_offset / sizeof(CollLine)] - .x0->v0_idx]; + &groundCollVtx[((CollLine*) (line_offset + (int) groundCollLine)) + ->x0->v0_idx]; pos_out->x = vtx->pos.x; pos_out->y = vtx->pos.y; pos_out->z = 0.0F; @@ -4236,24 +4347,27 @@ void mpLeftWallGetBottom(int line_id, Vec3* pos_out) void mpRightWallGetTop(int line_id, Vec3* pos_out) { - u32 kind; - int new_id; int line_offset; + int new_id; + u32 kind; LINEID_CHECK(4519, line_id); new_id = line_id; kind = mpLineGetKindInline(line_id); do { + MapLine* line; line_offset = new_id * sizeof(CollLine); - new_id = mpLineGetPrev(new_id); + line = ((CollLine*) (line_offset + (int) groundCollLine))->x0; + new_id = line->prev_id1; + new_id = mpLineGetPrevCheckInline(line, new_id); } while (new_id != -1 && - kind == (groundCollLine[new_id].flags & LINE_FLAG_KIND)); + !(kind != (groundCollLine[new_id].flags & LINE_FLAG_KIND))); { CollVtx* vtx = - &groundCollVtx[groundCollLine[line_offset / sizeof(CollLine)] - .x0->v0_idx]; + &groundCollVtx[((CollLine*) (line_offset + (int) groundCollLine)) + ->x0->v0_idx]; pos_out->x = vtx->pos.x; pos_out->y = vtx->pos.y; pos_out->z = 0.0F; @@ -4271,8 +4385,11 @@ void mpRightWallGetBottom(int line_id, Vec3* pos_out) new_id = line_id; kind = mpLineGetKindInline(line_id); do { + MapLine* line; line_offset = new_id * sizeof(CollLine); - new_id = mpLineGetNext(new_id); + line = groundCollLine[new_id].x0; + new_id = line->next_id1; + new_id = mpLineGetNextCheckInline(line, new_id); } while (new_id != -1 && kind == (groundCollLine[new_id].flags & LINE_FLAG_KIND)); @@ -5036,6 +5153,19 @@ int mpLib_80056B34(int arg0, int* arg1) return temp->x4C[1]; } +static inline float sqrtf_store(float x, volatile float* y) +{ + if (x > 0.0F) { + double guess = __frsqrte((double) x); + guess = 0.5 * guess * (3.0 - guess * guess * x); + guess = 0.5 * guess * (3.0 - guess * guess * x); + guess = 0.5 * guess * (3.0 - guess * guess * x); + *y = (float) (x * guess); + return *y; + } + return x; +} + int mpJointFromLine(int line_id) { if (line_id != -1) { @@ -5067,6 +5197,7 @@ bool mpLib_80056C54(int line_id, Vec3* pos, int* line_id_out, Vec3* vec_out, float sp64; Vec3 sp58; Vec3 sp4C; + float sqrt_tmp[2]; float dist_f28; float total_dist_f27; float x_f2; @@ -5090,7 +5221,7 @@ bool mpLib_80056C54(int line_id, Vec3* pos, int* line_id_out, Vec3* vec_out, mpLineGetV1Pos(line_id, &sp4C); x_f2 = SQ(sp58.x - sp4C.x); y_f0 = SQ(sp58.y - sp4C.y); - dist_f28 = sqrtf(x_f2 + y_f0); + dist_f28 = sqrtf_store(x_f2 + y_f0, sqrt_tmp - 4); flags_r0 = mpLineGetKind(line_id); if (flags_r0 & 0xC) { total_dist_f27 += dist_f28; @@ -5125,7 +5256,7 @@ bool mpLib_80056C54(int line_id, Vec3* pos, int* line_id_out, Vec3* vec_out, mpLineGetV0Pos(line_id, &sp4C); x_f2 = SQ(sp58.x - sp4C.x); y_f0 = SQ(sp58.y - sp4C.y); - dist_f28 = sqrtf(x_f2 + y_f0); + dist_f28 = sqrtf_store(x_f2 + y_f0, sqrt_tmp - 5); flags_r0 = mpLineGetKind(line_id); if (flags_r0 & 0xC) { total_dist_f27 += dist_f28; @@ -5471,6 +5602,14 @@ void mpJointGetCb2(int joint_id, mpLib_Callback* cb, Ground** gr) *gr = joint->x30; } +static inline void mpLib_GetJointVtxRange(CollJoint* joint, int* start, + int* count) +{ + MapJoint* map_joint = joint->inner; + *start = map_joint->vtx_start; + *count = map_joint->vtx_count; +} + void mpLib_800581DC(int joint_id0, int joint_id1) { struct pair { @@ -5482,12 +5621,17 @@ void mpLib_800581DC(int joint_id0, int joint_id1) CollLine* line_base; int i; MapJoint* cd0; - int vcount0; - CollVtx* v0_r29; int vstart0; + int vcount0; - j0_r9 = &groundCollJoint[joint_id0]; - j1_r10 = &groundCollJoint[joint_id1]; + { + CollJoint* joint = &groundCollJoint[joint_id0]; + j0_r9 = joint; + } + { + CollJoint* joint = &groundCollJoint[joint_id1]; + j1_r10 = joint; + } line_base = groundCollLine; for (i = 0; i < 5; i++) { int j; @@ -5541,29 +5685,33 @@ void mpLib_800581DC(int joint_id0, int joint_id1) } } - cd0 = j0_r9->inner; /* r3 */ - vstart0 = cd0->vtx_start; /* r4 */ - vcount0 = cd0->vtx_count; /* r31 */ + mpLib_GetJointVtxRange(j0_r9, &vstart0, &vcount0); - v0_r29 = &groundCollVtx[vstart0]; // for every pair of verts - for (i = 0; i < vcount0; i++) { + for (i = 0; i < vcount0; i++, vstart0++) { + CollVtx* v0_r29; int v; /* r28 */ int vcount1; /* r27 */ int vid_r26; /* r26 */ - int vid; int vstart1_r4; MapJoint* cd1 = j1_r10->inner; - vstart1_r4 = cd1->vtx_start; + { + CollVtx* vtx = &groundCollVtx[vstart0]; + v0_r29 = vtx; + } + { + int start = cd1->vtx_start; + vstart1_r4 = start; + } vcount1 = cd1->vtx_count; - vid = vstart1_r4; vid_r26 = vstart1_r4; - for (v = 0; v < vcount1; v++, vid++, vid_r26++) { + for (v = 0; v < vcount1; v++, vid_r26++) { int var_r25; + CollVtx* v1 = &groundCollVtx[vid_r26]; // ensure they are nearby - if (!(ABS(v0_r29[i].pos.x - groundCollVtx[vid].pos.x) < 2.0) || - !(ABS(v0_r29[i].pos.y - groundCollVtx[vid].pos.y) < 2.0)) + if (!(ABS(v0_r29->pos.x - v1->pos.x) < 2.0) || + !(ABS(v0_r29->pos.y - v1->pos.y) < 2.0)) { continue; } @@ -5583,7 +5731,7 @@ void mpLib_800581DC(int joint_id0, int joint_id1) s16 lstart_r20; s16 lcount_r17; CollLine* iter_r3; - if (vstart0 + i == lines[i_r23].x0->v0_idx) { + if (vstart0 == lines->x0->v0_idx) { // if the first vert is that line's v0 // find every line with the second vert as v1 for (j = 0; j < 5; j++) { @@ -5595,31 +5743,35 @@ void mpLib_800581DC(int joint_id0, int joint_id1) iter_r3 = &line_base[lstart_r20]; for (k = 0; k < lcount_r17; k++) { if (vid_r26 == iter_r3->x0->v1_idx) { - lines[i_r23].x0->prev_id1 = lstart_r20 + k; + lines->x0->prev_id1 = lstart_r20 + k; iter_r3->x0->next_id1 = lstart_r24; } iter_r3++; } } - } else if (vstart0 + i == lines[i_r23].x0->v1_idx) { + } else if (vstart0 == lines->x0->v1_idx) { // else if the first vert is that line's v1 // find every line with the second vert as v0 for (j = 0; j < 5; j++) { int k; lcount_r17 = ((struct pair*) j1_r10->inner)[j].count; - lstart_r20 = - ((struct pair*) j1_r10->inner)[j].start; + { + s16 start = + ((struct pair*) j1_r10->inner)[j].start; + lstart_r20 = start; + } iter_r3 = &line_base[lstart_r20]; for (k = 0; k < lcount_r17; k++) { if (vid_r26 == iter_r3->x0->v0_idx) { - lines[i_r23].x0->next_id1 = lstart_r20 + k; + lines->x0->next_id1 = lstart_r20 + k; iter_r3->x0->prev_id1 = lstart_r24; } iter_r3++; } } } + lines++; lstart_r24++; } } @@ -6064,6 +6216,11 @@ void mpLib_DrawEcbs(CollData* cd) GXEnd(); } +static inline GXColor mpLib_CopyColor(GXColor color) +{ + return color; +} + static const GXColor mpLib_804D80E0 = { 0xFF, 0x37, 0x37, 0x80 }; static const GXColor mpLib_804D80E4 = { 0x37, 0x37, 0xFF, 0x80 }; @@ -6121,7 +6278,7 @@ void mpLib_DrawSnapping(void) pos_y = cd->cur_pos.y; inner_x = cd->cur_pos.x + cd->ecb.left.x; - mpLib_SetupDraw(left_snap_color); + mpLib_SetupDraw(mpLib_CopyColor(left_snap_color)); GXBegin(GX_LINESTRIP, GX_VTXFMT0, 5); GXPosition3f32(inner_x - cd->ledge_snap_x, @@ -6146,7 +6303,7 @@ void mpLib_DrawSnapping(void) if ((item_r28 = HSD_GObj_Entities->items) != NULL) { if (!var_r31) { Mtx sp7C; - PAD_STACK(0x40); + PAD_STACK(0x34); GXSetCullMode(GX_CULL_NONE); GXClearVtxDesc(); GXSetVtxDesc(GX_VA_POS, GX_DIRECT); @@ -6174,7 +6331,7 @@ void mpLib_DrawSnapping(void) } } -void mpLib_DrawMatchingLines(int value, int flag, GXColor color) +int mpLib_DrawMatchingLines(int value, int flag, GXColor color) { CollLine* line_r31; int count_r28; @@ -6638,24 +6795,19 @@ void mpLib_80059E60(void) void mpLib_DrawCrosses(s16* idx, int len, GXColor arg2) { Vec3 sp34; - s16* idx_ptr; Vec3* out_vtx; int i; Vec3* vtx; int idx_i; int out_count; - PAD_STACK(4); - out_vtx = (vtx = mpLib_80458888); - for (idx_ptr = &idx[idx_i = 0], out_count = 0; - idx_i < len && out_count < 0x80; idx_i++) - { - if (Ground_801C2D24(*idx_ptr, &sp34)) { + vtx = mpLib_80458888; + out_vtx = vtx; + for (idx_i = 0, out_count = 0; idx_i < len && out_count < 0x80; idx_i++) { + if (Ground_801C2D24(idx[idx_i], &sp34)) { + out_vtx[out_count] = sp34; out_count += 1; - *out_vtx = sp34; - out_vtx++; } - idx_ptr += 1; } if (!out_count) { @@ -6681,6 +6833,8 @@ enum { mpLib_ExitVtxIds = 0x80, }; +static char mpLib_DebugBoundsFormat[] = "B(%d,%d)-(%d,%d)\n"; + static s16 mpLib_ItemSpawnVtxIds[] = { 0x7F, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, 0x90, 0x91, 0x92, 0x93, 0, 0x20, 0x21, diff --git a/src/melee/pl/pltrick.c b/src/melee/pl/pltrick.c index 144a6a0d51..2aaf757449 100644 --- a/src/melee/pl/pltrick.c +++ b/src/melee/pl/pltrick.c @@ -361,7 +361,7 @@ void pl_80038144(HSD_GObj* attacker_gobj, HSD_GObj* victim_gobj, s32 x18d4_int, attacked_from_behind, source_ply); } -void pl_800384DC(HSD_GObj* gobj, int arg1, void* arg2) +void pl_800384DC(HSD_GObj* gobj, volatile int arg1, void* arg2) { Fighter* fp; plActionStats* acp; @@ -369,9 +369,9 @@ void pl_800384DC(HSD_GObj* gobj, int arg1, void* arg2) ft_800898B4_t* ev_data; union Struct2070 ev; union Struct2070 ev2; - union Struct2070 ev3; union Struct2070 ev4; - PAD_STACK(16); + union Struct2070 ev3; + PAD_STACK(20); fp = GET_FIGHTER(gobj); ev_data = arg2; @@ -383,7 +383,10 @@ void pl_800384DC(HSD_GObj* gobj, int arg1, void* arg2) ev2.x2070_int = ev.x2070_int; acp = Player_GetActionStats(fp->player_id); ev3.x2070_int = ev.x2070_int; - pl_80037BC0_inline(&acp->hits, &ev3); + { + union Struct2070* ev3_ptr = &ev3; + pl_80037BC0_inline(&acp->hits, ev3_ptr); + } if (ev_data != NULL) { temp = &acp->hits; @@ -401,7 +404,10 @@ void pl_800384DC(HSD_GObj* gobj, int arg1, void* arg2) acp->x358_hits.by_attack_counts[attack_id]) { ev4.x2070_int = ev.x2070_int; - pl_80037BC0_inline(&acp->x358_hits, &ev4); + { + union Struct2070* ev4_ptr = &ev4; + pl_80037BC0_inline(&acp->x358_hits, ev4_ptr); + } if (ev_data != NULL) { temp = &acp->x358_hits; diff --git a/src/melee/ty/toy.c b/src/melee/ty/toy.c index f36c583269..bca15d561e 100644 --- a/src/melee/ty/toy.c +++ b/src/melee/ty/toy.c @@ -223,7 +223,7 @@ bool _Toy_80304CC8_noinline(int arg0) inline static unsigned short* Toy_80304D30_idk(void) { if (gm_8016B498() || gm_801A4310() == GM_TOY_LOTTERY) { - return M2C_FIELD(&_Toy_804A26B8, unsigned short**, 0xCF); + return &Toy_804A284C[5]; } else { return gmMainLib_8015CC78(); } @@ -239,8 +239,7 @@ inline static bool Toy_80304D30_4B0C(int arg0) unsigned short* v; unsigned short s; if (gm_8016B498() || gm_801A4310() == GM_TOY_LOTTERY) { - s = M2C_FIELD(&_Toy_804A26B8, unsigned short*, 0xCD) | - M2C_FIELD(&_Toy_804A26B8, unsigned short*, 0xCE); + s = Toy_804A284C[3] | Toy_804A284C[4]; v = &s; } else { v = gmMainLib_8015CC84(); @@ -286,7 +285,7 @@ int _Toy_80304D30(void) for (i = 0; i < idk; i++) { if (1 < (unsigned int) i && i != 3) { if (!Toy_80304D30_4B0C(i)) { - M2C_FIELD(&_Toy_804A26B8, unsigned char*, 0x194) = 2; + *(unsigned char*) Toy_804A284C = 2; Toy_80305918(i, 0, 0); } } @@ -297,7 +296,7 @@ int _Toy_80304D30(void) } if (4 <= i && i <= 6) { if (!Toy_80304D30_4B0C(i)) { - M2C_FIELD(&_Toy_804A26B8, unsigned char*, 0x194) = 2; + *(unsigned char*) Toy_804A284C = 2; Toy_80305918(i, 0, 0); break; } @@ -413,19 +412,21 @@ s32 Toy_80305058(s32 arg0, s32 arg1, s32 arg2, f32 farg0) goto add_obtained; } } else { - add_obtained: - if (gm_8016B498() != 0 || (u8) gm_801A4310() == 0xC) { - flags = default_flags; - } else { - flags = gmMainLib_8015CC78(); - } - if ((u8) * (u16*) ((u8*) flags + byte_off) != 0) { - obtained_arr[obtained_count++] = trophy; - } else { - add_trophy: - new_arr[new_count++] = trophy; + if (arg2 == 0) { + add_obtained: + if (gm_8016B498() != 0 || (u8) gm_801A4310() == 0xC) { + flags = default_flags; + } else { + flags = gmMainLib_8015CC78(); + } + if ((u8) * (u16*) ((u8*) flags + byte_off) != 0) { + obtained_arr[obtained_count++] = trophy; + } else { + add_trophy: + new_arr[new_count++] = trophy; + } + total++; } - total++; } } trophy++; @@ -502,7 +503,7 @@ void _Toy_803053C4(s32 targetValue, s32 count, s32 flag) ptr = gmMainLib_8015CC78(); } - if ((u8) * (u16*) ((u8*) ptr + i) == 0) { + if ((u8) ptr[trophyId] == 0) { Toy_SetUnlockState((s16) trophyId, HSD_Randi(0xFE) + 1); @@ -513,7 +514,7 @@ void _Toy_803053C4(s32 targetValue, s32 count, s32 flag) ptr = gmMainLib_8015CC78(); } - ptr = (u16*) ((u8*) ptr + i); + ptr += trophyId; count = count - 1; *ptr ^= 0x8000; } @@ -529,16 +530,15 @@ void _Toy_803053C4(s32 targetValue, s32 count, s32 flag) } } } else { - default_flags = &Toy_804A284C[5]; i = 0; - trophyId = 0; + default_flags = &Toy_804A284C[5]; - while (trophyId < 0x125) { + while (i < 0x125) { list = _Toy_sbss_804D6EB4; if (lbLang_IsSettingUS()) { while (*list != -1) { - if (*list == trophyId) { + if (*list == i) { found = 0; goto check_found2; } @@ -549,8 +549,8 @@ void _Toy_803053C4(s32 targetValue, s32 count, s32 flag) check_found2: if (found != 0) { - if ((f32) targetValue == Toy_803060BC(trophyId, 6)) { - Toy_SetUnlockState((s16) trophyId, HSD_Randi(0xFE) + 1); + if ((f32) targetValue == Toy_803060BC(i, 6)) { + Toy_SetUnlockState((s16) i, HSD_Randi(0xFE) + 1); if (gm_8016B498() || (u8) gm_801A4310() == 0xC) { ptr = default_flags; @@ -558,7 +558,7 @@ void _Toy_803053C4(s32 targetValue, s32 count, s32 flag) ptr = gmMainLib_8015CC78(); } - ptr = (u16*) ((u8*) ptr + i); + ptr += i; count = count - 1; *ptr ^= 0x8000; @@ -568,8 +568,7 @@ void _Toy_803053C4(s32 targetValue, s32 count, s32 flag) } } - trophyId++; - i += 2; + i++; } } @@ -1302,6 +1301,7 @@ void Toy_803067BC(s32 arg0, s32 arg1) s32 i; s16* dest; s32 count; + s32 j; s16* base; base = _Toy_sbss_804D6E64; @@ -1321,9 +1321,10 @@ void Toy_803067BC(s32 arg0, s32 arg1) count = *gmMainLib_8015CC90(); src = base + arg0; + j = count; dest = Toy_sbss_804D6EDC + count; if (count != 0) { - for (i = count; i != 0; i--) { + for (; j != 0; j--) { *dest-- = *src; src += 3; } @@ -1350,6 +1351,7 @@ void Toy_80306954(HSD_GObj* gobj, int unused) char* tbl; char* entry; + tbl = _Toy_str_TyLight_dat; state = Toy_sbss_804D6ED4; if (HSD_CObjSetCurrent((HSD_CObj*) gobj->hsd_obj)) { if (_Toy_sbss_804D6E50 == 0) { @@ -1454,15 +1456,6 @@ void Toy_80306BB8(HSD_GObj* gobj) } } -static inline void _Toy_80306C5C_GetOffset(unsigned char idx, s32* offset) -{ - unsigned char tmp; - *offset = (tmp = idx) * 0xC; -} -static inline void _Toy_80306C5C_InitIdx(s32* idx) -{ - *idx = 0; -} void _Toy_80306C5C(HSD_GObj* arg0) { s32 idx; @@ -1470,13 +1463,14 @@ void _Toy_80306C5C(HSD_GObj* arg0) TyLightData* base; HSD_GObj* data; u8* table; - unsigned char pad; + unsigned char new_var; HSD_LObj* lobj; HSD_LObj* next; - void* unused1; - void* unused2; - _Toy_80306C5C_InitIdx(&idx); - _Toy_80306C5C_GetOffset(idx, &offset); + + PAD_STACK(16); + + idx = 0; + offset = (new_var = idx) * 0xC; base = (TyLightData*) Toy_sbss_804D6ED4; data = base->gobj; table = (u8*) base + offset; @@ -1495,7 +1489,7 @@ void _Toy_80306C5C(HSD_GObj* arg0) data = base->gobj; } - HSD_LObjAnimAll(arg0->hsd_obj); + HSD_LObjAnimAll(((HSD_GObj*) arg0)->hsd_obj); } void Toy_RemoveUserData(void* ptr) @@ -1526,7 +1520,7 @@ void Toy_80306D70(s32 arg0) s32 idx; u8 kind; - base = (TyLightFile*) 0x803FDD18; + base = (TyLightFile*) _Toy_str_TyLight_dat; data = (TyLightData*) Toy_sbss_804D6ED4; if (data->archive != NULL && data->gobj != NULL) { @@ -1567,34 +1561,29 @@ void Toy_80306D70(s32 arg0) HSD_LObj* Toy_LoadLObjList(LightList** list, s32* hasAnim) { + u8* base; HSD_LObj* lobj; - HSD_LObj* first; HSD_LObj* prev; + HSD_LObj* first; HSD_LightAnim** anims; - LightList** cur; s32 idx; - u8* base; u8* animFlag; - u8* posTable; PAD_STACK(4); prev = NULL; - cur = list; - idx = 0; base = (u8*) Toy_sbss_804D6ED4; + idx = 0; if (hasAnim != NULL) { *hasAnim = 0; } - posTable = base + idx * 0xC; - - while (*cur != NULL) { - lobj = HSD_LObjLoadDesc((*cur)->desc); + while (*list != NULL) { + lobj = HSD_LObjLoadDesc((*list)->desc); if (lobj != NULL) { animFlag = base + idx + 0xDC; - anims = (*cur)->anims; + anims = (*list)->anims; *animFlag = 0; if (anims != NULL && *anims != NULL) { if (hasAnim != NULL) { @@ -1606,9 +1595,8 @@ HSD_LObj* Toy_LoadLObjList(LightList** list, s32* hasAnim) *animFlag = 1; } } - HSD_LObjGetPosition(lobj, (Vec3*) (posTable + 0x1C)); - HSD_LObjGetInterest(lobj, (Vec3*) (posTable + 0x7C)); - posTable += 0xC; + HSD_LObjGetPosition(lobj, (Vec3*) (base + idx * 0xC + 0x1C)); + HSD_LObjGetInterest(lobj, (Vec3*) (base + idx * 0xC + 0x7C)); idx += 1; } if (prev != NULL) { @@ -1620,7 +1608,7 @@ HSD_LObj* Toy_LoadLObjList(LightList** list, s32* hasAnim) first = lobj; } prev = lobj; - cur++; + list++; } return first; } @@ -1780,21 +1768,31 @@ void _Toy_8030715C(f32 cstick_x, f32 cstick_y) 1, 7, 22, 20, 18, 21, 19, 17, 23, }; +typedef union ToyPanelLabelData { + char bytes[1]; + char* ptrs[1]; +} ToyPanelLabelData; + +inline static void Toy_AddPanelAnims(HSD_JObj* jobj, + HSD_ShapeAnimJoint* shapanim, + HSD_MatAnimJoint* matanim, + HSD_AnimJoint* anim) +{ + HSD_JObjAddAnimAll(jobj, anim, matanim, shapanim); +} + void Toy_80307470(s32 arg0) { ToyGlobalsS_* tg; - char* data; - HSD_AnimJoint* anim; - HSD_MatAnimJoint* matanim; - HSD_ShapeAnimJoint* shapanim; + ToyPanelLabelData* data; + char** label; HSD_Joint* joint; HSD_JObj* loaded_jobj; - char** label; u8 kind; PAD_STACK(24); - data = (void*) 0x803FDD18; + data = (ToyPanelLabelData*) _Toy_str_TyLight_dat; tg = (ToyGlobalsS_*) Toy_sbss_804D6ED8; if (tg->x50 == NULL) { @@ -1807,24 +1805,26 @@ void Toy_80307470(s32 arg0) tg->x0 = NULL; } - label = (char**) (data + arg0 * 4); + label = &data->ptrs[arg0]; joint = HSD_ArchiveGetPublicAddress(tg->x50, *(label += 0x188 / 4)); if (joint != NULL) { tg->x0 = GObj_Create(9, 9, 0); loaded_jobj = HSD_JObjLoadJoint(joint); - label = (char**) (data + arg0 * 0xC); - anim = HSD_ArchiveGetPublicAddress(tg->x50, label[0x224 / 4]); - matanim = HSD_ArchiveGetPublicAddress(tg->x50, label[0x228 / 4]); - shapanim = HSD_ArchiveGetPublicAddress(tg->x50, label[0x22C / 4]); - HSD_JObjAddAnimAll(loaded_jobj, anim, matanim, shapanim); + Toy_AddPanelAnims(loaded_jobj, + HSD_ArchiveGetPublicAddress( + tg->x50, (&data->ptrs[arg0 * 3])[0x22C / 4]), + HSD_ArchiveGetPublicAddress( + tg->x50, (&data->ptrs[arg0 * 3])[0x228 / 4]), + HSD_ArchiveGetPublicAddress( + tg->x50, (&data->ptrs[arg0 * 3])[0x224 / 4])); HSD_JObjReqAnimAll(loaded_jobj, 0.0f); kind = HSD_GObj_804D7849; HSD_GObjObject_80390A70(tg->x0, kind, loaded_jobj); GObj_SetupGXLink(tg->x0, HSD_GObj_JObjCallback, 0x3C, 0); - lb_8001204C(loaded_jobj, (void*) ((u8*) tg + 0x10), _Toy_803FE3F8, 9); + lb_8001204C(loaded_jobj, (HSD_JObj**) &tg->x10, _Toy_803FE3F8, 9); Toy_803083D8(tg->x30, 0x3E7); return; @@ -1841,14 +1841,13 @@ void _Toy_803075E8(s32 arg0) HSD_Joint* joint; char** ptr; HSD_JObj* jobj; - HSD_AnimJoint* animjoint; - HSD_MatAnimJoint* matanim; HSD_ShapeAnimJoint* shapanim; ToyDataJObj* tdjobj; u8 kind; PAD_STACK(88); + data = _Toy_str_TyLight_dat; td = (ToyED8Data*) Toy_sbss_804D6ED8; if (td->archive == NULL) { @@ -1878,15 +1877,16 @@ void _Toy_803075E8(s32 arg0) HSD_GObjObject_80390A70(td->gobj, kind, jobj); GObj_SetupGXLink(td->gobj, HSD_GObj_JObjCallback, 0x33, 0); - ptr = (char**) (data + arg0 * 0xC); - animjoint = - HSD_ArchiveGetPublicAddress(td->archive, ptr[0x290 / 4]); - matanim = HSD_ArchiveGetPublicAddress(td->archive, ptr[0x294 / 4]); + arg0 = (u32) data + arg0 * 0xC; + ptr = ((ToyPanelLabelData*) arg0)->ptrs; + joint = HSD_ArchiveGetPublicAddress(td->archive, ptr[0x290 / 4]); + data = HSD_ArchiveGetPublicAddress(td->archive, ptr[0x294 / 4]); shapanim = HSD_ArchiveGetPublicAddress(td->archive, ptr[0x298 / 4]); - if (animjoint != NULL || matanim != NULL || shapanim != NULL) { - HSD_JObjAddAnimAll(jobj, animjoint, matanim, shapanim); + if (joint != NULL || data != NULL || shapanim != NULL) { + HSD_JObjAddAnimAll(jobj, (HSD_AnimJoint*) joint, + (HSD_MatAnimJoint*) data, shapanim); HSD_JObjReqAnimAll(jobj, 0.0f); HSD_JObjAnimAll(jobj); HSD_GObj_SetupProc(td->gobj, Toy_80306BB8, 0); @@ -2076,25 +2076,25 @@ void Toy_80307E84(HSD_GObj* gobj) void _Toy_80307F64(s32 arg0, s32 arg1) { s8 idx; - s32 kind = arg0; - s32* base; - HSD_JObj* jobj2; + Toy26B8* base; ToyAnimState* state; HSD_JObj* jobj1; - base = (s32*) &_Toy_804A26B8; - idx = ((Toy26B8*) base)->anim.x0E; - jobj1 = (HSD_JObj*) base[idx + (0x3F4 / 4)]; - jobj2 = (HSD_JObj*) base[(idx ^ 1) + (0x3F4 / 4)]; - state = &((Toy26B8*) base)->anim; + HSD_JObj* jobj2; - if (((Toy26B8*) base)->anim.x0F == 0) { + base = (Toy26B8*) &_Toy_804A26B8; + state = &base->anim; + idx = base->anim.x0E; + jobj1 = base->anim.jobj[(s32) idx]; + jobj2 = base->anim.jobj[(s32) (idx ^ 1)]; + + if (base->anim.x0F == 0) { if (arg1 != 0) { - if (kind != state->x11) { + if (arg0 != state->x11) { HSD_JObjRemoveAnimAll(jobj1); HSD_JObjRemoveAnimAll(jobj2); - state->x11 = kind; - state->x10 = kind; - if (kind == 1) { + state->x11 = (s8) arg0; + state->x10 = (s8) arg0; + if (arg0 == 1) { Toy_80306A48( jobj1, 0, "ToyStandModel_TopN_ACTION_action1_matanim_joint", 0, @@ -2118,7 +2118,7 @@ void _Toy_80307F64(s32 arg0, s32 arg1) HSD_GObj_80390CD4(state->gobj); } } else { - if (kind == 1) { + if (arg0 == 1) { Toy_80306A48(jobj1, 0, "ToyStandModel_TopN_ACTION_action1_matanim_joint", 0, Toy_sbss_804D6EC8, 10); @@ -2126,14 +2126,12 @@ void _Toy_80307F64(s32 arg0, s32 arg1) "ToyStandModel_TopN_ACTION_action1_matanim_joint", 0, Toy_sbss_804D6EC8, 10); } else { - Toy_80306A48( - jobj1, 0, - "ToyStandModel_TopN_ACTION_action1_shapeanim_joint", 0, - Toy_sbss_804D6EC8, 10); - Toy_80306A48( - jobj2, 0, - "ToyStandModel_TopN_ACTION_action1_shapeanim_joint", 0, - Toy_sbss_804D6EC8, 10); + Toy_80306A48(jobj1, 0, + "ToyStandModel_TopN_ACTION_action2_matanim_joint", + 0, Toy_sbss_804D6EC8, 10); + Toy_80306A48(jobj2, 0, + "ToyStandModel_TopN_ACTION_action2_matanim_joint", + 0, Toy_sbss_804D6EC8, 10); } HSD_JObjRemoveAnimAll(jobj1); HSD_JObjRemoveAnimAll(jobj2); @@ -2142,7 +2140,7 @@ void _Toy_80307F64(s32 arg0, s32 arg1) } } -char* Toy_8030813C(s16 arg0, enum_t unused) +char* Toy_8030813C(s32 arg0, enum_t unused) { char* ptr; s32 i; @@ -2190,7 +2188,9 @@ char* Toy_8030813C(s16 arg0, enum_t unused) void Toy_80308250(u8* arg0, s32 arg1, s32 arg2) { +#ifdef __MWERKS__ char* Toy_8030813C(s16 arg0, enum_t unused); +#endif void* sym; char* ptr; ptr = Toy_8030813C(arg1, arg1); @@ -2215,9 +2215,9 @@ s32 Toy_803082F8(s16 idx) return Toy_803063D4((s16) Toy_80308354(idx), 2, 0x128); } -void Toy_80308328(s32 arg0) +s32 Toy_80308328(s32 arg0) { - Toy_803063D4((s16) arg0, 2, 0x128); + return Toy_803063D4((s16) arg0, 2, 0x128); } s32 Toy_80308354(s16 idx) @@ -2392,7 +2392,6 @@ HSD_GObj* Toy_803087F4(void* arg0) HSD_Joint* joint; s16 trophy_id; char* model_name; - f32 v1, v2, v3, v4, v5; f32 scale, rot; UNUSED u8 pad[0x10]; char buf[0x48]; @@ -2402,8 +2401,15 @@ HSD_GObj* Toy_803087F4(void* arg0) anim = &Toy_804A2AA8; if (entry->x14 == NULL) { +#ifdef __MWERKS__ + char* Toy_8030813C(); +#endif trophy_id = entry->x10; +#ifdef __MWERKS__ + model_name = Toy_8030813C(trophy_id); +#else model_name = Toy_8030813C(trophy_id, trophy_id); +#endif if (entry->x14 != NULL) { lbArchive_80016EFC(entry->x14); entry->x14 = NULL; @@ -2457,21 +2463,18 @@ HSD_GObj* Toy_803087F4(void* arg0) DevText_Erase(_Toy_sbss_804D6E9C); DevText_SetCursorXY(_Toy_sbss_804D6E9C, 0, 0); - v5 = Toy_803060BC((s32) anim->xC, 5); - v4 = Toy_803060BC((s32) anim->xC, 4); - v3 = Toy_803060BC((s32) anim->xC, 3); - v2 = Toy_803060BC((s32) anim->xC, 2); - v1 = Toy_803060BC((s32) anim->xC, 1); - - sprintf(buf, - "X %3.2f\n" - "Y %3.2f\n" - "Z %3.2f\n" - "MS %3.2f\n" - "SS %3.2f\n" - "MD %3.2f", - - Toy_803060BC((s32) anim->xC, 0), v1, v2, v3, v4, v5); + sprintf( + buf, + "X %3.2f\n" + "Y %3.2f\n" + "Z %3.2f\n" + "MS %3.2f\n" + "SS %3.2f\n" + "MD %3.2f", + + Toy_803060BC((s32) anim->xC, 0), Toy_803060BC((s32) anim->xC, 1), + Toy_803060BC((s32) anim->xC, 2), Toy_803060BC((s32) anim->xC, 3), + Toy_803060BC((s32) anim->xC, 4), Toy_803060BC((s32) anim->xC, 5)); DevText_Print(_Toy_sbss_804D6E9C, buf); } @@ -2745,21 +2748,25 @@ f32 _Toy_80309338(Vec3* arg0, Vec3* arg1) void _Toy_80309404(HSD_GObj* gobj) { - UNUSED u8 eye_pad[0x48]; + struct { + u8 pad[0x2C]; + Vec3 pos; + u8 pad2[0x10]; + } eye_pad; Vec3 eye_pos; - Vec3 transition_eye; - Vec3 transition_interest; - ToyCameraControl* ed4; HSD_CObj* cobj; + Vec3 transition_interest; + Vec3 transition_eye; Toy26B8* base; - void* ed8; + ToyED8Data* ed8; Toy6E68* state; + ToyCameraControl* ed4; ToyAnimState* anim; f32 dist; f32 tmp; - f32 rotate_update; - f32 movement_update; f32 zoom_update; + f32 movement_update; + f32 rotate_update; u32 trigger; u32 button; s32 sign; @@ -2768,17 +2775,17 @@ void _Toy_80309404(HSD_GObj* gobj) s32 sp130; s32 sp12C; - PAD_STACK(256); + PAD_STACK(260); cobj = gobj->hsd_obj; - base = _Toy_804A26B8.x0; + base = (Toy26B8*) &_Toy_804A26B8; ed8 = Toy_sbss_804D6ED8; state = _Toy_sbss_804D6E68; anim = &base->anim; ed4 = (ToyCameraControl*) Toy_sbss_804D6ED4; - rotate_update = 0.0f; - movement_update = 0.0f; zoom_update = 0.0f; + movement_update = 0.0f; + rotate_update = 0.0f; HSD_CObjGetEyePosition(cobj, &eye_pos); dist = _Toy_80309338(&eye_pos, NULL); @@ -2803,6 +2810,7 @@ void _Toy_80309404(HSD_GObj* gobj) } state->x34 = Toy_80305DB0(); + state->x54 = 0.0f; state->x50 = 0.0f; @@ -2952,12 +2960,21 @@ void _Toy_80309404(HSD_GObj* gobj) _Toy_sbss_804D6E88 = HSD_CObjGetRight(cobj); _Toy_sbss_804D6E8C = HSD_CObjGetLeft(cobj); state->x5C = 0; - state->x0->x24 = 0; - state->x0->x20 = 0x480000; - state->x4->x24 = 0; - state->x4->x20 = 0; - state->xC->x24 = 0; - state->xC->x20 = 0; + { + ToyTransitionObj* obj = state->x0; + obj->x24 = 0; + obj->x20 = 0x480000; + } + { + ToyTransitionObj* obj = state->x4; + obj->x24 = 0; + obj->x20 = 0; + } + { + ToyTransitionObj* obj = state->xC; + obj->x24 = 0; + obj->x20 = 0; + } state->x61 = 1; _Toy_8030715C(0.0f, 0.0f); return; @@ -2975,13 +2992,14 @@ void _Toy_80309404(HSD_GObj* gobj) ToyJObjNode* jobj_node; _Toy_sbss_804D6E58 ^= 1; - jobj_node = (ToyJObjNode*) ((ToyED8Data*) ed8)->xC->x28; if (_Toy_sbss_804D6E58 != 0) { + jobj_node = (ToyJObjNode*) Toy_sbss_804D6ED8->xC->x28; while (jobj_node != NULL) { jobj_node->x40 = 9; jobj_node = (ToyJObjNode*) jobj_node->x4; } } else { + jobj_node = (ToyJObjNode*) Toy_sbss_804D6ED8->xC->x28; while (jobj_node != NULL) { jobj_node->x40 = 8; jobj_node = (ToyJObjNode*) jobj_node->x4; @@ -3000,13 +3018,23 @@ void _Toy_80309404(HSD_GObj* gobj) _Toy_sbss_804D6E88 = HSD_CObjGetRight(cobj); _Toy_sbss_804D6E8C = HSD_CObjGetLeft(cobj); - state->x0->x24 = 0; - state->x0->x20 = 0x50480000; - state->x4->x24 = 0; - state->x4->x20 = (s32) 0x80000000U; - state->xC->x24 = 0; - state->xC->x20 = 0x40000000; - jobj_node = (ToyJObjNode*) ((ToyED8Data*) ed8)->xC->x28; + { + ToyTransitionObj* obj = state->x0; + obj->x24 = 0; + obj->x20 = 0x50480000; + } + { + ToyTransitionObj* obj = state->x4; + obj->x24 = 0; + obj->x20 = (s32) 0x80000000U; + } + { + ToyTransitionObj* obj = state->xC; + obj->x24 = 0; + obj->x20 = 0x40000000; + } + jobj_node = + (ToyJObjNode*) Toy_sbss_804D6ED8->xC->x28; while (jobj_node != NULL) { jobj_node->x40 = 9; jobj_node = (ToyJObjNode*) jobj_node->x4; @@ -3015,7 +3043,7 @@ void _Toy_80309404(HSD_GObj* gobj) state->x5C = 0; transition_eye = _Toy_803B88E0; transition_interest = _Toy_803B88EC; - HSD_CObjGetEyePosition(cobj, &eye_pos); + HSD_CObjGetEyePosition(cobj, &eye_pad.pos); transition_eye.y = 8.0f; HSD_CObjGetInterest(cobj, &transition_interest); base->x0.x = (transition_eye.x - transition_interest.x) / 10.0f; @@ -3028,9 +3056,8 @@ void _Toy_80309404(HSD_GObj* gobj) trigger = Toy_80305B88(); - if ((state->x44 + (state->x40 + (state->x30 + state->x34)) + - (f32) trigger) == 0.0f) - { + tmp = state->x44 + (state->x40 + (state->x30 + state->x34)); + if ((tmp + (f32) trigger) == 0.0f) { state->x5C = state->x5C + 1; } else { state->x5C = 0; @@ -3097,6 +3124,8 @@ void _Toy_80309404(HSD_GObj* gobj) } } else { _Toy_803102C4(0); + } + if ((state->x50 != 0.0f) || (state->x54 != 0.0f)) { movement_update = 1.0f; } @@ -3411,7 +3440,7 @@ void _Toy_80309404(HSD_GObj* gobj) } } _Toy_803084A0(display->selected_entry->trophy_id); - Toy_803083D8(((ToyED8Data*) ed8)->x30, + Toy_803083D8(ed8->x30, (s32) display->selected_entry->trophy_id); state->x60 = 0x14; } @@ -3433,10 +3462,13 @@ void _Toy_80309404(HSD_GObj* gobj) trigger = Toy_80305B88(); if (trigger & 0x10) { + ToyCameraControl* camera; + _Toy_80307828(0); - ed4->x10 = 0; - Toy_80306D70(ed4->x10); - _Toy_803075E8(ed4->x10); + camera = (ToyCameraControl*) Toy_sbss_804D6ED4; + camera->x10 = 0; + Toy_80306D70(camera->x10); + _Toy_803075E8(camera->x10); anim->x11 = 2; anim->x10 = 2; anim->x0F = 0; @@ -3459,7 +3491,7 @@ void _Toy_80309404(HSD_GObj* gobj) void _Toy_8030B530(HSD_GObj* arg0) { HSD_GObj* gobj = arg0; - Toy26B8* base = _Toy_804A26B8.x0; + Toy26B8* base = (Toy26B8*) &_Toy_804A26B8; HSD_CObj* cobj = gobj->hsd_obj; Toy6E68* state = (Toy6E68*) _Toy_sbss_804D6E68; void* ed8 = Toy_sbss_804D6ED8; @@ -3485,7 +3517,7 @@ void _Toy_8030B530(HSD_GObj* arg0) s32 sp188; s32 sp184; - PAD_STACK(312); + PAD_STACK(272); { void* anim_state_ptr = M2C_FIELD(anim, void**, 0x0); @@ -3571,7 +3603,6 @@ void _Toy_8030B530(HSD_GObj* arg0) } trigger = Toy_80305B88(); - (void) trigger; if (trigger & 0x10) { lbAudioAx_80024030(0); @@ -3610,26 +3641,32 @@ void _Toy_8030B530(HSD_GObj* arg0) { u8 mode = state->x61; if ((s8) mode == 0) { - *(s32*) (M2C_FIELD(state, u8**, 0x00) + 0x24) = 0; - *(s32*) (M2C_FIELD(state, u8**, 0x00) + 0x20) = 0x480000; - *(s32*) (M2C_FIELD(state, u8**, 0x04) + 0x24) = 0; - *(s32*) (M2C_FIELD(state, u8**, 0x04) + 0x20) = 0; - *(s32*) (M2C_FIELD(state, u8**, 0x0C) + 0x24) = 0; - *(s32*) (M2C_FIELD(state, u8**, 0x0C) + 0x20) = 0; + ToyTransitionObj* transition = state->x0; + transition->x24 = 0; + transition->x20 = 0x480000; + transition = state->x4; + transition->x24 = 0; + transition->x20 = 0; + transition = state->xC; + transition->x24 = 0; + transition->x20 = 0; state->x61 = 1; state->x5C = 0; return; } if ((s8) mode == 2) { + ToyTransitionObj* transition; state->x5C = 0; _Toy_80307828(0); - *(s32*) (M2C_FIELD(state, u8**, 0x00) + 0x24) = 0; - *(s32*) (M2C_FIELD(state, u8**, 0x00) + 0x20) = 0x50480000; - *(s32*) (M2C_FIELD(state, u8**, 0x04) + 0x24) = 0; - *(s32*) (M2C_FIELD(state, u8**, 0x04) + 0x20) = - (s32) 0x80000000U; - *(s32*) (M2C_FIELD(state, u8**, 0x0C) + 0x24) = 0; - *(s32*) (M2C_FIELD(state, u8**, 0x0C) + 0x20) = 0x40000000; + transition = state->x0; + transition->x24 = 0; + transition->x20 = 0x50480000; + transition = state->x4; + transition->x24 = 0; + transition->x20 = (s32) 0x80000000U; + transition = state->xC; + transition->x24 = 0; + transition->x20 = 0x40000000; state->x5C = 0; state->x61 = 3; lbAudioAx_80024030(0); @@ -3657,10 +3694,11 @@ void _Toy_8030B530(HSD_GObj* arg0) } HSD_JObjAddRotationY(jobj_next, 0.017453292f * adj_x); - _Toy_803062EC((s32) anim->xC, 5U, 57.29578f * jobj_next->rotate.y); + _Toy_803062EC((s32) anim->xC, 5U, + 57.29578f * HSD_JObjGetRotationY(jobj_next)); { - f32 abs_y = (adj_y < 0.0f) ? -adj_y : adj_y; + f32 abs_y = ABS(adj_y); if (abs_y > 0.8f) { f32 dist = state->x20; state->x20 = (f32) - ((dist * (0.025f * adj_y)) - dist); @@ -3705,37 +3743,37 @@ void _Toy_8030B530(HSD_GObj* arg0) angle = lb_8000D008(adj_y, adj_x); if (state->x18 < -25.0f) { - f32 abs_x2 = (adj_x < 0.0f) ? -adj_x : adj_x; + f32 abs_x2 = ABS(adj_x); if (abs_x2 > 0.8f) { f32 dx = 0.01f * cosf(angle); HSD_JObjAddTranslationX(jobj_next, dx); _Toy_803062EC((s32) anim->xC, 0U, - jobj_next->translate.x); + HSD_JObjGetTranslationX(jobj_next)); } { - f32 abs_y2 = (adj_y < 0.0f) ? -adj_y : adj_y; + f32 abs_y2 = ABS(adj_y); if (abs_y2 > 0.8f) { f32 dz = 0.01f * -sinf(angle); HSD_JObjAddTranslationZ(jobj_next, dz); _Toy_803062EC((s32) anim->xC, 2U, - jobj_next->translate.z); + HSD_JObjGetTranslationZ(jobj_next)); } } } else { - f32 abs_x3 = (adj_x < 0.0f) ? -adj_x : adj_x; + f32 abs_x3 = ABS(adj_x); if (abs_x3 > 0.8f) { f32 dx = 0.01f * cosf(angle); HSD_JObjAddTranslationX(jobj_next, dx); _Toy_803062EC((s32) anim->xC, 0U, - jobj_next->translate.x); + HSD_JObjGetTranslationX(jobj_next)); } { - f32 abs_y3 = (adj_y < 0.0f) ? -adj_y : adj_y; + f32 abs_y3 = ABS(adj_y); if (abs_y3 > 0.8f) { f32 dy = 0.01f * sinf(angle); HSD_JObjAddTranslationY(jobj_next, dy); _Toy_803062EC((s32) anim->xC, 1U, - jobj_next->translate.y); + HSD_JObjGetTranslationY(jobj_next)); } } } @@ -3781,7 +3819,7 @@ void _Toy_8030B530(HSD_GObj* arg0) HSD_JObjAddScaleX(n2, -0.01f); HSD_JObjAddScaleZ(n2, -0.01f); _Toy_803062EC((s32) anim->xC, 4U, - n2->scale.x); + HSD_JObjGetScaleX(n2)); } btn10 = Toy_80305C44(); if (btn10 & 1) { @@ -3798,7 +3836,7 @@ void _Toy_8030B530(HSD_GObj* arg0) HSD_JObjAddScaleX(n2, 0.01f); HSD_JObjAddScaleZ(n2, 0.01f); _Toy_803062EC((s32) anim->xC, 4U, - n2->scale.x); + HSD_JObjGetScaleX(n2)); } btn10 = Toy_80305C44(); if (btn10 & 2) { @@ -3812,7 +3850,7 @@ void _Toy_8030B530(HSD_GObj* arg0) HSD_JObjAddScaleY(jobj_next, -0.01f); HSD_JObjAddScaleZ(jobj_next, -0.01f); _Toy_803062EC((s32) anim->xC, 3U, - jobj_next->scale.x); + HSD_JObjGetScaleX(jobj_next)); btn10 = Toy_80305C44(); if (btn10 & 4) { state->x60 = 8; @@ -3824,7 +3862,8 @@ void _Toy_8030B530(HSD_GObj* arg0) HSD_JObjAddScaleX(jobj_next, 0.01f); HSD_JObjAddScaleY(jobj_next, 0.01f); HSD_JObjAddScaleZ(jobj_next, 0.01f); - _Toy_803062EC((s32) anim->xC, 3U, jobj_next->scale.x); + _Toy_803062EC((s32) anim->xC, 3U, + HSD_JObjGetScaleX(jobj_next)); btn10 = Toy_80305C44(); if (btn10 & 8) { state->x60 = 8; @@ -3947,8 +3986,7 @@ void _Toy_8030B530(HSD_GObj* arg0) } else { cnt = *gmMainLib_8015CC90(); } - lk = cnt; - lk += cur_idx; + lk = cnt + cur_idx; entry = M2C_FIELD(display, u8**, 0x138); { s16 tid = Toy_sbss_804D6EDC[lk - 1]; @@ -4125,14 +4163,15 @@ void _Toy_8030B530(HSD_GObj* arg0) } { + f32 moved_x = 0.3f * adj_sx; + f32 moved_y = 0.3f * adj_sy; f32 top = HSD_CObjGetTop(cobj); f32 bottom = HSD_CObjGetBottom(cobj); f32 right = HSD_CObjGetRight(cobj); f32 left = HSD_CObjGetLeft(cobj); - f32 left_copy = left; if (HSD_PadCopyStatus[1].trigger & 0x1000) { - OSReport("top = %f, bottom = %f, right = %f, left = %f\n", - (u32) (s32) left_copy, top, bottom, right, left_copy); + OSReport("top = %f, bottom = %f, right = %f, left = %f\n", top, + bottom, right, left); return; } if (HSD_PadCopyStatus[1].button & 8) { @@ -4152,29 +4191,36 @@ void _Toy_8030B530(HSD_GObj* arg0) return; } if (HSD_PadCopyStatus[1].button & 1) { - f32 nr = HSD_CObjGetRight(cobj) - 0.001f; - f32 nl = HSD_CObjGetLeft(cobj) - 0.001f; + f32 nr = HSD_CObjGetRight(cobj); + f32 nl = HSD_CObjGetLeft(cobj); + nr -= 0.001f; + nl -= 0.001f; HSD_CObjSetRight(cobj, nr); HSD_CObjSetLeft(cobj, nl); OSReport("right = %f, left = %f\n", nr, nl); return; } if (HSD_PadCopyStatus[1].button & 2) { - f32 nr = HSD_CObjGetRight(cobj) + 0.001f; - f32 nl = HSD_CObjGetLeft(cobj) + 0.001f; + f32 nr = HSD_CObjGetRight(cobj); + f32 nl = HSD_CObjGetLeft(cobj); + nr += 0.001f; + nl += 0.001f; HSD_CObjSetRight(cobj, nr); HSD_CObjSetLeft(cobj, nl); OSReport("right = %f, left = %f\n", nr, nl); return; } - _Toy_8030715C(0.3f * adj_sx, 0.3f * adj_sy); + _Toy_8030715C(moved_x, moved_y); } } } void _Toy_8030E110(HSD_GObj* arg0) { - Vec3 sp140; + struct { + Vec3 vec; + u8 pad[8]; + } sp140; Vec3 sp134; Vec3 sp128; void* spD8; @@ -4196,9 +4242,9 @@ void _Toy_8030E110(HSD_GObj* arg0) s16 trophy_id; HSD_Archive* archive; - PAD_STACK(176); + PAD_STACK(168); - base = _Toy_804A26B8.x0; + base = (Toy26B8*) &_Toy_804A26B8; anim = &base->anim; state = (Toy6E68*) _Toy_sbss_804D6E68; ed4 = Toy_sbss_804D6ED4; @@ -4351,15 +4397,12 @@ void _Toy_8030E110(HSD_GObj* arg0) state->x5C = 0; sp134 = _Toy_803B88F8; sp128 = _Toy_803B8904; - HSD_CObjGetEyePosition(cobj, &sp140); + HSD_CObjGetEyePosition(cobj, &sp140.vec); sp134.y = 8.0f; HSD_CObjGetInterest(cobj, &sp128); - M2C_FIELD(_Toy_804A26B8.x0, f32*, 0x0) = - (f32) ((sp134.x - sp128.x) / 10.0f); - M2C_FIELD(_Toy_804A26B8.x0, f32*, 0x4) = - (f32) ((sp134.y - sp128.y) / 10.0f); - M2C_FIELD(_Toy_804A26B8.x0, f32*, 0x8) = - (f32) ((sp134.z - sp128.z) / 10.0f); + base->x0.x = (f32) ((sp134.x - sp128.x) / 10.0f); + base->x0.y = (f32) ((sp134.y - sp128.y) / 10.0f); + base->x0.z = (f32) ((sp134.z - sp128.z) / 10.0f); _Toy_sbss_804D6E90 = (state->x20 - 38.0f) / 10.0f; _Toy_sbss_804D6E94 = state->x18 / 10.0f; state->x61 = 3; @@ -4412,7 +4455,6 @@ void _Toy_8030E110(HSD_GObj* arg0) gm_801677E8(0); } else { button = HSD_PadCopyStatus[1].button; - (void) button; if (button != 0) { gm_801677E8(1); } else { @@ -4501,120 +4543,7 @@ void _Toy_8030E110(HSD_GObj* arg0) return; } } - if (!(state->x30 < 0.0f)) { - trigger = Toy_80305B88(); - if (trigger & 0x441) { - goto cycle_prev; - } - if (!(state->x30 > 0.0f)) { - trigger = Toy_80305B88(); - if (trigger & 0x822) { - goto cycle_next; - } - } else { - cycle_next: - lbAudioAx_80024030(2); - display->selectedIdx = - (s16) (display->selectedIdx + 1); - { - s32 tc2; - if ((gm_8016B498() != 0) || - (gm_801A4310() == 0xC)) - { - tc2 = base->trophy_count; - } else { - tc2 = *gmMainLib_8015CC90(); - } - if (display->selectedIdx >= tc2) { - display->selectedIdx = 0; - } - } - { - s32 tc3; - if ((gm_8016B498() != 0) || - (gm_801A4310() == 0xC)) - { - tc3 = base->trophy_count; - } else { - tc3 = *gmMainLib_8015CC90(); - } - if (tc3 > 3) { - s32 tc4; - s16 cur_trophy; - s32 next_idx; - if ((gm_8016B498() != 0) || - (gm_801A4310() == 0xC)) - { - tc4 = base->trophy_count; - } else { - tc4 = *gmMainLib_8015CC90(); - } - cur_trophy = display->selectedIdx; - next_idx = (s32) (cur_trophy + 1); - if (next_idx >= tc4) { - s32 tc5; - if ((gm_8016B498() != 0) || - (gm_801A4310() == 0xC)) - { - tc5 = base->trophy_count; - } else { - tc5 = *gmMainLib_8015CC90(); - } - entry = display->last_entry->next; - trophy_id = Toy_sbss_804D6EDC - [display->selectedIdx - tc5]; - result = Toy_8030813C( - trophy_id, - (s32) Toy_sbss_804D6EDC); - archive = entry->archive; - if (archive != NULL) { - lbArchive_80016EFC(archive); - entry->archive = NULL; - } - entry->archive_name = result + 4; - entry->symbol_name = result + 0x24; - entry->trophy_id = trophy_id; - entry->archive = lbArchive_LoadSymbols( - entry->archive_name, &spCC, - entry->symbol_name, 0); - } else { - entry = display->last_entry->next; - trophy_id = - Toy_sbss_804D6EDC[cur_trophy]; - result = Toy_8030813C( - trophy_id, (s32) &Toy_sbss_804D6EDC - [cur_trophy]); - archive = entry->archive; - if (archive != NULL) { - lbArchive_80016EFC(archive); - entry->archive = NULL; - } - entry->archive_name = result + 4; - entry->symbol_name = result + 0x24; - entry->trophy_id = trophy_id; - entry->archive = lbArchive_LoadSymbols( - entry->archive_name, &spC8, - entry->symbol_name, 0); - } - archive = display->first_entry->archive; - if (archive != NULL) { - lbArchive_80016EFC(archive); - display->first_entry->archive = NULL; - } - display->selected_entry = - display->selected_entry->next; - display->first_entry = - display->first_entry->next; - display->last_entry = - display->last_entry->next; - } else { - display->selected_entry = - display->selected_entry->next; - } - } - } - } else { - cycle_prev: + if ((state->x30 < 0.0f) || (Toy_80305B88() & 0x441)) { lbAudioAx_80024030(2); display->selectedIdx = (s16) (display->selectedIdx - 1); @@ -4699,6 +4628,103 @@ void _Toy_8030E110(HSD_GObj* arg0) display->selected_entry->prev; } } + } else if ((state->x30 > 0.0f) || (Toy_80305B88() & 0x822)) + { + lbAudioAx_80024030(2); + display->selectedIdx = + (s16) (display->selectedIdx + 1); + { + s32 tc2; + if ((gm_8016B498() != 0) || (gm_801A4310() == 0xC)) + { + tc2 = base->trophy_count; + } else { + tc2 = *gmMainLib_8015CC90(); + } + if (display->selectedIdx >= tc2) { + display->selectedIdx = 0; + } + } + { + s32 tc3; + if ((gm_8016B498() != 0) || (gm_801A4310() == 0xC)) + { + tc3 = base->trophy_count; + } else { + tc3 = *gmMainLib_8015CC90(); + } + if (tc3 > 3) { + s32 tc4; + s16 cur_trophy; + s32 next_idx; + if ((gm_8016B498() != 0) || + (gm_801A4310() == 0xC)) + { + tc4 = base->trophy_count; + } else { + tc4 = *gmMainLib_8015CC90(); + } + cur_trophy = display->selectedIdx; + next_idx = (s32) (cur_trophy + 1); + if (next_idx >= tc4) { + s32 tc5; + if ((gm_8016B498() != 0) || + (gm_801A4310() == 0xC)) + { + tc5 = base->trophy_count; + } else { + tc5 = *gmMainLib_8015CC90(); + } + entry = display->last_entry->next; + trophy_id = Toy_sbss_804D6EDC + [display->selectedIdx - tc5]; + result = Toy_8030813C( + trophy_id, (s32) Toy_sbss_804D6EDC); + archive = entry->archive; + if (archive != NULL) { + lbArchive_80016EFC(archive); + entry->archive = NULL; + } + entry->archive_name = result + 4; + entry->symbol_name = result + 0x24; + entry->trophy_id = trophy_id; + entry->archive = lbArchive_LoadSymbols( + entry->archive_name, &spCC, + entry->symbol_name, 0); + } else { + entry = display->last_entry->next; + trophy_id = Toy_sbss_804D6EDC[cur_trophy]; + result = Toy_8030813C( + trophy_id, + (s32) &Toy_sbss_804D6EDC[cur_trophy]); + archive = entry->archive; + if (archive != NULL) { + lbArchive_80016EFC(archive); + entry->archive = NULL; + } + entry->archive_name = result + 4; + entry->symbol_name = result + 0x24; + entry->trophy_id = trophy_id; + entry->archive = lbArchive_LoadSymbols( + entry->archive_name, &spC8, + entry->symbol_name, 0); + } + archive = display->first_entry->archive; + if (archive != NULL) { + lbArchive_80016EFC(archive); + display->first_entry->archive = NULL; + } + display->selected_entry = + display->selected_entry->next; + display->first_entry = + display->first_entry->next; + display->last_entry = + display->last_entry->next; + } else { + display->selected_entry = + display->selected_entry->next; + } + } } _Toy_80307828(0); state->x58 = 0x95E; @@ -4947,8 +4973,8 @@ void _Toy_8030FE48(void* arg0, s32 arg1) char* result; s16 trophyIdx; void* sym; - void* sym2; void* zero; + void* sym2; s32 start; u8* zero_entry; s32 remaining; @@ -5211,16 +5237,16 @@ void Toy_80310324(void) ToyGlobalsS_* tg5; ToyGlobalsS_* tg6; ToySubStructS_* sub; - UNK_T sp[4]; + UNK_T syms[3]; + UNK_T sym[1]; s32 one; s32 var_r0; - char* str; HSD_SObj* sobj; HSD_GObj* gobj; u16* flags; f32 two; - PAD_STACK(8); + PAD_STACK(4); toy = (void*) &_Toy_804A26B8; tg = (ToyGlobalsS_*) Toy_sbss_804D6ED8; @@ -5229,8 +5255,9 @@ void Toy_80310324(void) Toy_803067BC(toy->x195, toy->x196); if (tg->x50 == NULL) { - str = getViewDatFilename(); - tg->x50 = lbArchive_LoadSymbols(str, &sp[4], _Toy_803FDEA0, NULL); + tg->x50 = lbArchive_LoadSymbols( + lbLang_IsSavedLanguageJP() ? "TyMnView.dat" : "TyMnView.usd", + sym, _Toy_803FDEA0[0], NULL); } memzero(_Toy_sbss_804D6E68, 0x64); @@ -5241,8 +5268,8 @@ void Toy_80310324(void) if ((tg2 = (ToyGlobalsS_*) Toy_sbss_804D6ED8)->x54 == NULL) { tg2->x54 = lbArchive_LoadSymbols( - "TyMnBg.dat", &sp[1], _Toy_803FE038[0], &sp[2], _Toy_803FE038[1], - &sp[3], _Toy_803FE038[2], 0); + "TyMnBg.dat", &syms[0], _Toy_803FE038[0], &syms[1], + _Toy_803FE038[1], &syms[2], _Toy_803FE038[2], 0); tg2->x8 = GObj_Create(4, 5, 0); GObj_SetupGXLink(tg2->x8, HSD_SObjLib_803A49E0, 0x32, 0); @@ -5251,7 +5278,7 @@ void Toy_80310324(void) two = 2.0f; one = 1; do { - sobj = HSD_SObjLib_803A477C(tg2->x8, sp[i + 1], 0, 0, 0x80, 0); + sobj = HSD_SObjLib_803A477C(tg2->x8, syms[i], 0, 0, 0x80, 0); *(f32*) ((char*) sobj + 0x1C) = two; i += 1; *(f32*) ((char*) sobj + 0x20) = two; @@ -5510,54 +5537,16 @@ void _Toy_803109A0(s32 arg0, s32 arg1, s32 arg2) s32 idx; s32 target; - target = arg0; + target = (u32) arg0; /* Copy table from _Toy_803B8910 to stack */ table = *(ToyTable*) _Toy_803B8910; - /* Search for matching entry using pointer walk */ - { - ToyEntry* p = table.entries; - idx = 0; - if (target == p->id) { - goto found; - } - idx = 1; - if (target == (++p)->id) { - goto found; - } - idx = 2; - if (target == (++p)->id) { - goto found; - } - idx = 3; - if (target == (++p)->id) { - goto found; - } - idx = 4; - if (target == (++p)->id) { - goto found; - } - idx = 5; - if (target == (++p)->id) { - goto found; - } - idx = 6; - if (target == (++p)->id) { - goto found; - } - idx = 7; - if (target == (++p)->id) { - goto found; - } - idx = 8; - if (target == (++p)->id) { - goto found; + for (idx = 0; idx < 9; idx++) { + if (target == table.entries[idx].id) { + break; } - idx = 9; } - -found: if (arg2 != 0) { DevText_StoreColorIndex(_Toy_sbss_804D6E98, 1); } else { @@ -5656,22 +5645,26 @@ void _Toy_80310B48(HSD_GObj* gobj) lbAudioAx_80024030(1); Toy_80311960(); valptr = (s16*) editor; - i = 0; - do { - if (valptr[3] != 0) { - Toy_80305918((s8) i, 0, 0); - buttons = Toy_80305B88(); - if (buttons & 0x1000) { - _Toy_803053C4(i, (s32) valptr[3], 0); - } else { - _Toy_803053C4(i, (s32) valptr[3], 1); + { + s32 slot; + + slot = 0; + do { + if (valptr[3] != 0) { + Toy_80305918(slot, 0, 0); + buttons = Toy_80305B88(); + if (buttons & 0x1000) { + _Toy_803053C4(slot, (s32) valptr[3], 0); + } else { + _Toy_803053C4(slot, (s32) valptr[3], 1); + } + } else if (slot == 2) { + Toy_80305918(slot, 0, 0); } - } else if (i == 2) { - Toy_80305918((s8) i, 0, 0); - } - i += 1; - valptr += 1; - } while (i < 9); + slot += 1; + valptr += 1; + } while (slot < 9); + } Toy_80305918(0, 1, 0); Toy_80305918(1, 1, 0); Toy_80305918(8, 1, 0); @@ -5700,8 +5693,9 @@ void _Toy_80310B48(HSD_GObj* gobj) if ((s16) editor->values[(s8) editor->selected_slot] > Toy_80304B94((s32) (s8) editor->selected_slot)) { + u8 selected_slot = editor->selected_slot; editor->values[(s8) editor->selected_slot] = - (s16) Toy_80304B94((s32) (s8) editor->selected_slot); + (s16) Toy_80304B94((s32) (s8) selected_slot); } editor->repeat_delay = 4; changed = 1; @@ -5729,7 +5723,7 @@ void _Toy_80310B48(HSD_GObj* gobj) skip_decrement: - if (dirX == 0.0f && dirY != 0.0f) { + if (!dirX && dirY) { lbAudioAx_80024030(2); editor->selected_slot = (u8) (s32) ((f32) (s8) editor->selected_slot + dirY); @@ -5747,15 +5741,13 @@ void _Toy_80310B48(HSD_GObj* gobj) DevText_Erase(_Toy_sbss_804D6E98); DevText_SetCursorXY(_Toy_sbss_804D6E98, 0, 0); i = 0; - valptr = (s16*) editor; do { if (i == (s8) editor->selected_slot) { - _Toy_803109A0(i, (s32) valptr[3], 1); + _Toy_803109A0(i, (s32) editor->values[i], 1); } else { - _Toy_803109A0(i, (s32) valptr[3], 0); + _Toy_803109A0(i, (s32) editor->values[i], 0); } i += 1; - valptr += 1; } while (i < 9); } } @@ -5972,19 +5964,19 @@ void Toy_OnEnter_80311AB0(void* arg0) _Toy_sbss_804D6E68 = HSD_MemAlloc(sizeof(*_Toy_sbss_804D6E68)); Toy_sbss_804D6ED8 = HSD_MemAlloc(sizeof(*Toy_sbss_804D6ED8)); - Toy_sbss_804D6ED4 = HSD_MemAlloc(sizeof(*Toy_sbss_804D6ED4)); - Toy_sbss_804D6EDC = HSD_MemAlloc(sizeof(*Toy_sbss_804D6EDC)); - _Toy_sbss_804D6E64 = HSD_MemAlloc(sizeof(*_Toy_sbss_804D6E64)); + Toy_sbss_804D6ED4 = HSD_MemAlloc(0xE4); + Toy_sbss_804D6EDC = HSD_MemAlloc(0x24A); + _Toy_sbss_804D6E64 = HSD_MemAlloc(0x6DE); Toy_sbss_804D6EE0 = HSD_MemAlloc(sizeof(*Toy_sbss_804D6EE0)); - _Toy_sbss_804D6E6C = HSD_MemAlloc(sizeof(*_Toy_sbss_804D6E6C)); + _Toy_sbss_804D6E6C = HSD_MemAlloc(8); memzero(_Toy_sbss_804D6E68, sizeof(*_Toy_sbss_804D6E68)); memzero(Toy_sbss_804D6ED8, sizeof(*Toy_sbss_804D6ED8)); - memzero(Toy_sbss_804D6ED4, sizeof(*Toy_sbss_804D6ED4)); - memzero(Toy_sbss_804D6EDC, sizeof(*Toy_sbss_804D6EDC)); - memzero(_Toy_sbss_804D6E64, sizeof(*_Toy_sbss_804D6E64)); + memzero(Toy_sbss_804D6ED4, 0xE4); + memzero(Toy_sbss_804D6EDC, 0x24A); + memzero(_Toy_sbss_804D6E64, 0x6DE); memzero(Toy_sbss_804D6EE0, sizeof(*Toy_sbss_804D6EE0)); - memzero(_Toy_sbss_804D6E6C, sizeof(*_Toy_sbss_804D6E6C)); + memzero(_Toy_sbss_804D6E6C, 8); Toy_8031263C(); @@ -6069,25 +6061,24 @@ void Toy_OnFrame_80312018(void) void _Toy_80312050(HSD_GObj* gobj, int code) { - UNUSED u64 framepad; - Vec3 interest; - Vec3 sp98; - UNUSED u8 pad[16]; - Mtx viewMtx; - Vec3 up; - Vec3 left; - Vec3 eye; - Vec3 scaled; HSD_CObj* cobj; TyViewData* data; u8 color_ff; u8 color_00; - PAD_STACK(4); data = _Toy_sbss_804D6E6C; cobj = HSD_CObjGetCurrent(); if (data->x4 == 0) { + Vec3 interest; + Vec3 endpoint; + UNUSED u8 pad[16]; + Mtx viewMtx; + Vec3 up; + Vec3 left; + Vec3 eye; + Vec3 scaled; + HSD_CObjGetInterest(cobj, &interest); HSD_CObjGetLeftVector(cobj, &left); HSD_CObjGetUpVector(cobj, &up); @@ -6103,37 +6094,37 @@ void _Toy_80312050(HSD_GObj* gobj, int code) GXBegin(GX_LINES, GX_VTXFMT0, 6); PSVECScale(&left, &scaled, -3.25f); - PSVECAdd(&scaled, &interest, &sp98); + PSVECAdd(&scaled, &interest, &endpoint); color_ff = 0xFF; color_00 = 0; - GXPosition3f32(sp98.x, sp98.y, sp98.z); + GXPosition3f32(endpoint.x, endpoint.y, endpoint.z); GXColor4u8(color_ff, color_00, color_00, color_ff); PSVECScale(&left, &scaled, +3.25f); - PSVECAdd(&scaled, &interest, &sp98); - GXPosition3f32(sp98.x, sp98.y, sp98.z); + PSVECAdd(&scaled, &interest, &endpoint); + GXPosition3f32(endpoint.x, endpoint.y, endpoint.z); GXColor4u8(color_ff, color_00, color_00, color_ff); PSVECScale(&up, &scaled, -3.25f); - PSVECAdd(&scaled, &interest, &sp98); - GXPosition3f32(sp98.x, sp98.y, sp98.z); + PSVECAdd(&scaled, &interest, &endpoint); + GXPosition3f32(endpoint.x, endpoint.y, endpoint.z); GXColor4u8(color_00, color_ff, color_00, color_ff); PSVECScale(&up, &scaled, +3.25f); - PSVECAdd(&scaled, &interest, &sp98); - GXPosition3f32(sp98.x, sp98.y, sp98.z); + PSVECAdd(&scaled, &interest, &endpoint); + GXPosition3f32(endpoint.x, endpoint.y, endpoint.z); GXColor4u8(color_00, color_ff, color_00, color_ff); PSVECScale(&eye, &scaled, -3.25f); - PSVECAdd(&scaled, &interest, &sp98); - GXPosition3f32(sp98.x, sp98.y, sp98.z); + PSVECAdd(&scaled, &interest, &endpoint); + GXPosition3f32(endpoint.x, endpoint.y, endpoint.z); GXColor4u8(color_00, color_00, color_ff, color_ff); PSVECScale(&eye, &scaled, +3.25f); - PSVECAdd(&scaled, &interest, &sp98); - GXPosition3f32(sp98.x, sp98.y, sp98.z); + PSVECAdd(&scaled, &interest, &endpoint); + GXPosition3f32(endpoint.x, endpoint.y, endpoint.z); GXColor4u8(color_00, color_00, color_ff, color_ff); } } diff --git a/src/melee/ty/toy.h b/src/melee/ty/toy.h index 283d96f12d..ee024a540f 100644 --- a/src/melee/ty/toy.h +++ b/src/melee/ty/toy.h @@ -46,10 +46,10 @@ /* 306EEC */ HSD_LObj* Toy_LoadLObjList(LightList**, s32*); /* 307470 */ void Toy_80307470(s32); /* 307E84 */ void Toy_80307E84(HSD_GObj* gobj); -/* 30813C */ char* Toy_8030813C(s16 arg0, enum_t unused); +/* 30813C */ char* Toy_8030813C(s32 arg0, enum_t unused); /* 308250 */ void Toy_80308250(u8* arg0, s32 arg1, s32 arg2); /* 3082F8 */ s32 Toy_803082F8(s16 idx); -/* 308328 */ void Toy_80308328(s32 arg0); +/* 308328 */ s32 Toy_80308328(s32 arg0); /* 308354 */ s32 Toy_80308354(s16 idx); /* 3083D8 */ void Toy_803083D8(HSD_JObj* jobj, s32 arg1); /* 3087F4 */ HSD_GObj* Toy_803087F4(void*); diff --git a/src/melee/ty/tydisplay.c b/src/melee/ty/tydisplay.c index 5011bbc04c..5759d26038 100644 --- a/src/melee/ty/tydisplay.c +++ b/src/melee/ty/tydisplay.c @@ -81,6 +81,9 @@ /* 4D6F28 */ static s32 _tyDisplay_804D6F28; /* 4D6F2C */ static HSD_GObj* _tyDisplay_804D6F2C; +extern TyDspNameTables _tyDisplay_803B8988; +extern TyDspArchNames _tyDisplay_803B8A34; + STATIC_ASSERT(sizeof(_tyDisplay_devtext_buf) == 0x36); STATIC_ASSERT(sizeof(_tyDisplay_804A2DD0) == 0x18); @@ -100,65 +103,86 @@ static void order_data_44(void) /* +44 */ (void) "ScMenDisplay_fog"; } -static inline void quicksort(TySortElem* base, s32 lo, s32 hi) +static inline TySortElem* tyDisplay_SortElemAtOffset(TySortElem* base, + size_t offset) { - TySortElem tmp; - PAD_STACK(16); + return (TySortElem*) ((size_t) base + offset); +} + +void _tyDisplay_8031830C(TySortElem* base, s32 lo, s32 hi) +{ + TySortElem tmp0, tmp1, tmp2, tmp3, tmp4; + UNUSED unsigned char pad0[4]; + TySortElem tmp5; + UNUSED unsigned char pad1[4]; + TySortElem tmp6, tmp7; + UNUSED unsigned char pad2[4]; + TySortElem tmp8; if (lo < hi) { s32 mid = (lo + hi) / 2; - s32 pivot, i; + TySortElem* cur; + s32 pivot2, pivot, j, i; if (lo != mid) { - tmp = base[lo]; + tmp0 = base[lo]; base[lo] = base[mid]; - base[mid] = tmp; + base[mid] = tmp0; } pivot = lo; - for (i = lo + 1; i <= hi; i++) { - if (base[i].val < base[lo].val) { + j = lo; + j *= sizeof(TySortElem); + for (i = lo + 1, cur = &base[i]; i <= hi; i++, cur++) { + if (cur->val < base[lo].val) { + TySortElem* s; pivot++; + j += sizeof(TySortElem); if (pivot != i) { - tmp = base[pivot]; - base[pivot] = base[i]; - base[i] = tmp; + s = tyDisplay_SortElemAtOffset(base, j); + tmp1 = *s; + *s = *cur; + *cur = tmp1; } } } if (lo != pivot) { - tmp = base[lo]; + tmp2 = base[lo]; base[lo] = base[pivot]; - base[pivot] = tmp; + base[pivot] = tmp2; } if (lo < pivot - 1) { - s32 mid2 = (pivot + lo - 1) / 2; - s32 pivot2; + s32 mid2 = (lo + pivot - 1) / 2; if (lo != mid2) { - tmp = base[lo]; + tmp3 = base[lo]; base[lo] = base[mid2]; - base[mid2] = tmp; + base[mid2] = tmp3; } pivot2 = lo; + j = lo; + j *= sizeof(TySortElem); for (i = lo + 1; i <= pivot - 1; i++) { if (base[i].val < base[lo].val) { + TySortElem* s; pivot2++; + j += sizeof(TySortElem); if (pivot2 != i) { - tmp = base[pivot2]; - base[pivot2] = base[i]; - base[i] = tmp; + s = (TySortElem*) ((size_t) base + j); + tmp4 = *s; + *s = base[i]; + base[i] = tmp4; } } } if (lo != pivot2) { - tmp = base[lo]; + tmp5 = base[lo]; base[lo] = base[pivot2]; - base[pivot2] = tmp; + base[pivot2] = tmp5; } _tyDisplay_8031830C(base, lo, pivot2 - 1); @@ -166,31 +190,36 @@ static inline void quicksort(TySortElem* base, s32 lo, s32 hi) } if (pivot + 1 < hi) { - s32 mid3 = (pivot + hi + 1) / 2; + s32 mid3 = (pivot + 1 + hi) / 2; s32 pivot3; - if (pivot + 1 != mid3) { - tmp = base[pivot + 1]; + if (mid3 != pivot + 1) { + tmp6 = base[pivot + 1]; base[pivot + 1] = base[mid3]; - base[mid3] = tmp; + base[mid3] = tmp6; } pivot3 = pivot + 1; + j = pivot + 1; + j *= sizeof(TySortElem); for (i = pivot + 2; i <= hi; i++) { if (base[i].val < base[pivot + 1].val) { + TySortElem* s; pivot3++; + j += sizeof(TySortElem); if (pivot3 != i) { - tmp = base[pivot3]; - base[pivot3] = base[i]; - base[i] = tmp; + s = (TySortElem*) ((size_t) base + j); + tmp7 = *s; + *s = base[i]; + base[i] = tmp7; } } } if (pivot + 1 != pivot3) { - tmp = base[pivot + 1]; + tmp8 = base[pivot + 1]; base[pivot + 1] = base[pivot3]; - base[pivot3] = tmp; + base[pivot3] = tmp8; } _tyDisplay_8031830C(base, pivot + 1, pivot3 - 1); @@ -218,16 +247,124 @@ static void order_sdata2_0(void) /* +3C */ (void) 0.5f; } -void _tyDisplay_8031830C(TySortElem* base, s32 lo, s32 hi) +typedef struct TySortElemInt { + s32 key; + s32 val; +} TySortElemInt; + +static inline TySortElemInt* tyDisplay_GetSortElem(size_t offset, + TySortElemInt* base) { - PAD_STACK(16); - quicksort(base, lo, hi); + return (TySortElemInt*) ((size_t) base + offset); } -void _tyDisplay_80318714(TySortElem* base, s32 lo, s32 hi) +void _tyDisplay_80318714(TySortElem* base_, s32 lo, s32 hi) { + TySortElemInt tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8; + TySortElemInt* base = (TySortElemInt*) base_; PAD_STACK(16); - quicksort(base, lo, hi); + + if (lo < hi) { + s32 mid = (lo + hi) / 2; + s32 pivot2, pivot, j, i; + + if (lo != mid) { + tmp0 = base[lo]; + base[lo] = base[mid]; + base[mid] = tmp0; + } + + pivot = lo; + j = lo; + j *= sizeof(TySortElemInt); + for (i = lo + 1; i <= hi; i++) { + if (base[i].val > base[lo].val) { + TySortElemInt* s; + pivot++; + j += sizeof(TySortElemInt); + if (pivot != i) { + s = tyDisplay_GetSortElem(j, base); + tmp1 = *s; + *s = base[i]; + base[i] = tmp1; + } + } + } + + if (lo != pivot) { + tmp2 = base[lo]; + base[lo] = base[pivot]; + base[pivot] = tmp2; + } + + if (lo < pivot - 1) { + s32 mid2 = (pivot + lo - 1) / 2; + + if (lo != mid2) { + tmp3 = base[lo]; + base[lo] = base[mid2]; + base[mid2] = tmp3; + } + + pivot2 = lo; + j = lo; + j *= sizeof(TySortElemInt); + for (i = lo + 1; i <= pivot - 1; i++) { + if (base[i].val > base[lo].val) { + TySortElemInt* s; + pivot2++; + j += sizeof(TySortElemInt); + if (pivot2 != i) { + s = (TySortElemInt*) ((size_t) base + j); + tmp4 = *s; + *s = base[i]; + base[i] = tmp4; + } + } + } + + if (lo != pivot2) { + tmp5 = base[lo]; + base[lo] = base[pivot2]; + base[pivot2] = tmp5; + } + + _tyDisplay_80318714(base_, lo, pivot2 - 1); + _tyDisplay_80318714(base_, pivot2 + 1, pivot - 1); + } + + if (pivot + 1 < hi) { + s32 mid3 = (pivot + 1 + hi) / 2; + s32 pivot3; + + if (pivot + 1 != mid3) { + tmp6 = base[pivot + 1]; + base[pivot + 1] = base[mid3]; + base[mid3] = tmp6; + } + + pivot3 = 1 + pivot; + for (i = pivot + 2; i <= hi; i++) { + if (base[i].val > base[pivot + 1].val) { + pivot3++; + if (pivot3 != i) { + tmp7 = base[pivot3]; + base[pivot3] = base[i]; + base[i] = tmp7; + } + } + } + + if (pivot + 1 != pivot3) { + tmp8 = base[pivot + 1]; + base[pivot + 1] = base[pivot3]; + base[pivot3] = tmp8; + } + + _tyDisplay_80318714(base_, pivot + 1, pivot3 - 1); + _tyDisplay_80318714(base_, pivot3 + 1, hi); + } + } } void _tyDisplay_80318B1C(s32 arg0) @@ -296,6 +433,35 @@ void _tyDisplay_80318B1C(s32 arg0) } while (i < 0x125); } } + +static inline f32 _tyDisplay_80318CB4_calc_dist_sq(f32 dz, f32 dx) +{ + return dx * dx + dz * dz; +} + +static inline void _tyDisplay_80318CB4_place_toys(TyDspGrid* grid, + TyDspConfig* cfg) +{ + s32 k; + s32 pos_idx = 0; + s32 jobj_idx = 0; + + for (k = 0; k < cfg->x08; k++) { + HSD_GObj* gobj; + cfg->x78 = _tyDisplay_8031BC54(grid->sort[k].key); + gobj = cfg->x78; + if (gobj != NULL) { + _tyDisplay_804D6F10[jobj_idx] = (HSD_JObj*) gobj->hsd_obj; + HSD_JObjSetTranslateX(_tyDisplay_804D6F10[jobj_idx], + grid->pos[pos_idx].x); + HSD_JObjSetTranslateZ(_tyDisplay_804D6F10[jobj_idx], + grid->pos[pos_idx].z); + jobj_idx++; + pos_idx++; + } + } +} + void _tyDisplay_80318CB4(s32 arg0) { s32 n2; @@ -375,8 +541,8 @@ void _tyDisplay_80318CB4(s32 arg0) } for (k = i - 1; k >= start; k--) { f32 dx = grid->pos[i].x - grid->pos[k].x; - f32 dz = grid->pos[i].z - grid->pos[k].z; - f32 dist = sqrtf(dx * dx + dz * dz); + f32 dist = sqrtf(_tyDisplay_80318CB4_calc_dist_sq( + grid->pos[i].z - grid->pos[k].z, dx)); if (dist > 2.1474836e9f || dist < -2.1474836e9f) { OSReport("*** tyDisplay Atari Irregul!\n"); HSD_ASSERT(0xC6, 0); @@ -438,6 +604,7 @@ void _tyDisplay_80318CB4(s32 arg0) n2 = count - 1; if (n2 > 0) { TyDspPos tmp; + s32 j; mid = n2 / 2; if (mid != 0) { @@ -447,11 +614,13 @@ void _tyDisplay_80318CB4(s32 arg0) } pivot = 0; + j = 0; for (n = 1; n <= n2; n++) { if (grid->pos[n].z < grid->pos[0].z) { pivot += 1; + j += 8; if (pivot != n) { - TyDspPos* p = &grid->pos[pivot]; + TyDspPos* p = (TyDspPos*) ((size_t) grid + j + 0x97C); tmp = *p; *p = grid->pos[n]; grid->pos[n] = tmp; @@ -460,7 +629,10 @@ void _tyDisplay_80318CB4(s32 arg0) } if (pivot != 0) { - tmp = grid->pos[0]; + { + TyDspPos tmp2 = grid->pos[0]; + tmp = tmp2; + } grid->pos[0] = grid->pos[pivot]; grid->pos[pivot] = tmp; } @@ -480,26 +652,30 @@ void _tyDisplay_80318CB4(s32 arg0) mid = n2 / 2; if (mid != 0) { - { - TySortElem tmp2 = grid->sort[0]; - tmp = tmp2; - } + tmp = grid->sort[0]; grid->sort[0] = grid->sort[mid]; grid->sort[mid] = tmp; } pivot = 0; - for (n = 1; n <= n2; n++) { - if (grid->sort[n].val > grid->sort[0].val) { - pivot += 1; - if (pivot != n) { - TySortElem* s = &grid->sort[pivot]; - { - TySortElem tmp2 = *s; - tmp = tmp2; + { + s32 j = 0; + for (n = 1; n <= n2; n++) { + if (*(s32*) &grid->sort[n].val > + *(s32*) &grid->sort[0].val) + { + pivot += 1; + j += 8; + if (pivot != n) { + TySortElem* s = + (TySortElem*) ((size_t) grid + j + 0x14); + { + TySortElem tmp2 = *s; + tmp = tmp2; + } + *s = grid->sort[n]; + grid->sort[n] = tmp; } - *s = grid->sort[n]; - grid->sort[n] = tmp; } } } @@ -515,173 +691,220 @@ void _tyDisplay_80318CB4(s32 arg0) } } + _tyDisplay_80318CB4_place_toys(grid, cfg); +} + +static inline void _tyDisplay_80319540_sort_and_place(TyDspConfig* cfg, + TyDspGrid* grid) +{ + s32 n2; + _tyDisplay_80318B1C(cfg->x08); + + if (cfg->x08 > 1) { + n2 = (cfg->x08 / 3) * 2; + if (n2 > 0) { + TySortElem tmp0, tmp1, tmp2; + s32 mid = n2 / 2; + s32 pivot, n, j; + + if (mid != 0) { + tmp0 = grid->sort[0]; + grid->sort[0] = grid->sort[mid]; + grid->sort[mid] = tmp0; + } + + pivot = 0; + j = 0; + for (n = 1; n2 >= n; n++) { + if (*(s32*) &grid->sort[n].val > *(s32*) &grid->sort[0].val) { + pivot += 1; + j += 8; + if (pivot != n) { + TySortElem* s = + (TySortElem*) ((size_t) grid + j + 0x14); + tmp1 = *s; + *s = grid->sort[n]; + grid->sort[n] = tmp1; + } + } + } + + if (pivot != 0) { + tmp2 = grid->sort[0]; + grid->sort[0] = grid->sort[pivot]; + grid->sort[pivot] = tmp2; + } + + _tyDisplay_80318714(grid->sort, 0, pivot - 1); + _tyDisplay_80318714(grid->sort, pivot + 1, n2); + } + } + { + struct TyDspGridElemIter { + u8 pad_sort[0x14]; + TySortElem sort; + u8 pad_pos[0x960]; + TyDspPos pos; + }* cur; s32 k; - s32 posIdx = 0; - s32 jobjIdx = 0; - for (k = 0; k < cfg->x08; k++) { + s32 off; + + k = 0; + off = 0; + cur = (struct TyDspGridElemIter*) grid; + for (; k < cfg->x08; k++) { HSD_GObj* gobj; - cfg->x78 = _tyDisplay_8031BC54(grid->sort[k].key); + cfg->x78 = _tyDisplay_8031BC54(cur->sort.key); gobj = cfg->x78; if (gobj != NULL) { - _tyDisplay_804D6F10[jobjIdx] = (HSD_JObj*) gobj->hsd_obj; - HSD_JObjSetTranslateX(_tyDisplay_804D6F10[jobjIdx], - grid->pos[posIdx].x); - HSD_JObjSetTranslateZ(_tyDisplay_804D6F10[jobjIdx], - grid->pos[posIdx].z); - jobjIdx++; - posIdx++; + *(HSD_JObj**) ((size_t) _tyDisplay_804D6F10 + off) = + (HSD_JObj*) gobj->hsd_obj; + { + f32 xpos = cur->pos.x; + HSD_JObjSetTranslateX( + *(HSD_JObj**) ((size_t) _tyDisplay_804D6F10 + off), + xpos); + } + { + f32 zpos = cur->pos.z; + HSD_JObjSetTranslateZ( + *(HSD_JObj**) ((size_t) _tyDisplay_804D6F10 + off), + zpos); + } } + cur = + (struct TyDspGridElemIter*) ((size_t) cur + sizeof(TyDspPos)); + off += 4; } } } void _tyDisplay_80319540(s32 arg0) { - TyDspGrid* grid = _tyDisplay_804D6F14; TyDspConfig* cfg = _tyDisplay_804D6F18; - s32 count; - s32 col, row, remainder; + TyDspGrid* cur; s32 i; - s32 n2; - PAD_STACK(0x28); + s32 remainder; + s32 col; + s32 row; + TyDspGrid* grid = _tyDisplay_804D6F14; + PAD_STACK(0x20); memzero(grid, 0x12E4); + row = 0; + col = 0; grid->x08_min_z = -3.5f; grid->x04_min_x = -3.5f; grid->x10_max_z = 3.5f; grid->x0C_max_x = 3.5f; - count = cfg->x08; - if (count <= 1) { + if (cfg->x08 <= 1) { remainder = 0; } else { - remainder = count % (s8) cfg->x75; + remainder = cfg->x08 % (s8) cfg->x75; } - row = (col = 0); - col = 0; - for (i = 0; i < count; i++) { - if (i == 0) { - grid->pos[i].x = 0.0f; - grid->pos[i].z = 0.0f; - } else { - f32 x = 9.0f * (f32) col; - if (arg0 != 0 && (row % 2) != 0) { - x = x + 3.5f; + { + cur = grid; + i = 0; + while (i < cfg->x08) { + if (i == 0) { + cur->pos[0].x = 0.0f; + cur->pos[0].z = 0.0f; + } else { + cur->pos[0].x = 9.0f * (f32) col; + if (arg0 != 0 && (row % 2) != 0) { + cur->pos[0].x += 3.5f; + } + cur->pos[0].z = 9.0f * (f32) row; } - grid->pos[i].x = x; - grid->pos[i].z = 9.0f * (f32) row; - } - col += 1; - if (remainder != 0) { - remainder -= 1; - if (remainder == 0) { + col += 1; + if (remainder != 0) { + remainder -= 1; + if (remainder == 0) { + col = 0; + row += 1; + } + } else if (col >= (s8) cfg->x75) { col = 0; row += 1; } - } else if (col >= (s8) cfg->x75) { - col = 0; - row += 1; - } - { - f32 px = grid->pos[i].x; - if (px < grid->x04_min_x) { - grid->x04_min_x = px; + { + f32 px = cur->pos[0].x; + if (px < grid->x04_min_x) { + grid->x04_min_x = px; + } } - } - { - f32 px = grid->pos[i].x; - if (px > grid->x0C_max_x) { - grid->x0C_max_x = px; + { + f32 px = cur->pos[0].x; + if (px > grid->x0C_max_x) { + grid->x0C_max_x = px; + } } - } - { - f32 pz = grid->pos[i].z; - if (pz < grid->x08_min_z) { - grid->x08_min_z = pz; + { + f32 pz = cur->pos[0].z; + if (pz < grid->x08_min_z) { + grid->x08_min_z = pz; + } } - } - { - f32 pz = grid->pos[i].z; - if (pz > grid->x10_max_z) { - grid->x10_max_z = pz; + { + f32 pz = cur->pos[0].z; + if (pz > grid->x10_max_z) { + grid->x10_max_z = pz; + } } + cur = (TyDspGrid*) ((size_t) cur + sizeof(TyDspPos)); + i++; } - - count = cfg->x08; } - _tyDisplay_80318B1C(count); + _tyDisplay_80319540_sort_and_place(cfg, grid); +} - if (count > 1) { - n2 = (count / 3) * 2; - if (n2 > 0) { - s32 mid = n2 / 2; - s32 pivot, j, n; - TySortElem tmp; - TySortElem* sort = grid->sort; +static inline void _tyDisplay_80319994_sort_pos(TyDspGrid* grid, s32 count, + s32* n2, s32* pivot) +{ + if (*pivot != 0 && count > 1) { + *n2 = count - 1; + if (*n2 > 0) { + TyDspPos tmp; + s32 mid = *n2 / 2; + s32 n, j; if (mid != 0) { - tmp = sort[0]; - sort[0] = sort[mid]; - sort[mid] = tmp; + tmp = grid->pos[0]; + grid->pos[0] = grid->pos[mid]; + grid->pos[mid] = tmp; } - j = (pivot = 0); - pivot = 0; - for (n = 1; n2 >= n; n++) { - if (sort[n].val > sort[0].val) { - pivot += 1; + *pivot = 0; + j = 0; + for (n = 1; *n2 >= n; n++) { + if (grid->pos[n].z < grid->pos[0].z) { + *pivot += 1; j += 8; - if (pivot != n) { - TySortElem* s = (TySortElem*) ((u8*) grid->sort + j); - tmp = *s; - *s = sort[n]; - sort[n] = tmp; + if (*pivot != n) { + TyDspPos* p = + (TyDspPos*) ((size_t) grid + j + 0x97C); + tmp = *p; + *p = grid->pos[n]; + grid->pos[n] = tmp; } } } - if (pivot != 0) { - TySortElem* s = &sort[pivot]; - tmp = sort[0]; - sort[0] = *s; - *s = tmp; + if (*pivot != 0) { + tmp = grid->pos[0]; + grid->pos[0] = grid->pos[*pivot]; + grid->pos[*pivot] = tmp; } - _tyDisplay_80318714(sort, 0, pivot - 1); - _tyDisplay_80318714(sort, pivot + 1, n2); - } - } - - { - s32 k; - s32 off = 0; - - for (k = 0; k < cfg->x08; k++) { - HSD_GObj* gobj; - HSD_JObj** jobjArr; - cfg->x78 = _tyDisplay_8031BC54(grid->sort[0].key); - gobj = cfg->x78; - if (gobj != NULL) { - jobjArr = _tyDisplay_804D6F10; - jobjArr[k] = (HSD_JObj*) gobj->hsd_obj; - { - f32 xpos = grid->pos[k].x; - HSD_JObj* jobj = jobjArr[k]; - HSD_JObjSetTranslateX(jobj, xpos); - } - { - f32 zpos = grid->pos[k].z; - HSD_JObj* jobj = jobjArr[k]; - HSD_JObjSetTranslateZ(jobj, zpos); - } - } - off += 4; + _tyDisplay_8031830C((TySortElem*) grid->pos, 0, *pivot - 1); + _tyDisplay_8031830C((TySortElem*) grid->pos, *pivot + 1, *n2); } } } @@ -705,22 +928,26 @@ void _tyDisplay_80319994(s32 arg0) grid->x0C_max_x = 3.5f; { - TyDspPos* cur = grid->pos; - s32 ring = 1; - s32 i = 0; - s32 col = 0; - s32 row = 0; - + TyDspGrid* cur = grid; + s32 ring; + s32 i; + s32 col; + s32 row; + + row = 0; + col = 0; + ring = 1; + i = 0; for (; i < (count = cfg->x08); i++) { if (i == 0) { - cur->x = 0.0f; - cur->z = 0.0f; + cur->pos[0].x = 0.0f; + cur->pos[0].z = 0.0f; } else { - cur->x = 9.0f * (f32) col + xoff; + cur->pos[0].x = 9.0f * (f32) col + xoff; if (pivot != 0) { - cur->z = -9.0f * (f32) row; + cur->pos[0].z = -9.0f * (f32) row; } else { - cur->z = 9.0f * (f32) row; + cur->pos[0].z = 9.0f * (f32) row; } } col += 1; @@ -731,71 +958,34 @@ void _tyDisplay_80319994(s32 arg0) ring += 1; } { - f32 x = cur->x; + f32 x = cur->pos[0].x; if (x < grid->x04_min_x) { grid->x04_min_x = x; } } { - f32 x = cur->x; + f32 x = cur->pos[0].x; if (x > grid->x0C_max_x) { grid->x0C_max_x = x; } } { - f32 z = cur->z; + f32 z = cur->pos[0].z; if (z < grid->x08_min_z) { grid->x08_min_z = z; } } { - f32 z = cur->z; + f32 z = cur->pos[0].z; if (z > grid->x10_max_z) { grid->x10_max_z = z; } } - cur++; + cur = (TyDspGrid*) ((size_t) cur + sizeof(TyDspPos)); } } - { - if (pivot != 0 && count > 1) { - n2 = count - 1; - if (n2 > 0) { - TyDspPos tmp; - s32 mid = n2 / 2; - s32 n; - - if (mid != 0) { - tmp = grid->pos[0]; - grid->pos[0] = grid->pos[mid]; - grid->pos[mid] = tmp; - } - - pivot = 0; - for (n = 1; n2 >= n; n++) { - if (grid->pos[n].z < grid->pos[0].z) { - pivot += 1; - if (pivot != n) { - TyDspPos* p = &grid->pos[pivot]; - tmp = *p; - *p = grid->pos[n]; - grid->pos[n] = tmp; - } - } - } - - if (pivot != 0) { - tmp = grid->pos[0]; - grid->pos[0] = grid->pos[pivot]; - grid->pos[pivot] = tmp; - } - - _tyDisplay_8031830C((TySortElem*) grid->pos, 0, pivot - 1); - _tyDisplay_8031830C((TySortElem*) grid->pos, pivot + 1, n2); - } - } - } + _tyDisplay_80319994_sort_pos(grid, count, &n2, &pivot); _tyDisplay_80318B1C(cfg->x08); @@ -806,7 +996,7 @@ void _tyDisplay_80319994(s32 arg0) if (n2 > 0) { TySortElem tmp; s32 mid = n2 / 2; - s32 n; + s32 n, j; if (mid != 0) { tmp = grid->sort[0]; @@ -815,11 +1005,16 @@ void _tyDisplay_80319994(s32 arg0) } pivot = 0; + j = 0; for (n = 1; n2 >= n; n++) { - if (grid->sort[n].val > grid->sort[0].val) { + if (*(s32*) &grid->sort[n].val > + *(s32*) &grid->sort[0].val) + { pivot += 1; + j += 8; if (pivot != n) { - TySortElem* s = &grid->sort[pivot]; + TySortElem* s = + (TySortElem*) ((size_t) grid + j + 0x14); tmp = *s; *s = grid->sort[n]; grid->sort[n] = tmp; @@ -840,65 +1035,64 @@ void _tyDisplay_80319994(s32 arg0) } { + struct TyDspGridElemIter { + u8 pad_sort[0x14]; + TySortElem sort; + u8 pad_pos[0x960]; + TyDspPos pos; + }* cur = (struct TyDspGridElemIter*) grid; s32 k; - TyDspPos* pos = grid->pos; - TySortElem* sort = grid->sort; - HSD_JObj** jobj_slot = _tyDisplay_804D6F10; + s32 off = 0; for (k = 0; k < cfg->x08; k++) { HSD_GObj* gobj; - cfg->x78 = _tyDisplay_8031BC54(sort->key); + cfg->x78 = _tyDisplay_8031BC54(cur->sort.key); gobj = cfg->x78; if (gobj != NULL) { - *jobj_slot = (HSD_JObj*) gobj->hsd_obj; - { - f32 xpos = pos->x; - HSD_JObj* jobj = *jobj_slot; - HSD_JObjSetTranslateX(jobj, xpos); - } - { - f32 zpos = pos->z; - HSD_JObj* jobj = *jobj_slot; - HSD_JObjSetTranslateZ(jobj, zpos); - } + *(HSD_JObj**) ((size_t) _tyDisplay_804D6F10 + off) = + (HSD_JObj*) gobj->hsd_obj; + HSD_JObjSetTranslateX( + *(HSD_JObj**) ((size_t) _tyDisplay_804D6F10 + off), + cur->pos.x); + HSD_JObjSetTranslateZ( + *(HSD_JObj**) ((size_t) _tyDisplay_804D6F10 + off), + cur->pos.z); } - pos++; - sort++; - jobj_slot++; + cur = + (struct TyDspGridElemIter*) ((size_t) cur + sizeof(TyDspPos)); + off += 4; } } } void _tyDisplay_80319EF0(void) { + u8 _[8]; Vec3 interest; Vec3 sp28; Vec3 eyepos; TyDspGrid* grid = _tyDisplay_804D6F14; TyDspConfig* cfg = _tyDisplay_804D6F18; + HSD_CObj* cobj = (HSD_CObj*) cfg->x00->hsd_obj; TyDspBgData* bg = _tyDisplay_804D6F1C; - HSD_CObj* cobj; f32 range; f32 scale; PAD_STACK(16); - cobj = (HSD_CObj*) cfg->x00->hsd_obj; - range = grid->x0C_max_x - grid->x04_min_x; - if (range < 0.0f) { + if ((range = grid->x0C_max_x - grid->x04_min_x) < 0.0f) { range = -range; } - interest.x = range * 0.5f + grid->x04_min_x; + interest.x = range / 2.0f + grid->x04_min_x; if (grid->x00 == 3) { interest.x = 0.0f; } interest.y = 0.0f; { - f32 zmin = grid->x08_min_z; - f32 zrange = grid->x10_max_z - zmin; - if (zrange < 0.0f) { - zrange = -zrange; + f32 zmin; + if ((range = grid->x10_max_z - (zmin = grid->x08_min_z)) < 0.0f) { + range = -range; } - interest.z = zrange * 0.5f + zmin; + interest.z = range / 2.0f + zmin; } eyepos = interest; interest.z -= 10.0f; @@ -919,8 +1113,8 @@ void _tyDisplay_80319EF0(void) } cfg->x44 = 1.0f; - while (500.0f * tanf(0.017453292f * (cfg->x44 * 0.5f)) < cfg->x40 * 0.5f) { - cfg->x44 = cfg->x44 + 0.1f; + while (500.0f * tanf(0.017453292f * (cfg->x44 / 2.0f)) < cfg->x40 / 2.0f) { + cfg->x44 += 0.1f; } if (cfg->x44 < 3.0f) { @@ -944,25 +1138,25 @@ void _tyDisplay_80319EF0(void) switch (mode) { case 0: case 1: - cfg->x54 = -((14.0f + cfg->x40) * 0.5f - cfg->x5C.x); - cfg->x58 = (14.0f + cfg->x40) * 0.5f + cfg->x5C.x; + cfg->x54 = -((14.0f + cfg->x40) / 2.0f - cfg->x5C.x); + cfg->x58 = (14.0f + cfg->x40) / 2.0f + cfg->x5C.x; break; case 2: - cfg->x54 = -((7.0f + cfg->x40) * 0.5f - cfg->x5C.x); - cfg->x58 = (7.0f + cfg->x40) * 0.5f + cfg->x5C.x; + cfg->x54 = -((7.0f + cfg->x40) / 2.0f - cfg->x5C.x); + cfg->x58 = (7.0f + cfg->x40) / 2.0f + cfg->x5C.x; break; case 3: - cfg->x54 = -(cfg->x40 * 0.5f - cfg->x5C.x); - cfg->x58 = cfg->x40 * 0.5f + cfg->x5C.x; + cfg->x54 = -(cfg->x40 / 2.0f - cfg->x5C.x); + cfg->x58 = cfg->x40 / 2.0f + cfg->x5C.x; break; } } { f32 xdiff = cfg->x58 - cfg->x54; - cfg->x1C = 57.29578f * lb_8000D008(xdiff * 0.5f, 500.0f); + cfg->x1C = 57.29578f * lb_8000D008(xdiff / 2.0f, 500.0f); } - cfg->x18 = 57.29578f * lb_8000D008(cfg->x40 * 0.5f, 500.0f); + cfg->x18 = 57.29578f * lb_8000D008(cfg->x40 / 2.0f, 500.0f); { HSD_JObjSetTranslate((HSD_JObj*) bg->gobj4->hsd_obj, &eyepos); @@ -1471,7 +1665,7 @@ void _tyDisplay_8031B328(void) if ((temp3 = ptr)->archive == NULL) { OSReport("*** BG data aren't being loaded!\n"); - OSPanic(__FILE__, 1113, "0"); + OSPanic(__FILE__, 1113, ""); } if ((lightData = HSD_ArchiveGetPublicAddress( @@ -1488,8 +1682,10 @@ void _tyDisplay_8031B328(void) HSD_LObjSetColor(lobj, _tyDisplay_color_C8C8C8FF); } - if ((fogDesc = HSD_ArchiveGetPublicAddress( - temp3->archive, "ScMenDisplay_cam_int1_camera")) != NULL) + /// @todo .data order hack + (void) "ScMenDisplay_cam_int1_camera"; + if ((fogDesc = HSD_ArchiveGetPublicAddress(temp3->archive, + "ScMenDisplay_fog")) != NULL) { scene->x08 = GObj_Create(3, 4, 0); HSD_GObjObject_80390A70(scene->x08, temp2 = HSD_GObj_804D7848, @@ -1501,13 +1697,11 @@ void _tyDisplay_8031B328(void) void tyDisplay_OnEnter_8031B460(void* arg0) { s32 sp18; + char* strbase = "ToyDspPanel_Top_joint"; TyDspConfig* cfg; TyDspBgData* data; TyDspGrid* grid; - HSD_CObj* cobj; - HSD_GObj* gobj; int i; - char* strbase = (char*) 0x803FEFF0; PAD_STACK(8); _tyDisplay_804D6F10 = HSD_MemAlloc(0x4B0); @@ -1590,13 +1784,9 @@ void tyDisplay_OnEnter_8031B460(void* arg0) { s32 jp = lbLang_IsSavedLanguageJP(); - char* archname; - if (jp != 0) { - archname = strbase + 0xA8; - } else { - archname = strbase + 0xB8; - } - data->archive = lbArchive_80016DBC(archname, &sp18, strbase + 0x18, 0); + data->archive = + lbArchive_80016DBC(jp != 0 ? strbase + 0xA8 : strbase + 0xB8, + &sp18, strbase + 0x18, 0); } for (i = 0; i < 0x2B; i++) { @@ -1608,7 +1798,7 @@ void tyDisplay_OnEnter_8031B460(void* arg0) { TyDspConfig* cfg2 = _tyDisplay_804D6F18; - cobj = lb_80013B14(HSD_ArchiveGetPublicAddress( + HSD_CObj* cobj = lb_80013B14(HSD_ArchiveGetPublicAddress( _tyDisplay_804D6F1C->archive, strbase + 0x18C)); cfg2->x00 = GObj_Create(1, 2, 0); @@ -1616,8 +1806,10 @@ void tyDisplay_OnEnter_8031B460(void* arg0) GObj_SetupGXLinkMax(cfg2->x00, (GObj_RenderFunc) (Event) Toy_803068E0, 0); - gobj = cfg2->x00; - gobj->gxlink_prios = 0x1230000000000000ULL; + { + HSD_GObj* gobj = cfg2->x00; + gobj->gxlink_prios = 0x1230000000000000ULL; + } if ((s32) _tyDisplay_804D6F20 != 0) { HSD_GObj_SetupProc(cfg2->x00, (HSD_GObjEvent) _tyDisplay_8031A94C, @@ -1901,7 +2093,6 @@ s32 _tyDisplay_8031BBF4(s8 arg0) HSD_GObj* _tyDisplay_8031BC54(s32 arg0) { -#if 0 char buf[44]; HSD_GObj* gobj; s32 id = arg0; @@ -1954,7 +2145,7 @@ HSD_GObj* _tyDisplay_8031BC54(s32 arg0) HSD_JObjSetTranslateZ(child, entry->x0C); HSD_JObjAddChild(root, HSD_JObjLoadJoint(HSD_ArchiveGetPublicAddress( - data->archives[41], "ToyDspStand_Top_joint"))); + data->archives[41], _tyDisplay_803FF01C))); if (_tyDisplay_804D6F24 != NULL) { DevText_Erase(_tyDisplay_804D6F24); @@ -1965,9 +2156,6 @@ HSD_GObj* _tyDisplay_8031BC54(s32 arg0) } return gobj; -#else - NOT_IMPLEMENTED; -#endif } static inline HSD_JObj* un_8031BF34_inline(void) @@ -1990,7 +2178,7 @@ void _tyDisplay_8031BF34(s32 arg0) } } - Toy_80308250(a->x0, (s16) (u16) arg0, 0); + Toy_80308250(a->x0, (s16) arg0, 0); _tyDisplay_804D6F2C = Toy_803087F4(a->x0); HSD_JObjClearFlagsAll(anim->jobj[0], JOBJ_HIDDEN); @@ -2101,7 +2289,6 @@ s32 tyDisplay_8031C354(s32 id, s32 buf[], s32 max, s32 kind) s32 tyDisplay_8031C454(s32 arg0) { -#if 0 HSD_Archive* temp2; TyDspArchNames names1; TyDspArchNames names2; @@ -2153,9 +2340,6 @@ s32 tyDisplay_8031C454(s32 arg0) } return result; -#else - NOT_IMPLEMENTED; -#endif } inline void* un_8031C5E4_inline(HSD_Archive** arg0, u8 arg1, const char* arg2) @@ -2165,7 +2349,7 @@ inline void* un_8031C5E4_inline(HSD_Archive** arg0, u8 arg1, const char* arg2) HSD_JObj* tyDisplay_8031C5E4(s32 arg0) { -#if 0 +#if 1 u8 _1[12]; TyDspArchNames jobj_names1; char* temp; @@ -2226,8 +2410,8 @@ HSD_JObj* tyDisplay_8031C5E4(s32 arg0) return root; #else NOT_IMPLEMENTED; -} #endif +} void tyDisplay_8031C8B8(void) { diff --git a/src/melee/ty/tyfigupon.c b/src/melee/ty/tyfigupon.c index 650c7267ad..4e553c136a 100644 --- a/src/melee/ty/tyfigupon.c +++ b/src/melee/ty/tyfigupon.c @@ -62,7 +62,7 @@ /* 315C44 */ static void _tyFigupon_80315C44(HSD_GObj*); /* 316170 */ static void _tyFigupon_80316170(HSD_GObj*); /* 31638C */ static s32 _tyFigupon_8031638C(s16); -/* 316420 */ static void _tyFigupon_80316420(s16); +/* 316420 */ static void _tyFigupon_80316420(s32); /* 3168DC */ static void _tyFigupon_803168DC(HSD_GObj*); /* 316BF8 */ static void _tyFigupon_80316BF8(HSD_GObj*); /* 316C24 */ static void _tyFigupon_80316C24(HSD_GObj*); @@ -323,9 +323,7 @@ void _tyFigupon_803153EC(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) num = arg0; temp_r30 = _tyFigupon_804D6EF4; - digits_s.s.x8 = 0; - digits_s.s.x4 = (count = 0); - digits_s.s.x0 = (count = 0); + digits_s.s.x0 = digits_s.s.x4 = digits_s.s.x8 = (count = (count = 0)); do { digits_s.digits[count++] = num % 10; num /= 10; @@ -472,7 +470,7 @@ void _tyFigupon_803155C8(void) pct = 99.9f; } data->x20 = Toy_80305058(0x63, 3, 0, pct); - _tyFigupon_80316420(data->x20); + _tyFigupon_80316420((s16) data->x20); { s32 inv = _tyFigupon_80314B54(); // TODO: Initialization of this for loop is off @@ -570,7 +568,7 @@ static void order_data_108(void) void _tyFigupon_80315C44(HSD_GObj* arg0) { - TyFiguponUD* ud; + TyFiguponUD* ud = HSD_GObjGetUserData(arg0); struct un_804D6EF4_t* ef4 = _tyFigupon_804D6EF4; HSD_GObj* gobj; HSD_JObj* jobj; @@ -581,7 +579,6 @@ void _tyFigupon_80315C44(HSD_GObj* arg0) PAD_STACK(24); - ud = arg0->user_data; if (ud != NULL) { if (ud->x8 != 0) { if (ud->x10 == 0 && ud->x14 == 0 && ud->x18 != 0) { @@ -631,7 +628,10 @@ void _tyFigupon_80315C44(HSD_GObj* arg0) ud->x2C = i; ud->x28 = i; do { - ((s32*) ud)[i + 10] = count % 10; + { + s32 idx = i + 10; + ((s32*) ud)[idx] = count % 10; + } count /= 10; i++; } while (count > 0); @@ -758,19 +758,20 @@ s32 _tyFigupon_8031638C(s16 arg0) return var_r30; } -void _tyFigupon_80316420(s16 arg0) +void _tyFigupon_80316420(s32 arg0) { + s16 id = arg0; struct un_804D6EF4_t* ef4 = _tyFigupon_804D6EF4; TyFiguponData* data = _tyFigupon_804D6EF0; ToyAnimState* aa8 = &Toy_804A2AA8; - s32 temp_r31; + s32 count; HSD_GObj* gobj; HSD_JObj* jobj; f32 angle; - PAD_STACK(32); + PAD_STACK(24); - temp_r31 = Toy_803048C0(arg0); + count = Toy_803048C0(id); Toy_80308250((void*) _tyFigupon_804D6EF8, arg0, 0); gobj = Toy_803087F4(_tyFigupon_804D6EF8); HSD_JObjClearFlagsAll(aa8->jobj[0], JOBJ_HIDDEN); @@ -786,16 +787,15 @@ void _tyFigupon_80316420(s16 arg0) HSD_JObjSetRotationY(jobj, 0.017453292f * angle); HSD_GObj_SetupProc(gobj, _tyFigupon_80316170, 0); HSD_GObj_80390CD4(gobj); - if (temp_r31 == 0) { + if (count == 0) { Toy_80306B18(data->x8, 0, 0x48, 1); HSD_GObj_80390CD4(data->x8); } Toy_SetUnlockState(arg0, 1); Toy_8031234C(1); lb_8001CE00(); - Toy_80308328(arg0); - HSD_SisLib_803A6368(data->x14, temp_r31); - Toy_803083D8(ef4->jobjs[0xC], arg0); + HSD_SisLib_803A6368(data->x14, Toy_80308328(arg0)); + Toy_803083D8(ef4->jobjs[0xC], id); if (((TyModeState*) Toy_804A284C)->x0 == 2) { if ((u32) data->x10 == 0) { data->x10 = (s32) HSD_GObj_SetupProc( @@ -1196,17 +1196,17 @@ void _tyFigupon_80316C24(HSD_GObj* arg0) void _tyFigupon_8031753C(void) { - u8 _padA[24]; - struct un_804D6EF4_t* ef4 = _tyFigupon_804D6EF4; + s32 new_count; + s32 count; HSD_Joint* joint; + HSD_Joint* bet_joint; + HSD_Joint* par_joint; + HSD_Joint* panel_joint; HSD_JObj* jobj; - s32 total; - DigitInit digits_s; - s32* digit_ptr; - s32* digit_iter; + struct un_804D6EF4_t* ef4 = _tyFigupon_804D6EF4; s32 i; s32 trophy_total; - s32 new_count; + u8 _padA[24]; if (ef4->archive == NULL) { OSReport("*** BG data aren't being loaded!\n"); @@ -1216,12 +1216,18 @@ void _tyFigupon_8031753C(void) HSD_GObjPLink_80390228((HSD_GObj*) ef4->x00); ef4->x00 = 0; } - joint = HSD_ArchiveGetPublicAddress(ef4->archive, - "ToyFigurePonPanel_Top_joint"); - if (joint != NULL) { + panel_joint = HSD_ArchiveGetPublicAddress(ef4->archive, + "ToyFigurePonPanel_Top_joint"); + if (panel_joint != NULL) { + s32 total; + DigitInit digits_s; + s32* digit_ptr; ef4->x00 = (u32) GObj_Create(9, 9, 0); - jobj = HSD_JObjLoadJoint(joint); - HSD_GObjObject_80390A70((HSD_GObj*) ef4->x00, HSD_GObj_804D7849, jobj); + jobj = HSD_JObjLoadJoint(panel_joint); + { + HSD_GObj* gobj = (HSD_GObj*) ef4->x00; + HSD_GObjObject_80390A70(gobj, HSD_GObj_804D7849, jobj); + } GObj_SetupGXLink((HSD_GObj*) ef4->x00, HSD_GObj_JObjCallback, 0x3C, 1); lb_8001204C(jobj, ef4->jobjs, _tyFigupon_803FEB88, 0xD); _tyFigupon_80314AA8(ef4->jobjs[0xC], NULL, @@ -1231,7 +1237,10 @@ void _tyFigupon_8031753C(void) "ToyFigurePonBg_Top_joint"); ef4->unk4 = GObj_Create(9, 9, 0); jobj = HSD_JObjLoadJoint(joint); - HSD_GObjObject_80390A70(ef4->unk4, HSD_GObj_804D7849, jobj); + { + HSD_GObj* gobj = ef4->unk4; + HSD_GObjObject_80390A70(gobj, HSD_GObj_804D7849, jobj); + } GObj_SetupGXLink(ef4->unk4, HSD_GObj_JObjCallback, 0x3C, 0); _tyFigupon_80314AA8(jobj, "ToyFigurePonBg_Top_animjoint", "ToyFigurePonBg_Top_matanim_joint", @@ -1248,15 +1257,14 @@ void _tyFigupon_8031753C(void) HSD_JObjAnimAll(jobj); digits_s = _tyFigupon_803B8974; + count = 0; total = (s32) (gm_801623D8() / 10u); joint = HSD_ArchiveGetPublicAddress(ef4->archive, "ToyFigurePonNm_Top_joint"); digit_ptr = &digits_s.x0; - digit_iter = digit_ptr; do { - *digit_iter = total % 10; + digit_ptr[count++] = total % 10; total /= 10; - digit_iter++; } while (total > 0); for (i = 0; i < 3; i++, digit_ptr++) { @@ -1273,11 +1281,11 @@ void _tyFigupon_8031753C(void) HSD_JObjAnimAll(jobj); } - joint = HSD_ArchiveGetPublicAddress(ef4->archive, - "ToyFigurePonBet_Top_joint"); - for (i = 0; i < 2; i++) { - jobj = HSD_JObjLoadJoint(joint); - HSD_JObjAddChild(ef4->jobjs[6 + i], jobj); + bet_joint = HSD_ArchiveGetPublicAddress(ef4->archive, + "ToyFigurePonBet_Top_joint"); + for (count = 0; count < 2; count++) { + jobj = HSD_JObjLoadJoint(bet_joint); + HSD_JObjAddChild(ef4->jobjs[6 + count], jobj); _tyFigupon_80314AA8(jobj, "ToyFigurePonBet_Top_animjoint", "ToyFigurePonBet_Top_matanim_joint", "ToyFigurePonBet_Top_shapeanim_joint"); @@ -1292,7 +1300,10 @@ void _tyFigupon_8031753C(void) "ToyFigurePonLever_Top_joint"); ef4->x08 = (u32) GObj_Create(9, 9, 0); jobj = HSD_JObjLoadJoint(joint); - HSD_GObjObject_80390A70((HSD_GObj*) ef4->x08, HSD_GObj_804D7849, jobj); + { + HSD_GObj* gobj = (HSD_GObj*) ef4->x08; + HSD_GObjObject_80390A70(gobj, HSD_GObj_804D7849, jobj); + } GObj_SetupGXLink((HSD_GObj*) ef4->x08, HSD_GObj_JObjCallback, 0x3C, 0); _tyFigupon_80314AA8(jobj, "ToyFigurePonLever_Top_animjoint", "ToyFigurePonLever_Top_matanim_joint", @@ -1301,11 +1312,13 @@ void _tyFigupon_8031753C(void) trophy_total = _tyFigupon_80314B54(); new_count = 0; - for (i = 0; i < 9; i++) { + i = new_count; + do { if (i != 8 && (u32) i > 1U && Toy_80304B0C(i) != 0) { new_count += Toy_80304B94(i); } - } + i += 1; + } while (i < 9); if (new_count - trophy_total != 0) { HSD_JObjReqAnimAll(ef4->jobjs[0xE], 0.0f); } else { @@ -1314,11 +1327,11 @@ void _tyFigupon_8031753C(void) HSD_JObjAnimAll(ef4->jobjs[0xE]); ef4->x0C = (u32) GObj_Create(9, 9, 0); - joint = HSD_ArchiveGetPublicAddress(ef4->archive, - "ToyFigurePonPar_Top_joint"); - for (i = 0; i < 3; i++) { - jobj = HSD_JObjLoadJoint(joint); - HSD_JObjAddChild(ef4->jobjs[9 + i], jobj); + par_joint = HSD_ArchiveGetPublicAddress(ef4->archive, + "ToyFigurePonPar_Top_joint"); + for (count = 0; count < 3; count++) { + jobj = HSD_JObjLoadJoint(par_joint); + HSD_JObjAddChild(ef4->jobjs[9 + count], jobj); _tyFigupon_80314AA8(jobj, "ToyFigurePonPar_Top_animjoint", "ToyFigurePonPar_Top_matanim_joint", "ToyFigurePonPar_Top_shapeanim_joint"); @@ -1370,12 +1383,13 @@ void _tyFigupon_80317A60(void) HSD_CameraDescPerspective* cam_desc; HSD_CObj* cobj; HSD_GObj* gobj; - struct un_804D6EF4_t* new_var; // Permuter slop + struct un_804D6EF4_t* ef4; HSD_Text* text; PAD_STACK(40); - new_var = _tyFigupon_804D6EF4; - cam_desc = HSD_ArchiveGetPublicAddress(new_var->archive, - "ScMenFigure_scene_lights"); + + ef4 = _tyFigupon_804D6EF4; + cam_desc = HSD_ArchiveGetPublicAddress( + ef4->archive, Toy_str_ScMenFigure_cam_int1_camera); data->x0 = GObj_Create(1, 2, 0); cobj = lb_80013B14(cam_desc); _tyFigupon_804D6F04 = (HSD_CObjDesc*) cam_desc; @@ -1383,26 +1397,16 @@ void _tyFigupon_80317A60(void) GObj_SetupGXLinkMax(data->x0, _tyFigupon_80314BE4, 0); gobj = data->x0; gobj->gxlink_prios = 0x5010000000000000ULL; + data->x4 = GObj_Create(1, 2, 0); - // cobj = lb_80013B14(&_Toy_803FE68C); - // _tyFigupon_804D6F08 = &_Toy_803FE68C; - // Unholiest of Permuter slop - HSD_GObjObject_80390A70( - data->x4, - (((((((((((HSD_GObj_804D784B & 0xFFFFFFFFFFFFFFFFu) & - 0xFFFFFFFFFFFFFFFFu) & - 0xFFFFFFFFFFFFFFFFu) & - 0xFFFFFFFFFFFFFFFFu) & - 0xFFFFFFFFFFFFFFFFu) & - 0xFFFFFFFFFFFFFFFFu) & - 0xFFFFFFFFFFFFFFFFu) & - 0xFFFFFFFFFFFFFFFFu) & - 0xFFFFFFFFFFFFFFFFu) & - 0xFFFFFFFFFFFFFFFFu) & - 0xFFFFFFFFFFFFFFFFu) & - 0xFFFFFFFFFFFFFFFFu, - cobj); - GObj_SetupGXLinkMax(data->x4, (GObj_RenderFunc) (Event) Toy_803068E0, 0); + cobj = lb_80013B14( + (HSD_CameraDescPerspective*) ((u32) "ToyFigurePonPanel_Top_joint" + + 0x4EC)); + _tyFigupon_804D6F08 = + (HSD_CameraDescPerspective*) ((u32) "ToyFigurePonPanel_Top_joint" + + 0x4EC); + HSD_GObjObject_80390A70(data->x4, HSD_GObj_804D784B, cobj); + GObj_SetupGXLinkMax(data->x4, Toy_803068E0, 0); gobj = data->x4; gobj->gxlink_prios = 0x2680000000000000ULL; @@ -1462,6 +1466,11 @@ void _tyFigupon_80317A60(void) HSD_GObj_80390CD4(data->x0); } +static inline TyFiguponED4* tyFigupon_GetED4(void) +{ + return (TyFiguponED4*) Toy_sbss_804D6ED4; +} + static inline void tyFigupon_UpdateRemainingCount(struct un_804D6EF4_t* ef4) { s32 total_b54; @@ -1480,22 +1489,34 @@ static inline void tyFigupon_UpdateRemainingCount(struct un_804D6EF4_t* ef4) ef4->x54 = count - total_b54; } +static inline void tyFigupon_InitScene(struct un_804D6EF4_t** ef4_2, + TyFiguponED4** ed4) +{ + _tyFigupon_80317A60(); + *ef4_2 = _tyFigupon_804D6EF4; + *ed4 = tyFigupon_GetED4(); + if ((*ef4_2)->archive == NULL) { + OSReport("*** BG data aren't being loaded!\n"); + OSPanic(__FILE__, 1575, ""); + } +} + void tyFigupon_OnEnter_80317D80(void* arg0) { s16 x54; + s32 x5E; + TyFiguponData* data; struct un_804D6EF4_t* ef4; - struct un_804D6EF4_t* ef4_2; TyFiguponED4* ed4; + struct un_804D6EF4_t* ef4_2; HSD_Joint* joint; HSD_JObj* jobj; void* ud; - s32 x5E; - TyFiguponData* data; f32 total; f32 pct; char* archive_name; void* sp20; - PAD_STACK(20); + PAD_STACK(16); _tyFigupon_804D6EF0 = HSD_MemAlloc(0x34); _tyFigupon_804D6EF4 = HSD_MemAlloc(0x60); @@ -1519,14 +1540,7 @@ void tyFigupon_OnEnter_80317D80(void* arg0) ef4->archive = lbArchive_LoadSymbols(archive_name, &sp20, "ToyFigurePonPanel_Top_joint", 0); ef4->x58 = 0; - _tyFigupon_80317A60(); - ef4_2 = _tyFigupon_804D6EF4; - ed4 = (TyFiguponED4*) Toy_sbss_804D6ED4; - (void) ed4; - if (ef4_2->archive == NULL) { - OSReport("*** BG data aren't being loaded!\n"); - OSPanic(__FILE__, 1575, ""); - } + tyFigupon_InitScene(&ef4_2, &ed4); { LightList** temp = HSD_ArchiveGetPublicAddress( ef4_2->archive, "ScMenFigure_scene_lights"); @@ -1538,8 +1552,10 @@ void tyFigupon_OnEnter_80317D80(void* arg0) HSD_GObj* gobj = (HSD_GObj*) ed4->x0; HSD_GObjObject_80390A70(gobj, HSD_GObj_804D784A, lobj); } - GObj_SetupGXLink((HSD_GObj*) ed4->x0, HSD_GObj_LObjCallback, 0x34, - 0); + { + HSD_GObj* gobj = (HSD_GObj*) ed4->x0; + GObj_SetupGXLink(gobj, HSD_GObj_LObjCallback, 0x34, 0); + } } } memzero(Toy_sbss_804D6ED4, 0xE4); diff --git a/src/melee/ty/tylist.c b/src/melee/ty/tylist.c index db9e30a87c..559a98b44d 100644 --- a/src/melee/ty/tylist.c +++ b/src/melee/ty/tylist.c @@ -57,6 +57,27 @@ /* 314504 */ static void _tyList_80314504(HSD_GObj* gobj, int); /* 31457C */ static void _tyList_8031457C(void); /* 3148E4 */ static void _tyList_803148E4(s32 arg0); +typedef struct TyListGobjEntryInner { + /* 0x00 */ HSD_GObj* x0; + /* 0x04 */ HSD_GObj* x4; + /* 0x08 */ u8 pad_8[0x0C - 0x08]; + /* 0x0C */ s8 x0C; + /* 0x0D */ s8 x0D; + /* 0x0E */ u8 pad_E; + /* 0x0F */ s8 x0F; + /* 0x10 */ s8 x10; + /* 0x11 */ s8 x11; + /* 0x12 */ s8 x12; + /* 0x13 */ s8 x13; + /* 0x14 */ s8 x14; + /* 0x15 */ u8 pad_15[3]; + /* 0x18 */ HSD_GObj* x18; +} TyListGobjEntryInner; +typedef struct TyListAuxState { + /* 0x00 */ u8 pad_0[0x18]; + /* 0x18 */ HSD_GObj* gobj; + /* 0x1C */ u8 pad_1C[0x10]; +} TyListAuxState; /* 4A2AC0 */ static TyListState _tyList_804A2AC0; /* 4A2D6C */ static TyListGobjEntry _tyList_804A2D6C; /* 4D6EE8 */ static s32 _tyList_804D6EE8; @@ -141,13 +162,13 @@ void _tyList_80312904(void* arg0, s8 arg1) if (arg1 != 0x63) { if ((s8) row->x24 == arg1) { - row->text0->text_color = lb_804D3764; - row->text1->text_color = lb_804D3764; - row->text2->text_color = lb_804D3764; + row->text0->text_color = lb_ColorBlack; + row->text1->text_color = lb_ColorBlack; + row->text2->text_color = lb_ColorBlack; } else { - row->text0->text_color = lb_804D3760; - row->text1->text_color = lb_804D3760; - row->text2->text_color = lb_804D3760; + row->text0->text_color = lb_ColorWhite; + row->text1->text_color = lb_ColorWhite; + row->text2->text_color = lb_ColorWhite; } } @@ -187,119 +208,70 @@ void _tyList_80312904(void* arg0, s8 arg1) void _tyList_80312BAC(TyListState* state, s8 arg1) { - s32 i; s16 old_idx; - s32 var_r28; - ToyED8Data* archive = Toy_sbss_804D6ED8; + s32 i; + TyListArg* first_row; TyListArg* row; - HSD_JObj* jobj; + ToyED8Data* archive = Toy_sbss_804D6ED8; + s32 trophy_idx; old_idx = Toy_sbss_804D6EDC[state->selectedIdx]; Toy_803067BC((s8) state->x29B, (s8) state->x29C); state->selectedIdx = Toy_803062BC((s32) old_idx); if (Toy_GetTrophyTotal() <= 0xA) { - var_r28 = state->selectedIdx; + trophy_idx = state->selectedIdx; i = 0; while (i < (s8) state->x278->x24 + 1) { - if (--var_r28 < 0) { - var_r28 = Toy_GetTrophyTotal() - 1; + if (--trophy_idx < 0) { + trophy_idx = Toy_GetTrophyTotal() - 1; } i++; } } else { - var_r28 = state->selectedIdx; + trophy_idx = state->selectedIdx; i = 0; while (i < (s8) state->x278->x24 + 1) { - if (--var_r28 < 0) { - var_r28 = Toy_GetTrophyTotal() - 1; + if (--trophy_idx < 0) { + trophy_idx = Toy_GetTrophyTotal() - 1; } i++; } } - jobj = state->jobj; - row = state->x270; - (void) row; - if (jobj != NULL) { - f32 y = row->x30; - if (jobj == NULL) { - __assert("jobj.h", 0x3B3, "jobj"); - } - jobj->translate.y = y; - if (!(jobj->flags & 0x02000000)) { - if (jobj == NULL) { - goto done_first_dirty; - } - if (jobj == NULL) { - __assert("jobj.h", 0x234, "jobj"); - } - { - u32 flags = jobj->flags; - s32 skip = 0; - if (!(flags & 0x800000) && (flags & 0x40)) { - skip = 1; - } - if (skip == 0) { - HSD_JObjSetMtxDirtySub(jobj); - } - } - } + first_row = state->x270; + row = first_row; + if (state->jobj != NULL) { + HSD_JObjSetTranslateY(state->jobj, first_row->x30); } -done_first_dirty: for (i = 0; i < (s8) state->entryCount; i++) { - row->idx = var_r28; + row->idx = trophy_idx; _tyList_80312904(row, arg1); _tyList_80313464(row); if (row->x24 >= 0 && row->x24 < (s8) state->entryCount - 2 && row->idx == Toy_GetTrophyTotal() - 1) { - HSD_JObj* jobj2 = state->jobj; - if (jobj2 != NULL) { - f32 y = row->x30; - if (jobj2 == NULL) { - __assert("jobj.h", 0x3B3, "jobj"); - } - jobj2->translate.y = y; - if (!(jobj2->flags & 0x02000000)) { - if (jobj2 == NULL) { - goto done_inner_dirty; - } - if (jobj2 == NULL) { - __assert("jobj.h", 0x234, "jobj"); - } - { - u32 flags = jobj2->flags; - s32 skip = 0; - if (!(flags & 0x800000) && (flags & 0x40)) { - skip = 1; - } - if (skip == 0) { - HSD_JObjSetMtxDirtySub(jobj2); - } - } - } + if (state->jobj != NULL) { + HSD_JObjSetTranslateY(state->jobj, row->x30); } } - done_inner_dirty: row = row->links[1]; - var_r28++; - if (var_r28 >= Toy_GetTrophyTotal()) { - var_r28 = 0; + trophy_idx++; + if (trophy_idx >= Toy_GetTrophyTotal()) { + trophy_idx = 0; } } i = 0; while (i < 3) { - HSD_JObj* anim_jobj = *((HSD_JObj**) ((u8*) archive + i * 4 + 0x18)); - if (i == state->x29B) { - HSD_JObjReqAnim(anim_jobj, 1.0f); + if (i == (s8) state->x29B) { + HSD_JObjReqAnim(archive->jobjs[i], 1.0f); } else { - HSD_JObjReqAnim(anim_jobj, 0.0f); + HSD_JObjReqAnim(archive->jobjs[i], 0.0f); } - HSD_AObjSetRate(anim_jobj->u.dobj->mobj->tobj->aobj, 0.0f); - HSD_JObjAnim(anim_jobj); + HSD_AObjSetRate(archive->jobjs[i]->u.dobj->mobj->tobj->aobj, 0.0f); + HSD_JObjAnim(archive->jobjs[i]); i++; } } @@ -539,62 +511,70 @@ void _tyList_80313774(void) TyModeState* mode = (TyModeState*) Toy_804A284C; ToyGlobalsS_* disp = (ToyGlobalsS_*) Toy_sbss_804D6EE0; TyArchiveData* archive = (TyArchiveData*) Toy_sbss_804D6ED8; - s8* state_tail = (s8*) M2C_FIELD(&state, HSD_GObj**, 0x2AC); + TyListGobjEntry* state_tail = (TyListGobjEntry*) (state + 1); TyListArg* entry; HSD_JObj* root_jobj; - f32 step; f32 pos; - s16 idx; + f32 step; + s32 idx; + s32 entry_count; s32 i; s32 trophy_total; - PAD_STACK(0x40); + PAD_STACK(0x38); state->selectedIdx = Toy_804A284C[0x12A]; state->x29B = mode->x1; state->x29C = mode->x2; if (Toy_GetTrophyTotal() <= 0xA) { - state_tail[0xD] = mode->x3; - state_tail[0xC] = mode->x3; + state_tail->x0C = state_tail->x0D = mode->x3; } else { - state_tail[0xD] = mode->x3; - state_tail[0xC] = mode->x3; + state_tail->x0C = state_tail->x0D = mode->x3; } trophy_total = Toy_GetTrophyTotal(); if (Toy_GetTrophyTotal() <= 0xA) { state->entryCount = trophy_total + 2; - idx = Toy_803062BC(disp->x140->x10); + entry_count = trophy_total + 2; + idx = Toy_803062BC(((ToyListEntry*) disp->x140)->prev->trophy_id); } else { state->entryCount = 0xC; - idx = Toy_803062BC(disp->x140->x10); + entry_count = 0xC; + idx = Toy_803062BC(((ToyListEntry*) disp->x140)->prev->trophy_id); } - for (i = 0; i < state->entryCount; i++) { + for (i = 0; i < entry_count; i++) { entry = &state->entries[i]; if (i == 0) { - entry->links[0] = &state->entries[state->entryCount - 1]; + entry->links[0] = &state->entries[entry_count - 1]; } else { entry->links[0] = &state->entries[i - 1]; } - if (i == state->entryCount - 1) { + if (i == entry_count - 1) { entry->links[1] = &state->entries[0]; } else { entry->links[1] = &state->entries[i + 1]; } } - state->x278 = &state->entries[1]; - state->x270 = &state->entries[0]; - state->x274 = &state->entries[state->entryCount - 1]; + if (Toy_GetTrophyTotal() <= 0xA) { + state->x278 = &state->entries[1]; + state->x270 = &state->entries[0]; + state->x274 = &state->entries[state->entryCount - 1]; + } else { + state->x278 = &state->entries[1]; + state->x270 = &state->entries[0]; + state->x274 = &state->entries[state->entryCount - 1]; + } state->gobj = (HSD_GObj*) _tyList_80313508( NULL, "ToyFigurePanel_listpos01_joint", 0.0f, 0.0f, 0.0f); - root_jobj = (HSD_JObj*) state->gobj; - HSD_ASSERTMSG(0x3E1, root_jobj != NULL, "jobj"); - - step = 5.11f - root_jobj->translate.y; + root_jobj = GET_JOBJ(state->gobj); + HSD_JObjGetTranslationX(root_jobj); + step = HSD_JObjGetTranslationY(root_jobj); + HSD_JObjGetTranslationZ(root_jobj); + step = 5.11f - step; pos = -step; state->x2A8 = step; @@ -603,8 +583,7 @@ void _tyList_80313774(void) *(s32*) &entry->x28 = i; entry->jobjs[0] = _tyList_80313508( state->gobj, "ToyFigureListBase_Top_joint", 0.0f, pos, 0.0f); - entry->jobjs[2] = - entry->jobjs[0] != NULL ? entry->jobjs[0]->child : NULL; + entry->jobjs[2] = HSD_JObjGetChild(entry->jobjs[0]); Toy_80306A48(entry->jobjs[0], NULL, "ToyFigureListBase_Top_matanim_joint", NULL, archive->data, 0); @@ -616,7 +595,7 @@ void _tyList_80313774(void) 17.2f, 192.0f, 64.0f); entry->x30 = pos; entry->x24 = i - 1; - entry->idx = idx; + entry->idx = (s16) idx; idx++; if (idx >= Toy_GetTrophyTotal()) { idx = 0; @@ -632,21 +611,21 @@ void _tyList_80313774(void) if (Toy_GetTrophyTotal() <= 0xA) { state->x288 = _tyList_80313508( state->gobj, "ToyFigureListCursor_Top_joint", 0.0f, - state->entries[state_tail[0xC] + 1].x30, 0.0f); + state->entries[state_tail->x0C + 1].x30, 0.0f); } else { state->x288 = _tyList_80313508( state->gobj, "ToyFigureListCursor_Top_joint", 0.0f, - state->entries[state_tail[0xC] + 1].x30, 0.0f); + state->entries[state_tail->x0C + 1].x30, 0.0f); } - for (i = 0; i < state_tail[0xC]; i++) { + for (i = 0; i < state_tail->x0C; i++) { _tyList_80313358(state, 0, 1, 1); _tyList_8031305C(state_tail, state, 0); } entry = &state->entries[0]; for (i = 0; i < state->entryCount; i++) { - if (entry->x24 == state_tail[0xC]) { + if (entry->x24 == state_tail->x0C) { state->selectedIdx = entry->idx; state->x278 = entry; break; @@ -654,19 +633,22 @@ void _tyList_80313774(void) entry++; } - _tyList_80312BAC(state, state_tail[0xC]); + _tyList_80312BAC(state, state_tail->x0C); } void _tyList_80313BD8(HSD_GObj* gobj) { - TyListState* state = (TyListState*) &_tyList_804A2AC0; - s32 i; + TyListState* state; TyListArg* p; - TyListGobjEntry* g = &_tyList_804A2D6C; + s32 i; + TyListGobjEntryInner* g; f32 f30; f32 f31; s8 v; + state = &_tyList_804A2AC0; + g = (TyListGobjEntryInner*) (state + 1); + if (Toy_GetTrophyTotal() > 10) { if (_tyList_8031305C(g, state, 1) != 0) { return; @@ -676,7 +658,7 @@ void _tyList_80313BD8(HSD_GObj* gobj) return; } if ((s8) state->x29E != 0) { - s32 d = (s8) state->pad_29D; + s32 d = (s8) _tyList_804A2AC0.pad_29D; s32 half = d / 2; s32 r; if ((d % 2) != 0) { @@ -700,34 +682,33 @@ void _tyList_80313BD8(HSD_GObj* gobj) } } - /* Fall-through label: block_17 */ f30 = Toy_80305D00(); f31 = Toy_80305DB0(); if (f30 < -0.8f) { - M2C_FIELD(g, s8*, 0x12) = M2C_FIELD(g, s8*, 0x12) + 1; + g->x12 = g->x12 + 1; f30 = -1.0f; f31 = 0.0f; } else if (f30 > 0.8f) { - M2C_FIELD(g, s8*, 0x12) = M2C_FIELD(g, s8*, 0x12) + 1; + g->x12 = g->x12 + 1; f30 = 1.0f; f31 = 0.0f; } else if (f31 < -0.6f || (Toy_80305C44() & 4)) { - M2C_FIELD(g, s8*, 0x12) = M2C_FIELD(g, s8*, 0x12) + 1; + g->x12 = g->x12 + 1; f30 = 0.0f; f31 = 1.0f; } else if (f31 > 0.6f || (Toy_80305C44() & 8)) { - M2C_FIELD(g, s8*, 0x12) = M2C_FIELD(g, s8*, 0x12) + 1; + g->x12 = g->x12 + 1; f30 = 0.0f; f31 = -1.0f; } else { f31 = 0.0f; - M2C_FIELD(g, s8*, 0xF) = 0; + g->x0F = 0; f30 = f31; - M2C_FIELD(g, s8*, 0x12) = 0; - M2C_FIELD(g, s8*, 0x14) = 6; - M2C_FIELD(g, s8*, 0x13) = 0; - M2C_FIELD(g, s8*, 0x11) = 0; - M2C_FIELD(g, s8*, 0x10) = 0; + g->x12 = 0; + g->x14 = 6; + g->x13 = 0; + g->x11 = 0; + g->x10 = 0; } if (mn_8022F218() != 0) { @@ -762,34 +743,30 @@ void _tyList_80313BD8(HSD_GObj* gobj) return; } - if ((s8) M2C_FIELD(g, s8*, 0x12) > (s8) M2C_FIELD(g, s8*, 0x14)) { - M2C_FIELD(g, s8*, 0x12) = M2C_FIELD(g, s8*, 0x14) + 1; - M2C_FIELD(g, s8*, 0x14) = 3; - M2C_FIELD(g, s8*, 0xF) = 0; + if ((s8) g->x12 > (s8) g->x14) { + g->x12 = g->x14 + 1; + g->x14 = 3; + g->x0F = 0; } - if ((f30 < 0.0f && f30 != (f32) (s8) M2C_FIELD(g, s8*, 0x10)) || - (Toy_80305B88() & 0x41)) - { - M2C_FIELD(g, s8*, 0x10) = (s8) f30; + if ((f30 < 0.0f && f30 != (f32) (s8) g->x10) || (Toy_80305B88() & 0x41)) { + g->x10 = (s8) f30; state->x29B = state->x29B - 1; if ((s8) state->x29B < 0) { state->x29B = 2; } - _tyList_80312BAC(state, M2C_FIELD(g, s8*, 0xC)); + _tyList_80312BAC(state, g->x0C); lbAudioAx_80024030(1); return; } - if ((f30 > 0.0f && f30 != (f32) (s8) M2C_FIELD(g, s8*, 0x10)) || - (Toy_80305B88() & 0x22)) - { - M2C_FIELD(g, s8*, 0x10) = (s8) f30; + if ((f30 > 0.0f && f30 != (f32) (s8) g->x10) || (Toy_80305B88() & 0x22)) { + g->x10 = (s8) f30; state->x29B = state->x29B + 1; if ((s8) state->x29B >= 3) { state->x29B = 0; } - _tyList_80312BAC(state, M2C_FIELD(g, s8*, 0xC)); + _tyList_80312BAC(state, g->x0C); lbAudioAx_80024030(1); return; } @@ -830,53 +807,53 @@ void _tyList_80313BD8(HSD_GObj* gobj) if (f31 == 0.0f) { return; } - if ((s8) M2C_FIELD(g, s8*, 0xF) != 0) { + if ((s8) g->x0F != 0) { return; } - M2C_FIELD(g, s8*, 0xF) = 1; - M2C_FIELD(g, s8*, 0xC) = (s8) ((f32) (s8) M2C_FIELD(g, s8*, 0xC) + f31); - if ((s8) M2C_FIELD(g, s8*, 0xC) < 0) { - M2C_FIELD(g, s8*, 0xC) = 0; - } else if ((s8) M2C_FIELD(g, s8*, 0xC) > (s8) state->entryCount - 3) { - M2C_FIELD(g, s8*, 0xC) = state->entryCount - 3; + g->x0F = 1; + g->x0C = (s8) ((f32) (s8) g->x0C + f31); + if ((s8) g->x0C < 0) { + g->x0C = 0; + } else if ((s8) g->x0C > (s8) state->entryCount - 3) { + g->x0C = state->entryCount - 3; } - if ((s8) M2C_FIELD(g, s8*, 0xC) != (s8) M2C_FIELD(g, s8*, 0xD)) { + if ((s8) g->x0C != (s8) g->x0D) { i = 0; - M2C_FIELD(g, s8*, 0x12) = 0; + g->x12 = 0; p = &state->entries[0]; - M2C_FIELD(g, s8*, 0x13) = 0; - M2C_FIELD(g, s8*, 0x11) = (s8) f31; + g->x13 = 0; + g->x11 = (s8) f31; for (; i < (s8) state->entryCount; i++, p++) { - if (((s8*) p)[0x24] == M2C_FIELD(g, s8*, 0xC)) { + if (((s8*) p)[0x24] == g->x0C) { state->selectedIdx = p->idx; state->x278 = p; lbAudioAx_80024030(2); HSD_JObjSetTranslateY(state->x288, p->x30); } - _tyList_80312904(p, M2C_FIELD(state, s8*, 0x2B8)); + _tyList_80312904(p, ((s8*) state)[0x2B8]); } - M2C_FIELD(g, s8*, 0xD) = M2C_FIELD(g, s8*, 0xC); + g->x0D = g->x0C; return; } if (Toy_GetTrophyTotal() <= 10) { return; } - if ((s8) M2C_FIELD(g, s8*, 0x11) == 0) { - M2C_FIELD(g, s8*, 0x13) = 5; - M2C_FIELD(g, s8*, 0x12) = M2C_FIELD(g, s8*, 0x14) + 1; - M2C_FIELD(g, s8*, 0x14) = 3; - M2C_FIELD(g, s8*, 0xF) = 0; + if ((s8) g->x11 == 0) { + g->x13 = 5; + g->x12 = g->x14 + 1; + g->x14 = 3; + g->x0F = 0; } - M2C_FIELD(g, s8*, 0x11) = (s8) f31; - v = M2C_FIELD(g, s8*, 0x13); + g->x11 = (s8) f31; + v = g->x13; if (v == 0) { - M2C_FIELD(g, s8*, 0x13) = 1; + g->x13 = 1; return; } if (v < 5) { - M2C_FIELD(g, s8*, 0x13) = v + 1; + g->x13 = v + 1; return; } @@ -958,6 +935,8 @@ void _tyList_8031457C(void) ToyED8Data* archive = Toy_sbss_804D6ED8; HSD_CameraDescPerspective* desc; HSD_CObj* cobj; + u8 kind; + UNUSED unsigned char pad[8]; HSD_RectS16 viewport; Scissor scissor; Vec3 interest; @@ -971,7 +950,8 @@ void _tyList_8031457C(void) if (desc != NULL) { entry->x0 = GObj_Create(1, 2, 0); cobj = lb_80013B14(desc); - HSD_GObjObject_80390A70(entry->x0, HSD_GObj_804D784B, cobj); + kind = HSD_GObj_804D784B; + HSD_GObjObject_80390A70(entry->x0, kind, cobj); GObj_SetupGXLinkMax(entry->x0, Toy_80306954, 0); entry->x0->gxlink_prios = 0x9010000000000000ULL; HSD_GObj_SetupProc(entry->x0, _tyList_8031438C, 0); @@ -983,7 +963,8 @@ void _tyList_8031457C(void) if (desc != NULL) { entry->x4 = GObj_Create(1, 2, 0); cobj = lb_80013B14(desc); - HSD_GObjObject_80390A70(entry->x4, HSD_GObj_804D784B, cobj); + kind = HSD_GObj_804D784B; + HSD_GObjObject_80390A70(entry->x4, kind, cobj); GObj_SetupGXLinkMax(entry->x4, _tyList_80314504, 0); entry->x4->gxlink_prios = 0x0210000000000000ULL; interest.x = 1.1f; @@ -1015,21 +996,34 @@ void _tyList_8031457C(void) } } +static inline void _tyList_ClearAuxState(TyListState* state) +{ + memzero(state + 1, 0x18); + _tyList_8031457C(); + memzero(&((TyListAuxState*) (state + 1))->gobj, 0x14); +} + +static inline void _tyList_GetState(TyListState** state) +{ + *state = &_tyList_804A2AC0; +} + void tyList_803147C4(void) { - char* data = (char*) &_tyList_804A2AC0; + TyListState* state; TyArchiveData* archive; LightList** jobj; u8 new_var; HSD_GObj** gobj; - PAD_STACK(8); - memzero(data + 0x2AC, 0x18); - _tyList_8031457C(); - memzero(data + 0x2C4, 0x14); - - gobj = (HSD_GObj**) (data + 0x2C4); - archive = (TyArchiveData*) Toy_sbss_804D6ED8; + _tyList_GetState(&state); + _tyList_ClearAuxState(state); + { + TyArchiveData* loaded_archive = (TyArchiveData*) Toy_sbss_804D6ED8; + TyArchiveData* archive_data = loaded_archive; + archive = archive_data; + } + gobj = &((TyListAuxState*) (state + 1))->gobj; if (archive->data == NULL) { OSReport("*** BG data aren't being loaded!\n"); @@ -1047,7 +1041,7 @@ void tyList_803147C4(void) Toy_80307470(0); if (Toy_GetTrophyTotal() != 0) { - memzero(data, 0x2AC); + memzero(state, 0x2AC); _tyList_80313774(); } HSD_PadRenewStatus(); @@ -1056,12 +1050,14 @@ void tyList_803147C4(void) void _tyList_803148E4(s32 arg0) { TyListState* state = (TyListState*) &_tyList_804A2AC0; - TyListGobjEntry* entry = M2C_FIELD(state, TyListGobjEntry**, 0x2AC); + TyListGobjEntryInner* entry = + (TyListGobjEntryInner*) &_tyList_804A2D6C; TyArchiveData* archive; HSD_GObj** gobj_2C4; PAD_STACK(8); - gobj_2C4 = M2C_FIELD(state, HSD_GObj***, 0x2C4); + gobj_2C4 = + &((TyListGobjEntryInner*) &_tyList_804A2D6C)->x18; archive = (TyArchiveData*) Toy_sbss_804D6ED8; if (Toy_GetTrophyTotal() != 0) { diff --git a/src/melee/ty/types.h b/src/melee/ty/types.h index 9485de234e..4433be20e2 100644 --- a/src/melee/ty/types.h +++ b/src/melee/ty/types.h @@ -297,7 +297,15 @@ struct TyListGobjEntry { /* +4 */ HSD_GObj* x4; /* +8 */ u8 pad_8[0x0C - 0x08]; /* +C */ s8 x0C; - /* +D */ u8 pad_0D[0x16 - 0x0D]; + /* +D */ s8 x0D; + /* +E */ u8 pad_0E; + /* +F */ s8 x0F; + /* +10 */ s8 x10; + /* +11 */ s8 x11; + /* +12 */ s8 x12; + /* +13 */ s8 x13; + /* +14 */ s8 x14; + /* +15 */ u8 pad_15; /* +16 */ s8 x16; /* +18 */ u8 pad_18[0x2C - 0x18]; }; diff --git a/src/melee/vi/vi0401.c b/src/melee/vi/vi0401.c index eb0c8bbc04..2ebcf520da 100644 --- a/src/melee/vi/vi0401.c +++ b/src/melee/vi/vi0401.c @@ -125,16 +125,19 @@ static void fn_8031D168(HSD_GObj* gobj) void un_8031D288_OnEnter(void* data) { - HSD_GObj* cam_gobj; u8 char_index; - HSD_CObj* cobj; + HSD_Fog* fog; HSD_GObj* fog_gobj; HSD_LObj* lobj; HSD_GObj* light_gobj; - HSD_Fog* fog; - HSD_JObj* jobj; + HSD_CObj* cobj; + HSD_GObj* cam_gobj; int i; + HSD_JObj* jobj; HSD_GObj* gobj; + HSD_GObj* cam_gobj2; + HSD_JObj* jobj2; + HSD_GObj* gobj2; ViCharaDesc* desc; desc = (ViCharaDesc*) data; @@ -190,23 +193,23 @@ void un_8031D288_OnEnter(void* data) } } - cam_gobj = GObj_Create(0x13, 0x14, 0); + cam_gobj2 = GObj_Create(0x13, 0x14, 0); cobj = lb_80013B14((HSD_CameraDescPerspective*) un_804D6F50->cameras->desc); - HSD_GObjObject_80390A70(cam_gobj, HSD_GObj_804D784B, cobj); - GObj_SetupGXLinkMax(cam_gobj, HSD_GObj_803910D8, 0x8); - cam_gobj->gxlink_prios = 0x801; + HSD_GObjObject_80390A70(cam_gobj2, HSD_GObj_804D784B, cobj); + GObj_SetupGXLinkMax(cam_gobj2, HSD_GObj_803910D8, 0x8); + cam_gobj2->gxlink_prios = 0x801; for (i = 0; un_804D6F4C->models[i] != NULL; i++) { - gobj = GObj_Create(0xE, 0xF, 0); - jobj = HSD_JObjLoadJoint(un_804D6F4C->models[i]->joint); - HSD_GObjObject_80390A70(gobj, HSD_GObj_804D7849, jobj); - GObj_SetupGXLink(gobj, HSD_GObj_JObjCallback, 0xB, 0); - gm_8016895C(jobj, un_804D6F4C->models[i], + gobj2 = GObj_Create(0xE, 0xF, 0); + jobj2 = HSD_JObjLoadJoint(un_804D6F4C->models[i]->joint); + HSD_GObjObject_80390A70(gobj2, HSD_GObj_804D7849, jobj2); + GObj_SetupGXLink(gobj2, HSD_GObj_JObjCallback, 0xB, 0); + gm_8016895C(jobj2, un_804D6F4C->models[i], (un_804D6F4C->models[i] != NULL) * 0); - HSD_JObjReqAnimAll(jobj, 0.0f); - HSD_JObjAnimAll(jobj); - HSD_GObj_SetupProc(gobj, fn_8031D168, 0x17); + HSD_JObjReqAnimAll(jobj2, 0.0f); + HSD_JObjAnimAll(jobj2); + HSD_GObj_SetupProc(gobj2, fn_8031D168, 0x17); } un_8031D030(desc->p1_char_index, desc->p1_costume_index); vi_8031C9B4(1, 0); diff --git a/src/melee/vi/vi0501.c b/src/melee/vi/vi0501.c index 99aa296820..d1d568eb9e 100644 --- a/src/melee/vi/vi0501.c +++ b/src/melee/vi/vi0501.c @@ -101,8 +101,9 @@ void un_8031D9F8(CharacterKind char_kind, int costume, int spawn_mode, Player_80036F34(0, 8); counts = (u8*) spawn_count; - pos = grLib_801C9A10() + 1; + pos = grLib_801C9A10(); gobj_ptr = un_804A2E98 + 1; + pos = pos + 1; for (i = 1; i < 4; i++) { Player_80036E20(CKIND_KIRBY, un_804D6F74, 6); count = counts[i - 1]; diff --git a/src/melee/vi/vi1201v1.c b/src/melee/vi/vi1201v1.c index 9373a06757..c797bef592 100644 --- a/src/melee/vi/vi1201v1.c +++ b/src/melee/vi/vi1201v1.c @@ -167,19 +167,23 @@ void fn_8031FCBC(HSD_GObj* gobj) static inline void un_8031FD18_SetupScene(void) { s32 i; + HSD_GObj* new_var; HSD_JObj* jobj; HSD_GObj* gobj; - for (i = 0; un_804D6FE0->models[i] != NULL; i++) { + i = 0; + while (un_804D6FE0->models[i] != NULL) { gobj = GObj_Create(0xE, 0xF, 0); jobj = HSD_JObjLoadJoint(un_804D6FE0->models[i]->joint); - HSD_GObjObject_80390A70(gobj, HSD_GObj_804D7849, jobj); - GObj_SetupGXLink(gobj, HSD_GObj_JObjCallback, 0xB, 0); + new_var = gobj; + HSD_GObjObject_80390A70(new_var, HSD_GObj_804D7849, jobj); + GObj_SetupGXLink(new_var, HSD_GObj_JObjCallback, 0xB, 0); gm_8016895C(jobj, un_804D6FE0->models[i], 0); HSD_JObjReqAnimAll(jobj, 0.0f); HSD_JObjAnimAll(jobj); - HSD_GObj_SetupProc(gobj, fn_8031FAA8, 0); + HSD_GObj_SetupProc(new_var, fn_8031FAA8, 0); lb_80011E24(jobj, &un_804D6FF0, 3, -1); + i++; } Camera_80028B9C(6); @@ -188,28 +192,47 @@ static inline void un_8031FD18_SetupScene(void) Ground_801C0378(0x40); } +static inline void un_8031FD18_LoadArchives(u8* input) +{ + u8 char_index; + + char_index = input[0]; + + un_804D6FE8 = lbArchive_LoadSymbols("Vi1201v1.dat", &un_804D6FE0, + "visual1201v1Scene", NULL); + lbArchive_LoadSymbols("TyKoopa.dat", &un_804D6FEC, + "ToyKoopaModel_TopN_joint", NULL); + lbArchive_LoadSymbols("GmRgStnd.dat", &un_804D6FE4, "standScene", NULL); + Toy_803124BC(); + un_804D6FE8 = lbArchive_LoadSymbols(gm_80160438(char_index), NULL); +} + /// @todo .data order hack static void order_data(void) { (void) "!(jobj->flags & JOBJ_USE_QUATERNION)"; } +static inline HSD_Fog* un_8031FD18_LoadFog(void) +{ + return HSD_FogLoadDesc(un_804D6FE0->fogs->desc); +} + void un_8031FD18_OnEnter(void* arg) { u8* input = arg; - u8 char_index; HSD_CObj* cobj; HSD_GObj* gobj; - HSD_JObj* jobj; - HSD_JObj* child; HSD_Fog* fog; + HSD_JObj* child; + HSD_JObj* jobj; HSD_LObj* lobj; f32 scale; - char pad[24]; + PAD_STACK(24); un_804D6FFC = input[0]; un_804D6FFD = input[1]; - un_804D7000 = (void*) 0U; + un_804D7000 = NULL; lbAudioAx_800236DC(); efLib_Init(); @@ -217,15 +240,7 @@ void un_8031FD18_OnEnter(void* arg) lbAudioAx_80023F28(0x59); lbAudioAx_80024E50(1); - char_index = input[0]; - - un_804D6FE8 = lbArchive_LoadSymbols("Vi1201v1.dat", &un_804D6FE0, - "visual1201v1Scene", NULL); - lbArchive_LoadSymbols("TyKoopa.dat", &un_804D6FEC, - "ToyKoopaModel_TopN_joint", NULL); - lbArchive_LoadSymbols("GmRgStnd.dat", &un_804D6FE4, "standScene", NULL); - Toy_803124BC(); - un_804D6FE8 = lbArchive_LoadSymbols(gm_80160438(char_index), NULL); + un_8031FD18_LoadArchives(input); gobj = GObj_Create(0x13, 0x14, 0); cobj = @@ -287,7 +302,7 @@ void un_8031FD18_OnEnter(void* arg) lb_8000C290(jobj, un_804D6FF0); gobj = GObj_Create(0xB, 3, 0); - fog = HSD_FogLoadDesc(un_804D6FE0->fogs->desc); + fog = un_8031FD18_LoadFog(); HSD_GObjObject_80390A70(gobj, HSD_GObj_804D7848, fog); GObj_SetupGXLink(gobj, HSD_GObj_FogCallback, 0, 0); HSD_GObj_SetupProc(gobj, fn_8031FCBC, 0); diff --git a/src/melee/vi/vi1201v2.c b/src/melee/vi/vi1201v2.c index f10c3fa544..1720314242 100644 --- a/src/melee/vi/vi1201v2.c +++ b/src/melee/vi/vi1201v2.c @@ -257,13 +257,13 @@ void un_80320A40_OnEnter(void* arg) un_804D701C = lbArchive_LoadSymbols(un_80400304.vi1201v2_dat, &un_804D7010, un_80400304.visual1201v2_scene, NULL); + lbArchive_LoadSymbols(un_80400304.tykoopa_dat, &un_804D7020, + un_80400304.toykoopa_model_topn_joint, NULL); { - char* toykoopa_joint = un_80400304.toykoopa_model_topn_joint; - char* tykoopa_dat = un_80400304.tykoopa_dat; - lbArchive_LoadSymbols(tykoopa_dat, &un_804D7020, toykoopa_joint, NULL); + char* gmrgstnd_dat = un_80400304.gmrgstnd_dat; + lbArchive_LoadSymbols(gmrgstnd_dat, &un_804D7014, + un_80400304.stand_scene, NULL); } - lbArchive_LoadSymbols(un_80400304.gmrgstnd_dat, &un_804D7014, - un_80400304.stand_scene, NULL); Toy_803124BC(); un_804D7018 = lbArchive_LoadSymbols(viGetCharAnimByIndex(char_index), NULL); diff --git a/src/sysdolphin/baselib/axdriver.c b/src/sysdolphin/baselib/axdriver.c index 68706d1aa4..56f3f66a17 100644 --- a/src/sysdolphin/baselib/axdriver.c +++ b/src/sysdolphin/baselib/axdriver.c @@ -196,10 +196,32 @@ u32 AXDriver_8038C678(u32 param_type, u32 param_value) } } +/// MSL sqrtf expansion (src/MSL/math_ppc.h) writing its result through a +/// caller-provided slot, as in sqrtf_store in lbcollision.c and mplib.c. +/// Evidence: retail AXDriver_8038BF6C keeps its eight sqrt results in +/// adjacent 4-byte stack temps at frame offsets 0x10..0x2C (an 8-byte +/// aligned base), one slot per call in source order, each accessed as a +/// stfs/lfs pair. The volatile-qualified accesses through the slot pointer +/// pin those pairs without changing behavior. +static inline float sqrtf_store(float x, volatile float* y) +{ + if (x > 0.0F) { + double guess = __frsqrte((double) x); + guess = 0.5 * guess * (3.0 - guess * guess * x); + guess = 0.5 * guess * (3.0 - guess * guess * x); + guess = 0.5 * guess * (3.0 - guess * guess * x); + *y = (float) (x * guess); + return *(volatile float*) y; + } + return x; +} + void AXDriver_8038BF6C(HSD_SM* v) { u32 flag; int i; + /// sqrtf result slots; retail frame offsets 0x10..0x2C (base aligned 8) + float sqrt_tmp[8] ATTRIBUTE_ALIGN(8); for (i = 0; i <= 9; i++) { flag = 1 << i; @@ -209,10 +231,12 @@ void AXDriver_8038BF6C(HSD_SM* v) case 0x1: { float left_vol = (v->x26 * v->x24[0]) / 65535.0F; float right_vol = (v->x27 * v->x24[1]) / 65535.0F; - float left_sqrt = sqrtf(left_vol); - float left_inv_sqrt = sqrtf(1.0F - left_vol); - float right_sqrt = sqrtf(right_vol); - float right_inv_sqrt = sqrtf(1.0F - right_vol); + float left_sqrt = sqrtf_store(left_vol, &sqrt_tmp[7]); + float left_inv_sqrt = + sqrtf_store(1.0F - left_vol, &sqrt_tmp[6]); + float right_sqrt = sqrtf_store(right_vol, &sqrt_tmp[5]); + float right_inv_sqrt = + sqrtf_store(1.0F - right_vol, &sqrt_tmp[4]); float tmp2 = left_inv_sqrt * right_inv_sqrt; float pitch1 = powf(2.0F, v->x20 / 1200.0F); float pitch2 = powf(2.0F, v->fadetime / 1200.0F); @@ -260,10 +284,12 @@ void AXDriver_8038BF6C(HSD_SM* v) case 0x80: { float left_vol = (v->x26 * v->x24[0]) / 65535.0F; float right_vol = (v->x27 * v->x24[1]) / 65535.0F; - float left_sqrt = sqrtf(left_vol); - float left_inv_sqrt = sqrtf(1.0F - left_vol); - float right_sqrt = sqrtf(right_vol); - float right_inv_sqrt = sqrtf(1.0F - right_vol); + float left_sqrt = sqrtf_store(left_vol, &sqrt_tmp[3]); + float left_inv_sqrt = + sqrtf_store(1.0F - left_vol, &sqrt_tmp[2]); + float right_sqrt = sqrtf_store(right_vol, &sqrt_tmp[1]); + float right_inv_sqrt = + sqrtf_store(1.0F - right_vol, &sqrt_tmp[0]); HSD_SynthSFXSetMix( v->vID, left_inv_sqrt * (left_inv_sqrt * right_inv_sqrt), diff --git a/src/sysdolphin/baselib/cobj.c b/src/sysdolphin/baselib/cobj.c index 5619baf2e9..50ed8bdf69 100644 --- a/src/sysdolphin/baselib/cobj.c +++ b/src/sysdolphin/baselib/cobj.c @@ -646,6 +646,11 @@ static float upvec2roll(HSD_CObj* cobj, Vec3* up) return dot; } +static inline f32 vec_get_x(Vec3* v) +{ + return v->x; +} + static inline f64 cobj_fabsf_p(f32* v) { return __fabsf(*v); @@ -653,18 +658,19 @@ static inline f64 cobj_fabsf_p(f32* v) static int roll2upvec(HSD_CObj* cobj, Vec3* up, float roll) { + int res; Vec3 eye; Vec3 v0; Vec3 v1; Mtx m; - int res = HSD_CObjGetEyeVector(cobj, &eye); + res = HSD_CObjGetEyeVector(cobj, &eye); if (res != 0) { return res; } if (1.0 - cobj_fabsf_p(&eye.y) < 0.0001) { v0.x = sqrtf(eye.y * eye.y + eye.z * eye.z); - v0.y = eye.y * (-eye.x / v0.x); + v0.y = eye.y * (-vec_get_x(&eye) / v0.x); v0.z = eye.z * (-eye.x / v0.x); } else { v0.y = sqrtf(eye.x * eye.x + eye.z * eye.z); @@ -677,11 +683,6 @@ static int roll2upvec(HSD_CObj* cobj, Vec3* up, float roll) return 0; } -static inline f32 cobj_get_roll(HSD_CObj* cobj) -{ - return cobj->u.roll; -} - static inline f32 cobj_get_up_x(Vec3* up) { return up->x; @@ -694,7 +695,7 @@ int HSD_CObjGetUpVector(HSD_CObj* cobj, Vec3* up) *up = cobj->u.up; return 0; } - if (roll2upvec(cobj, up, cobj_get_roll(cobj)) == 0) { + if (roll2upvec(cobj, up, cobj->u.roll) == 0) { return 0; } } @@ -835,7 +836,6 @@ MtxPtr HSD_CObjGetInvViewingMtxPtr(HSD_CObj* cobj) void HSD_CObjSetRoll(HSD_CObj* cobj, float roll) { Vec3 up; - PAD_STACK(4); if (!cobj) { return; diff --git a/src/sysdolphin/baselib/debug.h b/src/sysdolphin/baselib/debug.h index dc5876b753..ca658a800e 100644 --- a/src/sysdolphin/baselib/debug.h +++ b/src/sysdolphin/baselib/debug.h @@ -23,6 +23,11 @@ ATTRIBUTE_NORETURN void HSD_Panic(char*, u32, char*); #define HSD_ASSERTREPORT(line, cond, ...) \ ((cond) ? (void) 0 \ : (OSReport(__VA_ARGS__), __assert(__FILE__, line, #cond))) +/// HSD_ASSERTREPORT for code split out of a larger retail TU: the retail +/// __FILE__ string and stringized condition belong to the original TU's +/// data, so they are taken as explicit arguments (see @todo above). +#define HSD_ASSERTREPORTFILE(file, line, cond, msg, ...) \ + ((cond) ? (void) 0 : (OSReport(__VA_ARGS__), __assert(file, line, msg))) #else #define HSD_ASSERT(line, cond) \ ((cond) ? ((void) 0) : __assert(__FILE__, __LINE__, #cond)) @@ -31,6 +36,9 @@ ATTRIBUTE_NORETURN void HSD_Panic(char*, u32, char*); #define HSD_ASSERTREPORT(line, cond, ...) \ ((cond) ? (void) 0 \ : (OSReport(__VA_ARGS__), __assert(__FILE__, __LINE__, #cond))) +#define HSD_ASSERTREPORTFILE(file, line, cond, msg, ...) \ + ((cond) ? (void) 0 \ + : (OSReport(__VA_ARGS__), __assert(__FILE__, __LINE__, #cond))) #endif int report_func(__file_handle arg0, unsigned char* arg1, size_t* arg2, diff --git a/src/sysdolphin/baselib/hsd_3A94.c b/src/sysdolphin/baselib/hsd_3A94.c index ebad363315..9af047e543 100644 --- a/src/sysdolphin/baselib/hsd_3A94.c +++ b/src/sysdolphin/baselib/hsd_3A94.c @@ -27,10 +27,10 @@ typedef struct CardBlock { } CardBlock; #define CMD_S32(off) \ - (((CardBufEntry*) (hsd_804D1138 + (off)))[hsd_804D7980].x0) + (((CardBufEntry*) ((unsigned char*) op + (off)))[hsd_804D7980].x0) #define CMD_STATE ((CardState*) CMD_S32(0x14)) #define CMD_PTR(off) ((void*) CMD_S32(off)) -#define CMD_TYPE (((CardBufEntry*) hsd_804D1138)[hsd_804D7980].x10) +#define CMD_TYPE (op[hsd_804D7980].x10) static inline s32 hsd_803A949C_Close(CardState* state) { @@ -68,6 +68,7 @@ static inline s32 hsd_803A949C_FileId(CardBlock* block) void hsd_803A949C(s32 chan, s32 arg1) { + CardBufEntry* op = (CardBufEntry*) hsd_804D1138; CardState* state; CardBlock* block; s32 result; diff --git a/src/sysdolphin/baselib/hsd_3AA7.c b/src/sysdolphin/baselib/hsd_3AA7.c index b6785519d3..2e65defa89 100644 --- a/src/sysdolphin/baselib/hsd_3AA7.c +++ b/src/sysdolphin/baselib/hsd_3AA7.c @@ -158,6 +158,7 @@ s32 hsd_803AAA48(void) s32 r; s32 retries; BOOL intr2; + PAD_STACK(128); while (1) { CardBufEntry* op = (CardBufEntry*) hsd_804D1138; @@ -223,7 +224,7 @@ s32 hsd_803AAA48(void) } } } - if ((void (*)(s32, s32)) op->x8 != NULL) { + if (op->x8 != 0) { ((void (*)(s32, s32)) op->x8)(op->xC, hsd_804D7988.status); } op->x0 = 0; @@ -1017,24 +1018,25 @@ void fn_803AC3F8(void* arg0, u8* data, s32 file_idx) void hsd_803AC558(struct CardState* file_desc, u8* data) { + u8* cur = data + 1; int i; + for (i = 0; i < 3; i++) { - u8 byte1 = data[1]; - u8 file_idx; - u32 size; - u8 flags; - data++; - file_idx = data[-1]; - size = (u32) data[1] | ((byte1 << 8) & 0x3F00); - flags = (byte1 >> 6) & 3; + u8 byte1 = cur[0]; + u8 file_idx = cur[-1]; + u8 mid = cur[1]; + u32 size = (u32) mid | ((byte1 << 8) & 0x3F00); + u8 low = cur[2]; + u8 flags = (byte1 >> 6) & 3; size <<= 8; - size |= data[2]; - data += 3; + size |= low; + cur += 3; if (size != 0 && file_desc->x4C[file_idx] == 0) { file_desc->x28[file_idx] = flags; file_desc->x4C[file_idx] = size; } + cur++; } } @@ -1053,14 +1055,13 @@ u32 fn_803AC634(struct CardState* file_desc, s32 file_idx) } if (file_idx == 0) { - u32 sector_size = file_desc->x8; u32 usable; + u32 sector_size = file_desc->x8; s32 remaining; remaining = file_desc->x4C[0]; - remaining = remaining - (s32) ((sector_size - 0x20) - + remaining = remaining - (s32) ((usable = sector_size - 0x20) - (file_desc->x24 + 48) % sector_size); - usable = sector_size - 0x20; if (remaining <= 0) { return 1; } @@ -1074,7 +1075,76 @@ u32 fn_803AC634(struct CardState* file_desc, s32 file_idx) } } +inline u32 fn_803AC6B8_first_block_count(struct CardState* file_desc) +{ + if (file_desc->x4C[0] <= 0) { + return 0; + } + + { + u32 usable; + u32 sector_size = file_desc->x8; + s32 remaining; + + remaining = file_desc->x4C[0]; + remaining = remaining - (s32) ((usable = sector_size - 0x20) - + (file_desc->x24 + 48) % sector_size); + if (remaining <= 0) { + return 1; + } + return (u32) (remaining + sector_size - 0x21) / usable + 1; + } +} + s32 fn_803AC6B8(struct CardState* file_desc, s32 file_count) +{ + u32 sector_size; + s32 remaining; + u32 usable; + s32 blocks; + s32 file_size; + s32 total; + s32 i; + + if (file_count >= 9) { + return 0; + } + if (file_count == 0) { + return 0; + } + + total = 1; + if (file_desc->x4C[0] > 0) { + total += fn_803AC6B8_first_block_count(file_desc) - 1; + } + + for (i = 1; i < file_count; i++) { + file_size = file_desc->x4C[i]; + if (file_size <= 0) { + blocks = 0; + } else if (i == 0) { + sector_size = file_desc->x8; + remaining = file_desc->x4C[0] - + (s32) ((usable = sector_size - 0x20) - + (file_desc->x24 + 48) % sector_size); + if (remaining <= 0) { + blocks = 1; + } else { + blocks = (u32) (remaining + sector_size - 0x21) / usable + 1; + } + } else { + sector_size = file_desc->x8; + blocks = + (u32) (file_size + sector_size - 0x21) / (sector_size - 0x20); + } + total += blocks; + } + + return total; +} + +static inline s32 fn_803AC6B8_blocks_before(struct CardState* file_desc, + s32 file_count) { s32 total; s32 i; @@ -1105,13 +1175,13 @@ inline u32 fn_803AC7DC_block_count(struct CardState* file_desc, s32 file_idx) } if (file_idx == 0) { + u32 usable; u32 sector_size = file_desc->x8; s32 remaining; - u32 usable; remaining = file_desc->x4C[0]; - remaining = fn_803AC634_remaining(sector_size, file_desc, remaining); - usable = sector_size - 0x20; + remaining = remaining - (s32) ((usable = sector_size - 0x20) - + (file_desc->x24 + 48) % sector_size); if (remaining <= 0) { return 1; } @@ -1214,6 +1284,7 @@ s32 fn_803ACC0C(CardState* state, s32 block_idx, s32 file_id, s32 seq_num, u8* buf; u32 sector_size; u8* data; + u32 read_offset; s32 offset; PAD_STACK(4); @@ -1224,12 +1295,24 @@ s32 fn_803ACC0C(CardState* state, s32 block_idx, s32 file_id, s32 seq_num, sector_size = state->x8; retries = 0; buf = state->x0; - offset = state->x24 + sector_size; - offset = (offset + 0x2F) / sector_size; - offset = sector_size * (block_idx + offset - 1); + { + u32 temp = state->x24 + sector_size; + u32 num = temp + 0x2F; + + temp = num / sector_size; + { + u32 idx = temp - 1; + idx = block_idx + idx; + read_offset = sector_size * idx; + } + } for (; retries < 10; retries++) { - result = CARDRead(&state->file_info, buf, sector_size, offset); + { + s32 tmp = + CARDRead(&state->file_info, buf, sector_size, read_offset); + result = tmp; + } if (result != -1) { break; } @@ -1381,31 +1464,21 @@ s32 fn_803ACF30(CardState* state, s32 file_id, s32 seq_num, s32 version) return 0; } +typedef u8* CardSectorPtr; + static inline u8* fn_803ACFC0_payload_dst(CardState* state, s32 hdr_offset) { - return state->x0 + hdr_offset + 0x20; + return hdr_offset + state->x0 + 0x20; } static inline u8* fn_803ACFC0_header(CardState* state, s32 hdr_offset) { - return state->x0 + hdr_offset; + return (CardSectorPtr) (hdr_offset + (s32) state->x0); } -static inline s32 fn_803ACFC0_write_block(CardState* state, s32 offset) +static inline u8* fn_803ACFC0_checksum_start(s32 hdr_offset, CardState* state) { - u8* buf; - s32 retries; - s32 result; - u32 write_size = state->x8; - - buf = state->x0; - for (retries = 0; retries < 10; retries++) { - result = CARDWrite(&state->file_info, buf, write_size, offset); - if (result != -1) { - break; - } - } - return result; + return hdr_offset + state->x0; } s32 fn_803ACFC0(CardState* state, s32 block_idx, s32 file_id, s32 seq_num, @@ -1448,15 +1521,16 @@ s32 fn_803ACFC0(CardState* state, s32 block_idx, s32 file_id, s32 seq_num, } if (payload_size > 0) { - memcpy(fn_803ACFC0_payload_dst(state, hdr_offset), payload, + memcpy(&fn_803ACFC0_header(state, hdr_offset)[0x20], payload, payload_size); } { s32 remaining = (state->x8 - hdr_offset) - payload_size - 0x20; if (remaining != 0) { - memset(state->x0 + (payload_size + 0x20) + hdr_offset, 0, - remaining); + s32 off = payload_size + 0x20; + s32 addr = (s32) state->x0; + memset((CardSectorPtr) (hdr_offset + off + addr), 0, remaining); } } @@ -1467,18 +1541,69 @@ s32 fn_803ACFC0(CardState* state, s32 block_idx, s32 file_id, s32 seq_num, (state->x0 + hdr_offset)[0x12] = (u8) seq_num; fn_803AC3F8(state, fn_803ACFC0_header(state, hdr_offset) + 0x13, version); - hsd_803B2FA0(state->x0 + hdr_offset, state->x8 - hdr_offset); + hsd_803B2FA0(fn_803ACFC0_checksum_start(hdr_offset, state), + state->x8 - hdr_offset); - result = fn_803ACFC0_write_block(state, offset); + { + s32 write_retries; + u8* write_buf; + u32 write_size; + write_size = state->x8; + write_retries = 0; + write_buf = state->x0; + for (; write_retries < 10; write_retries++) { + result = + CARDWrite(&state->file_info, write_buf, write_size, offset); + if (result != -1) { + break; + } + } + } return result; } +static inline int fn_803AD16C_file_type_nonzero(CardState* state, s32 file_id) +{ + return state->x28[file_id] != 0; +} + +static inline s32 fn_803AD16C_total_blocks(CardState* state) +{ + return state->x460; +} + +static inline s32 fn_803AD16C_logical_index(s32 blocks_before, s32 i) +{ + return blocks_before + i; +} + +static inline s32 fn_803AD16C_file_size(CardState* state, s32 file_id) +{ + return state->x4C[file_id]; +} + +static inline s32 fn_803AD16C_seq_at(s32* seq, s32 phys) +{ + return seq[phys]; +} + +static inline int fn_803AD16C_nonnegative(s32 logical) +{ + return logical >= 0; +} + +static inline s32 fn_803AD16C_queue_cmd(s32* cmd) +{ + return fn_803AC168(cmd); +} + s32 fn_803AD16C(CardState* state) { s32 work[64]; s32 seq[64]; s32 newmap[64]; + s32 pad; s32 filemap[64]; s32 chosen[64]; s32 result; @@ -1486,9 +1611,10 @@ s32 fn_803AD16C(CardState* state) s32 pass; s32 i; s32 phys; + s32 ofs; s32 blocks_before; s32 file_blocks; - PAD_STACK(68); + PAD_STACK(56); result = 0; for (i = 0; i <= state->x460; i++) { @@ -1507,7 +1633,7 @@ s32 fn_803AD16C(CardState* state) continue; } - blocks_before = fn_803AC6B8(state, file_id); + blocks_before = fn_803AC6B8_blocks_before(state, file_id); for (i = 0; i < file_blocks; i++) { filemap[i] = -1; @@ -1517,12 +1643,13 @@ s32 fn_803AD16C(CardState* state) for (pass = 0; pass <= state->x460; pass++) { s32 cur_seq = -1; - for (phys = 0; phys <= state->x460; phys++) { + for (phys = 0; phys <= fn_803AD16C_total_blocks(state); phys++) { if (work[phys] >= 0) { s32 logical = work[phys] - blocks_before; if (logical >= 0 && logical < file_blocks) { if (cur_seq == -1 || - fn_803ACB74(cur_seq, seq[phys]) > 0) + fn_803ACB74(cur_seq, + fn_803AD16C_seq_at(seq, phys)) > 0) { cur_seq = seq[phys]; } @@ -1535,8 +1662,8 @@ s32 fn_803AD16C(CardState* state) for (phys = 0; phys <= state->x460; phys++) { s32 logical = work[phys] - blocks_before; - if (logical >= 0 && logical < file_blocks && - cur_seq == seq[phys]) + if (fn_803AD16C_nonnegative(logical) && + logical < file_blocks && cur_seq == seq[phys]) { filemap[logical] = phys; } @@ -1571,12 +1698,15 @@ s32 fn_803AD16C(CardState* state) } } else { for (i = 0; i < file_blocks; i++) { - if (filemap[i] < 0) { - result = -0x103; - } else { - newmap[blocks_before + i] = filemap[i]; - if (result != -0x103) { - result = -0x104; + { + s32 tmp = filemap[i]; + if (tmp < 0) { + result = -0x103; + } else { + newmap[blocks_before + i] = filemap[i]; + if (result != -0x103) { + result = -0x104; + } } } } @@ -1584,17 +1714,17 @@ s32 fn_803AD16C(CardState* state) } for (file_id = 0; file_id < 9; file_id++) { - if (state->x4C[file_id] <= 0 || + if (fn_803AD16C_file_size(state, file_id) <= 0 || (state->x28[file_id] != 1 && state->x28[file_id] != 2)) { continue; } file_blocks = fn_803AC634(state, file_id); - blocks_before = fn_803AC6B8(state, file_id); + blocks_before = fn_803AC6B8_blocks_before(state, file_id); for (i = 0; i < file_blocks; i++) { - s32 logical = blocks_before + i; + s32 logical = fn_803AD16C_logical_index(blocks_before, i); if (newmap[logical] >= 0) { for (phys = 1; phys <= state->x460; phys++) { if (phys != newmap[logical] && @@ -1608,12 +1738,14 @@ s32 fn_803AD16C(CardState* state) } for (file_id = 0; file_id < 9; file_id++) { - if (state->x4C[file_id] <= 0 || state->x28[file_id] != 0) { + if (state->x4C[file_id] <= 0 || + fn_803AD16C_file_type_nonzero(state, file_id)) + { continue; } file_blocks = fn_803AC634(state, file_id); - blocks_before = fn_803AC6B8(state, file_id); + blocks_before = fn_803AC6B8_blocks_before(state, file_id); for (i = 0; i < file_blocks; i++) { s32 logical = blocks_before + i; @@ -1622,17 +1754,18 @@ s32 fn_803AD16C(CardState* state) s32 target_seq; s32 ret; - if (src < 0) { + if (newmap[logical] < 0) { continue; } target_seq = state->x270[src]; dup = -1; for (phys = 1; phys <= state->x460; phys++) { - if (phys != src && state->x170[phys] == logical) { + if (phys != newmap[logical] && state->x170[phys] == logical) { if (dup < 0) { dup = phys; } else { + pad = fn_803ACBE8(state, phys); if (phys == 0) { ret = -0x101; } else { @@ -1644,9 +1777,9 @@ s32 fn_803AD16C(CardState* state) cmd[5] = 0; cmd[6] = 0; cmd[8] = 0; - cmd[7] = fn_803ACBE8(state, phys); + cmd[7] = pad; cmd[2] = file_id; - ret = fn_803AC168(cmd); + ret = fn_803AD16C_queue_cmd(cmd); } if (ret < 0 && result == 0) { result = -0x10B; @@ -1665,23 +1798,25 @@ s32 fn_803AD16C(CardState* state) } } if (dup >= 0) { - if (src == 0 || dup == 0) { + if (newmap[logical] == 0 || dup == 0) { ret = -0x101; } else { s32 cmd[9]; + pad = fn_803ACBE8(state, newmap[logical]); cmd[0] = 0xF; cmd[1] = (s32) state; - cmd[3] = src; - cmd[7] = fn_803ACBE8(state, src); + cmd[3] = newmap[logical]; + cmd[7] = pad; ret = fn_803AC168(cmd); if (ret >= 0) { s32 cmd2[9]; + pad = fn_803ACBE8(state, dup); cmd2[0] = 0x10; cmd2[1] = (s32) state; cmd2[3] = dup; cmd2[4] = logical; cmd2[5] = target_seq; - cmd2[7] = fn_803ACBE8(state, dup); + cmd2[7] = pad; ret = fn_803AC168(cmd2); } } @@ -1690,23 +1825,28 @@ s32 fn_803AD16C(CardState* state) } } } else if (state->x270[dup] != target_seq) { - if (src == 0 || dup == 0) { + if (newmap[logical] == 0 || dup == 0) { ret = -0x101; } else { s32 cmd[9]; + pad = fn_803ACBE8(state, newmap[logical]); cmd[0] = 0xF; cmd[1] = (s32) state; - cmd[3] = src; - cmd[7] = fn_803ACBE8(state, src); - ret = fn_803AC168(cmd); + cmd[3] = newmap[logical]; + cmd[7] = pad; + { + s32 cmd_result = fn_803AC168(cmd); + ret = cmd_result; + } if (ret >= 0) { s32 cmd2[9]; + pad = fn_803ACBE8(state, dup); cmd2[0] = 0x10; cmd2[1] = (s32) state; cmd2[3] = dup; cmd2[4] = logical; cmd2[5] = target_seq; - cmd2[7] = fn_803ACBE8(state, dup); + cmd2[7] = pad; ret = fn_803AC168(cmd2); } } @@ -1779,31 +1919,62 @@ static inline s32 fn_803ADF90_read(CardState* state, void* buf, s32 offset) return CARDRead(&state->file_info, buf, state->x8, offset); } +static inline void fn_803ADF90_calc_file_blocks(s32 file_size, s32 file_idx, + CardState* arg0, + s32* remaining, + s32* file_blocks) +{ + CardState* state = arg0; + *remaining = file_size; + if (file_size <= 0) { + *file_blocks = 0; + } else if (file_idx == 0) { + u32 sector_size = state->x8; + u32 usable; + s32 rem; + + rem = state->x4C[0]; + usable = sector_size - 0x20; + rem = rem - (s32) (usable - (state->x24 + 0x30) % sector_size); + if (rem <= 0) { + *file_blocks = 1; + } else { + *file_blocks = + (u32) (rem + sector_size - 0x21) / (sector_size - 0x20) + 1; + } + } else { + u32 sector_size = state->x8; + *file_blocks = + (u32) (*remaining + sector_size - 0x21) / (sector_size - 0x20); + } +} + s32 fn_803ADF90(struct CardState* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) { CardState* state = arg0; CardBufEntry* entries = (CardBufEntry*) hsd_804D1138; + u8* dst; + s32 remaining; s32 block_map[64]; s32 blocks_before; s32 saved; s32 i; s32 logical; - u8* dst; s32 result; s32 file_blocks; s32 seq_num; s32 snap; s32 total_blocks; s32 ofs; - s32 remaining; s32 file_size; s32 callback_seq; - PAD_STACK(64); + PAD_STACK(56); callback_seq = 0; if (arg3 == 0) { - BOOL intr = OSDisableInterrupts(); + BOOL intr_state = OSDisableInterrupts(); + BOOL intr = intr_state; s32 busy; if (hsd_804D799C == 1) { busy = 1; @@ -1816,27 +1987,11 @@ s32 fn_803ADF90(struct CardState* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) } } - blocks_before = fn_803AC6B8(arg0, arg1); + blocks_before = fn_803AC6B8_blocks_before(arg0, arg1); file_size = state->x4C[arg1]; - remaining = file_size; - if (file_size <= 0) { - file_blocks = 0; - } else if (arg1 == 0) { - u32 sector_size = state->x8; - s32 rem = state->x4C[0] - (s32) ((sector_size - 0x20) - - (state->x24 + 0x30) % sector_size); - if (rem <= 0) { - file_blocks = 1; - } else { - file_blocks = - (u32) (rem + sector_size - 0x21) / (sector_size - 0x20) + 1; - } - } else { - u32 sector_size = state->x8; - file_blocks = - (u32) (remaining + sector_size - 0x21) / (sector_size - 0x20); - } + fn_803ADF90_calc_file_blocks(file_size, arg1, arg0, &remaining, + &file_blocks); total_blocks = fn_803AC7DC(arg0); for (i = 0; i < file_blocks; i++) { @@ -2106,12 +2261,11 @@ s32 fn_803AE7F8(struct CardState* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) CardBufEntry* entries = (CardBufEntry*) hsd_804D1138; s32 saved; s32 snap; - s32 primary[64]; - s32 secondary[64]; - s32 free_blocks[64]; + s32 block_map[3][64]; s32 blocks_before; s32 current_seq; s32 file_blocks; + s32 file_size; s32 free_count; s32 i; s32 logical; @@ -2120,6 +2274,7 @@ s32 fn_803AE7F8(struct CardState* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) s32 total_blocks; s32 verify_failed; u8* data; + PAD_STACK(80); repair_result = 0; verify_failed = 0; @@ -2137,59 +2292,90 @@ s32 fn_803AE7F8(struct CardState* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) } } - blocks_before = fn_803AC6B8(arg0, arg1); + blocks_before = fn_803AC6B8_blocks_before(arg0, arg1); - if (state->x4C[arg1] > 0) { - file_blocks = fn_803AC634(arg0, arg1); - } else { + { + s32 loaded_size = state->x4C[arg1]; + file_size = loaded_size; + } + if (file_size <= 0) { file_blocks = 0; + } else if (arg1 == 0) { + u32 sector_size = state->x8; + s32 rem = state->x4C[0] - (s32) ((sector_size - 0x20) - + (state->x24 + 0x30) % sector_size); + if (rem <= 0) { + file_blocks = 1; + } else { + u32 blocks = + (u32) (rem + sector_size - 0x21) / (sector_size - 0x20); + file_blocks = blocks + 1; + } + } else { + u32 sector_size = state->x8; + file_blocks = + (u32) (file_size + sector_size - 0x21) / (sector_size - 0x20); } - current_seq = -1; - free_count = 0; total_blocks = fn_803AC7DC(arg0); for (i = 0; i < file_blocks; i++) { - primary[i] = -1; - secondary[i] = -1; + block_map[0][i] = -1; + block_map[1][i] = -1; } - for (i = 0; i < total_blocks; i++) { - s32 phys = i + 1; - s32 file_idx = state->x170[phys]; + free_count = 0; + current_seq = -1; + + for (i = 1; i <= total_blocks; i++) { + s32 file_idx = state->x170[i]; if (file_idx < 0) { - free_blocks[free_count++] = phys; + block_map[2][free_count++] = i; continue; } logical = file_idx - blocks_before; if (logical >= 0 && logical < file_blocks) { if (current_seq == -1 || - fn_803ACB74(current_seq, state->x270[phys]) < 0) + fn_803ACB74(current_seq, state->x270[i]) < 0) { - current_seq = state->x270[phys]; + current_seq = state->x270[i]; } - if (primary[logical] < 0) { - primary[logical] = phys; + if (block_map[0][logical] < 0) { + block_map[0][logical] = i; } else { - secondary[logical] = phys; + block_map[1][logical] = i; } } } for (i = 0; i < file_blocks; i++) { - if (primary[i] < 0) { - if (free_count <= 0) { + if (block_map[0][i] < 0 || state->x270[block_map[0][i]] != current_seq) + { + verify_failed = 1; + break; + } + if (block_map[1][i] < 0 || state->x270[block_map[1][i]] != current_seq) + { + verify_failed = 1; + break; + } + } + + for (i = 0; i < file_blocks; i++) { + if (block_map[0][i] < 0) { + if (free_count > 0) { + block_map[0][i] = block_map[2][--free_count]; + } else { return -257; } - primary[i] = free_blocks[--free_count]; } - if (secondary[i] < 0) { - if (free_count <= 0) { - repair_result = -258; + if (block_map[1][i] < 0) { + if (free_count > 0) { + block_map[1][i] = block_map[2][--free_count]; } else { - secondary[i] = free_blocks[--free_count]; + repair_result = -258; } } } @@ -2212,15 +2398,12 @@ s32 fn_803AE7F8(struct CardState* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) } } - if (current_seq >= 0) { - s32* maps[2]; + if (verify_failed == 0) { s32 pass; + s32* map = block_map[0]; - maps[0] = primary; - maps[1] = secondary; - for (pass = 0; pass < 2 && !verify_failed; pass++) { - s32 remaining = state->x4C[arg1]; - s32* map = maps[pass]; + for (pass = 0; pass < 2; pass++, map += 64) { + s32 remaining = file_size; data = (u8*) arg2; for (i = 0; i < file_blocks && remaining > 0; i++) { @@ -2230,17 +2413,22 @@ s32 fn_803AE7F8(struct CardState* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) if (remaining > chunk) { if (phys >= 0) { if (arg3 != 0) { - s32 cmd[9]; + s32 cmd_result; + if (chunk == 0) { + cmd_result = 0; + } else { + s32 cmd[9]; - cmd[0] = 5; - cmd[1] = (s32) arg0; - cmd[4] = blocks_before + i; - cmd[5] = current_seq; - cmd[6] = (s32) data; - cmd[7] = fn_803ACBE8(arg0, phys); - cmd[8] = chunk; - result = fn_803AC168(cmd); - if (result < 0) { + cmd[0] = 5; + cmd[1] = (s32) arg0; + cmd[4] = blocks_before + i; + cmd[5] = current_seq; + cmd[6] = (s32) data; + cmd[7] = fn_803ACBE8(arg0, phys); + cmd[8] = chunk; + cmd_result = fn_803AC168(cmd); + } + if (cmd_result < 0) { snap = hsd_804D7998; (void) snap; if (snap >= 0) { @@ -2251,7 +2439,7 @@ s32 fn_803AE7F8(struct CardState* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) } hsd_804D7984 = snap; } - return result; + return cmd_result; } } else { result = fn_803ACC0C(arg0, phys, blocks_before + i, @@ -2277,17 +2465,22 @@ s32 fn_803AE7F8(struct CardState* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) } else { if (phys >= 0) { if (arg3 != 0) { - s32 cmd[9]; + s32 cmd_result; + if (remaining == 0) { + cmd_result = 0; + } else { + s32 cmd[9]; - cmd[0] = 5; - cmd[1] = (s32) arg0; - cmd[4] = blocks_before + i; - cmd[5] = current_seq; - cmd[6] = (s32) data; - cmd[7] = fn_803ACBE8(arg0, phys); - cmd[8] = remaining; - result = fn_803AC168(cmd); - if (result < 0) { + cmd[0] = 5; + cmd[1] = (s32) arg0; + cmd[4] = blocks_before + i; + cmd[5] = current_seq; + cmd[6] = (s32) data; + cmd[7] = fn_803ACBE8(arg0, phys); + cmd[8] = remaining; + cmd_result = fn_803AC168(cmd); + } + if (cmd_result < 0) { snap = hsd_804D7998; if (snap >= 0) { saved = snap; @@ -2297,7 +2490,7 @@ s32 fn_803AE7F8(struct CardState* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) } hsd_804D7984 = snap; } - return result; + return cmd_result; } } else { result = fn_803ACC0C(arg0, phys, blocks_before + i, @@ -2323,7 +2516,7 @@ s32 fn_803AE7F8(struct CardState* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) } } - if (!verify_failed) { + if (verify_failed == 0) { if (arg3 != 0) { s32 cmd[9]; @@ -2361,14 +2554,11 @@ s32 fn_803AE7F8(struct CardState* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) current_seq = (u8) (current_seq + 1); { - s32* maps[2]; s32 pass; + s32* map = block_map[0]; - maps[0] = primary; - maps[1] = secondary; - for (pass = 0; pass < 2; pass++) { - s32 remaining = state->x4C[arg1]; - s32* map = maps[pass]; + for (pass = 0; pass < 2; pass++, map += 64) { + s32 remaining = file_size; data = (u8*) arg2; for (i = 0; i < file_blocks && remaining > 0; i++) { @@ -2379,19 +2569,23 @@ s32 fn_803AE7F8(struct CardState* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) if (phys >= 0) { if (arg3 != 0) { s32 ofs = fn_803ACBE8(arg0, phys); - if (phys == 0 && blocks_before + i != 0) { - result = -0x101; - } else { + s32 cmd_result; + do { if (phys == 0) { - s32 cmd[9]; - cmd[0] = 2; - cmd[1] = (s32) arg0; - cmd[4] = 0; - cmd[5] = 0; - cmd[6] = 0; - cmd[7] = ofs; - cmd[8] = 0; - fn_803AC168(cmd); + if (blocks_before + i != 0) { + cmd_result = -0x101; + break; + } else { + s32 cmd[9]; + cmd[0] = 2; + cmd[1] = (s32) arg0; + cmd[4] = 0; + cmd[5] = 0; + cmd[6] = 0; + cmd[7] = ofs; + cmd[8] = 0; + fn_803AC168(cmd); + } } { s32 cmd[9]; @@ -2404,10 +2598,10 @@ s32 fn_803AE7F8(struct CardState* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) cmd[6] = (s32) data; cmd[7] = ofs; cmd[8] = chunk; - result = fn_803AC168(cmd); + cmd_result = fn_803AC168(cmd); } - } - if (result < 0) { + } while (0); + if (cmd_result < 0) { snap = hsd_804D7998; if (snap >= 0) { saved = snap; @@ -2417,15 +2611,15 @@ s32 fn_803AE7F8(struct CardState* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) } hsd_804D7984 = snap; } - return result; + return cmd_result; } } else { result = fn_803ACFC0(arg0, phys, blocks_before + i, current_seq, data, chunk, arg1); if (result < 0) { - state->x170[phys] = -0x7FFF; - state->x270[phys] = 0; + state->x170[block_map[pass][i]] = -0x7FFF; + state->x270[block_map[pass][i]] = 0; { s32 retries; for (retries = 0; retries < 10; retries++) @@ -2440,8 +2634,8 @@ s32 fn_803AE7F8(struct CardState* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) } } - state->x170[phys] = blocks_before + i; - state->x270[phys] = current_seq; + state->x170[map[i]] = blocks_before + i; + state->x270[map[i]] = current_seq; } remaining -= chunk; @@ -2450,19 +2644,23 @@ s32 fn_803AE7F8(struct CardState* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) if (phys >= 0) { if (arg3 != 0) { s32 ofs = fn_803ACBE8(arg0, phys); - if (phys == 0 && blocks_before + i != 0) { - result = -0x101; - } else { + s32 cmd_result; + do { if (phys == 0) { - s32 cmd[9]; - cmd[0] = 2; - cmd[1] = (s32) arg0; - cmd[4] = 0; - cmd[5] = 0; - cmd[6] = 0; - cmd[7] = ofs; - cmd[8] = 0; - fn_803AC168(cmd); + if (blocks_before + i != 0) { + cmd_result = -0x101; + break; + } else { + s32 cmd[9]; + cmd[0] = 2; + cmd[1] = (s32) arg0; + cmd[4] = 0; + cmd[5] = 0; + cmd[6] = 0; + cmd[7] = ofs; + cmd[8] = 0; + fn_803AC168(cmd); + } } { s32 cmd[9]; @@ -2475,10 +2673,10 @@ s32 fn_803AE7F8(struct CardState* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) cmd[6] = (s32) data; cmd[7] = ofs; cmd[8] = remaining; - result = fn_803AC168(cmd); + cmd_result = fn_803AC168(cmd); } - } - if (result < 0) { + } while (0); + if (cmd_result < 0) { snap = hsd_804D7998; if (snap >= 0) { saved = snap; @@ -2488,15 +2686,15 @@ s32 fn_803AE7F8(struct CardState* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) } hsd_804D7984 = snap; } - return result; + return cmd_result; } } else { result = fn_803ACFC0(arg0, phys, blocks_before + i, current_seq, data, remaining, arg1); if (result < 0) { - state->x170[phys] = -0x7FFF; - state->x270[phys] = 0; + state->x170[block_map[pass][i]] = -0x7FFF; + state->x270[block_map[pass][i]] = 0; { s32 retries; for (retries = 0; retries < 10; retries++) @@ -2511,8 +2709,8 @@ s32 fn_803AE7F8(struct CardState* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) } } - state->x170[phys] = blocks_before + i; - state->x270[phys] = current_seq; + state->x170[map[i]] = blocks_before + i; + state->x270[map[i]] = current_seq; } remaining = 0; @@ -2544,26 +2742,67 @@ s32 fn_803AE7F8(struct CardState* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) return repair_result; } +static inline s32 fn_803AF3F0_blocks_before(CardState* state, s32 file_count) +{ + s32 total; + s32 i; + + if (file_count >= 9) { + return 0; + } + if (file_count == 0) { + return 0; + } + + total = 1; + if (state->x4C[0] > 0) { + total = fn_803AC634(state, 0); + } + + for (i = 1; i < file_count; i++) { + total += fn_803AC634(state, i); + } + + return total; +} + +static inline s32 fn_803AF3F0_chunk_size(CardState* state) +{ + return state->x8 - 0x20; +} + +static inline void fn_803AF3F0_file_size(s32 arg1, CardState* state, + s32* file_size) +{ + { + s32 size = state->x4C[arg1]; + *file_size = size; + } +} + s32 fn_803AF3F0(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) { - CardState* state = (CardState*) arg0; + s32 snap; CardBufEntry* entries = (CardBufEntry*) hsd_804D1138; - s32 primary[64]; - s32 secondary[64]; - s32 free_blocks[64]; + s32 saved; + CardState* state = (CardState*) arg0; + s32 block_map[3][64]; + s32* secondary_ptr; + s32* free_ptr; s32 blocks_before; s32 file_blocks; + s32 file_size; s32 total_blocks; s32 current_seq; + s32 seq_match; s32 secondary_count; s32 free_count; s32 i; s32 remaining; s32 result; - s32 saved; - s32 seq_match; - s32 snap; + s32 retries; u8* data; + PAD_STACK(84); seq_match = 0; if (arg3 == 0) { @@ -2580,12 +2819,26 @@ s32 fn_803AF3F0(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) } } - blocks_before = fn_803AC6B8(state, arg1); + blocks_before = fn_803AF3F0_blocks_before(state, arg1); - if (state->x4C[arg1] > 0) { - file_blocks = fn_803AC634(state, arg1); - } else { + fn_803AF3F0_file_size(arg1, state, &file_size); + if (file_size <= 0) { file_blocks = 0; + } else if (arg1 == 0) { + u32 sector_size = state->x8; + s32 rem = + (sector_size - 0x20) - (s32) ((state->x24 + 0x30) % sector_size); + rem = state->x4C[0] - rem; + if (rem <= 0) { + file_blocks = 1; + } else { + file_blocks = + (u32) (rem + sector_size - 0x21) / (sector_size - 0x20) + 1; + } + } else { + u32 sector_size = state->x8; + file_blocks = + (u32) (file_size + sector_size - 0x21) / (sector_size - 0x20); } total_blocks = fn_803AC7DC(state); @@ -2593,69 +2846,76 @@ s32 fn_803AF3F0(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) if (arg3 != 0) { hsd_804D7998 = hsd_804D7984; } else { - s32 retries; s32 fd = state->x4; s32 ofs = state->x20; + s32 open_result; for (retries = 0; retries < 10; retries++) { - result = CARDFastOpen(fd, ofs, &state->file_info); - if (result != -1) { + open_result = CARDFastOpen(fd, ofs, &state->file_info); + if (open_result != -1) { break; } } - if (result < 0) { - return result; + if (open_result < 0) { + return open_result; } } for (i = 0; i < file_blocks; i++) { - primary[i] = -1; - secondary[i] = -1; + block_map[0][i] = -1; + block_map[1][i] = -1; } current_seq = -1; secondary_count = 0; free_count = 0; - for (i = 0; i < total_blocks; i++) { - s32 file_idx = state->x170[i + 1]; + secondary_ptr = block_map[0]; + free_ptr = block_map[0]; + for (i = 1; i <= total_blocks; i++) { + s32 arg1x = state->x170[i]; - if (file_idx >= 0) { - s32 logical = file_idx - blocks_before; + if (arg1x >= 0) { + s32 logical = arg1x - blocks_before; if (logical >= 0 && logical < file_blocks) { if (current_seq < 0 || - fn_803ACB74(current_seq, state->x270[i + 1]) < 0) + fn_803ACB74(current_seq, state->x270[i]) < 0) { - current_seq = state->x270[i + 1]; + current_seq = state->x270[i]; } - primary[logical] = i + 1; + block_map[0][logical] = i; } } else { - s32 logical = -(file_idx + blocks_before); + s32 logical = -(arg1x + blocks_before); if (logical >= 0 && logical < file_blocks) { - secondary[secondary_count++] = i + 1; + secondary_ptr[64] = i; + secondary_ptr++; + secondary_count++; } else { - free_blocks[free_count++] = i + 1; + free_ptr[128] = i; + free_ptr++; + free_count++; } } } for (i = 0; i < file_blocks; i++) { - if (primary[i] < 0 || state->x270[primary[i]] != current_seq) { + if (block_map[0][i] < 0 || state->x270[block_map[0][i]] != current_seq) + { seq_match = 1; break; } } if (seq_match == 0) { - remaining = state->x4C[arg1]; + remaining = file_size; data = (u8*) arg2; for (i = 0; i < file_blocks && remaining > 0; i++) { - s32 chunk = state->x8 - 0x20; + s32 chunk = fn_803AF3F0_chunk_size(state); if (remaining > chunk) { if (arg3 != 0) { if (chunk != 0) { s32 cmd[9]; - s32 ofs = fn_803ACBE8(state, primary[i]); + s32 ofs = fn_803ACBE8(state, block_map[0][i]); cmd[0] = 5; cmd[1] = (s32) state; cmd[4] = blocks_before + i; @@ -2678,10 +2938,10 @@ s32 fn_803AF3F0(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) return result; } } else { - result = fn_803ACC0C(state, primary[i], blocks_before + i, - current_seq, data, chunk); + result = + fn_803ACC0C(state, block_map[0][i], blocks_before + i, + current_seq, data, chunk); if (result < 0) { - s32 retries; for (retries = 0; retries < 10; retries++) { if (CARDClose(&state->file_info) != -1) { break; @@ -2699,7 +2959,7 @@ s32 fn_803AF3F0(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) if (arg3 != 0) { if (remaining != 0) { s32 cmd[9]; - s32 ofs = fn_803ACBE8(state, primary[i]); + s32 ofs = fn_803ACBE8(state, block_map[0][i]); cmd[0] = 5; cmd[1] = (s32) state; cmd[4] = blocks_before + i; @@ -2722,10 +2982,10 @@ s32 fn_803AF3F0(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) return result; } } else { - result = fn_803ACC0C(state, primary[i], blocks_before + i, - current_seq, data, remaining); + result = + fn_803ACC0C(state, block_map[0][i], blocks_before + i, + current_seq, data, remaining); if (result < 0) { - s32 retries; for (retries = 0; retries < 10; retries++) { if (CARDClose(&state->file_info) != -1) { break; @@ -2760,7 +3020,6 @@ s32 fn_803AF3F0(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) return result; } } else { - s32 retries; for (retries = 0; retries < 10; retries++) { result = CARDClose(&state->file_info); if (result != -1) { @@ -2778,13 +3037,13 @@ s32 fn_803AF3F0(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) if (secondary_count > file_blocks) { for (i = file_blocks; i < secondary_count; i++) { if (arg3 != 0) { - if (secondary[i] != 0) { + if (block_map[1][i] != 0) { s32 cmd[9]; - s32 ofs = fn_803ACBE8(state, secondary[i]); + s32 ofs = fn_803ACBE8(state, block_map[1][i]); cmd[0] = 1; cmd[1] = (s32) state; cmd[2] = arg1; - cmd[3] = secondary[i]; + cmd[3] = block_map[1][i]; cmd[4] = 0xFFFF; cmd[5] = 0; cmd[6] = 0; @@ -2807,12 +3066,11 @@ s32 fn_803AF3F0(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) return result; } } else { - result = - fn_803ACFC0(state, secondary[i], 0xFFFF, 0, NULL, 0, arg1); - state->x170[secondary[i]] = -0x7FFF; - state->x270[secondary[i]] = 0; + result = fn_803ACFC0(state, block_map[1][i], 0xFFFF, 0, NULL, + 0, arg1); + state->x170[block_map[1][i]] = -0x7FFF; + state->x270[block_map[1][i]] = 0; if (result < 0) { - s32 retries; for (retries = 0; retries < 10; retries++) { if (CARDClose(&state->file_info) != -1) { break; @@ -2824,17 +3082,16 @@ s32 fn_803AF3F0(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) } } else if (secondary_count < file_blocks) { while (secondary_count < file_blocks && free_count > 0) { - secondary[secondary_count++] = free_blocks[--free_count]; + block_map[1][secondary_count++] = block_map[2][--free_count]; } for (i = 0; secondary_count < file_blocks && i < file_blocks; i++) { - if (primary[i] >= 0) { - secondary[secondary_count++] = primary[i]; - primary[i] = -1; + if (block_map[0][i] >= 0) { + block_map[1][secondary_count++] = block_map[0][i]; + block_map[0][i] = -1; } } if (secondary_count < file_blocks) { if (arg3 == 0) { - s32 retries; for (retries = 0; retries < 10; retries++) { if (CARDClose(&state->file_info) != -1) { break; @@ -2846,18 +3103,18 @@ s32 fn_803AF3F0(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) } current_seq = (u8) (current_seq + 1); - remaining = state->x4C[arg1]; + remaining = file_size; data = (u8*) arg2; for (i = 0; i < file_blocks && remaining > 0; i++) { s32 chunk = state->x8 - 0x20; if (remaining > chunk) { if (arg3 != 0) { - s32 ofs = fn_803ACBE8(state, secondary[i]); - if (secondary[i] == 0 && blocks_before + i != 0) { + s32 ofs = fn_803ACBE8(state, block_map[1][i]); + if (block_map[1][i] == 0 && blocks_before + i != 0) { result = -0x101; } else { - if (secondary[i] == 0) { + if (block_map[1][i] == 0) { s32 cmd[9]; cmd[0] = 2; cmd[1] = (s32) state; @@ -2873,7 +3130,7 @@ s32 fn_803AF3F0(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) cmd[0] = 1; cmd[1] = (s32) state; cmd[2] = arg1; - cmd[3] = secondary[i]; + cmd[3] = block_map[1][i]; cmd[4] = blocks_before + i; cmd[5] = current_seq; cmd[6] = (s32) data; @@ -2895,13 +3152,12 @@ s32 fn_803AF3F0(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) return result; } } else { - result = fn_803ACFC0(state, secondary[i], blocks_before + i, + result = fn_803ACFC0(state, block_map[1][i], blocks_before + i, current_seq, data, chunk, arg1); if (result < 0) { - state->x170[secondary[i]] = -0x7FFF; - state->x270[secondary[i]] = 0; + state->x170[block_map[1][i]] = -0x7FFF; + state->x270[block_map[1][i]] = 0; { - s32 retries; for (retries = 0; retries < 10; retries++) { if (CARDClose(&state->file_info) != -1) { break; @@ -2910,18 +3166,18 @@ s32 fn_803AF3F0(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) } return result; } - state->x170[secondary[i]] = blocks_before + i; - state->x270[secondary[i]] = current_seq; + state->x170[block_map[1][i]] = blocks_before + i; + state->x270[block_map[1][i]] = current_seq; } remaining -= chunk; data += chunk; } else { if (arg3 != 0) { - s32 ofs = fn_803ACBE8(state, secondary[i]); - if (secondary[i] == 0 && blocks_before + i != 0) { + s32 ofs = fn_803ACBE8(state, block_map[1][i]); + if (block_map[1][i] == 0 && blocks_before + i != 0) { result = -0x101; } else { - if (secondary[i] == 0) { + if (block_map[1][i] == 0) { s32 cmd[9]; cmd[0] = 2; cmd[1] = (s32) state; @@ -2937,7 +3193,7 @@ s32 fn_803AF3F0(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) cmd[0] = 1; cmd[1] = (s32) state; cmd[2] = arg1; - cmd[3] = secondary[i]; + cmd[3] = block_map[1][i]; cmd[4] = blocks_before + i; cmd[5] = current_seq; cmd[6] = (s32) data; @@ -2959,13 +3215,12 @@ s32 fn_803AF3F0(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) return result; } } else { - result = fn_803ACFC0(state, secondary[i], blocks_before + i, + result = fn_803ACFC0(state, block_map[1][i], blocks_before + i, current_seq, data, remaining, arg1); if (result < 0) { - state->x170[secondary[i]] = -0x7FFF; - state->x270[secondary[i]] = 0; + state->x170[block_map[1][i]] = -0x7FFF; + state->x270[block_map[1][i]] = 0; { - s32 retries; for (retries = 0; retries < 10; retries++) { if (CARDClose(&state->file_info) != -1) { break; @@ -2974,18 +3229,17 @@ s32 fn_803AF3F0(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) } return result; } - state->x170[secondary[i]] = blocks_before + i; - state->x270[secondary[i]] = current_seq; + state->x170[block_map[1][i]] = blocks_before + i; + state->x270[block_map[1][i]] = current_seq; } remaining = 0; } } if (arg3 == 0) { - s32 retries; for (i = 0; i < file_blocks; i++) { - if (primary[i] >= 0) { - state->x170[primary[i]] = -state->x170[primary[i]]; + if (block_map[0][i] >= 0) { + state->x170[block_map[0][i]] = -state->x170[block_map[0][i]]; } } for (retries = 0; retries < 10; retries++) { @@ -3008,22 +3262,36 @@ s32 fn_803AF3F0(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) return 0; } +static inline void fn_803B0120_blk97637(s32 arg1, CardState* state, + s32* file_size) +{ + { + s32 size = state->x4C[arg1]; + (*file_size) = size; + } +} + +static inline u32 fn_803B0120_block_count(u32 sector_size, u32 file_size) +{ + return (file_size + sector_size - 0x21) / (sector_size - 0x20); +} + s32 fn_803B0120(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) { - CardState* state = (CardState*) arg0; + s32 snap; CardBufEntry* entries = (CardBufEntry*) hsd_804D1138; s32 saved; - s32 snap; + CardState* state = (CardState*) arg0; s32 block_map[3][64]; s32* secondary_ptr; s32* free_ptr; s32 blocks_before; - s32 file_blocks; + s32 secondary_count; s32 file_size; s32 total_blocks; s32 current_seq; s32 needs_rewrite; - s32 secondary_count; + s32 file_blocks; s32 free_count; s32 i; s32 remaining; @@ -3046,15 +3314,16 @@ s32 fn_803B0120(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) } } - blocks_before = fn_803AC6B8(state, arg1); + blocks_before = fn_803AC6B8_blocks_before(state, arg1); - file_size = state->x4C[arg1]; + fn_803B0120_blk97637(arg1, state, &file_size); if (file_size <= 0) { file_blocks = 0; } else if (arg1 == 0) { u32 sector_size = state->x8; - s32 rem = state->x4C[0] - (s32) ((sector_size - 0x20) - - (state->x24 + 0x30) % sector_size); + s32 rem = + (sector_size - 0x20) - (s32) ((state->x24 + 0x30) % sector_size); + rem = state->x4C[0] - rem; if (rem <= 0) { file_blocks = 1; } else { @@ -3063,8 +3332,7 @@ s32 fn_803B0120(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) } } else { u32 sector_size = state->x8; - file_blocks = - (u32) (file_size + sector_size - 0x21) / (sector_size - 0x20); + file_blocks = fn_803B0120_block_count(sector_size, file_size); } total_blocks = fn_803AC7DC(state); @@ -3072,17 +3340,18 @@ s32 fn_803B0120(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) if (arg3 != 0) { hsd_804D7998 = hsd_804D7984; } else { + s32 ofs = state->x20; s32 retries; s32 fd = state->x4; - s32 ofs = state->x20; + s32 r; for (retries = 0; retries < 10; retries++) { - result = CARDFastOpen(fd, ofs, &state->file_info); - if (result != -1) { + r = CARDFastOpen(fd, ofs, &state->file_info); + if (r != -1) { break; } } - if (result < 0) { - return result; + if (r < 0) { + return r; } } @@ -3092,6 +3361,7 @@ s32 fn_803B0120(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) } current_seq = -1; + secondary_count = 0; if (arg1 == 0) { if (state->x170[0] == 0) { current_seq = state->x270[0]; @@ -3101,18 +3371,16 @@ s32 fn_803B0120(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) block_map[0][0] = 0; } - secondary_count = 0; free_count = 0; - secondary_ptr = block_map[0]; free_ptr = block_map[0]; for (i = 1; i <= total_blocks; i++) { s32 file_idx = state->x170[i]; if (file_idx >= 0) { - s32 logical = file_idx - blocks_before; + s32 file_idx_off = file_idx - blocks_before; + s32 logical = file_idx_off; if (arg1 == 0 && logical == 0) { - secondary_ptr[64] = i; - secondary_ptr++; + block_map[1][secondary_count] = i; secondary_count++; } else if (logical >= 0 && logical < file_blocks) { if (current_seq < 0 || @@ -3125,8 +3393,7 @@ s32 fn_803B0120(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) } else { s32 logical = -(file_idx + blocks_before); if (logical >= 0 && logical < file_blocks) { - secondary_ptr[64] = i; - secondary_ptr++; + block_map[1][secondary_count] = i; secondary_count++; } else { free_ptr[128] = i; @@ -3136,6 +3403,8 @@ s32 fn_803B0120(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) } } + secondary_ptr = &block_map[0][secondary_count]; + free_ptr = &block_map[0][free_count]; for (i = 0; i < file_blocks; i++) { if (block_map[0][i] < 0) { needs_rewrite = 1; @@ -3178,10 +3447,10 @@ s32 fn_803B0120(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) remaining = file_size; data = (u8*) arg2; for (i = 0; i < file_blocks && remaining > 0; i++) { + s32 logical = blocks_before + i; s32 chunk; - if (blocks_before + i == 0) { + if (logical == 0) { chunk = (state->x8 - 0x20) - ((state->x24 + 0x30) % state->x8); - (void) chunk; } else { chunk = state->x8 - 0x20; } @@ -3311,13 +3580,61 @@ s32 fn_803B0120(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) } } } + while (secondary_count > 0) { + secondary_count--; + if (arg3 != 0) { + if (block_map[1][secondary_count] != 0) { + s32 cmd[9]; + s32 ofs = fn_803ACBE8(state, block_map[1][secondary_count]); + cmd[0] = 1; + cmd[1] = (s32) state; + cmd[2] = arg1; + cmd[3] = block_map[1][secondary_count]; + cmd[4] = 0xFFFF; + cmd[5] = 0; + cmd[6] = 0; + cmd[7] = ofs; + cmd[8] = 0; + result = fn_803AC168(cmd); + } else { + result = -257; + } + if (result < 0) { + snap = hsd_804D7998; + if (snap >= 0) { + saved = snap; + while (saved != hsd_804D7984) { + entries[saved].x10 = 0; + saved = (saved + 1) % 128; + } + hsd_804D7984 = snap; + } + return result; + } + } else { + result = fn_803ACFC0(state, block_map[1][secondary_count], 0xFFFF, + 0, NULL, 0, arg1); + state->x170[block_map[1][secondary_count]] = -0x7FFF; + state->x270[block_map[1][secondary_count]] = 0; + if (result < 0) { + s32 retries; + for (retries = 0; retries < 10; retries++) { + if (CARDClose(&state->file_info) != -1) { + break; + } + } + return result; + } + } + } current_seq = (u8) (current_seq + 1); - remaining = file_size; data = (u8*) arg2; + remaining = file_size; for (i = 0; i < file_blocks && remaining > 0; i++) { + s32 logical = blocks_before + i; s32 chunk; - if (blocks_before + i == 0) { + if (logical == 0) { chunk = (state->x8 - 0x20) - ((state->x24 + 0x30) % state->x8); } else { chunk = state->x8 - 0x20; @@ -3326,7 +3643,7 @@ s32 fn_803B0120(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) if (remaining > chunk) { if (arg3 != 0) { s32 ofs = fn_803ACBE8(state, block_map[0][i]); - if (block_map[0][i] == 0 && blocks_before + i != 0) { + if (block_map[0][i] == 0 && logical != 0) { result = -0x101; } else { if (block_map[0][i] == 0) { @@ -3367,8 +3684,11 @@ s32 fn_803B0120(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) return result; } } else { - result = fn_803ACFC0(state, block_map[0][i], blocks_before + i, - current_seq, data, chunk, arg1); + { + s32 block = block_map[0][i]; + result = fn_803ACFC0(state, block, blocks_before + i, + current_seq, data, chunk, arg1); + } if (result < 0) { state->x170[block_map[0][i]] = -0x7FFF; state->x270[block_map[0][i]] = 0; @@ -3390,7 +3710,7 @@ s32 fn_803B0120(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) } else { if (arg3 != 0) { s32 ofs = fn_803ACBE8(state, block_map[0][i]); - if (block_map[0][i] == 0 && blocks_before + i != 0) { + if (block_map[0][i] == 0 && logical != 0) { result = -0x101; } else { if (block_map[0][i] == 0) { @@ -3453,54 +3773,6 @@ s32 fn_803B0120(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) } } - while (secondary_count > 0) { - secondary_count--; - if (arg3 != 0) { - if (block_map[1][secondary_count] != 0) { - s32 cmd[9]; - s32 ofs = fn_803ACBE8(state, block_map[1][secondary_count]); - cmd[0] = 1; - cmd[1] = (s32) state; - cmd[2] = arg1; - cmd[3] = block_map[1][secondary_count]; - cmd[4] = 0xFFFF; - cmd[5] = 0; - cmd[6] = 0; - cmd[7] = ofs; - cmd[8] = 0; - result = fn_803AC168(cmd); - } else { - result = -257; - } - if (result < 0) { - snap = hsd_804D7998; - if (snap >= 0) { - saved = snap; - while (saved != hsd_804D7984) { - entries[saved].x10 = 0; - saved = (saved + 1) % 128; - } - hsd_804D7984 = snap; - } - return result; - } - } else { - result = fn_803ACFC0(state, block_map[1][secondary_count], 0xFFFF, - 0, NULL, 0, arg1); - state->x170[block_map[1][secondary_count]] = -0x7FFF; - state->x270[block_map[1][secondary_count]] = 0; - if (result < 0) { - s32 retries; - for (retries = 0; retries < 10; retries++) { - if (CARDClose(&state->file_info) != -1) { - break; - } - } - return result; - } - } - } - if (arg3 == 0) { s32 retries; for (retries = 0; retries < 10; retries++) { @@ -3524,6 +3796,11 @@ s32 fn_803B0120(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) return 0; } +static inline CARDFileInfo* fn_803B0E9C_file_info(struct CardState* arg0) +{ + return &arg0->file_info; +} + s32 fn_803B0E9C(struct CardState* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) { u8 digest[0x30]; @@ -3542,6 +3819,7 @@ s32 fn_803B0E9C(struct CardState* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) s32 digest_idx; s32 result; u32 sector_size; + s32 arg1_copy = arg1; arg0->x24 = hsd_803AC340(&arg0->x3B0); @@ -3552,7 +3830,7 @@ s32 fn_803B0E9C(struct CardState* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) { cmd_read_icon[0] = 10; cmd_read_icon[1] = (s32) arg0; - cmd_read_icon[3] = arg1; + cmd_read_icon[3] = arg1_copy; cmd_read_icon[4] = arg2; cmd_read_icon[2] = block_idx; result = fn_803AC168(cmd_read_icon); @@ -3577,7 +3855,7 @@ s32 fn_803B0E9C(struct CardState* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) return result; } } else { - result = fn_803ACD58(arg0, (void*) arg1, (void*) arg2); + result = fn_803ACD58(arg0, (UNK_T) arg1_copy, (UNK_T) arg2); if (result < 0) { return result; } @@ -3633,7 +3911,7 @@ s32 fn_803B0E9C(struct CardState* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) cmd_write_icon[0] = 9; cmd_write_icon[1] = (s32) arg0; cmd_write_icon[2] = arg4; - cmd_write_icon[3] = arg1; + cmd_write_icon[3] = arg1_copy; cmd_write_icon[4] = arg2; result = fn_803AC168(cmd_write_icon); if (result < 0) { @@ -3650,8 +3928,10 @@ s32 fn_803B0E9C(struct CardState* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) memset(arg0->x0, 0, sector_size); } else { s32 retries; + u8* buf = arg0->x0; for (retries = 0; retries < 10; retries++) { - result = CARDRead(&arg0->file_info, arg0->x0, sector_size, 0); + result = + CARDRead(fn_803B0E9C_file_info(arg0), buf, sector_size, 0); if (result != -1) { break; } @@ -3668,13 +3948,13 @@ s32 fn_803B0E9C(struct CardState* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) switch (arg0->x3B0) { case 2: { void* dst = arg0->x0 + 0x40; - memcpy(dst, (void*) arg1, 0x1800); + memcpy(dst, (UNK_T) arg1_copy, 0x1800); } payload_pos = 0x1840; break; case 1: { void* dst = arg0->x0 + 0x40; - memcpy(dst, (void*) arg1, 0xE00); + memcpy(dst, (UNK_T) arg1_copy, 0xE00); } payload_pos = 0xE40; break; @@ -3688,15 +3968,16 @@ s32 fn_803B0E9C(struct CardState* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) while (remaining >= 0) { sector_size = arg0->x8; if ((u32) (payload_pos + remaining) > sector_size) { - s32 copied = sector_size - payload_pos; s32 retries; s32 offset; u32 write_size; u8* buf; - memcpy(arg0->x0 + payload_pos, (void*) arg2, copied); - arg2 += copied; - remaining -= copied; + memcpy(arg0->x0 + payload_pos, (s32*) arg2, + sector_size - payload_pos); + sector_size = arg0->x8; + arg2 += sector_size - payload_pos; + remaining -= sector_size - payload_pos; hsd_803B2B20(arg0->x0, sector_size, &digest[digest_idx]); write_size = arg0->x8; @@ -3866,11 +4147,11 @@ s32 fn_803B1338(CardState* state, s32 arg1) sector_size - hdr_offset - 0x20, 0); offset = state->x8 - hdr_offset - 0x20; } - } - if (result < 0 && result != -0x105) { - state->x170[0] = -0x7FFF; - state->x270[0] = 0; - return result; + if (result < 0 && result != -0x105) { + state->x170[0] = -0x7FFF; + state->x270[0] = 0; + return result; + } } for (i = 1; i < file0_blocks; i++) { @@ -3878,19 +4159,22 @@ s32 fn_803B1338(CardState* state, s32 arg1) fdata = state->x70[0].ptr; if (fdata == NULL) { s32 ofs = fn_803ACBE8(state, logical); - if (logical == 0 && phys != 0) { - result = -0x101; - } else { + do { if (logical == 0) { - s32 cmd[9]; - cmd[0] = 2; - cmd[1] = (s32) state; - cmd[4] = 0; - cmd[5] = 0; - cmd[6] = 0; - cmd[8] = 0; - cmd[7] = ofs; - fn_803AC168(cmd); + if (phys != 0) { + result = -0x101; + break; + } else { + s32 cmd[9]; + cmd[0] = 2; + cmd[1] = (s32) state; + cmd[4] = 0; + cmd[5] = 0; + cmd[6] = 0; + cmd[8] = 0; + cmd[7] = ofs; + fn_803AC168(cmd); + } } { s32 cmd[9]; @@ -3905,24 +4189,27 @@ s32 fn_803B1338(CardState* state, s32 arg1) cmd[2] = 0; result = fn_803AC168(cmd); } - } + } while (0); } else { u8* wdata = fdata + offset; s32 chunk = state->x8 - 0x20; s32 ofs = fn_803ACBE8(state, logical); - if (logical == 0 && phys != 0) { - result = -0x101; - } else { + do { if (logical == 0) { - s32 cmd[9]; - cmd[0] = 2; - cmd[1] = (s32) state; - cmd[4] = 0; - cmd[5] = 0; - cmd[6] = 0; - cmd[8] = 0; - cmd[7] = ofs; - fn_803AC168(cmd); + if (phys != 0) { + result = -0x101; + break; + } else { + s32 cmd[9]; + cmd[0] = 2; + cmd[1] = (s32) state; + cmd[4] = 0; + cmd[5] = 0; + cmd[6] = 0; + cmd[8] = 0; + cmd[7] = ofs; + fn_803AC168(cmd); + } } { s32 cmd[9]; @@ -3939,7 +4226,7 @@ s32 fn_803B1338(CardState* state, s32 arg1) } offset += state->x8; offset -= 0x20; - } + } while (0); } if (result < 0) { return result; @@ -3978,19 +4265,22 @@ s32 fn_803B1338(CardState* state, s32 arg1) fdata = state->x70[file_id].ptr; if (fdata == NULL) { s32 ofs = fn_803ACBE8(state, logical); - if (logical == 0 && phys != 0) { - result = -0x101; - } else { + do { if (logical == 0) { - s32 cmd[9]; - cmd[0] = 2; - cmd[1] = (s32) state; - cmd[4] = 0; - cmd[5] = 0; - cmd[6] = 0; - cmd[8] = 0; - cmd[7] = ofs; - fn_803AC168(cmd); + if (phys != 0) { + result = -0x101; + break; + } else { + s32 cmd[9]; + cmd[0] = 2; + cmd[1] = (s32) state; + cmd[4] = 0; + cmd[5] = 0; + cmd[6] = 0; + cmd[8] = 0; + cmd[7] = ofs; + fn_803AC168(cmd); + } } { s32 cmd[9]; @@ -4005,24 +4295,27 @@ s32 fn_803B1338(CardState* state, s32 arg1) cmd[2] = file_id; result = CARD_QUEUE_CMD(cmd); } - } + } while (0); } else { u8* wdata = fdata + offset; s32 chunk = state->x8 - 0x20; s32 ofs = fn_803ACBE8(state, logical); - if (logical == 0 && phys != 0) { - result = -0x101; - } else { + do { if (logical == 0) { - s32 cmd[9]; - cmd[0] = 2; - cmd[1] = (s32) state; - cmd[4] = 0; - cmd[5] = 0; - cmd[6] = 0; - cmd[8] = 0; - cmd[7] = ofs; - fn_803AC168(cmd); + if (phys != 0) { + result = -0x101; + break; + } else { + s32 cmd[9]; + cmd[0] = 2; + cmd[1] = (s32) state; + cmd[4] = 0; + cmd[5] = 0; + cmd[6] = 0; + cmd[8] = 0; + cmd[7] = ofs; + fn_803AC168(cmd); + } } { s32 cmd[9]; @@ -4039,7 +4332,7 @@ s32 fn_803B1338(CardState* state, s32 arg1) } offset += state->x8; offset -= 0x20; - } + } while (0); } if (result < 0) { return result; @@ -4130,19 +4423,22 @@ s32 fn_803B1338(CardState* state, s32 arg1) fdata = state->x70[file_id].ptr; if (fdata == NULL) { s32 ofs = fn_803ACBE8(state, logical); - if (logical == 0 && phys != 0) { - result = -0x101; - } else { + do { if (logical == 0) { - s32 cmd[9]; - cmd[0] = 2; - cmd[1] = (s32) state; - cmd[4] = 0; - cmd[5] = 0; - cmd[6] = 0; - cmd[8] = 0; - cmd[7] = ofs; - fn_803AC168(cmd); + if (phys != 0) { + result = -0x101; + break; + } else { + s32 cmd[9]; + cmd[0] = 2; + cmd[1] = (s32) state; + cmd[4] = 0; + cmd[5] = 0; + cmd[6] = 0; + cmd[8] = 0; + cmd[7] = ofs; + fn_803AC168(cmd); + } } { s32 cmd[9]; @@ -4157,24 +4453,27 @@ s32 fn_803B1338(CardState* state, s32 arg1) cmd[2] = file_id; result = fn_803AC168(cmd); } - } + } while (0); } else { u8* wdata = fdata + offset; s32 chunk = state->x8 - 0x20; s32 ofs = fn_803ACBE8(state, logical); - if (logical == 0 && phys != 0) { - result = -0x101; - } else { + do { if (logical == 0) { - s32 cmd[9]; - cmd[0] = 2; - cmd[1] = (s32) state; - cmd[4] = 0; - cmd[5] = 0; - cmd[6] = 0; - cmd[8] = 0; - cmd[7] = ofs; - fn_803AC168(cmd); + if (phys != 0) { + result = -0x101; + break; + } else { + s32 cmd[9]; + cmd[0] = 2; + cmd[1] = (s32) state; + cmd[4] = 0; + cmd[5] = 0; + cmd[6] = 0; + cmd[8] = 0; + cmd[7] = ofs; + fn_803AC168(cmd); + } } { s32 cmd[9]; @@ -4191,7 +4490,7 @@ s32 fn_803B1338(CardState* state, s32 arg1) } offset += state->x8; offset -= 0x20; - } + } while (0); } if (result < 0) { return result; @@ -4515,32 +4814,39 @@ s32 hsd_803B2674(CardState* state) return blocks; } +static inline s32 fn_803B26CC_queue(s32* buf) +{ + return fn_803AC168(buf); +} + s32 fn_803B26CC(CardState* state, s32 file_id, s32 seq_num, s32 version, s32 callback) { - s32 buf[9]; + s32 buf[11]; u32 i; s32 result; s32 saved; s32 snap; CardBufEntry* entries = (CardBufEntry*) hsd_804D1138; - PAD_STACK(24); + PAD_STACK(12); state->x24 = hsd_803AC340(&state->x3B0); - hsd_804D7998 = hsd_804D7984; result = 0; - for (i = 0; i < (0x2F + state->x24 + state->x8) / state->x8; i++) { + for (i = 0, hsd_804D7998 = hsd_804D7984; + i < (0x2F + state->x24 + state->x8) / state->x8;) + { buf[0] = 11; buf[1] = (s32) state; buf[2] = (s32) i; buf[3] = file_id; buf[4] = seq_num; buf[5] = version; - result = fn_803AC168(buf); + result = fn_803B26CC_queue(buf); if (result < 0) { break; } + i++; } if (result < 0) { diff --git a/src/sysdolphin/baselib/hsd_3B2E.c b/src/sysdolphin/baselib/hsd_3B2E.c index f908fa870c..f40400e432 100644 --- a/src/sysdolphin/baselib/hsd_3B2E.c +++ b/src/sysdolphin/baselib/hsd_3B2E.c @@ -9,17 +9,16 @@ static s32 lbl_80430BD0[13] = { #pragma dont_inline on -static u8 fn_803B2E04(u8 prev, s32 cur) +static int fn_803B2E04(u8 prev, s32 cur) { u32 mod7; - u8 val; + u32 val; + u32 key; + key = lbl_80430BD0[prev % 13]; + val = prev ^ cur; + val ^= key; mod7 = prev % 7; - val = prev ^ cur ^ lbl_80430BD0[prev % 13]; - - if (mod7 > 6) { - return val; - } switch (mod7) { case 0: @@ -144,9 +143,6 @@ int hsd_803B31CC(u8* data, int len) int i; u32 cur; u8 check[16]; - u8* p; - u8* q; - int j; int k; if (data == NULL) { @@ -164,44 +160,10 @@ int hsd_803B31CC(u8* data, int len) hsd_803B2B20(data + 16, len - 16, check); - p = data; - q = check; - k = 0; - - for (j = 2; j != 0; j--) { - if (*q != *p) { - return -1; - } - if (*++q != *++p) { - return -1; - } - k++; - if (*++q != *++p) { - return -1; - } - k++; - if (*++q != *++p) { - return -1; - } - k++; - if (*++q != *++p) { - return -1; - } - k++; - if (*++q != *++p) { - return -1; - } - k++; - if (*++q != *++p) { - return -1; - } - k++; - if (*++q != *++p) { + for (k = 0; k < 16; k++) { + if (check[k] != data[k]) { return -1; } - q++; - k++; - p++; } return 0; diff --git a/src/sysdolphin/baselib/hsd_3B34.c b/src/sysdolphin/baselib/hsd_3B34.c index 7713bc06ed..9b785e1dc8 100644 --- a/src/sysdolphin/baselib/hsd_3B34.c +++ b/src/sysdolphin/baselib/hsd_3B34.c @@ -182,21 +182,20 @@ void hsd_803B3408(u8* arg0, s32 arg1, s32 arg2, s32 arg3, s32 unused_arg4) s32 work_r10; s32 work_r11; s32 work_r12; - u8* work_r24; s32 work_r26; s32 work_r27; s32 work_r7; - s32 work_r29; + s32 work_r7_2; s32 work_r30; s32 work_r6; - s32 work_r6_2; + u16 scratch_r22_6; s32 work_ctr_2; - s32 work_r7_2; + s32 work_r29; s32 work_r8; s32 work_r9; u16 scratch_r21; u16 scratch_r22_4; - u16 scratch_r22_6; + s32 work_r6_2; u16 scratch_r30; u16* scratch_r5; u8* scratch_r22_3; @@ -207,6 +206,7 @@ void hsd_803B3408(u8* arg0, s32 arg1, s32 arg2, s32 arg3, s32 unused_arg4) work_r11 = 0; work_r12 = 0; for (work_r28 = 0; work_r28 < 2; work_r28++) { + u8* work_r24; work_r8 = work_r11; work_r24 = arg0 + @@ -311,7 +311,7 @@ void hsd_803B3408(u8* arg0, s32 arg1, s32 arg2, s32 arg3, s32 unused_arg4) static void fn_803B376C(u8* arg0) { - f32 scratch_f11; + f32 scratch_f30; f32 scratch_f11_2; f32 scratch_f11_3; f32 scratch_f11_4; @@ -321,9 +321,9 @@ static void fn_803B376C(u8* arg0) f32 scratch_f27; f32 scratch_f6; f32 scratch_f27_3; - f32 scratch_f27_4; - f32 scratch_f30_4; + s32 scratch_r10_2; f32 scratch_f27_6; + f32 scratch_f30_4; f32 scratch_f28; f32 scratch_f28_2; f32 scratch_f28_3; @@ -334,32 +334,25 @@ static void fn_803B376C(u8* arg0) f32 scratch_f29; f32 scratch_f29_2; f32 scratch_f29_3; - f32 scratch_f30; + f32 scratch_f11; f32 scratch_f30_2; f32 scratch_f30_3; f32 scratch_f8_4; f32 scratch_f4; - s32 scratch_r11; f32 scratch_f27_2; f32 scratch_f6_2; f32 scratch_f8; f32 scratch_f8_2; f32 scratch_f8_3; f32 scratch_f27_5; - s32 scratch_r10; - s32 scratch_r10_2; + f32 scratch_f27_4; f32 scratch_f4_2; s32 scratch_r11_2; - s32 scratch_r12; s32 scratch_r12_2; s32 scratch_r29_2; - s32 scratch_r30; s32 scratch_r30_2; - s32 scratch_r31; f32 scratch_f26; - s32 scratch_r7; s32 scratch_r7_2; - s32 scratch_r9; s32 scratch_r9_2; s32 work_ctr; s32 work_ctr_2; @@ -370,8 +363,15 @@ static void fn_803B376C(u8* arg0) work_r4 = (s32*) arg0; for (work_ctr = 8; work_ctr != 0; work_ctr--) { + s32 scratch_r7; f32 scratch_f26_2; + s32 scratch_r9; + s32 scratch_r10; + s32 scratch_r11; + s32 scratch_r12; s32 scratch_r29; + s32 scratch_r30; + s32 scratch_r31; scratch_r29 = work_r4[0]; scratch_r30 = work_r4[7]; scratch_r31 = work_r4[1]; @@ -400,10 +400,10 @@ static void fn_803B376C(u8* arg0) (0.92388 * (f64) scratch_f26)); scratch_f11_3 = (f32) (0.707107 * (f64) (scratch_f8 + scratch_f11_2)); scratch_f8_2 = (f32) (0.707107 * (f64) (scratch_f8 - scratch_f11_2)); - scratch_f30_2 = scratch_f11_3 + scratch_f28_2; + scratch_f30_2 = scratch_f28_2 + scratch_f11_3; scratch_f26_2 = -scratch_f27_3 + scratch_f8_2; scratch_f28_3 = -scratch_f11_3 + scratch_f28_2; - scratch_f27_4 = scratch_f27_3 + scratch_f8_2; + scratch_f27_4 = scratch_f8_2 + scratch_f27_3; work_r4[7] = (s32) ((0.980785 * (f64) scratch_f26_2) + (0.19509 * (f64) scratch_f30_2)); work_r4[5] = (s32) ((0.83147 * (f64) scratch_f27_4) + @@ -445,11 +445,10 @@ static void fn_803B376C(u8* arg0) scratch_f11_6 = (f32) (0.707107 * (f64) (scratch_f8_3 + scratch_f11_5)); scratch_f8_4 = (f32) (0.707107 * (f64) (scratch_f8_3 - scratch_f11_5)); - scratch_f30_4 = scratch_f11_6 + scratch_f29_2; + scratch_f30_4 = scratch_f29_2 + scratch_f11_6; scratch_f27_6 = -scratch_f28_6 + scratch_f8_4; scratch_f29_3 = -scratch_f11_6 + scratch_f29_2; - scratch_f28_7 = scratch_f28_6; - scratch_f28_7 += scratch_f8_4; + scratch_f28_7 = scratch_f28_6 + scratch_f8_4; { f64 scratch_f30_5 = 0.19509 * (f64) scratch_f30_4; work_r4_2[56] = @@ -489,9 +488,12 @@ static void fn_803B376C(u8* arg0) void hsd_803B3CD8(s32 arg0) { - __jmp_buf* jmp_buf; s32 work_r31; + __jmp_buf* jmp_buf; + s32 scratch_r5_9; + u8* work_r26; u8* work_r7; + u16* work_r6; s32 scratch_r0; s32 scratch_r0_2; s32 scratch_r3; @@ -505,7 +507,6 @@ void hsd_803B3CD8(s32 arg0) s32 scratch_r4_22; s32 scratch_r4_23; s32 scratch_r4_2; - s32 scratch_r4_3; s32 scratch_r4_4; s32 scratch_r4_5; s32 scratch_r4_6; @@ -518,12 +519,12 @@ void hsd_803B3CD8(s32 arg0) s32 scratch_r5_6; s32 scratch_r5_7; s32 scratch_r5_8; - s32 scratch_r5_9; + u16* work_r27; s32 work_ctr; s32 work_ctr_2; s32 work_ctr_3; s32 work_r22; - s32 work_r23; + u8* scratch_r8; s32 work_r24; s32 work_r25; s32 work_r28; @@ -542,8 +543,6 @@ void hsd_803B3CD8(s32 arg0) u16 scratch_r29; u16 scratch_r31; u16 scratch_r31_2; - u16* work_r27; - u16* work_r6; u8* scratch_r4_10; u8* scratch_r4_11; u8* scratch_r4_13; @@ -558,32 +557,16 @@ void hsd_803B3CD8(s32 arg0) u8* scratch_r4_29; u8* scratch_r4_8; u8* scratch_r4_9; + s32 work_r23; u8* work_r25_2; - u8* work_r26; - u8* scratch_r8; - PAD_STACK(0x28); - if (arg0 == 0) { - work_r6 = lbl_80431678; - } else { - work_r6 = lbl_8043169C; - } + PAD_STACK(0x20); + work_r6 = (arg0 == 0) ? lbl_80431678 : lbl_8043169C; jmp_buf = &hsd_804D2648; - if (arg0 == 0) { - work_r7 = lbl_80431690; - } else { - work_r7 = lbl_804316B4; - } - if (arg0 == 0) { - work_r27 = (u16*) (lbl_80430C40 + 0x80); - } else { - work_r27 = (u16*) (lbl_80430C40 + 0x268); - } - if (arg0 == 0) { - work_r26 = lbl_80430C40 + 0x1C4; - } else { - work_r26 = lbl_80430C40 + 0x3AC; - } + work_r7 = (arg0 == 0) ? lbl_80431690 : lbl_804316B4; + work_r27 = + (u16*) ((arg0 == 0) ? (lbl_80430C40 + 0x80) : (lbl_80430C40 + 0x268)); + work_r26 = (arg0 == 0) ? (lbl_80430C40 + 0x1C4) : (lbl_80430C40 + 0x3AC); scratch_r8 = (u8*) jmp_buf + (arg0 * 4); work_r25 = M2C_FIELD((u8*) jmp_buf, s32*, 0x718) - M2C_FIELD(scratch_r8 += 0x818, s32*, 0); @@ -592,6 +575,7 @@ void hsd_803B3CD8(s32 arg0) scratch_r5 = (scratch_r0 ^ work_r25) - scratch_r0; work_r4 = 0x1F; for (work_ctr = 4; work_ctr != 0; work_ctr--) { + s32 scratch_r4_3; if (scratch_r5 & (1 << work_r4)) { work_r31 = work_r4 + 1; goto loop_13; @@ -980,10 +964,10 @@ void hsd_803B46D4(void) u8* scratch_r4_8; u8* scratch_r4_9; + scratch_r4 = hsd_804D79A0; sp8.word = lbl_804DEB88[0]; sp8.byte = lbl_804DEB8C[0]; jmp_buf = &hsd_804D2648; - scratch_r4 = hsd_804D79A0; if (scratch_r4 < &hsd_804D79A4[hsd_804D79A8]) { hsd_804D79A0 = scratch_r4 + 1; *scratch_r4 = 0xFF; @@ -1011,7 +995,7 @@ void hsd_803B46D4(void) } else { longjmp(jmp_buf, 1); } - if ((u8*) hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8 - 5]) { + if (hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8] - 5) { memcpy(hsd_804D79A0, &sp8, 5U); hsd_804D79A0 += 5; } else { @@ -1103,8 +1087,8 @@ void hsd_803B4A2C(void) u8* scratch_r4_7; u8* scratch_r4_8; u8* scratch_r4_9; - u8 operand_pad[4]; + PAD_STACK(8); jmp_buf = &hsd_804D2648; scratch_r4 = hsd_804D79A0; if (scratch_r4 < &hsd_804D79A4[hsd_804D79A8]) { @@ -1141,12 +1125,11 @@ void hsd_803B4A2C(void) } else { longjmp(jmp_buf, 1); } - work_r30 = lbl_80431638; - work_r28 = lbl_80431638; + work_r28 = (work_r30 = lbl_80431638); work_r27 = 0; do { - work_r5 = (s32) * (lbl_80430C40 + *work_r28) / (s32) lbl_804D6398; - (void) work_r5; + work_r5 = (s32) * (lbl_80430C40 + *work_r28); + work_r5 /= (s32) lbl_804D6398; work_r3 = (u8) work_r5; scratch_r4_6 = hsd_804D79A0; if (scratch_r4_6 < &hsd_804D79A4[hsd_804D79A8]) { @@ -1195,7 +1178,8 @@ void hsd_803B4A2C(void) } work_r28_2 = 0; do { - work_r5 = (s32) * (lbl_80430C80 + *work_r30) / (s32) lbl_804D6398; + work_r5 = (s32) * (lbl_80430C80 + *work_r30); + work_r5 /= (s32) lbl_804D6398; work_r3 = (u8) work_r5; scratch_r4_12 = hsd_804D79A0; if (scratch_r4_12 < &hsd_804D79A4[hsd_804D79A8]) { @@ -1367,15 +1351,38 @@ void hsd_803B4D64(u32 arg0, u32 arg1) longjmp(jmp_buf, 1); } -s32 hsd_803B51C8(s32 arg0, s32 arg1, s32 arg2, char* arg3, s32 arg4) +s32 hsd_803B51C8(u8* arg0, s32 arg1, s32 arg2, u8* arg3, s32 arg4) { - u8 sp1EC[0x15]; - u8 sp1D0[0x1C]; - u8 sp1B4[0x1C]; - u8 sp100[0xB2]; - u8 sp4C[0xB2]; - s32 scratch_r3_3; - s32 scratch_r3_4; + typedef struct JpegData20 { + s32 x0; + s32 x4; + s32 x8; + s32 xC; + s32 x10; + } JpegData20; + typedef struct JpegData28 { + s32 x0; + s32 x4; + s32 x8; + s32 xC; + s32 x10; + s32 x14; + s32 x18; + } JpegData28; + typedef struct JpegData8 { + s32 x0; + s32 x4; + } JpegData8; + typedef struct JpegWork { + u8 pad_0[0x718]; + s32 coef[0x40]; + s32 prev_dc[3]; + } JpegWork; + char comment[0x15]; + u8 huff_dc_luma[0x1C]; + u8 huff_dc_chroma[0x1C]; + u8 huff_ac_luma[0xB2]; + u8 huff_ac_chroma[0xB2]; s32 scratch_r6_4; s32 scratch_r6_5; s32 scratch_r7_2; @@ -1388,246 +1395,184 @@ s32 hsd_803B51C8(s32 arg0, s32 arg1, s32 arg2, char* arg3, s32 arg4) s32 work_r3; s32 work_r3_2; s32 work_r3_3; - u16 scratch_r0; - u32 scratch_r23; + s32 scratch_r0; + u8* work_r5_4; u8 scratch_r6_3; u8 scratch_r7; u8 scratch_r7_3; - u8* scratch_r3; - u8* scratch_r3_10; - u8* scratch_r3_11; - u8* scratch_r3_12; - u8* scratch_r3_13; - u8* scratch_r3_14; - u8* scratch_r3_15; - u8* scratch_r3_16; - u8* scratch_r3_17; - u8* scratch_r3_18; - u8* scratch_r3_19; - u8* scratch_r3_20; - u8* scratch_r3_21; - u8* scratch_r3_2; - u8* scratch_r3_5; - u8* scratch_r3_6; - u8* scratch_r3_7; - u8* scratch_r3_8; - u8* scratch_r3_9; + u8* work_r5; u8* scratch_r5; u8* scratch_r6; - u8* scratch_r6_2; + const u8* data; u8* quant_table; u8* base; u8* work_r23; u8* work_r26_2; - u8* work_r4; - u8* work_r4_2; + const u8* work_r4; + const u8* work_r4_2; u8* work_r4_3; u8* work_r4_4; u8* work_r4_5; - u8* work_r5; u8* work_r5_2; u8* work_r5_3; - u8* work_r5_4; + u32 scratch_r23; + s32 width; + s32 height; + u8* src; - quant_table = lbl_80430C40; + PAD_STACK(0x28); base = HSD_804D2648_BUF; + src = arg0; + width = arg1; + height = arg2; hsd_804D79A8 = arg4; + data = lbl_803B9670; hsd_804D79AC = 0; - hsd_804D79A4 = (hsd_804D79A0 = (u8*) arg3); - hsd_804D79A0 = (u8*) arg3; - M2C_FIELD(base, s32*, 0x820) = 0; - M2C_FIELD(base, s32*, 0x81C) = 0; - M2C_FIELD(base, s32*, 0x818) = 0; + hsd_804D79A0 = arg3; + hsd_804D79A4 = arg3; + quant_table = lbl_80430C40; + ((JpegWork*) base)->prev_dc[0] = ((JpegWork*) base)->prev_dc[1] = + ((JpegWork*) base)->prev_dc[2] = 0; if (__setjmp((__jmp_buf*) base) != 0) { return 0; } - if ((u8*) hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { - scratch_r3 = hsd_804D79A0; - hsd_804D79A0 = scratch_r3 + 1; - *scratch_r3 = 0xFF; + if (hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { + *hsd_804D79A0++ = 0xFF; } else { longjmp((__jmp_buf*) base, 1); } - if ((u8*) hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { - scratch_r3_2 = hsd_804D79A0; - hsd_804D79A0 = scratch_r3_2 + 1; - *scratch_r3_2 = 0xD8; + if (hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { + *hsd_804D79A0++ = 0xD8; } else { longjmp((__jmp_buf*) base, 1); } hsd_803B46D4(); - M2C_FIELD(sp1EC, s32*, 0) = M2C_FIELD(lbl_803B9670, s32*, 0); - M2C_FIELD(sp1EC, s32*, 4) = M2C_FIELD(lbl_803B9670, s32*, 4); - M2C_FIELD(sp1EC, s32*, 8) = M2C_FIELD(lbl_803B9670, s32*, 8); - M2C_FIELD(sp1EC, s32*, 0xC) = M2C_FIELD(lbl_803B9670, s32*, 0xC); - M2C_FIELD(sp1EC, s32*, 0x10) = M2C_FIELD(lbl_803B9670, s32*, 0x10); - M2C_FIELD(sp1EC, u8*, 0x14) = M2C_FIELD(lbl_803B9670, u8*, 0x14); - scratch_r23 = strlen((char*) sp1EC) + 1; + *(JpegData20*) comment = *(const JpegData20*) data; + comment[0x14] = data[0x14]; + scratch_r23 = strlen(comment) + 1; hsd_803B3344(0xFFU); hsd_803B3344(0xFEU); scratch_r0 = scratch_r23 + 2; hsd_803B3344((u8) (scratch_r0 >> 8U)); hsd_803B3344((u8) scratch_r0); - hsd_803B3398(sp1EC, scratch_r23); + hsd_803B3398(comment, scratch_r23); hsd_803B4A2C(); - M2C_FIELD(sp1D0, s32*, 0) = M2C_FIELD(lbl_803B9670, s32*, 0x18); - M2C_FIELD(sp1D0, s32*, 4) = M2C_FIELD(lbl_803B9670, s32*, 0x1C); - M2C_FIELD(sp1D0, s32*, 8) = M2C_FIELD(lbl_803B9670, s32*, 0x20); - M2C_FIELD(sp1D0, s32*, 0xC) = M2C_FIELD(lbl_803B9670, s32*, 0x24); - M2C_FIELD(sp1D0, s32*, 0x10) = M2C_FIELD(lbl_803B9670, s32*, 0x28); - M2C_FIELD(sp1D0, s32*, 0x14) = M2C_FIELD(lbl_803B9670, s32*, 0x2C); - M2C_FIELD(sp1D0, s32*, 0x18) = M2C_FIELD(lbl_803B9670, s32*, 0x30); + *(JpegData28*) huff_dc_luma = *(const JpegData28*) (data + 0x18); hsd_803B3344(0xFFU); hsd_803B3344(0xC4U); hsd_803B3344(0U); hsd_803B3344(0x1FU); hsd_803B3344(0U); - hsd_803B3398(sp1D0, 0x1CU); - M2C_FIELD(sp1B4, s32*, 0) = M2C_FIELD(lbl_803B9670, s32*, 0x34); - M2C_FIELD(sp1B4, s32*, 4) = M2C_FIELD(lbl_803B9670, s32*, 0x38); - M2C_FIELD(sp1B4, s32*, 8) = M2C_FIELD(lbl_803B9670, s32*, 0x3C); - M2C_FIELD(sp1B4, s32*, 0xC) = M2C_FIELD(lbl_803B9670, s32*, 0x40); - M2C_FIELD(sp1B4, s32*, 0x10) = M2C_FIELD(lbl_803B9670, s32*, 0x44); - M2C_FIELD(sp1B4, s32*, 0x14) = M2C_FIELD(lbl_803B9670, s32*, 0x48); - M2C_FIELD(sp1B4, s32*, 0x18) = M2C_FIELD(lbl_803B9670, s32*, 0x4C); + hsd_803B3398(huff_dc_luma, 0x1CU); + *(JpegData28*) huff_dc_chroma = *(const JpegData28*) (data + 0x34); hsd_803B3344(0xFFU); hsd_803B3344(0xC4U); hsd_803B3344(0U); hsd_803B3344(0x1FU); hsd_803B3344(1U); - hsd_803B3398(sp1B4, 0x1CU); - work_r5 = sp100 - 8; - work_r4 = (u8*) (lbl_803B9670 + 0x48); + hsd_803B3398(huff_dc_chroma, 0x1CU); + work_r4 = data + 0x48; + work_r5 = huff_ac_luma - 8; for (work_ctr = 0x16; work_ctr != 0; work_ctr--) { work_r4 += 8; work_r5 += 8; - M2C_FIELD(work_r5, s32*, 0) = M2C_FIELD(work_r4, s32*, 0); - M2C_FIELD(work_r5, s32*, 4) = M2C_FIELD(work_r4, s32*, 4); + *(JpegData8*) work_r5 = *(const JpegData8*) work_r4; } - M2C_FIELD(work_r5, u16*, 8) = (u16) M2C_FIELD(work_r4, u16*, 8); + *(u16*) (work_r5 + 8) = *(const u16*) (work_r4 + 8); hsd_803B3344(0xFFU); hsd_803B3344(0xC4U); hsd_803B3344(0U); hsd_803B3344(0xB5U); hsd_803B3344(0x10U); - hsd_803B3398(sp100, 0xB2U); - work_r5_2 = sp4C - 8; - work_r4_2 = (u8*) (lbl_803B9670 + 0xFC); + hsd_803B3398(huff_ac_luma, 0xB2U); + work_r4_2 = data + 0xFC; + work_r5_2 = huff_ac_chroma - 8; for (work_ctr_2 = 0x16; work_ctr_2 != 0; work_ctr_2--) { work_r4_2 += 8; work_r5_2 += 8; - M2C_FIELD(work_r5_2, s32*, 0) = M2C_FIELD(work_r4_2, s32*, 0); - M2C_FIELD(work_r5_2, s32*, 4) = M2C_FIELD(work_r4_2, s32*, 4); + *(JpegData8*) work_r5_2 = *(const JpegData8*) work_r4_2; } - M2C_FIELD(work_r5_2, u16*, 8) = (u16) M2C_FIELD(work_r4_2, u16*, 8); + *(u16*) (work_r5_2 + 8) = *(const u16*) (work_r4_2 + 8); hsd_803B3344(0xFFU); hsd_803B3344(0xC4U); hsd_803B3344(0U); hsd_803B3344(0xB5U); hsd_803B3344(0x11U); - hsd_803B3398(sp4C, 0xB2U); - hsd_803B4D64(arg1, arg2); - if ((u8*) hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { - scratch_r3_5 = hsd_804D79A0; - hsd_804D79A0 = scratch_r3_5 + 1; - *scratch_r3_5 = 0xFF; + hsd_803B3398(huff_ac_chroma, 0xB2U); + hsd_803B4D64(width, height); + if (hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { + *hsd_804D79A0++ = 0xFF; } else { longjmp((__jmp_buf*) base, 1); } - if ((u8*) hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { - scratch_r3_6 = hsd_804D79A0; - hsd_804D79A0 = scratch_r3_6 + 1; - *scratch_r3_6 = 0xDA; + if (hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { + *hsd_804D79A0++ = 0xDA; } else { longjmp((__jmp_buf*) base, 1); } - if ((u8*) hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { - scratch_r3_7 = hsd_804D79A0; - hsd_804D79A0 = scratch_r3_7 + 1; - *scratch_r3_7 = 0; + if (hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { + *hsd_804D79A0++ = 0; } else { longjmp((__jmp_buf*) base, 1); } - if ((u8*) hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { - scratch_r3_8 = hsd_804D79A0; - hsd_804D79A0 = scratch_r3_8 + 1; - *scratch_r3_8 = 0xC; + if (hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { + *hsd_804D79A0++ = 0xC; } else { longjmp((__jmp_buf*) base, 1); } - if ((u8*) hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { - scratch_r3_9 = hsd_804D79A0; - hsd_804D79A0 = scratch_r3_9 + 1; - *scratch_r3_9 = 3; + if (hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { + *hsd_804D79A0++ = 3; } else { longjmp((__jmp_buf*) base, 1); } - if ((u8*) hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { - scratch_r3_10 = hsd_804D79A0; - hsd_804D79A0 = scratch_r3_10 + 1; - *scratch_r3_10 = 0; + if (hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { + *hsd_804D79A0++ = 0; } else { longjmp((__jmp_buf*) base, 1); } - if ((u8*) hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { - scratch_r3_11 = hsd_804D79A0; - hsd_804D79A0 = scratch_r3_11 + 1; - *scratch_r3_11 = 0; + if (hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { + *hsd_804D79A0++ = 0; } else { longjmp((__jmp_buf*) base, 1); } - if ((u8*) hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { - scratch_r3_12 = hsd_804D79A0; - hsd_804D79A0 = scratch_r3_12 + 1; - *scratch_r3_12 = 1; + if (hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { + *hsd_804D79A0++ = 1; } else { longjmp((__jmp_buf*) base, 1); } - if ((u8*) hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { - scratch_r3_13 = hsd_804D79A0; - hsd_804D79A0 = scratch_r3_13 + 1; - *scratch_r3_13 = 0x11; + if (hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { + *hsd_804D79A0++ = 0x11; } else { longjmp((__jmp_buf*) base, 1); } - if ((u8*) hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { - scratch_r3_14 = hsd_804D79A0; - hsd_804D79A0 = scratch_r3_14 + 1; - *scratch_r3_14 = 2; + if (hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { + *hsd_804D79A0++ = 2; } else { longjmp((__jmp_buf*) base, 1); } - if ((u8*) hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { - scratch_r3_15 = hsd_804D79A0; - hsd_804D79A0 = scratch_r3_15 + 1; - *scratch_r3_15 = 0x11; + if (hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { + *hsd_804D79A0++ = 0x11; } else { longjmp((__jmp_buf*) base, 1); } - if ((u8*) hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { - scratch_r3_16 = hsd_804D79A0; - hsd_804D79A0 = scratch_r3_16 + 1; - *scratch_r3_16 = 0; + if (hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { + *hsd_804D79A0++ = 0; } else { longjmp((__jmp_buf*) base, 1); } - if ((u8*) hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { - scratch_r3_17 = hsd_804D79A0; - hsd_804D79A0 = scratch_r3_17 + 1; - *scratch_r3_17 = 0x3F; + if (hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { + *hsd_804D79A0++ = 0x3F; } else { longjmp((__jmp_buf*) base, 1); } - if ((u8*) hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { - scratch_r3_18 = hsd_804D79A0; - hsd_804D79A0 = scratch_r3_18 + 1; - *scratch_r3_18 = 0; + if (hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { + *hsd_804D79A0++ = 0; } else { - longjmp(&hsd_804D2648, 1); + longjmp((__jmp_buf*) base, 1); } - for (work_r24 = 0; work_r24 < arg2; work_r24 += 0x10) { - for (work_r25 = 0; work_r25 < arg1; work_r25 += 0x10) { - hsd_803B3408((u8*) arg0, work_r25, work_r24, arg1, arg2); + for (work_r24 = 0; work_r24 < height; work_r24 += 0x10) { + for (work_r25 = 0; work_r25 < width; work_r25 += 0x10) { + hsd_803B3408(src, work_r25, work_r24, width, height); work_r26 = 0; work_r23 = base + 0x118; loop_61: @@ -1683,7 +1628,11 @@ s32 hsd_803B51C8(s32 arg0, s32 arg1, s32 arg2, char* arg3, s32 arg4) work_r5_4 = work_r26_2; work_r4_4 = base + 0x518; for (work_r3_2 = 0; work_r3_2 < 0x40; work_r3_2 += 8) { - scratch_r6_2 = quant_table + 0x40 + work_r3_2; + u8* scratch_r6_2; + { + u8* tmp_p61648 = quant_table + 0x40; + scratch_r6_2 = tmp_p61648 + work_r3_2; + } scratch_r7_3 = M2C_FIELD(scratch_r6_2, u8*, 0); M2C_FIELD(work_r5_4, s32*, 0) = (s32) ((s32) M2C_FIELD(work_r4_4, s32*, 0) / @@ -1768,26 +1717,21 @@ s32 hsd_803B51C8(s32 arg0, s32 arg1, s32 arg2, char* arg3, s32 arg4) scratch_r6_5 = 8 - hsd_804D79AC; hsd_804D79B0 <<= scratch_r6_5; hsd_804D79B0 |= (1 << scratch_r6_5) - 1; - if ((u8*) hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { - scratch_r3_19 = hsd_804D79A0; - hsd_804D79A0 = scratch_r3_19 + 1; - *scratch_r3_19 = hsd_804D79B0; + if (hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { + *hsd_804D79A0++ = hsd_804D79B0; } else { longjmp((__jmp_buf*) base, 1); } - hsd_804D79AC = (hsd_804D79B0 = 0); + hsd_804D79B0 = 0; + hsd_804D79AC = 0; } - if ((u8*) hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { - scratch_r3_20 = hsd_804D79A0; - hsd_804D79A0 = scratch_r3_20 + 1; - *scratch_r3_20 = 0xFF; + if (hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { + *hsd_804D79A0++ = 0xFF; } else { longjmp((__jmp_buf*) base, 1); } - if ((u8*) hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { - scratch_r3_21 = hsd_804D79A0; - hsd_804D79A0 = scratch_r3_21 + 1; - *scratch_r3_21 = 0xD9; + if (hsd_804D79A0 < &hsd_804D79A4[hsd_804D79A8]) { + *hsd_804D79A0++ = 0xD9; } else { longjmp((__jmp_buf*) base, 1); } diff --git a/src/sysdolphin/baselib/hsd_3B34.h b/src/sysdolphin/baselib/hsd_3B34.h index b4464a4fd5..4386c3a211 100644 --- a/src/sysdolphin/baselib/hsd_3B34.h +++ b/src/sysdolphin/baselib/hsd_3B34.h @@ -8,7 +8,7 @@ /* 3B46D4 */ void hsd_803B46D4(void); /* 3B4A2C */ void hsd_803B4A2C(void); /* 3B4D64 */ void hsd_803B4D64(u32, u32); -/* 3B51C8 */ s32 hsd_803B51C8(s32, s32, s32, char*, s32); +/* 3B51C8 */ s32 hsd_803B51C8(u8*, s32, s32, u8*, s32); /* 3B5C2C */ void hsd_803B5C2C(s32); /* 3B5C4C */ s32 hsd_803B5C4C(s32); /* 3B5D70 */ s32 hsd_803B5D70(s32, s32); diff --git a/src/sysdolphin/baselib/hsd_3B5C.c b/src/sysdolphin/baselib/hsd_3B5C.c index 992619b520..bf3b51f82e 100644 --- a/src/sysdolphin/baselib/hsd_3B5C.c +++ b/src/sysdolphin/baselib/hsd_3B5C.c @@ -13,6 +13,11 @@ extern s32 hsd_804D79C0; extern s32 hsd_804D79C4; extern u8 hsd_804D79C8; +typedef struct HSD_JpegWork { + u8 data[0x818]; + s32 prev_dc[3]; +} HSD_JpegWork; + u8 lbl_80431090[0x5A8] = { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, @@ -263,6 +268,7 @@ s32 hsd_803B5D70(s32 arg0, s32 arg1) #pragma dont_inline on void hsd_803B5EA0(s32 arg0) { + u8* base; s32 scratch_r29; s32 scratch_r29_2; s32 scratch_r29_3; @@ -283,6 +289,7 @@ void hsd_803B5EA0(s32 arg0) s32 scratch_r27; s32* scratch_r5; + base = hsd_804D2E70; scratch_r27 = hsd_803B5D70(0, arg0); if (scratch_r27 > 0) { work_r3 = hsd_803B5C4C(scratch_r27); @@ -292,14 +299,14 @@ void hsd_803B5EA0(s32 arg0) } else { work_r3 = 0; } - scratch_r5 = (s32*) (hsd_804D2E70 + (arg0 * 4)); + scratch_r5 = (s32*) (base + (arg0 * 4)); scratch_r5[0x206] = (s32) (scratch_r5[0x206] + work_r3); work_r29 = 1; - HSD_COEFF(0) = (s32) scratch_r5[0x206]; + ((s32*) (base + 0x718))[0] = (s32) scratch_r5[0x206]; while (work_r29 < 0x40) { if ((scratch_r3_2 = hsd_803B5D70(1, arg0)) == 0) { while (work_r29 < 0x40) { - HSD_COEFF(lbl_80431638[work_r29]) = 0; + ((s32*) (base + 0x718))[lbl_80431638[work_r29]] = 0; work_r29 += 1; } return; @@ -312,20 +319,20 @@ void hsd_803B5EA0(s32 arg0) if (scratch_r0_4 != 0) { do { scratch_r29 = work_r29 + 1; - HSD_COEFF(lbl_80431638[work_r29]) = 0; + ((s32*) (base + 0x718))[lbl_80431638[work_r29]] = 0; scratch_r29_2 = scratch_r29 + 1; - HSD_COEFF(lbl_80431638[scratch_r29]) = 0; + ((s32*) (base + 0x718))[lbl_80431638[scratch_r29]] = 0; scratch_r29_3 = scratch_r29_2 + 1; scratch_r29_4 = scratch_r29_3 + 1; - HSD_COEFF(lbl_80431638[scratch_r29_2]) = 0; + ((s32*) (base + 0x718))[lbl_80431638[scratch_r29_2]] = 0; scratch_r29_5 = scratch_r29_4 + 1; - HSD_COEFF(lbl_80431638[scratch_r29_3]) = 0; + ((s32*) (base + 0x718))[lbl_80431638[scratch_r29_3]] = 0; scratch_r29_6 = scratch_r29_5 + 1; - HSD_COEFF(lbl_80431638[scratch_r29_4]) = 0; - HSD_COEFF(lbl_80431638[scratch_r29_5]) = 0; - work_r29 = scratch_r29_6 + 1 + 1; - HSD_COEFF(lbl_80431638[scratch_r29_6]) = 0; - HSD_COEFF(lbl_80431638[work_r29 - 1]) = 0; + ((s32*) (base + 0x718))[lbl_80431638[scratch_r29_4]] = 0; + ((s32*) (base + 0x718))[lbl_80431638[scratch_r29_5]] = 0; + work_r29 = scratch_r29_6 + 1; + ((s32*) (base + 0x718))[lbl_80431638[scratch_r29_6]] = 0; + ((s32*) (base + 0x718))[lbl_80431638[work_r29 - 1]] = 0; work_ctr_3 -= 1; } while (work_ctr_3 != 0); work_r3_3 &= 7; @@ -338,7 +345,7 @@ void hsd_803B5EA0(s32 arg0) do { scratch_r0_5 = lbl_80431638[work_r29]; work_r29 += 1; - HSD_COEFF(scratch_r0_5) = 0; + ((s32*) (base + 0x718))[scratch_r0_5] = 0; work_ctr_4 -= 1; } while (work_ctr_4 != 0); } @@ -350,7 +357,7 @@ void hsd_803B5EA0(s32 arg0) } scratch_r0_6 = lbl_80431638[work_r29]; work_r29 += 1; - HSD_COEFF(scratch_r0_6) = work_r3_4; + ((s32*) (base + 0x718))[scratch_r0_6] = work_r3_4; } } } @@ -364,26 +371,13 @@ static void fn_803B61B4(u8* arg0) f32 scratch_f11; f32 scratch_f11_2; f32 scratch_f12; - f32 scratch_f12_2; + f32 scratch_f24_2; f32 scratch_f12_3; f32 scratch_f13; f32 scratch_f13_2; f32 scratch_f13_3; f32 scratch_f13_4; f32 scratch_f13_5; - f32 scratch_f22; - f32 scratch_f22_2; - f32 scratch_f23; - f32 scratch_f23_2; - f32 scratch_f23_3; - f32 scratch_f24; - f32 scratch_f24_2; - f32 scratch_f24_3; - f32 scratch_f24_4; - f32 scratch_f25; - f32 scratch_f25_2; - f32 scratch_f25_3; - f32 scratch_f25_4; f32 scratch_f26; f32 scratch_f26_2; f32 scratch_f27; @@ -391,6 +385,19 @@ static void fn_803B61B4(u8* arg0) f32 scratch_f29; f32 scratch_f30; f32 scratch_f31; + f32 scratch_f25; + f32 scratch_f25_2; + f32 scratch_f25_3; + f32 scratch_f25_4; + f32 scratch_f24; + f32 scratch_f12_2; + f32 scratch_f24_3; + f32 scratch_f24_4; + f32 scratch_f23; + f32 scratch_f23_2; + f32 scratch_f23_3; + f32 scratch_f22; + f32 scratch_f22_2; f32 scratch_f9; f32 scratch_f9_2; f32 scratch_f9_3; @@ -417,6 +424,7 @@ static void fn_803B61B4(u8* arg0) s32* work_r4; s32* work_r4_2; + PAD_STACK(8); work_r4 = (s32*) arg0; for (work_ctr = 8; work_ctr != 0; work_ctr--) { scratch_r5 = work_r4[1]; @@ -551,7 +559,6 @@ static void fn_803B6820(u8* arg0, s32 arg1, s32 arg2, s32 arg3, s32 work_r12; s32 work_r21; s32 work_r22; - s32 work_r23; s32 work_r24; s32 work_r25; s32 work_r31; @@ -564,7 +571,7 @@ static void fn_803B6820(u8* arg0, s32 arg1, s32 arg2, s32 arg3, u8 work_r16; u8 work_r16_2; u8 work_r17; - u8* work_r27; + s32* work_r27; u8* work_r8; u8* work_r9; u8* scratch_r16; @@ -612,13 +619,13 @@ static void fn_803B6820(u8* arg0, s32 arg1, s32 arg2, s32 arg3, work_r9 += 0x100; } scratch_r6 = (s32) (arg3 + 0xF) / 16; - work_r23 = arg2 / 4; work_r22 = 0; work_r21 = 0; for (work_r6 = 0; work_r6 < 2; work_r6++) { work_r25 = work_r22; - work_r9_2 = (u16*) arg0 + - (((arg1 / 4) * 0x10) + ((scratch_r6 << 6) * work_r23)); + work_r9_2 = + (u16*) arg0 + (((arg1 / 4) * 0x10) + + ((scratch_r6 << 6) * ((arg2 / 4) + work_r6))); work_r24 = 0; for (work_r7 = 0; work_r7 < 2; work_r7++) { work_r12 = work_r21 * 8; @@ -626,7 +633,7 @@ static void fn_803B6820(u8* arg0, s32 arg1, s32 arg2, s32 arg3, work_r31 = (work_r24 + work_r12) * 4; for (work_r5 = 0; work_r5 < 4; work_r5++) { work_r8_2 = 0; - work_r27 = &base[work_r31] + 0x118; + work_r27 = (s32*) (&base[work_r31] + 0x118); for (work_ctr_2 = 4; work_ctr_2 != 0; work_ctr_2--) { scratch_r19 = *work_r27; scratch_r16 = @@ -672,7 +679,7 @@ static void fn_803B6820(u8* arg0, s32 arg1, s32 arg2, s32 arg3, ((work_r8_2 << 2) & 8))] = ((work_r16 << 8) & 0xF800) | ((work_r17 << 3) & 0x7E0) | (work_r16_2 >> 3U); - work_r27 += 0x100; + work_r27 += 0x40; work_r8_2 += 1; } work_r9_2 += 1; @@ -683,7 +690,6 @@ static void fn_803B6820(u8* arg0, s32 arg1, s32 arg2, s32 arg3, work_r25 += 2; work_r24 += 4; } - work_r23 += 1; work_r22 += 0x10; work_r21 += 4; } @@ -691,6 +697,11 @@ static void fn_803B6820(u8* arg0, s32 arg1, s32 arg2, s32 arg3, s32 hsd_803B6BE4(char* arg0, s32 arg1, void* arg2) { + HSD_JpegWork* base_s32; + u8* base; + u8* quant_table; + s32 work_r28; + s32 work_r29; s32 scratch_r6_4; s32 scratch_r7; s32 scratch_r7_3; @@ -719,7 +730,6 @@ s32 hsd_803B6BE4(char* arg0, s32 arg1, void* arg2) u8* scratch_r5_14; u8* scratch_r5_15; u8* scratch_r5_16; - u8* scratch_r5_17; u8* scratch_r5_2; u8* scratch_r5_3; u8* scratch_r5_4; @@ -728,12 +738,6 @@ s32 hsd_803B6BE4(char* arg0, s32 arg1, void* arg2) u8* scratch_r5_7; u8* scratch_r5_8; u8* scratch_r5_9; - u8* scratch_r6; - u8* scratch_r6_2; - u8* quant_table; - u8* base; - s32 work_r28; - s32 work_r29; u8* work_r24; u8* work_r24_2; u8* work_r4; @@ -745,18 +749,20 @@ s32 hsd_803B6BE4(char* arg0, s32 arg1, void* arg2) u8* work_r5_2; PAD_STACK(0x48); - quant_table = lbl_80431090; - base = hsd_804D2E70; + base_s32 = (HSD_JpegWork*) hsd_804D2E70; hsd_804D79C0 = arg1; + quant_table = lbl_80431090; hsd_804D79B8 = (u8*) arg0; hsd_804D79BC = (u8*) arg0; - M2C_FIELD(base, s32*, 0x820) = 0; - M2C_FIELD(base, s32*, 0x81C) = 0; - M2C_FIELD(base, s32*, 0x818) = 0; + base = base_s32->data; + base_s32->prev_dc[2] = 0; + base_s32->prev_dc[1] = 0; + base_s32->prev_dc[0] = 0; hsd_804D79C4 = 0; - if (__setjmp((__jmp_buf*) base) != 0) { + if (__setjmp((__jmp_buf*) base_s32) != 0) { return 0; } + scratch_r5 = &hsd_804D79BC[hsd_804D79C0]; loop_3: if (*(u16*) hsd_804D79B8 == 0xFFDB) { work_r4 = lbl_80431638; @@ -792,12 +798,13 @@ s32 hsd_803B6BE4(char* arg0, s32 arg1, void* arg2) } else { scratch_r0_2 = hsd_804D79B8 + 1; hsd_804D79B8 = scratch_r0_2; - if (scratch_r0_2 >= &hsd_804D79BC[hsd_804D79C0]) { + if (scratch_r0_2 >= scratch_r5) { longjmp((__jmp_buf*) base, 1); } else { goto loop_3; } } + scratch_r5 = &hsd_804D79BC[hsd_804D79C0]; loop_11: if (*(u16*) hsd_804D79B8 == 0xFFDB) { work_r4_2 = lbl_80431638; @@ -841,12 +848,13 @@ s32 hsd_803B6BE4(char* arg0, s32 arg1, void* arg2) } else { scratch_r0_4 = hsd_804D79B8 + 1; hsd_804D79B8 = scratch_r0_4; - if (scratch_r0_4 >= &hsd_804D79BC[hsd_804D79C0]) { + if (scratch_r0_4 >= scratch_r5) { longjmp((__jmp_buf*) base, 1); } else { goto loop_11; } } + scratch_r5 = &hsd_804D79BC[hsd_804D79C0]; loop_19: if (*(u16*) hsd_804D79B8 == 0xFFC0) { hsd_804D79B8 += 5; @@ -857,12 +865,13 @@ s32 hsd_803B6BE4(char* arg0, s32 arg1, void* arg2) } else { scratch_r0_5 = hsd_804D79B8 + 1; hsd_804D79B8 = scratch_r0_5; - if (scratch_r0_5 >= &hsd_804D79BC[hsd_804D79C0]) { + if (scratch_r0_5 >= scratch_r5) { longjmp((__jmp_buf*) base, 1); } else { goto loop_19; } } + scratch_r5 = &hsd_804D79BC[hsd_804D79C0]; loop_24: if (*(u16*) hsd_804D79B8 == 0xFFDA) { hsd_804D79B8 += 2; @@ -870,7 +879,7 @@ s32 hsd_803B6BE4(char* arg0, s32 arg1, void* arg2) } else { scratch_r0_6 = hsd_804D79B8 + 1; hsd_804D79B8 = scratch_r0_6; - if (scratch_r0_6 >= &hsd_804D79BC[hsd_804D79C0]) { + if (scratch_r0_6 >= scratch_r5) { longjmp((__jmp_buf*) base, 1); } else { goto loop_24; @@ -884,7 +893,7 @@ s32 hsd_803B6BE4(char* arg0, s32 arg1, void* arg2) work_r5 = work_r24; work_r4_3 = &base[0x718]; for (work_r3_3 = 0; work_r3_3 < 0x40; work_r3_3 += 8) { - scratch_r6 = quant_table + work_r3_3; + u8* scratch_r6 = quant_table + work_r3_3; scratch_r0_7 = M2C_FIELD(scratch_r6, u8*, 0); M2C_FIELD(work_r5, s32*, 0) = (s32) (M2C_FIELD(work_r4_3, s32*, 0) * scratch_r0_7); @@ -920,7 +929,7 @@ s32 hsd_803B6BE4(char* arg0, s32 arg1, void* arg2) work_r4_4 = work_r24_2; work_r5_2 = &base[0x518]; for (work_r3_4 = 0; work_r3_4 < 0x40; work_r3_4 += 8) { - scratch_r6_2 = quant_table + 0x40 + work_r3_4; + u8* scratch_r6_2 = quant_table + 0x40 + work_r3_4; scratch_r7_2 = M2C_FIELD(scratch_r6_2, u8*, 0); M2C_FIELD(work_r5_2, s32*, 0) = (s32) (M2C_FIELD(work_r4_4, s32*, 0) * scratch_r7_2); @@ -952,7 +961,7 @@ s32 hsd_803B6BE4(char* arg0, s32 arg1, void* arg2) hsd_803B5EA0(2); work_r4_5 = &base[0x618]; for (work_r3_5 = 0; work_r3_5 < 0x40; work_r3_5 += 8) { - scratch_r5_17 = quant_table + 0x40 + work_r3_5; + u8* scratch_r5_17 = quant_table + 0x40 + work_r3_5; scratch_r6_3 = M2C_FIELD(scratch_r5_17, u8*, 0); M2C_FIELD(work_r4_5, s32*, 0) = (s32) (M2C_FIELD(work_r24_2, s32*, 0) * scratch_r6_3); diff --git a/src/sysdolphin/baselib/jobj.h b/src/sysdolphin/baselib/jobj.h index 01fddb8a8d..1ae6bc5210 100644 --- a/src/sysdolphin/baselib/jobj.h +++ b/src/sysdolphin/baselib/jobj.h @@ -351,10 +351,11 @@ static inline void HSD_JObjSetRotationZWithMtxDirty(HSD_JObj* jobj, f32 z) } } -static inline void HSD_JObjGetRotation(HSD_JObj* jobj, Quaternion* quat) +static inline void HSD_JObjGetRotation(HSD_JObj* jobj, Quaternion* rotate) { HSD_ASSERT(699, jobj); - *quat = jobj->rotate; + HSD_ASSERT(700, rotate); + *rotate = jobj->rotate; } static inline f32 HSD_JObjGetRotationX(HSD_JObj* jobj) diff --git a/src/sysdolphin/baselib/leak.c b/src/sysdolphin/baselib/leak.c index 09d2e41b20..c5aeedb198 100644 --- a/src/sysdolphin/baselib/leak.c +++ b/src/sysdolphin/baselib/leak.c @@ -36,6 +36,20 @@ static void order_data(void) /* @todo Currently ~98.4% match - register allocation differences * remain: r28/r29 swap (scan/cap_ptr) and loop/local register swaps * in the allocation table scan and report indentation loops. */ +static inline u32* HSD_LeakGetCapacityPtr(HSD_LeakChecker* lc) +{ + return &lc->capacity; +} + +static inline void HSD_LeakReportSpaces(u32 count) +{ + u32 i; + + for (i = 0; i < count; i++) { + OSReport(" "); + } +} + int HSD_Leak_80387DF8(int indent) { u32 val; @@ -60,22 +74,16 @@ int HSD_Leak_80387DF8(int indent) leak_count = 0; if (lc->table == NULL) { - for (i = 0; i < (u32) indent; i++) { - OSReport(" "); - } + HSD_LeakReportSpaces(indent); OSReport("Leak checker is not initialized.\n"); return 0; } - for (i = 0; i < (u32) indent; i++) { - OSReport(" "); - } + HSD_LeakReportSpaces(indent); OSReport("Begin memory leak check ...\n"); - for (j = 0; j < (u32) (indent + 2); j++) { - OSReport(" "); - } - cap_ptr = &lc->capacity; + HSD_LeakReportSpaces(indent + 2); + cap_ptr = HSD_LeakGetCapacityPtr(lc); OSReport("number of registered ptr: %d / %d (peak %d)\n", lc->used, *cap_ptr, lc->peak); @@ -87,10 +95,10 @@ int HSD_Leak_80387DF8(int indent) if ((word & 3) == 0) { u32 top = word >> 28; if (top == 8 || top == 0xC) { - u32 phys_addr = word & 0x0FFFFFFF; - if (phys_addr >= heap_start_align && val > phys_addr) { - u32 virt = phys_addr | 0x80000000; - u32* hdr = (u32*) (virt - 0x20); + if ((word & 0x0FFFFFFF) >= heap_start_align && + val > (word & 0x0FFFFFFF)) + { + u32* hdr = (u32*) ((word | 0x80000000) - 0x20); if (*hdr == HEAP_MAGIC) { u32 reg_idx = hdr[1]; if ((u32) (reg_idx + 0x10000) != 0xFFFF && @@ -112,16 +120,16 @@ int HSD_Leak_80387DF8(int indent) /* Check allocation table for leaks */ i = indent; i += 2; - val = (u32) lc->table; - scan = (u32*) (val + (*cap_ptr << 2)); + scan = lc->table; ofs = 0; - for (heap_start_align = 0; heap_start_align < *cap_ptr; heap_start_align++) - { - u32* ep = (u32*) ((u32) lc->table + ofs); + val = (u32) (scan + *cap_ptr); + heap_start_align = 0; + for (; ofs < *cap_ptr; ofs++) { + u32* ep = (u32*) ((u32) lc->table + heap_start_align); heap_start_phys = (u32*) *ep; if ((u32) heap_start_phys & 1) { *ep = (u32) heap_start_phys & ~1u; - } else if ((u32*) val <= heap_start_phys && heap_start_phys < scan) { + } else if (scan <= heap_start_phys && heap_start_phys < (u32*) val) { } else if (heap_start_phys != NULL) { u32* block = (u32*) heap_start_phys; if (block[0] == HEAP_MAGIC) { @@ -150,7 +158,7 @@ int HSD_Leak_80387DF8(int indent) next_leak: leak_count++; } - ofs += 4; + heap_start_align += 4; } if (leak_count > 0) { diff --git a/src/sysdolphin/baselib/particle.c b/src/sysdolphin/baselib/particle.c index 2908e1d534..656a57df7b 100644 --- a/src/sysdolphin/baselib/particle.c +++ b/src/sysdolphin/baselib/particle.c @@ -3,7 +3,18 @@ typedef struct { /* 0x00 */ void* next; /* 0x04 */ s32 type; - /* 0x08 */ u8 content[0x80]; + /* 0x08 */ union { + u8 bytes[0x80]; + char text[0x80]; + struct { + s32 count; + u32 color; + } bars[16]; + struct { + f32 pos; + u32 color; + } gradient[16]; + } content; } PerfDispItem; static PerfDispItem hsd_804CE3F8[6]; @@ -47,7 +58,7 @@ typedef struct _ExcptNode { typedef struct _EventData { /* 0x00 */ u8 _pad[0x10]; - /* 0x10 */ u32* entries; + /* 0x10 */ char** entries; /* 0x14 */ s32 index; } EventData; @@ -58,6 +69,17 @@ typedef struct _MCCPacket { /* 0x5 */ u8 x5; } MCCPacket; +typedef struct _ParticleFontData { + /* 0x0000 */ u8 _pad0[0x700]; + /* 0x0700 */ u8 x700[0x38]; + /* 0x0738 */ u8 _pad738[0x230]; + /* 0x0968 */ u8 x968[0x38]; + /* 0x09A0 */ u8 _pad9A0[0x38]; + /* 0x09D8 */ u8 x9D8[0x38]; + /* 0x0A10 */ u8 _padA10[0x1110]; + /* 0x1B20 */ u8 x1B20[0x38]; +} ParticleFontData; + typedef struct _DispData { /* 0x00 */ u8 _pad[0x10]; /* 0x10 */ s32 x10; @@ -75,15 +97,17 @@ typedef struct { /* 0x04 */ void (*callback)(void* dst, s32 x, s32 y, s32 val, void* self); } GlyphEntry; +typedef struct { + s32 count; + u32 color; +} DispBar; + typedef struct _DispItem { /* 0x00 */ struct _DispItem* next; /* 0x04 */ s32 type; /* 0x08 */ union { char text[128]; - struct { - s32 count; - u32 color; - } bars[1]; + DispBar bars[1]; u8 gradient[8]; } content; } DispItem; @@ -100,6 +124,58 @@ struct EventPriority { int priority; }; +typedef struct MCCErrorMessages { + char no_initialize[0x18]; + char no_response[0xC]; + char ping_error[0xC]; + char initialize_hio[0x1C]; + char read_hio_mailbox[0x1C]; + char write_hio_mailbox[0x1C]; + char read_hio_memory[0x1C]; + char write_hio_memory[0x1C]; + char read_hio_status[0x1C]; + char flush_channel_info[0x1C]; + char load_channel_info[0x1C]; + char not_enough_memory[0x18]; + char invalid_function_parameter[0x1C]; + char invalid_channel_parameter[0x1C]; + char invalid_data_size[0x14]; + char invalid_offset_parameter[0x1C]; + char already_opened[0x20]; + char already_closed[0x20]; + char already_locked[0x20]; + char already_unlocked[0x20]; + char read_write_busy[0x1C]; + char unknown_error[0x10]; +} MCCErrorMessages; + +static MCCErrorMessages mcc_error_messages = { + "MCC is no initialize", + "No responce", + "PING error", + "Could not initialize HIO", + "Could not read HIO mailbox", + "Could not write HIO mailbox", + "Could not read HIO memory", + "Could not write HIO memory", + "Could not read HIO status", + "Could not flush channelInfo", + "Could not load channelInfo", + "Not enough memory block", + "Invalid function parameter", + "Invalid channel parameter", + "Invalid data size", + "Invalid offset parameter", + "Channel was (already) opened", + "Channel was (already) closed", + "Channel was (already) locked", + "Channel was (already) unlocked", + "Channel (read/write) busy", + "Unknown error", +}; +static char mcc_error_caller_fmt[] = "%s: MCC Error, %s (%d)\n"; +static char mcc_error_fmt[] = "MCC Error, %s (%d)\n"; + static u16 numPeakParticles; void DrawRectangle(f32 x_min, f32 y_min, f32 w, f32 h, GXColor* color) @@ -213,8 +289,8 @@ f32 DrawASCII(int chr, float x, float y, GXColor* color) { s32 index; u8* glyph; - u8* ptr; s32 i; + u8* ptr; u8 p0, p1; u8 r, g, b, a; PAD_STACK(48); @@ -257,10 +333,13 @@ f32 DrawASCII(int chr, float x, float y, GXColor* color) cx = (f32) ((f64) lbl_804D6070 * 0.3 + (f64) x); GXWGFifo.f32 = cx; GXWGFifo.f32 = (f32) ((f64) lbl_804D6074 * 0.3 + (f64) y); + { + u8 alpha = color->a; + a = alpha; + } r = color->r; g = color->g; b = color->b; - a = color->a; GXWGFifo.u8 = r; GXWGFifo.u8 = g; GXWGFifo.u8 = b; @@ -311,8 +390,7 @@ f32 DrawASCII(int chr, float x, float y, GXColor* color) } draw_glyph: - glyph = &lbl_80408630[index * 13]; - ptr = glyph; + ptr = glyph = &lbl_80408630[index * 13]; i = 0; while (i < 0x29 && (u8) ptr[0] != 0xFF) { p0 = glyph[i++]; @@ -534,9 +612,9 @@ void hsd_80391F28(GXColor* color, f32 x1, f32 y1, f32 x2, f32 y2, f32 count) GXWGFifo.f32 = x1; i = 0; + a = color->a; GXWGFifo.f32 = y1; - a = color->a; b = color->b; g = color->g; r = color->r; @@ -620,7 +698,6 @@ void hsd_803921B8(void* bitmap, s32 x, s32 y, s32 dst, s32 w, s32 h, s32 off_y; GlyphEntry* table; s32 bit_off; - s32 col; s32 x2; s32 data_off; u32 word; @@ -651,6 +728,7 @@ void hsd_803921B8(void* bitmap, s32 x, s32 y, s32 dst, s32 w, s32 h, x2 = x * 2; data_off = off_y * 4; while (off_y < 14 && (u32) y < h) { + s32 col; col = x; bit_x = off_x; cur_dst = dst + (y * v_stride) + x2; @@ -681,31 +759,27 @@ void hsd_803922FC(void* bitmap, s32 x, s32 y, s32 parity, s32 dst, s32 w, s32 h, s32 stride, void* tbl) { volatile s32 v_stride; - volatile s32 v_h; - s32 col; - s32 bit_off; s32 bit_x; + s32 cur_dst; + u32 max_x; s32 off_x; + s32 off_y; GlyphEntry* table; - u32 max_x; + s32 bit_off; s32 x2; s32 data_off; s32 row_idx; u32 word; - s32 cur_dst; s32 shift; s32 val; u8* bmp; - s32 off_y; GlyphEntry* entry; - v_h = h; v_stride = stride; bmp = bitmap; - table = tbl; off_y = 0; off_x = 0; - if (table == NULL) { + if ((table = tbl) == NULL) { table = lbl_80408898; } if (y < 0) { @@ -727,7 +801,8 @@ void hsd_803922FC(void* bitmap, s32 x, s32 y, s32 parity, s32 dst, s32 w, row_idx = y / 2; x2 = x * 2; data_off = off_y * 4; - while (off_y < 14 && (u32) y < v_h) { + while (off_y < 14 && (u32) y < h) { + s32 col; col = x; bit_x = off_x; cur_dst = dst + (row_idx * v_stride) + x2; @@ -806,33 +881,39 @@ static const u32 lbl_804DE8E0 = 0xFFFFFFFF; // @TODO: Currently 89.78% match - needs minor control flow and register fixes void hsd_8039254C(void) { + s32 type; s32 char_count; + s32 total_ticks; + s32 count; + DispItem* bar_ptr; + DispItem* bar_draw_ptr; + f32 line; + f32 bar_y; + f32 bar_x; + f32 t2; GXColor default_col; - GXColor bar_col; - GXColor bg_col3; - GXColor bg_col2; + GXColor bg_col0; GXColor bg_col1; GXColor txt_col; - GXColor bg_col0; - GXColor* p_bar_col = &bar_col; - GXColor* p_bg_col3 = &bg_col3; - GXColor* p_bg_col0 = &bg_col0; - GXColor* p_bg_col1 = &bg_col1; - GXColor* p_txt_col = &txt_col; - GXColor* p_bg_col2 = &bg_col2; + GXColor bg_col2; + GXColor bg_col3; + GXColor bar_col; + GXColor* p_bg_col0; + GXColor* p_bg_col1; + GXColor* p_txt_col; + GXColor* p_bg_col2; + GXColor* p_bg_col3; + GXColor* p_bar_col; s32 col_pos; s32 first; - f32 line; HSD_SList* event_node; - s32 type; - s32 total_ticks; - DispItem* bar_ptr; - f32 bar_y; - f32 bar_x; - f32 t2; - u8 operand_pad[8]; - PAD_STACK(8); + p_bar_col = &bar_col; + p_bg_col3 = &bg_col3; + p_bg_col2 = &bg_col2; + p_bg_col1 = &bg_col1; + p_txt_col = &txt_col; + p_bg_col0 = &bg_col0; col_pos = 60; first = 1; line = 1.0F; @@ -843,7 +924,6 @@ void hsd_8039254C(void) DispItem* item; DispCallback cb; cb = (DispCallback) ((void**) event_node->data)[0]; - (void) cb; item = cb(event_node->data); while (item != NULL) { @@ -870,11 +950,14 @@ void hsd_8039254C(void) char_count++; } else { j++; - switch ((s8) item->content.text[j]) { - case 'c': - case 'C': - j += 6; - break; + { + char* tmp = item->content.text; + switch ((s8) tmp[j]) { + case 'c': + case 'C': + j += 6; + break; + } } } j++; @@ -894,7 +977,7 @@ void hsd_8039254C(void) txt_col = default_col; hsd_80391AC8(item->content.text, p_txt_col, (f32) (col_pos * 10), 10.0F * line); - col_pos = 2 + char_count + col_pos; + col_pos = col_pos + (2 + char_count); break; case 2: if (col_pos != 0) { @@ -914,10 +997,9 @@ void hsd_8039254C(void) bar_ptr = item; total_ticks = 0; { - s32 count; while ((count = bar_ptr->content.bars[0].count) > 0) { total_ticks += count; - bar_ptr = (DispItem*) ((u8*) bar_ptr + 8); + bar_ptr = (DispItem*) ((DispBar*) bar_ptr + 1); } } if (total_ticks > 0) { @@ -932,20 +1014,23 @@ void hsd_8039254C(void) hsd_80391A04(10.0F, 10.0F, 12); bar_y = (10.0F * line) + 2.0F; bar_x = 0.0F; - bar_ptr = item; { - s32 count; - while ((count = bar_ptr->content.bars[0].count) > 0) { + bar_draw_ptr = item; + while ((count = bar_draw_ptr->content.bars[0].count) > + 0) + { f32 prev_x; prev_x = bar_x; bar_col = - *(GXColor*) &bar_ptr->content.bars[0].color; + *(GXColor*) &bar_draw_ptr->content.bars[0] + .color; bar_x += (600.0F / (f32) total_ticks) * (f32) count; - hsd_80391F28(p_bar_col, prev_x, bar_y, bar_x, - bar_y, - (f32) bar_ptr->content.bars[0].count); - bar_ptr = (DispItem*) ((u8*) bar_ptr + 8); + hsd_80391F28( + p_bar_col, prev_x, bar_y, bar_x, bar_y, + (f32) bar_draw_ptr->content.bars[0].count); + bar_draw_ptr = + (DispItem*) ((DispBar*) bar_draw_ptr + 1); } } col_pos = 60; @@ -1021,6 +1106,11 @@ static s32 lbl_804D60A4 = (s32) 0xC0C000FF; // @TODO: Currently 89.63% match - needs register allocation and expression // fixes +static inline PerfDispItem* get_perf_disp_item(s32 count) +{ + return &hsd_804CE3F8[count]; +} + void* fn_80392A3C(void) { volatile s32 green; @@ -1028,62 +1118,63 @@ void* fn_80392A3C(void) s32 bar_count; s32 count; PerfDispItem* entry; + PerfDispItem* entry2; count = 0; numFrames = lbl_804D6088; if (0 != numFrames) { + u8* counts = &hsd_804CE3F8[0].content.bytes[0]; + u8* colors_base = &hsd_804CE3F8[0].content.bytes[4]; + u8* colors = colors_base; hsd_804CE3F8[0].type = 1; - ((s32*) &hsd_804CE3F8[0].content[0])[0] = 1; - bar_count = 1; + *(s32*) counts = 1; + bar_count = count; + bar_count++; green = lbl_804D6098; - ((s32*) &hsd_804CE3F8[0].content[4])[0] = green; + *(s32*) colors = green; if (numFrames > 1) { s32 val = numFrames - 1; if (val > 3) { val = 3; } - { - s32 idx = bar_count; - ((s32*) &hsd_804CE3F8[0].content[0])[idx * 2] = val; - ((s32*) &hsd_804CE3F8[0].content[4])[idx * 2] = lbl_804D60A4; - } + *(s32*) (counts + bar_count * 8) = val; + *(s32*) (colors + bar_count * 8) = lbl_804D60A4; bar_count = 2; } if (numFrames > 4) { - ((s32*) &hsd_804CE3F8[0].content[0])[bar_count * 2] = - numFrames - 4; - ((s32*) &hsd_804CE3F8[0].content[4])[bar_count * 2] = lbl_804D6094; + *(s32*) (counts + bar_count * 8) = numFrames - 4; + *(s32*) (colors + bar_count * 8) = lbl_804D6094; bar_count++; } - ((s32*) &hsd_804CE3F8[0].content[0])[bar_count * 2] = -1; + *(s32*) (counts + bar_count * 8) = -1; hsd_804CE3F8[0].next = &hsd_804CE3F8[1]; hsd_804CE3F8[1].type = 2; count = 4; - ((f32*) &hsd_804CE3F8[1].content[0])[0] = + hsd_804CE3F8[1].content.gradient[0].pos = hsd_804D7860 / (f32) numFrames; - ((s32*) &hsd_804CE3F8[1].content[0])[1] = lbl_804D609C; - ((f32*) &hsd_804CE3F8[1].content[0])[2] = + hsd_804CE3F8[1].content.gradient[0].color = lbl_804D609C; + hsd_804CE3F8[1].content.gradient[1].pos = (f32) (s32) (0.9999F + hsd_804D7860) / (f32) numFrames; - ((s32*) &hsd_804CE3F8[1].content[0])[3] = lbl_804D60A0; - ((f32*) &hsd_804CE3F8[1].content[0])[4] = -1.0F; + hsd_804CE3F8[1].content.gradient[1].color = lbl_804D60A0; + hsd_804CE3F8[1].content.gradient[2].pos = -1.0F; hsd_804CE3F8[1].next = &hsd_804CE3F8[2]; hsd_804CE3F8[2].type = 2; - ((f32*) &hsd_804CE3F8[2].content[0])[0] = + hsd_804CE3F8[2].content.gradient[0].pos = hsd_804D785C / (f32) numFrames; - ((s32*) &hsd_804CE3F8[2].content[0])[1] = lbl_804D6090; - ((f32*) &hsd_804CE3F8[2].content[0])[2] = -1.0F; + hsd_804CE3F8[2].content.gradient[0].color = lbl_804D6090; + hsd_804CE3F8[2].content.gradient[1].pos = -1.0F; hsd_804CE3F8[2].next = &hsd_804CE3F8[3]; hsd_804CE3F8[3].type = 2; - ((f32*) &hsd_804CE3F8[3].content[0])[0] = + hsd_804CE3F8[3].content.gradient[0].pos = hsd_804D7858 / (f32) numFrames; - ((s32*) &hsd_804CE3F8[3].content[0])[1] = green; - ((f32*) &hsd_804CE3F8[3].content[0])[2] = -1.0F; + hsd_804CE3F8[3].content.gradient[0].color = green; + hsd_804CE3F8[3].content.gradient[1].pos = -1.0F; hsd_804CE3F8[3].next = &hsd_804CE3F8[4]; } if (lbl_804D608C != 0) { hsd_804CE3F8[count].type = 0; - entry = &hsd_804CE3F8[count]; - sprintf((char*) &entry->content, + entry = get_perf_disp_item(count); + sprintf(entry->content.text, "\\c00ff00%2.3f \\cffffff%2.3f \\c00ffff%2.3f " "\\c00ff00%2.3f \\cffffff%2.3f \\c00ffff%2.3f", hsd_804D7858, hsd_804D785C, hsd_804D7860, hsd_804D7864, @@ -1092,11 +1183,11 @@ void* fn_80392A3C(void) count++; if (hsd_804D7888 != 0) { hsd_804CE3F8[count].type = 0; - entry = &hsd_804CE3F8[count]; - sprintf((char*) &entry->content, + entry2 = &hsd_804CE3F8[count]; + sprintf(entry2->content.text, "\\c00ff00%2.3f \\cffffff%2.3f \\c00ffff%2.3f", hsd_804D787C, hsd_804D7880, hsd_804D7884); - entry->next = &hsd_804CE3F8[count + 1]; + entry2->next = &hsd_804CE3F8[count + 1]; count++; } } @@ -1124,77 +1215,77 @@ u8 fn_80392CD8(char* caller) case 0: return err; case 1: - msg = "MCC is no initialize"; + msg = mcc_error_messages.no_initialize; break; case 2: - msg = "No responce"; + msg = mcc_error_messages.no_response; break; case 3: - msg = "PING error"; + msg = mcc_error_messages.ping_error; break; case 4: - msg = "Could not initialize HIO"; + msg = mcc_error_messages.initialize_hio; break; case 5: - msg = "Could not read HIO mailbox"; + msg = mcc_error_messages.read_hio_mailbox; break; case 6: - msg = "Could not write HIO mailbox"; + msg = mcc_error_messages.write_hio_mailbox; break; case 7: - msg = "Could not read HIO memory"; + msg = mcc_error_messages.read_hio_memory; break; case 8: - msg = "Could not write HIO memory"; + msg = mcc_error_messages.write_hio_memory; break; case 9: - msg = "Could not read HIO status"; + msg = mcc_error_messages.read_hio_status; break; case 10: - msg = "Could not flush channelInfo"; + msg = mcc_error_messages.flush_channel_info; break; case 11: - msg = "Could not load channelInfo"; + msg = mcc_error_messages.load_channel_info; break; case 12: - msg = "Not enough memory block"; + msg = mcc_error_messages.not_enough_memory; break; case 13: - msg = "Invalid function parameter"; + msg = mcc_error_messages.invalid_function_parameter; break; case 14: - msg = "Invalid channel parameter"; + msg = mcc_error_messages.invalid_channel_parameter; break; case 15: - msg = "Invalid data size"; + msg = mcc_error_messages.invalid_data_size; break; case 16: - msg = "Invalid offset parameter"; + msg = mcc_error_messages.invalid_offset_parameter; break; case 17: - msg = "Channel was (already) opened"; + msg = mcc_error_messages.already_opened; break; case 18: - msg = "Channel was (already) closed"; + msg = mcc_error_messages.already_closed; break; case 19: - msg = "Channel was (already) locked"; + msg = mcc_error_messages.already_locked; break; case 20: - msg = "Channel was (already) unlocked"; + msg = mcc_error_messages.already_unlocked; break; case 21: - msg = "Channel (read/write) busy"; + msg = mcc_error_messages.read_write_busy; break; default: - msg = "Unknown error"; + msg = mcc_error_messages.unknown_error; break; } if (caller != NULL) { - OSReport("%s: MCC Error, %s (%d)\n", caller, msg, err); + OSReport(mcc_error_caller_fmt, caller, msg, err); } else { - OSReport("MCC Error, %s (%d)\n", msg, err); + OSReport(mcc_error_fmt, msg, err); } return err; } @@ -1222,7 +1313,7 @@ extern int hsd_804D78A0; // @TODO: Currently 92.84% match - needs minor register allocation fix void hsd_80392E80(void) { - s32 status; + enum MCC_CONNECT status; s32 event; s32 head; u32 ticksPerUnit; @@ -1230,7 +1321,7 @@ void hsd_80392E80(void) s32 waiting; s32 intr; s32* channel_flags; - PAD_STACK(16); + PAD_STACK(12); ticksPerUnit = *(u32*) 0x800000F8 >> 2; @@ -1244,7 +1335,7 @@ void hsd_80392E80(void) head = hsd_804D789C + 1; event = hsd_804CE728[hsd_804D789C]; hsd_804D7898 -= 1; - hsd_804D789C = head - (head / 256) * 256; + hsd_804D789C = head % 256; OSRestoreInterrupts(intr); switch (event) { @@ -1276,8 +1367,7 @@ void hsd_80392E80(void) waiting = 1; startTick = OSGetTick(); for (;;) { - if (MCCGetConnectionStatus( - 0xF, (enum MCC_CONNECT*) &status) != 0 && + if (MCCGetConnectionStatus(0xF, &status) != 0 && status == 3) { waiting = 0; @@ -1562,13 +1652,9 @@ void hsd_80393440(void* request, void* response) void hsd_80393840(void) {} -// @TODO: Currently 99.29% match - stack frame/register allocation differences -// remain void hsd_80393844(void) { ParticleLogEntry* base = hsd_804CEB40; - u8* resp_status = (u8*) (base + 0x100) + 0x44; - u8* req_status = (u8*) (base + 0x100) + 0x84; s32 type; u32 flags; s32 value; @@ -1582,15 +1668,11 @@ void hsd_80393844(void) return; } - { - s32 idx = hsd_804D78B8; - ParticleLogEntry* entry = &base[idx]; - type = entry->x0; - flags = entry->x4; - value = entry->x8; - hsd_804D78BC -= 1; - hsd_804D78B8 = (idx + 1) % 256; - } + type = base[hsd_804D78B8].x0; + flags = base[hsd_804D78B8].x4; + value = base[hsd_804D78B8].x8; + hsd_804D78BC -= 1; + hsd_804D78B8 = (hsd_804D78B8 + 1) % 256; OSRestoreInterrupts(irq); @@ -1612,7 +1694,7 @@ void hsd_80393844(void) hsd_804D78A8 = value & 0x7F; if (MCCRead(0xF, hsd_804D78A8 << 5, (u8*) &base[0x10A].x8, 0x20, 0) != 0 && - !((*req_status >> 7) & 1)) + !((MCCPacket*) &base[0x10A].x8)->x4_b7) { u8 cmd; memset((u8*) &base[0x105].x4, 0, 0x20); @@ -1649,19 +1731,24 @@ void hsd_80393A54(int level) // @TODO: Currently 95.53% match - lis hoisting, extra li r0, BSS relocation // encoding +static inline f32 kbps_scale(void) +{ + return 1.0F / 1024.0F; +} + int hsd_80393A5C(char* filename, int data, int size) { + u32* data_p; int ready; - s32 start; + u32 start; int fd; f32 written_f; f32 elapsed; - PAD_STACK(8); if (hsd_804D78A0 == 0) { ready = 0; } else if (FIOQuery() == 0) { - ready = hsd_804D78A0 = 0; + hsd_804D78A0 = ready = 0; } else { ready = 1; } @@ -1682,7 +1769,8 @@ int hsd_80393A5C(char* filename, int data, int size) return -1; } - written_f = (f32) (u32) FIOFwrite(fd, (void*) data, size); + data_p = (u32*) data; + written_f = (f32) (u32) FIOFwrite(fd, data_p, size); if ((f32) (s32) size != written_f) { OSReport("cannot save file\n"); @@ -1692,8 +1780,11 @@ int hsd_80393A5C(char* filename, int data, int size) FIOFclose(fd); elapsed = (f32) (OSGetTick() - start) / (f32) (*(u32*) 0x800000F8 >> 2); - OSReport("Done %s size:%d time:%f spped:%fkbps\n", filename, size, elapsed, - 8.0F * (f32) (u32) size / elapsed * (1.0F / 1024.0F)); + { + f32 bits = 8.0F * (f32) size; + OSReport("Done %s size:%d time:%f spped:%fkbps\n", filename, size, + elapsed, bits / elapsed * kbps_scale()); + } return size; } @@ -1878,8 +1969,8 @@ void hsd_80393EF4(int col_delta, int row_delta) *col_ptr = byte_val; } } else { - int* col_ptr = &sp->x14; - u32 col = *col_ptr; + int* col_ptr; + u32 col = *(col_ptr = &sp->x14); col_delta = -col_delta; if (col > (u32) col_delta) { *col_ptr = col - (u32) col_delta; @@ -2026,38 +2117,47 @@ s32 hsd_803941E8(void* xfb_out_ptr, void* xfb_cur_ptr) extern u8 lbl_804088B8[]; -// @TODO: Currently 99.61% match - .bss.0 relocation symbol instead of -/// hsd_804CF810 void hsd_80394314(void) { - memset(&hsd_804CF810, 0, 0xD8); - hsd_803941E8(&hsd_804CF810.x24, &hsd_804CF810.x2C); + void* sp = &hsd_804CF810; + + memset(sp, 0, 0xD8); + hsd_803941E8(&((struct ParticleScreenState*) sp)->x24, + &((struct ParticleScreenState*) sp)->x2C); { s32 mode; - if (hsd_804CF810.x28 != 0) { + if (((struct ParticleScreenState*) sp)->x28 != 0) { mode = 2; } else { mode = 1; } - hsd_804CF810.x38 = mode; - } - - hsd_804CF810.x34 = 0; - hsd_804CF810.x30 = &HSD_VIData; - hsd_804CF810.x3C = ((u16*) hsd_804CF810.x30)[2]; - hsd_804CF810.x40 = ((u16*) hsd_804CF810.x30)[4]; - hsd_804CF810.x44 = (((u16) hsd_804CF810.x3C + 15) * 2) & 0x1FFE0; - hsd_804CF810.x48 = hsd_804CF810.x44 * hsd_804CF810.x40; - hsd_804CF810.x4 = 0; - hsd_804CF810.x8 = hsd_804CF810.x40; - hsd_804CF810.x18 = 0; - hsd_804CF810.x14 = 0; - hsd_804CF810.x20 = (u32) (hsd_804CF810.x3C - 0x28) / 11; - hsd_804CF810.x1C = (u32) (hsd_804CF810.x40 - 0x50) / 14; - hsd_804CF810.x4C = lbl_804088B8; - hsd_804CF810.x50 = 0; - hsd_804CF810.xC4 = 0; + ((struct ParticleScreenState*) sp)->x38 = mode; + } + + ((struct ParticleScreenState*) sp)->x34 = 0; + ((struct ParticleScreenState*) sp)->x30 = &HSD_VIData; + ((struct ParticleScreenState*) sp)->x3C = + ((u16*) ((struct ParticleScreenState*) sp)->x30)[2]; + ((struct ParticleScreenState*) sp)->x40 = + ((u16*) ((struct ParticleScreenState*) sp)->x30)[4]; + ((struct ParticleScreenState*) sp)->x44 = + (((u16) ((struct ParticleScreenState*) sp)->x3C + 15) * 2) & 0x1FFE0; + ((struct ParticleScreenState*) sp)->x48 = + ((struct ParticleScreenState*) sp)->x44 * + ((struct ParticleScreenState*) sp)->x40; + ((struct ParticleScreenState*) sp)->x4 = 0; + ((struct ParticleScreenState*) sp)->x8 = + ((struct ParticleScreenState*) sp)->x40; + ((struct ParticleScreenState*) sp)->x18 = 0; + ((struct ParticleScreenState*) sp)->x14 = 0; + ((struct ParticleScreenState*) sp)->x20 = + (u32) (((struct ParticleScreenState*) sp)->x3C - 0x28) / 11; + ((struct ParticleScreenState*) sp)->x1C = + (u32) (((struct ParticleScreenState*) sp)->x40 - 0x50) / 14; + ((struct ParticleScreenState*) sp)->x4C = lbl_804088B8; + ((struct ParticleScreenState*) sp)->x50 = 0; + ((struct ParticleScreenState*) sp)->xC4 = 0; } // @TODO: Currently 94.99% match - obj file has extra addi for lis/addi @@ -2146,11 +2246,6 @@ extern u8 lbl_8040AB40[]; // @TODO: Currently 88.35% match - register allocation/loop counter // differences remain -static inline s32 hsd_80394668_get_interlace(struct ParticleScreenState* sp) -{ - return sp->x0_b6; -} - #pragma push #pragma global_optimizer off void hsd_80394668(void) @@ -2161,114 +2256,59 @@ void hsd_80394668(void) if ((u32) sp->x2C != 0) { /* Copy XFB data with brightness adjustment */ u8* src = (u8*) sp->x2C; - s32 offset = sp->x34; - u8* dst = (u8*) (&sp->x24)[offset]; - u32 half_count = ((u32) sp->x48 + 1) >> 1; + u32 size = sp->x48; + u32 count = (size + 1) >> 1; s32 pos = 0; + s32* dst_base = (s32*) sp + sp->x34; + u8* dst = 0; + dst += dst_base[9]; - if ((u32) sp->x48 > 0) { - u32 unrolled = half_count >> 3; - u32 remainder; - - if (unrolled != 0) { - do { - u8* s0 = src + pos; - u8* d0 = dst + pos; - pos += 2; - d0[0] = (u8) (((s0[0] - 0x10) & 0xFFFFFF) + 0x10); - d0[1] = s0[1]; - - s0 = src + pos; - d0 = dst + pos; - pos += 2; - d0[0] = (u8) (((s0[0] - 0x10) & 0xFFFFFF) + 0x10); - d0[1] = s0[1]; - - s0 = src + pos; - d0 = dst + pos; - pos += 2; - d0[0] = (u8) (((s0[0] - 0x10) & 0xFFFFFF) + 0x10); - d0[1] = s0[1]; - - s0 = src + pos; - d0 = dst + pos; - pos += 2; - d0[0] = (u8) (((s0[0] - 0x10) & 0xFFFFFF) + 0x10); - d0[1] = s0[1]; - - s0 = src + pos; - d0 = dst + pos; - pos += 2; - d0[0] = (u8) (((s0[0] - 0x10) & 0xFFFFFF) + 0x10); - d0[1] = s0[1]; - - s0 = src + pos; - d0 = dst + pos; - pos += 2; - d0[0] = (u8) (((s0[0] - 0x10) & 0xFFFFFF) + 0x10); - d0[1] = s0[1]; - - s0 = src + pos; - d0 = dst; - d0 += pos; - pos += 2; - d0[0] = (u8) (((s0[0] - 0x10) & 0xFFFFFF) + 0x10); - d0[1] = s0[1]; - - s0 = src + pos; - d0 = dst + pos; - pos += 2; - d0[0] = (u8) (((s0[0] - 0x10) & 0xFFFFFF) + 0x10); - d0[1] = s0[1]; - } while (--unrolled != 0); - remainder = half_count & 7; - if (remainder == 0) { - return; - } - } else { - remainder = half_count; - } - - do { + if (size > 0) { + while (count != 0) { u8* s1 = src + pos; - u8 luma = s1[0]; u8* d1 = dst + pos; pos += 2; - d1[0] = (u8) (((luma - 0x10) & 0xFFFFFF) + 0x10); + d1[0] = (u8) (((s1[0] - 0x10) & 0xFFFFFF) + 0x10); d1[1] = s1[1]; - } while (--remainder != 0); + count--; + } } } else { /* Draw console text to framebuffer */ - void** x50_ptr = &sp->x50; + void* saved_color; + s32 row; s32* x4_ptr = &sp->x4; + void** x50_ptr = &sp->x50; s32* x40_ptr = &sp->x40; s32* x8_ptr = &sp->x8; - void* saved_color = *x50_ptr; - s32 row; - s32 col; - s32 cur_x; + saved_color = *x50_ptr; *x50_ptr = lbl_8040AB40; row = 0; while (row <= sp->x1C) { - s32 y_off = (row + 1) * 14; + s32 y_off; + s32 cur_x; + s32 col; + y_off = (row + 1) * 14; col = 0; cur_x = 0x14; while (col < sp->x20) { *x4_ptr = cur_x; *x8_ptr = (*x40_ptr - 0x28) - y_off; - if (sp->x0_b7 != 0) { - s32 interlace = hsd_80394668_get_interlace(sp); - hsd_803922FC((void*) ((u8*) sp->x4C + 0x700), *x4_ptr, - *x8_ptr, interlace, (&sp->x24)[sp->x34], - sp->x3C, *x40_ptr, sp->x44, *x50_ptr); - } else { - hsd_803921B8((void*) ((u8*) sp->x4C + 0x700), *x4_ptr, - *x8_ptr, (&sp->x24)[sp->x34], sp->x3C, - *x40_ptr, sp->x44, *x50_ptr); + { + s32 interlace = sp->x0_b6; + if (sp->x0_b7 != 0) { + hsd_803922FC(((ParticleFontData*) sp->x4C)->x700, + *x4_ptr, *x8_ptr, interlace, + (&sp->x24)[sp->x34], sp->x3C, *x40_ptr, + sp->x44, *x50_ptr); + } else { + hsd_803921B8(((ParticleFontData*) sp->x4C)->x700, + *x4_ptr, *x8_ptr, (&sp->x24)[sp->x34], + sp->x3C, *x40_ptr, sp->x44, *x50_ptr); + } } cur_x += 11; col++; @@ -2315,8 +2355,15 @@ void hsd_80394950(OSContext* ctx) i = 0; p = (u8*) ctx; do { - OSReport("R%02d=%08X:%08X (%e, %e)\n", i, *(u32*) (p + 0x90), - *(u32*) (p + 0x94), *(f32*) (p + 0x90), *(f32*) (p + 0x94)); + OSReport( + "R%02d=%08X:%08X (%e, %e)\n" + "\0\0\0- MISC ----------------------------------------------\n" + "\0\0SRR0=%08X SRR1=%08X\n" + "\0\0\0\0CR =%08X LR =%08X\n" + "\0\0\0\0CTR =%08X XER =%08X\n" + "\0\0\0\0GQR%d=%08X GQR%d=%08X\n", + i, ((u32*) p)[0x24], ((u32*) p)[0x25], ((f32*) p)[0x24], + ((f32*) p)[0x25]); i++; p += 8; } while (i < 32); @@ -2332,7 +2379,7 @@ void Exception_ReportStackTrace(OSContext* ctx, int max_depth) u32 i; u32* sp; - OSReport("- STACK ---------------------------------\n"); + OSReport("- STACK ---------------------------------------------\n"); OSReport(" Address: Back Chain LR Save\n"); sp = (u32*) ctx->gpr[1]; @@ -2464,24 +2511,22 @@ void Exception_ReportCodeline(u16 error, int dsisr, int dar, OSContext* ctx) } } -// @TODO: Currently 97.87% match - lwz r0 + mr r4 instead of lwz r4 void fn_80394DF4(void* node_ptr) { + struct ParticleScreenState* sp = &hsd_804CF810; ExcptNode* node = node_ptr; ExcptNode* prev; ExcptNode* head; + ExcptNode** head_ptr; - if (node == NULL) { - return; - } - head = (ExcptNode*) hsd_804CF810.xD0; - if (head == NULL) { + if (node == NULL || (head = *(head_ptr = (ExcptNode**) &sp->xD0)) == NULL) + { return; } if (head == node) { - hsd_804CF810.xD0 = head->next; + *head_ptr = head->next; node->next = NULL; - hsd_804CF810.x0_b5 = 1; + sp->x0_b5 = 1; return; } prev = head; @@ -2489,7 +2534,7 @@ void fn_80394DF4(void* node_ptr) if (prev->next == node) { prev->next = node->next; node->next = NULL; - hsd_804CF810.x0_b5 = 1; + sp->x0_b5 = 1; return; } prev = prev->next; @@ -2526,11 +2571,11 @@ void hsd_80394E8C(void* node_ptr) extern u8 lbl_8040AB00[]; extern u8 lbl_8040AB20[]; -// @TODO: Currently 93.04% match - BSS relocation and register allocation +// @TODO: Currently 94.46% match - BSS relocation and register allocation // differences remain void hsd_80394F48(void* data) { - void* base_color = lbl_8040AB00; + u8* base_color = lbl_8040AB00; struct ParticleScreenState* sp = &hsd_804CF810; EventData* dp = data; s32 num_entries; @@ -2551,7 +2596,7 @@ void hsd_80394F48(void* data) PAD_STACK(64); - num_entries = strlen((char*) dp->entries[0]); + num_entries = strlen(dp->entries[0]); px50 = &sp->x50; pxC8 = &sp->xC8; pxCC = &sp->xCC; @@ -2567,10 +2612,10 @@ void hsd_80394F48(void* data) b6 = sp->x0_b6; if (sp->x0_b7 != 0) { - hsd_803922FC((void*) ((u8*) sp->x4C + 0x968), *px4, *px8, b6, + hsd_803922FC(((ParticleFontData*) sp->x4C)->x968, *px4, *px8, b6, (&sp->x24)[sp->x34], sp->x3C, *px40, sp->x44, *px50); } else { - hsd_803921B8((void*) ((u8*) sp->x4C + 0x968), *px4, *px8, + hsd_803921B8(((ParticleFontData*) sp->x4C)->x968, *px4, *px8, (&sp->x24)[sp->x34], sp->x3C, *px40, sp->x44, *px50); } @@ -2579,10 +2624,10 @@ void hsd_80394F48(void* data) while (i < num_entries) { b6 = sp->x0_b6; if (sp->x0_b7 != 0) { - hsd_803922FC((void*) ((u8*) sp->x4C + 0x9D8), *px4, *px8, b6, + hsd_803922FC(((ParticleFontData*) sp->x4C)->x9D8, *px4, *px8, b6, (&sp->x24)[sp->x34], sp->x3C, *px40, sp->x44, *px50); } else { - hsd_803921B8((void*) ((u8*) sp->x4C + 0x9D8), *px4, *px8, + hsd_803921B8(((ParticleFontData*) sp->x4C)->x9D8, *px4, *px8, (&sp->x24)[sp->x34], sp->x3C, *px40, sp->x44, *px50); } i++; @@ -2591,54 +2636,54 @@ void hsd_80394F48(void* data) b6 = sp->x0_b6; if (sp->x0_b7 != 0) { - hsd_803922FC((void*) ((u8*) sp->x4C + 0x968), *px4, *px8, b6, + hsd_803922FC(((ParticleFontData*) sp->x4C)->x968, *px4, *px8, b6, (&sp->x24)[sp->x34], sp->x3C, *px40, sp->x44, *px50); } else { - hsd_803921B8((void*) ((u8*) sp->x4C + 0x968), *px4, *px8, + hsd_803921B8(((ParticleFontData*) sp->x4C)->x968, *px4, *px8, (&sp->x24)[sp->x34], sp->x3C, *px40, sp->x44, *px50); } *px4 += 11; - i = 0; + entry_idx = 0; x_base = col_start * 11 + 0x14; - hi_color = (u8*) base_color + 0x20; + hi_color = base_color + 0x20; cur_row = row_start - 1; - while (dp->entries[i] != 0) { + while (dp->entries[entry_idx] != 0) { *px4 = x_base; *px8 = (*px40 - 0x28) - (cur_row + 1) * 14; cur_row--; b6 = sp->x0_b6; if (sp->x0_b7 != 0) { - hsd_803922FC((void*) ((u8*) sp->x4C + 0x1B20), *px4, *px8, b6, + hsd_803922FC(((ParticleFontData*) sp->x4C)->x1B20, *px4, *px8, b6, (&sp->x24)[sp->x34], sp->x3C, *px40, sp->x44, *px50); } else { - hsd_803921B8((void*) ((u8*) sp->x4C + 0x1B20), *px4, *px8, + hsd_803921B8(((ParticleFontData*) sp->x4C)->x1B20, *px4, *px8, (&sp->x24)[sp->x34], sp->x3C, *px40, sp->x44, *px50); } - if (i == dp->index) { + if (entry_idx == dp->index) { *px50 = hi_color; } else { *px50 = base_color; } *px4 += 11; - hsd_80394434((void*) dp->entries[i]); + hsd_80394434(dp->entries[entry_idx]); - *px4 += strlen((char*) dp->entries[i]) * 11; + *px4 += strlen(dp->entries[entry_idx]) * 11; *px50 = base_color; b6 = sp->x0_b6; if (sp->x0_b7 != 0) { - hsd_803922FC((void*) ((u8*) sp->x4C + 0x1B20), *px4, *px8, b6, + hsd_803922FC(((ParticleFontData*) sp->x4C)->x1B20, *px4, *px8, b6, (&sp->x24)[sp->x34], sp->x3C, *px40, sp->x44, *px50); } else { - hsd_803921B8((void*) ((u8*) sp->x4C + 0x1B20), *px4, *px8, + hsd_803921B8(((ParticleFontData*) sp->x4C)->x1B20, *px4, *px8, (&sp->x24)[sp->x34], sp->x3C, *px40, sp->x44, *px50); } - i++; + entry_idx++; } *px50 = base_color; @@ -2647,45 +2692,42 @@ void hsd_80394F48(void* data) b6 = sp->x0_b6; if (sp->x0_b7 != 0) { - hsd_803922FC((void*) ((u8*) sp->x4C + 0x968), *px4, *px8, b6, + hsd_803922FC(((ParticleFontData*) sp->x4C)->x968, *px4, *px8, b6, (&sp->x24)[sp->x34], sp->x3C, *px40, sp->x44, *px50); } else { - hsd_803921B8((void*) ((u8*) sp->x4C + 0x968), *px4, *px8, + hsd_803921B8(((ParticleFontData*) sp->x4C)->x968, *px4, *px8, (&sp->x24)[sp->x34], sp->x3C, *px40, sp->x44, *px50); } { - struct ParticleScreenState* sp = &hsd_804CF810; - s32 b6; - { - s32 j = 0; - *px4 += 11; - while (j < num_entries) { - if (sp->x0_b7 != 0) { - hsd_803922FC((void*) ((u8*) sp->x4C + 0x9D8), *px4, *px8, - sp->x0_b6, (&sp->x24)[sp->x34], sp->x3C, - *px40, sp->x44, *px50); - } else { - hsd_803921B8((void*) ((u8*) sp->x4C + 0x9D8), *px4, *px8, - (&sp->x24)[sp->x34], sp->x3C, *px40, sp->x44, - *px50); - } - j++; - *px4 += 11; + s32 j = 0; + *px4 += 11; + while (j < num_entries) { + b6 = sp->x0_b6; + if (sp->x0_b7 != 0) { + hsd_803922FC(((ParticleFontData*) sp->x4C)->x9D8, *px4, *px8, + b6, (&sp->x24)[sp->x34], sp->x3C, *px40, sp->x44, + *px50); + } else { + hsd_803921B8(((ParticleFontData*) sp->x4C)->x9D8, *px4, *px8, + (&sp->x24)[sp->x34], sp->x3C, *px40, sp->x44, + *px50); } + j++; + *px4 += 11; } + } - b6 = sp->x0_b6; - if (sp->x0_b7 != 0) { - hsd_803922FC((void*) ((u8*) sp->x4C + 0x968), *px4, *px8, b6, - (&sp->x24)[sp->x34], sp->x3C, *px40, sp->x44, *px50); - } else { - hsd_803921B8((void*) ((u8*) sp->x4C + 0x968), *px4, *px8, - (&sp->x24)[sp->x34], sp->x3C, *px40, sp->x44, *px50); - } - - *px4 += 11; + b6 = hsd_804CF810.x0_b6; + if (sp->x0_b7 != 0) { + hsd_803922FC(((ParticleFontData*) sp->x4C)->x968, *px4, *px8, b6, + (&sp->x24)[sp->x34], sp->x3C, *px40, sp->x44, *px50); + } else { + hsd_803921B8(((ParticleFontData*) sp->x4C)->x968, *px4, *px8, + (&sp->x24)[sp->x34], sp->x3C, *px40, sp->x44, *px50); } + + *px4 += 11; *pxC8 += 4; *pxCC -= dp->index + 1; } @@ -2703,7 +2745,7 @@ s32 hsd_80395550(void* event_ptr) if (counter > 0) { data->index = counter - 1; } else { - u32* base = data->entries; + char** base = data->entries; s32 count = 0; while (base[count + 1] != 0) { count++; @@ -2714,7 +2756,7 @@ s32 hsd_80395550(void* event_ptr) } case 0x4: { s32 idx = data->index; - u32* base = data->entries; + char** base = data->entries; if (base[idx + 1] != 0) { data->index = idx + 1; } else { @@ -2799,20 +2841,17 @@ void hsd_803957C0(u8 input) { struct ParticleScreenState* sp = &hsd_804CF810; s32* x10_ptr = &sp->x10; - s32* x4_ptr; + void** x50_ptr; s32* x8_ptr; s32* x40_ptr; - void** x50_ptr; + s32* x4_ptr; s32 col; s32 row; s32 b6; u8 ch; void* saved; - s32 saved_ch; PAD_STACK(24); - ch = input; - saved_ch = input; col = sp->x0C + sp->x18; row = *x10_ptr + sp->x14; @@ -2856,7 +2895,7 @@ void hsd_803957C0(u8 input) } } - if ((u32) sp->xD0 == saved_ch) { + if ((u32) sp->xD0 == input) { struct ParticleScreenState* final_sp = &hsd_804CF810; *x4_ptr = (final_sp->x20 - 0x27) * 11 + 20; *x8_ptr = (*x40_ptr - 40) - (final_sp->x1C + 1) * 14; @@ -2921,122 +2960,117 @@ extern struct { /* 0x18 */ void* x18; } lbl_8040BC3C; -// @TODO: Currently 92.03% match - needs register allocation fix s32 hsd_80395A78(void) { - struct ParticleScreenState* sp = &hsd_804CF810; - s32* pxC = &sp->x0C; - s32* px18 = &sp->x18; - s32* px10 = &sp->x10; - s32* px14 = &sp->x14; u32 bit; - u32 new_col_u; + s32 new_col; s32 new_scroll; + s32 sum; PAD_STACK(8); bit = 1; - while (bit <= sp->xBC) { - switch (sp->xBC & bit) { + while (bit <= hsd_804CF810.xBC) { + switch (hsd_804CF810.xBC & bit) { case 0x8: - if (*px10 < sp->x1C - 1) { - *px10 = *px10 + 1; + if (hsd_804CF810.x10 < hsd_804CF810.x1C - 1) { + hsd_804CF810.x10 = hsd_804CF810.x10 + 1; } else { - *px14 = *px14 + 1; + hsd_804CF810.x14 += 1; } return 1; case 0x4: - if (*px10 > 0) { - *px10 = *px10 - 1; - return 1; - } - if (*px14 > 0) { - *px14 = *px14 - 1; - return 1; + if (hsd_804CF810.x10 > 0) { + hsd_804CF810.x10 -= 1; + } else if (hsd_804CF810.x14 > 0) { + hsd_804CF810.x14 -= 1; + } else { + break; } - goto next_bit; + return 1; case 0x1: - if (*pxC > 0) { - *pxC = *pxC - 1; - } else if (*px18 > 0) { - *px18 = *px18 - 1; + if (hsd_804CF810.x0C > 0) { + hsd_804CF810.x0C -= 1; + } else if (hsd_804CF810.x18 > 0) { + hsd_804CF810.x18 -= 1; } else { - goto next_bit; + break; } - while (!(u8) hsd_80394128(*pxC + *px18, *px10 + *px14)) { - if (*pxC > 0) { - *pxC = *pxC - 1; - } else if (*px18 > 0) { - *px18 = *px18 - 1; + while (!(u8) hsd_80394128(hsd_804CF810.x0C + hsd_804CF810.x18, + hsd_804CF810.x10 + hsd_804CF810.x14)) + { + if (hsd_804CF810.x0C > 0) { + hsd_804CF810.x0C -= 1; + } else if (hsd_804CF810.x18 > 0) { + hsd_804CF810.x18 -= 1; } else { break; } } return 1; case 0x2: - new_scroll = *px18; - new_col_u = *pxC; - if ((u32) *pxC < (u32) (sp->x20 - 1)) { - new_col_u += 1; + new_col = hsd_804CF810.x0C; + new_scroll = hsd_804CF810.x18; + if ((u32) new_col < (u32) (hsd_804CF810.x20 - 1)) { + new_col += 1; } else { new_scroll += 1; } - if ((u8) hsd_80394128(new_col_u + new_scroll, *px10 + *px14)) { - *pxC = new_col_u; - *px18 = new_scroll; + sum = new_col + new_scroll; + if ((u8) hsd_80394128(sum, hsd_804CF810.x10 + hsd_804CF810.x14)) { + hsd_804CF810.x0C = new_col; + hsd_804CF810.x18 = new_scroll; return 1; } - goto next_bit; - case 0x100: { - ExcptNode* node = (ExcptNode*) &lbl_8040BC3C; + break; + case 0x100: lbl_8040BC3C.x10 = hsd_80395970(); lbl_8040BC3C.x18 = &lbl_8040BAF0; - if (node != NULL) { - fn_80394DF4(node); - node->next = (ExcptNode*) sp->xD0; - sp->xD0 = node; - if (node->callback != NULL) { - node->callback(node); + if ((ExcptNode*) &lbl_8040BC3C != NULL) { + fn_80394DF4((ExcptNode*) &lbl_8040BC3C); + ((ExcptNode*) &lbl_8040BC3C)->next = + (ExcptNode*) hsd_804CF810.xD0; + hsd_804CF810.xD0 = &lbl_8040BC3C; + if (((ExcptNode*) &lbl_8040BC3C)->callback != NULL) { + ((ExcptNode*) &lbl_8040BC3C) + ->callback((ExcptNode*) &lbl_8040BC3C); } - sp->x0_b5 = 1; + hsd_804CF810.x0_b5 = 1; } return 1; - } - case 0x400: { - ExcptNode* node = (ExcptNode*) &lbl_8040BC3C; + case 0x400: lbl_8040BC3C.x18 = &lbl_8040BAF0; - if (node != NULL) { - fn_80394DF4(node); - node->next = (ExcptNode*) sp->xD0; - sp->xD0 = node; - if (node->callback != NULL) { - node->callback(node); + if ((ExcptNode*) &lbl_8040BC3C != NULL) { + fn_80394DF4((ExcptNode*) &lbl_8040BC3C); + ((ExcptNode*) &lbl_8040BC3C)->next = + (ExcptNode*) hsd_804CF810.xD0; + hsd_804CF810.xD0 = &lbl_8040BC3C; + if (((ExcptNode*) &lbl_8040BC3C)->callback != NULL) { + ((ExcptNode*) &lbl_8040BC3C) + ->callback((ExcptNode*) &lbl_8040BC3C); } - sp->x0_b5 = 1; + hsd_804CF810.x0_b5 = 1; } return 1; - } - case 0x1000: { - ExcptNode* node = (ExcptNode*) lbl_8040BA5C; - if (node != NULL) { - fn_80394DF4(node); - node->next = (ExcptNode*) sp->xD0; - sp->xD0 = node; - if (node->callback != NULL) { - node->callback(node); + case 0x1000: + if ((ExcptNode*) lbl_8040BA5C != NULL) { + fn_80394DF4((ExcptNode*) lbl_8040BA5C); + ((ExcptNode*) lbl_8040BA5C)->next = + (ExcptNode*) hsd_804CF810.xD0; + hsd_804CF810.xD0 = lbl_8040BA5C; + if (((ExcptNode*) lbl_8040BA5C)->callback != NULL) { + ((ExcptNode*) lbl_8040BA5C) + ->callback((ExcptNode*) lbl_8040BA5C); } - sp->x0_b5 = 1; + hsd_804CF810.x0_b5 = 1; } return 1; - } default: - next_bit: - bit <<= 1; break; } + bit <<= 1; } return 0; } - extern u8 lbl_8040BEC4[]; static inline void ps_remove_node(struct ParticleScreenState* sp, void* node) @@ -3063,6 +3097,21 @@ static inline void ps_remove_node(struct ParticleScreenState* sp, void* node) sp->x0_b5 = 1; } +static inline void ps_clear_nodes(struct ParticleScreenState* sp) +{ + void** head_ptr; + ExcptNode* cur; + + cur = *(head_ptr = &sp->xD0); + while (cur != NULL) { + ExcptNode* next = cur->next; + cur->next = NULL; + cur = next; + } + *head_ptr = NULL; + sp->x0_b5 = 1; +} + // @TODO: Currently 99.38% match - remaining register allocation differences s32 hsd_80395D88(void* data) { @@ -3102,18 +3151,16 @@ s32 hsd_80395D88(void* data) s32 i; OSContext* ctx; OSContext** ctx_ptr; - u32* ctx_words; s32 saved; if (*(ctx_ptr = &sp->xD4) != NULL) { saved = hsd_80393D2C(1); - ctx_words = (u32*) *ctx_ptr; + ctx = *ctx_ptr; OSReport(msg + 0x728); i = 0; do { - OSReport(msg + 0x760, i, ctx_words[i], ctx_words[i], - i + 0x10, ctx_words[i + 0x10], - ctx_words[i + 0x10]); + OSReport(msg + 0x760, i, ctx->gpr[i], ctx->gpr[i], + i + 0x10, ctx->gpr[i + 0x10], ctx->gpr[i + 0x10]); i++; } while (i < 0x10); hsd_80394950(*ctx_ptr); @@ -3140,29 +3187,19 @@ s32 hsd_80395D88(void* data) case 7: hsd_80394E8C(lbl_8040BEC4); return 1; - case 8: { - void** head_ptr; - ExcptNode* cur; - cur = *(head_ptr = &sp->xD0); - while (cur != NULL) { - ExcptNode* next = cur->next; - cur->next = NULL; - cur = next; - } - *head_ptr = NULL; - sp->x0_b5 = 1; + case 8: + ps_clear_nodes(sp); return 1; - } default: - return 0; + break; } + break; } case -1: ps_remove_node(sp, data); return 1; - default: - return 0; } + return 0; } void hsd_80396130(void) @@ -3185,39 +3222,46 @@ static inline s32 hsd_80396188_calc_col(void) return ((hsd_804CF810.x20 - 0x2E) / 2) * 11 + 20; } -// @TODO: Currently 95.69% match - needs register allocation fix -void hsd_80396188(void) +// @TODO: Currently 95.83% match - needs register allocation fix +static inline void hsd_80396188_draw_rows(char* buf, s32 col, u32** addr) { - void* saved; - s32 col; s32 i; - u32* addr; - char buf[64]; - PAD_STACK(20); - addr = (u32*) lbl_8040BAF0.x10; - saved = hsd_804CF810.x50; - col = hsd_80396188_calc_col(); - hsd_804CF810.x50 = lbl_8040AB00; - hsd_804CF810.x4 = col; - hsd_804CF810.x8 = hsd_804CF810.x40 - 0x7C; hsd_80394434(lbl_804D62CC); i = 0; do { s32 row = 4 - i; hsd_804CF810.x4 = col; hsd_804CF810.x8 = (hsd_804CF810.x40 - 0x28) - (row + 1) * 14; - sprintf(buf, lbl_804D62D0, addr, addr[0], addr[1], addr[2], addr[3]); + sprintf(buf, lbl_804D62D0, *addr, (*addr)[0], (*addr)[1], (*addr)[2], + (*addr)[3]); hsd_80394434(buf); { u32 memsize = OSGetPhysicalMemSize(); - addr = (u32*) ((((u32) addr & 0x0FFFFFFF) + memsize + 0x10) % - memsize + - 0x80000000); + *addr = (u32*) ((((u32) *addr & 0x0FFFFFFF) + memsize + 0x10) % + memsize + + 0x80000000); } i++; } while (i < 4); hsd_804CF810.x4 = col; +} + +void hsd_80396188(void) +{ + void* saved; + s32 col; + u32* addr; + char buf[64]; + PAD_STACK(20); + + addr = (u32*) lbl_8040BAF0.x10; + saved = hsd_804CF810.x50; + col = hsd_80396188_calc_col(); + hsd_804CF810.x50 = lbl_8040AB00; + hsd_804CF810.x4 = col; + hsd_804CF810.x8 = hsd_804CF810.x40 - 0x7C; + hsd_80396188_draw_rows(buf, col, &addr); hsd_804CF810.x8 = hsd_804CF810.x40 - 0x36; hsd_80394434(lbl_804D62D4); hsd_804CF810.x50 = saved; @@ -3730,21 +3774,21 @@ static char lbl_804D6348[] = " "; static char lbl_804D634C[] = " "; static char lbl_804D6350[8] = ""; -// @TODO: Currently 85.84% match - .bss.0 relocation causes register shift +// @TODO: .bss.0 relocation causes register shift void hsd_80397110(void) { struct ParticleScreenState* sp = &hsd_804CF810; extern u8 lbl_8040BEC4[]; u8* base = lbl_8040AB00; + void* saved; + s32 offset; void** px50 = &sp->x50; s32* px4 = &sp->x4; s32* px40 = &sp->x40; s32* px8 = &sp->x8; char buf[32]; - void* saved; - u32 i; s32 row; - s32 offset; + u32 i; u32* spr_entry; char* padding; PAD_STACK(32); @@ -3753,12 +3797,10 @@ void hsd_80397110(void) row = sp->x1C - 1; *px50 = base; *px4 = 20; - *px8 = (*px40 - 0x28) - (row + 1) * 14; - row--; + *px8 = (*px40 - 0x28) - (row-- + 1) * 14; hsd_80394434(SPR_BOX_TOP()); *px4 = 20; - *px8 = (*px40 - 0x28) - (row + 1) * 14; - row--; + *px8 = (*px40 - 0x28) - (row-- + 1) * 14; hsd_80394434(SPR_BOX_HEADER()); { u32* bec4 = (u32*) lbl_8040BEC4; @@ -3769,7 +3811,8 @@ void hsd_80397110(void) if (spr_off + i >= 0x45) { break; } - spr_entry = (u32*) (base + (spr_off * 16) + offset + 0x2D8); + spr_entry = (u32*) (base + spr_off * 16 + offset); + spr_entry += 0xB6; if (i == bec4[5]) { if (spr_entry[3] != 0) { ((void (*)(u32)) spr_entry[3])(spr_entry[0]); @@ -3779,8 +3822,7 @@ void hsd_80397110(void) *px50 = base; } *px4 = 20; - *px8 = (*px40 - 0x28) - (row + 1) * 14; - row--; + *px8 = (*px40 - 0x28) - (row-- + 1) * 14; if (spr_entry[0] == 0) { hsd_80394434(SPR_GEKKO_ONLY()); } else { @@ -3817,8 +3859,7 @@ void hsd_80397110(void) *px50 = base; while (row > 0) { *px4 = 20; - *px8 = (*px40 - 0x28) - (row + 1) * 14; - row--; + *px8 = (*px40 - 0x28) - (row-- + 1) * 14; hsd_80394434(SPR_BLANK_ROW()); } *px4 = 20; @@ -3910,15 +3951,16 @@ void hsd_80397520(void* node_ptr) } } -// @TODO: Currently 94.61% match - register allocation differences remain +// @TODO: Currently 99.62% match - register allocation differences remain void hsd_803975D4(void) { struct ParticleScreenState* sp = &hsd_804CF810; - u32 reset_mask; PADStatus* cur_pads; + u32 reset_mask; s32 port; u16 buttons; - u16 new_press; + u16 changed; + u32 new_press; reset_mask = 0; if (OSGetResetSwitchState() != 0) { @@ -3928,8 +3970,8 @@ void hsd_803975D4(void) for (;;) { } } - cur_pads = (PADStatus*) ((u8*) sp + 0x54); - memcpy((u8*) cur_pads + 0x30, cur_pads, 0x30); + cur_pads = (PADStatus*) sp->_pad4; + memcpy(&sp->_pad4[0x30], cur_pads, 0x30); PADRead(cur_pads); PADClamp(cur_pads); for (port = 0; port < 4; port++) { @@ -3940,40 +3982,13 @@ void hsd_803975D4(void) if (reset_mask != 0) { PADReset(reset_mask); } - port = 0; - if ((s8) sp->_pad4[0x3A] != 0) { - goto port1; - } - if ((s8) sp->_pad4[0xA] == 0) { - goto port_done; - } -port1: - port = 1; - if ((s8) sp->_pad4[0x46] != 0) { - goto port2; - } - if ((s8) sp->_pad4[0x16] == 0) { - goto port_done; - } -port2: - port = 2; - if ((s8) sp->_pad4[0x52] != 0) { - goto port3; - } - if ((s8) sp->_pad4[0x22] == 0) { - goto port_done; - } -port3: - port = 3; - if ((s8) sp->_pad4[0x5E] != 0) { - goto port4; - } - if ((s8) sp->_pad4[0x2E] == 0) { - goto port_done; + for (port = 0; port < 4; port++) { + if ((s8) sp->_pad4[0x3A + port * 0xC] == 0 && + (s8) sp->_pad4[0xA + port * 0xC] == 0) + { + break; + } } -port4: - port = 4; -port_done: if (port == 4) { sp->xBC = 0; sp->xC0 = 0; @@ -3982,11 +3997,11 @@ void hsd_803975D4(void) *(s32*) ((u8*) sp + 0xB4) = port; buttons = ((PADStatus*) ((u8*) sp + 0x54))[*(s32*) ((u8*) sp + 0xB4)].button; - new_press = + changed = ((PADStatus*) ((u8*) sp + 0x84))[*(s32*) ((u8*) sp + 0xB4)].button ^ buttons; sp->xC0 = buttons; - new_press = buttons & new_press; + new_press = (u16) (buttons & changed); if (new_press != 0) { *(s32*) ((u8*) sp + 0xB8) = 0; } else if (((PADStatus*) ((u8*) sp + 0x54))[*(s32*) ((u8*) sp + 0xB4)] @@ -4162,15 +4177,18 @@ void* fn_80397814(void* arg) VISetBlack(0); /* Clear display list */ - keybuf = (u32*) &sp->xD0; { - void* cur = sp->xD0; + ExcptNode** head = (ExcptNode**) &sp->xD0; + ExcptNode* next; + ExcptNode* cur; + keybuf = (u32*) head; + cur = *head; while (cur != NULL) { - void* next = *(void**) cur; - *(void**) cur = NULL; + next = cur->next; + cur->next = NULL; cur = next; } - *(void**) keybuf = NULL; + *head = NULL; } /* Link exception node */ @@ -4189,24 +4207,34 @@ void* fn_80397814(void* arg) /* Initial display setup */ { - s32* fb_ptr = (s32*) &sp->x40; - s32* fb2_ptr = (s32*) &sp->x44; - u32 retrace2; - u32 next_retrace2; - s32* col_ptr = &sp->x34; - s32* x14_ptr = &sp->x14; - s32* x18_ptr = &sp->x18; - s32* x20_ptr = &sp->x20; - s32* nrows_ptr = &sp->x1C; - s32* fb_array = &sp->x24; - s32* x3C_ptr = &sp->x3C; + s32* x3C_ptr; + s32* x20_ptr; + s32* x14_ptr; + s32* x18_ptr; s32* c8_ptr; s32* cc_ptr; + s32* fb_ptr; + s32* fb2_ptr; + u32 retrace2; + u32 next_retrace2; + s32* col_ptr; + s32* nrows_ptr; + s32* fb_array; s32* size_ptr; void* lbl_ptr; s32 fb_idx; PSNode* node; + fb_ptr = (s32*) &sp->x40; + fb2_ptr = (s32*) &sp->x44; + col_ptr = &sp->x34; + x18_ptr = &sp->x18; + x14_ptr = &sp->x14; + x20_ptr = &sp->x20; + nrows_ptr = &sp->x1C; + fb_array = &sp->x24; + x3C_ptr = &sp->x3C; + hsd_80394544(*x18_ptr, *x14_ptr, *x20_ptr, *nrows_ptr, 20, *fb_ptr - 40, fb_array[*col_ptr], *x3C_ptr, *fb_ptr, *fb2_ptr, (s32) lbl_804088B8, NULL); @@ -4261,7 +4289,8 @@ void* fn_80397814(void* arg) if (*(void* (**) (void*) )((u8*) disp_node + 0xC) != NULL) { result = (s32) (*(void* (**) (void*) )((u8*) disp_node + 0xC))(disp_node); - if (result != 0) { + if (result == 0) { + } else { goto walk_done; } } @@ -4641,11 +4670,12 @@ void psInitDataBankLoad(int bank, int* cmdBank, int* texBank, u32* ref, int* formBank) { s32* base = (s32*) hsd_804D08E8; + char* data = + "particle.c\0\0illigal form data (strange number of group)\n\0\0\0\0" + "psInitDataBanks: unknown version\n"; u16 version; - if (formBank != NULL && *formBank != *texBank) { - OSPanic("particle.c", 177, - "illigal form data (strange number of group)\n"); + OSPanic(data, 177, data + 0xC); } (base + bank)[0x60 / 4] = (s32) ref; @@ -4674,7 +4704,7 @@ void psInitDataBankLoad(int bank, int* cmdBank, int* texBank, u32* ref, break; } default: - OSPanic("particle.c", 207, "psInitDataBanks: unknown version\n"); + OSPanic(data, 207, data + 0x3C); } } @@ -5083,6 +5113,7 @@ void hsd_80398F8C(HSD_Particle* pp, f32 angle) f32 abs_z; f32 temp; f32 abs_temp; + f32 angle_copy; PAD_STACK(16); { @@ -5129,10 +5160,11 @@ void hsd_80398F8C(HSD_Particle* pp, f32 angle) rand_angle = (f32) (3.141592653589793 * HSD_Randf() * 2.0); - sin_angle = vx * sinf(angle); + angle_copy = angle; + sin_angle = vx * sinf(angle_copy); cos_rand = sin_angle * cosf(rand_angle); sin_rand = sin_angle * sinf(rand_angle); - cos_angle = vx * cosf(angle); + cos_angle = vx * cosf(angle_copy); pp->vel.x = cos_rand * cos_e + cos_angle * sin_e; pp->vel.y = cos_e * (cos_angle * sin_a) + @@ -5187,7 +5219,7 @@ void* hsd_8039930C(void* pp_arg, void* prev_arg) HSD_Generator* gchild; HSD_PSCmdList* cl; HSD_PSTexGroup* tg; - PAD_STACK(464); + PAD_STACK(456); #define fval (*(f32*) &hsd_804D78D0) #define fbytes (*(ParticleFloatBytes*) &hsd_804D78D0).bytes @@ -5991,8 +6023,11 @@ void* hsd_8039930C(void* pp_arg, void* prev_arg) } hsd_803983A4(srt->gp); srt = pp->appsrt; - HSD_MtxSRT(srt->mmtx, &srt->scale, (Vec3*) &srt->rot, - &srt->translate, NULL); + { + Quaternion* rot = &srt->rot; + HSD_MtxSRT(srt->mmtx, &srt->scale, (Vec3*) rot, + &srt->translate, NULL); + } pp->pos.x = pp->appsrt->mmtx[0][1] * pp->pos.y + pp->appsrt->mmtx[0][0] * pp->pos.x + pp->appsrt->mmtx[0][2] * pp->pos.z + @@ -7508,7 +7543,7 @@ void hsd_8039D0A0(HSD_Generator* gen) prev = NULL; idnum = gen->idnum; head = (HSD_Particle**) &hsd_804D0908[gen->linkNo]; - prt = (HSD_Particle*) *head; + prt = *head; while (prt != NULL) { next = prt->next; @@ -7887,7 +7922,6 @@ f32 hsd_8039DAD4(HSD_Generator* gen) { Mtx rot_mtx; Vec3 vel_out; - Vec3 vel_temp; Vec3 tmpvec; Vec3 emit_pos; Vec3 vel_copy; @@ -7910,16 +7944,15 @@ f32 hsd_8039DAD4(HSD_Generator* gen) f32 elevation; f32 tmp; f32 angle3; - u8 operand_pad[12]; PAD_STACK(16); - angle3 = 0.0F; - vel_mag_sq = angle3; - - if (gen->count < 0.0F) { + if (gen->count < 1.0F) { return gen->count; } + angle3 = 0.0F; + vel_mag_sq = angle3; + /* Copy velocity */ vel_copy.x = gen->vel.x; vel_copy.y = gen->vel.y; @@ -8080,38 +8113,46 @@ f32 hsd_8039DAD4(HSD_Generator* gen) *(s32*) &comb &= 0x7FFFFFFF; if (comb < 1.1754944e-38F) { if (rot_mtx[0][2] >= 0.0F) { - elevation = 1.5707964F; + angle3 = 1.5707964F; } else { - elevation = -1.5707964F; + angle3 = -1.5707964F; } } else { - elevation = atan2f(rot_mtx[0][2], - rot_mtx[2][2] * c1 + rot_mtx[1][2] * s1); + angle3 = atan2f(rot_mtx[0][2], + rot_mtx[2][2] * c1 + rot_mtx[1][2] * s1); } - angle3 = elevation; } } /* Angle step computation (pre-loop) */ if (gen->angle < 0.0F) { - u32 shape = gen->type & 0xF; - if (shape == 0 || shape == 3 || shape == 4) { + switch (gen->type & 0xF) { + case 0: + case 3: + case 4: { f32 min_a = gen->aux.disc.minAngle; f32 rnd = HSD_Randf(); f32 range = gen->aux.disc.maxAngle - min_a; angle_step = range / (f32) (s32) gen->count; cur_angle = angle_step * rnd + min_a; - } else if (shape == 6 || shape == 7) { + break; + } + case 6: + case 7: { f32 min_a = gen->aux.cone.minAngle; f32 rnd = HSD_Randf(); f32 range = gen->aux.cone.maxAngle - min_a; angle_step = range / (f32) (s32) gen->count; cur_angle = angle_step * rnd + min_a; - } else { + break; + } + default: { f32 rnd = HSD_Randf(); cur_angle = (f32) ((f64) 6.2831855F * (f64) rnd); angle_step = (f32) ((f64) 6.2831855F / (f64) (f32) (s32) gen->count); + break; + } } } @@ -8125,7 +8166,7 @@ f32 hsd_8039DAD4(HSD_Generator* gen) case 6: case 7: { /* Compute radius */ - if (gen->radius < 0.0) { + if (gen->radius < 0.0F) { sin_az = -gen->radius; radius = 0.0F; } else { @@ -8314,6 +8355,7 @@ f32 hsd_8039DAD4(HSD_Generator* gen) case 5: /* rect */ { + Vec3 vel_temp; f32 rx = HSD_Randf(); f32 ry = HSD_Randf(); f32 rz = HSD_Randf(); @@ -8547,11 +8589,12 @@ f32 hsd_8039DAD4(HSD_Generator* gen) f32 az_angle; f32 r2 = gen->radius; az_angle = (f32) ((f64) M_TAU * (f64) rnd); - cone_angle = (f32) ((f64) M_TAU * az_angle); + cone_angle = az_angle; if (r2 < 0.0F) { sin_az = -r2; } else { + rnd = HSD_Randf(); if (rnd > 0.0F) { f64 e = __frsqrte(rnd); e = 0.5 * e * -(rnd * (e * e) - 3.0); @@ -8568,9 +8611,9 @@ f32 hsd_8039DAD4(HSD_Generator* gen) cos_r = cosf(cone_angle); cos_az = sinf(radius); vel_out.x = cos_az * cos_r; - sin_el = cosf(cone_angle); + sin_el = sinf(cone_angle); sin_r = sinf(radius); - vel_out.y = cos_az * sin_r; + vel_out.y = sin_el * sin_r; vel_out.z = cosf(radius); } @@ -8693,12 +8736,11 @@ HSD_Generator* hsd_8039EFAC(s32 linkNo, s32 bank, s32 gfx_id, HSD_JObj* jobj) return gen; } -// @TODO: Currently 80.79% match - .bss.0 section anchor hoist causes +// @TODO: Currently 92.58% match - .bss.0 section anchor hoist causes // register-allocation cascade (extra saved reg + frame shift) HSD_Generator* hsd_8039F05C(s32 linkNo, s32 bank, s32 idx) { - HSD_PSCmdList** cmdListArr; - HSD_PSCmdList* cl; + HSD_PSCmdList*** cmdListArr; HSD_PSTexGroup* tg; HSD_Generator* gen; s32 ofs; @@ -8720,36 +8762,34 @@ HSD_Generator* hsd_8039F05C(s32 linkNo, s32 bank, s32 idx) return NULL; } - cmdListArr = psCmdListArray[bank]; + cmdListArr = (HSD_PSCmdList***) &ptclref_804D0E5C[bank]; ofs = idx * 4; - if ((u32) * ((s32*) cmdListArr + idx) == 0) { + if ((*cmdListArr)[idx] == NULL) { return NULL; } gen = hsd_8039D9C8(); if (gen != NULL) { - cl = ((HSD_PSCmdList**) cmdListArr)[idx]; - - gen->type = cl->type; + gen->type = (*cmdListArr)[idx]->type; gen->bank = bank; gen->linkNo = linkNo; - gen->kind = cl->kind; - gen->texGroup = cl->texGroup; - gen->life = cl->life; - gen->genLife = cl->genLife; + gen->kind = (*cmdListArr)[idx]->kind; + gen->texGroup = (*cmdListArr)[idx]->texGroup; + gen->life = (*cmdListArr)[idx]->life; + gen->genLife = (*cmdListArr)[idx]->genLife; gen->pos.x = 0.0F; gen->pos.y = 0.0F; gen->pos.z = 0.0F; - gen->vel.x = cl->vx; - gen->vel.y = cl->vy; - gen->vel.z = cl->vz; - gen->grav = cl->grav; - gen->fric = cl->fric; - gen->angle = cl->angle; - gen->cmdList = cl->cmdList; - gen->radius = cl->radius; - gen->size = cl->size; - gen->random = cl->random; + gen->vel.x = (*cmdListArr)[idx]->vx; + gen->vel.y = (*cmdListArr)[idx]->vy; + gen->vel.z = (*cmdListArr)[idx]->vz; + gen->grav = (*cmdListArr)[idx]->grav; + gen->fric = (*cmdListArr)[idx]->fric; + gen->size = (*cmdListArr)[idx]->size; + gen->cmdList = (*cmdListArr)[idx]->cmdList; + gen->radius = (*cmdListArr)[idx]->radius; + gen->angle = (*cmdListArr)[idx]->angle; + gen->random = (*cmdListArr)[idx]->random; if (gen->kind & 0x100) { f1 = gen->random; @@ -8782,46 +8822,44 @@ HSD_Generator* hsd_8039F05C(s32 linkNo, s32 bank, s32 idx) case 0: case 3: case 4: { - HSD_PSCmdList* c = ((HSD_PSCmdList**) cmdListArr)[idx]; + HSD_PSCmdList* c = (*cmdListArr)[idx]; f32 p1 = c->param1; if (p1 == 0.0F && c->param2 == 0.0F) { gen->aux.disc.minAngle = 0.0F; gen->aux.disc.maxAngle = 6.2831855F; } else { gen->aux.disc.minAngle = p1; - gen->aux.disc.maxAngle = - ((HSD_PSCmdList**) cmdListArr)[idx]->param2; + gen->aux.disc.maxAngle = (*cmdListArr)[idx]->param2; } break; } case 1: - gen->aux.line.x2 = ((HSD_PSCmdList**) cmdListArr)[idx]->param1; - gen->aux.line.y2 = ((HSD_PSCmdList**) cmdListArr)[idx]->param2; - gen->aux.line.z2 = ((HSD_PSCmdList**) cmdListArr)[idx]->param3; + gen->aux.line.x2 = (*cmdListArr)[idx]->param1; + gen->aux.line.y2 = (*cmdListArr)[idx]->param2; + gen->aux.line.z2 = (*cmdListArr)[idx]->param3; break; case 6: case 7: { - HSD_PSCmdList* c = ((HSD_PSCmdList**) cmdListArr)[idx]; + HSD_PSCmdList* c = (*cmdListArr)[idx]; f32 p1 = c->param1; if (p1 == 0.0F && c->param2 == 0.0F) { gen->aux.cone.minAngle = 0.0F; gen->aux.cone.maxAngle = 6.2831855F; } else { gen->aux.cone.minAngle = p1; - gen->aux.cone.maxAngle = - ((HSD_PSCmdList**) cmdListArr)[idx]->param2; + gen->aux.cone.maxAngle = (*cmdListArr)[idx]->param2; } - gen->aux.cone.height = ((HSD_PSCmdList**) cmdListArr)[idx]->param3; + gen->aux.cone.height = (*cmdListArr)[idx]->param3; break; } case 5: { - f0 = ((HSD_PSCmdList**) cmdListArr)[idx]->param1; + f0 = (*cmdListArr)[idx]->param1; gen->aux.rect.x = f0; gen->aux.rect.xx = f0; - f0 = ((HSD_PSCmdList**) cmdListArr)[idx]->param2; + f0 = (*cmdListArr)[idx]->param2; gen->aux.rect.y = f0; gen->aux.rect.zx = f0; - f0 = ((HSD_PSCmdList**) cmdListArr)[idx]->param3; + f0 = (*cmdListArr)[idx]->param3; gen->aux.rect.z = f0; gen->aux.rect.zy = f0; gen->aux.rect.zz = 0.0F; @@ -8831,13 +8869,13 @@ HSD_Generator* hsd_8039F05C(s32 linkNo, s32 bank, s32 idx) gen->aux.rect.xz = 0.0F; gen->aux.rect.yx = 0.0F; gen->aux.rect.flag = 0; - if (((HSD_PSCmdList**) cmdListArr)[idx]->param1 < 0.0F) { + if ((*cmdListArr)[idx]->param1 < 0.0F) { gen->aux.rect.flag |= 1; } - if (((HSD_PSCmdList**) cmdListArr)[idx]->param2 < 0.0F) { + if ((*cmdListArr)[idx]->param2 < 0.0F) { gen->aux.rect.flag |= 2; } - if (((HSD_PSCmdList**) cmdListArr)[idx]->param3 < 0.0F) { + if ((*cmdListArr)[idx]->param3 < 0.0F) { gen->aux.rect.flag |= 4; } break; @@ -8891,15 +8929,13 @@ HSD_Generator* hsd_8039F05C(s32 linkNo, s32 bank, s32 idx) } else { gen->aux.sphere.lonMid = atan2f(gen->vel.z, gen->vel.x); } - gen->aux.sphere.latRange = - ((HSD_PSCmdList**) cmdListArr)[idx]->param1; + gen->aux.sphere.latRange = (*cmdListArr)[idx]->param1; f1 = gen->aux.sphere.latRange; if (f1 < 0.0F) { gen->aux.sphere.latRange = -f1; gen->aux.sphere.speed = -gen->aux.sphere.speed; } - gen->aux.sphere.lonRange = - ((HSD_PSCmdList**) cmdListArr)[idx]->param2; + gen->aux.sphere.lonRange = (*cmdListArr)[idx]->param2; break; } default: diff --git a/src/sysdolphin/baselib/sislib.c b/src/sysdolphin/baselib/sislib.c index 6d12bc646e..e1c22fe02c 100644 --- a/src/sysdolphin/baselib/sislib.c +++ b/src/sysdolphin/baselib/sislib.c @@ -72,7 +72,6 @@ static u8 static HSD_Archive* HSD_SisLib_804D1110[5]; SIS* HSD_SisLib_804D1124[5]; -s8 HSD_SisLib_804D6390[4] = { 0, 0, 0, 0 }; static inline u8* HSD_SisLib_BytePtr(void* ptr) { @@ -87,7 +86,6 @@ void* HSD_SisLib_Alloc(s32 size) s32 best_size; SisBlock* free_cur; SisBlock* alloc_cur; - SisBlock* search; best = NULL; alloc_tail = NULL; @@ -129,18 +127,16 @@ void* HSD_SisLib_Alloc(s32 size) OSPanic("sislib.c", 0x56, ""); } - search = free_head; + free_cur = free_head; - if (search == best) { - int remaining_size; + if (free_cur == best) { u8* data_ptr; SisBlock* next_free; + int remaining_size; data_ptr = (u8*) free_head->data; - next_free = free_head->next; - remaining_size = size; - remaining_size = - (free_head->size - remaining_size) - (sizeof(SisBlock)); + next_free = free_cur->next; + remaining_size = (free_cur->size - size) - (sizeof(SisBlock)); if (remaining_size < 0) { OSReport("Memory Empty\n"); OSPanic("sislib.c", 0x5F, ""); @@ -152,10 +148,10 @@ void* HSD_SisLib_Alloc(s32 size) free_head->size = remaining_size; best->size = size; } else { - while (search->next != best) { - search = search->next; + while (free_cur->next != best) { + free_cur = free_cur->next; } - search->next = best->next; + free_cur->next = best->next; } best->next = NULL; if (alloc_tail != NULL) { @@ -725,25 +721,26 @@ HSD_Text* HSD_SisLib_803A6754(int font_idx, s32 context_id) /// @return length of encoded string s32 HSD_SisLib_803A67EC(u8* data, u8* string) { - s32 has_kerning; + u8* lut_ptr; s32 state; s32 state_dot; s32 out_idx_digit; - s32 state_colon; + u8* str_cursor; s32 state_digit; - s32 lut_count; s32 lut_idx; s32 in_idx; s32 out_idx; u8* char_ptr; - u8* str_cursor; - u8* lut_ptr; + s32 state_colon; + s32 has_kerning; u8* out_ptr; u8 cur_char; u8 sjis_hi; u8 sjis_lo; str_cursor = string; + lut_ptr = HSD_SisLib_BytePtr(lbl_8040C8C0); + out_ptr = HSD_SisLib_BytePtr(HSD_SisLib_8040C680); has_kerning = 0; out_idx = 0; for (in_idx = 0; in_idx < 0x80; in_idx++, str_cursor++) { @@ -846,7 +843,6 @@ s32 HSD_SisLib_803A67EC(u8* data, u8* string) out_idx += 1; sjis_hi = 0x82; sjis_lo = (u8) *char_ptr + 0x20; - (void) sjis_lo; } else { data[out_idx] = 0xB; out_idx += 1; @@ -856,28 +852,34 @@ s32 HSD_SisLib_803A67EC(u8* data, u8* string) sjis_lo = str_cursor[1]; str_cursor += 1; } - lut_count = 0x11F; - lut_ptr = (u8*) lbl_8040C8C0; - lut_idx = 0; - do { - if ((sjis_hi == lut_ptr[0]) && (sjis_lo == lut_ptr[1])) { - out_ptr = (u8*) HSD_SisLib_8040C680 + lut_idx * 2; - data[out_idx++] = out_ptr[0]; - data[out_idx++] = out_ptr[1]; + for (lut_idx = 0; lut_idx < 0x11F; lut_idx++) { + if ((sjis_hi == lut_ptr[lut_idx * 2]) && + (sjis_lo == lut_ptr[lut_idx * 2 + 1])) + { + data[out_idx++] = out_ptr[lut_idx * 2]; + data[out_idx++] = out_ptr[lut_idx * 2 + 1]; break; } - lut_ptr += 2; - lut_idx += 1; - lut_count -= 1; - } while (lut_count != 0); + } } data[out_idx] = 0; return out_idx; } +static inline void HSD_SisLib_803A6B98_inline0(HSD_Text* text, u8** cur, + s32 encoded_len, u8* encoded, + s32* copied_bytes) +{ + *(*cur)++ = (u8) (s32) (256.0F * text->x34.y); + for (*copied_bytes = 0; *copied_bytes < encoded_len; (*copied_bytes)++) { + *(*cur)++ = encoded[*copied_bytes]; + } + *(*cur)++ = 0xF; +} + int HSD_SisLib_803A6B98(HSD_Text* text, float x, float y, const char* fmt, ...) { - u8 buffer[128]; + u8 buffer[112]; u8 encoded[128]; s32 x_coord; s32 y_coord; @@ -885,17 +887,12 @@ int HSD_SisLib_803A6B98(HSD_Text* text, float x, float y, const char* fmt, ...) SisBlock* alloc; s32 encoded_len; s32 copied_bytes; - s32 i; - s32 tail_count; u8* copy_dst; u8* copy_src; u8* new_buf; s32 copy_idx; - u8* bulk_src; - u8* tail_src; u32 required_size; u32 old_size; - u32 bulk_count; u8** cur; va_list args; @@ -909,11 +906,11 @@ int HSD_SisLib_803A6B98(HSD_Text* text, float x, float y, const char* fmt, ...) encoded_len = HSD_SisLib_803A67EC(encoded, buffer); } - old_buf = alloc->data; old_size = alloc->size; - required_size = - (HSD_SisLib_BytePtr(alloc->next) - HSD_SisLib_BytePtr(old_buf)) + 0x11; - required_size += encoded_len; + required_size = (HSD_SisLib_BytePtr(alloc->next) - + HSD_SisLib_BytePtr(old_buf = alloc->data)) + + 0x11; + required_size = encoded_len + required_size; if (old_size < required_size) { alloc->size = old_size + ((((u32) (required_size - old_size) >> 7U) + 1) << 7); @@ -952,34 +949,8 @@ int HSD_SisLib_803A6B98(HSD_Text* text, float x, float y, const char* fmt, ...) *(*cur)++ = (u8) (s32) text->x34.x; *(*cur)++ = (u8) (s32) (256.0F * text->x34.x); *(*cur)++ = (u8) (s32) text->x34.y; - *(*cur)++ = (u8) (s32) (256.0F * text->x34.y); - - if (encoded_len > 0) { - if (encoded_len > 8) { - bulk_count = (u32) ((encoded_len - 8) + 7) >> 3U; - bulk_src = encoded; - if ((encoded_len - 8) > 0) { - do { - copied_bytes += 8; - for (i = 0; i < 8; i++) { - *(*cur)++ = bulk_src[i]; - } - bulk_src += 8; - bulk_count -= 1; - } while (bulk_count != 0); - } - } - tail_src = encoded + copied_bytes; - (void) tail_src; - tail_count = encoded_len - copied_bytes; - if (copied_bytes < encoded_len) { - do { - *(*cur)++ = *tail_src++; - tail_count -= 1; - } while (tail_count != 0); - } - } - *(*cur)++ = 0xF; + HSD_SisLib_803A6B98_inline0(text, cur, encoded_len, encoded, + &copied_bytes); *(*cur)++ = 0xD; **cur = 0; return ((sisLib_803A7664_t*) alloc)->xC++; @@ -1047,9 +1018,7 @@ s32 HSD_SisLib_803A70A0(HSD_Text* text, s32 entry_idx, char* fmt, ...) u8 buffer[128]; u8 encoded[128]; s32 old_size; - HSD_Text* old_buf; - s32 new_size; - s32 grow_diff; + u8* new_buf; s32 shrink_diff; s32 tail_len; s32 copy_idx; @@ -1060,7 +1029,7 @@ s32 HSD_SisLib_803A70A0(HSD_Text* text, s32 entry_idx, char* fmt, ...) u32 bulk_count; u8* entry; u8* playhead; - u8* new_buf; + va_list args; u8* copy_src; u8* copy_dst; u8* src; @@ -1069,7 +1038,7 @@ s32 HSD_SisLib_803A70A0(HSD_Text* text, s32 entry_idx, char* fmt, ...) SisBlock* alloc; s32 result; SisBlock* old_end; - va_list args; + s32 new_size; entry = fn_803A6FEC((u8*) text->sis_buffer, entry_idx, &old_size); if (entry != NULL) { @@ -1084,8 +1053,9 @@ s32 HSD_SisLib_803A70A0(HSD_Text* text, s32 entry_idx, char* fmt, ...) new_size = 0; } if (old_size < new_size) { + HSD_Text* old_buf; old_end = alloc->next; - grow_diff = new_size - old_size; + result = new_size - old_size; old_buf = alloc->data; cur_size = alloc->size; tail_len = (u8*) old_end - playhead; @@ -1119,7 +1089,7 @@ s32 HSD_SisLib_803A70A0(HSD_Text* text, s32 entry_idx, char* fmt, ...) HSD_SisLib_Free(old_buf); playhead = (u8*) alloc->next - tail_len; } - dst = &playhead[grow_diff + tail_len]; + dst = &playhead[result + tail_len]; src = &playhead[tail_len]; if (tail_len > 0) { bulk_count = (u32) tail_len >> 3U; @@ -1146,7 +1116,8 @@ s32 HSD_SisLib_803A70A0(HSD_Text* text, s32 entry_idx, char* fmt, ...) } while (remainder != 0); } grow_done: - alloc->next = (SisBlock*) ((u8*) alloc->next + grow_diff); + alloc->next = + (SisBlock*) (HSD_SisLib_BytePtr(alloc->next) + result); } else if (old_size > new_size) { shrink_diff = old_size - new_size; i = 0; @@ -1351,7 +1322,6 @@ void HSD_SisLib_803A8134(void* cursor, HSD_Text* text, f32* out_width, TextGlyphTexture* glyph_tex; u8* default_kerning = HSD_SisLib_8040CB00; f32 line_height; - f32 line_height_2; f32 saved_scale_x; f32 saved_scale_y; f32 saved_spacing; @@ -1447,9 +1417,9 @@ void HSD_SisLib_803A8134(void* cursor, HSD_Text* text, f32* out_width, (((glyph_code - 0x2000) * 2) & 0x1FFFE)); kern_right = kern_data->right; - (void) kern_right; kern_left = kern_data->left; - kern_width = kern_left + (kern_right - 2); + kern_width = kern_right - 2; + kern_width = kern_left + kern_width; *out_width = -((text->x80.x * (f32) kern_width) - *out_width); } else { @@ -1458,7 +1428,8 @@ void HSD_SisLib_803A8134(void* cursor, HSD_Text* text, f32* out_width, ->data[((glyph_code - 0x4000) * 2) & 0x1FFFE]; kern_right = kern_data_2->right; kern_left = kern_data_2->left; - kern_width = kern_left + (kern_right - 2); + kern_width = kern_right - 2; + kern_width = kern_left + kern_width; *out_width = -((text->x80.x * (f32) kern_width) - *out_width); } @@ -1490,11 +1461,10 @@ void HSD_SisLib_803A8134(void* cursor, HSD_Text* text, f32* out_width, void HSD_SisLib_803A7684(HSD_Text* text, u8* cursor, u8 flags) { - s32 old_x6E; + u16 old_x6E; s32 new_x6E; s32 idx; - s32 count; - s32 k; + u16 count; s32 pos; u32 bulk; u8* old_buf; @@ -1507,17 +1477,30 @@ void HSD_SisLib_803A7684(HSD_Text* text, u8* cursor, u8 flags) new_x6E = old_x6E + 0x10; old_buf = (u8*) text->string_buffer; text->string_buffer = HSD_SisLib_Alloc(new_x6E); + src = old_buf; text->x6E = (u16) new_x6E; + count = old_x6E; idx = 0; if (old_x6E > 0) { - src = old_buf; - count = old_x6E; bulk = (u32) count >> 3U; if (bulk != 0) { do { - for (k = 0; k < 8; k++) { - text->string_buffer[idx++] = src[k]; - } + text->string_buffer[idx] = src[0]; + idx += 1; + text->string_buffer[idx] = src[1]; + idx += 1; + text->string_buffer[idx] = src[2]; + idx += 1; + text->string_buffer[idx] = src[3]; + idx += 1; + text->string_buffer[idx] = src[4]; + idx += 1; + text->string_buffer[idx] = src[5]; + idx += 1; + text->string_buffer[idx] = src[6]; + idx += 1; + text->string_buffer[idx] = src[7]; + idx += 1; src += 8; bulk -= 1; } while (bulk != 0); @@ -1559,17 +1542,30 @@ void HSD_SisLib_803A7684(HSD_Text* text, u8* cursor, u8 flags) new_x6E = old_x6E + 0x10; old_buf = (u8*) text->string_buffer; text->string_buffer = HSD_SisLib_Alloc(new_x6E); + src = old_buf; text->x6E = (u16) new_x6E; + count = old_x6E; idx = 0; if (old_x6E > 0) { - src = old_buf; - count = old_x6E; bulk = (u32) count >> 3U; if (bulk != 0) { do { - for (k = 0; k < 8; k++) { - text->string_buffer[idx++] = src[k]; - } + text->string_buffer[idx] = src[0]; + idx += 1; + text->string_buffer[idx] = src[1]; + idx += 1; + text->string_buffer[idx] = src[2]; + idx += 1; + text->string_buffer[idx] = src[3]; + idx += 1; + text->string_buffer[idx] = src[4]; + idx += 1; + text->string_buffer[idx] = src[5]; + idx += 1; + text->string_buffer[idx] = src[6]; + idx += 1; + text->string_buffer[idx] = src[7]; + idx += 1; src += 8; bulk -= 1; } while (bulk != 0); @@ -1608,17 +1604,30 @@ void HSD_SisLib_803A7684(HSD_Text* text, u8* cursor, u8 flags) new_x6E = old_x6E + 0x10; old_buf = (u8*) text->string_buffer; text->string_buffer = HSD_SisLib_Alloc(new_x6E); + src = old_buf; text->x6E = (u16) new_x6E; + count = old_x6E; idx = 0; if (old_x6E > 0) { - src = old_buf; - count = old_x6E; bulk = (u32) count >> 3U; if (bulk != 0) { do { - for (k = 0; k < 8; k++) { - text->string_buffer[idx++] = src[k]; - } + text->string_buffer[idx] = src[0]; + idx += 1; + text->string_buffer[idx] = src[1]; + idx += 1; + text->string_buffer[idx] = src[2]; + idx += 1; + text->string_buffer[idx] = src[3]; + idx += 1; + text->string_buffer[idx] = src[4]; + idx += 1; + text->string_buffer[idx] = src[5]; + idx += 1; + text->string_buffer[idx] = src[6]; + idx += 1; + text->string_buffer[idx] = src[7]; + idx += 1; src += 8; bulk -= 1; } while (bulk != 0); @@ -1660,17 +1669,30 @@ void HSD_SisLib_803A7684(HSD_Text* text, u8* cursor, u8 flags) new_x6E = old_x6E + 0x10; old_buf = (u8*) text->string_buffer; text->string_buffer = HSD_SisLib_Alloc(new_x6E); + src = old_buf; text->x6E = (u16) new_x6E; + count = old_x6E; idx = 0; if (old_x6E > 0) { - src = old_buf; - count = old_x6E; bulk = (u32) count >> 3U; if (bulk != 0) { do { - for (k = 0; k < 8; k++) { - text->string_buffer[idx++] = src[k]; - } + text->string_buffer[idx] = src[0]; + idx += 1; + text->string_buffer[idx] = src[1]; + idx += 1; + text->string_buffer[idx] = src[2]; + idx += 1; + text->string_buffer[idx] = src[3]; + idx += 1; + text->string_buffer[idx] = src[4]; + idx += 1; + text->string_buffer[idx] = src[5]; + idx += 1; + text->string_buffer[idx] = src[6]; + idx += 1; + text->string_buffer[idx] = src[7]; + idx += 1; src += 8; bulk -= 1; } while (bulk != 0); @@ -1704,17 +1726,30 @@ void HSD_SisLib_803A7684(HSD_Text* text, u8* cursor, u8 flags) old_buf = (u8*) text->string_buffer; (void) old_buf; text->string_buffer = HSD_SisLib_Alloc(new_x6E); + src = old_buf; text->x6E = (u16) new_x6E; + count = old_x6E; idx = 0; if (old_x6E > 0) { - src = old_buf; - count = old_x6E; bulk = (u32) count >> 3U; if (bulk != 0) { do { - for (k = 0; k < 8; k++) { - text->string_buffer[idx++] = src[k]; - } + text->string_buffer[idx] = src[0]; + idx += 1; + text->string_buffer[idx] = src[1]; + idx += 1; + text->string_buffer[idx] = src[2]; + idx += 1; + text->string_buffer[idx] = src[3]; + idx += 1; + text->string_buffer[idx] = src[4]; + idx += 1; + text->string_buffer[idx] = src[5]; + idx += 1; + text->string_buffer[idx] = src[6]; + idx += 1; + text->string_buffer[idx] = src[7]; + idx += 1; src += 8; bulk -= 1; } while (bulk != 0); @@ -1755,9 +1790,8 @@ void HSD_SisLib_803A7684(HSD_Text* text, u8* cursor, u8 flags) s32 HSD_SisLib_803A7F0C(HSD_Text* text, s32 flags) { - u8 entry; + s8 entry; s32 flag_hi; - s32 entry_type; s32 entry_flags; s32 target_type; s32 result; @@ -1771,17 +1805,15 @@ s32 HSD_SisLib_803A7F0C(HSD_Text* text, s32 flags) remove_size = 0; while (pos >= 0) { entry = text->string_buffer[pos]; - entry_type = entry & 0x7F; - (void) entry_type; entry_flags = entry & 0x80; - switch (entry_type) { /* irregular */ + switch ((u8) entry & 0x7F) { /* irregular */ case 1: pos -= 4; if (target_type == 1) { text->x78.x = - (f32) * (s16*) (text->string_buffer + pos) * 0.00390625F; - text->x78.y = (f32) * (s16*) (text->string_buffer + pos + 2) * - 0.00390625F; + (f32) * (s16*) (text->string_buffer + pos) / 256.0F; + text->x78.y = + (f32) * (s16*) (text->string_buffer + pos + 2) / 256.0F; if (flag_hi == entry_flags) { remove_size = 5; } @@ -1804,9 +1836,9 @@ s32 HSD_SisLib_803A7F0C(HSD_Text* text, s32 flags) pos -= 4; if (target_type == 3) { text->x80.x = - (f32) * (u16*) (text->string_buffer + pos) * 0.00390625F; - text->x80.y = (f32) * (u16*) (text->string_buffer + pos + 2) * - 0.00390625F; + (f32) * (u16*) (text->string_buffer + pos) / 256.0F; + text->x80.y = + (f32) * (u16*) (text->string_buffer + pos + 2) / 256.0F; if (flag_hi == entry_flags) { remove_size = 5; } diff --git a/src/sysdolphin/baselib/sislib.h b/src/sysdolphin/baselib/sislib.h index 2bed4a6e24..662b503f27 100644 --- a/src/sysdolphin/baselib/sislib.h +++ b/src/sysdolphin/baselib/sislib.h @@ -103,7 +103,6 @@ struct sislib_UnkAlloc3 { u8 xF; }; -extern s8 HSD_SisLib_804D6390[4]; extern SIS* HSD_SisLib_804D1124[5]; extern u32 lbl_8040C8C0[144]; extern u32 HSD_SisLib_8040C680[144]; diff --git a/src/sysdolphin/baselib/sobjlib.c b/src/sysdolphin/baselib/sobjlib.c index 205895c8dc..c2dd798da1 100644 --- a/src/sysdolphin/baselib/sobjlib.c +++ b/src/sysdolphin/baselib/sobjlib.c @@ -296,9 +296,9 @@ void HSD_SObjLib_803A4A68(HSD_SObj* sobj) origin_x = sobj->x10; origin_y = sobj->x14; } else { - center_width = (f32) obj_width * sobj->x1C; + center_width = sobj->x1C * (f32) obj_width; center_height = (f32) obj_height * sobj->x20; - origin_x = (center_width * HSD_SObjLib_804DEA94) + sobj->x10; + origin_x = (HSD_SObjLib_804DEA94 * center_width) + sobj->x10; origin_y = (center_height * HSD_SObjLib_804DEA94) + sobj->x14; } diff --git a/src/sysdolphin/baselib/synth.c b/src/sysdolphin/baselib/synth.c index f2ba6e6885..b2cc9d445e 100644 --- a/src/sysdolphin/baselib/synth.c +++ b/src/sysdolphin/baselib/synth.c @@ -67,9 +67,12 @@ void HSD_SynthSFXSampleLoadCallback(int result, int length, void* addr, dnw = total - header_size; *(u32*) ((u8*) HSD_Synth_804D7730 + (dnw & ~3)) = hsd_SynthSFXLoadBuf[4]; - ((u32*) HSD_Synth_804D7730)[(dnw >> 2) + 1] = hsd_SynthSFXLoadBuf[5]; - ((u32*) HSD_Synth_804D7730)[(dnw >> 2) + 2] = hsd_SynthSFXLoadBuf[6]; - ((u32*) HSD_Synth_804D7730)[(dnw >> 2) + 3] = hsd_SynthSFXLoadBuf[7]; + ((u32*) HSD_Synth_804D7730)[((dnw & ~3) >> 2) + 1] = + hsd_SynthSFXLoadBuf[5]; + ((u32*) HSD_Synth_804D7730)[((dnw & ~3) >> 2) + 2] = + hsd_SynthSFXLoadBuf[6]; + ((u32*) HSD_Synth_804D7730)[((dnw & ~3) >> 2) + 3] = + hsd_SynthSFXLoadBuf[7]; HSD_Synth_804D7734 = (u32*) ((u8*) HSD_Synth_804D7730 + (dnw & ~3)); bankID = HSD_Synth_804C2A60[0].bankID; @@ -870,6 +873,7 @@ s32 HSD_Synth_8038A000(void) struct HSD_SynthSFXNode** pnode; AXPBVE ve; + PAD_STACK(8); intr = OSDisableInterrupts(); if (HSD_Synth_804D7758 != 0) { int ch; @@ -904,23 +908,19 @@ s32 HSD_Synth_8038A000(void) *pnode = node->x20; continue; } - if (node->user_vol[0].x4 != 0) { - int c = node->user_vol[0].x4; - node->unk28 = (node->unk28 * ((f32) c - 1.0f)) / (f32) c + - node->user_vol[0].volume / (f32) c; - node->user_vol[0].x4 -= 1; - if (node->user_vol[0].x4 != 0) { - active = 1; - } - } - if (node->user_vol[1].x4 != 0) { - int c = node->user_vol[1].x4; - node->user_vol[0].x8_float = - (node->user_vol[0].x8_float * ((f32) c - 1.0f)) / (f32) c + - node->user_vol[1].volume / (f32) c; - node->user_vol[1].x4 -= 1; - if (node->user_vol[1].x4 != 0) { - active = 1; + { + int k; + for (k = 0; k < USERVOL_NUM; k++) { + if (*(volatile int*) &node->user_vol[k].x4 != 0) { + int c = node->user_vol[k].x4; + (&node->unk28)[k * 3] = + ((&node->unk28)[k * 3] * ((f32) c - 1.0f)) / (f32) c + + node->user_vol[k].volume / (f32) c; + node->user_vol[k].x4 -= 1; + if (node->user_vol[k].x4 != 0) { + active = 1; + } + } } } if (HSD_Synth_804C28E0_1784[node->xB].x178C != 0) { @@ -1205,13 +1205,42 @@ extern s32 HSD_Synth_804D7764; extern u32 HSD_Synth_804D7770; extern u32 HSD_Synth_804D7774; +static inline void HSD_Synth_8038ADD0_inline(u32 pos) +{ + BOOL intr; + s32 src; + + if ((s32) ((HSD_Synth_804D776C + 1) % 3) != pos) { + intr = OSDisableInterrupts(); + if (HSD_Synth_804D7778 != 0 || + HSD_Synth_804D7768 != HSD_Synth_804D776C) + { + OSRestoreInterrupts(intr); + return; + } + if (getNode(HSD_Synth_804D7760) != NULL) { + src = lbl_804C4540[HSD_Synth_804D776C].x8; + if (src == -1) { + HSD_Synth_804D776C = (HSD_Synth_804D776C + 1) % 3; + } else { + HSD_Synth_804D7768 = (HSD_Synth_804D776C + 1) % 3; + HSD_Synth_804D7778 = 1; + HSD_DevComRequest( + HSD_Synth_804D7764, src, + (uintptr_t) &lbl_804C4540[HSD_Synth_804D7768], 0x20, 0x21, + 0, (HSD_DevComCallback) (Event) HSD_Synth_8038AD74, + (struct HSD_SynthStreamHeader*) (src + 0x20)); + } + } + OSRestoreInterrupts(intr); + } +} + void HSD_Synth_8038ADD0(void) { struct HSD_SynthSFXNode* node = getNode(HSD_Synth_804D7760); u32 pos; s32 i; - BOOL intr; - s32 src; if (node == NULL) { return; @@ -1254,30 +1283,7 @@ void HSD_Synth_8038ADD0(void) } } } - if ((s32) ((HSD_Synth_804D776C + 1) % 3) != pos) { - intr = OSDisableInterrupts(); - if (HSD_Synth_804D7778 != 0 || - HSD_Synth_804D7768 != HSD_Synth_804D776C) - { - OSRestoreInterrupts(intr); - return; - } - if (getNode(HSD_Synth_804D7760) != NULL) { - src = lbl_804C4540[HSD_Synth_804D776C].x8; - if (src == -1) { - HSD_Synth_804D776C = (HSD_Synth_804D776C + 1) % 3; - } else { - HSD_Synth_804D7768 = (HSD_Synth_804D776C + 1) % 3; - HSD_Synth_804D7778 = 1; - HSD_DevComRequest( - HSD_Synth_804D7764, src, - (uintptr_t) &lbl_804C4540[HSD_Synth_804D7768], 0x20, 0x21, - 0, (HSD_DevComCallback) (Event) HSD_Synth_8038AD74, - (void*) (src + 0x20)); - } - } - OSRestoreInterrupts(intr); - } + HSD_Synth_8038ADD0_inline(pos); } void HSD_Synth_8038B120(void) diff --git a/src/sysdolphin/baselib/texpdag.c b/src/sysdolphin/baselib/texpdag.c index bc91c345f2..9ee544af35 100644 --- a/src/sysdolphin/baselib/texpdag.c +++ b/src/sysdolphin/baselib/texpdag.c @@ -161,12 +161,8 @@ int HSD_TExpMakeDag(HSD_TExp* root, HSD_TExpDag* list) { HSD_TExp* sp94[HSD_TEXP_MAX_NUM]; int sp14[32]; - HSD_TExp** base; HSD_TExpDag* dep_entry; HSD_TExpDag* dep_entry2; - HSD_TExpDag* dag; - int count; - int count2; int num; int j; int i; @@ -174,40 +170,40 @@ int HSD_TExpMakeDag(HSD_TExp* root, HSD_TExpDag* list) int l; int last; int idx; - int dist; - PAD_STACK(4); HSD_ASSERT(0xEE, HSD_TExpGetType(root) == HSD_TE_TEV); - base = &sp94[0]; num = 0; - base[num++] = root; - for (j = 0; j < num; j++) { - HSD_TExp* tmp; - HSD_ASSERT(0xF6, jtev.c_in[i].type == HSD_TE_TEV) { - for (k = 0; k < num; k++) { - if (sp94[k] == tmp->tev.c_in[i].exp) { - break; + sp94[num++] = root; + { + HSD_TExp** p = sp94; + for (j = 0; j < num; j++, p++) { + HSD_TExp* tmp; + HSD_ASSERT(0xF6, jtev.c_in[i].type == HSD_TE_TEV) { + for (k = 0; k < num; k++) { + if (sp94[k] == tmp->tev.c_in[i].exp) { + break; + } + } + if (k >= num) { + sp94[num++] = tmp->tev.c_in[i].exp; } - } - if (k >= num) { - base[num++] = tmp->tev.c_in[i].exp; } } - } - for (i = 0; i < 4; i++) { - if (tmp->tev.a_in[i].type == HSD_TE_TEV) { - for (k = 0; k < num; k++) { - if (base[k] == tmp->tev.a_in[i].exp) { - break; + for (i = 0; i < 4; i++) { + if (tmp->tev.a_in[i].type == HSD_TE_TEV) { + for (k = 0; k < num; k++) { + if (sp94[k] == tmp->tev.a_in[i].exp) { + break; + } + } + if (k >= num) { + sp94[num++] = tmp->tev.a_in[i].exp; } - } - if (k >= num) { - base[num++] = tmp->tev.a_in[i].exp; } } } @@ -245,20 +241,13 @@ int HSD_TExpMakeDag(HSD_TExp* root, HSD_TExpDag* list) list[last].tev = &tmp->tev; for (idx = 0; idx < 4; idx++) { if (tmp->tev.c_in[idx].type == HSD_TE_TEV) { - HSD_TExp** q = &sp94[last]; for (l = last; l < num; l++) { - if (tmp->tev.c_in[idx].exp == *q) { - HSD_TExpDag** deps; - u8 dep_count; - - dep_count = list[last].nb_dep; - deps = list[last].depend; + if (tmp->tev.c_in[idx].exp == sp94[l]) { dep_entry = &list[l]; for (l = 0; l < list[last].nb_dep; l++) { - if (*deps == dep_entry) { + if (list[last].depend[l] == dep_entry) { break; } - deps++; } if (l >= (int) list[last].nb_dep) { list[last].depend[list[last].nb_dep++] = dep_entry; @@ -266,7 +255,6 @@ int HSD_TExpMakeDag(HSD_TExp* root, HSD_TExpDag* list) } break; } - q++; } HSD_ASSERT(0x145, l < num); } @@ -274,27 +262,22 @@ int HSD_TExpMakeDag(HSD_TExp* root, HSD_TExpDag* list) for (idx = 0; idx < 4; idx++) { if (tmp->tev.a_in[idx].type == HSD_TE_TEV) { - HSD_TExp** r2 = &sp94[last]; for (l = last; l < num; l++) { - if (tmp->tev.a_in[i].exp == *r2) { - HSD_TExpDag** deps2; + if (tmp->tev.a_in[idx].exp == sp94[l]) { u8 dep_count2 = list[last].nb_dep; - deps2 = list[last].depend; dep_entry2 = &list[l]; - (void) dep_entry2; for (l = 0; l < (int) dep_count2; l++) { - if (*deps2 == dep_entry2) { + if (list[last].depend[l] == dep_entry2) { break; } - deps2++; } if (l >= list[last].nb_dep) { - list[last].depend[list[last].nb_dep++] = &list[l]; - list[l].nb_ref++; + list[last].depend[list[last].nb_dep++] = + dep_entry2; + dep_entry2->nb_ref++; } break; } - r2++; } HSD_ASSERT(0x15B, l < num); }