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 > Silly MapEd

#20107 - CyberSlag5k - Sun May 02, 2004 4:42 am

I've created a few maps with MapEd (I'm getting sooooo close to successfully completing a tile background after about a week of work), but for some reason when I export to a header file, the data is a little screwy.

My test map can be seen here:

http://homepages.udayton.edu/~pateramj/1.bmp

as you can see the top left corner provides a pretty easy way to make sure things are happening the way they should. There's a grass tile and then the dirt tiles set up in a formation like this:

GDG
DDD
GDG

where the G's are grass and the D's are dirt. However, the data MapEd creates looks like this:

const u16 towerMap[1024] =
{
0x0000,0x2001,0x0000,0x0000,0x0000,0x0000,0x1006,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x2002,0x2003,0x2004,0x0000,0x0000,0x0000,0x2008,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x2005,0x0000,0x0000,0x2001,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,

Looking at the bolded indices, you can see that something kind of like

GDG
GGG
DDD
GGG
GDG

is going to be drawn, and in fact it is:

http://homepages.udayton.edu/~pateramj/2.bmp

Now I create my maps in unoptimized mode as suggested because I'm using a 256 color tiles which MapEd does not support. To get around this I create my palette and tile data, which appear to work as the tiles that are drawn all look correct, just kind of jumbled as you can see. I've also tried doing it in optimized mode, just in case. Same result. Can anyone see what's going on here? Something I"ve overlooked?

Thanks.
_________________
When you find yourself in the company of a halfling and an ill-tempered Dragon, remember, you do not have to outrun the Dragon...

#20111 - NoMis - Sun May 02, 2004 9:12 am

How are you copying the data into the VRAM. It seems to export correct because if you look close the map is 32 tiles wide wich isnt seen first in the header file.
If you copy it with dma you can simply copy the whole array at one pice into the screen block you are using.
It this doesn't work send the code block were you are copying the map please.

NoMis

#20112 - yaustar - Sun May 02, 2004 9:30 am

how big is the map?
_________________
[Blog] [Portfolio]

#20117 - CyberSlag5k - Sun May 02, 2004 4:35 pm

Quote:
It seems to export correct because if you look close the map is 32 tiles wide wich isnt seen first in the header file.


That's true, I guess I was thinking each row in the array is the first row in the map.

My map is 256x256 pixels, which should be 32x32 tiles, right?

I load the data like this:

Code:
   tempPtr = (u16*)towerTiles;
   for(int i = 0; i < 16448; i++)
      tileData[i] = tempPtr[i];

   tempPtr = (u16*)towerMap;
   for(int i = 0; i < 512; i++)
      mapData[i] = tempPtr[i];

_________________
When you find yourself in the company of a halfling and an ill-tempered Dragon, remember, you do not have to outrun the Dragon...

#20135 - CyberSlag5k - Sun May 02, 2004 10:03 pm

No luck so far but I did just notice something. The map data is still a little off. Look at that third row:

0x2002,0x2003,0x2004,0x0000,0x0000,0x0000,0x2008,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,

and the tile set:

http://homepages.udayton.edu/~pateramj/tiles.bmp

0x2002 would be a grass tile on the left and a dirt tile to the right since they get read right to left (02 is grass, 20 is dirt). Why would it do that?
_________________
When you find yourself in the company of a halfling and an ill-tempered Dragon, remember, you do not have to outrun the Dragon...

#20153 - NoMis - Mon May 03, 2004 7:20 am

The copy method looks alright to me and i suppose you set the background to 256x256.
It may be a bug with 256 color mode because as far as i know it wasn't realy tested. Nessi may be able to help you.

NoMis

#20159 - CyberSlag5k - Mon May 03, 2004 1:27 pm

Yup, it's at 256x256. I thought the same about the 256 color thing but dagamer34 tells me it works. I sent an e-mail to Nessie last night.
_________________
When you find yourself in the company of a halfling and an ill-tempered Dragon, remember, you do not have to outrun the Dragon...

#20160 - Cearn - Mon May 03, 2004 1:35 pm

You're trying to use text-background data for a rotation background. For example, what you think are the first 3 map-entries

0x0000,0x2001,0x0000, etc, etc.

are interpreted by the GBA as the first 6 map-entries of your rotation map

0x00, 0x00, 0x01, 0x20, 0x00, 0x00, etc, etc.

Which naturally results in the map of 2.bmp.

#20164 - CyberSlag5k - Mon May 03, 2004 2:25 pm

Quote:
You're trying to use text-background data for a rotation background.


I wasn't aware that rotation backgrounds read data differently. What format would the data need to be in for a rotation background?
_________________
When you find yourself in the company of a halfling and an ill-tempered Dragon, remember, you do not have to outrun the Dragon...

#20165 - Cearn - Mon May 03, 2004 2:40 pm

Quote:
I wasn't aware that rotation backgrounds read data differently.

Yes you were; sajimori said so in response to one of your earlier posts :P

Anyway, map-entries in

a text background: 16 bits integer
bits 0-9 : tile index
bit 10 : horizontal flip
bit 11: vertical flip
bits 12-15 : sub-palette (for 16 color backgrounds)

a rotation background: 8 bits integer
bits 0-7 : tile-index; no more, no less.

Confusing the two wreaks havoc on your maps (just like confusion between 4 and 8 bit data do for tiles).

#20167 - NoMis - Mon May 03, 2004 3:56 pm

Man! why i didn't see it *hit me*

#20169 - CyberSlag5k - Mon May 03, 2004 4:04 pm

But the map data is still skewed, is it not?

0x2002,0x2003,0x2004,0x0000,0x0000,0x0000,0x2008,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,

That is the third line of my array (which should be the second row of tiles). It will be read as such:

0x02 0x20 0x03 0x20 0x04 0x20
grass dirt grass dirt grass dirt

Which is still wrong. It should be dirt dirt dirt grass
_________________
When you find yourself in the company of a halfling and an ill-tempered Dragon, remember, you do not have to outrun the Dragon...

#20171 - CyberSlag5k - Mon May 03, 2004 4:09 pm

ok, wait, i think i see it. tell me if I'm right here...I just wrote that the map was like this:

0x02 0x20 0x03 0x20 0x04 0x20
grass dirt grass dirt grass dirt

are the bold entries not tile locations, but information about the tiles themselves? Information that text backgrounds would use but rotation backgrounds would not? Those extra 8 bits, in other words?
_________________
When you find yourself in the company of a halfling and an ill-tempered Dragon, remember, you do not have to outrun the Dragon...

#20172 - CyberSlag5k - Mon May 03, 2004 5:23 pm

Haha! FINALLY! I finally have my tile background working as it should.

My problem was exactly as you said, Carn, I was using text background data for a rotation background.

Thank you to everyone!
_________________
When you find yourself in the company of a halfling and an ill-tempered Dragon, remember, you do not have to outrun the Dragon...

#20344 - Cearn - Sat May 08, 2004 1:22 pm

CyberSlag5k wrote:
ok, wait, i think i see it. tell me if I'm right here...I just wrote that the map was like this:

0x02 0x20 0x03 0x20 0x04 0x20
grass dirt grass dirt grass dirt

are the bold entries not tile locations, but information about the tiles themselves? Information that text backgrounds would use but rotation backgrounds would not? Those extra 8 bits, in other words?


Well, almost.
Starting with the tileset of tiles.bmp. This is a 256x256 pixel bitmap which , means it holds 32x32 tiles. The tiles are numbered linearly, just like the 1D mapping mode for sprites. Meaning that 0-3 are grass, 4-7 is dirt, 8-11 is road, then black tiles for the rest of the tile-row until we come to the second tile-row, which uses tile index 32 (0x20), which is grass again, not dirt.
This indexing is used in the map-entries (and I do mean map-entries and not tiles. Tiles are image data). Although text backgrounds use 16bit map-entries and rotational bgs use 8bits, it is possible to use the lower byte of a text map for the entries of a rotational map, like you thought.

In summary, if we take a part of the 16bits text map:
Code:

0x2002, 0x2003, 0x2004
grass   grass   dirt

The first nybble contains the palette-number, but that's only of interest in 16color maps.
Now, since you're using a rotational map, which uses 8bits, the GBA sees this as
Code:

[b]0x02[/b]  0x20  [b]0x03[/b]  0x20  [b]0x04[/b]  0x20
grass grass grass grass dirt  grass

The reason the bytes are switch is because we are using a little-endian
system; the lowerst bytes of a type with >8bits goes first. Now, the
bold entries contain the tile-indices, so you could use those to form the map. The rest is indeed extra information.

Now, although this does work, you'll get into trouble again when you try bigger or smaller maps. The bigger text maps are divided into screen-blocks, while rotational maps aren't. This means that you'll have to do that conversion manually as well. And the fact that the range of sizes
are different for text and rotational bgs can cause problems as well, just like the fact that you only can use two of them at most. And you've already seen that MapEd (like most map editors) exports to text backgrounds, and that you can't write to VRAM in 8bit chunks.

Hmmm, can I suggest you use text backgrounds instead, and save yourself a heap of trouble?

#20345 - CyberSlag5k - Sat May 08, 2004 4:51 pm

Thanks Cearn, that clears quite a bit up.

Quote:
Hmmm, can I suggest you use text backgrounds instead, and save yourself a heap of trouble?


Indeed I already have and it has made my life a ton easier. I have my backgrounds working exactly the way I want them.

Thanks again!
_________________
When you find yourself in the company of a halfling and an ill-tempered Dragon, remember, you do not have to outrun the Dragon...