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 > [SOLVED] TILE BGs over BMP BGs

#153069 - pawob - Mon Mar 24, 2008 6:57 pm

I'm trying to put tile bgs over bmp bgs, everything is ok but when I copy the tile to any part of memory the whole bmp bgs appears with the first color of the palette:

Things I've tried:
1.- Use memcpy,swiCopy,dmaCopy (different problems)
2.- Diferent values for B2,B3,Tile_Ram,Map_Ram
3.- Diferent values for the size value in the mem copy function

Code:

#include <nds.h>
#include <stdio.h>
#include <bitmap.h>
#include <sprites.h>
#include <string.h>

#include <park0_bmp.h>
#include <park1_bmp.h>
#include <park2_bmp.h>
#include "orangeShuttle.h"
#include "orangeShuttle2.h"


//create a tile called redTile
u8 redTile[64] =
{
   1,1,1,1,1,1,1,1,
   1,1,1,1,1,1,1,1,
   1,1,1,1,1,1,1,1,
   1,1,1,1,1,1,1,1,
   1,1,1,1,1,1,1,1,
   1,1,1,1,1,1,1,1,
   1,1,1,1,1,1,1,1,
   1,1,1,1,1,1,1,1
};

 
//create a tile called greenTile
u8 greenTile[64] =
{
   2,2,2,2,2,2,2,2,
   2,2,2,2,2,2,2,2,
   2,2,2,2,2,2,2,2,
   2,2,2,2,2,2,2,2,
   2,2,2,2,2,2,2,2,
   2,2,2,2,2,2,2,2,
   2,2,2,2,2,2,2,2,
   2,2,2,2,2,2,2,2
};

int main()
{
   // Powering up the DS 2D hardware
   REG_POWERCNT = POWER_ALL_2D;
   irqInit();
   irqEnable(IRQ_VBLANK);
      
      
vramSetMainBanks(VRAM_A_MAIN_BG_0x06000000,
                     VRAM_B_MAIN_BG_0x06020000,
                     VRAM_C_MAIN_BG_0x06040000,
                     VRAM_D_LCD);
vramSetBankE(VRAM_E_MAIN_SPRITE);
   
videoSetMode(MODE_5_2D |
       DISPLAY_BG0_ACTIVE |//BG0 for tiled map
       DISPLAY_BG2_ACTIVE |
                 DISPLAY_BG3_ACTIVE |
                 DISPLAY_SPR_ACTIVE |
                 DISPLAY_SPR_1D       
                 );
            
            
videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE);

int B3=10;
   int B2=8;
   
      //Create the pointers connected to the main bg ram
   u16* vbuffer0 = (u16*)BG_BMP_RAM(B3);
   u16* vbuffer1 = (u16*)BG_BMP_RAM(B2);
   // Setting a pointer to the BG0's map base
   u8* tileMemory = (u8*)BG_TILE_RAM(1);
   u16* mapMemory = (u16*)BG_MAP_RAM(1);
   
      //Assing the BGS properties
   BACKGROUND.control[3] = BG_BMP8_256x256 | BG_BMP_BASE(B3) | BG_PRIORITY(3) | BG_WRAP_ON;
   BACKGROUND.control[2] = BG_BMP8_256x256 | BG_BMP_BASE(B2) | BG_PRIORITY(3) | BG_WRAP_ON;
   //For the tiled map
   BG0_CR = BG_32x32 | BG_COLOR_256 | BG_MAP_BASE(1) | BG_TILE_BASE(1) | BG_PRIORITY(0);
   
      //Set transformations to zero
   BACKGROUND.bg3_rotation.xdy = 0;   BACKGROUND.bg3_rotation.xdx = 1 << 8;
   BACKGROUND.bg3_rotation.ydx = 0;   BACKGROUND.bg3_rotation.ydy = 1 << 8;
   BACKGROUND.bg2_rotation.xdy = 0;   BACKGROUND.bg2_rotation.xdx = 1 << 8;
   BACKGROUND.bg2_rotation.ydx = 0;   BACKGROUND.bg2_rotation.ydy = 1 << 8;


      //Assign pointers to the bitmaps
   Bmp16File* bmp0 = (Bmp16File*)park0_bmp;
   Bmp16File* bmp1 = (Bmp16File*)park1_bmp;

...
BG_PALETTE[1] = RGB15(31,0,0);
BG_PALETTE[2] = RGB15(0,31,0);
//Here is when it make nosense, 32
memcpy((void*)BG_TILE_RAM(1), redTile, 64);
memcpy((void*)(BG_TILE_RAM(1)+64), greenTile, 64);
   
   DisplayBmpFastPosY(vbuffer0,BG_PALETTE,bmp0,0);
DisplayBmpFastPosY(vbuffer1,BG_PALETTE,bmp1,bmp0->info.height);
   


bmp0 is 256x100 and bmp1 is 256x92 (that part is completely right)
the matter is with BG0 makes all the pixels with the same color and happens WITHOUT assigning the tiles to the map memory, happens when I pass the data to the tile ram

Is there any problem with the assignments, or sizes with memcpy, 32,64 or what?
_________________
http://overrider.blogspot.com


Last edited by pawob on Tue Mar 25, 2008 9:54 am; edited 1 time in total

#153123 - pawob - Tue Mar 25, 2008 9:54 am

Solved easily:

What you have to do is assign a transparent color, for instance:

BG_PALETTE[0] = RGB15(31,31,31);

Create a structure like:

Code:

u8 transpTile[64] =
{
   0,0,0,0,0,0,0,0,
   0,0,0,0,0,0,0,0,
   0,0,0,0,0,0,0,0,
   0,0,0,0,0,0,0,0,
   0,0,0,0,0,0,0,0,
   0,0,0,0,0,0,0,0,
   0,0,0,0,0,0,0,0,
   0,0,0,0,0,0,0,0
};


and now fill the screen with the transparent color and then with the tiles you want:
Code:

//copy the tiles into tile memory one after the other
   swiCopy(transpTile, tileMemory, 32);
   swiCopy(redTile, tileMemory+64, 32);
   swiCopy(greenTile, tileMemory + 64*2, 32);
   
   //create a map in map memory
   for(i = 0; i < 32 * 32; i++)
      mapMemory[i] = 0;
   
   for(i = 0; i < 32 * 2; i++)
      mapMemory[i] = (i & 1) + 1;


Now works!!
[/code]
_________________
http://overrider.blogspot.com