Jump to content
IGNORED

Death Star for Missing Link


Recommended Posts

Someone on my Mastodon list posted a mathematical program for the BBC to render the Death Star. I like this sort of thing, so I ported it to the TI under The Missing Link. ;) Meant to post it here. I used XB 2.9 GEM and The Missing Link in 2 color mode. ;)

It could, of course, be optimized a fair bit, and not sure I got everything perfect, but I was happy with it.

image.png.1a075b9a57de1242448389c5584dff48.png

100 REM Death Star by Electron Greg
110 REM Adapted by Tursilion - 256x192 version - unoptimized
120 REM TIXB with Missing Link
130 DIM AR(300)
180 DEF RAND(X)=INT(RND*X)+1
210 REM prepare lookup table
215 V=640 :: Z=522 :: R=300
220 A=2*PI/300 :: S=SIN(A):: C=COS(A):: X=R :: Y=0
222 FOR W=1 TO 300
224 B=X*C-Y*S :: Y=X*S+Y*C :: X=B :: AR(W)=600-(V+X)
226 NEXT W
230 CALL LINK("CLEAR")
232 CALL SCREEN(2)
234 CALL LINK("COLOR",8,2)
239 REM draw globe
240 FOR N=115 TO 210 :: REM latitude
250 CALL PROCC(64,(1080-(AR(219-N)*7))/5,AR(N)/2.5,N)
260 NEXT N
270 REM clear out dish area
280 CALL PROCB(100,130,40)
290 REM draw dish
300 FOR N=0 TO 44 STEP 4 :: CALL PROCCG(100,130,N):: NEXT N
310 REM spin forever
320 GOTO 320
330 REM draw the moon itself
340 SUB PROCC(INV,INZ,INR,INN)
345 DEF RAND(X)=INT(RND*X)+1
350 V=INV :: Z=INZ :: R=INR :: N=INN
360 A=2*PI/360 :: S=SIN(A):: C=COS(A):: X=R :: Y=0
370 FOR W=1 TO 360 :: P=(RAND(W))-(N/2):: IF P>100 THEN GOTO 420
380 B=X*C-Y*S :: Y=X*S+Y*C :: X=B :: Q=((V+X)*1.3)-(Z/10)+100 :: O=((Z+Y)/4.0)*1.34+(X/3)
390 IF W<180 THEN GOTO 420
400 IF N>148 AND N<152 THEN CALL PLOT(Q+12,O-1):: GOTO 420 :: REM belt
410 FOR M=1 TO (360-W)/30 :: CALL PLOT(Q+RAND(8),O):: NEXT M :: REM density set by how many random pixels are plotted
420 NEXT W
430 SUBEND
520 REM draw the circles inside the dish
530 SUB PROCCG(INV,INZ,INR)
535 DEF RAND(X)=INT(RND*X)+1
540 V=INV :: Z=INZ :: R=INR :: N=INR
550 A=2*PI/400 :: S=SIN(A):: C=COS(A):: X=R :: Y=0
560 FOR W=1 TO 400 :: B=X*C-Y*S :: Y=X*S+Y*C :: X=B
570 IF N>32 AND N<44 THEN GOTO 590
580 IF INT(RAND((44-N))/5)<>1 THEN GOTO 610
590 IF W>0 AND W<120+RAND(30)THEN CALL PLOT(V+X,Z+Y)
600 IF W>310+RAND(30)AND W<400 THEN CALL PLOT(V+X,Z+Y)
610 NEXT W
620 SUBEND
630 REM wipe the dish section - use the optimized brute force grid search
640 SUB PROCB(INV,INZ,INR)
645 CALL LINK("PE")
650 RAD=INR
660 REM Super fast filled circle (does require a single square root)
670 REM from https:://stackoverflow.com/questions/1201200/fast-algorithm-for-drawing-filled-circles
680 FOR X=-RAD TO RAD
690 HH=SQR(RAD*RAD-X*X)
700 RX=INV+X
710 PH=INZ+HH
720 FOR Y=INZ-HH TO PH
730 CALL PLOT(RX,Y)
740 NEXT Y
750 NEXT X
755 CALL LINK("PD")
760 SUBEND
770 SUB PLOT(X,Y)
780 IF Y<0 OR Y>191 THEN SUBEXIT
790 IF X<0 OR X>255 THEN SUBEXIT
800 MY=191-Y :: REM INVERTED Y AXIS
810 CALL LINK("PIXEL",MY,X)
820 SUBEND

 

 

  • Like 21
Link to comment
https://forums.atariage.com/topic/344814-death-star-for-missing-link/
Share on other sites

1 hour ago, arcadeshopper said:

this takes so long to draw anything i thought i had pasted badly had to turn on maximum overdrive 

That's how I felt, except that I thought I had messed up the draw commands. ;)

It was surprisingly tricky to port. First was that the BBC graphics commands were surprisingly multi-featured -- single commands could do dozens of things with just a single number changing. It also ran in a much higher resolution, so I had to reverse engineer the various loops to understand how it worked.

Anyway, was a fun exercise.

  • Like 6
2 hours ago, arcadeshopper said:

this takes so long to draw anything i thought i had pasted badly had to turn on maximum overdrive 

 

 

Would this benefit from compiling? Is it compiler compatible?  I'm not asking because I think it needs it, but more of a general question about what is possible.

2 hours ago, DuaneAL said:

Would this benefit from compiling? Is it compiler compatible?  I'm not asking because I think it needs it, but more of a general question about what is possible.

Looks like some fractional numbers, so probably not.

  • Thanks 1

Questions about LINK BASIC:

1. CALL LINK("PIXEL",MY,X)

does set a pixel at (x,my) on the screen ?

2. CALL LINK("CLEAR")::CALL SCREEN(2)::CALL LINK("COLOR",8,2)

does set the screen in bitmap mode (256x192x16 colors 3 nametables), using color 8 as foreground and 2 as background (here colors go from 1 to 16, instead of 0-15) ?

3. CALL LINK("PE")

what does it do?

4. CALL LINK("PD")

what does it do?

 

19 hours ago, artrag said:

Questions about LINK BASIC:

1. CALL LINK("PIXEL",MY,X)

does set a pixel at (x,my) on the screen ?

2. CALL LINK("CLEAR")::CALL SCREEN(2)::CALL LINK("COLOR",8,2)

does set the screen in bitmap mode (256x192x16 colors 3 nametables), using color 8 as foreground and 2 as background (here colors go from 1 to 16, instead of 0-15) ?

3. CALL LINK("PE")

what does it do?

4. CALL LINK("PD")

what does it do?

 

 The missing link is the source of these and is included with classic99 under the Harry willhielm folder 

19 hours ago, artrag said:

Questions about LINK BASIC:

1. CALL LINK("PIXEL",MY,X)

does set a pixel at (x,my) on the screen ?

2. CALL LINK("CLEAR")::CALL SCREEN(2)::CALL LINK("COLOR",8,2)

does set the screen in bitmap mode (256x192x16 colors 3 nametables), using color 8 as foreground and 2 as background (here colors go from 1 to 16, instead of 0-15) ?

3. CALL LINK("PE")

what does it do?

4. CALL LINK("PD")

what does it do?

Sounds like you got it, but yes. PE sets the drawing mode to "erase" and PD sets it to "draw" (Pen Erase and Pen Down - turtle style ;) ).

 

Other tricky bits - using DEF RAND to create a RAND function which is 1-based instead of 0-based like the BBC, and using SUB for the various calls. The SUB PLOT in particular was just so I could be lazy about the screen transform, since the BBC counts from the bottom up.

 

There is something wrong in what I do... I do not get the main base and the small circle is not centered....

@Tursi Any idea on what I did wrong ?

 

100 ' Death Star by Electron Greg
110 ' Adapted by Tursilion - 256x192 version - unoptimized
120 '
130 DIM AR(300)
140 DEF FNMYRD(X)=(INT(RND(1)*(X))+1)
150 ' prepare lookup table
160 V=640 : Z=522 : R=300 : PI = 3.1415926535898#
170 A=2*PI/R : S=SIN(A) : C=COS(A) : X=R : Y=0
180 FOR W=1 TO R
190 B=X*C-Y*S : Y=X*S+Y*C : X=B : AR(W)=600-(V+X)
200 NEXT W
210 '
220 SCREEN 2
230 COLOR 7,1,1:CLS
240 ' draw globe
250 FOR NN=115 TO 210 : ' latitude
260 INV=64:INZ = (1080-(AR(219-NN)*7))/5:INR = AR(NN)/2.5:INN = NN: GOSUB 380
270 NEXT NN
280 ' clear out dish area
290 INV=100:INZ=130:INR=40: GOSUB 660
300 ' draw dish
310 FOR NN=0 TO 44 STEP 4 
320 INV=100: INZ=130:INR=NN: GOSUB 530 
330 NEXT NN
340 ' spin forever
350 COLOR ,,15
360 GOTO 360
370 ' draw the moon itself
380 '
390 V=INV : Z=INZ : R=INR : N=INN
400 A=2*PI/360 : S=SIN(A) : C=COS(A) : X=R : Y=0
410 FOR W=1 TO 360 
420 P=FNMYRD(W)-(N/2)
430 IF P>100 THEN GOTO 500
440 B=X*C-Y*S : Y=X*S+Y*C : X=B : Q=((V+X)*1.3)-(Z/10)+100 : O=((Z+Y)/4!)*1.34+(X/3)
450 IF W<180 THEN GOTO 500
460 IF N>148 AND N<152 THEN PSET(Q+12,191-(O-1)): GOTO 500 : ' belt
470 FOR M=1 TO (360-W)/30
480 PSET(Q+FNMYRD(8),191-O) : ' density set by how many random pixels are plotted
490 NEXT M 
500 NEXT W
510 RETURN
520 ' draw the circles inside the dish
530 ' 
540 V=INV : Z=INZ : R=INR : N=INR
550 A=2*PI/400 : S=SIN(A) : C=COS(A) : X=R : Y=0
560 FOR W=1 TO 400 
570 B=X*C-Y*S : Y=X*S+Y*C : X=B
580 IF N>32 AND N<44 THEN GOTO 600
590 IF INT(FNMYRD((44-N))/5)<>1 THEN GOTO 620
600 IF W>0 AND W<120+FNMYRD(30)   THEN PSET(V+X,191-(Z+Y))
610 IF W>310+FNMYRD(30) AND W<400 THEN PSET(V+X,191-(Z+Y))
620 NEXT W
630 RETURN
640 ' wipe the dish section - use the optimized brute force grid search
650 '
660 ' Super fast filled circle (does require a single square root)
670 ' from https:://stackoverflow.com/questions/1201200/fast-algorithm-for-drawing-filled-circles
680 RAD=INR
690 FOR X=-RAD TO RAD
700 HH=SQR(RAD*RAD-X*X)
710 RX=INV+X
720 PH=INZ+HH
730 FOR Y=INZ-HH TO PH
740 PRESET(RX,191-Y)
750 NEXT Y
760 NEXT X
770 RETURN

 

Any suggestions for a good MSX emulator that has speed up and keyboard paste? ;)

 

I typed the whole thing by hand into BlueMSX, then pressed control-break to try and find the breakpoint key and it exited the emulator. So I pasted very slowly into fMSX, but I can't seem to make that run fast, so I saved from there, loaded into Blue... oi.

 

That was a stumper once I got it going though... but I figured it out. Like Applesoft, MSX BASIC only has 2 letter variables. So, for instance, INV and INZ are the same variable (IN). I only used those variables to deal with the fact some subs were modifying the input variables and shouldn't... ;)

 

Fixing up lines 260,290,320,390,540,680,710,720,730 seemed to fix the base (I just changed from INZ,INV etc to IZ, IV, etc. I left RAD alone since there were no conflicts).

 

 

 

Hi Tursi!

Openmsx comes with a good GUI (Catapult) where there is a tab to past text to the emulator.

 

BTW thanks for the suggestions ! I think that I have missed the two letters limit for names in msx basic.

I will try to fix that tonight and let you know 

Edited by artrag
On 12/10/2022 at 4:32 PM, arcadeshopper said:

this takes so long to draw anything i thought i had pasted badly had to turn on maximum overdrive 

The perceived potential of combining massive floating point calculations and bitmap graphics for scientific or demo purposes in an XB environment is quickly hampered by the significant slowness of such calculations on the TI coupled with the need to call AL subroutine for bitmap access. I found that out the hard way with Orbital Rendez-vous (https://tigameshelf.net/edu.htm)...

  • Like 2
7 hours ago, artrag said:

Openmsx comes with a good GUI (Catapult) where there is a tab to past text to the emulator.

 

BTW thanks for the suggestions ! I think that I have missed the two letters limit for names in msx basic.

I will try to fix that tonight and let you know 

Ah, I tried that one, but I deleted it about 2 minutes. Just getting /into/ the emulator was way more complicated than it needed to be. ;) But, if that's the one, I will keep it in mind.

 

msx_workdisk.dsk

 

Anyway, the fix should work. I got the full death star under BlueMSX. I guess I can just paste the disk image.

 

  • Like 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...