Permalink
Browse files

GLK: FROTZ: Fixes for saving and restoring in V6 games

  • Loading branch information...
dreammaster committed Feb 10, 2019
1 parent dbfc657 commit 0a08d2e18b202cc0167c5f9746c9707d5efe86ef
@@ -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) {
}

@@ -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 @@ class Mem : public Header, public virtual UserOptions {
* Constructor
*/
Mem();

/**
* Destructor
*/
virtual ~Mem() {}

/**
@@ -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);
@@ -1734,7 +1734,10 @@ class Processor : public GlkInterface, public virtual Mem {
/**
* 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
@@ -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]);
@@ -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);
}

@@ -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;

0 comments on commit 0a08d2e

Please sign in to comment.