From 12df1f050e31a56f09db4d97e21fab13ef8f549b Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Tue, 3 Jun 2025 10:23:47 +0200 Subject: [PATCH] Naming Screen file split --- include/menu_input.h | 2 +- include/naming_screen.h | 10 ++ ld_script.ld | 2 + src/code_8015080.c | 102 ++++++++++++++++++ src/code_801602C.c | 5 +- src/code_809A560.c | 5 +- src/friend_rescue.c | 5 +- src/menu_input.c | 14 +-- src/naming_screen.c | 201 +++++++++++------------------------- src/options_menu2.c | 2 +- src/other_menus2.c | 4 +- src/rescue_password_menu.c | 5 +- src/string_format.c | 2 +- src/thank_you_wonder_mail.c | 5 +- src/wonder_mail.c | 5 +- src/wonder_mail_main_menu.c | 5 +- sym_ewram_init.txt | 1 + 17 files changed, 193 insertions(+), 182 deletions(-) create mode 100644 include/naming_screen.h create mode 100644 src/code_8015080.c diff --git a/include/menu_input.h b/include/menu_input.h index 45ce30d76..62e1ed41b 100644 --- a/include/menu_input.h +++ b/include/menu_input.h @@ -6,7 +6,7 @@ u32 sub_8012A64(MenuInputStructSub *r0, s32 r1); s32 GetKeyPress(MenuInputStruct *r0); -s32 sub_8012AE8(void); +s32 GetMenuInput(void); void sub_8012BC4(u32 x, u32 y, s32 n, s32 len, u32 color, u32 windowId); void DrawCharOnWindowWidth12(u32 x, u32 y, u32 param_3, u32 color, u32 param_5); void sub_8012CAC(WindowTemplate *param_1, const MenuItem *param_2); diff --git a/include/naming_screen.h b/include/naming_screen.h new file mode 100644 index 000000000..b8a70ee79 --- /dev/null +++ b/include/naming_screen.h @@ -0,0 +1,10 @@ +#ifndef GUARD_NAMING_SCREEN_H +#define GUARD_NAMING_SCREEN_H + +u32 NamingScreen_Init(u32 type, u8 *defaultText); +u32 NamingScreen_HandleInput(void); +void NamingScreen_Free(void); +s32 GetStrWidth(u8 *buffer, s32 size); +s32 GetMaxPokeNameWidth(void); + +#endif diff --git a/ld_script.ld b/ld_script.ld index 8b1ff3766..4cda52652 100755 --- a/ld_script.ld +++ b/ld_script.ld @@ -101,6 +101,7 @@ SECTIONS { src/code_8012A18.o(.text); src/menu_input.o(.text); src/string_format.o(.text); + src/code_8015080.o(.text); src/naming_screen.o(.text); src/code_801602C.o(.text); src/felicity_bank.o(.text); @@ -453,6 +454,7 @@ SECTIONS { src/string_format.o(.rodata); data/data_80D47B8.o(.rodata); src/common_strings.o(.rodata); + src/code_8015080.o(.rodata); src/naming_screen.o(.rodata); src/code_801602C.o(.rodata); src/felicity_bank.o(.rodata); diff --git a/src/code_8015080.c b/src/code_8015080.c new file mode 100644 index 000000000..067dd7faf --- /dev/null +++ b/src/code_8015080.c @@ -0,0 +1,102 @@ +#include "global.h" +#include "globaldata.h" +#include "code_800D090.h" +#include "code_80118A4.h" +#include "code_803D0D8.h" +#include "input.h" +#include "memory.h" +#include "menu_input.h" +#include "sprite.h" +#include "string_format.h" +#include "text_1.h" +#include "text_2.h" +#include "text_3.h" +#include "text_util.h" +#include "constants/input.h" + +struct unkStruct_203B1F8 +{ + // size: 0x4B4 + u32 menuAction; + MenuStruct unk4; + WindowTemplates windows; + u8 buffer[0x400]; +}; + +EWRAM_INIT struct unkStruct_203B1F8 *gUnknown_203B1F8 = {NULL}; + +const WindowTemplate gUnknown_80DAF70 = { + 0x00, + 0x03, + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x00, + NULL +}; + +const WindowTemplate gUnknown_80DAF88 = { + 0x00, + 0x03, + 0x02, 0x02, + 0x1A, 0x0c, + 0x0c, 0x00, + NULL +}; + +const WindowTemplate gUnknown_80DAFA0 = { + 0x00, + 0x03, + 0x16, 0x0F, + 0x06, 0x03, + 0x03, 0x00, + NULL +}; + +bool8 sub_8015080(u8 *buffer, const MenuItem *menuItems) +{ + s32 index; + + gUnknown_203B1F8 = MemoryAlloc(sizeof(struct unkStruct_203B1F8), 8); + gUnknown_203B1F8->menuAction = 0; + + for(index = 0; index < 4; index++) + { + gUnknown_203B1F8->windows.id[index] = gUnknown_80DAF70; + } + + gUnknown_203B1F8->windows.id[0] = gUnknown_80DAF88; + gUnknown_203B1F8->windows.id[2] = gUnknown_80DAFA0; + sub_8012CAC(&gUnknown_203B1F8->windows.id[2], menuItems); + ResetUnusedInputStruct(); + ShowWindows(&gUnknown_203B1F8->windows, 1, 1); + sub_80073B8(0); + FormatString(buffer, gUnknown_203B1F8->buffer, gUnknown_203B1F8->buffer + 0x400, 0); + PrintStringOnWindow(4, 4, gUnknown_203B1F8->buffer, 0, 0); + sub_80073E0(0); + sub_8012D60(&gUnknown_203B1F8->unk4, menuItems, 0, 0, -1, 2); + return TRUE; +} + +u32 sub_801516C(void) +{ + if(!sub_8012FD8(&gUnknown_203B1F8->unk4)) { + sub_8013114(&gUnknown_203B1F8->unk4, &gUnknown_203B1F8->menuAction); + return 3; + } + else { + return 0; + } +} + +u32 sub_8015198(void) +{ + return gUnknown_203B1F8->menuAction; +} + +void sub_80151A4(void) +{ + if(gUnknown_203B1F8) { + MemoryFree(gUnknown_203B1F8); + gUnknown_203B1F8 = NULL; + } +} diff --git a/src/code_801602C.c b/src/code_801602C.c index 53cf4b8d7..9d9ef52c3 100644 --- a/src/code_801602C.c +++ b/src/code_801602C.c @@ -8,10 +8,7 @@ #include "string_format.h" #include "text_util.h" #include "text_1.h" - -u32 NamingScreen_Init(u32 type, u8 *defaultText); -u32 NamingScreen_HandleInput(void); -void NamingScreen_Free(void); +#include "naming_screen.h" EWRAM_INIT static struct unkStruct_203B200 *sUnknown_203B200 = {NULL}; diff --git a/src/code_809A560.c b/src/code_809A560.c index 944ea511a..476f34744 100644 --- a/src/code_809A560.c +++ b/src/code_809A560.c @@ -31,10 +31,7 @@ #include "wigglytuff_shop1.h" #include "wigglytuff_shop3.h" #include "wonder_mail.h" - -u32 NamingScreen_Init(u32 type, u8 *defaultText); -u32 NamingScreen_HandleInput(void); -void NamingScreen_Free(void); +#include "naming_screen.h" IWRAM_INIT struct unkStruct_3001B64 *gUnknown_3001B64 = { NULL }; diff --git a/src/friend_rescue.c b/src/friend_rescue.c index f40c21e72..e566a2f92 100644 --- a/src/friend_rescue.c +++ b/src/friend_rescue.c @@ -27,10 +27,7 @@ #include "text_util.h" #include "wonder_mail_4.h" #include "wonder_mail_5.h" - -u32 NamingScreen_Init(u32 type, u8 *defaultText); -u32 NamingScreen_HandleInput(void); -void NamingScreen_Free(void); +#include "naming_screen.h" extern void SetFriendRescueMenuState(u32); diff --git a/src/menu_input.c b/src/menu_input.c index b87de29a4..c93c34541 100644 --- a/src/menu_input.c +++ b/src/menu_input.c @@ -71,7 +71,7 @@ static bool8 sub_8013DD0(unkStructFor8013AA0 *); u32 sub_8012A64(MenuInputStructSub *r0, s32 r1) { if (r0 == NULL) - return sub_8012AE8(); + return GetMenuInput(); if (r1 != -1) nullsub_34(r0, r1); @@ -82,7 +82,7 @@ u32 sub_8012A64(MenuInputStructSub *r0, s32 r1) } if (r0->b_button == 0) - return sub_8012AE8(); + return GetMenuInput(); r0->b_button = 0; return INPUT_B_BUTTON; @@ -104,10 +104,10 @@ s32 GetKeyPress(MenuInputStruct *r0) return INPUT_DPAD_RIGHT; } - return sub_8012AE8(); + return GetMenuInput(); } -s32 sub_8012AE8(void) +s32 GetMenuInput(void) { if (gRealInputs.held & R_BUTTON) { if (gRealInputs.pressed & A_BUTTON) @@ -1051,7 +1051,7 @@ u32 sub_8013BBC(unkStructFor8013AA0 *a0) if (sub_8013DD0(a0)) return 1; - switch (sub_8012AE8()) { + switch (GetMenuInput()) { case INPUT_B_BUTTON: PlayMenuSoundEffect(1); return 2; @@ -1095,7 +1095,7 @@ void sub_8013D10(unkStructFor8013AA0 *a0) window = &gWindows[a0->unk14]; uVar4 = a0->unk24; - switch (sub_8012AE8()) { + switch (GetMenuInput()) { case INPUT_DPAD_LEFT: uVar4 = a0->unk24 < a0->unk25 - 1 ? a0->unk24 + 1 : 0; break; @@ -1121,7 +1121,7 @@ static bool8 sub_8013DD0(unkStructFor8013AA0 *a0) { s32 iVar2; - switch (sub_8012AE8()) { + switch (GetMenuInput()) { case INPUT_DPAD_UP: if (a0->unk0 == a0->unkC) { PlayMenuSoundEffect(2); diff --git a/src/naming_screen.c b/src/naming_screen.c index b40c636f0..bd786fa31 100644 --- a/src/naming_screen.c +++ b/src/naming_screen.c @@ -1,5 +1,6 @@ #include "global.h" #include "globaldata.h" +#include "naming_screen.h" #include "code_800D090.h" #include "code_80118A4.h" #include "code_803D0D8.h" @@ -14,43 +15,64 @@ #include "text_util.h" #include "constants/input.h" -struct unkStruct_203B1F8 +#define MAX_TEXT_SIZE 54 + +enum { - // size: 0x4B4 - u32 menuAction; - MenuStruct unk4; + MODE_OVR, + MODE_INS, +}; + +struct NamingScreen +{ + // size: 0x198 + u32 type; + bool8 isPassword; + // Note: These had to be declared like these, because SpriteOAM is aligned by 4 and these aren't. Makes you think if SpriteOAM is actually a struct, and not just an array of 4 u16s. + u16 spriteLetterCursor[4]; + u16 spriteInputCursor[4]; + u8 letterCursorFrames; + u8 inputCursorFrames; + u8 insOvr; + u8 inputCursorArrId; // Always 0 + u8 inputCursorPosition; + u8 maxLetters; + u8 letterCursorPos; + u16 letterTotalWidths[MAX_TEXT_SIZE]; + s16 letterWidths[MAX_TEXT_SIZE]; + u8 *textPtr; // Points to the field below. A bit over complicated in my opinion... + u8 text[MAX_TEXT_SIZE]; + u8 *defaultText; WindowTemplates windows; - u8 buffer[0x400]; }; -EWRAM_INIT struct unkStruct_203B1F8 *gUnknown_203B1F8 = {NULL}; +static EWRAM_INIT struct NamingScreen *sNamingScreen = NULL; -const WindowTemplate gUnknown_80DAF70 = { - 0x00, - 0x03, - 0x00, 0x00, - 0x00, 0x00, - 0x00, 0x00, - NULL +static s32 GetEnteredNameLength(void); +static void UpdateInputWindow(bool8); +static void UpdateNameWindow(void); +static void UpdateLetterWidths(void); +static void SetLetterCursorSpritePosition(void); +static void HandleInputCursor(void); +static void UpdatePassword1Window(u8 *text, s32 windowId, s32 _yAdd); +static void UpdatePassword2Window(u8 *text, s32 windowId, s32 _yAdd); +s32 GetMaxPokeNameWidth(void); +s32 GetStrWidth(u8 *buffer, s32 size); +static u32 HandleAPress(void); +static bool8 HandleBPress(void); + +enum +{ + NAMING_SELF, + NAMING_TEAM, + NAMING_POKEMON, + NAMING_PARTNER, + NAMING_PASSWORD1, + NAMING_PASSWORD2, }; -const WindowTemplate gUnknown_80DAF88 = { - 0x00, - 0x03, - 0x02, 0x02, - 0x1A, 0x0c, - 0x0c, 0x00, - NULL -}; - -const WindowTemplate gUnknown_80DAFA0 = { - 0x00, - 0x03, - 0x16, 0x0F, - 0x06, 0x03, - 0x03, 0x00, - NULL -}; +#define NAMING_WINDOW_INPUT 0 +#define NAMING_WINDOW_NAME 1 struct LayoutInfo { @@ -64,7 +86,6 @@ struct LayoutInfo s32 letter; }; -UNUSED static const char sPksDir[] = "pksdir0"; static const DungeonPos gUnknown_80DAFC0[] = { {3, 0xD}, @@ -295,114 +316,6 @@ static const WindowTemplate sPasswordNameWindowTemplate = { .header = NULL, }; -bool8 sub_8015080(u8 *buffer, const MenuItem *menuItems) -{ - s32 index; - - gUnknown_203B1F8 = MemoryAlloc(sizeof(struct unkStruct_203B1F8), 8); - gUnknown_203B1F8->menuAction = 0; - - for(index = 0; index < 4; index++) - { - gUnknown_203B1F8->windows.id[index] = gUnknown_80DAF70; - } - - gUnknown_203B1F8->windows.id[0] = gUnknown_80DAF88; - gUnknown_203B1F8->windows.id[2] = gUnknown_80DAFA0; - sub_8012CAC(&gUnknown_203B1F8->windows.id[2], menuItems); - ResetUnusedInputStruct(); - ShowWindows(&gUnknown_203B1F8->windows, 1, 1); - sub_80073B8(0); - FormatString(buffer, gUnknown_203B1F8->buffer, gUnknown_203B1F8->buffer + 0x400, 0); - PrintStringOnWindow(4, 4, gUnknown_203B1F8->buffer, 0, 0); - sub_80073E0(0); - sub_8012D60(&gUnknown_203B1F8->unk4, menuItems, 0, 0, -1, 2); - return TRUE; -} - -u32 sub_801516C(void) -{ - if(!sub_8012FD8(&gUnknown_203B1F8->unk4)) { - sub_8013114(&gUnknown_203B1F8->unk4, &gUnknown_203B1F8->menuAction); - return 3; - } - else { - return 0; - } -} - -u32 sub_8015198(void) -{ - return gUnknown_203B1F8->menuAction; -} - -void sub_80151A4(void) -{ - if(gUnknown_203B1F8) { - MemoryFree(gUnknown_203B1F8); - gUnknown_203B1F8 = NULL; - } -} - -#define MAX_TEXT_SIZE 54 - -enum -{ - MODE_OVR, - MODE_INS, -}; - -struct NamingScreen -{ - // size: 0x198 - u32 type; - bool8 isPassword; - // Note: These had to be declared like these, because SpriteOAM is aligned by 4 and these aren't. Makes you think if SpriteOAM is actually a struct, and not just an array of 4 u16s. - u16 spriteLetterCursor[4]; - u16 spriteInputCursor[4]; - u8 letterCursorFrames; - u8 inputCursorFrames; - u8 insOvr; - u8 inputCursorArrId; // Always 0 - u8 inputCursorPosition; - u8 maxLetters; - u8 letterCursorPos; - u16 letterTotalWidths[MAX_TEXT_SIZE]; - s16 letterWidths[MAX_TEXT_SIZE]; - u8 *textPtr; // Points to the field below. A bit over complicated in my opinion... - u8 text[MAX_TEXT_SIZE]; - u8 *defaultText; - WindowTemplates windows; -}; - -static EWRAM_INIT struct NamingScreen *sNamingScreen = NULL; - -static s32 GetEnteredNameLength(void); -static void UpdateInputWindow(bool8); -static void UpdateNameWindow(void); -static void UpdateLetterWidths(void); -static void SetLetterCursorSpritePosition(void); -static void HandleInputCursor(void); -static void UpdatePassword1Window(u8 *text, s32 windowId, s32 _yAdd); -static void UpdatePassword2Window(u8 *text, s32 windowId, s32 _yAdd); -s32 GetMaxPokeNameWidth(void); -s32 GetStrWidth(u8 *buffer, s32 size); -static u32 HandleAPress(void); -static bool8 HandleBPress(void); - -enum -{ - NAMING_SELF, - NAMING_TEAM, - NAMING_POKEMON, - NAMING_PARTNER, - NAMING_PASSWORD1, - NAMING_PASSWORD2, -}; - -#define NAMING_WINDOW_INPUT 0 -#define NAMING_WINDOW_NAME 1 - u32 NamingScreen_Init(u32 type, u8 *defaultText) { SpriteOAM *sprite; @@ -426,9 +339,13 @@ u32 NamingScreen_Init(u32 type, u8 *defaultText) sNamingScreen->isPassword = TRUE; sNamingScreen->maxLetters = 0x18; break; - case NAMING_SELF: case NAMING_TEAM: + sNamingScreen->inputCursorPosition = 6; + sNamingScreen->maxLetters = TEAM_NAME_LENGTH; + break; + case NAMING_SELF: case NAMING_PARTNER: + case NAMING_POKEMON: default: sNamingScreen->inputCursorPosition = 6; sNamingScreen->maxLetters = POKEMON_NAME_LENGTH; @@ -535,7 +452,7 @@ u32 NamingScreen_HandleInput(void) AddSprite((SpriteOAM *) &sNamingScreen->spriteInputCursor, 0x100, NULL, NULL); } - switch (sub_8012AE8()) { + switch (GetMenuInput()) { case INPUT_L_BUTTON: if (sNamingScreen->letterCursorPos == 0) { PlayMenuSoundEffect(2); @@ -706,7 +623,7 @@ static void HandleInputCursor(void) Window *window = &gWindows[0]; u32 newPosition; - switch (sub_8012AE8()) { + switch (GetMenuInput()) { case INPUT_DPAD_UP: newPosition = sLayoutInfo[sNamingScreen->inputCursorArrId][sNamingScreen->inputCursorPosition].upPos; break; diff --git a/src/options_menu2.c b/src/options_menu2.c index 7f7d87294..e14b8e94e 100644 --- a/src/options_menu2.c +++ b/src/options_menu2.c @@ -42,7 +42,7 @@ u32 sub_801E218(void) flag = FALSE; - switch (sub_8012AE8()) { + switch (GetMenuInput()) { case INPUT_B_BUTTON: PlayMenuSoundEffect(1); return 2; diff --git a/src/other_menus2.c b/src/other_menus2.c index 2c5c17b30..503b64e87 100644 --- a/src/other_menus2.c +++ b/src/other_menus2.c @@ -9,6 +9,7 @@ #include "other_menus2.h" #include "pokemon.h" #include "save.h" +#include "menu_input.h" #include "structs/str_dungeon.h" typedef struct unkStruct_800D670 @@ -41,7 +42,6 @@ extern u8 sub_800D600(void); extern void sub_800D670(s32 idx, void *dst, s32 size); extern void sub_800D68C(u32); void sub_800D414(void); -s32 sub_8012AE8(void); // Inline needed for 8-bit return cast static inline bool8 IsNotChunsoft(unkStruct_800D670 *unk) @@ -118,7 +118,7 @@ s32 sub_8037B28(s32 mode) while (TRUE) { for (i = 0; i < 1; i++) { sub_80373C4(); - switch (sub_8012AE8()) { + switch (GetMenuInput()) { case 2: case 3: sub_800D520(); diff --git a/src/rescue_password_menu.c b/src/rescue_password_menu.c index dfc284841..fcda9482d 100644 --- a/src/rescue_password_menu.c +++ b/src/rescue_password_menu.c @@ -15,10 +15,7 @@ #include "sprite.h" #include "string_format.h" #include "text_1.h" - -u32 NamingScreen_Init(u32 type, u8 *defaultText); -u32 NamingScreen_HandleInput(void); -void NamingScreen_Free(void); +#include "naming_screen.h" #define RESCUE_PASSWORD_SIZE 0x36 diff --git a/src/string_format.c b/src/string_format.c index 4161f829d..3abb929ac 100644 --- a/src/string_format.c +++ b/src/string_format.c @@ -46,7 +46,7 @@ void sub_8014114(void) { void nullsub_201(void) {} u32 sub_8014128(void) { - if(sub_8012AE8() == INPUT_B_BUTTON) return 0; + if(GetMenuInput() == INPUT_B_BUTTON) return 0; else return 1; } diff --git a/src/thank_you_wonder_mail.c b/src/thank_you_wonder_mail.c index 8808a4ae6..c30835543 100644 --- a/src/thank_you_wonder_mail.c +++ b/src/thank_you_wonder_mail.c @@ -24,10 +24,7 @@ #include "thank_you_wonder_mail.h" #include "wonder_mail_4.h" #include "wonder_mail_5.h" - -u32 NamingScreen_Init(u32 type, u8 *defaultText); -u32 NamingScreen_HandleInput(void); -void NamingScreen_Free(void); +#include "naming_screen.h" static EWRAM_INIT WonderMailStruct_203B2C4 *sUnknown_203B2C4 = {NULL}; diff --git a/src/wonder_mail.c b/src/wonder_mail.c index 9c78e4c7d..8e63b3793 100644 --- a/src/wonder_mail.c +++ b/src/wonder_mail.c @@ -22,10 +22,7 @@ #include "wonder_mail.h" #include "wonder_mail_4.h" #include "wonder_mail_5.h" - -u32 NamingScreen_Init(u32 type, u8 *defaultText); -u32 NamingScreen_HandleInput(void); -void NamingScreen_Free(void); +#include "naming_screen.h" static EWRAM_INIT WonderMailStruct_203B2C0 *sUnknown_203B2C0 = {NULL}; diff --git a/src/wonder_mail_main_menu.c b/src/wonder_mail_main_menu.c index c3ae9045e..03c88a914 100644 --- a/src/wonder_mail_main_menu.c +++ b/src/wonder_mail_main_menu.c @@ -20,10 +20,7 @@ #include "wonder_mail_5.h" #include "wonder_mail_802D098.h" #include "wonder_mail_main_menu.h" - -u32 NamingScreen_Init(u32 type, u8 *defaultText); -u32 NamingScreen_HandleInput(void); -void NamingScreen_Free(void); +#include "naming_screen.h" #define SELECT_WONDER_MAIL_MODE_MAIN_SCREEN 0 #define SEND_WONDER_MAIL_MAIN_SCREEN 1 diff --git a/sym_ewram_init.txt b/sym_ewram_init.txt index 727e7a283..aa5664ca0 100644 --- a/sym_ewram_init.txt +++ b/sym_ewram_init.txt @@ -24,6 +24,7 @@ .include "src/quick_save_read.o" .include "src/quick_save_write.o" .include "src/string_format.o" +.include "src/code_8015080.o" .include "src/naming_screen.o" .include "src/code_801602C.o" .include "src/felicity_bank.o"