From 7d42d7c0deeeec49d2e4e2768e42497913856367 Mon Sep 17 00:00:00 2001 From: theo3 Date: Wed, 15 Jul 2020 17:30:26 -0700 Subject: [PATCH 1/4] keese.c OK --- asm/keese.s | 74 ----------------------------------------------- linker.ld | 1 - src/enemy/keese.c | 31 ++++++++++++++++++-- 3 files changed, 28 insertions(+), 78 deletions(-) delete mode 100644 asm/keese.s diff --git a/asm/keese.s b/asm/keese.s deleted file mode 100644 index f1035924..00000000 --- a/asm/keese.s +++ /dev/null @@ -1,74 +0,0 @@ - .include "asm/macros.inc" - - .include "constants/constants.inc" - - .syntax unified - - .text - - thumb_func_start sub_08021F24 -sub_08021F24: @ 0x08021F24 - push {r4, lr} - adds r4, r0, #0 - adds r0, #0x78 - ldrh r0, [r0] - cmp r0, #0 - bne _08021F48 - movs r0, #2 - strb r0, [r4, #0xc] - bl Random - ldr r2, _08021F44 @ =gUnk_080CB6F6 - movs r1, #0xf - ands r1, r0 - adds r1, r1, r2 - ldrb r0, [r1] - b _08021F6E - .align 2, 0 -_08021F44: .4byte gUnk_080CB6F6 -_08021F48: - adds r0, r4, #0 - adds r0, #0x7a - ldrh r0, [r0] - cmp r0, #0 - bne _08021F80 - ldr r0, _08021F7C @ =gLinkEntity - movs r2, #0x2e - ldrsh r1, [r0, r2] - movs r3, #0x32 - ldrsh r2, [r0, r3] - adds r0, r4, #0 - movs r3, #0x70 - bl sub_0806FCB8 - cmp r0, #0 - bne _08021F80 - movs r0, #3 - strb r0, [r4, #0xc] - movs r0, #0x1e -_08021F6E: - strb r0, [r4, #0xe] - adds r0, r4, #0 - movs r1, #1 - bl InitializeAnimation - b _08021FA4 - .align 2, 0 -_08021F7C: .4byte gLinkEntity -_08021F80: - adds r0, r4, #0 - bl sub_08049FA0 - cmp r0, #0 - beq _08021F94 - bl Random - movs r1, #0x1f - ands r0, r1 - b _08021F9A -_08021F94: - adds r0, r4, #0 - bl sub_08049EE4 -_08021F9A: - strb r0, [r4, #0x15] - adds r0, r4, #0 - movs r1, #0 - bl InitializeAnimation -_08021FA4: - pop {r4, pc} - .align 2, 0 diff --git a/linker.ld b/linker.ld index 18b60a0d..b3b8c983 100644 --- a/linker.ld +++ b/linker.ld @@ -333,7 +333,6 @@ SECTIONS { src/enemy/hangingSeed.o(.text); asm/beetle.o(.text); src/enemy/keese.o(.text); - asm/keese.o(.text); asm/doorMimic.o(.text); asm/rockChuchu.o(.text); asm/spinyChuchu.o(.text); diff --git a/src/enemy/keese.c b/src/enemy/keese.c index 0cbc9acd..ea25214b 100644 --- a/src/enemy/keese.c +++ b/src/enemy/keese.c @@ -14,6 +14,8 @@ extern void sub_08021EF0(Entity*); extern void sub_080AEFB4(Entity*); extern void sub_08021F24(Entity*); extern u32 sub_0806FCB8(Entity*, s32, s32, u32); +extern u32 sub_08049FA0(Entity*); +extern u32 sub_08049EE4(Entity*); extern void (*gUnk_080CB69C[])(Entity*); extern void (*gUnk_080CB6B4[])(Entity*); @@ -21,9 +23,7 @@ extern void (*gUnk_080CB6C4[])(Entity*); extern u8 gUnk_080CB6D0[]; extern u16 gUnk_080CB6D6[]; - - -extern u8 gUnk_080CB6D0[]; +extern u8 gUnk_080CB6F6[]; void Keese(Entity *this) { @@ -129,3 +129,28 @@ void sub_08021EF0(Entity *this) this->field_0x7a = 0x3c; InitializeAnimation(this, 0); } + +void sub_08021F24(Entity *this) +{ + u32 bVar1; + + if (this->field_0x78.HWORD == 0) { + this->action = 2; + this->actionDelay = gUnk_080CB6F6[Random() & 0xf]; + InitializeAnimation(this, 1); + } + else if (!this->field_0x7a && !(sub_0806FCB8(this, gLinkEntity.x.HALF.HI, gLinkEntity.y.HALF.HI, 0x70))) { + this->action = 3; + this->actionDelay = 0x1e; + InitializeAnimation(this, 1); + } + else { + if (sub_08049FA0(this) != 0) { + this->direction = Random() & 0x1f; + } + else { + this->direction = sub_08049EE4(this); + } + InitializeAnimation(this, 0); + } +} \ No newline at end of file From 035d4a150f3341aecd6d9d124c7f2cb99ac83473 Mon Sep 17 00:00:00 2001 From: theo3 Date: Wed, 15 Jul 2020 20:12:52 -0700 Subject: [PATCH 2/4] tingleSiblings.c started --- asm/tingleSiblings.s | 79 ---------------------------------------- linker.ld | 1 + src/npc/tingleSiblings.c | 43 ++++++++++++++++++++++ 3 files changed, 44 insertions(+), 79 deletions(-) create mode 100644 src/npc/tingleSiblings.c diff --git a/asm/tingleSiblings.s b/asm/tingleSiblings.s index d4cb0bc2..e8d3f96c 100644 --- a/asm/tingleSiblings.s +++ b/asm/tingleSiblings.s @@ -6,85 +6,6 @@ .text - - thumb_func_start TingleSiblings -TingleSiblings: @ 0x08064D58 - push {lr} - adds r2, r0, #0 - ldrb r1, [r2, #0x10] - movs r0, #2 - ands r0, r1 - cmp r0, #0 - beq _08064D6E - adds r0, r2, #0 - bl sub_08064DE4 - b _08064D74 -_08064D6E: - adds r0, r2, #0 - bl sub_08064D78 -_08064D74: - pop {pc} - .align 2, 0 - - thumb_func_start sub_08064D78 -sub_08064D78: @ 0x08064D78 - push {lr} - ldr r2, _08064D8C @ =gUnk_0810FBFC - ldrb r1, [r0, #0xc] - lsls r1, r1, #2 - adds r1, r1, r2 - ldr r1, [r1] - bl _call_via_r1 - pop {pc} - .align 2, 0 -_08064D8C: .4byte gUnk_0810FBFC - - thumb_func_start sub_08064D90 -sub_08064D90: @ 0x08064D90 - push {r4, lr} - adds r4, r0, #0 - movs r1, #2 - bl InitAnimationForceUpdate - movs r0, #1 - strb r0, [r4, #0xf] - pop {r4, pc} - - thumb_func_start sub_08064DA0 -sub_08064DA0: @ 0x08064DA0 - push {r4, lr} - adds r4, r0, #0 - bl sub_08064EE8 - adds r0, r4, #0 - adds r0, #0x39 - ldrb r0, [r0] - lsls r0, r0, #0x18 - asrs r0, r0, #0x18 - cmp r0, #0 - beq _08064DC8 - movs r0, #2 - strb r0, [r4, #0xc] - adds r0, r4, #0 - movs r1, #6 - bl InitAnimationForceUpdate - movs r0, #0 - bl TextboxNoOverlapFollow -_08064DC8: - pop {r4, pc} - .align 2, 0 - - thumb_func_start sub_08064DCC -sub_08064DCC: @ 0x08064DCC - push {r4, lr} - adds r4, r0, #0 - bl sub_08064EE8 - adds r0, r4, #0 - movs r1, #2 - bl InitAnimationForceUpdate - movs r0, #1 - strb r0, [r4, #0xc] - pop {r4, pc} - .align 2, 0 - thumb_func_start sub_08064DE4 sub_08064DE4: @ 0x08064DE4 push {r4, r5, lr} diff --git a/linker.ld b/linker.ld index 3dd658a6..c7f40ab1 100644 --- a/linker.ld +++ b/linker.ld @@ -559,6 +559,7 @@ SECTIONS { asm/nayru.o(.text); asm/farore.o(.text); asm/sturgeon.o(.text); + src/npc/tingleSiblings.o(.text); asm/tingleSiblings.o(.text); asm/stockwell.o(.text); src/npc/talon.o(.text); diff --git a/src/npc/tingleSiblings.c b/src/npc/tingleSiblings.c new file mode 100644 index 00000000..ab50c63c --- /dev/null +++ b/src/npc/tingleSiblings.c @@ -0,0 +1,43 @@ +#include "global.h" +#include "entity.h" +#include "npc.h" +#include "textbox.h" + +extern void sub_08064DE4(Entity*); +extern void sub_08064D78(Entity*); +extern void sub_08064EE8(Entity*); + +extern void (*const gUnk_0810FBFC[])(Entity*); + +void TingleSiblings(Entity* this) { + if ((this->flags & 2) != 0) { + sub_08064DE4(this); + } + else { + sub_08064D78(this); + } +} + +void sub_08064D78(Entity* this) { + gUnk_0810FBFC[this->action](this); +} + +void sub_08064D90(Entity* this) { + InitAnimationForceUpdate(this, 2); + this->field_0xf = 1; +} + +void sub_08064DA0(Entity* this) { + sub_08064EE8(this); + if (this->interactType != 0) { + this->action = 2; + InitAnimationForceUpdate(this, 6); + TextboxNoOverlapFollow(0); + } +} + +void sub_08064DCC(Entity* this) { + sub_08064EE8(this); + InitAnimationForceUpdate(this, 2); + this->action = 1; +} \ No newline at end of file From d49545317a9b0b7707d439cf5657836e7abc94ed Mon Sep 17 00:00:00 2001 From: theo3 Date: Wed, 15 Jul 2020 20:45:28 -0700 Subject: [PATCH 3/4] input.c OK --- asm/readKeyInput.s | 54 ---------------------------------------------- linker.ld | 2 +- src/input.c | 44 +++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 55 deletions(-) delete mode 100644 asm/readKeyInput.s create mode 100644 src/input.c diff --git a/asm/readKeyInput.s b/asm/readKeyInput.s deleted file mode 100644 index 50e63e38..00000000 --- a/asm/readKeyInput.s +++ /dev/null @@ -1,54 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .syntax unified - - .text - - thumb_func_start ReadKeyInput -ReadKeyInput: @ 0x0801D6C0 - push {lr} - ldr r0, _0801D6D4 @ =0x04000130 - ldrh r0, [r0] - ldr r1, _0801D6D8 @ =0x000003FF - bics r1, r0 - ldr r0, _0801D6DC @ =gUnk_03000FF0 - bl sub_0801D6E0 - pop {pc} - .align 2, 0 -_0801D6D4: .4byte 0x04000130 -_0801D6D8: .4byte 0x000003FF -_0801D6DC: .4byte gUnk_03000FF0 - - - thumb_func_start sub_0801D6E0 -sub_0801D6E0: @ 0x0801D6E0 - push {lr} - adds r2, r0, #0 - ldrh r0, [r2] - adds r3, r1, #0 - bics r3, r0 - strh r3, [r2, #2] - cmp r1, r0 - bne _0801D70A - ldrb r0, [r2, #7] - subs r0, #1 - strb r0, [r2, #7] - lsls r0, r0, #0x18 - cmp r0, #0 - bne _0801D704 - movs r0, #4 - strb r0, [r2, #7] - strh r1, [r2, #4] - b _0801D710 -_0801D704: - movs r0, #0 - strh r0, [r2, #4] - b _0801D710 -_0801D70A: - movs r0, #0x14 - strb r0, [r2, #7] - strh r3, [r2, #4] -_0801D710: - strh r1, [r2] - pop {pc} diff --git a/linker.ld b/linker.ld index c7f40ab1..58006a85 100644 --- a/linker.ld +++ b/linker.ld @@ -319,7 +319,7 @@ SECTIONS { src/_dmaFill32.o(.text); asm/sub_0801D630.o(.text); asm/sub_0801D66C.o(.text); - asm/readKeyInput.o(.text); + src/input.o(.text); asm/code_0801D714.o(.text); asm/code_0801D79C.o(.text); /* enemies */ diff --git a/src/input.c b/src/input.c new file mode 100644 index 00000000..df5b2290 --- /dev/null +++ b/src/input.c @@ -0,0 +1,44 @@ +#include "global.h" +#include "entity.h" + +typedef struct { + u16 field_0x0; + u16 field_0x2; + u16 field_0x4; + u8 field_0x6; + u8 field_0x7; +} Input; + +void StoreKeyInput(Input *pkeyInput, u32 ioKeyInput); + +extern Input gUnk_03000FF0; + +void ReadKeyInput(void) +{ + u32 reg = ~*(u16*)0x04000130 & 0x3FF; + Input* input = &gUnk_03000FF0; + StoreKeyInput(input, reg); +} + +void StoreKeyInput(Input *input, u32 ioKeyInput) +{ + u32 difference; + u32 temp = input->field_0x0; + + difference = ioKeyInput & ~temp; + input->field_0x2 = difference; + if (ioKeyInput == temp) { + if (--input->field_0x7 == 0) { + input->field_0x7 = 4; + input->field_0x4 = ioKeyInput; + } + else { + input->field_0x4 = 0; + } + } + else { + input->field_0x7 = 0x14; + input->field_0x4 = difference; + } + input->field_0x0 = ioKeyInput; +} \ No newline at end of file From 75223bab243e67eb7233edf32ffd8a15a94c6b34 Mon Sep 17 00:00:00 2001 From: theo3 Date: Wed, 15 Jul 2020 20:49:59 -0700 Subject: [PATCH 4/4] entity->spriteTileSize, entity->spriteIndex --- include/entity.h | 2 +- src/code_08077DF4.c | 4 ++-- src/item11.c | 2 +- src/npc/townsperson.c | 12 ++++++------ 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/entity.h b/include/entity.h index b79d1d5a..14b963f3 100644 --- a/include/entity.h +++ b/include/entity.h @@ -50,7 +50,7 @@ typedef struct Entity { /*0x10*/ u8 flags; /*0x11*/ u8 scriptedScene : 4; /* */ u8 scriptedScene2 : 4; - /*0x12*/ s16 spriteTileSize; + /*0x12*/ s16 spriteIndex; /*0x14*/ u8 animationState; /*0x15*/ u8 direction; /*0x16*/ u8 possibleBool; diff --git a/src/code_08077DF4.c b/src/code_08077DF4.c index 467cbe35..3897a273 100644 --- a/src/code_08077DF4.c +++ b/src/code_08077DF4.c @@ -18,7 +18,7 @@ void sub_08077DF4(Entity *ent, u32 arg1) if ((arg1 & 0xff) > 0xb8) { arg1 += (ent->entityType).form >> 1; } - gLinkEntity.spriteTileSize = (short)(arg1 >> 8); + gLinkEntity.spriteIndex = (short)(arg1 >> 8); InitAnimationForceUpdate(&gLinkEntity, (u8)arg1); sub_08077E54(ent); } @@ -38,7 +38,7 @@ void sub_08077E3C(Entity *ent) void sub_08077E54(Entity *ent) { ent->action = gLinkEntity.animIndex; - *(u8 *)&ent->spriteTileSize = gLinkEntity.frameIndex; + *(u8 *)&ent->spriteIndex = gLinkEntity.frameIndex; ent->previousActionFlag = gLinkEntity.frameDuration; ent->actionDelay = gLinkEntity.frames.all; } diff --git a/src/item11.c b/src/item11.c index 4f90bba6..b464bdd9 100644 --- a/src/item11.c +++ b/src/item11.c @@ -56,7 +56,7 @@ void sub_08018CBC(Entity *this) } this->action = 2; this->spriteSettings.b.draw = 1; - this->spriteTileSize = 0xa6; + this->spriteIndex = 0xa6; this->palette = 0x33; this->spriteVramOffset = 0; (this->entityType).form = gLinkState.field_0x1d[0] - 1; diff --git a/src/npc/townsperson.c b/src/npc/townsperson.c index 7c4bf877..c99cce93 100644 --- a/src/npc/townsperson.c +++ b/src/npc/townsperson.c @@ -192,7 +192,7 @@ void sub_08061E90(Entity* this, Entity* arg1) { if (arg1->spriteSettings.raw == 0) { arg1->spriteSettings.raw++; - arg1->spriteTileSize = (Random() & 0x3f) + 0x20; + arg1->spriteIndex = (Random() & 0x3f) + 0x20; animIndex = Random() & 0x18; switch (this->direction) { case 0x0: @@ -227,23 +227,23 @@ void sub_08061E90(Entity* this, Entity* arg1) { iVar4 = this->x.HALF.HI - *(s16*)&this->field_0x6a.HWORD; if (0x10 < iVar4) { this->x.HALF.HI = this->field_0x6a.HWORD + 0x10; - arg1->spriteTileSize = 1; + arg1->spriteIndex = 1; } if (iVar4 < -0x10) { this->x.HALF.HI = *(s16*)&this->field_0x6a.HWORD - 0x10; - arg1->spriteTileSize = 1; + arg1->spriteIndex = 1; } iVar4 = this->y.HALF.HI - *(s16*)&this->field_0x6c; if (0x10 < iVar4) { this->y.HALF.HI = *(s16*)&this->field_0x6c + 0x10; - arg1->spriteTileSize = 1; + arg1->spriteIndex = 1; } if (iVar4 < -0x10) { this->y.HALF.HI = *(s16*)&this->field_0x6c - 0x10; - arg1->spriteTileSize = 1; + arg1->spriteIndex = 1; } - if (--arg1->spriteTileSize != 0) { + if (--arg1->spriteIndex != 0) { gUnk_02033280[6] = 0; } }