1
0

run.js 1.4 KB

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