aboutsummaryrefslogtreecommitdiff
path: root/engines/gargoyle/frotz
diff options
context:
space:
mode:
authorPaul Gilbert2018-11-12 11:26:59 -0800
committerPaul Gilbert2018-12-08 19:05:59 -0800
commitaab1dfeff8002a8b8f69d4d5f24110a7a01c263d (patch)
tree67b76a75007c143b36177c6dcf85e2725866a669 /engines/gargoyle/frotz
parent7a52f21c0bb267d6851ede650298b1d084493ef6 (diff)
downloadscummvm-rg350-aab1dfeff8002a8b8f69d4d5f24110a7a01c263d.tar.gz
scummvm-rg350-aab1dfeff8002a8b8f69d4d5f24110a7a01c263d.tar.bz2
scummvm-rg350-aab1dfeff8002a8b8f69d4d5f24110a7a01c263d.zip
GLK: FROTZ: Added memory redirect methods
Diffstat (limited to 'engines/gargoyle/frotz')
-rw-r--r--engines/gargoyle/frotz/frotz_types.h12
-rw-r--r--engines/gargoyle/frotz/processor.h23
-rw-r--r--engines/gargoyle/frotz/processor_mem.cpp96
-rw-r--r--engines/gargoyle/frotz/processor_streams.cpp4
4 files changed, 131 insertions, 4 deletions
diff --git a/engines/gargoyle/frotz/frotz_types.h b/engines/gargoyle/frotz/frotz_types.h
index 2b33fbddda..3ccaa451f8 100644
--- a/engines/gargoyle/frotz/frotz_types.h
+++ b/engines/gargoyle/frotz/frotz_types.h
@@ -239,6 +239,18 @@ struct UserOptions {
}
};
+#define MAX_NESTING 16
+struct Redirect {
+ zword _xSize;
+ zword _table;
+ zword _width;
+ zword _total;
+
+ Redirect() : _xSize(0), _table(0), _width(0), _total(0) {}
+ Redirect(zword xSize, zword table, zword width = 0, zword total = 0) :
+ _xSize(xSize), _table(table), _width(width), _total(total) {}
+};
+
} // End of namespace Frotz
} // End of namespace Gargoyle
diff --git a/engines/gargoyle/frotz/processor.h b/engines/gargoyle/frotz/processor.h
index 50c951a589..0a9d0efcdf 100644
--- a/engines/gargoyle/frotz/processor.h
+++ b/engines/gargoyle/frotz/processor.h
@@ -26,6 +26,8 @@
#include "gargoyle/frotz/err.h"
#include "gargoyle/frotz/mem.h"
#include "gargoyle/frotz/glk_interface.h"
+#include "gargoyle/frotz/frotz_types.h"
+#include "common/stack.h"
namespace Gargoyle {
namespace Frotz {
@@ -83,6 +85,7 @@ private:
// Stream related fields
int script_width;
strid_t sfp, rfp, pfp;
+ Common::FixedStack<Redirect, MAX_NESTING> _redirect;
private:
/**
* \defgroup General support methods
@@ -233,6 +236,26 @@ private:
*/
int restore_undo();
+ /**
+ * Begin output redirection to the memory of the Z-machine.
+ */
+ void memory_open(zword table, zword xsize, bool buffering);
+
+ /**
+ * End of output redirection.
+ */
+ void memory_close();
+
+ /**
+ * Redirect a newline to the memory of the Z-machine.
+ */
+ void memory_new_line();
+
+ /**
+ * Redirect a string of characters to the memory of the Z-machine.
+ */
+ void memory_word(const zchar *s);
+
/**@}*/
/**
diff --git a/engines/gargoyle/frotz/processor_mem.cpp b/engines/gargoyle/frotz/processor_mem.cpp
index 71abe77c1f..d46402c53c 100644
--- a/engines/gargoyle/frotz/processor_mem.cpp
+++ b/engines/gargoyle/frotz/processor_mem.cpp
@@ -118,5 +118,101 @@ int Processor::restore_undo(void) {
return 2;
}
+/**
+ * TOR: glkify -- this is for V6 only
+ */
+static zword get_max_width(zword win) { return 80; }
+
+void Processor::memory_open(zword table, zword xsize, bool buffering) {
+ if (_redirect.size() < MAX_NESTING) {
+ if (!buffering)
+ xsize = 0xffff;
+ if (buffering && (short)xsize <= 0)
+ xsize = get_max_width((zword)(-(short)xsize));
+
+ storew(table, 0);
+
+ _redirect.push(Redirect(xsize, table));
+ ostream_memory = true;
+ } else {
+ runtimeError(ERR_STR3_NESTING);
+ }
+}
+
+void Processor::memory_new_line() {
+ zword size;
+ zword addr;
+
+ Redirect &r = _redirect.top();
+ r._total += r._width;
+ r._width = 0;
+
+ addr = r._table;
+
+ LOW_WORD(addr, size);
+ addr += 2;
+
+ if (r._xSize != 0xffff) {
+ r._table = addr + size;
+ size = 0;
+ } else {
+ storeb((zword)(addr + (size++)), 13);
+ }
+
+ storew(r._table, size);
+}
+
+void Processor::memory_word(const zchar *s) {
+ zword size;
+ zword addr;
+ zchar c;
+
+ Redirect &r = _redirect.top();
+ if (h_version == V6) {
+ int width = os_string_width(s);
+
+ if (r._xSize != 0xffff) {
+ if (r._width + width > r._xSize) {
+
+ if (*s == ' ' || *s == ZC_INDENT || *s == ZC_GAP)
+ width = os_string_width(++s);
+
+ memory_new_line();
+ }
+ }
+
+ r._width += width;
+ }
+
+ addr = r._table;
+
+ LOW_WORD(addr, size);
+ addr += 2;
+
+ while ((c = *s++) != 0)
+ storeb((zword)(addr + (size++)), translate_to_zscii(c));
+
+ storew(r._table, size);
+}
+
+void Processor::memory_close(void) {
+ if (!_redirect.empty()) {
+ Redirect &r = _redirect.top();
+
+ if (r._xSize != 0xffff)
+ memory_new_line();
+
+ if (h_version == V6) {
+ h_line_width = (r._xSize != 0xffff) ? r._total : r._width;
+
+ SET_WORD(H_LINE_WIDTH, h_line_width);
+ }
+
+ _redirect.pop();
+ if (_redirect.empty())
+ ostream_memory = false;
+ }
+}
+
} // 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 95205a58bd..97784c8423 100644
--- a/engines/gargoyle/frotz/processor_streams.cpp
+++ b/engines/gargoyle/frotz/processor_streams.cpp
@@ -28,10 +28,6 @@ namespace Frotz {
// TODO: Implement method stubs
static void os_scrollback_char(zchar) {}
static void os_scrollback_erase(zword) {}
-static void memory_open(zword, zword, bool) {}
-static void memory_close() {}
-static void memory_word(const zchar *) {}
-static void memory_new_line() {}
static zchar console_read_key(zword) { return 0; }
static zchar console_read_input(uint, zchar *, uint, bool) { return 0; }