aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Gilbert2018-12-25 19:10:46 -0800
committerPaul Gilbert2018-12-27 00:10:38 -0800
commitf70180e78e09bc802bf1ba848fac903834e0b78e (patch)
treecbacd392f13963c8eb73cb7872badd058220d922
parent4b2dc67c8c27b20c0698dbf419540c85fe6a7a4c (diff)
downloadscummvm-rg350-f70180e78e09bc802bf1ba848fac903834e0b78e.tar.gz
scummvm-rg350-f70180e78e09bc802bf1ba848fac903834e0b78e.tar.bz2
scummvm-rg350-f70180e78e09bc802bf1ba848fac903834e0b78e.zip
GLK: MAGNETIC: Initial skeleton sub-engine
-rw-r--r--engines/glk/magnetic/detection.cpp118
-rw-r--r--engines/glk/magnetic/detection.h77
-rw-r--r--engines/glk/magnetic/detection_tables.h55
-rw-r--r--engines/glk/magnetic/magnetic.cpp79
-rw-r--r--engines/glk/magnetic/magnetic.h74
-rw-r--r--engines/glk/module.mk2
6 files changed, 405 insertions, 0 deletions
diff --git a/engines/glk/magnetic/detection.cpp b/engines/glk/magnetic/detection.cpp
new file mode 100644
index 0000000000..279f509a39
--- /dev/null
+++ b/engines/glk/magnetic/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/magnetic/detection.h"
+#include "glk/magnetic/detection_tables.h"
+#include "common/debug.h"
+#include "common/file.h"
+#include "common/md5.h"
+#include "engines/game.h"
+
+namespace Glk {
+namespace Magnetic {
+
+void MagneticMetaEngine::getSupportedGames(PlainGameList &games) {
+ for (const MagneticDescriptor *pd = MAGNETIC_GAME_LIST; pd->gameId; ++pd) {
+ games.push_back(*pd);
+ }
+}
+
+MagneticDescriptor MagneticMetaEngine::findGame(const char *gameId) {
+ for (const MagneticDescriptor *pd = MAGNETIC_GAME_LIST; pd->gameId; ++pd) {
+ if (!strcmp(gameId, pd->gameId))
+ return *pd;
+ }
+
+ return MagneticDescriptor();
+}
+
+bool MagneticMetaEngine::detectGames(const Common::FSList &fslist, DetectedGames &gameList) {
+ const char *const EXTENSIONS[3] = { ".magnetic" };
+
+ // 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 MagneticGameDescription *p = MAGNETIC_GAMES;
+ while (p->_gameId && (md5 != p->_md5 || filesize != p->_filesize))
+ ++p;
+
+ DetectedGame gd;
+ if (!p->_gameId) {
+ if (filename.hasSuffixIgnoreCase(".blb"))
+ 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 = MAGNETIC_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 MagneticMetaEngine::detectClashes(Common::StringMap &map) {
+ for (const MagneticDescriptor *pd = MAGNETIC_GAME_LIST; pd->gameId; ++pd) {
+ if (map.contains(pd->gameId))
+ error("Duplicate game Id found - %s", pd->gameId);
+ map[pd->gameId] = "";
+ }
+}
+
+} // End of namespace Magnetic
+} // End of namespace Glk
diff --git a/engines/glk/magnetic/detection.h b/engines/glk/magnetic/detection.h
new file mode 100644
index 0000000000..3ea881075e
--- /dev/null
+++ b/engines/glk/magnetic/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_GLULXE_DETECTION
+#define GLK_GLULXE_DETECTION
+
+#include "common/fs.h"
+#include "common/hash-str.h"
+#include "engines/game.h"
+
+namespace Glk {
+namespace Magnetic {
+
+/**
+ * Magnetic game descriptior
+ */
+struct MagneticDescriptor {
+ const char *gameId;
+ const char *description;
+
+ operator PlainGameDescriptor() const {
+ PlainGameDescriptor pd;
+ pd.gameId = gameId;
+ pd.description = description;
+ return pd;
+ }
+};
+
+/**
+ * Meta engine for Magnetic interpreter
+ */
+class MagneticMetaEngine {
+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 MagneticDescriptor 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 Magnetic
+} // End of namespace Glk
+
+#endif
diff --git a/engines/glk/magnetic/detection_tables.h b/engines/glk/magnetic/detection_tables.h
new file mode 100644
index 0000000000..a67d2a9a77
--- /dev/null
+++ b/engines/glk/magnetic/detection_tables.h
@@ -0,0 +1,55 @@
+/* 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 Magnetic {
+
+/**
+ * Game description
+ */
+struct MagneticGameDescription {
+ const char *const _gameId;
+ const char *const _extra;
+ const char *const _md5;
+ size_t _filesize;
+ Common::Language _language;
+};
+
+const MagneticDescriptor MAGNETIC_GAME_LIST[] = {
+ { "magnetic", "Magnetic Scrolls Game" },
+
+ { 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 MagneticGameDescription MAGNETIC_GAMES[] = {
+ TABLE_END_MARKER
+};
+
+} // End of namespace Magnetic
+} // End of namespace Glk
diff --git a/engines/glk/magnetic/magnetic.cpp b/engines/glk/magnetic/magnetic.cpp
new file mode 100644
index 0000000000..f3f3e79a86
--- /dev/null
+++ b/engines/glk/magnetic/magnetic.cpp
@@ -0,0 +1,79 @@
+/* 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/magnetic/magnetic.h"
+#include "common/config-manager.h"
+#include "common/translation.h"
+
+namespace Glk {
+namespace Magnetic {
+
+Magnetic::Magnetic(OSystem *syst, const GlkGameDescription &gameDesc) : GlkAPI(syst, gameDesc),
+ vm_exited_cleanly(false) {
+}
+
+void Magnetic::runGame(Common::SeekableReadStream *gameFile) {
+ _gameFile = gameFile;
+
+ if (!is_gamefile_valid())
+ return;
+
+ // TODO
+}
+
+Common::Error Magnetic::loadGameData(strid_t file) {
+ // TODO
+ return Common::kNoError;
+}
+
+Common::Error Magnetic::saveGameData(strid_t file, const Common::String &desc) {
+ // TODO
+ return Common::kNoError;
+}
+
+bool Magnetic::is_gamefile_valid() {
+ if (_gameFile->size() < 8) {
+ GUIErrorMessage(_("This is too short to be a valid Glulx file."));
+ return false;
+ }
+
+ if (_gameFile->readUint32BE() != MKTAG('G', 'l', 'u', 'l')) {
+ GUIErrorMessage(_("This is not a valid Glulx file."));
+ return false;
+ }
+
+ // We support version 2.0 through 3.1.*
+ uint version = _gameFile->readUint32BE();
+ if (version < 0x20000) {
+ GUIErrorMessage(_("This Glulx file is too old a version to execute."));
+ return false;
+ }
+ if (version >= 0x30200) {
+ GUIErrorMessage(_("This Glulx file is too new a version to execute."));
+ return false;
+ }
+
+ return true;
+}
+
+} // End of namespace Magnetic
+} // End of namespace Glk
diff --git a/engines/glk/magnetic/magnetic.h b/engines/glk/magnetic/magnetic.h
new file mode 100644
index 0000000000..6f30768d0c
--- /dev/null
+++ b/engines/glk/magnetic/magnetic.h
@@ -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.
+ *
+ */
+
+#ifndef GLK_GLULXE
+#define GLK_GLULXE
+
+#include "common/scummsys.h"
+#include "glk/glk_api.h"
+
+namespace Glk {
+namespace Magnetic {
+
+/**
+ * Magnetic game interpreter
+ */
+class Magnetic : 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
+ */
+ Magnetic(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_GLULXE; }
+
+ /**
+ * 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 Magnetic
+} // End of namespace Glk
+
+#endif
diff --git a/engines/glk/module.mk b/engines/glk/module.mk
index 71644814af..1af4ce6201 100644
--- a/engines/glk/module.mk
+++ b/engines/glk/module.mk
@@ -46,6 +46,8 @@ MODULE_OBJS := \
frotz/sound_folder.o \
glulxe/detection.o \
glulxe/glulxe.o \
+ magnetic/detection.o \
+ magnetic/magnetic.o \
scott/detection.o \
scott/scott.o \
tads/detection.o \