2016-03-20 17:00:00 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* REminiscence - Flashback interpreter
|
2018-01-20 17:00:00 +01:00
|
|
|
* Copyright (C) 2005-2018 Gregory Montoir (cyx@users.sourceforge.net)
|
2015-08-02 18:00:00 +02:00
|
|
|
*/
|
|
|
|
|
2017-06-07 18:00:00 +02:00
|
|
|
#include <SDL.h>
|
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"
|
2017-06-07 18:00:00 +02:00
|
|
|
" --levelnum=NUM Start to level, bypass introduction\n"
|
2016-05-09 18:00:00 +02:00
|
|
|
" --fullscreen Fullscreen display\n"
|
2018-03-28 18:00:00 +02:00
|
|
|
" --widescreen=MODE 16:9 display\n"
|
2017-11-03 17:00:00 +01:00
|
|
|
" --scaler=NAME@X Graphics scaler (default 'scale@3')\n"
|
2017-12-06 17:00:00 +01:00
|
|
|
" --language=LANG Language (fr,en,de,sp,it,jp)\n"
|
2016-03-20 17:00:00 +01:00
|
|
|
;
|
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" },
|
2018-01-20 17:00:00 +01:00
|
|
|
{ "LEVEL1.BNQ", kResourceTypeDOS, "DOS (Demo)" },
|
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)" },
|
2018-02-10 17:00:00 +01:00
|
|
|
{ "FLASHBACK.BIN", kResourceTypeMac, "Macintosh" },
|
2018-03-18 17:00:00 +01:00
|
|
|
{ "FLASHBACK.RSRC", kResourceTypeMac, "Macintosh" },
|
2017-06-07 18:00:00 +02:00
|
|
|
{ 0, -1, 0 }
|
2015-08-02 18:00:00 +02:00
|
|
|
};
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2018-03-28 18:00:00 +02:00
|
|
|
warning("Unable to detect language, defaults to English");
|
2015-08-02 18:00:00 +02:00
|
|
|
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.enable_password_menu = false;
|
2018-03-18 17:00:00 +01:00
|
|
|
g_options.enable_language_selection = false;
|
2016-03-20 17:00:00 +01:00
|
|
|
g_options.fade_out_palette = true;
|
2016-05-09 18:00:00 +02:00
|
|
|
g_options.use_text_cutscenes = false;
|
2017-06-07 18:00:00 +02:00
|
|
|
g_options.use_seq_cutscenes = true;
|
2018-02-10 17:00:00 +01:00
|
|
|
g_options.play_asc_cutscene = false;
|
|
|
|
g_options.play_caillou_cutscene = false;
|
|
|
|
g_options.play_metro_cutscene = false;
|
|
|
|
g_options.play_serrure_cutscene = false;
|
2016-03-20 17:00:00 +01:00
|
|
|
// read configuration file
|
|
|
|
struct {
|
|
|
|
const char *name;
|
|
|
|
bool *value;
|
|
|
|
} opts[] = {
|
|
|
|
{ "bypass_protection", &g_options.bypass_protection },
|
|
|
|
{ "enable_password_menu", &g_options.enable_password_menu },
|
2018-03-18 17:00:00 +01:00
|
|
|
{ "enable_language_selection", &g_options.enable_language_selection },
|
2016-03-20 17:00:00 +01:00
|
|
|
{ "fade_out_palette", &g_options.fade_out_palette },
|
|
|
|
{ "use_tiledata", &g_options.use_tiledata },
|
2016-05-09 18:00:00 +02:00
|
|
|
{ "use_text_cutscenes", &g_options.use_text_cutscenes },
|
2017-06-07 18:00:00 +02:00
|
|
|
{ "use_seq_cutscenes", &g_options.use_seq_cutscenes },
|
2018-02-10 17:00:00 +01:00
|
|
|
{ "play_asc_cutscene", &g_options.play_asc_cutscene },
|
|
|
|
{ "play_caillou_cutscene", &g_options.play_caillou_cutscene },
|
|
|
|
{ "play_metro_cutscene", &g_options.play_metro_cutscene },
|
|
|
|
{ "play_serrure_cutscene", &g_options.play_serrure_cutscene },
|
2016-03-20 17:00:00 +01:00
|
|
|
{ 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');
|
2018-03-28 18:00:00 +02:00
|
|
|
bool foundOption = false;
|
2016-03-20 17:00:00 +01:00
|
|
|
for (int i = 0; opts[i].name; ++i) {
|
|
|
|
if (strncmp(buf, opts[i].name, strlen(opts[i].name)) == 0) {
|
|
|
|
*opts[i].value = value;
|
2018-03-28 18:00:00 +02:00
|
|
|
foundOption = true;
|
2016-03-20 17:00:00 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-03-28 18:00:00 +02:00
|
|
|
if (!foundOption) {
|
|
|
|
warning("Unhandled option '%s', ignoring", buf);
|
|
|
|
}
|
2016-03-20 17:00:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-03 17:00:00 +01:00
|
|
|
static void parseScaler(char *name, ScalerParameters *scalerParameters) {
|
|
|
|
struct {
|
|
|
|
const char *name;
|
|
|
|
int type;
|
2018-03-28 18:00:00 +02:00
|
|
|
const Scaler *scaler;
|
2017-11-03 17:00:00 +01:00
|
|
|
} scalers[] = {
|
2018-03-28 18:00:00 +02:00
|
|
|
{ "point", kScalerTypePoint, 0 },
|
|
|
|
{ "linear", kScalerTypeLinear, 0 },
|
|
|
|
{ "scale", kScalerTypeInternal, &_internalScaler },
|
|
|
|
#ifdef USE_STATIC_SCALER
|
|
|
|
{ "nearest", kScalerTypeInternal, &scaler_nearest },
|
|
|
|
{ "tv2x", kScalerTypeInternal, &scaler_tv2x },
|
|
|
|
{ "xbrz", kScalerTypeInternal, &scaler_xbrz },
|
|
|
|
#endif
|
2017-11-03 17:00:00 +01:00
|
|
|
{ 0, -1 }
|
|
|
|
};
|
|
|
|
bool found = false;
|
|
|
|
char *sep = strchr(name, '@');
|
|
|
|
if (sep) {
|
|
|
|
*sep = 0;
|
|
|
|
}
|
|
|
|
for (int i = 0; scalers[i].name; ++i) {
|
|
|
|
if (strcmp(scalers[i].name, name) == 0) {
|
|
|
|
scalerParameters->type = (ScalerType)scalers[i].type;
|
2018-03-28 18:00:00 +02:00
|
|
|
scalerParameters->scaler = scalers[i].scaler;
|
2017-11-03 17:00:00 +01:00
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found) {
|
|
|
|
char libname[32];
|
|
|
|
snprintf(libname, sizeof(libname), "scaler_%s", name);
|
|
|
|
const Scaler *scaler = findScaler(libname);
|
2017-12-06 17:00:00 +01:00
|
|
|
if (!scaler) {
|
|
|
|
warning("Scaler '%s' not found, using default", libname);
|
|
|
|
} else if (scaler->tag != SCALER_TAG) {
|
|
|
|
warning("Unexpected tag %d for scaler '%s'", scaler->tag, libname);
|
|
|
|
} else {
|
2017-11-03 17:00:00 +01:00
|
|
|
scalerParameters->type = kScalerTypeExternal;
|
|
|
|
scalerParameters->scaler = scaler;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sep) {
|
|
|
|
scalerParameters->factor = atoi(sep + 1);
|
|
|
|
}
|
|
|
|
}
|
2016-03-20 17:00:00 +01:00
|
|
|
|
2018-03-28 18:00:00 +02:00
|
|
|
static WidescreenMode parseWidescreen(const char *mode) {
|
|
|
|
static const struct {
|
|
|
|
const char *name;
|
|
|
|
WidescreenMode mode;
|
|
|
|
} modes[] = {
|
|
|
|
{ "adjacent", kWidescreenAdjacentRooms },
|
|
|
|
{ "mirror", kWidescreenMirrorRoom },
|
|
|
|
{ 0, kWidescreenNone },
|
|
|
|
};
|
|
|
|
for (int i = 0; modes[i].name; ++i) {
|
|
|
|
if (strcasecmp(modes[i].name, mode) == 0) {
|
|
|
|
return modes[i].mode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
warning("Unhandled widecreen mode '%s', defaults to adjacent rooms", mode);
|
|
|
|
return kWidescreenAdjacentRooms; // default value
|
|
|
|
}
|
|
|
|
|
2015-08-02 18:00:00 +02:00
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
const char *dataPath = "DATA";
|
|
|
|
const char *savePath = ".";
|
|
|
|
int levelNum = 0;
|
2016-03-20 17:00:00 +01:00
|
|
|
bool fullscreen = false;
|
2018-03-28 18:00:00 +02:00
|
|
|
WidescreenMode widescreen = kWidescreenNone;
|
2017-11-03 17:00:00 +01:00
|
|
|
ScalerParameters scalerParameters = ScalerParameters::defaults();
|
2016-05-09 18:00:00 +02:00
|
|
|
int forcedLanguage = -1;
|
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 },
|
2016-05-09 18:00:00 +02:00
|
|
|
{ "language", required_argument, 0, 6 },
|
2018-03-28 18:00:00 +02:00
|
|
|
{ "widescreen", required_argument, 0, 7 },
|
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:
|
2017-11-03 17:00:00 +01:00
|
|
|
parseScaler(optarg, &scalerParameters);
|
2016-03-20 17:00:00 +01:00
|
|
|
break;
|
2016-05-09 18:00:00 +02:00
|
|
|
case 6: {
|
|
|
|
static const struct {
|
|
|
|
int lang;
|
|
|
|
const char *str;
|
|
|
|
} languages[] = {
|
|
|
|
{ LANG_FR, "FR" },
|
|
|
|
{ LANG_EN, "EN" },
|
|
|
|
{ LANG_DE, "DE" },
|
|
|
|
{ LANG_SP, "SP" },
|
|
|
|
{ LANG_IT, "IT" },
|
2017-12-06 17:00:00 +01:00
|
|
|
{ LANG_JP, "JP" },
|
2016-05-09 18:00:00 +02:00
|
|
|
{ -1, 0 }
|
|
|
|
};
|
|
|
|
for (int i = 0; languages[i].str; ++i) {
|
|
|
|
if (strcasecmp(languages[i].str, optarg) == 0) {
|
|
|
|
forcedLanguage = languages[i].lang;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2018-03-18 17:00:00 +01:00
|
|
|
case 7:
|
2018-03-28 18:00:00 +02:00
|
|
|
widescreen = parseWidescreen(optarg);
|
2018-03-18 17:00:00 +01:00
|
|
|
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;
|
|
|
|
}
|
2016-05-09 18:00:00 +02:00
|
|
|
const Language language = (forcedLanguage == -1) ? detectLanguage(&fs) : (Language)forcedLanguage;
|
2015-08-02 18:00:00 +02:00
|
|
|
SystemStub *stub = SystemStub_SDL_create();
|
2018-03-28 18:00:00 +02:00
|
|
|
Game *g = new Game(stub, &fs, savePath, levelNum, (ResourceType)version, language, widescreen);
|
|
|
|
stub->init(g_caption, g->_vid._w, g->_vid._h, fullscreen, widescreen != kWidescreenNone, &scalerParameters);
|
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;
|
|
|
|
}
|