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 2018-02-10 05:32:10

esotericsean
Member
From: Buena Park, CA
Registered: 2018-01-14
Posts: 16
Website

Trouble With Backgrounds

Hey guys,

So I had everything previously working and now I'm trying to make the simplest thing work and... it's being weird.

I have a tile set and a map. The tiles are 8x8 and the map is 20x18. I've included the .c files for them in the header.

My code is:

Code:

set_bkg_data (0, 110, esomods3);
set_bkg_tiles (0, 0, 20, 18, esomods3map);
    
SHOW_BKG;
DISPLAY_ON;

This is what it's supposed to look like and what I'm getting: https://imgur.com/a/oVtCs

What am I doing wrong? It looks like it's importing the tile data incorrectly into VRAM.

Sean

Offline

 

#2 2018-02-10 09:44:34

tobiasvl
Member
From: Norway
Registered: 2017-10-19
Posts: 26

Re: Trouble With Backgrounds

init() does call "DISPLAY_ON" after the tiles have been imported, and it's obviously fine to import the tiles to VRAM while the display is off... But it doesn't look like you ever turn the display off before transferring the tiles?

It would also be fine if you imported the tiles to VRAM during V-blank, but you don't call wait_vbl_done() before you transfer the tiles.

But I don't know anything about GBDK, so if set_bkg_data() actually does wait until V-blank before transferring the tiles, I have no idea what could be causing it. But how are you debugging this? Are you using BGB with all troubleshooting options turned on? It should let you know if you're trying to access VRAM when you shouldn't, for example. You can also set breakpoints, so you can step through single instructions to see exactly what it writes to VRAM, where, and when.

Last edited by tobiasvl (2018-02-10 11:37:56)


Discord: tobiasvl#6844 | GitHub: tobiasvl

Offline

 

#3 2018-02-10 12:48:17

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

Re: Trouble With Backgrounds

You need to load palettes, and it's done way differently on the CGB than on the DMG. I have no idea how it's done with GBDK, but in ASM it's extremely simple : you just select a palette with BCPS, then write the colors to BCPD.
You can check the loaded palettes in BGB's VRAM viewer, "Palettes" tab.

Oh, and, by the way -- on the CGB, SHOW_BKG doesn't do display the background, it enables BG priority.


(Aparté : this is why I wouldn't recommend GBDK, you have no clue what things actually do... plus, for such a big project, you're going to hit banking very soon, and that's a pain in the ass with GBDK.)

Last edited by ISSOtm (2018-02-10 12:49:55)


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

 

#4 2018-02-10 13:36:08

esotericsean
Member
From: Buena Park, CA
Registered: 2018-01-14
Posts: 16
Website

Re: Trouble With Backgrounds

Thanks guys, you're right in that I don't fully understand what's happening. I guess I just feel overwhelmed in trying to learn/understand it all. I am using BGB with the debugger and VRAM viewer.

ISSOtm, I think you're right that it's not loading a palette: https://i.imgur.com/Ka4cS8j.png

Offline

 

#5 2018-02-10 14:42:13

esotericsean
Member
From: Buena Park, CA
Registered: 2018-01-14
Posts: 16
Website

Re: Trouble With Backgrounds

Progress! I got color palettes working. But it's definitely loading the tiles in the wrong order or something.

It even seems to be loading duplicate tiles. I guess I need to read about how VRAM works.

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

Offline

 

#6 2018-02-10 17:08:53

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

Re: Trouble With Backgrounds

Well, if you were using ASM, I could help you, but I can't do anything for you.
I never understood how GBDK's functions even worked.

I'd really advise against using GBDK at all, since ASM isn't that complicated, and GBDK appears to be hardly suited for large projects - you'll have as much difficulties working around its limitations than you would with ASM, tbh.
I made a writeup on whether to use one or the other, if you want to read.

Last edited by ISSOtm (2018-02-10 17:18:36)


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

 

#7 2018-02-10 18:01:16

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

Re: Trouble With Backgrounds

To be honest, just go with GBDK.
GBDK is a pain sometimes, but contrary to what ISSOtm said, GBDK is much, MUCH easier to learn than assembly by a long shot. Assembly is actually extremely complicated, even though it does perform better. I personally don't see how some people actually make sense of all those register addresses loaded - almost as much as how people make sense of 0s and 1s (i.e. binary). I tried once and I FAILED. I decided assembly was way too complicated for me, at least for now. But I do know a little GBDK, but I'm still pretty new.
Now I'm not starting an argument or anything, but if you want to use GBDK, it's just fine - you don't have to do exactly as ISSOtm said.
As for your problem, esocentricsean, I had that exact same issue, or at least a similar issue, while trying to display my first picture a while back. Try adding this line before you set_bkg_tiles:

VBK_REG = 0;

Offline

 

#8 2018-02-10 18:17:11

esotericsean
Member
From: Buena Park, CA
Registered: 2018-01-14
Posts: 16
Website

Re: Trouble With Backgrounds

I read your write up, ISSO. Lots of good info. At the very least, I'm going to try ASM just to see what it's like, maybe write a Hello World or something.. I shouldn't just keep saying it's too difficult without even knowing what the code looks like.

Thanks turboboy. This is what my current init() looks like:

Code:

    set_bkg_palette (0, 32, &eso_p[0]);
    
    set_bkg_data (0, 110, esomods3);
    
    VBK_REG = 1;
    set_bkg_tiles( 0, 0, 20, 18, eso_a); //set what palettes to use
    
    VBK_REG = 0;
    set_bkg_tiles (0, 0, 20, 18, esomods3map); //set what tiles to use
    
    //move_bkg (0, -144); //move bkg offscreen before animating it
    
    SHOW_BKG;
    DISPLAY_ON;

So I guess the palette info is stored in bank 1 and the actual graphic information of the tiles is stored in bank 0.

Offline

 

#9 2018-02-10 18:49:41

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

Re: Trouble With Backgrounds

[strike]Using ` VBK_REG = 0` won't fix anything, since the tiles were loaded to VRAM bank 0 (as indicated by his screenshot of the VRAM viewer), and the tile map has been written to instead of the attribute map (otherwise only a solid color would be displayed to the screen).[/strike]
Ah, looks like I missed the line where the attribute map was written to.


I will back up my claim that ASM isn't that hard by quoting a few different people who initially used GBDK :
"I read through ASMSchool a while ago and was intrigued, ASM doesn't seem to be as evil as I originally though it was. tongue Actually, it seems to be very interesting."
" 'ASM isn't as hard as it may sound' is a statement I would readily agree with and hold as being reasonable."
I could also cite Imanolea, who switched to ASM once Last Crown Warriors started getting a bit too CPU-heavy (I re-used some of his screenshots in the writeup I linked to)

I'm not trying to enforce ASM "because C sucks", but because I've seen more good come from it than from C.
I suppose it's on a per-case basis, though. For large, long-terms projects, it's well worth a shot, considering how much GBDK can be a pain.


@esotericsean : If you're willing to try out ASM, it'll be a tad more difficult to get something to display on-screen. I would suggest looking up this list for tutorials and community help. I'll be honest, starting ASM on your own is very difficult, but with help from experienced devs, it's much, MUCH easier.
Also, in VRAM bank 1 is stored a bit more than the palettes. It also stores tile flipping info, and even some priority info - it's documented here. (The big block tells what each bit of each byte means)

Last edited by ISSOtm (2018-02-10 18:57:40)


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

 

#10 2018-02-11 01:07:17

esotericsean
Member
From: Buena Park, CA
Registered: 2018-01-14
Posts: 16
Website

Re: Trouble With Backgrounds

Thanks! I will look into ASM soon.

For now I did some more troubleshooting on my current situation. I was determined to figure out what was going wrong because everything was working fine previously.

Turns out that GBMB isn't exporting maps correctly. This is what my export settings look like: https://imgur.com/a/YMXGu

And this is what I'm getting:

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

As you can see, there are only 3 items in the exported map when there should be 6.

Anyone familiar with GBTD and GBMB?

Offline

 

#11 2018-02-11 02:23:09

ssjason123
Member
Registered: 2017-03-21
Posts: 45

Re: Trouble With Backgrounds

It kind of looks like they are being treated as 4-bit values.
0, 4, 1
2, 5, 0

The final 0 looks off, I would expect 3 instead of 0 if they were 4-bit though.

Offline

 

#12 2018-02-11 02:34:13

esotericsean
Member
From: Buena Park, CA
Registered: 2018-01-14
Posts: 16
Website

Re: Trouble With Backgrounds

ssjason123 wrote:

It kind of looks like they are being treated as 4-bit values.
0, 4, 1
2, 5, 0

The final 0 looks off, I would expect 3 instead of 0 if they were 4-bit though.

You're right. I switched the GBMB export settings from 0.5 plane (4 bits) to 1 plane (8 bits) and that fixed it.

That mostly fixed it. It's loading all 110 tiles, but the map isn't displaying the ones at the end. Maybe an overflow issue? Or just a glitch with GBMB?

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

Last edited by esotericsean (2018-02-11 02:34:27)

Offline

 

#13 2018-02-11 11:37:19

ssjason123
Member
Registered: 2017-03-21
Posts: 45

Re: Trouble With Backgrounds

What does your current initialization look like. The old stuff was loading a 20x18 map but it looks like the new map in your screenshot is 20x10.

Offline

 

#14 2018-02-11 14:15:33

esotericsean
Member
From: Buena Park, CA
Registered: 2018-01-14
Posts: 16
Website

Re: Trouble With Backgrounds

ssjason123 wrote:

What does your current initialization look like. The old stuff was loading a 20x18 map but it looks like the new map in your screenshot is 20x10.

New init() looks like this:

Code:

    set_bkg_data (0, 110, esomods3);
    
    set_bkg_tiles (0, 0, 20, 10, esomods3map);
        
    SHOW_BKG;
    DISPLAY_ON;

I discovered the issue, though! Seems that the map loaded the majority of the tiles correctly and then it started repeating the first tiles again. But all of the tiles did load. I'm manually going through the map and updating each tile to the correct one.

I'd still like to figure out why it does this. Maybe GBMB has trouble with too many tiles? Or maybe my export settings still weren't ideal? Not sure, but the issue does seem to be related to the map.

Last edited by esotericsean (2018-02-11 14:15:46)

Offline

 

#15 2018-02-11 20:20:06

esotericsean
Member
From: Buena Park, CA
Registered: 2018-01-14
Posts: 16
Website

Re: Trouble With Backgrounds

Success! (It runs smoother than it looks in the gif)

https://i.imgur.com/6Rl5EyT.gif

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson