C Code Generation

NOTE: This section assumes you understand the C programming language and Gameboy Advance programming.

This dialog is presented when you select the Generate C option. The Directory field lets you select which directory the generated source and header will be written into.

The Filename allows you to enter what the sources will be called. Note that no extensions are required; entering foo here will create foo.c and foo.h.

The Array entry allows you to provide a basename for the generated arrays and #defines. For example, entering bar here will create the following header file:

#ifndef FOO_H
#define FOO_H

#ifdef _cplusplus
extern "C" {
#endif

#define BAR_PAL256 0

extern const unsigned short bar_pal[256];
#define BAR_DATA_LEN 1488
extern const unsigned short bar_data[1488];

/* Sprite names
*/
#define A_SPRITE_NAME 12
#define ANOTHER_SPRITE_NAME 20


#ifndef GFXINFOTYPE
#define GFXINFOTYPE

/* Remember to add 512 to tile no when using bitmapped modes
*/
typedef struct
    {
    int pal;
    int tile;
    int width;
    int height;
    int shape1;
    int shape2;
    } GFXInfoType;

#endif

#define BAR_NO 30
extern const GFXInfoType bar_info[BAR_NO];

#ifdef _cplusplus
}
#endif

#endif

Going from the top of the header, these definitions and arrays are created:

BAR_PAL256
This defines whether the sprites are 256 colour or not. zero indicates 16 colour mode, one 256 colour mode.

bar_pal[]
This is the palette data. It is always 256 16-bit words long.

BAR_DATA_LEN
BAR_DATA_LEN defines the length of the sprite data (in 16-bit words).

bar_data[]
This is the sprite data itself.

A_SPRITE_NAME
If sprites have been named, then the names are defined here so that the bar_info array can be accessed symbolically. Note that while any text can be entered into the sprite name in the editor, once code is generated the following rules are applied:


BAR_NO
This defines the number of sprites in the set.

bar_info
This defines information for each sprite.
pal indicates the palette number if 16 colour mode is being used.
tile is the tile number the sprite starts at. As the comment says 512 should be added to this when using the sprites in bitmapped modes.
width and height are the size of the sprite in pixels.
shape1 and shape2 are the unshifted shape values for the size of the sprite (as used in the sprite registers).


Using the generated code

To use code generated, simply #include the created header where needed, compile the source file to an object file and link it in with your executable.

Note that the source file is not dependent on (i.e. does not include) the header!


Note on 1D/2D sprite data

Note that this tool always generates sprite data in 1D format. This is so that the Map Editor can edit using tiles bigger than 8x8, whilst still being able to work out which tile number to put in the map.