diff --git a/asm/pokenav_unk_9.s b/asm/pokenav_unk_9.s index 7f9d5d15be..5a91510fdb 100644 --- a/asm/pokenav_unk_9.s +++ b/asm/pokenav_unk_9.s @@ -5,206 +5,7 @@ @ File centered around AllocSubstruct(9) - thumb_func_start sub_81CF9BC -sub_81CF9BC: @ 81CF9BC - push {r4,lr} - movs r0, 0x9 - movs r1, 0x20 - bl AllocSubstruct - adds r4, r0, 0 - cmp r4, 0 - beq _081CF9FC - ldr r1, =0x000006ac - movs r0, 0x12 - bl AllocSubstruct - str r0, [r4, 0x1C] - cmp r0, 0 - beq _081CF9FC - ldr r0, =sub_81CFA68 - str r0, [r4] - ldr r0, =sub_81CFB74 - movs r1, 0x1 - bl CreateLoopedTask - str r0, [r4, 0x4] - movs r0, 0 - str r0, [r4, 0x14] - movs r0, 0x1 - b _081CF9FE - .pool -_081CF9FC: - movs r0, 0 -_081CF9FE: - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_81CF9BC - thumb_func_start sub_81CFA04 -sub_81CFA04: @ 81CFA04 - push {r4,lr} - movs r0, 0x9 - movs r1, 0x20 - bl AllocSubstruct - adds r4, r0, 0 - cmp r4, 0 - beq _081CFA2C - movs r0, 0x12 - bl GetSubstructPtr - str r0, [r4, 0x1C] - ldr r0, =sub_81CFA88 - str r0, [r4] - movs r0, 0x1 - str r0, [r4, 0x14] - b _081CFA2E - .pool -_081CFA2C: - movs r0, 0 -_081CFA2E: - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_81CFA04 - - thumb_func_start sub_81CFA34 -sub_81CFA34: @ 81CFA34 - push {lr} - movs r0, 0x9 - bl GetSubstructPtr - ldr r1, [r0] - bl _call_via_r1 - pop {r1} - bx r1 - thumb_func_end sub_81CFA34 - - thumb_func_start sub_81CFA48 -sub_81CFA48: @ 81CFA48 - push {lr} - movs r0, 0x9 - bl GetSubstructPtr - ldr r0, [r0, 0x18] - cmp r0, 0 - bne _081CFA5C - movs r0, 0x12 - bl FreePokenavSubstruct -_081CFA5C: - movs r0, 0x9 - bl FreePokenavSubstruct - pop {r0} - bx r0 - thumb_func_end sub_81CFA48 - - thumb_func_start sub_81CFA68 -sub_81CFA68: @ 81CFA68 - push {r4,lr} - adds r4, r0, 0 - ldr r0, [r4, 0x4] - bl IsLoopedTaskActive - cmp r0, 0 - bne _081CFA7A - ldr r0, =sub_81CFA88 - str r0, [r4] -_081CFA7A: - movs r0, 0 - pop {r4} - pop {r1} - bx r1 - .pool - thumb_func_end sub_81CFA68 - - thumb_func_start sub_81CFA88 -sub_81CFA88: @ 81CFA88 - 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 _081CFAA0 - movs r0, 0x1 - b _081CFAFE - .pool -_081CFAA0: - movs r0, 0x80 - ands r0, r1 - cmp r0, 0 - beq _081CFAAC - movs r0, 0x2 - b _081CFAFE -_081CFAAC: - ldrh r1, [r2, 0x2E] - movs r0, 0x20 - ands r0, r1 - cmp r0, 0 - beq _081CFABA - movs r0, 0x3 - b _081CFAFE -_081CFABA: - movs r0, 0x10 - ands r0, r1 - lsls r0, 16 - lsrs r2, r0, 16 - cmp r2, 0 - beq _081CFACA - movs r0, 0x4 - b _081CFAFE -_081CFACA: - movs r0, 0x2 - ands r0, r1 - cmp r0, 0 - beq _081CFAE0 - str r2, [r4, 0x18] - ldr r0, =sub_81CFB08 - str r0, [r4] - movs r0, 0x5 - b _081CFAFE - .pool -_081CFAE0: - movs r5, 0x1 - adds r0, r5, 0 - ands r0, r1 - cmp r0, 0 - bne _081CFAEE - movs r0, 0 - b _081CFAFE -_081CFAEE: - bl GetSelectedMatchCall - ldr r1, [r4, 0x1C] - strh r0, [r1, 0x2] - str r5, [r4, 0x18] - ldr r0, =sub_81CFB10 - str r0, [r4] - movs r0, 0x6 -_081CFAFE: - pop {r4,r5} - pop {r1} - bx r1 - .pool - thumb_func_end sub_81CFA88 - - thumb_func_start sub_81CFB08 -sub_81CFB08: @ 81CFB08 - ldr r0, =0x000186a5 - bx lr - .pool - thumb_func_end sub_81CFB08 - - thumb_func_start sub_81CFB10 -sub_81CFB10: @ 81CFB10 - ldr r0, =0x000186ad - bx lr - .pool - thumb_func_end sub_81CFB10 - - thumb_func_start sub_81CFB18 -sub_81CFB18: @ 81CFB18 - push {lr} - movs r0, 0x9 - bl GetSubstructPtr - ldr r0, [r0, 0x14] - pop {r1} - bx r1 - thumb_func_end sub_81CFB18 thumb_func_start sub_81CFB28 sub_81CFB28: @ 81CFB28 diff --git a/include/bg.h b/include/bg.h index ad5acd0ae9..3c7eee2927 100644 --- a/include/bg.h +++ b/include/bg.h @@ -27,13 +27,13 @@ enum struct BgTemplate { - u32 bg:2; // 0x1, 0x2 -> 0x3 - u32 charBaseIndex:2; // 0x4, 0x8 -> 0xC - u32 mapBaseIndex:5; // 0x10, 0x20, 0x40, 0x80, 0x100 -> 0x1F0 - u32 screenSize:2; // 0x200, 0x400 -> 0x600 - u32 paletteMode:1; // 0x800 - u32 priority:2; // 0x1000, 0x2000 > 0x3000 - u32 baseTile:10; + u16 bg:2; // 0x1, 0x2 -> 0x3 + u16 charBaseIndex:2; // 0x4, 0x8 -> 0xC + u16 mapBaseIndex:5; // 0x10, 0x20, 0x40, 0x80, 0x100 -> 0x1F0 + u16 screenSize:2; // 0x200, 0x400 -> 0x600 + u16 paletteMode:1; // 0x800 + u16 priority:2; // 0x1000, 0x2000 > 0x3000 + u16 baseTile:10; }; void ResetBgs(void); diff --git a/ld_script.txt b/ld_script.txt index f820a920e4..17d0d05748 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -318,6 +318,7 @@ SECTIONS { src/pokenav_unk_7.o(.text*); src/pokenav_unk_8.o(.text*); asm/pokenav_unk_8.o(.text*); + src/pokenav_unk_9.o(.text*); asm/pokenav_unk_9.o(.text*); src/pokenav_unk_10.o(.text*); src/pokenav_match_call_data.o(.text*); diff --git a/src/pokenav_match_call_ui.c b/src/pokenav_match_call_ui.c index bae3a8d7ae..5204f0ed7a 100644 --- a/src/pokenav_match_call_ui.c +++ b/src/pokenav_match_call_ui.c @@ -34,7 +34,7 @@ struct MatchCallWindowState { u32 unk10; }; -struct UnknownInnerStruct_81C81D4 +struct PokenavSub17Substruct { struct UnknownSubSubStruct_0203CF40 unk0; u32 unk10; @@ -55,68 +55,699 @@ struct UnknownInnerStruct_81C81D4 }; // Generally at index 0x11 (17) -struct UnknownSubStruct_81C81D4 +struct PokenavSub17 { - struct UnknownInnerStruct_81C81D4 unk0; + struct PokenavSub17Substruct unk0; u8 tilemapBuffer[0x800]; struct MatchCallWindowState unk888; - u32 unk89C; + s32 unk89C; u32 unk8A0; }; extern void sub_81DB620(u32 windowId, u32 a1, u32 a2, u32 a3, u32 a4); -void sub_81C82E4(struct UnknownSubStruct_81C81D4 *a0); -u32 sub_81C91AC(struct UnknownInnerStruct_81C81D4 *a0, const struct BgTemplate *a1, struct MatchCallListTemplate *a2, s32 a3); +void sub_81C82E4(struct PokenavSub17 *a0); +bool32 sub_81C91AC(struct PokenavSub17Substruct *a0, const struct BgTemplate *a1, struct MatchCallListTemplate *a2, s32 a3); void sub_81C9160(struct MatchCallWindowState *a0, struct MatchCallListTemplate *a1); void SpriteCB_MatchCallUpArrow(struct Sprite *sprite); void SpriteCB_MatchCallDownArrow(struct Sprite *sprite); void SpriteCB_MatchCallRightArrow(struct Sprite *sprite); -void ToggleMatchCallArrows(struct UnknownInnerStruct_81C81D4 *a0, u32 a1); -void sub_81C8FE0(struct UnknownInnerStruct_81C81D4 *a0); -void sub_81C8EF8(struct MatchCallWindowState *a0, struct UnknownInnerStruct_81C81D4 *a1); +void ToggleMatchCallArrows(struct PokenavSub17Substruct *a0, u32 a1); +void sub_81C8FE0(struct PokenavSub17Substruct *a0); +void sub_81C8EF8(struct MatchCallWindowState *a0, struct PokenavSub17Substruct *a1); void sub_81C8ED0(void); -void sub_81C8E54(struct MatchCallWindowState *a0, struct UnknownInnerStruct_81C81D4 *a1, u32 a2); -void PrintMatchCallFieldNames(struct UnknownInnerStruct_81C81D4 *a0, u32 a1); -void sub_81C8D4C(struct MatchCallWindowState *a0, struct UnknownInnerStruct_81C81D4 *a1); -void sub_81C8CB4(struct MatchCallWindowState *a0, struct UnknownInnerStruct_81C81D4 *a1); -void sub_81C8B70(struct UnknownSubSubStruct_0203CF40 *a0, u32 a1, u32 a2); -void sub_81C8568(s32 a0, struct UnknownInnerStruct_81C81D4 *a1); -void sub_81C83AC(u32 a0, u32 a1, u32 a2, u32 a3, u32 a4, struct UnknownInnerStruct_81C81D4 *a5); -void sub_81C837C(struct MatchCallWindowState *a0, struct UnknownInnerStruct_81C81D4 *a1); +void sub_81C8E54(struct MatchCallWindowState *a0, struct PokenavSub17Substruct *a1, u32 a2); +void PrintMatchCallFieldNames(struct PokenavSub17Substruct *a0, u32 a1); +void sub_81C8D4C(struct MatchCallWindowState *a0, struct PokenavSub17Substruct *a1); +void sub_81C8CB4(struct MatchCallWindowState *a0, struct PokenavSub17Substruct *a1); +void sub_81C8B70(struct UnknownSubSubStruct_0203CF40 *a0, s32 a1, s32 a2); +void sub_81C8568(s32 a0, struct PokenavSub17Substruct *a1); +void sub_81C83AC(u32 a0, u32 a1, u32 a2, u32 a3, u32 a4, struct PokenavSub17Substruct *a5); +void sub_81C837C(struct MatchCallWindowState *a0, struct PokenavSub17Substruct *a1); void sub_81C835C(struct UnknownSubSubStruct_0203CF40 *a0); -u32 LoopedTask_sub_81C8254(s32 a0); +u32 LoopedTask_sub_81C8254(s32 state); bool32 sub_81C83E0(void); -u32 LoopedTask_sub_81C83F0(s32 a0); -u32 LoopedTask_sub_81C85A0(s32 a0); -u32 LoopedTask_sub_81C8870(s32 a0); -u32 LoopedTask_sub_81C8A28(s32 a0); -u32 LoopedTask_sub_81C8958(s32 a0); +u32 LoopedTask_sub_81C83F0(s32 state); +u32 LoopedTask_sub_81C85A0(s32 state); +u32 LoopedTask_sub_81C8870(s32 state); +u32 LoopedTask_sub_81C8A28(s32 state); +u32 LoopedTask_sub_81C8958(s32 state); static const u16 sMatchcallArrowPaletteData[] = INCBIN_U16("graphics/pokenav/arrows_matchcall.gbapal"); static const u32 sMatchcallArrowSpriteSheetData[] = INCBIN_U32("graphics/pokenav/arrows_matchcall.4bpp.lz"); -static const u8 sPokenavColors_0861FBE4[] = -{ - 0, 2, 5 -}; +EWRAM_DATA u32 gUnknown_0203CF44 = 0; -static const u8 *const sMatchCallFieldNames[] = +bool32 sub_81C81D4(const struct BgTemplate *arg0, struct MatchCallListTemplate *arg1, s32 arg2) { - gText_PokenavMatchCall_Strategy, - gText_PokenavMatchCall_TrainerPokemon, - gText_PokenavMatchCall_SelfIntroduction -}; + struct PokenavSub17 *structPtr = AllocSubstruct(17, sizeof(struct PokenavSub17)); + if (structPtr == NULL) + return FALSE; -static const u8 sMatchCallFieldColors[] = -{ - 1, 4, 5 -}; + sub_81C9160(&structPtr->unk888, arg1); + if (!sub_81C91AC(&structPtr->unk0, arg0, arg1, arg2)) + return FALSE; -static const u8 sUnknown_0861FBF7[] = + CreateLoopedTask(LoopedTask_sub_81C8254, 6); + return TRUE; +} + +bool32 sub_81C8224(void) { - 2, 4, 6, 7, 0 -}; + return FuncIsActiveLoopedTask(LoopedTask_sub_81C8254); +} + +void sub_81C8234(void) +{ + struct PokenavSub17 *structPtr; + + structPtr = GetSubstructPtr(17); + sub_81C8FE0(&structPtr->unk0); + RemoveWindow(structPtr->unk0.unk0.windowId); + FreePokenavSubstruct(17); +} + +u32 LoopedTask_sub_81C8254(s32 state) +{ + struct PokenavSub17 *structPtr; + + if (IsDma3ManagerBusyWithBgCopy()) + return 2; + + structPtr = GetSubstructPtr(17); + + switch (state) + { + case 0: + sub_81C82E4(structPtr); + return LT_INC_AND_PAUSE; + case 1: + sub_81C835C(&structPtr->unk0.unk0); + return LT_INC_AND_PAUSE; + case 2: + sub_81C837C(&structPtr->unk888, &structPtr->unk0); + return LT_INC_AND_PAUSE; + case 3: + if (sub_81C83E0()) + { + return LT_PAUSE; + } + else + { + sub_81C8ED0(); + return LT_INC_AND_CONTINUE; + } + case 4: + sub_81C8EF8(&structPtr->unk888, &structPtr->unk0); + return LT_FINISH; + default: + return LT_FINISH; + } +} + +void sub_81C82E4(struct PokenavSub17 *a0) +{ + u16 tileNum = (a0->unk0.unk0.unk1 << 12) | a0->unk0.unk0.unk6; + sub_8199DF0(a0->unk0.unk0.bg, PIXEL_FILL(1), a0->unk0.unk0.unk6, 1); + sub_8199DF0(a0->unk0.unk0.bg, PIXEL_FILL(4), a0->unk0.unk0.unk6 + 1, 1); + SetBgTilemapBuffer(a0->unk0.unk0.bg, a0->tilemapBuffer); + FillBgTilemapBufferRect_Palette0(a0->unk0.unk0.bg, tileNum, 0, 0, 32, 32); + ChangeBgY(a0->unk0.unk0.bg, 0, 0); + ChangeBgX(a0->unk0.unk0.bg, 0, 0); + ChangeBgY(a0->unk0.unk0.bg, a0->unk0.unk0.unk3 << 11, 2); + CopyBgTilemapBufferToVram(a0->unk0.unk0.bg); +} + +void sub_81C835C(struct UnknownSubSubStruct_0203CF40 *a0) +{ + FillWindowPixelBuffer(a0->windowId, PIXEL_FILL(1)); + PutWindowTilemap(a0->windowId); + CopyWindowToVram(a0->windowId, 1); +} + +void sub_81C837C(struct MatchCallWindowState *a0, struct PokenavSub17Substruct *a1) +{ + s32 arg2 = a0->listLength - a0->windowTopIndex; + if (arg2 > a0->visibleEntries) + arg2 = a0->visibleEntries; + + sub_81C83AC(a0->unk10, a0->windowTopIndex, arg2, a0->unkC, 0, a1); +} + +void sub_81C83AC(u32 a0, u32 a1, u32 a2, u32 a3, u32 a4, struct PokenavSub17Substruct *a5) +{ + if (a2 == 0) + return; + + a5->unk1C = a0 + a1 * a3; + a5->unk18 = a3; + a5->unk0.unkC = 0; + a5->unk0.unkE = a2; + a5->unk14 = a1; + a5->unk10 = a4; + CreateLoopedTask(LoopedTask_sub_81C83F0, 5); +} + +bool32 sub_81C83E0(void) +{ + return FuncIsActiveLoopedTask(LoopedTask_sub_81C83F0); +} + +u32 LoopedTask_sub_81C83F0(s32 state) +{ + u32 v1; + struct PokenavSub17Substruct *structPtr = GetSubstructPtr(17); + + switch (state) + { + case 0: + v1 = (structPtr->unk0.unkA + structPtr->unk0.unkC + structPtr->unk10) & 0xF; + structPtr->unk34(structPtr->unk1C, structPtr->unkTextBuffer); + if (structPtr->unk38 != NULL) + structPtr->unk38(structPtr->unk0.windowId, structPtr->unk14, v1); + + AddTextPrinterParameterized(structPtr->unk0.windowId, structPtr->unk0.fontId, structPtr->unkTextBuffer, 8, (v1 << 4) + 1, 255, NULL); + if (++structPtr->unk0.unkC >= structPtr->unk0.unkE) + { + if (structPtr->unk38 != NULL) + CopyWindowToVram(structPtr->unk0.windowId, 3); + else + CopyWindowToVram(structPtr->unk0.windowId, 2); + return LT_INC_AND_PAUSE; + } + else + { + structPtr->unk1C += structPtr->unk18; + structPtr->unk14++; + return LT_CONTINUE; + } + case 1: + if (IsDma3ManagerBusyWithBgCopy()) + return LT_PAUSE; + return LT_FINISH; + } + return LT_FINISH; +} + +bool32 ShouldShowUpArrow(void) +{ + struct PokenavSub17 *structPtr = GetSubstructPtr(17); + + return (structPtr->unk888.windowTopIndex != 0); +} + +bool32 ShouldShowDownArrow(void) +{ + struct PokenavSub17 *structPtr = GetSubstructPtr(17); + struct MatchCallWindowState *subPtr = &structPtr->unk888; + + return (subPtr->windowTopIndex + subPtr->visibleEntries < subPtr->listLength); +} + +void MatchCall_MoveWindow(s32 a0, bool32 a1) +{ + struct PokenavSub17 *structPtr = GetSubstructPtr(17); + struct MatchCallWindowState *subPtr = &structPtr->unk888; + + if (a0 < 0) + { + if (subPtr->windowTopIndex + a0 < 0) + a0 = -1 * subPtr->windowTopIndex; + if (a1) + sub_81C83AC(subPtr->unk10, subPtr->windowTopIndex + a0, a0 * -1, subPtr->unkC, a0, &structPtr->unk0); + } + else if (a1) + { + s32 temp = gUnknown_0203CF44 = subPtr->windowTopIndex + subPtr->visibleEntries; + if (temp + a0 >= subPtr->listLength) + a0 = subPtr->listLength - temp; + + sub_81C83AC(subPtr->unk10, gUnknown_0203CF44, a0, subPtr->unkC, subPtr->visibleEntries, &structPtr->unk0); + } + + sub_81C8568(a0, &structPtr->unk0); + subPtr->windowTopIndex += a0; +} + +void sub_81C8568(s32 a0, struct PokenavSub17Substruct *a1) +{ + a1->unk20 = GetBgY(a1->unk0.bg); + a1->unk24 = a1->unk20 + (a0 << 12); + if (a0 > 0) + a1->unk30 = 1; + else + a1->unk30 = 2; + a1->unk2C = a0; + a1->unk28 = CreateLoopedTask(LoopedTask_sub_81C85A0, 6); +} + +u32 LoopedTask_sub_81C85A0(s32 state) +{ + s32 y, v1; + bool32 flag; + struct PokenavSub17 *structPtr = GetSubstructPtr(17); + struct PokenavSub17Substruct *subPtr = &structPtr->unk0; + + switch (state) + { + case 0: + if (!sub_81C83E0()) + return LT_INC_AND_CONTINUE; + return LT_PAUSE; + case 1: + flag = FALSE; + y = GetBgY(subPtr->unk0.bg); + v1 = ChangeBgY(subPtr->unk0.bg, 0x1000, subPtr->unk30); + if (subPtr->unk30 == 2) + { + if ((y > subPtr->unk24 || y <= subPtr->unk20) && v1 <= subPtr->unk24) + flag = TRUE; + } + else + { + if ((y < subPtr->unk24 || y >= subPtr->unk20) && v1 >= subPtr->unk24) + flag = TRUE; + } + + if (flag) + { + subPtr->unk0.unkA = (subPtr->unk0.unkA + subPtr->unk2C) & 0xF; + ChangeBgY(subPtr->unk0.bg, subPtr->unk24, 0); + return LT_FINISH; + } + return LT_PAUSE; + } + return LT_FINISH; +} + +bool32 sub_81C8630(void) +{ + struct PokenavSub17 *structPtr = GetSubstructPtr(17); + return IsLoopedTaskActive(structPtr->unk0.unk28); +} + +struct MatchCallWindowState *GetMatchCallWindowStruct(void) +{ + struct PokenavSub17 *structPtr = GetSubstructPtr(17); + return &structPtr->unk888; +} + +int MatchCall_MoveCursorUp(void) +{ + struct MatchCallWindowState *structPtr = GetMatchCallWindowStruct(); + + if (structPtr->selectedIndexOffset != 0) + { + structPtr->selectedIndexOffset--; + return 1; + } + if (ShouldShowUpArrow()) + { + MatchCall_MoveWindow(-1, TRUE); + return 2; + } + return 0; +} + +int MatchCall_MoveCursorDown(void) +{ + struct MatchCallWindowState *structPtr = GetMatchCallWindowStruct(); + + if (structPtr->windowTopIndex + structPtr->selectedIndexOffset >= structPtr->listLength - 1) + return 0; + if (structPtr->selectedIndexOffset < structPtr->visibleEntries - 1) + { + structPtr->selectedIndexOffset++; + return 1; + } + if (ShouldShowDownArrow()) + { + MatchCall_MoveWindow(1, TRUE); + return 2; + } + return 0; +} + +int MatchCall_PageUp(void) +{ + s32 scroll; + struct MatchCallWindowState *structPtr = GetMatchCallWindowStruct(); + + if (ShouldShowUpArrow()) + { + if (structPtr->windowTopIndex >= structPtr->visibleEntries) + scroll = structPtr->visibleEntries; + else + scroll = structPtr->windowTopIndex; + MatchCall_MoveWindow(scroll * -1, TRUE); + return 2; + } + else if (structPtr->selectedIndexOffset != 0) + { + structPtr->selectedIndexOffset = 0; + return 1; + } + return 0; +} + +int MatchCall_PageDown(void) +{ + struct MatchCallWindowState *structPtr = GetMatchCallWindowStruct(); + + if (ShouldShowDownArrow()) + { + s32 windowBottomIndex = structPtr->windowTopIndex + structPtr->visibleEntries; + s32 scroll = structPtr->unk4 - structPtr->windowTopIndex; + + if (windowBottomIndex <= structPtr->unk4) + scroll = structPtr->visibleEntries; + MatchCall_MoveWindow(scroll, TRUE); + return 2; + } + else + { + s32 cursor, lastVisibleIndex; + if (structPtr->listLength >= structPtr->visibleEntries) + { + cursor = structPtr->selectedIndexOffset; + lastVisibleIndex = structPtr->visibleEntries; + } + else + { + cursor = structPtr->selectedIndexOffset; + lastVisibleIndex = structPtr->listLength; + } + lastVisibleIndex -= 1; + if (cursor >= lastVisibleIndex) + return 0; + + structPtr->selectedIndexOffset = lastVisibleIndex; + return 1; + } +} + +u32 GetSelectedMatchCall(void) +{ + struct MatchCallWindowState *structPtr = GetMatchCallWindowStruct(); + + return structPtr->windowTopIndex + structPtr->selectedIndexOffset; +} + +u32 GetMatchCallListTopIndex(void) +{ + struct MatchCallWindowState *structPtr = GetMatchCallWindowStruct(); + + return structPtr->windowTopIndex; +} + +void sub_81C877C(void) +{ + struct PokenavSub17 *structPtr = GetSubstructPtr(17); + structPtr->unk89C = 0; + structPtr->unk8A0 = CreateLoopedTask(LoopedTask_sub_81C8870, 6); +} + +void sub_81C87AC(s16 a0) +{ + struct PokenavSub17 *structPtr = GetSubstructPtr(17); + structPtr->unk888.windowTopIndex += a0; + structPtr->unk89C = 0; + structPtr->unk8A0 = CreateLoopedTask(LoopedTask_sub_81C8958, 6); +} + +void sub_81C87F0(void) +{ + struct PokenavSub17 *structPtr = GetSubstructPtr(17); + structPtr->unk89C = 0; + structPtr->unk8A0 = CreateLoopedTask(LoopedTask_sub_81C8A28, 6); +} + +bool32 sub_81C8820(void) +{ + struct PokenavSub17 *structPtr = GetSubstructPtr(17); + return IsLoopedTaskActive(structPtr->unk8A0); +} + +void sub_81C8838(void) +{ + struct PokenavSub17 *structPtr = GetSubstructPtr(17); + struct MatchCallWindowState *subPtr = &structPtr->unk888; + structPtr->unk0.unk38(structPtr->unk0.unk0.windowId, subPtr->windowTopIndex + subPtr->selectedIndexOffset, (structPtr->unk0.unk0.unkA + subPtr->selectedIndexOffset) & 0xF); + CopyWindowToVram(structPtr->unk0.unk0.windowId, 1); +} + +u32 LoopedTask_sub_81C8870(s32 state) +{ + struct PokenavSub17 *structPtr = GetSubstructPtr(17); + + switch (state) + { + case 0: + ToggleMatchCallArrows(&structPtr->unk0, 1); + // fall-through + case 1: + if (structPtr->unk89C != structPtr->unk888.selectedIndexOffset) + sub_81C8B70(&structPtr->unk0.unk0, structPtr->unk89C, 1); + + structPtr->unk89C++; + return LT_INC_AND_PAUSE; + case 2: + if (!IsDma3ManagerBusyWithBgCopy()) + { + if (structPtr->unk89C != structPtr->unk888.visibleEntries) + return 6; + if (structPtr->unk888.selectedIndexOffset != 0) + sub_81C8B70(&structPtr->unk0.unk0, structPtr->unk89C, structPtr->unk888.selectedIndexOffset); + + return LT_INC_AND_PAUSE; + } + return LT_PAUSE; + case 3: + if (!IsDma3ManagerBusyWithBgCopy()) + { + if (structPtr->unk888.selectedIndexOffset != 0) + { + MatchCall_MoveWindow(structPtr->unk888.selectedIndexOffset, FALSE); + return LT_INC_AND_PAUSE; + } + return LT_FINISH; + } + return LT_PAUSE; + case 4: + if (sub_81C8630()) + return LT_PAUSE; + + structPtr->unk888.selectedIndexOffset = 0; + return LT_FINISH; + } + return LT_FINISH; +} + +u32 LoopedTask_sub_81C8958(s32 state) +{ + struct PokenavSub17 *structPtr = GetSubstructPtr(17); + if (IsDma3ManagerBusyWithBgCopy()) + return LT_PAUSE; + + switch (state) + { + case 0: + sub_81C8CB4(&structPtr->unk888, &structPtr->unk0); + break; + case 1: + PrintMatchCallFieldNames(&structPtr->unk0, 0); + break; + case 2: + sub_81C8E54(&structPtr->unk888, &structPtr->unk0, 0); + break; + case 3: + PrintMatchCallFieldNames(&structPtr->unk0, 1); + break; + case 4: + sub_81C8E54(&structPtr->unk888, &structPtr->unk0, 1); + break; + case 5: + PrintMatchCallFieldNames(&structPtr->unk0, 2); + break; + case 6: + sub_81C8E54(&structPtr->unk888, &structPtr->unk0, 2); + break; + case 7: + sub_81C8E54(&structPtr->unk888, &structPtr->unk0, 3); + break; + default: + return LT_FINISH; + } + return LT_INC_AND_PAUSE; +} + +u32 LoopedTask_sub_81C8A28(s32 state) +{ + struct PokenavSub17 *structPtr; + struct MatchCallWindowState *subPtr888; + struct PokenavSub17Substruct *subPtr0; + s32 r5, *ptr; + + if (IsDma3ManagerBusyWithBgCopy()) + return LT_PAUSE; + + structPtr = GetSubstructPtr(17); + subPtr888 = &structPtr->unk888; + subPtr0 = &structPtr->unk0; + + switch (state) + { + case 0: + sub_81C8D4C(subPtr888, subPtr0); + return LT_INC_AND_PAUSE; + case 1: + ptr = &structPtr->unk89C; + if (++(*ptr) < structPtr->unk888.visibleEntries) + { + sub_81C8B70(&subPtr0->unk0, *ptr, 1); + return LT_PAUSE; + } + + *ptr = 0; + if (subPtr888->listLength <= subPtr888->visibleEntries) + { + if (subPtr888->windowTopIndex != 0) + { + s32 r4 = subPtr888->windowTopIndex; + r5 = -r4; + sub_81C8B70(&subPtr0->unk0, r5, r4); + subPtr888->selectedIndexOffset = r4; + *ptr = r5; + return LT_INC_AND_PAUSE; + } + } + else + { + if (subPtr888->windowTopIndex + subPtr888->visibleEntries > subPtr888->listLength) + { + s32 r4 = subPtr888->windowTopIndex + subPtr888->visibleEntries - subPtr888->listLength; + r5 = -r4; + sub_81C8B70(&subPtr0->unk0, r5, r4); + subPtr888->selectedIndexOffset = r4; + *ptr = r5; + return LT_INC_AND_PAUSE; + } + } + return 9; + case 2: + MatchCall_MoveWindow(structPtr->unk89C, FALSE); + return LT_INC_AND_PAUSE; + case 3: + if (!sub_81C8630()) + { + structPtr->unk89C = 0; + return 1; + } + return 2; + case 4: + sub_81C83AC(subPtr888->unk10, subPtr888->windowTopIndex + structPtr->unk89C, 1, subPtr888->unkC, structPtr->unk89C, &structPtr->unk0); + return LT_INC_AND_PAUSE; + case 5: + if (sub_81C83E0()) + return LT_PAUSE; + if (++structPtr->unk89C >= subPtr888->listLength || structPtr->unk89C >= subPtr888->visibleEntries) + return LT_INC_AND_CONTINUE; + return 9; + case 6: + ToggleMatchCallArrows(subPtr0, 0); + return LT_FINISH; + } + + return LT_FINISH; +} + +void sub_81C8B70(struct UnknownSubSubStruct_0203CF40 *a0, s32 a1, s32 a2) +{ + u8 *v1 = (u8*)GetWindowAttribute(a0->windowId, WINDOW_TILE_DATA); + u32 v2 = a0->unk4 * 64; + + a1 = (a0->unkA + a1) & 0xF; + if (a1 + a2 <= 16) + { + CpuFastFill8(PIXEL_FILL(1), v1 + a1 * v2, a2 * v2); + CopyWindowToVram(a0->windowId, 2); + } + else + { + u32 v3 = 16 - a1; + u32 v4 = a2 - v3; + + CpuFastFill8(PIXEL_FILL(1), v1 + a1 * v2, v3 * v2); + CpuFastFill8(PIXEL_FILL(1), v1, v4 * v2); + CopyWindowToVram(a0->windowId, 2); + } + + for (a2--; a2 != -1; a1 = (a1 + 1) & 0xF, a2--) + sub_81CBD48(a0->windowId, a1); + + CopyWindowToVram(a0->windowId, 1); +} + +void sub_81C8C64(struct UnknownSubSubStruct_0203CF40 *a0, u32 a1) +{ + u16 var; + u16 *v1 = (u16*)GetBgTilemapBuffer(GetWindowAttribute(a0->windowId, WINDOW_BG)); + v1 += ((a0->unkA << 6) + a0->unk2) - 1; + + if (a1 != 0) + var = (a0->unk1 << 12) | (a0->unk6 + 1); + else + var = (a0->unk1 << 12) | (a0->unk6); + + v1[0] = var; + v1[0x20] = var; +} + +void sub_81C8CB4(struct MatchCallWindowState *a0, struct PokenavSub17Substruct *a1) +{ + u8 colors[3] = {0, 2, 5}; + + a1->unk34(a0->unk10 + a0->unkC * a0->windowTopIndex, a1->unkTextBuffer); + a1->unk38(a1->unk0.windowId, a0->windowTopIndex, a1->unk0.unkA); + FillWindowPixelRect(a1->unk0.windowId, PIXEL_FILL(4), 0, a1->unk0.unkA * 16, a1->unk0.unk4 * 8, 16); + AddTextPrinterParameterized3(a1->unk0.windowId, a1->unk0.fontId, 8, (a1->unk0.unkA * 16) + 1, colors, TEXT_SPEED_FF, a1->unkTextBuffer); + sub_81C8C64(&a1->unk0, 1); + CopyWindowRectToVram(a1->unk0.windowId, 3, 0, a1->unk0.unkA * 2, a1->unk0.unk4, 2); +} + +void sub_81C8D4C(struct MatchCallWindowState *a0, struct PokenavSub17Substruct *a1) +{ + a1->unk34(a0->unk10 + a0->unkC * a0->windowTopIndex, a1->unkTextBuffer); + FillWindowPixelRect(a1->unk0.windowId, PIXEL_FILL(1), 0, a1->unk0.unkA * 16, a1->unk0.unk4 * 8, 16); + AddTextPrinterParameterized(a1->unk0.windowId, a1->unk0.fontId, a1->unkTextBuffer, 8, a1->unk0.unkA * 16 + 1, TEXT_SPEED_FF, NULL); + sub_81C8C64(&a1->unk0, 0); + CopyWindowToVram(a1->unk0.windowId, 3); +} + +void PrintMatchCallFieldNames(struct PokenavSub17Substruct *a0, u32 fieldId) +{ + const u8 *fieldNames[] = {gText_PokenavMatchCall_Strategy, gText_PokenavMatchCall_TrainerPokemon, gText_PokenavMatchCall_SelfIntroduction}; + u8 colors[3] = {1, 4, 5}; + u32 top = (a0->unk0.unkA + 1 + (fieldId * 2)) & 0xF; + + FillWindowPixelRect(a0->unk0.windowId, PIXEL_FILL(1), 0, top << 4, a0->unk0.unk4, 16); + AddTextPrinterParameterized3(a0->unk0.windowId, 7, 2, (top << 4) + 1, colors, -1, fieldNames[fieldId]); + CopyWindowRectToVram(a0->unk0.windowId, 2, 0, top << 1, a0->unk0.unk4, 2); +} + +void sub_81C8E54(struct MatchCallWindowState *a0, struct PokenavSub17Substruct *a1, u32 a2) +{ + static const u8 array[] = {2, 4, 6, 7}; + u32 r6 = (a1->unk0.unkA + array[a2]) & 0xF; + const u8 *str = sub_81CAFD8(a0->windowTopIndex, a2); + + if (str != NULL) + { + sub_81DB620(a1->unk0.windowId, 1, r6 * 2, a1->unk0.unk4 - 1, 2); + AddTextPrinterParameterized(a1->unk0.windowId, 7, str, 2, (r6 << 4) + 1, TEXT_SPEED_FF, NULL); + CopyWindowRectToVram(a1->unk0.windowId, 2, 0, r6 * 2, a1->unk0.unk4, 2); + } +} static const struct CompressedSpriteSheet sMatchcallArrowSpriteSheets[] = { @@ -186,835 +817,38 @@ static const struct SpriteTemplate sMatchCallUpDownArrowSprite = .callback = SpriteCallbackDummy }; -EWRAM_DATA u32 gUnknown_0203CF44 = 0; - -bool32 sub_81C81D4(const struct BgTemplate *arg0, struct MatchCallListTemplate *arg1, s32 arg2) -{ - u32 v1; - struct UnknownSubStruct_81C81D4 *structPtr; - - structPtr = AllocSubstruct(0x11, sizeof(struct UnknownSubStruct_81C81D4)); - - if (structPtr == NULL) - return FALSE; - - sub_81C9160(&structPtr->unk888, arg1); - - v1 = sub_81C91AC(&structPtr->unk0, arg0, arg1, arg2); - if (v1 == 0) - return FALSE; - - CreateLoopedTask(LoopedTask_sub_81C8254, 6); - return TRUE; -} - -bool32 sub_81C8224(void) -{ - return FuncIsActiveLoopedTask(LoopedTask_sub_81C8254); -} - -void sub_81C8234(void) -{ - struct UnknownSubStruct_81C81D4 *structPtr; - - structPtr = GetSubstructPtr(0x11); - sub_81C8FE0(&structPtr->unk0); - RemoveWindow(structPtr->unk0.unk0.windowId); - FreePokenavSubstruct(0x11); -} - -u32 LoopedTask_sub_81C8254(s32 a0) -{ - struct UnknownSubStruct_81C81D4 *structPtr; - - if (IsDma3ManagerBusyWithBgCopy()) - return 2; - - structPtr = GetSubstructPtr(0x11); - - switch (a0) - { - case 0: - sub_81C82E4(structPtr); - return 0; - case 1: - sub_81C835C(&structPtr->unk0.unk0); - return 0; - case 2: - sub_81C837C(&structPtr->unk888, &structPtr->unk0); - return 0; - case 3: - if (sub_81C83E0()) - { - return 2; - } - else - { - sub_81C8ED0(); - return 1; - } - case 4: - sub_81C8EF8(&structPtr->unk888, &structPtr->unk0); - return 4; - default: - return 4; - } -} - -void sub_81C82E4(struct UnknownSubStruct_81C81D4 *a0) -{ - u16 v1 = (a0->unk0.unk0.unk1 << 12) | a0->unk0.unk0.unk6; - sub_8199DF0(a0->unk0.unk0.bg, PIXEL_FILL(1), a0->unk0.unk0.unk6, 1); - sub_8199DF0(a0->unk0.unk0.bg, PIXEL_FILL(4), a0->unk0.unk0.unk6 + 1, 1); - SetBgTilemapBuffer(a0->unk0.unk0.bg, a0->tilemapBuffer); - FillBgTilemapBufferRect_Palette0(a0->unk0.unk0.bg, v1, 0, 0, 32, 32); - ChangeBgY(a0->unk0.unk0.bg, 0, 0); - ChangeBgX(a0->unk0.unk0.bg, 0, 0); - ChangeBgY(a0->unk0.unk0.bg, a0->unk0.unk0.unk3 << 11, 2); - CopyBgTilemapBufferToVram(a0->unk0.unk0.bg); -} - -void sub_81C835C(struct UnknownSubSubStruct_0203CF40 *a0) -{ - FillWindowPixelBuffer(a0->windowId, PIXEL_FILL(1)); - PutWindowTilemap(a0->windowId); - CopyWindowToVram(a0->windowId, 1); -} - -void sub_81C837C(struct MatchCallWindowState *a0, struct UnknownInnerStruct_81C81D4 *a1) -{ - s32 v1; - s32 v2; - - // TODO: Clean this up. - v1 = a0->listLength - a0->windowTopIndex; - v2 = a0->visibleEntries; - if (v1 > a0->visibleEntries) - v1 = v2; - sub_81C83AC(a0->unk10, a0->windowTopIndex, v1, a0->unkC, 0, a1); -} - -void sub_81C83AC(u32 a0, u32 a1, u32 a2, u32 a3, u32 a4, struct UnknownInnerStruct_81C81D4 *a5) -{ - if (a2 == 0) - return; - - a5->unk1C = a0 + a1 * a3; - a5->unk18 = a3; - a5->unk0.unkC = 0; - a5->unk0.unkE = a2; - a5->unk14 = a1; - a5->unk10 = a4; - CreateLoopedTask(LoopedTask_sub_81C83F0, 5); -} - -bool32 sub_81C83E0(void) -{ - return FuncIsActiveLoopedTask(LoopedTask_sub_81C83F0); -} - -u32 LoopedTask_sub_81C83F0(s32 a0) -{ - struct UnknownInnerStruct_81C81D4 *structPtr; - u32 v1; - - structPtr = &((struct UnknownSubStruct_81C81D4*)GetSubstructPtr(0x11))->unk0; - switch (a0) - { - case 0: - v1 = (structPtr->unk0.unkA + structPtr->unk0.unkC + structPtr->unk10) & 0xF; - structPtr->unk34(structPtr->unk1C, structPtr->unkTextBuffer); - if (structPtr->unk38 != NULL) - // Accessing unk0.windowId as if it were a u16...? - // It's accessed as a u8 again in the very next line... - structPtr->unk38(*(u16*)(&structPtr->unk0.windowId), structPtr->unk14, v1); - - AddTextPrinterParameterized(structPtr->unk0.windowId, structPtr->unk0.fontId, structPtr->unkTextBuffer, 8, (v1 << 4) + 1, 255, NULL); - - if (++structPtr->unk0.unkC >= structPtr->unk0.unkE) - { - if (structPtr->unk38 != NULL) - CopyWindowToVram(structPtr->unk0.windowId, 3); - else - CopyWindowToVram(structPtr->unk0.windowId, 2); - return 0; - } - else - { - structPtr->unk1C += structPtr->unk18; - structPtr->unk14++; - return 3; - } - case 1: - if (IsDma3ManagerBusyWithBgCopy()) - return 2; - else - return 4; - default: - return 4; - } -} - -bool32 ShouldShowUpArrow(void) -{ - u16 v1; - s32 v2; - struct UnknownSubStruct_81C81D4 *structPtr; - structPtr = GetSubstructPtr(0x11); - - return structPtr->unk888.windowTopIndex != 0; -} - -bool32 ShouldShowDownArrow(void) -{ - struct MatchCallWindowState *subPtr; - struct UnknownSubStruct_81C81D4 *structPtr; - structPtr = GetSubstructPtr(0x11); - subPtr = &structPtr->unk888; - - return subPtr->windowTopIndex + subPtr->visibleEntries < subPtr->listLength; -} - -void MatchCall_MoveWindow(s32 a0, bool32 a1_) -{ - register bool32 a1 asm("r4")= a1_; - s32 v1; - struct UnknownSubStruct_81C81D4 *structPtr = GetSubstructPtr(0x11); - register struct MatchCallWindowState *subPtr asm("r5") = &structPtr->unk888; - - if (a0 < 0) - { - u16 temp = subPtr->windowTopIndex; - if (temp + a0 < 0) - v1 = -1 * temp; - else - v1 = a0; - if (a1) - sub_81C83AC(subPtr->unk10, temp + v1, v1 * -1, subPtr->unkC, v1, &structPtr->unk0); - } - else if (a1) - { - s32 temp = gUnknown_0203CF44 = subPtr->windowTopIndex + subPtr->visibleEntries; - s32 listLength; - if (temp + a0 >= (listLength = subPtr->listLength)) - v1 = listLength - temp; - else - v1 = a0; - - sub_81C83AC(subPtr->unk10, gUnknown_0203CF44, v1, subPtr->unkC, subPtr->visibleEntries, &structPtr->unk0); - // Needed to prevent GCC from combining the two sub_81C83AC calls. - asm(""); - } - else - { - v1 = a0; - } - - sub_81C8568(v1, &structPtr->unk0); - subPtr->windowTopIndex += v1; -} - -void sub_81C8568(s32 a0, struct UnknownInnerStruct_81C81D4 *a1) -{ - a1->unk20 = GetBgY(a1->unk0.bg); - a1->unk24 = a1->unk20 + (a0 << 12); - if (a0 > 0) - a1->unk30 = 1; - else - a1->unk30 = 2; - a1->unk2C = a0; - a1->unk28 = CreateLoopedTask(LoopedTask_sub_81C85A0, 6); -} - -u32 LoopedTask_sub_81C85A0(s32 a0) -{ - s32 y; - s32 v1; - bool32 flag; - struct UnknownInnerStruct_81C81D4 *structPtr; - structPtr = &((struct UnknownSubStruct_81C81D4 *)GetSubstructPtr(0x11))->unk0; - - 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 IsLoopedTaskActive(structPtr->unk0.unk28); -} - -struct MatchCallWindowState *GetMatchCallWindowStruct(void) -{ - struct UnknownSubStruct_81C81D4 *structPtr; - structPtr = GetSubstructPtr(0x11); - return &structPtr->unk888; -} - -int MatchCall_MoveCursorUp(void) -{ - struct MatchCallWindowState *structPtr; - structPtr = GetMatchCallWindowStruct(); - - if (structPtr->selectedIndexOffset != 0) - { - structPtr->selectedIndexOffset--; - return 1; - } - else - { - if (ShouldShowUpArrow()) - { - MatchCall_MoveWindow(-1, TRUE); - return 2; - } - else - { - return 0; - } - } -} - -int MatchCall_MoveCursorDown(void) -{ - struct MatchCallWindowState *structPtr; - structPtr = GetMatchCallWindowStruct(); - - if (structPtr->windowTopIndex + structPtr->selectedIndexOffset < structPtr->listLength - 1) - { - if (structPtr->selectedIndexOffset < structPtr->visibleEntries - 1) - { - structPtr->selectedIndexOffset++; - return 1; - } - else if (!ShouldShowDownArrow()) - { - return 0; - } - } - else - { - return 0; - } - MatchCall_MoveWindow(1, TRUE); - return 2; -} - -int MatchCall_PageUp(void) -{ - struct MatchCallWindowState *structPtr; - s32 scroll; - - structPtr = GetMatchCallWindowStruct(); - if (ShouldShowUpArrow()) - { - if (structPtr->windowTopIndex >= structPtr->visibleEntries) - scroll = structPtr->visibleEntries; - else - scroll = structPtr->windowTopIndex; - MatchCall_MoveWindow(scroll * -1, TRUE); - return 2; - } - else if (structPtr->selectedIndexOffset != 0) - { - structPtr->selectedIndexOffset = 0; - return 1; - } - else - { - return 0; - } -} - -int MatchCall_PageDown(void) -{ - struct MatchCallWindowState *structPtr; - structPtr = GetMatchCallWindowStruct(); - - if (ShouldShowDownArrow()) - { - s32 scroll; - s32 windowBottomIndex; - s32 v3; - windowBottomIndex = structPtr->windowTopIndex + structPtr->visibleEntries; - scroll = structPtr->unk4 - structPtr->windowTopIndex; - if (windowBottomIndex <= structPtr->unk4) - scroll = structPtr->visibleEntries; - MatchCall_MoveWindow(scroll, TRUE); - return 2; - } - else - { - s32 cursor; - s32 lastVisibleIndex; - if (structPtr->listLength >= structPtr->visibleEntries) - { - cursor = structPtr->selectedIndexOffset; - lastVisibleIndex = structPtr->visibleEntries; - } - else - { - cursor = structPtr->selectedIndexOffset; - lastVisibleIndex = structPtr->listLength; - } - lastVisibleIndex -= 1; - if (cursor >= lastVisibleIndex) - { - return 0; - } - else - { - structPtr->selectedIndexOffset = lastVisibleIndex; - return 1; - } - } -} - -u32 GetSelectedMatchCall(void) -{ - struct MatchCallWindowState *structPtr; - structPtr = GetMatchCallWindowStruct(); - - return structPtr->windowTopIndex + structPtr->selectedIndexOffset; -} - -u32 GetMatchCallListTopIndex(void) -{ - struct MatchCallWindowState *structPtr; - structPtr = GetMatchCallWindowStruct(); - - return structPtr->windowTopIndex; -} - -void sub_81C877C(void) -{ - struct UnknownSubStruct_81C81D4 *structPtr; - structPtr = GetSubstructPtr(0x11); - structPtr->unk89C = 0; - structPtr->unk8A0 = CreateLoopedTask(LoopedTask_sub_81C8870, 6); -} - -void sub_81C87AC(s16 a0) -{ - u16 temp; - struct UnknownSubStruct_81C81D4 *structPtr; - structPtr = GetSubstructPtr(0x11); - temp = structPtr->unk888.windowTopIndex; - temp += a0; - structPtr->unk888.windowTopIndex = temp; - structPtr->unk89C = 0; - structPtr->unk8A0 = CreateLoopedTask(LoopedTask_sub_81C8958, 6); -} - -void sub_81C87F0(void) -{ - struct UnknownSubStruct_81C81D4 *structPtr; - structPtr = GetSubstructPtr(0x11); - structPtr->unk89C = 0; - structPtr->unk8A0 = CreateLoopedTask(LoopedTask_sub_81C8A28, 6); -} - -bool32 sub_81C8820(void) -{ - struct UnknownSubStruct_81C81D4 *structPtr; - structPtr = GetSubstructPtr(0x11); - return IsLoopedTaskActive(structPtr->unk8A0); -} - -void sub_81C8838(void) -{ - struct UnknownSubStruct_81C81D4 *structPtr; - struct MatchCallWindowState *subStr; - structPtr = GetSubstructPtr(0x11); - subStr = &structPtr->unk888; - structPtr->unk0.unk38(structPtr->unk0.unk0.windowId, subStr->windowTopIndex + subStr->selectedIndexOffset, (structPtr->unk0.unk0.unkA + subStr->selectedIndexOffset) & 0xF); - CopyWindowToVram(structPtr->unk0.unk0.windowId, 1); -} - -u32 LoopedTask_sub_81C8870(s32 a0) -{ - struct UnknownSubStruct_81C81D4 *structPtr; - u16 v1; - u32 v2; - - // Needed to fix a register renaming issue. - register u16* temp asm("r1"); - structPtr = GetSubstructPtr(0x11); - - switch (a0) - { - case 0: - ToggleMatchCallArrows(&structPtr->unk0, 1); - // fall-through - case 1: - if (structPtr->unk89C != structPtr->unk888.selectedIndexOffset) - sub_81C8B70(&structPtr->unk0.unk0, structPtr->unk89C, 1); - - structPtr->unk89C++; - return 0; - case 2: - if (IsDma3ManagerBusyWithBgCopy()) - return 2; - - if (structPtr->unk89C != structPtr->unk888.visibleEntries) - return 6; - - if (structPtr->unk888.selectedIndexOffset != 0) - sub_81C8B70(&structPtr->unk0.unk0, structPtr->unk89C, structPtr->unk888.selectedIndexOffset); - - return 0; - case 3: - if (IsDma3ManagerBusyWithBgCopy()) - return 2; - temp = &structPtr->unk888.selectedIndexOffset; - v1 = *temp; - if (v1 == 0) - return 4; - - MatchCall_MoveWindow(v1, FALSE); - return 0; - case 4: - v2 = sub_81C8630(); - if (v2) - return 2; - - structPtr->unk888.selectedIndexOffset = v2; - return 4; - default: - return 4; - } -} - -u32 LoopedTask_sub_81C8958(s32 a0) -{ - struct UnknownSubStruct_81C81D4 *structPtr; - structPtr = GetSubstructPtr(0x11); - if (IsDma3ManagerBusyWithBgCopy()) - return 2; - - switch (a0) - { - case 0: - sub_81C8CB4(&structPtr->unk888, &structPtr->unk0); - break; - case 1: - PrintMatchCallFieldNames(&structPtr->unk0, 0); - break; - case 2: - sub_81C8E54(&structPtr->unk888, &structPtr->unk0, 0); - break; - case 3: - PrintMatchCallFieldNames(&structPtr->unk0, 1); - break; - case 4: - sub_81C8E54(&structPtr->unk888, &structPtr->unk0, 1); - break; - case 5: - PrintMatchCallFieldNames(&structPtr->unk0, 2); - break; - case 6: - sub_81C8E54(&structPtr->unk888, &structPtr->unk0, 2); - break; - case 7: - sub_81C8E54(&structPtr->unk888, &structPtr->unk0, 3); - break; - default: - return 4; - } - return 0; -} - -u32 LoopedTask_sub_81C8A28(s32 a0) -{ - struct UnknownSubStruct_81C81D4 *structPtr; - struct MatchCallWindowState *subPtr888; - register struct UnknownInnerStruct_81C81D4 *subPtr0 asm("r2"); - s32 v4; - - if (IsDma3ManagerBusyWithBgCopy()) - { - return 2; - } - - structPtr = GetSubstructPtr(0x11); - subPtr888 = &structPtr->unk888; - subPtr0 = &structPtr->unk0; - - switch (a0) - { - default: - return 4; - case 0: - sub_81C8D4C(subPtr888, subPtr0); - return 0; - case 1: - { - s32 v1; - s32 v2; - u32 *v3; - register s32 v4 asm("r5"); - - v3 = &structPtr->unk89C; - v1 = *v3 + 1; - *v3 = v1; - if (v1 < structPtr->unk888.visibleEntries) - { - sub_81C8B70(&subPtr0->unk0, v1, 1); - return 2; - } - - *v3 = 0; - if (subPtr888->listLength <= subPtr888->visibleEntries) - { - register u32 temp asm("r0"); - temp = subPtr888->windowTopIndex; - if (temp == 0) - return 9; - v2 = temp; - } - else - { - register s32 temp asm("r1"); - v2 = subPtr888->windowTopIndex + subPtr888->visibleEntries; - temp = (s32)subPtr888->listLength; - if (v2 <= temp) - return 9; - v2 -= temp; - } - v4 = v2 * -1; - sub_81C8B70(&subPtr0->unk0, v4, v2); - subPtr888->selectedIndexOffset = v2; - *v3 = v4; - return 0; - } - case 2: - MatchCall_MoveWindow(structPtr->unk89C, FALSE); - return 0; - case 3: - if (sub_81C8630()) - return 2; - - structPtr->unk89C = 0; - return 1; - case 4: - sub_81C83AC(subPtr888->unk10, subPtr888->windowTopIndex + structPtr->unk89C, 1, subPtr888->unkC, structPtr->unk89C, &structPtr->unk0); - return 0; - case 5: - if (sub_81C83E0()) - return 2; - - v4 = ++structPtr->unk89C; - if (v4 >= subPtr888->listLength || v4 >= subPtr888->visibleEntries) - return 1; - return 9; - case 6: - ToggleMatchCallArrows(subPtr0, 0); - return 4; - } -} - -void sub_81C8B70(struct UnknownSubSubStruct_0203CF40 *a0, u32 a1, u32 a2) -{ - u8 *v1; - u32 v2; - - v1 = (u8*)GetWindowAttribute(a0->windowId, WINDOW_TILE_DATA); - v2 = a0->unk4 * 64; - - a1 = (a0->unkA + a1) & 0xF; - if ((s32)(a1 + a2) <= 16) - { - CpuFastFill8(PIXEL_FILL(1), v1 + a1 * v2, a2 * v2); - CopyWindowToVram(a0->windowId, 2); - } - else - { - u32 v3; - u32 v4; - - v3 = 16 - a1; - v4 = a2 - v3; - - CpuFastFill8(PIXEL_FILL(1), v1 + a1 * v2, v3 * v2); - CpuFastFill8(PIXEL_FILL(1), v1, v4 * v2); - CopyWindowToVram(a0->windowId, 2); - } - - a2 -= 1; - for (a2; a2 != -1; a1 = (a1 + 1) & 0xF, a2--) - { - sub_81CBD48(a0->windowId, a1); - } - - CopyWindowToVram(a0->windowId, 1); -} - -void sub_81C8C64(struct UnknownSubSubStruct_0203CF40 *a0, u32 a1) -{ - u16 *v1; - register u32 v2 asm("r0"); - u32 v3; - - v1 = (u16*)GetBgTilemapBuffer(GetWindowAttribute(a0->windowId, WINDOW_BG)); - - v1 = &v1[(a0->unkA << 6) + a0->unk2 - 1]; - - if (a1 != 0) - { - v2 = a0->unk1 << 12; - v3 = a0->unk6 + 1; - } - else - { - v2 = a0->unk1 << 12; - v3 = a0->unk6; - } - { - register u16 v5 asm("r1"); - register u32 v6 asm("r0"); - v6 = (v3 | v2); - v6 = v6 << 16; - v5 = v6 >> 16; - v1[0] = v5; - v1[0x20] = v5; - } -} - -void sub_81C8CB4(struct MatchCallWindowState *a0, struct UnknownInnerStruct_81C81D4 *a1) -{ - u8 colors[3]; - - - memcpy(colors, sPokenavColors_0861FBE4, ARRAY_COUNT(sPokenavColors_0861FBE4)); - - a1->unk34(a0->unk10 + a0->unkC * a0->windowTopIndex, a1->unkTextBuffer); - a1->unk38(a1->unk0.windowId, a0->windowTopIndex, a1->unk0.unkA); - FillWindowPixelRect(a1->unk0.windowId, PIXEL_FILL(4), 0, a1->unk0.unkA * 16, a1->unk0.unk4 * 8, 16); - AddTextPrinterParameterized3(a1->unk0.windowId, a1->unk0.fontId, 8, (a1->unk0.unkA * 16) + 1, colors, TEXT_SPEED_FF, a1->unkTextBuffer); - sub_81C8C64(&a1->unk0, 1); - CopyWindowRectToVram(a1->unk0.windowId, 3, 0, a1->unk0.unkA * 2, a1->unk0.unk4, 2); -} - -void sub_81C8D4C(struct MatchCallWindowState *a0, struct UnknownInnerStruct_81C81D4 *a1) -{ - a1->unk34(a0->unk10 + a0->unkC * a0->windowTopIndex, a1->unkTextBuffer); - FillWindowPixelRect(a1->unk0.windowId, PIXEL_FILL(1), 0, a1->unk0.unkA * 16, a1->unk0.unk4 * 8, 16); - AddTextPrinterParameterized(a1->unk0.windowId, a1->unk0.fontId, a1->unkTextBuffer, 8, a1->unk0.unkA * 16 + 1, TEXT_SPEED_FF, NULL); - sub_81C8C64(&a1->unk0, 0); - CopyWindowToVram(a1->unk0.windowId, 3); -} - -void PrintMatchCallFieldNames(struct UnknownInnerStruct_81C81D4 *a0, u32 fieldId) -{ - const u8 *fieldNames[3]; - u8 colors[3]; - u32 r4; - u32 r5; - u32 tmp; - u32 one; - - memcpy(fieldNames, sMatchCallFieldNames, sizeof(sMatchCallFieldNames)); - memcpy(colors, sMatchCallFieldColors, sizeof(sMatchCallFieldColors)); - - r4 = a0->unk0.unkA; - tmp = fieldId * 2 + 1; - r4 += tmp; - r4 &= 0xF; - FillWindowPixelRect(a0->unk0.windowId, PIXEL_FILL(1), 0, r4 << 4, a0->unk0.unk4, 16); - - // This is a fake match. It should be this: - // AddTextPrinterParameterized3(a0->unk0.windowId, 7, 2, r4 << 4 + 1, colors, TEXT_SPEED_FF, fieldNames[fieldId]); - // But the original GCC does some clever reuse of the `1` constant that the current GCC doesn't. - one = 1; - AddTextPrinterParameterized3(a0->unk0.windowId, 7, 2, (r4 << 4) + one, colors, one - 2, fieldNames[fieldId]); - CopyWindowRectToVram(a0->unk0.windowId, 2, 0, r4 << 1, a0->unk0.unk4, 2); -} - -void sub_81C8E54(struct MatchCallWindowState *a0, struct UnknownInnerStruct_81C81D4 *a1, u32 a2) -{ - const u8 *str; - u32 r6; - - r6 = (a1->unk0.unkA + sUnknown_0861FBF7[a2]) & 0xF; - - str = sub_81CAFD8(a0->windowTopIndex, a2); - if (str != NULL) { - sub_81DB620(a1->unk0.windowId, 1, r6 * 2, a1->unk0.unk4 - 1, 2); - AddTextPrinterParameterized(a1->unk0.windowId, 7, str, 2, (r6 << 4) + 1, TEXT_SPEED_FF, NULL); - CopyWindowRectToVram(a1->unk0.windowId, 2, 0, r6 * 2, a1->unk0.unk4, 2); - } -} - void sub_81C8ED0(void) { u32 i; const struct CompressedSpriteSheet *ptr; - + for (i = 0, ptr = sMatchcallArrowSpriteSheets; i < ARRAY_COUNT(sMatchcallArrowSpriteSheets); ptr++, i++) - { LoadCompressedSpriteSheet(ptr); - } + Pokenav_AllocAndLoadPalettes(sMatchcallArrowPalettes); } -void sub_81C8EF8(struct MatchCallWindowState *a0, struct UnknownInnerStruct_81C81D4 *a1) +void sub_81C8EF8(struct MatchCallWindowState *a0, struct PokenavSub17Substruct *a1) { - register u32 spriteId asm("r3"); - s16 temp; + u32 spriteId; + s16 x; - spriteId = (u8)CreateSprite(&sMatchCallRightArrowSprite, a1->unk0.unk2 * 8 + 3, (a1->unk0.unk3 + 1) * 8, 7); + spriteId = CreateSprite(&sMatchCallRightArrowSprite, a1->unk0.unk2 * 8 + 3, (a1->unk0.unk3 + 1) * 8, 7); a1->rightArrow = &gSprites[spriteId]; - temp = a1->unk0.unk2 * 8 + (a1->unk0.unk4 - 1) * 4; - spriteId = (u8)CreateSprite(&sMatchCallUpDownArrowSprite, temp, a1->unk0.unk3 * 8 + a0->visibleEntries * 16, 7); + x = a1->unk0.unk2 * 8 + (a1->unk0.unk4 - 1) * 4; + spriteId = CreateSprite(&sMatchCallUpDownArrowSprite, x, a1->unk0.unk3 * 8 + a0->visibleEntries * 16, 7); a1->downArrow = &gSprites[spriteId]; a1->downArrow->oam.tileNum += 2; a1->downArrow->callback = SpriteCB_MatchCallDownArrow; - spriteId = (u8)CreateSprite(&sMatchCallUpDownArrowSprite, temp, a1->unk0.unk3 * 8, 7); + spriteId = CreateSprite(&sMatchCallUpDownArrowSprite, x, a1->unk0.unk3 * 8, 7); a1->upArrow = &gSprites[spriteId]; a1->upArrow->oam.tileNum += 4; a1->upArrow->callback = SpriteCB_MatchCallUpArrow; } -void sub_81C8FE0(struct UnknownInnerStruct_81C81D4 *a0) +void sub_81C8FE0(struct PokenavSub17Substruct *a0) { DestroySprite(a0->rightArrow); DestroySprite(a0->upArrow); @@ -1023,7 +857,7 @@ void sub_81C8FE0(struct UnknownInnerStruct_81C81D4 *a0) FreeSpritePaletteByTag(0x14); } -void ToggleMatchCallArrows(struct UnknownInnerStruct_81C81D4 *a0, bool32 shouldHide) +void ToggleMatchCallArrows(struct PokenavSub17Substruct *a0, bool32 shouldHide) { if (shouldHide) { @@ -1044,8 +878,7 @@ void ToggleMatchCallArrows(struct UnknownInnerStruct_81C81D4 *a0, bool32 shouldH void SpriteCB_MatchCallRightArrow(struct Sprite *sprite) { - struct UnknownSubStruct_81C81D4 *structPtr; - structPtr = GetSubstructPtr(0x11); + struct PokenavSub17 *structPtr = GetSubstructPtr(17); sprite->pos2.y = structPtr->unk888.selectedIndexOffset << 4; } @@ -1055,7 +888,7 @@ void SpriteCB_MatchCallDownArrow(struct Sprite *sprite) sprite->invisible = FALSE; else sprite->invisible = TRUE; - + if (++sprite->data[0] > 3) { s16 offset; @@ -1073,7 +906,7 @@ void SpriteCB_MatchCallUpArrow(struct Sprite *sprite) sprite->invisible = FALSE; else sprite->invisible = TRUE; - + if (++sprite->data[0] > 3) { s16 offset; @@ -1087,36 +920,31 @@ void SpriteCB_MatchCallUpArrow(struct Sprite *sprite) void ToggleMatchCallVerticalArrows(bool32 shouldHide) { - struct UnknownSubStruct_81C81D4 *structPtr; - structPtr = GetSubstructPtr(0x11); + struct PokenavSub17 *structPtr = GetSubstructPtr(17); structPtr->unk0.upArrow->data[7] = shouldHide; structPtr->unk0.downArrow->data[7] = shouldHide; } void sub_81C9160(struct MatchCallWindowState *a0, struct MatchCallListTemplate *a1) { - u32 unused1 = a0->unk10 = a1->unk0; - u32 v0 = a1->unk6; - u32 zero = 0; - u32 unused2 = a0->windowTopIndex = v0; - u32 v1 = a0->listLength = a1->unk4; - + a0->unk10 = a1->unk0; + a0->windowTopIndex = a1->unk6; + a0->listLength = a1->unk4; a0->unkC = a1->unk8; a0->visibleEntries = a1->unkC; - if (a0->visibleEntries >= (u16)v1) + if (a0->visibleEntries >= a0->listLength) { a0->windowTopIndex = 0; a0->unk4 = 0; - a0->selectedIndexOffset = v0; + a0->selectedIndexOffset = a1->unk6; } else { - s32 v2; a0->unk4 = a0->listLength - a0->visibleEntries; - v2 = a0->windowTopIndex + a0->visibleEntries; - if (v2 > a0->listLength) { - a0->selectedIndexOffset = v2 - a0->listLength; - a0->windowTopIndex = v0 - a0->selectedIndexOffset; + if (a0->windowTopIndex + a0->visibleEntries > a0->listLength) + { + a0->selectedIndexOffset = a0->windowTopIndex + a0->visibleEntries - a0->listLength; + a0->windowTopIndex = a1->unk6 - a0->selectedIndexOffset; } else { @@ -1125,15 +953,11 @@ void sub_81C9160(struct MatchCallWindowState *a0, struct MatchCallListTemplate * } } -u32 sub_81C91AC(struct UnknownInnerStruct_81C81D4 *a0, const struct BgTemplate *a1, struct MatchCallListTemplate *a2, s32 a3) +bool32 sub_81C91AC(struct PokenavSub17Substruct *a0, const struct BgTemplate *a1, struct MatchCallListTemplate *a2, s32 a3) { - register u32 raw_bg asm("r4") = ((a1->bg) << 30); - u8 bg = raw_bg >> 30; - u32 unknown = 0; struct WindowTemplate window; - u8 bg_again; - a0->unk0.bg = bg; + a0->unk0.bg = a1->bg; a0->unk0.unk6 = a3; a0->unk34 = a2->unk10; a0->unk38 = a2->unk14; @@ -1142,8 +966,8 @@ u32 sub_81C91AC(struct UnknownInnerStruct_81C81D4 *a0, const struct BgTemplate * a0->unk0.unk3 = a2->unkB; a0->unk0.unk4 = a2->unkA; a0->unk0.fontId = a2->unkE; - - window.bg = raw_bg >> 30; + + window.bg = a1->bg; window.tilemapLeft = a2->unk9; window.tilemapTop = 0; window.width = a2->unkA; @@ -1153,15 +977,11 @@ u32 sub_81C91AC(struct UnknownInnerStruct_81C81D4 *a0, const struct BgTemplate * a0->unk0.windowId = AddWindow(&window); if (a0->unk0.windowId == 0xFF) - { - return 0; - } - else - { - a0->unk0.unkA = unknown; - a0->rightArrow = NULL; - a0->upArrow = NULL; - a0->downArrow = NULL; - return 1; - } + return FALSE; + + a0->unk0.unkA = 0; + a0->rightArrow = NULL; + a0->upArrow = NULL; + a0->downArrow = NULL; + return 1; } diff --git a/src/pokenav_unk_9.c b/src/pokenav_unk_9.c index 2927d72111..7feee3c1db 100644 --- a/src/pokenav_unk_9.c +++ b/src/pokenav_unk_9.c @@ -3,17 +3,32 @@ #include "bg.h" #include "window.h" +struct PokenavSub9 +{ + u32 (*unk0)(struct PokenavSub9*); + u32 loopedTaskId; + u8 filler[0xC]; + u32 unk14; + u32 unk18; + struct PokenavSub18 *unk1C; +}; + +u32 sub_81CFA68(struct PokenavSub9 *structPtr); +u32 sub_81CFA88(struct PokenavSub9 *structPtr); +u32 sub_81CFB08(struct PokenavSub9 *structPtr); +u32 sub_81CFB10(struct PokenavSub9 *structPtr); u32 sub_81CFB8C(void); u32 sub_81CFC2C(void); u32 sub_81CFC40(void); -u32 sub_81CFFFC(s32); -u32 sub_81D0074(s32); -u32 sub_81D00EC(s32); -u32 sub_81D0164(s32); -u32 sub_81D01DC(s32); -u32 sub_81D021C(s32); +u32 sub_81CFB74(s32 state); +u32 sub_81CFFFC(s32 state); +u32 sub_81D0074(s32 state); +u32 sub_81D00EC(s32 state); +u32 sub_81D0164(s32 state); +u32 sub_81D01DC(s32 state); +u32 sub_81D021C(s32 state); -u32 (*const gUnknown_086235D8[])(void) = +u32 (*const gUnknown_086235D8[])(void) = { sub_81CFB8C, sub_81CFC2C, @@ -25,7 +40,7 @@ const u32 gUnknown_08623604[] = INCBIN_U32("graphics/pokenav/ui_ribbons.4bpp.lz" const u32 gUnknown_086236CC[] = INCBIN_U32("graphics/pokenav/ui_ribbons.bin.lz"); const u16 gUnknown_08623790[] = INCBIN_U16("graphics/pokenav/8623790.gbapal"); -const struct BgTemplate gUnknown_086237B0 = +const struct BgTemplate gUnknown_086237B0 = { .bg = 1, .charBaseIndex = 1, @@ -36,7 +51,7 @@ const struct BgTemplate gUnknown_086237B0 = .baseTile = 0 }; -const struct BgTemplate gUnknown_086237B4 = +const struct BgTemplate gUnknown_086237B4 = { .bg = 2, .charBaseIndex = 2, @@ -47,7 +62,7 @@ const struct BgTemplate gUnknown_086237B4 = .baseTile = 0 }; -const LoopedTask gUnknown_086237B8[] = +const LoopedTask gUnknown_086237B8[] = { NULL, sub_81CFFFC, @@ -58,7 +73,7 @@ const LoopedTask gUnknown_086237B8[] = sub_81D021C }; -const struct WindowTemplate gUnknown_086237D4 = +const struct WindowTemplate gUnknown_086237D4 = { .bg = 1, .tilemapLeft = 1, @@ -72,3 +87,94 @@ const struct WindowTemplate gUnknown_086237D4 = const u8 gUnknown_086237DC[] = _("{COLOR_HIGHLIGHT_SHADOW}{LIGHT_RED}{WHITE}{GREEN}♂{COLOR_HIGHLIGHT_SHADOW}{DARK_GREY}{WHITE}{LIGHT_GREY}"); const u8 gUnknown_086237E8[] = _("{COLOR_HIGHLIGHT_SHADOW}{LIGHT_GREEN}{WHITE}{BLUE}♀{COLOR_HIGHLIGHT_SHADOW}{DARK_GREY}{WHITE}{LIGHT_GREY}"); const u8 gUnknown_086237F4[] = _("{UNK_SPACER}"); + +bool32 sub_81CF9BC(void) +{ + struct PokenavSub9 *structPtr = AllocSubstruct(9, sizeof(struct PokenavSub9)); + if (structPtr == NULL) + return FALSE; + + structPtr->unk1C = AllocSubstruct(18, sizeof(struct PokenavSub18)); + if (structPtr->unk1C == NULL) + return FALSE; + + structPtr->unk0 = sub_81CFA68; + structPtr->loopedTaskId = CreateLoopedTask(sub_81CFB74, 1); + structPtr->unk14 = 0; + return TRUE; +} + +bool32 sub_81CFA04(void) +{ + struct PokenavSub9 *structPtr = AllocSubstruct(9, sizeof(struct PokenavSub9)); + if (structPtr == NULL) + return FALSE; + + structPtr->unk1C = GetSubstructPtr(18); + structPtr->unk0 = sub_81CFA88; + structPtr->unk14 = 1; + return TRUE; +} + +u32 sub_81CFA34(void) +{ + struct PokenavSub9 *structPtr = GetSubstructPtr(9); + return structPtr->unk0(structPtr); +} + +void sub_81CFA48(void) +{ + struct PokenavSub9 *structPtr = GetSubstructPtr(9); + if (!structPtr->unk18) + FreePokenavSubstruct(18); + FreePokenavSubstruct(9); +} + +u32 sub_81CFA68(struct PokenavSub9 *structPtr) +{ + if (!IsLoopedTaskActive(structPtr->loopedTaskId)) + structPtr->unk0 = sub_81CFA88; + return 0; +} + +u32 sub_81CFA88(struct PokenavSub9 *structPtr) +{ + if (gMain.newAndRepeatedKeys & DPAD_UP) + return 1; + if (gMain.newAndRepeatedKeys & DPAD_DOWN) + return 2; + if (gMain.newKeys & DPAD_LEFT) + return 3; + if (gMain.newKeys & DPAD_RIGHT) + return 4; + if (gMain.newKeys & B_BUTTON) + { + structPtr->unk18 = 0; + structPtr->unk0 = sub_81CFB08; + return 5; + } + if (gMain.newKeys & A_BUTTON) + { + structPtr->unk1C->unk2 = GetSelectedMatchCall(); + structPtr->unk18 = 1; + structPtr->unk0 = sub_81CFB10; + return 6; + } + return 0; +} + +u32 sub_81CFB08(struct PokenavSub9 *structPtr) +{ + return 0x186a5; +} + +u32 sub_81CFB10(struct PokenavSub9 *structPtr) +{ + return 0x186ad; +} + +u32 sub_81CFB18(void) +{ + struct PokenavSub9 *structPtr = GetSubstructPtr(9); + return structPtr->unk14; +}