aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
Diffstat (limited to 'engines')
-rw-r--r--engines/titanic/files.cpp167
-rw-r--r--engines/titanic/files.h82
-rw-r--r--engines/titanic/module.mk2
-rw-r--r--engines/titanic/string.cpp27
-rw-r--r--engines/titanic/string.h37
5 files changed, 315 insertions, 0 deletions
diff --git a/engines/titanic/files.cpp b/engines/titanic/files.cpp
new file mode 100644
index 0000000000..814746ecda
--- /dev/null
+++ b/engines/titanic/files.cpp
@@ -0,0 +1,167 @@
+/* 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 "titanic/files.h"
+#include "common/util.h"
+
+namespace Titanic {
+
+SimpleFile::SimpleFile() {
+}
+
+void SimpleFile::open(const Common::String &name, FileMode mode) {
+ assert(mode == FILE_READ);
+ if (!_file.open(name))
+ error("Could not find file - %s", name.c_str());
+}
+
+void SimpleFile::close() {
+ _file.close();
+}
+
+void SimpleFile::safeRead(void *dst, size_t count) {
+ if (_file.read(dst, count) != count)
+ error("Could not read %d bytes", count);
+}
+
+int SimpleFile::unsafeRead(void *dst, size_t count) {
+ return _file.read(dst, count);
+}
+
+CString SimpleFile::readString() {
+ char c;
+ CString result;
+ bool backslashFlag = false;
+
+ // First skip any spaces
+ do {
+ safeRead(&c, 1);
+ } while (Common::isSpace(c));
+
+ // Ensure we've found a starting quote for the string
+ if (c != '"')
+ error("Could not find starting quote");
+
+ bool endFlag = false;
+ while (!endFlag) {
+ // Read the next character
+ safeRead(&c, 1);
+
+ if (backslashFlag) {
+ backslashFlag = false;
+ switch (c) {
+ case 'n':
+ result += '\n';
+ break;
+ case 'r':
+ result += '\r';
+ break;
+ case '\t':
+ result += '\t';
+ break;
+ default:
+ result += c;
+ break;
+ }
+ } else {
+ switch (c) {
+ case '"':
+ endFlag = true;
+ break;
+ case '\\':
+ backslashFlag = true;
+ break;
+ default:
+ result += c;
+ break;
+ }
+ }
+ }
+
+ // Return the string
+ return result;
+}
+
+int SimpleFile::readNumber() {
+ char c;
+ int result = 0;
+ bool minusFlag = false;
+
+ // First skip any spaces
+ do {
+ safeRead(&c, 1);
+ } while (Common::isSpace(c));
+
+ // Check for prefix sign
+ if (c == '+' || c == '-') {
+ minusFlag = c == '-';
+ safeRead(&c, 1);
+ }
+
+ // Read in the number
+ if (!Common::isDigit(c))
+ error("Invalid number");
+
+ while (Common::isDigit(c)) {
+ result = result * 10 + (c - '0');
+ safeRead(&c, 1);
+ }
+
+ // Finally, if it's a minus value, then negate it
+ if (minusFlag)
+ result = -result;
+
+ return result;
+}
+
+double SimpleFile::readFloat() {
+ char c;
+ Common::String result;
+
+ // First skip any spaces
+ do {
+ safeRead(&c, 1);
+ } while (Common::isSpace(c));
+
+ // Check for prefix sign
+ if (c == '+' || c == '-') {
+ result += c;
+ safeRead(&c, 1);
+ }
+
+ // Read in the number
+ if (!Common::isDigit(c))
+ error("Invalid number");
+
+ while (Common::isDigit(c) || c == '.') {
+ result += c;
+ safeRead(&c, 1);
+ }
+
+ // Convert to a float and return it
+ float floatValue;
+ sscanf(result.c_str(), "%f", &floatValue);
+
+ return floatValue;
+}
+
+} // End of namespace Titanic
diff --git a/engines/titanic/files.h b/engines/titanic/files.h
new file mode 100644
index 0000000000..d8810dc84c
--- /dev/null
+++ b/engines/titanic/files.h
@@ -0,0 +1,82 @@
+/* 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 TITANIC_FILES_H
+#define TITANIC_FILES_H
+
+#include "common/scummsys.h"
+#include "common/file.h"
+#include "titanic/string.h"
+
+namespace Titanic {
+
+enum FileMode { FILE_READ = 1, FILE_WRITE = 2 };
+
+class SimpleFile {
+public:
+ Common::File _file;
+public:
+ SimpleFile();
+
+ /**
+ * Open a file for access
+ */
+ virtual void open(const Common::String &name, FileMode mode = FILE_READ);
+
+ /**
+ * Close the file
+ */
+ virtual void close();
+
+ /**
+ * Read from the file with validation
+ */
+ virtual void safeRead(void *dst, size_t count);
+
+ /**
+ * Read from the file
+ */
+ virtual int unsafeRead(void *dst, size_t count);
+
+ /**
+ * Read a string from the file
+ */
+ virtual CString readString();
+
+ /**
+ * Read a number from the file
+ */
+ virtual int readNumber();
+
+ /**
+ * Read a floating point number from the file
+ */
+ virtual double readFloat();
+};
+
+class CompressedFile : public SimpleFile {
+
+};
+
+} // End of namespace Titanic
+
+#endif /* TITANIC_FILES_H */
diff --git a/engines/titanic/module.mk b/engines/titanic/module.mk
index bc37fba5ec..d65459d2d1 100644
--- a/engines/titanic/module.mk
+++ b/engines/titanic/module.mk
@@ -3,11 +3,13 @@ MODULE := engines/titanic
MODULE_OBJS := \
detection.o \
direct_draw.o \
+ files.o \
font.o \
image.o \
main_game_window.o \
saveable_object.o \
screen_manager.o \
+ string.o \
titanic.o \
video_surface.o
diff --git a/engines/titanic/string.cpp b/engines/titanic/string.cpp
new file mode 100644
index 0000000000..cdc251d9c3
--- /dev/null
+++ b/engines/titanic/string.cpp
@@ -0,0 +1,27 @@
+/* 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 "titanic/files.h"
+
+namespace Titanic {
+
+} // End of namespace Titanic
diff --git a/engines/titanic/string.h b/engines/titanic/string.h
new file mode 100644
index 0000000000..9b8cca0396
--- /dev/null
+++ b/engines/titanic/string.h
@@ -0,0 +1,37 @@
+/* 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 TITANIC_STRING_H
+#define TITANIC_STRING_H
+
+#include "common/scummsys.h"
+#include "common/str.h"
+
+namespace Titanic {
+
+class CString : public Common::String {
+
+};
+
+} // End of namespace Titanic
+
+#endif /* TITANIC_STRING_H */