From 18a92fdcc05c9bf46c4ff11006043cccf5eefcff Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sat, 3 Mar 2018 14:58:41 +0100 Subject: [PATCH] list menu is decompiled --- asm/list_menu.s | 563 -------------------------------------- common_syms/list_menu.txt | 2 + include/list_menu.h | 36 ++- ld_script.txt | 1 - src/daycare.c | 19 +- src/decoration.c | 4 +- src/item_menu.c | 4 +- src/list_menu.c | 300 ++++++++++++++++---- src/pokeblock.c | 16 +- src/secret_base.c | 6 +- sym_common.txt | 6 +- 11 files changed, 303 insertions(+), 654 deletions(-) delete mode 100644 asm/list_menu.s create mode 100644 common_syms/list_menu.txt diff --git a/asm/list_menu.s b/asm/list_menu.s deleted file mode 100644 index 4eeb29fd4..000000000 --- a/asm/list_menu.s +++ /dev/null @@ -1,563 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .syntax unified - - .text - - - thumb_func_start ListMenuErasePrintedCursor -ListMenuErasePrintedCursor: @ 81AEC78 - push {r4-r7,lr} - mov r7, r8 - push {r7} - sub sp, 0x8 - adds r7, r0, 0 - lsls r1, 16 - lsrs r1, 16 - mov r8, r1 - ldrb r1, [r7, 0x17] - lsrs r0, r1, 6 - cmp r0, 0 - bne _081AECF4 - lsls r0, r1, 26 - lsrs r0, 26 - movs r1, 0x1 - bl GetFontAttribute - adds r4, r0, 0 - ldrb r0, [r7, 0x16] - lsls r0, 26 - lsrs r0, 29 - adds r4, r0 - lsls r4, 24 - lsrs r4, 24 - ldrb r0, [r7, 0x17] - lsls r0, 26 - lsrs r0, 26 - movs r1, 0 - bl GetMenuCursorDimensionByFont - adds r5, r0, 0 - lsls r5, 24 - lsrs r5, 24 - ldrb r0, [r7, 0x17] - lsls r0, 26 - lsrs r0, 26 - movs r1, 0x1 - bl GetMenuCursorDimensionByFont - lsls r0, 24 - lsrs r0, 24 - ldrb r6, [r7, 0x10] - ldrb r2, [r7, 0x15] - lsls r2, 28 - lsrs r1, r2, 4 - orrs r1, r2 - lsrs r1, 24 - ldrb r2, [r7, 0x13] - mov r3, r8 - muls r3, r4 - adds r4, r3, 0 - ldrb r3, [r7, 0x14] - lsls r3, 28 - lsrs r3, 28 - adds r3, r4 - lsls r3, 16 - lsrs r3, 16 - str r5, [sp] - str r0, [sp, 0x4] - adds r0, r6, 0 - bl FillWindowPixelRect -_081AECF4: - add sp, 0x8 - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end ListMenuErasePrintedCursor - - thumb_func_start ListMenuUpdateSelectedRowIndexAndScrollOffset -@ u8 ListMenuUpdateSelectedRowIndexAndScrollOffset(int, bool8 movingDown) -ListMenuUpdateSelectedRowIndexAndScrollOffset: @ 81AED00 - push {r4-r6,lr} - adds r4, r0, 0 - lsls r1, 24 - ldrh r3, [r4, 0x1A] - ldrh r5, [r4, 0x18] - cmp r1, 0 - bne _081AED74 - ldrh r0, [r4, 0xE] - cmp r0, 0x1 - bne _081AED18 - movs r2, 0 - b _081AED2A -_081AED18: - ldrh r0, [r4, 0xE] - lsrs r2, r0, 1 - movs r1, 0x1 - ands r1, r0 - adds r2, r1 - subs r0, r2 - subs r0, 0x1 - lsls r0, 16 - lsrs r2, r0, 16 -_081AED2A: - cmp r5, 0 - bne _081AED50 - cmp r3, 0 - beq _081AEDB6 - ldr r1, [r4] - movs r2, 0x3 - negs r2, r2 -_081AED38: - subs r0, r3, 0x1 - lsls r0, 16 - lsrs r3, r0, 16 - adds r0, r5, r3 - lsls r0, 3 - adds r0, r1 - ldr r0, [r0, 0x4] - cmp r0, r2 - bne _081AEDBA - cmp r3, 0 - bne _081AED38 - b _081AEDB6 -_081AED50: - cmp r3, r2 - bls _081AED70 - ldr r1, [r4] - movs r6, 0x3 - negs r6, r6 -_081AED5A: - subs r0, r3, 0x1 - lsls r0, 16 - lsrs r3, r0, 16 - adds r0, r5, r3 - lsls r0, 3 - adds r0, r1 - ldr r0, [r0, 0x4] - cmp r0, r6 - bne _081AEDBA - cmp r3, r2 - bhi _081AED5A -_081AED70: - subs r0, r5, 0x1 - b _081AEDE2 -_081AED74: - ldrh r0, [r4, 0xE] - cmp r0, 0x1 - bne _081AED7E - movs r2, 0 - b _081AED88 -_081AED7E: - ldrh r0, [r4, 0xE] - lsrs r2, r0, 1 - movs r1, 0x1 - ands r1, r0 - adds r2, r1 -_081AED88: - adds r1, r0, 0 - ldrh r0, [r4, 0xC] - subs r0, r1 - cmp r5, r0 - bne _081AEDC0 - subs r0, r1, 0x1 - cmp r3, r0 - bge _081AEDB6 - ldr r2, [r4] - movs r6, 0x3 - negs r6, r6 - adds r1, r0, 0 -_081AEDA0: - adds r0, r3, 0x1 - lsls r0, 16 - lsrs r3, r0, 16 - adds r0, r5, r3 - lsls r0, 3 - adds r0, r2 - ldr r0, [r0, 0x4] - cmp r0, r6 - bne _081AEDBA - cmp r3, r1 - blt _081AEDA0 -_081AEDB6: - movs r0, 0 - b _081AEDE8 -_081AEDBA: - strh r3, [r4, 0x1A] - movs r0, 0x1 - b _081AEDE8 -_081AEDC0: - cmp r3, r2 - bcs _081AEDE0 - ldr r1, [r4] - movs r6, 0x3 - negs r6, r6 -_081AEDCA: - adds r0, r3, 0x1 - lsls r0, 16 - lsrs r3, r0, 16 - adds r0, r5, r3 - lsls r0, 3 - adds r0, r1 - ldr r0, [r0, 0x4] - cmp r0, r6 - bne _081AEDBA - cmp r3, r2 - bcc _081AEDCA -_081AEDE0: - adds r0, r5, 0x1 -_081AEDE2: - strh r2, [r4, 0x1A] - strh r0, [r4, 0x18] - movs r0, 0x2 -_081AEDE8: - pop {r4-r6} - pop {r1} - bx r1 - thumb_func_end ListMenuUpdateSelectedRowIndexAndScrollOffset - - thumb_func_start ListMenuScroll -@ void ListMenuScroll(struct ListMenu *listMenu, int a2, bool8 movingDown) -ListMenuScroll: @ 81AEDF0 - push {r4-r7,lr} - mov r7, r8 - push {r7} - sub sp, 0x8 - adds r6, r0, 0 - lsls r1, 24 - lsrs r5, r1, 24 - adds r7, r5, 0 - lsls r2, 24 - lsrs r2, 24 - mov r8, r2 - ldrh r0, [r6, 0xE] - cmp r5, r0 - bcc _081AEE2A - ldrb r0, [r6, 0x10] - ldrb r2, [r6, 0x15] - lsls r2, 28 - lsrs r1, r2, 4 - orrs r1, r2 - lsrs r1, 24 - bl FillWindowPixelBuffer - ldrh r1, [r6, 0x18] - ldrh r3, [r6, 0xE] - adds r0, r6, 0 - movs r2, 0 - bl ListMenuPrintEntries - b _081AEF1A -_081AEE2A: - ldrb r0, [r6, 0x17] - lsls r0, 26 - lsrs r0, 26 - movs r1, 0x1 - bl GetFontAttribute - ldrb r1, [r6, 0x16] - lsls r1, 26 - lsrs r1, 29 - adds r0, r1 - lsls r0, 24 - lsrs r4, r0, 24 - mov r1, r8 - cmp r1, 0 - bne _081AEEBC - ldrb r0, [r6, 0x10] - adds r2, r5, 0 - muls r2, r4 - lsls r2, 24 - lsrs r2, 24 - ldrb r1, [r6, 0x15] - lsls r1, 28 - lsrs r3, r1, 4 - orrs r3, r1 - lsrs r3, 24 - movs r1, 0x1 - bl ScrollWindow - ldrh r1, [r6, 0x18] - adds r0, r6, 0 - movs r2, 0 - adds r3, r5, 0 - bl ListMenuPrintEntries - ldrh r0, [r6, 0xE] - adds r1, r0, 0 - muls r1, r4 - adds r0, r1, 0 - ldrb r4, [r6, 0x14] - lsls r4, 28 - lsrs r4, 28 - adds r4, r0 - lsls r4, 16 - lsrs r4, 16 - ldrb r0, [r6, 0x10] - movs r1, 0x3 - bl GetWindowAttribute - adds r5, r0, 0 - lsls r5, 19 - lsrs r5, 16 - ldrb r0, [r6, 0x10] - movs r1, 0x4 - bl GetWindowAttribute - lsls r0, 3 - subs r0, r4 - lsls r0, 16 - lsrs r0, 16 - ldrb r3, [r6, 0x10] - ldrb r2, [r6, 0x15] - lsls r2, 28 - lsrs r1, r2, 4 - orrs r1, r2 - lsrs r1, 24 - str r5, [sp] - str r0, [sp, 0x4] - adds r0, r3, 0 - movs r2, 0 - adds r3, r4, 0 - bl FillWindowPixelRect - b _081AEF1A -_081AEEBC: - ldrb r0, [r6, 0x10] - adds r2, r7, 0 - muls r2, r4 - lsls r2, 24 - lsrs r2, 24 - ldrb r1, [r6, 0x15] - lsls r1, 28 - lsrs r3, r1, 4 - orrs r3, r1 - lsrs r3, 24 - movs r1, 0 - bl ScrollWindow - ldrh r2, [r6, 0xE] - subs r2, r7 - ldrh r1, [r6, 0x18] - adds r1, r2 - lsls r1, 16 - lsrs r1, 16 - lsls r2, 16 - lsrs r2, 16 - adds r0, r6, 0 - adds r3, r7, 0 - bl ListMenuPrintEntries - ldrb r0, [r6, 0x10] - movs r1, 0x3 - bl GetWindowAttribute - lsls r0, 19 - lsrs r0, 16 - ldrb r3, [r6, 0x10] - ldrb r2, [r6, 0x15] - lsls r2, 28 - lsrs r1, r2, 4 - orrs r1, r2 - lsrs r1, 24 - str r0, [sp] - ldrb r0, [r6, 0x14] - lsls r0, 28 - lsrs r0, 28 - str r0, [sp, 0x4] - adds r0, r3, 0 - movs r2, 0 - movs r3, 0 - bl FillWindowPixelRect -_081AEF1A: - add sp, 0x8 - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end ListMenuScroll - - thumb_func_start ListMenuChangeSelection -@ bool8 ListMenuChangeSelection(struct ListMenu *listMenu, bool8 updateCursorAndCallCallback, u8 count, bool8 movingDown) -ListMenuChangeSelection: @ 81AEF28 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x4 - adds r4, r0, 0 - lsls r1, 24 - lsrs r1, 24 - str r1, [sp] - lsls r2, 24 - lsrs r2, 24 - mov r8, r2 - lsls r3, 24 - lsrs r3, 24 - mov r9, r3 - ldrh r0, [r4, 0x1A] - mov r10, r0 - movs r7, 0 - movs r5, 0 - movs r0, 0 - cmp r7, r8 - bcs _081AEF90 -_081AEF56: - adds r6, r0, 0x1 - b _081AEF76 -_081AEF5A: - adds r0, r7, 0x1 - lsls r0, 24 - lsrs r7, r0, 24 - ldrh r0, [r4, 0x18] - ldrh r1, [r4, 0x1A] - adds r0, r1 - ldr r1, [r4] - lsls r0, 3 - adds r0, r1 - ldr r1, [r0, 0x4] - movs r0, 0x3 - negs r0, r0 - cmp r1, r0 - bne _081AEF88 -_081AEF76: - adds r0, r4, 0 - mov r1, r9 - bl ListMenuUpdateSelectedRowIndexAndScrollOffset - lsls r0, 24 - lsrs r0, 24 - orrs r5, r0 - cmp r0, 0x2 - beq _081AEF5A -_081AEF88: - lsls r0, r6, 24 - lsrs r0, 24 - cmp r0, r8 - bcc _081AEF56 -_081AEF90: - ldr r0, [sp] - cmp r0, 0 - beq _081AEFEE - cmp r5, 0x1 - beq _081AEFA6 - cmp r5, 0x1 - ble _081AEFA2 - cmp r5, 0x3 - ble _081AEFC6 -_081AEFA2: - movs r0, 0x1 - b _081AEFF0 -_081AEFA6: - adds r0, r4, 0 - mov r1, r10 - bl ListMenuErasePrintedCursor - adds r0, r4, 0 - bl ListMenuDrawCursor - adds r0, r4, 0 - movs r1, 0 - bl ListMenuCallSelectionChangedCallback - ldrb r0, [r4, 0x10] - movs r1, 0x2 - bl CopyWindowToVram - b _081AEFEE -_081AEFC6: - adds r0, r4, 0 - mov r1, r10 - bl ListMenuErasePrintedCursor - adds r0, r4, 0 - adds r1, r7, 0 - mov r2, r9 - bl ListMenuScroll - adds r0, r4, 0 - bl ListMenuDrawCursor - adds r0, r4, 0 - movs r1, 0 - bl ListMenuCallSelectionChangedCallback - ldrb r0, [r4, 0x10] - movs r1, 0x2 - bl CopyWindowToVram -_081AEFEE: - movs r0, 0 -_081AEFF0: - add sp, 0x4 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end ListMenuChangeSelection - - thumb_func_start ListMenuCallSelectionChangedCallback -@ void ListMenuCallSelectionChangedCallback(struct ListMenu *listMenu, u8 a2) -ListMenuCallSelectionChangedCallback: @ 81AF000 - push {r4,lr} - adds r2, r0, 0 - lsls r1, 24 - lsrs r4, r1, 24 - ldr r3, [r2, 0x4] - cmp r3, 0 - beq _081AF022 - ldrh r0, [r2, 0x18] - ldrh r1, [r2, 0x1A] - adds r0, r1 - ldr r1, [r2] - lsls r0, 3 - adds r0, r1 - ldr r0, [r0, 0x4] - adds r1, r4, 0 - bl _call_via_r3 -_081AF022: - pop {r4} - pop {r0} - bx r0 - thumb_func_end ListMenuCallSelectionChangedCallback - - thumb_func_start sub_81AF028 -sub_81AF028: @ 81AF028 - push {r4-r7,lr} - mov r7, r8 - push {r7} - lsls r0, 24 - lsrs r0, 24 - lsls r1, 24 - lsls r2, 24 - lsrs r2, 24 - ldr r6, =gUnknown_03006300 - movs r5, 0xF - ands r0, r5 - ldrb r3, [r6] - mov r8, r3 - movs r4, 0x10 - negs r4, r4 - adds r3, r4, 0 - mov r7, r8 - ands r3, r7 - orrs r3, r0 - lsrs r1, 20 - ands r3, r5 - orrs r3, r1 - strb r3, [r6] - ands r2, r5 - ldrb r0, [r6, 0x1] - ands r4, r0 - orrs r4, r2 - strb r4, [r6, 0x1] - ldrb r0, [r6, 0x3] - movs r1, 0x80 - orrs r0, r1 - strb r0, [r6, 0x3] - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81AF028 - - thumb_func_start sub_81AF078 -sub_81AF078: @ 81AF078 - push {lr} - lsls r1, 24 - cmp r1, 0 - bne _081AF086 - movs r0, 0x5 - bl PlaySE -_081AF086: - pop {r0} - bx r0 - thumb_func_end sub_81AF078 - - .align 2, 0 @ Don't pad with nop. diff --git a/common_syms/list_menu.txt b/common_syms/list_menu.txt new file mode 100644 index 000000000..a346edeef --- /dev/null +++ b/common_syms/list_menu.txt @@ -0,0 +1,2 @@ +gUnknown_03006300 +gMultiuseListMenuTemplate diff --git a/include/list_menu.h b/include/list_menu.h index d25549845..0aa66a524 100644 --- a/include/list_menu.h +++ b/include/list_menu.h @@ -8,9 +8,7 @@ #define LIST_MULTIPLE_SCROLL_DPAD 1 #define LIST_MULTIPLE_SCROLL_L_R 2 -// Exported type declarations - -// Exported RAM declarations +struct ListMenu; struct ListMenuItem { @@ -18,22 +16,20 @@ struct ListMenuItem s32 id; }; -struct ListMenu; - struct ListMenuTemplate { const struct ListMenuItem *items; - void (* moveCursorFunc)(u32, bool8, struct ListMenu *); + void (* moveCursorFunc)(s32, bool8, struct ListMenu *); void (* unk_08)(u8 windowId, s32 itemId, u8 y); u16 totalItems; u16 maxShowed; u8 windowId; u8 unk_11; u8 unk_12; - u8 cursor_Y; + u8 cursor_X; u8 upText_Y:4; // x1, x2, x4, x8 = xF u8 cursorPal:4; // x10, x20, x40, x80 = xF0 - u8 fillPal:4; // x1, x2, x4, x8 = xF + u8 fillValue:4; // x1, x2, x4, x8 = xF u8 cursorShadowPal:4; // x10, x20, x40, x80 = xF0 u8 lettersSpacing:3; u8 unk_16_3:3; @@ -53,14 +49,30 @@ struct ListMenu u8 unk_1F; }; +struct UnknownListMenuWindowStruct +{ + u8 x; + u8 y; + u8 width; + u8 height; + u8 palNum; +}; + extern struct ListMenuTemplate gMultiuseListMenuTemplate; -// Exported ROM declarations - -u8 ListMenuInit(struct ListMenuTemplate *template, u16 scrollOffset, u16 selectedRow); +s32 DoMysteryGiftListMenu(struct WindowTemplate *windowTemplate, struct ListMenuTemplate *listMenuTemplate, u8 arg2, u16 tileNum, u16 palNum); +u8 ListMenuInit(struct ListMenuTemplate *listMenuTemplate, u16 scrollOffset, u16 selectedRow); +u8 ListMenuInitWithWindows(struct ListMenuTemplate *listMenuTemplate, struct UnknownListMenuWindowStruct *arg1, u16 scrollOffset, u16 selectedRow); s32 ListMenuHandleInputGetItemId(u8 listTaskId); -void ListMenuGetScrollAndRow(u8 listTaskId, u16 *scrollOffset, u16 *selectedRow); void DestroyListMenuTask(u8 listTaskId, u16 *scrollOffset, u16 *selectedRow); +void sub_81AE70C(u8 listTaskId); +void ChangeListMenuPals(u8 listTaskId, u8 cursorPal, u8 fillValue, u8 cursorShadowPal); +void ChangeListMenuCoords(u8 listTaskId, u8 x, u8 y); +s32 ListMenuTestInput(struct ListMenuTemplate *template, u32 scrollOffset, u32 selectedRow, u16 keys, u16 *newScrollOffset, u16 *newSelectedRow); +void ListMenuGetCurrentItemArrayId(u8 listTaskId, u16 *arrayId); +void ListMenuGetScrollAndRow(u8 listTaskId, u16 *scrollOffset, u16 *selectedRow); u16 ListMenuGetYCoordForPrintingArrowCursor(u8 listTaskId); +void sub_81AF028(u8 cursorPal, u8 fillValue, u8 cursorShadowPal); +void sub_81AF078(s32 arg0, u8 arg1, struct ListMenu *list); #endif //GUARD_LIST_MENU_H diff --git a/ld_script.txt b/ld_script.txt index 88306e790..8f104f391 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -248,7 +248,6 @@ SECTIONS { asm/battle_frontier_2.o(.text); src/item_menu.o(.text); src/list_menu.o(.text); - asm/list_menu.o(.text); asm/menu_indicators.o(.text); src/unk_text_util.o(.text); src/save_location.o(.text); diff --git a/src/daycare.c b/src/daycare.c index f4bd84af3..d567ff79a 100644 --- a/src/daycare.c +++ b/src/daycare.c @@ -45,7 +45,6 @@ extern void DestroyListMenuTask(u8, u16*, u16*); extern void sub_819746C(u8, bool8); extern void NewMenuHelpers_DrawStdWindowFrame(u8, bool8); extern void sub_81B9328(void); -extern void sub_81AF078(u32, bool8, struct ListMenu *); extern void CB2_ReturnToField(void); // this file's functions @@ -79,18 +78,18 @@ static const struct ListMenuTemplate sDaycareListMenuLevelTemplate = .unk_08 = DaycarePrintMonInfo, .totalItems = 3, .maxShowed = 3, - .unk_10 = 0, + .windowId = 0, .unk_11 = 0, .unk_12 = 8, - .cursor_Y = 0, + .cursor_X = 0, .upText_Y = 1, - .cursorColor = 2, - .fillColor = 1, - .cursorShadowColor = 3, - .unk_16_0 = TRUE, - .spaceBetweenItems = 0, + .cursorPal = 2, + .fillValue = 1, + .cursorShadowPal = 3, + .lettersSpacing = 1, + .unk_16_3 = 0, .scrollMultiple = LIST_NO_MULTIPLE_SCROLL, - .unk_17_0 = 1, + .fontId = 1, .cursorKind = 0 }; @@ -1299,7 +1298,7 @@ void ShowDaycareLevelMenu(void) NewMenuHelpers_DrawStdWindowFrame(windowId, FALSE); menuTemplate = sDaycareListMenuLevelTemplate; - menuTemplate.unk_10 = windowId; + menuTemplate.windowId = windowId; listMenuTaskId = ListMenuInit(&menuTemplate, 0, 0); CopyWindowToVram(windowId, 3); diff --git a/src/decoration.c b/src/decoration.c index 899851c6a..ffa1c3a68 100644 --- a/src/decoration.c +++ b/src/decoration.c @@ -113,7 +113,7 @@ void sub_812719C(u8 taskId); void sub_81271CC(u8 taskId); void sub_8127268(u8 taskId); void sub_8127454(u8 *dest, u16 decorId); -void sub_8127480(u32 a0, bool8 flag, struct ListMenu *menu); +void sub_8127480(s32 a0, bool8 flag, struct ListMenu *menu); void sub_81274A0(u8 a0, s32 a1, u8 a2); void sub_8127620(u8 taskId); void sub_812764C(u8 taskId); @@ -813,7 +813,7 @@ void sub_8127454(u8 *dest, u16 decorId) StringAppend(dest, gDecorations[decorId].name); } -void sub_8127480(u32 a0, bool8 flag, struct ListMenu *menu) +void sub_8127480(s32 a0, bool8 flag, struct ListMenu *menu) { if (flag != TRUE) { diff --git a/src/item_menu.c b/src/item_menu.c index a51894ea1..24dce79f6 100755 --- a/src/item_menu.c +++ b/src/item_menu.c @@ -128,7 +128,7 @@ void sub_81ABAC4(void); void sub_81ABAE0(void); u8 sub_81AB1F0(u8); void sub_81AC23C(u8); -void bag_menu_change_item_callback(u32 a, bool8 b, struct ListMenu*); +void bag_menu_change_item_callback(s32 a, bool8 b, struct ListMenu*); void sub_81AB520(u8 rboxId, int item_index_in_pocket, u8 a); void ItemMenu_UseOutOfBattle(u8 taskId); void ItemMenu_Toss(u8 taskId); @@ -688,7 +688,7 @@ void get_name(s8 *dest, u16 itemId) } } -void bag_menu_change_item_callback(u32 a, bool8 b, struct ListMenu *unused) +void bag_menu_change_item_callback(s32 a, bool8 b, struct ListMenu *unused) { if (b != 1) { diff --git a/src/list_menu.c b/src/list_menu.c index 91cc2532a..9b9921c8f 100644 --- a/src/list_menu.c +++ b/src/list_menu.c @@ -6,8 +6,11 @@ #include "main.h" #include "task.h" #include "menu_indicators.h" +#include "strings.h" +#include "sound.h" +#include "constants/songs.h" -struct ListMenuStruct +struct UnknownMysteryGiftLinkMenuStruct { s32 field_0; u8 field_4; @@ -15,27 +18,33 @@ struct ListMenuStruct u8 field_6; }; -struct UnknownListMenuStruct +struct UnknownListMenuPals { - u8 x; - u8 y; - u8 width; - u8 height; - u8 palNum; + u8 cursorPal:4; + u8 fillValue:4; + u8 cursorShadowPal:4; + u8 lettersSpacing:6; + u8 field_2_2:6; // unused + u8 fontId:7; + u8 field_3_7:1; }; -extern struct ListMenuStruct gUnknown_0203CE84; +extern struct UnknownMysteryGiftLinkMenuStruct gUnknown_0203CE84; // this file's functions -u8 ListMenuInitInternal(struct ListMenuTemplate *listMenuTemplate, u16 scrollOffset, u16 selectedRow); -bool8 ListMenuChangeSelection(struct ListMenu *list, bool8 updateCursorAndCallCallback, u8 count, bool8 movingDown); -void ListMenuPrintEntries(struct ListMenu *list, u16 startIndex, u16 yOffset, u16 count); -void ListMenuDrawCursor(struct ListMenu *list); -void ListMenuCallSelectionChangedCallback(struct ListMenu *list, u8 a2); -u8 ListMenuAddCursorObject(struct ListMenu *list, u32 cursorKind); +static u8 ListMenuInitInternal(struct ListMenuTemplate *listMenuTemplate, u16 scrollOffset, u16 selectedRow); +static bool8 ListMenuChangeSelection(struct ListMenu *list, bool8 updateCursorAndCallCallback, u8 count, bool8 movingDown); +static void ListMenuPrintEntries(struct ListMenu *list, u16 startIndex, u16 yOffset, u16 count); +static void ListMenuDrawCursor(struct ListMenu *list); +static void ListMenuCallSelectionChangedCallback(struct ListMenu *list, u8 a2); +static u8 ListMenuAddCursorObject(struct ListMenu *list, u32 cursorKind); + +// IWRAM common +struct UnknownListMenuPals gUnknown_03006300; +struct ListMenuTemplate gMultiuseListMenuTemplate; // code -void ListMenuDummyTask(u8 taskId) +static void ListMenuDummyTask(u8 taskId) { } @@ -111,7 +120,7 @@ u8 ListMenuInit(struct ListMenuTemplate *listMenuTemplate, u16 scrollOffset, u16 } // unused -u8 ListMenuInitWithWindows(struct ListMenuTemplate *listMenuTemplate, struct UnknownListMenuStruct *arg1, u16 scrollOffset, u16 selectedRow) +u8 ListMenuInitWithWindows(struct ListMenuTemplate *listMenuTemplate, struct UnknownListMenuWindowStruct *arg1, u16 scrollOffset, u16 selectedRow) { s32 i; @@ -208,19 +217,19 @@ void sub_81AE70C(u8 listTaskId) { struct ListMenu *list = (void*) gTasks[listTaskId].data; - FillWindowPixelBuffer(list->template.windowId, (list->template.fillPal << 4) | (list->template.fillPal)); + FillWindowPixelBuffer(list->template.windowId, (list->template.fillValue << 4) | (list->template.fillValue)); ListMenuPrintEntries(list, list->scrollOffset, 0, list->template.maxShowed); ListMenuDrawCursor(list); CopyWindowToVram(list->template.windowId, 2); } // unused -void ChangeListMenuPals(u8 listTaskId, u8 cursorPal, u8 fillPal, u8 cursorShadowPal) +void ChangeListMenuPals(u8 listTaskId, u8 cursorPal, u8 fillValue, u8 cursorShadowPal) { struct ListMenu *list = (void*) gTasks[listTaskId].data; list->template.cursorPal = cursorPal; - list->template.fillPal = fillPal; + list->template.fillValue = fillValue; list->template.cursorShadowPal = cursorShadowPal; } @@ -283,20 +292,7 @@ u16 ListMenuGetYCoordForPrintingArrowCursor(u8 listTaskId) return list->selectedRow * yMultiplier + list->template.upText_Y; } -struct ListMenuPals -{ - u8 field_0_0:4; - u8 field_0_4:4; - u8 field_1_0:4; - u8 lettersSpacing:6; - u8 field_2_2:6; - u8 fontId:7; - u8 field_3_7:1; -}; - -extern struct ListMenuPals gUnknown_03006300; - -u8 ListMenuInitInternal(struct ListMenuTemplate *listMenuTemplate, u16 scrollOffset, u16 selectedRow) +static u8 ListMenuInitInternal(struct ListMenuTemplate *listMenuTemplate, u16 scrollOffset, u16 selectedRow) { u8 listTaskId = CreateTask(ListMenuDummyTask, 0); struct ListMenu *list = (void*) gTasks[listTaskId].data; @@ -309,9 +305,9 @@ u8 ListMenuInitInternal(struct ListMenuTemplate *listMenuTemplate, u16 scrollOff list->unk_1E = 0xFF; list->unk_1F = 0; - gUnknown_03006300.field_0_0 = list->template.cursorPal; - gUnknown_03006300.field_0_4 = list->template.fillPal; - gUnknown_03006300.field_1_0 = list->template.cursorShadowPal; + gUnknown_03006300.cursorPal = list->template.cursorPal; + gUnknown_03006300.fillValue = list->template.fillValue; + gUnknown_03006300.cursorShadowPal = list->template.cursorShadowPal; gUnknown_03006300.lettersSpacing = list->template.lettersSpacing; gUnknown_03006300.fontId = list->template.fontId; gUnknown_03006300.field_3_7 = 0; @@ -319,7 +315,7 @@ u8 ListMenuInitInternal(struct ListMenuTemplate *listMenuTemplate, u16 scrollOff if (list->template.totalItems < list->template.maxShowed) list->template.maxShowed = list->template.totalItems; - FillWindowPixelBuffer(list->template.windowId, (list->template.fillPal << 4) | (list->template.fillPal)); + FillWindowPixelBuffer(list->template.windowId, (list->template.fillValue << 4) | (list->template.fillValue)); ListMenuPrintEntries(list, list->scrollOffset, 0, list->template.maxShowed); ListMenuDrawCursor(list); ListMenuCallSelectionChangedCallback(list, 1); @@ -327,14 +323,14 @@ u8 ListMenuInitInternal(struct ListMenuTemplate *listMenuTemplate, u16 scrollOff return listTaskId; } -void ListMenuPrint(struct ListMenu *list, const u8 *str, u8 x, u8 y) +static void ListMenuPrint(struct ListMenu *list, const u8 *str, u8 x, u8 y) { u8 colors[3]; if (gUnknown_03006300.field_3_7) { - colors[0] = gUnknown_03006300.field_0_4; - colors[1] = gUnknown_03006300.field_0_0; - colors[2] = gUnknown_03006300.field_1_0; + colors[0] = gUnknown_03006300.fillValue; + colors[1] = gUnknown_03006300.cursorPal; + colors[2] = gUnknown_03006300.cursorShadowPal; AddTextPrinterParameterized2(list->template.windowId, gUnknown_03006300.fontId, x, y, @@ -345,7 +341,7 @@ void ListMenuPrint(struct ListMenu *list, const u8 *str, u8 x, u8 y) } else { - colors[0] = list->template.fillPal; + colors[0] = list->template.fillValue; colors[1] = list->template.cursorPal; colors[2] = list->template.cursorShadowPal; AddTextPrinterParameterized2(list->template.windowId, @@ -356,7 +352,7 @@ void ListMenuPrint(struct ListMenu *list, const u8 *str, u8 x, u8 y) } } -void ListMenuPrintEntries(struct ListMenu *list, u16 startIndex, u16 yOffset, u16 count) +static void ListMenuPrintEntries(struct ListMenu *list, u16 startIndex, u16 yOffset, u16 count) { s32 i; u8 x, y; @@ -378,12 +374,10 @@ void ListMenuPrintEntries(struct ListMenu *list, u16 startIndex, u16 yOffset, u1 } } -extern const u8 gText_SelectorArrow2[]; - -void ListMenuDrawCursor(struct ListMenu *list) +static void ListMenuDrawCursor(struct ListMenu *list) { u8 yMultiplier = GetFontAttribute(list->template.fontId, 1) + list->template.unk_16_3; - u8 x = list->template.cursor_Y; + u8 x = list->template.cursor_X; u8 y = list->selectedRow * yMultiplier + list->template.upText_Y; switch (list->template.cursorKind) { @@ -409,7 +403,7 @@ void ListMenuDrawCursor(struct ListMenu *list) } } -u8 ListMenuAddCursorObject(struct ListMenu *list, u32 cursorKind) +static u8 ListMenuAddCursorObject(struct ListMenu *list, u32 cursorKind) { struct CursorStruct cursor; @@ -423,3 +417,213 @@ u8 ListMenuAddCursorObject(struct ListMenu *list, u32 cursorKind) return ListMenuAddCursorObjectInternal(&cursor, cursorKind); } + +static void ListMenuErasePrintedCursor(struct ListMenu *list, u16 selectedRow) +{ + u8 cursorKind = list->template.cursorKind; + if (cursorKind == 0) + { + u8 yMultiplier = GetFontAttribute(list->template.fontId, 1) + list->template.unk_16_3; + u8 width = GetMenuCursorDimensionByFont(list->template.fontId, 0); + u8 height = GetMenuCursorDimensionByFont(list->template.fontId, 1); + FillWindowPixelRect(list->template.windowId, + (list->template.fillValue << 4) | (list->template.fillValue), + list->template.cursor_X, + selectedRow * yMultiplier + list->template.upText_Y, + width, + height); + } +} + +static u8 ListMenuUpdateSelectedRowIndexAndScrollOffset(struct ListMenu *list, bool8 movingDown) +{ + u16 selectedRow = list->selectedRow; + u16 scrollOffset = list->scrollOffset; + u16 newRow; + u32 newScroll; + + if (!movingDown) + { + if (list->template.maxShowed == 1) + newRow = 0; + else + newRow = list->template.maxShowed - ((list->template.maxShowed / 2) + (list->template.maxShowed % 2)) - 1; + + if (scrollOffset == 0) + { + while (selectedRow != 0) + { + selectedRow--; + if (list->template.items[scrollOffset + selectedRow].id != -3) + { + list->selectedRow = selectedRow; + return 1; + } + } + + return 0; + } + else + { + while (selectedRow > newRow) + { + selectedRow--; + if (list->template.items[scrollOffset + selectedRow].id != -3) + { + list->selectedRow = selectedRow; + return 1; + } + } + + newScroll = scrollOffset - 1; + } + } + else + { + if (list->template.maxShowed == 1) + newRow = 0; + else + newRow = ((list->template.maxShowed / 2) + (list->template.maxShowed % 2)); + + if (scrollOffset == list->template.totalItems - list->template.maxShowed) + { + while (selectedRow < list->template.maxShowed - 1) + { + selectedRow++; + if (list->template.items[scrollOffset + selectedRow].id != -3) + { + list->selectedRow = selectedRow; + return 1; + } + } + + return 0; + } + else + { + while (selectedRow < newRow) + { + selectedRow++; + if (list->template.items[scrollOffset + selectedRow].id != -3) + { + list->selectedRow = selectedRow; + return 1; + } + } + + newScroll = scrollOffset + 1; + } + } + + list->selectedRow = newRow; + list->scrollOffset = newScroll; + return 2; +} + +static void ListMenuScroll(struct ListMenu *list, u8 count, bool8 movingDown) +{ + if (count >= list->template.maxShowed) + { + FillWindowPixelBuffer(list->template.windowId, (list->template.fillValue << 4) | (list->template.fillValue)); + ListMenuPrintEntries(list, list->scrollOffset, 0, list->template.maxShowed); + } + else + { + u8 yMultiplier = GetFontAttribute(list->template.fontId, 1) + list->template.unk_16_3; + + if (!movingDown) + { + u16 y, width, height; + + ScrollWindow(list->template.windowId, 1, count * yMultiplier, (list->template.fillValue << 4) | (list->template.fillValue)); + ListMenuPrintEntries(list, list->scrollOffset, 0, count); + + y = (list->template.maxShowed * yMultiplier) + list->template.upText_Y; + width = GetWindowAttribute(list->template.windowId, WINDOW_WIDTH) * 8; + height = (GetWindowAttribute(list->template.windowId, WINDOW_HEIGHT) * 8) - y; + FillWindowPixelRect(list->template.windowId, + (list->template.fillValue << 4) | (list->template.fillValue), + 0, y, width, height); + } + else + { + u16 width; + + ScrollWindow(list->template.windowId, 0, count * yMultiplier, (list->template.fillValue << 4) | (list->template.fillValue)); + ListMenuPrintEntries(list, list->scrollOffset + (list->template.maxShowed - count), list->template.maxShowed - count, count); + + width = GetWindowAttribute(list->template.windowId, WINDOW_WIDTH) * 8; + FillWindowPixelRect(list->template.windowId, + (list->template.fillValue << 4) | (list->template.fillValue), + 0, 0, width, list->template.upText_Y); + } + } +} + +static bool8 ListMenuChangeSelection(struct ListMenu *list, bool8 updateCursorAndCallCallback, u8 count, bool8 movingDown) +{ + u16 oldSelectedRow; + u8 selectionChange, i, cursorCount; + + oldSelectedRow = list->selectedRow; + cursorCount = 0; + selectionChange = 0; + for (i = 0; i < count; i++) + { + do + { + u8 ret = ListMenuUpdateSelectedRowIndexAndScrollOffset(list, movingDown); + selectionChange |= ret; + if (ret != 2) + break; + cursorCount++; + } while (list->template.items[list->scrollOffset + list->selectedRow].id == -3); + } + + if (updateCursorAndCallCallback) + { + switch (selectionChange) + { + case 0: + default: + return TRUE; + case 1: + ListMenuErasePrintedCursor(list, oldSelectedRow); + ListMenuDrawCursor(list); + ListMenuCallSelectionChangedCallback(list, 0); + CopyWindowToVram(list->template.windowId, 2); + break; + case 2: + case 3: + ListMenuErasePrintedCursor(list, oldSelectedRow); + ListMenuScroll(list, cursorCount, movingDown); + ListMenuDrawCursor(list); + ListMenuCallSelectionChangedCallback(list, 0); + CopyWindowToVram(list->template.windowId, 2); + break; + } + } + + return FALSE; +} + +static void ListMenuCallSelectionChangedCallback(struct ListMenu *list, u8 a2) +{ + if (list->template.moveCursorFunc != NULL) + list->template.moveCursorFunc(list->template.items[list->scrollOffset + list->selectedRow].id, a2, list); +} + +// unused +void sub_81AF028(u8 cursorPal, u8 fillValue, u8 cursorShadowPal) +{ + gUnknown_03006300.cursorPal = cursorPal; + gUnknown_03006300.fillValue = fillValue; + gUnknown_03006300.cursorShadowPal = cursorShadowPal; + gUnknown_03006300.field_3_7 = 1; +} + +void sub_81AF078(s32 arg0, u8 arg1, struct ListMenu *list) +{ + if (!arg1) + PlaySE(SE_SELECT); +} diff --git a/src/pokeblock.c b/src/pokeblock.c index 4c467017f..b244409c4 100644 --- a/src/pokeblock.c +++ b/src/pokeblock.c @@ -91,7 +91,7 @@ static void sub_81362E0(void); static void sub_8136344(void); static void HandlePokeblockListMenuItems(void); static void sub_81363BC(void); -static void MovePokeblockMenuCursor(u32 pkblId, bool8 arg1, struct ListMenu *arg2); +static void MovePokeblockMenuCursor(s32 pkblId, bool8 arg1, struct ListMenu *arg2); static void PutPokeblockInfoText(void); static void HandlePokeblockMenuCursor(u16 cursorPos, u16 arg1); static void PutPokeblockListMenuString(u8 *dst, u16 pkblId); @@ -322,15 +322,15 @@ static const struct ListMenuTemplate sPokeblockListMenuTemplate = .windowId = 1, .unk_11 = 0, .unk_12 = 1, - .cursor_Y = 0, + .cursor_X = 0, .upText_Y = 1, .cursorPal = 2, - .fillPal = 0, + .fillValue = 0, .cursorShadowPal = 3, - .unk_16_0 = FALSE, - .spaceBetweenItems = 32, + .lettersSpacing = 0, + .unk_16_3 = 0, .scrollMultiple = LIST_MULTIPLE_SCROLL_DPAD, - .unk_17_0 = 1, + .fontId = 1, .cursorKind = 1 }; @@ -620,7 +620,7 @@ static void HandlePokeblockListMenuItems(void) sPokeblockMenu->items[i].id = LIST_B_PRESSED; gMultiuseListMenuTemplate = sPokeblockListMenuTemplate; - gMultiuseListMenuTemplate.unk_17_0 = 7; + gMultiuseListMenuTemplate.fontId = 7; gMultiuseListMenuTemplate.totalItems = sPokeblockMenu->itemsNo; gMultiuseListMenuTemplate.items = sPokeblockMenu->items; gMultiuseListMenuTemplate.maxShowed = sPokeblockMenu->maxShowed; @@ -639,7 +639,7 @@ static void PutPokeblockListMenuString(u8 *dst, u16 pkblId) StringExpandPlaceholders(txtPtr, gText_LvVar1); } -static void MovePokeblockMenuCursor(u32 pkblId, bool8 arg1, struct ListMenu *arg2) +static void MovePokeblockMenuCursor(s32 pkblId, bool8 arg1, struct ListMenu *arg2) { if (arg1 != TRUE) { diff --git a/src/secret_base.c b/src/secret_base.c index 29bbc4245..c886912f4 100644 --- a/src/secret_base.c +++ b/src/secret_base.c @@ -6,8 +6,8 @@ #include "main.h" #include "task.h" #include "palette.h" -#include "list_menu.h" #include "window.h" +#include "list_menu.h" #include "menu.h" #include "menu_helpers.h" #include "menu_indicators.h" @@ -66,7 +66,7 @@ EWRAM_DATA struct SecretBaseListMenuBuffer *gUnknown_0203A020 = NULL; void sub_80E9C9C(u8 taskId); void game_continue(u8 taskId); -void sub_80E9DEC(u32 a0, bool8 flag, struct ListMenu *menu); +void sub_80E9DEC(s32 a0, bool8 flag, struct ListMenu *menu); void sub_80E9E00(u8 taskId); void sub_80E9E44(u8 taskId); void sub_80E9E90(u8 taskId); @@ -919,7 +919,7 @@ void game_continue(u8 taskId) gMultiuseListMenuTemplate.maxShowed = data[3]; } -void sub_80E9DEC(u32 a0, bool8 flag, struct ListMenu *menu) +void sub_80E9DEC(s32 a0, bool8 flag, struct ListMenu *menu) { if (flag != TRUE) { diff --git a/sym_common.txt b/sym_common.txt index ce3540ad9..01772fa5a 100644 --- a/sym_common.txt +++ b/sym_common.txt @@ -178,11 +178,7 @@ gUnknown_030062F0: @ 30062F0 gUnknown_030062F4: @ 30062F4 .space 0xC -gUnknown_03006300: @ 3006300 - .space 0x10 - -gMultiuseListMenuTemplate: @ 3006310 - .space 0x18 + .include "list_menu.o" gUnknown_03006328: @ 3006328 .space 0x48