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-31 23:17:45 +01:00
# include "script/functions.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-04-04 15:49:47 +01:00
# include "emmc/emmcmenu.h"
2020-05-01 19:09:17 +01:00
# include "../storage/nx_sd.h"
2020-05-01 21:42:49 +01:00
//#include "../hid/joycon.h"
# include "../hid/hid.h"
2020-05-01 19:09:17 +01:00
/*
2019-11-21 15:02:45 +00:00
extern bool sd_mount ( ) ;
extern void sd_unmount ( ) ;
2020-05-01 19:09:17 +01:00
*/
2019-12-01 14:42:37 +00:00
extern int launch_payload ( char * path ) ;
2020-03-22 21:56:36 +00:00
extern bool sd_inited ;
extern bool sd_mounted ;
2020-05-01 21:42:49 +01:00
extern bool disableB ;
2019-11-21 15:02:45 +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-05-02 13:06:56 +01:00
if ( gfx_defaultWaitMenu ( " You're about to enter EMMC \n Modifying anything here can result in a BRICK! \n \n Please only continue if you know what you're doing " , 4 ) ) {
2020-04-04 15:49:47 +01:00
makeMmcMenu ( SYSMMC ) ;
2020-02-11 16:18:29 +00:00
}
}
void MainMenu_EMUMMC ( ) {
2020-05-09 12:52:46 +01:00
makeMmcMenu ( EMUMMC ) ;
2020-02-11 16:18:29 +00:00
}
void MainMenu_MountSD ( ) {
2020-03-22 21:56:36 +00:00
( sd_mounted ) ? sd_unmount ( ) : sd_mount ( ) ;
2020-02-11 16:18:29 +00:00
}
void MainMenu_Tools ( ) {
2020-05-09 12:52:46 +01:00
res = menu_make ( mainmenu_tools , 4 , " -- 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 ;
}
}
void MainMenu_SDFormat ( ) {
2020-03-17 23:41:09 +00:00
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-05-02 13:06:56 +01:00
if ( gfx_defaultWaitMenu ( " Are you sure you want to format your sd? \n This will delete everything on your SD card! \n This action is irreversible! " , 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 ) ;
2020-03-19 22:01:30 +00:00
gfx_message ( COLOR_WHITE , mainmenu_credits ) ;
2020-02-11 16:18:29 +00:00
}
void MainMenu_Exit ( ) {
2020-03-22 21:56:36 +00:00
if ( sd_mounted ) {
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 = menu_make ( mainmenu_shutdown , 6 , " -- Shutdown Menu -- " ) ;
2020-05-04 12:55:26 +01:00
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
2020-05-04 12:55:26 +01:00
2020-02-11 16:18:29 +00:00
}
2020-03-31 23:17:45 +01:00
func_void_ptr mainmenu_functions [ ] = {
2020-02-11 16:18:29 +00:00
MainMenu_SDCard ,
MainMenu_EMMC ,
MainMenu_EMUMMC ,
MainMenu_MountSD ,
MainMenu_Tools ,
MainMenu_SDFormat ,
MainMenu_Credits ,
MainMenu_Exit ,
} ;
void RunMenuOption ( int option ) {
2020-04-04 15:49:47 +01:00
if ( option ! = 7 )
2020-03-18 22:58:32 +00:00
meter = 0 ;
2020-02-11 16:18:29 +00:00
if ( option > 0 )
mainmenu_functions [ option - 1 ] ( ) ;
}
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
2020-05-04 12:55:26 +01:00
//gfx_printf("Initing controller\n");
hidInit ( ) ;
//gfx_printf("Getting biskeys\n");
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-04-14 08:40:37 +01:00
//mainmenu_main[1].property |= ISHIDE;
2019-12-17 12:43:32 +00:00
}
2019-11-21 16:34:47 +00:00
2020-05-04 12:55:26 +01:00
//gfx_printf("Mounting SD\n");
2020-05-01 19:09:17 +01:00
sd_mount ( ) ;
2020-05-04 12:55:26 +01:00
//gfx_printf("Loading possible EMU\n");
2020-01-27 22:51:59 +00:00
if ( emummc_load_cfg ( ) ) {
2020-04-04 15:49:47 +01:00
mainmenu_main [ 2 ] . property | = ISHIDE ;
2020-01-27 22:51:59 +00:00
}
2020-04-14 08:40:37 +01:00
2020-05-04 12:55:26 +01:00
//gfx_printf("Dumping gpt\n");
2020-04-14 08:40:37 +01:00
dumpGpt ( ) ;
2020-01-27 22:51:59 +00:00
2020-05-04 12:55:26 +01:00
//gfx_printf("Disconnecting EMMC\n");
2020-02-06 22:31:19 +00:00
disconnect_mmc ( ) ;
2020-05-04 12:55:26 +01:00
//gfx_printf("Entering main menu\n");
2019-11-21 15:02:45 +00:00
while ( 1 ) {
2020-03-22 21:56:36 +00:00
setter = sd_mounted ;
2020-03-17 23:41:09 +00:00
if ( emu_cfg . enabled ) {
2020-04-04 15:49:47 +01:00
SETBIT ( mainmenu_main [ 2 ] . property , ISHIDE , ! setter ) ;
2020-03-17 23:41:09 +00:00
}
2020-03-19 22:01:30 +00:00
2020-03-17 23:41:09 +00:00
SETBIT ( mainmenu_main [ 0 ] . property , ISHIDE , ! setter ) ;
2020-04-04 15:49:47 +01:00
mainmenu_main [ 3 ] . name = ( menu_sd_states [ ! setter ] ) ;
2020-03-17 23:41:09 +00:00
2020-03-22 21:56:36 +00:00
setter = sd_inited ;
2020-04-04 15:49:47 +01:00
SETBIT ( mainmenu_main [ 5 ] . property , ISHIDE , ! setter ) ;
2020-03-17 23:41:09 +00:00
2020-05-01 21:42:49 +01:00
disableB = true ;
2020-04-04 15:49:47 +01:00
res = menu_make ( mainmenu_main , 8 , " -- Main Menu -- " ) + 1 ;
2020-05-01 21:42:49 +01:00
disableB = false ;
2020-02-11 16:18:29 +00:00
RunMenuOption ( res ) ;
2019-11-21 15:02:45 +00:00
}
}