382 lines
11 KiB
C
Raw Normal View History

2012-04-21 23:13:50 +02:00
/* RetroArch - A frontend for libretro.
2012-01-08 01:08:18 +01:00
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
2012-07-26 17:07:47 -04:00
* Copyright (C) 2012 - Michael Lelli
2011-12-14 12:49:13 +01:00
*
2012-04-21 23:13:50 +02:00
* RetroArch is free software: you can redistribute it and/or modify it under the terms
2011-12-14 12:49:13 +01: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 23:13:50 +02:00
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
2011-12-14 12:49:13 +01: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 23:31:57 +02:00
* You should have received a copy of the GNU General Public License along with RetroArch.
2011-12-14 12:49:13 +01:00
* If not, see <http://www.gnu.org/licenses/>.
*/
#undef main
2012-01-08 00:57:44 +01:00
#include <stdbool.h>
2012-06-23 21:06:38 +02:00
#include "../../driver.h"
#include "../../general.h"
#include "../../libretro.h"
#include "../../console/rgui/rgui.h"
#include "../../console/rarch_console_exec.h"
#include "../../console/rarch_console_input.h"
#include "../../console/rarch_console_main_wrap.h"
2012-01-08 00:57:44 +01:00
2011-12-14 16:01:16 +01:00
#include <stdlib.h>
2011-12-14 12:49:13 +01:00
#include <stddef.h>
2012-01-08 00:57:44 +01:00
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
2012-08-07 05:27:27 +02:00
#ifdef HW_RVL
2011-12-14 14:52:58 +01:00
#include <sdcard/wiisd_io.h>
2012-08-07 05:27:27 +02:00
#endif
2011-12-14 14:52:58 +01:00
#include <sdcard/gcsd.h>
#include <fat.h>
2012-01-08 00:57:44 +01:00
#ifdef HAVE_FILE_LOGGER
FILE * log_fp;
#endif
2012-08-07 13:12:51 -04:00
uint32_t menu_framebuf[320 * 240];
2012-08-07 23:40:17 -04:00
rgui_handle_t *rgui;
2012-01-08 00:57:44 +01:00
2012-07-30 23:00:20 -04:00
char app_dir[PATH_MAX];
2012-07-26 17:07:47 -04:00
static const struct retro_keybind _wii_nav_binds[] = {
2012-08-06 22:00:35 +02:00
{ 0, 0, 0, GX_GC_UP | GX_GC_LSTICK_UP | GX_GC_RSTICK_UP | GX_CLASSIC_UP | GX_CLASSIC_LSTICK_UP | GX_CLASSIC_RSTICK_UP | GX_WIIMOTE_UP | GX_NUNCHUK_UP, 0 },
{ 0, 0, 0, GX_GC_DOWN | GX_GC_LSTICK_DOWN | GX_GC_RSTICK_DOWN | GX_CLASSIC_DOWN | GX_CLASSIC_LSTICK_DOWN | GX_CLASSIC_RSTICK_DOWN | GX_WIIMOTE_DOWN | GX_NUNCHUK_DOWN, 0 },
{ 0, 0, 0, GX_GC_LEFT | GX_GC_LSTICK_LEFT | GX_GC_RSTICK_LEFT | GX_CLASSIC_LEFT | GX_CLASSIC_LSTICK_LEFT | GX_CLASSIC_RSTICK_LEFT | GX_WIIMOTE_LEFT | GX_NUNCHUK_LEFT, 0 },
{ 0, 0, 0, GX_GC_RIGHT | GX_GC_LSTICK_RIGHT | GX_GC_RSTICK_RIGHT | GX_CLASSIC_RIGHT | GX_CLASSIC_LSTICK_RIGHT | GX_CLASSIC_RSTICK_RIGHT | GX_WIIMOTE_RIGHT | GX_NUNCHUK_RIGHT, 0 },
{ 0, 0, 0, GX_GC_A | GX_CLASSIC_A | GX_WIIMOTE_A | GX_WIIMOTE_2, 0 },
{ 0, 0, 0, GX_GC_B | GX_CLASSIC_B | GX_WIIMOTE_B | GX_WIIMOTE_1, 0 },
{ 0, 0, 0, GX_GC_START | GX_CLASSIC_PLUS | GX_WIIMOTE_PLUS, 0 },
{ 0, 0, 0, GX_GC_Z_TRIGGER | GX_CLASSIC_MINUS | GX_WIIMOTE_MINUS, 0 },
{ 0, 0, 0, GX_WIIMOTE_HOME | GX_CLASSIC_HOME, 0 },
2012-07-26 17:07:47 -04:00
};
static const struct retro_keybind *wii_nav_binds[] = {
_wii_nav_binds
};
enum
{
2012-08-06 22:00:35 +02:00
GX_DEVICE_NAV_UP = 0,
GX_DEVICE_NAV_DOWN,
GX_DEVICE_NAV_LEFT,
GX_DEVICE_NAV_RIGHT,
GX_DEVICE_NAV_A,
GX_DEVICE_NAV_B,
GX_DEVICE_NAV_START,
GX_DEVICE_NAV_SELECT,
GX_DEVICE_NAV_EXIT,
GX_DEVICE_NAV_LAST
};
2012-08-07 23:40:17 -04:00
extern uint8_t _binary_console_font_bmp_start[];
2012-05-06 04:04:33 +02:00
static bool folder_cb(const char *directory, rgui_file_enum_cb_t file_cb,
2012-01-08 00:57:44 +01:00
void *userdata, void *ctx)
{
bool core_chooser = (userdata) ? *(rgui_file_type_t *)userdata == RGUI_SETTINGS_CORE : false;
2012-01-08 00:57:44 +01:00
if (!*directory)
{
#ifdef HW_RVL
file_cb(ctx, "sd:", RGUI_FILE_DEVICE, 0);
file_cb(ctx, "usb:", RGUI_FILE_DEVICE, 0);
#endif
file_cb(ctx, "carda:", RGUI_FILE_DEVICE, 0);
file_cb(ctx, "cardb:", RGUI_FILE_DEVICE, 0);
return true;
}
char _dir[PATH_MAX];
snprintf(_dir, sizeof(_dir), "%s/", directory);
DIR *dir = opendir(_dir);
2012-01-08 00:57:44 +01:00
if (!dir)
return false;
struct dirent *entry;
while ((entry = readdir(dir)))
{
char stat_path[PATH_MAX];
snprintf(stat_path, sizeof(stat_path), "%s/%s", directory, entry->d_name);
struct stat st;
if (stat(stat_path, &st) < 0)
continue;
if (!S_ISDIR(st.st_mode) && !S_ISREG(st.st_mode))
continue;
if (core_chooser && (strstr(entry->d_name, ".dol") != entry->d_name + strlen(entry->d_name) - 4 ||
strcasecmp(entry->d_name, "boot.dol") == 0))
continue;
2012-01-08 00:57:44 +01:00
file_cb(ctx,
entry->d_name, S_ISDIR(st.st_mode) ?
RGUI_FILE_DIRECTORY : RGUI_FILE_PLAIN, 0);
2012-01-08 00:57:44 +01:00
}
closedir(dir);
return true;
}
2012-08-07 23:40:17 -04:00
static void menu_loop(void)
2012-01-08 00:57:44 +01:00
{
gx_video_t *gx = (gx_video_t*)driver.video_data;
2012-08-07 23:40:17 -04:00
uint64_t old_input_state = 0;
2012-07-16 17:57:43 -04:00
bool first = true;
2012-01-08 01:07:26 +01:00
2012-08-07 23:40:17 -04:00
g_console.menu_enable = true;
if(g_console.ingame_menu_enable)
{
//TODO: fill in some stuff here to bring up ingame menu
}
gx->menu_render = true;
2012-08-07 23:40:17 -04:00
do
2012-01-08 00:57:44 +01:00
{
2012-08-07 23:40:17 -04:00
uint64_t input_state = 0;
2012-01-08 00:57:44 +01:00
input_gx.poll(NULL);
2012-07-26 17:07:47 -04:00
2012-08-06 22:00:35 +02:00
for (unsigned i = 0; i < GX_DEVICE_NAV_LAST; i++)
2012-01-08 01:32:45 +01:00
{
input_state |= input_gx.input_state(NULL, wii_nav_binds, 0,
2012-07-26 17:07:47 -04:00
RETRO_DEVICE_JOYPAD, 0, i) ? (1 << i) : 0;
2012-01-08 01:32:45 +01:00
}
2012-01-08 00:57:44 +01:00
2012-08-07 23:40:17 -04:00
static const struct retro_keybind _quit_binds[] = {
{ 0, 0, (enum retro_key)0, (GX_CLASSIC_HOME), 0 },
{ 0, 0, (enum retro_key)0, (GX_WIIMOTE_HOME), 0 },
{ 0, 0, (enum retro_key)0, (GX_QUIT_KEY), 0 },
2012-08-07 23:40:17 -04:00
};
const struct retro_keybind *quit_binds[] = {
_quit_binds
2012-08-07 23:40:17 -04:00
};
input_state |= input_gx.input_state(NULL, quit_binds, false,
2012-08-07 23:40:17 -04:00
RETRO_DEVICE_JOYPAD, 0, 0) ? (GX_CLASSIC_HOME) : 0;
input_state |= input_gx.input_state(NULL, quit_binds, false,
2012-08-07 23:40:17 -04:00
RETRO_DEVICE_JOYPAD, 0, 1) ? (GX_WIIMOTE_HOME) : 0;
input_state |= input_gx.input_state(NULL, quit_binds, false,
RETRO_DEVICE_JOYPAD, 0, 2) ? (GX_QUIT_KEY) : 0;
2012-08-07 23:40:17 -04:00
uint64_t trigger_state = input_state & ~old_input_state;
2012-07-26 17:07:47 -04:00
rgui_action_t action = RGUI_ACTION_NOOP;
2012-07-26 17:07:47 -04:00
// don't run anything first frame, only capture held inputs for old_input_state
if (!first)
2012-01-08 00:57:44 +01:00
{
2012-08-06 22:00:35 +02:00
if (trigger_state & (1 << GX_DEVICE_NAV_EXIT))
2012-08-07 23:40:17 -04:00
g_console.mode_switch = MODE_EXIT;
2012-01-08 00:57:44 +01:00
2012-08-06 22:00:35 +02:00
if (trigger_state & (1 << GX_DEVICE_NAV_B))
2012-07-26 17:07:47 -04:00
action = RGUI_ACTION_CANCEL;
2012-08-06 22:00:35 +02:00
else if (trigger_state & (1 << GX_DEVICE_NAV_A))
2012-07-26 17:07:47 -04:00
action = RGUI_ACTION_OK;
2012-08-06 22:00:35 +02:00
else if (trigger_state & (1 << GX_DEVICE_NAV_UP))
2012-07-26 17:07:47 -04:00
action = RGUI_ACTION_UP;
2012-08-06 22:00:35 +02:00
else if (trigger_state & (1 << GX_DEVICE_NAV_DOWN))
2012-07-26 17:07:47 -04:00
action = RGUI_ACTION_DOWN;
2012-08-06 22:00:35 +02:00
else if (trigger_state & (1 << GX_DEVICE_NAV_LEFT))
2012-07-26 17:07:47 -04:00
action = RGUI_ACTION_LEFT;
2012-08-06 22:00:35 +02:00
else if (trigger_state & (1 << GX_DEVICE_NAV_RIGHT))
2012-07-26 17:07:47 -04:00
action = RGUI_ACTION_RIGHT;
2012-08-06 22:00:35 +02:00
else if (trigger_state & (1 << GX_DEVICE_NAV_START))
2012-07-26 17:07:47 -04:00
action = RGUI_ACTION_START;
2012-08-06 22:00:35 +02:00
else if (trigger_state & (1 << GX_DEVICE_NAV_SELECT))
2012-07-26 17:07:47 -04:00
action = RGUI_ACTION_SETTINGS;
}
else
{
first = false;
}
2012-01-08 00:57:44 +01:00
2012-05-06 04:04:33 +02:00
const char *ret = rgui_iterate(rgui, action);
2012-08-07 23:40:17 -04:00
(void)ret;
rarch_render_cached_frame();
2012-01-08 00:57:44 +01:00
2012-08-07 23:40:17 -04:00
old_input_state = input_state;
bool goto_menu_key_pressed = ((trigger_state & GX_WIIMOTE_HOME) || (trigger_state & GX_CLASSIC_HOME)) ? true : false;
bool quit_key_pressed = (trigger_state & GX_QUIT_KEY) ? true : false;
2012-08-07 23:40:17 -04:00
if(IS_TIMER_EXPIRED(gx))
{
// if we want to force goto the emulation loop, skip this
if(g_console.mode_switch != MODE_EMULATION)
{
if(goto_menu_key_pressed)
2012-08-07 23:40:17 -04:00
{
g_console.menu_enable = (goto_menu_key_pressed && g_console.emulator_initialized) ? false : true;
2012-08-07 23:40:17 -04:00
g_console.mode_switch = g_console.menu_enable ? MODE_MENU : MODE_EMULATION;
}
}
}
if(quit_key_pressed)
{
g_console.menu_enable = false;
g_console.mode_switch = MODE_EXIT;
}
2012-08-07 23:40:17 -04:00
// set a timer delay so that we don't instantly switch back to the menu when
// press and holding QUIT in the emulation loop (lasts for 30 frame ticks)
if(g_console.mode_switch == MODE_EMULATION)
{
2012-08-07 23:40:17 -04:00
SET_TIMER_EXPIRATION(gx, 30);
}
2012-08-07 23:40:17 -04:00
}while(g_console.menu_enable);
gx->menu_render = false;
g_console.ingame_menu_enable = false;
}
static void menu_init(void)
{
rgui = rgui_init("",
menu_framebuf, RGUI_WIDTH * sizeof(uint32_t),
_binary_console_font_bmp_start, folder_cb, NULL);
rgui_iterate(rgui, RGUI_ACTION_REFRESH);
g_console.mode_switch = MODE_MENU;
}
static void menu_free(void)
{
rgui_free(rgui);
2012-01-08 00:57:44 +01:00
}
2011-12-14 12:49:13 +01:00
2012-04-21 23:25:32 +02:00
int rarch_main(int argc, char **argv);
2011-12-14 12:49:13 +01:00
2012-01-08 00:57:44 +01:00
2012-07-27 19:15:42 +02:00
static void get_environment_settings(void)
{
getcwd(default_paths.port_dir, MAXPATHLEN);
snprintf(default_paths.core_dir, sizeof(default_paths.core_dir), default_paths.port_dir);
2012-07-27 19:15:42 +02:00
snprintf(default_paths.config_file, sizeof(default_paths.config_file), "%sretroarch.cfg", default_paths.port_dir);
snprintf(default_paths.system_dir, sizeof(default_paths.system_dir), "%s/system", default_paths.core_dir);
snprintf(default_paths.savestate_dir, sizeof(default_paths.savestate_dir), "%s/savestates", default_paths.core_dir);
snprintf(default_paths.filesystem_root_dir, sizeof(default_paths.filesystem_root_dir), "/");
snprintf(default_paths.filebrowser_startup_dir, sizeof(default_paths.filebrowser_startup_dir), default_paths.filesystem_root_dir);
2012-07-27 19:15:42 +02:00
snprintf(default_paths.sram_dir, sizeof(default_paths.sram_dir), "%s/sram", default_paths.core_dir);
snprintf(default_paths.input_presets_dir, sizeof(default_paths.input_presets_dir), "%s/presets/input", default_paths.core_dir);
strlcpy(default_paths.executable_extension, ".dol", sizeof(default_paths.executable_extension));
}
2011-12-14 12:49:13 +01:00
int main(void)
{
2012-06-29 19:10:41 -04:00
#ifdef HW_RVL
2012-06-29 18:42:42 -04:00
L2Enhance();
2012-06-29 19:10:41 -04:00
#endif
2011-12-14 19:11:46 +01:00
fatInitDefault();
2012-07-30 23:00:20 -04:00
getcwd(app_dir, sizeof(app_dir));
2012-01-08 00:57:44 +01:00
2012-07-27 19:15:42 +02:00
get_environment_settings();
2012-07-27 17:51:36 -04:00
#ifdef HAVE_LOGGER
g_extern.verbose = true;
2012-07-27 17:51:36 -04:00
logger_init();
#endif
#ifdef HAVE_FILE_LOGGER
g_extern.verbose = true;
log_fp = fopen("/retroarch-log.txt", "w");
#endif
config_set_defaults();
input_gx.init();
video_gx.start();
2012-08-07 13:12:51 -04:00
gx_video_t *gx = (gx_video_t*)driver.video_data;
gx->menu_data = menu_framebuf;
char tmp_path[PATH_MAX];
const char *extension = default_paths.executable_extension;
snprintf(tmp_path, sizeof(tmp_path), default_paths.core_dir);
const char *path_prefix = tmp_path;
char full_path[1024];
snprintf(full_path, sizeof(full_path), "%sCORE%s", path_prefix, extension);
bool find_libretro_file = rarch_configure_libretro_core(full_path, path_prefix, path_prefix,
default_paths.config_file, extension);
rarch_settings_set_default(&input_gx);
rarch_config_load(default_paths.config_file, path_prefix, extension, find_libretro_file);
init_libretro_sym();
2012-01-08 00:57:44 +01:00
input_gx.post_init();
2012-08-07 23:40:17 -04:00
menu_init();
2012-07-27 19:15:42 +02:00
2012-08-07 23:40:17 -04:00
begin_loop:
if(g_console.mode_switch == MODE_EMULATION)
2012-01-08 00:57:44 +01:00
{
2012-04-13 23:16:51 +02:00
bool repeat = false;
input_gx.poll(NULL);
2012-08-07 23:40:17 -04:00
audio_start_func();
2012-04-13 23:16:51 +02:00
do{
2012-04-21 23:25:32 +02:00
repeat = rarch_main_iterate();
2012-04-13 23:16:51 +02:00
}while(repeat && !g_console.frame_advance_enable);
2012-06-25 15:27:41 -04:00
audio_stop_func();
2012-01-08 00:57:44 +01:00
}
2012-08-07 23:40:17 -04:00
else if(g_console.mode_switch == MODE_MENU)
{
menu_loop();
rarch_startup(default_paths.config_file);
}
else
goto begin_shutdown;
goto begin_loop;
2012-01-08 00:57:44 +01:00
2012-08-07 23:40:17 -04:00
begin_shutdown:
if(path_file_exists(default_paths.config_file))
rarch_config_save(default_paths.config_file);
2012-04-13 23:16:51 +02:00
if(g_console.emulator_initialized)
2012-04-21 23:25:32 +02:00
rarch_main_deinit();
2012-04-13 23:16:51 +02:00
input_gx.free(NULL);
video_gx.stop();
2012-08-07 23:40:17 -04:00
menu_free();
2012-01-08 00:57:44 +01:00
#ifdef HAVE_FILE_LOGGER
fclose(log_fp);
#endif
2012-07-27 17:51:36 -04:00
#ifdef HAVE_LOGGER
logger_shutdown();
#endif
if(g_console.return_to_launcher)
rarch_console_exec(g_console.launch_app_on_exit);
2012-08-07 23:40:17 -04:00
return 1;
2011-12-14 12:49:13 +01:00
}