nodejs.js 940 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/usr/bin/env node
  2. "use strict";
  3. var fs = require("fs");
  4. var V86 = require("../build/libv86.js").V86;
  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 V86({
  16. bios: { buffer: bios },
  17. cdrom: { buffer: linux },
  18. autostart: true,
  19. });
  20. emulator.add_listener("serial0-output-byte", function(byte)
  21. {
  22. var chr = String.fromCharCode(byte);
  23. if(chr <= "~")
  24. {
  25. process.stdout.write(chr);
  26. }
  27. });
  28. process.stdin.on("data", function(c)
  29. {
  30. if(c === "\u0003")
  31. {
  32. // ctrl c
  33. emulator.stop();
  34. process.stdin.pause();
  35. }
  36. else
  37. {
  38. emulator.serial0_send(c);
  39. }
  40. });