- Preselect current ROM - Don't quit when canceling ROM selection - Rename Load to Restore since I keep selecting the wrong thingmaster
| @@ -45,9 +45,9 @@ SRC_SRCS_1 += nes.c ppu.c input.c | |||||
| SRC_SRCS_1 += cart.c mapper.c | SRC_SRCS_1 += cart.c mapper.c | ||||
| SRC_SRCS_1 += apu.c audio.c | SRC_SRCS_1 += apu.c audio.c | ||||
| SRC_SRCS_1 += file.c save.c | SRC_SRCS_1 += file.c save.c | ||||
| SRC_SRCS_1 += overlay.c menu.c | |||||
| SRC_SRCS_1 += sdl_render.c sdl_input.c sdl_audio.c sdl_timer.c | SRC_SRCS_1 += sdl_render.c sdl_input.c sdl_audio.c sdl_timer.c | ||||
| SRC_SRCS_1 += overlay.c sdl_overlay.c | |||||
| SRC_SRCS_1 += sdl_menu.c | |||||
| SRC_SRCS_1 += sdl_overlay.c | |||||
| PLAT_SRCS_1 = filemap.c | PLAT_SRCS_1 = filemap.c | ||||
| @@ -85,6 +85,13 @@ static void free_file_list(file_list* files) { | |||||
| free(files->files); | free(files->files); | ||||
| } | } | ||||
| static int find_file(file_list* files, const char* filename) { | |||||
| int i = (files->count - 1); | |||||
| for ( ; i >= 0 && | |||||
| (0 != strcmp(files->files[i], filename)); --i); | |||||
| return i; | |||||
| } | |||||
| static void fix_filename(char* dst, int n, const char* src) { | static void fix_filename(char* dst, int n, const char* src) { | ||||
| for ( int i = 0; | for ( int i = 0; | ||||
| i < n && *src && '.' != *src; | i < n && *src && '.' != *src; | ||||
| @@ -189,7 +196,8 @@ static int run_menu(menu_state* state, const file_list* files, | |||||
| char* run_main_menu(menu_state* state, nes_Renderer* rend, | char* run_main_menu(menu_state* state, nes_Renderer* rend, | ||||
| nes_Input_Reader* input, nes* sys) { | |||||
| nes_Input_Reader* input, nes* sys, | |||||
| const char* cur_filename) { | |||||
| char* cart_filename = NULL; | char* cart_filename = NULL; | ||||
| DIR* dir = opendir("rom"); | DIR* dir = opendir("rom"); | ||||
| @@ -209,6 +217,12 @@ char* run_main_menu(menu_state* state, nes_Renderer* rend, | |||||
| menu_state menu = {0}; | menu_state menu = {0}; | ||||
| if (NULL != state) menu = *state; | if (NULL != state) menu = *state; | ||||
| if (NULL != cur_filename) { | |||||
| // Add 4 to skip past "rom/" | |||||
| int current = find_file(&files, cur_filename + 4); | |||||
| if (current >= 0) menu.cursor = current; | |||||
| } | |||||
| int status = run_menu(&menu, &files, 20, | int status = run_menu(&menu, &files, 20, | ||||
| rend, input, sys); | rend, input, sys); | ||||
| @@ -239,7 +253,7 @@ int run_game_menu(menu_state* state, nes_Renderer* rend, | |||||
| static char* items[] = { | static char* items[] = { | ||||
| "Resume", | "Resume", | ||||
| "Save", | "Save", | ||||
| "Load", | |||||
| "Restore", | |||||
| "Reset", | "Reset", | ||||
| "Select ROM", | "Select ROM", | ||||
| "Exit", | "Exit", | ||||
| @@ -14,9 +14,10 @@ typedef struct { | |||||
| // Returns filename of selected ROM | // Returns filename of selected ROM | ||||
| char* run_main_menu(menu_state*, nes_Renderer*, | char* run_main_menu(menu_state*, nes_Renderer*, | ||||
| nes_Input_Reader*, nes*); | |||||
| nes_Input_Reader*, nes*, | |||||
| const char* cur_filename); | |||||
| // TODO: What does this return? | |||||
| // Returns nes_Input_Result indicating the choice | |||||
| int run_game_menu(menu_state*, nes_Renderer*, | int run_game_menu(menu_state*, nes_Renderer*, | ||||
| nes_Input_Reader*, nes*); | nes_Input_Reader*, nes*); | ||||
| @@ -139,14 +139,17 @@ static int select_rom(menu_state* menu, nes_Renderer* rend, | |||||
| } | } | ||||
| if (0 == status) { | if (0 == status) { | ||||
| cart.filename = run_main_menu(menu, rend, | |||||
| input, sys); | |||||
| cart.filename = run_main_menu( | |||||
| menu, rend, input, sys, cur_cart->filename | |||||
| ); | |||||
| if ( NULL == cart.filename || | |||||
| (char*)-1 == cart.filename ) { | |||||
| // This means that we dumped out of the loader | |||||
| cart.filename = NULL; | |||||
| status = -1; | |||||
| if ((char*)-1 == cart.filename) { | |||||
| // This means that we quit | |||||
| status = input_Result_Quit; | |||||
| } else if (NULL == cart.filename) { | |||||
| // This means we didn't press "cancel" | |||||
| status = input_Result_Cancel; | |||||
| } else { | } else { | ||||
| cart.file = nes_load_cart(&new_cart, | cart.file = nes_load_cart(&new_cart, | ||||
| @@ -184,6 +187,7 @@ static int do_game_menu(menu_state* state, nes_Renderer* rend, | |||||
| sys, cart); | sys, cart); | ||||
| if (input_Result_Cancel == status) { | if (input_Result_Cancel == status) { | ||||
| status = input_Result_OK; | |||||
| continue; | continue; | ||||
| } | } | ||||
| } | } | ||||
| @@ -229,8 +233,7 @@ int main(int argc, char* argv[]) { | |||||
| // If we didn't launch with a file, run the loader | // If we didn't launch with a file, run the loader | ||||
| if (0 == status && NULL == cart.file) { | if (0 == status && NULL == cart.file) { | ||||
| status = select_rom(NULL, rend, input, | |||||
| &sys, &cart); | |||||
| status = select_rom(NULL, rend, input, &sys, &cart); | |||||
| } | } | ||||
| if (status == 0) { | if (status == 0) { | ||||