From 2e789dbbdc18f56cba62aef51156d44136b20632 Mon Sep 17 00:00:00 2001 From: Phlosioneer Date: Wed, 27 Feb 2019 02:11:45 -0500 Subject: [PATCH] Decompile another 7 functions --- asm/pokenav.s | 329 -------------------------------------------------- src/pokenav.c | 231 ++++++++++++++++++++++++++++++++++- 2 files changed, 226 insertions(+), 334 deletions(-) diff --git a/asm/pokenav.s b/asm/pokenav.s index 95fde9d4f..e2fb45851 100644 --- a/asm/pokenav.s +++ b/asm/pokenav.s @@ -5,335 +5,6 @@ .text - thumb_func_start sub_81C85A0 -sub_81C85A0: @ 81C85A0 - push {r4-r6,lr} - adds r5, r0, 0 - movs r0, 0x11 - bl GetSubstructPtr - adds r4, r0, 0 - cmp r5, 0 - beq _081C85B8 - cmp r5, 0x1 - beq _081C85C4 - movs r0, 0x4 - b _081C862A -_081C85B8: - bl sub_81C83E0 - cmp r0, 0 - bne _081C8628 - movs r0, 0x1 - b _081C862A -_081C85C4: - movs r6, 0 - ldrb r0, [r4] - bl GetBgY - adds r5, r0, 0 - ldrb r0, [r4] - movs r1, 0x80 - lsls r1, 5 - ldr r2, [r4, 0x30] - lsls r2, 24 - lsrs r2, 24 - bl ChangeBgY - adds r1, r0, 0 - ldr r0, [r4, 0x30] - cmp r0, 0x2 - bne _081C85F8 - ldr r2, [r4, 0x24] - cmp r5, r2 - bgt _081C85F2 - ldr r0, [r4, 0x20] - cmp r5, r0 - bgt _081C860A -_081C85F2: - cmp r1, r2 - bgt _081C860A - b _081C860E -_081C85F8: - ldr r2, [r4, 0x24] - cmp r5, r2 - blt _081C8604 - ldr r0, [r4, 0x20] - cmp r5, r0 - blt _081C860A -_081C8604: - cmp r1, r2 - blt _081C860A - movs r6, 0x1 -_081C860A: - cmp r6, 0 - beq _081C8628 -_081C860E: - ldr r1, [r4, 0x2C] - ldrh r0, [r4, 0xA] - adds r0, r1 - movs r1, 0xF - ands r0, r1 - strh r0, [r4, 0xA] - ldrb r0, [r4] - adds r1, r2, 0 - movs r2, 0 - bl ChangeBgY - movs r0, 0x4 - b _081C862A -_081C8628: - movs r0, 0x2 -_081C862A: - pop {r4-r6} - pop {r1} - bx r1 - thumb_func_end sub_81C85A0 - - thumb_func_start sub_81C8630 -sub_81C8630: @ 81C8630 - push {lr} - movs r0, 0x11 - bl GetSubstructPtr - ldr r0, [r0, 0x28] - bl sub_81C70D8 - pop {r1} - bx r1 - thumb_func_end sub_81C8630 - - thumb_func_start sub_81C8644 -sub_81C8644: @ 81C8644 - push {lr} - movs r0, 0x11 - bl GetSubstructPtr - ldr r1, =0x00000888 - adds r0, r1 - pop {r1} - bx r1 - .pool - thumb_func_end sub_81C8644 - - thumb_func_start sub_81C8658 -sub_81C8658: @ 81C8658 - push {lr} - bl sub_81C8644 - adds r1, r0, 0 - ldrh r0, [r1, 0x6] - cmp r0, 0 - beq _081C866E - subs r0, 0x1 - strh r0, [r1, 0x6] - movs r0, 0x1 - b _081C8686 -_081C866E: - bl sub_81C84A4 - cmp r0, 0 - bne _081C867A - movs r0, 0 - b _081C8686 -_081C867A: - movs r0, 0x1 - negs r0, r0 - movs r1, 0x1 - bl sub_81C84E8 - movs r0, 0x2 -_081C8686: - pop {r1} - bx r1 - thumb_func_end sub_81C8658 - - thumb_func_start sub_81C868C -sub_81C868C: @ 81C868C - push {lr} - bl sub_81C8644 - adds r2, r0, 0 - ldrh r1, [r2] - ldrh r3, [r2, 0x6] - adds r1, r3 - ldrh r0, [r2, 0x2] - subs r0, 0x1 - cmp r1, r0 - bge _081C86BA - ldrh r0, [r2, 0x8] - subs r0, 0x1 - cmp r3, r0 - bge _081C86B2 - adds r0, r3, 0x1 - strh r0, [r2, 0x6] - movs r0, 0x1 - b _081C86C8 -_081C86B2: - bl sub_81C84C0 - cmp r0, 0 - bne _081C86BE -_081C86BA: - movs r0, 0 - b _081C86C8 -_081C86BE: - movs r0, 0x1 - movs r1, 0x1 - bl sub_81C84E8 - movs r0, 0x2 -_081C86C8: - pop {r1} - bx r1 - thumb_func_end sub_81C868C - - thumb_func_start sub_81C86CC -sub_81C86CC: @ 81C86CC - push {r4,lr} - bl sub_81C8644 - adds r4, r0, 0 - bl sub_81C84A4 - adds r1, r0, 0 - cmp r1, 0 - beq _081C86F8 - ldrh r0, [r4] - ldrh r1, [r4, 0x8] - cmp r0, r1 - bcc _081C86EA - ldrh r0, [r4, 0x8] - b _081C86EC -_081C86EA: - ldrh r0, [r4] -_081C86EC: - negs r0, r0 - movs r1, 0x1 - bl sub_81C84E8 - movs r0, 0x2 - b _081C8706 -_081C86F8: - ldrh r0, [r4, 0x6] - cmp r0, 0 - bne _081C8702 - movs r0, 0 - b _081C8706 -_081C8702: - strh r1, [r4, 0x6] - movs r0, 0x1 -_081C8706: - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_81C86CC - - thumb_func_start sub_81C870C -sub_81C870C: @ 81C870C - push {r4,lr} - bl sub_81C8644 - adds r4, r0, 0 - bl sub_81C84C0 - cmp r0, 0 - beq _081C8736 - ldrh r0, [r4] - ldrh r3, [r4, 0x8] - adds r2, r0, r3 - ldrh r1, [r4, 0x4] - subs r0, r1, r0 - cmp r2, r1 - bgt _081C872C - adds r0, r3, 0 -_081C872C: - movs r1, 0x1 - bl sub_81C84E8 - movs r0, 0x2 - b _081C8756 -_081C8736: - ldrh r0, [r4, 0x2] - ldrh r1, [r4, 0x8] - cmp r0, r1 - bcc _081C8744 - ldrh r1, [r4, 0x6] - ldrh r0, [r4, 0x8] - b _081C8748 -_081C8744: - ldrh r1, [r4, 0x6] - ldrh r0, [r4, 0x2] -_081C8748: - subs r0, 0x1 - cmp r1, r0 - bge _081C8754 - strh r0, [r4, 0x6] - movs r0, 0x1 - b _081C8756 -_081C8754: - movs r0, 0 -_081C8756: - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_81C870C - - thumb_func_start sub_81C875C -sub_81C875C: @ 81C875C - push {lr} - bl sub_81C8644 - adds r1, r0, 0 - ldrh r0, [r1] - ldrh r1, [r1, 0x6] - adds r0, r1 - pop {r1} - bx r1 - thumb_func_end sub_81C875C - - thumb_func_start sub_81C8770 -sub_81C8770: @ 81C8770 - push {lr} - bl sub_81C8644 - ldrh r0, [r0] - pop {r1} - bx r1 - thumb_func_end sub_81C8770 - - thumb_func_start sub_81C877C -sub_81C877C: @ 81C877C - push {r4,lr} - movs r0, 0x11 - bl GetSubstructPtr - adds r4, r0, 0 - ldr r0, =0x0000089c - adds r1, r4, r0 - movs r0, 0 - str r0, [r1] - ldr r0, =sub_81C8870 - movs r1, 0x6 - bl sub_81C7078 - movs r1, 0x8A - lsls r1, 4 - adds r4, r1 - str r0, [r4] - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81C877C - - thumb_func_start sub_81C87AC -sub_81C87AC: @ 81C87AC - push {r4,r5,lr} - adds r4, r0, 0 - lsls r4, 16 - lsrs r4, 16 - movs r0, 0x11 - bl GetSubstructPtr - adds r5, r0, 0 - ldr r0, =0x00000888 - adds r1, r5, r0 - ldrh r0, [r1] - adds r0, r4 - movs r2, 0 - strh r0, [r1] - ldr r1, =0x0000089c - adds r0, r5, r1 - str r2, [r0] - ldr r0, =sub_81C8958 - movs r1, 0x6 - bl sub_81C7078 - movs r1, 0x8A - lsls r1, 4 - adds r5, r1 - str r0, [r5] - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81C87AC - thumb_func_start sub_81C87F0 sub_81C87F0: @ 81C87F0 push {r4,lr} diff --git a/src/pokenav.c b/src/pokenav.c index 16a67daf7..9b315dc9a 100644 --- a/src/pokenav.c +++ b/src/pokenav.c @@ -78,7 +78,7 @@ struct UnknownSubStruct_81C81D4 u32 unk18; u32 unk1C; s32 unk20; - u32 unk24; + s32 unk24; u32 unk28; s32 unk2C; u32 unk30; @@ -90,7 +90,8 @@ struct UnknownSubStruct_81C81D4 char unk48[0x40]; u8 tilemapBuffer[0x800]; struct UnknownSubSubStruct_81C81D4 unk888; - u8 unk898[0x6]; + u32 unk89C; + u32 unk8A0; }; #define SUBSTRUCT_COUNT 19 @@ -168,15 +169,17 @@ extern u32 sub_81D04B8(void); extern u32 sub_81D09F4(void); extern u32 sub_81CFA04(void); extern u32 sub_81CFE08(void); -extern u32 sub_81C85A0(s32); extern u32 sub_81C91AC(struct UnknownSubStruct_81C81D4 *a0, const void *a1, void *a2, s32 a3); extern u32 sub_81C9160(struct UnknownSubSubStruct_81C81D4 *a0, void *a1); extern void sub_81C8ED0(void); extern void sub_81C8EF8(struct UnknownSubSubStruct_81C81D4 *a0, struct UnknownSubSubStruct_0203CF40 *a1); +extern u32 sub_81C8870(s32 a0); +extern u32 sub_81C8958(s32 a0); +u32 sub_81C85A0(s32); void sub_81C8568(s32 a0, struct UnknownSubStruct_81C81D4 *a1); u32 sub_81C83F0(s32); -u32 sub_81C83E0(void); +bool32 sub_81C83E0(void); void sub_81C83AC(u32 a0, u32 a1, u32 a2, u32 a3, u32 a4, struct UnknownSubStruct_81C81D4 *a5); void sub_81C837C(struct UnknownSubSubStruct_81C81D4 *a0, struct UnknownSubStruct_81C81D4 *a1); void sub_81C835C(struct UnknownSubSubStruct_0203CF40 *a0); @@ -1612,7 +1615,7 @@ void sub_81C83AC(u32 a0, u32 a1, u32 a2, u32 a3, u32 a4, struct UnknownSubStruct sub_81C7078(sub_81C83F0, 5); } -u32 sub_81C83E0(void) +bool32 sub_81C83E0(void) { return sub_81C7124(sub_81C83F0); } @@ -1806,4 +1809,222 @@ void sub_81C8568(s32 a0, struct UnknownSubStruct_81C81D4 *a1) a1->unk30 = 2; a1->unk2C = a0; a1->unk28 = sub_81C7078(sub_81C85A0, 6); +} + +u32 sub_81C85A0(s32 a0) +{ + s32 y; + s32 v1; + bool32 flag; + struct UnknownSubStruct_81C81D4 *structPtr; + structPtr = GetSubstructPtr(0x11); + + switch (a0) + { + case 0: + if (sub_81C83E0() == FALSE) + return 1; + else + return 2; + case 1: + flag = FALSE; + y = GetBgY(structPtr->unk0.bg); + v1 = ChangeBgY(structPtr->unk0.bg, 0x1000, structPtr->unk30); + if (structPtr->unk30 == 2) + { + if ((y > structPtr->unk24 || y <= structPtr->unk20) && v1 <= structPtr->unk24) + { + flag = TRUE; + } + } + else + { + if ((y < structPtr->unk24 || y >= structPtr->unk20) && v1 >= structPtr->unk24) + { + flag = TRUE; + } + } + if (flag) + { + structPtr->unk0.unkA = (structPtr->unk0.unkA + structPtr->unk2C) & 0xF; + ChangeBgY(structPtr->unk0.bg, structPtr->unk24, 0); + return 4; + } + else + { + return 2; + } + default: + return 4; + } +} + +bool32 sub_81C8630(void) +{ + struct UnknownSubStruct_81C81D4 *structPtr; + structPtr = GetSubstructPtr(0x11); + return sub_81C70D8(structPtr->unk28); +} + +struct UnknownSubSubStruct_81C81D4 *sub_81C8644(void) +{ + struct UnknownSubStruct_81C81D4 *structPtr; + structPtr = GetSubstructPtr(0x11); + return &structPtr->unk888; +} + +u32 sub_81C8658(void) +{ + struct UnknownSubSubStruct_81C81D4 *structPtr; + structPtr = sub_81C8644(); + + // Using unk6 as a timer. + if (structPtr->unk6 != 0) + { + structPtr->unk6--; + return 1; + } + else + { + if (sub_81C84A4()) + { + sub_81C84E8(-1, 1); + return 2; + } + else + { + return 0; + } + } +} + +u32 sub_81C868C(void) +{ + struct UnknownSubSubStruct_81C81D4 *structPtr; + structPtr = sub_81C8644(); + + if (structPtr->unk0 + structPtr->unk6 < structPtr->unk2 - 1) + { + if (structPtr->unk6 < structPtr->unk8 - 1) + { + structPtr->unk6++; + return 1; + } + else if (!sub_81C84C0()) + { + return 0; + } + } + else + { + return 0; + } + sub_81C84E8(1, 1); + return 2; +} + +u32 sub_81C86CC(void) +{ + struct UnknownSubSubStruct_81C81D4 *structPtr; + s32 v1; + + structPtr = sub_81C8644(); + if (sub_81C84A4()) + { + if (structPtr->unk0 >= structPtr->unk8) + v1 = structPtr->unk8; + else + v1 = structPtr->unk0; + sub_81C84E8(v1 * -1, 1); + return 2; + } + else if (structPtr->unk6 != 0) + { + structPtr->unk6 = 0; + return 1; + } + else + { + return 0; + } +} + +u32 sub_81C870C(void) +{ + struct UnknownSubSubStruct_81C81D4 *structPtr; + structPtr = sub_81C8644(); + + if (sub_81C84C0()) + { + s32 v1; + s32 v2; + s32 v3; + v2 = structPtr->unk0 + structPtr->unk8; + v1 = structPtr->unk4 - structPtr->unk0; + if (v2 <= structPtr->unk4) + v1 = structPtr->unk8; + sub_81C84E8(v1, 1); + return 2; + } + else + { + s32 v1; + s32 v2; + if (structPtr->unk2 >= structPtr->unk8) + { + v1 = structPtr->unk6; + v2 = structPtr->unk8; + } + else + { + v1 = structPtr->unk6; + v2 = structPtr->unk2; + } + v2 -= 1; + if (v1 >= v2) + { + return 0; + } + else + { + structPtr->unk6 = v2; + return 1; + } + } +} + +u32 sub_81C875C(void) +{ + struct UnknownSubSubStruct_81C81D4 *structPtr; + structPtr = sub_81C8644(); + + return structPtr->unk0 + structPtr->unk6; +} + +u32 sub_81C8770(void) +{ + struct UnknownSubSubStruct_81C81D4 *structPtr; + structPtr = sub_81C8644(); + + return structPtr->unk0; +} + +void sub_81C877C(void) +{ + struct UnknownSubStruct_81C81D4 *structPtr; + structPtr = GetSubstructPtr(0x11); + structPtr->unk89C = 0; + structPtr->unk8A0 = sub_81C7078(sub_81C8870, 6); +} + +void sub_81C87AC(u16 a0) +{ + u16 temp; + struct UnknownSubStruct_81C81D4 *structPtr; + structPtr = GetSubstructPtr(0x11); + temp = structPtr->unk888.unk0; + temp += a0; + structPtr->unk888.unk0 = temp; + structPtr->unk89C = 0; + structPtr->unk8A0 = sub_81C7078(sub_81C8958, 6); } \ No newline at end of file