Firefly Zero
The official C SDK for making Firefly Zero apps.
Loading...
Searching...
No Matches
firefly.c File Reference

The function definitions for Firefly Zero C SDK. More...

#include "firefly.h"
#include "firefly_bindings.h"
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
Include dependency graph for firefly.c:

Functions

Angle radians (float a)
 An angle in radians where τ(2π) is the full circle.
Angle degrees (float a)
 An angle in degrees where 360.0 is the full circle.
AudioTime samples (int32_t s)
 Time in the number of samples.
AudioTime seconds (int32_t s)
 Time in seconds.
AudioTime miliseconds (int32_t s)
 Time in miliseconds.
DPad8 pad_to_dpad8 (Pad pad)
 Convert Pad to DPad8.
DPad4 pad_to_dpad4 (Pad self)
 Convert Pad to DPad4.
void clear_screen (Color c)
 Fill the whole frame with the given color.
void set_color (Color c, RGB v)
 Set a color value in the palette.
void draw_point (Point p, Color c)
 Set a single point (1 pixel is scaling is 1) on the frame.
void draw_line (Point a, Point b, LineStyle s)
 Draw a straight line from point a to point b.
void draw_rect (Point p, Size b, Style s)
 Draw a rectangle filling the given bounding box.
void draw_rounded_rect (Point p, Size b, Size c, Style s)
 Draw a rectangle with rounded corners.
void draw_circle (Point p, int32_t d, Style s)
 Draw a circle with the given diameter.
void draw_ellipse (Point p, Size b, Style s)
 Draw an ellipse (oval).
void draw_triangle (Point a, Point b, Point c, Style s)
 Draw a triangle.
void draw_arc (Point p, int32_t d, Angle start, Angle sweep, Style s)
 Draw an arc.
void draw_sector (Point p, int32_t d, Angle start, Angle sweep, Style s)
 Draw a sector.
void draw_text (char *t, Font f, Point p, Color c)
 Render a text message using the given font.
void draw_qr (char *t, Point p, Color black, Color white)
 Render a QR code for the given text.
void draw_image (Image i, Point p)
 Draw an image.
void draw_sub_image (SubImage i, Point p)
 Draw an image subregion.
void draw_sub_tile (SubImage i, Point p, Size s)
 Tile the given screen area with the provided sub-image.
void draw_nine_slice (SubImage i, Point p, Size s)
 Fill the given area with the given 9-slice.
void set_canvas (Canvas c)
 Set the target image for all subsequent drawing operations.
void unset_canvas ()
 Make all subsequent drawing operations target the screen instead of a canvas.
Pad read_pad (Peer peer)
 Read touchpad state: if it's pressed and where.
Buttons read_buttons (Peer peer)
 Get pressed buttons.
size_t get_file_size (char *path)
 Get size (in bytes) of the given file.
File load_file (char *path, Buffer buf)
 Read file from the given path into the given buffer.
void dump_file (char *path, File f)
 Write the given content into the given path.
void remove_file (char *path)
 Delete a file created using dump_file().
Peer get_me ()
 Get the Peer corresponding to the current device.
Peers get_peers ()
 Get a mapping of peers currently online.
bool is_online (Peers peers, Peer peer)
 Check if the given Peer is online.
void save_stash (Peer p, Stash s)
 Save the given Stash.
Stash load_stash (Peer p, Buffer s)
 Load Stash saved earlier (in this or previous run) by save_stash.
void log_debug (char *msg)
 Write a debug message.
void log_error (char *msg)
 Write an error message.
void set_seed (uintptr_t seed)
 Set the random seed. Useful for testing.
uintptr_t get_random ()
 Get a random integer.
Buffer get_name (Peer p, Buffer buf)
 Write device name into the given Buffer.
Color _parseColor (uint32_t c)
Settings get_settings (Peer p)
 Get system settings.
void restart ()
 Ask the runtime to restart the app after the current update iteration.
void quit ()
 Ask the runtime to exit the app after the current update iteration.
Progress add_progress (Peer p, Badge b, int16_t v)
 Add the given value to the progress for the badge.
Progress get_progress (Peer p, Badge b)
 Get the progress of earning the badge.
Score add_score (Peer p, Board b, Score v)
 Add the given score to the board.
Score get_score (Peer p, Board b)
 Get the personal best of the player.
AudioNode add_sine (AudioNode parent, float freq, float phase)
 Add sine AudioNode as a child node for the given node.
AudioNode add_square (AudioNode parent, float freq, float phase)
 Add square AudioNode as a child node for the given node.
AudioNode add_sawtooth (AudioNode parent, float freq, float phase)
 Add sawtooth AudioNode as a child node for the given node.
AudioNode add_triangle (AudioNode parent, float freq, float phase)
 Add triangle AudioNode as a child node for the given node.
AudioNode add_noise (AudioNode parent, int32_t seed)
 Add noise AudioNode as a child node for the given node.
AudioNode add_empty (AudioNode parent)
 Add empty AudioNode as a child node for the given node.
AudioNode add_zero (AudioNode parent)
 Add zero AudioNode as a child node for the given node.
AudioNode add_file (AudioNode parent, char *path)
 Add file AudioNode as a child node for the given node.
AudioNode add_mix (AudioNode parent)
 Add mix AudioNode as a child node for the given node.
AudioNode add_all_for_one (AudioNode parent)
 Add allforone AudioNode as a child node for the given node.
AudioNode add_gain (AudioNode parent, float lvl)
 Add gain AudioNode as a child node for the given node.
AudioNode add_loop (AudioNode parent)
 Add loop AudioNode as a child node for the given node.
AudioNode add_concat (AudioNode parent)
 Add concat AudioNode as a child node for the given node.
AudioNode add_pan (AudioNode parent, float lvl)
 Add pan AudioNode as a child node for the given node.
AudioNode add_mute (AudioNode parent)
 Add mute AudioNode as a child node for the given node.
AudioNode add_pause (AudioNode parent)
 Add pause AudioNode as a child node for the given node.
AudioNode add_track_position (AudioNode parent)
 Add trackposition AudioNode as a child node for the given node.
AudioNode add_low_pass (AudioNode parent, float freq, float q)
 Add lowpass AudioNode as a child node for the given node.
AudioNode add_high_pass (AudioNode parent, float freq, float q)
 Add highpass AudioNode as a child node for the given node.
AudioNode add_take_left (AudioNode parent)
 Add takeleft AudioNode as a child node for the given node.
AudioNode add_take_right (AudioNode parent)
 Add takeright AudioNode as a child node for the given node.
AudioNode add_swap (AudioNode parent)
 Add swap AudioNode as a child node for the given node.
AudioNode add_clip (AudioNode parent, float low, float high)
 Add clip AudioNode as a child node for the given node.
void audio_reset (AudioNode node)
 Reset the state of the given AudioNode.
void audio_reset_all (AudioNode node)
 Reset the state of the given AudioNode and all its child nodes.
void audio_clear (AudioNode node)
 Remove all child nodes from the given AudioNode.
void audio_set (AudioNode node, float val)
 Set an audio node's main parameter value.
void mod_linear (AudioNode node, float low, float high, LinearModulator mod)
 Modulate an audio node's main parameter using LinearModulator.
void mod_hold (AudioNode node, float low, float high, HoldModulator mod)
 Modulate an audio node's main parameter using HoldModulator.
void mod_adsr (AudioNode node, float low, float high, AdsrModulator mod)
 Modulate an audio node's main parameter using AdsrModulator.
void mod_sine (AudioNode node, float low, float high, SineModulator mod)
 Modulate an audio node's main parameter using SineModulator.
void mod_square (AudioNode node, float low, float high, SquareModulator mod)
 Modulate an audio node's main parameter using SquareModulator.
void mod_sawtooth (AudioNode node, float low, float high, SawtoothModulator mod)
 Modulate an audio node's main parameter using SawtoothModulator.

Detailed Description

The function definitions for Firefly Zero C SDK.

Function Documentation

◆ add_progress()

Progress add_progress ( Peer p,
Badge b,
int16_t v )

Add the given value to the progress for the badge.

May be negative if you want to decrease the progress. If zero, does not change the progress.

If the Peer is COMBINED, the progress is added to every peer and the returned value is the lowest progress.

◆ add_score()

Score add_score ( Peer p,
Board b,
Score v )

Add the given score to the board.

May be negative if you want the lower scores to rank higher. Zero value is not added to the board.

If the Peer is COMBINED, the score is added for every peer and the returned value is the lowest of their best scores.

◆ draw_nine_slice()

void draw_nine_slice ( SubImage i,
Point p,
Size s )

Fill the given area with the given 9-slice.

A 9-slice is used to tile an area with 9 sub-images: 4 corners, 4 edges, and 1 middle segment. It is useful for speech bubbles and other stylish boxes.

The whole image is the 9-slice. The sub-image is the center area of the 9-slice.

If the target area is bigger than the 9-slice segments, all the segments (except corners) are repeated ("tiled") without stretching or mirroring.

◆ dump_file()

void dump_file ( char * path,
File f )

Write the given content into the given path.

The created file can be loaded using [LoadFile] but only in a singleplayer game.

◆ get_file_size()

size_t get_file_size ( char * path)

Get size (in bytes) of the given file.

Useful for dynamically allocating Buffer of the right size for [load_file].

◆ get_name()

Buffer get_name ( Peer p,
Buffer buf )

Write device name into the given Buffer.

The buffer size must be at least 16 bytes.

◆ is_online()

bool is_online ( Peers peers,
Peer peer )

Check if the given Peer is online.

Accepts the bitmap of Peers returned by get_peers(). The Peer can be obtained by a for loop from 0 to 31.

◆ load_file()

File load_file ( char * path,
Buffer buf )

Read file from the given path into the given buffer.

The resulting File uses the same memory as the given Buffer but has its size adjusted to the file size.

◆ load_stash()

Stash load_stash ( Peer p,
Buffer s )

Load Stash saved earlier (in this or previous run) by save_stash.

The buffer should be big enough to fit the stash. If it's not, the stash will be truncated. If there is no stash or it's empty, nil is returned.

If the given buffer is nil, a new buffer will be allocated big enough to fit the biggest allowed stash. At the moment, it is 80 bytes.

◆ remove_file()

void remove_file ( char * path)

Delete a file created using dump_file().

Files in ROM cannot be deleted.

◆ save_stash()

void save_stash ( Peer p,
Stash s )

Save the given Stash.

When called, the stash for the given peer will be stored in RAM. Calling load_stash() for the same peer will return that stash. On exit, the runtime will persist the stash in FS. Next time the app starts, calling load_stash() will restore the stash saved earlier.

◆ unset_canvas()

void unset_canvas ( )

Make all subsequent drawing operations target the screen instead of a canvas.

Cancels the effect of [set_canvas].