boot.mjs (1938B)
1 // Test sans navigateur : démarre la ROM, vérifie le curseur K, charge le .P passé en 2 // argument (ou aucun) et affiche l'écran en texte. 3 // node test/boot.mjs [fichier.p] [secondes émulées] 4 import { readFileSync } from 'node:fs'; 5 import { fileURLToPath } from 'node:url'; 6 import { dirname, join } from 'node:path'; 7 import { ZX81, FRAME_T } from '../web/zx81.js'; 8 9 const here = dirname(fileURLToPath(import.meta.url)); 10 const rom = new Uint8Array(readFileSync(join(here, '..', 'web', 'zx81.rom'))); 11 const m = new ZX81(rom); 12 13 const runFrames = (n) => { for (let i = 0; i < n; i++) m.run(FRAME_T); }; 14 // Appuie sur une touche pendant quelques trames puis la relâche. 15 const press = (...names) => { 16 for (const k of names) m.keyDown(k); 17 runFrames(4); 18 for (const k of names) m.keyUp(k); 19 runFrames(4); 20 }; 21 22 runFrames(130); 23 const boot = m.screenText(); 24 const kCursor = boot.split('\n')[23].startsWith('k'); 25 console.log(`Démarrage : ${m.frames} trames, curseur K ${kCursor ? 'présent' : 'ABSENT'}`); 26 if (!kCursor) { console.log(boot); process.exit(1); } 27 28 const file = process.argv[2]; 29 if (file) { 30 m.tape = new Uint8Array(readFileSync(file)); 31 let loaded = false; 32 m.onLoad = () => { loaded = true; }; 33 press('J'); // LOAD 34 press('SHIFT', 'P'); press('SHIFT', 'P'); // "" 35 press('NEWLINE'); 36 runFrames(40); 37 console.log(`LOAD intercepté : ${loaded ? 'oui' : 'NON'}`); 38 if (!loaded) { console.error(m.screenText()); process.exitCode = 1; } 39 const secs = Number(process.argv[3] ?? 3); 40 runFrames(Math.round(secs * 50)); 41 } else { 42 // Tape PRINT 2+2 puis NEWLINE 43 press('P'); press('2'); press('SHIFT', 'K'); press('2'); press('NEWLINE'); 44 runFrames(80); 45 } 46 console.log('+' + '-'.repeat(32) + '+'); 47 for (const l of m.screenText().split('\n')) console.log('|' + l + '|'); 48 console.log('+' + '-'.repeat(32) + '+'); 49 console.log(`${m.frames} trames, ${(m.tstates / 3250000).toFixed(2)} s émulées`);