forked from satiator/satiator-menu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
133 lines (115 loc) · 3.42 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
#include <iapetus.h>
#include <stdio.h>
#include "satiator.h"
#include <string.h>
#include "cdparse.h"
#include "fade.h"
#include "syscall.h"
#include "gmenu.h"
#include "jhloader.h"
int image_file_filter(file_ent *entry) {
if (entry->isdir)
return 1;
int len = strlen(entry->name);
if (!strcasecmp(&entry->name[len-4], ".cue"))
return 1;
if (!strcasecmp(&entry->name[len-4], ".iso"))
return 1;
return 0;
}
void launch_game(const char *filename) {
dbgprintf("Loading ISO: '%s'\n", filename);
int ret = image2desc(filename, "out.desc");
if (ret) {
menu_error("Disc load failed!", cdparse_error_string ? cdparse_error_string : "Unknown error");
return;
}
fadeout(0x20);
restore_vdp_mem();
s_emulate("out.desc");
while (is_cd_present());
while (!is_cd_present());
s_mode(s_cdrom);
ret = boot_disc();
s_mode(s_api); // failed, restore order
s_emulate(""); // close the old file
fadein(0x20);
const char *error = "Unknown error";
switch(ret) {
case BOOT_BAD_HEADER:
error = "Bad disc header. Bad image?";
break;
case BOOT_BAD_REGION:
error = "Wrong region.";
break;
case BOOT_BAD_SECURITY_CODE:
error = "Bad security code. Bad image?";
break;
}
menu_error("Boot failed!", error);
}
char pathbuf[512];
void image_menu(void) {
char *name = NULL;
strcpy(pathbuf, "/");
for(;;) {
int nents;
file_ent *list = file_list_create(".", &nents, image_file_filter);
if (nents == 1 && strcmp(pathbuf, "/") && !list[0].isdir)
launch_game(list[0].name);
file_list_sort(list, nents);
char namebuf[32];
strcpy(namebuf, "Satiator - ");
char *dirname = strrchr(pathbuf, '/');
if (dirname[1])
dirname++;
strlcat(namebuf, dirname, sizeof(namebuf));
int entry = menu_picklist(list, nents, namebuf);
int ret;
if (entry == -1) {
if (!strcmp(pathbuf, "/")) {
return;
} else {
char *last_slash = strrchr(pathbuf, '/');
if (last_slash == pathbuf)
last_slash++;
*last_slash = '\0';
s_chdir(pathbuf);
}
} else if (list[entry].isdir) {
// Got to strip the slash :(
list[entry].name[strlen(list[entry].name) - 1] = '\0';
if (pathbuf[1])
strcat(pathbuf, "/");
strcat(pathbuf, list[entry].name);
ret = s_chdir(pathbuf);
if (ret != FR_OK) {
menu_error("chdir", "Can't change directory, corrupt SD card?");
}
}
else
name = strdup(list[entry].name);
file_list_free(list, nents);
if (name) {
launch_game(name);
free(name);
name = NULL;
}
}
}
void ar_menu(void);
const file_ent top_menu_options[] = {
{"Browse images", 0, &image_menu},
{"Action Replay tools", 0, &ar_menu},
};
void main_menu(void) {
menu_init();
image_menu();
while (1) {
int entry = menu_picklist(top_menu_options, sizeof(top_menu_options)/sizeof(*top_menu_options), "Satiator");
if (entry == -1)
continue;
void (*submenu)(void) = top_menu_options[entry].priv;
submenu();
}
}