From bdbe0c5e65fc751b800d82815ba22c3dd2a9db7f Mon Sep 17 00:00:00 2001 From: Ethan Roseman Date: Sun, 3 Jan 2021 18:34:04 +0900 Subject: [PATCH] a few --- .../code_197F40/InitTargetIterator.s | 25 --------- .../code_197F40/ResetAllActorSounds.s | 26 --------- .../code_197F40/ShowShockEffect.s | 26 --------- .../code_197F40/WaitForBuffDone.s | 9 ---- asm/nonmatchings/code_197F40/func_80271210.s | 22 -------- asm/nonmatchings/code_197F40/func_80271258.s | 22 -------- asm/nonmatchings/code_197F40/func_8027143C.s | 22 -------- include/common_structs.h | 2 +- include/functions.h | 3 ++ src/code_197F40.c | 54 ++++++++++++++++--- src/os/code_4ac90_len_3910.c | 4 +- tools/asm_sizes.py | 8 +-- 12 files changed, 58 insertions(+), 165 deletions(-) delete mode 100644 asm/nonmatchings/code_197F40/InitTargetIterator.s delete mode 100644 asm/nonmatchings/code_197F40/ResetAllActorSounds.s delete mode 100644 asm/nonmatchings/code_197F40/ShowShockEffect.s delete mode 100644 asm/nonmatchings/code_197F40/WaitForBuffDone.s delete mode 100644 asm/nonmatchings/code_197F40/func_80271210.s delete mode 100644 asm/nonmatchings/code_197F40/func_80271258.s delete mode 100644 asm/nonmatchings/code_197F40/func_8027143C.s diff --git a/asm/nonmatchings/code_197F40/InitTargetIterator.s b/asm/nonmatchings/code_197F40/InitTargetIterator.s deleted file mode 100644 index 788f42de4e..0000000000 --- a/asm/nonmatchings/code_197F40/InitTargetIterator.s +++ /dev/null @@ -1,25 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - -glabel InitTargetIterator -/* 19CC34 8026E354 27BDFFE8 */ addiu $sp, $sp, -0x18 -/* 19CC38 8026E358 AFBF0010 */ sw $ra, 0x10($sp) -/* 19CC3C 8026E35C 0C09A75B */ jal get_actor -/* 19CC40 8026E360 8C840148 */ lw $a0, 0x148($a0) -/* 19CC44 8026E364 0040202D */ daddu $a0, $v0, $zero -/* 19CC48 8026E368 80820425 */ lb $v0, 0x425($a0) -/* 19CC4C 8026E36C 00821021 */ addu $v0, $a0, $v0 -/* 19CC50 8026E370 8043040D */ lb $v1, 0x40d($v0) -/* 19CC54 8026E374 00031080 */ sll $v0, $v1, 2 -/* 19CC58 8026E378 00431021 */ addu $v0, $v0, $v1 -/* 19CC5C 8026E37C 00021080 */ sll $v0, $v0, 2 -/* 19CC60 8026E380 2442022C */ addiu $v0, $v0, 0x22c -/* 19CC64 8026E384 00821021 */ addu $v0, $a0, $v0 -/* 19CC68 8026E388 94430000 */ lhu $v1, ($v0) -/* 19CC6C 8026E38C A4830428 */ sh $v1, 0x428($a0) -/* 19CC70 8026E390 90430003 */ lbu $v1, 3($v0) -/* 19CC74 8026E394 A0830426 */ sb $v1, 0x426($a0) -/* 19CC78 8026E398 8FBF0010 */ lw $ra, 0x10($sp) -/* 19CC7C 8026E39C 24020002 */ addiu $v0, $zero, 2 -/* 19CC80 8026E3A0 03E00008 */ jr $ra -/* 19CC84 8026E3A4 27BD0018 */ addiu $sp, $sp, 0x18 diff --git a/asm/nonmatchings/code_197F40/ResetAllActorSounds.s b/asm/nonmatchings/code_197F40/ResetAllActorSounds.s deleted file mode 100644 index 2af7914189..0000000000 --- a/asm/nonmatchings/code_197F40/ResetAllActorSounds.s +++ /dev/null @@ -1,26 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - -glabel ResetAllActorSounds -/* 19DFCC 8026F6EC 27BDFFE8 */ addiu $sp, $sp, -0x18 -/* 19DFD0 8026F6F0 AFB00010 */ sw $s0, 0x10($sp) -/* 19DFD4 8026F6F4 0080802D */ daddu $s0, $a0, $zero -/* 19DFD8 8026F6F8 AFBF0014 */ sw $ra, 0x14($sp) -/* 19DFDC 8026F6FC 8E02000C */ lw $v0, 0xc($s0) -/* 19DFE0 8026F700 0C0B1EAF */ jal get_variable -/* 19DFE4 8026F704 8C450000 */ lw $a1, ($v0) -/* 19DFE8 8026F708 0040202D */ daddu $a0, $v0, $zero -/* 19DFEC 8026F70C 2402FF81 */ addiu $v0, $zero, -0x7f -/* 19DFF0 8026F710 14820002 */ bne $a0, $v0, .L8026F71C -/* 19DFF4 8026F714 00000000 */ nop -/* 19DFF8 8026F718 8E040148 */ lw $a0, 0x148($s0) -.L8026F71C: -/* 19DFFC 8026F71C 0C09A75B */ jal get_actor -/* 19E000 8026F720 00000000 */ nop -/* 19E004 8026F724 0C099EA7 */ jal reset_all_actor_sounds -/* 19E008 8026F728 0040202D */ daddu $a0, $v0, $zero -/* 19E00C 8026F72C 8FBF0014 */ lw $ra, 0x14($sp) -/* 19E010 8026F730 8FB00010 */ lw $s0, 0x10($sp) -/* 19E014 8026F734 24020002 */ addiu $v0, $zero, 2 -/* 19E018 8026F738 03E00008 */ jr $ra -/* 19E01C 8026F73C 27BD0018 */ addiu $sp, $sp, 0x18 diff --git a/asm/nonmatchings/code_197F40/ShowShockEffect.s b/asm/nonmatchings/code_197F40/ShowShockEffect.s deleted file mode 100644 index 0d7f73f5e2..0000000000 --- a/asm/nonmatchings/code_197F40/ShowShockEffect.s +++ /dev/null @@ -1,26 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - -glabel ShowShockEffect -/* 19E490 8026FBB0 27BDFFE8 */ addiu $sp, $sp, -0x18 -/* 19E494 8026FBB4 AFB00010 */ sw $s0, 0x10($sp) -/* 19E498 8026FBB8 0080802D */ daddu $s0, $a0, $zero -/* 19E49C 8026FBBC AFBF0014 */ sw $ra, 0x14($sp) -/* 19E4A0 8026FBC0 8E02000C */ lw $v0, 0xc($s0) -/* 19E4A4 8026FBC4 0C0B1EAF */ jal get_variable -/* 19E4A8 8026FBC8 8C450000 */ lw $a1, ($v0) -/* 19E4AC 8026FBCC 0040202D */ daddu $a0, $v0, $zero -/* 19E4B0 8026FBD0 2402FF81 */ addiu $v0, $zero, -0x7f -/* 19E4B4 8026FBD4 14820002 */ bne $a0, $v0, .L8026FBE0 -/* 19E4B8 8026FBD8 00000000 */ nop -/* 19E4BC 8026FBDC 8E040148 */ lw $a0, 0x148($s0) -.L8026FBE0: -/* 19E4C0 8026FBE0 0C09A75B */ jal get_actor -/* 19E4C4 8026FBE4 00000000 */ nop -/* 19E4C8 8026FBE8 0C09451D */ jal func_80251474 -/* 19E4CC 8026FBEC 0040202D */ daddu $a0, $v0, $zero -/* 19E4D0 8026FBF0 8FBF0014 */ lw $ra, 0x14($sp) -/* 19E4D4 8026FBF4 8FB00010 */ lw $s0, 0x10($sp) -/* 19E4D8 8026FBF8 24020002 */ addiu $v0, $zero, 2 -/* 19E4DC 8026FBFC 03E00008 */ jr $ra -/* 19E4E0 8026FC00 27BD0018 */ addiu $sp, $sp, 0x18 diff --git a/asm/nonmatchings/code_197F40/WaitForBuffDone.s b/asm/nonmatchings/code_197F40/WaitForBuffDone.s deleted file mode 100644 index 7c74cbe650..0000000000 --- a/asm/nonmatchings/code_197F40/WaitForBuffDone.s +++ /dev/null @@ -1,9 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - -glabel WaitForBuffDone -/* 19FA2C 8027114C 3C02802A */ lui $v0, %hi(D_8029FBD4) -/* 19FA30 80271150 8042FBD4 */ lb $v0, %lo(D_8029FBD4)($v0) -/* 19FA34 80271154 2C420001 */ sltiu $v0, $v0, 1 -/* 19FA38 80271158 03E00008 */ jr $ra -/* 19FA3C 8027115C 00021040 */ sll $v0, $v0, 1 diff --git a/asm/nonmatchings/code_197F40/func_80271210.s b/asm/nonmatchings/code_197F40/func_80271210.s deleted file mode 100644 index 4a636b4f21..0000000000 --- a/asm/nonmatchings/code_197F40/func_80271210.s +++ /dev/null @@ -1,22 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - -glabel func_80271210 -/* 19FAF0 80271210 27BDFFE8 */ addiu $sp, $sp, -0x18 -/* 19FAF4 80271214 0080102D */ daddu $v0, $a0, $zero -/* 19FAF8 80271218 AFBF0010 */ sw $ra, 0x10($sp) -/* 19FAFC 8027121C C4400084 */ lwc1 $f0, 0x84($v0) -/* 19FB00 80271220 46800020 */ cvt.s.w $f0, $f0 -/* 19FB04 80271224 44050000 */ mfc1 $a1, $f0 -/* 19FB08 80271228 C4400088 */ lwc1 $f0, 0x88($v0) -/* 19FB0C 8027122C 46800020 */ cvt.s.w $f0, $f0 -/* 19FB10 80271230 44060000 */ mfc1 $a2, $f0 -/* 19FB14 80271234 C440008C */ lwc1 $f0, 0x8c($v0) -/* 19FB18 80271238 46800020 */ cvt.s.w $f0, $f0 -/* 19FB1C 8027123C 44070000 */ mfc1 $a3, $f0 -/* 19FB20 80271240 0C01C2BC */ jal func_80070AF0 -/* 19FB24 80271244 0000202D */ daddu $a0, $zero, $zero -/* 19FB28 80271248 8FBF0010 */ lw $ra, 0x10($sp) -/* 19FB2C 8027124C 24020002 */ addiu $v0, $zero, 2 -/* 19FB30 80271250 03E00008 */ jr $ra -/* 19FB34 80271254 27BD0018 */ addiu $sp, $sp, 0x18 diff --git a/asm/nonmatchings/code_197F40/func_80271258.s b/asm/nonmatchings/code_197F40/func_80271258.s deleted file mode 100644 index dce375f695..0000000000 --- a/asm/nonmatchings/code_197F40/func_80271258.s +++ /dev/null @@ -1,22 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - -glabel func_80271258 -/* 19FB38 80271258 27BDFFE8 */ addiu $sp, $sp, -0x18 -/* 19FB3C 8027125C 0080102D */ daddu $v0, $a0, $zero -/* 19FB40 80271260 AFBF0010 */ sw $ra, 0x10($sp) -/* 19FB44 80271264 C4400084 */ lwc1 $f0, 0x84($v0) -/* 19FB48 80271268 46800020 */ cvt.s.w $f0, $f0 -/* 19FB4C 8027126C 44050000 */ mfc1 $a1, $f0 -/* 19FB50 80271270 C4400088 */ lwc1 $f0, 0x88($v0) -/* 19FB54 80271274 46800020 */ cvt.s.w $f0, $f0 -/* 19FB58 80271278 44060000 */ mfc1 $a2, $f0 -/* 19FB5C 8027127C C440008C */ lwc1 $f0, 0x8c($v0) -/* 19FB60 80271280 46800020 */ cvt.s.w $f0, $f0 -/* 19FB64 80271284 44070000 */ mfc1 $a3, $f0 -/* 19FB68 80271288 0C01C2BC */ jal func_80070AF0 -/* 19FB6C 8027128C 24040001 */ addiu $a0, $zero, 1 -/* 19FB70 80271290 8FBF0010 */ lw $ra, 0x10($sp) -/* 19FB74 80271294 24020002 */ addiu $v0, $zero, 2 -/* 19FB78 80271298 03E00008 */ jr $ra -/* 19FB7C 8027129C 27BD0018 */ addiu $sp, $sp, 0x18 diff --git a/asm/nonmatchings/code_197F40/func_8027143C.s b/asm/nonmatchings/code_197F40/func_8027143C.s deleted file mode 100644 index 74d1ffc4ed..0000000000 --- a/asm/nonmatchings/code_197F40/func_8027143C.s +++ /dev/null @@ -1,22 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - -glabel func_8027143C -/* 19FD1C 8027143C 27BDFFE8 */ addiu $sp, $sp, -0x18 -/* 19FD20 80271440 0080102D */ daddu $v0, $a0, $zero -/* 19FD24 80271444 AFBF0010 */ sw $ra, 0x10($sp) -/* 19FD28 80271448 C4400084 */ lwc1 $f0, 0x84($v0) -/* 19FD2C 8027144C 46800020 */ cvt.s.w $f0, $f0 -/* 19FD30 80271450 44050000 */ mfc1 $a1, $f0 -/* 19FD34 80271454 C4400088 */ lwc1 $f0, 0x88($v0) -/* 19FD38 80271458 46800020 */ cvt.s.w $f0, $f0 -/* 19FD3C 8027145C 44060000 */ mfc1 $a2, $f0 -/* 19FD40 80271460 C440008C */ lwc1 $f0, 0x8c($v0) -/* 19FD44 80271464 46800020 */ cvt.s.w $f0, $f0 -/* 19FD48 80271468 44070000 */ mfc1 $a3, $f0 -/* 19FD4C 8027146C 0C01C2A4 */ jal func_80070A90 -/* 19FD50 80271470 0000202D */ daddu $a0, $zero, $zero -/* 19FD54 80271474 8FBF0010 */ lw $ra, 0x10($sp) -/* 19FD58 80271478 24020002 */ addiu $v0, $zero, 2 -/* 19FD5C 8027147C 03E00008 */ jr $ra -/* 19FD60 80271480 27BD0018 */ addiu $sp, $sp, 0x18 diff --git a/include/common_structs.h b/include/common_structs.h index 8ecb5933b6..13a530be37 100644 --- a/include/common_structs.h +++ b/include/common_structs.h @@ -1335,7 +1335,7 @@ typedef struct Actor { /* 0x22C */ struct SelectableTarget targetData[24]; /* 0x40C */ s8 targetListLength; /* 0x40D */ s8 targetIndexList[24]; /* into targetData */ - /* 0x425 */ u8 selectedTargetIndex; /* into target index list */ + /* 0x425 */ s8 selectedTargetIndex; /* into target index list */ /* 0x426 */ s8 targetPartIndex; /* 0x427 */ char unk_427; /* 0x428 */ s16 targetActorID; diff --git a/include/functions.h b/include/functions.h index e21f624388..28a255fd4f 100644 --- a/include/functions.h +++ b/include/functions.h @@ -12,6 +12,9 @@ void boot_main(void); void osCleanupThread(void); +void func_80070A90(s32, f32, f32, f32); +void func_80070AF0(s32, f32, f32, f32); + s32 heap_malloc(s32 size); HeapNode* _heap_create(void* addr, s32 size); s32 dma_copy(s32 romStart, s32 romEnd, void* vramDest); diff --git a/src/code_197F40.c b/src/code_197F40.c index 29db736be7..9f1a52e929 100644 --- a/src/code_197F40.c +++ b/src/code_197F40.c @@ -1,6 +1,8 @@ #include "common.h" #include "battle/battle.h" +extern s8 D_8029FBD4; + s32 count_targets(Actor* actor, s32 targetHomeIndex, s32 targetSelectionFlags) { BattleStatus* battleStatus = BATTLE_STATUS; @@ -2077,7 +2079,16 @@ ApiStatus EnemyCreateTargetList(ScriptInstance* script, s32 isInitialCall) { return ApiStatus_DONE2; } -INCLUDE_ASM(s32, "code_197F40", InitTargetIterator); +ApiStatus InitTargetIterator(ScriptInstance* script, s32 isInitialCall) { + Bytecode* args = script->ptrReadPos; + Actor* actor = get_actor(script->owner1.actorID); + SelectableTarget* selectableTarget = &actor->targetData[actor->targetIndexList[actor->selectedTargetIndex]]; + + actor->targetActorID = selectableTarget->actorID; + actor->targetPartIndex = selectableTarget->partID; + + return ApiStatus_DONE2; +} INCLUDE_ASM(s32, "code_197F40", SetOwnerTarget); @@ -2147,7 +2158,16 @@ INCLUDE_ASM(s32, "code_197F40", SetBattleVar); INCLUDE_ASM(s32, "code_197F40", GetBattleVar); -INCLUDE_ASM(s32, "code_197F40", ResetAllActorSounds); +ApiStatus ResetAllActorSounds(ScriptInstance* script, s32 isInitialCall) { + ActorID actorID = get_variable(script, *script->ptrReadPos); + + if (actorID == ActorID_SELF) { + actorID = script->owner1.actorID; + } + + reset_all_actor_sounds(get_actor(actorID)); + return ApiStatus_DONE2; +} INCLUDE_ASM(s32, "code_197F40", SetActorSounds); @@ -2157,7 +2177,16 @@ INCLUDE_ASM(s32, "code_197F40", SetPartSounds); INCLUDE_ASM(s32, "code_197F40", SetActorType); -INCLUDE_ASM(s32, "code_197F40", ShowShockEffect); +ApiStatus ShowShockEffect(ScriptInstance* script, s32 isInitialCall) { + ActorID actorID = get_variable(script, *script->ptrReadPos); + + if (actorID == ActorID_SELF) { + actorID = script->owner1.actorID; + } + + func_80251474(get_actor(actorID)); + return ApiStatus_DONE2; +} INCLUDE_ASM(s32, "code_197F40", GetActorAttackBoost); @@ -2173,13 +2202,21 @@ INCLUDE_ASM(s32, "code_197F40", ElectrifyActor); INCLUDE_ASM(s32, "code_197F40", HealActor); -INCLUDE_ASM(s32, "code_197F40", WaitForBuffDone); +ApiStatus WaitForBuffDone(ScriptInstance* script, s32 isInitialCall) { + return (D_8029FBD4 == 0) * ApiStatus_DONE2; +} INCLUDE_ASM(s32, "code_197F40", CopyBuffs); -INCLUDE_ASM(s32, "code_197F40", func_80271210); +ApiStatus func_80271210(ScriptInstance* script, s32 isInitialCall) { + func_80070AF0(0, script->varTable[0], script->varTable[1], script->varTable[2]); + return ApiStatus_DONE2; +} -INCLUDE_ASM(s32, "code_197F40", func_80271258); +ApiStatus func_80271258(ScriptInstance* script, s32 isInitialCall) { + func_80070AF0(1, script->varTable[0], script->varTable[1], script->varTable[2]); + return ApiStatus_DONE2; +} INCLUDE_ASM(s32, "code_197F40", func_802712A0); @@ -2187,7 +2224,10 @@ INCLUDE_ASM(s32, "code_197F40", func_80271328); INCLUDE_ASM(s32, "code_197F40", func_802713B0); -INCLUDE_ASM(s32, "code_197F40", func_8027143C); +ApiStatus func_8027143C(ScriptInstance* script, s32 isInitialCall) { + func_80070A90(0, script->varTable[0], script->varTable[1], script->varTable[2]); + return ApiStatus_DONE2; +} INCLUDE_ASM(s32, "code_197F40", func_80271484); diff --git a/src/os/code_4ac90_len_3910.c b/src/os/code_4ac90_len_3910.c index e5df490a49..2fd30486e4 100644 --- a/src/os/code_4ac90_len_3910.c +++ b/src/os/code_4ac90_len_3910.c @@ -97,9 +97,9 @@ INCLUDE_ASM(s32, "os/code_4ac90_len_3910", func_800709D0); INCLUDE_ASM(s32, "os/code_4ac90_len_3910", func_80070A30); -INCLUDE_ASM(s32, "os/code_4ac90_len_3910", func_80070A90); +INCLUDE_ASM(void, "os/code_4ac90_len_3910", func_80070A90, s32 arg0, f32 arg1, f32 arg2, f32 arg3); -INCLUDE_ASM(s32, "os/code_4ac90_len_3910", func_80070AF0); +INCLUDE_ASM(void, "os/code_4ac90_len_3910", func_80070AF0, s32 arg0, f32 arg1, f32 arg2, f32 arg3); INCLUDE_ASM(s32, "os/code_4ac90_len_3910", func_80070B50); diff --git a/tools/asm_sizes.py b/tools/asm_sizes.py index c77b3bfa39..2e09f285d4 100755 --- a/tools/asm_sizes.py +++ b/tools/asm_sizes.py @@ -40,8 +40,10 @@ asm_dir = script_dir + "/../asm/nonmatchings" for root, dirs, files in os.walk(asm_dir): for asm_dir in dirs: - if "/os" not in root and "/world/" not in root: + if "/os" not in root and "/world/" not in root and "/battle/" not in root: do_dir(root, asm_dir) -for thing in sorted(sizes.keys(), key=lambda x: sizes[x][3]): - print(thing.ljust(25) + str(sizes[thing][3])) +for thing in sorted(sizes.keys(), key=lambda x: sizes[x][2]): + val = sizes[thing][2] + if val > 0: + print(thing.ljust(25) + str(val))