	opt	o+
ctime:		equ	0
cthetainc:	equ	2
cphiinc:	equ	4
crhoinc:	equ	6
cxinc:		equ	8
cyinc:		equ	10
czinc:		equ	12
NumStars	equ	100
bpwidth:	equ	320
bpheight:	equ	200
*	sound stuff	*
soundstarth:	equ	2
soundstartm:	equ	4
soundstartl:	equ	6
soundendh:	equ	$e
soundendm:	equ	$10
soundendl:	equ	$12
soundmode:	equ	$20
sounddma:	equ	0

cspritex:	equ	0
cspritey:	equ	2
cspriteheight:	equ	8
cspritewidth:	equ	10
cspritead:	equ	4
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
tacr:	equ	$fffa19
tbdr:	equ	$fffa21
tadr:	equ	$fffa1f
vbl_vec:	equ	$70
key_vec:	equ	$118
hbl_vec:	equ	$120
speed:		equ	350
zclip:		equ	0
start:
	move.l	a7,stacksave
	move.l	4(a7),a3      ;basepage
	move.l	$C(a3),d0     ;text length
	add.l 	$14(a3),d0    ;data length
	add.l 	$1C(a3),d0    ;BSS length
	add.l 	#500,d0     ;any additional memory
	add.l 	#$100,d0      ;basepage length
*	move.l	#mystack,a7   ;before shrinking
	move.l	d0,-(a7)
	move.l	a3,-(a7)
	clr.w 	-(a7)
	move.w	#$4a,-(a7)
	trap	#1		;do the shrink
	lea	12(sp),sp     



	clr.l   -(SP)           ;Go into supervisor mode
        move.w  #$20,-(SP)
        trap    #1
        addq.l  #6,SP
        move.l  D0,savesup

	move.l	$426,rvsave
	move.l	$42a,resave
	move.w	#4,-(sp)
	trap	#14
	addq.l	#2,sp
	move.w	d0,ressave

	jsr	getscrn
	move.w	#0,-(sp)	;set to low res
	move.l	seen,-(sp)
	move.l	seen,-(sp)
	move.w	#5,-(sp)
	trap	#14
	add.l	#12,sp
	lea	palsave,a0
	move.l	#$ff8240,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)+

setupkey:
	move.w	#1,-(sp)
	move.w	#14,-(sp)
	trap	#14
	addq.l	#4,sp
	move.l	d0,keybuf

	jsr	loadsound
	jsr	setsound
	jsr	load
	lea	bluepalette,a0
	jsr	mydocolors
	jsr	putrout
	jsr	clearboth
	jsr	plotinit
	jsr	setuphbl1
	move.l	#4,SVELOCITY
	move.l	#BPWIDTH/2,CENTREX
	move.l	#BPHEIGHT/2,CENTREY
	move.l	#$00200020,HSPREAD
	move.l	#STARSm,SRCPTR
	bsr	setupstars
	move.l	#mil,whichob
	move.w	commands,time		;set first time
	move.l	#commands,command
	move.w	#64,unitheta
	move.w	#192,uniphi
	move.w	#0,unirho
	move.w	#0,unix
	move.w	#64,uniy
	move.w	#-100,uniz

loop1:
	jsr	keyboard
	jsr	stars
	bsr	tester
	tst.w	d0
	bmi	nextbit
	jsr	flip_scr2
	bra	loop1

nextbit:
	bsr	setuphbl3
	move.w	#$000f,$ff8240+8*2
	move.l	#2,SVELOCITY
	move.w	#800,d7
loopn:
	move.w	d7,-(sp)
	addq.l	#2,srotx
	addq.l	#2,srotz
	jsr	keyboard
*	jsr	stars
	jsr	flip_scr3
	move.w	(sp)+,d7
	dbf	d7,loopn

	move.b	oldieb,ieb
	move.b	oldiea,iea
	move.b	oldima,ima
	move.l	oldhblvec2,hbl_vec
	lea	bluepalette,a0
	jsr	mydocolors

	move.w	#0,unix
	move.w	#0,uniy
	move.w	#0,uniz
	jsr	setuphbl2
	move.l	#monitor,whichob
	move.l	#movie,pointer
	move.w	#-1,firstrun
testloop:
	jsr	keyboard
	jsr	testdraw
	tst.w	dont
	bmi.s	skd2
	jsr	domovie
skd2:
	jsr	flip_scr2
	tst.w	firstrun
	bmi	testloop
	move.l	#playmovie5,whichroutine
	move.w	#150,moviechange
	move.w	#-1,lifetime
loop2:
	jsr	keyboard
	jsr	domovie
	jsr	testdraw
*	move.w	#0,numwhere
*	move.l	clear,d0
*	move.w	d0,number
*	bsr	prtnum
	jsr	flip_scr2
	subq.w	#1,moviechange
	bge.s	loop2
	lea	mlist,a0
	move.w	mplace,d0
	move.w	d0,d1
	move.l	(a0,d0.w),d0
	move.l	4(a0,d1.w),clear
	addq.w	#8,mplace
	cmp.w	#64,mplace
	ble	mok
	move.w	#0,mplace
mok:
	move.w	#150,moviechange
	move.l	d0,whichroutine
	bra	loop2
mlist:	dc.l	playmovie,-1,expandhalf,-1,expandall,1
	dc.l	playmovie2,-1,playmovie3,-1
	dc.l	playmovie4,-1,playmovie5,1,playmovie6,1,playmovie7,1
moviechange:	dc.w	0
mplace:		dc.w	0
	
frames:		dc.w	0
frames2:	dc.w	0
pointer:	dc.l	0
mtimer:		dc.l	0
d7emulator:	dc.w	0
flip:		dc.w	0
flip2:		dc.w	0

******************************************
*	sound stuff	*
*soundstarth:	equ	2
*soundstartm:	equ	4
*soundstartl:	equ	6
*soundendh:	equ	$e
*soundendm:	equ	$10
*soundendl:	equ	$12
*soundmode:	equ	$20
*sounddma:	equ	0

setsound:
	move.w	#$7ff,$ff8924
settreb:
	cmpi.w	#$7ff,$ff8924
	bne	settreb
	move.w	#%0000010010001100,d0		;010 for treb vol
	move.w	d0,$ff8922			;send data

setbass:
	cmpi.w	#$7ff,$ff8924
	bne	setbass
	move.w	#%0000010001001100,d0		;010 for treb vol
	move.w	d0,$ff8922			;send data
setvol:
	cmpi.w	#$7ff,$ff8924
	bne	setvol
	move.w	#%0000010011101000,d0		;010 for treb vol
	move.w	d0,$ff8922			;send data

	move.l	soundstart,d0
	move.l	soundend,d1
dosound:
	lea	$ff8900,a0	;sound register base address
	move.w	#0,sounddma(a0)
	move.w	d0,soundstartl(a0)
	lsr.l	#8,d0
	move.w	d0,soundstartm(a0)
	lsr.l	#8,d0
	move.w	d0,soundstarth(a0)
	move.w	d1,soundendl(a0)
	lsr.l	#8,d1
	move.w	d1,soundendm(a0)
	lsr.l	#8,d1
	move.w	d1,soundendh(a0)
	move.w	#%0000000010000001,soundmode(a0)
	move.w	#%0000000000000011,sounddma(a0)
dsback:
	rts





time:		dc.w	0
command:	dc.l	0
commands:	
		dc.w	100,0,0,0,0,0,0
		dc.w	180,0,0,0,0,0,20
		dc.w	128,0,-1,0,0,-1,0
		dc.w	90,0,0,0,0,0,-40
		dc.w	128,0,-1,0,0,1,0
		dc.w	40,0,0,0,0,0,30
		dc.w	128,0,-2,0,0,0,0
		dc.w	50,0,0,0,0,0,0
		dc.w	60,0,0,0,0,0,120,-1

****************************************
tester:
	move.l	whichob,a5
	move.l	obviewpb(a5),a0
	move.l	command,a1
	subq.w	#1,time
	bpl	acont
	add.l	#14,command
	move.l	command,a1
	move.w	ctime(a1),time
	bmi	aover
acont:
	move.w	cthetainc(a1),d0
	add.w	d0,unitheta
	move.w	cphiinc(a1),d0
	add.w	d0,uniphi
	move.w	crhoinc(a1),d0
	add.w	d0,unirho
	move.w	cxinc(a1),d0
	add.w	d0,unix
	move.w	cyinc(a1),d0
	add.w	d0,uniy
	move.w	czinc(a1),d0
	add.w	d0,uniz
	bsr	dobefore

	move.w	unitheta,d0
	and.w	#%0000000011111111,d0
	move.w	d0,unitheta
	move.w	uniphi,d0
	and.w	#%0000000011111111,d0
	move.w	d0,uniphi
	move.w	unirho,d0
	and.w	#%0000000011111111,d0
	move.w	d0,unirho


	moveq	#0,d0
	move.w	#255,d0
	sub.w	unitheta,d0
	add.w	#64,d0
	mulu	#282,d0
	divu	#100,d0
	bclr	#0,d0
	and.l	#$0000ffff,d0
	move.l	d0,srotx
	moveq	#0,d0
	move.w	uniphi,d0
	add.w	#64,d0
	mulu	#282,d0
	divu	#100,d0
	bclr	#0,d0
	and.l	#$0000ffff,d0
	move.l	d0,srotz
	moveq	#1,d0
	rts
aover:
	moveq	#-1,d0
	rts


*************************************************

setupstars:
	lea	starsm,a0
	move	#numstars,d7
	subq	#1,d7
supl:
	move.w	#2500,d0
	jsr	random
	swap	d0
	clr.w	d0
	swap	d0
	ext.l	d0
	move.l	d0,(a0)+
	move.w	#2500,d0
	jsr	random
	swap	d0
	clr.w	d0
	swap	d0
	ext.l	d0
	move.l	d0,(a0)+
	move.w	#2500,d0
	jsr	random
	swap	d0
	clr.w	d0
	swap	d0
	ext.l	d0
	move.l	d0,(a0)+
	dbf	d7,supl
	rts




***************************************
STARS:
*		move.l	#4,SVELOCITY
*		move.l	#BPWIDTH/2,CENTREX
*		move.l	#BPHEIGHT/2,CENTREY
;		move.l	#$FFFFFFC4,SROTX
;		move.l	#150,SROTY
;		move.l	#0,SROTZ
*		move.l	#$00200020,HSPREAD
*		move.l	#STARS1,SRCPTR
*
*		tst.w	$28c8
*		beq.s	NY

*		subq.w	#1,flip
*		bpl.s	dz
*		move.w	#1,flip
*		add.l	#2,SROTx
dz:
*		subq.w	#1,flip2
*		bpl.s	ny
*		move.w	#0,flip2
*		add.l	#2,srotz
NY:
;		add.l	#2,SROTY
		move.l	#StarBuff,a0
*		move.w	#NumStars-1,d7
*		bsr	ClrStars	;checks out
		bsr	GetSinCos	;checks out
		bsr	Rotate1		;checks out
		bsr	Rotate2		;checks out
		move.l	SrcPtr,a0
		move.w	#NumStars-1,d7emulator
		move.l	RDX,d0
		asr.l	#3,d0
		move.l	RDY,d1
		asr.l	#3,d1
		move.l	RDZ,d2
		asr.l	#3,d2
		bsr	ClipStars	;checks out
		move.l	SrcPtr,a1
		move.l	#StarBuff,a0
		move.w	#NumStars-1,d7emulator
		bsr	Perspective	;checks out
		move.l	#StarBuff,a0
*		move.l	seen,a1
		move.w	#NumStars-1,d7emulator
		bsr	PlotStars	;checks out
		rts

PlotStars:
		move.l	clrbuffhiden,a1
PlotLoop:
		move.l	(a0)+,d0
		move.l	(a0)+,d1
		move.l	(a0)+,d3
		tst.w	d0
		blt.s	PlotNext
		tst.w	d1
		blt.s	PlotNext
		cmp.w	#319,d0
		bgt.s	PlotNext
		cmp.w	#199,d1
		bgt.s	PlotNext
		moveq	#4,d4
		cmp.l	#-1024,d3
		blt.s	DoPlot
		moveq	#7,d4
		cmp.l	#1024,d3
		blt.s	DoPlot
		moveq	#12,d4
DoPlot:
	move.w	d4,pixelcolor
	move.w	d0,pixelx
	move.w	d1,pixely
	bsr	singleplot


*	move.l	a1,d5
*	move.l	hiden,a1

*	move.w	d0,d3         ;duplicate in D3
*	andi.w	#15,d3        ;mask off lower 4 bits

*	lsr.w	#1,d0             ;x coord / 2
*	and.w	#$00f8,d0      ;strip lower 3 bits
*	add.w	d0,a1        ;move x offset to A0

*	lsl.w	#5,d1
*	add.w	d1,a1
*	lsl.w	#2,d1
*	add.w	d1,a1


*	move.w	#$8000,d0     ;set ON pixel mask
*	lsr.w	d3,d0          ;shift right D3 times
*	add.w	d4,a1
*	or.w	d0,(a1)
*	exg	d5,a1

*	move.l	d5,(a1)+
PlotNext:
*	dbra	d7,PlotLoop
	subq.w	#1,d7emulator
	bpl	plotloop
	move.l	#-1,(a1)+
	rts

ClipStars:
		movem.l	(a0),d3-d5

		add.l	d0,d3
		cmp.l	#2560,d3
		ble.s	TstX2
		sub.l	#5120,d3
TstX2:		cmp.l	#-2560,d3
		bge.s	TstY
		add.l	#5120,d3

TstY:		add.l	d1,d4
		cmp.l	#2560,d4
		ble.s	TstY2
		sub.l	#5120,d4
TstY2:		cmp.l	#-2560,d4
		bge.s	TstZ1
		add.l	#5120,d4

TstZ1:		add.l	d2,d5
		cmp.l	#2560,d5
		ble.s	TstZ2
		sub.l	#5120,d5
TstZ2:		cmp.l	#-2560,d5
		bge.s	NextTst
		add.l	#5120,d5
NextTst:	move.l	d3,(a0)+
		move.l	d4,(a0)+
		move.l	d5,(a0)+
*		dbra	d7,ClipStars
		subq.w	#1,d7emulator
		bpl	clipstars
		rts

ClrStars:	move.l	ClrBuffhiden,a0
		moveq	#0,d0
SClrLoop:	tst.l	(a0)
		ble.s	EndSClr
		move.l	(a0)+,a1
		clr.w	(a1)
		bra.s	SClrLoop
EndSClr:	rts

Perspective:	move.l	(a1)+,d2		RDX
		move.l	(a1)+,d3		RDY
		move.l	(a1)+,d4		RDZ

		move.l	ZOOM1(pc),d1
		sub.l	d4,d1
		asr.l	#4,d1
		move.l	ZOOM2(pc),d0
		asr.l	#4,d0
		divs	d1,d0
		move.w	d0,d5			FZoom

		moveq	#9,d6
		move.l	d2,d0
		muls	d5,d0
*		asr.l	d6,d0
		asr.l	#8,d0
		asr.l	#1,d0
		muls	HSPREAD(pc),d0
*		asr.l	d6,d0
		asr.l	#8,d0
		asr.l	#1,d0
		add.l	CENTREX(pc),d0
		move.l	d0,(a0)+
		move.l	d3,d1
		muls	d5,d1
*		asr.l	d6,d1
		asr.l	#8,d1
		asr.l	#1,d1
		muls	VSPREAD(pc),d1
*		asr.l	d6,d1
		asr.l	#8,d1
		asr.l	#1,d1
		move.l	CENTREY(pc),d0
		sub.l	d1,d0
		move.l	d0,(a0)+
		move.l	d4,(a0)+
*		dbra	d7,Perspective
		subq.w	#1,d7emulator
		bpl	perspective
		rts

ROTATE2:	moveq	#0,d3
		moveq	#0,d4
		move.l	SVELOCITY,d5

		move.w	d3,d0
		muls	SVAL1,d0
		move.w	d4,d1
		muls	SVAL2,d1
		move.w	d5,d2
		muls	SVAL3,d2
		add.l	d1,d0
		add.l	d0,d2
		move.l	d2,RDX

		move.w	d3,d0
		muls	SVAL4,d0
		move.w	d4,d1
		muls	SVAL5,d1
		move.w	d5,d2
		muls	SVAL6,d2
		add.l	d1,d0
		add.l	d0,d2
		move.l	d2,RDY

		move.w	d3,d0
		muls	SVAL7,d0
		move.w	d4,d1
		muls	SVAL8,d1
		move.w	d5,d2
		muls	SVAL9,d2
		add.l	d1,d0
		add.l	d0,d2
		move.l	d2,RDZ
		rts

ROTATE1:	moveq	#9,d5
		move.w	SCOSX,d0
		muls	SCOSY,d0
		asr.l	d5,d0	
		move.w	SSINX,d1
		muls	SSINY,d1
		asr.l	d5,d1
		muls	SSINZ,d1
		asr.l	d5,d1
		sub.w	d1,d0
		move.w	d0,SVAL1	(CosX*CosY) - SinZ*(SinX*SinY)

		move.w	SCOSX,d0	
		neg.w	d0
		muls	SSINY,d0
		asr.l	d5,d0
		move.w	SSINX,d1
		muls	SCOSY,d1
		asr.l	d5,d1
		muls	SSINZ,d1
		asr.l	d5,d1
		sub.w	d1,d0
		move.w	d0,SVAL2	(-CosX*SinY) - SinZ*(SinX*CosY)
	
		move.w	SSINX,d0
		muls	SCOSZ,d0
		asr.l	d5,d0
		move.w	d0,SVAL3	SinX*CosZ
		move.w	SSINY,d0
		muls	SCOSZ,d0
		asr.l	d5,d0
		move.w	d0,SVAL4	SinY*CosZ
		move.w	SCOSY,d0
		muls	SCOSZ,d0
		asr.l	d5,d0
		move.w	d0,SVAL5	CosY*CosZ

		move.w	SSINZ,SVAL6	SinZ

		move.w	SSINX,d0
		neg.w	d0
		muls	SCOSY,d0
		asr.l	d5,d0
		move.w	SCOSX,d1
		muls	SSINY,d1
		asr.l	d5,d1
		muls	SSINZ,d1
		asr.l	d5,d1
		sub.w	d1,d0
		move.w	d0,SVAL7	(-SinX*CosY) - SinZ*(SinY*CosX) 

		move.w	SSINX,d0
		muls	SSINY,d0
		asr.l	d5,d0
		move.w	SCOSX,d1
		muls	SCOSY,d1
		asr.l	d5,d1
		muls	SSINZ,d1
		asr.l	d5,d1
		sub.w	d1,d0
		move.w	d0,SVAL8	(SinY*SinY) - SinZ*(CosX*CosY)
		move.w	SCOSX,d0
		muls	SCOSZ,d0
		asr.l	d5,d0
		move.w	d0,SVAL9	CosX*CosZ
		rts

GetSinCos:	cmp.l	#0,SROTX
		bge.s	RotX_Pos
		add.l	#720,SROTX
RotX_Pos:	cmp.l	#719,SROTX
		ble.s	DoRot_Y
		sub.l	#720,SROTX
DoRot_Y:	cmp.l	#0,SROTY
		bge.s	RotY_Pos
		add.l	#720,SROTY
RotY_Pos:	cmp.l	#719,SROTY
		ble.s	DoRot_Z
		sub.l	#720,SROTY
DoRot_Z:	cmp.l	#0,SROTZ
		bge.s	RotZ_Pos
		add.l	#720,SROTZ
RotZ_Pos:	cmp.l	#719,SROTZ
		ble.s	GetSCVals
		sub.l	#720,SROTZ
GetSCVals:	lea	SINTABLE,a0
		move.l	SROTX,d0
		move.w	0(a0,d0.l),SSINX
		add.l	#180,d0
		cmp.l	#719,d0
		ble.s	GetCosX
		sub.l	#720,d0
GetCosX:	move.w	0(a0,d0.l),SCOSX
		move.l	SROTY,d0
		move.w	0(a0,d0.l),SSINY
		add.l	#180,d0
		cmp.l	#719,d0
		ble.s	GetCosY
		sub.l	#720,d0
GetCosY:	move.w	0(a0,d0.l),SCOSY
		move.l	SROTZ,d0
		move.w	0(a0,d0.l),SSINZ
		add.l	#180,d0
		cmp.l	#719,d0
		ble	GetCosZ
		sub.l	#720,d0
GetCosZ:	move.w	0(a0,d0.l),SCOSZ
		rts

SROTX:		ds.l	1
SROTY:		ds.l	1
SROTZ:		ds.l	1
SSINX:		ds.w	1
SCOSX:		ds.w	1
SSINY:		ds.w	1
SCOSY:		ds.w	1
SSINZ:		ds.w	1
SCOSZ:		ds.w	1
HSPREAD:	dc.w	$001E
VSPREAD:	dc.w	$001E
CENTREX:	ds.l	1
CENTREY:	ds.l	1
SVELOCITY	ds.l	1
RDX:		dc.l	$000007F5
RDY:		dc.l	$FFFFFE00
RDZ:		dc.l	$000003CD
ZOOM2:		dc.l	$00100000		00140000
ZOOM1:		dc.l	$00000d00		00000C00
SVAL1:		dc.w	$006E
SVAL2:		dc.w	0
SVAL3:		dc.w	$FFC0
SVAL4:		dc.w	0
SVAL5:		dc.w	$0080
SVAL6:		dc.w	0
SVAL7:		dc.w	$0040
SVAL8:		dc.w	0
SVAL9:		dc.w	$006E
StarBuff:	dc.l	$000000F7
		dc.l	$0000004D
		dc.l	$000003CD
StarBuff2:	ds.l	NumStars*3
ClrBuff:	ds.l	NumStars*3
ClrBuff2:	ds.l	NumStars*3
SrcPtr		ds.l	1


SinTable	incbin	sintable






domovie:
	move.l	whichroutine,a0
	jsr	(a0)
	move.l	movie1delay,d0
	cmp.l	mtimer,d0
	bgt.s	noaddp
	move.l	#0,mtimer
	add.l	#2000,pointer
	move.l	movieend,d0
	cmp.l	pointer,d0
	ble	restartm
noaddp:
	rts
*	bra	mainloop
restartm:
	move.w	#1,firstrun
	move.l	#movie,pointer
	rts

firstrun:	dc.w	0
playmovie7:
	bsr	expandall2
	bsr	expandhalf
	bra	playmoviesingle
playmovie6:
	bsr	pm6
	bsr	pm6b
	rts

playmovie5:
pm6:
	move.l	hiden,a0
	move.l	a0,a1
	add.l	#40,a1
	move.l	a1,a2
	add.l	#40,a2
	move.l	a2,a3
	add.l	#40,a3
	move.l	pointer,a6
	moveq	#49,d7
	bsr	pml
	move.l	hiden,a0
	lea	8000(a0),a1
	bsr	copy5
	rts

copy5:
	move	#149,d7
c5l:
	rept	80
	move.w	(a0)+,(a1)+
	endr
	dbf	d7,c5l
	rts


playmovie4:
	move.l	hiden,a0
	lea	12000(a0),a0

	move.l	a0,a1
	add.l	#40,a1
	move.l	a1,a2
	add.l	#40,a2
	move.l	a2,a3
	add.l	#40,a3
	move.l	pointer,a6
	moveq	#49,d7
	bra	pml

playmovie2:
	move.l	hiden,a0
	lea	120(a0),a0

	move.l	a0,a1
	add.l	#8000-40,a1
	move.l	a1,a2
	add.l	#8000-40,a2
	move.l	a2,a3
	add.l	#8000-40,a3
	move.l	pointer,a6
	moveq	#49,d7
	bra.s	pml
playmovie3:
	move.l	hiden,a0
	lea	12056(a0),a0

	move.l	a0,a1
*	add.l	#8000-40,a1
	move.l	a1,a2
*	add.l	#8000-40,a2
	move.l	a2,a3
*	add.l	#8000-40,a3
	move.l	pointer,a6
	moveq	#49,d7
	bra.s	pml

**********************************

playmovie:
	move.l	hiden,a0
	move.l	a0,a1
	add.l	#8040,a1
	move.l	a1,a2
	add.l	#8040,a2
	move.l	a2,a3
	add.l	#8040,a3
	move.l	pointer,a6
	moveq	#49,d7
pml:
	rept	20
	move.w	(a6),(a0)+
	move.w	(a6),(a1)+
	move.w	(a6),(a2)+
	move.w	(a6)+,(a3)+
	endr
	lea	160-40(a0),a0
	lea	160-40(a1),a1
	lea	160-40(a2),a2
	lea	160-40(a3),a3
	dbf	d7,pml
	rts

playmoviesingle:
	move.l	hiden,a0
	lea	12056(a0),a0
	move.l	pointer,a6
	moveq	#49,d7
pmls:
	rept	20
	move.w	(a6)+,(a0)+
	endr
	lea	160-40(a0),a0
	dbf	d7,pmls
	rts

***********************************************
expandhalf:
pm6b:

	MOVE.L	hiden,A0
	lea	7880(a0),a0
	move.l	pointer,A1
	MOVEq	#49,D7		;49
hthird4:
	MOVEA.L	A0,A2
	MOVEA.L	A1,A3
	MOVEq	#4,D5
hsecond4:
	move.w	d5,a4
	MOVE.W	(A1)+,D1	;4 words for 16 pixels
	MOVE.W	(A1)+,D2
	MOVE.W	(A1)+,D3
	MOVE.W	(A1)+,D4
	moveq	#1,d5
hfirst4:
	moveq	#0,d0
	LSL.W	#1,D1
	ROXL.W	#2,D0
	btst	#1,d0
	beq.s	hd0a
	or.w	#1,d0
hd0a:
	LSL.W	#1,D1
	ROXL.W	#2,D0
   	btst	#1,d0
	beq.s	hd0b
	or.w	#1,d0
hd0b:
	LSL.W	#1,D1
	ROXL.W	#2,D0
	btst	#1,d0
	beq.s	hd0c
	or.w	#1,d0
hd0c:
	LSL.W	#1,D1
	ROXL.W	#2,D0
	btst	#1,d0
	beq.s	hd0d
	or.w	#1,d0
hd0d:
	LSL.W	#1,D1
	ROXL.W	#2,D0
	btst	#1,d0
	beq.s	hd0e
	or.w	#1,d0
hd0e:
	LSL.W	#1,D1
	ROXL.W	#2,D0
	btst	#1,d0
	beq.s	hd0f
	or.w	#1,d0
hd0f:
	LSL.W	#1,D1
	ROXL.W	#2,D0
	btst	#1,d0
	beq.s	hd0g
	or.w	#1,d0
hd0g:
	LSL.W	#1,D1
	ROXL.W	#2,D0
	btst	#1,d0
	beq.s	hd0h
	or.w	#1,d0
hd0h:
	move.w	d0,(a0)
	move.w	d0,160(a0)
	addq.l	#2,a0

	moveq	#0,d0
	LSL.W	#1,D2
	ROXL.W	#2,D0
	btst	#1,d0
	beq.s	hd1a
	or.w	#1,d0
hd1a:
	LSL.W	#1,D2
	ROXL.W	#2,D0
	btst	#1,d0
	beq.s	hd1b
	or.w	#1,d0
hd1b:
	LSL.W	#1,D2
	ROXL.W	#2,D0
	btst	#1,d0
	beq.s	hd1c
	or.w	#1,d0
hd1c:
	LSL.W	#1,D2
	ROXL.W	#2,D0
	btst	#1,d0
	beq.s	hd1d
	or.w	#1,d0
hd1d:
	LSL.W	#1,D2
	ROXL.W	#2,D0
	btst	#1,d0
	beq.s	hd1e
	or.w	#1,d0
hd1e:
	LSL.W	#1,D2
	ROXL.W	#2,D0
	btst	#1,d0
	beq.s	hd1f
	or.w	#1,d0
hd1f:
	LSL.W	#1,D2
	ROXL.W	#2,D0
	btst	#1,d0
	beq.s	hd1g
	or.w	#1,d0
hd1g:
	LSL.W	#1,D2
	ROXL.W	#2,D0
	btst	#1,d0
	beq.s	hd1h
	or.w	#1,d0
hd1h:
	move.w	d0,(a0)
	move.w	d0,160(a0)
	addq.l	#2,a0

	moveq	#0,d0
	LSL.W	#1,D3
	ROXL.W	#2,D0
	btst	#1,d0
	beq.s	hd2a
	or.w	#1,d0
hd2a:
	LSL.W	#1,D3
	ROXL.W	#2,D0
	btst	#1,d0
	beq.s	hd2b
	or.w	#1,d0
hd2b:
	LSL.W	#1,D3
	ROXL.W	#2,D0
	btst	#1,d0
	beq.s	hd2c
	or.w	#1,d0
hd2c:
	LSL.W	#1,D3
	ROXL.W	#2,D0
	btst	#1,d0
	beq.s	hd2d
	or.w	#1,d0
hd2d:
	LSL.W	#1,D3
	ROXL.W	#2,D0
	btst	#1,d0
	beq.s	hd2e
	or.w	#1,d0
hd2e:
	LSL.W	#1,D3
	ROXL.W	#2,D0
	btst	#1,d0
	beq.s	hd2f
	or.w	#1,d0
hd2f:
	LSL.W	#1,D3
	ROXL.W	#2,D0
	btst	#1,d0
	beq.s	hd2g
	or.w	#1,d0
hd2g:
	LSL.W	#1,D3
	ROXL.W	#2,D0
	btst	#1,d0
	beq.s	hd2h
	or.w	#1,d0
hd2h:
	move.w	d0,(a0)
	move.w	d0,160(a0)
	addq.l	#2,a0

	moveq	#0,d0
	LSL.W	#1,D4
	ROXL.W	#2,D0
	btst	#1,d0
	beq.s	hd3a
	or.w	#1,d0
hd3a:
	LSL.W	#1,D4
	ROXL.W	#2,D0
	btst	#1,d0
	beq.s	hd3b
	or.w	#1,d0
hd3b:
	LSL.W	#1,D4
	ROXL.W	#2,D0
	btst	#1,d0
	beq.s	hd3c
	or.w	#1,d0
hd3c:
	LSL.W	#1,D4
	ROXL.W	#2,D0
	btst	#1,d0
	beq.s	hd3d
	or.w	#1,d0
hd3d:
	LSL.W	#1,D4
	ROXL.W	#2,D0
	btst	#1,d0
	beq.s	hd3e
	or.w	#1,d0
hd3e:
	LSL.W	#1,D4
	ROXL.W	#2,D0
	btst	#1,d0
	beq.s	hd3f
	or.w	#1,d0
hd3f:
	LSL.W	#1,D4
	ROXL.W	#2,D0
	btst	#1,d0
	beq.s	hd3g
	or.w	#1,d0
hd3g:
	LSL.W	#1,D4
	ROXL.W	#2,D0
	btst	#1,d0
	beq.s	hd3h
	or.w	#1,d0
hd3h:
	move.w	d0,(a0)
	move.w	d0,160(a0)
	addq.l	#2,a0
	DBF	D5,hfirst4
	move.w	a4,d5
	dbf	d5,hsecond4
	MOVEA.L	A2,A0
*	MOVEA.L	A3,A1
*	lea	$280(a1),a1
	lea	2*160(a0),a0
	DBF	D7,hthird4
	RTS

***********************************************
expandall:
expandall2:
	MOVE.L	hiden,A0
	move.l	pointer,A1
	MOVEq	#49,D7		;49
third4:
	MOVEA.L	A0,A2
	MOVEA.L	A1,A3
	MOVEq	#4,D5
second4:
	move.w	d5,a4
	MOVE.W	(A1)+,D1	;4 words for 16 pixels
	MOVE.W	(A1)+,D2
	MOVE.W	(A1)+,D3
	MOVE.W	(A1)+,D4
	moveq	#3,d5
*	moveq	#0,d0
first4:
	moveq	#0,d0
	LSL.W	#1,D1
	ROXL.W	#4,D0
	btst	#3,d0
	beq.s	d0a
	or.w	#7,d0
d0a:
	LSL.W	#1,D1
	ROXL.W	#4,D0
   	btst	#3,d0
	beq.s	d0b
	or.w	#7,d0
d0b:
	LSL.W	#1,D1
	ROXL.W	#4,D0
	btst	#3,d0
	beq.s	d0c
	or.w	#7,d0
d0c:
	LSL.W	#1,D1
	ROXL.W	#4,D0
	btst	#3,d0
	beq.s	d0d
	or.w	#7,d0
d0d:
	move.w	d0,(a0)
	move.w	d0,160(a0)
	move.w	d0,320(a0)
	move.w	d0,480(a0)
	addq.l	#2,a0

	moveq	#0,d0
	LSL.W	#1,D2
	ROXL.W	#4,D0
	btst	#3,d0
	beq.s	d1a
	or.w	#7,d0
d1a:
	LSL.W	#1,D2
	ROXL.W	#4,D0
	btst	#3,d0
	beq.s	d1b
	or.w	#7,d0
d1b:
	LSL.W	#1,D2
	ROXL.W	#4,D0
	btst	#3,d0
	beq.s	d1c
	or.w	#7,d0
d1c:
	LSL.W	#1,D2
	ROXL.W	#4,D0
	btst	#3,d0
	beq.s	d1d
	or.w	#7,d0
d1d:
	move.w	d0,(a0)
	move.w	d0,160(a0)
	move.w	d0,320(a0)
	move.w	d0,480(a0)
	addq.l	#2,a0

	moveq	#0,d0
	LSL.W	#1,D3
	ROXL.W	#4,D0
	btst	#3,d0
	beq.s	d2a
	or.w	#7,d0
d2a:
	LSL.W	#1,D3
	ROXL.W	#4,D0
	btst	#3,d0
	beq.s	d2b
	or.w	#7,d0
d2b:
	LSL.W	#1,D3
	ROXL.W	#4,D0
	btst	#3,d0
	beq.s	d2c
	or.w	#7,d0
d2c:
	LSL.W	#1,D3
	ROXL.W	#4,D0
	btst	#3,d0
	beq.s	d2d
	or.w	#7,d0
d2d:
	move.w	d0,(a0)
	move.w	d0,160(a0)
	move.w	d0,320(a0)
	move.w	d0,480(a0)
	addq.l	#2,a0

	moveq	#0,d0
	LSL.W	#1,D4
	ROXL.W	#4,D0
	btst	#3,d0
	beq.s	d3a
	or.w	#7,d0
d3a:
	LSL.W	#1,D4
	ROXL.W	#4,D0
	btst	#3,d0
	beq.s	d3b
	or.w	#7,d0
d3b:
	LSL.W	#1,D4
	ROXL.W	#4,D0
	btst	#3,d0
	beq.s	d3c
	or.w	#7,d0
d3c:
	LSL.W	#1,D4
	ROXL.W	#4,D0
	btst	#3,d0
	beq.s	d3d
	or.w	#7,d0
d3d:
	move.w	d0,(a0)
	move.w	d0,160(a0)
	move.w	d0,320(a0)
	move.w	d0,480(a0)
	addq.l	#2,a0
	DBF	D5,first4
	move.w	a4,d5
	dbf	d5,second4
	MOVEA.L	A2,A0
*	MOVEA.L	A3,A1
*	lea	$280(a1),a1
	lea	4*160(a0),a0
	DBF	D7,third4
	RTS




************************************************
load:
	move    #0,-(SP)        ;Open file
	move.l  #moviename,-(SP) ;Address of filename
	move    #$3D,-(SP)
	trap    #1              ;Get handle number in D0
	addq.l  #8,SP
*	tst.w	d0
*	bmi	noinfo
	move.w	d0,-(sp)
	move.w	(sp),d0
	move.l  #movie,-(SP)	;load it straight onto screen
	move.l  #900000,-(SP)	;length to read in
	move    D0,-(SP)	;Handle
	move    #$3F,-(SP)	;bios number
	trap    #1		;Read file in
	add.l   #12,SP
	move.l	d0,savelength
	move.l	#movie,d0
	add.l	#800000,d0
	move.l	d0,movieend
	move    #$3E,-(SP)      ;Handle already on stack
	trap    #1              ;Close file
	addq.l  #4,SP
	move.l	savelength,d0
	lea	movie,a0
	bsr	decom
	rts
loadsound:
	move    #0,-(SP)        ;Open file
	move.l  #soundname,-(SP) ;Address of filename
	move    #$3D,-(SP)
	trap    #1              ;Get handle number in D0
	addq.l  #8,SP
	move.w	d0,-(sp)
	move.w	(sp),d0
	move.l  soundstart,-(SP)	;load it straight onto screen
	move.l  #900000,-(SP)	;length to read in
	move    D0,-(SP)	;Handle
	move    #$3F,-(SP)	;bios number
	trap    #1		;Read file in
	add.l   #12,SP
	move.l	d0,savelength
	move    #$3E,-(SP)      ;Handle already on stack
	trap    #1              ;Close file
	addq.l  #4,SP
	move.l	savelength,d0
	move.l	soundstart,a0
	bsr	decom
	rts

savelength:	dc.l	0
moviename:	dc.b	'dat1.dat',0
soundname:	dc.b	'dat2.dat',0
	even
whichroutine:	dc.l	playmovie3
roll:		dc.l	0
****************************************
movie1delay:	dc.l	5
movie2delay:	dc.l	110000
movieend:	ds.l	1
*********************************************************
*****************************************************************
*	decom2(address.L, length.L)				*
*								*
*	Decompress the compressed data.				*
*	Routine checks that the data is in fact compressed, and	*
*	if necessary decompresses it. 				*
*	This version just takes the address of the data and its	*
*	length. Specifically for our own screens.		*
*								*
*****************************************************************
decom:
	move.l	#0,-(sp)
*	move.l	savecard,a1
*	move.l	30(a1),a0	;address
*	move.l	34(a1),d0	;length
	lea	0(a0,d0.l),a5
	bsr.s	L0017
	cmpi.l	#'MVPX',d7	;check for compressed
	bne.s	L0012
	adda.w	#$78,a0
	bsr.s	L0017
	move.l	d7,(sp)
	lea	0(a0,d7.l),a6
	movea.l a6,a3
	movea.l a6,a1
	lea	savemem+$78(pc),a2
	moveq	#$77,d0
L000F:	move.b	-(a1),-(a2)
	dbra	d0,L000F
	bsr.s	L0017
	bsr.s	L0013
	move.l	(sp),d0
	lea	-120(a0),a1
L0010:	move.b	(a0)+,(a1)+
	dbra	d0,L0010
	subi.l	#$010000,d0
	bpl.s	L0010
	moveq	#$77,d0
	lea	savemem+$78(pc),a2
L0011:	move.b	-(a2),-(a3)
	dbra	d0,L0011
L0012:
	move.l	(sp)+,d0
*	movem.l (sp)+,d0-d7/a0-a6
	rts
L0013:	bsr.s	L001B
	bcc.s	L0016
	moveq	#0,d1
	bsr.s	L001B
	bcc.s	L0015
	lea	L0028(pc),a1
	moveq	#3,d3
L0014:	move.l	-(a1),d0
	bsr.s	L001E
	swap	d0
	cmp.w	d0,d1
	dbne	d3,L0014
	add.l	16(a1),d1
L0015:	move.b	-(a5),-(a6)
	dbra	d1,L0015
L0016:
	cmpa.l	a0,a6
	bgt.s	L0020
	rts
L0017:	moveq	#3,d0
L0018:	move.b	-(a5),d7
	ror.l	#8,d7
	dbra	d0,L0018
	rts
L0019:	move.w	a5,d7
	btst	#0,d7
	bne.s	L001A
	move.l	-(a5),d7
	addx.l	d7,d7
	addx.w	d1,d1
	dbra	d0,L001F
	rts
L001A:	move.l	-5(a5),d7
	lsl.l	#8,d7
	move.b	-(a5),d7
	subq.l	#3,a5
	add.l	d7,d7
	bset	#0,d7
	addx.w	d1,d1
	dbra	d0,L001F
	rts
L001B:	add.l	d7,d7
	beq.s	L001C
	rts
L001C:	move.w	a5,d7
	btst	#0,d7
	bne.s	L001D
	move.l	-(a5),d7
	addx.l	d7,d7
	rts
L001D:	move.l	-5(a5),d7
	lsl.l	#8,d7
	move.b	-(a5),d7
	subq.l	#3,a5
	add.l	d7,d7
	bset	#0,d7
	rts
L001E:	moveq	#0,d1
L001F:	add.l	d7,d7
	beq.s	L0019
	addx.w	d1,d1
	dbra	d0,L001F
	rts
L0020:	lea	L0029(pc),a1
	moveq	#3,d2
L0021:	bsr.s	L001B
	dbcc	d2,L0021
	moveq	#0,d4
	moveq	#0,d1
	move.b	1(a1,d2.w),d0
	ext.w	d0
	bmi.s	L0022
	bsr.s	L001E
L0022:	move.b	6(a1,d2.w),d4
	add.w	d1,d4
	beq.s	L0024
	lea	L002A(pc),a1
	moveq	#1,d2
L0023:	bsr.s	L001B
	dbcc	d2,L0023
	moveq	#0,d1
	move.b	1(a1,d2.w),d0
	ext.w	d0
	bsr.s	L001E
	add.w	d2,d2
	add.w	6(a1,d2.w),d1
	bra.s	L0026
L0024:	moveq	#0,d1
	moveq	#5,d0
	moveq	#0,d2
	bsr.s	L001B
	bcc.s	L0025
	moveq	#8,d0
	moveq	#$40,d2
L0025:	bsr.s	L001E
	add.w	d2,d1
L0026:	lea	2(a6,d4.w),a1
	adda.w	d1,a1
	move.b	-(a1),-(a6)
L0027:	move.b	-(a1),-(a6)
	dbra	d4,L0027
	bra	L0013

	  dc.b $03,$FF,$00,$09,$00,$07,$00,$02
	  dc.b $00,$03,$00,$01,$00,$03,$00,$01
L0028:	  dc.b $00,$00
	  dc.b $00,$0E,$00,$00,$00,$07,$00,$00
	  dc.b $00,$04,$00,$00,$00,$01
L0029:	  dc.b $09,$01,$00,$FF,$FF,$08,$04,$02
	  dc.b $01,$00
L002A:	  dc.b $0B,$04,$07,$00,$01,$20,$00,$00
	  dc.b $00,$20
savemem:	ds.b	120
	even
savecard:	dc.l	0

*********************************************************
*	clipped sprite header				*
*********************************************************
ballsp2:
	dc.w	50,50		;x,y
	dc.l	balldata0	;address of bank of 16 prerotated sprites
	dc.w	8		;height
	dc.w	8
ballsp1:
	dc.w	50,50		;x,y
	dc.l	balldata1	;address of bank of 16 prerotated sprites
	dc.w	16		;height
	dc.w	16
ballsp0:
	dc.w	50,50		;x,y
	dc.l	balldata2	;address of bank of 16 prerotated sprites
	dc.w	16		;height
	dc.w	16

*********************************************************
*	draw prerotated and clippped sprite		*
*	pass address of sprite header in a0		*
*********************************************************
drawclipped:
	cmpi.w	#0,cspritex(a0)
	ble	nosprite
	cmpi.w	#cxmax,cspritex(a0)
	bgt	nosprite
	move.w	cspritex(a0),d2 	;get x
	move.w	d2,d0
	move.w	d0,d4
	move.w	cspritey(a0),d1 ;get y
	move.w	d1,d5
	and.w	#15,d2		;get last 4 bits=offset
	move.w	d2,d3		;get a copy of last 4 bits

	move	cspriteheight(a0),d7		;counter before clipping
	move.w	#cymin,d6	;is it above cymin
	cmp.w	d6,d5
	bge	spcl1
	sub.w	d5,d6		;gives number of lines missing
	sub.w	d6,d7		;for counter
	mulu	#20,d6		;for add to sprite data address
	move.l	hiden,a6
	lea	cymin*160(a6),a6
	bra	spcl2
spcl1:
	moveq	#0,d6
	move.l	hiden,a6
	lsl.w	#5,d1		;*128
	add.w	d1,a6
	lsl.w	#2,d1
	add.w	d1,a6		;=*160 gives line add
spcl2:
	and.w	#$fff0,d0	;word
	lsr.w	#1,d0
	add.w	d0,a6		;a6 has actual screen address


	move.w	#cymax,d1
	sub.w	cspriteheight(a0),d1
	cmp.w	d1,d5
	ble	spcl3
	sub.w	d1,d5
	sub.w	d5,d7

spcl3:
	cmpi.w	#4,cspriteheight(a0)
	bne	spcl4
	move.l	cspritead(a0),a1
	lsl.w	#4,d3		;*16
	add.w	d3,a1		;a1 has ad of final sprite data
	lsl.w	#2,d3
	add.w	d3,a1
	add.w	d6,a1		;adjust for top yclip
	bra	extrastuff
spcl4:
	cmpi.w	#8,cspriteheight(a0)
	bne	spcl5
	move.l	cspritead(a0),a1
	lsl.w	#5,d3		;*16
	add.w	d3,a1		;a1 has ad of final sprite data
	lsl.w	#2,d3
	add.w	d3,a1
	add.w	d6,a1		;adjust for top yclip
	bra	extrastuff

spcl5:
	move.l	cspritead(a0),a1
	lsl.w	#6,d3		;*128
	add.w	d3,a1		;a1 has ad of final sprite data
	lsl.w	#2,d3
	add.w	d3,a1
	add.w	d6,a1		;adjust for top yclip

extrastuff:
	cmpi.w	#cxmin,d4
	bge	spcl6
	bra	clipleftsprite
spcl6:
	cmpi.w	#cxmax-16,d4
	ble	doallsprite
*	fall through

cliprightsprite:
	subq.w	#1,d7
	bmi	nosprite
crightloop:
	move.w	(a6),d0 	;get 4 screen words
	move.w	2(a6),d1
	move.w	4(a6),d2
	move.w	6(a6),d3
	and.w	(a1),d0 	;mask word
	and.w	(a1),d1 	;mask word
	and.w	(a1),d2 	;mask word
	and.w	(a1)+,d3	;mask word
	or.w	(a1)+,d0	;or the sprite image in the hole
	or.w	(a1)+,d1	;we just cut
	or.w	(a1)+,d2
	or.w	(a1)+,d3
	move.w	d0,(a6)+	;put the picture in th picture
	move.w	d1,(a6)+
	move.w	d2,(a6)+
	move.w	d3,(a6)+

*	 add.l	 #10,a1
	lea	10(a1),a1
*	 add.l	 #144+8,a6		 ;move to next screen line
	lea	144+8(a6),a6
	dbf	d7,crightloop
	rts

clipleftsprite:
	subq.w	#1,d7
	bmi	nosprite
cleftloop:
*	 add.l	 #10,a1
	lea	10(a1),a1
*	 addq.l  #8,a6
	lea	8(a6),a6
	move.w	(a6),d0 	;get 4 screen words
	move.w	2(a6),d1
	move.w	4(a6),d2
	move.w	6(a6),d3
	and.w	(a1),d0 	;mask word
	and.w	(a1),d1 	;mask word
	and.w	(a1),d2 	;mask word
	and.w	(a1)+,d3	;mask word
	or.w	(a1)+,d0	;or the sprite image in the hole
	or.w	(a1)+,d1	;we just cut
	or.w	(a1)+,d2
	or.w	(a1)+,d3
	move.w	d0,(a6)+	;put the picture in th picture
	move.w	d1,(a6)+
	move.w	d2,(a6)+
	move.w	d3,(a6)+
*	 add.l	 #144,a6	 ;move to next screen line
	lea	144(a6),a6
	dbf	d7,cleftloop
nosprite:
	rts
doallsprite:
	subq.w	#1,d7
	bmi	nosprite
doallloop:
	move.w	(a6),d0 	;get 4 screen words
	move.w	2(a6),d1
	move.w	4(a6),d2
	move.w	6(a6),d3
	and.w	(a1),d0 	;mask word
	and.w	(a1),d1 	;mask word
	and.w	(a1),d2 	;mask word
	and.w	(a1)+,d3	;mask word
	or.w	(a1)+,d0	;or the sprite image in the hole
	or.w	(a1)+,d1	;we just cut
	or.w	(a1)+,d2
	or.w	(a1)+,d3
	move.w	d0,(a6)+	;put the picture in th picture
	move.w	d1,(a6)+
	move.w	d2,(a6)+
	move.w	d3,(a6)+

	move.w	(a6),d0 	;get 4 screen words
	move.w	2(a6),d1
	move.w	4(a6),d2
	move.w	6(a6),d3
	and.w	(a1),d0 	;mask word
	and.w	(a1),d1 	;mask word
	and.w	(a1),d2 	;mask word
	and.w	(a1)+,d3	;mask word
	or.w	(a1)+,d0	;or the sprite image in the hole
	or.w	(a1)+,d1	;we just cut
	or.w	(a1)+,d2
	or.w	(a1)+,d3
	move.w	d0,(a6)+	;put the picture in th picture
	move.w	d1,(a6)+
	move.w	d2,(a6)+
	move.w	d3,(a6)+
*	 add.l	 #144,a6	 ;move to next screen line
	lea	144(a6),a6
	dbf	d7,doallloop
	rts


******************************************
setuphbl1:
	move.w	#$2700,sr
	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	vbl_vec,vblt+2		;set up vbl handler
	move.l	vbl_vec,oldvblvec
	move.l	#vbl_handler,vbl_vec
	move.l	$134,oldhblvec
	move.w	#$2300,sr
	rts
setuphbl2:
	move.w	#$2700,sr
	and.b	#$df,ieb	;stop 200hz timer
	and.b	#%11011111,iea	;stop hblank
	move.l	$134,oldhblvec
	move.l	#hblhandler1,$134
	or.b	#%00100000,iea			;enable hblank
	or.b	#%00100000,ima
	move.b	#0,tacr
	move.b	#6,tadr
	move.b	#6,tacr
	move.w	#$2300,sr
	rts
setuphbl3:
	move.w	#$2700,sr
	move.b	#%01000000,ieb
	and.b	#$fe,iea	;stop hblank
	move.l	hbl_vec,oldhblvec2
	move.l	#hblhandler3,hbl_vec
	move.b	#%00000001,iea
	or.b	#1,ima
	move.b	#0,tbcr
	move.b	#1,tbdr
	move.b	#8,tbcr
	move.w	#$2300,sr
	rts

hblhandler1:
	move.l	d0,-(sp)	;34
	move.w	color,$ff8242
	add.w	#$0011,color
	cmp.w	#$0077,color
	ble	nnnn
	move.w	#0000,color
nnnn:	and.w	#%0000000000000011,d0
	addq.w	#1,d0
	move.b	#0,tacr
	move.b	d0,tadr
	move.b	#6,tacr
	bclr	#5,isra
	move.l	(sp)+,d0
	rte
color:	dc.w	$0000
hblhandler3:
	movem.l	d0/a0,-(sp)	;34
	lea	collist,a0
	addq.w	#2,colplace
	cmpi.w	#88*2,colplace
	ble.s	cokh
	move.w	#0,colplace
cokh:
	add.w	colplace,a0
	move.w	(a0),$ff8400+8*2

	move.b	#0,tacr
	move.b	#1,tadr
	move.b	#8,tacr
	bclr	#0,isra
	movem.l	(sp)+,d0/a0
	rte

colplace:	dc.w	0
colplace2:	dc.w	0
collist:
	dc.w	$000f,$001f,$002f,$003f,$004f,$005f,$006f,$007f,$008f
	dc.w	$009f,$00af,$00bf,$00cf,$00df,$00ef,$00ff,$00fe,$00fd
	dc.w	$00fc,$00fb,$00fa,$00f9,$00f8,$00f7,$00f6,$00f5,$00f4
	dc.w	$00f3,$00f2,$00f1,$00f0,$01f0,$01f0,$03f0,$04f0,$05f0
	dc.w	$06f0,$07f0,$08f0,$09f0,$0af0,$0bf0,$0cf0,$0df0,$0ef0
	dc.w	$0fe0,$0fd0,$0fc0,$0fb0,$0fa0,$0f90,$0f80,$0f70,$0f60
	dc.w	$0f50,$0f40,$0f30,$0f20,$0f10,$0f00,$0f01,$0f02,$0f03
	dc.w	$0f04,$0f05,$0f06,$0f07,$0f08,$0f09,$0f0a,$0f0b,$0f0c
	dc.w	$0f0d,$0f0e,$0f0f,$0e0f,$0d0f,$0c0f,$0b0f,$0a0f,$090f
	dc.w	$080f,$070f,$060f,$050f,$040f,$030f,$020f,$010f

	

vbl_handler:
	addq.l	#1,mtimer
	addq.w	#2,colplace2
	cmpi.w	#88*2,colplace2
	ble.s	cokh2
	move.w	#0,colplace2
cokh2:
	move.w	colplace2,colplace
*	addq.w	#1,frames50
*	cmpi.w	#50,frames50
*	blt	vbb
*	move.w	frames,frames2
*	move.w	#0,frames
*	move.w	#0,frames50
	move.w	#$0,$ff8240
vbb:
	move.b	seen+1,$ff8205
	move.b	seen+2,$ff8207
	move.b	seen+3,$ff8209
vblt:	jmp	$0

key_handler:
	move.w	#$2500,sr
keyt:	jmp	$0


frames50:	dc.w	0
oldvblvec:	dc.l	0
oldkeyvec:	dc.l	0
oldhblvec:	dc.l	0
oldhblvec2:	dc.l	0
oldieb:		dc.b	0
oldiea:		dc.b	0
oldima:		dc.b	0
	even
restoremfp:
	move.b	oldieb,ieb
	move.b	oldiea,iea
	move.b	oldima,ima
	move.l	oldkeyvec,key_vec
	move.l	oldhblvec,$134
	move.l	oldvblvec,vbl_vec
	rts

*****************************************
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

surfacedfn:	dc.w	0	;color
		dc.l	surfacevrt
surfacevrt:	dc.w	0	;number of points
		ds.w	300

*****************************************
*	my own personal poly draw	*
*****************************************
draw_polygon3:
	movem.l	d0-d7/a0-a6,-(sp)
	move.w	surfacedfn,d0		;color
*	move.w	surfacedfn+2,d5
	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
	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
*	cmp	d0,d1
*	bgt	v_order_ok
	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
	jsr	2(a5)
	bra.s	row_done
multi_span:
	move.w	d2,d1
	not	d2
	jsr	2(a5)
	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)+
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)
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
next_scan:
	dbra	d7,polyfill_lp
poly_done:
	addq.l	#4,sp
abort_poly:
	movem.l	(sp)+,d0-d7/a0-a6
	rts
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

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

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


*************************************
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
*****************************************
sortfaces:
	movem.l	a0-a2,-(sp)
	move.w	(a0)+,d7	;number of em
	subq.w	#2,d7		;account for first centre z
sfl1:
	move	#-1,a5		;flag for noswaps
	move.l	a0,a6
	move.l	a6,a4
	move.w	d7,d6

	addq.l	#2,a6		;skip color word
	move.w	(a6)+,d5	;num of verts in face
	move.w	d5,d4
	addq.w	#1,d4		;for div
	moveq	#0,d1
sfl3a:
	move.w	(a6)+,d2
	asl.w	#3,d2		;*8
	add.w	4(a1,d2.w),d1	;add the z
	dbf	d5,sfl3a
	divs	d4,d1		;d1 has initial centre z
	ext.l	d1
sfl2:
	addq.l	#2,a6
	move.w	(a6)+,d5		;num of verts in face
	move.w	d5,d4
	addq.w	#1,d4			;for div
	moveq	#0,d3
sfl3:
	move.w	(a6)+,d2
	asl.w	#3,d2			;*8
	add.w	4(a1,d2.w),d3		;add the z
	dbf	d5,sfl3
	divs	d4,d3		;theres centre z
	ext.l	d3
	cmp.w	d1,d3
	bgt	swapcoords
	move.w	d3,d1
	addq.l	#2,a4		;other pointer into list (skip col)
	move.w	(a4)+,d0
	addq.w	#1,d0
	add.w	d0,d0
	add.w	d0,a4		;now pointing at next face
	dbf	d6,sfl2
	cmp.w	#-1,a5
	bne	sfl1
	movem.l	(sp)+,a0-a2
	rts

swapcoords:
	move.w	#1,a5
	move.l	a4,a3		;another copy
	move.w	2(a3),d0
	addq.w	#2,d0		;make up for color and num and -1
	lea	holdingpen,a2
swapl1:
	move.w	(a3)+,(a2)+
	dbf	d0,swapl1

	move.w	2(a3),d0
	addq.w	#2,d0		;make up for color and num and -1
swapl2:
	move.w	(a3)+,(a4)+
	dbf	d0,swapl2

	lea	holdingpen,a2
	move.w	2(a2),d0
	addq.w	#2,d0		;make up for color and num and -1
	move.l	a4,a3
swapl3:
	move.w	(a2)+,(a3)+
	dbf	d0,swapl3
	dbf	d6,sfl2

*	cmpi.w	#-1,a5
	bra	sfl1
*	movem.l	(sp)+,a0-a2
*	rts


holdingpen:	ds.w	20
thetainc:	dc.w	0
phiinc:	dc.w	0
rhoinc:	dc.w	0
clz:		dc.w	1500
mytheta:	dc.w	0
myphi:		dc.w	0
myrho:		dc.w	0
whichob:	dc.l	0
lifetime:	dc.w	-1
demaddress:	dc.l	demlist
zfinal:		dc.w	0
halflife:	dc.w	0
**********************************************************
*	address,initial dist,initial theta,phi,rho,zincr,zfinal
*	phiinc,rhoinc
*	and lifetime
*	dc.l	box,twist,dna,dna2,starball,fuji,box2,ballbox

demlist:
	dc.l	monitor
	dc.w	5200,64,64*3,0,17,400,0,2,700
	dc.l	mil
	dc.w	5200,0,0,0,50,400,4,2,500
	dc.l	tor
	dc.w	5200,0,0,0,50,400,4,2,500
	dc.l	box2
	dc.w	5200,0,0,0,50,400,4,2,500
	dc.l	-1
demlist2:
	dc.l	monitor
	dc.w	5200,64,64*3,0,60,400,2,4,700
	dc.l	mil
	dc.w	5200,0,0,0,50,400,4,2,500
	dc.l	tor
	dc.w	5200,0,0,0,50,400,4,2,500
	dc.l	box2
	dc.w	5200,0,0,0,50,400,4,2,500
	dc.l	-1
demomode:
	tst.w	firstrun
	bpl	demomode2
	tst.w	dont
	bpl	stillalive
	subq.w	#1,lifetime
	bpl	stillalive
	move.l	demaddress,a0
	tst.l	(a0)
	bpl	norestart
	lea	demlist,a0
norestart:
	move.l	(a0)+,whichob
	lea	boxvpb,a1
	move.w	(a0)+,uniz
	move.w	(a0)+,unitheta
	move.w	(a0)+,uniphi
	move.w	(a0)+,unirho
	move.w	(a0)+,zinc
	move.w	(a0)+,zfinal
	move.w	(a0)+,phiinc
	move.w	(a0)+,rhoinc
	move.w	(a0)+,lifetime
	move.w	lifetime,d0
	asr.w	#2,d0			;/2
	move.w	d0,halflife
	move.l	a0,demaddress
stillalive:
	move.l	whichob,a5
	lea	boxvpb,a0
	tst.w	dont
	bmi	sta
	bra	dobefore
sta:	move.w	phiinc,d0
	add.w	d0,uniphi
	move.w	rhoinc,d0
	add.w	d0,unirho
	move.w	halflife,d0
	cmp.w	lifetime,d0
	bgt	zoomout
	move.w	uniz,d0
	cmp.w	zfinal,d0
	ble.s	newbit
	sub.w	zinc,d0
	move.w	d0,uniz
	bra	dobefore
newbit:
	tst.w	setflag
	bpl	skipit
	move.w	unirho,d0
	and.w	#255,d0
	cmpi.w	#64,d0
	bne	dobefore
	move.w	#1,setflag
	move.w	#60,delayob
	move.w	#0,rhoinc
	bra	dobefore
skipit:
	subq.w	#1,delayob
	bpl.s	skipit2
	move.b	oldieb,ieb		;stop static
	move.b	oldiea,iea
	move.b	oldima,ima
	move.l	oldkeyvec,key_vec
	move.l	oldhblvec,$134
	move.w	#$0888,$ff8242
	move.w	#1,dont
skipit2:
	bra	dobefore

dont:		dc.w	-1
delayob2:	dc.w	0
delayob:	dc.w	0
setflag:	dc.w	-1

zoomout:
	move.w	uniz,d0
	add.w	zinc,d0
	move.w	d0,uniz
	bra	dobefore


demomode2:
	subq.w	#1,lifetime
	bpl	stillalive2
	move.l	demaddress,a0
	tst.l	(a0)
	bpl	norestart2
	lea	demlist2,a0
norestart2:
	move.l	(a0)+,whichob
	lea	boxvpb,a1
	move.w	(a0)+,uniz
	move.w	(a0)+,unitheta
	move.w	(a0)+,uniphi
	move.w	(a0)+,unirho
	move.w	(a0)+,zinc
	move.w	(a0)+,zfinal
	move.w	(a0)+,phiinc
	move.w	(a0)+,rhoinc
	move.w	(a0)+,lifetime
	move.w	lifetime,d0
	asr.w	#2,d0			;/2
	move.w	d0,halflife
	move.l	a0,demaddress
stillalive2:
	move.l	whichob,a5
	lea	boxvpb,a0
	move.w	phiinc,d0
	add.w	d0,uniphi
	move.w	rhoinc,d0
	add.w	d0,unirho
	move.w	halflife,d0
	cmp.w	lifetime,d0
	bgt.s	zoomout2
	move.w	uniz,d0
	cmp.w	zfinal,d0
	ble	dobefore
	sub.w	zinc,d0
	move.w	d0,uniz
	bra	dobefore
zoomout2:
	move.w	uniz,d0
	add.w	zinc,d0
	move.w	d0,uniz
	bra.s	dobefore


testdraw:
	move.l	whichob,a5
	move.l	obviewpb(a5),a0
	tst.w	mcontrol
	ble	nomc
	cmpi.w	#1,buttondat
	bne.s	mcin
	sub.w	#50,uniz
	bra.s	mouserots
mcin:
	cmpi.w	#2,buttondat
	bne.s	mouserots
	add.w	#50,uniz
mouserots:
	move.w	mx,unitheta
	move.w	my,uniphi
	bra.s	dobefore
nomc:
	tst.w	mcontrol
	beq	demomode
	rts			;no 3D object
dobefore:
	move.w	unitheta,theta(a0)
	move.w	uniphi,phi(a0)
	move.w	unirho,rho(a0)
	move.w	uniz,obz(a5)
	move.w	unix,obx(a5)
	move.w	uniy,oby(a5)

	move.w	obx(a5),plx
	move.w	oby(a5),ply
	move.w	obz(a5),plz
	cmp.w	#40,uniz
	bgt	drawobject
	rts
drawobject:
	bsr	init_vtrans
	move.l	whichob,a3 	;Point to verticies
	bsr	trans_vert	;Transform verticies
	move.l	whichob,a0
	lea	vtrans_vrt,a1	;list of transformed vertices
	lea	ptrans_vrt,a2	;list of onscreen coords
	move.w	linecolinfo(a0),linecolor
	cmpi.w	#dots,style(a0)
	beq	objectisdots
	cmpi.w	#balls,style(a0)
	beq	objectisballs
	move.w	hidenflag(a0),hdf
	move.l	obfacelist(a0),a0
	bsr	sortfaces
	move.w	(a0)+,d0	;number of faces
	subq	#1,d0
tdloop:
	move.w	(a0)+,facecolor1
	move.w	(a0)+,numfacesave	;number of points in face
	tst.w	hdf
	bmi	pdt
	move.w	(a0),d7
	add.w	d7,d7
	add.w	d7,d7
	move.w	(a2,d7.w),d1		;x1
	move.w	2(a2,d7.w),d2		;y1
	move.w	2(a0),d7
	add.w	d7,d7
	add.w	d7,d7
	move.w	(a2,d7.w),d3		;x1
	move.w	2(a2,d7.w),d4		;y1
	move.w	4(a0),d7
	add.w	d7,d7
	add.w	d7,d7
	move.w	(a2,d7.w),d5		;x1
	move.w	2(a2,d7.w),d6		;y1

	sub.w	d3,d1
	sub.w	d4,d2
	sub.w	d3,d5
	sub.w	d4,d6
	muls	d1,d6
	muls	d2,d5
	cmp.l	d5,d6
	blt	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
	add.w	d1,d1
	add.w	d1,a0	
	dbf	d0,tdloop
	rts


objectisballs:
	lea	ptrans_vrt,a1
	lea	vtrans_vrt,a2
	move.w	numdots(a0),d0		;number of em
bp1:	subq.w	#1,d0
oibl1:
	moveq	#-1,d7		;flag
	move.w	d0,d6		;counter
	move.l	a2,a6
	move.l	a1,a5
oibl2:
	move.w	4(a6),d1	;trans z
	cmp.w	12(a6),d1	;trans z
	blt	swapball
	addq.l	#8,a6
	addq.l	#4,a5
	dbf	d6,oibl2
	tst.w	d7
	bpl	oibl1
	bra.s	drawballs
	rts
swapball:
	moveq	#1,d7
	move.w	(a5),d3		;get x
	move.w	2(a5),d4
	move.w	4(a5),(a5)
	move.w	6(a5),2(a5)
	move.w	d3,4(a5)
	move.w	d4,6(a5)

	move.w	12(a6),4(a6)
	move.w	d1,12(a6)

	addq.l	#4,a5
	addq.l	#8,a6
	dbf	d6,oibl2
	bra	oibl1

drawballs:
*	addq.w	#1,d0		;counter
dbloop:
	move.w	4(a2),d1
	cmp.w	#1000,d1
	bgt.s	dba
	lea	ballsp0,a0
	bra.s	drawball
dba:
	cmp.w	#2000,d1
	bgt.s	dbb
	lea	ballsp1,a0
	bra.s	drawball
dbb:
	lea	ballsp2,a0
drawball:
	addq.l	#8,a2
	move.w	(a1)+,cspritex(a0)
	move.w	(a1)+,cspritey(a0)
	movem.l	d0/a1,-(sp)
	bsr	drawclipped
	movem.l	(sp)+,d0/a1
	dbf	d0,dbloop
	rts



objectisdots:
	move.w	#12,pixelcolor
	lea	ptrans_vrt,a1	;list of onscreen coords
	lea	vtrans_vrt,a2
	move.w	plz,d1
	move.w	numdots(a0),d0	;get the number of points
	subq.w	#1,d0
	tst.w	hidenflag(a0)
	bmi	nohides
dotloop:
	cmp.w	4(a2),d1
	blt	nopl
	tst.w	4(a2)
	bmi	nono
	addq.l	#8,a2
	move.w	#12,pixelcolor
	move.w	(a1)+,pixelx
	move.w	(a1)+,pixely
	bsr	singleplot
	dbf	d0,dotloop
	rts
nopl:
	addq.l	#8,a2
	move.w	#13,pixelcolor
	move.w	(a1)+,pixelx
	move.w	(a1)+,pixely
	bsr	singleplot
	dbf	d0,dotloop
	rts
nono:	addq.l	#4,a1
	addq.l	#8,a2
	dbf	d0,dotloop
	rts


nohides:
	move.w	(a1)+,pixelx
	move.w	(a1)+,pixely
	bsr	singleplot
	dbf	d0,nohides
	rts

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	0
cxmax:		equ	319
cymin:		equ	0
cymax:		equ	199
cbits:	dc.w	0
cbits2:	dc.w	0
xsav:	dc.w	0
ysav:	dc.w	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:
	dc.w	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:		dc.w	0
gradient:	dc.w	0
x1:		dc.w	0
x2:		dc.w	0
y1:		dc.w	0
y2:		dc.w	0
dx:		dc.w	0
dy:		dc.w	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
	move.w	d3,(a1)+
	move	d4,(a1)+
	cmpi.w	#zclip,d5
	bge	okz	
	move.w	#zclip,d5
okz:
	move	d5,(a1)+
	move.w	#0,(a1)+
	bsr	prsp_trans	;Apply perspective transformation
	move	d3,(a0)+	;Save transformed x-coordinate		
	move	d4,(a0)+	;Save transformed y-coordinate
	dbf	d6,trans_vert0
	move.l	(SP)+,a0	;Restore transformed vertex pointer
	rts

*******************************
*		VIEW TRANSFORM ON A VERTEX
*		On entry, d0 = x-coordinate of vertex
*			  d1 = y-coordinate of vertex
*			  d2 = z-coordinate of vertex
*		On exit , d3 = x-coordinate view transformed
*			  d4 = y-coordinate view transformed
*			  d5 = z-coordinate view transformed
*	Apply the view transform to a vertex.
view_trans:
	move.w	d0,d3			;get x
	muls	c_theta(a5),d3
	move.w	d1,d4			;get y
	muls	s_theta(a5),d4
	add.l	d4,d3
	swap	d3
	rol.l	#1,d3			;thats	x
	move.w	d1,d4			;get y
	muls	c_theta(a5),d4
	muls	s_theta(a5),d0		;x
	sub.l	d0,d4
	swap	d4
	rol.l	#1,d4			;thats	y
	move.w	d4,d1			;x
	move.w	d3,d0			;y

	move.w	d1,d3			;get y
	muls	c_phi(a5),d3
	move.w	d2,d4			;get z
	muls	s_phi(a5),d4
	add.l	d4,d3
	swap	d3
	rol.l	#1,d3			;thats	y
	move.w	d2,d4			;thats z
	muls	c_phi(a5),d4
	muls	s_phi(a5),d1		;y
	sub.l	d1,d4
	swap	d4
	rol.l	#1,d4			;thats	z
	move.w	d4,d2			;y

	move.w	d0,d4			;x
	muls	c_rho(a5),d4
	move.w	d2,d5
	muls	s_rho(a5),d5		;z
	sub.l	d5,d4
	swap	d4
	rol.l	#1,d4			;thats	x
	move.w	d4,d5
	muls	s_rho(a5),d0
	muls	c_rho(a5),d2
	add.l	d0,d2
	swap	d2
	rol.l	#1,d2		;thats	z
	move.w	d2,d5
	move.w	d3,d7
	move.w	d4,d3
	move.w	d7,d4
	rts

worldview_trans:
	tst.w	theta(a5)
	beq	skiptheta
	move.w	d0,d3			;get x
	muls	c_theta(a5),d3
	move.w	d1,d4			;get y
	muls	s_theta(a5),d4
	add.l	d4,d3
	swap	d3
	rol.l	#1,d3			;thats	y
	move.w	d1,d4			;get y
	muls	c_theta(a5),d4
	muls	s_theta(a5),d0		;x
	sub.l	d0,d4
	swap	d4
	rol.l	#1,d4			;thats	x
	move.w	d4,d1			;x
	move.w	d3,d0			;y

skiptheta:
	tst.w	rho(a5)
	beq	skiprho
	move.w	d0,d4			;x
	muls	c_rho(a5),d4
	move.w	d2,d5
	muls	s_rho(a5),d5		;z
	sub.l	d5,d4
	swap	d4
	rol.l	#1,d4			;thats	z
	move.w	d4,d7
	move.w	d0,d4
	muls	s_rho(a5),d4
	move.w	d2,d3
	muls	c_rho(a5),d3
	add.l	d4,d3
	swap	d3
	rol.l	#1,d3		;thats	x
	move.w	d3,d2
	move.w	d7,d0
skiprho:
	tst.w	phi(a5)
	beq	skipphi
	move.w	d1,d3			;get y
	muls	c_phi(a5),d3
	move.w	d2,d4			;get z
	muls	s_phi(a5),d4
	add.l	d4,d3
	swap	d3
	rol.l	#1,d3			;thats	z
	move.w	d2,d4			;thats z
	muls	c_phi(a5),d4
	muls	s_phi(a5),d1		;y
	sub.l	d1,d4
	swap	d4
	rol.l	#1,d4			;thats	y
	move.w	d4,d2			;y
	move.w	d3,d1
skipphi:
	move.w	d0,d3
	move.w	d1,d4
	move.w	d2,d5
	rts

***********************************************************************
*		PERSPECTIVE TRANSFORM
*		On entry, d3 = view transformed x-coordinate
*			  d4 = view transformed y-coordinate
*			  d5 = view transformed z-coordinate
*		On exit , d3 = screen x-coordinate ( Xe )
*			  d4 = screen y-coordinate ( Ye )
*	Calculate the screen coordinates of the vertex. The coordinates are
* centered about the centre of the screen.
*	Note, the distance to the screen is 2048.

prsp_trans:
	swap	d3		;Calculate Xs
	clr	d3		
	asr.l	#8,d3	  
	divs	d5,d3
	
	swap	d4		;Calculate Ys
	clr	d4
	asr.l	#8,d4
	divs	d5,d4

	add	#159-8,d3		;Adjust for centre of screen
	add	#103,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

clear:	dc.l	-1
****************************************
keyboard:
	move.l	keybuf,a0
	move.w	6(a0),d0
	cmp.w	8(a0),d0
	bne	ischar
	rts
ischar:
	move.w	#2,-(sp)
	move.w	#2,-(sp)
	trap	#13
	addq.l	#4,sp
	swap	d0
quit: 
	cmpi.w  #$10,d0
        bne	morj
        bra     gem
morj:
	cmpi.w	#$39,d0
	bne	restart
	addq.w	#1,mcontrol
	cmpi.w	#2,mcontrol
	blt	mcok
	move.w	#-1,mcontrol
mcok:
	move.w	#-1,lifetime
	move.l	#demlist,demaddress
	rts
restart:
	cmpi.w	#$1c,d0
	bne	plus
	move.l	#movie,pointer
	rts
plus:
	cmpi.w	#$4e,d0
	bne	minus
	subq.l	#1,movie1delay
	tst.l	movie1delay
	bge	m2
	move.l	#0,movie1delay
m2:
	rts
minus:
	cmpi.w	#$4a,d0
	bne	f1
	addq.l	#1,movie1delay
	rts

f1:
	cmpi.w	#$3b,d0
	bne	f2
	move.l	#playmovie,whichroutine
	bsr	clearquick
	move.w	#1000,moviechange
	move.w	#-1,clear
	rts
f2:
	cmpi.w	#$3c,d0
	bne	f3
	move.l	#expandhalf,whichroutine
	bsr	clearquick
	move.w	#1000,moviechange
	move.w	#-1,clear
	rts
f3:
	cmpi.w	#$3d,d0
	bne	f4
	move.l	#expandall,whichroutine
	bsr	clearquick
	move.w	#1000,moviechange
	move.w	#1,clear
	rts
f4:
	cmpi.w	#$3e,d0
	bne	f5
	move.l	#playmovie2,whichroutine
	bsr	clearquick
	move.w	#-1,clear
	move.w	#1000,moviechange
	rts
f5:
	cmpi.w	#$3f,d0
	bne	f6
	move.l	#playmovie3,whichroutine
	bsr	clearquick
	move.w	#-1,clear
	move.w	#1000,moviechange
	rts
f6:
	cmpi.w	#$40,d0
	bne	f7
	move.l	#playmovie4,whichroutine
	bsr	clearquick
	move.w	#-1,clear
	move.w	#1000,moviechange
	rts
f7:
	cmpi.w	#$41,d0
	bne	f8
	move.l	#playmovie5,whichroutine
	bsr	clearquick
	move.w	#1000,moviechange
	move.w	#1,clear
	rts
f8:
	cmpi.w	#$42,d0
	bne	f9
	move.l	#playmovie6,whichroutine
	move.w	#1000,moviechange
	bsr	clearquick
	move.w	#1,clear
	rts
f9:
	cmpi.w	#$43,d0
	bne	f10
	move.l	#playmovie7,whichroutine
	bsr	clearquick
	move.w	#1,clear
	move.w	#1000,moviechange
	rts
f10:
	cmpi.w	#$44,d0
	bne	kpenter
	move.w	#0,moviechange
	rts
kpenter:
	cmpi.w	#$72,d0
	bne	keyback
	move.w	#-1,lifetime
	rts
keyback:
	rts


mcontrol:	dc.w	0
obcounter:	dc.l	0
oblist:
	dc.l	box
*****************************
*****************************
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	#screen1,d0
*	and.w	#%1111111111111000,d0
*	move.l	d0,seen
*	move.l	#screen2,d0
*	and.w	#%1111111111111000,d0
*	move.l	d0,hiden

	move.l	#64008,-(sp)
	move.w	#$48,-(sp)
	trap	#1
	addq.l	#6,sp
	move.l	d0,savemem2
	add.l	#8,d0
	and.w	#$fff8,d0
	move.l	d0,seen
	add.l	#32000,d0
	move.l	d0,hiden

	move.l	#clrbuff,clrbuffseen
	move.l	#clrbuff2,clrbuffhiden

	move.l	#ytable2,ytable
	move.l	#ytable1,sytable

	move.l	#385004,-(sp)
	move.w	#$48,-(sp)
	trap	#1
	addq.l	#6,sp
	move.l	d0,soundstart
	add.l	#385004,d0
	move.l	d0,soundend
	rts

savemem2:	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:		dc.w	0
pixely:		dc.w	0
pixelcolor:
		dc.w	0
ytable1:	ds.l	200
ytable2:	ds.l	200
ytable:		dc.l	0
sytable:	dc.l	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!

*************************************
clearquick2:
	move.l	hiden,a0
	lea	text,a1
	move	#199,d0
	moveq	#0,d1
	lea	wigglelist,a2
	addq.w	#2,wiggleoff
	cmp.w	#800*2,wiggleoff
	ble	wig1
	move.w	#0,wiggleoff
wig1:
	add.w	wiggleoff,a2
cl2loop2:
	move.w	(a2)+,d7
	bpl.s	wok
	lea	wigglelist,a2
	move.w	(a2)+,d7
wok:
	move.l	d1,(a0)		;clear out screen pix
	move.l	d1,4(a0)
	rept	19
	moveq	#0,d4
	move.l	d4,(a0)
	move.w	d4,4(a0)
	move.w	(a1)+,d4
	ror.l	d7,d4
	or.w	d4,6(a0)
	swap	d4
	move.w	d4,6+8(a0)
	addq.l	#8,a0
	endr
	moveq	#0,d4
	move.l	d4,(a0)
	move.w	d4,4(a0)
	move.w	(a1)+,d4
	ror.l	d7,d4
	or.w	d4,6(a0)
	swap	d4
	addq.l	#8,a0
	dbf	d0,cl2loop2
	rts

wiggleoff:	dc.w	0
wigglelist:
	DC.W 8,9,10,11,12,13,13,14,14,15,15,15,15,15,15,14,14,13,13
	DC.W 12,12,11,10,9,9,8,7,7,6,6,5,5,5,5,5,4,5,5,5,5,5,6,6,6
	DC.W 7,7,7,7,8,8,8,8,8,8,8,8,8,8,7,7,7,6,6,6,6,5,5,5,5,5,4
	DC.W 4,4,5,5,5,5,5,6,6,6,7,7,7,8,8,8,9,9,9,9,9,9,9,9,9,9,9
	DC.W 9,9,9,8,8,8,8,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,8,8,8,8,9
	DC.W 9,9,9,9,9,10,10,10,10,10,10,10,9,9,9,9,9,9,8,8,8,8,8,7
	DC.W 7,7,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,4,4,4,4,4,3,3,3,3
	DC.W 3,3,3,3,3,3,4,4,4,5,5,6,6,7,8,8,9,10,10,11,12,12,13,13
	DC.W 14,14,14,14,15,15,14,14,14,13,13,12,12,11,10,10,9,8,7
	DC.W 7,6,5,5,4,4,3,3,3,3,3,3,3,3,4,4,4,5,5,6,6,7,7,8,8,8,8
	DC.W 9,9,9,9,9,9,8,8,8,7,7,7,6,6,5,5,5,4,4,4,4,4,4,4,4,5,5
	DC.W 5,6,6,7,7,8,9,9,10,10,10,11,11,11,12,12,12,12,11,11,11
	DC.W 11,10,10,9,9,8,8,7,6,6,6,5,5,5,5,5,5,5,5,5,5,6,6,7,7,8
	DC.W 8,9,9,10,10,11,11,11,11,12,12,12,11,11,11,11,10,10,9,8
	DC.W 8,7,6,6,5,5,4,3,3,2,2,2,2,1,1,1,2,2,2,2,3,3,3,4,4,5,5
	DC.W 6,6,7,7,8,8,9,9,9,10,10,10,10,11,11,11,11,11,11,11,11
	DC.W 11,11,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,9,9
	DC.W 9,8,8,8,7,7,7,6,6,5,5,5,4,4,4,4,4,4,4,4,4,4,4,4,4,5,5
	DC.W 5,5,6,6,6,7,7,7,7,8,8,8,8,8,8,8,8,8,8,7,7,7,7,7,7,7,7
	DC.W 6,6,6,7,7,7,7,7,7,8,8,8,9,9,9,10,10,10,10,11,11,11,11
	DC.W 11,11,10,10,10,10,9,9,8,8,7,7,7,6,6,5,5,5,5,5,5,5,5,5
	DC.W 5,6,6,6,7,7,8,8,9,9,10,10,11,11,11,11,11,11,11,11,10,10
	DC.W 9,9,8,8,7,6,5,5,4,3,2,2,1,1,0,0,0,0,0,0,1,1,2,2,3,4,4
	DC.W 5,6,7,8,9,10,11,11,12,13,13,14,14,14,14,14,14,14,14,13
	DC.W 13,13,12,11,11,10,10,9,9,8,8,7,7,7,6,6,6,6,6,6,6,6,6,6
	DC.W 6,7,7,7,7,7,7,7,7,7,7,7,7,6,6,6,6,5,5,5,5,4,4,4,4,4,4
	DC.W 4,4,4,4,4,4,5,5,6,6,6,7,7,8,8,8,9,9,10,10,10,10,10,11
	DC.W 11,11,11,10,10,10,10,10,9,9,9,9,9,8,8,8,8,8,7,7,7,7,7
	DC.W 7,7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,7,7,7,7,7,7,7,7,7
	DC.W 7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,7,7,7,6,6,6,5
	DC.W 5,5,4,4,4,3,3,3,3,3,2,3,3,3,3,4,4,4,5,6,6,7,8,9,9,10,11
	DC.W 12,12,13,13,14,14,14,15,15,15,15,14,14,14,13,13,12,11
	DC.W 11,10,9,8,8,7,6,6,5,4,4,4,3,3,3,3,3,3,4,4,4,5,5,5,6,6
	dc.w	-1

*	dc.w	0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
*	dc.w	14,13,12,11,10,9,8,7,6,5,4,3,2,1,0,-1

clearquick:
	tst.l	clear
	bpl	noclear
	move.l	hiden,a0
	move	#199,d0
	moveq	#0,d7
	move.l	d7,d6
	move.l	d6,d5
	move.l	d5,d4
	move.l	d4,d3
	move.l	d3,d2
	move.l	d2,d1
	move.l	d7,a1
	move.l	a1,a2
	move.l	a2,a3
	lea	32000(a0),a0
cl2loop:
	movem.l	d1-d7/a1-a3,-(a0)
	movem.l	d1-d7/a1-a3,-(a0)
	movem.l	d1-d7/a1-a3,-(a0)
	movem.l	d1-d7/a1-a3,-(a0)
	dbf	d0,cl2loop
noclear:
	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	#12000,d1
	add.l	#28000,d2
skloop:
	lea	$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
here:
        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
*	move.b	seen+1,$ff8205
*	move.b	seen+2,$ff8207
*	move.b	seen+3,$ff8209
	rts


flip_scr2:
        move.l  seen,A6
        move.l  hiden,seen
        move.l  A6,hiden
        move.l  sytable,A6
        move.l  ytable,sytable
        move.l  A6,ytable
        move.l  clrbuffseen,A0
        move.l  clrbuffhiden,clrbuffseen
        move.l  A0,clrbuffhiden
	move.w	#37,-(sp)
	trap	#14
	addq.l	#2,sp
	bsr	clearquick
	rts
flip_scr3:
        move.l  seen,A6
        move.l  hiden,seen
        move.l  A6,hiden
        move.l  sytable,A6
        move.l  ytable,sytable
        move.l  A6,ytable
        move.l  clrbuffseen,A0
        move.l  clrbuffhiden,clrbuffseen
        move.l  A0,clrbuffhiden
	move.w	#37,-(sp)
	trap	#14
	addq.l	#2,sp
	bsr	clearquick2
	rts

numvbl:		dc.w	0
*frames:		dc.w	0
framess:		dc.w	0
*****************************************
prtnum: 
	movem.l	d0/d6/d7/a0/a5/a1/a2,-(sp)
        moveq  	#0,d7
        move.w  number,d7
        andi.l  #$ffff,d7
        lea	lineout,a5
	tst.w	d7
	bpl	dodec2
	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
	lea	smallnumbers,a3
	move.w	numwhere,d6
out2:
	cmpa.l  #lineout,a5
        beq     decback2
	moveq	#0,d7
        move.b  -(a5),d7
	mulu	#28,d7
	move.l	a3,a0
	add.w	d7,a0
	moveq	#6,d0
	move.l	hiden,a2
	adda.w	d6,a2
oloop2:
	move.b	(a0)+,(a2)
	move.b	(a0)+,2(a2)
	move.b	(a0)+,4(a2)
	move.b	(a0)+,6(a2)
	lea	160(a2),a2
	dbf	d0,oloop2
	btst	#0,d6
	beq	oh2
	addq.w	#6,d6
oh2:	addq.w	#1,d6
	bra	out2
decback2:
	movem.l	(sp)+,d0/d6/d7/a0/a5/a1/a2
	rts


safe:	dc.w	0
lineout:	ds.l	5
times:		dc.w	0
number:		dc.w	0
numwhere:	dc.w	0
palsave:	ds.w	16
alertout:
	move.l	#0,ap1resv
	move.l	#0,ap2resv
	move.l	#0,ap3resv
	move.l	#0,ap4resv
	move.w	#10,opcode
	move.w	#0,sintin
	move.w	#1,sintout
	move.w	#0,saddrin
	move.w	#0,saddrout
	move.l	#aespb,d1
	move.w	#$c8,d0
	trap	#2

	move.w	#77,opcode
	move.w	#0,sintin
	move.w	#5,sintout
	move.w	#0,saddrin
	move.w	#0,saddrout
	move.l	#aespb,d1
	move.w	#$c8,d0
	trap	#2

	move.w	intout,grhandle

	move.w	#100,opcode
	move.w	#0,contrl+2
	move.w	#11,contrl+6
	move.w	grhandle,contrl+12
	move.w	#1,intin
	move.w	#1,intin+2
	move.w	#1,intin+4
	move.w	#1,intin+6
	move.w	#1,intin+8
	move.w	#1,intin+10
	move.w	#1,intin+12
	move.w	#1,intin+14
	move.w	#1,intin+16
	move.w	#1,intin+18
	move.w	#1,intin+20

	move.l	#vdipb,d1
	move.w	#$73,d0
	trap	#2


	move.w	#52,contrl	;form alert
	move.w	#1,contrl+2
	move.w	#1,contrl+4
	move.w	#1,contrl+6
	move.w	#0,contrl+8
	move.w	#1,intin
	move.l	#alarmtext,addrin
	move.l	#aespb,d1
	move.w	#$c8,d0
	trap	#2
	bra	gem2

alarmtext:
	dc.b	'[1][       This demo is for|'
	dc.b	'         the STE only|]'
	dc.b	'[ OH DEAR | BETTER BUY ONE ]',0,0
	even

aespb:
	dc.l	contrl,global,intin,intout,addrin,addrout
contrl:
opcode:	dc.w	10
sintin:	dc.w	0
sintout:dc.w	1
saddrin:dc.w	0
saddrout:dc.l	0
	ds.w	5

global:
apversion:	dc.w	0
apcount:	dc.w	0
apid:		dc.w	0
apprivate:	dc.l	0
apptree:	dc.l	0
ap1resv:	dc.l	0
ap2resv:	dc.l	0
ap3resv:	dc.l	0
ap4resv:	dc.l	0

intin:
	ds.w	128
ptsin:
	ds.w	128
intout:
	ds.w	128
ptsout:
	ds.w	128
addrin:
	ds.w	128
addrout:
	ds.w	128
vdipb:
	dc.l	contrl,intin,ptsin,intout,ptsout
grhandle:	dc.w	0

******************************************
rnd:	dc.l	0,0,0,0,0
*******************************************************************
randomseed:	ADD.L	D0,D1
		MOVEM.L D0/D1,RND
LongRnd:	MOVEM.L D1-D3,-(SP)	
		MOVEM.L RND,D0/D1
		ANDI.B	#$0E,D0
		ORI.B	#$20,D0
		MOVE.L	D0,D2
		MOVE.L	D1,D3
		ADD.L	D2,D2
		ADDX.L	D3,D3
		ADD.L	D2,D0
		ADDX.L	D3,D1
		SWAP	D3
		SWAP	D2
		MOVE.W	D2,D3
		CLR.W	D2
		ADD.L	D2,D0
		ADDX.L	D3,D1
		MOVEM.L D0/D1,RND
		MOVE.L	D1,D0
		MOVEM.L (SP)+,D1-D3
		RTS
random: 	MOVE.w	D2,-(SP)
		MOVE.W	D0,D2
		BEQ.S	r1
		BSR.S	LongRnd
		CLR.W	D0
		SWAP	D0
		ext.l	d0
		DIVs	D2,D0
		CLR.W	D0
		SWAP	D0
r1:		MOVE.w	(SP)+,D2
		RTS

randomplus:	MOVE.w	D2,-(SP)
		MOVE.W	D0,D2
		BEQ.S	r2
		BSR.S	LongRnd
		CLR.W	D0
		SWAP	D0
		DIVu	D2,D0
		CLR.W	D0
		SWAP	D0
r2:		MOVE.w	(SP)+,D2
		RTS



******************************************
*               RETURN TO GEM
gem:
	jsr	restoremfp
*	move.b	#%11111110,$ff820a
	move.w	#$0,$ff8900


	move.l	#$ff8240,a0
	lea	palsave,a1
	moveq	#15,d7
rspl:
	move.w	(a1)+,d0
	and.w	#$0777,d0
	move.w	d0,(a0)+
	dbf	d7,rspl


        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
        add.l  #12,sp

	move.l	rvsave,$426
	move.l	resave,$42a
	move.w	#%0000000000000000,sounddma(a0)

	move.l	savemem2,-(sp)
	move.w	#$49,-(sp)
	trap	#1
	addq.l	#6,sp
	move.l	soundstart,-(sp)
	move.w	#$49,-(sp)
	trap	#1
	addq.l	#6,sp

        
gem2:
        move.l  savesup,-(SP)    ;Back to user mode
        move.w  #$20,-(SP)
        trap    #1
        addq.l  #6,SP
*illegal
	clr.w	-(sp)
	trap	#1

rvsave:	dc.l	0
resave:	dc.l	0
*********************************************************
*	my routines for loading in the screens		*
*********************************************************

length:		dc.w	0
***************************************
oldmouse:	dc.l	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	 extra1
        move.w	#mmaxx,d0
        bra     extra2
extra1: cmpi.w   #mmaxx,d0
        ble     extra2
        move.w  #mminx,d0
extra2:	cmpi.w  #mminy,d1
        bge     extra3
        move.w  #mmaxy,d1
        bra	extra4
extra3: cmpi.w   #mmaxy,d1
        ble     extra4
        move.w  #mminy,d1
extra4:
        rts

buttondat:	dc.w	0
mx:		dc.w	160
my:		dc.w	100

mminx:	equ	0	;13
mmaxx:	equ	255
mminy:	equ	0	;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:
	incbin	'ste.pal'

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	$00,$00,$44,$7C,$00,$00,$AA,$EE
	 dc.b	$00,$00,$54,$DE,$00,$00,$28,$BA
	 dc.b	$00,$00,$54,$F6,$00,$00,$AA,$EE
	 dc.b	$00,$00,$44,$7C,$00,$00,$20,$30
	 dc.b	$00,$00,$40,$70,$00,$00,$20,$30
	 dc.b	$00,$00,$00,$10,$00,$00,$00,$10
	 dc.b	$00,$00,$28,$38,$00,$00,$44,$7C
	 dc.b	$00,$00,$82,$FE,$00,$00,$44,$C6
	 dc.b	$00,$00,$04,$06,$00,$00,$82,$FE
	 dc.b	$00,$00,$40,$C0,$00,$00,$40,$C0
	 dc.b	$00,$00,$00,$FE,$00,$00,$82,$FE
	 dc.b	$00,$00,$44,$C6,$00,$00,$04,$06
	 dc.b	$00,$00,$22,$3E,$00,$00,$04,$06
	 dc.b	$00,$00,$44,$C6,$00,$00,$82,$FE
	 dc.b	$00,$00,$10,$1C,$00,$00,$28,$3C
	 dc.b	$00,$00,$50,$74,$00,$00,$AA,$EE
	 dc.b	$00,$00,$00,$FE,$00,$00,$0A,$0E
	 dc.b	$00,$00,$00,$04,$00,$00,$00,$FE
	 dc.b	$00,$00,$40,$C0,$00,$00,$40,$C0
	 dc.b	$00,$00,$82,$FE,$00,$00,$04,$06
	 dc.b	$00,$00,$04,$06,$00,$00,$02,$FE
	 dc.b	$00,$00,$82,$FE,$00,$00,$44,$C6
	 dc.b	$00,$00,$40,$C0,$00,$00,$02,$FE
	 dc.b	$00,$00,$44,$C6,$00,$00,$44,$C6
	 dc.b	$00,$00,$82,$FE,$00,$00,$00,$FE
	 dc.b	$00,$00,$04,$06,$00,$00,$0A,$0E
	 dc.b	$00,$00,$14,$1C,$00,$00,$28,$38
	 dc.b	$00,$00,$50,$70,$00,$00,$20,$60
	 dc.b	$00,$00,$82,$FE,$00,$00,$44,$C6
	 dc.b	$00,$00,$44,$C6,$00,$00,$82,$FE
	 dc.b	$00,$00,$44,$C6,$00,$00,$44,$C6
	 dc.b	$00,$00,$82,$FE,$00,$00,$82,$FE
	 dc.b	$00,$00,$40,$C2,$00,$00,$44,$C6
	 dc.b	$00,$00,$80,$FE,$00,$00,$04,$06
	 dc.b	$00,$00,$04,$06,$00,$00,$82,$FE

	even
vtrans_vrt:	ds.w	1700	;View transformed coordinates	
ptrans_vrt:	ds.w	1700	;Perspective transformed coordinates
***************************************************************************
filled:		equ	0
line:		equ	1
dots:		equ	2
balls:		equ	3
obviewpb:	equ	0	;offsets for object linked list desc'n
obx:		equ	4
oby:		equ	6
obz:		equ	8
obvert:		equ	10
obfacelist:	equ	14
obvrtnum:	equ	0
obfacenum:	equ	0
centrepoint:	equ	20
style:		equ	18
numdots:	equ	20
linecolinfo:	equ	20
obcolors:	equ	22
hidenflag:	equ	26
activeflag:	equ	28
canitbehit:	equ	30
obw:		equ	32
onscreenx:	equ	34
onscreeny:	equ	36
obint:		equ	38
obxvel:		equ	40
obyvel:		equ	42
obzvel:		equ	44
worldvpb:	ds.w	20
boxvpb:		ds.w	20
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

dummyob:
	dc.l	0
	dc.w	0,0,0
	dc.l	0
	dc.l	0
	dc.w	0
	dc.w	0
	dc.l	helppalette
	dc.w	0
helppalette:
	dc.w	$0000,$06ee,$0d66,$05dd,$04cc,$03bb,$02aa,$0922
	dc.w	$0199,$00f0,$0030,$000f,$0ff0,$0660,$0cc0,$0330

box2:
	dc.l	boxvpb
	dc.w	0,0,1500
	dc.l	box2vrt
	dc.l	box2face
	dc.w	filled
	dc.w	12
	dc.l	box2palette
	dc.w	0
box2palette:
	dc.w	$0000,$040f,$010d,$0c3f,$021f,$0000,$0000,$0000
	dc.w	$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000
box2vrt:
	dc.w	4*4
	dc.w	-40,40,50
	dc.w	40,40,50
	dc.w	40,-40,50
	dc.w	-40,-40,50

	dc.w	50,40,40
	dc.w	50,40,-40
	dc.w	50,-40,-40
	dc.w	50,-40,40

	dc.w	40,40,-50
	dc.w	-40,40,-50
	dc.w	-40,-40,-50
	dc.w	40,-40,-50

	dc.w	-50,40,-40
	dc.w	-50,40,40
	dc.w	-50,-40,40
	dc.w	-50,-40,-40
	
box2face:
	dc.w	8
	dc.w	7,3,0,1,2,3
	dc.w	8,3,4,5,6,7
	dc.w	5,3,8,9,10,11
	dc.w	6,3,12,13,14,15

	dc.w	11,3,3,2,1,0
	dc.w	12,3,7,6,5,4
	dc.w	9,3,11,10,9,8
	dc.w	10,3,15,14,13,12

box:
	dc.l	boxvpb
	dc.w	0,0,1500
	dc.l	boxvrt
	dc.l	boxface
	dc.w	balls
	dc.w	9
	dc.l	boxpalette
	dc.w	0
boxpalette:
	dc.w	$0000,$0c0f,$0a0d,$010a,$000f,$0005,$0002,$0000
	dc.w	$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000
boxvrt:
	dc.w	9
	dc.w	 -50,50,50
	dc.w	50,50,50
	dc.w	50,50,-50
	dc.w	-50,50,-50
	dc.w	-50,-50,50
	dc.w	50,-50,50
	dc.w	50,-50,-50
	dc.w	-50,-50,-50
	dc.w	0,0,0
boxface:
	dc.w	10
	dc.w	3,3,0,1,2,3
	dc.w	1,2,0,8,1
	dc.w	2,2,1,8,2
	dc.w	1,2,2,8,3
	dc.w	2,2,3,8,0

	dc.w	6,3,4,7,6,5
	dc.w	4,2,5,8,4
	dc.w	5,2,6,8,5
	dc.w	4,2,7,8,6
	dc.w	5,2,4,8,7

tor:
	dc.l	boxvpb
	dc.w	0,0,1500
	dc.l	torvrt
	dc.l	torface
	dc.w	filled
	dc.w	38
	dc.l	boxpalette
	dc.w	1
torvrt:
	dc.w	25
	dc.w	73,00,07
	dc.w	64,00,-20
	dc.w	35,00,-20
	dc.w	26,00,07
	dc.w	50,00,25
	dc.w	22,70,07
	dc.w	19,61,-20
	dc.w	10,33,-20
	dc.w	08,25,07
	dc.w	15,47,25
	dc.w	-59,43,07
	dc.w	-52,37,-20
	dc.w	-28,20,-20
	dc.w	-21,15,07
	dc.w	-40,29,25
	dc.w	-59,-43,07
	dc.w	-52,-37,-20
	dc.w	-28,-20,-20
	dc.w	-21,-15,07
	dc.w	-40,-29,25
	dc.w	22,-70,07
	dc.w	19,-61,-20
	dc.w	10,-33,-20
	dc.w	08,-25,07
	dc.w	15,-47,25
torface:
	dc.w	25
	dc.w	10,3,00,01,06,05
	dc.w	08,3,01,02,07,06
	dc.w	09,3,02,03,08,07
	dc.w	10,3,03,04,09,08
	dc.w	14,3,04,00,05,09
	dc.w	14,3,05,06,11,10
	dc.w	10,3,06,07,12,11
	dc.w	08,3,07,08,13,12
	dc.w	09,3,08,09,14,13
	dc.w	10,3,09,05,10,14
	dc.w	10,3,10,11,16,15
	dc.w	14,3,11,12,17,16
	dc.w	10,3,12,13,18,17
	dc.w	08,3,13,14,19,18
	dc.w	09,3,14,10,15,19
	dc.w	09,3,15,16,21,20
	dc.w	10,3,16,17,22,21
	dc.w	14,3,17,18,23,22
	dc.w	10,3,18,19,24,23
	dc.w	08,3,19,15,20,24
	dc.w	08,3,20,21,01,00
	dc.w	09,3,21,22,02,01
	dc.w	10,3,22,23,03,02
	dc.w	14,3,23,24,04,03
	dc.w	10,3,24,20,00,04



mil:
	dc.l	boxvpb
	dc.w	0,0,1500
	dc.l	milvrt
	dc.l	milface
	dc.w	filled
	dc.w	38
	dc.l	boxpalette
	dc.w	1
milvrt:
	dc.w	38
	dc.w	-72,-89,-19
	dc.w	-115,-89,-19
	dc.w	-115,-115,-19
	dc.w	00,-116,-19
	dc.w	67,-93,-19
	dc.w	109,-35,-19
	dc.w	109,35,-19
	dc.w	67,93,-19
	dc.w	00,115,-19
	dc.w	-67,93,-19
	dc.w	-154,37,-19
	dc.w	-153,12,-19
	dc.w	-76,12,-19
	dc.w	-76,-12,-19
	dc.w	-153,-12,-19
	dc.w	-154,-35,-19
	dc.w	-72,-89,15	;16	x,x,05
	dc.w	-115,-89,05
	dc.w	-115,-115,05
	dc.w	00,-116,05
	dc.w	67,-93,05
	dc.w	109,-35,05
	dc.w	109,35,05
	dc.w	67,93,05
	dc.w	00,115,05
	dc.w	-67,93,05
	dc.w	-154,37,05
	dc.w	-153,12,05
	dc.w	-76,12,18
	dc.w	-76,-12,18
	dc.w	-153,-12,05
	dc.w	-154,-35,05
	dc.w	-25,00,36	;32
	dc.w	00,-32,36
	dc.w	32,00,36
	dc.w	00,31,36
	dc.w	-31,-89,25	;36
	dc.w	-31,-115,05
milface:
	dc.w	41
	dc.w	5,3,00,01,17,16
	dc.w	9,3,01,02,18,17
	dc.w	10,3,02,03,19,18
	dc.w	11,3,03,04,20,19
	dc.w	15,3,04,05,21,20
	dc.w	15,3,05,06,22,21
	dc.w	15,3,06,07,23,22
	dc.w	8,3,07,08,24,23
	dc.w	7,3,08,09,25,24
	dc.w	6,3,09,10,26,25
	dc.w	7,3,10,11,27,26
	dc.w	9,3,11,12,28,27
	dc.w	8,3,12,13,29,28
	dc.w	5,3,13,14,30,29
	dc.w	8,3,14,15,31,30
	dc.w	10,3,15,00,16,31		;16

	dc.w	3,3,02,01,00,03		;first bot
	dc.w	3,9,04,03,00,13,12,09,08,07,06,05
	dc.w	3,3,11,10,09,12
	dc.w	3,3,00,15,14,13	;to do

*	dc.w	15,2,24,35,23
	dc.w	10,3,23,35,34,22

	dc.w	11,2,22,34,21
	dc.w	13,3,34,33,20,21
	dc.w	12,2,20,33,19
	dc.w	10,2,19,33,32
	dc.w	07,2,32,35,24
	dc.w	09,2,24,35,23
	dc.w	08,2,25,32,24
	dc.w	13,2,19,32,36
	dc.w	14,2,19,36,37
	dc.w	12,2,36,17,37	;1
	dc.w	11,2,37,17,18
	dc.w	07,2,25,28,32
	dc.w	06,2,25,26,28
	dc.w	06,2,28,26,27
	dc.w	09,2,32,28,29
	dc.w	09,2,36,32,16
	dc.w	10,2,16,32,29
	dc.w	09,2,29,31,16
	dc.w	09,2,29,30,31
	dc.w	11,3,34,35,32,33



monitor:
	dc.l	boxvpb
	dc.w	0,0,1500
	dc.l	mvrt
	dc.l	mface
	dc.w	filled
	dc.w	3
	dc.l	boxpalette
	dc.w	1

v:	equ	10
mvrt:
	dc.w	28
         dc.w    64,  -92, -51+v
         dc.w    -64, -92, -51+v
         dc.w    -64, -92, 63-v
         dc.w    64,  -92, 63-v
         dc.w    64,  -64, -51+v
         dc.w    -64, -64, -51+v
         dc.w    -64, -64, 63-v
         dc.w    64,  -64, 63-v
         dc.w    57,  -44, -46+v
         dc.w    -57, -44, -46+v
         dc.w    -57, -44, 46-v
         dc.w    57,  -44, 46-v
         dc.w    57,  53,  -46+v
         dc.w    -57, 53,  -46+v
         dc.w    -57, 53,  46-v
         dc.w    57,  53,  46-v
         dc.w    28,  55,  -23+v
         dc.w    -28, 55,  -23+v
         dc.w    -28, 55,  23-v
         dc.w    28,  55,  23-v
         dc.w    28,  70,  -23+v
         dc.w    -28, 70,  -23+v
         dc.w    -28, 70,  23-v
         dc.w    28,  70,  23-v
 
         dc.w    50,  -95, -41+v
         dc.w    -50, -95, -41+v
         dc.w    -50, -95, 49-v
         dc.w    50,  -95, 49-v

mface:
	dc.w	23
         dc.w    5,3,00,01,05,04
         dc.w    6,3,01,02,06,05
         dc.w    11,3,02,03,07,06
         dc.w    12,3,03,00,04,07
         dc.w    4,3,04,05,09,08
         dc.w    5,3,05,06,10,09
         dc.w    10,3,06,07,11,10
         dc.w    11,3,07,04,08,11
         dc.w    3,3,08,09,13,12
         dc.w    4,3,09,10,14,13
         dc.w    9,3,10,11,15,14
         dc.w    10,3,11,08,12,15

         dc.w    6,3,12,13,17,16
         dc.w    7,3,13,14,18,17
         dc.w    8,3,14,15,19,18
         dc.w    8,3,15,12,16,19	;16
         dc.w    3,3,16,17,21,20
         dc.w    4,3,17,18,22,21
         dc.w    9,3,18,19,23,22
         dc.w    10,3,19,16,20,23	;20
         dc.w    10,3,02,01,00,03
         dc.w    6,3,20,21,22,23
         dc.w    1,3,27,26,25,24


palette:
	dc.w	$0077,$0167,$0257,$0347,$0437,$0527,$0617
	dc.w	$0707,$0716,$0725,$0734,$0743,$0752,$0761
	dc.w	$0770,$0771,$0772,$0773,$0774,$0775,$0776
	dc.w	$0777,$0677,$0577,$0477,$0377,$0277,$0177
	dc.w	$0077,$0067,$0057,$0047,$0037,$0027,$0017
	dc.w	$0007,$0107,$0207,$0307,$0407,$0507,$0607
	dc.w	$0707,$0706,$0705,$0704,$0703,$0702,$0701
	dc.w	$0700,$0710,$0720,$0730,$0740,$0750,$0760
	dc.w	$0770,$0670,$0570,$0470,$0370,$0270,$0170
	dc.w	$0070,$0071,$0072,$0073,$0074,$0075,$0076
	
letters:
	 dc.b	$38,$7C,$E6,$E6,$FE,$E6,$E6,$00
	 dc.b	$FC,$E6,$E6,$FC,$E6,$E6,$FC,$00
	 dc.b	$7C,$E6,$E0,$E0,$E0,$E6,$7C,$00
	 dc.b	$F8,$EC,$E6,$E6,$E6,$EC,$F8,$00
	 dc.b	$FE,$E0,$E0,$FC,$E0,$E0,$FE,$00
	 dc.b	$FE,$E0,$E0,$FC,$E0,$E0,$E0,$00
	 dc.b	$7E,$E0,$E0,$EE,$E6,$E6,$7E,$00
	 dc.b	$E6,$E6,$E6,$FE,$E6,$E6,$E6,$00
	 dc.b	$7C,$18,$18,$18,$18,$38,$7C,$00
	 dc.b	$06,$06,$06,$06,$06,$EE,$7C,$00
	 dc.b	$E6,$EC,$F8,$F0,$F8,$EC,$E6,$00
	 dc.b	$E0,$E0,$E0,$E0,$E0,$E0,$FE,$00
	 dc.b	$E3,$FF,$FF,$EB,$E3,$E3,$E3,$00
	 dc.b	$E6,$F6,$FE,$FE,$FE,$EE,$E6,$00
	 dc.b	$7C,$EE,$E6,$E6,$E6,$EE,$7C,$00
	 dc.b	$FC,$E6,$E6,$FC,$E0,$E0,$E0,$00
	 dc.b	$7C,$E6,$E6,$E6,$F6,$FC,$7E,$00
	 dc.b	$FC,$E6,$E6,$FC,$FC,$E6,$E6,$00
	 dc.b	$7C,$E6,$E0,$7C,$06,$E6,$7C,$00
	 dc.b	$FE,$38,$38,$38,$38,$38,$38,$00
	 dc.b	$E6,$E6,$E6,$E6,$E6,$E6,$7E,$00
	 dc.b	$E6,$E6,$E6,$E6,$E6,$7C,$38,$00
	 dc.b	$E3,$E3,$E3,$FB,$FF,$FF,$E7,$00
	 dc.b	$E6,$EE,$7C,$38,$7C,$EE,$E6,$00
	 dc.b	$E6,$E6,$EE,$7C,$38,$38,$38,$00
	 dc.b	$FE,$0E,$1C,$38,$70,$E0,$FE,$00
spacechar:
	dc.b	0,0,0,0,0,0,0,0

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

balldata2:
 dc.w	$F81F,$0000,$07E0,$07E0,$0000,$FFFF,$0000,$0000,$0000,$0000
 dc.w	$E007,$01E0,$1E18,$1FF8,$0000,$FFFF,$0000,$0000,$0000,$0000
 dc.w	$C003,$0210,$3C0C,$3FFC,$0000,$FFFF,$0000,$0000,$0000,$0000
 dc.w	$8001,$04A8,$78E6,$7F1E,$0000,$FFFF,$0000,$0000,$0000,$0000
 dc.w	$8001,$3554,$79B2,$7E0E,$0000,$FFFF,$0000,$0000,$0000,$0000
 dc.w	$0000,$34E4,$F953,$FE4F,$0040,$FFFF,$0000,$0000,$0000,$0000
 dc.w	$0000,$3554,$F9B3,$FE0F,$0000,$FFFF,$0000,$0000,$0000,$0000
 dc.w	$0000,$34A4,$F8E3,$FF1F,$0000,$FFFF,$0000,$0000,$0000,$0000
 dc.w	$0000,$3408,$F807,$FFFF,$0000,$FFFF,$0000,$0000,$0000,$0000
 dc.w	$0000,$B414,$780F,$FFFF,$0000,$FFFF,$0000,$0000,$0000,$0000
 dc.w	$0000,$9BE8,$7C1F,$FFFF,$0000,$FFFF,$0000,$0000,$0000,$0000
 dc.w	$8001,$4C18,$3FFE,$7FFE,$0000,$FFFF,$0000,$0000,$0000,$0000
 dc.w	$8001,$4FF0,$3FFE,$7FFE,$0000,$FFFF,$0000,$0000,$0000,$0000
 dc.w	$C003,$23E0,$1FFC,$3FFC,$0000,$FFFF,$0000,$0000,$0000,$0000
 dc.w	$E007,$1800,$07F8,$1FF8,$0000,$FFFF,$0000,$0000,$0000,$0000
 dc.w	$F81F,$03C0,$0420,$07E0,$0000,$FFFF,$0000,$0000,$0000,$0000
 dc.w	$FC0F,$0000,$03F0,$03F0,$0000,$FFFF,$0000,$0000,$0000,$0000
 dc.w	$F003,$00F0,$0F0C,$0FFC,$0000,$FFFF,$0000,$0000,$0000,$0000
 dc.w	$E001,$0108,$1E06,$1FFE,$0000,$FFFF,$0000,$0000,$0000,$0000
 dc.w	$C000,$0254,$3C73,$3F8F,$0000,$FFFF,$0000,$0000,$0000,$0000
 dc.w	$C000,$1AAA,$3CD9,$3F07,$0000,$FFFF,$0000,$0000,$0000,$0000
 dc.w	$8000,$1A72,$7CA9,$7F27,$0020,$7FFF,$0000,$8000,$8000,$0000
 dc.w	$8000,$1AAA,$7CD9,$7F07,$0000,$7FFF,$0000,$8000,$8000,$0000
 dc.w	$8000,$1A52,$7C71,$7F8F,$0000,$7FFF,$0000,$8000,$8000,$0000
 dc.w	$8000,$1A04,$7C03,$7FFF,$0000,$7FFF,$0000,$8000,$8000,$0000
 dc.w	$8000,$5A0A,$3C07,$7FFF,$0000,$7FFF,$0000,$8000,$8000,$0000
 dc.w	$8000,$4DF4,$3E0F,$7FFF,$0000,$7FFF,$0000,$8000,$8000,$0000
 dc.w	$C000,$260C,$1FFF,$3FFF,$0000,$FFFF,$0000,$0000,$0000,$0000
 dc.w	$C000,$27F8,$1FFF,$3FFF,$0000,$FFFF,$0000,$0000,$0000,$0000
 dc.w	$E001,$11F0,$0FFE,$1FFE,$0000,$FFFF,$0000,$0000,$0000,$0000
 dc.w	$F003,$0C00,$03FC,$0FFC,$0000,$FFFF,$0000,$0000,$0000,$0000
 dc.w	$FC0F,$01E0,$0210,$03F0,$0000,$FFFF,$0000,$0000,$0000,$0000
 dc.w	$FE07,$0000,$01F8,$01F8,$0000,$FFFF,$0000,$0000,$0000,$0000
 dc.w	$F801,$0078,$0786,$07FE,$0000,$FFFF,$0000,$0000,$0000,$0000
 dc.w	$F000,$0084,$0F03,$0FFF,$0000,$FFFF,$0000,$0000,$0000,$0000
 dc.w	$E000,$012A,$1E39,$1FC7,$0000,$7FFF,$0000,$8000,$8000,$0000
 dc.w	$E000,$0D55,$1E6C,$1F83,$0000,$7FFF,$0000,$8000,$8000,$0000
 dc.w	$C000,$0D39,$3E54,$3F93,$0010,$3FFF,$0000,$C000,$C000,$0000
 dc.w	$C000,$0D55,$3E6C,$3F83,$0000,$3FFF,$0000,$C000,$C000,$0000
 dc.w	$C000,$0D29,$3E38,$3FC7,$0000,$3FFF,$0000,$C000,$C000,$0000
 dc.w	$C000,$0D02,$3E01,$3FFF,$0000,$3FFF,$0000,$C000,$C000,$0000
 dc.w	$C000,$2D05,$1E03,$3FFF,$0000,$3FFF,$0000,$C000,$C000,$0000
 dc.w	$C000,$26FA,$1F07,$3FFF,$0000,$3FFF,$0000,$C000,$C000,$0000
 dc.w	$E000,$1306,$0FFF,$1FFF,$0000,$7FFF,$0000,$8000,$8000,$0000
 dc.w	$E000,$13FC,$0FFF,$1FFF,$0000,$7FFF,$0000,$8000,$8000,$0000
 dc.w	$F000,$08F8,$07FF,$0FFF,$0000,$FFFF,$0000,$0000,$0000,$0000
 dc.w	$F801,$0600,$01FE,$07FE,$0000,$FFFF,$0000,$0000,$0000,$0000
 dc.w	$FE07,$00F0,$0108,$01F8,$0000,$FFFF,$0000,$0000,$0000,$0000
 dc.w	$FF03,$0000,$00FC,$00FC,$0000,$FFFF,$0000,$0000,$0000,$0000
 dc.w	$FC00,$003C,$03C3,$03FF,$0000,$FFFF,$0000,$0000,$0000,$0000
 dc.w	$F800,$0042,$0781,$07FF,$0000,$7FFF,$0000,$8000,$8000,$0000
 dc.w	$F000,$0095,$0F1C,$0FE3,$0000,$3FFF,$0000,$C000,$C000,$0000
 dc.w	$F000,$06AA,$0F36,$0FC1,$0000,$3FFF,$8000,$4000,$C000,$0000
 dc.w	$E000,$069C,$1F2A,$1FC9,$0008,$1FFF,$8000,$6000,$E000,$0000
 dc.w	$E000,$06AA,$1F36,$1FC1,$0000,$1FFF,$8000,$6000,$E000,$0000
 dc.w	$E000,$0694,$1F1C,$1FE3,$0000,$1FFF,$8000,$6000,$E000,$0000
 dc.w	$E000,$0681,$1F00,$1FFF,$0000,$1FFF,$0000,$E000,$E000,$0000
 dc.w	$E000,$1682,$0F01,$1FFF,$0000,$1FFF,$8000,$E000,$E000,$0000
 dc.w	$E000,$137D,$0F83,$1FFF,$0000,$1FFF,$0000,$E000,$E000,$0000
 dc.w	$F000,$0983,$07FF,$0FFF,$0000,$3FFF,$0000,$C000,$C000,$0000
 dc.w	$F000,$09FE,$07FF,$0FFF,$0000,$3FFF,$0000,$C000,$C000,$0000
 dc.w	$F800,$047C,$03FF,$07FF,$0000,$7FFF,$0000,$8000,$8000,$0000
 dc.w	$FC00,$0300,$00FF,$03FF,$0000,$FFFF,$0000,$0000,$0000,$0000
 dc.w	$FF03,$0078,$0084,$00FC,$0000,$FFFF,$0000,$0000,$0000,$0000
 dc.w	$FF81,$0000,$007E,$007E,$0000,$FFFF,$0000,$0000,$0000,$0000
 dc.w	$FE00,$001E,$01E1,$01FF,$0000,$7FFF,$0000,$8000,$8000,$0000
 dc.w	$FC00,$0021,$03C0,$03FF,$0000,$3FFF,$0000,$C000,$C000,$0000
 dc.w	$F800,$004A,$078E,$07F1,$0000,$1FFF,$8000,$6000,$E000,$0000
 dc.w	$F800,$0355,$079B,$07E0,$0000,$1FFF,$4000,$2000,$E000,$0000
 dc.w	$F000,$034E,$0F95,$0FE4,$0004,$0FFF,$4000,$3000,$F000,$0000
 dc.w	$F000,$0355,$0F9B,$0FE0,$0000,$0FFF,$4000,$3000,$F000,$0000
 dc.w	$F000,$034A,$0F8E,$0FF1,$0000,$0FFF,$4000,$3000,$F000,$0000
 dc.w	$F000,$0340,$0F80,$0FFF,$0000,$0FFF,$8000,$7000,$F000,$0000
 dc.w	$F000,$0B41,$0780,$0FFF,$0000,$0FFF,$4000,$F000,$F000,$0000
 dc.w	$F000,$09BE,$07C1,$0FFF,$0000,$0FFF,$8000,$F000,$F000,$0000
 dc.w	$F800,$04C1,$03FF,$07FF,$0000,$1FFF,$8000,$E000,$E000,$0000
 dc.w	$F800,$04FF,$03FF,$07FF,$0000,$1FFF,$0000,$E000,$E000,$0000
 dc.w	$FC00,$023E,$01FF,$03FF,$0000,$3FFF,$0000,$C000,$C000,$0000
 dc.w	$FE00,$0180,$007F,$01FF,$0000,$7FFF,$0000,$8000,$8000,$0000
 dc.w	$FF81,$003C,$0042,$007E,$0000,$FFFF,$0000,$0000,$0000,$0000
 dc.w	$FFC0,$0000,$003F,$003F,$0000,$FFFF,$0000,$0000,$0000,$0000
 dc.w	$FF00,$000F,$00F0,$00FF,$0000,$3FFF,$0000,$C000,$C000,$0000
 dc.w	$FE00,$0010,$01E0,$01FF,$0000,$1FFF,$8000,$6000,$E000,$0000
 dc.w	$FC00,$0025,$03C7,$03F8,$0000,$0FFF,$4000,$3000,$F000,$0000
 dc.w	$FC00,$01AA,$03CD,$03F0,$0000,$0FFF,$A000,$9000,$7000,$0000
 dc.w	$F800,$01A7,$07CA,$07F2,$0002,$07FF,$2000,$9800,$7800,$0000
 dc.w	$F800,$01AA,$07CD,$07F0,$0000,$07FF,$A000,$9800,$7800,$0000
 dc.w	$F800,$01A5,$07C7,$07F8,$0000,$07FF,$2000,$1800,$F800,$0000
 dc.w	$F800,$01A0,$07C0,$07FF,$0000,$07FF,$4000,$3800,$F800,$0000
 dc.w	$F800,$05A0,$03C0,$07FF,$0000,$07FF,$A000,$7800,$F800,$0000
 dc.w	$F800,$04DF,$03E0,$07FF,$0000,$07FF,$4000,$F800,$F800,$0000
 dc.w	$FC00,$0260,$01FF,$03FF,$0000,$0FFF,$C000,$F000,$F000,$0000
 dc.w	$FC00,$027F,$01FF,$03FF,$0000,$0FFF,$8000,$F000,$F000,$0000
 dc.w	$FE00,$011F,$00FF,$01FF,$0000,$1FFF,$0000,$E000,$E000,$0000
 dc.w	$FF00,$00C0,$003F,$00FF,$0000,$3FFF,$0000,$C000,$C000,$0000
 dc.w	$FFC0,$001E,$0021,$003F,$0000,$FFFF,$0000,$0000,$0000,$0000
 dc.w	$FFE0,$0000,$001F,$001F,$0000,$7FFF,$0000,$8000,$8000,$0000
 dc.w	$FF80,$0007,$0078,$007F,$0000,$1FFF,$8000,$6000,$E000,$0000
 dc.w	$FF00,$0008,$00F0,$00FF,$0000,$0FFF,$4000,$3000,$F000,$0000
 dc.w	$FE00,$0012,$01E3,$01FC,$0000,$07FF,$A000,$9800,$7800,$0000
 dc.w	$FE00,$00D5,$01E6,$01F8,$0000,$07FF,$5000,$C800,$3800,$0000
 dc.w	$FC00,$00D3,$03E5,$03F9,$0001,$03FF,$9000,$4C00,$3C00,$0000
 dc.w	$FC00,$00D5,$03E6,$03F8,$0000,$03FF,$5000,$CC00,$3C00,$0000
 dc.w	$FC00,$00D2,$03E3,$03FC,$0000,$03FF,$9000,$8C00,$7C00,$0000
 dc.w	$FC00,$00D0,$03E0,$03FF,$0000,$03FF,$2000,$1C00,$FC00,$0000
 dc.w	$FC00,$02D0,$01E0,$03FF,$0000,$03FF,$5000,$3C00,$FC00,$0000
 dc.w	$FC00,$026F,$01F0,$03FF,$0000,$03FF,$A000,$7C00,$FC00,$0000
 dc.w	$FE00,$0130,$00FF,$01FF,$0000,$07FF,$6000,$F800,$F800,$0000
 dc.w	$FE00,$013F,$00FF,$01FF,$0000,$07FF,$C000,$F800,$F800,$0000
 dc.w	$FF00,$008F,$007F,$00FF,$0000,$0FFF,$8000,$F000,$F000,$0000
 dc.w	$FF80,$0060,$001F,$007F,$0000,$1FFF,$0000,$E000,$E000,$0000
 dc.w	$FFE0,$000F,$0010,$001F,$0000,$7FFF,$0000,$8000,$8000,$0000
 dc.w	$FFF0,$0000,$000F,$000F,$0000,$3FFF,$0000,$C000,$C000,$0000
 dc.w	$FFC0,$0003,$003C,$003F,$0000,$0FFF,$C000,$3000,$F000,$0000
 dc.w	$FF80,$0004,$0078,$007F,$0000,$07FF,$2000,$1800,$F800,$0000
 dc.w	$FF00,$0009,$00F1,$00FE,$0000,$03FF,$5000,$CC00,$3C00,$0000
 dc.w	$FF00,$006A,$00F3,$00FC,$0000,$03FF,$A800,$6400,$1C00,$0000
 dc.w	$FE00,$0069,$01F2,$01FC,$0000,$01FF,$C800,$A600,$9E00,$8000
 dc.w	$FE00,$006A,$01F3,$01FC,$0000,$01FF,$A800,$6600,$1E00,$0000
 dc.w	$FE00,$0069,$01F1,$01FE,$0000,$01FF,$4800,$C600,$3E00,$0000
 dc.w	$FE00,$0068,$01F0,$01FF,$0000,$01FF,$1000,$0E00,$FE00,$0000
 dc.w	$FE00,$0168,$00F0,$01FF,$0000,$01FF,$2800,$1E00,$FE00,$0000
 dc.w	$FE00,$0137,$00F8,$01FF,$0000,$01FF,$D000,$3E00,$FE00,$0000
 dc.w	$FF00,$0098,$007F,$00FF,$0000,$03FF,$3000,$FC00,$FC00,$0000
 dc.w	$FF00,$009F,$007F,$00FF,$0000,$03FF,$E000,$FC00,$FC00,$0000
 dc.w	$FF80,$0047,$003F,$007F,$0000,$07FF,$C000,$F800,$F800,$0000
 dc.w	$FFC0,$0030,$000F,$003F,$0000,$0FFF,$0000,$F000,$F000,$0000
 dc.w	$FFF0,$0007,$0008,$000F,$0000,$3FFF,$8000,$4000,$C000,$0000
 dc.w	$FFF8,$0000,$0007,$0007,$0000,$1FFF,$0000,$E000,$E000,$0000
 dc.w	$FFE0,$0001,$001E,$001F,$0000,$07FF,$E000,$1800,$F800,$0000
 dc.w	$FFC0,$0002,$003C,$003F,$0000,$03FF,$1000,$0C00,$FC00,$0000
 dc.w	$FF80,$0004,$0078,$007F,$0000,$01FF,$A800,$E600,$1E00,$0000
 dc.w	$FF80,$0035,$0079,$007E,$0000,$01FF,$5400,$B200,$0E00,$0000
 dc.w	$FF00,$0034,$00F9,$00FE,$0000,$00FF,$E400,$5300,$4F00,$4000
 dc.w	$FF00,$0035,$00F9,$00FE,$0000,$00FF,$5400,$B300,$0F00,$0000
 dc.w	$FF00,$0034,$00F8,$00FF,$0000,$00FF,$A400,$E300,$1F00,$0000
 dc.w	$FF00,$0034,$00F8,$00FF,$0000,$00FF,$0800,$0700,$FF00,$0000
 dc.w	$FF00,$00B4,$0078,$00FF,$0000,$00FF,$1400,$0F00,$FF00,$0000
 dc.w	$FF00,$009B,$007C,$00FF,$0000,$00FF,$E800,$1F00,$FF00,$0000
 dc.w	$FF80,$004C,$003F,$007F,$0000,$01FF,$1800,$FE00,$FE00,$0000
 dc.w	$FF80,$004F,$003F,$007F,$0000,$01FF,$F000,$FE00,$FE00,$0000
 dc.w	$FFC0,$0023,$001F,$003F,$0000,$03FF,$E000,$FC00,$FC00,$0000
 dc.w	$FFE0,$0018,$0007,$001F,$0000,$07FF,$0000,$F800,$F800,$0000
 dc.w	$FFF8,$0003,$0004,$0007,$0000,$1FFF,$C000,$2000,$E000,$0000
 dc.w	$FFFC,$0000,$0003,$0003,$0000,$0FFF,$0000,$F000,$F000,$0000
 dc.w	$FFF0,$0000,$000F,$000F,$0000,$03FF,$F000,$0C00,$FC00,$0000
	 dc.w	$FFE0,$0001,$001E,$001F,$0000,$01FF,$0800,$0600,$FE00,$0000
	 dc.w	$FFC0,$0002,$003C,$003F,$0000,$00FF,$5400,$7300,$8F00,$0000
	 dc.w	$FFC0,$001A,$003C,$003F,$0000,$00FF,$AA00,$D900,$0700,$0000
	 dc.w	$FF80,$001A,$007C,$007F,$0000,$007F,$7200,$A980,$2780,$2000
	 dc.w	$FF80,$001A,$007C,$007F,$0000,$007F,$AA00,$D980,$0780,$0000
	 dc.w	$FF80,$001A,$007C,$007F,$0000,$007F,$5200,$7180,$8F80,$0000
	 dc.w	$FF80,$001A,$007C,$007F,$0000,$007F,$0400,$0380,$FF80,$0000
	 dc.w	$FF80,$005A,$003C,$007F,$0000,$007F,$0A00,$0780,$FF80,$0000
	 dc.w	$FF80,$004D,$003E,$007F,$0000,$007F,$F400,$0F80,$FF80,$0000
	 dc.w	$FFC0,$0026,$001F,$003F,$0000,$00FF,$0C00,$FF00,$FF00,$0000
	 dc.w	$FFC0,$0027,$001F,$003F,$0000,$00FF,$F800,$FF00,$FF00,$0000
	 dc.w	$FFE0,$0011,$000F,$001F,$0000,$01FF,$F000,$FE00,$FE00,$0000
	 dc.w	$FFF0,$000C,$0003,$000F,$0000,$03FF,$0000,$FC00,$FC00,$0000
	 dc.w	$FFFC,$0001,$0002,$0003,$0000,$0FFF,$E000,$1000,$F000,$0000
	 dc.w	$FFFE,$0000,$0001,$0001,$0000,$07FF,$0000,$F800,$F800,$0000
	 dc.w	$FFF8,$0000,$0007,$0007,$0000,$01FF,$7800,$8600,$FE00,$0000
	 dc.w	$FFF0,$0000,$000F,$000F,$0000,$00FF,$8400,$0300,$FF00,$0000
	 dc.w	$FFE0,$0001,$001E,$001F,$0000,$007F,$2A00,$3980,$C780,$0000
	 dc.w	$FFE0,$000D,$001E,$001F,$0000,$007F,$5500,$6C80,$8380,$0000
	 dc.w	$FFC0,$000D,$003E,$003F,$0000,$003F,$3900,$54C0,$93C0,$1000
	 dc.w	$FFC0,$000D,$003E,$003F,$0000,$003F,$5500,$6CC0,$83C0,$0000
	 dc.w	$FFC0,$000D,$003E,$003F,$0000,$003F,$2900,$38C0,$C7C0,$0000
	 dc.w	$FFC0,$000D,$003E,$003F,$0000,$003F,$0200,$01C0,$FFC0,$0000
	 dc.w	$FFC0,$002D,$001E,$003F,$0000,$003F,$0500,$03C0,$FFC0,$0000
	 dc.w	$FFC0,$0026,$001F,$003F,$0000,$003F,$FA00,$07C0,$FFC0,$0000
	 dc.w	$FFE0,$0013,$000F,$001F,$0000,$007F,$0600,$FF80,$FF80,$0000
	 dc.w	$FFE0,$0013,$000F,$001F,$0000,$007F,$FC00,$FF80,$FF80,$0000
	 dc.w	$FFF0,$0008,$0007,$000F,$0000,$00FF,$F800,$FF00,$FF00,$0000
	 dc.w	$FFF8,$0006,$0001,$0007,$0000,$01FF,$0000,$FE00,$FE00,$0000
	 dc.w	$FFFE,$0000,$0001,$0001,$0000,$07FF,$F000,$0800,$F800,$0000
	 dc.w	$FFFF,$0000,$0000,$0000,$0000,$03FF,$0000,$FC00,$FC00,$0000
	 dc.w	$FFFC,$0000,$0003,$0003,$0000,$00FF,$3C00,$C300,$FF00,$0000
	 dc.w	$FFF8,$0000,$0007,$0007,$0000,$007F,$4200,$8180,$FF80,$0000
	 dc.w	$FFF0,$0000,$000F,$000F,$0000,$003F,$9500,$1CC0,$E3C0,$0000
	 dc.w	$FFF0,$0006,$000F,$000F,$0000,$003F,$AA80,$3640,$C1C0,$0000
	 dc.w	$FFE0,$0006,$001F,$001F,$0000,$001F,$9C80,$2A60,$C9E0,$0800
	 dc.w	$FFE0,$0006,$001F,$001F,$0000,$001F,$AA80,$3660,$C1E0,$0000
	 dc.w	$FFE0,$0006,$001F,$001F,$0000,$001F,$9480,$1C60,$E3E0,$0000
	 dc.w	$FFE0,$0006,$001F,$001F,$0000,$001F,$8100,$00E0,$FFE0,$0000
	 dc.w	$FFE0,$0016,$000F,$001F,$0000,$001F,$8280,$01E0,$FFE0,$0000
	 dc.w	$FFE0,$0013,$000F,$001F,$0000,$001F,$7D00,$83E0,$FFE0,$0000
	 dc.w	$FFF0,$0009,$0007,$000F,$0000,$003F,$8300,$FFC0,$FFC0,$0000
	 dc.w	$FFF0,$0009,$0007,$000F,$0000,$003F,$FE00,$FFC0,$FFC0,$0000
	 dc.w	$FFF8,$0004,$0003,$0007,$0000,$007F,$7C00,$FF80,$FF80,$0000
	 dc.w	$FFFC,$0003,$0000,$0003,$0000,$00FF,$0000,$FF00,$FF00,$0000
	 dc.w	$FFFF,$0000,$0000,$0000,$0000,$03FF,$7800,$8400,$FC00,$0000
	 dc.w	$FFFF,$0000,$0000,$0000,$0000,$81FF,$0000,$7E00,$7E00,$0000
	 dc.w	$FFFE,$0000,$0001,$0001,$0000,$007F,$1E00,$E180,$FF80,$0000
	 dc.w	$FFFC,$0000,$0003,$0003,$0000,$003F,$2100,$C0C0,$FFC0,$0000
	 dc.w	$FFF8,$0000,$0007,$0007,$0000,$001F,$4A80,$8E60,$F1E0,$0000
	 dc.w	$FFF8,$0003,$0007,$0007,$0000,$001F,$5540,$9B20,$E0E0,$0000
	 dc.w	$FFF0,$0003,$000F,$000F,$0000,$000F,$4E40,$9530,$E4F0,$0400
	 dc.w	$FFF0,$0003,$000F,$000F,$0000,$000F,$5540,$9B30,$E0F0,$0000
	 dc.w	$FFF0,$0003,$000F,$000F,$0000,$000F,$4A40,$8E30,$F1F0,$0000
	 dc.w	$FFF0,$0003,$000F,$000F,$0000,$000F,$4080,$8070,$FFF0,$0000
	 dc.w	$FFF0,$000B,$0007,$000F,$0000,$000F,$4140,$80F0,$FFF0,$0000
	 dc.w	$FFF0,$0009,$0007,$000F,$0000,$000F,$BE80,$C1F0,$FFF0,$0000
	 dc.w	$FFF8,$0004,$0003,$0007,$0000,$001F,$C180,$FFE0,$FFE0,$0000
	 dc.w	$FFF8,$0004,$0003,$0007,$0000,$001F,$FF00,$FFE0,$FFE0,$0000
	 dc.w	$FFFC,$0002,$0001,$0003,$0000,$003F,$3E00,$FFC0,$FFC0,$0000
	 dc.w	$FFFE,$0001,$0000,$0001,$0000,$007F,$8000,$7F80,$FF80,$0000
	 dc.w	$FFFF,$0000,$0000,$0000,$0000,$81FF,$3C00,$4200,$7E00,$0000
	 dc.w	$FFFF,$0000,$0000,$0000,$0000,$C0FF,$0000,$3F00,$3F00,$0000
	 dc.w	$FFFF,$0000,$0000,$0000,$0000,$003F,$0F00,$F0C0,$FFC0,$0000
	 dc.w	$FFFE,$0000,$0001,$0001,$0000,$001F,$1080,$E060,$FFE0,$0000
	 dc.w	$FFFC,$0000,$0003,$0003,$0000,$000F,$2540,$C730,$F8F0,$0000
	 dc.w	$FFFC,$0001,$0003,$0003,$0000,$000F,$AAA0,$CD90,$F070,$0000
	 dc.w	$FFF8,$0001,$0007,$0007,$0000,$0007,$A720,$CA98,$F278,$0200
	 dc.w	$FFF8,$0001,$0007,$0007,$0000,$0007,$AAA0,$CD98,$F078,$0000
	 dc.w	$FFF8,$0001,$0007,$0007,$0000,$0007,$A520,$C718,$F8F8,$0000
	 dc.w	$FFF8,$0001,$0007,$0007,$0000,$0007,$A040,$C038,$FFF8,$0000
	 dc.w	$FFF8,$0005,$0003,$0007,$0000,$0007,$A0A0,$C078,$FFF8,$0000
	 dc.w	$FFF8,$0004,$0003,$0007,$0000,$0007,$DF40,$E0F8,$FFF8,$0000
	 dc.w	$FFFC,$0002,$0001,$0003,$0000,$000F,$60C0,$FFF0,$FFF0,$0000
	 dc.w	$FFFC,$0002,$0001,$0003,$0000,$000F,$7F80,$FFF0,$FFF0,$0000
	 dc.w	$FFFE,$0001,$0000,$0001,$0000,$001F,$1F00,$FFE0,$FFE0,$0000
	 dc.w	$FFFF,$0000,$0000,$0000,$0000,$003F,$C000,$3FC0,$FFC0,$0000
	 dc.w	$FFFF,$0000,$0000,$0000,$0000,$C0FF,$1E00,$2100,$3F00,$0000
	 dc.w	$FFFF,$0000,$0000,$0000,$0000,$E07F,$0000,$1F80,$1F80,$0000
	 dc.w	$FFFF,$0000,$0000,$0000,$0000,$801F,$0780,$7860,$7FE0,$0000
	 dc.w	$FFFF,$0000,$0000,$0000,$0000,$000F,$0840,$F030,$FFF0,$0000
	 dc.w	$FFFE,$0000,$0001,$0001,$0000,$0007,$12A0,$E398,$FC78,$0000
	 dc.w	$FFFE,$0000,$0001,$0001,$0000,$0007,$D550,$E6C8,$F838,$0000
	 dc.w	$FFFC,$0000,$0003,$0003,$0000,$0003,$D390,$E54C,$F93C,$0100
	 dc.w	$FFFC,$0000,$0003,$0003,$0000,$0003,$D550,$E6CC,$F83C,$0000
	 dc.w	$FFFC,$0000,$0003,$0003,$0000,$0003,$D290,$E38C,$FC7C,$0000
	 dc.w	$FFFC,$0000,$0003,$0003,$0000,$0003,$D020,$E01C,$FFFC,$0000
	 dc.w	$FFFC,$0002,$0001,$0003,$0000,$0003,$D050,$E03C,$FFFC,$0000
	 dc.w	$FFFC,$0002,$0001,$0003,$0000,$0003,$6FA0,$F07C,$FFFC,$0000
	 dc.w	$FFFE,$0001,$0000,$0001,$0000,$0007,$3060,$FFF8,$FFF8,$0000
	 dc.w	$FFFE,$0001,$0000,$0001,$0000,$0007,$3FC0,$FFF8,$FFF8,$0000
	 dc.w	$FFFF,$0000,$0000,$0000,$0000,$000F,$8F80,$7FF0,$FFF0,$0000
	 dc.w	$FFFF,$0000,$0000,$0000,$0000,$801F,$6000,$1FE0,$7FE0,$0000
	 dc.w	$FFFF,$0000,$0000,$0000,$0000,$E07F,$0F00,$1080,$1F80,$0000
	 dc.w	$FFFF,$0000,$0000,$0000,$0000,$F03F,$0000,$0FC0,$0FC0,$0000
	 dc.w	$FFFF,$0000,$0000,$0000,$0000,$C00F,$03C0,$3C30,$3FF0,$0000
	 dc.w	$FFFF,$0000,$0000,$0000,$0000,$8007,$0420,$7818,$7FF8,$0000
	 dc.w	$FFFF,$0000,$0000,$0000,$0000,$0003,$0950,$F1CC,$FE3C,$0000
	 dc.w	$FFFF,$0000,$0000,$0000,$0000,$0003,$6AA8,$F364,$FC1C,$0000
	 dc.w	$FFFE,$0000,$0001,$0001,$0000,$0001,$69C8,$F2A6,$FC9E,$0080
	 dc.w	$FFFE,$0000,$0001,$0001,$0000,$0001,$6AA8,$F366,$FC1E,$0000
	 dc.w	$FFFE,$0000,$0001,$0001,$0000,$0001,$6948,$F1C6,$FE3E,$0000
	 dc.w	$FFFE,$0000,$0001,$0001,$0000,$0001,$6810,$F00E,$FFFE,$0000
	 dc.w	$FFFE,$0001,$0000,$0001,$0000,$0001,$6828,$F01E,$FFFE,$0000
	 dc.w	$FFFE,$0001,$0000,$0001,$0000,$0001,$37D0,$F83E,$FFFE,$0000
	 dc.w	$FFFF,$0000,$0000,$0000,$0000,$0003,$9830,$7FFC,$FFFC,$0000
	 dc.w	$FFFF,$0000,$0000,$0000,$0000,$0003,$9FE0,$7FFC,$FFFC,$0000
	 dc.w	$FFFF,$0000,$0000,$0000,$0000,$8007,$47C0,$3FF8,$7FF8,$0000
	 dc.w	$FFFF,$0000,$0000,$0000,$0000,$C00F,$3000,$0FF0,$3FF0,$0000
	 dc.w	$FFFF,$0000,$0000,$0000,$0000,$F03F,$0780,$0840,$0FC0,$0000


balldata1:
	DC.L	$F07F0000,$0F800F80,$0000FFFF,$00000000,$00000000,$C01F0440,$38203FE0,$0000FFFF
	DC.L	$00000000,$00000000,$800F0A80,$73B07C70,$0000FFFF,$00000000,$00000000,$800F2960
	DC.L	$72D07C30,$0000FFFF,$00000000,$00000000,$00072960,$F2D8FC38,$0000FFFF,$00000000
	DC.L	$00000000,$00072AA0,$F398FC78,$0000FFFF,$00000000,$00000000,$00072800,$F038FFF8
	DC.L	$0000FFFF,$00000000,$00000000,$0007B780,$7878FFF8,$0000FFFF,$00000000,$00000000
	DC.L	$800F5840,$3FF07FF0,$0000FFFF,$00000000,$00000000,$800F5FC0,$3FF07FF0,$0000FFFF
	DC.L	$00000000,$00000000,$C01F3000,$0FE03FE0,$0000FFFF,$00000000,$00000000,$F07F0700
	DC.L	$08800F80,$0000FFFF,$00000000,$00000000,$FFFF0000,$00000000,$0000FFFF,$00000000
	DC.L	$00000000,$FFFF0000,$00000000,$0000FFFF,$00000000,$00000000,$FFFF0000,$00000000
	DC.L	$0000FFFF,$00000000,$00000000,$FFFF0000,$00000000,$0000FFFF,$00000000,$00000000
	DC.L	$F83F0000,$07C007C0,$0000FFFF,$00000000,$00000000,$E00F0220,$1C101FF0,$0000FFFF
	DC.L	$00000000,$00000000,$C0070540,$39D83E38,$0000FFFF,$00000000,$00000000,$C00714B0
	DC.L	$39683E18,$0000FFFF,$00000000,$00000000,$800314B0,$796C7E1C,$0000FFFF,$00000000
	DC.L	$00000000,$80031550,$79CC7E3C,$0000FFFF,$00000000,$00000000,$80031400,$781C7FFC
	DC.L	$0000FFFF,$00000000,$00000000,$80035BC0,$3C3C7FFC,$0000FFFF,$00000000,$00000000
	DC.L	$C0072C20,$1FF83FF8,$0000FFFF,$00000000,$00000000,$C0072FE0,$1FF83FF8,$0000FFFF
	DC.L	$00000000,$00000000,$E00F1800,$07F01FF0,$0000FFFF,$00000000,$00000000,$F83F0380
	DC.L	$044007C0,$0000FFFF,$00000000,$00000000,$FFFF0000,$00000000,$0000FFFF,$00000000
	DC.L	$00000000,$FFFF0000,$00000000,$0000FFFF,$00000000,$00000000,$FFFF0000,$00000000
	DC.L	$0000FFFF,$00000000,$00000000,$FFFF0000,$00000000,$0000FFFF,$00000000,$00000000
	DC.L	$FC1F0000,$03E003E0,$0000FFFF,$00000000,$00000000,$F0070110,$0E080FF8,$0000FFFF
	DC.L	$00000000,$00000000,$E00302A0,$1CEC1F1C,$0000FFFF,$00000000,$00000000,$E0030A58
	DC.L	$1CB41F0C,$0000FFFF,$00000000,$00000000,$C0010A58,$3CB63F0E,$0000FFFF,$00000000
	DC.L	$00000000,$C0010AA8,$3CE63F1E,$0000FFFF,$00000000,$00000000,$C0010A00,$3C0E3FFE
	DC.L	$0000FFFF,$00000000,$00000000,$C0012DE0,$1E1E3FFE,$0000FFFF,$00000000,$00000000
	DC.L	$E0031610,$0FFC1FFC,$0000FFFF,$00000000,$00000000,$E00317F0,$0FFC1FFC,$0000FFFF
	DC.L	$00000000,$00000000,$F0070C00,$03F80FF8,$0000FFFF,$00000000,$00000000,$FC1F01C0
	DC.L	$022003E0,$0000FFFF,$00000000,$00000000,$FFFF0000,$00000000,$0000FFFF,$00000000
	DC.L	$00000000,$FFFF0000,$00000000,$0000FFFF,$00000000,$00000000,$FFFF0000,$00000000
	DC.L	$0000FFFF,$00000000,$00000000,$FFFF0000,$00000000,$0000FFFF,$00000000,$00000000
	DC.L	$FE0F0000,$01F001F0,$0000FFFF,$00000000,$00000000,$F8030088,$070407FC,$0000FFFF
	DC.L	$00000000,$00000000,$F0010150,$0E760F8E,$0000FFFF,$00000000,$00000000,$F001052C
	DC.L	$0E5A0F86,$0000FFFF,$00000000,$00000000,$E000052C,$1E5B1F87,$0000FFFF,$00000000
	DC.L	$00000000,$E0000554,$1E731F8F,$0000FFFF,$00000000,$00000000,$E0000500,$1E071FFF
	DC.L	$0000FFFF,$00000000,$00000000,$E00016F0,$0F0F1FFF,$0000FFFF,$00000000,$00000000
	DC.L	$F0010B08,$07FE0FFE,$0000FFFF,$00000000,$00000000,$F0010BF8,$07FE0FFE,$0000FFFF
	DC.L	$00000000,$00000000,$F8030600,$01FC07FC,$0000FFFF,$00000000,$00000000,$FE0F00E0
	DC.L	$011001F0,$0000FFFF,$00000000,$00000000,$FFFF0000,$00000000,$0000FFFF,$00000000
	DC.L	$00000000,$FFFF0000,$00000000,$0000FFFF,$00000000,$00000000,$FFFF0000,$00000000
	DC.L	$0000FFFF,$00000000,$00000000,$FFFF0000,$00000000,$0000FFFF,$00000000,$00000000
	DC.L	$FF070000,$00F800F8,$0000FFFF,$00000000,$00000000,$FC010044,$038203FE,$0000FFFF
	DC.L	$00000000,$00000000,$F80000A8,$073B07C7,$0000FFFF,$00000000,$00000000,$F8000296
	DC.L	$072D07C3,$0000FFFF,$00000000,$00000000,$F0000296,$0F2D0FC3,$00007FFF,$00008000
	DC.L	$80000000,$F00002AA,$0F390FC7,$00007FFF,$00008000,$80000000,$F0000280,$0F030FFF
	DC.L	$00007FFF,$00008000,$80000000,$F0000B78,$07870FFF,$00007FFF,$00008000,$80000000
	DC.L	$F8000584,$03FF07FF,$0000FFFF,$00000000,$00000000,$F80005FC,$03FF07FF,$0000FFFF
	DC.L	$00000000,$00000000,$FC010300,$00FE03FE,$0000FFFF,$00000000,$00000000,$FF070070
	DC.L	$008800F8,$0000FFFF,$00000000,$00000000,$FFFF0000,$00000000,$0000FFFF,$00000000
	DC.L	$00000000,$FFFF0000,$00000000,$0000FFFF,$00000000,$00000000,$FFFF0000,$00000000
	DC.L	$0000FFFF,$00000000,$00000000,$FFFF0000,$00000000,$0000FFFF,$00000000,$00000000
	DC.L	$FF830000,$007C007C,$0000FFFF,$00000000,$00000000,$FE000022,$01C101FF,$0000FFFF
	DC.L	$00000000,$00000000,$FC000054,$039D03E3,$00007FFF,$00008000,$80000000,$FC00014B
	DC.L	$039603E1,$00007FFF,$00008000,$80000000,$F800014B,$079607E1,$00003FFF,$0000C000
	DC.L	$C0000000,$F8000155,$079C07E3,$00003FFF,$0000C000,$C0000000,$F8000140,$078107FF
	DC.L	$00003FFF,$0000C000,$C0000000,$F80005BC,$03C307FF,$00003FFF,$0000C000,$C0000000
	DC.L	$FC0002C2,$01FF03FF,$00007FFF,$00008000,$80000000,$FC0002FE,$01FF03FF,$00007FFF
	DC.L	$00008000,$80000000,$FE000180,$007F01FF,$0000FFFF,$00000000,$00000000,$FF830038
	DC.L	$0044007C,$0000FFFF,$00000000,$00000000,$FFFF0000,$00000000,$0000FFFF,$00000000
	DC.L	$00000000,$FFFF0000,$00000000,$0000FFFF,$00000000,$00000000,$FFFF0000,$00000000
	DC.L	$0000FFFF,$00000000,$00000000,$FFFF0000,$00000000,$0000FFFF,$00000000,$00000000
	DC.L	$FFC10000,$003E003E,$0000FFFF,$00000000,$00000000,$FF000011,$00E000FF,$00007FFF
	DC.L	$00008000,$80000000,$FE00002A,$01CE01F1,$00003FFF,$0000C000,$C0000000,$FE0000A5
	DC.L	$01CB01F0,$00003FFF,$80004000,$C0000000,$FC0000A5,$03CB03F0,$00001FFF,$80006000
	DC.L	$E0000000,$FC0000AA,$03CE03F1,$00001FFF,$80006000,$E0000000,$FC0000A0,$03C003FF
	DC.L	$00001FFF,$0000E000,$E0000000,$FC0002DE,$01E103FF,$00001FFF,$0000E000,$E0000000
	DC.L	$FE000161,$00FF01FF,$00003FFF,$0000C000,$C0000000,$FE00017F,$00FF01FF,$00003FFF
	DC.L	$0000C000,$C0000000,$FF0000C0,$003F00FF,$00007FFF,$00008000,$80000000,$FFC1001C
	DC.L	$0022003E,$0000FFFF,$00000000,$00000000,$FFFF0000,$00000000,$0000FFFF,$00000000
	DC.L	$00000000,$FFFF0000,$00000000,$0000FFFF,$00000000,$00000000,$FFFF0000,$00000000
	DC.L	$0000FFFF,$00000000,$00000000,$FFFF0000,$00000000,$0000FFFF,$00000000,$00000000
	DC.L	$FFE00000,$001F001F,$0000FFFF,$00000000,$00000000,$FF800008,$0070007F,$00003FFF
	DC.L	$80004000,$C0000000,$FF000015,$00E700F8,$00001FFF,$00006000,$E0000000,$FF000052
	DC.L	$00E500F8,$00001FFF,$C000A000,$60000000,$FE000052,$01E501F8,$00000FFF,$C000B000
	DC.L	$70000000,$FE000055,$01E701F8,$00000FFF,$40003000,$F0000000,$FE000050,$01E001FF
	DC.L	$00000FFF,$00007000,$F0000000,$FE00016F,$00F001FF,$00000FFF,$0000F000,$F0000000
	DC.L	$FF0000B0,$007F00FF,$00001FFF,$8000E000,$E0000000,$FF0000BF,$007F00FF,$00001FFF
	DC.L	$8000E000,$E0000000,$FF800060,$001F007F,$00003FFF,$0000C000,$C0000000,$FFE0000E
	DC.L	$0011001F,$0000FFFF,$00000000,$00000000,$FFFF0000,$00000000,$0000FFFF,$00000000
	DC.L	$00000000,$FFFF0000,$00000000,$0000FFFF,$00000000,$00000000,$FFFF0000,$00000000
	DC.L	$0000FFFF,$00000000,$00000000,$FFFF0000,$00000000,$0000FFFF,$00000000,$00000000
	DC.L	$FFF00000,$000F000F,$00007FFF,$00008000,$80000000,$FFC00004,$0038003F,$00001FFF
	DC.L	$40002000,$E0000000,$FF80000A,$0073007C,$00000FFF,$8000B000,$70000000,$FF800029
	DC.L	$0072007C,$00000FFF,$6000D000,$30000000,$FF000029,$00F200FC,$000007FF,$6000D800
	DC.L	$38000000,$FF00002A,$00F300FC,$000007FF,$A0009800,$78000000,$FF000028,$00F000FF
	DC.L	$000007FF,$00003800,$F8000000,$FF0000B7,$007800FF,$000007FF,$80007800,$F8000000
	DC.L	$FF800058,$003F007F,$00000FFF,$4000F000,$F0000000,$FF80005F,$003F007F,$00000FFF
	DC.L	$C000F000,$F0000000,$FFC00030,$000F003F,$00001FFF,$0000E000,$E0000000,$FFF00007
	DC.L	$0008000F,$00007FFF,$00008000,$80000000,$FFFF0000,$00000000,$0000FFFF,$00000000
	DC.L	$00000000,$FFFF0000,$00000000,$0000FFFF,$00000000,$00000000,$FFFF0000,$00000000
	DC.L	$0000FFFF,$00000000,$00000000,$FFFF0000,$00000000,$0000FFFF,$00000000,$00000000
	DC.L	$FFF80000,$00070007,$00003FFF,$0000C000,$C0000000,$FFE00002,$001C001F,$00000FFF
	DC.L	$20001000,$F0000000,$FFC00005,$0039003E,$000007FF,$4000D800,$38000000,$FFC00014
	DC.L	$0039003E,$000007FF,$B0006800,$18000000,$FF800014,$0079007E,$000003FF,$B0006C00
	DC.L	$1C000000,$FF800015,$0079007E,$000003FF,$5000CC00,$3C000000,$FF800014,$0078007F
	DC.L	$000003FF,$00001C00,$FC000000,$FF80005B,$003C007F,$000003FF,$C0003C00,$FC000000
	DC.L	$FFC0002C,$001F003F,$000007FF,$2000F800,$F8000000,$FFC0002F,$001F003F,$000007FF
	DC.L	$E000F800,$F8000000,$FFE00018,$0007001F,$00000FFF,$0000F000,$F0000000,$FFF80003
	DC.L	$00040007,$00003FFF,$80004000,$C0000000,$FFFF0000,$00000000,$0000FFFF,$00000000
	DC.L	$00000000,$FFFF0000,$00000000,$0000FFFF,$00000000,$00000000,$FFFF0000,$00000000
	DC.L	$0000FFFF,$00000000,$00000000,$FFFF0000,$00000000,$0000FFFF,$00000000,$00000000
	DC.L	$FFFC0000,$00030003,$00001FFF,$0000E000,$E0000000,$FFF00001,$000E000F,$000007FF
	DC.L	$10000800,$F8000000,$FFE00002,$001C001F,$000003FF,$A000EC00,$1C000000,$FFE0000A
	DC.L	$001C001F,$000003FF,$5800B400,$0C000000,$FFC0000A,$003C003F,$000001FF,$5800B600
	DC.L	$0E000000,$FFC0000A,$003C003F,$000001FF,$A800E600,$1E000000,$FFC0000A,$003C003F
	DC.L	$000001FF,$00000E00,$FE000000,$FFC0002D,$001E003F,$000001FF,$E0001E00,$FE000000
	DC.L	$FFE00016,$000F001F,$000003FF,$1000FC00,$FC000000,$FFE00017,$000F001F,$000003FF
	DC.L	$F000FC00,$FC000000,$FFF0000C,$0003000F,$000007FF,$0000F800,$F8000000,$FFFC0001
	DC.L	$00020003,$00001FFF,$C0002000,$E0000000,$FFFF0000,$00000000,$0000FFFF,$00000000
	DC.L	$00000000,$FFFF0000,$00000000,$0000FFFF,$00000000,$00000000,$FFFF0000,$00000000
	DC.L	$0000FFFF,$00000000,$00000000,$FFFF0000,$00000000,$0000FFFF,$00000000,$00000000
	DC.L	$FFFE0000,$00010001,$00000FFF,$0000F000,$F0000000,$FFF80000,$00070007,$000003FF
	DC.L	$88000400,$FC000000,$FFF00001,$000E000F,$000001FF,$50007600,$8E000000,$FFF00005
	DC.L	$000E000F,$000001FF,$2C005A00,$86000000,$FFE00005,$001E001F,$000000FF,$2C005B00
	DC.L	$87000000,$FFE00005,$001E001F,$000000FF,$54007300,$8F000000,$FFE00005,$001E001F
	DC.L	$000000FF,$00000700,$FF000000,$FFE00016,$000F001F,$000000FF,$F0000F00,$FF000000
	DC.L	$FFF0000B,$0007000F,$000001FF,$0800FE00,$FE000000,$FFF0000B,$0007000F,$000001FF
	DC.L	$F800FE00,$FE000000,$FFF80006,$00010007,$000003FF,$0000FC00,$FC000000,$FFFE0000
	DC.L	$00010001,$00000FFF,$E0001000,$F0000000,$FFFF0000,$00000000,$0000FFFF,$00000000
	DC.L	$00000000,$FFFF0000,$00000000,$0000FFFF,$00000000,$00000000,$FFFF0000,$00000000
	DC.L	$0000FFFF,$00000000,$00000000,$FFFF0000,$00000000,$0000FFFF,$00000000,$00000000
	DC.L	$FFFF0000,$00000000,$000007FF,$0000F800,$F8000000,$FFFC0000,$00030003,$000001FF
	DC.L	$44008200,$FE000000,$FFF80000,$00070007,$000000FF,$A8003B00,$C7000000,$FFF80002
	DC.L	$00070007,$000000FF,$96002D00,$C3000000,$FFF00002,$000F000F,$0000007F,$96002D80
	DC.L	$C3800000,$FFF00002,$000F000F,$0000007F,$AA003980,$C7800000,$FFF00002,$000F000F
	DC.L	$0000007F,$80000380,$FF800000,$FFF0000B,$0007000F,$0000007F,$78008780,$FF800000
	DC.L	$FFF80005,$00030007,$000000FF,$8400FF00,$FF000000,$FFF80005,$00030007,$000000FF
	DC.L	$FC00FF00,$FF000000,$FFFC0003,$00000003,$000001FF,$0000FE00,$FE000000,$FFFF0000
	DC.L	$00000000,$000007FF,$70008800,$F8000000,$FFFF0000,$00000000,$0000FFFF,$00000000
	DC.L	$00000000,$FFFF0000,$00000000,$0000FFFF,$00000000,$00000000,$FFFF0000,$00000000
	DC.L	$0000FFFF,$00000000,$00000000,$FFFF0000,$00000000,$0000FFFF,$00000000,$00000000
	DC.L	$FFFF0000,$00000000,$000083FF,$00007C00,$7C000000,$FFFE0000,$00010001,$000000FF
	DC.L	$2200C100,$FF000000,$FFFC0000,$00030003,$0000007F,$54009D80,$E3800000,$FFFC0001
	DC.L	$00030003,$0000007F,$4B009680,$E1800000,$FFF80001,$00070007,$0000003F,$4B0096C0
	DC.L	$E1C00000,$FFF80001,$00070007,$0000003F,$55009CC0,$E3C00000,$FFF80001,$00070007
	DC.L	$0000003F,$400081C0,$FFC00000,$FFF80005,$00030007,$0000003F,$BC00C3C0,$FFC00000
	DC.L	$FFFC0002,$00010003,$0000007F,$C200FF80,$FF800000,$FFFC0002,$00010003,$0000007F
	DC.L	$FE00FF80,$FF800000,$FFFE0001,$00000001,$000000FF,$80007F00,$FF000000,$FFFF0000
	DC.L	$00000000,$000083FF,$38004400,$7C000000,$FFFF0000,$00000000,$0000FFFF,$00000000
	DC.L	$00000000,$FFFF0000,$00000000,$0000FFFF,$00000000,$00000000,$FFFF0000,$00000000
	DC.L	$0000FFFF,$00000000,$00000000,$FFFF0000,$00000000,$0000FFFF,$00000000,$00000000
	DC.L	$FFFF0000,$00000000,$0000C1FF,$00003E00,$3E000000,$FFFF0000,$00000000,$0000007F
	DC.L	$1100E080,$FF800000,$FFFE0000,$00010001,$0000003F,$2A00CEC0,$F1C00000,$FFFE0000
	DC.L	$00010001,$0000003F,$A580CB40,$F0C00000,$FFFC0000,$00030003,$0000001F,$A580CB60
	DC.L	$F0E00000,$FFFC0000,$00030003,$0000001F,$AA80CE60,$F1E00000,$FFFC0000,$00030003
	DC.L	$0000001F,$A000C0E0,$FFE00000,$FFFC0002,$00010003,$0000001F,$DE00E1E0,$FFE00000
	DC.L	$FFFE0001,$00000001,$0000003F,$6100FFC0,$FFC00000,$FFFE0001,$00000001,$0000003F
	DC.L	$7F00FFC0,$FFC00000,$FFFF0000,$00000000,$0000007F,$C0003F80,$FF800000,$FFFF0000
	DC.L	$00000000,$0000C1FF,$1C002200,$3E000000,$FFFF0000,$00000000,$0000FFFF,$00000000
	DC.L	$00000000,$FFFF0000,$00000000,$0000FFFF,$00000000,$00000000,$FFFF0000,$00000000
	DC.L	$0000FFFF,$00000000,$00000000,$FFFF0000,$00000000,$0000FFFF,$00000000,$00000000
	DC.L	$FFFF0000,$00000000,$0000E0FF,$00001F00,$1F000000,$FFFF0000,$00000000,$0000803F
	DC.L	$08807040,$7FC00000,$FFFF0000,$00000000,$0000001F,$1500E760,$F8E00000,$FFFF0000
	DC.L	$00000000,$0000001F,$52C0E5A0,$F8600000,$FFFE0000,$00010001,$0000000F,$52C0E5B0
	DC.L	$F8700000,$FFFE0000,$00010001,$0000000F,$5540E730,$F8F00000,$FFFE0000,$00010001
	DC.L	$0000000F,$5000E070,$FFF00000,$FFFE0001,$00000001,$0000000F,$6F00F0F0,$FFF00000
	DC.L	$FFFF0000,$00000000,$0000001F,$B0807FE0,$FFE00000,$FFFF0000,$00000000,$0000001F
	DC.L	$BF807FE0,$FFE00000,$FFFF0000,$00000000,$0000803F,$60001FC0,$7FC00000,$FFFF0000
	DC.L	$00000000,$0000E0FF,$0E001100,$1F000000,$FFFF0000,$00000000,$0000FFFF,$00000000
	DC.L	$00000000,$FFFF0000,$00000000,$0000FFFF,$00000000,$00000000,$FFFF0000,$00000000
	DC.L	$0000FFFF,$00000000,$00000000,$FFFF0000,$00000000,$0000FFFF,$00000000,$00000000

balldata0:
	DC.L	$C3FF0800,$34003C00,$0000FFFF,$00000000,$00000000,$81FF0000,$6A007600,$0000FFFF
	DC.L	$00000000,$00000000,$00FF4A00,$F500E300,$0000FFFF,$00000000,$00000000,$00FF4600
	DC.L	$ED00F300,$0000FFFF,$00000000,$00000000,$00FF7800,$E700FF00,$0000FFFF,$00000000
	DC.L	$00000000,$00FFA400,$7F00FF00,$0000FFFF,$00000000,$00000000,$81FF1800,$7E007E00
	DC.L	$0000FFFF,$00000000,$00000000,$C3FF1000,$2C003C00,$0000FFFF,$00000000,$00000000
	DC.L	$E1FF0400,$1A001E00,$0000FFFF,$00000000,$00000000,$C0FF0000,$35003B00,$0000FFFF
	DC.L	$00000000,$00000000,$807F2500,$7A807180,$0000FFFF,$00000000,$00000000,$807F2300
	DC.L	$76807980,$0000FFFF,$00000000,$00000000,$807F3C00,$73807F80,$0000FFFF,$00000000
	DC.L	$00000000,$807F5200,$3F807F80,$0000FFFF,$00000000,$00000000,$C0FF0C00,$3F003F00
	DC.L	$0000FFFF,$00000000,$00000000,$E1FF0800,$16001E00,$0000FFFF,$00000000,$00000000
	DC.L	$F0FF0200,$0D000F00,$0000FFFF,$00000000,$00000000,$E07F0000,$1A801D80,$0000FFFF
	DC.L	$00000000,$00000000,$C03F1280,$3D4038C0,$0000FFFF,$00000000,$00000000,$C03F1180
	DC.L	$3B403CC0,$0000FFFF,$00000000,$00000000,$C03F1E00,$39C03FC0,$0000FFFF,$00000000
	DC.L	$00000000,$C03F2900,$1FC03FC0,$0000FFFF,$00000000,$00000000,$E07F0600,$1F801F80
	DC.L	$0000FFFF,$00000000,$00000000,$F0FF0400,$0B000F00,$0000FFFF,$00000000,$00000000
	DC.L	$F87F0100,$06800780,$0000FFFF,$00000000,$00000000,$F03F0000,$0D400EC0,$0000FFFF
	DC.L	$00000000,$00000000,$E01F0940,$1EA01C60,$0000FFFF,$00000000,$00000000,$E01F08C0
	DC.L	$1DA01E60,$0000FFFF,$00000000,$00000000,$E01F0F00,$1CE01FE0,$0000FFFF,$00000000
	DC.L	$00000000,$E01F1480,$0FE01FE0,$0000FFFF,$00000000,$00000000,$F03F0300,$0FC00FC0
	DC.L	$0000FFFF,$00000000,$00000000,$F87F0200,$05800780,$0000FFFF,$00000000,$00000000
	DC.L	$FC3F0080,$034003C0,$0000FFFF,$00000000,$00000000,$F81F0000,$06A00760,$0000FFFF
	DC.L	$00000000,$00000000,$F00F04A0,$0F500E30,$0000FFFF,$00000000,$00000000,$F00F0460
	DC.L	$0ED00F30,$0000FFFF,$00000000,$00000000,$F00F0780,$0E700FF0,$0000FFFF,$00000000
	DC.L	$00000000,$F00F0A40,$07F00FF0,$0000FFFF,$00000000,$00000000,$F81F0180,$07E007E0
	DC.L	$0000FFFF,$00000000,$00000000,$FC3F0100,$02C003C0,$0000FFFF,$00000000,$00000000
	DC.L	$FE1F0040,$01A001E0,$0000FFFF,$00000000,$00000000,$FC0F0000,$035003B0,$0000FFFF
	DC.L	$00000000,$00000000,$F8070250,$07A80718,$0000FFFF,$00000000,$00000000,$F8070230
	DC.L	$07680798,$0000FFFF,$00000000,$00000000,$F80703C0,$073807F8,$0000FFFF,$00000000
	DC.L	$00000000,$F8070520,$03F807F8,$0000FFFF,$00000000,$00000000,$FC0F00C0,$03F003F0
	DC.L	$0000FFFF,$00000000,$00000000,$FE1F0080,$016001E0,$0000FFFF,$00000000,$00000000
	DC.L	$FF0F0020,$00D000F0,$0000FFFF,$00000000,$00000000,$FE070000,$01A801D8,$0000FFFF
	DC.L	$00000000,$00000000,$FC030128,$03D4038C,$0000FFFF,$00000000,$00000000,$FC030118
	DC.L	$03B403CC,$0000FFFF,$00000000,$00000000,$FC0301E0,$039C03FC,$0000FFFF,$00000000
	DC.L	$00000000,$FC030290,$01FC03FC,$0000FFFF,$00000000,$00000000,$FE070060,$01F801F8
	DC.L	$0000FFFF,$00000000,$00000000,$FF0F0040,$00B000F0,$0000FFFF,$00000000,$00000000
	DC.L	$FF870010,$00680078,$0000FFFF,$00000000,$00000000,$FF030000,$00D400EC,$0000FFFF
	DC.L	$00000000,$00000000,$FE010094,$01EA01C6,$0000FFFF,$00000000,$00000000,$FE01008C
	DC.L	$01DA01E6,$0000FFFF,$00000000,$00000000,$FE0100F0,$01CE01FE,$0000FFFF,$00000000
	DC.L	$00000000,$FE010148,$00FE01FE,$0000FFFF,$00000000,$00000000,$FF030030,$00FC00FC
	DC.L	$0000FFFF,$00000000,$00000000,$FF870020,$00580078,$0000FFFF,$00000000,$00000000
	DC.L	$FFC30008,$0034003C,$0000FFFF,$00000000,$00000000,$FF810000,$006A0076,$0000FFFF
	DC.L	$00000000,$00000000,$FF00004A,$00F500E3,$0000FFFF,$00000000,$00000000,$FF000046
	DC.L	$00ED00F3,$0000FFFF,$00000000,$00000000,$FF000078,$00E700FF,$0000FFFF,$00000000
	DC.L	$00000000,$FF0000A4,$007F00FF,$0000FFFF,$00000000,$00000000,$FF810018,$007E007E
	DC.L	$0000FFFF,$00000000,$00000000,$FFC30010,$002C003C,$0000FFFF,$00000000,$00000000
	DC.L	$FFE10004,$001A001E,$0000FFFF,$00000000,$00000000,$FFC00000,$0035003B,$0000FFFF
	DC.L	$00000000,$00000000,$FF800025,$007A0071,$00007FFF,$00008000,$80000000,$FF800023
	DC.L	$00760079,$00007FFF,$00008000,$80000000,$FF80003C,$0073007F,$00007FFF,$00008000
	DC.L	$80000000,$FF800052,$003F007F,$00007FFF,$00008000,$80000000,$FFC0000C,$003F003F
	DC.L	$0000FFFF,$00000000,$00000000,$FFE10008,$0016001E,$0000FFFF,$00000000,$00000000
	DC.L	$FFF00002,$000D000F,$0000FFFF,$00000000,$00000000,$FFE00000,$001A001D,$00007FFF
	DC.L	$00008000,$80000000,$FFC00012,$003D0038,$00003FFF,$80004000,$C0000000,$FFC00011
	DC.L	$003B003C,$00003FFF,$80004000,$C0000000,$FFC0001E,$0039003F,$00003FFF,$0000C000
	DC.L	$C0000000,$FFC00029,$001F003F,$00003FFF,$0000C000,$C0000000,$FFE00006,$001F001F
	DC.L	$00007FFF,$00008000,$80000000,$FFF00004,$000B000F,$0000FFFF,$00000000,$00000000
	DC.L	$FFF80001,$00060007,$00007FFF,$00008000,$80000000,$FFF00000,$000D000E,$00003FFF
	DC.L	$00004000,$C0000000,$FFE00009,$001E001C,$00001FFF,$4000A000,$60000000,$FFE00008
	DC.L	$001D001E,$00001FFF,$C000A000,$60000000,$FFE0000F,$001C001F,$00001FFF,$0000E000
	DC.L	$E0000000,$FFE00014,$000F001F,$00001FFF,$8000E000,$E0000000,$FFF00003,$000F000F
	DC.L	$00003FFF,$0000C000,$C0000000,$FFF80002,$00050007,$00007FFF,$00008000,$80000000
	DC.L	$FFFC0000,$00030003,$00003FFF,$80004000,$C0000000,$FFF80000,$00060007,$00001FFF
	DC.L	$0000A000,$60000000,$FFF00004,$000F000E,$00000FFF,$A0005000,$30000000,$FFF00004
	DC.L	$000E000F,$00000FFF,$6000D000,$30000000,$FFF00007,$000E000F,$00000FFF,$80007000
	DC.L	$F0000000,$FFF0000A,$0007000F,$00000FFF,$4000F000,$F0000000,$FFF80001,$00070007
	DC.L	$00001FFF,$8000E000,$E0000000,$FFFC0001,$00020003,$00003FFF,$0000C000,$C0000000
	DC.L	$FFFE0000,$00010001,$00001FFF,$4000A000,$E0000000,$FFFC0000,$00030003,$00000FFF
	DC.L	$00005000,$B0000000,$FFF80002,$00070007,$000007FF,$5000A800,$18000000,$FFF80002
	DC.L	$00070007,$000007FF,$30006800,$98000000,$FFF80003,$00070007,$000007FF,$C0003800
	DC.L	$F8000000,$FFF80005,$00030007,$000007FF,$2000F800,$F8000000,$FFFC0000,$00030003
	DC.L	$00000FFF,$C000F000,$F0000000,$FFFE0000,$00010001,$00001FFF,$80006000,$E0000000
	DC.L	$FFFF0000,$00000000,$00000FFF,$2000D000,$F0000000,$FFFE0000,$00010001,$000007FF
	DC.L	$0000A800,$D8000000,$FFFC0001,$00030003,$000003FF,$2800D400,$8C000000,$FFFC0001
	DC.L	$00030003,$000003FF,$1800B400,$CC000000,$FFFC0001,$00030003,$000003FF,$E0009C00
	DC.L	$FC000000,$FFFC0002,$00010003,$000003FF,$9000FC00,$FC000000,$FFFE0000,$00010001
	DC.L	$000007FF,$6000F800,$F8000000,$FFFF0000,$00000000,$00000FFF,$4000B000,$F0000000
	DC.L	$FFFF0000,$00000000,$000087FF,$10006800,$78000000,$FFFF0000,$00000000,$000003FF
	DC.L	$0000D400,$EC000000,$FFFE0000,$00010001,$000001FF,$9400EA00,$C6000000,$FFFE0000
	DC.L	$00010001,$000001FF,$8C00DA00,$E6000000,$FFFE0000,$00010001,$000001FF,$F000CE00
	DC.L	$FE000000,$FFFE0001,$00000001,$000001FF,$4800FE00,$FE000000,$FFFF0000,$00000000
	DC.L	$000003FF,$3000FC00,$FC000000,$FFFF0000,$00000000,$000087FF,$20005800,$78000000


keybuf:	dc.l	0
unitheta:	 dc.w	0
uniphi:		 dc.w	0
unirho:		 dc.w	0
uniz:		 dc.w	0
unix:		 dc.w	0
uniy:		 dc.w	0
zinc:		 dc.w	0
stacksave:	dc.l	0
clrbuffseen:	dc.l	0
clrbuffhiden:	dc.l	0
soundstart:	dc.l	0
soundend:	dc.l	0
text:
	incbin	'text1.dat'
	ds.l	1000
	section	bss
starsm:		ds.l	numstars*3
freespace:ds.b 644
movie:
	ds.b	900000

