Attachment:
pbj-image.png [ 8.49 KiB | Viewed 3186 times ]
In August I spent a lot of time crunching numbers to try to find a way to better compress chr data. Ultimately that effort failed because the LZMPi like bit-streams I was coming up with would bloat the decoder too much for my tastes, but I did find out that the core PB8 routine of PB53 was surprisingly effective. So late November I decided to upgrade my nametable compression format by having a PB8 mode. After I posted that quick hack I then proceeded to rearrange the codespace to make a much more efficient decoder.
Code:
## PBJ Stream format:
Initially starts in PB8 mode.
In PB8 mode:
00000000 : 0x00 8 times.
01111111 : 0xff 8 times.
0nnnnnnn ... : For each bit in the pb8 control byte,
0 is a new byte, 1 is the previous byte.
In BG mode:
0nnnnnnn : 128-N Run of BG
In both modes:
10011111 xx : Switch to BG mode and set BG to X.
100nnnnn xx : 32-N incrementing run starting at X.
10111111 : Switch to PB8 mode.
10111110 xx yy : Set PPU_ADDR to yyxx
101nnnnn xx yy : For 32-N times, emit alternately X and Y.
110nnnnn ... : 32-N literal bytes.
11111111 : End stream.
111nnnnn xx : 32-N run of X.
Initially starts in PB8 mode.
In PB8 mode:
00000000 : 0x00 8 times.
01111111 : 0xff 8 times.
0nnnnnnn ... : For each bit in the pb8 control byte,
0 is a new byte, 1 is the previous byte.
In BG mode:
0nnnnnnn : 128-N Run of BG
In both modes:
10011111 xx : Switch to BG mode and set BG to X.
100nnnnn xx : 32-N incrementing run starting at X.
10111111 : Switch to PB8 mode.
10111110 xx yy : Set PPU_ADDR to yyxx
101nnnnn xx yy : For 32-N times, emit alternately X and Y.
110nnnnn ... : 32-N literal bytes.
11111111 : End stream.
111nnnnn xx : 32-N run of X.
PB8 is the peanut butter, RLEINC2 the jelly, and my old nametable compression the bread that combines it all together into .pbj files.
The decoder assembles to 159 bytes of ROM and uses 5 bytes of RAM.
The current encoder is a bit dumb as it's only able to use either pb8 planes or everything else but not both.
Example file sizes:
The pbj picture in this post: 4513 bytes
The gus portrait from 240p test suite: 2297 bytes
The title screen from Zooming sectary: 1423 bytes
EDIT: oops, I uploaded the wrong decoder.