forked from libretro/RetroArch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
174 lines (138 loc) · 4.28 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* 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 <http://www.gnu.org/licenses/>.
*/
#undef main
#include <stdbool.h>
#include "../console/sgui/sgui.h"
#include "../driver.h"
#include "../general.h"
#include "../libretro.h"
#include "driver.h"
#include <stdlib.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
#include <sdcard/wiisd_io.h>
#include <sdcard/gcsd.h>
#include <fat.h>
#ifdef HAVE_FILE_LOGGER
FILE * log_fp;
#endif
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;
bool can_quit = false;
sgui_iterate(sgui, SGUI_ACTION_REFRESH);
for (;;)
{
uint16_t input_state = 0;
input_wii.poll(NULL);
if (input_wii.key_pressed(NULL, RARCH_QUIT_KEY))
{
if (can_quit)
return NULL;
}
else
can_quit = true;
for (unsigned i = 0; i < RARCH_FIRST_META_KEY; i++)
{
input_state |= input_wii.input_state(NULL, NULL, false,
RETRO_DEVICE_JOYPAD, 0, i) ? (1 << i) : 0;
}
uint16_t trigger_state = input_state & ~old_input_state;
sgui_action_t action = SGUI_ACTION_NOOP;
if (trigger_state & (1 << RETRO_DEVICE_ID_JOYPAD_B))
action = SGUI_ACTION_CANCEL;
else if (trigger_state & (1 << RETRO_DEVICE_ID_JOYPAD_A))
action = SGUI_ACTION_OK;
else if (trigger_state & (1 << RETRO_DEVICE_ID_JOYPAD_UP))
action = SGUI_ACTION_UP;
else if (trigger_state & (1 << RETRO_DEVICE_ID_JOYPAD_DOWN))
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;
rarch_sleep(10);
}
}
int rarch_main(int argc, char **argv);
extern uint8_t _binary_console_font_bmp_start[];
int main(void)
{
fatInitDefault();
#ifdef HAVE_FILE_LOGGER
g_extern.verbose = true;
log_fp = fopen("sd:/ssnes-log.txt", "w");
#endif
wii_video_init();
wii_input_init();
sgui_handle_t *sgui = sgui_init("sd:/",
menu_framebuf, SGUI_WIDTH * sizeof(uint16_t),
_binary_console_font_bmp_start, folder_cb, NULL);
const char *rom_path;
int ret = 0;
while ((rom_path = get_rom_path(sgui)) && ret == 0)
{
g_console.initialize_rarch_enable = true;
strlcpy(g_console.rom_path, rom_path, sizeof(g_console.rom_path));
rarch_startup(NULL);
bool repeat = false;
input_wii.poll(NULL);
do{
repeat = rarch_main_iterate();
}while(repeat && !g_console.frame_advance_enable);
}
if(g_console.emulator_initialized)
rarch_main_deinit();
wii_input_deinit();
wii_video_deinit();
#ifdef HAVE_FILE_LOGGER
fclose(log_fp);
#endif
sgui_free(sgui);
return ret;
}