P8URLFormat

From Pico-8 Wiki
Jump to navigation Jump to search

The PICO-8 education version can save cartridges consisting of code and sprites (but not map nor sound) to a URL.

The format of the URL is https://www.pico-8-edu.com/?c=<code>&g=<sprites>

The format uses a variation of base64, where character '_' stands for 62 and '-' for 63. (Note: this is the other way around from the usual url-safe base64 encoding!)

Code

First, the code is optionally compressed (if doing so saves space) via the format described in this page.

Next, the code is encoded in the aforementioned base64 variation, with padding.

Sprites

The sprite sheet is taken as a 128x128 sequence of colors (from left to right, then top to bottom).

Next, all trailing zeroes (the color 0) are removed from it, except that if the sprite sheet is entirely filled with zeroes - a single zero remains.

Next, the colors are compressed into a sequence of 6-bit values:

  • 0..15 : colors 0 through 15
  • 16..31 : colors 0 through 15 repeated twice
  • 32..47 : colors 0 through 15 repeated three times.
  • 48..63 : colors 0 through 15 repeated (N+4) times, where N is the next 6-bit value.

Finally, the 6-bit values are each encoded via the aforementioned base64 variation, without any padding.