46 Companion zmachine.js (25/28)
else if (n === -1) this.screenOn = false;
else if (n === 3) {
if (this.mem3.length >= 16) throw new ZError('output stream 3 nested too deeply');
this.mem3.push({ table: o[1], len: 0 });
} else if (n === -3) {
const top = this.mem3.pop();
if (top) this.ww(top.table, top.len);
}
return; // stream 2 (transcript) and 4 are ignored
}
case 0x14: return; // input_stream
case 0x15: return; // sound_effect
case 0x16: { // read_char
this.waiting = { kind: 'key', store: this.mem[this.pc++] };
return;
}
case 0x17: { // scan_table
const [x, table, len, form = 0x82] = o;
const size = form & 0x7f;
const words = (form & 0x80) !== 0;
let found = 0;
for (let i = 0; i < len; i++) {
const a = table + i * size;
if ((words ? this.rw(a) : this.mem[a]) === x) { found = a; break; }
}
this.store(found);
return this.branch(found !== 0);
}
case 0x18: return this.store(~o[0]);
case 0x19: return this.call(o[0], o.slice(1), -1);
case 0x1a: return this.call(o[0], o.slice(1), -1);
case 0x1b: return this.tokenise(o[0], o[1], o[2] || 0, !!o[3]);
case 0x1c: { // encode_text
const [text, len, from, coded] = o;