How did Zelda scroll?

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

calima
Posts: 1021
Joined: Tue Oct 06, 2015 10:16 am

How did Zelda scroll?

Post by calima » Sun Jun 04, 2017 5:21 am

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.

User avatar
thefox
Posts: 3141
Joined: Mon Jan 03, 2005 10:36 am
Location: Tampere, Finland
Contact:

Re: How did Zelda scroll?

Post by thefox » Sun Jun 04, 2017 5:31 am

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.)
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi

calima
Posts: 1021
Joined: Tue Oct 06, 2015 10:16 am

Re: How did Zelda scroll?

Post by calima » Sun Jun 04, 2017 5:41 am

I did check for the wiki's "two 2006 writes" technique too. The values written to 2006 were constant, despite the screen clearly changing.

Nicole
Posts: 218
Joined: Sun Mar 27, 2016 7:56 pm

Re: How did Zelda scroll?

Post by Nicole » Sun Jun 04, 2017 6:06 am

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.

User avatar
thefox
Posts: 3141
Joined: Mon Jan 03, 2005 10:36 am
Location: Tampere, Finland
Contact:

Re: How did Zelda scroll?

Post by thefox » Sun Jun 04, 2017 6:26 am

Put a breakpoint at $8560. It's writing to $2006 at scanline 63.
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi

User avatar
rainwarrior
Posts: 7680
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: How did Zelda scroll?

Post by rainwarrior » Sun Jun 04, 2017 7:59 am

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...)

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

Re: How did Zelda scroll?

Post by tokumaru » Sun Jun 04, 2017 8:53 am

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.

calima
Posts: 1021
Joined: Tue Oct 06, 2015 10:16 am

Re: How did Zelda scroll?

Post by calima » Sun Jun 04, 2017 11:04 am

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.

calima
Posts: 1021
Joined: Tue Oct 06, 2015 10:16 am

Re: How did Zelda scroll?

Post by calima » Sun Jun 04, 2017 11:06 am

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.

lidnariq
Posts: 8792
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: How did Zelda scroll?

Post by lidnariq » Sun Jun 04, 2017 11:18 am

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.

calima
Posts: 1021
Joined: Tue Oct 06, 2015 10:16 am

Re: How did Zelda scroll?

Post by calima » Sun Jun 04, 2017 11:26 am

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?

User avatar
thefox
Posts: 3141
Joined: Mon Jan 03, 2005 10:36 am
Location: Tampere, Finland
Contact:

Re: How did Zelda scroll?

Post by thefox » Sun Jun 04, 2017 1:37 pm

I can't be bothered to do the math, but note that those two $2007 reads also affect the address (and thus, scroll).
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi

calima
Posts: 1021
Joined: Tue Oct 06, 2015 10:16 am

Re: How did Zelda scroll?

Post by calima » Mon Jun 05, 2017 3:25 am

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?

User avatar
thefox
Posts: 3141
Joined: Mon Jan 03, 2005 10:36 am
Location: Tampere, Finland
Contact:

Re: How did Zelda scroll?

Post by thefox » Mon Jun 05, 2017 8:14 am

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.
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi

tepples
Posts: 21755
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: How did Zelda scroll?

Post by tepples » Mon Jun 05, 2017 8:43 am

And 1-frame jank tends to have been more likely when engineers lacked access to the frame-stepping tools available in the emulator era.

Post Reply