diff options
Diffstat (limited to 'engines')
-rw-r--r-- | engines/gargoyle/frotz/mem.cpp | 89 | ||||
-rw-r--r-- | engines/gargoyle/frotz/mem.h | 46 | ||||
-rw-r--r-- | engines/gargoyle/frotz/processor.h | 10 | ||||
-rw-r--r-- | engines/gargoyle/frotz/processor_input.cpp | 29 | ||||
-rw-r--r-- | engines/gargoyle/frotz/processor_mem.cpp | 39 | ||||
-rw-r--r-- | engines/gargoyle/frotz/processor_streams.cpp | 1 | ||||
-rw-r--r-- | engines/gargoyle/module.mk | 1 |
7 files changed, 159 insertions, 56 deletions
diff --git a/engines/gargoyle/frotz/mem.cpp b/engines/gargoyle/frotz/mem.cpp index d9ff53d449..57b282531d 100644 --- a/engines/gargoyle/frotz/mem.cpp +++ b/engines/gargoyle/frotz/mem.cpp @@ -134,11 +134,10 @@ void Mem::initialize() { if (story_size - size < 0x8000) n = story_size - size; - setPC(size); + SET_PC(size); if (story_fp->read(pcp, n) != n) error("Story file read error"); - } // Read header extension table @@ -236,5 +235,91 @@ zword Mem::get_header_extension(int entry) { return val; } +void Mem::set_header_extension(int entry, zword val) { + zword addr; + + if (h_extension_table == 0 || entry > hx_table_size) + return; + + addr = h_extension_table + 2 * entry; + SET_WORD(addr, val); +} + +void Mem::restart_header(void) { + zword screen_x_size; + zword screen_y_size; + zbyte font_x_size; + zbyte font_y_size; + + int i; + + SET_BYTE(H_CONFIG, h_config); + SET_WORD(H_FLAGS, h_flags); + + if (h_version >= V4) { + SET_BYTE(H_INTERPRETER_NUMBER, h_interpreter_number); + SET_BYTE(H_INTERPRETER_VERSION, h_interpreter_version); + SET_BYTE(H_SCREEN_ROWS, h_screen_rows); + SET_BYTE(H_SCREEN_COLS, h_screen_cols); + } + + /* It's less trouble to use font size 1x1 for V5 games, especially + because of a bug in the unreleased German version of "Zork 1" */ + + if (h_version != V6) { + screen_x_size = (zword)h_screen_cols; + screen_y_size = (zword)h_screen_rows; + font_x_size = 1; + font_y_size = 1; + } else { + screen_x_size = h_screen_width; + screen_y_size = h_screen_height; + font_x_size = h_font_width; + font_y_size = h_font_height; + } + + if (h_version >= V5) { + SET_WORD(H_SCREEN_WIDTH, screen_x_size); + SET_WORD(H_SCREEN_HEIGHT, screen_y_size); + SET_BYTE(H_FONT_HEIGHT, font_y_size); + SET_BYTE(H_FONT_WIDTH, font_x_size); + SET_BYTE(H_DEFAULT_BACKGROUND, h_default_background); + SET_BYTE(H_DEFAULT_FOREGROUND, h_default_foreground); + } + + if (h_version == V6) + for (i = 0; i < 8; i++) + storeb((zword)(H_USER_NAME + i), h_user_name[i]); + + SET_BYTE(H_STANDARD_HIGH, h_standard_high); + SET_BYTE(H_STANDARD_LOW, h_standard_low); + + set_header_extension(HX_FLAGS, hx_flags); + set_header_extension(HX_FORE_COLOUR, hx_fore_colour); + set_header_extension(HX_BACK_COLOUR, hx_back_colour); +} + +void Mem::storeb(zword addr, zbyte value) { + if (addr >= h_dynamic_size) + runtimeError(ERR_STORE_RANGE); + + if (addr == H_FLAGS + 1) { + // flags register is modified + + h_flags &= ~(SCRIPTING_FLAG | FIXED_FONT_FLAG); + h_flags |= value & (SCRIPTING_FLAG | FIXED_FONT_FLAG); + + flagsChanged(value); + } + + SET_BYTE(addr, value); +} + +void Mem::storew(zword addr, zword value) { + storeb((zword)(addr + 0), hi(value)); + storeb((zword)(addr + 1), lo(value)); +} + + } // End of namespace Scott } // End of namespace Gargoyle diff --git a/engines/gargoyle/frotz/mem.h b/engines/gargoyle/frotz/mem.h index e12c062ff8..c128994df1 100644 --- a/engines/gargoyle/frotz/mem.h +++ b/engines/gargoyle/frotz/mem.h @@ -24,6 +24,7 @@ #define GARGOYLE_FROTZ_MEM #include "gargoyle/frotz/frotz_types.h" +#include "gargoyle/frotz/err.h" namespace Gargoyle { namespace Frotz { @@ -202,46 +203,51 @@ private: * Handles loading the game header */ void loadGameHeader(); -public: +protected: /** - * Constructor + * Read a value from the header extension (former mouse table). */ - Mem(); + zword get_header_extension(int entry); /** - * Initialize + * Set an entry in the header extension (former mouse table). */ - void initialize(); + void set_header_extension(int entry, zword val); /** - * Read a word + * Set all header fields which hold information about the interpreter. */ - zword readWord() { - pcp += 2; - return READ_BE_UINT16(pcp - 2); - } + void restart_header(); /** - * Read a word at a given index relative to pcp + * Write a byte value to the dynamic Z-machine memory. */ - zword readWord(size_t ofs) { - return READ_BE_UINT16(pcp + ofs); - } + void storeb(zword addr, zbyte value); /** - * Get the PC + * Write a word value to the dynamic Z-machine memory. */ - uint getPC() const { return pcp - zmp; } + void storew(zword addr, zword value); /** - * Set the PC + * Generates a runtime error */ - void setPC(uint ofs) { pcp = zmp + ofs; } + virtual void runtimeError(ErrorCode errNum) = 0; /** - * Read a value from the header extension (former mouse table). + * Called when the flags are changed */ - zword get_header_extension(int entry); + virtual void flagsChanged(zbyte value) = 0; +public: + /** + * Constructor + */ + Mem(); + + /** + * Initialize + */ + void initialize(); }; } // End of namespace Frotz diff --git a/engines/gargoyle/frotz/processor.h b/engines/gargoyle/frotz/processor.h index 1554265092..b70bf440a2 100644 --- a/engines/gargoyle/frotz/processor.h +++ b/engines/gargoyle/frotz/processor.h @@ -208,14 +208,16 @@ private: */ /** - * Write a byte value to the dynamic Z-machine memory. + * Generates a runtime error */ - void storeb(zword addr, zbyte value); + virtual void runtimeError(ErrorCode errNum) override { + Errors::runtimeError(errNum); + } /** - * Write a word value to the dynamic Z-machine memory. + * Called when the H_FLAGS field of the header has changed */ - void storew(zword addr, zword value); + virtual void flagsChanged(zbyte value) override; /** * \defgroup Object support methods diff --git a/engines/gargoyle/frotz/processor_input.cpp b/engines/gargoyle/frotz/processor_input.cpp index 43f0aaf455..b9c9604183 100644 --- a/engines/gargoyle/frotz/processor_input.cpp +++ b/engines/gargoyle/frotz/processor_input.cpp @@ -80,35 +80,6 @@ int Processor::read_number() { return value; } -void Processor::storeb(zword addr, zbyte value) { - if (addr >= h_dynamic_size) - runtimeError(ERR_STORE_RANGE); - - if (addr == H_FLAGS + 1) { /* flags register is modified */ - - h_flags &= ~(SCRIPTING_FLAG | FIXED_FONT_FLAG); - h_flags |= value & (SCRIPTING_FLAG | FIXED_FONT_FLAG); - - if (value & SCRIPTING_FLAG) { - if (!ostream_script) - script_open(); - } else { - if (ostream_script) - script_close(); - } - - // TOR - glkified / refresh_text_style (); - } - - SET_BYTE(addr, value); - -} - -void Processor::storew(zword addr, zword value) { - storeb((zword)(addr + 0), hi(value)); - storeb((zword)(addr + 1), lo(value)); -} - void Processor::z_read() { zchar buffer[INPUT_BUFFER_SIZE]; zword addr; diff --git a/engines/gargoyle/frotz/processor_mem.cpp b/engines/gargoyle/frotz/processor_mem.cpp new file mode 100644 index 0000000000..1f3944ea17 --- /dev/null +++ b/engines/gargoyle/frotz/processor_mem.cpp @@ -0,0 +1,39 @@ +/* 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 "gargoyle/frotz/processor.h" + +namespace Gargoyle { +namespace Frotz { + +void Processor::flagsChanged(zbyte value) { + if (value & SCRIPTING_FLAG) { + if (!ostream_script) + script_open(); + } else { + if (ostream_script) + script_close(); + } +} + +} // End of namespace Scott +} // End of namespace Gargoyle diff --git a/engines/gargoyle/frotz/processor_streams.cpp b/engines/gargoyle/frotz/processor_streams.cpp index 3f35c1f4ca..44062757ef 100644 --- a/engines/gargoyle/frotz/processor_streams.cpp +++ b/engines/gargoyle/frotz/processor_streams.cpp @@ -49,7 +49,6 @@ static void record_open() {} static void record_close() {} static void record_write_key(zchar) {} static void record_write_input(zchar *, zchar) {} -static void restart_header() {} void Processor::scrollback_char (zchar c) { diff --git a/engines/gargoyle/module.mk b/engines/gargoyle/module.mk index 78bde80443..14cc04801e 100644 --- a/engines/gargoyle/module.mk +++ b/engines/gargoyle/module.mk @@ -31,6 +31,7 @@ MODULE_OBJS := \ frotz/processor_buffer.o \ frotz/processor_input.o \ frotz/processor_maths.o \ + frotz/processor_mem.o \ frotz/processor_objects.o \ frotz/processor_screen.o \ frotz/processor_streams.o \ |