From 2a16b7cb81419aed581a86a831d1e2413ad57b39 Mon Sep 17 00:00:00 2001 From: golem galvanize Date: Sun, 28 Jan 2018 00:22:06 -0500 Subject: [PATCH] decompile field_message_box --- asm/field_message_box.s | 337 ---------------------------------------- ld_script.txt | 2 +- src/field_message_box.c | 162 +++++++++++++++++++ 3 files changed, 163 insertions(+), 338 deletions(-) delete mode 100644 asm/field_message_box.s create mode 100755 src/field_message_box.c diff --git a/asm/field_message_box.s b/asm/field_message_box.s deleted file mode 100644 index 0c1fae6dee..0000000000 --- a/asm/field_message_box.s +++ /dev/null @@ -1,337 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .syntax unified - - .text - - thumb_func_start sub_8098128 -sub_8098128: @ 8098128 - ldr r1, =gUnknown_020375BC - movs r0, 0 - strb r0, [r1] - ldr r2, =gTextFlags - ldrb r1, [r2] - movs r0, 0x2 - negs r0, r0 - ands r0, r1 - movs r1, 0x3 - negs r1, r1 - ands r0, r1 - subs r1, 0x2 - ands r0, r1 - subs r1, 0x4 - ands r0, r1 - strb r0, [r2] - bx lr - .pool - thumb_func_end sub_8098128 - - thumb_func_start sub_8098154 -sub_8098154: @ 8098154 - push {r4,r5,lr} - lsls r0, 24 - lsrs r5, r0, 24 - lsls r0, r5, 2 - adds r0, r5 - lsls r0, 3 - ldr r1, =gTasks - adds r4, r0, r1 - movs r1, 0x8 - ldrsh r0, [r4, r1] - cmp r0, 0x1 - beq _08098188 - cmp r0, 0x1 - bgt _0809817C - cmp r0, 0 - beq _08098182 - b _080981B0 - .pool -_0809817C: - cmp r0, 0x2 - beq _08098198 - b _080981B0 -_08098182: - bl sub_81973A4 - b _08098190 -_08098188: - movs r0, 0 - movs r1, 0x1 - bl sub_81973C4 -_08098190: - ldrh r0, [r4, 0x8] - adds r0, 0x1 - strh r0, [r4, 0x8] - b _080981B0 -_08098198: - bl sub_8197224 - lsls r0, 16 - lsrs r0, 16 - cmp r0, 0x1 - beq _080981B0 - ldr r1, =gUnknown_020375BC - movs r0, 0 - strb r0, [r1] - adds r0, r5, 0 - bl DestroyTask -_080981B0: - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8098154 - - thumb_func_start task_add_textbox -task_add_textbox: @ 80981BC - push {lr} - ldr r0, =sub_8098154 - movs r1, 0x50 - bl CreateTask - pop {r0} - bx r0 - .pool - thumb_func_end task_add_textbox - - thumb_func_start task_del_textbox -task_del_textbox: @ 80981D0 - push {lr} - ldr r0, =sub_8098154 - bl FindTaskIdByFunc - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0xFF - beq _080981E4 - bl DestroyTask -_080981E4: - pop {r0} - bx r0 - .pool - thumb_func_end task_del_textbox - - thumb_func_start ShowFieldMessage -ShowFieldMessage: @ 80981EC - push {r4,lr} - adds r1, r0, 0 - ldr r4, =gUnknown_020375BC - ldrb r0, [r4] - cmp r0, 0 - bne _0809820C - adds r0, r1, 0 - movs r1, 0x1 - bl textbox_fdecode_auto_and_task_add - movs r0, 0x2 - strb r0, [r4] - movs r0, 0x1 - b _0809820E - .pool -_0809820C: - movs r0, 0 -_0809820E: - pop {r4} - pop {r1} - bx r1 - thumb_func_end ShowFieldMessage - - thumb_func_start sub_8098214 -sub_8098214: @ 8098214 - push {r4,lr} - lsls r0, 24 - lsrs r4, r0, 24 - bl sub_8196094 - adds r1, r0, 0 - cmp r1, 0 - bne _0809822E - ldr r0, =gUnknown_020375BC - strb r1, [r0] - adds r0, r4, 0 - bl DestroyTask -_0809822E: - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8098214 - - thumb_func_start sub_8098238 -sub_8098238: @ 8098238 - push {r4,r5,lr} - adds r4, r0, 0 - ldr r5, =gUnknown_020375BC - ldrb r0, [r5] - cmp r0, 0 - bne _08098270 - ldr r0, =gStringVar4 - adds r1, r4, 0 - bl StringExpandPlaceholders - ldr r0, =sub_8098214 - movs r1, 0 - bl CreateTask - adds r0, r4, 0 - bl sub_8196080 - movs r0, 0x2 - strb r0, [r5] - movs r0, 0x1 - b _08098272 - .pool -_08098270: - movs r0, 0 -_08098272: - pop {r4,r5} - pop {r1} - bx r1 - thumb_func_end sub_8098238 - - thumb_func_start ShowFieldAutoScrollMessage -ShowFieldAutoScrollMessage: @ 8098278 - push {lr} - adds r1, r0, 0 - ldr r2, =gUnknown_020375BC - ldrb r0, [r2] - cmp r0, 0 - bne _08098298 - movs r0, 0x3 - strb r0, [r2] - adds r0, r1, 0 - movs r1, 0 - bl textbox_fdecode_auto_and_task_add - movs r0, 0x1 - b _0809829A - .pool -_08098298: - movs r0, 0 -_0809829A: - pop {r1} - bx r1 - thumb_func_end ShowFieldAutoScrollMessage - - thumb_func_start sub_80982A0 -sub_80982A0: @ 80982A0 - push {lr} - ldr r2, =gUnknown_020375BC - movs r1, 0x3 - strb r1, [r2] - movs r1, 0x1 - bl textbox_fdecode_auto_and_task_add - movs r0, 0x1 - pop {r1} - bx r1 - .pool - thumb_func_end sub_80982A0 - - thumb_func_start sub_80982B8 -sub_80982B8: @ 80982B8 - push {lr} - ldr r1, =gUnknown_020375BC - ldrb r0, [r1] - cmp r0, 0 - bne _080982D4 - movs r0, 0x2 - strb r0, [r1] - bl textbox_auto_and_task_add - movs r0, 0x1 - b _080982D6 - .pool -_080982D4: - movs r0, 0 -_080982D6: - pop {r1} - bx r1 - thumb_func_end sub_80982B8 - - thumb_func_start textbox_fdecode_auto_and_task_add -textbox_fdecode_auto_and_task_add: @ 80982DC - push {r4,lr} - adds r2, r0, 0 - adds r4, r1, 0 - ldr r0, =gStringVar4 - adds r1, r2, 0 - bl StringExpandPlaceholders - lsls r4, 24 - lsrs r4, 24 - adds r0, r4, 0 - bl AddTextPrinterForMessage - bl task_add_textbox - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end textbox_fdecode_auto_and_task_add - - thumb_func_start textbox_auto_and_task_add -textbox_auto_and_task_add: @ 8098304 - push {lr} - movs r0, 0x1 - bl AddTextPrinterForMessage - bl task_add_textbox - pop {r0} - bx r0 - thumb_func_end textbox_auto_and_task_add - - thumb_func_start HideFieldMessageBox -HideFieldMessageBox: @ 8098314 - push {lr} - bl task_del_textbox - movs r0, 0 - movs r1, 0x1 - bl sub_8197434 - ldr r1, =gUnknown_020375BC - movs r0, 0 - strb r0, [r1] - pop {r0} - bx r0 - .pool - thumb_func_end HideFieldMessageBox - - thumb_func_start textbox_any_visible -textbox_any_visible: @ 8098330 - ldr r0, =gUnknown_020375BC - ldrb r0, [r0] - bx lr - .pool - thumb_func_end textbox_any_visible - - thumb_func_start IsFieldMessageBoxHidden -IsFieldMessageBoxHidden: @ 809833C - push {lr} - ldr r0, =gUnknown_020375BC - ldrb r0, [r0] - cmp r0, 0 - beq _08098350 - movs r0, 0 - b _08098352 - .pool -_08098350: - movs r0, 0x1 -_08098352: - pop {r1} - bx r1 - thumb_func_end IsFieldMessageBoxHidden - - thumb_func_start sub_8098358 -sub_8098358: @ 8098358 - push {lr} - bl task_del_textbox - movs r0, 0 - movs r1, 0x1 - bl sub_81973FC - ldr r1, =gUnknown_020375BC - movs r0, 0 - strb r0, [r1] - pop {r0} - bx r0 - .pool - thumb_func_end sub_8098358 - - thumb_func_start sub_8098374 -sub_8098374: @ 8098374 - push {lr} - bl task_del_textbox - ldr r1, =gUnknown_020375BC - movs r0, 0 - strb r0, [r1] - pop {r0} - bx r0 - .pool - thumb_func_end sub_8098374 - - .align 2, 0 @ Don't pad with nop. diff --git a/ld_script.txt b/ld_script.txt index f2a9d81963..44b503c554 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -98,7 +98,7 @@ SECTIONS { src/field_map_obj.o(.text); asm/field_ground_effect.o(.text); asm/map_obj_8097404.o(.text); - asm/field_message_box.o(.text); + src/field_message_box.o(.text); asm/map_obj_lock.o(.text); src/text_window.o(.text); src/script.o(.text); diff --git a/src/field_message_box.c b/src/field_message_box.c new file mode 100755 index 0000000000..fc51bc5888 --- /dev/null +++ b/src/field_message_box.c @@ -0,0 +1,162 @@ +#include "global.h" +#include "string.h" +#include "string_util.h" +#include "task.h" +#include "text.h" + +extern void sub_81973A4(void); +extern void sub_81973C4(u8, u8); +extern u16 sub_8197224(void); +extern int sub_8196094(void); +extern void sub_8196080(u8*); +extern void AddTextPrinterForMessage(u8); +extern void sub_8197434(u8, u8); +extern void sub_81973FC(u8, u8); + +extern u8 gUnknown_020375BC; + +void textbox_fdecode_auto_and_task_add(u8*, int); +void textbox_auto_and_task_add(void); + +void sub_8098128(void) +{ + gUnknown_020375BC = 0; + gTextFlags.flag_0 = 0; + gTextFlags.flag_1 = 0; + gTextFlags.flag_2 = 0; + gTextFlags.flag_3 = 0; +} + +void sub_8098154(u8 taskId) +{ + struct Task *task = &gTasks[taskId]; + + switch (task->data[0]) + { + case 0: + sub_81973A4(); + task->data[0]++; + break; + case 1: + sub_81973C4(0, 1); + task->data[0]++; + break; + case 2: + if (sub_8197224() != 1) + { + gUnknown_020375BC = 0; + DestroyTask(taskId); + } + } +} + +void task_add_textbox(void) +{ + CreateTask(sub_8098154, 0x50); +} + +void task_del_textbox(void) +{ + u8 taskId = FindTaskIdByFunc(sub_8098154); + if (taskId != 0xFF) + DestroyTask(taskId); +} + +bool8 ShowFieldMessage(u8 *str) +{ + if (gUnknown_020375BC != 0) + return FALSE; + textbox_fdecode_auto_and_task_add(str, 1); + gUnknown_020375BC = 2; + return TRUE; +} + +void sub_8098214(u8 taskId) +{ + if (sub_8196094() == 0) + { + gUnknown_020375BC = 0; + DestroyTask(taskId); + } +} + +bool8 sub_8098238(u8 *str) +{ + if (gUnknown_020375BC != 0) + return FALSE; + StringExpandPlaceholders(gStringVar4, str); + CreateTask(sub_8098214, 0); + sub_8196080(str); + gUnknown_020375BC = 2; + return TRUE; +} + +bool8 ShowFieldAutoScrollMessage(u8 *str) +{ + if (gUnknown_020375BC != 0) + return FALSE; + gUnknown_020375BC = 3; + textbox_fdecode_auto_and_task_add(str, 0); + return TRUE; +} + +bool8 sub_80982A0(u8 *str) +{ + gUnknown_020375BC = 3; + textbox_fdecode_auto_and_task_add(str, 1); + return TRUE; +} + +bool8 sub_80982B8(void) +{ + if (gUnknown_020375BC != 0) + return FALSE; + gUnknown_020375BC = 2; + textbox_auto_and_task_add(); + return TRUE; +} + +void textbox_fdecode_auto_and_task_add(u8* str, int a) +{ + StringExpandPlaceholders(gStringVar4, str); + AddTextPrinterForMessage(a); + task_add_textbox(); +} + +void textbox_auto_and_task_add(void) +{ + AddTextPrinterForMessage(1); + task_add_textbox(); +} + +void HideFieldMessageBox(void) +{ + task_del_textbox(); + sub_8197434(0, 1); + gUnknown_020375BC = 0; +} + +u8 textbox_any_visible(void) +{ + return gUnknown_020375BC; +} + +bool8 IsFieldMessageBoxHidden(void) +{ + if (gUnknown_020375BC == 0) + return TRUE; + return FALSE; +} + +void sub_8098358(void) +{ + task_del_textbox(); + sub_81973FC(0, 1); + gUnknown_020375BC = 0; +} + +void sub_8098374(void) +{ + task_del_textbox(); + gUnknown_020375BC = 0; +}