|
|
|
@@ -280,7 +280,7 @@ int64_t time_sleep_until(int64_t t_target) { |
|
|
|
return t_diff * 1000; |
|
|
|
} |
|
|
|
|
|
|
|
static nese_Action select_rom(platform_data* plat, char* file, int sz_file); |
|
|
|
static nese_Action game_menu(platform_data* plat); |
|
|
|
|
|
|
|
int nese_frame_ready(void* plat_data) { |
|
|
|
platform_data* plat = (platform_data*)plat_data; |
|
|
|
@@ -320,6 +320,7 @@ int nese_frame_ready(void* plat_data) { |
|
|
|
nese_Action action = process_events(plat->sys); |
|
|
|
switch (action) { |
|
|
|
case Action_Quit: |
|
|
|
// TODO: Save SRAM |
|
|
|
status = -1; |
|
|
|
break; |
|
|
|
|
|
|
|
@@ -345,18 +346,23 @@ int nese_frame_ready(void* plat_data) { |
|
|
|
break; |
|
|
|
|
|
|
|
case Action_Menu: |
|
|
|
action = select_rom(plat, plat->filename, PLAT_FILENAME_SIZE); |
|
|
|
if (Action_OK == action) { |
|
|
|
action = game_menu(plat); |
|
|
|
if (Action_Reset == action) { |
|
|
|
nes_reset(plat->sys); |
|
|
|
} else if (Action_Save == action) { |
|
|
|
status = save_state(plat->sys, plat->cart.filename); |
|
|
|
} else if (Action_Load == action) { |
|
|
|
status = load_state(plat->sys, plat->cart.filename); |
|
|
|
} else if (Action_Quit == action || NULL == plat->sys->cart_header) { |
|
|
|
status = -1; |
|
|
|
} |
|
|
|
// TODO: Other Actions? |
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
} |
|
|
|
|
|
|
|
// TODO: Perform more actions |
|
|
|
// TODO: Perform more actions? |
|
|
|
|
|
|
|
if (0 == status) { |
|
|
|
plat->t_target += FRAME_TIME_NS; |
|
|
|
@@ -501,6 +507,8 @@ static nese_Action select_rom(platform_data* plat, char* file, int sz_file) { |
|
|
|
nese_Action action = Action_OK; |
|
|
|
Menu_State menu = {0}; |
|
|
|
|
|
|
|
// TODO: Save SRAM |
|
|
|
|
|
|
|
while (Action_OK == action || NULL == plat->sys->cart_header) { |
|
|
|
action = run_rom_menu(plat, &menu, file, sz_file); |
|
|
|
if (Action_OK == action) { |
|
|
|
@@ -522,6 +530,75 @@ static nese_Action select_rom(platform_data* plat, char* file, int sz_file) { |
|
|
|
return action; |
|
|
|
} |
|
|
|
|
|
|
|
static nese_Action run_game_menu(platform_data* plat, Menu_State* state) { |
|
|
|
static char* items[] = { |
|
|
|
"Resume", |
|
|
|
"Save", |
|
|
|
"Restore", |
|
|
|
"Reset", |
|
|
|
"Select ROM", |
|
|
|
"Exit", |
|
|
|
}; |
|
|
|
static const nese_Action choices[] = { |
|
|
|
Action_Cancel, |
|
|
|
Action_Save, |
|
|
|
Action_Load, |
|
|
|
Action_Reset, |
|
|
|
Action_Menu, |
|
|
|
Action_Quit, |
|
|
|
}; |
|
|
|
static const File_List options = { |
|
|
|
.files = items, |
|
|
|
.count = (sizeof(items) / sizeof(*items)), |
|
|
|
}; |
|
|
|
|
|
|
|
Menu_State menu = {0}; |
|
|
|
if (NULL != state) menu = *state; |
|
|
|
|
|
|
|
nese_Action action = run_menu(plat, &menu, &options, 100); |
|
|
|
if (Action_Menu == action) { |
|
|
|
action = Action_Cancel; |
|
|
|
} else if (Action_OK == action) { |
|
|
|
if ( menu.cursor >= 0 && |
|
|
|
menu.cursor < (sizeof(choices) / sizeof(*choices))) { |
|
|
|
action = choices[menu.cursor]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (NULL != state) *state = menu; |
|
|
|
|
|
|
|
return action; |
|
|
|
} |
|
|
|
|
|
|
|
static nese_Action game_menu(platform_data* plat) { |
|
|
|
nese_Action action = Action_OK; |
|
|
|
Menu_State menu = {0}; |
|
|
|
|
|
|
|
while (Action_OK == action) { |
|
|
|
action = run_game_menu(plat, &menu); |
|
|
|
|
|
|
|
if (Action_Menu == action) { |
|
|
|
// Select ROM |
|
|
|
action = select_rom(plat, plat->filename, PLAT_FILENAME_SIZE); |
|
|
|
if (Action_OK == action) { |
|
|
|
// New ROM selected - Exit loop and reset |
|
|
|
action = Action_Reset; |
|
|
|
|
|
|
|
} else if (Action_Cancel == action) { |
|
|
|
// No ROM selected - Keep the menu running |
|
|
|
action = Action_OK; |
|
|
|
} |
|
|
|
|
|
|
|
if (NULL == plat->sys->cart_header) { |
|
|
|
// A failed ROM load means we shouldn't return to the game menu |
|
|
|
action = Action_Quit; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return action; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* Platform Data */ |
|
|
|
|
|
|
|
|