Log In  


PICO-8 supports bitplane drawing; the wiki (search "bitplane") has a description of how they work:

> 0x5f5e / 24414
> Allows PICO-8 to mask out certain bits of the input source color of drawing operations, and to write to specific bitplanes in the screen (there's 4 of them since PICO-8 uses a 4BPP display). Bits 0..3 indicate which bitplanes should be set to the new color value, while bits 4..7 indicate which input color bits to keep.
> For example, poke(0x5f5e, 0b00110111) will cause drawing operations to write to bitplanes 0, 1, and 2 only, with 0 and 1 receiving the color value bits, 2 being cleared, and 3 being unaltered.
> This formula is applied for every pixel written:
> dst_color = (dst_color & ~write_mask) | (src_color & write_mask & read_mask)

This is precise and correct, but I find it a bit hard to understand. So I made this cart to give myself an interactive sandbox where I can play around with bitplanes, to see how they affect drawing.

Cart #bitplane_explorer-1 | 2023-09-21 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
4

The code is straightforward:

  1. draw the full 16-color palette
  2. enable bitplanes, using the poke shown onscreen
  3. draw a circle, using the circfill shown onscreen

You can change the bitplane settings and the circle's "color" -- the controls are shown onscreen. This interactively shows how drawing any color will interact with any other color under the current bitplane settings.

You'll still need to study the description from the wiki (or read my overview post) to understand how to use bitplanes, but this cart is a helpful supplement for me when working with bitplanes. I hope you find it helpful too!

4


1

Here's a more in-depth version of the car. For any bitplane setting, it shows how all 16 src_color options interact with all 16 dst_color options.

The code:

  1. draw a huge palette in the background
  2. enable bitplanes, using the poke shown onscreen
  3. draw 16 small palettes, one in each square of the large palette

Cart #bitplane_grid-0 | 2023-09-21 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
1

Controls:

  • arrow keys to move/change bits.
  • type numbers (0-1 while binary is selected, 0-f while hex is selected)
  • z to toggle
  • ctrl-c to copy a poke snippet


[Please log in to post a comment]