From 071b256822292716b8adb042c8b0f712ea0cd8bf Mon Sep 17 00:00:00 2001 From: Zhengwen Jiang Date: Wed, 7 Aug 2024 01:26:06 -0500 Subject: [PATCH] more intro --- asm/intro.s | 793 ------------------------------------------------ include/intro.h | 31 +- src/intro.c | 184 ++++++++++- 3 files changed, 201 insertions(+), 807 deletions(-) diff --git a/asm/intro.s b/asm/intro.s index 6757591..a034fb7 100644 --- a/asm/intro.s +++ b/asm/intro.s @@ -5,799 +5,6 @@ .text - thumb_func_start sub_0814682C -sub_0814682C: @ 0x0814682C - push {r4, r5, r6, r7, lr} - mov r7, sl - mov r6, sb - mov r5, r8 - push {r5, r6, r7} - sub sp, #4 - adds r5, r0, #0 - adds r4, r1, #0 - movs r0, #0 - str r0, [sp] - ldr r1, _0814694C @ =0x000013EC - adds r0, r5, r1 - ldr r3, [r0] - cmp r3, #0 - beq _08146872 - ldr r6, _08146950 @ =0x0000FFFF -_0814684C: - cmp r3, r4 - beq _0814686C - ldrh r0, [r3] - ldrh r2, [r4] - adds r1, r6, #0 - ands r1, r0 - adds r0, r6, #0 - ands r0, r2 - cmp r1, r0 - bne _0814686C - ldrb r0, [r4, #2] - cmp r0, #0 - beq _0814686C - ldrb r1, [r3, #2] - cmp r0, r1 - beq _08146964 -_0814686C: - ldr r3, [r3, #0x18] - cmp r3, #0 - bne _0814684C -_08146872: - ldr r3, [sp] - cmp r3, #0 - bne _0814688E - ldr r2, _08146954 @ =gUnk_08D62530 - ldrb r1, [r4] - lsls r0, r1, #1 - adds r0, r0, r1 - lsls r0, r0, #1 - adds r2, #4 - adds r0, r0, r2 - ldrh r0, [r0] - bl VramMalloc - str r0, [sp] -_0814688E: - ldr r0, _08146958 @ =0x000005CA - adds r1, r5, r0 - ldrb r0, [r1] - adds r0, #1 - strb r0, [r1] - movs r1, #0xb9 - lsls r1, r1, #3 - adds r2, r5, r1 - ldrb r1, [r2] - lsls r1, r1, #2 - movs r3, #0xa9 - lsls r3, r3, #3 - adds r0, r5, r3 - adds r0, r0, r1 - ldr r3, [r0] - adds r1, r3, #0 - subs r1, #0x48 - subs r1, r1, r5 - lsls r0, r1, #1 - adds r0, r0, r1 - lsls r1, r0, #4 - adds r0, r0, r1 - lsls r1, r0, #8 - adds r0, r0, r1 - lsls r1, r0, #0x10 - adds r0, r0, r1 - rsbs r0, r0, #0 - asrs r0, r0, #3 - strb r0, [r4, #3] - ldrb r0, [r2] - adds r0, #1 - movs r1, #0x1f - ands r0, r1 - strb r0, [r2] - ldr r1, _0814695C @ =gUnk_08387348 - ldrb r2, [r4] - lsls r0, r2, #4 - adds r0, r0, r1 - ldrb r0, [r0] - mov ip, r0 - movs r1, #0 - ldr r0, _08146954 @ =gUnk_08D62530 - mov r8, r0 - adds r6, r2, #0 - adds r7, r5, #0 - adds r7, #0x12 - mov sl, r6 - ldrb r0, [r4, #1] - mov sb, r0 - adds r2, r7, #0 -_081468F2: - adds r0, r2, r1 - ldrb r0, [r0] - cmp r0, ip - beq _08146960 - adds r0, r1, #1 - lsls r0, r0, #0x18 - lsrs r1, r0, #0x18 - cmp r1, #0xf - bls _081468F2 - ldrb r0, [r5, #0x11] - adds r0, #1 - strb r0, [r5, #0x11] - movs r1, #0 - adds r5, r7, #0 -_0814690E: - adds r0, r5, r1 - ldrb r0, [r0] - cmp r0, #0xff - beq _08146960 - adds r0, r1, #1 - lsls r0, r0, #0x18 - lsrs r1, r0, #0x18 - cmp r1, #0xf - bls _0814690E - movs r0, #1 - rsbs r0, r0, #0 -_08146924: - lsls r0, r0, #0x18 - lsrs r1, r0, #0x18 - mov ip, r1 - asrs r0, r0, #0x18 - adds r0, r7, r0 - mov r1, sl - strb r1, [r0] - mov r1, sb - lsls r0, r1, #0x18 - cmp r0, #0 - bge _0814696A - lsls r0, r6, #1 - adds r0, r0, r6 - lsls r0, r0, #1 - mov r1, r8 - adds r1, #2 - adds r0, r0, r1 - ldrb r5, [r0] - b _08146982 - .align 2, 0 -_0814694C: .4byte 0x000013EC -_08146950: .4byte 0x0000FFFF -_08146954: .4byte gUnk_08D62530 -_08146958: .4byte 0x000005CA -_0814695C: .4byte gUnk_08387348 -_08146960: - adds r0, r1, #0 - b _08146924 -_08146964: - ldrb r0, [r3, #3] - strb r0, [r4, #3] - b _081469C4 -_0814696A: - ldrb r5, [r4, #1] - lsls r0, r6, #1 - adds r0, r0, r6 - lsls r0, r0, #1 - mov r1, r8 - adds r1, #2 - adds r0, r0, r1 - ldrh r0, [r0] - cmp r5, r0 - bne _08146982 - movs r0, #0xff - strb r0, [r4, #1] -_08146982: - ldr r0, [sp] - str r0, [r3] - ldrb r0, [r4, #5] - lsls r0, r0, #6 - movs r2, #0 - strh r0, [r3, #0x14] - ldrb r1, [r4] - lsls r0, r1, #1 - adds r0, r0, r1 - lsls r0, r0, #1 - add r0, r8 - ldrh r0, [r0] - strh r0, [r3, #0xc] - strb r5, [r3, #0x1a] - strh r2, [r3, #0x16] - movs r0, #0xff - strb r0, [r3, #0x1b] - ldrb r0, [r4, #6] - strb r0, [r3, #0x1c] - mov r1, ip - strb r1, [r3, #0x1f] - ldrh r0, [r4, #0xa] - lsls r0, r0, #0x10 - asrs r0, r0, #0x16 - strh r0, [r3, #0x10] - ldrh r0, [r4, #0xc] - lsls r0, r0, #0x10 - asrs r0, r0, #0x16 - strh r0, [r3, #0x12] - str r2, [r3, #8] - adds r0, r3, #0 - bl sub_08155128 -_081469C4: - add sp, #4 - pop {r3, r4, r5} - mov r8, r3 - mov sb, r4 - mov sl, r5 - pop {r4, r5, r6, r7} - pop {r0} - bx r0 - - thumb_func_start sub_081469D4 -sub_081469D4: @ 0x081469D4 - push {r4, r5, r6, r7, lr} - mov r7, sb - mov r6, r8 - push {r6, r7} - sub sp, #0x28 - adds r3, r0, #0 - adds r5, r1, #0 - ldr r0, _08146A48 @ =0x000005CA - adds r1, r3, r0 - ldrb r0, [r1] - adds r0, #1 - strb r0, [r1] - movs r1, #0xb9 - lsls r1, r1, #3 - adds r2, r3, r1 - ldrb r1, [r2] - lsls r1, r1, #2 - movs r4, #0xa9 - lsls r4, r4, #3 - adds r0, r3, r4 - adds r0, r0, r1 - ldr r6, [r0] - adds r1, r6, #0 - subs r1, #0x48 - subs r1, r1, r3 - lsls r0, r1, #1 - adds r0, r0, r1 - lsls r1, r0, #4 - adds r0, r0, r1 - lsls r1, r0, #8 - adds r0, r0, r1 - lsls r1, r0, #0x10 - adds r0, r0, r1 - rsbs r0, r0, #0 - asrs r0, r0, #3 - strb r0, [r5, #3] - ldrb r0, [r2] - adds r0, #1 - movs r1, #0x1f - ands r0, r1 - strb r0, [r2] - ldr r1, _08146A4C @ =gUnk_08387348 - ldrb r0, [r5] - lsls r0, r0, #4 - adds r0, r0, r1 - ldrb r4, [r0] - movs r1, #0 - adds r7, r3, #0 - adds r7, #0x12 - adds r2, r7, #0 -_08146A38: - adds r0, r2, r1 - ldrb r0, [r0] - cmp r0, r4 - bne _08146A50 - adds r0, r1, #0 - ldrb r2, [r5] - b _08146A80 - .align 2, 0 -_08146A48: .4byte 0x000005CA -_08146A4C: .4byte gUnk_08387348 -_08146A50: - adds r0, r1, #1 - lsls r0, r0, #0x18 - lsrs r1, r0, #0x18 - cmp r1, #0xf - bls _08146A38 - ldrb r0, [r3, #0x11] - adds r0, #1 - strb r0, [r3, #0x11] - movs r1, #0 - ldrb r2, [r5] - adds r3, r7, #0 -_08146A66: - adds r0, r3, r1 - ldrb r0, [r0] - cmp r0, #0xff - bne _08146A72 - adds r0, r1, #0 - b _08146A80 -_08146A72: - adds r0, r1, #1 - lsls r0, r0, #0x18 - lsrs r1, r0, #0x18 - cmp r1, #0xf - bls _08146A66 - movs r0, #1 - rsbs r0, r0, #0 -_08146A80: - lsls r0, r0, #0x18 - lsrs r3, r0, #0x18 - mov sb, r3 - lsls r0, r3, #0x18 - asrs r0, r0, #0x18 - adds r0, r7, r0 - movs r7, #0 - strb r2, [r0] - movs r0, #0x80 - lsls r0, r0, #3 - mov r8, r0 - cmp r2, #1 - beq _08146AEA - str r7, [sp] - mov r1, sp - movs r0, #0xff - lsls r0, r0, #6 - strh r0, [r1, #0x14] - mov r2, sp - ldr r1, _08146B5C @ =gUnk_08D626E0 - ldrb r0, [r5] - subs r0, #1 - lsls r0, r0, #2 - adds r0, r0, r1 - ldrh r0, [r0] - strh r0, [r2, #0xc] - ldrb r0, [r5] - subs r0, #1 - lsls r0, r0, #2 - adds r1, #2 - adds r0, r0, r1 - ldrh r0, [r0] - strb r0, [r2, #0x1a] - mov r0, sp - strh r7, [r0, #0x16] - mov r1, sp - movs r0, #0xff - strb r0, [r1, #0x1b] - movs r0, #0x10 - strb r0, [r1, #0x1c] - mov r0, sp - strb r3, [r0, #0x1f] - ldr r1, _08146B60 @ =0x0000FFC0 - strh r1, [r0, #0x10] - strh r1, [r0, #0x12] - str r7, [sp, #8] - bl sub_08155128 - movs r0, #0x80 - lsls r0, r0, #0xb - mov r1, r8 - orrs r1, r0 - mov r8, r1 -_08146AEA: - ldr r4, _08146B64 @ =gUnk_08D62530 - ldrb r1, [r5] - lsls r0, r1, #1 - adds r0, r0, r1 - lsls r0, r0, #1 - adds r1, r4, #4 - adds r0, r0, r1 - ldrh r0, [r0] - bl VramMalloc - str r0, [r6] - ldrb r0, [r5, #5] - lsls r0, r0, #6 - strh r0, [r6, #0x14] - ldrb r1, [r5] - lsls r0, r1, #1 - adds r0, r0, r1 - lsls r0, r0, #1 - adds r0, r0, r4 - ldrh r0, [r0] - strh r0, [r6, #0xc] - ldrb r1, [r5] - lsls r0, r1, #1 - adds r0, r0, r1 - lsls r0, r0, #1 - adds r4, #2 - adds r0, r0, r4 - ldrh r0, [r0] - strb r0, [r6, #0x1a] - strh r7, [r6, #0x16] - movs r0, #0xff - strb r0, [r6, #0x1b] - ldrb r0, [r5, #6] - strb r0, [r6, #0x1c] - mov r4, sb - strb r4, [r6, #0x1f] - ldrh r0, [r5, #0xa] - lsls r0, r0, #0x10 - asrs r0, r0, #0x16 - strh r0, [r6, #0x10] - ldrh r0, [r5, #0xc] - lsls r0, r0, #0x10 - asrs r0, r0, #0x16 - strh r0, [r6, #0x12] - mov r0, r8 - str r0, [r6, #8] - adds r0, r6, #0 - bl sub_08155128 - add sp, #0x28 - pop {r3, r4} - mov r8, r3 - mov sb, r4 - pop {r4, r5, r6, r7} - pop {r0} - bx r0 - .align 2, 0 -_08146B5C: .4byte gUnk_08D626E0 -_08146B60: .4byte 0x0000FFC0 -_08146B64: .4byte gUnk_08D62530 - - thumb_func_start sub_08146B68 -sub_08146B68: @ 0x08146B68 - push {r4, r5, r6, lr} - adds r3, r0, #0 - ldr r6, [r3, #0x20] - movs r5, #0 - strb r5, [r3] - ldr r0, _08146B88 @ =0x000013EC - adds r2, r6, r0 - ldr r1, _08146B8C @ =0x000013F0 - adds r0, r6, r1 - ldr r1, [r2] - ldr r4, [r0] - cmp r1, r4 - bne _08146B90 - str r5, [r0] - str r5, [r2] - b _08146BB4 - .align 2, 0 -_08146B88: .4byte 0x000013EC -_08146B8C: .4byte 0x000013F0 -_08146B90: - cmp r3, r1 - bne _08146B9A - ldr r1, [r3, #0x18] - str r1, [r2] - b _08146BB0 -_08146B9A: - cmp r3, r4 - bne _08146BA8 - ldr r1, [r3, #0x14] - str r1, [r0] - ldr r0, [r3, #0x18] - str r0, [r1, #0x18] - b _08146BB4 -_08146BA8: - ldr r1, [r3, #0x14] - ldr r0, [r3, #0x18] - str r0, [r1, #0x18] - ldr r1, [r3, #0x18] -_08146BB0: - ldr r0, [r3, #0x14] - str r0, [r1, #0x14] -_08146BB4: - ldr r4, _08146BE0 @ =0x000013F5 - adds r2, r6, r4 - ldrb r1, [r2] - lsls r1, r1, #2 - ldr r4, _08146BE4 @ =0x000012EC - adds r0, r6, r4 - adds r0, r0, r1 - str r3, [r0] - ldrb r0, [r2] - adds r0, #1 - movs r1, #0x3f - ands r0, r1 - strb r0, [r2] - ldr r0, _08146BE8 @ =0x000013F6 - adds r1, r6, r0 - ldrb r0, [r1] - subs r0, #1 - strb r0, [r1] - pop {r4, r5, r6} - pop {r0} - bx r0 - .align 2, 0 -_08146BE0: .4byte 0x000013F5 -_08146BE4: .4byte 0x000012EC -_08146BE8: .4byte 0x000013F6 - - thumb_func_start sub_08146BEC -sub_08146BEC: @ 0x08146BEC - push {r4, r5, lr} - adds r3, r0, #0 - ldr r4, [r3, #0x20] - movs r0, #3 - ldrsb r0, [r3, r0] - lsls r1, r0, #2 - adds r1, r1, r0 - lsls r1, r1, #3 - adds r1, #0x48 - adds r5, r4, r1 - ldr r1, _08146C20 @ =0x000013EC - adds r0, r4, r1 - ldr r2, [r0] - cmp r2, #0 - beq _08146C2A -_08146C0A: - cmp r2, r3 - beq _08146C24 - movs r1, #3 - ldrsb r1, [r2, r1] - movs r0, #3 - ldrsb r0, [r3, r0] - cmp r1, r0 - bne _08146C24 - movs r0, #0 - b _08146C50 - .align 2, 0 -_08146C20: .4byte 0x000013EC -_08146C24: - ldr r2, [r2, #0x18] - cmp r2, #0 - bne _08146C0A -_08146C2A: - ldr r3, _08146C58 @ =0x000005C9 - adds r2, r4, r3 - ldrb r1, [r2] - lsls r1, r1, #2 - subs r3, #0x81 - adds r0, r4, r3 - adds r0, r0, r1 - str r5, [r0] - ldrb r0, [r2] - adds r0, #1 - movs r1, #0x1f - ands r0, r1 - strb r0, [r2] - ldr r0, _08146C5C @ =0x000005CA - adds r1, r4, r0 - ldrb r0, [r1] - subs r0, #1 - strb r0, [r1] - adds r0, r5, #0 -_08146C50: - pop {r4, r5} - pop {r1} - bx r1 - .align 2, 0 -_08146C58: .4byte 0x000005C9 -_08146C5C: .4byte 0x000005CA - - thumb_func_start sub_08146C60 -sub_08146C60: @ 0x08146C60 - push {r4, r5, r6, r7, lr} - mov r7, r8 - push {r7} - adds r5, r0, #0 - ldr r1, _08146CD4 @ =0x00001414 - adds r0, r5, r1 - ldrb r1, [r0] - ldr r2, _08146CD8 @ =0x00001415 - adds r0, r5, r2 - ldrb r2, [r0] - ldr r3, _08146CDC @ =0x000013EC - adds r0, r5, r3 - ldr r4, [r0] - cmp r4, #0 - beq _08146CCA - lsls r0, r1, #0x18 - asrs r7, r0, #0x18 - ldr r0, _08146CE0 @ =gUnk_08387348 - mov r8, r0 - lsls r0, r2, #0x18 - asrs r6, r0, #0x18 -_08146C8A: - movs r0, #3 - ldrsb r0, [r4, r0] - cmp r0, #0 - blt _08146CC4 - adds r1, r0, #0 - lsls r0, r1, #2 - adds r0, r0, r1 - lsls r0, r0, #3 - adds r0, #0x48 - adds r0, r5, r0 - ldrh r1, [r4, #0xa] - lsls r1, r1, #0x10 - asrs r1, r1, #0x16 - subs r1, r1, r7 - strh r1, [r0, #0x10] - ldrh r2, [r4, #0xc] - lsls r2, r2, #0x10 - asrs r2, r2, #0x16 - ldrb r1, [r4] - lsls r1, r1, #4 - add r1, r8 - ldrb r1, [r1, #1] - lsls r1, r1, #0x18 - asrs r1, r1, #0x18 - subs r2, r2, r1 - subs r2, r2, r6 - strh r2, [r0, #0x12] - bl sub_0815604C -_08146CC4: - ldr r4, [r4, #0x18] - cmp r4, #0 - bne _08146C8A -_08146CCA: - pop {r3} - mov r8, r3 - pop {r4, r5, r6, r7} - pop {r0} - bx r0 - .align 2, 0 -_08146CD4: .4byte 0x00001414 -_08146CD8: .4byte 0x00001415 -_08146CDC: .4byte 0x000013EC -_08146CE0: .4byte gUnk_08387348 - - thumb_func_start sub_08146CE4 -sub_08146CE4: @ 0x08146CE4 - push {r4, r5, r6, lr} - adds r4, r0, #0 - ldrh r0, [r4, #0xe] - ldrh r2, [r4, #0xa] - adds r1, r0, r2 - strh r1, [r4, #0xa] - ldrh r0, [r4, #0x10] - ldrh r2, [r4, #0xc] - adds r0, r0, r2 - strh r0, [r4, #0xc] - ldrb r0, [r4] - cmp r0, #0 - beq _08146D38 - lsls r1, r1, #0x10 - asrs r1, r1, #0x16 - ldr r2, _08146D78 @ =gUnk_08387348 - lsls r0, r0, #4 - adds r0, r0, r2 - ldrb r0, [r0, #2] - lsrs r0, r0, #1 - adds r1, r1, r0 - cmp r1, #0 - bgt _08146D38 - adds r0, r4, #0 - bl sub_08146B68 - adds r0, r4, #0 - bl sub_08146BEC - adds r5, r0, #0 - cmp r5, #0 - beq _08146D38 - adds r0, r4, #0 - adds r1, r5, #0 - bl sub_081497B4 - cmp r0, #0 - beq _08146D38 - adds r0, r4, #0 - adds r1, r5, #0 - bl sub_08149814 -_08146D38: - ldr r6, [r4, #0x20] - ldrb r5, [r4, #3] - lsls r0, r5, #2 - adds r0, r0, r5 - lsls r0, r0, #3 - adds r0, #0x48 - adds r4, r6, r0 - ldr r1, _08146D7C @ =0x000005CC - adds r0, r6, r1 - adds r0, r0, r5 - ldrb r0, [r0] - cmp r0, #1 - beq _08146D70 - ldr r0, [r4] - cmp r0, #0 - beq _08146D66 - adds r0, r4, #0 - bl sub_08155128 - cmp r0, #0 - bne _08146D66 - movs r0, #0xff - strb r0, [r4, #0x1b] -_08146D66: - ldr r2, _08146D7C @ =0x000005CC - adds r0, r6, r2 - adds r0, r0, r5 - movs r1, #1 - strb r1, [r0] -_08146D70: - pop {r4, r5, r6} - pop {r0} - bx r0 - .align 2, 0 -_08146D78: .4byte gUnk_08387348 -_08146D7C: .4byte 0x000005CC - - thumb_func_start sub_08146D80 -sub_08146D80: @ 0x08146D80 - push {r4, r5, r6, lr} - adds r4, r0, #0 - adds r2, r4, #0 - adds r2, #0x24 - ldrh r0, [r2, #4] - adds r0, #1 - strh r0, [r2, #4] - lsls r0, r0, #0x10 - asrs r0, r0, #0x10 - movs r3, #2 - ldrsh r1, [r2, r3] - cmp r0, r1 - blt _08146DA4 - movs r0, #0 - strh r0, [r2, #4] - ldrh r0, [r4, #0x24] - bl m4aSongNumStart -_08146DA4: - ldrh r0, [r4, #0xe] - ldrh r2, [r4, #0xa] - adds r1, r0, r2 - strh r1, [r4, #0xa] - ldrh r0, [r4, #0x10] - ldrh r3, [r4, #0xc] - adds r0, r0, r3 - strh r0, [r4, #0xc] - ldrb r0, [r4] - cmp r0, #0 - beq _08146DF4 - lsls r1, r1, #0x10 - asrs r1, r1, #0x16 - ldr r2, _08146E34 @ =gUnk_08387348 - lsls r0, r0, #4 - adds r0, r0, r2 - ldrb r0, [r0, #2] - lsrs r0, r0, #1 - adds r1, r1, r0 - cmp r1, #0 - bgt _08146DF4 - adds r0, r4, #0 - bl sub_08146B68 - adds r0, r4, #0 - bl sub_08146BEC - adds r5, r0, #0 - cmp r5, #0 - beq _08146DF4 - adds r0, r4, #0 - adds r1, r5, #0 - bl sub_081497B4 - cmp r0, #0 - beq _08146DF4 - adds r0, r4, #0 - adds r1, r5, #0 - bl sub_08149814 -_08146DF4: - ldr r6, [r4, #0x20] - ldrb r5, [r4, #3] - lsls r0, r5, #2 - adds r0, r0, r5 - lsls r0, r0, #3 - adds r0, #0x48 - adds r4, r6, r0 - ldr r1, _08146E38 @ =0x000005CC - adds r0, r6, r1 - adds r0, r0, r5 - ldrb r0, [r0] - cmp r0, #1 - beq _08146E2C - ldr r0, [r4] - cmp r0, #0 - beq _08146E22 - adds r0, r4, #0 - bl sub_08155128 - cmp r0, #0 - bne _08146E22 - movs r0, #0xff - strb r0, [r4, #0x1b] -_08146E22: - ldr r2, _08146E38 @ =0x000005CC - adds r0, r6, r2 - adds r0, r0, r5 - movs r1, #1 - strb r1, [r0] -_08146E2C: - pop {r4, r5, r6} - pop {r0} - bx r0 - .align 2, 0 -_08146E34: .4byte gUnk_08387348 -_08146E38: .4byte 0x000005CC - thumb_func_start sub_08146E3C sub_08146E3C: @ 0x08146E3C push {r4, r5, r6, lr} diff --git a/include/intro.h b/include/intro.h index 86bf75a..85fa7ec 100644 --- a/include/intro.h +++ b/include/intro.h @@ -24,24 +24,25 @@ struct Unk_08145B64; struct Unk_08145B64_5EC { u8 unk0; - u8 unk1; + s8 unk1; u8 unk2; - u8 unk3; - u8 unk4; // index in Unk_08145B64::unk5EC + s8 unk3; // index in Unk_08145B64::unk48 + s8 unk4; // index in Unk_08145B64::unk5EC u8 unk5; u8 unk6; u8 unk7; u16 filler8; - u16 unkA; - u16 unkC; + s16 unkA; + s16 unkC; u16 unkE; u16 unk10; u16 filler12; struct Unk_08145B64_5EC *unk14; struct Unk_08145B64_5EC *unk18; - void (*unk1C)(struct Unk_08145B64 *); + void (*unk1C)(struct Unk_08145B64_5EC *); struct Unk_08145B64 *unk20; - u8 filler24[0x10]; + s16 unk24[3]; + u8 filler2A[0xA]; }; /* size = 0x34 */ struct Unk_08145B64 { @@ -60,7 +61,11 @@ struct Unk_08145B64 { u32 filler44; struct Sprite unk48[0x20]; struct Sprite *unk548[0x20]; - u8 filler5C8[0x24]; + u8 unk5C8; + u8 unk5C9; + u8 unk5CA; + u8 unk5CB; + u8 unk5CC[0x20]; struct Unk_08145B64_5EC unk5EC[0x40]; struct Unk_08145B64_5EC *unk12EC[0x40]; struct Unk_08145B64_5EC *unk13EC; @@ -76,8 +81,8 @@ struct Unk_08145B64 { u16 unk140C; s16 unk140E; void (*unk1410)(struct Unk_08145B64 *); - u8 unk1414; - u8 unk1415; + s8 unk1414; + s8 unk1415; u8 unk1416; u8 unk1417; u8 unk1418; @@ -86,11 +91,11 @@ struct Unk_08145B64 { struct Unk_08387348 { u8 unk0; - u8 unk1; + s8 unk1; u8 unk2; void (*unk4)(struct Unk_08145B64_5EC *, const struct Unk_08387814 *); - void (*unk8)(struct Unk_08145B64 *); - void (*const *unkC)(struct Unk_08145B64 *); + void (*unk8)(struct Unk_08145B64_5EC *); + void (*const *unkC)(struct Unk_08145B64_5EC *); }; /* size = 0x10 */ #endif diff --git a/src/intro.c b/src/intro.c index 3feb80c..0f99dd7 100644 --- a/src/intro.c +++ b/src/intro.c @@ -16,7 +16,7 @@ void sub_081464D4(struct Unk_08145B64 *, u8); void sub_0814669C(struct Unk_08145B64 *, const struct Unk_08387814 *); void sub_0814682C(struct Unk_08145B64 *, struct Unk_08145B64_5EC *); void sub_081469D4(struct Unk_08145B64 *, struct Unk_08145B64_5EC *); -void sub_08146CE4(struct Unk_08145B64 *); +void sub_08146CE4(struct Unk_08145B64_5EC *); bool32 sub_08148CD8(struct Unk_08145B64 *); void sub_081494E4(struct Unk_08145B64 *); void sub_08149628(struct Unk_08145B64 *); @@ -28,6 +28,8 @@ void sub_08149710(struct Unk_08145B64 *, u8); void sub_08149758(struct Unk_08145B64 *); void nullsub_134(struct Unk_08145B64 *); bool32 sub_081497B0(struct Unk_08145B64 *); +bool32 sub_081497B4(struct Unk_08145B64_5EC *, struct Sprite *); +bool32 sub_08149814(struct Unk_08145B64_5EC *, struct Sprite *); extern const struct Unk_08387348 gUnk_08387348[]; extern const u8 gUnk_083877A8[][8]; @@ -39,6 +41,7 @@ extern const struct Unk_08387814 gUnk_08387814[]; extern const u8 gUnk_08387D54; extern const u16 gUnk_08D62530[][3]; +extern const u16 gUnk_08D626E0[][2]; void sub_08145B64(u16 a1) { u8 i; @@ -373,3 +376,182 @@ void sub_0814669C(struct Unk_08145B64 *a1, const struct Unk_08387814 *a2) { sub_0814682C(a1, v4); } } + +static inline s8 sub_0814682C_helper(struct Unk_08145B64 *a1, u8 val) { + u8 i; + + for (i = 0; i < 0x10; ++i) { + if (a1->unk12[i] == val) + return i; + } + ++a1->unk11; + for (i = 0; i < 0x10; ++i) { + if (a1->unk12[i] == 0xFF) + return i; + } + return -1; +} + +void sub_0814682C(struct Unk_08145B64 *a1, struct Unk_08145B64_5EC *a2) { + u32 vram = 0; + struct Unk_08145B64_5EC *current; + struct Sprite *sprite; + s8 palId; + u8 variant; + + for (current = a1->unk13EC; current; current = current->unk18) { + if (current != a2 + && (current->unk0 == a2->unk0 && current->unk1 == a2->unk1) + && a2->unk2 + && a2->unk2 == current->unk2) { + a2->unk3 = current->unk3; + return; + } + } + if (vram == 0) // always TRUE + vram = VramMalloc(gUnk_08D62530[a2->unk0][2]); + ++a1->unk5CA; + sprite = a1->unk548[a1->unk5C8]; + a2->unk3 = (s32)(({(s32)sprite - offsetof(struct Unk_08145B64, unk48);}) - (s32)a1) * -0x33333333 >> 3; // divide by sizeof(struct Sprite) + a1->unk5C8 = (a1->unk5C8 + 1) & 0x1F; + palId = sub_0814682C_helper(a1, gUnk_08387348[a2->unk0].unk0); + a1->unk12[palId] = a2->unk0; + if (a2->unk1 < 0) + variant = gUnk_08D62530[a2->unk0][1]; + else { + variant = a2->unk1; + if (variant == gUnk_08D62530[a2->unk0][1]) + a2->unk1 = -1; + } + SpriteInitNoPointer2(sprite, vram, a2->unk5 * 0x40, gUnk_08D62530[a2->unk0][0], variant, 0, 0xFF, a2->unk6, palId, a2->unkA >> 6, a2->unkC >> 6, 0); +} + +void sub_081469D4(struct Unk_08145B64 *a1, struct Unk_08145B64_5EC *a2) { + struct Sprite *sprite; + s8 palId; + u32 unk8; + struct Sprite local; + + ++a1->unk5CA; + sprite = a1->unk548[a1->unk5C8]; + a2->unk3 = (s32)(({(s32)sprite - offsetof(struct Unk_08145B64, unk48);}) - (s32)a1) * -0x33333333 >> 3; // divide by sizeof(struct Sprite) + a1->unk5C8 = (a1->unk5C8 + 1) & 0x1F; + palId = sub_0814682C_helper(a1, gUnk_08387348[a2->unk0].unk0); + a1->unk12[palId] = a2->unk0; + unk8 = 0x400; + if (a2->unk0 != 1) { + SpriteInitNoPointer2(&local, 0, 0x3FC0, gUnk_08D626E0[a2->unk0 - 1][0], gUnk_08D626E0[a2->unk0 - 1][1], 0, 0xFF, 0x10, + palId, -0x40, -0x40, 0); + unk8 |= 0x40000; + } + SpriteInitNoPointer2(sprite, VramMalloc(gUnk_08D62530[a2->unk0][2]), a2->unk5 * 0x40, gUnk_08D62530[a2->unk0][0], gUnk_08D62530[a2->unk0][1], + 0, 0xFF, a2->unk6, palId, a2->unkA >> 6, a2->unkC >> 6, unk8); +} + +void sub_08146B68(struct Unk_08145B64_5EC *a1) { + struct Unk_08145B64 *v2 = a1->unk20; + + a1->unk0 = 0; + if (v2->unk13EC == v2->unk13F0) { + v2->unk13EC = v2->unk13F0 = NULL; + } else if (a1 == v2->unk13EC) { + v2->unk13EC = a1->unk18; + v2->unk13EC->unk14 = a1->unk14; + } else if (a1 == v2->unk13F0) { + v2->unk13F0 = a1->unk14; + v2->unk13F0->unk18 = a1->unk18; + } else { + a1->unk14->unk18 = a1->unk18; + a1->unk18->unk14 = a1->unk14; + } + v2->unk12EC[v2->unk13F5] = a1; + v2->unk13F5 = (v2->unk13F5 + 1) & 0x3F; + --v2->unk13F6; +} + +struct Sprite *sub_08146BEC(struct Unk_08145B64_5EC *a1) { + struct Unk_08145B64 *v1 = a1->unk20; + struct Sprite *sprite = &v1->unk48[a1->unk3]; + struct Unk_08145B64_5EC *current; + + for (current = v1->unk13EC; current; current = current->unk18) { + if (current != a1 && current->unk3 == a1->unk3) + return NULL; + } + v1->unk548[v1->unk5C9] = sprite; + v1->unk5C9 = (v1->unk5C9 + 1) & 0x1F; + --v1->unk5CA; + return sprite; +} + +void sub_08146C60(struct Unk_08145B64 *a1) { + struct Unk_08145B64_5EC *current; + s8 unk1414 = a1->unk1414, unk1415 = a1->unk1415; + + for (current = a1->unk13EC; current; current = current->unk18) { + if (current->unk3 >= 0) { + struct Sprite *sprite = &a1->unk48[current->unk3]; + + sprite->x = (current->unkA >> 6) - unk1414; + sprite->y = (current->unkC >> 6) - gUnk_08387348[current->unk0].unk1 - unk1415; + sub_0815604C(sprite); + } + } +} + +void sub_08146CE4(struct Unk_08145B64_5EC *a1) { + struct Sprite *sprite; + struct Unk_08145B64 *v5; + u8 unk3; + + a1->unkA += a1->unkE; + a1->unkC += a1->unk10; + if (a1->unk0 + && (a1->unkA >> 6) + (gUnk_08387348[a1->unk0].unk2 >> 1) <= 0) { + struct Sprite *sprite; + + sub_08146B68(a1); + sprite = sub_08146BEC(a1); + if (sprite && sub_081497B4(a1, sprite)) + sub_08149814(a1, sprite); + } + v5 = a1->unk20; + unk3 = a1->unk3; + sprite = &v5->unk48[unk3]; + if (v5->unk5CC[unk3] != 1) { + if (sprite->tilesVram && !sub_08155128(&v5->unk48[unk3])) + sprite->unk1B = 0xFF; + v5->unk5CC[unk3] = 1; + } +} + +void sub_08146D80(struct Unk_08145B64_5EC *a1) { + struct Sprite *sprite; + struct Unk_08145B64 *v5; + u8 unk3; + s16 *ptr = a1->unk24; + + if (++ptr[2] >= ptr[1]) { + ptr[2] = 0; + m4aSongNumStart(a1->unk24[0]); + } + a1->unkA += a1->unkE; + a1->unkC += a1->unk10; + if (a1->unk0 + && (a1->unkA >> 6) + (gUnk_08387348[a1->unk0].unk2 >> 1) <= 0) { + struct Sprite *sprite; + + sub_08146B68(a1); + sprite = sub_08146BEC(a1); + if (sprite && sub_081497B4(a1, sprite)) + sub_08149814(a1, sprite); + } + v5 = a1->unk20; + unk3 = a1->unk3; + sprite = &v5->unk48[unk3]; + if (v5->unk5CC[unk3] != 1) { + if (sprite->tilesVram && !sub_08155128(&v5->unk48[unk3])) + sprite->unk1B = 0xFF; + v5->unk5CC[unk3] = 1; + } +}