diff --git a/asm/include/overlay_11_022EBEAC.inc b/asm/include/overlay_11_022EBFC8.inc similarity index 99% rename from asm/include/overlay_11_022EBEAC.inc rename to asm/include/overlay_11_022EBFC8.inc index c82bdca7..2bde1c10 100644 --- a/asm/include/overlay_11_022EBEAC.inc +++ b/asm/include/overlay_11_022EBFC8.inc @@ -324,6 +324,8 @@ .public ov11_022EB3C8 .public ov11_022EBAA0 .public ov11_022EBC18 +.public ov11_022EBEAC +.public ov11_022EBF60 .public ov11_02316AFC .public ov11_02316B04 .public ov11_02316B14 @@ -2494,9 +2496,7 @@ .public sub_02062D9C .public sub_02062DB4 .public sub_0206351C -.public sub_020635C8 .public sub_020635D8 -.public sub_02063600 .public sub_02063628 .public sub_0206367C .public sub_02063734 diff --git a/asm/overlay_11_022EBEAC.s b/asm/overlay_11_022EBFC8.s similarity index 99% rename from asm/overlay_11_022EBEAC.s rename to asm/overlay_11_022EBFC8.s index 3c4b640f..858e65b5 100644 --- a/asm/overlay_11_022EBEAC.s +++ b/asm/overlay_11_022EBFC8.s @@ -1,94 +1,8 @@ .include "asm/macros.inc" - .include "overlay_11_022EBEAC.inc" + .include "overlay_11_022EBFC8.inc" .text - arm_func_start ov11_022EBEAC -ov11_022EBEAC: ; 0x022EBEAC - stmdb sp!, {r4, r5, r6, r7, r8, lr} - mov r8, r0 - bl ov11_022EBFC8 - ldr r0, [r8, #0x2d8] - cmp r0, #0 - beq _022EBED0 - bl MemFree - mov r0, #0 - str r0, [r8, #0x2d8] -_022EBED0: - mov r7, #0 - mov r6, r7 - mov r5, r7 - mov r4, r7 -_022EBEE0: - add r0, r8, r7, lsl #2 - ldr r0, [r0, #0x2dc] - cmp r0, #0 - beq _022EBF10 - add r1, r8, r7, lsl #1 - add r1, r1, #0x200 - ldrsh r1, [r1, #0xca] - cmp r1, #0 - ble _022EBF08 - bl MemFree -_022EBF08: - add r0, r8, r7, lsl #2 - str r6, [r0, #0x2dc] -_022EBF10: - add r1, r8, r7, lsl #2 - ldr r0, [r1, #0x2ec] - cmp r0, #0 - strne r5, [r1, #0x2ec] - add r0, r8, r7, lsl #2 - ldr r0, [r0, #0x2e4] - cmp r0, #0 - beq _022EBF50 - add r1, r8, r7, lsl #1 - add r1, r1, #0x200 - ldrsh r1, [r1, #0xca] - cmp r1, #0 - ble _022EBF48 - bl MemFree -_022EBF48: - add r0, r8, r7, lsl #2 - str r4, [r0, #0x2e4] -_022EBF50: - add r7, r7, #1 - cmp r7, #2 - blt _022EBEE0 - ldmia sp!, {r4, r5, r6, r7, r8, pc} - arm_func_end ov11_022EBEAC - - arm_func_start ov11_022EBF60 -ov11_022EBF60: ; 0x022EBF60 - stmdb sp!, {r3, r4, r5, r6, r7, lr} - mov r7, r0 - mov r6, #0 - add r5, r7, #0xc4 - mov r4, #0x2c -_022EBF74: - mla r0, r6, r4, r5 - add r0, r0, #8 - bl ZInit8 - add r6, r6, #1 - cmp r6, #4 - blt _022EBF74 - add r0, r7, #0x1a0 - bl sub_02063600 - add r0, r7, #0x194 - bl sub_020635C8 - mov r1, #0 - add r0, r7, #0x174 - strb r1, [r7, #0x1bc] - bl ZInit8 - add r0, r7, #0x17c - bl ZInit8 - add r0, r7, #0x184 - bl ZInit8 - add r0, r7, #0x18c - bl ZInit8 - ldmia sp!, {r3, r4, r5, r6, r7, pc} - arm_func_end ov11_022EBF60 - arm_func_start ov11_022EBFC8 ov11_022EBFC8: ; 0x022EBFC8 stmdb sp!, {r4, r5, r6, r7, r8, lr} diff --git a/include/overlay_11_022EBB40.h b/include/overlay_11_022EBB40.h index 6b92044c..6a6705a0 100644 --- a/include/overlay_11_022EBB40.h +++ b/include/overlay_11_022EBB40.h @@ -1,12 +1,21 @@ #ifndef PMDSKY_OVERLAY_11_022EBB40_H #define PMDSKY_OVERLAY_11_022EBB40_H +// TODO: Move these to actual headers later on struct iovec { void* iov_base; u32 iov_len; }; +typedef struct PixelPos +{ + /* 0x0 */ s32 x; + /* 0x4 */ s32 y; +} PixelPos; + + + #define BG_NAME_LEN 8 struct bg_list_entry_sub_struct { @@ -28,12 +37,6 @@ struct bg_list_entry { #define UNK_3E0_ARR_COUNT 4 // Was 2 in Red #define NUM_LAYERS 2 -typedef struct PixelPos -{ - /* 0x0 */ s32 x; - /* 0x4 */ s32 y; -} PixelPos; - typedef struct SubStruct_0 { s16 unk0; @@ -78,7 +81,49 @@ typedef struct SubStruct_52C void *unk18; // Maybe void (*unk14)(void *, const void *, BmaHeader *, s32); // TODO: fix void * to proper ptr types 0x540 } SubStruct_52C; -#define CHUNK_DIMENSIONS_3x3 2 +struct UnkGroundBg_1A0 +{ + 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; +}; + +struct UnkGroundBg_194 +{ + u8 unk0; + u8 unk1; + u8 unk2; + u8 unk3; + u8 unk4; + u8 unk5; + u8 unk6; + u8 unk7; + u8 unk8; + u8 unk9; + u8 unkA; + u8 unkB; +}; // size: 0x55C typedef struct GroundBg @@ -86,74 +131,12 @@ typedef struct GroundBg u16 newUnk0; // Not present in Red SubStruct_0 unk0[UNK_0_ARR_COUNT]; SubStruct_3E0 unk3E0[UNK_3E0_ARR_COUNT]; // 0xc4 - u8 unk174; // 0x174 - u8 unk175; - u8 unk176; - u8 unk177; - u8 unk178; - u8 unk179; - u8 unk17A; - u8 unk17B; - u8 unk17C; - u8 unk17D; - u8 unk17E; - u8 unk17F; - u8 unk180; - u8 unk181; - u8 unk182; - u8 unk183; - u8 unk184; - u8 unk185; - u8 unk186; - u8 unk187; - u8 unk188; - u8 unk189; - u8 unk18A; - u8 unk18B; - u8 unk18C; - u8 unk18D; - u8 unk18E; - u8 unk18F; - u8 unk190; - u8 unk191; - u8 unk192; - u8 unk193; - u8 unk194; - u8 unk195; - u8 unk196; - u8 unk197; - u8 unk198; - u8 unk199; - u8 unk19A; - u8 unk19B; - u8 unk19C; - u8 unk19D; - u8 unk19E; - u8 unk19F; - u8 unk1A0; - u8 unk1A1; - u8 unk1A2; - u8 unk1A3; - u8 unk1A4; - u8 unk1A5; - u8 unk1A6; - u8 unk1A7; - u8 unk1A8; - u8 unk1A9; - u8 unk1AA; - u8 unk1AB; - u8 unk1AC; - u8 unk1AD; - u8 unk1AE; - u8 unk1AF; - u8 unk1B0; - u8 unk1B1; - u8 unk1B2; - u8 unk1B3; - u8 unk1B4; - u8 unk1B5; - u8 unk1B6; - u8 unk1B7; + struct iovec bplFile; // 0x174 + struct iovec unk17C; // 0x17C + struct iovec bpcFile; // 0x184 + struct iovec bmaFile; // 0x18c + struct UnkGroundBg_194 unk194; + struct UnkGroundBg_1A0 unk1A0; u8 unk1B8; u8 unk1B9; u8 unk1BA; @@ -231,5 +214,7 @@ typedef struct GroundBg void LoadBackgroundAttributes(struct bg_list_entry* entry, int bgId); void ov11_022EBC18(GroundBg *groundBg, const SubStruct_52C *a1); +void ov11_022EBEAC(GroundBg *groundBg); +void ov11_022EBF60(GroundBg *groundBg); #endif //PMDSKY_OVERLAY_11_022EBB40_H diff --git a/main.lsf b/main.lsf index e757552b..af5441c0 100644 --- a/main.lsf +++ b/main.lsf @@ -185,7 +185,7 @@ Overlay OVY_11 After OVY_10 Object asm/overlay_11.o Object src/overlay_11_022EBB40.o - Object asm/overlay_11_022EBEAC.o + Object asm/overlay_11_022EBFC8.o } Overlay OVY_12 { diff --git a/src/overlay_11_022EBB40.c b/src/overlay_11_022EBB40.c index fa7b0df9..db36cdce 100644 --- a/src/overlay_11_022EBB40.c +++ b/src/overlay_11_022EBB40.c @@ -1,8 +1,19 @@ #include "overlay_11_022EBB40.h" #include "file_rom.h" +// TODO: Move these to headers extern void FileClose(struct file_stream* file); +extern void ZInit8(struct iovec *dst); extern void* MemAlloc(u32 len, u32 flags); +extern void MemFree(void* ptr); +#define FREE_AND_SET_NULL(ptr) \ +{ \ + MemFree(ptr); \ + ptr = NULL; \ +} + +#define TRY_FREE_AND_SET_NULL(ptr) if (ptr != NULL) FREE_AND_SET_NULL(ptr) + extern const char ov11_02320C44[]; @@ -36,6 +47,9 @@ void LoadBackgroundAttributes(struct bg_list_entry* entry, int bgId) void ov11_022EBF60(GroundBg *groundBg); void *sub_0200B500(void *unk); +void ov11_022EBFC8(GroundBg *groundBg); // Close Opened Files ? +void sub_02063600(void *); +void sub_020635C8(struct UnkGroundBg_194 *); struct UnkStruct_2324CBC { @@ -144,3 +158,48 @@ void ov11_022EBC18(GroundBg *groundBg, const SubStruct_52C *a1) groundBg->cameraPixelPosition[i] = ov11_02320BE4.sPositionZero; } } + +void ov11_022EBEAC(GroundBg *groundBg) +{ + s32 i; + + ov11_022EBFC8(groundBg); + TRY_FREE_AND_SET_NULL(groundBg->unk2D8); + + for (i = 0; i < NUM_LAYERS; i++) { + if (groundBg->unk2DC[i] != NULL) { + if (groundBg->unk52C.unkE[i] > 0) { + MemFree(groundBg->unk2DC[i]); + } + groundBg->unk2DC[i] = NULL; + } + if (groundBg->unk2EC[i] != NULL) { + groundBg->unk2EC[i] = NULL; + } + if (groundBg->unk2E4[i] != NULL) { + if (groundBg->unk52C.unkE[i] > 0) { + MemFree(groundBg->unk2E4[i]); + } + groundBg->unk2E4[i] = NULL; + } + } +} + +void ov11_022EBF60(GroundBg *groundBg) +{ + s32 i; + + for (i = 0; i < UNK_3E0_ARR_COUNT; i++) { + SubStruct_3E0 *unkPtr = &groundBg->unk3E0[i]; + ZInit8(&unkPtr->bpaFile); + } + + sub_02063600(&groundBg->unk1A0); + sub_020635C8(&groundBg->unk194); + groundBg->unk1BC = 0; + + ZInit8(&groundBg->bplFile); + ZInit8(&groundBg->unk17C); + ZInit8(&groundBg->bpcFile); + ZInit8(&groundBg->bmaFile); +}