2019-12-01 16:10:01 +00:00
# include <string.h>
# include <stdlib.h>
# include <stdio.h>
2019-11-21 15:02:45 +00:00
# include "../gfx/gfx.h"
# include "te.h"
# include "../utils/btn.h"
2019-12-01 00:49:36 +00:00
# include "../utils/util.h"
2019-11-21 15:02:45 +00:00
# include "gfx.h"
2019-12-01 00:49:36 +00:00
# include "fs.h"
2019-12-01 16:10:01 +00:00
# include "../mem/minerva.h"
2020-03-03 14:19:42 +00:00
# include "../power/max17050.h"
2020-01-04 19:18:26 +00:00
# include <stdarg.h>
2020-03-16 23:26:35 +00:00
# include "../storage/emummc.h"
# include "emmc.h"
2019-12-01 00:49:36 +00:00
const char fixedoptions [ 3 ] [ 50 ] = {
2019-12-01 19:31:17 +00:00
" Folder -> previous folder " ,
" Clipboard -> Current folder " ,
2020-01-01 23:38:36 +00:00
" Current folder menu "
2019-12-01 00:49:36 +00:00
} ;
const char sizevalues [ 4 ] [ 3 ] = {
2019-12-03 09:06:11 +00:00
" B " ,
2019-12-01 00:49:36 +00:00
" KB " ,
" MB " ,
" GB "
} ;
2019-11-21 15:02:45 +00:00
void clearscreen ( ) {
2020-03-03 14:19:42 +00:00
int battery = 0 ;
max17050_get_property ( MAX17050_RepSOC , & battery ) ;
2019-11-21 15:02:45 +00:00
gfx_clear_grey ( 0x1B ) ;
2020-03-03 14:19:42 +00:00
SWAPCOLOR ( COLOR_DEFAULT ) ;
SWAPBGCOLOR ( COLOR_WHITE ) ;
gfx_box ( 0 , 1263 , 719 , 1279 , COLOR_WHITE ) ;
gfx_con_setpos ( 0 , 1263 ) ;
gfx_printf ( " Move: Vol+/- | Select: Pow | Battery: %3d%% " , battery > > 8 ) ;
2019-11-21 15:02:45 +00:00
gfx_box ( 0 , 0 , 719 , 15 , COLOR_WHITE ) ;
gfx_con_setpos ( 0 , 0 ) ;
2020-03-15 11:35:18 +00:00
gfx_printf ( " Tegraexplorer v1.3.3 \n " ) ;
2020-03-03 14:19:42 +00:00
RESETCOLOR ;
2019-11-21 15:02:45 +00:00
}
2020-01-04 19:18:26 +00:00
int message ( u32 color , const char * message , . . . ) {
va_list ap ;
va_start ( ap , message ) ;
2019-11-21 15:02:45 +00:00
clearscreen ( ) ;
2020-01-04 19:18:26 +00:00
SWAPCOLOR ( color ) ;
gfx_vprintf ( message , ap ) ;
va_end ( ap ) ;
2019-11-21 15:02:45 +00:00
return btn_wait ( ) ;
}
2020-03-17 23:41:09 +00:00
/*
int gfx_errprint ( u32 color , int func , int err , int add ) {
clearscreen ( ) ;
SWAPCOLOR ( COLOR_ORANGE ) ;
gfx_printf ( " \n An error occured: \n \n " ) ;
gfx_printf ( " Function: %s \n Errcode: %d \n Desc: %s \n " ) ;
if ( add )
gfx_printf ( " Additional info: %d " ) ;
gfx_printf ( " \n Press any button to return " ) ;
RESETCOLOR ;
return btn_wait ( ) ;
}
*/
// Change makemenu to combine makefilemenu to save space + make nagivation more consistant
2019-11-21 15:02:45 +00:00
int makemenu ( menu_item menu [ ] , int menuamount ) {
int currentpos = 1 , i , res ;
clearscreen ( ) ;
while ( 1 ) {
gfx_con_setpos ( 0 , 31 ) ;
2019-11-21 16:34:47 +00:00
if ( currentpos = = 1 ) {
2019-11-21 19:54:18 +00:00
while ( currentpos < menuamount & & menu [ currentpos - 1 ] . property < 1 )
2019-11-21 16:34:47 +00:00
currentpos + + ;
}
if ( currentpos = = menuamount ) {
2019-11-21 19:54:18 +00:00
while ( currentpos > 1 & & menu [ currentpos - 1 ] . property < 1 )
2019-11-21 16:34:47 +00:00
currentpos - - ;
}
2019-11-21 15:02:45 +00:00
for ( i = 0 ; i < menuamount ; i + + ) {
2019-11-21 16:34:47 +00:00
if ( menu [ i ] . property < 0 )
2019-11-21 15:02:45 +00:00
continue ;
if ( i = = currentpos - 1 )
gfx_printf ( " %k%K%s%K \n " , COLOR_DEFAULT , COLOR_WHITE , menu [ i ] . name , COLOR_DEFAULT ) ;
else
gfx_printf ( " %k%s \n " , menu [ i ] . color , menu [ i ] . name ) ;
}
gfx_printf ( " \n %k%s " , COLOR_WHITE , menuamount ) ;
res = btn_wait ( ) ;
2019-11-21 16:34:47 +00:00
if ( res & BTN_VOL_UP & & currentpos > 1 ) {
2019-11-21 15:02:45 +00:00
currentpos - - ;
2019-11-21 19:54:18 +00:00
while ( menu [ currentpos - 1 ] . property < 1 & & currentpos > 1 )
2019-11-21 16:34:47 +00:00
currentpos - - ;
}
else if ( res & BTN_VOL_DOWN & & currentpos < menuamount ) {
2019-11-21 15:02:45 +00:00
currentpos + + ;
2019-11-21 19:54:18 +00:00
while ( menu [ currentpos - 1 ] . property < 1 & & currentpos < menuamount )
2019-11-21 16:34:47 +00:00
currentpos + + ;
}
2019-11-21 15:02:45 +00:00
else if ( res & BTN_POWER )
return menu [ currentpos - 1 ] . internal_function ;
}
2019-12-01 00:49:36 +00:00
}
2019-12-07 20:49:58 +00:00
void printbytes ( u8 print [ ] , u32 size , u32 offset ) {
gfx_con_setpos ( 0 , 31 ) ;
gfx_hexdump ( offset , print , size * sizeof ( u8 ) ) ;
}
2019-12-11 12:18:57 +00:00
int makewaitmenu ( char * initialmessage , char * hiddenmessage , int timer ) {
clearscreen ( ) ;
2020-03-15 11:35:18 +00:00
return makewaitmenunoclear ( initialmessage , hiddenmessage , timer ) ;
}
int makewaitmenunoclear ( char * initialmessage , char * hiddenmessage , int timer ) {
2019-12-11 12:18:57 +00:00
int res ;
u32 start = get_tmr_s ( ) ;
gfx_printf ( initialmessage ) ;
2020-03-15 11:35:18 +00:00
while ( btn_read ( ) ! = 0 ) ;
2019-12-11 12:18:57 +00:00
while ( 1 ) {
res = btn_read ( ) ;
if ( res & BTN_VOL_DOWN | | res & BTN_VOL_UP )
return 0 ;
if ( start + timer > get_tmr_s ( ) )
2019-12-11 13:45:30 +00:00
gfx_printf ( " \r <Wait %d seconds> " , timer + start - get_tmr_s ( ) ) ;
2019-12-11 12:18:57 +00:00
else if ( res & BTN_POWER )
return 1 ;
else
gfx_printf ( " \r %k%s%k " , COLOR_RED , hiddenmessage , COLOR_WHITE ) ;
}
}
2020-03-16 23:26:35 +00:00
/*
int mmcChoiceMenu ( ) {
if ( emu_cfg . enabled ) {
}
return SYSMMC ;
}
*/
2020-01-04 19:18:26 +00:00
void gfx_print_length ( int size , char * toprint ) {
char * temp ;
temp = ( char * ) malloc ( size + 1 ) ;
if ( strlen ( toprint ) > size ) {
strlcpy ( temp , toprint , size ) ;
memset ( temp + size - 3 , ' . ' , 3 ) ;
memset ( temp + size , ' \0 ' , 1 ) ;
}
else
strcpy ( temp , toprint ) ;
gfx_printf ( " %s " , temp ) ;
free ( temp ) ;
}
2019-12-01 19:31:17 +00:00
void printfsentry ( fs_entry file , bool highlight , bool refresh ) {
2019-12-01 00:49:36 +00:00
int size = 0 ;
2019-12-01 16:10:01 +00:00
char * display ;
2019-12-01 19:31:17 +00:00
int length ;
2019-12-01 16:10:01 +00:00
display = ( char * ) malloc ( 38 ) ;
memset ( display + 37 , ' \0 ' , 1 ) ;
if ( strlen ( file . name ) > 37 ) {
strlcpy ( display , file . name , 37 ) ;
memset ( display + 34 , ' . ' , 3 ) ;
}
2019-12-01 19:31:17 +00:00
else
2019-12-01 16:10:01 +00:00
strcpy ( display , file . name ) ;
2020-01-04 19:18:26 +00:00
2019-12-01 00:49:36 +00:00
if ( highlight )
gfx_printf ( " %K%k " , COLOR_WHITE , COLOR_DEFAULT ) ;
else
2019-12-18 15:02:45 +00:00
RESETCOLOR ;
2019-12-01 00:49:36 +00:00
if ( file . property & ISDIR )
2019-12-18 15:02:45 +00:00
gfx_printf ( " %s " , display ) ;
2019-12-01 00:49:36 +00:00
else {
for ( size = 4 ; size < 8 ; size + + )
if ( ( file . property & ( 1 < < size ) ) )
break ;
2019-12-18 15:02:45 +00:00
SWAPCOLOR ( COLOR_VIOLET ) ;
gfx_printf ( " %s " , display ) ;
2019-12-01 19:31:17 +00:00
}
2019-12-18 15:02:45 +00:00
RESETCOLOR ;
2019-12-01 19:31:17 +00:00
if ( refresh ) {
length = strlen ( display ) ;
for ( int i = 0 ; i < ( 42 - length ) ; i + + )
gfx_printf ( " " ) ;
2019-12-01 00:49:36 +00:00
}
2019-12-01 19:31:17 +00:00
2019-12-18 15:02:45 +00:00
if ( file . property & ISDIR )
gfx_printf ( " \n " ) ;
else {
SWAPCOLOR ( COLOR_BLUE ) ;
2019-12-01 19:31:17 +00:00
gfx_printf ( " \a %d \ e%s " , file . size , sizevalues [ size - 4 ] ) ;
2019-12-18 15:02:45 +00:00
}
2019-12-01 19:31:17 +00:00
2019-12-01 16:20:46 +00:00
free ( display ) ;
2019-12-01 00:49:36 +00:00
}
int makefilemenu ( fs_entry * files , int amount , char * path ) {
2019-12-01 19:31:17 +00:00
int currentpos = - 2 , i , res = 0 , offset = 0 , quickoffset = 300 ;
2020-03-17 23:41:09 +00:00
u32 timer , scrolltimer ;
2019-12-01 19:31:17 +00:00
bool refresh = false ;
2019-12-01 00:49:36 +00:00
clearscreen ( ) ;
gfx_con_setpos ( 544 , 0 ) ;
2020-01-04 19:18:26 +00:00
gfx_printf ( " %K%k%d files \n %K%k%s%k \n \n " , COLOR_WHITE , COLOR_DEFAULT , amount , COLOR_DEFAULT , COLOR_GREEN , path , COLOR_DEFAULT ) ;
2019-12-01 00:49:36 +00:00
while ( 1 ) {
gfx_con_setpos ( 0 , 47 ) ;
2019-12-01 16:10:01 +00:00
timer = get_tmr_ms ( ) ;
2019-12-01 19:31:17 +00:00
for ( i = - 3 + offset ; i < amount & & i < 60 + offset ; i + + ) {
2019-12-01 00:49:36 +00:00
if ( i < 0 ) {
if ( i = = currentpos - 1 )
gfx_printf ( " %k%K%s%K \n " , COLOR_ORANGE , COLOR_WHITE , fixedoptions [ i + 3 ] , COLOR_DEFAULT ) ;
else
2019-12-01 16:10:01 +00:00
gfx_printf ( " %k%K%s \n " , COLOR_ORANGE , COLOR_DEFAULT , fixedoptions [ i + 3 ] ) ;
2019-12-01 00:49:36 +00:00
}
else
2019-12-01 19:31:17 +00:00
printfsentry ( files [ i ] , ( i = = currentpos - 1 ) , refresh ) ;
2019-12-01 00:49:36 +00:00
}
2019-12-01 19:31:17 +00:00
refresh = false ;
gfx_printf ( " \n %k%K %s %s \n \n Time taken for screen draw: %dms " , COLOR_BLUE , COLOR_DEFAULT , ( offset + 60 < amount ) ? " v " : " " , ( offset > 0 ) ? " ^ " : " " , get_tmr_ms ( ) - timer ) ;
2019-12-01 16:10:01 +00:00
2020-03-17 23:41:09 +00:00
while ( btn_read ( ) & BTN_POWER ) ;
res = 0 ;
while ( ! res ) {
2019-12-01 00:49:36 +00:00
res = btn_read ( ) ;
2020-03-17 23:41:09 +00:00
if ( ! res )
quickoffset = 300 ;
if ( quickoffset < 300 ) {
scrolltimer = get_tmr_ms ( ) ;
while ( res ) {
if ( scrolltimer + quickoffset < = get_tmr_ms ( ) )
break ;
res = btn_read ( ) ;
}
}
if ( quickoffset > 46 & & res )
quickoffset - = 45 ;
}
2019-12-01 00:49:36 +00:00
2019-12-01 16:10:01 +00:00
if ( ( res & BTN_VOL_UP ) & & currentpos > - 2 ) {
2019-12-01 00:49:36 +00:00
currentpos - - ;
2019-12-01 16:10:01 +00:00
if ( offset ! = 0 & & currentpos < offset - 2 ) {
offset - - ;
2019-12-01 19:31:17 +00:00
refresh = true ;
2019-12-01 16:10:01 +00:00
}
}
if ( ( res & BTN_VOL_DOWN ) & & currentpos < amount ) {
2019-12-01 00:49:36 +00:00
currentpos + + ;
2019-12-01 19:31:17 +00:00
if ( currentpos - offset > 60 ) {
2019-12-01 16:10:01 +00:00
offset + + ;
2019-12-01 19:31:17 +00:00
refresh = true ;
2019-12-01 16:10:01 +00:00
}
}
2019-12-01 00:49:36 +00:00
if ( res & BTN_POWER )
return currentpos ;
}
2019-12-01 16:10:01 +00:00
minerva_periodic_training ( ) ;
2019-11-21 15:02:45 +00:00
}