diff --git a/asm/bombPeahat.s b/asm/bombPeahat.s index e41bf3b2..86b5a143 100644 --- a/asm/bombPeahat.s +++ b/asm/bombPeahat.s @@ -6,134 +6,6 @@ .text - thumb_func_start sub_0802A84C -sub_0802A84C: @ 0x0802A84C - push {r4, lr} - adds r4, r0, #0 - ldrb r0, [r4, #0xa] - cmp r0, #2 - beq _0802A878 - cmp r0, #3 - beq _0802A894 - ldr r0, _0802A874 @ =gUnk_080CD108 - ldrb r1, [r4, #0xc] - lsls r1, r1, #2 - adds r1, r1, r0 - ldr r1, [r1] - adds r0, r4, #0 - bl _call_via_r1 - adds r0, r4, #0 - bl sub_0802AD54 - b _0802A8A4 - .align 2, 0 -_0802A874: .4byte gUnk_080CD108 -_0802A878: - ldr r0, _0802A890 @ =gUnk_080CD120 - ldrb r1, [r4, #0xc] - lsls r1, r1, #2 - adds r1, r1, r0 - ldr r1, [r1] - adds r0, r4, #0 - bl _call_via_r1 - adds r0, r4, #0 - bl sub_0802B048 - b _0802A8A4 - .align 2, 0 -_0802A890: .4byte gUnk_080CD120 -_0802A894: - ldr r0, _0802A8A8 @ =gUnk_080CD134 - ldrb r1, [r4, #0xc] - lsls r1, r1, #2 - adds r1, r1, r0 - ldr r1, [r1] - adds r0, r4, #0 - bl _call_via_r1 -_0802A8A4: - pop {r4, pc} - .align 2, 0 -_0802A8A8: .4byte gUnk_080CD134 - - thumb_func_start sub_0802A8AC -sub_0802A8AC: @ 0x0802A8AC - push {lr} - adds r1, r0, #0 - adds r2, r1, #0 - adds r2, #0x81 - movs r0, #0 - strb r0, [r2] - ldrb r0, [r1, #0xa] - cmp r0, #1 - bhi _0802A8C6 - adds r0, r1, #0 - movs r1, #0 - bl InitializeAnimation -_0802A8C6: - pop {pc} - - thumb_func_start sub_0802A8C8 -sub_0802A8C8: @ 0x0802A8C8 - push {lr} - ldr r2, _0802A8DC @ =gUnk_080CD140 - ldrb r1, [r0, #0xd] - lsls r1, r1, #2 - adds r1, r1, r2 - ldr r1, [r1] - bl _call_via_r1 - pop {pc} - .align 2, 0 -_0802A8DC: .4byte gUnk_080CD140 - - thumb_func_start sub_0802A8E0 -sub_0802A8E0: @ 0x0802A8E0 - movs r1, #1 - strb r1, [r0, #0xd] - movs r1, #0x3c - strb r1, [r0, #0x1d] - bx lr - .align 2, 0 - - thumb_func_start sub_0802A8EC -sub_0802A8EC: @ 0x0802A8EC - push {lr} - bl sub_0806F4E8 - pop {pc} - - thumb_func_start sub_0802A8F4 -sub_0802A8F4: @ 0x0802A8F4 - push {lr} - bl sub_0806F3E4 - pop {pc} - - thumb_func_start sub_0802A8FC -sub_0802A8FC: @ 0x0802A8FC - push {lr} - adds r2, r0, #0 - ldr r0, _0802A914 @ =gLinkState - ldrb r0, [r0, #0x1c] - movs r1, #0xf - ands r1, r0 - cmp r1, #0 - bne _0802A912 - adds r0, r2, #0 - adds r0, #0x45 - strb r1, [r0] -_0802A912: - pop {pc} - .align 2, 0 -_0802A914: .4byte gLinkState - - thumb_func_start nullsub_143 -nullsub_143: @ 0x0802A918 - bx lr - .align 2, 0 - - thumb_func_start sub_0802A91C -sub_0802A91C: @ 0x0802A91C - adds r0, #0x45 - movs r1, #0 - strb r1, [r0] - bx lr - thumb_func_start sub_0802A924 sub_0802A924: @ 0x0802A924 push {r4, r5, r6, r7, lr} diff --git a/asm/object56.s b/asm/object56.s index 59ec0bdc..08145dcd 100644 --- a/asm/object56.s +++ b/asm/object56.s @@ -6,57 +6,6 @@ .text - - thumb_func_start Object56 -Object56: @ 0x08091E60 - push {lr} - ldr r2, _08091E74 @ =gUnk_08122598 - ldrb r1, [r0, #0xc] - lsls r1, r1, #2 - adds r1, r1, r2 - ldr r1, [r1] - bl _call_via_r1 - pop {pc} - .align 2, 0 -_08091E74: .4byte gUnk_08122598 - - thumb_func_start sub_08091E78 -sub_08091E78: @ 0x08091E78 - push {r4, lr} - adds r4, r0, #0 - movs r2, #1 - movs r0, #1 - strb r0, [r4, #0xc] - ldrb r1, [r4, #0x18] - subs r0, #5 - ands r0, r1 - orrs r0, r2 - strb r0, [r4, #0x18] - ldrb r0, [r4, #0xe] - cmp r0, #0 - bne _08091E96 - movs r0, #0x2d - strb r0, [r4, #0xe] -_08091E96: - ldrb r1, [r4, #0x1b] - movs r0, #0x3f - ands r0, r1 - movs r1, #0x40 - orrs r0, r1 - strb r0, [r4, #0x1b] - ldrb r1, [r4, #0xb] - adds r0, r4, #0 - bl InitializeAnimation - ldr r1, _08091EBC @ =gUnk_08122590 - ldrb r0, [r4, #0xb] - lsls r0, r0, #1 - adds r0, r0, r1 - ldrh r0, [r0] - bl PlaySFX - pop {r4, pc} - .align 2, 0 -_08091EBC: .4byte gUnk_08122590 - thumb_func_start sub_08091EC0 sub_08091EC0: @ 0x08091EC0 push {r4, lr} diff --git a/data/data_902.s b/data/data_902.s index e93fba92..a1062359 100644 --- a/data/data_902.s +++ b/data/data_902.s @@ -1276,10 +1276,10 @@ gUnk_08122538:: @ 08122538 gUnk_08122540:: @ 08122540 .incbin "baserom.gba", 0x122540, 0x0000050 -gUnk_08122590:: @ 08122590 +ThoughtBubble_SFX:: @ 08122590 .incbin "baserom.gba", 0x122590, 0x0000008 -gUnk_08122598:: @ 08122598 +ThoughtBubble_Behaviors:: @ 08122598 .incbin "baserom.gba", 0x122598, 0x0000008 gUnk_081225A0:: @ 081225A0 diff --git a/include/entity.h b/include/entity.h index c963f7f2..6db5d830 100644 --- a/include/entity.h +++ b/include/entity.h @@ -70,8 +70,8 @@ typedef struct Entity { u8 palette; struct { u8 b0 : 4; - u8 b1 : 1; - u8 b2 : 3; + u8 b1 : 2; + u8 b2 : 2; } PACKED spriteOrientation; u8 filler[2]; u8 frameIndex; diff --git a/include/link.h b/include/link.h index 5ca18299..8ec7259d 100644 --- a/include/link.h +++ b/include/link.h @@ -19,7 +19,9 @@ typedef struct { u8 hurtBlinkSpeed; u8 filler4[4]; u16 filler5[3]; - u8 filler6[8]; + u8 filler6[2]; + u8 field_0x1c; + u8 filler9[2]; u16 filler7[2]; u8 swimState; u8 filler8[5]; @@ -52,6 +54,7 @@ typedef struct { u32 unk8; } LinkState; + typedef struct { u8 walletType; u8 heartPieces; diff --git a/include/object.h b/include/object.h index 057a6750..b24a30d2 100644 --- a/include/object.h +++ b/include/object.h @@ -90,7 +90,7 @@ extern void Object52(Entity*); extern void Object53(Entity*); extern void PullableLever(Entity*); extern void Minecart(Entity*); -extern void Object56(Entity*); +extern void ThoughtBubble(Entity*); extern void HiddenLadderDown(Entity*); extern void GentariCurtain(Entity*); extern void LavaPlatform(Entity*); diff --git a/linker.ld b/linker.ld index 2d9ebfc8..db430a69 100644 --- a/linker.ld +++ b/linker.ld @@ -677,7 +677,7 @@ SECTIONS { asm/object53.o(.text); asm/pullableLever.o(.text); asm/minecart.o(.text); - asm/object56.o(.text); + src/thoughtBubble.o(.text); asm/hiddenLadderDown.o(.text); asm/gentariCurtains.o(.text); asm/lavaPlatform.o(.text); diff --git a/src/bombPeahat.c b/src/bombPeahat.c index 4efa91bd..efd14570 100644 --- a/src/bombPeahat.c +++ b/src/bombPeahat.c @@ -1,22 +1,87 @@ #include "global.h" #include "entity.h" #include "functions.h" +#include "link.h" extern s32 sub_080012DC(Entity*); extern u32 GetNextFunction(Entity*); +extern void sub_0802AD54(Entity*); +extern void sub_0802B048(Entity*); +extern void InitializeAnimation(Entity*, u32); +extern void sub_0806F4E8(Entity*); +extern void sub_0806F3E4(Entity*); -extern void (*gUnk_080012C8[])(Entity*); -extern void (*gUnk_080CD0F0[])(Entity*); +extern void (*const gUnk_080012C8[])(Entity*); +extern void (*const gUnk_080CD0F0[])(Entity*); +extern void (*const gUnk_080CD120[])(Entity*); +extern void (*const gUnk_080CD134[])(Entity*); +extern void (*const gUnk_080CD108[])(Entity*); +extern void (*const gUnk_080CD140[])(Entity*); -void BombPeahat(Entity *this) +void BombPeahat(Entity* this) { + s32 iVar1; + u32 uVar2; + + if (((this->entityType).form == 2) && (iVar1 = sub_080012DC(this), iVar1)) { + gUnk_080012C8[iVar1](this); + } else { + gUnk_080CD0F0[GetNextFunction(this)](this); + } +} + +void sub_0802A84C(Entity* this) { + switch (this->entityType.form) { + default: + gUnk_080CD108[this->action](this); + sub_0802AD54(this); + return; + case 2: + gUnk_080CD120[this->action](this); + sub_0802B048(this); + return; + case 3: + gUnk_080CD134[this->action](this); + } +} + +void sub_0802A8AC(Entity *this) { + *((u8 *)&this->field_0x80 + 1) = 0; + if (this->entityType.form < 2) { + InitializeAnimation(this, 0); + } +} + +void sub_0802A8C8(Entity* this) { - s32 iVar1; - u32 uVar2; - - if (((this->entityType).form == 2) && (iVar1 = sub_080012DC(this), iVar1 != 0)) { - gUnk_080012C8[iVar1](this); - } - else { - gUnk_080CD0F0[GetNextFunction(this)](this); + gUnk_080CD140[this->previousActionFlag](this); +} + +void sub_0802A8E0(Entity *this) +{ + this->previousActionFlag = 1; + this->filler[1] = 0x3c; +} + +void sub_0802A8EC(Entity *this) +{ + sub_0806F4E8(this); +} + +void sub_0802A8F4(Entity *this) +{ + sub_0806F3E4(this); +} + +void sub_0802A8FC(Entity *this) +{ + if ((gLinkState.field_0x1c & 0xf) == 0) { + this->currentHealth = gLinkState.field_0x1c & 0xf; } +} + +void nullsub_143(Entity* this){} + +void sub_0802A91C(Entity *this) +{ + this->currentHealth = 0; } \ No newline at end of file diff --git a/src/greatFairy.c b/src/greatFairy.c index e2b23df5..28e9de33 100644 --- a/src/greatFairy.c +++ b/src/greatFairy.c @@ -9,8 +9,8 @@ void GreatFairy(Entity* this) { u8 bVar1; if (this->action == 0) { - bVar1 = __modsi3((this->entityType).form, 11); - (this->entityType).parameter = bVar1; + bVar1 = __modsi3(this->entityType.form, 11); + this->entityType.parameter = bVar1; } GreatFairy_Main[(this->entityType).parameter](this); } @@ -281,7 +281,7 @@ void GreatFairy_MiniAffineUpdate(Entity* this) { sub_0805EC60(this); } else { iVar2 = this->nonPlanarMovement -= 24; - sub_0805EC9C(this, 256, iVar2 * 65536 >> 20, 0); + sub_0805EC9C(this, 256, iVar2 * 0x10000 >> 20, 0); } } @@ -301,7 +301,7 @@ void GreatFairy_DropletInit(Entity* this) { void GreatFairy_DropletUpdate(Entity* this) { GetNextFrame(this); - if ((this->frames.all & 128) != 0) { + if (this->frames.b.f3) { DeleteEntity(this); } } @@ -367,7 +367,7 @@ void GreatFairy_EnergyInit(Entity* this) { void GreatFairy_EnergyUpdate(Entity* this) { GetNextFrame(this); - if ((this->frames.all & 128) != 0) { + if (this->frames.b.f3) { DeleteEntity(this); } } @@ -403,8 +403,7 @@ void sub_08087150(Entity* this) { } #endif -void nullsub_516() { -} +void nullsub_516(Entity* this) {} void sub_080871A8(Entity* this) { u32 bVar1; diff --git a/src/object.c b/src/object.c index 8ea522e0..d4062e0b 100644 --- a/src/object.c +++ b/src/object.c @@ -89,7 +89,7 @@ void (*const gObjectFunctions[])(Entity*) = { Object53, PullableLever, Minecart, - Object56, + ThoughtBubble, HiddenLadderDown, GentariCurtain, LavaPlatform, diff --git a/src/thoughtBubble.c b/src/thoughtBubble.c new file mode 100644 index 00000000..eebbba1b --- /dev/null +++ b/src/thoughtBubble.c @@ -0,0 +1,43 @@ +#include "global.h" +#include "entity.h" + +extern void InitializeAnimation(Entity*, u32); +extern void PlaySFX(u32); +extern void DeleteThisEntity(); +extern void GetNextFrame(Entity*); + +extern void (*const ThoughtBubble_Behaviors[])(Entity*); + +extern u16 ThoughtBubble_SFX[]; + +void ThoughtBubble(Entity* this) +{ + ThoughtBubble_Behaviors[this->action](this); +} + +void ThoughtBubble_Init(Entity *this) +{ + this->action = 1; + this->spriteSettings.b.ss0 = 1; + if (this->actionDelay == 0) { + this->actionDelay = 0x2d; + } + this->spriteOrientation.b2 = 1; + InitializeAnimation(this, this->entityType.parameter); + PlaySFX(ThoughtBubble_SFX[this->entityType.parameter]); +} + +void ThoughtBubble_Update(Entity *this) +{ + if (this->parent != NULL) { + this->x.HALF.HI = this->parent->x.HALF.HI; + this->y.HALF.HI = this->parent->y.HALF.HI; + this->height.HALF.HI = this->parent->height.HALF.HI; + } + if ((this->entityType).parameter != 2) { + if (--this->actionDelay == 0) { + DeleteThisEntity(); + } + } + GetNextFrame(this); +}