RetroArch/wii/main.c

175 lines
4.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.
*
* You should have received a copy of the GNU General Public License along with SSNES.
* If not, see <http://www.gnu.org/licenses/>.
*/
#undef main
2012-01-08 00:57:44 +01:00
#include <stdbool.h>
2012-04-10 22:40:44 +02:00
#include "../console/sgui/sgui.h"
2012-01-08 00:57:44 +01:00
#include "../driver.h"
#include "../general.h"
#include "../libretro.h"
2012-01-08 00:57:44 +01:00
#include "driver.h"
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-01-08 00:57:44 +01:00
static uint16_t menu_framebuf[SGUI_WIDTH * SGUI_HEIGHT];
static bool folder_cb(const char *directory, sgui_file_enum_cb_t file_cb,
void *userdata, void *ctx)
{
(void)userdata;
DIR *dir = opendir(directory);
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) ?
SGUI_FILE_DIRECTORY : SGUI_FILE_PLAIN);
}
closedir(dir);
return true;
}
static const char *get_rom_path(sgui_handle_t *sgui)
{
uint16_t old_input_state = 0;
2012-01-08 01:32:45 +01:00
bool can_quit = false;
2012-01-08 01:07:26 +01:00
sgui_iterate(sgui, SGUI_ACTION_REFRESH);
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);
if (input_wii.key_pressed(NULL, SSNES_QUIT_KEY))
2012-01-08 01:32:45 +01:00
{
if (can_quit)
return NULL;
}
else
can_quit = true;
2012-01-08 00:57:44 +01:00
for (unsigned i = 0; i < SSNES_FIRST_META_KEY; i++)
{
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;
sgui_action_t action = SGUI_ACTION_NOOP;
2012-04-10 03:14:21 +02:00
if (trigger_state & (1 << RETRO_DEVICE_ID_JOYPAD_B))
2012-01-08 00:57:44 +01:00
action = SGUI_ACTION_CANCEL;
2012-04-10 03:14:21 +02:00
else if (trigger_state & (1 << RETRO_DEVICE_ID_JOYPAD_A))
2012-01-08 00:57:44 +01:00
action = SGUI_ACTION_OK;
2012-04-10 03:14:21 +02:00
else if (trigger_state & (1 << RETRO_DEVICE_ID_JOYPAD_UP))
2012-01-08 00:57:44 +01:00
action = SGUI_ACTION_UP;
2012-04-10 03:14:21 +02:00
else if (trigger_state & (1 << RETRO_DEVICE_ID_JOYPAD_DOWN))
2012-01-08 00:57:44 +01:00
action = SGUI_ACTION_DOWN;
const char *ret = sgui_iterate(sgui, action);
if (ret)
return ret;
video_wii.frame(NULL, menu_framebuf,
SGUI_WIDTH, SGUI_HEIGHT,
SGUI_WIDTH * sizeof(uint16_t), NULL);
old_input_state = input_state;
ssnes_sleep(10);
}
}
2011-12-14 12:49:13 +01:00
int ssnes_main(int argc, char **argv);
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)
{
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("sd:/ssnes-log.txt", "w");
#endif
2012-01-08 00:57:44 +01:00
wii_video_init();
wii_input_init();
2012-01-08 01:07:26 +01:00
sgui_handle_t *sgui = sgui_init("sd:/",
2012-01-08 00:57:44 +01:00
menu_framebuf, SGUI_WIDTH * sizeof(uint16_t),
_binary_console_font_bmp_start, folder_cb, NULL);
2012-01-08 01:32:45 +01:00
const char *rom_path;
2012-01-08 00:57:44 +01:00
int ret = 0;
2012-01-08 01:32:45 +01:00
while ((rom_path = get_rom_path(sgui)) && ret == 0)
2012-01-08 00:57:44 +01:00
{
2012-04-13 23:16:51 +02:00
g_console.initialize_ssnes_enable = true;
strlcpy(g_console.rom_path, rom_path, sizeof(g_console.rom_path));
ssnes_startup(NULL);
bool repeat = false;
input_wii.poll(NULL);
do{
repeat = ssnes_main_iterate();
}while(repeat && !g_console.frame_advance_enable);
2012-01-08 00:57:44 +01:00
}
2012-04-13 23:16:51 +02:00
if(g_console.emulator_initialized)
ssnes_main_deinit();
2012-01-08 00:57:44 +01:00
wii_input_deinit();
wii_video_deinit();
#ifdef HAVE_FILE_LOGGER
fclose(log_fp);
#endif
2012-01-08 00:57:44 +01:00
sgui_free(sgui);
return ret;
2011-12-14 12:49:13 +01:00
}