From 6317c203801bc332af7777cfb80346d46356e209 Mon Sep 17 00:00:00 2001 From: Seth Barberee Date: Tue, 21 May 2024 15:39:42 -0700 Subject: [PATCH] more decomp --- asm/code_803D110.s | 134 ----------------------------------------- include/code_803D0D8.h | 4 +- ld_script.txt | 1 - src/code_803D0D8.c | 71 +++++++++++++++++++++- src/code_807E5AC.c | 11 ---- src/trap.c | 9 +++ 6 files changed, 82 insertions(+), 148 deletions(-) delete mode 100644 src/code_807E5AC.c diff --git a/asm/code_803D110.s b/asm/code_803D110.s index ef2f1ca63..8b8ee7069 100644 --- a/asm/code_803D110.s +++ b/asm/code_803D110.s @@ -5,140 +5,6 @@ .text - thumb_func_start sub_803D110 -sub_803D110: - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - sub sp, 0x6C - adds r6, r0, 0 - mov r9, r1 - adds r5, r2, 0 - add r7, sp, 0x48 - adds r2, r7, 0 - movs r1, 0 - mov r0, sp - adds r0, 0x69 -_0803D12A: - strb r1, [r0] - subs r0, 0x1 - cmp r0, r2 - bge _0803D12A - movs r4, 0 - cmp r4, r5 - bge _0803D158 -_0803D138: - ldrb r0, [r6] - bl sub_803D0F0 - add r1, sp, 0x10 - adds r1, r4 - strb r0, [r1] - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0xFF - bne _0803D150 - movs r0, 0 - b _0803D19A -_0803D150: - adds r6, 0x1 - adds r4, 0x1 - cmp r4, r5 - blt _0803D138 -_0803D158: - lsls r0, r5, 2 - adds r0, r5 - adds r2, r0, 0x5 - cmp r2, 0 - bge _0803D164 - adds r2, 0x7 -_0803D164: - asrs r2, 3 - mov r8, r2 - mov r0, sp - adds r1, r7, 0 - bl xxx_init_struct_8094924_save_809486C - movs r4, 0 - cmp r4, r5 - bge _0803D188 - add r6, sp, 0x10 -_0803D178: - adds r1, r6, r4 - mov r0, sp - movs r2, 0x5 - bl SaveIntegerBits - adds r4, 0x1 - cmp r4, r5 - blt _0803D178 -_0803D188: - mov r0, sp - bl nullsub_102 - mov r0, r9 - adds r1, r7, 0 - mov r2, r8 - bl MemoryCopy8 - movs r0, 0x1 -_0803D19A: - add sp, 0x6C - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_803D110 - - thumb_func_start sub_803D1A8 -sub_803D1A8: - push {r4-r7,lr} - sub sp, 0x48 - adds r7, r0, 0 - adds r5, r2, 0 - lsls r0, r5, 2 - adds r0, r5 - adds r2, r0, 0x5 - cmp r2, 0 - bge _0803D1BC - adds r2, 0x7 -_0803D1BC: - asrs r2, 3 - mov r0, sp - bl xxx_init_struct_8094924_restore_809485C - movs r4, 0 - cmp r4, r5 - bge _0803D1DC - add r6, sp, 0x10 -_0803D1CC: - adds r1, r6, r4 - mov r0, sp - movs r2, 0x5 - bl RestoreIntegerBits - adds r4, 0x1 - cmp r4, r5 - blt _0803D1CC -_0803D1DC: - mov r0, sp - bl nullsub_102 - movs r4, 0 - cmp r4, r5 - bge _0803D1FC - add r6, sp, 0x10 -_0803D1EA: - adds r0, r6, r4 - ldrb r0, [r0] - bl sub_803D100 - strb r0, [r7] - adds r7, 0x1 - adds r4, 0x1 - cmp r4, r5 - blt _0803D1EA -_0803D1FC: - add sp, 0x48 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_803D1A8 - thumb_func_start sub_803D204 sub_803D204: push {r4-r7,lr} diff --git a/include/code_803D0D8.h b/include/code_803D0D8.h index ae279de62..69de868c6 100644 --- a/include/code_803D0D8.h +++ b/include/code_803D0D8.h @@ -4,5 +4,7 @@ u8 sub_803D0D8(void); u8 sub_803D0F0(u8); u8 sub_803D100(u8); +u8 sub_803D110(u8 *param_1, u8 *param_2, s32 size); +void sub_803D1A8(u8 *param_1, u8 *param_2, s32 size); -#endif // GUARD_CODE_803D0D8_H \ No newline at end of file +#endif // GUARD_CODE_803D0D8_H diff --git a/ld_script.txt b/ld_script.txt index 37d2f531b..0a33b03e9 100755 --- a/ld_script.txt +++ b/ld_script.txt @@ -275,7 +275,6 @@ SECTIONS { src/code_807CD9C.o(.text); src/weather.o(.text); asm/code_807E5AC.o(.text); - src/code_807E5AC.o(.text); src/trap.o(.text); asm/code_807FCD4.o(.text); src/trap_1.o(.text); diff --git a/src/code_803D0D8.c b/src/code_803D0D8.c index f699ae50c..9a1377e5b 100644 --- a/src/code_803D0D8.c +++ b/src/code_803D0D8.c @@ -1,6 +1,8 @@ #include "global.h" #include "globaldata.h" #include "code_803D0D8.h" +#include "code_8092334.h" +#include "memory.h" static EWRAM_DATA_2 u8 sUnknown_203B408 = {0}; @@ -26,4 +28,71 @@ u8 sub_803D100(u8 r0) return sUnknown_80F42D0[r0]; } -// Probably continues in code_803D110.s \ No newline at end of file +u8 sub_803D110(u8 *param_1, u8 *param_2, s32 size) +{ + s32 index1; + s32 newSize; + s32 save; + unkStruct_8094924 auStack_88; + u8 local_78 [56]; + u8 auStack_40 [36]; + + + for(index1 = 0; index1 < 34; index1++) + { + auStack_40[index1] = 0; + } + + for (index1 = 0; index1 < size; index1++) + { + local_78[index1] = sub_803D0F0(*param_1); + if (local_78[index1] == 0xff) { + return 0; + } + param_1++; + } + + newSize = size * 5 + 5; + if (newSize < 0) { + newSize = size * 5 + 0xc; + } + + newSize >>= 3; + save = newSize; + xxx_init_struct_8094924_save_809486C(&auStack_88,auStack_40, save); + + for(index1 = 0; index1 < size; index1++) + { + SaveIntegerBits(&auStack_88, &local_78[index1], 5); + } + nullsub_102(&auStack_88); + MemoryCopy8(param_2, auStack_40, save); + return 1; +} + +void sub_803D1A8(u8 *param_1, u8 *param_2, s32 size) +{ + s32 index; + s32 newSize; + unkStruct_8094924 auStack_5c; + u8 local_4c [56]; + + newSize = size * 5 + 5; + if (newSize < 0) { + newSize = size * 5 + 0xc; + } + newSize >>= 3; + xxx_init_struct_8094924_restore_809485C(&auStack_5c, param_2, newSize); + for(index = 0; index < size; index++) + { + RestoreIntegerBits(&auStack_5c, &local_4c[index], 5); + } + + nullsub_102(&auStack_5c); + for(index = 0; index < size; index++) + { + *param_1++ = sub_803D100(local_4c[index]); + } +} + +// Probably continues in code_803D110.s diff --git a/src/code_807E5AC.c b/src/code_807E5AC.c deleted file mode 100644 index 2ad284f90..000000000 --- a/src/code_807E5AC.c +++ /dev/null @@ -1,11 +0,0 @@ -#include "global.h" -#include "structs/str_dungeon.h" - -void sub_807FC3C(Position *pos, u32 trapID, u32 param_3) -{ - gDungeon->trapPos.x = pos->x; - gDungeon->trapPos.y = pos->y; - gDungeon->trapID = trapID; - gDungeon->unk13579 = param_3; - gDungeon->unk13570 = 1; -} diff --git a/src/trap.c b/src/trap.c index 6d271f7c9..075c8a17b 100644 --- a/src/trap.c +++ b/src/trap.c @@ -110,6 +110,15 @@ Entity *sub_8045684(u8, Position *, u8); extern void sub_807D148(Entity *pokemon, Entity *target, u32 r2, Position *r3); extern void sub_807DF38(Entity *pokemon, Entity *target, Position *pos, u32, u8 moveType, s16); +void sub_807FC3C(Position *pos, u32 trapID, u32 param_3) +{ + gDungeon->trapPos.x = pos->x; + gDungeon->trapPos.y = pos->y; + gDungeon->trapID = trapID; + gDungeon->unk13579 = param_3; + gDungeon->unk13570 = 1; +} + bool8 CanLayTrap(Position *pos) { struct Tile *tile = GetTileSafe(pos->x, pos->y);