From 22fa63e39382ba0abdde7c761f4c6a149f7b70a3 Mon Sep 17 00:00:00 2001 From: "Nalfein (Kenny)" Date: Wed, 21 Jul 2021 10:37:24 -0400 Subject: [PATCH] Decomp btl_are_all_enemies_defeated (#337) * Initial decomp * Rearrange variable definitions and if-statements * Getting closer to matching * Only address matching left * Rename variables for clarity * Search and replace was too eager... * Rewrite as a for-loop. Matches! * Removed and renamed variables * Rearrange statements for neatness. Remove unneccessary comments * Ran coverage * Change the typing to Actor* * Rename variables, don't be so literal with return values, and compare pointer to NULL, you dunce * Move variable definitions around --- src/190B20.c | 21 ++++++++++++++- .../190B20/btl_are_all_enemies_defeated.s | 26 ------------------- 2 files changed, 20 insertions(+), 27 deletions(-) delete mode 100644 ver/us/asm/nonmatchings/190B20/btl_are_all_enemies_defeated.s diff --git a/src/190B20.c b/src/190B20.c index ed20854034..6ec487a335 100644 --- a/src/190B20.c +++ b/src/190B20.c @@ -1072,7 +1072,26 @@ INCLUDE_ASM(s32, "190B20", func_80263268); INCLUDE_ASM(s32, "190B20", func_80263300); -INCLUDE_ASM(s32, "190B20", btl_are_all_enemies_defeated); +s32 btl_are_all_enemies_defeated(void) { + BattleStatus* battleStatus = &gBattleStatus; + Actor* enemy; + s32 enemiesStillAlive = FALSE; + s32 i; + + for (i = 0; i < ARRAY_COUNT(battleStatus->enemyActors); i++) { + s32 flagEnemyDefeated = 0x404000; + enemy = battleStatus->enemyActors[i]; + + // If currentEnemyFlags signify that the enemy isn't dead yet... + if (enemy != NULL) { + if (!(enemy->flags & flagEnemyDefeated)) { + // Countinue the battle + enemiesStillAlive = TRUE; + } + } + } + return !enemiesStillAlive; +} s32 btl_check_enemies_defeated(void) { if (btl_are_all_enemies_defeated()) { diff --git a/ver/us/asm/nonmatchings/190B20/btl_are_all_enemies_defeated.s b/ver/us/asm/nonmatchings/190B20/btl_are_all_enemies_defeated.s deleted file mode 100644 index 82b36b2a26..0000000000 --- a/ver/us/asm/nonmatchings/190B20/btl_are_all_enemies_defeated.s +++ /dev/null @@ -1,26 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - -glabel btl_are_all_enemies_defeated -/* 191CC8 802633E8 0000282D */ daddu $a1, $zero, $zero -/* 191CCC 802633EC 00A0202D */ daddu $a0, $a1, $zero -/* 191CD0 802633F0 3C060040 */ lui $a2, 0x40 -/* 191CD4 802633F4 34C64000 */ ori $a2, $a2, 0x4000 -/* 191CD8 802633F8 3C03800E */ lui $v1, %hi(gBattleStatus) -/* 191CDC 802633FC 2463C070 */ addiu $v1, $v1, %lo(gBattleStatus) -.L80263400: -/* 191CE0 80263400 8C6200E0 */ lw $v0, 0xe0($v1) -/* 191CE4 80263404 50400006 */ beql $v0, $zero, .L80263420 -/* 191CE8 80263408 24840001 */ addiu $a0, $a0, 1 -/* 191CEC 8026340C 8C420000 */ lw $v0, ($v0) -/* 191CF0 80263410 00461024 */ and $v0, $v0, $a2 -/* 191CF4 80263414 50400001 */ beql $v0, $zero, .L8026341C -/* 191CF8 80263418 24050001 */ addiu $a1, $zero, 1 -.L8026341C: -/* 191CFC 8026341C 24840001 */ addiu $a0, $a0, 1 -.L80263420: -/* 191D00 80263420 28820018 */ slti $v0, $a0, 0x18 -/* 191D04 80263424 1440FFF6 */ bnez $v0, .L80263400 -/* 191D08 80263428 24630004 */ addiu $v1, $v1, 4 -/* 191D0C 8026342C 03E00008 */ jr $ra -/* 191D10 80263430 38A20001 */ xori $v0, $a1, 1