From 56b124fdecd3fab46eca856b80a5582235eb5abe Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Thu, 25 Jul 2019 21:41:02 +0200 Subject: [PATCH] Some more pokenav --- asm/pokenav_unk_8.s | 212 -------------------------------------------- include/pokenav.h | 15 +++- ld_script.txt | 1 + src/pokenav.c | 4 +- src/pokenav_unk_6.c | 12 --- src/pokenav_unk_8.c | 115 ++++++++++++++++++++++++ 6 files changed, 132 insertions(+), 227 deletions(-) create mode 100644 src/pokenav_unk_8.c diff --git a/asm/pokenav_unk_8.s b/asm/pokenav_unk_8.s index 5bba161bb..6fcf21374 100644 --- a/asm/pokenav_unk_8.s +++ b/asm/pokenav_unk_8.s @@ -5,219 +5,7 @@ @ File centered around AllocSubstruct(7) - thumb_func_start sub_81CEF3C -sub_81CEF3C: @ 81CEF3C - push {r4,lr} - movs r0, 0x7 - movs r1, 0x24 - bl AllocSubstruct - adds r4, r0, 0 - cmp r4, 0 - beq _081CEF90 - ldr r1, =0x000006ac - movs r0, 0x12 - bl AllocSubstruct - str r0, [r4, 0x20] - cmp r0, 0 - beq _081CEF90 - ldr r0, =sub_81CF010 - str r0, [r4] - ldr r0, =sub_81CF11C - movs r1, 0x1 - bl CreateLoopedTask - str r0, [r4, 0x4] - movs r0, 0 - str r0, [r4, 0x18] - bl sub_81C76AC - ldr r1, =gUnknown_086233A0 - lsls r0, 2 - adds r0, r1 - ldr r0, [r0] - str r0, [r4, 0x14] - movs r0, 0x1 - b _081CEF92 - .pool -_081CEF90: - movs r0, 0 -_081CEF92: - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_81CEF3C - thumb_func_start sub_81CEF98 -sub_81CEF98: @ 81CEF98 - push {r4,lr} - movs r0, 0x7 - movs r1, 0x24 - bl AllocSubstruct - adds r4, r0, 0 - cmp r4, 0 - beq _081CEFD4 - movs r0, 0x12 - bl GetSubstructPtr - str r0, [r4, 0x20] - ldr r0, =sub_81CF030 - str r0, [r4] - movs r0, 0x1 - str r0, [r4, 0x18] - bl sub_81C76AC - ldr r1, =gUnknown_086233A0 - lsls r0, 2 - adds r0, r1 - ldr r0, [r0] - str r0, [r4, 0x14] - movs r0, 0x1 - b _081CEFD6 - .pool -_081CEFD4: - movs r0, 0 -_081CEFD6: - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_81CEF98 - - thumb_func_start sub_81CEFDC -sub_81CEFDC: @ 81CEFDC - push {lr} - movs r0, 0x7 - bl GetSubstructPtr - ldr r1, [r0] - bl _call_via_r1 - pop {r1} - bx r1 - thumb_func_end sub_81CEFDC - - thumb_func_start sub_81CEFF0 -sub_81CEFF0: @ 81CEFF0 - push {lr} - movs r0, 0x7 - bl GetSubstructPtr - ldr r0, [r0, 0x1C] - cmp r0, 0 - bne _081CF004 - movs r0, 0x12 - bl FreePokenavSubstruct -_081CF004: - movs r0, 0x7 - bl FreePokenavSubstruct - pop {r0} - bx r0 - thumb_func_end sub_81CEFF0 - - thumb_func_start sub_81CF010 -sub_81CF010: @ 81CF010 - push {r4,lr} - adds r4, r0, 0 - ldr r0, [r4, 0x4] - bl IsLoopedTaskActive - cmp r0, 0 - bne _081CF022 - ldr r0, =sub_81CF030 - str r0, [r4] -_081CF022: - movs r0, 0 - pop {r4} - pop {r1} - bx r1 - .pool - thumb_func_end sub_81CF010 - - thumb_func_start sub_81CF030 -sub_81CF030: @ 81CF030 - push {r4,r5,lr} - adds r4, r0, 0 - ldr r2, =gMain - ldrh r1, [r2, 0x30] - movs r0, 0x40 - ands r0, r1 - cmp r0, 0 - beq _081CF048 - movs r0, 0x1 - b _081CF0A6 - .pool -_081CF048: - movs r0, 0x80 - ands r0, r1 - cmp r0, 0 - beq _081CF054 - movs r0, 0x2 - b _081CF0A6 -_081CF054: - ldrh r1, [r2, 0x2E] - movs r0, 0x20 - ands r0, r1 - cmp r0, 0 - beq _081CF062 - movs r0, 0x3 - b _081CF0A6 -_081CF062: - movs r0, 0x10 - ands r0, r1 - lsls r0, 16 - lsrs r2, r0, 16 - cmp r2, 0 - beq _081CF072 - movs r0, 0x4 - b _081CF0A6 -_081CF072: - movs r0, 0x2 - ands r0, r1 - cmp r0, 0 - beq _081CF088 - str r2, [r4, 0x1C] - ldr r0, =sub_81CF0B0 - str r0, [r4] - movs r0, 0x5 - b _081CF0A6 - .pool -_081CF088: - movs r5, 0x1 - adds r0, r5, 0 - ands r0, r1 - cmp r0, 0 - bne _081CF096 - movs r0, 0 - b _081CF0A6 -_081CF096: - bl GetSelectedMatchCall - ldr r1, [r4, 0x20] - strh r0, [r1, 0x2] - str r5, [r4, 0x1C] - ldr r0, =sub_81CF0B8 - str r0, [r4] - movs r0, 0x6 -_081CF0A6: - pop {r4,r5} - pop {r1} - bx r1 - .pool - thumb_func_end sub_81CF030 - - thumb_func_start sub_81CF0B0 -sub_81CF0B0: @ 81CF0B0 - ldr r0, =0x000186a3 - bx lr - .pool - thumb_func_end sub_81CF0B0 - - thumb_func_start sub_81CF0B8 -sub_81CF0B8: @ 81CF0B8 - ldr r0, =0x000186a9 - bx lr - .pool - thumb_func_end sub_81CF0B8 - - thumb_func_start sub_81CF0C0 -sub_81CF0C0: @ 81CF0C0 - push {lr} - movs r0, 0x7 - bl GetSubstructPtr - ldr r0, [r0, 0x18] - pop {r1} - bx r1 - thumb_func_end sub_81CF0C0 thumb_func_start sub_81CF0D0 sub_81CF0D0: @ 81CF0D0 diff --git a/include/pokenav.h b/include/pokenav.h index b6d3fff86..d254858ac 100644 --- a/include/pokenav.h +++ b/include/pokenav.h @@ -3,9 +3,22 @@ #include "bg.h" #include "main.h" +#include "pokemon_storage_system.h" typedef u32 (*LoopedTask)(s32 state); +struct PokenavSub18 +{ + u16 unk0; + u16 unk2; + struct + { + u8 boxId; + u8 monId; + u16 unk6; + } unk4[TOTAL_BOXES_COUNT * IN_BOX_COUNT + PARTY_SIZE]; +}; + // Return values of LoopedTask functions. #define LT_INC_AND_PAUSE 0 #define LT_INC_AND_CONTINUE 1 @@ -43,7 +56,7 @@ enum // pokenav.c void sub_81C7694(u32); -u16 sub_81C76AC(void); +u32 sub_81C76AC(void); void CB2_InitPokeNav(void); u32 CreateLoopedTask(LoopedTask loopedTask, u32 priority); diff --git a/ld_script.txt b/ld_script.txt index f2eb6b88f..9bb3dbb41 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -318,6 +318,7 @@ SECTIONS { src/pokenav_unk_5.o(.text*); src/pokenav_unk_6.o(.text*); src/pokenav_unk_7.o(.text*); + src/pokenav_unk_8.o(.text*); asm/pokenav_unk_8.o(.text*); asm/pokenav_unk_9.o(.text*); asm/pokenav_unk_10.o(.text*); diff --git a/src/pokenav.c b/src/pokenav.c index be3826bed..132e4123b 100644 --- a/src/pokenav.c +++ b/src/pokenav.c @@ -318,7 +318,7 @@ void Task_RunLoopedTask_LinkMode(u8 taskId) if (sub_8087598()) return; - + task = (LoopedTask)GetWordTaskArg(taskId, 1); state = &gTasks[taskId].data[0]; action = task(*state); @@ -605,7 +605,7 @@ void sub_81C7694(u32 a0) gPokenavResources->fieldA = value; } -u16 sub_81C76AC(void) +u32 sub_81C76AC(void) { return gPokenavResources->fieldA; } diff --git a/src/pokenav_unk_6.c b/src/pokenav_unk_6.c index 0fe5f7a8f..638884d3f 100644 --- a/src/pokenav_unk_6.c +++ b/src/pokenav_unk_6.c @@ -35,18 +35,6 @@ struct PokenavSub11 u8 unk678A; }; -struct PokenavSub18 -{ - u16 unk0; - u16 unk2; - struct - { - u8 boxId; - u8 monId; - u16 unk6; - } unk4[TOTAL_BOXES_COUNT * IN_BOX_COUNT + PARTY_SIZE]; -}; - void sub_81CD970(void); void sub_81CD9F8(void); u32 sub_81CD08C(struct PokenavSub11 *structPtr); diff --git a/src/pokenav_unk_8.c b/src/pokenav_unk_8.c new file mode 100644 index 000000000..56ffd0f0a --- /dev/null +++ b/src/pokenav_unk_8.c @@ -0,0 +1,115 @@ +#include "global.h" +#include "pokenav.h" + +struct PokenavSub7 +{ + u32 (*unk0)(struct PokenavSub7 *); + u32 loopedTaskId; + u8 fill1[12]; + u32 unk14; + u32 unk18; + u32 unk1C; + struct PokenavSub18 *unkPtr; +}; + +extern const u32 gUnknown_086233A0[]; + +u32 sub_81CF010(struct PokenavSub7 *structPtr); +u32 sub_81CF030(struct PokenavSub7 *structPtr); +u32 sub_81CF0B8(struct PokenavSub7 *structPtr); +u32 sub_81CF0B0(struct PokenavSub7 *structPtr); +u32 sub_81CF11C(s32 state); + +bool32 sub_81CEF3C(void) +{ + struct PokenavSub7 *structPtr = AllocSubstruct(7, sizeof(struct PokenavSub7)); + if (structPtr == NULL) + return FALSE; + + structPtr->unkPtr = AllocSubstruct(18, sizeof(struct PokenavSub18)); + if (structPtr->unkPtr == NULL) + return FALSE; + + structPtr->unk0 = sub_81CF010; + structPtr->loopedTaskId = CreateLoopedTask(sub_81CF11C, 1); + structPtr->unk18 = 0; + structPtr->unk14 = gUnknown_086233A0[sub_81C76AC()]; + return TRUE; +} + +bool32 sub_81CEF98(void) +{ + struct PokenavSub7 *structPtr = AllocSubstruct(7, sizeof(struct PokenavSub7)); + if (structPtr == NULL) + return FALSE; + + structPtr->unkPtr = GetSubstructPtr(18); + structPtr->unk0 = sub_81CF030; + structPtr->unk18 = 1; + structPtr->unk14 = gUnknown_086233A0[sub_81C76AC()]; + return TRUE; +} + +u32 sub_81CEFDC(void) +{ + struct PokenavSub7 *structPtr = GetSubstructPtr(7); + return structPtr->unk0(structPtr); +} + +void sub_81CEFF0(void) +{ + struct PokenavSub7 *structPtr = GetSubstructPtr(7); + if (structPtr->unk1C == 0) + FreePokenavSubstruct(18); + FreePokenavSubstruct(7); +} + +bool32 sub_81CF010(struct PokenavSub7 *structPtr) +{ + if (!IsLoopedTaskActive(structPtr->loopedTaskId)) + structPtr->unk0 = sub_81CF030; + return FALSE; +} + +u32 sub_81CF030(struct PokenavSub7 *structPtr) +{ + if (gMain.newAndRepeatedKeys & DPAD_UP) + return 1; + else if (gMain.newAndRepeatedKeys & DPAD_DOWN) + return 2; + else if (gMain.newKeys & DPAD_LEFT) + return 3; + else if (gMain.newKeys & DPAD_RIGHT) + return 4; + else if (gMain.newKeys & B_BUTTON) + { + structPtr->unk1C = 0; + structPtr->unk0 = sub_81CF0B0; + return 5; + } + else if (gMain.newKeys & A_BUTTON) + { + structPtr->unkPtr->unk2 = GetSelectedMatchCall(); + structPtr->unk1C = 1; + structPtr->unk0 = sub_81CF0B8; + return 6; + } + else + return 0; +} + +u32 sub_81CF0B0(struct PokenavSub7 *structPtr) +{ + return 0x186A3; +} + +u32 sub_81CF0B8(struct PokenavSub7 *structPtr) +{ + return 0x186A9; +} + +u32 sub_81CF0C0(void) +{ + struct PokenavSub7 *structPtr = GetSubstructPtr(7); + return structPtr->unk18; +}