diff --git a/examples/nodejs.js b/examples/nodejs.js index 20e9b465..546cb365 100755 --- a/examples/nodejs.js +++ b/examples/nodejs.js @@ -1,4 +1,4 @@ -#!/bin/env node +#!/usr/bin/env node "use strict"; var fs = require("fs"); @@ -9,8 +9,6 @@ function readfile(path) return new Uint8Array(fs.readFileSync(path)).buffer; } -console.log("Use F2 to save the state and F3 to restore."); - var bios = readfile(__dirname + "/../bios/seabios.bin"); var linux = readfile(__dirname + "/../images/linux.iso"); @@ -18,6 +16,11 @@ process.stdin.setRawMode(true); process.stdin.resume(); process.stdin.setEncoding("utf8"); +var boot_start = Date.now(); +var booted = false; + +console.log("Now booting, please stand by ..."); + var emulator = new V86Starter({ bios: { buffer: bios }, cdrom: { buffer: linux }, @@ -36,12 +39,6 @@ emulator.add_listener("serial0-output-char", function(chr) process.stdout.write(chr); }); -console.log("Now booting, please stand by ..."); - -var boot_start = Date.now(); -var booted = false; -var state; - process.stdin.on("data", function(c) { if(c === "\u0003") @@ -49,29 +46,6 @@ process.stdin.on("data", function(c) // 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); diff --git a/examples/nodejs_state.js b/examples/nodejs_state.js new file mode 100755 index 00000000..fb3ed05f --- /dev/null +++ b/examples/nodejs_state.js @@ -0,0 +1,70 @@ +#!/usr/bin/env node +"use strict"; + +var fs = require("fs"); +var V86Starter = require("../build/libv86.js").V86Starter; + +function readfile(path) +{ + return new Uint8Array(fs.readFileSync(path)).buffer; +} + +console.log("Use F2 to save the state and F3 to restore."); + +var bios = readfile(__dirname + "/../bios/seabios.bin"); +var linux = readfile(__dirname + "/../images/linux.iso"); + +process.stdin.setRawMode(true); +process.stdin.resume(); +process.stdin.setEncoding("utf8"); + +console.log("Now booting, please stand by ..."); + +var emulator = new V86Starter({ + bios: { buffer: bios }, + cdrom: { buffer: linux }, + autostart: true, +}); + +emulator.add_listener("serial0-output-char", function(chr) +{ + process.stdout.write(chr); +}); + +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); + } +});