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.

Graphics > Simple Text tile modes

#2893 - Mug - Fri Feb 14, 2003 9:17 am

can anyone direct me to a good read about how to use background modes like mode 0 for simple text?

or even better, an open source rom that just shows the use of text in tile modes.

#2900 - ampz - Fri Feb 14, 2003 10:34 am

http://www.hh.se/stud/d99tibr/index5.html

#2904 - Lord Graga - Fri Feb 14, 2003 10:55 am

Go to GBADev.org and download SM's library v 6, it has a lib called lib_text.h, take a look in it.

#2906 - Mug - Fri Feb 14, 2003 11:02 am

i cant find that library for download anywhere on the site

actrually how about this, could someone quickly throw together a program in C that displays

'ABC123'

or something on the screen using an apropriate tile mode in a simple way? that would be great

#2911 - Quirky - Fri Feb 14, 2003 1:55 pm

You store the tiles for the text in tile ram, then set the map data to the tile index for each letter. It is a peice of cake. Here is some code I wrote to do these steps...

Tp place the correct char tile at the x, y position in the Bg "bg" I use this. e.g. print_text("ABC123", 0,1, &bg0);

Code:

void print_text(char* text, u16 x, u16 y , Bg* bg)
{
   u32 indx=0;
   u16 newx = x;
   
   u16 letter;
      while( (text[indx]!= 0) )
      {
        letter = text[indx]-0x21; // first thing is !, index 0x21
        if (text[indx] != 32)
          bg->mapData[newx+y*32] = letter+bgmapoffset;
        else
          bg->mapData[newx+y*32] = 0;
        newx++;
        indx++;
   }
}


Where Bg is as defined in the pern project.

The actual tile data is taken from a bmp of letters I drew... loading that into the appropriate tile data section is done like this, where "offset" is how many tiles you want to skip before loading the text, pLetters is a pointer to the bmp data and Bg is the background again:

Code:

void SetUpLetters(Bg* bg, u32 offset) {
 // transfer in the Letters
 bgmapoffset = offset;
 u32 realos = bgmapoffset*8*4;

 REG_DMA3SAD = (u32)pLetters;
 REG_DMA3DAD = (u32)&bg->tileData[realos];
 REG_DMA3CNT = 3104 |DMA_16NOW;
}


The first text character into the tile ram is a "!" and the letters are in the correct ascii order. This is for 256 colour tiles.

Knocking up entire C code for a "demo" would lose the idea behind all the set up code. If you implement something like the above (or better, how about non uni-spaced text?), you'll have a far better understanding of how it all works.