27 Companion zmachine.js (6/28)

  pokeVar(n, v) {
    if (n === 0) {
      if (this.stack.length <= this.frameBase()) this.stack.push(u16(v));
      else this.stack[this.stack.length - 1] = u16(v);
    } else this.writeVar(n, v);
  }

  frameBase() { return this.frames.length ? this.frames[this.frames.length - 1].base : 0; }
  localsOf() {
    if (!this.frames.length) throw new ZError('no routine frame for a local variable');
    return this.frames[this.frames.length - 1].locals;
  }

  // ---------------------------------------------------------------- text

  zsciiToChar(z) {
    if (z === 13) return '\n';
    if (z >= 32 && z <= 126) return String.fromCharCode(z);
    if (z >= 155 && z < 155 + this.extra.length) return this.extra[z - 155];
    return '';
  }

  charToZscii(ch) {
    const c = ch.codePointAt(0);
    if (c === 10 || c === 13) return 13;
    if (c >= 32 && c <= 126) return c;
    return this.unicodeToZscii.get(ch) ?? 63; // '?'
  }
‹ PreviousReader file (.txt)Next ›