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

How did Zelda scroll?

How did Zelda scroll?
by on (#197357)
I'm having trouble understanding how Zelda scrolls. The docs state mid-screen Y split was not discovered during the commercial era, and my debugging seems to confirm this.

I watched all writes to 2005 and 2006 during screen transitions. Scrolling does not change at any point, not during vblank, not at the bottom of the status bar. When going up/down, there are 32 writes to vram, writing a row of the new tiles, over two frames.

The Zelda commented disassembly online (computerarcheology.com) does not comment on this. I searched nesdev and found nothing more than guesses. Google has nothing.

--

So, it does not scroll, and it does not rewrite an entire nametable. It does not have a mid-screen split. How the heck does it work?

edit: I confirmed the watchpoint also catches (indirect),y writes, so it's not writing to 2005 like that either.
Re: How did Zelda scroll?
by on (#197359)
Pretty sure it changes the scroll with $2006. At least I seem to have debugged it at some point in the past: viewtopic.php?p=153799#p153799

They were able to do Y splits back in the day, just not pixel perfect. (If we discount rare cases like Battletoads, which seems to have managed in some way.)
Re: How did Zelda scroll?
by on (#197360)
I did check for the wiki's "two 2006 writes" technique too. The values written to 2006 were constant, despite the screen clearly changing.
Re: How did Zelda scroll?
by on (#197361)
How are you going about checking which values are written to $2005 and $2006? If you're trying to use something like the Watch feature in Mesen to watch [$2005] and [$2006], keep in mind those are write-only registers, so trying to read from them won't get you anywhere.
Re: How did Zelda scroll?
by on (#197363)
Put a breakpoint at $8560. It's writing to $2006 at scanline 63.
Re: How did Zelda scroll?
by on (#197369)
calima wrote:
The docs state mid-screen Y split was not discovered during the commercial era, and my debugging seems to confirm this.

What docs say that? There's tons of games that clearly know how to Y split. (Super Mario 3, Rad Racer, Battletoads...)
Re: How did Zelda scroll?
by on (#197373)
The $2006/5/5/6 trick wasn't widely known (or at all?), but $2006-only scroll changes were frequently used, which means that games would usually set the scroll to the very top of a tile, and if they wanted pixel precision, they'd use timed code or IRQs to vary the pixel count BEFORE the split.
Re: How did Zelda scroll?
by on (#197390)
Nicole wrote:
How are you going about checking which values are written to $2005 and $2006? If you're trying to use something like the Watch feature in Mesen to watch [$2005] and [$2006], keep in mind those are write-only registers, so trying to read from them won't get you anywhere.


Mednafen shows the contents of registers. For a sta write, I look at the A register.
Re: How did Zelda scroll?
by on (#197392)
thefox wrote:
Put a breakpoint at $8560. It's writing to $2006 at scanline 63.


Yes, that's the target address for the 32 tiles write.
edit: Sample values for that are $22a0, $22c0... Normal nametable addresses that do not make sense with the wiki's two-write 2006 formula. Those were taken from a vertical transition on successive frames.

According to the wiki, that would cause a 2-pixel fine Y scroll. Yet the tiles in Zelda are perfectly 8-aligned.
Re: How did Zelda scroll?
by on (#197395)
calima wrote:
According to the wiki, that would cause a 2-pixel fine Y scroll. Yet the tiles in Zelda are perfectly 8-aligned.
You sure about that? I'm pretty certain I see an offset during the vertical scrolling.
Re: How did Zelda scroll?
by on (#197398)
Took fresh screenshots, and there's indeed an offset - 5 pixels. Which is not possible according to the wiki, which says the high fine Y bit is cleared, or to the written value which would result in a 2-pixel offset.

Okay, then it's indeed that write and I'm just confused. But why the offset discrepancy?
Re: How did Zelda scroll?
by on (#197422)
I can't be bothered to do the math, but note that those two $2007 reads also affect the address (and thus, scroll).
Re: How did Zelda scroll?
by on (#197481)
I've been thinking about how the writes are an exact match to nametable addresses. Did the Zelda programmers believe it should be a nametable address, and take the fine Y offset as an unavoidable quirk?

Have official NES docs been leaked? Or, do other double-2006 games also write nametable addresses, ie the high nibble being 2?
Re: How did Zelda scroll?
by on (#197509)
calima wrote:
I've been thinking about how the writes are an exact match to nametable addresses. Did the Zelda programmers believe it should be a nametable address, and take the fine Y offset as an unavoidable quirk?

I'm guessing a fair bit of trial and error was involved. There are some bugs which they could've avoided. E.g., when the screen starts to scroll up, it first yanks downwards for one frame. Likewise, when the screen scrolls down, at the end of the scroll it scrolls a bit too far, and then corrects itself.
Re: How did Zelda scroll?
by on (#197514)
And 1-frame jank tends to have been more likely when engineers lacked access to the frame-stepping tools available in the emulator era.
Re: How did Zelda scroll?
by on (#197515)
I heard developers used VHS recordings to do frame-by-frame debugging.