From d52cbe6bcb7777547ba1dc0c3e58c9d72aff4338 Mon Sep 17 00:00:00 2001 From: Phlosioneer Date: Tue, 12 Feb 2019 02:23:08 -0500 Subject: [PATCH] Decompiled sub_81C72BC --- asm/pokenav.s | 45 ----------------------- src/pokenav_main.c | 90 +++++++++++++++++----------------------------- 2 files changed, 33 insertions(+), 102 deletions(-) diff --git a/asm/pokenav.s b/asm/pokenav.s index 64439e890..dbe58020a 100644 --- a/asm/pokenav.s +++ b/asm/pokenav.s @@ -5,51 +5,6 @@ .text - - thumb_func_start sub_81C72BC -sub_81C72BC: @ 81C72BC - push {r4,lr} - bl UpdatePaletteFade - ldr r0, =gPaletteFade - ldrb r1, [r0, 0x7] - movs r0, 0x80 - ands r0, r1 - cmp r0, 0 - bne _081C7320 - ldr r4, =gUnknown_0203CF40 - movs r0, 0x5C - bl Alloc - str r0, [r4] - cmp r0, 0 - bne _081C72F0 - ldr r0, =CB2_ReturnToFieldContinueScriptPlayMapMusic - bl SetMainCallback2 - b _081C7320 - .pool -_081C72F0: - bl sub_81C7360 - ldr r1, [r4] - movs r0, 0x1 - strh r0, [r1, 0x8] - bl ResetTasks - bl ResetSpriteData - bl FreeAllSpritePalettes - movs r0, 0 - bl SetVBlankCallback - ldr r0, =sub_81C742C - movs r1, 0 - bl CreateTask - ldr r0, =sub_81C7400 - bl SetMainCallback2 - ldr r0, =sub_81C7418 - bl SetVBlankCallback -_081C7320: - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81C72BC - thumb_func_start sub_81C7334 sub_81C7334: @ 81C7334 push {r4,lr} diff --git a/src/pokenav_main.c b/src/pokenav_main.c index 13b6331a5..0712b95d5 100644 --- a/src/pokenav_main.c +++ b/src/pokenav_main.c @@ -4,55 +4,28 @@ #include "main.h" #include "overworld.h" #include "field_weather.h" +#include "palette.h" -/* +// Can confirm the size is correct on line 287 of the generated pokenav_main.s +// file. The expected size is 0x5C. +struct UnknownStruct_0203CF40 { + u8 data1[8]; + u16 field_0; + u8 data[0x52]; +}; - thumb_func_start CB2_PokeNav -CB2_PokeNav: @ 81C7250 - push {r4,lr} - ldr r4, =gUnknown_0203CF40 - movs r0, 0x5C - bl Alloc - str r0, [r4] - cmp r0, 0 - bne _081C7270 - ldr r0, =CB2_ReturnToFieldWithOpenMenu - bl SetMainCallback2 - b _081C7292 - .pool -_081C7270: - bl sub_81C7360 - bl ResetTasks - movs r0, 0 - bl SetVBlankCallback - ldr r0, =sub_81C742C - movs r1, 0 - bl CreateTask - ldr r0, =sub_81C7400 - bl SetMainCallback2 - ldr r0, =sub_81C7418 - bl SetVBlankCallback -_081C7292: - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end CB2_PokeNav +extern struct UnknownStruct_0203CF40 *gUnknown_0203CF40; +extern u8 gUnknown_0203CF3C; -*/ - -extern u8* gUnknown_0203CF40; extern void sub_81C7360(void); extern void sub_81C742C(u8 taskId); extern void sub_81C7400(void); extern void sub_81C7418(void); - - - -extern u8 gUnknown_0203CF3C; extern void sub_81C7170(u8 a0); extern void sub_81C71E4(u8 a0); +void sub_81C72BC(void); + u32 sub_81C7078(u32 (*a0)(u32), u32 a1) { u16 taskId; @@ -162,7 +135,7 @@ void sub_81C71E4(u8 taskId) { void CB2_PokeNav(void) { - gUnknown_0203CF40 = Alloc(0x5C); + gUnknown_0203CF40 = Alloc(sizeof(struct UnknownStruct_0203CF40)); if (gUnknown_0203CF40 == NULL) { SetMainCallback2(CB2_ReturnToFieldWithOpenMenu); } else { @@ -175,24 +148,27 @@ void CB2_PokeNav(void) } } -/* - thumb_func_start sub_81C72A4 -sub_81C72A4: @ 81C72A4 - push {lr} - ldr r0, =sub_81C72BC - bl SetMainCallback2 - movs r0, 0x1 - movs r1, 0 - bl FadeScreen - pop {r0} - bx r0 - .pool - thumb_func_end sub_81C72A4 -*/ - -extern void sub_81C72BC(void); - void sub_81C72A4() { SetMainCallback2(sub_81C72BC); FadeScreen(1, 0); +} + +void sub_81C72BC() { + UpdatePaletteFade(); + if (!gPaletteFade.active) { + gUnknown_0203CF40 = Alloc(sizeof(struct UnknownStruct_0203CF40)); + if (gUnknown_0203CF40 == NULL) { + SetMainCallback2(CB2_ReturnToFieldContinueScriptPlayMapMusic); + } else { + sub_81C7360(); + gUnknown_0203CF40->field_0 = 1; + ResetTasks(); + ResetSpriteData(); + FreeAllSpritePalettes(); + SetVBlankCallback(NULL); + CreateTask(sub_81C742C, 0); + SetMainCallback2(sub_81C7400); + SetVBlankCallback(sub_81C7418); + } + } } \ No newline at end of file