2013-01-08 00:26:18 +00: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-03-11 05:59:53 +00:00
|
|
|
#include "../config.def.h"
|
2013-01-09 17:31:14 +00:00
|
|
|
#include "menu/rmenu.h"
|
2013-01-09 01:31:54 +00:00
|
|
|
|
2013-01-08 00:26:18 +00:00
|
|
|
#if defined(__CELLOS_LV2__)
|
2013-01-09 01:31:54 +00:00
|
|
|
#include "platform/platform_ps3_exec.c"
|
2013-03-09 21:57:42 +00:00
|
|
|
#include "platform/platform_ps3.c"
|
2013-01-08 04:48:21 +00:00
|
|
|
#elif defined(GEKKO)
|
2013-02-14 14:47:52 +00:00
|
|
|
#ifdef HW_RVL
|
2013-01-09 01:31:54 +00:00
|
|
|
#include "platform/platform_gx_exec.c"
|
2013-02-14 14:47:52 +00:00
|
|
|
#endif
|
2013-03-09 21:57:42 +00:00
|
|
|
#include "platform/platform_gx.c"
|
2013-01-08 05:26:02 +00:00
|
|
|
#elif defined(_XBOX)
|
2013-01-09 01:31:54 +00:00
|
|
|
#include "platform/platform_xdk_exec.c"
|
2013-03-09 21:57:42 +00:00
|
|
|
#include "platform/platform_xdk.c"
|
2013-01-08 07:38:25 +00:00
|
|
|
#elif defined(PSP)
|
|
|
|
#include "platform/platform_psp.c"
|
2013-01-08 00:26:18 +00:00
|
|
|
#endif
|
|
|
|
|
2013-01-08 02:56:17 +00:00
|
|
|
#undef main
|
|
|
|
|
2013-01-09 04:54:48 +00:00
|
|
|
default_paths_t default_paths;
|
|
|
|
|
2013-03-23 03:35:30 +00:00
|
|
|
static inline void inl_logger_init(void)
|
|
|
|
{
|
|
|
|
#if defined(HAVE_LOGGER)
|
2013-03-24 01:02:15 +00:00
|
|
|
g_extern.verbose = true;
|
2013-03-23 03:35:30 +00:00
|
|
|
logger_init();
|
|
|
|
#elif defined(HAVE_FILE_LOGGER)
|
2013-03-24 01:02:15 +00:00
|
|
|
g_extern.verbose = true;
|
2013-03-23 03:35:30 +00:00
|
|
|
g_extern.log_file = fopen("/retroarch-log.txt", "w");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void inl_logger_deinit(void)
|
|
|
|
{
|
|
|
|
#if defined(HAVE_LOGGER)
|
|
|
|
logger_shutdown();
|
|
|
|
#elif defined(HAVE_FILE_LOGGER)
|
|
|
|
if (g_extern.log_file)
|
|
|
|
fclose(g_extern.log_file);
|
|
|
|
g_extern.log_file = NULL;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-03-13 05:43:18 +00:00
|
|
|
#ifdef HAVE_LIBRETRO_MANAGEMENT
|
2013-03-24 02:13:10 +00:00
|
|
|
static bool libretro_install_core(const char *path_prefix, const char *extension)
|
2013-01-09 02:34:05 +00:00
|
|
|
{
|
2013-03-24 02:13:10 +00:00
|
|
|
char core_exe_path[256];
|
|
|
|
char tmp_path[PATH_MAX], tmp_pathnewfile[PATH_MAX];
|
|
|
|
int ret;
|
2013-03-22 19:54:33 +00:00
|
|
|
|
2013-03-24 02:13:10 +00:00
|
|
|
snprintf(core_exe_path, sizeof(core_exe_path), "%sCORE%s", path_prefix, DEFAULT_EXE_EXT);
|
|
|
|
|
|
|
|
if (!path_file_exists(core_exe_path))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* If a CORE executable of name CORE.extension exists, rename filename
|
|
|
|
* to a more sane name. */
|
2013-01-09 02:34:05 +00:00
|
|
|
|
2013-03-24 02:13:10 +00:00
|
|
|
ret = 0;
|
2013-01-09 02:34:05 +00:00
|
|
|
|
2013-03-24 02:13:10 +00:00
|
|
|
libretro_get_current_core_pathname(tmp_path, sizeof(tmp_path));
|
|
|
|
|
|
|
|
strlcat(tmp_path, extension, sizeof(tmp_path));
|
|
|
|
snprintf(tmp_pathnewfile, sizeof(tmp_pathnewfile), "%s%s", path_prefix, tmp_path);
|
2013-01-09 02:34:05 +00:00
|
|
|
|
|
|
|
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);
|
2013-01-13 15:45:57 +00:00
|
|
|
strlcpy(g_settings.libretro, tmp_pathnewfile, sizeof(g_settings.libretro));
|
2013-01-09 02:34:05 +00:00
|
|
|
}
|
|
|
|
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-02-25 05:47:26 +00:00
|
|
|
int rarch_main(int argc, char *argv[])
|
2013-01-08 00:26:18 +00:00
|
|
|
{
|
|
|
|
system_init();
|
|
|
|
|
|
|
|
rarch_main_clear_state();
|
2013-01-08 21:17:38 +00:00
|
|
|
|
2013-03-24 01:02:15 +00:00
|
|
|
g_extern.verbose = true;
|
2013-01-10 04:07:38 +00:00
|
|
|
|
2013-01-08 00:26:18 +00:00
|
|
|
get_environment_settings(argc, argv);
|
2013-01-08 22:22:08 +00:00
|
|
|
config_load();
|
2013-01-10 05:38:19 +00:00
|
|
|
|
2013-01-08 22:22:08 +00:00
|
|
|
init_libretro_sym();
|
2013-01-08 21:52:56 +00:00
|
|
|
rarch_init_system_info();
|
2013-01-08 00:26:18 +00:00
|
|
|
|
2013-03-13 03:16:56 +00:00
|
|
|
global_init_drivers();
|
2013-01-08 00:26:18 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_LIBRETRO_MANAGEMENT
|
|
|
|
char path_prefix[PATH_MAX];
|
2013-01-10 05:05:38 +00:00
|
|
|
#if defined(_WIN32)
|
2013-03-24 02:13:10 +00:00
|
|
|
char slash = '\\';
|
2013-01-08 05:26:02 +00:00
|
|
|
#else
|
2013-03-24 02:13:10 +00:00
|
|
|
char slash = '/';
|
2013-01-08 05:26:02 +00:00
|
|
|
#endif
|
2013-01-08 00:26:18 +00:00
|
|
|
|
2013-01-10 05:05:38 +00:00
|
|
|
snprintf(path_prefix, sizeof(path_prefix), "%s%c", default_paths.core_dir, slash);
|
2013-01-08 00:26:18 +00:00
|
|
|
|
2013-03-24 02:13:10 +00:00
|
|
|
// Save new libretro core path to config file
|
|
|
|
if (libretro_install_core(path_prefix, DEFAULT_EXE_EXT))
|
|
|
|
config_save_file(g_extern.config_path);
|
2013-01-08 00:26:18 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
init_libretro_sym();
|
|
|
|
|
|
|
|
system_post_init();
|
|
|
|
|
|
|
|
menu_init();
|
|
|
|
|
|
|
|
system_process_args(argc, argv);
|
|
|
|
|
|
|
|
begin_loop:
|
2013-01-13 02:34:55 +00:00
|
|
|
if(g_extern.lifecycle_mode_state & (1ULL << MODE_GAME))
|
2013-01-08 00:26:18 +00:00
|
|
|
{
|
|
|
|
driver.input->poll(NULL);
|
2013-03-10 03:16:35 +00:00
|
|
|
|
|
|
|
if (driver.video_poke->set_aspect_ratio)
|
|
|
|
driver.video_poke->set_aspect_ratio(driver.video_data, g_settings.video.aspect_ratio_idx);
|
2013-01-12 00:42:04 +00:00
|
|
|
|
2013-01-12 02:13:03 +00:00
|
|
|
if (g_extern.lifecycle_mode_state & (1ULL << MODE_VIDEO_THROTTLE_ENABLE))
|
2013-01-12 00:42:04 +00:00
|
|
|
audio_start_func();
|
|
|
|
|
2013-01-08 00:26:18 +00:00
|
|
|
while(rarch_main_iterate());
|
2013-01-12 00:42:04 +00:00
|
|
|
|
2013-01-12 02:13:03 +00:00
|
|
|
if (g_extern.lifecycle_mode_state & (1ULL << MODE_VIDEO_THROTTLE_ENABLE))
|
2013-01-12 00:42:04 +00:00
|
|
|
audio_stop_func();
|
2013-01-13 02:34:55 +00:00
|
|
|
g_extern.lifecycle_mode_state &= ~(1ULL << MODE_GAME);
|
2013-01-08 00:26:18 +00:00
|
|
|
}
|
2013-01-12 02:13:03 +00:00
|
|
|
else if (g_extern.lifecycle_mode_state & (1ULL << MODE_INIT))
|
2013-01-08 00:26:18 +00:00
|
|
|
{
|
|
|
|
if(g_extern.main_is_init)
|
|
|
|
rarch_main_deinit();
|
|
|
|
|
|
|
|
struct rarch_main_wrap args = {0};
|
|
|
|
|
|
|
|
args.verbose = g_extern.verbose;
|
2013-01-13 03:12:10 +00:00
|
|
|
args.sram_path = (g_extern.lifecycle_mode_state & (1ULL << MODE_LOAD_GAME_SRAM_DIR_ENABLE)) ? g_extern.console.main_wrap.default_sram_dir : NULL;
|
|
|
|
args.state_path = (g_extern.lifecycle_mode_state & (1ULL << MODE_LOAD_GAME_STATE_DIR_ENABLE)) ? g_extern.console.main_wrap.default_savestate_dir : NULL;
|
2013-01-09 07:25:38 +00:00
|
|
|
args.rom_path = g_extern.fullpath;
|
2013-01-08 00:26:18 +00:00
|
|
|
args.libretro_path = g_settings.libretro;
|
|
|
|
|
2013-01-22 11:53:11 +00:00
|
|
|
if (path_file_exists(g_extern.config_path))
|
|
|
|
args.config_path = g_extern.config_path;
|
|
|
|
else
|
|
|
|
args.config_path = NULL;
|
|
|
|
|
2013-03-13 05:43:18 +00:00
|
|
|
if (rarch_main_init_wrap(&args) == 0)
|
2013-01-08 07:11:05 +00:00
|
|
|
{
|
2013-01-08 00:26:18 +00:00
|
|
|
RARCH_LOG("rarch_main_init succeeded.\n");
|
2013-01-13 02:34:55 +00:00
|
|
|
g_extern.lifecycle_mode_state |= (1ULL << MODE_GAME);
|
2013-01-08 07:11:05 +00:00
|
|
|
}
|
2013-01-08 00:26:18 +00:00
|
|
|
else
|
2013-01-08 07:11:05 +00:00
|
|
|
{
|
2013-01-08 00:26:18 +00:00
|
|
|
RARCH_ERR("rarch_main_init failed.\n");
|
2013-01-12 02:13:03 +00:00
|
|
|
g_extern.lifecycle_mode_state |= (1ULL << MODE_MENU);
|
2013-03-23 18:34:38 +00:00
|
|
|
msg_queue_push(g_extern.msg_queue, "ERROR - An error occurred during ROM loading.", 1, 180);
|
2013-01-08 07:11:05 +00:00
|
|
|
}
|
2013-01-12 02:13:03 +00:00
|
|
|
g_extern.lifecycle_mode_state &= ~(1ULL << MODE_INIT);
|
2013-01-08 00:26:18 +00:00
|
|
|
}
|
2013-01-12 02:13:03 +00:00
|
|
|
else if(g_extern.lifecycle_mode_state & (1ULL << MODE_MENU))
|
2013-01-10 18:17:35 +00:00
|
|
|
{
|
2013-01-12 02:13:03 +00:00
|
|
|
g_extern.lifecycle_mode_state |= (1ULL << MODE_MENU_PREINIT);
|
2013-03-09 15:22:11 +00:00
|
|
|
while (menu_iterate());
|
2013-01-12 02:13:03 +00:00
|
|
|
g_extern.lifecycle_mode_state &= ~(1ULL << MODE_MENU);
|
2013-01-10 18:17:35 +00:00
|
|
|
}
|
2013-01-08 00:26:18 +00:00
|
|
|
else
|
|
|
|
goto begin_shutdown;
|
|
|
|
|
|
|
|
goto begin_loop;
|
|
|
|
|
|
|
|
begin_shutdown:
|
|
|
|
config_save_file(g_extern.config_path);
|
|
|
|
|
2013-01-08 04:48:21 +00:00
|
|
|
system_deinit_save();
|
|
|
|
|
2013-01-08 00:26:18 +00:00
|
|
|
if(g_extern.main_is_init)
|
|
|
|
rarch_main_deinit();
|
|
|
|
|
|
|
|
menu_free();
|
2013-03-13 03:16:56 +00:00
|
|
|
global_uninit_drivers();
|
2013-01-08 00:26:18 +00:00
|
|
|
|
2013-01-08 07:30:54 +00:00
|
|
|
#ifdef PERF_TEST
|
|
|
|
rarch_perf_log();
|
2013-01-08 04:48:21 +00:00
|
|
|
#endif
|
|
|
|
|
2013-01-08 00:26:18 +00:00
|
|
|
system_deinit();
|
2013-01-12 02:13:03 +00:00
|
|
|
if (g_extern.lifecycle_mode_state & (1ULL << MODE_EXITSPAWN))
|
2013-01-11 19:13:02 +00:00
|
|
|
system_exitspawn();
|
2013-01-08 00:26:18 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|