-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli.c
314 lines (298 loc) · 7.54 KB
/
cli.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
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
/* Sarien - A Sierra AGI resource interpreter engine
* Copyright (C) 1999-2001 Stuart George and Claudio Matsuoka
*
* $Id: cli.c,v 1.39 2002/09/12 01:09:01 cmatsuoka Exp $
*
* This program 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 Foundation; see docs/COPYING for further details.
*/
#include "sarien.h"
#ifdef USE_COMMAND_LINE
#include <stdio.h>
#include <string.h>
#include <getopt.h>
#include "sound.h"
extern char *optarg;
static void help (int argc, char **argv)
{
/* printf() breaks GCC 3.0 build */
fprintf (stdout,
"Syntax is -:- %s [switches] [gamedir]\n"
"\n"
"Where [switches] are optionally:\n"
#ifdef AGDS_SUPPORT
" -a --agds Enables sarien to play AGDS created games.\n"
#endif
" -A --amiga Forces the game to be seen as an Amiga word padded game.\n"
" -C --crc CRC and identify the game files and stop.\n"
#ifndef PCCGA
" -c --cga-palette Use PC CGA video mode emulation.\n"
#endif
#ifdef OPT_LIST_DICT
" -d --list-dictionary\n"
" List dictionary words.\n"
#endif
#ifndef PCCGA
" -e --ega-palette Use PC EGA palette instead of amiga-ish palette\n"
#endif
" -L --list-games List all the games in the ID file\n"
" -F --full-screen Run in full-screen mode if allowed by the graphics device\n"
" -g --no-gfx-optimizations\n"
" Disable optimized graphic driver hacks (if available).\n"
#ifdef USE_HIRES
" -H --hires {0|1} Enable/disable hi-res mode.\n"
#endif
" -h --help Display this help screen.\n"
#ifdef USE_MOUSE
#ifndef __MSDOS__
" -m --agimouse AGI Mouse 1.0 compatibility mode.\n"
#endif
#endif
" -n --no-sound Disable sound output.\n"
#ifdef OPT_PICTURE_VIEWER
" -p --picture-viewer\n"
" Interactive picture viewer.\n"
#endif
#ifdef OPT_LIST_OBJECTS
" -o --list-objects List objects.\n"
#endif
#ifndef __MSDOS__
" -S --scale {num} Window size scale (only for windowed graphics).\n"
#ifndef __MSDOS__
" -s --emulate-sound {type}\n"
" Emulate the sound of Sierra AGI running in different\n"
" computers. Valid emulations are pc, mac and amiga\n"
#endif
" -r --aspect-ratio {0|1}\n"
" Adjust aspect ratio to match the PC EGA 320x200 screen.\n"
#endif
" -v --emulate-version {version}\n"
" Force version to emulate. Valid v2 game versions are:\n"
" 2.089, 2.272, 2.440, 2.917, 2.936. Valid v3 games are:\n"
" 3.002.086, 3.002.149.\n"
" -V --version Display version information.\n"
#ifndef __MSDOS__
" -x --no-x-shm Disable X shared memory extension (if available).\n"
#endif
#if 0
" -xd --dga Use XFree86 DGA extension (if available).\n"
#endif
"\n"
"[gamedir] is optionally the directory the game is in, if no directory is\n"
"specified, the current directory is assumed.\n"
"\n"
"Example: %s -v2.272 /games/sierra/sq1\n", argv[0], argv[0]);
}
int parse_cli (int argc, char **argv)
{
int i;
int ec = err_OK;
struct {
UINT16 vers;
char *string;
} cmp_versions[]= {
{ 0x2089, "2.089" },
{ 0x2272, "2.272" },
{ 0x2440, "2.440" },
{ 0x2917, "2.917" },
{ 0x2936, "2.936" },
{ 0x3086, "3.002.086" },
{ 0x3149, "3.002.149" },
{ 0x0, "" }
};
int o, optidx = 0;
#define OPTIONS "AaCcDdE:eFgH:hLlmnopr:skS:Vv:x"
static struct option lopt[] = {
{ "version", 0, 0, 'V' },
{ "help", 0, 0, 'h' },
#ifdef AGDS_SUPPORT
{ "agds", 0, 0, 'a' },
#endif
{ "amiga", 0, 0, 'A'},
{ "emulate-version", 1, 0, 'v' },
{ "crc", 0, 0, 'C'},
#ifndef PCCGA
{ "cga-palette", 0, 0, 'c'},
#endif
{ "list-games", 0, 0, 'L'},
#ifdef OPT_LIST_DICT
{ "list-dictionary", 0, 0, 'd' },
#endif
#ifndef PCCGA
{ "ega-palette", 0, 0, 'e' },
#endif
{ "full-screen", 0, 0, 'F' },
#ifdef USE_HIRES
{ "hires", 1, 0, 'H' },
#endif
{ "no-sound", 0, 0, 'n' },
#ifdef OPT_LIST_OBJECTS
{ "list-objects", 0, 0, 'o' },
#endif
#ifdef OPT_PICTURE_VIEWER
{ "picture-viewer", 0, 0, 'p' },
#endif
{ "wait-key", 0, 0, 'k' },
{ "no-x-shm", 0, 0, 'x' },
{ "aspect-ratio", 1, 0, 'r' },
#ifdef USE_MOUSE
{ "agimouse", 0, 0, 'm' },
#endif
{ "scale", 1, 0, 'S' },
#ifndef __MSDOS__
{ "emulate-sound", 1, 0, 's' },
#endif
{ "no-gfx-optimizations",0,0, 'g' }
};
/* FIXME: Add support for a rc file for UNIX */
/* Set defaults */
memset (&opt, 0, sizeof (struct sarien_options));
opt.gamerun = GAMERUN_RUNGAME;
opt.scale = 2;
opt.fixratio = TRUE;
opt.gfxhacks = TRUE;
#ifdef USE_HIRES
opt.hires = TRUE;
#endif
#ifdef MITSHM
opt.mitshm = TRUE;
#endif
opt.soundemu = SOUND_EMU_NONE;
while ((o = getopt_long (argc, argv, OPTIONS, lopt, &optidx)) != -1) {
switch (o) {
case 'V':
printf ("Version : " VERSION " Compiled on " __DATE__ "; " __TIME__ "\n");
printf ("Logic patching is ");
#ifdef PATCH_LOGIC
printf ("enabled\n");
#else
printf ("disabled\n");
#endif
printf("AGDS games and Russian/Cyrillic font is ");
#ifdef AGDS_SUPPORT
printf("supported\n");
#else
printf("not supported\n");
#endif
printf("Listing Objects is ");
#ifdef OPT_LIST_OBJECTS
printf("supported\n");
#else
printf("not supported\n");
#endif
printf("Dictionary Listing is ");
#ifdef OPT_LIST_DICT
printf("enabled\n");
#else
printf("disabled\n");
#endif
exit (0);
case 'A':
opt.amiga = TRUE;
break;
case 'a':
opt.agds = TRUE;
break;
case 'C':
opt.gamerun = GAMERUN_CRC;
break;
#ifndef PCCGA
case 'c':
opt.cgaemu = TRUE;
break;
#endif
#ifdef OPT_LIST_DICT
case 'd':
opt.gamerun = GAMERUN_WORDS;
break;
#endif
#ifndef PCCGA
case 'e':
opt.egapal = TRUE;
break;
#endif
case 'F':
opt.fullscreen = TRUE;
break;
case 'L':
opt.gamerun = GAMERUN_GAMES;
break;
case 'g':
opt.gfxhacks = FALSE;
break;
#ifdef USE_HIRES
case 'H':
opt.hires = strtoul (optarg, NULL, 0);
break;
#endif
#ifdef USE_MOUSE
case 'm':
opt.agimouse = TRUE;
break;
#endif
case 'n':
opt.nosound = TRUE;
break;
#ifdef OPT_LIST_OBJECTS
case 'o':
opt.gamerun = GAMERUN_OBJECTS;
break;
#endif
#ifdef OPT_PICTURE_VIEWER
case 'p':
opt.gamerun = GAMERUN_PICVIEW;
break;
#endif
#ifndef __MSDOS__
case 'r':
opt.fixratio = strtoul (optarg, NULL, 0);
break;
case 'S':
opt.scale = strtoul (optarg, NULL, 0);
if (opt.scale < 1)
opt.scale = 1;
if (opt.scale > 4)
opt.scale = 4;
break;
case 's':
if (!strcmp (optarg, "pc"))
opt.soundemu = SOUND_EMU_PC;
else if (!strcmp (optarg, "mac"))
opt.soundemu = SOUND_EMU_MAC;
else if (!strcmp (optarg, "amiga"))
opt.soundemu = SOUND_EMU_AMIGA;
else {
fprintf (stderr, "Sound emulation \"%s\" is "
"unknown\n", optarg);
exit (0);
}
break;
#endif
case 'v':
for (i = 0; cmp_versions[i].vers; i++) {
if (!strcmp (optarg, cmp_versions[i].string)) {
opt.emuversion = cmp_versions[i].vers;
break;
}
}
if (!opt.emuversion) {
printf ("Error: bad AGI version number \"%s\"\n",
optarg);
exit (-1);
}
break;
#ifdef MITSHM
case 'x':
opt.mitshm = FALSE;
break;
#endif
case 'h':
help (argc, argv);
default:
exit (-1);
}
}
return ec;
}
#endif /* USE_COMMAND_LINE */