aboutsummaryrefslogtreecommitdiff
path: root/engines/glk
diff options
context:
space:
mode:
authorPaul Gilbert2019-02-10 11:19:18 -0800
committerPaul Gilbert2019-02-10 11:19:18 -0800
commit0a08d2e18b202cc0167c5f9746c9707d5efe86ef (patch)
treec472b59e69e6347481c9289ae64eee0b29fb4aff /engines/glk
parentdbfc657a2c305946483e60d8bd68bb40575fb3a4 (diff)
downloadscummvm-rg350-0a08d2e18b202cc0167c5f9746c9707d5efe86ef.tar.gz
scummvm-rg350-0a08d2e18b202cc0167c5f9746c9707d5efe86ef.tar.bz2
scummvm-rg350-0a08d2e18b202cc0167c5f9746c9707d5efe86ef.zip
GLK: FROTZ: Fixes for saving and restoring in V6 games
Diffstat (limited to 'engines/glk')
-rw-r--r--engines/glk/frotz/mem.cpp2
-rw-r--r--engines/glk/frotz/mem.h8
-rw-r--r--engines/glk/frotz/processor.cpp12
-rw-r--r--engines/glk/frotz/processor.h5
-rw-r--r--engines/glk/frotz/processor_buffer.cpp2
-rw-r--r--engines/glk/frotz/processor_streams.cpp3
-rw-r--r--engines/glk/frotz/quetzal.cpp4
7 files changed, 23 insertions, 13 deletions
diff --git a/engines/glk/frotz/mem.cpp b/engines/glk/frotz/mem.cpp
index ea3ca183c7..32e3ab3159 100644
--- a/engines/glk/frotz/mem.cpp
+++ b/engines/glk/frotz/mem.cpp
@@ -29,7 +29,7 @@ namespace Glk {
namespace Frotz {
Mem::Mem() : story_fp(nullptr), story_size(0), first_undo(nullptr), last_undo(nullptr),
- curr_undo(nullptr), undo_mem(nullptr), zmp(nullptr), prev_zmp(nullptr),
+ curr_undo(nullptr), undo_mem(nullptr), zmp(nullptr), pcp(nullptr), prev_zmp(nullptr),
undo_diff(nullptr), undo_count(0), reserve_mem(0) {
}
diff --git a/engines/glk/frotz/mem.h b/engines/glk/frotz/mem.h
index c58ef658e4..3a927e25b4 100644
--- a/engines/glk/frotz/mem.h
+++ b/engines/glk/frotz/mem.h
@@ -36,13 +36,15 @@ namespace Frotz {
#define SET_BYTE(addr,v) zmp[addr] = v
#define LOW_BYTE(addr,v) v = zmp[addr]
+typedef uint offset_t;
+
/**
* Stores undo information
*/
struct undo_struct {
undo_struct *next;
undo_struct *prev;
- long pc;
+ offset_t pc;
long diff_size;
zword frame_count;
zword stack_size;
@@ -150,6 +152,10 @@ public:
* Constructor
*/
Mem();
+
+ /**
+ * Destructor
+ */
virtual ~Mem() {}
/**
diff --git a/engines/glk/frotz/processor.cpp b/engines/glk/frotz/processor.cpp
index b9631c85e4..eebcc606d2 100644
--- a/engines/glk/frotz/processor.cpp
+++ b/engines/glk/frotz/processor.cpp
@@ -293,7 +293,7 @@ void Processor::interpret() {
}
void Processor::call(zword routine, int argc, zword *args, int ct) {
- long pc;
+ uint32 pc;
zword value;
zbyte count;
int i;
@@ -357,7 +357,7 @@ void Processor::call(zword routine, int argc, zword *args, int ct) {
}
void Processor::ret(zword value) {
- long pc;
+ offset_t pc;
int ct;
if (_sp > _fp)
@@ -369,7 +369,7 @@ void Processor::ret(zword value) {
_frameCount--;
_fp = _stack + 1 + *_sp++;
pc = *_sp++;
- pc = ((long)*_sp++ << 9) | pc;
+ pc = ((offset_t)*_sp++ << 9) | pc;
SET_PC(pc);
@@ -385,7 +385,7 @@ void Processor::ret(zword value) {
}
void Processor::branch(bool flag) {
- long pc;
+ offset_t pc;
zword offset;
zbyte specifier;
zbyte off1;
@@ -539,12 +539,12 @@ void Processor::z_check_arg_count() {
}
void Processor::z_jump() {
- long pc;
+ offset_t pc;
GET_PC(pc);
pc += (short)zargs[0] - 2;
- if ((uint)pc >= story_size)
+ if (pc >= story_size)
runtimeError(ERR_ILL_JUMP_ADDR);
SET_PC(pc);
diff --git a/engines/glk/frotz/processor.h b/engines/glk/frotz/processor.h
index 83d24433cf..e992a78100 100644
--- a/engines/glk/frotz/processor.h
+++ b/engines/glk/frotz/processor.h
@@ -1734,7 +1734,10 @@ public:
/**
* Return the current program execution offset
*/
- uint getPC() const { return pcp - zmp; }
+ uint getPC() const {
+ assert(pcp);
+ return pcp - zmp;
+ }
/**
* Set the program execution offset
diff --git a/engines/glk/frotz/processor_buffer.cpp b/engines/glk/frotz/processor_buffer.cpp
index 65f1fdacb5..9473411b51 100644
--- a/engines/glk/frotz/processor_buffer.cpp
+++ b/engines/glk/frotz/processor_buffer.cpp
@@ -167,7 +167,7 @@ void Processor::runtimeError(ErrorCode errNum) {
if ((_err_report_mode == ERR_REPORT_ALWAYS)
|| (_err_report_mode == ERR_REPORT_ONCE && wasfirst)) {
- long pc;
+ offset_t pc;
GET_PC(pc);
print_string("Warning: ");
print_string(ERR_MESSAGES[errNum - 1]);
diff --git a/engines/glk/frotz/processor_streams.cpp b/engines/glk/frotz/processor_streams.cpp
index 067708fb23..aedec2f6cf 100644
--- a/engines/glk/frotz/processor_streams.cpp
+++ b/engines/glk/frotz/processor_streams.cpp
@@ -535,9 +535,10 @@ void Processor::z_restart() {
_frameCount = 0;
if (h_version != V6 && h_version != V9) {
- long pc = (long)h_start_pc;
+ offset_t pc = (offset_t)h_start_pc;
SET_PC(pc);
} else {
+ SET_PC(0);
call(h_start_pc, 0, nullptr, 0);
}
diff --git a/engines/glk/frotz/quetzal.cpp b/engines/glk/frotz/quetzal.cpp
index 53de2933e5..e025b2bcc7 100644
--- a/engines/glk/frotz/quetzal.cpp
+++ b/engines/glk/frotz/quetzal.cpp
@@ -53,7 +53,7 @@ bool Quetzal::read_long(Common::ReadStream *f, uint *result) {
bool Quetzal::save(Common::WriteStream *svf, Processor *proc, const Common::String &desc) {
Processor &p = *proc;
uint ifzslen = 0, cmemlen = 0, stkslen = 0, descLen = 0;
- uint pc;
+ offset_t pc;
zword i, j, n;
zword nvars, nargs, nstk;
zbyte var;
@@ -214,7 +214,7 @@ bool Quetzal::save(Common::WriteStream *svf, Processor *proc, const Common::Stri
int Quetzal::restore(Common::SeekableReadStream *svf, Processor *proc) {
Processor &p = *proc;
uint ifzslen, currlen, tmpl;
- uint pc;
+ offset_t pc;
zword i, tmpw;
int fatal = 0; // Set to -1 when errors must be fatal.
zbyte skip, progress = GOT_NONE;