RetroArch/dynamic.c

1666 lines
50 KiB
C
Raw Normal View History

2014-02-07 07:14:02 +00:00
/* RetroArch - A frontend for libretro.
2014-01-01 00:50:59 +00:00
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
2016-01-10 03:06:50 +00:00
* Copyright (C) 2011-2016 - Daniel De Matteis
*
2012-04-21 21:13:50 +00:00
* RetroArch is free software: you can redistribute it and/or modify it under the terms
2010-12-30 12:54:49 +00:00
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
2012-04-21 21:13:50 +00:00
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
2010-12-30 12:54:49 +00:00
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
2012-04-21 21:31:57 +00:00
* You should have received a copy of the GNU General Public License along with RetroArch.
2010-12-30 12:54:49 +00:00
* If not, see <http://www.gnu.org/licenses/>.
*/
2016-09-05 23:02:25 +00:00
#include <stdarg.h>
2010-12-30 12:54:49 +00:00
#include <string.h>
2013-03-22 19:56:23 +00:00
#include <ctype.h>
2011-01-07 16:59:53 +00:00
2016-02-05 12:51:30 +00:00
#include <boolean.h>
#include <file/file_path.h>
#include <compat/strl.h>
#include <compat/posix_string.h>
2015-12-05 19:26:37 +00:00
#include <dynamic/dylib.h>
#include <string/stdstring.h>
2016-02-05 12:51:30 +00:00
#include <retro_assert.h>
2015-09-15 03:22:57 +00:00
#include <features/features_cpu.h>
2011-01-07 16:59:53 +00:00
#ifdef HAVE_CONFIG_H
2010-12-30 12:54:49 +00:00
#include "config.h"
2011-01-07 16:59:53 +00:00
#endif
2016-09-08 03:48:43 +00:00
#ifdef HAVE_CHEEVOS
#include "cheevos.h"
#endif
2016-12-12 12:30:50 +00:00
#ifdef HAVE_NETWORKING
#include "network/netplay/netplay.h"
#endif
2016-03-22 01:56:06 +00:00
#include "dynamic.h"
2016-05-09 18:30:47 +00:00
#include "command.h"
2016-03-22 01:56:06 +00:00
2015-11-23 18:40:09 +00:00
#include "audio/audio_driver.h"
#include "camera/camera_driver.h"
#include "location/location_driver.h"
#include "record/record_driver.h"
2016-05-08 03:29:10 +00:00
#include "core.h"
2016-09-11 14:31:23 +00:00
#include "driver.h"
2016-05-10 06:53:14 +00:00
#include "performance_counters.h"
#include "gfx/video_context_driver.h"
#include "cores/internal_cores.h"
2015-12-24 20:17:44 +00:00
#include "frontend/frontend_driver.h"
2016-03-02 05:20:36 +00:00
#include "content.h"
2016-09-17 14:14:25 +00:00
#include "dirs.h"
2016-09-17 10:19:17 +00:00
#include "paths.h"
2015-01-09 16:40:47 +00:00
#include "retroarch.h"
2016-09-01 16:01:41 +00:00
#include "runloop.h"
2015-06-02 15:17:46 +00:00
#include "configuration.h"
2015-07-02 12:04:15 +00:00
#include "msg_hash.h"
2015-11-23 11:03:38 +00:00
#include "verbosity.h"
2010-12-30 12:54:49 +00:00
2012-04-05 09:47:43 +00:00
#ifdef HAVE_DYNAMIC
2015-09-15 03:22:57 +00:00
#define SYMBOL(x) do { \
2012-04-07 09:55:37 +00:00
function_t func = dylib_proc(lib_handle, #x); \
memcpy(&current_core->x, &func, sizeof(func)); \
2016-05-09 05:09:26 +00:00
if (current_core->x == NULL) { RARCH_ERR("Failed to load symbol: \"%s\"\n", #x); retroarch_fail(1, "init_libretro_sym()"); } \
2011-10-15 10:56:48 +00:00
} while (0)
2010-12-30 12:54:49 +00:00
2013-04-14 14:24:19 +00:00
static dylib_t lib_handle;
2012-04-05 09:47:43 +00:00
#else
#define SYMBOL(x) current_core->x = x
2011-01-19 12:25:18 +00:00
#endif
2010-12-30 12:54:49 +00:00
#define SYMBOL_DUMMY(x) current_core->x = libretro_dummy_##x
#ifdef HAVE_FFMPEG
#define SYMBOL_FFMPEG(x) current_core->x = libretro_ffmpeg_##x
#endif
2015-06-28 16:55:00 +00:00
#ifdef HAVE_IMAGEVIEWER
#define SYMBOL_IMAGEVIEWER(x) current_core->x = libretro_imageviewer_##x
2015-06-28 16:55:00 +00:00
#endif
2015-06-28 15:02:01 +00:00
2016-09-29 19:07:10 +00:00
#if defined(HAVE_NETWORKING) && defined(HAVE_NETWORKGAMEPAD)
#define SYMBOL_NETRETROPAD(x) current_core->x = libretro_netretropad_##x
#endif
2016-07-28 18:01:38 +00:00
#if defined(HAVE_VIDEO_PROCESSOR)
2016-07-28 17:10:18 +00:00
#define SYMBOL_VIDEOPROCESSOR(x) current_core->x = libretro_videoprocessor_##x
#endif
2016-09-08 12:11:32 +00:00
static bool ignore_environment_cb = false;
static bool *load_no_content_hook = NULL;
2014-09-23 01:07:33 +00:00
2016-01-25 06:02:26 +00:00
const struct retro_subsystem_info *libretro_find_subsystem_info(
const struct retro_subsystem_info *info, unsigned num_info,
const char *ident)
{
unsigned i;
for (i = 0; i < num_info; i++)
{
if (string_is_equal(info[i].ident, ident))
return &info[i];
else if (string_is_equal(info[i].desc, ident))
return &info[i];
}
return NULL;
}
/**
* libretro_find_controller_description:
* @info : Pointer to controller info handle.
* @id : Identifier of controller to search
* for.
*
* Search for a controller of type @id in @info.
*
* Returns: controller description of found controller on success,
* otherwise NULL.
**/
const struct retro_controller_description *
libretro_find_controller_description(
const struct retro_controller_info *info, unsigned id)
{
unsigned i;
for (i = 0; i < info->num_types; i++)
{
if (info->types[i].id != id)
continue;
return &info->types[i];
}
return NULL;
}
/**
* 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));
}
2014-09-02 03:57:53 +00:00
static bool environ_cb_get_system_info(unsigned cmd, void *data)
{
switch (cmd)
{
case RETRO_ENVIRONMENT_SET_SUPPORT_NO_GAME:
2014-07-28 17:37:25 +00:00
*load_no_content_hook = *(const bool*)data;
break;
default:
return false;
}
return true;
}
2016-09-12 17:58:05 +00:00
#ifdef HAVE_DYNAMIC
2016-09-16 23:45:24 +00:00
/**
* libretro_get_environment_info:
* @func : Function pointer for get_environment_info.
* @load_no_content : If true, core should be able to auto-start
* without any content loaded.
*
* Sets environment callback in order to get statically known
* information from it.
*
* Fetched via environment callbacks instead of
* retro_get_system_info(), as this info is part of extensions.
*
* Should only be called once right after core load to
* avoid overwriting the "real" environ callback.
*
* For statically linked cores, pass retro_set_environment as argument.
*/
void libretro_get_environment_info(void (*func)(retro_environment_t),
bool *load_no_content)
{
load_no_content_hook = load_no_content;
/* load_no_content gets set in this callback. */
func(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;
func(rarch_environment_cb);
ignore_environment_cb = false;
}
static bool load_dynamic_core(void)
2016-09-16 23:45:24 +00:00
{
function_t sym = dylib_proc(NULL, "retro_init");
if (sym)
{
/* Try to verify that -lretro was not linked in from other modules
* since loading it dynamically and with -l will fail hard. */
RARCH_ERR("Serious problem. RetroArch wants to load libretro cores"
2016-11-30 04:00:04 +00:00
" dynamically, but it is already linked.\n");
2016-09-16 23:45:24 +00:00
RARCH_ERR("This could happen if other modules RetroArch depends on "
"link against libretro directly.\n");
RARCH_ERR("Proceeding could cause a crash. Aborting ...\n");
retroarch_fail(1, "init_libretro_sym()");
}
2016-09-29 06:23:41 +00:00
if (string_is_empty(path_get(RARCH_PATH_CORE)))
2016-09-16 23:45:24 +00:00
{
RARCH_ERR("RetroArch is built for dynamic libretro cores, but "
"libretro_path is not set. Cannot continue.\n");
retroarch_fail(1, "init_libretro_sym()");
}
/* Need to use absolute path for this setting. It can be
* saved to content history, and a relative path would
* break in that scenario. */
path_resolve_realpath(
2016-10-03 13:46:07 +00:00
path_get_ptr(RARCH_PATH_CORE),
2016-10-03 14:16:55 +00:00
path_get_realsize(RARCH_PATH_CORE));
2016-09-16 23:45:24 +00:00
RARCH_LOG("Loading dynamic libretro core from: \"%s\"\n",
2016-09-29 06:23:41 +00:00
path_get(RARCH_PATH_CORE));
lib_handle = dylib_load(path_get(RARCH_PATH_CORE));
2016-12-15 11:11:21 +00:00
if (lib_handle)
return true;
RARCH_ERR("Failed to open libretro core: \"%s\"\n",
path_get(RARCH_PATH_CORE));
RARCH_ERR("Error(s): %s\n", dylib_error());
runloop_msg_queue_push(msg_hash_to_str(MSG_FAILED_TO_OPEN_LIBRETRO_CORE), 1, 180, true);
2016-12-15 11:11:21 +00:00
return false;
2016-09-16 23:45:24 +00:00
}
2016-09-12 17:58:05 +00:00
static dylib_t libretro_get_system_info_lib(const char *path,
struct retro_system_info *info, bool *load_no_content)
{
dylib_t lib = dylib_load(path);
void (*proc)(struct retro_system_info*);
if (!lib)
{
RARCH_ERR("%s: \"%s\"\n",
msg_hash_to_str(MSG_FAILED_TO_OPEN_LIBRETRO_CORE),
path);
RARCH_ERR("Error(s): %s\n", dylib_error());
return NULL;
}
proc = (void (*)(struct retro_system_info*))
dylib_proc(lib, "retro_get_system_info");
if (!proc)
{
dylib_close(lib);
return NULL;
}
proc(info);
if (load_no_content)
{
void (*set_environ)(retro_environment_t);
*load_no_content = false;
set_environ = (void (*)(retro_environment_t))
dylib_proc(lib, "retro_set_environment");
if (!set_environ)
return lib;
libretro_get_environment_info(set_environ, load_no_content);
}
return lib;
}
#else
2016-09-12 16:16:42 +00:00
static 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
2016-09-12 17:56:50 +00:00
/**
* libretro_get_system_info:
* @path : Path to libretro library.
* @info : Pointer to system info information.
* @load_no_content : If true, core should be able to auto-start
* without any content loaded.
*
* Gets system info from an arbitrary lib.
* The struct returned must be freed as strings are allocated dynamically.
*
* Returns: true (1) if successful, otherwise false (0).
**/
bool libretro_get_system_info(const char *path,
struct retro_system_info *info, bool *load_no_content)
{
#ifdef HAVE_DYNAMIC
struct retro_system_info dummy_info = {0};
2016-12-15 11:11:21 +00:00
dylib_t lib = libretro_get_system_info_lib(
path, &dummy_info, load_no_content);
2016-09-12 17:56:50 +00:00
if (!lib)
return false;
memcpy(info, &dummy_info, sizeof(*info));
2016-12-15 11:11:21 +00:00
info->library_name = strdup(dummy_info.library_name);
info->library_version = strdup(dummy_info.library_version);
2016-09-12 17:56:50 +00:00
if (dummy_info.valid_extensions)
info->valid_extensions = strdup(dummy_info.valid_extensions);
2016-12-15 11:11:21 +00:00
2016-09-12 17:56:50 +00:00
dylib_close(lib);
#else
2016-09-12 18:40:07 +00:00
if (!libretro_get_system_info_static(info, load_no_content))
return false;
2016-09-12 17:56:50 +00:00
#endif
2016-09-12 18:40:07 +00:00
return true;
2016-09-12 17:56:50 +00:00
}
2015-01-15 01:48:40 +00:00
/**
* load_symbols:
2015-06-20 21:42:30 +00:00
* @type : Type of core to be loaded.
* If CORE_TYPE_DUMMY, will
2015-06-20 21:42:30 +00:00
* load dummy symbols.
2015-01-15 01:48:40 +00:00
*
* Setup libretro callback symbols. Returns true on success,
* or false if symbols could not be loaded.
2015-01-15 01:48:40 +00:00
**/
static bool load_symbols(enum rarch_core_type type, struct retro_core_t *current_core)
2010-12-30 12:54:49 +00:00
{
2015-06-20 21:42:30 +00:00
switch (type)
{
2015-06-20 21:42:30 +00:00
case CORE_TYPE_PLAIN:
#ifdef HAVE_DYNAMIC
if (!load_dynamic_core())
return false;
2015-06-20 21:42:30 +00:00
#endif
2015-09-15 03:22:57 +00:00
SYMBOL(retro_init);
SYMBOL(retro_deinit);
2010-12-30 12:54:49 +00:00
2015-09-15 03:22:57 +00:00
SYMBOL(retro_api_version);
SYMBOL(retro_get_system_info);
SYMBOL(retro_get_system_av_info);
2010-12-30 12:54:49 +00:00
2015-09-15 03:22:57 +00:00
SYMBOL(retro_set_environment);
SYMBOL(retro_set_video_refresh);
SYMBOL(retro_set_audio_sample);
SYMBOL(retro_set_audio_sample_batch);
SYMBOL(retro_set_input_poll);
SYMBOL(retro_set_input_state);
2012-04-05 09:47:43 +00:00
2015-09-15 03:22:57 +00:00
SYMBOL(retro_set_controller_port_device);
2012-04-05 09:47:43 +00:00
2015-09-15 03:22:57 +00:00
SYMBOL(retro_reset);
SYMBOL(retro_run);
2012-04-05 09:47:43 +00:00
2015-09-15 03:22:57 +00:00
SYMBOL(retro_serialize_size);
SYMBOL(retro_serialize);
SYMBOL(retro_unserialize);
2012-04-05 09:47:43 +00:00
2015-09-15 03:22:57 +00:00
SYMBOL(retro_cheat_reset);
SYMBOL(retro_cheat_set);
2012-04-05 09:47:43 +00:00
2015-09-15 03:22:57 +00:00
SYMBOL(retro_load_game);
SYMBOL(retro_load_game_special);
2010-12-30 12:54:49 +00:00
2015-09-15 03:22:57 +00:00
SYMBOL(retro_unload_game);
SYMBOL(retro_get_region);
SYMBOL(retro_get_memory_data);
SYMBOL(retro_get_memory_size);
2015-06-20 21:42:30 +00:00
break;
case CORE_TYPE_DUMMY:
2015-09-15 03:22:57 +00:00
SYMBOL_DUMMY(retro_init);
SYMBOL_DUMMY(retro_deinit);
2013-04-14 14:24:19 +00:00
2015-09-15 03:22:57 +00:00
SYMBOL_DUMMY(retro_api_version);
SYMBOL_DUMMY(retro_get_system_info);
SYMBOL_DUMMY(retro_get_system_av_info);
2013-04-14 14:24:19 +00:00
2015-09-15 03:22:57 +00:00
SYMBOL_DUMMY(retro_set_environment);
SYMBOL_DUMMY(retro_set_video_refresh);
SYMBOL_DUMMY(retro_set_audio_sample);
SYMBOL_DUMMY(retro_set_audio_sample_batch);
SYMBOL_DUMMY(retro_set_input_poll);
SYMBOL_DUMMY(retro_set_input_state);
2013-04-14 14:24:19 +00:00
2015-09-15 03:22:57 +00:00
SYMBOL_DUMMY(retro_set_controller_port_device);
2013-04-14 14:24:19 +00:00
2015-09-15 03:22:57 +00:00
SYMBOL_DUMMY(retro_reset);
SYMBOL_DUMMY(retro_run);
2013-04-14 14:24:19 +00:00
2015-09-15 03:22:57 +00:00
SYMBOL_DUMMY(retro_serialize_size);
SYMBOL_DUMMY(retro_serialize);
SYMBOL_DUMMY(retro_unserialize);
2013-04-14 14:24:19 +00:00
2015-09-15 03:22:57 +00:00
SYMBOL_DUMMY(retro_cheat_reset);
SYMBOL_DUMMY(retro_cheat_set);
2013-04-14 14:24:19 +00:00
2015-09-15 03:22:57 +00:00
SYMBOL_DUMMY(retro_load_game);
SYMBOL_DUMMY(retro_load_game_special);
2013-04-14 14:24:19 +00:00
2015-09-15 03:22:57 +00:00
SYMBOL_DUMMY(retro_unload_game);
SYMBOL_DUMMY(retro_get_region);
SYMBOL_DUMMY(retro_get_memory_data);
SYMBOL_DUMMY(retro_get_memory_size);
2015-06-20 21:42:30 +00:00
break;
case CORE_TYPE_FFMPEG:
2016-01-25 06:04:54 +00:00
#ifdef HAVE_FFMPEG
2015-09-15 03:22:57 +00:00
SYMBOL_FFMPEG(retro_init);
SYMBOL_FFMPEG(retro_deinit);
2015-09-15 03:22:57 +00:00
SYMBOL_FFMPEG(retro_api_version);
SYMBOL_FFMPEG(retro_get_system_info);
SYMBOL_FFMPEG(retro_get_system_av_info);
2015-09-15 03:22:57 +00:00
SYMBOL_FFMPEG(retro_set_environment);
SYMBOL_FFMPEG(retro_set_video_refresh);
SYMBOL_FFMPEG(retro_set_audio_sample);
SYMBOL_FFMPEG(retro_set_audio_sample_batch);
SYMBOL_FFMPEG(retro_set_input_poll);
SYMBOL_FFMPEG(retro_set_input_state);
2015-09-15 03:22:57 +00:00
SYMBOL_FFMPEG(retro_set_controller_port_device);
2015-09-15 03:22:57 +00:00
SYMBOL_FFMPEG(retro_reset);
SYMBOL_FFMPEG(retro_run);
2015-09-15 03:22:57 +00:00
SYMBOL_FFMPEG(retro_serialize_size);
SYMBOL_FFMPEG(retro_serialize);
SYMBOL_FFMPEG(retro_unserialize);
2015-09-15 03:22:57 +00:00
SYMBOL_FFMPEG(retro_cheat_reset);
SYMBOL_FFMPEG(retro_cheat_set);
2015-09-15 03:22:57 +00:00
SYMBOL_FFMPEG(retro_load_game);
SYMBOL_FFMPEG(retro_load_game_special);
2015-09-15 03:22:57 +00:00
SYMBOL_FFMPEG(retro_unload_game);
SYMBOL_FFMPEG(retro_get_region);
SYMBOL_FFMPEG(retro_get_memory_data);
SYMBOL_FFMPEG(retro_get_memory_size);
#endif
2016-01-25 06:04:54 +00:00
break;
2015-06-28 15:02:01 +00:00
case CORE_TYPE_IMAGEVIEWER:
2015-06-28 16:55:00 +00:00
#ifdef HAVE_IMAGEVIEWER
2015-09-15 03:22:57 +00:00
SYMBOL_IMAGEVIEWER(retro_init);
SYMBOL_IMAGEVIEWER(retro_deinit);
2015-06-28 15:02:01 +00:00
2015-09-15 03:22:57 +00:00
SYMBOL_IMAGEVIEWER(retro_api_version);
SYMBOL_IMAGEVIEWER(retro_get_system_info);
SYMBOL_IMAGEVIEWER(retro_get_system_av_info);
2015-06-28 15:02:01 +00:00
2015-09-15 03:22:57 +00:00
SYMBOL_IMAGEVIEWER(retro_set_environment);
SYMBOL_IMAGEVIEWER(retro_set_video_refresh);
SYMBOL_IMAGEVIEWER(retro_set_audio_sample);
SYMBOL_IMAGEVIEWER(retro_set_audio_sample_batch);
SYMBOL_IMAGEVIEWER(retro_set_input_poll);
SYMBOL_IMAGEVIEWER(retro_set_input_state);
2015-06-28 15:02:01 +00:00
2015-09-15 03:22:57 +00:00
SYMBOL_IMAGEVIEWER(retro_set_controller_port_device);
2015-06-28 15:02:01 +00:00
2015-09-15 03:22:57 +00:00
SYMBOL_IMAGEVIEWER(retro_reset);
SYMBOL_IMAGEVIEWER(retro_run);
2015-06-28 15:02:01 +00:00
2015-09-15 03:22:57 +00:00
SYMBOL_IMAGEVIEWER(retro_serialize_size);
SYMBOL_IMAGEVIEWER(retro_serialize);
SYMBOL_IMAGEVIEWER(retro_unserialize);
2015-06-28 15:02:01 +00:00
2015-09-15 03:22:57 +00:00
SYMBOL_IMAGEVIEWER(retro_cheat_reset);
SYMBOL_IMAGEVIEWER(retro_cheat_set);
2015-06-28 15:02:01 +00:00
2015-09-15 03:22:57 +00:00
SYMBOL_IMAGEVIEWER(retro_load_game);
SYMBOL_IMAGEVIEWER(retro_load_game_special);
2015-06-28 15:02:01 +00:00
2015-09-15 03:22:57 +00:00
SYMBOL_IMAGEVIEWER(retro_unload_game);
SYMBOL_IMAGEVIEWER(retro_get_region);
SYMBOL_IMAGEVIEWER(retro_get_memory_data);
SYMBOL_IMAGEVIEWER(retro_get_memory_size);
#endif
break;
case CORE_TYPE_NETRETROPAD:
2016-09-29 19:07:10 +00:00
#if defined(HAVE_NETWORKING) && defined(HAVE_NETWORKGAMEPAD)
SYMBOL_NETRETROPAD(retro_init);
SYMBOL_NETRETROPAD(retro_deinit);
SYMBOL_NETRETROPAD(retro_api_version);
SYMBOL_NETRETROPAD(retro_get_system_info);
SYMBOL_NETRETROPAD(retro_get_system_av_info);
SYMBOL_NETRETROPAD(retro_set_environment);
SYMBOL_NETRETROPAD(retro_set_video_refresh);
SYMBOL_NETRETROPAD(retro_set_audio_sample);
SYMBOL_NETRETROPAD(retro_set_audio_sample_batch);
SYMBOL_NETRETROPAD(retro_set_input_poll);
SYMBOL_NETRETROPAD(retro_set_input_state);
SYMBOL_NETRETROPAD(retro_set_controller_port_device);
SYMBOL_NETRETROPAD(retro_reset);
SYMBOL_NETRETROPAD(retro_run);
SYMBOL_NETRETROPAD(retro_serialize_size);
SYMBOL_NETRETROPAD(retro_serialize);
SYMBOL_NETRETROPAD(retro_unserialize);
SYMBOL_NETRETROPAD(retro_cheat_reset);
SYMBOL_NETRETROPAD(retro_cheat_set);
SYMBOL_NETRETROPAD(retro_load_game);
SYMBOL_NETRETROPAD(retro_load_game_special);
SYMBOL_NETRETROPAD(retro_unload_game);
SYMBOL_NETRETROPAD(retro_get_region);
SYMBOL_NETRETROPAD(retro_get_memory_data);
SYMBOL_NETRETROPAD(retro_get_memory_size);
2016-07-28 17:10:18 +00:00
#endif
break;
2016-07-28 18:35:05 +00:00
case CORE_TYPE_VIDEO_PROCESSOR:
2016-07-28 18:01:38 +00:00
#if defined(HAVE_VIDEO_PROCESSOR)
2016-07-28 17:10:18 +00:00
SYMBOL_VIDEOPROCESSOR(retro_init);
SYMBOL_VIDEOPROCESSOR(retro_deinit);
SYMBOL_VIDEOPROCESSOR(retro_api_version);
SYMBOL_VIDEOPROCESSOR(retro_get_system_info);
SYMBOL_VIDEOPROCESSOR(retro_get_system_av_info);
SYMBOL_VIDEOPROCESSOR(retro_set_environment);
SYMBOL_VIDEOPROCESSOR(retro_set_video_refresh);
SYMBOL_VIDEOPROCESSOR(retro_set_audio_sample);
SYMBOL_VIDEOPROCESSOR(retro_set_audio_sample_batch);
SYMBOL_VIDEOPROCESSOR(retro_set_input_poll);
SYMBOL_VIDEOPROCESSOR(retro_set_input_state);
SYMBOL_VIDEOPROCESSOR(retro_set_controller_port_device);
SYMBOL_VIDEOPROCESSOR(retro_reset);
SYMBOL_VIDEOPROCESSOR(retro_run);
SYMBOL_VIDEOPROCESSOR(retro_serialize_size);
SYMBOL_VIDEOPROCESSOR(retro_serialize);
SYMBOL_VIDEOPROCESSOR(retro_unserialize);
SYMBOL_VIDEOPROCESSOR(retro_cheat_reset);
SYMBOL_VIDEOPROCESSOR(retro_cheat_set);
SYMBOL_VIDEOPROCESSOR(retro_load_game);
SYMBOL_VIDEOPROCESSOR(retro_load_game_special);
SYMBOL_VIDEOPROCESSOR(retro_unload_game);
SYMBOL_VIDEOPROCESSOR(retro_get_region);
SYMBOL_VIDEOPROCESSOR(retro_get_memory_data);
SYMBOL_VIDEOPROCESSOR(retro_get_memory_size);
2015-06-28 16:55:00 +00:00
#endif
2015-06-28 15:02:01 +00:00
break;
2013-04-28 02:21:52 +00:00
}
return true;
2013-04-14 14:24:19 +00:00
}
2015-01-09 20:30:07 +00:00
/**
* libretro_get_current_core_pathname:
* @name : Sanitized name of libretro core.
* @size : Size of @name
*
* Transforms a library id to a name suitable as a pathname.
**/
void libretro_get_current_core_pathname(char *name, size_t size)
{
size_t i;
2016-01-27 07:42:52 +00:00
struct retro_system_info info;
const char *id = msg_hash_to_str(MSG_UNKNOWN);
2015-01-09 20:30:07 +00:00
if (size == 0)
return;
2016-05-07 23:33:57 +00:00
core_get_system_info(&info);
2016-01-27 07:59:54 +00:00
2016-01-27 07:42:52 +00:00
if (info.library_name)
id = info.library_name;
if (!id || strlen(id) >= size)
{
name[0] = '\0';
return;
}
name[strlen(id)] = '\0';
for (i = 0; id[i] != '\0'; i++)
{
char c = id[i];
2015-01-15 01:48:40 +00:00
2015-09-05 12:34:33 +00:00
if (isspace((int)c) || isblank((int)c))
name[i] = '_';
else
2015-09-05 12:34:33 +00:00
name[i] = tolower((int)c);
}
}
2015-01-15 01:48:40 +00:00
/**
* init_libretro_sym:
2015-06-20 21:42:30 +00:00
* @type : Type of core to be loaded.
* If CORE_TYPE_DUMMY, will
2015-06-20 21:42:30 +00:00
* load dummy symbols.
2015-01-15 01:48:40 +00:00
*
* Initializes libretro symbols and
* setups environment callback functions. Returns true on success,
* or false if symbols could not be loaded.
2015-01-15 01:48:40 +00:00
**/
bool init_libretro_sym(enum rarch_core_type type, struct retro_core_t *current_core)
2010-12-30 12:54:49 +00:00
{
2014-09-02 03:57:53 +00:00
/* Guarantee that we can do "dirty" casting.
* Every OS that this program supports should pass this. */
retro_assert(sizeof(void*) == sizeof(void (*)(void)));
if (!load_symbols(type, current_core))
return false;
return true;
2010-12-30 12:54:49 +00:00
}
2015-01-15 01:48:40 +00:00
/**
* uninit_libretro_sym:
*
* Frees libretro core.
*
* Frees all core options,
* associated state, and
* unbind all libretro callback symbols.
**/
2016-01-28 02:36:14 +00:00
void uninit_libretro_sym(struct retro_core_t *current_core)
2010-12-30 12:54:49 +00:00
{
2011-12-04 16:54:00 +00:00
#ifdef HAVE_DYNAMIC
2010-12-30 12:54:49 +00:00
if (lib_handle)
2011-03-07 18:12:14 +00:00
dylib_close(lib_handle);
2013-04-14 14:24:19 +00:00
lib_handle = NULL;
2011-03-07 18:12:14 +00:00
#endif
2016-01-28 05:30:12 +00:00
memset(current_core, 0, sizeof(struct retro_core_t));
2015-12-07 12:56:33 +00:00
runloop_ctl(RUNLOOP_CTL_CORE_OPTIONS_DEINIT, NULL);
2015-12-07 12:56:33 +00:00
runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_FREE, NULL);
2016-04-06 00:30:20 +00:00
runloop_ctl(RUNLOOP_CTL_FRAME_TIME_FREE, NULL);
2015-12-05 13:39:52 +00:00
camera_driver_ctl(RARCH_CAMERA_CTL_UNSET_ACTIVE, NULL);
2015-12-05 14:40:29 +00:00
location_driver_ctl(RARCH_LOCATION_CTL_UNSET_ACTIVE, NULL);
2014-09-02 03:57:53 +00:00
/* Performance counters no longer valid. */
2016-05-16 08:00:50 +00:00
performance_counters_clear();
2011-03-07 18:12:14 +00:00
}
2014-09-02 03:57:53 +00:00
static void rarch_log_libretro(enum retro_log_level level,
const char *fmt, ...)
{
2015-01-09 20:30:07 +00:00
va_list vp;
2015-03-20 18:48:23 +00:00
settings_t *settings = config_get_ptr();
if ((unsigned)level < settings->libretro_log_level)
return;
va_start(vp, fmt);
switch (level)
{
case RETRO_LOG_DEBUG:
RARCH_LOG_V("[libretro DEBUG]", fmt, vp);
break;
case RETRO_LOG_INFO:
RARCH_LOG_OUTPUT_V("[libretro INFO]", fmt, vp);
break;
case RETRO_LOG_WARN:
RARCH_WARN_V("[libretro WARN]", fmt, vp);
break;
case RETRO_LOG_ERROR:
RARCH_ERR_V("[libretro ERROR]", fmt, vp);
break;
default:
break;
}
va_end(vp);
}
static size_t mmap_add_bits_down(size_t n)
{
2016-05-10 19:47:14 +00:00
n |= n >> 1;
n |= n >> 2;
n |= n >> 4;
n |= n >> 8;
n |= n >> 16;
/* double shift to avoid warnings on 32bit (it's dead code, but compilers suck) */
2016-05-10 19:47:14 +00:00
if (sizeof(size_t) > 4)
n |= n >> 16 >> 16;
2016-05-10 19:47:14 +00:00
return n;
}
static size_t mmap_inflate(size_t addr, size_t mask)
{
2016-05-10 19:47:14 +00:00
while (mask)
{
size_t tmp = (mask - 1) & ~mask;
2016-09-08 12:11:32 +00:00
/* to put in an 1 bit instead, OR in tmp+1 */
2016-09-08 12:11:32 +00:00
addr = ((addr & ~tmp) << 1) | (addr & tmp);
mask = mask & (mask - 1);
}
return addr;
}
static size_t mmap_reduce(size_t addr, size_t mask)
{
while (mask)
{
size_t tmp = (mask - 1) & ~mask;
2016-09-08 12:11:32 +00:00
addr = (addr & tmp) | ((addr >> 1) & ~tmp);
mask = (mask & (mask - 1)) >> 1;
}
return addr;
}
static size_t mmap_highest_bit(size_t n)
{
n = mmap_add_bits_down(n);
return n ^ (n >> 1);
}
static bool mmap_preprocess_descriptors(rarch_memory_descriptor_t *first, unsigned count)
{
size_t top_addr = 1;
rarch_memory_descriptor_t *desc = NULL;
const rarch_memory_descriptor_t *end = first + count;
for (desc = first; desc < end; desc++)
{
if (desc->core.select != 0)
top_addr |= desc->core.select;
else
top_addr |= desc->core.start + desc->core.len - 1;
}
top_addr = mmap_add_bits_down(top_addr);
for (desc = first; desc < end; desc++)
{
if (desc->core.select == 0)
{
if (desc->core.len == 0)
return false;
if ((desc->core.len & (desc->core.len - 1)) != 0)
return false;
2016-12-15 11:11:21 +00:00
desc->core.select = top_addr & ~mmap_inflate(mmap_add_bits_down(desc->core.len - 1),
desc->core.disconnect);
}
if (desc->core.len == 0)
2016-12-15 11:11:21 +00:00
desc->core.len = mmap_add_bits_down(mmap_reduce(top_addr & ~desc->core.select,
desc->core.disconnect)) + 1;
if (desc->core.start & ~desc->core.select)
return false;
while (mmap_reduce(top_addr & ~desc->core.select, desc->core.disconnect) >> 1 > desc->core.len - 1)
desc->core.disconnect |= mmap_highest_bit(top_addr & ~desc->core.select & ~desc->core.disconnect);
desc->disconnect_mask = mmap_add_bits_down(desc->core.len - 1);
desc->core.disconnect &= desc->disconnect_mask;
while ((~desc->disconnect_mask) >> 1 & desc->core.disconnect)
{
desc->disconnect_mask >>= 1;
desc->core.disconnect &= desc->disconnect_mask;
}
}
return true;
}
2016-08-31 01:34:34 +00:00
static bool dynamic_request_hw_context(enum retro_hw_context_type type,
unsigned minor, unsigned major)
{
switch (type)
{
case RETRO_HW_CONTEXT_NONE:
RARCH_LOG("Requesting no HW context.\n");
break;
case RETRO_HW_CONTEXT_VULKAN:
#ifdef HAVE_VULKAN
RARCH_LOG("Requesting Vulkan context.\n");
break;
#else
RARCH_ERR("Requesting Vulkan context, but RetroArch is not compiled against Vulkan. Cannot use HW context.\n");
return false;
#endif
#if defined(HAVE_OPENGLES)
#if (defined(HAVE_OPENGLES2) || defined(HAVE_OPENGLES3))
case RETRO_HW_CONTEXT_OPENGLES2:
case RETRO_HW_CONTEXT_OPENGLES3:
RARCH_LOG("Requesting OpenGLES%u context.\n",
type == RETRO_HW_CONTEXT_OPENGLES2 ? 2 : 3);
break;
#if defined(HAVE_OPENGLES3)
case RETRO_HW_CONTEXT_OPENGLES_VERSION:
RARCH_LOG("Requesting OpenGLES%u.%u context.\n",
major, minor);
break;
#endif
#endif
case RETRO_HW_CONTEXT_OPENGL:
case RETRO_HW_CONTEXT_OPENGL_CORE:
RARCH_ERR("Requesting OpenGL context, but RetroArch "
"is compiled against OpenGLES. Cannot use HW context.\n");
return false;
#elif defined(HAVE_OPENGL)
case RETRO_HW_CONTEXT_OPENGLES2:
case RETRO_HW_CONTEXT_OPENGLES3:
RARCH_ERR("Requesting OpenGLES%u context, but RetroArch "
"is compiled against OpenGL. Cannot use HW context.\n",
type == RETRO_HW_CONTEXT_OPENGLES2 ? 2 : 3);
return false;
case RETRO_HW_CONTEXT_OPENGLES_VERSION:
RARCH_ERR("Requesting OpenGLES%u.%u context, but RetroArch "
"is compiled against OpenGL. Cannot use HW context.\n",
major, minor);
return false;
case RETRO_HW_CONTEXT_OPENGL:
RARCH_LOG("Requesting OpenGL context.\n");
break;
case RETRO_HW_CONTEXT_OPENGL_CORE:
{
gfx_ctx_flags_t flags;
flags.flags = 0;
BIT32_SET(flags.flags, GFX_CTX_FLAGS_GL_CORE_CONTEXT);
video_context_driver_set_flags(&flags);
RARCH_LOG("Requesting core OpenGL context (%u.%u).\n",
major, minor);
}
break;
#endif
default:
RARCH_LOG("Requesting unknown context.\n");
return false;
}
return true;
}
static bool dynamic_verify_hw_context(enum retro_hw_context_type type,
unsigned minor, unsigned major)
{
const char *video_ident = video_driver_get_ident();
switch (type)
{
case RETRO_HW_CONTEXT_VULKAN:
if (!string_is_equal(video_ident, "vulkan"))
return false;
break;
case RETRO_HW_CONTEXT_OPENGLES2:
case RETRO_HW_CONTEXT_OPENGLES3:
case RETRO_HW_CONTEXT_OPENGLES_VERSION:
case RETRO_HW_CONTEXT_OPENGL:
case RETRO_HW_CONTEXT_OPENGL_CORE:
if (!string_is_equal(video_ident, "gl"))
return false;
break;
default:
break;
}
return true;
}
2015-01-15 01:48:40 +00:00
/**
* rarch_environment_cb:
* @cmd : Identifier of command.
* @data : Pointer to data.
*
* Environment callback function implementation.
*
* Returns: true (1) if environment callback command could
* be performed, otherwise false (0).
**/
bool rarch_environment_cb(unsigned cmd, void *data)
{
2014-12-05 13:29:40 +00:00
unsigned p;
settings_t *settings = config_get_ptr();
rarch_system_info_t *system = NULL;
2015-12-10 21:30:25 +00:00
runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &system);
2014-09-21 12:33:51 +00:00
if (ignore_environment_cb)
return false;
switch (cmd)
{
2012-04-07 09:55:37 +00:00
case RETRO_ENVIRONMENT_GET_OVERSCAN:
2015-03-20 18:48:23 +00:00
*(bool*)data = !settings->video.crop_overscan;
2014-09-02 03:57:53 +00:00
RARCH_LOG("Environ GET_OVERSCAN: %u\n",
2015-03-20 18:48:23 +00:00
(unsigned)!settings->video.crop_overscan);
2011-11-09 21:18:48 +00:00
break;
2012-04-07 09:55:37 +00:00
case RETRO_ENVIRONMENT_GET_CAN_DUPE:
2011-11-22 16:27:02 +00:00
*(bool*)data = true;
2012-04-21 21:25:32 +00:00
RARCH_LOG("Environ GET_CAN_DUPE: true\n");
2011-12-02 18:12:47 +00:00
break;
2012-04-07 09:55:37 +00:00
case RETRO_ENVIRONMENT_GET_VARIABLE:
if (!runloop_ctl(RUNLOOP_CTL_CORE_OPTIONS_GET, data))
{
struct retro_variable *var = (struct retro_variable*)data;
2016-12-15 11:11:21 +00:00
if (var)
{
2015-12-26 00:16:33 +00:00
RARCH_LOG("Environ GET_VARIABLE %s: not implemented.\n", var->key);
var->value = NULL;
}
}
break;
2013-04-04 11:58:30 +00:00
case RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE:
*(bool*)data = runloop_ctl(RUNLOOP_CTL_IS_CORE_OPTION_UPDATED, NULL);
2013-04-04 11:58:30 +00:00
break;
2012-04-07 09:55:37 +00:00
case RETRO_ENVIRONMENT_SET_VARIABLES:
2013-04-04 11:58:30 +00:00
RARCH_LOG("Environ SET_VARIABLES.\n");
2012-02-06 15:13:29 +00:00
runloop_ctl(RUNLOOP_CTL_CORE_OPTIONS_DEINIT, NULL);
2015-12-07 13:16:34 +00:00
runloop_ctl(RUNLOOP_CTL_CORE_OPTIONS_INIT, data);
2013-04-04 11:58:30 +00:00
2012-02-06 15:13:29 +00:00
break;
2012-04-07 09:55:37 +00:00
case RETRO_ENVIRONMENT_SET_MESSAGE:
2012-03-11 23:37:44 +00:00
{
2012-04-07 09:55:37 +00:00
const struct retro_message *msg = (const struct retro_message*)data;
2012-04-21 21:25:32 +00:00
RARCH_LOG("Environ SET_MESSAGE: %s\n", msg->msg);
runloop_msg_queue_push(msg->msg, 3, msg->frames, true);
2012-03-11 23:37:44 +00:00
break;
}
2012-04-07 09:55:37 +00:00
case RETRO_ENVIRONMENT_SET_ROTATION:
2012-03-30 17:09:34 +00:00
{
unsigned rotation = *(const unsigned*)data;
2012-04-21 21:25:32 +00:00
RARCH_LOG("Environ SET_ROTATION: %u\n", rotation);
2015-03-20 18:48:23 +00:00
if (!settings->video.allow_rotate)
2012-04-01 14:12:04 +00:00
break;
2016-06-30 15:40:19 +00:00
if (system)
system->rotation = rotation;
2012-04-01 17:20:37 +00:00
2015-03-22 09:38:26 +00:00
if (!video_driver_set_rotation(rotation))
2012-03-30 17:09:34 +00:00
return false;
break;
}
2012-05-22 18:14:07 +00:00
case RETRO_ENVIRONMENT_SHUTDOWN:
RARCH_LOG("Environ SHUTDOWN.\n");
runloop_ctl(RUNLOOP_CTL_SET_SHUTDOWN, NULL);
2015-11-30 20:42:59 +00:00
runloop_ctl(RUNLOOP_CTL_SET_CORE_SHUTDOWN, NULL);
2012-05-22 18:14:07 +00:00
break;
case RETRO_ENVIRONMENT_SET_PERFORMANCE_LEVEL:
2016-06-30 15:40:19 +00:00
if (system)
{
system->performance_level = *(const unsigned*)data;
RARCH_LOG("Environ PERFORMANCE_LEVEL: %u.\n",
system->performance_level);
}
break;
case RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY:
2016-04-28 17:26:02 +00:00
if (string_is_empty(settings->directory.system))
{
2016-10-03 13:39:48 +00:00
const char *fullpath = path_get(RARCH_PATH_CONTENT);
if (!string_is_empty(fullpath))
{
2016-12-19 18:04:52 +00:00
char temp_path[PATH_MAX_LENGTH];
temp_path[0] = '\0';
2016-09-17 14:14:25 +00:00
RARCH_WARN("SYSTEM DIR is empty, assume CONTENT DIR %s\n",
fullpath);
2016-09-17 14:14:25 +00:00
fill_pathname_basedir(temp_path, fullpath, sizeof(temp_path));
2016-10-03 06:20:33 +00:00
dir_set(RARCH_DIR_SYSTEM, temp_path);
}
2016-10-03 06:15:41 +00:00
*(const char**)data = dir_get_ptr(RARCH_DIR_SYSTEM);
RARCH_LOG("Environ SYSTEM_DIRECTORY: \"%s\".\n",
2016-10-03 06:15:41 +00:00
dir_get(RARCH_DIR_SYSTEM));
}
else
{
2016-04-28 17:26:02 +00:00
*(const char**)data = settings->directory.system;
RARCH_LOG("Environ SYSTEM_DIRECTORY: \"%s\".\n",
2016-04-28 17:26:02 +00:00
settings->directory.system);
}
break;
2014-02-07 07:14:02 +00:00
case RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY:
2016-10-03 06:15:41 +00:00
*(const char**)data = dir_get(RARCH_DIR_CURRENT_SAVEFILE);
break;
2014-08-01 02:37:00 +00:00
case RETRO_ENVIRONMENT_GET_USERNAME:
2015-03-20 18:48:23 +00:00
*(const char**)data = *settings->username ?
settings->username : NULL;
2014-09-02 03:57:53 +00:00
RARCH_LOG("Environ GET_USERNAME: \"%s\".\n",
2015-03-20 18:48:23 +00:00
settings->username);
2014-08-01 02:37:00 +00:00
break;
case RETRO_ENVIRONMENT_GET_LANGUAGE:
2016-06-07 04:05:41 +00:00
#ifdef HAVE_LANGEXTRA
2015-03-20 18:48:23 +00:00
*(unsigned *)data = settings->user_language;
RARCH_LOG("Environ GET_LANGUAGE: \"%u\".\n",
2015-03-20 18:48:23 +00:00
settings->user_language);
2016-06-07 04:05:41 +00:00
#endif
break;
2012-06-16 13:07:31 +00:00
case RETRO_ENVIRONMENT_SET_PIXEL_FORMAT:
{
enum retro_pixel_format pix_fmt =
2014-09-02 03:57:53 +00:00
*(const enum retro_pixel_format*)data;
2012-06-16 13:07:31 +00:00
switch (pix_fmt)
{
case RETRO_PIXEL_FORMAT_0RGB1555:
RARCH_LOG("Environ SET_PIXEL_FORMAT: 0RGB1555.\n");
break;
case RETRO_PIXEL_FORMAT_RGB565:
RARCH_LOG("Environ SET_PIXEL_FORMAT: RGB565.\n");
break;
2012-06-16 13:07:31 +00:00
case RETRO_PIXEL_FORMAT_XRGB8888:
RARCH_LOG("Environ SET_PIXEL_FORMAT: XRGB8888.\n");
break;
default:
return false;
}
2015-05-20 18:59:12 +00:00
video_driver_set_pixel_format(pix_fmt);
2012-06-16 13:07:31 +00:00
break;
}
case RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS:
{
2016-06-30 15:40:19 +00:00
static const char *libretro_btn_desc[] = {
2015-06-26 15:46:13 +00:00
"B (bottom)", "Y (left)", "Select", "Start",
"D-Pad Up", "D-Pad Down", "D-Pad Left", "D-Pad Right",
"A (right)", "X (up)",
"L", "R", "L2", "R2", "L3", "R3",
};
if (system)
{
unsigned retro_id;
const struct retro_input_descriptor *desc = NULL;
memset(&system->input_desc_btn, 0,
sizeof(system->input_desc_btn));
2014-09-02 03:57:53 +00:00
desc = (const struct retro_input_descriptor*)data;
for (; desc->description; desc++)
{
unsigned retro_port = desc->port;
2016-01-26 04:06:11 +00:00
retro_id = desc->id;
2015-01-15 01:48:40 +00:00
if (desc->port >= MAX_USERS)
continue;
/* Ignore all others for now. */
if (desc->device != RETRO_DEVICE_JOYPAD &&
desc->device != RETRO_DEVICE_ANALOG)
continue;
if (desc->id >= RARCH_FIRST_CUSTOM_BIND)
continue;
if (desc->device == RETRO_DEVICE_ANALOG)
{
switch (retro_id)
{
case RETRO_DEVICE_ID_ANALOG_X:
switch (desc->index)
{
case RETRO_DEVICE_INDEX_ANALOG_LEFT:
system->input_desc_btn[retro_port]
[RARCH_ANALOG_LEFT_X_PLUS] = desc->description;
system->input_desc_btn[retro_port]
[RARCH_ANALOG_LEFT_X_MINUS] = desc->description;
break;
case RETRO_DEVICE_INDEX_ANALOG_RIGHT:
system->input_desc_btn[retro_port]
[RARCH_ANALOG_RIGHT_X_PLUS] = desc->description;
system->input_desc_btn[retro_port]
[RARCH_ANALOG_RIGHT_X_MINUS] = desc->description;
break;
}
break;
case RETRO_DEVICE_ID_ANALOG_Y:
switch (desc->index)
{
case RETRO_DEVICE_INDEX_ANALOG_LEFT:
system->input_desc_btn[retro_port]
[RARCH_ANALOG_LEFT_Y_PLUS] = desc->description;
system->input_desc_btn[retro_port]
[RARCH_ANALOG_LEFT_Y_MINUS] = desc->description;
break;
case RETRO_DEVICE_INDEX_ANALOG_RIGHT:
system->input_desc_btn[retro_port]
[RARCH_ANALOG_RIGHT_Y_PLUS] = desc->description;
system->input_desc_btn[retro_port]
[RARCH_ANALOG_RIGHT_Y_MINUS] = desc->description;
break;
}
break;
}
}
else
system->input_desc_btn[retro_port]
[retro_id] = desc->description;
}
RARCH_LOG("Environ SET_INPUT_DESCRIPTORS:\n");
for (p = 0; p < settings->input.max_users; p++)
{
for (retro_id = 0; retro_id < RARCH_FIRST_CUSTOM_BIND; retro_id++)
{
const char *description = system->input_desc_btn[p][retro_id];
2015-01-09 20:30:07 +00:00
if (!description)
continue;
2015-01-15 01:48:40 +00:00
RARCH_LOG("\tRetroPad, User %u, Button \"%s\" => \"%s\"\n",
p + 1, libretro_btn_desc[retro_id], description);
}
}
core_set_input_descriptors();
}
break;
}
case RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK:
{
retro_keyboard_event_t *frontend_key_event = NULL;
retro_keyboard_event_t *key_event = NULL;
const struct retro_keyboard_callback *info =
2014-09-02 03:57:53 +00:00
(const struct retro_keyboard_callback*)data;
2015-01-09 20:30:07 +00:00
runloop_ctl(RUNLOOP_CTL_FRONTEND_KEY_EVENT_GET, &frontend_key_event);
2015-12-13 13:31:06 +00:00
runloop_ctl(RUNLOOP_CTL_KEY_EVENT_GET, &key_event);
2015-01-09 20:30:07 +00:00
RARCH_LOG("Environ SET_KEYBOARD_CALLBACK.\n");
if (key_event)
*key_event = info->callback;
if (frontend_key_event && key_event)
*frontend_key_event = *key_event;
break;
}
case RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE:
RARCH_LOG("Environ SET_DISK_CONTROL_INTERFACE.\n");
2016-06-30 15:40:19 +00:00
if (system)
system->disk_control_cb =
*(const struct retro_disk_control_callback*)data;
break;
2013-03-27 15:15:15 +00:00
case RETRO_ENVIRONMENT_SET_HW_RENDER:
2014-09-02 03:57:53 +00:00
case RETRO_ENVIRONMENT_SET_HW_RENDER | RETRO_ENVIRONMENT_EXPERIMENTAL:
2013-03-27 15:15:15 +00:00
{
struct retro_hw_render_callback *cb =
2014-09-02 03:57:53 +00:00
(struct retro_hw_render_callback*)data;
2016-08-31 01:34:34 +00:00
struct retro_hw_render_callback *hwr =
video_driver_get_hw_context();
2015-01-09 20:30:07 +00:00
RARCH_LOG("Environ SET_HW_RENDER.\n");
2016-08-31 01:34:34 +00:00
if (!dynamic_request_hw_context(cb->context_type, cb->version_minor, cb->version_major))
return false;
if (!dynamic_verify_hw_context(cb->context_type, cb->version_minor, cb->version_major))
return false;
cb->get_current_framebuffer = video_driver_get_current_framebuffer;
cb->get_proc_address = video_driver_get_proc_address;
2016-01-26 04:03:41 +00:00
/* Old ABI. Don't copy garbage. */
if (cmd & RETRO_ENVIRONMENT_EXPERIMENTAL)
memcpy(hwr,
2014-09-02 03:57:53 +00:00
cb, offsetof(struct retro_hw_render_callback, stencil));
else
memcpy(hwr, cb, sizeof(*cb));
2013-03-27 15:15:15 +00:00
break;
}
case RETRO_ENVIRONMENT_SET_SUPPORT_NO_GAME:
{
bool state = *(const bool*)data;
RARCH_LOG("Environ SET_SUPPORT_NO_GAME: %s.\n", state ? "yes" : "no");
2016-03-02 05:20:36 +00:00
if (state)
2016-05-08 03:17:31 +00:00
content_set_does_not_need_content();
2016-03-02 05:20:36 +00:00
else
2016-05-08 03:17:31 +00:00
content_unset_does_not_need_content();
break;
}
case RETRO_ENVIRONMENT_GET_LIBRETRO_PATH:
{
const char **path = (const char**)data;
#ifdef HAVE_DYNAMIC
2016-09-29 06:23:41 +00:00
*path = path_get(RARCH_PATH_CORE);
#else
*path = NULL;
#endif
break;
}
case RETRO_ENVIRONMENT_SET_AUDIO_CALLBACK:
#ifdef HAVE_THREADS
{
2015-06-26 15:46:13 +00:00
RARCH_LOG("Environ SET_AUDIO_CALLBACK.\n");
2016-12-12 12:30:50 +00:00
#ifdef HAVE_NETWORKING
if (netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_ENABLED, NULL))
return false;
#endif
if (recording_driver_get_data_ptr()) /* A/V sync is a must. */
return false;
2016-05-08 14:45:58 +00:00
audio_driver_set_callback(data);
}
#endif
break;
case RETRO_ENVIRONMENT_SET_FRAME_TIME_CALLBACK:
2013-07-14 11:43:01 +00:00
{
RARCH_LOG("Environ SET_FRAME_TIME_CALLBACK.\n");
runloop_ctl(RUNLOOP_CTL_SET_FRAME_TIME, data);
break;
2013-07-14 11:43:01 +00:00
}
case RETRO_ENVIRONMENT_GET_RUMBLE_INTERFACE:
{
struct retro_rumble_interface *iface =
2014-09-02 03:57:53 +00:00
(struct retro_rumble_interface*)data;
2015-01-09 20:30:07 +00:00
RARCH_LOG("Environ GET_RUMBLE_INTERFACE.\n");
iface->set_rumble_state = input_driver_set_rumble_state;
break;
}
case RETRO_ENVIRONMENT_GET_INPUT_DEVICE_CAPABILITIES:
{
uint64_t *mask = (uint64_t*)data;
2015-01-09 20:30:07 +00:00
RARCH_LOG("Environ GET_INPUT_DEVICE_CAPABILITIES.\n");
2016-05-08 21:12:04 +00:00
if (input_driver_has_capabilities())
2015-03-23 03:18:27 +00:00
*mask = input_driver_get_capabilities();
else
return false;
break;
}
case RETRO_ENVIRONMENT_GET_SENSOR_INTERFACE:
{
struct retro_sensor_interface *iface =
2014-09-02 03:57:53 +00:00
(struct retro_sensor_interface*)data;
2015-01-09 20:30:07 +00:00
RARCH_LOG("Environ GET_SENSOR_INTERFACE.\n");
2015-01-18 18:28:51 +00:00
iface->set_sensor_state = input_sensor_set_state;
iface->get_sensor_input = input_sensor_get_input;
break;
}
case RETRO_ENVIRONMENT_GET_CAMERA_INTERFACE:
{
2014-09-02 03:57:53 +00:00
struct retro_camera_callback *cb =
(struct retro_camera_callback*)data;
2015-01-09 20:30:07 +00:00
RARCH_LOG("Environ GET_CAMERA_INTERFACE.\n");
2016-03-04 17:16:07 +00:00
cb->start = driver_camera_start;
cb->stop = driver_camera_stop;
camera_driver_ctl(RARCH_CAMERA_CTL_SET_CB, cb);
2015-12-05 13:39:52 +00:00
if (cb->caps != 0)
camera_driver_ctl(RARCH_CAMERA_CTL_SET_ACTIVE, NULL);
else
camera_driver_ctl(RARCH_CAMERA_CTL_UNSET_ACTIVE, NULL);
break;
}
case RETRO_ENVIRONMENT_GET_LOCATION_INTERFACE:
{
2014-09-02 03:57:53 +00:00
struct retro_location_callback *cb =
(struct retro_location_callback*)data;
2015-01-09 20:30:07 +00:00
RARCH_LOG("Environ GET_LOCATION_INTERFACE.\n");
cb->start = driver_location_start;
cb->stop = driver_location_stop;
cb->get_position = driver_location_get_position;
cb->set_interval = driver_location_set_interval;
2016-06-30 15:40:19 +00:00
if (system)
system->location_cb = *cb;
2015-12-05 14:40:29 +00:00
location_driver_ctl(RARCH_LOCATION_CTL_UNSET_ACTIVE, NULL);
break;
}
case RETRO_ENVIRONMENT_GET_LOG_INTERFACE:
{
struct retro_log_callback *cb = (struct retro_log_callback*)data;
2015-01-09 20:30:07 +00:00
RARCH_LOG("Environ GET_LOG_INTERFACE.\n");
cb->log = rarch_log_libretro;
break;
}
case RETRO_ENVIRONMENT_GET_PERF_INTERFACE:
{
struct retro_perf_callback *cb = (struct retro_perf_callback*)data;
2015-01-09 20:30:07 +00:00
RARCH_LOG("Environ GET_PERF_INTERFACE.\n");
2016-05-10 07:17:04 +00:00
cb->get_time_usec = cpu_features_get_time_usec;
cb->get_cpu_features = cpu_features_get;
cb->get_perf_counter = cpu_features_get_perf_counter;
2016-01-26 04:03:41 +00:00
cb->perf_register = performance_counter_register;
cb->perf_start = performance_counter_start;
2016-05-16 07:48:14 +00:00
cb->perf_stop = performance_counter_stop;
2016-01-26 04:03:41 +00:00
cb->perf_log = retro_perf_log;
break;
}
case RETRO_ENVIRONMENT_GET_CORE_ASSETS_DIRECTORY:
{
const char **dir = (const char**)data;
2015-01-09 20:30:07 +00:00
2016-04-28 17:26:02 +00:00
*dir = *settings->directory.core_assets ?
settings->directory.core_assets : NULL;
RARCH_LOG("Environ CORE_ASSETS_DIRECTORY: \"%s\".\n",
2016-04-28 17:26:02 +00:00
settings->directory.core_assets);
break;
}
case RETRO_ENVIRONMENT_SET_SYSTEM_AV_INFO:
{
RARCH_LOG("Environ SET_SYSTEM_AV_INFO.\n");
return driver_ctl(RARCH_DRIVER_CTL_UPDATE_SYSTEM_AV_INFO,
(void**)&data);
}
case RETRO_ENVIRONMENT_SET_SUBSYSTEM_INFO:
2014-04-04 12:58:42 +00:00
{
2014-04-04 14:02:53 +00:00
unsigned i, j;
const struct retro_subsystem_info *info =
2014-09-02 03:57:53 +00:00
(const struct retro_subsystem_info*)data;
2015-01-09 20:30:07 +00:00
RARCH_LOG("Environ SET_SUBSYSTEM_INFO.\n");
2014-04-04 12:58:42 +00:00
for (i = 0; info[i].ident; i++)
2014-04-04 14:02:53 +00:00
{
RARCH_LOG("Special game type: %s\n", info[i].desc);
RARCH_LOG(" Ident: %s\n", info[i].ident);
RARCH_LOG(" ID: %u\n", info[i].id);
2014-07-28 18:01:27 +00:00
RARCH_LOG(" Content:\n");
2014-04-04 14:02:53 +00:00
for (j = 0; j < info[i].num_roms; j++)
{
RARCH_LOG(" %s (%s)\n",
2014-09-02 03:57:53 +00:00
info[i].roms[j].desc, info[i].roms[j].required ?
"required" : "optional");
2014-04-04 14:02:53 +00:00
}
}
2014-04-04 12:58:42 +00:00
2016-06-30 15:40:19 +00:00
if (system)
{
2016-12-25 01:05:34 +00:00
struct retro_subsystem_info *info_ptr = NULL;
2016-06-30 15:40:19 +00:00
free(system->subsystem.data);
2016-12-25 01:05:34 +00:00
system->subsystem.data = NULL;
2014-09-02 03:57:53 +00:00
2016-12-25 01:05:34 +00:00
info_ptr = (struct retro_subsystem_info*)
calloc(i, sizeof(*info_ptr));
if (!info_ptr)
2016-06-30 15:40:19 +00:00
return false;
2014-04-04 12:58:42 +00:00
2016-12-25 01:05:34 +00:00
system->subsystem.data = info_ptr;
2016-06-30 15:40:19 +00:00
memcpy(system->subsystem.data, info,
i * sizeof(*system->subsystem.data));
system->subsystem.size = i;
}
2014-04-04 12:58:42 +00:00
break;
}
case RETRO_ENVIRONMENT_SET_CONTROLLER_INFO:
{
unsigned i, j;
const struct retro_controller_info *info =
2014-09-02 03:57:53 +00:00
(const struct retro_controller_info*)data;
2015-01-09 20:30:07 +00:00
RARCH_LOG("Environ SET_CONTROLLER_INFO.\n");
for (i = 0; info[i].types; i++)
{
2014-04-12 17:06:37 +00:00
RARCH_LOG("Controller port: %u\n", i + 1);
for (j = 0; j < info[i].num_types; j++)
2014-09-02 03:57:53 +00:00
RARCH_LOG(" %s (ID: %u)\n", info[i].types[j].desc,
info[i].types[j].id);
}
2016-06-30 15:38:16 +00:00
if (system)
{
2016-12-25 01:05:34 +00:00
struct retro_controller_info *info_ptr = NULL;
2016-06-30 15:38:16 +00:00
free(system->ports.data);
2016-12-25 01:05:34 +00:00
system->ports.data = NULL;
info_ptr = (struct retro_controller_info*)calloc(i, sizeof(*info_ptr));
if (!info_ptr)
2016-06-30 15:38:16 +00:00
return false;
2016-12-25 01:05:34 +00:00
system->ports.data = info_ptr;
2016-06-30 15:38:16 +00:00
memcpy(system->ports.data, info,
i * sizeof(*system->ports.data));
system->ports.size = i;
}
break;
}
case RETRO_ENVIRONMENT_SET_MEMORY_MAPS:
{
if (system)
{
unsigned i;
const struct retro_memory_map *mmaps =
(const struct retro_memory_map*)data;
rarch_memory_descriptor_t *descriptors = NULL;
RARCH_LOG("Environ SET_MEMORY_MAPS.\n");
free((void*)system->mmaps.descriptors);
system->mmaps.num_descriptors = 0;
descriptors = (rarch_memory_descriptor_t*)
calloc(mmaps->num_descriptors,
sizeof(*descriptors));
if (!descriptors)
return false;
2016-12-25 01:05:34 +00:00
system->mmaps.descriptors = descriptors;
system->mmaps.num_descriptors = mmaps->num_descriptors;
for (i = 0; i < mmaps->num_descriptors; i++)
system->mmaps.descriptors[i].core = mmaps->descriptors[i];
mmap_preprocess_descriptors(descriptors, mmaps->num_descriptors);
if (sizeof(void *) == 8)
RARCH_LOG(" ndx flags ptr offset start select disconn len addrspace\n");
else
RARCH_LOG(" ndx flags ptr offset start select disconn len addrspace\n");
for (i = 0; i < system->mmaps.num_descriptors; i++)
{
const rarch_memory_descriptor_t *desc =
&system->mmaps.descriptors[i];
char flags[7];
flags[0] = 'M';
if ((desc->core.flags & RETRO_MEMDESC_MINSIZE_8) == RETRO_MEMDESC_MINSIZE_8)
flags[1] = '8';
else if ((desc->core.flags & RETRO_MEMDESC_MINSIZE_4) == RETRO_MEMDESC_MINSIZE_4)
flags[1] = '4';
else if ((desc->core.flags & RETRO_MEMDESC_MINSIZE_2) == RETRO_MEMDESC_MINSIZE_2)
flags[1] = '2';
else
flags[1] = '1';
flags[2] = 'A';
if ((desc->core.flags & RETRO_MEMDESC_ALIGN_8) == RETRO_MEMDESC_ALIGN_8)
flags[3] = '8';
else if ((desc->core.flags & RETRO_MEMDESC_ALIGN_4) == RETRO_MEMDESC_ALIGN_4)
flags[3] = '4';
else if ((desc->core.flags & RETRO_MEMDESC_ALIGN_2) == RETRO_MEMDESC_ALIGN_2)
flags[3] = '2';
else
flags[3] = '1';
flags[4] = (desc->core.flags & RETRO_MEMDESC_BIGENDIAN) ? 'B' : 'b';
flags[5] = (desc->core.flags & RETRO_MEMDESC_CONST) ? 'C' : 'c';
flags[6] = 0;
RARCH_LOG(" %03u %s %p %08X %08X %08X %08X %08X %s\n",
i + 1, flags, desc->core.ptr, desc->core.offset, desc->core.start,
desc->core.select, desc->core.disconnect, desc->core.len,
desc->core.addrspace ? desc->core.addrspace : "");
}
}
else
{
RARCH_WARN("Environ SET_MEMORY_MAPS, but system pointer not initialized..\n");
}
break;
}
2014-06-07 11:19:28 +00:00
case RETRO_ENVIRONMENT_SET_GEOMETRY:
{
2016-01-26 04:03:41 +00:00
const struct retro_game_geometry *in_geom = NULL;
struct retro_game_geometry *geom = NULL;
struct retro_system_av_info *av_info =
video_viewport_get_system_av_info();
if (av_info)
geom = (struct retro_game_geometry*)&av_info->geometry;
2014-06-07 11:19:28 +00:00
2015-09-28 14:20:26 +00:00
if (!geom)
return false;
2016-01-26 04:03:41 +00:00
in_geom = (const struct retro_game_geometry*)data;
2015-01-09 20:30:07 +00:00
RARCH_LOG("Environ SET_GEOMETRY.\n");
2014-09-02 03:57:53 +00:00
/* Can potentially be called every frame,
* don't do anything unless required. */
2014-06-07 11:19:28 +00:00
if (geom->base_width != in_geom->base_width ||
geom->base_height != in_geom->base_height ||
geom->aspect_ratio != in_geom->aspect_ratio)
{
geom->base_width = in_geom->base_width;
geom->base_height = in_geom->base_height;
geom->aspect_ratio = in_geom->aspect_ratio;
2016-01-26 04:03:41 +00:00
2014-06-07 11:19:28 +00:00
RARCH_LOG("SET_GEOMETRY: %ux%u, aspect: %.3f.\n",
geom->base_width, geom->base_height, geom->aspect_ratio);
/* Forces recomputation of aspect ratios if
2014-09-02 03:57:53 +00:00
* using core-dependent aspect ratios. */
2016-05-09 18:51:53 +00:00
command_event(CMD_EVENT_VIDEO_SET_ASPECT_RATIO, NULL);
2014-09-02 03:57:53 +00:00
/* TODO: Figure out what to do, if anything, with recording. */
2014-06-07 11:19:28 +00:00
}
break;
}
case RETRO_ENVIRONMENT_GET_CURRENT_SOFTWARE_FRAMEBUFFER:
2016-05-08 12:00:51 +00:00
return video_driver_get_current_software_framebuffer(
2016-01-26 04:06:11 +00:00
(struct retro_framebuffer*)data);
2016-02-16 19:24:00 +00:00
case RETRO_ENVIRONMENT_GET_HW_RENDER_INTERFACE:
2016-05-08 12:00:51 +00:00
return video_driver_get_hw_render_interface(
2016-02-16 19:24:00 +00:00
(const struct retro_hw_render_interface**)data);
case RETRO_ENVIRONMENT_SET_SUPPORT_ACHIEVEMENTS:
2016-05-13 02:41:46 +00:00
#ifdef HAVE_CHEEVOS
{
bool state = *(const bool*)data;
RARCH_LOG("Environ SET_SUPPORT_ACHIEVEMENTS: %s.\n", state ? "yes" : "no");
cheevos_set_support_cheevos(state);
}
2016-05-13 02:41:46 +00:00
#endif
break;
case RETRO_ENVIRONMENT_SET_HW_RENDER_CONTEXT_NEGOTIATION_INTERFACE:
{
const struct retro_hw_render_context_negotiation_interface *iface =
(const struct retro_hw_render_context_negotiation_interface*)data;
RARCH_LOG("Environ SET_HW_RENDER_CONTEXT_NEGOTIATION_INTERFACE.\n");
video_driver_set_context_negotiation_interface(iface);
break;
}
2016-02-16 19:24:00 +00:00
case RETRO_ENVIRONMENT_SET_SERIALIZATION_QUIRKS:
2016-09-30 22:36:02 +00:00
{
uint64_t *quirks = (uint64_t *) data;
core_set_serialization_quirks(*quirks);
break;
2016-09-30 22:36:02 +00:00
}
/* Default */
default:
2012-04-21 21:25:32 +00:00
RARCH_LOG("Environ UNSUPPORTED (#%u).\n", cmd);
return false;
}
return true;
}