41 Companion zmachine.js (20/28)

  exec(form, num, o) {
    const v = this.version;
    if (form === '2op') {
      const [a, b] = o;
      switch (num) {
        case 0x01: return this.branch(o.slice(1).some((x) => x === a));
        case 0x02: return this.branch(s16(a) < s16(b));
        case 0x03: return this.branch(s16(a) > s16(b));
        case 0x04: { const x = s16(this.peekVar(a)) - 1; this.pokeVar(a, x); return this.branch(s16(x) < s16(b)); }
        case 0x05: { const x = s16(this.peekVar(a)) + 1; this.pokeVar(a, x); return this.branch(s16(x) > s16(b)); }
        case 0x06: return this.branch(a !== 0 && this.parent(a) === b);
        case 0x07: return this.branch((a & b) === b);
        case 0x08: return this.store(a | b);
        case 0x09: return this.store(a & b);
        case 0x0a: return this.branch(a !== 0 && this.testAttr(a, b));
        case 0x0b: if (a) this.setAttr(a, b, true); return;
        case 0x0c: if (a) this.setAttr(a, b, false); return;
        case 0x0d: return this.pokeVar(a, b);
        case 0x0e: if (a && b) this.insertObj(a, b); return;
        case 0x0f: return this.store(this.rw(u16(a + 2 * s16(b))));
        case 0x10: return this.store(this.mem[u16(a + s16(b))]);
        case 0x11: {
          if (!a) return this.store(0);
          const p = this.findProp(a, b);
          if (!p) return this.store(this.rw(this.objects + 2 * (b - 1)));
          return this.store(p.len === 1 ? this.mem[p.addr] : this.rw(p.addr));
        }
‹ PreviousReader file (.txt)Next ›