From a978a6a62400b2bfba7107b66077d21822759cff Mon Sep 17 00:00:00 2001 From: Marcus Huderle Date: Fri, 29 Mar 2019 21:22:51 -0500 Subject: [PATCH] Finish decompiling union_room_chat.c --- asm/union_room_chat.s | 1272 ----------------------------------------- include/graphics.h | 9 + include/menu.h | 1 + ld_script.txt | 1 - src/union_room_chat.c | 551 ++++++++++++++++-- 5 files changed, 511 insertions(+), 1323 deletions(-) delete mode 100755 asm/union_room_chat.s diff --git a/asm/union_room_chat.s b/asm/union_room_chat.s deleted file mode 100755 index 1bd768d44..000000000 --- a/asm/union_room_chat.s +++ /dev/null @@ -1,1272 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .syntax unified - - .text - - thumb_func_start sub_80201A4 -sub_80201A4: @ 80201A4 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x4C - movs r0, 0x2 - movs r1, 0xFF - bl FillWindowPixelBuffer - bl sub_801F0B0 - lsls r0, 24 - lsrs r2, r0, 24 - add r1, sp, 0xC - movs r0, 0 - strb r0, [r1] - movs r0, 0xE - strb r0, [r1, 0x1] - movs r0, 0xD - strb r0, [r1, 0x2] - cmp r2, 0x3 - beq _08020240 - add r1, sp, 0x10 - movs r0, 0xFC - strb r0, [r1] - movs r0, 0x14 - strb r0, [r1, 0x1] - movs r0, 0x8 - strb r0, [r1, 0x2] - str r0, [sp, 0x40] - str r1, [sp, 0x44] - cmp r2, 0x2 - bne _080201EC - movs r1, 0x6 - str r1, [sp, 0x40] -_080201EC: - movs r7, 0 - movs r6, 0 - lsls r0, r2, 2 - ldr r1, =gUnknown_082F2BA8 - adds r0, r2 - lsls r0, 3 - adds r4, r0, r1 - ldr r0, [sp, 0x40] - lsls r5, r0, 24 -_080201FE: - ldr r1, [r4] - cmp r1, 0 - bne _08020206 - b _0802030C -_08020206: - mov r0, sp - adds r0, 0x13 - bl StringCopy - lsls r3, r6, 24 - lsrs r3, 24 - add r1, sp, 0xC - str r1, [sp] - movs r0, 0x1 - negs r0, r0 - str r0, [sp, 0x4] - ldr r0, [sp, 0x44] - str r0, [sp, 0x8] - movs r0, 0x2 - movs r1, 0 - lsrs r2, r5, 24 - bl AddTextPrinterParameterized3 - adds r4, 0x4 - adds r7, 0x1 - adds r0, r6, 0 - adds r0, 0xC - lsls r0, 16 - lsrs r6, r0, 16 - cmp r7, 0x9 - ble _080201FE - b _0802030C - .pool -_08020240: - movs r1, 0x4 - str r1, [sp, 0x40] - movs r7, 0 - movs r6, 0 -_08020248: - adds r0, r7, 0 - bl sub_801EE6C - adds r5, r0, 0 - movs r0, 0 - adds r1, r5, 0 - movs r2, 0 - bl GetStringWidth - cmp r0, 0x28 - bgt _08020286 - lsls r3, r6, 24 - lsrs r3, 24 - add r4, sp, 0xC - str r4, [sp] - movs r0, 0x1 - negs r0, r0 - str r0, [sp, 0x4] - str r5, [sp, 0x8] - movs r0, 0x2 - movs r1, 0 - movs r4, 0x80 - lsls r4, 19 - lsrs r2, r4, 24 - bl AddTextPrinterParameterized3 - adds r0, r7, 0x1 - str r0, [sp, 0x48] - adds r6, 0xC - mov r10, r6 - b _08020300 -_08020286: - adds r0, r5, 0 - bl StringLength_Multibyte - adds r4, r0, 0 - mov r1, sp - adds r1, 0x10 - str r1, [sp, 0x44] - ldr r0, [sp, 0x40] - lsls r0, 24 - mov r8, r0 - lsls r1, r6, 24 - mov r9, r1 - adds r0, r7, 0x1 - str r0, [sp, 0x48] - adds r6, 0xC - mov r10, r6 - ldr r7, [sp, 0x40] - adds r7, 0x23 - ldr r6, [sp, 0x44] -_080202AC: - subs r4, 0x1 - adds r0, r6, 0 - adds r1, r5, 0 - adds r2, r4, 0 - bl StringCopyN_Multibyte - movs r0, 0 - adds r1, r6, 0 - movs r2, 0 - bl GetStringWidth - cmp r0, 0x23 - bgt _080202AC - mov r1, r8 - lsrs r2, r1, 24 - mov r0, r9 - lsrs r4, r0, 24 - add r1, sp, 0xC - str r1, [sp] - movs r0, 0x1 - negs r0, r0 - str r0, [sp, 0x4] - ldr r1, [sp, 0x44] - str r1, [sp, 0x8] - movs r0, 0x2 - movs r1, 0 - adds r3, r4, 0 - bl AddTextPrinterParameterized3 - adds r2, r7, 0 - add r0, sp, 0xC - str r0, [sp] - movs r1, 0x1 - negs r1, r1 - str r1, [sp, 0x4] - ldr r0, =gText_Ellipsis - str r0, [sp, 0x8] - movs r0, 0x2 - movs r1, 0 - adds r3, r4, 0 - bl AddTextPrinterParameterized3 -_08020300: - ldr r7, [sp, 0x48] - mov r4, r10 - lsls r0, r4, 16 - lsrs r6, r0, 16 - cmp r7, 0x9 - ble _08020248 -_0802030C: - add sp, 0x4C - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80201A4 - - thumb_func_start sub_8020320 -sub_8020320: @ 8020320 - push {r4,lr} - ldr r1, =gUnknown_02022C88 - ldr r2, [r1] - ldrh r3, [r2, 0x20] - movs r4, 0x20 - ldrsh r0, [r2, r4] - cmp r0, 0x37 - bgt _08020354 - adds r0, r3, 0 - adds r0, 0xC - strh r0, [r2, 0x20] - lsls r0, 16 - asrs r0, 16 - cmp r0, 0x37 - ble _08020348 - movs r0, 0x38 - strh r0, [r2, 0x20] - b _08020354 - .pool -_08020348: - movs r1, 0x20 - ldrsh r0, [r2, r1] - bl sub_80207C0 - movs r0, 0x1 - b _08020360 -_08020354: - ldr r0, [r1] - movs r4, 0x20 - ldrsh r0, [r0, r4] - bl sub_8020818 - movs r0, 0 -_08020360: - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_8020320 - - thumb_func_start sub_8020368 -sub_8020368: @ 8020368 - push {r4,lr} - ldr r1, =gUnknown_02022C88 - ldr r2, [r1] - ldrh r3, [r2, 0x20] - movs r4, 0x20 - ldrsh r0, [r2, r4] - cmp r0, 0 - ble _0802039C - adds r0, r3, 0 - subs r0, 0xC - strh r0, [r2, 0x20] - lsls r0, 16 - cmp r0, 0 - bgt _08020390 - movs r0, 0 - strh r0, [r2, 0x20] - b _0802039C - .pool -_08020390: - movs r1, 0x20 - ldrsh r0, [r2, r1] - bl sub_80207C0 - movs r0, 0x1 - b _080203A8 -_0802039C: - ldr r0, [r1] - movs r4, 0x20 - ldrsh r0, [r0, r4] - bl sub_8020818 - movs r0, 0 -_080203A8: - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_8020368 - - thumb_func_start sub_80203B0 -sub_80203B0: @ 80203B0 - push {r4,r5,lr} - sub sp, 0xC - movs r0, 0x3 - movs r1, 0x11 - bl FillWindowPixelBuffer - movs r0, 0x3 - movs r1, 0x1 - movs r2, 0xD - bl sub_8098858 - movs r5, 0xE - str r5, [sp] - movs r4, 0x5 - str r4, [sp, 0x4] - ldr r0, =gUnknown_082F2DC8 - str r0, [sp, 0x8] - movs r0, 0x3 - movs r1, 0x2 - movs r2, 0x8 - movs r3, 0x1 - bl PrintTextArray - bl sub_801F0B0 - lsls r0, 24 - lsrs r0, 24 - str r5, [sp] - str r4, [sp, 0x4] - str r0, [sp, 0x8] - movs r0, 0x3 - movs r1, 0x2 - movs r2, 0 - movs r3, 0x1 - bl sub_81983AC - movs r0, 0x3 - bl PutWindowTilemap - add sp, 0xC - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80203B0 - - thumb_func_start sub_802040C -sub_802040C: @ 802040C - push {lr} - movs r0, 0x3 - movs r1, 0 - bl ClearStdWindowAndFrameToTransparent - movs r0, 0x3 - bl ClearWindowTilemap - pop {r0} - bx r0 - thumb_func_end sub_802040C - - thumb_func_start sub_8020420 -sub_8020420: @ 8020420 - push {r4,r5,lr} - sub sp, 0x10 - adds r5, r1, 0 - lsls r0, 16 - lsrs r0, 16 - lsls r2, 24 - add r3, sp, 0xC - movs r1, 0x1 - strb r1, [r3] - lsrs r2, 23 - adds r1, r2, 0x2 - strb r1, [r3, 0x1] - adds r1, r3, 0 - adds r2, 0x3 - strb r2, [r1, 0x2] - lsls r4, r0, 4 - subs r4, r0 - lsls r3, r4, 16 - lsrs r3, 16 - movs r0, 0xA8 - str r0, [sp] - movs r0, 0xF - str r0, [sp, 0x4] - movs r0, 0 - movs r1, 0x11 - movs r2, 0 - bl FillWindowPixelRect - adds r4, 0x1 - lsls r4, 24 - lsrs r4, 24 - add r0, sp, 0xC - str r0, [sp] - movs r0, 0x1 - negs r0, r0 - str r0, [sp, 0x4] - str r5, [sp, 0x8] - movs r0, 0 - movs r1, 0x2 - movs r2, 0 - adds r3, r4, 0 - bl AddTextPrinterParameterized3 - add sp, 0x10 - pop {r4,r5} - pop {r0} - bx r0 - thumb_func_end sub_8020420 - - thumb_func_start sub_8020480 -sub_8020480: @ 8020480 - push {lr} - movs r0, 0 - movs r1, 0 - movs r2, 0 - bl ChangeBgX - movs r0, 0 - movs r1, 0 - movs r2, 0 - bl ChangeBgY - movs r0, 0x1 - movs r1, 0 - movs r2, 0 - bl ChangeBgX - movs r0, 0x1 - movs r1, 0 - movs r2, 0 - bl ChangeBgY - movs r0, 0x2 - movs r1, 0 - movs r2, 0 - bl ChangeBgX - movs r0, 0x2 - movs r1, 0 - movs r2, 0 - bl ChangeBgY - movs r0, 0x3 - movs r1, 0 - movs r2, 0 - bl ChangeBgX - movs r0, 0x3 - movs r1, 0 - movs r2, 0 - bl ChangeBgY - movs r0, 0 - bl ShowBg - movs r0, 0x1 - bl ShowBg - movs r0, 0x2 - bl ShowBg - movs r0, 0x3 - bl ShowBg - movs r1, 0x82 - lsls r1, 5 - movs r0, 0 - bl SetGpuRegBits - movs r0, 0x50 - movs r1, 0 - bl SetGpuReg - movs r1, 0xE0 - lsls r1, 8 - movs r0, 0 - bl ClearGpuRegBits - movs r1, 0x80 - lsls r1, 6 - movs r0, 0 - bl SetGpuRegBits - ldr r1, =0x000040f0 - movs r0, 0x40 - bl SetGpuReg - movs r0, 0x44 - movs r1, 0x90 - bl SetGpuReg - movs r0, 0x48 - movs r1, 0x3D - bl SetGpuReg - movs r0, 0x4A - movs r1, 0x3F - bl SetGpuReg - pop {r0} - bx r0 - .pool - thumb_func_end sub_8020480 - - thumb_func_start sub_8020538 -sub_8020538: @ 8020538 - push {r4,lr} - ldr r4, =gUnknown_02022C88 - ldr r1, [r4] - movs r0, 0x94 - lsls r0, 1 - adds r1, r0 - movs r0, 0 - bl SetBgTilemapBuffer - ldr r1, [r4] - ldr r0, =0x00000928 - adds r1, r0 - movs r0, 0x1 - bl SetBgTilemapBuffer - ldr r1, [r4] - ldr r0, =0x00001128 - adds r1, r0 - movs r0, 0x3 - bl SetBgTilemapBuffer - ldr r1, [r4] - ldr r0, =0x00001928 - adds r1, r0 - movs r0, 0x2 - bl SetBgTilemapBuffer - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8020538 - - thumb_func_start sub_8020584 -sub_8020584: @ 8020584 - push {lr} - sub sp, 0x8 - movs r1, 0xC0 - lsls r1, 19 - movs r0, 0 - movs r2, 0x20 - movs r3, 0x1 - bl RequestDma3Fill - movs r0, 0x20 - str r0, [sp] - str r0, [sp, 0x4] - movs r0, 0 - movs r1, 0 - movs r2, 0 - movs r3, 0 - bl FillBgTilemapBufferRect_Palette0 - movs r0, 0 - bl CopyBgTilemapBufferToVram - add sp, 0x8 - pop {r0} - bx r0 - thumb_func_end sub_8020584 - - thumb_func_start sub_80205B4 -sub_80205B4: @ 80205B4 - push {lr} - sub sp, 0x4 - ldr r0, =gUnknown_08DD4BD0 - movs r1, 0x70 - movs r2, 0x20 - bl LoadPalette - ldr r0, =gUnknown_08DD4BB0 - movs r1, 0xC0 - movs r2, 0x20 - bl LoadPalette - ldr r1, =gUnknown_08DD4BF0 - movs r0, 0 - str r0, [sp] - movs r0, 0x1 - movs r2, 0 - movs r3, 0 - bl decompress_and_copy_tile_data_to_vram - ldr r1, =gUnknown_08DD4C4C - movs r0, 0x1 - movs r2, 0 - movs r3, 0 - bl CopyToBgTilemapBuffer - movs r0, 0x1 - bl CopyBgTilemapBufferToVram - add sp, 0x4 - pop {r0} - bx r0 - .pool - thumb_func_end sub_80205B4 - - thumb_func_start task_tutorial_story_unknown -task_tutorial_story_unknown: @ 8020604 - push {r4,r5,lr} - sub sp, 0x4 - ldr r0, =gLinkMiscMenu_Pal - movs r1, 0 - movs r2, 0x20 - bl LoadPalette - ldr r1, =gLinkMiscMenu_Gfx - movs r0, 0 - str r0, [sp] - movs r0, 0x2 - movs r2, 0 - movs r3, 0 - bl decompress_and_copy_tile_data_to_vram - adds r5, r0, 0 - cmp r5, 0 - beq _0802064E - movs r1, 0x88 - lsls r1, 2 - adds r0, r5, r1 - ldr r4, =gUnknown_02022C88 - ldr r1, [r4] - ldr r2, =0x00002128 - adds r1, r2 - movs r2, 0x8 - bl CpuFastSet - movs r1, 0x84 - lsls r1, 3 - adds r0, r5, r1 - ldr r1, [r4] - ldr r2, =0x00002148 - adds r1, r2 - movs r2, 0x8 - bl CpuFastSet -_0802064E: - ldr r1, =gLinkMiscMenu_Tilemap - movs r0, 0x2 - movs r2, 0 - movs r3, 0 - bl CopyToBgTilemapBuffer - movs r0, 0x2 - bl CopyBgTilemapBufferToVram - add sp, 0x4 - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end task_tutorial_story_unknown - - thumb_func_start sub_8020680 -sub_8020680: @ 8020680 - push {lr} - ldr r0, =gUnknown_082F2C20 - movs r1, 0x80 - movs r2, 0x20 - bl LoadPalette - ldr r1, =0x06004020 - movs r0, 0 - movs r2, 0x20 - movs r3, 0x1 - bl RequestDma3Fill - pop {r0} - bx r0 - .pool - thumb_func_end sub_8020680 - - thumb_func_start sub_80206A4 -sub_80206A4: @ 80206A4 - push {lr} - ldr r0, =gUnknown_082F2C40 - movs r1, 0xF0 - movs r2, 0x20 - bl LoadPalette - movs r0, 0 - bl PutWindowTilemap - movs r0, 0 - movs r1, 0x11 - bl FillWindowPixelBuffer - movs r0, 0 - movs r1, 0x3 - bl CopyWindowToVram - pop {r0} - bx r0 - .pool - thumb_func_end sub_80206A4 - - thumb_func_start sub_80206D0 -sub_80206D0: @ 80206D0 - push {lr} - movs r0, 0x2 - bl PutWindowTilemap - bl sub_80201A4 - movs r0, 0x2 - movs r1, 0x3 - bl CopyWindowToVram - pop {r0} - bx r0 - thumb_func_end sub_80206D0 - - thumb_func_start sub_80206E8 -sub_80206E8: @ 80206E8 - push {r4,lr} - sub sp, 0xC - add r1, sp, 0x8 - movs r0, 0 - strb r0, [r1] - movs r0, 0xFF - strb r0, [r1, 0x1] - movs r4, 0 -_080206F8: - ldr r0, =gUnknown_02022C88 - ldr r1, [r0] - ldr r0, =0x00002128 - adds r1, r0 - lsls r2, r4, 19 - lsrs r2, 16 - movs r0, 0x8 - str r0, [sp] - movs r0, 0x10 - str r0, [sp, 0x4] - movs r0, 0x1 - movs r3, 0 - bl BlitBitmapToWindow - adds r4, 0x1 - cmp r4, 0xE - ble _080206F8 - movs r0, 0x1 - movs r1, 0 - bl FillWindowPixelBuffer - movs r0, 0x1 - bl PutWindowTilemap - movs r0, 0x1 - movs r1, 0x3 - bl CopyWindowToVram - add sp, 0xC - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80206E8 - - thumb_func_start sub_8020740 -sub_8020740: @ 8020740 - push {lr} - movs r0, 0x3 - movs r1, 0x11 - bl FillWindowPixelBuffer - movs r0, 0x3 - movs r1, 0x1 - movs r2, 0xD0 - bl LoadUserWindowBorderGfx - movs r0, 0x3 - movs r1, 0xA - movs r2, 0x20 - bl LoadUserWindowBorderGfx_ - ldr r0, =gUnknown_0860F074 - movs r1, 0xE0 - movs r2, 0x20 - bl LoadPalette - pop {r0} - bx r0 - .pool - thumb_func_end sub_8020740 - - thumb_func_start sub_8020770 -sub_8020770: @ 8020770 - push {lr} - sub sp, 0x10 - ldr r0, =0xa2600001 - str r0, [sp, 0x4] - ldr r0, =0x04000014 - str r0, [sp] - mov r2, sp - movs r1, 0 - movs r0, 0x1 - strb r0, [r2, 0x8] - mov r0, sp - strb r1, [r0, 0x9] - ldr r0, =gUnknown_02022C88 - ldr r0, [r0] - strh r1, [r0, 0x20] - str r1, [sp, 0xC] - add r0, sp, 0xC - ldr r1, =gScanlineEffectRegBuffers - ldr r2, =0x010003c0 - bl CpuFastSet - ldr r0, [sp] - ldr r1, [sp, 0x4] - ldr r2, [sp, 0x8] - bl ScanlineEffect_SetParams - add sp, 0x10 - pop {r0} - bx r0 - .pool - thumb_func_end sub_8020770 - - thumb_func_start sub_80207C0 -sub_80207C0: @ 80207C0 - push {r4,r5,lr} - sub sp, 0x4 - lsls r0, 16 - lsrs r0, 16 - mov r1, sp - strh r0, [r1] - ldr r5, =gScanlineEffect - ldrb r0, [r5, 0x14] - lsls r1, r0, 4 - subs r1, r0 - lsls r1, 7 - ldr r4, =gScanlineEffectRegBuffers - adds r1, r4 - ldr r2, =0x01000090 - mov r0, sp - bl CpuSet - mov r0, sp - adds r0, 0x2 - movs r1, 0 - strh r1, [r0] - ldrb r2, [r5, 0x14] - lsls r1, r2, 4 - subs r1, r2 - lsls r1, 7 - movs r2, 0x90 - lsls r2, 1 - adds r4, r2 - adds r1, r4 - ldr r2, =0x01000010 - bl CpuSet - add sp, 0x4 - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80207C0 - - thumb_func_start sub_8020818 -sub_8020818: @ 8020818 - push {r4-r6,lr} - mov r6, r9 - mov r5, r8 - push {r5,r6} - sub sp, 0x8 - adds r4, r0, 0 - lsls r4, 16 - lsrs r4, 16 - mov r0, sp - strh r4, [r0] - ldr r5, =gScanlineEffectRegBuffers - ldr r0, =0x01000090 - mov r9, r0 - mov r0, sp - adds r1, r5, 0 - mov r2, r9 - bl CpuSet - mov r0, sp - adds r0, 0x2 - movs r6, 0 - strh r6, [r0] - movs r2, 0x90 - lsls r2, 1 - adds r1, r5, r2 - ldr r2, =0x01000010 - mov r8, r2 - bl CpuSet - add r0, sp, 0x4 - strh r4, [r0] - movs r2, 0xF0 - lsls r2, 3 - adds r1, r5, r2 - mov r2, r9 - bl CpuSet - mov r0, sp - adds r0, 0x6 - strh r6, [r0] - movs r1, 0x8A - lsls r1, 4 - adds r5, r1 - adds r1, r5, 0 - mov r2, r8 - bl CpuSet - add sp, 0x8 - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8020818 - - thumb_func_start sub_8020890 -sub_8020890: @ 8020890 - push {r4,r5,lr} - movs r5, 0 - ldr r4, =gUnknown_082F3134 -_08020896: - adds r0, r4, 0 - bl LoadCompressedSpriteSheet - adds r4, 0x8 - adds r5, 0x1 - cmp r5, 0x4 - bls _08020896 - ldr r0, =gUnknown_082F315C - bl LoadSpritePalette - ldr r4, =gUnknown_02022C8C - movs r0, 0x18 - bl Alloc - str r0, [r4] - cmp r0, 0 - beq _080208C8 - movs r0, 0x1 - b _080208CA - .pool -_080208C8: - movs r0, 0 -_080208CA: - pop {r4,r5} - pop {r1} - bx r1 - thumb_func_end sub_8020890 - - thumb_func_start sub_80208D0 -sub_80208D0: @ 80208D0 - push {lr} - ldr r0, =gUnknown_02022C8C - ldr r0, [r0] - cmp r0, 0 - beq _080208DE - bl Free -_080208DE: - pop {r0} - bx r0 - .pool - thumb_func_end sub_80208D0 - - thumb_func_start sub_80208E8 -sub_80208E8: @ 80208E8 - push {lr} - ldr r0, =gUnknown_082F319C - movs r1, 0xA - movs r2, 0x18 - movs r3, 0 - bl CreateSprite - lsls r0, 24 - lsrs r0, 24 - ldr r1, =gUnknown_02022C8C - ldr r2, [r1] - lsls r1, r0, 4 - adds r1, r0 - lsls r1, 2 - ldr r0, =gSprites - adds r1, r0 - str r1, [r2] - pop {r0} - bx r0 - .pool - thumb_func_end sub_80208E8 - - thumb_func_start sub_802091C -sub_802091C: @ 802091C - ldr r1, =gUnknown_02022C8C - ldr r1, [r1] - ldr r2, [r1] - adds r2, 0x3E - movs r1, 0x1 - ands r0, r1 - lsls r0, 2 - ldrb r3, [r2] - movs r1, 0x5 - negs r1, r1 - ands r1, r3 - orrs r1, r0 - strb r1, [r2] - bx lr - .pool - thumb_func_end sub_802091C - - thumb_func_start sub_802093C -sub_802093C: @ 802093C - push {r4,r5,lr} - sub sp, 0x4 - bl sub_801F0B0 - adds r4, r0, 0 - lsls r4, 24 - lsrs r4, 24 - mov r5, sp - adds r5, 0x1 - mov r0, sp - adds r1, r5, 0 - bl sub_801F0BC - cmp r4, 0x3 - beq _0802097C - ldr r4, =gUnknown_02022C8C - ldr r0, [r4] - ldr r0, [r0] - movs r1, 0 - bl StartSpriteAnim - ldr r1, [r4] - ldr r2, [r1] - mov r0, sp - ldrb r0, [r0] - lsls r0, 3 - adds r0, 0xA - strh r0, [r2, 0x20] - ldr r2, [r1] - b _08020992 - .pool -_0802097C: - ldr r4, =gUnknown_02022C8C - ldr r0, [r4] - ldr r0, [r0] - movs r1, 0x2 - bl StartSpriteAnim - ldr r2, [r4] - ldr r1, [r2] - movs r0, 0x18 - strh r0, [r1, 0x20] - ldr r2, [r2] -_08020992: - ldrb r1, [r5] - lsls r0, r1, 1 - adds r0, r1 - lsls r0, 2 - adds r0, 0x18 - strh r0, [r2, 0x22] - add sp, 0x4 - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_802093C - - thumb_func_start sub_80209AC -sub_80209AC: @ 80209AC - push {r4,lr} - adds r4, r0, 0 - lsls r4, 2 - ldr r0, =gUnknown_082F2DF0+2 - adds r4, r0 - movs r0, 0 - bl IndexOfSpritePaletteTag - adds r1, r0, 0 - lsls r1, 24 - lsrs r1, 4 - ldr r0, =0x01010000 - adds r1, r0 - lsrs r1, 16 - adds r0, r4, 0 - movs r2, 0x4 - bl LoadPalette - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80209AC - - thumb_func_start sub_80209E0 -sub_80209E0: @ 80209E0 - push {lr} - bl sub_801F0B0 - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x3 - beq _08020A00 - ldr r0, =gUnknown_02022C8C - ldr r0, [r0] - ldr r0, [r0] - movs r1, 0x1 - bl StartSpriteAnim - b _08020A0C - .pool -_08020A00: - ldr r0, =gUnknown_02022C8C - ldr r0, [r0] - ldr r0, [r0] - movs r1, 0x3 - bl StartSpriteAnim -_08020A0C: - ldr r0, =gUnknown_02022C8C - ldr r1, [r0] - movs r0, 0 - strh r0, [r1, 0x14] - pop {r0} - bx r0 - .pool - thumb_func_end sub_80209E0 - - thumb_func_start sub_8020A1C -sub_8020A1C: @ 8020A1C - push {r4,lr} - ldr r4, =gUnknown_02022C8C - ldr r1, [r4] - ldrh r0, [r1, 0x14] - cmp r0, 0x3 - bls _08020A30 -_08020A28: - movs r0, 0 - b _08020A62 - .pool -_08020A30: - adds r0, 0x1 - strh r0, [r1, 0x14] - lsls r0, 16 - lsrs r0, 16 - cmp r0, 0x3 - bls _08020A60 - bl sub_801F0B0 - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x3 - beq _08020A54 - ldr r0, [r4] - ldr r0, [r0] - movs r1, 0 - bl StartSpriteAnim - b _08020A28 -_08020A54: - ldr r0, [r4] - ldr r0, [r0] - movs r1, 0x2 - bl StartSpriteAnim - b _08020A28 -_08020A60: - movs r0, 0x1 -_08020A62: - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_8020A1C - - thumb_func_start sub_8020A68 -sub_8020A68: @ 8020A68 - push {r4,r5,lr} - ldr r0, =gUnknown_082F31BC - movs r1, 0x4C - movs r2, 0x98 - movs r3, 0x2 - bl CreateSprite - lsls r0, 24 - lsrs r0, 24 - ldr r5, =gUnknown_02022C8C - ldr r2, [r5] - lsls r1, r0, 4 - adds r1, r0 - lsls r1, 2 - ldr r4, =gSprites - adds r1, r4 - str r1, [r2, 0x8] - ldr r0, =gUnknown_082F31D4 - movs r1, 0x40 - movs r2, 0x98 - movs r3, 0x1 - bl CreateSprite - lsls r0, 24 - lsrs r0, 24 - ldr r2, [r5] - lsls r1, r0, 4 - adds r1, r0 - lsls r1, 2 - adds r1, r4 - str r1, [r2, 0x4] - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8020A68 - - thumb_func_start sub_8020ABC -sub_8020ABC: @ 8020ABC - push {r4,lr} - adds r4, r0, 0 - bl sub_801F198 - adds r3, r0, 0 - cmp r3, 0xF - bne _08020AD8 - adds r0, r4, 0 - adds r0, 0x3E - ldrb r1, [r0] - movs r2, 0x4 - orrs r1, r2 - strb r1, [r0] - b _08020AEC -_08020AD8: - adds r2, r4, 0 - adds r2, 0x3E - ldrb r0, [r2] - movs r1, 0x5 - negs r1, r1 - ands r1, r0 - strb r1, [r2] - lsls r0, r3, 3 - adds r0, 0x4C - strh r0, [r4, 0x20] -_08020AEC: - pop {r4} - pop {r0} - bx r0 - thumb_func_end sub_8020ABC - - thumb_func_start sub_8020AF4 -sub_8020AF4: @ 8020AF4 - push {lr} - adds r1, r0, 0 - ldrh r0, [r1, 0x2E] - adds r0, 0x1 - movs r2, 0 - strh r0, [r1, 0x2E] - lsls r0, 16 - asrs r0, 16 - cmp r0, 0x4 - ble _08020B1A - strh r2, [r1, 0x2E] - ldrh r0, [r1, 0x24] - adds r0, 0x1 - strh r0, [r1, 0x24] - lsls r0, 16 - asrs r0, 16 - cmp r0, 0x4 - ble _08020B1A - strh r2, [r1, 0x24] -_08020B1A: - pop {r0} - bx r0 - thumb_func_end sub_8020AF4 - - thumb_func_start sub_8020B20 -sub_8020B20: @ 8020B20 - push {r4,r5,lr} - ldr r0, =gUnknown_082F322C - movs r1, 0x8 - movs r2, 0x98 - movs r3, 0x3 - bl CreateSprite - lsls r0, 24 - lsrs r0, 24 - ldr r5, =gUnknown_02022C8C - ldr r2, [r5] - lsls r1, r0, 4 - adds r1, r0 - lsls r1, 2 - ldr r4, =gSprites - adds r1, r4 - str r1, [r2, 0xC] - ldr r0, =gUnknown_082F3244 - movs r1, 0x20 - movs r2, 0x98 - movs r3, 0x4 - bl CreateSprite - lsls r0, 24 - lsrs r0, 24 - ldr r2, [r5] - lsls r1, r0, 4 - adds r1, r0 - lsls r1, 2 - adds r1, r4 - str r1, [r2, 0x10] - adds r1, 0x3E - ldrb r0, [r1] - movs r2, 0x4 - orrs r0, r2 - strb r0, [r1] - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8020B20 - - thumb_func_start sub_8020B80 -sub_8020B80: @ 8020B80 - push {r4,lr} - bl sub_801F0B0 - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x3 - bne _08020BB8 - bl sub_801F0DC - cmp r0, 0 - beq _08020BC2 - ldr r3, =gUnknown_02022C8C - ldr r0, [r3] - ldr r1, [r0, 0x10] - adds r1, 0x3E - ldrb r2, [r1] - movs r0, 0x5 - negs r0, r0 - ands r0, r2 - strb r0, [r1] - ldr r0, [r3] - ldr r0, [r0, 0x10] - movs r1, 0x3 - bl StartSpriteAnim - b _08020BF6 - .pool -_08020BB8: - bl sub_801F1A4 - adds r4, r0, 0 - cmp r4, 0x3 - bne _08020BD8 -_08020BC2: - ldr r0, =gUnknown_02022C8C - ldr r0, [r0] - ldr r1, [r0, 0x10] - adds r1, 0x3E - ldrb r0, [r1] - movs r2, 0x4 - orrs r0, r2 - strb r0, [r1] - b _08020BF6 - .pool -_08020BD8: - ldr r3, =gUnknown_02022C8C - ldr r0, [r3] - ldr r1, [r0, 0x10] - adds r1, 0x3E - ldrb r2, [r1] - movs r0, 0x5 - negs r0, r0 - ands r0, r2 - strb r0, [r1] - ldr r0, [r3] - ldr r0, [r0, 0x10] - lsls r1, r4, 24 - lsrs r1, 24 - bl StartSpriteAnim -_08020BF6: - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8020B80 - - .align 2, 0 @ don't pad with nop diff --git a/include/graphics.h b/include/graphics.h index 03840b6ff..b49b2a661 100644 --- a/include/graphics.h +++ b/include/graphics.h @@ -4908,4 +4908,13 @@ extern const u16 gEasyChatRightWindow_Pal[]; // Use Pokeblock extern const u32 gUsePokeblockCondition_Gfx[]; +// Union Room Chat +extern const u16 gUnknown_08DD4BB0[]; +extern const u16 gUnknown_08DD4BD0[]; +extern const u32 gUnknown_08DD4BF0[]; +extern const u32 gUnknown_08DD4C4C[]; +extern const u16 gLinkMiscMenu_Pal[]; +extern const u32 gLinkMiscMenu_Gfx[]; +extern const u32 gLinkMiscMenu_Tilemap[]; + #endif //GUARD_GRAPHICS_H diff --git a/include/menu.h b/include/menu.h index e236ffcfa..ff5730bad 100644 --- a/include/menu.h +++ b/include/menu.h @@ -99,5 +99,6 @@ void sub_8199CBC(u8 bgId, u16 *dest, u8 left, u8 top, u8 width, u8 height); u8 sub_81980F0(u8 bg, u8 xPos, u8 yPos, u8 palette, u16 baseTile); void sub_8198314(void); void sub_8198180(const u8 *string, u8 a2, bool8 copyToVram); +void PrintTextArray(u8 windowId, u8 fontId, u8 left, u8 top, u8 lineHeight, u8 itemCount, const struct MenuAction *strs); #endif // GUARD_MENU_H diff --git a/ld_script.txt b/ld_script.txt index 83f430ebe..c1ea072b5 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -63,7 +63,6 @@ SECTIONS { asm/mevent_server_helpers.o(.text); asm/mevent_news.o(.text); src/union_room_chat.o(.text); - asm/union_room_chat.o(.text); asm/berry_crush.o(.text); src/berry_powder.o(.text); asm/dodrio_berry_picking.o(.text); diff --git a/src/union_room_chat.c b/src/union_room_chat.c index 4de15c563..85cfa6e2e 100755 --- a/src/union_room_chat.c +++ b/src/union_room_chat.c @@ -1,7 +1,11 @@ #include "global.h" #include "alloc.h" #include "bg.h" +#include "decompress.h" +#include "dma3.h" #include "dynamic_placeholder_text_util.h" +#include "gpu_regs.h" +#include "graphics.h" #include "link.h" #include "link_rfu.h" #include "load_save.h" @@ -66,8 +70,24 @@ struct UnionRoomChat2 u16 unk1A; u16 unk1C; u16 unk1E; - u8 filler20[0x2]; - u8 unk22[0x2146]; + s16 unk20; + u8 unk22[0x106]; + u8 unk128[BG_SCREEN_SIZE]; + u8 unk928[BG_SCREEN_SIZE]; + u8 unk1128[BG_SCREEN_SIZE]; + u8 unk1928[BG_SCREEN_SIZE]; + u8 unk2128[0x20]; + u8 unk2148[0x20]; +}; + +struct UnionRoomChat3 +{ + struct Sprite *unk0; + struct Sprite *unk4; + struct Sprite *unk8; + struct Sprite *unkC; + struct Sprite *unk10; + u16 unk14; }; struct Unk82F2C98 @@ -113,14 +133,14 @@ static void sub_801EDE0(void); static void sub_801EE10(void); static void sub_801EE2C(void); static u8 *sub_801EE84(void); -u8 *sub_801EEA8(void); +static u8 *sub_801EEA8(void); static void sub_801EF1C(u8 *); static void sub_801EF24(u8 *); static void sub_801EF4C(u8 *); static void sub_801EF7C(u8 *); static void sub_801EFA8(u8 *); static void sub_801EFD0(u8 *); -u8 *sub_801F114(void); +static u8 *sub_801F114(void); static void sub_801F2B4(u8 taskId); static bool8 sub_801F4D0(void); static bool32 sub_801F534(void); @@ -129,33 +149,33 @@ static void sub_801F5B8(void); static void sub_801F5EC(u16, u8); static bool8 sub_801F644(u8); static s8 sub_801FF08(void); -bool32 sub_8020890(void); -void sub_8020770(void); +static bool32 sub_8020890(void); +static void sub_8020770(void); static void sub_801F574(struct UnionRoomChat2 *); static void sub_801F580(void); -void sub_80208D0(void); +static void sub_80208D0(void); static bool32 sub_801FDD8(u8 *); -void sub_8020480(void); -void sub_8020538(void); -void sub_8020584(void); -void sub_80205B4(void); -void task_tutorial_story_unknown(void); -void sub_8020680(void); -void sub_80206A4(void); -void sub_80206D0(void); -void sub_8020740(void); -void sub_80206E8(void); -void sub_80208E8(void); -void sub_8020A68(void); -void sub_8020B20(void); -void sub_80203B0(void); -void sub_802040C(void); -void sub_802091C(int); -bool32 sub_8020320(void); -void sub_80201A4(void); -bool32 sub_8020368(void); -void sub_802093C(void); -void sub_8020B80(void); +static void sub_8020480(void); +static void sub_8020538(void); +static void sub_8020584(void); +static void sub_80205B4(void); +static void sub_8020604(void); +static void sub_8020680(void); +static void sub_80206A4(void); +static void sub_80206D0(void); +static void sub_8020740(void); +static void sub_80206E8(void); +static void sub_80208E8(void); +static void sub_8020A68(void); +static void sub_8020B20(void); +static void sub_80203B0(void); +static void sub_802040C(void); +static void sub_802091C(bool32); +static bool32 sub_8020320(void); +static void sub_80201A4(void); +static bool32 sub_8020368(void); +static void sub_802093C(void); +static void sub_8020B80(void); static void sub_801FF18(int, u16); static void sub_801FDDC(u8, u8, u8); static void sub_8020094(void); @@ -164,13 +184,16 @@ static void sub_80200C8(void); static void sub_801FEE4(void); static void sub_80200EC(u16, u16, u8); static void sub_8020118(u16, u8 *, u8, u8, u8); -void sub_80209AC(int); -void sub_8020420(u16, u8 *, u8); -void sub_80209E0(void); -bool32 sub_8020A1C(void); +static void sub_80209AC(int); +static void sub_8020420(u16, u8 *, u8); +static void sub_80209E0(void); +static bool32 sub_8020A1C(void); +static void sub_80207C0(s16); +static void sub_8020818(s16); extern struct UnionRoomChat *gUnknown_02022C84; extern struct UnionRoomChat2 *gUnknown_02022C88; +extern struct UnionRoomChat3 *gUnknown_02022C8C; extern const u8 *const gUnknown_082F2BA8[][10]; extern const u8 gUnknown_082F2AA8[]; @@ -178,6 +201,18 @@ extern const struct BgTemplate gUnknown_082F2C60[4]; extern const struct WindowTemplate gUnknown_082F2C70[]; extern const struct Unk82F2C98 gUnknown_082F2C98[]; extern const struct Unk82F2D40 gUnknown_082F2D40[]; +extern const u8 gText_Ellipsis[]; +extern const struct MenuAction gUnknown_082F2DC8[]; +extern const u16 gUnknown_082F2C20[]; +extern const u16 gUnknown_082F2C40[]; +extern const struct CompressedSpriteSheet gUnknown_082F3134[]; +extern const struct SpritePalette gUnknown_082F315C; +extern const struct SpriteTemplate gUnknown_082F319C; +extern const u16 gUnknown_082F2DF0[]; +extern const struct SpriteTemplate gUnknown_082F31BC; +extern const struct SpriteTemplate gUnknown_082F31D4; +extern const struct SpriteTemplate gUnknown_082F322C; +extern const struct SpriteTemplate gUnknown_082F3244; void sub_801DD98(void) @@ -1065,7 +1100,7 @@ static void sub_801EE2C(void) StringCopy(gSaveBlock1Ptr->unk3C88[i], gUnknown_02022C84->unkB9[i]); } -u8 *sub_801EE6C(int arg0) +static u8 *sub_801EE6C(int arg0) { return gUnknown_02022C84->unkB9[arg0]; } @@ -1079,7 +1114,7 @@ static u8 *sub_801EE84(void) return str; } -u8 *sub_801EEA8(void) +static u8 *sub_801EEA8(void) { u8 *str = gUnknown_02022C84->unk1A; u8 *str2 = str; @@ -1094,7 +1129,7 @@ u8 *sub_801EEA8(void) return str2; } -u16 sub_801EED8(void) +static u16 sub_801EED8(void) { u8 *str; u32 i, numChars, strLength; @@ -1159,7 +1194,7 @@ static void sub_801EFD0(u8 *arg0) arg0[1 + (PLAYER_NAME_LENGTH + 1)] = gUnknown_02022C84->unk13; } -bool32 sub_801EFF8(u8 *arg0, u8 *arg1) +static bool32 sub_801EFF8(u8 *arg0, u8 *arg1) { u8 *tempStr; u8 var0 = *arg1; @@ -1203,12 +1238,12 @@ bool32 sub_801EFF8(u8 *arg0, u8 *arg1) return FALSE; } -u8 sub_801F0B0(void) +static u8 sub_801F0B0(void) { return gUnknown_02022C84->unk10; } -void sub_801F0BC(u8 *arg0, u8 *arg1) +static void sub_801F0BC(u8 *arg0, u8 *arg1) { *arg0 = gUnknown_02022C84->unk11; *arg1 = gUnknown_02022C84->unk12; @@ -1219,13 +1254,13 @@ static u8 *sub_801F0D0(void) return gUnknown_02022C84->unk1A; } -int sub_801F0DC(void) +static int sub_801F0DC(void) { u8 *str = sub_801F0D0(); return StringLength_Multibyte(str); } -void sub_801F0EC(u32 *arg0, u32 *arg1) +static void sub_801F0EC(u32 *arg0, u32 *arg1) { int diff = gUnknown_02022C84->unk15 - gUnknown_02022C84->unk14; if (diff < 0) @@ -1241,7 +1276,7 @@ void sub_801F0EC(u32 *arg0, u32 *arg1) *arg1 = diff; } -u8 *sub_801F114(void) +static u8 *sub_801F114(void) { int i; u16 numChars = sub_801EED8(); @@ -1257,7 +1292,7 @@ u8 *sub_801F114(void) return str; } -u16 sub_801F144(void) +static u16 sub_801F144(void) { u16 count; u32 i; @@ -1274,22 +1309,22 @@ u16 sub_801F144(void) return count; } -u8 *sub_801F180(void) +static u8 *sub_801F180(void) { return gUnknown_02022C84->unk39; } -u8 sub_801F18C(void) +static u8 sub_801F18C(void) { return gUnknown_02022C84->unk16; } -int sub_801F198(void) +static int sub_801F198(void) { return gUnknown_02022C84->unk15; } -int sub_801F1A4(void) +static int sub_801F1A4(void) { u8 *str = sub_801EEA8(); u32 character = *str; @@ -1299,7 +1334,7 @@ int sub_801F1A4(void) return 0; } -u8 *sub_801F1D0(void) +static u8 *sub_801F1D0(void) { return gUnknown_02022C84->unk79; } @@ -1540,7 +1575,7 @@ bool32 sub_801F658(u8 *state) sub_80205B4(); break; case 3: - task_tutorial_story_unknown(); + sub_8020604(); break; case 4: sub_8020680(); @@ -1604,7 +1639,7 @@ bool32 sub_801F768(u8 *state) switch (*state) { case 0: - sub_802091C(1); + sub_802091C(TRUE); if (sub_8020320()) return TRUE; @@ -1620,7 +1655,7 @@ bool32 sub_801F768(u8 *state) return TRUE; sub_802093C(); - sub_802091C(0); + sub_802091C(FALSE); sub_8020B80(); return FALSE; } @@ -2177,3 +2212,419 @@ static void sub_8020118(u16 x, u8 *str, u8 fillValue, u8 arg3, u8 arg4) StringCopy(&str2[3], str); AddTextPrinterParameterized3(1, 2, x * 8, 1, sp, TEXT_SPEED_FF, str2); } + +static void sub_80201A4(void) +{ + u8 var0; + int i; + int var1; + u16 left; + u16 top; + u8 sp[52]; + u8 *str; + u8 *str2; + + FillWindowPixelBuffer(2, PIXEL_FILL(15)); + var0 = sub_801F0B0(); + sp[0] = 0; + sp[1] = 14; + sp[2] = 13; + if (var0 != 3) + { + str = &sp[4]; + str[0] = EXT_CTRL_CODE_BEGIN; + str[1] = EXT_CTRL_CODE_MIN_LETTER_SPACING; + var1 = 8; + str[2] = var1; + left = var1; + if (var0 == 2) + left = 6; + + for (i = 0, top = 0; i < 10; i++, top += 12) + { + if (!gUnknown_082F2BA8[var0][i]) + return; + + StringCopy(&sp[7], gUnknown_082F2BA8[var0][i]); + AddTextPrinterParameterized3(2, 0, left, top, sp, TEXT_SPEED_FF, &sp[4]); + } + } + else + { + left = 4; + for (i = 0, top = 0; i < 10; i++, top += 12) + { + str2 = sub_801EE6C(i); + if (GetStringWidth(0, str2, 0) <= 40) + { + AddTextPrinterParameterized3(2, 0, left, top, sp, TEXT_SPEED_FF, str2); + } + else + { + int length = StringLength_Multibyte(str2); + do + { + length--; + StringCopyN_Multibyte(&sp[4], str2, length); + } while (GetStringWidth(0, &sp[4], 0) > 35); + + AddTextPrinterParameterized3(2, 0, left, top, sp, TEXT_SPEED_FF, &sp[4]); + AddTextPrinterParameterized3(2, 0, left + 35, top, sp, TEXT_SPEED_FF, gText_Ellipsis); + } + } + } +} + +static bool32 sub_8020320(void) +{ + if (gUnknown_02022C88->unk20 < 56) + { + gUnknown_02022C88->unk20 += 12; + if (gUnknown_02022C88->unk20 >= 56) + gUnknown_02022C88->unk20 = 56; + + if (gUnknown_02022C88->unk20 < 56) + { + sub_80207C0(gUnknown_02022C88->unk20); + return TRUE; + } + } + + sub_8020818(gUnknown_02022C88->unk20); + return FALSE; +} + +static bool32 sub_8020368(void) +{ + if (gUnknown_02022C88->unk20 > 0) + { + gUnknown_02022C88->unk20 -= 12; + if (gUnknown_02022C88->unk20 <= 0) + gUnknown_02022C88->unk20 = 0; + + if (gUnknown_02022C88->unk20 > 0) + { + sub_80207C0(gUnknown_02022C88->unk20); + return TRUE; + } + } + + sub_8020818(gUnknown_02022C88->unk20); + return FALSE; +} + +static void sub_80203B0(void) +{ + FillWindowPixelBuffer(3, PIXEL_FILL(1)); + sub_8098858(3, 1, 13); + PrintTextArray(3, 2, 8, 1, 14, 5, gUnknown_082F2DC8); + sub_81983AC(3, 2, 0, 1, 14, 5, sub_801F0B0()); + PutWindowTilemap(3); +} + +static void sub_802040C(void) +{ + ClearStdWindowAndFrameToTransparent(3, FALSE); + ClearWindowTilemap(3); +} + +static void sub_8020420(u16 row, u8 *str, u8 arg2) +{ + u8 color[3]; + color[0] = 1; + color[1] = arg2 * 2 + 2; + color[2] = arg2 * 2 + 3; + FillWindowPixelRect(0, PIXEL_FILL(1), 0, row * 15, 168, 15); + AddTextPrinterParameterized3(0, 2, 0, row * 15 + 1, color, TEXT_SPEED_FF, str); +} + +static void sub_8020480(void) +{ + ChangeBgX(0, 0, 0); + ChangeBgY(0, 0, 0); + ChangeBgX(1, 0, 0); + ChangeBgY(1, 0, 0); + ChangeBgX(2, 0, 0); + ChangeBgY(2, 0, 0); + ChangeBgX(3, 0, 0); + ChangeBgY(3, 0, 0); + ShowBg(0); + ShowBg(1); + ShowBg(2); + ShowBg(3); + SetGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP); + SetGpuReg(REG_OFFSET_BLDCNT, 0); + ClearGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_WIN0_ON | DISPCNT_WIN1_ON | DISPCNT_OBJWIN_ON); + SetGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_WIN0_ON); + SetGpuReg(REG_OFFSET_WIN0H, WIN_RANGE(64, 240)); + SetGpuReg(REG_OFFSET_WIN0V, WIN_RANGE(0, 144)); + SetGpuReg(REG_OFFSET_WININ, WININ_WIN0_BG0 | WININ_WIN0_BG2 | WININ_WIN0_BG3 + | WININ_WIN0_OBJ | WININ_WIN0_CLR); + SetGpuReg(REG_OFFSET_WINOUT, WINOUT_WIN01_BG_ALL | WINOUT_WIN01_OBJ | WINOUT_WIN01_CLR); +} + +static void sub_8020538(void) +{ + SetBgTilemapBuffer(0, gUnknown_02022C88->unk128); + SetBgTilemapBuffer(1, gUnknown_02022C88->unk928); + SetBgTilemapBuffer(3, gUnknown_02022C88->unk1128); + SetBgTilemapBuffer(2, gUnknown_02022C88->unk1928); +} + +static void sub_8020584(void) +{ + RequestDma3Fill(0, (void *)BG_CHAR_ADDR(0), 0x20, 1); + FillBgTilemapBufferRect_Palette0(0, 0, 0, 0, 32, 32); + CopyBgTilemapBufferToVram(0); +} + +static void sub_80205B4(void) +{ + LoadPalette(gUnknown_08DD4BD0, 0x70, 0x20); + LoadPalette(gUnknown_08DD4BB0, 0xC0, 0x20); + decompress_and_copy_tile_data_to_vram(1, gUnknown_08DD4BF0, 0, 0, 0); + CopyToBgTilemapBuffer(1, gUnknown_08DD4C4C, 0, 0); + CopyBgTilemapBufferToVram(1); +} + +static void sub_8020604(void) +{ + u8 *ptr; + + LoadPalette(gLinkMiscMenu_Pal, 0, 0x20); + ptr = decompress_and_copy_tile_data_to_vram(2, gLinkMiscMenu_Gfx, 0, 0, 0); + if (ptr) + { + CpuFastCopy(&ptr[0x220], gUnknown_02022C88->unk2128, 0x20); + CpuFastCopy(&ptr[0x420], gUnknown_02022C88->unk2148, 0x20); + } + + CopyToBgTilemapBuffer(2, gLinkMiscMenu_Tilemap, 0, 0); + CopyBgTilemapBufferToVram(2); +} + +static void sub_8020680(void) +{ + LoadPalette(gUnknown_082F2C20, 0x80, 0x20); + RequestDma3Fill(0, (void *)BG_CHAR_ADDR(1) + 0x20, 0x20, 1); +} + +static void sub_80206A4(void) +{ + LoadPalette(gUnknown_082F2C40, 0xF0, 0x20); + PutWindowTilemap(0); + FillWindowPixelBuffer(0, PIXEL_FILL(1)); + CopyWindowToVram(0, 3); +} + +static void sub_80206D0(void) +{ + PutWindowTilemap(2); + sub_80201A4(); + CopyWindowToVram(2, 3); +} + +static void sub_80206E8(void) +{ + int i; + u8 var0[2]; + var0[0] = 0; + var0[1] = 0xFF; + + for (i = 0; i < 15; i++) + BlitBitmapToWindow(1, gUnknown_02022C88->unk2128, i * 8, 0, 8, 16); + + FillWindowPixelBuffer(1, PIXEL_FILL(0)); + PutWindowTilemap(1); + CopyWindowToVram(1, 3); +} + +static void sub_8020740(void) +{ + FillWindowPixelBuffer(3, PIXEL_FILL(1)); + LoadUserWindowBorderGfx(3, 1, 0xD0); + LoadUserWindowBorderGfx_(3, 0xA, 0x20); + LoadPalette(gUnknown_0860F074, 0xE0, 0x20); +} + +static void sub_8020770(void) +{ + struct ScanlineEffectParams params; + params.dmaControl = SCANLINE_EFFECT_DMACNT_16BIT; + params.dmaDest = ®_BG1HOFS; + params.initState = 1; + params.unused9 = 0; + gUnknown_02022C88->unk20 = 0; + CpuFastFill(0, gScanlineEffectRegBuffers, sizeof(gScanlineEffectRegBuffers)); + ScanlineEffect_SetParams(params); +} + +static void sub_80207C0(s16 arg0) +{ + CpuFill16(arg0, gScanlineEffectRegBuffers[gScanlineEffect.srcBuffer], 0x120); + CpuFill16(0, gScanlineEffectRegBuffers[gScanlineEffect.srcBuffer] + 0x90, 0x20); +} + +static void sub_8020818(s16 arg0) +{ + CpuFill16(arg0, gScanlineEffectRegBuffers[0], 0x120); + CpuFill16(0, gScanlineEffectRegBuffers[0] + 0x90, 0x20); + CpuFill16(arg0, gScanlineEffectRegBuffers[0] + 0x3C0, 0x120); + CpuFill16(0, gScanlineEffectRegBuffers[0] + 0x450, 0x20); +} + +static bool32 sub_8020890(void) +{ + u32 i; + for (i = 0; i < 5; i++) + LoadCompressedSpriteSheet(&gUnknown_082F3134[i]); + + LoadSpritePalette(&gUnknown_082F315C); + gUnknown_02022C8C = Alloc(0x18); + if (!gUnknown_02022C8C) + return FALSE; + + return TRUE; +} + +static void sub_80208D0(void) +{ + if (gUnknown_02022C8C) + Free(gUnknown_02022C8C); +} + +static void sub_80208E8(void) +{ + u8 spriteId = CreateSprite(&gUnknown_082F319C, 10, 24, 0); + gUnknown_02022C8C->unk0 = &gSprites[spriteId]; +} + +static void sub_802091C(bool32 invisible) +{ + gUnknown_02022C8C->unk0->invisible = invisible; +} + +static void sub_802093C(void) +{ + u8 x, y; + u8 var2 = sub_801F0B0(); + sub_801F0BC(&x, &y); + if (var2 != 3) + { + StartSpriteAnim(gUnknown_02022C8C->unk0, 0); + gUnknown_02022C8C->unk0->pos1.x = x * 8 + 10; + gUnknown_02022C8C->unk0->pos1.y = y * 12 + 24; + } + else + { + StartSpriteAnim(gUnknown_02022C8C->unk0, 2); + gUnknown_02022C8C->unk0->pos1.x = 24; + gUnknown_02022C8C->unk0->pos1.y = y * 12 + 24; + } +} + +static void sub_80209AC(int arg0) +{ + const u16 *palette = &gUnknown_082F2DF0[arg0 * 2 + 1]; + u8 index = IndexOfSpritePaletteTag(0); + LoadPalette(palette, index * 16 + 0x101, 4); +} + +static void sub_80209E0(void) +{ + if (sub_801F0B0() != 3) + StartSpriteAnim(gUnknown_02022C8C->unk0, 1); + else + StartSpriteAnim(gUnknown_02022C8C->unk0, 3); + + gUnknown_02022C8C->unk14 = 0; +} + +static bool32 sub_8020A1C(void) +{ + if (gUnknown_02022C8C->unk14 > 3) + return FALSE; + + if (++gUnknown_02022C8C->unk14 > 3) + { + if (sub_801F0B0() != 3) + StartSpriteAnim(gUnknown_02022C8C->unk0, 0); + else + StartSpriteAnim(gUnknown_02022C8C->unk0, 2); + + return FALSE; + } + + return TRUE; +} + +static void sub_8020A68(void) +{ + u8 spriteId = CreateSprite(&gUnknown_082F31BC, 76, 152, 2); + gUnknown_02022C8C->unk8 = &gSprites[spriteId]; + spriteId = CreateSprite(&gUnknown_082F31D4, 64, 152, 1); + gUnknown_02022C8C->unk4 = &gSprites[spriteId]; +} + +void sub_8020ABC(struct Sprite *sprite) +{ + int var0 = sub_801F198(); + if (var0 == 15) + { + sprite->invisible = 1; + } + else + { + sprite->invisible = 0; + sprite->pos1.x = var0 * 8 + 76; + } +} + +void sub_8020AF4(struct Sprite *sprite) +{ + if (++sprite->data[0] > 4) + { + sprite->data[0] = 0; + if (++sprite->pos2.x > 4) + sprite->pos2.x = 0; + } +} + +static void sub_8020B20(void) +{ + u8 spriteId = CreateSprite(&gUnknown_082F322C, 8, 152, 3); + gUnknown_02022C8C->unkC = &gSprites[spriteId]; + spriteId = CreateSprite(&gUnknown_082F3244, 32, 152, 4); + gUnknown_02022C8C->unk10 = &gSprites[spriteId]; + gUnknown_02022C8C->unk10->invisible = 1; +} + +static void sub_8020B80(void) +{ + if (sub_801F0B0() == 3) + { + if (sub_801F0DC() != 0) + { + gUnknown_02022C8C->unk10->invisible = 0; + StartSpriteAnim(gUnknown_02022C8C->unk10, 3); + } + else + { + gUnknown_02022C8C->unk10->invisible = 1; + } + } + else + { + int anim = sub_801F1A4(); + if (anim == 3) + { + gUnknown_02022C8C->unk10->invisible = 1; + } + else + { + gUnknown_02022C8C->unk10->invisible = 0; + StartSpriteAnim(gUnknown_02022C8C->unk10, anim); + } + } + +}