aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/util.cpp69
-rw-r--r--common/util.h52
2 files changed, 120 insertions, 1 deletions
diff --git a/common/util.cpp b/common/util.cpp
index cdb9bf9c60..05deda925b 100644
--- a/common/util.cpp
+++ b/common/util.cpp
@@ -75,6 +75,9 @@ void hexdump(const byte * data, int len, int bytesPerLine) {
printf("|\n");
}
+#pragma mark -
+
+
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.
@@ -96,6 +99,9 @@ uint RandomSource::getRandomNumberRng(uint min, uint max) {
return getRandomNumber(max - min) + min;
}
+#pragma mark -
+
+
StackLock::StackLock(OSystem::MutexRef mutex, OSystem *syst)
: _mutex(mutex), _syst(syst) {
if (syst == 0)
@@ -117,4 +123,67 @@ void StackLock::unlock() {
_syst->unlock_mutex(_mutex);
}
+
+#pragma mark -
+
+
+struct LanguageDescription {
+ const char *name;
+ const char *description;
+ Common::Language id;
+};
+
+static const struct LanguageDescription languages[] = {
+ {"en", "English", EN_USA},
+ {"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},
+ {"gb", "English", EN_GRB},
+ {"se", "Swedish", SE_SWE},
+ {"hb", "Hebrew", HB_HEB},
+ {0, 0, UNK_LANG}
+};
+
+Language parseLanguage(const String &str) {
+ if (str.isEmpty())
+ return UNK_LANG;
+
+ const char *s = str.c_str();
+ const LanguageDescription *l = languages;
+ while (l->name) {
+ if (!scumm_stricmp(l->name, s))
+ return l->id;
+ l++;
+ }
+
+ return UNK_LANG;
+}
+
+
+#pragma mark -
+
+
+Platform parsePlatform(const String &str) {
+ if (str.isEmpty())
+ return kPlatformUnknown;
+
+ const char *s = str.c_str();
+ if (!scumm_stricmp(s, "pc"))
+ return kPlatformPC;
+ else if (!scumm_stricmp(s, "amiga") || !scumm_stricmp(s, "1"))
+ return kPlatformAmiga;
+ else if (!scumm_stricmp(s, "atari-st") || !scumm_stricmp(s, "atari") || !scumm_stricmp(s, "2"))
+ return kPlatformAtariST;
+ else if (!scumm_stricmp(s, "macintosh") || !scumm_stricmp(s, "mac") || !scumm_stricmp(s, "3"))
+ return kPlatformMacintosh;
+ else
+ return kPlatformUnknown;
+}
+
+
} // End of namespace Common
diff --git a/common/util.h b/common/util.h
index 760ad25a08..d647b88f7b 100644
--- a/common/util.h
+++ b/common/util.h
@@ -37,6 +37,8 @@ template<typename T> inline void SWAP(T &a, T &b) { T tmp = a; a = b; b = tmp; }
namespace Common {
+class String;
+
/**
* Print a hexdump of the data passed in. The number of bytes per line is
* customizable.
@@ -44,7 +46,7 @@ namespace Common {
* @param len the lenght of that data
* @param bytes_per_line number of bytes to print per line (default: 16)
*/
-void hexdump(const byte * data, int len, int bytesPerLine = 16);
+extern void hexdump(const byte * data, int len, int bytesPerLine = 16);
/**
* Simple random number generator. Although it is definitely not suitable for
@@ -86,6 +88,54 @@ public:
~StackLock();
};
+/**
+ * List of language ids.
+ * @note The order and mappings of the values 0..8 are *required* to stay the
+ * way they are now, as scripts in COMI rely on them. So don't touch them.
+ * I am working on removing this restriction.
+ */
+enum Language {
+ UNK_LANG = -1, // Use default language (i.e. none specified)
+ EN_USA = 0,
+ DE_DEU = 1,
+ FR_FRA = 2,
+ IT_ITA = 3,
+ PT_BRA = 4,
+ ES_ESP = 5,
+ JA_JPN = 6,
+ ZH_TWN = 7,
+ KO_KOR = 8,
+ SE_SWE = 9,
+ EN_GRB = 10,
+ HB_HEB = 20
+};
+
+/** Convert a string containing a language name into a Language enum value. */
+extern Language parseLanguage(const String &str);
+
+/**
+ * List of game platforms. Specifying a platform for a target can be used to
+ * give the game engines a hint for which platform the game data file are.
+ * This may be optional or required, depending on the game engine and the
+ * game in question.
+ */
+enum Platform {
+ kPlatformUnknown = -1,
+ kPlatformPC = 0,
+ kPlatformAmiga = 1,
+ kPlatformAtariST = 2,
+ kPlatformMacintosh = 3
+/*
+ kPlatformNES,
+ kPlatformSEGA,
+ kPlatformFMTowns,
+ kPlatformPCEngine
+*/
+};
+
+/** Convert a string containing a platform name into a Platform enum value. */
+extern Platform parsePlatform(const String &str);
+
} // End of namespace Common