Expand description
§wasmcart
Rust bindings for the wasmcart cart ABI (v3).
A wasmcart cart is a freestanding wasm32-unknown-unknown module that exports
memory, wc_get_info, wc_render (and, optionally but conventionally,
wc_init). There is no runtime to embed and no JS glue: this crate is a
binding, not an engine.
§Quick start
#![no_std]
use wasmcart::*;
wc_cart!(320, 240);
#[no_mangle]
pub extern "C" fn wc_init() {}
#[no_mangle]
pub extern "C" fn wc_render() {
for px in fb() {
*px = 0xFF3050C0;
}
}wc_cart! declares every buffer the ABI needs plus the live wc_info_t
struct, and emits wc_get_info. It also installs a panic handler that
reports the panic through wc_log before parking, so a panicking cart says
why instead of freezing silently.
§no_std
This crate is #![no_std] and has no dependencies. The optional std
feature exists only to let a cart that wants Vec/String link against
std; it is NOT enabled by default, and enabling it pulls in machinery that
makes the cart substantially larger.
Modules§
- gl
- OpenGL ES 3.0 / WebGL2 bindings, imported from the wasm module
gl. - key
- USB HID scancodes, as delivered in the
keys_ptrbitmask. - modifier
- Keyboard modifier bitmask values.
Macros§
- shader_
source - A NUL-terminated GLSL source literal, ready for [
compile_shader]. - wc_cart
- Declare a cart: buffers, the live
WcInfo,wc_get_info, and a panic handler that logs the panic message throughwc_logbefore trapping. - wc_
cart_ config - Declare a cart from an explicit
CartConfigconst expression.
Structs§
- Cart
Config - Cart configuration, consumed by
wc_cart!at compile time. - WcHost
Info - Written by the host before
wc_init, read by the cart once at init. - WcInfo
- The struct
wc_get_inforeturns a pointer to. All fields areu32; field order is load-bearing and matches the Cwc_info_texactly. - WcPad
- Gamepad state, 16 bytes. The host writes this before each
wc_render. - WcPointer
- Unified mouse/touch pointer, 8 bytes.
- WcTime
- Frame timing, 20 bytes and 8-byte aligned (two
f64then au32).
Constants§
- WC_
ABI_ VERSION - ABI version implemented by this crate.
- WC_
BTN_ A - WC_
BTN_ B - WC_
BTN_ DOWN - WC_
BTN_ L - WC_
BTN_ L3 - WC_
BTN_ LEFT - WC_
BTN_ R - WC_
BTN_ R3 - WC_
BTN_ RIGHT - WC_
BTN_ SELECT - WC_
BTN_ START - WC_
BTN_ UP - WC_
BTN_ X - WC_
BTN_ Y - WC_
FLAG_ AUDIO_ F32 - Audio ring buffer holds
f32samples rather thani16. - WC_
FLAG_ DEBUG - Cart exports
wc_debug_state(). Opt-in, default off. - WC_
FLAG_ DETERMINISTIC - Cart honors deterministic mode. Opt-in, default off.
- WC_
FLAG_ KEYBOARD - Cart wants raw keyboard input.
- WC_
FLAG_ NET_ DC - Cart wants data-channel imports.
- WC_
FLAG_ NET_ WS - Cart wants WebSocket imports.
- WC_
FLAG_ POINTER - Cart wants pointer (mouse/touch) input.
- WC_
GPU_ API_ NONE - 2D framebuffer only.
- WC_
GPU_ API_ VULKAN - Reserved.
- WC_
GPU_ API_ WEBG L2 - WebGL2 / OpenGL ES 3.0.
- WC_
GPU_ API_ WEBGPU - Reserved.
- WC_
HOST_ FLAG_ DETERMINISTIC - Host-info flag: this run is a deterministic replay.
- WC_
KEYS_ STATE_ SIZE - Bytes in the keyboard bitmask at
keys_ptr(256 keys). - WC_
MAX_ PADS - Pads exposed through
input_ptr. - WC_
MAX_ POINTERS - Pointers exposed through
pointer_ptr. - WC_
RUMBLE_ MAX_ MS - Longest single rumble effect the host will honor, in milliseconds.
Functions§
- key_
is_ down - Test a keycode against a 32-byte key-state bitmask.
- wc_
asset_ size - Size of an asset packed into the
.wascarchive, orNoneif absent. Bare.wasmcarts have no archive and always getNone. - wc_
debug_ mark - Stamp
{frame, id}into a debug-capable host’s event trace. - wc_
load_ asset - Load an archive asset into
dest. Returns bytes loaded, orNoneon error. - wc_log
- Write a message to the host’s debug log.
- wc_
pad_ has_ rumble - True if the host reports rumble support for this pad. Capability is per-device, so ask rather than assume.
- wc_
pad_ name - Copy the host’s name for
pad_idintobuf. Returns bytes written. - wc_
pad_ rumble - Start a rumble effect.
low/highare clamped to 0..1 by the host, andduration_msis capped atWC_RUMBLE_MAX_MS. Re-arm each frame for sustained rumble. - wc_
pad_ rumble_ stop - Stop any rumble effect on this pad.