diff --git a/asm/menu_helpers.s b/asm/menu_helpers.s deleted file mode 100644 index dd8e1401b..000000000 --- a/asm/menu_helpers.s +++ /dev/null @@ -1,230 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .syntax unified - - .text - - - - - thumb_func_start sub_8122344 -sub_8122344: @ 8122344 - push {r4-r7,lr} - mov r7, r8 - push {r7} - mov r8, r0 - lsls r1, 24 - lsrs r6, r1, 24 - movs r5, 0 - cmp r5, r6 - bcs _0812239C - ldr r7, =gSprites -_08122358: - lsls r1, r5, 4 - ldr r0, =gUnknown_0859F524 - movs r2, 0 - movs r3, 0 - bl CreateSprite - mov r1, r8 - adds r4, r1, r5 - strb r0, [r4] - cmp r5, 0 - beq _0812237E - ldrb r1, [r4] - lsls r0, r1, 4 - adds r0, r1 - lsls r0, 2 - adds r0, r7 - movs r1, 0x1 - bl StartSpriteAnim -_0812237E: - ldrb r1, [r4] - lsls r0, r1, 4 - adds r0, r1 - lsls r0, 2 - adds r0, r7 - adds r0, 0x3E - ldrb r1, [r0] - movs r2, 0x4 - orrs r1, r2 - strb r1, [r0] - adds r0, r5, 0x1 - lsls r0, 24 - lsrs r5, r0, 24 - cmp r5, r6 - bcc _08122358 -_0812239C: - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8122344 - - thumb_func_start sub_81223B0 -sub_81223B0: @ 81223B0 - push {r4-r7,lr} - adds r6, r0, 0 - lsls r1, 24 - lsrs r5, r1, 24 - movs r4, 0 - cmp r4, r5 - bcs _081223F6 - ldr r7, =gSprites -_081223C0: - subs r0, r5, 0x1 - cmp r4, r0 - bne _081223DC - adds r0, r6, r4 - ldrb r1, [r0] - lsls r0, r1, 4 - adds r0, r1 - lsls r0, 2 - adds r0, r7 - bl DestroySpriteAndFreeResources - b _081223EC - .pool -_081223DC: - adds r0, r6, r4 - ldrb r1, [r0] - lsls r0, r1, 4 - adds r0, r1 - lsls r0, 2 - adds r0, r7 - bl DestroySprite -_081223EC: - adds r0, r4, 0x1 - lsls r0, 24 - lsrs r4, r0, 24 - cmp r4, r5 - bcc _081223C0 -_081223F6: - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_81223B0 - - thumb_func_start sub_81223FC -sub_81223FC: @ 81223FC - push {r4-r7,lr} - adds r6, r0, 0 - lsls r1, 24 - lsrs r4, r1, 24 - lsls r2, 24 - lsrs r0, r2, 24 - movs r3, 0 - cmp r3, r4 - bcs _0812243E - ldr r1, =gSprites - mov r12, r1 - movs r1, 0x1 - ands r0, r1 - lsls r5, r0, 2 - movs r7, 0x5 - negs r7, r7 -_0812241C: - adds r0, r6, r3 - ldrb r0, [r0] - lsls r1, r0, 4 - adds r1, r0 - lsls r1, 2 - add r1, r12 - adds r1, 0x3E - ldrb r2, [r1] - adds r0, r7, 0 - ands r0, r2 - orrs r0, r5 - strb r0, [r1] - adds r0, r3, 0x1 - lsls r0, 24 - lsrs r3, r0, 24 - cmp r3, r4 - bcc _0812241C -_0812243E: - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81223FC - - thumb_func_start sub_8122448 -@ void sub_8122448(int a1, u8 a2, u16 x, u16 y) -sub_8122448: @ 8122448 - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - adds r6, r0, 0 - lsls r1, 24 - lsrs r4, r1, 24 - lsls r2, 16 - lsrs r7, r2, 16 - lsls r3, 16 - lsrs r3, 16 - mov r9, r3 - movs r0, 0x80 - ands r0, r4 - lsls r0, 24 - lsrs r0, 24 - mov r8, r0 - movs r0, 0x7F - ands r4, r0 - movs r3, 0 - cmp r3, r4 - bcs _081224C8 - ldr r5, =gSprites - lsls r0, r7, 16 - asrs r0, 16 - subs r0, 0x8 - mov r12, r0 -_0812247E: - subs r0, r4, 0x1 - cmp r3, r0 - bne _081224A0 - mov r0, r8 - cmp r0, 0 - beq _081224A0 - adds r2, r6, r3 - ldrb r1, [r2] - lsls r0, r1, 4 - adds r0, r1 - lsls r0, 2 - adds r0, r5 - mov r1, r12 - strh r1, [r0, 0x24] - b _081224AE - .pool -_081224A0: - adds r2, r6, r3 - ldrb r1, [r2] - lsls r0, r1, 4 - adds r0, r1 - lsls r0, 2 - adds r0, r5 - strh r7, [r0, 0x24] -_081224AE: - ldrb r1, [r2] - lsls r0, r1, 4 - adds r0, r1 - lsls r0, 2 - adds r0, r5 - mov r1, r9 - adds r1, 0x1 - strh r1, [r0, 0x22] - adds r0, r3, 0x1 - lsls r0, 24 - lsrs r3, r0, 24 - cmp r3, r4 - bcc _0812247E -_081224C8: - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_8122448 - - .align 2, 0 @ Don't pad with nop. diff --git a/data/menu_helpers.s b/data/menu_helpers.s deleted file mode 100644 index 25ca66485..000000000 --- a/data/menu_helpers.s +++ /dev/null @@ -1,37 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .section .rodata - .align 2, 0 - -gUnknown_0859F4E8:: @ 859F4E8 - .2byte 0x00 - .2byte 0x4000 - .2byte 0x00 - .2byte 0x00 - -gUnknown_0859F4F0:: @ 859F4F0 - obj_image_anim_frame 0x00, 0x00 - obj_image_anim_end - -gUnknown_0859F4F8:: @ 859F4F8 - obj_image_anim_frame 0x04, 0x00 - obj_image_anim_end - -gUnknown_0859F500:: @ 859F500 - obj_image_anim_frame 0x00, 0x40 - obj_image_anim_end - -gUnknown_0859F508:: @ 859F508 - .4byte gUnknown_0859F4F0 - .4byte gUnknown_0859F4F8 - .4byte gUnknown_0859F500 - -gUnknown_0859F514:: @ 859F514 - .4byte gBagSwapLineGfx, 0x6D0100 - -gUnknown_0859F51C:: @ 859F51C - .4byte gBagSwapLinePal, 0x6D - -gUnknown_0859F524:: @ 859F524 - spr_template 0x6D, 0x6D, gUnknown_0859F4E8, gUnknown_0859F508, NULL, gDummySpriteAffineAnimTable, SpriteCallbackDummy diff --git a/include/menu_helpers.h b/include/menu_helpers.h index 4de6603a3..387a89fdd 100644 --- a/include/menu_helpers.h +++ b/include/menu_helpers.h @@ -14,29 +14,27 @@ struct YesNoFuncTable // Exported RAM declarations // Exported ROM declarations -void sub_812220C(struct ItemSlot *, u8, u8 *, u8 *, u8); -void sub_812225C(u16 *, u16 *, u8, u8); -void sub_8122298(u16 *, u16 *, u8, u8, u8); -void sub_8121F68(u8 taskId, const struct YesNoFuncTable *data); -bool8 sub_81221AC(void); -bool8 sub_81221EC(void); void ResetVramOamAndBgCntRegs(void); -void SetVBlankHBlankCallbacksToNull(void); void ResetAllBgsCoordinates(void); +void SetVBlankHBlankCallbacksToNull(void); +void DisplayMessageAndContinueTask(u8 taskId, u8 windowId, u16 arg2, u8 arg3, u8 fontId, u8 textSpeed, const u8 *string, void *taskFunc); bool16 RunTextPrintersRetIsActive(u8 textPrinterId); -void sub_8122344(u8 *arg0, u8 arg1); -void sub_81223B0(u8 *arg0, u8 arg1); -void LoadListMenuArrowsGfx(void); -void sub_81223FC(u8 *a0, u8 count, u8 a2); -void sub_8122448(u8 *a0, u8 count, u16 x, u16 y); -void DisplayMessageAndContinueTask(u8 taskId, u8 arg1, u16 arg2, u8 arg3, u8 arg4, u8 textSpeed, const u8 *string, void *taskFunc); +void sub_8121F68(u8 taskId, const struct YesNoFuncTable *data); void CreateYesNoMenuWithCallbacks(u8 taskId, const struct WindowTemplate *template, u8 arg2, u8 arg3, u8 arg4, u16 tileStart, u8 palette, const struct YesNoFuncTable *yesNo); +bool8 AdjustQuantityAccordingToDPadInput(s16 *arg0, u16 arg1); u8 GetLRKeysState(void); u8 sub_812210C(void); -bool8 sub_81221EC(void); +bool8 sub_8122148(u16 itemId); +bool8 itemid_80BF6D8_mail_related(u16 itemId); bool8 sub_81221AC(void); -bool8 sub_8122148(u16); -bool8 AdjustQuantityAccordingToDPadInput(s16*, u16); -bool8 itemid_80BF6D8_mail_related(u16); +bool8 sub_81221EC(void); +void sub_812220C(struct ItemSlot *slots, u8 count, u8 *arg2, u8 *usedSlotsCount, u8 maxUsedSlotsCount); +void sub_812225C(u16 *arg0, u16 *arg1, u8 arg2, u8 arg3); +void sub_8122298(u16 *arg0, u16 *arg1, u8 arg2, u8 arg3, u8 arg4); +void LoadListMenuArrowsGfx(void); +void sub_8122344(u8 *spriteIds, u8 count); +void sub_81223B0(u8 *spriteIds, u8 count); +void sub_81223FC(u8 *spriteIds, u8 count, bool8 invisible); +void sub_8122448(u8 *spriteIds, u8 count, s16 x, u16 y); #endif //GUARD_MENU_HELPERS_H diff --git a/ld_script.txt b/ld_script.txt index 2aa273ac7..d053e670e 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -164,7 +164,6 @@ SECTIONS { src/mauville_old_man.o(.text); src/mail.o(.text); src/menu_helpers.o(.text); - asm/menu_helpers.o(.text); src/dewford_trend.o(.text); src/heal_location.o(.text); src/region_map.o(.text); @@ -457,7 +456,7 @@ SECTIONS { src/mon_markings.o(.rodata); src/mauville_old_man.o(.rodata); src/mail.o(.rodata); - data/menu_helpers.o(.rodata); + src/menu_helpers.o(.rodata); src/heal_location.o(.rodata); src/region_map.o(.rodata); data/cute_sketch.o(.rodata); diff --git a/src/menu_helpers.c b/src/menu_helpers.c index 8e8197a12..178fbb5fa 100644 --- a/src/menu_helpers.c +++ b/src/menu_helpers.c @@ -17,19 +17,85 @@ #include "constants/items.h" #include "constants/maps.h" -extern u8 gUnknown_0203A140; -extern TaskFunc gUnknown_0300117C; -extern struct YesNoFuncTable gUnknown_0203A138; - -extern const struct CompressedSpriteSheet gUnknown_0859F514; -extern const struct CompressedSpritePalette gUnknown_0859F51C; - -extern bool32 InUnionRoom(void); extern bool32 sub_800B504(void); +extern const u8 gBagSwapLineGfx[]; +extern const u8 gBagSwapLinePal[]; + // this file's functions -void Task_ContinueTaskAfterMessagePrints(u8 taskId); -void Task_CallYesOrNoCallback(u8 taskId); +static void Task_ContinueTaskAfterMessagePrints(u8 taskId); +static void Task_CallYesOrNoCallback(u8 taskId); + +// EWRAM vars +EWRAM_DATA static struct YesNoFuncTable gUnknown_0203A138 = {0}; +EWRAM_DATA static u8 gUnknown_0203A140 = 0; + +// IWRAM bss vars +IWRAM_DATA static TaskFunc gUnknown_0300117C; + +// const rom data +static const struct OamData sOamData_859F4E8 = +{ + .y = 0, + .affineMode = 0, + .objMode = 0, + .mosaic = 0, + .bpp = 0, + .shape = 0, + .x = 0, + .matrixNum = 0, + .size = 1, + .tileNum = 0, + .priority = 0, + .paletteNum = 0, + .affineParam = 0 +}; + +static const union AnimCmd sSpriteAnim_859F4F0[] = +{ + ANIMCMD_FRAME(0, 0), + ANIMCMD_END +}; + +static const union AnimCmd sSpriteAnim_859F4F8[] = +{ + ANIMCMD_FRAME(4, 0), + ANIMCMD_END +}; + +static const union AnimCmd sSpriteAnim_859F500[] = +{ + ANIMCMD_FRAME(0, 0, 1, 0), + ANIMCMD_END +}; + +static const union AnimCmd *const sSpriteAnimTable_859F508[] = +{ + sSpriteAnim_859F4F0, + sSpriteAnim_859F4F8, + sSpriteAnim_859F500 +}; + +static const struct CompressedSpriteSheet gUnknown_0859F514 = +{ + gBagSwapLineGfx, 0x100, 109 +}; + +static const struct CompressedSpritePalette gUnknown_0859F51C = +{ + gBagSwapLinePal, 109 +}; + +static const struct SpriteTemplate gUnknown_0859F524 = +{ + .tileTag = 109, + .paletteTag = 109, + .oam = &sOamData_859F4E8, + .anims = sSpriteAnimTable_859F508, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = SpriteCallbackDummy, +}; // code void ResetVramOamAndBgCntRegs(void) @@ -82,7 +148,7 @@ bool16 RunTextPrintersRetIsActive(u8 textPrinterId) return IsTextPrinterActive(textPrinterId); } -void Task_ContinueTaskAfterMessagePrints(u8 taskId) +static void Task_ContinueTaskAfterMessagePrints(u8 taskId) { if (!RunTextPrintersRetIsActive(gUnknown_0203A140)) gUnknown_0300117C(taskId); @@ -101,7 +167,7 @@ void CreateYesNoMenuWithCallbacks(u8 taskId, const struct WindowTemplate *templa gTasks[taskId].func = Task_CallYesOrNoCallback; } -void Task_CallYesOrNoCallback(u8 taskId) +static void Task_CallYesOrNoCallback(u8 taskId) { switch (ProcessMenuInputNoWrap_()) { @@ -296,105 +362,94 @@ void sub_812225C(u16 *arg0, u16 *arg1, u8 arg2, u8 arg3) } } -#ifdef NONMATCHING void sub_8122298(u16 *arg0, u16 *arg1, u8 arg2, u8 arg3, u8 arg4) { - if (arg2 & 1) - { + u8 i; + if (arg4 % 2 != 0) + { + if ((*arg1) >= arg4 / 2) + { + for (i = 0; i < (*arg1) - (arg4 / 2); i++) + { + if ((*arg0) + arg2 == arg3) + break; + (*arg1)--; + (*arg0)++; + } + } } else { - + if ((*arg1) >= (arg4 / 2) + 1) + { + for (i = 0; i <= (*arg1) - (arg4 / 2); i++) + { + if ((*arg0) + arg2 == arg3) + break; + (*arg1)--; + (*arg0)++; + } + } } } -#else -NAKED -void sub_8122298(u16 *arg0, u16 *arg1, u8 arg2, u8 arg3, u8 arg4) -{ - asm_unified("\n\ - push {r4-r7,lr}\n\ - adds r5, r0, 0\n\ - adds r4, r1, 0\n\ - ldr r0, [sp, 0x14]\n\ - lsls r2, 24\n\ - lsrs r7, r2, 24\n\ - lsls r3, 24\n\ - lsrs r6, r3, 24\n\ - lsls r2, r0, 24\n\ - lsrs r0, r2, 24\n\ - movs r1, 0x1\n\ - ands r0, r1\n\ - cmp r0, 0\n\ - beq _081222F0\n\ - lsrs r2, 25\n\ - ldrh r0, [r4]\n\ - cmp r0, r2\n\ - bcc _08122322\n\ - movs r1, 0\n\ - subs r0, r2\n\ - cmp r1, r0\n\ - bge _08122322\n\ - ldrh r0, [r5]\n\ - adds r0, r7\n\ - cmp r0, r6\n\ - beq _08122322\n\ -_081222CC:\n\ - ldrh r0, [r4]\n\ - subs r0, 0x1\n\ - strh r0, [r4]\n\ - ldrh r0, [r5]\n\ - adds r0, 0x1\n\ - strh r0, [r5]\n\ - adds r0, r1, 0x1\n\ - lsls r0, 24\n\ - lsrs r1, r0, 24\n\ - ldrh r0, [r4]\n\ - subs r0, r2\n\ - cmp r1, r0\n\ - bge _08122322\n\ - ldrh r0, [r5]\n\ - adds r0, r7\n\ - cmp r0, r6\n\ - bne _081222CC\n\ - b _08122322\n\ -_081222F0:\n\ - ldrh r3, [r4]\n\ - lsrs r2, 25\n\ - adds r0, r2, 0x1\n\ - cmp r3, r0\n\ - blt _08122322\n\ - movs r1, 0\n\ - subs r0, r3, r2\n\ - b _08122316\n\ -_08122300:\n\ - ldrh r0, [r4]\n\ - subs r0, 0x1\n\ - strh r0, [r4]\n\ - ldrh r0, [r5]\n\ - adds r0, 0x1\n\ - strh r0, [r5]\n\ - adds r0, r1, 0x1\n\ - lsls r0, 24\n\ - lsrs r1, r0, 24\n\ - ldrh r0, [r4]\n\ - subs r0, r2\n\ -_08122316:\n\ - cmp r1, r0\n\ - bgt _08122322\n\ - ldrh r0, [r5]\n\ - adds r0, r7\n\ - cmp r0, r6\n\ - bne _08122300\n\ -_08122322:\n\ - pop {r4-r7}\n\ - pop {r0}\n\ - bx r0"); -} -#endif // NONMATCHING void LoadListMenuArrowsGfx(void) { LoadCompressedObjectPic(&gUnknown_0859F514); LoadCompressedObjectPalette(&gUnknown_0859F51C); } + +void sub_8122344(u8 *spriteIds, u8 count) +{ + u8 i; + + for (i = 0; i < count; i++) + { + spriteIds[i] = CreateSprite(&gUnknown_0859F524, i * 16, 0, 0); + if (i != 0) + StartSpriteAnim(&gSprites[spriteIds[i]], 1); + + gSprites[spriteIds[i]].invisible = 1; + } +} + +void sub_81223B0(u8 *spriteIds, u8 count) +{ + u8 i; + + for (i = 0; i < count; i++) + { + if (i == count - 1) + DestroySpriteAndFreeResources(&gSprites[spriteIds[i]]); + else + DestroySprite(&gSprites[spriteIds[i]]); + } +} + +void sub_81223FC(u8 *spriteIds, u8 count, bool8 invisible) +{ + u8 i; + + for (i = 0; i < count; i++) + { + gSprites[spriteIds[i]].invisible = invisible; + } +} + +void sub_8122448(u8 *spriteIds, u8 count, s16 x, u16 y) +{ + u8 i; + bool8 unknownBit = count & 0x80; + count &= ~(0x80); + + for (i = 0; i < count; i++) + { + if (i == count - 1 && unknownBit) + gSprites[spriteIds[i]].pos2.x = x - 8; + else + gSprites[spriteIds[i]].pos2.x = x; + + gSprites[spriteIds[i]].pos1.y = 1 + y; + } +} diff --git a/sym_bss.txt b/sym_bss.txt index 186ff8ced..089f25761 100644 --- a/sym_bss.txt +++ b/sym_bss.txt @@ -29,11 +29,7 @@ .include "src/record_mixing.o" .include "src/tv.o" .include "src/mauville_old_man.o" - - .align 2 -gUnknown_0300117C: @ 300117C - .space 0x4 - + .include "src/menu_helpers.o" .include "src/region_map.o" gUnknown_03001188: @ 3001188 diff --git a/sym_ewram.txt b/sym_ewram.txt index dd41ff5ac..4d7ae4f19 100644 --- a/sym_ewram.txt +++ b/sym_ewram.txt @@ -533,13 +533,7 @@ gUnknown_0203A120: @ 203A120 .include "src/mon_markings.o" .include "src/mauville_old_man.o" .include "src/mail.o" - -gUnknown_0203A138: @ 203A138 - .space 0x8 - -gUnknown_0203A140: @ 203A140 - .space 0x4 - + .include "src/menu_helpers.o" .include "src/region_map.o" .include "src/decoration.o" .align 2