From b20adedb188c4ea9722c878b45075c0afd0e607b Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sat, 21 Sep 2024 12:41:52 +0200 Subject: [PATCH 1/5] sub_803D73C --- asm/code_803D110.s | 418 +--------------------------------- include/structs/str_dungeon.h | 80 +++++-- ld_script.txt | 1 + src/code_803D0D8.c | 12 +- src/code_803D110.c | 410 +++++++++++++++++++++++++++++++++ src/code_8045A00.c | 46 ++-- src/code_809447C.c | 2 +- src/dungeon_music.c | 8 +- src/weather.c | 2 +- 9 files changed, 504 insertions(+), 475 deletions(-) create mode 100644 src/code_803D110.c diff --git a/asm/code_803D110.s b/asm/code_803D110.s index 6c0b66b90..82bf81c7d 100644 --- a/asm/code_803D110.s +++ b/asm/code_803D110.s @@ -5,424 +5,8 @@ .text - thumb_func_start sub_803D4D0 -sub_803D4D0: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x1FC - ldr r6, _0803D654 - ldr r1, [r6] - movs r4, 0xC9 - lsls r4, 3 - adds r0, r1, r4 - ldr r2, _0803D658 - adds r1, r2 - bl sub_80901D8 - ldr r0, [r6] - ldr r3, _0803D65C - adds r2, r0, r3 - adds r1, r0, r4 - ldrh r0, [r2] - ldrh r4, [r1] - cmp r0, r4 - bne _0803D500 - b _0803D6E0 -_0803D500: - ldr r0, [r1] - str r0, [r2] - ldr r0, _0803D660 - ldr r1, _0803D664 - bl OpenFileAndGetFileDataPtr - mov r9, r0 - ldr r3, [r0, 0x4] - ldr r2, [r6] - ldr r7, _0803D65C - adds r0, r2, r7 - ldrb r1, [r0] - ldr r0, [r3] - lsls r1, 2 - adds r1, r0 - ldr r3, _0803D668 - adds r0, r2, r3 - ldrb r0, [r0] - lsls r0, 4 - ldr r1, [r1] - adds r1, r0 - mov r8, r1 - ldr r4, _0803D658 - adds r2, r4 - ldrb r0, [r2] - bl GetDungeonFloorCount - ldr r1, [r6] - ldr r7, _0803D66C - adds r1, r7 - strb r0, [r1] - ldr r0, [r6] - adds r0, r4 - ldrb r0, [r0] - bl sub_80902C8 - ldr r1, [r6] - strh r0, [r1, 0x14] - mov r2, r9 - ldr r0, [r2, 0x4] - mov r3, r8 - movs r4, 0 - ldrsh r2, [r3, r4] - ldr r3, [r0, 0x4] - lsls r0, r2, 3 - subs r0, r2 - lsls r0, 2 - ldr r7, _0803D670 - adds r1, r7 - adds r0, r3 - ldm r0!, {r2-r4} - stm r1!, {r2-r4} - ldm r0!, {r2,r3,r7} - stm r1!, {r2,r3,r7} - ldr r0, [r0] - str r0, [r1] - movs r5, 0 - mov r10, r6 - ldr r4, _0803D674 -_0803D576: - mov r6, r10 - ldr r2, [r6] - lsls r3, r5, 1 - adds r2, r4 - adds r2, r3 - mov r7, r9 - ldr r1, [r7, 0x4] - mov r6, r8 - movs r7, 0x4 - ldrsh r0, [r6, r7] - ldr r1, [r1, 0x10] - lsls r0, 2 - adds r0, r1 - ldr r0, [r0] - adds r3, r0 - ldrh r0, [r3] - strh r0, [r2] - adds r5, 0x1 - cmp r5, 0x13 - ble _0803D576 - movs r5, 0 - adds r6, 0x6 - str r6, [sp, 0x1F8] - ldr r6, _0803D678 - mov r10, r6 -_0803D5A8: - ldr r1, _0803D654 - ldr r0, [r1] - lsls r3, r5, 3 - mov r2, r10 - adds r4, r0, r2 - adds r4, r3 - mov r12, r4 - mov r4, r9 - ldr r2, [r4, 0x4] - mov r7, r8 - movs r4, 0x2 - ldrsh r1, [r7, r4] - ldr r2, [r2, 0xC] - lsls r1, 2 - adds r1, r2 - ldr r1, [r1] - adds r3, r1 - ldr r1, [r3] - ldr r2, [r3, 0x4] - mov r7, r12 - str r1, [r7] - str r2, [r7, 0x4] - adds r0, r6 - bl ExtractSpeciesIndex - lsls r0, 16 - cmp r0, 0 - beq _0803D5E8 - adds r6, 0x8 - adds r5, 0x1 - cmp r5, 0x1E - ble _0803D5A8 -_0803D5E8: - cmp r5, 0x1F - bgt _0803D606 - ldr r6, _0803D654 - lsls r0, r5, 3 - ldr r1, _0803D678 - adds r4, r0, r1 -_0803D5F4: - ldr r0, [r6] - adds r0, r4 - movs r1, 0 - bl sub_808E9C4 - adds r4, 0x8 - adds r5, 0x1 - cmp r5, 0x1F - ble _0803D5F4 -_0803D606: - movs r5, 0 - ldr r2, _0803D67C - mov r10, r2 -_0803D60C: - mov r3, r9 - ldr r1, [r3, 0x4] - lsls r0, r5, 1 - ldr r4, [sp, 0x1F8] - adds r0, r4, r0 - movs r6, 0 - ldrsh r0, [r0, r6] - ldr r1, [r1, 0x8] - lsls r0, 2 - adds r0, r1 - movs r4, 0 - adds r7, r5, 0x1 - mov r8, r7 - lsls r1, r5, 6 - mov r12, r1 - ldr r3, [r0] - mov r2, sp -_0803D62E: - ldrh r0, [r3] - cmp r0, r10 - bls _0803D684 - ldrh r0, [r3] - ldr r6, _0803D680 - adds r1, r0, r6 - cmp r1, 0 - beq _0803D68A - movs r6, 0 - lsls r0, r4, 1 - add r0, sp -_0803D644: - strh r6, [r0] - adds r0, 0x2 - adds r2, 0x2 - adds r4, 0x1 - subs r1, 0x1 - cmp r1, 0 - bne _0803D644 - b _0803D68A - .align 2, 0 -_0803D654: .4byte gDungeon -_0803D658: .4byte 0x00000644 -_0803D65C: .4byte 0x0001c570 -_0803D660: .4byte gUnknown_80F4D8C -_0803D664: .4byte gDungeonFileArchive -_0803D668: .4byte 0x0001c571 -_0803D66C: .4byte 0x0001cec8 -_0803D670: .4byte 0x0001c574 -_0803D674: .4byte 0x0001cd70 -_0803D678: .4byte 0x0001cd98 -_0803D67C: .4byte 0x0000752f -_0803D680: .4byte 0xffff8ad0 -_0803D684: - strh r0, [r2] - adds r2, 0x2 - adds r4, 0x1 -_0803D68A: - adds r3, 0x2 - cmp r4, 0xFB - ble _0803D62E - ldr r7, _0803D6F0 - mov r1, r12 - subs r0, r1, r5 - movs r4, 0xB - mov r3, sp - lsls r2, r0, 3 - ldr r6, _0803D6F4 -_0803D69E: - ldr r0, [r7] - adds r0, r6 - adds r0, r2 - ldrh r1, [r3] - strh r1, [r0] - adds r3, 0x2 - adds r2, 0x2 - subs r4, 0x1 - cmp r4, 0 - bge _0803D69E - ldr r6, _0803D6F0 - mov r2, r12 - subs r0, r2, r5 - lsls r3, r0, 3 - add r2, sp, 0x18 - ldr r5, _0803D6F8 - movs r4, 0xEF -_0803D6C0: - ldr r0, [r6] - adds r0, r5 - adds r0, r3 - ldrh r1, [r2] - strh r1, [r0] - adds r2, 0x2 - adds r3, 0x2 - subs r4, 0x1 - cmp r4, 0 - bge _0803D6C0 - mov r5, r8 - cmp r5, 0x3 - ble _0803D60C - mov r0, r9 - bl CloseFile -_0803D6E0: - add sp, 0x1FC - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_0803D6F0: .4byte gDungeon -_0803D6F4: .4byte 0x0001c590 -_0803D6F8: .4byte 0x0001c5a8 - thumb_func_end sub_803D4D0 + - thumb_func_start sub_803D6FC -sub_803D6FC: - push {r4,lr} - ldr r0, _0803D720 - bl DungeonRandInt - adds r3, r0, 0 - movs r2, 0 - ldr r0, _0803D724 - ldr r0, [r0] - ldr r4, _0803D728 - adds r1, r0, r4 -_0803D710: - ldrh r0, [r1] - cmp r0, 0 - beq _0803D72C - cmp r0, r3 - blt _0803D72C - lsls r0, r2, 24 - lsrs r0, 24 - b _0803D736 - .align 2, 0 -_0803D720: .4byte 0x00002710 -_0803D724: .4byte gDungeon -_0803D728: .4byte 0x0001cd70 -_0803D72C: - adds r1, 0x2 - adds r2, 0x1 - cmp r2, 0x13 - ble _0803D710 - movs r0, 0x10 -_0803D736: - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_803D6FC - - thumb_func_start sub_803D73C -sub_803D73C: - push {r4-r7,lr} - mov r7, r8 - push {r7} - sub sp, 0x8 - adds r4, r0, 0 - ldr r0, _0803D784 - bl DungeonRandInt - adds r7, r0, 0 - movs r0, 0xC - mov r8, r0 - movs r6, 0 - ldr r0, _0803D788 - ldr r2, [r0] - lsls r1, r4, 6 - subs r0, r1, r4 - adds r5, r1, 0 - lsls r0, 3 - ldr r1, _0803D78C - adds r2, r1 - adds r1, r0, r2 -_0803D766: - movs r2, 0 - ldrsh r0, [r1, r2] - cmp r0, 0 - beq _0803D772 - cmp r0, r7 - bge _0803D790 -_0803D772: - adds r1, 0x2 - adds r6, 0x1 - cmp r6, 0xB - ble _0803D766 -_0803D77A: - mov r0, r8 - cmp r0, 0xC - bne _0803D79C - b _0803D7EC - .align 2, 0 -_0803D784: .4byte 0x00002710 -_0803D788: .4byte gDungeon -_0803D78C: .4byte 0x0001c590 -_0803D790: - lsls r0, r6, 24 - lsrs r0, 24 - mov r8, r0 - b _0803D77A -_0803D798: - adds r0, r5, 0 - b _0803D7EE -_0803D79C: - ldr r0, _0803D7FC - bl DungeonRandInt - adds r7, r0, 0 - movs r6, 0 - ldr r2, _0803D800 - subs r0, r5, r4 - ldr r1, _0803D804 - lsls r4, r0, 3 -_0803D7AE: - ldr r0, [r2] - adds r0, r1 - adds r0, r4 - movs r3, 0 - ldrsh r0, [r0, r3] - cmp r0, 0 - beq _0803D7E4 - lsls r0, r6, 24 - lsrs r5, r0, 24 - adds r0, r5, 0 - str r1, [sp] - str r2, [sp, 0x4] - bl GetItemCategory - lsls r0, 24 - lsrs r0, 24 - ldr r1, [sp] - ldr r2, [sp, 0x4] - cmp r0, r8 - bne _0803D7E4 - ldr r0, [r2] - adds r0, r1 - adds r0, r4 - movs r3, 0 - ldrsh r0, [r0, r3] - cmp r0, r7 - bge _0803D798 -_0803D7E4: - adds r4, 0x2 - adds r6, 0x1 - cmp r6, 0xEF - ble _0803D7AE -_0803D7EC: - movs r0, 0x69 -_0803D7EE: - add sp, 0x8 - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r1} - bx r1 - .align 2, 0 -_0803D7FC: .4byte 0x00002710 -_0803D800: .4byte gDungeon -_0803D804: .4byte 0x0001c5a8 - thumb_func_end sub_803D73C thumb_func_start sub_803D808 sub_803D808: diff --git a/include/structs/str_dungeon.h b/include/structs/str_dungeon.h index 3199f5deb..fb0e166fc 100644 --- a/include/structs/str_dungeon.h +++ b/include/structs/str_dungeon.h @@ -47,7 +47,7 @@ typedef struct Weather } Weather; // size: 0x30 -typedef struct unkDungeonGlobal_unk1CE98_sub +typedef struct UnkDungeonGlobal_unk1CE98_sub { /* 0x0 */ u8 buffer1[10]; /* 0xA */ u8 buffer2[10]; @@ -67,7 +67,7 @@ typedef struct unkDungeonGlobal_unk1CE98_sub /* 0x2D */ u8 defBoost; /* 0x2E */ u8 spDefBoost; u8 unk2F; // speedBoost? -} unkDungeonGlobal_unk1CE98_sub; +} UnkDungeonGlobal_unk1CE98_sub; // size: 0x10 typedef struct DungeonMusicPlayer @@ -81,7 +81,7 @@ typedef struct DungeonMusicPlayer } DungeonMusicPlayer; // Size unknown? -typedef struct unkDungeonGlobal_unk181E8_sub +typedef struct UnkDungeonGlobal_unk181E8_sub { /* 0x181E8 */ Position cameraPos; /* 0x181EC */ Position cameraPosMirror; @@ -115,7 +115,51 @@ typedef struct unkDungeonGlobal_unk181E8_sub u8 fill1821D; u8 fill1821E; u8 fill1821F; -} unkDungeonGlobal_unk181E8_sub; +} UnkDungeonGlobal_unk181E8_sub; + +// Sizeof: 0x1C +typedef struct UnkDungeonGlobal_unk1C574 +{ + u8 unk0; + u8 unk1; + u8 unk2; + u8 unk3; + u8 unk4; + u8 unk5; + u8 unk6; + u8 unk7; + u8 unk8; + u8 unk9; + u8 unkA; + u8 unkB; + u8 unkC; + u8 unkD; + u8 unkE; + u8 unkF; + u8 unk10; + u8 unk11; + u8 unk12; + u8 unk13; + u8 unk14; + u8 unk15; + u8 unk16; + u8 unk17; + u8 unk18; + u8 unk19; + u8 unk1A; +} UnkDungeonGlobal_unk1C574; + +typedef struct UnkDungeonGlobal_unk1C590 +{ + s16 unk0[NUM_ITEM_CATEGORIES]; + s16 unk18[NUMBER_OF_ITEM_IDS]; +} UnkDungeonGlobal_unk1C590; + +typedef struct UnkDungeonGlobal_unk1CD98 +{ + struct PokemonStruct1 *unk0; + void *unk4; +} UnkDungeonGlobal_unk1CD98; // size: 0x1CEDC typedef struct Dungeon @@ -136,7 +180,8 @@ typedef struct Dungeon u8 unk10; u8 unk11; s16 unk12; - u8 fill14[0xB8 - 0x14]; + s16 unk14; + u8 fill14[0xB8 - 0x16]; Entity *unkB8; Entity *unkBC; u8 fillC0[0x13C - 0xC0]; @@ -154,7 +199,8 @@ typedef struct Dungeon /* 0x5C0 */ s32 unk5C0; /* 0x5C4 */ u8 fill5C4[0x644 - 0x5C4]; /* 0x644 */ DungeonLocation dungeonLocation; - u8 fill646[0x654 - 0x648]; + /* 0x648 */ DungeonLocation dungeonLocation2; + u8 fill64C[0x654 - 0x64C]; u8 unk654; u8 fill655[0x65B - 0x655]; u8 unk65B; @@ -269,21 +315,17 @@ typedef struct Dungeon /* 0x17B3C */ u32 unk17B40; /* 0x17B44 */ OpenedFile *sprites[MONSTER_MAX]; /* 0x181E4 */ OpenedFile *paletFile; - /* 0x181E8 */ unkDungeonGlobal_unk181E8_sub unk181e8; + /* 0x181E8 */ UnkDungeonGlobal_unk181E8_sub unk181e8; u8 fill18220[0x1C06C - 0x18220]; - u32 unk1C06C; + u32 unk1C06C; u8 fill1C070[0x1C570 - 0x1C070]; - u8 unk1C570; - u8 unk1C571; - u8 fill1C572[0x1C578 - 0x1C572]; - u8 unk1C578; - u8 fill1C579[0x1C57E - 0x1C579]; - u8 unk1C57E; - u8 fill1C57F[0x1C58B - 0x1C57F]; - u8 unk1C58B; - u8 fill1C58C[0x1CE98 - 0x1C58C]; - unkDungeonGlobal_unk1CE98_sub unk1CE98; // TODO: not sure how large this is - u32 unk1CEC8; + /* 0x1C570 */ DungeonLocation unk1C570; + /* 0x1C574 */ UnkDungeonGlobal_unk1C574 unk1C574; + /* 0x1C590 */ UnkDungeonGlobal_unk1C590 unk1C590[4]; + u16 unk1CD70[20]; + UnkDungeonGlobal_unk1CD98 unk1CD98[32]; + UnkDungeonGlobal_unk1CE98_sub unk1CE98; // TODO: not sure how large this is + u8 unk1CEC8; /* 0x1CECC */ DungeonMusicPlayer musPlayer; } Dungeon; diff --git a/ld_script.txt b/ld_script.txt index 0c66956f3..3c3295d40 100755 --- a/ld_script.txt +++ b/ld_script.txt @@ -205,6 +205,7 @@ SECTIONS { src/personality_test1.o(.text); src/personality_test2.o(.text); src/code_803D0D8.o(.text); + src/code_803D110.o(.text); asm/code_803D110.o(.text); src/code_803E46C.o(.text); asm/code_803E724.o(.text); diff --git a/src/code_803D0D8.c b/src/code_803D0D8.c index 2e01b9199..3c424f85d 100644 --- a/src/code_803D0D8.c +++ b/src/code_803D0D8.c @@ -46,7 +46,7 @@ u8 sub_803D110(u8 *param_1, u8 *param_2, s32 size) auStack_40[index1] = 0; } - for (index1 = 0; index1 < size; index1++) + for (index1 = 0; index1 < size; index1++) { local_78[index1] = sub_803D0F0(*param_1); if (local_78[index1] == 0xff) { @@ -107,7 +107,7 @@ bool8 sub_803D204(u8 *buffer,unkStruct_203B480 *param_2) u8 localBuffer [PASSWORD_BUFFER_SIZE]; unkStruct_8094924 uStack_30; s32 index; - + checksum = 0; MemoryCopy8(localBuffer,buffer,sizeof(localBuffer)); for(index = 0; index < PASSWORD_BUFFER_SIZE; index++) @@ -119,9 +119,9 @@ bool8 sub_803D204(u8 *buffer,unkStruct_203B480 *param_2) translateBuffer[index] = localBuffer[innerIndex]; } - + if (sub_803D110(translateBuffer,local_c4,sizeof(translateBuffer)) != 0) { - + for(index = 1; index < 34; index++) { checksum += local_c4[index] + index; @@ -242,6 +242,6 @@ void sub_803D414(u8 *buffer,WonderMail *mail) void sub_803D4AC(void) { - gDungeon->unk1C570 = 0x63; - gDungeon->unk1C571 = 0xFF; + gDungeon->unk1C570.id = 0x63; + gDungeon->unk1C570.floor = 0xFF; } diff --git a/src/code_803D110.c b/src/code_803D110.c new file mode 100644 index 000000000..e5e9d3a1c --- /dev/null +++ b/src/code_803D110.c @@ -0,0 +1,410 @@ +#include "global.h" +#include "dungeon.h" +#include "pokemon.h" +#include "file_system.h" +#include "dungeon_random.h" + +extern void sub_80901D8(DungeonLocation *param_1,DungeonLocation *param_2); +extern s32 sub_80902C8(u8 dungeon); +extern u16 ExtractSpeciesIndex(UnkDungeonGlobal_unk1CD98 *r0); +extern void sub_808E9C4(UnkDungeonGlobal_unk1CD98 *r0, s16 r1); + +extern const char gUnknown_80F4D8C[]; // "mapparam" +extern struct FileArchive gDungeonFileArchive; + +struct UnkDungeonFileData +{ + s16 unk0; + s16 unk2; + s16 unk4; + s16 unk6[5]; +}; + +struct UnkDataFileStruct +{ + struct UnkDungeonFileData **unk0; + UnkDungeonGlobal_unk1C574 *unk4; + u16 **unk8; + UnkDungeonGlobal_unk1CD98 **unkC; + u16 **unk10; +}; + +// TODO https://decomp.me/scratch/nXUH3 +/* +void sub_803D4D0(void) +{ + u16 spArray[252]; + s32 i, j, k; + OpenedFile *file; + struct UnkDungeonFileData *strPtr; + + sub_80901D8(&gDungeon->dungeonLocation2, &gDungeon->dungeonLocation); + if (gDungeon->unk1C570.id == gDungeon->dungeonLocation2.id && gDungeon->unk1C570.floor == gDungeon->dungeonLocation2.floor) + return; + + gDungeon->unk1C570 = gDungeon->dungeonLocation2; + file = OpenFileAndGetFileDataPtr(gUnknown_80F4D8C, &gDungeonFileArchive); + + strPtr = &file->data.dungData->unk0[gDungeon->unk1C570.id][gDungeon->unk1C570.floor]; + + gDungeon->unk1CEC8 = GetDungeonFloorCount(gDungeon->dungeonLocation.id); + gDungeon->unk14 = sub_80902C8(gDungeon->dungeonLocation.id); + + gDungeon->unk1C574 = file->data.dungData->unk4[strPtr->unk0]; + + for (i = 0; i < 20; i++) { + gDungeon->unk1CD70[i] = file->data.dungData->unk10[strPtr->unk4][i]; + } + for (i = 0; i < 31; i++) { + gDungeon->unk1CD98[i] = file->data.dungData->unkC[strPtr->unk2][i]; + if (ExtractSpeciesIndex(&gDungeon->unk1CD98[i]) == 0) + break; + } + while (i <= 31) { + sub_808E9C4(&gDungeon->unk1CD98[i], 0); + i++; + } + + for (i = 0; i < 4; i++) + { + u16 *src = file->data.dungData->unk8[strPtr->unk6[i]]; + + for (j = 0; j < 252; src++) { + if (*src > 29999) { + for (k = *src - 30000; k != 0; k--) { + spArray[j++] = 0; + } + } + else { + spArray[j++] = *src; + } + } + + for (j = 0; j < 12; j++) { + gDungeon->unk1C590[i].unk0[j] = spArray[j]; + } + + for (j = 0; j < 240; j++) { + gDungeon->unk1C590[i].unk18[j] = spArray[12 + j]; + } + } + + CloseFile(file); +} + +*/ +// + +NAKED void sub_803D4D0(void) +{ + asm_unified(" .text\n" +" push {r4-r7,lr}\n" +" mov r7, r10\n" +" mov r6, r9\n" +" mov r5, r8\n" +" push {r5-r7}\n" +" sub sp, 0x1FC\n" +" ldr r6, _0803D654\n" +" ldr r1, [r6]\n" +" movs r4, 0xC9\n" +" lsls r4, 3\n" +" adds r0, r1, r4\n" +" ldr r2, _0803D658\n" +" adds r1, r2\n" +" bl sub_80901D8\n" +" ldr r0, [r6]\n" +" ldr r3, _0803D65C\n" +" adds r2, r0, r3\n" +" adds r1, r0, r4\n" +" ldrh r0, [r2]\n" +" ldrh r4, [r1]\n" +" cmp r0, r4\n" +" bne _0803D500\n" +" b _0803D6E0\n" +"_0803D500:\n" +" ldr r0, [r1]\n" +" str r0, [r2]\n" +" ldr r0, _0803D660\n" +" ldr r1, _0803D664\n" +" bl OpenFileAndGetFileDataPtr\n" +" mov r9, r0\n" +" ldr r3, [r0, 0x4]\n" +" ldr r2, [r6]\n" +" ldr r7, _0803D65C\n" +" adds r0, r2, r7\n" +" ldrb r1, [r0]\n" +" ldr r0, [r3]\n" +" lsls r1, 2\n" +" adds r1, r0\n" +" ldr r3, _0803D668\n" +" adds r0, r2, r3\n" +" ldrb r0, [r0]\n" +" lsls r0, 4\n" +" ldr r1, [r1]\n" +" adds r1, r0\n" +" mov r8, r1\n" +" ldr r4, _0803D658\n" +" adds r2, r4\n" +" ldrb r0, [r2]\n" +" bl GetDungeonFloorCount\n" +" ldr r1, [r6]\n" +" ldr r7, _0803D66C\n" +" adds r1, r7\n" +" strb r0, [r1]\n" +" ldr r0, [r6]\n" +" adds r0, r4\n" +" ldrb r0, [r0]\n" +" bl sub_80902C8\n" +" ldr r1, [r6]\n" +" strh r0, [r1, 0x14]\n" +" mov r2, r9\n" +" ldr r0, [r2, 0x4]\n" +" mov r3, r8\n" +" movs r4, 0\n" +" ldrsh r2, [r3, r4]\n" +" ldr r3, [r0, 0x4]\n" +" lsls r0, r2, 3\n" +" subs r0, r2\n" +" lsls r0, 2\n" +" ldr r7, _0803D670\n" +" adds r1, r7\n" +" adds r0, r3\n" +" ldm r0!, {r2-r4}\n" +" stm r1!, {r2-r4}\n" +" ldm r0!, {r2,r3,r7}\n" +" stm r1!, {r2,r3,r7}\n" +" ldr r0, [r0]\n" +" str r0, [r1]\n" +" movs r5, 0\n" +" mov r10, r6\n" +" ldr r4, _0803D674\n" +"_0803D576:\n" +" mov r6, r10\n" +" ldr r2, [r6]\n" +" lsls r3, r5, 1\n" +" adds r2, r4\n" +" adds r2, r3\n" +" mov r7, r9\n" +" ldr r1, [r7, 0x4]\n" +" mov r6, r8\n" +" movs r7, 0x4\n" +" ldrsh r0, [r6, r7]\n" +" ldr r1, [r1, 0x10]\n" +" lsls r0, 2\n" +" adds r0, r1\n" +" ldr r0, [r0]\n" +" adds r3, r0\n" +" ldrh r0, [r3]\n" +" strh r0, [r2]\n" +" adds r5, 0x1\n" +" cmp r5, 0x13\n" +" ble _0803D576\n" +" movs r5, 0\n" +" adds r6, 0x6\n" +" str r6, [sp, 0x1F8]\n" +" ldr r6, _0803D678\n" +" mov r10, r6\n" +"_0803D5A8:\n" +" ldr r1, _0803D654\n" +" ldr r0, [r1]\n" +" lsls r3, r5, 3\n" +" mov r2, r10\n" +" adds r4, r0, r2\n" +" adds r4, r3\n" +" mov r12, r4\n" +" mov r4, r9\n" +" ldr r2, [r4, 0x4]\n" +" mov r7, r8\n" +" movs r4, 0x2\n" +" ldrsh r1, [r7, r4]\n" +" ldr r2, [r2, 0xC]\n" +" lsls r1, 2\n" +" adds r1, r2\n" +" ldr r1, [r1]\n" +" adds r3, r1\n" +" ldr r1, [r3]\n" +" ldr r2, [r3, 0x4]\n" +" mov r7, r12\n" +" str r1, [r7]\n" +" str r2, [r7, 0x4]\n" +" adds r0, r6\n" +" bl ExtractSpeciesIndex\n" +" lsls r0, 16\n" +" cmp r0, 0\n" +" beq _0803D5E8\n" +" adds r6, 0x8\n" +" adds r5, 0x1\n" +" cmp r5, 0x1E\n" +" ble _0803D5A8\n" +"_0803D5E8:\n" +" cmp r5, 0x1F\n" +" bgt _0803D606\n" +" ldr r6, _0803D654\n" +" lsls r0, r5, 3\n" +" ldr r1, _0803D678\n" +" adds r4, r0, r1\n" +"_0803D5F4:\n" +" ldr r0, [r6]\n" +" adds r0, r4\n" +" movs r1, 0\n" +" bl sub_808E9C4\n" +" adds r4, 0x8\n" +" adds r5, 0x1\n" +" cmp r5, 0x1F\n" +" ble _0803D5F4\n" +"_0803D606:\n" +" movs r5, 0\n" +" ldr r2, _0803D67C\n" +" mov r10, r2\n" +"_0803D60C:\n" +" mov r3, r9\n" +" ldr r1, [r3, 0x4]\n" +" lsls r0, r5, 1\n" +" ldr r4, [sp, 0x1F8]\n" +" adds r0, r4, r0\n" +" movs r6, 0\n" +" ldrsh r0, [r0, r6]\n" +" ldr r1, [r1, 0x8]\n" +" lsls r0, 2\n" +" adds r0, r1\n" +" movs r4, 0\n" +" adds r7, r5, 0x1\n" +" mov r8, r7\n" +" lsls r1, r5, 6\n" +" mov r12, r1\n" +" ldr r3, [r0]\n" +" mov r2, sp\n" +"_0803D62E:\n" +" ldrh r0, [r3]\n" +" cmp r0, r10\n" +" bls _0803D684\n" +" ldrh r0, [r3]\n" +" ldr r6, _0803D680\n" +" adds r1, r0, r6\n" +" cmp r1, 0\n" +" beq _0803D68A\n" +" movs r6, 0\n" +" lsls r0, r4, 1\n" +" add r0, sp\n" +"_0803D644:\n" +" strh r6, [r0]\n" +" adds r0, 0x2\n" +" adds r2, 0x2\n" +" adds r4, 0x1\n" +" subs r1, 0x1\n" +" cmp r1, 0\n" +" bne _0803D644\n" +" b _0803D68A\n" +" .align 2, 0\n" +"_0803D654: .4byte gDungeon\n" +"_0803D658: .4byte 0x00000644\n" +"_0803D65C: .4byte 0x0001c570\n" +"_0803D660: .4byte gUnknown_80F4D8C\n" +"_0803D664: .4byte gDungeonFileArchive\n" +"_0803D668: .4byte 0x0001c571\n" +"_0803D66C: .4byte 0x0001cec8\n" +"_0803D670: .4byte 0x0001c574\n" +"_0803D674: .4byte 0x0001cd70\n" +"_0803D678: .4byte 0x0001cd98\n" +"_0803D67C: .4byte 0x0000752f\n" +"_0803D680: .4byte 0xffff8ad0\n" +"_0803D684:\n" +" strh r0, [r2]\n" +" adds r2, 0x2\n" +" adds r4, 0x1\n" +"_0803D68A:\n" +" adds r3, 0x2\n" +" cmp r4, 0xFB\n" +" ble _0803D62E\n" +" ldr r7, _0803D6F0\n" +" mov r1, r12\n" +" subs r0, r1, r5\n" +" movs r4, 0xB\n" +" mov r3, sp\n" +" lsls r2, r0, 3\n" +" ldr r6, _0803D6F4\n" +"_0803D69E:\n" +" ldr r0, [r7]\n" +" adds r0, r6\n" +" adds r0, r2\n" +" ldrh r1, [r3]\n" +" strh r1, [r0]\n" +" adds r3, 0x2\n" +" adds r2, 0x2\n" +" subs r4, 0x1\n" +" cmp r4, 0\n" +" bge _0803D69E\n" +" ldr r6, _0803D6F0\n" +" mov r2, r12\n" +" subs r0, r2, r5\n" +" lsls r3, r0, 3\n" +" add r2, sp, 0x18\n" +" ldr r5, _0803D6F8\n" +" movs r4, 0xEF\n" +"_0803D6C0:\n" +" ldr r0, [r6]\n" +" adds r0, r5\n" +" adds r0, r3\n" +" ldrh r1, [r2]\n" +" strh r1, [r0]\n" +" adds r2, 0x2\n" +" adds r3, 0x2\n" +" subs r4, 0x1\n" +" cmp r4, 0\n" +" bge _0803D6C0\n" +" mov r5, r8\n" +" cmp r5, 0x3\n" +" ble _0803D60C\n" +" mov r0, r9\n" +" bl CloseFile\n" +"_0803D6E0:\n" +" add sp, 0x1FC\n" +" pop {r3-r5}\n" +" mov r8, r3\n" +" mov r9, r4\n" +" mov r10, r5\n" +" pop {r4-r7}\n" +" pop {r0}\n" +" bx r0\n" +" .align 2, 0\n" +"_0803D6F0: .4byte gDungeon\n" +"_0803D6F4: .4byte 0x0001c590\n" +"_0803D6F8: .4byte 0x0001c5a8\n"); +} + +u8 sub_803D6FC(void) +{ + s32 i; + s32 rand = DungeonRandInt(10000); + for (i = 0; i < 20; i++) { + if (gDungeon->unk1CD70[i] != 0 && gDungeon->unk1CD70[i] >= rand) + return i; + } + + return 16; +} + +u8 sub_803D73C(s32 a0) +{ + s32 i; + s32 rand = DungeonRandInt(10000); + u8 category = NUM_ITEM_CATEGORIES; + for (i = 0; i < NUM_ITEM_CATEGORIES; i++) { + if (gDungeon->unk1C590[a0].unk0[i] != 0 && gDungeon->unk1C590[a0].unk0[i] >= rand) { + category = i; + break; + } + } + if (category == NUM_ITEM_CATEGORIES) + return 105; + + rand = DungeonRandInt(10000); + for (i = 0; i < NUMBER_OF_ITEM_IDS; i++) { + if (gDungeon->unk1C590[a0].unk18[i] != 0 && GetItemCategory(i) == category && gDungeon->unk1C590[a0].unk18[i] >= rand) { + return i; + } + } + + return 105; +} + diff --git a/src/code_8045A00.c b/src/code_8045A00.c index e9b2268e5..38cdf10e0 100644 --- a/src/code_8045A00.c +++ b/src/code_8045A00.c @@ -98,38 +98,30 @@ void sub_8045C18(u8 *buffer, Item *item) sub_8090E14(buffer, item, &gUnknown_80F6990); } -void sub_8045C28(Item *Item, u8 itemID, u32 param_3) +void sub_8045C28(Item *item, u8 itemID, u32 param_3) { - bool8 stickyFlag; - u32 total; - - xxx_init_itemslot_8090A8C(Item,itemID,0); - stickyFlag = FALSE; - if (IsNotSpecialItem(itemID)) { - if (param_3 == 0) { - if (DungeonRandInt(100) >= gDungeon->unk1C57E) - { - goto _short; + bool8 stickyFlag; + + xxx_init_itemslot_8090A8C(item,itemID,0); + stickyFlag = FALSE; + if (IsNotSpecialItem(itemID)) { + if (param_3 == 0) { + if (DungeonRandInt(100) < gDungeon->unk1C574.unkA) + stickyFlag = TRUE; + else + stickyFlag = FALSE; } - else - { - goto _store; + else if (param_3 == 1) { + stickyFlag = TRUE; } } - else if (param_3 == 1) { - stickyFlag = TRUE; + if (stickyFlag) { + item->flags |= ITEM_FLAG_STICKY; + } + + if (GetItemCategory(itemID) == CATEGORY_POKE) { + sub_8046CE4(item, gDungeon->unk1C574.unk17 * 40); } - } -_short: - if (stickyFlag) -_store: - Item->flags = Item->flags | ITEM_FLAG_STICKY; - if (GetItemCategory(itemID) == CATEGORY_POKE) { - // FIXME: total hack but too lazy to figure out array for now - total = (gDungeon->unk1C58B << 2) + gDungeon->unk1C58B; - total <<= 3; - sub_8046CE4(Item, total); - } } void sub_8045CB0(void) diff --git a/src/code_809447C.c b/src/code_809447C.c index 090a080ff..869fbf568 100644 --- a/src/code_809447C.c +++ b/src/code_809447C.c @@ -80,7 +80,7 @@ static u8 sub_8094528(s16 moveID) } } -void sub_8094558(u32 param_1,u8 *param_2,unkDungeonGlobal_unk1CE98_sub *param_3) +void sub_8094558(u32 param_1,u8 *param_2,UnkDungeonGlobal_unk1CE98_sub *param_3) { u8 buffer [200]; s32 x, y; diff --git a/src/dungeon_music.c b/src/dungeon_music.c index 36c839621..fc486f8d9 100644 --- a/src/dungeon_music.c +++ b/src/dungeon_music.c @@ -34,7 +34,7 @@ void sub_8083AB0(s16 param_0, Entity * target, Entity * entity) EntityInfo * targetEntityInfo; u8 *spAttPtr; u8 buffer [0x14]; - unkDungeonGlobal_unk1CE98_sub *temp; + UnkDungeonGlobal_unk1CE98_sub *temp; u8 *id; s32 param_0_s32 = param_0; @@ -96,7 +96,7 @@ void sub_8083AB0(s16 param_0, Entity * target, Entity * entity) bool8 sub_8083C24(void) { - unkDungeonGlobal_unk1CE98_sub *temp; + UnkDungeonGlobal_unk1CE98_sub *temp; temp = &gDungeon->unk1CE98; @@ -110,7 +110,7 @@ bool8 sub_8083C24(void) bool8 sub_8083C50(void) { - unkDungeonGlobal_unk1CE98_sub *temp; + UnkDungeonGlobal_unk1CE98_sub *temp; temp = &gDungeon->unk1CE98; @@ -124,7 +124,7 @@ bool8 sub_8083C50(void) bool8 sub_8083C88(u8 param_1) { - unkDungeonGlobal_unk1CE98_sub *temp; + UnkDungeonGlobal_unk1CE98_sub *temp; temp = &gDungeon->unk1CE98; diff --git a/src/weather.c b/src/weather.c index f64ed70aa..cd391ee9e 100644 --- a/src/weather.c +++ b/src/weather.c @@ -25,7 +25,7 @@ u8 GetApparentWeather(Entity *pokemon) void sub_807E5AC(void) { u8 weather; - weather = gDungeon->unk1C578; + weather = gDungeon->unk1C574.unk4; if(weather == WEATHER_RANDOM) weather = DungeonRandInt(WEATHER_RANDOM); sub_807E5E4(weather); From 1c9a67668a558ad75e4eb5e00745f1088584a3de Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sat, 21 Sep 2024 19:58:53 +0200 Subject: [PATCH 2/5] ShowDungeonNameBanner --- asm/code_803D110.s | 519 ---------------------------------- include/structs/str_dungeon.h | 13 +- src/code_803D110.c | 168 ++++++++++- 3 files changed, 176 insertions(+), 524 deletions(-) diff --git a/asm/code_803D110.s b/asm/code_803D110.s index 82bf81c7d..dfd3fca66 100644 --- a/asm/code_803D110.s +++ b/asm/code_803D110.s @@ -5,527 +5,8 @@ .text - - thumb_func_start sub_803D808 -sub_803D808: - push {r4-r7,lr} - mov r7, r8 - push {r7} - sub sp, 0x4 - adds r7, r1, 0 - movs r6, 0 - ldr r2, _0803D820 - lsls r1, r7, 3 - adds r1, r0 - mov r8, r1 - b _0803D840 - .align 2, 0 -_0803D820: .4byte 0x0001cd98 -_0803D824: - ldr r0, [r5] - ldr r1, _0803D868 - adds r0, r1 - adds r0, r4 - ldr r1, [r0, 0x4] - ldr r0, [r0] - mov r3, r8 - adds r3, 0x8 - mov r8, r3 - subs r3, 0x8 - stm r3!, {r0,r1} - adds r7, 0x1 - adds r2, 0x8 - adds r6, 0x1 -_0803D840: - cmp r6, 0x1F - bgt _0803D85A - ldr r5, _0803D86C - lsls r4, r6, 3 - ldr r0, [r5] - adds r0, r2 - str r2, [sp] - bl ExtractSpeciesIndex - lsls r0, 16 - ldr r2, [sp] - cmp r0, 0 - bne _0803D824 -_0803D85A: - adds r0, r7, 0 - add sp, 0x4 - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r1} - bx r1 - .align 2, 0 -_0803D868: .4byte 0x0001cd98 -_0803D86C: .4byte gDungeon - thumb_func_end sub_803D808 - - thumb_func_start sub_803D870 -sub_803D870: - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - adds r6, r1, 0 - movs r5, 0 - lsls r1, r6, 3 - adds r1, r0 - mov r9, r1 - b _0803D8B8 -_0803D884: - bl GetBodySize - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x1 - bhi _0803D8B6 - ldr r1, [r7] - adds r0, r1, r4 - ldr r2, _0803D8E4 - adds r0, r2 - movs r2, 0 - ldrsh r0, [r0, r2] - cmp r0, 0 - beq _0803D8B6 - mov r2, r8 - adds r0, r1, r2 - adds r0, r4 - ldr r1, [r0, 0x4] - ldr r0, [r0] - mov r2, r9 - adds r2, 0x8 - mov r9, r2 - subs r2, 0x8 - stm r2!, {r0,r1} - adds r6, 0x1 -_0803D8B6: - adds r5, 0x1 -_0803D8B8: - cmp r5, 0x1F - bgt _0803D8D6 - ldr r7, _0803D8E8 - lsls r4, r5, 3 - ldr r0, _0803D8EC - mov r8, r0 - adds r1, r4, r0 - ldr r0, [r7] - adds r0, r1 - bl ExtractSpeciesIndex - lsls r0, 16 - asrs r0, 16 - cmp r0, 0 - bne _0803D884 -_0803D8D6: - adds r0, r6, 0 - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r1} - bx r1 - .align 2, 0 -_0803D8E4: .4byte 0x0001cd9a -_0803D8E8: .4byte gDungeon -_0803D8EC: .4byte 0x0001cd98 - thumb_func_end sub_803D870 - - thumb_func_start sub_803D8F0 -sub_803D8F0: - push {r4,lr} - ldr r4, _0803D920 - ldr r0, [r4] - ldr r2, _0803D924 - adds r1, r0, r2 - ldrb r0, [r1] - cmp r0, 0 - bne _0803D918 - movs r0, 0x1 - strb r0, [r1] - ldr r0, [r4] - ldr r1, _0803D928 - adds r0, r1 - movs r1, 0 - bl sub_803D808 - ldr r1, [r4] - ldr r2, _0803D92C - adds r1, r2 - str r0, [r1] -_0803D918: - pop {r4} - pop {r0} - bx r0 - .align 2, 0 -_0803D920: .4byte gDungeon -_0803D924: .4byte 0x000037ec -_0803D928: .4byte 0x0000343c -_0803D92C: .4byte 0x000037e4 - thumb_func_end sub_803D8F0 - - thumb_func_start sub_803D930 -sub_803D930: - push {r4-r7,lr} - lsls r0, 16 - asrs r6, r0, 16 - movs r5, 0 - ldr r7, _0803D940 - ldr r4, _0803D944 - b _0803D954 - .align 2, 0 -_0803D940: .4byte gDungeon -_0803D944: .4byte 0x0001cd98 -_0803D948: - cmp r0, r6 - bne _0803D950 - movs r0, 0x1 - b _0803D96A -_0803D950: - adds r4, 0x8 - adds r5, 0x1 -_0803D954: - cmp r5, 0x1F - bgt _0803D968 - ldr r0, [r7] - adds r0, r4 - bl ExtractSpeciesIndex - lsls r0, 16 - asrs r0, 16 - cmp r0, 0 - bne _0803D948 -_0803D968: - movs r0, 0 -_0803D96A: - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_803D930 - - thumb_func_start sub_803D970 -sub_803D970: - push {r4-r7,lr} - adds r5, r0, 0 - ldr r0, _0803D9EC - bl DungeonRandInt - adds r6, r0, 0 - movs r3, 0 - ldr r1, _0803D9F0 - ldr r0, [r1] - ldr r2, _0803D9F4 - adds r0, r2 - ldr r0, [r0] - cmp r3, r0 - bge _0803D9BA - ldr r4, _0803D9F8 -_0803D98E: - ldr r2, [r1] - lsls r1, r5, 1 - lsls r0, r3, 3 - adds r1, r0 - ldr r7, _0803D9FC - adds r0, r2, r7 - adds r1, r0, r1 - movs r7, 0 - ldrsh r0, [r1, r7] - cmp r0, 0 - beq _0803D9A8 - cmp r0, r6 - bge _0803D9E0 -_0803D9A8: - adds r4, 0x8 - adds r3, 0x1 - ldr r1, _0803D9F0 - ldr r0, [r1] - ldr r2, _0803D9F4 - adds r0, r2 - ldr r0, [r0] - cmp r3, r0 - blt _0803D98E -_0803D9BA: - movs r3, 0 - ldr r0, _0803D9F0 - ldr r1, [r0] - ldr r7, _0803D9F4 - adds r1, r7 - ldr r1, [r1] - adds r6, r0, 0 - cmp r3, r1 - bge _0803DA10 - ldr r4, _0803D9F8 - lsls r1, r5, 1 -_0803D9D0: - ldr r2, [r6] - ldr r5, _0803D9FC - adds r0, r2, r5 - adds r0, r1 - movs r7, 0 - ldrsh r0, [r0, r7] - cmp r0, 0 - beq _0803DA00 -_0803D9E0: - adds r0, r2, r4 - bl ExtractSpeciesIndex - lsls r0, 16 - asrs r0, 16 - b _0803DA14 - .align 2, 0 -_0803D9EC: .4byte 0x00002710 -_0803D9F0: .4byte gDungeon -_0803D9F4: .4byte 0x000037e4 -_0803D9F8: .4byte 0x0000343c -_0803D9FC: .4byte 0x0000343e -_0803DA00: - adds r4, 0x8 - adds r1, 0x8 - adds r3, 0x1 - ldr r5, _0803DA1C - adds r0, r2, r5 - ldr r0, [r0] - cmp r3, r0 - blt _0803D9D0 -_0803DA10: - movs r0, 0xBE - lsls r0, 1 -_0803DA14: - pop {r4-r7} - pop {r1} - bx r1 - .align 2, 0 -_0803DA1C: .4byte 0x000037e4 - thumb_func_end sub_803D970 - - thumb_func_start sub_803DA20 -sub_803DA20: - push {r4-r7,lr} - lsls r0, 16 - asrs r7, r0, 16 - movs r5, 0 - ldr r1, _0803DA54 - ldr r0, [r1] - ldr r2, _0803DA58 - adds r0, r2 - ldr r0, [r0] - cmp r5, r0 - bge _0803DA70 - adds r6, r1, 0 - ldr r4, _0803DA5C -_0803DA3A: - ldr r0, [r6] - adds r0, r4 - bl ExtractSpeciesIndex - lsls r0, 16 - asrs r0, 16 - cmp r0, r7 - bne _0803DA60 - ldr r0, [r6] - adds r0, r4 - bl ExtractLevel - b _0803DA72 - .align 2, 0 -_0803DA54: .4byte gDungeon -_0803DA58: .4byte 0x000037e4 -_0803DA5C: .4byte 0x0000343c -_0803DA60: - adds r4, 0x8 - adds r5, 0x1 - ldr r0, [r6] - ldr r1, _0803DA78 - adds r0, r1 - ldr r0, [r0] - cmp r5, r0 - blt _0803DA3A -_0803DA70: - movs r0, 0x1 -_0803DA72: - pop {r4-r7} - pop {r1} - bx r1 - .align 2, 0 -_0803DA78: .4byte 0x000037e4 - thumb_func_end sub_803DA20 - - thumb_func_start ShowDungeonNameBanner -ShowDungeonNameBanner: - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - sub sp, 0x68 - ldr r0, _0803DB84 - ldr r4, _0803DB88 - adds r1, r4, 0 - bl OpenFileAndGetFileDataPtr - ldr r5, _0803DB8C - str r0, [r5] - ldr r0, _0803DB90 - adds r1, r4, 0 - bl OpenFileAndGetFileDataPtr - ldr r1, _0803DB94 - str r0, [r1] - ldr r1, _0803DB98 - ldr r0, [r0, 0x4] - ldr r0, [r0, 0x4] - str r0, [r1] - movs r4, 0 -_0803DAAA: - adds r0, r4, 0 - adds r0, 0xE0 - ldr r1, [r5] - lsls r2, r4, 2 - ldr r1, [r1, 0x4] - adds r1, r2 - bl SetBGPaletteBufferColorArray - adds r4, 0x1 - cmp r4, 0xF - ble _0803DAAA - ldr r0, _0803DB9C - movs r1, 0xE0 - lsls r1, 5 - bl CpuClear - bl sub_80848EC - lsls r0, 24 - cmp r0, 0 - bne _0803DAD6 - b _0803DBEA -_0803DAD6: - ldr r0, _0803DBA0 - ldr r0, [r0] - ldr r1, _0803DBA4 - adds r2, r0, r1 - movs r3, 0x14 - ldrsh r1, [r0, r3] - ldrb r2, [r2] - adds r2, r1 - mov r8, r2 - ldr r1, _0803DBA8 - adds r0, r1 - ldrb r0, [r0] - bl GetDungeonName2 - mov r9, r0 - movs r5, 0xA - movs r0, 0 -_0803DAF8: - movs r4, 0 - adds r6, r0, 0x4 - adds r7, r0, 0x1 -_0803DAFE: - adds r4, 0x1 - ldr r3, _0803DBAC - adds r0, r3, 0 - adds r2, r5, 0 - orrs r2, r0 - lsls r2, 16 - lsrs r2, 16 - adds r0, r4, 0 - adds r1, r6, 0 - movs r3, 0 - bl sub_8008DC8 - adds r5, 0x1 - cmp r4, 0x1B - ble _0803DAFE - adds r0, r7, 0 - cmp r0, 0x7 - ble _0803DAF8 - mov r0, r9 - bl CalcStringWidth - movs r1, 0xE0 - subs r1, r0 - lsrs r0, r1, 31 - adds r1, r0 - asrs r1, 1 - mov r0, r9 - movs r2, 0 - bl sub_803DC14 - adds r7, r0, 0 - ldr r0, _0803DBA0 - ldr r0, [r0] - ldr r1, _0803DBA8 - adds r0, r1 - ldrb r0, [r0] - bl IsStairDirectionUp - lsls r0, 24 - ldr r6, _0803DBB0 - cmp r0, 0 - beq _0803DB54 - ldr r6, _0803DBB4 -_0803DB54: - mov r3, r8 - cmp r3, 0x9 - ble _0803DBBC - ldr r5, _0803DBB8 - mov r0, r8 - movs r1, 0xA - bl __divsi3 - adds r4, r0, 0 - adds r4, 0x30 - mov r0, r8 - movs r1, 0xA - bl __modsi3 - adds r0, 0x30 - str r0, [sp] - add r0, sp, 0x4 - adds r1, r5, 0 - adds r2, r6, 0 - adds r3, r4, 0 - bl sprintfStatic - b _0803DBCA - .align 2, 0 -_0803DB84: .4byte gUnknown_80F60F8 -_0803DB88: .4byte gDungeonFileArchive -_0803DB8C: .4byte gDungeonNameBannerPalette -_0803DB90: .4byte gUnknown_80F6100 -_0803DB94: .4byte gDungeonNameBannerFontFile -_0803DB98: .4byte gDungeonNameBannerFont -_0803DB9C: .4byte 0x06000140 -_0803DBA0: .4byte gDungeon -_0803DBA4: .4byte 0x00000645 -_0803DBA8: .4byte 0x00000644 -_0803DBAC: .4byte 0xffffe000 -_0803DBB0: .4byte gUnknown_80F610C -_0803DBB4: .4byte gUnknown_80F6108 -_0803DBB8: .4byte gUnknown_80F6110 -_0803DBBC: - ldr r1, _0803DC08 - mov r3, r8 - adds r3, 0x30 - add r0, sp, 0x4 - adds r2, r6, 0 - bl sprintfStatic -_0803DBCA: - add r0, sp, 0x4 - bl CalcStringWidth - movs r1, 0xE0 - subs r1, r0 - lsrs r0, r1, 31 - adds r1, r0 - asrs r1, 1 - adds r2, r7, 0 - adds r2, 0x20 - add r0, sp, 0x4 - bl sub_803DC14 - ldr r1, _0803DC0C - movs r0, 0x1 - strb r0, [r1] -_0803DBEA: - ldr r0, _0803DC10 - ldr r0, [r0] - bl CloseFile - movs r0, 0x2 - bl sub_803E46C - add sp, 0x68 - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_0803DC08: .4byte gUnknown_80F6118 -_0803DC0C: .4byte gUnknown_20274A5 -_0803DC10: .4byte gDungeonNameBannerFontFile - thumb_func_end ShowDungeonNameBanner - thumb_func_start sub_803DC14 sub_803DC14: push {r4-r6,lr} diff --git a/include/structs/str_dungeon.h b/include/structs/str_dungeon.h index fb0e166fc..d1cf5b0ae 100644 --- a/include/structs/str_dungeon.h +++ b/include/structs/str_dungeon.h @@ -157,8 +157,8 @@ typedef struct UnkDungeonGlobal_unk1C590 typedef struct UnkDungeonGlobal_unk1CD98 { - struct PokemonStruct1 *unk0; - void *unk4; + s16 unk0; // species + s16 unk2[2]; } UnkDungeonGlobal_unk1CD98; // size: 0x1CEDC @@ -242,9 +242,14 @@ typedef struct Dungeon u8 fill69A[0x69C - 0x69A]; EntityInfo unk69C[4]; EntityInfo unkEBC[1]; // Unsure about the size... See sub_8082A08() - u8 fill10C4[0x363C - 0x10C4]; + u8 fill10C4[0x343C - 0x10C4]; + /* 0x343C */ UnkDungeonGlobal_unk1CD98 unk343C[32]; + u8 fill353C[0x363c-0x353c]; /* 0x363C */ u8 expYieldRankings[NUM_MONSTERS]; - u8 fill37D9[0x37F0 - 0x37D9]; + u8 fill37D9[0x37E4 - 0x37D9]; + /* 0x37E4 */ s32 unk37E4; + u8 fill37E8[4]; + /* 0x37EC */ u8 unk37EC; /* 0x37F0 */ u32 unk37F0; /* 0x37F4 */ s32 unk37F4; /* 0x37F8 */ bool8 plusIsActive[2]; // Index 0: Enemy , Index 1: Team diff --git a/src/code_803D110.c b/src/code_803D110.c index e5e9d3a1c..851a9c10a 100644 --- a/src/code_803D110.c +++ b/src/code_803D110.c @@ -2,15 +2,27 @@ #include "dungeon.h" #include "pokemon.h" #include "file_system.h" +#include "code_803E46C.h" +#include "cpu.h" #include "dungeon_random.h" +#include "bg_palette_buffer.h" +#include "code_800D090.h" extern void sub_80901D8(DungeonLocation *param_1,DungeonLocation *param_2); extern s32 sub_80902C8(u8 dungeon); -extern u16 ExtractSpeciesIndex(UnkDungeonGlobal_unk1CD98 *r0); +extern s16 ExtractSpeciesIndex(UnkDungeonGlobal_unk1CD98 *r0); +extern u32 ExtractLevel(UnkDungeonGlobal_unk1CD98 *r0); extern void sub_808E9C4(UnkDungeonGlobal_unk1CD98 *r0, s16 r1); +extern u8 GetBodySize(s16 index); +extern bool8 sub_80848EC(void); extern const char gUnknown_80F4D8C[]; // "mapparam" +extern const char gUnknown_80F60F8[]; // "banrpal" +extern const char gUnknown_80F6100[]; // "banfont" extern struct FileArchive gDungeonFileArchive; +extern OpenedFile *gDungeonNameBannerPalette; +extern OpenedFile *gDungeonNameBannerFontFile; +extern void *gDungeonNameBannerFont; struct UnkDungeonFileData { @@ -408,3 +420,157 @@ u8 sub_803D73C(s32 a0) return 105; } +s32 sub_803D808(UnkDungeonGlobal_unk1CD98 *strPtr, s32 id) +{ + s32 i; + + for (i = 0; i < 32; i++) { + if (ExtractSpeciesIndex(&gDungeon->unk1CD98[i]) == 0) + break; + strPtr[id] = gDungeon->unk1CD98[i]; + id++; + } + + return id; +} + +s32 sub_803D870(UnkDungeonGlobal_unk1CD98 *strPtr, s32 id) +{ + s32 i; + + for (i = 0; i < 32; i++) { + s16 species = ExtractSpeciesIndex(&gDungeon->unk1CD98[i]); + if (species == 0) + break; + if (GetBodySize(species) < 2 && gDungeon->unk1CD98[i].unk2[0] != 0) { + strPtr[id] = gDungeon->unk1CD98[i]; + id++; + } + } + + return id; +} + +void sub_803D8F0(void) +{ + if (gDungeon->unk37EC == 0) { + gDungeon->unk37EC = 1; + gDungeon->unk37E4 = sub_803D808(gDungeon->unk343C, 0); + } +} + +// Hmm... +static inline s16 SpeciesId(s32 id) +{ + return id; +} + +bool8 sub_803D930(s16 speciesToFind) +{ + s32 i; + s32 id = SpeciesId(speciesToFind); + + for (i = 0; i < 32; i++) { + s16 species = ExtractSpeciesIndex(&gDungeon->unk1CD98[i]); + if (species == 0) + break; + if (species == id) + return TRUE; + } + return FALSE; +} + +s16 sub_803D970(s32 arrId) +{ + s32 i; + s32 rand = DungeonRandInt(10000); + + for (i = 0; i < gDungeon->unk37E4; i++) { + if (gDungeon->unk343C[i].unk2[arrId] != 0 && gDungeon->unk343C[i].unk2[arrId] >= rand) { + return ExtractSpeciesIndex(&gDungeon->unk343C[i]); + } + } + for (i = 0; i < gDungeon->unk37E4; i++) { + if (gDungeon->unk343C[i].unk2[arrId] != 0) { + return ExtractSpeciesIndex(&gDungeon->unk343C[i]); + } + } + + return MONSTER_KECLEON; +} + +s32 sub_803DA20(s32 species) +{ + s32 i; + s32 speciesId = SpeciesId(species); + + for (i = 0; i < gDungeon->unk37E4; i++) { + if (ExtractSpeciesIndex(&gDungeon->unk343C[i]) == speciesId) + return ExtractLevel(&gDungeon->unk343C[i]); + } + return 1; +} + +extern const u8 *GetDungeonName2(u8 dungeon); +extern void sub_8008DC8(s32 r0, s32 r1, u16 r2, u16 r3); + +extern const char gUnknown_80F6108[]; +extern const char gUnknown_80F610C[]; +extern const char gUnknown_80F6110[]; +extern const char gUnknown_80F6118[]; + +extern u8 gUnknown_20274A5; + +s32 sub_803DC14(const u8 *dungName, s32 strWidth, s32 a2); +s32 CalcStringWidth(const u8 *dungName); + +void ShowDungeonNameBanner(void) +{ + u8 text[100]; + s32 var; + s32 i, r7; + const u8 *r6; + + gDungeonNameBannerPalette = OpenFileAndGetFileDataPtr(gUnknown_80F60F8, &gDungeonFileArchive); + gDungeonNameBannerFontFile = OpenFileAndGetFileDataPtr(gUnknown_80F6100, &gDungeonFileArchive); + gDungeonNameBannerFont = ((u8**) gDungeonNameBannerFontFile->data)[1]; + for (i = 0; i < 16; i++) { + SetBGPaletteBufferColorArray(i + 224, (void*) &((u8**) gDungeonNameBannerPalette->data)[i]); // Todo: Fix when there is a better idea what to do with structs from opened files + } + CpuClear((void *)(VRAM + 0x140), 0x1C00); + if (sub_80848EC()) { + s32 r8 = gDungeon->dungeonLocation.floor + gDungeon->unk14; + const u8 *dungName = GetDungeonName2(gDungeon->dungeonLocation.id); + s32 r5 = 10; + + for (r7 = 0; r7 < 8; r7++) { + for (i = 0; i < 28; r5++) { + u16 a2; + + i++; + a2 = r5 | 0xE000; + sub_8008DC8(i, r7 + 4, r5 | a2, 0); + } + } + + var = sub_803DC14(dungName, (224 - CalcStringWidth(dungName)) / 2, 0); + if (IsStairDirectionUp(gDungeon->dungeonLocation.id)) + r6 = gUnknown_80F6108; + else + r6 = gUnknown_80F610C; + + if (r8 > 9) { + sprintfStatic(text, gUnknown_80F6110, r6, 48 + (r8 / 10), 48 + (r8 % 10)); + } + else { + sprintfStatic(text, gUnknown_80F6118, r6, 48 + r8); + } + + sub_803DC14(text, (224 - CalcStringWidth(text)) / 2, var + 32); + gUnknown_20274A5 = 1; + } + + CloseFile(gDungeonNameBannerFontFile); + sub_803E46C(2); +} + From c07d06ef3f3a459f70c75d7e924e4cb30aef968e Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sun, 22 Sep 2024 11:34:40 +0200 Subject: [PATCH 3/5] sub_803DD30 --- asm/code_803D110.s | 334 --------------------------------------------- src/code_803D110.c | 143 +++++++++++++++++++ 2 files changed, 143 insertions(+), 334 deletions(-) diff --git a/asm/code_803D110.s b/asm/code_803D110.s index dfd3fca66..aa0b5d122 100644 --- a/asm/code_803D110.s +++ b/asm/code_803D110.s @@ -6,340 +6,6 @@ .text - - thumb_func_start sub_803DC14 -sub_803DC14: - push {r4-r6,lr} - adds r4, r0, 0 - adds r5, r1, 0 - adds r6, r2, 0 - b _0803DC5C -_0803DC1E: - ldrb r1, [r4] - adds r4, 0x1 - cmp r1, 0x2F - bne _0803DC2C - movs r5, 0 - adds r6, 0x18 - b _0803DC5C -_0803DC2C: - cmp r1, 0x23 - bne _0803DC34 - adds r5, 0x8 - b _0803DC5C -_0803DC34: - cmp r1, 0x20 - bne _0803DC3C - adds r5, 0xC - b _0803DC5C -_0803DC3C: - movs r0, 0x80 - ands r0, r1 - cmp r0, 0 - beq _0803DC50 - ldrb r0, [r4] - cmp r0, 0 - beq _0803DC50 - lsls r1, 8 - orrs r1, r0 - adds r4, 0x1 -_0803DC50: - adds r0, r1, 0 - adds r1, r5, 0 - adds r2, r6, 0 - bl sub_803DC6C - adds r5, r0 -_0803DC5C: - ldrb r0, [r4] - cmp r0, 0 - bne _0803DC1E - adds r0, r6, 0 - pop {r4-r6} - pop {r1} - bx r1 - thumb_func_end sub_803DC14 - - thumb_func_start sub_803DC6C -sub_803DC6C: - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - sub sp, 0x120 - adds r7, r1, 0 - adds r5, r2, 0 - bl sub_803DEC8 - adds r4, r0, 0 - ldr r0, [r4] - mov r1, sp - bl sub_803DD30 - ldrb r4, [r4, 0x6] - mov r9, r4 - mov r6, sp - adds r0, r5, 0 - cmp r5, 0 - bge _0803DC96 - adds r0, r5, 0x7 -_0803DC96: - asrs r0, 3 - lsls r3, r0, 3 - subs r0, r3, r0 - lsls r0, 2 - adds r1, r7, 0 - cmp r7, 0 - bge _0803DCA6 - adds r1, r7, 0x7 -_0803DCA6: - asrs r1, 3 - adds r0, r1 - lsls r0, 5 - ldr r4, _0803DD28 - adds r2, r0, r4 - subs r0, r5, r3 - lsls r0, 2 - adds r2, r0 - lsls r1, 3 - subs r1, r7, r1 - lsls r1, 4 - ldr r0, _0803DD2C - adds r4, r1, r0 - movs r0, 0 -_0803DCC2: - adds r3, r2, 0 - adds r7, r3, 0x4 - adds r5, 0x1 - mov r12, r5 - adds r0, 0x1 - mov r8, r0 - movs r5, 0x2 -_0803DCD0: - ldr r2, [r6] - cmp r2, 0 - beq _0803DCF6 - ldr r1, [r4] - ands r1, r2 - ldr r0, [r4, 0x8] - lsls r1, r0 - ldr r0, [r3] - orrs r0, r1 - str r0, [r3] - adds r3, 0x20 - ldr r0, [r4, 0x4] - ands r2, r0 - ldr r0, [r4, 0xC] - lsrs r2, r0 - ldr r0, [r3] - orrs r0, r2 - str r0, [r3] - subs r3, 0x20 -_0803DCF6: - adds r6, 0x4 - adds r3, 0x20 - subs r5, 0x1 - cmp r5, 0 - bge _0803DCD0 - adds r2, r7, 0 - mov r5, r12 - movs r0, 0x7 - ands r0, r5 - cmp r0, 0 - bne _0803DD12 - movs r0, 0xD8 - lsls r0, 2 - adds r2, r7, r0 -_0803DD12: - mov r0, r8 - cmp r0, 0x17 - ble _0803DCC2 - mov r0, r9 - add sp, 0x120 - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r1} - bx r1 - .align 2, 0 -_0803DD28: .4byte 0x06000140 -_0803DD2C: .4byte gUnknown_80F6120 - thumb_func_end sub_803DC6C - - thumb_func_start sub_803DD30 -sub_803DD30: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - ldr r4, _0803DDBC - add sp, r4 - adds r4, r0, 0 - mov r10, r1 - movs r3, 0 - movs r5, 0 - ldr r0, _0803DDC0 - mov r8, r0 - movs r6, 0xF - movs r7, 0xF - mov r2, sp -_0803DD50: - ldrb r0, [r4] - lsrs r1, r0, 4 - ands r1, r6 - strb r1, [r2] - adds r1, r7, 0 - ands r1, r0 - strb r1, [r2, 0x1] - adds r4, 0x1 - adds r2, 0x2 - adds r5, 0x2 - cmp r5, r8 - ble _0803DD50 - ldr r1, _0803DDC0 - cmp r3, r1 - bgt _0803DDF8 - movs r0, 0x90 - lsls r0, 2 - mov r2, sp - adds r2, r0 - mov r12, r2 - mov r8, r1 - mov r2, sp - mov r9, r0 -_0803DD7E: - ldrb r1, [r2] - adds r2, 0x1 - movs r6, 0x7 - ands r6, r1 - movs r0, 0x8 - ands r1, r0 - cmp r1, 0 - beq _0803DDC4 - ldrb r1, [r2] - adds r2, 0x1 - movs r4, 0 - cmp r4, r6 - bge _0803DDF4 - mov r5, r12 - adds r0, r5, r3 - strb r1, [r0] - adds r3, 0x1 - cmp r3, r8 - bgt _0803DDF8 - mov r5, sp - add r5, r9 - ldr r7, _0803DDC0 -_0803DDAA: - adds r4, 0x1 - cmp r4, r6 - bge _0803DDF4 - adds r0, r5, r3 - strb r1, [r0] - adds r3, 0x1 - cmp r3, r7 - ble _0803DDAA - b _0803DDF4 - .align 2, 0 -_0803DDBC: .4byte 0xfffffb80 -_0803DDC0: .4byte 0x0000023f -_0803DDC4: - movs r4, 0 - cmp r4, r6 - bge _0803DDF4 - ldrb r1, [r2] - adds r2, 0x1 - mov r5, r12 - adds r0, r5, r3 - strb r1, [r0] - adds r3, 0x1 - cmp r3, r8 - bgt _0803DDF8 - mov r5, sp - add r5, r9 - ldr r7, _0803DE78 -_0803DDE0: - adds r4, 0x1 - cmp r4, r6 - bge _0803DDF4 - ldrb r1, [r2] - adds r2, 0x1 - adds r0, r5, r3 - strb r1, [r0] - adds r3, 0x1 - cmp r3, r7 - ble _0803DDE0 -_0803DDF4: - cmp r3, r8 - ble _0803DD7E -_0803DDF8: - movs r5, 0 - ldr r4, _0803DE78 - add r3, sp, 0x240 -_0803DDFE: - ldrb r2, [r3, 0x7] - lsls r2, 28 - ldrb r0, [r3, 0x6] - lsls r0, 24 - movs r1, 0xF0 - lsls r1, 20 - ands r0, r1 - orrs r2, r0 - ldrb r0, [r3, 0x5] - lsls r0, 20 - movs r1, 0xF0 - lsls r1, 16 - ands r0, r1 - orrs r2, r0 - ldrb r0, [r3, 0x4] - lsls r0, 16 - movs r1, 0xF0 - lsls r1, 12 - ands r0, r1 - orrs r2, r0 - ldrb r0, [r3, 0x3] - lsls r0, 12 - movs r1, 0xF0 - lsls r1, 8 - ands r0, r1 - orrs r2, r0 - ldrb r0, [r3, 0x2] - lsls r0, 8 - movs r1, 0xF0 - lsls r1, 4 - ands r0, r1 - orrs r2, r0 - ldrb r0, [r3, 0x1] - lsls r0, 4 - movs r1, 0xF0 - ands r0, r1 - orrs r2, r0 - ldrb r1, [r3] - movs r0, 0xF - ands r0, r1 - orrs r2, r0 - mov r0, r10 - adds r0, 0x4 - mov r10, r0 - subs r0, 0x4 - stm r0!, {r2} - adds r3, 0x8 - adds r5, 0x8 - cmp r5, r4 - ble _0803DDFE - movs r3, 0x90 - lsls r3, 3 - add sp, r3 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_0803DE78: .4byte 0x0000023f - thumb_func_end sub_803DD30 - thumb_func_start CalcStringWidth CalcStringWidth: push {r4,r5,lr} diff --git a/src/code_803D110.c b/src/code_803D110.c index 851a9c10a..b0ddbe129 100644 --- a/src/code_803D110.c +++ b/src/code_803D110.c @@ -574,3 +574,146 @@ void ShowDungeonNameBanner(void) sub_803E46C(2); } +s32 sub_803DC6C(u32 chr, s32 strWidth, s32 a2); + +s32 sub_803DC14(const u8 *dungName, s32 strWidth, s32 a2) +{ + while (*dungName != '\0') { + u32 currChar = *(dungName++); + if (currChar == '/') { + strWidth = 0; + a2 += 24; + } + else if (currChar == '#') { + strWidth += 8; + } + else if (currChar == ' ') { + strWidth += 12; + } + else { + if (currChar & 0x80 && *dungName != '\0') { + currChar = (currChar << 8) | *dungName; + dungName++; + } + strWidth += sub_803DC6C(currChar, strWidth, a2); + } + } + return a2; +} + +struct UnkStruct_sub_803DC6C +{ + u8 *unk0; + u8 unk4; + u8 unk5; + u8 unk6; +}; + +struct UnkStruct_sub_803DC6C *sub_803DEC8(u32 chr); +void sub_803DD30(u8 *a0, u32 *a1); + +extern const u32 gUnknown_80F6120[]; + +s32 sub_803DC6C(u32 chr, s32 strWidth, s32 a2) +{ + u32 *spPtr; + s32 i, j, a2DivMul; + u32 *vramPtr; + const u32 *constData; + u32 sp[72]; + s32 r9; + struct UnkStruct_sub_803DC6C *strPtr = sub_803DEC8(chr); + + sub_803DD30(strPtr->unk0, sp); + r9 = strPtr->unk6; + spPtr = sp; + + a2DivMul = ((a2 / 8) * 8); + vramPtr = (void *)(VRAM + 0x140 + (((a2DivMul - a2 / 8) * 4) + (strWidth / 8)) * 32); // Pixels? + vramPtr += a2 - a2DivMul; + constData = &gUnknown_80F6120[(strWidth - ((strWidth / 8) * 8)) * 4]; + for (i = 0; i < 24; i++) { + u32 *vramPtrLoop = vramPtr; + for (j = 0; j < 3; j++) { + // Sadly cannot match it without asm :/ + #ifdef NONMATCHING + u32 spVal = *spPtr; + #else + register u32 spVal asm("r2") = *spPtr; + #endif // NONMATCHING + + if (spVal != 0) { + *vramPtrLoop |= ((constData[0] & spVal) << constData[2]); + + vramPtrLoop += 8; + spVal &= constData[1]; + spVal >>= constData[3]; + *vramPtrLoop |= spVal; + vramPtrLoop -= 8; + } + spPtr++; + vramPtrLoop += 8; + } + + vramPtr++; + a2++; + + if (!(a2 & 7)) { + vramPtr += 216; + } + } + + return r9; +} + +void sub_803DD30(u8 *a0, u32 *a1) +{ + u8 sp[576]; + u8 sp575[576]; + s32 spId = 0; + s32 i, j = 0, k; + u32 currSp; + s32 r6; + + for (i = 0; i < 576; i += 2) { + sp[i] = (*a0 >> 4) & 0xF; + sp[i+1] = *a0 & 0xF; + a0++; + } + + while (j < 576) { + currSp = sp[spId++]; + r6 = currSp & 7; + if (currSp & 8) { + currSp = sp[spId++]; + for (k = 0; k < r6; k++) { + sp575[j] = currSp; + if (++j >= 576) + break; + } + } + else { + for (k = 0; k < r6; k++) { + currSp = sp[spId++]; + sp575[j] = currSp; + if (++j >= 576) + break; + } + } + if (j >= 576) + break; + } + + for (i = 0; i < 576; i += 8) { + u32 val = sp575[i + 7] << 0x1C; + val |= (sp575[i + 6] << 0x18) & 0xF000000; + val |= (sp575[i + 5] << 0x14) & 0xF00000; + val |= (sp575[i + 4] << 0x10) & 0xF0000; + val |= (sp575[i + 3] << 0xC) & 0xF000; + val |= (sp575[i + 2] << 0x8) & 0xF00; + val |= (sp575[i + 1] << 0x4) & 0xF0; + val |= (sp575[i]) & 0xF; + *(a1++) = val; + } +} + From 3c5cc45ed96a3b288a639f3250dc25ab76c34eba Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sun, 22 Sep 2024 21:31:34 +0200 Subject: [PATCH 4/5] sub_803DEC8 --- asm/code_803D110.s | 129 --------------------------------------------- src/code_803D110.c | 80 ++++++++++++++++++++++++++-- 2 files changed, 75 insertions(+), 134 deletions(-) diff --git a/asm/code_803D110.s b/asm/code_803D110.s index aa0b5d122..39feaf615 100644 --- a/asm/code_803D110.s +++ b/asm/code_803D110.s @@ -6,135 +6,6 @@ .text - thumb_func_start CalcStringWidth -CalcStringWidth: - push {r4,r5,lr} - adds r4, r0, 0 - movs r5, 0 - b _0803DEBA -_0803DE84: - ldrb r1, [r4] - adds r4, 0x1 - cmp r1, 0x23 - bne _0803DE90 - adds r5, 0x8 - b _0803DEBA -_0803DE90: - cmp r1, 0x20 - bne _0803DE98 - adds r5, 0xC - b _0803DEBA -_0803DE98: - movs r0, 0x80 - ands r0, r1 - cmp r0, 0 - beq _0803DEAC - ldrb r0, [r4] - cmp r0, 0 - beq _0803DEAC - lsls r1, 8 - orrs r1, r0 - adds r4, 0x1 -_0803DEAC: - adds r0, r1, 0 - bl sub_803DEC8 - cmp r0, 0 - beq _0803DEBA - ldrb r0, [r0, 0x6] - adds r5, r0 -_0803DEBA: - ldrb r0, [r4] - cmp r0, 0 - bne _0803DE84 - adds r0, r5, 0 - pop {r4,r5} - pop {r1} - bx r1 - thumb_func_end CalcStringWidth - - thumb_func_start sub_803DEC8 -sub_803DEC8: - push {r4,r5,lr} - adds r3, r0, 0 - ldr r0, _0803DEFC - ldr r0, [r0] - ldr r0, [r0, 0x4] - ldr r5, [r0] - ldr r0, _0803DF00 - adds r1, r3, r0 - ldr r0, _0803DF04 - cmp r1, r0 - bhi _0803DF08 - movs r2, 0xFF - ands r2, r3 - movs r1, 0xFF - lsls r1, 8 - ands r1, r3 - asrs r1, 8 - subs r2, 0x20 - subs r1, 0xF8 - lsls r0, r1, 3 - subs r0, r1 - lsls r0, 5 - adds r0, r2 - lsls r0, 3 - adds r1, r5, r0 - b _0803DF56 - .align 2, 0 -_0803DEFC: .4byte gDungeonNameBannerFontFile -_0803DF00: .4byte 0xffff0800 -_0803DF04: .4byte 0x000007fe -_0803DF08: - movs r4, 0 - ldr r0, _0803DF1C - ldr r0, [r0] - subs r2, r0, 0x1 - cmp r4, r2 - bge _0803DF48 - lsrs r0, r2, 31 - adds r0, r2, r0 - b _0803DF3A - .align 2, 0 -_0803DF1C: .4byte gDungeonNameBannerFont -_0803DF20: - lsls r0, r1, 3 - adds r0, r5 - ldrh r0, [r0, 0x4] - cmp r0, r3 - bge _0803DF2E - adds r4, r1, 0x1 - b _0803DF30 -_0803DF2E: - adds r2, r1, 0 -_0803DF30: - cmp r4, r2 - bge _0803DF48 - adds r0, r4, r2 - lsrs r1, r0, 31 - adds r0, r1 -_0803DF3A: - asrs r1, r0, 1 - lsls r0, r1, 3 - adds r0, r5 - ldrh r0, [r0, 0x4] - cmp r0, r3 - bne _0803DF20 - adds r4, r1, 0 -_0803DF48: - lsls r0, r4, 3 - adds r1, r5, r0 - ldrh r0, [r1, 0x4] - cmp r0, r3 - beq _0803DF56 - adds r1, r5, 0 - adds r1, 0x8 -_0803DF56: - adds r0, r1, 0 - pop {r4,r5} - pop {r1} - bx r1 - thumb_func_end sub_803DEC8 - thumb_func_start sub_803DF60 sub_803DF60: push {r4-r7,lr} diff --git a/src/code_803D110.c b/src/code_803D110.c index b0ddbe129..eb540c773 100644 --- a/src/code_803D110.c +++ b/src/code_803D110.c @@ -22,7 +22,7 @@ extern const char gUnknown_80F6100[]; // "banfont" extern struct FileArchive gDungeonFileArchive; extern OpenedFile *gDungeonNameBannerPalette; extern OpenedFile *gDungeonNameBannerFontFile; -extern void *gDungeonNameBannerFont; +extern s32 gDungeonNameBannerFont; struct UnkDungeonFileData { @@ -533,7 +533,7 @@ void ShowDungeonNameBanner(void) gDungeonNameBannerPalette = OpenFileAndGetFileDataPtr(gUnknown_80F60F8, &gDungeonFileArchive); gDungeonNameBannerFontFile = OpenFileAndGetFileDataPtr(gUnknown_80F6100, &gDungeonFileArchive); - gDungeonNameBannerFont = ((u8**) gDungeonNameBannerFontFile->data)[1]; + gDungeonNameBannerFont = (s32)(((u8**) gDungeonNameBannerFontFile->data)[1]); for (i = 0; i < 16; i++) { SetBGPaletteBufferColorArray(i + 224, (void*) &((u8**) gDungeonNameBannerPalette->data)[i]); // Todo: Fix when there is a better idea what to do with structs from opened files } @@ -604,12 +604,11 @@ s32 sub_803DC14(const u8 *dungName, s32 strWidth, s32 a2) struct UnkStruct_sub_803DC6C { u8 *unk0; - u8 unk4; - u8 unk5; + u16 unk4; u8 unk6; }; -struct UnkStruct_sub_803DC6C *sub_803DEC8(u32 chr); +struct UnkStruct_sub_803DC6C *sub_803DEC8(s32 chr); void sub_803DD30(u8 *a0, u32 *a1); extern const u32 gUnknown_80F6120[]; @@ -717,3 +716,74 @@ void sub_803DD30(u8 *a0, u32 *a1) } } +// Could be a misnomer? +s32 CalcStringWidth(const u8 *dungName) +{ + s32 w = 0; + + while (*dungName != '\0') { + u32 currChar = *(dungName++); + if (currChar == '#') { + w += 8; + } + else if (currChar == ' ') { + w += 12; + } + else { + struct UnkStruct_sub_803DC6C *strPtr; + + if (currChar & 0x80 && *dungName != '\0') { + currChar = (currChar << 8) | *dungName; + dungName++; + } + strPtr = sub_803DEC8(currChar); + if (strPtr != NULL) { + w += strPtr->unk6; + } + } + } + + return w; +} + +struct UnkStruct_sub_803DC6C *sub_803DEC8(s32 chr) +{ + s32 r2, r4; + struct UnkStruct_sub_803DC6C *ret; + struct UnkStruct_sub_803DC6C *strPtr = *((struct UnkStruct_sub_803DC6C **) gDungeonNameBannerFontFile->data); + // Fakematch? Or just magic numbers which will make more sense once this file is documented? + if (chr > 63487 && chr < 65535) + { + s32 r2 = chr & 0xFF; + s32 r1 = (chr & 0xFF00) / 256; + r2 -= 32; + r1 -= 248; + ret = &strPtr[r1 * 224 + r2]; + } + else + { + r4 = 0; + r2 = gDungeonNameBannerFont - 1; + while (r4 < r2) { + s32 r1 = (r4 + r2) / 2; + if (strPtr[r1].unk4 == chr) { + r4 = r1; + break; + } + else if (strPtr[r1].unk4 < chr) { + r4 = r1 + 1; + } + else { + r2 = r1; + } + } + + ret = &strPtr[r4]; + if (ret->unk4 != chr) + ret = &strPtr[1]; + + + } + return ret; +}; + From af3cacd131723d32e67d31a608457ad83ac89a25 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Mon, 23 Sep 2024 13:08:42 +0200 Subject: [PATCH 5/5] sub_803E214 --- asm/code_803D110.s | 359 --------------------------------------------- src/code_803D110.c | 356 ++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 329 insertions(+), 386 deletions(-) diff --git a/asm/code_803D110.s b/asm/code_803D110.s index 39feaf615..e7f0bdf5d 100644 --- a/asm/code_803D110.s +++ b/asm/code_803D110.s @@ -6,365 +6,6 @@ .text - thumb_func_start sub_803DF60 -sub_803DF60: - push {r4-r7,lr} - ldr r0, _0803DFF8 - ldr r1, _0803DFFC - bl OpenFileAndGetFileDataPtr - adds r7, r0, 0 - ldr r0, [r7, 0x4] - ldr r5, [r0] - ldm r5!, {r4} - ldr r6, _0803E000 - cmp r4, 0 - beq _0803DF8C -_0803DF78: - adds r0, r6, 0 - adds r1, r5, 0 - movs r2, 0x20 - bl CpuCopy - adds r6, 0x20 - adds r5, 0x20 - subs r4, 0x1 - cmp r4, 0 - bne _0803DF78 -_0803DF8C: - adds r0, r7, 0 - bl CloseFile - ldr r0, _0803E004 - ldr r1, _0803DFFC - bl OpenFileAndGetFileDataPtr - adds r7, r0, 0 - ldr r5, [r7, 0x4] - ldm r5!, {r4} - ldr r6, _0803E008 - cmp r4, 0 - beq _0803DFBA -_0803DFA6: - adds r0, r6, 0 - adds r1, r5, 0 - movs r2, 0x20 - bl CpuCopy - adds r6, 0x20 - adds r5, 0x20 - subs r4, 0x1 - cmp r4, 0 - bne _0803DFA6 -_0803DFBA: - adds r0, r7, 0 - bl CloseFile - ldr r0, _0803E00C - ldr r4, _0803DFFC - adds r1, r4, 0 - bl OpenFileAndGetFileDataPtr - ldr r1, _0803E010 - str r0, [r1] - ldr r0, _0803E014 - adds r1, r4, 0 - bl OpenFileAndGetFileDataPtr - ldr r1, _0803E018 - str r0, [r1] - ldr r0, _0803E01C - adds r1, r4, 0 - bl OpenFileAndGetFileDataPtr - ldr r1, _0803E020 - str r0, [r1] - ldr r0, _0803E024 - adds r1, r4, 0 - bl OpenFileAndGetFileDataPtr - ldr r1, _0803E028 - str r0, [r1] - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_0803DFF8: .4byte gUnknown_80F61A8 -_0803DFFC: .4byte gDungeonFileArchive -_0803E000: .4byte 0x06013400 -_0803E004: .4byte gUnknown_80F61B0 -_0803E008: .4byte 0x06014000 -_0803E00C: .4byte gUnknown_80F61B8 -_0803E010: .4byte gUnknown_202EC94 -_0803E014: .4byte gUnknown_80F61C4 -_0803E018: .4byte gUnknown_202EC98 -_0803E01C: .4byte gUnknown_80F61CC -_0803E020: .4byte gUnknown_202EC9C -_0803E024: .4byte gUnknown_80F61D4 -_0803E028: .4byte gUnknown_202ECA0 - thumb_func_end sub_803DF60 - - thumb_func_start sub_803E02C -sub_803E02C: - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - sub sp, 0xC - bl sub_803E13C - mov r1, sp - ldr r0, _0803E118 - ldm r0!, {r2,r3} - stm r1!, {r2,r3} - ldr r1, _0803E11C - mov r0, sp - bl OpenFileAndGetFileDataPtr - adds r7, r0, 0 - ldr r0, [r7, 0x4] - ldr r5, [r0] - ldm r5!, {r4} - ldr r6, _0803E120 - cmp r4, 0 - beq _0803E06C -_0803E058: - adds r0, r6, 0 - adds r1, r5, 0 - movs r2, 0x20 - bl CpuCopy - adds r6, 0x20 - adds r5, 0x20 - subs r4, 0x1 - cmp r4, 0 - bne _0803E058 -_0803E06C: - ldr r0, _0803E124 - ldr r1, [r7, 0x4] - ldr r1, [r1, 0x4] - movs r2, 0x80 - bl CpuCopy - adds r0, r7, 0 - bl CloseFile - movs r6, 0x80 - lsls r6, 2 - movs r4, 0 - ldr r0, _0803E128 - mov r9, r0 - ldr r1, _0803E12C - mov r12, r1 - movs r7, 0 - ldr r2, _0803E130 - mov r8, r2 -_0803E092: - mov r3, r12 - ldrh r0, [r3] - lsls r5, r0, 12 - adds r2, r7, 0 - movs r3, 0x8 -_0803E09C: - mov r0, r9 - ldr r1, [r0] - add r1, r8 - adds r1, r2 - adds r0, r5, 0 - orrs r0, r6 - strh r0, [r1] - adds r6, 0x1 - adds r2, 0x2 - subs r3, 0x1 - cmp r3, 0 - bge _0803E09C - movs r1, 0x2 - add r12, r1 - adds r7, 0x12 - adds r4, 0x1 - cmp r4, 0x1C - ble _0803E092 - movs r4, 0 - ldr r5, _0803E128 - ldr r3, _0803E134 - movs r2, 0xC0 - lsls r2, 8 -_0803E0CA: - ldr r0, [r5] - lsls r1, r4, 1 - adds r0, r3 - adds r0, r1 - strh r2, [r0] - adds r4, 0x1 - cmp r4, 0x8 - ble _0803E0CA - movs r4, 0 - ldr r2, _0803E128 - movs r6, 0xBE - lsls r6, 1 - ldr r5, _0803E138 - movs r3, 0xBF - lsls r3, 1 -_0803E0E8: - ldr r0, [r2] - lsls r1, r4, 2 - adds r0, r1 - adds r0, r6 - strb r4, [r0] - ldr r0, [r2] - adds r0, r1 - adds r0, r5 - strb r4, [r0] - ldr r0, [r2] - adds r0, r1 - adds r0, r3 - strb r4, [r0] - adds r4, 0x1 - cmp r4, 0xFF - ble _0803E0E8 - add sp, 0xC - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_0803E118: .4byte gUnknown_80F61DC -_0803E11C: .4byte gDungeonFileArchive -_0803E120: .4byte 0x0600c000 -_0803E124: .4byte gUnknown_202ECA4 -_0803E128: .4byte gDungeon -_0803E12C: .4byte gUnknown_80F5F70 -_0803E130: .4byte 0x00012a18 -_0803E134: .4byte 0x00013554 -_0803E138: .4byte 0x0000017d - thumb_func_end sub_803E02C - - thumb_func_start sub_803E13C -sub_803E13C: - push {r4,r5,lr} - bl SetWindowBGColor - ldr r0, _0803E170 - ldr r0, [r0] - ldrb r0, [r0, 0xB] - ldr r5, _0803E174 - cmp r0, 0 - beq _0803E154 - movs r0, 0x80 - lsls r0, 1 - adds r5, r0 -_0803E154: - movs r4, 0 -_0803E156: - adds r0, r4, 0 - adds r0, 0xF0 - adds r1, r5, 0 - bl SetBGPaletteBufferColorArray - adds r5, 0x4 - adds r4, 0x1 - cmp r4, 0xF - ble _0803E156 - pop {r4,r5} - pop {r0} - bx r0 - .align 2, 0 -_0803E170: .4byte gGameOptionsRef -_0803E174: .4byte gFontPalette - thumb_func_end sub_803E13C - - thumb_func_start sub_803E178 -sub_803E178: - push {r4,lr} - bl sub_8043D10 - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0 - bne _0803E1E0 - ldr r0, _0803E1AC - ldr r2, [r0] - ldr r3, _0803E1B0 - adds r1, r2, r3 - ldrb r1, [r1] - adds r3, r0, 0 - cmp r1, 0x15 - bne _0803E1BC - ldr r1, _0803E1B4 - adds r0, r2, r1 - ldrb r0, [r0] - cmp r0, 0 - bne _0803E1BC - ldr r3, _0803E1B8 - adds r1, r2, r3 - movs r0, 0x1C - strh r0, [r1] - b _0803E204 - .align 2, 0 -_0803E1AC: .4byte gDungeon -_0803E1B0: .4byte 0x00000644 -_0803E1B4: .4byte 0x000037fe -_0803E1B8: .4byte 0x00003a12 -_0803E1BC: - ldr r4, [r3] - ldr r1, _0803E1D8 - adds r0, r4, r1 - ldrb r0, [r0] - bl IsStairDirectionUp - lsls r0, 24 - movs r1, 0x16 - cmp r0, 0 - beq _0803E1D2 - movs r1, 0x17 -_0803E1D2: - ldr r2, _0803E1DC - adds r0, r4, r2 - b _0803E202 - .align 2, 0 -_0803E1D8: .4byte 0x00000644 -_0803E1DC: .4byte 0x00003a12 -_0803E1E0: - cmp r0, 0x1 - bne _0803E1F8 - ldr r0, _0803E1F0 - ldr r0, [r0] - ldr r3, _0803E1F4 - adds r0, r3 - movs r1, 0x6 - b _0803E202 - .align 2, 0 -_0803E1F0: .4byte gDungeon -_0803E1F4: .4byte 0x00003a12 -_0803E1F8: - ldr r0, _0803E20C - ldr r0, [r0] - ldr r1, _0803E210 - adds r0, r1 - movs r1, 0x18 -_0803E202: - strh r1, [r0] -_0803E204: - pop {r4} - pop {r0} - bx r0 - .align 2, 0 -_0803E20C: .4byte gDungeon -_0803E210: .4byte 0x00003a12 - thumb_func_end sub_803E178 - - thumb_func_start sub_803E214 -sub_803E214: - push {lr} - ldr r0, _0803E23C - ldr r0, [r0] - bl CloseFile - ldr r0, _0803E240 - ldr r0, [r0] - bl CloseFile - ldr r0, _0803E244 - ldr r0, [r0] - bl CloseFile - ldr r0, _0803E248 - ldr r0, [r0] - bl CloseFile - pop {r0} - bx r0 - .align 2, 0 -_0803E23C: .4byte gUnknown_202EC94 -_0803E240: .4byte gUnknown_202EC98 -_0803E244: .4byte gUnknown_202EC9C -_0803E248: .4byte gUnknown_202ECA0 - thumb_func_end sub_803E214 - - thumb_func_start nullsub_56 -nullsub_56: - bx lr - thumb_func_end nullsub_56 - thumb_func_start sub_803E250 sub_803E250: push {r4-r7,lr} diff --git a/src/code_803D110.c b/src/code_803D110.c index eb540c773..6f815efd9 100644 --- a/src/code_803D110.c +++ b/src/code_803D110.c @@ -7,6 +7,8 @@ #include "dungeon_random.h" #include "bg_palette_buffer.h" #include "code_800D090.h" +#include "game_options.h" +#include "constants/dungeon.h" extern void sub_80901D8(DungeonLocation *param_1,DungeonLocation *param_2); extern s32 sub_80902C8(u8 dungeon); @@ -15,14 +17,30 @@ extern u32 ExtractLevel(UnkDungeonGlobal_unk1CD98 *r0); extern void sub_808E9C4(UnkDungeonGlobal_unk1CD98 *r0, s16 r1); extern u8 GetBodySize(s16 index); extern bool8 sub_80848EC(void); +extern u8 sub_8043D10(void); +extern const u8 *GetDungeonName2(u8 dungeon); +extern void sub_8008DC8(s32 r0, s32 r1, u16 r2, u16 r3); extern const char gUnknown_80F4D8C[]; // "mapparam" extern const char gUnknown_80F60F8[]; // "banrpal" extern const char gUnknown_80F6100[]; // "banfont" +extern const char gUnknown_80F6108[]; +extern const char gUnknown_80F610C[]; +extern const char gUnknown_80F6110[]; +extern const char gUnknown_80F6118[]; +extern const char gUnknown_80F61A8[]; +extern const u32 gUnknown_80F6120[]; + extern struct FileArchive gDungeonFileArchive; extern OpenedFile *gDungeonNameBannerPalette; extern OpenedFile *gDungeonNameBannerFontFile; +extern OpenedFile *gUnknown_202ECA0; +extern OpenedFile *gUnknown_202EC9C; +extern OpenedFile *gUnknown_202EC98; +extern OpenedFile *gUnknown_202EC94; extern s32 gDungeonNameBannerFont; +extern u8 gUnknown_20274A5; +extern u8 gFontPalette[]; struct UnkDungeonFileData { @@ -41,6 +59,19 @@ struct UnkDataFileStruct u16 **unk10; }; +struct UnkStruct_sub_803DC6C +{ + u8 *unk0; + u16 unk4; + u8 unk6; +}; + +s32 sub_803DC14(const u8 *dungName, s32 strWidth, s32 a2); +s32 CalcStringWidth(const u8 *dungName); +s32 sub_803DC6C(u32 chr, s32 strWidth, s32 a2); +struct UnkStruct_sub_803DC6C *sub_803DEC8(s32 chr); +void sub_803DD30(u8 *a0, u32 *a1); + // TODO https://decomp.me/scratch/nXUH3 /* void sub_803D4D0(void) @@ -511,19 +542,6 @@ s32 sub_803DA20(s32 species) return 1; } -extern const u8 *GetDungeonName2(u8 dungeon); -extern void sub_8008DC8(s32 r0, s32 r1, u16 r2, u16 r3); - -extern const char gUnknown_80F6108[]; -extern const char gUnknown_80F610C[]; -extern const char gUnknown_80F6110[]; -extern const char gUnknown_80F6118[]; - -extern u8 gUnknown_20274A5; - -s32 sub_803DC14(const u8 *dungName, s32 strWidth, s32 a2); -s32 CalcStringWidth(const u8 *dungName); - void ShowDungeonNameBanner(void) { u8 text[100]; @@ -574,8 +592,6 @@ void ShowDungeonNameBanner(void) sub_803E46C(2); } -s32 sub_803DC6C(u32 chr, s32 strWidth, s32 a2); - s32 sub_803DC14(const u8 *dungName, s32 strWidth, s32 a2) { while (*dungName != '\0') { @@ -601,18 +617,6 @@ s32 sub_803DC14(const u8 *dungName, s32 strWidth, s32 a2) return a2; } -struct UnkStruct_sub_803DC6C -{ - u8 *unk0; - u16 unk4; - u8 unk6; -}; - -struct UnkStruct_sub_803DC6C *sub_803DEC8(s32 chr); -void sub_803DD30(u8 *a0, u32 *a1); - -extern const u32 gUnknown_80F6120[]; - s32 sub_803DC6C(u32 chr, s32 strWidth, s32 a2) { u32 *spPtr; @@ -787,3 +791,301 @@ struct UnkStruct_sub_803DC6C *sub_803DEC8(s32 chr) return ret; }; +/* +I'm leaving this as it is, because I'm not sure how to generate the ldmia asm instruction. Maybe once the file's data format is better understood. +struct FileSub_803DF60Struct +{ + s32 count; + void *unkPtr; +}; + +struct OpenedFile_sub_803DF60 +{ + File *file; + struct FileSub_803DF60Struct **strPtr; +}; + +void sub_803DF60(void) +{ + s32 i; + struct OpenedFile_sub_803DF60 *file = (void*) OpenFileAndGetFileDataPtr(gUnknown_80F61A8, &gDungeonFileArchive); + struct FileSub_803DF60Struct r5 = **file->strPtr; + + for (i = 0; i < r5.count; i++) { + CpuCopy((void *)VRAM + 0x13400 + i * 0x20, r5.unkPtr + i * 0x20, 0x20); + } + + CloseFile(file); +} + +*/ + +NAKED void sub_803DF60(void) +{ + asm_unified(" push {r4-r7,lr}\n" +" ldr r0, _0803DFF8\n" +" ldr r1, _0803DFFC\n" +" bl OpenFileAndGetFileDataPtr\n" +" adds r7, r0, 0\n" +" ldr r0, [r7, 0x4]\n" +" ldr r5, [r0]\n" +" ldm r5!, {r4}\n" +" ldr r6, _0803E000\n" +" cmp r4, 0\n" +" beq _0803DF8C\n" +"_0803DF78:\n" +" adds r0, r6, 0\n" +" adds r1, r5, 0\n" +" movs r2, 0x20\n" +" bl CpuCopy\n" +" adds r6, 0x20\n" +" adds r5, 0x20\n" +" subs r4, 0x1\n" +" cmp r4, 0\n" +" bne _0803DF78\n" +"_0803DF8C:\n" +" adds r0, r7, 0\n" +" bl CloseFile\n" +" ldr r0, _0803E004\n" +" ldr r1, _0803DFFC\n" +" bl OpenFileAndGetFileDataPtr\n" +" adds r7, r0, 0\n" +" ldr r5, [r7, 0x4]\n" +" ldm r5!, {r4}\n" +" ldr r6, _0803E008\n" +" cmp r4, 0\n" +" beq _0803DFBA\n" +"_0803DFA6:\n" +" adds r0, r6, 0\n" +" adds r1, r5, 0\n" +" movs r2, 0x20\n" +" bl CpuCopy\n" +" adds r6, 0x20\n" +" adds r5, 0x20\n" +" subs r4, 0x1\n" +" cmp r4, 0\n" +" bne _0803DFA6\n" +"_0803DFBA:\n" +" adds r0, r7, 0\n" +" bl CloseFile\n" +" ldr r0, _0803E00C\n" +" ldr r4, _0803DFFC\n" +" adds r1, r4, 0\n" +" bl OpenFileAndGetFileDataPtr\n" +" ldr r1, _0803E010\n" +" str r0, [r1]\n" +" ldr r0, _0803E014\n" +" adds r1, r4, 0\n" +" bl OpenFileAndGetFileDataPtr\n" +" ldr r1, _0803E018\n" +" str r0, [r1]\n" +" ldr r0, _0803E01C\n" +" adds r1, r4, 0\n" +" bl OpenFileAndGetFileDataPtr\n" +" ldr r1, _0803E020\n" +" str r0, [r1]\n" +" ldr r0, _0803E024\n" +" adds r1, r4, 0\n" +" bl OpenFileAndGetFileDataPtr\n" +" ldr r1, _0803E028\n" +" str r0, [r1]\n" +" pop {r4-r7}\n" +" pop {r0}\n" +" bx r0\n" +" .align 2, 0\n" +"_0803DFF8: .4byte gUnknown_80F61A8\n" +"_0803DFFC: .4byte gDungeonFileArchive\n" +"_0803E000: .4byte 0x06013400\n" +"_0803E004: .4byte gUnknown_80F61B0\n" +"_0803E008: .4byte 0x06014000\n" +"_0803E00C: .4byte gUnknown_80F61B8\n" +"_0803E010: .4byte gUnknown_202EC94\n" +"_0803E014: .4byte gUnknown_80F61C4\n" +"_0803E018: .4byte gUnknown_202EC98\n" +"_0803E01C: .4byte gUnknown_80F61CC\n" +"_0803E020: .4byte gUnknown_202EC9C\n" +"_0803E024: .4byte gUnknown_80F61D4\n" +"_0803E028: .4byte gUnknown_202ECA0\n"); +} + +NAKED void sub_803E02C(void) +{ + asm_unified( "push {r4-r7,lr}\n" +" mov r7, r9\n" +" mov r6, r8\n" +" push {r6,r7}\n" +" sub sp, 0xC\n" +" bl sub_803E13C\n" +" mov r1, sp\n" +" ldr r0, _0803E118\n" +" ldm r0!, {r2,r3}\n" +" stm r1!, {r2,r3}\n" +" ldr r1, _0803E11C\n" +" mov r0, sp\n" +" bl OpenFileAndGetFileDataPtr\n" +" adds r7, r0, 0\n" +" ldr r0, [r7, 0x4]\n" +" ldr r5, [r0]\n" +" ldm r5!, {r4}\n" +" ldr r6, _0803E120\n" +" cmp r4, 0\n" +" beq _0803E06C\n" +"_0803E058:\n" +" adds r0, r6, 0\n" +" adds r1, r5, 0\n" +" movs r2, 0x20\n" +" bl CpuCopy\n" +" adds r6, 0x20\n" +" adds r5, 0x20\n" +" subs r4, 0x1\n" +" cmp r4, 0\n" +" bne _0803E058\n" +"_0803E06C:\n" +" ldr r0, _0803E124\n" +" ldr r1, [r7, 0x4]\n" +" ldr r1, [r1, 0x4]\n" +" movs r2, 0x80\n" +" bl CpuCopy\n" +" adds r0, r7, 0\n" +" bl CloseFile\n" +" movs r6, 0x80\n" +" lsls r6, 2\n" +" movs r4, 0\n" +" ldr r0, _0803E128\n" +" mov r9, r0\n" +" ldr r1, _0803E12C\n" +" mov r12, r1\n" +" movs r7, 0\n" +" ldr r2, _0803E130\n" +" mov r8, r2\n" +"_0803E092:\n" +" mov r3, r12\n" +" ldrh r0, [r3]\n" +" lsls r5, r0, 12\n" +" adds r2, r7, 0\n" +" movs r3, 0x8\n" +"_0803E09C:\n" +" mov r0, r9\n" +" ldr r1, [r0]\n" +" add r1, r8\n" +" adds r1, r2\n" +" adds r0, r5, 0\n" +" orrs r0, r6\n" +" strh r0, [r1]\n" +" adds r6, 0x1\n" +" adds r2, 0x2\n" +" subs r3, 0x1\n" +" cmp r3, 0\n" +" bge _0803E09C\n" +" movs r1, 0x2\n" +" add r12, r1\n" +" adds r7, 0x12\n" +" adds r4, 0x1\n" +" cmp r4, 0x1C\n" +" ble _0803E092\n" +" movs r4, 0\n" +" ldr r5, _0803E128\n" +" ldr r3, _0803E134\n" +" movs r2, 0xC0\n" +" lsls r2, 8\n" +"_0803E0CA:\n" +" ldr r0, [r5]\n" +" lsls r1, r4, 1\n" +" adds r0, r3\n" +" adds r0, r1\n" +" strh r2, [r0]\n" +" adds r4, 0x1\n" +" cmp r4, 0x8\n" +" ble _0803E0CA\n" +" movs r4, 0\n" +" ldr r2, _0803E128\n" +" movs r6, 0xBE\n" +" lsls r6, 1\n" +" ldr r5, _0803E138\n" +" movs r3, 0xBF\n" +" lsls r3, 1\n" +"_0803E0E8:\n" +" ldr r0, [r2]\n" +" lsls r1, r4, 2\n" +" adds r0, r1\n" +" adds r0, r6\n" +" strb r4, [r0]\n" +" ldr r0, [r2]\n" +" adds r0, r1\n" +" adds r0, r5\n" +" strb r4, [r0]\n" +" ldr r0, [r2]\n" +" adds r0, r1\n" +" adds r0, r3\n" +" strb r4, [r0]\n" +" adds r4, 0x1\n" +" cmp r4, 0xFF\n" +" ble _0803E0E8\n" +" add sp, 0xC\n" +" pop {r3,r4}\n" +" mov r8, r3\n" +" mov r9, r4\n" +" pop {r4-r7}\n" +" pop {r0}\n" +" bx r0\n" +" .align 2, 0\n" +"_0803E118: .4byte gUnknown_80F61DC\n" +"_0803E11C: .4byte gDungeonFileArchive\n" +"_0803E120: .4byte 0x0600c000\n" +"_0803E124: .4byte gUnknown_202ECA4\n" +"_0803E128: .4byte gDungeon\n" +"_0803E12C: .4byte gUnknown_80F5F70\n" +"_0803E130: .4byte 0x00012a18\n" +"_0803E134: .4byte 0x00013554\n" +"_0803E138: .4byte 0x0000017d\n"); +} + +void sub_803E13C(void) +{ + s32 i; + u8 *pal; + + SetWindowBGColor(); + if (gGameOptionsRef->playerGender != 0) + pal = gFontPalette + 256; + else + pal = gFontPalette; + + for (i = 0; i < 16; i++) { + SetBGPaletteBufferColorArray(240 + i, pal); + pal += 4; + } +} + +void sub_803E178(void) +{ + s32 val = sub_8043D10(); + + if (val == 0) { + if (gDungeon->dungeonLocation.id == DUNGEON_METEOR_CAVE && !gDungeon->deoxysDefeat) { + gDungeon->unk3A12 = 28; + } + else { + gDungeon->unk3A12 = (IsStairDirectionUp(gDungeon->dungeonLocation.id) != FALSE) ? 23 : 22; + } + } + else if (val == 1) { + gDungeon->unk3A12 = 6; + } + else { + gDungeon->unk3A12 = 24; + } +} + +void sub_803E214(void) +{ + CloseFile(gUnknown_202EC94); + CloseFile(gUnknown_202EC98); + CloseFile(gUnknown_202EC9C); + CloseFile(gUnknown_202ECA0); +} + +void nullsub_56(void) {} + +// sub_803E250 left, but it seems to be sprite related, and I'd rather not deal with it now lol +