Add config file support. Thanks |Pixel| :)

svn-id: r4111
This commit is contained in:
James Brown 2002-04-27 16:58:29 +00:00
parent d2fe8ce153
commit 2b50dd2742
8 changed files with 196 additions and 64 deletions

View file

@ -1,6 +1,6 @@
# $Header$ # $Header$
CC = gcc CC = g++
CFLAGS = -g -O -Wall -Wstrict-prototypes -Wuninitialized -Wno-long-long -Wno-multichar CFLAGS = -g -O -Wall -Wstrict-prototypes -Wuninitialized -Wno-long-long -Wno-multichar
DEFINES = -DUNIX DEFINES = -DUNIX
LDFLAGS := LDFLAGS :=

View file

@ -12,7 +12,7 @@ OBJS += actor.o boxes.o costume.o gfx.o object.o resource.o \
sound/imuse.o sound/fmopl.o sound/mixer.o debugrl.o \ sound/imuse.o sound/fmopl.o sound/mixer.o debugrl.o \
akos.o vars.o insane.o gameDetector.o init.o \ akos.o vars.o insane.o gameDetector.o init.o \
v3/resource_v3.o v4/resource_v4.o 2xsai.o main.o \ v3/resource_v3.o v4/resource_v4.o 2xsai.o main.o \
simon/midi.o simon/simon.o simon/simonsys.o sound/mididrv.o simon/midi.o simon/simon.o simon/simonsys.o sound/mididrv.o config-file.o
DISTFILES=$(OBJS:.o=.cpp) Makefile scumm.h scummsys.h stdafx.h stdafx.cpp \ DISTFILES=$(OBJS:.o=.cpp) Makefile scumm.h scummsys.h stdafx.h stdafx.cpp \
debugrl.h whatsnew.txt readme.txt copying.txt \ debugrl.h whatsnew.txt readme.txt copying.txt \

View file

@ -39,7 +39,7 @@ static const char USAGE_STRING[] =
"Flags:\n" "Flags:\n"
"\t-v - show version info and exit\n" "\t-v - show version info and exit\n"
"\t-c<num> - use cdrom <num> for cd audio\n" "\t-c<num> - use cdrom <num> for cd audio\n"
"\t-d[<num>]- enable debug output (level <num>)\n" "\t-d[<num>] - enable debug output (level <num>)\n"
"\t-n - no subtitles for speech\n" "\t-n - no subtitles for speech\n"
"\t-b<num> - start in room <num>\n" "\t-b<num> - start in room <num>\n"
"\t-t<num> - set music tempo. Suggested: 1F0000\n" "\t-t<num> - set music tempo. Suggested: 1F0000\n"
@ -51,8 +51,60 @@ static const char USAGE_STRING[] =
"\t-f - fullscreen mode\n" "\t-f - fullscreen mode\n"
"\t-g<mode> - graphics mode. normal,2x,3x,2xsai,super2xsai,supereagle.advmame2x\n" "\t-g<mode> - graphics mode. normal,2x,3x,2xsai,super2xsai,supereagle.advmame2x\n"
"\t-a - specify game is amiga version\n" "\t-a - specify game is amiga version\n"
"\t-w[<file>]- write the config file\n"
"\t-l<file> - load a different config file\n"
; ;
void GameDetector::updateconfig()
{
const char * val;
if ((val = scummcfg->get("amiga")))
if (!scumm_stricmp(val, "true"))
_amiga = true;
else
_amiga = false;
if ((val = scummcfg->get("fullscreen", "scummvm")))
if (!scumm_stricmp(val, "true"))
_fullScreen = true;
else
_fullScreen = false;
if ((val = scummcfg->get("path")))
_gameDataPath = Scumm::Strdup(val);
if ((val = scummcfg->get("tempo")))
_gameTempo = strtol(val, 0, 0);
if ((val = scummcfg->get("music_volume")))
_music_volume = atoi(val);
if ((val = scummcfg->get("sfx_volume")))
_sfx_volume = atoi(val);
if ((val = scummcfg->get("mt32emulate")))
if (!scumm_stricmp(val, "true"))
_mt32emulate = true;
else
_mt32emulate = false;
if ((val = scummcfg->get("music_driver")))
if (!parseMusicDriver(val)) {
printf(USAGE_STRING);
exit(-1);
}
if ((val = scummcfg->get("gfx_mode")))
if ((_gfx_mode = parseGraphicsMode(val)) == -1) {
printf(USAGE_STRING);
exit(-1);
}
if ((val = scummcfg->get("cdrom")))
_cdrom = atoi(val);
}
void GameDetector::parseCommandLine(int argc, char **argv) void GameDetector::parseCommandLine(int argc, char **argv)
{ {
#if !defined(__APPLE__CW) #if !defined(__APPLE__CW)
@ -65,6 +117,7 @@ void GameDetector::parseCommandLine(int argc, char **argv)
//exit(1); //exit(1);
} }
scummcfg->set_domain("game-specific");
/* Parse the arguments */ /* Parse the arguments */
for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
s = argv[i]; s = argv[i];
@ -75,6 +128,7 @@ void GameDetector::parseCommandLine(int argc, char **argv)
switch (tolower(*s++)) { switch (tolower(*s++)) {
case 'a': case 'a':
_amiga = true; _amiga = true;
scummcfg->set("amiga", "true");
break; break;
case 'b': case 'b':
s = GET_VALUE(); s = GET_VALUE();
@ -87,6 +141,7 @@ void GameDetector::parseCommandLine(int argc, char **argv)
if (*s == '\0') if (*s == '\0')
goto ShowHelpAndExit; goto ShowHelpAndExit;
_cdrom = atoi(s); _cdrom = atoi(s);
scummcfg->set("cdrom", _cdrom);
goto NextArg; goto NextArg;
case 'd': case 'd':
_debugMode = true; _debugMode = true;
@ -99,50 +154,64 @@ void GameDetector::parseCommandLine(int argc, char **argv)
s = GET_VALUE(); s = GET_VALUE();
if (!parseMusicDriver(s)) if (!parseMusicDriver(s))
goto ShowHelpAndExit; goto ShowHelpAndExit;
scummcfg->set("music_driver", s);
goto NextArg; goto NextArg;
case 'f': case 'f':
_fullScreen = true; _fullScreen = true;
scummcfg->set("fullscreen", "true", "scummvm");
break; break;
case 'g': { case 'g':
s = GET_VALUE(); s = GET_VALUE();
int gfx_mode = parseGraphicsMode(s); _gfx_mode = parseGraphicsMode(s);
if (gfx_mode == -1) if (_gfx_mode == -1)
goto ShowHelpAndExit; goto ShowHelpAndExit;
_gfx_mode = gfx_mode; scummcfg->set("gfx_mode", _gfx_mode, "scummvm");
}
goto NextArg; goto NextArg;
case 'm':{ case 'l':
s = GET_VALUE();
if (*s != '\0') {
Config * newconfig = new Config(s, "scummvm");
scummcfg->merge_config(newconfig);
delete newconfig;
updateconfig();
goto NextArg;
} else
goto ShowHelpAndExit;
case 'm':
s = GET_VALUE(); s = GET_VALUE();
if (*s == '\0') if (*s == '\0')
goto ShowHelpAndExit; goto ShowHelpAndExit;
_music_volume = atoi(s); _music_volume = atoi(s);
scummcfg->set("music_volume", _music_volume, "scummvm");
goto NextArg; goto NextArg;
}
case 'n': case 'n':
_noSubtitles = true; _noSubtitles = true;
scummcfg->set("nosubtitles", "true");
break; break;
case 'p': case 'p':
s = GET_VALUE(); s = GET_VALUE();
if (*s == '\0') if (*s == '\0')
goto ShowHelpAndExit; goto ShowHelpAndExit;
_gameDataPath = s; _gameDataPath = s;
scummcfg->set("path", _gameDataPath);
goto NextArg; goto NextArg;
case 'r':{ case 'r':
_mt32emulate = true; _mt32emulate = true;
scummcfg->set("mt32emulate", "true");
break; break;
} case 's':
case 's':{
s = GET_VALUE(); s = GET_VALUE();
if (*s == '\0') if (*s == '\0')
goto ShowHelpAndExit; goto ShowHelpAndExit;
_sfx_volume = atoi(s); _sfx_volume = atoi(s);
scummcfg->set("sfx_volume", _sfx_volume, "scummvm");
goto NextArg; goto NextArg;
}
case 't': case 't':
s = GET_VALUE(); s = GET_VALUE();
if (*s == '\0') if (*s == '\0')
goto ShowHelpAndExit; goto ShowHelpAndExit;
_gameTempo = atoi(s); _gameTempo = strtol(s + 1, 0, 0);
scummcfg->set("tempo", s + 1);
goto NextArg; goto NextArg;
case 'v': case 'v':
printf("ScummVM " SCUMMVM_VERSION "\nBuilt on " __DATE__ " " printf("ScummVM " SCUMMVM_VERSION "\nBuilt on " __DATE__ " "
@ -152,6 +221,12 @@ void GameDetector::parseCommandLine(int argc, char **argv)
#endif #endif
exit(1); exit(1);
case 'w':
_saveconfig = true;
s = GET_VALUE();
if (*s != '\0')
scummcfg->change_filename(s);
goto NextArg;
default: default:
ShowHelpAndExit:; ShowHelpAndExit:;
printf(USAGE_STRING); printf(USAGE_STRING);
@ -163,9 +238,14 @@ void GameDetector::parseCommandLine(int argc, char **argv)
if (_exe_name) if (_exe_name)
goto ShowHelpAndExit; goto ShowHelpAndExit;
_exe_name = s; _exe_name = s;
scummcfg->rename_domain(s);
scummcfg->set_domain(s);
updateconfig();
} }
} }
if (_saveconfig)
scummcfg->flush();
#else #else
_midi_driver = 4; /* FIXME: don't use numerics */ _midi_driver = 4; /* FIXME: don't use numerics */
_exe_name = *argv; _exe_name = *argv;
@ -346,9 +426,9 @@ char *GameDetector::getGameName()
if (_gameText == NULL) { if (_gameText == NULL) {
char buf[256]; char buf[256];
sprintf(buf, "Unknown game: \"%s\"", _exe_name); sprintf(buf, "Unknown game: \"%s\"", _exe_name);
return strdup(buf); return Scumm::Strdup(buf);
} }
return strdup(_gameText); return Scumm::Strdup(_gameText);
} }
int GameDetector::detectMain(int argc, char **argv) int GameDetector::detectMain(int argc, char **argv)
@ -387,6 +467,8 @@ int GameDetector::detectMain(int argc, char **argv)
extern int dc_setup(GameDetector &detector); extern int dc_setup(GameDetector &detector);
dc_setup(*this); dc_setup(*this);
#else #else
_saveconfig = false;
updateconfig();
parseCommandLine(argc, argv); parseCommandLine(argc, argv);
#endif #endif
@ -413,7 +495,7 @@ int GameDetector::detectMain(int argc, char **argv)
if (!_gameDataPath) { if (!_gameDataPath) {
warning("No path was provided. Assuming the data files are in the current directory"); warning("No path was provided. Assuming the data files are in the current directory");
_gameDataPath = strdup(""); _gameDataPath = Scumm::Strdup("");
} }
if (_amiga) if (_amiga)

View file

@ -57,10 +57,14 @@ public:
int _scummVersion; int _scummVersion;
int _cdrom; int _cdrom;
bool _saveconfig;
int parseGraphicsMode(const char *s); int parseGraphicsMode(const char *s);
bool parseMusicDriver(const char *s); bool parseMusicDriver(const char *s);
void updateconfig();
public: public:
OSystem *createSystem(); OSystem *createSystem();
MidiDriver *createMidi(); MidiDriver *createMidi();

View file

@ -26,12 +26,15 @@
#include "gameDetector.h" #include "gameDetector.h"
#include "gui.h" #include "gui.h"
#include "simon/simon.h" #include "simon/simon.h"
#include "config-file.h"
GameDetector detector; GameDetector detector;
Gui gui; Gui gui;
Scumm *g_scumm; Scumm *g_scumm;
Config * scummcfg;
#if defined(__APPLE__) #if defined(__APPLE__)
#include <SDL.h> #include <SDL.h>
@ -39,6 +42,8 @@ Scumm *g_scumm;
#undef main #undef main
#endif #endif
#define DEFAULT_CONFIG_FILE "scummvm.ini"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
#if defined(MACOS) #if defined(MACOS)
@ -74,7 +79,8 @@ int main(int argc, char *argv[])
fclose(argf); fclose(argf);
#endif #endif
scummcfg = new Config(DEFAULT_CONFIG_FILE, "scummvm");
scummcfg->set("versioninfo", SCUMMVM_VERSION);
if (detector.detectMain(argc, argv)) if (detector.detectMain(argc, argv))
return (-1); return (-1);
@ -83,7 +89,7 @@ int main(int argc, char *argv[])
{ {
char *s = detector.getGameName(); char *s = detector.getGameName();
system->property(OSystem::PROP_SET_WINDOW_CAPTION, (long)s); system->property(OSystem::PROP_SET_WINDOW_CAPTION, (long)s);
free(s); Scumm::free(s);
} }
/* Simon the Sorcerer? */ /* Simon the Sorcerer? */
@ -108,5 +114,7 @@ int main(int argc, char *argv[])
scumm->go(); scumm->go();
} }
delete scummcfg;
return 0; return 0;
} }

View file

@ -176,6 +176,10 @@ and you wish to disable subtitles and run in fullscreen:
C:\Games\LucasArts\scummvm.exe -f -n -pD:\resource\ ft C:\Games\LucasArts\scummvm.exe -f -n -pD:\resource\ ft
Note that if you run the game once this way, and specify the -w commandline
parameter (or edit scummvm.ini manually), ScummVM will remember the path,
and other settings for this game.
The short game name you see at the end of the command line is very The short game name you see at the end of the command line is very
important. A short list is contained at the top of this file. You can also important. A short list is contained at the top of this file. You can also
get the current list of games and game names at: get the current list of games and game names at:
@ -206,7 +210,8 @@ Command Line Options:
-r - Enable Roland conversion. Try if music sounds incorrect. -r - Enable Roland conversion. Try if music sounds incorrect.
-a - Enable amiga pal conversion, for playing Amiga versions -a - Enable amiga pal conversion, for playing Amiga versions
-d[<num>] - Set debug verbosity to <num> -d[<num>] - Set debug verbosity to <num>
-w[<file>] - Write configuration file
-l<file> - Load alternate configration file (default: scummvm.ini)
In game Hot Keys: In game Hot Keys:
----------------- -----------------
@ -376,6 +381,7 @@ Credits:
Daniel Schepler - Final MI1 CD music support Daniel Schepler - Final MI1 CD music support
Tim 'realmz' - Initial MI1 CD music support Tim 'realmz' - Initial MI1 CD music support
Jonathan 'khalek' - Expert weaver in the Loom Jonathan 'khalek' - Expert weaver in the Loom
Nicolas Noble - Config file support
And to all the contributors, users, and beta testers we've missed. And to all the contributors, users, and beta testers we've missed.
Thanks! Thanks!

View file

@ -22,6 +22,7 @@
#include "scummsys.h" #include "scummsys.h"
#include "system.h" #include "system.h"
#include "sound/mixer.h" #include "sound/mixer.h"
#include "config-file.h"
#define SCUMMVM_VERSION "0.2.0 devel" #define SCUMMVM_VERSION "0.2.0 devel"
#define SCUMMVM_CVS "042002" #define SCUMMVM_CVS "042002"
@ -1337,7 +1338,9 @@ public:
uint fileReadWordBE(); uint fileReadWordBE();
static byte *alloc(int size); static byte *alloc(int size);
static byte *realloc(void *mem, int size);
static void free(void *mem); static void free(void *mem);
static char *Strdup(const char *);
/* Version 5 script opcodes */ /* Version 5 script opcodes */
void o5_actorFollowCamera(); void o5_actorFollowCamera();
@ -1848,6 +1851,8 @@ void outputdisplay2(Scumm *s, int disp);
extern const byte revBitMask[8]; extern const byte revBitMask[8];
//void blitToScreen(Scumm *s, byte *src, int x, int y, int w, int h); //void blitToScreen(Scumm *s, byte *src, int x, int y, int w, int h);
extern Config * scummcfg;
#if defined(__GNUC__) #if defined(__GNUC__)
void CDECL error(const char *s, ...) NORETURN; void CDECL error(const char *s, ...) NORETURN;
#else #else

27
sys.cpp
View file

@ -184,6 +184,33 @@ void Scumm::free(void *mem)
} }
} }
byte *Scumm::realloc(void *mem, int size)
{
byte * me = (byte *) mem;
if (mem) {
if (size) {
me = (byte *) ::realloc((me - 4), size + 4);
return me + 4;
} else {
free(me);
return NULL;
}
} else {
return alloc(size);
}
}
char *Scumm::Strdup(const char *s)
{
if (s) {
int l = strlen(s) + 1;
char * r = (char *) alloc(l);
memcpy(r, s, l);
return r;
}
return NULL;
}
bool Scumm::checkFixedDisk() bool Scumm::checkFixedDisk()
{ {
return true; return true;