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-exl100-cmd.mjs (1808B)


      1 // EXL 100 + CROS 16K sur un volume .cram donné : tape des commandes (séparées par ;) et capture après chacune.
      2 //   node test/cram-exl100-cmd.mjs <volume.cram> "DIR;REN" [base-url] [prefix]
      3 import { open, sleep } from './cdp.mjs';
      4 import { readFileSync } from 'node:fs';
      5 
      6 const img = readFileSync(process.argv[2]);
      7 const cmds = (process.argv[3] ?? 'DIR').split(';');
      8 const base = process.argv[4] ?? 'http://127.0.0.1:8195';
      9 const prefix = process.argv[5] ?? '/tmp/xc';
     10 const page = await open(base + '/?game=exl100&rom=/roms/exl100.zip&exelmem=1', { width: 900, height: 1100 });
     11 await page.evaluate(`localStorage.setItem('exl100.cram.exl100', ${JSON.stringify(Buffer.from(img).toString('base64'))})`);
     12 await page.evaluate('location.reload()');
     13 const ev = (type, k, code, vk, mods = 0) =>
     14   page.send('Input.dispatchKeyEvent', { type, key: k, code, windowsVirtualKeyCode: vk, modifiers: mods });
     15 const key = async (k, code, vk, hold = 80, gap = 400) => { await ev('keyDown', k, code, vk); await sleep(hold); await ev('keyUp', k, code, vk); await sleep(gap); };
     16 const type = async (s) => {
     17   for (const ch of s) {
     18     if (ch === ' ') await key(' ', 'Space', 32);
     19     else if (ch === '.') await key('.', 'Period', 190);
     20     else if (/[0-9]/.test(ch)) await key(ch, 'Digit' + ch, ch.charCodeAt(0));
     21     else await key(ch.toLowerCase(), 'Key' + ch.toUpperCase(), ch.toUpperCase().charCodeAt(0));
     22   }
     23 };
     24 await sleep(9000);
     25 let n = 0;
     26 for (const c of cmds) {
     27   if (c === 'ESC') await key('Escape', 'Escape', 27);
     28   else if (c === 'ENTER') await key('Enter', 'Enter', 13);
     29   else { await type(c); await key('Enter', 'Enter', 13); }
     30   await sleep(1800);
     31   await page.screenshot(`${prefix}-${n++}-${c.replace(/[^A-Za-z0-9]+/g, '_').slice(0, 12)}.png`);
     32 }
     33 console.log('captures', prefix + '-*.png');
     34 page.close();