exl100

Émulateur Exelvision EXL 100 (1984) dans le navigateur : dsp-cpp en WebAssembly, cartouches et cassettes BASIC
git clone https://git.schurger.org/exl100.git
Log | Files | Refs | README

cram-autostart.mjs (2388B)


      1 // Volume Exelmémoire sur l'EXELTEL : Périphériques -> Autostart (5e). Captures + trace PC.
      2 // Le rythme est calé sur les trames émulées (lignes « FRnnnn » de la build de debug), pas sur l'horloge :
      3 // la build de debug tourne au ralenti pendant le démarrage.
      4 //   node test/cram-autostart.mjs <volume.cram> [base-url] [prefix]
      5 import { open, sleep } from './cdp.mjs';
      6 import { readFileSync, writeFileSync } from 'node:fs';
      7 
      8 const img = readFileSync(process.argv[2]);
      9 const base = process.argv[3] ?? 'http://127.0.0.1:8194';
     10 const prefix = process.argv[4] ?? '/tmp/as';
     11 const page = await open(base + '/?game=exeltel&rom=/roms/exeltel.zip', { width: 900, height: 1100 });
     12 await page.evaluate(`localStorage.setItem('exl100.cram.exeltel', ${JSON.stringify(Buffer.from(img).toString('base64'))})`);
     13 await page.evaluate('location.reload()');
     14 const frame = () => {
     15   for (let i = page.logs.length - 1; i >= 0; i--) {
     16     const m = /FR(\d+) PC=/.exec(page.logs[i]);
     17     if (m) return Number(m[1]);
     18   }
     19   return -1;
     20 };
     21 const untilFrame = async (n) => { while (frame() < n) await sleep(100); };
     22 const frames = async (n) => untilFrame(frame() + n);
     23 const key = async (k, code, vk) => {
     24   await page.send('Input.dispatchKeyEvent', { type: 'keyDown', key: k, code, windowsVirtualKeyCode: vk });
     25   await frames(4);
     26   await page.send('Input.dispatchKeyEvent', { type: 'keyUp', key: k, code, windowsVirtualKeyCode: vk });
     27   await frames(30);
     28 };
     29 const down = () => key('ArrowDown', 'ArrowDown', 40);
     30 const enter = () => key('Enter', 'Enter', 13);
     31 await untilFrame(Number(process.env.BOOT_FRAMES ?? 300));
     32 await down(); await down(); await down(); await enter(); await frames(60);    // Périphériques
     33 await down(); await down(); await down(); await down();                       // Autostart (5e)
     34 await page.screenshot(prefix + '-0-hl.png');
     35 const launch = frame();
     36 await enter(); await frames(100);
     37 await page.screenshot(prefix + '-1.png');
     38 await frames(400);
     39 await page.screenshot(prefix + '-2.png');
     40 writeFileSync(prefix + '.log', page.logs.join('\n') + '\n');
     41 const fr = page.logs.map((l) => l.replace(/^\[\w+\]\s*/, '')).filter((l) => /^FR\d+ PC=/.test(l));
     42 console.log('lancement à la trame', launch, '; frames PC en CRAM :', fr.filter((l) => /PC=[89ab]/.test(l)).length, '/', fr.length,
     43             '; derniers :', fr.slice(-10).map((l) => l.split('PC=')[1]).join(' '));
     44 page.close();