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 > Help on tiles

#15259 - Cuauhtemoc - Tue Jan 20, 2004 4:34 am

Hello, I wrote(tried) a simple mode 0 program, but it doesn't work. I'm just a newbie, I can't figure why it doesn't work. Could somebody help me ?

#include "tile.c"
#include "map.c"
#include "palette.c"

#define REG_DISPCNT *(unsigned short*)0x4000000
#define Video ((unsigned short*)0x6000000)
#define BG0 0x100
#define BG_PAL ((unsigned short *)0x5000000)

#define BG0CTRL *(unsigned short*) 0x4000008
#define CharBlock(n) (((n)*0x4000)+0x6000000)
#define ScreenBlock(n) (((n)*0x800)+0x6000000)


int main(void)
{
unsigned short c;
unsigned short* Tile =((unsigned short*) CharBlock(1));
unsigned short* Map =((unsigned short*) ScreenBlock(0));
REG_DISPCNT=(0x0|0x100); // (MODE_0 | BG0)
BG0CTRL=(0x80|8<<0|2<<1);// (256clrs|ScrnBlk|ChrBlk)
for(c=0;c<256;c++)BG_PAL[c]=Pal[c];
for(c=0;c<3072;c++)Tile[c]=tiles[c];
for(c=0;c<1024;c++)Map[c]=_map_[c];
while(1){}
return 0;
}


THANK YOU VERY MUCH

#15261 - dagamer34 - Tue Jan 20, 2004 5:02 am

I can't exactly tell what you are trying to do but take a look at the tutorials on this site. This might help when loading a textbg map.

http://home.no/neogeo/HOVEDSIDE_INDEX/GBA_HOVEDSIDE_INDEX_ENGELSK/index.html

I STRONGLY suggest that use use defines when setting up data and memory registers. Try to do something like this:

Code:

SetMode (MODE_0 | BG0_ENABLE);


Its easier to remember. There is also a list of defines that make life easier. For example, unsigned short can be shortened to u16 and unsigned char becomes u8.

What size of BG do you want anyway? I can't tell from your code. Missing a lot of info here.
_________________
Little kids and Playstation 2's don't mix. :(

#15265 - poslundc - Tue Jan 20, 2004 5:18 am

Cuauhtemoc wrote:
Hello, I wrote(tried) a simple mode 0 program, but it doesn't work. I'm just a newbie, I can't figure why it doesn't work. Could somebody help me ?


Might help if you told us what happened when you try to run it. Does it compile properly? Do you get any errors? Does the ROM launch in the emulator? What do you get on screen when it does? What do you expect to get onscreen?

Some other notes:

- You are #including C files. Bad, bad, bad. Compile them separately and link them.

- You might want to fix up your coding style. Don't put statements on the same line as your "for" control statements. Indent stuff. (You need to encase your code in the code tags for the indents to show up on this bulletin board.) This is all a matter of personal preference, of course, but the easier you make it for us to read your code the more likely it is we will be able to help you with it.

- All the stuff dagamer34 said.

Good luck,

Dan.

#15275 - Cuauhtemoc - Tue Jan 20, 2004 8:07 am

I thank you both for replying my post.

Well, the program was supposed to show a Final Fantasy IV room(a bedroom). I got no errors or warnings when compiling it. The emulator(Visual Boy and Mappy with the same results)launchs it but I get just a black screen. What could the problem be ?


Thanks Again[/quote]

#15277 - sajiimori - Tue Jan 20, 2004 9:28 am

Looks to me like you're setting the BG control register incorrectly.

Seriously, you should use #defines for the bits of the registers you use. For example:
Code:

#define BG_COLOR_256 0x80
#define BG_TILEBLK(x) ((x) << 2)
#define BG_MAPBLK(x) ((x) << 8)

REG_BG0CNT = BG_COLOR_256 | BG_TILEBLK(1) | BG_MAPBLK(0);

#15279 - yaustar - Tue Jan 20, 2004 9:49 am

Are the tiles/map being loaded into memory correctly?
_________________
[Blog] [Portfolio]

#15280 - qw3rty - Tue Jan 20, 2004 11:07 am

Code:

.
.
.
BG0CTRL=(0x80|8<<0|2<<1);// (256clrs|ScrnBlk|ChrBlk)
unsigned short* Tile =((unsigned short*) CharBlock(1));
unsigned short* Map =((unsigned short*) ScreenBlock(0)); .

.
.


You are TRYING to enable background 0 with screenbaseblock 8, but your are enabling BG0 with char-base-block 3 (8 << 0 == 8 ; 2 << 1 = 4; 8+3 = 12 == BIT2 & BIT 3)
You should change "8<<0" with "0 << 8" (or 0 ;) ) and "2<<1" with "1 << 2".

Furthermore you are forgetting to enable the background (forgot to set REG_DIPCNT( := *(u32*)0x4000000))

I suggest you read again day 1 & 2 at the pern-project !
(http://www.thepernproject.com/)

P.S. : I just noticed, that you ARE setting the display mode ( I haven`t checked for errors though...)

#15403 - Cuauhtemoc - Thu Jan 22, 2004 3:15 am

Thank's qw3rty, it is working now :)