diff --git a/asm/code_80521D0.s b/asm/code_80521D0.s index 047c2768..ce36cfab 100644 --- a/asm/code_80521D0.s +++ b/asm/code_80521D0.s @@ -6,288 +6,6 @@ .text - - thumb_func_start sub_805317C -sub_805317C: - push {lr} - ldr r0, _08053198 - ldr r1, [r0] - movs r2, 0xCF - lsls r2, 3 - adds r0, r1, r2 - ldrb r0, [r0] - cmp r0, 0x1 - beq _0805319C - subs r2, 0x34 - adds r0, r1, r2 - ldrb r0, [r0] - b _0805319E - .align 2, 0 -_08053198: .4byte gDungeon -_0805319C: - movs r0, 0x3F -_0805319E: - bl GetDungeonName1 - pop {r1} - bx r1 - thumb_func_end sub_805317C - - thumb_func_start sub_80531A8 -sub_80531A8: - push {r4-r6,lr} - ldr r2, _080531F0 - ldr r1, [r2] - movs r0, 0 - strh r0, [r1, 0x16] - movs r0, 0x1 - strb r0, [r1, 0xB] - movs r4, 0 - movs r3, 0 - ldr r5, _080531F4 -_080531BC: - ldr r0, [r2] - lsls r1, r4, 6 - adds r0, r1 - adds r0, r5 - strb r3, [r0] - ldr r0, [r2] - adds r0, r1 - ldr r6, _080531F8 - adds r0, r6 - strb r3, [r0] - ldr r0, [r2] - adds r0, r1 - adds r6, 0x1 - adds r0, r6 - strb r3, [r0] - ldr r0, [r2] - adds r0, r1 - ldr r1, _080531FC - adds r0, r1 - strb r3, [r0] - adds r4, 0x1 - cmp r4, 0x13 - ble _080531BC - pop {r4-r6} - pop {r0} - bx r0 - .align 2, 0 -_080531F0: .4byte gDungeon -_080531F4: .4byte 0x0001c073 -_080531F8: .4byte 0x0001c070 -_080531FC: .4byte 0x0001c072 - thumb_func_end sub_80531A8 - - thumb_func_start sub_8053200 -sub_8053200: - ldr r0, _0805320C - ldr r1, [r0] - movs r0, 0x1 - strb r0, [r1, 0xB] - bx lr - .align 2, 0 -_0805320C: .4byte gDungeon - thumb_func_end sub_8053200 - - thumb_func_start sub_8053210 -sub_8053210: - push {r4-r7,lr} - mov r7, r8 - push {r7} - adds r6, r0, 0 - ldr r0, _08053264 - mov r12, r0 - ldr r3, [r0] - movs r0, 0x16 - ldrsh r4, [r3, r0] - lsls r4, 6 - ldr r5, _08053268 - adds r0, r4, r5 - adds r0, r3, r0 - adds r7, r0, 0x3 - adds r0, 0x3E - mov r8, r0 - adds r3, r4 - adds r3, r5 - movs r0, 0x1 - strb r0, [r3] - mov r4, r12 - ldr r3, [r4] - movs r4, 0x16 - ldrsh r0, [r3, r4] - lsls r0, 6 - adds r3, r0 - ldr r0, _0805326C - adds r3, r0 - strb r1, [r3] - mov r3, r12 - ldr r1, [r3] - movs r4, 0x16 - ldrsh r0, [r1, r4] - lsls r0, 6 - adds r1, r0 - ldr r0, _08053270 - adds r1, r0 - strb r2, [r1] - ldrb r2, [r6] - adds r0, r2, 0 - mov r1, r12 - b _08053282 - .align 2, 0 -_08053264: .4byte gDungeon -_08053268: .4byte 0x0001c070 -_0805326C: .4byte 0x0001c071 -_08053270: .4byte 0x0001c072 -_08053274: - cmp r7, r8 - bcs _0805327C - strb r2, [r7] - adds r7, 0x1 -_0805327C: - adds r6, 0x1 - ldrb r2, [r6] - adds r0, r2, 0 -_08053282: - cmp r0, 0 - beq _0805328A - cmp r0, 0xD - bne _08053274 -_0805328A: - movs r0, 0 - strb r0, [r7] - ldr r2, [r1] - ldrh r0, [r2, 0x16] - adds r0, 0x1 - strh r0, [r2, 0x16] - lsls r0, 16 - asrs r0, 16 - cmp r0, 0x13 - ble _080532A2 - movs r0, 0 - strh r0, [r2, 0x16] -_080532A2: - ldr r1, [r1] - movs r0, 0x1 - strb r0, [r1, 0xB] - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_8053210 - - thumb_func_start sub_80532B4 -sub_80532B4: - push {r4-r6,lr} - sub sp, 0xC - mov r0, sp - bl sub_801317C - movs r0, 0x9 - movs r1, 0 - bl sub_803EAF0 -_080532C6: - movs r0, 0xD - bl sub_803E46C - movs r0, 0 - bl sub_8008D8C - lsls r0, 24 - lsrs r1, r0, 24 - cmp r1, 0 - bne _080532C6 - ldr r0, _08053374 - str r1, [r0] - ldr r4, _08053378 - strb r1, [r4] - bl sub_80533A4 - adds r6, r4, 0 -_080532E8: - movs r5, 0 - strb r5, [r6] - mov r0, sp - movs r1, 0 - bl nullsub_34 - movs r0, 0 - ldr r1, _0805337C - bl sub_8014140 - adds r4, r0, 0 - bl sub_8053430 - lsls r0, 24 - lsrs r0, 24 - negs r1, r0 - orrs r1, r0 - lsrs r5, r1, 31 - adds r0, r4, 0 - bl sub_8053540 - lsls r0, 24 - cmp r0, 0 - beq _0805331A - movs r5, 0x1 -_0805331A: - cmp r5, 0 - bne _08053324 - movs r0, 0xD - bl sub_803E46C -_08053324: - ldrb r1, [r6] - movs r5, 0x1 - adds r0, r5, 0 - ands r0, r1 - cmp r0, 0 - beq _0805333A - movs r0, 0x1 - movs r1, 0x8 - negs r1, r1 - bl sub_805363C -_0805333A: - ldrb r1, [r6] - movs r4, 0x2 - adds r0, r4, 0 - ands r0, r1 - cmp r0, 0 - beq _0805334E - movs r0, 0 - movs r1, 0x72 - bl sub_805363C -_0805334E: - bl sub_80048C8 - lsls r0, 24 - cmp r0, 0 - bne _080532E8 - ldr r0, _08053380 - ldrh r1, [r0, 0x2] - adds r0, r4, 0 - ands r0, r1 - cmp r0, 0 - bne _0805336C - mov r0, sp - ldrb r0, [r0, 0x2] - cmp r0, 0 - beq _08053384 -_0805336C: - bl sub_8083D30 - b _08053390 - .align 2, 0 -_08053374: .4byte gUnknown_202F1F8 -_08053378: .4byte gUnknown_202F1FC -_0805337C: .4byte gUnknown_8106990 -_08053380: .4byte gRealInputs -_08053384: - adds r0, r5, 0 - ands r0, r1 - cmp r0, 0 - beq _080532E8 - bl sub_8083D08 -_08053390: - movs r0, 0 - movs r1, 0 - bl sub_803EAF0 - movs r0, 0x1 - add sp, 0xC - pop {r4-r6} - pop {r1} - bx r1 - thumb_func_end sub_80532B4 - thumb_func_start sub_80533A4 sub_80533A4: push {r4-r7,lr} diff --git a/include/menu_input.h b/include/menu_input.h index 1d4bf20a..0f7415b7 100644 --- a/include/menu_input.h +++ b/include/menu_input.h @@ -41,7 +41,7 @@ void sub_8013984(MenuInputStruct * param_1); void sub_8013A54(MenuInputStruct *param_1); void sub_8013A7C(MenuInputStruct *param_1); void AddMenuCursorSprite_(MenuInputStruct *, u8 *); -void nullsub_34(MenuInputStructSub *); +void nullsub_34(MenuInputStructSub *, s32 a1); void sub_8013AA0(unkStructFor8013AA0 *); u32 sub_8013BBC(unkStructFor8013AA0 *); diff --git a/include/structs/str_dungeon.h b/include/structs/str_dungeon.h index 5c9770e8..d0274837 100644 --- a/include/structs/str_dungeon.h +++ b/include/structs/str_dungeon.h @@ -227,6 +227,17 @@ struct UnkStructDungeon1BDD4 u32 unk1C06C; // 0x298 }; +#define UNK_1C070_ARR_COUNT 20 +#define UNK_1C070_BUFFER_SIZE 60 + +struct UnkDungeonStruct1C070 +{ + u8 unk0; + u8 unk1; + u8 unk2; + u8 unk3[UNK_1C070_BUFFER_SIZE]; +}; + // size: 0x1CEDC typedef struct Dungeon { @@ -250,6 +261,7 @@ typedef struct Dungeon u8 unk11; s16 unk12; s16 unk14; + s16 unk16; u32 unk18[(0xB8 - 0x18) / 4]; Entity *unkB8; Entity *unkBC; @@ -397,7 +409,7 @@ typedef struct Dungeon /* 0x181E8 */ UnkDungeonGlobal_unk181E8_sub unk181e8; u8 fill18220[0x1BDD4 - 0x1822C]; struct UnkStructDungeon1BDD4 unk1BDD4; - u8 fill1C070[0x1C570 - 0x1C070]; + struct UnkDungeonStruct1C070 unk1C070[UNK_1C070_ARR_COUNT]; /* 0x1C570 */ DungeonLocation unk1C570; /* 0x1C574 */ UnkDungeonGlobal_unk1C574 unk1C574; /* 0x1C590 */ UnkDungeonGlobal_unk1C590 unk1C590[4]; diff --git a/src/code_80521D0.c b/src/code_80521D0.c index 56d77c9d..0f703f3f 100644 --- a/src/code_80521D0.c +++ b/src/code_80521D0.c @@ -5,6 +5,7 @@ #include "code_803E46C.h" #include "code_80130A8.h" #include "code_800E9E4.h" +#include "menu_input.h" #include "code_803E668.h" #include "bg_palette_buffer.h" #include "input.h" @@ -790,3 +791,129 @@ void sub_8052FB8(const u8 *str) } sub_803E708(8, 9); } + +const u8 *GetCurrentDungeonName(void) +{ + if (gDungeon->unk678 == 1) { + return GetDungeonName1(DUNGEON_OUT_ON_RESCUE); + } + else { + return GetDungeonName1(gDungeon->dungeonLocation.id); + } +} + +void sub_80531A8(void) +{ + s32 i; + + gDungeon->unk16 = 0; + gDungeon->unkB = 1; + for (i = 0; i < UNK_1C070_ARR_COUNT; i++) { + gDungeon->unk1C070[i].unk3[0] = 0; + gDungeon->unk1C070[i].unk0 = 0; + gDungeon->unk1C070[i].unk1 = 0; + gDungeon->unk1C070[i].unk2 = 0; + } +} + +UNUSED void sub_8053200(void) +{ + gDungeon->unkB = 1; +} + +void sub_8053210(u8 *txt, u32 a1, u32 a2) +{ + u8 *dst = &gDungeon->unk1C070[gDungeon->unk16].unk3[0]; + u8 *maxDst = &gDungeon->unk1C070[gDungeon->unk16].unk3[UNK_1C070_BUFFER_SIZE - 1]; + gDungeon->unk1C070[gDungeon->unk16].unk0 = 1; + gDungeon->unk1C070[gDungeon->unk16].unk1 = a1; + gDungeon->unk1C070[gDungeon->unk16].unk2 = a2; + + while (*txt != '\0') { + if (*txt == '\r') break; + if (dst < maxDst) { + *(dst++) = *txt; + } + txt++; + } + + *dst = '\0'; + if (++gDungeon->unk16 >= UNK_1C070_ARR_COUNT) { + gDungeon->unk16 = 0; + } + + gDungeon->unkB = 1; +} + +extern const u8 gUnknown_8106990[]; // Possibly something menu related? + +extern bool8 sub_8008D8C(u32 strId); +extern u32 sub_8014140(s32 a0, const void *a1); +extern void sub_8083D30(void); +extern void sub_8083D08(void); + +extern s32 gUnknown_202F1F8; +extern u8 gUnknown_202F1FC; + +void sub_80533A4(void); +bool8 sub_8053540(s32 a0); +bool8 sub_8053430(s32 a0); +void sub_805363C(s32 a0, s32 a1); + +bool32 sub_80532B4(void) +{ + bool8 unkRet; + MenuInputStructSub menuInput; + + sub_801317C(&menuInput); + sub_803EAF0(9, 0); + do { + sub_803E46C(13); + unkRet = sub_8008D8C(0); + } while (unkRet); + + gUnknown_202F1F8 = 0; + gUnknown_202F1FC = 0; + sub_80533A4(); + + while (1) { + s32 unkVar; + bool8 unkBool = FALSE; + + gUnknown_202F1FC = 0; + nullsub_34(&menuInput, 0); + unkVar = sub_8014140(0, gUnknown_8106990); + if (sub_8053430(unkVar)) + unkBool = TRUE; + else + unkBool = FALSE; + + if (sub_8053540(unkVar)) + unkBool = TRUE; + + if (!unkBool) { + sub_803E46C(0xD); + } + + if (gUnknown_202F1FC & 1) { + sub_805363C(1, -8); + } + if (gUnknown_202F1FC & 2) { + sub_805363C(0, 114); + } + + if (!sub_80048C8()) { + if (gRealInputs.pressed & B_BUTTON || menuInput.b_button) { + sub_8083D30(); + break; + } + else if (gRealInputs.pressed & A_BUTTON) { + sub_8083D08(); + break; + } + } + } + + sub_803EAF0(0, 0); + return TRUE; +} diff --git a/src/code_805D8C8_1.c b/src/code_805D8C8_1.c index 3a97f026..eb85a056 100644 --- a/src/code_805D8C8_1.c +++ b/src/code_805D8C8_1.c @@ -2168,7 +2168,7 @@ extern const u8 *const gUnknown_80F91E0; extern const u8 *const gUnknown_80F91A8; extern const u8 *const gUnknown_80FE954; -const u8 *sub_805317C(void); +const u8 *GetCurrentDungeonName(void); void GetWeatherName(u8 *dst, u8 weatherId); extern s32 gFormatData_202DE30[]; @@ -2232,7 +2232,7 @@ void DrawFieldMenu(u8 a0) if (a0) { u32 hours, minutes, seconds; EntityInfo *leaderInfo = GetLeader()->info; - const u8 *dungeonName = sub_805317C(); + const u8 *dungeonName = GetCurrentDungeonName(); x = (136 - sub_8008ED0(dungeonName)) / 2; sub_80073B8(1); diff --git a/src/menu_input.c b/src/menu_input.c index 397d9b54..5b8333d3 100644 --- a/src/menu_input.c +++ b/src/menu_input.c @@ -77,7 +77,7 @@ u32 sub_8012A64(MenuInputStructSub *r0, s32 r1) return sub_8012AE8(); if (r1 != -1) - nullsub_34(r0); + nullsub_34(r0, r1); if (r0->a_button != 0) { r0->a_button = 0; @@ -712,7 +712,7 @@ void AddMenuCursorSprite_(MenuInputStruct *a0, u8 *a1) a0->unk24++; } -void nullsub_34(MenuInputStructSub *a0) +void nullsub_34(MenuInputStructSub *a0, s32 a1) { }