Skip to main content

Memory Layout

Endianness#

WebAssembly is, in general, a little-endian system.

Memory Map#

WASM-4 uses a fixed memory layout of 64 KB.

AddressSize (Bytes)Description
$00004Unused
$000416PALETTE
$00142DRAW_COLORS
$00164GAMEPADS
$001a2MOUSE_X
$001c2MOUSE_Y
$001e1MOUSE_BUTTONS
$001f1SYSTEM_FLAGS
$00201NETPLAY
$0021127Reserved for future use
$00a06400FRAMEBUFFER
$19a058976Available program memory

PALETTE#

An array of 4 colors, each represented by a 32 bit integer. Each color is laid out in memory like this:

BitsDescription
0 - 7Blue channel
8 - 15Green channel
16 - 23Red channel
24 - 31Unused

Example:

PALETTE[0] = 0xff0000; // Set the first palette color to red,PALETTE[1] = 0x00ff00; // the second to green,PALETTE[2] = 0x0000ff; // the third to blue,PALETTE[3] = 0xffffff; // and the fourth to white.

DRAW_COLORS#

Indexes into the color palette used by all drawing functions.

BitsDescription
0 - 3Draw color 1
4 - 7Draw color 2
8 - 11Draw color 3
12 - 15Draw color 4

Each draw color can be a value between 1 and 4 representing a palette color, or 0 to signify transparency.

Example:

// Set the first draw color to palette color #2, the second to// transparent, and the third to palette color #4.*DRAW_COLORS = 0x402;

GAMEPADS#

4 gamepads, with each gamepad represented by a single byte.

BitNameDescription
0BUTTON_1X button
1BUTTON_2Z button
2Unused
3Unused
4BUTTON_LEFTD-pad left
5BUTTON_RIGHTD-pad right
6BUTTON_UPD-pad up
7BUTTON_DOWND-pad down

MOUSE_X#

Signed 16 bit integer containing the X position of the mouse. Can contain positions outside of the game window.

MOUSE_Y#

Signed 16 bit integer containing the Y position of the mouse. Can contain positions outside of the game window.

MOUSE_BUTTONS#

Byte containing the mouse buttons state.

BitNameDescription
0MOUSE_LEFTLeft mouse button
1MOUSE_RIGHTRight mouse button
2MOUSE_MIDDLEMiddle mouse button

SYSTEM_FLAGS#

Byte containing flags that modify WASM-4's operation. By default all flags are off.

BitNameDescription
0SYSTEM_PRESERVE_FRAMEBUFFERPrevent clearing the framebuffer between frames.
1SYSTEM_HIDE_GAMEPAD_OVERLAYHide the gamepad UI overlay on mobile.

NETPLAY#

Byte containing netplay multiplayer state.

BitsDescription
0 - 1Local player index (0 to 3).
2Set if netplay is currently active.

FRAMEBUFFER#

Array of 160x160 pixels, with each pixel packed into 2 bits (colors 0 to 3).

This region can be freely modified for direct pixel manipulation.