tape-timing.mjs (1961B)
1 // Sépare LOAD et RUN d'une cassette pour voir ce qui prend du temps. 2 // node test/tape-timing.mjs <fichier.k7> [base-url] [prefix] 3 import { open, sleep } from './cdp.mjs'; 4 5 const k7 = process.argv[2] ?? 'world-war-3.k7'; 6 const base = process.argv[3] ?? 'http://127.0.0.1:8195'; 7 const prefix = process.argv[4] ?? '/tmp/tt'; 8 const url = base + '/?game=exl100&rom=/roms/exl100.zip&exelmem=0&args=' + 9 encodeURIComponent('--tape /roms/cartridges/exelbasic.bin --tape /roms/tapes/' + k7); 10 const page = await open(url, { width: 900, height: 1100 }); 11 const ev = (type, k, code, vk, mods = 0) => 12 page.send('Input.dispatchKeyEvent', { type, key: k, code, windowsVirtualKeyCode: vk, modifiers: mods }); 13 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); }; 14 const quote = async () => { 15 await ev('keyDown', 'Shift', 'ShiftLeft', 16); await sleep(80); 16 await ev('keyDown', '"', 'Digit3', 51, 8); await sleep(80); await ev('keyUp', '"', 'Digit3', 51, 8); await sleep(80); 17 await ev('keyUp', 'Shift', 'ShiftLeft', 16); await sleep(400); 18 }; 19 const type = async (s) => { for (const ch of s) { if (ch === '"') await quote(); else if (/[0-9]/.test(ch)) await key(ch, 'Digit' + ch, ch.charCodeAt(0)); else await key(ch.toLowerCase(), 'Key' + ch, ch.charCodeAt(0)); } }; 20 await sleep(9000); 21 const t0 = Date.now(); 22 await type('LOAD"1"'); await key('Enter', 'Enter', 13); 23 await sleep(3000); await page.screenshot(prefix + '-1-load-3s.png'); 24 await key('Escape', 'Escape', 27); await sleep(500); 25 await type('RUN'); await key('Enter', 'Enter', 13); 26 await sleep(2000); await page.screenshot(prefix + '-2-run-2s.png'); 27 await sleep(18000); await page.screenshot(prefix + '-3-run-20s.png'); 28 await sleep(30000); await page.screenshot(prefix + '-4-run-50s.png'); 29 console.log('captures', prefix + '-*.png ; durée', Math.round((Date.now() - t0) / 1000), 's'); 30 page.close();