serial.html 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <!doctype html>
  2. <title>Serial example</title>
  3. <script src="../build/libv86.js"></script>
  4. <script>
  5. "use strict";
  6. window.onload = function()
  7. {
  8. var emulator = new V86Starter({
  9. wasm_path: "../build/v86.wasm",
  10. // Uncomment to see what's going on
  11. //screen_container: document.getElementById("screen_container"),
  12. bios: {
  13. url: "../bios/seabios.bin",
  14. },
  15. vga_bios: {
  16. url: "../bios/vgabios.bin",
  17. },
  18. cdrom: {
  19. url: "../images/linux4.iso",
  20. },
  21. autostart: true,
  22. disable_keyboard: true,
  23. });
  24. // In this example we wait for output from the serial terminal, which
  25. // should be running busybox. We log in as soon as a prompt appears and then
  26. // retrieve a directory listing of the root directory
  27. var data = "";
  28. var stages = [
  29. {
  30. test: "~% ",
  31. send: "ls -1 --color=never /\n",
  32. },
  33. {
  34. test: "~% ",
  35. send: "lua -e 'print(3+4)'\n",
  36. },
  37. ];
  38. var stage = 0;
  39. emulator.add_listener("serial0-output-char", function(char)
  40. {
  41. if(char === "\r")
  42. {
  43. return;
  44. }
  45. data += char;
  46. document.getElementById("terminal").value += char;
  47. var current = stages[stage];
  48. if(!current)
  49. {
  50. return;
  51. }
  52. if(data.endsWith(current.test))
  53. {
  54. stage++;
  55. emulator.serial0_send(current.send);
  56. var log = "Sending: " + current.send.replace(/\n/g, "\\n") + "\n";
  57. document.getElementById("log").value += log;
  58. }
  59. });
  60. };
  61. </script>
  62. <textarea readonly rows=25 cols=60 id="log">Waiting for boot ...
  63. </textarea>
  64. <textarea readonly rows=25 cols=60 id="terminal"></textarea>
  65. <div id="screen_container">
  66. <div style="white-space: pre; font: 14px monospace; line-height: 14px"></div>
  67. <canvas style="display: none"></canvas>
  68. </div>