Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 14:12 28 Apr 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : CMM2: 270.000 lines of code per second, question

     Page 2 of 2    
Author Message
capsikin
Guru

Joined: 30/06/2020
Location: Australia
Posts: 341
Posted: 05:03am 21 Jul 2020
Copy link to clipboard 
Print this post

  berighteous said  Does the CMM2 processor have hardware math?  The horrible soul crushing experience with AppleSoft basic is that 6502 had no math above addition and subtraction, so doing something like this plot

takes several HOURS to draw.  

Here's the applesoft code for this:
10 GOTO 40
20 XE = - X * S1 + Y * C1 : YE = -X * C1 * C2 - Y* S1 * C2 + Z * S2 : ZE = - X * S2 * C1 - Y *S2 * S1 + Z * C2 + RHO
30 SX = D * XE / Z E + CX : SY = CY - D * YE / Z E :RETURN
40 RHO = 30 : D = 350 : THETA = .1 : PHI = 1 : CX =140 : CY = 96 : S1 = SIN (THETA) : S2 = SIN(PHI) : C1 = COS (THETA) : C2 = COS (PHI)
50 DEF FN Z(X) = COS (.1 * (X * X + Y * Y))
60 HGR2 : HCOLOR= 3
70 FOR X = -20 TO 20 STEP .3
80 FL = 0
90 FOR Y = - 20 TO 20 STEP .07
100 Z = FN Z(X): GOSUB 20
110 IF SX < 0 OR SX > 279 OR SY < 0 OR SY > 191 THEN FL = 0 : GOTO 140
120 IF FL = 0 THEN FL = 1 : HPLOT SX,SY
130 HCOLOR=3:HPLOT SX,SY:HCOLOR=0:HPLOT SX,SY+1 TO SX,191
140 NEXT Y,X
150 PRINT CHR$(7):GET Q$:TEXT

Even in AppleWin on full speed (like 100x apple native) it took a few minutes to do.


I modified it to run on the CMM2 and it took about 15 seconds.


starttime=timer

10 GOTO 40
20 XE = - X * S1 + Y * C1 : YE = -X * C1 * C2 - Y* S1 * C2 + Z * S2 : ZE = - X * S2 * C1 - Y *S2 * S1 + Z * C2 + RHO
30 SX = D * XE / ZE + CX : SY = CY - D * YE / ZE :RETURN
40 RHO = 30 : D = 350 : THETA = .1 : PHI = 1 : CX =140 : CY = 96 : S1 = SIN (THETA) : S2 = SIN(PHI) : C1 = COS (THETA) : C2 = COS (PHI)

' 50 DEF FN Z(X) = COS (.1 * (X * X + Y * Y))
FUNCTION FNZ(X)
 FNZ = COS (.1 * (X * X + Y * Y))
END FUNCTION

'60 HGR2 : HCOLOR= 3

70 FOR X = -20 TO 20 STEP .3
80 FL = 0
90 FOR Y = - 20 TO 20 STEP .07
100 Z = FNZ(X): GOSUB 20
110 IF SX < 0 OR SX > 279 OR SY < 0 OR SY > 191 THEN FL = 0 : GOTO 140
120 IF FL = 0 THEN FL = 1 : PIXEL SX,SY
'130 HCOLOR=3:HPLOT SX,SY:HCOLOR=0:HPLOT SX,SY+1 TO SX,191
PIXEL SX,SY : LINE SX,SY+1, SX,191,,255 ' Colour 255 is blue, so I can see where it's drawing.
140 NEXT Y,X
'150 PRINT CHR$(7):GET Q$:TEXT
print @(0,200) "Time: ";timer-starttime
 
berighteous
Senior Member

Joined: 18/07/2020
Location: United States
Posts: 110
Posted: 08:53am 21 Jul 2020
Copy link to clipboard 
Print this post

SWEET!  Thanks.
yeah, I had it plotting a dot in white and then drawing a black line down to the bottom of the screen to clear out anything under it to clean up the plot. The program came originally from "Microcomputer Graphics: by Roy E. Meyers 1982

I ordered my CMM2 on 7/2 from RicTech but it hasn't shipped yet.  I paid for the shipping upgrade to EMS so it should move faster and be trackable when it starts moving though!
 
mkopack73
Senior Member

Joined: 03/07/2020
Location: United States
Posts: 261
Posted: 12:24pm 21 Jul 2020
Copy link to clipboard 
Print this post

  abraxas said  CMM2 definitely has hardware for floating point calculations. Whether the implementation of trig functions in MMBasic is speedy I don't know. Just port and test it. However, with the amount of RAM that CMM2 gives you it's trivial to optimize this by precalculating and storing SIN/COS outputs for a quarter of the circle to the accuracy that is required and then the cost of trig functions will be that of a lookup in an array. You can make this run on a CMM2 in seconds. Maybe faster.


Actually I just ran a little test - generated sin+cos using the MMBAsic functions for all
Integer angles from 0 to 90. Then regenerated then and put them into a 2D array (one column for sin one for cos). Then timed how long it would take to lookup the sin and cos for all 0-90 from the table.


Math functions took 2.212 ms
Look up table took 2.742 ms

So I’d say use the math functions!
 
berighteous
Senior Member

Joined: 18/07/2020
Location: United States
Posts: 110
Posted: 04:47pm 21 Jul 2020
Copy link to clipboard 
Print this post

the remembered to convert degrees to radians before you calculated sines and cosines, right?
 
mkopack73
Senior Member

Joined: 03/07/2020
Location: United States
Posts: 261
Posted: 06:08pm 21 Jul 2020
Copy link to clipboard 
Print this post

  berighteous said  the remembered to convert degrees to radians before you calculated sines and cosines, right?


Yes.

With the math functions version I do that conversion on the fly (in the loop)

With the table lookup I do it when populating the table not when performing the lookup. Which just shows how much slower the lookup is in that it’s not even having to perform the conversion to radians first.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8582
Posted: 02:20pm 26 Jul 2020
Copy link to clipboard 
Print this post

New record with 5.05.04RC12. berighteous' code now takes 10.78 seconds



Edited 2020-07-27 00:25 by matherp
 
diabolus
Newbie

Joined: 25/05/2020
Location: United Kingdom
Posts: 12
Posted: 02:18am 12 Jun 2021
Copy link to clipboard 
Print this post

Necro thread bump, using the latest firmware posted in the last few days. Running a Circuit Gizmos Color Maximite 2 at 504Mhz.

Averages ~505,000



Edited 2021-06-12 12:19 by diabolus
 
     Page 2 of 2    
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024