REminiscence/main.cpp

196 lines
4.8 KiB
C++
Raw Normal View History

2016-03-20 17:00:00 +01:00
/*
* REminiscence - Flashback interpreter
* Copyright (C) 2005-2015 Gregory Montoir (cyx@users.sourceforge.net)
2015-08-02 18:00:00 +02:00
*/
2016-03-20 17:00:00 +01:00
#include <ctype.h>
2015-08-02 18:00:00 +02:00
#include <getopt.h>
#include <sys/stat.h>
#include "file.h"
#include "fs.h"
#include "game.h"
2016-03-20 17:00:00 +01:00
#include "scaler.h"
2015-08-02 18:00:00 +02:00
#include "systemstub.h"
2016-03-20 17:00:00 +01:00
#include "util.h"
2015-08-02 18:00:00 +02:00
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"
2016-03-20 17:00:00 +01:00
" --levelnum=NUM Start level (default '0')\n"
" --fullscreen Start fullscreen\n"
" --scaler=INDEX Graphics scaler\n"
;
2015-08-02 18:00:00 +02:00
static int detectVersion(FileSystem *fs) {
static const struct {
const char *filename;
int type;
const char *name;
} table[] = {
2016-03-20 17:00:00 +01:00
{ "DEMO_UK.ABA", kResourceTypeDOS, "DOS (Demo)" },
{ "INTRO.SEQ", kResourceTypeDOS, "DOS CD" },
{ "LEVEL1.MAP", kResourceTypeDOS, "DOS" },
2015-08-02 18:00:00 +02:00
{ "LEVEL1.LEV", kResourceTypeAmiga, "Amiga" },
2016-03-20 17:00:00 +01:00
{ "DEMO.LEV", kResourceTypeAmiga, "Amiga (Demo)" },
2015-08-02 18:00:00 +02:00
{ 0, -1 }
};
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;
}
2016-03-20 17:00:00 +01:00
Options g_options;
2015-08-02 18:00:00 +02:00
const char *g_caption = "REminiscence";
2016-03-20 17:00:00 +01:00
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;
// 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 },
{ 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;
2015-08-02 18:00:00 +02:00
#undef main
int main(int argc, char *argv[]) {
const char *dataPath = "DATA";
const char *savePath = ".";
int levelNum = 0;
2016-03-20 17:00:00 +01:00
int scaler = DEFAULT_SCALER;
bool fullscreen = false;
2015-08-02 18:00:00 +02:00
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[] = {
2016-03-20 17:00:00 +01:00
{ "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 },
2015-08-02 18:00:00 +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:
dataPath = strdup(optarg);
break;
case 2:
savePath = strdup(optarg);
break;
case 3:
levelNum = atoi(optarg);
break;
2016-03-20 17:00:00 +01:00
case 4:
fullscreen = true;
break;
case 5:
scaler = atoi(optarg);
if (scaler < 0 || scaler >= NUM_SCALERS) {
scaler = DEFAULT_SCALER;
}
break;
2015-08-02 18:00:00 +02:00
default:
printf(USAGE, argv[0]);
return 0;
}
}
2016-03-20 17:00:00 +01:00
initOptions();
2015-08-02 18:00:00 +02:00
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;
}
Language language = detectLanguage(&fs);
SystemStub *stub = SystemStub_SDL_create();
Game *g = new Game(stub, &fs, savePath, levelNum, (ResourceType)version, language);
2016-03-20 17:00:00 +01:00
stub->init(g_caption, Video::GAMESCREEN_W, Video::GAMESCREEN_H, scaler, fullscreen);
2015-08-02 18:00:00 +02:00
g->run();
delete g;
2016-03-20 17:00:00 +01:00
stub->destroy();
2015-08-02 18:00:00 +02:00
delete stub;
return 0;
}