virtual-machine 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -206,17 +206,17 @@ if (!("encodeInto" in cachedTextEncoder)) {
206
206
  };
207
207
  }
208
208
  var WASM_VECTOR_LEN = 0;
209
- function wasm_bindgen__convert__closures_____invoke__h68f644bdb48dd813(arg0, arg1, arg2) {
210
- wasm.wasm_bindgen__convert__closures_____invoke__h68f644bdb48dd813(arg0, arg1, arg2);
209
+ function wasm_bindgen__convert__closures_____invoke__he00a4f55faf9050f(arg0, arg1) {
210
+ wasm.wasm_bindgen__convert__closures_____invoke__he00a4f55faf9050f(arg0, arg1);
211
211
  }
212
- function wasm_bindgen__convert__closures_____invoke__h5c64d96786ac00c5(arg0, arg1) {
213
- wasm.wasm_bindgen__convert__closures_____invoke__h5c64d96786ac00c5(arg0, arg1);
212
+ function wasm_bindgen__convert__closures_____invoke__h260170fb96639bcf(arg0, arg1, arg2) {
213
+ wasm.wasm_bindgen__convert__closures_____invoke__h260170fb96639bcf(arg0, arg1, arg2);
214
214
  }
215
- function wasm_bindgen__convert__closures_____invoke__h39d3e89751b07765(arg0, arg1, arg2) {
216
- wasm.wasm_bindgen__convert__closures_____invoke__h39d3e89751b07765(arg0, arg1, arg2);
215
+ function wasm_bindgen__convert__closures_____invoke__hd159192dfee36a06(arg0, arg1) {
216
+ wasm.wasm_bindgen__convert__closures_____invoke__hd159192dfee36a06(arg0, arg1);
217
217
  }
218
- function wasm_bindgen__convert__closures_____invoke__h2a4d868e42b21102(arg0, arg1) {
219
- wasm.wasm_bindgen__convert__closures_____invoke__h2a4d868e42b21102(arg0, arg1);
218
+ function wasm_bindgen__convert__closures_____invoke__hedae94b906f728f2(arg0, arg1, arg2) {
219
+ wasm.wasm_bindgen__convert__closures_____invoke__hedae94b906f728f2(arg0, arg1, arg2);
220
220
  }
221
221
  var __wbindgen_enum_WorkerType = ["classic", "module"];
222
222
  var WasmVmFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
@@ -253,6 +253,22 @@ var WasmVm = class _WasmVm {
253
253
  const ptr = this.__destroy_into_raw();
254
254
  wasm.__wbg_wasmvm_free(ptr, 0);
255
255
  }
256
+ /**
257
+ * Enable VirtIO GPU device for graphics rendering.
258
+ *
259
+ * The GPU device allows the kernel to render to a framebuffer which can
260
+ * then be displayed in a Canvas element. Use `get_gpu_frame()` to retrieve
261
+ * the rendered frame pixels.
262
+ *
263
+ * # Arguments
264
+ * * `width` - Display width in pixels (default 800 if 0)
265
+ * * `height` - Display height in pixels (default 600 if 0)
266
+ * @param {number} width
267
+ * @param {number} height
268
+ */
269
+ enable_gpu(width, height) {
270
+ wasm.wasmvm_enable_gpu(this.__wbg_ptr, width, height);
271
+ }
256
272
  /**
257
273
  * Get a byte from the UART output buffer, if available.
258
274
  *
@@ -264,6 +280,24 @@ var WasmVm = class _WasmVm {
264
280
  const ret = wasm.wasmvm_get_output(this.__wbg_ptr);
265
281
  return ret === 16777215 ? void 0 : ret;
266
282
  }
283
+ /**
284
+ * Enable VirtIO Input device for keyboard input.
285
+ *
286
+ * After calling this, use `send_key_event()` to forward keyboard events
287
+ * from JavaScript to the guest kernel.
288
+ */
289
+ enable_input() {
290
+ wasm.wasmvm_enable_input(this.__wbg_ptr);
291
+ }
292
+ /**
293
+ * Get GPU display dimensions.
294
+ * Returns [width, height] or null if GPU is not enabled.
295
+ * @returns {Uint32Array | undefined}
296
+ */
297
+ get_gpu_size() {
298
+ const ret = wasm.wasmvm_get_gpu_size(this.__wbg_ptr);
299
+ return ret;
300
+ }
267
301
  /**
268
302
  * Print the VM banner to UART output (visible in browser).
269
303
  * Call this after creating the VM to show a boot banner.
@@ -288,6 +322,20 @@ var WasmVm = class _WasmVm {
288
322
  const ret = wasm.wasmvm_get_cpu_count(this.__wbg_ptr);
289
323
  return ret >>> 0;
290
324
  }
325
+ /**
326
+ * Get GPU frame data as RGBA pixels.
327
+ * Returns a Uint8Array of pixel data, or null if no frame is available.
328
+ *
329
+ * The frame data is in RGBA format with 4 bytes per pixel (800x600 = 1,920,000 bytes).
330
+ *
331
+ * This reads from a fixed framebuffer address in guest memory (0x8100_0000).
332
+ * The kernel GPU driver writes pixels there, and we read them here.
333
+ * @returns {Uint8Array | undefined}
334
+ */
335
+ get_gpu_frame() {
336
+ const ret = wasm.wasmvm_get_gpu_frame(this.__wbg_ptr);
337
+ return ret;
338
+ }
291
339
  /**
292
340
  * Get system uptime in milliseconds (from kernel-reported value).
293
341
  * @returns {bigint}
@@ -296,6 +344,17 @@ var WasmVm = class _WasmVm {
296
344
  const ret = wasm.wasmvm_get_uptime_ms(this.__wbg_ptr);
297
345
  return BigInt.asUintN(64, ret);
298
346
  }
347
+ /**
348
+ * Check if there's a GPU frame ready for rendering.
349
+ *
350
+ * With direct memory framebuffer, this always returns true when GPU is enabled.
351
+ * The framebuffer at FRAMEBUFFER_ADDR always contains the current frame.
352
+ * @returns {boolean}
353
+ */
354
+ has_gpu_frame() {
355
+ const ret = wasm.wasmvm_has_gpu_frame(this.__wbg_ptr);
356
+ return ret !== 0;
357
+ }
299
358
  /**
300
359
  * Start worker threads for secondary harts (1..num_harts).
301
360
  *
@@ -360,6 +419,22 @@ var WasmVm = class _WasmVm {
360
419
  }
361
420
  return _WasmVm.__wrap(ret[0]);
362
421
  }
422
+ /**
423
+ * Send a keyboard event to the guest.
424
+ *
425
+ * # Arguments
426
+ * * `key_code` - JavaScript keyCode (e.g., 65 for 'A')
427
+ * * `pressed` - true for keydown, false for keyup
428
+ *
429
+ * Returns true if the event was sent successfully.
430
+ * @param {number} key_code
431
+ * @param {boolean} pressed
432
+ * @returns {boolean}
433
+ */
434
+ send_key_event(key_code, pressed) {
435
+ const ret = wasm.wasmvm_send_key_event(this.__wbg_ptr, key_code, pressed);
436
+ return ret !== 0;
437
+ }
363
438
  /**
364
439
  * Get current memory usage (DRAM size) in bytes.
365
440
  * @returns {bigint}
@@ -368,6 +443,25 @@ var WasmVm = class _WasmVm {
368
443
  const ret = wasm.wasmvm_get_memory_usage(this.__wbg_ptr);
369
444
  return BigInt.asUintN(64, ret);
370
445
  }
446
+ /**
447
+ * Send a mouse event to the guest.
448
+ *
449
+ * # Arguments
450
+ * * `x` - X position (0-799)
451
+ * * `y` - Y position (0-599)
452
+ * * `buttons` - Button state bitmask (bit 0 = left, bit 1 = right, bit 2 = middle)
453
+ * * `prev_buttons` - Previous button state to detect changes
454
+ *
455
+ * Returns true if the event was sent successfully.
456
+ * @param {number} x
457
+ * @param {number} y
458
+ * @param {number} buttons
459
+ * @returns {boolean}
460
+ */
461
+ send_mouse_event(x, y, buttons) {
462
+ const ret = wasm.wasmvm_send_mouse_event(this.__wbg_ptr, x, y, buttons);
463
+ return ret !== 0;
464
+ }
371
465
  /**
372
466
  * Get the total disk capacity from attached VirtIO block devices.
373
467
  * Returns total bytes across all block devices.
@@ -386,6 +480,20 @@ var WasmVm = class _WasmVm {
386
480
  const ret = wasm.wasmvm_get_shared_buffer(this.__wbg_ptr);
387
481
  return ret;
388
482
  }
483
+ /**
484
+ * Send a mouse button event to the guest.
485
+ *
486
+ * # Arguments
487
+ * * `button` - Button number (0 = left, 1 = right, 2 = middle)
488
+ * * `pressed` - true for press, false for release
489
+ * @param {number} button
490
+ * @param {boolean} pressed
491
+ * @returns {boolean}
492
+ */
493
+ send_mouse_button(button, pressed) {
494
+ const ret = wasm.wasmvm_send_mouse_button(this.__wbg_ptr, button, pressed);
495
+ return ret !== 0;
496
+ }
389
497
  /**
390
498
  * Terminate all workers.
391
499
  */
@@ -941,6 +1049,10 @@ function __wbg_get_imports() {
941
1049
  const ret = new Uint8Array(arg0, arg1 >>> 0, arg2 >>> 0);
942
1050
  return ret;
943
1051
  };
1052
+ imports.wbg.__wbg_new_with_length_202b3db94ba5fc86 = function(arg0) {
1053
+ const ret = new Uint32Array(arg0 >>> 0);
1054
+ return ret;
1055
+ };
944
1056
  imports.wbg.__wbg_new_with_length_aa5eaf41d35235e5 = function(arg0) {
945
1057
  const ret = new Uint8Array(arg0 >>> 0);
946
1058
  return ret;
@@ -1036,6 +1148,9 @@ function __wbg_get_imports() {
1036
1148
  imports.wbg.__wbg_set_index_04c4b93e64d08a52 = function(arg0, arg1, arg2) {
1037
1149
  arg0[arg1 >>> 0] = arg2;
1038
1150
  };
1151
+ imports.wbg.__wbg_set_index_42abe35f117e614e = function(arg0, arg1, arg2) {
1152
+ arg0[arg1 >>> 0] = arg2 >>> 0;
1153
+ };
1039
1154
  imports.wbg.__wbg_set_onmessage_deb94985de696ac7 = function(arg0, arg1) {
1040
1155
  arg0.onmessage = arg1;
1041
1156
  };
@@ -1115,24 +1230,24 @@ function __wbg_get_imports() {
1115
1230
  return ret;
1116
1231
  }, arguments);
1117
1232
  };
1118
- imports.wbg.__wbindgen_cast_1b00663567edb453 = function(arg0, arg1) {
1119
- const ret = makeClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h534978b8728125b3, wasm_bindgen__convert__closures_____invoke__h5c64d96786ac00c5);
1120
- return ret;
1121
- };
1122
1233
  imports.wbg.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
1123
1234
  const ret = getStringFromWasm0(arg0, arg1);
1124
1235
  return ret;
1125
1236
  };
1126
- imports.wbg.__wbindgen_cast_614f6ca309748622 = function(arg0, arg1) {
1127
- const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h534978b8728125b3, wasm_bindgen__convert__closures_____invoke__h2a4d868e42b21102);
1237
+ imports.wbg.__wbindgen_cast_32327f67251393a4 = function(arg0, arg1) {
1238
+ const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h2f2b52f94c430d4b, wasm_bindgen__convert__closures_____invoke__he00a4f55faf9050f);
1239
+ return ret;
1240
+ };
1241
+ imports.wbg.__wbindgen_cast_3d2491109ac86f9d = function(arg0, arg1) {
1242
+ const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h612f8e24953b61d5, wasm_bindgen__convert__closures_____invoke__h260170fb96639bcf);
1128
1243
  return ret;
1129
1244
  };
1130
- imports.wbg.__wbindgen_cast_9d58885f229d7092 = function(arg0, arg1) {
1131
- const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__hf225e18fc5ab9bc1, wasm_bindgen__convert__closures_____invoke__h39d3e89751b07765);
1245
+ imports.wbg.__wbindgen_cast_bbd4dd9b33de0f05 = function(arg0, arg1) {
1246
+ const ret = makeClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h2f2b52f94c430d4b, wasm_bindgen__convert__closures_____invoke__hd159192dfee36a06);
1132
1247
  return ret;
1133
1248
  };
1134
1249
  imports.wbg.__wbindgen_cast_bda31cc20c54b248 = function(arg0, arg1) {
1135
- const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h534978b8728125b3, wasm_bindgen__convert__closures_____invoke__h68f644bdb48dd813);
1250
+ const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h2f2b52f94c430d4b, wasm_bindgen__convert__closures_____invoke__hedae94b906f728f2);
1136
1251
  return ret;
1137
1252
  };
1138
1253
  imports.wbg.__wbindgen_cast_d6cd19b81560fd6e = function(arg0) {