diff options
-rw-r--r-- | base/gameDetector.cpp | 58 | ||||
-rw-r--r-- | base/gameDetector.h | 23 | ||||
-rw-r--r-- | common/util.cpp | 69 | ||||
-rw-r--r-- | common/util.h | 52 | ||||
-rw-r--r-- | scumm/charset.cpp | 9 | ||||
-rw-r--r-- | scumm/scummvm.cpp | 20 | ||||
-rw-r--r-- | simon/simon.cpp | 2 | ||||
-rw-r--r-- | sky/sky.cpp | 43 | ||||
-rw-r--r-- | sky/sky.h | 1 |
9 files changed, 163 insertions, 114 deletions
diff --git a/base/gameDetector.cpp b/base/gameDetector.cpp index d3a2ecc5a9..38e71aaa4f 100644 --- a/base/gameDetector.cpp +++ b/base/gameDetector.cpp @@ -151,28 +151,6 @@ static const struct GraphicsMode gfx_modes[] = { {0, 0, 0} }; -struct LanguageDescription { - const char *name; - const char *description; - 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} -}; - GameDetector::GameDetector() { // Graphics @@ -365,7 +343,7 @@ void GameDetector::parseCommandLine(int argc, char **argv) { break; case 'q': HANDLE_OPTION(); - if (parseLanguage(option) == UNK_LANG) + if (Common::parseLanguage(option) == Common::UNK_LANG) goto ShowHelpAndExit; ConfMan.set("language", option); break; @@ -409,7 +387,7 @@ void GameDetector::parseCommandLine(int argc, char **argv) { // Long options. Let the fun begin! if (!strncmp(s, "platform=", 9)) { s += 9; - int platform = parsePlatform(s); + int platform = Common::parsePlatform(s); if (platform == kPlatformUnknown) goto ShowHelpAndExit; @@ -491,38 +469,6 @@ int GameDetector::parseGraphicsMode(const String &str) { return -1; } -Language GameDetector::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; -} - -Platform GameDetector::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; -} - int GameDetector::parseMusicDriver(const String &str) { if (str.isEmpty()) return -1; diff --git a/base/gameDetector.h b/base/gameDetector.h index 81213a3836..bcc3e45d31 100644 --- a/base/gameDetector.h +++ b/base/gameDetector.h @@ -38,27 +38,6 @@ enum { GF_DEFAULT_TO_1X_SCALER = 1 << 31 }; -/** - * 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. - */ -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 -}; - enum Platform { kPlatformUnknown = -1, kPlatformPC = 0, @@ -115,8 +94,6 @@ public: static int parseGraphicsMode(const String &s); // Used in main() static int parseMusicDriver(const String &s); - static Language parseLanguage(const String &s); - static Platform parsePlatform(const String &s); static GameSettings findGame(const String &gameName, const Plugin **plugin = NULL); 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 diff --git a/scumm/charset.cpp b/scumm/charset.cpp index 0cf0ad8f27..6461775a1a 100644 --- a/scumm/charset.cpp +++ b/scumm/charset.cpp @@ -22,7 +22,6 @@ #include "scumm/charset.h" #include "scumm/scumm.h" #include "scumm/nut_renderer.h" -#include "base/gameDetector.h" namespace Scumm { @@ -868,16 +867,16 @@ static byte spanishCharsetDataV2[] = { void CharsetRendererV2::setCurID(byte id) { switch (_vm->_language) { - case DE_DEU: + case Common::DE_DEU: _fontPtr = germanCharsetDataV2; break; - case FR_FRA: + case Common::FR_FRA: _fontPtr = frenchCharsetDataV2; break; - case IT_ITA: + case Common::IT_ITA: _fontPtr = italianCharsetDataV2; break; - case ES_ESP: + case Common::ES_ESP: _fontPtr = spanishCharsetDataV2; break; default: diff --git a/scumm/scummvm.cpp b/scumm/scummvm.cpp index 4050f144a3..682389c2c2 100644 --- a/scumm/scummvm.cpp +++ b/scumm/scummvm.cpp @@ -609,7 +609,9 @@ ScummEngine::ScummEngine(GameDetector *detector, OSystem *syst) _confirmExit = ConfMan.getBool("confirm_exit"); _defaultTalkDelay = ConfMan.getInt("talkspeed"); _native_mt32 = ConfMan.getBool("native_mt32"); - _language = GameDetector::parseLanguage(ConfMan.get("language")); + // TODO: We shouldn't rely on the global Language values matching those COMI etc. expect. + // Rather we should explicitly translate them. + _language = Common::parseLanguage(ConfMan.get("language")); memset(&res, 0, sizeof(res)); _hexdumpScripts = false; _showStack = false; @@ -707,19 +709,19 @@ ScummEngine::ScummEngine(GameDetector *detector, OSystem *syst) // Load CJK font _CJKMode = false; - if ((_gameId == GID_DIG || _gameId == GID_CMI) && (_language == KO_KOR || _language == JA_JPN || _language == ZH_TWN)) { + if ((_gameId == GID_DIG || _gameId == GID_CMI) && (_language == Common::KO_KOR || _language == Common::JA_JPN || _language == Common::ZH_TWN)) { File fp; const char *fontFile = NULL; switch(_language) { - case KO_KOR: + case Common::KO_KOR: _CJKMode = true; fontFile = "korean.fnt"; break; - case JA_JPN: + case Common::JA_JPN: _CJKMode = true; fontFile = (_gameId == GID_DIG) ? "kanji16.fnt" : "japanese.fnt"; break; - case ZH_TWN: + case Common::ZH_TWN: if (_gameId == GID_CMI) { _CJKMode = true; fontFile = "chinese.fnt"; @@ -734,13 +736,13 @@ ScummEngine::ScummEngine(GameDetector *detector, OSystem *syst) int numChar = 0; switch(_language) { - case KO_KOR: + case Common::KO_KOR: numChar = 2350; break; - case JA_JPN: + case Common::JA_JPN: numChar = (_gameId == GID_DIG) ? 1 : 1; //FIXME break; - case ZH_TWN: + case Common::ZH_TWN: numChar = 1; //FIXME break; } @@ -2640,7 +2642,7 @@ Engine *Engine_SCUMM_create(GameDetector *detector, OSystem *syst) { detector->_game.features |= GF_AMIGA; } - switch (GameDetector::parsePlatform(ConfMan.get("platform"))) { + switch (Common::parsePlatform(ConfMan.get("platform"))) { case kPlatformAmiga: detector->_game.features |= GF_AMIGA; break; diff --git a/simon/simon.cpp b/simon/simon.cpp index 4bd189628f..75c07fee7c 100644 --- a/simon/simon.cpp +++ b/simon/simon.cpp @@ -489,7 +489,7 @@ SimonEngine::SimonEngine(GameDetector *detector, OSystem *syst) _debugMode = ConfMan.hasKey("debuglevel"); _debugLevel = ConfMan.getInt("debuglevel"); - _language = GameDetector::parseLanguage(ConfMan.get("language")); + _language = Common::parseLanguage(ConfMan.get("language")); _noSubtitles = ConfMan.getBool("nosubtitles"); _system->init_size(320, 200); diff --git a/sky/sky.cpp b/sky/sky.cpp index 730553828f..8337556db5 100644 --- a/sky/sky.cpp +++ b/sky/sky.cpp @@ -137,20 +137,6 @@ void SkyEngine::initVirgin() { _skyScreen->showScreen(60110); } -uint8 SkyEngine::_languageTable[11] = { - SKY_USA, // EN_USA - SKY_GERMAN, // DE_DEU - SKY_FRENCH, // FR_FRA - SKY_ITALIAN, // IT_ITA - SKY_PORTUGUESE, // PT_BRA - SKY_SPANISH, // ES_ESP - SKY_USA, // JA_JPN - SKY_USA, // ZH_TWN - SKY_USA, // KO_KOR - SKY_SWEDISH, // SE_SWE - SKY_ENGLISH // EN_GRB -}; - void SkyEngine::doCheat(uint8 num) { switch(num) { @@ -297,11 +283,32 @@ void SkyEngine::initialise(void) { if (_systemVars.gameVersion == 288) SkyCompact::patchFor288(); - int language = GameDetector::parseLanguage(ConfMan.get("language")); - if (language < 0 || language > 10) + switch (Common::parseLanguage(ConfMan.get("language"))) { + case Common::DE_DEU: + _systemVars.language = SKY_GERMAN; + break; + case Common::FR_FRA: + _systemVars.language = SKY_FRENCH; + break; + case Common::IT_ITA: + _systemVars.language = SKY_ITALIAN; + break; + case Common::PT_BRA: + _systemVars.language = SKY_PORTUGUESE; + break; + case Common::ES_ESP: + _systemVars.language = SKY_SPANISH; + break; + case Common::SE_SWE: + _systemVars.language = SKY_SWEDISH; + break; + case Common::EN_GRB: + _systemVars.language = SKY_ENGLISH; + break; + default: _systemVars.language = SKY_USA; - else - _systemVars.language = _languageTable[language]; + break; + } if (!_skyDisk->fileExists(60600 + SkyEngine::_systemVars.language * 8)) { warning("The language you selected does not exist in your BASS version."); @@ -53,7 +53,6 @@ class SkyEngine : public Engine { protected: byte _game; byte _key_pressed; - static uint8 _languageTable[11]; bool _quickLaunch; // set when starting with -x bool _floppyIntro; |