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.

Graphics > Updating maps - newbie.

#10810 - goro - Tue Sep 16, 2003 4:47 pm

Hi,

Thanks to Nessie & Tepples I have manage to learn about tile maps.

I'm using mode 0/16-color tiles and I want to update the map in memory (256x256 pixels)with I'm elements from the map array(2048x256pixels) created using MapEd095.

The first screen is displayed using :-

Code:
for(loop = 0; loop <256; loop++)
      BGPaletteMem[loop] = backgroundPalette[loop];

   for(loop = 0; loop < 6880; loop++)  //load tile image data
      bg1.tileData[loop] = bgTiles[loop]; //4128

   //load the map image data
   DrawMap();

Code:
void DrawMap()
{
   u16 index1 = 0;
   u16 index2 = 0;
   u16 loop;
   u16 loop2;
   u16* temp = (u16*)map;

   for (loop = 0; loop < 32; loop++)
   {
      for (loop2 = 0; loop2 <32; loop2++)
      {
      
         bg1.mapData[index1+loop2] = temp[index2+loop2];//draw 32 tiles;
      }         
      index1 += 32;
      index2 += 256;   
                                }
}


-That should give you an idea of how my map array is organised (output from MapEd095)

I suspect that my map updating code contains the error :-
Code:
void DrawUpdate()
{
   u16 index1 = 0;
   u16 index2 = 32;
   
   u16 loop;
   u16 loop2;
   u16* temp = (u16*)map;

   for (loop2 = 0; loop2 <32; loop2++)
      {
         bg1.mapData[index1+Counter] = temp[index2+Counter];//draw 32 tiles;
               
      
      index1 += 32;
      index2 += 256;
      }
}


Can anyone help me? (if you need me to post more code-just ask)

#10817 - tepples - Tue Sep 16, 2003 8:40 pm

Now I understand what your "vertical alignment" problem is.

In memory, the space after row 5 column 31 is row 6 column 0. But on screen, the space to the right of row 5 column 31 is row 5 column 0. (This has been true of all Nintendo systems' tile video architectures.)

You have to code properly for the wraparound. Keep track of horizontal and vertical offsets in screen-space separately, and make sure all writes to nametables fall in (0, 0) to (31, 31) by using the & (bitwise AND) operator.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#10863 - goro - Thu Sep 18, 2003 5:54 pm

Hi,
I got the scrolling thing to work (same 2048x256 map).

It seems the (output from MapEd095) offset is 256 tiles per column for this size of map while the VRAM offset is 32.

Now,
Quote:
In memory, the space after row 5 column 31 is row 6 column 0. But on screen, the space to the right of row 5 column 31 is row 5 column 0. (This has been true of all Nintendo systems' tile video architectures.)

You have to code properly for the wraparound. Keep track of horizontal and vertical offsets in screen-space separately, and make sure all writes to nametables fall in (0, 0) to (31, 31) by using the & (bitwise AND) operator.


If (onscreen) the space to the right of row 5 column 31 is row 5 column 0, what is the space to the right of row 4 column 31?

I think this might also be throwing off my scroll/update sync. I don't want to see the screen updating so I'm doing it offscreen and I'm currently updating the columns once for every 8 pixels of scroll (because each tile is 8x8). But the screen always catches up with the scroll or vice versa.

Also -What is the syntax of the &(bitwise AND) operator in this case?

I know that I'm asking for a bit much here but can anyone give a rough bit of code to demonstrate how I might overcome this...

#10873 - jenswa - Thu Sep 18, 2003 8:25 pm

Well i am not a wonder in these things, but my help might sometimes work.

the space to the right of row 4 column 31, is row 4 column 0
But in memory the space is row 5 column.
But i think you might have figured this one out, because tepples mentionned it in his post before (only he used 5 and 6).


You scroll 8 pixels and then call the update function?
And your background wraps around?

The screen space is 240 pixels wide, 0 - 29 columns, 30 and 31 are offscreen, the latest 16 pixels.
So when you've scrolled 8 pixels left, all rows column 0 should be wrapped behind column 31 (to the right that is) and you should update that column with column 32 of your main map.
If we move again 8 pixels left, all rows column 1 should be wrapped behind column 1 (also on the right side, because of the wraparound).
So you want to update all rows, column 1, with column 33 from your main map.


I hope this might give you some help.
_________________
It seems this wasn't lost after all.