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 > How to manage vrams right

#70476 - Payk - Mon Feb 06, 2006 8:12 pm

ok i tried to have 16bit sprites and bg. it should map randompixels to bg and have some sprites (12 if it matter later more but not much more then 20 at size of 64_64)

Code:
   //turn everything on
    powerON(POWER_ALL_2D);

    //irqs are nice
   irqInit();
   irqSet(IRQ_VBLANK, 0);
    irqEnable(IRQ_VBLANK);

    //enable vram and map it to the right places
    vramSetMainBanks(   VRAM_A_MAIN_SPRITE,        //A and B maped consecutivly as sprite memory
                        VRAM_B_MAIN_SPRITE,        //this gives us 256KB which is the max
                        VRAM_C_MAIN_BG_0x6000000,  //map C to background memory
                        VRAM_D_LCD                 //not using D
                        );
   
   //set the video mode
    videoSetMode(  MODE_0_2D |
                   DISPLAY_SPR_ACTIVE |    //turn on sprites
                   DISPLAY_SPR_2D |        //this is used when in tile mode
                   DISPLAY_SPR_1D_BMP |    //and this in bitmap mode
                   DISPLAY_BG3_ACTIVE);
    
   //turn down all sprites (0-127)
   for(int i = 0; i < 128; i++)
   {
      sprites[i].attribute[0] = 0;
      sprites[i].attribute[1] = 0;
      sprites[i].attribute[2] = 0;
    }
   
      BG3_CR = BG_BMP16_256x256;
   
   //these are rotation backgrounds so you must set the rotation attributes:
    //these are fixed point numbers with the low 8 bits the fractional part
    //this basicaly gives it a 1:1 translation in x and y so you get a nice flat bitmap
        BG3_XDX = 1 << 8;
        BG3_XDY = 0;
        BG3_YDX = 0;
        BG3_YDY = 1 << 8;
    //our bitmap looks a bit better if we center it so scroll down (256 - 192) / 2
        BG3_CX = 0;
        BG3_CY = 0;
   u16* frontBuffer = (u16*)(0x06000000);
   
        for(int iy = 0; iy < 196 ; iy++)
            for(int ix = 0; ix < 256 ; ix++)
               frontBuffer[iy * 256 + ix] = rand() | BIT(15);
               
    //WaitForVblank
      while(DISP_Y!=192);
   while(DISP_Y==192);


untill here is no use of sprites but will be used later and they run perfect.
but all i get on bg is black. ok i didnt forget the alphabit and all code is mixed up from to examples (Double_buffer and Sprite_bitmap i think)
what did i wrong? thanx

#70477 - Payk - Mon Feb 06, 2006 8:14 pm

i also tried with dmacopy and also not to use that array which is linked to 0x60000000. i used bg_gfx[] also like in other examples.hmmh....

#70481 - DekuTree64 - Mon Feb 06, 2006 8:56 pm

BG3 is a text layer in mode 0, and only extended affine layers can do bitmap mode. Try mode 3, 4, or 5, BG3 is extended affine in those modes.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#70484 - Payk - Mon Feb 06, 2006 9:22 pm

hey thanx dekotree64 !! i tried mode 3 and it runs perfectly!!!!!!!
THANX THANX THANX
ohh damn i tried all but not that. so here again THANX