2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2002-07-12 16:24:11 +00:00
|
|
|
*
|
|
|
|
* 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 2
|
|
|
|
* 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, write to the Free Software
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-07-12 16:24:11 +00:00
|
|
|
*
|
2006-02-11 09:53:53 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2002-07-12 16:24:11 +00:00
|
|
|
*/
|
|
|
|
|
2003-08-01 12:21:04 +00:00
|
|
|
#include "common/util.h"
|
2006-09-23 00:51:30 +00:00
|
|
|
#include "common/system.h"
|
2009-07-13 18:47:32 +00:00
|
|
|
#include "common/config-manager.h"
|
2002-07-12 16:24:11 +00:00
|
|
|
|
2003-10-04 11:50:21 +00:00
|
|
|
namespace Common {
|
2002-07-12 16:24:11 +00:00
|
|
|
|
2002-09-16 10:42:12 +00:00
|
|
|
//
|
2003-05-02 21:29:05 +00:00
|
|
|
// Print hexdump of the data passed in
|
2002-09-16 10:42:12 +00:00
|
|
|
//
|
2009-05-12 07:07:17 +00:00
|
|
|
void hexdump(const byte * data, int len, int bytesPerLine, int startOffset) {
|
2003-10-04 11:50:21 +00:00
|
|
|
assert(1 <= bytesPerLine && bytesPerLine <= 32);
|
2002-07-25 16:29:07 +00:00
|
|
|
int i;
|
|
|
|
byte c;
|
2009-05-12 07:07:17 +00:00
|
|
|
int offset = startOffset;
|
2003-10-04 11:50:21 +00:00
|
|
|
while (len >= bytesPerLine) {
|
2003-05-04 13:46:06 +00:00
|
|
|
printf("%06x: ", offset);
|
2003-10-04 11:50:21 +00:00
|
|
|
for (i = 0; i < bytesPerLine; i++) {
|
2002-07-25 16:29:07 +00:00
|
|
|
printf("%02x ", data[i]);
|
2003-05-04 13:46:06 +00:00
|
|
|
if (i % 4 == 3)
|
|
|
|
printf(" ");
|
|
|
|
}
|
2002-07-25 16:29:07 +00:00
|
|
|
printf(" |");
|
2003-10-04 11:50:21 +00:00
|
|
|
for (i = 0; i < bytesPerLine; i++) {
|
2002-07-25 16:29:07 +00:00
|
|
|
c = data[i];
|
2002-08-31 14:14:24 +00:00
|
|
|
if (c < 32 || c >= 127)
|
2002-07-25 16:29:07 +00:00
|
|
|
c = '.';
|
|
|
|
printf("%c", c);
|
|
|
|
}
|
|
|
|
printf("|\n");
|
2003-10-04 11:50:21 +00:00
|
|
|
data += bytesPerLine;
|
|
|
|
len -= bytesPerLine;
|
|
|
|
offset += bytesPerLine;
|
2002-07-25 16:29:07 +00:00
|
|
|
}
|
|
|
|
|
2005-07-30 21:11:48 +00:00
|
|
|
if (len <= 0)
|
2002-07-26 17:40:04 +00:00
|
|
|
return;
|
|
|
|
|
2003-05-04 13:46:06 +00:00
|
|
|
printf("%06x: ", offset);
|
2003-12-13 17:33:21 +00:00
|
|
|
for (i = 0; i < bytesPerLine; i++) {
|
|
|
|
if (i < len)
|
|
|
|
printf("%02x ", data[i]);
|
|
|
|
else
|
|
|
|
printf(" ");
|
2003-05-04 13:46:06 +00:00
|
|
|
if (i % 4 == 3)
|
|
|
|
printf(" ");
|
|
|
|
}
|
2002-07-25 16:29:07 +00:00
|
|
|
printf(" |");
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
c = data[i];
|
2002-08-31 14:14:24 +00:00
|
|
|
if (c < 32 || c >= 127)
|
2002-07-25 16:29:07 +00:00
|
|
|
c = '.';
|
|
|
|
printf("%c", c);
|
|
|
|
}
|
2003-10-04 11:50:21 +00:00
|
|
|
for (; i < bytesPerLine; i++)
|
2002-07-25 16:29:07 +00:00
|
|
|
printf(" ");
|
|
|
|
printf("|\n");
|
|
|
|
}
|
2002-09-15 09:06:58 +00:00
|
|
|
|
2009-01-30 01:17:12 +00:00
|
|
|
|
2003-10-17 15:35:46 +00:00
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
|
2010-04-06 09:27:13 +00:00
|
|
|
bool parseBool(const Common::String &val, bool &valAsBool) {
|
|
|
|
if (val.equalsIgnoreCase("true") ||
|
|
|
|
val.equalsIgnoreCase("yes") ||
|
|
|
|
val.equals("1")) {
|
|
|
|
valAsBool = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (val.equalsIgnoreCase("false") ||
|
|
|
|
val.equalsIgnoreCase("no") ||
|
|
|
|
val.equals("0")) {
|
|
|
|
valAsBool = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
|
2003-11-05 00:58:02 +00:00
|
|
|
const LanguageDescription g_languages[] = {
|
2009-12-31 18:52:42 +00:00
|
|
|
{"zh-cn", "Chinese (China)", ZH_CNA},
|
2007-04-24 06:31:04 +00:00
|
|
|
{"zh", "Chinese (Taiwan)", ZH_TWN},
|
|
|
|
{"cz", "Czech", CZ_CZE},
|
|
|
|
{"nl", "Dutch", NL_NLD},
|
2006-04-08 23:20:15 +00:00
|
|
|
{"en", "English", EN_ANY}, // Generic English (when only one game version exist)
|
2006-04-11 22:31:47 +00:00
|
|
|
{"gb", "English (GB)", EN_GRB},
|
2007-04-24 06:31:04 +00:00
|
|
|
{"us", "English (US)", EN_USA},
|
2003-10-17 15:35:46 +00:00
|
|
|
{"fr", "French", FR_FRA},
|
2007-04-24 06:31:04 +00:00
|
|
|
{"de", "German", DE_DEU},
|
2007-11-01 17:02:28 +00:00
|
|
|
{"gr", "Greek", GR_GRE},
|
2010-04-12 21:21:06 +00:00
|
|
|
{"he", "Hebrew", HE_ISR},
|
|
|
|
{"hb", "Hebrew", HE_ISR}, // Deprecated
|
2010-01-03 16:33:03 +00:00
|
|
|
{"hu", "Hungarian", HU_HUN},
|
2003-10-17 15:35:46 +00:00
|
|
|
{"it", "Italian", IT_ITA},
|
|
|
|
{"jp", "Japanese", JA_JPN},
|
|
|
|
{"kr", "Korean", KO_KOR},
|
2005-09-03 19:59:33 +00:00
|
|
|
{"nb", "Norwegian Bokm\xE5l", NB_NOR},
|
2005-11-18 00:59:47 +00:00
|
|
|
{"pl", "Polish", PL_POL},
|
2007-04-24 06:31:04 +00:00
|
|
|
{"br", "Portuguese", PT_BRA},
|
|
|
|
{"ru", "Russian", RU_RUS},
|
|
|
|
{"es", "Spanish", ES_ESP},
|
|
|
|
{"se", "Swedish", SE_SWE},
|
2003-10-17 15:35:46 +00:00
|
|
|
{0, 0, UNK_LANG}
|
|
|
|
};
|
|
|
|
|
|
|
|
Language parseLanguage(const String &str) {
|
2006-03-28 09:42:54 +00:00
|
|
|
if (str.empty())
|
2003-10-17 15:35:46 +00:00
|
|
|
return UNK_LANG;
|
|
|
|
|
2003-11-05 00:58:02 +00:00
|
|
|
const LanguageDescription *l = g_languages;
|
2003-12-30 19:07:55 +00:00
|
|
|
for (; l->code; ++l) {
|
2008-08-27 20:41:28 +00:00
|
|
|
if (str.equalsIgnoreCase(l->code))
|
2003-10-17 15:35:46 +00:00
|
|
|
return l->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
return UNK_LANG;
|
|
|
|
}
|
|
|
|
|
2003-12-30 19:07:55 +00:00
|
|
|
const char *getLanguageCode(Language id) {
|
|
|
|
const LanguageDescription *l = g_languages;
|
|
|
|
for (; l->code; ++l) {
|
|
|
|
if (l->id == id)
|
|
|
|
return l->code;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2003-10-17 15:35:46 +00:00
|
|
|
|
2003-12-30 19:07:55 +00:00
|
|
|
const char *getLanguageDescription(Language id) {
|
2003-11-05 00:58:02 +00:00
|
|
|
const LanguageDescription *l = g_languages;
|
2003-12-30 19:07:55 +00:00
|
|
|
for (; l->code; ++l) {
|
2003-11-05 00:58:02 +00:00
|
|
|
if (l->id == id)
|
2003-12-30 19:07:55 +00:00
|
|
|
return l->description;
|
2003-11-05 00:58:02 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-17 15:35:46 +00:00
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
|
2004-02-07 17:10:48 +00:00
|
|
|
const PlatformDescription g_platforms[] = {
|
2009-10-15 22:05:52 +00:00
|
|
|
{"2gs", "2gs", "2gs", "Apple IIgs", kPlatformApple2GS},
|
2007-01-29 23:25:51 +00:00
|
|
|
{"3do", "3do", "3do", "3DO", kPlatform3DO},
|
|
|
|
{"acorn", "acorn", "acorn", "Acorn", kPlatformAcorn},
|
|
|
|
{"amiga", "ami", "amiga", "Amiga", kPlatformAmiga},
|
|
|
|
{"atari", "atari-st", "st", "Atari ST", kPlatformAtariST},
|
|
|
|
{"c64", "c64", "c64", "Commodore 64", kPlatformC64},
|
|
|
|
{"pc", "dos", "ibm", "DOS", kPlatformPC},
|
2007-09-15 14:53:21 +00:00
|
|
|
{"pc98", "pc98", "pc98", "PC-98", kPlatformPC98},
|
2008-09-03 01:47:01 +00:00
|
|
|
{"wii", "wii", "wii", "Nintendo Wii", kPlatformWii},
|
2009-06-06 18:22:43 +00:00
|
|
|
{"coco3", "coco3", "coco3", "CoCo3", kPlatformCoCo3},
|
2004-02-07 16:01:00 +00:00
|
|
|
|
|
|
|
// The 'official' spelling seems to be "FM-TOWNS" (e.g. in the Indy4 demo).
|
|
|
|
// However, on the net many variations can be seen, like "FMTOWNS",
|
|
|
|
// "FM TOWNS", "FmTowns", etc.
|
2007-01-29 23:25:51 +00:00
|
|
|
{"fmtowns", "towns", "fm", "FM-TOWNS", kPlatformFMTowns},
|
2004-02-07 16:01:00 +00:00
|
|
|
|
2007-01-29 23:25:51 +00:00
|
|
|
{"linux", "linux", "linux", "Linux", kPlatformLinux},
|
|
|
|
{"macintosh", "mac", "mac", "Macintosh", kPlatformMacintosh},
|
2009-10-15 22:05:52 +00:00
|
|
|
{"pce", "pce", "pce", "PC-Engine", kPlatformPCEngine},
|
2007-01-29 23:25:51 +00:00
|
|
|
{"nes", "nes", "nes", "NES", kPlatformNES},
|
|
|
|
{"segacd", "segacd", "sega", "SegaCD", kPlatformSegaCD},
|
|
|
|
{"windows", "win", "win", "Windows", kPlatformWindows},
|
2009-06-05 22:35:13 +00:00
|
|
|
{"playstation", "psx", "psx", "Sony PlayStation", kPlatformPSX},
|
2009-10-15 22:05:52 +00:00
|
|
|
{"cdi", "cdi", "cdi", "Phillips CD-i", kPlatformCDi},
|
2006-12-19 01:06:45 +00:00
|
|
|
|
2007-01-29 23:25:51 +00:00
|
|
|
{0, 0, 0, "Default", kPlatformUnknown}
|
2003-12-30 19:07:55 +00:00
|
|
|
};
|
|
|
|
|
2003-10-17 15:35:46 +00:00
|
|
|
Platform parsePlatform(const String &str) {
|
2006-03-28 09:42:54 +00:00
|
|
|
if (str.empty())
|
2003-10-17 15:35:46 +00:00
|
|
|
return kPlatformUnknown;
|
|
|
|
|
2003-12-30 19:07:55 +00:00
|
|
|
// Handle some special case separately, for compatibility with old config
|
|
|
|
// files.
|
2008-08-27 20:41:28 +00:00
|
|
|
if (str == "1")
|
2003-10-17 15:35:46 +00:00
|
|
|
return kPlatformAmiga;
|
2008-08-27 20:41:28 +00:00
|
|
|
else if (str == "2")
|
2003-10-17 15:35:46 +00:00
|
|
|
return kPlatformAtariST;
|
2008-08-27 20:41:28 +00:00
|
|
|
else if (str == "3")
|
2003-10-17 15:35:46 +00:00
|
|
|
return kPlatformMacintosh;
|
2003-12-30 19:07:55 +00:00
|
|
|
|
|
|
|
const PlatformDescription *l = g_platforms;
|
|
|
|
for (; l->code; ++l) {
|
2008-08-27 20:41:28 +00:00
|
|
|
if (str.equalsIgnoreCase(l->code) || str.equalsIgnoreCase(l->code2) || str.equalsIgnoreCase(l->abbrev))
|
2003-12-30 19:07:55 +00:00
|
|
|
return l->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
return kPlatformUnknown;
|
2003-10-17 15:35:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-30 19:07:55 +00:00
|
|
|
const char *getPlatformCode(Platform id) {
|
|
|
|
const PlatformDescription *l = g_platforms;
|
|
|
|
for (; l->code; ++l) {
|
|
|
|
if (l->id == id)
|
|
|
|
return l->code;
|
2003-11-05 00:58:02 +00:00
|
|
|
}
|
2003-12-30 19:07:55 +00:00
|
|
|
return 0;
|
2003-11-05 00:58:02 +00:00
|
|
|
}
|
|
|
|
|
2007-01-29 23:25:51 +00:00
|
|
|
const char *getPlatformAbbrev(Platform id) {
|
|
|
|
const PlatformDescription *l = g_platforms;
|
|
|
|
for (; l->code; ++l) {
|
|
|
|
if (l->id == id)
|
|
|
|
return l->abbrev;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-12-30 19:07:55 +00:00
|
|
|
const char *getPlatformDescription(Platform id) {
|
|
|
|
const PlatformDescription *l = g_platforms;
|
|
|
|
for (; l->code; ++l) {
|
|
|
|
if (l->id == id)
|
|
|
|
return l->description;
|
|
|
|
}
|
2004-01-26 16:52:19 +00:00
|
|
|
return l->description;
|
2003-12-30 19:07:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-20 00:17:22 +00:00
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
|
|
|
|
const RenderModeDescription g_renderModes[] = {
|
2005-03-02 21:46:51 +00:00
|
|
|
{"hercGreen", "Hercules Green", kRenderHercG},
|
|
|
|
{"hercAmber", "Hercules Amber", kRenderHercA},
|
2005-02-20 00:17:22 +00:00
|
|
|
{"cga", "CGA", kRenderCGA},
|
|
|
|
{"ega", "EGA", kRenderEGA},
|
2005-03-07 00:39:48 +00:00
|
|
|
{"amiga", "Amiga", kRenderAmiga},
|
2005-02-20 00:17:22 +00:00
|
|
|
{0, 0, kRenderDefault}
|
|
|
|
};
|
|
|
|
|
|
|
|
RenderMode parseRenderMode(const String &str) {
|
2006-03-28 09:42:54 +00:00
|
|
|
if (str.empty())
|
2005-02-20 00:17:22 +00:00
|
|
|
return kRenderDefault;
|
|
|
|
|
|
|
|
const RenderModeDescription *l = g_renderModes;
|
|
|
|
for (; l->code; ++l) {
|
2008-08-27 20:41:28 +00:00
|
|
|
if (str.equalsIgnoreCase(l->code))
|
2005-02-20 00:17:22 +00:00
|
|
|
return l->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
return kRenderDefault;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *getRenderModeCode(RenderMode id) {
|
|
|
|
const RenderModeDescription *l = g_renderModes;
|
|
|
|
for (; l->code; ++l) {
|
|
|
|
if (l->id == id)
|
|
|
|
return l->code;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *getRenderModeDescription(RenderMode id) {
|
|
|
|
const RenderModeDescription *l = g_renderModes;
|
|
|
|
for (; l->code; ++l) {
|
|
|
|
if (l->id == id)
|
|
|
|
return l->description;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-06-06 17:56:41 +00:00
|
|
|
const struct GameOpt {
|
|
|
|
uint32 option;
|
|
|
|
const char *desc;
|
|
|
|
} g_gameOptions[] = {
|
2010-06-15 10:56:12 +00:00
|
|
|
{ GUIO_NOSUBTITLES, "sndNoSubs" },
|
|
|
|
{ GUIO_NOMUSIC, "sndNoMusic" },
|
|
|
|
{ GUIO_NOSPEECH, "sndNoSpeech" },
|
|
|
|
{ GUIO_NOSFX, "sndNoSFX" },
|
|
|
|
{ GUIO_NOMIDI, "sndNoMIDI" },
|
2009-06-06 17:56:41 +00:00
|
|
|
{ GUIO_NOLAUNCHLOAD, "launchNoLoad" },
|
2010-06-15 10:56:12 +00:00
|
|
|
|
|
|
|
{ GUIO_MIDIPCSPK, "midiPCSpk" },
|
|
|
|
{ GUIO_MIDICMS, "midiCMS" },
|
|
|
|
{ GUIO_MIDIPCJR, "midiPCJr" },
|
|
|
|
{ GUIO_MIDIADLIB, "midiAdLib" },
|
|
|
|
{ GUIO_MIDITOWNS, "midiTowns" },
|
|
|
|
{ GUIO_MIDI, "midiMidi" },
|
|
|
|
|
2009-06-06 17:56:41 +00:00
|
|
|
{ GUIO_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
bool checkGameGUIOption(GameGUIOption option, const String &str) {
|
|
|
|
for (int i = 0; g_gameOptions[i].desc; i++) {
|
|
|
|
if (g_gameOptions[i].option & option) {
|
|
|
|
if (str.contains(g_gameOptions[i].desc))
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32 parseGameGUIOptions(const String &str) {
|
|
|
|
uint32 res = 0;
|
|
|
|
|
|
|
|
for (int i = 0; g_gameOptions[i].desc; i++)
|
|
|
|
if (str.contains(g_gameOptions[i].desc))
|
|
|
|
res |= g_gameOptions[i].option;
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
String getGameGUIOptionsDescription(uint32 options) {
|
|
|
|
String res = "";
|
|
|
|
|
|
|
|
for (int i = 0; g_gameOptions[i].desc; i++)
|
|
|
|
if (options & g_gameOptions[i].option)
|
|
|
|
res += String(g_gameOptions[i].desc) + " ";
|
|
|
|
|
|
|
|
res.trim();
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
2007-02-04 13:28:17 +00:00
|
|
|
|
2009-07-13 18:47:32 +00:00
|
|
|
void updateGameGUIOptions(const uint32 options) {
|
|
|
|
if ((options && !ConfMan.hasKey("guioptions")) ||
|
|
|
|
(ConfMan.hasKey("guioptions") && options != parseGameGUIOptions(ConfMan.get("guioptions")))) {
|
|
|
|
ConfMan.set("guioptions", getGameGUIOptionsDescription(options));
|
|
|
|
ConfMan.flushToDisk();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-04 11:50:21 +00:00
|
|
|
} // End of namespace Common
|