forked from cyxx/rawgl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
233 lines (217 loc) · 5.51 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
228
229
230
231
232
233
/*
* Another World engine rewrite
* Copyright (C) 2004-2005 Gregory Montoir (cyx@users.sourceforge.net)
*/
#ifdef __SWITCH__
#include <SDL2/SDL.h>
#include <switch.h>
#else
#include <SDL.h>
#endif
#include <getopt.h>
#include <sys/stat.h>
#include "engine.h"
#include "graphics.h"
#include "resource.h"
#include "systemstub.h"
#include "util.h"
static const char *USAGE =
"Raw(gl) - Another World Interpreter\n"
"Usage: rawgl [OPTIONS]...\n"
" --datapath=PATH Path to data files (default '.')\n"
" --language=LANG Language (fr,us,de,es,it)\n"
" --part=NUM Game part to start from (0-35 or 16001-16009)\n"
" --render=NAME Renderer (original,software,gl)\n"
" --window=WxH Windowed displayed size (default '640x480')\n"
" --fullscreen Fullscreen display (stretched)\n"
" --fullscreen-ar Fullscreen display (4:3 aspect ratio)\n"
" --ega-palette Use EGA palette with DOS version\n"
;
static const struct {
const char *name;
int lang;
} LANGUAGES[] = {
{ "fr", LANG_FR },
{ "us", LANG_US },
{ "de", LANG_DE },
{ "es", LANG_ES },
{ "it", LANG_IT },
{ 0, -1 }
};
static const struct {
const char *name;
int type;
} GRAPHICS[] = {
{ "original", GRAPHICS_ORIGINAL },
{ "software", GRAPHICS_SOFTWARE },
{ "gl", GRAPHICS_GL },
{ 0, -1 }
};
bool Graphics::_is1991 = false;
bool Graphics::_use565 = false;
bool Video::_useEGA = false;
static Graphics *createGraphics(int type) {
switch (type) {
case GRAPHICS_ORIGINAL:
Graphics::_is1991 = true;
// fall-through
case GRAPHICS_SOFTWARE:
debug(DBG_INFO, "Using software graphics");
return GraphicsSoft_create();
case GRAPHICS_GL:
debug(DBG_INFO, "Using GL graphics");
#ifdef USE_GL
// return GraphicsGL_create();
#endif
}
return 0;
}
static int getGraphicsType(Resource::DataType type) {
switch (type) {
case Resource::DT_15TH_EDITION:
case Resource::DT_20TH_EDITION:
case Resource::DT_3DO:
return GRAPHICS_GL;
default:
return GRAPHICS_ORIGINAL;
}
}
struct Scaler {
char name[32];
int factor;
};
static void parseScaler(char *name, Scaler *s) {
char *sep = strchr(name, '@');
if (sep) {
*sep = 0;
strncpy(s->name, name, sizeof(s->name) - 1);
s->name[sizeof(s->name) - 1] = 0;
}
if (sep) {
s->factor = atoi(sep + 1);
}
}
static const int DEFAULT_WINDOW_W = 1280;
static const int DEFAULT_WINDOW_H = 720;
int main(int argc, char *argv[]) {
char *dataPath = (char *)"data";
#if defined(__SWITCH__) && defined(NXLINK_DEBUG)
dataPath = (char *)"/switch/rawgl/data";
#endif
int part = 16001;
Language lang = LANG_FR;
int graphicsType = GRAPHICS_SOFTWARE;
DisplayMode dm;
dm.mode = DisplayMode::FULLSCREEN_AR;
dm.width = DEFAULT_WINDOW_W;
dm.height = DEFAULT_WINDOW_H;
dm.opengl = (graphicsType == GRAPHICS_GL);
Scaler scaler;
scaler.name[0] = 0;
scaler.factor = 1;
bool defaultGraphics = true;
#if defined(__SWITCH__) && defined(NXLINK_DEBUG)
socketInitializeDefault();
nxlinkStdio();
#endif
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, 'd' },
{ "language", required_argument, 0, 'l' },
{ "part", required_argument, 0, 'p' },
{ "render", required_argument, 0, 'r' },
{ "window", required_argument, 0, 'w' },
{ "fullscreen", no_argument, 0, 'f' },
{ "fullscreen-ar", no_argument, 0, 'a' },
{ "scaler", required_argument, 0, 's' },
{ "ega-palette", no_argument, 0, 'e' },
{ "help", no_argument, 0, 'h' },
{ 0, 0, 0, 0 }
};
int index;
const int c = getopt_long(argc, argv, "", options, &index);
if (c == -1) {
break;
}
switch (c) {
case 'd':
dataPath = strdup(optarg);
break;
case 'l':
for (int i = 0; LANGUAGES[i].name; ++i) {
if (strcmp(optarg, LANGUAGES[i].name) == 0) {
lang = (Language)LANGUAGES[i].lang;
break;
}
}
break;
case 'p':
part = atoi(optarg);
break;
case 'r':
for (int i = 0; GRAPHICS[i].name; ++i) {
if (strcmp(optarg, GRAPHICS[i].name) == 0) {
graphicsType = GRAPHICS[i].type;
dm.opengl = (graphicsType == GRAPHICS_GL);
defaultGraphics = false;
break;
}
}
break;
case 'w':
sscanf(optarg, "%dx%d", &dm.width, &dm.height);
break;
case 'f':
dm.mode = DisplayMode::FULLSCREEN;
break;
case 'a':
dm.mode = DisplayMode::FULLSCREEN_AR;
break;
case 's':
parseScaler(optarg, &scaler);
break;
case 'e':
Video::_useEGA = true;
break;
case 'h':
// fall-through
default:
printf("%s\n", USAGE);
return 0;
}
}
g_debugMask = DBG_INFO | DBG_VIDEO | DBG_SND | DBG_SCRIPT | DBG_BANK | DBG_SER;
Engine *e = new Engine(dataPath, part);
if (defaultGraphics) {
// if not set, use original software graphics for 199x editions and GL for the anniversary and 3DO versions
graphicsType = getGraphicsType(e->_res.getDataType());
dm.opengl = (graphicsType == GRAPHICS_GL);
}
if (graphicsType != GRAPHICS_GL && e->_res.getDataType() == Resource::DT_3DO) {
graphicsType = GRAPHICS_SOFTWARE;
Graphics::_use565 = true;
}
Graphics *graphics = createGraphics(graphicsType);
SystemStub *stub = SystemStub_SDL_create();
stub->init(e->getGameTitle(lang), &dm);
e->setSystemStub(stub, graphics);
e->setup(lang, graphicsType, scaler.name, scaler.factor);
while (!stub->_pi.quit) {
e->run();
}
e->finish();
delete e;
stub->fini();
delete stub;
#if defined(__SWITCH__) && defined(NXLINK_DEBUG)
socketExit();
#endif
return 0;
}