diff --git a/include/arm9/menu.h b/include/arm9/menu.h index 375a4f5..00f19be 100644 --- a/include/arm9/menu.h +++ b/include/arm9/menu.h @@ -1,5 +1,7 @@ #pragma once +#include "arm9/menu_nand.h" + enum menu_state_type { MENU_STATE_MAIN = 0, MENU_STATE_NAND_MENU, diff --git a/source/arm9/menu.c b/source/arm9/menu.c index 1c1a76c..828a495 100644 --- a/source/arm9/menu.c +++ b/source/arm9/menu.c @@ -18,8 +18,6 @@ #include "arm9/interrupt.h" #include "arm9/config.h" -// PrintConsole for each screen -extern PrintConsole con_top, con_bottom; const menu_state_options menu_main = { 5, @@ -54,6 +52,8 @@ int menu_event_state; +static void menuRunOnce(int state); + static void menu_main_draw_top() { const char *sd_res[2] = {"\x1B[31mNo ", "\x1B[32mYes"}; @@ -64,12 +64,12 @@ uiPrintCentered("fastboot 3DS v%" PRIu16 ".%" PRIu16, BOOTLOADER_VERSION>>16, BOOTLOADER_VERSION & 0xFFFFu); - printf(" Model: %s\n", bootInfo.model); - printf(" \x1B[33m%s\e[0m\n", bootInfo.boot_env); - printf(" \x1B[32m(%s Mode)\e[0m\n\n", bootInfo.mode); - printf(" SD card inserted: %s\e[0m\n", sd_res[bootInfo.sd_status]); - printf(" NAND status: %s\e[0m\n", nand_res[bootInfo.nand_status]); - printf(" Wifi flash status: %s\e[0m", nand_res[bootInfo.wififlash_status]); + uiPrintTextAt(1, 3, "Model: %s", bootInfo.model); + uiPrintTextAt(1, 4, "\x1B[33m%s\e[0m", bootInfo.boot_env); + uiPrintTextAt(1, 5, "\x1B[32m(%s Mode)\e[0m", bootInfo.mode); + uiPrintTextAt(1, 7, "SD card inserted: %s\e[0m", sd_res[bootInfo.sd_status]); + uiPrintTextAt(1, 8, "NAND status: %s\e[0m", nand_res[bootInfo.nand_status]); + uiPrintTextAt(1, 9, "Wifi flash status: %s\e[0m", nand_res[bootInfo.wififlash_status]); } static void rewindConsole() @@ -78,7 +78,7 @@ consoleSelect(&con_top); printf("\033[0;0H"); // set cursor to the upper left corner consoleSelect(&con_bottom); - printf("\033[0;0H\n\n\n\n"); + printf("\033[0;0H"); } int enter_menu(int initial_state) @@ -127,7 +127,7 @@ // print all the options of the current state consoleSelect(&con_bottom); for(int i=0; i < cur_options->count; i++) - printf("\t\t\t%s\e[0m %s\n", cursor_pos == i ? "\x1B[33m*" : " ", + uiPrintTextAt(9, 4+i, "%s\e[0m %s\n", cursor_pos == i ? "\x1B[33m*" : " ", cur_options->options[i].name); if(keys & KEY_DUP) @@ -250,7 +250,7 @@ return 0; } -void menuRunOnce(int state) +static void menuRunOnce(int state) { switch(state) { diff --git a/source/arm9/menu_nand.c b/source/arm9/menu_nand.c index fe3916f..a1b44c6 100644 --- a/source/arm9/menu_nand.c +++ b/source/arm9/menu_nand.c @@ -12,7 +12,7 @@ #include "arm9/util_nand.h" -u64 getFreeSpace(const char *drive) +static u64 getFreeSpace(const char *drive) { FATFS *fs; DWORD freeClusters; @@ -34,9 +34,6 @@ UINT bytesWritten; uiClearConsoles(); - - consoleSelect(&con_bottom); - printf("\n\t\tPress B to cancel"); consoleSelect(&con_top); u8 *buf = (u8*)malloc(sectorBlkSize<<9); @@ -45,13 +42,13 @@ if(getFreeSpace("sdmc:") < sectorCount<<9) { - printf("Not enough space on the SD card!\n"); + uiPrintError("Not enough space on the SD card!\n"); goto fail; } if((fres = f_open(&file, filePath, FA_CREATE_ALWAYS | FA_WRITE)) != FR_OK) { - printf("Failed to create '%s'! Error: %X\n", filePath, fres); + uiPrintError("Failed to create '%s'! Error: %X\n", filePath, fres); f_close(&file); goto fail; } @@ -59,7 +56,7 @@ // Allocate space to make sure the nand image is a contiguous file if((fres = f_expand(&file, sectorCount<<9, 0)) != FR_OK) { - printf("Failed to expand file! Error: %X\n", fres); + uiPrintError("Failed to expand file! Error: %X\n", fres); f_close(&file); goto fail; } @@ -75,13 +72,13 @@ if(!dev_rawnand->read_sector(curSector, curSectorBlkSize, buf)) { - printf("\nFailed to read sector 0x%"PRIx32"!\n", curSector); + uiPrintError("\nFailed to read sector 0x%"PRIx32"!\n", curSector); f_close(&file); goto fail; } if((f_write(&file, buf, curSectorBlkSize<<9, &bytesWritten) != FR_OK) || (bytesWritten != curSectorBlkSize<<9)) { - printf("\nFailed to write to file!\n"); + uiPrintError("\nFailed to write to file!\n"); f_close(&file); goto fail; } @@ -89,7 +86,7 @@ hidScanInput(); if(hidKeysDown() & KEY_B) { - printf("\n...canceled!\n"); + uiPrintInfo("\n...canceled!\n"); f_close(&file); goto fail; } @@ -97,10 +94,12 @@ curSector += curSectorBlkSize; // print current progress information - printf("\r%"PRId32"/%"PRId32" MB (Sector 0x%"PRIX32"/0x%"PRIX32")", curSector>>11, sectorCount>>11, + uiPrintInfo("\r%"PRId32"/%"PRId32" MB (Sector 0x%"PRIX32"/0x%"PRIX32")", curSector>>11, sectorCount>>11, curSector, sectorCount); - + + uiPrintProgressBar(10, 10, 200, 100 * curSector/sectorCount); + switch(menuUpdateGlobalState()) { case MENU_EVENT_HOME_PRESSED: @@ -126,7 +125,7 @@ fail: free(buf); - printf("Press any key to return..."); + uiPrintInfo("Press any key to return..."); menuWaitForAnyPadkey(); menuSetReturnToState(STATE_PREVIOUS);