From a70f8aa4e3a4d8084989cccd59df9a5a64d75f35 Mon Sep 17 00:00:00 2001 From: Eebit Date: Sun, 10 Apr 2022 14:24:24 -0400 Subject: [PATCH 1/7] (bmmind) Decompile up to ActionSummonDK --- asm/bmmind.s | 698 -------------------------------------------- include/functions.h | 2 +- include/rng.h | 4 +- ldscript.txt | 1 + src/bmmind.c | 370 +++++++++++++++++++++++ 5 files changed, 374 insertions(+), 701 deletions(-) create mode 100644 src/bmmind.c diff --git a/asm/bmmind.s b/asm/bmmind.s index d2d5298ae..143b4fedc 100644 --- a/asm/bmmind.s +++ b/asm/bmmind.s @@ -4,704 +4,6 @@ @ Unit Action stuff (why "mind"?) - THUMB_FUNC_START StoreRNStateToActionStruct -StoreRNStateToActionStruct: @ 0x08031FEC - push {lr} - ldr r0, _08031FF8 @ gActionData - bl StoreRNState - pop {r0} - bx r0 - .align 2, 0 -_08031FF8: .4byte gActionData - - THUMB_FUNC_END StoreRNStateToActionStruct - - THUMB_FUNC_START LoadRNStateFromActionStruct -LoadRNStateFromActionStruct: @ 0x08031FFC - push {lr} - ldr r0, _08032008 @ gActionData - bl LoadRNState - pop {r0} - bx r0 - .align 2, 0 -_08032008: .4byte gActionData - - THUMB_FUNC_END LoadRNStateFromActionStruct - - THUMB_FUNC_START ApplyUnitAction -ApplyUnitAction: @ 0x0803200C - push {r4, r5, lr} - adds r4, r0, #0 - ldr r5, _08032054 @ gActionData - ldrb r0, [r5, #0xc] - bl GetUnit - ldr r1, _08032058 @ gActiveUnit - str r0, [r1] - ldrb r0, [r5, #0x11] - cmp r0, #2 - bne _0803203C - ldrb r0, [r5, #0xc] - bl GetUnit - ldrb r1, [r5, #0x12] - lsls r1, r1, #1 - adds r0, #0x1e - adds r0, r0, r1 - ldrh r0, [r0] - bl GetItemIndex - cmp r0, #0xa6 - bne _0803203C - b _08032148 -_0803203C: - ldr r0, _08032054 @ gActionData - ldrb r0, [r0, #0x11] - subs r0, #1 - cmp r0, #0x1d - bls _08032048 - b _0803215C -_08032048: - lsls r0, r0, #2 - ldr r1, _0803205C @ _08032060 - adds r0, r0, r1 - ldr r0, [r0] - mov pc, r0 - .align 2, 0 -_08032054: .4byte gActionData -_08032058: .4byte gActiveUnit -_0803205C: .4byte _08032060 -_08032060: @ jump table - .4byte _080320D8 @ case 0 - .4byte _08032104 @ case 1 - .4byte _08032148 @ case 2 - .4byte _0803210C @ case 3 - .4byte _0803215C @ case 4 - .4byte _08032124 @ case 5 - .4byte _0803212C @ case 6 - .4byte _08032134 @ case 7 - .4byte _080320EC @ case 8 - .4byte _080320F4 @ case 9 - .4byte _0803215C @ case 10 - .4byte _0803215C @ case 11 - .4byte _0803215C @ case 12 - .4byte _08032114 @ case 13 - .4byte _0803211C @ case 14 - .4byte _080320FC @ case 15 - .4byte _080320FC @ case 16 - .4byte _08032148 @ case 17 - .4byte _0803215C @ case 18 - .4byte _08032148 @ case 19 - .4byte _08032152 @ case 20 - .4byte _0803215C @ case 21 - .4byte _0803215C @ case 22 - .4byte _0803215C @ case 23 - .4byte _0803213C @ case 24 - .4byte _08032148 @ case 25 - .4byte _0803215C @ case 26 - .4byte _0803215C @ case 27 - .4byte _0803215C @ case 28 - .4byte _080320D8 @ case 29 -_080320D8: - ldr r0, _080320E8 @ gActiveUnit - ldr r2, [r0] - ldr r0, [r2, #0xc] - movs r1, #0x40 - orrs r0, r1 - str r0, [r2, #0xc] - b _0803215C - .align 2, 0 -_080320E8: .4byte gActiveUnit -_080320EC: - adds r0, r4, #0 - bl ActionRescue - b _08032142 -_080320F4: - adds r0, r4, #0 - bl ActionDrop - b _08032142 -_080320FC: - adds r0, r4, #0 - bl ActionVisitAndSieze - b _08032142 -_08032104: - adds r0, r4, #0 - bl ActionCombat - b _08032142 -_0803210C: - adds r0, r4, #0 - bl ActionDance - b _08032142 -_08032114: - adds r0, r4, #0 - bl ActionTalk - b _08032142 -_0803211C: - adds r0, r4, #0 - bl ActionSupport - b _08032142 -_08032124: - adds r0, r4, #0 - bl ActionSteal - b _08032142 -_0803212C: - adds r0, r4, #0 - bl ActionSummon - b _08032142 -_08032134: - adds r0, r4, #0 - bl ActionSummonDK - b _08032142 -_0803213C: - adds r0, r4, #0 - bl ActionArena -_08032142: - lsls r0, r0, #0x18 - asrs r0, r0, #0x18 - b _0803215E -_08032148: - adds r0, r4, #0 - bl ActionStaffDoorChestUseItem - movs r0, #0 - b _0803215E -_08032152: - adds r0, r4, #0 - bl ActionPick - movs r0, #0 - b _0803215E -_0803215C: - movs r0, #1 -_0803215E: - pop {r4, r5} - pop {r1} - bx r1 - - THUMB_FUNC_END ApplyUnitAction - - THUMB_FUNC_START ActionRescue -ActionRescue: @ 0x08032164 - push {r4, r5, r6, lr} - adds r6, r0, #0 - ldr r4, _080321B4 @ gActionData - ldrb r0, [r4, #0xc] - bl GetUnit - adds r5, r0, #0 - ldrb r0, [r4, #0xd] - bl GetUnit - adds r4, r0, #0 - bl TryRemoveUnitFromBallista - movs r0, #0x10 - ldrsb r0, [r5, r0] - movs r1, #0x11 - ldrsb r1, [r5, r1] - movs r2, #0x10 - ldrsb r2, [r4, r2] - movs r3, #0x11 - ldrsb r3, [r4, r3] - bl GetSomeFacingDirection - adds r1, r0, #0 - adds r0, r4, #0 - movs r2, #0 - adds r3, r6, #0 - bl Make6CKOIDO - adds r0, r5, #0 - adds r1, r4, #0 - bl UnitRescue - adds r0, r4, #0 - bl HideUnitSMS - movs r0, #0 - pop {r4, r5, r6} - pop {r1} - bx r1 - .align 2, 0 -_080321B4: .4byte gActionData - - THUMB_FUNC_END ActionRescue - - THUMB_FUNC_START sub_80321B8 -sub_80321B8: @ 0x080321B8 - push {lr} - ldr r1, [r0, #0x54] - bl sub_80377F0 - lsls r0, r0, #0x18 - asrs r0, r0, #0x18 - pop {r1} - bx r1 - - THUMB_FUNC_END sub_80321B8 - - THUMB_FUNC_START sub_80321C8 -sub_80321C8: @ 0x080321C8 - push {lr} - bl RefreshEntityBmMaps - bl RenderBmMap - bl SMS_UpdateFromGameData - bl SMS_FlushIndirect - pop {r1} - bx r1 - - THUMB_FUNC_END sub_80321C8 - - THUMB_FUNC_START ActionDrop -ActionDrop: @ 0x080321E0 - push {r4, r5, r6, lr} - adds r6, r0, #0 - ldr r4, _08032248 @ gActionData - ldrb r0, [r4, #0xd] - bl GetUnit - adds r5, r0, #0 - ldrb r0, [r4, #0x14] - ldr r1, _0803224C @ gBmMapHidden - ldr r1, [r1] - lsls r0, r0, #2 - adds r0, r0, r1 - ldrb r1, [r4, #0x13] - ldr r0, [r0] - adds r0, r0, r1 - ldrb r1, [r0] - movs r0, #1 - ands r0, r1 - cmp r0, #0 - bne _08032254 - ldrb r0, [r4, #0xc] - bl GetUnit - bl UnitFinalizeMovement - ldrb r0, [r4, #0x13] - ldrb r1, [r4, #0x14] - movs r2, #0x10 - ldrsb r2, [r5, r2] - movs r3, #0x11 - ldrsb r3, [r5, r3] - bl GetSomeFacingDirection - adds r1, r0, #0 - adds r0, r5, #0 - movs r2, #2 - adds r3, r6, #0 - bl Make6CKOIDO - ldrb r0, [r4, #0xc] - bl GetUnit - ldrb r1, [r4, #0x13] - ldrb r2, [r4, #0x14] - bl UnitDrop - ldr r0, _08032250 @ gUnknown_0859DA6C - adds r1, r6, #0 - bl Proc_StartBlocking - str r5, [r0, #0x54] - b _08032262 - .align 2, 0 -_08032248: .4byte gActionData -_0803224C: .4byte gBmMapHidden -_08032250: .4byte gUnknown_0859DA6C -_08032254: - ldr r0, _0803226C @ gWorkingMovementScript - movs r1, #0xa - strb r1, [r0] - movs r1, #4 - strb r1, [r0, #1] - bl MU_StartMoveScript_Auto -_08032262: - movs r0, #0 - pop {r4, r5, r6} - pop {r1} - bx r1 - .align 2, 0 -_0803226C: .4byte gWorkingMovementScript - - THUMB_FUNC_END ActionDrop - - THUMB_FUNC_START ActionVisitAndSieze -ActionVisitAndSieze: @ 0x08032270 - push {r4, r5, lr} - ldr r5, _08032298 @ gActionData - ldrb r0, [r5, #0xc] - bl GetUnit - movs r4, #0x10 - ldrsb r4, [r0, r4] - ldrb r0, [r5, #0xc] - bl GetUnit - movs r1, #0x11 - ldrsb r1, [r0, r1] - adds r0, r4, #0 - bl sub_80840C4 - movs r0, #0 - pop {r4, r5} - pop {r1} - bx r1 - .align 2, 0 -_08032298: .4byte gActionData - - THUMB_FUNC_END ActionVisitAndSieze - - THUMB_FUNC_START ActionCombat -ActionCombat: @ 0x0803229C - push {r4, r5, r6, r7, lr} - adds r7, r0, #0 - ldr r4, _0803231C @ gActionData - ldrb r0, [r4, #0xd] - bl GetUnit - adds r6, r0, #0 - ldrb r0, [r4, #0xc] - bl GetUnit - ldrb r1, [r4, #0x12] - lsls r1, r1, #1 - adds r0, #0x1e - adds r0, r0, r1 - ldrh r0, [r0] - bl GetItemIndex - ldr r1, _08032320 @ gBattleActor - adds r1, #0x7e - movs r2, #0 - strb r2, [r1] - cmp r0, #0xa6 - bne _080322FC - ldrb r0, [r4, #0xc] - bl GetUnit - bl MakeTargetListForFuckingNightmare - bl sub_804FD28 - adds r5, r0, #0 - movs r4, #0 - cmp r4, r5 - bge _080322FC -_080322E0: - adds r0, r4, #0 - bl GetTarget - ldrb r0, [r0, #2] - lsls r0, r0, #0x18 - asrs r0, r0, #0x18 - bl GetUnit - movs r1, #2 - bl SetUnitStatus - adds r4, #1 - cmp r4, r5 - blt _080322E0 -_080322FC: - cmp r6, #0 - bne _08032304 - bl InitObstacleBattleUnit -_08032304: - ldr r1, _0803231C @ gActionData - ldrb r0, [r1, #0x12] - cmp r0, #8 - bne _08032324 - ldrb r0, [r1, #0xc] - bl GetUnit - adds r1, r6, #0 - bl BattleGenerateBallistaReal - b _08032330 - .align 2, 0 -_0803231C: .4byte gActionData -_08032320: .4byte gBattleActor -_08032324: - ldrb r0, [r1, #0xc] - bl GetUnit - adds r1, r6, #0 - bl BattleGenerateReal -_08032330: - ldr r0, _08032340 @ gUnknown_0859DABC - adds r1, r7, #0 - bl Proc_StartBlocking - movs r0, #0 - pop {r4, r5, r6, r7} - pop {r1} - bx r1 - .align 2, 0 -_08032340: .4byte gUnknown_0859DABC - - THUMB_FUNC_END ActionCombat - - THUMB_FUNC_START ActionArena -ActionArena: @ 0x08032344 - push {lr} - adds r1, r0, #0 - ldr r0, _08032354 @ gUnknown_0859DB24 - bl Proc_StartBlocking - movs r0, #0 - pop {r1} - bx r1 - .align 2, 0 -_08032354: .4byte gUnknown_0859DB24 - - THUMB_FUNC_END ActionArena - - THUMB_FUNC_START ActionDance -ActionDance: @ 0x08032358 - push {r4, r5, lr} - adds r5, r0, #0 - ldr r4, _0803239C @ gActionData - ldrb r0, [r4, #0xd] - bl GetUnit - ldr r1, [r0, #0xc] - ldr r2, _080323A0 @ 0xFFFFFBBD - ands r1, r2 - str r1, [r0, #0xc] - ldrb r0, [r4, #0xc] - bl GetUnit - movs r1, #1 - negs r1, r1 - bl BattleInitItemEffect - ldrb r0, [r4, #0xd] - bl GetUnit - bl BattleInitItemEffectTarget - ldr r1, _080323A4 @ gBattleStats - movs r0, #0x40 - strh r0, [r1] - adds r0, r5, #0 - bl BattleApplyMiscAction - bl BeginBattleAnimations - movs r0, #0 - pop {r4, r5} - pop {r1} - bx r1 - .align 2, 0 -_0803239C: .4byte gActionData -_080323A0: .4byte 0xFFFFFBBD -_080323A4: .4byte gBattleStats - - THUMB_FUNC_END ActionDance - - THUMB_FUNC_START ActionTalk -ActionTalk: @ 0x080323A8 - push {r4, r5, lr} - ldr r4, _080323D0 @ gActionData - ldrb r0, [r4, #0xc] - bl GetUnit - ldr r0, [r0] - ldrb r5, [r0, #4] - ldrb r0, [r4, #0xd] - bl GetUnit - ldr r0, [r0] - ldrb r1, [r0, #4] - adds r0, r5, #0 - bl sub_8083FB0 - movs r0, #0 - pop {r4, r5} - pop {r1} - bx r1 - .align 2, 0 -_080323D0: .4byte gActionData - - THUMB_FUNC_END ActionTalk - - THUMB_FUNC_START ActionSupport -ActionSupport: @ 0x080323D4 - push {r4, r5, r6, r7, lr} - mov r7, r9 - mov r6, r8 - push {r6, r7} - ldr r0, _08032474 @ gActionData - ldrb r0, [r0, #0xd] - bl GetUnit - adds r4, r0, #0 - ldr r0, _08032478 @ gActiveUnit - mov r9, r0 - ldr r0, [r0] - ldr r1, [r4] - ldrb r1, [r1, #4] - bl GetUnitSupporterNum - adds r7, r0, #0 - mov r1, r9 - ldr r0, [r1] - ldr r0, [r0] - ldrb r1, [r0, #4] - adds r0, r4, #0 - bl GetUnitSupporterNum - mov r8, r0 - adds r0, r4, #0 - mov r1, r8 - bl CanUnitSupportNow - mov r2, r9 - ldr r0, [r2] - adds r1, r7, #0 - bl UnitGainSupportLevel - adds r0, r4, #0 - mov r1, r8 - bl UnitGainSupportLevel - mov r1, r9 - ldr r0, [r1] - ldr r1, [r0] - ldrb r6, [r1, #4] - ldr r1, [r4] - ldrb r5, [r1, #4] - adds r1, r7, #0 - bl GetUnitSupportLevel - adds r2, r0, #0 - adds r0, r6, #0 - adds r1, r5, #0 - bl sub_808371C - mov r2, r9 - ldr r0, [r2] - adds r0, #0x32 - adds r0, r0, r7 - ldrb r0, [r0] - adds r4, #0x32 - add r4, r8 - ldrb r1, [r4] - cmp r0, r1 - beq _08032464 - cmp r0, r1 - ble _08032456 - strb r0, [r4] -_08032456: - cmp r0, r1 - bge _08032464 - mov r2, r9 - ldr r0, [r2] - adds r0, #0x32 - adds r0, r0, r7 - strb r1, [r0] -_08032464: - movs r0, #0 - pop {r3, r4} - mov r8, r3 - mov r9, r4 - pop {r4, r5, r6, r7} - pop {r1} - bx r1 - .align 2, 0 -_08032474: .4byte gActionData -_08032478: .4byte gActiveUnit - - THUMB_FUNC_END ActionSupport - - THUMB_FUNC_START ActionSteal -ActionSteal: @ 0x0803247C - push {r4, r5, r6, r7, lr} - adds r7, r0, #0 - ldr r4, _080324F4 @ gActionData - ldrb r0, [r4, #0xd] - bl GetUnit - adds r5, r0, #0 - ldr r0, [r5, #0xc] - movs r1, #0x80 - lsls r1, r1, #5 - ands r0, r1 - cmp r0, #0 - beq _080324AC - ldrb r4, [r4, #0x12] - adds r0, r5, #0 - bl GetUnitItemCount - subs r0, #1 - cmp r4, r0 - bne _080324AC - ldr r0, [r5, #0xc] - ldr r1, _080324F8 @ 0xFFFFEFFF - ands r0, r1 - str r0, [r5, #0xc] -_080324AC: - ldr r4, _080324F4 @ gActionData - ldrb r0, [r4, #0xd] - bl GetUnit - ldrb r1, [r4, #0x12] - lsls r1, r1, #1 - adds r0, #0x1e - adds r0, r0, r1 - ldrh r6, [r0] - ldrb r0, [r4, #0xd] - bl GetUnit - ldrb r1, [r4, #0x12] - bl UnitRemoveItem - movs r0, #0xff - ands r0, r6 - cmp r0, #0x9a - blt _080324FC - cmp r0, #0xa0 - ble _080324DE - cmp r0, #0xb9 - bgt _080324FC - cmp r0, #0xb8 - blt _080324FC -_080324DE: - bl GetPartyGoldAmount - adds r4, r0, #0 - adds r0, r6, #0 - bl GetItemCost - adds r4, r4, r0 - adds r0, r4, #0 - bl SetPartyGoldAmount - b _0803250A - .align 2, 0 -_080324F4: .4byte gActionData -_080324F8: .4byte 0xFFFFEFFF -_080324FC: - ldr r0, _0803254C @ gActionData - ldrb r0, [r0, #0xc] - bl GetUnit - adds r1, r6, #0 - bl UnitAddItem -_0803250A: - ldr r5, _0803254C @ gActionData - ldrb r0, [r5, #0xc] - bl GetUnit - movs r1, #1 - negs r1, r1 - bl BattleInitItemEffect - ldr r4, _08032550 @ gBattleTarget - adds r1, r4, #0 - adds r1, #0x55 - movs r0, #1 - strb r0, [r1] - ldrb r0, [r5, #0xd] - bl GetUnit - adds r1, r0, #0 - adds r0, r4, #0 - bl InitBattleUnit - adds r4, #0x48 - strh r6, [r4] - adds r0, r7, #0 - bl BattleApplyMiscAction - bl MU_EndAll - bl BeginMapAnimForSteal - movs r0, #0 - pop {r4, r5, r6, r7} - pop {r1} - bx r1 - .align 2, 0 -_0803254C: .4byte gActionData -_08032550: .4byte gBattleTarget - - THUMB_FUNC_END ActionSteal - - THUMB_FUNC_START ActionSummon -ActionSummon: @ 0x08032554 - push {r4, lr} - adds r4, r0, #0 - ldr r0, _08032578 @ gBattleActor - ldr r1, _0803257C @ gActiveUnit - ldr r1, [r1] - bl InitBattleUnit - adds r0, r4, #0 - bl BattleApplyMiscAction - bl MU_EndAll - bl BeginMapAnimForSummon - movs r0, #0 - pop {r4} - pop {r1} - bx r1 - .align 2, 0 -_08032578: .4byte gBattleActor -_0803257C: .4byte gActiveUnit - - THUMB_FUNC_END ActionSummon - - THUMB_FUNC_START ActionSummonDK -ActionSummonDK: @ 0x08032580 - push {r4, lr} - adds r4, r0, #0 - ldr r0, _080325A4 @ gBattleActor - ldr r1, _080325A8 @ gActiveUnit - ldr r1, [r1] - bl InitBattleUnit - adds r0, r4, #0 - bl BattleApplyMiscAction - bl MU_EndAll - bl BeginMapAnimForSummonDK - movs r0, #0 - pop {r4} - pop {r1} - bx r1 - .align 2, 0 -_080325A4: .4byte gBattleActor -_080325A8: .4byte gActiveUnit - - THUMB_FUNC_END ActionSummonDK - THUMB_FUNC_START sub_80325AC sub_80325AC: @ 0x080325AC push {r4, r5, r6, r7, lr} diff --git a/include/functions.h b/include/functions.h index 5d1b4f9bd..b852d853a 100644 --- a/include/functions.h +++ b/include/functions.h @@ -1250,7 +1250,7 @@ void ChangeActiveUnitFacing(int xLook, int yLook); // ??? sub_8024CE0(???); // ??? GetPhaseAbleUnitCount(???); u32 GetPartyGoldAmount(void); -// ??? SetPartyGoldAmount(???); +void SetPartyGoldAmount(s32); // ??? sub_8024E20(???); // ??? sub_8024E40(???); // ??? ForEachUnitInRange(???); diff --git a/include/rng.h b/include/rng.h index e74d6a30b..8f4a46454 100644 --- a/include/rng.h +++ b/include/rng.h @@ -4,8 +4,8 @@ // rng.c // ??? NextRN(???); void InitRN(s32 unk1); -// ??? LoadRNState(???); -// ??? StoreRNState(???); +void StoreRNState(u16* seeds); +void LoadRNState(const u16* seeds); int NextRN_100(void); int NextRN_N(int max); s8 Roll1RN(int threshold); diff --git a/ldscript.txt b/ldscript.txt index 9a2f1f661..24ae5199b 100644 --- a/ldscript.txt +++ b/ldscript.txt @@ -97,6 +97,7 @@ SECTIONS src/bmcontainer.o(.text); asm/bmusort.o(.text); asm/bmarena.o(.text); + src/bmmind.o(.text); asm/bmmind.o(.text); src/bmpatharrowdisp.o(.text); src/sallycursor.o(.text); diff --git a/src/bmmind.c b/src/bmmind.c new file mode 100644 index 000000000..08e55fe63 --- /dev/null +++ b/src/bmmind.c @@ -0,0 +1,370 @@ +#include "global.h" + +#include "proc.h" +#include "rng.h" +#include "bmunit.h" +#include "bmitem.h" +#include "bmmap.h" +#include "mu.h" +#include "mapselect.h" +#include "bmbattle.h" +#include "bmreliance.h" +#include "constants/items.h" +#include "constants/terrains.h" + +struct UnknownBMMindProc { + /* 00 */ PROC_HEADER; + + /* 29 */ u8 unk_29[0x54-0x29]; + + /* 54 */ struct Unit* unk_54; + +}; + +extern struct ProcCmd CONST_DATA gUnknown_0859DA6C[]; +extern struct ProcCmd CONST_DATA gUnknown_0859DABC[]; +extern struct ProcCmd CONST_DATA gUnknown_0859DB24[]; + +// koido.s +void Make6CKOIDO(struct Unit*, int, u8, ProcPtr); +int GetSomeFacingDirection(int, int, int, int); + +// bmtrap.s +s8 sub_80377F0(ProcPtr, struct Unit*); + +// ev_triggercheck.s +void sub_808371C(u8, u8, int); +void sub_8083FB0(u8, u8); +void sub_80840C4(int, int); + +// ui_targetselection.s +struct SelectTarget* GetTarget(int index); + +// bmtarget.s +void MakeTargetListForFuckingNightmare(struct Unit*); + +// code_mapanim.s +void BeginMapAnimForSteal(void); +void BeginMapAnimForSummon(void); +void BeginMapAnimForSummonDK(void); + +s8 ActionRescue(ProcPtr); +s8 ActionDrop(ProcPtr); +s8 ActionVisitAndSieze(ProcPtr); +s8 ActionCombat(ProcPtr); +s8 ActionDance(ProcPtr); +s8 ActionTalk(ProcPtr); +s8 ActionSupport(ProcPtr); +s8 ActionSteal(ProcPtr); +s8 ActionSummon(ProcPtr); +s8 ActionSummonDK(ProcPtr); +s8 ActionArena(ProcPtr); +s8 ActionStaffDoorChestUseItem(ProcPtr); +s8 ActionPick(ProcPtr); + +void StoreRNStateToActionStruct() { + StoreRNState(gActionData._u00); + return; +} + +void LoadRNStateFromActionStruct() { + LoadRNState(gActionData._u00); + return; +} + +unsigned int ApplyUnitAction(ProcPtr proc) { + gActiveUnit = GetUnit(gActionData.subjectIndex); + + if (gActionData.unitActionType == UNIT_ACTION_COMBAT) { // UNIT_ACTION_STAFF = 2, UNIT_ACTION_COMBAT = 1 + int itemIdx = GetItemIndex( + GetUnit(gActionData.subjectIndex)->items[gActionData.itemSlotIndex] + ); + + if (itemIdx == ITEM_NIGHTMARE) { + ActionStaffDoorChestUseItem(proc); + return 0; + } + } + + switch (gActionData.unitActionType) { + case UNIT_ACTION_WAIT: + case UNIT_ACTION_TRAPPED: + gActiveUnit->state |= US_HAS_MOVED; + return 1; + case UNIT_ACTION_RESCUE: + return ActionRescue(proc); + case UNIT_ACTION_DROP: + return ActionDrop(proc); + case UNIT_ACTION_VISIT: + case UNIT_ACTION_SEIZE: + return ActionVisitAndSieze(proc); + case UNIT_ACTION_COMBAT: + return ActionCombat(proc); + case UNIT_ACTION_DANCE: + return ActionDance(proc); + case UNIT_ACTION_TALK: + return ActionTalk(proc); + case UNIT_ACTION_SUPPORT: + return ActionSupport(proc); + case UNIT_ACTION_STEAL: + return ActionSteal(proc); + case UNIT_ACTION_SUMMON: + return ActionSummon(proc); + case UNIT_ACTION_SUMMON_DK: + return ActionSummonDK(proc); + case UNIT_ACTION_ARENA: + return ActionArena(proc); + case UNIT_ACTION_STAFF: + case UNIT_ACTION_DOOR: + case UNIT_ACTION_CHEST: + case UNIT_ACTION_USE_ITEM: + ActionStaffDoorChestUseItem(proc); + return 0; + case UNIT_ACTION_PICK: + ActionPick(proc); + return 0; + default: + return 1; + } +} + +s8 ActionRescue(ProcPtr proc) { + struct Unit* subject = GetUnit(gActionData.subjectIndex); + struct Unit* target = GetUnit(gActionData.targetIndex); + + TryRemoveUnitFromBallista(target); + + Make6CKOIDO( + target, + GetSomeFacingDirection(subject->xPos, subject->yPos, target->xPos, target->yPos), + 0, + proc + ); + + UnitRescue(subject, target); + HideUnitSMS(target); + + return 0; +} + +int sub_80321B8(struct UnknownBMMindProc* proc) { + return sub_80377F0(proc, proc->unk_54); +} + +int sub_80321C8() { + RefreshEntityBmMaps(); + RenderBmMap(); + SMS_UpdateFromGameData(); + SMS_FlushIndirect(); + + // return; // BUG? +} + +s8 ActionDrop(ProcPtr proc) { + struct Unit* target = GetUnit(gActionData.targetIndex); + ProcPtr child; + + if ((1 & gBmMapHidden[gActionData.yOther][gActionData.xOther])) { + gWorkingMovementScript[0] = 0xA; + gWorkingMovementScript[1] = 4; + MU_StartMoveScript_Auto(gWorkingMovementScript); + return 0; + } + + UnitFinalizeMovement(GetUnit(gActionData.subjectIndex)); + + Make6CKOIDO( + target, + GetSomeFacingDirection(gActionData.xOther, gActionData.yOther, target->xPos, target->yPos), + 2, + proc + ); + + UnitDrop( + GetUnit(gActionData.subjectIndex), + gActionData.xOther, + gActionData.yOther + ); + + child = Proc_StartBlocking(gUnknown_0859DA6C, proc); + ((struct UnknownBMMindProc*)(child))->unk_54 = target; + + return 0; +} + +// TODO: Fake match - register allocation prefers r5 without the register keyword +s8 ActionVisitAndSieze(ProcPtr proc) { + register int x asm("r4"); + int y; + + x = GetUnit(gActionData.subjectIndex)->xPos; + y = GetUnit(gActionData.subjectIndex)->yPos; + + sub_80840C4(x, y); + + return 0; +} + +s8 ActionCombat(ProcPtr proc) { + struct Unit* target = GetUnit(gActionData.targetIndex); + + int itemIdx = GetItemIndex( + GetUnit(gActionData.subjectIndex)->items[gActionData.itemSlotIndex] + ); + + gBattleActor.hasItemEffectTarget = 0; + + if (itemIdx == ITEM_NIGHTMARE) { + int i, targetCount; + + MakeTargetListForFuckingNightmare(GetUnit(gActionData.subjectIndex)); + targetCount = sub_804FD28(); + + for (i = 0; i < targetCount; i++) { + SetUnitStatus( + GetUnit(GetTarget(i)->uid), + UNIT_STATUS_SLEEP + ); + } + } + + if (target == 0) { + InitObstacleBattleUnit(); + } + + if (gActionData.itemSlotIndex == 8) { + BattleGenerateBallistaReal(GetUnit(gActionData.subjectIndex), target); + } else { + BattleGenerateReal(GetUnit(gActionData.subjectIndex), target); + } + + Proc_StartBlocking(gUnknown_0859DABC, proc); + + return 0; +} + +s8 ActionArena(ProcPtr proc) { + Proc_StartBlocking(gUnknown_0859DB24, proc); + return 0; +} + +s8 ActionDance(ProcPtr proc) { + GetUnit(gActionData.targetIndex)->state &= ~( US_UNSELECTABLE | US_HAS_MOVED | US_HAS_MOVED_AI ); + + BattleInitItemEffect(GetUnit(gActionData.subjectIndex), -1); + BattleInitItemEffectTarget(GetUnit(gActionData.targetIndex)); + + gBattleStats.config = 0x40; + + BattleApplyMiscAction(proc); + BeginBattleAnimations(); + + return 0; +} + +s8 ActionTalk(ProcPtr proc) { + sub_8083FB0( + GetUnit(gActionData.subjectIndex)->pCharacterData->number, + GetUnit(gActionData.targetIndex)->pCharacterData->number + ); + + return 0; +} + +s8 ActionSupport(ProcPtr proc) { + int subjectExp, targetExp; + + struct Unit* target = GetUnit(gActionData.targetIndex); + + int targetSupportNum = GetUnitSupporterNum(gActiveUnit, target->pCharacterData->number); + int subjectSupportNum = GetUnitSupporterNum(target, gActiveUnit->pCharacterData->number); + + CanUnitSupportNow(target, subjectSupportNum); + + UnitGainSupportLevel(gActiveUnit, targetSupportNum); + UnitGainSupportLevel(target, subjectSupportNum); + + sub_808371C( + gActiveUnit->pCharacterData->number, + target->pCharacterData->number, + GetUnitSupportLevel(gActiveUnit, targetSupportNum) + ); + + subjectExp = gActiveUnit->supports[targetSupportNum]; + targetExp = target->supports[subjectSupportNum]; + + if (subjectExp != targetExp) { + if (subjectExp > targetExp) { + target->supports[subjectSupportNum] = subjectExp; + } + + if (subjectExp < targetExp) { + gActiveUnit->supports[targetSupportNum] = targetExp; + } + } + + return 0; +} + +s8 ActionSteal(ProcPtr proc) { + int itemIdx; + struct Unit* target = GetUnit(gActionData.targetIndex); + + if ((target->state & US_DROP_ITEM)) { + if (gActionData.itemSlotIndex == (GetUnitItemCount(target) - 1)) { + target->state &= ~US_DROP_ITEM; + } + } + + itemIdx = GetUnit(gActionData.targetIndex)->items[gActionData.itemSlotIndex]; + + UnitRemoveItem(GetUnit(gActionData.targetIndex), gActionData.itemSlotIndex); + + switch (0xFF & itemIdx) { + case ITEM_1G: + case ITEM_5G: + case ITEM_10G: + case ITEM_50G: + case ITEM_100G: + case ITEM_150G: + case ITEM_200G: + case ITEM_3000G: + case ITEM_5000G: + SetPartyGoldAmount(GetPartyGoldAmount() + GetItemCost(itemIdx)); + break; + default: + UnitAddItem(GetUnit(gActionData.subjectIndex), itemIdx); + break; + } + + BattleInitItemEffect(GetUnit(gActionData.subjectIndex), -1); + gBattleTarget.terrainId = TERRAIN_PLAINS; + InitBattleUnit(&gBattleTarget, GetUnit(gActionData.targetIndex)); + gBattleTarget.weapon = itemIdx; + BattleApplyMiscAction(proc); + + MU_EndAll(); + BeginMapAnimForSteal(); + + return 0; +} + +s8 ActionSummon(ProcPtr proc) { + InitBattleUnit(&gBattleActor, gActiveUnit); + + BattleApplyMiscAction(proc); + MU_EndAll(); + BeginMapAnimForSummon(); + + return 0; +} + +s8 ActionSummonDK(ProcPtr proc) { + InitBattleUnit(&gBattleActor, gActiveUnit); + + BattleApplyMiscAction(proc); + MU_EndAll(); + BeginMapAnimForSummonDK(); + + return 0; +} \ No newline at end of file From 65f660eecfe8d23de5928d398f971dfa0c389732 Mon Sep 17 00:00:00 2001 From: Eebit Date: Sun, 10 Apr 2022 14:43:25 -0400 Subject: [PATCH 2/7] (bmmind) Decompile functions related to death drop --- asm/bmmind.s | 192 --------------------------------------------------- src/bmmind.c | 97 +++++++++++++++++++++++++- 2 files changed, 96 insertions(+), 193 deletions(-) diff --git a/asm/bmmind.s b/asm/bmmind.s index 143b4fedc..e2ba76e39 100644 --- a/asm/bmmind.s +++ b/asm/bmmind.s @@ -4,198 +4,6 @@ @ Unit Action stuff (why "mind"?) - THUMB_FUNC_START sub_80325AC -sub_80325AC: @ 0x080325AC - push {r4, r5, r6, r7, lr} - mov r7, r8 - push {r7} - sub sp, #4 - adds r6, r0, #0 - movs r0, #0x38 - ldrsh r1, [r6, r0] - movs r3, #0x3c - ldrsh r2, [r6, r3] - adds r7, r6, #0 - adds r7, #0x46 - movs r4, #0 - ldrsh r3, [r7, r4] - adds r5, r6, #0 - adds r5, #0x48 - movs r4, #0 - ldrsh r0, [r5, r4] - str r0, [sp] - movs r0, #0 - bl sub_8012DCC - mov r8, r0 - movs r0, #0x3a - ldrsh r1, [r6, r0] - movs r3, #0x3e - ldrsh r2, [r6, r3] - movs r4, #0 - ldrsh r3, [r7, r4] - movs r4, #0 - ldrsh r0, [r5, r4] - str r0, [sp] - movs r0, #0 - bl sub_8012DCC - adds r2, r0, #0 - adds r1, r6, #0 - adds r1, #0x40 - movs r3, #0 - ldrsh r0, [r1, r3] - adds r2, r2, r0 - adds r3, r6, #0 - adds r3, #0x42 - ldrh r0, [r3] - ldrh r4, [r1] - adds r0, r0, r4 - strh r0, [r1] - adds r0, r6, #0 - adds r0, #0x44 - ldrh r0, [r0] - ldrh r1, [r3] - adds r0, r0, r1 - strh r0, [r3] - ldr r1, _08032654 @ gUnknown_0202BCB0 - movs r3, #0xc - ldrsh r0, [r1, r3] - mov r3, r8 - subs r4, r3, r0 - movs r3, #0xe - ldrsh r0, [r1, r3] - subs r2, r2, r0 - ldr r3, [r6, #0x2c] - movs r0, #7 - adds r1, r4, #0 - bl sub_8027B60 - ldrh r0, [r7] - adds r0, #1 - strh r0, [r7] - lsls r0, r0, #0x10 - asrs r0, r0, #0x10 - movs r4, #0 - ldrsh r1, [r5, r4] - cmp r0, r1 - bne _08032646 - adds r0, r6, #0 - bl Proc_Break -_08032646: - add sp, #4 - pop {r3} - mov r8, r3 - pop {r4, r5, r6, r7} - pop {r0} - bx r0 - .align 2, 0 -_08032654: .4byte gUnknown_0202BCB0 - - THUMB_FUNC_END sub_80325AC - - THUMB_FUNC_START sub_8032658 -sub_8032658: @ 0x08032658 - push {lr} - ldr r1, [r0, #0x2c] - bl sub_8037830 - pop {r0} - bx r0 - - THUMB_FUNC_END sub_8032658 - - THUMB_FUNC_START sub_8032664 -sub_8032664: @ 0x08032664 - push {lr} - bl RefreshEntityBmMaps - bl SMS_UpdateFromGameData - pop {r0} - bx r0 - - THUMB_FUNC_END sub_8032664 - - THUMB_FUNC_START sub_8032674 -sub_8032674: @ 0x08032674 - push {r4, r5, r6, lr} - adds r4, r0, #0 - adds r5, r1, #0 - adds r0, r5, #0 - bl GetUnitCurrentHp - adds r6, r0, #0 - cmp r6, #0 - bne _08032716 - ldr r0, [r5, #0xc] - movs r1, #0x10 - ands r0, r1 - cmp r0, #0 - beq _08032716 - ldr r0, _0803271C @ gUnknown_0859DA94 - adds r1, r4, #0 - bl Proc_StartBlocking - adds r4, r0, #0 - ldrb r0, [r5, #0x1b] - bl GetUnit - str r0, [r4, #0x2c] - adds r1, r4, #0 - adds r1, #0x30 - adds r2, r4, #0 - adds r2, #0x34 - adds r0, r5, #0 - bl UnitGetDeathDropLocation - ldr r1, [r4, #0x30] - ldr r2, [r4, #0x34] - adds r0, r5, #0 - bl UnitDrop - movs r0, #0x10 - ldrsb r0, [r5, r0] - lsls r0, r0, #4 - strh r0, [r4, #0x38] - movs r0, #0x11 - ldrsb r0, [r5, r0] - lsls r0, r0, #4 - strh r0, [r4, #0x3a] - ldr r0, [r4, #0x30] - lsls r0, r0, #4 - strh r0, [r4, #0x3c] - ldr r0, [r4, #0x34] - lsls r0, r0, #4 - strh r0, [r4, #0x3e] - adds r0, r4, #0 - adds r0, #0x40 - strh r6, [r0] - adds r1, r4, #0 - adds r1, #0x42 - ldr r0, _08032720 @ 0x0000FFFB - strh r0, [r1] - adds r1, #2 - movs r0, #1 - strh r0, [r1] - adds r0, r4, #0 - adds r0, #0x46 - strh r6, [r0] - adds r1, #4 - movs r0, #0xb - strh r0, [r1] - ldr r0, [r4, #0x2c] - bl GetUnitSMSId - bl SMS_RegisterUsage - bl SMS_FlushIndirect - ldr r0, _08032724 @ gRAMChapterData - adds r0, #0x41 - ldrb r0, [r0] - lsls r0, r0, #0x1e - cmp r0, #0 - blt _08032716 - movs r0, #0xac - bl m4aSongNumStart -_08032716: - pop {r4, r5, r6} - pop {r0} - bx r0 - .align 2, 0 -_0803271C: .4byte gUnknown_0859DA94 -_08032720: .4byte 0x0000FFFB -_08032724: .4byte gRAMChapterData - - THUMB_FUNC_END sub_8032674 - THUMB_FUNC_START sub_8032728 sub_8032728: @ 0x08032728 push {r4, r5, lr} diff --git a/src/bmmind.c b/src/bmmind.c index 08e55fe63..7c694a2bb 100644 --- a/src/bmmind.c +++ b/src/bmmind.c @@ -9,6 +9,9 @@ #include "mapselect.h" #include "bmbattle.h" #include "bmreliance.h" +#include "m4a.h" +#include "soundwrapper.h" + #include "constants/items.h" #include "constants/terrains.h" @@ -21,7 +24,22 @@ struct UnknownBMMindProc { }; +struct DeathDropAnimProc { + /* 00 */ PROC_HEADER; + + /* 2C */ struct Unit* unit; + /* 30 */ int xDrop, yDrop; + /* 38 */ short xFrom, yFrom; + /* 3C */ short xTo, yTo; + /* 40 */ short yOffset; + /* 42 */ short ySpeed; + /* 44 */ short yAccel; + /* 46 */ short clock; + /* 48 */ short clockEnd; +}; + extern struct ProcCmd CONST_DATA gUnknown_0859DA6C[]; +extern struct ProcCmd CONST_DATA gUnknown_0859DA94[]; extern struct ProcCmd CONST_DATA gUnknown_0859DABC[]; extern struct ProcCmd CONST_DATA gUnknown_0859DB24[]; @@ -31,6 +49,7 @@ int GetSomeFacingDirection(int, int, int, int); // bmtrap.s s8 sub_80377F0(ProcPtr, struct Unit*); +void sub_8037830(ProcPtr, struct Unit*); // ev_triggercheck.s void sub_808371C(u8, u8, int); @@ -48,6 +67,10 @@ void BeginMapAnimForSteal(void); void BeginMapAnimForSummon(void); void BeginMapAnimForSummonDK(void); +// bmudisp.s +void SMS_RegisterUsage(int); +void sub_8027B60(int, int, int, struct Unit*); + s8 ActionRescue(ProcPtr); s8 ActionDrop(ProcPtr); s8 ActionVisitAndSieze(ProcPtr); @@ -367,4 +390,76 @@ s8 ActionSummonDK(ProcPtr proc) { BeginMapAnimForSummonDK(); return 0; -} \ No newline at end of file +} + +void sub_80325AC(struct DeathDropAnimProc* proc) { + int x = sub_8012DCC(0, proc->xFrom, proc->xTo, proc->clock, proc->clockEnd); + int y = sub_8012DCC(0, proc->yFrom, proc->yTo, proc->clock, proc->clockEnd); + + y += proc->yOffset; + + proc->yOffset += proc->ySpeed; + proc->ySpeed += proc->yAccel; + + sub_8027B60( + 7, + x - gUnknown_0202BCB0.camera.x, + y - gUnknown_0202BCB0.camera.y, + proc->unit + ); + + ++proc->clock; + + if (proc->clock == proc->clockEnd) { + Proc_Break(proc); + } + + return; +} + +void sub_8032658(struct DeathDropAnimProc* proc) { + sub_8037830(proc, proc->unit); + return; +} + +void sub_8032664() { + RefreshEntityBmMaps(); + SMS_UpdateFromGameData(); + + return; +} + +void sub_8032674(ProcPtr proc, struct Unit* unit) { + struct DeathDropAnimProc* child; + + if (GetUnitCurrentHp(unit) != 0) { + return; + } + + if (!(unit->state & US_RESCUING)) { + return; + } + + child = Proc_StartBlocking(gUnknown_0859DA94, proc); + + child->unit = GetUnit(unit->rescueOtherUnit); + + UnitGetDeathDropLocation(unit, &child->xDrop, &child->yDrop); + UnitDrop(unit, child->xDrop, child->yDrop); + + child->xFrom = unit->xPos * 16; + child->yFrom = unit->yPos * 16; + child->xTo = child->xDrop * 16; + child->yTo = child->yDrop * 16; + child->yOffset = 0; + child->ySpeed = -5; + child->yAccel = 1; + child->clock = 0; + child->clockEnd = 11; + + SMS_RegisterUsage(GetUnitSMSId(child->unit)); + SMS_FlushIndirect(); + + PlaySoundEffect(0xAC); + return; +} From ecba3f26874ac9b0b4e98eead525f455414f7de6 Mon Sep 17 00:00:00 2001 From: Eebit Date: Sun, 10 Apr 2022 14:58:25 -0400 Subject: [PATCH 3/7] (bmmind) Decompile up to sub_80329A0 --- asm/bmmind.s | 353 ----------------------------------------- include/soundwrapper.h | 4 +- src/bmmind.c | 196 ++++++++++++++++++++++- 3 files changed, 195 insertions(+), 358 deletions(-) diff --git a/asm/bmmind.s b/asm/bmmind.s index e2ba76e39..0d1789b57 100644 --- a/asm/bmmind.s +++ b/asm/bmmind.s @@ -4,359 +4,6 @@ @ Unit Action stuff (why "mind"?) - THUMB_FUNC_START sub_8032728 -sub_8032728: @ 0x08032728 - push {r4, r5, lr} - adds r4, r0, #0 - adds r5, r1, #0 - bl GetUnitCurrentHp - cmp r0, #0 - bne _0803274A - ldr r0, [r4] - ldrb r0, [r0, #4] - ldr r1, [r5] - ldrb r1, [r1, #4] - movs r2, #2 - bl BWL_AddWinOrLossIdk - adds r0, r4, #0 - bl UnitKill -_0803274A: - pop {r4, r5} - pop {r0} - bx r0 - - THUMB_FUNC_END sub_8032728 - - THUMB_FUNC_START sub_8032750 -sub_8032750: @ 0x08032750 - push {r4, lr} - adds r4, r0, #0 - bl GetUnitCurrentHp - cmp r0, #0 - bne _0803276E - adds r0, r4, #0 - bl UnitKill - ldr r0, [r4] - ldrb r0, [r0, #4] - movs r1, #0 - movs r2, #6 - bl BWL_AddWinOrLossIdk -_0803276E: - pop {r4} - pop {r0} - bx r0 - - THUMB_FUNC_END sub_8032750 - - THUMB_FUNC_START BATTLE_GOTO1_IfNobodyIsDead -BATTLE_GOTO1_IfNobodyIsDead: @ 0x08032774 - push {lr} - adds r2, r0, #0 - ldr r0, _080327A8 @ gBattleStats - ldrh r1, [r0] - movs r0, #0x80 - ands r0, r1 - cmp r0, #0 - bne _0803279C - ldr r0, _080327AC @ gBattleActor - ldrb r0, [r0, #0x13] - lsls r0, r0, #0x18 - asrs r0, r0, #0x18 - cmp r0, #0 - beq _080327A4 - ldr r0, _080327B0 @ gBattleTarget - ldrb r0, [r0, #0x13] - lsls r0, r0, #0x18 - asrs r0, r0, #0x18 - cmp r0, #0 - beq _080327A4 -_0803279C: - adds r0, r2, #0 - movs r1, #1 - bl Proc_Goto -_080327A4: - pop {r0} - bx r0 - .align 2, 0 -_080327A8: .4byte gBattleStats -_080327AC: .4byte gBattleActor -_080327B0: .4byte gBattleTarget - - THUMB_FUNC_END BATTLE_GOTO1_IfNobodyIsDead - - THUMB_FUNC_START DidUnitDie -DidUnitDie: @ 0x080327B4 - push {lr} - bl GetUnitCurrentHp - cmp r0, #0 - bne _080327C2 - movs r0, #1 - b _080327C4 -_080327C2: - movs r0, #0 -_080327C4: - pop {r1} - bx r1 - - THUMB_FUNC_END DidUnitDie - - THUMB_FUNC_START BATTLE_ProbablyMakesTheDeadUnitDissapear -BATTLE_ProbablyMakesTheDeadUnitDissapear: @ 0x080327C8 - push {r4, r5, r6, r7, lr} - adds r6, r0, #0 - movs r0, #0 - str r0, [r6, #0x54] - ldr r7, _08032850 @ gBattleActor - adds r0, r7, #0 - bl DidUnitDie - lsls r0, r0, #0x18 - cmp r0, #0 - beq _080327F2 - ldr r0, _08032854 @ gProcScr_MoveUnit - bl Proc_Find - adds r4, r0, #0 - bl MU_StartDeathFade - str r4, [r6, #0x54] - adds r0, r7, #0 - bl TryRemoveUnitFromBallista -_080327F2: - ldr r5, _08032858 @ gBattleTarget - adds r0, r5, #0 - bl DidUnitDie - lsls r0, r0, #0x18 - cmp r0, #0 - beq _0803284A - movs r0, #0xb - ldrsb r0, [r5, r0] - bl GetUnit - ldr r1, [r0, #0xc] - movs r2, #1 - orrs r1, r2 - str r1, [r0, #0xc] - bl TryRemoveUnitFromBallista - bl SMS_UpdateFromGameData - adds r0, r5, #0 - bl MU_Create - adds r4, r0, #0 - movs r0, #0x10 - ldrsb r0, [r7, r0] - movs r1, #0x11 - ldrsb r1, [r7, r1] - movs r2, #0x10 - ldrsb r2, [r5, r2] - movs r3, #0x11 - ldrsb r3, [r5, r3] - bl GetFacingDirection - ldr r1, _0803285C @ gWorkingMovementScript - strb r0, [r1] - movs r0, #4 - strb r0, [r1, #1] - adds r0, r4, #0 - bl MU_StartMoveScript - adds r0, r4, #0 - bl MU_StartDeathFade - str r4, [r6, #0x54] -_0803284A: - pop {r4, r5, r6, r7} - pop {r0} - bx r0 - .align 2, 0 -_08032850: .4byte gBattleActor -_08032854: .4byte gProcScr_MoveUnit -_08032858: .4byte gBattleTarget -_0803285C: .4byte gWorkingMovementScript - - THUMB_FUNC_END BATTLE_ProbablyMakesTheDeadUnitDissapear - - THUMB_FUNC_START BATTLE_DeleteLinkedMOVEUNIT -BATTLE_DeleteLinkedMOVEUNIT: @ 0x08032860 - push {lr} - ldr r0, [r0, #0x54] - bl MU_End - pop {r0} - bx r0 - - THUMB_FUNC_END BATTLE_DeleteLinkedMOVEUNIT - - THUMB_FUNC_START sub_803286C -sub_803286C: @ 0x0803286C - push {r4, r5, r6, lr} - adds r5, r0, #0 - adds r0, #0x64 - movs r1, #0 - ldrsh r0, [r0, r1] - bl GetUnit - adds r6, r0, #0 - adds r0, r5, #0 - adds r0, #0x66 - movs r1, #0 - ldrsh r0, [r0, r1] - bl GetUnit - adds r4, r0, #0 - adds r0, r5, #0 - adds r1, r6, #0 - bl sub_8032674 - adds r0, r5, #0 - adds r1, r4, #0 - bl sub_8032674 - adds r0, r6, #0 - adds r1, r4, #0 - bl sub_8032728 - adds r0, r4, #0 - adds r1, r6, #0 - bl sub_8032728 - pop {r4, r5, r6} - pop {r0} - bx r0 - - THUMB_FUNC_END sub_803286C - - THUMB_FUNC_START sub_80328B0 -sub_80328B0: @ 0x080328B0 - push {r4, lr} - bl GetCurrentMapMusicIndex - adds r4, r0, #0 - bl Sound_GetCurrentSong - cmp r0, r4 - beq _080328CA - adds r0, r4, #0 - movs r1, #6 - movs r2, #0 - bl Sound_PlaySong80024E4 -_080328CA: - pop {r4} - pop {r0} - bx r0 - - THUMB_FUNC_END sub_80328B0 - - THUMB_FUNC_START BATTLE_HandleItemDrop -BATTLE_HandleItemDrop: @ 0x080328D0 - push {r4, r5, r6, r7, lr} - mov r7, r8 - push {r7} - mov r8, r0 - movs r7, #0 - ldr r6, _08032960 @ gBattleActor - movs r1, #0xb - ldrsb r1, [r6, r1] - adds r0, #0x64 - strh r1, [r0] - ldr r4, _08032964 @ gBattleTarget - movs r0, #0xb - ldrsb r0, [r4, r0] - mov r1, r8 - adds r1, #0x66 - strh r0, [r1] - movs r0, #0x13 - ldrsb r0, [r6, r0] - cmp r0, #0 - bne _0803290C - movs r0, #0xb - ldrsb r0, [r6, r0] - bl GetUnit - adds r7, r0, #0 - movs r0, #0xb - ldrsb r0, [r4, r0] - bl GetUnit - adds r5, r0, #0 -_0803290C: - movs r0, #0x13 - ldrsb r0, [r4, r0] - cmp r0, #0 - bne _08032928 - movs r0, #0xb - ldrsb r0, [r4, r0] - bl GetUnit - adds r7, r0, #0 - movs r0, #0xb - ldrsb r0, [r6, r0] - bl GetUnit - adds r5, r0, #0 -_08032928: - cmp r7, #0 - beq _08032968 - ldr r0, [r7, #0xc] - movs r1, #0x80 - lsls r1, r1, #5 - ands r0, r1 - cmp r0, #0 - beq _08032968 - ldrh r0, [r7, #0x1e] - cmp r0, #0 - beq _08032968 - movs r0, #0xb - ldrsb r0, [r5, r0] - movs r1, #0xc0 - ands r0, r1 - cmp r0, #0 - bne _08032968 - adds r0, r7, #0 - bl GetUnitLastItem - adds r1, r0, #0 - adds r0, r5, #0 - mov r2, r8 - bl NewGeneralItemGot - movs r0, #0 - b _0803296A - .align 2, 0 -_08032960: .4byte gBattleActor -_08032964: .4byte gBattleTarget -_08032968: - movs r0, #1 -_0803296A: - pop {r3} - mov r8, r3 - pop {r4, r5, r6, r7} - pop {r1} - bx r1 - - THUMB_FUNC_END BATTLE_HandleItemDrop - - THUMB_FUNC_START sub_8032974 -sub_8032974: @ 0x08032974 - push {lr} - adds r2, r0, #0 - ldr r1, _08032998 @ gBattleTarget - movs r0, #1 - strb r0, [r1, #0x12] - strb r0, [r1, #0x13] - ldr r0, _0803299C @ gBattleActor - ldrb r0, [r0, #0x13] - lsls r0, r0, #0x18 - asrs r0, r0, #0x18 - cmp r0, #0 - beq _08032994 - adds r0, r2, #0 - movs r1, #1 - bl Proc_Goto -_08032994: - pop {r0} - bx r0 - .align 2, 0 -_08032998: .4byte gBattleTarget -_0803299C: .4byte gBattleActor - - THUMB_FUNC_END sub_8032974 - - THUMB_FUNC_START sub_80329A0 -sub_80329A0: @ 0x080329A0 - push {r4, r5, lr} - adds r5, r0, #0 - ldr r4, _080329BC @ gActiveUnit - ldr r0, [r4] - bl sub_8032750 - ldr r1, [r4] - adds r0, r5, #0 - bl sub_8032674 - pop {r4, r5} - pop {r0} - bx r0 - .align 2, 0 -_080329BC: .4byte gActiveUnit - - THUMB_FUNC_END sub_80329A0 - THUMB_FUNC_START sub_80329C0 sub_80329C0: @ 0x080329C0 push {r4, lr} diff --git a/include/soundwrapper.h b/include/soundwrapper.h index e71214a0c..41121770a 100644 --- a/include/soundwrapper.h +++ b/include/soundwrapper.h @@ -1,7 +1,7 @@ #ifndef GUARD_SOUNDWRAPPER_H #define GUARD_SOUNDWRAPPER_H -// ??? Sound_GetCurrentSong(???); +int Sound_GetCurrentSong(void); // ??? sub_8002264(???); // ??? Sound_SetVolume8002274(???); // ??? Sound_SetVolume80022EC(???); @@ -11,7 +11,7 @@ // ??? Sound_PlaySong8002448(???); // ??? PlaySong8002478(???); // ??? Sound_PlaySong80024D4(???); -// ??? Sound_PlaySong80024E4(???); +void Sound_PlaySong80024E4(int songId, int speed, struct MusicPlayerInfo *player); // ??? sub_80024F0(???); // ??? Sound_PlaySong8002574(???); // ??? sub_8002620(???); diff --git a/src/bmmind.c b/src/bmmind.c index 7c694a2bb..f684200ec 100644 --- a/src/bmmind.c +++ b/src/bmmind.c @@ -17,11 +17,22 @@ struct UnknownBMMindProc { /* 00 */ PROC_HEADER; - + /* 29 */ u8 unk_29[0x54-0x29]; - + /* 54 */ struct Unit* unk_54; - +}; + +struct UnknownBMMindProc_2 { + /* 00 */ PROC_HEADER; + + /* 29 */ u8 unk_29[0x54-0x29]; + + /* 54 */ struct MUProc* unk_54; + /* 58 */ u8 unk_58[0x64-0x58]; + + /* 64 */ s16 unitIdA; + /* 66 */ s16 unitIdB; }; struct DeathDropAnimProc { @@ -71,6 +82,15 @@ void BeginMapAnimForSummonDK(void); void SMS_RegisterUsage(int); void sub_8027B60(int, int, int, struct Unit*); +// code.s +void BWL_AddWinOrLossIdk(u8, u8, int); + +// bm.s +int GetCurrentMapMusicIndex(void); + +// popup.s +void NewGeneralItemGot(struct Unit*, int, ProcPtr); + s8 ActionRescue(ProcPtr); s8 ActionDrop(ProcPtr); s8 ActionVisitAndSieze(ProcPtr); @@ -463,3 +483,173 @@ void sub_8032674(ProcPtr proc, struct Unit* unit) { PlaySoundEffect(0xAC); return; } + +void sub_8032728(struct Unit* unitA, struct Unit* unitB) { + if (GetUnitCurrentHp(unitA) != 0) { + return; + } + + BWL_AddWinOrLossIdk(unitA->pCharacterData->number, unitB->pCharacterData->number, 2); + + UnitKill(unitA); + + return; +} + +void sub_8032750(struct Unit* unit) { + if (GetUnitCurrentHp(unit) != 0) { + return; + } + + UnitKill(unit); + + BWL_AddWinOrLossIdk(unit->pCharacterData->number, 0, 6); + + return; +} + +void BATTLE_GOTO1_IfNobodyIsDead(ProcPtr proc) { + if ((gBattleStats.config & 0x80) == 0) { + if (gBattleActor.unit.curHP == 0) { + return; + } + + if (gBattleTarget.unit.curHP == 0) { + return; + } + } + + Proc_Goto(proc, 1); + + return; +} + +bool8 DidUnitDie(struct Unit* unit) { + if (GetUnitCurrentHp(unit) != 0) { + return 0; + } else { + return 1; + } +} + +void BATTLE_ProbablyMakesTheDeadUnitDissapear(ProcPtr proc) { + struct MUProc* muProc; + + ((struct UnknownBMMindProc_2*)(proc))->unk_54 = 0; + + if (DidUnitDie(&gBattleActor.unit)) { + muProc = Proc_Find(gProcScr_MoveUnit); + MU_StartDeathFade(muProc); + ((struct UnknownBMMindProc_2*)(proc))->unk_54 = muProc; + + TryRemoveUnitFromBallista(&gBattleActor.unit); + } + + if (DidUnitDie(&gBattleTarget.unit)) { + struct Unit* target = GetUnit(gBattleTarget.unit.index); + target->state |= US_HIDDEN; + + TryRemoveUnitFromBallista(target); + + SMS_UpdateFromGameData(); + muProc = MU_Create(&gBattleTarget.unit); + + gWorkingMovementScript[0] = GetFacingDirection(gBattleActor.unit.xPos, gBattleActor.unit.yPos, gBattleTarget.unit.xPos, gBattleTarget.unit.yPos); + gWorkingMovementScript[1] = 4; + + MU_StartMoveScript(muProc, gWorkingMovementScript); + MU_StartDeathFade(muProc); + + ((struct UnknownBMMindProc_2*)(proc))->unk_54 = muProc; + } + + return; +} + +void BATTLE_DeleteLinkedMOVEUNIT(ProcPtr r0) { + MU_End(((struct UnknownBMMindProc_2*)(r0))->unk_54); + return; +} + +void sub_803286C(ProcPtr proc) { + struct Unit* unitA = GetUnit(((struct UnknownBMMindProc_2*)(proc))->unitIdA); + struct Unit* unitB = GetUnit(((struct UnknownBMMindProc_2*)(proc))->unitIdB); + + sub_8032674(proc, unitA); + sub_8032674(proc, unitB); + + sub_8032728(unitA, unitB); + sub_8032728(unitB, unitA); + + return; +} + +void sub_80328B0() { + int bgmIdx = GetCurrentMapMusicIndex(); + + if (Sound_GetCurrentSong() != bgmIdx) { + Sound_PlaySong80024E4(bgmIdx, 6, NULL); + } + + return; +} + +bool8 BATTLE_HandleItemDrop(ProcPtr proc) { + struct Unit* unitA = NULL; + struct Unit* unitB; + + ((struct UnknownBMMindProc_2*)(proc))->unitIdA = gBattleActor.unit.index; + ((struct UnknownBMMindProc_2*)(proc))->unitIdB = gBattleTarget.unit.index; + + if (gBattleActor.unit.curHP == 0) { + unitA = GetUnit(gBattleActor.unit.index); + unitB = GetUnit(gBattleTarget.unit.index); + } + + if (gBattleTarget.unit.curHP == 0) { + unitA = GetUnit(gBattleTarget.unit.index); + unitB = GetUnit(gBattleActor.unit.index); + } + + if (unitA == NULL) { + return 1; + } + + if (!(unitA->state & US_DROP_ITEM)) { + return 1; + } + + if (unitA->items[0] == 0) { + return 1; + } + + if ((UNIT_FACTION(unitB)) != 0) { + return 1; + } + + NewGeneralItemGot( + unitB, + GetUnitLastItem(unitA), + proc + ); + + return 0; +} + +void sub_8032974(ProcPtr proc) { + gBattleTarget.unit.maxHP = 1; + gBattleTarget.unit.curHP = 1; + + if (gBattleActor.unit.curHP != 0) { + Proc_Goto(proc, 1); + } + + return; +} + +void sub_80329A0(ProcPtr proc) { + sub_8032750(gActiveUnit); + sub_8032674(proc, gActiveUnit); + + return; +} \ No newline at end of file From 6281cae333b2a0886c521bffdef9083d47398c39 Mon Sep 17 00:00:00 2001 From: Eebit Date: Sun, 10 Apr 2022 15:04:15 -0400 Subject: [PATCH 4/7] (bmmind) Non-matching - Move last function into bmmind.c --- asm/bmmind.s | 23 ----------------------- ldscript.txt | 1 - src/bmmind.c | 33 ++++++++++++++++++++++++++++++++- 3 files changed, 32 insertions(+), 25 deletions(-) delete mode 100644 asm/bmmind.s diff --git a/asm/bmmind.s b/asm/bmmind.s deleted file mode 100644 index 0d1789b57..000000000 --- a/asm/bmmind.s +++ /dev/null @@ -1,23 +0,0 @@ - .INCLUDE "macro.inc" - - .SYNTAX UNIFIED - - @ Unit Action stuff (why "mind"?) - - THUMB_FUNC_START sub_80329C0 -sub_80329C0: @ 0x080329C0 - push {r4, lr} - ldr r4, _080329D4 @ gUnknown_0203A974 - adds r1, r4, #0 - movs r2, #7 - bl CpuFastSet - adds r0, r4, #0 - pop {r4} - pop {r1} - bx r1 - .align 2, 0 -_080329D4: .4byte gUnknown_0203A974 - - THUMB_FUNC_END sub_80329C0 - -.align 2, 0 diff --git a/ldscript.txt b/ldscript.txt index 24ae5199b..56fea799f 100644 --- a/ldscript.txt +++ b/ldscript.txt @@ -98,7 +98,6 @@ SECTIONS asm/bmusort.o(.text); asm/bmarena.o(.text); src/bmmind.o(.text); - asm/bmmind.o(.text); src/bmpatharrowdisp.o(.text); src/sallycursor.o(.text); asm/bmcommanddbg.o(.text); diff --git a/src/bmmind.c b/src/bmmind.c index f684200ec..cbd33157e 100644 --- a/src/bmmind.c +++ b/src/bmmind.c @@ -652,4 +652,35 @@ void sub_80329A0(ProcPtr proc) { sub_8032674(proc, gActiveUnit); return; -} \ No newline at end of file +} + +#if NONMATCHING + +??? sub_80329C0(u8 r0) { + CpuFastFill(r0, gUnknown_0203A974, 7); + + return gUnknown_0203A974; +} + +#else // if !NONMATCHING + +__attribute__((naked)) +void sub_80329C0(u8 r0) { + asm("\n\ + .syntax unified\n\ + push {r4, lr}\n\ + ldr r4, _080329D4 @ gUnknown_0203A974\n\ + adds r1, r4, #0\n\ + movs r2, #7\n\ + bl CpuFastSet\n\ + adds r0, r4, #0\n\ + pop {r4}\n\ + pop {r1}\n\ + bx r1\n\ + .align 2, 0\n\ + _080329D4: .4byte gUnknown_0203A974\n\ + .syntax divided\n\ + "); +} + +#endif // NONMATCHING \ No newline at end of file From 7d47f6d13f619b74318e03ee4e99362ed5017b01 Mon Sep 17 00:00:00 2001 From: Eebit Date: Sun, 10 Apr 2022 15:12:13 -0400 Subject: [PATCH 5/7] (bmmind) Create bmmind.h --- include/bmmind.h | 37 +++++++++++++++++++++++++++++++++++++ include/functions.h | 32 -------------------------------- src/bmmind.c | 1 + 3 files changed, 38 insertions(+), 32 deletions(-) create mode 100644 include/bmmind.h diff --git a/include/bmmind.h b/include/bmmind.h new file mode 100644 index 000000000..f21047d58 --- /dev/null +++ b/include/bmmind.h @@ -0,0 +1,37 @@ +#ifndef GUARD_BM_MIND_H +#define GUARD_BM_MIND_H + +void StoreRNStateToActionStruct(void); +void LoadRNStateFromActionStruct(void); +unsigned int ApplyUnitAction(ProcPtr proc); +// ??? ActionRescue(???); +// ??? sub_80321B8(???); +// ??? sub_80321C8(???); +// ??? ActionDrop(???); +// ??? ActionVisitAndSieze(???); +// ??? ActionCombat(???); +// ??? ActionArena(???); +// ??? ActionDance(???); +// ??? ActionTalk(???); +// ??? ActionSupport(???); +// ??? ActionSteal(???); +// ??? ActionSummon(???); +// ??? ActionSummonDK(???); +// ??? sub_80325AC(???); +// ??? sub_8032658(???); +// ??? sub_8032664(???); +// ??? sub_8032674(???); +// ??? sub_8032728(???); +// ??? sub_8032750(???); +// ??? BATTLE_GOTO1_IfNobodyIsDead(???); +// ??? DidUnitDie(???); +// ??? BATTLE_ProbablyMakesTheDeadUnitDissapear(???); +// ??? BATTLE_DeleteLinkedMOVEUNIT(???); +// ??? sub_803286C(???); +// ??? sub_80328B0(???); +// ??? BATTLE_HandleItemDrop(???); +// ??? sub_8032974(???); +// ??? sub_80329A0(???); +// ??? sub_80329C0(???); + +#endif // GUARD_BM_MIND_H diff --git a/include/functions.h b/include/functions.h index b852d853a..60c7818d5 100644 --- a/include/functions.h +++ b/include/functions.h @@ -1433,38 +1433,6 @@ void PrepareArena2(struct Unit* unit); // ??? sub_8031F50(???); // ??? sub_8031F74(???); // ??? sub_8031FC8(???); -// ??? StoreRNStateToActionStruct(???); -// ??? LoadRNStateFromActionStruct(???); -// ??? ApplyUnitAction(???); -// ??? ActionRescue(???); -// ??? sub_80321B8(???); -// ??? sub_80321C8(???); -// ??? ActionDrop(???); -// ??? ActionVisitAndSieze(???); -// ??? ActionCombat(???); -// ??? ActionArena(???); -// ??? ActionDance(???); -// ??? ActionTalk(???); -// ??? ActionSupport(???); -// ??? ActionSteal(???); -// ??? ActionSummon(???); -// ??? ActionSummonDK(???); -// ??? sub_80325AC(???); -// ??? sub_8032658(???); -// ??? sub_8032664(???); -// ??? sub_8032674(???); -// ??? sub_8032728(???); -// ??? sub_8032750(???); -// ??? BATTLE_GOTO1_IfNobodyIsDead(???); -// ??? DidUnitDie(???); -// ??? BATTLE_ProbablyMakesTheDeadUnitDissapear(???); -// ??? BATTLE_DeleteLinkedMOVEUNIT(???); -// ??? sub_803286C(???); -// ??? sub_80328B0(???); -// ??? BATTLE_HandleItemDrop(???); -// ??? sub_8032974(???); -// ??? sub_80329A0(???); -// ??? sub_80329C0(???); // ??? sub_8032E28(???); // ??? sub_80330D4(???); // ??? sub_803318C(???); diff --git a/src/bmmind.c b/src/bmmind.c index cbd33157e..d89b7933e 100644 --- a/src/bmmind.c +++ b/src/bmmind.c @@ -11,6 +11,7 @@ #include "bmreliance.h" #include "m4a.h" #include "soundwrapper.h" +#include "bmmind.h" #include "constants/items.h" #include "constants/terrains.h" From ce94f311e9466c09f923b060c0c29121663b9428 Mon Sep 17 00:00:00 2001 From: Eebit Date: Sun, 10 Apr 2022 15:29:24 -0400 Subject: [PATCH 6/7] (bmmind) Decompile proc data for bmmind --- data/data_59D9FC.s | 24 --------------- data/data_59DB6C.s | 9 ++++++ ldscript.txt | 2 ++ src/bmmind.c | 74 ++++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 79 insertions(+), 30 deletions(-) create mode 100644 data/data_59DB6C.s diff --git a/data/data_59D9FC.s b/data/data_59D9FC.s index a57e62a12..69bfddbdc 100644 --- a/data/data_59D9FC.s +++ b/data/data_59D9FC.s @@ -11,27 +11,3 @@ gUnknown_0859DA22: @ 0x0859DA22 .global gUnknown_0859DA4A gUnknown_0859DA4A: @ 0x0859DA4A .incbin "baserom.gba", 0x59DA4A, 0x22 - - .global gUnknown_0859DA6C -gUnknown_0859DA6C: @ 0x0859DA6C - .incbin "baserom.gba", 0x59DA6C, 0x28 - - .global gUnknown_0859DA94 -gUnknown_0859DA94: @ 0x0859DA94 - .incbin "baserom.gba", 0x59DA94, 0x28 - - .global gUnknown_0859DABC -gUnknown_0859DABC: @ 0x0859DABC - .incbin "baserom.gba", 0x59DABC, 0x68 - - .global gUnknown_0859DB24 -gUnknown_0859DB24: @ 0x0859DB24 - .incbin "baserom.gba", 0x59DB24, 0x48 - - .global gPathArrowOAMTable -gPathArrowOAMTable: @ 0x0859DB6C - .incbin "baserom.gba", 0x59DB6C, 0x34 - - .global gUnknown_0859DBA0 -gUnknown_0859DBA0: @ 0x0859DBA0 - .incbin "baserom.gba", 0x59DBA0, 0x4 diff --git a/data/data_59DB6C.s b/data/data_59DB6C.s new file mode 100644 index 000000000..3a0ea86b3 --- /dev/null +++ b/data/data_59DB6C.s @@ -0,0 +1,9 @@ + .section .data + + .global gPathArrowOAMTable +gPathArrowOAMTable: @ 0x0859DB6C + .incbin "baserom.gba", 0x59DB6C, 0x34 + + .global gUnknown_0859DBA0 +gUnknown_0859DBA0: @ 0x0859DBA0 + .incbin "baserom.gba", 0x59DBA0, 0x4 diff --git a/ldscript.txt b/ldscript.txt index 56fea799f..656caf407 100644 --- a/ldscript.txt +++ b/ldscript.txt @@ -265,6 +265,8 @@ SECTIONS . = ALIGN(4); data/data_59D238.o(.data); . = ALIGN(4); src/bmio.o(.data); . = ALIGN(4); data/data_59D9FC.o(.data); + . = ALIGN(4); src/bmmind.o(.data); + . = ALIGN(4); data/data_59DB6C.o(.data); . = ALIGN(4); src/sallycursor.o(.data); . = ALIGN(4); data/data_59E13C.o(.data); . = ALIGN(4); src/cp_phase.o(.data); diff --git a/src/bmmind.c b/src/bmmind.c index d89b7933e..206946d96 100644 --- a/src/bmmind.c +++ b/src/bmmind.c @@ -50,10 +50,72 @@ struct DeathDropAnimProc { /* 48 */ short clockEnd; }; -extern struct ProcCmd CONST_DATA gUnknown_0859DA6C[]; -extern struct ProcCmd CONST_DATA gUnknown_0859DA94[]; -extern struct ProcCmd CONST_DATA gUnknown_0859DABC[]; -extern struct ProcCmd CONST_DATA gUnknown_0859DB24[]; +static int sub_80321B8(struct UnknownBMMindProc* proc); +static int sub_80321C8(void); + +struct ProcCmd CONST_DATA gUnknown_0859DA6C[] = { + PROC_SLEEP(0), + PROC_WHILE(MU_IsAnyActive), + PROC_CALL_2(sub_80321B8), + PROC_CALL(sub_80321C8), + + PROC_END, +}; + +static void sub_80325AC(struct DeathDropAnimProc* proc); +static void sub_8032658(struct DeathDropAnimProc* proc); +static void sub_8032664(void); + +struct ProcCmd CONST_DATA gUnknown_0859DA94[] = { + PROC_REPEAT(sub_80325AC), + PROC_CALL(sub_8032658), + PROC_SLEEP(0), + PROC_CALL(sub_8032664), + + PROC_END, +}; + +static void BATTLE_GOTO1_IfNobodyIsDead(ProcPtr proc); +static void BATTLE_ProbablyMakesTheDeadUnitDissapear(ProcPtr proc); +static void BATTLE_DeleteLinkedMOVEUNIT(ProcPtr proc); +static bool8 BATTLE_HandleItemDrop(ProcPtr proc); +static void sub_803286C(ProcPtr proc); + +struct ProcCmd CONST_DATA gUnknown_0859DABC[] = { + PROC_CALL(BeginBattleAnimations), + PROC_SLEEP(1), + PROC_CALL(BattleApplyGameStateUpdates), + PROC_WHILE(DoesBMXFADEExist), + PROC_CALL(BATTLE_GOTO1_IfNobodyIsDead), + PROC_CALL(BATTLE_ProbablyMakesTheDeadUnitDissapear), + PROC_SLEEP(0x20), + PROC_CALL(BATTLE_DeleteLinkedMOVEUNIT), + +PROC_LABEL(1), + PROC_CALL_2(BATTLE_HandleItemDrop), + PROC_CALL(sub_803286C), + PROC_SLEEP(0), + + PROC_END, +}; + +static void sub_8032974(ProcPtr proc); +static void sub_80329A0(ProcPtr proc); + +struct ProcCmd CONST_DATA gUnknown_0859DB24[] = { + PROC_SLEEP(0), + PROC_CALL(sub_8032974), + PROC_CALL(BATTLE_ProbablyMakesTheDeadUnitDissapear), + PROC_SLEEP(0x20), + PROC_CALL(BATTLE_DeleteLinkedMOVEUNIT), + +PROC_LABEL(1), + PROC_CALL(sub_80329A0), + PROC_SLEEP(0), + + PROC_END, +}; + // koido.s void Make6CKOIDO(struct Unit*, int, u8, ProcPtr); @@ -567,8 +629,8 @@ void BATTLE_ProbablyMakesTheDeadUnitDissapear(ProcPtr proc) { return; } -void BATTLE_DeleteLinkedMOVEUNIT(ProcPtr r0) { - MU_End(((struct UnknownBMMindProc_2*)(r0))->unk_54); +void BATTLE_DeleteLinkedMOVEUNIT(ProcPtr proc) { + MU_End(((struct UnknownBMMindProc_2*)(proc))->unk_54); return; } From 9ae4de95ab144befc1c12e1f9e35662673873636 Mon Sep 17 00:00:00 2001 From: Eebit Date: Sun, 10 Apr 2022 17:28:00 -0400 Subject: [PATCH 7/7] (bmmind) Cleanup and renames of various functions --- asm/bb.s | 2 +- include/bmmind.h | 16 +++++------ include/variables.h | 4 --- src/bmmind.c | 68 ++++++++++++++++++++++----------------------- 4 files changed, 43 insertions(+), 47 deletions(-) diff --git a/asm/bb.s b/asm/bb.s index 453bfb435..3cea1c45b 100644 --- a/asm/bb.s +++ b/asm/bb.s @@ -469,7 +469,7 @@ _080357BC: _080357D4: adds r0, r6, #0 adds r1, r4, #0 - bl sub_8032674 + bl DropRescueOnDeath pop {r4, r5, r6} pop {r0} bx r0 diff --git a/include/bmmind.h b/include/bmmind.h index f21047d58..b9f95be07 100644 --- a/include/bmmind.h +++ b/include/bmmind.h @@ -5,10 +5,10 @@ void StoreRNStateToActionStruct(void); void LoadRNStateFromActionStruct(void); unsigned int ApplyUnitAction(ProcPtr proc); // ??? ActionRescue(???); -// ??? sub_80321B8(???); +// ??? AfterDrop_CheckTrapAfterDropMaybe(???); // ??? sub_80321C8(???); // ??? ActionDrop(???); -// ??? ActionVisitAndSieze(???); +// ??? ActionVisitAndSeize(???); // ??? ActionCombat(???); // ??? ActionArena(???); // ??? ActionDance(???); @@ -20,18 +20,18 @@ unsigned int ApplyUnitAction(ProcPtr proc); // ??? sub_80325AC(???); // ??? sub_8032658(???); // ??? sub_8032664(???); -// ??? sub_8032674(???); -// ??? sub_8032728(???); -// ??? sub_8032750(???); +void DropRescueOnDeath(ProcPtr proc, struct Unit* unit); +// ??? KillUnitOnCombatDeath(???); +// ??? KillUnitOnArenaDeathMaybe(???); // ??? BATTLE_GOTO1_IfNobodyIsDead(???); // ??? DidUnitDie(???); -// ??? BATTLE_ProbablyMakesTheDeadUnitDissapear(???); +// ??? BATTLE_PostCombatDeathFades(???); // ??? BATTLE_DeleteLinkedMOVEUNIT(???); -// ??? sub_803286C(???); +// ??? BATTLE_HandleCombatDeaths(???); // ??? sub_80328B0(???); // ??? BATTLE_HandleItemDrop(???); // ??? sub_8032974(???); -// ??? sub_80329A0(???); +// ??? BATTLE_HandleArenaDeathsMaybe(???); // ??? sub_80329C0(???); #endif // GUARD_BM_MIND_H diff --git a/include/variables.h b/include/variables.h index 7f906f993..6ff7ea4c5 100644 --- a/include/variables.h +++ b/include/variables.h @@ -1539,10 +1539,6 @@ extern struct ProcCmd CONST_DATA gUnknown_0859AE18[]; // extern ??? gUnknown_0859D9FC // extern ??? gUnknown_0859DA22 // extern ??? gUnknown_0859DA4A -// extern ??? gUnknown_0859DA6C -// extern ??? gUnknown_0859DA94 -// extern ??? gUnknown_0859DABC -// extern ??? gUnknown_0859DB24 // extern ??? gUnknown_0859DBA0 // extern ??? gUnknown_0859E13C // extern ??? gUnknown_0859E14C diff --git a/src/bmmind.c b/src/bmmind.c index 206946d96..fbb98ca97 100644 --- a/src/bmmind.c +++ b/src/bmmind.c @@ -50,13 +50,13 @@ struct DeathDropAnimProc { /* 48 */ short clockEnd; }; -static int sub_80321B8(struct UnknownBMMindProc* proc); +static int AfterDrop_CheckTrapAfterDropMaybe(struct UnknownBMMindProc* proc); static int sub_80321C8(void); -struct ProcCmd CONST_DATA gUnknown_0859DA6C[] = { +struct ProcCmd CONST_DATA sProcScr_AfterDropAction[] = { PROC_SLEEP(0), PROC_WHILE(MU_IsAnyActive), - PROC_CALL_2(sub_80321B8), + PROC_CALL_2(AfterDrop_CheckTrapAfterDropMaybe), PROC_CALL(sub_80321C8), PROC_END, @@ -66,7 +66,7 @@ static void sub_80325AC(struct DeathDropAnimProc* proc); static void sub_8032658(struct DeathDropAnimProc* proc); static void sub_8032664(void); -struct ProcCmd CONST_DATA gUnknown_0859DA94[] = { +struct ProcCmd CONST_DATA sProcScr_DeathDropAnim[] = { PROC_REPEAT(sub_80325AC), PROC_CALL(sub_8032658), PROC_SLEEP(0), @@ -76,41 +76,41 @@ struct ProcCmd CONST_DATA gUnknown_0859DA94[] = { }; static void BATTLE_GOTO1_IfNobodyIsDead(ProcPtr proc); -static void BATTLE_ProbablyMakesTheDeadUnitDissapear(ProcPtr proc); +static void BATTLE_PostCombatDeathFades(ProcPtr proc); static void BATTLE_DeleteLinkedMOVEUNIT(ProcPtr proc); static bool8 BATTLE_HandleItemDrop(ProcPtr proc); -static void sub_803286C(ProcPtr proc); +static void BATTLE_HandleCombatDeaths(ProcPtr proc); -struct ProcCmd CONST_DATA gUnknown_0859DABC[] = { +struct ProcCmd CONST_DATA sProcScr_CombatAction[] = { PROC_CALL(BeginBattleAnimations), PROC_SLEEP(1), PROC_CALL(BattleApplyGameStateUpdates), PROC_WHILE(DoesBMXFADEExist), PROC_CALL(BATTLE_GOTO1_IfNobodyIsDead), - PROC_CALL(BATTLE_ProbablyMakesTheDeadUnitDissapear), + PROC_CALL(BATTLE_PostCombatDeathFades), PROC_SLEEP(0x20), PROC_CALL(BATTLE_DeleteLinkedMOVEUNIT), PROC_LABEL(1), PROC_CALL_2(BATTLE_HandleItemDrop), - PROC_CALL(sub_803286C), + PROC_CALL(BATTLE_HandleCombatDeaths), PROC_SLEEP(0), PROC_END, }; static void sub_8032974(ProcPtr proc); -static void sub_80329A0(ProcPtr proc); +static void BATTLE_HandleArenaDeathsMaybe(ProcPtr proc); -struct ProcCmd CONST_DATA gUnknown_0859DB24[] = { +struct ProcCmd CONST_DATA sProcScr_ArenaAction[] = { PROC_SLEEP(0), PROC_CALL(sub_8032974), - PROC_CALL(BATTLE_ProbablyMakesTheDeadUnitDissapear), + PROC_CALL(BATTLE_PostCombatDeathFades), PROC_SLEEP(0x20), PROC_CALL(BATTLE_DeleteLinkedMOVEUNIT), PROC_LABEL(1), - PROC_CALL(sub_80329A0), + PROC_CALL(BATTLE_HandleArenaDeathsMaybe), PROC_SLEEP(0), PROC_END, @@ -156,7 +156,7 @@ void NewGeneralItemGot(struct Unit*, int, ProcPtr); s8 ActionRescue(ProcPtr); s8 ActionDrop(ProcPtr); -s8 ActionVisitAndSieze(ProcPtr); +s8 ActionVisitAndSeize(ProcPtr); s8 ActionCombat(ProcPtr); s8 ActionDance(ProcPtr); s8 ActionTalk(ProcPtr); @@ -181,7 +181,7 @@ void LoadRNStateFromActionStruct() { unsigned int ApplyUnitAction(ProcPtr proc) { gActiveUnit = GetUnit(gActionData.subjectIndex); - if (gActionData.unitActionType == UNIT_ACTION_COMBAT) { // UNIT_ACTION_STAFF = 2, UNIT_ACTION_COMBAT = 1 + if (gActionData.unitActionType == UNIT_ACTION_COMBAT) { int itemIdx = GetItemIndex( GetUnit(gActionData.subjectIndex)->items[gActionData.itemSlotIndex] ); @@ -203,7 +203,7 @@ unsigned int ApplyUnitAction(ProcPtr proc) { return ActionDrop(proc); case UNIT_ACTION_VISIT: case UNIT_ACTION_SEIZE: - return ActionVisitAndSieze(proc); + return ActionVisitAndSeize(proc); case UNIT_ACTION_COMBAT: return ActionCombat(proc); case UNIT_ACTION_DANCE: @@ -253,7 +253,7 @@ s8 ActionRescue(ProcPtr proc) { return 0; } -int sub_80321B8(struct UnknownBMMindProc* proc) { +int AfterDrop_CheckTrapAfterDropMaybe(struct UnknownBMMindProc* proc) { return sub_80377F0(proc, proc->unk_54); } @@ -292,14 +292,14 @@ s8 ActionDrop(ProcPtr proc) { gActionData.yOther ); - child = Proc_StartBlocking(gUnknown_0859DA6C, proc); + child = Proc_StartBlocking(sProcScr_AfterDropAction, proc); ((struct UnknownBMMindProc*)(child))->unk_54 = target; return 0; } // TODO: Fake match - register allocation prefers r5 without the register keyword -s8 ActionVisitAndSieze(ProcPtr proc) { +s8 ActionVisitAndSeize(ProcPtr proc) { register int x asm("r4"); int y; @@ -344,13 +344,13 @@ s8 ActionCombat(ProcPtr proc) { BattleGenerateReal(GetUnit(gActionData.subjectIndex), target); } - Proc_StartBlocking(gUnknown_0859DABC, proc); + Proc_StartBlocking(sProcScr_CombatAction, proc); return 0; } s8 ActionArena(ProcPtr proc) { - Proc_StartBlocking(gUnknown_0859DB24, proc); + Proc_StartBlocking(sProcScr_ArenaAction, proc); return 0; } @@ -512,7 +512,7 @@ void sub_8032664() { return; } -void sub_8032674(ProcPtr proc, struct Unit* unit) { +void DropRescueOnDeath(ProcPtr proc, struct Unit* unit) { struct DeathDropAnimProc* child; if (GetUnitCurrentHp(unit) != 0) { @@ -523,7 +523,7 @@ void sub_8032674(ProcPtr proc, struct Unit* unit) { return; } - child = Proc_StartBlocking(gUnknown_0859DA94, proc); + child = Proc_StartBlocking(sProcScr_DeathDropAnim, proc); child->unit = GetUnit(unit->rescueOtherUnit); @@ -547,7 +547,7 @@ void sub_8032674(ProcPtr proc, struct Unit* unit) { return; } -void sub_8032728(struct Unit* unitA, struct Unit* unitB) { +void KillUnitOnCombatDeath(struct Unit* unitA, struct Unit* unitB) { if (GetUnitCurrentHp(unitA) != 0) { return; } @@ -559,7 +559,7 @@ void sub_8032728(struct Unit* unitA, struct Unit* unitB) { return; } -void sub_8032750(struct Unit* unit) { +void KillUnitOnArenaDeathMaybe(struct Unit* unit) { if (GetUnitCurrentHp(unit) != 0) { return; } @@ -595,7 +595,7 @@ bool8 DidUnitDie(struct Unit* unit) { } } -void BATTLE_ProbablyMakesTheDeadUnitDissapear(ProcPtr proc) { +void BATTLE_PostCombatDeathFades(ProcPtr proc) { struct MUProc* muProc; ((struct UnknownBMMindProc_2*)(proc))->unk_54 = 0; @@ -634,15 +634,15 @@ void BATTLE_DeleteLinkedMOVEUNIT(ProcPtr proc) { return; } -void sub_803286C(ProcPtr proc) { +void BATTLE_HandleCombatDeaths(ProcPtr proc) { struct Unit* unitA = GetUnit(((struct UnknownBMMindProc_2*)(proc))->unitIdA); struct Unit* unitB = GetUnit(((struct UnknownBMMindProc_2*)(proc))->unitIdB); - sub_8032674(proc, unitA); - sub_8032674(proc, unitB); + DropRescueOnDeath(proc, unitA); + DropRescueOnDeath(proc, unitB); - sub_8032728(unitA, unitB); - sub_8032728(unitB, unitA); + KillUnitOnCombatDeath(unitA, unitB); + KillUnitOnCombatDeath(unitB, unitA); return; } @@ -710,9 +710,9 @@ void sub_8032974(ProcPtr proc) { return; } -void sub_80329A0(ProcPtr proc) { - sub_8032750(gActiveUnit); - sub_8032674(proc, gActiveUnit); +void BATTLE_HandleArenaDeathsMaybe(ProcPtr proc) { + KillUnitOnArenaDeathMaybe(gActiveUnit); + DropRescueOnDeath(proc, gActiveUnit); return; }