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 > Map editing questions

#11692 - ken2 - Thu Oct 16, 2003 12:40 am

I was thinking of making my own map editing program to make a small demo, I tried MapEd 0.97 and it takes a little getting into, and MapEditor Beta 4 is really buggy apparently. But anyway, I was testing some stuff with manually coding maps in C and I came across a problem. How is the tile data referred to? I always thought it was 0x(vertical)(horizontal) and that if they went beyond 9, they went from A to Z. But apparently some tiles in the second row dont show up with 0x10 0x11 etc. One of the second row tiles came up with 0x0A... hows this all work out? BTW, i have an 8 tiles wide by 3 tiles tall bmp.

#11694 - poslundc - Thu Oct 16, 2003 1:06 am

The "0x" prefix isn't something special to indicate a tile index; rather, it indicates that the number following the 0x is in hexadecimal notation.

That is to say, wherever you see the 0x prefix you are looking at a number in base 16.

Numbers in base 16 have 16 possible values for each digit. Since we only have 10 when we count in decimal (the numerals 0 through 9), hexadecimal uses the letters A, B, C, D, E, and F to represent the numbers 10, 11, 12, 13, 14 and 15 respectively.

So the hexadecimal number 0x2C4 would be equal to:

2 * 16^2 +
12 * 16^1 +
4 * 16^0
= 708 in decimal notation.

Hexadecimal notation is important in GBA programming (as well as most types of low-level programming) because it conforms well to chunks of computer memory. Two hexadecimal digits (eg. 0x2F) are a byte of data, four digits are a half-word (16 bits), and eight digits are a word (32 bits). This is invaluable when you are less concerned with the number stored in memory and more concerned about which bits in memory are on and which are off.

Therefore, the tile data is not actually 0x(vertical)(horizontal) or anything like that; it is just a number indexing into the set of tiles available. You could write the number in decimal instead of hex if you so chose, but it usually less convenient or readable to do so.

I strongly suggest that you work through the Pern Tutorials from day 1 in order to get used to coding for the GBA. A reasonably solid grasp of hexadecimal notation is pretty much a prerequisite before you get into stuff like tiles and maps.

Dan.