gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Beginners > Multiple BackGrounds

#130070 - =Cadet Zemm= - Wed May 30, 2007 7:34 pm

I'm very new to GBA programming (and game programming in general) and I've been reading through the tonc tutorials for the past month or so and finally decided I'd read enough to try to make my own Pong game from scratch (using tonclib).

I got it all working exactly how I wanted it on the emulator (VBA) but when I put it on my cart and run it on my DS (I don't have a GBA) I got artifacts during the title screen, which went away when it went into the game. At which time the logo BG is turned off and sprites are turned on (for the paddles/ball) and the text BG is left on. During the title screen BG1 is being used for text (using the se_txt system in tonclib set to CBB 1, SBB 31) and BG0 for the logo and is set as a regular BG using CBB 0 and SBB 30 (and it's only 88 tiles, so there should be plenty of room between the Charblocks (which is verified looking at the tile viewer in VBA)).

I fixed the problem by just putting the text system and the logo onto the same BG(0) and passing 512 to se_puts()'s se0 parm, but this makes me have to clear the logo tilemap (and then remap it when the game ends and returns to the menu... in my original design I just turned BG0 off or on to hide/show the logo) in order to still be able to use BG0 for the text for my score keeping and win/lose/pause messages. Which isn't a big deal, it just seems like I shouldn't have to do this, and I'm one of those who likes to know the WHY ;)

Anyway, after all that explanation (hehe, sorry) my question is: It seems like the functionality is in place for me to create a BG just for the Logo and one just for text and keep it that way throughout the multiple states of my game (it never leaves Mode 0), and be able to turn either one on or off as I please, and it does indeed work in VBA... any ideas why it would artifact on an actual GBA (only when the two BG's are on simultaneously, I forgot to mention that either BG enabled by itself showed up fine, but when both were on I got the artifacts (and it looks like the artifacts are only on the logo BG(0), but it's hard to tell for sure either way)).

If you want to see any code or anything let me know, I'll post it here or send it, however you prefer. Or if you need clarification on anything as I understand this is a very long and muddled up post (sorry bout that). I'm not looking for a specific answer or anything necessarily, more just looking for some ideas that could lead me to finding the why. Thanks in advance for any and all help!!

#130081 - tepples - Wed May 30, 2007 9:04 pm

First, I'd like to see screenshots of the artifacts. Do you have a camera, preferably one with a "macro" mode?

You're using screen base blocks near the end of VRAM. The behavior of the GBA and DS differ if the end of a screen area goes past the end of screen base block 31. Are you sure these are set to the small (256x256) screen size?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#130087 - =Cadet Zemm= - Wed May 30, 2007 9:36 pm

Yes they are set to the small screen size... as far as I can tell anyway, that should be done by making sure the last two bits of REG_BGxCNT are set to 0, right? And I tried moving them to SBB 24 during my initial troubleshooting as well just in case, but got the same results.

I do have a camera and I'll try to set it up (the current version (considering it pretty much complete, as is) is not experiencing the problem, but I'll go back and set it back up the way that it was) and get pictures and post them. I don't know what "macro" mode is, so I'm not sure if it has that or not. But the screen is not animated (aside from the "Press Start" (the only text on the screen) flashing (which is done using se_puts() and se_clrs())) which is what that sounds like it has to do with.... wait or is "macro" mode the one with the flower on it, for up close shots? I dunno, I'll just make sure it's a good pic ;)

The artifacts are all turquoise and yellow, they look like they are tiles for something else, but I can't tell what, and they're not from my tileset... unless they're using a different palette, I didn't think about that... but still, I don't think they were.

#130141 - =Cadet Zemm= - Thu May 31, 2007 8:10 am

Ok, I recreated the problem, it's slightly different this time. Now when I switch into the Gamestate I still have the artifacts in the background, even though only one BG is enabled. The pictures below show what it looks like when I have the txt going to BG1 and the logo to BG0. If I swap them I am able to see the logo and the text, however the artifacts are still there.

Here is the pic with the Press Start text:
[Images not permitted - Click here to view it]

Without the text:
[Images not permitted - Click here to view it]

And what it's supposed to look like:
[Images not permitted - Click here to view it]

Thanks again for your help! Let me know if there's anything else you'd like to see.

=Z=

#130143 - =Cadet Zemm= - Thu May 31, 2007 8:20 am

I think my problem may lie in the tilemap I'm using for the Logo. It's simple enough I think I'm going to try creating it manually tomorrow and see if that makes a difference...

Currently I'm using what I got from Usenti. I created the Logo in Usenti and then exported it to a c file as a 32x32t (256x256p) sbb map of 4bpp tiles... which should work as far as I can tell.

But I think the map itself should be pretty simple to just write manually, so I'll try that tomorrow... but I'm off to bed for tonight :P

#130191 - Cearn - Thu May 31, 2007 7:31 pm

=Cadet Zemm= wrote:

Here is the pic with the Press Start text:
<<flakey graphics>>

I have seen something like this one: if you try to use tilemaps that access tiles outside the BG charblock range (i.e., those that actually part of object VRAM), the GBA will render the addresses themselves, rather than the data in them. The result would be vertical stripes. This does not show up in VBA, but might in no$gba.

I'd like to see the binary (and perhaps the source), if possible.

#130199 - =Cadet Zemm= - Thu May 31, 2007 8:34 pm

The code can be downloaded here.

I included the Proj and Solution files, but left the Makefiles out because they are customized to work in my directory structure, but the Makefiles I use just use the tonc.mak system enabling me to build and run from Visual C++ Express with my specific directory structure... nothin real fancy.

All of my code knowledge is book and online tutorial generated, so if I have any bad coding habits in there, or it's extremely confusing, I'm sorry! I will try to answer any questions you have about why I did something the way I did as well.

Thanks for all the help (here and the wonder that is tonc.chm ;) )!

Cearn wrote:
I have seen something like this one: if you try to use tilemaps that access tiles outside the BG charblock range (i.e., those that actually part of object VRAM), the GBA will render the addresses themselves, rather than the data in them. The result would be vertical stripes. This does not show up in VBA, but might in no$gba.


This is what I was thinking the problem might be based on what tonc had to say in the Regular Tiled Backgrounds chapter and where it seemed like tepples was going, but I just don't see how, unless I'm doing something wrong in the export from Usenti and the memcpy into se_mem. But I tried pushing it all the way back to SBB[16][0]... so my only other thought is either the text system is filling more than 2 SB's (which I didn't think it would) or I need to just write the map manually.

Or I'm having more trouble understanding the way tiles and tilemaps work than I thought I was. Hopefully somebody who knows what they're doin' looking at my code will clear things up ;)

Thanks again guys!

#130369 - =Cadet Zemm= - Sat Jun 02, 2007 4:47 pm

Don't suppose you've had a chance to look at my code yet? I tried to write the map myself but it's taking me longer than I thought because I'm having trouble understanding exactly how SBs and CBs work together, and all that, and just not had a lot of code time lately.

#130373 - Cearn - Sat Jun 02, 2007 5:42 pm

The code seems to work just fine on both the emulators I've tried, as well as hardware (GBA SP and DS Lite+Supercard CF). Some hardware anomaly maybe?

Couple of points on the code though: only use 'inline' (or in my case INLINE) for very short functions. Inline functions are incorporated into their callers completely, which is fine and often desirable for small functions, but for large ones it can cause significant code bloat.

It is conventional (at least in C) that all-caps signify constants and macros. Using BALL etc for variables could be might be misinterpreted. Not that this point matters that much, but I'm just saying.

Also, your title map doesn't use any tile reduction. titleTiles has enough data for 1024 tiles (i.e., two full charblocks), even though only 67 tiles of the title screen are actually unique. This is also why the font appears on the bottom of the screen. Because the map isn't tile-reduced, the map is essentially a sequence of incrementing indices from 0 to 1023. The tiles over 512 actually come from charblock 1.

#130417 - =Cadet Zemm= - Sun Jun 03, 2007 4:18 am

Well that's interesting... reassuring in a way, I guess, because it means what I thought SHOULD work DID actually work, just not for me. I guess it must be my flash cartridge (G6 Flash, I guess I should have done a bit more research before ordering this as I read afterward that G6 isn't very homebrew friendly) since it does the same thing on my wife's DS.

Thank you very much for the tips and for the help!