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.

#1 2016-12-24 02:41:47

MineRobber
New member
Registered: 2016-12-24
Posts: 3

GBDK color support not working

The builtin colors in GBDK (in gb/cgb.h) don't work.

See:

https://i.imgur.com/1leBpPx.png

(left image is the image on the original site, right image is built version of the same ROM loaded in BGB)

Are there any workarounds, or will my games just have to not be in color?

Offline

 

#2 2016-12-24 05:05:26

nitro2k01
Administrator
Registered: 2008-02-22
Posts: 249

Re: GBDK color support not working

The example does have color, just incorrect color. It seems like that example was written without an understanding of how colors work on GBC. Or maybe Virtual Gameboy has incorrect emulation and the demo was written to work in VGB. I don't know how or why. The example also has a quite convoluted ordering of the color bars as seen in the array bar_a. The colors are given as constants in the code, so as an example, the code gives no reference to how you would actually generate a given color.

Here's a macro I just wrote and an example on how to use it.

Code:

// Values must be in the range 0-31! For example, CGB_PAL(31,31,31) is white, CGB_PAL(0,0,0) is black, and CGB_PAL(0,31,0) is green.
#define CGB_PAL(r,g,b) (((b)&31)<<10 | ((g)&31)<<5 | ((r)&31))

const UWORD palette_table[] =
{
  CGB_PAL(31,31,31), CGB_PAL(24,24,24), CGB_PAL(16,16,16), CGB_PAL(8,8,8),    /* Grays */
  CGB_PAL(31,31,0),  CGB_PAL(24,24,0),  CGB_PAL(16,16,0),  CGB_PAL(8,8,0),  /* Yellows */
};

// Later, in main or somewhere else:
  set_bkg_palette( 0, 1, &palette_table[0] );
  set_bkg_palette( 1, 1, &palette_table[4] );

Looking further at this: Actually, as for what's wrong with the code, it seems like the colors are transferred in the wrong order from the table. It transfers &bar_p[0] to palette index 7 and &bar_p[28] (the last palette in the table) to palette index 0. Again, no idea why.
It seems like all you would have to do is reverse the order of the transfer, ie the first thing in main. The colors will then be correct, albeit a bit washed out. This is to be expected since BGB emulates what it would look like on a real GBC, and the GBC screen can't do better than this.

https://i.imgur.com/bQ8iyWL.png

Incorrect:

Code:

  /* Transfer color palettes */
  set_bkg_palette( 7, 1, &bar_p[0] );
  set_bkg_palette( 6, 1, &bar_p[4] );
  set_bkg_palette( 5, 1, &bar_p[8] );
  set_bkg_palette( 4, 1, &bar_p[12] );
  set_bkg_palette( 3, 1, &bar_p[16] );
  set_bkg_palette( 2, 1, &bar_p[20] );
  set_bkg_palette( 1, 1, &bar_p[24] );
  set_bkg_palette( 0, 1, &bar_p[28] );

Correct:

Code:

  /* Transfer color palettes */
  set_bkg_palette( 0, 1, &bar_p[0] );
  set_bkg_palette( 1, 1, &bar_p[4] );
  set_bkg_palette( 2, 1, &bar_p[8] );
  set_bkg_palette( 3, 1, &bar_p[12] );
  set_bkg_palette( 4, 1, &bar_p[16] );
  set_bkg_palette( 5, 1, &bar_p[20] );
  set_bkg_palette( 6, 1, &bar_p[24] );
  set_bkg_palette( 7, 1, &bar_p[28] );

Blog: Gameboy Genius
"A journey of a thousand miles begins with one small step"
Old Chinese Proverb

Offline

 

#3 2016-12-24 14:38:47

MineRobber
New member
Registered: 2016-12-24
Posts: 3

Re: GBDK color support not working

This doesn't seem to work for me.

Palette definition (using your palette macro):

Code:

const UWORD palette[] = {
    0,CGB_PAL(0,0,0),CGB_PAL(0,31,31),CGB_PAL(3,3,31),
};

Code for loading palette (if on GBC, using the same codebase for both the GB version and the GBC version):

Code:

if (HARDWARE_TYPE == 0x80U) {
    set_sprite_palette(0,1,palette);
    set_sprite_prop(0,0);
}

This doesn't work,and leads to:
https://i.imgur.com/mnVwpdh.png

What am I doing wrong, if the color support works correctly in the colorbar example?

Offline

 

#4 2016-12-24 17:14:53

nitro2k01
Administrator
Registered: 2008-02-22
Posts: 249

Re: GBDK color support not working

I'm not really used to GBDK (I do 100% asm for Gameboy) so I'm not sure what could be wrong. First as a sanity check, can you confirm that the code for checking the hardware type is correct, ie printing something from within the if so you know that that code path is actually taken? In BGB's debugger, in the VRAM viewer, can you show me the palettes tab, and the OAM tab while hovering the sprite in question? Otherwise, can you show me the source code or a compiled ROM?

Also, can you confirm whether the proposed change for the colorbar demo works on your end?


Blog: Gameboy Genius
"A journey of a thousand miles begins with one small step"
Old Chinese Proverb

Offline

 

#5 2016-12-27 16:09:56

MineRobber
New member
Registered: 2016-12-24
Posts: 3

Re: GBDK color support not working

Sorry for the late response. The colorbar demo DOES work.

I don't think the hardware check was the issue, but I removed it (splitting my codebase into 2 main files) and now it works.

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson