From 91c6c244007944ffcd5da2e42b1a5221b0ce2074 Mon Sep 17 00:00:00 2001 From: scnorton Date: Sun, 21 Jan 2018 16:51:04 -0500 Subject: [PATCH] sub_8006218 --- asm/text.s | 134 ----------------------------------------- include/code_800558C.h | 6 ++ include/file_system.h | 34 +++++++++++ ld_script.txt | 1 + src/file_system.c | 32 ++-------- src/text.c | 75 +++++++++++++++++++++++ 6 files changed, 120 insertions(+), 162 deletions(-) create mode 100644 include/code_800558C.h create mode 100644 include/file_system.h create mode 100644 src/text.c diff --git a/asm/text.s b/asm/text.s index a8e6dc56..f1235bb6 100644 --- a/asm/text.s +++ b/asm/text.s @@ -5,140 +5,6 @@ .text - thumb_func_start sub_8006218 -sub_8006218: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - ldr r1, _080062F4 - movs r0, 0 - str r0, [r1] - ldr r0, _080062F8 - ldr r5, _080062FC - adds r1, r5, 0 - bl OpenFileAndGetFileDataPtr - ldr r4, _08006300 - str r0, [r4] - ldr r0, _08006304 - adds r1, r5, 0 - bl OpenFileAndGetFileDataPtr - str r0, [r4, 0x4] - ldr r2, _08006308 - ldr r1, [r4] - ldr r1, [r1, 0x4] - str r1, [r2] - ldr r0, [r0, 0x4] - str r0, [r2, 0x4] - ldr r1, _0800630C - movs r0, 0xB - str r0, [r1] - movs r0, 0xC - str r0, [r1, 0x4] - ldr r0, _08006310 - movs r4, 0 - movs r3, 0 - adds r2, r0, 0 - adds r2, 0x46 - adds r0, 0x4 - movs r1, 0x3 -_08006264: - strh r3, [r0] - strh r3, [r0, 0x4] - strb r4, [r2] - adds r2, 0x48 - adds r0, 0x48 - subs r1, 0x1 - cmp r1, 0 - bge _08006264 - ldr r1, _08006314 - movs r0, 0 - strh r0, [r1] - movs r3, 0 - ldr r0, _08006318 - mov r9, r0 - ldr r1, _0800631C - mov r10, r1 - ldr r7, _08006320 - ldr r2, _08006324 - mov r8, r2 - movs r0, 0x80 - lsls r0, 4 - adds r6, r7, r0 - ldr r4, _08006328 - movs r5, 0 - mov r12, r6 -_08006296: - lsls r0, r3, 6 - adds r2, r0, r7 - mov r1, r8 - strh r1, [r2] - adds r1, r0, r6 - strh r4, [r1] - adds r3, 0x1 - add r0, r12 - adds r0, 0x2 - adds r2, 0x2 - movs r1, 0x1E -_080062AC: - strh r5, [r2] - strh r4, [r0] - adds r0, 0x2 - adds r2, 0x2 - subs r1, 0x1 - cmp r1, 0 - bge _080062AC - cmp r3, 0x13 - ble _08006296 - movs r1, 0 - movs r0, 0x1 - mov r2, r9 - strb r0, [r2] - ldr r0, _0800632C - mov r2, r10 - str r0, [r2] - ldr r0, _08006330 - str r1, [r0] - ldr r2, _08006334 - strb r1, [r2] - movs r0, 0x1 - ldr r1, _08006338 - str r0, [r1] - movs r0, 0x14 - ldr r2, _0800633C - str r0, [r2] - movs r0, 0 - bl xxx_update_some_bg_tiles - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_080062F4: .4byte gUnknown_20274AC -_080062F8: .4byte gUnknown_80B87B4 -_080062FC: .4byte gUnknown_8300500 -_08006300: .4byte gUnknown_202AFB4 -_08006304: .4byte gUnknown_80B87BC -_08006308: .4byte gUnknown_2027490 -_0800630C: .4byte gUnknown_202B028 -_08006310: .4byte gUnknown_2027370 -_08006314: .4byte gUnknown_2027498 -_08006318: .4byte gUnknown_202B034 -_0800631C: .4byte gUnknown_202B030 -_08006320: .4byte gUnknown_202B038 -_08006324: .4byte 0x0000f279 -_08006328: .4byte 0x0000f27a -_0800632C: .4byte 0x88888888 -_08006330: .4byte gUnknown_203B078 -_08006334: .4byte gUnknown_20274A5 -_08006338: .4byte gUnknown_202B020 -_0800633C: .4byte gUnknown_202B024 - thumb_func_end sub_8006218 - thumb_func_start xxx_update_some_bg_tiles xxx_update_some_bg_tiles: push {r4,r5,lr} diff --git a/include/code_800558C.h b/include/code_800558C.h new file mode 100644 index 00000000..be974cc8 --- /dev/null +++ b/include/code_800558C.h @@ -0,0 +1,6 @@ +#ifndef GUARD_code_800558C_H +#define GUARD_code_800558C_H + +extern u32 gUnknown_203B078; + +#endif //GUARD_code_800558C_H diff --git a/include/file_system.h b/include/file_system.h new file mode 100644 index 00000000..360f7aca --- /dev/null +++ b/include/file_system.h @@ -0,0 +1,34 @@ +#ifndef GUARD_FILE_SYSTEM_H +#define GUARD_FILE_SYSTEM_H + +struct File +{ + char *name; + u8 *data; +}; + +struct OpenedFile +{ + struct File *file; + u8 *data; +}; + +struct FileArchive +{ + char magic[8]; + s32 count; + struct File *entries; +}; + +struct SiroArchive +{ + u32 magic; + u8 *data; +}; + +struct OpenedFile *OpenFile(const char *filename, const struct FileArchive *arc); +u8 *GetFileDataPtr(struct OpenedFile *openedFile, int unused); +struct OpenedFile *OpenFileAndGetFileDataPtr(const char *filename, const struct FileArchive *arc); +struct OpenedFile *Call_OpenFileAndGetFileDataPtr(const char *filename, const struct FileArchive *arc); + +#endif //GUARD_FILE_SYSTEM_H diff --git a/ld_script.txt b/ld_script.txt index e3a6af75..f3ecc120 100755 --- a/ld_script.txt +++ b/ld_script.txt @@ -58,6 +58,7 @@ SECTIONS { asm/sprite.o(.text); asm/code_800558C.o(.text); src/random.o(.text); + src/text.o(.text); asm/text.o(.text); asm/code_8009804.o(.text); src/file_system.o(.text); diff --git a/src/file_system.c b/src/file_system.c index 296478d2..0d8de102 100644 --- a/src/file_system.c +++ b/src/file_system.c @@ -1,29 +1,5 @@ #include "global.h" - -struct File -{ - char *name; - u8 *data; -}; - -struct OpenedFile -{ - struct File *file; - u8 *data; -}; - -struct FileArchive -{ - char magic[8]; - s32 count; - struct File *entries; -}; - -struct SiroArchive -{ - u32 magic; - u8 *data; -}; +#include "file_system.h" extern struct OpenedFile gUnknown_202D2A8[]; @@ -56,7 +32,7 @@ u32 sub_800A8F8(u32 value) return oldValue; } -struct OpenedFile *OpenFile(char *filename, struct FileArchive *arc) +struct OpenedFile *OpenFile(const char *filename, const struct FileArchive *arc) { char buffer[0x12C]; s32 left, right; @@ -138,7 +114,7 @@ u8 *GetFileDataPtr(struct OpenedFile *openedFile, int unused) return GetSiroPtr(openedFile); } -struct OpenedFile *OpenFileAndGetFileDataPtr(char *filename, struct FileArchive *arc) +struct OpenedFile *OpenFileAndGetFileDataPtr(const char *filename, const struct FileArchive *arc) { struct OpenedFile *openedFile = OpenFile(filename, arc); if (openedFile) @@ -146,7 +122,7 @@ struct OpenedFile *OpenFileAndGetFileDataPtr(char *filename, struct FileArchive return openedFile; } -struct OpenedFile *Call_OpenFileAndGetFileDataPtr(char *filename, struct FileArchive *arc) +struct OpenedFile *Call_OpenFileAndGetFileDataPtr(const char *filename, const struct FileArchive *arc) { return OpenFileAndGetFileDataPtr(filename, arc); } diff --git a/src/text.c b/src/text.c new file mode 100644 index 00000000..929d8b1c --- /dev/null +++ b/src/text.c @@ -0,0 +1,75 @@ +// ------------------------ +// TEXT.C +// Decompiled by PikalaxALT +// ------------------------ + +#include "global.h" +#include "file_system.h" +#include "code_800558C.h" + +struct UnkTextStruct1 { + u8 fill00[4]; + u16 unk04; + u8 fill06[2]; + u16 unk08; + u8 fill04[0x3c]; + u8 unk46; +}; + +EWRAM_DATA struct UnkTextStruct1 gUnknown_2027370[4]; +EWRAM_DATA u8 *gUnknown_2027490[2]; +EWRAM_DATA u16 gUnknown_2027498; +EWRAM_DATA u8 gUnknown_20274A5; +EWRAM_DATA u32 gUnknown_20274AC; +EWRAM_DATA struct OpenedFile *gUnknown_202AFB4[2]; +EWRAM_DATA u32 gUnknown_202B020; +EWRAM_DATA u32 gUnknown_202B024; +EWRAM_DATA u32 gUnknown_202B028[2]; +EWRAM_DATA u32 gUnknown_202B030; +EWRAM_DATA u8 gUnknown_202B034; +EWRAM_DATA u16 gUnknown_202B038[2][32][32]; + +void xxx_update_some_bg_tiles(int a0); + +extern const char gUnknown_80B87B4[]; +extern const char gUnknown_80B87BC[]; +extern const struct FileArchive gUnknown_8300500; + +void sub_8006218(void) +{ + int i; + int j; + int k; + + gUnknown_20274AC = 0; + gUnknown_202AFB4[0] = OpenFileAndGetFileDataPtr(gUnknown_80B87B4, &gUnknown_8300500); + gUnknown_202AFB4[1] = OpenFileAndGetFileDataPtr(gUnknown_80B87BC, &gUnknown_8300500); + gUnknown_2027490[0] = gUnknown_202AFB4[0]->data; + gUnknown_2027490[1] = gUnknown_202AFB4[1]->data; + gUnknown_202B028[0] = 11; + gUnknown_202B028[1] = 12; + for (k = 0; k < 4; k++) + { + gUnknown_2027370[k].unk04 = 0; + gUnknown_2027370[k].unk08 = 0; + gUnknown_2027370[k].unk46 = 0; + } + gUnknown_2027498 = 0; + for (i = 0; i < 20; i++) + { + gUnknown_202B038[0][i][0] = 0xf279; + gUnknown_202B038[1][i][0] = 0xf27a; + for (j = 1; j < 32; j++) + { + gUnknown_202B038[0][i][j] = 0; + gUnknown_202B038[1][i][j] = 0xf27a; + } + } + gUnknown_202B034 = 1; + gUnknown_202B030 = 0x88888888; + gUnknown_203B078 = 0; + gUnknown_20274A5 = 0; + gUnknown_202B020 = 1; + gUnknown_202B024 = 20; + xxx_update_some_bg_tiles(0); +}