virtual-machine 0.3.0 → 0.3.3

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
@@ -15,17 +15,17 @@ declare class WasmVm {
15
15
  free(): void;
16
16
  [Symbol.dispose](): void;
17
17
  /**
18
- * Enable VirtIO GPU device for graphics rendering.
18
+ * Enable D1 Display device for graphics rendering.
19
19
  *
20
- * The GPU device allows the kernel to render to a framebuffer which can
20
+ * The display device allows the kernel to render to a framebuffer which can
21
21
  * then be displayed in a Canvas element. Use `get_gpu_frame()` to retrieve
22
22
  * the rendered frame pixels.
23
23
  *
24
24
  * # Arguments
25
- * * `width` - Display width in pixels (default 800 if 0)
26
- * * `height` - Display height in pixels (default 600 if 0)
25
+ * * `width` - Display width in pixels (ignored, uses 1024x768)
26
+ * * `height` - Display height in pixels (ignored, uses 1024x768)
27
27
  */
28
- enable_gpu(width: number, height: number): void;
28
+ enable_gpu(_width: number, _height: number): void;
29
29
  /**
30
30
  * Get a byte from the UART output buffer, if available.
31
31
  *
@@ -62,7 +62,7 @@ declare class WasmVm {
62
62
  * Get GPU frame data as RGBA pixels.
63
63
  * Returns a Uint8Array of pixel data, or null if no frame is available.
64
64
  *
65
- * The frame data is in RGBA format with 4 bytes per pixel (800x600 = 1,920,000 bytes).
65
+ * The frame data is in RGBA format with 4 bytes per pixel (1024×768 = 3,145,728 bytes).
66
66
  *
67
67
  * This reads from a fixed framebuffer address in guest memory (0x8100_0000).
68
68
  * The kernel GPU driver writes pixels there, and we read them here.
@@ -101,7 +101,7 @@ declare class WasmVm {
101
101
  get_heap_usage(): Array<any>;
102
102
  /**
103
103
  * Get the current network connection status.
104
- * This checks the actual connection state by seeing if an IP was assigned.
104
+ * This checks the actual connection state by seeing if D1 EMAC is enabled.
105
105
  */
106
106
  network_status(): NetworkStatus;
107
107
  /**
@@ -138,6 +138,17 @@ declare class WasmVm {
138
138
  * Returns true if the event was sent successfully.
139
139
  */
140
140
  send_mouse_event(x: number, y: number, buttons: number): boolean;
141
+ /**
142
+ * Send a touch event to the D1 GT911 touchscreen controller.
143
+ *
144
+ * # Arguments
145
+ * * `x` - X position (0 to display width)
146
+ * * `y` - Y position (0 to display height)
147
+ * * `pressed` - true for touch down/move, false for touch up
148
+ *
149
+ * Returns true if the event was sent successfully.
150
+ */
151
+ send_touch_event(x: number, y: number, pressed: boolean): boolean;
141
152
  /**
142
153
  * Get the total disk capacity from attached VirtIO block devices.
143
154
  * Returns total bytes across all block devices.
@@ -174,6 +185,22 @@ declare class WasmVm {
174
185
  * Note: Connection is asynchronous. Check network_status() to monitor connection state.
175
186
  */
176
187
  connect_webtransport(url: string, cert_hash?: string | null): void;
188
+ /**
189
+ * Get a direct zero-copy view into the framebuffer in SharedArrayBuffer.
190
+ *
191
+ * This eliminates all memory copies by creating a Uint8Array view directly
192
+ * into the SharedArrayBuffer at the framebuffer offset. The browser can
193
+ * pass this directly to WebGPU's writeTexture for zero-copy rendering.
194
+ *
195
+ * Returns None if SharedArrayBuffer is not available (single-threaded mode).
196
+ */
197
+ get_framebuffer_view(): Uint8Array | undefined;
198
+ /**
199
+ * Get the current frame version from kernel memory.
200
+ * Returns a u32 that increments each time the kernel flushes dirty pixels.
201
+ * Browser can compare this to skip fetching unchanged frames.
202
+ */
203
+ get_gpu_frame_version(): number;
177
204
  /**
178
205
  * Inject a network packet to be received by the guest.
179
206
  * Called from JavaScript when the native WebTransport addon receives a packet.
@@ -270,7 +297,7 @@ declare class WasmVm {
270
297
  */
271
298
  is_halted(): boolean;
272
299
  /**
273
- * Load a disk image and attach it as a VirtIO block device.
300
+ * Load a disk image and attach it as a D1 MMC device.
274
301
  * This should be called before starting execution if the kernel needs a filesystem.
275
302
  */
276
303
  load_disk(disk_image: Uint8Array): void;
@@ -302,10 +329,22 @@ declare class WorkerState {
302
329
  * Get the total step count.
303
330
  */
304
331
  step_count(): bigint;
332
+ /**
333
+ * Check if MSIP is pending for this hart (for debugging).
334
+ */
335
+ is_msip_pending(): boolean;
336
+ /**
337
+ * Check if timer is pending for this hart (for debugging).
338
+ */
339
+ is_timer_pending(): boolean;
305
340
  /**
306
341
  * Create a new worker state for a secondary hart.
307
342
  */
308
343
  constructor(hart_id: number, shared_mem: any, entry_pc: bigint);
344
+ /**
345
+ * Get the a0 register value (for debugging hart ID passing).
346
+ */
347
+ get_a0(): bigint;
309
348
  /**
310
349
  * Get the hart ID.
311
350
  */
@@ -332,6 +371,11 @@ declare enum WorkerStepResult {
332
371
  * Fatal error occurred
333
372
  */
334
373
  Error = 3,
374
+ /**
375
+ * WFI executed - worker should yield to prevent busy loop
376
+ * TypeScript should add a small delay before calling step_batch again
377
+ */
378
+ Wfi = 4,
335
379
  }
336
380
 
337
381
  /**
@@ -370,7 +414,9 @@ interface InitOutput {
370
414
  readonly wasmvm_get_cpu_count: (a: number) => number;
371
415
  readonly wasmvm_get_disk_capacity: (a: number) => bigint;
372
416
  readonly wasmvm_get_disk_usage: (a: number) => any;
417
+ readonly wasmvm_get_framebuffer_view: (a: number) => any;
373
418
  readonly wasmvm_get_gpu_frame: (a: number) => any;
419
+ readonly wasmvm_get_gpu_frame_version: (a: number) => number;
374
420
  readonly wasmvm_get_gpu_size: (a: number) => any;
375
421
  readonly wasmvm_get_heap_usage: (a: number) => any;
376
422
  readonly wasmvm_get_memory_usage: (a: number) => bigint;
@@ -394,6 +440,7 @@ interface InitOutput {
394
440
  readonly wasmvm_send_key_event: (a: number, b: number, c: number) => number;
395
441
  readonly wasmvm_send_mouse_button: (a: number, b: number, c: number) => number;
396
442
  readonly wasmvm_send_mouse_event: (a: number, b: number, c: number, d: number) => number;
443
+ readonly wasmvm_send_touch_event: (a: number, b: number, c: number, d: number) => number;
397
444
  readonly wasmvm_set_external_network_ip: (a: number, b: any) => number;
398
445
  readonly wasmvm_setup_external_network: (a: number, b: any) => [number, number];
399
446
  readonly wasmvm_start_workers: (a: number, b: number, c: number) => [number, number];
@@ -402,17 +449,20 @@ interface InitOutput {
402
449
  readonly wasmvm_terminate_workers: (a: number) => void;
403
450
  readonly wasmvm_uart_output_pending: (a: number) => number;
404
451
  readonly worker_check_interrupts: (a: number, b: any) => bigint;
405
- readonly worker_entry: (a: number, b: any, c: bigint) => void;
452
+ readonly workerstate_get_a0: (a: number) => bigint;
406
453
  readonly workerstate_hart_id: (a: number) => number;
454
+ readonly workerstate_is_msip_pending: (a: number) => number;
455
+ readonly workerstate_is_timer_pending: (a: number) => number;
407
456
  readonly workerstate_new: (a: number, b: any, c: bigint) => number;
408
457
  readonly workerstate_step_batch: (a: number, b: number) => number;
409
458
  readonly workerstate_step_count: (a: number) => bigint;
410
- readonly wasm_bindgen__convert__closures_____invoke__he00a4f55faf9050f: (a: number, b: number) => void;
411
- readonly wasm_bindgen__closure__destroy__h2f2b52f94c430d4b: (a: number, b: number) => void;
459
+ readonly worker_entry: (a: number, b: any, c: bigint) => void;
460
+ readonly wasm_bindgen__convert__closures_____invoke__hf9330c20899fe446: (a: number, b: number) => void;
461
+ readonly wasm_bindgen__closure__destroy__h1f949ca759a20457: (a: number, b: number) => void;
412
462
  readonly wasm_bindgen__convert__closures_____invoke__h260170fb96639bcf: (a: number, b: number, c: any) => void;
413
463
  readonly wasm_bindgen__closure__destroy__h612f8e24953b61d5: (a: number, b: number) => void;
414
- readonly wasm_bindgen__convert__closures_____invoke__hd159192dfee36a06: (a: number, b: number) => void;
415
- readonly wasm_bindgen__convert__closures_____invoke__hedae94b906f728f2: (a: number, b: number, c: any) => void;
464
+ readonly wasm_bindgen__convert__closures_____invoke__h201459934189f4a1: (a: number, b: number, c: any) => void;
465
+ readonly wasm_bindgen__convert__closures_____invoke__h6b88ef80ef3d6675: (a: number, b: number) => void;
416
466
  readonly __wbindgen_malloc: (a: number, b: number) => number;
417
467
  readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
418
468
  readonly __wbindgen_exn_store: (a: number) => void;
@@ -535,6 +585,37 @@ interface VmOptions {
535
585
  * @returns WasmVm instance
536
586
  */
537
587
  declare function createVM(kernelData: Uint8Array, options?: VmOptions): Promise<WasmVm>;
588
+ interface SDBootInfo {
589
+ kernelData: Uint8Array;
590
+ sdcardData: Uint8Array;
591
+ fsPartitionStart: number;
592
+ }
593
+ /**
594
+ * Parse an SD card image to extract kernel from FAT32 boot partition.
595
+ *
596
+ * SD Card layout:
597
+ * - MBR with partition table
598
+ * - Partition 1 (FAT32): kernel.bin
599
+ * - Partition 2: SFS filesystem
600
+ */
601
+ declare function parseSDCard(sdcard: Uint8Array): SDBootInfo;
602
+ /**
603
+ * Fetch an SD card image from a URL for browser use.
604
+ *
605
+ * @param url - URL to fetch SD card image from
606
+ * @returns Parsed boot info with kernel and disk data
607
+ */
608
+ declare function loadSDCardFromUrl(url: string): Promise<SDBootInfo>;
609
+ /**
610
+ * Create a VM from an SD card image (fetched from URL).
611
+ *
612
+ * This is the recommended way to boot the VM in browser.
613
+ *
614
+ * @param sdcardUrl - URL to SD card image
615
+ * @param options - VM configuration options
616
+ * @returns WasmVm instance ready to run
617
+ */
618
+ declare function createVMFromSDCard(sdcardUrl: string, options?: VmOptions): Promise<WasmVm>;
538
619
  /**
539
620
  * Run the VM with an output callback for UART data.
540
621
  *
@@ -602,4 +683,4 @@ interface WorkerManager {
602
683
  */
603
684
  declare function createWorkerManager(): WorkerManager;
604
685
 
605
- export { NetworkStatus, REQUIRED_HEADERS, type SharedMemorySupport, type VmOptions, WasmInternal, WasmVm, type WorkerErrorMessage, type WorkerHaltedMessage, type WorkerInitMessage, type WorkerManager, type WorkerOutboundMessage, type WorkerReadyMessage, checkSharedMemorySupport, createVM, createWorkerManager, isCrossOriginIsolated, isHaltRequested, isHalted, requestHalt, runVM };
686
+ export { NetworkStatus, REQUIRED_HEADERS, type SharedMemorySupport, type VmOptions, WasmInternal, WasmVm, type WorkerErrorMessage, type WorkerHaltedMessage, type WorkerInitMessage, type WorkerManager, type WorkerOutboundMessage, type WorkerReadyMessage, checkSharedMemorySupport, createVM, createVMFromSDCard, createWorkerManager, isCrossOriginIsolated, isHaltRequested, isHalted, loadSDCardFromUrl, parseSDCard, requestHalt, runVM };