
iera            equ $fffffa07           ;Interrupt-Enable-Register A
ierb            equ $fffffa09           ;                                                               B
imra            equ $fffffa13
isra            equ $fffffa0f
isrb            equ $fffffa11
tacr            equ $fffffa19
tbcr            equ $fffffa1b
tadr            equ $fffffa1f
tbdr            equ $fffffa21
tccr            equ $fffffa1d
tcdr            equ $fffffa23
aer             equ $fffffa03
STColor         equ $ffff8240
FColor          equ $ffff9800
vbl             equ $70
timer_int       equ $0120
timer_c_int     equ $0114

ym_select       equ $ffff8800
ym_write        equ $ffff8802
ym_read         equ $ffff8800


bw:		equ	120	;width of block data screen
blocky:		equ	119	;width of blocks

*slength:		equ	2854547
slength:		equ	600000
mscale:			equ	0

val200a:		equ	200
val670a:		equ	670
val15a: 		equ	16

sba:		equ	128
scon:		equ	1

* BLiTTER BASE ADDRESS

blitter         equ     $FF8A00

* BLiTTER REGISTER OFFSETS

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
vbl_vec:	equ	$70

vertflag:	equ	$0100
stmodes:	equ	$0080
overscan:	equ	$0040
pal:		equ	$0020
vga:		equ	$0010
tv:		equ	$0000

col80:		equ	$0008
col40:		equ	$0000
numcols:	equ	$0007

bps16:		equ	4
bps8:		equ	3
bps4:		equ	2
bps2:		equ	1
bps1:		equ	0
mybit:		equ	%0000001000000000


sw:	equ	320
sh:	equ	240

key_vec:	equ	$118
hbl_vec:	equ	$120
bpwidth:	equ	320
bpheight:	equ	200
i1 	EQU 0
i2 	EQU 0
i3 	EQU 15

xsin 	EQU 2
ycos 	EQU 4
ysin 	EQU 6
zcos 	EQU 8
zsin 	EQU 10
*****************************************************************
*	Falcon Slide Demo.					*
*	Version 1.0						*
*****************************************************************
	include	'fequates.s'
start:
	move.l	4(a7),a3		base page
	move.l	#mystack,a7
	move.l	$c(a3),d0		text len
	add.l	$14(a3),d0		data len
	add.l	$1c(a3),d0		BSS len
	add.l	#$100,d0		basepage
	move.l	d0,-(sp)
	move.l	a3,-(sp)
	clr.w	-(sp)
	move.w	#$4a,-(sp)
	trap	#1			shrink memory
	lea	12(sp),sp

	clr.l	-(sp)		;as usual the first thing to
	move.w	#$20,-(sp)	;do is go into supervisor mode
	trap	#1
	addq.l	#6,sp
	move.l	d0,savesp

	dc.w	$a00a
	jsr	putrout
	jsr	putvbl

	jsr	setupscreen
	jsr	doscreens

	jsr	Init_Music
	jsr	Init_Music_IT

	jsr	startofg


	lea	cylynder2,a0
	move.l	(a0),obpointlist
	move.l	4(a0),obfacelist
*	bsr	dointro
	move.w	#-1,lifetime
	move.l	#demlist,demaddress
mainloop:
	tst.w	doclear		;clear screen 3
	bmi.s	noclear
	bsr	clearscreen
noclear:
	bsr	dodem
	bsr	swapnshow
	jsr	keyboard
	bra	mainloop


	rsreset
objtlxyz:	rs.w	3
objbrxyz:	rs.w	3
objtlxy:	rs.w	2
objbrxy:	rs.w	2
objdata:	rs.l	1


object1:
	dc.w	-60,-60,0		;top left
	dc.w	60,60,0		;bottom right
	dc.w	200,100,261,161		;2d xy after perspective transform
	dc.l	balls			;address of graph data
object2:
	dc.w	-60,-60,0		;top left
	dc.w	60,60,0		;bottom right

	dc.w	200,100,261,161		;2d xy after perspective transform
	dc.l	balls+(121*bw*2)		;address of graph data
object3:
	dc.w	-60,-60,0		;top left
	dc.w	60,60,0		;bottom right
	dc.w	200,100,261,161		;2d xy after perspective transform
	dc.l	balls+(242*bw*2)		;address of graph data
object4:
	dc.w	-60,-60,0		;top left
	dc.w	60,60,0		;bottom right
	dc.w	200,100,261,161		;2d xy after perspective transform
	dc.l	balls+(362*bw*2)		;address of graph data

endedflag:	dc.w	-1
whatobj:	dc.l	0

dointro:
	move.w	#-1,endedflag
	move.l	#idemlist,demaddress
	move.w	#-1,lifetime
introloop:
	tst.w	doclear		;clear screen 3
	bmi.s	inoclear
	bsr	clearscreen
inoclear:
	bsr	introanim
	bsr	swapnshow
	jsr	keyboard
	tst.w	endedflag
	bmi	introloop
	move.w	#-1,lifetime
	move.l	#demlist,demaddress
	rts
idemlist:
	dc.l	object1
	dc.w	3910,150,235,110
	dc.l	object2
	dc.w	3910,150,255,110
	dc.l	object3
	dc.w	3910,150,260,110
	dc.l	object4
	dc.w	3910,150,260,110
	dc.l	-1

introanim:
	move.l	whatobj,a6
	subq.w	#1,lifetime
	bpl	istillalive
	move.l	demaddress,a0
	tst.l	(a0)
	bpl	inorestart
	move.w	#1,endedflag
	lea	idemlist,a0
inorestart:
	move.l	(a0)+,a6		;object
	move.l	a6,whatobj
	move.w	(a0)+,zdist		;initial distance
	move.w	zdist,zdist2
	move.w	(a0)+,zinc		;speed out and in screen
	move.w	(a0)+,zfinal		;close as it gets
	move.w	(a0)+,lifetime
	move.w	lifetime,d0
	asr.w	#2,d0			;/2
	move.w	d0,halflife
	move.l	a0,demaddress
istillalive:
	move.w	halflife,d0
	cmp.w	lifetime,d0
	bgt.s	izoomout
	move.w	zdist,d0
	cmp.w	zfinal,d0
	ble.s	iokh
	sub.w	#3,zinc
	sub.w	zinc,d0
	cmp.w	zfinal,d0
	bge.s	iisz
	move.w	zfinal,d0
iisz:
	move.w	d0,zdist
	bra.s	iokh
izoomout:
	move.w	zdist,d0
	add.w	#5,zinc
	add.w	zinc,d0
	move.w	d0,zdist
	cmp.w	zdist2,d0
	ble.s	iokh
	move.w	#-1,lifetime
iokh:
	move.w	d0,objtlxyz+4(a6)
	move.w	d0,objbrxyz+4(a6)
	bsr	calc3d
	move.l	a6,-(sp)
	bsr	expand
	move.l	(sp)+,a6
	rts
calc3d:
	moveq	#0,d0
	moveq	#0,d1
	moveq	#0,d2
	movem.w	objtlxyz(a6),d0-d2
	asl.w	#8,d0
	divs	d2,d0
	add	#(sw/2),d0	;centre it
	asl.w	#8,d1
	divs	d2,d1
	add.w	#110,d1	;centre it
	movem.w	d0-d1,objtlxy(a6)

	moveq	#0,d0
	moveq	#0,d1
	moveq	#0,d2
	movem.w	objbrxyz(a6),d0-d2
	asl.w	#8,d0
	divs	d2,d0
	add.w	#(sw/2),d0	;centre it
	asl.w	#8,d1
	divs	d2,d1
	add.w	#110,d1	;centre it
	movem.w	d0-d1,objbrxy(a6)
	rts

*********************************************************
*	Pass objects structure in a6			*
*							*
*********************************************************
expand:
	movem.w	objtlxy(a6),d0-d3
	sub.w	d0,d2
	ble	rover		;not big enough
	sub.w	d1,d3
	ble	rover
	ext.l	d0
	asl.l	#1,d0
	mulu	#sw*2,d1
	add.l	d0,d1
	move.l	viewscreen2,a5
	add.l	d1,a5			;screen ad to start at
	move.w	d3,d6			;save (d6 not used in dx1 or dx2)
	move.w	d2,d3
	lea	coordsx,a0
	bsr	dx1
	lea	coordsy,a0
	move.l	objdata(a6),d0
	move.w	d6,d3
	bsr	dx2

	lea	coordsy,a2
	lea	coordsx,a6
	move.l	a5,a0		;screen add
eloop1:
	move.l	a2,a3
	moveq	#0,d1
	move.w	(a6)+,d1
	bmi	eloop1over
	asl.w	#1,d1
	move.l	a0,a5
eloop2:
	move.l	(a3)+,d0
	bmi	eloop2over
	add.l	d1,d0
	move.l	d0,a1
	move.w	(a1),d2
	beq.s	nopixel
	move.w	d2,(a5)	;put pixel
nopixel:
	lea	sw*2(a5),a5
	bra	eloop2
eloop2over:
	addq.l	#2,a0
	bra	eloop1
eloop1over:
rover:
	rts

coordsx:	ds.w	400
coordsy:
		ds.l	400

*********************************************************
*	Routine to calculate stretchy stuff		*
*	Pass x width in d3				*
*	block address in d0
*	array to fill in a0				*
*********************************************************
dx2:
	moveq	#blocky,d2
	move.l	d0,d7
	move.w 	d3,d0		;dy
	moveq	#0,d5
lineloopdx2:
	move.l 	d7,(a0)+
	add.w 	d2,d5
testdx2:
	cmp.w 	d3,d5
	blt.s 	noacrossdx2
	sub.w 	d3,d5
	add.l 	#bw*2,d7
	bra.s 	testdx2
noacrossdx2:
	dbra 	d0,lineloopdx2
	move.l	#-1,(a0)+
nolinedx2:
	rts

*********************************************************
*	Routine to calculate stretchy stuff		*
*	Pass x width in d3				*
*	array to fill in a0				*
*********************************************************
dx1:
	moveq	#blocky,d2
	moveq 	#0,d7		;x1
	move.w 	d3,d0		;dy
	moveq	#0,d5
lineloopdx1:
	move.w 	d7,(a0)+
	add.w 	d2,d5
testdx1:
	cmp.w 	d3,d5
	blt.s 	noacrossdx1
	sub.w 	d3,d5
	addq.w 	#1,d7
	bra.s 	testdx1
noacrossdx1:
	dbra 	d0,lineloopdx1
	move.w	#-1,(a0)+
nolinedx1:
	rts

lifetime:	dc.w	-1
halflife:	dc.w	0
demaddress:	dc.l	0
zdist:		dc.w	20000
zdist2:		dc.w	20000
zinc:		dc.w	0
zfinal:		dc.w	0
**********************************************************
*	address,initial dist,zincr,zfinal,lifetime

demlist:
	dc.l	spyramid
	dc.w	30000,400,5000,250
	dc.l	pyramid
	dc.w	28000,400,3500,250
	dc.l	cube1
	dc.w	28000,400,3500,250
	dc.l	cylynder1
	dc.w	28000,400,3500,250
	dc.l	sball
	dc.w	28000,400,3500,250
	dc.l	cone1
	dc.w	28000,400,3500,250
	dc.l	pyramid2
	dc.w	28000,600,5000,250
	dc.l	cylynder3
	dc.w	28000,400,5500,250
	dc.l	ball1
	dc.w	28000,400,3500,250
	dc.l	cylynder2
	dc.w	28000,400,3500,250
	dc.l	ball2
	dc.w	28000,400,3500,250
	dc.l	-1

dodem:
	subq.w	#1,lifetime
	bpl	stillalive
	move.l	demaddress,a0
	tst.l	(a0)
	bpl	norestart
	bsr	dointro
	lea	demlist,a0
norestart:
	move.l	(a0)+,a1		;object
	move.l	(a1),obpointlist
	move.l	4(a1),obfacelist
	move.w	(a0)+,zdist		;initial distance
	move.w	zdist,zdist2
	move.w	(a0)+,zinc		;speed out and in screen
	move.w	(a0)+,zfinal		;close as it gets
	move.w	(a0)+,lifetime
	move.w	lifetime,d0
	asr.w	#2,d0			;/2
	move.w	d0,halflife
	move.l	a0,demaddress
stillalive:
	move.w	halflife,d0
	cmp.w	lifetime,d0
	bgt.s	zoomout
	move.w	zdist,d0
	cmp.w	zfinal,d0
	ble.s	okh
	sub.w	zinc,d0
	cmp.w	zfinal,d0
	bge.s	isz
	move.w	zfinal,d0
isz:
	move.w	d0,zdist
	bra.s	okh
zoomout:
	move.w	zdist,d0
	add.w	zinc,d0
	move.w	d0,zdist
	cmp.w	zdist2,d0
	ble.s	okh
	move.w	#-1,lifetime
okh:
	bsr	 lop
	rts

workx:	equ	70
worky:	equ	55
workw:	equ	320-(workx*2)
workh:	equ	110

clearscreen:
	rts

	lea	blitter,a6
.waitblit:
	btst	#7,line_num(a6)
	bne	.waitblit

	move.l	savescreen2,a0
	add.l	#worky*(sw*2)+workx*2,a0
	move.l	a0,src_addr(a6)


	move.l	viewscreen2,a0
	add.l	#worky*(sw*2)+workx*2,a0
	move.l	a0,dst_addr(a6)

	move.w	#2,src_xinc(a6)
	move.w	#2,dst_xinc(a6)
	move.w	#((sw*2)-(workw*2))+2,src_yinc(a6)
	move.w	#((sw*2)-(workw*2))+2,dst_yinc(a6)

	move.w	#workw,x_count(a6)
	move.w	#workh,y_count(a6)
	move.w	#-1,endmask1(a6)
	move.w	#-1,endmask2(a6)
	move.w	#-1,endmask3(a6)
	move.b	#0,skew(a6)
	move.b	#$3,op(a6)
	move.b	#2,hop(a6)
	bset	#6,line_num(a6)
	bset	#7,line_num(a6)
	rts

swapnshow:
	move.l	viewscreen1,d0
	move.l	viewscreen2,viewscreen1
	move.l	d0,viewscreen2
waitvbl:
	move.w	#1,vblflag
wvbloop:
	tst.w	vblflag
	bpl	wvbloop

	move.l	viewscreen1,d0
	move.l	d0,d1
	move.l	d1,d2
	lsr.l	#8,d0
	lsr.l	#8,d0
	move.w	d0,vid_bh
	lsr.l	#8,d1
	and.l	#$000000ff,d1
	move.w	d1,vid_bm
	and.l	#$000000ff,d2
	move.w	d2,vid_bl
	rts

startofg:
	move.l #brights,botpt
	move.l #brights,toppt
	move.l #brights+38,midpt
	bsr	clearlefts
	rts

clearlefts:
	lea	lefts,a6
	moveq	#0,d0
	move.w	#240,d1
.loop:
	move.l	d0,(a6)+
	dbf	d1,.loop
	rts

lop:
	move.w	#2048,d7
	lea 	svals,a1
	lea	sin,a0
	move.w 	xspos,d0
	move.w 	(a0,d0),xsin(a1)
	lea	(a0,d7.w),a0
	move.w 	(a0,d0),(a1)

	move.l 	#sin,a0
	move.w 	yspos,d0
	move.w 	(a0,d0),ysin(a1)
	lea	(a0,d7.w),a0
	move.w 	(a0,d0),ycos(a1)

	move.l 	#sin,a0
	move.w 	zspos,d0
	move.w 	(a0,d0),zsin(a1)
	lea	(a0,d7.w),a0
	move.w 	(a0,d0),zcos(a1)
rotaters:
	add.w 	#104,xspos
	add.w 	#50,yspos
	add.w 	#50,zspos
*	move.w	my,xspos
*	move.w	mx,yspos
	and.w 	#$1fff,xspos
	and.w 	#$1fff,yspos
	and.w 	#$1fff,zspos

	move.l	obpointlist,a0
	lea 	pts,a1
	lea 	svals,a2
	lea 	zvals,a3
	move.w 	(a0)+,d7
threetwo:			;this loop does the 3D calcs
	movem.w	(a0)+,d0-d2

	move.w 	d0,d3
	muls 	ycos(a2),d3
	move.w 	d2,d4
	muls 	ysin(a2),d4
	sub.l 	d4,d3
	add.l 	d3,d3
	swap 	d3
	move.w 	d0,d4
	move.w 	d3,d0
	move.w 	d2,d3
	muls 	ycos(a2),d3
	muls 	ysin(a2),d4
	add.l 	d3,d4
	add.l 	d4,d4
	swap 	d4
	move.w 	d4,d2

	move.w 	d1,d3
	muls 	(a2),d3
	move.w 	d2,d4
	muls 	xsin(a2),d4
	sub.l 	d4,d3
	add.l 	d3,d3
	swap 	d3
	move.w 	d1,d4
	move.w 	d3,d1
	move.w 	d2,d3
	muls 	(a2),d3
	muls 	xsin(a2),d4
	add.l 	d3,d4
	add.l 	d4,d4
	swap 	d4
	move.w 	d4,d2

	move.w 	d0,d3
	muls 	zcos(a2),d3
	move.w 	d1,d4
	muls 	zsin(a2),d4
	sub.l 	d4,d3
	add.l 	d3,d3
	swap 	d3
	move.w 	d0,d4
	move.w 	d3,d0
	move.w 	d1,d3
	muls 	zcos(a2),d3
	muls 	zsin(a2),d4
	add.l 	d3,d4
	add.l 	d4,d4
	swap 	d4
	move.w 	d4,d1

	ext.l 	d0
	ext.l 	d1
	move.w 	d2,(a3)+
	add.w 	zdist,d2		;z dist
	asl.l 	#8,d0
	asl.l 	#8,d1
	divs 	d2,d0
	divs 	d2,d1
	add.w 	#160,d0		;centre the points on screen
	add.w 	#110,d1
	move.w 	d0,(a1)+
	move.w 	d1,(a1)+
	dbra 	d7,threetwo

	move.l	obfacelist,a0
	move.w 	(a0)+,d7
	lea 	pts,a1
	lea 	zvals,a2
polyloop:
	move.l	(a0)+,facecolor
	movem.w	(a0)+,d0-d2
	asl.w	#1,d0
	asl.w	#1,d1
	asl.w	#1,d2

	move.w 	(a2,d0.w),z1
	move.w 	(a2,d1.w),z2
	move.w 	(a2,d2.w),z3

	add.w 	d0,d0
	add.w 	d1,d1
	add.w 	d2,d2
	move.l 	(a1,d0.w),x1
	move.l 	(a1,d1.w),x2
	move.l 	(a1,d2.w),x3
	bsr 	gouraud
	bsr	clearlefts
	dbra 	d7,polyloop
	rts
sball:
	dc.l	sballp
	dc.l	sballf
sballp:
	dc.w	41
	dc.w	0,0,-500
	dc.w	-362,-263,-224
	dc.w	137,-425,-224
	dc.w	447,0,-224
	dc.w	137,425,-224
	dc.w	-362,263,-224
	dc.w	-138,-425,223
	dc.w	361,-263,223
	dc.w	361,263,223
	dc.w	-138,425,223
	dc.w	-447,0,223
	dc.w	0,0,500
	dc.w	-213,-155,-425
	dc.w	81,-250,-425
	dc.w	263,0,-425
	dc.w	81,249,-425
	dc.w	-213,154,-425
	dc.w	-425,0,-263
	dc.w	-131,-405,-263
	dc.w	344,-250,-263
	dc.w	344,249,-263
	dc.w	-131,404,-263
	dc.w	-476,-155,0
	dc.w	-294,-405,0
	dc.w	0,-500,0
	dc.w	293,-405,0
	dc.w	475,-155,0
	dc.w	475,154,0
	dc.w	293,404,0
	dc.w	0,500,0
	dc.w	-294,404,0
	dc.w	-476,154,0
	dc.w	-344,-250,263
	dc.w	131,-405,263
	dc.w	425,0,263
	dc.w	131,404,263
	dc.w	-344,249,263
	dc.w	-81,-250,425
	dc.w	212,-155,425
	dc.w	212,154,425
	dc.w	-81,249,425
	dc.w	-263,0,425

sballf:
	dc.w	79
	dc.l	purples		;no mans
	dc.w	40,36,9
	dc.l	purples		;1
	dc.w	40,41,36
	dc.l	purples		;1
	dc.w	36,41,10
	dc.l	purples		;1
	dc.w	41,40,11
	dc.l	blues		;1
	dc.w	39,35,8
	dc.l	blues		;1
	dc.w	39,40,35
	dc.l	blues		;1
	dc.w	35,40,9
	dc.l	blues		;nomans  rrrrrr
	dc.w	40,39,11
	dc.l	greens		;1
	dc.w	38,34,7
	dc.l	greens		;1
	dc.w	38,39,34
	dc.l	greens		;no mans
	dc.w	34,39,8
	dc.l	greens		;1
	dc.w	39,38,11
	dc.l	reds		;top penta
	dc.w	37,33,6
	dc.l	greens		;1
	dc.w	37,38,33
	dc.l	greens		;1
	dc.w	33,38,7
	dc.l	greens		;1
	dc.w	38,37,11
	dc.l	purples		;1
	dc.w	41,32,10
	dc.l	purples		;1
	dc.w	41,37,32
	dc.l	reds		;top penta
	dc.w	32,37,6
	dc.l	purples		;1
	dc.w	37,41,11
	dc.l	yellows		;2
	dc.w	31,5,30
	dc.l	yellows		;2
	dc.w	31,30,36
	dc.l	yellows		;2
	dc.w	30,9,36
	dc.l	yellows		;nomans
	dc.w	36,10,31
	dc.l	reds		;bottom penta
	dc.w	29,4,28
	dc.l	blues		;1
	dc.w	29,28,35
	dc.l	blues		;1
	dc.w	28,8,35
	dc.l	blues		;1
	dc.w	35,9,29
	dc.l	cyans		;2
	dc.w	27,3,26
	dc.l	cyans		;2
	dc.w	27,26,34
	dc.l	cyans		;nomans
	dc.w	26,7,34
	dc.l	cyans		;2
	dc.w	34,8,27
	dc.l	yellows		;1
	dc.w	25,2,24
	dc.l	yellows		;1
	dc.w	25,24,33
	dc.l	reds		;top penta
	dc.w	24,6,33
	dc.l	yellows		;1
	dc.w	33,7,25
	dc.l	cyans		;1
	dc.w	23,1,22
	dc.l	cyans		;1
	dc.w	23,22,32
	dc.l	cyans		;1
	dc.w	22,10,32
	dc.l	reds		;top penta
	dc.w	32,6,23
	dc.l	reds		;bottom penta
	dc.w	29,21,4
	dc.l	yellows		;2
	dc.w	29,30,21
	dc.l	yellows		;2
	dc.w	21,30,5
	dc.l	yellows		;2
	dc.w	30,29,9
	dc.l	cyans		;2
	dc.w	27,20,3
	dc.l	cyans		;2
	dc.w	27,28,20
	dc.l	reds		;bot penta
	dc.w	20,28,4
	dc.l	cyans		;2
	dc.w	28,27,8
	dc.l	yellows		;1
	dc.w	25,19,2
	dc.l	yellows		;1
	dc.w	25,26,19
	dc.l	yellows		;nomans
	dc.w	19,26,3
	dc.l	yellows		;1
	dc.w	26,25,7
	dc.l	blues		;2
	dc.w	23,18,1
	dc.l	blues		;2
	dc.w	23,24,18
	dc.l	blues		;2
	dc.w	18,24,2
	dc.l	reds		;top penta
	dc.w	24,23,6
	dc.l	cyans		;nomans
	dc.w	31,17,5
	dc.l	cyans		;1
	dc.w	31,22,17
	dc.l	cyans		;1
	dc.w	17,22,1
	dc.l	cyans		;1
	dc.w	22,31,10
	dc.l	greens		;3
	dc.w	16,0,15
	dc.l	greens		;3
	dc.w	16,15,21
	dc.l	reds		;bot penta
	dc.w	15,4,21
	dc.l	greens		;3
	dc.w	21,5,16
	dc.l	purples		;2
	dc.w	15,0,14
	dc.l	purples		;2
	dc.w	15,14,20
	dc.l	purples		;2
	dc.w	14,3,20
	dc.l	reds		;bot penta
	dc.w	20,4,15
	dc.l	purples		;2
	dc.w	14,0,13
	dc.l	purples		;2
	dc.w	14,13,19
	dc.l	purples		;nomams
	dc.w	13,2,19
	dc.l	purples		;2
	dc.w	19,3,14
	dc.l	greens		;3
	dc.w	16,12,0
	dc.l	greens		;3
	dc.w	16,17,12
	dc.l	greens		;nomans
	dc.w	12,17,1
	dc.l	greens		;3
	dc.w	17,16,5
	dc.l	blues		;nomans
	dc.w	13,0,12
	dc.l	blues		;2
	dc.w	13,12,18
	dc.l	blues		;2
	dc.w	12,1,18
	dc.l	blues		;2
	dc.w	18,2,13


cylynder1:
	dc.l	cylynder		;plain cylynder
	dc.l	cylynderfaces
cylynder2:
	dc.l	cylynder		;striped
	dc.l	cylynderfaces2
cylynder3:
	dc.l	cylynder		;striped
	dc.l	cylynderfaces3


cylynder:
	dc.w	19
	dc.w	293,-500,404
	dc.w	475,-500,154
	dc.w	475,-500,-154
	dc.w	293,-500,-404
	dc.w	000,-500,-500
	dc.w	-293,-500,-404
	dc.w	-475,-500,-154
	dc.w	-475,-500,154
	dc.w	-293,-500,404
	dc.w	000,-500,500
	dc.w	293,500,404
	dc.w	475,500,154
	dc.w	475,500,-154
	dc.w	293,500,-404
	dc.w	000,500,-500
	dc.w	-293,500,-404
	dc.w	-475,500,-154
	dc.w	-475,500,154
	dc.w	-293,500,404
	dc.w	000,500,500

cylynderfaces:
	dc.w	35
	dc.l	blues
	dc.w	11,01,00
	dc.l	blues
	dc.w	10,11,00
	dc.l	blues
	dc.w	12,02,01
	dc.l	blues
	dc.w	11,12,01
	dc.l	blues
	dc.w	13,03,02
	dc.l	blues
	dc.w	12,13,02
	dc.l	blues
	dc.w	14,04,03
	dc.l	blues
	dc.w	13,14,03
	dc.l	blues
	dc.w	15,05,04
	dc.l	blues
	dc.w	14,15,04
	dc.l	blues
	dc.w	16,06,05
	dc.l	blues
	dc.w	15,16,05
	dc.l	blues
	dc.w	17,07,06
	dc.l	blues
	dc.w	16,17,06
	dc.l	blues
	dc.w	18,08,07
	dc.l	blues
	dc.w	17,18,07
	dc.l	blues
	dc.w	19,09,08
	dc.l	blues
	dc.w	18,19,08
	dc.l	blues
	dc.w	10,00,09
	dc.l	blues
	dc.w	19,10,09
	dc.l	blues
	dc.w	00,01,02
	dc.l	blues
	dc.w	12,11,10
	dc.l	blues
	dc.w	00,02,03
	dc.l	blues
	dc.w	13,12,10
	dc.l	blues
	dc.w	00,03,04
	dc.l	blues
	dc.w	14,13,10
	dc.l	blues
	dc.w	00,04,05
	dc.l	blues
	dc.w	15,14,10
	dc.l	blues
	dc.w	00,05,06
	dc.l	blues
	dc.w	16,15,10
	dc.l	blues
	dc.w	00,06,07
	dc.l	blues
	dc.w	17,16,10
	dc.l	blues
	dc.w	00,07,08
	dc.l	blues
	dc.w	18,17,10
	dc.l	blues
	dc.w	00,08,09
	dc.l	blues
	dc.w	19,18,10


cylynderfaces3:
	dc.w	35
	dc.l	shinyyellows
	dc.w	11,01,00
	dc.l	shinyyellows
	dc.w	10,11,00
	dc.l	shinyyellows
	dc.w	12,02,01
	dc.l	shinyyellows
	dc.w	11,12,01
	dc.l	shinyyellows
	dc.w	13,03,02
	dc.l	shinyyellows
	dc.w	12,13,02
	dc.l	shinyyellows
	dc.w	14,04,03
	dc.l	shinyyellows
	dc.w	13,14,03
	dc.l	shinyyellows
	dc.w	15,05,04
	dc.l	shinyyellows
	dc.w	14,15,04
	dc.l	shinyyellows
	dc.w	16,06,05
	dc.l	shinyyellows
	dc.w	15,16,05
	dc.l	shinyyellows
	dc.w	17,07,06
	dc.l	shinyyellows
	dc.w	16,17,06
	dc.l	shinyyellows
	dc.w	18,08,07
	dc.l	shinyyellows
	dc.w	17,18,07
	dc.l	shinyyellows
	dc.w	19,09,08
	dc.l	shinyyellows
	dc.w	18,19,08
	dc.l	shinyyellows
	dc.w	10,00,09
	dc.l	shinyyellows
	dc.w	19,10,09
	dc.l	shinyyellows
	dc.w	00,01,02
	dc.l	shinyyellows
	dc.w	12,11,10
	dc.l	shinyyellows
	dc.w	00,02,03
	dc.l	shinyyellows
	dc.w	13,12,10
	dc.l	shinyyellows
	dc.w	00,03,04
	dc.l	shinyyellows
	dc.w	14,13,10
	dc.l	shinyyellows
	dc.w	00,04,05
	dc.l	shinyyellows
	dc.w	15,14,10
	dc.l	shinyyellows
	dc.w	00,05,06
	dc.l	shinyyellows
	dc.w	16,15,10
	dc.l	shinyyellows
	dc.w	00,06,07
	dc.l	shinyyellows
	dc.w	17,16,10
	dc.l	shinyyellows
	dc.w	00,07,08
	dc.l	shinyyellows
	dc.w	18,17,10
	dc.l	shinyyellows
	dc.w	00,08,09
	dc.l	shinyyellows
	dc.w	19,18,10

cylynderfaces2:
	dc.w	35
	dc.l	blues
	dc.w	11,01,00
	dc.l	blues
	dc.w	10,11,00
	dc.l	purples
	dc.w	12,02,01
	dc.l	purples
	dc.w	11,12,01
	dc.l	blues
	dc.w	13,03,02
	dc.l	blues
	dc.w	12,13,02
	dc.l	purples
	dc.w	14,04,03
	dc.l	purples
	dc.w	13,14,03
	dc.l	blues
	dc.w	15,05,04
	dc.l	blues
	dc.w	14,15,04
	dc.l	purples
	dc.w	16,06,05
	dc.l	purples
	dc.w	15,16,05
	dc.l	blues
	dc.w	17,07,06
	dc.l	blues
	dc.w	16,17,06
	dc.l	purples
	dc.w	18,08,07
	dc.l	purples
	dc.w	17,18,07
	dc.l	blues
	dc.w	19,09,08
	dc.l	blues
	dc.w	18,19,08
	dc.l	purples
	dc.w	10,00,09
	dc.l	purples
	dc.w	19,10,09
	dc.l	blues
	dc.w	00,01,02
	dc.l	blues
	dc.w	12,11,10
	dc.l	blues
	dc.w	00,02,03
	dc.l	blues
	dc.w	13,12,10
	dc.l	blues
	dc.w	00,03,04
	dc.l	blues
	dc.w	14,13,10
	dc.l	blues
	dc.w	00,04,05
	dc.l	blues
	dc.w	15,14,10
	dc.l	blues
	dc.w	00,05,06
	dc.l	blues
	dc.w	16,15,10
	dc.l	blues
	dc.w	00,06,07
	dc.l	blues
	dc.w	17,16,10
	dc.l	blues
	dc.w	00,07,08
	dc.l	blues
	dc.w	18,17,10
	dc.l	blues
	dc.w	00,08,09
	dc.l	blues
	dc.w	19,18,10
cone1:
	dc.l	cone
	dc.l	conefaces
cone:
	dc.w	11
	dc.w	000,000,-500
	dc.w	000,000,500
	dc.w	500,000,-500
	dc.w	404,293,-500
	dc.w	154,475,-500
	dc.w	-154,475,-500
	dc.w	-404,293,-500
	dc.w	-500,000,-500
	dc.w	-404,-293,-500
	dc.w	-154,-475,-500
	dc.w	154,-475,-500
	dc.w	404,-293,-500

conefaces:
	dc.w	19
	dc.l	yellows
	dc.w	03,02,01
	dc.l	yellows
	dc.w	03,00,02
	dc.l	yellows
	dc.w	04,03,01
	dc.l	yellows
	dc.w	04,00,03
	dc.l	yellows
	dc.w	05,04,01
	dc.l	yellows
	dc.w	05,00,04
	dc.l	yellows
	dc.w	06,05,01
	dc.l	yellows
	dc.w	06,00,05
	dc.l	yellows
	dc.w	07,06,01
	dc.l	yellows
	dc.w	07,00,06
	dc.l	yellows
	dc.w	08,07,01
	dc.l	yellows
	dc.w	08,00,07
	dc.l	yellows
	dc.w	09,08,01
	dc.l	yellows
	dc.w	09,00,08
	dc.l	yellows
	dc.w	10,09,01
	dc.l	yellows
	dc.w	10,00,09
	dc.l	yellows
	dc.w	11,10,01
	dc.l	yellows
	dc.w	11,00,10
	dc.l	yellows
	dc.w	02,11,01
	dc.l	yellows
	dc.w	02,00,11

ball1:
	dc.l	ball
	dc.l	ballfaces	;plain ball
ball2:
	dc.l	ball
	dc.l	ballfaces2	;checked

ball:
	dc.w	25
	dc.w	353,000,353
	dc.w	500,000,000
	dc.w	353,000,-353
	dc.w	000,000,-500
	dc.w	000,000,500
	dc.w	249,249,353
	dc.w	353,353,000
	dc.w	249,249,-353
	dc.w	000,353,353
	dc.w	000,500,000
	dc.w	000,353,-353
	dc.w	-249,249,353
	dc.w	-353,353,000
	dc.w	-249,249,-353
	dc.w	-353,000,353
	dc.w	-500,000,000
	dc.w	-353,000,-353
	dc.w	-249,-249,353
	dc.w	-353,-353,000
	dc.w	-249,-249,-353
	dc.w	000,-353,353
	dc.w	000,-500,000
	dc.w	000,-353,-353
	dc.w	249,-249,353
	dc.w	353,-353,000
	dc.w	249,-249,-353
ballfaces:
	dc.w	47
	dc.l	reds
	dc.w	06,01,00
	dc.l	reds
	dc.w	05,06,00
	dc.l	reds
	dc.w	07,02,01
	dc.l	reds
	dc.w	06,07,01
	dc.l	reds
	dc.w	07,03,02
	dc.l	reds
	dc.w	05,00,04
	dc.l	reds
	dc.w	09,06,05
	dc.l	reds
	dc.w	08,09,05
	dc.l	reds
	dc.w	10,07,06
	dc.l	reds
	dc.w	09,10,06
	dc.l	reds
	dc.w	10,03,07
	dc.l	reds
	dc.w	08,05,04
	dc.l	reds
	dc.w	12,09,08
	dc.l	reds
	dc.w	11,12,08
	dc.l	reds
	dc.w	13,10,09
	dc.l	reds
	dc.w	12,13,09
	dc.l	reds
	dc.w	13,03,10
	dc.l	reds
	dc.w	11,08,04
	dc.l	reds
	dc.w	15,12,11
	dc.l	reds
	dc.w	14,15,11
	dc.l	reds
	dc.w	16,13,12
	dc.l	reds
	dc.w	15,16,12
	dc.l	reds
	dc.w	16,03,13
	dc.l	reds
	dc.w	14,11,04
	dc.l	reds
	dc.w	18,15,14
	dc.l	reds
	dc.w	17,18,14
	dc.l	reds
	dc.w	19,16,15
	dc.l	reds
	dc.w	18,19,15
	dc.l	reds
	dc.w	19,03,16
	dc.l	reds
	dc.w	17,14,04
	dc.l	reds
	dc.w	21,18,17
	dc.l	reds
	dc.w	20,21,17
	dc.l	reds
	dc.w	22,19,18
	dc.l	reds
	dc.w	21,22,18
	dc.l	reds
	dc.w	22,03,19
	dc.l	reds
	dc.w	20,17,04
	dc.l	reds
	dc.w	24,21,20
	dc.l	reds
	dc.w	23,24,20
	dc.l	reds
	dc.w	25,22,21
	dc.l	reds
	dc.w	24,25,21
	dc.l	reds
	dc.w	25,03,22
	dc.l	reds
	dc.w	23,20,04
	dc.l	reds
	dc.w	01,24,23
	dc.l	reds
	dc.w	00,01,23
	dc.l	reds
	dc.w	02,25,24
	dc.l	reds
	dc.w	01,02,24
	dc.l	reds
	dc.w	02,03,25
	dc.l	reds
	dc.w	00,23,04
ballfaces2:
	dc.w	47
	dc.l	greys
	dc.w	06,01,00
	dc.l	greys
	dc.w	05,06,00
	dc.l	reds
	dc.w	07,02,01
	dc.l	reds
	dc.w	06,07,01
	dc.l	greys
	dc.w	07,03,02
	dc.l	reds
	dc.w	05,00,04
	dc.l	reds
	dc.w	09,06,05
	dc.l	reds
	dc.w	08,09,05
	dc.l	greys
	dc.w	10,07,06
	dc.l	greys
	dc.w	09,10,06
	dc.l	reds
	dc.w	10,03,07
	dc.l	greys
	dc.w	08,05,04
	dc.l	greys
	dc.w	12,09,08
	dc.l	greys
	dc.w	11,12,08
	dc.l	reds
	dc.w	13,10,09
	dc.l	reds
	dc.w	12,13,09
	dc.l	greys
	dc.w	13,03,10
	dc.l	reds
	dc.w	11,08,04
	dc.l	reds
	dc.w	15,12,11
	dc.l	reds
	dc.w	14,15,11
	dc.l	greys
	dc.w	16,13,12
	dc.l	greys
	dc.w	15,16,12
	dc.l	reds
	dc.w	16,03,13
	dc.l	greys
	dc.w	14,11,04
	dc.l	greys
	dc.w	18,15,14
	dc.l	greys
	dc.w	17,18,14
	dc.l	reds
	dc.w	19,16,15
	dc.l	reds
	dc.w	18,19,15
	dc.l	greys
	dc.w	19,03,16
	dc.l	reds
	dc.w	17,14,04
	dc.l	reds
	dc.w	21,18,17
	dc.l	reds
	dc.w	20,21,17
	dc.l	greys
	dc.w	22,19,18
	dc.l	greys
	dc.w	21,22,18
	dc.l	reds
	dc.w	22,03,19
	dc.l	greys
	dc.w	20,17,04
	dc.l	greys
	dc.w	24,21,20
	dc.l	greys
	dc.w	23,24,20
	dc.l	reds
	dc.w	25,22,21
	dc.l	reds
	dc.w	24,25,21
	dc.l	greys
	dc.w	25,03,22
	dc.l	reds
	dc.w	23,20,04
	dc.l	reds
	dc.w	01,24,23
	dc.l	reds
	dc.w	00,01,23
	dc.l	greys
	dc.w	02,25,24
	dc.l	greys
	dc.w	01,02,24
	dc.l	reds
	dc.w	02,03,25
	dc.l	greys
	dc.w	00,23,04
cube1:
	dc.l	cube
	dc.l	cubefaces
cube2:
	dc.l	cube
	dc.l	cubefaces2

cube:
	dc.w	7
	dc.w	400,-400,400
	dc.w	400,-400,-400
	dc.w	-400,-400,-400
	dc.w	-400,-400,400
	dc.w	400,400,400
	dc.w	400,400,-400
	dc.w	-400,400,-400
	dc.w	-400,400,400
cubefaces:
	dc.w	11
	dc.l	cyans
	dc.w	1,3,0
	dc.l	cyans
	dc.w	2,3,1
	dc.l	cyans
	dc.w	7,5,4
	dc.l	cyans
	dc.w	7,6,5
	dc.l	cyans
	dc.w	4,5,0
	dc.l	cyans
	dc.w	5,1,0
	dc.l	cyans
	dc.w	2,1,5
	dc.l	cyans
	dc.w	5,6,2
	dc.l	cyans
	dc.w	6,3,2
	dc.l	cyans
	dc.w	3,6,7
	dc.l	cyans
	dc.w	7,4,3
	dc.l	cyans
	dc.w	4,0,3

cubefaces2:
	dc.w	11
	dc.l	mono2
	dc.w	1,3,0
	dc.l	mono2
	dc.w	2,3,1
	dc.l	mono2
	dc.w	7,5,4
	dc.l	mono2
	dc.w	7,6,5
	dc.l	mono1
	dc.w	4,5,0
	dc.l	mono1
	dc.w	5,1,0
	dc.l	mono3
	dc.w	2,1,5
	dc.l	mono3
	dc.w	5,6,2
	dc.l	mono1
	dc.w	6,3,2
	dc.l	mono1
	dc.w	3,6,7
	dc.l	mono3
	dc.w	7,4,3
	dc.l	mono3
	dc.w	4,0,3

spyramid:
	dc.l	simplepyramid
	dc.l	simplepyramidfaces
simplepyramid:
	dc.w	3
*	dc.w	0,-500,-500
*	dc.w	500,-500,500
*	dc.w	-500,-500,500
*	dc.w	0,500,0

	dc.w	942,0,-333
	dc.w	-471,816,-333
	dc.w	-471,-816,-333
	dc.w	0,0,1000
	

simplepyramidfaces:
	dc.w	3
	dc.l	purples
	dc.w	0,1,2
	dc.l	purples
	dc.w	0,3,1
	dc.l	purples
	dc.w	2,1,3
	dc.l	purples
	dc.w	2,3,0
pyramid:
	dc.l	pyramidp
	dc.l	pfaces
pyramid2:
	dc.l	pyramidp
	dc.l	pfaces2
pfaces:
	dc.w	15
	dc.l	greens
	dc.w	0,1,8
	dc.l	greens
	dc.w	0,2,1
	dc.l	greens
	dc.w	0,3,2
	dc.l	greens
	dc.w	0,4,3
	dc.l	greens
	dc.w	0,5,4
	dc.l	greens
	dc.w	0,6,5
	dc.l	greens
	dc.w	0,7,6
	dc.l	greens
	dc.w	0,8,7
	dc.l	greens
	dc.w	9,1,2
	dc.l	greens
	dc.w	9,2,3
	dc.l	greens
	dc.w	9,3,4
	dc.l	greens
	dc.w	9,4,5
	dc.l	greens
	dc.w	9,5,6
	dc.l	greens
	dc.w	9,6,7
	dc.l	greens
	dc.w	9,7,8
	dc.l	greens
	dc.w	9,8,1
pfaces2:
	dc.w	15
	dc.l	shinyred
	dc.w	0,1,8
	dc.l	shinyred
	dc.w	0,2,1
	dc.l	shinyred
	dc.w	0,3,2
	dc.l	shinyred
	dc.w	0,4,3
	dc.l	shinyred
	dc.w	0,5,4
	dc.l	shinyred
	dc.w	0,6,5
	dc.l	shinyred
	dc.w	0,7,6
	dc.l	shinyred
	dc.w	0,8,7
	dc.l	shinyred
	dc.w	9,1,2
	dc.l	shinyred
	dc.w	9,2,3
	dc.l	shinyred
	dc.w	9,3,4
	dc.l	shinyred
	dc.w	9,4,5
	dc.l	shinyred
	dc.w	9,5,6
	dc.l	shinyred
	dc.w	9,6,7
	dc.l	shinyred
	dc.w	9,7,8
	dc.l	shinyred
	dc.w	9,8,1

pyramidp:
	dc.w 	9
	dc.w 	0,0,600
	dc.w 	0,-600,0
	dc.w 	420,-420,0
	dc.w 	600,0,0
	dc.w 	420,420,0
	dc.w 	0,600,0
	dc.w 	-420,420,0
	dc.w 	-600,0,0
	dc.w 	-420,-420,0
	dc.w 	0,0,-600

gouraud:
	movem.l	d0-d7/a0-a6,-(a7)
	move.w	z1,d0
	neg.w	d0
	add.w	#val200a,d0
	ext.l	d0
	asl.l 	#4,d0
	divs 	#val670a,d0
	bge.s 	large1
	moveq 	#0,d0
large1:
	cmp.w 	#val15a,d0
	ble.s 	small1
	move.w 	#val15a,d0
small1:
	move.w 	d0,topbright
	move.w 	z2,d0
	neg.w 	d0
	add.w 	#val200a,d0
	ext.l 	d0
	asl.l 	#4,d0
	divs 	#val670a,d0
	bge.s 	large2
	moveq 	#0,d0
large2:
	cmp.w 	#val15a,d0
	ble.s 	small2
	move.w 	#val15a,d0
small2:
	move.w 	d0,midbright
	move.w 	z3,d0
	neg.w 	d0
	add.w 	#val200a,d0
	ext.l 	d0
	asl.l 	#4,d0
	divs 	#val670a,d0
	bge.s 	large3
	moveq 	#0,d0
large3:
	cmp.w 	#val15a,d0
	ble.s 	small3
	move.w 	#val15a,d0
small3:
	move.w 	d0,botbright
	move.w 	x2,d0
	sub.w 	x1,d0
	move.w 	y3,d1
	sub.w 	y1,d1
	muls 	d1,d0

	move.w 	x3,d1
	sub.w 	x1,d1
	move.w 	y2,d2
	sub.w 	y1,d2
	muls 	d2,d1
	sub.l 	d1,d0
	move.l 	d0,d1
	sub.l 	#5,d0		;25
	ble 	nopoly

	move.l 	x1,d0
	move.l 	x2,d1
	cmp.w 	d0,d1
	bge.s 	noswap1
	move.l 	d0,x2
	move.l 	d1,x1

	move.w 	topbright,d0
	move.w 	midbright,topbright
	move.w 	d0,midbright
noswap1:
	move.l 	x2,d0
	move.l 	x3,d1
	cmp.w 	d0,d1
	bge.s 	noswap2
	move.l 	d0,x3
	move.l 	d1,x2
	move.w 	midbright,d0
	move.w 	botbright,midbright
	move.w 	d0,botbright
noswap2:
	move.l 	x1,d0
	move.l 	x2,d1
	cmp.w 	d0,d1
	bge.s 	noswap3
	move.l 	d0,x2
	move.l 	d1,x1
	move.w 	topbright,d0
	move.w 	midbright,topbright
	move.w 	d0,midbright
noswap3:
	move.w 	botbright,d0
	sub.w 	topbright,d0
	move.w 	d0,difftopbot

	move.w 	midbright,d0
	sub.w 	topbright,d0
	move.w 	d0,difftopmid

	move.w 	y3,d0
	sub.w 	y1,d0
	move.w 	d0,topbot
	move.w 	y2,d0
	sub.w 	y1,d0
	move.w 	d0,topmid
	move.w 	y3,d0
	sub.w 	y2,d0
	move.w 	d0,midbot

	move.w 	y1,d0
	move.w 	x1,d1
	move.w 	y3,cm1
	sub.w 	d0,cm1
	move.w 	x3,cm2
	sub.w 	d1,cm2
	move.w 	x2,cm3
	sub.w 	d1,cm3
	move.w 	y2,cm4
	sub.w 	d0,cm4
	move.w 	cm1,d1
	muls 	cm3,d1
	move.w 	cm2,d2
	muls 	cm4,d2
	sub.l 	d2,d1
	beq 	nopoly
	move.w 	d1,cm5
bpnow:
	move.w 	x1,d0
	move.w 	y1,d1
	move.w 	x2,d2
	move.w 	y2,d3
	move.w 	#0,d7
	bsr 	linedraw

	move.w 	x2,d0
	move.w 	y2,d1
	move.w 	x3,d2
	move.w 	y3,d3
	move.w 	#0,d7
	bsr 	linedraw

	move.w 	x1,d0
	move.w 	y1,d1
	move.w 	x3,d2
	move.w 	y3,d3
	move.w 	#0,d7
	bsr 	linedraw
bp2:
	lea 	lefts,a0
	move.w 	y1,d0
	move.w 	y3,d7
	sub.w 	d0,d7		;height of poly??
	add.w 	d0,d0
	adda.w 	d0,a0
	adda.w 	d0,a0		;a0 points to start of left right
	move.l 	viewscreen2,a4		;screen address
	muls 	#320,d0		;already mult by 2 up a bit, makes *640
	add.l 	d0,a4

	move.w 	midbright,d0
	muls 	topbot,d0
	asl.l 	#8,d0
	divs 	cm5,d0
	move.w 	d0,cm6

	move.w 	botbright,d0
	muls 	topmid,d0
	neg.l 	d0
	asl.l 	#8,d0
	divs 	cm5,d0
	add.w 	d0,cm6

	move.w 	topbright,d0
	muls 	midbot,d0
	neg.l 	d0
	asl.l 	#8,d0
	divs 	cm5,d0
	add.w 	d0,cm6

	moveq 	#0,d2	; y-y1
	move.l	facecolor,a1
	move.l	clipbot2,a5
	move.l	cliptop2,a6
plotem:
	movem.w	(a0)+,d0-d1
	sub.w 	d0,d1
	beq 	noplot
	lea	(a4,d0),a3	;a3 is screen add of line start
	asr.w 	#1,d1
	asr.w 	#1,d0
	sub.w 	x1,d0
	move.w 	cm1,d3
	muls 	d0,d3
	move.w 	cm2,d4
	muls 	d2,d4
	sub.l 	d4,d3
	asl.l 	#8,d3
	divs 	cm5,d3		; a

	move.w 	cm3,d4
	muls 	d2,d4
	move.w 	cm4,d5
	muls 	d0,d5
	sub.l 	d5,d4
	asl.l 	#8,d4
	divs 	cm5,d4		; b

	move.w 	topbright,d0
	ext.l 	d0
	asl.l 	#8,d0
	muls 	difftopmid,d3
	add.l 	d3,d0
	muls 	difftopbot,d4
	add.l 	d4,d0		; initial brightness
	move.w 	cm6,d6
	ext.l 	d6
	move.w 	d0,d5		;D0 IS COLOR (BRIGHTNESS)
	asr.w	#7,d5
	cmpi.w	#31,d5
	ble.s	.ok1
	moveq	#31,d5
	bra.s	.ok2
.ok1:
	tst.w	d5
	bge.s	.ok2
	moveq	#0,d5
.ok2:
	move.w	d5,d3
	asl.w	#1,d3
	asl.w 	#7,d5		;8
	sub.w 	d5,d0		; how far through first colour
	sub.w 	#sba,d0
	moveq 	#32,d5
	tst.w 	d6
	bge.s 	okok
	neg.w 	d0
	sub.w 	#sba,d0
	neg.w 	d6
	neg.w 	d5
okok:
	asr.w	#4,d5
	move.w	(a1,d3.w),d4
drawpoints:
	move.w	d4,(a3)+
np2:	add.w 	d6,d0
backone:
	ble.s 	nonext
	add.w 	d5,d3
	bge	.ok1
	moveq	#0,d3
	moveq	#0,d5
.ok1:
	cmp.w	#62,d3
	ble.s	.ok2
	move.w	#62,d3
	moveq	#0,d5
.ok2:
	move.w	(a1,d3.w),d4
	sub.w 	#sba,d0
	bra.s 	backone
nonext:
	dbra 	d1,drawpoints
noplot:
	lea	sw*2(a4),a4
np:	addq.w 	#1,d2
	dbra 	d7,plotem
nopoly:
	movem.l (a7)+,d0-d7/a0-a6
	rts

mono1:
	rept	32
*	      bitrrrrrggggggbbbbb
	dc.w	%1100011000011000
	endr
mono2:
	rept	32
*	      bitrrrrrggggggbbbbb
	dc.w	%0111001110001110
	endr
mono3:
	rept	32
*	      bitrrrrrggggggbbbbb
	dc.w	%0011000110000110
	endr
blues:
r	set	0
g	set	0
b	set	0
	rept	32
	dc.w	r|g|b
*		bitrrrrrggggggbbbbb
r	set	r+%0000000000000000
g	set	g+%0000000000000000
b	set	b+%0000000000000001
	endr


shinyred:
r	set	0
g	set	0
b	set	0
	rept	20
	dc.w	r|g|b
*		bitrrrrrggggggbbbbb
r	set	r+%0000100000000000
g	set	g+%0000000000000000
b	set	b+%0000000000000000
	endr
	rept	11
	dc.w	r|g|b
*		bitrrrrrggggggbbbbb
r	set	r+%0000100000000000
g	set	g+%0000000010100000
b	set	b+%0000000000000011
	endr
	dc.w	-1	
shinyyellows:
r	set	0
g	set	0
b	set	0
	rept	20
	dc.w	r|g|b
*		bitrrrrrggggggbbbbb
r	set	r+%0000100000000000
g	set	g+%0000000001000000
b	set	b+%0000000000000000
	endr
	rept	11
	dc.w	r|g|b
*		bitrrrrrggggggbbbbb
r	set	r+%0000100000000000
g	set	g+%0000000001000000
b	set	b+%0000000000000011
	endr
	dc.w	-1	

purples:
r	set	0
g	set	0
b	set	0
	rept	32
	dc.w	r|g|b
*		bitrrrrrggggggbbbbb
r	set	r+%0000100000000000
g	set	g+%0000000000000000
b	set	b+%0000000000000001
	endr
cyans:
r	set	0
g	set	0
b	set	0
	rept	32
	dc.w	r|g|b
*		bitrrrrrggggggbbbbb
r	set	r+%0000000001000000
g	set	g+%0000000000000000
b	set	b+%0000000000000001
	endr
 
yellows:				;yellow
r	set	0
g	set	0
b	set	0
	rept	32
	dc.w	r|g|b
*		bitrrrrrggggggbbbbb
r	set	r+%0000100000000000
g	set	g+%0000000001000000
b	set	b+%0000000000000000
	endr
greens:				;green
r	set	0
g	set	0
b	set	0
	rept	32
	dc.w	r|g|b
*		bitrrrrrggggggbbbbb
r	set	r+%0000000000000000
g	set	g+%0000000001000000
b	set	b+%0000000000000000
	endr
reds:				;red
r	set	0
g	set	0
b	set	0
	rept	32
	dc.w	r|g|b
*		bitrrrrrggggggbbbbb
r	set	r+%0000100000000000
g	set	g+%0000000000000000
b	set	b+%0000000000000000
	endr
greys:				;grey
r	set	0
g	set	0
b	set	0
	rept	32
	dc.w	r|g|b
*		bitrrrrrggggggbbbbb
r	set	r+%0000100000000000
g	set	g+%0000000001000000
b	set	b+%0000000000000001
	endr


leftpt:
	dc.l	0
rightpt:
	dc.l	0
oldleft:
	dc.l 	0
oldright:
	dc.l 	0
cm1:
	dc.w 	0
cm2:
	dc.w 	0
cm3:
	dc.w 	0
cm4:
	dc.w 	0
cm5:
	dc.w 	0
cm6:
	dc.w 	0

x1: 	dc.w 	160
y1: 	dc.w 	60
x2: 	dc.w 	230
y2: 	dc.w 	110
x3: 	dc.w 	100
y3: 	dc.w 	160

z1: 	dc.w 	0
z2: 	dc.w 	0
z3: 	dc.w 	0

zvals:
	ds.l 	1600


linedraw:
	moveq 	#0,d7
	cmp.w 	d1,d3
	beq.s 	noline
	bge.s 	okdown
	exg 	d1,d3
	exg 	d0,d2
okdown:
	moveq 	#2,d6
	sub.w 	d1,d3		; dy

	sub.w 	d0,d2		; dx
	bge.s 	okright
	neg.w 	d2
	neg.w 	d6
okright:
	asl.w	#2,d1
	lea 	lefts,a0
	adda.w 	d1,a0
	move.w 	d0,d7		;x1
	add.w 	d7,d7		;x1*2
	move.w 	d3,d0		;dy
	moveq	#0,d1
	moveq	#0,d4
	moveq	#0,d5
lineloop:
	cmp.w 	2(a0),d7
	bgt.s 	onright
	blt.s 	onleft
			; still undecided
	move.w 	d7,(a0)+
	move.w 	d7,(a0)+
	add.w 	d2,d5
test:
	cmp.w 	d3,d5
	blt.s 	noacross
	sub.w 	d3,d5
	add.w 	d6,d7
	bra.s 	test
noacross:
	dbra 	d0,lineloop
noline:
	rts

onright:
	move.w 	2(a0),(a0)+
	move.w 	d7,(a0)+
	add.w 	d2,d5
test2:
	cmp.w 	d3,d5
	blt.s 	noacross2
	sub.w 	d3,d5
	add.w 	d6,d7
	bra.s 	test2
noacross2:
	dbra 	d0,onright
	rts

onleft:
	move.w 	d7,(a0)+
	addq.w 	#2,a0
	add.w 	d2,d5
test3:
	cmp.w 	d3,d5
	blt.s 	noacross3
	sub.w 	d3,d5
	add.w 	d6,d7
	bra.s 	test3
noacross3:
	dbra 	d0,onleft
	rts

xoff:
 	dc.w 	0
yoff:
 	dc.w 	0

lefts:	ds.w 	256
rights:	ds.w 	256
lefts2:	ds.w 	256
rights2:	ds.w 	256

showpt:	dc.l	0
clrpt:	dc.l	0
zpos: 	dc.w	0
scypos:	dc.w	0
xpos:	ds.w	320
saveinters:	dc.w	0
which:	dc.w	0
pts:	ds.l	16
leftbits:
rightbits:
dummy:	ds.w	512
botbright:	dc.w	15
midbright:	dc.w	8
topbright:	dc.w	0
difftopbot:	dc.w	0
difftopmid:	dc.w	0
brights:
val SET 0
 REPT 16
 dc.w val,val,val
val SET val+1
 ENDR 

val SET 15
 REPT 16
 dc.w val,val
val SET val-1
 ENDR 

endbr
toppt:	dc.l	0
botpt:	dc.l	0
midpt:	dc.l	0
topbot:	dc.w	0
topmid:	dc.w	0
midbot:	dc.w	0
sin:
	incbin "bigsine"
xspos:	dc.w	0
yspos:	dc.w	0
zspos:	dc.w	0
svals:
;xcos
	dc.w	0
;xsin
	dc.w	0 
;ycos
	dc.w	0
;ysin
	dc.w	0
;zcos
	dc.w	0
;zsin
	dc.w	0

keyboard:
	move.w	#$ff,-(sp)
	move.w	#$6,-(sp)
	trap	#1
	addq.l	#4,sp
	tst.l	d0
	beq	keyback
	swap	d0
	cmp.b	#16,d0		*space
	beq	exit		*yes/no
	cmpi.b	#$39,d0
	beq	pause
ckey:
	cmpi.b	#$2e,d0
	bne	keyback
	neg.w	doclear
keyback:
	rts
doclear:	dc.w	1
pause:
	move.w	#7,-(sp)
	trap	#1
	addq.l	#2,sp
	rts

buttondat:	dc.w	0
mx:		dc.w	200
my:		dc.w	100
*************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
mousehasgoneup:	dc.w	0

**************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	#1,mousehasgoneup
	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
*	asl.w	#mscale,d1
*	asl.w	#mscale,d0
	add.w	d0,mx
	add.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	extra1
        move.w	#mminx,d0
        bra	extra2
extra1: cmpi.w   #mmaxx,d0
        ble	extra2
        move.w  #mmaxx,d0
extra2:	cmpi.w  #mminy,d1
        bge	extra3
        move.w  #mminy,d1
        bra	extra4
extra3: cmpi.w   #mmaxy,d1
        ble	extra4
        move.w  #mmaxy,d1
extra4:
        rts

mminx:	equ	0
*mmaxx:	equ	2048*4
mmaxx:	equ	300
mminy:	equ	0
*mmaxy:	equ	2048*4
mmaxy:	equ	240


putvbl:
	move.l	vbl_vec,vblt+2		;set up vbl handler
	move.l	vbl_vec,oldvblvec
	move.l	#vbl_handler,vbl_vec
	rts

halfframe:	dc.w	0
ddl:		dc.w	-1
vbl_handler:
	move.w	#-1,vblflag
vblt:
	jmp	$0.L

exit:

	jsr	Stop_Music_IT
	jsr	Stop_Music

	move.w  #34,-(sp)
        trap    #14
        addq.l  #2,sp
        move.l  d0,a0
	move.l	oldmouse,16(a0)

	lea	memlist,a6
demem:
	move.l	(a6)+,d0
	bmi	nomoremem
	beq	demem
	bsr	deallocate
	bra	demem
nomoremem:
	move.l	oldvblvec,vbl_vec

	ifne	scon
	move.w	savemode,-(sp)
	move.w	#3,-(sp)
	move.l	savescreen,-(sp)
	move.l	savescreen,-(sp)
	move.w	#5,-(sp)
	trap	#14
	add.l	#14,sp
	endc

	move.l	savesp,-(sp)
	move.w	#$20,-(sp)
	trap	#1
	addq.l	#6,sp

	clr.w	-(sp)
	trap	#1

deallocate:
	move.l	d0,-(sp)
	move.w	#$49,-(sp)
	trap	#1
	addq.l	#6,sp
	rts

*********************************************************
*	One call does it all				*
*	Allocates memory for 3 screens 			*
*	targa load/hold area is internal.		*
*	Then sets all the hardware stuff to create	*
*	a 384*480 16bit screen				*
*********************************************************
setupscreen:
	move.l	#((sw*2)*sh)+4+((sw*2)*100),-(sp)	;thats 1 screen size
	move.w	#$48,-(sp)
	trap	#1
	addq.l	#6,sp
	tst.l	d0
	bmi	exit
	move.l	d0,savemem1
	add.l	#4,d0
	and.l	#$fffffffc,d0
	move.l	d0,viewscreen1
	move.l	d0,a0

	move.l	#((sw*2)*sh)+4+((sw*2)*100),-(sp)	;thats 1 screen size
	move.w	#$48,-(sp)
	trap	#1
	addq.l	#6,sp
	tst.l	d0
	bmi	exit
	move.l	d0,savemem2
	add.l	#4,d0
	and.l	#$fffffffc,d0
	move.l	d0,viewscreen2

	ifne	scon

	move.w	#2,-(sp)
	trap	#14
	addq.l	#2,sp
	move.l	d0,savescreen


	move.w	#-1,-(sp)
	move.w	#88,-(sp)
	trap	#14
	addq.l	#4,sp
	move.w	d0,savemode

	move.w	#vertflag|vga|col40|bps16,-(sp)
	move.w	#3,-(sp)
	move.l	#-1,-(sp)
	move.l	#-1,-(sp)
	move.w	#5,-(sp)
	trap	#14
	add.l	#14,sp

*	move.l	#0,$ffff9800

	endc

	move.w	#2,-(sp)
	trap	#14
	addq.l	#2,sp
	move.l	d0,savescreen2

	rts



*********************************************************
*	copy whole screen with blitter			*
*	set screen to copy to in a1			*
*********************************************************
copywhole:
	move.l	savescreen2,a0
*	move.l	viewscreen,a1
	lea	blitter,a6
.waitblit:
	btst	#7,line_num(a6)
	bne	.waitblit

	move.l	a0,src_addr(a6)
	move.l	a1,dst_addr(a6)
	move.w	#2,src_xinc(a6)
	move.w	#2,dst_xinc(a6)
	move.w	#2,src_yinc(a6)
	move.w	#2,dst_yinc(a6)
	move.w	#sw,x_count(a6)
	move.w	#sh,y_count(a6)
	move.w	#-1,endmask1(a6)
	move.w	#-1,endmask2(a6)
	move.w	#-1,endmask3(a6)
	move.b	#0,skew(a6)
	move.b	#$3,op(a6)
	move.b	#2,hop(a6)
	bset	#6,line_num(a6)
	bset	#7,line_num(a6)
	rts


doscreens:
	lea	scrnback,a0
	move.l	savescreen2,a1
	jsr	ice_unpack
	move.l	viewscreen1,a1
	bsr	copywhole
	move.l	viewscreen2,a1
	bsr	copywhole
	rts

;********************************************* Unpackroutine von ICE-PACK
; assemble with Devpac or any other Assembler
; length of this unpacking routine: 294 bytes
;  a0 = address of packed data
;  a1 = address of unpacked data
ice_unpack:
	movem.l d0-a6,-(sp)
	bsr	ice04
	cmpi.l	#'Ice!',d0		; Is file packed?
	bne	ice03			; no, leave this routine
	bsr	ice04
	lea	-8(a0,d0.l),a5
	bsr	ice04
*	move.l	d0,(sp)
	movea.l a1,a4
	movea.l a1,a6
	adda.l	d0,a6
	movea.l a6,a3
	move.b	-(a5),d7
	bsr	ice06
ice03:
	movem.l (sp)+,d0-a6
	rts
ice04:	moveq	#3,d1
ice05:	lsl.l	#8,d0
	move.b	(a0)+,d0
	dbra	d1,ice05
	rts
ice06:	bsr	ice0a
	bcc	ice09
	moveq	#0,d1
	bsr	ice0a
	bcc	ice08
	lea	ice17(pc),a1
	moveq	#4,d3
ice07:	move.l	-(a1),d0
	bsr	ice0c
	swap	d0
	cmp.w	d0,d1
	dbne	d3,ice07
	add.l	20(a1),d1
ice08:	move.b	-(a5),-(a6)
	dbra	d1,ice08
ice09:	cmpa.l	a4,a6
	bgt	ice0f
	rts
ice0a:	add.b	d7,d7
	bne	ice0b
	move.b	-(a5),d7
	addx.b	d7,d7
ice0b:	rts
ice0c:	moveq	#0,d1
ice0d:	add.b	d7,d7
	bne	ice0e
	move.b	-(a5),d7
	addx.b	d7,d7
ice0e:	addx.w	d1,d1
	dbra	d0,ice0d
	rts
ice0f:	lea	ice18(pc),a1
	moveq	#3,d2
ice10:	bsr	ice0a
	dbcc	d2,ice10
	moveq	#0,d4
	moveq	#0,d1
	move.b	1(a1,d2.w),d0
	ext.w	d0
	bmi	ice11
	bsr	ice0c
ice11:	move.b	6(a1,d2.w),d4
	add.w	d1,d4
	beq	ice13
	lea	ice19(pc),a1
	moveq	#1,d2
ice12:	bsr	ice0a
	dbcc	d2,ice12
	moveq	#0,d1
	move.b	1(a1,d2.w),d0
	ext.w	d0
	bsr	ice0c
	add.w	d2,d2
	add.w	6(a1,d2.w),d1
	bpl	ice15
	sub.w	d4,d1
	bra	ice15
ice13:	moveq	#0,d1
	moveq	#5,d0
	moveq	#-1,d2
	bsr	ice0a
	bcc	ice14
	moveq	#8,d0
	moveq	#$3f,d2
ice14:	bsr	ice0c
	add.w	d2,d1
ice15:	lea	2(a6,d4.w),a1
	adda.w	d1,a1
	move.b	-(a1),-(a6)
ice16:	move.b	-(a1),-(a6)
	dbra	d4,ice16
	bra	ice06

	DC.B $7f,$ff,$00,$0e,$00,$ff,$00,$07
	DC.B $00,$07,$00,$02,$00,$03,$00,$01
	DC.B $00,$03,$00,$01
ice17:	DC.B $00,$00,$01,$0d,$00,$00,$00,$0e
	DC.B $00,$00,$00,$07,$00,$00,$00,$04
	DC.B $00,$00,$00,$01
ice18:	DC.B $09,$01,$00,$ff,$ff,$08,$04,$02
	DC.B $01,$00
ice19:	DC.B $0b,$04,$07,$00,$01,$1f,$ff,$ff
	DC.B $00,$1f
	even



		Include	'TRACKER.S'

	section	data
Module	IncBin	'URA.MOD'		; LAST OF THE DATA SECTION
	even
viewscreen2:	dc.l	-1
viewscreen1:	dc.l	-1
memlist:
savemem1:	dc.l	0
savemem2:	dc.l	0
savemem3:	dc.l	0
savemem4:	dc.l	0
savemem5:	dc.l	0
		dc.l	-1	;end of mem list flag

soundmem:	dc.l	0
howlong:	dc.l	0
handles:	dc.w	0
	even
	section data
scrnback:	incbin	'road.img'
balls:		incbin	'test.img'

	SECTION BSS
		ds.l	1000
mystack:	ds.w	1	;stacks go backwards
		section bss
		even
SaveArea:       ds.b 6
ime		ds.l	16

svft:	ds.w	1
svss:	ds.w	1
svbb:	ds.w	1
svbe:	ds.w	1
svdb:	ds.w	1
svde:	ds.w	1
shht:	ds.w	1
shss:	ds.w	1
shbb:	ds.w	1
shbe:	ds.w	1
shdb:	ds.w	1
shde:	ds.w	1
shfs:	ds.w	1
shee	ds.w	1
sst_shift:	ds.w	1
ssp_shift:	ds.w	1
svco:	ds.w	1
svwrap:	ds.w	1
svid_bh:	ds.w	1
svid_bm:	ds.w	1
svid_bl:	ds.w	1
savepal:	ds.w	16

color:		ds.w	1
pixelx:		ds.w	1
pixely:		ds.w	1
savesp:		ds.l	1
time:		ds.l	1
frames:		ds.l	1
blitx:		ds.l	1
blity:		ds.l	1
picsource:	ds.l	1
expansion:	ds.w	1
oldmouse:	ds.l	1
whichpic:	ds.l	1
frame:		ds.l	1
whicheffect:	ds.l	1
oldvblvec:	ds.l	1
vblflag:	ds.w	1
savescreen:	ds.l	1
savescreen2:	ds.l	1
savemode:	ds.w	1
save114:	ds.l	1
mastervol:	ds.w	1
obpointlist:	ds.l	1
obfacelist:	ds.l	1
facecolor:	ds.l	1
clipbot1:	ds.l	1
clipbot2:	ds.l	1
clipbot3:	ds.l	1
cliptop1:	ds.l	1
cliptop2:	ds.l	1
cliptop3:	ds.l	1
bufferword:	ds.w	1
