Table of Contents

Class Palettes

Namespace
GB
Assembly
GBSharp.Framework.dll

Colour, on both machines.

public static class Palettes
Inheritance
Palettes
Inherited Members

Remarks

The two machines work differently and this class does not pretend otherwise. An original Game Boy has one background palette and two sprite palettes, each mapping the four values in a tile to four fixed shades. A Game Boy Color has eight background and eight sprite palettes of four real colours, chosen per tile through the attribute map.

A game that runs on both sets the shades unconditionally and the colours behind IsColorHardware: the colour calls do nothing on a DMG, but the data they would have read still costs ROM.

Fields

ColorPaletteCount

Background palettes available on Game Boy Color.

public const byte ColorPaletteCount = 8

Field Value

byte

ColorsPerPalette

Colours in one palette, on either machine.

public const byte ColorsPerPalette = 4

Field Value

byte

Properties

BackgroundRaw

The raw background palette register, for code that wants it.

public static byte BackgroundRaw { get; set; }

Property Value

byte

IsColorHardware

True when running on Game Boy Color hardware.

[Native("gbs_is_color")]
public static bool IsColorHardware { get; }

Property Value

bool

Methods

LoadBackgroundColors(byte, byte, ushort[])

Loads Game Boy Color background palettes, four colours each.

[Native("gbs_set_bkg_palette")]
public static void LoadBackgroundColors(byte firstPalette, byte count, ushort[] colors)

Parameters

firstPalette byte
count byte
colors ushort[]

LoadSpriteColors(byte, byte, ushort[])

Loads Game Boy Color sprite palettes, four colours each.

[Native("gbs_set_sprite_palette")]
public static void LoadSpriteColors(byte firstPalette, byte count, ushort[] colors)

Parameters

firstPalette byte
count byte
colors ushort[]

Rgb(byte, byte, byte)

Builds a Game Boy Color colour from three 5-bit channels.

[Native("gbs_rgb")]
public static ushort Rgb(byte r, byte g, byte b)

Parameters

r byte
g byte
b byte

Returns

ushort

Remarks

Each channel runs 0-31, not 0-255. Folds to a constant when the arguments are literals, so a palette written inline costs nothing at runtime.

SetBackgroundShades(Shade, Shade, Shade, Shade)

Maps the four tile values to shades, for the background.

[Native("gbs_set_bkg_shades")]
public static void SetBackgroundShades(Shade c0, Shade c1, Shade c2, Shade c3)

Parameters

c0 Shade
c1 Shade
c2 Shade
c3 Shade

SetSpriteShades(byte, Shade, Shade, Shade, Shade)

Maps the four tile values to shades, for one of the two sprite palettes.

[Native("gbs_set_sprite_shades")]
public static void SetSpriteShades(byte palette, Shade c0, Shade c1, Shade c2, Shade c3)

Parameters

palette byte
c0 Shade
c1 Shade
c2 Shade
c3 Shade

Remarks

Value 0 is always transparent for sprites, so c0 is never drawn. Sprites choose between palette 0 and 1 through UseSecondPalette.

UseDefaultColors()

Restores GBDK's default colour palettes.

[Native("set_default_palette")]
public static void UseDefaultColors()