run.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env node
  2. "use strict";
  3. process.on("unhandledRejection", exn => { throw exn; });
  4. var V86 = require("../../build/libv86-debug.js").V86;
  5. var fs = require("fs");
  6. function readfile(path)
  7. {
  8. return new Uint8Array(fs.readFileSync(path)).buffer;
  9. }
  10. function Loader(path)
  11. {
  12. this.buffer = readfile(path);
  13. this.byteLength = this.buffer.byteLength;
  14. }
  15. Loader.prototype.load = function()
  16. {
  17. this.onload && this.onload({});
  18. };
  19. var bios = readfile(__dirname + "/../../bios/seabios.bin");
  20. var vga_bios = readfile(__dirname + "/../../bios/vgabios.bin");
  21. var emulator = new V86({
  22. bios: { buffer: bios },
  23. vga_bios: { buffer: vga_bios },
  24. multiboot: new Loader(process.argv[2]),
  25. autostart: true,
  26. memory_size: 64 * 1024 * 1024,
  27. log_level: 0,
  28. });
  29. emulator.bus.register("emulator-started", function()
  30. {
  31. emulator.v86.cpu.io.register_write_consecutive(0xF4, {},
  32. function(value)
  33. {
  34. console.log("Test exited with code " + value);
  35. process.exit(value);
  36. },
  37. function() {},
  38. function() {},
  39. function() {});
  40. });
  41. emulator.add_listener("serial0-output-char", function(chr)
  42. {
  43. process.stdout.write(chr);
  44. });