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 > Quadrant two askew

#20201 - CyberSlag5k - Tue May 04, 2004 6:24 pm

I've been trying to get text backgrounds greater than 256x256 in size up and running. I have the basic theory and I've got 512x256 really close, however I am experiencing a bit of an anomaly. The left half of the map is fine, but the right half is shifted down one row, as seen here:

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

I load the map data like this:

Code:
   for(int i = 0; i < 32; i++)
      for(int j = 0; j < 32; j++)
         mapData1[j + i*32] = towerMap[j + i*64];

   for(int i = 0; i < 32; i++)
      for(int j = 32; j < 64; j++)
         mapData2[j + i*32] = towerMap[j + i*64];


towerMap is the map data and mapData 1 and 2 are pointers to screen base blocks. Just doing it by hand, everything looks fine to me. Then again, I am but a humble padawan learner when it comes to the art of gba dev. Might on of you jedi masters point out my mistake?
_________________
When you find yourself in the company of a halfling and an ill-tempered Dragon, remember, you do not have to outrun the Dragon...

#20215 - DiscoStew - Tue May 04, 2004 9:49 pm

Since you are working by hand (meaning the tile data is done manually), there will always be those little problems that will arise, such as this one. I don't know exactly the problem, but I will be asking a few questions.

1) Since you are editing it manually, have you made sure that the actual tile data (the towerMap array) is correctly aligned? Your code MAY be loading correctly, but the actual data could be off by a single vertical tile.

2) Is your mapData2 pointer correctly pointing to the correct place? Your mapData1 pointer could be pointing to the correct Screen Base Block, and being that you are working in 512x256 text mode, mapData2 should be pointing to mapData1 + 1024, because in 512x256 and 512x512 text modes, they are not linear (which I assume you know because of what your code is showing).

JFYI, check out The Pern Project at the link here about tile modes and working with 512x256 and 512x512 text modes. If that doesn't help, then you may have to post a little more code, because your loading code doesn't show us anything except that you are taking an array, and putting it into another.

(Final Fantasy IV, a great game, but those tiles look like they are shrunk by half on each axis)
_________________
DS - It's all about DiscoStew

#20217 - CyberSlag5k - Tue May 04, 2004 10:35 pm

Quote:
Since you are working by hand (meaning the tile data is done manually), there will always be those little problems that will arise


I'm sorry, I meant I was doing the math for the arrays by hand. Working out which indices I should use (namely j+i*64). My map data is exported by MapEd.

Quote:
Is your mapData2 pointer correctly pointing to the correct place?


Well, I think so. Then again, I totally just guessed and did this:

Code:
   u16* mapData1 = (u16*)ScreenBaseBlock(screenBaseBlock);
   u16* mapData2 = (u16*)ScreenBaseBlock(screenBaseBlock + 1);
   u16* mapData3 = (u16*)ScreenBaseBlock(screenBaseBlock + 2);
   u16* mapData4 = (u16*)ScreenBaseBlock(screenBaseBlock + 3);


*winces expecting verbal backlash*

Anyway, I'll give the mapDat1 + 1024 thing and see if that changes anything.

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...

#20223 - DiscoStew - Tue May 04, 2004 11:28 pm

You were setting mapData2 through mapData4 as part of ScreenBaseBlocks? One thing to remember is that the ScreenBaseBlocks is for setting the mapdata for each individual background, not individual areas of a 256x256, 512x256, etc, map area. I assume you are using the ScreenBaseBlock macro from your code.
To properly use 512x256 and 512x512 text modes, imagine that the area is either 2 32x32 tile blocks side by side, or 4 32x32 tile blocks in an order like a "Z". To access these other blocks, add to the index of the mapData array with (n * 1024) where "n" equals the specific quadrant. Or in your circumstance, set mapData2 to "mapData1 + 1024", mapData3 to "mapData1 + 2048", and mapData4 to "mapData1 + 3072".

Try that, and see if it works.
_________________
DS - It's all about DiscoStew

#20228 - sajiimori - Wed May 05, 2004 12:58 am

Your math is wrong. To prove it to yourself, consider:
Code:

for(int i = 0; i < 32; i++)
   for(int j = 32; j < 64; j++)
      mapData2[j + i*32] = towerMap[j + i*64];

What index of mapData2 do you want to access on the first iteration? What index is actually accessed?

But despite DiscoStew's objection, you were right that each screen base block corresponds to a 32x32 tile area, and it's ok to handle each block seperately as you have done.

#20230 - CyberSlag5k - Wed May 05, 2004 1:08 am

Hahar! Good call Sajiimori. I also liked how you just gave me the question I needed to ask myself instead of its answer. I learn more when I do it for myself.

For anyone who experiences the same problem in the future, take a look at what I was doing:

Code:
   for(int i = 0; i < 32; i++)
      for(int j = 0; j < 32; j++)
         mapData1[j + i*32] = towerMap[j + i*64];

   for(int i = 0; i < 32; i++)
      for(int j = 32; j < 64; j++)
         mapData2[j + i*32] = towerMap[j + i*64];


My indices for mapData1 were fine. The first few iterations would yield indices 1, 2, 3.... (1+(0)(32), 1+(1)(32), 1+(2)(32)), and as i was incremented 32, 33, 34 ...(0+(1)(32), 1+(1)(32), 2+(1)(32). This is ok. But take a look at mapData2. My first few iterations would have been 32, 33, and 34 (32+(0)(32), 33+(0)(32), 34+(0)(32)) which is just silly. To fix the problem I made the line:

mapData2[j-32 + i*32] = towerMap[j + i*64];

Hope this helps someone and thanks again to all who helped me!
_________________
When you find yourself in the company of a halfling and an ill-tempered Dragon, remember, you do not have to outrun the Dragon...

#20232 - sajiimori - Wed May 05, 2004 2:43 am

Quote:

I also liked how you just gave me the question I needed to ask myself instead of its answer. I learn more when I do it for myself.

Oh don't overestimate my teaching skills -- I'm just too lazy to type the answer! :P

#20233 - DiscoStew - Wed May 05, 2004 2:44 am

Looks to me like I need to get back on tiles, maps, and stuff. I've been working on my sprite handler for so long that even simple things like this with tiled backgrounds requires me to get back into it.
_________________
DS - It's all about DiscoStew