From ef79734e7cc59f4655539cb7a7b7d90fbb5d1f1d Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Mon, 21 Mar 2016 22:57:19 +0100 Subject: [PATCH] Use same system as dynamic cores to get system info. --- command_event.c | 2 ++ driver.c | 4 --- dynamic.c | 70 +++++++++++++++++++++++++++++++++++----------- dynamic.h | 16 ++++++++++- menu/menu_driver.c | 2 -- 5 files changed, 70 insertions(+), 24 deletions(-) diff --git a/command_event.c b/command_event.c index 770415300e..905e6e6a6f 100644 --- a/command_event.c +++ b/command_event.c @@ -1013,6 +1013,8 @@ bool event_cmd_ctl(enum event_command cmd, void *data) libretro_get_system_info(settings->libretro, system, ptr); +#else + libretro_get_system_info_static(system, ptr); #endif info_find.path = settings->libretro; diff --git a/driver.c b/driver.c index 396b3837c7..7a0ccf5c8d 100644 --- a/driver.c +++ b/driver.c @@ -288,10 +288,6 @@ static void menu_update_libretro_info(void) if (!info) return; -#ifndef HAVE_DYNAMIC - retro_get_system_info(info); -#endif - event_cmd_ctl(EVENT_CMD_CORE_INFO_INIT, NULL); event_cmd_ctl(EVENT_CMD_LOAD_CORE_PERSIST, NULL); } diff --git a/dynamic.c b/dynamic.c index 4b26e83af1..0506c69ef7 100644 --- a/dynamic.c +++ b/dynamic.c @@ -113,7 +113,23 @@ libretro_find_controller_description( return NULL; } -#ifdef HAVE_DYNAMIC +/** + * libretro_free_system_info: + * @info : Pointer to system info information. + * + * Frees system information. + **/ +void libretro_free_system_info(struct retro_system_info *info) +{ + if (!info) + return; + + free((void*)info->library_name); + free((void*)info->library_version); + free((void*)info->valid_extensions); + memset(info, 0, sizeof(*info)); +} + static bool *load_no_content_hook; static bool environ_cb_get_system_info(unsigned cmd, void *data) @@ -131,6 +147,42 @@ static bool environ_cb_get_system_info(unsigned cmd, void *data) return true; } +#ifndef HAVE_DYNAMIC +bool libretro_get_system_info_static(struct retro_system_info *info, + bool *load_no_content) +{ + struct retro_system_info dummy_info = {0}; + + if (load_no_content) + { + load_no_content_hook = load_no_content; + + /* load_no_content gets set in this callback. */ + retro_set_environment(environ_cb_get_system_info); + + /* It's possible that we just set get_system_info callback + * to the currently running core. + * + * Make sure we reset it to the actual environment callback. + * Ignore any environment callbacks here in case we're running + * on the non-current core. */ + ignore_environment_cb = true; + retro_set_environment(rarch_environment_cb); + ignore_environment_cb = false; + } + + retro_get_system_info(&dummy_info); + memcpy(info, &dummy_info, sizeof(*info)); + + info->library_name = strdup(dummy_info.library_name); + info->library_version = strdup(dummy_info.library_version); + if (dummy_info.valid_extensions) + info->valid_extensions = strdup(dummy_info.valid_extensions); + return true; +} +#endif + +#ifdef HAVE_DYNAMIC /** * libretro_get_environment_info: * @func : Function pointer for get_environment_info. @@ -238,22 +290,6 @@ bool libretro_get_system_info(const char *path, return true; } -/** - * libretro_free_system_info: - * @info : Pointer to system info information. - * - * Frees system information. - **/ -void libretro_free_system_info(struct retro_system_info *info) -{ - if (!info) - return; - - free((void*)info->library_name); - free((void*)info->library_version); - free((void*)info->valid_extensions); - memset(info, 0, sizeof(*info)); -} static void load_dynamic_core(void) { settings_t *settings = config_get_ptr(); diff --git a/dynamic.h b/dynamic.h index c8c654bc75..570414be36 100644 --- a/dynamic.h +++ b/dynamic.h @@ -72,6 +72,21 @@ void libretro_get_environment_info(void (*)(retro_environment_t), **/ bool libretro_get_system_info(const char *path, struct retro_system_info *info, bool *load_no_content); +#else +/** + * libretro_get_system_info_static: + * @info : System info information. + * @load_no_content : If true, core should be able to auto-start + * without any content loaded. + * + * Gets system info from the current statically linked libretro library. + * The struct returned must be freed as strings are allocated dynamically. + * + * Returns: true (1) if successful, otherwise false (0). + **/ +bool libretro_get_system_info_static(struct retro_system_info *info, + bool *load_no_content); +#endif /** * libretro_free_system_info: @@ -80,7 +95,6 @@ bool libretro_get_system_info(const char *path, * Frees system information. **/ void libretro_free_system_info(struct retro_system_info *info); -#endif /** * libretro_get_current_core_pathname: diff --git a/menu/menu_driver.c b/menu/menu_driver.c index e9216c1e58..ccdb2416cb 100644 --- a/menu/menu_driver.c +++ b/menu/menu_driver.c @@ -423,10 +423,8 @@ bool menu_driver_ctl(enum rarch_menu_ctl_state state, void *data) } break; case RARCH_MENU_CTL_SYSTEM_INFO_DEINIT: -#ifdef HAVE_DYNAMIC libretro_free_system_info(&menu_driver_system); memset(&menu_driver_system, 0, sizeof(struct retro_system_info)); -#endif break; case RARCH_MENU_CTL_RENDER_MESSAGEBOX: if (menu_driver_ctx->render_messagebox)