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.