From 249a6c9a3a8570c4270eceadf9c7e26ee8190f20 Mon Sep 17 00:00:00 2001 From: Nemhardy Date: Thu, 3 Mar 2016 00:32:59 +0100 Subject: [PATCH] Now saving the choice wether pretty print is enabled or not --- Taumath.cpp | 3 +++ config.c | 37 ++++++++++++++++++++++++++----------- config.h | 12 ++++++++++-- 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/Taumath.cpp b/Taumath.cpp index 1dba4ad..25506d4 100644 --- a/Taumath.cpp +++ b/Taumath.cpp @@ -7,6 +7,7 @@ extern "C"{ #include "fxlib.h" #include "syscalls.h" #include "tex/TeX.h" +#include "config.h" #define EXPR_BUF_SIZE 256 extern U ** mem; @@ -81,6 +82,8 @@ int AddIn_main(int isAppli, unsigned short OptionNum) TeX_init(); Console_Init(); Console_Disp(); + load_config(); + while(1) { if((expr=Console_GetLine())==NULL) stop("memory error"); diff --git a/config.c b/config.c index 8dbbaaa..caa699c 100644 --- a/config.c +++ b/config.c @@ -43,16 +43,16 @@ void draw_menu(Menu* menu) for(i=0; i < menu->items_number; i++) { PrintMini(box.left + border + margin, box.top + margin + item_height*i, (unsigned char*)menu->items[i]->str, MINI_OVER); if(menu->items[i]->type == CHECK_BOX) { - if((menu->items[i]->action.value)) { - if(*(menu->items[i]->action.value)) PrintMini(box.right - border - margin - (check_box_width/2) , box.top + margin + item_height*i, (unsigned char*)"[x]", MINI_OVER); + if((menu->items[i]->action.val.value)) { + if(*(menu->items[i]->action.val.value)) PrintMini(box.right - border - margin - (check_box_width/2) , box.top + margin + item_height*i, (unsigned char*)"[x]", MINI_OVER); else PrintMini(box.right - border - margin - (check_box_width/2) , box.top + margin + item_height*i, (unsigned char*)"[ ]", MINI_OVER); } } } PrintMini(box.left + border + margin, box.top + margin + item_height*cursor_y, (unsigned char*)menu->items[cursor_y]->str, MINI_REV); if(menu->items[cursor_y]->type == CHECK_BOX) { - if((menu->items[cursor_y]->action.value)) { - if(*(menu->items[cursor_y]->action.value)) PrintMini(box.right - border - margin - (check_box_width/2) , box.top + margin + item_height*cursor_y, (unsigned char*)"[x]", MINI_OVER); + if((menu->items[cursor_y]->action.val.value)) { + if(*(menu->items[cursor_y]->action.val.value)) PrintMini(box.right - border - margin - (check_box_width/2) , box.top + margin + item_height*cursor_y, (unsigned char*)"[x]", MINI_OVER); else PrintMini(box.right - border - margin - (check_box_width/2) , box.top + margin + item_height*cursor_y, (unsigned char*)"[ ]", MINI_OVER); } } @@ -64,9 +64,11 @@ void draw_menu(Menu* menu) if (key == KEY_CTRL_EXE) { //menu_test(); if(menu->items[cursor_y]->type == CHECK_BOX) { - if(menu->items[cursor_y]->action.value != NULL) { //Changing the state of the variable, as a boolean - if(*(menu->items[cursor_y]->action.value)) *(menu->items[cursor_y]->action.value) = 0; - else *(menu->items[cursor_y]->action.value) = 1; + if(menu->items[cursor_y]->action.val.value != NULL) { //Changing the state of the variable, as a boolean + if(*(menu->items[cursor_y]->action.val.value)) *(menu->items[cursor_y]->action.val.value) = 0; + else *(menu->items[cursor_y]->action.val.value) = 1; + + if (menu->items[cursor_y]->action.val.save_function != NULL) (*menu->items[cursor_y]->action.val.save_function)(); } } else if(menu->items[cursor_y]->type == FUNCTION_CALL) { @@ -85,8 +87,8 @@ void menu_setup() Menu menu; menu.items = malloc(sizeof(Menu_Item*) * number); - menu.items[0] = menu_create_item("About", FUNCTION_CALL, menu_about); - menu.items[1] = menu_create_item("Pretty Print", CHECK_BOX, get_tex_flag_address()); + menu.items[0] = menu_create_item("About", FUNCTION_CALL, menu_about, (void*)NULL); + menu.items[1] = menu_create_item("Pretty Print", CHECK_BOX, get_tex_flag_address(), save_config); if(menu.items[0] && menu.items[1]) menu.items_number = number; else { menu_free_item(menu.items[0]); @@ -115,7 +117,7 @@ void menu_about() return; } -Menu_Item* menu_create_item(const char* str, Menu_Item_Type type, void* other) +Menu_Item* menu_create_item(const char* str, Menu_Item_Type type, void* other, void* save_func) { Menu_Item* item = malloc(sizeof(Menu_Item)); if(item == NULL) return NULL; @@ -129,8 +131,21 @@ Menu_Item* menu_create_item(const char* str, Menu_Item_Type type, void* other) item->type = type; - if(type == CHECK_BOX) item->action.value = other; + if(type == CHECK_BOX) { + item->action.val.value = other; + item->action.val.save_function = save_func; + } else if(type == FUNCTION_CALL) item->action.function = other; return item; +} + +void save_config() +{ + memory_save(CONFIG_FILE, (int*)get_tex_flag_address(), 4); +} + +void load_config() +{ + if(memory_exists(CONFIG_FILE)) *(int*)(get_tex_flag_address()) = *((int*)memory_load(CONFIG_FILE)); } \ No newline at end of file diff --git a/config.h b/config.h index 779077f..dc270c6 100644 --- a/config.h +++ b/config.h @@ -6,6 +6,8 @@ extern "C"{ #endif +#define CONFIG_FILE "\\\\fls0\\EIGEN.CONF" + typedef enum { CHECK_BOX, FUNCTION_CALL, } Menu_Item_Type; @@ -14,7 +16,10 @@ typedef struct { char* str; Menu_Item_Type type; union { //The item can act on a variable or call a function - int* value; + struct { + int* value; + void (*save_function)(void); + } val; void (*function)(void); } action; } Menu_Item; @@ -28,7 +33,10 @@ typedef struct { void draw_menu(Menu* menu); void menu_setup(); void menu_about(); -Menu_Item* menu_create_item(const char* str, Menu_Item_Type type, void* other); +Menu_Item* menu_create_item(const char* str, Menu_Item_Type type, void* other, void* save_func); + +void save_config(); +void load_config(); #ifdef __cplusplus }