Matrix multiplication / 3D demo

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

Moderator: Moderators

Post Reply
User avatar
abonetochew
Posts: 34
Joined: Mon Sep 20, 2004 4:07 pm
Location: South Dakota

Matrix multiplication / 3D demo

Post by abonetochew » Sun Jan 02, 2005 8:06 pm

I haven't had anything else to do for the last three days, so I put together a little 3D demo for the NES. The methods I used are far from optimal, but the code seems to be stable and runs correctly on every emulator I've tested.

Features include:
- 1-8 moving objects, selectable
- 1-3 axes of rotation, selectable
- hex display of rotation matrix
- frame rate counter

Framerate ranges from 6 to 60 FPS, depending on how many objects and how many matrices are in use. I do plan to rewrite this sometime in the future to use a faster multiplication algorithm, and faster 3D transformations. (I really need to get into GBA assembly...)

The ROM is available on my temporary website. (my main website is currently being redesigned)

Would anyone with an NROM devcart be willing to test this on hardware?
- abonetochew

doynax
Posts: 162
Joined: Mon Nov 22, 2004 3:24 pm
Location: Sweden
Contact:

Re: Matrix multiplication / 3D demo

Post by doynax » Sun Jan 02, 2005 8:49 pm

Nice work, I'm impressed! There's nothing quite like watching hex dumps in a tech-demo =)

The depressing thing is that there's some insane C64 demos out there than beat the crap out of anything we mere mortals could ever write. Dawnfall somehow manages to rotate 250 points in full framerate on a machine half as fast..

User avatar
Memblers
Site Admin
Posts: 3878
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Post by Memblers » Mon Jan 03, 2005 6:45 am

Awesome! I wanted to write something like this a while back, but I suck too much at math. I tried, but only ended up with some neat sinewave-based 2D patterns, heheh.

I'll test this on my cart later and let you know how it went. I might be able to make it run faster, it could be a good test for Squeedo's hardware multiplier feature.

User avatar
Memblers
Site Admin
Posts: 3878
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Post by Memblers » Mon Jan 03, 2005 11:20 am

It works. I'll try something to speed it up a little.

User avatar
abonetochew
Posts: 34
Joined: Mon Sep 20, 2004 4:07 pm
Location: South Dakota

Post by abonetochew » Mon Jan 03, 2005 3:43 pm

Yay! I've written a NES demo that actually works on hardware! Happiness! Glee!
... Now that I'm done with that, where might I be able to find some of these C64 demos? I need to study the techniques of the immortal coders...
- abonetochew

User avatar
Memblers
Site Admin
Posts: 3878
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Post by Memblers » Mon Jan 03, 2005 3:54 pm

There were some really good 3D articles in a few C=Hacking issues also (I forgot which ones, there's an index tho).
http://www.ffd2.com/fridge/chacking/

doynax
Posts: 162
Joined: Mon Nov 22, 2004 3:24 pm
Location: Sweden
Contact:

Post by doynax » Mon Jan 03, 2005 4:49 pm

abonetochew wrote:Yay! I've written a NES demo that actually works on hardware! Happiness! Glee!
... Now that I'm done with that, where might I be able to find some of these C64 demos? I need to study the techniques of the immortal coders...
Try watching through the top demos at http://noname.c64.org/csdb.
Seeing Deus Ex Machina for the first time is something of a revelation, I just didn't want to believe it was possible until I saw it on hardware.
Oh, and I meant One-Der, not Dawnfall (both are 64 kB intros by Oxyron).

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

Post by thefox » Tue Jan 04, 2005 11:07 am

An ok demo, tho I think much more could be taken out of NES 3D-wise :)

It's not worth comparing NES with C64... they're pretty different. NES was designed to be easy to write games with, whereas C64 (as it seems to me) is much more versatile. There's also much more information for C64 available and also many more developers developing for C64.

RoboNes
Posts: 48
Joined: Mon Sep 20, 2004 6:47 am

Post by RoboNes » Wed Jan 05, 2005 7:09 am

and ever important the c64 has MUCH more ram available

User avatar
abonetochew
Posts: 34
Joined: Mon Sep 20, 2004 4:07 pm
Location: South Dakota

Post by abonetochew » Wed Jan 05, 2005 6:25 pm

I rewrote my multiplier subroutine, and the demo now runs at 15 FPS at XYZ/8.

old routine:
sign-extend mul_a and mul_b from 16 to 32 bits
loop through the 32-bit add-and-shift loop 32 times

new routine:
don't sign-extend
if mul_a is negative, negate it and toggle neg_flag
if mul_b is negative, negate it and toggle neg_flag
loop through the hybrid 16/32 bit add-and-shift loop 16 times
if neg_flag is set, negate mul_c

I still think there has got to be a better way to multiply 8.8 fixed point numbers (without using any cartridge hardware), but I'm not going to figure it out any time soon. I'm also going to restructure the 3D "pipeline" to avoid those nasty 27-multiply matrix operations. This would be a lot easier if I had sources for some of those C64 demos to leech off of. :)
- abonetochew

doynax
Posts: 162
Joined: Mon Nov 22, 2004 3:24 pm
Location: Sweden
Contact:

Post by doynax » Wed Jan 05, 2005 6:49 pm

abonetochew wrote:I still think there has got to be a better way to multiply 8.8 fixed point numbers (without using any cartridge hardware), but I'm not going to figure it out any time soon. I'm also going to restructure the 3D "pipeline" to avoid those nasty 27-multiply matrix operations. This would be a lot easier if I had sources for some of those C64 demos to leech off of. :)
How about combining a couple of these (http://www.ffd2.com/fridge/math/fastmult) 8-bit multiplies?
Do you really need 16-bit precision at all? The vertices really shoudn't need them and a rotation matrix should only contain fractional values (almost anyway).

There's a proud tradition in the C64 scene of disassembling the works of the masters instead of giving out source codes.
Otherwise there's an explanation of the plotter from One-Der somewhere on the CSDB forum, I'll do a quick scan over the topics list and see if I can find it for you. I don't think it actually did any multiplies at all (per vertex anyway) but had everything precalculated instead.

edit: I managed to find the relevant thread (http://noname.c64.org/csdb/forums/?room ... 3369#13381).
Apparently everything is based on LUTs, there's no perspective at all, it's uses a bunch of speedcode, there's no pixel masking, and the display mode is hacked togheter with raster interrupts. Neat =)

Post Reply