2002-07-12 16:24:11 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
2005-01-01 16:09:25 +00:00
|
|
|
* Copyright (C) 2002-2005 The ScummVM project
|
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
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* $Header$
|
|
|
|
*/
|
|
|
|
|
2005-06-24 15:23:51 +00:00
|
|
|
#include "common/stdafx.h"
|
2003-09-18 02:07:18 +00:00
|
|
|
#include "base/engine.h"
|
2003-08-01 12:21:04 +00:00
|
|
|
#include "common/util.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
|
|
|
//
|
2003-10-04 11:50:21 +00:00
|
|
|
void hexdump(const byte * data, int len, int bytesPerLine) {
|
|
|
|
assert(1 <= bytesPerLine && bytesPerLine <= 32);
|
2002-07-25 16:29:07 +00:00
|
|
|
int i;
|
|
|
|
byte c;
|
2003-05-04 13:46:06 +00:00
|
|
|
int offset = 0;
|
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
|
|
|
|
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.
|
2005-06-21 22:08:21 +00:00
|
|
|
#if defined (__SYMBIAN32__) && defined (__WINS__)
|
|
|
|
uint32 seed = 0; // Symbian produces RT crash on time(0)
|
|
|
|
#else
|
|
|
|
uint32 seed = time(0);
|
|
|
|
#endif
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
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[] = {
|
|
|
|
{"en", "English (US)", EN_USA},
|
2003-10-17 15:35:46 +00:00
|
|
|
{"de", "German", DE_DEU},
|
|
|
|
{"fr", "French", FR_FRA},
|
|
|
|
{"it", "Italian", IT_ITA},
|
|
|
|
{"pt", "Portuguese", PT_BRA},
|
|
|
|
{"es", "Spanish", ES_ESP},
|
|
|
|
{"jp", "Japanese", JA_JPN},
|
|
|
|
{"zh", "Chinese (Taiwan)", ZH_TWN},
|
|
|
|
{"kr", "Korean", KO_KOR},
|
2003-11-05 00:58:02 +00:00
|
|
|
{"gb", "English (GB)", EN_GRB},
|
2003-10-17 15:35:46 +00:00
|
|
|
{"se", "Swedish", SE_SWE},
|
2004-02-10 13:24:12 +00:00
|
|
|
{"hb", "Hebrew", HB_ISR},
|
2003-11-08 22:43:46 +00:00
|
|
|
{"ru", "Russian", RU_RUS},
|
2004-01-06 12:28:24 +00:00
|
|
|
{"cz", "Czech", CZ_CZE},
|
2004-02-10 12:37:40 +00:00
|
|
|
{"nl", "Dutch", NL_NLD},
|
2005-09-03 19:59:33 +00:00
|
|
|
{"nb", "Norwegian Bokm\xE5l", NB_NOR},
|
2003-10-17 15:35:46 +00:00
|
|
|
{0, 0, UNK_LANG}
|
|
|
|
};
|
|
|
|
|
|
|
|
Language parseLanguage(const String &str) {
|
|
|
|
if (str.isEmpty())
|
|
|
|
return UNK_LANG;
|
|
|
|
|
|
|
|
const char *s = str.c_str();
|
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) {
|
|
|
|
if (!scumm_stricmp(l->code, s))
|
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[] = {
|
2004-02-07 16:01:00 +00:00
|
|
|
{"amiga", "ami", "Amiga", kPlatformAmiga},
|
|
|
|
{"atari", "atari-st", "Atari ST", kPlatformAtariST},
|
2005-05-17 23:56:21 +00:00
|
|
|
{"c64", "c64", "Commodore 64", kPlatformC64},
|
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.
|
|
|
|
{"fmtowns", "towns", "FM-TOWNS", kPlatformFMTowns},
|
|
|
|
|
2005-10-14 02:50:05 +00:00
|
|
|
{"linux", "linux", "Linux", kPlatformLinux},
|
2004-02-07 17:10:48 +00:00
|
|
|
{"macintosh", "mac", "Macintosh", kPlatformMacintosh},
|
2005-04-08 20:49:13 +00:00
|
|
|
{"nes", "nes", "NES", kPlatformNES},
|
2004-08-20 15:25:12 +00:00
|
|
|
{"pc", "dos", "DOS", kPlatformPC},
|
2005-04-09 13:13:04 +00:00
|
|
|
{"windows", "win", "Windows", kPlatformWindows},
|
2004-02-07 17:10:48 +00:00
|
|
|
|
2004-02-07 16:01:00 +00:00
|
|
|
{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) {
|
|
|
|
if (str.isEmpty())
|
|
|
|
return kPlatformUnknown;
|
|
|
|
|
|
|
|
const char *s = str.c_str();
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-12-30 19:07:55 +00:00
|
|
|
// Handle some special case separately, for compatibility with old config
|
|
|
|
// files.
|
2004-02-07 16:01:00 +00:00
|
|
|
if (!strcmp(s, "1"))
|
2003-10-17 15:35:46 +00:00
|
|
|
return kPlatformAmiga;
|
2004-02-07 16:01:00 +00:00
|
|
|
else if (!strcmp(s, "2"))
|
2003-10-17 15:35:46 +00:00
|
|
|
return kPlatformAtariST;
|
2004-02-07 16:01:00 +00:00
|
|
|
else if (!strcmp(s, "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) {
|
2004-02-07 16:01:00 +00:00
|
|
|
if (!scumm_stricmp(l->code, s) || !scumm_stricmp(l->code2, s))
|
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
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
if (str.isEmpty())
|
|
|
|
return kRenderDefault;
|
|
|
|
|
|
|
|
const char *s = str.c_str();
|
|
|
|
const RenderModeDescription *l = g_renderModes;
|
|
|
|
for (; l->code; ++l) {
|
|
|
|
if (!scumm_stricmp(l->code, s))
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2003-11-05 00:58:02 +00:00
|
|
|
|
2003-10-04 11:50:21 +00:00
|
|
|
} // End of namespace Common
|