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

The type definitions and function declarations for Firefly Zero C SDK. More...

#include "firefly_bindings.h"
#include <stdbool.h>
#include <stdint.h>
Include dependency graph for firefly.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  Point
 A point on the screen. More...
struct  Size
 Size of a bounding box for a shape. More...
struct  Angle
 An angle between two vectors. More...
struct  Style
 Style of a shape. More...
struct  LineStyle
 The same as Style but without a fill color (only stroke color and width). More...
struct  RGB
 The RGB value of a color in the palette. More...
struct  Buffer
 A dynamically sized array. More...
struct  SubImage
 A subregion of an Image. More...
struct  Pad
 Get if the touchpad is pressed, and if so, where. More...
struct  DPad8
 8-directional DPad-like representation of the Pad. More...
struct  Buttons
 State of the buttons. True is pressed, false is released. More...
struct  Peers
 The bitmap of peers currently online. More...
struct  Progress
struct  Theme
 User preferred color scheme. More...
struct  Settings
 System settings. More...
struct  AudioNode
 A node in the audio tree. More...
struct  AudioTime
 A time or duration used by audio modulators. More...
struct  LinearModulator
 Linear (ramp up or down) envelope. More...
struct  HoldModulator
 Hold envelope. More...
struct  AdsrModulator
 ADSR envelope. More...
struct  SineModulator
 Sine wave low-frequency oscillator. More...
struct  SquareModulator
 Square wave low-frequency oscillator. More...
struct  SawtoothModulator
 Sawtooth wave low-frequency oscillator. More...

Macros

#define BOOT   __attribute__((export_name("boot")))
 Mark a "boot" callback function.
#define UPDATE   __attribute__((export_name("update")))
 Mark an "update" callback function.
#define RENDER   __attribute__((export_name("render")))
 Mark an "render" callback function.
#define CHEAT   __attribute__((export_name("cheat")))
 Mark a "cheat" callback function.
#define BEFORE_EXIT   __attribute__((export_name("BEFORE_EXIT")))
 Mark a "before_exit" callback function.
#define WIDTH   240
 Screen width.
#define HEIGHT   160
 Screen height.
#define SAMPLE_RATE   44100
 The sample rate of the audio engine.

Typedefs

typedef struct Point Point
typedef struct Size Size
typedef struct Angle Angle
typedef enum Color Color
typedef struct Style Style
typedef struct LineStyle LineStyle
typedef struct RGB RGB
typedef struct Buffer Buffer
typedef struct Buffer File
typedef struct Buffer Image
typedef struct Buffer Canvas
typedef struct Buffer Stash
typedef struct Buffer Font
typedef struct SubImage SubImage
typedef struct Pad Pad
typedef struct DPad8 DPad8
typedef enum DPad4 DPad4
typedef struct Buttons Buttons
typedef struct Peers Peers
typedef int32_t Peer
 An ID of a connected device in the multiplayer.
typedef uint32_t Badge
typedef uint32_t Board
typedef int32_t Score
typedef struct Progress Progress
typedef enum Language Language
typedef struct Theme Theme
typedef struct Settings Settings
typedef struct AudioNode AudioNode
typedef struct AudioTime AudioTime
typedef struct LinearModulator LinearModulator
typedef struct HoldModulator HoldModulator
typedef struct AdsrModulator AdsrModulator
typedef struct SineModulator SineModulator
typedef struct SquareModulator SquareModulator
typedef struct SawtoothModulator SawtoothModulator

Enumerations

enum  Color {
  NONE = 0 , BLACK = 1 , PURPLE = 2 , RED = 3 ,
  ORANGE = 4 , YELLOW = 5 , LIGHT_GREEN = 6 , GREEN = 7 ,
  DARK_GREEN = 8 , DARK_BLUE = 9 , BLUE = 10 , LIGHT_BLUE = 11 ,
  CYAN = 12 , WHITE = 13 , LIGHT_GRAY = 14 , GRAY = 15 ,
  DARK_GRAY = 16
}
 A pointer to a color in the color palette. More...
enum  DPad4 {
  DPAD4_NONE = 0 , DPAD4_LEFT = 1 , DPAD4_RIGHT = 2 , DPAD4_UP = 3 ,
  DPAD4_DOWN = 4
}
enum  Language {
  English , Dutch , French , German ,
  Italian , Polish , Romanian , Russian ,
  Spanish , Swedish , Turkish , Ukrainian ,
  TokiPona
}
 User interface language. More...

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 pad)
 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_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_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_image (Image img, Point p)
 Draw an image.
void draw_sub_image (SubImage s, 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.
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 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.
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.

Variables

const Peer COMBINED = 0xFF
 A peer ID representing all peers at once.
const AudioNode OUT = {.id = 0}
 The root audio node. Its child nodes are mixed and played on the device output.

Detailed Description

The type definitions and function declarations for Firefly Zero C SDK.

Enumeration Type Documentation

◆ Color

enum Color

A pointer to a color in the color palette.

Enumerator
NONE 

No color (100% transparency).

BLACK 

Black color: #1A1C2C.

PURPLE 

Purple color: #5D275D.

RED 

Red color: #B13E53.

ORANGE 

Orange color: #EF7D57.

YELLOW 

Yellow color: #FFCD75.

LIGHT_GREEN 

Light green color: #A7F070.

GREEN 

Green color: #38B764.

DARK_GREEN 

Dark green color: #257179.

DARK_BLUE 

Dark blue color: #29366F.

BLUE 

Blue color: #3B5DC9.

LIGHT_BLUE 

Light blue color: #41A6F6.

CYAN 

Cyan color: #73EFF7.

WHITE 

White color: #F4F4F4.

LIGHT_GRAY 

Light gray color: #94B0C2.

GRAY 

Gray color: #566C86.

DARK_GRAY 

Dark gray color: #333C57.

◆ Language

enum Language

User interface language.

Enumerator
English 

en 🇬🇧 💂

Dutch 

nl 🇳🇱 🧀

French 

fr 🇫🇷 🥐

German 

de 🇩🇪 🥨

Italian 

it 🇮🇹 🍕

Polish 

pl 🇵🇱 🥟

Romanian 

ro 🇷🇴 🧛

Russian 

ru 🇷🇺 🪆

Spanish 

es 🇪🇸 🐂

Swedish 

sv 🇸🇪 ❄️

Turkish 

tr 🇹🇷 🕌

Ukrainian 

uk 🇺🇦 ✊

TokiPona 

tp 🇨🇦 🙂

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].