2020-05-16 14:56:09 +00:00
|
|
|
#include "config.h"
|
2019-09-24 14:14:06 +00:00
|
|
|
|
2020-04-30 02:53:45 +00:00
|
|
|
#define get_object(id) gtk_builder_get_object(builder, id)
|
|
|
|
#define builder_get(type, id) type(get_object(id))
|
|
|
|
|
2020-05-16 14:56:09 +00:00
|
|
|
gchar* config_file_path;
|
2020-05-12 22:25:13 +00:00
|
|
|
GKeyFile *key_file;
|
|
|
|
|
2019-09-25 00:48:07 +00:00
|
|
|
static void print_config_error(GError *error) {
|
|
|
|
if (error == NULL) return;
|
2019-09-24 14:14:06 +00:00
|
|
|
|
2019-09-25 20:47:04 +00:00
|
|
|
if (!g_error_matches(error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND) && !g_error_matches(error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_GROUP_NOT_FOUND)) {
|
2020-04-10 02:07:01 +00:00
|
|
|
g_warning("Config error: %s", error->message);
|
2019-09-25 00:48:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-10 02:07:01 +00:00
|
|
|
void _print_config(config_t *config, GLogLevelFlags log_level) {
|
2020-05-12 18:55:29 +00:00
|
|
|
#define EXPAND_GROUP(name, members) { \
|
|
|
|
g_log(G_LOG_DOMAIN, log_level, "[%s]", #name); \
|
|
|
|
struct config_ ## name ## _t *group = &config->name; \
|
|
|
|
members \
|
|
|
|
}
|
2019-09-25 00:48:07 +00:00
|
|
|
|
2020-05-12 18:55:29 +00:00
|
|
|
#define EXPAND_GROUP_MEMBER(member, key_type, default_value) \
|
|
|
|
g_log(G_LOG_DOMAIN, log_level, "%s="FORMAT_FOR_KEY_TYPE(key_type)"", #member, group->member);
|
2019-09-25 00:48:07 +00:00
|
|
|
|
|
|
|
EXPAND_CONFIG
|
2020-05-12 18:55:29 +00:00
|
|
|
#undef EXPAND_GROUP
|
|
|
|
#undef EXPAND_GROUP_MEMBER
|
|
|
|
}
|
|
|
|
|
|
|
|
// Duplicates the input and converts the first character to uppercase
|
|
|
|
gchar* ascii_ucfirst(gchar *str) {
|
|
|
|
gchar *out = g_strdup(str);
|
|
|
|
out[0] = g_ascii_toupper(str[0]);
|
2019-09-25 00:48:07 +00:00
|
|
|
|
2020-05-12 18:55:29 +00:00
|
|
|
return out;
|
2019-09-25 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void load_config_from_key_file(config_t *config, GKeyFile *key_file) {
|
2020-04-10 02:07:01 +00:00
|
|
|
g_message("Loading config from key file");
|
2019-09-25 20:47:04 +00:00
|
|
|
GError *error = NULL;
|
2019-09-25 00:48:07 +00:00
|
|
|
|
2020-05-12 18:55:29 +00:00
|
|
|
#define EXPAND_GROUP(name_arg, members) { \
|
|
|
|
struct config_ ## name_arg ## _t *group = &config->name_arg; \
|
|
|
|
g_autofree gchar *group_name = ascii_ucfirst(#name_arg); \
|
|
|
|
members \
|
2019-09-27 21:10:28 +00:00
|
|
|
}
|
2019-09-25 00:48:07 +00:00
|
|
|
|
2020-05-12 18:55:29 +00:00
|
|
|
#define EXPAND_GROUP_MEMBER(member, key_type, default_value) \
|
|
|
|
group->member = g_key_file_get_##key_type(key_file, group_name, #member, &error); \
|
|
|
|
if (error != NULL) { \
|
|
|
|
group->member = default_value; \
|
|
|
|
print_config_error(error); \
|
|
|
|
g_clear_error(&error); \
|
|
|
|
}
|
|
|
|
|
2019-09-25 00:48:07 +00:00
|
|
|
EXPAND_CONFIG
|
|
|
|
|
2020-05-12 18:55:29 +00:00
|
|
|
if (config->emulation.rewind_duration > 600) {
|
2020-04-10 02:07:01 +00:00
|
|
|
g_warning("Setting Emulation.rewind_duration too high might affect performance.");
|
2019-09-25 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
2020-05-12 18:55:29 +00:00
|
|
|
#undef EXPAND_GROUP
|
|
|
|
#undef EXPAND_GROUP_MEMBER
|
2019-09-25 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
2020-04-10 02:07:01 +00:00
|
|
|
void print_config(config_t *config) {
|
|
|
|
_print_config(config, G_LOG_LEVEL_MESSAGE);
|
|
|
|
}
|
|
|
|
|
2019-09-25 20:47:04 +00:00
|
|
|
void save_config_to_key_file(config_t *config, GKeyFile *key_file) {
|
2020-04-10 02:07:01 +00:00
|
|
|
g_message("Saving config to key file");
|
2019-09-25 20:47:04 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
gchar *group_name;
|
|
|
|
|
2020-05-12 18:55:29 +00:00
|
|
|
#define EXPAND_GROUP(name_arg, members) { \
|
|
|
|
struct config_ ## name_arg ## _t *group = &config->name_arg; \
|
|
|
|
g_autofree gchar *group_name = ascii_ucfirst(#name_arg); \
|
|
|
|
members \
|
|
|
|
}
|
2019-09-25 20:47:04 +00:00
|
|
|
|
2020-05-12 18:55:29 +00:00
|
|
|
#define EXPAND_GROUP_MEMBER_IF_0(member, key_type, default_value) \
|
|
|
|
g_key_file_set_##key_type(key_file, group_name, #member, group->member);
|
2019-09-25 20:47:04 +00:00
|
|
|
|
2020-05-12 18:55:29 +00:00
|
|
|
#define EXPAND_GROUP_MEMBER_IF_1(member, key_type, default_value) \
|
|
|
|
if (group->member != NULL) { \
|
|
|
|
g_key_file_set_##key_type(key_file, group_name, #member, group->member); \
|
2019-09-25 20:47:04 +00:00
|
|
|
} \
|
2020-05-12 18:55:29 +00:00
|
|
|
else if (g_key_file_has_key(key_file, group_name, #member, &error)) { \
|
|
|
|
if (error != NULL) { \
|
|
|
|
g_warning("%s", error->message); \
|
|
|
|
g_clear_error(&error); \
|
|
|
|
} \
|
|
|
|
g_key_file_remove_key(key_file, group_name, #member, &error); \
|
|
|
|
if (error != NULL) { \
|
|
|
|
g_warning("%s", error->message); \
|
|
|
|
g_clear_error(&error); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define EXPAND_GROUP_MEMBER_IF_EVAL(y, member, key_type, default_value) EXPAND_GROUP_MEMBER_IF_ ## y(member, key_type, default_value)
|
|
|
|
#define EXPAND_GROUP_MEMBER_IF(member, key_type, is_pointer, default_value) EXPAND_GROUP_MEMBER_IF_EVAL(is_pointer, member, key_type, default_value)
|
|
|
|
#define EXPAND_GROUP_MEMBER(member, key_type, default_value) EXPAND_GROUP_MEMBER_IF(member, key_type, GTYPE_IS_POINTER(key_type), default_value)
|
2019-09-25 20:47:04 +00:00
|
|
|
|
|
|
|
EXPAND_CONFIG
|
|
|
|
|
2020-05-12 18:55:29 +00:00
|
|
|
#undef EXPAND_GROUP
|
|
|
|
#undef EXPAND_GROUP_MEMBER
|
|
|
|
#undef EXPAND_GROUP_MEMBER_IF
|
|
|
|
#undef EXPAND_GROUP_MEMBER_IF_EVAL
|
|
|
|
#undef EXPAND_GROUP_MEMBER_IF_0
|
|
|
|
#undef EXPAND_GROUP_MEMBER_IF_1
|
2020-05-12 22:25:13 +00:00
|
|
|
|
|
|
|
// Save config to disk
|
2020-05-16 14:56:09 +00:00
|
|
|
if (!g_key_file_save_to_file(key_file, config_file_path, &error)) {
|
|
|
|
g_warning ("Failed to save %s: %s", config_file_path, error->message);
|
2020-05-12 22:25:13 +00:00
|
|
|
g_error_free(error);
|
|
|
|
return;
|
|
|
|
}
|
2019-09-25 20:47:04 +00:00
|
|
|
}
|
|
|
|
|
2019-09-30 20:30:33 +00:00
|
|
|
void on_preferences_realize(GtkWidget *w, gpointer builder_ptr) {
|
2019-09-27 21:10:28 +00:00
|
|
|
GtkWindow *preferences = GTK_WINDOW(w);
|
|
|
|
GtkBuilder *builder = (GtkBuilder *) builder_ptr;
|
2020-05-12 21:32:49 +00:00
|
|
|
GApplication *app = G_APPLICATION(gtk_builder_get_application(builder));
|
|
|
|
|
2019-09-27 21:10:28 +00:00
|
|
|
update_boot_rom_selector(builder);
|
|
|
|
|
|
|
|
// Hook up the static preferences
|
2020-05-12 18:55:29 +00:00
|
|
|
gtk_combo_box_set_active_id(builder_get(GTK_COMBO_BOX, "rewind_duration_selector"), g_strdup_printf("%i", config.emulation.rewind_duration));
|
|
|
|
gtk_combo_box_set_active_id(builder_get(GTK_COMBO_BOX, "dmg_revision_selector"), config.emulation.dmg_revision_name);
|
|
|
|
gtk_combo_box_set_active_id(builder_get(GTK_COMBO_BOX, "sgb_revision_selector"), config.emulation.sgb_revision_name);
|
|
|
|
gtk_combo_box_set_active_id(builder_get(GTK_COMBO_BOX, "cgb_revision_selector"), config.emulation.cgb_revision_name);
|
2020-05-12 21:32:49 +00:00
|
|
|
|
2020-05-12 18:55:29 +00:00
|
|
|
gtk_combo_box_set_active_id(builder_get(GTK_COMBO_BOX, "shader_selector"), config.video.shader);
|
|
|
|
gtk_combo_box_set_active_id(builder_get(GTK_COMBO_BOX, "color_correction_selector"), config.video.color_correction_id);
|
|
|
|
gtk_combo_box_set_active_id(builder_get(GTK_COMBO_BOX, "frame_blending_selector"), config.video.frame_blending_mode);
|
|
|
|
gtk_combo_box_set_active_id(builder_get(GTK_COMBO_BOX, "display_border_selector"), config.video.display_border_mode);
|
|
|
|
gtk_combo_box_set_active_id(builder_get(GTK_COMBO_BOX, "monochrome_palette_selector"), config.video.monochrome_palette_id);
|
|
|
|
gtk_toggle_button_set_active(builder_get(GTK_TOGGLE_BUTTON, "integer_scaling_toggle"), config.video.use_integer_scaling);
|
|
|
|
gtk_toggle_button_set_active(builder_get(GTK_TOGGLE_BUTTON, "aspect_ratio_toggle"), config.video.keep_aspect_ratio);
|
2020-05-12 21:32:49 +00:00
|
|
|
|
2020-05-12 18:55:29 +00:00
|
|
|
gtk_combo_box_set_active_id(builder_get(GTK_COMBO_BOX, "highpass_filter_selector"), config.audio.high_pass_filter_id);
|
|
|
|
gtk_combo_box_set_active_id(builder_get(GTK_COMBO_BOX, "sample_rate_selector"), g_strdup_printf("%i", config.audio.sample_rate));
|
2020-05-12 21:32:49 +00:00
|
|
|
|
2020-05-12 18:55:29 +00:00
|
|
|
gtk_toggle_button_set_active(builder_get(GTK_TOGGLE_BUTTON, "analog_speed_controls_toggle"), config.controls.analog_speed_controls);
|
|
|
|
gtk_combo_box_set_active_id(builder_get(GTK_COMBO_BOX, "rumble_mode_selector"), config.controls.rumble_mode);
|
2019-09-27 21:10:28 +00:00
|
|
|
}
|
|
|
|
|
2020-05-16 14:56:09 +00:00
|
|
|
void init_config(GApplication *app, gchar *path, GDateTime **modification_date, GtkWindow *preferences) {
|
|
|
|
free_config();
|
2019-09-25 00:48:07 +00:00
|
|
|
key_file = g_key_file_new();
|
2019-09-24 14:14:06 +00:00
|
|
|
|
|
|
|
if (path != NULL) {
|
2020-05-16 14:56:09 +00:00
|
|
|
config_file_path = path;
|
2019-09-24 14:14:06 +00:00
|
|
|
}
|
|
|
|
else {
|
2020-05-16 14:56:09 +00:00
|
|
|
config_file_path = g_build_filename(g_get_user_config_dir(), CONFIG_FILE, NULL);
|
2019-09-24 14:14:06 +00:00
|
|
|
}
|
|
|
|
|
2020-05-16 14:56:09 +00:00
|
|
|
load_config(app, modification_date);
|
2019-09-24 14:14:06 +00:00
|
|
|
}
|
|
|
|
|
2020-05-16 14:56:09 +00:00
|
|
|
void load_config(GApplication *app, GDateTime **modification_date) {
|
2019-09-24 14:14:06 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
|
2020-05-16 14:56:09 +00:00
|
|
|
g_message("Trying to load config from %s", config_file_path);
|
2019-09-24 14:14:06 +00:00
|
|
|
|
2020-05-16 14:56:09 +00:00
|
|
|
g_autoptr(GFile) file = g_file_new_for_path(config_file_path);
|
2020-05-12 22:25:13 +00:00
|
|
|
g_autoptr(GFileInfo) file_info = g_file_query_info(file, "time::*", G_FILE_QUERY_INFO_NONE, NULL, NULL);
|
2020-05-16 14:30:29 +00:00
|
|
|
|
|
|
|
#if GLIB_CHECK_VERSION(2,62,0)
|
|
|
|
*modification_date = g_file_info_get_modification_date_time(file_info);
|
|
|
|
#else
|
|
|
|
GTimeVal tv;
|
|
|
|
g_file_info_get_modification_time(file_info, &tv);
|
|
|
|
*modification_date = g_date_time_new_from_timeval_utc(&tv);
|
|
|
|
#endif
|
2020-05-12 22:25:13 +00:00
|
|
|
|
2020-05-16 14:56:09 +00:00
|
|
|
if (!g_key_file_load_from_file(key_file, config_file_path, G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS, &error)) {
|
2019-09-25 00:48:07 +00:00
|
|
|
if (error->domain == G_FILE_ERROR) {
|
2020-05-16 14:56:09 +00:00
|
|
|
g_warning("Unable to load %s: %s", config_file_path, error->message);
|
2019-09-25 00:48:07 +00:00
|
|
|
}
|
|
|
|
else if (error->domain == G_KEY_FILE_ERROR) {
|
2020-05-16 14:56:09 +00:00
|
|
|
g_warning("Failed to parse %s: %s", config_file_path, error->message);
|
2019-09-25 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
2019-09-24 14:14:06 +00:00
|
|
|
g_error_free(error);
|
|
|
|
}
|
2019-09-25 00:48:07 +00:00
|
|
|
|
|
|
|
load_config_from_key_file(&config, key_file);
|
2020-04-10 02:07:01 +00:00
|
|
|
_print_config(&config, G_LOG_LEVEL_DEBUG);
|
2019-09-25 00:48:07 +00:00
|
|
|
|
2020-05-12 21:32:49 +00:00
|
|
|
// Update GAction states
|
|
|
|
g_action_group_change_action_state(G_ACTION_GROUP(app), "toggle_mute", g_variant_new_boolean(config.audio.muted));
|
2019-09-24 14:14:06 +00:00
|
|
|
}
|
|
|
|
|
2020-05-16 14:56:09 +00:00
|
|
|
void save_config(GtkWindow *main_window, GDateTime *saved_modification_date) {
|
2019-09-24 14:14:06 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
|
2020-05-16 14:56:09 +00:00
|
|
|
g_message("Trying to save config to %s", config_file_path);
|
2019-09-24 14:14:06 +00:00
|
|
|
|
2020-05-16 14:56:09 +00:00
|
|
|
g_autoptr(GFile) file = g_file_new_for_path(config_file_path);
|
2020-05-12 22:25:13 +00:00
|
|
|
g_autoptr(GFileInfo) file_info = g_file_query_info(file, "time::*", G_FILE_QUERY_INFO_NONE, NULL, NULL);
|
2020-05-16 14:30:29 +00:00
|
|
|
|
|
|
|
#if GLIB_CHECK_VERSION(2,62,0)
|
|
|
|
GDateTime *modification_date = g_file_info_get_modification_date_time(file_info);
|
|
|
|
#else
|
|
|
|
GTimeVal tv;
|
|
|
|
g_file_info_get_modification_time(file_info, &tv);
|
|
|
|
GDateTime *modification_date = g_date_time_new_from_timeval_utc(&tv);
|
|
|
|
#endif
|
2020-05-12 22:25:13 +00:00
|
|
|
|
|
|
|
if (!g_date_time_equal(saved_modification_date, modification_date)) {
|
|
|
|
GtkMessageDialog *dialog = GTK_MESSAGE_DIALOG(gtk_message_dialog_new(
|
|
|
|
main_window,
|
|
|
|
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
GTK_MESSAGE_QUESTION,
|
|
|
|
GTK_BUTTONS_YES_NO,
|
|
|
|
"It looks like the configuration has changed on disk. Overwrite?"
|
|
|
|
));
|
|
|
|
|
|
|
|
gtk_window_set_title(GTK_WINDOW(dialog), "SameBoy");
|
|
|
|
|
|
|
|
gint result = gtk_dialog_run(GTK_DIALOG(dialog));
|
|
|
|
|
|
|
|
switch (result) {
|
|
|
|
case GTK_RESPONSE_YES:
|
|
|
|
save_config_to_key_file(&config, key_file);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// Action has been canceled
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
save_config_to_key_file(&config, key_file);
|
2019-09-24 14:14:06 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-25 00:48:07 +00:00
|
|
|
|
2020-05-16 14:56:09 +00:00
|
|
|
void free_config(void) {
|
2019-09-25 00:48:07 +00:00
|
|
|
if (key_file != NULL) {
|
|
|
|
g_key_file_free(key_file);
|
|
|
|
key_file = NULL;
|
|
|
|
}
|
|
|
|
}
|
2019-09-25 20:47:04 +00:00
|
|
|
|
2019-09-27 21:10:28 +00:00
|
|
|
void update_boot_rom_selector(GtkBuilder *builder) {
|
2019-10-03 01:13:53 +00:00
|
|
|
GtkComboBoxText *combo_box = builder_get(GTK_COMBO_BOX_TEXT, "boot_rom_selector");
|
2019-09-27 21:10:28 +00:00
|
|
|
gtk_combo_box_text_remove_all(combo_box);
|
|
|
|
gtk_combo_box_text_append(combo_box, "auto", "Use Built-in Boot ROMs");
|
2020-05-12 18:55:29 +00:00
|
|
|
if (config.emulation.boot_rom_path != NULL && !g_str_equal(config.emulation.boot_rom_path, "auto") && !g_str_equal(config.emulation.boot_rom_path, "other")) {
|
|
|
|
gtk_combo_box_text_append(combo_box, config.emulation.boot_rom_path, config.emulation.boot_rom_path);
|
|
|
|
gtk_combo_box_set_active_id(GTK_COMBO_BOX(combo_box), config.emulation.boot_rom_path);
|
2019-09-27 21:10:28 +00:00
|
|
|
}
|
2019-09-27 22:15:37 +00:00
|
|
|
else {
|
|
|
|
gtk_combo_box_set_active_id(GTK_COMBO_BOX(combo_box), "auto");
|
|
|
|
}
|
2019-09-27 21:10:28 +00:00
|
|
|
gtk_combo_box_text_append_text(combo_box, "<separator>");
|
|
|
|
gtk_combo_box_text_append(combo_box, "other", "Other");
|
|
|
|
}
|
|
|
|
|
2020-05-16 14:56:09 +00:00
|
|
|
GB_color_correction_mode_t config_get_color_correction_mode(void) {
|
2020-05-12 18:55:29 +00:00
|
|
|
if (config.video.color_correction_id == NULL) goto default_value;
|
2019-09-26 14:22:30 +00:00
|
|
|
|
2020-05-12 18:55:29 +00:00
|
|
|
if (g_strcmp0(config.video.color_correction_id, "disabled") == 0) {
|
2019-09-26 14:22:30 +00:00
|
|
|
return GB_COLOR_CORRECTION_DISABLED;
|
|
|
|
}
|
2020-05-12 18:55:29 +00:00
|
|
|
else if (g_strcmp0(config.video.color_correction_id, "correct_color_curves") == 0) {
|
2019-09-26 14:22:30 +00:00
|
|
|
return GB_COLOR_CORRECTION_CORRECT_CURVES;
|
|
|
|
}
|
2020-05-12 18:55:29 +00:00
|
|
|
else if (g_strcmp0(config.video.color_correction_id, "emulate_hardware") == 0) {
|
2019-09-26 14:22:30 +00:00
|
|
|
return GB_COLOR_CORRECTION_EMULATE_HARDWARE;
|
|
|
|
}
|
2020-05-12 18:55:29 +00:00
|
|
|
else if (g_strcmp0(config.video.color_correction_id, "preserve_brightness") == 0) {
|
2019-09-26 14:22:30 +00:00
|
|
|
return GB_COLOR_CORRECTION_PRESERVE_BRIGHTNESS;
|
|
|
|
}
|
2020-05-12 18:55:29 +00:00
|
|
|
else if (g_strcmp0(config.video.color_correction_id, "reduce_contrast") == 0) {
|
2020-04-10 02:07:01 +00:00
|
|
|
return GB_COLOR_CORRECTION_REDUCE_CONTRAST;
|
|
|
|
}
|
2019-09-26 14:22:30 +00:00
|
|
|
|
|
|
|
// This should not happen
|
2020-05-12 18:55:29 +00:00
|
|
|
g_warning("Unknown color correction mode: %s\nFalling back to “Emulate Hardware”", config.video.color_correction_id);
|
2019-09-26 14:22:30 +00:00
|
|
|
default_value: return GB_COLOR_CORRECTION_EMULATE_HARDWARE;
|
|
|
|
}
|
|
|
|
|
2020-05-16 14:56:09 +00:00
|
|
|
void config_set_color_correction_mode(GB_color_correction_mode_t mode) {
|
2019-09-26 14:22:30 +00:00
|
|
|
switch (mode) {
|
|
|
|
case GB_COLOR_CORRECTION_DISABLED:
|
2020-05-12 18:55:29 +00:00
|
|
|
config.video.color_correction_id = "disabled";
|
2019-09-26 14:22:30 +00:00
|
|
|
break;
|
|
|
|
case GB_COLOR_CORRECTION_CORRECT_CURVES:
|
2020-05-12 18:55:29 +00:00
|
|
|
config.video.color_correction_id = "correct_color_curves";
|
2019-09-26 14:22:30 +00:00
|
|
|
break;
|
|
|
|
case GB_COLOR_CORRECTION_EMULATE_HARDWARE:
|
2020-05-12 18:55:29 +00:00
|
|
|
config.video.color_correction_id = "emulate_hardware";
|
2019-09-26 14:22:30 +00:00
|
|
|
break;
|
|
|
|
case GB_COLOR_CORRECTION_PRESERVE_BRIGHTNESS:
|
2020-05-12 18:55:29 +00:00
|
|
|
config.video.color_correction_id = "preserve_brightness";
|
2019-09-26 14:22:30 +00:00
|
|
|
break;
|
2020-04-10 02:07:01 +00:00
|
|
|
case GB_COLOR_CORRECTION_REDUCE_CONTRAST:
|
2020-05-12 18:55:29 +00:00
|
|
|
config.video.color_correction_id = "reduce_contrast";
|
2020-04-10 02:07:01 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-16 14:56:09 +00:00
|
|
|
GB_frame_blending_mode_t config_get_frame_blending_mode(void) {
|
2020-05-12 18:55:29 +00:00
|
|
|
if (config.video.frame_blending_mode == NULL) goto default_value;
|
2020-04-10 02:07:01 +00:00
|
|
|
|
2020-05-12 18:55:29 +00:00
|
|
|
if (g_strcmp0(config.video.frame_blending_mode, "disabled") == 0) {
|
2020-04-10 02:07:01 +00:00
|
|
|
return GB_FRAME_BLENDING_MODE_DISABLED;
|
|
|
|
}
|
2020-05-12 18:55:29 +00:00
|
|
|
else if (g_strcmp0(config.video.frame_blending_mode, "simple") == 0) {
|
2020-04-10 02:07:01 +00:00
|
|
|
return GB_FRAME_BLENDING_MODE_SIMPLE;
|
|
|
|
}
|
2020-05-12 18:55:29 +00:00
|
|
|
else if (g_strcmp0(config.video.frame_blending_mode, "accurate") == 0) {
|
2020-04-10 02:07:01 +00:00
|
|
|
return GB_FRAME_BLENDING_MODE_ACCURATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This should not happen
|
2020-05-12 18:55:29 +00:00
|
|
|
g_warning("Unknown frame blending mode: %s\nFalling back to “Disabled”", config.video.frame_blending_mode);
|
2020-04-10 02:07:01 +00:00
|
|
|
default_value: return GB_FRAME_BLENDING_MODE_DISABLED;
|
|
|
|
}
|
|
|
|
|
2020-05-16 14:56:09 +00:00
|
|
|
void config_set_frame_blending_mode(GB_frame_blending_mode_t mode) {
|
2020-04-10 02:07:01 +00:00
|
|
|
switch (mode) {
|
|
|
|
case GB_FRAME_BLENDING_MODE_DISABLED:
|
2020-05-12 18:55:29 +00:00
|
|
|
config.video.frame_blending_mode = "disabled";
|
2020-04-10 02:07:01 +00:00
|
|
|
break;
|
|
|
|
case GB_FRAME_BLENDING_MODE_SIMPLE:
|
2020-05-12 18:55:29 +00:00
|
|
|
config.video.frame_blending_mode = "simple";
|
2020-04-10 02:07:01 +00:00
|
|
|
break;
|
|
|
|
case GB_FRAME_BLENDING_MODE_ACCURATE:
|
|
|
|
case GB_FRAME_BLENDING_MODE_ACCURATE_ODD:
|
2020-05-12 18:55:29 +00:00
|
|
|
config.video.frame_blending_mode = "accurate";
|
2020-04-10 02:07:01 +00:00
|
|
|
break;
|
2019-09-26 14:22:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-16 14:56:09 +00:00
|
|
|
GB_border_mode_t config_get_display_border_mode(void) {
|
2020-05-12 18:55:29 +00:00
|
|
|
if (config.video.display_border_mode == NULL) goto default_value;
|
2020-04-10 19:42:03 +00:00
|
|
|
|
2020-05-12 18:55:29 +00:00
|
|
|
if (g_strcmp0(config.video.display_border_mode, "never") == 0) {
|
2020-04-10 19:42:03 +00:00
|
|
|
return GB_BORDER_NEVER;
|
|
|
|
}
|
2020-05-12 18:55:29 +00:00
|
|
|
else if (g_strcmp0(config.video.display_border_mode, "sgb_only") == 0) {
|
2020-04-10 19:42:03 +00:00
|
|
|
return GB_BORDER_SGB;
|
|
|
|
}
|
2020-05-12 18:55:29 +00:00
|
|
|
else if (g_strcmp0(config.video.display_border_mode, "always") == 0) {
|
2020-04-10 19:42:03 +00:00
|
|
|
return GB_BORDER_ALWAYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This should not happen
|
2020-05-12 18:55:29 +00:00
|
|
|
g_warning("Unknown SGB border mode: %s\nFalling back to “Never”", config.video.display_border_mode);
|
2020-04-10 19:42:03 +00:00
|
|
|
default_value: return GB_BORDER_NEVER;
|
|
|
|
}
|
|
|
|
|
2020-05-16 14:56:09 +00:00
|
|
|
void config_set_display_border_mode(GB_border_mode_t mode) {
|
2020-04-10 19:42:03 +00:00
|
|
|
switch (mode) {
|
|
|
|
case GB_BORDER_NEVER:
|
2020-05-12 18:55:29 +00:00
|
|
|
config.video.display_border_mode = "never";
|
2020-04-10 19:42:03 +00:00
|
|
|
break;
|
|
|
|
case GB_BORDER_SGB:
|
2020-05-12 18:55:29 +00:00
|
|
|
config.video.display_border_mode = "sgb_only";
|
2020-04-10 19:42:03 +00:00
|
|
|
break;
|
|
|
|
case GB_BORDER_ALWAYS:
|
2020-05-12 18:55:29 +00:00
|
|
|
config.video.display_border_mode = "always";
|
2020-04-10 19:42:03 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-16 14:56:09 +00:00
|
|
|
const GB_palette_t* config_get_monochrome_palette(void) {
|
2020-05-12 18:55:29 +00:00
|
|
|
if (config.video.monochrome_palette_id == NULL) goto default_value;
|
2020-04-10 20:19:40 +00:00
|
|
|
|
2020-05-12 18:55:29 +00:00
|
|
|
if (g_strcmp0(config.video.monochrome_palette_id, "greyscale") == 0) {
|
2020-04-10 20:19:40 +00:00
|
|
|
return &GB_PALETTE_GREY;
|
|
|
|
}
|
2020-05-12 18:55:29 +00:00
|
|
|
else if (g_strcmp0(config.video.monochrome_palette_id, "lime") == 0) {
|
2020-04-10 20:19:40 +00:00
|
|
|
return &GB_PALETTE_DMG;
|
|
|
|
}
|
2020-05-12 18:55:29 +00:00
|
|
|
else if (g_strcmp0(config.video.monochrome_palette_id, "olive") == 0) {
|
2020-04-10 20:19:40 +00:00
|
|
|
return &GB_PALETTE_MGB;
|
|
|
|
}
|
2020-05-12 18:55:29 +00:00
|
|
|
else if (g_strcmp0(config.video.monochrome_palette_id, "teal") == 0) {
|
2020-04-10 20:19:40 +00:00
|
|
|
return &GB_PALETTE_GBL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This should not happen
|
2020-05-12 18:55:29 +00:00
|
|
|
g_warning("Unknown monochrome palette: %s\nFalling back to “Greyscale”", config.video.monochrome_palette_id);
|
2020-04-10 20:19:40 +00:00
|
|
|
default_value: return &GB_PALETTE_GREY;
|
|
|
|
}
|
|
|
|
|
2020-05-16 14:56:09 +00:00
|
|
|
void config_set_monochrome_palette(const GB_palette_t *mode) {
|
2020-04-10 20:19:40 +00:00
|
|
|
g_message("%p | %p | %p | %p | %p", mode, &GB_PALETTE_GREY, &GB_PALETTE_DMG, &GB_PALETTE_MGB, &GB_PALETTE_GBL);
|
|
|
|
|
|
|
|
if (mode == &GB_PALETTE_GREY) {
|
2020-05-12 18:55:29 +00:00
|
|
|
config.video.monochrome_palette_id = "greyscale";
|
2020-04-10 20:19:40 +00:00
|
|
|
}
|
|
|
|
else if (mode == &GB_PALETTE_DMG) {
|
2020-05-12 18:55:29 +00:00
|
|
|
config.video.monochrome_palette_id = "lime";
|
2020-04-10 20:19:40 +00:00
|
|
|
}
|
|
|
|
else if (mode == &GB_PALETTE_MGB) {
|
2020-05-12 18:55:29 +00:00
|
|
|
config.video.monochrome_palette_id = "olive";
|
2020-04-10 20:19:40 +00:00
|
|
|
}
|
|
|
|
else if (mode == &GB_PALETTE_GBL) {
|
2020-05-12 18:55:29 +00:00
|
|
|
config.video.monochrome_palette_id = "teal";
|
2020-04-10 20:19:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-16 14:56:09 +00:00
|
|
|
GB_highpass_mode_t config_get_highpass_mode(void) {
|
2020-05-12 18:55:29 +00:00
|
|
|
if (config.audio.high_pass_filter_id == NULL) goto default_value;
|
2019-09-26 14:22:30 +00:00
|
|
|
|
2020-05-12 18:55:29 +00:00
|
|
|
if (g_strcmp0(config.audio.high_pass_filter_id, "disabled") == 0) {
|
2019-09-26 14:22:30 +00:00
|
|
|
return GB_HIGHPASS_OFF;
|
|
|
|
}
|
2020-05-12 18:55:29 +00:00
|
|
|
else if (g_strcmp0(config.audio.high_pass_filter_id, "emulate_hardware") == 0) {
|
2019-09-26 14:22:30 +00:00
|
|
|
return GB_HIGHPASS_ACCURATE;
|
|
|
|
}
|
2020-05-12 18:55:29 +00:00
|
|
|
else if (g_strcmp0(config.audio.high_pass_filter_id, "preserve_waveform") == 0) {
|
2019-09-26 14:22:30 +00:00
|
|
|
return GB_HIGHPASS_REMOVE_DC_OFFSET;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This should not happen
|
2020-05-12 18:55:29 +00:00
|
|
|
g_warning("Unknown highpass mode: %s\nFalling back to “Accurate”", config.audio.high_pass_filter_id);
|
2019-09-26 14:22:30 +00:00
|
|
|
default_value: return GB_HIGHPASS_ACCURATE;
|
|
|
|
}
|
|
|
|
|
2020-05-16 14:56:09 +00:00
|
|
|
void config_set_highpass_mode(GB_highpass_mode_t mode) {
|
2019-09-26 14:22:30 +00:00
|
|
|
switch (mode) {
|
|
|
|
case GB_HIGHPASS_OFF:
|
2020-05-12 18:55:29 +00:00
|
|
|
config.audio.high_pass_filter_id = "disabled";
|
2019-09-26 14:22:30 +00:00
|
|
|
break;
|
|
|
|
case GB_HIGHPASS_MAX:
|
2020-04-10 02:07:01 +00:00
|
|
|
g_warning("GB_HIGHPASS_MAX is not a valid highpass mode, falling back to “Accurate”.");
|
2019-09-26 14:22:30 +00:00
|
|
|
case GB_HIGHPASS_ACCURATE:
|
2020-05-12 18:55:29 +00:00
|
|
|
config.audio.high_pass_filter_id = "emulate_hardware";
|
2019-09-26 14:22:30 +00:00
|
|
|
break;
|
|
|
|
case GB_HIGHPASS_REMOVE_DC_OFFSET:
|
2020-05-12 18:55:29 +00:00
|
|
|
config.audio.high_pass_filter_id = "preserve_waveform";
|
2019-09-25 20:47:04 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-10-14 14:01:51 +00:00
|
|
|
|
2020-05-16 14:56:09 +00:00
|
|
|
const GB_rumble_mode_t config_get_rumble_mode(void) {
|
2020-05-12 18:55:29 +00:00
|
|
|
if (config.controls.rumble_mode == NULL) goto default_value;
|
2020-05-03 23:41:14 +00:00
|
|
|
|
2020-05-12 18:55:29 +00:00
|
|
|
if (g_strcmp0(config.controls.rumble_mode, "never") == 0) {
|
2020-05-03 23:41:14 +00:00
|
|
|
return GB_RUMBLE_DISABLED;
|
|
|
|
}
|
2020-05-12 18:55:29 +00:00
|
|
|
else if (g_strcmp0(config.controls.rumble_mode, "rumble_cartridges") == 0) {
|
2020-05-03 23:41:14 +00:00
|
|
|
return GB_RUMBLE_CARTRIDGE_ONLY;
|
|
|
|
}
|
2020-05-12 18:55:29 +00:00
|
|
|
else if (g_strcmp0(config.controls.rumble_mode, "always") == 0) {
|
2020-05-03 23:41:14 +00:00
|
|
|
return GB_RUMBLE_ALL_GAMES;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This should not happen
|
2020-05-12 18:55:29 +00:00
|
|
|
g_warning("Unknown highpass mode: %s\nFalling back to “Never”", config.controls.rumble_mode);
|
2020-05-03 23:41:14 +00:00
|
|
|
default_value: return GB_RUMBLE_DISABLED;
|
|
|
|
}
|
|
|
|
|
2020-05-16 14:56:09 +00:00
|
|
|
void config_set_rumble_mode(GB_rumble_mode_t mode) {
|
2020-05-03 23:41:14 +00:00
|
|
|
switch (mode) {
|
|
|
|
case GB_RUMBLE_DISABLED:
|
2020-05-12 18:55:29 +00:00
|
|
|
config.controls.rumble_mode = "never";
|
2020-05-03 23:41:14 +00:00
|
|
|
break;
|
|
|
|
case GB_RUMBLE_CARTRIDGE_ONLY:
|
2020-05-12 18:55:29 +00:00
|
|
|
config.controls.rumble_mode = "rumble_cartridges";
|
2020-05-03 23:41:14 +00:00
|
|
|
break;
|
|
|
|
case GB_RUMBLE_ALL_GAMES:
|
2020-05-12 18:55:29 +00:00
|
|
|
config.controls.rumble_mode = "always";
|
2020-05-03 23:41:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-16 14:56:09 +00:00
|
|
|
GB_model_t config_get_model(void) {
|
2020-05-12 19:51:55 +00:00
|
|
|
if (g_strcmp0(config.emulation.model, "DMG") == 0) {
|
2020-05-16 14:56:09 +00:00
|
|
|
return config_get_dmg_model();
|
2020-05-12 19:51:55 +00:00
|
|
|
}
|
|
|
|
else if (g_strcmp0(config.emulation.model, "MGB") == 0) {
|
|
|
|
g_warning("Emulation of MGBs is unsupported, falling back to DMG.");
|
2020-05-12 21:32:49 +00:00
|
|
|
|
2020-05-16 14:56:09 +00:00
|
|
|
return config_get_dmg_model();
|
2020-05-12 19:51:55 +00:00
|
|
|
}
|
|
|
|
else if (g_strcmp0(config.emulation.model, "AGB") == 0) {
|
|
|
|
return GB_MODEL_AGB;
|
|
|
|
}
|
|
|
|
else if (g_strcmp0(config.emulation.model, "SGB") == 0) {
|
2020-05-16 14:56:09 +00:00
|
|
|
return config_get_sgb_model();
|
2020-05-12 19:51:55 +00:00
|
|
|
}
|
|
|
|
|
2020-05-16 14:56:09 +00:00
|
|
|
return config_get_cgb_model();
|
2020-05-12 19:51:55 +00:00
|
|
|
}
|
|
|
|
|
2020-05-16 14:56:09 +00:00
|
|
|
void config_set_model(GB_model_t model) {
|
2020-05-12 19:51:55 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-16 14:56:09 +00:00
|
|
|
GB_model_t config_get_dmg_model(void) {
|
2020-05-12 18:55:29 +00:00
|
|
|
if (config.emulation.dmg_revision_name == NULL) goto default_value;
|
2019-10-14 14:01:51 +00:00
|
|
|
|
|
|
|
// TODO: Synchronize with GB_model_t (Core/gb.h)
|
2020-05-12 18:55:29 +00:00
|
|
|
if (g_strcmp0(config.emulation.dmg_revision_name, "DMG_CPU_B") == 0) {
|
2019-10-14 14:01:51 +00:00
|
|
|
return GB_MODEL_DMG_B;
|
|
|
|
}
|
|
|
|
|
|
|
|
default_value: return GB_MODEL_DMG_B;
|
|
|
|
}
|
|
|
|
|
2020-05-16 14:56:09 +00:00
|
|
|
GB_model_t config_get_sgb_model(void) {
|
2020-05-12 18:55:29 +00:00
|
|
|
if (config.emulation.sgb_revision_name == NULL) goto default_value;
|
2019-10-14 14:01:51 +00:00
|
|
|
|
|
|
|
// TODO: Synchronize with GB_model_t (Core/gb.h)
|
2020-05-12 18:55:29 +00:00
|
|
|
if (g_strcmp0(config.emulation.sgb_revision_name, "SGB1_NTSC") == 0) {
|
2019-10-14 14:01:51 +00:00
|
|
|
return GB_MODEL_SGB_NTSC;
|
|
|
|
}
|
2020-05-12 18:55:29 +00:00
|
|
|
else if (g_strcmp0(config.emulation.sgb_revision_name, "SGB1_PAL") == 0) {
|
2019-10-14 14:01:51 +00:00
|
|
|
return GB_MODEL_SGB_PAL;
|
|
|
|
}
|
2020-05-12 18:55:29 +00:00
|
|
|
else if (g_strcmp0(config.emulation.sgb_revision_name, "SGB2") == 0) {
|
2019-10-14 14:01:51 +00:00
|
|
|
return GB_MODEL_SGB2;
|
|
|
|
}
|
|
|
|
|
|
|
|
default_value: return GB_MODEL_SGB2;
|
|
|
|
}
|
|
|
|
|
2020-05-16 14:56:09 +00:00
|
|
|
GB_model_t config_get_cgb_model(void) {
|
2020-05-12 18:55:29 +00:00
|
|
|
if (config.emulation.cgb_revision_name == NULL) goto default_value;
|
2019-10-14 14:01:51 +00:00
|
|
|
|
|
|
|
// TODO: Synchronize with GB_model_t (Core/gb.h)
|
2020-05-12 18:55:29 +00:00
|
|
|
if (g_strcmp0(config.emulation.cgb_revision_name, "CPU_CGB_C") == 0) {
|
2019-10-14 14:01:51 +00:00
|
|
|
return GB_MODEL_CGB_C;
|
|
|
|
}
|
2020-05-12 18:55:29 +00:00
|
|
|
else if (g_strcmp0(config.emulation.cgb_revision_name, "CPU_CGB_E") == 0) {
|
2019-10-14 14:01:51 +00:00
|
|
|
return GB_MODEL_CGB_E;
|
|
|
|
}
|
|
|
|
|
|
|
|
default_value: return GB_MODEL_CGB_E;
|
|
|
|
}
|