lang.html 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 V86({
  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", async 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. await emulator.create_file("/root/code.js", buffer);
  40. emulator.serial0_send("node /root/code.js > /root/out.txt 2> /root/out.txt\n");
  41. });
  42. var serial_out = "";
  43. emulator.add_listener("serial0-output-byte", async function(byte)
  44. {
  45. var chr = String.fromCharCode(byte);
  46. serial_out += chr;
  47. if(serial_out.endsWith("root@nyu"))
  48. {
  49. const data = await emulator.read_file("/root/out.txt");
  50. document.getElementById("output").textContent += String.fromCharCode.apply(this, data);
  51. }
  52. });
  53. }
  54. </script>
  55. <pre><span id=time></span> <span id=status></span></pre>
  56. <!-- A minimal structure for the ScreenAdapter defined in browser/screen.js -->
  57. <div id="screen_container">
  58. <div style="white-space: pre; font: 14px monospace; line-height: 14px"></div>
  59. <canvas style="display: none"></canvas>
  60. </div>
  61. <hr>
  62. <pre id=output></pre>