Rad Racer scrolling

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems. See the NESdev wiki for more information.

Moderator: Moderators

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

Rad Racer scrolling

Post by rainwarrior »

I went and traced through Rad Racer to get an idea of how it does its rendering. I thought it was quite interesting, so I wanted to share what I found.


So, the NMI looks like this:

> The frame begins with horizontal mirroring set (done in previous frame).
> Scrolling is set for the sky's parallax.
> Game logic runs while the sky renders.
> When finished executing logic, jump to $0600
> Write first 4 bits to MMC1 mirroring control, preparing to set vertical mirroring (but not yet).
> Spin until sprite 0 hit.
> Sprite 0 is hit (X = #$3E, Y = ~#$74)
> Timed 1-line loops, each writes 2006/2006/2005 in series.
> Timed 2-line loops, the first writes 2006/2006/2005, the second writes 2005
> Write last bit to MMC1 to select vertical mirroring.
> Set up scroll for the bottom section of the road.
> Timed 1-line loop, each writes 2005 (with immediate 2002 after).
> Set MMC1 for horizontal mirroring.
> Set scrolling for the HUD.
> Spin until next NMI.


The arrangement of the nametable is very interesting, and an integral part of the plan. It's essentially static, except for the HUD. It always looks like this:
Image
http://rainwarrior.ca/projects/nes/radr ... etable.png

The sky obviously is meant to wrap horizontally, just a big page that scrolls around on its own for a nice parallax effect, and to put something interesting on the screen while the game executes its logic.

After the sky, there is a series of 1 or 2 line segments. Notice that all the road tiles are arranged into 2-line segments in the second page of the nametable. This controls the appearance of the height curve of the road, 1-line loops give a low slope, 2-line loops give a higher slope (possibly there is a concept here of "0-line" skips for a very low slope). Also note that the area off to the side of the road is a single colour; this way the scroll writes can happen in a wide range of space without causing visible glitches. Writes are usually near the end of a line (Nintendulator is telling me ~219 for the 2005 write in most cases; though I think there is logic in there that times it differently for when the road curves significantly left or right).

Next, the bottom segment of the road is hit. You can see how it is arranged nicely for horizontal wrapping. So, immediately the mirroring is changed, and now it controlls everything through the fine X scroll (2005).

Finally we reset back to horizontal mirroring in preparation for the next frame, and setup the scrolling to display the HUD before finishing out the frame.


The red/white road edges are animated with the palette; they do not change in the nametable.

Another interesting thing is that the render code is stored in RAM at $0600-07FF. The line loops actually overwrite the immediate values in the code that are going to be written to 2006/2005 in the code to set up for the next loop.

Also, it's notable that this isn't really glitch free, but it's designed in such a way that it responds pretty robustly to timing errors. I mentioned the sides of the screen being being a flat colour to help this, but also since the scroll usually only changes by a pixel or two per line, an error here won't usually look too out of place (especially since it's changing every frame anyway). There's actually a very noticable glitch at the switch to vertical mirroring, which shows up very prominently on the right hand side for me on the NES, in Nintendulator it doesn't show up as strongly but you can see it if you get the road turned to the right a bit.

I missed what happens with the bottom 8 lines of the sky; they weren't visible in the frame I traced. Basically it has its own horiziontal scroll, different from the rest of the sky. I presume there is another timed loop that waits until the first line of road.


Anyhow, I hope some of you enjoy this. I sure did. Sorry Bregalad if this mostly reiterates what you said in the other thread.
Last edited by rainwarrior on Sat May 05, 2012 6:19 pm, edited 3 times in total.
User avatar
Dwedit
Posts: 5098
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Post by Dwedit »

Rad Racer 2 used 4-screen mirroring, which really wasn't necessary, but the programmers did not know the sequence of 2005/2006 writes to seemlessly scroll horizontally and vertically every scanline. Instead they reset fine Y to zero every scanline, so they needed more vertical room to do scrolling.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
User avatar
noattack
Posts: 147
Joined: Tue Feb 13, 2007 9:02 pm
Location: Richmond, VA

Post by noattack »

Pretty clever. I've never paid much attention to Rad Racer's scrolling effects, but they're impressive. Nice sense of speed.

Thanks for posting this.
User avatar
Bregalad
Posts: 8115
Joined: Fri Nov 12, 2004 2:49 pm
Location: Divonne-les-bains, France

Post by Bregalad »

Don't worry you analized the things in much more detail than I. And I completely forgot about the lower 8 lines that gets their own scroll value. In level 1 I don't think this has any effect, but in the city levels (2 and 5) this is very visible, as well as in the Grand Canyon level (I think it's 3).
It gives an additional parallax effects to the background, and of course the sprite zero hit is right before this first split point (not right before the start of the road).

It's interesting to see the game was designed to be robust on timing errors. Effectively everything is timed from the sprite zero hit and they had to prevent the status bar from shaking and stuff like that. Considering the tools they had back then it's impressive.

I think the reason Rad Racer uses self-modifying code is because the game was originally written for the FDS. I know there was never any FDS release of the game, but it's pretty obvious it was intended for the FDS : The game engine is heavily based on 3D-Wolrdrunner which originally was a FDS game, and it still uses FDS registers like $100-$103 for it's interrupts.

Also it uses raw uncompressed nametables, which sounds dumb at first, but on the FDS you could store nametables as files and load them directly into VRAM (without loading them in RAM) which the FDS version of 3D worldrunner does.
Useless, lumbering half-wits don't scare us.
User avatar
zeroone
Posts: 939
Joined: Mon Dec 29, 2014 1:46 pm
Location: New York, NY
Contact:

Re: Rad Racer scrolling

Post by zeroone »

@rainwarrior Any idea why 3D mode (Select) doesn't work correctly in Nintendulator?
User avatar
rainwarrior
Posts: 8759
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Rad Racer scrolling

Post by rainwarrior »

zeroone wrote:@rainwarrior Any idea why 3D mode (Select) doesn't work correctly in Nintendulator?
It seems to work normally to me. You probably have frameskip on, or otherwise aren't vsyncing properly or something else? I don't think this has much to do with emulation, just whether you're seeing 60fps properly.
User avatar
zeroone
Posts: 939
Joined: Mon Dec 29, 2014 1:46 pm
Location: New York, NY
Contact:

Re: Rad Racer scrolling

Post by zeroone »

rainwarrior wrote:It seems to work normally to me. You probably have frameskip on, or otherwise aren't vsyncing properly or something else? I don't think this has much to do with emulation, just whether you're seeing 60fps properly.
Leave it running for a minute or 2. Every few seconds I see horizontal bands of color slowly move up the screen. I'll experiment with frame skipping and vsync to see if it makes a difference.
tepples
Posts: 22862
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Rad Racer scrolling

Post by tepples »

zeroone wrote:
rainwarrior wrote:It seems to work normally to me. You probably have frameskip on, or otherwise aren't vsyncing properly or something else? I don't think this has much to do with emulation, just whether you're seeing 60fps properly.
Leave it running for a minute or 2. Every few seconds I see horizontal bands of color slowly move up the screen.
That's tearing. Properly working vsync kills tearing dead. But some display systems and some video drivers require full screen mode in order for vsync to work.
User avatar
zeroone
Posts: 939
Joined: Mon Dec 29, 2014 1:46 pm
Location: New York, NY
Contact:

Re: Rad Racer scrolling

Post by zeroone »

rainwarrior wrote:It seems to work normally to me. You probably have frameskip on, or otherwise aren't vsyncing properly or something else? I don't think this has much to do with emulation, just whether you're seeing 60fps properly.
tepples wrote:That's tearing. Properly working vsync kills tearing dead. But some display systems and some video drivers require full screen mode in order for vsync to work.
Both of you are absolutely correct! It's an illusion on my box. The 3D mode is created by alternating blue and red frames. For some reason, I thought they were merged-color frames, which is probably impossible on the NES. Anyway, Window mode is not vync'd and this was creating what appeared to be bands of color. In full screen mode, that effect is gone. I saw a similar effect in all the other emulators out there. I guess it's just very difficult to get vsync to work in Window mode generally.
User avatar
zeroone
Posts: 939
Joined: Mon Dec 29, 2014 1:46 pm
Location: New York, NY
Contact:

Re: Rad Racer scrolling

Post by zeroone »

On a side note, my original reaction was that it was some sort of NMI timing issue. Nintendulator actually does not pass all the NMI timing tests. I've been trying to debug it to figure out why, but I have yet to find a solution. I would still like to fix it and I welcome suggestions to that end.
User avatar
thefox
Posts: 3134
Joined: Mon Jan 03, 2005 10:36 am
Location: the universe
Contact:

Re: Rad Racer scrolling

Post by thefox »

I'd suggest to turn off frame-skipping entirely (I actually removed the option altogether from NDX).

You can press Ctrl+F to enter frame step mode. Then press Space to step to the next frame. It's pretty useful for diagnosing stuff like you talked about.
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
User avatar
zeroone
Posts: 939
Joined: Mon Dec 29, 2014 1:46 pm
Location: New York, NY
Contact:

Re: Rad Racer scrolling

Post by zeroone »

thefox wrote:I'd suggest to turn off frame-skipping entirely (I actually removed the option altogether from NDX).

You can press Ctrl+F to enter frame step mode. Then press Space to step to the next frame. It's pretty useful for diagnosing stuff like you talked about.
I did just that. And, I also used frame-step to confirm that it was alternating properly between red and blue frames. The purple bands were just an illusion.

This experience suggests that average user may gain the false impression of emulation inaccuracy as consequence of seeing graphical effects like this. Such a user is unlikely to realize that if they switch to full screen mode, everything will look correct. An average user will probably just switch to a "better" emulator. Nonetheless, very few emulators provide vync in windows mode, at least in my environment.
User avatar
thefox
Posts: 3134
Joined: Mon Jan 03, 2005 10:36 am
Location: the universe
Contact:

Re: Rad Racer scrolling

Post by thefox »

Did you have sound turned off by any chance?
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
User avatar
zeroone
Posts: 939
Joined: Mon Dec 29, 2014 1:46 pm
Location: New York, NY
Contact:

Re: Rad Racer scrolling

Post by zeroone »

thefox wrote:Did you have sound turned off by any chance?
I don't think so. Does disabling sound have side effects?
User avatar
thefox
Posts: 3134
Joined: Mon Jan 03, 2005 10:36 am
Location: the universe
Contact:

Re: Rad Racer scrolling

Post by thefox »

zeroone wrote:
thefox wrote:Did you have sound turned off by any chance?
I don't think so. Does disabling sound have side effects?
Nintendulator syncs rendering to sound and if it's turned off (in emulator), it will let it run free. Pretty stupid behavior, to be honest. It should be quite obvious if you had it turned off since the frame rate would go through the roof.

Anyway, that probably wasn't the problem here.
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
Post Reply