Work on settings

Start work on new file gui
This commit is contained in:
Robin Jones 2023-06-08 19:16:48 +01:00
parent 7942c5209b
commit 48f4a1e662
4 changed files with 101 additions and 66 deletions

View File

@ -33,6 +33,17 @@ static char *get_file_type(FILINFO current_fileinfo) {
}
}
void menu_fileinfo_draw_n64_rom_info(surface_t *disp) {
// rom_header_t temp_header = file_read_rom_header(tmp_buffer);
// sprintf(buff, "ROM checksum: %llu\n", temp_header.checksum);
// sprintf(buff, "ROM title: %s\n", temp_header.title);
// sprintf(buff, "ROM media type: %c\n", temp_header.metadata.media_type);
// sprintf(buff, "ROM unique id: %.2s\n", (char*)&(temp_header.metadata.unique_identifier));
// sprintf(buff, "ROM dest market: %c\n", temp_header.metadata.destination_market);
// sprintf(buff, "ROM version: %hhu\n", temp_header.version);
}
void menu_fileinfo_draw_header(surface_t *disp) {
graphics_draw_text(disp, (disp->width / 2) - 64, vertical_start_position, "FILE INFORMATION"); // centre = numchars * font_horizontal_pixels / 2
@ -86,6 +97,8 @@ void menu_fileinfo(FILINFO current_fileinfo) {
graphics_draw_text(disp, horizontal_start_position, vertical_position, "Type:");
graphics_draw_text(disp, horizontal_indent, vertical_position += font_vertical_pixels, get_file_type(current_fileinfo));
//menu_fileinfo_draw_n64_rom_info(disp);
menu_fileinfo_draw_footer(disp);
display_show(disp);

View File

@ -22,6 +22,40 @@ static int items_in_dir = 1;
static FILINFO current_fileinfo;
void load_n64_rom() {
console_clear();
char tmp_buffer[280];
sprintf(tmp_buffer, "sd:/%s", current_fileinfo.fname);
rom_header_t temp_header = file_read_rom_header(tmp_buffer);
printf("ROM title: %s\n\n", temp_header.title);
printf("ROM media type: %c\n", temp_header.metadata.media_type);
printf("ROM unique id: %.2s\n", (char*)&(temp_header.metadata.unique_identifier));
printf("uid as int: %d\n\n", temp_header.metadata.unique_identifier);
printf("ROM destination market: %c\n\n", temp_header.metadata.destination_market);
printf("ROM version: %hhu\n", temp_header.version);
printf("ROM checksum: %llu\n\n", temp_header.checksum);
uint8_t save_type = rom_db_match_save_type(temp_header);
printf("save type: %d\n", save_type);
sprintf(tmp_buffer, "%s.%llu.sav", current_fileinfo.fname, temp_header.checksum);
wait_ms(5000); // wait used for debugging. Can be removed later.
assertf(flashcart_load_save(tmp_buffer, (flashcart_save_type_t)save_type, true) == FLASHCART_OK, "ROM load save error");
assertf(flashcart_load_rom(current_fileinfo.fname) == FLASHCART_OK, "ROM load error");
}
// FIXME: use newlib rather than fatfs to do this!
FRESULT scan_file_path (char *path) {
@ -158,27 +192,8 @@ void menu_main_init (settings_t *settings) {
if (str_endswith(current_fileinfo.fname, ".z64") || str_endswith(current_fileinfo.fname, ".n64") || str_endswith(current_fileinfo.fname, ".v64") || str_endswith(current_fileinfo.fname, ".rom")) {
printf("Loading N64 ROM type...\n");
printf("%s\n", current_fileinfo.fname);
char tmp_buffer[280];
sprintf(tmp_buffer, "sd:/%s", current_fileinfo.fname);
rom_header_t temp_header = file_read_rom_header(tmp_buffer);
printf("ROM checksum: %llu\n", temp_header.checksum);
printf("ROM title: %s\n", temp_header.title);
printf("ROM media type: %c\n", temp_header.metadata.media_type);
printf("ROM unique id: %.2s\n", (char*)&(temp_header.metadata.unique_identifier));
printf("ROM dest market: %c\n", temp_header.metadata.destination_market);
printf("ROM version: %hhu\n", temp_header.version);
printf("uid as int: %d\n", temp_header.metadata.unique_identifier);
uint8_t save_type = rom_db_match_save_type(temp_header);
printf("save type: %d\n", save_type);
sprintf(tmp_buffer, "%s.%llu.sav", current_fileinfo.fname, temp_header.checksum);
wait_ms(5000); // wait used for debugging. Can be removed later.
assertf(flashcart_load_save(tmp_buffer, (flashcart_save_type_t)save_type, true) == FLASHCART_OK, "ROM load save error");
assertf(flashcart_load_rom(current_fileinfo.fname) == FLASHCART_OK, "ROM load error");
load_n64_rom();
break; //required!
}
@ -210,6 +225,10 @@ void menu_main_init (settings_t *settings) {
menu_fileinfo(current_fileinfo);
menu_main_refresh(current_dir, disp);
}
if (joypad.c[0].L) {
//load the new File list GUI
//menu_file_scroll(current_fileinfo);
}
}
// TODO: write menu state to SD card

View File

@ -13,37 +13,31 @@
void settings_load_from_file(settings_t *settings) {
FILE *fp = NULL;
char error_buffer[256];
printf("Loading settings file %s\n", SC64_SETTINGS_FILEPATH);
wait_ms(1000);
fp = fopen(SC64_SETTINGS_FILEPATH, "r");
FILE *fp = fopen(SC64_SETTINGS_FILEPATH, "r");
if (!fp) {
printf("Error loading config file %s\n", SC64_SETTINGS_FILEPATH);
// generate a default config file.
printf("Creating a new one!");
// Generate a default config file.
printf("Creating a new one!\n");
wait_ms(10000);
//assertf(!fp, "Couldn't open toml config file: %s", SC64_SETTINGS_FILEPATH);
settings_save_default_state();
settings_load_default_state(settings);
return;
}
char error_buffer[256];
toml_table_t *conf = toml_parse_file(fp, error_buffer, sizeof(error_buffer));
fclose(fp);
if (!conf) {
printf("Error parsing config: %s\n", error_buffer);
wait_ms(10000);
printf("Attempt a repair!");
printf("Attempt a repair!\n");
settings_validate();
printf("Creating a new one!");
settings_save_default_state();
printf("Creating a new one!\n");
settings_load_default_state(settings);
//assertf(!conf, "Couldn't parse toml config: %s", error_buffer); // TODO: work out why and handle appropriately.
return;
}
//fclose(fp);
assertf(!fclose(fp), "Couldn't close toml config file"); // TODO: work out why and handle appropriately.
fp = NULL;
// Handle last_rom
toml_table_t *last_rom = toml_table_in(conf, "last_rom");
if (!last_rom) {
@ -131,18 +125,26 @@ void settings_load_from_file (settings_t *settings) {
}
void settings_save(void) {
// TODO: if there is a failure, validate or write the default state.
FILE *fp = NULL;
printf("Saving settings file %s\n", SC64_SETTINGS_FILEPATH);
wait_ms(1000);
fp = fopen(SC64_SETTINGS_FILEPATH, "w");
void settings_save(const char* filename, const settings_t* settings) {
// FILE* fp = fopen(filename, "wb");
// if (!fp) {
// perror("Failed to open file for writing");
// return 1;
// }
// TODO: convert and save the state to TOML
fclose(fp);
assertf(!fclose(fp), "Couldn't close toml settings file"); // TODO: work out why and handle appropriately.
fp = NULL;
// // Populate settings data...
// if (result != 0) {
// fprintf(stderr, "Failed to write TOML data to file\n");
// }
// fclose(fp);
// return result;
return;
}
void settings_load_default_state(settings_t *settings) {
@ -162,15 +164,17 @@ void settings_load_default_state(settings_t *settings) {
settings->boot_params.reset_type = BOOT_RESET_TYPE_NMI;
settings->boot_params.detect_tv_type = true;
settings->boot_params.detect_cic_seed = true;
// Initialize other default settings...
//#endif
}
void settings_save_default_state(void) {
void settings_reset(void) {
}
void settings_validate(void) {
// Validate settings against a file schema...
// TODO: should validate against a file schema.
// Must take into account that the settings will change in future, so should be backwards compatible.
}

View File

@ -34,10 +34,9 @@ typedef struct {
} settings_t;
void settings_load_from_file (settings_t *settings);
void settings_save (void);
void settings_save(const char* filename, const settings_t* settings);
void settings_reset (void);
void settings_load_default_state(settings_t *settings);
void settings_save_default_state(void);
void settings_validate (void);
#endif