lang.html 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <!doctype html>
  2. <title>Basic Emulator</title><!-- not BASIC! -->
  3. <script src="../build/libv86.js"></script>
  4. <script>
  5. "use strict";
  6. window.onload = function()
  7. {
  8. var start = Date.now();
  9. setInterval(function()
  10. {
  11. document.getElementById("time").textContent = Math.round((Date.now() - start) / 1000);
  12. }, 999);
  13. var emulator = new V86Starter({
  14. wasm_path: "../build/v86.wasm",
  15. memory_size: 512 * 1024 * 1024,
  16. vga_memory_size: 8 * 1024 * 1024,
  17. screen_container: document.getElementById("screen_container"),
  18. bios: {
  19. url: "../bios/seabios.bin",
  20. },
  21. vga_bios: {
  22. url: "../bios/vgabios.bin",
  23. },
  24. initial_state: {
  25. url: "../images/arch_state.bin.zst",
  26. },
  27. filesystem: {
  28. baseurl: "../images/arch/",
  29. },
  30. autostart: true,
  31. });
  32. document.getElementById("status").textContent += ".";
  33. emulator.add_listener("emulator-ready", function()
  34. {
  35. document.getElementById("status").textContent += ".";
  36. var code = "console.log(3 * 7);\n";
  37. var buffer = new Uint8Array(code.length);
  38. buffer.set(code.split("").map(function(chr) { return chr.charCodeAt(0); }));
  39. emulator.create_file("/root/code.js", buffer, function(error)
  40. {
  41. if(error) throw error;
  42. emulator.serial0_send("node /root/code.js > /root/out.txt 2> /root/out.txt\n");
  43. });
  44. });
  45. var serial_out = "";
  46. emulator.add_listener("serial0-output-char", function(chr)
  47. {
  48. serial_out += chr;
  49. //document.getElementById("output").textContent += chr;
  50. if(serial_out.endsWith("root@nyu"))
  51. {
  52. emulator.read_file("/root/out.txt", function(error, data)
  53. {
  54. if(error) throw error;
  55. document.getElementById("output").textContent += String.fromCharCode.apply(this, data);
  56. });
  57. }
  58. });
  59. }
  60. </script>
  61. <pre><span id=time></span> <span id=status></span></pre>
  62. <!-- A minimal structure for the ScreenAdapter defined in browser/screen.js -->
  63. <div id="screen_container">
  64. <div style="white-space: pre; font: 14px monospace; line-height: 14px"></div>
  65. <canvas style="display: none"></canvas>
  66. </div>
  67. <hr>
  68. <pre id=output></pre>