virtual-machine 0.2.1 → 0.2.2

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.
package/build/index.d.ts CHANGED
@@ -14,6 +14,18 @@ declare enum NetworkStatus {
14
14
  declare class WasmVm {
15
15
  free(): void;
16
16
  [Symbol.dispose](): void;
17
+ /**
18
+ * Enable VirtIO GPU device for graphics rendering.
19
+ *
20
+ * The GPU device allows the kernel to render to a framebuffer which can
21
+ * then be displayed in a Canvas element. Use `get_gpu_frame()` to retrieve
22
+ * the rendered frame pixels.
23
+ *
24
+ * # Arguments
25
+ * * `width` - Display width in pixels (default 800 if 0)
26
+ * * `height` - Display height in pixels (default 600 if 0)
27
+ */
28
+ enable_gpu(width: number, height: number): void;
17
29
  /**
18
30
  * Get a byte from the UART output buffer, if available.
19
31
  *
@@ -21,6 +33,18 @@ declare class WasmVm {
21
33
  * and the local UART buffer (for hart 0 output).
22
34
  */
23
35
  get_output(): number | undefined;
36
+ /**
37
+ * Enable VirtIO Input device for keyboard input.
38
+ *
39
+ * After calling this, use `send_key_event()` to forward keyboard events
40
+ * from JavaScript to the guest kernel.
41
+ */
42
+ enable_input(): void;
43
+ /**
44
+ * Get GPU display dimensions.
45
+ * Returns [width, height] or null if GPU is not enabled.
46
+ */
47
+ get_gpu_size(): Uint32Array | undefined;
24
48
  /**
25
49
  * Print the VM banner to UART output (visible in browser).
26
50
  * Call this after creating the VM to show a boot banner.
@@ -34,10 +58,27 @@ declare class WasmVm {
34
58
  * Get CPU count (from kernel-reported value).
35
59
  */
36
60
  get_cpu_count(): number;
61
+ /**
62
+ * Get GPU frame data as RGBA pixels.
63
+ * Returns a Uint8Array of pixel data, or null if no frame is available.
64
+ *
65
+ * The frame data is in RGBA format with 4 bytes per pixel (800x600 = 1,920,000 bytes).
66
+ *
67
+ * This reads from a fixed framebuffer address in guest memory (0x8100_0000).
68
+ * The kernel GPU driver writes pixels there, and we read them here.
69
+ */
70
+ get_gpu_frame(): Uint8Array | undefined;
37
71
  /**
38
72
  * Get system uptime in milliseconds (from kernel-reported value).
39
73
  */
40
74
  get_uptime_ms(): bigint;
75
+ /**
76
+ * Check if there's a GPU frame ready for rendering.
77
+ *
78
+ * With direct memory framebuffer, this always returns true when GPU is enabled.
79
+ * The framebuffer at FRAMEBUFFER_ADDR always contains the current frame.
80
+ */
81
+ has_gpu_frame(): boolean;
41
82
  /**
42
83
  * Start worker threads for secondary harts (1..num_harts).
43
84
  *
@@ -71,6 +112,16 @@ declare class WasmVm {
71
112
  * * `num_harts` - Number of harts (0 = auto-detect)
72
113
  */
73
114
  static new_with_harts(kernel: Uint8Array, num_harts: number): WasmVm;
115
+ /**
116
+ * Send a keyboard event to the guest.
117
+ *
118
+ * # Arguments
119
+ * * `key_code` - JavaScript keyCode (e.g., 65 for 'A')
120
+ * * `pressed` - true for keydown, false for keyup
121
+ *
122
+ * Returns true if the event was sent successfully.
123
+ */
124
+ send_key_event(key_code: number, pressed: boolean): boolean;
74
125
  /**
75
126
  * Get current memory usage (DRAM size) in bytes.
76
127
  */
@@ -289,6 +340,8 @@ interface InitOutput {
289
340
  readonly wasmvm_allow_workers_to_start: (a: number) => void;
290
341
  readonly wasmvm_connect_webtransport: (a: number, b: number, c: number, d: number, e: number) => [number, number];
291
342
  readonly wasmvm_disconnect_network: (a: number) => void;
343
+ readonly wasmvm_enable_gpu: (a: number, b: number, c: number) => void;
344
+ readonly wasmvm_enable_input: (a: number) => void;
292
345
  readonly wasmvm_entry_pc: (a: number) => bigint;
293
346
  readonly wasmvm_external_network_rx_pending: (a: number) => number;
294
347
  readonly wasmvm_external_network_tx_pending: (a: number) => number;
@@ -297,12 +350,15 @@ interface InitOutput {
297
350
  readonly wasmvm_get_cpu_count: (a: number) => number;
298
351
  readonly wasmvm_get_disk_capacity: (a: number) => bigint;
299
352
  readonly wasmvm_get_disk_usage: (a: number) => any;
353
+ readonly wasmvm_get_gpu_frame: (a: number) => any;
354
+ readonly wasmvm_get_gpu_size: (a: number) => any;
300
355
  readonly wasmvm_get_heap_usage: (a: number) => any;
301
356
  readonly wasmvm_get_memory_usage: (a: number) => bigint;
302
357
  readonly wasmvm_get_output: (a: number) => number;
303
358
  readonly wasmvm_get_shared_buffer: (a: number) => any;
304
359
  readonly wasmvm_get_uptime_ms: (a: number) => bigint;
305
360
  readonly wasmvm_halt_code: (a: number) => bigint;
361
+ readonly wasmvm_has_gpu_frame: (a: number) => number;
306
362
  readonly wasmvm_inject_network_packet: (a: number, b: any) => number;
307
363
  readonly wasmvm_input: (a: number, b: number) => void;
308
364
  readonly wasmvm_is_external_network_connected: (a: number) => number;
@@ -315,6 +371,7 @@ interface InitOutput {
315
371
  readonly wasmvm_num_harts: (a: number) => number;
316
372
  readonly wasmvm_print_banner: (a: number) => void;
317
373
  readonly wasmvm_print_status: (a: number, b: number, c: number) => void;
374
+ readonly wasmvm_send_key_event: (a: number, b: number, c: number) => number;
318
375
  readonly wasmvm_set_external_network_ip: (a: number, b: any) => number;
319
376
  readonly wasmvm_setup_external_network: (a: number, b: any) => [number, number];
320
377
  readonly wasmvm_start_workers: (a: number, b: number, c: number) => [number, number];
@@ -328,12 +385,12 @@ interface InitOutput {
328
385
  readonly workerstate_new: (a: number, b: any, c: bigint) => number;
329
386
  readonly workerstate_step_batch: (a: number, b: number) => number;
330
387
  readonly workerstate_step_count: (a: number) => bigint;
331
- readonly wasm_bindgen__convert__closures_____invoke__h68f644bdb48dd813: (a: number, b: number, c: any) => void;
332
- readonly wasm_bindgen__closure__destroy__h534978b8728125b3: (a: number, b: number) => void;
333
- readonly wasm_bindgen__convert__closures_____invoke__h5c64d96786ac00c5: (a: number, b: number) => void;
334
- readonly wasm_bindgen__convert__closures_____invoke__h39d3e89751b07765: (a: number, b: number, c: any) => void;
335
- readonly wasm_bindgen__closure__destroy__hf225e18fc5ab9bc1: (a: number, b: number) => void;
336
- readonly wasm_bindgen__convert__closures_____invoke__h2a4d868e42b21102: (a: number, b: number) => void;
388
+ readonly wasm_bindgen__convert__closures_____invoke__h74d7f37f0b0d661d: (a: number, b: number, c: any) => void;
389
+ readonly wasm_bindgen__closure__destroy__h01c75dc83ec8dfae: (a: number, b: number) => void;
390
+ readonly wasm_bindgen__convert__closures_____invoke__h9f0ee31d317d33d7: (a: number, b: number) => void;
391
+ readonly wasm_bindgen__convert__closures_____invoke__h260170fb96639bcf: (a: number, b: number, c: any) => void;
392
+ readonly wasm_bindgen__closure__destroy__h612f8e24953b61d5: (a: number, b: number) => void;
393
+ readonly wasm_bindgen__convert__closures_____invoke__h97b9bec6245a8424: (a: number, b: number) => void;
337
394
  readonly __wbindgen_malloc: (a: number, b: number) => number;
338
395
  readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
339
396
  readonly __wbindgen_exn_store: (a: number) => void;