diamond-in commited on
Commit
1e68309
·
verified ·
1 Parent(s): 2a9b1e4

Update main.cpp

Browse files
Files changed (1) hide show
  1. main.cpp +13 -23
main.cpp CHANGED
@@ -30,7 +30,7 @@ const char* HTML_PAGE = R"(
30
  #input-wrapper { display: flex; border-top: 1px solid #333; padding: 10px; background: #111; }
31
  #prompt { color: #0f0; padding-right: 10px; font-weight: bold; }
32
  #cmd { background: transparent; border: none; color: white; flex-grow: 1; outline: none; font-family: inherit; font-size: 16px; }
33
- .local-echo { color: #888; } /* Style for text you type */
34
  </style>
35
  </head>
36
  <body>
@@ -55,13 +55,9 @@ const char* HTML_PAGE = R"(
55
  .finally(() => setTimeout(poll, 300));
56
  }
57
 
58
- // Send Command Logic
59
  async function sendCommand(val) {
60
- // 1. Local Echo (Show what you typed immediately in grey)
61
  term.innerHTML += `<span class="local-echo">${val}</span>`;
62
  term.scrollTop = term.scrollHeight;
63
-
64
- // 2. Send via POST (Append \n for Linux Enter)
65
  await fetch('/input', { method: 'POST', body: val + '\n' });
66
  }
67
 
@@ -73,14 +69,8 @@ const char* HTML_PAGE = R"(
73
  }
74
  });
75
 
76
- // FORCE FOCUS on click (Fixes iframe blocking issues)
77
- document.addEventListener('click', () => {
78
- cmd.focus();
79
- });
80
-
81
- // Focus immediately on load (try/catch in case browser blocks it)
82
  try { cmd.focus(); } catch(e){}
83
-
84
  poll();
85
  </script>
86
  </body>
@@ -111,6 +101,7 @@ void start_vm() {
111
 
112
  const char* bios = file_exists("bios.elf") ? "bios.elf" : "default";
113
 
 
114
  execlp("qemu-system-riscv64", "qemu-system-riscv64",
115
  "-nographic",
116
  "-machine", "virt",
@@ -119,12 +110,16 @@ void start_vm() {
119
  "-bios", bios,
120
  "-kernel", "vmlinuz",
121
  "-initrd", "initramfs",
122
- "-drive", "file=alpine.iso,format=raw,id=hd0",
123
- "-device", "virtio-blk-device,drive=hd0",
 
 
 
 
124
  "-serial", "stdio",
125
  "-monitor", "none",
126
- // CRITICAL: console=ttyS0 connects the VM output to our C++ Pipe
127
- "-append", "console=ttyS0 root=/dev/vda modules=loop,squashfs,sd-mod,usb-storage quiet",
128
  NULL
129
  );
130
  exit(1);
@@ -136,7 +131,7 @@ void start_vm() {
136
  master_read_fd = pipe_out[0];
137
  fcntl(master_read_fd, F_SETFL, O_NONBLOCK);
138
 
139
- std::string msg = "--- SYSTEM ONLINE. CLICK SCREEN TO TYPE. ---\n";
140
  output_history.insert(output_history.end(), msg.begin(), msg.end());
141
  }
142
 
@@ -175,9 +170,7 @@ int main() {
175
  char buf[4096];
176
  int n = read(master_read_fd, buf, sizeof(buf));
177
  if(n > 0) {
178
- // LOG RAW OUTPUT TO CONSOLE FOR DEBUGGING
179
  std::cout.write(buf, n);
180
-
181
  output_history.insert(output_history.end(), buf, buf+n);
182
  if(output_history.size() > MAX_HISTORY) output_history.erase(output_history.begin(), output_history.begin() + 4096);
183
  }
@@ -204,10 +197,7 @@ int main() {
204
  size_t pos = s.find("\r\n\r\n");
205
  if(pos != std::string::npos) {
206
  std::string v = s.substr(pos+4);
207
- if(master_write_fd != -1) {
208
- write(master_write_fd, v.c_str(), v.length());
209
- std::cout << "[INPUT RECEIVED]: " << v << std::endl; // Log input to HF Console
210
- }
211
  }
212
  send_http(client, "ok", "text/plain");
213
  }
 
30
  #input-wrapper { display: flex; border-top: 1px solid #333; padding: 10px; background: #111; }
31
  #prompt { color: #0f0; padding-right: 10px; font-weight: bold; }
32
  #cmd { background: transparent; border: none; color: white; flex-grow: 1; outline: none; font-family: inherit; font-size: 16px; }
33
+ .local-echo { color: #888; }
34
  </style>
35
  </head>
36
  <body>
 
55
  .finally(() => setTimeout(poll, 300));
56
  }
57
 
 
58
  async function sendCommand(val) {
 
59
  term.innerHTML += `<span class="local-echo">${val}</span>`;
60
  term.scrollTop = term.scrollHeight;
 
 
61
  await fetch('/input', { method: 'POST', body: val + '\n' });
62
  }
63
 
 
69
  }
70
  });
71
 
72
+ document.addEventListener('click', () => cmd.focus());
 
 
 
 
 
73
  try { cmd.focus(); } catch(e){}
 
74
  poll();
75
  </script>
76
  </body>
 
101
 
102
  const char* bios = file_exists("bios.elf") ? "bios.elf" : "default";
103
 
104
+ // --- UPDATED BOOT LOGIC ---
105
  execlp("qemu-system-riscv64", "qemu-system-riscv64",
106
  "-nographic",
107
  "-machine", "virt",
 
110
  "-bios", bios,
111
  "-kernel", "vmlinuz",
112
  "-initrd", "initramfs",
113
+
114
+ // NEW DRIVE CONFIG FOR ALPINE V3.23
115
+ "-device", "virtio-scsi-device,id=scsi0",
116
+ "-drive", "file=alpine.iso,format=raw,if=none,id=drive0",
117
+ "-device", "scsi-cd,bus=scsi0.0,drive=drive0",
118
+
119
  "-serial", "stdio",
120
  "-monitor", "none",
121
+ // Boot from CDROM (sr0)
122
+ "-append", "console=ttyS0 root=/dev/sr0 modules=sd-mod,usb-storage,sr_mod quiet",
123
  NULL
124
  );
125
  exit(1);
 
131
  master_read_fd = pipe_out[0];
132
  fcntl(master_read_fd, F_SETFL, O_NONBLOCK);
133
 
134
+ std::string msg = "--- SYSTEM ONLINE. LOADING CD-ROM... ---\n";
135
  output_history.insert(output_history.end(), msg.begin(), msg.end());
136
  }
137
 
 
170
  char buf[4096];
171
  int n = read(master_read_fd, buf, sizeof(buf));
172
  if(n > 0) {
 
173
  std::cout.write(buf, n);
 
174
  output_history.insert(output_history.end(), buf, buf+n);
175
  if(output_history.size() > MAX_HISTORY) output_history.erase(output_history.begin(), output_history.begin() + 4096);
176
  }
 
197
  size_t pos = s.find("\r\n\r\n");
198
  if(pos != std::string::npos) {
199
  std::string v = s.substr(pos+4);
200
+ if(master_write_fd != -1) write(master_write_fd, v.c_str(), v.length());
 
 
 
201
  }
202
  send_http(client, "ok", "text/plain");
203
  }