In this chapter, we will replace the “Hello World” program
we wrote in Chapter 2 with a program that builds a tile-mode display of
the canyon from our game. We will start by taking a tile data bitmap and
use it to produce a set of source data to be #included in the project.
We will then use this data to setup a tile mode display.
Since my artist is currently out of town, we’ll be using left-over
“Programmer-Art” from the PC version of Boulder Bombers for
the canyon tile bitmap.
The first step to putting the tile data on the screen is to convert the
bitmap into code that can be included in the project.
Now that we have our data squared away, it’s time to add code to
use it. Open the bbadvance.c file in your editor and make the following
changes:
Incorporate the data you just generated by inserting the following
#include statements after the #include “Socrates.h” statement:
// =======================================================================
// Constant data
// =======================================================================
#include "bbtilesPalette.dat"
#include "bbtilesTileSet.dat"
Insert the following variable declaration after the __gba_multiboot
declaration. This variable contains the tile index (map) data for a
sample canyon. Please feel free to cut-and-paste this section to your
source – typing this in was no fun at all.
const u16 canyonData[] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,5,5,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
10,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,9,
6,10,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,8,7,
6,7,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,6,7,
6,6,10,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,8,6,7,
6,6,7,3,3,3,3,3,3,8,10,3,3,3,3,3,3,3,3,8,10,3,3,3,3,3,3,6,6,7,
6,6,6,10,3,3,3,3,8,6,6,6,10,3,3,3,3,8,6,6,6,10,3,3,3,3,8,6,6,7,
6,6,6,6,10,3,3,8,6,6,6,6,6,10,3,3,8,6,6,6,6,6,10,3,3,8,6,6,6,7
};
Remove SoPaletteSetGreyScale call and all of the SoMode4Renderer calls
from AgbMain and in their place insert a call to a new subroutine 'setupPlayfield'.
setupPlayfield();
Insert the following implementation of the setupPlayfield subroutine
after the canyonData declaration:
// ***********************************************************************
// *** INITIALIZATION
// ***********************************************************************
// Setup Playfield (BKGs)
void setupPlayfield(void)
{
// set palette
SoPaletteSetPalette(SO_SCREEN_PALETTE, bbtilesPalette, true);
// set mode 0 (tile mode)
SoDisplaySetMode(0);
// load tile data
SoTileSetBkgLoad(&bbtilesTileSet, 0, 0);
// allocate a background layer
SoBkgSetup(0, SO_BKG_PRIORITY_0 | SO_BKG_CHARBASE(0)
| SO_BKG_MOSAIC_DISABLE | SO_BKG_CLRMODE_256 | SO_BKG_SCRBASE(0x1f)
| SO_BKG_TEXTSIZE_256x256);
// load the tile indexes into the background
SoBkgWriteBlock(0, 0, 0, 30, 20, 30, (u16*)&canyonData[0]);
// turn on the background display
SoBkgEnable(0, true);
}
Since understanding these calls is important for getting tile mode working,
we’ll examine them in greater detail.
When you’re all finished, save the file.
Compile your updated project by running ‘make’ from a command
shell in the BBAdvance directory. Once it’s done, try it out in
your GBA emulator. You will get a screen like this one.