diff --git a/include/arm9/menu.h b/include/arm9/menu.h index f7bcaf1..8720492 100644 --- a/include/arm9/menu.h +++ b/include/arm9/menu.h @@ -53,6 +53,9 @@ extern int menu_event_state; +// Enable or disable the pseudo VBlank in the menu. +void menuSetVBlank(bool enable); + int enter_menu(int initial_state); // Use this to change to another sub-menu. diff --git a/source/arm9/menu.c b/source/arm9/menu.c index 73579c2..b04a508 100644 --- a/source/arm9/menu.c +++ b/source/arm9/menu.c @@ -53,6 +53,7 @@ int menu_previous_states_count; int menu_event_state; +static bool waitForVBlank; static void menuRunOnce(int state); @@ -74,6 +75,22 @@ uiPrintTextAt(1, 10, "Wifi flash status: %s\e[0m", nand_res[bootInfo.wififlash_status]); } +void menuSetVBlank(bool enable) +{ + if(enable) + { + IRQ_registerHandler(IRQ_TIMER_0, NULL); + TIMER_start(TIMER_0, TIMER_PRESCALER_64, TIMER_FREQ_64(60.0f), true); + waitForVBlank = true; + } + else + { + waitForVBlank = false; + TIMER_stop(TIMER_0); + IRQ_unregisterHandler(IRQ_TIMER_0); + } +} + int enter_menu(int initial_state) { u32 keys; @@ -88,7 +105,7 @@ uiClearConsoles(); uiDrawConsoleWindow(); - //TIMER_start(TIMER_0, TIMER_PRESCALER_64, TIMER_FREQ_64(60.0f), true); + menuSetVBlank(true); // caller requested to enter a submenu? if(initial_state != MENU_STATE_MAIN) @@ -145,13 +162,17 @@ break; case MENU_STATE_NAND_BACKUP: + menuSetVBlank(false); menuDumpNand("sdmc:/nand.bin"); uiClearConsoles(); + menuSetVBlank(true); break; case MENU_STATE_NAND_RESTORE: + menuSetVBlank(false); menuRestoreNand("sdmc:/nand.bin"); uiClearConsoles(); + menuSetVBlank(true); break; case MENU_STATE_NAND_FLASH_FIRM: @@ -159,8 +180,10 @@ uiClearConsoles(); if(!path) break; + menuSetVBlank(false); menuFlashFirmware(path); uiClearConsoles(); + menuSetVBlank(true); break; case MENU_STATE_OPTIONS_MENU: @@ -188,8 +211,10 @@ break; case MENU_STATE_UPDATE: + menuSetVBlank(false); menuUpdateLoader(); uiClearConsoles(); + menuSetVBlank(true); break; case MENU_STATE_CREDITS: @@ -223,7 +248,7 @@ } exitAndLaunchFirm: - //TIMER_stop(TIMER_0); + menuSetVBlank(false); return 0; } @@ -293,7 +318,7 @@ // Later if PXI interrupts are implemented we need an // interrupt handler here which can tell the timer and // PXI interrupts apart. - //waitForIrq(); + if(waitForVBlank) waitForIrq(); /* Check PXI Response register */ diff --git a/source/arm9/menu_nand.c b/source/arm9/menu_nand.c index 056140e..30eaded 100644 --- a/source/arm9/menu_nand.c +++ b/source/arm9/menu_nand.c @@ -72,7 +72,7 @@ } uiPrintTextAt(0, 5, "Dumping NAND...\n"); - uiPrintTextAt(0, 22, "Press B to cancel."); + uiPrintTextAt(0, 22, "Press B to cancel."); /* Main loop */