2013-01-08 01:26:18 +01:00
|
|
|
/* RetroArch - A frontend for libretro.
|
|
|
|
* Copyright (C) 2010-2013 - Hans-Kristian Arntzen
|
|
|
|
* Copyright (C) 2011-2013 - Daniel De Matteis
|
|
|
|
*
|
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include "../boolean.h"
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2013-01-09 03:34:05 +01:00
|
|
|
#include "frontend_console.h"
|
2013-01-09 02:31:54 +01:00
|
|
|
|
2013-01-08 01:26:18 +01:00
|
|
|
#if defined(__CELLOS_LV2__)
|
2013-01-08 07:44:57 +01:00
|
|
|
#include "platform/platform_ps3.c"
|
2013-01-09 02:31:54 +01:00
|
|
|
#include "platform/platform_ps3_exec.c"
|
2013-01-07 23:48:21 -05:00
|
|
|
#elif defined(GEKKO)
|
2013-01-08 07:44:57 +01:00
|
|
|
#include "platform/platform_gx.c"
|
2013-01-09 02:31:54 +01:00
|
|
|
#include "platform/platform_gx_exec.c"
|
2013-01-08 06:26:02 +01:00
|
|
|
#elif defined(_XBOX)
|
2013-01-08 07:44:57 +01:00
|
|
|
#include "platform/platform_xdk.c"
|
2013-01-09 02:31:54 +01:00
|
|
|
#include "platform/platform_xdk_exec.c"
|
2013-01-08 08:38:25 +01:00
|
|
|
#elif defined(PSP)
|
|
|
|
#include "platform/platform_psp.c"
|
2013-01-08 01:26:18 +01:00
|
|
|
#endif
|
|
|
|
|
2013-01-08 03:56:17 +01:00
|
|
|
#undef main
|
|
|
|
|
2013-01-09 05:54:48 +01:00
|
|
|
default_paths_t default_paths;
|
|
|
|
|
2013-01-09 00:10:19 +01:00
|
|
|
#ifdef IS_SALAMANDER
|
|
|
|
|
2013-01-09 02:49:20 +01:00
|
|
|
//We need to set libretro to the first entry in the cores
|
|
|
|
//directory so that it will be saved to the config file
|
|
|
|
static void rarch_manage_libretro_set_first_file(char *first_file,
|
|
|
|
size_t size_of_first_file, const char *libretro_path,
|
|
|
|
const char * exe_ext)
|
|
|
|
{
|
|
|
|
struct string_list *dir_list = dir_list_new(libretro_path, exe_ext, false);
|
|
|
|
|
|
|
|
const char * first_exe;
|
|
|
|
|
|
|
|
if (!dir_list)
|
|
|
|
{
|
|
|
|
RARCH_ERR("Couldn't read directory.\n");
|
|
|
|
RARCH_ERR("Failed to set first entry to libretro path.\n");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
first_exe = dir_list->elems[0].data;
|
|
|
|
|
|
|
|
if(first_exe)
|
|
|
|
{
|
|
|
|
char fname_tmp[PATH_MAX];
|
|
|
|
fill_pathname_base(fname_tmp, first_exe, sizeof(fname_tmp));
|
|
|
|
|
|
|
|
if(strncmp(fname_tmp, default_paths.salamander_file, sizeof(fname_tmp)) == 0)
|
|
|
|
{
|
|
|
|
RARCH_WARN("First entry is RetroArch Salamander itself, increment entry by one and check if it exists.\n");
|
|
|
|
first_exe = dir_list->elems[1].data;
|
|
|
|
fill_pathname_base(fname_tmp, first_exe, sizeof(fname_tmp));
|
|
|
|
|
|
|
|
if(!first_exe)
|
|
|
|
{
|
|
|
|
RARCH_ERR("Unlikely error happened - no second entry - no choice but to set it to RetroArch Salamander\n");
|
|
|
|
first_exe = dir_list->elems[0].data;
|
|
|
|
fill_pathname_base(fname_tmp, first_exe, sizeof(fname_tmp));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
strlcpy(first_file, fname_tmp, size_of_first_file);
|
|
|
|
RARCH_LOG("Set first entry in libretro core dir to libretro path: [%s].\n", first_file);
|
|
|
|
}
|
|
|
|
|
|
|
|
end:
|
|
|
|
dir_list_free(dir_list);
|
|
|
|
}
|
|
|
|
|
2013-01-09 00:10:19 +01:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
system_init();
|
|
|
|
get_environment_settings(argc, argv);
|
|
|
|
salamander_init_settings();
|
|
|
|
system_deinit();
|
|
|
|
system_exitspawn();
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2013-01-09 03:34:05 +01:00
|
|
|
#ifdef HAVE_LIBRETRO_MANAGEMENT
|
|
|
|
|
|
|
|
// Transforms a library id to a name suitable as a pathname.
|
|
|
|
static void get_libretro_core_name(char *name, size_t size)
|
|
|
|
{
|
|
|
|
if (size == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
struct retro_system_info info;
|
|
|
|
retro_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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If a CORE executable of name CORE.extension exists, rename filename
|
|
|
|
// to a more sane name.
|
|
|
|
static bool install_libretro_core(const char *core_exe_path, const char *tmp_path,
|
|
|
|
const char *libretro_path, const char *config_path, const char *extension)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
char tmp_path2[PATH_MAX], tmp_pathnewfile[PATH_MAX];
|
|
|
|
|
|
|
|
get_libretro_core_name(tmp_path2, sizeof(tmp_path2));
|
|
|
|
|
|
|
|
strlcat(tmp_path2, extension, sizeof(tmp_path2));
|
|
|
|
snprintf(tmp_pathnewfile, sizeof(tmp_pathnewfile), "%s%s", tmp_path, tmp_path2);
|
|
|
|
|
|
|
|
if (path_file_exists(tmp_pathnewfile))
|
|
|
|
{
|
|
|
|
// If core already exists, we are upgrading the core -
|
|
|
|
// delete existing file first.
|
|
|
|
|
|
|
|
RARCH_LOG("Upgrading emulator core...\n");
|
|
|
|
ret = remove(tmp_pathnewfile);
|
|
|
|
|
|
|
|
if (ret == 0)
|
|
|
|
RARCH_LOG("Succeeded in removing pre-existing libretro core: [%s].\n", tmp_pathnewfile);
|
|
|
|
else
|
|
|
|
RARCH_ERR("Failed to remove pre-existing libretro core: [%s].\n", tmp_pathnewfile);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now attempt the renaming of the core.
|
|
|
|
ret = rename(core_exe_path, tmp_pathnewfile);
|
|
|
|
|
|
|
|
if (ret == 0)
|
|
|
|
{
|
|
|
|
RARCH_LOG("Libretro core [%s] successfully renamed to: [%s].\n", core_exe_path, tmp_pathnewfile);
|
|
|
|
snprintf(g_settings.libretro, sizeof(g_settings.libretro), tmp_pathnewfile);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RARCH_ERR("Failed to rename CORE executable.\n");
|
|
|
|
RARCH_WARN("CORE executable was not found, or some other error occurred. Will attempt to load libretro core path from config file.\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2013-01-08 23:22:08 +01:00
|
|
|
// Only called once on init and deinit.
|
|
|
|
// Video and input drivers need to be active (owned)
|
|
|
|
// before retroarch core starts.
|
2013-01-08 22:17:38 +01:00
|
|
|
static void init_console_drivers(void)
|
|
|
|
{
|
2013-01-08 23:22:08 +01:00
|
|
|
init_drivers_pre(); // Set driver.* function callbacks.
|
|
|
|
driver.video->start(); // Statically starts video driver. Sets driver.video_data.
|
2013-01-08 03:56:17 +01:00
|
|
|
driver.input_data = driver.input->init();
|
|
|
|
rarch_input_set_controls_default(driver.input);
|
|
|
|
driver.input->post_init();
|
|
|
|
|
2013-01-08 22:17:38 +01:00
|
|
|
// Core handles audio.
|
2013-01-08 03:56:17 +01:00
|
|
|
}
|
|
|
|
|
2013-01-08 22:17:38 +01:00
|
|
|
static void uninit_console_drivers(void)
|
2013-01-08 08:11:05 +01:00
|
|
|
{
|
2013-01-08 22:17:38 +01:00
|
|
|
if (driver.video_data)
|
|
|
|
{
|
|
|
|
driver.video->stop();
|
|
|
|
driver.video_data = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (driver.input_data)
|
|
|
|
{
|
|
|
|
driver.input->free(NULL);
|
|
|
|
driver.input_data = NULL;
|
|
|
|
}
|
2013-01-08 08:11:05 +01:00
|
|
|
}
|
|
|
|
|
2013-01-08 01:26:18 +01:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
system_init();
|
|
|
|
|
|
|
|
rarch_main_clear_state();
|
2013-01-08 22:17:38 +01:00
|
|
|
|
2013-01-08 01:26:18 +01:00
|
|
|
get_environment_settings(argc, argv);
|
2013-01-08 22:17:38 +01:00
|
|
|
config_set_defaults();
|
|
|
|
rarch_settings_set_default();
|
|
|
|
rarch_config_load();
|
|
|
|
|
2013-01-08 23:22:08 +01:00
|
|
|
config_load();
|
|
|
|
init_libretro_sym();
|
2013-01-08 22:52:56 +01:00
|
|
|
rarch_init_system_info();
|
2013-01-08 01:26:18 +01:00
|
|
|
|
2013-01-08 22:17:38 +01:00
|
|
|
init_console_drivers();
|
2013-01-08 01:26:18 +01:00
|
|
|
|
|
|
|
#ifdef HAVE_LIBRETRO_MANAGEMENT
|
|
|
|
char core_exe_path[PATH_MAX];
|
|
|
|
char path_prefix[PATH_MAX];
|
|
|
|
const char *extension = default_paths.executable_extension;
|
2013-01-08 06:26:02 +01:00
|
|
|
#if defined(_XBOX1)
|
|
|
|
snprintf(path_prefix, sizeof(path_prefix), "D:\\");
|
|
|
|
#elif defined(_XBOX360)
|
|
|
|
snprintf(path_prefix, sizeof(path_prefix), default_paths.filesystem_root_dir);
|
|
|
|
#else
|
2013-01-08 01:26:18 +01:00
|
|
|
snprintf(path_prefix, sizeof(path_prefix), "%s/", default_paths.core_dir);
|
2013-01-08 06:26:02 +01:00
|
|
|
#endif
|
2013-01-08 01:26:18 +01:00
|
|
|
snprintf(core_exe_path, sizeof(core_exe_path), "%sCORE%s", path_prefix, extension);
|
|
|
|
|
|
|
|
|
|
|
|
if (path_file_exists(core_exe_path))
|
|
|
|
{
|
2013-01-09 03:34:05 +01:00
|
|
|
if (install_libretro_core(core_exe_path, path_prefix, path_prefix,
|
2013-01-08 01:26:18 +01:00
|
|
|
g_extern.config_path, extension))
|
|
|
|
{
|
|
|
|
RARCH_LOG("New default libretro core saved to config file: %s.\n", g_settings.libretro);
|
|
|
|
config_save_file(g_extern.config_path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
init_libretro_sym();
|
|
|
|
|
|
|
|
system_post_init();
|
|
|
|
|
|
|
|
menu_init();
|
|
|
|
|
|
|
|
system_process_args(argc, argv);
|
|
|
|
|
|
|
|
begin_loop:
|
|
|
|
if(g_extern.console.rmenu.mode == MODE_EMULATION)
|
|
|
|
{
|
|
|
|
driver.input->poll(NULL);
|
|
|
|
driver.video->set_aspect_ratio(driver.video_data, g_settings.video.aspect_ratio_idx);
|
2013-01-07 23:48:21 -05:00
|
|
|
audio_start_func();
|
2013-01-08 01:26:18 +01:00
|
|
|
while(rarch_main_iterate());
|
2013-01-07 23:48:21 -05:00
|
|
|
audio_stop_func();
|
2013-01-08 01:26:18 +01:00
|
|
|
}
|
|
|
|
else if (g_extern.console.rmenu.mode == MODE_INIT)
|
|
|
|
{
|
|
|
|
if(g_extern.main_is_init)
|
|
|
|
rarch_main_deinit();
|
|
|
|
|
|
|
|
struct rarch_main_wrap args = {0};
|
|
|
|
|
|
|
|
args.verbose = g_extern.verbose;
|
|
|
|
args.config_path = g_extern.config_path;
|
|
|
|
args.sram_path = g_extern.console.main_wrap.state.default_sram_dir.enable ? g_extern.console.main_wrap.paths.default_sram_dir : NULL,
|
|
|
|
args.state_path = g_extern.console.main_wrap.state.default_savestate_dir.enable ? g_extern.console.main_wrap.paths.default_savestate_dir : NULL,
|
2013-01-09 06:40:55 +01:00
|
|
|
args.rom_path = g_extern.fullpath;
|
2013-01-08 01:26:18 +01:00
|
|
|
args.libretro_path = g_settings.libretro;
|
|
|
|
|
|
|
|
int init_ret = rarch_main_init_wrap(&args);
|
|
|
|
|
|
|
|
if (init_ret == 0)
|
2013-01-08 08:11:05 +01:00
|
|
|
{
|
2013-01-08 01:26:18 +01:00
|
|
|
RARCH_LOG("rarch_main_init succeeded.\n");
|
2013-01-08 08:11:05 +01:00
|
|
|
g_extern.console.rmenu.mode = MODE_EMULATION;
|
|
|
|
}
|
2013-01-08 01:26:18 +01:00
|
|
|
else
|
2013-01-08 08:11:05 +01:00
|
|
|
{
|
2013-01-08 01:26:18 +01:00
|
|
|
RARCH_ERR("rarch_main_init failed.\n");
|
2013-01-08 08:11:05 +01:00
|
|
|
g_extern.console.rmenu.mode = MODE_MENU;
|
|
|
|
rarch_settings_msg(S_MSG_ROM_LOADING_ERROR, S_DELAY_180);
|
|
|
|
}
|
2013-01-08 01:26:18 +01:00
|
|
|
}
|
|
|
|
else if(g_extern.console.rmenu.mode == MODE_MENU)
|
|
|
|
while(rmenu_iterate());
|
|
|
|
else
|
|
|
|
goto begin_shutdown;
|
|
|
|
|
|
|
|
goto begin_loop;
|
|
|
|
|
|
|
|
begin_shutdown:
|
|
|
|
config_save_file(g_extern.config_path);
|
|
|
|
|
2013-01-07 23:48:21 -05:00
|
|
|
system_deinit_save();
|
|
|
|
|
2013-01-08 01:26:18 +01:00
|
|
|
if(g_extern.main_is_init)
|
|
|
|
rarch_main_deinit();
|
|
|
|
|
|
|
|
menu_free();
|
2013-01-08 22:17:38 +01:00
|
|
|
uninit_console_drivers();
|
2013-01-08 01:26:18 +01:00
|
|
|
|
2013-01-08 08:30:54 +01:00
|
|
|
#ifdef PERF_TEST
|
|
|
|
rarch_perf_log();
|
2013-01-07 23:48:21 -05:00
|
|
|
#endif
|
|
|
|
|
2013-01-08 01:26:18 +01:00
|
|
|
system_deinit();
|
|
|
|
system_exitspawn();
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
2013-01-09 00:10:19 +01:00
|
|
|
|
|
|
|
#endif
|