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.

DS development > tiled background for a newbie

#123122 - nimaranjbar - Sun Mar 25, 2007 9:40 am

Hello guys,
I am trying to display a tiled background.
I have 16color paletted tiles and map.
I use this code but the result is an ugly background with corrupted tiles (every thing is green and I dont know why):

Code:

#include<nds.h>
#include<bmpTiles_bin.h>
#include<bmpMap_bin.h>
#include<bmpPalette_bin.h>
int main()
{
    u8* tileMemory = (u8*)BG_TILE_RAM(1);
    u16* mapMemory = (u16*)BG_MAP_RAM(0);
    u16* thePalette= (u16*)BG_PALETTE;


    videoSetMode(MODE_0_2D|DISPLAY_BG0_ACTIVE);
    vramSetBankA(VRAM_A_MAIN_BG_0x06000000);
    BG0_CR=BG_32x32|BG_COLOR_16|BG_MAP_BASE(0)|BG_TILE_BASE(1);

    memcpy(tileMemory,bmpTiles_bin,bmpTiles_bin_size);
    memcpy(mapMemory,bmpMap_bin,bmpMap_bin_size);
    memcpy(thePalette,bmpPalette_bin,bmpPalette_bin_size);

   while(1)
   {
   }
}


I'll appreciate your support.

#123137 - Lick - Sun Mar 25, 2007 2:18 pm

Code:
#include <nds.h>
#include <bmpTiles_bin.h>
#include <bmpMap_bin.h>
#include <bmpPalette_bin.h>

int main()
{
    powerON(POWER_ALL_2D);
    irqInit();
    irqSet(IRQ_VBLANK, 0);
    irqEnable(IRQ_VBLANK);

    u8 *tileMemory = (u8 *)BG_TILE_RAM(1);
    u16 *mapMemory = (u16 *)BG_MAP_RAM(0);
    u16 *thePalette = (u16 *)BG_PALETTE;

    videoSetMode(MODE_0_2D | DISPLAY_BG0_ACTIVE);
    vramSetBankA(VRAM_A_MAIN_BG);
    BG0_CR = BG_32x32 | BG_COLOR_16 | BG_MAP_BASE(0) | BG_TILE_BASE(1);

    memcpy(tileMemory,  bmpTiles_bin,  bmpTiles_bin_size);
    memcpy(mapMemory, bmpMap_bin,  bmpMap_bin_size);
    memcpy(thePalette,  bmpPalette_bin,  bmpPalette_bin_size);

    while(1)
    {
         swiWaitForVBlank();
    }

    return 0;
}

_________________
http://licklick.wordpress.com