[GTK3] Save selected model family

This commit is contained in:
Maximilian Mader 2020-05-12 21:51:55 +02:00
parent 2887110e99
commit bdb22e7034
Signed by: Max
GPG Key ID: F71D56A3151C4FB3
3 changed files with 74 additions and 33 deletions

View File

@ -574,26 +574,12 @@ static gboolean init_audio(void) {
return gui_data.audio_initialized = true; 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) { if (gui_data.cli_options.model != -1) {
return gui_data.cli_options.model; return gui_data.cli_options.model;
} }
GAction *action = g_action_map_lookup_action(G_ACTION_MAP(gui_data.main_application), "change_model"); return get_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();
} }
static void gb_audio_callback(GB_gameboy_t *gb, GB_sample_t *sample) { 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) { static void init(void) {
if (GB_is_inited(&gb)) return; 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_vblank_callback(&gb, vblank);
GB_set_pixels_output(&gb, get_current_buffer()); GB_set_pixels_output(&gb, get_current_buffer());
@ -1481,8 +1467,8 @@ static void init(void) {
} }
static void reset(void) { static void reset(void) {
g_debug("Reset: %d == %d", get_model(), gui_data.prev_model); g_debug("Reset: %d == %d", get_model_type(), gui_data.prev_model);
GB_model_t current_model = get_model(); GB_model_t current_model = get_model_type();
if (gui_data.prev_model == -1 || gui_data.prev_model == current_model) { if (gui_data.prev_model == -1 || gui_data.prev_model == current_model) {
GB_reset(&gb); GB_reset(&gb);
@ -1493,7 +1479,7 @@ static void reset(void) {
GB_set_palette(&gb, get_monochrome_palette()); 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 // 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) { 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; gui_data.cli_options.model = -1;
g_simple_action_set_state(action, value); g_simple_action_set_state(action, value);
g_free(config.emulation.model);
config.emulation.model = g_strdup(g_variant_get_string(value, NULL));
reset(); reset();
break; break;
default: 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) { 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) { G_MODULE_EXPORT void on_dmg_model_changed(GtkWidget *w, gpointer user_data_ptr) {

View File

@ -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); gtk_combo_box_set_active_id(builder_get(GTK_COMBO_BOX, "rumble_mode_selector"), config.controls.rumble_mode);
#if ! NDEBUG #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 #else
if (builder_get(GTK_COMBO_BOX, "menubar_override_selector") != NULL) { if (builder_get(GTK_COMBO_BOX, "menubar_override_selector") != NULL) {
gtk_widget_destroy(GTK_WIDGET(builder_get(GTK_COMBO_BOX, "menubar_override_selector"))); 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) { 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; 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; 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; 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; return MENUBAR_SHOW_HAMBURGER;
} }
// This should not happen // 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; default_value: return MENUBAR_AUTO;
} }
void set_show_menubar(enum menubar_type_t value) { void set_show_menubar(enum menubar_type_t value) {
switch (value) { switch (value) {
case MENUBAR_AUTO: case MENUBAR_AUTO:
config.video.menubar_override = "auto"; config.window.menubar_override = "auto";
break; break;
case MENUBAR_SHOW_IN_SHELL: case MENUBAR_SHOW_IN_SHELL:
config.video.menubar_override = "show_in_shell"; config.window.menubar_override = "show_in_shell";
break; break;
case MENUBAR_SHOW_IN_WINDOW: case MENUBAR_SHOW_IN_WINDOW:
config.video.menubar_override = "show_in_window"; config.window.menubar_override = "show_in_window";
break; break;
case MENUBAR_SHOW_HAMBURGER: case MENUBAR_SHOW_HAMBURGER:
config.video.menubar_override = "show_hamburger"; config.window.menubar_override = "show_hamburger";
break; 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) { GB_model_t get_dmg_model(void) {
if (config.emulation.dmg_revision_name == NULL) goto default_value; if (config.emulation.dmg_revision_name == NULL) goto default_value;

View File

@ -33,6 +33,7 @@
EXPAND_GROUP_MEMBER(dmg_revision_name, string, "DMG_CPU_C") \ EXPAND_GROUP_MEMBER(dmg_revision_name, string, "DMG_CPU_C") \
EXPAND_GROUP_MEMBER(sgb_revision_name, string, "SGB2") \ EXPAND_GROUP_MEMBER(sgb_revision_name, string, "SGB2") \
EXPAND_GROUP_MEMBER(cgb_revision_name, string, "CPU_CGB_E") \ EXPAND_GROUP_MEMBER(cgb_revision_name, string, "CPU_CGB_E") \
EXPAND_GROUP_MEMBER(model, string, "cgb") \
) \ ) \
EXPAND_GROUP(video, \ EXPAND_GROUP(video, \
EXPAND_GROUP_MEMBER(shader, string, "NearestNeighbor") \ EXPAND_GROUP_MEMBER(shader, string, "NearestNeighbor") \
@ -42,7 +43,6 @@
EXPAND_GROUP_MEMBER(monochrome_palette_id, string, "greyscale") \ EXPAND_GROUP_MEMBER(monochrome_palette_id, string, "greyscale") \
EXPAND_GROUP_MEMBER(keep_aspect_ratio, boolean, true) \ EXPAND_GROUP_MEMBER(keep_aspect_ratio, boolean, true) \
EXPAND_GROUP_MEMBER(use_integer_scaling, boolean, true) \ EXPAND_GROUP_MEMBER(use_integer_scaling, boolean, true) \
EXPAND_GROUP_MEMBER(menubar_override, string, "auto") \
) \ ) \
EXPAND_GROUP(audio, \ EXPAND_GROUP(audio, \
EXPAND_GROUP_MEMBER(high_pass_filter_id, string, "emulate_hardware") \ EXPAND_GROUP_MEMBER(high_pass_filter_id, string, "emulate_hardware") \
@ -51,6 +51,9 @@
EXPAND_GROUP(controls, \ EXPAND_GROUP(controls, \
EXPAND_GROUP_MEMBER(analog_speed_controls, boolean, false) \ EXPAND_GROUP_MEMBER(analog_speed_controls, boolean, false) \
EXPAND_GROUP_MEMBER(rumble_mode, string, "Never") \ EXPAND_GROUP_MEMBER(rumble_mode, string, "Never") \
) \
EXPAND_GROUP(window, \
EXPAND_GROUP_MEMBER(menubar_override, string, "auto") \
) )
typedef struct config_t { 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); const GB_rumble_mode_t get_rumble_mode(void);
void set_rumble_mode(const GB_rumble_mode_t); 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_dmg_model(void);
GB_model_t get_sgb_model(void); GB_model_t get_sgb_model(void);
GB_model_t get_cgb_model(void); GB_model_t get_cgb_model(void);