From 38011442e000cb8562511506a3e55a1441951a0a Mon Sep 17 00:00:00 2001 From: Tal Hayon Date: Tue, 1 Feb 2022 21:29:06 +0200 Subject: [PATCH] Decompile the rest of cucco --- asm/non_matching/cucco/sub_0806E564.inc | 64 -------------------- asm/non_matching/cucco/sub_0806E5E4.inc | 50 ---------------- asm/non_matching/cucco/sub_0806E6A8.inc | 26 --------- assets/assets.json | 10 ---- data/const/npc/cucco.s | 18 ------ linker.ld | 2 +- src/npc/cucco.c | 78 +++++++++++++++++++++---- 7 files changed, 67 insertions(+), 181 deletions(-) delete mode 100644 asm/non_matching/cucco/sub_0806E564.inc delete mode 100644 asm/non_matching/cucco/sub_0806E5E4.inc delete mode 100644 asm/non_matching/cucco/sub_0806E6A8.inc delete mode 100644 data/const/npc/cucco.s diff --git a/asm/non_matching/cucco/sub_0806E564.inc b/asm/non_matching/cucco/sub_0806E564.inc deleted file mode 100644 index 69dbcecf..00000000 --- a/asm/non_matching/cucco/sub_0806E564.inc +++ /dev/null @@ -1,64 +0,0 @@ - .syntax unified - push {r4, lr} - adds r4, r0, #0 - ldrb r0, [r4, #0xd] - cmp r0, #0 - bne _0806E5AA - adds r0, #1 - strb r0, [r4, #0xd] - bl Random - movs r2, #1 - ands r0, r2 - cmp r0, #0 - beq _0806E590 - ldrb r0, [r4, #0x18] - lsls r1, r0, #0x19 - lsrs r1, r1, #0x1f - eors r1, r2 - lsls r1, r1, #6 - subs r2, #0x42 - ands r2, r0 - orrs r2, r1 - strb r2, [r4, #0x18] -_0806E590: - bl Random - movs r1, #1 - ands r0, r1 - adds r0, #1 - strb r0, [r4, #0xe] - movs r0, #0xc0 - lsls r0, r0, #9 - str r0, [r4, #0x20] - adds r0, r4, #0 - movs r1, #1 - bl InitAnimationForceUpdate -_0806E5AA: - movs r1, #0xa0 - lsls r1, r1, #6 - adds r0, r4, #0 - bl GravityUpdate - cmp r0, #0 - bne _0806E5D4 - ldrb r0, [r4, #0xe] - subs r0, #1 - strb r0, [r4, #0xe] - lsls r0, r0, #0x18 - lsrs r1, r0, #0x18 - cmp r1, #0 - bne _0806E5CE - movs r0, #1 - strb r0, [r4, #0xc] - strb r1, [r4, #0xd] - b _0806E5D4 -_0806E5CE: - movs r0, #0xc0 - lsls r0, r0, #9 - str r0, [r4, #0x20] -_0806E5D4: - adds r0, r4, #0 - bl sub_0806E65C - adds r0, r4, #0 - bl UpdateAnimationSingleFrame - pop {r4, pc} - .align 2, 0 - .syntax divided diff --git a/asm/non_matching/cucco/sub_0806E5E4.inc b/asm/non_matching/cucco/sub_0806E5E4.inc deleted file mode 100644 index 2e2a651e..00000000 --- a/asm/non_matching/cucco/sub_0806E5E4.inc +++ /dev/null @@ -1,50 +0,0 @@ - .syntax unified - push {r4, r5, lr} - adds r4, r0, #0 - ldrb r0, [r4, #0xd] - cmp r0, #0 - bne _0806E622 - adds r0, #1 - strb r0, [r4, #0xd] - bl Random - movs r5, #1 - ands r0, r5 - cmp r0, #0 - beq _0806E612 - ldrb r0, [r4, #0x18] - lsls r1, r0, #0x19 - lsrs r1, r1, #0x1f - eors r1, r5 - lsls r1, r1, #6 - movs r2, #0x41 - rsbs r2, r2, #0 - ands r2, r0 - orrs r2, r1 - strb r2, [r4, #0x18] -_0806E612: - bl Random - adds r1, r0, #0 - ands r1, r5 - adds r1, #2 - adds r0, r4, #0 - bl InitAnimationForceUpdate -_0806E622: - adds r0, r4, #0 - adds r0, #0x5a - ldrb r1, [r0] - movs r0, #0x80 - ands r0, r1 - cmp r0, #0 - beq _0806E638 - movs r1, #0 - movs r0, #1 - strb r0, [r4, #0xc] - strb r1, [r4, #0xd] -_0806E638: - adds r0, r4, #0 - bl sub_0806E65C - adds r0, r4, #0 - bl UpdateAnimationSingleFrame - pop {r4, r5, pc} - .align 2, 0 - .syntax divided diff --git a/asm/non_matching/cucco/sub_0806E6A8.inc b/asm/non_matching/cucco/sub_0806E6A8.inc deleted file mode 100644 index 1c05898d..00000000 --- a/asm/non_matching/cucco/sub_0806E6A8.inc +++ /dev/null @@ -1,26 +0,0 @@ - .syntax unified - push {r4, r5, lr} - adds r4, r0, #0 - movs r5, #0 - bl sub_08002632 - ldr r1, _0806E6D4 @ =gSave - ldr r2, _0806E6D8 @ =0x000001C1 - adds r1, r1, r2 - adds r0, r0, r1 - ldrb r0, [r0] - cmp r0, #0xf3 - bne _0806E6C2 - movs r5, #1 -_0806E6C2: - ldr r0, _0806E6DC @ =gUnk_081145D0 - lsls r1, r5, #1 - adds r1, r1, r0 - ldrh r0, [r1] - adds r1, r4, #0 - bl MessageNoOverlap - pop {r4, r5, pc} - .align 2, 0 -_0806E6D4: .4byte gSave -_0806E6D8: .4byte 0x000001C1 -_0806E6DC: .4byte gUnk_081145D0 - .syntax divided diff --git a/assets/assets.json b/assets/assets.json index bac7cd65..85d863a8 100644 --- a/assets/assets.json +++ b/assets/assets.json @@ -41209,16 +41209,6 @@ "start": 1131772, "size": 64 }, - { - "path": "cucco/gUnk_081145C8.bin", - "start": 1131976, - "size": 8 - }, - { - "path": "cucco/gUnk_081145D0.bin", - "start": 1131984, - "size": 4 - }, { "path": "phonograph/gUnk_081145E4.bin", "start": 1132004, diff --git a/data/const/npc/cucco.s b/data/const/npc/cucco.s deleted file mode 100644 index b5eed6d6..00000000 --- a/data/const/npc/cucco.s +++ /dev/null @@ -1,18 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .section .rodata - .align 2 - -gUnk_081145B4:: @ 081145B4 - .4byte sub_0806E4B8 - .4byte sub_0806E4EC - .4byte sub_0806E564 - .4byte sub_0806E5E4 - .4byte sub_0806E648 - -gUnk_081145C8:: @ 081145C8 - .incbin "cucco/gUnk_081145C8.bin" - -gUnk_081145D0:: @ 081145D0 - .incbin "cucco/gUnk_081145D0.bin" diff --git a/linker.ld b/linker.ld index ded45e35..ab658bd4 100644 --- a/linker.ld +++ b/linker.ld @@ -1323,7 +1323,7 @@ SECTIONS { data/animations/npc/smallTownMinish.o(.rodata); data/const/npc/hurdyGurdyMan.o(.rodata); data/animations/npc/hurdyGurdyMan.o(.rodata); - data/const/npc/cucco.o(.rodata); + src/npc/cucco.o(.rodata); data/const/npc/cuccoChick.o(.rodata); data/const/npc/phonograph.o(.rodata); data/const/npc/npc58.o(.rodata); diff --git a/src/npc/cucco.c b/src/npc/cucco.c index bca662c1..73b17303 100644 --- a/src/npc/cucco.c +++ b/src/npc/cucco.c @@ -1,20 +1,19 @@ #include "npc.h" #include "functions.h" -extern void (*const gUnk_081145B4[])(Entity*); +void (*const Cucco_Actions[])(Entity*); +const u16 Cucco_Sounds[]; +const u16 Cucco_Messages[]; void sub_0806E4EC(Entity*); - -void sub_0806E6A8(Entity*); - -extern u16 gUnk_081145C8[]; +void Cucco_ShowMessage(Entity*); void sub_0806E65C(Entity* this); void Cucco(Entity* this) { - gUnk_081145B4[this->action](this); + Cucco_Actions[this->action](this); } -void sub_0806E4B8(Entity* this) { +void Cucco_Init(Entity* this) { this->action += 1; this->field_0x68.HALF.LO = sub_0801E99C(this); sub_080787A8(this, this->field_0x68.HALF.LO); @@ -37,16 +36,56 @@ void sub_0806E4EC(Entity* this) { } this->subAction = 0; if ((Random() & 1) != 0) { - EnqueueSFX(gUnk_081145C8[Random() & 3]); + EnqueueSFX(Cucco_Sounds[Random() & 3]); } } sub_0806E65C(this); UpdateAnimationSingleFrame(this); } -ASM_FUNC("asm/non_matching/cucco/sub_0806E564.inc", void sub_0806E564(Entity* this)) +void Cucco_Fly(Entity* this) { + if (this->subAction == 0) { + this->subAction++; + if (Random() & 1) { + this->spriteSettings.flipX ^= 1; + } -ASM_FUNC("asm/non_matching/cucco/sub_0806E5E4.inc", void sub_0806E5E4(Entity* this)) + this->actionDelay = (Random() & 1) + 1; + this->zVelocity = 0x18000; + InitAnimationForceUpdate(this, 1); + } + + if (GravityUpdate(this, 0x2800) == 0) { + if (--this->actionDelay == 0) { + this->action = 1; + this->subAction = 0; + } else { + this->zVelocity = 0x18000; + } + } + + sub_0806E65C(this); + UpdateAnimationSingleFrame(this); +} + +void Cucco_Idle(Entity* this) { + if (this->subAction == 0) { + this->subAction++; + if (Random() & 1) { + this->spriteSettings.flipX ^= 1; + } + + InitAnimationForceUpdate(this, (Random() & 1) + 2); + } + + if (this->frame & 0x80) { + this->action = 1; + this->subAction = 0; + } + + sub_0806E65C(this); + UpdateAnimationSingleFrame(this); +} void sub_0806E648(Entity* this) { if (UpdateFuseInteraction(this) != 0) { @@ -61,7 +100,7 @@ void sub_0806E65C(Entity* this) { this->action = 4; sub_0806F118(this); } else { - sub_0806E6A8(this); + Cucco_ShowMessage(this); } } else { ResetPlayerAnimationAndAction(); @@ -71,7 +110,15 @@ void sub_0806E65C(Entity* this) { } } -ASM_FUNC("asm/non_matching/cucco/sub_0806E6A8.inc", void sub_0806E6A8(Entity* this)) +void Cucco_ShowMessage(Entity* this) { + u32 val = 0; + u32 index = sub_08002632(this); + if (gSave.unk1C1[index] == 0xf3) { + val = 1; + } + + MessageNoOverlap(Cucco_Messages[val], this); +} void Cucco_Fusion(Entity* this) { if (this->action == 0) { @@ -82,3 +129,10 @@ void Cucco_Fusion(Entity* this) { UpdateAnimationSingleFrame(this); } } + +void (*const Cucco_Actions[])(Entity*) = { + Cucco_Init, sub_0806E4EC, Cucco_Fly, Cucco_Idle, sub_0806E648, +}; + +const u16 Cucco_Sounds[] = { SFX_VO_CUCCO1, SFX_VO_CUCCO2, SFX_VO_CUCCO3, SFX_VO_CUCCO4 }; +const u16 Cucco_Messages[] = { 0xdb4, 0xdb5 };