run.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. log_level: 0,
  29. });
  30. emulator.bus.register("emulator-started", function()
  31. {
  32. emulator.v86.cpu.io.register_write_consecutive(0xF4, {},
  33. function(value)
  34. {
  35. console.log("Test exited with code " + value);
  36. process.exit(value);
  37. },
  38. function() {},
  39. function() {},
  40. function() {});
  41. });
  42. emulator.add_listener("serial0-output-char", function(chr)
  43. {
  44. process.stdout.write(chr);
  45. });