Gameboy Development Forum

Discussion about software development for the old-school Gameboys, ranging from the "Gray brick" to Gameboy Color
(Launched in 2008)

You are not logged in.

Ads

#1 2017-06-15 00:06:36

turboboy215
Member
Registered: 2015-07-30
Posts: 15

How to add colors to background tilemap (not using GBTD/GBMB)?

After a year and a half of inactivity, I've finally decided to restart GB/GBC development using GBDK and many other tools. With some help from online for some things (also with some trial and error), I've been able to successfully compile several demos, and there's one that I've finished for the classic Game Boy, but I'm having trouble getting it to work with a proper color set.

Basically, my GBC demo shows a picture and plays a sample. This picture was converted using a (rather inefficient, since it seems unnecessary to have to use multiple programs to do it) method using GBTK preview to render an image fit for the Game Boy, but since I didn't have an option to optimize tiles in that program, I then saved it as a BMP and converted it to an 8-color PCX using GIMP and in PCX2GB, converted it to a pair of tile-optimized C files which I slightly modified to work with my code (adding variables and such). I then got it to display properly on the Game Boy, and I then added a PCM sample which I (through some trial and error) got to play properly as well.
However, I'm currently trying to make a Game Boy Color version of the demo, but I've been having trouble with adding colors to it, even a single palette.

Here is my code:

#include <gb/gb.h>
#include <gb/cgb.h>
#include <gb/sample.h>
#include <stdio.h>
#include "sjaypic.c"
#include "sjaypic.map"
#include "sjaycal.c"
//extern UBYTE call[];

UWORD jayPalette[] = {
0, RGB_RED, RGB_ORANGE, RGB_YELLOW,
0, RGB_GREEN, RGB_BLUE, RGB_PURPLE,
0, RGB_BLACK, RGB_DARKGRAY, RGB_WHITE
};

void main()
{
    //Load up the tile data
        set_bkg_data(0,255,sjaytiledata);
    set_bkg_palette(0, 3, jayPalette);

    //Switch to VRAM
    VBK_REG = 1;

    //Set screen x,y pos to 0,0 and draw the map 20,18 (size of the screen)
    set_bkg_tiles(0, 0, 20, 18, sjaytilemap);

    //Show the background
    SHOW_BKG;

    //Turn the display on
    DISPLAY_ON;
    play_sample(sjaycall, 18034 / 32);

       
}

Here are the entire program files, with a ROM of the current build with a problem:
https://drive.google.com/file/d/0B_zYoz … sp=sharing


The problem:


When my GBC demo version is run in classic GB mode, it looks just fine:
https://drive.google.com/open?id=0B_zYo … Up5S0VlVzg

But in GBC mode, it looks completely different, with just a bunch of random black or white tiles:
https://drive.google.com/open?id=0B_zYo … 0UxNGZ2QVE

I honestly don't know how I would properly color the entire background, and I would also like to know how to set a palette to each individual background tile. Sprites work just fine; it's the background tiles that I am having problems with. Every example code that uses color background tiles I can find uses GBTD and GBMB, which I will only use for tilesets, and not full-screen images. Can someone please tell me what I should do?

Offline

 

#2 2017-06-15 07:16:20

ISSOtm
Member
From: Somewhere in Echo RAM
Registered: 2017-04-18
Posts: 160
Website

Re: How to add colors to background tilemap (not using GBTD/GBMB)?

Lemme tell you I know nothing about C for the GB, so I can't give you any code.

But, you seem to switch to VRAM bank 1 before writing your background.
Actually, you will want to switch to bank 0.

At a given address, the byte in bank 0 identifies which tile you want there, and the byte in bank 1 gives its metadata. See there.

I think you will want to do something like this :

Code:

VBK_REG = 1;
set_bkg_tiles(0, 0, 20, 18, sjaymetatiles); // Set attributes (metadata)
VBK_REG = 0;
set_bkg_tiles(0, 0, 20, 18, sjaytilemap); // Draw the map

Attributes allow you to set color, tile bank, and flipping. You can see those in BGB :
https://puu.sh/wkGLH/30f3fa488c.png


The French Lord Of Laziness.
Legend of Zelda and Undertale fan, I also tend to break Pokémon R/B/Y a little too much.

Twitter | Me on GCL | Discord : ISSOtm#9015 | Skype : isso.tm (I don't login anymore)

Offline

 

#3 2017-06-15 07:51:50

tmk
Member
Registered: 2017-05-01
Posts: 63
Website

Re: How to add colors to background tilemap (not using GBTD/GBMB)?

Same as ISSOtm, accidentally found this while browsing for totally different stuff:

http://belial.blarzwurst.de/gb/gbdok.txt wrote:

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

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson