diff --git a/asm/giantLeaf.s b/asm/giantLeaf.s deleted file mode 100644 index d6810508..00000000 --- a/asm/giantLeaf.s +++ /dev/null @@ -1,87 +0,0 @@ - .include "asm/macros.inc" - - .include "constants/constants.inc" - - .syntax unified - - .text - - - thumb_func_start sub_0808D5DC -sub_0808D5DC: @ 0x0808D5DC - push {lr} - adds r3, r0, #0 - ldrb r0, [r3, #0xc] - cmp r0, #0 - bne _0808D614 - movs r2, #1 - movs r0, #1 - strb r0, [r3, #0xc] - ldrb r1, [r3, #0x18] - subs r0, #5 - ands r0, r1 - orrs r0, r2 - strb r0, [r3, #0x18] - ldrb r0, [r3, #0x19] - movs r1, #0xc0 - orrs r0, r1 - strb r0, [r3, #0x19] - adds r2, r3, #0 - adds r2, #0x29 - ldrb r0, [r2] - movs r1, #7 - orrs r0, r1 - strb r0, [r2] - ldrb r0, [r3, #0xa] - strb r0, [r3, #0x1e] - adds r0, r3, #0 - bl sub_0808D618 -_0808D614: - pop {pc} - .align 2, 0 - - thumb_func_start sub_0808D618 -sub_0808D618: @ 0x0808D618 - push {r4, r5, r6, r7, lr} - adds r4, r0, #0 - ldrb r0, [r4, #0xa] - ldr r7, _0808D664 @ =gUnk_08121750 - cmp r0, #0 - beq _0808D626 - ldr r7, _0808D668 @ =gUnk_0812176A -_0808D626: - movs r1, #0x2e - ldrsh r0, [r4, r1] - ldr r3, _0808D66C @ =gRoomControls - ldrh r1, [r3, #6] - subs r0, r0, r1 - asrs r5, r0, #4 - movs r2, #0x3f - ands r5, r2 - movs r1, #0x32 - ldrsh r0, [r4, r1] - ldrh r1, [r3, #8] - subs r0, r0, r1 - asrs r0, r0, #4 - ands r0, r2 - lsls r0, r0, #6 - orrs r5, r0 - movs r6, #0 - adds r4, r7, #0 -_0808D64A: - movs r0, #0 - ldrsh r1, [r4, r0] - adds r1, r5, r1 - ldr r0, _0808D670 @ =0x00004074 - movs r2, #1 - bl SetTile - adds r4, #2 - adds r6, #1 - cmp r6, #0xc - bls _0808D64A - pop {r4, r5, r6, r7, pc} - .align 2, 0 -_0808D664: .4byte gUnk_08121750 -_0808D668: .4byte gUnk_0812176A -_0808D66C: .4byte gRoomControls -_0808D670: .4byte 0x00004074 diff --git a/asm/well.s b/asm/well.s deleted file mode 100644 index ca4558be..00000000 --- a/asm/well.s +++ /dev/null @@ -1,79 +0,0 @@ - .include "asm/macros.inc" - - .include "constants/constants.inc" - - .syntax unified - - .text - - - thumb_func_start sub_080A0E98 -sub_080A0E98: @ 0x080A0E98 - push {lr} - ldr r2, _080A0EAC @ =gUnk_08124C08 - ldrb r1, [r0, #0xc] - lsls r1, r1, #2 - adds r1, r1, r2 - ldr r1, [r1] - bl _call_via_r1 - pop {pc} - .align 2, 0 -_080A0EAC: .4byte gUnk_08124C08 - - thumb_func_start sub_080A0EB0 -sub_080A0EB0: @ 0x080A0EB0 - push {r4, r5, lr} - movs r1, #1 - strb r1, [r0, #0xc] - movs r1, #0x2e - ldrsh r2, [r0, r1] - ldr r3, _080A0EE8 @ =gRoomControls - ldrh r1, [r3, #6] - subs r2, r2, r1 - asrs r2, r2, #4 - movs r4, #0x3f - ands r2, r4 - movs r5, #0x32 - ldrsh r1, [r0, r5] - ldrh r3, [r3, #8] - subs r1, r1, r3 - asrs r1, r1, #4 - ands r1, r4 - lsls r1, r1, #6 - orrs r2, r1 - adds r0, #0x80 - strh r2, [r0] - ldr r2, _080A0EEC @ =0x0000407D - ldrh r1, [r0] - adds r0, r2, #0 - movs r2, #1 - bl SetTile - pop {r4, r5, pc} - .align 2, 0 -_080A0EE8: .4byte gRoomControls -_080A0EEC: .4byte 0x0000407D - - thumb_func_start sub_080A0EF0 -sub_080A0EF0: @ 0x080A0EF0 - push {r4, lr} - adds r4, r0, #0 - adds r0, #0x80 - ldrh r0, [r0] - movs r1, #1 - bl GetTileType - ldr r1, _080A0F1C @ =0x0000407D - cmp r0, r1 - beq _080A0F18 - bl sub_08078B48 - ldr r1, _080A0F20 @ =gLinkEntity - ldr r0, [r4, #0x2c] - str r0, [r1, #0x2c] - ldrh r0, [r4, #0x32] - adds r0, #4 - strh r0, [r1, #0x32] - bl sub_0805E780 -_080A0F18: - pop {r4, pc} - .align 2, 0 -_080A0F1C: .4byte 0x0000407D -_080A0F20: .4byte gLinkEntity diff --git a/include/entity.h b/include/entity.h index a4abf24d..6f6d08a8 100644 --- a/include/entity.h +++ b/include/entity.h @@ -64,8 +64,10 @@ typedef struct Entity struct { u8 b0:2; u8 b1:2; - u8 b2:4; + u8 b2:2; + u8 b3:2; } PACKED spriteOrder; + u8 palette; struct { u8 b0:4; @@ -132,7 +134,8 @@ typedef struct Entity u8 filler3[2]; u16 itemCooldown; u32 field_0x7c; - u32 field_0x80; + u16 field_0x80; + u16 field_0x82; union SplitHWord cutsceneBeh; u16 field_0x86; diff --git a/linker.ld b/linker.ld index 5b600f8e..fd818e2b 100644 --- a/linker.ld +++ b/linker.ld @@ -644,7 +644,7 @@ SECTIONS { asm/macroLink.o(.text); asm/object3D.o(.text); asm/object3E.o(.text); - asm/giantLeaf.o(.text); + src/giantLeaf.o(.text); asm/fairy.o(.text); asm/ladderUp.o(.text); asm/object42.o(.text); @@ -698,7 +698,7 @@ SECTIONS { asm/object72.o(.text); asm/lilypadSmall.o(.text); asm/object74.o(.text); - asm/bell.o(.text); + src/bell.o(.text); asm/macroDecorations.o(.text); asm/object79.o(.text); asm/steam.o(.text); @@ -762,7 +762,7 @@ SECTIONS { asm/objectB4.o(.text); asm/objectB5.o(.text); asm/objectB6.o(.text); - asm/well.o(.text); + src/well.o(.text); asm/windTribeTeleporter.o(.text); asm/objectB9.o(.text); asm/objectBA.o(.text); diff --git a/src/bell.c b/src/bell.c new file mode 100644 index 00000000..589d0117 --- /dev/null +++ b/src/bell.c @@ -0,0 +1,28 @@ +#include "entity.h" +#include "global.h" + +extern void sub_080042B8(); +extern void (*gUnk_08123384[])(Entity*); + +extern void UpdateSpriteOrderAndFlip(Entity*); +extern void LoadAnimation(); + +void sub_08097D78(Entity *ent) +{ + gUnk_08123384[ent->action](ent); +} + +void sub_08097D90(Entity *ent) +{ + ent->action = 1; + ent->spriteSettings.b.ss0 = 1; + ent->collisionLayer = 1; + ent->ticks.b0 = 0; + UpdateSpriteOrderAndFlip(ent); + LoadAnimation(ent, 0); +} + +void sub_08097DCC(Entity *ent) +{ + sub_080042B8(ent); +} diff --git a/src/giantLeaf.c b/src/giantLeaf.c new file mode 100644 index 00000000..6c6b4d47 --- /dev/null +++ b/src/giantLeaf.c @@ -0,0 +1,38 @@ +#include "global.h" +#include "entity.h" +#include "room.h" + +void SetTile(u32 tileIndex, s32 tilePosition, s32 layerIndex); +void sub_0808D618(Entity* ent); + +extern RoomControls gRoomControls; +extern s16 gUnk_08121750[]; +extern s16 gUnk_0812176A[]; + +void sub_0808D5DC(Entity* ent) +{ + if (ent->action == 0) + { + ent->action = 1; + ent->spriteSettings.b.ss0 = 1; + ent->spriteOrder.b3 = 3; + ent->ticks.b0 = 7; + ent->animationList = ent->entityType.parameter1; + sub_0808D618(ent); + } +} + +void sub_0808D618(Entity *ent) +{ + u32 tilePos; + s16 *arr; + u32 i; + + arr = (ent->entityType.parameter1 != 0) ? gUnk_0812176A : gUnk_08121750; + tilePos = (((ent->x.HALF.HI - gRoomControls.roomOriginX) >> 4) & 0x3F) | ((((ent->y.HALF.HI - gRoomControls.roomOriginY) >> 4) & 0x3F) * 64); + + for (i = 0; i < 13; i++) + { + SetTile(16500, tilePos + arr[i], 1); + } +} diff --git a/src/well.c b/src/well.c new file mode 100644 index 00000000..dee89ae0 --- /dev/null +++ b/src/well.c @@ -0,0 +1,41 @@ +#include "global.h" +#include "entity.h" +#include "room.h" + +void SetTile(u32 tileIndex, s32 tilePosition, s32 layerIndex); +s32 GetTileType(s32 tilePosition, s32 layerIndex); +void sub_08078B48(); +void sub_0805E780(); + +extern Entity gLinkEntity; +extern RoomControls gRoomControls; +extern void (*gUnk_08124C08[])(Entity *); + +void sub_080A0E98(Entity* ent) +{ + gUnk_08124C08[ent->action](ent); +} + +void sub_080A0EB0(Entity* ent) +{ + u32 tilePos; + + ent->action = 1; + tilePos = (((ent->x.HALF.HI - gRoomControls.roomOriginX) >> 4) & 0x3F) | ((((ent->y.HALF.HI - gRoomControls.roomOriginY) >> 4) & 0x3F) * 64); + ent->field_0x80 = tilePos; + SetTile(16509, ent->field_0x80, 1); +} + +void sub_080A0EF0(Entity* ent) +{ + s32 tileIndex; + + tileIndex = GetTileType(ent->field_0x80, 1); + if (tileIndex != 16509) + { + sub_08078B48(); + gLinkEntity.x.WORD = ent->x.WORD; + gLinkEntity.y.HALF.HI = ent->y.HALF.HI + 4; + sub_0805E780(); + } +}