2018-07-08 16:08:53 +02:00
|
|
|
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include "sys.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
struct options_t g_options;
|
|
|
|
|
|
|
|
static const char *DEFAULT_DATA_PATH = ".";
|
|
|
|
|
2018-07-16 14:43:34 +02:00
|
|
|
static const int DEFAULT_SCALE_FACTOR = 2;
|
|
|
|
|
|
|
|
static const char *DEFAULT_SCALE_FILTER = 0; // nearest pixel sampling
|
|
|
|
|
2018-07-08 16:08:53 +02:00
|
|
|
static const char *USAGE =
|
|
|
|
"Usage: %s [OPTIONS]...\n"
|
|
|
|
" --datapath=PATH Path to data files (default '.')\n"
|
|
|
|
" --level=NUM Start at level NUM\n"
|
2018-08-12 16:55:27 +02:00
|
|
|
" --cheats=MASK Cheats mask\n"
|
2018-07-27 16:02:05 +02:00
|
|
|
" --startpos=XxY Start at position (X,Y)\n"
|
|
|
|
" --fullscreen Enable fullscreen\n"
|
2018-12-16 13:34:03 +01:00
|
|
|
" --scale=N Graphics scaling factor (default 2)\n"
|
|
|
|
" --filter=NAME Graphics scaling filter (default 'nearest')\n"
|
2018-07-27 16:02:05 +02:00
|
|
|
" --screensize=WxH Graphics screen size (default 320x200)\n"
|
2018-08-12 16:55:27 +02:00
|
|
|
" --cga Enable CGA colors\n"
|
2018-07-08 16:08:53 +02:00
|
|
|
;
|
|
|
|
|
2018-12-16 13:34:03 +01:00
|
|
|
static struct game_t *detect_game(const char *data_path) {
|
|
|
|
#if 0
|
|
|
|
extern struct game_t bb_game;
|
|
|
|
extern struct game_t ja_game;
|
2019-05-29 01:54:47 +02:00
|
|
|
extern struct game_t p2_game;
|
2018-12-16 13:34:03 +01:00
|
|
|
static struct game_t *games[] = {
|
|
|
|
&bb_game,
|
|
|
|
&ja_game,
|
2019-05-29 01:54:47 +02:00
|
|
|
&p2_game,
|
2018-12-16 13:34:03 +01:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2018-07-08 16:08:53 +02:00
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
g_options.start_xpos16 = -1;
|
|
|
|
g_options.start_ypos16 = -1;
|
2018-07-27 16:02:05 +02:00
|
|
|
g_options.screen_w = 320;
|
|
|
|
g_options.screen_h = 200;
|
2021-12-19 01:26:40 +01:00
|
|
|
g_options.amiga_copper_bars = true;
|
2018-07-08 16:08:53 +02:00
|
|
|
g_options.amiga_colors = true;
|
2018-07-22 15:28:05 +02:00
|
|
|
// g_options.amiga_status_bar = true;
|
2018-08-12 14:27:20 +02:00
|
|
|
g_options.dos_scrolling = false;
|
2018-08-12 16:55:27 +02:00
|
|
|
g_options.cga_colors = false;
|
2018-07-08 16:08:53 +02:00
|
|
|
const char *data_path = DEFAULT_DATA_PATH;
|
2018-07-16 14:43:34 +02:00
|
|
|
int scale_factor = DEFAULT_SCALE_FACTOR;
|
|
|
|
const char *scale_filter = DEFAULT_SCALE_FILTER;
|
|
|
|
bool fullscreen = false;
|
2018-07-08 16:08:53 +02:00
|
|
|
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[] = {
|
2018-08-12 16:55:27 +02:00
|
|
|
{ "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 },
|
|
|
|
{ "filter", required_argument, 0, 8 },
|
2018-07-27 16:02:05 +02:00
|
|
|
{ "screensize", required_argument, 0, 9 },
|
2018-08-12 16:55:27 +02:00
|
|
|
{ "cga", no_argument, 0, 10 },
|
2018-07-08 16:08:53 +02:00
|
|
|
{ 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;
|
2018-07-16 14:43:34 +02:00
|
|
|
case 6:
|
|
|
|
fullscreen = true;
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
scale_factor = atoi(optarg);
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
scale_filter = strdup(optarg);
|
|
|
|
break;
|
2018-07-27 16:02:05 +02:00
|
|
|
case 9:
|
2018-08-12 14:27:20 +02:00
|
|
|
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;
|
2018-12-16 13:34:03 +01:00
|
|
|
g_options.screen_h = ((g_options.screen_h + 15) & ~15) + 40; // PANEL_H
|
2018-08-12 14:27:20 +02:00
|
|
|
}
|
2018-07-27 16:02:05 +02:00
|
|
|
break;
|
2018-08-12 16:55:27 +02:00
|
|
|
case 10:
|
|
|
|
g_options.cga_colors = true;
|
|
|
|
break;
|
2018-07-08 16:08:53 +02:00
|
|
|
default:
|
|
|
|
fprintf(stdout, USAGE, argv[0]);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2018-12-16 13:34:03 +01:00
|
|
|
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(GAME_SCREEN_W, GAME_SCREEN_H, game->name, scale_factor, scale_filter, fullscreen);
|
|
|
|
game->run(data_path);
|
|
|
|
g_sys.fini();
|
|
|
|
}
|
2018-07-08 16:08:53 +02:00
|
|
|
if (data_path != DEFAULT_DATA_PATH) {
|
|
|
|
free((char *)data_path);
|
|
|
|
}
|
2018-07-27 16:02:05 +02:00
|
|
|
if (scale_filter != DEFAULT_SCALE_FILTER) {
|
|
|
|
free((char *)scale_filter);
|
|
|
|
}
|
2018-07-08 16:08:53 +02:00
|
|
|
return 0;
|
|
|
|
}
|