Moss API

Detailed specification of the Moss API

Display

  • Fixed 256×144 resolution
  • 32-color palette (5-bit indexed color) (DawnBringer 32)
fn wait_vsync()

Waits for vertical retrace (typically 60 Hz).

fn clear(color: Int)

Clears the screen to a single color.

fn set(x: Int, y: Int, color: Int)

Sets a single pixel.

fn get(x: Int, y: Int) -> Int

Reads the color of a pixel.

Sprites

fn sprite(x: Int, y: Int, width: Int, colors: [U8])

Draws a sprite. Color 0 is transparent.

fn sprite_flip(x: Int, y: Int, width: Int, colors: [U8], flip_h: Bool, flip_v: Bool)

Draws a sprite with horizontal/vertical flipping.

fn sprite_ex(x: Int, y: Int, width: Int, height: Int, colors_offset: Int, colors_stride: Int, colors: [U8])

Advanced sprite() version where you control the colors_stride (how many pixels to advance for each Y) and colors_offset (where to start reading from in colors). Useful for drawing from sprite sheets.

struct TilemapExParams {
    tile_size: Int,     // Must be 8, 16, 32 or 64
    tile_offset: Int,   // Offset into the `tiles`. Normally 0.
    tile_stride: Int,   // How many tiles in total in a row in `tiles`
    colors_offset: Int, // Where to start in `colors`. Normally 0.
    colors_width: Int,  // The number of pixels in a row in `colors`
}

fn tilemap_ex(x: Int, y: Int, grid_width: Int, grid_height: Int, params: TilemapExParams, tiles: [U8], colors: [U8])

Draws a tilemap using an array of tile ids in tiles. Each tile id (0-255) indexes into the colors array to look up the pixel data for that tile. The tile_stride allows you to create larger tilemaps than what fits on screen, making it easy to scroll around in a bigger world by adjusting tile_offset.

Shapes

fn line(x0: Int, y0: Int, x1: Int, y1: Int, color: Int)

Draws a line.

fn box(x: Int, y: Int, width: Int, height: Int, color: Int)

Draws a filled rectangle.

fn box_outline(x: Int, y: Int, width: Int, height: Int, color: Int)

Draws a rectangle outline.

fn circle(x: Int, y: Int, radius: Int, color: Int)

Draws a circle outline.

fn circle_fill(x: Int, y: Int, radius: Int, color: Int)

Draws a filled circle.

Text

fn char(x: Int, y: Int, ch: U8, color: Int)

Draws a single character.

fn text(x: Int, y: Int, text: String, color: Int)

Draws a text string.

Input

struct Gamepad {
    up: Bool,
    down: Bool,
    left: Bool,
    right: Bool,
    a: Bool,
    b: Bool,
    start: Bool,
}

fn gamepad(player: Int) -> Gamepad

Reads gamepad state for player 0 or 1. (currently only 0 supported)

Audio

  • 8-voice mixer
  • 64 sounds with ADSR envelopes
  • Output: 22.05 kHz, 8-bit unsigned PCM, stereo.
struct Adsr {
    attack: Int,    // Attack time in milliseconds
    decay: Int,     // Decay time in milliseconds
    sustain: Float, // Sustain level (0.0 to 1.0)
    release: Int,   // Release time in milliseconds
}

struct SoundDefinition {
    adsr: Adsr,
    root_note: Int, // MIDI note number
}

fn sound_mono(id: Int, raw: [U8], sound: SoundDefinition)

Defines a mono sound (id: 0-63). The raw samples are unsigned 8-bit values.

fn sound_stereo(id: Int, raw: [U8], sound: SoundDefinition)

Defines a stereo sound (id: 0-63). The raw samples are unsigned 8-bit values interleaved (L,R,L,R,…).

fn note_on(voice: Int, note: Int, sound_id: Int, volume: Float)

Starts playing a note on a voice (0-7).

fn note_off(voice: Int)

Stops playing on a voice.

fn pan(voice: Int, pan: Float)

Sets voice panning (-1.0 = left, 0.0 = center, 1.0 = right).

The Link Port API provides software access to the Link Port hardware.

struct Net {
}

impl Net {
    fn new(host: String) -> Net
    fn write(mut self, enum_data: Any)
    fn read(mut self, mut enum_data: Any) -> Bool
}

Creates a link port connection to the specified endpoint (format: “host:port”).Messages are exchanged as enum-typed values using write() and read().

The read() method returns true if a message was received.

Example:

mut net := Net::new("127.0.0.1:50000")

net.write( YourEnum::YourVariant { x: 10 } )

mut receive_message := YourEnum::FirstVariant

msg_was_received := net.read(&receive_message)

if msg_was_received {
    // process receive_message
}