mode7 like f-zero

Discussion of hardware and software development for Super NES and Super Famicom.

Moderator: Moderators

Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
alekmaul
Posts: 54
Joined: Tue Apr 24, 2012 12:22 pm
Contact:

mode7 like f-zero

Post by alekmaul » Tue Apr 24, 2012 12:34 pm

Hello all,
I'm new here but not new for gba/nds homebrews (http://www.portabledev.com).
Very nice forum with lot's of information regarding SNES.
Some times ago, a french friend wanted to test some snes programming with C source code, so i began to do a snes lib based on snes sdk.
You can see my work here : http://www.portabledev.com/wiki/doku.php
Currently, it works fine with mode1/mode3, scrolling, input, sprite.
Here is my question : I begin to work on mode7 and i can do rotation / scaling but I have no idea to do something like F-ZERO or Mario Kart ...
It seems a little different than on GBA or SNES because I can't use HBL interrupt ...
I did a VBL interrupt like I saw in SNES wiki (to manage A..D Matrix , and so on ..) but i really don't know how can I simulate a ground like in F-ZERO or Mario Kart (or like in Squaresoft Mode 7 Demo).
Please, can someone help me doing such effect ?

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

Post by tepples » Tue Apr 24, 2012 1:01 pm

I'm pretty sure that what they use is HDMA to change the rotation matrix after each scanline. At least that's how the "mode 7" effect is done in GBA mode 1.

User avatar
Bregalad
Posts: 7808
Joined: Fri Nov 12, 2004 2:49 pm
Location: Chexbres, VD, Switzerland

Post by Bregalad » Tue Apr 24, 2012 1:08 pm

There is a HBL interrupt on the SNES, but it's rarely used - HDMA is more commonly used, so that you can change the scaling factor each scanline, and make the map progressively larger as it goes down to the screen, for the amazing 3D effect.

You just need to find doccumentation about HDMA - which is DMA that can be programmed to write to registers automatically at the end of the desired scanline (in our case, you'd want to write matrix coefficient).

I'm not sure if the SNES is fast enough to handle interrupts every scan line - especially if programmed in C, so I really think HDMA is a better approach. Interrupt would be the way to go if you only change a register once in the middle of the screen, and it would waste a HDMA channel for only a signle write.
Life is complex: it has both real and imaginary components.

alekmaul
Posts: 54
Joined: Tue Apr 24, 2012 12:22 pm
Contact:

Post by alekmaul » Tue Apr 24, 2012 9:50 pm

thanks for reply, didn't think that HDMA was for Horizontal DMA, so stupid am I :oops:
Will see if http://wiki.superfamicom.org/snes/show/ ... n+the+SNES is useful for that.

wiiqwertyuiop
Posts: 19
Joined: Tue Apr 17, 2012 8:30 am

Post by wiiqwertyuiop » Wed Apr 25, 2012 8:16 pm

Also I'm not sure about F-Zero, but Mario Kart used the DSP-1 for it's mode 7 effects.

alekmaul
Posts: 54
Joined: Tue Apr 24, 2012 12:22 pm
Contact:

Post by alekmaul » Wed Apr 25, 2012 9:37 pm

yes, certainly, it required the specfici dsp1 rom with no$sns.
But now, i begin to have something that works with HDMA :).

Image

Just need to know how to add background like sky in FZero, certainly also with HDMA and correct registers.

User avatar
MottZilla
Posts: 2832
Joined: Wed Dec 06, 2006 8:18 pm

Post by MottZilla » Wed Apr 25, 2012 9:56 pm

I think for that you change screen settings part way down the screen, perhaps the screen mode itself. You could always watch F-Zero in a debugger to find out.

smkd
Posts: 101
Joined: Sun Apr 22, 2007 6:07 am

Post by smkd » Thu Apr 26, 2012 12:40 am

That's right. You can set up a channel to write the BG modes you want to $2105 for different parts of the screen. For a game like F-Zero with mode 1 at the top and mode 7 at the bottom, you only have to change $2105 once in the middle of the frame. The IRQ method can also work well for that since it's only needed once so it won't add any real slowdown and will save you a channel for something else.

alekmaul
Posts: 54
Joined: Tue Apr 24, 2012 12:22 pm
Contact:

Post by alekmaul » Thu Apr 26, 2012 1:06 am

OK, thanks, will try that.
HDMA is a really great feature for the Snes :)

User avatar
Bregalad
Posts: 7808
Joined: Fri Nov 12, 2004 2:49 pm
Location: Chexbres, VD, Switzerland

Post by Bregalad » Thu Apr 26, 2012 4:05 am

wiiqwertyuiop wrote:Also I'm not sure about F-Zero, but Mario Kart used the DSP-1 for it's mode 7 effects.
The DSP1 is not necessarly to do mode 7 effects.
I think it was used to speed up the calculations to know the distance between the karts and things like that. I'm not too sure cause I haven't reverse engineered SMK, but I'm sure it's possible to do 3D style effects without using a DSP1.
Life is complex: it has both real and imaginary components.

smkd
Posts: 101
Joined: Sun Apr 22, 2007 6:07 am

Post by smkd » Thu Apr 26, 2012 7:48 am

F-Zero had tables in ROM for each angle they wanted visible. The game just points the HDMA source to the entry for the visible angle on screen. The camera only rotates on a single dimension when racing so that helps keep the number of table entries reasonable. It's limiting though depending on what flexibility you want in your game. You wouldn't get away with that method if you wanted something like Pilotwings. Too many tables for each possible angle if you wanted to avoid calculating anything in real time.

Mario Kart had a similar approach even though it had a DSP1. They used the chip to build all the needed mode 7 tables once and stored them all in RAM. They get pointed to for HDMA similar to how F-Zero does it. Even though the DSP1 can do the mode 7 setup faster than the SNES, it still takes a while to actually get the results from the chip into RAM so I'm guessing that's why they precomputed everything. It's doing all of that when the "Nintendo" logo appears on startup if you want to see in a debugger. This method doesn't need a DSP1 obviously and it avoids excessive ROM usage too. Both F-Zero and Mario Kart had the same limits camera rotation so they could get away with this type of shortcut.

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

Post by tepples » Thu Apr 26, 2012 8:08 am

How many angles do those games use, and how many scanlines are in each table?

smkd
Posts: 101
Joined: Sun Apr 22, 2007 6:07 am

Post by smkd » Fri Apr 27, 2012 5:38 am

I haven't touched F-Zero in a while and I forgot what it used. F-Zero's track animation when you rotate is pretty jittery and the sprite animation doesn't look good either so they (understandably) cut corners there compared to SMK. I know SMK had 48K of RAM used for mode 7 plus some extra data for the overhead map view. It gets 128 angles worth of tables from the chip and only saves 2 of the ABCD parameters. Each one is 96 lines large so 128 * 96 * 2 = 24K each or 48K total for the 2 parameters.

User avatar
MottZilla
Posts: 2832
Joined: Wed Dec 06, 2006 8:18 pm

Post by MottZilla » Fri Apr 27, 2012 9:04 am

Does that mean SMK doesn't use the DSP chip after this table is precomputed?

Edit: Nevermind, it apparently does.

User avatar
Bregalad
Posts: 7808
Joined: Fri Nov 12, 2004 2:49 pm
Location: Chexbres, VD, Switzerland

Post by Bregalad » Fri Apr 27, 2012 12:01 pm

I don't really understand this approach.
If I were to program something like that I'd definitely do all the calculations in real time.

OK multiplications aren't so fast on 65xxx processors, and you have to compute 4 matrix coefficient for every scanline, but because of the symety of a rotation/scaling matrix, only 2 have to be computed, so there is 128 scanlines that 256 multiplications to do.

However I'm sure there is ways to cheat and makes the multiplications faster, and that way you're not limited in angles and all this stuff.

Also you could change the scaling factor only every 2 scanlines or so. Maybe it wouldn't look as great, but it would half the number of multiplications.
Life is complex: it has both real and imaginary components.

Post Reply