copying over an ex palette?

Post Reply
DayTripperID
Posts: 22
Joined: Tue Aug 07, 2012 8:57 pm

copying over an ex palette?

Post by DayTripperID » Thu Sep 20, 2012 10:24 pm

Hey all, I was wondering how to properly copy over an extended palette? Would it be something like:

Code: Select all

   /* Unlock vram (cannot write to vram while it is mapped as a palette). */
   vramSetBankF(VRAM_F_LCD);

   /* Copy main_gfx palette into palette memory. */
   dmaCopy(main_gfxPal, (u16*)VRAM_F_SPRITE_EXT_PALETTE, main_gfxPalLen);
   
   /* Set vram to ex palette. */
   vramSetBankF(VRAM_F_SPRITE_EXT_PALETTE);

  /* Initialize oam. */
  oamInit(&oamMain, SpriteMapping_1D_128, true);
the dmaCopy() line is giving me trouble. All the sprites are a dark green monochrome.

mtheall
Posts: 210
Joined: Thu Feb 03, 2011 10:47 pm

Re: copying over an ex palette?

Post by mtheall » Sat Sep 22, 2012 3:05 am

VRAM_F_SPRITE_EXT_PALETTE is an enum, not an address. You probably want to use VRAM_F_EXT_SPR_PALETTE.

Code: Select all

 /* Unlock vram (cannot write to vram while it is mapped as a palette). */
   vramSetBankF(VRAM_F_LCD);

   /* Copy main_gfx palette into palette memory. */
   dmaCopy(main_gfxPal, VRAM_F_EXT_SPR_PALETTE, main_gfxPalLen);
   
   /* Set vram to ex palette. */
   vramSetBankF(VRAM_F_SPRITE_EXT_PALETTE);

  /* Initialize oam. */
  oamInit(&oamMain, SpriteMapping_1D_128, true);

DayTripperID
Posts: 22
Joined: Tue Aug 07, 2012 8:57 pm

Re: copying over an ex palette?

Post by DayTripperID » Sat Sep 22, 2012 5:34 pm

My mistake-- when I posted this code I put dmaCopy(main_gfxPal, VRAM_F_SPRITE_EXT_PALLETE, main_gfxPalLen);

That was a typo. In my program I actually had dmaCopy(main_gfxPal, VRAM_F_EXT_SPR_PALETTE, main_gfxPalLen);

Anyways, I managed to get ext palette working, but it was a strange workaround.

Instead of mapping a VRAM bank to an ex palette, I just copied over the 256 color palette to SPRITE_PALETTE and ex palette indexing worked fine, even when I used Oaminit() with the ex palette flag set to false.

For some reason, the only way I could get the sprites to use a palette mapped to an ex palette bank was by setting them to 256 color with -gB8 grit options, but then the ex palette indexing wouldn't work (i'm assuming it used an offset of 256 instead of 16?).

Either way, it seems to be solved. If anyone has any input about this I'd like to hear it because I'm worried that this workaround might cause problems down the line.

mtheall
Posts: 210
Joined: Thu Feb 03, 2011 10:47 pm

Re: copying over an ex palette?

Post by mtheall » Sat Sep 22, 2012 5:50 pm

What grit options were you using previously. And what parameters did you use in oamInit?

DayTripperID
Posts: 22
Joined: Tue Aug 07, 2012 8:57 pm

Re: copying over an ex palette?

Post by DayTripperID » Sat Sep 22, 2012 7:19 pm

Previously, and currently, I was using the following grit options: -W3 -p -gt -gB4

As for oamInit(), i was using: oamInit(&oamMain, SpriteMapping_1D_128, true);

With these options, I couldn't get the sprites to show color when used:

Code: Select all

 vramSetBankF(VRAM_F_LCD);

 dmaCopy(main_gfxPal, VRAM_F_EXT_SPR_PALETTE, main_gfxPalLen);
   
 vramSetBankF(VRAM_F_SPRITE_EXT_PALETTE);

 oamInit(&oamMain, SpriteMapping_1D_128, true);
Instead, I used: dmaCopy(main_gfxPal, SPRITE_PALETTE, main_gfxPalLen); without setting up Bank F at all.

So currently, I am using:

Code: Select all

 dmaCopy(main_gfxPal, SPRITE_PALETTE, main_gfxPalLen);

oamInit(&oamMain, SpriteMapping_1D_128, true);
And ex palette is working, albeit at the default palette address.

It also works with oamInit(&oamMain, SpriteMapping_1D_128, false);

mtheall
Posts: 210
Joined: Thu Feb 03, 2011 10:47 pm

Re: copying over an ex palette?

Post by mtheall » Sat Sep 22, 2012 9:06 pm

There are three kinds of sprites: 4bpp Tiled, 8bpp Tiled, and 16bpp bitmapped.

4bpp ones use the SPRITE_PALETTE (or SPRITE_PALETTE_SUB). The "palette" parameter picks which 16-color "row" to use in this 256-color palette. Use the grit options "-gt -gB4 -p"

8bpp ones use this same palette, ignoring the "palette" parameter, because its palette is already selected. But this is where extended palettes come in. VRAM F can be mapped to extended sprite palettes, which is a set of 16 256-color palettes. If you enable extended palettes in oamInit(), then 8bpp sprites "palette" parameter will choose one of these 16 palettes. They will be unable to use the main sprite palette. Use the grit options "-gt -gB8 -p"

16bpp ones use the "palette" parameter for opacity. 0 = transparent, 15 = fully non-transparent, and 1-14 are partial transparency. These have no use for palettes, since they are not paletted! Use the grit options "-gb -gB16 -p!"

So in short, only 8bpp sprites can use extended palettes. 4bpp simply choose one of the 16 "rows" in the main palette, i.e. what they use is *not* extended palettes.

DayTripperID
Posts: 22
Joined: Tue Aug 07, 2012 8:57 pm

Re: copying over an ex palette?

Post by DayTripperID » Sat Sep 22, 2012 9:15 pm

Ok, got it. Thanks for clearing that up!

Post Reply

Who is online

Users browsing this forum: No registered users and 21 guests