Code Explanation
map_fragment_info_ptr bg_paradise;
This data type is used to store all the information about our background.
If you want to know more about it, here's a code snippet from mygba.h.
typedef struct map_fragment_info_typ
{
u16* src; // location of this map (usually ROM/EXWRAM)
u16* src_ofs; // location of the data start IN the map
currently set
u8 map_rot; // designates this map to be rotation type
map
u16 map_total_x; // actual map size in tiles / x
u16 map_total_y; // actual map size in tiles / y
u16 map_ofs_x; // offset into maps location start in
tiles / x
u16 map_ofs_y; // offset into maps location start in
tiles / y
u16 map_tiles_x; // actual map size (from offset on)
in tiles / x
u16 map_tiles_y; // actual map size (from offset on)
in tiles / y
u16 map_line_ofs; // offset that needs to be added after
reading 1 line
// of the map to reach next lines map_x
} map_fragment_info,*map_fragment_info_ptr;
ham_SetBgMode(1);
For this example we'll use Mode
1 . In this tile mode the screen is composed of 8x8 pixel squares.
Backgrounds 0, 1, and 2 are available. Background 2 can be rotated
or scaled.
ham_bg[0].ti
= ham_InitTileSet( ... );
This loads our tileset to background 0. It is passed the address
of the tileset, the size of the tiles to be copied in 16 bit chunks,
the color mode, and cbb_only_mode. This last parameter is somewhat
tricky - I recommend you use the default of 1 for now.
ham_bg[0].mi
= ham_InitMapEmptySet(3,0);
This sets up an empty map linked to a background. Basically
it just gets a map ready for the next function we'll call.
bg_paradise
= ham_InitMapFragment(...)
This sets up a rectangular portion on our background into which
we'll "paste" our data with the next function.
ham_InsertMapFragment(bg_paradise,0,0,0);
This actually copies the map from the fragment we just created into
our empty background.
ham_InitBg(0,1,0,0);
This will actually draw the background. It is passed the background
number you wish to initialize, whether the background is hidden
or not, the priority of the background, and whether the background
should be mosaic or not. If you have no't setup the .ti and .mi parameters,
this will return an error.
Well, I don't think that was too difficult. Again, mess with the
code and see what you can do before moving on to Day
7. |