48 Companion zmachine.js (27/28)

        case 0x04: return this.store(o[0] === 1 || o[0] === 4 ? 1 : 0); // set_font
        case 0x09: { // save_undo
          const storeVar = this.mem[this.pc++];
          this.undoState = { snap: this.snapshot(), storeVar };
          return this.writeVar(storeVar, 1);
        }
        case 0x0a: { // restore_undo
          const storeVar = this.mem[this.pc++];
          if (!this.undoState) return this.writeVar(storeVar, 0);
          const u = this.undoState;
          this.load(u.snap);
          this.undoState = null;
          return this.writeVar(u.storeVar, 2);
        }
        case 0x0b: return this.print(String.fromCodePoint(o[0]));
        case 0x0c: return this.store(o[0] >= 32 && o[0] <= 0xffff ? 3 : 0); // check_unicode
        case 0x0d: return; // set_true_colour
        default: return; // other extended opcodes (mostly v6) are ignored
      }
    }
    throw new ZError(`unknown opcode ${form} ${num}`);
  }

  // In-game SAVE/RESTORE use one slot per game, kept by the server. The server
  // copies this.saveSlot into its session file.
  doSave() {
    // The slot is resumed like a restore of this very instruction, so remember
    // where its result goes.
    const v = this.version;
    const at = this.pc; // points at the branch byte (v3) or store byte (v4+)
    this.saveSlot = { snap: this.snapshot(), at, v };
    return true;
  }
‹ PreviousReader file (.txt)Next ›