30 Companion zmachine.js (9/28)
printUpper(s) {
for (const ch of s) {
if (ch === '\n') { this.cursor.row++; this.cursor.col = 1; continue; }
const r = this.cursor.row - 1;
if (r < 0 || r >= Math.max(this.upperHeight, 1) || this.cursor.col > this.screenWidth) {
this.cursor.col++;
continue;
}
while (this.upper.length <= r) this.upper.push([]);
this.upper[r][this.cursor.col - 1] = ch;
this.cursor.col++;
}
}
// The status line / upper window as text lines.
upperText() {
const lines = [];
for (let r = 0; r < Math.max(this.upperHeight, this.version <= 3 ? 1 : 0); r++) {
const row = this.upper[r] || [];
const line = Array.from({ length: row.length }, (_, i) => row[i] || ' ').join('').replace(/\s+/g, ' ').trim();
if (line) lines.push(line);
}
return lines;
}
showStatusV3() {
const locObj = this.readVar(16);
const name = locObj ? this.objectName(locObj) : '';
let right;
if (this.version === 3 && this.mem[0x01] & 0x02) {
const h = s16(this.readVar(17));
const m = s16(this.readVar(18));
right = `Time: ${((h + 11) % 12) + 1}:${String(m).padStart(2, '0')} ${h < 12 ? 'am' : 'pm'}`;
} else {
right = `Score: ${s16(this.readVar(17))} Moves: ${s16(this.readVar(18))}`;
}
this.statusV3 = `${name} ${right}`;
this.upper[0] = this.statusV3.split('');
}
// ---------------------------------------------------------------- objects