It is currently Thu Jun 22, 2017 9:32 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Rad Racer scrolling
PostPosted: Sun Feb 05, 2012 3:25 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5303
Location: Canada
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/radracer_nametable.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.

Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 05, 2012 3:44 pm 
Online
User avatar

Joined: Fri Nov 19, 2004 7:35 pm
Posts: 3875
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!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 05, 2012 4:59 pm 
Offline
User avatar

Joined: Tue Feb 13, 2007 9:02 pm
Posts: 147
Location: Richmond, VA
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.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 05, 2012 10:35 pm 
Offline
User avatar

Joined: Fri Nov 12, 2004 2:49 pm
Posts: 7073
Location: Jongny, VD, Switzerland
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.

_________________
Life is complex: it has both real and imaginary components.


Top
 Profile  
 
 Post subject: Re: Rad Racer scrolling
PostPosted: Mon Feb 29, 2016 1:33 pm 
Offline
User avatar

Joined: Mon Dec 29, 2014 1:46 pm
Posts: 685
Location: New York, NY
@rainwarrior Any idea why 3D mode (Select) doesn't work correctly in Nintendulator?


Top
 Profile  
 
 Post subject: Re: Rad Racer scrolling
PostPosted: Mon Feb 29, 2016 4:14 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5303
Location: Canada
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.


Top
 Profile  
 
 Post subject: Re: Rad Racer scrolling
PostPosted: Mon Feb 29, 2016 4:22 pm 
Offline
User avatar

Joined: Mon Dec 29, 2014 1:46 pm
Posts: 685
Location: New York, NY
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.


Top
 Profile  
 
 Post subject: Re: Rad Racer scrolling
PostPosted: Mon Feb 29, 2016 4:27 pm 
Online

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 18510
Location: NE Indiana, USA (NTSC)
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.


Top
 Profile  
 
 Post subject: Re: Rad Racer scrolling
PostPosted: Mon Feb 29, 2016 4:31 pm 
Offline
User avatar

Joined: Mon Dec 29, 2014 1:46 pm
Posts: 685
Location: New York, NY
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.


Top
 Profile  
 
 Post subject: Re: Rad Racer scrolling
PostPosted: Mon Feb 29, 2016 4:36 pm 
Offline
User avatar

Joined: Mon Dec 29, 2014 1:46 pm
Posts: 685
Location: New York, NY
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.


Top
 Profile  
 
 Post subject: Re: Rad Racer scrolling
PostPosted: Mon Feb 29, 2016 11:35 pm 
Offline
User avatar

Joined: Mon Jan 03, 2005 10:36 am
Posts: 2835
Location: Tampere, Finland
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: kkfos.aspekt.fi


Top
 Profile  
 
 Post subject: Re: Rad Racer scrolling
PostPosted: Tue Mar 01, 2016 7:40 am 
Offline
User avatar

Joined: Mon Dec 29, 2014 1:46 pm
Posts: 685
Location: New York, NY
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.


Top
 Profile  
 
 Post subject: Re: Rad Racer scrolling
PostPosted: Tue Mar 01, 2016 7:49 am 
Offline
User avatar

Joined: Mon Jan 03, 2005 10:36 am
Posts: 2835
Location: Tampere, Finland
Did you have sound turned off by any chance?

_________________
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: kkfos.aspekt.fi


Top
 Profile  
 
 Post subject: Re: Rad Racer scrolling
PostPosted: Tue Mar 01, 2016 7:51 am 
Offline
User avatar

Joined: Mon Dec 29, 2014 1:46 pm
Posts: 685
Location: New York, NY
thefox wrote:
Did you have sound turned off by any chance?


I don't think so. Does disabling sound have side effects?


Top
 Profile  
 
 Post subject: Re: Rad Racer scrolling
PostPosted: Tue Mar 01, 2016 8:15 am 
Offline
User avatar

Joined: Mon Jan 03, 2005 10:36 am
Posts: 2835
Location: Tampere, Finland
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: kkfos.aspekt.fi


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next

All times are UTC - 7 hours


Who is online

Users browsing this forum: Bing [Bot] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group