diff --git a/asm/manager5.s b/asm/manager5.s deleted file mode 100644 index 0a6c1d56..00000000 --- a/asm/manager5.s +++ /dev/null @@ -1,256 +0,0 @@ - .include "asm/macros.inc" - - .include "constants/constants.inc" - - .syntax unified - - .text - - thumb_func_start sub_08057AD0 -sub_08057AD0: @ 0x08057AD0 - push {lr} - ldr r2, _08057AE4 @ =gUnk_08108044 - ldrb r1, [r0, #0xc] - lsls r1, r1, #2 - adds r1, r1, r2 - ldr r1, [r1] - bl _call_via_r1 - pop {pc} - .align 2, 0 -_08057AE4: .4byte gUnk_08108044 - - thumb_func_start sub_08057AE8 -sub_08057AE8: @ 0x08057AE8 - push {r4, r5, lr} - adds r5, r0, #0 - ldrb r0, [r5, #0xb] - movs r1, #3 - ands r1, r0 - lsls r1, r1, #1 - ldrb r0, [r5, #0xe] - cmp r0, #1 - bne _08057B04 - ldr r0, _08057B00 @ =0x00000323 - strh r0, [r5, #0x30] - b _08057B12 - .align 2, 0 -_08057B00: .4byte 0x00000323 -_08057B04: - movs r0, #2 - ands r0, r1 - movs r2, #0x36 - cmp r0, #0 - beq _08057B10 - movs r2, #0x37 -_08057B10: - strh r2, [r5, #0x30] -_08057B12: - ldr r2, _08057B9C @ =gUnk_08108024 - lsls r3, r1, #1 - adds r0, r3, r2 - ldrh r0, [r0] - movs r4, #0 - strh r0, [r5, #0x28] - adds r1, #1 - lsls r1, r1, #1 - adds r2, r1, r2 - ldrh r0, [r2] - strh r0, [r5, #0x2a] - ldr r2, _08057BA0 @ =gUnk_08108034 - adds r3, r3, r2 - ldrh r0, [r3] - strh r0, [r5, #0x2c] - adds r1, r1, r2 - ldrh r0, [r1] - strh r0, [r5, #0x2e] - ldrb r2, [r5, #0xb] - lsrs r0, r2, #2 - movs r1, #0xf - ands r0, r1 - adds r0, #1 - strh r0, [r5, #0x32] - movs r0, #0x1c - strb r0, [r5, #0xe] - strb r4, [r5, #0xf] - movs r0, #0x80 - ands r0, r2 - movs r1, #1 - cmp r0, #0 - beq _08057B54 - movs r1, #2 -_08057B54: - strb r1, [r5, #0xc] - cmp r1, #2 - bne _08057B9A - ldrh r0, [r5, #0x3e] - bl CheckFlags - cmp r0, #0 - beq _08057B9A - ldrh r0, [r5, #0x32] - cmp r0, #0 - beq _08057B94 -_08057B6A: - ldrh r1, [r5, #0x28] - ldrh r2, [r5, #0x2a] - adds r0, r5, #0 - bl sub_08057CA4 - ldrh r0, [r5, #0x30] - movs r2, #0x38 - ldrsh r1, [r5, r2] - movs r3, #0x3a - ldrsh r2, [r5, r3] - lsls r2, r2, #6 - orrs r1, r2 - ldrh r2, [r5, #0x3c] - bl sub_0807B7D8 - ldrh r0, [r5, #0x32] - subs r0, #1 - strh r0, [r5, #0x32] - lsls r0, r0, #0x10 - cmp r0, #0 - bne _08057B6A -_08057B94: - adds r0, r5, #0 - bl DeleteManager -_08057B9A: - pop {r4, r5, pc} - .align 2, 0 -_08057B9C: .4byte gUnk_08108024 -_08057BA0: .4byte gUnk_08108034 - - thumb_func_start sub_08057BA4 -sub_08057BA4: @ 0x08057BA4 - push {r4, lr} - adds r4, r0, #0 - ldrb r0, [r4, #0xe] - subs r0, #1 - strb r0, [r4, #0xe] - lsls r0, r0, #0x18 - cmp r0, #0 - bne _08057C24 - movs r0, #8 - strb r0, [r4, #0xe] - ldrh r0, [r4, #0x3e] - bl CheckFlags - cmp r0, #0 - beq _08057BF6 - ldrh r0, [r4, #0x32] - ldrb r1, [r4, #0xf] - cmp r0, r1 - beq _08057C24 - ldrh r1, [r4, #0x28] - ldrh r2, [r4, #0x2a] - adds r0, r4, #0 - bl sub_08057CA4 - ldrh r0, [r4, #0x30] - movs r2, #0x38 - ldrsh r1, [r4, r2] - movs r3, #0x3a - ldrsh r2, [r4, r3] - lsls r2, r2, #6 - orrs r1, r2 - ldrh r2, [r4, #0x3c] - bl sub_0807B7D8 - ldrb r0, [r4, #0xf] - adds r0, #1 - strb r0, [r4, #0xf] - movs r0, #0x71 - bl PlaySFX - b _08057C24 -_08057BF6: - ldrb r0, [r4, #0xf] - cmp r0, #0 - beq _08057C24 - movs r1, #0x38 - ldrsh r0, [r4, r1] - movs r2, #0x3a - ldrsh r1, [r4, r2] - lsls r1, r1, #6 - orrs r0, r1 - ldrh r1, [r4, #0x3c] - bl sub_0807BA8C - ldrh r1, [r4, #0x2c] - ldrh r2, [r4, #0x2e] - adds r0, r4, #0 - bl sub_08057CA4 - ldrb r0, [r4, #0xf] - subs r0, #1 - strb r0, [r4, #0xf] - movs r0, #0x71 - bl PlaySFX -_08057C24: - pop {r4, pc} - .align 2, 0 - - thumb_func_start sub_08057C28 -sub_08057C28: @ 0x08057C28 - push {r4, lr} - adds r4, r0, #0 - ldrb r0, [r4, #0xd] - cmp r0, #0 - bne _08057C44 - ldrh r0, [r4, #0x3e] - bl CheckFlags - cmp r0, #0 - beq _08057C9C - ldrb r0, [r4, #0xd] - adds r0, #1 - strb r0, [r4, #0xd] - b _08057C9C -_08057C44: - ldrb r0, [r4, #0xe] - subs r0, #1 - strb r0, [r4, #0xe] - lsls r0, r0, #0x18 - cmp r0, #0 - bne _08057C9C - movs r0, #8 - strb r0, [r4, #0xe] - ldrh r0, [r4, #0x32] - ldrb r1, [r4, #0xf] - cmp r0, r1 - beq _08057C88 - ldrh r1, [r4, #0x28] - ldrh r2, [r4, #0x2a] - adds r0, r4, #0 - bl sub_08057CA4 - ldrh r0, [r4, #0x30] - movs r2, #0x38 - ldrsh r1, [r4, r2] - movs r3, #0x3a - ldrsh r2, [r4, r3] - lsls r2, r2, #6 - orrs r1, r2 - ldrh r2, [r4, #0x3c] - bl sub_0807B7D8 - ldrb r0, [r4, #0xf] - adds r0, #1 - strb r0, [r4, #0xf] - movs r0, #0x71 - bl PlaySFX - b _08057C9C -_08057C88: - ldrh r1, [r4, #0x30] - ldr r0, _08057CA0 @ =0x00000323 - cmp r1, r0 - beq _08057C96 - movs r0, #0x72 - bl PlaySFX -_08057C96: - adds r0, r4, #0 - bl DeleteManager -_08057C9C: - pop {r4, pc} - .align 2, 0 -_08057CA0: .4byte 0x00000323 - - thumb_func_start sub_08057CA4 -sub_08057CA4: @ 0x08057CA4 - ldrh r3, [r0, #0x38] - adds r3, r3, r1 - strh r3, [r0, #0x38] - ldrh r1, [r0, #0x3a] - adds r1, r1, r2 - strh r1, [r0, #0x3a] - bx lr - .align 2, 0 \ No newline at end of file diff --git a/data/data_08107BC8.s b/data/data_08107BC8.s index 8c290db5..699c41d5 100755 --- a/data/data_08107BC8.s +++ b/data/data_08107BC8.s @@ -99,39 +99,3 @@ gUnk_08107DA0:: @ 08107DA0 gUnk_08107DC0:: @ 08107DC0 .incbin "baserom.gba", 0x107DC0, 0x0000264 - -gUnk_08108024:: @ 08108024 - .incbin "baserom.gba", 0x108024, 0x0000010 - -gUnk_08108034:: @ 08108034 - .incbin "baserom.gba", 0x108034, 0x0000010 - -gUnk_08108044:: @ 08108044 - .incbin "baserom.gba", 0x108044, 0x000000C - -gUnk_08108050:: @ 08108050 - .incbin "baserom.gba", 0x108050, 0x000001E - -gUnk_0810806E:: @ 0810806E - .incbin "baserom.gba", 0x10806E, 0x0000036 - -gUnk_081080A4:: @ 081080A4 - .incbin "baserom.gba", 0x1080A4, 0x0000020 - -gUnk_081080C4:: @ 081080C4 - .incbin "baserom.gba", 0x1080C4, 0x0000043 - -gUnk_08108107:: @ 08108107 - .incbin "baserom.gba", 0x108107, 0x0000079 - -gUnk_08108180:: @ 08108180 - .incbin "baserom.gba", 0x108180, 0x0000064 - -gUnk_081081E4:: @ 081081E4 - .incbin "baserom.gba", 0x1081E4, 0x0000008 - -gUnk_081081EC:: @ 081081EC - .incbin "baserom.gba", 0x1081EC, 0x0000008 - -gUnk_081081F4:: @ 081081F4 - .incbin "baserom.gba", 0x1081F4, 0x0000014 diff --git a/data/data_08108050.s b/data/data_08108050.s new file mode 100644 index 00000000..a9c5a932 --- /dev/null +++ b/data/data_08108050.s @@ -0,0 +1,32 @@ + .include "asm/macros.inc" + .include "constants/constants.inc" + + .section .rodata + .align 2 + +gUnk_08108050:: @ 08108050 + .incbin "baserom.gba", 0x108050, 0x000001E + +gUnk_0810806E:: @ 0810806E + .incbin "baserom.gba", 0x10806E, 0x0000036 + +gUnk_081080A4:: @ 081080A4 + .incbin "baserom.gba", 0x1080A4, 0x0000020 + +gUnk_081080C4:: @ 081080C4 + .incbin "baserom.gba", 0x1080C4, 0x0000043 + +gUnk_08108107:: @ 08108107 + .incbin "baserom.gba", 0x108107, 0x0000079 + +gUnk_08108180:: @ 08108180 + .incbin "baserom.gba", 0x108180, 0x0000064 + +gUnk_081081E4:: @ 081081E4 + .incbin "baserom.gba", 0x1081E4, 0x0000008 + +gUnk_081081EC:: @ 081081EC + .incbin "baserom.gba", 0x1081EC, 0x0000008 + +gUnk_081081F4:: @ 081081F4 + .incbin "baserom.gba", 0x1081F4, 0x0000014 diff --git a/include/functions.h b/include/functions.h index 9ce5f423..2662b815 100644 --- a/include/functions.h +++ b/include/functions.h @@ -268,4 +268,5 @@ extern void sub_08080CB4(Entity*); extern u32 GetTileTypeByEntity(Entity*); extern u32 sub_0800442E(Entity*); extern void sub_08081404(Entity*, u32); +extern void sub_0807B7D8(u32, u32, u32); #endif diff --git a/linker.ld b/linker.ld index 2d4cf2f0..0502bcf7 100644 --- a/linker.ld +++ b/linker.ld @@ -473,7 +473,7 @@ SECTIONS { asm/manager2.o(.text); src/manager/manager3.o(.text); src/manager/manager4.o(.text); - asm/manager5.o(.text); + src/manager/manager5.o(.text); src/manager/manager6.o(.text); asm/manager7.o(.text); asm/manager8.o(.text); @@ -983,6 +983,8 @@ SECTIONS { data/metatile_headers.o(.rodata); data/map_headers.o(.rodata); data/data_08107BC8.o(.rodata); + src/manager/manager5.o(.rodata); + data/data_08108050.o(.rodata); src/manager/managerB.o(.rodata); data/data_0810821C.o(.rodata); src/item.o(.rodata); diff --git a/src/manager/manager5.c b/src/manager/manager5.c new file mode 100644 index 00000000..de4e08b9 --- /dev/null +++ b/src/manager/manager5.c @@ -0,0 +1,129 @@ +#include "global.h" +#include "manager.h" +#include "flags.h" +#include "functions.h" + + +typedef struct { + Manager manager; + u8 unk_20[0x08]; + u16 unk_28; + u16 unk_2a; + u16 unk_2c; + u16 unk_2e; + u16 unk_30; + u16 unk_32; + u8 unk_34[0x04]; + s16 unk_38; + s16 unk_3a; + u16 unk_3c; + u16 unk_3e; +} Manager5; + +void sub_08057AE8(Manager5*); +void sub_08057BA4(Manager5*); +void sub_08057C28(Manager5*); + +const u16 gUnk_08108024[] = { + 0, + -1, + 1, + 0, + 0, + 1, + -1, + 0 +}; +const u16 gUnk_08108034[] = { + 0, + 1, + -1, + 0, + 0, + -1, + 1, + 0 +}; + +void (*const gUnk_08108044[])(Manager5*) = { + sub_08057AE8, + sub_08057BA4, + sub_08057C28 +}; + +void sub_08057AD0(Manager5* this) { + gUnk_08108044[this->manager.action](this); +} + +void sub_08057CA4(Manager5*, u32, u32); + +extern void DeleteManager(Manager*); + +void sub_08057AE8(Manager5* this) { + u32 tmp; + tmp = (this->manager.unk_0b & 0x3)<<1; + if (this->manager.unk_0e == 1) { + this->unk_30 = 0x323; + } else { + this->unk_30 = tmp & 2 ? 0x37 : 0x36; + } + this->unk_28 = gUnk_08108024[tmp]; + this->unk_2a = gUnk_08108024[tmp+1]; + this->unk_2c = gUnk_08108034[tmp]; + this->unk_2e = gUnk_08108034[tmp+1]; + this->unk_32 = ((this->manager.unk_0b>>2)&0xF)+1; + this->manager.unk_0e = 0x1C; + this->manager.unk_0f = 0; + this->manager.action = (this->manager.unk_0b & 0x80)?2:1; + if (this->manager.action != 2 + || !CheckFlags(this->unk_3e)) return; + for (;this->unk_32;this->unk_32--) { + sub_08057CA4(this, this->unk_28, this->unk_2a); + sub_0807B7D8(this->unk_30, this->unk_38 | (this->unk_3a << 6),this->unk_3c); + } + DeleteManager(&this->manager); +} + +void sub_08057BA4(Manager5* this) { + if (--this->manager.unk_0e) return; + this->manager.unk_0e = 8; + if (CheckFlags(this->unk_3e)) { + if (this->unk_32 == this->manager.unk_0f) return; + sub_08057CA4(this, this->unk_28, this->unk_2a); + sub_0807B7D8(this->unk_30, this->unk_38 | (this->unk_3a << 6), this->unk_3c); + this->manager.unk_0f++; + PlaySFX(0x71); + } else { + if (!this->manager.unk_0f) return; + sub_0807BA8C(this->unk_38 | (this->unk_3a << 6), this->unk_3c); + sub_08057CA4(this, this->unk_2c, this->unk_2e); + this->manager.unk_0f--; + PlaySFX(0x71); + } +} + +void sub_08057C28(Manager5* this) { + if (!this->manager.unk_0d) { + if (!CheckFlags(this->unk_3e)) return; + this->manager.unk_0d++; + } else { + if (--this->manager.unk_0e) return; + this->manager.unk_0e = 8; + if (this->unk_32 != this->manager.unk_0f) { + sub_08057CA4(this, this->unk_28, this->unk_2a); + sub_0807B7D8(this->unk_30, this->unk_38 | (this->unk_3a << 6), this->unk_3c); + this->manager.unk_0f++; + PlaySFX(0x71); + } else { + if (this->unk_30 != 0x323) { + PlaySFX(0x72); + } + DeleteManager(&this->manager); + } + } +} + +void sub_08057CA4(Manager5* this, u32 unk1, u32 unk2) { + this->unk_38 += unk1; + this->unk_3a += unk2; +}