mirror of
https://github.com/copy/v86.git
synced 2025-12-31 12:33:15 +00:00
emulator.stop sometimes works (when the GC can figure out that .start() is unreachable and nothing can call into the instance). However, some resources, such as any WebSocket connection, need to be closed manually.
48 lines
943 B
JavaScript
Executable file
48 lines
943 B
JavaScript
Executable file
#!/usr/bin/env node
|
|
"use strict";
|
|
|
|
var fs = require("fs");
|
|
var V86 = require("../build/libv86.js").V86;
|
|
|
|
function readfile(path)
|
|
{
|
|
return new Uint8Array(fs.readFileSync(path)).buffer;
|
|
}
|
|
|
|
var bios = readfile(__dirname + "/../bios/seabios.bin");
|
|
var linux = readfile(__dirname + "/../images/linux4.iso");
|
|
|
|
process.stdin.setRawMode(true);
|
|
process.stdin.resume();
|
|
process.stdin.setEncoding("utf8");
|
|
|
|
console.log("Now booting, please stand by ...");
|
|
|
|
var emulator = new V86({
|
|
bios: { buffer: bios },
|
|
cdrom: { buffer: linux },
|
|
autostart: true,
|
|
});
|
|
|
|
emulator.add_listener("serial0-output-byte", function(byte)
|
|
{
|
|
var chr = String.fromCharCode(byte);
|
|
if(chr <= "~")
|
|
{
|
|
process.stdout.write(chr);
|
|
}
|
|
});
|
|
|
|
process.stdin.on("data", function(c)
|
|
{
|
|
if(c === "\u0003")
|
|
{
|
|
// ctrl c
|
|
emulator.destroy();
|
|
process.stdin.pause();
|
|
}
|
|
else
|
|
{
|
|
emulator.serial0_send(c);
|
|
}
|
|
});
|