From 86173a8955e51114acc3fd8e4977c99cc093b42f Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Mon, 2 Jun 2025 20:18:14 +0200 Subject: [PATCH 1/7] Start documenting Naming Screen --- include/code_8012A18_1.h | 6 +- include/string_format.h | 1 - include/structs/str_text.h | 2 +- ld_script.ld | 1 - src/code_8012A18_1.c | 100 -------- src/code_8015080.c | 475 ++++++++++++++++++++---------------- src/code_801602C.c | 20 +- src/code_809A560.c | 14 +- src/friend_rescue.c | 22 +- src/menu_input.c | 6 +- src/pokemon_mail.c | 4 +- src/rescue_password_menu.c | 22 +- src/text_1.c | 2 +- src/text_2.c | 2 +- src/text_3.c | 4 +- src/thank_you_wonder_mail.c | 14 +- src/wonder_mail.c | 14 +- src/wonder_mail_main_menu.c | 14 +- sym_ewram_init.txt | 1 - 19 files changed, 356 insertions(+), 368 deletions(-) delete mode 100644 src/code_8012A18_1.c diff --git a/include/code_8012A18_1.h b/include/code_8012A18_1.h index 99f960677..68df79c40 100644 --- a/include/code_8012A18_1.h +++ b/include/code_8012A18_1.h @@ -1,7 +1,7 @@ #ifndef GUARD_CODE_8012A18_1_H #define GUARD_CODE_8012A18_1_H -s32 sub_8015FEC(u8 *buffer, s32 size); -s32 sub_8016028(void); +s32 GetStrWidth(u8 *buffer, s32 size); +s32 GetMaxPokeNameWidth(void); -#endif // GUARD_CODE_8012A18_1_H \ No newline at end of file +#endif // GUARD_CODE_8012A18_1_H diff --git a/include/string_format.h b/include/string_format.h index 1e4b97720..3e25e36dc 100644 --- a/include/string_format.h +++ b/include/string_format.h @@ -12,7 +12,6 @@ void sub_80140DC(void); void sub_8014114(void); s32 sub_80144A4(s32 *); -u32 sub_80151C0(u32, u8 *); u32 sub_80154F0(void); void sub_80155F0(void); diff --git a/include/structs/str_text.h b/include/structs/str_text.h index 3f22ef2ba..ea1f5e1b0 100644 --- a/include/structs/str_text.h +++ b/include/structs/str_text.h @@ -8,7 +8,7 @@ typedef struct unkChar { const u16 *unk0; u16 unk4; - s16 unk6; + s16 width; u8 unk8; u8 fill9; u8 unkA; diff --git a/ld_script.ld b/ld_script.ld index 99e396318..d78fbe146 100755 --- a/ld_script.ld +++ b/ld_script.ld @@ -102,7 +102,6 @@ SECTIONS { src/menu_input.o(.text); src/string_format.o(.text); src/code_8015080.o(.text); - src/code_8012A18_1.o(.text); src/code_801602C.o(.text); src/felicity_bank.o(.text); src/kangaskhan_storage1.o(.text); diff --git a/src/code_8012A18_1.c b/src/code_8012A18_1.c deleted file mode 100644 index 7c8cfca35..000000000 --- a/src/code_8012A18_1.c +++ /dev/null @@ -1,100 +0,0 @@ -#include "global.h" -#include "structs/sprite_oam.h" -#include "code_8012A18_1.h" -#include "text_2.h" -#include "text_util.h" - -struct unkStruct_203B1FC -{ - // size: 0x198 - u32 unk0; - u8 unk4; - SpriteOAM unk6; - SpriteOAM unkE; - u8 unk16; - u8 unk17; - u8 unk18; - u8 unk1B; - u8 unk1C; - s16 unk1E[1]; - u8 fill20[0x8A - 0x20]; - s16 unk8A[2]; - u8 fill8E[0xF8 - 0x8E]; - u8 *unkF8; - u8 unkFC[54]; -}; - -EWRAM_INIT struct unkStruct_203B1FC *gUnknown_203B1FC = NULL; - -s32 sub_8015F44(void) -{ - s32 index; - s32 counter; - index = 0; - - if (index < gUnknown_203B1FC->unk1B && gUnknown_203B1FC->unkF8[0] != 0) { - index = 1; - counter = 1; - while (TRUE) { - if (counter >= gUnknown_203B1FC->unk1B) - return index; - if (gUnknown_203B1FC->unkF8[counter] == 0) - return index; - index = counter + 1; - counter = index; - } - } - return index; -} - -void sub_8015F84(void) -{ - u32 uVar2; - const unkChar *puVar3; - s32 index; - s32 total; - - total = 0; - for(index = 0; index < gUnknown_203B1FC->unk1B; index++) - { - gUnknown_203B1FC->unk1E[index] = total; - if (gUnknown_203B1FC->unkF8[index] == 0) { - gUnknown_203B1FC->unk8A[index] = 8; - return; - } - uVar2 = ReturnIntFromChar2(gUnknown_203B1FC->unkF8[index]); - puVar3 = GetCharacter(uVar2); - gUnknown_203B1FC->unk8A[index] = puVar3->unk6; - total += puVar3->unk6; - } -} - -// TODO: Above code is in code_80130A8.s - -s32 sub_8015FEC(u8 *buffer, s32 size) -{ - const unkChar *iVar2; - s32 currLength; - s32 length; - u8 *bufferPtr; - - length = 0; - currLength = 0; - - if (currLength < size && *buffer != '\0') { - bufferPtr = buffer; // Had to have another variable to match.. - do { - iVar2 = GetCharacter(ReturnIntFromChar2(*bufferPtr)); - length += iVar2->unk6; - bufferPtr++; - currLength++; - } while (currLength < size && *bufferPtr != '\0'); - } - - return length; -} - -s32 sub_8016028(void) -{ - return 60; -} diff --git a/src/code_8015080.c b/src/code_8015080.c index 5be6ad797..cb01d4283 100644 --- a/src/code_8015080.c +++ b/src/code_8015080.c @@ -11,6 +11,8 @@ #include "text_1.h" #include "text_2.h" #include "text_3.h" +#include "text_util.h" +#include "constants/input.h" struct unkStruct_203B1F8 { @@ -337,123 +339,136 @@ void sub_80151A4(void) } } -struct unkStruct_203B1FC +#define MAX_TEXT_SIZE 54 + +struct NamingScreen { // size: 0x198 - u32 unk0; + u32 type; u8 unk4; // 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 sprite1Attribs[4]; u16 sprite2Attribs[4]; - u8 unk16; - u8 unk17; + u8 letterCursorFrames; + u8 inputCursorFrames; u8 unk18; u8 unk19; - u8 unk1A; - u8 unk1B; - u8 unk1C; - u16 unk1E[54]; - s16 unk8A[54]; - u8 *unkF8; - u8 unkFC[56]; - u8 *unk134; + 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; }; -extern struct unkStruct_203B1FC *gUnknown_203B1FC; -s32 sub_8015F44(void); +static EWRAM_INIT struct NamingScreen *sNamingScreen = NULL; + +static s32 GetEnteredNameLength(void); void sub_8015A08(u32); -void sub_8015C1C(void); +static void UpdateNameWindow(void); void sub_8015F84(); -void sub_80157D8(void); -void sub_80158BC(void); -void sub_8015E10(u8 *a0, s32 a1, s32 _a2); -void sub_8015EB4(u8 *a0, s32 a1, s32 _a2); -s32 sub_8016028(void); -s32 sub_8015FEC(u8 *buffer, s32 size); -u32 sub_801560C(void); -bool8 sub_8015748(void); +static void SetLetterCursorSpritePosition(void); +static void HandleInputCursor(void); +static void sub_8015E10(u8 *a0, s32 a1, s32 _a2); +static void sub_8015EB4(u8 *a0, s32 a1, s32 _a2); +s32 GetMaxPokeNameWidth(void); +s32 GetStrWidth(u8 *buffer, s32 size); +static u32 HandleAPress(void); +static bool8 HandleBPress(void); -u32 sub_80151C0(u32 r0, u8 *buffer) +enum +{ + NAMING_SELF, + NAMING_TEAM, + NAMING_POKEMON, + NAMING_PARTNER, + NAMING_PASSWORD1, + NAMING_PASSWORD2, +}; + +u32 NamingScreen_Init(u32 type, u8 *defaultText) { SpriteOAM *sprite; s32 index; s32 i; - gUnknown_203B1FC = MemoryAlloc(sizeof(*gUnknown_203B1FC), 8); - gUnknown_203B1FC->unk0 = r0; - gUnknown_203B1FC->unk19 = 0; - gUnknown_203B1FC->unk18 = 0; - gUnknown_203B1FC->unk4 = 0; + sNamingScreen = MemoryAlloc(sizeof(*sNamingScreen), 8); + sNamingScreen->type = type; + sNamingScreen->unk19 = 0; + sNamingScreen->unk18 = 0; + sNamingScreen->unk4 = 0; - switch(gUnknown_203B1FC->unk0) { - case 4: - gUnknown_203B1FC->unk1A = 9; - gUnknown_203B1FC->unk4 = 1; - gUnknown_203B1FC->unk1B = 0x36; + switch (sNamingScreen->type) { + case NAMING_PASSWORD1: + sNamingScreen->inputCursorPosition = 9; + sNamingScreen->unk4 = 1; + sNamingScreen->maxLetters = 0x36; break; - case 5: - gUnknown_203B1FC->unk1A = 9; - gUnknown_203B1FC->unk4 = 1; - gUnknown_203B1FC->unk1B = 0x18; + case NAMING_PASSWORD2: + sNamingScreen->inputCursorPosition = 9; + sNamingScreen->unk4 = 1; + sNamingScreen->maxLetters = 0x18; break; - case 0: - case 1: - case 3: + case NAMING_SELF: + case NAMING_TEAM: + case NAMING_PARTNER: default: - gUnknown_203B1FC->unk1A = 6; - gUnknown_203B1FC->unk1B = 0xA; + sNamingScreen->inputCursorPosition = 6; + sNamingScreen->maxLetters = POKEMON_NAME_LENGTH; break; } - gUnknown_203B1FC->unk134 = buffer; - gUnknown_203B1FC->unkF8 = gUnknown_203B1FC->unkFC; + sNamingScreen->defaultText = defaultText; + sNamingScreen->textPtr = sNamingScreen->text; - for (i = 0; i < 0x36; i++) { - gUnknown_203B1FC->unkF8[i] = 0; + for (i = 0; i < MAX_TEXT_SIZE; i++) { + sNamingScreen->textPtr[i] = '\0'; } - MemoryCopy8(gUnknown_203B1FC->unkF8, gUnknown_203B1FC->unk134, gUnknown_203B1FC->unk1B); + MemoryCopy8(sNamingScreen->textPtr, sNamingScreen->defaultText, sNamingScreen->maxLetters); - for (i = 0; i < gUnknown_203B1FC->unk1B; i++) { - if (gUnknown_203B1FC->unkF8[i] == 0) { + for (i = 0; i < sNamingScreen->maxLetters; i++) { + if (sNamingScreen->textPtr[i] == '\0') { break; } } - for (; i < gUnknown_203B1FC->unk1B; i++) { - gUnknown_203B1FC->unkF8[i] = 0; + for (; i < sNamingScreen->maxLetters; i++) { + sNamingScreen->textPtr[i] = '\0'; } - gUnknown_203B1FC->unk1C = sub_8015F44(); - if (gUnknown_203B1FC->unk1C == gUnknown_203B1FC->unk1B) { - gUnknown_203B1FC->unk1C--; + sNamingScreen->letterCursorPos = GetEnteredNameLength(); + if (sNamingScreen->letterCursorPos == sNamingScreen->maxLetters) { + sNamingScreen->letterCursorPos--; } - SpriteSetAffine1((SpriteOAM *) &gUnknown_203B1FC->sprite1Attribs, 0); - SpriteSetAffine2((SpriteOAM *) &gUnknown_203B1FC->sprite1Attribs, 0); - SpriteSetObjMode((SpriteOAM *) &gUnknown_203B1FC->sprite1Attribs, 0); - SpriteSetMosaic((SpriteOAM *) &gUnknown_203B1FC->sprite1Attribs, 0); - SpriteSetBpp((SpriteOAM *) &gUnknown_203B1FC->sprite1Attribs, 0); - SpriteSetPriority((SpriteOAM *) &gUnknown_203B1FC->sprite1Attribs, 0); - SpriteSetPalNum((SpriteOAM *) &gUnknown_203B1FC->sprite1Attribs, 15); - SpriteSetX((SpriteOAM *) &gUnknown_203B1FC->sprite1Attribs, DISPLAY_WIDTH); - SpriteSetY((SpriteOAM *) &gUnknown_203B1FC->sprite1Attribs, DISPLAY_WIDTH); + SpriteSetAffine1((SpriteOAM *) &sNamingScreen->sprite1Attribs, 0); + SpriteSetAffine2((SpriteOAM *) &sNamingScreen->sprite1Attribs, 0); + SpriteSetObjMode((SpriteOAM *) &sNamingScreen->sprite1Attribs, 0); + SpriteSetMosaic((SpriteOAM *) &sNamingScreen->sprite1Attribs, 0); + SpriteSetBpp((SpriteOAM *) &sNamingScreen->sprite1Attribs, 0); + SpriteSetPriority((SpriteOAM *) &sNamingScreen->sprite1Attribs, 0); + SpriteSetPalNum((SpriteOAM *) &sNamingScreen->sprite1Attribs, 15); + SpriteSetX((SpriteOAM *) &sNamingScreen->sprite1Attribs, DISPLAY_WIDTH); + SpriteSetY((SpriteOAM *) &sNamingScreen->sprite1Attribs, DISPLAY_WIDTH); - if (gUnknown_203B1FC->unk4 != 0) { - SpriteSetMatrixNum((SpriteOAM *) &gUnknown_203B1FC->sprite1Attribs, 0); - SpriteSetTileNum((SpriteOAM *) &gUnknown_203B1FC->sprite1Attribs, 0x3F6); - SpriteSetSize((SpriteOAM *) &gUnknown_203B1FC->sprite1Attribs, 0); - SpriteSetShape((SpriteOAM *) &gUnknown_203B1FC->sprite1Attribs, 1); + if (sNamingScreen->unk4 != 0) { + SpriteSetMatrixNum((SpriteOAM *) &sNamingScreen->sprite1Attribs, 0); + SpriteSetTileNum((SpriteOAM *) &sNamingScreen->sprite1Attribs, 0x3F6); + SpriteSetSize((SpriteOAM *) &sNamingScreen->sprite1Attribs, 0); + SpriteSetShape((SpriteOAM *) &sNamingScreen->sprite1Attribs, 1); } else { - SpriteSetMatrixNum((SpriteOAM *) &gUnknown_203B1FC->sprite1Attribs, 16); - SpriteSetTileNum((SpriteOAM *) &gUnknown_203B1FC->sprite1Attribs, 0x3F0); - SpriteSetSize((SpriteOAM *) &gUnknown_203B1FC->sprite1Attribs, 0); - SpriteSetShape((SpriteOAM *) &gUnknown_203B1FC->sprite1Attribs, 1); + SpriteSetMatrixNum((SpriteOAM *) &sNamingScreen->sprite1Attribs, 16); + SpriteSetTileNum((SpriteOAM *) &sNamingScreen->sprite1Attribs, 0x3F0); + SpriteSetSize((SpriteOAM *) &sNamingScreen->sprite1Attribs, 0); + SpriteSetShape((SpriteOAM *) &sNamingScreen->sprite1Attribs, 1); } - gUnknown_203B1FC->unk16 = 4; + sNamingScreen->letterCursorFrames = 4; - sprite = (SpriteOAM *) &gUnknown_203B1FC->sprite2Attribs; + sprite = (SpriteOAM *) &sNamingScreen->sprite2Attribs; SpriteSetAffine1(sprite, 0); SpriteSetAffine2(sprite, 0); @@ -469,134 +484,134 @@ u32 sub_80151C0(u32 r0, u8 *buffer) SpriteSetX(sprite, DISPLAY_WIDTH); SpriteSetY(sprite, DISPLAY_WIDTH); - gUnknown_203B1FC->unk17 = 0; + sNamingScreen->inputCursorFrames = 0; for (index = 0; index < 4; index++) { - gUnknown_203B1FC->windows.id[index] = gUnknown_80DB538; + sNamingScreen->windows.id[index] = gUnknown_80DB538; } - if(gUnknown_203B1FC->unk4 != 0) { - gUnknown_203B1FC->windows.id[1] = gUnknown_80DB580; + if(sNamingScreen->unk4 != 0) { + sNamingScreen->windows.id[1] = gUnknown_80DB580; } else { - gUnknown_203B1FC->windows.id[1] = gUnknown_80DB568; + sNamingScreen->windows.id[1] = gUnknown_80DB568; } - gUnknown_203B1FC->windows.id[0] = gUnknown_80DB550; + sNamingScreen->windows.id[0] = gUnknown_80DB550; ResetUnusedInputStruct(); - ShowWindows(&gUnknown_203B1FC->windows, 1, 1); + ShowWindows(&sNamingScreen->windows, 1, 1); sub_8015A08(1); - sub_8015C1C(); + UpdateNameWindow(); sub_8015F84(); return 1; } -u32 sub_80154F0(void) +u32 NamingScreen_HandleInput(void) { - gUnknown_203B1FC->unk16++; - sub_80157D8(); - if (gUnknown_203B1FC->unk16 & 8) { - AddSprite((SpriteOAM *) &gUnknown_203B1FC->sprite1Attribs, 0x100, NULL, NULL); + sNamingScreen->letterCursorFrames++; + SetLetterCursorSpritePosition(); + if (sNamingScreen->letterCursorFrames & 8) { + AddSprite((SpriteOAM *) &sNamingScreen->sprite1Attribs, 0x100, NULL, NULL); } - gUnknown_203B1FC->unk17++; - sub_80158BC(); - if (gUnknown_203B1FC->unk17 & 8) { - AddSprite((SpriteOAM *) &gUnknown_203B1FC->sprite2Attribs, 0x100, NULL, NULL); + sNamingScreen->inputCursorFrames++; + HandleInputCursor(); + if (sNamingScreen->inputCursorFrames & 8) { + AddSprite((SpriteOAM *) &sNamingScreen->sprite2Attribs, 0x100, NULL, NULL); } switch (sub_8012AE8()) { - case 5: - if (gUnknown_203B1FC->unk1C == 0) { + case INPUT_L_BUTTON: + if (sNamingScreen->letterCursorPos == 0) { PlayMenuSoundEffect(2); } else { - gUnknown_203B1FC->unk1C--; + sNamingScreen->letterCursorPos--; PlayMenuSoundEffect(3); } break; - case 6: - if (gUnknown_203B1FC->unk1C != gUnknown_203B1FC->unk1B - 1 && gUnknown_203B1FC->unk1C < sub_8015F44()) { - gUnknown_203B1FC->unk1C++; + case INPUT_R_BUTTON: + if (sNamingScreen->letterCursorPos != sNamingScreen->maxLetters - 1 && sNamingScreen->letterCursorPos < GetEnteredNameLength()) { + sNamingScreen->letterCursorPos++; PlayMenuSoundEffect(3); } else { PlayMenuSoundEffect(2); } break; - case 1: - return sub_801560C(); - case 2: - if (sub_8015748()) { + case INPUT_A_BUTTON: + return HandleAPress(); + case INPUT_B_BUTTON: + if (HandleBPress()) { return 2; } break; - case 4: + case INPUT_START_BUTTON: PlayMenuSoundEffect(3); - gUnknown_203B1FC->unk1A = 5; + sNamingScreen->inputCursorPosition = 5; break; } return 0; } -void sub_80155F0(void) +void NamingScreen_Free(void) { - if (gUnknown_203B1FC != NULL) { - MemoryFree(gUnknown_203B1FC); - gUnknown_203B1FC = NULL; + if (sNamingScreen != NULL) { + MemoryFree(sNamingScreen); + sNamingScreen = NULL; } } -u32 sub_801560C(void) +static u32 HandleAPress(void) { - s32 var = gUnknown_80DB0F8[gUnknown_203B1FC->unk19][gUnknown_203B1FC->unk1A].unk8; + s32 var = gUnknown_80DB0F8[sNamingScreen->unk19][sNamingScreen->inputCursorPosition].unk8; switch (var) { case 0x107: - gUnknown_203B1FC->unk18 = (gUnknown_203B1FC->unk18 == 0); + sNamingScreen->unk18 = (sNamingScreen->unk18 == 0); PlayMenuSoundEffect(4); sub_8015A08(0); break; case 0x105: - if (sub_8015748()) { + if (HandleBPress()) { return 2; } break; case 0x106: - if (sub_8015F44() == 0 || (gUnknown_203B1FC->unk4 != 0 && sub_8015F44() != gUnknown_203B1FC->unk1B)) { + if (GetEnteredNameLength() == 0 || (sNamingScreen->unk4 != 0 && GetEnteredNameLength() != sNamingScreen->maxLetters)) { PlayMenuSoundEffect(2); } else { PlayMenuSoundEffect(0); - MemoryCopy8(gUnknown_203B1FC->unk134, gUnknown_203B1FC->unkF8, gUnknown_203B1FC->unk1B); + MemoryCopy8(sNamingScreen->defaultText, sNamingScreen->textPtr, sNamingScreen->maxLetters); return 3; } break; default: - if (gUnknown_203B1FC->unk4 != 0 && sub_803D0F0(var) == 0xFF) { + if (sNamingScreen->unk4 != 0 && sub_803D0F0(var) == 0xFF) { PlayMenuSoundEffect(2); } else { - if (gUnknown_203B1FC->unk18 == 1) { + if (sNamingScreen->unk18 == 1) { s32 i; - for (i = gUnknown_203B1FC->unk1B - 2; i >= gUnknown_203B1FC->unk1C; i--) { - u8 *ptr = &gUnknown_203B1FC->unkF8[i]; + for (i = sNamingScreen->maxLetters - 2; i >= sNamingScreen->letterCursorPos; i--) { + u8 *ptr = &sNamingScreen->textPtr[i]; ptr[1] = ptr[0]; } } - gUnknown_203B1FC->unkF8[gUnknown_203B1FC->unk1C] = var; - if (gUnknown_203B1FC->unk1C < gUnknown_203B1FC->unk1B - 1) { - gUnknown_203B1FC->unk1C++; + sNamingScreen->textPtr[sNamingScreen->letterCursorPos] = var; + if (sNamingScreen->letterCursorPos < sNamingScreen->maxLetters - 1) { + sNamingScreen->letterCursorPos++; } else { - gUnknown_203B1FC->unk1A = 5; + sNamingScreen->inputCursorPosition = 5; } PlayMenuSoundEffect(0); - sub_8015C1C(); + UpdateNameWindow(); sub_8015F84(); } break; @@ -605,108 +620,106 @@ u32 sub_801560C(void) return 0; } -bool8 sub_8015748(void) +bool8 HandleBPress(void) { - u32 val = gUnknown_203B1FC->unkF8[gUnknown_203B1FC->unk1C]; - - if (val == 0) { - if (gUnknown_203B1FC->unk1C == 0) { + if (sNamingScreen->textPtr[sNamingScreen->letterCursorPos] == '\0') { + if (sNamingScreen->letterCursorPos == 0) { PlayMenuSoundEffect(2); return TRUE; } else { - gUnknown_203B1FC->unk1C--; - gUnknown_203B1FC->unkF8[gUnknown_203B1FC->unk1C] = val; + sNamingScreen->letterCursorPos--; + sNamingScreen->textPtr[sNamingScreen->letterCursorPos] = '\0'; PlayMenuSoundEffect(1); - sub_8015C1C(); + UpdateNameWindow(); sub_8015F84(); } } else { s32 i, n; - n = sub_8015F44() - 1; - for (i = gUnknown_203B1FC->unk1C; i < n; i++) { - u8 *ptr = &gUnknown_203B1FC->unkF8[i]; + n = GetEnteredNameLength() - 1; + for (i = sNamingScreen->letterCursorPos; i < n; i++) { + u8 *ptr = &sNamingScreen->textPtr[i]; ptr[0] = ptr[1]; } - gUnknown_203B1FC->unkF8[n] = 0; + sNamingScreen->textPtr[n] = 0; PlayMenuSoundEffect(1); - sub_8015C1C(); + UpdateNameWindow(); sub_8015F84(); } return FALSE; } -void sub_80157D8(void) +static void SetLetterCursorSpritePosition(void) { Window *window = &gWindows[1]; - // Note: for cases 4 and 5, the code is identical except for different position structs. - if (gUnknown_203B1FC->unk0 == 4) { + // Note: for cases NAMING_PASSWORD1 and NAMING_PASSWORD2, the code is identical except for different position structs. + if (sNamingScreen->type == NAMING_PASSWORD1) { s32 x, y; - x = gUnknown_80DAFC0[gUnknown_203B1FC->unk1C].x + (window->x * 8); - SpriteSetX((SpriteOAM *) &gUnknown_203B1FC->sprite1Attribs, x); + x = gUnknown_80DAFC0[sNamingScreen->letterCursorPos].x + (window->x * 8); + SpriteSetX((SpriteOAM *) &sNamingScreen->sprite1Attribs, x); - y = gUnknown_80DAFC0[gUnknown_203B1FC->unk1C].y + (window->y * 8) + 5; - SpriteSetY((SpriteOAM *) &gUnknown_203B1FC->sprite1Attribs, y); + y = gUnknown_80DAFC0[sNamingScreen->letterCursorPos].y + (window->y * 8) + 5; + SpriteSetY((SpriteOAM *) &sNamingScreen->sprite1Attribs, y); } - else if (gUnknown_203B1FC->unk0 == 5) { + else if (sNamingScreen->type == NAMING_PASSWORD2) { s32 x, y; - x = gUnknown_80DB098[gUnknown_203B1FC->unk1C].x + (window->x * 8); - SpriteSetX((SpriteOAM *) &gUnknown_203B1FC->sprite1Attribs, x); + x = gUnknown_80DB098[sNamingScreen->letterCursorPos].x + (window->x * 8); + SpriteSetX((SpriteOAM *) &sNamingScreen->sprite1Attribs, x); - y = gUnknown_80DB098[gUnknown_203B1FC->unk1C].y + (window->y * 8) + 5; - SpriteSetY((SpriteOAM *) &gUnknown_203B1FC->sprite1Attribs, y); + y = gUnknown_80DB098[sNamingScreen->letterCursorPos].y + (window->y * 8) + 5; + SpriteSetY((SpriteOAM *) &sNamingScreen->sprite1Attribs, y); } else { s32 x, y; - x = gUnknown_203B1FC->unk1E[gUnknown_203B1FC->unk1C] + (gUnknown_203B1FC->unk8A[gUnknown_203B1FC->unk1C] / 2) + 30 + (window->x * 8); - SpriteSetX((SpriteOAM *) &gUnknown_203B1FC->sprite1Attribs, (u16) x); + x = sNamingScreen->letterTotalWidths[sNamingScreen->letterCursorPos] + (sNamingScreen->letterWidths[sNamingScreen->letterCursorPos] / 2) + 30 + (window->x * 8); + SpriteSetX((SpriteOAM *) &sNamingScreen->sprite1Attribs, (u16) x); y = (window->y * 8) + 34; - SpriteSetY((SpriteOAM *) &gUnknown_203B1FC->sprite1Attribs, y); + SpriteSetY((SpriteOAM *) &sNamingScreen->sprite1Attribs, y); } } -void sub_80158BC(void) +static void HandleInputCursor(void) { s32 x, y; Window *window = &gWindows[0]; - u32 var; + u32 newPosition; switch (sub_8012AE8()) { - case 7: - var = gUnknown_80DB0F8[gUnknown_203B1FC->unk19][gUnknown_203B1FC->unk1A].unk0; + case INPUT_DPAD_UP: + newPosition = gUnknown_80DB0F8[sNamingScreen->unk19][sNamingScreen->inputCursorPosition].unk0; break; - case 8: - var = gUnknown_80DB0F8[gUnknown_203B1FC->unk19][gUnknown_203B1FC->unk1A].unk1; + case INPUT_DPAD_DOWN: + newPosition = gUnknown_80DB0F8[sNamingScreen->unk19][sNamingScreen->inputCursorPosition].unk1; break; - case 9: - var = gUnknown_80DB0F8[gUnknown_203B1FC->unk19][gUnknown_203B1FC->unk1A].unk2; + case INPUT_DPAD_LEFT: + newPosition = gUnknown_80DB0F8[sNamingScreen->unk19][sNamingScreen->inputCursorPosition].unk2; break; - case 10: - var = gUnknown_80DB0F8[gUnknown_203B1FC->unk19][gUnknown_203B1FC->unk1A].unk3; + case INPUT_DPAD_RIGHT: + newPosition = gUnknown_80DB0F8[sNamingScreen->unk19][sNamingScreen->inputCursorPosition].unk3; break; default: - var = gUnknown_203B1FC->unk1A; + newPosition = sNamingScreen->inputCursorPosition; break; } - if (var != gUnknown_203B1FC->unk1A) { - gUnknown_203B1FC->unk1A = var; + if (newPosition != sNamingScreen->inputCursorPosition) { + sNamingScreen->inputCursorPosition = newPosition; PlayMenuSoundEffect(3); - gUnknown_203B1FC->unk17 = 8; + sNamingScreen->inputCursorFrames = 8; } - x = gUnknown_80DB0F8[gUnknown_203B1FC->unk19][gUnknown_203B1FC->unk1A].x + (window->x * 8) - 5; - y = gUnknown_80DB0F8[gUnknown_203B1FC->unk19][gUnknown_203B1FC->unk1A].y + (window->y * 8) + 1; - SpriteSetX((SpriteOAM *) &gUnknown_203B1FC->sprite2Attribs, x); - SpriteSetY((SpriteOAM *) &gUnknown_203B1FC->sprite2Attribs, y); + x = gUnknown_80DB0F8[sNamingScreen->unk19][sNamingScreen->inputCursorPosition].x + (window->x * 8) - 5; + y = gUnknown_80DB0F8[sNamingScreen->unk19][sNamingScreen->inputCursorPosition].y + (window->y * 8) + 1; + SpriteSetX((SpriteOAM *) &sNamingScreen->sprite2Attribs, x); + SpriteSetY((SpriteOAM *) &sNamingScreen->sprite2Attribs, y); } void sub_8015A08(u32 unused) @@ -719,10 +732,10 @@ void sub_8015A08(u32 unused) CallPrepareTextbox_8008C54(0); sub_80073B8(0); - for (i = 0; (r4 = gUnknown_80DB0F8[gUnknown_203B1FC->unk19][i].unk8) != 0x109; i++) { + for (i = 0; (r4 = gUnknown_80DB0F8[sNamingScreen->unk19][i].unk8) != 0x109; i++) { s32 r5; - switch (gUnknown_80DB0F8[gUnknown_203B1FC->unk19][i].unk6) { + switch (gUnknown_80DB0F8[sNamingScreen->unk19][i].unk6) { case 1: r5 = 5; break; @@ -734,7 +747,7 @@ void sub_8015A08(u32 unused) break; default: r5 = 7; - if (gUnknown_203B1FC->unk4 != 0) { + if (sNamingScreen->unk4 != 0) { if (r4 <= 0xFF) { if (sub_803D0F0(r4) == 0xFF) { r5 = 2; @@ -749,23 +762,23 @@ void sub_8015A08(u32 unused) if (r4 != 0x108) { if (r4 == 0x107) { - if (gUnknown_203B1FC->unk18 == 0) { - PrintStringOnWindow(gUnknown_80DB0F8[gUnknown_203B1FC->unk19][i].x + 3, gUnknown_80DB0F8[gUnknown_203B1FC->unk19][i].y, _("{COLOR GREEN}OVR{RESET}"), 0, '\0'); + if (sNamingScreen->unk18 == 0) { + PrintStringOnWindow(gUnknown_80DB0F8[sNamingScreen->unk19][i].x + 3, gUnknown_80DB0F8[sNamingScreen->unk19][i].y, _("{COLOR GREEN}OVR{RESET}"), 0, '\0'); } else { - PrintStringOnWindow(gUnknown_80DB0F8[gUnknown_203B1FC->unk19][i].x + 3, gUnknown_80DB0F8[gUnknown_203B1FC->unk19][i].y, _("{COLOR YELLOW}INS{RESET}"), 0, '\0'); + PrintStringOnWindow(gUnknown_80DB0F8[sNamingScreen->unk19][i].x + 3, gUnknown_80DB0F8[sNamingScreen->unk19][i].y, _("{COLOR YELLOW}INS{RESET}"), 0, '\0'); } } else if (r4 == 0x20) { sprintfStatic(text1, _("{COLOR}%c{0x81}{0x59}"), r5); - PrintStringOnWindow(gUnknown_80DB0F8[gUnknown_203B1FC->unk19][i].x + 1, gUnknown_80DB0F8[gUnknown_203B1FC->unk19][i].y, text1, 0, '\0'); + PrintStringOnWindow(gUnknown_80DB0F8[sNamingScreen->unk19][i].x + 1, gUnknown_80DB0F8[sNamingScreen->unk19][i].y, text1, 0, '\0'); } else if (r4 > 0xFF) { sprintfStatic(text2, _("{COLOR}%c%s"), r5, gUnknown_80DB4F4[r4 & 0xFF]); - PrintStringOnWindow(gUnknown_80DB0F8[gUnknown_203B1FC->unk19][i].x + 3, gUnknown_80DB0F8[gUnknown_203B1FC->unk19][i].y, text2, 0, '\0'); + PrintStringOnWindow(gUnknown_80DB0F8[sNamingScreen->unk19][i].x + 3, gUnknown_80DB0F8[sNamingScreen->unk19][i].y, text2, 0, '\0'); } else { - sub_8012C60(gUnknown_80DB0F8[gUnknown_203B1FC->unk19][i].x, gUnknown_80DB0F8[gUnknown_203B1FC->unk19][i].y, (u8) r4, r5, 0); + sub_8012C60(gUnknown_80DB0F8[sNamingScreen->unk19][i].x, gUnknown_80DB0F8[sNamingScreen->unk19][i].y, (u8) r4, r5, 0); } } } @@ -777,13 +790,13 @@ void sub_8015A08(u32 unused) sub_80073E0(0); } -void sub_8015C1C(void) +static void UpdateNameWindow(void) { u8 text[80]; CallPrepareTextbox_8008C54(1); sub_80073B8(1); - if (gUnknown_203B1FC->unk4 != 0) { + if (sNamingScreen->unk4 != 0) { AddUnderScoreHighlight(1, 0, 0, 0xE0, 0xE); AddUnderScoreHighlight(1, 0, 0x37, 0xE0, 0xE); sub_8007A78(1, 0, 0, 0x38, 0xE); @@ -796,47 +809,47 @@ void sub_8015C1C(void) sub_8007A78(1, 0xAF, 0, 0x28, 0xE); } - switch (gUnknown_203B1FC->unk0) { - case 0: + switch (sNamingScreen->type) { + case NAMING_SELF: PrintStringOnWindow(8, 5, _("What is your name?"), 1, '\0'); break; - case 2: + case NAMING_POKEMON: PrintStringOnWindow(8, 5, _("What is this Pokémon's nickname?"), 1, '\0'); break; - case 3: + case NAMING_PARTNER: PrintStringOnWindow(8, 5, _("What is your partner's nickname?"), 1, '\0'); break; - case 1: + case NAMING_TEAM: PrintStringOnWindow(8, 5, _("What is your team's name?"), 1, '\0'); break; - case 4: + case NAMING_PASSWORD1: PrintStringOnWindow(54, 2, _("Please enter the password."), 1, '\0'); break; - case 5: + case NAMING_PASSWORD2: PrintStringOnWindow(48, 4, _("Please enter the password."), 1, '\0'); break; } - switch (gUnknown_203B1FC->unk0) { - case 4: - sub_8015E10(gUnknown_203B1FC->unkF8, 1, 0); + switch (sNamingScreen->type) { + case NAMING_PASSWORD1: + sub_8015E10(sNamingScreen->textPtr, 1, 0); break; - case 5: - sub_8015EB4(gUnknown_203B1FC->unkF8, 1, 0); + case NAMING_PASSWORD2: + sub_8015EB4(sNamingScreen->textPtr, 1, 0); break; - case 0: - case 1: - case 2: - case 3: - AddDoubleUnderScoreHighlight(1, 38, 33, sub_8016028(), 4); - if (sub_8015FEC(gUnknown_203B1FC->unkF8, gUnknown_203B1FC->unk1B) > sub_8016028()) { - sprintfStatic(text, _("{COLOR RED}%s{RESET}"), gUnknown_203B1FC->unkF8); + case NAMING_SELF: + case NAMING_TEAM: + case NAMING_POKEMON: + case NAMING_PARTNER: + AddDoubleUnderScoreHighlight(1, 38, 33, GetMaxPokeNameWidth(), 4); + if (GetStrWidth(sNamingScreen->textPtr, sNamingScreen->maxLetters) > GetMaxPokeNameWidth()) { + sprintfStatic(text, _("{COLOR RED}%s{RESET}"), sNamingScreen->textPtr); } - else if (sub_8015F44() == gUnknown_203B1FC->unk1B) { - sprintfStatic(text, _("{COLOR CYAN}%s{RESET}"), gUnknown_203B1FC->unkF8); + else if (GetEnteredNameLength() == sNamingScreen->maxLetters) { + sprintfStatic(text, _("{COLOR CYAN}%s{RESET}"), sNamingScreen->textPtr); } else { - sprintfStatic(text, _("%s"), gUnknown_203B1FC->unkF8); + sprintfStatic(text, _("%s"), sNamingScreen->textPtr); } PrintStringOnWindow(38, 22, text, 1, '\0'); break; @@ -845,7 +858,7 @@ void sub_8015C1C(void) sub_80073E0(1); } -void sub_8015E10(u8 *a0, s32 a1, s32 _a2) +static void sub_8015E10(u8 *a0, s32 a1, s32 _a2) { s32 i; s32 a2 = (s16) _a2; @@ -871,7 +884,7 @@ void sub_8015E10(u8 *a0, s32 a1, s32 _a2) } } -void sub_8015EB4(u8 *a0, s32 a1, s32 _a2) +static void sub_8015EB4(u8 *a0, s32 a1, s32 _a2) { s32 i; s32 a2 = (s16) _a2; @@ -892,3 +905,57 @@ void sub_8015EB4(u8 *a0, s32 a1, s32 _a2) sub_8012C60(gUnknown_80DB098[i].x, gUnknown_80DB098[i].y + a2, a0[i], arg3, a1); } } + +static s32 GetEnteredNameLength(void) +{ + s32 len = 0; + s32 i; + + for (i = 0; i < sNamingScreen->maxLetters; i++) { + if (sNamingScreen->textPtr[i] != '\0') { + len = i + 1; + } + else { + break; + } + } + + return len; +} + +void sub_8015F84(void) +{ + u32 uVar2; + const unkChar *puVar3; + s32 i; + s32 total = 0; + + for (i = 0; i < sNamingScreen->maxLetters; i++) { + sNamingScreen->letterTotalWidths[i] = total; + if (sNamingScreen->textPtr[i] == '\0') { + sNamingScreen->letterWidths[i] = 8; + return; + } + uVar2 = ReturnIntFromChar2(sNamingScreen->textPtr[i]); + puVar3 = GetCharacter(uVar2); + sNamingScreen->letterWidths[i] = puVar3->width; + total += puVar3->width; + } +} + +s32 GetStrWidth(u8 *buffer, s32 size) +{ + s32 i; + s32 width = 0; + + for (i = 0; i < size && buffer[i] != '\0'; i++) { + width += GetCharacter(ReturnIntFromChar2(buffer[i]))->width; + } + + return width; +} + +s32 GetMaxPokeNameWidth(void) +{ + return 60; +} diff --git a/src/code_801602C.c b/src/code_801602C.c index fe42be4b4..53cf4b8d7 100644 --- a/src/code_801602C.c +++ b/src/code_801602C.c @@ -9,6 +9,10 @@ #include "text_util.h" #include "text_1.h" +u32 NamingScreen_Init(u32 type, u8 *defaultText); +u32 NamingScreen_HandleInput(void); +void NamingScreen_Free(void); + EWRAM_INIT static struct unkStruct_203B200 *sUnknown_203B200 = {NULL}; #include "data/code_801602C.h" @@ -98,7 +102,7 @@ static void sub_8016110(void) { switch (sUnknown_203B200->state) { case CONFIRM_NAME_MENU_INIT: - sub_80151C0(sUnknown_203B200->unk4, sUnknown_203B200->pokeName); + NamingScreen_Init(sUnknown_203B200->unk4, sUnknown_203B200->pokeName); break; case CONFIRM_NAME_MENU_PROMPT: BuildConfirmNameMenu(); @@ -135,21 +139,17 @@ static void BuildConfirmNameMenu(void) static void sub_80161F8(void) { - s32 length; - s32 maxLength; - - if (sub_80154F0() != 3) + if (NamingScreen_HandleInput() != 3) return; - sub_80155F0(); - + NamingScreen_Free(); if (IsNameEmpty()) { SetConfirmNameMenuState(CONFIRM_NAME_MENU_EMPTY); } else { - length = sub_8015FEC(sUnknown_203B200->pokeName, POKEMON_NAME_LENGTH); - maxLength = sub_8016028(); // returns 60 - if (length > maxLength) + s32 width = GetStrWidth(sUnknown_203B200->pokeName, POKEMON_NAME_LENGTH); + s32 maxWidth = GetMaxPokeNameWidth(); // returns 60 + if (width > maxWidth) SetConfirmNameMenuState(CONFIRM_NAME_MENU_TOO_LONG); else SetConfirmNameMenuState(CONFIRM_NAME_MENU_PROMPT); diff --git a/src/code_809A560.c b/src/code_809A560.c index 33c4c08b5..944ea511a 100644 --- a/src/code_809A560.c +++ b/src/code_809A560.c @@ -32,6 +32,10 @@ #include "wigglytuff_shop3.h" #include "wonder_mail.h" +u32 NamingScreen_Init(u32 type, u8 *defaultText); +u32 NamingScreen_HandleInput(void); +void NamingScreen_Free(void); + IWRAM_INIT struct unkStruct_3001B64 *gUnknown_3001B64 = { NULL }; extern bool8 sub_802FCF0(void); @@ -709,7 +713,7 @@ void MakuhitaDojo_Delete(); u32 HandleMakuhitaDojoState(); s16 sub_802FED0(); u8 sub_801FB50(); -void sub_80155F0(); +void NamingScreen_Free(); s32 sub_80160D8(); void ResetTextbox_809B294(); s32 sub_801A8AC(); @@ -1385,13 +1389,13 @@ bool8 sub_809B648(void) case 6: if (gUnknown_3001B64->unk420 == 1) { ResetTextbox_809B294(); - sub_80151C0(4,gUnknown_3001B64->unk42C); + NamingScreen_Init(4,gUnknown_3001B64->unk42C); } else { - s32 var = sub_80154F0(); + s32 var = NamingScreen_HandleInput(); if (var == 3) { - sub_80155F0(); + NamingScreen_Free(); gUnknown_3001B64->unk430 = 1; return 0; } @@ -1400,7 +1404,7 @@ bool8 sub_809B648(void) if (gUnknown_3001B64->unk424 == 0) { return 1; } - sub_80155F0(); + NamingScreen_Free(); gUnknown_3001B64->unk430 = 0; return 0; } diff --git a/src/friend_rescue.c b/src/friend_rescue.c index 27cb19f60..f40c21e72 100644 --- a/src/friend_rescue.c +++ b/src/friend_rescue.c @@ -28,6 +28,10 @@ #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); + extern void SetFriendRescueMenuState(u32); extern TeamInventory *gTeamInventoryRef; @@ -688,7 +692,7 @@ void CleanFriendRescueMenu(void) sub_803084C(); sub_8031E10(); FriendList_Free(); - sub_80155F0(); + NamingScreen_Free(); sub_801CBB8(); sub_802F2C0(); sub_8030DE4(); @@ -1057,7 +1061,7 @@ void sub_8032828(void) RestoreSavedWindows(&gUnknown_203B33C->unk3BC); ResetUnusedInputStruct(); ShowWindows(NULL, TRUE, TRUE); - sub_80151C0(4, gUnknown_203B33C->passwordBuffer); + NamingScreen_Init(4, gUnknown_203B33C->passwordBuffer); break; case 0x5A: CreateMenuDialogueBoxAndPortrait(&gUnknown_80E30A4[0], 0, 6, gUnknown_80E2458, NULL, 4, 0, NULL, 0x101); @@ -1133,7 +1137,7 @@ void sub_8032828(void) RestoreSavedWindows(&gUnknown_203B33C->unk3BC); ResetUnusedInputStruct(); ShowWindows(NULL, TRUE, TRUE); - sub_80151C0(4, gUnknown_203B33C->passwordBuffer); + NamingScreen_Init(4, gUnknown_203B33C->passwordBuffer); break; case 0x66: CreateDialogueBoxAndPortrait(gUnknown_80E314C, 0, 0, 0x101); @@ -1659,7 +1663,7 @@ void sub_8033DBC(void) unkStruct_203B480 mail; unkStruct_203B480 *mail2; - return_var = sub_80154F0(); + return_var = NamingScreen_HandleInput(); MemoryFill8(&mail, 0, sizeof(unkStruct_203B480)); switch(return_var) { @@ -1717,10 +1721,10 @@ void sub_8033DBC(void) default: break; } - sub_80155F0(); + NamingScreen_Free(); break; case 2: - sub_80155F0(); + NamingScreen_Free(); ResetUnusedInputStruct(); ShowWindows(&gUnknown_203B33C->unk3BC, TRUE, TRUE); SetFriendRescueMenuState(FRIEND_RESCUE_MENU_MAIN); @@ -2555,7 +2559,7 @@ void sub_8034D74(void) unkStruct_203B480 mail; unkStruct_203B480 *mail2; - return_var = sub_80154F0(); + return_var = NamingScreen_HandleInput(); MemoryFill8(&mail, 0, sizeof(unkStruct_203B480)); switch(return_var) { @@ -2585,10 +2589,10 @@ void sub_8034D74(void) default: break; } - sub_80155F0(); + NamingScreen_Free(); break; case 2: - sub_80155F0(); + NamingScreen_Free(); ResetUnusedInputStruct(); ShowWindows(&gUnknown_203B33C->unk3BC, TRUE, TRUE); SetFriendRescueMenuState(FRIEND_RESCUE_MENU_MAIN); diff --git a/src/menu_input.c b/src/menu_input.c index 92269690e..9a0478b88 100644 --- a/src/menu_input.c +++ b/src/menu_input.c @@ -198,7 +198,7 @@ void sub_8012BC4(u32 x, u32 y, s32 n, s32 len, u32 color, u32 windowId) piVar4++; chr = ReturnIntFromChar2(iVar1 + 0x30); iVar3 = GetCharacter(chr); - total_x += iVar3->unk6; + total_x += iVar3->width; xxx_call_draw_char(x - total_x, y, chr, color, windowId); counter++; if (counter >= len) @@ -216,8 +216,8 @@ void sub_8012C60(u32 x, u32 y, u32 a2, u32 color, u32 a4) uVar2 = ReturnIntFromChar2(a2); iVar3 = GetCharacter(uVar2); - if (iVar3->unk6 < 12) - add_x = ((12 - iVar3->unk6) / 2); + if (iVar3->width < 12) + add_x = ((12 - iVar3->width) / 2); else add_x = 0; diff --git a/src/pokemon_mail.c b/src/pokemon_mail.c index 533a7c4d3..a62b9b751 100644 --- a/src/pokemon_mail.c +++ b/src/pokemon_mail.c @@ -101,10 +101,10 @@ void CreateRescueTitle(unkStruct_802C39C *param_1) if (param_1->mailTitleType == 7) { if (param_1->playerName == NULL) - PrintStringOnWindow(178 - sub_8016028(), param_1->y, GetMonSpecies(param_1->clientSpecies), param_1->unk0[0], 0); + PrintStringOnWindow(178 - GetMaxPokeNameWidth(), param_1->y, GetMonSpecies(param_1->clientSpecies), param_1->unk0[0], 0); else { sub_80922B4(buf_2, param_1->playerName, POKEMON_NAME_LENGTH); - PrintStringOnWindow(178 - sub_8016028(), param_1->y, buf_2, param_1->unk0[0], 0); + PrintStringOnWindow(178 - GetMaxPokeNameWidth(), param_1->y, buf_2, param_1->unk0[0], 0); } } else { diff --git a/src/rescue_password_menu.c b/src/rescue_password_menu.c index ec4d40188..dfc284841 100644 --- a/src/rescue_password_menu.c +++ b/src/rescue_password_menu.c @@ -16,6 +16,10 @@ #include "string_format.h" #include "text_1.h" +u32 NamingScreen_Init(u32 type, u8 *defaultText); +u32 NamingScreen_HandleInput(void); +void NamingScreen_Free(void); + #define RESCUE_PASSWORD_SIZE 0x36 EWRAM_DATA s32 gCommsTimeout = {0}; @@ -292,7 +296,7 @@ void CreateRescuePasswordMenu(u32 currMenu) case 0x1C: case 0x1E: case 0x20: - sub_80151C0(4, gRescuePasswordBuffer); + NamingScreen_Init(4, gRescuePasswordBuffer); break; case MENU_DISPLAY_RESCUE_PASSWORD: temp = GetMailatIndex(0x1F); @@ -302,7 +306,7 @@ void CreateRescuePasswordMenu(u32 currMenu) sub_8031D70(0x1F, 0); break; case MENU_RESCUE_PASSWORD_ENTRY: - sub_80151C0(4, gRescuePasswordBuffer); + NamingScreen_Init(4, gRescuePasswordBuffer); break; } @@ -316,7 +320,7 @@ void CleanRescuePasswordMenu(void) ResetUnusedInputStruct(); ShowWindows(NULL, TRUE, TRUE); if (gRescuePasswordMenu != NULL) { - sub_80155F0(); + NamingScreen_Free(); sub_8031E10(); MemoryFree(gRescuePasswordMenu); gRescuePasswordMenu = NULL; @@ -358,7 +362,7 @@ s32 UpdateRescuePasswordMenu(void) case 1: case 3: case 5: - iVar7 = sub_80154F0(); + iVar7 = NamingScreen_HandleInput(); MemoryFill8(&mail, 0, sizeof(unkStruct_203B480)); switch(iVar7) { @@ -460,7 +464,7 @@ s32 UpdateRescuePasswordMenu(void) nextMenu = UpdateRescuePasswordMenu_sub(MENU_WONDER_MAIL); break; case 7: - switch(sub_80154F0()) + switch(NamingScreen_HandleInput()) { case 3: nextMenu = PASSWORD_ENTRY_NOT_WONDER_MAIL; @@ -496,7 +500,7 @@ s32 UpdateRescuePasswordMenu(void) sub_8039174(); ResetUnusedInputStruct(); ShowWindows(NULL, TRUE, TRUE); - sub_80151C0(4,gRescuePasswordBuffer); + NamingScreen_Init(4,gRescuePasswordBuffer); gRescuePasswordMenu->state = 8; subtract = gRescuePasswordMenu->currMenu - 0x21; nextMenu = MENU_FRIEND_RESCUE; @@ -524,7 +528,7 @@ s32 UpdateRescuePasswordMenu(void) sub_8039174(); ResetUnusedInputStruct(); ShowWindows(NULL, TRUE, TRUE); - sub_80151C0(4,gRescuePasswordBuffer); + NamingScreen_Init(4,gRescuePasswordBuffer); gRescuePasswordMenu->state = ConvertMenutoRescuePasswordState(gRescuePasswordMenu->currMenu); subtract = gRescuePasswordMenu->currMenu - 0x21; nextMenu = 0x2a; @@ -547,7 +551,7 @@ void DisplayRescuePasswordError(u32 passwordError) RestoreSavedWindows(&gRescuePasswordMenu->unk1A8); ResetUnusedInputStruct(); ShowWindows(NULL, TRUE, TRUE); - sub_80155F0(); + NamingScreen_Free(); switch(passwordError) { case PASSWORD_ENTRY_INCORRECT_PASSWORD: SetMenuItems(gRescuePasswordMenu->unk8,&gRescuePasswordMenu->unk148,0,&gUnknown_80E71FC,gUnknown_80E7214,FALSE,13,FALSE); @@ -587,7 +591,7 @@ void DisplayPasswordAcceptScreen(void) RestoreSavedWindows(&gRescuePasswordMenu->unk1A8); ResetUnusedInputStruct(); ShowWindows(NULL, TRUE, TRUE); - sub_80155F0(); + NamingScreen_Free(); SetMenuItems(gRescuePasswordMenu->unk8,&gRescuePasswordMenu->unk148,0,&gUnknown_80E7278,gUnknown_80E7290,FALSE,13,FALSE); sub_8035CF4(gRescuePasswordMenu->unk8,0,TRUE); } diff --git a/src/text_1.c b/src/text_1.c index a99630f59..165f60737 100644 --- a/src/text_1.c +++ b/src/text_1.c @@ -95,7 +95,7 @@ const unkChar gUnknown_80B86A4 = { .unk0 = sUnknown_80B865C, .unk4 = 0x81A1, - .unk6 = 7, + .width = 7, .unk8 = 10, .fill9 = 0, .unkA = 0, diff --git a/src/text_2.c b/src/text_2.c index 10aec2c28..c24504e5b 100644 --- a/src/text_2.c +++ b/src/text_2.c @@ -223,7 +223,7 @@ u32 xxx_draw_char(Window *windows, s32 x, s32 y, u32 chr, u32 color, u32 windowI } } - return sp0->unk6 + gCharacterSpacing; + return sp0->width + gCharacterSpacing; } // Copied to 01ff98f8 in NDS diff --git a/src/text_3.c b/src/text_3.c index 4bdc2842c..0ff5aa8a8 100644 --- a/src/text_3.c +++ b/src/text_3.c @@ -129,7 +129,7 @@ s32 sub_8008ED0(const u8 *str) else { const unkChar *ptr = GetCharacter(chr); if (ptr != NULL) { - ret += ptr->unk6 + gCharacterSpacing; + ret += ptr->width + gCharacterSpacing; } } } @@ -211,7 +211,7 @@ static void xxx_draw_string(Window *strArr, s32 x, s32 y, const u8 *str, u32 win if (chrPtr != NULL) { s32 x = sp.unk0; s32 x2 = gCharacterSpacing + 10; - x +=((x2 - chrPtr->unk6) / 2); + x +=((x2 - chrPtr->width) / 2); xxx_draw_char(strArr, x, sp.unk2, currChr, sp.unk10, windowId); sp.unk0 += characterSpacing; } diff --git a/src/thank_you_wonder_mail.c b/src/thank_you_wonder_mail.c index ffe5b2ba0..8808a4ae6 100644 --- a/src/thank_you_wonder_mail.c +++ b/src/thank_you_wonder_mail.c @@ -25,6 +25,10 @@ #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); + static EWRAM_INIT WonderMailStruct_203B2C4 *sUnknown_203B2C4 = {NULL}; #define THANK_YOU_MAIL_MAIN_MENU 0 @@ -414,7 +418,7 @@ void CleanThankYouMailPelipper(void) FreeItemDescriptionWindow(); sub_803084C(); sub_801CBB8(); - sub_80155F0(); + NamingScreen_Free(); sub_8031E10(); sub_802F2C0(); } @@ -790,7 +794,7 @@ void HandleThankYouMailPasswordMenu(void) u32 return_var; unkStruct_203B480 mail1; - return_var = sub_80154F0(); + return_var = NamingScreen_HandleInput(); MemoryFill8(&mail1, 0, sizeof(unkStruct_203B480)); switch(return_var) { @@ -821,10 +825,10 @@ void HandleThankYouMailPasswordMenu(void) case 7: break; } - sub_80155F0(); + NamingScreen_Free(); break; case 2: - sub_80155F0(); + NamingScreen_Free(); ResetUnusedInputStruct(); ShowWindows(&sUnknown_203B2C4->unk3BC, TRUE, TRUE); SetThankYouMailMenuState(ANYTHING_ELSE_THANK_YOU_MAIN_MENU); @@ -1333,7 +1337,7 @@ void UpdateThankYouMailText(void) RestoreSavedWindows(&sUnknown_203B2C4->unk3BC); ResetUnusedInputStruct(); ShowWindows(NULL, TRUE, TRUE); - sub_80151C0(4,sUnknown_203B2C4->passwordBuffer); + NamingScreen_Init(4,sUnknown_203B2C4->passwordBuffer); break; case 0x1a: RestoreSavedWindows(&sUnknown_203B2C4->unk3BC); diff --git a/src/wonder_mail.c b/src/wonder_mail.c index c2a4207b4..9c78e4c7d 100644 --- a/src/wonder_mail.c +++ b/src/wonder_mail.c @@ -23,6 +23,10 @@ #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); + static EWRAM_INIT WonderMailStruct_203B2C0 *sUnknown_203B2C0 = {NULL}; extern void sub_8011C28(u32); @@ -403,7 +407,7 @@ void sub_80282FC(void) sub_8031E10(); FriendList_Free(); sub_803084C(); - sub_80155F0(); + NamingScreen_Free(); sub_80310B4(); sub_8030DE4(); sub_802453C(); @@ -575,7 +579,7 @@ void sub_8028348(void) RestoreSavedWindows(&sUnknown_203B2C0->unk3BC); ResetUnusedInputStruct(); ShowWindows(NULL, TRUE, TRUE); - sub_80151C0(4, sUnknown_203B2C0->passwordBuffer); + NamingScreen_Init(4, sUnknown_203B2C0->passwordBuffer); break; case 8: switch(sUnknown_203B2C0->unk538) @@ -1356,7 +1360,7 @@ void sub_80293F4(void) u32 return_var; unkStruct_203B480 mail; - return_var = sub_80154F0(); + return_var = NamingScreen_HandleInput(); MemoryFill8(&mail, 0, sizeof(unkStruct_203B480)); switch(return_var) { @@ -1387,10 +1391,10 @@ void sub_80293F4(void) default: break; } - sub_80155F0(); + NamingScreen_Free(); break; case 2: - sub_80155F0(); + NamingScreen_Free(); ResetUnusedInputStruct(); ShowWindows(&sUnknown_203B2C0->unk3BC, TRUE, TRUE); SetFriendRescueCounterState(FRIEND_RESCUE_MAIN); diff --git a/src/wonder_mail_main_menu.c b/src/wonder_mail_main_menu.c index 8c4a90eab..c3ae9045e 100644 --- a/src/wonder_mail_main_menu.c +++ b/src/wonder_mail_main_menu.c @@ -21,6 +21,10 @@ #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); + #define SELECT_WONDER_MAIL_MODE_MAIN_SCREEN 0 #define SEND_WONDER_MAIL_MAIN_SCREEN 1 #define SEND_GAME_LINK_CABLE 2 @@ -171,7 +175,7 @@ void CleanWonderMailMenu(void) FreeItemDescriptionWindow(); // Frees 203B230 sub_803084C(); // Frees 203B320 sub_801CBB8(); // Frees 203B244 - sub_80155F0(); // Frees 203B1FC + NamingScreen_Free(); // Frees 203B1FC sub_8031E10(); // Frees 203B334 } } @@ -325,11 +329,11 @@ void HandlePasswordEntryScreen(void) { s32 iVar2; - iVar2 = sub_80154F0(); + iVar2 = NamingScreen_HandleInput(); MemoryFill8(gUnknown_203B3E8->UNK38.unk38_u8, 0, sizeof(gUnknown_203B3E8->UNK38)); switch(iVar2){ case 3: - sub_80155F0(); + NamingScreen_Free(); ResetUnusedInputStruct(); ShowWindows(&gUnknown_203B3E8->unk1EC, TRUE, TRUE); if ( !DecodeWonderMailPassword(gUnknown_203B3E8->PasswordEntryBuffer, &gUnknown_203B3E8->UNK38.decodedMail) || !IsValidWonderMail(&gUnknown_203B3E8->UNK38.decodedMail) ) @@ -347,7 +351,7 @@ void HandlePasswordEntryScreen(void) } break; case 2: - sub_80155F0(); + NamingScreen_Free(); ResetUnusedInputStruct(); ShowWindows(&gUnknown_203B3E8->unk1EC, TRUE, TRUE); SetWonderMailMainMenuState(EXIT_TO_MAIN_MENU); @@ -561,7 +565,7 @@ void WonderMailMainMenuCallback(void) RestoreSavedWindows(&gUnknown_203B3E8->unk1EC); ResetUnusedInputStruct(); ShowWindows(NULL, TRUE, TRUE); - sub_80151C0(5,gUnknown_203B3E8->PasswordEntryBuffer); + NamingScreen_Init(5,gUnknown_203B3E8->PasswordEntryBuffer); break; case PASSWORD_INVALID: CreateMenuDialogueBoxAndPortrait(gUnknown_80E7CC4,0,6,gUnknown_80E78F8,0,4,0,0,0x101); diff --git a/sym_ewram_init.txt b/sym_ewram_init.txt index 0ee7af698..957e6f4fe 100644 --- a/sym_ewram_init.txt +++ b/sym_ewram_init.txt @@ -25,7 +25,6 @@ .include "src/quick_save_write.o" .include "src/string_format.o" .include "src/code_8015080.o" -.include "src/code_8012A18_1.o" .include "src/code_801602C.o" .include "src/felicity_bank.o" .include "src/kangaskhan_storage1.o" From f3c13712914df9f1857516a1d2dfaf80c53f97ed Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Mon, 2 Jun 2025 23:29:21 +0200 Subject: [PATCH 2/7] More naming screen documentation --- ld_script.ld | 4 +- src/{code_8015080.c => naming_screen.c} | 402 ++++++++++++------------ sym_ewram_init.txt | 2 +- 3 files changed, 208 insertions(+), 200 deletions(-) rename src/{code_8015080.c => naming_screen.c} (67%) diff --git a/ld_script.ld b/ld_script.ld index d78fbe146..8b1ff3766 100755 --- a/ld_script.ld +++ b/ld_script.ld @@ -101,7 +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); src/kangaskhan_storage1.o(.text); @@ -453,7 +453,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); src/kangaskhan_storage1.o(.rodata); diff --git a/src/code_8015080.c b/src/naming_screen.c similarity index 67% rename from src/code_8015080.c rename to src/naming_screen.c index cb01d4283..45933a779 100644 --- a/src/code_8015080.c +++ b/src/naming_screen.c @@ -52,16 +52,16 @@ const WindowTemplate gUnknown_80DAFA0 = { NULL }; -struct Struct80DB0F8 +struct LayoutInfo { - u8 unk0; - u8 unk1; - u8 unk2; - u8 unk3; + u8 upPos; + u8 downPos; + u8 leftPos; + u8 rightPos; u8 x; u8 y; - u8 unk6; - s32 unk8; + u8 colorType; + s32 letter; }; UNUSED static const char sPksDir[] = "pksdir0"; @@ -151,99 +151,105 @@ static const DungeonPos gUnknown_80DB098[] = {0xBA, 0x24}, }; +#define NAMING_LETTER_DEL 0x105 +#define NAMING_LETTER_END 0x106 +#define NAMING_LETTER_INS_OVR 0x107 +#define NAMING_LETTER_BLANK 0x108 +#define NAMING_LETTER_TERMINATOR 0x109 + // It was programmed as a 2d array, however it's effectively a 1d array(since there's only one entry for [0][x]). Could be different in Blue? -static const struct Struct80DB0F8 gUnknown_80DB0F8[][85] = +static const struct LayoutInfo sLayoutInfo[][85] = { [0] = { - {0, 0, 0, 0, 8, 3, 0, 264}, - {0, 0, 0, 0, 8, 14, 0, 264}, - {0, 0, 0, 0, 8, 25, 0, 264}, - {5, 4, 81, 9, 8, 36, 3, 263}, - {3, 5, 82, 10, 8, 47, 3, 261}, - {4, 3, 83, 11, 8, 58, 3, 262}, - {11, 7, 78, 12, 36, 3, 0, 97}, - {6, 8, 79, 13, 36, 14, 0, 110}, - {7, 9, 80, 14, 36, 25, 0, 65}, - {8, 10, 3, 15, 36, 36, 0, 78}, - {9, 11, 4, 16, 36, 47, 0, 233}, - {10, 6, 5, 17, 36, 58, 0, 43}, - {17, 13, 6, 18, 50, 3, 0, 98}, - {12, 14, 7, 19, 50, 14, 0, 111}, - {13, 15, 8, 20, 50, 25, 0, 66}, - {14, 16, 9, 21, 50, 36, 0, 79}, - {15, 17, 10, 22, 50, 47, 0, 49}, - {16, 12, 11, 23, 50, 58, 0, 45}, - {23, 19, 12, 24, 64, 3, 0, 99}, - {18, 20, 13, 25, 64, 14, 0, 112}, - {19, 21, 14, 26, 64, 25, 0, 67}, - {20, 22, 15, 27, 64, 36, 0, 80}, - {21, 23, 16, 28, 64, 47, 0, 50}, - {22, 18, 17, 29, 64, 58, 0, 44}, - {29, 25, 18, 30, 78, 3, 0, 100}, - {24, 26, 19, 31, 78, 14, 0, 113}, - {25, 27, 20, 32, 78, 25, 0, 68}, - {26, 28, 21, 33, 78, 36, 0, 81}, - {27, 29, 22, 34, 78, 47, 0, 51}, - {28, 24, 23, 35, 78, 58, 0, 46}, - {35, 31, 24, 36, 92, 3, 0, 101}, - {30, 32, 25, 37, 92, 14, 0, 114}, - {31, 33, 26, 38, 92, 25, 0, 69}, - {32, 34, 27, 39, 92, 36, 0, 82}, - {33, 35, 28, 40, 92, 47, 0, 52}, - {34, 30, 29, 41, 92, 58, 0, 33}, - {41, 37, 30, 42, 106, 3, 0, 102}, - {36, 38, 31, 43, 106, 14, 0, 115}, - {37, 39, 32, 44, 106, 25, 0, 70}, - {38, 40, 33, 45, 106, 36, 0, 83}, - {39, 41, 34, 46, 106, 47, 0, 53}, - {40, 36, 35, 47, 106, 58, 0, 63}, - {47, 43, 36, 48, 120, 3, 0, 103}, - {42, 44, 37, 49, 120, 14, 0, 116}, - {43, 45, 38, 50, 120, 25, 0, 71}, - {44, 46, 39, 51, 120, 36, 0, 84}, - {45, 47, 40, 52, 120, 47, 0, 54}, + {0, 0, 0, 0, 8, 3, 0, NAMING_LETTER_BLANK}, + {0, 0, 0, 0, 8, 14, 0, NAMING_LETTER_BLANK}, + {0, 0, 0, 0, 8, 25, 0, NAMING_LETTER_BLANK}, + {5, 4, 81, 9, 8, 36, 3, NAMING_LETTER_INS_OVR}, + {3, 5, 82, 10, 8, 47, 3, NAMING_LETTER_DEL}, + {4, 3, 83, 11, 8, 58, 3, NAMING_LETTER_END}, + {11, 7, 78, 12, 36, 3, 0, 'a'}, + {6, 8, 79, 13, 36, 14, 0, 'n'}, + {7, 9, 80, 14, 36, 25, 0, 'A'}, + {8, 10, 3, 15, 36, 36, 0, 'N'}, + {9, 11, 4, 16, 36, 47, 0, 233}, + {10, 6, 5, 17, 36, 58, 0, '+'}, + {17, 13, 6, 18, 50, 3, 0, 'b'}, + {12, 14, 7, 19, 50, 14, 0, 'o'}, + {13, 15, 8, 20, 50, 25, 0, 'B'}, + {14, 16, 9, 21, 50, 36, 0, 'O'}, + {15, 17, 10, 22, 50, 47, 0, '1'}, + {16, 12, 11, 23, 50, 58, 0, '-'}, + {23, 19, 12, 24, 64, 3, 0, 'c'}, + {18, 20, 13, 25, 64, 14, 0, 'p'}, + {19, 21, 14, 26, 64, 25, 0, 'C'}, + {20, 22, 15, 27, 64, 36, 0, 'P'}, + {21, 23, 16, 28, 64, 47, 0, '2'}, + {22, 18, 17, 29, 64, 58, 0, ','}, + {29, 25, 18, 30, 78, 3, 0, 'd'}, + {24, 26, 19, 31, 78, 14, 0, 'q'}, + {25, 27, 20, 32, 78, 25, 0, 'D'}, + {26, 28, 21, 33, 78, 36, 0, 'Q'}, + {27, 29, 22, 34, 78, 47, 0, '3'}, + {28, 24, 23, 35, 78, 58, 0, '.'}, + {35, 31, 24, 36, 92, 3, 0, 'e'}, + {30, 32, 25, 37, 92, 14, 0, 'r'}, + {31, 33, 26, 38, 92, 25, 0, 'E'}, + {32, 34, 27, 39, 92, 36, 0, 'R'}, + {33, 35, 28, 40, 92, 47, 0, '4'}, + {34, 30, 29, 41, 92, 58, 0, '!'}, + {41, 37, 30, 42, 106, 3, 0, 'f'}, + {36, 38, 31, 43, 106, 14, 0, 's'}, + {37, 39, 32, 44, 106, 25, 0, 'F'}, + {38, 40, 33, 45, 106, 36, 0, 'S'}, + {39, 41, 34, 46, 106, 47, 0, '5'}, + {40, 36, 35, 47, 106, 58, 0, '?'}, + {47, 43, 36, 48, 120, 3, 0, 'g'}, + {42, 44, 37, 49, 120, 14, 0, 't'}, + {43, 45, 38, 50, 120, 25, 0, 'G'}, + {44, 46, 39, 51, 120, 36, 0, 'T'}, + {45, 47, 40, 52, 120, 47, 0, '6'}, {46, 42, 41, 53, 120, 58, 0, 145}, - {53, 49, 42, 54, 134, 3, 0, 104}, - {48, 50, 43, 55, 134, 14, 0, 117}, - {49, 51, 44, 56, 134, 25, 0, 72}, - {50, 52, 45, 57, 134, 36, 0, 85}, - {51, 53, 46, 58, 134, 47, 0, 55}, + {53, 49, 42, 54, 134, 3, 0, 'h'}, + {48, 50, 43, 55, 134, 14, 0, 'u'}, + {49, 51, 44, 56, 134, 25, 0, 'H'}, + {50, 52, 45, 57, 134, 36, 0, 'U'}, + {51, 53, 46, 58, 134, 47, 0, '7'}, {52, 48, 47, 59, 134, 58, 0, 146}, - {59, 55, 48, 60, 148, 3, 0, 105}, - {54, 56, 49, 61, 148, 14, 0, 118}, - {55, 57, 50, 62, 148, 25, 0, 73}, - {56, 58, 51, 63, 148, 36, 0, 86}, - {57, 59, 52, 64, 148, 47, 0, 56}, + {59, 55, 48, 60, 148, 3, 0, 'i'}, + {54, 56, 49, 61, 148, 14, 0, 'v'}, + {55, 57, 50, 62, 148, 25, 0, 'I'}, + {56, 58, 51, 63, 148, 36, 0, 'V'}, + {57, 59, 52, 64, 148, 47, 0, '8'}, {58, 54, 53, 65, 148, 58, 0, 147}, - {65, 61, 54, 66, 162, 3, 0, 106}, - {60, 62, 55, 67, 162, 14, 0, 119}, - {61, 63, 56, 68, 162, 25, 0, 74}, - {62, 64, 57, 69, 162, 36, 0, 87}, - {63, 65, 58, 70, 162, 47, 0, 57}, + {65, 61, 54, 66, 162, 3, 0, 'j'}, + {60, 62, 55, 67, 162, 14, 0, 'w'}, + {61, 63, 56, 68, 162, 25, 0, 'J'}, + {62, 64, 57, 69, 162, 36, 0, 'W'}, + {63, 65, 58, 70, 162, 47, 0, '9'}, {64, 60, 59, 71, 162, 58, 0, 148}, - {71, 67, 60, 72, 176, 3, 0, 107}, - {66, 68, 61, 73, 176, 14, 0, 120}, - {67, 69, 62, 74, 176, 25, 0, 75}, - {68, 70, 63, 75, 176, 36, 0, 88}, - {69, 71, 64, 76, 176, 47, 0, 48}, + {71, 67, 60, 72, 176, 3, 0, 'k'}, + {66, 68, 61, 73, 176, 14, 0, 'x'}, + {67, 69, 62, 74, 176, 25, 0, 'K'}, + {68, 70, 63, 75, 176, 36, 0, 'X'}, + {69, 71, 64, 76, 176, 47, 0, '0'}, {70, 66, 65, 77, 176, 58, 0, 189}, - {77, 73, 66, 78, 190, 3, 0, 108}, - {72, 74, 67, 79, 190, 14, 0, 121}, - {73, 75, 68, 80, 190, 25, 0, 76}, - {74, 76, 69, 81, 190, 36, 0, 89}, - {75, 77, 70, 82, 190, 47, 0, 58}, + {77, 73, 66, 78, 190, 3, 0, 'l'}, + {72, 74, 67, 79, 190, 14, 0, 'y'}, + {73, 75, 68, 80, 190, 25, 0, 'L'}, + {74, 76, 69, 81, 190, 36, 0, 'Y'}, + {75, 77, 70, 82, 190, 47, 0, ':'}, {76, 72, 71, 83, 190, 58, 0, 190}, - {83, 79, 72, 6, 204, 3, 0, 109}, - {78, 80, 73, 7, 204, 14, 0, 122}, - {79, 81, 74, 8, 204, 25, 0, 77}, - {80, 82, 75, 3, 204, 36, 0, 90}, - {81, 83, 76, 4, 204, 47, 0, 133}, - {82, 78, 77, 5, 204, 58, 0, 32}, - {0, 0, 0, 0, 8, 3, 2, 265}, + {83, 79, 72, 6, 204, 3, 0, 'm'}, + {78, 80, 73, 7, 204, 14, 0, 'z'}, + {79, 81, 74, 8, 204, 25, 0, 'M'}, + {80, 82, 75, 3, 204, 36, 0, 'Z'}, + {81, 83, 76, 4, 204, 47, 0, 133}, + {82, 78, 77, 5, 204, 58, 0, ' '}, + {0, 0, 0, 0, 8, 3, 2, NAMING_LETTER_TERMINATOR}, } }; -static const u8 *const gUnknown_80DB4F4[] = +static const u8 *const sSpecialLetters[] = { _("゛"), _("゜"), @@ -254,40 +260,39 @@ static const u8 *const gUnknown_80DB4F4[] = _("END"), }; -static const WindowTemplate gUnknown_80DB538 = { - 0x00, - 0x03, - 0x00, 0x00, - 0x00, 0x00, - 0x00, 0x00, - NULL +static const WindowTemplate sWindowTemplateDummy = WIN_TEMPLATE_DUMMY; + +static const WindowTemplate sInputWindowTemplate = { + .unk0 = 0, + .type = WINDOW_TYPE_WITHOUT_BORDER, + .pos = {1, 10}, + .width = 28, + .height = 9, + .unk10 = 9, + .unk12 = 0, + .header = NULL, }; -static const WindowTemplate gUnknown_80DB550 = { - 0x00, - 0x01, - 0x01, 0x0A, - 0x1C, 0x09, - 0x09, 0x00, - NULL +static const WindowTemplate sNameWindowTemplate = { + .unk0 = 0, + .type = WINDOW_TYPE_WITHOUT_BORDER, + .pos = {4, 3}, + .width = 22, + .height = 5, + .unk10 = 5, + .unk12 = 0, + .header = NULL, }; -static const WindowTemplate gUnknown_80DB568 = { - 0x00, - 0x01, - 0x04, 0x03, - 0x16, 0x05, - 0x05, 0x00, - NULL -}; - -static const WindowTemplate gUnknown_80DB580 = { - 0x00, - 0x01, - 0x01, 0x02, - 0x1C, 0x07, - 0x07, 0x00, - NULL +static const WindowTemplate sPasswordNameWindowTemplate = { + .unk0 = 0, + .type = WINDOW_TYPE_WITHOUT_BORDER, + .pos = {1, 2}, + .width = 28, + .height = 7, + .unk10 = 7, + .unk12 = 0, + .header = NULL, }; bool8 sub_8015080(u8 *buffer, const MenuItem *menuItems) @@ -345,14 +350,14 @@ struct NamingScreen { // size: 0x198 u32 type; - u8 unk4; + 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 sprite1Attribs[4]; u16 sprite2Attribs[4]; u8 letterCursorFrames; u8 inputCursorFrames; u8 unk18; - u8 unk19; + u8 inputCursorArrId; // Always 0 u8 inputCursorPosition; u8 maxLetters; u8 letterCursorPos; @@ -367,7 +372,7 @@ struct NamingScreen static EWRAM_INIT struct NamingScreen *sNamingScreen = NULL; static s32 GetEnteredNameLength(void); -void sub_8015A08(u32); +static void UpdateInputWindow(bool8); static void UpdateNameWindow(void); void sub_8015F84(); static void SetLetterCursorSpritePosition(void); @@ -389,6 +394,9 @@ enum NAMING_PASSWORD2, }; +#define NAMING_WINDOW_INPUT 0 +#define NAMING_WINDOW_NAME 1 + u32 NamingScreen_Init(u32 type, u8 *defaultText) { SpriteOAM *sprite; @@ -397,19 +405,19 @@ u32 NamingScreen_Init(u32 type, u8 *defaultText) sNamingScreen = MemoryAlloc(sizeof(*sNamingScreen), 8); sNamingScreen->type = type; - sNamingScreen->unk19 = 0; + sNamingScreen->inputCursorArrId = 0; sNamingScreen->unk18 = 0; - sNamingScreen->unk4 = 0; + sNamingScreen->isPassword = 0; switch (sNamingScreen->type) { case NAMING_PASSWORD1: sNamingScreen->inputCursorPosition = 9; - sNamingScreen->unk4 = 1; + sNamingScreen->isPassword = TRUE; sNamingScreen->maxLetters = 0x36; break; case NAMING_PASSWORD2: sNamingScreen->inputCursorPosition = 9; - sNamingScreen->unk4 = 1; + sNamingScreen->isPassword = TRUE; sNamingScreen->maxLetters = 0x18; break; case NAMING_SELF: @@ -453,7 +461,7 @@ u32 NamingScreen_Init(u32 type, u8 *defaultText) SpriteSetX((SpriteOAM *) &sNamingScreen->sprite1Attribs, DISPLAY_WIDTH); SpriteSetY((SpriteOAM *) &sNamingScreen->sprite1Attribs, DISPLAY_WIDTH); - if (sNamingScreen->unk4 != 0) { + if (sNamingScreen->isPassword) { SpriteSetMatrixNum((SpriteOAM *) &sNamingScreen->sprite1Attribs, 0); SpriteSetTileNum((SpriteOAM *) &sNamingScreen->sprite1Attribs, 0x3F6); SpriteSetSize((SpriteOAM *) &sNamingScreen->sprite1Attribs, 0); @@ -486,22 +494,22 @@ u32 NamingScreen_Init(u32 type, u8 *defaultText) sNamingScreen->inputCursorFrames = 0; - for (index = 0; index < 4; index++) { - sNamingScreen->windows.id[index] = gUnknown_80DB538; + for (index = 0; index < MAX_WINDOWS; index++) { + sNamingScreen->windows.id[index] = sWindowTemplateDummy; } - if(sNamingScreen->unk4 != 0) { - sNamingScreen->windows.id[1] = gUnknown_80DB580; + if (sNamingScreen->isPassword) { + sNamingScreen->windows.id[NAMING_WINDOW_NAME] = sPasswordNameWindowTemplate; } else { - sNamingScreen->windows.id[1] = gUnknown_80DB568; + sNamingScreen->windows.id[NAMING_WINDOW_NAME] = sNameWindowTemplate; } - sNamingScreen->windows.id[0] = gUnknown_80DB550; + sNamingScreen->windows.id[NAMING_WINDOW_INPUT] = sInputWindowTemplate; ResetUnusedInputStruct(); ShowWindows(&sNamingScreen->windows, 1, 1); - sub_8015A08(1); + UpdateInputWindow(TRUE); UpdateNameWindow(); sub_8015F84(); return 1; @@ -566,21 +574,21 @@ void NamingScreen_Free(void) static u32 HandleAPress(void) { - s32 var = gUnknown_80DB0F8[sNamingScreen->unk19][sNamingScreen->inputCursorPosition].unk8; + s32 letter = sLayoutInfo[sNamingScreen->inputCursorArrId][sNamingScreen->inputCursorPosition].letter; - switch (var) { - case 0x107: + switch (letter) { + case NAMING_LETTER_INS_OVR: sNamingScreen->unk18 = (sNamingScreen->unk18 == 0); PlayMenuSoundEffect(4); - sub_8015A08(0); + UpdateInputWindow(FALSE); break; - case 0x105: + case NAMING_LETTER_DEL: if (HandleBPress()) { return 2; } break; - case 0x106: - if (GetEnteredNameLength() == 0 || (sNamingScreen->unk4 != 0 && GetEnteredNameLength() != sNamingScreen->maxLetters)) { + case NAMING_LETTER_END: + if (GetEnteredNameLength() == 0 || (sNamingScreen->isPassword && GetEnteredNameLength() != sNamingScreen->maxLetters)) { PlayMenuSoundEffect(2); } else { @@ -590,7 +598,7 @@ static u32 HandleAPress(void) } break; default: - if (sNamingScreen->unk4 != 0 && sub_803D0F0(var) == 0xFF) { + if (sNamingScreen->isPassword && sub_803D0F0(letter) == 0xFF) { PlayMenuSoundEffect(2); } else { @@ -602,7 +610,7 @@ static u32 HandleAPress(void) } } - sNamingScreen->textPtr[sNamingScreen->letterCursorPos] = var; + sNamingScreen->textPtr[sNamingScreen->letterCursorPos] = letter; if (sNamingScreen->letterCursorPos < sNamingScreen->maxLetters - 1) { sNamingScreen->letterCursorPos++; } @@ -694,16 +702,16 @@ static void HandleInputCursor(void) switch (sub_8012AE8()) { case INPUT_DPAD_UP: - newPosition = gUnknown_80DB0F8[sNamingScreen->unk19][sNamingScreen->inputCursorPosition].unk0; + newPosition = sLayoutInfo[sNamingScreen->inputCursorArrId][sNamingScreen->inputCursorPosition].upPos; break; case INPUT_DPAD_DOWN: - newPosition = gUnknown_80DB0F8[sNamingScreen->unk19][sNamingScreen->inputCursorPosition].unk1; + newPosition = sLayoutInfo[sNamingScreen->inputCursorArrId][sNamingScreen->inputCursorPosition].downPos; break; case INPUT_DPAD_LEFT: - newPosition = gUnknown_80DB0F8[sNamingScreen->unk19][sNamingScreen->inputCursorPosition].unk2; + newPosition = sLayoutInfo[sNamingScreen->inputCursorArrId][sNamingScreen->inputCursorPosition].leftPos; break; case INPUT_DPAD_RIGHT: - newPosition = gUnknown_80DB0F8[sNamingScreen->unk19][sNamingScreen->inputCursorPosition].unk3; + newPosition = sLayoutInfo[sNamingScreen->inputCursorArrId][sNamingScreen->inputCursorPosition].rightPos; break; default: newPosition = sNamingScreen->inputCursorPosition; @@ -716,15 +724,15 @@ static void HandleInputCursor(void) sNamingScreen->inputCursorFrames = 8; } - x = gUnknown_80DB0F8[sNamingScreen->unk19][sNamingScreen->inputCursorPosition].x + (window->x * 8) - 5; - y = gUnknown_80DB0F8[sNamingScreen->unk19][sNamingScreen->inputCursorPosition].y + (window->y * 8) + 1; + x = sLayoutInfo[sNamingScreen->inputCursorArrId][sNamingScreen->inputCursorPosition].x + (window->x * 8) - 5; + y = sLayoutInfo[sNamingScreen->inputCursorArrId][sNamingScreen->inputCursorPosition].y + (window->y * 8) + 1; SpriteSetX((SpriteOAM *) &sNamingScreen->sprite2Attribs, x); SpriteSetY((SpriteOAM *) &sNamingScreen->sprite2Attribs, y); } -void sub_8015A08(u32 unused) +static void UpdateInputWindow(bool8 unused) { - s32 r4; + s32 letter; s32 i; u8 text1[16]; u8 text2[16]; @@ -732,62 +740,62 @@ void sub_8015A08(u32 unused) CallPrepareTextbox_8008C54(0); sub_80073B8(0); - for (i = 0; (r4 = gUnknown_80DB0F8[sNamingScreen->unk19][i].unk8) != 0x109; i++) { - s32 r5; + for (i = 0; (letter = sLayoutInfo[sNamingScreen->inputCursorArrId][i].letter) != NAMING_LETTER_TERMINATOR; i++) { + s32 color; - switch (gUnknown_80DB0F8[sNamingScreen->unk19][i].unk6) { + switch (sLayoutInfo[sNamingScreen->inputCursorArrId][i].colorType) { case 1: - r5 = 5; + color = 5; break; case 2: - r5 = 2; + color = 2; break; case 3: - r5 = 7; + color = 7; break; default: - r5 = 7; - if (sNamingScreen->unk4 != 0) { - if (r4 <= 0xFF) { - if (sub_803D0F0(r4) == 0xFF) { - r5 = 2; + color = 7; + if (sNamingScreen->isPassword) { + if (letter <= 0xFF) { + if (sub_803D0F0(letter) == 0xFF) { + color = 2; } } - else if (r4 < 0x102) { - r5 = 2; + else if (letter < 0x102) { + color = 2; } } break; } - if (r4 != 0x108) { - if (r4 == 0x107) { + if (letter != NAMING_LETTER_BLANK) { + if (letter == NAMING_LETTER_INS_OVR) { if (sNamingScreen->unk18 == 0) { - PrintStringOnWindow(gUnknown_80DB0F8[sNamingScreen->unk19][i].x + 3, gUnknown_80DB0F8[sNamingScreen->unk19][i].y, _("{COLOR GREEN}OVR{RESET}"), 0, '\0'); + PrintStringOnWindow(sLayoutInfo[sNamingScreen->inputCursorArrId][i].x + 3, sLayoutInfo[sNamingScreen->inputCursorArrId][i].y, _("{COLOR GREEN}OVR{RESET}"), NAMING_WINDOW_INPUT, '\0'); } else { - PrintStringOnWindow(gUnknown_80DB0F8[sNamingScreen->unk19][i].x + 3, gUnknown_80DB0F8[sNamingScreen->unk19][i].y, _("{COLOR YELLOW}INS{RESET}"), 0, '\0'); + PrintStringOnWindow(sLayoutInfo[sNamingScreen->inputCursorArrId][i].x + 3, sLayoutInfo[sNamingScreen->inputCursorArrId][i].y, _("{COLOR YELLOW}INS{RESET}"), NAMING_WINDOW_INPUT, '\0'); } } - else if (r4 == 0x20) { - sprintfStatic(text1, _("{COLOR}%c{0x81}{0x59}"), r5); - PrintStringOnWindow(gUnknown_80DB0F8[sNamingScreen->unk19][i].x + 1, gUnknown_80DB0F8[sNamingScreen->unk19][i].y, text1, 0, '\0'); + else if (letter == ' ') { + sprintfStatic(text1, _("{COLOR}%c{0x81}{0x59}"), color); + PrintStringOnWindow(sLayoutInfo[sNamingScreen->inputCursorArrId][i].x + 1, sLayoutInfo[sNamingScreen->inputCursorArrId][i].y, text1, NAMING_WINDOW_INPUT, '\0'); } - else if (r4 > 0xFF) { - sprintfStatic(text2, _("{COLOR}%c%s"), r5, gUnknown_80DB4F4[r4 & 0xFF]); - PrintStringOnWindow(gUnknown_80DB0F8[sNamingScreen->unk19][i].x + 3, gUnknown_80DB0F8[sNamingScreen->unk19][i].y, text2, 0, '\0'); + else if (letter > 0xFF) { + sprintfStatic(text2, _("{COLOR}%c%s"), color, sSpecialLetters[letter & 0xFF]); + PrintStringOnWindow(sLayoutInfo[sNamingScreen->inputCursorArrId][i].x + 3, sLayoutInfo[sNamingScreen->inputCursorArrId][i].y, text2, NAMING_WINDOW_INPUT, '\0'); } else { - sub_8012C60(gUnknown_80DB0F8[sNamingScreen->unk19][i].x, gUnknown_80DB0F8[sNamingScreen->unk19][i].y, (u8) r4, r5, 0); + sub_8012C60(sLayoutInfo[sNamingScreen->inputCursorArrId][i].x, sLayoutInfo[sNamingScreen->inputCursorArrId][i].y, (u8) letter, color, 0); } } } - AddUnderScoreHighlight(0, 0, 0, 0xE0, 0xE); - AddUnderScoreHighlight(0, 0, 0x47, 0xE0, 0xE); - sub_8007A78(0, 0, 0, 0x48, 0xE); - sub_8007A78(0, 0xDF, 0, 0x48, 0xE); - sub_80073E0(0); + AddUnderScoreHighlight(NAMING_WINDOW_INPUT, 0, 0, 0xE0, 0xE); + AddUnderScoreHighlight(NAMING_WINDOW_INPUT, 0, 0x47, 0xE0, 0xE); + sub_8007A78(NAMING_WINDOW_INPUT, 0, 0, 0x48, 0xE); + sub_8007A78(NAMING_WINDOW_INPUT, 0xDF, 0, 0x48, 0xE); + sub_80073E0(NAMING_WINDOW_INPUT); } static void UpdateNameWindow(void) @@ -796,37 +804,37 @@ static void UpdateNameWindow(void) CallPrepareTextbox_8008C54(1); sub_80073B8(1); - if (sNamingScreen->unk4 != 0) { - AddUnderScoreHighlight(1, 0, 0, 0xE0, 0xE); - AddUnderScoreHighlight(1, 0, 0x37, 0xE0, 0xE); - sub_8007A78(1, 0, 0, 0x38, 0xE); - sub_8007A78(1, 0xDF, 0, 0x38, 0xE); + if (sNamingScreen->isPassword) { + AddUnderScoreHighlight(NAMING_WINDOW_NAME, 0, 0, 0xE0, 0xE); + AddUnderScoreHighlight(NAMING_WINDOW_NAME, 0, 0x37, 0xE0, 0xE); + sub_8007A78(NAMING_WINDOW_NAME, 0, 0, 0x38, 0xE); + sub_8007A78(NAMING_WINDOW_NAME, 0xDF, 0, 0x38, 0xE); } else { - AddUnderScoreHighlight(1, 0, 0, 0xB0, 0xE); - AddUnderScoreHighlight(1, 0, 0x27, 0xB0, 0xE); - sub_8007A78(1, 0, 0, 0x28, 0xE); - sub_8007A78(1, 0xAF, 0, 0x28, 0xE); + AddUnderScoreHighlight(NAMING_WINDOW_NAME, 0, 0, 0xB0, 0xE); + AddUnderScoreHighlight(NAMING_WINDOW_NAME, 0, 0x27, 0xB0, 0xE); + sub_8007A78(NAMING_WINDOW_NAME, 0, 0, 0x28, 0xE); + sub_8007A78(NAMING_WINDOW_NAME, 0xAF, 0, 0x28, 0xE); } switch (sNamingScreen->type) { case NAMING_SELF: - PrintStringOnWindow(8, 5, _("What is your name?"), 1, '\0'); + PrintStringOnWindow(8, 5, _("What is your name?"), NAMING_WINDOW_NAME, '\0'); break; case NAMING_POKEMON: - PrintStringOnWindow(8, 5, _("What is this Pokémon's nickname?"), 1, '\0'); + PrintStringOnWindow(8, 5, _("What is this Pokémon's nickname?"), NAMING_WINDOW_NAME, '\0'); break; case NAMING_PARTNER: - PrintStringOnWindow(8, 5, _("What is your partner's nickname?"), 1, '\0'); + PrintStringOnWindow(8, 5, _("What is your partner's nickname?"), NAMING_WINDOW_NAME, '\0'); break; case NAMING_TEAM: - PrintStringOnWindow(8, 5, _("What is your team's name?"), 1, '\0'); + PrintStringOnWindow(8, 5, _("What is your team's name?"), NAMING_WINDOW_NAME, '\0'); break; case NAMING_PASSWORD1: - PrintStringOnWindow(54, 2, _("Please enter the password."), 1, '\0'); + PrintStringOnWindow(54, 2, _("Please enter the password."), NAMING_WINDOW_NAME, '\0'); break; case NAMING_PASSWORD2: - PrintStringOnWindow(48, 4, _("Please enter the password."), 1, '\0'); + PrintStringOnWindow(48, 4, _("Please enter the password."), NAMING_WINDOW_NAME, '\0'); break; } @@ -841,7 +849,7 @@ static void UpdateNameWindow(void) case NAMING_TEAM: case NAMING_POKEMON: case NAMING_PARTNER: - AddDoubleUnderScoreHighlight(1, 38, 33, GetMaxPokeNameWidth(), 4); + AddDoubleUnderScoreHighlight(NAMING_WINDOW_NAME, 38, 33, GetMaxPokeNameWidth(), 4); if (GetStrWidth(sNamingScreen->textPtr, sNamingScreen->maxLetters) > GetMaxPokeNameWidth()) { sprintfStatic(text, _("{COLOR RED}%s{RESET}"), sNamingScreen->textPtr); } @@ -851,11 +859,11 @@ static void UpdateNameWindow(void) else { sprintfStatic(text, _("%s"), sNamingScreen->textPtr); } - PrintStringOnWindow(38, 22, text, 1, '\0'); + PrintStringOnWindow(38, 22, text, NAMING_WINDOW_NAME, '\0'); break; } - sub_80073E0(1); + sub_80073E0(NAMING_WINDOW_NAME); } static void sub_8015E10(u8 *a0, s32 a1, s32 _a2) diff --git a/sym_ewram_init.txt b/sym_ewram_init.txt index 957e6f4fe..727e7a283 100644 --- a/sym_ewram_init.txt +++ b/sym_ewram_init.txt @@ -24,7 +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" .include "src/kangaskhan_storage1.o" From 7ef8b081fe5e9a8ae0019d841e52fe0c30dd40a6 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Tue, 3 Jun 2025 09:55:13 +0200 Subject: [PATCH 3/7] More naming screen documentation --- include/menu_input.h | 2 +- include/text_2.h | 4 +- src/code_8023144.c | 6 +- src/code_8031D70.c | 2 +- src/dungeon_message.c | 2 +- src/menu_input.c | 19 +++-- src/naming_screen.c | 164 ++++++++++++++++++++++-------------------- src/pokemon_mail.c | 2 +- src/string_format.c | 2 +- src/text_2.c | 6 +- src/text_3.c | 16 ++--- 11 files changed, 114 insertions(+), 111 deletions(-) diff --git a/include/menu_input.h b/include/menu_input.h index 4e69a1f95..45ce30d76 100644 --- a/include/menu_input.h +++ b/include/menu_input.h @@ -8,7 +8,7 @@ u32 sub_8012A64(MenuInputStructSub *r0, s32 r1); s32 GetKeyPress(MenuInputStruct *r0); s32 sub_8012AE8(void); void sub_8012BC4(u32 x, u32 y, s32 n, s32 len, u32 color, u32 windowId); -void sub_8012C60(u32 x, u32 y, u32 param_3, u32 color, u32 param_5); +void DrawCharOnWindowWidth12(u32 x, u32 y, u32 param_3, u32 color, u32 param_5); void sub_8012CAC(WindowTemplate *param_1, const MenuItem *param_2); void sub_8012D08(WindowTemplate *param_1, s32 param_2); void sub_8012D34(WindowTemplate *param_1, s32 param_2); diff --git a/include/text_2.h b/include/text_2.h index 4e0d7e3bb..fa3f509fc 100644 --- a/include/text_2.h +++ b/include/text_2.h @@ -16,9 +16,9 @@ void sub_8007B7C(u32 a0, s32 x, s32 y, s32 a3, u32 color); void sub_8007E20(u32 a0, u32 a1, u32 a2, u32 a3, u32 a4, u32 *a5, u32 a6); void sub_80087EC(s32 a0, s32 a1, s32 a2, s32 a3, s32 a4); void sub_80089AC(const WindowTemplate *r4, DungeonPos *r5_Str); -u32 xxx_call_draw_char(s32 x, s32 y, u32 chr, u32 color, u32 windowId); +u32 DrawCharOnWindow(s32 x, s32 y, u32 chr, u32 color, u32 windowId); bool8 xxx_call_update_bg_vram(void); -u32 xxx_draw_char(Window *windows, s32 x, s32 y, u32 chr, u32 color, u32 windowId); +u32 DrawCharOnWindowInternal(Window *windows, s32 x, s32 y, u32 chr, u32 color, u32 windowId); const u8 *xxx_get_next_char_from_string(const u8 *a1, u32 *dstChr); #endif // GUARD_TEXT_2_H diff --git a/src/code_8023144.c b/src/code_8023144.c index ad73ab849..c5d8565ef 100644 --- a/src/code_8023144.c +++ b/src/code_8023144.c @@ -175,17 +175,17 @@ static void sub_80234BC(void) iVar4 = GetDexInternalNo(species, 0); cVar2 = (iVar4 % 10) + 48; - sub_8012C60(20, y, cVar2, color, gUnknown_3001B5C->s35C.s0.winId); + DrawCharOnWindowWidth12(20, y, cVar2, color, gUnknown_3001B5C->s35C.s0.winId); if (9 < iVar4) { iVar4 /= 10; cVar2 = (iVar4 % 10) + 48; - sub_8012C60(13, y, cVar2, color, gUnknown_3001B5C->s35C.s0.winId); + DrawCharOnWindowWidth12(13, y, cVar2, color, gUnknown_3001B5C->s35C.s0.winId); if (9 < iVar4) { uVar3 = iVar4 / 10; cVar2 = (uVar3 % 10) + 48; - sub_8012C60(6, y, cVar2, color, gUnknown_3001B5C->s35C.s0.winId); + DrawCharOnWindowWidth12(6, y, cVar2, color, gUnknown_3001B5C->s35C.s0.winId); } } diff --git a/src/code_8031D70.c b/src/code_8031D70.c index 7a13380c4..471dcabf4 100644 --- a/src/code_8031D70.c +++ b/src/code_8031D70.c @@ -171,7 +171,7 @@ void DrawSOSPasswordScreen(void) } rowIndex = index % 0x12; x = rowIndex * 0xb + 6; - sub_8012C60(x,y,buffer[index],color,gUnknown_203B334->unk10); // Draw character + DrawCharOnWindowWidth12(x,y,buffer[index],color,gUnknown_203B334->unk10); // Draw character AddDoubleUnderScoreHighlight(gUnknown_203B334->unk10,x,y + 0xA,10,COLOR_CYAN); // Draw underscore beneath character } sub_80073E0(gUnknown_203B334->unk10); diff --git a/src/dungeon_message.c b/src/dungeon_message.c index 5037cfde9..ed81bc5d2 100644 --- a/src/dungeon_message.c +++ b/src/dungeon_message.c @@ -252,7 +252,7 @@ void xxx_draw_string_80524F0(void) sp.unk0 += 6; } else { - sp.unk0 += xxx_call_draw_char(sp.unk0, sp.unk2, currChr, sp.unk10, 0); + sp.unk0 += DrawCharOnWindow(sp.unk0, sp.unk2, currChr, sp.unk10, 0); } } sub_80073E0(0); diff --git a/src/menu_input.c b/src/menu_input.c index 9a0478b88..b87de29a4 100644 --- a/src/menu_input.c +++ b/src/menu_input.c @@ -199,7 +199,7 @@ void sub_8012BC4(u32 x, u32 y, s32 n, s32 len, u32 color, u32 windowId) chr = ReturnIntFromChar2(iVar1 + 0x30); iVar3 = GetCharacter(chr); total_x += iVar3->width; - xxx_call_draw_char(x - total_x, y, chr, color, windowId); + DrawCharOnWindow(x - total_x, y, chr, color, windowId); counter++; if (counter >= len) break; @@ -207,21 +207,18 @@ void sub_8012BC4(u32 x, u32 y, s32 n, s32 len, u32 color, u32 windowId) } } -void sub_8012C60(u32 x, u32 y, u32 a2, u32 color, u32 a4) +void DrawCharOnWindowWidth12(u32 x, u32 y, u32 chr, u32 color, u32 windowId) { u32 add_x; - const unkChar *iVar3; - u32 uVar2; + u32 chrId = ReturnIntFromChar2(chr); + const unkChar *chrInfo = GetCharacter(chrId); - uVar2 = ReturnIntFromChar2(a2); - iVar3 = GetCharacter(uVar2); - - if (iVar3->width < 12) - add_x = ((12 - iVar3->width) / 2); + if (chrInfo->width < 12) + add_x = ((12 - chrInfo->width) / 2); else add_x = 0; - xxx_call_draw_char(x + add_x, y, uVar2, color, a4); + DrawCharOnWindow(x + add_x, y, chrId, color, windowId); } void sub_8012CAC(WindowTemplate *a0, const MenuItem *a1) @@ -1082,7 +1079,7 @@ void sub_8013C68(unkStructFor8013AA0 *a0) else ch = '0' + sp[i]; - sub_8012C60(a0->unk1C - ((i + 1) * 12), a0->unk20, ch, 7, a0->unk14); + DrawCharOnWindowWidth12(a0->unk1C - ((i + 1) * 12), a0->unk20, ch, 7, a0->unk14); } for (i = 0; i < a0->unk10; i++) diff --git a/src/naming_screen.c b/src/naming_screen.c index 45933a779..b40c636f0 100644 --- a/src/naming_screen.c +++ b/src/naming_screen.c @@ -346,17 +346,23 @@ void sub_80151A4(void) #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 sprite1Attribs[4]; - u16 sprite2Attribs[4]; + u16 spriteLetterCursor[4]; + u16 spriteInputCursor[4]; u8 letterCursorFrames; u8 inputCursorFrames; - u8 unk18; + u8 insOvr; u8 inputCursorArrId; // Always 0 u8 inputCursorPosition; u8 maxLetters; @@ -374,11 +380,11 @@ static EWRAM_INIT struct NamingScreen *sNamingScreen = NULL; static s32 GetEnteredNameLength(void); static void UpdateInputWindow(bool8); static void UpdateNameWindow(void); -void sub_8015F84(); +static void UpdateLetterWidths(void); static void SetLetterCursorSpritePosition(void); static void HandleInputCursor(void); -static void sub_8015E10(u8 *a0, s32 a1, s32 _a2); -static void sub_8015EB4(u8 *a0, s32 a1, s32 _a2); +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); @@ -406,7 +412,7 @@ u32 NamingScreen_Init(u32 type, u8 *defaultText) sNamingScreen = MemoryAlloc(sizeof(*sNamingScreen), 8); sNamingScreen->type = type; sNamingScreen->inputCursorArrId = 0; - sNamingScreen->unk18 = 0; + sNamingScreen->insOvr = MODE_OVR; sNamingScreen->isPassword = 0; switch (sNamingScreen->type) { @@ -451,32 +457,32 @@ u32 NamingScreen_Init(u32 type, u8 *defaultText) sNamingScreen->letterCursorPos--; } - SpriteSetAffine1((SpriteOAM *) &sNamingScreen->sprite1Attribs, 0); - SpriteSetAffine2((SpriteOAM *) &sNamingScreen->sprite1Attribs, 0); - SpriteSetObjMode((SpriteOAM *) &sNamingScreen->sprite1Attribs, 0); - SpriteSetMosaic((SpriteOAM *) &sNamingScreen->sprite1Attribs, 0); - SpriteSetBpp((SpriteOAM *) &sNamingScreen->sprite1Attribs, 0); - SpriteSetPriority((SpriteOAM *) &sNamingScreen->sprite1Attribs, 0); - SpriteSetPalNum((SpriteOAM *) &sNamingScreen->sprite1Attribs, 15); - SpriteSetX((SpriteOAM *) &sNamingScreen->sprite1Attribs, DISPLAY_WIDTH); - SpriteSetY((SpriteOAM *) &sNamingScreen->sprite1Attribs, DISPLAY_WIDTH); + SpriteSetAffine1((SpriteOAM *) &sNamingScreen->spriteLetterCursor, 0); + SpriteSetAffine2((SpriteOAM *) &sNamingScreen->spriteLetterCursor, 0); + SpriteSetObjMode((SpriteOAM *) &sNamingScreen->spriteLetterCursor, 0); + SpriteSetMosaic((SpriteOAM *) &sNamingScreen->spriteLetterCursor, 0); + SpriteSetBpp((SpriteOAM *) &sNamingScreen->spriteLetterCursor, 0); + SpriteSetPriority((SpriteOAM *) &sNamingScreen->spriteLetterCursor, 0); + SpriteSetPalNum((SpriteOAM *) &sNamingScreen->spriteLetterCursor, 15); + SpriteSetX((SpriteOAM *) &sNamingScreen->spriteLetterCursor, DISPLAY_WIDTH); + SpriteSetY((SpriteOAM *) &sNamingScreen->spriteLetterCursor, DISPLAY_WIDTH); if (sNamingScreen->isPassword) { - SpriteSetMatrixNum((SpriteOAM *) &sNamingScreen->sprite1Attribs, 0); - SpriteSetTileNum((SpriteOAM *) &sNamingScreen->sprite1Attribs, 0x3F6); - SpriteSetSize((SpriteOAM *) &sNamingScreen->sprite1Attribs, 0); - SpriteSetShape((SpriteOAM *) &sNamingScreen->sprite1Attribs, 1); + SpriteSetMatrixNum((SpriteOAM *) &sNamingScreen->spriteLetterCursor, 0); + SpriteSetTileNum((SpriteOAM *) &sNamingScreen->spriteLetterCursor, 0x3F6); + SpriteSetSize((SpriteOAM *) &sNamingScreen->spriteLetterCursor, 0); + SpriteSetShape((SpriteOAM *) &sNamingScreen->spriteLetterCursor, 1); } else { - SpriteSetMatrixNum((SpriteOAM *) &sNamingScreen->sprite1Attribs, 16); - SpriteSetTileNum((SpriteOAM *) &sNamingScreen->sprite1Attribs, 0x3F0); - SpriteSetSize((SpriteOAM *) &sNamingScreen->sprite1Attribs, 0); - SpriteSetShape((SpriteOAM *) &sNamingScreen->sprite1Attribs, 1); + SpriteSetMatrixNum((SpriteOAM *) &sNamingScreen->spriteLetterCursor, 16); + SpriteSetTileNum((SpriteOAM *) &sNamingScreen->spriteLetterCursor, 0x3F0); + SpriteSetSize((SpriteOAM *) &sNamingScreen->spriteLetterCursor, 0); + SpriteSetShape((SpriteOAM *) &sNamingScreen->spriteLetterCursor, 1); } sNamingScreen->letterCursorFrames = 4; - sprite = (SpriteOAM *) &sNamingScreen->sprite2Attribs; + sprite = (SpriteOAM *) &sNamingScreen->spriteInputCursor; SpriteSetAffine1(sprite, 0); SpriteSetAffine2(sprite, 0); @@ -511,7 +517,7 @@ u32 NamingScreen_Init(u32 type, u8 *defaultText) UpdateInputWindow(TRUE); UpdateNameWindow(); - sub_8015F84(); + UpdateLetterWidths(); return 1; } @@ -520,13 +526,13 @@ u32 NamingScreen_HandleInput(void) sNamingScreen->letterCursorFrames++; SetLetterCursorSpritePosition(); if (sNamingScreen->letterCursorFrames & 8) { - AddSprite((SpriteOAM *) &sNamingScreen->sprite1Attribs, 0x100, NULL, NULL); + AddSprite((SpriteOAM *) &sNamingScreen->spriteLetterCursor, 0x100, NULL, NULL); } sNamingScreen->inputCursorFrames++; HandleInputCursor(); if (sNamingScreen->inputCursorFrames & 8) { - AddSprite((SpriteOAM *) &sNamingScreen->sprite2Attribs, 0x100, NULL, NULL); + AddSprite((SpriteOAM *) &sNamingScreen->spriteInputCursor, 0x100, NULL, NULL); } switch (sub_8012AE8()) { @@ -578,7 +584,7 @@ static u32 HandleAPress(void) switch (letter) { case NAMING_LETTER_INS_OVR: - sNamingScreen->unk18 = (sNamingScreen->unk18 == 0); + sNamingScreen->insOvr = (sNamingScreen->insOvr == 0); // Flip PlayMenuSoundEffect(4); UpdateInputWindow(FALSE); break; @@ -602,7 +608,7 @@ static u32 HandleAPress(void) PlayMenuSoundEffect(2); } else { - if (sNamingScreen->unk18 == 1) { + if (sNamingScreen->insOvr == MODE_INS) { s32 i; for (i = sNamingScreen->maxLetters - 2; i >= sNamingScreen->letterCursorPos; i--) { u8 *ptr = &sNamingScreen->textPtr[i]; @@ -620,7 +626,7 @@ static u32 HandleAPress(void) PlayMenuSoundEffect(0); UpdateNameWindow(); - sub_8015F84(); + UpdateLetterWidths(); } break; } @@ -628,7 +634,7 @@ static u32 HandleAPress(void) return 0; } -bool8 HandleBPress(void) +static bool8 HandleBPress(void) { if (sNamingScreen->textPtr[sNamingScreen->letterCursorPos] == '\0') { if (sNamingScreen->letterCursorPos == 0) { @@ -640,7 +646,7 @@ bool8 HandleBPress(void) sNamingScreen->textPtr[sNamingScreen->letterCursorPos] = '\0'; PlayMenuSoundEffect(1); UpdateNameWindow(); - sub_8015F84(); + UpdateLetterWidths(); } } else { @@ -654,7 +660,7 @@ bool8 HandleBPress(void) sNamingScreen->textPtr[n] = 0; PlayMenuSoundEffect(1); UpdateNameWindow(); - sub_8015F84(); + UpdateLetterWidths(); } return FALSE; @@ -669,28 +675,28 @@ static void SetLetterCursorSpritePosition(void) s32 x, y; x = gUnknown_80DAFC0[sNamingScreen->letterCursorPos].x + (window->x * 8); - SpriteSetX((SpriteOAM *) &sNamingScreen->sprite1Attribs, x); + SpriteSetX((SpriteOAM *) &sNamingScreen->spriteLetterCursor, x); y = gUnknown_80DAFC0[sNamingScreen->letterCursorPos].y + (window->y * 8) + 5; - SpriteSetY((SpriteOAM *) &sNamingScreen->sprite1Attribs, y); + SpriteSetY((SpriteOAM *) &sNamingScreen->spriteLetterCursor, y); } else if (sNamingScreen->type == NAMING_PASSWORD2) { s32 x, y; x = gUnknown_80DB098[sNamingScreen->letterCursorPos].x + (window->x * 8); - SpriteSetX((SpriteOAM *) &sNamingScreen->sprite1Attribs, x); + SpriteSetX((SpriteOAM *) &sNamingScreen->spriteLetterCursor, x); y = gUnknown_80DB098[sNamingScreen->letterCursorPos].y + (window->y * 8) + 5; - SpriteSetY((SpriteOAM *) &sNamingScreen->sprite1Attribs, y); + SpriteSetY((SpriteOAM *) &sNamingScreen->spriteLetterCursor, y); } else { s32 x, y; x = sNamingScreen->letterTotalWidths[sNamingScreen->letterCursorPos] + (sNamingScreen->letterWidths[sNamingScreen->letterCursorPos] / 2) + 30 + (window->x * 8); - SpriteSetX((SpriteOAM *) &sNamingScreen->sprite1Attribs, (u16) x); + SpriteSetX((SpriteOAM *) &sNamingScreen->spriteLetterCursor, (u16) x); y = (window->y * 8) + 34; - SpriteSetY((SpriteOAM *) &sNamingScreen->sprite1Attribs, y); + SpriteSetY((SpriteOAM *) &sNamingScreen->spriteLetterCursor, y); } } @@ -726,8 +732,8 @@ static void HandleInputCursor(void) x = sLayoutInfo[sNamingScreen->inputCursorArrId][sNamingScreen->inputCursorPosition].x + (window->x * 8) - 5; y = sLayoutInfo[sNamingScreen->inputCursorArrId][sNamingScreen->inputCursorPosition].y + (window->y * 8) + 1; - SpriteSetX((SpriteOAM *) &sNamingScreen->sprite2Attribs, x); - SpriteSetY((SpriteOAM *) &sNamingScreen->sprite2Attribs, y); + SpriteSetX((SpriteOAM *) &sNamingScreen->spriteInputCursor, x); + SpriteSetY((SpriteOAM *) &sNamingScreen->spriteInputCursor, y); } static void UpdateInputWindow(bool8 unused) @@ -770,7 +776,7 @@ static void UpdateInputWindow(bool8 unused) if (letter != NAMING_LETTER_BLANK) { if (letter == NAMING_LETTER_INS_OVR) { - if (sNamingScreen->unk18 == 0) { + if (sNamingScreen->insOvr == MODE_OVR) { PrintStringOnWindow(sLayoutInfo[sNamingScreen->inputCursorArrId][i].x + 3, sLayoutInfo[sNamingScreen->inputCursorArrId][i].y, _("{COLOR GREEN}OVR{RESET}"), NAMING_WINDOW_INPUT, '\0'); } else { @@ -786,7 +792,7 @@ static void UpdateInputWindow(bool8 unused) PrintStringOnWindow(sLayoutInfo[sNamingScreen->inputCursorArrId][i].x + 3, sLayoutInfo[sNamingScreen->inputCursorArrId][i].y, text2, NAMING_WINDOW_INPUT, '\0'); } else { - sub_8012C60(sLayoutInfo[sNamingScreen->inputCursorArrId][i].x, sLayoutInfo[sNamingScreen->inputCursorArrId][i].y, (u8) letter, color, 0); + DrawCharOnWindowWidth12(sLayoutInfo[sNamingScreen->inputCursorArrId][i].x, sLayoutInfo[sNamingScreen->inputCursorArrId][i].y, (u8) letter, color, 0); } } } @@ -840,10 +846,10 @@ static void UpdateNameWindow(void) switch (sNamingScreen->type) { case NAMING_PASSWORD1: - sub_8015E10(sNamingScreen->textPtr, 1, 0); + UpdatePassword1Window(sNamingScreen->textPtr, NAMING_WINDOW_NAME, 0); break; case NAMING_PASSWORD2: - sub_8015EB4(sNamingScreen->textPtr, 1, 0); + UpdatePassword2Window(sNamingScreen->textPtr, NAMING_WINDOW_NAME, 0); break; case NAMING_SELF: case NAMING_TEAM: @@ -866,51 +872,51 @@ static void UpdateNameWindow(void) sub_80073E0(NAMING_WINDOW_NAME); } -static void sub_8015E10(u8 *a0, s32 a1, s32 _a2) +static void UpdatePassword1Window(u8 *text, s32 windowId, s32 _yAdd) { s32 i; - s32 a2 = (s16) _a2; + s32 yAdd = (s16) _yAdd; for (i = 0; i < ARRAY_COUNT_INT(gUnknown_80DAFC0); i++) { - AddDoubleUnderScoreHighlight(a1, gUnknown_80DAFC0[i].x, gUnknown_80DAFC0[i].y + 11 + a2, 11, 5); + AddDoubleUnderScoreHighlight(windowId, gUnknown_80DAFC0[i].x, gUnknown_80DAFC0[i].y + 11 + yAdd, 11, 5); } - for (i = 0; i < ARRAY_COUNT_INT(gUnknown_80DAFC0) && a0[i] != 0; i++) { - s32 arg3; + for (i = 0; i < ARRAY_COUNT_INT(gUnknown_80DAFC0) && text[i] != '\0'; i++) { + s32 color; - if (i <= 4) arg3 = 7; - else if (i <= 12) arg3 = 6; - else if (i <= 17) arg3 = 7; - else if (i <= 22) arg3 = 7; - else if (i <= 30) arg3 = 6; - else if (i <= 35) arg3 = 7; - else if (i <= 40) arg3 = 7; - else if (i <= 48) arg3 = 6; - else arg3 = 7; + if (i <= 4) color = 7; + else if (i <= 12) color = 6; + else if (i <= 17) color = 7; + else if (i <= 22) color = 7; + else if (i <= 30) color = 6; + else if (i <= 35) color = 7; + else if (i <= 40) color = 7; + else if (i <= 48) color = 6; + else color = 7; - sub_8012C60(gUnknown_80DAFC0[i].x, gUnknown_80DAFC0[i].y + a2, a0[i], arg3, a1); + DrawCharOnWindowWidth12(gUnknown_80DAFC0[i].x, gUnknown_80DAFC0[i].y + yAdd, text[i], color, windowId); } } -static void sub_8015EB4(u8 *a0, s32 a1, s32 _a2) +static void UpdatePassword2Window(u8 *text, s32 windowId, s32 _yAdd) { s32 i; - s32 a2 = (s16) _a2; + s32 yAdd = (s16) _yAdd; for (i = 0; i < ARRAY_COUNT_INT(gUnknown_80DB098); i++) { - AddDoubleUnderScoreHighlight(a1, gUnknown_80DB098[i].x, gUnknown_80DB098[i].y + 11 + a2, 12, 5); + AddDoubleUnderScoreHighlight(windowId, gUnknown_80DB098[i].x, gUnknown_80DB098[i].y + 11 + yAdd, 12, 5); } - for (i = 0; i < ARRAY_COUNT_INT(gUnknown_80DB098) && a0[i] != 0; i++) { - s32 arg3; + for (i = 0; i < ARRAY_COUNT_INT(gUnknown_80DB098) && text[i] != '\0'; i++) { + s32 color; - if (i <= 3) arg3 = 7; - else if (i <= 7) arg3 = 6; - else if (i <= 15) arg3 = 7; - else if (i <= 19) arg3 = 6; - else arg3 = 7; + if (i <= 3) color = 7; + else if (i <= 7) color = 6; + else if (i <= 15) color = 7; + else if (i <= 19) color = 6; + else color = 7; - sub_8012C60(gUnknown_80DB098[i].x, gUnknown_80DB098[i].y + a2, a0[i], arg3, a1); + DrawCharOnWindowWidth12(gUnknown_80DB098[i].x, gUnknown_80DB098[i].y + yAdd, text[i], color, windowId); } } @@ -931,10 +937,10 @@ static s32 GetEnteredNameLength(void) return len; } -void sub_8015F84(void) +static void UpdateLetterWidths(void) { - u32 uVar2; - const unkChar *puVar3; + u32 chrId; + const unkChar *chrInfo; s32 i; s32 total = 0; @@ -944,10 +950,10 @@ void sub_8015F84(void) sNamingScreen->letterWidths[i] = 8; return; } - uVar2 = ReturnIntFromChar2(sNamingScreen->textPtr[i]); - puVar3 = GetCharacter(uVar2); - sNamingScreen->letterWidths[i] = puVar3->width; - total += puVar3->width; + chrId = ReturnIntFromChar2(sNamingScreen->textPtr[i]); + chrInfo = GetCharacter(chrId); + sNamingScreen->letterWidths[i] = chrInfo->width; + total += chrInfo->width; } } diff --git a/src/pokemon_mail.c b/src/pokemon_mail.c index a62b9b751..c7308b826 100644 --- a/src/pokemon_mail.c +++ b/src/pokemon_mail.c @@ -379,7 +379,7 @@ void CreateRescueDescription(unkStruct_802C39C *param_1) } x = counter % 12; - sub_8012C60((x * 10) + 84, y, local_34[counter], color, param_1->unk0[0]); + DrawCharOnWindowWidth12((x * 10) + 84, y, local_34[counter], color, param_1->unk0[0]); } } } diff --git a/src/string_format.c b/src/string_format.c index 3527bf375..4161f829d 100644 --- a/src/string_format.c +++ b/src/string_format.c @@ -376,7 +376,7 @@ void DrawDialogueBoxString(void) u32 chr; str = xxx_get_next_char_from_string(str, &chr); - gUnknown_202E748.unk0 += xxx_call_draw_char(gUnknown_202E748.unk0, gUnknown_202E748.unk2, chr, gUnknown_202E748.unk10, 0); + gUnknown_202E748.unk0 += DrawCharOnWindow(gUnknown_202E748.unk0, gUnknown_202E748.unk2, chr, gUnknown_202E748.unk10, 0); gUnknown_202E748.unk2C = gUnknown_202E78C; } diff --git a/src/text_2.c b/src/text_2.c index c24504e5b..0497dc253 100644 --- a/src/text_2.c +++ b/src/text_2.c @@ -24,9 +24,9 @@ static bool8 xxx_update_bg_vram(Window *windows); // TODO: Find these funcs in blue. DTCM funcs // In NDS, this func is copied to 01FF9F34 -u32 xxx_call_draw_char(s32 x, s32 y, u32 chr, u32 color, u32 windowId) +u32 DrawCharOnWindow(s32 x, s32 y, u32 chr, u32 color, u32 windowId) { - return xxx_draw_char(gWindows, x, y, chr, color, windowId); + return DrawCharOnWindowInternal(gWindows, x, y, chr, color, windowId); } UNUSED static bool8 sub_8007464(void) @@ -35,7 +35,7 @@ UNUSED static bool8 sub_8007464(void) } // In NDS, this func is copied to 01FF994C -u32 xxx_draw_char(Window *windows, s32 x, s32 y, u32 chr, u32 color, u32 windowId) +u32 DrawCharOnWindowInternal(Window *windows, s32 x, s32 y, u32 chr, u32 color, u32 windowId) { u32 *r3; const unkShiftData *shiftData; diff --git a/src/text_3.c b/src/text_3.c index 0ff5aa8a8..8e0296cdb 100644 --- a/src/text_3.c +++ b/src/text_3.c @@ -6,7 +6,7 @@ static const u8 *HandleTextFormat(Window *windows, const u8 *str, UnkDrawStringStruct *sp); static s32 InterpretColorChar(u8 a0); static const u8 *sub_800915C(s16 *a0, const u8 *str); -static void xxx_draw_string(Window *strArr, s32 x, s32 y, const u8 *str, u32 windowId, u32 terminatingChr, s32 characterSpacing, s32 lineSpacing); +static void DrawStringInternal(Window *windows, s32 x, s32 y, const u8 *str, u32 windowId, u32 terminatingChr, s32 characterSpacing, s32 lineSpacing); // arm9.bin::02003D4C bool8 sub_8008D8C(s32 windowId) @@ -140,13 +140,13 @@ s32 sub_8008ED0(const u8 *str) // arm9.bin::02003AE8 void PrintStringOnWindow2(s32 x, s32 y, const u8 *str, u32 windowId, u32 terminatingChr, s32 lineSpacing) { - xxx_draw_string(gWindows, x, y, str, windowId, terminatingChr, 0, lineSpacing); + DrawStringInternal(gWindows, x, y, str, windowId, terminatingChr, 0, lineSpacing); } // arm9.bin::02003A9C void PrintStringOnWindow(s32 x, s32 y, const u8 *str, u32 windowId, u32 terminatingChr) { - xxx_draw_string(gWindows, x, y, str, windowId, terminatingChr, 0, 13); + DrawStringInternal(gWindows, x, y, str, windowId, terminatingChr, 0, 13); } // arm9.bin::02003A50 @@ -159,7 +159,7 @@ UNUSED static void nullsub_170(s32 x, s32 y, const u8 *str, u32 windowId, u32 te // Identical to PrintStringOnWindow UNUSED static void UnusedPrintStringOnWindow(s32 x, u32 y, const u8 *str, u32 windowId, u32 terminatingChr) { - xxx_draw_string(gWindows, x, y, str, windowId, terminatingChr, 0, 13); + DrawStringInternal(gWindows, x, y, str, windowId, terminatingChr, 0, 13); } UNUSED static void nullsub_171(void) @@ -168,7 +168,7 @@ UNUSED static void nullsub_171(void) #endif // arm9.bin::020038A4 -static void xxx_draw_string(Window *strArr, s32 x, s32 y, const u8 *str, u32 windowId, u32 terminatingChr, s32 characterSpacing, s32 lineSpacing) +static void DrawStringInternal(Window *windows, s32 x, s32 y, const u8 *str, u32 windowId, u32 terminatingChr, s32 characterSpacing, s32 lineSpacing) { UnkDrawStringStruct sp; u32 currChr; @@ -178,7 +178,7 @@ static void xxx_draw_string(Window *strArr, s32 x, s32 y, const u8 *str, u32 win sp.unkC = x; sp.unk10 = 7; while (TRUE) { - str = HandleTextFormat(strArr, str, &sp); + str = HandleTextFormat(windows, str, &sp); str = xxx_get_next_char_from_string(str, &currChr); if (currChr == '\0' || currChr == terminatingChr) break; @@ -204,7 +204,7 @@ static void xxx_draw_string(Window *strArr, s32 x, s32 y, const u8 *str, u32 win sp.unk0 += 6; } else if (characterSpacing == 0) { - sp.unk0 += xxx_draw_char(strArr, sp.unk0, sp.unk2, currChr, sp.unk10, windowId); + sp.unk0 += DrawCharOnWindowInternal(windows, sp.unk0, sp.unk2, currChr, sp.unk10, windowId); } else { const unkChar *chrPtr = GetCharacter(currChr); @@ -212,7 +212,7 @@ static void xxx_draw_string(Window *strArr, s32 x, s32 y, const u8 *str, u32 win s32 x = sp.unk0; s32 x2 = gCharacterSpacing + 10; x +=((x2 - chrPtr->width) / 2); - xxx_draw_char(strArr, x, sp.unk2, currChr, sp.unk10, windowId); + DrawCharOnWindowInternal(windows, x, sp.unk2, currChr, sp.unk10, windowId); sp.unk0 += characterSpacing; } } From 12df1f050e31a56f09db4d97e21fab13ef8f549b Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Tue, 3 Jun 2025 10:23:47 +0200 Subject: [PATCH 4/7] 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" From 1953171ad9272187181db51895b579a9f3c7f408 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Tue, 3 Jun 2025 11:34:58 +0200 Subject: [PATCH 5/7] Finish naming screen documentation --- src/code_8015080.c | 13 +++---------- src/naming_screen.c | 30 ++++++++++++++---------------- 2 files changed, 17 insertions(+), 26 deletions(-) diff --git a/src/code_8015080.c b/src/code_8015080.c index 067dd7faf..f547dc339 100644 --- a/src/code_8015080.c +++ b/src/code_8015080.c @@ -25,14 +25,7 @@ struct unkStruct_203B1F8 EWRAM_INIT struct unkStruct_203B1F8 *gUnknown_203B1F8 = {NULL}; -const WindowTemplate gUnknown_80DAF70 = { - 0x00, - 0x03, - 0x00, 0x00, - 0x00, 0x00, - 0x00, 0x00, - NULL -}; +static const WindowTemplate sWindowTemplateDummy = WIN_TEMPLATE_DUMMY; const WindowTemplate gUnknown_80DAF88 = { 0x00, @@ -59,9 +52,9 @@ bool8 sub_8015080(u8 *buffer, const MenuItem *menuItems) gUnknown_203B1F8 = MemoryAlloc(sizeof(struct unkStruct_203B1F8), 8); gUnknown_203B1F8->menuAction = 0; - for(index = 0; index < 4; index++) + for(index = 0; index < MAX_WINDOWS; index++) { - gUnknown_203B1F8->windows.id[index] = gUnknown_80DAF70; + gUnknown_203B1F8->windows.id[index] = sWindowTemplateDummy; } gUnknown_203B1F8->windows.id[0] = gUnknown_80DAF88; diff --git a/src/naming_screen.c b/src/naming_screen.c index bd786fa31..bdafff9f1 100644 --- a/src/naming_screen.c +++ b/src/naming_screen.c @@ -56,8 +56,6 @@ 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); @@ -86,7 +84,7 @@ struct LayoutInfo s32 letter; }; -static const DungeonPos gUnknown_80DAFC0[] = +static const DungeonPos sPassword1CursorPositions[] = { {3, 0xD}, {0xF, 0xD}, @@ -144,7 +142,7 @@ static const DungeonPos gUnknown_80DAFC0[] = {0xD1, 0x28}, }; -static const DungeonPos gUnknown_80DB098[] = +static const DungeonPos sPassword2CursorPositions[] = { {0x20, 0x12}, {0x2E, 0x12}, @@ -591,19 +589,19 @@ static void SetLetterCursorSpritePosition(void) if (sNamingScreen->type == NAMING_PASSWORD1) { s32 x, y; - x = gUnknown_80DAFC0[sNamingScreen->letterCursorPos].x + (window->x * 8); + x = sPassword1CursorPositions[sNamingScreen->letterCursorPos].x + (window->x * 8); SpriteSetX((SpriteOAM *) &sNamingScreen->spriteLetterCursor, x); - y = gUnknown_80DAFC0[sNamingScreen->letterCursorPos].y + (window->y * 8) + 5; + y = sPassword1CursorPositions[sNamingScreen->letterCursorPos].y + (window->y * 8) + 5; SpriteSetY((SpriteOAM *) &sNamingScreen->spriteLetterCursor, y); } else if (sNamingScreen->type == NAMING_PASSWORD2) { s32 x, y; - x = gUnknown_80DB098[sNamingScreen->letterCursorPos].x + (window->x * 8); + x = sPassword2CursorPositions[sNamingScreen->letterCursorPos].x + (window->x * 8); SpriteSetX((SpriteOAM *) &sNamingScreen->spriteLetterCursor, x); - y = gUnknown_80DB098[sNamingScreen->letterCursorPos].y + (window->y * 8) + 5; + y = sPassword2CursorPositions[sNamingScreen->letterCursorPos].y + (window->y * 8) + 5; SpriteSetY((SpriteOAM *) &sNamingScreen->spriteLetterCursor, y); } else { @@ -794,11 +792,11 @@ static void UpdatePassword1Window(u8 *text, s32 windowId, s32 _yAdd) s32 i; s32 yAdd = (s16) _yAdd; - for (i = 0; i < ARRAY_COUNT_INT(gUnknown_80DAFC0); i++) { - AddDoubleUnderScoreHighlight(windowId, gUnknown_80DAFC0[i].x, gUnknown_80DAFC0[i].y + 11 + yAdd, 11, 5); + for (i = 0; i < ARRAY_COUNT_INT(sPassword1CursorPositions); i++) { + AddDoubleUnderScoreHighlight(windowId, sPassword1CursorPositions[i].x, sPassword1CursorPositions[i].y + 11 + yAdd, 11, 5); } - for (i = 0; i < ARRAY_COUNT_INT(gUnknown_80DAFC0) && text[i] != '\0'; i++) { + for (i = 0; i < ARRAY_COUNT_INT(sPassword1CursorPositions) && text[i] != '\0'; i++) { s32 color; if (i <= 4) color = 7; @@ -811,7 +809,7 @@ static void UpdatePassword1Window(u8 *text, s32 windowId, s32 _yAdd) else if (i <= 48) color = 6; else color = 7; - DrawCharOnWindowWidth12(gUnknown_80DAFC0[i].x, gUnknown_80DAFC0[i].y + yAdd, text[i], color, windowId); + DrawCharOnWindowWidth12(sPassword1CursorPositions[i].x, sPassword1CursorPositions[i].y + yAdd, text[i], color, windowId); } } @@ -820,11 +818,11 @@ static void UpdatePassword2Window(u8 *text, s32 windowId, s32 _yAdd) s32 i; s32 yAdd = (s16) _yAdd; - for (i = 0; i < ARRAY_COUNT_INT(gUnknown_80DB098); i++) { - AddDoubleUnderScoreHighlight(windowId, gUnknown_80DB098[i].x, gUnknown_80DB098[i].y + 11 + yAdd, 12, 5); + for (i = 0; i < ARRAY_COUNT_INT(sPassword2CursorPositions); i++) { + AddDoubleUnderScoreHighlight(windowId, sPassword2CursorPositions[i].x, sPassword2CursorPositions[i].y + 11 + yAdd, 12, 5); } - for (i = 0; i < ARRAY_COUNT_INT(gUnknown_80DB098) && text[i] != '\0'; i++) { + for (i = 0; i < ARRAY_COUNT_INT(sPassword2CursorPositions) && text[i] != '\0'; i++) { s32 color; if (i <= 3) color = 7; @@ -833,7 +831,7 @@ static void UpdatePassword2Window(u8 *text, s32 windowId, s32 _yAdd) else if (i <= 19) color = 6; else color = 7; - DrawCharOnWindowWidth12(gUnknown_80DB098[i].x, gUnknown_80DB098[i].y + yAdd, text[i], color, windowId); + DrawCharOnWindowWidth12(sPassword2CursorPositions[i].x, sPassword2CursorPositions[i].y + yAdd, text[i], color, windowId); } } From c3e9a5cf504590e1a260692ba52b67840c283228 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Tue, 3 Jun 2025 11:40:38 +0200 Subject: [PATCH 6/7] remove not needed include file --- include/code_8012A18_1.h | 7 ------- src/code_801602C.c | 1 - src/pokemon_mail.c | 2 +- 3 files changed, 1 insertion(+), 9 deletions(-) delete mode 100644 include/code_8012A18_1.h diff --git a/include/code_8012A18_1.h b/include/code_8012A18_1.h deleted file mode 100644 index 68df79c40..000000000 --- a/include/code_8012A18_1.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef GUARD_CODE_8012A18_1_H -#define GUARD_CODE_8012A18_1_H - -s32 GetStrWidth(u8 *buffer, s32 size); -s32 GetMaxPokeNameWidth(void); - -#endif // GUARD_CODE_8012A18_1_H diff --git a/src/code_801602C.c b/src/code_801602C.c index 9d9ef52c3..27f8c43f3 100644 --- a/src/code_801602C.c +++ b/src/code_801602C.c @@ -1,6 +1,5 @@ #include "global.h" #include "globaldata.h" -#include "code_8012A18_1.h" #include "code_801602C.h" #include "common_strings.h" #include "input.h" diff --git a/src/pokemon_mail.c b/src/pokemon_mail.c index c7308b826..724264b49 100644 --- a/src/pokemon_mail.c +++ b/src/pokemon_mail.c @@ -2,7 +2,6 @@ #include "globaldata.h" #include "constants/colors.h" #include "code_800D090.h" -#include "code_8012A18_1.h" #include "code_803C1D0.h" #include "code_803D0D8.h" #include "dungeon.h" @@ -17,6 +16,7 @@ #include "string_format.h" #include "text_3.h" #include "text_util.h" +#include "naming_screen.h" #include "data/pokemon_mail.h" From a36d84f07db05ecfe68b8fe64796b2d891af7a01 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Wed, 4 Jun 2025 09:16:42 +0200 Subject: [PATCH 7/7] use COLOR constants in naming screem --- src/naming_screen.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/src/naming_screen.c b/src/naming_screen.c index bdafff9f1..651783eaa 100644 --- a/src/naming_screen.c +++ b/src/naming_screen.c @@ -14,6 +14,7 @@ #include "text_3.h" #include "text_util.h" #include "constants/input.h" +#include "constants/colors.h" #define MAX_TEXT_SIZE 54 @@ -666,24 +667,24 @@ static void UpdateInputWindow(bool8 unused) switch (sLayoutInfo[sNamingScreen->inputCursorArrId][i].colorType) { case 1: - color = 5; + color = COLOR_CYAN; break; case 2: - color = 2; + color = COLOR_RED; break; case 3: - color = 7; + color = COLOR_WHITE_2; break; default: - color = 7; + color = COLOR_WHITE_2; if (sNamingScreen->isPassword) { if (letter <= 0xFF) { if (sub_803D0F0(letter) == 0xFF) { - color = 2; + color = COLOR_RED; } } else if (letter < 0x102) { - color = 2; + color = COLOR_RED; } } break; @@ -799,14 +800,14 @@ static void UpdatePassword1Window(u8 *text, s32 windowId, s32 _yAdd) for (i = 0; i < ARRAY_COUNT_INT(sPassword1CursorPositions) && text[i] != '\0'; i++) { s32 color; - if (i <= 4) color = 7; - else if (i <= 12) color = 6; - else if (i <= 17) color = 7; - else if (i <= 22) color = 7; - else if (i <= 30) color = 6; - else if (i <= 35) color = 7; - else if (i <= 40) color = 7; - else if (i <= 48) color = 6; + if (i <= 4) color = COLOR_WHITE_2; + else if (i <= 12) color = COLOR_YELLOW; + else if (i <= 17) color = COLOR_WHITE_2; + else if (i <= 22) color = COLOR_WHITE_2; + else if (i <= 30) color = COLOR_YELLOW; + else if (i <= 35) color = COLOR_WHITE_2; + else if (i <= 40) color = COLOR_WHITE_2; + else if (i <= 48) color = COLOR_YELLOW; else color = 7; DrawCharOnWindowWidth12(sPassword1CursorPositions[i].x, sPassword1CursorPositions[i].y + yAdd, text[i], color, windowId); @@ -825,11 +826,11 @@ static void UpdatePassword2Window(u8 *text, s32 windowId, s32 _yAdd) for (i = 0; i < ARRAY_COUNT_INT(sPassword2CursorPositions) && text[i] != '\0'; i++) { s32 color; - if (i <= 3) color = 7; - else if (i <= 7) color = 6; - else if (i <= 15) color = 7; - else if (i <= 19) color = 6; - else color = 7; + if (i <= 3) color = COLOR_WHITE_2; + else if (i <= 7) color = COLOR_YELLOW; + else if (i <= 15) color = COLOR_WHITE_2; + else if (i <= 19) color = COLOR_YELLOW; + else color = COLOR_WHITE_2; DrawCharOnWindowWidth12(sPassword2CursorPositions[i].x, sPassword2CursorPositions[i].y + yAdd, text[i], color, windowId); }