aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Gilbert2018-11-18 09:51:32 -0800
committerPaul Gilbert2018-12-08 19:05:59 -0800
commit79f3d946ef23ff121f30d9e429d2c4ab985ce29c (patch)
treed86c0a5ff560cd75378855c86744893dbeab7595
parent41a437816999c913f30f3ef2c1c751f646399c91 (diff)
downloadscummvm-rg350-79f3d946ef23ff121f30d9e429d2c4ab985ce29c.tar.gz
scummvm-rg350-79f3d946ef23ff121f30d9e429d2c4ab985ce29c.tar.bz2
scummvm-rg350-79f3d946ef23ff121f30d9e429d2c4ab985ce29c.zip
GLK: FROTZ: Shift Header class into it's own file
-rw-r--r--engines/glk/frotz/header.cpp112
-rw-r--r--engines/glk/frotz/header.h159
-rw-r--r--engines/glk/frotz/mem.cpp84
-rw-r--r--engines/glk/frotz/mem.h125
-rw-r--r--engines/glk/module.mk1
5 files changed, 274 insertions, 207 deletions
diff --git a/engines/glk/frotz/header.cpp b/engines/glk/frotz/header.cpp
new file mode 100644
index 0000000000..f7ebb5ec00
--- /dev/null
+++ b/engines/glk/frotz/header.cpp
@@ -0,0 +1,112 @@
+/* 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/frotz/header.h"
+#include "common/textconsole.h"
+
+namespace Glk {
+namespace Frotz {
+
+const Header::StoryEntry Header::RECORDS[25] = {
+ { SHERLOCK, 21, "871214" },
+ { SHERLOCK, 26, "880127" },
+ { BEYOND_ZORK, 47, "870915" },
+ { BEYOND_ZORK, 49, "870917" },
+ { BEYOND_ZORK, 51, "870923" },
+ { BEYOND_ZORK, 57, "871221" },
+ { ZORK_ZERO, 296, "881019" },
+ { ZORK_ZERO, 366, "890323" },
+ { ZORK_ZERO, 383, "890602" },
+ { ZORK_ZERO, 393, "890714" },
+ { SHOGUN, 292, "890314" },
+ { SHOGUN, 295, "890321" },
+ { SHOGUN, 311, "890510" },
+ { SHOGUN, 322, "890706" },
+ { ARTHUR, 54, "890606" },
+ { ARTHUR, 63, "890622" },
+ { ARTHUR, 74, "890714" },
+ { JOURNEY, 26, "890316" },
+ { JOURNEY, 30, "890322" },
+ { JOURNEY, 77, "890616" },
+ { JOURNEY, 83, "890706" },
+ { LURKING_HORROR, 203, "870506" },
+ { LURKING_HORROR, 219, "870912" },
+ { LURKING_HORROR, 221, "870918" },
+ { UNKNOWN, 0, "------" }
+};
+
+void Header::loadHeader(Common::SeekableReadStream &f) {
+ h_version = f.readByte();
+ h_config = f.readByte();
+
+ if (h_version < V1 || h_version > V8)
+ error("Unknown Z-code version");
+
+ if (h_version == V6)
+ error("Cannot play Z-code version 6");
+
+ if (h_version == V3 && (h_config & CONFIG_BYTE_SWAPPED))
+ error("Byte swapped story file");
+
+ h_release = f.readUint16BE();
+ h_resident_size = f.readUint16BE();
+ h_start_pc = f.readUint16BE();
+ h_dictionary = f.readUint16BE();
+ h_objects = f.readUint16BE();
+ h_globals = f.readUint16BE();
+ h_dynamic_size = f.readUint16BE();
+ h_flags = f.readUint16BE();
+ f.read(h_serial, 6);
+
+ /* Auto-detect buggy story files that need special fixes */
+ _storyId = UNKNOWN;
+
+ for (int i = 0; RECORDS[i]._storyId != UNKNOWN; ++i) {
+ if (h_release == RECORDS[i]._release) {
+ if (!strncmp((const char *)h_serial, RECORDS[i]._serial, 6)) {
+ _storyId = RECORDS[i]._storyId;
+ break;
+ }
+ }
+ }
+
+ h_abbreviations = f.readUint16BE();
+ h_file_size = f.readUint16BE();
+ h_checksum = f.readUint16BE();
+
+ f.seek(H_FUNCTIONS_OFFSET);
+ h_functions_offset = f.readUint16BE();
+ h_strings_offset = f.readUint16BE();
+ f.seek(H_TERMINATING_KEYS);
+ h_terminating_keys = f.readUint16BE();
+ f.seek(H_ALPHABET);
+ h_alphabet = f.readUint16BE();
+ h_extension_table = f.readUint16BE();
+
+
+ // Zork Zero Macintosh doesn't have the graphics flag set
+ if (_storyId == ZORK_ZERO && h_release == 296)
+ h_flags |= GRAPHICS_FLAG;
+}
+
+} // End of namespace Scott
+} // End of namespace Glk
diff --git a/engines/glk/frotz/header.h b/engines/glk/frotz/header.h
new file mode 100644
index 0000000000..cf7ab64f4f
--- /dev/null
+++ b/engines/glk/frotz/header.h
@@ -0,0 +1,159 @@
+/* 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_FROTZ_HEADER
+#define GLK_FROTZ_HEADER
+
+#include "glk/frotz/frotz_types.h"
+
+namespace Glk {
+namespace Frotz {
+
+enum HeaderByte {
+ H_VERSION = 0,
+ H_CONFIG = 1,
+ H_RELEASE = 2,
+ H_RESIDENT_SIZE = 4,
+ H_START_PC = 6,
+ H_DICTIONARY = 8,
+ H_OBJECTS = 10,
+ H_GLOBALS = 12,
+ H_DYNAMIC_SIZE = 14,
+ H_FLAGS = 16,
+ H_SERIAL = 18,
+ H_ABBREVIATIONS = 24,
+ H_FILE_SIZE = 26,
+ H_CHECKSUM = 28,
+ H_INTERPRETER_NUMBER = 30,
+ H_INTERPRETER_VERSION = 31,
+ H_SCREEN_ROWS = 32,
+ H_SCREEN_COLS = 33,
+ H_SCREEN_WIDTH = 34,
+ H_SCREEN_HEIGHT = 36,
+ H_FONT_HEIGHT = 38, ///< this is the font width in V5
+ H_FONT_WIDTH = 39, ///< this is the font height in V5
+ H_FUNCTIONS_OFFSET = 40,
+ H_STRINGS_OFFSET = 42,
+ H_DEFAULT_BACKGROUND = 44,
+ H_DEFAULT_FOREGROUND = 45,
+ H_TERMINATING_KEYS = 46,
+ H_LINE_WIDTH = 48,
+ H_STANDARD_HIGH = 50,
+ H_STANDARD_LOW = 51,
+ H_ALPHABET = 52,
+ H_EXTENSION_TABLE = 54,
+ H_USER_NAME = 56
+};
+
+enum {
+ HX_TABLE_SIZE = 0,
+ HX_MOUSE_X = 1,
+ HX_MOUSE_Y = 2,
+ HX_UNICODE_TABLE = 3,
+ HX_FLAGS = 4,
+ HX_FORE_COLOUR = 5,
+ HX_BACK_COLOUR = 6
+};
+
+/**
+ * Story file header data
+ */
+struct Header {
+private:
+ struct StoryEntry {
+ Story _storyId;
+ zword _release;
+ char _serial[7];
+ };
+ static const StoryEntry RECORDS[25];
+public:
+ zbyte h_version;
+ zbyte h_config;
+ zword h_release;
+ zword h_resident_size;
+ zword h_start_pc;
+ zword h_dictionary;
+ zword h_objects;
+ zword h_globals;
+ zword h_dynamic_size;
+ zword h_flags;
+ zbyte h_serial[6];
+ zword h_abbreviations;
+ zword h_file_size;
+ zword h_checksum;
+ zbyte h_interpreter_number;
+ zbyte h_interpreter_version;
+ zbyte h_screen_rows;
+ zbyte h_screen_cols;
+ zword h_screen_width;
+ zword h_screen_height;
+ zbyte h_font_height;
+ zbyte h_font_width;
+ zword h_functions_offset;
+ zword h_strings_offset;
+ zbyte h_default_background;
+ zbyte h_default_foreground;
+ zword h_terminating_keys;
+ zword h_line_width;
+ zbyte h_standard_high;
+ zbyte h_standard_low;
+ zword h_alphabet;
+ zword h_extension_table;
+ zbyte h_user_name[8];
+
+ zword hx_table_size;
+ zword hx_mouse_x;
+ zword hx_mouse_y;
+ zword hx_unicode_table;
+ zword hx_flags;
+ zword hx_fore_colour;
+ zword hx_back_colour;
+
+ Story _storyId;
+
+ /**
+ * Constructor
+ */
+ Header() : h_version(0), h_config(0), h_release(0), h_resident_size(0), h_start_pc(0),
+ h_dictionary(0), h_objects(0), h_globals(0), h_dynamic_size(0), h_flags(0),
+ h_abbreviations(0), h_file_size(0), h_checksum(0), h_interpreter_number(0),
+ h_interpreter_version(0), h_screen_rows(0), h_screen_cols(0), h_screen_width(0),
+ h_screen_height(0), h_font_height(1), h_font_width(1), h_functions_offset(0),
+ h_strings_offset(0), h_default_background(0), h_default_foreground(0),
+ h_terminating_keys(0), h_line_width(0), h_standard_high(1), h_standard_low(1),
+ h_alphabet(0), h_extension_table(0),
+ hx_table_size(0), hx_mouse_x(0), hx_mouse_y(0), hx_unicode_table(0),
+ hx_flags(0), hx_fore_colour(0), hx_back_colour(0), _storyId(UNKNOWN) {
+ Common::fill(&h_serial[0], &h_serial[6], '\0');
+ Common::fill(&h_user_name[0], &h_user_name[8], '\0');
+ }
+
+ /**
+ * Load the header
+ */
+ void loadHeader(Common::SeekableReadStream &f);
+};
+
+} // End of namespace Frotz
+} // End of namespace Glk
+
+#endif
diff --git a/engines/glk/frotz/mem.cpp b/engines/glk/frotz/mem.cpp
index 6ee6781690..da0acaa69f 100644
--- a/engines/glk/frotz/mem.cpp
+++ b/engines/glk/frotz/mem.cpp
@@ -28,90 +28,6 @@
namespace Glk {
namespace Frotz {
-const Header::StoryEntry Header::RECORDS[25] = {
- { SHERLOCK, 21, "871214" },
- { SHERLOCK, 26, "880127" },
- { BEYOND_ZORK, 47, "870915" },
- { BEYOND_ZORK, 49, "870917" },
- { BEYOND_ZORK, 51, "870923" },
- { BEYOND_ZORK, 57, "871221" },
- { ZORK_ZERO, 296, "881019" },
- { ZORK_ZERO, 366, "890323" },
- { ZORK_ZERO, 383, "890602" },
- { ZORK_ZERO, 393, "890714" },
- { SHOGUN, 292, "890314" },
- { SHOGUN, 295, "890321" },
- { SHOGUN, 311, "890510" },
- { SHOGUN, 322, "890706" },
- { ARTHUR, 54, "890606" },
- { ARTHUR, 63, "890622" },
- { ARTHUR, 74, "890714" },
- { JOURNEY, 26, "890316" },
- { JOURNEY, 30, "890322" },
- { JOURNEY, 77, "890616" },
- { JOURNEY, 83, "890706" },
- { LURKING_HORROR, 203, "870506" },
- { LURKING_HORROR, 219, "870912" },
- { LURKING_HORROR, 221, "870918" },
- { UNKNOWN, 0, "------" }
-};
-
-void Header::loadHeader(Common::SeekableReadStream &f) {
- h_version = f.readByte();
- h_config = f.readByte();
-
- if (h_version < V1 || h_version > V8)
- error("Unknown Z-code version");
-
- if (h_version == V6)
- error("Cannot play Z-code version 6");
-
- if (h_version == V3 && (h_config & CONFIG_BYTE_SWAPPED))
- error("Byte swapped story file");
-
- h_release = f.readUint16BE();
- h_resident_size = f.readUint16BE();
- h_start_pc = f.readUint16BE();
- h_dictionary = f.readUint16BE();
- h_objects = f.readUint16BE();
- h_globals = f.readUint16BE();
- h_dynamic_size = f.readUint16BE();
- h_flags = f.readUint16BE();
- f.read(h_serial, 6);
-
- /* Auto-detect buggy story files that need special fixes */
- _storyId = UNKNOWN;
-
- for (int i = 0; RECORDS[i]._storyId != UNKNOWN; ++i) {
- if (h_release == RECORDS[i]._release) {
- if (!strncmp((const char *)h_serial, RECORDS[i]._serial, 6)) {
- _storyId = RECORDS[i]._storyId;
- break;
- }
- }
- }
-
- h_abbreviations = f.readUint16BE();
- h_file_size = f.readUint16BE();
- h_checksum = f.readUint16BE();
-
- f.seek(H_FUNCTIONS_OFFSET);
- h_functions_offset = f.readUint16BE();
- h_strings_offset = f.readUint16BE();
- f.seek(H_TERMINATING_KEYS);
- h_terminating_keys = f.readUint16BE();
- f.seek(H_ALPHABET);
- h_alphabet = f.readUint16BE();
- h_extension_table = f.readUint16BE();
-
-
- // Zork Zero Macintosh doesn't have the graphics flag set
- if (_storyId == ZORK_ZERO && h_release == 296)
- h_flags |= GRAPHICS_FLAG;
-}
-
-/*--------------------------------------------------------------------------*/
-
Mem::Mem() : story_fp(nullptr), blorb_ofs(0), blorb_len(0), story_size(0),
first_undo(nullptr), last_undo(nullptr), curr_undo(nullptr),
undo_mem(nullptr), prev_zmp(nullptr), undo_diff(nullptr),
diff --git a/engines/glk/frotz/mem.h b/engines/glk/frotz/mem.h
index 372c7e78d1..3b1b81b21f 100644
--- a/engines/glk/frotz/mem.h
+++ b/engines/glk/frotz/mem.h
@@ -24,6 +24,7 @@
#define GLK_FROTZ_MEM
#include "glk/frotz/frotz_types.h"
+#include "glk/frotz/header.h"
namespace Glk {
namespace Frotz {
@@ -35,52 +36,6 @@ namespace Frotz {
#define SET_BYTE(addr,v) zmp[addr] = v
#define LOW_BYTE(addr,v) v = zmp[addr]
-enum HeaderByte {
- H_VERSION = 0,
- H_CONFIG = 1,
- H_RELEASE = 2,
- H_RESIDENT_SIZE = 4,
- H_START_PC = 6,
- H_DICTIONARY = 8,
- H_OBJECTS = 10,
- H_GLOBALS = 12,
- H_DYNAMIC_SIZE = 14,
- H_FLAGS = 16,
- H_SERIAL = 18,
- H_ABBREVIATIONS = 24,
- H_FILE_SIZE = 26,
- H_CHECKSUM = 28,
- H_INTERPRETER_NUMBER = 30,
- H_INTERPRETER_VERSION = 31,
- H_SCREEN_ROWS = 32,
- H_SCREEN_COLS = 33,
- H_SCREEN_WIDTH = 34,
- H_SCREEN_HEIGHT = 36,
- H_FONT_HEIGHT = 38, ///< this is the font width in V5
- H_FONT_WIDTH = 39, ///< this is the font height in V5
- H_FUNCTIONS_OFFSET = 40,
- H_STRINGS_OFFSET = 42,
- H_DEFAULT_BACKGROUND = 44,
- H_DEFAULT_FOREGROUND = 45,
- H_TERMINATING_KEYS = 46,
- H_LINE_WIDTH = 48,
- H_STANDARD_HIGH = 50,
- H_STANDARD_LOW = 51,
- H_ALPHABET = 52,
- H_EXTENSION_TABLE = 54,
- H_USER_NAME = 56
-};
-
-enum {
- HX_TABLE_SIZE = 0,
- HX_MOUSE_X = 1,
- HX_MOUSE_Y = 2,
- HX_UNICODE_TABLE = 3,
- HX_FLAGS = 4,
- HX_FORE_COLOUR = 5,
- HX_BACK_COLOUR = 6
-};
-
/**
* Stores undo information
*/
@@ -97,84 +52,8 @@ struct undo_struct {
typedef undo_struct undo_t;
/**
- * Story file header data
+ * Handles the memory, header, and user options
*/
-struct Header {
-private:
- struct StoryEntry {
- Story _storyId;
- zword _release;
- char _serial[7];
- };
- static const StoryEntry RECORDS[25];
-public:
- zbyte h_version;
- zbyte h_config;
- zword h_release;
- zword h_resident_size;
- zword h_start_pc;
- zword h_dictionary;
- zword h_objects;
- zword h_globals;
- zword h_dynamic_size;
- zword h_flags;
- zbyte h_serial[6];
- zword h_abbreviations;
- zword h_file_size;
- zword h_checksum;
- zbyte h_interpreter_number;
- zbyte h_interpreter_version;
- zbyte h_screen_rows;
- zbyte h_screen_cols;
- zword h_screen_width;
- zword h_screen_height;
- zbyte h_font_height;
- zbyte h_font_width;
- zword h_functions_offset;
- zword h_strings_offset;
- zbyte h_default_background;
- zbyte h_default_foreground;
- zword h_terminating_keys;
- zword h_line_width;
- zbyte h_standard_high;
- zbyte h_standard_low;
- zword h_alphabet;
- zword h_extension_table;
- zbyte h_user_name[8];
-
- zword hx_table_size;
- zword hx_mouse_x;
- zword hx_mouse_y;
- zword hx_unicode_table;
- zword hx_flags;
- zword hx_fore_colour;
- zword hx_back_colour;
-
- Story _storyId;
-
- /**
- * Constructor
- */
- Header() : h_version(0), h_config(0), h_release(0), h_resident_size(0), h_start_pc(0),
- h_dictionary(0), h_objects(0), h_globals(0), h_dynamic_size(0), h_flags(0),
- h_abbreviations(0), h_file_size(0), h_checksum(0), h_interpreter_number(0),
- h_interpreter_version(0), h_screen_rows(0), h_screen_cols(0), h_screen_width(0),
- h_screen_height(0), h_font_height(1), h_font_width(1), h_functions_offset(0),
- h_strings_offset(0), h_default_background(0), h_default_foreground(0),
- h_terminating_keys(0), h_line_width(0), h_standard_high(1), h_standard_low(1),
- h_alphabet(0), h_extension_table(0),
- hx_table_size(0), hx_mouse_x(0), hx_mouse_y(0), hx_unicode_table(0),
- hx_flags(0), hx_fore_colour(0), hx_back_colour(0), _storyId(UNKNOWN) {
- Common::fill(&h_serial[0], &h_serial[6], '\0');
- Common::fill(&h_user_name[0], &h_user_name[8], '\0');
- }
-
- /**
- * Load the header
- */
- void loadHeader(Common::SeekableReadStream &f);
-};
-
class Mem : public Header, public virtual UserOptions {
protected:
Common::SeekableReadStream *story_fp;
diff --git a/engines/glk/module.mk b/engines/glk/module.mk
index b5230344a0..10cef3220b 100644
--- a/engines/glk/module.mk
+++ b/engines/glk/module.mk
@@ -24,6 +24,7 @@ MODULE_OBJS := \
frotz/detection.o \
frotz/frotz.o \
frotz/glk_interface.o \
+ frotz/header.o \
frotz/mem.o \
frotz/processor.o \
frotz/processor_buffer.o \