It is currently Wed Nov 22, 2017 8:59 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Thu Dec 09, 2010 10:06 am 
Offline

Joined: Sat Feb 27, 2010 8:32 am
Posts: 115
Location: Maine
Okay, so I'm working on doing some 4 way scrolling, but updating the attribute tables is getting to me.

It makes sense, to me at least, to update the tables in chunks when scrolling horizontally with vertical mirroring. For example, you move right four tiles and then you update a vertical chunk of attribute tables. You could even buffer the attribute data of columns as you draw them and then once you've drawn 4 columns, update the attribute tables if you needed.

However, once you bring the four way scrolling into play I start to get a little confused. Would the best way to do it be updating the attribute tables for four tile chunks when you scroll left and right, but keep a buffer or something for updating them with a vertical scroll?

Does that make sense, or am I way off course here?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 09, 2010 10:17 am 
Offline
User avatar

Joined: Fri Nov 12, 2004 2:49 pm
Posts: 7272
Location: Chexbres, VD, Switzerland
4 way scrolling is a total pain to get working, I never got any fully working personally despite multiple tries.

However, for updating attribute tables, I suggests a method who works with 2x2 blocks, which computes the VRAM adress using lockup tables (to make things relatively simple), and does AND/OR operations with the older value. You can do that either by read-modify-write $2007 (needs to be in VBlank), or by using one/two $40 bytes tables in memory that "mirrors" the attribute table for logic, and update it to RAM on next VBLank.

_________________
Life is complex: it has both real and imaginary components.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 09, 2010 11:38 am 
Online
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10118
Location: Rio de Janeiro - Brazil
This is kinda annoying to get right on the first time. The main problem is that the name tables are 30 tiles high instead of 32, so the attribute bytes don't align properly across adjacent vertical screens.

Personally, I have done what Bregalad suggested. I have a copy of the attribute tables in RAM, and I modify each 16x16-pixel square individually, using masks. Then during VBlank, I just copy entire rows or columns of attribute bytes.

Accessing the bits can be really easy: based on the address of the tile you can easily locate the corresponding attribute byte and bits. Since the name table is 32x30 tiles, the address of a tile is defined like this: YYYYYXXXXX. Just combine the 3 highest bits of each coordinate to find the address of the attribute byte, like this: YYYXXX. Then, combine bit 1 of each coordinate (bit 0 is not needed for anything, because the NES doesn't assign attributes to individual tiles) to form an index into tables of masks that will be used for bit manipulation:

Code:
AttributeMasks:
   .db %00000011
   .db %00001100
   .db %00110000
   .db %11000000

I usually copy to RAM the masks I'm gonna need to RAM (when rendering column of metatiles for example, I need one mask for the top block and another one for the bottom block, and I alternate between them) so that the index registers can be use to access the array of new attributes and the mirror of the attribute table.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 09, 2010 8:56 pm 
Offline

Joined: Sat Feb 27, 2010 8:32 am
Posts: 115
Location: Maine
Awesome guys! Super helpful, thanks to you both!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group