From 7735fb2ad38ea84e43e1264fe882981706675e88 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Mon, 14 May 2018 23:03:40 +0200 Subject: [PATCH 1/2] start menu helpers decomp --- asm/menu_helpers.s | 756 --------------------------------------------- ld_script.txt | 1 + src/menu_helpers.c | 400 ++++++++++++++++++++++++ 3 files changed, 401 insertions(+), 756 deletions(-) create mode 100644 src/menu_helpers.c diff --git a/asm/menu_helpers.s b/asm/menu_helpers.s index 90e846b97b..dd8e1401b3 100644 --- a/asm/menu_helpers.s +++ b/asm/menu_helpers.s @@ -5,764 +5,8 @@ .text - thumb_func_start ResetVramOamAndBgCntRegs -ResetVramOamAndBgCntRegs: @ 8121DA0 - push {r4,lr} - sub sp, 0xC - movs r0, 0 - movs r1, 0 - bl SetGpuReg - movs r0, 0xE - movs r1, 0 - bl SetGpuReg - movs r0, 0xC - movs r1, 0 - bl SetGpuReg - movs r0, 0xA - movs r1, 0 - bl SetGpuReg - movs r0, 0x8 - movs r1, 0 - bl SetGpuReg - mov r1, sp - movs r0, 0 - strh r0, [r1] - movs r1, 0xC0 - lsls r1, 19 - ldr r2, =0x0100c000 - mov r0, sp - bl CpuSet - movs r4, 0 - str r4, [sp, 0x4] - add r0, sp, 0x4 - movs r1, 0xE0 - lsls r1, 19 - ldr r2, =0x05000100 - bl CpuSet - add r0, sp, 0x8 - strh r4, [r0] - movs r1, 0xA0 - lsls r1, 19 - ldr r2, =0x01000200 - bl CpuSet - add sp, 0xC - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end ResetVramOamAndBgCntRegs - thumb_func_start ResetAllBgsCoordinates -ResetAllBgsCoordinates: @ 8121E10 - push {lr} - movs r0, 0 - movs r1, 0 - movs r2, 0 - bl ChangeBgX - movs r0, 0 - movs r1, 0 - movs r2, 0 - bl ChangeBgY - movs r0, 0x1 - movs r1, 0 - movs r2, 0 - bl ChangeBgX - movs r0, 0x1 - movs r1, 0 - movs r2, 0 - bl ChangeBgY - movs r0, 0x2 - movs r1, 0 - movs r2, 0 - bl ChangeBgX - movs r0, 0x2 - movs r1, 0 - movs r2, 0 - bl ChangeBgY - movs r0, 0x3 - movs r1, 0 - movs r2, 0 - bl ChangeBgX - movs r0, 0x3 - movs r1, 0 - movs r2, 0 - bl ChangeBgY - pop {r0} - bx r0 - thumb_func_end ResetAllBgsCoordinates - thumb_func_start SetVBlankHBlankCallbacksToNull -@ void SetVBlankHBlankCallbacksToNull() -SetVBlankHBlankCallbacksToNull: @ 8121E68 - push {lr} - movs r0, 0 - bl SetVBlankCallback - movs r0, 0 - bl SetHBlankCallback - pop {r0} - bx r0 - thumb_func_end SetVBlankHBlankCallbacksToNull - - thumb_func_start DisplayMessageAndContinueTask -@ void DisplayMessageAndContinueTask(u8 taskId, u8 windowId, u16 windowBorderFirstTileNum, u8 windowBorderPalette, u8 fontId, u8 speed, u8 *str, void ( *callback)(u8 taskId)) -DisplayMessageAndContinueTask: @ 8121E7C - push {r4-r7,lr} - mov r7, r8 - push {r7} - sub sp, 0x10 - ldr r4, [sp, 0x28] - ldr r5, [sp, 0x2C] - lsls r0, 24 - lsrs r0, 24 - mov r8, r0 - lsls r1, 24 - lsrs r1, 24 - adds r6, r1, 0 - lsls r2, 16 - lsrs r2, 16 - lsls r3, 24 - lsrs r3, 24 - lsls r4, 24 - lsrs r7, r4, 24 - lsls r5, 24 - lsrs r5, 24 - ldr r0, =gUnknown_0203A140 - strb r6, [r0] - adds r0, r6, 0 - movs r1, 0x1 - bl sub_8197B1C - ldr r4, =gStringVar4 - ldr r0, [sp, 0x30] - cmp r0, r4 - beq _08121EC0 - adds r0, r4, 0 - ldr r1, [sp, 0x30] - bl StringExpandPlaceholders -_08121EC0: - ldr r2, =gTextFlags - ldrb r0, [r2] - movs r1, 0x1 - orrs r0, r1 - strb r0, [r2] - movs r0, 0 - str r0, [sp] - movs r0, 0x2 - str r0, [sp, 0x4] - movs r0, 0x1 - str r0, [sp, 0x8] - movs r0, 0x3 - str r0, [sp, 0xC] - adds r0, r6, 0 - adds r1, r7, 0 - adds r2, r4, 0 - adds r3, r5, 0 - bl AddTextPrinterParameterized - ldr r1, =gUnknown_0300117C - ldr r0, [sp, 0x34] - str r0, [r1] - ldr r1, =gTasks - mov r2, r8 - lsls r0, r2, 2 - add r0, r8 - lsls r0, 3 - adds r0, r1 - ldr r1, =Task_ContinueTaskAfterMessagePrints - str r1, [r0] - add sp, 0x10 - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end DisplayMessageAndContinueTask - - thumb_func_start RunTextPrintersRetIsActive -RunTextPrintersRetIsActive: @ 8121F20 - push {r4,lr} - adds r4, r0, 0 - lsls r4, 24 - lsrs r4, 24 - bl RunTextPrinters - adds r0, r4, 0 - bl IsTextPrinterActive - lsls r0, 16 - lsrs r0, 16 - pop {r4} - pop {r1} - bx r1 - thumb_func_end RunTextPrintersRetIsActive - - thumb_func_start Task_ContinueTaskAfterMessagePrints -@ void Task_ContinueTaskAfterMessagePrints(u8 taskId) -Task_ContinueTaskAfterMessagePrints: @ 8121F3C - push {r4,lr} - lsls r0, 24 - lsrs r4, r0, 24 - ldr r0, =gUnknown_0203A140 - ldrb r0, [r0] - bl RunTextPrintersRetIsActive - lsls r0, 16 - cmp r0, 0 - bne _08121F5A - ldr r0, =gUnknown_0300117C - ldr r1, [r0] - adds r0, r4, 0 - bl _call_via_r1 -_08121F5A: - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end Task_ContinueTaskAfterMessagePrints - - thumb_func_start sub_8121F68 -sub_8121F68: @ 8121F68 - lsls r0, 24 - lsrs r0, 24 - ldr r3, =gUnknown_0203A138 - ldr r2, [r1, 0x4] - ldr r1, [r1] - str r1, [r3] - str r2, [r3, 0x4] - ldr r2, =gTasks - lsls r1, r0, 2 - adds r1, r0 - lsls r1, 3 - adds r1, r2 - ldr r0, =Task_CallYesOrNoCallback - str r0, [r1] - bx lr - .pool - thumb_func_end sub_8121F68 - - thumb_func_start CreateYesNoMenuWithCallbacks -@ void CreateYesNoMenuWithCallbacks(u8 taskId, struct WindowTemplate *windowTemplate, int a3, int a4, int a5, u16 borderFirstTileNum, u8 borderPalette, void ( **callbacks)(u8 taskId)) -CreateYesNoMenuWithCallbacks: @ 8121F94 - push {r4,r5,lr} - adds r4, r0, 0 - adds r0, r1, 0 - ldr r1, [sp, 0x10] - ldr r2, [sp, 0x14] - ldr r5, [sp, 0x18] - lsls r4, 24 - lsrs r4, 24 - lsls r1, 16 - lsrs r1, 16 - lsls r2, 24 - lsrs r2, 24 - movs r3, 0 - bl CreateYesNoMenu - ldr r2, =gUnknown_0203A138 - ldr r0, [r5] - ldr r1, [r5, 0x4] - str r0, [r2] - str r1, [r2, 0x4] - ldr r1, =gTasks - lsls r0, r4, 2 - adds r0, r4 - lsls r0, 3 - adds r0, r1 - ldr r1, =Task_CallYesOrNoCallback - str r1, [r0] - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end CreateYesNoMenuWithCallbacks - - thumb_func_start Task_CallYesOrNoCallback -@ void Task_CallYesOrNoCallback(u8 taskId) -Task_CallYesOrNoCallback: @ 8121FDC - push {r4,lr} - lsls r0, 24 - lsrs r4, r0, 24 - bl ProcessMenuInputNoWrap_ - lsls r0, 24 - asrs r1, r0, 24 - cmp r1, 0 - beq _08122002 - cmp r1, 0 - bgt _08121FFC - movs r0, 0x1 - negs r0, r0 - cmp r1, r0 - beq _08122018 - b _08122028 -_08121FFC: - cmp r1, 0x1 - beq _08122018 - b _08122028 -_08122002: - movs r0, 0x5 - bl PlaySE - ldr r0, =gUnknown_0203A138 - ldr r1, [r0] - adds r0, r4, 0 - bl _call_via_r1 - b _08122028 - .pool -_08122018: - movs r0, 0x5 - bl PlaySE - ldr r0, =gUnknown_0203A138 - ldr r1, [r0, 0x4] - adds r0, r4, 0 - bl _call_via_r1 -_08122028: - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end Task_CallYesOrNoCallback - - thumb_func_start AdjustQuantityAccordingToDPadInput -@ bool8 AdjustQuantityAccordingToDPadInput(u16 *quantity, u16 maxQuantity) -AdjustQuantityAccordingToDPadInput: @ 8122034 - push {r4-r6,lr} - adds r2, r0, 0 - lsls r1, 16 - lsrs r1, 16 - adds r5, r1, 0 - ldrh r4, [r2] - adds r6, r4, 0 - ldr r0, =gMain - ldrh r0, [r0, 0x30] - movs r3, 0xF0 - ands r3, r0 - cmp r3, 0x40 - bne _0812206C - adds r0, r4, 0x1 - strh r0, [r2] - movs r3, 0 - ldrsh r0, [r2, r3] - cmp r0, r1 - ble _0812205E - movs r0, 0x1 - strh r0, [r2] -_0812205E: - movs r0, 0 - ldrsh r1, [r2, r0] -_08122062: - lsls r0, r4, 16 - b _081220B6 - .pool -_0812206C: - cmp r3, 0x80 - bne _08122082 - subs r0, r4, 0x1 - strh r0, [r2] - lsls r0, 16 - cmp r0, 0 - bgt _0812207C - strh r1, [r2] -_0812207C: - movs r3, 0 - ldrsh r1, [r2, r3] - b _08122062 -_08122082: - cmp r3, 0x10 - bne _0812209C - adds r0, r4, 0 - adds r0, 0xA - strh r0, [r2] - movs r1, 0 - ldrsh r0, [r2, r1] - cmp r0, r5 - ble _08122096 - strh r5, [r2] -_08122096: - movs r3, 0 - ldrsh r1, [r2, r3] - b _08122062 -_0812209C: - cmp r3, 0x20 - bne _081220C6 - adds r0, r4, 0 - subs r0, 0xA - strh r0, [r2] - lsls r0, 16 - cmp r0, 0 - bgt _081220B0 - movs r0, 0x1 - strh r0, [r2] -_081220B0: - movs r0, 0 - ldrsh r1, [r2, r0] - lsls r0, r6, 16 -_081220B6: - asrs r0, 16 - cmp r1, r0 - beq _081220C6 - movs r0, 0x5 - bl PlaySE - movs r0, 0x1 - b _081220C8 -_081220C6: - movs r0, 0 -_081220C8: - pop {r4-r6} - pop {r1} - bx r1 - thumb_func_end AdjustQuantityAccordingToDPadInput - - thumb_func_start GetLRKeysState -GetLRKeysState: @ 81220D0 - push {lr} - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldrb r0, [r0, 0x13] - cmp r0, 0x1 - bne _08122106 - ldr r0, =gMain - ldrh r1, [r0, 0x2E] - movs r0, 0x80 - lsls r0, 2 - ands r0, r1 - cmp r0, 0 - beq _081220F8 - movs r0, 0x1 - b _08122108 - .pool -_081220F8: - movs r0, 0x80 - lsls r0, 1 - ands r0, r1 - cmp r0, 0 - beq _08122106 - movs r0, 0x2 - b _08122108 -_08122106: - movs r0, 0 -_08122108: - pop {r1} - bx r1 - thumb_func_end GetLRKeysState - - thumb_func_start sub_812210C -sub_812210C: @ 812210C - push {lr} - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldrb r0, [r0, 0x13] - cmp r0, 0x1 - bne _08122142 - ldr r0, =gMain - ldrh r1, [r0, 0x30] - movs r0, 0x80 - lsls r0, 2 - ands r0, r1 - cmp r0, 0 - beq _08122134 - movs r0, 0x1 - b _08122144 - .pool -_08122134: - movs r0, 0x80 - lsls r0, 1 - ands r0, r1 - cmp r0, 0 - beq _08122142 - movs r0, 0x2 - b _08122144 -_08122142: - movs r0, 0 -_08122144: - pop {r1} - bx r1 - thumb_func_end sub_812210C - - thumb_func_start sub_8122148 -sub_8122148: @ 8122148 - push {lr} - lsls r0, 16 - lsrs r0, 16 - cmp r0, 0xAF - bne _08122174 - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - ldrh r1, [r0, 0x4] - ldr r0, =0x00001919 - cmp r1, r0 - beq _08122166 - bl InUnionRoom - cmp r0, 0x1 - bne _08122174 -_08122166: - movs r0, 0 - b _08122176 - .pool -_08122174: - movs r0, 0x1 -_08122176: - pop {r1} - bx r1 - thumb_func_end sub_8122148 - - thumb_func_start itemid_80BF6D8_mail_related -itemid_80BF6D8_mail_related: @ 812217C - push {r4,lr} - lsls r0, 16 - lsrs r4, r0, 16 - bl is_c1_link_related_active - cmp r0, 0x1 - beq _08122192 - bl InUnionRoom - cmp r0, 0x1 - bne _081221A4 -_08122192: - adds r0, r4, 0 - bl ItemIsMail - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x1 - bne _081221A4 - movs r0, 0 - b _081221A6 -_081221A4: - movs r0, 0x1 -_081221A6: - pop {r4} - pop {r1} - bx r1 - thumb_func_end itemid_80BF6D8_mail_related - - thumb_func_start sub_81221AC -sub_81221AC: @ 81221AC - push {lr} - bl is_c1_link_related_active - cmp r0, 0x1 - beq _081221BE - ldr r0, =gReceivedRemoteLinkPlayers - ldrb r0, [r0] - cmp r0, 0x1 - bne _081221C8 -_081221BE: - movs r0, 0x1 - b _081221CA - .pool -_081221C8: - movs r0, 0 -_081221CA: - pop {r1} - bx r1 - thumb_func_end sub_81221AC - - thumb_func_start sub_81221D0 -sub_81221D0: @ 81221D0 - push {lr} - bl sub_81221AC - lsls r0, 24 - cmp r0, 0 - beq _081221E6 - bl sub_8087598 - lsls r0, 24 - lsrs r0, 24 - b _081221E8 -_081221E6: - movs r0, 0 -_081221E8: - pop {r1} - bx r1 - thumb_func_end sub_81221D0 - - thumb_func_start sub_81221EC -sub_81221EC: @ 81221EC - push {lr} - bl sub_81221D0 - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x1 - beq _08122202 - bl sub_800B504 - cmp r0, 0x1 - bne _08122206 -_08122202: - movs r0, 0x1 - b _08122208 -_08122206: - movs r0, 0 -_08122208: - pop {r1} - bx r1 - thumb_func_end sub_81221EC - - thumb_func_start sub_812220C -sub_812220C: @ 812220C - push {r4-r6,lr} - adds r6, r2, 0 - ldr r2, [sp, 0x10] - lsls r1, 24 - lsls r2, 24 - lsrs r5, r2, 24 - adds r4, r0, 0 - movs r0, 0 - strb r0, [r3] - movs r2, 0 - lsrs r1, 24 - cmp r2, r1 - bcs _08122240 -_08122226: - lsls r0, r2, 2 - adds r0, r4 - ldrh r0, [r0] - cmp r0, 0 - beq _08122236 - ldrb r0, [r3] - adds r0, 0x1 - strb r0, [r3] -_08122236: - adds r0, r2, 0x1 - lsls r0, 16 - lsrs r2, r0, 16 - cmp r2, r1 - bcc _08122226 -_08122240: - ldrb r0, [r3] - adds r1, r0, 0x1 - strb r1, [r3] - lsls r0, r1, 24 - lsrs r0, 24 - cmp r0, r5 - bls _08122252 - strb r5, [r6] - b _08122254 -_08122252: - strb r1, [r6] -_08122254: - pop {r4-r6} - pop {r0} - bx r0 - thumb_func_end sub_812220C - - thumb_func_start sub_812225C -sub_812225C: @ 812225C - push {r4,r5,lr} - adds r4, r0, 0 - adds r5, r1, 0 - lsls r2, 24 - lsrs r2, 24 - lsls r3, 24 - lsrs r3, 24 - ldrh r0, [r4] - cmp r0, 0 - beq _0812227A - adds r0, r2 - cmp r0, r3 - ble _0812227A - subs r0, r3, r2 - strh r0, [r4] -_0812227A: - ldrh r0, [r4] - ldrh r1, [r5] - adds r0, r1 - cmp r0, r3 - blt _08122290 - cmp r3, 0 - bne _0812228C - strh r3, [r5] - b _08122290 -_0812228C: - subs r0, r3, 0x1 - strh r0, [r5] -_08122290: - pop {r4,r5} - pop {r0} - bx r0 - thumb_func_end sub_812225C - - thumb_func_start sub_8122298 -sub_8122298: @ 8122298 - push {r4-r7,lr} - adds r5, r0, 0 - adds r4, r1, 0 - ldr r0, [sp, 0x14] - lsls r2, 24 - lsrs r7, r2, 24 - lsls r3, 24 - lsrs r6, r3, 24 - lsls r2, r0, 24 - lsrs r0, r2, 24 - movs r1, 0x1 - ands r0, r1 - cmp r0, 0 - beq _081222F0 - lsrs r2, 25 - ldrh r0, [r4] - cmp r0, r2 - bcc _08122322 - movs r1, 0 - subs r0, r2 - cmp r1, r0 - bge _08122322 - ldrh r0, [r5] - adds r0, r7 - cmp r0, r6 - beq _08122322 -_081222CC: - ldrh r0, [r4] - subs r0, 0x1 - strh r0, [r4] - ldrh r0, [r5] - adds r0, 0x1 - strh r0, [r5] - adds r0, r1, 0x1 - lsls r0, 24 - lsrs r1, r0, 24 - ldrh r0, [r4] - subs r0, r2 - cmp r1, r0 - bge _08122322 - ldrh r0, [r5] - adds r0, r7 - cmp r0, r6 - bne _081222CC - b _08122322 -_081222F0: - ldrh r3, [r4] - lsrs r2, 25 - adds r0, r2, 0x1 - cmp r3, r0 - blt _08122322 - movs r1, 0 - subs r0, r3, r2 - b _08122316 -_08122300: - ldrh r0, [r4] - subs r0, 0x1 - strh r0, [r4] - ldrh r0, [r5] - adds r0, 0x1 - strh r0, [r5] - adds r0, r1, 0x1 - lsls r0, 24 - lsrs r1, r0, 24 - ldrh r0, [r4] - subs r0, r2 -_08122316: - cmp r1, r0 - bgt _08122322 - ldrh r0, [r5] - adds r0, r7 - cmp r0, r6 - bne _08122300 -_08122322: - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_8122298 - - thumb_func_start LoadListMenuArrowsGfx -LoadListMenuArrowsGfx: @ 8122328 - push {lr} - ldr r0, =gUnknown_0859F514 - bl LoadCompressedObjectPic - ldr r0, =gUnknown_0859F51C - bl LoadCompressedObjectPalette - pop {r0} - bx r0 - .pool - thumb_func_end LoadListMenuArrowsGfx thumb_func_start sub_8122344 sub_8122344: @ 8122344 diff --git a/ld_script.txt b/ld_script.txt index cf218af512..2aa273ac76 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -163,6 +163,7 @@ SECTIONS { src/mon_markings.o(.text); 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); diff --git a/src/menu_helpers.c b/src/menu_helpers.c new file mode 100644 index 0000000000..8e8197a121 --- /dev/null +++ b/src/menu_helpers.c @@ -0,0 +1,400 @@ +#include "global.h" +#include "task.h" +#include "window.h" +#include "menu.h" +#include "menu_helpers.h" +#include "gpu_regs.h" +#include "bg.h" +#include "main.h" +#include "text.h" +#include "link.h" +#include "string_util.h" +#include "sound.h" +#include "mail.h" +#include "overworld.h" +#include "decompress.h" +#include "constants/songs.h" +#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); + +// this file's functions +void Task_ContinueTaskAfterMessagePrints(u8 taskId); +void Task_CallYesOrNoCallback(u8 taskId); + +// code +void ResetVramOamAndBgCntRegs(void) +{ + SetGpuReg(REG_OFFSET_DISPCNT, 0); + SetGpuReg(REG_OFFSET_BG3CNT, 0); + SetGpuReg(REG_OFFSET_BG2CNT, 0); + SetGpuReg(REG_OFFSET_BG1CNT, 0); + SetGpuReg(REG_OFFSET_BG0CNT, 0); + CpuFill16(0, (void*) VRAM, VRAM_SIZE); + CpuFill32(0, (void*) OAM, OAM_SIZE); + CpuFill16(0, (void*) PLTT, PLTT_SIZE); +} + +void ResetAllBgsCoordinates(void) +{ + ChangeBgX(0, 0, 0); + ChangeBgY(0, 0, 0); + ChangeBgX(1, 0, 0); + ChangeBgY(1, 0, 0); + ChangeBgX(2, 0, 0); + ChangeBgY(2, 0, 0); + ChangeBgX(3, 0, 0); + ChangeBgY(3, 0, 0); +} + +void SetVBlankHBlankCallbacksToNull(void) +{ + SetVBlankCallback(NULL); + SetHBlankCallback(NULL); +} + +void DisplayMessageAndContinueTask(u8 taskId, u8 windowId, u16 arg2, u8 arg3, u8 fontId, u8 textSpeed, const u8 *string, void *taskFunc) +{ + gUnknown_0203A140 = windowId; + sub_8197B1C(windowId, TRUE, arg2, arg3); + + if (string != gStringVar4) + StringExpandPlaceholders(gStringVar4, string); + + gTextFlags.flag_0 = 1; + AddTextPrinterParameterized(windowId, fontId, gStringVar4, textSpeed, NULL, 2, 1, 3); + gUnknown_0300117C = taskFunc; + gTasks[taskId].func = Task_ContinueTaskAfterMessagePrints; +} + +bool16 RunTextPrintersRetIsActive(u8 textPrinterId) +{ + RunTextPrinters(); + return IsTextPrinterActive(textPrinterId); +} + +void Task_ContinueTaskAfterMessagePrints(u8 taskId) +{ + if (!RunTextPrintersRetIsActive(gUnknown_0203A140)) + gUnknown_0300117C(taskId); +} + +void sub_8121F68(u8 taskId, const struct YesNoFuncTable *data) +{ + gUnknown_0203A138 = *data; + gTasks[taskId].func = Task_CallYesOrNoCallback; +} + +void CreateYesNoMenuWithCallbacks(u8 taskId, const struct WindowTemplate *template, u8 arg2, u8 arg3, u8 arg4, u16 tileStart, u8 palette, const struct YesNoFuncTable *yesNo) +{ + CreateYesNoMenu(template, tileStart, palette, 0); + gUnknown_0203A138 = *yesNo; + gTasks[taskId].func = Task_CallYesOrNoCallback; +} + +void Task_CallYesOrNoCallback(u8 taskId) +{ + switch (ProcessMenuInputNoWrap_()) + { + case 0: + PlaySE(SE_SELECT); + gUnknown_0203A138.yesFunc(taskId); + break; + case 1: + case MENU_B_PRESSED: + PlaySE(SE_SELECT); + gUnknown_0203A138.noFunc(taskId); + break; + } +} + +bool8 AdjustQuantityAccordingToDPadInput(s16 *arg0, u16 arg1) +{ + s16 valBefore = (*arg0); + + if ((gMain.newAndRepeatedKeys & DPAD_ANY) == DPAD_UP) + { + (*arg0)++; + if ((*arg0) > arg1) + (*arg0) = 1; + + if ((*arg0) == valBefore) + { + return FALSE; + } + else + { + PlaySE(SE_SELECT); + return TRUE; + } + } + else if ((gMain.newAndRepeatedKeys & DPAD_ANY) == DPAD_DOWN) + { + (*arg0)--; + if ((*arg0) <= 0) + (*arg0) = arg1; + + if ((*arg0) == valBefore) + { + return FALSE; + } + else + { + PlaySE(SE_SELECT); + return TRUE; + } + } + else if ((gMain.newAndRepeatedKeys & DPAD_ANY) == DPAD_RIGHT) + { + (*arg0) += 10; + if ((*arg0) > arg1) + (*arg0) = arg1; + + if ((*arg0) == valBefore) + { + return FALSE; + } + else + { + PlaySE(SE_SELECT); + return TRUE; + } + } + else if ((gMain.newAndRepeatedKeys & DPAD_ANY) == DPAD_LEFT) + { + (*arg0) -= 10; + if ((*arg0) <= 0) + (*arg0) = 1; + + if ((*arg0) == valBefore) + { + return FALSE; + } + else + { + PlaySE(SE_SELECT); + return TRUE; + } + } + + return FALSE; +} + +u8 GetLRKeysState(void) +{ + if (gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR) + { + if (gMain.newKeys & L_BUTTON) + return 1; + if (gMain.newKeys & R_BUTTON) + return 2; + } + + return 0; +} + +u8 sub_812210C(void) +{ + if (gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR) + { + if (gMain.newAndRepeatedKeys & L_BUTTON) + return 1; + if (gMain.newAndRepeatedKeys & R_BUTTON) + return 2; + } + + return 0; +} + +bool8 sub_8122148(u16 itemId) +{ + if (itemId != ITEM_ENIGMA_BERRY) + return TRUE; + else if (gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(TRADE_CENTER) && gSaveBlock1Ptr->location.mapNum == MAP_NUM(TRADE_CENTER)) + return FALSE; + else if (InUnionRoom() != TRUE) + return TRUE; + else + return FALSE; +} + +bool8 itemid_80BF6D8_mail_related(u16 itemId) +{ + if (is_c1_link_related_active() != TRUE && InUnionRoom() != TRUE) + return TRUE; + else if (ItemIsMail(itemId) != TRUE) + return TRUE; + else + return FALSE; +} + +bool8 sub_81221AC(void) +{ + if (is_c1_link_related_active() == TRUE || gReceivedRemoteLinkPlayers == 1) + return TRUE; + else + return FALSE; +} + +static bool8 sub_81221D0(void) +{ + if (!sub_81221AC()) + return FALSE; + else + return sub_8087598(); +} + +bool8 sub_81221EC(void) +{ + if (sub_81221D0() == TRUE) + return TRUE; + else if (sub_800B504() != TRUE) + return FALSE; + else + return TRUE; +} + +void sub_812220C(struct ItemSlot *slots, u8 count, u8 *arg2, u8 *usedSlotsCount, u8 maxUsedSlotsCount) +{ + u16 i; + struct ItemSlot *slots_ = slots; + + (*usedSlotsCount) = 0; + for (i = 0; i < count; i++) + { + if (slots_[i].itemId != ITEM_NONE) + (*usedSlotsCount)++; + } + + (*usedSlotsCount)++; + if ((*usedSlotsCount) > maxUsedSlotsCount) + *arg2 = maxUsedSlotsCount; + else + *arg2 = (*usedSlotsCount); +} + +void sub_812225C(u16 *arg0, u16 *arg1, u8 arg2, u8 arg3) +{ + if ((*arg0) != 0 && (*arg0) + arg2 > arg3) + (*arg0) = arg3 - arg2; + + if ((*arg0) + (*arg1) >= arg3) + { + if (arg3 == 0) + (*arg1) = 0; + else + (*arg1) = arg3 - 1; + } +} + +#ifdef NONMATCHING +void sub_8122298(u16 *arg0, u16 *arg1, u8 arg2, u8 arg3, u8 arg4) +{ + if (arg2 & 1) + { + + } + else + { + + } +} +#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); +} From 0cf3836a0376f539108ce10a4cf4d31b758d0ac4 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Tue, 15 May 2018 20:22:19 +0200 Subject: [PATCH 2/2] decompile menu helpers --- asm/menu_helpers.s | 230 ------------------------------------- data/menu_helpers.s | 37 ------ include/menu_helpers.h | 32 +++--- ld_script.txt | 3 +- src/menu_helpers.c | 255 +++++++++++++++++++++++++---------------- sym_bss.txt | 6 +- sym_ewram.txt | 8 +- 7 files changed, 173 insertions(+), 398 deletions(-) delete mode 100644 asm/menu_helpers.s delete mode 100644 data/menu_helpers.s diff --git a/asm/menu_helpers.s b/asm/menu_helpers.s deleted file mode 100644 index dd8e1401b3..0000000000 --- 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 25ca664859..0000000000 --- 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 4de6603a3c..387a89fdd6 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 2aa273ac76..d053e670e9 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 8e8197a121..178fbb5fac 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 186ff8cedd..089f257615 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 dd41ff5ac6..4d7ae4f196 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