From 1b303aeee87095400aae7c0d1ff9f94e83594691 Mon Sep 17 00:00:00 2001 From: golem galvanize Date: Wed, 7 Feb 2018 14:11:08 -0500 Subject: [PATCH] decompiled up to task_new_game_prof_birch_speech_3 --- asm/main_menu.s | 2095 ----------------------------------------------- ld_script.txt | 1 + src/main_menu.c | 880 ++++++++++++++++++++ 3 files changed, 881 insertions(+), 2095 deletions(-) diff --git a/asm/main_menu.s b/asm/main_menu.s index 08e0c3103..1aaef8697 100644 --- a/asm/main_menu.s +++ b/asm/main_menu.s @@ -5,2101 +5,6 @@ .text - thumb_func_start CB2_MainMenu -@ void CB2_MainMenu() -CB2_MainMenu: @ 802F6B0 - push {lr} - bl RunTasks - bl AnimateSprites - bl BuildOamBuffer - bl UpdatePaletteFade - pop {r0} - bx r0 - thumb_func_end CB2_MainMenu - - thumb_func_start VBlankCB_MainMenu -@ void VBlankCB_MainMenu() -VBlankCB_MainMenu: @ 802F6C8 - push {lr} - bl LoadOam - bl ProcessSpriteCopyRequests - bl TransferPlttBuffer - pop {r0} - bx r0 - thumb_func_end VBlankCB_MainMenu - - thumb_func_start CB2_InitMainMenu -@ void CB2_InitMainMenu() -CB2_InitMainMenu: @ 802F6DC - push {lr} - movs r0, 0 - bl InitMainMenu - pop {r0} - bx r0 - thumb_func_end CB2_InitMainMenu - - thumb_func_start CB2_ReinitMainMenu -@ void CB2_ReinitMainMenu() -CB2_ReinitMainMenu: @ 802F6E8 - push {lr} - movs r0, 0x1 - bl InitMainMenu - pop {r0} - bx r0 - thumb_func_end CB2_ReinitMainMenu - - thumb_func_start InitMainMenu -@ void InitMainMenu(bool8 affects_palette_maybe) -InitMainMenu: @ 802F6F4 - push {r4,r5,lr} - sub sp, 0xC - adds r4, r0, 0 - lsls r4, 24 - lsrs r4, 24 - movs r0, 0 - bl SetVBlankCallback - movs r0, 0 - movs r1, 0 - bl SetGpuReg - movs r0, 0xC - movs r1, 0 - bl SetGpuReg - movs r0, 0xA - movs r1, 0 - bl SetGpuReg - movs r0, 0x8 - movs r1, 0 - bl SetGpuReg - movs r0, 0x18 - movs r1, 0 - bl SetGpuReg - movs r0, 0x1A - movs r1, 0 - bl SetGpuReg - movs r0, 0x14 - movs r1, 0 - bl SetGpuReg - movs r0, 0x16 - movs r1, 0 - bl SetGpuReg - movs r0, 0x10 - movs r1, 0 - bl SetGpuReg - movs r0, 0x12 - movs r1, 0 - bl SetGpuReg - add r1, sp, 0x4 - movs r0, 0 - strh r0, [r1] - ldr r1, =0x040000d4 - add r0, sp, 0x4 - str r0, [r1] - movs r0, 0xC0 - lsls r0, 19 - str r0, [r1, 0x4] - ldr r0, =0x8100c000 - str r0, [r1, 0x8] - ldr r0, [r1, 0x8] - movs r5, 0 - str r5, [sp, 0x8] - add r0, sp, 0x8 - str r0, [r1] - movs r0, 0xE0 - lsls r0, 19 - str r0, [r1, 0x4] - ldr r0, =0x85000100 - str r0, [r1, 0x8] - ldr r0, [r1, 0x8] - add r0, sp, 0x4 - strh r5, [r0] - str r0, [r1] - ldr r0, =0x05000002 - str r0, [r1, 0x4] - ldr r0, =0x810001ff - str r0, [r1, 0x8] - ldr r0, [r1, 0x8] - bl ResetPaletteFade - ldr r0, =gMainMenuBgPal - movs r1, 0 - movs r2, 0x20 - bl LoadPalette - ldr r0, =gMainMenuTextPal - movs r1, 0xF0 - movs r2, 0x20 - bl LoadPalette - bl ScanlineEffect_Stop - bl ResetTasks - bl ResetSpriteData - bl FreeAllSpritePalettes - cmp r4, 0 - beq _0802F7EC - movs r0, 0x1 - negs r0, r0 - str r5, [sp] - movs r1, 0 - movs r2, 0x10 - movs r3, 0 - bl BeginNormalPaletteFade - b _0802F7FE - .pool -_0802F7EC: - movs r0, 0x1 - negs r0, r0 - ldr r1, =0x0000ffff - str r1, [sp] - movs r1, 0 - movs r2, 0x10 - movs r3, 0 - bl BeginNormalPaletteFade -_0802F7FE: - movs r0, 0 - bl ResetBgsAndClearDma3BusyFlags - ldr r1, =gUnknown_082FF0E8 - movs r0, 0 - movs r2, 0x2 - bl InitBgsFromTemplates - 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 - ldr r0, =gUnknown_082FF038 - bl InitWindows - bl DeactivateAllTextPrinters - ldr r1, =0x000001d5 - movs r0, 0 - bl LoadMainMenuWindowFrameTiles - movs r0, 0x40 - movs r1, 0 - bl SetGpuReg - movs r0, 0x44 - movs r1, 0 - bl SetGpuReg - movs r0, 0x48 - movs r1, 0 - bl SetGpuReg - movs r0, 0x4A - movs r1, 0 - bl SetGpuReg - movs r0, 0x50 - movs r1, 0 - bl SetGpuReg - movs r0, 0x52 - movs r1, 0 - bl SetGpuReg - movs r0, 0x54 - movs r1, 0 - bl SetGpuReg - movs r0, 0x1 - bl EnableInterrupts - ldr r0, =VBlankCB_MainMenu - bl SetVBlankCallback - ldr r0, =CB2_MainMenu - bl SetMainCallback2 - movs r1, 0xC1 - lsls r1, 6 - movs r0, 0 - bl SetGpuReg - movs r0, 0 - bl ShowBg - movs r0, 0x1 - bl HideBg - ldr r0, =Task_MainMenuCheckSaveFile - movs r1, 0 - bl CreateTask - movs r0, 0 - add sp, 0xC - pop {r4,r5} - pop {r1} - bx r1 - .pool - thumb_func_end InitMainMenu - - thumb_func_start Task_MainMenuCheckSaveFile -@ void Task_MainMenuCheckSaveFile(u8 taskId) -Task_MainMenuCheckSaveFile: @ 802F8D8 - push {r4-r7,lr} - mov r7, r8 - push {r7} - lsls r0, 24 - lsrs r6, r0, 24 - lsls r0, r6, 2 - adds r0, r6 - lsls r7, r0, 3 - ldr r0, =gTasks + 0x8 - mov r8, r0 - adds r4, r7, r0 - ldr r0, =gPaletteFade - ldrb r1, [r0, 0x7] - movs r0, 0x80 - ands r0, r1 - lsls r0, 24 - lsrs r5, r0, 24 - cmp r5, 0 - beq _0802F900 - b _0802FA4E -_0802F900: - movs r0, 0x40 - movs r1, 0 - bl SetGpuReg - movs r0, 0x44 - movs r1, 0 - bl SetGpuReg - movs r0, 0x48 - movs r1, 0x11 - bl SetGpuReg - movs r0, 0x4A - movs r1, 0x31 - bl SetGpuReg - movs r0, 0x50 - movs r1, 0xC1 - bl SetGpuReg - movs r0, 0x52 - movs r1, 0 - bl SetGpuReg - movs r0, 0x54 - movs r1, 0x7 - bl SetGpuReg - bl sub_80093CC - lsls r0, 24 - cmp r0, 0 - beq _0802F946 - movs r0, 0x1 - strh r0, [r4, 0x1E] -_0802F946: - ldr r0, =gSaveFileStatus - ldrh r0, [r0] - cmp r0, 0x2 - beq _0802F990 - cmp r0, 0x2 - bgt _0802F968 - cmp r0, 0 - beq _0802F9D0 - cmp r0, 0x1 - beq _0802F972 - b _0802F9D0 - .pool -_0802F968: - cmp r0, 0x4 - beq _0802F9EC - cmp r0, 0xFF - beq _0802F9A4 - b _0802F9D0 -_0802F972: - strh r0, [r4] - bl IsMysteryGiftEnabled - cmp r0, 0 - beq _0802F982 - ldrh r0, [r4] - adds r0, 0x1 - strh r0, [r4] -_0802F982: - mov r0, r8 - subs r0, 0x8 - adds r0, r7, r0 - ldr r1, =Task_MainMenuCheckBattery - b _0802F9FC - .pool -_0802F990: - ldr r0, =gText_SaveFileErased - bl CreateMainMenuErrorWindow - strh r5, [r4] - mov r0, r8 - subs r0, 0x8 - adds r0, r7, r0 - b _0802F9FA - .pool -_0802F9A4: - ldr r0, =gText_SaveFileCorrupted - bl CreateMainMenuErrorWindow - mov r0, r8 - subs r0, 0x8 - adds r0, r7, r0 - ldr r1, =Task_WaitForSaveFileErrorWindow - str r1, [r0] - movs r0, 0x1 - strh r0, [r4] - bl IsMysteryGiftEnabled - cmp r0, 0x1 - bne _0802F9FE - ldrh r0, [r4] - adds r0, 0x1 - strh r0, [r4] - b _0802F9FE - .pool -_0802F9D0: - movs r0, 0 - strh r0, [r4] - ldr r1, =gTasks - lsls r0, r6, 2 - adds r0, r6 - lsls r0, 3 - adds r0, r1 - ldr r1, =Task_MainMenuCheckBattery - b _0802F9FC - .pool -_0802F9EC: - ldr r0, =gJPText_No1MSubCircuit - bl CreateMainMenuErrorWindow - mov r0, r8 - subs r0, 0x8 - adds r0, r7, r0 - strh r5, [r0, 0x8] -_0802F9FA: - ldr r1, =Task_WaitForSaveFileErrorWindow -_0802F9FC: - str r1, [r0] -_0802F9FE: - ldr r2, =gUnknown_02022D06 - ldrh r1, [r2] - movs r0, 0x80 - lsls r0, 8 - ands r0, r1 - cmp r0, 0 - beq _0802FA3E - movs r1, 0 - ldrsh r0, [r4, r1] - cmp r0, 0x2 - beq _0802FA36 - cmp r0, 0x2 - ble _0802FA2C - cmp r0, 0x3 - beq _0802FA3A - b _0802FA3E - .pool -_0802FA2C: - cmp r0, 0 - blt _0802FA3E - ldrh r0, [r4] - adds r0, 0x1 - b _0802FA3C -_0802FA36: - movs r0, 0x3 - b _0802FA3C -_0802FA3A: - movs r0, 0x4 -_0802FA3C: - strh r0, [r2] -_0802FA3E: - ldrh r1, [r2] - ldr r0, =0x00007fff - ands r0, r1 - strh r0, [r2] - strh r0, [r4, 0x2] - ldrh r0, [r4] - adds r0, 0x2 - strh r0, [r4, 0x18] -_0802FA4E: - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end Task_MainMenuCheckSaveFile - - thumb_func_start Task_WaitForSaveFileErrorWindow -@ void Task_WaitForSaveFileErrorWindow(u8 taskId) -Task_WaitForSaveFileErrorWindow: @ 802FA5C - push {r4,lr} - lsls r0, 24 - lsrs r4, r0, 24 - bl RunTextPrinters - movs r0, 0x7 - bl IsTextPrinterActive - lsls r0, 16 - cmp r0, 0 - bne _0802FA98 - ldr r0, =gMain - ldrh r1, [r0, 0x2E] - movs r0, 0x1 - ands r0, r1 - cmp r0, 0 - beq _0802FA98 - movs r0, 0x7 - bl ClearWindowTilemap - ldr r0, =gUnknown_082FF070 - bl sub_8032250 - ldr r1, =gTasks - lsls r0, r4, 2 - adds r0, r4 - lsls r0, 3 - adds r0, r1 - ldr r1, =Task_MainMenuCheckBattery - str r1, [r0] -_0802FA98: - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end Task_WaitForSaveFileErrorWindow - - thumb_func_start Task_MainMenuCheckBattery -@ void Task_MainMenuCheckBattery(u8 taskId) -Task_MainMenuCheckBattery: @ 802FAB0 - push {r4,r5,lr} - lsls r0, 24 - lsrs r4, r0, 24 - adds r5, r4, 0 - ldr r0, =gPaletteFade - ldrb r1, [r0, 0x7] - movs r0, 0x80 - ands r0, r1 - cmp r0, 0 - bne _0802FB3C - movs r0, 0x40 - movs r1, 0 - bl SetGpuReg - movs r0, 0x44 - movs r1, 0 - bl SetGpuReg - movs r0, 0x48 - movs r1, 0x11 - bl SetGpuReg - movs r0, 0x4A - movs r1, 0x31 - bl SetGpuReg - movs r0, 0x50 - movs r1, 0xC1 - bl SetGpuReg - movs r0, 0x52 - movs r1, 0 - bl SetGpuReg - movs r0, 0x54 - movs r1, 0x7 - bl SetGpuReg - bl RtcGetErrorStatus - movs r1, 0xFF - lsls r1, 4 - ands r1, r0 - cmp r1, 0 - bne _0802FB28 - ldr r0, =gTasks - lsls r1, r4, 2 - adds r1, r4 - lsls r1, 3 - adds r1, r0 - ldr r0, =Task_DisplayMainMenu - str r0, [r1] - b _0802FB3C - .pool -_0802FB28: - ldr r0, =gText_BatteryRunDry - bl CreateMainMenuErrorWindow - ldr r1, =gTasks - lsls r0, r5, 2 - adds r0, r5 - lsls r0, 3 - adds r0, r1 - ldr r1, =Task_WaitForBatteryDryErrorWindow - str r1, [r0] -_0802FB3C: - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end Task_MainMenuCheckBattery - - thumb_func_start Task_WaitForBatteryDryErrorWindow -@ void Task_WaitForBatteryDryErrorWindow(u8 taskId) -Task_WaitForBatteryDryErrorWindow: @ 802FB50 - push {r4,lr} - lsls r0, 24 - lsrs r4, r0, 24 - bl RunTextPrinters - movs r0, 0x7 - bl IsTextPrinterActive - lsls r0, 16 - cmp r0, 0 - bne _0802FB8C - ldr r0, =gMain - ldrh r1, [r0, 0x2E] - movs r0, 0x1 - ands r0, r1 - cmp r0, 0 - beq _0802FB8C - movs r0, 0x7 - bl ClearWindowTilemap - ldr r0, =gUnknown_082FF070 - bl sub_8032250 - ldr r1, =gTasks - lsls r0, r4, 2 - adds r0, r4 - lsls r0, 3 - adds r0, r1 - ldr r1, =Task_DisplayMainMenu - str r1, [r0] -_0802FB8C: - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end Task_WaitForBatteryDryErrorWindow - - thumb_func_start Task_DisplayMainMenu -@ void Task_DisplayMainMenu(u8 taskId) -Task_DisplayMainMenu: @ 802FBA4 - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - sub sp, 0x10 - lsls r0, 24 - lsrs r7, r0, 24 - lsls r0, r7, 2 - adds r0, r7 - lsls r0, 3 - ldr r1, =gTasks + 0x8 - adds r6, r0, r1 - ldr r0, =gPaletteFade - ldrb r1, [r0, 0x7] - movs r0, 0x80 - ands r0, r1 - lsls r0, 24 - lsrs r4, r0, 24 - cmp r4, 0 - beq _0802FBCE - b _0803006C -_0802FBCE: - movs r0, 0x40 - movs r1, 0 - bl SetGpuReg - movs r0, 0x44 - movs r1, 0 - bl SetGpuReg - movs r0, 0x48 - movs r1, 0x11 - bl SetGpuReg - movs r0, 0x4A - movs r1, 0x31 - bl SetGpuReg - movs r0, 0x50 - movs r1, 0xC1 - bl SetGpuReg - movs r0, 0x52 - movs r1, 0 - bl SetGpuReg - movs r0, 0x54 - movs r1, 0x7 - bl SetGpuReg - add r0, sp, 0xC - strh r4, [r0] - movs r1, 0xFE - movs r2, 0x2 - bl LoadPalette - add r1, sp, 0xC - ldr r2, =0x00007fff - adds r0, r2, 0 - strh r0, [r1] - adds r0, r1, 0 - movs r1, 0xFA - movs r2, 0x2 - bl LoadPalette - add r1, sp, 0xC - ldr r2, =0x0000318c - adds r0, r2, 0 - strh r0, [r1] - adds r0, r1, 0 - movs r1, 0xFB - movs r2, 0x2 - bl LoadPalette - add r1, sp, 0xC - ldr r2, =0x0000675a - adds r0, r2, 0 - strh r0, [r1] - adds r0, r1, 0 - movs r1, 0xFC - movs r2, 0x2 - bl LoadPalette - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldrb r0, [r0, 0x8] - cmp r0, 0 - bne _0802FC84 - add r1, sp, 0xC - ldr r2, =0x00007e04 - adds r0, r2, 0 - strh r0, [r1] - adds r0, r1, 0 - movs r1, 0xF1 - movs r2, 0x2 - bl LoadPalette - b _0802FC96 - .pool -_0802FC84: - add r1, sp, 0xC - ldr r2, =0x0000547f - adds r0, r2, 0 - strh r0, [r1] - adds r0, r1, 0 - movs r1, 0xF1 - movs r2, 0x2 - bl LoadPalette -_0802FC96: - ldr r0, =gTasks - mov r8, r0 - lsls r1, r7, 2 - adds r0, r1, r7 - lsls r0, 3 - add r0, r8 - movs r2, 0x8 - ldrsh r0, [r0, r2] - mov r9, r1 - cmp r0, 0x1 - beq _0802FD44 - cmp r0, 0x1 - ble _0802FCBC - cmp r0, 0x2 - bne _0802FCB6 - b _0802FE00 -_0802FCB6: - cmp r0, 0x3 - bne _0802FCBC - b _0802FEFC -_0802FCBC: - movs r0, 0 - movs r1, 0xAA - bl FillWindowPixelBuffer - movs r0, 0x1 - movs r1, 0xAA - bl FillWindowPixelBuffer - ldr r5, =gUnknown_082FF0E0 - str r5, [sp] - movs r4, 0x1 - negs r4, r4 - str r4, [sp, 0x4] - ldr r0, =gText_MainMenuNewGame - str r0, [sp, 0x8] - movs r0, 0 - movs r1, 0x1 - movs r2, 0 - movs r3, 0x1 - bl box_print - str r5, [sp] - str r4, [sp, 0x4] - ldr r0, =gText_MainMenuOption - str r0, [sp, 0x8] - movs r0, 0x1 - movs r1, 0x1 - movs r2, 0 - movs r3, 0x1 - bl box_print - movs r0, 0 - bl PutWindowTilemap - movs r0, 0x1 - bl PutWindowTilemap - movs r0, 0 - movs r1, 0x2 - bl CopyWindowToVram - movs r0, 0x1 - movs r1, 0x2 - bl CopyWindowToVram - ldr r4, =gUnknown_082FF038 - ldr r5, =0x000001d5 - adds r0, r4, 0 - adds r1, r5, 0 - bl DrawMainMenuWindowBorder - adds r4, 0x8 - b _0802FED4 - .pool -_0802FD44: - movs r0, 0x2 - movs r1, 0xAA - bl FillWindowPixelBuffer - movs r0, 0x3 - movs r1, 0xAA - bl FillWindowPixelBuffer - movs r0, 0x4 - movs r1, 0xAA - bl FillWindowPixelBuffer - ldr r5, =gUnknown_082FF0E0 - str r5, [sp] - movs r4, 0x1 - negs r4, r4 - str r4, [sp, 0x4] - ldr r0, =gText_MainMenuContinue - str r0, [sp, 0x8] - movs r0, 0x2 - movs r1, 0x1 - movs r2, 0 - movs r3, 0x1 - bl box_print - str r5, [sp] - str r4, [sp, 0x4] - ldr r0, =gText_MainMenuNewGame - str r0, [sp, 0x8] - movs r0, 0x3 - movs r1, 0x1 - movs r2, 0 - movs r3, 0x1 - bl box_print - str r5, [sp] - str r4, [sp, 0x4] - ldr r0, =gText_MainMenuOption - str r0, [sp, 0x8] - movs r0, 0x4 - movs r1, 0x1 - movs r2, 0 - movs r3, 0x1 - bl box_print - bl fmt_savegame - movs r0, 0x2 - bl PutWindowTilemap - movs r0, 0x3 - bl PutWindowTilemap - movs r0, 0x4 - bl PutWindowTilemap - movs r0, 0x2 - movs r1, 0x2 - bl CopyWindowToVram - movs r0, 0x3 - movs r1, 0x2 - bl CopyWindowToVram - movs r0, 0x4 - movs r1, 0x2 - bl CopyWindowToVram - ldr r4, =gUnknown_082FF048 - ldr r5, =0x000001d5 - adds r0, r4, 0 - adds r1, r5, 0 - bl DrawMainMenuWindowBorder - adds r0, r4, 0 - adds r0, 0x8 - adds r1, r5, 0 - bl DrawMainMenuWindowBorder - adds r4, 0x10 - b _0802FED4 - .pool -_0802FE00: - movs r0, 0x2 - movs r1, 0xAA - bl FillWindowPixelBuffer - movs r0, 0x3 - movs r1, 0xAA - bl FillWindowPixelBuffer - movs r0, 0x4 - movs r1, 0xAA - bl FillWindowPixelBuffer - movs r0, 0x5 - movs r1, 0xAA - bl FillWindowPixelBuffer - ldr r5, =gUnknown_082FF0E0 - str r5, [sp] - movs r4, 0x1 - negs r4, r4 - str r4, [sp, 0x4] - ldr r0, =gText_MainMenuContinue - str r0, [sp, 0x8] - movs r0, 0x2 - movs r1, 0x1 - movs r2, 0 - movs r3, 0x1 - bl box_print - str r5, [sp] - str r4, [sp, 0x4] - ldr r0, =gText_MainMenuNewGame - str r0, [sp, 0x8] - movs r0, 0x3 - movs r1, 0x1 - movs r2, 0 - movs r3, 0x1 - bl box_print - str r5, [sp] - str r4, [sp, 0x4] - ldr r0, =gText_MainMenuMysteryGift - str r0, [sp, 0x8] - movs r0, 0x4 - movs r1, 0x1 - movs r2, 0 - movs r3, 0x1 - bl box_print - str r5, [sp] - str r4, [sp, 0x4] - ldr r0, =gText_MainMenuOption - str r0, [sp, 0x8] - movs r0, 0x5 - movs r1, 0x1 - movs r2, 0 - movs r3, 0x1 - bl box_print - bl fmt_savegame - movs r0, 0x2 - bl PutWindowTilemap - movs r0, 0x3 - bl PutWindowTilemap - movs r0, 0x4 - bl PutWindowTilemap - movs r0, 0x5 - bl PutWindowTilemap - movs r0, 0x2 - movs r1, 0x2 - bl CopyWindowToVram - movs r0, 0x3 - movs r1, 0x2 - bl CopyWindowToVram - movs r0, 0x4 - movs r1, 0x2 - bl CopyWindowToVram - movs r0, 0x5 - movs r1, 0x2 - bl CopyWindowToVram - ldr r4, =gUnknown_082FF048 - ldr r5, =0x000001d5 - adds r0, r4, 0 - adds r1, r5, 0 - bl DrawMainMenuWindowBorder - adds r0, r4, 0 - adds r0, 0x8 - adds r1, r5, 0 - bl DrawMainMenuWindowBorder - adds r0, r4, 0 - adds r0, 0x10 - adds r1, r5, 0 - bl DrawMainMenuWindowBorder - adds r4, 0x18 -_0802FED4: - adds r0, r4, 0 - adds r1, r5, 0 - bl DrawMainMenuWindowBorder - b _0803005E - .pool -_0802FEFC: - movs r0, 0x2 - movs r1, 0xAA - bl FillWindowPixelBuffer - movs r0, 0x3 - movs r1, 0xAA - bl FillWindowPixelBuffer - movs r0, 0x4 - movs r1, 0xAA - bl FillWindowPixelBuffer - movs r0, 0x5 - movs r1, 0xAA - bl FillWindowPixelBuffer - movs r0, 0x6 - movs r1, 0xAA - bl FillWindowPixelBuffer - ldr r5, =gUnknown_082FF0E0 - str r5, [sp] - movs r4, 0x1 - negs r4, r4 - str r4, [sp, 0x4] - ldr r0, =gText_MainMenuContinue - str r0, [sp, 0x8] - movs r0, 0x2 - movs r1, 0x1 - movs r2, 0 - movs r3, 0x1 - bl box_print - str r5, [sp] - str r4, [sp, 0x4] - ldr r0, =gText_MainMenuNewGame - str r0, [sp, 0x8] - movs r0, 0x3 - movs r1, 0x1 - movs r2, 0 - movs r3, 0x1 - bl box_print - str r5, [sp] - str r4, [sp, 0x4] - ldr r0, =gText_MainMenuMysteryGift2 - str r0, [sp, 0x8] - movs r0, 0x4 - movs r1, 0x1 - movs r2, 0 - movs r3, 0x1 - bl box_print - str r5, [sp] - str r4, [sp, 0x4] - ldr r0, =gText_MainMenuMysteryEvents - str r0, [sp, 0x8] - movs r0, 0x5 - movs r1, 0x1 - movs r2, 0 - movs r3, 0x1 - bl box_print - str r5, [sp] - str r4, [sp, 0x4] - ldr r0, =gText_MainMenuOption - str r0, [sp, 0x8] - movs r0, 0x6 - movs r1, 0x1 - movs r2, 0 - movs r3, 0x1 - bl box_print - bl fmt_savegame - movs r0, 0x2 - bl PutWindowTilemap - movs r0, 0x3 - bl PutWindowTilemap - movs r0, 0x4 - bl PutWindowTilemap - movs r0, 0x5 - bl PutWindowTilemap - movs r0, 0x6 - bl PutWindowTilemap - movs r0, 0x2 - movs r1, 0x2 - bl CopyWindowToVram - movs r0, 0x3 - movs r1, 0x2 - bl CopyWindowToVram - movs r0, 0x4 - movs r1, 0x2 - bl CopyWindowToVram - movs r0, 0x5 - movs r1, 0x2 - bl CopyWindowToVram - movs r0, 0x6 - movs r1, 0x2 - bl CopyWindowToVram - ldr r5, =gUnknown_082FF048 - ldr r4, =0x000001d5 - adds r0, r5, 0 - adds r1, r4, 0 - bl DrawMainMenuWindowBorder - adds r0, r5, 0 - adds r0, 0x8 - adds r1, r4, 0 - bl DrawMainMenuWindowBorder - adds r0, r5, 0 - adds r0, 0x10 - adds r1, r4, 0 - bl DrawMainMenuWindowBorder - adds r0, r5, 0 - adds r0, 0x18 - adds r1, r4, 0 - bl DrawMainMenuWindowBorder - adds r0, r5, 0 - adds r0, 0x20 - adds r1, r4, 0 - bl DrawMainMenuWindowBorder - ldr r0, =gUnknown_082FF0F4 - ldr r4, =gUnknown_02022D06 - adds r1, r4, 0 - bl AddScrollIndicatorArrowPair - lsls r0, 24 - lsrs r0, 24 - strh r0, [r6, 0x1A] - movs r0, 0x1A - ldrsh r1, [r6, r0] - lsls r0, r1, 2 - adds r0, r1 - lsls r0, 3 - add r0, r8 - ldr r1, =Task_ScrollIndicatorArrowPairOnMainMenu - str r1, [r0] - ldrh r0, [r4] - cmp r0, 0x4 - bne _0803005E - movs r4, 0x80 - lsls r4, 6 - movs r0, 0 - adds r1, r4, 0 - movs r2, 0x1 - bl ChangeBgY - movs r0, 0x1 - adds r1, r4, 0 - movs r2, 0x1 - bl ChangeBgY - movs r0, 0x1 - strh r0, [r6, 0x1C] - movs r2, 0x1A - ldrsh r1, [r6, r2] - lsls r0, r1, 2 - adds r0, r1 - lsls r0, 3 - add r0, r8 - movs r1, 0x1 - strh r1, [r0, 0x26] -_0803005E: - ldr r0, =gTasks - mov r2, r9 - adds r1, r2, r7 - lsls r1, 3 - adds r1, r0 - ldr r0, =Task_HighlightSelectedMainMenuItem - str r0, [r1] -_0803006C: - add sp, 0x10 - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end Task_DisplayMainMenu - - thumb_func_start Task_HighlightSelectedMainMenuItem -@ void Task_HighlightSelectedMainMenuItem(u8 taskId) -Task_HighlightSelectedMainMenuItem: @ 80300B0 - push {r4,lr} - lsls r0, 24 - lsrs r0, 24 - ldr r1, =gTasks - lsls r4, r0, 2 - adds r4, r0 - lsls r4, 3 - adds r4, r1 - ldrb r0, [r4, 0x8] - ldrb r1, [r4, 0xA] - movs r3, 0x24 - ldrsh r2, [r4, r3] - bl HighlightSelectedMainMenuItem - ldr r0, =Task_HandleMainMenuInput - str r0, [r4] - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end Task_HighlightSelectedMainMenuItem - - thumb_func_start HandleMainMenuInput -@ u8 HandleMainMenuInput(u8 taskId) -HandleMainMenuInput: @ 80300E0 - push {r4-r7,lr} - sub sp, 0x4 - lsls r0, 24 - lsrs r0, 24 - lsls r1, r0, 2 - adds r1, r0 - lsls r4, r1, 3 - ldr r7, =gTasks + 0x8 - adds r5, r4, r7 - ldr r1, =gMain - ldrh r2, [r1, 0x2E] - movs r0, 0x1 - ands r0, r2 - cmp r0, 0 - beq _08030130 - movs r0, 0x5 - bl PlaySE - bl sub_80093CC - movs r0, 0x1 - negs r0, r0 - movs r1, 0 - str r1, [sp] - movs r2, 0 - movs r3, 0x10 - bl BeginNormalPaletteFade - adds r0, r7, 0 - subs r0, 0x8 - adds r0, r4, r0 - ldr r1, =Task_HandleMainMenuAPressed - str r1, [r0] - b _08030240 - .pool -_08030130: - movs r0, 0x2 - ands r0, r2 - lsls r0, 16 - lsrs r6, r0, 16 - cmp r6, 0 - beq _08030178 - movs r0, 0x5 - bl PlaySE - movs r0, 0x1 - negs r0, r0 - ldr r1, =0x0000ffff - str r1, [sp] - movs r1, 0 - movs r2, 0 - movs r3, 0x10 - bl BeginNormalPaletteFade - movs r0, 0x40 - movs r1, 0xF0 - bl SetGpuReg - movs r0, 0x44 - movs r1, 0xA0 - bl SetGpuReg - adds r0, r7, 0 - subs r0, 0x8 - adds r0, r4, r0 - ldr r1, =Task_HandleMainMenuBPressed - str r1, [r0] - b _08030240 - .pool -_08030178: - movs r0, 0x40 - ands r0, r2 - cmp r0, 0 - beq _080301CA - movs r0, 0x2 - ldrsh r2, [r5, r0] - cmp r2, 0 - ble _080301CA - movs r1, 0 - ldrsh r0, [r5, r1] - cmp r0, 0x3 - bne _080301C4 - movs r1, 0x1C - ldrsh r0, [r5, r1] - cmp r0, 0x1 - bne _080301C4 - cmp r2, 0x1 - bne _080301C4 - movs r4, 0x80 - lsls r4, 6 - movs r0, 0 - adds r1, r4, 0 - movs r2, 0x2 - bl ChangeBgY - movs r0, 0x1 - adds r1, r4, 0 - movs r2, 0x2 - bl ChangeBgY - movs r2, 0x1A - ldrsh r1, [r5, r2] - lsls r0, r1, 2 - adds r0, r1 - lsls r0, 3 - adds r0, r7, r0 - strh r6, [r5, 0x1C] - strh r6, [r0, 0x1E] -_080301C4: - ldrh r0, [r5, 0x2] - subs r0, 0x1 - b _0803022C -_080301CA: - ldrh r1, [r1, 0x2E] - movs r0, 0x80 - ands r0, r1 - cmp r0, 0 - beq _08030240 - movs r0, 0x2 - ldrsh r1, [r5, r0] - movs r2, 0x18 - ldrsh r0, [r5, r2] - subs r0, 0x1 - cmp r1, r0 - bge _08030240 - movs r1, 0 - ldrsh r0, [r5, r1] - cmp r0, 0x3 - bne _08030228 - movs r2, 0x2 - ldrsh r0, [r5, r2] - cmp r0, 0x3 - bne _08030228 - movs r1, 0x1C - ldrsh r0, [r5, r1] - cmp r0, 0 - bne _08030228 - movs r4, 0x80 - lsls r4, 6 - movs r0, 0 - adds r1, r4, 0 - movs r2, 0x1 - bl ChangeBgY - movs r0, 0x1 - adds r1, r4, 0 - movs r2, 0x1 - bl ChangeBgY - ldr r2, =gTasks - movs r0, 0x1A - ldrsh r1, [r5, r0] - lsls r0, r1, 2 - adds r0, r1 - lsls r0, 3 - adds r0, r2 - movs r1, 0x1 - strh r1, [r5, 0x1C] - movs r1, 0x1 - strh r1, [r0, 0x26] -_08030228: - ldrh r0, [r5, 0x2] - adds r0, 0x1 -_0803022C: - strh r0, [r5, 0x2] - ldr r1, =gUnknown_02022D06 - strh r0, [r1] - movs r0, 0x1 - b _08030242 - .pool -_08030240: - movs r0, 0 -_08030242: - add sp, 0x4 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end HandleMainMenuInput - - thumb_func_start Task_HandleMainMenuInput -@ void Task_HandleMainMenuInput(u8 taskId) -Task_HandleMainMenuInput: @ 803024C - push {r4,lr} - lsls r0, 24 - lsrs r4, r0, 24 - adds r0, r4, 0 - bl HandleMainMenuInput - lsls r0, 24 - cmp r0, 0 - beq _0803026C - ldr r0, =gTasks - lsls r1, r4, 2 - adds r1, r4 - lsls r1, 3 - adds r1, r0 - ldr r0, =Task_HighlightSelectedMainMenuItem - str r0, [r1] -_0803026C: - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end Task_HandleMainMenuInput - - thumb_func_start Task_HandleMainMenuAPressed -@ void Task_HandleMainMenuAPressed(int task_id) -Task_HandleMainMenuAPressed: @ 803027C - push {r4-r7,lr} - sub sp, 0x4 - lsls r0, 24 - lsrs r6, r0, 24 - ldr r0, =gPaletteFade - ldrb r1, [r0, 0x7] - movs r0, 0x80 - ands r0, r1 - cmp r0, 0 - beq _08030292 - b _08030536 -_08030292: - ldr r2, =gTasks - lsls r1, r6, 2 - adds r0, r1, r6 - lsls r0, 3 - adds r4, r0, r2 - movs r2, 0x8 - ldrsh r0, [r4, r2] - adds r7, r1, 0 - cmp r0, 0x3 - bne _080302B0 - ldrh r0, [r4, 0x22] - lsls r0, 24 - lsrs r0, 24 - bl RemoveScrollIndicatorArrowPair -_080302B0: - movs r0, 0 - movs r1, 0x1 - bl sub_819746C - movs r0, 0x1 - movs r1, 0x1 - bl sub_819746C - movs r0, 0x2 - movs r1, 0x1 - bl sub_819746C - movs r0, 0x3 - movs r1, 0x1 - bl sub_819746C - movs r0, 0x4 - movs r1, 0x1 - bl sub_819746C - movs r0, 0x5 - movs r1, 0x1 - bl sub_819746C - movs r0, 0x6 - movs r1, 0x1 - bl sub_819746C - movs r0, 0x7 - movs r1, 0x1 - bl sub_819746C - bl sub_80093CC - lsls r0, 24 - lsrs r2, r0, 24 - movs r3, 0x8 - ldrsh r0, [r4, r3] - cmp r0, 0x1 - beq _08030324 - cmp r0, 0x1 - ble _0803030C - cmp r0, 0x2 - beq _08030336 - cmp r0, 0x3 - beq _08030358 -_0803030C: - movs r1, 0xA - ldrsh r0, [r4, r1] - cmp r0, 0 - beq _08030388 - cmp r0, 0x1 - bne _08030388 - b _080303D8 - .pool -_08030324: - movs r2, 0xA - ldrsh r0, [r4, r2] - cmp r0, 0x1 - beq _08030388 - cmp r0, 0x1 - ble _08030384 - cmp r0, 0x2 - bne _08030384 - b _080303D8 -_08030336: - movs r3, 0xA - ldrsh r0, [r4, r3] - cmp r0, 0x1 - beq _08030388 - cmp r0, 0x1 - ble _08030384 - cmp r0, 0x2 - beq _0803034C - cmp r0, 0x3 - beq _080303D8 - b _08030384 -_0803034C: - movs r5, 0x3 - cmp r2, 0 - bne _080303DA - movs r5, 0x6 - strh r2, [r4, 0x8] - b _080303DA -_08030358: - movs r1, 0xA - ldrsh r0, [r4, r1] - cmp r0, 0x4 - bhi _08030384 - lsls r0, 2 - ldr r1, =_08030370 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_08030370: - .4byte _08030384 - .4byte _08030388 - .4byte _0803038C - .4byte _080303BC - .4byte _080303D8 -_08030384: - movs r5, 0x1 - b _080303DA -_08030388: - movs r5, 0 - b _080303DA -_0803038C: - ldr r0, =gTasks - adds r1, r7, r6 - lsls r1, 3 - adds r1, r0 - movs r3, 0x26 - ldrsh r0, [r1, r3] - cmp r0, 0 - beq _080303AC - movs r5, 0x3 - cmp r2, 0 - bne _080303DA - movs r5, 0x6 - strh r2, [r1, 0x8] - b _080303DA - .pool -_080303AC: - cmp r2, 0 - beq _080303B8 - movs r5, 0x6 - movs r0, 0x1 - strh r0, [r1, 0x8] - b _080303DA -_080303B8: - movs r5, 0x5 - b _080303DA -_080303BC: - cmp r2, 0 - beq _080303D4 - movs r5, 0x6 - ldr r0, =gTasks - adds r1, r7, r6 - lsls r1, 3 - adds r1, r0 - movs r0, 0x2 - strh r0, [r1, 0x8] - b _080303DA - .pool -_080303D4: - movs r5, 0x4 - b _080303DA -_080303D8: - movs r5, 0x2 -_080303DA: - movs r0, 0 - movs r1, 0 - movs r2, 0 - bl ChangeBgY - movs r0, 0x1 - movs r1, 0 - movs r2, 0 - bl ChangeBgY - cmp r5, 0x6 - bhi _0803041C - lsls r0, r5, 2 - ldr r1, =_08030400 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_08030400: - .4byte _0803041C - .4byte _08030444 - .4byte _08030460 - .4byte _08030478 - .4byte _08030480 - .4byte _08030488 - .4byte _0803049C -_0803041C: - ldr r0, =gPlttBufferUnfaded - movs r1, 0 - strh r1, [r0] - ldr r0, =gPlttBufferFaded - strh r1, [r0] - ldr r1, =gTasks - adds r0, r7, r6 - lsls r0, 3 - adds r0, r1 - ldr r1, =task_new_game_prof_birch_speech_1 - str r1, [r0] - b _08030514 - .pool -_08030444: - ldr r0, =gPlttBufferUnfaded - movs r1, 0 - strh r1, [r0] - ldr r0, =gPlttBufferFaded - strh r1, [r0] - ldr r0, =sub_8086230 - b _0803048A - .pool -_08030460: - ldr r0, =gMain - ldr r1, =CB2_ReinitMainMenu - str r1, [r0, 0x8] - ldr r0, =CB2_InitOptionMenu - b _0803048A - .pool -_08030478: - ldr r0, =c2_mystery_gift - b _0803048A - .pool -_08030480: - ldr r0, =CB2_InitMysteryEventMenu - b _0803048A - .pool -_08030488: - ldr r0, =sub_801867C -_0803048A: - bl SetMainCallback2 - adds r0, r6, 0 - bl DestroyTask - b _08030514 - .pool -_0803049C: - ldr r1, =gTasks - adds r0, r7, r6 - lsls r0, 3 - adds r0, r1 - movs r4, 0 - strh r4, [r0, 0xA] - ldr r1, =Task_DisplayMainMenuInvalidActionError - str r1, [r0] - ldr r0, =gPlttBufferUnfaded - movs r2, 0xF1 - lsls r2, 1 - adds r0, r2 - ldr r1, =0x00007fff - strh r1, [r0] - ldr r0, =gPlttBufferFaded - adds r0, r2 - strh r1, [r0] - movs r0, 0x18 - movs r1, 0 - bl SetGpuReg - movs r0, 0x1A - movs r1, 0 - bl SetGpuReg - movs r0, 0x14 - movs r1, 0 - bl SetGpuReg - movs r0, 0x16 - movs r1, 0 - bl SetGpuReg - movs r0, 0x10 - movs r1, 0 - bl SetGpuReg - movs r0, 0x12 - movs r1, 0 - bl SetGpuReg - movs r0, 0x1 - negs r0, r0 - str r4, [sp] - movs r1, 0 - movs r2, 0x10 - movs r3, 0 - bl BeginNormalPaletteFade - b _08030536 - .pool -_08030514: - bl FreeAllWindowBuffers - cmp r5, 0x2 - beq _08030528 - ldr r1, =gUnknown_02022D06 - movs r0, 0 - strh r0, [r1] - b _08030536 - .pool -_08030528: - ldr r0, =gUnknown_02022D06 - ldrh r1, [r0] - movs r3, 0x80 - lsls r3, 8 - adds r2, r3, 0 - orrs r1, r2 - strh r1, [r0] -_08030536: - add sp, 0x4 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end Task_HandleMainMenuAPressed - - thumb_func_start Task_HandleMainMenuBPressed -@ void Task_HandleMainMenuBPressed(u8 taskId) -Task_HandleMainMenuBPressed: @ 8030544 - push {r4,r5,lr} - lsls r0, 24 - lsrs r2, r0, 24 - adds r5, r2, 0 - ldr r0, =gPaletteFade - ldrb r1, [r0, 0x7] - movs r0, 0x80 - ands r0, r1 - lsls r0, 24 - lsrs r4, r0, 24 - cmp r4, 0 - bne _0803058C - ldr r0, =gTasks - lsls r1, r2, 2 - adds r1, r2 - lsls r1, 3 - adds r1, r0 - movs r2, 0x8 - ldrsh r0, [r1, r2] - cmp r0, 0x3 - bne _08030578 - ldrh r0, [r1, 0x22] - lsls r0, 24 - lsrs r0, 24 - bl RemoveScrollIndicatorArrowPair -_08030578: - ldr r0, =gUnknown_02022D06 - strh r4, [r0] - bl FreeAllWindowBuffers - ldr r0, =c2_title_screen_1 - bl SetMainCallback2 - adds r0, r5, 0 - bl DestroyTask -_0803058C: - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end Task_HandleMainMenuBPressed - - thumb_func_start Task_DisplayMainMenuInvalidActionError -@ void Task_DisplayMainMenuInvalidActionError(u8 taskId) -Task_DisplayMainMenuInvalidActionError: @ 80305A4 - push {r4,r5,lr} - sub sp, 0x8 - lsls r0, 24 - lsrs r5, r0, 24 - ldr r1, =gTasks - lsls r0, r5, 2 - adds r0, r5 - lsls r0, 3 - adds r4, r0, r1 - movs r0, 0xA - ldrsh r1, [r4, r0] - cmp r1, 0x1 - beq _0803063C - cmp r1, 0x1 - bgt _080305CC - cmp r1, 0 - beq _080305D6 - b _08030688 - .pool -_080305CC: - cmp r1, 0x2 - beq _0803064C - cmp r1, 0x3 - beq _08030664 - b _08030688 -_080305D6: - movs r0, 0x1E - str r0, [sp] - movs r0, 0x14 - str r0, [sp, 0x4] - movs r0, 0 - movs r1, 0 - movs r2, 0 - movs r3, 0 - bl FillBgTilemapBufferRect_Palette0 - movs r1, 0x8 - ldrsh r0, [r4, r1] - cmp r0, 0x1 - beq _08030610 - cmp r0, 0x1 - bgt _080305FC - cmp r0, 0 - beq _08030602 - b _08030622 -_080305FC: - cmp r0, 0x2 - beq _0803061C - b _08030622 -_08030602: - ldr r0, =gText_WirelessNotConnected - bl CreateMainMenuErrorWindow - b _08030622 - .pool -_08030610: - ldr r0, =gText_MysteryGiftCantUse - bl CreateMainMenuErrorWindow - b _08030622 - .pool -_0803061C: - ldr r0, =gText_MysteryEventsCantUse - bl CreateMainMenuErrorWindow -_08030622: - ldr r0, =gTasks - lsls r1, r5, 2 - adds r1, r5 - lsls r1, 3 - adds r1, r0 - ldrh r0, [r1, 0xA] - adds r0, 0x1 - strh r0, [r1, 0xA] - b _08030688 - .pool -_0803063C: - ldr r0, =gPaletteFade - ldrb r1, [r0, 0x7] - movs r0, 0x80 - ands r0, r1 - b _08030658 - .pool -_0803064C: - bl RunTextPrinters - movs r0, 0x7 - bl IsTextPrinterActive - lsls r0, 16 -_08030658: - cmp r0, 0 - bne _08030688 - ldrh r0, [r4, 0xA] - adds r0, 0x1 - strh r0, [r4, 0xA] - b _08030688 -_08030664: - ldr r0, =gMain - ldrh r0, [r0, 0x2E] - ands r1, r0 - cmp r1, 0 - beq _08030688 - movs r0, 0x5 - bl PlaySE - movs r0, 0x1 - negs r0, r0 - movs r1, 0 - str r1, [sp] - movs r2, 0 - movs r3, 0x10 - bl BeginNormalPaletteFade - ldr r0, =Task_HandleMainMenuBPressed - str r0, [r4] -_08030688: - add sp, 0x8 - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end Task_DisplayMainMenuInvalidActionError - - thumb_func_start HighlightSelectedMainMenuItem -@ void HighlightSelectedMainMenuItem(u8 a1, u8 selectedMenuItem, u16 a3) -HighlightSelectedMainMenuItem: @ 8030698 - push {r4-r6,lr} - lsls r0, 24 - lsrs r5, r0, 24 - lsls r1, 24 - lsrs r4, r1, 24 - lsls r2, 16 - lsrs r6, r2, 16 - ldr r1, =0x000009e7 - movs r0, 0x40 - bl SetGpuReg - cmp r5, 0x1 - beq _080306DC - cmp r5, 0x1 - ble _080306BE - cmp r5, 0x2 - beq _08030700 - cmp r5, 0x3 - beq _08030728 -_080306BE: - cmp r4, 0 - beq _080306C6 - cmp r4, 0x1 - beq _080306D4 -_080306C6: - ldr r1, =0x0000011f - b _0803078E - .pool -_080306D4: - ldr r1, =0x0000213f - b _0803078E - .pool -_080306DC: - cmp r4, 0x1 - beq _080306F0 - cmp r4, 0x1 - ble _080306E8 - cmp r4, 0x2 - beq _080306F8 -_080306E8: - ldr r1, =0x0000013f - b _0803078E - .pool -_080306F0: - ldr r1, =0x0000415f - b _0803078E - .pool -_080306F8: - ldr r1, =0x0000617f - b _0803078E - .pool -_08030700: - cmp r4, 0x1 - beq _08030718 - cmp r4, 0x1 - ble _08030710 - cmp r4, 0x2 - beq _08030720 - cmp r4, 0x3 - beq _0803078C -_08030710: - ldr r1, =0x0000013f - b _0803078E - .pool -_08030718: - ldr r1, =0x0000415f - b _0803078E - .pool -_08030720: - ldr r1, =0x0000617f - b _0803078E - .pool -_08030728: - cmp r4, 0x4 - bhi _08030750 - lsls r0, r4, 2 - ldr r1, =_0803073C - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_0803073C: - .4byte _08030750 - .4byte _08030758 - .4byte _0803076C - .4byte _08030780 - .4byte _0803079C -_08030750: - ldr r1, =0x0000013f - b _0803078E - .pool -_08030758: - cmp r6, 0 - beq _08030764 - ldr r1, =0x0000213f - b _0803078E - .pool -_08030764: - ldr r1, =0x0000415f - b _0803078E - .pool -_0803076C: - cmp r6, 0 - beq _08030778 - ldr r1, =0x0000415f - b _0803078E - .pool -_08030778: - ldr r1, =0x0000617f - b _0803078E - .pool -_08030780: - cmp r6, 0 - beq _0803078C - ldr r1, =0x0000617f - b _0803078E - .pool -_0803078C: - ldr r1, =0x0000819f -_0803078E: - movs r0, 0x44 - bl SetGpuReg - b _080307A4 - .pool -_0803079C: - ldr r1, =0x0000819f - movs r0, 0x44 - bl SetGpuReg -_080307A4: - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end HighlightSelectedMainMenuItem - - thumb_func_start task_new_game_prof_birch_speech_1 -@ void task_new_game_prof_birch_speech_1(int task_id) -task_new_game_prof_birch_speech_1: @ 80307B0 - push {r4,r5,lr} - sub sp, 0x4 - adds r4, r0, 0 - lsls r4, 24 - lsrs r4, 24 - movs r0, 0 - movs r1, 0 - bl SetGpuReg - movs r1, 0x82 - lsls r1, 5 - movs r0, 0 - bl SetGpuReg - ldr r0, =gUnknown_082FF0F0 - bl InitBgFromTemplate - movs r0, 0x40 - movs r1, 0 - bl SetGpuReg - movs r0, 0x44 - movs r1, 0 - bl SetGpuReg - movs r0, 0x48 - movs r1, 0 - bl SetGpuReg - movs r0, 0x4A - movs r1, 0 - bl SetGpuReg - movs r0, 0x50 - movs r1, 0 - bl SetGpuReg - movs r0, 0x52 - movs r1, 0 - bl SetGpuReg - movs r0, 0x54 - movs r1, 0 - bl SetGpuReg - ldr r0, =gBirchIntroShadowGfx - movs r1, 0xC0 - lsls r1, 19 - bl LZ77UnCompVram - ldr r0, =gUnknown_082FEEF0 - ldr r1, =0x06003800 - bl LZ77UnCompVram - ldr r0, =gUnknown_082FECFC - movs r1, 0 - movs r2, 0x40 - bl LoadPalette - ldr r0, =gUnknown_082FF028 - movs r1, 0x1 - movs r2, 0x10 - bl LoadPalette - bl ScanlineEffect_Stop - bl ResetSpriteData - bl FreeAllSpritePalettes - bl dp13_810BB8C - adds r0, r4, 0 - bl AddBirchSpeechObjects - movs r0, 0x1 - negs r0, r0 - movs r5, 0 - str r5, [sp] - movs r1, 0 - movs r2, 0x10 - movs r3, 0 - bl BeginNormalPaletteFade - ldr r1, =gTasks - lsls r0, r4, 2 - adds r0, r4 - lsls r0, 3 - adds r0, r1 - strh r5, [r0, 0x10] - ldr r1, =task_new_game_prof_birch_speech_2 - str r1, [r0] - movs r1, 0xFF - strh r1, [r0, 0xC] - strh r1, [r0, 0xE] - movs r1, 0xD8 - strh r1, [r0, 0x16] - movs r0, 0xBB - lsls r0, 1 - bl PlayBGM - movs r0, 0 - bl ShowBg - movs r0, 0x1 - bl ShowBg - add sp, 0x4 - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end task_new_game_prof_birch_speech_1 - - thumb_func_start task_new_game_prof_birch_speech_2 -task_new_game_prof_birch_speech_2: @ 80308B0 - push {r4,r5,lr} - lsls r0, 24 - lsrs r5, r0, 24 - ldr r1, =gTasks - lsls r0, r5, 2 - adds r0, r5 - lsls r0, 3 - adds r4, r0, r1 - ldrh r1, [r4, 0x16] - movs r2, 0x16 - ldrsh r0, [r4, r2] - cmp r0, 0 - beq _080308D4 - subs r0, r1, 0x1 - strh r0, [r4, 0x16] - b _0803091A - .pool -_080308D4: - ldrb r0, [r4, 0x18] - ldr r2, =gSprites - lsls r1, r0, 4 - adds r1, r0 - lsls r1, 2 - adds r1, r2 - movs r0, 0x88 - strh r0, [r1, 0x20] - movs r0, 0x3C - strh r0, [r1, 0x22] - adds r3, r1, 0 - adds r3, 0x3E - ldrb r2, [r3] - subs r0, 0x41 - ands r0, r2 - strb r0, [r3] - ldrb r2, [r1, 0x1] - movs r0, 0xD - negs r0, r0 - ands r0, r2 - movs r2, 0x4 - orrs r0, r2 - strb r0, [r1, 0x1] - adds r0, r5, 0 - movs r1, 0xA - bl sub_8031BAC - adds r0, r5, 0 - movs r1, 0x14 - bl sub_8031D34 - movs r0, 0x50 - strh r0, [r4, 0x16] - ldr r0, =task_new_game_prof_birch_speech_3 - str r0, [r4] -_0803091A: - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end task_new_game_prof_birch_speech_2 - - thumb_func_start task_new_game_prof_birch_speech_3 -@ int task_new_game_prof_birch_speech_3() -task_new_game_prof_birch_speech_3: @ 8030928 - push {r4,lr} - lsls r0, 24 - lsrs r0, 24 - ldr r2, =gTasks - lsls r1, r0, 2 - adds r1, r0 - lsls r1, 3 - adds r4, r1, r2 - movs r1, 0x12 - ldrsh r0, [r4, r1] - cmp r0, 0 - beq _080309B6 - ldr r2, =gSprites - movs r1, 0x18 - ldrsh r0, [r4, r1] - lsls r1, r0, 4 - adds r1, r0 - lsls r1, 2 - adds r1, r2 - ldrb r2, [r1, 0x1] - movs r0, 0xD - negs r0, r0 - ands r0, r2 - strb r0, [r1, 0x1] - ldrh r1, [r4, 0x16] - movs r2, 0x16 - ldrsh r0, [r4, r2] - cmp r0, 0 - beq _08030970 - subs r0, r1, 0x1 - strh r0, [r4, 0x16] - b _080309B6 - .pool -_08030970: - ldr r0, =gUnknown_082FF080 - bl InitWindows - movs r0, 0 - movs r1, 0xF3 - bl LoadMainMenuWindowFrameTiles - movs r0, 0 - movs r1, 0xFC - movs r2, 0xF0 - bl copy_textbox_border_tile_patterns_to_vram - movs r0, 0 - movs r1, 0x1 - bl unknown_rbox_to_vram - movs r0, 0 - bl PutWindowTilemap - movs r0, 0 - movs r1, 0x2 - bl CopyWindowToVram - movs r0, 0 - bl sub_8032318 - ldr r0, =gStringVar4 - ldr r1, =gUnknown_082C897B - bl StringExpandPlaceholders - movs r0, 0x1 - bl AddTextPrinterForMessage - ldr r0, =task_new_game_prof_birch_speech_4 - str r0, [r4] -_080309B6: - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end task_new_game_prof_birch_speech_3 - thumb_func_start task_new_game_prof_birch_speech_4 task_new_game_prof_birch_speech_4: @ 80309CC push {r4,lr} diff --git a/ld_script.txt b/ld_script.txt index 345afb27f..19661fb56 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -54,6 +54,7 @@ SECTIONS { src/string_util.o(.text); asm/link.o(.text); src/rtc.o(.text); + src/main_menu.o(.text); asm/main_menu.o(.text); src/battle_controllers.o(.text); src/decompress.o(.text); diff --git a/src/main_menu.c b/src/main_menu.c index 8608159c2..f5e210b58 100644 --- a/src/main_menu.c +++ b/src/main_menu.c @@ -1,11 +1,34 @@ // Includes #include "global.h" +#include "bg.h" +#include "constants/rgb.h" +#include "constants/songs.h" +#include "decompress.h" +#include "event_data.h" +#include "gpu_regs.h" +#include "main.h" +#include "menu.h" +#include "menu_indicators.h" +#include "new_menu_helpers.h" +#include "palette.h" +#include "rtc.h" +#include "save.h" +#include "scanline_effect.h" +#include "sound.h" +#include "sprite.h" +#include "string.h" +#include "string_util.h" +#include "task.h" +#include "text.h" +#include "text_window.h" +#include "window.h" // Static type declarations // Static RAM declarations + IWRAM_DATA u8 gUnknown_03000DD0; // Static ROM declarations @@ -13,3 +36,860 @@ IWRAM_DATA u8 gUnknown_03000DD0; // .rodata // .text + +enum +{ + HAS_NO_SAVED_GAME, //NEW GAME, OPTION + HAS_SAVED_GAME, //CONTINUE, NEW GAME, OPTION + HAS_MYSTERY_GIFT, //CONTINUE, NEW GAME, MYSTERY EVENTS, OPTION + HAS_MYSTERY_EVENTS, +}; + +struct ArrowStruct { + u8 unk0[6]; + u16 unk6[5]; +}; + +extern u16 gMainMenuBgPal[]; +extern u16 gMainMenuTextPal[]; +extern struct BgTemplate gUnknown_082FF0E8[]; +extern struct WindowTemplate gUnknown_082FF038[]; +extern u8 gText_SaveFileErased[]; +extern u8 gText_SaveFileCorrupted[]; +extern u8 gJPText_No1MSubCircuit[]; +extern u16 gUnknown_02022D06; +extern struct WindowTemplate gUnknown_082FF070[]; +extern u8 gText_BatteryRunDry[]; +extern struct TextColor gUnknown_082FF0E0; +extern u8 gText_MainMenuNewGame[]; +extern struct WindowTemplate gUnknown_082FF048[]; +extern struct ArrowStruct gUnknown_082FF0F4; +extern u8 gText_MainMenuOption[]; +extern u8 gText_MainMenuContinue[]; +extern u8 gText_MainMenuMysteryGift2[]; +extern u8 gText_MainMenuMysteryEvents[]; +extern u8 gText_MainMenuMysteryGift[]; +extern u8 gText_WirelessNotConnected[]; +extern u8 gText_MysteryGiftCantUse[]; +extern u8 gText_MysteryEventsCantUse[]; +extern struct BgTemplate gUnknown_082FF0F0; +extern u8 gBirchIntroShadowGfx[]; +extern u8 gUnknown_082FEEF0[]; +extern u16 gUnknown_082FECFC[]; +extern u16 gUnknown_082FF028[]; +extern struct WindowTemplate gUnknown_082FF080[]; +extern u8 gUnknown_082C897B[]; + +u32 InitMainMenu(bool8); +void Task_MainMenuCheckSaveFile(u8); +void Task_MainMenuCheckBattery(u8); +void Task_WaitForSaveFileErrorWindow(u8); +void CreateMainMenuErrorWindow(u8*); +void sub_8032250(struct WindowTemplate*); +void Task_DisplayMainMenu(u8); +void Task_WaitForBatteryDryErrorWindow(u8); +void fmt_savegame(void); +u8 AddScrollIndicatorArrowPair(struct ArrowStruct*, u16*); +void HighlightSelectedMainMenuItem(u8, u8, s16); +void Task_HandleMainMenuInput(u8); +void Task_HandleMainMenuAPressed(u8); +void Task_HandleMainMenuBPressed(u8); +void task_new_game_prof_birch_speech_1(u8); +void Task_DisplayMainMenuInvalidActionError(u8); +void AddBirchSpeechObjects(u8); +void task_new_game_prof_birch_speech_2(u8); +void sub_8031BAC(u8, u8); +void sub_8031D34(u8, u8); +void task_new_game_prof_birch_speech_3(u8); +void unknown_rbox_to_vram(u8, u8); +void sub_8032318(u8); +void task_new_game_prof_birch_speech_4(u8); + +extern void LoadMainMenuWindowFrameTiles(u8, u16); +extern bool8 sub_80093CC(void); +extern void Task_ScrollIndicatorArrowPairOnMainMenu(u8); +extern void Task_HighlightSelectedMainMenuItem(u8); +extern void DrawMainMenuWindowBorder(struct WindowTemplate*, u16); +extern void sub_819746C(u8, u8); +extern void sub_8086230(void); +extern void CB2_InitOptionMenu(void); +extern void c2_mystery_gift(void); +extern void CB2_InitMysteryEventMenu(void); +extern void sub_801867C(void); +extern void c2_title_screen_1(void); +extern void dp13_810BB8C(void); + +void CB2_MainMenu(void) +{ + RunTasks(); + AnimateSprites(); + BuildOamBuffer(); + UpdatePaletteFade(); +} + +void VBlankCB_MainMenu(void) +{ + LoadOam(); + ProcessSpriteCopyRequests(); + TransferPlttBuffer(); +} + +void CB2_InitMainMenu(void) +{ + InitMainMenu(FALSE); +} + +void CB2_ReinitMainMenu(void) +{ + InitMainMenu(TRUE); +} + +u32 InitMainMenu(bool8 affects_palette_maybe) +{ + SetVBlankCallback(NULL); + + SetGpuReg(REG_OFFSET_DISPCNT, 0); + SetGpuReg(REG_OFFSET_BG2CNT, 0); + SetGpuReg(REG_OFFSET_BG1CNT, 0); + SetGpuReg(REG_OFFSET_BG0CNT, 0); + SetGpuReg(REG_OFFSET_BG2HOFS, 0); + SetGpuReg(REG_OFFSET_BG2VOFS, 0); + SetGpuReg(REG_OFFSET_BG1HOFS, 0); + SetGpuReg(REG_OFFSET_BG1VOFS, 0); + SetGpuReg(REG_OFFSET_BG0HOFS, 0); + SetGpuReg(REG_OFFSET_BG0VOFS, 0); + + DmaFill16(3, 0, (void *)VRAM, VRAM_SIZE); + DmaFill32(3, 0, (void *)OAM, OAM_SIZE); + DmaFill16(3, 0, (void *)(PLTT + 2), PLTT_SIZE - 2); + + ResetPaletteFade(); + LoadPalette(gMainMenuBgPal, 0, 32); + LoadPalette(gMainMenuTextPal, 0xF0, 32); + ScanlineEffect_Stop(); + ResetTasks(); + ResetSpriteData(); + FreeAllSpritePalettes(); + if (affects_palette_maybe) + BeginNormalPaletteFade(-1, 0, 0x10, 0, 0x0000); // fade to black + else + BeginNormalPaletteFade(-1, 0, 0x10, 0, 0xFFFF); // fade to white + ResetBgsAndClearDma3BusyFlags(0); + InitBgsFromTemplates(0, gUnknown_082FF0E8, 2); + ChangeBgX(0, 0, 0); + ChangeBgY(0, 0, 0); + ChangeBgX(1, 0, 0); + ChangeBgY(1, 0, 0); + InitWindows(gUnknown_082FF038); + DeactivateAllTextPrinters(); + LoadMainMenuWindowFrameTiles(0, 0x1D5); + + SetGpuReg(REG_OFFSET_WIN0H, 0); + SetGpuReg(REG_OFFSET_WIN0V, 0); + SetGpuReg(REG_OFFSET_WININ, 0); + SetGpuReg(REG_OFFSET_WINOUT, 0); + SetGpuReg(REG_OFFSET_BLDCNT, 0); + SetGpuReg(REG_OFFSET_BLDALPHA, 0); + SetGpuReg(REG_OFFSET_BLDY, 0); + + EnableInterrupts(1); + SetVBlankCallback(VBlankCB_MainMenu); + SetMainCallback2(CB2_MainMenu); + SetGpuReg(REG_OFFSET_DISPCNT, 0x3040); + ShowBg(0); + HideBg(1); + CreateTask(Task_MainMenuCheckSaveFile, 0); + + return 0; +} + +void Task_MainMenuCheckSaveFile(u8 taskId) +{ + s16* data = gTasks[taskId].data; + + if (!gPaletteFade.active) + { + SetGpuReg(REG_OFFSET_WIN0H, 0); + SetGpuReg(REG_OFFSET_WIN0V, 0); + SetGpuReg(REG_OFFSET_WININ, 17); + SetGpuReg(REG_OFFSET_WINOUT, 0x31); + SetGpuReg(REG_OFFSET_BLDCNT, 0xC1); + SetGpuReg(REG_OFFSET_BLDALPHA, 0); + SetGpuReg(REG_OFFSET_BLDY, 7); + + if (sub_80093CC()) + data[15] = 1; + switch (gSaveFileStatus) + { + case 1: + data[0] = HAS_SAVED_GAME; + if (IsMysteryGiftEnabled()) + data[0]++; + gTasks[taskId].func = Task_MainMenuCheckBattery; + break; + case 2: + CreateMainMenuErrorWindow(gText_SaveFileErased); + data[0] = 0; + gTasks[taskId].func = Task_WaitForSaveFileErrorWindow; + break; + case 0xFF: + CreateMainMenuErrorWindow(gText_SaveFileCorrupted); + gTasks[taskId].func = Task_WaitForSaveFileErrorWindow; + data[0] = HAS_SAVED_GAME; + if (IsMysteryGiftEnabled() == TRUE) + data[0]++; + break; + case 0: + default: + data[0] = HAS_NO_SAVED_GAME; + gTasks[taskId].func = Task_MainMenuCheckBattery; + break; + case 4: + CreateMainMenuErrorWindow(gJPText_No1MSubCircuit); + gTasks[taskId].data[0] = HAS_NO_SAVED_GAME; + gTasks[taskId].func = Task_WaitForSaveFileErrorWindow; + break; + } + if (gUnknown_02022D06 & 0x8000) + { + switch (data[0]) + { + case HAS_NO_SAVED_GAME: + case HAS_SAVED_GAME: + gUnknown_02022D06 = data[0] + 1; + break; + case HAS_MYSTERY_GIFT: + gUnknown_02022D06 = 3; + break; + case 3: + gUnknown_02022D06 = 4; + break; + } + } + gUnknown_02022D06 &= 0x7FFF; + data[1] = gUnknown_02022D06; + data[12] = data[0] + 2; + } +} + +void Task_WaitForSaveFileErrorWindow(u8 taskId) +{ + RunTextPrinters(); + if (!IsTextPrinterActive(7) && (gMain.newKeys & A_BUTTON)) + { + ClearWindowTilemap(7); + sub_8032250(gUnknown_082FF070); + gTasks[taskId].func = Task_MainMenuCheckBattery; + } +} + +void Task_MainMenuCheckBattery(u8 taskId) +{ + if (!gPaletteFade.active) + { + SetGpuReg(REG_OFFSET_WIN0H, 0); + SetGpuReg(REG_OFFSET_WIN0V, 0); + SetGpuReg(REG_OFFSET_WININ, 17); + SetGpuReg(REG_OFFSET_WINOUT, 0x31); + SetGpuReg(REG_OFFSET_BLDCNT, 0xC1); + SetGpuReg(REG_OFFSET_BLDALPHA, 0); + SetGpuReg(REG_OFFSET_BLDY, 7); + + if (!(RtcGetErrorStatus() & RTC_ERR_FLAG_MASK)) + gTasks[taskId].func = Task_DisplayMainMenu; + else + { + CreateMainMenuErrorWindow(gText_BatteryRunDry); + gTasks[taskId].func = Task_WaitForBatteryDryErrorWindow; + } + } +} + +void Task_WaitForBatteryDryErrorWindow(u8 taskId) +{ + RunTextPrinters(); + if (!IsTextPrinterActive(7) && (gMain.newKeys & A_BUTTON)) + { + ClearWindowTilemap(7); + sub_8032250(gUnknown_082FF070); + gTasks[taskId].func = Task_DisplayMainMenu; + } +} + +void Task_DisplayMainMenu(u8 taskId) +{ + s16* data = gTasks[taskId].data; + u16 palette; + + if (!gPaletteFade.active) + { + SetGpuReg(REG_OFFSET_WIN0H, 0); + SetGpuReg(REG_OFFSET_WIN0V, 0); + SetGpuReg(REG_OFFSET_WININ, 17); + SetGpuReg(REG_OFFSET_WINOUT, 0x31); + SetGpuReg(REG_OFFSET_BLDCNT, 0xC1); + SetGpuReg(REG_OFFSET_BLDALPHA, 0); + SetGpuReg(REG_OFFSET_BLDY, 7); + + palette = RGB_BLACK; + LoadPalette(&palette, 254, 2); + + palette = RGB_WHITE; + LoadPalette(&palette, 250, 2); + + palette = RGB(12, 12, 12); + LoadPalette(&palette, 251, 2); + + palette = RGB(26, 26, 25); + LoadPalette(&palette, 252, 2); + + if (gSaveBlock2Ptr->playerGender == MALE) + { + palette = RGB(4, 16, 31); + LoadPalette(&palette, 241, 2); + } + else + { + palette = RGB(31, 3, 21); + LoadPalette(&palette, 241, 2); + } + + + + switch (gTasks[taskId].data[0]) + { + case HAS_NO_SAVED_GAME: + default: + FillWindowPixelBuffer(0, 0xAA); + FillWindowPixelBuffer(1, 0xAA); + box_print(0, 1, 0, 1, &gUnknown_082FF0E0, -1, gText_MainMenuNewGame); + box_print(1, 1, 0, 1, &gUnknown_082FF0E0, -1, gText_MainMenuOption); + PutWindowTilemap(0); + PutWindowTilemap(1); + CopyWindowToVram(0, 2); + CopyWindowToVram(1, 2); + DrawMainMenuWindowBorder(gUnknown_082FF038, 0x1D5); + DrawMainMenuWindowBorder(&gUnknown_082FF038[1], 0x1D5); + break; + case HAS_SAVED_GAME: + FillWindowPixelBuffer(2, 0xAA); + FillWindowPixelBuffer(3, 0xAA); + FillWindowPixelBuffer(4, 0xAA); + box_print(2, 1, 0, 1, &gUnknown_082FF0E0, -1, gText_MainMenuContinue); + box_print(3, 1, 0, 1, &gUnknown_082FF0E0, -1, gText_MainMenuNewGame); + box_print(4, 1, 0, 1, &gUnknown_082FF0E0, -1, gText_MainMenuOption); + fmt_savegame(); + PutWindowTilemap(2); + PutWindowTilemap(3); + PutWindowTilemap(4); + CopyWindowToVram(2, 2); + CopyWindowToVram(3, 2); + CopyWindowToVram(4, 2); + DrawMainMenuWindowBorder(gUnknown_082FF048, 0x1D5); + DrawMainMenuWindowBorder(&gUnknown_082FF048[1], 0x1D5); + DrawMainMenuWindowBorder(&gUnknown_082FF048[2], 0x1D5); + break; + case HAS_MYSTERY_GIFT: + FillWindowPixelBuffer(2, 0xAA); + FillWindowPixelBuffer(3, 0xAA); + FillWindowPixelBuffer(4, 0xAA); + FillWindowPixelBuffer(5, 0xAA); + box_print(2, 1, 0, 1, &gUnknown_082FF0E0, -1, gText_MainMenuContinue); + box_print(3, 1, 0, 1, &gUnknown_082FF0E0, -1, gText_MainMenuNewGame); + box_print(4, 1, 0, 1, &gUnknown_082FF0E0, -1, gText_MainMenuMysteryGift); + box_print(5, 1, 0, 1, &gUnknown_082FF0E0, -1, gText_MainMenuOption); + fmt_savegame(); + PutWindowTilemap(2); + PutWindowTilemap(3); + PutWindowTilemap(4); + PutWindowTilemap(5); + CopyWindowToVram(2, 2); + CopyWindowToVram(3, 2); + CopyWindowToVram(4, 2); + CopyWindowToVram(5, 2); + DrawMainMenuWindowBorder(gUnknown_082FF048, 0x1D5); + DrawMainMenuWindowBorder(&gUnknown_082FF048[1], 0x1D5); + DrawMainMenuWindowBorder(&gUnknown_082FF048[2], 0x1D5); + DrawMainMenuWindowBorder(&gUnknown_082FF048[3], 0x1D5); + break; + case HAS_MYSTERY_EVENTS: + FillWindowPixelBuffer(2, 0xAA); + FillWindowPixelBuffer(3, 0xAA); + FillWindowPixelBuffer(4, 0xAA); + FillWindowPixelBuffer(5, 0xAA); + FillWindowPixelBuffer(6, 0xAA); + box_print(2, 1, 0, 1, &gUnknown_082FF0E0, -1, gText_MainMenuContinue); + box_print(3, 1, 0, 1, &gUnknown_082FF0E0, -1, gText_MainMenuNewGame); + box_print(4, 1, 0, 1, &gUnknown_082FF0E0, -1, gText_MainMenuMysteryGift2); + box_print(5, 1, 0, 1, &gUnknown_082FF0E0, -1, gText_MainMenuMysteryEvents); + box_print(6, 1, 0, 1, &gUnknown_082FF0E0, -1, gText_MainMenuOption); + fmt_savegame(); + PutWindowTilemap(2); + PutWindowTilemap(3); + PutWindowTilemap(4); + PutWindowTilemap(5); + PutWindowTilemap(6); + CopyWindowToVram(2, 2); + CopyWindowToVram(3, 2); + CopyWindowToVram(4, 2); + CopyWindowToVram(5, 2); + CopyWindowToVram(6, 2); + DrawMainMenuWindowBorder(gUnknown_082FF048, 0x1D5); + DrawMainMenuWindowBorder(&gUnknown_082FF048[1], 0x1D5); + DrawMainMenuWindowBorder(&gUnknown_082FF048[2], 0x1D5); + DrawMainMenuWindowBorder(&gUnknown_082FF048[3], 0x1D5); + DrawMainMenuWindowBorder(&gUnknown_082FF048[4], 0x1D5); + data[13] = AddScrollIndicatorArrowPair(&gUnknown_082FF0F4, &gUnknown_02022D06); + gTasks[data[13]].func = Task_ScrollIndicatorArrowPairOnMainMenu; + if (gUnknown_02022D06 == 4) + { + ChangeBgY(0, 0x2000, 1); + ChangeBgY(1, 0x2000, 1); + data[14] = 1; + gTasks[data[13]].data[15] = 1; + } + break; + } + gTasks[taskId].func = Task_HighlightSelectedMainMenuItem; + } +} + +void Task_HighlightSelectedMainMenuItem(u8 taskId) +{ + HighlightSelectedMainMenuItem(gTasks[taskId].data[0], gTasks[taskId].data[1], gTasks[taskId].data[14]); + gTasks[taskId].func = Task_HandleMainMenuInput; +} + +bool8 HandleMainMenuInput(u8 taskId) +{ + s16* data = gTasks[taskId].data; + + if (gMain.newKeys & A_BUTTON) + { + PlaySE(SE_SELECT); + sub_80093CC(); + BeginNormalPaletteFade(-1, 0, 0, 0x10, 0x0000); + gTasks[taskId].func = Task_HandleMainMenuAPressed; + } + else if (gMain.newKeys & B_BUTTON) + { + PlaySE(SE_SELECT); + BeginNormalPaletteFade(-1, 0, 0, 0x10, 0xFFFF); + SetGpuReg(REG_OFFSET_WIN0H, 0xF0); + SetGpuReg(REG_OFFSET_WIN0V, 0xA0); + gTasks[taskId].func = Task_HandleMainMenuBPressed; + } + else if ((gMain.newKeys & DPAD_UP) && data[1] > 0) + { + if (data[0] == 3 && data[14] == 1 && data[1] == 1) + { + ChangeBgY(0, 0x2000, 2); + ChangeBgY(1, 0x2000, 2); + gTasks[data[13]].data[15] = data[14] = 0; + } + data[1]--; + gUnknown_02022D06 = data[1]; + return TRUE; + } + else if ((gMain.newKeys & DPAD_DOWN) && data[1] < data[12] - 1) + { + if (data[0] == 3 && data[1] == 3 && data[14] == 0) + { + ChangeBgY(0, 0x2000, 1); + ChangeBgY(1, 0x2000, 1); + gTasks[data[13]].data[15] = data[14] = 1; + } + data[1]++; + gUnknown_02022D06 = data[1]; + return TRUE; + } + return FALSE; +} + +void Task_HandleMainMenuInput(u8 taskId) +{ + if (HandleMainMenuInput(taskId)) + gTasks[taskId].func = Task_HighlightSelectedMainMenuItem; +} + +void Task_HandleMainMenuAPressed(u8 taskId) +{ + bool8 r2; + u8 action; + + if (!gPaletteFade.active) + { + if (gTasks[taskId].data[0] == 3) + RemoveScrollIndicatorArrowPair(gTasks[taskId].data[13]); + sub_819746C(0, 1); + sub_819746C(1, 1); + sub_819746C(2, 1); + sub_819746C(3, 1); + sub_819746C(4, 1); + sub_819746C(5, 1); + sub_819746C(6, 1); + sub_819746C(7, 1); + r2 = sub_80093CC(); + switch (gTasks[taskId].data[0]) + { + case HAS_NO_SAVED_GAME: + default: + switch (gTasks[taskId].data[1]) + { + case 0: + default: + action = 0; + break; + case 1: + action = 2; + break; + } + break; + case HAS_SAVED_GAME: + switch (gTasks[taskId].data[1]) + { + case 0: + default: + action = 1; + break; + case 1: + action = 0; + break; + case 2: + action = 2; + break; + } + break; + case HAS_MYSTERY_GIFT: + switch (gTasks[taskId].data[1]) + { + case 0: + default: + action = 1; + break; + case 1: + action = 0; + break; + case 2: + action = 3; + if (r2 == FALSE) + { + action = 6; + gTasks[taskId].data[0] = 0; + } + break; + case 3: + action = 2; + break; + } + break; + case HAS_MYSTERY_EVENTS: + switch (gTasks[taskId].data[1]) + { + case 0: + default: + action = 1; + break; + case 1: + action = 0; + break; + case 2: + if (gTasks[taskId].data[15]) + { + action = 3; + if (r2 == FALSE) + { + action = 6; + gTasks[taskId].data[0] = 0; + } + } + else if (r2) + { + action = 6; + gTasks[taskId].data[0] = 1; + } + else + action = 5; + break; + case 3: + if (r2) + { + action = 6; + gTasks[taskId].data[0] = 2; + } + else + action = 4; + break; + case 4: + action = 2; + break; + } + break; + } + ChangeBgY(0, 0, 0); + ChangeBgY(1, 0, 0); + switch (action) + { + case 0: + default: + gPlttBufferUnfaded[0] = RGB_BLACK; + gPlttBufferFaded[0] = RGB_BLACK; + gTasks[taskId].func = task_new_game_prof_birch_speech_1; + break; + case 1: + gPlttBufferUnfaded[0] = RGB_BLACK; + gPlttBufferFaded[0] = RGB_BLACK; + SetMainCallback2(sub_8086230); + DestroyTask(taskId); + break; + case 2: + gMain.savedCallback = CB2_ReinitMainMenu; + SetMainCallback2(CB2_InitOptionMenu); + DestroyTask(taskId); + break; + case 3: + SetMainCallback2(c2_mystery_gift); + DestroyTask(taskId); + break; + case 4: + SetMainCallback2(CB2_InitMysteryEventMenu); + DestroyTask(taskId); + break; + case 5: + SetMainCallback2(sub_801867C); + DestroyTask(taskId); + break; + case 6: + gTasks[taskId].data[1] = 0; + gTasks[taskId].func = Task_DisplayMainMenuInvalidActionError; + gPlttBufferUnfaded[0xF1] = RGB_WHITE; + gPlttBufferFaded[0xF1] = RGB_WHITE; + SetGpuReg(REG_OFFSET_BG2HOFS, 0); + SetGpuReg(REG_OFFSET_BG2VOFS, 0); + SetGpuReg(REG_OFFSET_BG1HOFS, 0); + SetGpuReg(REG_OFFSET_BG1VOFS, 0); + SetGpuReg(REG_OFFSET_BG0HOFS, 0); + SetGpuReg(REG_OFFSET_BG0VOFS, 0); + BeginNormalPaletteFade(-1, 0, 16, 0, 0); + return; + } + FreeAllWindowBuffers(); + if (action != 2) + gUnknown_02022D06 = 0; + else + gUnknown_02022D06 |= 0x8000; + } +} + +void Task_HandleMainMenuBPressed(u8 taskId) +{ + if (!gPaletteFade.active) + { + if (gTasks[taskId].data[0] == 3) + RemoveScrollIndicatorArrowPair(gTasks[taskId].data[13]); + gUnknown_02022D06 = 0; + FreeAllWindowBuffers(); + SetMainCallback2(c2_title_screen_1); + DestroyTask(taskId); + } +} + +void Task_DisplayMainMenuInvalidActionError(u8 taskId) +{ + switch (gTasks[taskId].data[1]) + { + case 0: + FillBgTilemapBufferRect_Palette0(0, 0, 0, 0, 30, 20); + switch (gTasks[taskId].data[0]) + { + case 0: + CreateMainMenuErrorWindow(gText_WirelessNotConnected); + break; + case 1: + CreateMainMenuErrorWindow(gText_MysteryGiftCantUse); + break; + case 2: + CreateMainMenuErrorWindow(gText_MysteryEventsCantUse); + break; + } + gTasks[taskId].data[1]++; + break; + case 1: + if (!gPaletteFade.active) + gTasks[taskId].data[1]++; + break; + case 2: + RunTextPrinters(); + if (!IsTextPrinterActive(7)) + gTasks[taskId].data[1]++; + break; + case 3: + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) + { + PlaySE(SE_SELECT); + BeginNormalPaletteFade(-1, 0, 0, 16, 0); + gTasks[taskId].func = Task_HandleMainMenuBPressed; + } + } +} + +void HighlightSelectedMainMenuItem(u8 menuType, u8 selectedMenuItem, s16 a) +{ + SetGpuReg(REG_OFFSET_WIN0H, 0x9E7); + + switch (menuType) + { + case HAS_NO_SAVED_GAME: + default: + switch (selectedMenuItem) + { + case 0: + default: + SetGpuReg(REG_OFFSET_WIN0V, 0x11F); + break; + case 1: + SetGpuReg(REG_OFFSET_WIN0V, 0x213F); + break; + } + break; + case HAS_SAVED_GAME: + switch (selectedMenuItem) + { + case 0: + default: + SetGpuReg(REG_OFFSET_WIN0V, 0x13F); + break; + case 1: + SetGpuReg(REG_OFFSET_WIN0V, 0x415F); + break; + case 2: + SetGpuReg(REG_OFFSET_WIN0V, 0x617F); + break; + } + break; + case HAS_MYSTERY_GIFT: + switch (selectedMenuItem) + { + case 0: + default: + SetGpuReg(REG_OFFSET_WIN0V, 0x13F); + break; + case 1: + SetGpuReg(REG_OFFSET_WIN0V, 0x415F); + break; + case 2: + SetGpuReg(REG_OFFSET_WIN0V, 0x617F); + break; + case 3: + SetGpuReg(REG_OFFSET_WIN0V, 0x819F); + break; + } + break; + case HAS_MYSTERY_EVENTS: + switch (selectedMenuItem) + { + case 0: + default: + SetGpuReg(REG_OFFSET_WIN0V, 0x13F); + break; + case 1: + if (a) + SetGpuReg(REG_OFFSET_WIN0V, 0x213F); + else + SetGpuReg(REG_OFFSET_WIN0V, 0x415F); + break; + case 2: + if (a) + SetGpuReg(REG_OFFSET_WIN0V, 0x415F); + else + SetGpuReg(REG_OFFSET_WIN0V, 0x617F); + break; + case 3: + if (a) + SetGpuReg(REG_OFFSET_WIN0V, 0x617F); + else + SetGpuReg(REG_OFFSET_WIN0V, 0x819F); + break; + case 4: + SetGpuReg(REG_OFFSET_WIN0V, 0x819F); + break; + } + break; + } +} + +void task_new_game_prof_birch_speech_1(u8 taskId) +{ + SetGpuReg(REG_OFFSET_DISPCNT, 0); + SetGpuReg(REG_OFFSET_DISPCNT, 0x1040); + InitBgFromTemplate(&gUnknown_082FF0F0); + SetGpuReg(REG_OFFSET_WIN0H, 0); + SetGpuReg(REG_OFFSET_WIN0V, 0); + SetGpuReg(REG_OFFSET_WININ, 0); + SetGpuReg(REG_OFFSET_WINOUT, 0); + SetGpuReg(REG_OFFSET_BLDCNT, 0); + SetGpuReg(REG_OFFSET_BLDALPHA, 0); + SetGpuReg(REG_OFFSET_BLDY, 0); + + LZ77UnCompVram(gBirchIntroShadowGfx, (void*)VRAM); + LZ77UnCompVram(gUnknown_082FEEF0, (void*)(VRAM + 0x3800)); + LoadPalette(gUnknown_082FECFC, 0, 64); + LoadPalette(gUnknown_082FF028, 1, 16); + ScanlineEffect_Stop(); + ResetSpriteData(); + FreeAllSpritePalettes(); + dp13_810BB8C(); + AddBirchSpeechObjects(taskId); + BeginNormalPaletteFade(-1, 0, 16, 0, 0); + gTasks[taskId].data[4] = 0; + gTasks[taskId].func = task_new_game_prof_birch_speech_2; + gTasks[taskId].data[2] = 0xFF; + gTasks[taskId].data[3] = 0xFF; + gTasks[taskId].data[7] = 0xD8; + PlayBGM(MUS_DOORO_X4); + ShowBg(0); + ShowBg(1); +} + +void task_new_game_prof_birch_speech_2(u8 taskId) +{ + u8 spriteId; + + if (gTasks[taskId].data[7]) + gTasks[taskId].data[7]--; + else + { + spriteId = gTasks[taskId].data[8]; + gSprites[spriteId].pos1.x = 0x88; + gSprites[spriteId].pos1.y = 0x3C; + gSprites[spriteId].invisible = 0; + gSprites[spriteId].oam.objMode = 1; + sub_8031BAC(taskId, 10); + sub_8031D34(taskId, 20); + gTasks[taskId].data[7] = 0x50; + gTasks[taskId].func = task_new_game_prof_birch_speech_3; + } +} + +void task_new_game_prof_birch_speech_3(u8 taskId) +{ + if (gTasks[taskId].data[5]) + { + gSprites[gTasks[taskId].data[8]].oam.objMode = 0; + if (gTasks[taskId].data[7]) + gTasks[taskId].data[7]--; + else + { + InitWindows(gUnknown_082FF080); + LoadMainMenuWindowFrameTiles(0, 0xF3); + copy_textbox_border_tile_patterns_to_vram(0, 0xFC, 0xF0); + unknown_rbox_to_vram(0, 1); + PutWindowTilemap(0); + CopyWindowToVram(0, 2); + sub_8032318(0); + StringExpandPlaceholders(gStringVar4, gUnknown_082C897B); + AddTextPrinterForMessage(1); + gTasks[taskId].func = task_new_game_prof_birch_speech_4; + } + } +}