gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > LZSS compression for GBA

#24852 - DKL - Thu Aug 12, 2004 2:24 pm

Little update : see below for v1.2.03

http://www.geocities.com/dkl_74/

I'm currently working on a big project and since it will be really "RAM intensive", I coded my own LZSS compressor in pure ASM, trying to keep memory usage to a minimum. Maybe somebody will be interested, so... For decompression, simply call the appropriate bios function (0x11 or 0x12).

There are 2 different implementations. The oldest one is based on hash tables and only need 10240 bytes (or a little less, or a little more) of temporary space. But it can be really slow in worst case scenarios if you are compressing big files (say 64Kbytes). I included it because it can still be used for little files.

The newest one is based on binary trees and is way faster, but needs 25088 bytes of temporary space.

You can compress directly in SRAM too.

I'm using GAS but it wouln't take too long to convert it to another assembler.

This source code is released in public domain.

If you find some errors, don't hesitate to contact me. Thanks.

The link : dead

Regards,
DKL


Last edited by DKL on Fri Aug 13, 2004 11:58 am; edited 3 times in total

#24855 - dagamer34 - Thu Aug 12, 2004 5:02 pm

Do you think you could create a small example of how to use these functions, that way you don't get blitzed with lots of questions?
_________________
Little kids and Playstation 2's don't mix. :(

#24860 - DKL - Thu Aug 12, 2004 6:09 pm

dagamer34 wrote:
Do you think you could create a small example of how to use these functions, that way you don't get blitzed with lots of questions?


Instructions are in the readme file. This is easy, really. If you intend to call it from C, just declare a function like this :

extern __attribute__((long_call)) *char LZ77CompWRAM(char*, char*, int, short*, char*);

or

extern *char LZ77CompWRAM(char*, char*, int, short*, char*);

if you're calling from IWRAM.

Let's say the data to compress are (just an example) :

/* 32 bytes of data */
char *data_2_compress="01234567890123456789012345678901";

Let's say you have 25088 bytes of free ram in EWRAM starting at address 0x02010000 and that you want to compress to SRAM (0x0E000000) directly, just call the declared function like this :

char *ret;
ret = LZ77CompWRAM(data_2_compress, (char*) 0x0E000000, 32, (short*) 0x02010000, (char*) 0x0E010000);

The last argument is considered by the compressor as the output limit, he won't write anything starting at this address.

The return value will be
1) the address of the first free byte after the compressed file, or
2) 0 (error) if the limit was reached or if the compressed file is larger than the uncompressed one (compression was so stopped).

To uncompress the data, just call the bios function 0x11. There's an example in 'readme.txt'.

Tell me if you need a more complex example (I mean if you really really need it, I'm lazy you know ;) )

#24861 - dagamer34 - Thu Aug 12, 2004 6:23 pm

For me, I think that'll do quite nicely. :)
_________________
Little kids and Playstation 2's don't mix. :(

#24901 - DKL - Fri Aug 13, 2004 11:56 am

I made a lame webpage to stop posting for any little update I do.

You can find the last version of the LZSS compressor for GBA, here :

http://www.geocities.com/dkl_74/

#25019 - DKL - Sun Aug 15, 2004 1:02 pm

The bios LZSS functions won't allow you to uncompress directly from SRAM. I just uploaded 2 small functions (sisters of bios fct 0x11 & 0x12) to solve the problem. I didn't devote a lot of time on them, so if you see errors, please contact me. Thanks.

www.geocities.com/dkl_74/

Regards,
DKL

#25028 - DKL - Sun Aug 15, 2004 7:28 pm

Just to warn interested people : there was an error in the uncompressing functions v1.0. Please update & destroy the old version. Thanks. :)