aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Brown2002-04-27 16:58:29 +0000
committerJames Brown2002-04-27 16:58:29 +0000
commit2b50dd27420654d3eeee7c163ec96aedc0478936 (patch)
tree1c9f8406ec52560777848b2a63692c0fec50e890
parentd2fe8ce153ac764cf65a1ab4a895d57a150df116 (diff)
downloadscummvm-rg350-2b50dd27420654d3eeee7c163ec96aedc0478936.tar.gz
scummvm-rg350-2b50dd27420654d3eeee7c163ec96aedc0478936.tar.bz2
scummvm-rg350-2b50dd27420654d3eeee7c163ec96aedc0478936.zip
Add config file support. Thanks |Pixel| :)
svn-id: r4111
-rw-r--r--Makefile2
-rw-r--r--Makefile.common2
-rw-r--r--gameDetector.cpp170
-rw-r--r--gameDetector.h4
-rw-r--r--main.cpp12
-rw-r--r--readme.txt38
-rw-r--r--scumm.h5
-rw-r--r--sys.cpp27
8 files changed, 196 insertions, 64 deletions
diff --git a/Makefile b/Makefile
index 998779849a..de431fe47d 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
# $Header$
-CC = gcc
+CC = g++
CFLAGS = -g -O -Wall -Wstrict-prototypes -Wuninitialized -Wno-long-long -Wno-multichar
DEFINES = -DUNIX
LDFLAGS :=
diff --git a/Makefile.common b/Makefile.common
index ca380787be..35194e5797 100644
--- a/Makefile.common
+++ b/Makefile.common
@@ -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 \
akos.o vars.o insane.o gameDetector.o init.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 \
debugrl.h whatsnew.txt readme.txt copying.txt \
diff --git a/gameDetector.cpp b/gameDetector.cpp
index bbc9180bc1..71e79519c1 100644
--- a/gameDetector.cpp
+++ b/gameDetector.cpp
@@ -37,22 +37,74 @@ static const char USAGE_STRING[] =
"Syntax:\n"
"\tscummvm [-v] [-d[<num>]] [-n] [-b<num>] [-t<num>] [-s<num>] [-p<path>] [-m<num>] [-f] game\n"
"Flags:\n"
- "\t-v - show version info and exit\n"
- "\t-c<num> - use cdrom <num> for cd audio\n"
- "\t-d[<num>]- enable debug output (level <num>)\n"
- "\t-n - no subtitles for speech\n"
- "\t-b<num> - start in room <num>\n"
- "\t-t<num> - set music tempo. Suggested: 1F0000\n"
- "\t-p<path> - look for game in <path>\n"
- "\t-m<num> - set music volume to <num> (0-100)\n"
- "\t-s<num> - set sfx volume to <num> (0-255)\n"
- "\t-e<mode> - set music engine. see readme.txt for details\n"
- "\t-r - emulate roland mt32 instruments\n"
- "\t-f - fullscreen mode\n"
- "\t-g<mode> - graphics mode. normal,2x,3x,2xsai,super2xsai,supereagle.advmame2x\n"
- "\t-a - specify game is amiga version\n"
+ "\t-v - show version info and exit\n"
+ "\t-c<num> - use cdrom <num> for cd audio\n"
+ "\t-d[<num>] - enable debug output (level <num>)\n"
+ "\t-n - no subtitles for speech\n"
+ "\t-b<num> - start in room <num>\n"
+ "\t-t<num> - set music tempo. Suggested: 1F0000\n"
+ "\t-p<path> - look for game in <path>\n"
+ "\t-m<num> - set music volume to <num> (0-100)\n"
+ "\t-s<num> - set sfx volume to <num> (0-255)\n"
+ "\t-e<mode> - set music engine. see readme.txt for details\n"
+ "\t-r - emulate roland mt32 instruments\n"
+ "\t-f - fullscreen mode\n"
+ "\t-g<mode> - graphics mode. normal,2x,3x,2xsai,super2xsai,supereagle.advmame2x\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)
{
#if !defined(__APPLE__CW)
@@ -65,6 +117,7 @@ void GameDetector::parseCommandLine(int argc, char **argv)
//exit(1);
}
+ scummcfg->set_domain("game-specific");
/* Parse the arguments */
for (i = 1; i < argc; i++) {
s = argv[i];
@@ -75,6 +128,7 @@ void GameDetector::parseCommandLine(int argc, char **argv)
switch (tolower(*s++)) {
case 'a':
_amiga = true;
+ scummcfg->set("amiga", "true");
break;
case 'b':
s = GET_VALUE();
@@ -87,6 +141,7 @@ void GameDetector::parseCommandLine(int argc, char **argv)
if (*s == '\0')
goto ShowHelpAndExit;
_cdrom = atoi(s);
+ scummcfg->set("cdrom", _cdrom);
goto NextArg;
case 'd':
_debugMode = true;
@@ -99,50 +154,64 @@ void GameDetector::parseCommandLine(int argc, char **argv)
s = GET_VALUE();
if (!parseMusicDriver(s))
goto ShowHelpAndExit;
+ scummcfg->set("music_driver", s);
goto NextArg;
case 'f':
_fullScreen = true;
+ scummcfg->set("fullscreen", "true", "scummvm");
break;
- case 'g': {
- s = GET_VALUE();
- int gfx_mode = parseGraphicsMode(s);
- if (gfx_mode == -1)
- goto ShowHelpAndExit;
- _gfx_mode = gfx_mode;
- }
+ case 'g':
+ s = GET_VALUE();
+ _gfx_mode = parseGraphicsMode(s);
+ if (_gfx_mode == -1)
+ goto ShowHelpAndExit;
+ scummcfg->set("gfx_mode", _gfx_mode, "scummvm");
+ goto NextArg;
+ 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();
+ if (*s == '\0')
+ goto ShowHelpAndExit;
+ _music_volume = atoi(s);
+ scummcfg->set("music_volume", _music_volume, "scummvm");
goto NextArg;
- case 'm':{
- s = GET_VALUE();
- if (*s == '\0')
- goto ShowHelpAndExit;
- _music_volume = atoi(s);
- goto NextArg;
- }
case 'n':
_noSubtitles = true;
+ scummcfg->set("nosubtitles", "true");
break;
case 'p':
s = GET_VALUE();
if (*s == '\0')
goto ShowHelpAndExit;
_gameDataPath = s;
+ scummcfg->set("path", _gameDataPath);
goto NextArg;
- case 'r':{
- _mt32emulate = true;
- break;
- }
- case 's':{
- s = GET_VALUE();
- if (*s == '\0')
- goto ShowHelpAndExit;
- _sfx_volume = atoi(s);
- goto NextArg;
- }
+ case 'r':
+ _mt32emulate = true;
+ scummcfg->set("mt32emulate", "true");
+ break;
+ case 's':
+ s = GET_VALUE();
+ if (*s == '\0')
+ goto ShowHelpAndExit;
+ _sfx_volume = atoi(s);
+ scummcfg->set("sfx_volume", _sfx_volume, "scummvm");
+ goto NextArg;
case 't':
s = GET_VALUE();
if (*s == '\0')
goto ShowHelpAndExit;
- _gameTempo = atoi(s);
+ _gameTempo = strtol(s + 1, 0, 0);
+ scummcfg->set("tempo", s + 1);
goto NextArg;
case 'v':
printf("ScummVM " SCUMMVM_VERSION "\nBuilt on " __DATE__ " "
@@ -152,6 +221,12 @@ void GameDetector::parseCommandLine(int argc, char **argv)
#endif
exit(1);
+ case 'w':
+ _saveconfig = true;
+ s = GET_VALUE();
+ if (*s != '\0')
+ scummcfg->change_filename(s);
+ goto NextArg;
default:
ShowHelpAndExit:;
printf(USAGE_STRING);
@@ -163,9 +238,14 @@ void GameDetector::parseCommandLine(int argc, char **argv)
if (_exe_name)
goto ShowHelpAndExit;
_exe_name = s;
+ scummcfg->rename_domain(s);
+ scummcfg->set_domain(s);
+ updateconfig();
}
}
-
+
+ if (_saveconfig)
+ scummcfg->flush();
#else
_midi_driver = 4; /* FIXME: don't use numerics */
_exe_name = *argv;
@@ -346,9 +426,9 @@ char *GameDetector::getGameName()
if (_gameText == NULL) {
char buf[256];
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)
@@ -387,6 +467,8 @@ int GameDetector::detectMain(int argc, char **argv)
extern int dc_setup(GameDetector &detector);
dc_setup(*this);
#else
+ _saveconfig = false;
+ updateconfig();
parseCommandLine(argc, argv);
#endif
@@ -413,7 +495,7 @@ int GameDetector::detectMain(int argc, char **argv)
if (!_gameDataPath) {
warning("No path was provided. Assuming the data files are in the current directory");
- _gameDataPath = strdup("");
+ _gameDataPath = Scumm::Strdup("");
}
if (_amiga)
diff --git a/gameDetector.h b/gameDetector.h
index 5fb53cc804..caf2427f02 100644
--- a/gameDetector.h
+++ b/gameDetector.h
@@ -56,10 +56,14 @@ public:
int _scummVersion;
int _cdrom;
+
+ bool _saveconfig;
int parseGraphicsMode(const char *s);
bool parseMusicDriver(const char *s);
+
+ void updateconfig();
public:
OSystem *createSystem();
diff --git a/main.cpp b/main.cpp
index caae3d0f6e..188545d399 100644
--- a/main.cpp
+++ b/main.cpp
@@ -26,12 +26,15 @@
#include "gameDetector.h"
#include "gui.h"
#include "simon/simon.h"
+#include "config-file.h"
GameDetector detector;
Gui gui;
Scumm *g_scumm;
+Config * scummcfg;
+
#if defined(__APPLE__)
#include <SDL.h>
@@ -39,6 +42,8 @@ Scumm *g_scumm;
#undef main
#endif
+#define DEFAULT_CONFIG_FILE "scummvm.ini"
+
int main(int argc, char *argv[])
{
#if defined(MACOS)
@@ -74,7 +79,8 @@ int main(int argc, char *argv[])
fclose(argf);
#endif
-
+ scummcfg = new Config(DEFAULT_CONFIG_FILE, "scummvm");
+ scummcfg->set("versioninfo", SCUMMVM_VERSION);
if (detector.detectMain(argc, argv))
return (-1);
@@ -83,7 +89,7 @@ int main(int argc, char *argv[])
{
char *s = detector.getGameName();
system->property(OSystem::PROP_SET_WINDOW_CAPTION, (long)s);
- free(s);
+ Scumm::free(s);
}
/* Simon the Sorcerer? */
@@ -108,5 +114,7 @@ int main(int argc, char *argv[])
scumm->go();
}
+ delete scummcfg;
+
return 0;
}
diff --git a/readme.txt b/readme.txt
index 4eba4f5f75..ecb9a4635b 100644
--- a/readme.txt
+++ b/readme.txt
@@ -176,6 +176,10 @@ and you wish to disable subtitles and run in fullscreen:
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
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:
@@ -191,22 +195,23 @@ Command Line Options:
scummvm [OPTIONS] [GAME]
- [GAME] - Short name of game to load. E.g. monkey for Monkey Island.
+ [GAME] - Short name of game to load. E.g. monkey for Monkey Island.
- -p<path> - Path to where the game is installed. Default is Cwd.
- -b<num> - Start in room <num>.
- -c<num> - Drive to play cd audio from. E.g., 0 is first drive.
- -s<num> - Set the sfx volume, 0-255. Default is '100'
- -m<num> - Set the music volume, 0-100. Default is '60'
- -t<num> - Set music tempo. Default is '2031616'
- -e<mode> - Select sound engine. See below.
- -g<mode> - Select graphics scaler. See below.
- -f - Full-screen mode.
- -n - Disable subtitles. Use with games that have voice.
- -r - Enable Roland conversion. Try if music sounds incorrect.
- -a - Enable amiga pal conversion, for playing Amiga versions
- -d[<num>] - Set debug verbosity to <num>
-
+ -p<path> - Path to where the game is installed. Default is Cwd.
+ -b<num> - Start in room <num>.
+ -c<num> - Drive to play cd audio from. E.g., 0 is first drive.
+ -s<num> - Set the sfx volume, 0-255. Default is '100'
+ -m<num> - Set the music volume, 0-100. Default is '60'
+ -t<num> - Set music tempo. Default is '2031616'
+ -e<mode> - Select sound engine. See below.
+ -g<mode> - Select graphics scaler. See below.
+ -f - Full-screen mode.
+ -n - Disable subtitles. Use with games that have voice.
+ -r - Enable Roland conversion. Try if music sounds incorrect.
+ -a - Enable amiga pal conversion, for playing Amiga versions
+ -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:
-----------------
@@ -376,7 +381,8 @@ Credits:
Daniel Schepler - Final MI1 CD music support
Tim 'realmz' - Initial MI1 CD music support
Jonathan 'khalek' - Expert weaver in the Loom
-
+ Nicolas Noble - Config file support
+
And to all the contributors, users, and beta testers we've missed.
Thanks!
diff --git a/scumm.h b/scumm.h
index 421ff60225..c35b5a19cc 100644
--- a/scumm.h
+++ b/scumm.h
@@ -22,6 +22,7 @@
#include "scummsys.h"
#include "system.h"
#include "sound/mixer.h"
+#include "config-file.h"
#define SCUMMVM_VERSION "0.2.0 devel"
#define SCUMMVM_CVS "042002"
@@ -1337,7 +1338,9 @@ public:
uint fileReadWordBE();
static byte *alloc(int size);
+ static byte *realloc(void *mem, int size);
static void free(void *mem);
+ static char *Strdup(const char *);
/* Version 5 script opcodes */
void o5_actorFollowCamera();
@@ -1848,6 +1851,8 @@ void outputdisplay2(Scumm *s, int disp);
extern const byte revBitMask[8];
//void blitToScreen(Scumm *s, byte *src, int x, int y, int w, int h);
+extern Config * scummcfg;
+
#if defined(__GNUC__)
void CDECL error(const char *s, ...) NORETURN;
#else
diff --git a/sys.cpp b/sys.cpp
index 56c1516ad8..5c5d23e431 100644
--- a/sys.cpp
+++ b/sys.cpp
@@ -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()
{
return true;