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 > Extended palettes.

#69812 - ProblemBaby - Thu Feb 02, 2006 3:48 am

Trying to use extended palettes.
Ive enabled Bit 31 in DISPCNT
Ive enabled Bit 13 (colormode) for my sprite
Ive enabled a vrambank.
something ive missed? the sprite still uses the standard palette!
please help!

#69813 - knight0fdragon - Thu Feb 02, 2006 4:13 am

are u doing it in 16 color mode or 256?
_________________
http://www.myspace.com/knight0fdragonds

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

#69816 - ProblemBaby - Thu Feb 02, 2006 4:56 am

Quote:

are u doing it in 16 color mode or 256?


Don't understand. I want to have 16 256 color palettes. Ive enabled 256 color mode for the sprite. But I cant understand why it still use the standard palette when Ive enabled extended object palette in the display control.

#69823 - knight0fdragon - Thu Feb 02, 2006 5:43 am

from what ive been reading i believe only the 16 color mode can use the extended palettes. not the 256 or 16bit mode, the reason why i believe this is is 16 colors * 16 different palletes gets u the 256 different pallets available
_________________
http://www.myspace.com/knight0fdragonds

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

#69838 - Mollusk - Thu Feb 02, 2006 8:32 am

knightofdragon, that was on gba... On DS you can have 16 256 colors palettes for backgrounds and sprites

hat vram bank did you use ? could you post the code you set up ? Did you check in dualis that your palette was correctly loaded ?
_________________
PAlib official forum : http://www.palib.info
PAlib official tutorials: http://www.palib.info/wiki
Updates, help, code examples, tutorials, etc...

#69844 - knight0fdragon - Thu Feb 02, 2006 9:09 am

oh ok, well a lot of the stuff i am looking at is from GBA, since the DS documentation is still not as good
_________________
http://www.myspace.com/knight0fdragonds

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

#69849 - ProblemBaby - Thu Feb 02, 2006 10:11 am

Quote:

hat vram bank did you use ? could you post the code you set up ? Did you check in dualis that your palette was correctly loaded ?


It is supposed to work in dualis, right? Iam using vram bank F, I can see in dualis that my palette is loaded to that bank. But it must be something more than bit 31 in dispcnt that enables extended palettes! Cuase, why, why, why is it using the standard palette???

#72929 - mlequim - Wed Feb 22, 2006 2:43 pm

does the extended palettes works on the two screens ? I would like to use 16*256 colors palettes for both screens in tiles mode

#72931 - Mollusk - Wed Feb 22, 2006 2:49 pm

it should work, and it works on both screens.

Try loading the palette a bit everywhere, and having sprites with different palettes shown. Did you enable the VRAM to extended palettes ?
_________________
PAlib official forum : http://www.palib.info
PAlib official tutorials: http://www.palib.info/wiki
Updates, help, code examples, tutorials, etc...

#72932 - mlequim - Wed Feb 22, 2006 2:52 pm

thank's mollusk,
I have not done a test because I have no hardware to test extended palettes, I asked that to know if my pals who does the graphism can use more palettes. We limit to the features that work simultaneously on both screens.

#72934 - Mollusk - Wed Feb 22, 2006 2:54 pm

oh, and it works on Dualis and DeSmuMe
_________________
PAlib official forum : http://www.palib.info
PAlib official tutorials: http://www.palib.info/wiki
Updates, help, code examples, tutorials, etc...

#72935 - mlequim - Wed Feb 22, 2006 2:55 pm

ho nice !! i will download the latest versions !

#100488 - Goosey - Mon Aug 28, 2006 5:38 am

Hello I am running into similar issues.

My video init routine:
Code:
   // Map VRAM to display a background on the main and sub screen and give us lots of sprites
   vramSetMainBanks(   VRAM_A_MAIN_BG_0x6000000,   // Map A and B to main BG memory. This gives us 256KB which is healthy of 16-bit GFX
                  VRAM_B_MAIN_BG_0x6020000,   
                  VRAM_C_SUB_BG_0x6200000,   // Map C to sub background memory
                  VRAM_D_LCD );            // Map D to LCD free space

   // Mapping E to main sprites gives us 64k for sprites. (64k is the max space that 1024 tiles take up in 256 color mode)
   vramSetBankE( VRAM_E_MAIN_SPRITE );

   // Map banks for extended sprite palette
   vramSetBankF( VRAM_F_OBJ_EXT_PALETTE );

   // Set video mode on the main screen
   videoSetMode(   MODE_5_2D |                  // Set the graphics mode to Mode 5 2D
               DISPLAY_SPR_ACTIVE |         // Turn on sprites
               DISPLAY_BG3_ACTIVE |         // Turn on background 3
               DISPLAY_SPR_1D |            // This is used when in tile mode
               DISPLAY_SPR_EXT_PALETTE);

   // Set the video mode on the sub screen
   videoSetModeSub(   MODE_5_2D |               // Set the graphics mode to Mode 5 2D
                  DISPLAY_BG3_ACTIVE );      // Turn on background 3


Sprite setup routine
Code:
   // Map banks for extended sprite palette
   vramSetBankF( VRAM_F_LCD );

   uint16 entirePaletteMem[256*3] = {0};
   dmaCopy(blueyellow.Pal,   &entirePaletteMem[0],   sizeof(u16)*blueyellow.PalSize);
   dmaCopy(cyanpurple.Pal,   &entirePaletteMem[256],   sizeof(u16)*cyanpurple.PalSize);
   dmaCopy(redgreen.Pal,   &entirePaletteMem[512],   sizeof(u16)*redgreen.PalSize);

   dmaCopy(entirePaletteMem, VRAM_F_EXT_PALETTE, sizeof(uint16)*256*3);

   // Map banks for extended sprite palette
   vramSetBankF( VRAM_F_OBJ_EXT_PALETTE );
   
   uint32 gfxIDOffset = 0;
   for (uint32 i = 0; i < spriteDatList.size(); ++i)
   {
      SpriteData& curDat = *(spriteDatList[i]);   

      //copy in the sprite graphics
      dmaCopy(   curDat.Sprite,                     //from address
               &SPRITE_GFX[gfxIDOffset>>1],         //to address
               sizeof(u8)*curDat.SpriteSize );         //size of data to copy
      spriteEntry[i].attribute[0]   =   ATTR0_COLOR_256 | ATTR0_ROTSCALE;      //256 colors, able to rotscale
      spriteEntry[i].attribute[1]   =   ATTR1_ROTDATA(i) | ATTR1_SIZE_64;      //size 64x64

      int paletteBank            = i; //for extended palettes only
      int displayPriority         = 0;
      int startingTileOffset      = gfxIDOffset>>5; //div by 32
      spriteEntry[i].attribute[2]   =   (0xF000 & (paletteBank<<12)) |
                              (0x0C00 & (displayPriority<<10)) |
                              (0x03FF & startingTileOffset);
      gfxIDOffset += (curDat.SpriteSize);
   }

   updateSprites(ships, spriteEntry, spriteRotation);

   //update the OAM
   updateOAM(spriteEntry);


Sorry code not formatted well for forum.. :\

So, I am setting the DISPLAY_SPR_EXT_PALETTE, setting VRAM_F to be the VRAM_F_OBJ_EXT_PALETTE, and copying in the data.

The code seems to work properly in Dualis, but on HW it fails (the sprites are all black, as if VRAM_F is not filled)

Some things:

  • Originally I did not set the VRAM_F to VRAM_F_LCD while copying and reset it to VRAM_F_OBJ_EXT_PALETTE afterowrds (seems illogical to me). However that results in VRAM_F being blank in Dualis (and still blank in hardware). This suggestion (thx KoD) seems to help in Dualis at least.
  • If I don't buffer the palettes into 'entirePaletteMem' then only the first palette appears to be in VRAM_F in Dualis. In hardware the third palette would appear to be in VRAM_F at the location the first palette should be (as if each dmaCopy was overwriting the previous, altough I DID dmaCopy into offsets of the VRAM_F).
  • Have tried replacing the dmaCopy's with swiFastCopy calls. In Dualis this results in black sprites, in HW this seems to result in transparent sprites (???)
  • Have tried replacing the dmaCopy's with memcpy calls. In both cases this results in black sprites.



No idea where I am going wrong, this seems like it should be fairly straightfoward. Any suggestions appreciated.

#100492 - pkwong - Mon Aug 28, 2006 6:06 am

i'm trying to ext. palettes for sprites too
can display on HW with some errors

try removing this:
(0xF000 & (paletteBank<<12))

>C-F SP OE_A2_16C# Sub-palette to use when in 16-color mode. Has no effect if the color mode flag (attr0{C}) is set.
(quote from: http://user.chem.tue.nl/jakvijn/tonc/regobj.htm )

and try to copy to VRAM_F instead of VRAM_F_EXT_PALETTE

i dunno if it works, but that's the difference from my code




let me ask my question here too. :P
i have around 5xx color palettes, using ext. palette at VRAM_F.
the sprites using the first 256 palettes works fine, but the later ones are corrupted.
i see in dualis that the palettes are mapped to VRAM_F, Set 0, #1
is there something extra i need to set before using that part of palettes?

#100493 - pkwong - Mon Aug 28, 2006 6:24 am

i've just done some testing,
it seems that copying the palettes to an array first won't work on HW

try direct copying them to VRAM_F from blueyellow.Pal..etc

sould it be the problem of dmaCopy?

#100536 - Goosey - Mon Aug 28, 2006 3:21 pm

Thanks for the replies pkwong,

If you are not setting the palette offset in the sprite OAMs then all the sprites are going to be using the first palette. The link to Tonc's site refers to GBA which could not use additional 256 color palettes.

As I understand the extended palettes will map 8KB (of the 16KB buffer) for use in extended palettes. This will give space for 16 palettes of 256 colors.

Not copying into the temporary buffer was (as noted in my first post) something that I did try to no avail.

#100546 - pkwong - Mon Aug 28, 2006 4:47 pm

many thanks!
i solved my problem.

sorry for misleading you...


last try :P
coz i really dun see much diff between yours and mine
>If I don't buffer the palettes into 'entirePaletteMem' then only the first palette appears to be in VRAM_F

don't buffer to entirePaletteMem AND copy to VRAM_F instead of VRAM_F_OBJ_EXT_PALETTE
and of coz set to VRAM_F_LCD before that and VRAM_F_OBJ_EXT_PALETTE after
and use dmaCopy, though i didn't try swiFastCopy

good luck!

#100635 - Goosey - Tue Aug 29, 2006 2:15 am

Thanks pkwong! I have it working now following exactly as you described. Odd because I could have sworn I had this arrangement last night and it did not work, but *shrug* it work now! :D (both in HW and in Dualis).

Any experts have any explanation for why it fails to put this in a temporary buffer first? Not that I would find that preferable, but I find it very suprising that it didn't work.

EDIT:

One other question that is bugging me:

When I use extended OBJ palettes the original palette memory isn't used for that functionionality anymore.. Anyone know if it is used for another purpose by the NDS when extended palettes are active? Is it safe for CPU use? It is exposed to both CPU's right, so could use it for another IPC area?

Thx

#101145 - dannyboy - Sun Sep 03, 2006 4:37 am

Well I got this working having a palette written to an array, here's my code:

Code:

// First add this option to the video mode
| DISPLAY_SPR_EXT_PALETTE

void CSprite::SetPaletteColours(u8 PaletteID)
{
    for (int i = 0; i < 256; i++) {
        VRAM_I[(PaletteID * 256) + i] = Image.palette[i];
    }
}


void CSprite::LoadImage(unsigned char* pcxFile, int i) // Load simage into the given memory location
{
    int offset = i*32*16;           // offset in memory for multiple sprites

    loadPCX(pcxFile, &Image);           // load our pcx file into an image
    imageTileData(&Image);              // tile it so it is useful as sprite data
    SetPaletteColours(i);                   // load it's palette
    for(int i = 0; i < 32*16; i++) { SPRITE_GFX_SUB[offset + i] = Image.data16[i]; }
}


void CSprite::LoadImages()
{
    vramSetBankI(VRAM_I_LCD);                       // Open VRAM bank for writing in palettes
    // load pcx file into an image and then to sprite memory and also load palette
    LoadImage((u8*)gbfs_get_obj(&data_gbfs, "zero.pcx", NULL), 0);
    LoadImage((u8*)gbfs_get_obj(&data_gbfs, "one.pcx", NULL), 1);
    vramSetBankI(VRAM_I_SUB_SPRITE_EXT_PALETTE);    // Close VRAM bank
}

// void CSprite::SetImage(int i, int Value, int palette)
{
    sprites[i].oam->attribute[0] = ATTR0_COLOR_256 | ATTR0_SQUARE;
    sprites[i].oam->attribute[1] = ATTR1_SIZE_32;
    sprites[i].oam->attribute[2] = ATTR2_PALETTE(palette) | Value*32;     // how many 2 bytes to skip
}