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.

Coding > Specify a BG to use a 16 color palette

#10388 - RaBBi - Wed Sep 03, 2003 10:03 pm

Hi,

Just a little question:

Is it possible (and how to) to specify a BG to use a 16 colors palette ?

I explain what I'm trying to do.

I load a 256 colors maps, really use ~67 colors, on BG3.
The colors are loaded from index0 of the palette.

Then I load a 16 colors tileset on BG0.
So before I loaded a 16 colors palette in the bank 15.

And I wanted to specify BG0 to use this last palette.

As I'm using HaM, I ask the same question on ngine.de forum.

Thank you ^^
_________________
Sorry for my poor english, but it would be worst for you to understand me if I speak in my native language, French ^^

#10393 - sajiimori - Thu Sep 04, 2003 1:59 am

Sure, you can do that. First, clear bit 7 of REG_BG0CNT for 16 color.
Code:

REG_BG0CNT &= ~(1<<7);

You don't choose a palette for a whole background, though. You can choose a different palette for each tile using bits 12-15.
Code:

u16* tile = ...;
*tile |= palette_number << 12;

Check the CowBite spec for details.

#10405 - RaBBi - Thu Sep 04, 2003 7:58 am

Thank you Sajimori for answer ^^

But I knew it, how to attribute a palette to a tile.

In fact I identified what's the matter dealing with 256 and 16 in may case.

The 67 colors are loaded from start of palette.
They are used by tileset/map on BG3.
Then I load the 16 colors palette in bank 15 and attribute the BG0 in 16 colors mode.

And when I fill it with tile 0, this tile uses the 4th color of the entire palette.
I attached the 16 colors tileset to the BG0 so it may use not a color from the entire palette....

Umm I got an idea !
In the 16 color tileset, it may be indicated that the tile 0 use the 4th color of its own palette !
And so when I load it in GBA, it's unable to make the difference between it's own palette and the entire palette that is loaded in GBA memory !

Do you think I'm right thinking like that ?

In that case, how can I deal with BG transparencies in 256/16 colors mix ?? :/
_________________
Sorry for my poor english, but it would be worst for you to understand me if I speak in my native language, French ^^

#10427 - antysix - Thu Sep 04, 2003 4:00 pm

No, I don't think you understand fully. You can't have a mix of a 256 color palette and 16 color at the same time, like you call it.
If you specify in REG_BGxCNT that you use 16 16 color palettes then it's only that, and not 256 color.
And how to do that sajimori said already: set which palette you use in the map entry. Just mind that your tiles use with 16 16 color palettes only 4bit per pixel, instaed of 8 bit.
_________________
Currently playing: NGC: Metroid Prime
GBA: Golden Sun: The Lost Age

Currently developping: Project ~ [ Phail ]

#10428 - niltsair - Thu Sep 04, 2003 4:47 pm

He can mix 256 and 16colors. Not within the same background but amongs different background. Thus he could ...

Code:
0----------------------------208---------224---------240--------256
|  Palette0                   | Palette1  | Palette2  | Palette3 |
|  256colors(only access 208) | 16colors  | 16colors  | 16colors |
 -----------------------------------------------------------------

-BG0 set to 256 colors, using Palette 0.
-Bg1,2,3 set to use 16colors palettes. Each tile being able to use Palette 1,2,3. They could also access group of 16colors in Palette 0, but without being able to change colors in it without screwing palette 0.

He basicly need to...
-Set some background to use a 256colors palette, while only acessing the x first colors.
-He then has 256-x colors available to use for 16colors palettes has he wishes.

#10432 - Nessie - Thu Sep 04, 2003 5:42 pm

With some careful arrangement of your BG palette and BG artwork it would be quite possible to use 16 16-colour palettes on one layer and use that *exact* same palette for a 256 colour BG layer.

As niltsair suggests, the BG system just interprets the BG palette data differently in 16 colour mode vs. 256 colour mode...colour 0 is transparent in 256 colour mode. Whereas, colours 0,16,32,etc are transparent in 16 colour mode.

So, depending on what you are doing, niltsair's suggestion is probably the easiest, but if you needed lots of 16 colour palettes and maybe could get an acceptable 256 colour set of tiles (if needed) out of the combined colours in those 16 palettes, that is also a possibility.

#10436 - RaBBi - Thu Sep 04, 2003 8:09 pm

A big very thank to you, all guys, to try to find a way to realise that (while I've spend my time with a girl lol).

I will try those different ways, I think I had to learn a few more about REGs.

But when I'll be ok with that, I'll post here the way I finally use.

Very thank, I notice that once more cause the Ham community is not as cool and free and helpfull as you are ^^

In fact I think I'll use Ham functions/commands for very such easy things, but for tricks like this, I may have to use pure coding:)
_________________
Sorry for my poor english, but it would be worst for you to understand me if I speak in my native language, French ^^

#10458 - RaBBi - Fri Sep 05, 2003 4:38 pm

Hi!

As I promised in my precedent post, I tell you how I resolved my problem of mixing 256/16 colors tilesets/maps ^^

In fact, I didn't use coding tricks but simply a switch in gfx2gba.
This switch is -b that can specify what bank of the palette the tileset may use.

In my case, I would use BG0 as a "text display background" for my RPG.
All the dialogs will be drawn on it.
So I can specifiy that my fonts and dialog box tileset uses the bank 15 for example, if I'm sure that I don't use this bank for another.
In fact, I decided to reserve this last bank for it ^^

And HaM, the dev kit I use, don't make problem with it.

Hope that my switch trick, for the first time, can help some of you ^^
_________________
Sorry for my poor english, but it would be worst for you to understand me if I speak in my native language, French ^^