(PS3/360) libretro_manage_core made portable and moved to console_ext.c

This commit is contained in:
Twinaphex 2012-04-13 15:57:59 +02:00
parent add97b9ef5
commit 2ffffee571
8 changed files with 125 additions and 161 deletions

View File

@ -369,83 +369,6 @@ static void get_environment_settings (void)
strlcpy(SYS_CONFIG_FILE, "game:\\ssnes.cfg", sizeof(SYS_CONFIG_FILE));
}
static bool manage_libretro_core(void)
{
g_extern.verbose = true;
bool return_code;
bool set_libretro_path = false;
char tmp_path[1024], tmp_path2[1024], tmp_pathnewfile[1024];
snprintf(tmp_path, sizeof(tmp_path), "game:\\CORE.xex");
SSNES_LOG("Assumed path of CORE.xex: [%s]\n", tmp_path);
if(path_file_exists(tmp_path))
{
//if CORE.xex exists, this indicates we have just installed
//a new libretro port and that we need to change it to a more
//sane name.
int ret;
ssnes_console_name_from_id(tmp_path2, sizeof(tmp_path2));
strlcat(tmp_path2, ".xex", sizeof(tmp_path2));
snprintf(tmp_pathnewfile, sizeof(tmp_pathnewfile), "game:\\%s", tmp_path2);
if(path_file_exists(tmp_pathnewfile))
{
SSNES_LOG("Upgrading emulator core...\n");
//if libretro core already exists, then that means we are
//upgrading the libretro core - so delete pre-existing
//file first
ret = DeleteFile(tmp_pathnewfile);
if(ret != 0)
{
SSNES_LOG("Succeeded in removing pre-existing libretro core: [%s].\n", tmp_pathnewfile);
}
else
{
SSNES_LOG("Failed to remove pre-existing libretro core: [%s].\n", tmp_pathnewfile);
}
}
//now attempt the renaming
ret = MoveFileExA(tmp_path, tmp_pathnewfile, NULL);
if(ret == 0)
{
SSNES_ERR("Failed to rename CORE.xex.\n");
}
else
{
SSNES_LOG("libretro core [%s] renamed to: [%s].\n", tmp_path, tmp_pathnewfile);
set_libretro_path = true;
}
}
else
{
SSNES_LOG("CORE.xex was not found, libretro core path will be loaded from config file.\n");
}
if(set_libretro_path)
{
//CORE.xex has been renamed, libretro path will now be set to the recently
//renamed new libretro core
strlcpy(g_settings.libretro, tmp_pathnewfile, sizeof(g_settings.libretro));
return_code = 0;
}
else
{
//There was no CORE.xex present, or the CORE.xex file was not renamed.
//The libretro core path will still be loaded from the config file
return_code = 1;
}
g_extern.verbose = false;
return return_code;
}
int main(int argc, char *argv[])
{
get_environment_settings();
@ -453,7 +376,10 @@ int main(int argc, char *argv[])
ssnes_main_clear_state();
config_set_defaults();
bool load_libretro_path = manage_libretro_core();
char full_path[1024];
snprintf(full_path, sizeof(full_path), "game:\\CORE.xex");
bool load_libretro_path = ssnes_manage_libretro_core(full_path, "game:\\", ".xex");
set_default_settings();
init_settings(load_libretro_path);

View File

@ -68,7 +68,7 @@ endif
PPU_LDLIBS = -ldbgfont $(GL_LIBS) -lretro -lcgc -lgcm_cmd -lgcm_sys_stub -lresc_stub -lm -lio_stub -lfs_stub -lsysutil_stub -lsysutil_game_stub -lsysutil_screenshot_stub -lsysutil_np_stub -lpngdec_stub -ljpgdec_stub -lsysmodule_stub -laudio_stub -lnet_stub -lnetctl_stub -lpthread
DEFINES += -DSSNES_CONSOLE -DHAVE_OPENGL -DHAVE_CG -DHAVE_FBO -DHAVE_RSOUND -DHAVE_ZLIB -D__CELLOS_LV2__ -DHAVE_CONFIGFILE=1 -DHAVE_NETPLAY=1 -DHAVE_SOCKET_LEGACY=1 -DHAVE_GRIFFIN=1 -DPACKAGE_VERSION=\"$(SSNES_VERSION)\" -Dmain=ssnes_main -DPC_DEVELOPMENT_IP_ADDRESS=\"$(PC_DEVELOPMENT_IP_ADDRESS)\" -DPC_DEVELOPMENT_UDP_PORT=$(PC_DEVELOPMENT_UDP_PORT)
DEFINES += -DSSNES_CONSOLE -DHAVE_OPENGL -DHAVE_CG -DHAVE_FBO -DHAVE_LIBRETRO_MANAGEMENT -DHAVE_RSOUND -DHAVE_ZLIB -D__CELLOS_LV2__ -DHAVE_CONFIGFILE=1 -DHAVE_NETPLAY=1 -DHAVE_SOCKET_LEGACY=1 -DHAVE_GRIFFIN=1 -DPACKAGE_VERSION=\"$(SSNES_VERSION)\" -Dmain=ssnes_main -DPC_DEVELOPMENT_IP_ADDRESS=\"$(PC_DEVELOPMENT_IP_ADDRESS)\" -DPC_DEVELOPMENT_UDP_PORT=$(PC_DEVELOPMENT_UDP_PORT)
ifeq ($(DEBUG), 1)
PPU_OPTIMIZE_LV := -O0 -g

View File

@ -26,6 +26,7 @@
#include "../compat/strl.h"
#include "main_wrap.h"
#include "console_ext.h"
#include "../file.h"
#ifdef HAVE_ZLIB
#include "szlib/zlib.h"
@ -594,3 +595,99 @@ struct aspectratios_list_t aspectratio_lut[ASPECT_RATIO_CUSTOM+1] = {
{"Auto", 0.0f},
{"Custom", 0.0f}
};
/*============================================================
LIBRETRO
============================================================ */
#ifdef HAVE_LIBRETRO_MANAGEMENT
bool ssnes_manage_libretro_core(const char * full_path, const char * path, const char * exe_ext)
{
g_extern.verbose = true;
bool return_code;
bool set_libretro_path = false;
char tmp_path2[1024], tmp_pathnewfile[1024];
SSNES_LOG("Assumed path of CORE executable: [%s]\n", full_path);
if(path_file_exists(full_path))
{
//if CORE executable exists, this means we have just installed
//a new libretro port and therefore we need to change it to a more
//sane name.
#if defined(__CELLOS_LV2__)
CellFsErrno ret;
#else
int ret;
#endif
ssnes_console_name_from_id(tmp_path2, sizeof(tmp_path2));
strlcat(tmp_path2, exe_ext, sizeof(tmp_path2));
snprintf(tmp_pathnewfile, sizeof(tmp_pathnewfile), "%s%s", path, tmp_path2);
if(path_file_exists(tmp_pathnewfile))
{
//if libretro core already exists, this means we are
//upgrading the libretro core - so delete pre-existing
//file first.
SSNES_LOG("Upgrading emulator core...\n");
#if defined(__CELLOS_LV2__)
ret = cellFsUnlink(tmp_pathnewfile);
if(ret == CELL_FS_SUCCEEDED)
#elif defined(_XBOX)
ret = DeleteFile(tmp_pathnewfile);
if(ret != 0)
#endif
{
SSNES_LOG("Succeeded in removing pre-existing libretro core: [%s].\n", tmp_pathnewfile);
}
else
{
SSNES_LOG("Failed to remove pre-existing libretro core: [%s].\n", tmp_pathnewfile);
}
}
//now attempt the renaming.
#if defined(__CELLOS_LV2__)
ret = cellFsRename(full_path, tmp_pathnewfile);
if(ret != CELL_FS_SUCCEEDED)
#elif defined(_XBOX)
ret = MoveFileExA(full_path, tmp_pathnewfile, NULL);
if(ret == 0)
#endif
{
SSNES_ERR("Failed to rename CORE executable.\n");
}
else
{
SSNES_LOG("Libsnes core [%s] renamed to: [%s].\n", full_path, tmp_pathnewfile);
set_libretro_path = true;
}
}
else
{
SSNES_LOG("CORE executable was not found, libretro core path will be loaded from config file.\n");
}
if(set_libretro_path)
{
//CORE executable has been renamed, libretro path will now be set to the recently
//renamed new libretro core.
strlcpy(g_settings.libretro, tmp_pathnewfile, sizeof(g_settings.libretro));
return_code = 0;
}
else
{
//There was no CORE executable present, or the CORE executable file was not renamed.
//The libretro core path will still be loaded from the config file.
return_code = 1;
}
g_extern.verbose = false;
return return_code;
}
#endif

View File

@ -81,4 +81,8 @@ void ssnes_input_set_default_keybind_names_for_emulator(void);
void ssnes_input_set_keybind(unsigned player, unsigned keybind_action, uint64_t default_retro_joypad_id);
#if defined(__CELLOS_LV2__) || defined(_XBOX)
bool ssnes_manage_libretro_core(const char * full_path, const char * path, const char * exe_ext);
#endif
#endif

View File

@ -40,6 +40,10 @@
#define NP_POOL_SIZE (128*1024)
#endif
#ifndef PATH_MAX
#define PATH_MAX 512
#endif
#define MAX_PATH_LENGTH 1024
#ifdef HAVE_LOGGER

4
file.h
View File

@ -24,6 +24,10 @@
#include <sys/types.h>
#include "general.h"
#ifdef __CELLOS_LV2__
#include <cell/cell_fs.h>
#endif
// Generic file, path and directory handling.
ssize_t read_file(const char *path, void **buf);

View File

@ -112,7 +112,7 @@
<MinimalRebuild>true</MinimalRebuild>
<BufferSecurityCheck>false</BufferSecurityCheck>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PreprocessorDefinitions>_DEBUG;_XBOX;PACKAGE_VERSION="0.9.5";%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS;main=ssnes_main;SSNES_CONSOLE;HAVE_CONFIGFILE;HAVE_NETPLAY;HAVE_SOCKET_LEGACY;HAVE_ZLIB;D3DCOMPILE_USEVOIDS;HAVE_GRIFFIN</PreprocessorDefinitions>
<PreprocessorDefinitions>_DEBUG;_XBOX;PACKAGE_VERSION="0.9.5";%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS;main=ssnes_main;SSNES_CONSOLE;HAVE_CONFIGFILE;HAVE_NETPLAY;HAVE_SOCKET_LEGACY;HAVE_ZLIB;HAVE_LIBRETRO_MANAGEMENT;D3DCOMPILE_USEVOIDS;HAVE_GRIFFIN</PreprocessorDefinitions>
<CallAttributedProfiling>Callcap</CallAttributedProfiling>
</ClCompile>
<Link>
@ -150,7 +150,7 @@
<PREfast>AnalyzeOnly</PREfast>
<BufferSecurityCheck>false</BufferSecurityCheck>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PreprocessorDefinitions>_DEBUG;_XBOX;%(PreprocessorDefinitions);PACKAGE_VERSION="0.9.5";_CRT_SECURE_NO_WARNINGS;main=ssnes_main;HAVE_CONFIGFILE;SSNES_CONSOLE;HAVE_ZLIB;D3DCOMPILE_USEVOIDS;HAVE_GRIFFIN</PreprocessorDefinitions>
<PreprocessorDefinitions>_DEBUG;_XBOX;%(PreprocessorDefinitions);PACKAGE_VERSION="0.9.5";_CRT_SECURE_NO_WARNINGS;main=ssnes_main;HAVE_CONFIGFILE;SSNES_CONSOLE;HAVE_ZLIB;HAVE_LIBRETRO_MANAGEMENT;D3DCOMPILE_USEVOIDS;HAVE_GRIFFIN</PreprocessorDefinitions>
<CallAttributedProfiling>Callcap</CallAttributedProfiling>
</ClCompile>
<Link>
@ -189,7 +189,7 @@
<FavorSizeOrSpeed>Size</FavorSizeOrSpeed>
<BufferSecurityCheck>false</BufferSecurityCheck>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<PreprocessorDefinitions>NDEBUG;_XBOX;PROFILE;%(PreprocessorDefinitions);PACKAGE_VERSION="0.9.5";_CRT_SECURE_NO_WARNINGS;SSNES_CONSOLE;main=ssnes_main;HAVE_CONFIGFILE;HAVE_ZLIB;D3DCOMPILE_USEVOIDS;HAVE_GRIFFIN</PreprocessorDefinitions>
<PreprocessorDefinitions>NDEBUG;_XBOX;PROFILE;%(PreprocessorDefinitions);PACKAGE_VERSION="0.9.5";_CRT_SECURE_NO_WARNINGS;SSNES_CONSOLE;main=ssnes_main;HAVE_CONFIGFILE;HAVE_ZLIB;HAVE_LIBRETRO_MANAGEMENT;D3DCOMPILE_USEVOIDS;HAVE_GRIFFIN</PreprocessorDefinitions>
<CallAttributedProfiling>Callcap</CallAttributedProfiling>
</ClCompile>
<Link>
@ -233,7 +233,7 @@
<FavorSizeOrSpeed>Size</FavorSizeOrSpeed>
<BufferSecurityCheck>false</BufferSecurityCheck>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<PreprocessorDefinitions>NDEBUG;_XBOX;PROFILE;FASTCAP;%(PreprocessorDefinitions);PACKAGE_VERSION="0.9.5";_CRT_SECURE_NO_WARNINGS;main=ssnes_main;HAVE_CONFIGFILE;HAVE_ZLIB;D3DCOMPILE_USEVOIDS;HAVE_GRIFFIN</PreprocessorDefinitions>
<PreprocessorDefinitions>NDEBUG;_XBOX;PROFILE;FASTCAP;%(PreprocessorDefinitions);PACKAGE_VERSION="0.9.5";_CRT_SECURE_NO_WARNINGS;main=ssnes_main;HAVE_CONFIGFILE;HAVE_ZLIB;HAVE_LIBRETRO_MANAGEMENT;D3DCOMPILE_USEVOIDS;HAVE_GRIFFIN</PreprocessorDefinitions>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
@ -274,7 +274,7 @@
<ExceptionHandling>false</ExceptionHandling>
<BufferSecurityCheck>false</BufferSecurityCheck>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<PreprocessorDefinitions>NDEBUG;_XBOX;%(PreprocessorDefinitions);PACKAGE_VERSION="0.9.5";_CRT_SECURE_NO_WARNINGS;main=ssnes_main;SSNES_CONSOLE=1;HAVE_CONFIGFILE;HAVE_NETPLAY;HAVE_SOCKET_LEGACY;HAVE_ZLIB;D3DCOMPILE_USEVOIDS;HAVE_GRIFFIN</PreprocessorDefinitions>
<PreprocessorDefinitions>NDEBUG;_XBOX;%(PreprocessorDefinitions);PACKAGE_VERSION="0.9.5";_CRT_SECURE_NO_WARNINGS;main=ssnes_main;SSNES_CONSOLE=1;HAVE_CONFIGFILE;HAVE_NETPLAY;HAVE_SOCKET_LEGACY;HAVE_ZLIB;HAVE_LIBRETRO_MANAGEMENT;D3DCOMPILE_USEVOIDS;HAVE_GRIFFIN</PreprocessorDefinitions>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
@ -315,7 +315,7 @@
<ExceptionHandling>false</ExceptionHandling>
<BufferSecurityCheck>false</BufferSecurityCheck>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<PreprocessorDefinitions>NDEBUG;_XBOX;LTCG;%(PreprocessorDefinitions);PACKAGE_VERSION="0.9.5";_CRT_SECURE_NO_WARNINGS;SSNES_CONSOLE;main=ssnes_main;HAVE_CONFIGFILE;HAVE_NETPLAY;HAVE_SOCKET_LEGACY;HAVE_ZLIB;D3DCOMPILE_USEVOIDS;HAVE_GRIFFIN</PreprocessorDefinitions>
<PreprocessorDefinitions>NDEBUG;_XBOX;LTCG;%(PreprocessorDefinitions);PACKAGE_VERSION="0.9.5";_CRT_SECURE_NO_WARNINGS;SSNES_CONSOLE;main=ssnes_main;HAVE_CONFIGFILE;HAVE_NETPLAY;HAVE_SOCKET_LEGACY;HAVE_ZLIB;HAVE_LIBRETRO_MANAGEMENT;D3DCOMPILE_USEVOIDS;HAVE_GRIFFIN</PreprocessorDefinitions>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
@ -644,4 +644,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>

View File

@ -457,80 +457,6 @@ static void startup_ssnes(void)
}
}
static bool manage_libretro_core(void)
{
g_extern.verbose = true;
bool return_code;
bool set_libretro_path = false;
char tmp_path[1024], tmp_path2[1024], tmp_pathnewfile[1024];
snprintf(tmp_path, sizeof(tmp_path), "%s/%s/CORE.SELF", usrDirPath, EMULATOR_CORE_DIR);
SSNES_LOG("Assumed path of CORE.SELF: [%s]\n", tmp_path);
if(path_file_exists(tmp_path))
{
//if CORE.SELF exists, this indicates we have just installed
//a new libretro port and that we need to change it to a more
//sane name.
CellFsErrno ret;
ssnes_console_name_from_id(tmp_path2, sizeof(tmp_path2));
strlcat(tmp_path2, ".SELF", sizeof(tmp_path2));
snprintf(tmp_pathnewfile, sizeof(tmp_pathnewfile), "%s/%s/%s", usrDirPath, EMULATOR_CORE_DIR, tmp_path2);
if(path_file_exists(tmp_pathnewfile))
{
SSNES_LOG("Upgrading emulator core...\n");
//if libretro core already exists, then that means we are
//upgrading the libretro core - so delete pre-existing
//file first
ret = cellFsUnlink(tmp_pathnewfile);
if(ret == CELL_FS_SUCCEEDED)
{
SSNES_LOG("Succeeded in removing pre-existing libretro core: [%s].\n", tmp_pathnewfile);
}
else
{
SSNES_LOG("Failed to remove pre-existing libretro core: [%s].\n", tmp_pathnewfile);
}
}
//now attempt the renaming
ret = cellFsRename(tmp_path, tmp_pathnewfile);
if(ret != CELL_FS_SUCCEEDED)
{
SSNES_ERR("Failed to rename CORE.SELF.\n");
}
else
{
SSNES_LOG("Libsnes core [%s] renamed to: [%s].\n", tmp_path, tmp_pathnewfile);
set_libretro_path = true;
}
}
else
{
SSNES_LOG("CORE.SELF was not found, libretro core path will be loaded from config file.\n");
}
if(set_libretro_path)
{
//CORE.BIN has been renamed, libretro path will now be set to the recently
//renamed new libretro core
strlcpy(g_settings.libretro, tmp_pathnewfile, sizeof(g_settings.libretro));
return_code = 0;
}
else
{
//There was no CORE.BIN present, or the CORE.BIN file was not renamed.
//The libretro core path will still be loaded from the config file
return_code = 1;
}
g_extern.verbose = false;
return return_code;
}
int main(int argc, char *argv[])
{
@ -559,7 +485,10 @@ int main(int argc, char *argv[])
config_set_defaults();
bool load_libretro_path = manage_libretro_core();
char full_path[1024], tmp_path[1024];
snprintf(full_path, sizeof(full_path), "%s/%s/CORE.SELF", usrDirPath, EMULATOR_CORE_DIR);
snprintf(tmp_path, sizeof(tmp_path), "%s/%s/", usrDirPath, EMULATOR_CORE_DIR);
bool load_libretro_path = ssnes_manage_libretro_core(full_path, tmp_path, ".SELF");
set_default_settings();
init_settings(load_libretro_path);