209 lines
5.3 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
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>
#include "rgui.h"
2012-06-23 21:06:38 +02:00
#include "../../driver.h"
#include "../../general.h"
#include "../../libretro.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>
2011-12-14 14:52:58 +01:00
#include <sdcard/wiisd_io.h>
#include <sdcard/gcsd.h>
#include <fat.h>
2012-01-08 00:57:44 +01:00
#ifdef HAVE_FILE_LOGGER
FILE * log_fp;
#endif
2012-05-06 04:04:33 +02:00
static uint16_t menu_framebuf[RGUI_WIDTH * RGUI_HEIGHT];
2012-01-08 00:57:44 +01:00
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)
{
(void)userdata;
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;
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;
}
static bool get_rom_path(rgui_handle_t *rgui)
2012-01-08 00:57:44 +01:00
{
uint16_t old_input_state = 0;
2012-01-08 01:32:45 +01:00
bool can_quit = false;
2012-07-16 17:57:43 -04:00
bool first = true;
2012-01-08 01:07:26 +01:00
2012-01-08 00:57:44 +01:00
for (;;)
{
2012-01-08 01:07:26 +01:00
uint16_t input_state = 0;
2012-01-08 00:57:44 +01:00
input_wii.poll(NULL);
2012-04-21 23:25:32 +02:00
if (input_wii.key_pressed(NULL, RARCH_QUIT_KEY))
2012-01-08 01:32:45 +01:00
{
if (can_quit)
return false;
2012-01-08 01:32:45 +01:00
}
else
can_quit = true;
2012-01-08 00:57:44 +01:00
2012-04-21 23:25:32 +02:00
for (unsigned i = 0; i < RARCH_FIRST_META_KEY; i++)
2012-01-08 00:57:44 +01:00
{
input_state |= input_wii.input_state(NULL, NULL, false,
2012-04-10 03:14:21 +02:00
RETRO_DEVICE_JOYPAD, 0, i) ? (1 << i) : 0;
2012-01-08 00:57:44 +01:00
}
uint16_t trigger_state = input_state & ~old_input_state;
2012-05-06 04:04:33 +02:00
rgui_action_t action = RGUI_ACTION_NOOP;
2012-04-10 03:14:21 +02:00
if (trigger_state & (1 << RETRO_DEVICE_ID_JOYPAD_B))
2012-05-06 04:04:33 +02:00
action = RGUI_ACTION_CANCEL;
2012-04-10 03:14:21 +02:00
else if (trigger_state & (1 << RETRO_DEVICE_ID_JOYPAD_A))
2012-05-06 04:04:33 +02:00
action = RGUI_ACTION_OK;
2012-04-10 03:14:21 +02:00
else if (trigger_state & (1 << RETRO_DEVICE_ID_JOYPAD_UP))
2012-05-06 04:04:33 +02:00
action = RGUI_ACTION_UP;
2012-04-10 03:14:21 +02:00
else if (trigger_state & (1 << RETRO_DEVICE_ID_JOYPAD_DOWN))
2012-05-06 04:04:33 +02:00
action = RGUI_ACTION_DOWN;
else if (trigger_state & (1 << RETRO_DEVICE_ID_JOYPAD_LEFT))
action = RGUI_ACTION_LEFT;
else if (trigger_state & (1 << RETRO_DEVICE_ID_JOYPAD_RIGHT))
action = RGUI_ACTION_RIGHT;
else if (trigger_state & (1 << RETRO_DEVICE_ID_JOYPAD_START))
action = RGUI_ACTION_START;
2012-07-16 17:57:43 -04:00
else if (trigger_state & (1 << RETRO_DEVICE_ID_JOYPAD_SELECT) && !first) // don't catch start+select+l+r when exiting
action = RGUI_ACTION_SETTINGS;
2012-01-08 00:57:44 +01:00
2012-05-06 04:04:33 +02:00
const char *ret = rgui_iterate(rgui, action);
2012-01-08 00:57:44 +01:00
video_wii.frame(NULL, menu_framebuf,
2012-05-06 04:04:33 +02:00
RGUI_WIDTH, RGUI_HEIGHT,
RGUI_WIDTH * sizeof(uint16_t), NULL);
2012-01-08 00:57:44 +01:00
if (ret)
{
g_console.initialize_rarch_enable = true;
strlcpy(g_console.rom_path, ret, sizeof(g_console.rom_path));
if (rarch_startup(NULL))
return true;
}
2012-01-08 00:57:44 +01:00
old_input_state = input_state;
2012-07-16 17:57:43 -04:00
first = false;
2012-04-21 23:25:32 +02:00
rarch_sleep(10);
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
extern uint8_t _binary_console_font_bmp_start[];
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-01-08 00:57:44 +01:00
#ifdef HAVE_FILE_LOGGER
g_extern.verbose = true;
log_fp = fopen("/retroarch-log.txt", "w");
#endif
config_set_defaults();
g_settings.audio.rate_control = true;
g_settings.audio.rate_control_delta = 0.004;
g_console.block_config_read = true;
2012-01-08 00:57:44 +01:00
wii_video_init();
2012-05-28 05:06:25 +02:00
input_wii.init();
2012-01-08 00:57:44 +01:00
rgui_handle_t *rgui = rgui_init("",
2012-05-06 04:04:33 +02:00
menu_framebuf, RGUI_WIDTH * sizeof(uint16_t),
2012-01-08 00:57:44 +01:00
_binary_console_font_bmp_start, folder_cb, NULL);
rgui_iterate(rgui, RGUI_ACTION_REFRESH);
2012-01-08 00:57:44 +01:00
int ret = 0;
while (get_rom_path(rgui) && ret == 0)
2012-01-08 00:57:44 +01:00
{
2012-04-13 23:16:51 +02:00
bool repeat = false;
input_wii.poll(NULL);
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-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
2012-01-08 00:57:44 +01:00
wii_video_deinit();
2012-05-28 05:06:25 +02:00
input_wii.free(NULL);
2012-01-08 00:57:44 +01:00
#ifdef HAVE_FILE_LOGGER
fclose(log_fp);
#endif
2012-05-06 04:04:33 +02:00
rgui_free(rgui);
2012-01-08 00:57:44 +01:00
return ret;
2011-12-14 12:49:13 +01:00
}