aboutsummaryrefslogtreecommitdiff
path: root/engines/gargoyle/frotz
diff options
context:
space:
mode:
authorPaul Gilbert2018-11-11 22:18:24 -0800
committerPaul Gilbert2018-12-08 19:05:59 -0800
commitfbe7fb7e1a6223070bd0d0c9929b372391756c8c (patch)
tree9f298cce10cf790354783d5f11cbe3a8645ecaa7 /engines/gargoyle/frotz
parent7a3dd94de1e5343f00316d69674e46d129f56914 (diff)
downloadscummvm-rg350-fbe7fb7e1a6223070bd0d0c9929b372391756c8c.tar.gz
scummvm-rg350-fbe7fb7e1a6223070bd0d0c9929b372391756c8c.tar.bz2
scummvm-rg350-fbe7fb7e1a6223070bd0d0c9929b372391756c8c.zip
GLK: FROTZ: Merge Buffer class into Processor
Diffstat (limited to 'engines/gargoyle/frotz')
-rw-r--r--engines/gargoyle/frotz/buffer.h72
-rw-r--r--engines/gargoyle/frotz/processor.cpp4
-rw-r--r--engines/gargoyle/frotz/processor.h46
-rw-r--r--engines/gargoyle/frotz/processor_buffer.cpp (renamed from engines/gargoyle/frotz/buffer.cpp)23
-rw-r--r--engines/gargoyle/frotz/processor_streams.cpp1
-rw-r--r--engines/gargoyle/frotz/processor_text.cpp2
6 files changed, 52 insertions, 96 deletions
diff --git a/engines/gargoyle/frotz/buffer.h b/engines/gargoyle/frotz/buffer.h
deleted file mode 100644
index 608e087f3d..0000000000
--- a/engines/gargoyle/frotz/buffer.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/* 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 GARGOYLE_FROTZ_BUFFER
-#define GARGOYLE_FROTZ_BUFFER
-
-#include "gargoyle/frotz/frotz_types.h"
-
-namespace Gargoyle {
-namespace Frotz {
-
-#define TEXT_BUFFER_SIZE 200
-
-/**
- * Text buffer class
- */
-class Buffer {
-public:
- zchar _buffer[TEXT_BUFFER_SIZE];
- size_t _bufPos;
- bool _locked;
- zchar _prevC;
-public:
- /**
- * Constructor
- */
- Buffer();
-
- /**
- * Copy the contents of the text buffer to the output streams.
- */
- void flush();
-
- /**
- * High level output function.
- */
- void printChar(zchar c);
-
- /**
- * High level newline function.
- */
- void newLine();
-
- /**
- * Returns true if the buffer is empty
- */
- bool empty() const { return !_bufPos; }
-};
-
-} // End of namespace Frotz
-} // End of namespace Gargoyle
-
-#endif
diff --git a/engines/gargoyle/frotz/processor.cpp b/engines/gargoyle/frotz/processor.cpp
index 721f64b4bf..85a539b48f 100644
--- a/engines/gargoyle/frotz/processor.cpp
+++ b/engines/gargoyle/frotz/processor.cpp
@@ -135,7 +135,8 @@ Processor::Processor(OSystem *syst, const GargoyleGameDescription *gameDesc) :
GlkInterface(syst, gameDesc), Errors(),
_finished(0), _sp(nullptr), _fp(nullptr), _frameCount(0),
zargc(0), _decoded(nullptr), _encoded(nullptr), _resolution(0),
- _randomInterval(0), _randomCtr(0), first_restart(true) {
+ _randomInterval(0), _randomCtr(0), first_restart(true), _bufPos(0),
+ _locked(false), _prevC('\0') {
static const Opcode OP0_OPCODES[16] = {
&Processor::z_rtrue,
&Processor::z_rfalse,
@@ -177,6 +178,7 @@ Processor::Processor(OSystem *syst, const GargoyleGameDescription *gameDesc) :
Common::copy(&OP1_OPCODES[0], &OP1_OPCODES[16], op1_opcodes);
Common::fill(&_stack[0], &_stack[STACK_SIZE], 0);
Common::fill(&zargs[0], &zargs[8], 0);
+ Common::fill(&_buffer[0], &_buffer[TEXT_BUFFER_SIZE], '\0');
}
void Processor::initialize() {
diff --git a/engines/gargoyle/frotz/processor.h b/engines/gargoyle/frotz/processor.h
index 77192b4f6a..d754b1f1ee 100644
--- a/engines/gargoyle/frotz/processor.h
+++ b/engines/gargoyle/frotz/processor.h
@@ -23,7 +23,6 @@
#ifndef GARGOYLE_FROTZ_PROCESSOR
#define GARGOYLE_FROTZ_PROCESSOR
-#include "gargoyle/frotz/buffer.h"
#include "gargoyle/frotz/err.h"
#include "gargoyle/frotz/mem.h"
#include "gargoyle/frotz/glk_interface.h"
@@ -37,6 +36,7 @@ namespace Frotz {
#define GET_PC(v) v = pcp - zmp
#define SET_PC(v) pcp = zmp + v
+#define TEXT_BUFFER_SIZE 200
enum string_type {
LOW_STRING, ABBREVIATION, HIGH_STRING, EMBEDDED_STRING, VOCABULARY
@@ -48,12 +48,8 @@ typedef void (Processor::*Opcode)();
/**
* Zcode processor
*/
-class Processor : public virtual Mem, public Errors, public GlkInterface {
+class Processor : public Errors, public GlkInterface, public virtual Mem {
private:
- Opcode op0_opcodes[16];
- Opcode op1_opcodes[16];
- static Opcode var_opcodes[64];
- static Opcode ext_opcodes[64];
int _finished;
zword zargs[8];
int zargc;
@@ -71,6 +67,17 @@ private:
static zchar ZSCII_TO_LATIN1[];
zchar *_decoded, *_encoded;
int _resolution;
+
+ // Buffer related fields
+ zchar _buffer[TEXT_BUFFER_SIZE];
+ size_t _bufPos;
+ bool _locked;
+ zchar _prevC;
+
+ Opcode op0_opcodes[16];
+ Opcode op1_opcodes[16];
+ static Opcode var_opcodes[64];
+ static Opcode ext_opcodes[64];
private:
/**
* \defgroup General support methods
@@ -146,6 +153,33 @@ private:
*/
/**
+ * Copy the contents of the text buffer to the output streams.
+ */
+ void flush_buffer();
+
+ /**
+ * High level output function.
+ */
+ void print_char(zchar c);
+
+ /**
+ * High level newline function.
+ */
+ void new_line();
+
+ /**
+ * Returns true if the buffer is empty
+ */
+ bool bufferEmpty() const { return !_bufPos; }
+
+ /**@}*/
+
+ /**
+ * \defgroup Input support methods
+ * @{
+ */
+
+ /**
* Check if the given key is an input terminator.
*/
bool is_terminator(zchar key);
diff --git a/engines/gargoyle/frotz/buffer.cpp b/engines/gargoyle/frotz/processor_buffer.cpp
index 7d9e64465b..be30bfe560 100644
--- a/engines/gargoyle/frotz/buffer.cpp
+++ b/engines/gargoyle/frotz/processor_buffer.cpp
@@ -20,8 +20,7 @@
*
*/
-#include "gargoyle/frotz/buffer.h"
-#include "gargoyle/frotz/frotz.h"
+#include "gargoyle/frotz/processor.h"
#include "common/algorithm.h"
#include "common/textconsole.h"
@@ -33,17 +32,13 @@ void stream_char(zchar) {}
void stream_word(const zchar *) {}
void stream_new_line(void) {}
-Buffer::Buffer() : _bufPos(0), _locked(false), _prevC('\0') {
- Common::fill(&_buffer[0], &_buffer[TEXT_BUFFER_SIZE], '\0');
-}
-
-void Buffer::flush() {
+void Processor::flush_buffer() {
/* Make sure we stop when flush_buffer is called from flush_buffer.
* Note that this is difficult to avoid as we might print a newline
* during flush_buffer, which might cause a newline interrupt, that
* might execute any arbitrary opcode, which might flush the buffer.
*/
- if (_locked || empty())
+ if (_locked || bufferEmpty())
return;
// Send the buffer to the output streams
@@ -58,14 +53,14 @@ void Buffer::flush() {
_prevC = '\0';
}
-void Buffer::printChar(zchar c) {
+void Processor::print_char(zchar c) {
static bool flag = false;
- if (g_vm->message || g_vm->ostream_memory || g_vm->enable_buffering) {
+ if (message || ostream_memory || enable_buffering) {
if (!flag) {
// Characters 0 and ZC_RETURN are special cases
if (c == ZC_RETURN) {
- newLine();
+ new_line();
return;
}
if (c == 0)
@@ -73,7 +68,7 @@ void Buffer::printChar(zchar c) {
// Flush the buffer before a whitespace or after a hyphen
if (c == ' ' || c == ZC_INDENT || c == ZC_GAP || (_prevC == '-' && c != '-'))
- flush();
+ flush_buffer();
// Set the flag if this is part one of a style or font change
if (c == ZC_NEW_FONT || c == ZC_NEW_STYLE)
@@ -95,8 +90,8 @@ void Buffer::printChar(zchar c) {
}
}
-void Buffer::newLine() {
- flush();
+void Processor::new_line() {
+ flush_buffer();
stream_new_line();
}
diff --git a/engines/gargoyle/frotz/processor_streams.cpp b/engines/gargoyle/frotz/processor_streams.cpp
index 5fe526fbe4..ae4dbaada1 100644
--- a/engines/gargoyle/frotz/processor_streams.cpp
+++ b/engines/gargoyle/frotz/processor_streams.cpp
@@ -28,7 +28,6 @@ namespace Frotz {
// TODO: Implement method stubs
static void os_scrollback_char(zchar) {}
static void os_scrollback_erase(zword) {}
-static void flush_buffer() {}
static void script_open() {}
static void script_close() {}
static void script_mssg_on() {}
diff --git a/engines/gargoyle/frotz/processor_text.cpp b/engines/gargoyle/frotz/processor_text.cpp
index e660ac1fd9..f6a82fb56e 100644
--- a/engines/gargoyle/frotz/processor_text.cpp
+++ b/engines/gargoyle/frotz/processor_text.cpp
@@ -26,8 +26,6 @@ namespace Gargoyle {
namespace Frotz {
// TODO: Replace method stubs
-static void new_line() {}
-static void print_char(zchar) {}
static void storeb(zword, zchar) {}
static void storew(zword, zword) {}