1.2 Color Gameboy Support


* Note: Before you can set the color attributes for a tile
you have to switch to the 2nd video-memory bank (VBK_REG=1).
The CGB can now address upto 512 tiles
(by use of BIT 3 from the attribute byte)


The attribute byte looks like this:

BIT 0-2: Palettenumber (0-7)
BIT 3 : Character Bank select
BIT 5 : Flip Tile Horizontal
BIT 6 : Flip Tile Vertical
BIT 7 : Background Priority


VBK_REG = 1; /* Use this before setting tile-attributes */
VBK_REG = 0; /* Use this before setting tile-offsets */
VBK_REG sets the Video Bank Register. When set to zero, it loads the
tile data into the background. When set to one, it loads the palette
data into the background. You're supposed to set the palette data
before you set the tile data.


void set_bkg_palette(UBYTE first_palette,UBYTE nb_palettes,UWORD *rgb_data);

set_bkg_palette loads the palette data into memory so the gameboy color
can access it. first_palette is the first palette to be loaded. nb_palettes
is the number of palettes to load. *rgb_data is a pointer to where the
palette data is located.
* Note : Never forget to set all 8 palettes after another
Itīs not safe to set individual palettes
* Note/Plug : Jason's Colors.h has the most common colors predefined for use
with gbdk projects.


void set_sprite_palette(UBYTE first_palette,UBYTE nb_palettes,UWORD *rgb_data);

set_sprite_palette loads the sprite palette into memory so the gameboy color
can access it. first_palette is the first palette to be loaded. nb_palettes
is the number of palettes to load. *rgb_data is a pointer to where the
palette data is located.
* Note : Never forget to set all 8 palettes after another
Itīs not safe to set individual palettes
* Note/Plug : Jason's Colors.h has the most common colors predefined for use
with gbdk projects.


/* GB type (GB, PGB, CGB) */
/* Read this byte to determine the type of Gameboy*/

extern UBYTE _cpu;

#define DMG_TYPE 0x01 /* Original GB or Super GB */
#define MGB_TYPE 0xFF /* Pocket GB or Super GB 2 */
#define CGB_TYPE 0x11 /* Color GB */

So if you want to be backwards compatible to the normal gameboy use this:

if(_cpu == 0x11) {
color-related material
}

where 0x11 can also be replaced with CGB_TYPE.