nsamount2:	equ	1
ewamount2:	equ	1
nsamount:	equ	25
ewamount:	equ	25
iea:	equ	$fffa07
ieb:	equ	$fffa09
isra:	equ	$fffa0f
ima:	equ	$fffa13
tbcr:	equ	$fffa1b
tbdr:	equ	$fffa21
vbl_vec:	equ	$70
key_vec:	equ	$118
hbl_vec:	equ	$120
magic:		equ	1650
magic2:		equ	1650
numstars:	equ	12
speed:		equ	350
zclip:		equ	100
start:
	clr.l   -(SP)           ;Go into supervisor mode
        move.w  #$20,-(SP)
        trap    #1
        addq.l  #6,SP
        move.l  D0,savesup
*	move.b	#0,$484
	move.l	$426,rvsave
	move.l	$42a,resave
	move.w	#4,-(sp)
	trap	#14
	addq.l	#2,sp
	move.w	d0,ressave

	move.w	#0,-(sp)	;set to low res
	move.l	#-1,-(sp)
	move.l	#-1,-(sp)
	move.w	#5,-(sp)
	trap	#14
	add.l	#12,sp

	lea	bluepalette,a0
	jsr	mydocolors
	jsr	putrout
	jsr	getscrn
	jsr	plotinit
	jsr	clearboth
	move.l	#fileshipcomp,filename
	jsr	loadscr
	jsr	copyintoboth
	jsr	setuphbl
testloop:
	jsr	testdraw
	jsr	flip_scr
	jsr	keyboard
	bra	testloop


*****************************************
clip_poly:
	move.l	a0,a1
	move.w	d7,d0
	lsl	#2,d0
	lea	-4(a1,d0.w),a2
	movem	(a2)+,d0/d1
	move	d0,d2
	move.w	d1,d3

*	move.w	2(a6),d6
	move.w	#cymin,d6
	cmp.w	d6,d3
	bge.s	next_cp1_t
	bra.s	next_cp2_t
cp_lp1_t:
	movem	(a1)+,d0/d1
	cmp.w	d6,d1
	bge.s	cp1_t
	bsr	horiz_cross
	moveq	#-1,d4
	bra.s	next_cp2_t
cp3_t:
	bsr	horiz_cross
cp1_t:
	move.w	d0,(a2)+
	move.w	d1,(a2)+
	move.w	d0,d2
	move.w	d1,d3
next_cp1_t:
	dbra	d7,cp_lp1_t
	bra.s	cp5_t
cp_lp2_t:
	move.w	d0,d2
	move.w	d1,d3
	movem	(a1)+,d0/d1
	cmp.w	d6,d1
next_cp2_t:
	dbge	d7,cp_lp2_t
	beq.s	cp1_t
	bgt.s	cp3_t

cp5_t:
	subq.l	#4,a2
	move.w	(a2)+,d0
	move.w	(a2)+,d1
	move.w	d0,d2
	move.w	d1,d3
	move.l	a2,d7
	sub.l	a1,d7
	beq	cp_off
	lsr	#2,d7
*	move.w	(a6),d6
	move.w	#cxmin,d6
	cmp.w	d6,d2
	bge.s	next_cp1_l
	bra.s	next_cp2_l
cp_lp1_l:
	movem	(a1)+,d0/d1
	cmp.w	d6,d0
	bge.s	cp1_l
	bsr	vert_cross
	moveq	#-1,d4
	bra.s	next_cp2_l
cp3_l:
	bsr	vert_cross
cp1_l:
	move.w	d0,(a2)+
	move.w	d1,(a2)+
	move.w	d0,d2
	move.w	d1,d3
next_cp1_l:
	dbra	d7,cp_lp1_l
	bra	cp5_l
cp_lp2_l:
	move.w	d0,d2
	move.w	d1,d3
	movem	(a1)+,d0/d1
	cmp	d6,d0
next_cp2_l:
	dbge	d7,cp_lp2_l
	beq.s	cp1_l
	bgt.s	cp3_l

cp5_l:
	subq.l	#4,a2
	move.w	(a2)+,d0
	move.w	(a2)+,d1
	move.w	d0,d2
	move.w	d1,d3
	move.l	a2,d7
	sub.l	a1,d7
	beq	cp_off
	lsr	#2,d7
*	move.w	(a6),d6
	move.w	#cymax,d6
	cmp.w	d6,d3
	ble.s	next_cp1_b
	bra.s	next_cp2_b
cp_lp1_b:
	movem	(a1)+,d0/d1
	cmp.w	d6,d1
	ble.s	cp1_b
	bsr	horiz_cross
	moveq	#1,d4
	bra.s	next_cp2_b
cp3_b:
	bsr	horiz_cross
cp1_b:
	move.w	d0,(a2)+
	move.w	d1,(a2)+
	move.w	d0,d2
	move.w	d1,d3
next_cp1_b:
	dbra	d7,cp_lp1_b
	bra	cp5_b
cp_lp2_b:
	move.w	d0,d2
	move.w	d1,d3
	movem	(a1)+,d0/d1
	cmp	d6,d1
next_cp2_b:
	dble	d7,cp_lp2_b
	beq.s	cp1_b
	blt.s	cp3_b

cp5_b:
	subq.l	#4,a2
	move.w	(a2)+,d0
	move.w	(a2)+,d1
	move.w	d0,d2
	move.w	d1,d3
	move.l	a2,d7
	sub.l	a1,d7
	beq	cp_off
	lsr	#2,d7
*	move.w	(a6),d6
	move.l	a0,a2
	move.w	#cxmax,d6
	cmp.w	d6,d2
	ble.s	next_cp1_r
	bra.s	next_cp2_r
cp_lp1_r:
	movem	(a1)+,d0/d1
	cmp.w	d6,d0
	ble.s	cp1_r
	bsr	vert_cross
	moveq	#1,d4
	bra.s	next_cp2_r
cp3_r:
	bsr.s	vert_cross
cp1_r:
	move.w	d0,(a2)+
	move.w	d1,(a2)+
	move.w	d0,d2
	move.w	d1,d3
next_cp1_r:
	dbra	d7,cp_lp1_r
	bra	cp5_r
cp_lp2_r:
	move.w	d0,d2
	move.w	d1,d3
	movem	(a1)+,d0/d1
	cmp	d6,d0
next_cp2_r:
	dble	d7,cp_lp2_r
	beq.s	cp1_r
	blt.s	cp3_r
cp5_r:
	move.l	a2,d7
	sub.l	a0,d7
	beq.s	cp_off
	lsr.w	#2,d7
	moveq	#0,d0
	rts
cp_off:
	moveq	#-1,d0
	rts
horiz_cross:
	move.w	d0,d4
	sub.w	d2,d4
	move.w	d1,d5
	sub.w	d6,d5
	muls	d5,d4
	move	d1,d5
	sub.w	d3,d5
	divs	d5,d4
	neg	d4
	add	d0,d4
	move.w	d4,(a2)+
	move.w	d6,(a2)+
	rts
vert_cross:
	move.w	d1,d4
	sub.w	d3,d4
	move.w	d0,d5
	sub.w	d6,d5
	muls	d5,d4
	move	d0,d5
	sub.w	d2,d5
	divs	d5,d4
	neg	d4
	add	d1,d4
	move.w	d6,(a2)+
	move.w	d4,(a2)+
	rts

*****************************************
*	my own personal poly draw	*
*****************************************
draw_polygon3:
	movem.l	d0-d7/a0-a6,-(sp)

	move.w	surfacedfn,d7		;color
	move.w	surfacedfn+2,d5
	bsr	init_hcol2

	lea	surfacevrt,a0
	move.w	(a0)+,d7		;count
	addq.w	#1,d7

	move.w	d0,-(sp)
	bsr	clip_poly
	move	(sp)+,a1
	bmi	abort_poly
*	move	a1,d0
*	move.l	a6,-(sp)

*	move.w	d0,d1
*	lsl.w	#3,d1
*	lea	col_dat,a1
*	adda	d1,a1
*	lea	col_code,a5
*	move.l	(a1)+,(a5)+
*	move.l	(a1),(a5)+
*	move.b	d0,(a5)

	move.w	d7,d0
	move.w	d0,d2
	move.w	d2,d6
	lsl.w	#2,d0
	lea	(a0,d0.w),a1
	lea	(a1,d0.w),a2
	move.l	a1,a4
	move.w	#$8000,d0
	move.w	#$7fff,d1
	bra.s	next_coord
coord_lp:
	move.l	(a0)+,d3
	cmp.w	d3,d0
	bge.s	check_low_y
	move.w	d3,d0
check_low_y:
	cmp.w	d3,d1
	ble.s	coord_trans
	move.w	d3,d1
	move.l	a1,a4
coord_trans:
	move.l	d3,(a1)+
	move.l	d3,(a2)+
next_coord:
	dbra	d6,coord_lp

	move.w	d0,d7
	sub.w	d1,d7

	move.l	a4,a3
	move.l	(a4),d0
	addq.w	#1,d7
flat_tp_lp1:
	addq.l	#4,a4
	subq.w	#1,d7
	bmi	abort_poly
	cmp	2(a4),d0
	beq.s	flat_tp_lp1
	bra.s	look_back
flat_tp_lp2:
	subq.l	#4,a3
look_back:
	cmp.w	-2(a3),d0
	beq.s	flat_tp_lp2

	move.l	hiden,a6
	lsl.w	#5,d0
	add.w	d0,a6
	lsl.w	#2,d0
	add.w	d0,a6
	lea	fcoltable1,a5
	pea	fcoltable2
	moveq	#0,d6
	bra	start_poly

polyfill_lp:
	move.l	d3,d0
	swap	d0
	bpl.s	no_rnd_1
	addq.w	#1,d0
no_rnd_1:
	move.l	d4,d1
	swap	d1
	bpl.s	no_rnd_r
	addq.w	#1,d1
no_rnd_r:
	add.l	a1,d3
	add.l	a2,d4

	exg	d0,d1
v_order_ok:
	move.w	d0,d2
	sub.w	d0,d1
	lsr.w	#1,d2
	and.w	#$fff8,d2
	lea	(a6,d2.w),a0
	and.w	#$f,d0
	moveq	#-1,d2
	lsr	d0,d2
	add.w	d1,d0
	sub.w	#16,d0
	bpl	multi_span
	addq.w	#1,d0
	neg.w	d0
	moveq	#-1,d1
	lsl.w	d0,d1
	and.w	d1,d2
	move.w	d2,d1
*	not	d2
	bsr	myputline
	bra.s	row_done
multi_span:
	move.w	d2,d1
*	not	d2
*	jsr	2(a5)
	bsr	myputline
	addq.w	#1,d0
	move.w	d0,d1
	lsr.w	#4,d0
	and.w	#$f,d1
	move.w	d1,-(sp)
*	movem.l	-8(a5),d1/d2
	bra.s	next_p_row
p_row_lp:
*	move.l	d1,(a0)+
*	move.l	d2,(a0)+
	move.w	(a5),(a0)+
	move.w	2(a5),(a0)+
	move.w	4(a5),(a0)+
	move.w	6(a5),(a0)+
next_p_row:
	dbra	d0,p_row_lp
	move.w	(sp)+,d1
	moveq	#-1,d2
	lsr.w	d1,d2
	move.w	d2,d1
*	not	d1
*	jsr	2(a5)
	bsr	myputline2
row_done:
	tst.w	d7
	beq.s	poly_done
	subq.w	#1,d5
	bpl.s	more_rows_1
start_poly:
	sub.l	a2,d4
	moveq	#0,d3
	move.w	(a3),d3
	swap	d3
	move.w	-(a3),d5
	sub	4(a3),d5
	moveq	#0,d0
	move.w	d5,d0
	moveq	#0,d1
	move.w	-(a3),d1
	sub.w	4(a3),d1

	bsr.s	get_grad
	move.l	d0,a1
	cmpi.w	#1,d6
	bmi.s	two_verts
	addq.w	#1,d7
	bra.s	next_scan
more_rows_1:
	subq.w	#1,d6
	bpl.s	more_rows_r
	addq.w	#1,d5
	sub.l	a1,d3
two_verts:
bp2:	moveq	#0,d4
	move.w	-4(a4),d4
	swap	d4
	moveq	#0,d1
	move.w	(a4)+,d1
	move.w	(a4)+,d6
	sub.w	-6(a4),d6
	moveq	#0,d0
	move.w	d6,d0
	sub.w	-8(a4),d1

	bsr.s	get_grad
	move.l	d0,a2
	addq.w	#1,d7
	bra.s	next_scan
more_rows_r:
	lea	160(a6),a6
	move.l	(sp)+,d1
	exg	d1,a5
	move.l	d1,-(sp)
next_scan:
	dbra	d7,polyfill_lp
poly_done:
	addq.l	#4,sp
*	move.l	(sp)+,a6
abort_poly:
	movem.l	(sp)+,d0-d7/a0-a6
	rts
bp1:
get_grad:
	beq.s	vert_grad
	bmi.s	neg_grad

	divu	d0,d1
	swap	d0
	move.w	d1,d0
	swap	d0
	clr	d1
	divu	d0,d1
	move.w	d1,d0
	rts
vert_grad:
	moveq	#0,d0
	rts
neg_grad:
	neg.w	d1
	divu	d0,d1
	swap	d0
	move.w	d1,d0
	swap	d0
	clr	d1
	divu	d0,d1
	move.w	d1,d0
	neg.l	d0
	rts




myputline:
	not	d2
	and.w	d2,(a0)
	and.w	d2,2(a0)
	and.w	d2,4(a0)
	and.w	d2,6(a0)
	not	d2
	move.w	(a5),d1
	and.w	d2,d1
	or.w	d1,(a0)+
	move.w	2(a5),d1
	and.w	d2,d1
	or.w	d1,(a0)+
	move.w	4(a5),d1
	and.w	d2,d1
	or.w	d1,(a0)+
	move.w	6(a5),d1
	and.w	d2,d1
	or.w	d1,(a0)+
	rts
myputline2:
*	not	d2
	and.w	d2,(a0)
	and.w	d2,2(a0)
	and.w	d2,4(a0)
	and.w	d2,6(a0)
	not	d2
	move.w	(a5),d1
	and.w	d2,d1
	or.w	d1,(a0)+
	move.w	2(a5),d1
	and.w	d2,d1
	or.w	d1,(a0)+
	move.w	4(a5),d1
	and.w	d2,d1
	or.w	d1,(a0)+
	move.w	6(a5),d1
	and.w	d2,d1
	or.w	d1,(a0)+
	rts




col_code:
	dc.l	0,0
	dc.w	0
	btst	#0,(a5)
	bne.s	s_p_a

	and.w	d2,(a0)+
	bra.s	c_p_a
s_p_a:
	or.w	d1,(a0)+
c_p_a:
	btst	#1,(a5)
	bne.s	s_p_b
	and.w	d2,(a0)+
	bra.s	c_p_b
s_p_b:
	or.w	d1,(a0)+
c_p_b:
	btst	#2,(a5)
	bne.s	s_p_c
	and.w	d2,(a0)+
	bra.s	c_p_c
s_p_c:
	or.w	d1,(a0)+
c_p_c:
	btst	#3,(a5)
	bne.s	s_p_d
	and.w	d2,(a0)+
	rts
s_p_d:
	or.w	d1,(a0)+
	rts

col_dat:
	dc.l	$00000000,$00000000
	dc.l	$ffff0000,$00000000
	dc.l	$0000ffff,$00000000
	dc.l	$ffffffff,$00000000
	dc.l	$00000000,$ffff0000
	dc.l	$ffff0000,$ffff0000
	dc.l	$0000ffff,$ffff0000
	dc.l	$ffffffff,$ffff0000
	dc.l	$00000000,$0000ffff
	dc.l	$ffff0000,$0000ffff
	dc.l	$0000ffff,$0000ffff
	dc.l	$ffffffff,$0000ffff
	dc.l	$00000000,$ffffffff
	dc.l	$ffff0000,$ffffffff
	dc.l	$0000ffff,$ffffffff
	dc.l	$ffffffff,$ffffffff


*****************************************
*	my own personal poly draw	*
*****************************************
draw_polygon2:
	movem.l	d0-d7/a0-a6,-(sp)
	lea	surfacevrt,a6
	move.l	a6,a5
	move.w	(a5)+,d7		;get number
	move.w	#1024,d2		;lowest poss x,y
getminloop:
	cmp.w	(a5),d2
	blt.s	gmm1
	move.w	(a5),d2		;becomes new max
gmm1:
	addq.l	#4,a5
	dbf	d7,getminloop
	move.l	a6,a5
	move.w	(a5)+,d7		;get number
	move.w	#-1024,d3		;lowest poss x,y
getmaxloop:
	cmp.w	(a5),d3
	bgt.s	gmm2
	move.w	(a5),d3		;becomes new max
gmm2:
	addq.l	#4,a5
	dbf	d7,getmaxloop

	cmpi.w	#cxmax,d2
	bge	nono
	cmpi.w	#cxmin,d3
	ble	nono
	move.l	a6,a0
	move.w	(a0)+,d7		;number of vertices
	moveq	#0,d6
	move.w	#-1024,d0
getl:
	cmp.w	2(a0),d0
	ble.s	swappeml
	addq.l	#4,a0
	addq.w	#1,d6
	dbf	d7,getl
	bra.s	rotatelist
swappeml:
	move.w	2(a0),d0
	move.w	d6,d5
	addq.w	#1,d6		;count how far in
	addq.l	#4,a0
	dbf	d7,getl		;note that is highest on screen

rotatelist:
	cmpi.w	#cymin,d0	;check if lowest y is above clipy
	ble	nono
	move.w	d5,d0
	beq.s	noneedtorot
	move.l	a6,a0
	move.w	(a0)+,d5
	subq.w	#1,d5
	move.l	a0,a1
	subq.w	#1,d0
rtloop:
	move.l	a1,a0
	move.w	d5,d1
	move.w	(a0),d2
	move.w	2(a0),d3
rtloop2:
	move.w	4(a0),(a0)
	move.w	6(a0),2(a0)
	addq.l	#4,a0
	dbf	d1,rtloop2
	move.w	d2,(a0)
	move.w	d3,2(a0)
	dbf	d0,rtloop
noneedtorot:
gethighest:		;actually lowest
	move.l	a6,a0
	move.w	(a0)+,d7		;number of vertices
	moveq	#0,d6
	move.w	#1024,d0
geth:
	cmp.w	2(a0),d0
	bgt.s	swappemh
	addq.l	#4,a0
	addq.w	#1,d6
	dbf	d7,geth
	bra.s	seperateleftright
swappemh:
	move.w	2(a0),d0
	move.w	d6,d5
	addq.w	#1,d6		;count how far in
	addq.l	#4,a0
	dbf	d7,geth		;note that is highest on screen
seperateleftright:
	cmpi.w	#cymax,d0
	bge	nono
	move.l	a6,a0
	move.w	(a0)+,d3
	lea	rightlist,a1
	move.w	d5,d0
	beq	nono
	move.w	d0,(a1)+	;number of points
sprloop:
	move.w	(a0)+,(a1)+
	move.w	(a0)+,(a1)+
	dbf	d0,sprloop
	move.l	a6,a3
	move.w	d5,d0
	sub.w	d0,d3		;overall number of points -highest
	lea	leftlist,a1
	move.w	d3,(a1)+	;number of points
	move.w	(a3)+,d4	;get number
	addq.w	#1,d4
	move.w	(a3),(a1)+	;top point
	move.w	2(a3),(a1)+
	asl.w	#2,d4		;*4
	add.w	d4,a3		;should now point at bottom of list
splloop:
	move.w	-(a3),2(a1)	;y
	move.w	-(a3),(a1)	;x	
	addq.l	#4,a1
	dbf	d3,splloop
calculatecoords:
	moveq	#-1,d5
	lea	lxylist,a6
	addq.l	#2,a6		;fill in number later
	lea	leftlist,a0
	moveq	#0,d6		;counter for Ys
	bsr.s	calccoords
	move.w	d6,lxylist		;count of y's
	ble	nono

	moveq	#1,d5
	lea	rxylist,a6
*	addq.l	#2,a6		;fill in number later
	lea	rightlist,a0
	moveq	#0,d6		;counter for Ys
	bsr.s	calccoords
*	move.w	d6,rxylist		;count of y's
*	ble	nono
	bra	drawitin
calccoords:
	move.w	(a0)+,d7	;number of line segs
ccloop1:
	moveq	#0,d0
	moveq	#0,d1
	moveq	#0,d2
	moveq	#0,d3
	move.w	(a0),d0		;x1
	move.w	2(a0),d1	;y1
	move.w	4(a0),d2	;x2
	move.w	6(a0),d3	;y2
	sub.w	d1,d3		;y2-y1	gives number of y's
	bge.s	skipthis
	neg.w	d3
	sub.w	d0,d2		;x2-x1
	asl.l	#5,d2		;scale up
	ext.l	d2
	divs	d3,d2		;div by y
	ext.l	d2
	asl.l	#5,d0
	subq.w	#1,d3
ccloop1in:
	move.l	d0,d4
	cmpi.w	#cymin,d1
	bge.s	clp3
	bra.s	clp5
clp3:
	cmpi.w	#cymax,d1
	ble.s	clp4
	bra.s	clp5
clp4:
	asr.l	#5,d4		;scale down
	cmpi.w	#cxmin,d4
	bge.s	clp1
	move.w	#cxmin,d4
	bra.s	clp2
clp1:
	cmpi.w	#cxmax,d4
	ble.s	clp2
	move.w	#cxmax,d4
clp2:
	tst.w	d5
	bpl	noy
	move.w	d1,(a6)+	;y
	moveq	#1,d5
noy:	move.w	d4,(a6)+	;x
	addq.w	#1,d6
clp5:	add.l	d2,d0		;add xamount
	subq.w	#1,d1		;next y
	dbf	d3,ccloop1in
skipthis:
	addq.l	#4,a0		;move to next coords
	dbf	d7,ccloop1
	asr.l	#5,d0
	move.w	d0,(a6)+	;spit the last out
*	move.w	d1,(a6)+
skt:	rts

drawitin:
	lea	surfacedfn,a0
	move.w	(a0)+,d7
	move.w	(a0)+,d5		;secondcol
	bsr	init_hcol2
	lea	lxylist,a5
	lea	rxylist,a6
	move.w	(a5)+,d6	;count of y's
	subq.w	#1,d6
	move.w	(a5)+,d0	;get the first y
	move.l	ytable,a0	;add of tab with y addresses
	lsl.w	#2,d0		;mult by 4
	move.l	(a0,d0.w),a0	;a0 has add of start of line
	move.l	a0,yadd
diiloop:
	move.w	(a5)+,d2	;x1
	move.w	(a6)+,d4	;x2
	move.l	yadd,a0
	bsr.L	drawtheline
	subi.l	#160,yadd
	dbf	d6,diiloop
nono:	movem.l	(sp)+,d0-d7/a0-a6
	rts

surfacedfn:	dc.w	0	;color
		dc.l	surfacevrt
surfacevrt:	dc.w	0	;number of points
		blk.w	64,0
******************************************
*	d0=y1  d2=x1  d4=x2
noline:
	rts
drawtheline:
	exg	a3,a2
	cmpi.w	#cxmax,d2
	bgt.s	noline		;totally off screen
	cmpi.w	#cxmin,d4
	blt.s	noline		;totally off screen
dlt4:
	cmp.w	d2,d4
	blt.s	noline
	move.w	d2,x1
	move.w	d4,x2
	move.w	d2,d3		;make a copy x1
	and.w	#$fff0,d2
	lsr.w	#1,d2	
	add.w	d2,a0		;a0 has add of start of line
	move.w	d4,d5		;d5 has x2
	and.w	#$fff0,d4
	lsr.w	#4,d4
	move.w	d3,d2
	and.w	#$fff0,d2
	lsr.w	#4,d2
	sub.w	d2,d4		;gives number of words across
	lea	endmask,a1
	and.w	#15,d3
	lsl.w	#1,d3
	move.w	(a1,d3.w),d0	;d0 start mask
	lea	startmask,a1
	and.w	#15,d5
	lsl.w	#1,d5
	move.w	(a1,d5.w),d1	;d1 end mask
drawhline:
	cmpi.w	#1,d4
	blt	allline
	beq	spechline
	bsr	drawstart
	bsr	drawmid
	bsr	drawend
	rts

spechline:
	bsr	drawstart
	bsr	drawend
	rts

drawstart:
	move.w	d0,d7
	not	d7
	and.w	d0,(a0)
	move.w	(a3),d5
	and.w	d7,d5
	or	d5,(a0)+
	and.w	d0,(a0)
	move.w	2(a3),d5
	and.w	d7,d5
	or	d5,(a0)+
	and.w	d0,(a0)
	move.w	4(a3),d5
	and.w	d7,d5
	or	d5,(a0)+
	and.w	d0,(a0)
	move.w	6(a3),d5
	and.w	d7,d5
	or	d5,(a0)+
	rts
*******************
*	d0=start mask
*	d1=end mask
*	d4=words across may have to sub 1 or 2 ????
*	d6=number of y positions
*	a0=start address
*	a1=copy of a0
*	a3=color table
*******************
drawmid:
	move.w	d4,d2	;copy width
	subq.w	#2,d2
dml:
	move.w	(a3),(a0)+
	move.w	2(a3),(a0)+
	move.w	4(a3),(a0)+
	move.w	6(a3),(a0)+
	dbf	d2,dml
	rts
drawend:
	move.w	d1,d7
	not	d7
	and.w	d1,(a0)
	move.w	(a3),d5
	and.w	d7,d5
	or	d5,(a0)+
	and.w	d1,(a0)
	move.w	2(a3),d5
	and.w	d7,d5
	or	d5,(a0)+
	and.w	d1,(a0)
	move.w	4(a3),d5
	and.w	d7,d5
	or	d5,(a0)+
	and.w	d1,(a0)
	move.w	6(a3),d5
	and.w	d7,d5
	or	d5,(a0)+
	rts

allline:
	move.w	x1,d2	;x1
	and.w	#15,d2
	move.w	x2,d5
	and.w	#15,d5
	add.w	d2,d2
	add.w	d5,d5
	move.l	#startmask,a4
	move.w	(a4,d2.w),d0	
	move.l	#endmask,a4
	and.w	(a4,d5.w),d0	
	move.w	d0,d7
	not	d7
	and.w	d7,(a0)
	move.w	(a3),d5
	and.w	d0,d5
	or	d5,(a0)+
	and.w	d7,(a0)
	move.w	2(a3),d5
	and.w	d0,d5
	or	d5,(a0)+
	and.w	d7,(a0)
	move.w	4(a3),d5
	and.w	d0,d5
	or	d5,(a0)+
	and.w	d7,(a0)
	move.w	6(a3),d5
	and.w	d0,d5
	or	d5,(a0)+
	rts

startmask:
	dc.w	$ffff,$7fff,$3fff,$1fff
	dc.w	$0fff,$07ff,$03ff,$01ff
	dc.w	$00ff,$007f,$003f,$001f
	dc.w	$000f,$0007,$0003,$0001
	dc.w	$0000
endmask:
	dc.w	$0000,$8000,$c000,$e000
	dc.w	$f000,$f800,$fc00,$fe00
	dc.w	$ff00,$ff80,$ffc0,$ffe0
	dc.w	$fff0,$fff8,$fffc,$fffe
	dc.w	$ffff


init_hcol2:
		asl.w   #3,D7		;index a3 table
		asl.w   #3,D5		;index a3 table
                lea     col_table,a4
                lea     (a4,D7.w),a4 
		lea	fcoltable1,a3
		move.w	(a4)+,d0
		move.w	(a4)+,d1
		move.w	(a4)+,d2
		move.w	(a4)+,d3
		lea	col_table2,a4
		lea	(a4,d5.w),a4
		or.w	(a4)+,d0
		or.w	(a4)+,d1
		or.w	(a4)+,d2
		or.w	(a4)+,d3
		lea	fcoltable2,a2
		move.w	d0,(a3)
		move.w	d1,2(a3)
		move.w	d2,4(a3)
		move.w	d3,6(a3)
		ror.w	#1,d0
		ror.w	#1,d1
		ror.w	#1,d2
		ror.w	#1,d3
		move.w	d0,(a2)
		move.w	d1,2(a2)
		move.w	d2,4(a2)
		move.w	d3,6(a2)
                rts
fcoltable1:
	dc.w	0,0,0,0
fcoltable2:
	dc.w	0,0,0,0

col_table:
		DC.w      00,00,00,00     ;Colour 0
                DC.w      $aaaa,00,00,00     ;Colour 1
                DC.w      00,$aaaa,00,00     ;Colour 2
                DC.w      $aaaa,$aaaa,00,00     ;Colour 3
                DC.w      00,00,$aaaa,00     ;Colour 4        
                DC.w      $aaaa,00,$aaaa,00     ;Colour 5        
                DC.w      00,$aaaa,$aaaa,00     ;Colour 6        
                DC.w      $aaaa,$aaaa,$aaaa,00     ;Colour 7        
                DC.w      00,00,00,$aaaa     ;Colour 8        
                DC.w      $aaaa,00,00,$aaaa     ;Colour 9
                DC.w      00,$aaaa,00,$aaaa     ;Colour 10
                DC.w      $aaaa,$aaaa,00,$aaaa     ;Colour 11
                DC.w      00,00,$aaaa,$aaaa     ;Colour 12
                DC.w      $aaaa,00,$aaaa,$aaaa     ;Colour 13
                DC.w      00,$aaaa,$aaaa,$aaaa     ;Colour 14       
                DC.w      $aaaa,$aaaa,$aaaa,$aaaa     ;Colour 15
col_table2:
		DC.w      00,00,00,00     ;Colour 0
                DC.w      $5555,00,00,00     ;Colour 1
                DC.w      00,$5555,00,00     ;Colour 2
                DC.w      $5555,$5555,00,00     ;Colour 3
                DC.w      00,00,$5555,00     ;Colour 4        
                DC.w      $5555,00,$5555,00     ;Colour 5        
                DC.w      00,$5555,$5555,00     ;Colour 6        
                DC.w      $5555,$5555,$5555,00     ;Colour 7        
                DC.w      00,00,00,$5555     ;Colour 8        
                DC.w      $5555,00,00,$5555     ;Colour 9
                DC.w      00,$5555,00,$5555     ;Colour 10
                DC.w      $5555,$5555,00,$5555     ;Colour 11
                DC.w      00,00,$5555,$5555     ;Colour 12
                DC.w      $5555,00,$5555,$5555     ;Colour 13
                DC.w      00,$5555,$5555,$5555     ;Colour 14       
                DC.w      $5555,$5555,$5555,$5555     ;Colour 15
lxylist:	blk.w	500,0		;space for 123 coord pairs
rxylist:	blk.w	500,0
highestpair:	dc.w	0
lowestpair:	dc.w	0
leftlist:	blk.w	500,0
rightlist:	blk.w	500,0
scrollx:	dc.w	0
scrolly:	dc.w	0
******************************************
setuphbl:
	move.w	#$2700,sr
	move.l	#hbllist,hblsave
	move.b	ieb,oldieb
	move.b	iea,oldiea
	move.b	ima,oldima
	move.l	key_vec,oldkeyvec
	move.l	key_vec,keyt+2
	move.l	#key_handler,key_vec		;put new key stuff in
	move.l	hbl_vec,oldhblvec

*	and.b	#$df,ieb	;stop 200hz timer
	move.b	#%01000000,ieb
	and.b	#$fe,iea	;stop hblank
	move.l	hbl_vec,oldhblvec
	move.l	#hblhandler1,hbl_vec
*	or.b	#1,iea			;enable hblank
	move.b	#%00000001,iea
	or.b	#1,ima

*	move.l	vbl_vec,vblt+2		;set up vbl handler
	move.l	vbl_vec,oldvblvec
	move.l	#vbl_handler,vbl_vec
	move.b	#0,tbcr
	move.b	#5,tbdr
	move.b	#8,tbcr
	move.w	#$2300,sr
	rts

hblhandler2:
	movem.l	a0/a1,-(sp)
	move.l	#$ff8240,a0
	lea	palette2,a1
	move.l	(a1)+,(a0)+
	move.l	(a1)+,(a0)+
	move.l	(a1)+,(a0)+
	move.l	(a1)+,(a0)+
	move.l	(a1)+,(a0)+
	move.l	(a1)+,(a0)+
	move.l	(a1)+,(a0)+
	move.l	(a1)+,(a0)+
	movem.l	(sp)+,a0/a1
	move.b	#0,tbcr
	move.b	#100,tbdr
	move.b	#8,tbcr
	bclr	#0,isra
	rte
hblhandler1:
	movem.l	d0/a0,-(sp)
	move.l	hblsave,a0
	move.w	(a0)+,d0
	bmi	endlist
	move.w	d0,$ff8240
	move.b	#0,tbcr
	move.w	(a0)+,d0
	move.l	a0,hblsave
	move.b	d0,tbdr
	move.b	#8,tbcr
	bclr	#0,isra
	movem.l	(sp)+,d0/a0
	rte
endlist:
	movem.l	a0/a1,-(sp)
	move.l	#$ff8240,a0
	lea	palette2,a1
	move.l	(a1)+,(a0)+
	move.l	(a1)+,(a0)+
	move.l	(a1)+,(a0)+
	move.l	(a1)+,(a0)+
	move.l	(a1)+,(a0)+
	move.l	(a1)+,(a0)+
	move.l	(a1)+,(a0)+
	move.l	(a1)+,(a0)+
	movem.l	(sp)+,a0/a1
	move.b	#0,tbcr
	move.w	(a0)+,d0
	move.l	a0,hblsave
	move.b	d0,tbdr
	move.b	#8,tbcr
	bclr	#0,isra
	movem.l	(sp)+,d0/a0
	rte
	

hbllist:
	dc.w	$0007,1,$0005,6,$0007,1,$0005,110,$0004
	dc.w	4,$0005,3,$0004,1,$0333,2,$0555,13,-1,200
	dc.w	$0444,1,$0666,1,$0777,1,$0555,1,$0444
	dc.w	1,$0333,1,$0555,1,$0333,6,$0555,9,$0444
	dc.w	1,$0666,1,$0777,1,$0555,1,$0444,1,$0333
	dc.w	1,$0555,1,$0333,6,$0555,13

hblsave:	dc.l	0
	
vbl_handler:
	move.l	#hbllist,hblsave
	move.b	#0,tbcr
	move.b	#5,tbdr
	move.b	#8,tbcr
*	move.l	#hblhandler1,hbl_vec
vblt:
	movem.l	d0-d7/a0-a6,-(sp)
	bsr	framevbl
	movem.l	(sp)+,d0-d7/a0-a6
	rte

key_handler:
	move.w	#$2500,sr
keyt:	jmp	$0


oldvblvec:	blk.l	1,0
oldkeyvec:	blk.l	1,0
oldhblvec:	blk.l	1,0
oldieb:		blk.b	1,0
oldiea:		blk.b	1,0
oldima:		blk.b	1,0
even

restoremfp:
	move.b	oldieb,ieb
	move.b	oldiea,iea
	move.b	oldima,ima
	move.l	oldkeyvec,key_vec
	move.l	oldhblvec,hbl_vec
	move.l	oldvblvec,vbl_vec
	rts
*************************************
leftbutton:	equ	1
rightbutton:	equ	2
bothbuttons:	equ	3
**********************************
clearboth:
	move.l	seen,a0
	move.l	hiden,a1
	move.w	#15999,d0
cbl:
	move.w	#0,(a0)+
	move.w	#0,(a1)+
	dbf	d0,cbl
	rts
*****************************************
copyintoboth:
	move.l	screen3,a0
	move.l	hiden,a1
	move.l	seen,a2
	move.w	#7999,d0
cibloop:
	move.l	(a0),(a1)+
	move.l	(a0)+,(a2)+
	dbf	d0,cibloop
	rts

mytheta:	dc.w	0
myphi:		dc.w	0
myrho:		dc.w	0
whichob:	dc.l	0
testdraw:
anim1:
	lea	lights,a0
	move.l	a0,whichob
	move.w	#525,obz(a0)
*	move.w	my,d0
*	add.w	d0,obz(a0)
	move.w	#-30,oby(a0)
	move.l	obviewpb(a0),a0
*	move.w	mx,theta(a0)
	move.w	my,rho(a0)
*	tst.w	buttondat
*	bne	skipa1
*	addq.w	#2,rho(a0)
skipa1:
	move.w	#0,phi(a0)
	bsr	dobefore

	lea	road,a0
	move.l	a0,whichob
	move.w	#525,obz(a0)
	move.w	#40,oby(a0)
	move.w	my,d0
	add.w	d0,obz(a0)
	bsr	dobefore

	lea	car,a0
	move.l	a0,whichob
	sub.w	#30,obz(a0)
	cmpi.w	#100,obz(a0)
	bgt.s	zokt
	move.w	#1050,obz(a0)
zokt:
*	move.w	#450,obz(a0)
	move.w	#30,oby(a0)
	bsr	dobefore

	lea	car,a1
	lea	carwire,a0
	move.l	a0,whichob
	move.w	obz(a1),obz(a0)
	move.w	oby(a1),oby(a0)
	bra	dobefore
	rts

dobefore:
	move.l	whichob,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
	move.w	d3,onscreenx(a0)
	move.w	d4,onscreeny(a0)
	lea	vtrans_vrt,a1	;list of transformed vertices
	lea	ptrans_vrt,a2	;list of onscreen coords
	move.w	linecolinfo(a0),linecolor
	cmpi.w	#dots,style(a0)
	beq	objectisdots
	move.w	hidenflag(a0),hdf
	move.l	obcolors(a0),a6		;face color list
	move.l	obfacelist(a0),a0
	move.w	(a0)+,d0	;number of faces
	subq	#1,d0
tdloop:
	move.w	(a0)+,numfacesave	;number of points in face
*	subq.w	#1,numfacesave		;save number of points-1
	move.w	(a6)+,facecolor1
	move.w	(a6)+,facecolor2
	tst.w	hdf
	bmi	pdt
*	bra	pdt
	move.w	(a0),d2		;offset of face point
	move.w	2(a0),d3	;second point
	move.w	4(a0),d4	;third point

	move.w	d2,d5		;simulate mulu #6 only faster
	lsl.w	#1,d2
	lsl.w	#2,d5
	add.w	d5,d2

	move.w	d3,d5		;simulate mulu #6 only faster
	lsl.w	#1,d3
	lsl.w	#2,d5
	add.w	d5,d3

	move.w	d4,d5		;simulate mulu #6 only faster
	lsl.w	#1,d4
	lsl.w	#2,d5
	add.w	d5,d4

	move.w	(a1,d3.w),d5	;get x2
	move.w	d5,kx
	sub.w	(a1,d2.w),d5	;x2-x1
	move.w	d5,px
	move.w	2(a1,d3.w),d5	;get y2
	move.w	d5,ky
	sub.w	2(a1,d2.w),d5	;y2-y1
	move.w	d5,py
	move.w	4(a1,d3.w),d5	;get z2
	move.w	d5,kz
	sub.w	4(a1,d2.w),d5	;z2-z1
	move.w	d5,pz

	move.w	(a1,d4.w),d5	;x3
	sub.w	(a1,d2.w),d5	;x3-x1
	move.w	2(a1,d4.w),d6	;y3
	sub.w	2(a1,d2.w),d6	;y3-y1
	move.w	4(a1,d4.w),d7	;z3
	sub.w	4(a1,d2.w),d7	;z3-z1

	move.w	d5,d1
	move.w	d6,d2
	move.w	d7,d3

	muls	py,d3
	muls	pz,d2
	sub.w	d2,d3
	move.w	d3,rx
	muls	pz,d1
	muls	px,d7
	sub.w	d7,d1
	move.w	d1,ry
	muls	px,d6
	muls	py,d5
	sub.w	d5,d6
	move.w	d6,rz

	moveq	#0,d1		;projection centre x
	sub.w	kx,d1
	moveq	#0,d2		;projection centre y
	sub.w	ky,d2
	moveq	#0,d3		;projection centre z
	sub.w	kz,d3
	muls	rx,d1
	muls	ry,d2
	muls	rz,d3
	add.l	d1,d2
	add.l	d2,d3
	ble	notvisible
pdt:
	move.w	numfacesave,d1
	move.l	whichob,a5
	cmpi.w	#filled,style(a5)
	beq	drawfilled
	move.w	(a0),d2
	asl.w	#2,d2		;*4 for offsett
	move.w	(a2,d2.w),x1s
	move.w	2(a2,d2.w),y1s
	subq.w	#1,d1
	bpl.s	visible
	addq.w	#1,d1
visible:
	move.w	(a0),d2
	asl.w	#2,d2		;*4 for offsett
	move.w	(a2,d2.w),x1
	move.w	2(a2,d2.w),y1
	move.w	2(a0),d2
	asl.w	#2,d2		;*4 for offsett
	move.w	(a2,d2.w),x2
	move.w	2(a2,d2.w),y2
	move.w	x2,x2s
	move.w	y2,y2s
	bsr	clipit
	addq.l	#2,a0
	dbf	d1,visible
	move.w	x1s,x1
	move.w	y1s,y1
	move.w	x2s,x2
	move.w	y2s,y2
	bsr	clipit
	addq.l	#2,a0
	dbf	d0,tdloop
	rts

drawfilled:
	move.w	facecolor1,surfacedfn	;color
	move.w	facecolor2,surfacedfn+2
	lea	surfacevrt,a5
	move.w	d1,(a5)+		;number of points
dfloop:
	move.w	(a0)+,d2
	asl.w	#2,d2		;*4 for offsett
	move.w	(a2,d2.w),(a5)+
	move.w	2(a2,d2.w),(a5)+
	dbf	d1,dfloop
	bsr	draw_polygon3
	dbf	d0,tdloop
	rts

notvisible:
	move.w	numfacesave,d1
	addq.w	#1,d1
	asl.w	#1,d1
	add.w	d1,a0	
*	addq.l	#2,a0
	dbf	d0,tdloop
	rts

objectisdots:
	move.w	#11,pixelcolor
	lea	ptrans_vrt,a1	;list of onscreen coords
	move.w	numdots(a0),d0	;get the number of points
	subq.w	#1,d0
dotloop:
	move.w	(a1)+,pixelx
	move.w	(a1)+,pixely
	bsr	singleplot
	dbf	d0,dotloop
	rts

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
cxmin:		equ	16
cxmax:		equ	303
cymin:		equ	13
cymax:		equ	122
cbits:	blk.w	1,0
cbits2:	blk.w	1,0
xsav:	blk.w	1,0
ysav:	blk.w	1,0
*/**//*/*//*//*/*//*//*/*/*//*/*/*/*//*/*/*/*//*//*//*///*/*/
bitcode:clr.l   d4
        cmpi.w  #cxmin,d0
        bge     b1
        or.b    #8,d4
b1:     cmpi.w  #cxmax,d0
        ble     b2
        or.b    #4,d4
b2:     cmpi.w  #cymin,d1
        bge     b3
        or.b    #1,d4
b3:     cmpi.w  #cymax,d1
        ble     b4
        or.b    #2,d4
b4:     move.w  d4,cbits
        rts
*****
bitc2:   clr.l   d5
        cmpi.w  #cxmin,d2
        bge     b5
        or.b    #8,d5
b5:     cmpi.w  #cxmax,d2
        ble     b6
        or.b    #4,d5
b6:     cmpi.w  #cymin,d3
        bge     b7
        or.b    #1,d5
b7:     cmpi.w  #cymax,d3
        ble     b8
        or.b    #2,d5
b8:     move.w  d5,cbits2
        rts
********************************************************
clipit:
	movem.l	d0-d7/a0,-(sp)
	move.w	x1,d0
	move.w	y1,d1
	move.w	x2,d2
	move.w	y2,d3

	bsr     bitcode
        bsr     bitc2
clipit2:or.b    d4,d5
        tst.b   d5
        beq     cliphome        ;finish if
        move.w  cbits,d4
        move.w  d2,xsav
        move.w  d3,ysav
        move.w  cbits2,d5
clip1:  and.b   d4,d5
        tst.b   d5
        bgt     clipb           ;home if line completely out
        move.w  cbits,d4
        move.w  cbits2,d5
        sub.w   d0,d2           ;d1 has dx
        move.w  d2,dx
        sub.w   d1,d3           ;d3 has dy
        move.w  d3,dy
        move.w  xsav,d2
        move.w  ysav,d3
        tst.w   d4
        beq     clip2   	;if x1<xmin
        cmpi.w  #cxmin,d0 	;y1=y1+dy*(xmin-x1)/dx
        bge     c1      
        move.w  #cxmin,d7         ;put xmin in d7
        sub.w   d0,d7
        muls    dy,d7           ;multiply by dy
        divs    dx,d7
        add.w   d1,d7
        move.w  d7,d1
        move.w  #cxmin,d0         ;x1=xmin
        bra     c4
c1:     cmpi.w  #cxmax,d0         ;if x1>xmax
        ble     c2              ;y1=y1+dy*(xmax-x1)/dx
        move.w  #cxmax,d7         ;put xmax in d7
        sub.w   d0,d7
        muls    dy,d7           ;multiply by dy
        divs    dx,d7
        add.w   d1,d7
        move.w  d7,d1
        move.w  #cxmax,d0         ;x1=xmax
        bra     c4
c2:     cmpi.w  #cymin,d1         ;if y1<ymin
        bge     c3
        move.w  #cymin,d7         ;put ymin in d7
        sub.w   d1,d7
        muls    dx,d7           ;multiply by dx
        divs    dy,d7
        add.w   d0,d7
        move.w  d7,d0
        move.w  #cymin,d1         ;y1=ymin
        bra     c4
c3:     cmpi.w  #cymax,d1         ;if y1>xmax
        ble     c4
        move.w  #cymax,d7         ;put ymax in d7
        sub.w   d1,d7
        muls    dx,d7           ;multiply by dy
        divs    dy,d7
        add.w   d0,d7
        move.w  d7,d0
        move.w  #cymax,d1         ;y1=ymax
c4:     bsr     bitcode
        bra     cliploop
******
clip2:  cmpi.w  #cxmin,d2 ;	y1=y1+dy*(xmin-x1)/dx
        bge     cc1     
        move.w  #cxmin,d7         ;put xmin in d7
        sub.w   d2,d7
        muls    dy,d7           ;multiply by dy
        divs    dx,d7
        add.w   d3,d7
        move.w  d7,d3
        move.w  #cxmin,d2         ;x2=xmin
        bra     cc4
cc1:    cmpi.w  #cxmax,d2         ;if x2>xmax
        ble     cc2
        move.w  #cxmax,d7         ;put xmax in d7
        sub.w   d2,d7
        muls    dy,d7           ;multiply by dy
        divs    dx,d7
        add.w   d3,d7
        move.w  d7,d3
        move.w  #cxmax,d2         ;x1=xmax
        bra     cc4
cc2:    cmpi.w  #cymin,d3         ;if y1<ymin
        bge     cc3
        move.w  #cymin,d7         ;put ymin in d7
        sub.w   d3,d7
        muls    dx,d7           ;multiply by dx
        divs    dy,d7
        add.w   d2,d7
        move.w  d7,d2
        move.w  #cymin,d3         ;y1=ymin
        bra     cc4
cc3:    cmpi.w  #cymax,d3         ;if y1>xmax
        ble     cc4
        move.w  #cymax,d7         ;put ymax in d7
        sub.w   d3,d7
        muls    dx,d7           ;multiply by dy
        divs    dy,d7
        add.w   d2,d7
        move.w  d7,d2
        move.w  #cymax,d3         ;y1=ymax
cc4:    bsr     bitc2
        bra     cliploop

cliploop:
        bra     clipit2
cliphome:
        move.w  d0,x1
        move.w  d1,y1
        move.w  d2,x2
        move.w  d3,y2
	bsr	myline
	movem.l	(sp)+,d0-d7/a0
	rts
clipb:
	movem.l	(sp)+,d0-d7/a0
	rts
*********************************************************
linecolor:
	blk.w	1,0
***********************************************
*	lets plot a fucking line
*	but lets do it fast
*	first some conventions
*	draws line on hiden screen
*	between x1,y1,x2,y2 
***********************************************
myline:
*	movem.l	d4-d7/a0,-(sp)
calcdx:
	move.w	x2,d0
	sub.w	x1,d0	;x2-x1
	move.w	d0,dx	;d0 is dx
	bpl	calcdy
	neg	d0
calcdy:
	move.w	y2,d1
	sub.w	y1,d1	;y2-y1	
	move.w	d1,dy	;d6 is dy
	bpl	cmparedxdy
	neg	d1
cmparedxdy:
	cmp.w	d0,d1
	bgt	ymajor	;if dy is greater then ymajor
xmajor:
*	tst.w	dy
*	beq	horizontal	;special case
	tst.w	dx
	bpl	noswapx
	move.w	x2,d0
	move.w	x1,x2
	move.w	d0,x1
	move.w	y2,d0
	move.w	y1,y2
	move.w	d0,y1
	neg	dx
	neg	dy
noswapx:
	moveq	#0,d0
	move.w	dx,d0
	divs	dy,d0
	bmi	xpositive

xnegative:
	move.l	hiden,a0	;screen ad
	move.w	dx,d0
	move.w	d0,d7	;counter is d7
	subq.w	#1,d7
	asr.w	#1,d0	;div by 2
	move.w	d0,d6	;dump is d6
	move.w	x1,d0	;will hold bitpattern
	move.w	d0,d2
	move.w	y1,d1
	lsl.w	#5,d1	;mult y by 128
	adda.w	d1,a0	;add it to screen address
	lsl.w	#2,d1	;mult by 32 makes mult by 160
	adda.w	d1,a0	;a0 now has start screen address
	and.w	#$fff0,d0	;mask off last 4 bits gives word across
	lsr.w	#1,d0
	add.w	d0,a0
	moveq	#0,d4
	tst.w	d7
	bmi	specxneg
	move.w	d2,d3
	and.w	#15,d3
	bne	xmnloop
	subq.l	#8,a0
xmnloop:
	move.w	d2,d3
	and.w	#15,d3
	bne	xmnla
	bsr	putlinein
	moveq	#0,d4
	addq.l	#8,a0
xmnla:	sub.w	#15,d3
	neg	d3
	bset	d3,d4
	sub.w	dy,d6	;sub dy from dump
	bpl	xmn
	add.w	dx,d6
	bsr	putlinein
	adda.l	#160,a0		;moveit to next line
	moveq	#0,d4
xmn:
	addq.w	#1,d2
	dbf	d7,xmnloop
specxneg:
	move.w	d2,d3
	and.w	#15,d3
	bne	spct1
	rts
spct1:	sub.w	#15,d3
	neg	d3
	bset	d3,d4
	bsr	putlinein
	rts

putlinein:
	move.w	d4,d5
	eor.w	#$ffff,d5
	and.w	d5,(a0)		;clearout old pixels
	and.w	d5,2(a0)
	and.w	d5,4(a0)
	and.w	d5,6(a0)
	move.w	linecolor,d5
plane1:
	btst	#0,d5
	beq	plane2
	or.w	d4,(a0)
plane2:
	btst	#1,d5
	beq	plane3
	or.w	d4,2(a0)
plane3:
	btst	#2,d5
	beq	plane4
	or.w	d4,4(a0)
plane4:
	btst	#3,d5
	beq	plane5
	or.w	d4,6(a0)
plane5:
	rts

xpositive:
	move.l	hiden,a0	;screen ad
	move.w	dx,d0
	move.w	d0,d7	;counter is d7
	subq.w	#1,d7
	asr.w	#1,d0	;div by 2
	move.w	d0,d6	;dump is d6
	move.w	x1,d0	;will hold bitpattern
	move.w	d0,d2
	move.w	y1,d1
	lsl.w	#5,d1	;mult y by 128
	adda.w	d1,a0	;add it to screen address
	lsl.w	#2,d1	;mult by 32 makes mult by 160
	add.w	d1,a0	;a0 now has start screen address
	and.w	#$fff0,d0	;mask off last 4 bits gives word across
	lsr.w	#1,d0
	add.w	d0,a0
	moveq	#0,d4
	move.w	d2,d3
	and.w	#15,d3
	bne	xmploop
	subq.l	#8,a0
xmploop:
	move.w	d2,d3
	and.w	#15,d3
	bne	xmpla
	bsr	putlinein
	moveq	#0,d4
	addq.l	#8,a0
xmpla:	sub.w	#15,d3
	neg	d3
	bset	d3,d4
	add.w	dy,d6	;sub dy from dump
	bpl	xmp
	add.w	dx,d6
	bsr	putlinein
	moveq	#0,d4
	suba.l	#160,a0		;moveit to next line
xmp:
	addq.w	#1,d2
	dbf	d7,xmploop
	move.w	d2,d3
	and.w	#15,d3
	bne	spct2
	rts
spct2:	sub.w	#15,d3
	neg	d3
	bset	d3,d4
	bsr	putlinein
	rts

ymajor:
	tst.w	dy
	bpl	noswapy
	move.w	x2,d0
	move.w	x1,x2
	move.w	d0,x1
	move.w	y2,d0
	move.w	y1,y2
	move.w	d0,y1
	neg	dx
	neg	dy
noswapy:
	moveq	#0,d0
	move.w	dy,d0
	divs	dx,d0
	bmi	ypositive
ynegative:
	tst.w	dx
	beq	straightup1	;special case vertical line
	move.l	hiden,a0	;screen ad
	move.w	dy,d0
	move.w	d0,d7	;counter is d7
*	subq.w	#1,d7
	asr.w	#1,d0	;div by 2
	move.w	d0,d6	;dump is d6
	move.w	x1,d0	;will hold bitpattern
	move.w	d0,d3
	move.w	y1,d1
	move.w	d1,d2
	lsl.w	#5,d1	;mult y by 128
	adda.w	d1,a0	;add it to screen address
	lsl.w	#2,d1	;mult by 32 makes mult by 160
	add.w	d1,a0	;a0 now has start screen address
	and.w	#$fff0,d0	;mask off last 4 bits gives word across
	lsr.w	#1,d0
	add.w	d0,a0
	move.w	d3,d0	;x
	moveq	#0,d4
	move.w	d0,d3
	and.w	#15,d3
	move.w	#$8000,d4
	lsr.w	d3,d4
ymnloop:
	bsr	putlinein
	add.w	#160,a0		;y+1
	sub.w	dx,d6		;sub dy from dump
	bpl	ymn
	add.w	dy,d6
	addq.w	#1,d0		;x+1
	move.w	d0,d3
	and.w	#15,d3
	bne	ymnla
	addq.l	#8,a0
ymnla:	move.w	#$8000,d4
	lsr.w	d3,d4
ymn:
	dbf	d7,ymnloop
*	movem.l	(sp)+,d4-d7/a0
	rts

ypositive:
	tst.w	dx
	beq	straightup	;special case vertical line
	move.l	hiden,a0	;screen ad
	move.w	dy,d0
	move.w	d0,d7	;counter is d7
	subq.w	#1,d7
	asr.w	#1,d0	;div by 2
	move.w	d0,d6	;dump is d6
	move.w	x1,d0	;will hold bitpattern
	move.w	d0,d3
	move.w	y1,d1
	move.w	d1,d2
	lsl.w	#5,d1	;mult y by 128
	adda.w	d1,a0	;add it to screen address
	lsl.w	#2,d1	;mult by 32 makes mult by 160
	add.w	d1,a0	;a0 now has start screen address
	and.w	#$fff0,d0	;mask off last 4 bits gives word across
	lsr.w	#1,d0
	add.w	d0,a0
	move.w	d3,d0	;x
	moveq	#0,d4
*	move.w	d0,d3
	and.w	#15,d3
	move.w	#$8000,d4
	lsr.w	d3,d4

ymploop:
	bsr	putlinein
	add.w	#160,a0	;y+1
	add.w	dx,d6	;sub dy from dump
	bpl	ymp
	add.w	dy,d6
	subq.w	#1,d0	;x+1
	move.w	d0,d3
	and.w	#15,d3
	cmpi.w	#15,d3
	bne	ympla
	subq.l	#8,a0
ympla:	move.w	#$8000,d4
	lsr.w	d3,d4
ymp:
	dbf	d7,ymploop
*	movem.l	(sp)+,d4-d7/a0
	rts

straightup:
	move.l	hiden,a0	;screen ad
	move.w	dy,d7
	move.w	x1,d0	;will hold bitpattern
	move.w	d0,d3
	move.w	y1,d1
	lsl.w	#5,d1	;mult y by 128
	adda.w	d1,a0	;add it to screen address
	lsl.w	#2,d1	;mult by 32 makes mult by 160
	add.w	d1,a0	;a0 now has start screen address
	and.w	#$fff0,d0	;mask off last 4 bits gives word across
	lsr.w	#1,d0
	add.w	d0,a0	;now a0 is ready
	moveq	#0,d4
	and.w	#15,d3
	move.w	#$8000,d4
	lsr.w	d3,d4	;d4 has proper bit pattern
	add.l	#160,a0
	addq.w	#1,d7
stuploop:
	bsr	putlinein
	add.l	#160,a0
	dbf	d7,stuploop
*	movem.l	(sp)+,d4-d7/a0
	rts	

straightup1:
	move.l	hiden,a0	;screen ad
	move.w	dy,d7
	move.w	x1,d0	;will hold bitpattern
	move.w	d0,d3
	move.w	y1,d1
	lsl.w	#5,d1	;mult y by 128
	adda.w	d1,a0	;add it to screen address
	lsl.w	#2,d1	;mult by 32 makes mult by 160
	add.w	d1,a0	;a0 now has start screen address
	and.w	#$fff0,d0	;mask off last 4 bits gives word across
	lsr.w	#1,d0
	add.w	d0,a0	;now a0 is ready
	moveq	#0,d4
	and.w	#15,d3
	move.w	#$8000,d4
	lsr.w	d3,d4	;d4 has proper bit pattern
	add.l	#160,a0
	addq.w	#1,d7
stuploop1:
	bsr	putlinein
	sub.l	#160,a0
	dbf	d7,stuploop
*	movem.l	(sp)+,d4-d7/a0
	rts	


dump:	blk.w	1,0
gradient:	blk.w	1,0
x1:	blk.w	1,0
x2:	blk.w	1,0
y1:	blk.w	1,0
y2:	blk.w	1,0
dx:	blk.w	1,0
dy:	blk.w	1,0
plx:	dc.w	0
ply:	dc.w	0
plz:	dc.w	0
myviewx:	dc.w	0
myviewy:	dc.w	0

***************************************************************************
*		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
	cmpi.w	#100,d5
	bge.s	zok
	moveq	#100,d5
zok:
	move.w	d3,(a1)+
	move	d4,(a1)+
	move	d5,(a1)+
okz:	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	#67,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
****************************************
keyboard:
        move.w  #$ff,-(sp)
        move.w  #6,-(sp)
        trap    #1
        addq.l  #4,sp
        tst.l   d0
        beq     keyback
        swap    d0
quit:   cmpi.w  #$10,d0
        bne     space
        bra     gem
space:
	cmpi.w	#$39,d0
	bne	keyback
	bra	pause

keyback:rts
*****************************
pause:  
        move.w  #$ff,-(sp)
        move.w  #6,-(sp)
        trap    #1
        addq.l  #4,sp
        tst.l   d0
        beq     pause
        swap    d0
        cmpi.w  #$1e,d0
        bne     keyback 
        bsr     gkey
        cmpi.w  #$32,d0
        bne     keyback
        bsr     gkey
        cmpi.w  #$1e,d0
        bne     keyback
        bsr     gkey
        cmpi.w  #$31,d0
        bne     keyback
        bsr     gkey
        cmpi.w  #$20,d0
        bne     keyback
        bsr     gkey
        cmpi.w  #$1e,d0
        bne     keyback
	move.w	#1,cheat
	rts

gkey:
        move.w  #$ff,-(sp)
        move.w  #6,-(sp)
        trap    #1
        addq.l  #4,sp
        tst.l   d0
        beq     gkey
        swap    d0
        rts
gkey2:
	movem.l	d1-d7/a0-a6,-(sp)
gk3:    move.w  #$ff,-(sp)
        move.w  #6,-(sp)
        trap    #1
        addq.l  #4,sp
        tst.l   d0
        beq     gk3
	swap    d0
*	bsr	fitcode
	movem.l	(sp)+,d1-d7/a0-a6
        rts
cheat:	dc.w	-1


***********************************
mydocolors:
	move.l	#$ff8240,a1
	moveq	#15,d0
mdcloop:
	move.w	(a0)+,(a1)+
	dbf	d0,mdcloop
	rts

************get screen address***************
getscrn:move.w  #2,-(sp)
        trap    #14
        addq.l  #2,sp
        move.l  d0,screen
        move.l  d0,screen1
        move.l  d0,screen2
        subi.l  #$8000,screen2
        move.l  screen1,seen
        move.l  screen2,hiden
	move.l	screen2,screen3
	subi.l	#$8000,screen3
	move.l	screen3,generalstore
	subi.l	#100000,generalstore
	move.l	#ytable2,ytable
	move.l	#ytable1,sytable
	rts
screen1:	dc.l	0
screen2:	dc.l	0
screen3:	dc.l	0
generalstore:	dc.l	0
seen:	dc.l	0
hiden:	dc.l	0
screen:	dc.l	0


********************************************
* Atari ST hi-speed plotting subroutine    *
* For Low-resolution mode only		   *
********************************************
plotinit:
	move.l	seen,a0		;screen addr in A0
	move.b	#200,d1		;200 Y positions
	lea	ytable1,a1	;y table address in A1

iloop:
	move.l	a0,(a1)+	;move address to table
	adda.w	#160,a0		;increment address
	subq.b	#1,d1		;1 less y position
	bne	iloop		;loop if there's more!

	move.l	hiden,a0	;screen addr in A0
	move.b	#200,d1		;200 Y positions
	lea	ytable2,a1	;y table address in A1

iloop2:
	move.l	a0,(a1)+	;move address to table
	adda.w	#160,a0		;increment address
	subq.b	#1,d1		;1 less y position
	bne	iloop2		;loop if there's more!
	rts

pixelx:	blk.w	1,0
pixely:	blk.w	1,0
pixelcolor:
	blk.w	1,0
ytable1:	blk.l	200,0
ytable2:	blk.l	200,0
ytable:		blk.l	1,0
sytable:	blk.l	1,0
**********************************************
singleplot:
	movem.l	d0-d5/a0-a1,-(sp)
	move.w	pixelx,d0      ;x coordinate in D0
	cmp.w	#cxmax,d0
	bgt	pltxit
	cmpi.w	#cxmin,d0
	blt	pltxit
	move.w	d0,d3         ;duplicate in D3
	andi.w	#15,d3        ;mask off lower 4 bits
	move.w	pixely,d1      ;get y coordinate,
	cmp.w	#cymax,d1
	bgt	pltxit
	cmpi.w	#cymin,d1
	blt	pltxit
	lsl.w	#2,d1          ;mult by 4 for index
	move.w	pixelcolor,d2      ;get color number

	lsr.w	#1,d0             ;x coord / 2
	and.w	#$00f8,d0      ;strip lower 3 bits
	move.w	d0,a0        ;move x offset to A0
	move.l	ytable,a1   ;get y table addr
	adda.l	(a1,d1.w),a0 ;got final pixel addr!

	move.w #$8000,d4     ;set ON pixel mask
	lsr.w d3,d4          ;shift right D3 times
	move.l #$80008000,d5 ;set OFF pixel mask
	lsr.l d3,d5          ;shift right D3 times
	eor.l #$ffffffff,d5  ;toggle all bits in D5
	bra	myphere

myphere:
	and.l d5,(a0)        ;turn off old pixel
	and.l d5,4(a0)       ;(both longwords)
******************************
* Now turn on the new pixel! *
******************************
	btst #0,d2           ;set the bit?
	beq bit2             ;no!
	or.w d4,(a0)         ;turn it on!
bit2:
	btst #1,d2           ;set it?
	beq bit4             ;no!
	or.w d4,2(a0)        ;turn it on!
bit4:
	btst #2,d2           ;set bit?
	beq bit8             ;no!
	or.w d4,4(a0)        ;turn it on!
bit8:
	btst #3,d2           ;set bit?
	beq pltxit           ;no, exit.
	or.w d4,6(a0)        ;turn it on!
pltxit:
	movem.l	(sp)+,d0-d5/a0-a1
	rts                  ;bye!
pltxit2:
	movem.l	(sp)+,d0-d5/a0-a1
	moveq	#-1,d0
	rts                  ;bye!

*************************************
clearquick:
	move.l	hiden,a0
	adda.l	#2088,a0
	moveq	#109,d0
	move.l	#$ffff0000,d7
	moveq	#0,d6
cl2loop:
	move.l	d7,(a0)+
	move.l	d6,(a0)+
	move.l	d7,(a0)+
	move.l	d6,(a0)+
	move.l	d7,(a0)+
	move.l	d6,(a0)+
	move.l	d7,(a0)+
	move.l	d6,(a0)+
	move.l	d7,(a0)+
	move.l	d6,(a0)+
	move.l	d7,(a0)+
	move.l	d6,(a0)+
	move.l	d7,(a0)+
	move.l	d6,(a0)+
	move.l	d7,(a0)+
	move.l	d6,(a0)+
	move.l	d7,(a0)+
	move.l	d6,(a0)+
	move.l	d7,(a0)+
	move.l	d6,(a0)+
	move.l	d7,(a0)+
	move.l	d6,(a0)+
	move.l	d7,(a0)+
	move.l	d6,(a0)+
	move.l	d7,(a0)+
	move.l	d6,(a0)+
	move.l	d7,(a0)+
	move.l	d6,(a0)+
	move.l	d7,(a0)+
	move.l	d6,(a0)+
	move.l	d7,(a0)+
	move.l	d6,(a0)+
	move.l	d7,(a0)+
	move.l	d6,(a0)+
	move.l	d7,(a0)+
	move.l	d6,(a0)+
	add.l	#16,a0
	dbf	d0,cl2loop
cqb:	rts


beamer:
	move.l	#$ff8205,a0
	moveq	#0,d0
	move.b	(a0),d0
	asl.l	#8,d0
	adda.w	#2,a0
	move.b	(a0),d0
	asl.l	#8,d0
	adda.w	#2,a0
	move.b	(a0),d0
	move.l	d0,a0
	move.w	#0,(a0)
	rts
flip_scr:
	move.l	seen,d1
	move.l	d1,d2
	add.l	#4000,d1
	add.l	#18000,d2
skloop:
	move.l	#$ff8205,a0
	moveq	#0,d0
	move.b	(a0),d0
	asl.l	#8,d0
	addq.l	#2,a0
	move.b	(a0),d0
	asl.l	#8,d0
	addq.l	#2,a0
	move.b	(a0),d0
	cmp.l	d1,d0
	blt.s	skloop
	cmp.l	d2,d0
	bgt.s	skloop
        move.l  seen,A6
        move.l  hiden,seen
        move.l  A6,hiden
        move.l  sytable,A6
        move.l  ytable,sytable
        move.l  A6,ytable
	bsr	clearquick
	move.b	seen+1,$ff8201
	move.b	seen+2,$ff8203
	addq.w	#1,frames
	rts

framevbl:
	move.w	framess,number
	move.w	#27048,numwhere
	bsr	prtnum
	addq.w	#1,numvbl
	cmpi.w	#50,numvbl
	blt	fvblback
	move.w	frames,framess
	move.w	#0,numvbl
	move.w	#0,frames
fvblback:
*	lea	bluepalette,a0
*	bsr	mydocolors
	bsr	dolightcolors
	rts


dolightcolors:
	subq.w	#1,ldelay
	bpl	dlok2
	move.w	#1,ldelay
	move.w	lcount,d0
	lea	lplist,a0
	move.l	(a0,d0.w),a0
	addq.w	#4,lcount
	cmpi.w	#16,lcount
	ble.s	dlok
	move.w	#0,lcount
dlok:
	move.l	a0,lastpal
	bsr	mydocolors
	rts
dlok2:
	move.l	lastpal,a0
	bsr	mydocolors
	rts

lastpal:	dc.l	0
lcount:		dc.w	0	
ldelay:		dc.w	2
numvbl:		dc.w	0
frames:		dc.w	0
framess:		dc.w	0
*****************************************
prtnum: 
	movem.l	d0/d6/d7/a0/a5/a1,-(sp)
	move.w	#0,times
        moveq  	#0,d7
	moveq	#4,d0
        move.w  number,d7
        andi.l  #$ffff,d7
        lea	lineout,a5
	tst.w	d7
	bpl	dodec2
	move.b	#10,(a5)+
	neg.w	d7
dodec2:
	move.l  d7,d6
        divu    #10,d6
        move.w  d6,d7
        swap    d6
        move.b  d6,(a5)+
	subq.w	#1,d0
        tst.w  d7
        bne     dodec2
	tst.w	d0
	bmi	out2
blankloop:
	move.b	#10,(a5)+
	dbf	d0,blankloop
out2:
	cmpa.l  #lineout,a5
        beq     decback2
	moveq	#0,d7
        move.b  -(a5),d7
	subq.w	#1,d6
*        andi.w  #$ff,d7
	lea	smallnumbers,a0
	mulu	#44,d7
	add.w	d7,a0
	moveq	#10,d0
	move.l	seen,a1
	adda.w	numwhere,a1
oloop2:
	move.b	(a0)+,(a1)
	move.b	(a0)+,2(a1)
	move.b	(a0)+,4(a1)
	move.b	(a0)+,6(a1)
	add.l	#160,a1
	dbf	d0,oloop2
	addq.w	#1,times
	cmpi.w	#2,times
	blt	oh2
	move.w	#0,times
	addq.w	#6,numwhere
oh2:	addq.w	#1,numwhere
	bra	out2
decback2:
	movem.l	(sp)+,d0/d6/d7/a0/a5/a1
	rts


safe:	dc.w	0
lineout:	blk.l	5
times:		dc.w	0
number:		dc.w	0
numwhere:	dc.w	0
******************************************
*               RETURN TO GEM
gem:
	bsr	restoremfp
	move.b	#%11111110,$ff820a
	move.w	#$0777,$ff8240
	move.w	#$0000,$ff8242
	move.w	#$0000,$ff8244
	move.w	#$0000,$ff8246

*	move.w	#0,$452
*	move.l	oldvbl1,a0
*	move.l	#0,(a0)
*	move.w	#1,$452

*	jsr	res_mouse
        move.b  #7,$484

	move.w  #34,-(sp)
        trap    #14
        addq.l  #2,sp
        move.l  d0,a0
	move.l	oldmouse,16(a0)

        move.w  ressave,-(sp)
        move.l  screen,-(sp)
        move.l  screen,-(sp)
        move.w  #5,-(sp)
        trap    #14
        addi.l  #12,sp

	move.l	rvsave,$426
	move.l	resave,$42a
        
        move.l  savesup,-(SP)    ;Back to user mode
        move.w  #$20,-(SP)
        trap    #1
        addq.l  #6,(SP)
illegal

rvsave:	dc.l	0
resave:	dc.l	0

*********************************************************
*	my routines for loading in the screens		*
*********************************************************
loadscr:
*	move.b	oldieb,ieb
	move	#0,-(SP)	;Open file
	move.l	filename,-(SP) ;Address of filename
	move	#$3D,-(SP)
	trap	#1		;Get handle number in D0
	addq.l	#8,SP
	tst.w	d0
	bmi	nofile
	move.l	hiden,-(SP)    ;load it straight onto screen
	move.l	#32000,-(SP)		;length to read in
	move	D0,-(SP)	;Handle
	move	#$3F,-(SP)	;bios number
	trap	#1		;Read file in
	addi.l	 #12,SP

	move	#$3E,-(SP)	;Handle already on stack
	trap	#1		;Close file
	addq.l	#2,SP
*	and.b	#$df,ieb

	move.l	hiden,a0
	move.l	a0,a1
stl:
	move.b	(a1)+,d0
	bne	stl
	move.l	screen3,a2	;where to put it
decom:
	move.l	a2,a3		; a3 sauvegarde debut ecran
	moveq	#39,d0		; d0 indice des colonnes = 40 passages
	move.l	#199,d1 	; d1 indice des lignes	 = 200 passages
	sub.l	d2,d2		; d2 est remis a zero ...
	move.b	(a0)+,d2	; on prend le premier compteur
	subq.l	#1,d2		; decrement du compteur pour dbra
	move.b	(a1)+,d3
	lsl.l	#8,d3
	move.b	(a1)+,d3
	lsl.l	#8,d3
	move.b	(a1)+,d3
	lsl.l	#8,d3
	move.b	(a1)+,d3
	moveq	#4,d7
boucle:
	move.l	d3,(a2) 	; qu'on bazarde a l'ecran
	dbra	d2,encore	; test et decrement du compteur
	sub.l	d2,d2		; remise a zero du compteur
	move.b	(a0)+,d2	; si le compteur = 0 on rechoppe de 
	subq.l	#1,d2		; decrement de d2 (pour faire un dbra)
	move.b	(a1)+,d3
	lsl.l	#8,d3
	move.b	(a1)+,d3
	lsl.l	#8,d3
	move.b	(a1)+,d3
	lsl.l	#8,d3
	move.b	(a1)+,d3
encore:
	lea	160(a2),a2
	dbra	d1,boucle	; test pour voir si on est en bas
	adda.l	d7,a3		; un long plus loin
	move.l	a3,a2
	move.l	#199,d1 	; et c'est parti pour une nouvelle colonne
	dbra	d0,boucle
nofile:
	rts

length:		dc.w	0
***************************************
oldmouse:	blk.l	1,0
*************puts my mouse interupt in***************** 
putrout:move.w  #34,-(sp)
        trap    #14
        addq.l  #2,sp
        move.l  d0,a0
	move.l	16(a0),oldmouse
        move.l  #myrout,16(a0)
        rts
lastb:		dc.w	-1
**************my ubeut mouse interupt*******************
myrout:
	movem.l	d0-d2/a0-a1,-(sp)
	moveq	#0,d0	
	move.b	(a0),d0
	cmpi.b	#$fa,d0
	bne	myr1
	move.w	#1,buttondat
	bra	myrxy
myr1:
	cmpi.b	#$f9,d0
	bne	myr2
	move.w	#2,buttondat
	bra	myrxy
myr2:
	cmpi.b	#$fb,d0
	bne	myr3
	move.w	#3,buttondat
	bra	myrxy
myr3:
	move.w	#0,buttondat
myrxy:
	moveq	#0,d0
	move.b	1(a0),d0
	ext.w	d0
	moveq	#0,d1
	move.b	2(a0),d1
	ext.w	d1
*	lsl.w	#6,d0
*	lsl.w	#6,d1
	sub.w	d0,mx
	sub.w	d1,my
myr4:	move.w	mx,d0
	move.w	my,d1
	bsr	extra
	move.w	d0,mx
	move.w	d1,my
	movem.l	(sp)+,d0-d2/a0-a1
	rts

extra:  cmpi.w	#mminx,d0
        bge    .S extra1
        move.w	#mminx,d0
        bra    .S extra2
extra1: cmpi.w   #mmaxx,d0
        ble    .S extra2
        move.w  #mmaxx,d0
extra2:	cmpi.w  #mminy,d1
        bge    .S extra3
        move.w  #mminy,d1
        bra	extra4
extra3: cmpi.w   #mmaxy,d1
        ble    .S extra4
        move.w  #mmaxy,d1
extra4:
        rts

buttondat:	dc.w	0
mx:		dc.w	160
my:		dc.w	100

mminx:	equ	-255	;13
mmaxx:	equ	255
mminy:	equ	-255	;3
mmaxy:	equ	255	; 13 123
fileshipcomp:	dc.b	'front.cmp',0
even
savesup:	dc.l	0
ressave:	dc.w	0
filename:	dc.l	0
bluepalette:
	dc.w	$0555,$0000,$0555,$0333,$0507,$0406,$0305,$0007
	dc.w	$0006,$0005,$0004,$0070,$0040,$0020,$0055,$0077
lpalette1:
	dc.w	$0555,$0000,$0555,$0333,$0000,$0333,$0777,$0007
	dc.w	$0006,$0005,$0004,$0070,$0040,$0020,$0333,$0000
lpalette2:
	dc.w	$0555,$0000,$0555,$0333,$0000,$0000,$0333,$0007
	dc.w	$0006,$0005,$0004,$0070,$0040,$0020,$0777,$0333
lpalette3:
	dc.w	$0555,$0000,$0555,$0333,$0333,$0000,$0000,$0007
	dc.w	$0006,$0005,$0004,$0070,$0040,$0020,$0333,$0777
lpalette4:
	dc.w	$0555,$0000,$0555,$0333,$0777,$0333,$0000,$0007
	dc.w	$0006,$0005,$0004,$0070,$0040,$0020,$0000,$0333
lpalette5:
	dc.w	$0555,$0000,$0555,$0333,$0333,$0777,$0333,$0007
	dc.w	$0006,$0005,$0004,$0070,$0040,$0020,$0000,$0000
lplist:
	dc.l	lpalette1,lpalette2,lpalette3,lpalette4,lpalette5

palette2:
	dc.w	$0555,$0000,$0777,$0666,$0555,$0444,$0333,$0443
	dc.w	$0332,$0732,$0247,$0124,$0740
p2cyc:	dc.w	$0077,$0066,$0055

smallnumbers:
	dc.b	$87,$87,$87,$78,$7B,$7B,$7B,$84
	dc.b	$7B,$7B,$7B,$84,$7B,$7B,$7B,$84
	dc.b	$7B,$7B,$7B,$84,$FF,$87,$FF,$00
	dc.b	$7B,$7B,$7B,$84,$7B,$7B,$7B,$84
	dc.b	$7B,$7B,$7B,$84,$7B,$7B,$7B,$84
	dc.b	$87,$87,$87,$78,$FF,$87,$FF,$00
	dc.b	$FB,$7B,$FB,$04,$FB,$7B,$FB,$04
	dc.b	$FB,$7B,$FB,$04,$FB,$7B,$FB,$04
	dc.b	$FF,$87,$FF,$00,$FB,$7B,$FB,$04
	dc.b	$FB,$7B,$FB,$04,$FB,$7B,$FB,$04
	dc.b	$FB,$7B,$FB,$04,$FF,$87,$FF,$00
	dc.b	$87,$87,$87,$78,$FB,$7B,$FB,$04
	dc.b	$FB,$7B,$FB,$04,$FB,$7B,$FB,$04
	dc.b	$FB,$7B,$FB,$04,$87,$87,$87,$78
	dc.b	$7F,$7B,$7F,$80,$7F,$7B,$7F,$80
	dc.b	$7F,$7B,$7F,$80,$7F,$7B,$7F,$80
	dc.b	$87,$87,$87,$78,$87,$87,$87,$78
	dc.b	$FB,$7B,$FB,$04,$FB,$7B,$FB,$04
	dc.b	$FB,$7B,$FB,$04,$FB,$7B,$FB,$04
	dc.b	$87,$87,$87,$78,$FB,$7B,$FB,$04
	dc.b	$FB,$7B,$FB,$04,$FB,$7B,$FB,$04
	dc.b	$FB,$7B,$FB,$04,$87,$87,$87,$78
	dc.b	$FF,$87,$FF,$00,$7B,$7B,$7B,$84
	dc.b	$7B,$7B,$7B,$84,$7B,$7B,$7B,$84
	dc.b	$7B,$7B,$7B,$84,$87,$87,$87,$78
	dc.b	$FB,$7B,$FB,$04,$FB,$7B,$FB,$04
	dc.b	$FB,$7B,$FB,$04,$FB,$7B,$FB,$04
	dc.b	$FF,$87,$FF,$00,$87,$87,$87,$78
	dc.b	$7F,$7B,$7F,$80,$7F,$7B,$7F,$80
	dc.b	$7F,$7B,$7F,$80,$7F,$7B,$7F,$80
	dc.b	$87,$87,$87,$78,$FB,$7B,$FB,$04
	dc.b	$FB,$7B,$FB,$04,$FB,$7B,$FB,$04
	dc.b	$FB,$7B,$FB,$04,$87,$87,$87,$78
	dc.b	$87,$87,$87,$78,$7F,$7B,$7F,$80
	dc.b	$7F,$7B,$7F,$80,$7F,$7B,$7F,$80
	dc.b	$7F,$7B,$7F,$80,$87,$87,$87,$78
	dc.b	$7B,$7B,$7B,$84,$7B,$7B,$7B,$84
	dc.b	$7B,$7B,$7B,$84,$7B,$7B,$7B,$84
	dc.b	$87,$87,$87,$78,$87,$87,$87,$78
	dc.b	$FB,$7B,$FB,$04,$FB,$7B,$FB,$04
	dc.b	$FB,$7B,$FB,$04,$FB,$7B,$FB,$04
	dc.b	$FF,$87,$FF,$00,$FB,$7B,$FB,$04
	dc.b	$FB,$7B,$FB,$04,$FB,$7B,$FB,$04
	dc.b	$FB,$7B,$FB,$04,$FF,$87,$FF,$00
	dc.b	$87,$87,$87,$78,$7B,$7B,$7B,$84
	dc.b	$7B,$7B,$7B,$84,$7B,$7B,$7B,$84
	dc.b	$7B,$7B,$7B,$84,$87,$87,$87,$78
	dc.b	$7B,$7B,$7B,$84,$7B,$7B,$7B,$84
	dc.b	$7B,$7B,$7B,$84,$7B,$7B,$7B,$84
	dc.b	$87,$87,$87,$78,$87,$87,$87,$78
	dc.b	$7B,$7B,$7B,$84,$7B,$7B,$7B,$84
	dc.b	$7B,$7B,$7B,$84,$7B,$7B,$7B,$84
	dc.b	$87,$87,$87,$78,$FB,$7B,$FB,$04
	dc.b	$FB,$7B,$FB,$04,$FB,$7B,$FB,$04
	dc.b	$FB,$7B,$FB,$04,$FF,$87,$FF,$00
	dc.b	$FF,$87,$FF,$00,$FF,$7B,$FF,$00
	dc.b	$FF,$7B,$FF,$00,$FF,$7B,$FF,$00
	dc.b	$FF,$7B,$FF,$00,$FF,$87,$FF,$00
	dc.b	$FF,$7B,$FF,$00,$FF,$7B,$FF,$00
	dc.b	$FF,$7B,$FF,$00,$FF,$7B,$FF,$00
	dc.b	$FF,$87,$FF,$00

even
vtrans_vrt:	blk.w	500	;View transformed coordinates	
ptrans_vrt:	blk.w	500	;Perspective transformed coordinates
***************************************************************************
filled:		equ	0
line:		equ	1
dots:		equ	2
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:	blk.w	20,0
boxvpb:		blk.w	20,0
startvpb:	blk.w	20,0
template:
*	dc.l	met1vpb		;pointer to the vpb
	dc.w	0,0,-1500	;overall object x,y,z
*	dc.l	met1vrt		;pointer to its vertices
*	dc.l	met1face	;pointer to faces
	dc.w	filled		;filled or line or dots
	dc.w	11		;when line becomes color info or numdots
*	dc.l	met1colors	;face color pointer
	dc.w	1		;hidden line removal flag
	dc.w	-1		;activeflag
	dc.w	1		;can it be hit
	dc.w	100		;obwidth,height,depth for collision
	dc.w	0,0		;onscreenx,y
box:
	dc.l	boxvpb
	dc.w	0,0,1000		;overall object x,y,z
	dc.l	boxvrt
	dc.l	boxface
	dc.w	line		;filled or line or dots
	dc.w	15		;number of dots
	dc.l	boxcol		;face color list
	dc.w	-1		;1 is do hiden line removal
	dc.w	-1
	dc.w	1
	dc.w	120
	dc.w	0,0		;onscreenx,y
boxcol:
	dc.w	5,5,6,6,7,7,8,8,9,9,4,4
boxvrt:
	dc.w	16
	dc.w	 -40,40,40
	dc.w	40,40,40
	dc.w	40,40,-40
	dc.w	-40,40,-40
	dc.w	-40,-40,40
	dc.w	40,-40,40
	dc.w	40,-40,-40
	dc.w	-40,-40,-40

	dc.w	 -60,60,60
	dc.w	60,60,60
	dc.w	60,60,-60
	dc.w	-60,60,-60
	dc.w	-60,-60,60
	dc.w	60,-60,60
	dc.w	60,-60,-60
	dc.w	-60,-60,-60

boxface:
	dc.w	14
	dc.w	3,4,5,1,0
	dc.w	3,1,5,6,2
	dc.w	3,2,6,7,3
	dc.w	3,3,7,4,0
	dc.w	3,0,1,2,3
	dc.w	3,4,7,6,5
	dc.w	0,0,8
	dc.w	0,1,9
	dc.w	0,2,10
	dc.w	0,3,11
	dc.w	0,4,12
	dc.w	0,5,13
	dc.w	0,6,14
	dc.w	0,7,15

testvpb:	blk.w	20,0
test:
	dc.l	testvpb
	dc.w	0,0,800		;overall object x,y,z
	dc.l	testvrt
	dc.l	testface
	dc.w	filled		;filled or line or dots
	dc.w	15		;number of dots
	dc.l	testcolors		;face color list
	dc.w	1		;1 is do hiden line removal
	dc.w	-1
	dc.w	1
	dc.w	120
	dc.w	0,0		;onscreenx,y
testcolors:
	dc.w	7,7,10,10,8,8,8,9,9,9,10,9,4,4,4,5
	dc.w	5,5,5,6,4,5,5,5
	dc.w	5,6,6,6
testvrt:
	dc.w	24
	dc.w	-10,30,-30
	dc.w	10,30,-30
	dc.w	30,10,-30
	dc.w	30,-10,-30
	dc.w	10,-30,-30
	dc.w	-10,-30,-30
	dc.w	-30,-10,-30
	dc.w	-30,10,-30

	dc.w	30,30,-10
	dc.w	30,-30,-10
	dc.w	-30,-30,-10
	dc.w	-30,30,-10

	dc.w	-10,30,30
	dc.w	10,30,30
	dc.w	30,10,30
	dc.w	30,-10,30
	dc.w	10,-30,30
	dc.w	-10,-30,30
	dc.w	-30,-10,30
	dc.w	-30,10,30

	dc.w	30,30,10
	dc.w	30,-30,10
	dc.w	-30,-30,10
	dc.w	-30,30,10


testface:
	dc.w	14		;13
	dc.w	7,0,1,2,3,4,5,6,7
	dc.w	7,19,18,17,16,15,14,13,12
	dc.w	7,2,8,20,14,15,21,9,3
	dc.w	7,0,11,23,12,13,20,8,1
	dc.w	7,11,7,6,10,22,18,19,23
	dc.w	7,10,5,4,9,21,16,17,22

	dc.w	2,1,8,2
	dc.w	2,3,9,4
	dc.w	2,6,5,10
	dc.w	2,11,0,7

	dc.w	2,13,14,20
	dc.w	2,15,16,21
	dc.w	2,22,17,18
	dc.w	2,12,23,19

ship3vpb:	blk.w	20,0
ship3:
	dc.l	ship3vpb
	dc.w	0,0,1100
	dc.l	ship3vrt
	dc.l	ship3face
	dc.w	filled
	dc.w	0
	dc.l	ship3colors
	dc.w	1
	dc.w	-1
	dc.w	-1
	dc.w	0
	dc.w	0,0
ship3colors:
	dc.w	7,7,7,8,8,9,14,14,1,9,1,8,1,9
	dc.w	15,14,7,8,8,9,9,10,14,14,7,5,7,4

ship3vrt:
	dc.w	17
	dc.w	47,00,00
	dc.w	51,01,-70
	dc.w	31,00,-114
	dc.w	-24,82,00
	dc.w	-26,89,-70
	dc.w	-16,55,-114
	dc.w	00,00,158
	dc.w	-23,-83,00
	dc.w	-25,-90,-70
	dc.w	-15,-55,-114
	dc.w	00,00,-149
	dc.w	00,-20,98
	dc.w	-6,-60,10
	dc.w	26,-20,10
	dc.w	00,20,98
	dc.w	-6,60,10
	dc.w	26,20,10
ship3face:
	dc.w	14
	dc.w	2,06,00,03
	dc.w	3,00,01,04,03
	dc.w	3,01,02,05,04
	dc.w	2,02,10,05
	dc.w	2,06,03,07
	dc.w	3,03,04,08,07
	dc.w	3,04,05,09,08
	dc.w	2,05,10,09
	dc.w	2,06,07,00
	dc.w	3,07,08,01,00
	dc.w	3,08,09,02,01
	dc.w	2,09,10,02
	dc.w	2,11,12,13
	dc.w	2,16,15,14



road:
	dc.l	lightsvpb
	dc.w	0,30,1100
	dc.l	roadvrt
	dc.l	roadface
	dc.w	filled
	dc.w	3
	dc.l	roadcolors
	dc.w	-1
	dc.w	-1
	dc.w	-1
	dc.w	0
	dc.w	0,0
roadcolors:
	dc.w	3,3
roadvrt:
	dc.w	4
	dc.w	-80,0,1050
	dc.w	-80,0,-1050
	dc.w	80,0,1050
	dc.w	80,0,-1050
roadface:
*	dc.w	2
*	dc.w	1,0,1
*	dc.w	1,2,3
	dc.w	1
	dc.w	3,0,1,3,2

lightsvpb:	blk.w	20,0
lights:
	dc.l	lightsvpb
	dc.w	0,0,1100
	dc.l	lightvrt
	dc.l	lightface
	dc.w	filled
	dc.w	42
	dc.l	lightcolors
	dc.w	-1
	dc.w	-1
	dc.w	-1
	dc.w	0
	dc.w	0,0
lightcolors:
	dc.w	4,4,5,5,6,6,14,14,15,15
	dc.w	4,4,5,5,6,6,14,14,15,15
	dc.w	4,4,5,5,6,6,14,14,15,15
	dc.w	4,4,5,5,6,6,14,14,15,15

*lightvrt:
*	dc.w	42
lightvrt:
        dc.w    42
        dc.w    -5,0,150*7
        dc.w    5,0,150*7
        dc.w    -5,0,135*7
        dc.w    5,0,135*7
        dc.w    -5,0,120*7
        dc.w    5,0,120*7
        dc.w    -5,0,105*7
        dc.w    5,0,105*7
        dc.w    -5,0,90*7
        dc.w    5,0,90*7
        dc.w    -5,0,75*7
        dc.w    5,0,75*7
        dc.w    -5,0,60*7
        dc.w    5,0,60*7
        dc.w    -5,0,45*7
        dc.w    5,0,45*7
        dc.w    -5,0,30*7
        dc.w    5,0,30*7
        dc.w    -5,0,15*7
        dc.w    5,0,15*7
        dc.w    -5,0,0
        dc.w    5,0,0
        dc.w    -5,0,-15*7
        dc.w    5,0,-15*7
        dc.w    -5,0,-30*7
        dc.w    5,0,-30*7
        dc.w    -5,0,-45*7
        dc.w    5,0,-45*7
        dc.w    -5,0,-60*7
        dc.w    5,0,-60*7
        dc.w    -5,0,-75*7
        dc.w    5,0,-75*7
        dc.w    -5,0,-90*7
        dc.w    5,0,-90*7
        dc.w    -5,0,-105*7
        dc.w    5,0,-105*7
        dc.w    -5,0,-120*7
        dc.w    5,0,-120*7
        dc.w    -5,0,-135*7
        dc.w    5,0,-135*7
        dc.w    -5,0,-150*7
        dc.w    5,0,-150*7

lightface:
	dc.w	20
	dc.w	3,0,1,3,2
	dc.w	3,2,3,5,4
	dc.w	3,4,5,7,6
	dc.w	3,6,7,9,8
	dc.w	3,8,9,11,10
	dc.w	3,10,11,13,12
	dc.w	3,12,13,15,14
	dc.w	3,14,15,17,16
	dc.w	3,16,17,19,18
	dc.w	3,18,19,21,20
	dc.w	3,20,21,23,22
	dc.w	3,22,23,25,24
	dc.w	3,24,25,27,26
	dc.w	3,26,27,29,28
	dc.w	3,28,29,31,30
	dc.w	3,30,31,33,32
	dc.w	3,32,33,35,34
	dc.w	3,34,35,37,36
	dc.w	3,36,37,39,38
	dc.w	3,38,39,41,40



carvpb:	blk.w	20,0
car:
	dc.l	lightsvpb
	dc.w	0,0,800		;overall object x,y,z
	dc.l	carvrt
	dc.l	carface
	dc.w	filled		;filled or line or dots
	dc.w	16		;number of dots
	dc.l	carcolors		;face color list
	dc.w	1		;1 is do hiden line removal
	dc.w	-1
	dc.w	1
	dc.w	120
	dc.w	0,0		;onscreenx,y

carcolors:
	dc.w	8,9,9,9,10,10,9,9,10,10,7,8,7,7,7,8,
	dc.w	10,10,8,9,8,8,8,9
	dc.w	11,11,9,9
	dc.w	1,1
	dc.w	4,4,5,5,6,6,14,14,15,15
	dc.w	4,4,5,5,6,6,14,14,15,15

carvrt:
	dc.w	42
	dc.w	20,06,-50	;car
	dc.w	-20,06,-50
	dc.w	-15,-09,-50
	dc.w	15,-09,-50
	dc.w	26,06,-25
	dc.w	-26,06,-25
	dc.w	-15,-16,-25
	dc.w	15,-16,-25
	dc.w	26,06,05
	dc.w	-26,06,05
	dc.w	-15,-16,05
	dc.w	15,-16,05
	dc.w	19,06,50
	dc.w	-19,06,50
	dc.w	-13,-02,60
	dc.w	13,-02,60

	dc.w	04,-06,44
	dc.w	04,-06,41
	dc.w	04,-07,37
	dc.w	05,-08,34
	dc.w	05,-09,31
	dc.w	05,-10,28
	dc.w	05,-11,25
	dc.w	06,-11,21
	dc.w	06,-12,18
	dc.w	06,-13,15
	dc.w	06,-14,12
	dc.w	-04,-06,44
	dc.w	-04,-06,41
	dc.w	-04,-07,37
	dc.w	-05,-08,34
	dc.w	-05,-09,31
	dc.w	-05,-10,28
	dc.w	-05,-11,25
	dc.w	-06,-11,21
	dc.w	-06,-12,18
	dc.w	-06,-13,15
	dc.w	-06,-14,12

	dc.w	10,-06,44
	dc.w	15,-14,12
	dc.w	-10,-06,44
	dc.w	-15,-14,12


	dc.w	-20,-50,-06
	dc.w	-15,-50,09
	dc.w	15,-50,09
	dc.w	26,-25,-06
	dc.w	-26,-25,-06
	dc.w	-15,-25,16
	dc.w	15,-25,16
	dc.w	26,05,-06
	dc.w	-26,05,-06
	dc.w	-15,05,16
	dc.w	15,05,16
	dc.w	19,50,-06
	dc.w	-19,50,-06
	dc.w	-13,60,02
	dc.w	13,60,02

	dc.w	04,44,06
	dc.w	04,41,06
	dc.w	04,37,07
	dc.w	05,34,08
	dc.w	05,31,09
	dc.w	05,28,10
	dc.w	05,25,11
	dc.w	06,21,11
	dc.w	06,18,12
	dc.w	06,15,13
	dc.w	06,12,14
	dc.w	-04,44,06
	dc.w	-04,41,06
	dc.w	-04,37,07
	dc.w	-05,34,08
	dc.w	-05,31,09
	dc.w	-05,28,10
	dc.w	-05,25,11
	dc.w	-06,21,11
	dc.w	-06,18,12
	dc.w	-06,15,13
	dc.w	-06,12,14

	dc.w	10,44,06
	dc.w	15,12,14
	dc.w	-10,44,06
	dc.w	-15,12,14

carface:
	dc.w	25
	dc.w	3,02,03,07,06
	dc.w	3,03,00,04,07
	dc.w	3,00,01,05,04
	dc.w	3,01,02,06,05
	dc.w	3,04,05,09,08
	dc.w	3,05,06,10,09
	dc.w	3,06,07,11,10
	dc.w	3,07,04,08,11
	dc.w	3,08,09,13,12
	dc.w	3,09,10,14,13
	dc.w	3,10,11,15,14
	dc.w	3,11,08,12,15
	dc.w	3,03,02,01,00		;end
	dc.w	3,12,13,14,15

	dc.w	3,39,38,40,41

	dc.w	3,16,27,28,17
	dc.w	3,17,28,29,18
	dc.w	3,18,29,30,19
	dc.w	3,19,30,31,20

	dc.w	3,20,31,32,21
	dc.w	3,21,32,33,22
	dc.w	3,22,33,34,23
	dc.w	3,23,34,35,24
	dc.w	3,24,35,36,25
	dc.w	3,25,36,37,26

carwire:
	dc.l	lightsvpb
	dc.w	0,0,800		;overall object x,y,z
	dc.l	carwvrt
	dc.l	carwface
	dc.w	line		;filled or line or dots
	dc.w	10		;number of dots
	dc.l	carcolors		;face color list
	dc.w	1		;1 is do hiden line removal
	dc.w	-1
	dc.w	1
	dc.w	120
	dc.w	0,0		;onscreenx,y


carwvrt:
	dc.w	16
	dc.w	15,-16,-19
	dc.w	15,-16,-1
	dc.w	23,-0,-19
	dc.w	23,-00,-01
	dc.w	-15,-16,-19
	dc.w	-15,-16,-01
	dc.w	-23,-00,-19
	dc.w	-23,-00,-01
	dc.w	11,-14,-30
	dc.w	11,-10,-44
	dc.w	-11,-14,-30
	dc.w	-11,-10,-44

	dc.w	10,-06,44
	dc.w	15,-14,12
	dc.w	-10,-06,44
	dc.w	-15,-14,12



carwface:
	dc.w	4
	dc.w	3,01,00,02,03
	dc.w	3,04,05,07,06
	dc.w	3,08,10,11,09
	dc.w	3,13,12,14,15

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
