Add Node support back
This commit is contained in:
parent
89e061d555
commit
2609e0debf
65
docs/samples/nodejs.js
Normal file
65
docs/samples/nodejs.js
Normal file
|
@ -0,0 +1,65 @@
|
|||
"use strict";
|
||||
|
||||
var fs = require("fs");
|
||||
var V86Starter = require("../../build/libv86.js").V86Starter;
|
||||
|
||||
function readfile(path)
|
||||
{
|
||||
return new Uint8Array(fs.readFileSync(path)).buffer;
|
||||
}
|
||||
|
||||
var bios = readfile(__dirname + "/../../bios/seabios.bin");
|
||||
var linux = readfile(__dirname + "/../../images/linux.iso");
|
||||
|
||||
var emulator = new V86Starter({
|
||||
bios: { buffer: bios },
|
||||
cdrom: { buffer: linux },
|
||||
autostart: true,
|
||||
});
|
||||
|
||||
emulator.add_listener("serial0-output-char", function(chr)
|
||||
{
|
||||
process.stdout.write(chr);
|
||||
});
|
||||
|
||||
process.stdin.setRawMode(true);
|
||||
process.stdin.resume();
|
||||
process.stdin.setEncoding("utf8");
|
||||
|
||||
var state;
|
||||
|
||||
process.stdin.on("data", function(c)
|
||||
{
|
||||
if(c === "\u0003")
|
||||
{
|
||||
// ctrl c
|
||||
process.exit();
|
||||
}
|
||||
else if(c === "\x1b\x4f\x51")
|
||||
{
|
||||
// f2
|
||||
emulator.save_state(function(err, s)
|
||||
{
|
||||
console.log("--- Saved ---");
|
||||
if(err)
|
||||
{
|
||||
throw err;
|
||||
}
|
||||
|
||||
state = s;
|
||||
});
|
||||
}
|
||||
else if(c === "\x1b\x4f\x52")
|
||||
{
|
||||
// f3
|
||||
if(state)
|
||||
{
|
||||
console.log("--- Restored ---");
|
||||
emulator.restore_state(state);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
emulator.serial0_send(c);
|
||||
}
|
||||
});
|
|
@ -614,22 +614,26 @@ V86Starter.prototype.serial0_send = function(data)
|
|||
if(typeof window !== "undefined")
|
||||
{
|
||||
window["V86Starter"] = V86Starter;
|
||||
|
||||
V86Starter.prototype["run"] = V86Starter.prototype.run;
|
||||
V86Starter.prototype["stop"] = V86Starter.prototype.stop;
|
||||
V86Starter.prototype["restart"] = V86Starter.prototype.restart;
|
||||
V86Starter.prototype["add_listener"] = V86Starter.prototype.add_listener;
|
||||
V86Starter.prototype["remove_listener"] = V86Starter.prototype.remove_listener;
|
||||
V86Starter.prototype["restore_state"] = V86Starter.prototype.restore_state;
|
||||
V86Starter.prototype["save_state"] = V86Starter.prototype.save_state;
|
||||
V86Starter.prototype["get_statistics"] = V86Starter.prototype.get_statistics;
|
||||
V86Starter.prototype["is_running"] = V86Starter.prototype.is_running;
|
||||
V86Starter.prototype["keyboard_send_scancodes"] = V86Starter.prototype.keyboard_send_scancodes;
|
||||
V86Starter.prototype["screen_make_screenshot"] = V86Starter.prototype.screen_make_screenshot;
|
||||
V86Starter.prototype["screen_set_scale"] = V86Starter.prototype.screen_set_scale;
|
||||
V86Starter.prototype["screen_go_fullscreen"] = V86Starter.prototype.screen_go_fullscreen;
|
||||
V86Starter.prototype["lock_mouse"] = V86Starter.prototype.lock_mouse;
|
||||
V86Starter.prototype["mouse_set_status"] = V86Starter.prototype.mouse_set_status;
|
||||
V86Starter.prototype["keyboard_set_status"] = V86Starter.prototype.keyboard_set_status;
|
||||
V86Starter.prototype["serial0_send"] = V86Starter.prototype.serial0_send;
|
||||
}
|
||||
else if(typeof module !== "undefined" && typeof module.exports !== "undefined")
|
||||
{
|
||||
module.exports["V86Starter"] = V86Starter;
|
||||
}
|
||||
|
||||
V86Starter.prototype["run"] = V86Starter.prototype.run;
|
||||
V86Starter.prototype["stop"] = V86Starter.prototype.stop;
|
||||
V86Starter.prototype["restart"] = V86Starter.prototype.restart;
|
||||
V86Starter.prototype["add_listener"] = V86Starter.prototype.add_listener;
|
||||
V86Starter.prototype["remove_listener"] = V86Starter.prototype.remove_listener;
|
||||
V86Starter.prototype["restore_state"] = V86Starter.prototype.restore_state;
|
||||
V86Starter.prototype["save_state"] = V86Starter.prototype.save_state;
|
||||
V86Starter.prototype["get_statistics"] = V86Starter.prototype.get_statistics;
|
||||
V86Starter.prototype["is_running"] = V86Starter.prototype.is_running;
|
||||
V86Starter.prototype["keyboard_send_scancodes"] = V86Starter.prototype.keyboard_send_scancodes;
|
||||
V86Starter.prototype["screen_make_screenshot"] = V86Starter.prototype.screen_make_screenshot;
|
||||
V86Starter.prototype["screen_set_scale"] = V86Starter.prototype.screen_set_scale;
|
||||
V86Starter.prototype["screen_go_fullscreen"] = V86Starter.prototype.screen_go_fullscreen;
|
||||
V86Starter.prototype["lock_mouse"] = V86Starter.prototype.lock_mouse;
|
||||
V86Starter.prototype["mouse_set_status"] = V86Starter.prototype.mouse_set_status;
|
||||
V86Starter.prototype["keyboard_set_status"] = V86Starter.prototype.keyboard_set_status;
|
||||
V86Starter.prototype["serial0_send"] = V86Starter.prototype.serial0_send;
|
||||
|
|
Loading…
Reference in a new issue