From 0a060ae254c48f7cbee99974b1c7bffd378d9c38 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Sun, 29 Oct 2017 10:38:25 -0400 Subject: [PATCH] Start decompiling field_region_map --- asm/field_region_map.s | 101 ----------------------------------------- include/menu.h | 2 + ld_script.txt | 2 + src/field_region_map.c | 84 ++++++++++++++++++++++++++++++++++ sym_ewram.txt | 3 +- 5 files changed, 89 insertions(+), 103 deletions(-) create mode 100644 src/field_region_map.c diff --git a/asm/field_region_map.s b/asm/field_region_map.s index 512dfb151..10652e5e9 100644 --- a/asm/field_region_map.s +++ b/asm/field_region_map.s @@ -5,107 +5,6 @@ .text - thumb_func_start sub_817018C -sub_817018C: @ 817018C - push {r4,r5,lr} - adds r5, r0, 0 - movs r0, 0 - bl SetVBlankCallback - ldr r4, =gUnknown_0203BCD0 - movs r0, 0x89 - lsls r0, 4 - bl Alloc - str r0, [r4] - ldr r1, =0x0000088c - adds r2, r0, r1 - movs r1, 0 - strh r1, [r2] - str r5, [r0] - ldr r0, =sub_81701C4 - bl SetMainCallback2 - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_817018C - - thumb_func_start sub_81701C4 -sub_81701C4: @ 81701C4 - push {lr} - movs r0, 0 - movs r1, 0 - bl SetGpuReg - movs r0, 0x10 - movs r1, 0 - bl SetGpuReg - movs r0, 0x12 - movs r1, 0 - bl SetGpuReg - movs r0, 0x14 - movs r1, 0 - bl SetGpuReg - movs r0, 0x16 - movs r1, 0 - bl SetGpuReg - movs r0, 0x18 - movs r1, 0 - bl SetGpuReg - movs r0, 0x1A - movs r1, 0 - bl SetGpuReg - movs r0, 0x1C - movs r1, 0 - bl SetGpuReg - movs r0, 0x1E - movs r1, 0 - bl SetGpuReg - bl ResetSpriteData - bl FreeAllSpritePalettes - movs r0, 0 - bl ResetBgsAndClearDma3BusyFlags - ldr r1, =gUnknown_085E5068 - movs r0, 0x1 - movs r2, 0x2 - bl InitBgsFromTemplates - ldr r0, =gUnknown_085E5070 - bl InitWindows - bl DeactivateAllTextPrinters - movs r0, 0 - movs r1, 0x27 - movs r2, 0xD0 - bl sub_809882C - bl clear_scheduled_bg_copies_to_vram - ldr r0, =sub_8170274 - bl SetMainCallback2 - ldr r0, =sub_8170260 - bl SetVBlankCallback - pop {r0} - bx r0 - .pool - thumb_func_end sub_81701C4 - - thumb_func_start sub_8170260 -sub_8170260: @ 8170260 - push {lr} - bl LoadOam - bl ProcessSpriteCopyRequests - bl TransferPlttBuffer - pop {r0} - bx r0 - thumb_func_end sub_8170260 - - thumb_func_start sub_8170274 -sub_8170274: @ 8170274 - push {lr} - bl sub_8170290 - bl AnimateSprites - bl BuildOamBuffer - bl UpdatePaletteFade - bl do_scheduled_bg_tilemap_copies_to_vram - pop {r0} - bx r0 - thumb_func_end sub_8170274 - thumb_func_start sub_8170290 sub_8170290: @ 8170290 push {r4,r5,lr} diff --git a/include/menu.h b/include/menu.h index 927c3d3d4..51c95051b 100644 --- a/include/menu.h +++ b/include/menu.h @@ -28,5 +28,7 @@ bool8 free_temp_tile_data_buffers_if_possible(void); u64 sub_8198A50(struct WindowTemplate*, u8, u8, u8, u8, u8, u8, u16); // returns something but it isn't used, fix when menu.s is decomp'd void CreateYesNoMenu(const struct WindowTemplate *windowTemplate, u16 borderFirstTileNum, u8 borderPalette, u8 initialCursorPos); s8 sub_8198C58(void); +void do_scheduled_bg_tilemap_copies_to_vram(void); +void clear_scheduled_bg_copies_to_vram(void); #endif // GUARD_MENU_H diff --git a/ld_script.txt b/ld_script.txt index eb8327f24..252c0e11d 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -212,6 +212,7 @@ SECTIONS { asm/player_pc.o(.text); asm/intro.o(.text); src/reset_save_heap.o(.text); + src/field_region_map.o(.text); asm/field_region_map.o(.text); asm/battle_anim_8170478.o(.text); asm/hall_of_fame.o(.text); @@ -433,6 +434,7 @@ SECTIONS { data/battle_controller_wally.o(.rodata); data/player_pc.o(.rodata); data/intro.o(.rodata); + src/field_region_map.o(.rodata); data/field_region_map.o(.rodata); data/battle_anim_8170478.o(.rodata); data/hall_of_fame.o(.rodata); diff --git a/src/field_region_map.c b/src/field_region_map.c new file mode 100644 index 000000000..4923f2069 --- /dev/null +++ b/src/field_region_map.c @@ -0,0 +1,84 @@ + +// Includes +#include "global.h" +#include "main.h" +#include "malloc.h" +#include "gpu_regs.h" +#include "bg.h" +#include "text.h" +#include "window.h" +#include "text_window.h" +#include "palette.h" +#include "menu.h" + +// Static type declarations + +// Static RAM declarations + +EWRAM_DATA struct { + MainCallback callback; + u8 filler_004[0x888]; + u16 unk_88c; +} *gUnknown_0203BCD0 = NULL; + +// Static ROM declarations + +static void sub_81701C4(void); +static void sub_8170260(void); +static void sub_8170274(void); +void sub_8170290(void); + +// .rodata + +extern const struct BgTemplate gUnknown_085E5068[]; +extern const struct WindowTemplate gUnknown_085E5070[]; + +// .text + +void sub_817018C(MainCallback callback) +{ + SetVBlankCallback(NULL); + gUnknown_0203BCD0 = malloc(sizeof(*gUnknown_0203BCD0)); + gUnknown_0203BCD0->unk_88c = 0; + gUnknown_0203BCD0->callback = callback; + SetMainCallback2(sub_81701C4); +} + +static void sub_81701C4(void) +{ + SetGpuReg(REG_OFFSET_DISPCNT, 0); + SetGpuReg(REG_OFFSET_BG0HOFS, 0); + SetGpuReg(REG_OFFSET_BG0VOFS, 0); + SetGpuReg(REG_OFFSET_BG1HOFS, 0); + SetGpuReg(REG_OFFSET_BG1VOFS, 0); + SetGpuReg(REG_OFFSET_BG2HOFS, 0); + SetGpuReg(REG_OFFSET_BG2VOFS, 0); + SetGpuReg(REG_OFFSET_BG3HOFS, 0); + SetGpuReg(REG_OFFSET_BG3VOFS, 0); + ResetSpriteData(); + FreeAllSpritePalettes(); + ResetBgsAndClearDma3BusyFlags(0); + InitBgsFromTemplates(1, gUnknown_085E5068, 2); + InitWindows(gUnknown_085E5070); + DeactivateAllTextPrinters(); + sub_809882C(0, 0x27, 0xd0); + clear_scheduled_bg_copies_to_vram(); + SetMainCallback2(sub_8170274); + SetVBlankCallback(sub_8170260); +} + +static void sub_8170260(void) +{ + LoadOam(); + ProcessSpriteCopyRequests(); + TransferPlttBuffer(); +} + +static void sub_8170274(void) +{ + sub_8170290(); + AnimateSprites(); + BuildOamBuffer(); + UpdatePaletteFade(); + do_scheduled_bg_tilemap_copies_to_vram(); +} diff --git a/sym_ewram.txt b/sym_ewram.txt index d2779079e..53680a1bb 100644 --- a/sym_ewram.txt +++ b/sym_ewram.txt @@ -1410,8 +1410,7 @@ gUnknown_0203BCC8: @ 203BCC8 gUnknown_0203BCCC: @ 203BCCC .space 0x4 -gUnknown_0203BCD0: @ 203BCD0 - .space 0x4 + .include "src/field_region_map.o" gUnknown_0203BCD4: @ 203BCD4 .space 0x4