From ce030bc8ac4b39c20c9f07a265872d4b9d6200f5 Mon Sep 17 00:00:00 2001 From: chandler Date: Sun, 14 Jun 2020 01:49:21 -0400 Subject: [PATCH] malon OK. made functions.h. fixed typos in format.sh. tidied up epona.c --- asm/malon.s | 204 -------------------------------------------- format.sh | 2 +- include/functions.h | 27 ++++++ linker.ld | 2 +- src/epona.c | 21 +---- src/malon.c | 80 +++++++++++++++++ 6 files changed, 112 insertions(+), 224 deletions(-) delete mode 100644 asm/malon.s mode change 100644 => 100755 format.sh create mode 100644 include/functions.h create mode 100644 src/malon.c diff --git a/asm/malon.s b/asm/malon.s deleted file mode 100644 index d9d7fed5..00000000 --- a/asm/malon.s +++ /dev/null @@ -1,204 +0,0 @@ - .include "asm/macros.inc" - - .include "constants/constants.inc" - - .syntax unified - - .text - - - thumb_func_start sub_0806581C -sub_0806581C: @ 0x0806581C - push {r4, lr} - adds r4, r0, #0 - ldrb r1, [r4, #0x10] - movs r0, #2 - ands r0, r1 - cmp r0, #0 - beq _08065840 - ldr r0, _0806583C @ =gUnk_0810FF64 - ldrb r1, [r4, #0xc] - lsls r1, r1, #2 - adds r1, r1, r0 - ldr r1, [r1] - adds r0, r4, #0 - bl _call_via_r1 - b _0806585C - .align 2, 0 -_0806583C: .4byte gUnk_0810FF64 -_08065840: - ldr r1, _08065860 @ =gUnk_0810FF5C - ldrb r0, [r4, #0xc] - lsls r0, r0, #2 - adds r0, r0, r1 - ldr r1, [r0] - adds r0, r4, #0 - bl _call_via_r1 - ldrb r0, [r4, #0xc] - cmp r0, #0 - beq _0806585C - adds r0, r4, #0 - bl sub_0806ED78 -_0806585C: - pop {r4, pc} - .align 2, 0 -_08065860: .4byte gUnk_0810FF5C - - thumb_func_start sub_08065864 -sub_08065864: @ 0x08065864 - push {lr} - movs r3, #1 - movs r1, #1 - strb r1, [r0, #0xc] - ldrb r2, [r0, #0x18] - subs r1, #5 - ands r1, r2 - orrs r1, r3 - strb r1, [r0, #0x18] - movs r1, #0xc - bl LoadAnimation - pop {pc} - .align 2, 0 - - thumb_func_start sub_08065880 -sub_08065880: @ 0x08065880 - push {lr} - bl sub_080042B8 - pop {pc} - - thumb_func_start sub_08065888 -sub_08065888: @ 0x08065888 - 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] - movs r0, #4 - strb r0, [r4, #0x14] - adds r0, r4, #0 - bl sub_0801E99C - adds r1, r4, #0 - adds r1, #0x68 - strb r0, [r1] - ldrb r1, [r1] - adds r0, r4, #0 - bl sub_08078784 - adds r0, r4, #0 - bl sub_0807DD50 - pop {r4, pc} - - thumb_func_start sub_080658BC -sub_080658BC: @ 0x080658BC - push {r4, lr} - adds r4, r0, #0 - adds r2, r4, #0 - adds r2, #0x39 - movs r1, #0 - ldrsb r1, [r2, r1] - cmp r1, #2 - bne _080658F4 - movs r0, #0 - strb r1, [r4, #0xc] - strb r0, [r2] - ldr r1, _080658F0 @ =gLinkEntity - adds r0, r4, #0 - bl sub_080045C4 - bl sub_0806F5A4 - adds r1, r0, #0 - adds r0, r4, #0 - bl LoadAnimation - adds r0, r4, #0 - bl sub_0806F118 - b _080658FC - .align 2, 0 -_080658F0: .4byte gLinkEntity -_080658F4: - adds r0, r4, #0 - movs r1, #0 - bl sub_0807DD94 -_080658FC: - pop {r4, pc} - .align 2, 0 - - thumb_func_start sub_08065900 -sub_08065900: @ 0x08065900 - push {r4, lr} - adds r4, r0, #0 - bl UpdateFuseInteraction - cmp r0, #0 - beq _08065910 - movs r0, #1 - strb r0, [r4, #0xc] -_08065910: - pop {r4, pc} - .align 2, 0 - - thumb_func_start sub_08065914 -sub_08065914: @ 0x08065914 - push {r4, r5, lr} - adds r5, r0, #0 - movs r0, #7 - movs r1, #0x1f - movs r2, #7 - bl sub_0805EB00 - adds r4, r0, #0 - cmp r4, #0 - beq _08065938 - movs r2, #0xc0 - lsls r2, r2, #0xd - ldr r3, _0806595C @ =0xFFFF0000 - adds r0, r5, #0 - adds r1, r4, #0 - bl PositionRelative - str r5, [r4, #0x50] -_08065938: - movs r0, #7 - movs r1, #0x20 - movs r2, #7 - bl sub_0805EB00 - adds r4, r0, #0 - cmp r4, #0 - beq _08065958 - movs r2, #0xa0 - lsls r2, r2, #0xe - adds r0, r5, #0 - adds r1, r4, #0 - movs r3, #0 - bl PositionRelative - str r5, [r4, #0x50] -_08065958: - pop {r4, r5, pc} - .align 2, 0 -_0806595C: .4byte 0xFFFF0000 - - thumb_func_start sub_08065960 -sub_08065960: @ 0x08065960 - push {lr} - adds r2, r0, #0 - ldrb r0, [r2, #0xc] - cmp r0, #0 - bne _08065986 - adds r0, #1 - strb r0, [r2, #0xc] - ldrb r1, [r2, #0x18] - movs r0, #4 - rsbs r0, r0, #0 - ands r0, r1 - movs r1, #1 - orrs r0, r1 - strb r0, [r2, #0x18] - adds r0, r2, #0 - movs r1, #0xc - bl LoadAnimation - b _0806598C -_08065986: - adds r0, r2, #0 - bl sub_080042B8 -_0806598C: - pop {pc} - .align 2, 0 diff --git a/format.sh b/format.sh old mode 100644 new mode 100755 index 0c232115..28dc63e0 --- a/format.sh +++ b/format.sh @@ -24,7 +24,7 @@ clang-format ${FORMAT_OPTS} src/**/*.c clang-format ${FORMAT_OPTS} include/**/*.h echo "Running clang-tidy..." clang-tidy ${TIDY_OPTS} src/**/*.c -- ${COMPILER_OPTS} &> /dev/null -clang-format ${FORMAT_OPTS} include/**/*.h +clang-tidy ${TIDY_OPTS} include/**/*.h -- ${COMPILER_OPTS} &> /dev/null echo "Adding missing final new lines..." find src/ -type f -name "*.c" -exec sed -i -e '$a\' {} \; echo "Done formatting all files." diff --git a/include/functions.h b/include/functions.h new file mode 100644 index 00000000..0a4249c2 --- /dev/null +++ b/include/functions.h @@ -0,0 +1,27 @@ +#ifndef _FUNCTIONS_H_ +#define _FUNCTIONS_H_ + +#include "global.h" +#include "entity.h" + +void LoadAnimation(Entity*, u32); +void sub_080042B8(Entity*); +u32 sub_080045C4(Entity*, Entity*); +u32 sub_0801E99C(Entity*); +void sub_0805E3A0(Entity*, u32); +Entity* sub_0805EB00(u32, u32, u32); +void sub_0806ED78(Entity*); +void sub_0806F118(Entity*); +u32 UpdateFuseInteraction(void); +void ShowNPCDialogue(Entity*, u64*); +u32 sub_0806F5A4(u32); +void PositionRelative(Entity*, Entity*, s32, s32); +void sub_08078778(Entity*); +void sub_08078784(Entity*, u32); +void sub_080787A8(Entity*, u32); +void sub_080791D0(void); +void sub_0807DD50(Entity*); +void sub_0807DD94(Entity*, u32); +void PlaySFX(u32); + +#endif \ No newline at end of file diff --git a/linker.ld b/linker.ld index 9f5cbd53..76ae00d6 100644 --- a/linker.ld +++ b/linker.ld @@ -489,7 +489,7 @@ SECTIONS { asm/tingleSiblings.o(.text); asm/stockwell.o(.text); asm/talon.o(.text); - asm/malon.o(.text); + src/malon.o(.text); src/epona.o(.text); src/milkCart.o(.text); asm/ghostBrothers.o(.text); diff --git a/src/epona.c b/src/epona.c index be050c87..c5a84726 100644 --- a/src/epona.c +++ b/src/epona.c @@ -2,28 +2,14 @@ #include "entity.h" #include "textbox.h" #include "link.h" - -extern void sub_0806ED78(Entity*); -extern u32 sub_0801E99C(Entity*); -extern void LoadAnimation(Entity*, u32); -extern void sub_080042B8(Entity*); -extern void sub_08065AA4(Entity*); -extern u32 UpdateFuseInteraction(void); -extern void ShowNPCDialogue(Entity*, u64*); -extern void sub_08078778(Entity*); -extern void sub_080787A8(Entity*, u32); -extern void sub_0806F118(Entity*); -extern void sub_0805E3A0(Entity*, u8); -extern u32 sub_080045C4(Entity*, Entity*); -extern u32 sub_0806F5A4(void); -extern void sub_080791D0(void); -extern void PlaySFX(u32); +#include "functions.h" extern TextBox gTextBox; extern LinkState gLinkState; extern Entity gLinkEntity; void sub_08065A64(Entity* this); +void sub_08065AA4(Entity*); extern void (*gUnk_0811006C[])(Entity*); extern u64 gUnk_08110080[]; @@ -96,8 +82,7 @@ void sub_08065AA4(Entity* this) { sub_0805E3A0(this, 2); sub_08065A50(this); } - sub_080045C4(this, &gLinkEntity); - LoadAnimation(this, sub_0806F5A4()); + LoadAnimation(this, sub_0806F5A4(sub_080045C4(this, &gLinkEntity))); } else { sub_08065A50(this); sub_080791D0(); diff --git a/src/malon.c b/src/malon.c new file mode 100644 index 00000000..d3f7a452 --- /dev/null +++ b/src/malon.c @@ -0,0 +1,80 @@ +#include "global.h" +#include "functions.h" +#include "entity.h" + +extern Entity gLinkEntity; + +extern void (*gUnk_0810FF5C[])(Entity* this); +extern void (*gUnk_0810FF64[])(Entity* this); + +void sub_0806581C(Entity* this) { + if (this->flags & 0x2) { + gUnk_0810FF64[this->action](this); + } else { + gUnk_0810FF5C[this->action](this); + if (this->action != 0) { + sub_0806ED78(this); + } + } +} + +void sub_08065864(Entity* this) { + this->action = 1; + this->spriteSettings.b.ss0 = 1; + LoadAnimation(this, 0xC); +} + +void sub_08065880(Entity* this) { + sub_080042B8(this); +} + +void sub_08065888(Entity* this) { + this->action = 1; + this->spriteSettings.b.ss0 = 1; + this->animationState = 4; + this->field_0x68 = sub_0801E99C(this); + sub_08078784(this, this->field_0x68); + sub_0807DD50(this); +} + +void sub_080658BC(Entity* this) { + if (this->interactType == 2) { + this->action = 2; + this->interactType = 0; + LoadAnimation(this, sub_0806F5A4(sub_080045C4(this, &gLinkEntity))); + sub_0806F118(this); + } else { + sub_0807DD94(this, 0); + } +} + +void sub_08065900(Entity* this) { + if (UpdateFuseInteraction() != 0) { + this->action = 1; + } +} + +void sub_08065914(Entity* this) { + Entity* target; + + target = sub_0805EB00(7, 0x1F, 7); + if (target != NULL) { + PositionRelative(this, target, 0x180000, -0x10000); + target->parent = this; + } + target = sub_0805EB00(7, 0x20, 7); + if (target != NULL) { + PositionRelative(this, target, 0x280000, 0); + target->parent = this; + } +} + +void sub_08065960(Entity* this) { + if (this->action == 0) { + this->action++; + this->spriteSettings.b.ss0 = 1; + LoadAnimation(this, 0xC); + } else { + sub_080042B8(this); + } +}