sgdk: pal.h File Reference

sgdk

- Main Page
- Related Pages
- Classes
- Files

- File List
- File Members

Classes | Defines | Functions | Variables
pal.h File Reference

Palette support (herited from vdp_pal.h unit) More...

`#include "config.h"`
`#include "types.h"`
`#include "dma.h"`

Go to the source code of this file.

## Classes

struct | Palette
| Palette structure contains color data. More...

## Defines

#define | VDPPALETTE_REDSFT 1
#define | VDPPALETTE_GREENSFT 5
#define | VDPPALETTE_BLUESFT 9
#define | VDPPALETTE_REDMASK 0x000E
#define | VDPPALETTE_GREENMASK 0x00E0
#define | VDPPALETTE_BLUEMASK 0x0E00
#define | VDPPALETTE_COLORMASK 0x0EEE
#define | RGB24_TO_VDPCOLOR(color) (((color >> ((2 * 8) + 4)) & VDPPALETTE_REDMASK) | ((color >> ((1 * 4) + 4)) & VDPPALETTE_GREENMASK) | ((color << 4) & VDPPALETTE_BLUEMASK))
| Convert a RGB 24 bits color to VDP color.

## Functions

u16 | PAL_getColor (u16 index)
| Returns RGB color value from CRAM for the specified palette entry.
void | PAL_getColors (u16 index, u16 *dest, u16 count)
| Read count RGB colors from CRAM starting at specified index and store them in specified destination palette.
void | PAL_getPalette (u16 numPal, u16 *dest)
| Get a complete palette (16 colors) from CRAM.
void | PAL_setColor (u16 index, u16 value)
| Set RGB color into CRAM for the specified palette entry.
void | PAL_setColors (u16 index, const u16 *pal, u16 count, TransferMethod tm)
| Write RGB colors into CRAM for the specified palette entries.
void | PAL_setPaletteColors (u16 index, const Palette *pal, TransferMethod tm)
| Write the given Palette RGB colors into CRAM for the specified palette entries.
void | PAL_setPalette (u16 numPal, const u16 *pal, TransferMethod tm)
| Set a complete palette (16 colors) into CRAM.
void | PAL_setColorsDMA (u16 index, const u16 *pal, u16 count)
void | PAL_setPaletteColorsDMA (u16 index, const Palette *pal)
void | PAL_setPaletteDMA (u16 numPal, const u16 *pal)
bool | PAL_initFade (u16 fromCol, u16 toCol, const u16 *palSrc, const u16 *palDst, u16 numFrame)
bool | PAL_doFadeStep ()
void | PAL_fade (u16 fromCol, u16 toCol, const u16 *palSrc, const u16 *palDst, u16 numFrame, bool async)
| General palette fading effect.
void | PAL_fadeTo (u16 fromCol, u16 toCol, const u16 *pal, u16 numFrame, bool async)
| Fade current color palette to specified one.
void | PAL_fadeOut (u16 fromCol, u16 toCol, u16 numFrame, bool async)
| Fade out (current color to black) effect.
void | PAL_fadeIn (u16 fromCol, u16 toCol, const u16 *pal, u16 numFrame, bool async)
| Fade in (black to specified color) effect.
void | PAL_fadePalette (u16 numPal, const u16 *palSrc, const u16 *palDst, u16 numFrame, bool async)
| Do palette fade effect.
void | PAL_fadeToPalette (u16 numPal, const u16 *pal, u16 numFrame, bool async)
| Fade current palette to specified one.
void | PAL_fadeOutPalette (u16 numPal, u16 numFrame, bool async)
| Fade out (current color to black) effect.
void | PAL_fadeInPalette (u16 numPal, const u16 *pal, u16 numFrame, bool async)
| Fade in (black to specified color) effect.
void | PAL_fadeAll (const u16 *palSrc, const u16 *palDst, u16 numFrame, bool async)
| Global palette fading effect.
void | PAL_fadeToAll (const u16 *pal, u16 numFrame, bool async)
| Palettes fade to specified one.
void | PAL_fadeOutAll (u16 numFrame, bool async)
| Fade out (current color to black) effect.
void | PAL_fadeInAll (const u16 *pal, u16 numFrame, bool async)
| Fade in (black to specified color) effect.
bool | PAL_isDoingFade ()
| Returns TRUE if currently doing a asynchronous fade operation.
void | PAL_waitFadeCompletion ()
| Wait for palette fading operation to complete (for asynchrone fading).
void | PAL_interruptFade ()
| Interrupt any asynchronous palette fading effect.

## Variables

const u16 *const | palette_black
| Default black palette.
const u16 | palette_grey [16]
| Default grey palette.
const u16 | palette_red [16]
| Default red palette.
const u16 | palette_green [16]
| Default green palette.
const u16 | palette_blue [16]
| Default blue palette.
u16 | fadeCurrentPal [64]
| Current fade palette.
u16 | fadeEndPal [64]
| End fade palette.

## Detailed Description

Palette support (herited from vdp_pal.h unit)

Author:
  Stephane Dallongeville

Date:
  06/2019

This unit provides methods to manipulate the VDP Color Palette.
The Sega Genesis VDP has 4 palettes of 16 colors.
Color is defined with 3 bits for each component : xxxxBBBxGGGxRRRx

## Define Documentation

#define RGB24_TO_VDPCOLOR | ( |  | color | ) | (((color >> ((2 * 8) + 4)) & VDPPALETTE_REDMASK) | ((color >> ((1 * 4) + 4)) & VDPPALETTE_GREENMASK) | ((color << 4) & VDPPALETTE_BLUEMASK))

Convert a RGB 24 bits color to VDP color.

Parameters:

  color | RGB 24 bits color

## Function Documentation

void PAL_fade | ( | u16 | fromCol,
|  | u16 | toCol,
|  | const u16 * | palSrc,
|  | const u16 * | palDst,
|  | u16 | numFrame,
|  | bool | async
| ) |  |

General palette fading effect.

Parameters:

  fromCol | Start color index for the fade effect (0-63).
  toCol | End color index for the fade effect (0-63 and >= fromCol).
  palSrc | Fade departure palette.
  palDst | Fade arrival palette.
  numFrame | Duration of palette fading in number of frame.
  async | Async process. If set the function return immediatly else the function wait for fading to complete.

This function does general palette fading effect.
The fade operation is done to all palette entries between 'fromCol' and 'toCol'.
Example: fading to all palette entries --> fromCol = 0 and toCol = 63

void PAL_fadeAll | ( | const u16 * | palSrc,
|  | const u16 * | palDst,
|  | u16 | numFrame,
|  | bool | async
| ) |  |

Global palette fading effect.

Parameters:

  palSrc | Fade departure palette (should contains 64 colors entries).
  palDst | Fade arrival palette (should contains 64 colors entries).
  numFrame | Duration of palette fading in number of frame.
  async | Async process. If set the function return immediatly else the function wait for fading to complete.

The fade operation is done to all palette entries.

void PAL_fadeIn | ( | u16 | fromCol,
|  | u16 | toCol,
|  | const u16 * | pal,
|  | u16 | numFrame,
|  | bool | async
| ) |  |

Fade in (black to specified color) effect.

Parameters:

  fromCol | Start color index for the fade operation (0-63).
  toCol | End color index for the fade operation (0-63 and >= fromCol).
  pal | Fade arrival palette.
  numFrame | Duration of palette fading in number of frame.
  async | Async process. If set the function return immediatly else the function wait for fading to complete.

See PAL_fade() for more informations.

void PAL_fadeInAll | ( | const u16 * | pal,
|  | u16 | numFrame,
|  | bool | async
| ) |  |

Fade in (black to specified color) effect.

Parameters:

  pal | Fade arrival palette (should contains 64 entries).
  numFrame | Duration of palette fading in number of frame.
  async | Async process. If set the function return immediatly else the function wait for fading to complete.

The fade operation is done to all palette entries.
See PAL_fadeAll().

void PAL_fadeInPalette | ( | u16 | numPal,
|  | const u16 * | pal,
|  | u16 | numFrame,
|  | bool | async
| ) |  |

Fade in (black to specified color) effect.

Parameters:

  numPal | Palette to fade.
  pal | Fade arrival palette.
  numFrame | Duration of palette fading in number of frame.
  async | Async process. If set the function return immediatly else the function wait for fading to complete.

See PAL_fadePal() for more informations.

void PAL_fadeOut | ( | u16 | fromCol,
|  | u16 | toCol,
|  | u16 | numFrame,
|  | bool | async
| ) |  |

Fade out (current color to black) effect.

Parameters:

  fromCol | Start color index for the fade operation (0-63).
  toCol | End color index for the fade operation (0-63 and >= fromCol).
  numFrame | Duration of palette fading in number of frame.
  async | Async process. If set the function return immediatly else the function wait for fading to complete.

See PAL_fade() for more informations.

void PAL_fadeOutAll | ( | u16 | numFrame,
|  | bool | async
| ) |  |

Fade out (current color to black) effect.

Parameters:

  numFrame | Duration of palette fading in number of frame.
  async | Async process. If set the function return immediatly else the function wait for fading to complete.

The fade operation is done to all palette entries.
See PAL_fadeAll().

void PAL_fadeOutPalette | ( | u16 | numPal,
|  | u16 | numFrame,
|  | bool | async
| ) |  |

Fade out (current color to black) effect.

Parameters:

  numPal | Palette to fade.
  numFrame | Duration of palette fading in number of frame.
  async | Async process. If set the function return immediatly else the function wait for fading to complete.

See PAL_fadePal() for more informations.

void PAL_fadePalette | ( | u16 | numPal,
|  | const u16 * | palSrc,
|  | const u16 * | palDst,
|  | u16 | numFrame,
|  | bool | async
| ) |  |

Do palette fade effect.

Parameters:

  numPal | Palette number to use for fade effect.
  palSrc | Fade departure palette.
  palDst | Fade arrival palette.
  numFrame | Duration of palette fading in number of frame.
  async | Async process. If set the function return immediatly else the function wait for fading to complete.

The fade operation is done to all specified palette entries.
See PAL_fade() for more informations.

void PAL_fadeTo | ( | u16 | fromCol,
|  | u16 | toCol,
|  | const u16 * | pal,
|  | u16 | numFrame,
|  | bool | async
| ) |  |

Fade current color palette to specified one.

Parameters:

  fromCol | Start color index for the fade operation (0-63).
  toCol | End color index for the fade operation (0-63 and >= fromCol).
  pal | Fade arrival palette.
  numFrame | Duration of palette fading in number of frame.
  async | Async process. If set the function return immediatly else the function wait for fading to complete.

See PAL_fade() for more informations.

void PAL_fadeToAll | ( | const u16 * | pal,
|  | u16 | numFrame,
|  | bool | async
| ) |  |

Palettes fade to specified one.

Parameters:

  pal | Fade arrival palette (should contains 64 entries).
  numFrame | Duration of palette fading in number of frame.
  async | Async process. If set the function return immediatly else the function wait for fading to complete.

The fade operation is done to all palette entries.
See PAL_fadeAll().

void PAL_fadeToPalette | ( | u16 | numPal,
|  | const u16 * | pal,
|  | u16 | numFrame,
|  | bool | async
| ) |  |

Fade current palette to specified one.

Parameters:

  numPal | Palette to fade.
  pal | Fade arrival palette.
  numFrame | Duration of palette fading in number of frame.
  async | Async process. If set the function return immediatly else the function wait for fading to complete.

See PAL_fadePal() for more informations.

u16 PAL_getColor | ( | u16 | index | ) |

Returns RGB color value from CRAM for the specified palette entry.

Parameters:

  index | Color index (0-63).

Returns:
  RGB intensity for the specified color index.

void PAL_getColors | ( | u16 | index,
|  | u16 * | dest,
|  | u16 | count
| ) |  |

Read count RGB colors from CRAM starting at specified index and store them in specified destination palette.

Parameters:

  index | Color index where start to read (0-63).
  dest | Destination palette where to write read the RGB color values (should be large enough to store count colors).
  count | Number of color to get.

void PAL_getPalette | ( | u16 | numPal,
|  | u16 * | dest
| ) |  |

Get a complete palette (16 colors) from CRAM.

Parameters:

  numPal | Palette number: PAL0, PAL1, PAL2 or PAL3
  dest | Destination where to write palette colors (should be 16 words long at least)

void PAL_setColor | ( | u16 | index,
|  | u16 | value
| ) |  |

Set RGB color into CRAM for the specified palette entry.

Parameters:

  index | Color index to set (0-63).
  value | RGB intensity to set at the specified color index.

void PAL_setColors | ( | u16 | index,
|  | const u16 * | pal,
|  | u16 | count,
|  | TransferMethod | tm
| ) |  |

Write RGB colors into CRAM for the specified palette entries.

Parameters:

  index | Color index where to start to write (0-63).
  pal | RGB intensities to set.
  count | Number of color to set.

  tm

  Transfer method.
  Accepted values are:
  - CPU
  - DMA
  - DMA_QUEUE
  - DMA_QUEUE_COPY

void PAL_setColorsDMA | ( | u16 | index,
|  | const u16 * | pal,
|  | u16 | count
| ) |  |

Deprecated:
  Use PAL_setColors(..) instead

void PAL_setPalette | ( | u16 | numPal,
|  | const u16 * | pal,
|  | TransferMethod | tm
| ) |  |

Set a complete palette (16 colors) into CRAM.

Parameters:

  numPal | Palette number: PAL0, PAL1, PAL2 or PAL3
  pal | Source palette.

  tm

  Transfer method.
  Accepted values are:
  - CPU
  - DMA
  - DMA_QUEUE
  - DMA_QUEUE_COPY

void PAL_setPaletteColors | ( | u16 | index,
|  | const Palette * | pal,
|  | TransferMethod | tm
| ) |  |

Write the given Palette RGB colors into CRAM for the specified palette entries.

Parameters:

  index | Color index where to start to write (0-63).
  pal | Source Palette.

  tm

  Transfer method.
  Accepted values are:
  - CPU
  - DMA
  - DMA_QUEUE
  - DMA_QUEUE_COPY

void PAL_setPaletteColorsDMA | ( | u16 | index,
|  | const Palette * | pal
| ) |  |

Deprecated:
  Use PAL_setPaletteColors(..) instead

void PAL_setPaletteDMA | ( | u16 | numPal,
|  | const u16 * | pal
| ) |  |

Deprecated:
  Use PAL_setPalette(..) instead

All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines