Rinc

Rinc is a small computer for making and playing little games, in the spirit of PICO-8. It boots in an instant to its home screen and a console, and its programs, called apps, are written in Rio. It runs on RP2350 boards (the Adafruit Fruit Jam first), on the desktop, and in the browser, and an app runs the same on all of them.

Apps are Rio programs, so the Rio docs cover the language.

Home

Home (system/home/home.rio, a system app) is where a Rinc starts: the apps it has, in storage and built in, in order of their titles, each with what it does.

keys
typingnarrow the list to the apps whose name or title has what's typed
up, down (or the d-pad)pick an app
Page Up, Page Down, Home, Enda page up or down, the first, the last
Enter (or A)start it
Escclear what's typed
Ctrl+Entermake it the active app (or project, chord+) and open it in the editor: a yellow mark at its left shows the active one
a click (or A, pointing)pick the app clicked; a click on the one picked starts it
the wheel (or the right stick)pick an app further up or down

A controller's left stick moves the pointer, and its d-pad picks apps, as the arrows do.

From any app, the system key with Esc comes back here: the Windows key (on a Fruit Jam), a controller's guide button, or Ctrl and Shift tapped together, and then Esc. The system key with Tab switches among the apps used lately, with Q goes back to the app before, with R starts this one again, afresh (compiled anew, without what it kept of where it was), and with H shows its help. With the arrows it moves the pointer, and V and C click.

An app's title and description come from its first line, a comment: # Bounce: the arrow keys tilt gravity. An app named home in storage takes this one's place.

Help

Help (system/help/help.rio, a system app) reads the help texts a Rinc has: Rinc's docs and Rio's, these pages among them, and any app's own. It starts where it was last, or with the contents: a list of the sets of texts, each by its own table of contents.

Moving about

keys
up, down, Page Up, Page Down, Home, Endscroll
Tab, Shift+Tabpick the next link, or the one before
Enterfollow the picked link: to another text, or a heading in one
Backspace, Esc, Alt+Leftback
Alt+Rightforward
Alt+Upup: to a text's contents, then to all of them
Alt+Home, Ctrl+Oall the contents

With a mouse, a click follows a link, the wheel scrolls, and the right button goes back. With a controller, the d-pad scrolls, LB and RB (or left and right) pick links, A follows the picked link and B goes back; or the left stick moves the pointer, A clicks the link it's on, and the right stick scrolls. Links to web pages show where they go but don't open.

Help remembers the last 32 places it's been, back and forward, and where it was in each, through a restart; and its contents page, made again when an app comes or goes. That's its stash, which the system key with R drops, to start over, finding any help texts changed since.

Help texts

A help text is Markdown: headings, paragraphs, lists, tables, code (in blocks and inline), strong and emphasized text, and links. Rinc finds them in two kinds of place:

  • An app's own, in its help folder: /apps/chord/help/keys.md is the text chord/keys. They come and go with the app, and are edited with it.
  • Those that are no app's, in /help: /help/rinc/spec/apps.md is rinc/spec/apps. Rinc's docs are the set rinc, and Rio's rio.

A Rinc's bundle can carry help texts the same way (the Fruit Jam's carries Rinc's and Rio's docs), and a text in storage takes the place of a bundled one of the same name. A set with a SUMMARY text is listed in the contents by that, as these docs are.

For apps

An app opens help at a text, and a heading in it, by calling it: pc.call("help", "rio/spec/statements#if"). The rest of what help uses is there for any app: see "Help texts", in "Apps and storage", in Rinc's docs.

Editor

The editor (system/edit/edit.rio, a system app) edits a file at a time, by path (an app's source, its other files, its help, its saves), up to 32 KB, with the keys of most editors. Ctrl+O opens one through Files, and Ctrl+Shift+S saves as another, through Files too, which asks where. Ctrl+R saves it and runs the app or project it's in, and the system key with Tab comes back to the editor. If the app stopped with an error, a compile error or a runtime one, the editor comes back at it: in the file it was in (one of the app's parts, say), the cursor on it, and what was wrong at the bottom. Ctrl+Shift+P (or the system key with P) lists every command, with its keys.

Projects are where apps are worked on: chord+ is app chord in work, in /projects, with saves of its own (a copy of the app's), so trying things can't spoil the app's. An installed app's files are read only, for reading; saving one saves it in the app's project, made from the app first, and Ctrl+R on it, unchanged, runs the app. Files (or the console's install chord) installs project chord+ as the app.

The app or project of the file it has open is the active one, the whole Rinc's setting, and it starts with what's active (another app can pick one for it), else the file it had last, where it was.

Keys

keys
arrows, Home, End, Page Up, Page Downmove: with Ctrl, by words and to either end; with Shift, select
Ctrl+O, Ctrl+S, Ctrl+Shift+Sopen a file (Files picks it), save it, save it as another (Files picks where)
Ctrl+Tab, Ctrl+Shift+Tabthe files had lately (the last 8), listed while Ctrl's held: Tab moves down it (Shift+Tab up), letting go of Ctrl opens the one picked where it was, and Esc closes it. A quick Ctrl+Tab goes back and forth between two
Ctrl+Wclose this file: out of the files had lately, the one before it opened where it was (none left: a new file). Not saved: Ctrl+W again drops the changes
Ctrl+R, Ctrl+Nsave and run its app or project, start a new file
Ctrl+Shift+Pevery command, to type to narrow and pick one (the system's list: the system key with P too)
Ctrl+Z, Ctrl+Y (or Ctrl+Shift+Z)undo, redo
Ctrl+X, Ctrl+C, Ctrl+Vcut, copy, paste (the whole line, with nothing selected), on the clipboard every app shares: text another app copied pastes here too
Ctrl+A, Ctrl+Lselect all, select the line (and the next, again)
Tab, Shift+Tabindent, outdent (the selected lines)
Alt+Up, Alt+Down, Ctrl+Shift+Kmove the lines up or down, delete them
Ctrl+Shift+Jjoin the next line onto this one (or the selected lines)
Ctrl+Spacecomplete the word
Ctrl+/comment the lines (the selected ones, or the cursor's), or uncomment them
Ctrl+Backspace, Ctrl+Deletedelete a word
Ctrl+F, Ctrl+Gfind (Enter finds the next), go to a line
Esclet go of the selection, or close the bar at the bottom

With a mouse, a click puts the cursor there and dragging selects (past the top or bottom, scrolling), and the wheel scrolls (sideways too, tilted, or on a trackpad, as far as the longest line in view). In the list of apps that Ctrl+O shows, a click opens one, and a click outside the list closes it. A controller's left stick moves the pointer, A clicks, and the right stick scrolls, up and down or sideways.

Writing Rio

Enter keeps the line's indent, and goes a step further in after a line that opens a block (if, for, a proc and so on); end, else and case step back out as they're typed. In a comment line, Enter goes on with the comment (its # again), and on an empty one, ends it. Tab and Backspace move by whole steps of two spaces in the indent. Rio's keywords, strings, numbers and comments each have a color of their own.

Ctrl+Space offers what could finish the word at the cursor, as Rio sees it there: the names in scope (the proc's own parameters and locals first), with what each is (a variable's type, a proc's parameters), and Rio's words that fit (a statement's, an expression's, and, or and is after a value); then the file's own words. With just one, it's put in. After a dot, it's what's before the dot has: a value's fields and methods (len and push too, where its kind has them), a type's values and static procs (pc.Rect.), a module's names (pc.). The list opens only for Ctrl+Space, never by itself, so typing is never held up: Rio's view of the file comes from checking it, up to the cursor's line, and on the board a big app's check takes about half a second. Typing narrows the list; Up and Down (and Page Up and Down) pick, Tab or Enter puts the pick in, a click puts one in, and Esc or any other key closes it.

A pause in typing checks the whole file: its first error is underlined, with a mark beside its line, and what it says shows at the bottom while the cursor's on that line. Line numbers are off at first (a mark beside the cursor's line stands in for them, and the top bar has its number): ^Shift+P, Line numbers, shows them, and the editor remembers.

Saving a .rio file lays it out the one way, as rio fmt does: only spaces and line breaks change (and a trailing comma may be added), and the cursor stays on the same code, where it was on the screen. A list in brackets goes on one line, unless it ends with a trailing comma (then an item a line) or has a line break after its opening bracket (then its items on a line of their own); add the comma to put it over lines, and take it off, with Ctrl+Shift+J on the opening bracket's line, to bring it back. Code between # nofmt and # /nofmt comment lines is left as it is. Ctrl+Z undoes the layout.

Undo groups typing by words, and goes back as far as the file was opened: it's kept on the card (the editor's stash), so it's there after another app has run, or Rinc has started again. When there's an app with unsaved changes, opening another or starting a new one asks first.

Console

The console (system/console/console.rio, a system app) runs Rio as it's typed, a line or a block at a time, in a session of its own: try things out, and look at what apps do. On the Fruit Jam, Ctrl+C over the USB serial port opens it from anywhere, which is how tools/send.py sends apps.

Typing Rio

What's typed is Rio: a statement runs when it's complete, and a block (a proc, an if, a loop) when its end comes. A value on its own is shown. Up and down bring back lines typed before: they're kept in /save/console/history.txt (8 KB of them, a few hundred lines), so they're there after another app's run, or a restart.

> x := 6 * 7
> sq :: proc(n: Int) -> Int
.   return n * n
. end
> sq(x)
1764

Commands

A line on its own can be a command instead:

command
runrun what's been typed as a game (its update* and draw*), until Esc
lslist the apps, and the projects (a + after the name: chord+)
run namerun app name, as itself
delete nameremove app name
install nameinstall project name+ as app name (its dev folder, its own saves and tests, stays with the project)
active, active namesay which app or project is active (what the editor opens), or make name it
homeback home
history, history clearthe last 20 lines typed, or forget them all (its file too)

Each name can be a project's, with its +: run chord+ runs project chord+, with its own saves. Apps are written in the editor; a library is tried here by typing its import (import clip), its names there after.

A first app

An app is a Rio program, in one .rio file. Its top-level code runs once, and then, if it defines update* and draw*, Rinc calls them 60 times a second. Everything Rinc can do is in the module pc, which every app has without an import:

x := 0
update* :: proc()
  x += 1
end
draw* :: proc()
  pc.cls(1)                       # dark blue
  pc.rect({x % 320, 100}, {20, 20}, 8)  # a red square, moving right
  pc.print("HELLO", {10, 10}, 7)
end

The * marks update and draw so Rinc can find them. Both are optional: an app with neither just runs its top-level code, which suits trying things out.

Running it

  • In a browser: the demo page runs the apps in this repository.
  • On the desktop: rinc hello.rio opens a window. See the desktop.
  • On the Fruit Jam: put it on the SD card as /apps/hello/hello.rio, and pick it in the list at home; or type or paste it into the console and type run. See the Fruit Jam.

log

log prints to the console (the terminal on the desktop, the console and the USB serial port on the board), which is handy while working on an app:

total := 0
for i in 1..=10
  total += i
end
log("total", total)
total 55

Next: drawing.

Drawing

The screen is 320 by 240 pixels, x from the left and y from the top. Each pixel is a color number from 0 to 255, picked from Rinc's palette: the 16 PICO-8 colors first, then PICO-8's 16 secret colors, then a band of 16 for each of 12 hues, then 16 tints and 16 grays. The screen keeps what's drawn until something draws over it, so a game usually starts its draw with pc.cls.

pc.cls(0)                        # fill the screen: black
pc.pset({5, 5}, 8)                 # one red pixel
pc.rect({10, 20}, {30, 10}, 12)      # x, y, width, height, color: blue
pc.print("SCORE 12", {0, 40}, 7)   # text, 6 pixels a character
log(pc.pget({5, 5}), pc.pget({15, 25}), pc.pget({400, 0}))
8 12 0

Drawing off the screen is fine: it's cut off at the edges, and reading a pixel off the screen gives 0.

The palette

colors
0 to 15PICO-8's: 0 black, 1 dark blue, 2 dark purple, 3 dark green, 4 brown, 5 dark gray, 6 light gray, 7 white, 8 red, 9 orange, 10 yellow, 11 green, 12 blue, 13 lavender, 14 pink, 15 peach
16 to 31PICO-8's secret palette, darker and in-between shades of those (see the screen)
32 to 223a band of 16 for each hue: red, orange, yellow, lime, green, teal, cyan, azure, blue, violet, magenta, crimson. Each is 8 vivid colors, dark to light, then 8 muted ones
224 to 239tints: 8 warm grays, then 8 cool ones, dark to light
240 to 255grays, black to white

The Colors app shows them that way, a band to a row, and says what each is.

RED :: 0      # the hues, in their order
ORANGE :: 1
BLUE :: 8
vivid :: proc(hue, step: Int) -> Int    # step 0, darkest, to 7, lightest
  return 32 + 16 * hue + step
end
muted :: proc(hue, step: Int) -> Int
  return 32 + 16 * hue + 8 + step
end
gray :: proc(step: Int) -> Int          # 0, black, to 15, white
  return 240 + step
end
for x in 0..<8
  pc.rect({x * 20, 0}, {20, 20}, vivid(ORANGE, x))   # dark brown to light orange
end
log(vivid(RED, 0), muted(BLUE, 7), gray(15), pc.rgb(gray(15)))
32 175 255 16777215

Pictures as data

Rinc has no sprite format of its own: a picture is just bytes, one color number each, drawn with pset. hexBlob writes them in the app:

heart := hexBlob(
  "00 08 00 08 00
  "08 08 08 08 08
  "00 08 08 08 00
  "00 00 08 00 00"
)
drawPic :: proc(pic: Blob, w, x, y: Int)
  for c, i in pic
    if c != 0                    # 0: see-through
      pc.pset({x + i % w, y + i / w}, c)
    end
  end
end
drawPic(heart, 5, 100, 100)
log(pc.pget({101, 100}), pc.pget({100, 100}))
8 235

(The 235 is the screen's background, Steel's dark gray, from before anything was drawn there.)

Next: input.

Input

Buttons

pc.btn(b) is 1 while button b (.left, .a and the like: a pc.Button) is held, else 0; pc.btnp(b) is 1 as it's pressed, and again while it's held, as PICO-8's. The arrow keys and the first four face buttons work everywhere, on the keyboard or on a controller's d-pad and buttons:

bbuttonkey
.left .right .up .downthe arrowsthe arrows
.aAV
.bBC
.xXX
.yYZ
.lb .rb .ls .rs .start .backa controller's LB, RB, left stick pressed, right stick pressed, Start, Back
x := 160
update* :: proc()
  x += pc.btn(.right) - pc.btn(.left)     # right minus left
  if pc.btn(.a) == 1
    log("A")
  end
end
draw* :: proc()
  pc.cls(0)
  pc.rect({x, 200}, {16, 8}, 7)
end

Sticks and triggers

pc.stick(i) reads a controller's sticks, from -1 to 1 (i: 0 left stick x, 1 its y, 2 and 3 the right stick's; down is +), and pc.trigger(i) its triggers, from 0 to 1 (0 left, 1 right). Without a controller they're 0. The left stick pushed well over also presses the arrow buttons.

Typing

pc.key() gives the next character typed, or -1 when there's none: for names, chat or a typed-in command. It's the printable ASCII characters, 13 for Enter, 8 for Backspace and 27 for Esc. Keys held down still press buttons too, so an app can use either.

name: Blob[..16]
update* :: proc()
  for
    c := pc.key()
    if c < 0
      break
    end
    if c == 8 and name.len() > 0
      _ = name.pop()
    case c >= 32
      _ = name.push(c)
    end
  end
end
draw* :: proc()
  pc.cls(1)
  pc.print(name[].asString(), {10, 10}, 7)
end

Time

pc.appTime() is seconds since the app started, as a Float; pc.appTimeReset() starts it from 0 again (at a level's start, say). Frames come 60 times a second, so counting frames also measures time.

Next: sound.

Sound

Rinc plays sound on 16 voices, numbered 0 to 15. A voice plays bytes from the app's own memory, at whatever rate it's told, so an app can make sound by computing it, or carry recorded sound as data.

wave: Blob[2048]
for i in 0..<wave.len()
  wave[i] = (i / 16 % 2) * 60 - 30 # a square wave: 8-bit signed samples
end
pc.sound(0, wave[], {bits = 8, rate = 22050.0})  # voice 0: 8-bit samples, 22050 a second
log(pc.soundPlaying(0))
1

pc.sound(voice, data, s) starts data playing on that voice, once, from the start, at full volume and centered. s, a pc.Sound, says how to read it: bits 16 or 8 (signed samples) or 4 (IMA ADPCM, below), channels 1 or 2, and rate, frames a second. What's left out is 0, which means 16 bits, 1 channel and 16000 a second, so pc.sound(0, data, {}) plays 16-bit mono at 16000. While it plays:

  • pc.soundSet(v, .rate, rate) changes its speed, and so its pitch.
  • pc.soundSet(v, .volume, volume) from 0 to 1, and pc.soundSet(v, .pan, pan) from -1 (left) to 1 (right).
  • pc.soundLoop(v, start, stop) makes it go back to frame start each time it reaches frame stop, for music and engine hums (stop 0: no loop).
  • pc.soundStop(v) stops it, and pc.soundPlaying(v) is 1 while it plays.

The voice reads the bytes as it plays, so they have to stay put: keep sound in globals.

Notes, on the synth

A voice can play notes instead, made into sound as it goes: 4 bytes a note, its pitch (0 is C0, and a semitone a step), wave, volume (0 to 7) and effect, as Sound (studio/sound) keeps them.

tune: Blob[16]
for i in 0..<4
  tune[i * 4] = 24 + i * 4  # pitch: C2, E2, G#2, C3
  tune[i * 4 + 1] = 3       # square
  tune[i * 4 + 2] = 5       # volume
end
pc.synth(0, tune[], 20)     # voice 0, each note 20 120ths of a second
pc.soundLoop(0, 0, 4)       # notes 0 to 3, over and over
log(pc.soundPlaying(0))
1

The waves are triangle, tilted, saw, square, pulse, organ, noise and phaser (0 to 7), and the effects slide, vibrato, drop, fade in, fade out and two arpeggios (1 to 7): see the synth. pc.synthMake(out, notes, speed) makes the same sound into a byte builder, 16-bit at 16,000 samples a second, for a WAV file or to change before playing it.

Each voice has settings of its own, which change what it's playing as they're set:

saw: Blob[4]
saw[0] = 36                    # C3
saw[1] = 2                     # saw
saw[2] = 7
pc.synth(0, saw[], 30)
pc.soundSet(0, .synthRate, 48000.0) # samples made a second: cleaner high notes, for 3 times the work
pc.soundSet(0, .smooth, 1)          # the saw, square and pulse rounded off where they jump: cleaner, cheaply
pc.soundSet(0, .bend, 0.5)          # every pitch up a quarter tone
pc.soundSet(0, .attack, 0.2)        # notes rise slowly (0.2 seconds)
pc.soundSet(0, .release, 1.0)       # and fall more slowly still
log(pc.soundPlaying(0))
1

Voice -1's settings are the ones synthMake uses. Waves 8 to 15 are the app's own: pc.synthWave(8, cycle[]) makes wave 8 one cycle of 16-bit samples, which any voice plays at any pitch.

Recorded sound

IMA ADPCM keeps sound in a quarter of the space of 16-bit, and sounds close to it: a second of 22 kHz mono is 11 KB. tools/adpcm.py turns a 16-bit WAV file into Rio source for an app, which pc.fromHex reads into a Blob (see apps/chord, its sound in parts/sound.rio). pc.soundWav(voice, data) plays a whole WAV file's bytes, 16-bit or ADPCM, at its own rate.

Next: apps and home.

Apps and home

On a Rinc with storage, such as the Fruit Jam's SD card, each app is a Rio file in a folder of its own name: /apps/bounce/bounce.rio. Home lists them, and its first line describes it:

# Bounce: the arrow keys tilt gravity

Home is an app too (system/home/home.rio), using procs any app can:

  • appfiles.list(out) (Rinc's library) looks for the apps, adds a line for each to a Blob (its name, a tab, and its first line without the #), and says how many there are.
  • pc.launch(name) starts an app (or home, or console) after the current frame.

So is the console (system/console/console.rio): it runs the Rio you type in a session of its own, with pc.rioStart, pc.rioEval and the rest (see Rio inside an app), and reads and writes apps with Rinc's library appfiles (appfiles.source, appfiles.save, appfiles.remove). And so is the editor (system/edit/edit.rio), which opens, saves and runs apps the same way.

The system key with Esc always goes home: Windows+Esc, a controller's Xbox+Back, or Ctrl and Shift tapped together and then Esc.

What a Rinc is

This part says what every Rinc provides, so an app that runs on one runs the same on all of them: the Fruit Jam, the desktop and the web today, and any other Rinc someone makes. Where this implementation doesn't match yet, the page says so.

A Rinc provides:

  • Rio, the language apps are written in, at the version in lib/rio.
  • The pc module: src/core/pc.rio, built into Rinc and compiled with each app (and in the console): its host procs, with exactly those names and types, and the types they use, such as pc.Pointer, visible in every module without an import. Every host proc this Rinc registers must be declared there, with matching types, or nothing compiles; the tests check it too.
  • Running apps: compiling one, then its frames, 60 a second.
  • The screen: 320x240, a 256-color palette, and a 5x8 font.
  • Input: buttons, a controller's sticks and triggers, typed text and time.
  • Sound: 16 voices playing from the app's memory.
  • Memory: 256 KB for each app, and nothing allocated while it runs.
  • Apps and storage: apps, home, the console and the system key.
  • Rio inside an app: a session of Rio that an app runs, for a console or an editor.

A Rinc can have more than this, such as a debugger or a volume knob, but an app can't depend on it.

Running apps

An app is one Rio source file. To run it, a Rinc:

  1. Starts fresh: an empty app space, every voice stopped, no typed text waiting.

  2. Compiles the whole app, with pc auto-imported, as memory says. If it doesn't compile, it doesn't run, and the first error is shown. Nothing of it runs.

  3. Runs its top-level code, then its main proc if it has one.

  4. Runs frames, if the app has update* or draw* (exported, so the Rinc can find them), 60 times a second until the app is left. Each frame:

    1. The Rinc sets the buttons, sticks and triggers as they are now, and queues what was typed since the last frame.
    2. It calls update, then draw, each if the app has it.
    3. It shows the screen as the app left it. The screen isn't cleared between frames.

    An app with neither update nor draw isn't a game: it's done once main returns.

A runtime error stops the app, showing the error and its line. log writes a line where the Rinc shows text: on the screen while an app starts or once it's done (but not over a game's frames), and to a serial port or a terminal.

An app is left for another with pc.launch, or for home with the system key. Leaving stops every voice.

Frames come 60 a second. An app that takes too long gets its frames late (how a Rinc catches up, if it does, is its own), so for real time, use pc.appTime().

The screen

The screen is 320 pixels wide and 240 high, x from the left and y from the top. Each pixel holds a color number, 0 to 255. A Rinc shows it at any whole-number scale (the Fruit Jam's HDMI output is 640x480, each pixel 2x2). An app starts with the screen all the theme's background (pc.theme(.bg); 235, Steel's dark gray, without one): Rinc's text screen, where what it logs shows until it draws, and where Rinc shows what went wrong if it fails.

Drawing

proc
pc.cls(c)every pixel becomes c
pc.pset({x, y}, c)pixel x, y becomes c; nothing happens off the screen
pc.pget({x, y}) -> Intpixel x, y, or 0 off the screen
pc.rect({x, y}, {w, h}, c)pixels from x up to x + w, and y up to y + h, become c; cut off at the screen's edges; nothing when w or h is 0 or less
pc.rect(pos, size, c, {outline = true, radius = r})its edge alone, a pixel wide; its corners rounded by r pixels (at most half its width or height)
pc.ellipse({x, y}, {w, h}, c)the ellipse in that rectangle (a square: a circle); a pixel's drawn if its center's inside; {outline = true}: its edge alone, with no gaps
pc.triangle(p, q, r, c)the triangle with those corners (pixels: each in it); {outline = true}: its three edges, as line draws them
pc.curve(from, c1, c2, to, c)a curve (cubic Bezier; its points [2]Float, between pixels too) from from to to, pulled toward c1 then c2 (both the same point: a gentler, quadratic-like bend); as lines a few pixels long, both ends drawn
pc.polygon(points, c, how?)a polygon, its corners in order ([][2]Float: between pixels too, a pixel in if its center is) ({{10, 10}, {40, 10}, {25, 30}}), the last joined to the first; filled where its edges wind around (crossing itself: still filled), each corner's pixel in; at most 64 edges crossing any one row; {outline = true}: its edges; two points: a line
p: pc.Path, then p.clear(), p.move(to), p.line(to), p.curve(c1, c2, to), p.arc(center, radii, from, to), p.close(), p.draw(c, how?)a path of lines, curves and arcs (angles in radians, as sin and cos: 0 right, a quarter turn down; an arc begins with a line from where the path is), in parts (move starts one); kept in the app's memory, 128 points at most (a curve or an arc takes 3); filled: each part closed, filled where its edges wind around (a part inside another going the other way round: a hole; move to the center, arc, close: a pie's slice); {outline = true}: its lines, a part closed only by close
pc.transform(m), pc.transformBy(m)the transform all drawing goes through (pset, line, rect, ellipse, triangle, curve, polygon, paths, blit, print): m is a, b, c, d, e, f, the plane the pixels tile (pixel x, y the square from x, y to x + 1, y + 1) taken to a x + c y + e, b x + d y + f, an image's or a rect's whole area with it (a scale of 2: as blit's own); a pixel's drawn if its center lands inside; an image, each screen pixel taken back to the image's pixel there (nearest); transform sets it, transformBy puts m under the one there (m first: a part turned inside its whole, moved); each gives back the one it replaced, to put back with transform; plain again at each frame's start and each app's. Made by pc.plain(), pc.moved(by), pc.scaled(by), pc.turned(angle) and pc.turnedAround(angle, at) (radians: a quarter turn, right to down). Transformed, a rect or an ellipse is drawn as a polygon (filled: its area's edge; outlined: through its edge pixels)
pc.line(from, to, c)a line, both ends drawn, a pixel each step along its longer way; cut off at the screen's edges (far off it costs nothing)
pc.rgb(c) -> Intcolor c of the palette (0 to 255), as 0xRRGGBB
pc.print(s, {x, y}, c)the text's characters, one every 6 pixels from x, drawn at y in color c
pc.blit(image, at, b?)a picture (a pc.Image: its pixels, row by row, a byte each or packed as its depth says, and its size; as pc.imageRead gives one, see apps), its top left at at, or b.size of it from b.from (a 0 in size: the rest of it that way), each pixel b.scale wide and high (a 0: 1; negative mirrors it that way: {-1, 1} flips it left for right); its 0s are see-through. b is a pc.Blit (from, size and scale, each a [2]Int, and map), so what's left out of {...} is 0, and b left out is all 0s: pc.blit(image, {10, 20}) draws all of it at its size. b.map, a []Int, draws it in other colors: each pixel's index (a byte-a-pixel picture's color) to the color drawn, 0 or -1 see-through, instead of its own palette: a sheet's red team blue, a hit's flash

A color is the low 8 bits of the number given: pc.cls(257) is pc.cls(1).

pc.cls(300)
pc.rect({-5, -5}, {10, 10}, 7)
pc.rect({10, 10}, {0, 5}, 9)
log(pc.pget({0, 0}), pc.pget({4, 4}), pc.pget({5, 5}), pc.pget({10, 10}))
7 7 44 44

A sprite drawn twice as big, its see-through pixel leaving what's under it, then its bottom row alone:

pc.cls(1)
pic: Blob[4] # (2 by 2)
pic[0] = 8
pic[1] = 0
pic[2] = 9
pic[3] = 10
image := pc.Image{pixels = pic[], size = {2, 2}}
pc.blit(image, {10, 10}, {scale = {2, 2}})
pc.blit(image, {40, 10}, {scale = {-2, 2}}) # (mirrored)
log(pc.pget({10, 10}), pc.pget({11, 11}), pc.pget({12, 10}), pc.pget({13, 13}), pc.pget({14, 14}))
pc.blit(image, {30, 30}, {from = {0, 1}, size = {0, 1}})
log(pc.pget({30, 30}), pc.pget({31, 30}), pc.pget({30, 31}))
8 8 1 10 1
9 10 1

Half and quarter screens

pc.screen(.half) makes the app's screen 160 by 120, each pixel shown 2 by 2; pc.screen(.quarter), 80 by 60, each shown 4 by 4; pc.screen(.full), 320 by 240 again. It's the app's alone: every app starts full. Drawing is clipped to the screen's size, so drawing is quicker the smaller it is; text is drawn as big as the pixels are, and the pointer's place (pc.pointerState().at) is in them. pc.screenSize() is its size now. The system's own (its notices, the command list) stay full size.

pc.screen(.half)
log(pc.screenSize())
pc.screen(.full)
log(pc.screenSize())
[160, 120]
[320, 240]

A frame that would come out wrong can be held back: pc.holdFrame(), during a frame, keeps it from being shown, the frame before it staying on the screen a 60th of a second more. It's for drawing that's right a frame late, as the ui library's layouts are when what's in them changes size: it holds that frame, and the next, laid out by it, is shown. Never two in a row: the next frame is shown whatever it asks, so a screen can't freeze.

Text

pc.print draws each character of the text (UTF-8: a code point each) with Rinc's own font, 5x11 glyphs in 6x12 cells, fixed width: the pixels of the character's glyph become c, and the rest are left as they are. It has ASCII and Latin-1, 33 to 255 (é, ñ, ©); the others draw nothing, and every character moves 6 pixels to the right. It's compact unless asked: a line of 9 pixels (the default) leaves out the glyphs' top 3 rows, which no ASCII glyph uses (the accents over capitals: É is drawn as E there), and a line of 12 ({font = {line = 12}}) has them all; a line between leaves out what it must. Rinc works the 3 out from the glyphs themselves (the rows above every ASCII one), so a font with other proportions needs no note.

A newline starts the next line, 9 pixels down. pc.print(s, pos, c, how) lays the text out as how, a pc.Text, says: width, in pixels, wraps it, a line breaking at the last space that fits (the space not drawn) and a word longer than a line breaking where it must; its font's line is the pixels from a line to the next (0: its cell's height; Rinc's own, 9, compact): {font = {line = 12}} spaces Rinc's own font 12 apart, its glyphs whole. pc.textSize(s, how?) is how big print draws it: its widest line's width and its lines' height, for a box around it or text placed by its size.

log(pc.textSize("Kree! Clouds below, stars above.", {width = 96}))
log(pc.textSize("a\nbc"))
[71, 26]
[11, 17]

Fonts

Rinc's own font is such a sheet too: src/core/rinc-font.png (5x11 cells, 16 across, 32 to 255, 1 bit, saved uncompressed), carried in the firmware as the file's bytes and drawn from where they lie, its cells as its notes say. To change it, draw it in Paint (any depth), then python tools/fontsheet.py --from it.png: it writes rinc-font.png and font.c (an ASCII glyph left blank keeps the one there now, named as a placeholder).

A font is a sheet of glyphs, a picture in cells of one size, a character a cell across its rows: Paint makes one as it makes a sprite sheet. Its notes say what it is, a line each:

line
font 32 126it's a font: its first cell's character and its last's
sprite 6x9its cells' size
proportionaleach glyph as wide as its columns with pixels (its empty ones trimmed, either side); else every glyph its cell's width (a 6x12 font of glyphs up to 5x11: sprite 5x11, gap 1, line 12; or sprite 6x12, the spare column and row left empty)
gap 1pixels after each glyph, negative for closer (if it's left out: 1 for a proportional font, 0 for a fixed one)
space 3a space's width, and an empty glyph's (half a cell if it's left out)
line 10pixels from a line to the next (its cells' height if it's left out)
colorsits glyphs drawn in their own colors (else in the color print is given)

pc.fontRead(path, room, o?) reads one into the Blob[..] room (its picture, as pc.imageRead does, at its own depth, or, o a pc.ImageRead with from and size, just whole rows of its cells: those characters, {from = {0, 12}, size = {80, 24}} the second and third rows of a 16-across 5x12 font; at its own depth: a font of 1 bit, 2 colors, takes an eighth of the room of 8; then two bytes a glyph for a proportional one: where it starts in its cell, and its width), as a pc.Font; pc.Text's font draws in it (print) and measures it (textSize), wrapping as its glyphs' widths say. A picture that isn't a font, or isn't there, reads as a pc.Font with no cells: Rinc's own.

room: Blob[..(96 + 1) * 54 + 190]          # its picture's rows, as it's read; and two bytes a glyph
title := pc.fontRead("title.png", room)
pc.print("CLOUDLAMP", {20, 20}, 10, {font = title})

The palette

The palette is 16 bands of 16 colors, a band to each row of 16 (as the Colors app shows them). Colors 0 to 15 are PICO-8's, 16 to 31 its secret palette (PICO-8's 128 to 143); then a band for each of 12 hues; then 16 tints and 16 grays. PICO-8's are:

colorRGBcolorRGB
0000000 black8FF004D red
11D2B53 dark blue9FFA300 orange
27E2553 dark purple10FFEC27 yellow
3008751 dark green1100E436 green
4AB5236 brown1229ADFF blue
55F574F dark gray1383769C lavender
6C2C3C7 light gray14FF77A8 pink
7FFF1E8 white15FFCCAA peach
16291814 brownish black24BE1250 dark red
17111D35 darker blue25FF6C24 dark orange
18422136 darker purple26A8E72E lime green
19125359 blue green2700B543 medium green
20742F29 dark brown28065AB5 true blue
2149333B darker gray29754665 mauve
22A28879 medium gray30FF6E59 dark peach
23F3EF7D light yellow31FF9D81 peach

The rest are made in OKLCH (Björn Ottosson's OKLab, as lightness, chroma and hue: a color space made so equal steps look equal), by tools/palette.py, which writes them as the table in src/core/palette.h:

colorsbandhue
32 to 47red29
48 to 63orange65
64 to 79yellow100
80 to 95lime121
96 to 111green142
112 to 127teal169
128 to 143cyan195
144 to 159azure229
160 to 175blue264
176 to 191violet296
192 to 207magenta328
208 to 223crimson359
224 to 239tints: 8 warm, then 8 cool60, 250
240 to 255grays
  • A hue's band: its first 8 are vivid, dark to light, then 8 muted, dark to light: 32 + 16 * k is hue k's darkest vivid, and + 8 its darkest muted. The hues are sRGB's red, yellow, green, cyan, blue and magenta (where OKLCH puts them, but a warmer yellow), and the hue halfway between each two. The vivid steps run from lightness 0.28 to 0.88 (0.91 for orange to azure, most vivid when light), one of them where the hue is most vivid, at nearly the most chroma sRGB has there, no step much more than its neighbours; the muted ones from 0.36 to 0.86, at the same chroma, 0.07, for every hue.
  • The tints: warm grays (toward orange) and cool ones (toward blue), each 8 from lightness 0.18 to 0.92, at chroma 0.025.
  • The grays: pure grays, black to white, even in lightness as it looks: 000000, 101010, 202020, 303030, 404040, 4E4E4E, 5E5E5E, 6E6E6E, 808080, 919191, A2A2A2, B4B4B4, C7C7C7, D9D9D9, EBEBEB, FFFFFF. Color 240 is black, as 0 is, for when 0 is see-through.

Each of the hues' and tints' colors is the one at 16 bits a pixel (below) nearest what OKLCH asked for, so what a Rinc shows keeps its hue.

Every Rinc shows the palette at 16 bits a pixel, RGB565: each component's top 5, 6 and 5 bits. Where a display has more bits, a component v of n bits becomes v * 255 / (2^n - 1), rounded down, so every Rinc shows exactly the same colors.

Input

A Rinc reads its keyboard and controller before each frame, and an app sees the same values for the whole frame. A Rinc may have no controller, or (in principle) no keyboard; the procs then give 0 or -1.

Buttons

pc.btn(b) is 1 while button b (a pc.Button) is held, and 0 otherwise:

bbuttonkeyboardcontroller
.left, .right, .up, .downthe arrowsarrowsd-pad, or the left stick pushed past half way (but not in pointer mode: see below)
.aAVA
.bBCB
.xXXX
.yYZY
.lb, .rbLB, RBshoulder buttons (pressing one also types Shift+Tab or Tab: see below)
.ls, .rsLS, RSsticks pressed in
.startStartStart: the app's own, for its pause and its menus
.backBackBack, or a SNES pad's Select: an app never sees it held (it opens the command list: see below)

pc.btnp(b) is 1 in the frame b is pressed, and again while it's held: after 15 frames, then each 4th, as PICO-8's btnp (a menu's step, held). pc.dpad() is the arrows held, a [2]Int of -1, 0 or 1 each way ({1, 0}: right); pc.dpadp() is the arrows as btnp has them, one way at a time (left or right before up or down), for moving a step on a grid. pc.keyButton(k) is the button an arrow key from pc.key() is (pc.LEFT to pc.DOWN), so pc.btn(pc.keyButton(k)) == 0 says it was typed (over serial, say), not held.

The face buttons are named as on an Xbox controller, in order of importance, so an app that needs one button uses A; on a controller with letters of its own (a SNES pad), each is the button with its letter.

Players

Each of these takes a player last, 0 to 3: pc.btn(.a, 1), pc.btnp(.start, 2), pc.stick(0, 3), pc.trigger(1, 1). Left out, it's player 0: the keyboard and the first controller, a button held if either holds it. Each controller is a player's as it's plugged in, the lowest number free, and keeps it while it's there, so unplugging one doesn't renumber the rest. pc.controllers() says which players have one: bit k is player k's (pc.controllers() & 2: player 1 has one), for a game to show who's there, or ask for another. A player with no controller, or one past 3, holds nothing.

Back (a SNES pad's Select), any player's, opens the command list, and again closes it: a pause, with the system's commands (home first) there for a controller, the app and its sound waiting under it, and any player's d-pad, A and B working it. So no app sees Back. Start is the app's own, for its pause and its menus.

Over serial, where a terminal sends keys only as they're typed, a developer's tool can hold buttons the way kitty's keyboard protocol says when keys go down and up: ESC [ 1 ; 1 : 1 C presses right, ESC [ 1 ; 1 : 3 C lets it go (A, B, D: up, down, left), and ESC [ 118 ; 1 : 1 u and : 3 u V, the A button (99 C, 120 X, 122 Z). A press is typed too, a release isn't; a button still held when another app starts is let go. So a test can play a game on a board.

Sticks and triggers

pc.stick(i) is a stick's position from -1 to 1: i 0 is the left stick's x (+ right), 1 its y (+ down), and 2 and 3 the right stick's. Within 0.15 of the middle it's 0, and beyond that it's rescaled to reach 1 at the edge, so a resting stick reads 0. pc.trigger(i) is a trigger from 0 to 1, i 0 the left one and 1 the right. Without a controller, or for another i, they're 0. Each takes a player too (above). A controller with no sticks (a SNES pad, whose d-pad its maker gives as one) has none here: its d-pad is the arrows.

Typed text

pc.key() takes the next key typed from a queue, or gives -1 when it's empty, for text and for editing it, all in the order they came. The queue keeps what's typed for an app that reads it: in a frame where the app doesn't call pc.key(), what's waiting is dropped as the frame ends, so a game that reads no keys (its V, C, X and Z, say, which type as well as press) doesn't collect them, and when it starts to (a name to type) it gets what came since. An app reading keys each frame keeps all that's typed ahead:

key
a characterwhat's typed, a character at a time, as its code point (Unicode's number: 'a' is 97, '\u{E9}' 233, '\u{4E2D}' 20013), after the keyboard's layout and Shift: 'A' with Shift, '@' with AltGr where that types it
8, 9, 13, 27Backspace, Tab, Enter, Esc
pc.LEFT, pc.RIGHT, pc.UP, pc.DOWNthe arrows
pc.HOME, pc.END, pc.DELETE, pc.PAGE_UP, pc.PAGE_DOWNthe editing keys
pc.F1 + 0 to 11F1 to F12 (where the Rinc gets them: a browser keeps F5, F11 and F12 for itself too, and the desktop's F11 is its whole display)
pc.COMMAND + none of the app's own commands, picked from the command list (see its commands)

The keys that type nothing start at pc.LEFT, 0x110000, past Unicode's last code point, so no character can be one. A key that isn't a character (all but what's typed, and Esc) also says which modifiers were held with it, as bits added on: pc.SHIFT, pc.CTRL, pc.ALT, together pc.MODS. Ctrl+Right is pc.RIGHT | pc.CTRL, Shift+Tab pc.TAB | pc.SHIFT. Ctrl with a letter is the letter, small, with Ctrl's bit: Ctrl+S is 's' | pc.CTRL, and Ctrl+Shift+Z 'z' | pc.CTRL | pc.SHIFT. Where Ctrl and Alt together are AltGr (Windows'), and it types a character, the character is what comes, not the key with Ctrl and Alt. (A terminal sends Ctrl+letter as one byte, 1 to 26, which Rinc reads so; but its Ctrl+H, Ctrl+I and Ctrl+M are the bytes of Backspace, Tab and Enter, so from a terminal they're those, unless it sends keys with their modifiers, as xterm's and kitty's ways do.) Enter and Backspace don't take Shift, as it's easily still held from typing. So c & ~pc.MODS is the key without its modifiers, and an app that doesn't care about them can use that; pc.keyBase(c) is the same, but keeps Ctrl on a letter ('s' | pc.CTRL, not 's', which is typed), for an app's switch of its keys; pc.isText(c) says whether it's a character typed.

The names are constants, so a key with its modifiers is one too, in a command list as anywhere:

log(pc.ENTER, pc.UP | pc.SHIFT == pc.UP + pc.SHIFT, 's' | pc.CTRL == pc.keyBase('s' | pc.CTRL | pc.SHIFT))
log(pc.keyBase(pc.UP | pc.SHIFT) == pc.UP, pc.keyBase('s'), pc.isText('\u{E9}'), pc.isText(pc.UP), pc.isText('s' | pc.CTRL))
13 true true
true 115 true false false

pc.modsHeld() -> Int says which modifiers are held now, with the same bits: pc.CTRL while Ctrl is down, say, or locked (tapped twice). It's for what goes on while one's held, as the editor's Ctrl+Tab walks back through its files until Ctrl is let go, or the arrows held with Shift selecting. Where Rinc can't tell (in a terminal), it's -1. In a pointer app (pc.Pointer.ui, below), a controller's left trigger, held, counts as Shift and its right one as Ctrl, so its d-pad selects as the arrows do (a game's triggers stay its own: pc.trigger).

pc.keyHeld(k) -> Int is 1 while key k is held down, and 0 otherwise: k as pc.key() gives it, without the modifiers (a letter in either case, 32 Space, 13 Enter, 8 Backspace, 134 Delete, 128 to 131 the arrows, the rest as the table says), its key as the keyboard's layout has it. It's for what goes on while a key's held in a pointer app, whose keys type rather than hold buttons: Maps and Paint draw while Space is held and the arrows move. Where Rinc can't tell (in a terminal) it's -1, and while a system combination's held, 0. rinc -hold holds keys too, for tests: space, enter, delete and the other editing keys by name, keyq for Q, and the arrows' names.

A controller's RB types Tab as it's pressed, and LB Shift+Tab, so anything moved through with Tab works from a controller too. Caps Lock types letters as capitals (with Shift, small), on every Rinc; other keys (the system key and the like) add nothing. A Rinc drops what's typed beyond 63 keys waiting, and one fed text faster than that (a serial port, a paste) waits for room. Keys also hold buttons down while they're held (the arrows, V, C, X and Z), so an app reads them either way: in a game. In a pointer app (pc.Pointer.ui, below) the keyboard types, and only its arrows are buttons too; there a controller's A and B, with the pointer hidden, type Enter and Esc, so one works such an app through the keys it reads.

A line of text, edited

pc.Field edits a line of text as a text box does (in Windows, say): a name to give, something to find. It holds the text, in room of the app's own, the cursor, and the selection's other end:

room: Blob[..32]
name := pc.Field{text = room}
name.set("tune.png")       # its text, all of it selected
name.select(0, 4)          # just "tune": typing takes its place
c := pc.key()
if c >= 0 and not name.key(c) # (Enter and Esc aren't its: the app's)
  log("the app's key", c)
end
name.draw({10, 100}, 30, 7, 2, 10) # 30 characters across, scrolled to show the cursor: text, selection and cursor colors
key
typingin place of what's selected, while there's room
Backspace, Deletethe character before or after, or what's selected; with Ctrl, a word
left, righta character, or with Ctrl a word; with Shift, selecting; with nothing held, out of a selection to that side
Home, Endits start, its end (with Shift, selecting)
Ctrl+Aall of it

key(c) says whether the key was the field's; the rest (Enter, Esc, Tab, up and down) are the app's. set(s) gives it new text, all selected; select(from, to) selects from from to to, the cursor at to; selected() says whether anything is. Its text is the app's own room, so the app reads it there: name.text.asString().

A terminal's escape sequences (ESC [ A for up, ESC [ 3 ~ for Delete, and so on) become the key codes above, so a Rinc fed by a serial terminal types the same keys. Modifiers come as xterm sends them: ESC [ 1 ; 5 C is Ctrl+Right, ESC [ Z Shift+Tab, and ESC [ 27 ; m ; k ~ key k with modifiers m.

The pointer

A mouse moves a pointer, and Rinc draws it: a small arrow over the screen. Moving the mouse or pressing one of its buttons shows it; typing hides it, as do the arrows (the d-pad's too), a controller's center buttons (Start, Back and guide) and the system key, and so does the mouse leaving the window, unless a button's held. So it's there only while it's in use, and a drag goes on outside the window till the button's let go.

Without a mouse, the system key moves it too: with the arrows (or a controller's guide button and d-pad), a pixel a frame, faster the longer they're held, and V and C (A and B) are its primary and secondary buttons. That's every Rinc's pointer, in any mode but none; the app sees just the pointer.

pc.pointerState() gives all of it, as it is this frame (asking again in the same frame gives the same), as a pc.PointerState:

field
at: [2]Intwhere it points, in screen pixels
primary: Bool, secondary: Bool, middle: Boolits buttons held: the left one, the right one, the middle
shown: Boolit's drawn now
scrolled: [2]Intthe whole steps scrolled this frame: across (+ right), and up and down (+ up, away from you, as on a wheel); a trackpad's fractions of a step wait for the frames after

pc.pointer(mode) says what the pointer is for, until the app ends, with a pc.Pointer:

mode
gameeach app's to start: the mouse's only; the left stick is still the arrows
uia pointer app's: a controller's too, its left stick moving the pointer (faster the further it's pushed), its right one scrolling, and A and B its primary and secondary buttons while it's shown (still pc.btn 4 and 5 too; hidden, they type Enter and Esc, and don't show it). The keyboard types: V, C, X and Z aren't buttons here
noneit's never shown

The d-pad is the arrows in every mode, and everything a pointer does should have keys too, since not every Rinc has a mouse or a controller. A list that a click picks from, and the arrows too:

items := [3]String{"Play", "Options", "Quit"}
picked := 0
clicked := 0
pc.pointer(pc.Pointer.ui)
update* :: proc()
  k := pc.key()
  for k >= 0
    switch
    case k == pc.UP
      picked = (picked + 2) % 3
    case k == pc.DOWN
      picked = (picked + 1) % 3
    end
    k = pc.key()
  end
  p := pc.pointerState()
  down := p.primary.toInt()
  y := p.at.y
  if down == 1 and clicked == 0 and y >= 100 and y < 100 + 3 * 10
    picked = (y - 100) / 10
  end
  clicked = down
end
draw* :: proc()
  pc.cls(1)
  for i in 0..<3
    c := 6
    if i == picked
      c = 7
    end
    pc.print(items[i], {140, 100 + i * 10}, c)
  end
end

Time

pc.appTime() is the seconds since the app started (each start: an app called back to starts again), as a Float, and pc.appTimeReset() starts it from 0 again, so the microseconds a Float keeps are there for as long as an app runs, not lost as a board stays on for days. On the desktop and the web, it's the board's clock (board speed: what the app's work would have taken on the Fruit Jam), unless -turbo.

Sound

A Rinc mixes 16 voices, numbered 0 to 15, into 48,000 frames a second of 16-bit stereo. Each voice plays sound data straight from the app's memory, reading it as it plays, or notes, on the synth. (The Fruit Jam mixes on its second core, beside the HDMI, so sound takes none of an app's time: 16 synth voices at the synth's starting rate take about 40% of that core's; at its top rate, smoothed, three times the work a voice, so 16 of those would be too much, and the sound would break up. pc.audioLoad says.)

The procs

Each proc takes a voice number first; a number outside 0 to 15 does nothing (and soundPlaying gives 0).

proc
pc.sound(v, data, s)play data from its start, once, full volume, centered, with no loop, in place of whatever v was playing, as s, a pc.Sound, says: bits 16, 8 or 4 (0: 16), channels 1 or 2 (0: 1), else nothing happens, and rate frames a second (0: 16000)
pc.soundWav(v, data) -> Intplay a WAV file's sound data at the file's own rate, as sound would; 1 if it could, 0 if the file isn't one it plays
pc.soundSet(v, setting, value)one of v's settings, a pc.SoundSetting (below), from now on: pc.soundSet(v, .volume, 0.5)
pc.soundLoop(v, start, stop)on reaching frame stop, go on from frame start; stop past the end is the end; stop 0 or less, or start not before stop, ends any loop
pc.soundStop(v)stops (on the synth, fading out, as after its last note)
pc.soundSeek(v, at)on from frame at (on the synth, note at), as it plays; past the end, the last
pc.audioLoad() -> [2]Inthow much of its time mixing takes, in percent: on average and at most, since last asked; {-1, -1} where it isn't measured (the board measures it: it mixes on its second core, with the HDMI, so its share is that core's, not the app's)
pc.soundPlaying(v) -> Int1 while v plays, else 0
pc.synth(v, notes, speed)play notes on the synth, from the first, each speed 120ths of a second (1 to 255), full volume, centered, with no loop, in place of whatever v was playing; fewer than 4 bytes of notes stops v
pc.synthMake(out, notes, speed) -> Intthe samples synth would make, added to out instead: 16-bit, little-endian, with voice -1's settings (below), until the notes end or out is full; how many. speed 0: on from where the last one stopped (its next sample, in the notes given now), so a sound longer than out holds can be made a piece at a time
pc.synthWave(w, cycle)wave w, 8 to 15, for every voice: one cycle of 16-bit little-endian samples, read as it plays; fewer than 2 samples: silent (to start)

A voice's settings, each a Float, the value given (outside its range: the nearest end):

setting
.rateframes a second from now on, from 0 (paused) to 768,000
.volumefrom 0 to 1
.panfrom -1 (left only) through 0 (both, full) to 1 (right only)
.synthRatesamples the synth makes a second, from 8,000 to 48,000 (16,000 to start)
.bendevery pitch moved by that many semitones, from -96 to 96 (0 to start)
.attack, .releaseseconds the volume heard takes to rise, and to fall, about 2/3 of the way to a note's: from 0 (at once) to 10 (0.0062 to start)
.smoothmore than 0: the saw, square and pulse smoothed where they jump; 0: not (to start)

The synth's settings (.synthRate to .smooth) are a voice's own, kept from one synth to the next, and a voice playing on the synth changes as they're set. Voice -1's are synthMake's. An app starts with every setting as above, and no waves of its own.

Sound data

A frame is one sample for each channel; stereo samples come left first.

  • 16 bits: signed, little-endian.
  • 8 bits: signed, one byte each.
  • 4 bits, IMA ADPCM, laid out as in WAV files (format 0x11), in blocks of 256 bytes for each channel (256 mono, 512 stereo). A block starts with each channel's first sample (16 bits) and step index (a byte, then a byte of 0), then 4-bit codes: for mono, in byte order, the low half of a byte first; for stereo, 4 bytes (8 codes) of the left channel, then 4 of the right, and so on. A 256-byte mono block is 505 frames.

soundWav plays WAV files with 16-bit PCM or IMA ADPCM (any block size), mono or stereo. It reads the fmt and data chunks, and plays what there is of a cut-short file. (WAV's 8-bit samples are unsigned, so it doesn't take those.)

The number of frames is the data's length divided by the bytes a frame takes (rounded down), or for ADPCM the frames its blocks hold.

Mixing

A voice moves through its data at rate / 48000 frames for each frame of output, and takes the value between the two nearest frames in a straight line. A mono voice plays on both sides. Its volume and pan scale each side: left by volume * (1 - pan) when pan is above 0, right by volume * (1 + pan) when it's below 0, and each side by volume otherwise. The voices are added together, scaled by the Rinc's own volume (where it has one), and cut off at the 16-bit range.

Changing a voice's data while it plays changes what's heard. A voice that reaches the end of its data without a loop stops.

The synth

On the synth, a voice plays notes: 4 bytes each, the same as Sound's (studio/sound).

byte
pitch0 is C0 (65.406 Hz), and each step a semitone up: 65.406 * 2^(pitch / 12) Hz (above 95: 95)
wave0 triangle, 1 tilted (a triangle up slowly, down fast), 2 saw, 3 square, 4 pulse (a quarter up), 5 organ (a triangle and its octave), 6 noise (a new value 8 times a cycle), 7 phaser (two triangles 0.7% apart), 8 to 15 the app's own (synthWave); only the low 4 bits count
volume0 (silent) to 7 (full); only the low 3 bits count
effect0 none, 1 slide (from the note before, its pitch and volume, across the note), 2 vibrato (a quarter tone either way, 7.5 times a second), 3 drop (the pitch down to 0 across the note), 4 fade in, 5 fade out, 6 a fast arpeggio (the four notes of its group of 4, 30 a second), 7 a slow one (15 a second); only the low 3 bits count

It makes rate samples a second (.synthRate), as it plays, and they're mixed as any sound's at that rate. A note lasts speed * 133 * rate / 16000 samples, so the same time at any rate (a note partway along when the rate changes stays as far along). Each sample is the wave at the note's pitch plus the bend, at the volume heard, times 10,240: a synth wave's peak is near its average, so this is about as loud as recorded sound peaking at full scale. The volume heard moves toward the note's by 1 - e^(-1 / (seconds * rate)) of the way each sample, seconds being the attack while it rises and the release while it falls (.attack and .release; to start, 1% a sample at 16,000), so changes don't click. At full volume, the triangle and the saw reach 10,240 and 7,168, the square and the pulse 5,120, and an app's wave its own samples times 10,240 / 32,768. After the last note, it fades out over 50 ms or 5 releases, whichever is longer, and stops.

An app's wave is read where the cycle is, in a straight line between its two nearest samples (after the last, the first). Smoothing (.smooth) is PolyBLEP: within a sample's step either side of a jump, the wave is rounded off, so the jump's overtones too high for the rate mostly don't come back as false tones lower down.

On a synth voice, soundLoop's start and stop are notes, .rate speeds it up or slows it down as a whole (16,000 is as it is, at any .synthRate), and the rest are the same. Volume and pan changes ease in within 64 frames of output. Changing the notes while they play changes what's heard.

Songs

Rinc plays a song as studio's Music makes it, on its own once started, so a game calls nothing each frame: rinc's song library reads the files and calls these, one song at a time.

proc
pc.songPlay(v, room, notes, patterns, uses, from, how)play the song in room's tables, its sounds' notes in notes, from use from (its track; the others where they'd be then), on voices from v on; how: 1 just that use (its track alone), 2 round again from the first at its end, and from bit 8 on how many voices it may take (0: 8); in place of the song playing
pc.songStop()its voices fading out, as after a sound's last note
pc.songPause(on)1 holds it where it is (its voices silent), 0 goes on
pc.songLevers(shift, volume, speed)semitones (-96 to 96), eighths (0 to 8), percent (1 to 400) over the whole song: shift and volume at once, speed from the next placements on
pc.songAt() -> [3]Intthe use playing in the track it was started from, its time round (from 0), and how far into its pattern, in thousandths (that track ended, the others on: its last use, 1000); {-1, 0, 0} when none plays
pc.freeVoice() -> Intthe first voice not playing and not the song's (-1: none): a game's sounds there, never in the song's way (the song library's sound(-1, n) takes one so)

room holds, from its start: the patterns, 6 bytes each (its steps; a step's length, in 120ths of a second; its first placement, 2 bytes, low first; how many it has; 0); then the uses, 11 bytes each (its pattern; its shift and its shift at its end, each plus 64; its volume and at its end, in eighths; its speed, in percent, 2 bytes, low first; its marks, 1 a loop begins, 2 a loop ends, 4 the song stops, and its track times 16, 0 to 7; how many times it's played over; its pan and its pan at its end); then the placements, 9 bytes each (its step; its channel, 0 to 7; its sound; its shift plus 64; its volume, in eighths; its speed, or 0 for its sound's; its hold, in steps, or 0; its pan; its file of sounds, 0 the song's own). Its sound is its number in the row of all the song's sounds: the song's own file's first, then each file a pattern picks of its own, just the sounds the song places from it (the song library lays them out so, and notes holds them in that order). A pan is a signed byte, -8 to 8, eighths of the way left or right, 0 the center: a placement's and its use's (ramped across its times round, as shift and volume are) added. Then, for each sound the song plays, from 0, its speed and its loop's start and end, 3 bytes. notes holds the sounds' notes, 128 bytes a sound (32 notes of 4 bytes, as the synth takes them).

A song's uses are in tracks, played side by side (a drum beat in one, the melody's patterns in another): each track its uses in the table's order, in turn, as below, with its own loops; a stop mark in any ends the song, and the song ends when every track has. The tracks take voices in order: track 0's channel c on voice v + c (its pattern's highest channel, plus one, the voices it takes), a later track's after the tracks before it, just the channels its pattern uses (a bass on channel 6 alone takes one voice), worked out again as a track's pattern changes; a channel past the song's voices is dropped (silent). So the first track's are never dropped.

Time goes in ticks of 1/120 s, kept by the mixer. At its step a placement starts on its channel's voice as pc.synth would play its sound, its notes as long as its speed (scaled by its use's speed and the speed lever), to its loop's end or its last note heard, round its loop, until its hold is up, the next placement on its channel starts, or its pattern ends. Its pitch moves by its shift, its use's (ramped across all its times round) and the shift lever's; its volume is its own times its use's (ramped) times the volume lever's. At a pattern's end, the next time round, or the next use: after a loop's end, back to the use where it began; after a stop, or the last use, the song ends (or, as how 2 says, starts again). Rinc reads both as it plays, an app's changes too, and checks every index against them.

Memory

An app gets one block of memory, its app space: 256 KB, for everything it is. Nothing is allocated while it runs, so whether an app fits is known before it runs, and it's the same on every Rinc.

How an app is compiled

Every Rinc compiles an app the same way, so it gets the same answer for the same app:

  1. Rio's compiler works in the app space itself. That's memory the program will use for globals and arrays, which are zero until it runs, so the compiler borrows it.
  2. The app's files are read a part at a time, through a 3.5 KB window (2 KB of text, and room for the tokens and names it's reading) at the top of the compiler's string pool, so no file has to fit in memory whole, and an app can be as many files, as big, as it likes. Its string literals go into the string pool as they're read (in Rio's C API: rio_init with the app space as its memory and no separate code buffer, then rio_compileStream: see Rio's memory model).
  3. The program's final layout then takes the whole app space.

So an app has two limits:

  • Compiling: the compiler's tables, the constants and the strings share the app space. The tables are sized to fill it, the same for every app, however many files it is or however long they are.
  • Running: the code (8 bytes an instruction), the constants, the globals and arrays, the procs' frames (procs that never run at the same time share one), the strings, and Rio's small runtime tables.

An app that doesn't fit gets a compile error ("out of memory", "too many symbols" and so on), and doesn't run.

big: [60000]Int                    # 240 KB of the 256
big[59999] = 1
log(big.len())
60000
toobig: [70000]Int  # error: out of memory

Seeing how near the limits an app comes

rinc -m app.rio on the desktop compiles an app as every Rinc does and reports both limits: how full each of the compiler's tables got, and where the memory goes when it runs:

apps/chord/chord.rio: fits in the 256 KB app space
  compiler room   248208 bytes
  source window   3584 bytes
  symbols         112 of 1742: 6%
  ...
  string pool     11756 of 21120: 55%
  constants       356 bytes
  data            82876 bytes
  code            2112 bytes
  strings, tables 11672 bytes
  free            165128 bytes

Whatever comes nearest 100% is what would run out first: here the string pool, as chord carries its sound as hex text (in parts/sound.rio). When an app runs out of something, the Fruit Jam and the desktop show the same report with the error.

Outside the app space

A Rinc keeps its own things outside the app space, where apps can't reach them except through the pc procs: the screen (75 KB, a byte a pixel), the voices' state, the typed-text queues, and one Rio session (see Rio inside an app), whose memory is the app's own. They don't count against an app's 256 KB, and a Rinc needs room for them besides. The voices read sound data from the app space as they play, so they need no copies.

Images

An app can also be compiled ahead of time into a Rio image, as the web pages and exported games are. An image's memory addresses are absolute, so images for a Rinc are compiled for a 256 KB app space, as above, and load into one.

Apps and storage

Every app is one Rio file, run as running apps says, with the whole app space to itself. A Rinc finds apps in two places: its storage (the Fruit Jam's SD card, a folder on the desktop, the browser's IndexedDB), and its bundle, the apps it carries with it. Storage comes first, so an app there takes the place of a bundled one of the same name.

Storage

A Rinc's storage is a folder of its own, and apps can't reach outside it. Inside Rinc, it's /: an app says /save/chord/best. Where it really is, Rinc knows: /rinc on the Fruit Jam's SD card (so a card can hold other things too), a folder of the desktop's (see the desktop), a page's storage in a browser. Its top is Rinc's own folders, each a name Rinc gives, never an app or a device:

/apps/chord/chord.rio    an app: a folder of its name, holding its Rio file of the same name
/apps/chord/help/...     its help texts, Markdown (see help texts)
/apps/rinc/themes/...    Rinc's own themes (see themes): rinc is no app, so it isn't listed
/projects/chord/...      its project, chord+: the app in work (see projects)
/projects/chord/dev/...  its dev folder: its maker's, not the app's (its own saves, its tests)
/save/chord/...          its own files (save:best, to the app): only the app changes them
/stash/chord/...         where it was, for its next start (stash:view): Rinc may drop it
/cache/chord/...         what it can make again (cache:thumbs): anything may clear it
/cache/rinc/apps/chord.rioi   Rinc's own cache: the app, compiled (see compiled apps)
/cache/rinc/projects/chord.rioi   and its project
/help/...                help texts that are no app's own (Rinc's and Rio's docs)
/settings/...            the whole Rinc's settings, shared by the apps (settings:active, the app in work)
/stick/...               the stick, while one's in: a thumb drive on the board, a zip or a folder
                         dropped on the desktop, a zip dropped on a page

Apps read anywhere in it, and write inside its folders (the stick's too), never at / itself.

An app is all of its folder but one part: its dev folder, dev/, which is its maker's, not the app's. Everything that isn't the app goes there: a project's own saves (dev/save/), its tests (dev/test.rio), notes and drafts. Installing it, copying it as a new project, bundles and exports take all the rest, and leave out its dev folder. There's no list of an app's files to keep.

An app's name is 1 to 32 letters, digits, _ and -. If its first line is a comment, that's its description, by convention a title, a colon, and what it does:

# Chord: an ADPCM chord on 8 voices, with pitch and pan

Bundles

A bundle is the files a Rinc carries with it, laid out as in storage: an app is apps/<name>/<name>.rio, or, compiled for a Rinc without a compiler, apps/<name>/<name>.rioi (a Rio image for a 256 KB app space) with its description in apps/<name>/<name>.info. A bundle also names its home app, the one home means, and its storage folder, where its apps' save spaces go.

  • The Fruit Jam's firmware, the desktop and the web carry none, so they stay small: their apps and help texts are in storage (on the Fruit Jam, its SD card, filled by tools/install.py). A firmware can be built with a bundle of its own, though, such as a game's.
  • An exported game carries its own apps, starting at its home app. One app on its own is home. It carries them compiled, unless one of them runs Rio itself or writes apps (the console, the editor): then their sources, so they can be read and changed too.

home means, in this order:

  • the app a Rinc was started with, for that session: rinc chord on the desktop makes chord home until it quits, so system+Esc comes back to it, though it's still named chord;
  • a bundle's home app, if the bundle carries apps (an exported game, a web page, a firmware of its own);
  • the home setting, if it names an app (see settings);
  • else the app named home.

An app on storage of the same name as a bundled one takes its place.

Every Rinc reads the same format, all numbers little-endian:

bytes
8RINCBUN1
4how many files
32the storage folder's name, 0-padded (empty: Rinc's own)
32the home app's name, 0-padded
104 eacheach file's entry: its path (96 bytes, 0-padded, at most 95 long), where its bytes start (4, from the bundle's start) and how many (4)
the files' bytes

A desktop program carries its bundle at its end, followed by the bundle's size (4 bytes) and RINCBUN1 again. A web page carries it in base64.

Finding apps

proc
pc.launch(name)after this frame, leave this app and run app name

Rinc's library appfiles lists them: appfiles.list(out) -> Int adds a line to out for each app, in storage and in the bundle (the first 64, in order of name ignoring case, each project after its app; home aside, as it shows them): its name, a tab, and its description, its first line after # and any spaces (nothing, if it doesn't start with #); as many whole lines as fit. It says how many apps there are, so a list too long for out, cut at a line's end, can be told.

An app's source is a file, /apps/<name>/<name>.rio, which the file calls read and change (reading finds a bundled app's too). Rinc's library appfiles (see Rinc's library) does it by name, an app's or a project's, with what goes with it:

proc
appfiles.source(name, out) -> Intapp name's source (from storage, else the bundle), added to out, as much as fits: its whole length, or -1 if there's none
appfiles.save(name, text) -> Inttext becomes app name's source (its folder too, if it's new): 0, or -1
appfiles.remove(name) -> Intall of app name's folder, its compiled image, and the active setting if it was the active one: 0, or -1
appfiles.main(name), appfiles.folder(name)its paths, /apps/chord/chord.rio and /apps/chord (a project's, chord+: /projects/chord/...), or "" for a name no app can have

An app's own files

Every app has a save space of its own, /save/<app>, for high scores, settings and the like. The file calls (see files) reach it, and the app's other areas, by a word and a colon, with no need to know the app's name:

path
save:bestits save space, /save/<app>/best (a project's own: see projects)
stash:viewits stash, /stash/<app>/view: where it was (see its stash)
cache:thumbsits cache, /cache/<app>/thumbs (see its cache)
settings:themethe whole Rinc's settings, /settings/theme, shared by the apps (see settings)

After the colon come names with / between them, for folders (save:levels/1), each 1 to 32 letters, digits, _, - and ., not starting with a dot; the word and colon alone are the area itself, to look in (pc.dir("save:", out)), not to change. A colon is in no file's name, so these can't be mistaken for a file in the app's own folder (sprites.png), and an absolute path still reaches another app's (/stash/rinc/clip, the clipboard).

Whatever reads into out takes a byte builder (Blob[..N], or a view, Blob[..], over an array or part of one) and adds to what it holds, so out.len() tells how much came in; the result says how long the whole thing is, so more than came in means it didn't all fit.

log(pc.fileWrite("save:best.txt", "42"))
out: Blob[..16]
n := pc.fileRead("save:best.txt", out)
log(n, out.asString(), pc.fileRead("save:nope.txt", out))
out.clear()
log(pc.fileDelete("save:best.txt"), pc.fileRead("save:best.txt", out))
0
2 42 -1
0 -1

Where a Rinc has no storage, an app can't save: these give -1. A project's save space is its own (see projects), so work on it can't spoil the app's.

Projects

An app in work is a project: /projects/chord, which is chord+ wherever an app's name goes (a star after it), and installing it makes it the app, chord. It's the same app at another stage, so it shares the app's name, and what goes with the name: its stash, and its own cache. A star marks it where it's listed: home, the switcher, the editor's list.

/projects/chord/chord.rio      its source
/projects/chord/help/...       its help texts
/projects/chord/dev/save/...   its own save space: the app's saves, copied in on its first run

Only its saves are its own. A project being worked on can do anything to them, and the app's own, /save/chord, the live ones, are left alone: on its first run (when it has no save space yet), the app's saves are copied in, so it starts from real data. Deleting its dev/save folder starts it over from the app's again. Nothing goes back the other way. (A project's saves from before the dev folder, in save/, are moved into it, as they are, the first time it runs.)

pc.launch("chord+") runs the project (and pc.launch("chord+/dev/test") its tests: see an app's tests), and appfiles' procs take a project's name too (appfiles.remove removes all of its folder: a project's own saves too, but never the app's, in /save). The rest, each 0 or -1:

proc
pc.appInstall("chord")project chord+ installed as app chord: its files copied over the app's (its save space aside); the console's install chord too
appfiles.copy(from, "tune+")app or project from copied as new project tune+: its files, its main file renamed tune.rio (a project's own saves aside; a bundled app's source, from the bundle)
appfiles.rename("tune+", "song+")project tune+ renamed song+: its folder and its main file (and the active setting, if it was the active one)

Files

Any app can look through storage by path, as Files (system/files/files.rio) does: absolute paths, /save/chord/best, with no . or .. parts; or its own areas, save:best and the like (see an app's own files); or, for reading, a file of its own folder, sprites.png. / is the root: looking goes anywhere in it, changing only inside its folders, never / itself. (An exported program's storage is its own folder, still / to its apps.) Reading sees a bundle's files too (see bundles), after storage's: an exported game's own files, say, or the themes a web page carries; changes go to storage. Each gives 0, or -1, unless it says otherwise:

proc
pc.dir(path, out) -> Inta folder's entries, added to out, folders first, then by name, a line each (d name, f name): how many, or -1 if it's no folder
pc.fileRead(path, out) -> Inta file, added to out, as much as fits: its whole length, or -1
pc.fileWrite(path, data) -> Inta file's contents, its folders made
pc.fileReadAt(path, at, out) -> Inta file from byte at on, added to out, as much as fits: its whole length, or -1
pc.fileWriteAt(path, at, data) -> Intdata written over a file from byte at on (-1: at its end, adding to it; past its end, no), the file made if it isn't there (its folders too): where it went, or -1
pc.fileDelete(path) -> Inta file, or a folder and everything in it
pc.fileCopy(from, to) -> Inta file, or a folder and everything in it, to a path not taken
pc.fileRename(from, to) -> Intto a path not taken
pc.dirMake(path) -> Inta folder, at a path not taken (the folders along the way too)
log(pc.fileWrite("/save/demo/notes/a.txt", "hi"), pc.fileCopy("/save/demo/notes", "/save/demo/copy"))
out: Blob[..64]
n := pc.dir("/save/demo", out)
log(n, out.asString())
log(pc.fileCopy("/save/demo/notes", "/save/demo/copy"), pc.fileDelete("/save/demo"))
0 0
2 d copy
d notes

-1 0

fileReadAt and fileWriteAt read and change a part of a file, so a big one (a log, a level) needn't all be in memory at once. Each opens the file and closes it again, so what's written is on the card when it says so, even if the power goes then.

log(pc.fileWriteAt("/save/demo/log", -1, "abc"), pc.fileWriteAt("/save/demo/log", -1, "def"), pc.fileWriteAt("/save/demo/log", 1, "XY"))
out: Blob[..4]
log(pc.fileReadAt("/save/demo/log", 2, out), out.asString())
log(pc.fileWriteAt("/save/demo/log", 9, "?"), pc.fileDelete("/save/demo"))
0 3 1
6 Ydef
-1 0

Files shows them: its help text, files/README, says how. Deleting there takes the whole name typed.

Pictures are image files, PNGs so far. A picture in memory is a pc.Image: its pixels, a Blob, a color number each, row by row, 0 see-through, and its size, a [2]Int:

proc
pc.imageWrite(path, image, o?) -> Inta picture as an indexed PNG: Rinc's 256 colors are its own, 0 see-through, so other programs show it as Rinc does. o is a pc.ImageWrite: notes, the app's notes about it (text up to 512 bytes: a sprite sheet's sprite size, say), kept in the PNG as a text chunk named Rinc, which other programs keep or ignore; format, a pc.ImageFormat: fromName (left out: the path ends .png) or png; flags, a sprite sheet's flags (below); and sheet, written as a sheet: the colors it uses its own palette, in order (0 first, see-through), at as few bits as hold them (2 colors: 1 bit; 4: 2; 16: 4; more: 8), its rows uncompressed, each in a stored block of its own, so a row can be read in place (Paint saves so). 0, or -1
pc.imageRead(path, pixels, o?) -> pc.Imagea PNG (8 bits a color, or indexed at 1 to 8 bits; not interlaced), its pixels added to the builder pixels, each color Rinc's nearest (exactly the same, for one imageWrite wrote): the picture, its pixels viewing them (size {0, 0}, and none, if it can't be read). An indexed one of 1, 2 or 4 bits is kept at its depth: its rows packed (depth 1, 2 or 4), each pixel an index into its own colors, its palette, which follows its rows in pixels (index to Rinc's color, 0 see-through); a font of 1 bit takes an eighth of the room. Drawing takes any depth; pc.imageAt(image, p) reads a pixel's color at any depth; an app that reads or edits pixels a byte each asks for them so, o a pc.ImageRead with bytes = true. o.from and o.size read just that part of it into memory (a font's range of characters, a few sprites), the rest never there: from a sheet saved uncompressed (as Paint saves), its rows read one by one; any other PNG gives none, and the log says why. A part past its edges is what's in it. pixels needs room past what it holds for the PNG's rows as they come, each with a byte saying how it's packed: (w + 1) * h bytes for one of Rinc's, or any indexed or gray PNG; (3 * w + 1) * h for RGB, (4 * w + 1) * h with alpha. Without it, the picture has its size but no pixels, and the log says how much room it needs
pc.imageNotes(path, out) -> Intthose notes, added to out: how many bytes, or -1 (none, or no such PNG)
pc.imageFlags(path, out) -> Inta sprite sheet's flags, as records: x, y and flags for each, 3 Ints each in the []Int out, as many as fit: how many the PNG has, or -1 (no such PNG)
pc.imageSpriteFlags(path, w, h, out) -> Intthe same, by sprite: a byte for each sprite added to the Blob[..] out, its flags (its sprites w by h, counted across the rows; 0 for none; a record not at a sprite's top left left out): how many records the PNG has, or -1 (no such PNG, or no room for a byte a sprite: none added, and the log says how much it needs)
pc.imageFlag(path, name) -> Inta flag's bit, by the name the notes give it: 0 if none has that name
pic: Blob[4]
pic[0] = 8
pic[3] = 12
log(pc.imageWrite("/save/demo2/tiny.png", {pixels = pic[], size = {2, 2}}, {notes = "sprite 2"}))
back: Blob[..16]
image := pc.imageRead("/save/demo2/tiny.png", back)
log(image.size, image.pixels.len(), image.pixels[0], image.pixels[1], image.pixels[3])
notes: Blob[..16]
log(pc.imageNotes("/save/demo2/tiny.png", notes), notes.asString())
log(pc.fileDelete("/save/demo2"))
0
[2, 2] 4 8 0 12
8 sprite 2
0

Sprite flags

A sprite sheet's sprites can each have flags, 8 of them, a byte's bits: which are solid, say, or a ladder, or hurt. Studio's Paint sets them, and names them; a game asks for a flag's bit by its name once, and tests each sprite's flags in its loops after. A flag goes with a sprite's top left pixel, whatever size the sprites are (9 by 9, say). In the PNG, the flags are a chunk of Rinc's own, rnFg (5 bytes a sprite with any: x and y, 2 bytes each, high first, then its flags), and their names are lines in its notes (flag 0 solid), with its sprites' size (sprite 8x8). Other programs show the picture as it is; most leave out chunks they don't know when they save one, so flags are Paint's to change. They're read without the picture's pixels, so they need no room but where they go.

pic: Blob[16 * 8]
records := [6]Int{0, 0, 1, 8, 0, 5}  # (sprite 0: solid; sprite 1: solid and ladder)
log(pc.imageWrite("/save/demo3/tiles.png", {pixels = pic[], size = {16, 8}},
                  {notes = "sprite 8x8\nflag 0 solid\nflag 2 ladder\n", flags = records[]}))
solid := pc.imageFlag("/save/demo3/tiles.png", "solid")
ladder := pc.imageFlag("/save/demo3/tiles.png", "ladder")
tileFlags: Blob[..2]
log(pc.imageSpriteFlags("/save/demo3/tiles.png", 8, 8, tileFlags))
log(tileFlags[0] & solid != 0, tileFlags[0] & ladder != 0, tileFlags[1] & ladder != 0)
log(pc.fileDelete("/save/demo3"))
0
2
true false true
0

The app for a file

An app says which files it opens in opens.txt in its folder: a line each, the extension, then what such a file is.

png  picture or sprite sheet

A line * says it opens any file (the editor's: * any file, as text). Such an app is listed in Files' Open with for every file, after the apps for its kind, but Enter opens a file in it only once it's been picked for that kind there.

So installing an app is all that registers it, and removing it takes it away. pc.appsFor(ext, out) -> Int gives the installed apps that open files ending .ext, into out a line each, name what, in order of name: how many. The one picked for them is the setting files/appreg/<ext>; with one app for a kind, that one, picked or not. An app is given a file as pc.call(name, "open /its/path"), so it reads pc.args as it starts, and opens that (the system key with Q comes back, to Files, say).

Files opens a file with Enter in its kind's app: the one picked, else the only one. With two or more and none picked, it asks, in Open with, and the one picked there becomes the kind's. Open with (the menu's W) lists them all, then Files' own view of the file's text: Enter opens it in the one picked, this time; Ctrl+Enter makes it the kind's from now on. A file no app opens shows its text. Rinc's own apps open these: the editor rio, md, txt, json, csv and cfg (text that isn't .rio is edited as plain text: no Rio checking or completing); Help md too (read, as help is); Paint png; Sound snd; Maps map; Music mus.

Calling an app

An app can start another for something, such as a file picked, and have the answer back. pc.call(name, args) starts app name after this frame, with args, which it reads with pc.args(out) -> Int (added to out, as text that reads into a builder does; how long: 0 for none). When it's done, pc.done(result) goes back to the app that called it (it's left out of the recent apps, as the system key's Q leaves an app out), and that app, starting again, reads the result with pc.result(out) -> Int (how long, or -1 if there's none: it's taken). What's typed ahead, after a call, is the called app's.

Files is a picker this way: pc.call("files", "pick /save/chord") starts it in that folder, and Enter on a file gives its path back (Esc at the top, nothing: an empty result):

out: Blob[..96]
if pc.result(out) < 0
  pc.call("files", "pick")      # (the first time)
else
  log("picked", out.asString())
end

The editor saves to projects: a new app is a project, and an installed app opens read only, like a page's source in a browser, until saving it makes its project.

Errors

An app that stops with an error, one that didn't compile or a runtime error, shows it on the screen, and Rinc keeps where it was for an editor: pc.appError(path, message) -> pc.AppError gives its line (0 when there's none), column and width (0 when they're not known, as for a runtime error's), and whether it was a runtime error, with the file's path (the app's main file, or the part it was in) and what was wrong added to the builders path and message, as much as fits. It's taken: a second call gives none. The editor takes it as it starts, so coming back to it after Ctrl+R puts the cursor on the error.

path: Blob[..128]
message: Blob[..96]
e := pc.appError(path, message)
if e.line > 0
  log(path.asString(), e.line, e.col, message.asString())
end

Settings

The whole Rinc's settings, not any one app's, are in /settings, a file a key, and any app can read and change them with the file calls, as settings:key: pc.fileRead("settings:theme", out), pc.fileWrite("settings:theme", "rinc/slate"). Keys are named as save files are, or are such names with / between them, for settings in folders (settings:files/appreg/png).

active is the app or project being worked on: chord, or its project, chord+ (an installed app can be active too, to read its source). The editor makes what it opens active, and starts with what's active, so an app that picks one (a file browser, say) has the editor open it next. Home's Ctrl+Enter makes the app picked there active and opens the editor, and marks the active one; the console's active name makes name active.

home names the app home means (see bundles), when the Rinc wasn't started with one: launcher, say, for a home app of another name. Without it, home is the app named home.

theme names the theme in use, rinc/slate say (see themes).

files/appreg/<ext> names the app picked to open files ending .ext: files/appreg/png holding paint, say (see the app for a file).

Themes

A theme gives a palette color to each role the system apps draw with, so they look alike and code is colored the same in all of them. theme (a setting) names the one in use, owner/id: the file themes/id.theme.rio of app owner, in its folder (or the bundle's) or its save space (/save/owner/themes), or of project owner+; owner/id+ is only the save space's, a copy of a locked one. Rinc's own themes are rinc's: /apps/rinc/themes, rinc/slate and so on. Without a theme, or for a role it leaves out, the color is Rinc's own, Steel's (rinc/steel). The Themes app picks, makes and edits them (see its help).

pc.theme(role) -> Int is the color a role has in the theme in use, read as each app starts:

pc.RoleRinc's ownfor
bg, bar1, 0the background; bars and boxes to type in
text, soft, dim, faint7, 6, 13, 5text; long text; what goes with it; hints
accent, heading10, 9what stands out, the cursor; other headings
pick, select12, 2behind the row picked; behind selected text
link, error, ok12, 8, 11links; what went wrong; what went right
codeBg17behind code, among text
code, punct, keyword, type7, 6, 14, 15code: names, operators, keywords, a capital's names
call, number, string, comment12, 9, 11, 13code: calls, numbers, strings, comments
pc.cls(pc.theme(pc.Role.bg))
pc.print("hello", {8, 8}, pc.theme(pc.Role.text))

A theme's file is Rio constants, but Rinc only reads them, never runs it: lines of name :: number (a star after the name or not), comments, and its first line, a comment, its title.

# Slate: warm slate gray, with yellow and blue
bg*      :: 5    # dark gray
text*    :: 7    # white

Where an app was: its stash

An app's stash is what it keeps of where it was, for its next start: the text it was showing, an unsaved draft, something slow to make again. It keeps it under keys of its own (named as save files are), and writes it whenever it likes, as it goes. Unlike its save space, which only the app changes, the Rinc drops all of an app's stash when it's told to start the app afresh: the system key with R (this app again) or Q (back to the app before).

The file calls keep it, as stash:key: pc.fileWrite("stash:place", data), pc.fileRead("stash:place", out) (-1 if there's none), pc.fileDelete("stash:place"); and fileReadAt and fileWriteAt, a part at a time, for a stash too big to hold at once (an undo log, say).

proc
pc.boot() -> Inthow many times this Rinc has started (kept in /save/rinc/boot; 0 without storage): to tell a restart from being opened again

Rinc keeps an app's stash when the app changes (a newer one installed, a project edited), so its drafts aren't lost; Sys+Q and Sys+R are what drop it. So an app that stashes something in a layout of its own, in bytes especially (an undo log, say), starts it with that layout's version, and checks it as it reads it back: one it doesn't know, from a version of the app before or after it, it leaves be and starts again. Checking what it reads as it goes (Maps' undo checks each step against the map) also catches a file cut short, or a card that's failing.

Leaving

An app that keeps its stash only now and then (once it's rested a moment, say, not each step of a held arrow) can have a leaving* :: proc(). The Rinc calls it just before the app gives way to another (the system key with Tab, Esc or H, an app called, pc.launch), and before it stops (the desktop's window closed), so the app can keep where it is then, and coming back finds it as it was. Not when the app's being forgotten (the system key with Q or R: its stash dropped). It can't draw or wait: the next app's on its way. Rinc's own apps have one, and the editor keeps changes not yet saved with it, as a draft, to have again.

place: Blob[..64]
leaving* :: proc()
  ok := pc.fileWrite("stash:place", place.asString())
end

The clipboard

Every app copies to and pastes from one clipboard, rinc's clip library's, on the card in Rinc's own stash (/stash/rinc/clip): so what's copied is there in another app, after Files has been called, and after a restart. The last 8 things copied are kept, and the newest is pasted. Each has a kind:

kind
texttext: every app that takes text pastes it
an app's ownwhat only it reads: paint (a sprite's pixels), maps (tiles, or things), music (uses, or sounds placed), files (paths, cut or copied)

An app's own kind can carry text beside it, for the apps that take text: Files' paths, say, which the editor pastes as text. An app pasting asks for its kind: it gets the newest's data if it's of that kind, or, asking for text, a text's, or another kind's text beside it. Each one copied has a number, too (clip.number(), the newest's), so an app can tell its own copy is still the newest: the editor's whole lines (copied with nothing selected) paste above the cursor's line while they are, and any other text pastes at the cursor.

import clip
_ = clip.copy("text", "hello")             # the newest now (an app's own: clip.copy("maps", data, rio))
got: Blob[..256]
if clip.paste("text", got) >= 0            # its whole length, or -1: none, or not of the kind
  log(got.asString())
end
kind: Blob[..16]
_ = clip.kind(kind)                        # the newest's kind (back 1: the one before it, and so on)

clip.more(data) adds to the newest (a big one, written a piece at a time), clip.pasteAt(kind, at, out) reads one a piece at a time, clip.drop() lets the newest go (files cut, then moved: not there to paste again), and clip.count() says how many are kept: a list of them to pick from, to come.

The code to load a file

Studio's Snippet app shows the code a game needs to load a file of studio's, so it's never typed: a map (its room and its sheets' pixels, sized as it needs, the tilemap.Map, its load, its layers' numbers by name and its sheets' flags), a picture (a sprite sheet and its flags, or a font), a song or sounds. Each of studio's apps has the command ("Open a code snippet to load it", in Sys+P's list) for the file it has open, as saved; Snippet run on its own asks Files for one. The code is written to a file in Snippet's stash (/stash/snippet/cloudlamp-map.rio) and opened in Edit, to copy with Edit's own selection; Sys+Q there comes back. A map's layers are an enum, passed to tilemap's calls as they are (an enum goes where an Int is wanted). The sizes are just what the file needs: a byte less, and it doesn't load (the log says how much it needs).

import tilemap
# cloudlamp.map: its room, its sheets' pixels
mapRoom: Blob[1247]
mapPixels: Blob[..520]
level := tilemap.Map{room = mapRoom[], pixels = mapPixels}
_ = level.load("cloudlamp.map")
# its layers: level.at(Layer.ground, cell)
Layer :: enum
  ground
  folk
end
# its flags: level.flagsAt(layer, cell) & one
SOLID :: 1

Its cache, and its log

What an app can always make again (thumbnails, an index, a download) goes in its cache space, /cache/<app> (a project's, chord+, its own), which the file calls reach as cache:name (pc.fileWrite("cache:thumbs", data)). Anything may clear it, at any time, and the app carries on, only slower.

Rinc keeps each app's log there too, as log: what the app logged lately and what Rinc said about it (a runtime error, an imageRead that needs more room), the newest 4 KB of it, with a -- started line each time the app starts. It's written as it comes, at most a second apart, and whenever the app stops. The system key with O opens it in the Log app, at this app's log, and Esc there comes back; Tab goes through the other apps' logs. On a board, that's the one place to see what an app logged once it's drawing.

Compiled apps

An app starts from its source, compiled whole. Rinc keeps what that makes, its Rio image, so the next start can load it instead of compiling again:

/apps/help/help.rio              the source (or the firmware's, for an app built in)
/cache/rinc/apps/help.rioi        its image: Rinc's header, then Rio's image

Help, on the Fruit Jam, starts in about 30 ms this way, instead of about 140; breakout in about 12, instead of 23.

When an image is used. The header says which source it's from and which Rinc made it:

header
RINCIMG1what it is
the buildwhich build of Rinc made it (when it was built): a new firmware, or a new rinc, compiles again
the source's length, and its hash64-bit FNV-1a, of the source's bytes
the image's lengththen Rio's image, that long

An image is used only when all of those match the source as it is now. A Rinc can't go by file dates (the Fruit Jam has no clock, and a card can be changed on another computer), so it reads the source and hashes it, which is far quicker than compiling it. Anything else (no image, another build's, one cut short or damaged, a source that's changed) and the app is compiled again, and its image written over the old one. If the image can't be written (a full card, say), the app still runs.

Checking once. On a Rinc whose storage changes only through itself while it runs (the Fruit Jam), an app checked once loads its image straight away from then on, without reading its source, until:

  • the Rinc starts again (a start always checks: the card may have changed while it was off);
  • anything in /apps or /lib is written or removed (the editor's saves among them);
  • the card has to be mounted again, after a failure (it may be another card, or this one changed).

The desktop and the web check every time: there, other programs (another editor, another tab of the page) can change storage while Rinc runs.

The system key. With R, the app starts again fresh: its stash and its image are both dropped, so it's compiled anew. With Q, the app is left out of the recent apps and its stash is dropped, but its image stays: it's still the image of its source, and only makes the next start quicker.

Home

A Rinc with apps starts at home (on the Fruit Jam, system/home/home.rio), which lists the apps in order of title, and starts what's picked with pc.launch.

The system key

One key belongs to the Rinc, not to apps: the system key. With another key it makes a combination for the Rinc itself; on its own it does nothing, so it isn't pressed by accident. While it's on, what's typed isn't the app's. It's:

  • the Windows key, held, on a keyboard that has one and a Rinc that gets it (the Fruit Jam);
  • a controller's guide button (the Xbox button), held;
  • or, anywhere, Ctrl and Shift tapped together: the system key for the next key, as a lock (SYS). The next key uses it up, whether it makes a combination or not (but not the pointer's keys, below: with them, steer and click, then tap Ctrl and Shift again); tapping Ctrl and Shift again turns it off. (Ctrl+Shift+Esc belongs to Windows, so the system key here is a lock, never held.)
combination
system + Esc (or a controller's Back)home, from any app
system + Tab (or a controller's RB)the switcher: the recent apps, the one before this picked
system + Shift+Tab (or LB)the switcher, from the other end
system + Qback to the app before, this one left out of the recent apps (its stash dropped); at home, the recent apps forgotten (home's stash dropped too)
system + Rthis app again, fresh: its stash and its compiled image dropped
system + Hthis app's help (its help/README), in the help app; or a notice, at the bottom, that it has none
system + Othis app's log, in the Log app (see its cache, and its log); Esc there comes back
system + arrows (or the d-pad)move the pointer, faster the longer they're held
system + V, C (or A, B)the pointer's primary and secondary buttons
system + Pthe command list: this app's commands, then the system's own (see its commands)
system + Mthe performance strip, on or off
system + Lsleep: the screen black and the sound silent, and on a board the video signal stopped, so the monitor goes to standby; the app goes on. Once every key's let go, any key or button wakes it (that key isn't the app's). Nothing's locked
system + Enterthe whole display, or a window again, where the Rinc can (the desktop's F11 too). The whole display keeps the mouse on Rinc's screen; on the web, where the browser lets a page have Esc and its own Ctrl+N, Ctrl+T, Ctrl+W (Chrome, Edge: holding Esc leaves), after a click there. Alt+Tab and Cmd+Tab are always the system's

Print Screen (no system key: the app never sees it) saves the screen as the app drew it, as /shots/<app>-<n>.png (the next number free), and says so at the bottom. Over serial it's ESC [ 57361 u, as a terminal speaking kitty's keyboard protocol sends it; the console's get brings the file back (see the Fruit Jam).

While the system key is on, a strip across the bottom of the screen shows these, apart from the app's own screen (which it doesn't change), and the app gets none of the keys or buttons that make them. In the switcher, Tab and Shift+Tab (RB and LB) move along the recent apps; Enter, or letting go of a held system key, switches to the one picked, and Esc stays. Nothing here has a time limit. The recent apps are kept in rinc's own stash (/stash/rinc/recent, a name a line), so they're there after a restart; an app gone since is left out, and so is anything in it that isn't an app's name (it never decides what starts: a Rinc always starts at home).

Locks. Shift, Ctrl or Alt tapped twice locks it: it then counts as held for every key typed, until it's tapped again. A tap is a press of those keys alone, let go within 0.4 seconds, with the two taps of a lock within 0.4 seconds of each other; any other key pressed during them means no lock, so typing capitals or Ctrl+letter never locks anything. A locked Shift capitalizes letters, a locked Ctrl makes a letter Ctrl+letter (the letter with Ctrl's bit), and on a key that isn't a character each adds its bit, as held ones do. Each lock on shows as a badge at the bottom right (SHIFT, CTRL, ALT, SYS), over the screen, which shows through around them.

The performance strip shows how long each frame's update* and draw* take, against the 1/60 s a frame has: the latest, and a bar for each of the last few seconds' frames, 8 pixels high for the whole 1/60 s (green under half of it, yellow up to all of it, red over).

Its commands

The system key with P, or a controller's Back (a SNES pad's Select; any player's), shows a list of what the app can do, over its screen: the app's own commands, then the system's (home, switching apps, this app's help and log, and the rest of the system key's). Back again closes it. An app may also show it with a key of its own (the editor's Ctrl+Shift+P), with pc.showCommands(). Typing narrows the list to the commands with that in their names; up and down (or the d-pad) move, Enter (a controller's A, any player's) does the one picked, as does a click on it; Esc (B), or a click outside, closes it. While it's up, the app waits: no update* or draw*, and its sound held, silent, till it closes. So it's a game's pause, its own commands (restart, options) there with the system's.

An app gives its commands with commandList*, which Rinc asks each time the list opens, so it can say what makes sense then (a label's &, an Alt letter's for the ui library, isn't shown: &Save is Save, && an &): up to 240 of them (Rinc reads them where they are, in the app's memory; past 240, the log says so, and the rest are left out):

commands := [2]pc.Command{
  {label = "Flip the sprite sideways", keys = "H", key = 'h'},
  {label = "Grid, shown or not", keys = "G", key = 'g'},
}
commandList* :: proc() -> []pc.Command
  return commands[0..<2]
end
pc.Command
labelwhat it does (38 characters show)
keysits keys, as shown at the right ("" for none; 11 characters show)
keywhat picking it types: the key, as pc.key() gives it next (before anything typed after), so a command is just its key; or pc.COMMAND + n, a command of the app's own with no key

Up to 56 of an app's are listed. A key or button still held as the list closes isn't the app's until it's let go.

The console

The console (system/console/console.rio) is an ordinary app: Rio, typed and run in a session of its own (see Rio inside an app), and commands for the apps in storage. Its help text, console/README, says how.

Help texts

Help texts are Markdown, for the help app (system/help/help.rio) and any app that shows help. Each app's own are in its folder, as /apps/<app>/help/<path>.md (named <app>/<path>), and those that are no app's in /help/<path>.md (named <path>); a bundle carries them the same way (apps/<app>/help/..., help/...), and storage takes the place of the bundle, as for apps. A name leaves .md off: rinc/spec/apps. A set of texts (the first part of their names) with a SUMMARY text is listed by that, as the docs' tables of contents are. A project's texts are its own, in /projects/<app>/help, named with its +: chord+/README, which the system key with H shows while the project runs.

The file calls reach them by name, as help:name, like an app's own areas (see an app's own files), for reading only:

pc.dir("help:", out) -> Intlooks again, and adds every help text's name to out, in order, a line each (f rinc/spec/apps), as many whole lines as fit: how many there are
pc.fileRead("help:rinc/spec/apps", out) -> Inta text, added to out, as much as fits: its whole length, or -1 if there's none (an app's own first, then the rest: storage's, else the bundle's)
pc.call("help", "rio/spec/statements#if")the help app, at that text and maybe a heading (it reads the name as its args: see calling an app)

The help app shows them, and follows their links; its own help text, help/README, says how.

More files

An app can be more files than one, in its folder: include "parts/a.rio" makes another file part of this one, and import .shapes makes a module of shapes.rio (or shapes/shapes.rio), both from the app's own folder; import tween is from the library, /lib (tween.rio, or tween/tween.rio), shared by every app. Storage's files come first, then the bundle's (apps/<app>/..., lib/...), then, for the library, Rinc's own, built into every Rinc (its library folder: tilemap, song and undolog), so those are there with no card, or none installed; a card's own file of the same name wins. An app is at most 16 files besides its main one, of any length (they're read a part at a time as it compiles: see memory). Its compiled image notes every file it read (see compiled apps), so a change to any of them compiles it again. On the desktop, rinc game/ (or rinc ., in the folder) runs the app of a folder, game/game.rio, its own files from beside it; exporting it carries all of its folder. The system apps are made this way, each a main file and its parts.

/projects/game/game.rio          include "parts/levels.rio", import .shapes, import tween
/projects/game/parts/levels.rio
/projects/game/shapes/shapes.rio
/lib/tween.rio

Rinc's library

Built into every Rinc (and installed in /lib with the system apps, where a newer one can go):

  • tilemap: tile maps, read, written and drawn, as studio's Maps makes them (maps).
  • song: songs as studio's Music makes them, and their sounds (Sound's file): read a line at a time, and played by Rinc (pc.songPlay, sound) on up to 8 voices (from its voice), one song at a time. A song has patterns, each sounds placed in time (at a step, on a channel, at a pitch shift, a volume and a speed), and uses them in turn, each use with its own shift, volume and speed (shift and volume ramped across it), round its loops; levers over the whole song (shift, volume, speed) change as it plays. A sound of the file on its own plays too, for a game's effects. The app gives it room, one Blob (its buffer, as big as Music shows): load puts the sounds' notes first, 128 bytes a sound (song.SOUND_BYTES), from the first to the last the song plays, then the song's patterns, uses and placements, and its sounds' speeds and loops. (Or the two apart, notes and room: for sounds alone, as many as the app likes from the first, as Sound shows.) load logs it when there isn't enough. The sounds come from the path the song names, or a file of that name beside the song, so a game keeps its song and sounds together in its folder. Music plays songs with it, so a game plays them just as Music does.
import song
buffer: Blob[1112]                        # its sounds' notes and the song, together (as Music says)
tune := song.Song{buffer = buffer[], voice = 4} # voices from 4 on: 0 to 3 the game's own
_ = tune.loop("tune.mus")                 # read (its sounds too; else the log says why), then round and round
if tune.load("tune.mus")                  # or read, then
  _ = tune.play(0, false)                 # from its first pattern (true: that one alone)
end                                       # (Rinc plays it from here: nothing to call each frame)
tune.sound(0, 2)                          # sound 2, once, on voice 0
tune.setShift(2)                          # the whole song 2 semitones up, at once (setVolume, setSpeed too)
tune.pause(true)                          # held where it is (false: on again)
tune.tick()                               # only to show where it's playing: tune.playUse, tune.playPart
  • clip: the clipboard every app shares (see the clipboard).
  • appfiles: apps and projects by name, their sources and folders: read, saved, copied as projects, renamed, removed (see finding apps, and projects). Files, the editor and the console use it.
  • recent: the files an app had lately, the latest first, each with where it was (a note of the app's own), in its stash: Ctrl+Tab walks them (the list on the screen while Ctrl's held, letting go opens the pick), Ctrl+W closes one (out of the list). The editor and studio's apps use it.
  • notice: a few words shown for a while, then gone (a game's "Keeper: our lamp went out", an app's "Saved"): said once, drawn each frame while it lasts (counted as it's drawn: 4 seconds, or as long as it's told), in a box at the screen's bottom, or where the app says, wrapped to it. What's said is kept as it is, not copied (say(s: static String): a literal, or a view that lasts).
import notice
said := notice.Notice{}                   # (or {box = pc.Rect.of({0, 0}, {160, 22}), seconds = 2.0})
said.say("The lamp burns bright.")
draw* :: proc()
  said.draw()                             # while it lasts: its box, then its words
end
  • ui: forms, buttons and fields, so apps look and work alike (plans/ui.md). In draw*, each call draws its widget and says what happened to it; the app keeps its own values, the library only which widget is focused and where the text being edited is. Top to bottom, a label beside each value, lined up. The keys are the same everywhere: Tab and Shift+Tab, or Up and Down (a controller's d-pad), go from widget to widget in the order of the calls; Left and Right change a value; Enter (A) presses; a click focuses and presses; "&Save" makes Alt+S press it (its letter underlined while Alt's held; && shows an &). A list of names, a choice's, the pages', an ask's answers, is a String apart by | ("&Options|&Fruit", each with its letter; || is an | in one). Esc (B) is the app's, ui.back(), and the keys the ui didn't use are ui.key()'s. ui.hints() is a line at the bottom saying what the keys do on the focused widget, for the keyboard or the controller, whichever was used last. Its looks are the theme's, its letters Rinc's font whole (room above for accents); ui.style sets an app's own colors (rarely: a game's menu), and its font (ui.style.font: {line = 9} is Rinc's own compact, or one of the app's, pc.fontRead's, fixed or proportional; ui.style.pad, pixels more a row): a widget's height is its font's line, and everything's measured in it. And pages (ui.tabs: LB and RB, Ctrl+Page Up and Down, a click), a list (ui.list, its rows each drawn by ui.item; Up and Down move its pick, Enter chooses), a question over the rest (ui.ask, called each frame while it's asked: -1 till it's answered), a few words for a few seconds (ui.toast), and a button that's a command (ui.command: pressed by its key typed anywhere, or picked from the command list, its keys shown in the hints). More, for an app's own screens: a search steering the list after it (ui.find), a menu over the rest (ui.menu, its items apart by |, ~ one that can't be done now), a question with a line of text to type (ui.askText), text to read, scrolled, wrapped or not, a color a line if the app gives them (ui.view), cells to pick from that the app draws (ui.grid, each at ui.cellBox(i)), and for drawing of its own: a box among the widgets (ui.space), the box the last one took (ui.last), and a list row's room before its words (ui.item(s, indent)). ui.placeAt puts the next widget where the app says, ui.hint sets the hints' words for a screen, ui.entered says Enter was pressed in a field, and ui.pending gives an app that reads keys itself the ones the ui kept (typed after a question's answer). A list can pick many (ui.list(label, &pick, count, rows, marks), a Bool a row, the app's), as Windows' Explorer does, but seen: a move picks none (the pick alone is what's acted on), Shift a run from the anchor, Ctrl moves alone, Ctrl+Space (Ctrl+click, a controller's X) adds one or takes it away, Ctrl+A all; ui.item shows a row picked (marked) and in a color of the app's, and ui.rowAt says which row is at a point (a right click's). ui.modal() says a menu or a question is shown this frame (opened after the last frame's widgets): the widgets before it answer to nothing. A letter alone, with no field focused, is its widget's (as in a Windows dialog), a button pressed, the rest focused; keys go in order, a focus change at a time (the rest wait in Rinc's queue, for whatever's next: the command list, say); Tab with nowhere else to go is the app's. A list after a find with words in it, and nothing in it, says nothing matches; ui.rowAt is -1 below its last row. ui.next({...}) sets the next widget's own way, the rest as the style has it: plain, a list or a view on the screen's own background (one that's most of the screen: Home's, Files'), framed while it's focused; font, one of the app's in ui.fonts (1 to 3: ui.fonts[0] = big, then {font = 1}); and flex, its share of the room left along the way the widgets go. In a row (ui.row), the widgets without a flex are as wide as they need (a button its words, a check its label and box) and those with one share the rest by it; down the page, a flex's share is of the height left above the hints' line, a list's or a view's rows as many as it holds (a flex space in a row pushes what's after it to the right). Flex is laid out by last frame's sizes; a frame whose sizes changed where it mattered isn't shown (pc.holdFrame), the next, laid out by them, is, so nothing jumps; a layout that never settles is said, in the log and in the hints' line. ui.rowsLeft() is the rows a list fits above the hints (for an app that needs the number first), and for an app's own words among the widgets: ui.ink prints in the style's font, ui.measure and ui.fits measure in it, ui.lineHeight() is a widget's height, and ui.fitted cuts words to a width where a word ends.
import ui
name: Blob[..24]
volume := 5
speed := 1
music := true
draw* :: proc()
  pc.cls(pc.theme(.bg))
  ui.begin()
  ui.title("Options")
  _ = ui.field("&Name", name)             # a line of text, the app's own Blob: true as it changes
  _ = ui.number("&Volume", &volume, 0, 10) # Left and Right, + and -, its digits typed
  _ = ui.choice("&Speed", &speed, "Slow|Normal|Fast")
  _ = ui.check("&Music", &music)
  ui.row(2)                               # the next two side by side
  if ui.button("&Save") do save()
  if ui.button("&Reset") do volume = 5
  ui.text("Saved as you go.")             # words, wrapped
  ui.done()
  ui.hints()
end
_ = ui.tabs("Options|Files", &page)       # pages along the top
r := ui.list("&Files", &pick, count, 8)   # 8 rows shown: r.x to r.y, each drawn
for i in r.x..<r.y do ui.item(names[i])
if ui.chosen() do open(pick)              # Enter, A, or a click on the row picked
if ui.command(commands[0]) do save()      # {label = "&Save", keys = "Ctrl+S", key = 's' | pc.CTRL}
if deleting
  a := ui.ask("Delete it?", "&Delete|Cancel") # last of all: over the rest
  if a == 0 do remove()
  if a >= 0 do deleting = false
end
ui.toast("Saved")                         # a literal, or words that last
  • undolog: undo and redo kept on the card, in the app's stash, so they reach back as far as the app likes and are there again after another app has run. The app's steps are its own bytes; the library keeps them, groups them (one undo takes back a group), checks them as they're read back, and hands each to the app to undo or redo. A log has a head: the library's version, the app's (version), and what it's about (a file's path, say), so an app before or after this one, or another file, isn't taken on. Studio's Paint, Sound and Music, and the editor, keep their undo with it.
import undolog
room: Blob[..1100]                        # the most a step can be, and 8 more (120 bytes at least)
u := undolog.Log{room = room, version = 1}
_ = u.resume("undo", "my.thing")          # the log as it was, if it's about this; else a new one
apply :: callback proc(step: String, back: Bool) -> Bool  # (undone, or redone: false if it doesn't fit)
  return true
end
u.group()                                 # what one undo takes back starts here
_ = u.step("its bytes")
_ = u.undo(apply)                         # u.broke: a step didn't fit, and the log started again
_ = u.redo(apply)
u.tick()                                  # each frame: what's waiting goes onto the card after a moment
u.flush()                                 # before leaving (leaving*)
u.start(key, about), u.resume(key, about) -> Boola new log under the stash's key; or the one there, if it's about about (and this version)
u.group(), u.step(s) -> Boolthe next step starts a group; a step (false: bigger than room)
u.undo(apply) -> Bool, u.redo(apply) -> Boolthe last group undone (its steps last to first), or the next redone, each through apply
u.rewrite(s)in apply: the step's bytes made s (the same length), for an app that swaps what a step keeps with what's there
u.retitle(about)what it's about, changed (a file saved under another name)
u.tick(), u.flush()steps onto the card a moment after the last; at once

An app's tests

An app's tests go in dev/test.rio, in its dev folder. It includes the parts it tests (from the app's folder: include "parts/text.rio"), and any setup part they need, then calls their procs and checks what they do with assert, so a failure stops it at its line. pc.launch("game+/dev/test"), or run game+/dev/test in the console, runs it as the project does, on every Rinc: its other files from the app's folder and its saves the project's. Being in its dev folder, an app's tests are left out of installing, bundles and exports. The editor's are an example: system/edit/dev/test.rio, with parts/setup.rio its sizes and colors.

The editor

The editor (system/edit/edit.rio) is an ordinary app too: a file at a time, by path, up to 32 KB, with the keys of most editors. Ctrl+O opens a file, through Files (called to pick one), and Ctrl+Shift+S saves as another (Files, called to pick where: what's unsaved waits in the editor's stash meanwhile). An installed app's files are read only: saving one of an app's saves it in its project, made from the app first (see projects). Ctrl+R saves and runs the app or project the file is in, and Ctrl+Shift+P lists every command. Its help text, edit/README, lists the keys.

Tile maps

A tile map is a picture made of tiles: a grid of cells, each a sprite of a sheet (a PNG, as Paint makes them), or empty. A map can also hold things: sprites placed anywhere, the player's start, enemies, doors, signs. Rinc keeps maps in .map files, as studio's Maps app makes them, and its library's tilemap reads, writes and draws them, for games and editors alike.

A map's file

Text, so it's small and can be read and changed in the editor. rinc map 4, then its sheets, then its layers, drawn one over another, the first at the bottom:

rinc map 4
sheet 1 /save/paint/cave.png 8
sheet 2 /save/paint/chars.png 8x16
layer 1 ground tiles 1
size 4 2
offset 0 0
000001000200----
------------0300
layer 2 actors things 2
offset 0 0
thing 0201 at 40 64 name player
thing 0700 at 120 64
thing 0300 at 64 96 span 2 1
thing ---- at 200 0 span 2 4 name exit
  • sheet: its number (from 1), its path, and its sprites' size (8, or 8x16 for 8 across and 16 down; 4 to 64 each). A sheet can be any width and height: its sprites are the whole ones across and down (pixels past the last whole sprite, at its right or bottom, aren't one). A new map with no sheet yet has one with an empty path.
  • A tile, or a thing's sprite, is a sprite's place in its sheet, {column, row} from {0, 0}: four hex digits, the column's two then the row's (0201: column 2, row 1), or ---- for none. So a sheet grown or shrunk across never moves a map's tiles (one past its edge now is drawn as missing, and kept). Up to 256 sprites across and down; the very last of them, {255, 255}, means none, and Maps keeps the one before it for its fill.
  • layer: its number (from 1), its name, its kind (tiles or things) and its sheet's number.
  • A tiles layer: its size (cells across and down, 1024 at most each), its offset (where its first cell is, in the map's pixels, negative too), then a line a row, four hex digits a cell (its sprite, column and row), or ---- for empty.
  • A things layer: its offset, then a thing line each, in the order they're drawn: its sprite (four hex digits, column and row; ---- for none, a trigger or a start), at (pixels from the layer's offset, -32768 to 32767 each), then only when they aren't the usual: span, how many sprites across and down it is from its sprite at the top left (1 to 16 each; 1 1 left out), and name.
  • A name, a layer's or a thing's: 1 to 15 bytes of letters, digits, _, - and .. No spaces, so a line reads only one way. Two things can share a name (find finds the first).

Maps of before read too, and are written as rinc map 4: rinc map 3 (each sprite a number, three hex digits, counted across its sheet's rows, with across on the sheet's line: made {column, row} as they're read), and rinc map 2, of before sheets were listed and things (each layer with its own tiles path and size, and across: a sheet each). A rinc map 1 isn't read.

tilemap: the library's maps

import tilemap (/lib/tilemap.rio). It's Rio, and keeps nothing of a map's own: the app gives a map its room, one Blob for its cells, its things and their names, and arrays for its sheets and layers, as big as it likes, and reads each new level into the same ones. Each sheet's picture is the app's too: it reads it (pc.imageRead) and passes it to draw. The library's own room is tilemap.work, 4 KB (tilemap.WORK), to read and write files through, a piece at a time: a map's text never has to fit in memory. Between its calls nothing's left in it, so an app can use it for its own work too (Maps keeps its undo's steps there, and writes them to the card before it loads or saves a map).

Its sheets and layers go in arrays of tilemap.Sheet and tilemap.Layer: the library's own (4 sheets and 8 layers, for one map at a time: a game's map, each level read into it), or the app's, as many as it likes (tilemap.Map{sheets = sheetRoom[], layers = layerRoom[], ...}: a second map, or a bigger one).

How much room: Maps shows it at its top right, as the Blob a game needs (and says so when it saves); tilemap.roomIn(path) says from a map's file; and load, when a map doesn't fit, logs what it needs.

import tilemap
room: Blob[12000]                            # its cells, things and names
pixels: Blob[..(128 + 1) * 128 + 256]       # its sheet's pixels and flags (as Paint says)
level := tilemap.Map{room = room[], pixels = pixels} # (its sheets and layers: the library's own)
if level.load("/save/maps/cave.map")    # (and its sheet; else the log says why: the room it needs, say)
  actors := level.layerNamed("actors")       # -1: none
  for i in 0..<level.things(actors)
    t := level.thing(actors, i)
    if t.name.asString() == "player"
      start(t.at)
    case t.sprite.x >= 0                     # ({-1, -1}: no sprite)
      spawn(t.at, t.sprite, t.span)
    end
  end
end
camera := {0, 0}
draw* :: proc()
  pc.cls(0)
  level.draw(0, camera)                      # layer 0, the map's pixel camera at the screen's top left
  if level.at(0, (camera + {160, 120}) / 8) == {5, 0}   # (the sprite at column 5, row 0 of its sheet)
    pc.print("on a {5, 0}", {4, 4}, 7)
  end
end

Its structs

Sheet* :: struct
  path: Blob[..96]
  sprite: [2]Int     # its sprites' size, in pixels
  at: Int            # read (readSheets): its pixels, from here in the map's pixels
  size: [2]Int       # and its picture's size ({0, 0}: not read)
  flagsAt: Int       # then its sprites' flags, a byte each, flagCount of them
  flagCount: Int
end
Layer* :: struct
  name: Blob[..15]
  kind: Int          # TILES or THINGS
  sheet: Int         # which of the map's sheets (from 0)
  at: [2]Int         # its offset, in pixels
  size: [2]Int       # TILES: in cells
  start: Int         # TILES: its first cell, in the room's cells; THINGS: its first thing
  count: Int         # THINGS: how many
end
Thing* :: struct     # one thing, unpacked (in the room it's packed: below)
  at: [2]Int         # pixels, from its layer's offset
  sprite: [2]Int     # its top-left sprite, {column, row} in its sheet ({-1, -1}: none)
  span: [2]Int       # sprites across and down ({1, 1}: one)
  name: Blob[..15]   # "" for none: a copy, so it stays good as the map changes
end
Room* :: struct      # what a map needs (-1s: not a map)
  bytes: Int         # its room's
  sheets: Int
  layers: Int
end
Map* :: struct
  sheets: []Sheet    # the app's arrays, as many as it has room for
  sheetCount: Int
  layers: []Layer
  count: Int         # layers
  room: Blob         # the app's room: the cells, the things and their names
  cells: Int         # in all its tiles layers
  thingCount: Int    # in all its things layers
  names: Int         # their bytes, at the room's end
  pixels: Blob[..]   # the app's, if it gives one: its sheets' pictures and flags (readSheets, as it loads)
end

In the room: the tiles layers' cells from its start, 2 bytes a cell, row by row; then the things, 10 bytes each (x and y, 2 bytes each, signed; the sprite, 2; the span less 1, a byte, 4 bits across and 4 down; a byte kept for later; and where its name is, 2 bytes, 0 for none); and the names at the room's end, growing down, each a length byte and its bytes. A name taken out or changed gives its bytes back at once. So 200 things take 2 KB, and their names only what they spell.

A layer's cells are where its start says: a layer moved (moveLayer) moves no bytes. A Sheet is 27 words (its path), past Rio's 16 for a copy, so code reaches one by number, &level.sheets[i].

Its procs

m.load(path) -> Bool, m.loadStash(key) -> Boola map's file (or one kept in the app's stash) read into it: false if it can't be, and it's as it was; the log says why: no such file, not a map (and the line), or the room it needs (Blob[n], sheets, layers)
m.save(path) -> Bool, m.saveStash(key) -> Boolwritten as rinc map 4: false if it couldn't be
tilemap.roomIn(path) -> Room, m.needs() -> Room, m.used() -> Intwhat a map's file needs, and what this one does; the room's bytes it uses
m.start(size, path, sprite) -> Boola new map: one tiles layer of size, all empty, of the sheet at path
m.at(layer, p) -> [2]Int, m.filled(layer, p) -> Bool, m.set(layer, p, t), m.clear(layer, p), m.inside(layer, p) -> Boolcell p's tile, {column, row} in its sheet ({-1, -1} for none, and past the layer's edges); whether it has one; changed; emptied; whether it's a cell
m.cell(layer, p) -> Int, m.setCell(layer, p, c), tilemap.packed(t) -> Int, tilemap.unpacked(c) -> [2]Intfor editors: a cell's tile packed as the room keeps it, column + row * 256 (tilemap.NO_TILE, 65535, for none), and set so; a tile packed, and back
m.tile(layer) -> [2]Int, m.sheetPath(layer) -> Stringa layer's sheet: its sprites' size, its path
m.spriteAt(layer, t) -> [2]Intsprite t's ({column, row}) top left in the layer's sheet, in pixels
m.readSheets() -> Booleach sheet's picture, then its sprites' flags (a byte a sprite, as Paint sets them: apps), into the map's pixels; load does it, for a map given pixels. False if one can't be read, or there's no room (the log says)
m.flag(layer, name) -> Int, m.flagsAt(layer, p) -> Inta flag's bit, by its name in the layer's sheet (0: none of that name); the flags of cell p's tile (0 for an empty cell, or past the edges). A game asks a flag's bit once (solid := m.flag(ground, "solid")) and tests m.flagsAt(ground, cell) & solid
m.sprite(layer, t, p)sprite t of the layer's sheet (the map's own) drawn with its top left at the screen's p
m.thingIn(layer, p) -> ?Thingthe thing of a things layer whose top left is in cell p (counted in its tiles, from its offset), or nil
m.sheetFor(path, sprite) -> Inta sheet's number in the map's list, added if it isn't there (-1: no room)
m.setSheet(layer, path, sprite) -> Boola layer's sheet changed, its tiles kept as they are ({column, row} in it)
m.draw(layer, camera, how?)a layer from its sheet (the map's own, read into its pixels), the map's pixel camera at the top left: a tiles layer's tiles; a things layer's things, in order (one with no sprite isn't drawn). how (a tilemap.Drawing): sheet, another sheet's picture to draw from (an editor's); the box it's in (at, size: left out, to the screen's edge, whatever its size: pc.screen), shrink (2, 4: an editor's view of big tiles), missing (a color for a sprite past the sheet's)
m.things(layer) -> Int, m.thing(layer, j) -> Thinga things layer's count, and its thing j, unpacked
m.place(layer, t) -> Bool, m.placeAt(layer, j, t) -> Bool, m.change(layer, j, t) -> Bool, m.takeOut(layer, j)a thing added (drawn over the others; or as thing j, those from it on one later), changed, or taken out: false if there's no room (or it's no thing)
m.thingOver(layer, p) -> Intthe last-drawn thing over the map's pixel p (-1: none), as an editor picks one
m.find(name) -> [2]Intthe first thing of that name: its layer and its number ({-1, -1}: none)
m.layerNamed(name) -> Int, m.nameLayer(layer, name) -> Bool, tilemap.nameOk(s) -> Boollayers by name
m.addLayer(after, kind, size?) -> Boola layer after one (-1: first): a tiles layer as big as the nearest tiles layer (or size), and where it is, empty; a things layer, with none. False if there's no room
m.removeLayer(layer) -> Bool, m.moveLayer(layer, to)a layer taken out (never the last), or moved to be number to
m.reshape(layer, size, shift) -> Boola tiles layer made size, its cells moved shift, what's past its new edges gone, its offset moved back as far (so its cells stay where they were on the map): false if it doesn't fit
tilemap.sizeIn(s) -> [2]Int, tilemap.notedSize(path) -> [2]Int"8" or "8x16" as a size; a sheet's sprites' size as Paint's notes in it say (else 8 by 8)

A game that draws its own way, edges worked out from the cells around each one, say, reads the cells with at and draws as it likes; or works them out once, as a level loads, into a layer of its own that draw then draws.

Speed

On the Fruit Jam: a screen of 8 by 8 tiles drawn, about 5 ms; 500 things, 3 ms. A map of 16,384 cells and 500 things (38 KB of text): loaded in about 380 ms, saved in 340 ms, almost all of it the card's. Reshaping, finding a thing and placing one take a millisecond or two.

Limits

  • Sprites. A sheet's first 256 sprites across and 256 down can be placed (a 2048 by 2048 sheet of 8 by 8 sprites, all of it), but for the very last, {255, 255}: none.
  • Pixels. A thing's x and y are 16 bits, -32,768 to 32,767, though a layer 1,024 cells of 64 pixels is 65,536 across.
  • Sheets changing width. Nothing's renumbered: each tile is {column, row}. One now past the sheet's right or bottom edge draws as missing (how.missing), and is kept, so it's back if the sheet grows again.
  • One sheet a layer. A level whose things come from two sheets uses two things layers.
  • Order. Things draw in their list's order. Games that sort by y (a thing lower down drawn over one higher) sort them themselves.

Rio inside an app

An app can run Rio of its own: a console, an editor, a tutorial with exercises to type. It hands a session some of its own memory, gives it Rio to compile and run, and runs the session's frames from its own. The session has the pc module too, so what it draws shows on the screen. There's one session at a time, and a session can't start one of its own.

proc
pc.rioStart(mem, tables, app?) -> Inta fresh session: its code and data in mem, its compiler's tables in tables, both the app's own memory: 0, or -1. app, an app's name (chord, or a project, chord+): the session's paths start in its folder, as the app's own do (include "parts/x.rio", import .x, a file it reads); left out, only absolute paths and Rinc's library
pc.rioEval(text) -> Intcompile and run a piece of Rio, as a REPL does: 0 done, 1 unfinished (it needs more text), -1 an error
pc.rioFrame() -> Intthe session's update then draw: 0, 1 if it has neither, -1 an error
pc.rioType(key)a key for the session's pc.key()
pc.rioError(out) -> Intthe last error, as text, added to out: how long it is
pc.rioLog(out) -> Intwhat the session has logged since the last call, as much as fits, taken and added to out: how much (each line ends with 10)
pc.rioIndent(text) -> Inthow many steps an unfinished input's next line is indented

Like a REPL, a session keeps its globals, procs and types from one piece to the next, and a bare expression logs its value:

mem: Blob[65536]
tables: Blob[40960]
out: Blob[..256]
log(pc.rioStart(mem[], tables[]))
r := pc.rioEval("x := 6 * 7\nx + 1\n")
_ = pc.rioLog(out)
log(r, out.asString())
log(pc.rioEval("y := nope\n"))
out.clear()
_ = pc.rioError(out)
log(out.asString())
0
0 43

-1
1:6: undefined name near 'nope'

tables needs room for the compiler's tables, the pc module's included: 40 KB is plenty for what's typed (room for pc and about as much again of a program's own names, structs and procs); past 40 KB, the rest holds a program's strings, for an app loaded whole (the console's is 48 KB). Too little is an error from pc.rioStart, which pc.rioError explains. The memory handed over is the session's from then on: the app mustn't use it for anything else while the session lives. An app starting over, or pc.rioStart again, ends the session. A session's keys come only from pc.rioType, so the app decides what it gets: the console keeps Esc, to stop what's running.

The built-in console, system/console/console.rio, is an ordinary app built on these procs.

Building

This guide is about the Rinc in this repository: the Fruit Jam firmware, the desktop program and the web player, all from one C core. What any Rinc provides is in the platform.

git clone --recursive https://github.com/rincpc/rinc     # (or: git submodule update --init)
  • The Fruit Jam: the Pico SDK and an ARM GCC, then cmake -S . -B build -G Ninja -DPICO_SDK_PATH=/path/to/pico-sdk && cmake --build build. See the Fruit Jam.
  • The desktop: cmake -S . -B build-desktop -DRINC_PLATFORM=desktop && cmake --build build-desktop --config Release. See the desktop.
  • The web: python tools/web.py --wasm=rinc.wasm --wasm-full=rinc-full.wasm, with zig. See the web.

Prebuilt desktop programs (each just the one program, zipped), web players and firmware are in the nightly release.

Source layout

lib/rio/           Rio, as a git submodule
lib/Pico-PIO-USB/  USB host over PIO, for keyboards on the Fruit Jam
lib/fatfs/         FatFs, the SD card's filesystem (vendored)
src/core/          shared by every platform: the screen, palette, font and console, host procs
                   (rinc.c, audio.c), bundles, the terminal REPL, and pc.rio (the host procs,
                   written out in Rio) with pc_host.h, its C (rinc -H src/core/pc_host.h
                   src/core/pc.rio, after changing pc.rio: its source, structs and sigs)
src/rp2350/        the Fruit Jam: HDMI out (video.c), USB keyboards (keyboard.c) and controllers
                   (gamepad.c), sound (audio.c), the SD card (sd.c), the main loop
src/desktop/       a window (SDL3, built in) or headless
src/web/           wasm for a web page, and the page around it (page.html)
system/            the built-in apps, ordinary apps: home.rio and console.rio
apps/              demo apps
tests/             pc.c: pc_host.h is pc.rio's, and pc.rio matches what Rinc registers
tools/             font.py (the font table), web.py (the web players' wasm), send.py (an app to
                   the board), install.py (Rinc's apps and docs onto the board's SD card),
                   embed.cmake (the web players, built into the desktop rinc), bundle.cmake (a
                   firmware's own apps, if any), adpcm.py (sound into IMA ADPCM)
docs/              these docs: SUMMARY.md sets the order; mdbook builds them as a site

The Fruit Jam

Rinc runs on the Adafruit Fruit Jam, an RP2350 board with HDMI out, USB host ports, an SD card slot and a headphone jack.

Building and flashing

Install the Pico SDK (2.x) and an ARM GCC; the Raspberry Pi Pico extension for VS Code sets up both.

cmake -S . -B build -G Ninja -DPICO_SDK_PATH=/path/to/pico-sdk   # or set PICO_SDK_PATH in the environment
cmake --build build --target flash   # picotool reboots the running board into BOOT mode, writes rinc, starts it

The first time (or if the board isn't answering on USB), hold BOOT while resetting it and copy build/rinc.uf2 to the drive that appears.

The firmware carries no apps, as on the desktop and the web: they go on the SD card (below), so the firmware stays small (about 650 KB) and quick to flash, and apps change without flashing. A firmware can still carry apps, such as a game of its own, as its bundle: RINC_BUNDLE, its apps' .rio files separated by |, RINC_HOME, the one home means (by default the only app, or one named home), and RINC_HELP, help texts (name=folder pairs: Rinc's docs as rinc, say). An app of the same name on the card takes a bundled one's place.

cmake -S . -B build -G Ninja "-DRINC_BUNDLE=$PWD/apps/breakout.rio" -DRINC_HOME=breakout

Using it

Rinc starts at home on the HDMI screen (640x480, each pixel 2x2): the apps on the SD card, sorted, and the console. Type to narrow the list, up and down (or the d-pad) to choose, Enter (or A) to start. The system key with Esc comes back home from anywhere: Windows+Esc, a controller's Xbox+Back, or Ctrl and Shift tapped together and then Esc. Esc and Ctrl+C alone belong to apps. A keyboard's volume knob or keys set the volume (both outputs, in 2.5 dB steps, and mute).

An app that isn't a game, or one that stops with an error, leaves its log and the error on the screen, until system+Esc goes home. One that runs out of memory shows how near each limit it came too.

The first start of an app compiles it, and keeps what that makes on the card, in /rinc/cache/rinc/apps, so later starts are quicker (help: about 30 ms instead of 140). Changing an app's source compiles it again, and system+R starts an app afresh, compiled anew: see compiled apps.

Keyboards plug into the USB host ports. Controllers there can be wired Xbox 360 and Xbox One/Series ones, recognized by the USB interfaces they offer (src/rp2350/gamepad.c).

What the console shows also goes out the USB serial port, a line at a time, and what's typed there goes to the console too:

python -m serial.tools.miniterm COM3 115200 --eol CR   # pip install pyserial; Ctrl+] quits

Over serial (not the keyboard), Ctrl-C opens the console in place of whatever's running, for tools such as send.py, and Ctrl-B opens the firmware's own console, which needs no apps on the card (below). A serial terminal sees each line once it's entered, not as it's typed.

Apps on the SD card

A FAT32 card holds Rinc's storage, /rinc on the card (inside Rinc, that's /: an app's /save/x is the card's /rinc/save/x): apps as /rinc/apps/name/name.rio, with their other files beside them, each app's own files in /rinc/save/name, and help texts in /rinc/help. To fill a card, the board plugged in over USB:

uv run tools/install.py              # home, the console, the editor, help, files, colors, the demos, and Rinc's and Rio's docs
uv run tools/install.py home chord   # just these apps
uv run tools/install.py --to E:      # or into a card in a reader, at E:

That replaces those files on the card and leaves the rest alone (your projects, saves and other apps). Running it again after changing Rinc updates the card. Without a checkout, a release's rinc-system-apps.zip (the system apps and the docs) and rinc-demo-apps.zip each hold a rinc folder: unzip them onto the card's top level.

With no home app on the card, the board starts in the firmware's own console, on the screen and over serial: Rio, with ls, save, delete, home, and put path, any file under /rinc as hex (how install.py sends them); get path sends one back the same way (a screen saved with Print Screen, get shots/<app>-1.png). With no console app, Ctrl-C opens it too. audio says how much of the time mixing takes, and frame how long the app's frames took since it started or since last asked: update's and draw's time (each on average and at most), how many frames ran over a 60th of a second, and the longest gap between two frames' starts (uv run tools/boardplay.py COM3 "con:run paint" wait 5 hold right 10 "fw:frame": ask once, at the end, as the console leaves the app for home). jit off and jit on start apps from then on without native code, or with it (tools/boardspeed.py times both).

For working on the board from a PC, tools/ has a few more, each uv run tools/<name>.py COM3 ... (their first lines say how): boardput.py puts files on the card and boardget.py brings them back (a second or so each, by put and get); boardpaste.py pastes an app's source in, as a person with a serial terminal would (save, then Ctrl-D); and boardplay.py plays an app as its user does (the console's run, buttons tapped and held as kitty's keyboard protocol sends them, waits) and takes screenshots, fetched and enlarged to look at on the PC.

Apps on the card are managed from the console app with ls, run, delete, install and home (see the console). From a PC, uv run tools/send.py apps/bounce.rio sends one app and starts it, in a couple of seconds, and --save keeps it on the card.

The console edits the line being typed (left and right, Home and End or Ctrl-A and Ctrl-E, Backspace and Delete; up and down go back through earlier lines), colors it (keywords, constants, comments), and indents each next line of an unfinished input. A serial terminal gets the same, as terminal escapes, which the screen's console understands too. apps/combo.rio tries everything at once: sound, a controller and the keyboard, both as buttons and as typing.

A thumb drive in a USB-A port (or the board's hub) is the stick: its files at /stick, beside Rinc's own folders (in Files, at /), to copy onto the card (an app's folder copied to /apps is installed), and to copy things onto, to take elsewhere. The first one plugged in, FAT32 or FAT16 (not exFAT, as the card), 512-byte blocks, read through TinyUSB's mass storage host as FatFs's second drive; it's mounted the first time it's looked in, and goes when it's pulled out.

Memory

Of the RP2350's 520 KB of SRAM:

the app space256 KB: Rio's memory, for an app's code and data (and its source, read from the card, while it compiles); Rio compiles the app's simple loops and procs to Thumb-2 code in what the app leaves free
the screen150 KB: the one drawn into, and the copy being shown
code kept in SRAM, as it's faster than flash36 KB: Rio's interpreter loop (13.5 KB, with its jump table), sound's mixing (5 KB), the USB host's (4 KB: the keyboard, its timing tight), HDMI's sound packets (2 KB), the USB serial port's interrupts (2 KB), malloc's arena (1 KB), the rest small
the sound's 16 voices2.4 KB
USB host buffers, the big stack6 KB each
the log, the serial port's ring4 KB each
the command list's overlay, the VM, the console's line, the restabout 15 KB
the card's and the stick's FatFsabout 2 KB: a volume each (its 512-byte sector buffer), two files open (a copy's), the stick's USB state; FatFs's tiny buffers (files share their volume's: FF_FS_TINY), which paid for the stick
freeabout 1.8 KB past the rest (measured 2026-11-21: malloc's, as it grows), and a few hundred bytes of a scratch bank

No PSRAM is needed. Every app, home and the console included, gets the whole app space (see memory); the console's own Rio session lives in the console's memory.

Sound goes out over HDMI and the 3.5 mm jack at once, mixed on the second core along with the video. Mixing 8 ADPCM voices takes about 13% of a core; 16-bit, about 6%.

Speed

Measured on the Fruit Jam (2026-11-13) with apps/drawbench.rio and apps/bench.rio, with the JIT on, as apps run, unless noted:

drawingin 10 ms
8x8 sprites from a sheet (pc.blit), solid1,466
8x8 sprites at 2x (16x16 on the screen), solid299
400 actors, each moved and drawn as an 8x8 sprite1,418
8x8 rectangles (pc.rect)2,960

A sprite's see-through pixels (color 0) cost less than solid ones; scaled sprites take a slower path (each pixel drawn as a block), and so do mirrored ones. Drawing is C, so Rio's own speed barely shows in it: the rectangles drew as many with the JIT off.

Falling sand ("dust": each grain falls, or slides down left or right; 30% of the cells filled), a step of the whole grid in Rio, and drawing it as one picture:

grida step, with the JITwithout itdrawn (scale)
64x641.0 ms4.0 ms1.0 ms (3x)
100x1002.4 ms9.7 ms1.7 ms (2x)
128x1283.9 ms15.7 ms0.6 ms (1x)
160x1606.0 ms24.4 ms1.0 ms (1x)
240x24013.4 ms54.7 ms2.2 ms (1x)

At 60 frames a second (16.7 ms each), about 200x200 fits, step and drawing; 240x240 runs at 30. Here Rio's speed is most of it: the JIT makes the step about 4 times faster. Drawn instead a pc.rect a cell, the calls cost more than the step: about 3.4 us each, so about 50x50 cells at 60.

The desktop

cmake -S . -B build-desktop -DRINC_PLATFORM=desktop   # fetches and builds SDL3 the first time
cmake --build build-desktop --config Release

The result is one program, with SDL3 (and, with MSVC, the C runtime) linked in. -DRINC_SDL=OFF builds it without a window. A release is that one program, zipped on Windows and a .tar.gz on macOS (Apple silicon) and Linux (x86-64, and arm64 for a Raspberry Pi 4 or 5 with 64-bit Raspberry Pi OS), so rinc -help and rinc -license carry what would otherwise be files beside it.

rinc app.rio                      play, in a window (closing it quits); it's home until then
rinc game/   (or rinc ., in it)   an app of a folder: game/game.rio, with its other files (include, import)
rinc                              home (or the app the home setting names), in a window; with nothing
                                  installed, a window that says so and takes a bundle dropped on it
rinc -app chord                   an app from storage, by name, home for this session too
rinc -install apps.zip game/      apps into storage: a bundle of them (a release's rinc-system-apps.zip),
                                  an app's folder (all of it, but its dev/ folder), or app.rio
  -data folder                    with any of these: storage in this folder instead
rinc -repl                        Rio typed in the terminal, a line at a time
rinc app.rio -m                   how near the app comes to its limits (see memory)
rinc app.rio -frames 120          no window: run 120 frames (A held for the first 3, unless -type), as
                                  fast as they go, pc.appTime() the frames' (60 a second), as the sound is
  -board                          and as the board would run them (below): a frame its board time spans
  -nojit                          and count no code as compiled by the board's JIT (as on a Rinc without)
  -meter counts.txt               and write what's counted, at each pc.appTime and each frame's end
                                  (tools/boardspeed.py, tools/boardframe.py)
rinc app.rio -turbo               in a window as fast as this computer goes, not the board
rinc app.rio -play                with board speed as a player gets it (below): 20% slack
  -o screen.ppm                   then save the screen
  -wav sound.wav                  and the sound those frames made
  -type 'x := 1\nlog(x)\n'        and type this, as fast as the app takes it (\n Enter, \e Esc, \t Tab,
                                  \xHH a byte as a terminal sends it: \x13 Ctrl+S, \x1b[1;5C Ctrl+right)
  -drop apps.zip                  and first, as if it were dropped on the window
  -stick things.zip               and that zip (or folder) plugged in as the stick (/stick)
  -downloads folder               where the stick goes, downloaded (else the Downloads folder)
  -hold 'a 10-40, right 20-30'    and hold buttons, as a controller would, in those frames (counted from
                                  0): left right up down a b x y lb rb ls rs start back, and the
                                  sticks pushed: lsleft lsright lsup lsdown rsleft rsright rsup rsdown
rinc app.rio -i app.rioi          compile to an image, and list the host procs its code calls
rinc a.rio b.rio -export game     a program to hand out (game.exe on Windows): rinc with the apps in it
  -home a                         the one it starts at (by default the only one, or one named home)
  -name folder                    its storage folder's name (by default its home app's)
  -docs rinc=docs                 help texts for the help app: the folder's .md files, as rinc/... (repeatable)
  -files apps/rinc=system/rinc    other files: all of the folder, as apps/rinc/... (under apps/, help/ or
                                  lib/; repeatable), such as the themes
  -runner path/to/rinc            a copy of that rinc instead, such as another system's from a release
rinc a.rio b.rio -web game.html   a page that plays them (see the web)
rinc -help                        all this; and rinc -license, the licenses of what's in it

Board speed

An app in a window (and in a web page) runs no faster than on the Fruit Jam: what it does is counted (each Rio instruction, apart those the board's JIT would compile, and each drawing and file call with its pixels or bytes), each frame takes as many 60ths of a second as the board would need, and the ones past its first are skipped, as the board would still be busy. pc.appTime() reads that board clock, so an app timing itself sees the board's numbers. So a game made on a computer isn't a surprise on the board. It's within about 10% on Rinc's own tests of each cost and within 15 to 20% on apps (Paint, falling sand); -turbo turns it off. That's as a developer sees it; an exported game and a web page play with slack, a frame skipped only once the board's time passes 120% of a 60th of a second, so a game that just keeps up on the board isn't the one that stutters on a computer (-play shows it so). Sys+M shows each frame's board time either way. What each thing costs is measured on the board by tools/boardspeed.py (plans/board-speed.md), into src/core/boardcost.h; rinc app.rio -frames 300 -board ends with what the board's frame would say, and tools/boardframe.py says where a frame's time went.

In a window, the arrows and V, C, X and Z are the buttons (in a game: in a pointer app, such as home, the letters type, and a controller's A and B are Enter and Esc), any controller SDL knows is player 1 (Xbox, PlayStation, Switch and more), and Esc is the app's. The system key is Ctrl and Shift tapped together (the operating system keeps the Windows key), or a controller's guide button; with Esc (or Back) it goes home. F11, or the system key with Enter, fills the display, and keeps the mouse on it until it's a window again (or another window gets the focus: Alt+Tab, Cmd+Tab).

Dropping a .zip on the window plugs it in as the stick: its files at /stick, where Files shows them (at /, beside Rinc's own folders), and copying an app's folder from there to /apps installs it. The stick can be written to as well (in memory: copy things onto it), and the command list (Sys+P) has "The stick: download it, as a zip", which writes it to the Downloads folder (-downloads folder: there), and "The stick: a new, empty one". A second zip dropped replaces the first (what was written to it goes, unless downloaded). On a Rinc with nothing installed yet (no home), a dropped zip is installed instead, as rinc -install does, and then it goes home: a release's rinc-system-apps.zip is how a Rinc starts. A folder dropped is the stick too, the folder itself (what's written to the stick is written there, as it's made: nothing to download), unless it's an app's (its name.rio in it): that's installed, as before. rinc -stick things.zip (or a folder) plugs one in from the start (plans/drives.md: a thumb drive on the board, and a stick you can write to, later). On Windows, a double-clicked rinc.exe closes the console Windows opens for it, so there's only the window; started in a terminal, it prints there as usual.

Storage

The desktop rinc carries no apps of its own, so the program stays small. Its storage is a folder in your user data folder, laid out as on the Fruit Jam's SD card (apps/name/name.rio, and each app's save/name):

Windows%APPDATA%\rinc
macOS~/Library/Application Support/rinc
Linux and others$XDG_DATA_HOME/rinc, or ~/.local/share/rinc

rinc -install rinc-system-apps.zip gets the same setup as the Fruit Jam: home, the console and the rest of the standard apps, and the help texts, from the zip a release carries (rinc-demo-apps.zip has the demos). A bundle's apps replace those of the same names; projects and saves stay. rinc -install mygame/ copies an app of your own in (all of its folder, but its dev/ folder: its tests, notes), as does rinc -install mygame.rio. Rinc itself never goes on the network. Apps only see their Rinc's folder, never the rest of the computer.

ctest --test-dir build-desktop -C Release runs every app headless, checks that an exported game draws exactly what rinc does, runs home, the console and the editor (typing at them), checks pc.rio, and runs the examples in these docs.

An app's parts can be tested without running the app: see an app's tests. rinc mygame/dev/test.rio -frames 1 runs them from the folder (the app's other files from mygame/), and rinc -app mygame+/dev/test a project's from storage, as every Rinc does. On the Fruit Jam, uv run tools/send.py mygame --test sends the app and its tests, then runs them and prints what they say.

Exported games

-export writes a copy of rinc with a bundle of the apps after it (see bundles): each app compiled to an image. Started without an app, rinc looks for a bundle at its own end, and starts its home app, in a window, or headless with -frames. An exported game keeps its save files in a storage folder of its own name (-name), not Rinc's. With -runner, one machine can make games for all three systems (on Linux and macOS, chmod +x a game made elsewhere).

The web

rinc apps/breakout.rio -web breakout.html

makes one self-contained page: a bundle of the app compiled to an image, Rinc's VM as wasm (gzipped, and unzipped by the browser), and a small JS host (src/web/page.html). Breakout comes to 94 KB, most of it the 54 KB player, in base64. Open it from disk or any server. The arrows and V, C, X and Z are the buttons (in a game: in a pointer app the letters type), and any controller the browser maps to the standard layout is player 1. Sound starts with the first key or click, as browsers require.

A page can carry several apps, as an exported program does (see the desktop):

rinc system/home system/console system/edit system/files system/help system/colors system/themes \
  apps/*.rio apps/chord -home home -name rinc -files apps/rinc=system/rinc -web rinc.html

is the whole Rinc, as on the Fruit Jam: every system app, and the themes (-files carries a folder's files, here the themes, which apps read as they would storage's). A page's apps and files have no fixed limit (a big one is slower to open: it's all in the page). Storage is the browser's IndexedDB, under the bundle's storage name, so what's saved stays in that browser, for pages from the same site (or, from disk, the same folder), as much as the browser allows (localStorage's few MB, before; what a page kept there moves in the first time). Each change is kept as it's made, and other tabs of the site hold it too at once (the newest change wins). Ctrl and Shift tapped together, and then Esc, goes home; on a controller it's the guide button and Back. The page keeps a lone Alt from the browser's menus, as Alt tapped twice is Rinc's Alt lock.

A .zip dropped on such a page is plugged in as the stick, as on the desktop: its files at /stick, for Files to show, copy from and onto (the command list's "The stick: download it, as a zip" saves it as a file; it's in the page's storage meanwhile, kept through a reload) (an app's folder copied to /apps is installed, into the page's storage). A second one dropped replaces the first. Installed apps come before the page's own of the same name. A page with only the VM-only player (below) can't run apps from storage, so it says so and installs nothing.

rinc -name rinc-empty -web empty.html

is a Rinc with nothing installed: it says so, and installs a dropped bundle (no stick: there's no Files yet), as the desktop rinc does with none. Its Reset button, in the corner, takes it back to empty (it asks first). The storage name, which an empty page must have, keeps it apart from other pages from the same site: each keeps its storage under its own.

The two players

The desktop rinc carries two web players and gives a page the smaller one it can:

  • VM-only (54 KB gzipped): runs compiled apps, the common case.
  • With the compiler (114 KB gzipped): for a page with an app that runs Rio itself (pc.rio*, as the console does) or writes apps (importing Rinc's library appfiles, as the editor and Files do). It also runs apps saved to storage, from source, and such a page carries its apps as source, so the editor can open them.

They're built in when the desktop rinc is configured with -DRINC_WEB_WASM=rinc.wasm and -DRINC_WEB_WASM_FULL=rinc-full.wasm, which the CI does for the releases. Making them takes zig (zig cc, no emscripten): python tools/web.py --wasm=rinc.wasm --wasm-full=rinc-full.wasm.

The demo site is made this way from apps/ on each push to main, with a page for each app, one of the whole Rinc, and these docs at rincpc.com/docs. tools/demosite.py makes the pages (with Rinc's logo as their icon, as every page rinc -web makes has), and the demo_site test makes the same ones and plays each.

Working on Rinc

Tests

ctest in a desktop build runs every app headless, runs home, the console and the editor (typing at them with -type), checks rinc -m, compares an exported game's screen with rinc's, checks pc.rio against the host procs Rinc registers, and runs every rio example in these docs with a headless rinc (rinc main.rio -frames 2), using the runner from Rio (lib/rio/tests/docs.py). The examples follow Rio's conventions: an output block after one is its exact log output.

Rio at the same time

RIO_DIR picks the Rio to build against. It defaults to the lib/rio submodule; point it at a working copy to change both without committing in between (tools/web.py takes --rio=path):

cmake -S . -B build-desktop -DRINC_PLATFORM=desktop -DRIO_DIR=../rio

When a Rio change is pushed, move the submodule to it: git -C lib/rio pull, and commit lib/rio here.

CI and releases

.github/workflows/ci.yml builds and tests on every push: the web players' wasm (with zig), the desktop rinc for Windows, macOS (Apple silicon) and Linux with those built in (each runs the tests), and rinc.uf2 for the Fruit Jam (Arm's toolchain and the Pico SDK). Each is kept as a download on the run. A tag like v0.1.0 also publishes them as a GitHub release. Each night that main has changed, and whenever the ci workflow is run by hand (Actions > ci > Run workflow), they're published as the rolling nightly prerelease.

.github/workflows/pages.yml makes the demo site on each push to main: a page for each app, an index, and these docs under /docs.