Quote:
What I don't understand is, if your routine has no scrolling and then when the hit flag is set it starts scrolling, does that mean that if you have Sprite 0 somewhere in the horizontal center of the screen, that the rest of the pixels in that scanline will be drawn with the scroll applied to them, or is the scroll not applied until the following scanline starts to be drawn? (I mean, does the change happen immediately when the overlapping pixels are detected?)
This depend of your programm. Sprite zero hit doesn't make anything scrolling, it just helps a lot to TIME your programm.
The NES doesn't have any HDMAs or anything : you cannot just tell to the NES : Scroll background = 0 before the hit and ScrollFieldX after hit. You have to set the scroll to 0, wait the hit, and then rewrite ScrollFieldX after that in your scrolling register.
So you can use it for scrolling or whathever, or just wait a little more constant time until you upload the scrolling if you want to do so (looks like it is what SMB does).
Now, at the time you first write to $2005, as my undestanding, this will affect the horizontal scrolling immediately. To change vertical scrolling, you have to play with both $2005 and $2006 registers ($2006 is basically for adress, but during rendering it serves to adress tiles to render inside the screen). This is incredibly absurd and horrible to understand, and myself I've only understood half of that stuff (just enough to make some working mid-frame vertical scrolling in my game after loads of tries). Fortunatly, as long as you just scroll horizontally, things keeps simple.
Note that sprite zero hit isn't limited to scrolling. Actually, you'll have to use it for almost all effects changing anything midframe. You can change the scrolling each scanline inside a timed loop to have various wavy effects, change the colour emphasis or monochrome bit mid-frame and even mid-scanline, turn either BG or sprites (or even both) on and off, turn the left clipping on and off (while I haven't found any interesting use of this), change pattern table used for either BG or sprites, change name table used (this often comes together with horizontal scrolling). You can even turn the whole screen off during some scanline to write stuff to PPU memory through $2006/7 (such as the palette or re-do sprite DMA to have 2 regions with 256 sprites available) and turn the screen back, but this is hard to do proprely and doesn't make much sense in my opinion.