From 2bd2fe5fcb217f9189443196d085d6bfd45aa665 Mon Sep 17 00:00:00 2001 From: Noah Nelson Date: Mon, 8 Aug 2022 04:40:01 +0000 Subject: [PATCH] Decompile the rest of the code in branched_promotion.s Now can move over the data and try to document more, especially the procs --- asm/branched_promotion.s | 377 --------------------------------------- include/fontgrp.h | 2 +- ldscript.txt | 1 - src/branched_promotion.c | 176 +++++++++++++++++- 4 files changed, 176 insertions(+), 380 deletions(-) delete mode 100644 asm/branched_promotion.s diff --git a/asm/branched_promotion.s b/asm/branched_promotion.s deleted file mode 100644 index bbb9f21a..00000000 --- a/asm/branched_promotion.s +++ /dev/null @@ -1,377 +0,0 @@ - .INCLUDE "macro.inc" - - .SYNTAX UNIFIED - - THUMB_FUNC_START PromotionCommand_OnSelect -PromotionCommand_OnSelect: @ 0x080CDB34 - push {r4, r5, r6, r7, lr} - sub sp, #8 - adds r7, r0, #0 - adds r6, r1, #0 - ldr r0, [r7, #0x14] - ldr r0, [r0, #0x14] - ldr r4, [r0, #0x14] - adds r0, #0x40 - ldrb r0, [r0] - cmp r0, #0 - bne _080CDBFA - adds r0, r4, #0 - adds r0, #0x38 - ldrb r0, [r0] - bl GetUnitFromCharId - adds r5, r0, #0 - ldr r0, [r5, #4] - ldrb r1, [r0, #4] - adds r3, r6, #0 - adds r3, #0x3c - movs r0, #0 - ldrsb r0, [r3, r0] - cmp r0, #1 - bgt _080CDB78 - ldr r2, _080CDB74 @ gUnknown_0895DFA4 - lsls r1, r1, #1 - adds r0, r0, r1 - adds r0, r0, r2 - ldrb r1, [r0] - b _080CDBA6 - .align 2, 0 -_080CDB74: .4byte gUnknown_0895DFA4 -_080CDB78: - adds r2, r4, #0 - adds r2, #0x3b - cmp r0, #2 - bne _080CDBAE - cmp r1, #0x3e - beq _080CDB9A - cmp r1, #0x3e - bgt _080CDB8E - cmp r1, #0x3d - beq _080CDB94 - b _080CDBA6 -_080CDB8E: - cmp r1, #0x47 - beq _080CDBA0 - b _080CDBA6 -_080CDB94: - movs r0, #0x7e - strb r0, [r2] - b _080CDBAE -_080CDB9A: - movs r0, #0x7f - strb r0, [r2] - b _080CDBAE -_080CDBA0: - movs r0, #0x37 - strb r0, [r2] - b _080CDBAE -_080CDBA6: - adds r0, r4, #0 - adds r0, #0x3b - strb r1, [r0] - adds r2, r0, #0 -_080CDBAE: - ldrb r0, [r2] - cmp r0, #0x1e - bgt _080CDBCA - cmp r0, #0x1d - blt _080CDBCA - ldr r0, [r5, #0xc] - movs r1, #0x80 - lsls r1, r1, #4 - ands r0, r1 - cmp r0, #0 - beq _080CDBCA - adds r0, r5, #0 - bl TryRemoveUnitFromBallista -_080CDBCA: - ldr r0, _080CDC04 @ gUnknown_03005360 - ldr r1, _080CDC08 @ 0x06001000 - movs r2, #0x80 - movs r3, #5 - bl Font_InitForUI - ldr r0, _080CDC0C @ gUnknown_02022DBA - movs r1, #0xa - movs r2, #6 - movs r3, #0 - bl TileMap_FillRect - movs r0, #1 - bl BG_EnableSyncByMask - ldr r0, _080CDC10 @ gUnknown_08B12930 - movs r1, #0 - str r1, [sp] - str r7, [sp, #4] - movs r1, #2 - movs r2, #0 - movs r3, #0 - bl StartMenuExt -_080CDBFA: - movs r0, #0 - add sp, #8 - pop {r4, r5, r6, r7} - pop {r1} - bx r1 - .align 2, 0 -_080CDC04: .4byte gUnknown_03005360 -_080CDC08: .4byte 0x06001000 -_080CDC0C: .4byte gUnknown_02022DBA -_080CDC10: .4byte gUnknown_08B12930 - - THUMB_FUNC_END PromotionCommand_OnSelect - - THUMB_FUNC_START sub_80CDC14 -sub_80CDC14: @ 0x080CDC14 - push {r4, lr} - ldr r1, [r0, #0x14] - ldr r4, [r1, #0x14] - ldr r0, [r4, #0x14] - ldr r0, [r0, #0x14] - adds r0, #0x31 - ldrb r0, [r0] - cmp r0, #0 - beq _080CDC2E - cmp r0, #1 - beq _080CDC32 - cmp r0, #2 - beq _080CDC32 -_080CDC2E: - movs r0, #0 - b _080CDC42 -_080CDC32: - adds r0, r1, #0 - bl Proc_End - adds r0, r4, #0 - movs r1, #2 - bl Proc_Goto - movs r0, #0xb -_080CDC42: - pop {r4} - pop {r1} - bx r1 - - THUMB_FUNC_END sub_80CDC14 - - THUMB_FUNC_START sub_80CDC48 -sub_80CDC48: @ 0x080CDC48 - push {r4, r5, r6, r7, lr} - sub sp, #0x20 - adds r7, r0, #0 - adds r5, r1, #0 - adds r6, r2, #0 - ldr r1, [r5, #0x30] - ldrb r0, [r1, #8] - cmp r0, #0 - beq _080CDC64 - adds r0, r5, #0 - adds r0, #0x34 - ldrb r1, [r1, #8] - bl Text_SetColorId -_080CDC64: - adds r0, r5, #0 - adds r0, #0x3d - ldrb r0, [r0] - adds r4, r5, #0 - adds r4, #0x34 - cmp r0, #2 - bne _080CDC7A - adds r0, r4, #0 - movs r1, #1 - bl Text_SetColorId -_080CDC7A: - adds r0, r4, #0 - movs r1, #0 - movs r2, #0x14 - bl sub_8003E00 - adds r0, r4, #0 - movs r1, #8 - bl Text_SetXCursor - adds r0, r4, #0 - adds r1, r6, #0 - bl Text_AppendString - adds r0, r7, #0 - adds r0, #0x64 - ldrb r0, [r0] - lsls r0, r0, #0x1c - lsrs r0, r0, #0x1e - bl BG_GetMapBuffer - adds r1, r0, #0 - movs r2, #0x2c - ldrsh r0, [r5, r2] - lsls r0, r0, #5 - movs r3, #0x2a - ldrsh r2, [r5, r3] - adds r0, r0, r2 - lsls r0, r0, #1 - adds r1, r1, r0 - adds r0, r4, #0 - bl Text_Draw - add sp, #0x20 - pop {r4, r5, r6, r7} - pop {r0} - bx r0 - - THUMB_FUNC_END sub_80CDC48 - - THUMB_FUNC_START PromotionCommand_OnTextDraw -PromotionCommand_OnTextDraw: @ 0x080CDCC4 - push {r4, r5, lr} - sub sp, #0x48 - adds r4, r0, #0 - adds r5, r1, #0 - ldr r0, [r4, #0x14] - ldr r1, [r0, #0x14] - adds r0, r5, #0 - adds r0, #0x3c - ldrb r0, [r0] - lsls r0, r0, #0x18 - asrs r0, r0, #0x18 - lsls r0, r0, #1 - adds r1, #0x2c - adds r1, r1, r0 - ldrh r0, [r1] - bl GetClassData - ldrh r0, [r0] - bl GetStringFromIndex - adds r2, r0, #0 - adds r0, r4, #0 - adds r1, r5, #0 - bl sub_80CDC48 - add sp, #0x48 - pop {r4, r5} - pop {r1} - bx r1 - - THUMB_FUNC_END PromotionCommand_OnTextDraw - - THUMB_FUNC_START PromotionCommand_OnChange -PromotionCommand_OnChange: @ 0x080CDD00 - push {lr} - ldr r0, [r0, #0x14] - ldr r3, [r0, #0x14] - adds r2, r3, #0 - adds r2, #0x40 - movs r0, #1 - strb r0, [r2] - adds r1, #0x3c - ldrb r0, [r1] - adds r1, r3, #0 - adds r1, #0x41 - strb r0, [r1] - ldrb r1, [r1] - lsls r1, r1, #1 - adds r0, r3, #0 - adds r0, #0x38 - adds r0, r0, r1 - movs r1, #0 - ldrsh r0, [r0, r1] - bl ChangeClassDescription - movs r0, #1 - negs r0, r0 - bl sub_8006AF0 - pop {r1} - bx r1 - - THUMB_FUNC_END PromotionCommand_OnChange - - THUMB_FUNC_START Usability_ThirdPromotionOption -Usability_ThirdPromotionOption: @ 0x080CDD38 - push {r4, lr} - ldr r0, _080CDD6C @ gUnknown_08B12A08 - bl Proc_Find - ldr r0, [r0, #0x14] - ldr r4, [r0, #0x14] - bl sub_80CCCA4 - lsls r0, r0, #0x18 - cmp r0, #0 - beq _080CDD70 - adds r0, r4, #0 - adds r0, #0x38 - ldrb r0, [r0] - bl GetUnitFromCharId - ldr r0, [r0, #4] - ldrb r0, [r0, #4] - cmp r0, #0x3d - blt _080CDD70 - cmp r0, #0x3e - ble _080CDD68 - cmp r0, #0x47 - bne _080CDD70 -_080CDD68: - movs r0, #1 - b _080CDD72 - .align 2, 0 -_080CDD6C: .4byte gUnknown_08B12A08 -_080CDD70: - movs r0, #3 -_080CDD72: - pop {r4} - pop {r1} - bx r1 - - THUMB_FUNC_END Usability_ThirdPromotionOption - - THUMB_FUNC_START BuildPromotionMenu -BuildPromotionMenu: @ 0x080CDD78 - push {r4, r5, r6, lr} - sub sp, #0xc - adds r6, r0, #0 - adds r0, #0x4c - movs r5, #0 - strb r5, [r0] - bl sub_8003D20 - bl Font_InitForUIDefault - movs r0, #0 - bl SetFontGlyphSet - ldr r4, _080CDDC4 @ gUnknown_03005380 - ldr r1, _080CDDC8 @ 0x06001400 - adds r0, r4, #0 - movs r2, #0xa0 - movs r3, #5 - bl Font_InitForUI - adds r0, r4, #0 - bl SetFont - ldr r0, _080CDDCC @ gUnknown_08B129E4 - ldr r1, _080CDDD0 @ gUnknown_08B12A60 - ldr r1, [r1] - str r5, [sp] - str r5, [sp, #4] - str r6, [sp, #8] - movs r2, #2 - movs r3, #0 - bl StartMenuCore - str r0, [r6, #0x50] - add sp, #0xc - pop {r4, r5, r6} - pop {r0} - bx r0 - .align 2, 0 -_080CDDC4: .4byte gUnknown_03005380 -_080CDDC8: .4byte 0x06001400 -_080CDDCC: .4byte gUnknown_08B129E4 -_080CDDD0: .4byte gUnknown_08B12A60 - - THUMB_FUNC_END BuildPromotionMenu - - THUMB_FUNC_START sub_80CDDD4 -sub_80CDDD4: @ 0x080CDDD4 - bx lr - - THUMB_FUNC_END sub_80CDDD4 - - THUMB_FUNC_START nullsub_61 -nullsub_61: @ 0x080CDDD8 - bx lr - - THUMB_FUNC_END nullsub_61 - - THUMB_FUNC_START Make6C_PromotionMenuSelect -Make6C_PromotionMenuSelect: @ 0x080CDDDC - push {lr} - adds r1, r0, #0 - ldr r0, _080CDDEC @ gUnknown_08B12A08 - bl Proc_Start - pop {r1} - bx r1 - .align 2, 0 -_080CDDEC: .4byte gUnknown_08B12A08 - - THUMB_FUNC_END Make6C_PromotionMenuSelect diff --git a/include/fontgrp.h b/include/fontgrp.h index 7297c27a..77ce2952 100644 --- a/include/fontgrp.h +++ b/include/fontgrp.h @@ -88,7 +88,7 @@ void Text_Init(struct TextHandle *a, int tileWidth); void Text_Allocate(struct TextHandle *th, int tileWidth); void InitTextBatch(const struct TextBatch* a); void Text_Clear(struct TextHandle* a); -// ??? sub_8003E00(???); +void sub_8003E00(struct TextHandle *th, int b, int c); // ??? sub_8003E40(???); // ??? Text_GetXCursor(???); void Text_SetXCursor(struct TextHandle *th, int x); diff --git a/ldscript.txt b/ldscript.txt index ec0aa5ab..38ff102d 100644 --- a/ldscript.txt +++ b/ldscript.txt @@ -132,7 +132,6 @@ SECTIONS src/statscreen.o(.text); asm/code.o(.text); src/branched_promotion.o(.text); - asm/branched_promotion.o(.text); asm/code_80CCA64.o(.text); asm/m4a_1.o(.text); src/m4a.o(.text); diff --git a/src/branched_promotion.c b/src/branched_promotion.c index 322a8e60..765261e7 100644 --- a/src/branched_promotion.c +++ b/src/branched_promotion.c @@ -2,6 +2,7 @@ #include "anime.h" #include "ap.h" +#include "bmarch.h" #include "bmbattle.h" #include "bmio.h" #include "bmitem.h" @@ -31,6 +32,10 @@ struct PromoProc struct Unit *u38; s32 u3c; u32 u40; + u32 _u44; + u32 _u48; + u8 u4c; + struct MenuProc* u50; }; extern const struct ProcCmd gUnknown_08B12614[]; @@ -399,7 +404,7 @@ struct PromoProc3 s8 _u2b; u16 u2c[3]; u16 u32[3]; - u16 u38[3]; + s16 u38[3]; u16 _u3e; u8 u40; u8 u41; @@ -1453,3 +1458,172 @@ u32 sub_80CDB28(struct MenuProc *proc) { SyncMenuBgs(proc); return 0; } + +extern struct Font gUnknown_03005360; +extern u16 gUnknown_02022DBA[]; +extern struct MenuDef gUnknown_08B12930; +u32 PromotionCommand_OnSelect(struct MenuItemProc *proc, struct MenuItemProc *proc2) { + struct Proc *parent; + struct PromoProc3 *gparent; + struct PromoProc2 *ggparent; + parent = proc->proc_parent; + gparent = parent->proc_parent; + ggparent = gparent->proc_parent; + if (gparent->u40 == 0) { + struct Unit *unit = GetUnitFromCharId(ggparent->u38); + u8 classnumber = unit->pClassData->number; + if (proc2->itemNumber <= 1) { + classnumber = gUnknown_0895DFA4[classnumber][proc2->itemNumber]; + ggparent->u3b = classnumber; + } else { + if (proc2->itemNumber == 2) { + switch (classnumber) { + case 0x3d: + ggparent->u3b = 0x7e; + break; + case 0x3e: + ggparent->u3b = 0x7f; + break; + case 0x47: + ggparent->u3b = 0x37; + break; + default: + ggparent->u3b = classnumber; + break; + } + } + } + switch ((u8) ggparent->u3b) { + case 0x1e: + case 0x1d: + if (unit->state & 0x800) { + TryRemoveUnitFromBallista(unit); + } + break; + } + Font_InitForUI(&gUnknown_03005360, (void *) 0x06001000, 0x80, 0x5); + TileMap_FillRect(gUnknown_02022DBA, 0xa, 0x6, 0); + BG_EnableSyncByMask(1); + StartMenuExt(&gUnknown_08B12930, 2, 0, 0, 0, (struct Proc *) proc); + } + return 0; +} + +u32 sub_80CDC14(struct Proc *proc) { + struct Proc *parent; + struct Proc *gparent; + struct Proc *ggparent; + struct PromoProc *gggparent; + parent = proc->proc_parent; + gparent = parent->proc_parent; + ggparent = gparent->proc_parent; + gggparent = ggparent->proc_parent; + if (gggparent->u31 == 0) { + return 0; + } else { + if (gggparent->u31 == 1) { + Proc_End(parent); + Proc_Goto(gparent, 2); + return 11; + } + if (gggparent->u31 == 2) { + Proc_End(parent); + Proc_Goto(gparent, 2); + return 11; + } + return 0; + } +} + +void sub_80CDC48(struct MenuProc *a, struct MenuItemProc *b, char *c) { + u8 unused_stack[32]; + u16 *mapbuf; + if (b->def->color) { + Text_SetColorId(&b->text, b->def->color); + } + if (b->availability == 2) { + Text_SetColorId(&b->text, 1); + } + sub_8003E00(&b->text, 0, 20); + Text_SetXCursor(&b->text, 8); + Text_AppendString(&b->text, c); + mapbuf = BG_GetMapBuffer(a->frontBg); + + Text_Draw(&b->text, &mapbuf[b->yTile * 32 + b->xTile]); +} + +u32 PromotionCommand_OnTextDraw(struct MenuProc *a, struct MenuItemProc *b) { + u8 unused_stack[0x48]; + struct Proc *parent; + struct PromoProc3 *gparent; + const struct ClassData *class_data; + char *string; + parent = a->proc_parent; + gparent = parent->proc_parent; + class_data = GetClassData(gparent->u2c[b->itemNumber]); + string = GetStringFromIndex(class_data->nameTextId); + sub_80CDC48(a, b, string); +} + +u32 PromotionCommand_OnChange(struct MenuProc *a, struct MenuItemProc *b) { + struct Proc *parent; + struct PromoProc3 *gparent; + const struct ClassData *class_data; + const char *string; + parent = a->proc_parent; + gparent = parent->proc_parent; + gparent->u40 = 1; + gparent->u41 = b->itemNumber; + ChangeClassDescription(gparent->u38[gparent->u41]); + sub_8006AF0(-1); +} + +extern struct ProcCmd gUnknown_08B12A08[]; +u32 Usability_ThirdPromotionOption(void) { + struct Proc *proc = Proc_Find(gUnknown_08B12A08); + struct Proc *parent = proc->proc_parent; + struct PromoProc2 *gparent = parent->proc_parent; + const struct ClassData *class_data; + const char *string; + if (sub_80CCCA4()) { + struct Unit *unit = GetUnitFromCharId(gparent->u38); + switch (unit->pClassData->number) { + case 0x3d: + case 0x3e: + case 0x47: + return 1; + default: + return 3; + } + } else { + return 3; + } +} + +extern struct MenuDef gUnknown_08B129E4; +extern struct MenuRect gUnknown_08B12A60; + +void BuildPromotionMenu(struct PromoProc *proc) { + proc->u4c = 0; + sub_8003D20(); + Font_InitForUIDefault(); + SetFontGlyphSet(0); + Font_InitForUI(&gUnknown_03005380, (void *) 0x06001400, 160, 5); + SetFont(&gUnknown_03005380); + proc->u50 = StartMenuCore( + &gUnknown_08B129E4, + gUnknown_08B12A60, + 2, + 0, + 0, + 0, + (struct Proc *) proc); +} + +void sub_80CDDD4(void) {} + +void nullsub_61(void) {} + +ProcPtr Make6C_PromotionMenuSelect(ProcPtr parent) { + return Proc_Start(gUnknown_08B12A08, parent); +}