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.

Coding > Simple Tiled BG issues...

#165416 - opal - Fri Dec 19, 2008 11:15 pm

Although I'm not new to programming, console development is new for me, and I've been seriously struggling trying to get a grasp on it.

I've been looking at a few websites for information, particularly The Pern Project and Tonc's GBA deving guide...

Unfortunately, the Pern Project sometimes uses register names that are different due to the ever-changing devkitpro, and Tonc has his own defines of registers and such. Because of this, I've had to go digging through files like gba_video.h for the right code. It's been a hassle, but I've pulled through and the code compiles ok.

Ah, speaking of which, the code...I'm starting out simple- just trying to display as simple of a tiled BG as you get.

I've gone through most of the motions with no problems- my issue comes along when I try to load the tileset, tile palette, and tilemap into VRAM.
Tonc, Pern, and devkitpros' examples show all sorts of ways of loading graphics into memory. After trying all of them, I found that the only one that worked for me was using a for loop...and so that's what I did.

I threw together a very basic tileset and tile palette using tonc's Usenti program. I haven't put together a map yet because I've been unable to find a good map editor.

I've gotten the code with for loops to compile correctly, and obviously when I run the program it shows a black screen because there's no map file to tell the GBA where to draw which tiles.

However, when I run it in an emulator rather than a flashcart and look in the tile data, it seems to be mis-paletted (the tiles are the wrong color) and around tiles 16-20 (which don't exist) there's some random pixels in the tiles.

My questions are this:
Look at my source code. Am I doing everything correctly, particularly in the loading functions I've made?

Do you have a better way to take the tileset/palette and load it into VRAM?

Can you suggest a good map editor so I can put together a map and hopefully by the end of this 3+ day attempt to put together a simple tiled map on the screen?

Sourcecode, tileset/palette, and original tileset pcx image are here:
http://uploading.com/files/Y31YJRYJ/game.zip.html
(tilemap_1 is the actual tileset/palette folder, although these files can also be found in the include folder of the 'game' folder)

#165435 - opal - Sat Dec 20, 2008 6:20 am

I found my issue with the mis-coloring of the tiles!
I forgot I'm in 16 color mode, meaning each tile uses a 16-color palette.

Ok...the junk data around tile 16 is still there, but my tileset doesn't even go that far, so I'm sure it's just a buggy emulator, if not I'll deal with it later...

What I need now is some suggestions on how to improve my code and some suggestions for a map editor.

#165437 - Kyoufu Kawa - Sat Dec 20, 2008 12:51 pm

opal wrote:
Ok...the junk data around tile 16 is still there, but my tileset doesn't even go that far, so I'm sure it's just a buggy emulator, if not I'll deal with it later...
If you try to load more tiles than you actually have, you'll load the surrounding data as well. It's pretty much the law, not a bug.

#165456 - gmiller - Sun Dec 21, 2008 6:12 pm

The tiles are loaded properly but there is no data in the map so all tiles are tile zero which is black ... I did not see the map data in your files nor the code to load it. You loaded the palette and the raw data tiles but no map so there is nothing to describe how the small set of tiles should be displayed. You did set the map index in the BG0 control register but never loaded the data.