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"
|
|
|
|
#include "gui/debugger.h"
|
2009-01-30 01:17:12 +00:00
|
|
|
#include "engines/engine.h"
|
2002-07-12 16:24:11 +00:00
|
|
|
|
2009-01-23 03:30:40 +00:00
|
|
|
#include <stdarg.h> // For va_list etc.
|
|
|
|
|
2006-10-08 18:15:18 +00:00
|
|
|
#ifdef _WIN32_WCE
|
|
|
|
// This is required for the debugger attachment
|
|
|
|
extern bool isSmartphone(void);
|
|
|
|
#endif
|
|
|
|
|
2007-03-08 17:36:52 +00:00
|
|
|
#ifdef __PLAYSTATION2__
|
|
|
|
// for those replaced fopen/fread/etc functions
|
|
|
|
typedef unsigned long uint64;
|
|
|
|
typedef signed long int64;
|
|
|
|
#include "backends/platform/ps2/fileio.h"
|
|
|
|
|
|
|
|
#define fprintf ps2_fprintf
|
2009-01-30 01:17:12 +00:00
|
|
|
#define fputs(str, file) ps2_fputs(str, file)
|
2007-03-08 17:36:52 +00:00
|
|
|
#define fflush(a) ps2_fflush(a)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __DS__
|
2008-01-18 17:24:34 +00:00
|
|
|
#include "backends/fs/ds/ds-fs.h"
|
2007-10-13 15:44:56 +00:00
|
|
|
|
2008-01-28 00:14:17 +00:00
|
|
|
void std_fprintf(FILE* handle, const char* fmt, ...);
|
|
|
|
void std_fflush(FILE* handle);
|
2007-03-08 17:36:52 +00:00
|
|
|
|
2009-01-30 01:17:12 +00:00
|
|
|
#define fprintf(file, fmt, ...) do { char str[128]; sprintf(str, fmt, ##__VA_ARGS__); DS::std_fwrite(str, strlen(str), 1, file); } while(0)
|
|
|
|
#define fputs(str, file) DS::std_fwrite(str, strlen(str), 1, file)
|
2007-03-08 17:36:52 +00:00
|
|
|
#define fflush(file) DS::std_fflush(file)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2003-10-04 11:50:21 +00:00
|
|
|
namespace Common {
|
2002-07-12 16:24:11 +00:00
|
|
|
|
2008-02-08 04:11:20 +00:00
|
|
|
StringTokenizer::StringTokenizer(const String &str, const String &delimiters) : _str(str), _delimiters(delimiters) {
|
|
|
|
reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void StringTokenizer::reset() {
|
|
|
|
_tokenBegin = _tokenEnd = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool StringTokenizer::empty() const {
|
|
|
|
// Search for the next token's start (i.e. the next non-delimiter character)
|
|
|
|
for (uint i = _tokenEnd; i < _str.size(); i++) {
|
|
|
|
if (!_delimiters.contains(_str[i]))
|
|
|
|
return false; // Found a token so the tokenizer is not empty
|
|
|
|
}
|
|
|
|
// Didn't find any more tokens so the tokenizer is empty
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
String StringTokenizer::nextToken() {
|
|
|
|
// Seek to next token's start (i.e. jump over the delimiters before next token)
|
2009-01-29 05:26:12 +00:00
|
|
|
for (_tokenBegin = _tokenEnd; _tokenBegin < _str.size() && _delimiters.contains(_str[_tokenBegin]); _tokenBegin++)
|
|
|
|
;
|
2008-02-08 04:11:20 +00:00
|
|
|
// Seek to the token's end (i.e. jump over the non-delimiters)
|
2009-01-29 05:26:12 +00:00
|
|
|
for (_tokenEnd = _tokenBegin; _tokenEnd < _str.size() && !_delimiters.contains(_str[_tokenEnd]); _tokenEnd++)
|
|
|
|
;
|
2008-02-08 04:11:20 +00:00
|
|
|
// Return the found token
|
|
|
|
return String(_str.c_str() + _tokenBegin, _tokenEnd - _tokenBegin);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
String tag2string(uint32 tag) {
|
|
|
|
char str[5];
|
|
|
|
str[0] = (char)(tag >> 24);
|
|
|
|
str[1] = (char)(tag >> 16);
|
|
|
|
str[2] = (char)(tag >> 8);
|
|
|
|
str[3] = (char)tag;
|
|
|
|
str[4] = '\0';
|
|
|
|
// Replace non-printable chars by dot
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
if (!isprint(str[i]))
|
|
|
|
str[i] = '.';
|
|
|
|
}
|
|
|
|
return Common::String(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-17 15:35:46 +00:00
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
|
2003-10-14 10:24:27 +00:00
|
|
|
RandomSource::RandomSource() {
|
|
|
|
// Use system time as RNG seed. Normally not a good idea, if you are using
|
|
|
|
// a RNG for security purposes, but good enough for our purposes.
|
2007-12-06 21:11:26 +00:00
|
|
|
assert(g_system);
|
|
|
|
uint32 seed = g_system->getMillis();
|
2005-06-21 22:08:21 +00:00
|
|
|
setSeed(seed);
|
2002-12-01 14:57:50 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 16:27:06 +00:00
|
|
|
void RandomSource::setSeed(uint32 seed) {
|
2002-12-01 14:57:50 +00:00
|
|
|
_randSeed = seed;
|
|
|
|
}
|
|
|
|
|
2003-03-06 16:27:06 +00:00
|
|
|
uint RandomSource::getRandomNumber(uint max) {
|
2002-12-01 14:57:50 +00:00
|
|
|
_randSeed = 0xDEADBF03 * (_randSeed + 1);
|
|
|
|
_randSeed = (_randSeed >> 13) | (_randSeed << 19);
|
|
|
|
return _randSeed % (max + 1);
|
|
|
|
}
|
|
|
|
|
2008-02-17 16:12:54 +00:00
|
|
|
uint RandomSource::getRandomBit(void) {
|
|
|
|
_randSeed = 0xDEADBF03 * (_randSeed + 1);
|
|
|
|
_randSeed = (_randSeed >> 13) | (_randSeed << 19);
|
|
|
|
return _randSeed & 1;
|
|
|
|
}
|
|
|
|
|
2003-03-06 16:27:06 +00:00
|
|
|
uint RandomSource::getRandomNumberRng(uint min, uint max) {
|
2002-12-01 14:57:50 +00:00
|
|
|
return getRandomNumber(max - min) + min;
|
|
|
|
}
|
|
|
|
|
2003-10-17 15:35:46 +00:00
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
|
2003-11-05 00:58:02 +00:00
|
|
|
const LanguageDescription g_languages[] = {
|
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},
|
2007-04-24 06:31:04 +00:00
|
|
|
{"hb", "Hebrew", HB_ISR},
|
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},
|
2009-06-23 17:55:09 +00:00
|
|
|
{"hu", "Hungarian", HU_HUN},
|
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[] = {
|
2007-03-03 12:59:48 +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},
|
2007-03-03 12:59:48 +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},
|
2004-02-07 17:10:48 +00:00
|
|
|
|
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[] = {
|
|
|
|
{ GUIO_NOSUBTITLES, "sndNoSubs" },
|
|
|
|
{ GUIO_NOMUSIC, "sndNoMusic" },
|
|
|
|
{ GUIO_NOSPEECH, "sndNoSpeech" },
|
|
|
|
{ GUIO_NOSFX, "sndNoSFX" },
|
|
|
|
{ GUIO_NOMIDI, "sndNoMIDI" },
|
|
|
|
{ GUIO_NOLAUNCHLOAD, "launchNoLoad" },
|
|
|
|
{ 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
|
|
|
|
2003-10-04 11:50:21 +00:00
|
|
|
} // End of namespace Common
|
2006-02-14 23:31:25 +00:00
|
|
|
|
2006-04-02 09:31:06 +00:00
|
|
|
|
|
|
|
|
2008-11-13 11:26:47 +00:00
|
|
|
#ifndef DISABLE_TEXT_CONSOLE
|
2006-04-02 09:31:06 +00:00
|
|
|
|
2008-11-13 11:26:47 +00:00
|
|
|
void warning(const char *s, ...) {
|
|
|
|
char buf[STRINGBUFLEN];
|
|
|
|
va_list va;
|
|
|
|
|
|
|
|
va_start(va, s);
|
|
|
|
vsnprintf(buf, STRINGBUFLEN, s, va);
|
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
#if !defined (__SYMBIAN32__)
|
|
|
|
fprintf(stderr, "WARNING: %s!\n", buf);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined( USE_WINDBG )
|
|
|
|
strcat(buf, "\n");
|
|
|
|
#if defined( _WIN32_WCE )
|
|
|
|
TCHAR buf_unicode[1024];
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, buf, strlen(buf) + 1, buf_unicode, sizeof(buf_unicode));
|
|
|
|
OutputDebugString(buf_unicode);
|
|
|
|
#else
|
|
|
|
OutputDebugString(buf);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void NORETURN error(const char *s, ...) {
|
2006-09-23 00:51:30 +00:00
|
|
|
char buf_input[STRINGBUFLEN];
|
|
|
|
char buf_output[STRINGBUFLEN];
|
|
|
|
va_list va;
|
|
|
|
|
|
|
|
// Generate the full error message
|
|
|
|
va_start(va, s);
|
|
|
|
vsnprintf(buf_input, STRINGBUFLEN, s, va);
|
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
|
2006-11-13 20:56:11 +00:00
|
|
|
// Next, give the active engine (if any) a chance to augment the message
|
2006-09-23 00:51:30 +00:00
|
|
|
if (g_engine) {
|
2008-11-15 03:16:41 +00:00
|
|
|
g_engine->errorString(buf_input, buf_output, STRINGBUFLEN);
|
2006-09-23 00:51:30 +00:00
|
|
|
} else {
|
2008-11-15 03:22:00 +00:00
|
|
|
strncpy(buf_output, buf_input, STRINGBUFLEN);
|
2006-09-23 00:51:30 +00:00
|
|
|
}
|
|
|
|
|
2009-01-30 01:17:12 +00:00
|
|
|
buf_output[STRINGBUFLEN-3] = '\0';
|
|
|
|
buf_output[STRINGBUFLEN-2] = '\0';
|
|
|
|
buf_output[STRINGBUFLEN-1] = '\0';
|
|
|
|
strcat(buf_output, "!\n");
|
|
|
|
|
2006-09-23 00:51:30 +00:00
|
|
|
|
|
|
|
// Print the error message to stderr
|
2009-01-30 01:17:12 +00:00
|
|
|
fputs(buf_output, stderr);
|
2006-09-23 00:51:30 +00:00
|
|
|
|
|
|
|
// Unless this error -originated- within the debugger itself, we
|
|
|
|
// now invoke the debugger, if available / supported.
|
|
|
|
if (g_engine) {
|
|
|
|
GUI::Debugger *debugger = g_engine->getDebugger();
|
|
|
|
#ifdef _WIN32_WCE
|
|
|
|
if (isSmartphone())
|
|
|
|
debugger = 0;
|
|
|
|
#endif
|
|
|
|
if (debugger && !debugger->isAttached()) {
|
|
|
|
debugger->attach(buf_output);
|
|
|
|
debugger->onFrame();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if defined( USE_WINDBG )
|
|
|
|
#if defined( _WIN32_WCE )
|
|
|
|
TCHAR buf_output_unicode[1024];
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, buf_output, strlen(buf_output) + 1, buf_output_unicode, sizeof(buf_output_unicode));
|
|
|
|
OutputDebugString(buf_output_unicode);
|
2007-04-09 18:00:22 +00:00
|
|
|
#ifndef DEBUG
|
|
|
|
drawError(buf_output);
|
2006-09-23 00:51:30 +00:00
|
|
|
#else
|
2007-04-09 18:00:22 +00:00
|
|
|
int cmon_break_into_the_debugger_if_you_please = *(int *)(buf_output + 1); // bus error
|
|
|
|
printf("%d", cmon_break_into_the_debugger_if_you_please); // don't optimize the int out
|
2006-09-23 00:51:30 +00:00
|
|
|
#endif
|
2007-04-09 18:00:22 +00:00
|
|
|
#else
|
|
|
|
OutputDebugString(buf_output);
|
2006-09-23 00:51:30 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef PALMOS_MODE
|
2007-05-01 09:37:40 +00:00
|
|
|
extern void PalmFatalError(const char *err);
|
2006-09-23 00:51:30 +00:00
|
|
|
PalmFatalError(buf_output);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __SYMBIAN32__
|
|
|
|
Symbian::FatalError(buf_output);
|
|
|
|
#endif
|
|
|
|
// Finally exit. quit() will terminate the program if g_system is present
|
|
|
|
if (g_system)
|
|
|
|
g_system->quit();
|
|
|
|
|
|
|
|
exit(1);
|
|
|
|
}
|