This page looks best with JavaScript enabled

GameBoy Dev07: Technicolor rainbow

 ·  🎃 kr0m

It is recommended to read the previous articles to better understand this one:


In the previous article, we learned how to manipulate the GameBoy’s color palette. This time, we will create a program that shows us all possible combinations. The transition is a bit fast, but we can change the value of the delay to make it slower or pause the emulator itself and look at the color combination of the palette to know which BGP_REG configuration we should assign.

The code is as follows:

vi 07.c
#include <gb/gb.h>
#include <stdio.h>
#include "CyberPunkTiles.c"
#include "CyberPunkMap.c"

UINT8 i;

void technicolor_rainbow(){
    // Default palette: 11 10 01 00 -> E4
    // 2^8: 256
    for(i=0; i<255; i++){
        BGP_REG = i;
        delay(100);
    }
}

void main(){
    // grep TILESET_TILE_COUNT CyberPunkTiles.h
    set_bkg_data(0, 106, TILESET);

    // grep TILEMAP_ CyberPunkMap.h
    set_bkg_tiles(0, 0, 20, 18, TILEMAP);

    SHOW_BKG;
    DISPLAY_ON;

    while(1){
        BGP_REG = 0xE4;
        waitpad(J_START);
        technicolor_rainbow();
        delay(100);
    }
}

We compile it:

~/GBDEV/gbdk/bin/lcc 07.c -o 07.gb

We load the ROM into the emulator and every time we press Start, we will see the effect:

If you liked the article, you can treat me to a RedBull here