Getting right attribute tables with scrolling

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Getting right attribute tables with scrolling

Post by tokumaru »

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: Select all

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.
DarkMoe
Posts: 70
Joined: Sat Jun 27, 2015 1:09 pm

Re: Getting right attribute tables with scrolling

Post by DarkMoe »

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.
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Getting right attribute tables with scrolling

Post by tepples »

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.
DarkMoe
Posts: 70
Joined: Sat Jun 27, 2015 1:09 pm

Re: Getting right attribute tables with scrolling

Post by DarkMoe »

Excellent, thank you !
DarkMoe
Posts: 70
Joined: Sat Jun 27, 2015 1:09 pm

Re: Getting right attribute tables with scrolling

Post by DarkMoe »

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 ?
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Getting right attribute tables with scrolling

Post by tepples »

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.
DarkMoe
Posts: 70
Joined: Sat Jun 27, 2015 1:09 pm

Re: Getting right attribute tables with scrolling

Post by DarkMoe »

You couldn't make it any clear.

You're awesome, thank you !
Post Reply