Fading colors

Palette fades
Palettes can be faded to white or black by respectively incrementing or decrementing each color component of each color individually. Of course, care has to be taken so that each value stops at $1F or 0.

Fading to a specific color can also be done this way, by comparing each actual components to the target ones and incrementing/decrementing them accordingly (see example code).

Simulated fades




Since it has the highest priority on the screen, the fix layer can be used to fade the underlaying display by using pre-dithered tiles. This can only be used if the fix doesn't have to show important information.

This is also used in Metal Slug 3 as transitions in between areas of certain levels (uses a sprite layer instead of the fix ?).

Color handling code
If not using pre-calculated palette tables for fades, each color component of each color needs to be modified.

RGB components can then be compared with a target palette in RAM and adjusted until they match, for example: