$4016 strobing

Strictly for discussing ZSNES development and for submitting code. You can also join us on IRC at irc.libera.chat in #zsnes.
Please, no requests here.

Moderator: ZSNES Mods

Post Reply
byuu

$4016 strobing

Post by byuu »

http://nesdev.parodius.com/bbs/viewtopi ... 4026#14026

Disch> I remember hearing about this a while back -- from what I recall, when the strobe bit is set, reading $4016/7 will return in real-time status of the first button (A button).

blargg> Disch recalls correctly. When strobe bit is left at 1, reading the joypad status returns the current A button status at the time of the read, not the A button status when you set strobe.

---

Obviously, the NES and SNES controller interface is virtually identical, even using the same registers ($4016/$4017) and the same strobing mechanism. Just a different key order.

So, has anyone found out whether this was applicable to the SNES as well. And better yet, has anyone emulated this?

Some interesting info there. I also read that having the PPU turned off will result in the one-dot-short line on odd frames, scanline 240 non-interlace mode not being a dot short after all. However, I don't believe this is the case with the SNES. But another good test to see if these NES findings apply to the SNES as well.
blargg
Regular
Posts: 327
Joined: Thu Jun 30, 2005 1:54 pm
Location: USA
Contact:

Post by blargg »

The missing clock occurs every other frame when the NES PPU is on. The visual effect is to shift the color burst phases of each scanline between two values, lessening the visual artifacts. The SNES colorburst has the same characteristics and might have a similar extra/missing (~5.37 MHz) clock every other frame, or its video circuitry might be more advanced than the super-simple one the NES uses, eliminating the need for this. An accurate timing test should reveal which it is pretty easily.
byuu

Post by byuu »

Ah, so that's what it's for. I can't tell you how long I tried to figure out what the hell was up with that missing dot, and how much I doubted it even existed when I first heard about it >_<

So, one PPU dot is 1/4th of 21mhz, one color cycle is 1/6th of 21mhz core timing crystal.

6*4=24 && 1/4*24=6 && 1/6*24=4

PPU { [0], 6, [12], 18, [24] }
Color subcarrier { [0], 4, 8, [12], 16, 20, [24] }

My logic sucks, but by skipping the one dot every other frame, it's causing there to be two (or three?) different color phases, and the actual color phase only changes after every TWO fields (since it's non-interlace and it doesn't skip a dot on even fields). I'm thinking that means there are two separate color phase differences when rendering the image.

I imagine interlace mode avoids the "missing dot" because of the fact that instead of 262 scanlines * 341 dots (=178684, an even number of dots), the 525*341=179025, an odd number. So it's actually inverting the color phase every two fields anyway as a result.

And that means this needs to be tested in interlace mode as well. If non-interlace has the extra dot in non-interlace with the PPU off, then interlace will have an extra dot or a missing dot (likely a missing dot) when the PPU is off.
blargg
Regular
Posts: 327
Joined: Thu Jun 30, 2005 1:54 pm
Location: USA
Contact:

Post by blargg »

For the NES PPU, it's a little more involved. There is an internal 12-phase color generator that's clocked at ~42.95 MHz (it's clocked on both edges of the ~21.48 MHz clock). It's never reset (as far as I know), so the colorburst phase for the first scanline of successive frames depends on the number of color generator clocks each frame is, MOD 12.

On the NES PPU, each of the 262 scanlines is normally 341 PPU clocks. Multiply by 8 to get ~42.95 MHz clocks = 714736 color generator clocks per frame. That MOD 12 = 4. So the colorburst phase of the first scanline would shift by 1/3 (120 degrees) between successive frames, and this is what happens if you disable the NES PPU at just the right time every frame when it would otherwise skip a PPU clock every other frame (Battletoads unintentionally does this during game play).

Having the colorburst go through three different phases makes the screen have a noticeable color artifact pattern that moves upwards. By skipping a clock every other frame, the color phase is made to toggle between only two values, making the artifact pattern more stable and less-noticeable. If the SNES equivalent to the color phase generator can have its phase directly set, then no skipped clock would be necessary. I wouldn't be surprised if Nintendo kept the skipped clock in there for better compatibility with code ported from the NES.
Post Reply