From cda5c5f925024acca194837007b9f88597ce4db8 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Fri, 20 Oct 2017 18:52:01 +0200 Subject: [PATCH 1/3] start working on walda phrase --- asm/pokemon_storage_system.s | 84 ++++---- asm/rayquaza_scene.s | 4 +- asm/walda_phrase.s | 375 ----------------------------------- data/specials.inc | 4 +- data/walda_phrase.s | 7 - include/global.h | 12 +- include/naming_screen.h | 2 +- include/new_game.h | 1 + ld_script.txt | 3 +- src/walda_phrase.c | 185 +++++++++++++++++ 10 files changed, 246 insertions(+), 431 deletions(-) delete mode 100644 data/walda_phrase.s create mode 100644 src/walda_phrase.c diff --git a/asm/pokemon_storage_system.s b/asm/pokemon_storage_system.s index 298409e9c..d1f7bd161 100755 --- a/asm/pokemon_storage_system.s +++ b/asm/pokemon_storage_system.s @@ -1043,7 +1043,7 @@ _080C77C2: lsrs r5, r0, 16 cmp r5, 0xD bls _080C77C2 - bl sub_80D242C + bl ResetWaldaWallpaper pop {r4-r6} pop {r0} bx r0 @@ -7122,7 +7122,7 @@ sub_80CADD8: @ 80CADD8 bl sub_80CFF34 movs r0, 0x15 bl sub_80CFF34 - bl sub_80D2494 + bl IsWaldaWallpaperUnlocked cmp r0, 0 beq _080CAE04 movs r0, 0x16 @@ -10421,7 +10421,7 @@ _080CC888: b _080CC9DA .pool _080CC8C4: - bl sub_80D24A8 + bl GetWaldaWallpaperPatternId lsls r1, r0, 1 adds r1, r0 lsls r1, 2 @@ -10448,13 +10448,13 @@ _080CC8C4: adds r1, r4 movs r2, 0x20 bl CpuSet - bl sub_80D2510 + bl GetWaldaWallpaperColorsPtr ldr r1, [r7] ldr r2, =0x00000794 adds r1, r2 movs r2, 0x2 bl CpuSet - bl sub_80D2510 + bl GetWaldaWallpaperColorsPtr ldr r1, [r7] ldr r3, =0x000007b4 adds r1, r3 @@ -10500,7 +10500,7 @@ _080CC976: adds r1, r5 str r0, [r1] ldr r4, =gUnknown_0857B004 - bl sub_80D24DC + bl GetWaldaWallpaperIconId lsls r0, 2 adds r0, r4 ldr r0, [r0] @@ -21544,8 +21544,8 @@ _080D241E: bx r1 thumb_func_end sub_80D23A8 - thumb_func_start sub_80D242C -sub_80D242C: @ 80D242C + thumb_func_start ResetWaldaWallpaper +ResetWaldaWallpaper: @ 80D242C ldr r2, =gSaveBlock1Ptr ldr r0, [r2] ldr r1, =0x00003d84 @@ -21575,10 +21575,10 @@ sub_80D242C: @ 80D242C strb r0, [r1] bx lr .pool - thumb_func_end sub_80D242C + thumb_func_end ResetWaldaWallpaper - thumb_func_start sub_80D2480 -sub_80D2480: @ 80D2480 + thumb_func_start SetWaldaWallpaperLockedOrUnlocked +SetWaldaWallpaperLockedOrUnlocked: @ 80D2480 ldr r1, =gSaveBlock1Ptr ldr r1, [r1] ldr r2, =0x00003d86 @@ -21586,10 +21586,10 @@ sub_80D2480: @ 80D2480 strb r0, [r1] bx lr .pool - thumb_func_end sub_80D2480 + thumb_func_end SetWaldaWallpaperLockedOrUnlocked - thumb_func_start sub_80D2494 -sub_80D2494: @ 80D2494 + thumb_func_start IsWaldaWallpaperUnlocked +IsWaldaWallpaperUnlocked: @ 80D2494 ldr r0, =gSaveBlock1Ptr ldr r0, [r0] ldr r1, =0x00003d86 @@ -21597,10 +21597,10 @@ sub_80D2494: @ 80D2494 ldrb r0, [r0] bx lr .pool - thumb_func_end sub_80D2494 + thumb_func_end IsWaldaWallpaperUnlocked - thumb_func_start sub_80D24A8 -sub_80D24A8: @ 80D24A8 + thumb_func_start GetWaldaWallpaperPatternId +GetWaldaWallpaperPatternId: @ 80D24A8 ldr r0, =gSaveBlock1Ptr ldr r0, [r0] ldr r1, =0x00003d85 @@ -21608,10 +21608,10 @@ sub_80D24A8: @ 80D24A8 ldrb r0, [r0] bx lr .pool - thumb_func_end sub_80D24A8 + thumb_func_end GetWaldaWallpaperPatternId - thumb_func_start sub_80D24BC -sub_80D24BC: @ 80D24BC + thumb_func_start SetWaldaWallpaperPatternId +SetWaldaWallpaperPatternId: @ 80D24BC push {lr} lsls r0, 24 lsrs r1, r0, 24 @@ -21626,10 +21626,10 @@ _080D24D0: pop {r0} bx r0 .pool - thumb_func_end sub_80D24BC + thumb_func_end SetWaldaWallpaperPatternId - thumb_func_start sub_80D24DC -sub_80D24DC: @ 80D24DC + thumb_func_start GetWaldaWallpaperIconId +GetWaldaWallpaperIconId: @ 80D24DC ldr r0, =gSaveBlock1Ptr ldr r0, [r0] ldr r1, =0x00003d84 @@ -21637,10 +21637,10 @@ sub_80D24DC: @ 80D24DC ldrb r0, [r0] bx lr .pool - thumb_func_end sub_80D24DC + thumb_func_end GetWaldaWallpaperIconId - thumb_func_start sub_80D24F0 -sub_80D24F0: @ 80D24F0 + thumb_func_start SetWaldaWallpaperIconId +SetWaldaWallpaperIconId: @ 80D24F0 push {lr} lsls r0, 24 lsrs r1, r0, 24 @@ -21655,20 +21655,20 @@ _080D2504: pop {r0} bx r0 .pool - thumb_func_end sub_80D24F0 + thumb_func_end SetWaldaWallpaperIconId - thumb_func_start sub_80D2510 -sub_80D2510: @ 80D2510 + thumb_func_start GetWaldaWallpaperColorsPtr +GetWaldaWallpaperColorsPtr: @ 80D2510 ldr r0, =gSaveBlock1Ptr ldr r0, [r0] ldr r1, =0x00003d70 adds r0, r1 bx lr .pool - thumb_func_end sub_80D2510 + thumb_func_end GetWaldaWallpaperColorsPtr - thumb_func_start sub_80D2524 -sub_80D2524: @ 80D2524 + thumb_func_start SetWaldaWallpaperColors +SetWaldaWallpaperColors: @ 80D2524 push {r4,lr} ldr r2, =gSaveBlock1Ptr ldr r2, [r2] @@ -21682,20 +21682,20 @@ sub_80D2524: @ 80D2524 pop {r0} bx r0 .pool - thumb_func_end sub_80D2524 + thumb_func_end SetWaldaWallpaperColors - thumb_func_start sub_80D2548 -sub_80D2548: @ 80D2548 + thumb_func_start GetWaldaPhrasePtr +GetWaldaPhrasePtr: @ 80D2548 ldr r0, =gSaveBlock1Ptr ldr r0, [r0] ldr r1, =0x00003d74 adds r0, r1 bx lr .pool - thumb_func_end sub_80D2548 + thumb_func_end GetWaldaPhrasePtr - thumb_func_start sub_80D255C -sub_80D255C: @ 80D255C + thumb_func_start SetWaldaPhrase +SetWaldaPhrase: @ 80D255C push {lr} adds r1, r0, 0 ldr r0, =gSaveBlock1Ptr @@ -21706,10 +21706,10 @@ sub_80D255C: @ 80D255C pop {r0} bx r0 .pool - thumb_func_end sub_80D255C + thumb_func_end SetWaldaPhrase - thumb_func_start sub_80D2578 -sub_80D2578: @ 80D2578 + thumb_func_start IsWaldaPhraseEmpty +IsWaldaPhraseEmpty: @ 80D2578 push {lr} movs r1, 0 ldr r0, =gSaveBlock1Ptr @@ -21725,7 +21725,7 @@ _080D258C: pop {r1} bx r1 .pool - thumb_func_end sub_80D2578 + thumb_func_end IsWaldaPhraseEmpty thumb_func_start sub_80D259C sub_80D259C: @ 80D259C diff --git a/asm/rayquaza_scene.s b/asm/rayquaza_scene.s index fdfd22979..1649f0131 100755 --- a/asm/rayquaza_scene.s +++ b/asm/rayquaza_scene.s @@ -5971,11 +5971,11 @@ _081D99B4: thumb_func_start sub_81D99BC sub_81D99BC: @ 81D99BC push {r4,lr} - bl sub_80D2578 + bl IsWaldaPhraseEmpty cmp r0, 0 bne _081D99DC ldr r4, =gStringVar1 - bl sub_80D2548 + bl GetWaldaPhrasePtr adds r1, r0, 0 adds r0, r4, 0 bl StringCopy diff --git a/asm/walda_phrase.s b/asm/walda_phrase.s index be754f386..f6f55a668 100755 --- a/asm/walda_phrase.s +++ b/asm/walda_phrase.s @@ -5,382 +5,7 @@ .text - thumb_func_start walda_maybe -walda_maybe: @ 81D99E4 - push {r4,lr} - sub sp, 0x8 - ldr r4, =gStringVar2 - bl sub_80D2548 - adds r1, r0, 0 - adds r0, r4, 0 - bl StringCopy - movs r0, 0 - str r0, [sp] - ldr r0, =sub_81D9A1C - str r0, [sp, 0x4] - movs r0, 0x4 - adds r1, r4, 0 - movs r2, 0 - movs r3, 0 - bl DoNamingScreen - add sp, 0x8 - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end walda_maybe - thumb_func_start sub_81D9A1C -sub_81D9A1C: @ 81D9A1C - push {r4,r5,lr} - ldr r4, =gSpecialVar_0x8004 - ldr r5, =gStringVar2 - adds r0, r5, 0 - bl sub_81D9A98 - strh r0, [r4] - ldrh r0, [r4] - cmp r0, 0x1 - beq _081D9A68 - cmp r0, 0x1 - bgt _081D9A44 - cmp r0, 0 - beq _081D9A62 - b _081D9A68 - .pool -_081D9A44: - cmp r0, 0x2 - bne _081D9A68 - bl sub_80D2578 - cmp r0, 0 - beq _081D9A5C - ldr r0, =gText_Peekaboo - bl sub_80D255C - b _081D9A68 - .pool -_081D9A5C: - movs r0, 0x1 - strh r0, [r4] - b _081D9A68 -_081D9A62: - adds r0, r5, 0 - bl sub_80D255C -_081D9A68: - ldr r4, =gStringVar1 - bl sub_80D2548 - adds r1, r0, 0 - adds r0, r4, 0 - bl StringCopy - ldr r1, =gFieldCallback - ldr r0, =sub_80AF168 - str r0, [r1] - ldr r0, =c2_exit_to_overworld_2_switch - bl SetMainCallback2 - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81D9A1C - - thumb_func_start sub_81D9A98 -sub_81D9A98: @ 81D9A98 - push {r4,lr} - adds r4, r0, 0 - ldrb r0, [r4] - cmp r0, 0xFF - bne _081D9AA6 - movs r0, 0x2 - b _081D9ABC -_081D9AA6: - bl sub_80D2548 - adds r1, r0, 0 - adds r0, r4, 0 - bl StringCompare - cmp r0, 0 - beq _081D9ABA - movs r0, 0 - b _081D9ABC -_081D9ABA: - movs r0, 0x1 -_081D9ABC: - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_81D9A98 - - thumb_func_start sub_81D9AC4 -sub_81D9AC4: @ 81D9AC4 - push {r4-r7,lr} - mov r7, r8 - push {r7} - sub sp, 0x10 - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - adds r0, 0xA - bl ReadUnalignedWord - adds r4, r0, 0 - lsls r4, 16 - lsrs r4, 16 - ldr r0, =gScriptResult - mov r8, r0 - bl sub_80D2548 - mov r7, sp - adds r7, 0xA - add r6, sp, 0xC - mov r5, sp - adds r5, 0xD - str r4, [sp] - str r0, [sp, 0x4] - add r0, sp, 0x8 - adds r1, r7, 0 - adds r2, r6, 0 - adds r3, r5, 0 - bl sub_81D9B68 - mov r1, r8 - strh r0, [r1] - lsls r0, 16 - cmp r0, 0 - beq _081D9B1E - ldrb r0, [r5] - bl sub_80D24BC - ldrb r0, [r6] - bl sub_80D24F0 - add r0, sp, 0x8 - ldrh r0, [r0] - ldrh r1, [r7] - bl sub_80D2524 -_081D9B1E: - mov r1, r8 - ldrh r0, [r1] - bl sub_80D2480 - mov r1, r8 - ldrb r0, [r1] - add sp, 0x10 - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r1} - bx r1 - .pool - thumb_func_end sub_81D9AC4 - - thumb_func_start sub_81D9B40 -sub_81D9B40: @ 81D9B40 - push {lr} - lsls r0, 24 - lsrs r2, r0, 24 - movs r1, 0 - ldr r3, =gUnknown_0862AD14 -_081D9B4A: - adds r0, r1, r3 - ldrb r0, [r0] - cmp r0, r2 - bne _081D9B5C - lsls r0, r1, 24 - lsrs r0, 24 - b _081D9B64 - .pool -_081D9B5C: - adds r1, 0x1 - cmp r1, 0x1F - bls _081D9B4A - movs r0, 0x20 -_081D9B64: - pop {r1} - bx r1 - thumb_func_end sub_81D9B40 - - thumb_func_start sub_81D9B68 -sub_81D9B68: @ 81D9B68 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x2C - mov r10, r0 - str r1, [sp, 0x20] - str r2, [sp, 0x24] - str r3, [sp, 0x28] - ldr r0, [sp, 0x4C] - ldr r5, [sp, 0x50] - lsls r0, 16 - lsrs r0, 16 - mov r9, r0 - adds r0, r5, 0 - bl StringLength - lsls r0, 16 - lsrs r0, 16 - cmp r0, 0xF - bne _081D9C7E - movs r4, 0 - add r7, sp, 0x10 -_081D9B98: - adds r0, r5, r4 - ldrb r0, [r0] - bl sub_81D9B40 - adds r1, r7, r4 - strb r0, [r1] - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x20 - beq _081D9C7E - adds r4, 0x1 - cmp r4, 0xE - ble _081D9B98 - movs r6, 0x3 - movs r5, 0 - movs r0, 0x5 - mov r8, r0 - movs r4, 0xD -_081D9BBC: - mov r1, r8 - str r1, [sp] - add r0, sp, 0x4 - adds r1, r7, 0 - adds r2, r5, 0 - adds r3, r6, 0 - bl sub_81D9D5C - adds r6, 0x8 - adds r5, 0x5 - subs r4, 0x1 - cmp r4, 0 - bge _081D9BBC - movs r0, 0x2 - str r0, [sp] - add r0, sp, 0x4 - adds r1, r7, 0 - movs r2, 0x46 - movs r3, 0x73 - bl sub_81D9D5C - add r0, sp, 0x4 - movs r1, 0 - movs r2, 0x3 - bl sub_81D9DAC - adds r4, r0, 0 - adds r0, r7, 0 - movs r1, 0x75 - movs r2, 0x3 - bl sub_81D9DAC - cmp r4, r0 - bne _081D9C7E - add r0, sp, 0x4 - movs r1, 0x9 - movs r2, 0x15 - bl sub_81D9C90 - add r0, sp, 0x4 - ldrb r0, [r0, 0x8] - movs r2, 0xF - ands r2, r0 - add r0, sp, 0x4 - movs r1, 0x8 - bl sub_81D9C90 - add r0, sp, 0x4 - ldrb r2, [r0, 0x8] - lsrs r2, 4 - movs r1, 0x8 - bl sub_81D9CDC - add r0, sp, 0x4 - ldrb r2, [r0, 0x6] - adds r1, r0, 0 - ldrb r0, [r0] - ldrb r1, [r1, 0x2] - eors r0, r1 - add r1, sp, 0x4 - ldrb r4, [r1, 0x4] - eors r0, r4 - mov r3, r9 - lsrs r1, r3, 8 - eors r0, r1 - cmp r2, r0 - bne _081D9C7E - add r0, sp, 0x4 - ldrb r3, [r0, 0x7] - adds r2, r0, 0 - ldrb r1, [r0, 0x1] - ldrb r0, [r2, 0x3] - eors r1, r0 - adds r0, r2, 0 - ldrb r2, [r0, 0x5] - eors r1, r2 - movs r0, 0xFF - mov r5, r9 - ands r0, r5 - eors r1, r0 - cmp r3, r1 - bne _081D9C7E - add r0, sp, 0x4 - ldrh r0, [r0] - mov r1, r10 - strh r0, [r1] - mov r0, sp - adds r0, 0x6 - ldrh r0, [r0] - ldr r3, [sp, 0x20] - strh r0, [r3] - ldr r5, [sp, 0x24] - strb r4, [r5] - ldr r0, [sp, 0x28] - strb r2, [r0] - movs r0, 0x1 - b _081D9C80 -_081D9C7E: - movs r0, 0 -_081D9C80: - add sp, 0x2C - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_81D9B68 - - thumb_func_start sub_81D9C90 -sub_81D9C90: @ 81D9C90 - push {r4-r7,lr} - adds r7, r0, 0 - mov r12, r1 - subs r3, r2, 0x1 - cmp r2, 0 - beq _081D9CD6 -_081D9C9C: - ldrb r1, [r7] - movs r0, 0x80 - ands r0, r1 - lsls r0, 24 - lsrs r4, r0, 31 - mov r2, r12 - subs r2, 0x1 - subs r5, r3, 0x1 - cmp r2, 0 - blt _081D9CCC - movs r6, 0x80 - adds r3, r2, r7 -_081D9CB4: - ldrb r1, [r3] - adds r0, r6, 0 - ands r0, r1 - lsls r0, 24 - lsls r1, 1 - orrs r4, r1 - strb r4, [r3] - lsrs r4, r0, 31 - subs r3, 0x1 - subs r2, 0x1 - cmp r2, 0 - bge _081D9CB4 -_081D9CCC: - adds r3, r5, 0 - movs r0, 0x1 - negs r0, r0 - cmp r3, r0 - bne _081D9C9C -_081D9CD6: - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_81D9C90 thumb_func_start sub_81D9CDC sub_81D9CDC: @ 81D9CDC diff --git a/data/specials.inc b/data/specials.inc index bb9a41ab7..7818d4825 100644 --- a/data/specials.inc +++ b/data/specials.inc @@ -520,8 +520,8 @@ gSpecials:: @ 81DBA64 def_special sub_81D4BEC def_special sub_80224D0 def_special sub_81D99BC - def_special walda_maybe - def_special sub_81D9AC4 + def_special DoWaldaNamingScreen + def_special TryGetWallpaperWithWaldaPhrase def_special sub_8139ED0 def_special sub_813B968 def_special sub_80F8B94 diff --git a/data/walda_phrase.s b/data/walda_phrase.s deleted file mode 100644 index c168353b4..000000000 --- a/data/walda_phrase.s +++ /dev/null @@ -1,7 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .section .rodata - -gUnknown_0862AD14:: @ 862AD14 - .incbin "baserom.gba", 0x62ad14, 0x20 diff --git a/include/global.h b/include/global.h index 58a0d79dc..d8547d9c3 100644 --- a/include/global.h +++ b/include/global.h @@ -500,6 +500,16 @@ typedef union // TODO u8 id; } LilycoveLady; +struct WaldaPhrase +{ + u16 field_0; + u16 field_2; + u8 text[16]; + u8 iconId; + u8 patternId; + bool8 patternUnlocked; +}; + struct SaveBlock1 { /*0x00*/ struct Coords16 pos; @@ -586,7 +596,7 @@ struct SaveBlock1 /*0x3B24*/ u8 seen2[52]; /*0x3B58*/ LilycoveLady lilycoveLady; /*0x3B88*/ u8 filler_3B88[0x1E8]; - /*0x3D70*/ u8 babyPhrase[24]; // TODO: convert to a struct + /*0x3D70*/ struct WaldaPhrase waldaPhrase; // sizeof: 0x3D88 }; diff --git a/include/naming_screen.h b/include/naming_screen.h index 55a8e75a3..3d69b834f 100644 --- a/include/naming_screen.h +++ b/include/naming_screen.h @@ -5,7 +5,7 @@ #define NAMING_SCREEN_BOX 1 #define NAMING_SCREEN_CAUGHT_MON 2 #define NAMING_SCREEN_3 3 -#define NAMING_SCREEN_WANDA 4 +#define NAMING_SCREEN_WALDA 4 void DoNamingScreen(u8 caseId, u8* dst, u16 monSpecies, u8 monGender, u32 monPersonality, void (*callback)(void)); diff --git a/include/new_game.h b/include/new_game.h index 060279c25..2088d1826 100644 --- a/include/new_game.h +++ b/include/new_game.h @@ -2,6 +2,7 @@ #define GUARD_NEW_GAME_H void WriteUnalignedWord(u32 var, u8 *dataPtr); +u32 ReadUnalignedWord(u8* dataPtr); void CopyUnalignedWord(u8 *copyTo, u8 *copyFrom); void InitPlayerTrainerId(void); void SetDefaultOptions(void); diff --git a/ld_script.txt b/ld_script.txt index 634ab34cc..bfabd96bc 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -257,6 +257,7 @@ SECTIONS { asm/pokemon_summary_screen.o(.text); asm/pokenav.o(.text); asm/rayquaza_scene.o(.text); + src/walda_phrase.o(.text); asm/walda_phrase.o(.text); asm/contest_link_81D9DE4.o(.text); asm/trainer_rematch.o(.text); @@ -466,7 +467,7 @@ SECTIONS { data/pokemon_summary_screen.o(.rodata); data/pokenav.o(.rodata); data/rayquaza_scene.o(.rodata); - data/walda_phrase.o(.rodata); + src/walda_phrase.o(.rodata); data/trainer_rematch.o(.rodata); data/unk_sprite_file.o(.rodata); data/unk_transition.o(.rodata); diff --git a/src/walda_phrase.c b/src/walda_phrase.c new file mode 100644 index 000000000..1da2bddce --- /dev/null +++ b/src/walda_phrase.c @@ -0,0 +1,185 @@ +#include "global.h" +#include "string_util.h" +#include "event_data.h" +#include "naming_screen.h" +#include "main.h" +#include "text.h" +#include "new_game.h" + +extern void (*gFieldCallback)(void); + +extern const u8 gText_Peekaboo[]; + +extern u8 *GetWaldaPhrasePtr(void); +extern bool32 IsWaldaPhraseEmpty(void); +extern void sub_80AF168(void); +extern void c2_exit_to_overworld_2_switch(void); +extern void SetWaldaPhrase(const u8 *src); +extern void SetWaldaWallpaperPatternId(u8 patternId); +extern void SetWaldaWallpaperIconId(u8 iconId); +extern void SetWaldaWallpaperColors(u16 backgroundColor, u16 foregroundColor); +extern void SetWaldaWallpaperLockedOrUnlocked(bool32 unlocked); + +// this file's functions +void CB2_HandleGivenWaldaPhrase(void); +u32 GetWaldaPhraseInputCase(u8 *inputPtr); +bool32 TryCalculateWallpaper(u16* backgroundClr, u16 *foregroundClr, u8 *iconId, u8 *patternId, u16 trainerId, u8 *phrase); +void sub_81D9D5C(u8 *array, u8 *letterTableIds, s32 arg2, s32 arg3, s32 arg4); +s32 sub_81D9DAC(u8 *array, s32 arg1, s32 arg2); +void sub_81D9C90(u8 *array, s32 arg1, s32 arg2); +void sub_81D9CDC(u8 *array, s32 arg1, u8 arg2); + +// only consonants are allowed, no vowels, some lowercase letters are missing +static const u8 sWaldaLettersTable[] = +{ + CHAR_B, CHAR_C, CHAR_D, CHAR_F, CHAR_G, CHAR_H, CHAR_J, CHAR_K, CHAR_L, CHAR_M, CHAR_N, CHAR_P, CHAR_Q, CHAR_R, CHAR_S, CHAR_T, CHAR_V, CHAR_W, CHAR_Z, + CHAR_b, CHAR_c, CHAR_d, CHAR_f, CHAR_g, CHAR_h, CHAR_j, CHAR_k, CHAR_m, CHAR_n, CHAR_p, CHAR_q, CHAR_s +}; + +enum +{ + PHRASE_GIVEN_NEW, + PHRASE_NO_CHANGE, + PHRASE_FIRST_ATTEMPT +}; + +void DoWaldaNamingScreen(void) +{ + StringCopy(gStringVar2, GetWaldaPhrasePtr()); + DoNamingScreen(NAMING_SCREEN_WALDA, gStringVar2, 0, 0, 0, CB2_HandleGivenWaldaPhrase); +} + +void CB2_HandleGivenWaldaPhrase(void) +{ + gSpecialVar_0x8004 = GetWaldaPhraseInputCase(gStringVar2); + + switch (gSpecialVar_0x8004) + { + case PHRASE_FIRST_ATTEMPT: + if (IsWaldaPhraseEmpty()) + SetWaldaPhrase(gText_Peekaboo); + else + gSpecialVar_0x8004 = PHRASE_NO_CHANGE; + break; + case PHRASE_GIVEN_NEW: + SetWaldaPhrase(gStringVar2); + break; + case PHRASE_NO_CHANGE: + break; + } + + StringCopy(gStringVar1, GetWaldaPhrasePtr()); + gFieldCallback = sub_80AF168; + SetMainCallback2(c2_exit_to_overworld_2_switch); +} + +u32 GetWaldaPhraseInputCase(u8 *inputPtr) +{ + if (inputPtr[0] == EOS) + return PHRASE_FIRST_ATTEMPT; + if (StringCompare(inputPtr, GetWaldaPhrasePtr()) == 0) + return PHRASE_NO_CHANGE; + + return PHRASE_GIVEN_NEW; +} + +u16 TryGetWallpaperWithWaldaPhrase(void) +{ + u16 backgroundClr, foregroundClr; + u8 patternId, iconId; + u16 trainerId = ReadUnalignedWord(gSaveBlock2Ptr->playerTrainerId); + gScriptResult = TryCalculateWallpaper(&backgroundClr, &foregroundClr, &iconId, &patternId, trainerId, GetWaldaPhrasePtr()); + + if (gScriptResult) + { + SetWaldaWallpaperPatternId(patternId); + SetWaldaWallpaperIconId(iconId); + SetWaldaWallpaperColors(backgroundClr, foregroundClr); + } + + SetWaldaWallpaperLockedOrUnlocked(gScriptResult); + return (bool8)(gScriptResult); +} + +u8 GetLetterTableId(u8 letter) +{ + s32 i; + + for (i = 0; i < ARRAY_COUNT(sWaldaLettersTable); i++) + { + if (sWaldaLettersTable[i] == letter) + return i; + } + + return ARRAY_COUNT(sWaldaLettersTable); +} + +bool32 TryCalculateWallpaper(u16* backgroundClr, u16 *foregroundClr, u8 *iconId, u8 *patternId, u16 trainerId, u8 *phrase) +{ + s32 i; + ALIGNED(2) u8 array[12]; + u8 charsByTableId[16]; + u16 *ptr; + + if (StringLength(phrase) != 15) + return FALSE; + + for (i = 0; i < 15; i++) + { + charsByTableId[i] = GetLetterTableId(phrase[i]); + if (charsByTableId[i] == ARRAY_COUNT(sWaldaLettersTable)) + return FALSE; + } + + for (i = 0; i < 14; i++) + { + sub_81D9D5C(array, charsByTableId, (5 * i), 3 + (8 * i), 5); + } + + sub_81D9D5C(array, charsByTableId, 70, 115, 2); + + if (sub_81D9DAC(array, 0, 3) != sub_81D9DAC(charsByTableId, 117, 3)) + return FALSE; + + sub_81D9C90(array, 9, 21); + sub_81D9C90(array, 8, array[8] & 0xF); + sub_81D9CDC(array, 8, array[8] >> 4); + + if (array[6] != (array[0] ^ array[2] ^ array[4] ^ (trainerId >> 8))) + return FALSE; + + if (array[7] != (array[1] ^ array[3] ^ array[5] ^ (trainerId & 0xFF))) + return FALSE; + + ptr = (u16*)(&array[0]); + *backgroundClr = *ptr; + + ptr = (u16*)(&array[2]); + *foregroundClr = *ptr; + + *iconId = array[4]; + *patternId = array[5]; + + return TRUE; +} + +void sub_81D9C90(u8 *array, s32 arg1, s32 arg2) +{ + s32 i, j; + u8 var1, var2; + + for (i = arg2 - 1; i != -1; i--) + { + var1 = (array[0] & 0x80) >> 7; + + var1++;var1--; // needed to match + + for (j = arg1 - 1; j >= 0; j--) + { + var2 = array[j] & 0x80; + array[j] <<= 1; + array[j] |= var1; + var1 = var2 >> 7; + } + } +} From 8c85a273461557bde4b42630ba3a56701c8f4d81 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Fri, 20 Oct 2017 20:39:00 +0200 Subject: [PATCH 2/3] walda phrase is done --- asm/walda_phrase.s | 168 ----------------------------------------- include/walda_phrase.h | 7 ++ ld_script.txt | 1 - src/walda_phrase.c | 89 ++++++++++++++++++---- 4 files changed, 83 insertions(+), 182 deletions(-) delete mode 100755 asm/walda_phrase.s create mode 100644 include/walda_phrase.h diff --git a/asm/walda_phrase.s b/asm/walda_phrase.s deleted file mode 100755 index f6f55a668..000000000 --- a/asm/walda_phrase.s +++ /dev/null @@ -1,168 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .syntax unified - - .text - - - - thumb_func_start sub_81D9CDC -sub_81D9CDC: @ 81D9CDC - push {r4-r6,lr} - adds r6, r0, 0 - adds r5, r1, 0 - lsls r2, 24 - lsrs r3, r2, 24 - lsls r0, r3, 4 - orrs r3, r0 - lsls r0, r3, 24 - lsrs r3, r0, 24 - movs r4, 0 - cmp r4, r5 - bcs _081D9D04 -_081D9CF4: - adds r2, r6, r4 - ldrb r1, [r2] - adds r0, r3, 0 - eors r0, r1 - strb r0, [r2] - adds r4, 0x1 - cmp r4, r5 - bcc _081D9CF4 -_081D9D04: - pop {r4-r6} - pop {r0} - bx r0 - thumb_func_end sub_81D9CDC - - thumb_func_start sub_81D9D0C -sub_81D9D0C: @ 81D9D0C - push {lr} - lsrs r3, r1, 3 - movs r2, 0x7 - ands r2, r1 - movs r1, 0x80 - asrs r1, r2 - adds r0, r3 - ldrb r0, [r0] - ands r0, r1 - cmp r0, 0 - beq _081D9D24 - movs r0, 0x1 -_081D9D24: - pop {r1} - bx r1 - thumb_func_end sub_81D9D0C - - thumb_func_start sub_81D9D28 -sub_81D9D28: @ 81D9D28 - lsrs r3, r1, 3 - movs r2, 0x7 - ands r2, r1 - movs r1, 0x80 - asrs r1, r2 - lsls r1, 24 - lsrs r1, 24 - adds r0, r3 - ldrb r2, [r0] - orrs r1, r2 - strb r1, [r0] - bx lr - thumb_func_end sub_81D9D28 - - thumb_func_start sub_81D9D40 -sub_81D9D40: @ 81D9D40 - lsrs r3, r1, 3 - movs r2, 0x7 - ands r2, r1 - movs r1, 0x80 - asrs r1, r2 - mvns r1, r1 - lsls r1, 24 - lsrs r1, 24 - adds r0, r3 - ldrb r2, [r0] - ands r1, r2 - strb r1, [r0] - bx lr - thumb_func_end sub_81D9D40 - - thumb_func_start sub_81D9D5C -sub_81D9D5C: @ 81D9D5C - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - adds r6, r0, 0 - mov r9, r1 - adds r1, r2, 0 - mov r8, r3 - ldr r7, [sp, 0x1C] - movs r5, 0 - cmp r5, r7 - bcs _081D9DA0 - adds r4, r1, 0 -_081D9D76: - mov r0, r8 - adds r1, r0, r5 - mov r0, r9 - bl sub_81D9D0C - lsls r0, 24 - cmp r0, 0 - beq _081D9D90 - adds r0, r6, 0 - adds r1, r4, 0 - bl sub_81D9D28 - b _081D9D98 -_081D9D90: - adds r0, r6, 0 - adds r1, r4, 0 - bl sub_81D9D40 -_081D9D98: - adds r4, 0x1 - adds r5, 0x1 - cmp r5, r7 - bcc _081D9D76 -_081D9DA0: - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_81D9D5C - - thumb_func_start sub_81D9DAC -sub_81D9DAC: @ 81D9DAC - push {r4-r7,lr} - mov r7, r8 - push {r7} - mov r8, r0 - adds r7, r1, 0 - adds r6, r2, 0 - movs r4, 0 - movs r5, 0 - cmp r4, r6 - bcs _081D9DD6 -_081D9DC0: - lsls r4, 1 - adds r1, r7, r5 - mov r0, r8 - bl sub_81D9D0C - lsls r0, 24 - lsrs r0, 24 - orrs r4, r0 - adds r5, 0x1 - cmp r5, r6 - bcc _081D9DC0 -_081D9DD6: - adds r0, r4, 0 - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_81D9DAC - - .align 2, 0 @ Don't pad with nop. diff --git a/include/walda_phrase.h b/include/walda_phrase.h new file mode 100644 index 000000000..7a711a413 --- /dev/null +++ b/include/walda_phrase.h @@ -0,0 +1,7 @@ +#ifndef GUARD_WALDA_PHRASE_H +#define GUARD_WALDA_PHRASE_H + +void DoWaldaNamingScreen(void); +u16 TryGetWallpaperWithWaldaPhrase(void); + +#endif // GUARD_WALDA_PHRASE_H diff --git a/ld_script.txt b/ld_script.txt index bfabd96bc..ca9432d94 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -258,7 +258,6 @@ SECTIONS { asm/pokenav.o(.text); asm/rayquaza_scene.o(.text); src/walda_phrase.o(.text); - asm/walda_phrase.o(.text); asm/contest_link_81D9DE4.o(.text); asm/trainer_rematch.o(.text); asm/unk_sprite_file.o(.text); diff --git a/src/walda_phrase.c b/src/walda_phrase.c index 1da2bddce..21f39f784 100644 --- a/src/walda_phrase.c +++ b/src/walda_phrase.c @@ -1,4 +1,5 @@ #include "global.h" +#include "walda_phrase.h" #include "string_util.h" #include "event_data.h" #include "naming_screen.h" @@ -21,13 +22,13 @@ extern void SetWaldaWallpaperColors(u16 backgroundColor, u16 foregroundColor); extern void SetWaldaWallpaperLockedOrUnlocked(bool32 unlocked); // this file's functions -void CB2_HandleGivenWaldaPhrase(void); -u32 GetWaldaPhraseInputCase(u8 *inputPtr); -bool32 TryCalculateWallpaper(u16* backgroundClr, u16 *foregroundClr, u8 *iconId, u8 *patternId, u16 trainerId, u8 *phrase); -void sub_81D9D5C(u8 *array, u8 *letterTableIds, s32 arg2, s32 arg3, s32 arg4); -s32 sub_81D9DAC(u8 *array, s32 arg1, s32 arg2); -void sub_81D9C90(u8 *array, s32 arg1, s32 arg2); -void sub_81D9CDC(u8 *array, s32 arg1, u8 arg2); +static void CB2_HandleGivenWaldaPhrase(void); +static u32 GetWaldaPhraseInputCase(u8 *inputPtr); +static bool32 TryCalculateWallpaper(u16* backgroundClr, u16 *foregroundClr, u8 *iconId, u8 *patternId, u16 trainerId, u8 *phrase); +static void sub_81D9D5C(u8 *array, u8 *letterTableIds, u32 arg2, u32 arg3, u32 loopCount); +static u32 sub_81D9DAC(u8 *array, u32 arg1, u32 loopCount); +static void sub_81D9C90(u8 *array, s32 arg1, s32 arg2); +static void sub_81D9CDC(u8 *array, u32 loopCount, u8 arg2); // only consonants are allowed, no vowels, some lowercase letters are missing static const u8 sWaldaLettersTable[] = @@ -49,7 +50,7 @@ void DoWaldaNamingScreen(void) DoNamingScreen(NAMING_SCREEN_WALDA, gStringVar2, 0, 0, 0, CB2_HandleGivenWaldaPhrase); } -void CB2_HandleGivenWaldaPhrase(void) +static void CB2_HandleGivenWaldaPhrase(void) { gSpecialVar_0x8004 = GetWaldaPhraseInputCase(gStringVar2); @@ -73,7 +74,7 @@ void CB2_HandleGivenWaldaPhrase(void) SetMainCallback2(c2_exit_to_overworld_2_switch); } -u32 GetWaldaPhraseInputCase(u8 *inputPtr) +static u32 GetWaldaPhraseInputCase(u8 *inputPtr) { if (inputPtr[0] == EOS) return PHRASE_FIRST_ATTEMPT; @@ -101,7 +102,7 @@ u16 TryGetWallpaperWithWaldaPhrase(void) return (bool8)(gScriptResult); } -u8 GetLetterTableId(u8 letter) +static u8 GetLetterTableId(u8 letter) { s32 i; @@ -114,7 +115,7 @@ u8 GetLetterTableId(u8 letter) return ARRAY_COUNT(sWaldaLettersTable); } -bool32 TryCalculateWallpaper(u16* backgroundClr, u16 *foregroundClr, u8 *iconId, u8 *patternId, u16 trainerId, u8 *phrase) +static bool32 TryCalculateWallpaper(u16* backgroundClr, u16 *foregroundClr, u8 *iconId, u8 *patternId, u16 trainerId, u8 *phrase) { s32 i; ALIGNED(2) u8 array[12]; @@ -163,7 +164,7 @@ bool32 TryCalculateWallpaper(u16* backgroundClr, u16 *foregroundClr, u8 *iconId, return TRUE; } -void sub_81D9C90(u8 *array, s32 arg1, s32 arg2) +static void sub_81D9C90(u8 *array, s32 arg1, s32 arg2) { s32 i, j; u8 var1, var2; @@ -172,7 +173,7 @@ void sub_81D9C90(u8 *array, s32 arg1, s32 arg2) { var1 = (array[0] & 0x80) >> 7; - var1++;var1--; // needed to match + var1++; var1--; // needed to match for (j = arg1 - 1; j >= 0; j--) { @@ -183,3 +184,65 @@ void sub_81D9C90(u8 *array, s32 arg1, s32 arg2) } } } + +static void sub_81D9CDC(u8 *array, u32 loopCount, u8 arg2) +{ + u32 i; + + arg2 |= (arg2 << 4); + + for (i = 0; i < loopCount; i++) + { + array[i] ^= arg2; + } +} + +static bool8 sub_81D9D0C(u8 *array, u32 arg1) +{ + u32 arrayId = arg1 >> 3; + u32 bits = 0x80 >> (7 & arg1); + + return ((array[arrayId] & bits) != 0); +} + +static void sub_81D9D28(u8 *array, u32 arg1) +{ + u32 arrayId = arg1 >> 3; + u8 bits = 0x80 >> (7 & arg1); + + array[arrayId] |= bits; +} + +static void sub_81D9D40(u8 *array, u32 arg1) +{ + u32 arrayId = arg1 >> 3; + u8 bits = ~(0x80 >> (7 & arg1)); + + array[arrayId] &= bits; +} + +static void sub_81D9D5C(u8 *array, u8 *letterTableIds, u32 arg2, u32 arg3, u32 loopCount) +{ + u32 i; + + for (i = 0; i < loopCount; i++) + { + if (sub_81D9D0C(letterTableIds, arg3 + i)) + sub_81D9D28(array, arg2 + i); + else + sub_81D9D40(array, arg2 + i); + } +} + +static u32 sub_81D9DAC(u8 *array, u32 arg1, u32 loopCount) +{ + u32 ret, i; + + for (ret = 0, i = 0; i < loopCount; i++) + { + ret <<= 1; + ret |= sub_81D9D0C(array, arg1 + i); + } + + return ret; +} From 31e0b468c7f859e72e758f3f0fc1051ab887d9a5 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Fri, 20 Oct 2017 20:46:26 +0200 Subject: [PATCH 3/3] move from raq scene to walda phrase --- asm/rayquaza_scene.s | 21 --------------------- data/specials.inc | 2 +- include/walda_phrase.h | 1 + src/walda_phrase.c | 9 +++++++++ 4 files changed, 11 insertions(+), 22 deletions(-) diff --git a/asm/rayquaza_scene.s b/asm/rayquaza_scene.s index 1649f0131..f9936f1ca 100755 --- a/asm/rayquaza_scene.s +++ b/asm/rayquaza_scene.s @@ -5968,26 +5968,5 @@ _081D99B4: bx r0 thumb_func_end sub_81D98B4 - thumb_func_start sub_81D99BC -sub_81D99BC: @ 81D99BC - push {r4,lr} - bl IsWaldaPhraseEmpty - cmp r0, 0 - bne _081D99DC - ldr r4, =gStringVar1 - bl GetWaldaPhrasePtr - adds r1, r0, 0 - adds r0, r4, 0 - bl StringCopy - movs r0, 0x1 - b _081D99DE - .pool -_081D99DC: - movs r0, 0 -_081D99DE: - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_81D99BC .align 2, 0 @ Don't pad with nop. diff --git a/data/specials.inc b/data/specials.inc index 7818d4825..49f6b91a0 100644 --- a/data/specials.inc +++ b/data/specials.inc @@ -519,7 +519,7 @@ gSpecials:: @ 81DBA64 def_special sub_813B80C def_special sub_81D4BEC def_special sub_80224D0 - def_special sub_81D99BC + def_special TryBufferWaldaPhrase def_special DoWaldaNamingScreen def_special TryGetWallpaperWithWaldaPhrase def_special sub_8139ED0 diff --git a/include/walda_phrase.h b/include/walda_phrase.h index 7a711a413..3d7701123 100644 --- a/include/walda_phrase.h +++ b/include/walda_phrase.h @@ -1,6 +1,7 @@ #ifndef GUARD_WALDA_PHRASE_H #define GUARD_WALDA_PHRASE_H +u16 TryBufferWaldaPhrase(void); void DoWaldaNamingScreen(void); u16 TryGetWallpaperWithWaldaPhrase(void); diff --git a/src/walda_phrase.c b/src/walda_phrase.c index 21f39f784..7e06d1319 100644 --- a/src/walda_phrase.c +++ b/src/walda_phrase.c @@ -44,6 +44,15 @@ enum PHRASE_FIRST_ATTEMPT }; +u16 TryBufferWaldaPhrase(void) +{ + if (IsWaldaPhraseEmpty()) + return FALSE; + + StringCopy(gStringVar1, GetWaldaPhrasePtr()); + return TRUE; +} + void DoWaldaNamingScreen(void) { StringCopy(gStringVar2, GetWaldaPhrasePtr());