v86/examples/nodejs.js

48 lines
919 B
JavaScript
Raw Normal View History

2015-12-30 18:18:23 +01:00
#!/usr/bin/env node
2015-01-17 20:48:11 +01:00
"use strict";
var fs = require("fs");
2015-09-12 00:35:44 +02:00
var V86Starter = require("../build/libv86.js").V86Starter;
2015-01-17 20:48:11 +01:00
function readfile(path)
{
return new Uint8Array(fs.readFileSync(path)).buffer;
}
2015-09-12 00:35:44 +02:00
var bios = readfile(__dirname + "/../bios/seabios.bin");
2021-01-02 03:10:47 +01:00
var linux = readfile(__dirname + "/../images/linux4.iso");
2015-01-17 20:48:11 +01:00
process.stdin.setRawMode(true);
process.stdin.resume();
process.stdin.setEncoding("utf8");
2015-12-30 18:18:23 +01:00
console.log("Now booting, please stand by ...");
2015-01-17 20:48:11 +01:00
var emulator = new V86Starter({
bios: { buffer: bios },
cdrom: { buffer: linux },
autostart: true,
});
emulator.add_listener("serial0-output-char", function(chr)
{
2021-01-02 03:10:47 +01:00
if(chr <= "~")
{
2021-01-02 03:10:47 +01:00
process.stdout.write(chr);
}
2015-01-17 20:48:11 +01:00
});
process.stdin.on("data", function(c)
{
if(c === "\u0003")
{
// ctrl c
2015-12-30 21:00:37 +01:00
emulator.stop();
process.stdin.pause();
2015-01-17 20:48:11 +01:00
}
else
{
emulator.serial0_send(c);
}
});