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 > Tip: Compressing Code

#25005 - Lord Graga - Sun Aug 15, 2004 12:10 am

I decided to post this tip due to the size limits of the current compo. It might be wellknown to everybody, but I really don't see why I should give people a bit of insight in how it's done if they don't know. This will be purely theoretical.

Okay, imagine that you have compiled a final ROM of your game at around ~300 kbyte. Now you want it all to be compressed, but it needs to be 256 kbyte (at max) to run in EWRAM. So you start crunching a few images, and it's down on 256 kbyte or less in the end. This is something everybody should do to every data in their program.

Anyway, crush the whole program up, and write a small assembler program. All it shall do is point the decompresion source pointer at the end of the binary (usually 0x8000100 if you pad the program), the decompression pointer at 0x200000, and do your SWI call. Then append your compressed binary to your assembled program, and do a test run. If it doesn't work, then you have done something wrong :)


LG.

#25008 - tepples - Sun Aug 15, 2004 12:23 am

Lord Graga wrote:
Okay, imagine that you have compiled a final ROM of your game at around ~300 kbyte. Now you want it all to be compressed, but it needs to be 256 kbyte (at max) to run in EWRAM. So you start crunching a few images, and it's down on 256 kbyte or less in the end. This is something everybody should do to every data in their program.

Do GBA programs really have more than 256 KBytes of code, rather than say 64 KB of code and lots more of assets?

Quote:
crush the whole program up, and write a small assembler program. All it shall do is point the decompresion source pointer at the end of the binary (usually 0x8000100 if you pad the program), the decompression pointer at 0x200000, and do your SWI call. Then append your compressed binary to your assembled program

Reminds me of UPX.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#25020 - torne - Sun Aug 15, 2004 1:32 pm

I have programs with more than 256k of code. Not games, though.

#25025 - sajiimori - Sun Aug 15, 2004 6:24 pm

Code size can definitely become a problem when you have to execute from RAM. It's not uncommon to load only the routines that are needed, excluding things like AI for characters that aren't present.

Use a bytecode-compiled scripting language to reduce your code size by perhaps a factor of 6.