New Byte Compressor 2022

0
0
Published 2023-06-12


(v04 12-18-22)
TO LOAD THIS PICO-8 CART, in immediate mode, type: load #newcompress

Hello.

I have need of a data compressor for the 2023 project I'm working on now so I wrote one. And it's better than a 6-bit or 7-bit because once again, this is an 8-bit compressor.

Now this is different from the picture compressor I wrote which you can find HERE:

https://www.lexaloffle.com/bbs/?tid=45335

That compressor is looking for Pico-8 pixels specifically.

No, THIS compressor is looking for raw data. While I am demonstrating it with pictures it is in fact geared for byte data, maps, PCM sound, and what have you.

Usage:

There are 2-functions all squeezed down to a single programming line each.

The first is the compressor. It can be used 2-ways.

string=compres8(m,e,s,f)
compres8(m,e,s,f)
(251 tokens in size)

It uses 4-arguments and the string in the beginning is optional. By default it will save your compressed data to the clipboard for immediate use. If you want to save it to a string then put that variable in front.

The first is "M" the memory location to start where you want to begin your compression. You can also use 0x8000 high memory if you so choose.

The second is "E" the length to read. For instance the screen at 0x0000 is 0x2000 or 8192-bytes in length. You can also use a length greater than 0x2000 if you so choose.

The next is "S" for shift. Now by default this is zero. With some fiddling of it you can shave off a few bytes from your string compression. Basically it SHIFTS the value so for instance if you had a bunch of "\0" in your code, by shifting it 128 you would then get █ instead which registers as a single character whereas "\0" registers as 2-characters from your 64k available.

However you should never find \0\0\0 beside itself ever in the final compressed data. Everything gets compressed when a pattern is found.

If you don't want to mess with it, don't enter a value or if you need the next argument, leave it at zero.

The last argument is "F" for flag. If it is anything except NIL then it will not convert to a clipboard friendly string, instead it will save the image to a true 8-bit string that can only be output but not pasted in your code. You will need the starting variable for this.

It is for debugging and you shouldn't need it unless you come across some data that is not compressing properly and you need to show this to me so I can isolate the problem.

However if you are not debugging and just using the compressor normally, after you have called the compressor it is ready for use !

In a line of your code, press CTRL+P, CTRL+V, then CTRL+P again followed by the ENTER key to confirm. That will save your data to the string in your code, and of course, you can rename the variable data to whatever you want.

It will look something like this:

Then you are ready to decompress it as described in the next function to follow.

decompres8(string,o,s)
(126 tokens in size)

The 1st argument is for the string that you created with compres8(). It will be a series of odd characters within 2-quote marks. See code sample above.

The "O" (oh) variable is for the memory you wish to start writing it to. You are not limited to 0x0000 or 0x6000, you can also write to 0x8000 if you so choose.

The "S" is exactly as above. It SHIFTS the value. So if you recorded using compres8() with a shift of 64, then you need to use decompres8() also with the value shift of 64.

And that's it ! Please see the sourcecode for the sample cartridge above for further information, especially on usage of the 2-functions.

Now I wrote these functions for myself as I need them for the main project I'm working on. However if you find them of use yourself or have any questions to this point, please let me know.

Thanks !