| \*************************************************
\ 3-D Plotter and Rotator
\ Written in 68000 Machine Code
\ Using the Assembler in Fast Basic
\
\ By
\ Gary Radburn
\ 12 July 1988
\*************************************************
\*Reserve space for program
RESERVE code,$C000
FOR pass=0 TO 2
[
OPT pass,"L-W-"
ORG code
progstart
MOVE.L #scrspace,D0 \Get address
ADD.L #256,D0 \of second screen
AND.L #$FFFF00,D0 \for page
MOVE.L D0,screen1 \flipping and store it
MOVE.W #2,-(SP) \Get address
TRAP #14 \of current
ADDQ.L #2,SP \screen
MOVE.L D0,screen0 \and store it
MOVE.L #contrl,A0 \Get control field address
MOVE.W #100,(A0) \and set parameters to
MOVE.W #6,4(A0) \open a virtual workstation
MOVE.W #11,6(A0)
MOVE.W #45,8(A0)
MOVE.L #intin,A0
MOVE.W #0,D0
set
MOVE.W #1,(A0)+
ADDQ.W #1,D0
CMPI.W #10,D0
BNE set
MOVE.W #2,(A0)
BSR vdi \Open the workstation
MOVE.L #contrl,A0
MOVE.W 12(A0),device \Store device handle number
MOVE.L #intout,A0
MOVE.W (A0),D0 \Get width of screen
LSR.W #1,D0 \Divide by two
MOVE.L D0,oa \and store it
MOVE.W 2(A0),D0 \Get height of screen
LSR.W #1,D0 \Divide by two
MOVE.L D0,ob \and store it
MOVE.L #contrl,A0
MOVE.W #129,(A0) \Set the clipping rectangle
MOVE.W #2,2(A0)
MOVE.W #1,6(A0)
MOVE.L #ptsin,A1 \Specify corners
MOVE.L #intout,A0
MOVE.W #0,(A1)
MOVE.W #0,2(A1) \as 0,0
MOVE.W (A0),4(A1)
MOVE.W 2(A0),6(A1) \and width,height
MOVE.W #1,intin \turn it on
BSR vdi
MOVE.L #contrl,A0 \Hide mouse cursor
MOVE.W #123,(A0)
BSR vdi
\Main Program Loop
again
BSR rotate
BSR changescreen
BSR cls
BSR draw
BSR checkkey
CMPI.L #0,keypress \If a key is pressed
BNE end \then finish up
BSR increment \Else increment the orientation
\angles
BRA again \and repeat
end
MOVE.W #101,contrl \Close the workstation
BSR vdi
MOVE.L #contrl,A0 \Show mouse cursor
MOVE.W #122,(A0)
MOVE.W #1,6(A0)
BSR vdi
RTS \End of Main Program
\********** Start of Subroutines **********
line
LEA contrl,A0 \Draw a line between two points
MOVE.W #6,(A0)
MOVE.W #2,2(A0)
LEA ptsin,A0
MOVE.W xstart,(A0) \Set x start position
MOVE.W ystart,2(A0) \Set y start position
MOVE.W xfinish,4(A0) \Set x finish position
MOVE.W yfinish,6(A0) \Set y finish position
BSR vdi \Draw it
RTS
vdi
LEA contrl,A0 \Execute the vdi routine
MOVE.W device,12(A0) \specified
LEA vdipb,A0
MOVE.L A0,D1
MOVE.W #$73,D0
TRAP #2
RTS
\** Subroutine to caclulate the position of all the points
\** within 3-D space
rotate
MOVE.L #cos,A0 \Get COS t
MOVE.W t,D0
LSL.W #2,D0
MOVE.L 0(A0,D0.W),ct \and store it
MOVE.W u,D0 \Get COS u
LSL.W #2,D0
MOVE.L 0(A0,D0.W),cu \and store it
MOVE.W v,D0 \Get COS v
LSL.W #2,D0
MOVE.L 0(A0,D0.W),cv \and store it
MOVE.L #sin,A0 \Get SIN t
MOVE.W t,D0
LSL.W #2,D0
MOVE.L 0(A0,D0.W),st \and store it
MOVE.W u,D0 \Get SIN u
LSL.W #2,D0
MOVE.L 0(A0,D0.W),su \and store it
MOVE.W v,D0 \Get SIN v
LSL.W #2,D0
MOVE.L 0(A0,D0.W),sv \and store it
MOVE.W #0,D1 \Counter for points done
MOVE.L #points,A0 \Address of Data
looping
MOVE.L (A0)+,x \Get x
MOVE.L (A0)+,y \Get y
MOVE.L (A0)+,z \Get z
\Rotate on X axis
MOVE.L y,D2 \Three D calculations
MOVE.L ct,D4
MOVE.L st,D5
MULS D4,D2
ASR.L #8,D2 \Divide result by 1024
ASR.L #2,D2
MOVE.L z,D3
MULS D5,D3
ASR.L #8,D3
ASR.L #2,D3
ADD.L D2,D3 \Work out temp=y*ct+z*st
MOVE.L D3,temp
MOVE.L z,D2
MULS D4,D2
ASR.L #8,D2
ASR.L #2,D2
MOVE.L y,D3
MULS D5,D3
ASR.L #8,D3
ASR.L #2,D3
SUB.L D3,D2 \Work out z=z*ct-y*st
MOVE.L D2,z
MOVE.L temp,y \Put y=temp
\Rotate on Y axis
MOVE.L x,D2
MOVE.L cu,D4
MOVE.L su,D5
MULS D4,D2
ASR.L #8,D2
ASR.L #2,D2
MOVE.L z,D3
MULS D5,D3
ASR.L #8,D3
ASR.L #2,D3
SUB.L D3,D2
MOVE.L D2,temp \Work out temp=x*cu-z*su
MOVE.L z,D2
MULS D4,D2
ASR.L #8,D2
ASR.L #2,D2
MOVE.L x,D3
MULS D5,D3
ASR.L #8,D3
ASR.L #2,D3
ADD.L D3,D2
MOVE.L D2,z \Work out z=z*cu+x*su
MOVE.L temp,x \Put x=temp
\Rotate on Z axis
MOVE.L x,D2
MOVE.L cv,D4
MOVE.L sv,D5
MULS D4,D2
ASR.L #8,D2
ASR.L #2,D2
MOVE.L y,D3
MULS D5,D3
ASR.L #8,D3
ASR.L #2,D3
SUB.L D3,D2 \Work out temp=x*cv-y*sv
MOVE.L D2,temp
MOVE.L y,D2
MULS D4,D2
ASR.L #8,D2
ASR.L #2,D2
MOVE.L x,D3
MULS D5,D3
ASR.L #8,D3
ASR.L #2,D3
ADD.L D3,D2 \Work out y=y*cv+x*sv
MOVE.L D2,y
MOVE.L temp,x \Put x=temp
\End of Rotate
\Convert the 3D co-ordinates in 2D co-ordinates
MOVE.L x,D2 \Calculate the x position
MOVE.L viewdist,D3 \on the screen
MULS D3,D2
ADD.L viewdepth,D3
SUB.L z,D3
DIVS D3,D2
ADD.L oa,D2
MOVE.L #a,A1 \and store in the
LSL.W #1,D1 \space defined by label a
MOVE.W D2,0(A1,D1.W)
LSR.W #1,D1
MOVE.L y,D2 \Calculate the y position
MOVE.L viewdist,D3 \on the screen
MULS D3,D2
ADD.L viewdepth,D3
SUB.L z,D3
DIVS D3,D2
MOVE.L ob,D3
SUB.L D2,D3
MOVE.L #b,A1 \and store in the
LSL.W #1,D1 \space defined by label b
MOVE.W D3,0(A1,D1.W)
LSR.W #1,D1 \Check if all the
ADDQ.W #1,D1 \points have been
CMP.W nopoints,D1 \calculated
BNE looping \If not then loop again
RTS
\** Subroutine to draw all the lines of the object
draw
MOVE.L #lines,A2 \Get the address of lines
MOVE.L #a,A3 \Address of x coords
MOVE.L #b,A4 \Address of y coords
MOVE.W #0,D4 \Zero out counter
nextline
MOVE.W (A2)+,D2 \Get start point of line
MOVE.W (A2)+,D3 \Get end point of line
SUBQ.W #1,D2
SUBQ.W #1,D3
LSL.W #1,D2
LSL.W #1,D3
MOVE.W 0(A3,D2.W),xstart \Get start x coord
MOVE.W 0(A4,D2.W),ystart \Get start y coord
MOVE.W 0(A3,D3.W),xfinish \Get finish x coord
MOVE.W 0(A4,D3.W),yfinish \Get finish y coord
BSR line \and draw it
ADDQ.W #1,D4 \Increment counter
CMP.W nolines,D4 \If another line left
BNE nextline \then repeat it
RTS
\** Subroutine to clear the workstation
cls
MOVE.W #3,contrl
BSR vdi
RTS
\** Subroutine to flip between screens for animation
changescreen
MOVE.W #-1,-(SP) \Do not change resolution
CMPI.W #1,screenflip \Which screen?
BNE scr1 \Bring on other one
MOVE.L screen0,-(SP) \Physical screen
MOVE.L screen1,-(SP) \Logical screen
MOVE.W #0,screenflip \Change flag
BRA setit \and change screen
scr1
MOVE.L screen1,-(SP) \Physical screen
MOVE.L screen0,-(SP) \Logical screen
MOVE.W #1,screenflip \Change flag
setit
MOVE.W #5,-(SP) \Code for screen flip
TRAP #14 \and do it
ADD.L #12,SP \Clean up stack
MOVE.W #37,-(SP) \Wait for the vertical blank
TRAP #14
ADDQ.L #2,SP \Before returning
RTS
\** Subroutine to check for key press
checkkey
MOVE.W #255,-(SP) \Read a character
MOVE.W #6,-(SP) \Code to read one
TRAP #1 \Look at keyboard
ADDQ.L #4,SP \Clean up stack
MOVE.L D0,keypress \Store the keypress
RTS
\** Subroutine to increment all three angles
increment
MOVE.W tstep,D0 \Increment t
ADD.W D0,t
CMPI.W #360,t \If less than 360
BLO incu \then ok
SUB.W #360,t
incu
MOVE.W ustep,D0 \Increment u
ADD.W D0,u
CMPI.W #360,u \If less than 360
BLO incv \then ok
SUB.W #360,u
incv
MOVE.W vstep,D0 \Increment v
ADD.W D0,v
CMPI.W #360,v \If less than 360
BLO fininc \then ok
SUB.W #360,v
fininc
RTS
EVEN
\* VDI parameter block
vdipb DC.L contrl,intin,ptsin,intout,ptsout
contrl DS.W 32,0
intin DS.W 128,0
ptsin DS.W 128,0
intout DS.W 128,0
ptsout DS.W 128,0
t DS.W 1 \Current angles
u DS.W 1 \in the three
v DS.W 1 \planes
device DS.W 1 \Device number of screen
xstart DS.W 1 \Line Start x
ystart DS.W 1 \Line Start y
xfinish DS.W 1 \Line Finish x
yfinish DS.W 1 \Line Finish y
a DS.W 100 \Storage for x coords
b DS.W 100 \Storage for y coords
x DS.L 1 \x calc storage
y DS.L 1 \y calc storage
z DS.L 1 \z calc storage
ct DS.L 1 \COS t storage
cu DS.L 1 \COS u storage
cv DS.L 1 \COS v storage
st DS.L 1 \SIN t storage
su DS.L 1 \SIN u storage
sv DS.L 1 \SIN v storage
temp DS.L 1 \Temp calc storage
oa DS.L 1 \Screen x centre
ob DS.L 1 \Screen y centre
screenflip DS.L 1 \Screen change flag
keypress DS.L 1 \Key press indicator
screen0 DS.L 1 \Address of screen 0
screen1 DS.L 1 \Address of screen 1
tstep DC.W 2 \Degree step in t
ustep DC.W 5 \Degree step in u
vstep DC.W 1 \Degree step in v
nopoints DC.W 44 \Number of points in object
nolines DC.W 58 \Number of lines in object
viewdist DC.L 200 \Viewer distance (from 0)
viewdepth DC.L 400 \Object distance (from 0)
\* Data for object goes here
\DC.L X, Y, Z
points
DC.L -55,-55,0
DC.L -80,-10,0
DC.L -80,30,0
DC.L -160,140,0
DC.L -160,170,0
DC.L -55,210,0
DC.L 0,160,25
DC.L 0,0,25
DC.L -25,0,12
DC.L -25,-65,12
DC.L 0,-75,25
DC.L -13,-20,15
DC.L -13,-75,15
DC.L -25,185,12
DC.L -45,220,65
DC.L -45,180,65
DC.L -32,130,30
DC.L -25,55,12
DC.L -40,-60,0
DC.L -40,-75,0
DC.L 0,-260,0
DC.L 40,-75,0
DC.L 40,-60,0
DC.L 12,-75,15
DC.L 12,-20,15
DC.L 25,0,12
DC.L 25,-65,12
DC.L 55,-55,0
DC.L 55,210,0
DC.L 25,185,12
DC.L 45,220,65
DC.L 45,180,65
DC.L 32,130,30
DC.L 25,55,12
DC.L 160,170,0
DC.L 160,140,0
DC.L 80,30,0
DC.L 80,-10,0
DC.L 35,-95,2
DC.L 5,-95,20
DC.L 5,-190,6
DC.L -5,-95,20
DC.L -35,-95,2
DC.L -5,-190,6
\* Data for lines
\DC.W Start point, End Point
lines
DC.W 7,6
DC.W 6,29
DC.W 29,7
DC.W 29,35
DC.W 35,36
DC.W 36,37
DC.W 37,38
DC.W 38,28
DC.W 28,29
DC.W 6,5
DC.W 5,4
DC.W 4,3
DC.W 3,2
DC.W 2,1
DC.W 1,6
DC.W 7,8
DC.W 8,9
DC.W 9,10
DC.W 10,1
DC.W 8,26
DC.W 26,27
DC.W 27,28
DC.W 30,31
DC.W 31,32
DC.W 32,33
DC.W 33,34
DC.W 34,30
DC.W 14,15
DC.W 15,16
DC.W 16,17
DC.W 17,18
DC.W 18,14
DC.W 10,13
DC.W 13,12
DC.W 12,9
DC.W 12,8
DC.W 13,11
DC.W 11,8
DC.W 8,25
DC.W 25,26
DC.W 11,24
DC.W 24,25
DC.W 27,24
DC.W 24,23
DC.W 23,22
DC.W 22,24
DC.W 13,19
DC.W 19,20
DC.W 20,13
DC.W 11,21
DC.W 21,22
DC.W 20,21
DC.W 42,43
DC.W 43,44
DC.W 44,42
DC.W 39,40
DC.W 40,41
DC.W 41,39
\* Start of trigonometric lookup tables
sin
DC.L 0, 17, 35, 53, 71, 89
DC.L 107, 124, 142, 160, 177, 195
DC.L 212, 230, 247, 264, 282, 299
DC.L 316, 333, 350, 366, 383, 400
DC.L 416, 432, 448, 464, 480, 496
DC.L 511, 527, 542, 557, 572, 587
DC.L 601, 616, 630, 644, 658, 671
DC.L 685, 698, 711, 723, 736, 748
DC.L 760, 772, 784, 795, 806, 817
DC.L 828, 838, 848, 858, 868, 877
DC.L 886, 895, 904, 912, 920, 927
DC.L 935, 942, 949, 955, 962, 968
DC.L 973, 979, 984, 989, 993, 997
DC.L 1001, 1005, 1008, 1011, 1013, 1016
DC.L 1018, 1020, 1021, 1022, 1023, 1023
DC.L 1023, 1023, 1023, 1022, 1021, 1020
DC.L 1018, 1016, 1014, 1011, 1008, 1005
DC.L 1001, 997, 993, 989, 984, 979
DC.L 973, 968, 962, 956, 949, 942
DC.L 935, 928, 920, 912, 904, 895
DC.L 887, 877, 868, 859, 849, 839
DC.L 828, 818, 807, 796, 784, 773
DC.L 761, 749, 736, 724, 711, 698
DC.L 685, 672, 658, 644, 630, 616
DC.L 602, 587, 573, 558, 543, 527
DC.L 512, 496, 481, 465, 449, 433
DC.L 416, 400, 384, 367, 350, 333
DC.L 316, 299, 282, 265, 248, 230
DC.L 213, 195, 178, 160, 143, 125
DC.L 107, 89, 72, 54, 36, 18
DC.L 0, -18, -36, -53, -71, -89
DC.L -107, -125, -142, -160, -178, -195
DC.L -213, -230, -248, -265, -282, -299
DC.L -316, -333, -350, -367, -383, -400
DC.L -416, -433, -449, -465, -481, -496
DC.L -512, -527, -543, -558, -573, -587
DC.L -602, -616, -630, -644, -658, -672
DC.L -685, -698, -711, -724, -737, -749
DC.L -761, -773, -784, -796, -807, -818
DC.L -828, -839, -849, -859, -868, -878
DC.L -887, -896, -904, -913, -921, -928
DC.L -936, -943, -950, -956, -962, -968
DC.L -974, -980, -985, -989, -994, -998
DC.L -1002, -1006, -1009, -1012, -1014, -1017
DC.L -1019, -1021, -1022, -1023, -1024, -1024
DC.L -1024, -1024, -1024, -1023, -1022, -1021
DC.L -1019, -1017, -1015, -1012, -1009, -1006
DC.L -1002, -998, -994, -990, -985, -980
DC.L -975, -969, -963, -957, -950, -943
DC.L -936, -929, -921, -913, -905, -897
DC.L -888, -879, -869, -860, -850, -840
DC.L -830, -819, -808, -797, -786, -774
DC.L -762, -750, -738, -725, -713, -700
DC.L -686, -673, -660, -646, -632, -618
DC.L -603, -589, -574, -559, -544, -529
DC.L -513, -498, -482, -466, -450, -434
DC.L -418, -402, -385, -369, -352, -335
DC.L -318, -301, -284, -267, -249, -232
DC.L -215, -197, -179, -162, -144, -126
DC.L -109, -91, -73, -55, -37, -20
cos
DC.L 1024, 1023, 1023, 1022, 1021, 1020
DC.L 1018, 1016, 1014, 1011, 1008, 1005
DC.L 1001, 997, 993, 989, 984, 979
DC.L 973, 968, 962, 956, 949, 942
DC.L 935, 928, 920, 912, 904, 895
DC.L 886, 877, 868, 858, 848, 838
DC.L 828, 817, 807, 795, 784, 772
DC.L 761, 749, 736, 724, 711, 698
DC.L 685, 671, 658, 644, 630, 616
DC.L 602, 587, 572, 557, 542, 527
DC.L 512, 496, 480, 465, 449, 432
DC.L 416, 400, 383, 367, 350, 333
DC.L 316, 299, 282, 265, 247, 230
DC.L 213, 195, 178, 160, 142, 125
DC.L 107, 89, 71, 53, 36, 18
DC.L 0, -18, -36, -54, -72, -89
DC.L -107, -125, -143, -160, -178, -196
DC.L -213, -231, -248, -265, -282, -300
DC.L -317, -334, -350, -367, -384, -400
DC.L -417, -433, -449, -465, -481, -497
DC.L -512, -528, -543, -558, -573, -587
DC.L -602, -616, -631, -645, -658, -672
DC.L -685, -699, -712, -724, -737, -749
DC.L -761, -773, -785, -796, -807, -818
DC.L -829, -839, -849, -859, -869, -878
DC.L -887, -896, -904, -913, -921, -928
DC.L -936, -943, -950, -956, -963, -969
DC.L -974, -980, -985, -989, -994, -998
DC.L -1002, -1006, -1009, -1012, -1014, -1017
DC.L -1019, -1021, -1022, -1023, -1024, -1024
DC.L -1024, -1024, -1024, -1023, -1022, -1021
DC.L -1019, -1017, -1015, -1012, -1009, -1006
DC.L -1002, -998, -994, -990, -985, -980
DC.L -975, -969, -963, -957, -950, -943
DC.L -936, -929, -921, -913, -905, -896
DC.L -888, -879, -869, -860, -850, -840
DC.L -829, -819, -808, -797, -785, -774
DC.L -762, -750, -738, -725, -712, -699
DC.L -686, -673, -659, -646, -632, -617
DC.L -603, -588, -574, -559, -544, -529
DC.L -513, -498, -482, -466, -450, -434
DC.L -418, -401, -385, -368, -352, -335
DC.L -318, -301, -284, -266, -249, -232
DC.L -214, -197, -179, -162, -144, -126
DC.L -108, -91, -73, -55, -37, -19
DC.L -1, 16, 34, 52, 70, 88
DC.L 106, 123, 141, 159, 176, 194
DC.L 211, 229, 246, 264, 281, 298
DC.L 315, 332, 349, 366, 382, 399
DC.L 415, 431, 447, 463, 479, 495
DC.L 511, 526, 541, 556, 571, 586
DC.L 601, 615, 629, 643, 657, 671
DC.L 684, 697, 710, 723, 735, 748
DC.L 760, 772, 783, 795, 806, 817
DC.L 827, 838, 848, 858, 867, 877
DC.L 886, 895, 903, 911, 919, 927
DC.L 935, 942, 949, 955, 961, 967
DC.L 973, 978, 984, 988, 993, 997
DC.L 1001, 1004, 1008, 1011, 1013, 1016
DC.L 1018, 1019, 1021, 1022, 1023, 1023
\* Storage space for second screen
scrspace DS.L 8192
\**** End of Code ****
]
NEXT
CALL code
|