PDA

Voir la version complète : [GBA][Tutorial] Compressed maps with HEL and GBACrusher


Chano
03/04/2008, 18h50
Compressed maps with HEL and GBACrusher
Author: Chano

Hi! :p

With this tutorial you'll learn how to show compressed maps with dynamic tile reloading in GBA using HEL and GBACrusher. In this tutorial only raw data is compressed, but you can compress map and palette data in a similar way.

1) Download and install GBACrusher:
Download GBACrusher from THIS PAGE (http://members.iinet.net.au/~freeaxs/gbacomp/#GBA%20Crusher) and uncompress GBACrusherCL.exe on %HAMDIR%/tools/win32 (%HAMDIR% is your HAM folder).

2) Create a new project:
Create a new HAM/HEL enabled project with a valid makefile. I recommend VisualHAM for this.

3) Change makefile to support map compression:
For example, if the bitmap you want to show as a background is called potato.bmp, add this lines to your gfx target in makefile to compress the bitmap:
.PHONY gfx: makefile
gfx2gba -t8 -m -F -fraw -ogfx -ppotato.pal potato.bmp
GBACrusherCL -LV gfx/potato.raw -O gfx/potato.raw
katie --output-h --output-asm-arm gfx/*.* With this code GBACrusherCL compress potato raw data with LZ77 (VRAM Safe) algorithm. GBA BIOS is able to decompress LZ77 compressed info in realtime, so to decompress this data we'll only need one GBA BIOS call! :)

4) Decompress raw data on GBA:
To decompress raw data on GBA we'll need a HUGE buffer to store uncompressed tiles. This buffer is g_BufferTiles. The size of this buffer is determined by MAX_TILES constant, so with MAX_TILES = 2200 the size of g_BufferTiles is almost 138KB :blink:! We need to store this buffer in external RAM using ATTR_EWRAM. Anyway, the vast mayority of GBA titles doesn't use backgrounds with so many different tiles, so you can reduce this value to gain some external RAM. Raw data is decompressed in g_BufferTiles calling hel_SwiLZ77UnCompWram():

// Max number of tiles per background:
#define MAX_TILES 2200

...

// This buffer is used to store uncompressed tiles:
u8 ATTR_EWRAM g_BufferTiles[MAX_TILES * 64];

// This buffer is to resolve Ram to Rom tilenumbers,
// reference counting and a "stack" to pop and push
// tileslots:
u16 ATTR_EWRAM g_BufferRam[31 * 21 * 3];

// This buffer is used to resolve Rom to Ram tilenumbers:
u16 ATTR_EWRAM g_BufferRom[MAX_TILES];

...

// Uncompress raw data on g_BufferTiles
hel_SwiLZ77UnCompWram(g_BufferTiles, ResData(RES_POTATO_RAW));

// Init Tile-System for Background 0
hel_TileCreate(0, // BgNo
g_BufferTiles, // Uncompressed tiles buffer
MAX_TILES, // Number of tiles in ROM
g_BufferRom, // BufferA
31 * 21, // Maximum number of tiles on screen
g_BufferRam, // BufferB
1, // Tileset colormode (0=16colors, 1=256colors)
0, // Palettenumber in 16color mode (0..15)
TRUE); // CBB only mode

// Init Map-System for Background 0
hel_MapCreate(0, // BgNo
POTATO_WIDTH, // MapWidth in tiles
POTATO_HEIGHT, // MapHeight in tiles
ResData(RES_POTATO_MAP), // Source MapData
sizeof(u16), // DataTypeSize
MAP_FLAGS_DEFAULT | MAP_FLAGS_DYNAMICTILERELOADING); // Flags to control map behaviour

// Load Background Palette
hel_PalBgLoad256(ResData(RES_POTATO_PAL));

// Turn on Background
ham_InitBg(0, TRUE, 0, FALSE);

5) Compile and enjoy:
;)

6) Final words:
As I said before, in this tutorial only raw data is compressed, but you can compress map and palette data in a similar way. In the example included below, tile data size has been reduced from 134KB to 86KB, that's 35% smaller. The bitmap included with the example is very complex, so with less detailed bitmaps you can reduce tile size in ROM upon 80%! So if you want to put a lot of detailed porn pics in your game map compression is very important. :D

7) Example with source:
HERE (http://www.fileden.com/files/2008/2/17/1764711/MapComp.zip)

Dr.Vince
03/04/2008, 19h18
thanks for this tutorial ;)

Yodajr
03/04/2008, 19h57
Yeah, thank you ! :w00t:
You kept your word ^^

I'll try soon, and I'll come back here if I have any problem :p

So if you want to put a lot of detailed porn pics in your game map compression is very important.
:D