Added model selection GUI in the SDL port. Closes #24

This commit is contained in:
Lior Halphon 2018-01-13 13:49:20 +02:00
parent 69a712b07f
commit 5c16d0e656
3 changed files with 66 additions and 47 deletions

View File

@ -60,7 +60,8 @@ configuration_t configuration =
.color_correction_mode = GB_COLOR_CORRECTION_EMULATE_HARDWARE, .color_correction_mode = GB_COLOR_CORRECTION_EMULATE_HARDWARE,
.highpass_mode = GB_HIGHPASS_ACCURATE, .highpass_mode = GB_HIGHPASS_ACCURATE,
.scaling_mode = GB_SDL_SCALING_INTEGER_FACTOR, .scaling_mode = GB_SDL_SCALING_INTEGER_FACTOR,
.blend_frames = true .blend_frames = true,
.model = MODEL_CGB
}; };
@ -72,7 +73,6 @@ static const char *help[] ={
" Open Menu: Escape\n" " Open Menu: Escape\n"
" Reset: " MODIFIER_NAME "+R\n" " Reset: " MODIFIER_NAME "+R\n"
" Pause: " MODIFIER_NAME "+P\n" " Pause: " MODIFIER_NAME "+P\n"
" Toggle DMG/CGB: " MODIFIER_NAME "+T\n"
" Save state: " MODIFIER_NAME "+(0-9)\n" " Save state: " MODIFIER_NAME "+(0-9)\n"
" Load state: " MODIFIER_NAME "+" SHIFT_STRING "+(0-9)\n" " Load state: " MODIFIER_NAME "+" SHIFT_STRING "+(0-9)\n"
#ifdef __APPLE__ #ifdef __APPLE__
@ -225,6 +225,7 @@ static void item_help(unsigned index)
gui_state = SHOWING_HELP; gui_state = SHOWING_HELP;
} }
static void enter_emulation_menu(unsigned index);
static void enter_graphics_menu(unsigned index); static void enter_graphics_menu(unsigned index);
static void enter_controls_menu(unsigned index); static void enter_controls_menu(unsigned index);
static void enter_joypad_menu(unsigned index); static void enter_joypad_menu(unsigned index);
@ -232,6 +233,7 @@ static void enter_audio_menu(unsigned index);
static const struct menu_item paused_menu[] = { static const struct menu_item paused_menu[] = {
{"Resume", NULL}, {"Resume", NULL},
{"Enumlation Options", enter_emulation_menu},
{"Graphic Options", enter_graphics_menu}, {"Graphic Options", enter_graphics_menu},
{"Audio Options", enter_audio_menu}, {"Audio Options", enter_audio_menu},
{"Keyboard", enter_controls_menu}, {"Keyboard", enter_controls_menu},
@ -243,6 +245,49 @@ static const struct menu_item paused_menu[] = {
static const struct menu_item *const nonpaused_menu = &paused_menu[1]; static const struct menu_item *const nonpaused_menu = &paused_menu[1];
static void return_to_root_menu(unsigned index)
{
current_menu = root_menu;
current_selection = 0;
}
static void cycle_model(unsigned index)
{
configuration.model++;
if (configuration.model == MODEL_MAX) {
configuration.model = 0;
}
pending_command = GB_SDL_RESET_COMMAND;
}
static void cycle_model_backwards(unsigned index)
{
if (configuration.model == 0) {
configuration.model = MODEL_MAX;
}
configuration.model--;
pending_command = GB_SDL_RESET_COMMAND;
}
const char *current_model_string(unsigned index)
{
return (const char *[]){"Game Boy", "Game Boy Color", "Game Boy Advance"}
[configuration.model];
}
static const struct menu_item emulation_menu[] = {
{"Emulated Model:", cycle_model, current_model_string, cycle_model_backwards},
{"Back", return_to_root_menu},
{NULL,}
};
static void enter_emulation_menu(unsigned index)
{
current_menu = emulation_menu;
current_selection = 0;
}
const char *current_scaling_mode(unsigned index) const char *current_scaling_mode(unsigned index)
{ {
return (const char *[]){"Fill Entire Window", "Retain Aspect Ratio", "Retain Integer Factor"} return (const char *[]){"Fill Entire Window", "Retain Aspect Ratio", "Retain Integer Factor"}
@ -374,12 +419,6 @@ const char *current_filter_name(unsigned index)
return shaders[i].display_name; return shaders[i].display_name;
} }
static void return_to_root_menu(unsigned index)
{
current_menu = root_menu;
current_selection = 0;
}
static void toggle_blend_frames(unsigned index) static void toggle_blend_frames(unsigned index)
{ {
configuration.blend_frames ^= true; configuration.blend_frames ^= true;
@ -808,9 +847,12 @@ void run_gui(bool is_running)
current_selection--; current_selection--;
should_render = true; should_render = true;
} }
else if (event.key.keysym.scancode == SDL_SCANCODE_RETURN) { else if (event.key.keysym.scancode == SDL_SCANCODE_RETURN && !current_menu[current_selection].backwards_handler) {
if (current_menu[current_selection].handler) { if (current_menu[current_selection].handler) {
current_menu[current_selection].handler(current_selection); current_menu[current_selection].handler(current_selection);
if (pending_command == GB_SDL_RESET_COMMAND && !is_running) {
pending_command = GB_SDL_NO_COMMAND;
}
if (pending_command) { if (pending_command) {
if (!is_running && pending_command == GB_SDL_QUIT_COMMAND) { if (!is_running && pending_command == GB_SDL_QUIT_COMMAND) {
exit(0); exit(0);

View File

@ -25,7 +25,6 @@ enum pending_command {
GB_SDL_LOAD_STATE_COMMAND, GB_SDL_LOAD_STATE_COMMAND,
GB_SDL_RESET_COMMAND, GB_SDL_RESET_COMMAND,
GB_SDL_NEW_FILE_COMMAND, GB_SDL_NEW_FILE_COMMAND,
GB_SDL_TOGGLE_MODEL_COMMAND,
GB_SDL_QUIT_COMMAND, GB_SDL_QUIT_COMMAND,
}; };
@ -44,6 +43,12 @@ typedef struct {
bool swap_joysticks_bits_1_and_2; bool swap_joysticks_bits_1_and_2;
char filter[32]; char filter[32];
enum {
MODEL_DMG,
MODEL_CGB,
MODEL_AGB,
MODEL_MAX,
} model;
} configuration_t; } configuration_t;
extern configuration_t configuration; extern configuration_t configuration;

View File

@ -14,7 +14,6 @@
#endif #endif
GB_gameboy_t gb; GB_gameboy_t gb;
static bool dmg = false;
static bool paused = false; static bool paused = false;
static uint32_t pixel_buffer_1[160*144], pixel_buffer_2[160*144]; static uint32_t pixel_buffer_1[160*144], pixel_buffer_2[160*144];
static uint32_t *active_pixel_buffer = pixel_buffer_1, *previous_pixel_buffer = pixel_buffer_2; static uint32_t *active_pixel_buffer = pixel_buffer_1, *previous_pixel_buffer = pixel_buffer_2;
@ -185,12 +184,6 @@ static void handle_events(GB_gameboy_t *gb)
} }
break; break;
case SDL_SCANCODE_T:
if (event.key.keysym.mod & MODIFIER) {
pending_command = GB_SDL_TOGGLE_MODEL_COMMAND;
}
break;
case SDL_SCANCODE_P: case SDL_SCANCODE_P:
if (event.key.keysym.mod & MODIFIER) { if (event.key.keysym.mod & MODIFIER) {
paused = !paused; paused = !paused;
@ -308,8 +301,7 @@ static bool handle_pending_command(void)
} }
case GB_SDL_RESET_COMMAND: case GB_SDL_RESET_COMMAND:
GB_reset(&gb); return true;
return false;
case GB_SDL_NO_COMMAND: case GB_SDL_NO_COMMAND:
return false; return false;
@ -317,10 +309,6 @@ static bool handle_pending_command(void)
case GB_SDL_NEW_FILE_COMMAND: case GB_SDL_NEW_FILE_COMMAND:
return true; return true;
case GB_SDL_TOGGLE_MODEL_COMMAND:
dmg = !dmg;
return true;
case GB_SDL_QUIT_COMMAND: case GB_SDL_QUIT_COMMAND:
GB_save_battery(&gb, battery_save_path_ptr); GB_save_battery(&gb, battery_save_path_ptr);
exit(0); exit(0);
@ -333,10 +321,10 @@ static void run(void)
pending_command = GB_SDL_NO_COMMAND; pending_command = GB_SDL_NO_COMMAND;
restart: restart:
if (GB_is_inited(&gb)) { if (GB_is_inited(&gb)) {
GB_switch_model_and_reset(&gb, !dmg); GB_switch_model_and_reset(&gb, configuration.model != MODEL_DMG);
} }
else { else {
if (dmg) { if (configuration.model == MODEL_DMG) {
GB_init(&gb); GB_init(&gb);
} }
else { else {
@ -353,12 +341,8 @@ restart:
bool error = false; bool error = false;
start_capturing_logs(); start_capturing_logs();
if (dmg) { const char * const boot_roms[] = {"dmg_boot.bin", "cgb_boot.bin", "agb_boot.bin"};
error = GB_load_boot_rom(&gb, executable_relative_path("dmg_boot.bin")); error = GB_load_boot_rom(&gb, executable_relative_path(boot_roms[configuration.model]));
}
else {
error = GB_load_boot_rom(&gb, executable_relative_path("cgb_boot.bin"));
}
end_capturing_logs(true, error); end_capturing_logs(true, error);
start_capturing_logs(); start_capturing_logs();
@ -416,25 +400,13 @@ int main(int argc, char **argv)
#define xstr(x) str(x) #define xstr(x) str(x)
fprintf(stderr, "SameBoy v" xstr(VERSION) "\n"); fprintf(stderr, "SameBoy v" xstr(VERSION) "\n");
if (argc > 3) { if (argc > 2) {
usage: fprintf(stderr, "Usage: %s [rom]\n", argv[0]);
fprintf(stderr, "Usage: %s [--dmg] [rom]\n", argv[0]);
exit(1); exit(1);
} }
for (unsigned i = 1; i < argc; i++) { if (argc == 2) {
if (strcmp(argv[i], "--dmg") == 0) { filename = argv[2];
if (dmg) {
goto usage;
}
dmg = true;
}
else if (!filename) {
filename = argv[i];
}
else {
goto usage;
}
} }
signal(SIGINT, debugger_interrupt); signal(SIGINT, debugger_interrupt);