133 lines
3.5 KiB
C++
133 lines
3.5 KiB
C++
/* REminiscence - Flashback interpreter
|
|
* Copyright (C) 2005-2015 Gregory Montoir
|
|
*
|
|
* 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, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include <getopt.h>
|
|
#include <sys/stat.h>
|
|
#include "file.h"
|
|
#include "fs.h"
|
|
#include "game.h"
|
|
#include "systemstub.h"
|
|
|
|
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"
|
|
" --levelnum=NUM Starting level (default '0')";
|
|
|
|
static int detectVersion(FileSystem *fs) {
|
|
static const struct {
|
|
const char *filename;
|
|
int type;
|
|
const char *name;
|
|
} table[] = {
|
|
{ "LEVEL1.MAP", kResourceTypePC, "PC" },
|
|
{ "LEVEL1.LEV", kResourceTypeAmiga, "Amiga" },
|
|
{ "DEMO.LEV", kResourceTypeAmiga, "Amiga" },
|
|
{ 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;
|
|
}
|
|
|
|
const char *g_caption = "REminiscence";
|
|
|
|
#undef main
|
|
int main(int argc, char *argv[]) {
|
|
const char *dataPath = "DATA";
|
|
const char *savePath = ".";
|
|
int levelNum = 0;
|
|
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[] = {
|
|
{ "datapath", required_argument, 0, 1 },
|
|
{ "savepath", required_argument, 0, 2 },
|
|
{ "levelnum", required_argument, 0, 3 },
|
|
{ 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;
|
|
default:
|
|
printf(USAGE, argv[0]);
|
|
return 0;
|
|
}
|
|
}
|
|
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);
|
|
g->run();
|
|
delete g;
|
|
delete stub;
|
|
return 0;
|
|
}
|