From c77b49b19a8e3818e1f6d1321e23e41f711e48fb Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sat, 28 Jul 2012 16:21:05 +0200 Subject: [PATCH] (RARCH_CONSOLE) Split up main_wrap code into its own file --- console/griffin/griffin.c | 4 ++ console/rarch_console.c | 100 --------------------------- console/rarch_console.h | 14 ---- console/rarch_console_main_wrap.c | 110 ++++++++++++++++++++++++++++++ console/rarch_console_main_wrap.h | 31 +++++++++ ps3/frontend/main.c | 1 + wii/frontend/main.c | 1 + xdk/frontend/main.c | 1 + 8 files changed, 148 insertions(+), 114 deletions(-) create mode 100644 console/rarch_console_main_wrap.c create mode 100644 console/rarch_console_main_wrap.h diff --git a/console/griffin/griffin.c b/console/griffin/griffin.c index 8410968a63..9bce970bc5 100644 --- a/console/griffin/griffin.c +++ b/console/griffin/griffin.c @@ -25,6 +25,10 @@ CONSOLE EXTENSIONS #include "../rarch_console_video.c" +#ifdef HAVE_RARCH_MAIN_WRAP +#include "../rarch_console_main_wrap.c" +#endif + #include "../rarch_console.c" #ifdef HAVE_CONFIGFILE diff --git a/console/rarch_console.c b/console/rarch_console.c index 47eef3fd75..c513c5658b 100644 --- a/console/rarch_console.c +++ b/console/rarch_console.c @@ -16,7 +16,6 @@ #include #include -#include #include #include "../boolean.h" #include "../compat/strl.h" @@ -27,107 +26,8 @@ #include "rarch_console.h" -#define MAX_ARGS 32 - default_paths_t default_paths; -/*============================================================ - RetroArch MAIN WRAP - ============================================================ */ - -#ifdef HAVE_RARCH_MAIN_WRAP - -static int rarch_main_init_wrap(const struct rarch_main_wrap *args) -{ - int argc = 0; - char *argv[MAX_ARGS] = {NULL}; - - argv[argc++] = strdup("retroarch"); - - if (args->rom_path) - argv[argc++] = strdup(args->rom_path); - - if (args->sram_path) - { - argv[argc++] = strdup("-s"); - argv[argc++] = strdup(args->sram_path); - } - - if (args->state_path) - { - argv[argc++] = strdup("-S"); - argv[argc++] = strdup(args->state_path); - } - - if (args->config_path) - { - argv[argc++] = strdup("-c"); - argv[argc++] = strdup(args->config_path); - } - - if (args->verbose) - argv[argc++] = strdup("-v"); - -#ifdef HAVE_FILE_LOGGER - RARCH_LOG("foo\n"); - for(int i = 0; i < argc; i++) - RARCH_LOG("arg #%d: %s\n", i, argv[i]); - RARCH_LOG("bar\n"); -#endif - - int ret = rarch_main_init(argc, argv); - - char **tmp = argv; - while (*tmp) - { - free(*tmp); - tmp++; - } - - return ret; -} - -bool rarch_startup (const char * config_path) -{ - bool retval = false; - - if(g_console.initialize_rarch_enable) - { - if(g_console.emulator_initialized) - rarch_main_deinit(); - - struct rarch_main_wrap args = {0}; - - args.verbose = g_extern.verbose; - args.config_path = config_path; - args.sram_path = g_console.default_sram_dir_enable ? g_console.default_sram_dir : NULL, - args.state_path = g_console.default_savestate_dir_enable ? g_console.default_savestate_dir : NULL, - args.rom_path = g_console.rom_path; - - int init_ret = rarch_main_init_wrap(&args); - (void)init_ret; - - if(init_ret == 0) - { - g_console.emulator_initialized = 1; - g_console.initialize_rarch_enable = 0; - retval = true; - } - else - { - //failed to load the ROM for whatever reason - g_console.emulator_initialized = 0; - g_console.mode_switch = MODE_MENU; - rarch_settings_msg(S_MSG_ROM_LOADING_ERROR, S_DELAY_180); - } - } - - return retval; -} - - -#endif - #ifdef HAVE_RARCH_EXEC #ifdef __CELLOS_LV2__ diff --git a/console/rarch_console.h b/console/rarch_console.h index d190c6a15c..9b3424290d 100644 --- a/console/rarch_console.h +++ b/console/rarch_console.h @@ -92,20 +92,6 @@ enum { #define MENU_ITEM_LAST MENU_ITEM_RETURN_TO_DASHBOARD+1 -#ifdef HAVE_RARCH_MAIN_WRAP - -struct rarch_main_wrap -{ - const char *rom_path; - const char *sram_path; - const char *state_path; - const char *config_path; - bool verbose; -}; - -bool rarch_startup (const char * config_path); -#endif - #ifdef HAVE_RARCH_EXEC void rarch_exec (void); #endif diff --git a/console/rarch_console_main_wrap.c b/console/rarch_console_main_wrap.c new file mode 100644 index 0000000000..b32fe8a593 --- /dev/null +++ b/console/rarch_console_main_wrap.c @@ -0,0 +1,110 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2012 - Hans-Kristian Arntzen + * Copyright (C) 2011-2012 - 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 . + */ + +#include +#include + +#include "rarch_console_main_wrap.h" + +#define MAX_ARGS 32 + +static int rarch_main_init_wrap(const struct rarch_main_wrap *args) +{ + int argc = 0; + char *argv[MAX_ARGS] = {NULL}; + + argv[argc++] = strdup("retroarch"); + + if (args->rom_path) + argv[argc++] = strdup(args->rom_path); + + if (args->sram_path) + { + argv[argc++] = strdup("-s"); + argv[argc++] = strdup(args->sram_path); + } + + if (args->state_path) + { + argv[argc++] = strdup("-S"); + argv[argc++] = strdup(args->state_path); + } + + if (args->config_path) + { + argv[argc++] = strdup("-c"); + argv[argc++] = strdup(args->config_path); + } + + if (args->verbose) + argv[argc++] = strdup("-v"); + +#ifdef HAVE_FILE_LOGGER + RARCH_LOG("foo\n"); + for(int i = 0; i < argc; i++) + RARCH_LOG("arg #%d: %s\n", i, argv[i]); + RARCH_LOG("bar\n"); +#endif + + int ret = rarch_main_init(argc, argv); + + char **tmp = argv; + while (*tmp) + { + free(*tmp); + tmp++; + } + + return ret; +} + +bool rarch_startup (const char * config_path) +{ + bool retval = false; + + if(g_console.initialize_rarch_enable) + { + if(g_console.emulator_initialized) + rarch_main_deinit(); + + struct rarch_main_wrap args = {0}; + + args.verbose = g_extern.verbose; + args.config_path = config_path; + args.sram_path = g_console.default_sram_dir_enable ? g_console.default_sram_dir : NULL, + args.state_path = g_console.default_savestate_dir_enable ? g_console.default_savestate_dir : NULL, + args.rom_path = g_console.rom_path; + + int init_ret = rarch_main_init_wrap(&args); + (void)init_ret; + + if(init_ret == 0) + { + g_console.emulator_initialized = 1; + g_console.initialize_rarch_enable = 0; + retval = true; + } + else + { + //failed to load the ROM for whatever reason + g_console.emulator_initialized = 0; + g_console.mode_switch = MODE_MENU; + rarch_settings_msg(S_MSG_ROM_LOADING_ERROR, S_DELAY_180); + } + } + + return retval; +} diff --git a/console/rarch_console_main_wrap.h b/console/rarch_console_main_wrap.h new file mode 100644 index 0000000000..919cb84fac --- /dev/null +++ b/console/rarch_console_main_wrap.h @@ -0,0 +1,31 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2012 - Hans-Kristian Arntzen + * Copyright (C) 2011-2012 - 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 . + */ + +#ifndef RARCH_CONSOLE_MAIN_WRAP_H__ +#define RARCH_CONSOLE_MAIN_WRAP_H__ + +struct rarch_main_wrap +{ + const char *rom_path; + const char *sram_path; + const char *state_path; + const char *config_path; + bool verbose; +}; + +bool rarch_startup (const char * config_path); + +#endif diff --git a/ps3/frontend/main.c b/ps3/frontend/main.c index f871e89b4a..c36b3691c6 100644 --- a/ps3/frontend/main.c +++ b/ps3/frontend/main.c @@ -49,6 +49,7 @@ #include "../../console/rarch_console_input.h" #include "../../console/rarch_console_config.h" #include "../../console/rarch_console_settings.h" +#include "../../console/rarch_console_main_wrap.h" #include "../../console/rarch_console_video.h" #include "../../conf/config_file.h" #include "../../conf/config_file_macros.h" diff --git a/wii/frontend/main.c b/wii/frontend/main.c index d2c816d5cc..7d0381b298 100644 --- a/wii/frontend/main.c +++ b/wii/frontend/main.c @@ -23,6 +23,7 @@ #include "../../libretro.h" #include "../../console/rarch_console_input.h" +#include "../../console/rarch_console_main_wrap.h" #include #include diff --git a/xdk/frontend/main.c b/xdk/frontend/main.c index 7f070df6db..696ab33454 100644 --- a/xdk/frontend/main.c +++ b/xdk/frontend/main.c @@ -39,6 +39,7 @@ #include "../../console/rarch_console.h" #include "../../console/rarch_console_config.h" +#include "../../console/rarch_console_main_wrap.h" #include "../../conf/config_file.h" #include "../../conf/config_file_macros.h" #include "../../file.h"