Backgrounds - multiple palettes

Post Reply
DarkShadow44
Posts: 19
Joined: Wed Apr 15, 2009 3:17 pm

Backgrounds - multiple palettes

Post by DarkShadow44 » Wed Apr 15, 2009 3:28 pm

Hello.
I want to use multiple backgrounds at one screen (extended palettes).
Can you say, what's worng with this Code ?

Code: Select all

#include <nds.h>

#include <stdio.h>

// grit adds a nice header we can include to access the data
// this has the same name as the image
#include "drunkenlogo.h"
#include "drunkenlogo2.h"

#include <string.h>

int main(void)
{
    // set the mode for 2 text layers and two extended background layers
	videoSetMode(MODE_5_2D);
    vramSetBankA(VRAM_A_MAIN_BG);
	
	REG_DISPCNT |= DISPLAY_BG_EXT_PALETTE;

	int bg2 = bgInit(2, BgType_Bmp8, BgSize_B8_128x128, 0,0); 
	int bg3 = bgInit(3, BgType_Bmp8, BgSize_B8_256x256, 1,0); 
	
	vramSetBankG(VRAM_G_LCD);

		dmaCopy(drunkenlogoPal,VRAM_G_EXT_PALETTE[0],256*2); 
		dmaCopy(drunkenlogo2Pal,VRAM_G_EXT_PALETTE[1],256*2); 
		
	// set vram to ex palette
	vramSetBankG(VRAM_G_BG_EXT_PALETTE);
		


	REG_BG2CNT |= BG_PALETTE_SLOT1 ;
	REG_BG3CNT |= BG_PALETTE_SLOT0 ;

	
	dmaCopy(drunkenlogo2Bitmap, bgGetGfxPtr(bg2), 128*128);//bg 2 //klein
	
	dmaCopy(drunkenlogoBitmap, bgGetGfxPtr(bg3), 256*256); //bg3 //gross
	


    while(1) swiWaitForVBlank();

	return 0;

RyouArashi
Posts: 29
Joined: Sun Mar 29, 2009 9:23 pm

Re: Backgrounds - multiple palettes

Post by RyouArashi » Wed Apr 15, 2009 4:34 pm

The extended palettes for BGs consist of 4 Slots each (Slot 0-3), one for each Background Layer.
Each palette slot can store 16 (IIRC) 256color palettes (selectable via map entry). Basically
Slot 0 is for BG0
Slot 1 for BG1
and so on...

Theres another trap in the VRAM mapping for VRAM_F and VRAM_G, which is not shown
in the VRAM table (see http://www.dev-scene.com/NDS/NDS_Tutorials_VramTable):

You have to specify which Slots you want your VRAM banks to fill, in your case
set

Code: Select all

VRAMBankG(VRAM_G_BG_EXT_PALETTE_SLOT23);
(Leave out the

Code: Select all

REG_BG2CNT |= BG_PALETTE_SLOT1 ;
REG_BG3CNT |= BG_PALETTE_SLOT0 ;
for now)

My greatest problem at the beginning was finding out the correkt palette
base address, which ist - when using VRAM_F and VRAM_G -

Code: Select all

VRAM_F + (Slot << 12) + (PaletteIndex << 8);
(copied from palib sources :-)
Where PaletteIndex usually is 0...

Then copy your palettes to

Code: Select all

dmaCopy(drunkenlogoPal,VRAM_F + (3 << 12) + (0 << 8),256*2);
dmaCopy(drunkenlogo2Pal,VRAM_F + (2 << 12) + (0 << 8),256*2); 
evtl. casten, weiß ich grad nicht auswendig...


Hope this helps you

DarkShadow44
Posts: 19
Joined: Wed Apr 15, 2009 3:17 pm

Re: Backgrounds - multiple palettes

Post by DarkShadow44 » Thu Apr 16, 2009 12:19 pm

You said "when using VRAM_F and VRAM_G", but I only use VRAM_G...
I still see a black screen...
Can you Post the whole code, that works on your computer ?

Another question, is it possible to use sprites with extended palettes on both screens and also backgrounds with extended palettes on both sreens ?

RyouArashi
Posts: 29
Joined: Sun Mar 29, 2009 9:23 pm

Re: Backgrounds - multiple palettes

Post by RyouArashi » Thu Apr 16, 2009 8:36 pm

Here some code I'm currently using in my project:

I'm using VRAM_F and VRAM_G for Main BG Ext. palettes, VRAM_H for Sub BG Ext. palettes.

Video Modes are MODE_0_3D and MODE_0_2D (Main/Sub).
BG Ext. palettes enabled for both screens

VRAM Inits:

Code: Select all

  // Setup VRAM
  //vramSetBankA(VRAM_A_LCD); Used by NitroEngine
  //vramSetBankB(VRAM_B_LCD); Used by NitroEngine
  vramSetBankC(VRAM_C_SUB_BG_0x06200000);
  vramSetBankD(VRAM_D_MAIN_BG_0x06000000);
  //vramSetBankE(VRAM_E_LCD); Used by NitroEngine
  vramSetBankF(VRAM_F_BG_EXT_PALETTE_SLOT01);
  vramSetBankG(VRAM_G_BG_EXT_PALETTE_SLOT23);
  vramSetBankH(VRAM_H_SUB_BG_EXT_PALETTE);
  vramSetBankI(VRAM_I_LCD);
Loading BGs:

Code: Select all

  vramSetBankF(VRAM_F_LCD);
  vramSetBankG(VRAM_G_LCD);
  vramSetBankH(VRAM_H_LCD);  
  
  PictureBG1 = bgInit(1, BgType_Text8bpp, BgSize_T_256x256, 4,2);
    dmaCopy(bg_splash_1b_Tiles, bgGetGfxPtr(PictureBG1), sizeof(bg_splash_1b_Tiles));
    dmaCopy(bg_splash_1b_Map,   bgGetMapPtr(PictureBG1), sizeof(bg_splash_1b_Map));
    dmaCopy(bg_splash_1b_Pal,   (u16*)(VRAM_F + (1 << 12) + (0 << 8)), sizeof(bg_splash_1b_Pal));
    
  PictureBG1Sub = bgInitSub(1, BgType_Text8bpp, BgSize_T_256x256, 4,2);
    dmaCopy(bg_splash_1t_Tiles, bgGetGfxPtr(PictureBG1Sub), sizeof(bg_splash_1t_Tiles));
    dmaCopy(bg_splash_1t_Map,   bgGetMapPtr(PictureBG1Sub), sizeof(bg_splash_1t_Map));
    dmaCopy(bg_splash_1t_Pal,   (u16*)(VRAM_H + (1 << 12) + (0 << 8)), sizeof(bg_splash_1t_Pal));	    
  
  PictureBG2 = bgInit(2, BgType_Text8bpp, BgSize_T_256x256, 5,4);
    dmaCopy(bg_splash_2b_Tiles, bgGetGfxPtr(PictureBG2), sizeof(bg_splash_2b_Tiles));
    dmaCopy(bg_splash_2b_Map,   bgGetMapPtr(PictureBG2), sizeof(bg_splash_2b_Map));
    dmaCopy(bg_splash_2b_Pal,   (u16*)(VRAM_F + (2 << 12) + (0 << 8)), sizeof(bg_splash_2b_Pal));
		
  PictureBG2Sub = bgInitSub(2, BgType_Text8bpp, BgSize_T_256x256, 5,4);
    dmaCopy(bg_supaplex_Tiles, bgGetGfxPtr(PictureBG2Sub), sizeof(bg_supaplex_Tiles));
    dmaCopy(bg_supaplex_Map,   bgGetMapPtr(PictureBG2Sub), sizeof(bg_supaplex_Map));
    dmaCopy(bg_supaplex_Pal,   (u16*)(VRAM_H + (2 << 12) + (0 << 8)), sizeof(bg_supaplex_Pal));		    
	
  vramSetBankF(VRAM_F_BG_EXT_PALETTE_SLOT01);
  vramSetBankG(VRAM_G_BG_EXT_PALETTE_SLOT23);
  vramSetBankH(VRAM_H_SUB_BG_EXT_PALETTE); 
All BGs were converted using PAGfx as "TileBg" and are 256x256 pixels^2 large.
In case of Main BG2, the palette actually is stored in VRAM_G, but VRAM_F still is the base address.
It also didn't work for me until I used

Code: Select all

VRAM_F_BG_EXT_PALETTE_SLOT01
VRAM_G_BG_EXT_PALETTE_SLOT23
instead of just

Code: Select all

VRAM_F_BG_EXT_PALETTE
VRAM_G_BG_EXT_PALETTE

DarkShadow44
Posts: 19
Joined: Wed Apr 15, 2009 3:17 pm

Re: Backgrounds - multiple palettes

Post by DarkShadow44 » Sat Apr 18, 2009 9:41 pm

Thanks! That works.

But why does it work if I write

Code: Select all

dmaCopy(bg0_Tiles, bgGetGfxPtr(PictureBG1), 0);
instead of

Code: Select all

dmaCopy(bg0_Tiles, bgGetGfxPtr(PictureBG1), sizeof(bg0_Tiles));

ganja
Posts: 1
Joined: Mon Nov 30, 2009 8:46 pm

Re: Backgrounds - multiple palettes

Post by ganja » Mon Nov 30, 2009 8:52 pm

hi, extended palettes don't work with bitmap background?
even I activate extended palette, bitmap background still use BG_PALETTE
or did I miss something?

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest