mirror of
https://github.com/Polprzewodnikowy/N64FlashcartMenu.git
synced 2024-11-28 05:24:15 +01:00
Switch to graphics for main menu
This commit is contained in:
parent
48f4a1e662
commit
39ac475bc1
@ -25,12 +25,16 @@ static FILINFO current_fileinfo;
|
|||||||
|
|
||||||
void load_n64_rom() {
|
void load_n64_rom() {
|
||||||
|
|
||||||
|
console_init();
|
||||||
console_clear();
|
console_clear();
|
||||||
|
|
||||||
char tmp_buffer[280];
|
char sd_path_buffer[1024];
|
||||||
sprintf(tmp_buffer, "sd:/%s", current_fileinfo.fname);
|
sprintf(sd_path_buffer, "sd:/%s", current_fileinfo.fname);
|
||||||
|
|
||||||
rom_header_t temp_header = file_read_rom_header(tmp_buffer);
|
rom_header_t temp_header = file_read_rom_header(sd_path_buffer);
|
||||||
|
|
||||||
|
printf("Loading N64 ROM type...\n");
|
||||||
|
printf("%s\n\n", current_fileinfo.fname);
|
||||||
|
|
||||||
printf("ROM title: %s\n\n", temp_header.title);
|
printf("ROM title: %s\n\n", temp_header.title);
|
||||||
|
|
||||||
@ -47,22 +51,24 @@ void load_n64_rom() {
|
|||||||
uint8_t save_type = rom_db_match_save_type(temp_header);
|
uint8_t save_type = rom_db_match_save_type(temp_header);
|
||||||
|
|
||||||
printf("save type: %d\n", save_type);
|
printf("save type: %d\n", save_type);
|
||||||
sprintf(tmp_buffer, "%s.%llu.sav", current_fileinfo.fname, temp_header.checksum);
|
sprintf(sd_path_buffer, "%s.%llu.sav", current_fileinfo.fname, temp_header.checksum);
|
||||||
wait_ms(5000); // wait used for debugging. Can be removed later.
|
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_save(sd_path_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");
|
assertf(flashcart_load_rom(current_fileinfo.fname) == FLASHCART_OK, "ROM load error");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: use newlib rather than fatfs to do this!
|
// FIXME: use newlib rather than fatfs to do this!
|
||||||
FRESULT scan_file_path (char *path) {
|
FRESULT scan_file_path (surface_t *disp, char *path) {
|
||||||
|
|
||||||
FRESULT res;
|
FRESULT res;
|
||||||
DIR dir;
|
DIR dir;
|
||||||
char sfno[280];
|
char sfno[1024];
|
||||||
int counter = 0; //FIXME: we dont account for an empty dir or only one valid file!
|
int counter = 0; //FIXME: we dont account for an empty dir or only one valid file!
|
||||||
|
int16_t vertical_position = 56;
|
||||||
|
char str_buffer[1036];
|
||||||
|
|
||||||
res = f_opendir(&dir, path);
|
res = f_opendir(&dir, path);
|
||||||
|
|
||||||
@ -81,20 +87,22 @@ FRESULT scan_file_path (char *path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
counter ++;
|
counter ++;
|
||||||
|
|
||||||
// TODO: convert these to icons...
|
// TODO: convert these to icons...
|
||||||
sprintf(sfno, "| %c%c%c | %10d | %s",
|
sprintf(sfno, "| %c%c%c | %10d | %s",
|
||||||
((file_info.fattrib & AM_DIR) ? 'D' : '-'),
|
((file_info.fattrib & AM_DIR) ? 'D' : '-'),
|
||||||
((file_info.fattrib & AM_RDO) ? 'R' : '-'),
|
((file_info.fattrib & AM_RDO) ? 'R' : '-'),
|
||||||
((file_info.fattrib & AM_HID) ? 'H' : '-'),
|
((file_info.fattrib & AM_HID) ? 'H' : '-'),
|
||||||
(int)file_info.fsize, file_info.fname);
|
(int)file_info.fsize, file_info.fname);
|
||||||
|
|
||||||
if (scroll_menu_position == counter) {
|
if (scroll_menu_position == counter) {
|
||||||
printf("-> %s\n", sfno);
|
sprintf(str_buffer, "-> %s\n", sfno);
|
||||||
|
graphics_draw_text(disp, horizontal_indent, vertical_position += font_vertical_pixels, str_buffer);
|
||||||
current_fileinfo = file_info;
|
current_fileinfo = file_info;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
printf(" %s\n", sfno);
|
sprintf(str_buffer, " %s\n", sfno);
|
||||||
|
graphics_draw_text(disp, horizontal_indent, vertical_position += font_vertical_pixels, str_buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -105,62 +113,66 @@ FRESULT scan_file_path (char *path) {
|
|||||||
|
|
||||||
void menu_main_draw_header(surface_t *disp) {
|
void menu_main_draw_header(surface_t *disp) {
|
||||||
|
|
||||||
printf(" FILE MENU\n\n\n\n");
|
graphics_draw_text(disp, (disp->width / 2) - 36, vertical_start_position, "FILE MENU"); // centre = numchars * font_horizontal_pixels / 2
|
||||||
|
graphics_draw_line(disp,0,30,disp->width,30, 0xff);
|
||||||
// graphics_draw_text(disp, (disp->width / 2) - 36, vertical_start_position, "FILE MENU"); // centre = numchars * font_horizontal_pixels / 2
|
|
||||||
// graphics_draw_line(disp,0,30,disp->width,30, 0xff);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void menu_main_draw_footer(char *dir_path, surface_t *disp) {
|
void menu_main_draw_footer(char *dir_path, surface_t *disp) {
|
||||||
|
|
||||||
// graphics_draw_line(disp,0,disp->height - overscan_vertical_pixels - font_vertical_pixels,disp->width,disp->height - overscan_vertical_pixels - font_vertical_pixels, 0xff);
|
graphics_draw_line(disp,0,disp->height - overscan_vertical_pixels - font_vertical_pixels,disp->width,disp->height - overscan_vertical_pixels - font_vertical_pixels, 0xff);
|
||||||
|
|
||||||
printf("\n\nCurrent Directory: %s\n", dir_path);
|
char str_buffer[1024];
|
||||||
printf(" File: %d of %d\n\n", scroll_menu_position, items_in_dir);
|
sprintf(str_buffer, "Current Directory: SD:%s\nFile: %d of %d\n\n", dir_path, scroll_menu_position, items_in_dir);
|
||||||
|
|
||||||
|
graphics_draw_text(disp, (disp->width / 2) - 160,disp->height - overscan_vertical_pixels, str_buffer); // centre = numchars * font_horizontal_pixels / 2
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void menu_main_refresh (char *dir_path, surface_t *disp) {
|
void menu_main_refresh (char *dir_path) {
|
||||||
|
|
||||||
console_clear();
|
surface_t *disp = display_get();
|
||||||
|
graphics_fill_screen(disp, 0);
|
||||||
|
|
||||||
menu_main_draw_header(disp);
|
menu_main_draw_header(disp);
|
||||||
|
|
||||||
printf(" | DRH | FILE SIZE | FILE NAME\n");
|
int16_t vertical_position = 40;
|
||||||
printf(" |-----|------------|----------\n");
|
|
||||||
|
char str_buffer[1024];
|
||||||
|
sprintf(str_buffer, " | DRH | FILE SIZE | FILE NAME\n");
|
||||||
|
graphics_draw_text(disp, horizontal_indent, vertical_position += font_vertical_pixels, str_buffer);
|
||||||
|
sprintf(str_buffer, " |-----|------------|----------\n");
|
||||||
|
graphics_draw_text(disp, horizontal_indent, vertical_position += font_vertical_pixels, str_buffer);
|
||||||
|
|
||||||
scan_file_path(dir_path);
|
scan_file_path(disp, dir_path);
|
||||||
|
|
||||||
menu_main_draw_footer(dir_path, disp);
|
menu_main_draw_footer(dir_path, disp);
|
||||||
|
|
||||||
|
display_show(disp);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void menu_main_init (settings_t *settings) {
|
void menu_main_init (settings_t *settings) {
|
||||||
// TODO: implement nice user interface here
|
|
||||||
surface_t *disp = display_try_get();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
console_init();
|
|
||||||
console_set_debug(true);
|
|
||||||
console_clear();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
char *current_dir = settings->last_state.current_directory;
|
char *current_dir = settings->last_state.current_directory;
|
||||||
char *last_dir = current_dir;
|
char *last_dir = current_dir;
|
||||||
struct controller_data joypad = get_keys_down();
|
struct controller_data joypad = get_keys_down();
|
||||||
|
|
||||||
if ((settings->last_state.auto_load_last_rom) && !(joypad.c[0].B)) { // FIXME: the B button on any controller!
|
if ((settings->last_state.auto_load_last_rom) && !(joypad.c[0].B)) { // FIXME: the B button on any controller!
|
||||||
printf("Loading last ROM: %s\n", settings->last_rom.rom_path);
|
|
||||||
assertf(flashcart_load_rom(settings->last_rom.rom_path) == FLASHCART_OK, "ROM load error");
|
|
||||||
|
|
||||||
printf("Loading save: %s, type: %d, writeback: %d\n", settings->last_rom.save_path, settings->last_rom.save_type, settings->last_rom.save_writeback);
|
console_init();
|
||||||
assertf(flashcart_load_save(settings->last_rom.save_path, settings->last_rom.save_type, settings->last_rom.save_writeback) == FLASHCART_OK, "Save load error");
|
console_clear();
|
||||||
|
|
||||||
|
printf("Loading last ROM: %s\n", settings->last_rom.rom_path);
|
||||||
|
assertf(flashcart_load_rom(settings->last_rom.rom_path) == FLASHCART_OK, "ROM load error");
|
||||||
|
|
||||||
|
printf("Loading save: %s, type: %d, writeback: %d\n", settings->last_rom.save_path, settings->last_rom.save_type, settings->last_rom.save_writeback);
|
||||||
|
assertf(flashcart_load_save(settings->last_rom.save_path, settings->last_rom.save_type, settings->last_rom.save_writeback) == FLASHCART_OK, "Save load error");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
settings->last_state.auto_load_last_rom = false;
|
settings->last_state.auto_load_last_rom = false;
|
||||||
menu_main_refresh(current_dir, disp);
|
menu_main_refresh(current_dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@ -174,7 +186,7 @@ void menu_main_init (settings_t *settings) {
|
|||||||
else {
|
else {
|
||||||
scroll_menu_position = items_in_dir;
|
scroll_menu_position = items_in_dir;
|
||||||
}
|
}
|
||||||
menu_main_refresh(current_dir, disp);
|
menu_main_refresh(current_dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (joypad.c[0].down) {
|
if (joypad.c[0].down) {
|
||||||
@ -184,14 +196,12 @@ void menu_main_init (settings_t *settings) {
|
|||||||
else {
|
else {
|
||||||
scroll_menu_position = 1;
|
scroll_menu_position = 1;
|
||||||
}
|
}
|
||||||
menu_main_refresh(current_dir, disp);
|
menu_main_refresh(current_dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (joypad.c[0].A) {
|
if (joypad.c[0].A) {
|
||||||
// TODO: move this to a function and check that the ROM is valid by checking the header...
|
// TODO: move this to a function and check that the ROM is valid by checking the header...
|
||||||
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")) {
|
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);
|
|
||||||
|
|
||||||
load_n64_rom();
|
load_n64_rom();
|
||||||
|
|
||||||
@ -204,31 +214,31 @@ void menu_main_init (settings_t *settings) {
|
|||||||
scroll_menu_position = 1;
|
scroll_menu_position = 1;
|
||||||
last_dir = current_dir;
|
last_dir = current_dir;
|
||||||
current_dir = current_fileinfo.fname;
|
current_dir = current_fileinfo.fname;
|
||||||
menu_main_refresh(current_dir, disp);
|
menu_main_refresh(current_dir);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
|
console_init();
|
||||||
|
console_clear();
|
||||||
|
|
||||||
printf("Failed... Returning to menu...\n");
|
printf("Failed... Returning to menu...\n");
|
||||||
wait_ms(1000);
|
wait_ms(1000);
|
||||||
menu_main_refresh(current_dir, disp);
|
menu_main_refresh(current_dir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (joypad.c[0].B) {
|
if (joypad.c[0].B) {
|
||||||
menu_main_refresh(last_dir, disp);
|
menu_main_refresh(current_dir);
|
||||||
current_dir = last_dir;
|
current_dir = last_dir;
|
||||||
}
|
}
|
||||||
if (joypad.c[0].start) { // FIXME: the START button on any controller!
|
if (joypad.c[0].start) { // FIXME: the START button on any controller!
|
||||||
menu_info();
|
menu_info();
|
||||||
menu_main_refresh(current_dir, disp);
|
menu_main_refresh(current_dir);
|
||||||
}
|
}
|
||||||
if (joypad.c[0].Z) {
|
if (joypad.c[0].Z) {
|
||||||
menu_fileinfo(current_fileinfo);
|
menu_fileinfo(current_fileinfo);
|
||||||
menu_main_refresh(current_dir, disp);
|
menu_main_refresh(current_dir);
|
||||||
}
|
}
|
||||||
if (joypad.c[0].L) {
|
|
||||||
//load the new File list GUI
|
|
||||||
//menu_file_scroll(current_fileinfo);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// TODO: write menu state to SD card
|
// TODO: write menu state to SD card
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user