[GTK3] Make use of GB_set_boot_rom_load_callback

This commit is contained in:
Maximilian Mader 2020-04-10 18:10:09 +02:00
parent 53934aedec
commit 5b79094293
Signed by: Max
GPG Key ID: F71D56A3151C4FB3
2 changed files with 23 additions and 37 deletions

View File

@ -2097,57 +2097,42 @@ static void init(GuiData *gui_data) {
GB_set_input_callback(&gb, sync_console_input);
GB_set_async_input_callback(&gb, async_console_input);
GB_set_log_callback(&gb, console_log);
GB_set_boot_rom_load_callback(&gb, load_boot_rom);
}
static void load_boot_rom(GuiData *gui_data) {
static void load_boot_rom(GB_gameboy_t *gb, GB_boot_rom_t type) {
GError *error = NULL;
char *boot_rom_path = NULL;
char *boot_rom_name = NULL;
GBytes *boot_rom_f = NULL;
const guchar *boot_rom_data;
gsize boot_rom_size;
if (gui_data->cli_options.boot_rom_path != NULL) {
g_message("Trying to load boot ROM from %s", gui_data->cli_options.boot_rom_path);
if (GB_load_boot_rom(&gb, gui_data->cli_options.boot_rom_path)) {
static const char *const names[] = {
[GB_BOOT_ROM_DMG0] = "dmg0_boot.bin",
[GB_BOOT_ROM_DMG] = "dmg_boot.bin",
[GB_BOOT_ROM_MGB] = "mgb_boot.bin",
[GB_BOOT_ROM_SGB] = "sgb_boot.bin",
[GB_BOOT_ROM_SGB2] = "sgb2_boot.bin",
[GB_BOOT_ROM_CGB0] = "cgb0_boot.bin",
[GB_BOOT_ROM_CGB] = "cgb_boot.bin",
[GB_BOOT_ROM_AGB] = "agb_boot.bin",
};
const char *const boot_rom_name = names[type];
if (gui_data.cli_options.boot_rom_path != NULL) {
g_message("[CLI override] Trying to load boot ROM from %s", gui_data.cli_options.boot_rom_path);
if (GB_load_boot_rom(gb, gui_data.cli_options.boot_rom_path)) {
g_warning("Falling back to boot ROM from config");
goto config_boot_rom;
}
}
else { config_boot_rom:
// TODO: Synchronize with GB_model_t (Core/gb.h)
switch (get_model()) {
case GB_MODEL_DMG_B:
boot_rom_name = "dmg_boot.bin";
break;
case GB_MODEL_SGB:
case GB_MODEL_SGB_PAL:
case GB_MODEL_SGB_NO_SFC:
case GB_MODEL_SGB_PAL_NO_SFC:
boot_rom_name = "sgb_boot.bin";
break;
case GB_MODEL_SGB2:
case GB_MODEL_SGB2_NO_SFC:
boot_rom_name = "sgb2_boot.bin";
break;
case GB_MODEL_CGB_C:
case GB_MODEL_CGB_E:
boot_rom_name = "cgb_boot.bin";
break;
case GB_MODEL_AGB:
boot_rom_name = "agb_boot.bin";
break;
}
if (config.boot_rom_path != NULL && g_strcmp0(config.boot_rom_path, "other") != 0 && g_strcmp0(config.boot_rom_path, "auto") != 0) {
boot_rom_path = g_build_filename(config.boot_rom_path, boot_rom_name, NULL);
g_message("Trying to load boot ROM from %s", boot_rom_path);
if (GB_load_boot_rom(&gb, boot_rom_path)) {
if (GB_load_boot_rom(gb, boot_rom_path)) {
g_free(boot_rom_path);
g_warning("Falling back to internal boot ROM");
goto internal_boot_rom;
@ -2158,6 +2143,8 @@ static void load_boot_rom(GuiData *gui_data) {
else { internal_boot_rom:
boot_rom_path = g_build_filename(RESOURCE_PREFIX "bootroms/", boot_rom_name, NULL);
boot_rom_f = g_resources_lookup_data(boot_rom_path, G_RESOURCE_LOOKUP_FLAGS_NONE, &error);
g_message("Loading internal boot ROM: %s", boot_rom_path);
g_free(boot_rom_path);
if (boot_rom_f == NULL) {
@ -2167,7 +2154,7 @@ static void load_boot_rom(GuiData *gui_data) {
}
boot_rom_data = g_bytes_get_data(boot_rom_f, &boot_rom_size);
GB_load_boot_rom_from_buffer(&gb, boot_rom_data, boot_rom_size);
GB_load_boot_rom_from_buffer(gb, boot_rom_data, boot_rom_size);
g_bytes_unref(boot_rom_f);
}
@ -2214,7 +2201,6 @@ static void reset(GuiData *gui_data) {
update_window_geometry();
}
load_boot_rom(gui_data);
char *path = g_file_get_path(gui_data->file);

View File

@ -159,7 +159,7 @@ static void update_window_geometry();
static void run(GuiData *gui_data);
static gpointer run_thread(gpointer user_data_gptr);
static void init(GuiData *gui_data);
static void load_boot_rom(GuiData *gui_data);
static void load_boot_rom(GB_gameboy_t *gb, GB_boot_rom_t type);
static void handle_events(GB_gameboy_t *gb);
static uint32_t convert_color(uint16_t color);