PAlib: Palette system

Main Page | Modules | File List | Globals | Search for

# Palette system

## Defines

#define | PA_LoadPal(palette, source)
| Load a 256 color palette in the Bg or Sprite palette of screen 0 or 1. Ex : PA_LoadPal(PALETTE_BG1, bg_pal);
#define | PA_LoadPal16(palette, n_palette, source) DMA_Copy((void*)source, (void*)(palette + (n_palette << 5)), 16, DMA_16NOW);
| Load a 16 color palette in the Bg or Sprite palette of screen 0 or 1. Ex : PA_LoadPal16(PALETTE_BG1, 4, bg_pal);
#define | PA_RGB(r, g, b) ((1 << 15) + (r) + ((g)<<5) + ((b)<<10))
| Convert Red, Green, and Blue color indexes into a number used in the palette system. Careful : the R, G, B values range from 0 to 31 on gba !
#define | PA_SetBgPalCol(screen, color_number, colorRGB) BG_PALETTE[color_number + (screen << 9)] = colorRGB
| Change the color of one of the main background palette colors. Not used anymore
#define | PA_AdjustCol(color, bright) color+= bright; if (color < 0) color = 0; if (color > 31) color = 31

## Functions

void | PA_LoadNormalBgPal (u8 screen, void *Pal)
void | PA_SetBrightness (u8 screen, s8 bright)
| Set the screen's brightness
void | PA_SetPalNeg (u32 palette)
| Set all the palette's color to negative. To undo this, simply negative again...
void | PA_SetPal16Neg (u32 palette, u8 n_palette)
| Set 16 color palette to negative. To undo this, simply negative again...
void | PA_InitSpriteExtPal (void)
| Initialise 16 palette mode for 256 color sprites. Done by default
void | PA_InitBgExtPal (void)
| Initialise 16 palette mode for 256 color backgrounds
void | PA_LoadSpritePal (u8 screen, u8 palette_number, void *palette)
| Load a 256 color palette for Sprites
void | PA_LoadBgPal (u8 screen, u16 bg_number, void *palette)
| Load a 256 color palette in the Background palettes
void | PA_LoadBgPalN (u8 screen, u8 bg_number, u8 pal_number, void *palette)
| Load a 256 color palette in a given Background's palette
void | PA_SetBgPalNCol (u8 screen, u8 bg_number, u8 pal_number, u8 color_number, u16 color)
| Change the color of one of the backgrounds' palettes' colors
void | PA_SetBgColor (u8 screen, u16 color)
| Change the background color of a given screen
void | PA_SetSpritePalCol (u8 screen, u8 pal_number, u8 color_number, u16 color)
| Change a color in a sprite palette
void | PA_CreatePalBright (u16 *pal, u16 *newpal, s8 bright)
void | PA_CreatePalTransition (u16 *pal, u16 *newpal, s8 level, u8 destr, u8 destg, u8 destb)

## Detailed Description

Load palettes, change palette colors, set the gamma, etc...

## Define Documentation

#define PA_LoadPal | ( | palette,
|  | source |  | ) |

Value:

    {\
           DMA_Copy((void*)source, (void*)palette, 256, DMA_16NOW);\
           if (palette == PAL_SPRITE0) PA_LoadSpritePal(0, 0, (void*)source);\
           if (palette == PAL_SPRITE1) PA_LoadSpritePal(1, 0, (void*)source);\
           if (palette == PAL_BG0) {u8 itemp; for (itemp = 0; itemp < 4; itemp++) PA_LoadBgPal(0, itemp, (void*)source);}\
           if (palette == PAL_BG1) {u8 itemp; for (itemp = 0; itemp < 4; itemp++) PA_LoadBgPal(1, itemp, (void*)source);}}

Load a 256 color palette in the Bg or Sprite palette of screen 0 or 1. Ex : PA_LoadPal(PALETTE_BG1, bg_pal);

Parameters:

  | palette | Set the Bg palette or Obj palette, screen 0 or 1 : PAL_BG0, PAL_SPRITE0, PAL_BG1, or PAL_SPRITE1
  | source | Palette name (ex : master_Palette)

#define PA_LoadPal16 | ( | palette,
|  | n_palette,
|  | source |  | ) | DMA_Copy((void*)source, (void*)(palette + (n_palette << 5)), 16, DMA_16NOW);

Load a 16 color palette in the Bg or Sprite palette of screen 0 or 1. Ex : PA_LoadPal16(PALETTE_BG1, 4, bg_pal);

Parameters:

  | palette | Set the Bg palette or Obj palette, screen 0 or 1 : PAL_BG0, PAL_SPRITE0, PAL_BG1, or PAL_SPRITE1
  | n_palette | Number of the 16 color palette to load (0-15)
  | source | Palette name (ex : master_Palette)

#define PA_RGB | ( | r,
|  | g,
|  | b |  | ) | ((1 << 15) + (r) + ((g)<<5) + ((b)<<10))

Convert Red, Green, and Blue color indexes into a number used in the palette system. Careful : the R, G, B values range from 0 to 31 on gba !

Parameters:

  | r | Red (0-31)
  | g | Green (0-31)
  | b | Blue (0-31)

#define PA_SetBgPalCol | ( | screen,
|  | color_number,
|  | colorRGB |  | ) | BG_PALETTE[color_number + (screen << 9)] = colorRGB

Change the color of one of the main background palette colors. Not used anymore

Parameters:

  | screen | Screen...
  | color_number | Color number in palette (0-255)
  | colorRGB | RGB value, like PA_RGB(31, 31, 31) for white

## Function Documentation

void PA_LoadBgPal | ( | u8 | screen,
|  | u16 | bg_number,
|  | void * | palette
| ) | `[inline]`

Load a 256 color palette in the Background palettes

Parameters:

  | screen | Screen...
  | bg_number | Background number (0-3)
  | palette | Palette to load ((void*)palette_name)

void PA_LoadBgPalN | ( | u8 | screen,
|  | u8 | bg_number,
|  | u8 | pal_number,
|  | void * | palette
| ) |

Load a 256 color palette in a given Background's palette

Parameters:

  | screen | Screen...
  | bg_number | Background number (0-3)
  | pal_number | Palette number (0-15)
  | palette | Palette to load ((void*)palette_name)

void PA_LoadSpritePal | ( | u8 | screen,
|  | u8 | palette_number,
|  | void * | palette
| ) | `[inline]`

Load a 256 color palette for Sprites

Parameters:

  | screen | Screen...
  | palette_number | Palette number (0-15)
  | palette | Palette to load ((void*)palette_name)

inline void PA_SetBgColor | ( | u8 | screen,
|  | u16 | color
| ) | `[inline]`

Change the background color of a given screen

Parameters:

  | screen | Screen...
  | color | RGB value, like PA_RGB(31, 31, 31) for white

void PA_SetBgPalNCol | ( | u8 | screen,
|  | u8 | bg_number,
|  | u8 | pal_number,
|  | u8 | color_number,
|  | u16 | color
| ) |

Change the color of one of the backgrounds' palettes' colors

Parameters:

  | screen | Screen...
  | bg_number | Background number (0-3)
  | pal_number | Palette number (0-15). Leave to 0 if unsure
  | color_number | Color number in palette (0-255)
  | color | RGB value, like PA_RGB(31, 31, 31) for white

void PA_SetBrightness | ( | u8 | screen,
|  | s8 | bright
| ) |

Set the screen's brightness

Parameters:

  | screen | Chose de screen (0 or 1)
  | bright | Brightness level, from -32 to 32, 0 being neutral

inline void PA_SetPal16Neg | ( | u32 | palette,
|  | u8 | n_palette
| ) | `[inline]`

Set 16 color palette to negative. To undo this, simply negative again...

Parameters:

  | palette | Set the Bg palette or Obj palette, screen 0 or 1 : PAL_BG0, PAL_SPRITE0, PAL_BG1, or PAL_SPRITE1
  | n_palette | Number of the 16 color palette (0-15)

inline void PA_SetPalNeg | ( | u32 | palette | ) | `[inline]`

Set all the palette's color to negative. To undo this, simply negative again...

Parameters:

  | palette | Set the Bg palette or Obj palette, screen 0 or 1 : PAL_BG0, PAL_SPRITE0, PAL_BG1, or PAL_SPRITE1

void PA_SetSpritePalCol | ( | u8 | screen,
|  | u8 | pal_number,
|  | u8 | color_number,
|  | u16 | color
| ) |

Change a color in a sprite palette

Parameters:

  | screen | Screen...
  | pal_number | Palette number
  | color_number | Color in the palette
  | color | Color (given by PA_RGB...)