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.

Beginners > whats the best way to load bg (for dummies?)

#43758 - sabkaraja - Thu May 26, 2005 9:27 am

Hi

I searched much of the beginners forum for a best way to load bg. At the moment, I am able to do it by trial and error, but the clever way to do this eludes me.
I am clear with loading sprites to VRAM and find the character index. Similarly, I believe there must be some way to load bg's and put them in appropriate charbase and screenblock.

Thanks

Rajesh

#43786 - tepples - Thu May 26, 2005 8:19 pm

Have you tried AGBTTY? Here's a gentle way to learn the basics of tiled backgrounds on a GBA:
  1. Install and learn AGBTTY.
  2. Learn how to write to arbitrary positions on the map (hint: MAP[n][y][x]).
  3. Hack the font in a tile editor.
  4. Replace the font with a 4-bit-per-pixel font.

_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#43819 - sabkaraja - Fri May 27, 2005 1:02 am

Hi

I believe I was not clear enough. When we are loading sprites into the VRAM, I use this method:

Code:
//ball is sprite of size (8*8) * 4 frames
//box is a sprite of size (32*32)
//cat is a sprite of size (64*32) * 5 frames

//so I load them like this

#define BALL_VRAM   OBJ_MODE0_VRAM
#define BOX_VRAM    BALL_VRAM + (8*8*4) // ball's size
#define CAT_VRAM    BOX_VRAM + (32 * 32) // box's size

//and the CHARS are

#define BALL_CHAR   (BALL_VRAM - OBJ_MODE0_VRAM)/ 0x20
#define BOX_CHAR    (BOX_VRAM -  OBJ_MODE0_VRAM)/ 0x20
#define CAT_CHAR    (CAT_VRAM -  OBJ_MODE0_VRAM)/ 0x20


In this way I am able to load the images. However I am not sure this is the best method. I would like to listen to the expert comments on this as well.

Similarly, there must be some way where you can load the images into RAM and place them using some calculation.

What it might be?

Regards

Rajesh

#43830 - tepples - Fri May 27, 2005 2:32 am

These macros should help:
Code:
/* Pattern tables

   For example, tile 137 of pattern table 2 is PATRAM4(2, 137)
   or PATRAM8(2, 137) depending on the bitdepth.
*/

#define PATRAM(x) ((u32 *)(0x06000000 | ((x) << 14)))
#define PATRAM4(x, c) ((u32 *)(0x06000000 | (((x) << 14) + ((c) << 5)) ))
#define PATRAM8(x, c) ((u32 *)(0x06000000 | (((x) << 14) + ((c) << 6)) ))
#define SPR_VRAM(x) ((u32 *)(0x06010000 | ((x) << 5)))

/* Nametables

They may or may not be called "nametables" in official
Nintendo GBA documentation, but because I come from
the NES community, and the NES community calls the
map data areas "nametables", that's what I call them.

fedcba9876543210  Text nametable entries
||||||||||||||||
||||||++++++++++- Tile number
|||||+----------- Flip tile horizontally (b <-> d)
||||+------------ Flip tile vertically (b <-> P)
++++------------- Palette number, that is,
                  bits 4-7 of palette index for opaque pixels
                  of 16-color tiles

*/
typedef u16 NAMETABLE[32][32];

#define MAP ((NAMETABLE *)0x06000000)
#define MAP_HFLIP      0x0400
#define MAP_VFLIP      0x0800
#define MAP_FLIP       0x0c00
#define MAP_PALETTE(x) ((x) << 12)


Then to access tile number c of CHR base block x, use PATRAM4(x, c) in 16-color mode or PATRAM8(x, c) in 256-color mode. To write to map #n at tile position (x, y), use MAP[n][y][x].
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#43875 - sabkaraja - Fri May 27, 2005 3:39 pm

Thanks mate. I will look into it over the weekend