From bdb22e70343438fdd9aa65be2c9a3a390f3dbd28 Mon Sep 17 00:00:00 2001 From: Maximilian Mader Date: Tue, 12 May 2020 21:51:55 +0200 Subject: [PATCH] [GTK3] Save selected model family --- gtk3/main.c | 32 ++++++++--------------- gtk3/settings.c | 67 +++++++++++++++++++++++++++++++++++++++++-------- gtk3/settings.h | 8 +++++- 3 files changed, 74 insertions(+), 33 deletions(-) diff --git a/gtk3/main.c b/gtk3/main.c index 4b6283a..e039a92 100644 --- a/gtk3/main.c +++ b/gtk3/main.c @@ -574,26 +574,12 @@ static gboolean init_audio(void) { return gui_data.audio_initialized = true; } -static GB_model_t get_model(void) { +static GB_model_t get_model_type(void) { if (gui_data.cli_options.model != -1) { return gui_data.cli_options.model; } - GAction *action = g_action_map_lookup_action(G_ACTION_MAP(gui_data.main_application), "change_model"); - GVariant *value = g_action_get_state(action); - const gchar *family = g_variant_get_string(value, NULL); - - if (g_strcmp0(family, "DMG") == 0) { - return get_dmg_model(); - } - else if (g_strcmp0(family, "AGB") == 0) { - return GB_MODEL_AGB; - } - else if (g_strcmp0(family, "SGB") == 0) { - return get_sgb_model(); - } - - return get_cgb_model(); + return get_model(); } static void gb_audio_callback(GB_gameboy_t *gb, GB_sample_t *sample) { @@ -1454,7 +1440,7 @@ static void load_boot_rom(GB_gameboy_t *gb, GB_boot_rom_t type) { static void init(void) { if (GB_is_inited(&gb)) return; - GB_init(&gb, get_model()); + GB_init(&gb, get_model_type()); GB_set_vblank_callback(&gb, vblank); GB_set_pixels_output(&gb, get_current_buffer()); @@ -1481,8 +1467,8 @@ static void init(void) { } static void reset(void) { - g_debug("Reset: %d == %d", get_model(), gui_data.prev_model); - GB_model_t current_model = get_model(); + g_debug("Reset: %d == %d", get_model_type(), gui_data.prev_model); + GB_model_t current_model = get_model_type(); if (gui_data.prev_model == -1 || gui_data.prev_model == current_model) { GB_reset(&gb); @@ -1493,7 +1479,7 @@ static void reset(void) { GB_set_palette(&gb, get_monochrome_palette()); - gui_data.prev_model = get_model(); + gui_data.prev_model = get_model_type(); // Check SGB -> non-SGB and non-SGB to SGB transitions if (GB_get_screen_width(&gb) != gui_data.last_screen_width || GB_get_screen_height(&gb) != gui_data.last_screen_height) { @@ -2494,6 +2480,10 @@ static void on_model_changed(GSimpleAction *action, GVariant *value, gpointer us gui_data.cli_options.model = -1; g_simple_action_set_state(action, value); + + g_free(config.emulation.model); + config.emulation.model = g_strdup(g_variant_get_string(value, NULL)); + reset(); break; default: @@ -2578,7 +2568,7 @@ G_MODULE_EXPORT void on_monochrome_palette_changed(GtkWidget *w, gpointer user_d } G_MODULE_EXPORT void on_color_menubar_override_changed(GtkWidget *w, gpointer user_data_ptr) { - config.video.menubar_override = (gchar *)gtk_combo_box_get_active_id(GTK_COMBO_BOX(w)); + config.window.menubar_override = (gchar *)gtk_combo_box_get_active_id(GTK_COMBO_BOX(w)); } G_MODULE_EXPORT void on_dmg_model_changed(GtkWidget *w, gpointer user_data_ptr) { diff --git a/gtk3/settings.c b/gtk3/settings.c index 68b3c12..9971472 100644 --- a/gtk3/settings.c +++ b/gtk3/settings.c @@ -134,7 +134,7 @@ void on_preferences_realize(GtkWidget *w, gpointer builder_ptr) { gtk_combo_box_set_active_id(builder_get(GTK_COMBO_BOX, "rumble_mode_selector"), config.controls.rumble_mode); #if ! NDEBUG - gtk_combo_box_set_active_id(builder_get(GTK_COMBO_BOX, "menubar_override_selector"), config.video.menubar_override); + gtk_combo_box_set_active_id(builder_get(GTK_COMBO_BOX, "menubar_override_selector"), config.window.menubar_override); #else if (builder_get(GTK_COMBO_BOX, "menubar_override_selector") != NULL) { gtk_widget_destroy(GTK_WIDGET(builder_get(GTK_COMBO_BOX, "menubar_override_selector"))); @@ -216,39 +216,39 @@ void update_boot_rom_selector(GtkBuilder *builder) { } enum menubar_type_t get_show_menubar(void) { - if (config.video.menubar_override == NULL) goto default_value; + if (config.window.menubar_override == NULL) goto default_value; - if (g_strcmp0(config.video.menubar_override, "auto") == 0) { + if (g_strcmp0(config.window.menubar_override, "auto") == 0) { return MENUBAR_AUTO; } - else if (g_strcmp0(config.video.menubar_override, "show_in_shell") == 0) { + else if (g_strcmp0(config.window.menubar_override, "show_in_shell") == 0) { return MENUBAR_SHOW_IN_SHELL; } - else if (g_strcmp0(config.video.menubar_override, "show_in_window") == 0) { + else if (g_strcmp0(config.window.menubar_override, "show_in_window") == 0) { return MENUBAR_SHOW_IN_WINDOW; } - else if (g_strcmp0(config.video.menubar_override, "show_hamburger") == 0) { + else if (g_strcmp0(config.window.menubar_override, "show_hamburger") == 0) { return MENUBAR_SHOW_HAMBURGER; } // This should not happen - g_warning("Unknown menubar setting: %s\nFalling back to “Auto”", config.video.menubar_override); + g_warning("Unknown menubar setting: %s\nFalling back to “Auto”", config.window.menubar_override); default_value: return MENUBAR_AUTO; } void set_show_menubar(enum menubar_type_t value) { switch (value) { case MENUBAR_AUTO: - config.video.menubar_override = "auto"; + config.window.menubar_override = "auto"; break; case MENUBAR_SHOW_IN_SHELL: - config.video.menubar_override = "show_in_shell"; + config.window.menubar_override = "show_in_shell"; break; case MENUBAR_SHOW_IN_WINDOW: - config.video.menubar_override = "show_in_window"; + config.window.menubar_override = "show_in_window"; break; case MENUBAR_SHOW_HAMBURGER: - config.video.menubar_override = "show_hamburger"; + config.window.menubar_override = "show_hamburger"; break; } } @@ -466,6 +466,51 @@ void set_rumble_mode(GB_rumble_mode_t mode) { } } +GB_model_t get_model(void) { + if (g_strcmp0(config.emulation.model, "DMG") == 0) { + return get_dmg_model(); + } + else if (g_strcmp0(config.emulation.model, "MGB") == 0) { + g_warning("Emulation of MGBs is unsupported, falling back to DMG."); + + return get_dmg_model(); + } + else if (g_strcmp0(config.emulation.model, "AGB") == 0) { + return GB_MODEL_AGB; + } + else if (g_strcmp0(config.emulation.model, "SGB") == 0) { + return get_sgb_model(); + } + + return get_cgb_model(); +} + +void set_model(GB_model_t model) { + switch (model & GB_MODEL_FAMILY_MASK) { + case GB_MODEL_DMG_FAMILY: + if (model & GB_MODEL_SGB) { + config.emulation.model = "SGB"; + } + else { + config.emulation.model = "DMG"; + } + break; + + case GB_MODEL_MGB_FAMILY: + config.emulation.model = "MGB"; + break; + + case GB_MODEL_CGB_FAMILY: + if (model & GB_MODEL_AGB) { + config.emulation.model = "AGB"; + } + else { + config.emulation.model = "CGB"; + } + break; + } +} + GB_model_t get_dmg_model(void) { if (config.emulation.dmg_revision_name == NULL) goto default_value; diff --git a/gtk3/settings.h b/gtk3/settings.h index 7f81057..59059a9 100644 --- a/gtk3/settings.h +++ b/gtk3/settings.h @@ -33,6 +33,7 @@ EXPAND_GROUP_MEMBER(dmg_revision_name, string, "DMG_CPU_C") \ EXPAND_GROUP_MEMBER(sgb_revision_name, string, "SGB2") \ EXPAND_GROUP_MEMBER(cgb_revision_name, string, "CPU_CGB_E") \ + EXPAND_GROUP_MEMBER(model, string, "cgb") \ ) \ EXPAND_GROUP(video, \ EXPAND_GROUP_MEMBER(shader, string, "NearestNeighbor") \ @@ -42,7 +43,6 @@ EXPAND_GROUP_MEMBER(monochrome_palette_id, string, "greyscale") \ EXPAND_GROUP_MEMBER(keep_aspect_ratio, boolean, true) \ EXPAND_GROUP_MEMBER(use_integer_scaling, boolean, true) \ - EXPAND_GROUP_MEMBER(menubar_override, string, "auto") \ ) \ EXPAND_GROUP(audio, \ EXPAND_GROUP_MEMBER(high_pass_filter_id, string, "emulate_hardware") \ @@ -51,6 +51,9 @@ EXPAND_GROUP(controls, \ EXPAND_GROUP_MEMBER(analog_speed_controls, boolean, false) \ EXPAND_GROUP_MEMBER(rumble_mode, string, "Never") \ + ) \ + EXPAND_GROUP(window, \ + EXPAND_GROUP_MEMBER(menubar_override, string, "auto") \ ) typedef struct config_t { @@ -109,6 +112,9 @@ void set_monochrome_palette(const GB_palette_t*); const GB_rumble_mode_t get_rumble_mode(void); void set_rumble_mode(const GB_rumble_mode_t); +void set_model(GB_model_t model); +GB_model_t get_model(void); + GB_model_t get_dmg_model(void); GB_model_t get_sgb_model(void); GB_model_t get_cgb_model(void);