// headless runner: node run.mjs flash.bin [seconds] [--psram] import fs from 'fs'; import { ESP32 } from '../web/js/soc.js'; const romDir = process.env.ROMDIR || new URL('../web/rom/', import.meta.url).pathname; const [, , flashPath, secs = '5', ...flags] = process.argv; const soc = new ESP32({ log: console.log }); soc.loadRoms(fs.readFileSync(romDir + 'esp32-v3-rom.bin'), fs.readFileSync(romDir + 'esp32-v3-rom-app.bin')); soc.setFlash(fs.readFileSync(flashPath)); soc.enablePsram(flags.includes('--psram')); let out = ''; soc.onUart = (n, b) => { if (n === 0) process.stdout.write(String.fromCharCode(b)); }; soc.reset('power'); const t0 = Date.now(); const limitNs = parseFloat(secs) * 1e9; let instr = 0; while (soc.timeNs < limitNs) { instr += soc.run(200000); if (soc.idleForever) break; } const dt = (Date.now() - t0) / 1000; console.log(`\n[emu] virtual ${(soc.timeNs / 1e9).toFixed(3)}s, ${instr} instr, wall ${dt.toFixed(2)}s, ${(instr / dt / 1e6).toFixed(1)} MIPS, pc0=${(soc.cpus[0].pc >>> 0).toString(16)} pc1=${(soc.cpus[1].pc >>> 0).toString(16)}`);