Expand description
Primitives and constants from WASM-4 fantasy console
WASM-4 ships a w4
application that can generate a
preconfigured Rust crate to build a game.
That crate contains a wasm4
module that exports all primitives and
constants exposed by the console.
This crate replicates that module, documenting each public symbol and
adding few Rust attributes where needed, so that w4
is no longer
necessary to build a game.
Note that w4
application is still required to play the game or to
generate a self-contained cartridge from the final .wasm
artefact.
Constants§
- BLIT_
1BPP - Flag for 1-bit-per-pixel sprites
- BLIT_
2BPP - Flag for 2-bits-per-pixel sprites
- BLIT_
FLIP_ X - Flag for horizontally flipping sprites
- BLIT_
FLIP_ Y - Flag for vertically flipping sprites
- BLIT_
ROTATE - Flag for counter-clockwise rotating sprites
- BUTTON_
1 - Gamepad X button state bitmask
- BUTTON_
2 - Gamepad Z button state bitmask
- BUTTON_
DOWN - Gamepad down button state bitmask
- BUTTON_
LEFT - Gamepad left button state bitmask
- BUTTON_
RIGHT - Gamepad right button state bitmask
- BUTTON_
UP - Gamepad up button state bitmask
- DRAW_
COLORS - Address of current drawing colors
- GAMEPA
D1 - Address of first gamepad
- GAMEPA
D2 - Address of second gamepad
- GAMEPA
D3 - Address of third gamepad
- GAMEPA
D4 - Address of fourth gamepad
- MOUSE_
BUTTONS - Address of mouse buttons
- MOUSE_
LEFT - Mouse left button state bitmask
- MOUSE_
MIDDLE - Mouse middle button state bitmask
- MOUSE_
RIGHT - Mouse right button state bitmask
- MOUSE_X
- Address of mouse x coordinate
- MOUSE_Y
- Address of mouse y coordinate
- SCREEN_
SIZE - Width and height of the screen in pixels
- SYSTEM_
FLAGS - System flags
- SYSTEM_
HIDE_ GAMEPAD_ OVERLAY - Flag for hiding gamepad overlay
- SYSTEM_
PRESERVE_ FRAMEBUFFER - Flag for preserving framebuffer content between frames
- TONE_
MODE1 - Select 12.5% duty cycle
- TONE_
MODE2 - Select 25% duty cycle
- TONE_
MODE3 - Select 50% duty cycle
- TONE_
MODE4 - Select 75% duty cycle
- TONE_
NOISE - Select noise wave form
- TONE_
PULS E1 - Select first pulse wave form
- TONE_
PULS E2 - Select second pulse wave form
- TONE_
TRIANGLE - Select triangle wave form
Statics§
- FRAMEBUFFER
- Framebuffer memory region
- PALETTE
- System palette memory region
Functions§
- blit
- Copy pixels to the framebuffer
- blit_
sub - Copy a subregion within a larger sprite atlas to the framebuffer
- diskr⚠
- Read up to
size
bytes from persistent storage into the pointerdest
- diskw⚠
- Write up to
size
bytes from the pointersrc
into persistent storage - hline
- Draw a horizontal line
- line
- Draw a line between two points
- oval
- Draw an oval (or circle)
- rect
- Draw a rectangle
- text
- Draw text using the built-in system font
- tone
- Play a sound tone
- trace
- Print a message to the debug console
- vline
- Draw a vertical line