RICO-16
v0.1 · this page is for v0.1, things will change
- Welcome
- Getting started
- Specification
- Shell commands
- API functions
- Button IDs
- Hotkeys
- Editors
- How colour works
- Sound
- Tokens
- Cart files
- Startup options
- License
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
| DISPLAY | 256x224 pixels. Also 320x180 (wide) and 512x448 (hires), see cart files. |
| COLOURS | 16 palettes of 16 colours, any 24-bit RGB. Every sprite picks its own palette. |
| SPRITES | 512 sprites of 16x16 pixels, flip, rotate and scale. The sheet is 256x512 pixels. |
| MAP | 4 layers, each up to 128x128 tiles (2048x2048 pixels). Layers wrap around. Mode 7 on any layer. |
| SOUND | 8 channel synth, 8 waveforms, 8 effects. 64 sfx of 32 notes, 64 music patterns. No samples. |
| INPUT | 4 SNES-style pads: d-pad, A B X Y, L R, start. Keyboard is player 1, gamepads work too. |
| CODE | Lua 5.4, 16,384 tokens. |
| CART | 64 KB compressed, saved as text (.r16) or as a png (.r16.png). |
| SPEED | 60 fps. |
| EXPORT | Linux, Windows and web. |
Shell commands
Type these in the shell. up / down go through the history.
| Command | What it does | Usage |
|---|---|---|
help | List the commands. | help |
new | Start a new cart (the hello cart). | new |
load | Load a cart. You can leave out the extension, it tries .r16, .r16.png and .lua. | load <cart> |
run | Run the loaded cart from the start (Hotkey: ctrl+r in the editors). | run |
resume | Go back to the running cart where you left it. | resume |
save | Save 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] |
export | Make 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] |
ls | List carts and folders here. | ls |
cd | Change folder. No folder prints where you are. | cd [folder]cd .. |
cls | Clear 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) -> v | Read 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]) -> x | Draw 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) -> col | Read a pixel from the sprite sheet. |
sprpal(n, [p]) -> p | Get 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) -> n | Get 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, h | Get 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]) -> bool | Is button b held down? See button IDs. Players are 0-3. |
btnp(b, [player=0]) -> bool | Was 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
| ID | Button | Keyboard (player 1) | Gamepad |
|---|---|---|---|
| 0 | left | left | d-pad / left stick |
| 1 | right | right | d-pad / left stick |
| 2 | up | up | d-pad / left stick |
| 3 | down | down | d-pad / left stick |
| 4 | A | x | right face button (B on Xbox) |
| 5 | B | z | bottom face button (A on Xbox) |
| 6 | X | s | top face button (Y on Xbox) |
| 7 | Y | a | left face button (X on Xbox) |
| 8 | L | q | left shoulder |
| 9 | R | w | right shoulder |
| 10 | start | enter | start |
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
| Key | What it does |
|---|---|
| esc | Shell ↔ editors. While a cart runs: stop it and go back. |
| F1 F2 F3 | Code, sprite, map editor (works from the shell and while running too). |
| ctrl+1 ctrl+2 ctrl+3 | Same, inside the editors. |
| ctrl+r | Run the cart. |
| ctrl+s | Save the cart. |
| tab while running | Try 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+v | Copy, cut, paste |
| ctrl+a | Select all |
| shift + arrows, mouse drag | Select |
| home / end | Start / end of the line (with ctrl: of the file) |
| page up / page down | Scroll a screen |
The status bar shows the line and how many tokens you've used.
Sprite
| left click | Paint with the pen, fill or eraser |
| right click | Pick the colour under the mouse |
| arrows | Previous / next sprite (up and down jump a row) |
pal - + | Change the palette this sprite uses |
| 1-8 | Sheet pages, 64 sprites each |
Map
| left click | Put the selected sprite |
| right click | Pick the sprite under the mouse |
| arrows, middle drag | Scroll |
| layer 0-3 | Pick 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 |
|---|---|---|---|---|---|---|---|
| 0 | 1a1625 | 4 | c9c3d6 | 8 | 4f7a7a | 12 | e39a9a |
| 1 | 2e2a3f | 5 | f2ece4 | 9 | 8db3a8 | 13 | 8a5a44 |
| 2 | 4a4560 | 6 | 5c6f8f | 10 | 6b3d5c | 14 | c98f5e |
| 3 | 7a7391 | 7 | 2f4a52 | 11 | b0607a | 15 | e3c78f |
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 |
|---|---|---|---|
| 0 | sine | 0 | none |
| 1 | triangle | 1 | slide from the last note |
| 2 | saw | 2 | vibrato |
| 3 | square | 3 | drop |
| 4 | pulse | 4 | fade in |
| 5 | thin pulse | 5 | fade out |
| 6 | organ | 6 | arpeggio fast |
| 7 | noise | 7 | arpeggio 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
.r16 | Text file: the code plus hex for sprites, maps, palettes, sfx and music. Easy to diff and keep in git. |
.r16.png | The 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. |
.lua | Just 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.