Monday 15 July 2013

BACKGROUNDS

Direct Memory Access (DMA) functions are found in C:\devkitPro\libnds\include\nds\dma.h.

All of the functions relating to setting backgrounds (including bgInit(), bgGetGfxPtr(id), etc.) can be found in C:\devkitPro\libnds\include\nds\arm9\background.h

When you use the <background.h> function :

int bgInit(int layer, Enum BgType, Enum BgSize, int mapBase, int tileBase)

you, both, receive an id for that background which can be used later in such functions as bgGetGfxPtr(id) and bgGetMapPtr(id); while, additionally, setting the memory slots for both map and tile bases, which the compiler will subsequently utilize to give you those memory addresses required.

Therefore, store it in a variable, thus:

int bg1 = bgInit(0, BgType_Text8bpp, BgSize_T_256x256, 0,1);

  • The standard tile size used by the DS is 8*8 pixels => 256x256 is 32 tiles squared. A standard map block in VRAM memory is therefore (u16 or half-word) 2 bytes * 32*32, which equals 2kb. This is the value, starting at zero, that is required in the mapBase parameter of bgInit.
  • If you plan on using larger maps, such as BgSize_T_512x512, etc. you will be using 4 map blocks or above, and subsequent calls to bgInit() will require that you start with a mapBase value of 4 (or 8, 12, etc. )
  • If go into (or beyond) mapBase of 8, you will intrude upon the space commonly occupied by the tile Blocks...
  • Each tile Block is 16kb in length (the equivalent of 256 tiles; and bearing in mind that most good map editors will only list the tiles actually used in any one map), and they commonly start in block 1 of the VRAM memory space (as above). If, however, the map blocks exceed their normal slot, it is a simple matter of transferring the tile Blocks forward to a tileBase of 2, thus:

int bg3 = bgInit(2, BgType_Text8bpp, BgSize_T_512x512, 8,2);

The DS provides two ways to assign graphics data to the appropriate VRAM banks: swiCopy(), which uses the CPU; and dmaCopy(), which bypasses it. Their templates are very similar:
void swiCopy(const void * source, void * dest, int flags);

void dmaCopy(const void * source, void * dest, uint32 size)


  • flags, apparently represents the size of the data to copy/fill (in words or 4byte) or'd with the copy mode size (word or halfword) and type (copy or fill).    

No comments:

Post a Comment