-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
179 lines (171 loc) · 4.84 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
174
175
176
177
178
179
#include <getopt.h>
#include <sys/stat.h>
#include "sys.h"
#include "util.h"
struct options_t g_options;
static const char *DEFAULT_DATA_PATH = ".";
static int DEFAULT_JUMP_BUTTON = 0;
static const int DEFAULT_SCALE_FACTOR = 2;
static const char *USAGE =
"Usage: %s [OPTIONS]...\n"
" --datapath=PATH Path to data files (default '%s')\n"
" --level=NUM Start at level NUM\n"
" --cheats=MASK Cheats mask\n"
" --startpos=XxY Start at position (X,Y)\n"
" --fullscreen Enable fullscreen\n"
" --scale=N Graphics scaling factor (default %d)\n"
" --screensize=WxH Graphics screen size (default %dx%d)\n"
" --cga Enable CGA colors\n"
" --dosscroll Enable DOS style screen scrolling\n"
" --hybrid Enable fuchsia color as in Hybrid crack\n"
" --palette=NUM Pick palette NUM for screen colors\n"
" --nomap Do not scroll map before each level\n"
" --jumpbtn=NUM Select button NUM for jump (default %d)\n"
" --nosound Disable sound\n"
" --noanimtiles Disable animated tiles\n"
;
static struct game_t *detect_game(const char *data_path) {
#if 0
extern struct game_t bb_game;
extern struct game_t ja_game;
extern struct game_t p2_game;
static struct game_t *games[] = {
&bb_game,
&ja_game,
&p2_game,
0
};
for (int i = 0; games[i]; ++i) {
if (games[i]->detect(data_path)) {
return games[i];
}
}
return 0;
#else
extern struct game_t game;
return &game;
#endif
}
int main(int argc, char *argv[]) {
g_options.start_xpos16 = -1;
g_options.start_ypos16 = -1;
g_options.screen_w = ORIG_W;
g_options.screen_h = ORIG_H;
g_options.dos_scrolling = false;
g_options.amiga_copper_bars = true;
g_options.amiga_colors = true;
// g_options.amiga_status_bar = true;
g_options.cga_colors = false;
g_options.dos_scrolling = false;
g_options.hybrid_color = false;
g_options.show_map = true;
g_options.animate_tiles = true;
g_sys.audio = true;
const char *data_path = DEFAULT_DATA_PATH;
int scale_factor = DEFAULT_SCALE_FACTOR;
g_sys.input.jump_button = DEFAULT_JUMP_BUTTON;
bool fullscreen = false;
if (argc == 2) {
struct stat st;
if (stat(argv[1], &st) == 0 && S_ISDIR(st.st_mode)) {
data_path = strdup(argv[1]);
}
}
while (1) {
static struct option options[] = {
{ "datapath", required_argument, 0, 1 },
{ "level", required_argument, 0, 2 },
{ "debug", required_argument, 0, 3 },
{ "cheats", required_argument, 0, 4 },
{ "startpos", required_argument, 0, 5 },
{ "fullscreen", no_argument, 0, 6 },
{ "scale", required_argument, 0, 7 },
{ "screensize", required_argument, 0, 9 },
{ "cga", no_argument, 0, 10 },
{ "dosscroll", no_argument, 0, 11 },
{ "hybrid", no_argument, 0, 12 },
{ "palette", required_argument, 0, 13 },
{ "nomap", no_argument, 0, 14 },
{ "jumpbtn", required_argument, 0, 15 },
{ "nosound", no_argument , 0, 16 },
{ "noanimtiles",no_argument , 0, 17 },
{ 0, 0, 0, 0 },
};
int index;
const int c = getopt_long(argc, argv, "", options, &index);
if (c == -1) {
break;
}
switch (c) {
case 1:
data_path = strdup(optarg);
break;
case 2:
g_options.start_level = atoi(optarg);
break;
case 3:
g_debug_mask = atoi(optarg);
break;
case 4:
g_options.cheats = atoi(optarg);
break;
case 5:
sscanf(optarg, "%dx%d", &g_options.start_xpos16, &g_options.start_ypos16);
break;
case 6:
fullscreen = true;
break;
case 7:
scale_factor = atoi(optarg);
break;
case 9:
if (sscanf(optarg, "%dx%d", &g_options.screen_w, &g_options.screen_h) == 2) {
// align to tile 16x16
g_options.screen_w = (g_options.screen_w + 15) & ~15;
g_options.screen_h = ((g_options.screen_h + 15) & ~15) + 40; // PANEL_H
}
break;
case 10:
g_options.cga_colors = true;
break;
case 11:
g_options.dos_scrolling = true;
break;
case 12:
g_options.hybrid_color = true;
break;
case 13:
sscanf(optarg, "%hhd", &g_options.palette);
fprintf(stdout, "Using palette #%d\n", g_options.palette);
break;
case 14:
g_options.show_map = false;
break;
case 15:
sscanf(optarg, "%d", &g_sys.input.jump_button);
break;
case 16:
g_sys.audio = false;
break;
case 17:
g_options.animate_tiles = false;
break;
default:
fprintf(stdout, USAGE, argv[0], DEFAULT_DATA_PATH, DEFAULT_SCALE_FACTOR, ORIG_W, ORIG_H, DEFAULT_JUMP_BUTTON);
return -1;
}
}
struct game_t *game = detect_game(data_path);
if (!game) {
fprintf(stdout, "No data files found\n");
} else {
g_sys.init();
g_sys.set_screen_size(g_options.screen_w * scale_factor, g_options.screen_h * scale_factor, game->name, scale_factor, fullscreen, g_options.hybrid_color);
game->run(data_path);
g_sys.fini();
}
if (data_path != DEFAULT_DATA_PATH) {
free((char *)data_path);
}
return 0;
}