diff options
author | Filippos Karapetis | 2018-12-27 13:20:53 +0200 |
---|---|---|
committer | Filippos Karapetis | 2018-12-27 13:20:53 +0200 |
commit | b37a41286099faf4a36e73e69b377022345091e7 (patch) | |
tree | 7a6ddbf81c6e5a719854451698603ce726b7e87e | |
parent | 0ade566d649fd9b1803276944d2cae77130aeca7 (diff) | |
download | scummvm-rg350-b37a41286099faf4a36e73e69b377022345091e7.tar.gz scummvm-rg350-b37a41286099faf4a36e73e69b377022345091e7.tar.bz2 scummvm-rg350-b37a41286099faf4a36e73e69b377022345091e7.zip |
GLK: ALAN2: Initial skeleton sub-engine
-rw-r--r-- | engines/glk/alan2/alan2.cpp | 74 | ||||
-rw-r--r-- | engines/glk/alan2/alan2.h | 75 | ||||
-rw-r--r-- | engines/glk/alan2/detection.cpp | 118 | ||||
-rw-r--r-- | engines/glk/alan2/detection.h | 77 | ||||
-rw-r--r-- | engines/glk/alan2/detection_tables.h | 57 | ||||
-rw-r--r-- | engines/glk/detection.cpp | 12 | ||||
-rw-r--r-- | engines/glk/module.mk | 2 |
7 files changed, 414 insertions, 1 deletions
diff --git a/engines/glk/alan2/alan2.cpp b/engines/glk/alan2/alan2.cpp new file mode 100644 index 0000000000..3869e34c90 --- /dev/null +++ b/engines/glk/alan2/alan2.cpp @@ -0,0 +1,74 @@ +/* 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. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "glk/alan2/alan2.h" +#include "common/config-manager.h" +#include "common/translation.h" +#include "common/error.h" +#include "common/scummsys.h" +#include "common/system.h" +#include "glk/glk.h" +#include "glk/streams.h" + +namespace Glk { +namespace Alan2 { + + +Alan2::Alan2(OSystem *syst, const GlkGameDescription &gameDesc) : GlkAPI(syst, gameDesc), + vm_exited_cleanly(false) { +} + +void Alan2::runGame(Common::SeekableReadStream *gameFile) { + _gameFile = gameFile; + + if (!is_gamefile_valid()) + return; + + // TODO +} + +Common::Error Alan2::loadGameData(strid_t file) { + // TODO + return Common::kNoError; +} + +Common::Error Alan2::saveGameData(strid_t file, const Common::String &desc) { + // TODO + return Common::kNoError; +} + +bool Alan2::is_gamefile_valid() { + if (_gameFile->size() < 8) { + GUIErrorMessage(_("This is too short to be a valid Alan2 file.")); + return false; + } + + if (_gameFile->readUint32BE() != MKTAG(2, 8, 1, 0)) { + GUIErrorMessage(_("This is not a valid Alan2 file.")); + return false; + } + + return true; +} + +} // End of namespace Alan2 +} // End of namespace Glk diff --git a/engines/glk/alan2/alan2.h b/engines/glk/alan2/alan2.h new file mode 100644 index 0000000000..f4515516f7 --- /dev/null +++ b/engines/glk/alan2/alan2.h @@ -0,0 +1,75 @@ +/* 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. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef GLK_ALAN2 +#define GLK_ALAN2 + +#include "common/scummsys.h" +#include "common/stack.h" +#include "glk/glk_api.h" + +namespace Glk { +namespace Alan2 { + +/** + * Alan2 game interpreter + */ +class Alan2 : public GlkAPI { +public: + Common::SeekableReadStream *_gameFile; + bool vm_exited_cleanly; +private: + /** + * Validates the game file, and if it's invalid, displays an error dialog + */ + bool is_gamefile_valid(); +public: + /** + * Constructor + */ + Alan2(OSystem *syst, const GlkGameDescription &gameDesc); + + /** + * Run the game + */ + void runGame(Common::SeekableReadStream *gameFile); + + /** + * Returns the running interpreter type + */ + virtual InterpreterType getInterpreterType() const override { return INTERPRETER_ALAN2; } + + /** + * Load a savegame from the passed stream + */ + virtual Common::Error loadGameData(strid_t file) override; + + /** + * Save the game to the passed stream + */ + virtual Common::Error saveGameData(strid_t file, const Common::String &desc) override; +}; + +} // End of namespace Alan2 +} // End of namespace Glk + +#endif diff --git a/engines/glk/alan2/detection.cpp b/engines/glk/alan2/detection.cpp new file mode 100644 index 0000000000..f4be3f1c16 --- /dev/null +++ b/engines/glk/alan2/detection.cpp @@ -0,0 +1,118 @@ +/* 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. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "glk/alan2/detection.h" +#include "glk/alan2/detection_tables.h" +#include "common/debug.h" +#include "common/file.h" +#include "common/md5.h" +#include "engines/game.h" + +namespace Glk { +namespace Alan2 { + +void Alan2MetaEngine::getSupportedGames(PlainGameList &games) { + for (const Alan2Descriptor *pd = ALAN2_GAME_LIST; pd->gameId; ++pd) { + games.push_back(*pd); + } +} + +Alan2Descriptor Alan2MetaEngine::findGame(const char *gameId) { + for (const Alan2Descriptor *pd = ALAN2_GAME_LIST; pd->gameId; ++pd) { + if (!strcmp(gameId, pd->gameId)) + return *pd; + } + + return Alan2Descriptor(); +} + +bool Alan2MetaEngine::detectGames(const Common::FSList &fslist, DetectedGames &gameList) { + const char *const EXTENSIONS[3] = { ".acd", ".dat" }; + + // Loop through the files of the folder + for (Common::FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) { + // Check for a recognised filename + if (file->isDirectory()) + continue; + Common::String filename = file->getName(); + bool hasExt = false; + for (int idx = 0; idx < 3 && !hasExt; ++idx) + hasExt = filename.hasSuffixIgnoreCase(EXTENSIONS[idx]); + if (!hasExt) + continue; + + // Open up the file and calculate the md5 + Common::File gameFile; + if (!gameFile.open(*file)) + continue; + Common::String md5 = Common::computeStreamMD5AsString(gameFile, 5000); + size_t filesize = gameFile.size(); + gameFile.close(); + + // Check for known games + const Alan2GameDescription *p = ALAN2_GAMES; + while (p->_gameId && (md5 != p->_md5 || filesize != p->_filesize)) + ++p; + + DetectedGame gd; + if (!p->_gameId) { + if (filename.hasSuffixIgnoreCase(".dat")) + continue; + + if (gDebugLevel > 0) { + // Print an entry suitable for putting into the detection_tables.h, using the + // name of the parent folder the game is in as the presumed game Id + Common::String folderName = file->getParent().getName(); + if (folderName.hasSuffix("\\")) + folderName.deleteLastChar(); + Common::String fname = filename; + const char *dot = strchr(fname.c_str(), '.'); + if (dot) + fname = Common::String(fname.c_str(), dot); + + debug("ENTRY0(\"%s\", \"%s\", %u),", fname.c_str(), md5.c_str(), (uint)filesize); + } + const PlainGameDescriptor &desc = ALAN2_GAME_LIST[0]; + gd = DetectedGame(desc.gameId, desc.description, Common::UNK_LANG, Common::kPlatformUnknown); + } else { + PlainGameDescriptor gameDesc = findGame(p->_gameId); + gd = DetectedGame(p->_gameId, gameDesc.description, p->_language, Common::kPlatformUnknown, p->_extra); + gd.setGUIOptions(GUIO4(GUIO_NOSPEECH, GUIO_NOSFX, GUIO_NOMUSIC, GUIO_NOSUBTITLES)); + } + + gd.addExtraEntry("filename", filename); + gameList.push_back(gd); + } + + return !gameList.empty(); +} + +void Alan2MetaEngine::detectClashes(Common::StringMap &map) { + for (const Alan2Descriptor *pd = ALAN2_GAME_LIST; pd->gameId; ++pd) { + if (map.contains(pd->gameId)) + error("Duplicate game Id found - %s", pd->gameId); + map[pd->gameId] = ""; + } +} + +} // End of namespace Alan2 +} // End of namespace Glk diff --git a/engines/glk/alan2/detection.h b/engines/glk/alan2/detection.h new file mode 100644 index 0000000000..b3fa3bd473 --- /dev/null +++ b/engines/glk/alan2/detection.h @@ -0,0 +1,77 @@ +/* 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. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef GLK_ALAN2_DETECTION +#define GLK_ALAN2_DETECTION + +#include "common/fs.h" +#include "common/hash-str.h" +#include "engines/game.h" + +namespace Glk { +namespace Alan2 { + +/** + * Alan2 game descriptior + */ +struct Alan2Descriptor { + const char *gameId; + const char *description; + + operator PlainGameDescriptor() const { + PlainGameDescriptor pd; + pd.gameId = gameId; + pd.description = description; + return pd; + } +}; + +/** + * Meta engine for Alan2 interpreter + */ +class Alan2MetaEngine { +public: + /** + * Get a list of supported games + */ + static void getSupportedGames(PlainGameList &games); + + /** + * Returns a game description for the given game Id, if it's supported + */ + static Alan2Descriptor findGame(const char *gameId); + + /** + * Detect supported games + */ + static bool detectGames(const Common::FSList &fslist, DetectedGames &gameList); + + /** + * Check for game Id clashes with other sub-engines + */ + static void detectClashes(Common::StringMap &map); +}; + +} // End of namespace Alan2 +} // End of namespace Glk + +#endif diff --git a/engines/glk/alan2/detection_tables.h b/engines/glk/alan2/detection_tables.h new file mode 100644 index 0000000000..2a09a02ed0 --- /dev/null +++ b/engines/glk/alan2/detection_tables.h @@ -0,0 +1,57 @@ +/* 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. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "engines/game.h" +#include "common/gui_options.h" +#include "common/language.h" + +namespace Glk { +namespace Alan2 { + +/** + * Game description + */ +struct Alan2GameDescription { + const char *const _gameId; + const char *const _extra; + const char *const _md5; + size_t _filesize; + Common::Language _language; +}; + +const Alan2Descriptor ALAN2_GAME_LIST[] = { + { "alan2", "Alan2 Game" }, + //{ "cragne", "Cragne Manor" }, + + { nullptr, nullptr } +}; + +#define ENTRY0(ID, MD5, FILESIZE) { ID, nullptr, MD5, FILESIZE, Common::EN_ANY } +#define TABLE_END_MARKER { nullptr, nullptr, nullptr, 0, Common::EN_ANY } + +const Alan2GameDescription ALAN2_GAMES[] = { + //ENTRY0("cragne", "082f518c0120d2323ce340bef8a2d5a9", 8869096), + TABLE_END_MARKER +}; + +} // End of namespace Alan2 +} // End of namespace Glk diff --git a/engines/glk/detection.cpp b/engines/glk/detection.cpp index 1e1eb10a8f..7a49989c89 100644 --- a/engines/glk/detection.cpp +++ b/engines/glk/detection.cpp @@ -21,6 +21,8 @@ */ #include "glk/glk.h" +#include "glk/alan2/detection.h" +#include "glk/alan2/alan2.h" #include "glk/frotz/detection.h" #include "glk/frotz/frotz.h" #include "glk/glulxe/detection.h" @@ -140,7 +142,9 @@ Common::Error GlkMetaEngine::createInstance(OSystem *syst, Engine **engine) cons f.close(); // Create the correct engine - if (Glk::Frotz::FrotzMetaEngine::findGame(gameDesc._gameId.c_str()).description) { + if (Glk::Alan2::Alan2MetaEngine::findGame(gameDesc._gameId.c_str()).description) { + *engine = new Glk::Alan2::Alan2(syst, gameDesc); + } else if (Glk::Frotz::FrotzMetaEngine::findGame(gameDesc._gameId.c_str()).description) { *engine = new Glk::Frotz::Frotz(syst, gameDesc); } else if (Glk::Glulxe::GlulxeMetaEngine::findGame(gameDesc._gameId.c_str()).description) { *engine = new Glk::Glulxe::Glulxe(syst, gameDesc); @@ -182,6 +186,7 @@ Common::String GlkMetaEngine::findFileByGameId(const Common::String &gameId) con PlainGameList GlkMetaEngine::getSupportedGames() const { PlainGameList list; + Glk::Alan2::Alan2MetaEngine::getSupportedGames(list); Glk::Frotz::FrotzMetaEngine::getSupportedGames(list); Glk::Glulxe::GlulxeMetaEngine::getSupportedGames(list); Glk::Scott::ScottMetaEngine::getSupportedGames(list); @@ -193,6 +198,9 @@ PlainGameList GlkMetaEngine::getSupportedGames() const { PlainGameDescriptor GlkMetaEngine::findGame(const char *gameId) const { PlainGameDescriptor gd; + gd = Glk::Alan2::Alan2MetaEngine::findGame(gameId); + if (gd.description) return gd; + gd = Glk::Frotz::FrotzMetaEngine::findGame(gameId); if (gd.description) return gd; @@ -213,6 +221,7 @@ DetectedGames GlkMetaEngine::detectGames(const Common::FSList &fslist) const { detectClashes(); DetectedGames detectedGames; + Glk::Alan2::Alan2MetaEngine::detectGames(fslist, detectedGames); Glk::Frotz::FrotzMetaEngine::detectGames(fslist, detectedGames); Glk::Glulxe::GlulxeMetaEngine::detectGames(fslist, detectedGames); Glk::Scott::ScottMetaEngine::detectGames(fslist, detectedGames); @@ -223,6 +232,7 @@ DetectedGames GlkMetaEngine::detectGames(const Common::FSList &fslist) const { void GlkMetaEngine::detectClashes() const { Common::StringMap map; + Glk::Alan2::Alan2MetaEngine::detectClashes(map); Glk::Frotz::FrotzMetaEngine::detectClashes(map); Glk::Glulxe::GlulxeMetaEngine::detectClashes(map); Glk::Scott::ScottMetaEngine::detectClashes(map); diff --git a/engines/glk/module.mk b/engines/glk/module.mk index 1af4ce6201..13d630544d 100644 --- a/engines/glk/module.mk +++ b/engines/glk/module.mk @@ -22,6 +22,8 @@ MODULE_OBJS := \ window_pair.o \ window_text_buffer.o \ window_text_grid.o \ + alan2/alan2.o \ + alan2/detection.o \ frotz/config.o \ frotz/detection.o \ frotz/frotz.o \ |