
*	blitter stuff	*
halftone:	equ	0
src_xinc:	equ	32
src_yinc:	equ	34
src_addr:	equ	36
endmask1:	equ	40
endmask2:	equ	42
endmask3:	equ	44
dst_xinc:	equ	46
dst_yinc:	equ	48
dst_addr:	equ	50
x_count:	equ	54
y_count:	equ	56
hop:		equ	58
op:		equ	59
line_num:	equ	60
skew:		equ	61
fhop_source:	equ	1
fhop_halftone:	equ	0
fskewfxsr:	equ	7
fskewnfsr:	equ	6
flinebusy:	equ	7
flinehog:	equ	6
flinesmudge:	equ	5
mhop_source:	equ	$02
mhop_halftone:	equ	$01
mskewfxsr:	equ	$80
mskewnfsr:	equ	$40
mlinebusy:	equ	$80
mlinehog:	equ	$40
mlinesmudge:	equ	$20

magic:		equ	1650
magic2:		equ	1650
numstars:	equ	12
speed:		equ	350
zclip:		equ	100



testdraw:
	move.l	whichob,a5
	move.l	obviewpb(a5),a0
*	tst.w	mcontrol
*	ble	nomc
	cmpi.w	#1,buttondat
	bne.s	mcin
	sub.w	#50,uniz
	bra.s	mouserots
mcin:
	cmpi.w	#2,buttondat
	bne.s	mouserots
	add.w	#50,uniz
mouserots:
	move.w	mx,unitheta
	move.w	my,uniphi
	bra.s	dobefore
nomc:
	tst.w	mcontrol
	beq	demomode
	move.w	thetainc,d0
	add.w	d0,unitheta
	move.w	phiinc,d0
	add.w	d0,uniphi
	move.w	rhoinc,d0
	add.w	d0,unirho
dobefore:
	move.w	unitheta,theta(a0)
	move.w	uniphi,phi(a0)
	move.w	unirho,rho(a0)
	move.w	uniz,obz(a5)
	move.w	obx(a5),plx
	move.w	oby(a5),ply
	move.w	obz(a5),plz
drawobject:
	bsr	init_vtrans
	move.l	whichob,a3 	;Point to verticies
	bsr	trans_vert	;Transform verticies
	move.l	whichob,a0
	lea	vtrans_vrt,a1	;list of transformed vertices
	lea	ptrans_vrt,a2	;list of onscreen coords
	cmpi.w	#dots,style(a0)
	beq	objectisdots

objectisdots:
	move.w	#12,pixelcolor
	lea	ptrans_vrt,a1	;list of onscreen coords
	lea	vtrans_vrt,a2
	move.w	plz,d1
	move.w	numdots(a0),d0	;get the number of points
	subq.w	#1,d0
	tst.w	hidenflag(a0)
	bmi	nohides
dotloop:
	cmp.w	4(a2),d1
	blt	nopl
	tst.w	4(a2)
	bmi	nono
	addq.l	#8,a2
	move.w	#12,pixelcolor
	move.w	(a1)+,pixelx
	move.w	(a1)+,pixely
	bsr	singleplot
	dbf	d0,dotloop
	rts
nopl:
	addq.l	#8,a2
	move.w	#13,pixelcolor
	move.w	(a1)+,pixelx
	move.w	(a1)+,pixely
	bsr	singleplot
	dbf	d0,dotloop
	rts
nono:	addq.l	#4,a1
	addq.l	#8,a2
	dbf	d0,dotloop
	rts


nohides:
	move.w	(a1)+,pixelx
	move.w	(a1)+,pixely
	bsr	singleplot
	dbf	d0,nohides
	rts

cxmin:		equ	0
cxmax:		equ	319
cymin:		equ	0
cymax:		equ	150


***************************************************************************
*		TRANSFORM A LIST OF VERTICIES
*		On entry,   d6 = number of verticies
*			    a3 = pointer to verticies
*		On exit , a0 = pointer to transformed verticies
*	Transform a list of verticies in 3-D space according to the
* 	viewing transformation.
trans_vert:
	lea.l	vtrans_vrt,a1	;Point to vertex tables
	lea.l	ptrans_vrt,a0
	move.l	a0,-(SP)
	move.l	obviewpb(a3),a5
	move.l	obvert(a3),a3
	move.w	(a3)+,d6	;get number of verts
	subq	#1,d6		;Pre-decrement vertex counter
trans_vert0:
	move	(a3)+,d0		;Get x-coordinate of vertex
	move	(a3)+,d1	;Get y-coordinate
	move	(a3)+,d2	;Get z-coordinate
	bsr	view_trans	;Apply view transformatrmed coordinates
	add.w	plx,d3
	add.w	ply,d4
	add.w	plz,d5
	add.w	myviewx,d3
	add.w	myviewy,d4
	move.w	d3,(a1)+
	move	d4,(a1)+
	cmpi.w	#zclip,d5
	bge	okz	
	move.w	#zclip,d5
okz:
	move	d5,(a1)+
	move.w	#0,(a1)+
	bsr	prsp_trans	;Apply perspective transformation
	move	d3,(a0)+	;Save transformed x-coordinate		
	move	d4,(a0)+	;Save transformed y-coordinate
	dbf	d6,trans_vert0
	move.l	(SP)+,a0	;Restore transformed vertex pointer
	rts

*******************************
*		VIEW TRANSFORM ON A VERTEX
*		On entry, d0 = x-coordinate of vertex
*			  d1 = y-coordinate of vertex
*			  d2 = z-coordinate of vertex
*		On exit , d3 = x-coordinate view transformed
*			  d4 = y-coordinate view transformed
*			  d5 = z-coordinate view transformed
*	Apply the view transform to a vertex.
view_trans:
	move.w	d0,d3			;get x
	muls	c_theta(a5),d3
	move.w	d1,d4			;get y
	muls	s_theta(a5),d4
	add.l	d4,d3
	swap	d3
	rol.l	#1,d3			;thats	x
	move.w	d1,d4			;get y
	muls	c_theta(a5),d4
	muls	s_theta(a5),d0		;x
	sub.l	d0,d4
	swap	d4
	rol.l	#1,d4			;thats	y
	move.w	d4,d1			;x
	move.w	d3,d0			;y

	move.w	d1,d3			;get y
	muls	c_phi(a5),d3
	move.w	d2,d4			;get z
	muls	s_phi(a5),d4
	add.l	d4,d3
	swap	d3
	rol.l	#1,d3			;thats	y
	move.w	d2,d4			;thats z
	muls	c_phi(a5),d4
	muls	s_phi(a5),d1		;y
	sub.l	d1,d4
	swap	d4
	rol.l	#1,d4			;thats	z
	move.w	d4,d2			;y

	move.w	d0,d4			;x
	muls	c_rho(a5),d4
	move.w	d2,d5
	muls	s_rho(a5),d5		;z
	sub.l	d5,d4
	swap	d4
	rol.l	#1,d4			;thats	x
	move.w	d4,d5
	muls	s_rho(a5),d0
	muls	c_rho(a5),d2
	add.l	d0,d2
	swap	d2
	rol.l	#1,d2		;thats	z
	move.w	d2,d5
	move.w	d3,d7
	move.w	d4,d3
	move.w	d7,d4
	rts

worldview_trans:
	tst.w	theta(a5)
	beq	skiptheta
	move.w	d0,d3			;get x
	muls	c_theta(a5),d3
	move.w	d1,d4			;get y
	muls	s_theta(a5),d4
	add.l	d4,d3
	swap	d3
	rol.l	#1,d3			;thats	y
	move.w	d1,d4			;get y
	muls	c_theta(a5),d4
	muls	s_theta(a5),d0		;x
	sub.l	d0,d4
	swap	d4
	rol.l	#1,d4			;thats	x
	move.w	d4,d1			;x
	move.w	d3,d0			;y

skiptheta:
	tst.w	rho(a5)
	beq	skiprho
	move.w	d0,d4			;x
	muls	c_rho(a5),d4
	move.w	d2,d5
	muls	s_rho(a5),d5		;z
	sub.l	d5,d4
	swap	d4
	rol.l	#1,d4			;thats	z
	move.w	d4,d7
	move.w	d0,d4
	muls	s_rho(a5),d4
	move.w	d2,d3
	muls	c_rho(a5),d3
	add.l	d4,d3
	swap	d3
	rol.l	#1,d3		;thats	x
	move.w	d3,d2
	move.w	d7,d0
skiprho:
	tst.w	phi(a5)
	beq	skipphi
	move.w	d1,d3			;get y
	muls	c_phi(a5),d3
	move.w	d2,d4			;get z
	muls	s_phi(a5),d4
	add.l	d4,d3
	swap	d3
	rol.l	#1,d3			;thats	z
	move.w	d2,d4			;thats z
	muls	c_phi(a5),d4
	muls	s_phi(a5),d1		;y
	sub.l	d1,d4
	swap	d4
	rol.l	#1,d4			;thats	y
	move.w	d4,d2			;y
	move.w	d3,d1
skipphi:
	move.w	d0,d3
	move.w	d1,d4
	move.w	d2,d5
	rts

***********************************************************************
*		PERSPECTIVE TRANSFORM
*		On entry, d3 = view transformed x-coordinate
*			  d4 = view transformed y-coordinate
*			  d5 = view transformed z-coordinate
*		On exit , d3 = screen x-coordinate ( Xe )
*			  d4 = screen y-coordinate ( Ye )
*	Calculate the screen coordinates of the vertex. The coordinates are
* centered about the centre of the screen.
*	Note, the distance to the screen is 2048.

prsp_trans:
	swap	d3		;Calculate Xs
	clr	d3		
	asr.l	#8,d3	  
	divs	d5,d3
	
	swap	d4		;Calculate Ys
	clr	d4
	asr.l	#8,d4
	divs	d5,d4

	add	#159,d3		;Adjust for centre of screen
	add	#76,d4
	rts

***************************************************************************
*		INITIALISE VIEW TRANSFORM
*	Initialise the viewing transformation.
*	expects	address of object data in a5
init_vtrans:
	move.l	obviewpb(a5),a5
	move	theta(a5),d3		;Calculate SIN amd COS theta
	bsr	trig
	move	d4,s_theta(a5)
	move	d5,c_theta(a5)
	
	move	phi(a5),d3	;Calculate SIN and COS phi
	bsr	trig
	move	d4,s_phi(a5)
	move	d5,c_phi(a5)

	move	rho(a5),d3	;Calculate Vl
	bsr	trig
	move.w	d4,s_rho(a5)
	move.w	d5,c_rho(a5)
	rts

***************************************************************************
*		CALCULATE SINE AND COSINE OF ANGLE
*		On entry, d3 = angle
*		On exit ,   d4 = sine of angle
*			    d5 = cosine of angle
*	Find the sine and cosine of an angle.

trig:	addi.w	#$40,d3		;Find cCOS of angle
	bsr	find_sin
	move	d4,d5
	subi.w	#$40,d3		;Find SIN of angle
	bsr	find_sin
	rts

***************************************************************************
*		FIND SINE OF AN ANGLE
*		On entry, d3 = angle
*		On exit ,   d5 = cosine of angle 
*	Find the cosine of an angle. The value of the sign is a 16 bit
* signed number.
*	Note, to scale down, divide by 15 bits, ie &8000.
find_cos:
	move	d4,-(SP)	;Save SIN
	move	d3,-(SP)	;Save angle
	addi.w	#$40,d3		;Find COS of angle
	bsr	find_sin
	move	d4,d5
		
	move	(SP)+,d3	;Restore angle
	move	(SP)+,d4	;Restore SIN
		
	rts	

***************************************************************************
*		FIND THE SIN OF AN ANGLE
*		On entry, d3 = angle
*		On exit ,   d4 = SIN of angle
*	Find the SIN of an angle. The value of the sign is a 16 bit
* signed number.
*	Note, to scale down, divide by 15 bits, ie &8000.

find_sin:
	move	d3,-(SP)	;Save angle	

	and.l	#$7F,d3		;Move to quadrants 1 and 2
	btst	#6,d3		;Test if in 1st quadrant
	beq	quad0		;Branch if in 1st quadrant
	bclr	#6,d3		;Reflect angle into 1st quadrant
	subi.b	#$3F,d3
	neg.b	d3
		
quad0:	asl	#1,d3		;Get value of SIN from table
	lea.l	sin_vt,a6
	move	0(a6,d3),d4
		
	move	(SP)+,d3

	btst	#7,d3		;Adjust value if 3rd or 4th quadrant
	beq	quad1
	neg	d4		;Negate SIN value
		
quad1:	rts

***************************************************************************
*		SIN LOOK UP TABLE
*	This is the SIN value look up table. Values for the 1st quadrant
* are given only. The values range from 0 - 32758 for angles 0 - 63.
* Thus, the value of a sine in the 1st quadrant is a 15 bit number.
* Therefore, the table can be used to construct a 16 bit signed value of
* SIN for angles 0 - 255.

sin_vt:	dc.w	0,804,1608,2411
	dc.w	3212,4011,4808,5602
	dc.w	6393,7180,7962,8740
	dc.w	9512,10279,11039,11793
	dc.w	12540,13279,14010,14733
	dc.w	15447,16151,16846,17531
	dc.w	18205,18868,19520,20160
	dc.w	20788,21403,22006,22595
	dc.w	23170,23732,24279,24812
	dc.w	25330,25832,26320,26791
	dc.w	27246,27684,28106,28511
	dc.w	28899,29269,29622,29957
	dc.w	30274,30572,30853,31114
	dc.w	31357,31581,31786,31972
	dc.w	32138,32286,32413,32522
	dc.w	32610,32679,32729,32758

vtrans_vrt:	ds.w	1700	;View transformed coordinates	
ptrans_vrt:	ds.w	1700	;Perspective transformed coordinates
***************************************************************************
filled:		equ	0
line:		equ	1
dots:		equ	2
balls:		equ	3
obviewpb:	equ	0	;offsets for object linked list desc'n
obx:		equ	4
oby:		equ	6
obz:		equ	8
obvert:		equ	10
obfacelist:	equ	14
obvrtnum:	equ	0
obfacenum:	equ	0
centrepoint:	equ	20
style:		equ	18
numdots:	equ	20
linecolinfo:	equ	20
obcolors:	equ	22
hidenflag:	equ	26
activeflag:	equ	28
canitbehit:	equ	30
obw:		equ	32
onscreenx:	equ	34
onscreeny:	equ	36
obint:		equ	38
obxvel:		equ	40
obyvel:		equ	42
obzvel:		equ	44
worldvpb:	ds.w	20
boxvpb:		ds.w	20
box2:
	dc.l	boxvpb
	dc.w	0,0,1500
	dc.l	box2vrt
	dc.l	box2face
	dc.w	filled
	dc.w	12
	dc.l	box2palette
	dc.w	1
box2palette:
	dc.w	$0000,$040f,$010d,$0c3f,$021f,$0000,$0000,$0000
	dc.w	$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000
box2vrt:
	dc.w	4*4
	dc.w	-40,40,50
	dc.w	40,40,50
	dc.w	40,-40,50
	dc.w	-40,-40,50

	dc.w	50,40,40
	dc.w	50,40,-40
	dc.w	50,-40,-40
	dc.w	50,-40,40

	dc.w	40,40,-50
	dc.w	-40,40,-50
	dc.w	-40,-40,-50
	dc.w	40,-40,-50

	dc.w	-50,40,-40
	dc.w	-50,40,40
	dc.w	-50,-40,40
	dc.w	-50,-40,-40
	
box2face:
	dc.w	8
	dc.w	1,3,0,1,2,3
	dc.w	2,3,4,5,6,7
	dc.w	1,3,8,9,10,11
	dc.w	2,3,12,13,14,15

	dc.w	3,3,3,2,1,0
	dc.w	4,3,7,6,5,4
	dc.w	3,3,11,10,9,8
	dc.w	4,3,15,14,13,12


rho:		equ	0
theta:		equ	2
phi:		equ	4
s_theta:	equ	6
c_theta:	equ	8
s_phi:		equ	10
c_phi:		equ	12
s_rho:		equ	14
c_rho:		equ	16
x1s:	dc.w	0
y1s:	dc.w	0
x2s:	dc.w	0
y2s:	dc.w	0
yadd:	dc.l	0

unitheta:	dc.w	0
uniphi:		dc.w	0
unirho:		dc.w	0
uniz:		dc.w	500
thetainc:	dc.w	0
phiinc:	dc.w	0
rhoinc:	dc.w	0
clz:		dc.w	1500
mytheta:	dc.w	0
myphi:		dc.w	0
myrho:		dc.w	0
whichob:	dc.l	0
lifetime:	dc.w	-1
demaddress:	dc.l	demlist
zfinal:		dc.w	0
halflife:	dc.w	0
kx:	dc.w	0
px:	dc.w	0
ky:	dc.w	0
py:	dc.w	0
kz:	dc.w	0
pz:	dc.w	0
rx:	dc.w	0
ry:	dc.w	0
rz:	dc.w	0
hdf:		dc.w	0
numfacesave:	dc.w	0
facepoints:	dc.w	0
facecolor1:	dc.w	0
facecolor2:	dc.w	0
cbits:	dc.w	0
cbits2:	dc.w	0
xsav:	dc.w	0
ysav:	dc.w	0

plx:	dc.w	0
ply:	dc.w	0
plz:	dc.w	0
myviewx:	dc.w	0
myviewy:	dc.w	0
