From 10293e00d35eed14f0dafeed345e96d5e7cb58f9 Mon Sep 17 00:00:00 2001 From: Tal Hayon Date: Thu, 30 Dec 2021 10:51:41 +0200 Subject: [PATCH 1/4] Decompile bowMoblin.s --- asm/enemy/bowMoblin.s | 717 -------------------- asm/non_matching/bowMoblin/sub_0803C4B0.inc | 98 +++ linker.ld | 1 - src/enemy/bowMoblin.c | 339 +++++++++ 4 files changed, 437 insertions(+), 718 deletions(-) delete mode 100644 asm/enemy/bowMoblin.s create mode 100644 asm/non_matching/bowMoblin/sub_0803C4B0.inc diff --git a/asm/enemy/bowMoblin.s b/asm/enemy/bowMoblin.s deleted file mode 100644 index 1a005d0f..00000000 --- a/asm/enemy/bowMoblin.s +++ /dev/null @@ -1,717 +0,0 @@ - .include "asm/macros.inc" - - .include "constants/constants.inc" - - .syntax unified - - .text - - thumb_func_start sub_0803C1E0 -sub_0803C1E0: @ 0x0803C1E0 - push {r4, lr} - adds r4, r0, #0 - bl sub_0804A720 - movs r1, #0 - movs r2, #1 - strb r2, [r4, #0xc] - adds r0, r4, #0 - adds r0, #0x7b - strb r1, [r0] - adds r0, #5 - strb r1, [r0] - adds r0, #3 - strb r1, [r0] - subs r0, #2 - strb r1, [r0] - subs r0, #7 - strb r1, [r0] - adds r0, #8 - strb r2, [r0] - ldrb r0, [r4, #0xe] - cmp r0, #0 - beq _0803C228 - ldrb r1, [r4, #0xb] - lsls r0, r1, #1 - strb r0, [r4, #0x14] - movs r0, #0x1e - strb r0, [r4, #0xe] - movs r0, #0x80 - strh r0, [r4, #0x24] - lsls r1, r1, #3 - strb r1, [r4, #0x15] - adds r0, r4, #0 - bl sub_0803C690 - b _0803C232 -_0803C228: - movs r0, #0x10 - strb r0, [r4, #0x14] - adds r0, r4, #0 - bl sub_0803C4B0 -_0803C232: - pop {r4, pc} - - thumb_func_start sub_0803C234 -sub_0803C234: @ 0x0803C234 - push {r4, lr} - adds r4, r0, #0 - adds r1, r4, #0 - adds r1, #0x81 - ldrb r0, [r1] - cmp r0, #0 - beq _0803C246 - subs r0, #1 - strb r0, [r1] -_0803C246: - ldrb r0, [r4, #0xe] - subs r0, #1 - strb r0, [r4, #0xe] - movs r3, #0xff - lsls r0, r0, #0x18 - cmp r0, #0 - bne _0803C292 - adds r1, r4, #0 - adds r1, #0x80 - ldrb r0, [r1] - adds r2, r0, #1 - strb r2, [r1] - adds r0, r2, #0 - ands r0, r3 - cmp r0, #0xf - bls _0803C26E - adds r0, r4, #0 - bl sub_0803C5C4 - b _0803C2D2 -_0803C26E: - movs r0, #3 - ands r2, r0 - cmp r2, #0 - bne _0803C28A - bl Random - movs r1, #0x10 - ands r1, r0 - cmp r1, #0 - beq _0803C28A - adds r0, r4, #0 - bl sub_0803C624 - b _0803C2D2 -_0803C28A: - adds r0, r4, #0 - bl sub_0803C4B0 - b _0803C2D2 -_0803C292: - adds r0, r4, #0 - bl sub_0803C6F8 - cmp r0, #0 - beq _0803C2C2 - ldrh r1, [r4, #0x2a] - adds r0, r4, #0 - bl sub_0800417E - ldrb r0, [r4, #0x15] - adds r0, #4 - movs r1, #0x18 - ands r0, r1 - asrs r0, r0, #2 - strb r0, [r4, #0x14] - adds r1, r4, #0 - adds r1, #0x83 - ldrb r0, [r1] - adds r0, #1 - strb r0, [r1] - adds r0, r4, #0 - bl sub_0803C690 - b _0803C2D2 -_0803C2C2: - adds r0, r4, #0 - bl sub_0803C568 - cmp r0, #0 - beq _0803C2D2 - adds r0, r4, #0 - bl sub_0803C5F0 -_0803C2D2: - adds r0, r4, #0 - bl sub_0803C6DC - pop {r4, pc} - .align 2, 0 - - thumb_func_start sub_0803C2DC -sub_0803C2DC: @ 0x0803C2DC - push {r4, lr} - adds r4, r0, #0 - ldrb r0, [r4, #0xe] - subs r0, #1 - strb r0, [r4, #0xe] - lsls r0, r0, #0x18 - lsrs r1, r0, #0x18 - cmp r1, #0 - bne _0803C308 - movs r0, #3 - strb r0, [r4, #0xc] - adds r0, r4, #0 - adds r0, #0x82 - strb r1, [r0] - subs r0, #2 - strb r1, [r0] - movs r0, #0x10 - strb r0, [r4, #0x14] - adds r0, r4, #0 - bl sub_0803C4B0 - b _0803C31E -_0803C308: - adds r0, r4, #0 - bl sub_0803C568 - cmp r0, #0 - beq _0803C31E - adds r2, r4, #0 - adds r2, #0x7b - ldrb r0, [r2] - movs r1, #1 - orrs r0, r1 - strb r0, [r2] -_0803C31E: - ldrb r0, [r4, #0xf] - cmp r0, #0xb - bls _0803C336 - adds r0, r4, #0 - adds r0, #0x7b - ldrb r0, [r0] - cmp r0, #0 - beq _0803C33A - adds r0, r4, #0 - bl sub_0803C5F0 - b _0803C33A -_0803C336: - adds r0, #1 - strb r0, [r4, #0xf] -_0803C33A: - adds r0, r4, #0 - bl sub_0803C6DC - pop {r4, pc} - .align 2, 0 - - thumb_func_start sub_0803C344 -sub_0803C344: @ 0x0803C344 - push {r4, lr} - adds r4, r0, #0 - ldrb r0, [r4, #0xe] - subs r0, #1 - strb r0, [r4, #0xe] - lsls r0, r0, #0x18 - cmp r0, #0 - bne _0803C3F8 - adds r0, r4, #0 - adds r0, #0x82 - ldrb r1, [r0] - adds r2, r0, #0 - cmp r1, #5 - bhi _0803C3C8 - lsls r0, r1, #2 - ldr r1, _0803C36C @ =_0803C370 - adds r0, r0, r1 - ldr r0, [r0] - mov pc, r0 - .align 2, 0 -_0803C36C: .4byte _0803C370 -_0803C370: @ jump table - .4byte _0803C3C8 @ case 0 - .4byte _0803C3C8 @ case 1 - .4byte _0803C3A6 @ case 2 - .4byte _0803C388 @ case 3 - .4byte _0803C3BE @ case 4 - .4byte _0803C39C @ case 5 -_0803C388: - movs r0, #4 - strb r0, [r4, #0xc] - movs r0, #0x80 - strh r0, [r4, #0x24] - adds r0, r4, #0 - movs r1, #1 - bl sub_08049F84 - strb r0, [r4, #0x15] - b _0803C3E2 -_0803C39C: - movs r0, #4 - strb r0, [r4, #0xc] - movs r0, #0x80 - strh r0, [r4, #0x24] - b _0803C3E2 -_0803C3A6: - movs r1, #0 - movs r0, #2 - strb r0, [r4, #0xc] - strh r1, [r4, #0x24] - bl Random - movs r1, #7 - ands r0, r1 - lsls r1, r0, #1 - adds r1, r1, r0 - adds r1, #0x40 - b _0803C3E0 -_0803C3BE: - ldrb r0, [r4, #0x15] - adds r0, #0x10 - movs r1, #0x18 - ands r0, r1 - strb r0, [r4, #0x15] -_0803C3C8: - movs r0, #1 - strb r0, [r4, #0xc] - strb r0, [r2] - movs r0, #0x80 - strh r0, [r4, #0x24] - bl Random - movs r1, #7 - ands r0, r1 - lsls r1, r0, #1 - adds r1, r1, r0 - adds r1, #0x22 -_0803C3E0: - strb r1, [r4, #0xe] -_0803C3E2: - movs r0, #0 - strb r0, [r4, #0xf] - ldrb r0, [r4, #0x15] - adds r0, #4 - movs r1, #0x18 - ands r0, r1 - asrs r0, r0, #2 - strb r0, [r4, #0x14] - adds r0, r4, #0 - bl sub_0803C690 -_0803C3F8: - adds r0, r4, #0 - bl sub_0803C6DC - pop {r4, pc} - - thumb_func_start sub_0803C400 -sub_0803C400: @ 0x0803C400 - push {r4, r5, lr} - adds r4, r0, #0 - ldrb r0, [r4, #0xf] - adds r1, r0, #0 - cmp r1, #0 - beq _0803C458 - subs r0, #1 - strb r0, [r4, #0xf] - movs r2, #0xff - lsls r0, r0, #0x18 - lsrs r5, r0, #0x18 - cmp r5, #0 - bne _0803C4AC - adds r0, r4, #0 - adds r0, #0x82 - ldrb r0, [r0] - cmp r0, #3 - bne _0803C450 - adds r1, r4, #0 - adds r1, #0x7a - ldrb r0, [r1] - adds r0, #1 - strb r0, [r1] - ands r0, r2 - cmp r0, #2 - bhi _0803C450 - bl Random - movs r1, #0xc0 - ands r1, r0 - cmp r1, #0 - beq _0803C450 - strb r5, [r4, #0xe] - adds r0, r4, #0 - bl sub_0803C690 - adds r0, r4, #0 - bl sub_0803C6DC - b _0803C4AC -_0803C450: - adds r0, r4, #0 - bl sub_0803C634 - b _0803C4AC -_0803C458: - ldrb r0, [r4, #0xe] - adds r0, #1 - strb r0, [r4, #0xe] - lsls r0, r0, #0x18 - lsrs r0, r0, #0x18 - cmp r0, #1 - beq _0803C46C - cmp r0, #0x18 - beq _0803C494 - b _0803C49A -_0803C46C: - ldrb r2, [r4, #0x14] - lsls r0, r2, #2 - strb r0, [r4, #0x15] - lsls r2, r2, #0x18 - lsrs r2, r2, #0x19 - adds r0, r4, #0 - movs r1, #0xd - bl CreateProjectileWithParent - adds r2, r0, #0 - cmp r2, #0 - beq _0803C49A - str r2, [r4, #0x54] - ldrb r0, [r4, #0x15] - adds r0, #4 - movs r1, #0x18 - ands r0, r1 - strb r0, [r2, #0x15] - str r4, [r2, #0x50] - b _0803C49A -_0803C494: - strb r1, [r4, #0xe] - movs r0, #0x20 - strb r0, [r4, #0xf] -_0803C49A: - adds r0, r4, #0 - bl sub_0803C6DC - ldr r0, [r4, #0x54] - cmp r0, #0 - beq _0803C4AC - adds r0, r4, #0 - bl sub_0803C714 -_0803C4AC: - pop {r4, r5, pc} - .align 2, 0 - - thumb_func_start sub_0803C4B0 -sub_0803C4B0: @ 0x0803C4B0 - push {r4, r5, r6, r7, lr} - adds r5, r0, #0 - movs r1, #0 - strb r1, [r5, #0xf] - adds r0, #0x82 - ldrb r0, [r0] - cmp r0, #1 - bne _0803C54C - bl Random - ldr r1, _0803C4F0 @ =gUnk_080CFFA4 - movs r7, #7 - ands r0, r7 - adds r0, r0, r1 - ldrb r0, [r0] - strb r0, [r5, #0xe] - movs r0, #0x80 - strh r0, [r5, #0x24] - adds r0, r5, #0 - bl sub_08049FA0 - cmp r0, #0 - beq _0803C4F4 - bl Random - adds r4, r0, #0 - movs r0, #6 - ands r4, r0 - lsls r0, r4, #2 - strb r0, [r5, #0x15] - b _0803C556 - .align 2, 0 -_0803C4F0: .4byte gUnk_080CFFA4 -_0803C4F4: - adds r0, r5, #0 - bl sub_08049EE4 - adds r4, r0, #0 - adds r6, r5, #0 - adds r6, #0x83 - ldrb r0, [r6] - cmp r0, #0 - bne _0803C520 - bl Random - ldr r2, _0803C51C @ =gUnk_080CFFAC - movs r1, #0xf - ands r1, r0 - adds r1, r1, r2 - movs r0, #0 - ldrsb r0, [r1, r0] - adds r4, r4, r0 - b _0803C53E - .align 2, 0 -_0803C51C: .4byte gUnk_080CFFAC -_0803C520: - bl Random - ldr r1, _0803C548 @ =gUnk_080CFFAC - ands r0, r7 - adds r0, r0, r1 - ldrb r0, [r0] - lsls r0, r0, #0x18 - asrs r0, r0, #0x18 - adds r4, r4, r0 - ldrb r0, [r5, #0xe] - adds r0, #0x10 - strb r0, [r5, #0xe] - ldrb r0, [r6] - subs r0, #1 - strb r0, [r6] -_0803C53E: - adds r0, r4, #4 - movs r1, #0x18 - ands r0, r1 - strb r0, [r5, #0x15] - b _0803C554 - .align 2, 0 -_0803C548: .4byte gUnk_080CFFAC -_0803C54C: - movs r0, #0xc - strb r0, [r5, #0xe] - strh r1, [r5, #0x24] - ldrb r0, [r5, #0x15] -_0803C554: - lsrs r4, r0, #2 -_0803C556: - ldrb r0, [r5, #0x14] - cmp r4, r0 - beq _0803C564 - strb r4, [r5, #0x14] - adds r0, r5, #0 - bl sub_0803C690 -_0803C564: - pop {r4, r5, r6, r7, pc} - .align 2, 0 - - thumb_func_start sub_0803C568 -sub_0803C568: @ 0x0803C568 - push {r4, r5, lr} - adds r5, r0, #0 - adds r0, #0x81 - ldrb r0, [r0] - cmp r0, #0 - bne _0803C5C0 - movs r0, #1 - bl sub_08049DF4 - adds r4, r0, #0 - cmp r4, #0 - beq _0803C5C0 - adds r0, r5, #0 - adds r0, #0x82 - ldrb r0, [r0] - cmp r0, #2 - bne _0803C598 - adds r0, r5, #0 - adds r1, r4, #0 - movs r2, #0x30 - bl sub_0806FC80 - cmp r0, #0 - bne _0803C5BC -_0803C598: - adds r0, r5, #0 - adds r1, r4, #0 - movs r2, #0x40 - bl sub_0806FC80 - cmp r0, #0 - beq _0803C5C0 - adds r0, r5, #0 - adds r1, r4, #0 - bl GetFacingDirection - adds r0, #4 - movs r1, #0x18 - ands r0, r1 - lsrs r0, r0, #2 - ldrb r5, [r5, #0x14] - cmp r0, r5 - bne _0803C5C0 -_0803C5BC: - movs r0, #1 - b _0803C5C2 -_0803C5C0: - movs r0, #0 -_0803C5C2: - pop {r4, r5, pc} - - thumb_func_start sub_0803C5C4 -sub_0803C5C4: @ 0x0803C5C4 - push {r4, lr} - adds r4, r0, #0 - ldrb r0, [r4, #0x15] - adds r0, #4 - movs r1, #0x18 - ands r0, r1 - asrs r0, r0, #2 - strb r0, [r4, #0x14] - lsls r0, r0, #2 - strb r0, [r4, #0x15] - adds r1, r4, #0 - adds r1, #0x83 - ldrb r0, [r1] - lsrs r0, r0, #1 - strb r0, [r1] - adds r0, r4, #0 - bl sub_0803C664 - adds r4, #0x82 - movs r0, #2 - strb r0, [r4] - pop {r4, pc} - - thumb_func_start sub_0803C5F0 -sub_0803C5F0: @ 0x0803C5F0 - push {r4, lr} - adds r4, r0, #0 - movs r1, #1 - bl sub_08049F84 - movs r2, #0 - strb r0, [r4, #0x15] - ldrb r0, [r4, #0x15] - adds r0, #4 - movs r1, #0x18 - ands r0, r1 - asrs r0, r0, #2 - strb r0, [r4, #0x14] - adds r0, r4, #0 - adds r0, #0x83 - strb r2, [r0] - subs r0, #9 - strb r2, [r0] - adds r0, r4, #0 - bl sub_0803C664 - adds r4, #0x82 - movs r0, #3 - strb r0, [r4] - pop {r4, pc} - .align 2, 0 - - thumb_func_start sub_0803C624 -sub_0803C624: @ 0x0803C624 - push {r4, lr} - adds r4, r0, #0 - bl sub_0803C664 - adds r4, #0x82 - movs r0, #5 - strb r0, [r4] - pop {r4, pc} - - thumb_func_start sub_0803C634 -sub_0803C634: @ 0x0803C634 - push {r4, lr} - adds r4, r0, #0 - ldrb r0, [r4, #0x15] - adds r0, #4 - movs r1, #0x18 - ands r0, r1 - asrs r0, r0, #2 - movs r1, #0 - strb r0, [r4, #0x14] - lsls r0, r0, #2 - strb r0, [r4, #0x15] - adds r0, r4, #0 - adds r0, #0x83 - strb r1, [r0] - adds r0, r4, #0 - bl sub_0803C664 - ldrb r0, [r4, #0xe] - lsls r0, r0, #1 - strb r0, [r4, #0xe] - adds r4, #0x82 - movs r0, #4 - strb r0, [r4] - pop {r4, pc} - - thumb_func_start sub_0803C664 -sub_0803C664: @ 0x0803C664 - push {lr} - adds r2, r0, #0 - movs r1, #0 - movs r0, #3 - strb r0, [r2, #0xc] - movs r0, #0x20 - strb r0, [r2, #0xe] - strb r1, [r2, #0xf] - adds r0, r2, #0 - adds r0, #0x80 - strb r1, [r0] - subs r0, #5 - strb r1, [r0] - movs r0, #0 - strh r1, [r2, #0x24] - adds r1, r2, #0 - adds r1, #0x82 - strb r0, [r1] - adds r0, r2, #0 - bl sub_0803C690 - pop {pc} - - thumb_func_start sub_0803C690 -sub_0803C690: @ 0x0803C690 - push {lr} - adds r3, r0, #0 - ldrb r0, [r3, #0x14] - lsrs r2, r0, #1 - adds r0, r3, #0 - adds r0, #0x82 - ldrb r0, [r0] - cmp r0, #5 - bhi _0803C6D2 - lsls r0, r0, #2 - ldr r1, _0803C6AC @ =_0803C6B0 - adds r0, r0, r1 - ldr r0, [r0] - mov pc, r0 - .align 2, 0 -_0803C6AC: .4byte _0803C6B0 -_0803C6B0: @ jump table - .4byte _0803C6D2 @ case 0 - .4byte _0803C6C8 @ case 1 - .4byte _0803C6D0 @ case 2 - .4byte _0803C6CC @ case 3 - .4byte _0803C6C8 @ case 4 - .4byte _0803C6CC @ case 5 -_0803C6C8: - adds r2, #4 - b _0803C6D2 -_0803C6CC: - adds r2, #8 - b _0803C6D2 -_0803C6D0: - adds r2, #0xc -_0803C6D2: - adds r0, r3, #0 - adds r1, r2, #0 - bl InitializeAnimation - pop {pc} - - thumb_func_start sub_0803C6DC -sub_0803C6DC: @ 0x0803C6DC - push {r4, lr} - adds r4, r0, #0 - adds r0, #0x82 - ldrb r0, [r0] - cmp r0, #0 - bne _0803C6EA - strh r0, [r4, #0x24] -_0803C6EA: - adds r0, r4, #0 - bl ProcessMovement - adds r0, r4, #0 - bl GetNextFrame - pop {r4, pc} - - thumb_func_start sub_0803C6F8 -sub_0803C6F8: @ 0x0803C6F8 - ldr r2, _0803C710 @ =gUnk_080CFFBC - ldrb r1, [r0, #0x14] - lsrs r1, r1, #1 - lsls r1, r1, #1 - adds r1, r1, r2 - ldrh r0, [r0, #0x2a] - ldrh r1, [r1] - ands r1, r0 - rsbs r0, r1, #0 - orrs r0, r1 - lsrs r0, r0, #0x1f - bx lr - .align 2, 0 -_0803C710: .4byte gUnk_080CFFBC - - thumb_func_start sub_0803C714 -sub_0803C714: @ 0x0803C714 - push {lr} - ldr r1, [r0, #0x54] - ldrb r3, [r0, #0x14] - ldr r2, _0803C734 @ =gUnk_080CFFC4 - adds r3, r3, r2 - movs r2, #0 - ldrsb r2, [r3, r2] - lsls r2, r2, #0x10 - ldrb r3, [r3, #1] - lsls r3, r3, #0x18 - asrs r3, r3, #0x18 - lsls r3, r3, #0x10 - bl PositionRelative - pop {pc} - .align 2, 0 -_0803C734: .4byte gUnk_080CFFC4 diff --git a/asm/non_matching/bowMoblin/sub_0803C4B0.inc b/asm/non_matching/bowMoblin/sub_0803C4B0.inc new file mode 100644 index 00000000..4e3a0ffb --- /dev/null +++ b/asm/non_matching/bowMoblin/sub_0803C4B0.inc @@ -0,0 +1,98 @@ + + + .syntax unified + + .text + + push {r4, r5, r6, r7, lr} + adds r5, r0, #0 + movs r1, #0 + strb r1, [r5, #0xf] + adds r0, #0x82 + ldrb r0, [r0] + cmp r0, #1 + bne _0803C54C + bl Random + ldr r1, _0803C4F0 @ =gUnk_080CFFA4 + movs r7, #7 + ands r0, r7 + adds r0, r0, r1 + ldrb r0, [r0] + strb r0, [r5, #0xe] + movs r0, #0x80 + strh r0, [r5, #0x24] + adds r0, r5, #0 + bl sub_08049FA0 + cmp r0, #0 + beq _0803C4F4 + bl Random + adds r4, r0, #0 + movs r0, #6 + ands r4, r0 + lsls r0, r4, #2 + strb r0, [r5, #0x15] + b _0803C556 + .align 2, 0 +_0803C4F0: .4byte gUnk_080CFFA4 +_0803C4F4: + adds r0, r5, #0 + bl sub_08049EE4 + adds r4, r0, #0 + adds r6, r5, #0 + adds r6, #0x83 + ldrb r0, [r6] + cmp r0, #0 + bne _0803C520 + bl Random + ldr r2, _0803C51C @ =gUnk_080CFFAC + movs r1, #0xf + ands r1, r0 + adds r1, r1, r2 + movs r0, #0 + ldrsb r0, [r1, r0] + adds r4, r4, r0 + b _0803C53E + .align 2, 0 +_0803C51C: .4byte gUnk_080CFFAC +_0803C520: + bl Random + ldr r1, _0803C548 @ =gUnk_080CFFAC + ands r0, r7 + adds r0, r0, r1 + ldrb r0, [r0] + lsls r0, r0, #0x18 + asrs r0, r0, #0x18 + adds r4, r4, r0 + ldrb r0, [r5, #0xe] + adds r0, #0x10 + strb r0, [r5, #0xe] + ldrb r0, [r6] + subs r0, #1 + strb r0, [r6] +_0803C53E: + adds r0, r4, #4 + movs r1, #0x18 + ands r0, r1 + strb r0, [r5, #0x15] + b _0803C554 + .align 2, 0 +_0803C548: .4byte gUnk_080CFFAC +_0803C54C: + movs r0, #0xc + strb r0, [r5, #0xe] + strh r1, [r5, #0x24] + ldrb r0, [r5, #0x15] +_0803C554: + lsrs r4, r0, #2 +_0803C556: + ldrb r0, [r5, #0x14] + cmp r4, r0 + beq _0803C564 + strb r4, [r5, #0x14] + adds r0, r5, #0 + bl sub_0803C690 +_0803C564: + pop {r4, r5, r6, r7, pc} + .align 2, 0 + + .syntax divided \ No newline at end of file diff --git a/linker.ld b/linker.ld index 76401066..f3936118 100644 --- a/linker.ld +++ b/linker.ld @@ -438,7 +438,6 @@ SECTIONS { src/enemy/mazaalBracelet.o(.text); asm/enemy/takkuri.o(.text); src/enemy/bowMoblin.o(.text); - asm/enemy/bowMoblin.o(.text); src/enemy/lakitu.o(.text); src/enemy/lakituCloud.o(.text); asm/enemy/enemy49.o(.text); diff --git a/src/enemy/bowMoblin.c b/src/enemy/bowMoblin.c index c9605ce2..74899e8f 100644 --- a/src/enemy/bowMoblin.c +++ b/src/enemy/bowMoblin.c @@ -4,10 +4,27 @@ #include "functions.h" extern void sub_0803C5F0(Entity*); +extern void sub_0803C690(Entity*); +extern void sub_0803C4B0(Entity*); +extern void sub_0803C5C4(Entity*); +extern void sub_0803C624(Entity*); +extern void sub_0803C6DC(Entity*); +extern void sub_0803C714(Entity*); +extern void sub_0803C634(Entity*); +extern u32 sub_0803C6F8(Entity*); +extern u32 sub_0803C568(Entity*); +extern Entity* sub_08049DF4(u32); +extern u32 sub_0806FC80(Entity*, Entity*, s32); +extern void sub_0803C664(Entity*); extern void (*const gUnk_080CFF78[])(Entity*); extern void (*const gUnk_080CFF90[])(Entity*); +extern const s8 gUnk_080CFFC4[8]; +extern const s8 gUnk_080CFFA4[8]; +extern const s8 gUnk_080CFFAC[16]; +extern const u16 gUnk_080CFFBC[4]; + void BowMoblin(Entity* this) { EnemyFunctionHandler(this, gUnk_080CFF78); SetChildOffset(this, 0, 1, -0x18); @@ -35,3 +52,325 @@ void sub_0803C198(Entity* this) { void nullsub_168(Entity* this) { } + +void sub_0803C1E0(Entity* this) { + sub_0804A720(this); + + this->action = 1; + this->field_0x7a.HALF.HI = 0; + this->field_0x80.HALF.LO = 0; + this->field_0x82.HALF.HI = 0; + this->field_0x80.HALF.HI = 0; + this->field_0x7a.HALF.LO = 0; + this->field_0x82.HALF.LO = 1; + + if (this->actionDelay) { + this->animationState = this->type2 << 1; + this->actionDelay = 0x1e; + this->speed = 0x80; + this->direction = this->type2 << 3; + sub_0803C690(this); + } else { + this->animationState = 0x10; + sub_0803C4B0(this); + } +} + +void sub_0803C234(Entity* this) { + u8 mask; + if (this->field_0x80.HALF.HI) { + this->field_0x80.HALF.HI--; + } + mask = 0xff; + if (((--this->actionDelay) & mask) == 0) { + u8 tmp = ++this->field_0x80.HALF.LO; + + if ((tmp) > 0xf) { + sub_0803C5C4(this); + } else if (((this->field_0x80.HALF.LO & 0x3) == 0) && (Random() & 0x10)) { + sub_0803C624(this); + } else { + sub_0803C4B0(this); + } + + } else if (sub_0803C6F8(this)) { + sub_0800417E(this, this->collisions); + this->animationState = ((this->direction + 4) & 0x18) >> 2; + this->field_0x82.HALF.HI++; + sub_0803C690(this); + } else if (sub_0803C568(this)) { + sub_0803C5F0(this); + } + + sub_0803C6DC(this); +} + +void sub_0803C2DC(Entity* this) { + u32 res; + u32 actionDelay = --this->actionDelay; + if (actionDelay == 0) { + this->action = 3; + this->field_0x82.HALF.LO = actionDelay; + this->field_0x80.HALF.LO = actionDelay; + this->animationState = 0x10; + sub_0803C4B0(this); + } else if (res = sub_0803C568(this), res) { + this->field_0x7a.HALF.HI |= 0x1; + } + + if (this->field_0xf > 0xb) { + if (this->field_0x7a.HALF.HI != 0) { + sub_0803C5F0(this); + } + } else { + this->field_0xf++; + } + + sub_0803C6DC(this); +} + +void sub_0803C344(Entity* this) { + if (--this->actionDelay == 0) { + switch (this->field_0x82.HALF.LO) { + case 3: { + this->action = 4; + this->speed = 0x80; + this->direction = sub_08049F84(this, 1); + break; + } + case 5: { + this->action = 4; + this->speed = 0x80; + break; + } + case 2: { + u32 tmp; + this->action = 2; + this->speed = 0; + tmp = Random() & 0x7; + this->actionDelay = (tmp << 1) + tmp + 0x40; + break; + } + case 4: { + this->direction = (this->direction + 0x10) & 0x18; + } + case 0: + case 1: + default: { + u32 tmp; + this->action = 1; + this->field_0x82.HALF.LO = 1; + this->speed = 0x80; + tmp = (Random() & 0x7); + this->actionDelay = (tmp << 1) + tmp + 0x22; + break; + } + } + + this->field_0xf = 0; + this->animationState = ((this->direction + 4) & 0x18) >> 2; + sub_0803C690(this); + } + sub_0803C6DC(this); +} + +void sub_0803C400(Entity* this) { + if (this->field_0xf) { + u8 mask; + this->field_0xf--; + mask = 0xff; + if ((this->field_0xf & mask) == 0) { + if (this->field_0x82.HALF.LO == 3) { + this->field_0x7a.HALF.LO++; + if ((this->field_0x7a.HALF.LO & mask) <= 2) { + if (Random() & 0xc0) { + this->actionDelay = 0; + sub_0803C690(this); + sub_0803C6DC(this); + return; + } + } + } + sub_0803C634(this); + } + } else { + Entity* projectile; + switch (++this->actionDelay) { + case 1: + this->direction = this->animationState << 2; + projectile = CreateProjectileWithParent(this, 0xd, this->animationState >> 1); + if (projectile) { + this->child = projectile; + projectile->direction = (this->direction + 4) & 0x18; + projectile->parent = this; + } + break; + case 24: + this->actionDelay = 0; + this->field_0xf = 0x20; + break; + } + + sub_0803C6DC(this); + if (this->child) { + sub_0803C714(this); + } + } +} + +NONMATCH("asm/non_matching/bowMoblin/sub_0803C4B0.inc", void sub_0803C4B0(Entity* this)) { + u32 dir; + this->field_0xf = 0; + if (this->field_0x82.HALF.LO == 1) { + this->actionDelay = gUnk_080CFFA4[Random() & 7]; + this->speed = 0x80; + + if (sub_08049FA0(this)) { + this->direction = (Random() & 6) << 2; + } else { + dir = sub_08049EE4(this); + if (this->field_0x82.HALF.HI == 0) { + dir += gUnk_080CFFAC[Random() & 0xf]; + } else { + dir += gUnk_080CFFAC[Random() & 0x7]; + this->actionDelay += 0x10; + this->field_0x82.HALF.HI--; + } + + dir = (dir + 4) & 0x18; + this->direction = dir; + dir <<= 2; + } + } else { + this->actionDelay = 0xc; + this->speed = this->field_0xf; + dir = this->direction; + dir <<= 2; + } + + if (this->animationState != dir) { + this->animationState = dir; + sub_0803C690(this); + } +} +END_NONMATCH + +u32 sub_0803C568(Entity* this) { + if (this->field_0x80.HALF.HI == 0) { + Entity* ent = sub_08049DF4(1); + if (ent) { + if (this->field_0x82.HALF.LO == 2) { + if (sub_0806FC80(this, ent, 0x30)) { + return 1; + } + } + + if (sub_0806FC80(this, ent, 0x40)) { + u32 direction = (GetFacingDirection(this, ent) + 4) & 0x18; + direction = direction >> 2; + if (direction == this->animationState) { + return 1; + } + } + } + } + + return 0; +} + +void sub_0803C5C4(Entity* this) { + u32 state = ((this->direction + 4) & 0x18) >> 2; + this->animationState = state; + this->direction = state << 2; + this->field_0x82.HALF.HI >>= 1; + sub_0803C664(this); + this->field_0x82.HALF.LO = 2; +} + +void sub_0803C5F0(Entity* this) { + this->direction = sub_08049F84(this, 1); + this->animationState = ((this->direction + 4) & 0x18) >> 2; + this->field_0x82.HALF.HI = 0; + this->field_0x7a.HALF.LO = 0; + sub_0803C664(this); + this->field_0x82.HALF.LO = 3; +} + +void sub_0803C624(Entity* this) { + sub_0803C664(this); + this->field_0x82.HALF.LO = 5; +} + +void sub_0803C634(Entity* this) { + this->animationState = ((this->direction + 4) & 0x18) >> 2; + this->direction = this->animationState << 2; + this->field_0x82.HALF.HI = 0; + sub_0803C664(this); + this->actionDelay <<= 1; + this->field_0x82.HALF.LO = 4; +} + +void sub_0803C664(Entity* this) { + this->action = 3; + this->actionDelay = 0x20; + this->field_0xf = 0; + this->field_0x80.HALF.LO = 0; + this->field_0x7a.HALF.HI = 0; + this->speed = 0; + this->field_0x82.HALF.LO = 0; + sub_0803C690(this); +} + +void sub_0803C690(Entity* this) { + u32 tmp = this->animationState >> 1; + switch (this->field_0x82.HALF.LO) { + case 1: + case 4: { + tmp += 0x4; + break; + } + case 3: + case 5: { + tmp += 0x8; + break; + } + case 2: { + tmp += 0xc; + break; + } + case 0: { + break; + } + } + + InitializeAnimation(this, tmp); +} + +void sub_0803C6DC(Entity* this) { + u8 tmp = this->field_0x82.HALF.LO; + if (tmp == 0) { + this->speed = tmp; + } + + ProcessMovement(this); + GetNextFrame(this); +} + +u32 sub_0803C6F8(Entity* this) { + u32 tmp = (this->collisions & gUnk_080CFFBC[(this->animationState ^ 1) / 2]); + u32 tmp2 = -tmp; + return (tmp2 | tmp) >> 0x1f; +} + +void sub_0803C714(Entity* this) { + Entity* child = this->child; // Unused + const s8* tmp; + u32 offsetX; + u32 offsetY; + tmp = &gUnk_080CFFC4[this->animationState]; + // TODO fix array access + offsetX = tmp[0] << 0x10; + offsetY = tmp[1] << 0x10; + + PositionRelative(this, child, offsetX, offsetY); +} From 87514fcbf70a4090abcb908e264535e5f6446659 Mon Sep 17 00:00:00 2001 From: Ibot02 Date: Thu, 30 Dec 2021 10:51:40 +0100 Subject: [PATCH 2/4] bowMoblin.c: fix nonmatching --- asm/non_matching/bowMoblin/sub_0803C4B0.inc | 98 --------------------- src/enemy/bowMoblin.c | 19 ++-- 2 files changed, 7 insertions(+), 110 deletions(-) delete mode 100644 asm/non_matching/bowMoblin/sub_0803C4B0.inc diff --git a/asm/non_matching/bowMoblin/sub_0803C4B0.inc b/asm/non_matching/bowMoblin/sub_0803C4B0.inc deleted file mode 100644 index 4e3a0ffb..00000000 --- a/asm/non_matching/bowMoblin/sub_0803C4B0.inc +++ /dev/null @@ -1,98 +0,0 @@ - - - .syntax unified - - .text - - push {r4, r5, r6, r7, lr} - adds r5, r0, #0 - movs r1, #0 - strb r1, [r5, #0xf] - adds r0, #0x82 - ldrb r0, [r0] - cmp r0, #1 - bne _0803C54C - bl Random - ldr r1, _0803C4F0 @ =gUnk_080CFFA4 - movs r7, #7 - ands r0, r7 - adds r0, r0, r1 - ldrb r0, [r0] - strb r0, [r5, #0xe] - movs r0, #0x80 - strh r0, [r5, #0x24] - adds r0, r5, #0 - bl sub_08049FA0 - cmp r0, #0 - beq _0803C4F4 - bl Random - adds r4, r0, #0 - movs r0, #6 - ands r4, r0 - lsls r0, r4, #2 - strb r0, [r5, #0x15] - b _0803C556 - .align 2, 0 -_0803C4F0: .4byte gUnk_080CFFA4 -_0803C4F4: - adds r0, r5, #0 - bl sub_08049EE4 - adds r4, r0, #0 - adds r6, r5, #0 - adds r6, #0x83 - ldrb r0, [r6] - cmp r0, #0 - bne _0803C520 - bl Random - ldr r2, _0803C51C @ =gUnk_080CFFAC - movs r1, #0xf - ands r1, r0 - adds r1, r1, r2 - movs r0, #0 - ldrsb r0, [r1, r0] - adds r4, r4, r0 - b _0803C53E - .align 2, 0 -_0803C51C: .4byte gUnk_080CFFAC -_0803C520: - bl Random - ldr r1, _0803C548 @ =gUnk_080CFFAC - ands r0, r7 - adds r0, r0, r1 - ldrb r0, [r0] - lsls r0, r0, #0x18 - asrs r0, r0, #0x18 - adds r4, r4, r0 - ldrb r0, [r5, #0xe] - adds r0, #0x10 - strb r0, [r5, #0xe] - ldrb r0, [r6] - subs r0, #1 - strb r0, [r6] -_0803C53E: - adds r0, r4, #4 - movs r1, #0x18 - ands r0, r1 - strb r0, [r5, #0x15] - b _0803C554 - .align 2, 0 -_0803C548: .4byte gUnk_080CFFAC -_0803C54C: - movs r0, #0xc - strb r0, [r5, #0xe] - strh r1, [r5, #0x24] - ldrb r0, [r5, #0x15] -_0803C554: - lsrs r4, r0, #2 -_0803C556: - ldrb r0, [r5, #0x14] - cmp r4, r0 - beq _0803C564 - strb r4, [r5, #0x14] - adds r0, r5, #0 - bl sub_0803C690 -_0803C564: - pop {r4, r5, r6, r7, pc} - .align 2, 0 - - .syntax divided \ No newline at end of file diff --git a/src/enemy/bowMoblin.c b/src/enemy/bowMoblin.c index 74899e8f..5f945054 100644 --- a/src/enemy/bowMoblin.c +++ b/src/enemy/bowMoblin.c @@ -218,15 +218,16 @@ void sub_0803C400(Entity* this) { } } -NONMATCH("asm/non_matching/bowMoblin/sub_0803C4B0.inc", void sub_0803C4B0(Entity* this)) { +void sub_0803C4B0(Entity* this) { u32 dir; this->field_0xf = 0; if (this->field_0x82.HALF.LO == 1) { this->actionDelay = gUnk_080CFFA4[Random() & 7]; this->speed = 0x80; - if (sub_08049FA0(this)) { - this->direction = (Random() & 6) << 2; + dir = Random(); + dir &= 6; + this->direction = dir << 2; } else { dir = sub_08049EE4(this); if (this->field_0x82.HALF.HI == 0) { @@ -236,24 +237,18 @@ NONMATCH("asm/non_matching/bowMoblin/sub_0803C4B0.inc", void sub_0803C4B0(Entity this->actionDelay += 0x10; this->field_0x82.HALF.HI--; } - - dir = (dir + 4) & 0x18; - this->direction = dir; - dir <<= 2; + dir = (this->direction = (dir + 4) & 0x18) >> 2; } } else { this->actionDelay = 0xc; this->speed = this->field_0xf; - dir = this->direction; - dir <<= 2; + dir = this->direction >> 2; } - - if (this->animationState != dir) { + if (dir != this->animationState) { this->animationState = dir; sub_0803C690(this); } } -END_NONMATCH u32 sub_0803C568(Entity* this) { if (this->field_0x80.HALF.HI == 0) { From a139e43d933bcb9b6baf79c0c68ce4b16e649bfa Mon Sep 17 00:00:00 2001 From: Tal Hayon Date: Thu, 30 Dec 2021 13:38:55 +0200 Subject: [PATCH 3/4] Use new Entity style --- src/enemy/bowMoblin.c | 325 ++++++++++++++++++++++-------------------- 1 file changed, 169 insertions(+), 156 deletions(-) diff --git a/src/enemy/bowMoblin.c b/src/enemy/bowMoblin.c index 5f945054..97b79a21 100644 --- a/src/enemy/bowMoblin.c +++ b/src/enemy/bowMoblin.c @@ -1,21 +1,34 @@ +#define NENT_DEPRECATED #include "global.h" #include "entity.h" #include "enemy.h" #include "functions.h" -extern void sub_0803C5F0(Entity*); -extern void sub_0803C690(Entity*); -extern void sub_0803C4B0(Entity*); -extern void sub_0803C5C4(Entity*); -extern void sub_0803C624(Entity*); -extern void sub_0803C6DC(Entity*); -extern void sub_0803C714(Entity*); -extern void sub_0803C634(Entity*); -extern u32 sub_0803C6F8(Entity*); -extern u32 sub_0803C568(Entity*); +typedef struct { + Entity base; + u8 filler[0x12]; + u8 unk_0x7a; + u8 unk_0x7b; + u8 filter[0x4]; + u8 unk_0x80; + u8 unk_0x81; + u8 unk_0x82; + u8 unk_0x83; +} BowMoblinEntity; + +void sub_0803C5F0(BowMoblinEntity*); +void sub_0803C690(BowMoblinEntity*); +void sub_0803C4B0(BowMoblinEntity*); +void sub_0803C5C4(BowMoblinEntity*); +void sub_0803C624(BowMoblinEntity*); +void sub_0803C6DC(BowMoblinEntity*); +void sub_0803C714(BowMoblinEntity*); +void sub_0803C634(BowMoblinEntity*); +u32 sub_0803C6F8(BowMoblinEntity*); +u32 sub_0803C568(BowMoblinEntity*); extern Entity* sub_08049DF4(u32); extern u32 sub_0806FC80(Entity*, Entity*, s32); -extern void sub_0803C664(Entity*); +void sub_0803C664(BowMoblinEntity*); extern void (*const gUnk_080CFF78[])(Entity*); extern void (*const gUnk_080CFF90[])(Entity*); @@ -30,73 +43,73 @@ void BowMoblin(Entity* this) { SetChildOffset(this, 0, 1, -0x18); } -void sub_0803C180(Entity* this) { - gUnk_080CFF90[this->action](this); +void sub_0803C180(BowMoblinEntity* this) { + gUnk_080CFF90[super->action](super); } -void sub_0803C198(Entity* this) { +void sub_0803C198(BowMoblinEntity* this) { Entity* pEVar1; - if (this->field_0x43 != 0) { - sub_0804A9FC(this, 0x1c); + if (super->field_0x43 != 0) { + sub_0804A9FC(super, 0x1c); } - sub_0804AA30(this, gUnk_080CFF78); - if ((this->bitfield & 0x80) != 0) { + sub_0804AA30(super, gUnk_080CFF78); + if ((super->bitfield & 0x80) != 0) { sub_0803C5F0(this); - pEVar1 = this->child; + pEVar1 = super->child; if (pEVar1 != NULL) { pEVar1->field_0xf++; } } } -void nullsub_168(Entity* this) { +void nullsub_168(BowMoblinEntity* this) { } -void sub_0803C1E0(Entity* this) { - sub_0804A720(this); +void sub_0803C1E0(BowMoblinEntity* this) { + sub_0804A720(super); - this->action = 1; - this->field_0x7a.HALF.HI = 0; - this->field_0x80.HALF.LO = 0; - this->field_0x82.HALF.HI = 0; - this->field_0x80.HALF.HI = 0; - this->field_0x7a.HALF.LO = 0; - this->field_0x82.HALF.LO = 1; + super->action = 1; + this->unk_0x7b = 0; + this->unk_0x80 = 0; + this->unk_0x83 = 0; + this->unk_0x81 = 0; + this->unk_0x7a = 0; + this->unk_0x82 = 1; - if (this->actionDelay) { - this->animationState = this->type2 << 1; - this->actionDelay = 0x1e; - this->speed = 0x80; - this->direction = this->type2 << 3; + if (super->actionDelay) { + super->animationState = super->type2 << 1; + super->actionDelay = 0x1e; + super->speed = 0x80; + super->direction = super->type2 << 3; sub_0803C690(this); } else { - this->animationState = 0x10; + super->animationState = 0x10; sub_0803C4B0(this); } } -void sub_0803C234(Entity* this) { +void sub_0803C234(BowMoblinEntity* this) { u8 mask; - if (this->field_0x80.HALF.HI) { - this->field_0x80.HALF.HI--; + if (this->unk_0x81) { + this->unk_0x81--; } mask = 0xff; - if (((--this->actionDelay) & mask) == 0) { - u8 tmp = ++this->field_0x80.HALF.LO; + if (((--super->actionDelay) & mask) == 0) { + u8 tmp = ++this->unk_0x80; if ((tmp) > 0xf) { sub_0803C5C4(this); - } else if (((this->field_0x80.HALF.LO & 0x3) == 0) && (Random() & 0x10)) { + } else if (((this->unk_0x80 & 0x3) == 0) && (Random() & 0x10)) { sub_0803C624(this); } else { sub_0803C4B0(this); } } else if (sub_0803C6F8(this)) { - sub_0800417E(this, this->collisions); - this->animationState = ((this->direction + 4) & 0x18) >> 2; - this->field_0x82.HALF.HI++; + sub_0800417E(super, super->collisions); + super->animationState = ((super->direction + 4) & 0x18) >> 2; + this->unk_0x83++; sub_0803C690(this); } else if (sub_0803C568(this)) { sub_0803C5F0(this); @@ -105,86 +118,86 @@ void sub_0803C234(Entity* this) { sub_0803C6DC(this); } -void sub_0803C2DC(Entity* this) { +void sub_0803C2DC(BowMoblinEntity* this) { u32 res; - u32 actionDelay = --this->actionDelay; + u32 actionDelay = --super->actionDelay; if (actionDelay == 0) { - this->action = 3; - this->field_0x82.HALF.LO = actionDelay; - this->field_0x80.HALF.LO = actionDelay; - this->animationState = 0x10; + super->action = 3; + this->unk_0x82 = actionDelay; + this->unk_0x80 = actionDelay; + super->animationState = 0x10; sub_0803C4B0(this); } else if (res = sub_0803C568(this), res) { - this->field_0x7a.HALF.HI |= 0x1; + this->unk_0x7b |= 0x1; } - if (this->field_0xf > 0xb) { - if (this->field_0x7a.HALF.HI != 0) { + if (super->field_0xf > 0xb) { + if (this->unk_0x7b != 0) { sub_0803C5F0(this); } } else { - this->field_0xf++; + super->field_0xf++; } sub_0803C6DC(this); } -void sub_0803C344(Entity* this) { - if (--this->actionDelay == 0) { - switch (this->field_0x82.HALF.LO) { +void sub_0803C344(BowMoblinEntity* this) { + if (--super->actionDelay == 0) { + switch (this->unk_0x82) { case 3: { - this->action = 4; - this->speed = 0x80; - this->direction = sub_08049F84(this, 1); + super->action = 4; + super->speed = 0x80; + super->direction = sub_08049F84(super, 1); break; } case 5: { - this->action = 4; - this->speed = 0x80; + super->action = 4; + super->speed = 0x80; break; } case 2: { u32 tmp; - this->action = 2; - this->speed = 0; + super->action = 2; + super->speed = 0; tmp = Random() & 0x7; - this->actionDelay = (tmp << 1) + tmp + 0x40; + super->actionDelay = (tmp << 1) + tmp + 0x40; break; } case 4: { - this->direction = (this->direction + 0x10) & 0x18; + super->direction = (super->direction + 0x10) & 0x18; } case 0: case 1: default: { u32 tmp; - this->action = 1; - this->field_0x82.HALF.LO = 1; - this->speed = 0x80; + super->action = 1; + this->unk_0x82 = 1; + super->speed = 0x80; tmp = (Random() & 0x7); - this->actionDelay = (tmp << 1) + tmp + 0x22; + super->actionDelay = (tmp << 1) + tmp + 0x22; break; } } - this->field_0xf = 0; - this->animationState = ((this->direction + 4) & 0x18) >> 2; + super->field_0xf = 0; + super->animationState = ((super->direction + 4) & 0x18) >> 2; sub_0803C690(this); } sub_0803C6DC(this); } -void sub_0803C400(Entity* this) { - if (this->field_0xf) { +void sub_0803C400(BowMoblinEntity* this) { + if (super->field_0xf) { u8 mask; - this->field_0xf--; + super->field_0xf--; mask = 0xff; - if ((this->field_0xf & mask) == 0) { - if (this->field_0x82.HALF.LO == 3) { - this->field_0x7a.HALF.LO++; - if ((this->field_0x7a.HALF.LO & mask) <= 2) { + if ((super->field_0xf & mask) == 0) { + if (this->unk_0x82 == 3) { + this->unk_0x7a++; + if ((this->unk_0x7a & mask) <= 2) { if (Random() & 0xc0) { - this->actionDelay = 0; + super->actionDelay = 0; sub_0803C690(this); sub_0803C6DC(this); return; @@ -195,75 +208,75 @@ void sub_0803C400(Entity* this) { } } else { Entity* projectile; - switch (++this->actionDelay) { + switch (++super->actionDelay) { case 1: - this->direction = this->animationState << 2; - projectile = CreateProjectileWithParent(this, 0xd, this->animationState >> 1); + super->direction = super->animationState << 2; + projectile = CreateProjectileWithParent(super, 0xd, super->animationState >> 1); if (projectile) { - this->child = projectile; - projectile->direction = (this->direction + 4) & 0x18; - projectile->parent = this; + super->child = projectile; + projectile->direction = (super->direction + 4) & 0x18; + projectile->parent = super; } break; case 24: - this->actionDelay = 0; - this->field_0xf = 0x20; + super->actionDelay = 0; + super->field_0xf = 0x20; break; } sub_0803C6DC(this); - if (this->child) { + if (super->child) { sub_0803C714(this); } } } -void sub_0803C4B0(Entity* this) { +void sub_0803C4B0(BowMoblinEntity* this) { u32 dir; - this->field_0xf = 0; - if (this->field_0x82.HALF.LO == 1) { - this->actionDelay = gUnk_080CFFA4[Random() & 7]; - this->speed = 0x80; - if (sub_08049FA0(this)) { + super->field_0xf = 0; + if (this->unk_0x82 == 1) { + super->actionDelay = gUnk_080CFFA4[Random() & 7]; + super->speed = 0x80; + if (sub_08049FA0(super)) { dir = Random(); dir &= 6; - this->direction = dir << 2; + super->direction = dir << 2; } else { - dir = sub_08049EE4(this); - if (this->field_0x82.HALF.HI == 0) { + dir = sub_08049EE4(super); + if (this->unk_0x83 == 0) { dir += gUnk_080CFFAC[Random() & 0xf]; } else { dir += gUnk_080CFFAC[Random() & 0x7]; - this->actionDelay += 0x10; - this->field_0x82.HALF.HI--; + super->actionDelay += 0x10; + this->unk_0x83--; } - dir = (this->direction = (dir + 4) & 0x18) >> 2; + dir = (super->direction = (dir + 4) & 0x18) >> 2; } } else { - this->actionDelay = 0xc; - this->speed = this->field_0xf; - dir = this->direction >> 2; + super->actionDelay = 0xc; + super->speed = super->field_0xf; + dir = super->direction >> 2; } - if (dir != this->animationState) { - this->animationState = dir; + if (dir != super->animationState) { + super->animationState = dir; sub_0803C690(this); } } -u32 sub_0803C568(Entity* this) { - if (this->field_0x80.HALF.HI == 0) { +u32 sub_0803C568(BowMoblinEntity* this) { + if (this->unk_0x81 == 0) { Entity* ent = sub_08049DF4(1); if (ent) { - if (this->field_0x82.HALF.LO == 2) { - if (sub_0806FC80(this, ent, 0x30)) { + if (this->unk_0x82 == 2) { + if (sub_0806FC80(super, ent, 0x30)) { return 1; } } - if (sub_0806FC80(this, ent, 0x40)) { - u32 direction = (GetFacingDirection(this, ent) + 4) & 0x18; + if (sub_0806FC80(super, ent, 0x40)) { + u32 direction = (GetFacingDirection(super, ent) + 4) & 0x18; direction = direction >> 2; - if (direction == this->animationState) { + if (direction == super->animationState) { return 1; } } @@ -273,52 +286,52 @@ u32 sub_0803C568(Entity* this) { return 0; } -void sub_0803C5C4(Entity* this) { - u32 state = ((this->direction + 4) & 0x18) >> 2; - this->animationState = state; - this->direction = state << 2; - this->field_0x82.HALF.HI >>= 1; +void sub_0803C5C4(BowMoblinEntity* this) { + u32 state = ((super->direction + 4) & 0x18) >> 2; + super->animationState = state; + super->direction = state << 2; + this->unk_0x83 >>= 1; sub_0803C664(this); - this->field_0x82.HALF.LO = 2; + this->unk_0x82 = 2; } -void sub_0803C5F0(Entity* this) { - this->direction = sub_08049F84(this, 1); - this->animationState = ((this->direction + 4) & 0x18) >> 2; - this->field_0x82.HALF.HI = 0; - this->field_0x7a.HALF.LO = 0; +void sub_0803C5F0(BowMoblinEntity* this) { + super->direction = sub_08049F84(super, 1); + super->animationState = ((super->direction + 4) & 0x18) >> 2; + this->unk_0x83 = 0; + this->unk_0x7a = 0; sub_0803C664(this); - this->field_0x82.HALF.LO = 3; + this->unk_0x82 = 3; } -void sub_0803C624(Entity* this) { +void sub_0803C624(BowMoblinEntity* this) { sub_0803C664(this); - this->field_0x82.HALF.LO = 5; + this->unk_0x82 = 5; } -void sub_0803C634(Entity* this) { - this->animationState = ((this->direction + 4) & 0x18) >> 2; - this->direction = this->animationState << 2; - this->field_0x82.HALF.HI = 0; +void sub_0803C634(BowMoblinEntity* this) { + super->animationState = ((super->direction + 4) & 0x18) >> 2; + super->direction = super->animationState << 2; + this->unk_0x83 = 0; sub_0803C664(this); - this->actionDelay <<= 1; - this->field_0x82.HALF.LO = 4; + super->actionDelay <<= 1; + this->unk_0x82 = 4; } -void sub_0803C664(Entity* this) { - this->action = 3; - this->actionDelay = 0x20; - this->field_0xf = 0; - this->field_0x80.HALF.LO = 0; - this->field_0x7a.HALF.HI = 0; - this->speed = 0; - this->field_0x82.HALF.LO = 0; +void sub_0803C664(BowMoblinEntity* this) { + super->action = 3; + super->actionDelay = 0x20; + super->field_0xf = 0; + this->unk_0x80 = 0; + this->unk_0x7b = 0; + super->speed = 0; + this->unk_0x82 = 0; sub_0803C690(this); } -void sub_0803C690(Entity* this) { - u32 tmp = this->animationState >> 1; - switch (this->field_0x82.HALF.LO) { +void sub_0803C690(BowMoblinEntity* this) { + u32 tmp = super->animationState >> 1; + switch (this->unk_0x82) { case 1: case 4: { tmp += 0x4; @@ -338,34 +351,34 @@ void sub_0803C690(Entity* this) { } } - InitializeAnimation(this, tmp); + InitializeAnimation(super, tmp); } -void sub_0803C6DC(Entity* this) { - u8 tmp = this->field_0x82.HALF.LO; +void sub_0803C6DC(BowMoblinEntity* this) { + u8 tmp = this->unk_0x82; if (tmp == 0) { - this->speed = tmp; + super->speed = tmp; } - ProcessMovement(this); - GetNextFrame(this); + ProcessMovement(super); + GetNextFrame(super); } -u32 sub_0803C6F8(Entity* this) { - u32 tmp = (this->collisions & gUnk_080CFFBC[(this->animationState ^ 1) / 2]); +u32 sub_0803C6F8(BowMoblinEntity* this) { + u32 tmp = (super->collisions & gUnk_080CFFBC[(super->animationState ^ 1) / 2]); u32 tmp2 = -tmp; return (tmp2 | tmp) >> 0x1f; } -void sub_0803C714(Entity* this) { - Entity* child = this->child; // Unused +void sub_0803C714(BowMoblinEntity* this) { + Entity* child = super->child; // Unused const s8* tmp; u32 offsetX; u32 offsetY; - tmp = &gUnk_080CFFC4[this->animationState]; + tmp = &gUnk_080CFFC4[super->animationState]; // TODO fix array access offsetX = tmp[0] << 0x10; offsetY = tmp[1] << 0x10; - PositionRelative(this, child, offsetX, offsetY); + PositionRelative(super, child, offsetX, offsetY); } From 68973c163ba5f6aa26f03d006f472cac4d682fe3 Mon Sep 17 00:00:00 2001 From: Tal Hayon Date: Fri, 31 Dec 2021 01:06:02 +0200 Subject: [PATCH 4/4] Review Fixes --- include/enemy.h | 2 +- include/entity.h | 4 ++++ include/functions.h | 2 +- src/enemy/bowMoblin.c | 12 ++++++------ src/player.c | 2 -- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/include/enemy.h b/include/enemy.h index 5905ce5b..c4ef561e 100644 --- a/include/enemy.h +++ b/include/enemy.h @@ -12,7 +12,7 @@ #include "entity.h" extern u32 GetNextFunction(Entity*); -extern void EnemyFunctionHandler(Entity*, void (*const func[])(Entity*)); +extern void EnemyFunctionHandler(Entity*, EntityActionArray); extern void sub_08001324(Entity*); extern Entity* sub_0804A9FC(Entity*, u32); diff --git a/include/entity.h b/include/entity.h index 9afeafe1..d98445b4 100644 --- a/include/entity.h +++ b/include/entity.h @@ -149,6 +149,10 @@ typedef struct Entity_ { #endif } Entity; +typedef void(EntityAction)(Entity*); +typedef void(*EntityActionPtr)(Entity*); +typedef void(*const* EntityActionArray)(Entity*); + typedef struct LinkedList { Entity* last; Entity* first; diff --git a/include/functions.h b/include/functions.h index a271ad64..79fe5c2d 100644 --- a/include/functions.h +++ b/include/functions.h @@ -48,7 +48,7 @@ extern void ChangeObjPalette(Entity*, u32); extern void sub_0806FD3C(Entity*); extern void sub_0805ED14(u32*); extern void sub_080A7C18(u32, u32, u32); -extern void sub_0804AA30(Entity*, void (*const funcs[])(Entity*)); +extern void sub_0804AA30(Entity*, EntityActionArray); extern void sub_0804A720(Entity*); extern u32 sub_080AEFE0(Entity*); extern u32 sub_08049FA0(Entity*); diff --git a/src/enemy/bowMoblin.c b/src/enemy/bowMoblin.c index 97b79a21..29fdd6bc 100644 --- a/src/enemy/bowMoblin.c +++ b/src/enemy/bowMoblin.c @@ -30,8 +30,8 @@ extern Entity* sub_08049DF4(u32); extern u32 sub_0806FC80(Entity*, Entity*, s32); void sub_0803C664(BowMoblinEntity*); -extern void (*const gUnk_080CFF78[])(Entity*); -extern void (*const gUnk_080CFF90[])(Entity*); +extern void (*const gUnk_080CFF78[])(BowMoblinEntity*); +extern void (*const gUnk_080CFF90[])(BowMoblinEntity*); extern const s8 gUnk_080CFFC4[8]; extern const s8 gUnk_080CFFA4[8]; @@ -39,12 +39,12 @@ extern const s8 gUnk_080CFFAC[16]; extern const u16 gUnk_080CFFBC[4]; void BowMoblin(Entity* this) { - EnemyFunctionHandler(this, gUnk_080CFF78); + EnemyFunctionHandler(this, (EntityActionArray)gUnk_080CFF78); SetChildOffset(this, 0, 1, -0x18); } void sub_0803C180(BowMoblinEntity* this) { - gUnk_080CFF90[super->action](super); + gUnk_080CFF90[super->action](this); } void sub_0803C198(BowMoblinEntity* this) { @@ -53,7 +53,7 @@ void sub_0803C198(BowMoblinEntity* this) { if (super->field_0x43 != 0) { sub_0804A9FC(super, 0x1c); } - sub_0804AA30(super, gUnk_080CFF78); + sub_0804AA30(super, (EntityActionArray)gUnk_080CFF78); if ((super->bitfield & 0x80) != 0) { sub_0803C5F0(this); pEVar1 = super->child; @@ -371,7 +371,7 @@ u32 sub_0803C6F8(BowMoblinEntity* this) { } void sub_0803C714(BowMoblinEntity* this) { - Entity* child = super->child; // Unused + Entity* child = super->child; const s8* tmp; u32 offsetX; u32 offsetY; diff --git a/src/player.c b/src/player.c index 3a12ef17..65af62d8 100644 --- a/src/player.c +++ b/src/player.c @@ -31,8 +31,6 @@ #define DEFAULT_ANIM 0x100 -typedef void(EntityAction)(Entity*); - static EntityAction PlayerInit; static EntityAction PlayerNormal; // static EntityAction PlayerInit;