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 > Using 2 exrot. bg's with different palettes?

#100768 - ThomasS - Wed Aug 30, 2006 12:45 pm

Hi,
I want to use 2 extended rotation backgrounds (Mode 5). Code for loading one of them:

Code:
    BG3_CR = BG_BMP8_256x256 + BG_BMP_BASE(0);
    BG3_XDX = 1 << 8;
    BG3_XDY = 0;
    BG3_YDX = 0;
    BG3_YDY = 1 << 8;
    BG3_CX = 0 << 8;
    BG3_CY = 0 << 8;

    dmaCopy(Title_bin, (uint16*)(BG_BMP_RAM(0), 256*256);
    dmaCopy(TitlePal_bin, BG_PALETTE, 256*2);


The background alone is displayed ok, but I want the other background to use a different palette:

Code:
    dmaCopy(OtherPal_bin, BG_PALETTE + 256*2, 256*2);


But how can I tell the DS which palette a BG should use?

#100770 - Lick - Wed Aug 30, 2006 1:13 pm

There is a limitation to the size of the background palette. The max. number of colors is 256. For 16-color palettes this would mean there is room for 16 different palettes, but for 256-color palettes, do the math, there's only room for 1.
You'll have to switch to high color. (ATTR0_BMP)
_________________
http://licklick.wordpress.com

#100779 - knight0fdragon - Wed Aug 30, 2006 2:18 pm

thst is not true, there is something called extended palette


you may need somethings do do this:


place this in your display CR

DISPLAY_BG_EXT_PALETTE


you will need one of these in your BG_CR, depending on the BG#

BG_PALETTE_SLOT0
BG_PALETTE_SLOT1
BG_PALETTE_SLOT2
BG_PALETTE_SLOT3

note BG_PALETTE 0 and 1 are the same, along with 2 and 3 being the same

BG0 can be used with the BG_PALETTE_SLOT2 and
BG1 can be swapped with the BG_PALETTE_SLOT3 also

if you are using slo

to write to the extended palette

vramSetBankF( VRAM_F_LCD );
// copy the palette date to VRAM_F at this point
vramSetBankF( VRAM_F_BG_EXT_PALETTE );
_________________
http://www.myspace.com/knight0fdragonds

MK DS FC: Dragon 330772 075464
AC WW FC: Anthony SamsClub 1933-3433-9458
MPFH: Dragon 0215 4231 1206

#100788 - ThomasS - Wed Aug 30, 2006 4:19 pm

Ok, thank you! I'll try it soon ...

#100800 - ThomasS - Wed Aug 30, 2006 6:15 pm

I can't get it to work ...

Quote:
you will need one of these in your BG_CR, depending on the BG#

BG_PALETTE_SLOT0
BG_PALETTE_SLOT1
BG_PALETTE_SLOT2
BG_PALETTE_SLOT3

note BG_PALETTE 0 and 1 are the same, along with 2 and 3 being the same


Putting BG_PALETTE_SLOT2 or 3 in the BG_CR only activates wrapping:

Code:
#define BG_WRAP_ON     (1 << 13)

// ==

#define BIT(n) (1 << (n))
#define BG_PALETTE_SLOT3 BIT(13)


And why are BG_PALETTE_SLOT0 and 1 / 2 and 3 the same?

#100848 - knight0fdragon - Thu Aug 31, 2006 2:43 am

only 4 palettes are needed, one for each background, so i guess naturally the hardware just knows what the palettee is, be that if using BG1. it knows that the palette starts at 512
_________________
http://www.myspace.com/knight0fdragonds

MK DS FC: Dragon 330772 075464
AC WW FC: Anthony SamsClub 1933-3433-9458
MPFH: Dragon 0215 4231 1206

#100849 - knight0fdragon - Thu Aug 31, 2006 2:50 am

according to gbatek slots are only used for BG0 and 1
_________________
http://www.myspace.com/knight0fdragonds

MK DS FC: Dragon 330772 075464
AC WW FC: Anthony SamsClub 1933-3433-9458
MPFH: Dragon 0215 4231 1206

#100881 - ThomasS - Thu Aug 31, 2006 10:09 am

I can't get the backgrounds to use extended palettes:
Code:
   videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE | DISPLAY_BG2_ACTIVE | DISPLAY_BG_EXT_PALETTE);

   BG3_CR = BG_BMP8_256x256 | BG_BMP_BASE(0);

    BG3_XDX = 1 << 8;
    BG3_XDY = 0;
    BG3_YDX = 0;
    BG3_YDY = 1 << 8;

    BG3_CX = 0 << 8;
    BG3_CY = 0 << 8;

   u16 bg_number = 3;

   dmaCopy(Title_bin, (uint16*)(BG_BMP_RAM(0)), 256*256);   // Copy bitmap data ...
   vramSetBankF(VRAM_F_LCD);
   dmaCopy(TitlePal_bin, VRAM_F + (bg_number * 256*2), 256*2);   // Copy palette data ...
   vramSetBankF(VRAM_F_BG_EXT_PALETTE);


... doesn't work - only a black screen appears. It works only if I copy the palette to BG_PALETTE instead of VRAM_F + (bg_number * 256*2).
And it seems like it doesn't matter if I set DISPLAY_BG_EXT_PALETTE or not - it only works if I copy the palette directly to BG_PALETTE, without any offset depending on the BG# ... help!