2019-11-21 15:02:45 +00:00
# include <stdio.h>
# include <string.h>
2020-03-18 23:11:18 +00:00
# include "mainmenu.h"
2019-11-21 15:02:45 +00:00
# include "../utils/util.h"
2020-03-18 11:18:39 +00:00
# include "utils/tools.h"
2019-12-11 12:18:57 +00:00
# include "../utils/btn.h"
2020-03-18 23:11:18 +00:00
# include "emmc/emmc.h"
2020-01-27 22:51:59 +00:00
# include "../storage/emummc.h"
2020-03-18 11:18:39 +00:00
# include "utils/script.h"
2019-11-21 15:02:45 +00:00
2020-03-17 23:41:09 +00:00
# include "common/common.h"
# include "gfx/menu.h"
# include "utils/utils.h"
2020-03-18 11:18:39 +00:00
# include "gfx/gfxutils.h"
2020-03-18 22:58:32 +00:00
# include "fs/fsutils.h"
# include "fs/fsmenu.h"
2020-03-19 12:00:42 +00:00
# include "emmc/emmcoperations.h"
2020-03-17 23:41:09 +00:00
2019-11-21 15:02:45 +00:00
extern bool sd_mount ( ) ;
extern void sd_unmount ( ) ;
2019-12-20 20:00:47 +00:00
extern bool return_sd_mounted ( int value ) ;
2019-12-01 14:42:37 +00:00
extern int launch_payload ( char * path ) ;
2019-11-21 15:02:45 +00:00
2020-03-17 23:41:09 +00:00
/*
2019-11-21 15:02:45 +00:00
menu_item mainmenu [ MAINMENU_AMOUNT ] = {
2019-12-22 11:10:59 +00:00
{ " [SD:/] SD CARD \n " , COLOR_GREEN , SD_CARD , 1 } ,
{ " [SYSTEM:/] EMMC " , COLOR_ORANGE , EMMC_SYS , 1 } ,
{ " [USER:/] EMMC " , COLOR_ORANGE , EMMC_USR , 1 } ,
{ " [SAFE:/] EMMC " , COLOR_ORANGE , EMMC_SAF , 1 } ,
2020-01-27 22:51:59 +00:00
{ " \n [SYSTEM:/] EMUMMC " , COLOR_BLUE , EMUMMC_SYS , 1 } ,
{ " [USER:/] EMUMMC " , COLOR_BLUE , EMUMMC_USR , 1 } ,
{ " [SAFE:/] EMUMMC " , COLOR_BLUE , EMUMMC_SAF , 1 } ,
2019-11-21 20:27:48 +00:00
{ " \n Mount/Unmount SD " , COLOR_WHITE , MOUNT_SD , 1 } ,
{ " Tools " , COLOR_VIOLET , TOOLS , 1 } ,
2019-12-11 12:18:57 +00:00
{ " SD format " , COLOR_VIOLET , SD_FORMAT , 1 } ,
2019-11-21 20:27:48 +00:00
{ " \n Credits " , COLOR_WHITE , CREDITS , 1 } ,
{ " Exit " , COLOR_WHITE , EXIT , 1 }
2019-11-21 15:02:45 +00:00
} ;
2019-12-01 14:42:37 +00:00
menu_item shutdownmenu [ 7 ] = {
2019-11-21 19:54:18 +00:00
{ " -- EXIT -- \n " , COLOR_ORANGE , - 1 , 0 } ,
2019-11-21 20:27:48 +00:00
{ " Back " , COLOR_WHITE , - 1 , 1 } ,
{ " \n Reboot to RCM " , COLOR_VIOLET , REBOOT_RCM , 1 } ,
{ " Reboot normally " , COLOR_ORANGE , REBOOT_NORMAL , 1 } ,
2019-12-01 14:42:37 +00:00
{ " Power off \n " , COLOR_BLUE , POWER_OFF , 1 } ,
{ " Reboot to Hekate " , COLOR_GREEN , HEKATE , - 1 } ,
{ " Reboot to Atmosphere " , COLOR_GREEN , AMS , - 1 }
2019-11-21 19:54:18 +00:00
} ;
2020-03-15 11:35:18 +00:00
menu_item toolsmenu [ 8 ] = {
2019-11-21 19:54:18 +00:00
{ " -- TOOLS -- \n " , COLOR_VIOLET , - 1 , 0 } ,
2019-11-21 20:27:48 +00:00
{ " Back " , COLOR_WHITE , - 1 , 1 } ,
2019-12-03 09:06:11 +00:00
{ " \n Display Console Info " , COLOR_GREEN , DISPLAY_INFO , 1 } ,
2019-12-11 13:45:30 +00:00
{ " Display GPIO pins " , COLOR_VIOLET , DISPLAY_GPIO , 1 } ,
2020-01-07 20:53:02 +00:00
{ " Dump Firmware " , COLOR_BLUE , DUMPFIRMWARE , 1 } ,
2020-03-14 14:03:08 +00:00
{ " Dump User Saves " , COLOR_YELLOW , DUMPUSERSAVE , 1 } ,
2020-03-15 11:35:18 +00:00
{ " [DEBUG] Dump bis " , COLOR_RED , DUMP_BOOT , 1 } ,
{ " [DEBUG] Restore bis " , COLOR_RED , RESTORE_BOOT , 1 }
2019-12-11 13:45:30 +00:00
} ;
menu_item formatmenu [ 4 ] = {
{ " -- FORMAT SD -- \n " , COLOR_RED , - 1 , 0 } ,
{ " Back \n " , COLOR_WHITE , - 1 , 1 } ,
2019-12-18 15:14:14 +00:00
{ " Format entire SD to FAT32 " , COLOR_RED , FORMAT_ALL_FAT32 , 1 } ,
{ " Format for EmuMMC setup (FAT32/RAW) " , COLOR_RED , FORMAT_EMUMMC , 1 }
2019-11-21 15:02:45 +00:00
} ;
2020-01-30 22:53:27 +00:00
menu_item mmcChoice [ 3 ] = {
{ " Back \n " , COLOR_WHITE , - 1 , 1 } ,
{ " SysMMC " , COLOR_ORANGE , SYSMMC , 1 } ,
{ " EmuMMC " , COLOR_BLUE , EMUMMC , 1 }
} ;
2020-03-17 23:41:09 +00:00
*/
2020-01-30 22:53:27 +00:00
2019-12-22 11:10:59 +00:00
2020-03-18 22:58:32 +00:00
int res = 0 , meter = 0 ;
2020-02-11 16:18:29 +00:00
void MainMenu_SDCard ( ) {
2020-03-18 22:58:32 +00:00
fileexplorer ( " SD:/ " , 0 ) ;
2020-02-11 16:18:29 +00:00
}
void MainMenu_EMMC ( ) {
2020-03-18 22:58:32 +00:00
gfx_clearscreen ( ) ;
gfx_printf ( " You're about to enter EMMC \n Modifying anything here \n can result in a BRICK! \n \n Please only continue \n if you know what you're doing \n \n Press Vol+/- to return \n " ) ;
if ( gfx_makewaitmenu ( " Press Power to enter " , 4 ) ) {
2020-02-11 16:18:29 +00:00
connect_mmc ( SYSMMC ) ;
2020-03-17 23:41:09 +00:00
if ( ! mount_mmc ( emmc_fs_entries [ res - 2 ] , res - 1 ) )
2020-03-18 22:58:32 +00:00
fileexplorer ( " emmc:/ " , 1 ) ;
2020-02-11 16:18:29 +00:00
}
}
void MainMenu_EMUMMC ( ) {
connect_mmc ( EMUMMC ) ;
2020-03-17 23:41:09 +00:00
if ( ! mount_mmc ( emmc_fs_entries [ res - 5 ] , res - 4 ) )
2020-03-18 22:58:32 +00:00
fileexplorer ( " emmc:/ " , 1 ) ;
2020-02-11 16:18:29 +00:00
}
void MainMenu_MountSD ( ) {
if ( return_sd_mounted ( 1 ) )
sd_unmount ( ) ;
else
sd_mount ( ) ;
}
void MainMenu_Tools ( ) {
2020-03-17 23:41:09 +00:00
//res = makemenu(toolsmenu, 8);
2020-03-19 15:17:36 +00:00
res = menu_make ( mainmenu_tools , 6 , " -- Tools Menu -- " ) ;
2020-02-11 16:18:29 +00:00
switch ( res ) {
2020-03-17 23:41:09 +00:00
case TOOLS_DISPLAY_INFO :
2020-02-11 16:18:29 +00:00
displayinfo ( ) ;
break ;
2020-03-17 23:41:09 +00:00
case TOOLS_DISPLAY_GPIO :
2020-02-11 16:18:29 +00:00
displaygpio ( ) ;
break ;
2020-03-17 23:41:09 +00:00
case TOOLS_DUMPFIRMWARE :
2020-02-11 16:18:29 +00:00
dumpfirmware ( SYSMMC ) ;
break ;
2020-03-17 23:41:09 +00:00
case TOOLS_DUMPUSERSAVE :
if ( ( res = utils_mmcMenu ( ) ) > 0 )
dumpusersaves ( res ) ;
2020-02-11 16:18:29 +00:00
break ;
2020-03-17 23:41:09 +00:00
case TOOLS_DUMP_BOOT :
2020-03-19 12:00:42 +00:00
dump_emmc_parts ( PART_BOOT | PART_PKG2 , SYSMMC ) ;
2020-03-14 14:03:08 +00:00
break ;
2020-02-11 16:18:29 +00:00
}
}
void MainMenu_SDFormat ( ) {
2020-03-17 23:41:09 +00:00
//res = makemenu(formatmenu, 4);
res = menu_make ( mainmenu_format , 3 , " -- Format Menu -- " ) ;
2020-02-11 16:18:29 +00:00
2020-03-17 23:41:09 +00:00
if ( res > 0 ) {
2020-03-18 22:58:32 +00:00
gfx_clearscreen ( ) ;
gfx_printf ( " Are you sure you want to format your sd? \n This will delete everything on your SD card \n This action is irreversible! \n \n Press Vol+/- to cancel \n " ) ;
if ( gfx_makewaitmenu ( " Press Power to continue " , 10 ) ) {
2020-02-11 16:18:29 +00:00
if ( format ( res ) ) {
sd_unmount ( ) ;
}
}
}
}
void MainMenu_Credits ( ) {
2020-03-18 22:58:32 +00:00
if ( + + meter > = 3 )
gfx_errDisplay ( " credits " , 53 , 0 ) ;
gfx_message ( COLOR_WHITE , CREDITS_MESSAGE ) ;
2020-02-11 16:18:29 +00:00
}
void MainMenu_Exit ( ) {
2020-03-17 23:41:09 +00:00
if ( return_sd_mounted ( 1 ) ) {
/*
2020-02-11 16:18:29 +00:00
shutdownmenu [ 5 ] . property = ( checkfile ( " /bootloader/update.bin " ) ) ? 1 : - 1 ;
shutdownmenu [ 6 ] . property = ( checkfile ( " /atmosphere/reboot_payload.bin " ) ) ? 1 : - 1 ;
2020-03-17 23:41:09 +00:00
*/
2020-03-18 22:58:32 +00:00
SETBIT ( mainmenu_shutdown [ 4 ] . property , ISHIDE , ! fsutil_checkfile ( " /bootloader/update.bin " ) ) ;
SETBIT ( mainmenu_shutdown [ 5 ] . property , ISHIDE , ! fsutil_checkfile ( " /atmosphere/reboot_payload.bin " ) ) ;
2020-02-11 16:18:29 +00:00
}
else {
2020-03-17 23:41:09 +00:00
for ( int i = 4 ; i < = 5 ; i + + )
SETBIT ( mainmenu_shutdown [ i ] . property , ISHIDE , 1 ) ;
2020-02-11 16:18:29 +00:00
}
2020-03-17 23:41:09 +00:00
//res = makemenu(shutdownmenu, 7);
res = menu_make ( mainmenu_shutdown , 6 , " -- Shutdown Menu -- " ) ;
2020-02-11 16:18:29 +00:00
switch ( res ) {
2020-03-17 23:41:09 +00:00
case SHUTDOWN_REBOOT_RCM :
2020-02-11 16:18:29 +00:00
reboot_rcm ( ) ;
2020-03-17 23:41:09 +00:00
case SHUTDOWN_REBOOT_NORMAL :
2020-02-11 16:18:29 +00:00
reboot_normal ( ) ;
2020-03-17 23:41:09 +00:00
case SHUTDOWN_POWER_OFF :
2020-02-11 16:18:29 +00:00
power_off ( ) ;
2020-03-17 23:41:09 +00:00
case SHUTDOWN_HEKATE :
2020-02-11 16:18:29 +00:00
launch_payload ( " /bootloader/update.bin " ) ;
2020-03-17 23:41:09 +00:00
case SHUTDOWN_AMS :
2020-02-11 16:18:29 +00:00
launch_payload ( " /atmosphere/reboot_payload.bin " ) ;
} //todo declock bpmp
}
part_handler mainmenu_functions [ ] = {
MainMenu_SDCard ,
MainMenu_EMMC ,
MainMenu_EMMC ,
MainMenu_EMMC ,
MainMenu_EMUMMC ,
MainMenu_EMUMMC ,
MainMenu_EMUMMC ,
MainMenu_MountSD ,
MainMenu_Tools ,
MainMenu_SDFormat ,
MainMenu_Credits ,
MainMenu_Exit ,
} ;
void RunMenuOption ( int option ) {
2020-03-18 22:58:32 +00:00
if ( option ! = 11 )
meter = 0 ;
2020-02-11 16:18:29 +00:00
if ( option > 0 )
mainmenu_functions [ option - 1 ] ( ) ;
}
2020-03-17 23:41:09 +00:00
/*
2019-11-21 15:02:45 +00:00
void fillmainmenu ( ) {
int i ;
for ( i = 0 ; i < MAINMENU_AMOUNT ; i + + ) {
switch ( i + 1 ) {
2020-01-27 22:51:59 +00:00
case 5 :
case 6 :
2019-12-22 11:10:59 +00:00
case 7 :
2020-01-27 22:51:59 +00:00
if ( mainmenu [ i ] . property = = - 2 )
continue ;
case 1 :
case 10 :
2019-12-20 20:00:47 +00:00
if ( return_sd_mounted ( i + 1 ) )
2019-11-21 15:02:45 +00:00
mainmenu [ i ] . property = 1 ;
else
mainmenu [ i ] . property = - 1 ;
break ;
2020-01-27 22:51:59 +00:00
case 8 :
2019-12-20 20:00:47 +00:00
if ( return_sd_mounted ( 1 ) ) {
2020-03-17 23:41:09 +00:00
//mainmenu[i].property = 2;
//strcpy(mainmenu[i].name, "\nUnmount SD");
mainmenu_main [ 7 ] . name = ( menu_sd_states [ 0 ] ) ;
2019-11-21 16:34:47 +00:00
}
else {
2020-03-17 23:41:09 +00:00
//mainmenu[i].property = 1;
//strcpy(mainmenu[i].name, "\nMount SD");
mainmenu_main [ 7 ] . name = ( menu_sd_states [ 1 ] ) ;
2019-11-21 16:34:47 +00:00
}
2019-11-21 15:02:45 +00:00
break ;
}
}
}
2020-03-17 23:41:09 +00:00
*/
2019-11-21 15:02:45 +00:00
void te_main ( ) {
2020-03-17 23:41:09 +00:00
int setter ;
2019-11-21 15:02:45 +00:00
2019-12-17 12:43:32 +00:00
if ( dump_biskeys ( ) = = - 1 ) {
2020-03-19 12:00:42 +00:00
gfx_errDisplay ( " dump_biskey " , ERR_BISKEY_DUMP_FAILED , 0 ) ;
2020-03-17 23:41:09 +00:00
for ( int i = 1 ; i < = 3 ; i + + )
mainmenu_main [ i ] . property | = ISHIDE ;
2019-12-17 12:43:32 +00:00
}
2019-11-21 16:34:47 +00:00
2020-01-27 22:51:59 +00:00
if ( emummc_load_cfg ( ) ) {
2020-03-17 23:41:09 +00:00
for ( int i = 4 ; i < = 6 ; i + + )
mainmenu_main [ i ] . property | = ISHIDE ;
2020-01-27 22:51:59 +00:00
}
2020-02-06 22:31:19 +00:00
disconnect_mmc ( ) ;
2019-11-21 15:02:45 +00:00
while ( 1 ) {
2020-03-17 23:41:09 +00:00
//fillmainmenu();
setter = return_sd_mounted ( 1 ) ;
if ( emu_cfg . enabled ) {
for ( int i = 4 ; i < = 6 ; i + + )
SETBIT ( mainmenu_main [ i ] . property , ISHIDE , ! setter ) ;
}
SETBIT ( mainmenu_main [ 0 ] . property , ISHIDE , ! setter ) ;
mainmenu_main [ 7 ] . name = ( menu_sd_states [ ! setter ] ) ;
/*
if ( return_sd_mounted ( 1 ) ) {
if ( emu_cfg . enabled ) {
for ( int i = 4 ; i < = 6 ; i + + )
SETBIT ( mainmenu_main [ i ] , ISHIDE , 0 ) ;
}
SETBIT ( mainmenu_main [ 0 ] , ISHIDE , 0 ) ;
mainmenu_main [ 7 ] . name = ( menu_sd_states [ 0 ] ) ;
}
else {
if ( emu_cfg . enabled ) {
for ( int i = 4 ; i < = 6 ; i + + )
SETBIT ( mainmenu_main [ i ] , ISHIDE , 1 ) ;
}
SETBIT ( mainmenu_main [ 0 ] , ISHIDE , 1 ) ;
mainmenu_main [ 7 ] . name = ( menu_sd_states [ 1 ] ) ;
}
*/
setter = return_sd_mounted ( 10 ) ;
SETBIT ( mainmenu_main [ 9 ] . property , ISHIDE , ! setter ) ;
/*
if ( return_sd_mounted ( 10 ) )
SETBIT ( mainmenu_main [ 0 ] , ISHIDE , 0 ) ;
else
SETBIT ( mainmenu_main [ 0 ] , ISHIDE , 1 ) ;
*/
//res = makemenu(mainmenu, MAINMENU_AMOUNT);
res = menu_make ( mainmenu_main , 12 , " -- Main Menu -- " ) + 1 ;
2020-02-11 16:18:29 +00:00
RunMenuOption ( res ) ;
2019-11-21 15:02:45 +00:00
}
}