nodejs.js 919 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/env node
  2. "use strict";
  3. var fs = require("fs");
  4. var V86Starter = require("../build/libv86.js").V86Starter;
  5. function readfile(path)
  6. {
  7. return new Uint8Array(fs.readFileSync(path)).buffer;
  8. }
  9. var bios = readfile(__dirname + "/../bios/seabios.bin");
  10. var linux = readfile(__dirname + "/../images/linux4.iso");
  11. process.stdin.setRawMode(true);
  12. process.stdin.resume();
  13. process.stdin.setEncoding("utf8");
  14. console.log("Now booting, please stand by ...");
  15. var emulator = new V86Starter({
  16. bios: { buffer: bios },
  17. cdrom: { buffer: linux },
  18. autostart: true,
  19. });
  20. emulator.add_listener("serial0-output-char", function(chr)
  21. {
  22. if(chr <= "~")
  23. {
  24. process.stdout.write(chr);
  25. }
  26. });
  27. process.stdin.on("data", function(c)
  28. {
  29. if(c === "\u0003")
  30. {
  31. // ctrl c
  32. emulator.stop();
  33. process.stdin.pause();
  34. }
  35. else
  36. {
  37. emulator.serial0_send(c);
  38. }
  39. });