It is currently Sun Dec 16, 2018 9:57 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: Sat Jul 21, 2018 3:11 pm 
Offline

Joined: Fri Mar 23, 2018 4:21 pm
Posts: 14
I'm really close to implementing full fine-x scrolling, which is awesome. However, it appears I have some discoloration on certain tiles when scrolling.

So the question is, is this where the attribute byte should be different based on fine-x, or is the palette choice wrong in the correct attribute byte?

I've attached a screenshot to show what I mean.

Image

Thanks!


Top
 Profile  
 
PostPosted: Sat Jul 21, 2018 3:24 pm 
Offline
User avatar

Joined: Thu Aug 13, 2015 4:40 pm
Posts: 328
Location: Rio de Janeiro - Brazil
I didn't even know it was possible to misalign the tiles and the attributes.

_________________
https://twitter.com/bitinkstudios <- Follow me on twitter! Thanks!


Top
 Profile  
 
PostPosted: Sat Jul 21, 2018 3:31 pm 
Offline

Joined: Fri Mar 23, 2018 4:21 pm
Posts: 14
Which leads me to believe that perhaps it's choosing the wrong palette based on fine-x. Just wondering if anyone saw this before or has a good idea of what it might be.

TD


Top
 Profile  
 
PostPosted: Sat Jul 21, 2018 4:46 pm 
Offline
User avatar

Joined: Thu Aug 13, 2015 4:40 pm
Posts: 328
Location: Rio de Janeiro - Brazil
My knowledge of the NES workings is recent, so I may be missing something. Nonetheless, I'm interested in taking a look at the ROM (is it just a static image, and not actually super mario bros?). I bet someone more knowledgeable will quickly tell you what's going on though.

_________________
https://twitter.com/bitinkstudios <- Follow me on twitter! Thanks!


Top
 Profile  
 
PostPosted: Sat Jul 21, 2018 4:52 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 7025
Location: Canada
nesrocks: OP is developing an emulator, not an NES ROM.

The bottom line: attribute rendering exactly corresponds to tile rendering, so there is no possibility for a partial match like this. I don't know what you're doing that is trying to apply different scrolling logic for attributes, but maybe try to unify them?


Top
 Profile  
 
PostPosted: Sat Jul 21, 2018 9:01 pm 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 11013
Location: Rio de Janeiro - Brazil
The information used to calculate attribute table addresses is the exact same information used to calculate name table addresses, the bits are just organized differently:

Code:
NN: name table;
ABCDE: tile's X coordinate;
FGHIJ:  tile's Y coordinate;

NT address: 0010NNFG HIJABCDE
AT address: 0010NN11 11FGHABC
AT mask: ID (00 = 00000011; 01 = 00001100; 10 = 00110000; 11 = 11000000)

Since the source of the bits that form the addresses is the same, it shouldn't be possible for them to be out of sync.


Top
 Profile  
 
PostPosted: Sun Jul 22, 2018 9:58 am 
Offline

Joined: Fri Mar 23, 2018 4:21 pm
Posts: 14
Could this be just pulling the wrong palette out of the CORRECT attribute byte?

TD


Top
 Profile  
 
PostPosted: Sun Jul 22, 2018 10:19 am 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 7025
Location: Canada
tdondich wrote:
Could this be just pulling the wrong palette out of the CORRECT attribute byte?

That wouldn't explain how you managed to get 4 pixels worth of the wrong attribute on some tiles there. The whole tile should be wrong or none of it. So, whether or not you're pulling the attribute or palette wrongly you still need to solve the problem that they aren't directly linked to the tiles.


Top
 Profile  
 
PostPosted: Sun Jul 22, 2018 11:25 am 
Offline

Joined: Fri Mar 23, 2018 4:21 pm
Posts: 14
But one attribute byte consists of a 32x32 pixel grid, so it overlaps multiple tiles and is in 4 quadrants. And my thought is, this discoloration only happens on tiles that happen to be next to something different. In the screenshot above, the only tiles that happen to be discolored are the bricks next to blank spaces (which could potentially be a different palette). Is this thinking totally off the rails? Am I understanding attribute bytes incorrectly?

My attribute byte fetching is done via:
Code:
     
      // Now get attribute byte
      //address = baseAddress + 0x3c0;
      let address = 0x23c0 | (v & 0x0c00) | ((v >> 4) & 0x38) | ((v >> 2) & 0x07);

      // Shift top 8 bits to the right
      this.attributeTableByte = (this.attributeTableByte >>> 8) | (this.vram.get(address) << 8);


And the determination of color is:
Code:
// Note: x is the cycle on the scanline (x coordinate of screen
// this.x is fine X position
          if (((x % 32) + this.x) < 16) {
            if (y % 32 < 16) {
              // top left
              palette = this.attributeTableByte & 0b00000011;
            } else {
              // bottom left
              palette = (this.attributeTableByte & 0b00110000) >>> 4;
            }
          } else {
            if (y % 32 < 16) {
              // top right
              palette = (this.attributeTableByte & 0b00001100) >>> 2;
            } else {
              // bottom right
              palette = (this.attributeTableByte & 0b11000000) >>> 6;
            }
          }


TD


Top
 Profile  
 
PostPosted: Sun Jul 22, 2018 11:45 am 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 7025
Location: Canada
Well, my advice is to throw out that complicated attempt to determine the attribute to use via pixel location, and instead determine it earlier by the affected tile's memory address:

The horizontal quadrant is determined by address & 2 (every 2 tiles enters a new horizontal attribute quadrant).

The vertical quadrant is determined by address & 64 (every 2 rows of tiles, it enters a new vertical attribute quadrant).

These two bits are what are actually used to select the quadrant. There's no need to try and do calculations with individual pixels or fine scrolling, the information is already right there in these two bits of the nametable address of the tile you're rendering.


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

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 3 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