RICO-16

v0.1 · this page is for v0.1, things will change

Welcome

RICO-16 is a fantasy console, the spiritual successor to PICO-8. Think of it like the SNES was for the NES: same idea, one generation later.

You write your games (carts) in Lua 5.4 and make the sprites and maps in the built-in editors. A cart is one file you can share, or a png with a label on it. When it's done you can export it as a game for Linux, Windows or the web.

The limits are part of the fun: 256x224 screen, 16 palettes of 16 colours, 512 sprites of 16x16, 4 map layers, Mode 7, an 8 channel synth and 16,384 tokens of code.

Getting started

Download it from itch.io (Linux and Windows), unzip and run rico16 (or rico16.exe). On Linux, bash install_linux.sh adds it to your app menu.

It boots into the shell with a small hello cart already loaded. Try this:

run          -- run the hello cart, arrows move the sprite
esc          -- back to the shell
esc          -- open the editors, the code is there
ctrl+r       -- run it again from the editor
save mygame  -- saves mygame.r16

This is the hello cart:

function _init()
  x = 120
  y = 100
end

function _update()
  if btn(0) then x = x - 1 end
  if btn(1) then x = x + 1 end
end

function _draw()
  cls(4)
  print("hello rico", 106, 80, 1)
  spr(0, x, y)
end

A cart can have three functions, all optional:

_init()Called once when the cart starts.
_update()Called 60 times a second. Read buttons and move things here.
_draw()Called after _update, draw everything here.

You don't have to use the built-in code editor. Load a .lua or .r16 file, edit it in your own editor and save: RICO-16 notices and reloads it (and restarts it if it was running).

Specification

DISPLAY256x224 pixels. Also 320x180 (wide) and 512x448 (hires), see cart files.
COLOURS16 palettes of 16 colours, any 24-bit RGB. Every sprite picks its own palette.
SPRITES512 sprites of 16x16 pixels, flip, rotate and scale. The sheet is 256x512 pixels.
MAP4 layers, each up to 128x128 tiles (2048x2048 pixels). Layers wrap around. Mode 7 on any layer.
SOUND8 channel synth, 8 waveforms, 8 effects. 64 sfx of 32 notes, 64 music patterns. No samples.
INPUT4 SNES-style pads: d-pad, A B X Y, L R, start. Keyboard is player 1, gamepads work too.
CODELua 5.4, 16,384 tokens.
CART64 KB compressed, saved as text (.r16) or as a png (.r16.png).
SPEED60 fps.
EXPORTLinux, Windows and web.

Shell commands

Type these in the shell. up / down go through the history.

CommandWhat it doesUsage
helpList the commands.help
newStart a new cart (the hello cart).new
loadLoad a cart. You can leave out the extension, it tries .r16, .r16.png and .lua.load <cart>
runRun the loaded cart from the start (Hotkey: ctrl+r in the editors).run
resumeGo back to the running cart where you left it.resume
saveSave the cart. No name saves over the current file. End the name in .png to save a png cart with a label (Hotkey: ctrl+s in the editors).save [name]
save [name.r16.png]
exportMake a standalone game in <name>_export/ for the computer you're on, plus a web version if the web player is next to rico16.export [name]
lsList carts and folders here.ls
cdChange folder. No folder prints where you are.cd [folder]
cd ..
clsClear the shell.cls

API functions

Arguments in [brackets] are optional, the value after = is what you get if you leave it out. Colours are 0-15. Coordinates are in pixels and floats get rounded down.

Graphics

cls([col=0])Clear the screen with a colour.
pset(x, y, [col=7])Draw one pixel.
pget(x, y) -> vRead a pixel from the screen. Returns palette * 16 + colour. Ignores the camera.
line(x0, y0, x1, y1, [col=7])Draw a line.
rect(x0, y0, x1, y1, [col=7])Draw a rectangle outline. Both corners are included.
rectfill(x0, y0, x1, y1, [col=7])Draw a filled rectangle.
circ(x, y, r, [col=7])Draw a circle outline.
circfill(x, y, r, [col=7])Draw a filled circle.
print(text, [x=0], [y=0], [col=7]) -> xDraw text. \n starts a new line (7 px down). Returns the x where the text ended, handy to keep printing after it. Numbers work too.
camera([x=0], [y=0])Move the camera: everything after it is drawn shifted by -x, -y. Works for shapes, text, sprites and map, not for mode7.

Sprites

spr(n, x, y, [flip_x=false], [flip_y=false])Draw sprite n (0-511) with its top left corner at x, y.
sprx(n, cx, cy, [angle=0], [sx=1], [sy=sx])Draw sprite n centred on cx, cy, rotated and scaled. angle is in turns: 0.25 is a quarter turn, 1 is a full turn. A negative scale flips it.
sset(x, y, [col=7])Set a pixel on the sprite sheet (256x512). Sprite n is at (n % 16) * 16, (n // 16) * 16.
sget(x, y) -> colRead a pixel from the sprite sheet.
sprpal(n, [p]) -> pGet the palette sprite n uses, or set it to p (0-15). See colour.

Palettes

pal(c0, c1)Draw colour c0 as c1 from now on (for shapes, text, sprites and maps).
pal()Reset all pal swaps and transparency.
palt(col, transparent)Make a colour transparent (or not) when drawing sprites and maps. Colour 0 is transparent by default.
palt()Reset transparency: only colour 0.
palset(p, col, rgb)Change colour col of palette p to an RGB value, like palset(1, 5, 0xff8800). It changes the colour everywhere on screen right away.

Map

map(layer, [x=0], [y=0])Draw a whole map layer (0-3) with its top left at x, y. The layer repeats, so it always fills the screen. Tile 0 is empty.
mget(layer, cx, cy) -> nGet the sprite number at a tile. Outside the layer it's 0.
mset(layer, cx, cy, n)Put sprite n at a tile.
mapsize(layer, [w], [h]) -> w, hGet the size of a layer in tiles, or set it (1-128). Default 128x128.
mode7(layer, x, y, [angle=0], [height=32], [horizon=64])Draw a layer as a Mode 7 floor below screen row horizon. x, y is the camera on the map in pixels, angle in turns, height is how high the camera is.
mode7line(layer, y, wx, wy, dx, dy)Draw one screen row y of a layer: starts at map pixel wx, wy and moves dx, dy per screen pixel. For your own effects (waves, wobble, custom perspective).

Input

btn(b, [player=0]) -> boolIs button b held down? See button IDs. Players are 0-3.
btnp(b, [player=0]) -> boolWas it just pressed? If you keep holding it, it's true again after 15 frames and then every 4 frames.

Sound

sfx(n, [channel=-1])Play sfx n (0-63). Without a channel it picks a free one of 4-7.
sfx(-1, [channel=-1])Stop a channel, or all the sfx channels (4-7).
music([p=-1])Play music from pattern p (0-63). music() or music(-1) stops it.
sfxset(n, i, pitch, [wave=0], [vol=5], [fx=0])Set note i (0-31) of sfx n. pitch 0-95 (48 is C4, 57 is A4 = 440 Hz), vol 0-7, wave and fx below.
sfxspeed(n, speed, [loop_start=0], [loop_end=0])Set how long each note of sfx n lasts (1-255, 16 is the default, about 0.13 s). If loop_end > loop_start those notes loop.
pattern(p, flags, s0, [s1=-1], [s2=-1], [s3=-1])Set music pattern p: the sfx for channels 0-3 (-1 is silent). flags: 1 = loop start, 2 = loop back from here, 4 = stop after this one. Add them up.

Lua

You get Lua 5.4 with table, string, math, coroutine and utf8. No io, os or require. print is the RICO-16 one (it draws). Use math.random for random numbers and // for integer division.

Button IDs

IDButtonKeyboard (player 1)Gamepad
0leftleftd-pad / left stick
1rightrightd-pad / left stick
2upupd-pad / left stick
3downdownd-pad / left stick
4Axright face button (B on Xbox)
5Bzbottom face button (A on Xbox)
6Xstop face button (Y on Xbox)
7Yaleft face button (X on Xbox)
8Lqleft shoulder
9Rwright shoulder
10startenterstart

The face buttons go by position like on a SNES pad, so A is on the right. Up to 4 gamepads, the first one is also player 1.

Hotkeys

KeyWhat it does
escShell ↔ editors. While a cart runs: stop it and go back.
F1 F2 F3Code, sprite, map editor (works from the shell and while running too).
ctrl+1 ctrl+2 ctrl+3Same, inside the editors.
ctrl+rRun the cart.
ctrl+sSave the cart.
tab while runningTry the cart in the next screen mode. Not saved.

Editors

The sfx and music editors are hidden in v0.1, they come back in the next version. Sound from code works.

Code

ctrl+z / ctrl+y (or ctrl+shift+z)Undo / redo
ctrl+c ctrl+x ctrl+vCopy, cut, paste
ctrl+aSelect all
shift + arrows, mouse dragSelect
home / endStart / end of the line (with ctrl: of the file)
page up / page downScroll a screen

The status bar shows the line and how many tokens you've used.

Sprite

left clickPaint with the pen, fill or eraser
right clickPick the colour under the mouse
arrowsPrevious / next sprite (up and down jump a row)
pal - +Change the palette this sprite uses
1-8Sheet pages, 64 sprites each

Map

left clickPut the selected sprite
right clickPick the sprite under the mouse
arrows, middle dragScroll
layer 0-3Pick the layer you're editing (the ones below are drawn too)

How colour works

There are 16 palettes of 16 colours. They all start as the RICO palette, change them with palset. Each sprite has a palette number (sprpal, or the pal buttons in the sprite editor), so the same 16 colour indices can look different on different sprites, like on the SNES.

Shapes, text and cls always use palette 0. Colour 0 is transparent for sprites and maps unless you change it with palt.

#RGB#RGB#RGB#RGB
01a16254c9c3d684f7a7a12e39a9a
12e2a3f5f2ece498db3a8138a5a44
24a456065c6f8f106b3d5c14c98f5e
37a739172f4a5211b0607a15e3c78f

Sound

It's a synth, every sound is made from waveforms. Channels 0-3 play music, channels 4-7 play sfx. An sfx is 32 notes, each with its own pitch, wave, volume and effect. It stops after the last note that isn't silent, unless it loops.

#Wave#Effect
0sine0none
1triangle1slide from the last note
2saw2vibrato
3square3drop
4pulse4fade in
5thin pulse5fade out
6organ6arpeggio fast
7noise7arpeggio slow

A small example, a jump sound on A:

function _init()
  sfxset(0, 0, 48, 3, 5, 1)  -- C4, square, slide
  sfxset(0, 1, 55, 3, 5, 1)  -- G4
  sfxset(0, 2, 60, 3, 3, 5)  -- C5, fade out
  sfxspeed(0, 3)
end

function _update()
  if btnp(4) then sfx(0) end
end

Tokens

Code is limited to 16,384 tokens, not characters, so comments, spaces and long names are free. Each name, number, string and operator is one token. end, local, commas, dots, semicolons, colons and closing brackets cost nothing. The code editor shows the count in the status bar.

Cart files

.r16Text file: the code plus hex for sprites, maps, palettes, sfx and music. Easy to diff and keep in git.
.r16.pngThe same cart hidden inside a 256x256 png, so it shows a label. Up to 64 KB compressed. If mygame.label.png is next to it, that image is used as the label.
.luaJust code. Loads fine, saving turns it into a .r16.

The screen mode is a line at the top of the .r16 file: mode 0 (256x224), mode 1 (320x180) or mode 2 (512x448).

If a cart crashes you get the error on screen. Fix it and save, it reloads by itself.

Startup options

rico16              -- boot into the shell
rico16 mygame.r16   -- load a cart and run it

An exported game is a copy of rico16 with the cart inside, it just plays the cart.

License

RICO-16 is MIT licensed, the source is on GitHub. The font is Everyday Slight by VEXED.