nesdev.com
http://forums.nesdev.com/

Getting right attribute tables with scrolling
http://forums.nesdev.com/viewtopic.php?f=3&t=14795
Page 2 of 2

Author:  tokumaru [ Thu Sep 22, 2016 1:24 pm ]
Post subject:  Re: Getting right attribute tables with scrolling

The fine X scroll should have no influence on the attributes at all! The AT address can easily be derived from the NT address:

Code:
NN: name table;
JIHGF: coarse Y scroll;
EDCBA: coarse X scroll;
NT address: %0010NNJI HGFEDCBA
AT address: %0010NN11 11JIHEDC
Quadrant: %GB

So, if you fetch a tile from %00100101 01111010, simply get its attributes from the byte at %00100111 11010110, and use quadrant %10, while completely ignoring the lowest bit of the coarse X and Y scrolls (attributes are applied to 16x16-pixel areas after all) and the fine scroll. The address of a tile in the name tables is directly linked to the address of the attribute byte it uses.

Author:  DarkMoe [ Tue Sep 27, 2016 6:35 am ]
Post subject:  Re: Getting right attribute tables with scrolling

Followed all your advise, and got closer to the right behaviour.

So what was happening, I was trying to fetch tiles using the fine x scroll value, in order to draw pixels directly, grabbing attributes the same way, but when I calculated the quadrant using the V register, I would always be off by 0-7, depending on the fine X scroll value (except when there was no scroll).

So, what I did now, is to ignore the fine x scroll, and then move shift all pixels to the left using the fine X scroll value. Using my current logic, that leaves now the right pixels undrawn, since I'm calling the draw pixel function 256 times (and the first times don't draw anything if there's scroll).

Is there a way, to include the fine x scroll into the calculation of the quadrant ?? That would solve everything I think.

Author:  tepples [ Tue Sep 27, 2016 8:36 am ]
Post subject:  Re: Getting right attribute tables with scrolling

DarkMoe wrote:
So, what I did now, is to ignore the fine x scroll, and then move shift all pixels to the left using the fine X scroll value.

It turns out that's exactly what the PPU actually does. Fine X scroll has absolutely nothing to do with how tiles are fetched. The PPU has a set of shift registers used as a variable delay line to move the background 8-1 pixels to the right for fine X scroll values of 0-7.

Author:  DarkMoe [ Tue Sep 27, 2016 10:50 am ]
Post subject:  Re: Getting right attribute tables with scrolling

Excellent, thank you !

Author:  DarkMoe [ Wed Sep 28, 2016 7:00 am ]
Post subject:  Re: Getting right attribute tables with scrolling

One more question though.

If the PPU render a pixel for each PPU cycle, and cycle 0 is idle, it means that each pixel is rendered between cycles 1-256 on each scanline right ?

How does that work when there's a fine X scroll ? if I just discard the 7 first pixels (if fine X is 7), then I'm missing the right 7 pixels (the last pixels of the scanline).

I think I should bring another tile when fine scroll X is not 0, but how does it fit with the PPU timings ?

Author:  tepples [ Wed Sep 28, 2016 7:36 am ]
Post subject:  Re: Getting right attribute tables with scrolling

On each scanline, your PPU should fetch 34 tile columns during the following pixels:

  • Fetch 1 is at X=321 to 328.
  • Fetch 2 is at X=329 to 336.
  • Fetch 3 has a false start at X=337, waits a few microseconds, and restarts at X=1 to 8. The MMC5 depends on this false start to detect a new scanline.
  • Fetch 4 is at X=9 to 16.
  • ...
  • Fetch 33 (used for the partial row of tiles at right) is at X=241 to 248. The PPU uses this data for the partial column at far right whenever fine X scroll is nonzero. Otherwise, the PPU discards this fetched data.
  • Fetch 34 (discarded) is at X=249 to 256. The PPU always discards this data, but games using the MMC2 and MMC4 depend on this discarded fetch to reset the bank number to the starting point.

Author:  DarkMoe [ Wed Sep 28, 2016 8:10 am ]
Post subject:  Re: Getting right attribute tables with scrolling

You couldn't make it any clear.

You're awesome, thank you !

Page 2 of 2 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/