Spaces:
Runtime error
Runtime error
File size: 1,291 Bytes
8df6da4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
#!/usr/bin/env node
import fs from "node:fs";
import url from "node:url";
import { V86 } from "../build/libv86.mjs";
const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
console.log("Use F2 to save the state and F3 to restore.");
process.stdin.setRawMode(true);
process.stdin.resume();
process.stdin.setEncoding("utf8");
console.log("Now booting, please stand by ...");
var emulator = new V86({
bios: { url: __dirname + "/../bios/seabios.bin" },
cdrom: { url: __dirname + "/../images/linux4.iso" },
autostart: true,
});
emulator.add_listener("serial0-output-byte", function(byte)
{
var chr = String.fromCharCode(byte);
if(chr <= "~")
{
process.stdout.write(chr);
}
});
var state;
process.stdin.on("data", async function(c)
{
if(c === "\u0003")
{
// ctrl c
emulator.destroy();
process.stdin.pause();
}
else if(c === "\x1b\x4f\x51")
{
// f2
state = await emulator.save_state();
console.log("--- Saved ---");
}
else if(c === "\x1b\x4f\x52")
{
// f3
if(state)
{
console.log("--- Restored ---");
await emulator.restore_state(state);
}
}
else
{
emulator.serial0_send(c);
}
});
|