-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
227 lines (218 loc) · 5.67 KB
/
main.cpp
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/*
* REminiscence - Flashback interpreter
* Copyright (C) 2005-2015 Gregory Montoir ([email protected])
*/
#include <SDL.h>
#include <ctype.h>
#include <getopt.h>
#include <sys/stat.h>
#include "file.h"
#include "fs.h"
#include "game.h"
#include "scaler.h"
#include "systemstub.h"
#include "util.h"
static const char *USAGE =
"REminiscence - Flashback Interpreter\n"
"Usage: %s [OPTIONS]...\n"
" --datapath=PATH Path to data files (default 'DATA')\n"
" --savepath=PATH Path to save files (default '.')\n"
" --levelnum=NUM Start to level, bypass introduction\n"
" --fullscreen Fullscreen display\n"
" --scaler=INDEX Graphics scaler\n"
" --language=LANG Language (fr,en,de,sp,it)\n"
;
static int detectVersion(FileSystem *fs) {
static const struct {
const char *filename;
int type;
const char *name;
} table[] = {
{ "DEMO_UK.ABA", kResourceTypeDOS, "DOS (Demo)" },
{ "INTRO.SEQ", kResourceTypeDOS, "DOS CD" },
{ "LEVEL1.MAP", kResourceTypeDOS, "DOS" },
{ "LEVEL1.LEV", kResourceTypeAmiga, "Amiga" },
{ "DEMO.LEV", kResourceTypeAmiga, "Amiga (Demo)" },
{ 0, -1, 0 }
};
for (int i = 0; table[i].filename; ++i) {
File f;
if (f.open(table[i].filename, "rb", fs)) {
debug(DBG_INFO, "Detected %s version", table[i].name);
return table[i].type;
}
}
return -1;
}
static Language detectLanguage(FileSystem *fs) {
static const struct {
const char *filename;
Language language;
} table[] = {
// PC
{ "ENGCINE.TXT", LANG_EN },
{ "FR_CINE.TXT", LANG_FR },
{ "GERCINE.TXT", LANG_DE },
{ "SPACINE.TXT", LANG_SP },
{ "ITACINE.TXT", LANG_IT },
// Amiga
{ "FRCINE.TXT", LANG_FR },
{ 0, LANG_EN }
};
for (int i = 0; table[i].filename; ++i) {
File f;
if (f.open(table[i].filename, "rb", fs)) {
return table[i].language;
}
}
return LANG_EN;
}
Options g_options;
const char *g_caption = "REminiscence";
static void initOptions() {
// defaults
g_options.bypass_protection = true;
g_options.play_disabled_cutscenes = false;
g_options.enable_password_menu = false;
g_options.fade_out_palette = true;
g_options.use_text_cutscenes = false;
g_options.use_seq_cutscenes = true;
// read configuration file
struct {
const char *name;
bool *value;
} opts[] = {
{ "bypass_protection", &g_options.bypass_protection },
{ "play_disabled_cutscenes", &g_options.play_disabled_cutscenes },
{ "enable_password_menu", &g_options.enable_password_menu },
{ "fade_out_palette", &g_options.fade_out_palette },
{ "use_tiledata", &g_options.use_tiledata },
{ "use_text_cutscenes", &g_options.use_text_cutscenes },
{ "use_seq_cutscenes", &g_options.use_seq_cutscenes },
{ 0, 0 }
};
static const char *filename = "rs.cfg";
FILE *fp = fopen(filename, "rb");
if (fp) {
char buf[256];
while (fgets(buf, sizeof(buf), fp)) {
if (buf[0] == '#') {
continue;
}
const char *p = strchr(buf, '=');
if (p) {
++p;
while (*p && isspace(*p)) {
++p;
}
if (*p) {
const bool value = (*p == 't' || *p == 'T' || *p == '1');
for (int i = 0; opts[i].name; ++i) {
if (strncmp(buf, opts[i].name, strlen(opts[i].name)) == 0) {
*opts[i].value = value;
break;
}
}
}
}
}
fclose(fp);
}
}
static const int DEFAULT_SCALER = SCALER_SCALE_3X;
int main(int argc, char *argv[]) {
const char *dataPath = "DATA";
const char *savePath = ".";
int levelNum = 0;
int scaler = DEFAULT_SCALER;
bool fullscreen = false;
int forcedLanguage = -1;
int demoNum = -1;
if (argc == 2) {
// data path as the only command line argument
struct stat st;
if (stat(argv[1], &st) == 0 && S_ISDIR(st.st_mode)) {
dataPath = strdup(argv[1]);
}
}
while (1) {
static struct option options[] = {
{ "datapath", required_argument, 0, 1 },
{ "savepath", required_argument, 0, 2 },
{ "levelnum", required_argument, 0, 3 },
{ "fullscreen", no_argument, 0, 4 },
{ "scaler", required_argument, 0, 5 },
{ "language", required_argument, 0, 6 },
{ "playdemo", required_argument, 0, 7 },
{ 0, 0, 0, 0 }
};
int index;
const int c = getopt_long(argc, argv, "", options, &index);
if (c == -1) {
break;
}
switch (c) {
case 1:
dataPath = strdup(optarg);
break;
case 2:
savePath = strdup(optarg);
break;
case 3:
levelNum = atoi(optarg);
break;
case 4:
fullscreen = true;
break;
case 5:
scaler = atoi(optarg);
if (scaler < 0 || scaler >= NUM_SCALERS) {
scaler = DEFAULT_SCALER;
}
break;
case 6: {
static const struct {
int lang;
const char *str;
} languages[] = {
{ LANG_FR, "FR" },
{ LANG_EN, "EN" },
{ LANG_DE, "DE" },
{ LANG_SP, "SP" },
{ LANG_IT, "IT" },
{ -1, 0 }
};
for (int i = 0; languages[i].str; ++i) {
if (strcasecmp(languages[i].str, optarg) == 0) {
forcedLanguage = languages[i].lang;
break;
}
}
}
break;
case 7:
demoNum = atoi(optarg);
break;
default:
printf(USAGE, argv[0]);
return 0;
}
}
initOptions();
g_debugMask = DBG_INFO; // DBG_CUT | DBG_VIDEO | DBG_RES | DBG_MENU | DBG_PGE | DBG_GAME | DBG_UNPACK | DBG_COL | DBG_MOD | DBG_SFX | DBG_FILE;
FileSystem fs(dataPath);
const int version = detectVersion(&fs);
if (version == -1) {
error("Unable to find data files, check that all required files are present");
return -1;
}
const Language language = (forcedLanguage == -1) ? detectLanguage(&fs) : (Language)forcedLanguage;
SystemStub *stub = SystemStub_SDL_create();
Game *g = new Game(stub, &fs, savePath, levelNum, demoNum, (ResourceType)version, language);
stub->init(g_caption, Video::GAMESCREEN_W, Video::GAMESCREEN_H, scaler, fullscreen);
g->run();
delete g;
stub->destroy();
delete stub;
return 0;
}