From 0688725afb36ae02c4f4904dfe02aa6b8e8e29fa Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sat, 26 Jan 2019 14:50:24 +0100 Subject: [PATCH] Document and decompile more of frontier pass. --- asm/frontier_pass.s | 1334 +-------------------------------------- include/frontier_pass.h | 7 + include/graphics.h | 3 + include/palette.h | 2 +- include/strings.h | 7 +- src/frontier_pass.c | 579 +++++++++++++++-- src/start_menu.c | 5 +- src/trainer_card.c | 4 +- 8 files changed, 546 insertions(+), 1395 deletions(-) create mode 100644 include/frontier_pass.h diff --git a/asm/frontier_pass.s b/asm/frontier_pass.s index c9a2ddc84e..7f9cf934be 100644 --- a/asm/frontier_pass.s +++ b/asm/frontier_pass.s @@ -7,1332 +7,8 @@ - - thumb_func_start sub_80C5934 -sub_80C5934: @ 80C5934 - push {lr} - bl sub_80C570C - cmp r0, 0 - beq _080C599A - ldr r0, =gUnknown_02039CEC - ldr r2, [r0] - ldrb r0, [r2, 0xE] - lsls r0, 28 - lsrs r0, 29 - cmp r0, 0x2 - beq _080C5994 - cmp r0, 0x2 - bgt _080C595C - cmp r0, 0x1 - beq _080C5962 - b _080C599A - .pool -_080C595C: - cmp r0, 0x3 - beq _080C5970 - b _080C599A -_080C5962: - ldr r0, =sub_80C5868 - bl sub_80C6454 - b _080C599A - .pool -_080C5970: - ldr r1, =gUnknown_02039CF8 - ldr r0, [r2] - str r0, [r1] - ldrh r0, [r2, 0x8] - strh r0, [r1, 0x4] - ldrh r0, [r2, 0xA] - strh r0, [r1, 0x6] - bl sub_80C52E4 - ldr r0, =sub_80C58D4 - bl PlayRecordedBattle - b _080C599A - .pool -_080C5994: - ldr r0, =sub_80C5868 - bl ShowPlayerTrainerCard -_080C599A: - pop {r0} - bx r0 - .pool - thumb_func_end sub_80C5934 - - thumb_func_start sub_80C59A4 -sub_80C59A4: @ 80C59A4 - push {r4,lr} - lsls r0, 24 - lsrs r3, r0, 24 - adds r4, r3, 0 - lsls r1, 24 - lsrs r1, 24 - adds r2, r1, 0 - cmp r1, 0x1 - blt _080C59CC - cmp r1, 0x2 - ble _080C59F4 - cmp r1, 0x3 - bne _080C59CC - ldr r0, =gUnknown_02039CEC - ldr r2, [r0] - ldrb r1, [r2, 0xE] - movs r0, 0x1 - ands r0, r1 - cmp r0, 0 - bne _080C59D4 -_080C59CC: - movs r0, 0 - b _080C5A30 - .pool -_080C59D4: - movs r0, 0xF - negs r0, r0 - ands r0, r1 - movs r1, 0x6 - orrs r0, r1 - strb r0, [r2, 0xE] - adds r0, r3, 0 - bl DestroyTask - ldr r0, =sub_80C5934 - bl SetMainCallback2 - b _080C5A1A - .pool -_080C59F4: - ldr r0, =gUnknown_02039CEC - ldr r3, [r0] - movs r0, 0x7 - ands r2, r0 - lsls r2, 1 - ldrb r1, [r3, 0xE] - subs r0, 0x16 - ands r0, r1 - orrs r0, r2 - strb r0, [r3, 0xE] - ldr r1, =gTasks - lsls r0, r4, 2 - adds r0, r4 - lsls r0, 3 - adds r0, r1 - ldr r1, =sub_80C5BD8 - str r1, [r0] - movs r1, 0 - strh r1, [r0, 0x8] -_080C5A1A: - ldr r0, =gUnknown_02039CEC - ldr r2, [r0] - ldr r0, =gUnknown_02039CF0 - ldr r1, [r0] - ldr r0, [r1] - ldrh r0, [r0, 0x20] - strh r0, [r2, 0x8] - ldr r0, [r1] - ldrh r0, [r0, 0x22] - strh r0, [r2, 0xA] - movs r0, 0x1 -_080C5A30: - pop {r4} - pop {r1} - bx r1 - .pool - thumb_func_end sub_80C59A4 - - thumb_func_start sub_80C5A48 -sub_80C5A48: @ 80C5A48 - push {r4-r7,lr} - lsls r0, 24 - lsrs r6, r0, 24 - movs r5, 0 - ldr r2, =gMain - ldrh r1, [r2, 0x2C] - movs r0, 0x40 - ands r0, r1 - cmp r0, 0 - beq _080C5A80 - ldr r0, =gUnknown_02039CF0 - ldr r4, [r0] - ldr r1, [r4] - ldrh r3, [r1, 0x22] - movs r7, 0x22 - ldrsh r0, [r1, r7] - cmp r0, 0x8 - ble _080C5A80 - subs r0, r3, 0x2 - strh r0, [r1, 0x22] - ldr r1, [r4] - movs r3, 0x22 - ldrsh r0, [r1, r3] - cmp r0, 0x7 - bgt _080C5A7E - movs r0, 0x2 - strh r0, [r1, 0x22] -_080C5A7E: - movs r5, 0x1 -_080C5A80: - ldrh r1, [r2, 0x2C] - movs r0, 0x80 - ands r0, r1 - cmp r0, 0 - beq _080C5AAE - ldr r0, =gUnknown_02039CF0 - ldr r4, [r0] - ldr r1, [r4] - ldrh r3, [r1, 0x22] - movs r7, 0x22 - ldrsh r0, [r1, r7] - cmp r0, 0x87 - bgt _080C5AAE - adds r0, r3, 0x2 - strh r0, [r1, 0x22] - ldr r1, [r4] - movs r3, 0x22 - ldrsh r0, [r1, r3] - cmp r0, 0x88 - ble _080C5AAC - movs r0, 0x88 - strh r0, [r1, 0x22] -_080C5AAC: - movs r5, 0x1 -_080C5AAE: - ldrh r1, [r2, 0x2C] - movs r0, 0x20 - ands r0, r1 - cmp r0, 0 - beq _080C5ADC - ldr r0, =gUnknown_02039CF0 - ldr r4, [r0] - ldr r1, [r4] - ldrh r3, [r1, 0x20] - movs r7, 0x20 - ldrsh r0, [r1, r7] - cmp r0, 0x5 - ble _080C5ADC - subs r0, r3, 0x2 - strh r0, [r1, 0x20] - ldr r1, [r4] - movs r3, 0x20 - ldrsh r0, [r1, r3] - cmp r0, 0x4 - bgt _080C5ADA - movs r0, 0x5 - strh r0, [r1, 0x20] -_080C5ADA: - movs r5, 0x1 -_080C5ADC: - ldrh r1, [r2, 0x2C] - movs r0, 0x10 - ands r0, r1 - cmp r0, 0 - beq _080C5B0A - ldr r0, =gUnknown_02039CF0 - ldr r4, [r0] - ldr r1, [r4] - ldrh r3, [r1, 0x20] - movs r7, 0x20 - ldrsh r0, [r1, r7] - cmp r0, 0xE7 - bgt _080C5B0A - adds r0, r3, 0x2 - strh r0, [r1, 0x20] - ldr r1, [r4] - movs r3, 0x20 - ldrsh r0, [r1, r3] - cmp r0, 0xE8 - ble _080C5B08 - movs r0, 0xE8 - strh r0, [r1, 0x20] -_080C5B08: - movs r5, 0x1 -_080C5B0A: - cmp r5, 0 - bne _080C5B88 - ldr r4, =gUnknown_02039CEC - ldr r0, [r4] - ldrb r3, [r0, 0xC] - cmp r3, 0 - beq _080C5B5E - ldrh r1, [r2, 0x2E] - movs r0, 0x1 - ands r0, r1 - cmp r0, 0 - beq _080C5B5E - cmp r3, 0x3 - bhi _080C5B48 - movs r0, 0x5 - bl PlaySE - ldr r0, [r4] - ldrb r1, [r0, 0xC] - adds r0, r6, 0 - bl sub_80C59A4 - cmp r0, 0 - bne _080C5BCA - b _080C5B5E - .pool -_080C5B48: - cmp r3, 0x4 - bne _080C5B5E - movs r0, 0x3 - bl PlaySE - ldr r0, =sub_80C5470 - bl SetMainCallback2 - adds r0, r6, 0 - bl DestroyTask -_080C5B5E: - ldr r0, =gMain - ldrh r1, [r0, 0x2E] - movs r0, 0x2 - ands r0, r1 - cmp r0, 0 - beq _080C5BCA - movs r0, 0x3 - bl PlaySE - ldr r0, =sub_80C5470 - bl SetMainCallback2 - adds r0, r6, 0 - bl DestroyTask - b _080C5BCA - .pool -_080C5B88: - ldr r0, =gUnknown_02039CF0 - ldr r0, [r0] - ldr r1, [r0] - ldrh r0, [r1, 0x20] - subs r0, 0x5 - lsls r0, 16 - asrs r0, 16 - ldrh r1, [r1, 0x22] - adds r1, 0x5 - lsls r1, 16 - asrs r1, 16 - bl sub_80C57FC - lsls r0, 24 - lsrs r5, r0, 24 - ldr r4, =gUnknown_02039CEC - ldr r0, [r4] - ldrb r0, [r0, 0xC] - cmp r0, r5 - beq _080C5BCA - adds r0, r5, 0 - bl sub_80C5ED0 - ldr r1, [r4] - ldrb r0, [r1, 0xC] - strb r0, [r1, 0xD] - ldr r0, [r4] - strb r5, [r0, 0xC] - ldr r1, [r4] - ldrb r0, [r1, 0xC] - ldrb r1, [r1, 0xD] - bl sub_80C6104 -_080C5BCA: - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80C5A48 - - thumb_func_start sub_80C5BD8 -sub_80C5BD8: @ 80C5BD8 - push {r4-r7,lr} - mov r7, r8 - push {r7} - sub sp, 0x4 - lsls r0, 24 - lsrs r4, r0, 24 - lsls r0, r4, 2 - adds r0, r4 - lsls r5, r0, 3 - ldr r0, =gTasks + 0x8 - mov r8, r0 - adds r6, r5, r0 - ldr r7, =gUnknown_02039CEC - ldr r0, [r7] - ldrh r0, [r0, 0x4] - cmp r0, 0x1 - beq _080C5CD4 - cmp r0, 0x1 - bgt _080C5C0C - cmp r0, 0 - beq _080C5C14 - b _080C5D9C - .pool -_080C5C0C: - cmp r0, 0x2 - bne _080C5C12 - b _080C5D2A -_080C5C12: - b _080C5D9C -_080C5C14: - movs r1, 0 - ldrsh r0, [r6, r1] - cmp r0, 0 - bne _080C5C4C - movs r0, 0x1 - movs r1, 0 - bl sub_80C5F58 - movs r1, 0x80 - lsls r1, 1 - adds r0, r1, 0 - strh r0, [r6, 0x2] - strh r0, [r6, 0x4] - movs r0, 0x15 - strh r0, [r6, 0x6] - strh r0, [r6, 0x8] - movs r0, 0x1 - negs r0, r0 - ldr r1, =0x00007fff - str r1, [sp] - movs r1, 0 - movs r2, 0 - movs r3, 0x10 - bl BeginNormalPaletteFade - b _080C5CA4 - .pool -_080C5C4C: - movs r1, 0xFE - lsls r1, 1 - adds r0, r1, 0 - strh r0, [r6, 0x2] - strh r0, [r6, 0x4] - movs r1, 0x15 - negs r1, r1 - adds r0, r1, 0 - strh r0, [r6, 0x6] - strh r0, [r6, 0x8] - movs r1, 0x82 - lsls r1, 5 - movs r0, 0 - bl SetGpuReg - movs r0, 0 - bl ShowBg - movs r0, 0x1 - bl ShowBg - movs r0, 0x2 - bl ShowBg - bl sub_80C62DC - ldr r0, =sub_80C53AC - bl SetVBlankCallback - movs r5, 0x1 - negs r5, r5 - ldr r4, =0x00007fff - adds r0, r5, 0 - movs r1, 0x10 - adds r2, r4, 0 - bl BlendPalettes - str r4, [sp] - adds r0, r5, 0 - movs r1, 0 - movs r2, 0x10 - movs r3, 0 - bl BeginNormalPaletteFade -_080C5CA4: - ldr r4, =gUnknown_02039CF0 - ldr r0, [r4] - adds r0, 0x2C - movs r1, 0x1 - strb r1, [r0] - movs r1, 0x2 - ldrsh r0, [r6, r1] - bl sub_8151624 - ldr r1, [r4] - strh r0, [r1, 0x2E] - movs r1, 0x4 - ldrsh r0, [r6, r1] - bl sub_8151624 - ldr r1, [r4] - strh r0, [r1, 0x30] - b _080C5D9C - .pool -_080C5CD4: - bl UpdatePaletteFade - ldrh r0, [r6, 0x6] - ldrh r1, [r6, 0x2] - adds r0, r1 - strh r0, [r6, 0x2] - ldrh r0, [r6, 0x8] - ldrh r1, [r6, 0x4] - adds r0, r1 - strh r0, [r6, 0x4] - movs r1, 0x2 - ldrsh r0, [r6, r1] - bl sub_8151624 - ldr r4, =gUnknown_02039CF0 - ldr r1, [r4] - strh r0, [r1, 0x2E] - movs r1, 0x4 - ldrsh r0, [r6, r1] - bl sub_8151624 - ldr r1, [r4] - strh r0, [r1, 0x30] - movs r1, 0 - ldrsh r0, [r6, r1] - cmp r0, 0 - bne _080C5D1C - movs r0, 0x2 - ldrsh r1, [r6, r0] - movs r0, 0xFE - lsls r0, 1 - cmp r1, r0 - ble _080C5DA6 - b _080C5D9C - .pool -_080C5D1C: - movs r0, 0x2 - ldrsh r1, [r6, r0] - movs r0, 0x80 - lsls r0, 1 - cmp r1, r0 - bne _080C5DA6 - b _080C5D9C -_080C5D2A: - ldr r0, =gUnknown_02039CF0 - ldr r0, [r0] - adds r1, r0, 0 - adds r1, 0x2C - ldrb r0, [r1] - cmp r0, 0 - beq _080C5D3C - movs r0, 0 - strb r0, [r1] -_080C5D3C: - bl UpdatePaletteFade - lsls r0, 24 - cmp r0, 0 - bne _080C5DA6 - movs r1, 0 - ldrsh r0, [r6, r1] - cmp r0, 0 - bne _080C5D64 - adds r0, r4, 0 - bl DestroyTask - ldr r0, =sub_80C5934 - bl SetMainCallback2 - b _080C5D82 - .pool -_080C5D64: - movs r0, 0 - movs r1, 0 - bl sub_80C5F58 - ldr r2, [r7] - ldrb r1, [r2, 0xE] - movs r0, 0xF - negs r0, r0 - ands r0, r1 - strb r0, [r2, 0xE] - mov r0, r8 - subs r0, 0x8 - adds r0, r5, r0 - ldr r1, =sub_80C5A48 - str r1, [r0] -_080C5D82: - movs r0, 0x2 - movs r1, 0x6 - movs r2, 0 - bl SetBgAttribute - ldr r0, =gUnknown_02039CEC - ldr r1, [r0] - movs r0, 0 - b _080C5DA4 - .pool -_080C5D9C: - ldr r0, =gUnknown_02039CEC - ldr r1, [r0] - ldrh r0, [r1, 0x4] - adds r0, 0x1 -_080C5DA4: - strh r0, [r1, 0x4] -_080C5DA6: - add sp, 0x4 - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80C5BD8 - - thumb_func_start sub_80C5DB8 -sub_80C5DB8: @ 80C5DB8 - push {r4-r6,lr} - mov r6, r8 - push {r6} - sub sp, 0xC - movs r4, 0 -_080C5DC2: - adds r0, r4, 0 - bl PutWindowTilemap - adds r0, r4, 0 - movs r1, 0 - bl FillWindowPixelBuffer - adds r0, r4, 0x1 - lsls r0, 24 - lsrs r4, r0, 24 - cmp r4, 0x4 - bls _080C5DC2 - ldr r4, =gText_SymbolsEarned - movs r0, 0x1 - adds r1, r4, 0 - movs r2, 0x60 - bl GetStringCenterAlignXOffset - lsls r2, r0, 24 - lsrs r2, 24 - ldr r6, =gUnknown_08571448 - str r6, [sp] - movs r0, 0 - mov r8, r0 - str r0, [sp, 0x4] - str r4, [sp, 0x8] - movs r1, 0x1 - movs r3, 0x5 - bl AddTextPrinterParameterized3 - ldr r4, =gText_BattleRecord - movs r0, 0x1 - adds r1, r4, 0 - movs r2, 0x60 - bl GetStringCenterAlignXOffset - lsls r2, r0, 24 - lsrs r2, 24 - str r6, [sp] - mov r1, r8 - str r1, [sp, 0x4] - str r4, [sp, 0x8] - movs r0, 0x1 - movs r1, 0x1 - movs r3, 0x5 - bl AddTextPrinterParameterized3 - str r6, [sp] - mov r0, r8 - str r0, [sp, 0x4] - ldr r0, =gText_BattlePoints - str r0, [sp, 0x8] - movs r0, 0x2 - movs r1, 0x8 - movs r2, 0x5 - movs r3, 0x4 - bl AddTextPrinterParameterized3 - ldr r4, =gStringVar4 - ldr r5, =gUnknown_02039CEC - ldr r0, [r5] - ldrh r1, [r0, 0x6] - adds r0, r4, 0 - movs r2, 0 - movs r3, 0x5 - bl ConvertIntToDecimalStringN - movs r0, 0x8 - adds r1, r4, 0 - movs r2, 0x5B - bl GetStringRightAlignXOffset - lsls r2, r0, 24 - lsrs r2, 24 - str r6, [sp] - mov r1, r8 - str r1, [sp, 0x4] - str r4, [sp, 0x8] - movs r0, 0x2 - movs r1, 0x8 - movs r3, 0x10 - bl AddTextPrinterParameterized3 - ldr r1, [r5] - ldrh r0, [r1, 0x8] - subs r0, 0x5 - lsls r0, 16 - asrs r0, 16 - ldrh r1, [r1, 0xA] - adds r1, 0x5 - lsls r1, 16 - asrs r1, 16 - bl sub_80C57FC - ldr r1, [r5] - strb r0, [r1, 0xC] - ldr r0, [r5] - mov r1, r8 - strb r1, [r0, 0xD] - ldr r0, [r5] - ldrb r0, [r0, 0xC] - bl sub_80C5ED0 - movs r4, 0 -_080C5E92: - adds r0, r4, 0 - movs r1, 0x3 - bl CopyWindowToVram - adds r0, r4, 0x1 - lsls r0, 24 - lsrs r4, r0, 24 - cmp r4, 0x4 - bls _080C5E92 - movs r0, 0 - bl CopyBgTilemapBufferToVram - add sp, 0xC - pop {r3} - mov r8, r3 - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80C5DB8 - - thumb_func_start sub_80C5ED0 -sub_80C5ED0: @ 80C5ED0 - push {r4,lr} - sub sp, 0xC - lsls r0, 24 - lsrs r4, r0, 24 - movs r0, 0x3 - movs r1, 0 - bl FillWindowPixelBuffer - cmp r4, 0x3 - bne _080C5F18 - ldr r0, =gUnknown_02039CEC - ldr r0, [r0] - ldrb r0, [r0, 0xE] - movs r1, 0x1 - ands r1, r0 - cmp r1, 0 - bne _080C5F18 - ldr r0, =gUnknown_0857144B - str r0, [sp] - str r1, [sp, 0x4] - ldr r0, =gUnknown_08571614 - ldr r0, [r0] - str r0, [sp, 0x8] - movs r0, 0x3 - movs r1, 0x1 - movs r2, 0x2 - movs r3, 0 - bl AddTextPrinterParameterized3 - b _080C5F3A - .pool -_080C5F18: - cmp r4, 0 - beq _080C5F3A - ldr r0, =gUnknown_0857144B - str r0, [sp] - movs r0, 0 - str r0, [sp, 0x4] - ldr r1, =gUnknown_08571614 - lsls r0, r4, 2 - adds r0, r1 - ldr r0, [r0] - str r0, [sp, 0x8] - movs r0, 0x3 - movs r1, 0x1 - movs r2, 0x2 - movs r3, 0 - bl AddTextPrinterParameterized3 -_080C5F3A: - movs r0, 0x3 - movs r1, 0x3 - bl CopyWindowToVram - movs r0, 0 - bl CopyBgTilemapBufferToVram - add sp, 0xC - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80C5ED0 - - thumb_func_start sub_80C5F58 -sub_80C5F58: @ 80C5F58 - push {r4-r7,lr} - mov r7, r8 - push {r7} - sub sp, 0x10 - lsls r0, 24 - lsrs r2, r0, 24 - lsls r1, 24 - lsrs r7, r1, 24 - ldr r0, =gUnknown_02039CEC - ldr r0, [r0] - ldrb r0, [r0, 0xE] - lsls r0, 28 - lsrs r0, 29 - cmp r0, 0x1 - beq _080C5F80 - cmp r0, 0x2 - beq _080C5FC2 - b _080C60EE - .pool -_080C5F80: - cmp r2, 0 - beq _080C5FA8 - ldr r0, =gUnknown_02039CF0 - ldr r0, [r0] - ldr r1, [r0, 0x20] - movs r0, 0xC - str r0, [sp] - movs r0, 0x7 - str r0, [sp, 0x4] - movs r0, 0x10 - str r0, [sp, 0x8] - movs r0, 0x2 - movs r2, 0x10 - movs r3, 0x3 - bl CopyToBgTilemapBufferRect_ChangePalette - b _080C6004 - .pool -_080C5FA8: - movs r0, 0xC - str r0, [sp] - movs r0, 0x7 - str r0, [sp, 0x4] - movs r0, 0x10 - str r0, [sp, 0x8] - movs r0, 0x2 - movs r1, 0 - movs r2, 0x10 - movs r3, 0x3 - bl FillBgTilemapBufferRect - b _080C6004 -_080C5FC2: - cmp r2, 0 - beq _080C5FEC - ldr r0, =gUnknown_02039CF0 - ldr r0, [r0] - ldr r1, [r0, 0x20] - adds r1, 0x54 - movs r0, 0xC - str r0, [sp] - movs r0, 0x7 - str r0, [sp, 0x4] - movs r0, 0x10 - str r0, [sp, 0x8] - movs r0, 0x2 - movs r2, 0x10 - movs r3, 0xA - bl CopyToBgTilemapBufferRect_ChangePalette - b _080C6004 - .pool -_080C5FEC: - movs r0, 0xC - str r0, [sp] - movs r0, 0x7 - str r0, [sp, 0x4] - movs r0, 0x10 - str r0, [sp, 0x8] - movs r0, 0x2 - movs r1, 0 - movs r2, 0x10 - movs r3, 0xA - bl FillBgTilemapBufferRect -_080C6004: - movs r0, 0x2 - bl CopyBgTilemapBufferToVram - cmp r7, 0 - beq _080C6084 - movs r4, 0xFE - lsls r4, 1 - adds r0, r4, 0 - bl sub_8151624 - adds r6, r0, 0 - lsls r6, 16 - asrs r6, 16 - adds r0, r4, 0 - bl sub_8151624 - lsls r0, 16 - asrs r0, 16 - ldr r5, =gUnknown_085713E0 - ldr r1, =gUnknown_02039CEC - ldr r1, [r1] - ldrb r4, [r1, 0xE] - lsls r4, 28 - lsrs r1, r4, 29 - subs r1, 0x1 - lsls r1, 2 - adds r1, r5 - movs r2, 0 - ldrsh r1, [r1, r2] - lsls r1, 8 - lsrs r2, r4, 29 - subs r2, 0x1 - lsls r2, 2 - adds r3, r5, 0x2 - mov r8, r3 - add r2, r8 - movs r3, 0 - ldrsh r2, [r2, r3] - lsls r2, 8 - lsrs r3, r4, 29 - subs r3, 0x1 - lsls r3, 2 - adds r3, r5 - movs r5, 0 - ldrsh r3, [r3, r5] - lsrs r4, 29 - subs r4, 0x1 - lsls r4, 2 - add r4, r8 - movs r5, 0 - ldrsh r4, [r4, r5] - str r4, [sp] - str r6, [sp, 0x4] - str r0, [sp, 0x8] - movs r0, 0 - str r0, [sp, 0xC] - movs r0, 0x2 - bl SetBgAffine - b _080C60EE - .pool -_080C6084: - movs r4, 0x80 - lsls r4, 1 - adds r0, r4, 0 - bl sub_8151624 - adds r6, r0, 0 - lsls r6, 16 - asrs r6, 16 - adds r0, r4, 0 - bl sub_8151624 - lsls r0, 16 - asrs r0, 16 - ldr r5, =gUnknown_085713E0 - ldr r1, =gUnknown_02039CEC - ldr r1, [r1] - ldrb r4, [r1, 0xE] - lsls r4, 28 - lsrs r1, r4, 29 - subs r1, 0x1 - lsls r1, 2 - adds r1, r5 - movs r2, 0 - ldrsh r1, [r1, r2] - lsls r1, 8 - lsrs r2, r4, 29 - subs r2, 0x1 - lsls r2, 2 - adds r3, r5, 0x2 - mov r8, r3 - add r2, r8 - movs r3, 0 - ldrsh r2, [r2, r3] - lsls r2, 8 - lsrs r3, r4, 29 - subs r3, 0x1 - lsls r3, 2 - adds r3, r5 - movs r5, 0 - ldrsh r3, [r3, r5] - lsrs r4, 29 - subs r4, 0x1 - lsls r4, 2 - add r4, r8 - movs r5, 0 - ldrsh r4, [r4, r5] - str r4, [sp] - str r6, [sp, 0x4] - str r0, [sp, 0x8] - str r7, [sp, 0xC] - movs r0, 0x2 - bl SetBgAffine -_080C60EE: - add sp, 0x10 - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80C5F58 - - thumb_func_start sub_80C6104 -sub_80C6104: @ 80C6104 - push {r4,r5,lr} - sub sp, 0xC - lsls r0, 24 - lsrs r4, r0, 24 - lsls r1, 24 - lsrs r5, r1, 24 - cmp r5, 0x2 - beq _080C614C - cmp r5, 0x2 - bgt _080C611E - cmp r5, 0x1 - beq _080C6128 - b _080C61C4 -_080C611E: - cmp r5, 0x3 - beq _080C6170 - cmp r5, 0x4 - beq _080C61A4 - b _080C61C4 -_080C6128: - ldr r0, =gUnknown_02039CF0 - ldr r0, [r0] - ldr r1, [r0, 0x24] - movs r0, 0xC - str r0, [sp] - movs r0, 0x7 - str r0, [sp, 0x4] - movs r0, 0x11 - str r0, [sp, 0x8] - movs r0, 0x1 - movs r2, 0x10 - movs r3, 0x3 - bl CopyToBgTilemapBufferRect_ChangePalette - b _080C61CE - .pool -_080C614C: - ldr r0, =gUnknown_02039CF0 - ldr r0, [r0] - ldr r1, [r0, 0x24] - movs r0, 0xA8 - lsls r0, 1 - adds r1, r0 - movs r0, 0xC - str r0, [sp] - movs r0, 0x7 - str r0, [sp, 0x4] - movs r0, 0x11 - str r0, [sp, 0x8] - movs r0, 0x1 - movs r2, 0x10 - b _080C6192 - .pool -_080C6170: - ldr r0, =gUnknown_02039CEC - ldr r0, [r0] - ldrb r1, [r0, 0xE] - movs r0, 0x1 - ands r0, r1 - cmp r0, 0 - beq _080C61C4 - ldr r0, =gUnknown_02039CF0 - ldr r0, [r0] - ldr r1, [r0, 0x28] - movs r0, 0xC - str r0, [sp] - str r5, [sp, 0x4] - movs r0, 0x11 - str r0, [sp, 0x8] - movs r0, 0x1 - movs r2, 0x2 -_080C6192: - movs r3, 0xA - bl CopyToBgTilemapBufferRect_ChangePalette - b _080C61CE - .pool -_080C61A4: - ldr r1, =gUnknown_08DE3350 - movs r0, 0x9 - str r0, [sp] - movs r0, 0x2 - str r0, [sp, 0x4] - movs r0, 0x11 - str r0, [sp, 0x8] - movs r0, 0x1 - movs r2, 0x15 - movs r3, 0 - bl CopyToBgTilemapBufferRect_ChangePalette - b _080C61CE - .pool -_080C61C4: - subs r0, r4, 0x1 - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x3 - bhi _080C6294 -_080C61CE: - cmp r4, 0x2 - beq _080C620C - cmp r4, 0x2 - bgt _080C61DC - cmp r4, 0x1 - beq _080C61E6 - b _080C6284 -_080C61DC: - cmp r4, 0x3 - beq _080C6230 - cmp r4, 0x4 - beq _080C6264 - b _080C6284 -_080C61E6: - ldr r0, =gUnknown_02039CF0 - ldr r0, [r0] - ldr r1, [r0, 0x24] - adds r1, 0xA8 - movs r0, 0xC - str r0, [sp] - movs r0, 0x7 - str r0, [sp, 0x4] - movs r0, 0x11 - str r0, [sp, 0x8] - movs r0, 0x1 - movs r2, 0x10 - movs r3, 0x3 - bl CopyToBgTilemapBufferRect_ChangePalette - b _080C628E - .pool -_080C620C: - ldr r0, =gUnknown_02039CF0 - ldr r0, [r0] - ldr r1, [r0, 0x24] - movs r0, 0xFC - lsls r0, 1 - adds r1, r0 - movs r0, 0xC - str r0, [sp] - movs r0, 0x7 - str r0, [sp, 0x4] - movs r0, 0x11 - str r0, [sp, 0x8] - movs r0, 0x1 - movs r2, 0x10 - b _080C6254 - .pool -_080C6230: - ldr r0, =gUnknown_02039CEC - ldr r0, [r0] - ldrb r1, [r0, 0xE] - movs r0, 0x1 - ands r0, r1 - cmp r0, 0 - beq _080C6294 - ldr r0, =gUnknown_02039CF0 - ldr r0, [r0] - ldr r1, [r0, 0x28] - adds r1, 0x48 - movs r0, 0xC - str r0, [sp] - str r4, [sp, 0x4] - movs r0, 0x11 - str r0, [sp, 0x8] - movs r0, 0x1 - movs r2, 0x2 -_080C6254: - movs r3, 0xA - bl CopyToBgTilemapBufferRect_ChangePalette - b _080C628E - .pool -_080C6264: - ldr r1, =gUnknown_08DE3374 - movs r0, 0x9 - str r0, [sp] - movs r0, 0x2 - str r0, [sp, 0x4] - movs r0, 0x11 - str r0, [sp, 0x8] - movs r0, 0x1 - movs r2, 0x15 - movs r3, 0 - bl CopyToBgTilemapBufferRect_ChangePalette - b _080C628E - .pool -_080C6284: - subs r0, r5, 0x1 - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x3 - bhi _080C6294 -_080C628E: - movs r0, 0x1 - bl CopyBgTilemapBufferToVram -_080C6294: - add sp, 0xC - pop {r4,r5} - pop {r0} - bx r0 - thumb_func_end sub_80C6104 - - thumb_func_start sub_80C629C -sub_80C629C: @ 80C629C - push {r4,lr} - ldr r1, =gUnknown_08DE3060 - movs r0, 0x1 - movs r2, 0 - movs r3, 0 - bl CopyToBgTilemapBuffer - ldr r4, =gUnknown_02039CEC - ldr r1, [r4] - ldrb r0, [r1, 0xC] - ldrb r1, [r1, 0xD] - bl sub_80C6104 - ldr r0, [r4] - ldrb r1, [r0, 0xE] - lsls r1, 28 - lsrs r1, 29 - movs r0, 0x1 - bl sub_80C5F58 - bl sub_80C5DB8 - movs r0, 0x1 - bl CopyBgTilemapBufferToVram - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80C629C - - thumb_func_start sub_80C62DC -sub_80C62DC: @ 80C62DC - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - sub sp, 0x18 - movs r5, 0 - bl FreeAllSpritePalettes - bl ResetAffineAnimData - ldr r0, =gUnknown_085714E4 - bl LoadSpritePalettes - ldr r4, =gUnknown_085714BC - adds r0, r4, 0 - bl LoadCompressedSpriteSheet - adds r4, 0x10 - adds r0, r4, 0 - bl LoadCompressedSpriteSheet - ldr r0, =gUnknown_085715B4 - ldr r1, =gUnknown_02039CEC - ldr r2, [r1] - movs r3, 0x8 - ldrsh r1, [r2, r3] - movs r6, 0xA - ldrsh r2, [r2, r6] - movs r3, 0 - bl CreateSprite - lsls r0, 24 - lsrs r0, 24 - ldr r3, =gUnknown_02039CF0 - ldr r2, [r3] - lsls r1, r0, 4 - adds r1, r0 - lsls r1, 2 - ldr r0, =gSprites - adds r1, r0 - str r1, [r2] - ldrb r2, [r1, 0x5] - movs r0, 0xD - negs r0, r0 - ands r0, r2 - strb r0, [r1, 0x5] - mov r8, sp - mov r9, r3 -_080C633C: - ldr r0, =gUnknown_02039CEC - ldr r0, [r0] - adds r0, 0xF - adds r2, r0, r5 - ldrb r0, [r2] - adds r4, r5, 0x1 - cmp r0, 0 - beq _080C63C2 - mov r1, sp - ldr r0, =gUnknown_085715E4 - ldm r0!, {r3,r6,r7} - stm r1!, {r3,r6,r7} - ldm r0!, {r3,r6,r7} - stm r1!, {r3,r6,r7} - mov r7, r8 - ldrh r0, [r7, 0x2] - ldr r1, =0x0000ffff - adds r0, r1 - ldrb r2, [r2] - adds r0, r2 - strh r0, [r7, 0x2] - ldr r1, =gUnknown_08571454 - adds r0, r5, 0x6 - lsls r0, 3 - adds r0, r1 - ldrh r1, [r0, 0x4] - adds r1, 0x8 - lsls r1, 16 - asrs r1, 16 - ldrh r2, [r0] - adds r2, 0x6 - lsls r2, 16 - asrs r2, 16 - lsls r3, r4, 24 - lsrs r3, 24 - mov r0, sp - bl CreateSprite - lsls r0, 24 - lsrs r0, 24 - mov r3, r9 - ldr r2, [r3] - lsls r3, r5, 2 - adds r2, 0x4 - adds r2, r3 - lsls r1, r0, 4 - adds r1, r0 - lsls r1, 2 - ldr r0, =gSprites - adds r1, r0 - str r1, [r2] - ldrb r2, [r1, 0x5] - movs r6, 0xD - negs r6, r6 - adds r0, r6, 0 - ands r2, r0 - movs r0, 0x8 - orrs r2, r0 - strb r2, [r1, 0x5] - mov r7, r9 - ldr r0, [r7] - adds r0, 0x4 - adds r0, r3 - ldr r0, [r0] - adds r1, r5, 0 - bl StartSpriteAnim -_080C63C2: - lsls r0, r4, 24 - lsrs r5, r0, 24 - cmp r5, 0x6 - bls _080C633C - add sp, 0x18 - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80C62DC - - thumb_func_start sub_80C63FC -sub_80C63FC: @ 80C63FC - push {r4-r6,lr} - movs r5, 0 - ldr r4, =gUnknown_02039CF0 - ldr r0, [r4] - ldr r0, [r0] - bl DestroySprite - ldr r0, [r4] - str r5, [r0] - adds r6, r4, 0 -_080C6410: - ldr r0, [r6] - lsls r4, r5, 2 - adds r0, 0x4 - adds r0, r4 - ldr r0, [r0] - cmp r0, 0 - beq _080C642C - bl DestroySprite - ldr r0, [r6] - adds r0, 0x4 - adds r0, r4 - movs r1, 0 - str r1, [r0] -_080C642C: - adds r0, r5, 0x1 - lsls r0, 24 - lsrs r5, r0, 24 - cmp r5, 0x6 - bls _080C6410 - bl FreeAllSpritePalettes - movs r0, 0x2 - bl FreeSpriteTilesByTag - movs r0, 0 - bl FreeSpriteTilesByTag - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80C63FC - - thumb_func_start nullsub_39 -nullsub_39: @ 80C6450 - bx lr - thumb_func_end nullsub_39 - - thumb_func_start sub_80C6454 -sub_80C6454: @ 80C6454 + thumb_func_start ShowFrontierMap +ShowFrontierMap: @ 80C6454 push {r4,r5,lr} adds r4, r0, 0 ldr r5, =gUnknown_02039CF4 @@ -1350,13 +26,13 @@ _080C6466: ldr r0, =sub_80C67BC movs r1, 0 bl CreateTask - ldr r0, =sub_80C5438 + ldr r0, =CB2_FrontierPass bl SetMainCallback2 pop {r4,r5} pop {r0} bx r0 .pool - thumb_func_end sub_80C6454 + thumb_func_end ShowFrontierMap thumb_func_start sub_80C6498 sub_80C6498: @ 80C6498 @@ -1524,7 +200,7 @@ _080C6628: movs r0, 0x2 bl ShowBg bl sub_80C6974 - ldr r0, =sub_80C53AC + ldr r0, =VblankCb_FrontierPass bl SetVBlankCallback movs r5, 0x1 negs r5, r5 diff --git a/include/frontier_pass.h b/include/frontier_pass.h new file mode 100644 index 0000000000..bdfc1996fe --- /dev/null +++ b/include/frontier_pass.h @@ -0,0 +1,7 @@ +#ifndef GUARD_FRONTIER_PASS_H +#define GUARD_FRONTIER_PASS_H + +void ShowFrontierPass(void (*callback)(void)); +void CB2_ReshowFrontierPass(void); + +#endif // GUARD_FRONTIER_PASS_H diff --git a/include/graphics.h b/include/graphics.h index d6a32cab28..ed91b06c11 100644 --- a/include/graphics.h +++ b/include/graphics.h @@ -4863,6 +4863,9 @@ extern const u32 gUnknown_08DD1F78[]; // Frontier Pass extern const u32 gUnknown_08DE08C8[]; extern const u32 gUnknown_08DE2084[]; +extern const u32 gUnknown_08DE3350[]; +extern const u32 gUnknown_08DE3374[]; +extern const u32 gUnknown_08DE3060[]; extern const u16 gUnknown_08DE07C8[][16]; #endif //GUARD_GRAPHICS_H diff --git a/include/palette.h b/include/palette.h index f51dc4b88d..e24da3e00b 100644 --- a/include/palette.h +++ b/include/palette.h @@ -63,7 +63,7 @@ void TintPlttBuffer(u32, s8, s8, s8); void UnfadePlttBuffer(u32); void BeginFastPaletteFade(u8); void BeginHardwarePaletteFade(u8, u8, u8, u8, u8); -void BlendPalettes(u32, u8, u16); +void BlendPalettes(u32 selectedPalettes, u8 coeff, u16 color); void BlendPalettesUnfaded(u32, u8, u16); void sub_80A2C44(u32 a1, s8 a2, u8 a3, u8 a4, u16 a5, u8 a6, u8 a7); void TintPalette_GrayScale(u16 *palette, u16 count); diff --git a/include/strings.h b/include/strings.h index 4e9c91ff55..2c07eb68ec 100644 --- a/include/strings.h +++ b/include/strings.h @@ -2248,4 +2248,9 @@ extern const u8 gText_Var1DarkLightGreyBP[]; extern const u8 gText_BattleTower[]; extern const u8 gText_BattlePtsWon[]; -#endif //GUARD_STRINGS_H +// Frontier Pass +extern const u8 gText_SymbolsEarned[]; +extern const u8 gText_BattleRecord[]; +extern const u8 gText_BattlePoints[]; + +#endif // GUARD_STRINGS_H diff --git a/src/frontier_pass.c b/src/frontier_pass.c index 7b25ca9b8e..078baaff15 100644 --- a/src/frontier_pass.c +++ b/src/frontier_pass.c @@ -10,19 +10,36 @@ #include "text_window.h" #include "task.h" #include "graphics.h" +#include "strings.h" +#include "frontier_pass.h" +#include "international_string_util.h" #include "palette.h" #include "window.h" +#include "decompress.h" #include "menu_helpers.h" #include "menu.h" #include "bg.h" #include "sound.h" +#include "string_util.h" #include "battle_pyramid.h" #include "overworld.h" +#include "math_util.h" #include "constants/battle_frontier.h" #include "constants/rgb.h" #include "constants/region_map_sections.h" #include "constants/songs.h" +// All windows displayed in the frontier pass. +enum +{ + WINDOW_EARNED_SYMBOLS, + WINDOW_BATTLE_RECORD, + WINDOW_BATTLE_POINTS, + WINDOW_DESCRIPTION, + WINDOW_4, + WINDOW_COUNT +}; + enum { CURSOR_AREA_NOTHING, @@ -41,8 +58,8 @@ struct FrontierPassData void (*callback)(void); u16 state; u16 battlePoints; - s16 x; - s16 y; + s16 cursorX; + s16 cursorY; u8 cursorArea; u8 previousCursorArea; u8 hasBattleRecord:1; @@ -51,13 +68,14 @@ struct FrontierPassData u8 facilitySymbols[NUM_FRONTIER_FACILITIES]; }; -struct FrontierPassUnk +struct FrontierPassGfx { - u32 unk0[8]; + struct Sprite *cursorSprite; + struct Sprite *symbolSprites[NUM_FRONTIER_FACILITIES]; u8 *unk20; u8 *unk24; u8 *unk28; - bool8 unk2C; + bool8 setAffine; s16 unk2E; s16 unk30; u8 tilemapBuff1[0x1000]; @@ -68,26 +86,29 @@ struct FrontierPassUnk struct FrontierPassSaved { void (*callback)(void); - s16 x; - s16 y; + s16 cursorX; + s16 cursorY; }; extern struct FrontierPassData *gUnknown_02039CEC; -extern struct FrontierPassUnk *gUnknown_02039CF0; +extern struct FrontierPassGfx *gUnknown_02039CF0; extern struct FrontierPassSaved gUnknown_02039CF8; // This file's functions. -u32 sub_80C51F0(void (*callback)(void)); -void sub_80C544C(void); +u32 AllocateFrontierPassData(void (*callback)(void)); +void ShowFrontierMap(void (*callback)(void)); +void CB2_InitFrontierPass(void); void sub_80C629C(void); -void sub_80C63FC(void); -void sub_80C62DC(void); -u32 sub_80C52E4(void); -bool32 sub_80C5484(void); -bool32 sub_80C570C(void); -void sub_80C5A48(u8 taskId); -void sub_80C5BD8(u8 taskId); +void FreeCursorAndSymbolSprites(void); +void LoadCursorAndSymbolSprites(void); +u32 FreeFrontierPassData(void); +bool32 InitFrontierPass(void); +bool32 HideFrontierPass(void); +void Task_HandleFrontierPassInput(u8 taskId); +void Task_DoFadeEffect(u8 taskId); void sub_80C6104(u8 cursorArea, u8 previousCursorArea); +void PrintAreaDescription(u8 cursorArea); +void sub_80C5F58(bool8 arg0, bool8 arg1); // Const rom data. extern const s16 gUnknown_085713E0[][2]; @@ -96,6 +117,13 @@ extern const struct WindowTemplate gUnknown_08571400[]; extern const u32 gUnknown_085712F8[]; extern const u32 gUnknown_085712C0[]; extern const u32 gUnknown_08571060[]; +extern const u8 gUnknown_08571448[]; +extern const u8 gUnknown_0857144B[]; +extern const u8 *const gUnknown_08571614[]; +extern const struct SpritePalette gUnknown_085714E4[]; +extern const struct CompressedSpriteSheet gUnknown_085714BC[]; +extern const struct SpriteTemplate gUnknown_085715B4; +extern const struct SpriteTemplate gUnknown_085715E4; // code void sub_80C50D0(void) @@ -126,19 +154,19 @@ void sub_80C50D0(void) CpuFill32(0, (void *)OAM, OAM_SIZE); } -void sub_80C51C4(void (*callback)(void)) +void ShowFrontierPass(void (*callback)(void)) { - sub_80C51F0(callback); - SetMainCallback2(sub_80C544C); + AllocateFrontierPassData(callback); + SetMainCallback2(CB2_InitFrontierPass); } -void sub_80C51D8(void) +void LeaveFrontierPass(void) { SetMainCallback2(gUnknown_02039CEC->callback); - sub_80C52E4(); + FreeFrontierPassData(); } -u32 sub_80C51F0(void (*callback)(void)) +u32 AllocateFrontierPassData(void (*callback)(void)) { u8 i; @@ -153,13 +181,13 @@ u32 sub_80C51F0(void (*callback)(void)) i = GetCurrentRegionMapSectionId(); if (i != MAPSEC_BATTLE_FRONTIER && i != MAPSEC_ARTISAN_CAVE) { - gUnknown_02039CEC->x = 176; - gUnknown_02039CEC->y = 104; + gUnknown_02039CEC->cursorX = 176; + gUnknown_02039CEC->cursorY = 104; } else { - gUnknown_02039CEC->x = 176; - gUnknown_02039CEC->y = 48; + gUnknown_02039CEC->cursorX = 176; + gUnknown_02039CEC->cursorY = 48; } gUnknown_02039CEC->battlePoints = gSaveBlock2Ptr->frontier.battlePoints; @@ -177,7 +205,7 @@ u32 sub_80C51F0(void (*callback)(void)) return 0; } -u32 sub_80C52E4(void) +u32 FreeFrontierPassData(void) { if (gUnknown_02039CEC == NULL) return 1; @@ -187,7 +215,7 @@ u32 sub_80C52E4(void) return 0; } -u32 sub_80C5310(void) +u32 AllocateFrontierPassGfx(void) { if (gUnknown_02039CF0 != NULL) return 1; @@ -199,7 +227,7 @@ u32 sub_80C5310(void) return 0; } -u32 sub_80C5340(void) +u32 FreeFrontierPassGfx(void) { FreeAllWindowBuffers(); if (gUnknown_02039CF0 == NULL) @@ -217,9 +245,9 @@ u32 sub_80C5340(void) return 0; } -void sub_80C53AC(void) +void VblankCb_FrontierPass(void) { - if (gUnknown_02039CF0->unk2C) + if (gUnknown_02039CF0->setAffine) { SetBgAffine(2, gUnknown_085713E0[gUnknown_02039CEC->unkE - 1][0] << 8, @@ -235,31 +263,31 @@ void sub_80C53AC(void) TransferPlttBuffer(); } -void sub_80C5438(void) +void CB2_FrontierPass(void) { RunTasks(); AnimateSprites(); BuildOamBuffer(); } -void sub_80C544C(void) +void CB2_InitFrontierPass(void) { - if (sub_80C5484()) + if (InitFrontierPass()) { - CreateTask(sub_80C5A48, 0); - SetMainCallback2(sub_80C5438); + CreateTask(Task_HandleFrontierPassInput, 0); + SetMainCallback2(CB2_FrontierPass); } } -void sub_80C5470(void) +void CB2_HideFrontierPass(void) { - if (sub_80C570C()) + if (HideFrontierPass()) { - sub_80C51D8(); + LeaveFrontierPass(); } } -bool32 sub_80C5484(void) +bool32 InitFrontierPass(void) { u32 sizeOut = 0; @@ -282,7 +310,7 @@ bool32 sub_80C5484(void) reset_temp_tile_data_buffers(); break; case 3: - sub_80C5310(); + AllocateFrontierPassGfx(); break; case 4: ResetBgsAndClearDma3BusyFlags(0); @@ -330,8 +358,8 @@ bool32 sub_80C5484(void) ShowBg(0); ShowBg(1); ShowBg(2); - sub_80C62DC(); - SetVBlankCallback(sub_80C53AC); + LoadCursorAndSymbolSprites(); + SetVBlankCallback(VblankCb_FrontierPass); BlendPalettes(0xFFFFFFFF, 0x10, 0); BeginNormalPaletteFade(0xFFFFFFFF, 0, 0x10, 0, RGB_BLACK); break; @@ -349,7 +377,7 @@ bool32 sub_80C5484(void) return FALSE; } -bool32 sub_80C570C(void) +bool32 HideFrontierPass(void) { switch (gUnknown_02039CEC->state) { @@ -378,7 +406,7 @@ bool32 sub_80C570C(void) SetVBlankHBlankCallbacksToNull(); break; case 3: - sub_80C63FC(); + FreeCursorAndSymbolSprites(); break; case 4: sub_80C50D0(); @@ -390,7 +418,7 @@ bool32 sub_80C570C(void) UnsetBgTilemapBuffer(0); UnsetBgTilemapBuffer(1); UnsetBgTilemapBuffer(2); - sub_80C5340(); + FreeFrontierPassGfx(); gUnknown_02039CEC->state = 0; return TRUE; } @@ -408,7 +436,7 @@ struct } extern const gUnknown_08571454[]; -u8 sub_80C57FC(s16 x, s16 y) +u8 GetCursorAreaFromCoords(s16 x, s16 y) { u8 i; @@ -428,35 +456,35 @@ u8 sub_80C57FC(s16 x, s16 y) return 0; } -void sub_80C5868(void) +void CB2_ReshowFrontierPass(void) { u8 taskId; - if (!sub_80C5484()) + if (!InitFrontierPass()) return; switch (gUnknown_02039CEC->unkE) { case 1: case 2: - taskId = CreateTask(sub_80C5BD8, 0); - gTasks[taskId].data[0] = 1; + taskId = CreateTask(Task_DoFadeEffect, 0); + gTasks[taskId].data[0] = TRUE; break; case 3: default: gUnknown_02039CEC->unkE = 0; - taskId = CreateTask(sub_80C5A48, 0); + taskId = CreateTask(Task_HandleFrontierPassInput, 0); break; } - SetMainCallback2(sub_80C5438); + SetMainCallback2(CB2_FrontierPass); } -void sub_80C58D4(void) +void CB2_ReturnFromRecord(void) { - sub_80C51F0(gUnknown_02039CF8.callback); - gUnknown_02039CEC->x = gUnknown_02039CF8.x; - gUnknown_02039CEC->y = gUnknown_02039CF8.y; + AllocateFrontierPassData(gUnknown_02039CF8.callback); + gUnknown_02039CEC->cursorX = gUnknown_02039CF8.cursorX; + gUnknown_02039CEC->cursorY = gUnknown_02039CF8.cursorY; memset(&gUnknown_02039CF8, 0, sizeof(gUnknown_02039CF8)); switch (InBattlePyramid()) { @@ -471,5 +499,438 @@ void sub_80C58D4(void) break; } - SetMainCallback2(sub_80C5868); + SetMainCallback2(CB2_ReshowFrontierPass); } + +void CB2_ShowFrontierPassFeature(void) +{ + if (!HideFrontierPass()) + return; + + switch (gUnknown_02039CEC->unkE) + { + case 1: + ShowFrontierMap(CB2_ReshowFrontierPass); + break; + case 3: + gUnknown_02039CF8.callback = gUnknown_02039CEC->callback; + gUnknown_02039CF8.cursorX = gUnknown_02039CEC->cursorX; + gUnknown_02039CF8.cursorY = gUnknown_02039CEC->cursorY; + FreeFrontierPassData(); + PlayRecordedBattle(CB2_ReturnFromRecord); + break; + case 2: + ShowPlayerTrainerCard(CB2_ReshowFrontierPass); + break; + } +} + +bool32 TryCallPassAreaFunction(u8 taskId, u8 cursorArea) +{ + switch (cursorArea) + { + case CURSOR_AREA_RECORD: + if (!gUnknown_02039CEC->hasBattleRecord) + return FALSE; + gUnknown_02039CEC->unkE = 3; + DestroyTask(taskId); + SetMainCallback2(CB2_ShowFrontierPassFeature); + break; + case CURSOR_AREA_MAP: + case CURSOR_AREA_CARD: + gUnknown_02039CEC->unkE = cursorArea; + gTasks[taskId].func = Task_DoFadeEffect; + gTasks[taskId].data[0] = FALSE; + break; + default: + return FALSE; + } + + gUnknown_02039CEC->cursorX = gUnknown_02039CF0->cursorSprite->pos1.x; + gUnknown_02039CEC->cursorY = gUnknown_02039CF0->cursorSprite->pos1.y; + return TRUE; +} + +void Task_HandleFrontierPassInput(u8 taskId) +{ + u8 var = FALSE; // Reused, first informs whether the cursor moves, then used as the new cursor area. + + if (gMain.heldKeys & DPAD_UP && gUnknown_02039CF0->cursorSprite->pos1.y >= 9) + { + gUnknown_02039CF0->cursorSprite->pos1.y -= 2; + if (gUnknown_02039CF0->cursorSprite->pos1.y <= 7) + gUnknown_02039CF0->cursorSprite->pos1.y = 2; + var = TRUE; + } + if (gMain.heldKeys & DPAD_DOWN && gUnknown_02039CF0->cursorSprite->pos1.y <= 135) + { + gUnknown_02039CF0->cursorSprite->pos1.y += 2; + if (gUnknown_02039CF0->cursorSprite->pos1.y >= 137) + gUnknown_02039CF0->cursorSprite->pos1.y = 136; + var = TRUE; + } + + if (gMain.heldKeys & DPAD_LEFT && gUnknown_02039CF0->cursorSprite->pos1.x >= 6) + { + gUnknown_02039CF0->cursorSprite->pos1.x -= 2; + if (gUnknown_02039CF0->cursorSprite->pos1.x <= 4) + gUnknown_02039CF0->cursorSprite->pos1.x = 5; + var = TRUE; + } + if (gMain.heldKeys & DPAD_RIGHT && gUnknown_02039CF0->cursorSprite->pos1.x <= 231) + { + gUnknown_02039CF0->cursorSprite->pos1.x += 2; + if (gUnknown_02039CF0->cursorSprite->pos1.x >= 233) + gUnknown_02039CF0->cursorSprite->pos1.x = 232; + var = TRUE; + } + + if (!var) // Cursor did not change. + { + if (gUnknown_02039CEC->cursorArea != CURSOR_AREA_NOTHING && gMain.newKeys & A_BUTTON) + { + if (gUnknown_02039CEC->cursorArea <= CURSOR_AREA_RECORD) // Map, Card, Record + { + PlaySE(SE_SELECT); + if (TryCallPassAreaFunction(taskId, gUnknown_02039CEC->cursorArea)) + return; + } + else if (gUnknown_02039CEC->cursorArea == CURSOR_AREA_CANCEL) + { + PlaySE(SE_PC_OFF); + SetMainCallback2(CB2_HideFrontierPass); + DestroyTask(taskId); + // BUG. The function should return here. Otherwise, it can play the same sound twice and destroy the same task twice. + } + } + + if (gMain.newKeys & B_BUTTON) + { + PlaySE(SE_PC_OFF); + SetMainCallback2(CB2_HideFrontierPass); + DestroyTask(taskId); + } + } + else + { + var = GetCursorAreaFromCoords(gUnknown_02039CF0->cursorSprite->pos1.x - 5, gUnknown_02039CF0->cursorSprite->pos1.y + 5); + if (gUnknown_02039CEC->cursorArea != var) + { + PrintAreaDescription(var); + gUnknown_02039CEC->previousCursorArea = gUnknown_02039CEC->cursorArea; + gUnknown_02039CEC->cursorArea = var; + sub_80C6104(gUnknown_02039CEC->cursorArea, gUnknown_02039CEC->previousCursorArea); + } + } +} + +void Task_DoFadeEffect(u8 taskId) +{ + s16 *data = gTasks[taskId].data; + + switch (gUnknown_02039CEC->state) + { + case 0: + if (!data[0]) + { + sub_80C5F58(TRUE, FALSE); + data[1] = 0x100; + data[2] = 0x100; + data[3] = 0x15; + data[4] = 0x15; + BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 0x10, RGB_WHITE); + } + else + { + data[1] = 0x1FC; + data[2] = 0x1FC; + data[3] = -0x15; + data[4] = -0x15; + SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP); + ShowBg(0); + ShowBg(1); + ShowBg(2); + LoadCursorAndSymbolSprites(); + SetVBlankCallback(VblankCb_FrontierPass); + BlendPalettes(0xFFFFFFFF, 0x10, RGB_WHITE); + BeginNormalPaletteFade(0xFFFFFFFF, 0, 0x10, 0, RGB_WHITE); + } + gUnknown_02039CF0->setAffine = TRUE; + gUnknown_02039CF0->unk2E = sub_8151624(data[1]); + gUnknown_02039CF0->unk30 = sub_8151624(data[2]); + break; + case 1: + UpdatePaletteFade(); + data[1] += data[3]; + data[2] += data[4]; + gUnknown_02039CF0->unk2E = sub_8151624(data[1]); + gUnknown_02039CF0->unk30 = sub_8151624(data[2]); + if (!data[0]) + { + if (data[1] <= 0x1FC) + return; + } + else + { + if (data[1] != 0x100) + return; + } + break; + case 2: + if (gUnknown_02039CF0->setAffine) // Nonsensical check. + gUnknown_02039CF0->setAffine = FALSE; + if (UpdatePaletteFade()) + return; + if (!data[0]) + { + DestroyTask(taskId); + SetMainCallback2(CB2_ShowFrontierPassFeature); + } + else + { + sub_80C5F58(FALSE, FALSE); + gUnknown_02039CEC->unkE = 0; + gTasks[taskId].func = Task_HandleFrontierPassInput; + } + SetBgAttribute(2, BG_ATTR_WRAPAROUND, 0); + gUnknown_02039CEC->state = 0; + return; + } + + gUnknown_02039CEC->state++; +} + +void ShowAndPrintWindows(void) +{ + s32 x; + u8 i; + + for (i = 0; i < WINDOW_COUNT; i++) + { + PutWindowTilemap(i); + FillWindowPixelBuffer(i, 0); + } + + x = GetStringCenterAlignXOffset(1, gText_SymbolsEarned, 0x60); + AddTextPrinterParameterized3(WINDOW_EARNED_SYMBOLS, 1, x, 5, gUnknown_08571448, 0, gText_SymbolsEarned); + + x = GetStringCenterAlignXOffset(1, gText_BattleRecord, 0x60); + AddTextPrinterParameterized3(WINDOW_BATTLE_RECORD, 1, x, 5, gUnknown_08571448, 0, gText_BattleRecord); + + AddTextPrinterParameterized3(WINDOW_BATTLE_POINTS, 8, 5, 4, gUnknown_08571448, 0, gText_BattlePoints); + ConvertIntToDecimalStringN(gStringVar4, gUnknown_02039CEC->battlePoints, STR_CONV_MODE_LEFT_ALIGN, 5); + x = GetStringRightAlignXOffset(8, gStringVar4, 0x5B); + AddTextPrinterParameterized3(WINDOW_BATTLE_POINTS, 8, x, 16, gUnknown_08571448, 0, gStringVar4); + + gUnknown_02039CEC->cursorArea = GetCursorAreaFromCoords(gUnknown_02039CEC->cursorX - 5, gUnknown_02039CEC->cursorY + 5); + gUnknown_02039CEC->previousCursorArea = CURSOR_AREA_NOTHING; + PrintAreaDescription(gUnknown_02039CEC->cursorArea); + + for (i = 0; i < WINDOW_COUNT; i++) + CopyWindowToVram(i, 3); + + CopyBgTilemapBufferToVram(0); +} + +void PrintAreaDescription(u8 cursorArea) +{ + FillWindowPixelBuffer(WINDOW_DESCRIPTION, 0); + if (cursorArea == CURSOR_AREA_RECORD && !gUnknown_02039CEC->hasBattleRecord) + AddTextPrinterParameterized3(WINDOW_DESCRIPTION, 1, 2, 0, gUnknown_0857144B, 0, gUnknown_08571614[0]); + else if (cursorArea != CURSOR_AREA_NOTHING) + AddTextPrinterParameterized3(WINDOW_DESCRIPTION, 1, 2, 0, gUnknown_0857144B, 0, gUnknown_08571614[cursorArea]); + + CopyWindowToVram(WINDOW_DESCRIPTION, 3); + CopyBgTilemapBufferToVram(0); +} + +void sub_80C5F58(bool8 arg0, bool8 arg1) +{ + switch (gUnknown_02039CEC->unkE) + { + case 1: + if (arg0) + CopyToBgTilemapBufferRect_ChangePalette(2, gUnknown_02039CF0->unk20, 16, 3, 12, 7, 16); + else + FillBgTilemapBufferRect(2, 0, 16, 3, 12, 7, 16); + break; + case 2: + if (arg0) + CopyToBgTilemapBufferRect_ChangePalette(2, gUnknown_02039CF0->unk20 + 84, 16, 10, 12, 7, 16); + else + FillBgTilemapBufferRect(2, 0, 16, 10, 12, 7, 16); + break; + default: + return; + } + + CopyBgTilemapBufferToVram(2); + if (arg1) + { + SetBgAffine(2, + gUnknown_085713E0[gUnknown_02039CEC->unkE - 1][0] << 8, + gUnknown_085713E0[gUnknown_02039CEC->unkE - 1][1] << 8, + gUnknown_085713E0[gUnknown_02039CEC->unkE - 1][0], + gUnknown_085713E0[gUnknown_02039CEC->unkE - 1][1], + sub_8151624(0x1FC), + sub_8151624(0x1FC), + 0); + } + else + { + SetBgAffine(2, + gUnknown_085713E0[gUnknown_02039CEC->unkE - 1][0] << 8, + gUnknown_085713E0[gUnknown_02039CEC->unkE - 1][1] << 8, + gUnknown_085713E0[gUnknown_02039CEC->unkE - 1][0], + gUnknown_085713E0[gUnknown_02039CEC->unkE - 1][1], + sub_8151624(0x100), + sub_8151624(0x100), + 0); + } +} + +void sub_80C6104(u8 cursorArea, u8 previousCursorArea) +{ + bool32 var; + + switch (previousCursorArea) + { + case CURSOR_AREA_MAP: + CopyToBgTilemapBufferRect_ChangePalette(1, gUnknown_02039CF0->unk24, 16, 3, 12, 7, 17); + var = TRUE; + break; + case CURSOR_AREA_CARD: + CopyToBgTilemapBufferRect_ChangePalette(1, gUnknown_02039CF0->unk24 + 336, 16, 10, 12, 7, 17); + var = TRUE; + break; + case CURSOR_AREA_RECORD: + if (!gUnknown_02039CEC->hasBattleRecord) + { + var = FALSE; + } + else + { + CopyToBgTilemapBufferRect_ChangePalette(1, gUnknown_02039CF0->unk28, 2, 10, 12, 3, 17); + var = TRUE; + } + break; + case CURSOR_AREA_CANCEL: + CopyToBgTilemapBufferRect_ChangePalette(1, gUnknown_08DE3350, 21, 0, 9, 2, 17); + var = TRUE; + break; + default: + var = FALSE; + break; + } + + if (!var) + { + if (cursorArea == CURSOR_AREA_NOTHING || cursorArea > CURSOR_AREA_CANCEL) + return; + } + + switch (cursorArea) + { + case CURSOR_AREA_MAP: + CopyToBgTilemapBufferRect_ChangePalette(1, gUnknown_02039CF0->unk24 + 168, 16, 3, 12, 7, 17); + var = TRUE; + break; + case CURSOR_AREA_CARD: + CopyToBgTilemapBufferRect_ChangePalette(1, gUnknown_02039CF0->unk24 + 504, 16, 10, 12, 7, 17); + var = TRUE; + break; + case CURSOR_AREA_RECORD: + if (!gUnknown_02039CEC->hasBattleRecord) + return; + + CopyToBgTilemapBufferRect_ChangePalette(1, gUnknown_02039CF0->unk28 + 72, 2, 10, 12, 3, 17); + var = TRUE; + break; + case CURSOR_AREA_CANCEL: + CopyToBgTilemapBufferRect_ChangePalette(1, gUnknown_08DE3374, 21, 0, 9, 2, 17); + var = TRUE; + break; + default: + var = FALSE; + break; + } + + if (!var) + { + asm("":::"r4"); + if (previousCursorArea == CURSOR_AREA_NOTHING || previousCursorArea > CURSOR_AREA_CANCEL) + return; + } + + CopyBgTilemapBufferToVram(1); +} + +void sub_80C629C(void) +{ + CopyToBgTilemapBuffer(1, gUnknown_08DE3060, 0, 0); + sub_80C6104(gUnknown_02039CEC->cursorArea, gUnknown_02039CEC->previousCursorArea); + sub_80C5F58(TRUE, gUnknown_02039CEC->unkE); + ShowAndPrintWindows(); + CopyBgTilemapBufferToVram(1); +} + +void LoadCursorAndSymbolSprites(void) +{ + u8 spriteId; + u8 i = 0; + + FreeAllSpritePalettes(); + ResetAffineAnimData(); + LoadSpritePalettes(gUnknown_085714E4); + LoadCompressedSpriteSheet(&gUnknown_085714BC[0]); + LoadCompressedSpriteSheet(&gUnknown_085714BC[2]); + spriteId = CreateSprite(&gUnknown_085715B4, gUnknown_02039CEC->cursorX, gUnknown_02039CEC->cursorY, 0); + gUnknown_02039CF0->cursorSprite = &gSprites[spriteId]; + gUnknown_02039CF0->cursorSprite->oam.priority = 0; + + for (i = 0; i < NUM_FRONTIER_FACILITIES; i++) + { + if (gUnknown_02039CEC->facilitySymbols[i] != 0) + { + struct SpriteTemplate sprite = gUnknown_085715E4; + + sprite.paletteTag += gUnknown_02039CEC->facilitySymbols[i] - 1; + spriteId = CreateSprite(&sprite, gUnknown_08571454[i + CURSOR_AREA_SYMBOL - 1].xStart + 8, gUnknown_08571454[i + CURSOR_AREA_SYMBOL - 1].yStart + 6, i + 1); + gUnknown_02039CF0->symbolSprites[i] = &gSprites[spriteId]; + gUnknown_02039CF0->symbolSprites[i]->oam.priority = 2; + StartSpriteAnim(gUnknown_02039CF0->symbolSprites[i], i); + } + } +} + +void FreeCursorAndSymbolSprites(void) +{ + u8 i = 0; + + DestroySprite(gUnknown_02039CF0->cursorSprite); + gUnknown_02039CF0->cursorSprite = NULL; + for (i = 0; i < NUM_FRONTIER_FACILITIES; i++) + { + if (gUnknown_02039CF0->symbolSprites[i] != NULL) + { + DestroySprite(gUnknown_02039CF0->symbolSprites[i]); + gUnknown_02039CF0->symbolSprites[i] = NULL; + } + } + FreeAllSpritePalettes(); + FreeSpriteTilesByTag(2); + FreeSpriteTilesByTag(0); +} + +void nullsub_39(void) +{ + +} + +// Frontier Map code. +/* +void ShowFrontierMap(void (*callback)(void)); +{ + +} +*/ diff --git a/src/start_menu.c b/src/start_menu.c index 6b4b0e7752..5c7e5365de 100644 --- a/src/start_menu.c +++ b/src/start_menu.c @@ -10,6 +10,7 @@ #include "bg.h" #include "field_effect.h" #include "party_menu.h" +#include "frontier_pass.h" #include "task.h" #include "overworld.h" #include "link.h" @@ -92,8 +93,6 @@ extern void sub_808B864(void); extern void CB2_Pokedex(void); extern void PlayRainSoundEffect(void); extern void CB2_PokeNav(void); -extern void ShowPlayerTrainerCard(void (*)(void)); -extern void sub_80C51C4(void (*)(void)); extern void ScriptUnfreezeEventObjects(void); extern void sub_81A9EC8(void); extern void save_serialize_map(void); @@ -678,7 +677,7 @@ static bool8 StartMenuPlayerNameCallback(void) if (is_c1_link_related_active() || InUnionRoom()) ShowPlayerTrainerCard(CB2_ReturnToFieldWithOpenMenu); // Display trainer card else if (FlagGet(FLAG_SYS_FRONTIER_PASS)) - sub_80C51C4(CB2_ReturnToFieldWithOpenMenu); // Display frontier pass + ShowFrontierPass(CB2_ReturnToFieldWithOpenMenu); // Display frontier pass else ShowPlayerTrainerCard(CB2_ReturnToFieldWithOpenMenu); // Display trainer card diff --git a/src/trainer_card.c b/src/trainer_card.c index cde15ae34c..e4b9c5edfa 100755 --- a/src/trainer_card.c +++ b/src/trainer_card.c @@ -8,6 +8,7 @@ #include "link.h" #include "bg.h" #include "sound.h" +#include "frontier_pass.h" #include "overworld.h" #include "menu.h" #include "text.h" @@ -90,7 +91,6 @@ struct TrainerCardData //external functions extern u8 sub_80D30A0(u16); -extern void sub_80C5868(void); // EWRAM EWRAM_DATA static struct TrainerCardData *sData = NULL; @@ -1754,7 +1754,7 @@ void ShowPlayerTrainerCard(void (*callback)(void)) { sData = AllocZeroed(sizeof(*sData)); sData->callback2 = callback; - if (callback == sub_80C5868) + if (callback == CB2_ReshowFrontierPass) sData->var_52C = 0x7FFF; else sData->var_52C = 0;