Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
 Welcome to our latest new user Harvey ! (Registered 2024-11-25) You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > SID to calculate line slope
2010-08-16 08:38
TWW

Registered: Jul 2009
Posts: 545
SID to calculate line slope

To calculate a slope of a line you can use something like:


lda DeltaX
NoChange:
tax
(Plotpixel)
sec (Might not be neccessary if done right...)
txa
sbc DeltaY (Immediate)
bcs NoChange
(Change shit)
adc DeltaX (Immediate)
jmp NoChange

Which gives 11/15 cycles for each calculation/pixel(Oswald do you agree?^^). If unrolling one would have to add a cycle on the sbc/adc by use of ZP instead of Immediate values which means 12/14 cycles (No jmp if unrolled).

This is pretty good. In fact the two things I see as a possible optimalisation here is getting rid of the SEC by use of clever programming and the ADC DeltaX if you scale the relation between DeltaX and DeltaY so that the largest value = 256. You would require a division and mayhaps you get reduced accuracy (not confirmed though). Looking aside from the div. (tables perhaps?!) you'll end up with 9/11 (10/9 if unrolled(need to watch the branching here and build the routine so that you'd get a 9/10 instead) cycles fully optimized. (Am I missing something?)

However...


I read somewhere (Can't remeber where) that there is a technique where you can use the SID to calculate slopes. The SID is the chip i know the least about so I figgured I'd post here the folowing questions:

#1: Can it be done?
#2: If yes, How?
#3: How much time would the calc. use?

-TWW
 
... 10 posts hidden. Click here to view all posts....
 
2013-07-02 08:27
Rastah Bar
Account closed

Registered: Oct 2012
Posts: 336
So how many cycles per pixel are needed on average if you include EVERYTHING (initialization, slope calculation, changing bitmask, changing gfx pointer for plotting)?

I guess I need about 30-35 cycles per pixel in TOTAL when drawing 12 lines of a cube on a single color 128x128 pixel character screen. I do not unroll the loops and my code does not run in ZP.(For slope calculations I do not use the log/exp method, but just a plain divide. I should change that :-) ).
2013-07-02 09:18
Bitbreaker

Registered: Oct 2002
Posts: 504
Hard to give exact values, but for a cube in said size it is possible to render it > 50fps while even moving the 16x16 grid across the screen.
With all overhead i need around 9900 cycles per frame (without clear). If you know about the average linelength you can find out how many cycles i need for a pixel :-)
2013-07-02 10:57
Rastah Bar
Account closed

Registered: Oct 2012
Posts: 336
Sorry, but I don't understand how 9900 cycles is possible.
ora (ZP),y
sta (ZP),y
for the plotting is already 11 cycles. With the 9/10 cycles mentioned above we have at least 20 cycles per pixel. And this does not include any overhead, changing of bitmask etc.

12 lines times 50 pixels per line times 20 cycles is already 12000 cycles.
2013-07-02 11:02
chatGPZ

Registered: Dec 2001
Posts: 11360
so you just found out the trick is not doing that per pixel =P
2013-07-02 11:03
Bitbreaker

Registered: Oct 2002
Posts: 504
There's also horizontal lines and hidden surface removal done, the latter is something i include, but reading again that you draw 12 lines, it seems you draw all lines of the cube.
Also one can forgo on the ora if it is sure that the line is out of reach of other lines (what would cause clashes).
2013-08-01 16:18
Rastah Bar
Account closed

Registered: Oct 2012
Posts: 336
I made some improvements to my code and can draw and rotate 12 lines ("a cube") at about 30-35 fps.

Rotations about x,y, or z axes are over a fixed small angle though (of about 7 degrees). This I do to make the rotations fast. The angle is chosen such that sin(phi)=1/8, then cos(phi) is very close to 1-1/128-1/32768. Further, suppose you rotate first around the x-axis and then around the z-axis, then you can write:

x(i+2)=z(i)+(x(i+1)-z(i+1))*cos(phi)
y(i+2)=y(i)+(x(i+1)-z(i+1))*sin(phi)

where e.g. y(i) is the y-coord after the i-th rotation.
Now you need to calculate only 2 cos/sin terms, while with the rotation matrix there are 4 of such terms.

Similar equations can be derived for 2 consecutive rotations around any 2 axes.
Previous - 1 | 2 - Next
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
Flex/Artline Designs
A3/AFL
Six/G★P
The Syndrom/TIA/Pret..
Alakran_64
Bob/Censor Design
Critikill (CK)/S16 ^..
kbs/Pht/Lxt
dyme
TheRyk/MYD!
Fresh
Thunder.Bird/HF/MYD!..
Laurikka
Jak T Rip/DMAgic
encore
Holy Moses/Role
JEZ
Guests online: 184
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Coma Light 13  (9.7)
4 The Demo Coder  (9.6)
5 Edge of Disgrace  (9.6)
6 Mojo  (9.6)
7 What Is The Matrix 2  (9.6)
8 Uncensored  (9.6)
9 Wonderland XIV  (9.6)
10 Comaland 100%  (9.6)
Top onefile Demos
1 Layers  (9.6)
2 Party Elk 2  (9.6)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.6)
5 Libertongo  (9.5)
6 Rainbow Connection  (9.5)
7 Onscreen 5k  (9.5)
8 Morph  (9.5)
9 Dawnfall V1.1  (9.5)
10 It's More Fun to Com..  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Nostalgia  (9.3)
5 Triad  (9.2)
Top Fullscreen Graphicians
1 Joe  (9.7)
2 Veto  (9.6)
3 Facet  (9.6)
4 The Sarge  (9.6)
5 Carrion  (9.5)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.043 sec.