1
0
Fork 0
mirror of https://github.com/suchmememanyskill/TegraExplorer.git synced 2024-12-26 11:26:05 +00:00

add more functions

This commit is contained in:
Such Meme, Many Skill 2020-04-01 00:17:45 +02:00
parent 45a732c388
commit 0e39c8dda9
5 changed files with 137 additions and 21 deletions

View file

@ -145,7 +145,7 @@ int filemenu(menu_entry file){
}
SETBIT(fs_menu_file[7].property, ISHIDE, !(strstr(file.name, ".bin") != NULL && file.property & ISKB));
SETBIT(fs_menu_file[8].property, ISHIDE, !(strstr(file.name, ".tegrascript") != NULL));
SETBIT(fs_menu_file[8].property, ISHIDE, !(strstr(file.name, ".te") != NULL));
SETBIT(fs_menu_file[10].property, ISHIDE, !(strstr(file.name, ".bis") != NULL));
SETBIT(fs_menu_file[11].property, ISHIDE, !(strstr(file.name, ".bis") != NULL));

View file

@ -6,7 +6,7 @@
#include "../utils/btn.h"
#include "emmc/emmc.h"
#include "../storage/emummc.h"
#include "utils/script.h"
#include "script/functions.h"
#include "common/common.h"
#include "gfx/menu.h"
@ -127,7 +127,7 @@ void MainMenu_Exit(){
} //todo declock bpmp
}
part_handler mainmenu_functions[] = {
func_void_ptr mainmenu_functions[] = {
MainMenu_SDCard,
MainMenu_EMMC,
MainMenu_EMMC,

View file

@ -17,10 +17,12 @@
#include "../utils/utils.h"
#include "functions.h"
#include "../fs/fsutils.h"
#include "../../utils/sprintf.h"
extern FIL scriptin;
extern char **argv;
extern u32 argc;
extern int forceExit;
int parseIntInput(char *in, int *out){
if (in[0] == '@'){
@ -57,8 +59,10 @@ int parseStringInput(char *in, char **out){
}
}
u32 currentcolor = COLOR_WHITE;
int part_printf(){
char *toprint;
SWAPCOLOR(currentcolor);
parseStringInput(argv[0], &toprint);
gfx_printf(toprint);
gfx_printf("\n");
@ -73,6 +77,24 @@ int part_print_int(){
return 0;
}
int part_Wait(){
int arg;
u32 begintime;
SWAPCOLOR(currentcolor);
if (parseIntInput(argv[0], &arg))
return -1;
begintime = get_tmr_s();
while (begintime + arg > get_tmr_s()){
gfx_printf("\r<Wait %d seconds> ", (begintime + arg) - get_tmr_s());
}
gfx_printf("\r \r");
return 0;
}
int part_if(){
int condition;
if (parseIntInput(argv[0], &condition))
@ -105,7 +127,7 @@ int part_Math(){
case '/':
return left * right;
}
return 0;
return -1;
}
int part_Check(){
@ -138,9 +160,13 @@ int part_SetInt(){
}
int part_SetString(){
char *arg0;
if (parseStringInput(argv[0], &arg0))
return -1;
if (argv[1][0] != '$')
return -1;
str_str_add(argv[1], argv[0]);
str_str_add(argv[1], arg0);
return 0;
}
@ -180,6 +206,87 @@ int part_fs_exists(){
return fsutil_checkfile(path);
}
int part_ConnectMMC(){
char *arg;
parseStringInput(argv[0], &arg);
if (!strcmp(arg, "SYSMMC"))
connect_mmc(SYSMMC);
else if (!strcmp(arg, "EMUMMC"))
connect_mmc(EMUMMC);
else
return -1;
return 0;
}
int part_MountMMC(){
char *arg;
parseStringInput(argv[0], &arg);
return mount_mmc(arg, 2);
}
int part_Pause(){
int res;
while (btn_read() != 0);
res = btn_wait();
str_int_add("@BTN_POWER", (res & BTN_POWER));
str_int_add("@BTN_VOL+", (res & BTN_VOL_UP));
str_int_add("@BTN_VOL-", (res & BTN_VOL_DOWN));
return res;
}
int part_addstrings(){
char *combined, *left, *middle;
if (parseStringInput(argv[0], &left))
return -1;
if (parseStringInput(argv[1], &middle))
return -1;
if (argv[2][0] != '$')
return -1;
combined = calloc(strlen(left) + strlen(middle) + 1, sizeof(char));
sprintf(combined, "%s%s", left, middle);
str_str_add(argv[2], combined);
free(combined);
return 0;
}
int part_setColor(){
char *arg;
if (parseStringInput(argv[0], &arg))
return -1;
if (!strcmp(arg, "RED"))
currentcolor = COLOR_RED;
else if (!strcmp(arg, "ORANGE"))
currentcolor = COLOR_ORANGE;
else if (!strcmp(arg, "YELLOW"))
currentcolor = COLOR_YELLOW;
else if (!strcmp(arg, "GREEN"))
currentcolor = COLOR_GREEN;
else if (!strcmp(arg, "BLUE"))
currentcolor = COLOR_BLUE;
else if (!strcmp(arg, "VIOLET"))
currentcolor = COLOR_VIOLET;
else if (!strcmp(arg, "WHITE"))
currentcolor = COLOR_WHITE;
else
return -1;
return 0;
}
int part_Exit(){
forceExit = true;
return 0;
}
str_fnc_struct functions[] = {
{"printf", part_printf, 1},
{"printInt", part_print_int, 1},
@ -190,8 +297,15 @@ str_fnc_struct functions[] = {
{"goto", part_goto, 1},
{"setString", part_SetString, 2},
{"setStringIndex", part_SetStringIndex, 2},
{"setColor", part_setColor, 1},
{"combineStrings", part_addstrings, 3},
{"invert", part_invert, 1},
{"fs_exists", part_fs_exists, 1},
{"mmc_connect", part_ConnectMMC, 1},
{"mmc_mount", part_MountMMC, 1},
{"pause", part_Pause, 0},
{"wait", part_Wait, 1},
{"exit", part_Exit, 0},
{NULL, NULL, 0}
};

View file

@ -120,6 +120,10 @@ char *readtilchar(char end, char ignore){
offset = f_tell(&scriptin);
getfollowingchar(end);
size = f_tell(&scriptin) - offset;
if (size <= 0)
return NULL;
f_lseek(&scriptin, offset - 1);
return makestr((u32)size, ignore);
@ -144,8 +148,13 @@ void functionparser(){
unsplitargs = readtilchar(')', 0);
argc = splitargs(unsplitargs);
getnextchar();
if (unsplitargs != NULL){
argc = splitargs(unsplitargs);
getnextchar();
}
else {
argc = 0;
}
getnextchar();
free(unsplitargs);
@ -199,7 +208,8 @@ void mainparser(){
res = run_function(funcbuff, &out);
if (res < 0){
printerrors = true;
btn_wait();
//gfx_printf("%s|%s|%d", funcbuff, argv[0], argc);
//btn_wait();
gfx_errDisplay("mainparser", ERR_PARSE_FAIL, f_tell(&scriptin));
forceExit = true;
//gfx_printf("Func: %s\nArg1: %s\n", funcbuff, argv[0]);
@ -246,10 +256,12 @@ void skipbrackets(){
}
}
extern u32 currentcolor;
void tester(char *path){
int res;
forceExit = false;
currentchar = 0;
currentcolor = COLOR_WHITE;
gfx_clearscreen();
res = f_open(&scriptin, path, FA_READ | FA_OPEN_EXISTING);
@ -257,6 +269,8 @@ void tester(char *path){
gfx_errDisplay("ParseScript", res, 1);
return;
}
printerrors = false;
//add builtin vars
str_int_add("@EMUMMC", emu_cfg.enabled);
@ -266,7 +280,6 @@ void tester(char *path){
str_int_add("@BTN_VOL-", 0);
//str_int_printall();
printerrors = false;
while (!f_eof(&scriptin) && !forceExit){
mainparser();
@ -279,5 +292,5 @@ void tester(char *path){
str_int_clear();
str_jmp_clear();
str_str_clear();
btn_wait();
//btn_wait();
}

View file

@ -1,11 +0,0 @@
#pragma once
#define strcmpcheck(x, y) (!strcmp(x, y))
typedef void (*part_handler)();
typedef struct _script_parts {
char name[11];
part_handler handler;
short arg_amount;
} script_parts;
//void ParseScript(char* path);