47 Companion zmachine.js (26/28)

          const bytes = this.encodeWord(this.mem.subarray(text + from, text + from + len));
          bytes.forEach((b, i) => (this.mem[coded + i] = b));
          return;
        }
        case 0x1d: { // copy_table
          const [first, second, size] = o;
          const n = Math.abs(s16(size));
          if (second === 0) { for (let i = 0; i < n; i++) this.mem[first + i] = 0; return; }
          if (s16(size) < 0) for (let i = 0; i < n; i++) this.mem[second + i] = this.mem[first + i];
          else this.mem.set(this.mem.slice(first, first + n), second);
          return;
        }
        case 0x1e: { // print_table
          const [text, width, height = 1, skip = 0] = o;
          let a = text;
          for (let r = 0; r < height; r++) {
            if (r) this.print('\n');
            let line = '';
            for (let c = 0; c < width; c++) line += this.zsciiToChar(this.mem[a++]);
            this.print(line);
            a += skip;
          }
          return;
        }
        case 0x1f: return this.branch(o[0] <= this.frames[this.frames.length - 1].argc);
      }
    } else if (form === 'ext') {
      switch (num) {
        case 0x00: return this.store(this.doSave() ? 1 : 0);
        case 0x01: return this.store(this.doRestore() ? 2 : 0);
        case 0x02: { const n = s16(o[1]); return this.store(n >= 0 ? o[0] << n : o[0] >>> -n); }
        case 0x03: { const n = s16(o[1]); return this.store(n >= 0 ? s16(o[0]) << n : s16(o[0]) >> -n); }
‹ PreviousReader file (.txt)Next ›