Download tools/ps2dbg.mjs from HelloSun/esp32emu: direct link, hf CLI and curl.
- Browser
- Download file 2.92 kB
-
https://huggingface.co/spaces/HelloSun/esp32emu/resolve/main/tools/ps2dbg.mjs
- Command line
-
hf download hf://spaces/HelloSun/esp32emu/tools/ps2dbg.mjs
-
curl -L -o ps2dbg.mjs https://huggingface.co/spaces/HelloSun/esp32emu/resolve/main/tools/ps2dbg.mjs
2.92 kB
| import fs from 'fs'; | |
| import { createESP32 } from '../web/js/soc.js'; | |
| const romDir = new URL('../web/rom/', import.meta.url).pathname; | |
| const wasmBytes = fs.readFileSync(new URL('../wasm/xtensa.wasm', import.meta.url)); | |
| const soc = await createESP32({ wasmBytes }); | |
| soc.loadRoms(fs.readFileSync(romDir + 'esp32-v3-rom.bin'), fs.readFileSync(romDir + 'esp32-v3-rom-app.bin')); | |
| soc.setFlash(fs.readFileSync(process.argv[2])); soc.enablePsram(false); | |
| soc.onUart = (n, b) => process.stdout.write(String.fromCharCode(b)); | |
| soc.reset('power'); | |
| const kb = soc.ps2.kbd; | |
| const T = () => (soc.timeNs / 1e6).toFixed(2) + 'ms'; | |
| const oc = kb.command.bind(kb); kb.command = (b) => { console.log(T(), '[cmd]', b.toString(16)); const r = oc(b); console.log(T(), ' txq', kb.txq.map(x=>x.toString(16))); return r; }; | |
| const ot = kb.tryTx.bind(kb); kb.tryTx = () => { console.log(T(), '[tryTx] state', kb.state, 'clk', soc.gpio.level(33), 'dat', soc.gpio.level(32), 'q', kb.txq.length); return ot(); }; | |
| const ow = soc.rtc.ulpWake.bind(soc.rtc); soc.rtc.ulpWake = () => { const m=(i)=>soc.rtcSlow32[0x200+i]&0xffff; console.log(T(), '[ulp wake] RX0', m(8), 'DATAIN0', m(12).toString(16), 'timeout0', m(10), 'rxen0', m(14)); return ow(); }; | |
| let lastc = -1; const tl=[]; | |
| const ocl = kb.onClk.bind(kb); kb.onClk = (l) => { const t = soc.nowNs; if (false) console.log(((t/1e3)|0)+'us onClk', l, 'fall', ((kb.clkFallNs/1e3)|0), 'state', kb.state, 'driving', kb.driving, 'dat', soc.gpio.level(32)); return ocl(l); }; | |
| soc.gpio.listeners.push((n, l) => { if ((n===33||n===32) && false) tl.push(`${(soc.timeNs/1e3-428000).toFixed(1)}us ${n===33?'CLK':'DAT'}=${l} ulp.t=${((soc.ulp.tNs)/1e3-428000).toFixed(1)} pc=${soc.ulp.pc} R=${soc.ulp.reg} stage=${soc.ulp.stage}`); if ((n === 33 || n === 32) && soc.timeNs > 0.4e9 && soc.timeNs < 0.9e9 && n === 33 && l !== lastc) { lastc = l; } }); | |
| let sent=false; let dumped=false; while (soc.timeNs < 4.0e9) { soc.run(20000); if (!dumped && soc.timeNs > 3.51e9) { dumped=true; for (const c of soc.cpus) console.log('cpu'+c.id, 'pc', (c.pc>>>0).toString(16), 'ps', c.ps.toString(16), 'intenable', (c.intenable>>>0).toString(16), 'pins', (c.intPins>>>0).toString(16), 'intset', (c.intSet>>>0).toString(16), 'halted', c.halted, 'pending', c.pendingLevel()); const mm=(i)=>soc.rtcSlow32[0x200+i]&0xffff; console.log('mem', Array.from({length:16},(_,i)=>mm(i).toString(16)).join(' ')); console.log('map1[46]', soc.intMap[1][46], 'map0[46]', soc.intMap[0][46], 'src46', soc.srcLevel[46], 'rtc raw', soc.rtc.intRaw, 'ena', soc.rtc.intEna); } if (!sent && soc.timeNs > 3.5e9) { sent = true; console.log(T(), 'send KeyH'); kb.key('KeyH', true); setTimeout(()=>{},0); soc.scheduleIn(50e6, () => kb.key('KeyH', false)); } } | |
| console.log(tl.join('\n')); | |
| console.log('ulp running', soc.ulp.running, 'pc', soc.ulp.pc, 'rtcmem', Array.from(soc.rtcSlow32.slice(0x200, 0x210)).map(x => (x & 0xffff).toString(16)).join(' ')); | |