This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

When are sprite patterns fetched?

When are sprite patterns fetched?
by on (#33255)
When, during the rendering of a scanline, are sprite patterns fetched? Can anyone make this clear?

I'm trying to reload sprite patterns through CHR bankswitching, and I want this to be a clean switch: one scanline uses the previous patterns, and the very next one uses the new patters, but I notice that a few sprites in this split area (it probably depends on the order they were evaluated) have a line that flickers between the 2 sets of patterns.

Currently, I'm waiting for the visible start of the scanline to do the switch (because I assumed the patterns were fetched during the previous HBlank, after the sprites were evaluated), but that must be wrong. Please tell me if there is a safe time to switch the sprite patterns.

Thanks for the help.

EDIT: 2C02 technical reference.TXT says that this happens during "Memory fetch phase 129 thru 160", but I'm not sure what those numbers mean (they are not clock cycles!), so I can't tell when exactly is this... little help? I'll keep reading the doc anyway, maybe I'll find something.

by on (#33257)
(because I assumed the patterns were fetched during the previous HBlank, after the sprites were evaluated)

Yes, approximate timing: clockcycles 260 to 320. Could you recheck your bankswitch timing?

by on (#33258)
Oh crap! You are right (and so was I)! My problem is actually something else... The problematic sprites are comming from the BG side of the pattern table, that I bankswitch a bit before. Stupid me, I forgot that! :oops:

So, yeah, I'll have to check my timing, keeping in mind that sprite patterns can come from anywhere in the pattern tables.

by on (#33260)
Fixed it. Just so you guys know what was actually going on:

The timing was right. I have this somewhat complex scheme going on to hide the topmost 16 scanlines (to hide vertical scrolling glitches). Initially, only transparent patterns are loaded, and the sprite height is set to 8, so that I can use a MMC3 IRQ. So, before the IRQ fires, all you see is color 0, but when it fires, I make both sprite and BG fetch tiles from the sprite side, so that everything remains transparent while I load the BG patterns. Then I wait for HBlank, when I make the BG fetch tiles from the correct side.

The problem was that at this point, I also changed the height of the sprites to 16, so that they are evaluated with the correct size for the next scanline. My mistake was forgetting that the new size would also affect what patterns are fetched. So now I wait for the start of the next scanline to change the height of the sprites, and then finally load the sprite patterns.

It's working well now, and the blanked area behaves as expected. Sorry for my moment of stupidity! =)