[Coco] (Simple?) Binary File Compression

Roger Taylor operator at coco3.com
Tue Feb 12 21:30:05 EST 2008


At 12:16 PM 2/12/2008, you wrote:
>Hi Folks,
>
>I'm working on a freeware game for the CoCo 3.  I'm doing it mostly in
>Urbane BASIC.  The game will have some graphics that will be loaded from
>floppy at various times during play.  The pictures used during most of the
>game will be 320x150x16, (to make room for the UI) but there will also be
>higher quality, full-screen versions of the same images using the
>palette-switching 64-color mode from Sockmaster's Hi-color program that can
>be viewed at the player's option, as an intermission from gameplay.
>
>I want to mildly compress the images on disk, both to squeeze more pictures
>on a floppy (image) and also to deter casual peeking that would spoil the
>game.  Any ideas for something that is fairly easily implemented from a
>BASIC program (a short ML routine is fine, especially if it is small enough
>that it can be squeezed into some seldom-used cranny of memory, like BASIC's
>cassette buffer, or something.)
>
>The goal is to make the game run in 128K, but take advantage of more memory
>if it is present by caching pictures or parts of pictures (as 8K blocks) in
>RAM.  The game will have a separate set=up program which will allow the user
>to patch DECB for 40 tracks and 2 sides if the hardware supports it and the
>DOS isn't already patched.  It should also write out some config files to
>tell the main program where to look for graphics.  I think I can just fit
>everything on two sides of a 40-track floppy, but a little compression would
>make it more comfortable.
>
>Any ideas?


Here's what I suggest:

For solid or cartoonish quality images on the CoCo 3, I prefer the 
nibble format where you just specify {repeat 0-15}{color 0-15}.  A 
repeat of 0 would mean 16, so you can represent 16 repeats of 16 
colors, per nibble packet.  In other words, each byte in the 
compressed stream tells the decompressor to {repeat}{color}.
Try that and if it doesn't yield good compression, scan the image for 
the least used color, use that color as the compression code flag, 
then in the compressed stream, output any screen BYTE that doesn't 
repeat more than 3 times (that's 6 colors, actually), directly, then 
for any repeated colors output {compression code} {bytes to repeat} 
{color bytes}.  Note that this would be byte compression which would 
work well with half-tone dithered images as well as solid, but not 
error-diffusion dithering.





More information about the Coco mailing list