RetroArch/dynamic.c

769 lines
22 KiB
C
Raw Normal View History

2012-04-21 21:13:50 +00:00
/* RetroArch - A frontend for libretro.
2013-01-01 00:37:37 +00:00
* Copyright (C) 2010-2013 - Hans-Kristian Arntzen
2010-12-30 12:54:49 +00:00
*
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/>.
*/
#include "dynamic.h"
#include "general.h"
2012-03-16 22:26:57 +00:00
#include "compat/strl.h"
#include "compat/posix_string.h"
#include "file.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
2012-04-21 21:25:32 +00:00
#ifdef RARCH_CONSOLE
#include "console/rarch_console.h"
2012-03-11 23:37:44 +00:00
#endif
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
2011-12-24 12:46:12 +00:00
#include "boolean.h"
2012-04-07 09:55:37 +00:00
#include "libretro.h"
2013-04-14 14:24:19 +00:00
#include "dynamic_dummy.h"
2010-12-30 12:54:49 +00:00
#ifdef NEED_DYNAMIC
2011-01-19 12:25:18 +00:00
#ifdef _WIN32
#include <windows.h>
#else
#include <dlfcn.h>
2011-03-07 18:12:14 +00:00
#endif
2011-12-01 20:54:42 +00:00
#endif
2011-03-07 18:12:14 +00:00
2012-04-05 09:47:43 +00:00
#ifdef HAVE_DYNAMIC
2013-07-05 17:29:48 +00:00
#undef SYM
2012-04-05 09:47:43 +00:00
#define SYM(x) do { \
2012-04-07 09:55:37 +00:00
function_t func = dylib_proc(lib_handle, #x); \
2012-04-05 09:47:43 +00:00
memcpy(&p##x, &func, sizeof(func)); \
2012-04-21 21:25:32 +00:00
if (p##x == NULL) { RARCH_ERR("Failed to load symbol: \"%s\"\n", #x); rarch_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 SYM(x) p##x = x
2011-01-19 12:25:18 +00:00
#endif
2010-12-30 12:54:49 +00:00
2013-04-14 14:24:19 +00:00
#define SYM_DUMMY(x) p##x = libretro_dummy_##x
2012-04-05 09:47:43 +00:00
void (*pretro_init)(void);
void (*pretro_deinit)(void);
2010-12-30 12:54:49 +00:00
2012-04-05 09:47:43 +00:00
unsigned (*pretro_api_version)(void);
2010-12-30 12:54:49 +00:00
2012-04-05 09:47:43 +00:00
void (*pretro_get_system_info)(struct retro_system_info*);
void (*pretro_get_system_av_info)(struct retro_system_av_info*);
2010-12-30 12:54:49 +00:00
2012-04-05 09:47:43 +00:00
void (*pretro_set_environment)(retro_environment_t);
void (*pretro_set_video_refresh)(retro_video_refresh_t);
void (*pretro_set_audio_sample)(retro_audio_sample_t);
void (*pretro_set_audio_sample_batch)(retro_audio_sample_batch_t);
void (*pretro_set_input_poll)(retro_input_poll_t);
void (*pretro_set_input_state)(retro_input_state_t);
2011-04-17 11:30:59 +00:00
2012-04-09 22:37:09 +00:00
void (*pretro_set_controller_port_device)(unsigned, unsigned);
2010-12-30 12:54:49 +00:00
2012-04-05 09:47:43 +00:00
void (*pretro_reset)(void);
void (*pretro_run)(void);
2012-04-05 09:47:43 +00:00
size_t (*pretro_serialize_size)(void);
bool (*pretro_serialize)(void*, size_t);
bool (*pretro_unserialize)(const void*, size_t);
2010-12-30 12:54:49 +00:00
2012-04-05 09:47:43 +00:00
void (*pretro_cheat_reset)(void);
void (*pretro_cheat_set)(unsigned, bool, const char*);
2012-04-07 09:55:37 +00:00
bool (*pretro_load_game)(const struct retro_game_info*);
bool (*pretro_load_game_special)(unsigned, const struct retro_game_info*, size_t);
2010-12-30 12:54:49 +00:00
2012-04-05 09:47:43 +00:00
void (*pretro_unload_game)(void);
2010-12-30 12:54:49 +00:00
2012-04-05 09:47:43 +00:00
unsigned (*pretro_get_region)(void);
2010-12-30 12:54:49 +00:00
2012-04-05 09:47:43 +00:00
void *(*pretro_get_memory_data)(unsigned);
size_t (*pretro_get_memory_size)(unsigned);
2010-12-30 12:54:49 +00:00
2013-04-14 14:24:19 +00:00
static bool environment_cb(unsigned cmd, void *data);
2012-10-14 18:09:26 +00:00
#ifdef HAVE_DYNAMIC
#if defined(__APPLE__)
#define DYNAMIC_EXT "dylib"
#elif defined(_WIN32)
#define DYNAMIC_EXT "dll"
#else
#define DYNAMIC_EXT "so"
#endif
static bool *load_no_rom_hook;
static bool environ_cb_get_system_info(unsigned cmd, void *data)
{
switch (cmd)
{
case RETRO_ENVIRONMENT_SET_SUPPORT_NO_GAME:
*load_no_rom_hook = *(const bool*)data;
break;
default:
return false;
}
return true;
}
void libretro_get_environment_info(void (*func)(retro_environment_t), bool *load_no_rom)
{
load_no_rom_hook = load_no_rom;
// load_no_rom gets set in this callback.
func(environ_cb_get_system_info);
}
static dylib_t libretro_get_system_info_lib(const char *path, struct retro_system_info *info, bool *load_no_rom)
2013-03-17 19:08:24 +00:00
{
dylib_t lib = dylib_load(path);
if (!lib)
return NULL;
void (*proc)(struct retro_system_info*) =
(void (*)(struct retro_system_info*))dylib_proc(lib, "retro_get_system_info");
if (!proc)
{
dylib_close(lib);
return NULL;
}
proc(info);
if (load_no_rom)
{
*load_no_rom = false;
void (*set_environ)(retro_environment_t) =
(void (*)(retro_environment_t))dylib_proc(lib, "retro_set_environment");
if (!set_environ)
return lib;
libretro_get_environment_info(set_environ, load_no_rom);
}
2013-03-17 19:08:24 +00:00
return lib;
}
bool libretro_get_system_info(const char *path, struct retro_system_info *info,
bool *load_no_rom)
2013-03-17 19:08:24 +00:00
{
struct retro_system_info dummy_info = {0};
dylib_t lib = libretro_get_system_info_lib(path, &dummy_info, load_no_rom);
2013-03-17 19:08:24 +00:00
if (!lib)
return false;
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);
2013-03-17 19:08:24 +00:00
dylib_close(lib);
return true;
}
void libretro_free_system_info(struct retro_system_info *info)
{
free((void*)info->library_name);
free((void*)info->library_version);
free((void*)info->valid_extensions);
memset(info, 0, sizeof(*info));
}
static bool find_first_libretro(char *path, size_t size,
const char *dir, const char *rom_path)
{
bool ret = false;
const char *ext = path_get_extension(rom_path);
if (!ext || !*ext)
{
RARCH_ERR("Path has no extension. Cannot infer libretro implementation.\n");
return false;
}
RARCH_LOG("Searching for valid libretro implementation in: \"%s\".\n", dir);
struct string_list *list = dir_list_new(dir, DYNAMIC_EXT, false);
if (!list)
{
RARCH_ERR("Couldn't open directory: \"%s\".\n", dir);
return false;
}
for (size_t i = 0; i < list->size && !ret; i++)
{
RARCH_LOG("Checking library: \"%s\".\n", list->elems[i].data);
struct retro_system_info info = {0};
dylib_t lib = libretro_get_system_info_lib(list->elems[i].data, &info, NULL);
2013-03-17 19:08:24 +00:00
if (!lib)
continue;
if (!info.valid_extensions)
{
dylib_close(lib);
continue;
}
struct string_list *supported_ext = string_split(info.valid_extensions, "|");
if (string_list_find_elem(supported_ext, ext))
{
strlcpy(path, list->elems[i].data, size);
ret = true;
}
string_list_free(supported_ext);
dylib_close(lib);
}
dir_list_free(list);
return ret;
}
2012-10-14 18:09:26 +00:00
#endif
2013-04-28 02:21:52 +00:00
static void load_symbols(bool is_dummy)
2010-12-30 12:54:49 +00:00
{
2013-04-28 02:21:52 +00:00
if (is_dummy)
{
2013-04-28 02:21:52 +00:00
SYM_DUMMY(retro_init);
SYM_DUMMY(retro_deinit);
2013-04-28 02:21:52 +00:00
SYM_DUMMY(retro_api_version);
SYM_DUMMY(retro_get_system_info);
SYM_DUMMY(retro_get_system_av_info);
2010-12-30 12:54:49 +00:00
2013-04-28 02:21:52 +00:00
SYM_DUMMY(retro_set_environment);
SYM_DUMMY(retro_set_video_refresh);
SYM_DUMMY(retro_set_audio_sample);
SYM_DUMMY(retro_set_audio_sample_batch);
SYM_DUMMY(retro_set_input_poll);
SYM_DUMMY(retro_set_input_state);
2010-12-30 12:54:49 +00:00
2013-04-28 02:21:52 +00:00
SYM_DUMMY(retro_set_controller_port_device);
2012-04-05 09:47:43 +00:00
2013-04-28 02:21:52 +00:00
SYM_DUMMY(retro_reset);
SYM_DUMMY(retro_run);
2012-04-05 09:47:43 +00:00
2013-04-28 02:21:52 +00:00
SYM_DUMMY(retro_serialize_size);
SYM_DUMMY(retro_serialize);
SYM_DUMMY(retro_unserialize);
2012-04-05 09:47:43 +00:00
2013-04-28 02:21:52 +00:00
SYM_DUMMY(retro_cheat_reset);
SYM_DUMMY(retro_cheat_set);
2012-04-05 09:47:43 +00:00
2013-04-28 02:21:52 +00:00
SYM_DUMMY(retro_load_game);
SYM_DUMMY(retro_load_game_special);
2012-04-05 09:47:43 +00:00
2013-04-28 02:21:52 +00:00
SYM_DUMMY(retro_unload_game);
SYM_DUMMY(retro_get_region);
SYM_DUMMY(retro_get_memory_data);
SYM_DUMMY(retro_get_memory_size);
}
else
{
#ifdef HAVE_DYNAMIC
if (path_is_directory(g_settings.libretro))
{
char libretro_core_buffer[PATH_MAX];
2013-04-28 02:21:52 +00:00
if (!find_first_libretro(libretro_core_buffer, sizeof(libretro_core_buffer),
g_settings.libretro, g_extern.fullpath))
{
RARCH_ERR("libretro_path is a directory, but no valid libretro implementation was found.\n");
rarch_fail(1, "load_dynamic()");
}
strlcpy(g_settings.libretro, libretro_core_buffer, sizeof(g_settings.libretro));
2013-04-28 02:21:52 +00:00
}
2012-04-05 09:47:43 +00:00
// Need to use absolute path for this setting. It can be saved to ROM history,
// and a relative path would break in that scenario.
path_resolve_realpath(g_settings.libretro, sizeof(g_settings.libretro));
RARCH_LOG("Loading dynamic libretro from: \"%s\"\n", g_settings.libretro);
lib_handle = dylib_load(g_settings.libretro);
2013-04-28 02:21:52 +00:00
if (!lib_handle)
{
RARCH_ERR("Failed to open dynamic library: \"%s\"\n", g_settings.libretro);
2013-04-28 02:21:52 +00:00
rarch_fail(1, "load_dynamic()");
}
#endif
2010-12-30 12:54:49 +00:00
2013-04-28 02:21:52 +00:00
SYM(retro_init);
SYM(retro_deinit);
2013-04-14 14:24:19 +00:00
2013-04-28 02:21:52 +00:00
SYM(retro_api_version);
SYM(retro_get_system_info);
SYM(retro_get_system_av_info);
2013-04-14 14:24:19 +00:00
2013-04-28 02:21:52 +00:00
SYM(retro_set_environment);
SYM(retro_set_video_refresh);
SYM(retro_set_audio_sample);
SYM(retro_set_audio_sample_batch);
SYM(retro_set_input_poll);
SYM(retro_set_input_state);
2013-04-14 14:24:19 +00:00
2013-04-28 02:21:52 +00:00
SYM(retro_set_controller_port_device);
2013-04-14 14:24:19 +00:00
2013-04-28 02:21:52 +00:00
SYM(retro_reset);
SYM(retro_run);
2013-04-14 14:24:19 +00:00
2013-04-28 02:21:52 +00:00
SYM(retro_serialize_size);
SYM(retro_serialize);
SYM(retro_unserialize);
2013-04-14 14:24:19 +00:00
2013-04-28 02:21:52 +00:00
SYM(retro_cheat_reset);
SYM(retro_cheat_set);
2013-04-14 14:24:19 +00:00
2013-04-28 02:21:52 +00:00
SYM(retro_load_game);
SYM(retro_load_game_special);
2013-04-14 14:24:19 +00:00
2013-04-28 02:21:52 +00:00
SYM(retro_unload_game);
SYM(retro_get_region);
SYM(retro_get_memory_data);
SYM(retro_get_memory_size);
}
2013-04-14 14:24:19 +00:00
}
void libretro_get_current_core_pathname(char *name, size_t size)
{
if (size == 0)
return;
struct retro_system_info info = {0};
2013-03-22 19:56:23 +00:00
pretro_get_system_info(&info);
const char *id = info.library_name ? info.library_name : "Unknown";
if (!id || strlen(id) >= size)
{
name[0] = '\0';
return;
}
name[strlen(id)] = '\0';
for (size_t i = 0; id[i] != '\0'; i++)
{
char c = id[i];
if (isspace(c) || isblank(c))
name[i] = '_';
else
name[i] = tolower(c);
}
}
2013-04-14 14:24:19 +00:00
void init_libretro_sym(bool dummy)
2010-12-30 12:54:49 +00:00
{
// Guarantee that we can do "dirty" casting.
// Every OS that this program supports should pass this ...
2012-04-21 21:25:32 +00:00
rarch_assert(sizeof(void*) == sizeof(void (*)(void)));
2013-04-28 02:21:52 +00:00
if (!dummy)
{
2013-04-14 14:24:19 +00:00
#ifdef HAVE_DYNAMIC
// Try to verify that -lretro was not linked in from other modules
// since loading it dynamically and with -l will fail hard.
function_t sym = dylib_proc(NULL, "retro_init");
if (sym)
{
RARCH_ERR("Serious problem. RetroArch wants to load libretro dyamically, but it is already linked.\n");
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");
rarch_fail(1, "init_libretro_sym()");
}
2013-04-14 14:24:19 +00:00
if (!*g_settings.libretro)
{
RARCH_ERR("RetroArch is built for dynamic libretro, but libretro_path is not set. Cannot continue.\n");
rarch_fail(1, "init_libretro_sym()");
}
#endif
2013-04-14 14:24:19 +00:00
}
2013-04-28 02:21:52 +00:00
load_symbols(dummy);
2013-04-14 14:24:19 +00:00
pretro_set_environment(environment_cb);
2010-12-30 12:54:49 +00:00
}
2012-04-07 10:17:40 +00:00
void uninit_libretro_sym(void)
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
if (g_extern.system.core_options)
{
core_option_flush(g_extern.system.core_options);
core_option_free(g_extern.system.core_options);
}
// No longer valid.
memset(&g_extern.system, 0, sizeof(g_extern.system));
2011-03-07 18:12:14 +00:00
}
#ifdef NEED_DYNAMIC
2011-03-07 18:12:14 +00:00
// Platform independent dylib loading.
dylib_t dylib_load(const char *path)
{
2011-01-19 12:25:18 +00:00
#ifdef _WIN32
dylib_t lib = LoadLibrary(path);
if (!lib)
2012-04-21 21:25:32 +00:00
RARCH_ERR("Failed to load library, error code: 0x%x\n", (unsigned)GetLastError());
return lib;
2011-01-19 12:25:18 +00:00
#else
2012-10-03 21:33:17 +00:00
dylib_t lib = dlopen(path, RTLD_LAZY);
if (!lib)
RARCH_ERR("dylib_load() failed: \"%s\".\n", dlerror());
return lib;
2011-01-19 12:25:18 +00:00
#endif
2011-03-07 18:12:14 +00:00
}
function_t dylib_proc(dylib_t lib, const char *proc)
2011-03-07 18:12:14 +00:00
{
#ifdef _WIN32
2011-12-24 12:46:12 +00:00
function_t sym = (function_t)GetProcAddress(lib ? (HMODULE)lib : GetModuleHandle(NULL), proc);
2011-03-07 18:12:14 +00:00
#else
void *ptr_sym = NULL;
if (lib)
ptr_sym = dlsym(lib, proc);
else
{
void *handle = dlopen(NULL, RTLD_LAZY);
if (handle)
{
ptr_sym = dlsym(handle, proc);
dlclose(handle);
}
}
2011-11-02 18:34:08 +00:00
// Dirty hack to workaround the non-legality of (void*) -> fn-pointer casts.
function_t sym;
memcpy(&sym, &ptr_sym, sizeof(void*));
2011-03-07 18:12:14 +00:00
#endif
2011-03-07 18:56:40 +00:00
return sym;
2011-03-07 18:12:14 +00:00
}
void dylib_close(dylib_t lib)
{
#ifdef _WIN32
2011-12-24 12:46:12 +00:00
FreeLibrary((HMODULE)lib);
2011-03-07 18:12:14 +00:00
#else
dlclose(lib);
2010-12-30 12:54:49 +00:00
#endif
}
2012-01-02 14:42:53 +00:00
#endif
2011-03-07 18:12:14 +00:00
static bool environment_cb(unsigned cmd, void *data)
{
switch (cmd)
{
2012-04-07 09:55:37 +00:00
case RETRO_ENVIRONMENT_GET_OVERSCAN:
2011-11-09 21:18:48 +00:00
*(bool*)data = !g_settings.video.crop_overscan;
2012-04-21 21:25:32 +00:00
RARCH_LOG("Environ GET_OVERSCAN: %u\n", (unsigned)!g_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:
{
2012-04-07 09:55:37 +00:00
struct retro_variable *var = (struct retro_variable*)data;
2013-04-04 11:58:30 +00:00
RARCH_LOG("Environ GET_VARIABLE %s:\n", var->key);
2013-04-04 11:58:30 +00:00
if (g_extern.system.core_options)
core_option_get(g_extern.system.core_options, var);
else
var->value = NULL;
RARCH_LOG("\t%s\n", var->value ? var->value : "N/A");
break;
}
2013-04-04 11:58:30 +00:00
case RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE:
*(bool*)data = g_extern.system.core_options ?
core_option_updated(g_extern.system.core_options) : false;
break;
2012-04-07 09:55:37 +00:00
case RETRO_ENVIRONMENT_SET_VARIABLES:
2012-02-06 15:13:29 +00:00
{
2013-04-04 11:58:30 +00:00
RARCH_LOG("Environ SET_VARIABLES.\n");
2012-02-06 15:13:29 +00:00
2013-04-04 11:58:30 +00:00
if (g_extern.system.core_options)
{
core_option_flush(g_extern.system.core_options);
core_option_free(g_extern.system.core_options);
2012-02-06 15:13:29 +00:00
}
2013-04-04 11:58:30 +00:00
const struct retro_variable *vars = (const struct retro_variable*)data;
2013-05-12 19:21:19 +00:00
const char *options_path = g_settings.core_options_path;
char buf[PATH_MAX];
if (!*options_path && *g_extern.config_path)
{
fill_pathname_resolve_relative(buf, g_extern.config_path, ".retroarch-core-options.cfg", sizeof(buf));
options_path = buf;
}
g_extern.system.core_options = core_option_new(options_path, vars);
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);
2012-03-11 23:37:44 +00:00
if (g_extern.msg_queue)
{
msg_queue_clear(g_extern.msg_queue);
2012-03-11 23:37:44 +00:00
msg_queue_push(g_extern.msg_queue, msg->msg, 1, msg->frames);
}
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);
2012-04-01 14:12:04 +00:00
if (!g_settings.video.allow_rotate)
break;
2012-04-01 17:20:37 +00:00
g_extern.system.rotation = rotation;
if (driver.video && driver.video->set_rotation)
{
if (driver.video_data)
video_set_rotation_func(rotation);
}
2012-03-30 17:09:34 +00:00
else
return false;
break;
}
2012-05-22 18:14:07 +00:00
case RETRO_ENVIRONMENT_SHUTDOWN:
RARCH_LOG("Environ SHUTDOWN.\n");
2012-05-22 18:14:07 +00:00
g_extern.system.shutdown = true;
break;
case RETRO_ENVIRONMENT_SET_PERFORMANCE_LEVEL:
g_extern.system.performance_level = *(const unsigned*)data;
RARCH_LOG("Environ PERFORMANCE_LEVEL: %u.\n", g_extern.system.performance_level);
break;
case RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY:
*(const char **)data = *g_settings.system_directory ? g_settings.system_directory : NULL;
RARCH_LOG("Environ SYSTEM_DIRECTORY: \"%s\".\n", g_settings.system_directory);
break;
2012-06-16 13:07:31 +00:00
case RETRO_ENVIRONMENT_SET_PIXEL_FORMAT:
{
enum retro_pixel_format pix_fmt = *(const enum retro_pixel_format*)data;
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;
}
g_extern.system.pix_fmt = pix_fmt;
2012-06-16 13:07:31 +00:00
break;
}
case RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS:
{
memset(g_extern.system.input_desc_btn, 0, sizeof(g_extern.system.input_desc_btn));
const struct retro_input_descriptor *desc = (const struct retro_input_descriptor*)data;
for (; desc->description; desc++)
{
if (desc->port >= MAX_PLAYERS)
continue;
if (desc->device != RETRO_DEVICE_JOYPAD) // Ignore all others for now.
continue;
2012-10-01 20:15:48 +00:00
if (desc->id >= RARCH_FIRST_CUSTOM_BIND)
continue;
g_extern.system.input_desc_btn[desc->port][desc->id] = desc->description;
}
static const char *libretro_btn_desc[] = {
"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",
};
RARCH_LOG("Environ SET_INPUT_DESCRIPTORS:\n");
for (unsigned p = 0; p < MAX_PLAYERS; p++)
{
2012-10-01 20:15:48 +00:00
for (unsigned id = 0; id < RARCH_FIRST_CUSTOM_BIND; id++)
{
const char *desc = g_extern.system.input_desc_btn[p][id];
if (desc)
{
RARCH_LOG("\tRetroPad, Player %u, Button \"%s\" => \"%s\"\n",
p + 1, libretro_btn_desc[id], desc);
}
}
}
break;
}
case RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK:
{
RARCH_LOG("Environ SET_KEYBOARD_CALLBACK.\n");
const struct retro_keyboard_callback *info = (const struct retro_keyboard_callback*)data;
g_extern.system.key_event = info->callback;
break;
}
case RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE:
RARCH_LOG("Environ SET_DISK_CONTROL_INTERFACE.\n");
g_extern.system.disk_control = *(const struct retro_disk_control_callback*)data;
break;
2013-03-27 15:15:15 +00:00
case RETRO_ENVIRONMENT_SET_HW_RENDER:
case RETRO_ENVIRONMENT_SET_HW_RENDER | RETRO_ENVIRONMENT_EXPERIMENTAL: // ABI compat
2013-03-27 15:15:15 +00:00
{
RARCH_LOG("Environ SET_HW_RENDER.\n");
struct retro_hw_render_callback *cb = (struct retro_hw_render_callback*)data;
switch (cb->context_type)
{
case RETRO_HW_CONTEXT_NONE:
RARCH_LOG("Requesting no HW context.\n");
break;
#if defined(HAVE_OPENGLES2)
case RETRO_HW_CONTEXT_OPENGLES2:
RARCH_LOG("Requesting OpenGLES2 context.\n");
driver.video = &video_gl;
break;
case RETRO_HW_CONTEXT_OPENGL:
case RETRO_HW_CONTEXT_OPENGL_CORE:
RARCH_ERR("Requesting OpenGL context, but RetroArch is compiled against OpenGLES2. Cannot use HW context.\n");
return false;
#elif defined(HAVE_OPENGL)
case RETRO_HW_CONTEXT_OPENGLES2:
RARCH_ERR("Requesting OpenGLES2 context, but RetroArch is compiled against OpenGL. Cannot use HW context.\n");
return false;
case RETRO_HW_CONTEXT_OPENGL:
RARCH_LOG("Requesting OpenGL context.\n");
driver.video = &video_gl;
break;
case RETRO_HW_CONTEXT_OPENGL_CORE:
RARCH_LOG("Requesting core OpenGL context (%u.%u).\n", cb->version_major, cb->version_minor);
driver.video = &video_gl;
break;
#endif
default:
RARCH_LOG("Requesting unknown context.\n");
return false;
}
2013-03-27 15:15:15 +00:00
cb->get_current_framebuffer = driver_get_current_framebuffer;
cb->get_proc_address = driver_get_proc_address;
if (cmd & RETRO_ENVIRONMENT_EXPERIMENTAL) // Old ABI. Don't copy garbage.
memcpy(&g_extern.system.hw_render_callback, cb, offsetof(struct retro_hw_render_callback, stencil));
else
memcpy(&g_extern.system.hw_render_callback, 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");
g_extern.system.no_game = state;
break;
}
case RETRO_ENVIRONMENT_GET_LIBRETRO_PATH:
{
const char **path = (const char**)data;
#ifdef HAVE_DYNAMIC
*path = g_settings.libretro;
#else
*path = NULL;
#endif
break;
}
#ifdef HAVE_THREADS
case RETRO_ENVIRONMENT_SET_AUDIO_CALLBACK:
{
RARCH_LOG("Environ SET_AUDIO_CALLBACK.\n");
const struct retro_audio_callback *info = (const struct retro_audio_callback*)data;
2013-07-15 18:36:18 +00:00
#ifdef HAVE_FFMPEG
if (g_extern.recording) // A/V sync is a must.
return false;
2013-07-15 18:36:18 +00:00
#endif
#ifdef HAVE_NETPLAY
if (g_extern.netplay_enable)
return false;
#endif
g_extern.system.audio_callback = info->callback;
break;
}
#endif
case RETRO_ENVIRONMENT_SET_FRAME_TIME_CALLBACK:
2013-07-14 11:43:01 +00:00
{
RARCH_LOG("Environ SET_FRAME_TIME_CALLBACK.\n");
2013-07-15 18:36:18 +00:00
#ifdef HAVE_NETPLAY
if (g_extern.netplay_enable) // retro_run() will be called in very strange and mysterious ways, have to disable it.
return false;
2013-07-15 18:36:18 +00:00
#endif
const struct retro_frame_time_callback *info = (const struct retro_frame_time_callback*)data;
2013-07-14 11:43:01 +00:00
g_extern.system.frame_time = *info;
break;
2013-07-14 11:43:01 +00:00
}
default:
2012-04-21 21:25:32 +00:00
RARCH_LOG("Environ UNSUPPORTED (#%u).\n", cmd);
return false;
}
return true;
}