
start:  clr.l   -(SP)           ;Go into supervisor mode
        move.w  #$20,-(SP)
        trap    #1
        addq.l  #6,SP
        move.l  D0,spv_sp
	move.b	#0,$484

	move.l	#$31415926,$426	;set reset vector valid
	move.l	#myreset,$42a
	move.w	#4,-(sp)
	trap	#14
	addq.l	#2,sp
	move.w	d0,ressave


	move.w	#0,-(sp)	;set to low res
	move.l	#-1,-(sp)
	move.l	#-1,-(sp)
	move.w	#5,-(sp)
	trap	#14
	add.l	#12,sp


        jsr     mousof
	jsr	joystuff
        jsr     getscrn
	jsr	plotinit
        jsr     linea
        move.w  #10,d0
        jsr     randomseed
*	bsr	prestuff	;prerotate some sprites matey

	lea	joydir,a0
	jsr	putvbl
	move.l	a1,oldvbl1
	move.l	#land1palette,temppal
	bsr	docolors

************************************************
*********************************
*	stars demo       	*
*********************************
inc:		equ	0
magic:		equ	550
buttondat:	equ	$26e6
mx:		equ	$26e0
my:		equ	$26e2
tall:		equ	15
yadj:		equ	50
xadj:		equ	200

ftf:
	move.w	#-6,minusvel
	move.w	#6,plusvel
	bsr	loadscreen
	bsr	copyintoboth
	bsr	putfirst
	bsr	ramware

test:
	bsr	clearfast
	bsr	downcount
	bsr	calcpoints
	bsr	drawsquares
	bsr	keyboard
	bsr	flip2
	addq.w	#1,score
	bra	test
	
counter:	blk.w	1,0


cint:
	addq.w	#1,counter
	cmpi.w	#50,counter
	blt	cintback
	bsr	printscore
	move.w	#0,counter
	move.w	#0,score

cintback:
	rts


putfirst:
	lea	points1,a0	;the first plane of points
	move.w	#1000,z1		;originally furthest away
	bsr	putpoints

	lea	points2,a0	;the first plane of points
	move.w	#800,z2		;originally furthest away
	bsr	putpoints

	lea	points3,a0	;the first plane of points
	move.w	#600,z3		;originally furthest away
	bsr	putpoints

	lea	points4,a0	;the first plane of points
	move.w	#400,z4		;originally furthest away
	bsr	putpoints
	rts

putpoints:
	move.w	#-200,(a0)+	;X-first in row is extreme left
	move.w	#-150,(a0)+	;Y-random value
	move.w	#-50,(a0)+	;X-first in row is extreme left
	move.w	#-50,(a0)+	;Y-random value

	move.w	#50,(a0)+	;X-first in row is extreme left
	move.w	#-150,(a0)+	;Y-random value
	move.w	#200,(a0)+	;X-first in row is extreme left
	move.w	#-50,(a0)+	;Y-random value

	move.w	#-200,(a0)+	;X-first in row is extreme left
	move.w	#50,(a0)+	;Y-random value
	move.w	#-50,(a0)+	;X-first in row is extreme left
	move.w	#150,(a0)+	;Y-random value

	move.w	#50,(a0)+	;X-first in row is extreme left
	move.w	#50,(a0)+	;Y-random value
	move.w	#200,(a0)+	;X-first in row is extreme left
	move.w	#150,(a0)+	;Y-random value
	rts

opoints1:	blk.w	56,0
opoints2:	blk.w	56,0
opoints3:	blk.w	56,0
opoints4:	blk.w	56,0
points1:	blk.w	56,0
points2:	blk.w	56,0
points3:	blk.w	56,0
points4:	blk.w	56,0
z1:		blk.w	1,0
z2:		blk.w	1,0
z3:		blk.w	1,0
z4:		blk.w	1,0
pflag1:		blk.w	1,0
pflag2:		blk.w	1,0
pflag3:		blk.w	1,0
pflag4:		blk.w	1,0

calcpoints:
	move.l	#z1,a1
	move.l	#points1,a0	;x-y-z
	move.l	#opoints1,a6	;onscreen x and y
	move.l	#pflag1,a2
	bsr	cp2
	move.l	#z2,a1
	move.l	#points2,a0	;x-y-z
	move.l	#opoints2,a6	;onscreen x and y
	move.l	#pflag2,a2
	bsr	cp2
	move.l	#z3,a1
	move.l	#points3,a0	;x-y-z
	move.l	#opoints3,a6	;onscreen x and y
	move.l	#pflag3,a2
	bsr	cp2
	move.l	#z4,a1
	move.l	#points4,a0	;x-y-z
	move.l	#opoints4,a6	;onscreen x and y
	move.l	#pflag4,a2
	bsr	cp2
	rts

cp2:
	move.w	updown,d0
	sub.w	d0,(a1)
	cmpi.w	#400,(a1)	;is it too near
	bgt	cp3		;if not carry on
	move.w	#-1,(a2)	;and make it furthest away
	bra	cpt
cp3:
	move.w	#1,(a2)	
cpt:	move.w	#7,d7		;calc 8 point pairs
cpl:
	move.w	down2,d2
	add.w	d2,(a0)		;move down screen
	move.l	#0,d0
	move.w	(a0)+,d0	;get x
	muls	#magic,d0	;mult by perspective
	divs	(a1),d0		;div by z
	add.w	#xadj,d0	;adjust for centre
	move.w	d0,(a6)+	;move x into onscreen co-ord list
	move.w	down,d1
	add.w	d1,(a0)		;move down screen
	move.l	#0,d0
	move.w	(a0)+,d0	;get y
	muls	#magic,d0	;mult by perspective value
	divs	(a1),d0		;div by z	
	add.w	#yadj,d0	;adjust for centre
	move.w	d0,(a6)+	;move y into onscreen co-ord list
	move.w	down2,d2
	add.w	d2,(a0)		;move down screen
	move.l	#0,d0
	move.w	(a0)+,d0	;get x
	muls	#magic,d0	;mult by perspective
	divs	(a1),d0		;div by z
	add.w	#xadj,d0	;adjust for centre
	move.w	d0,(a6)+	;move x into onscreen co-ord list
	move.w	down,d1
	add.w	d1,(a0)		;move down screen
	move.l	#0,d0
	move.w	(a0)+,d0	;get y
	muls	#magic,d0	;mult by perspective value
	divs	(a1),d0		;div by z	
	add.w	#yadj,d0	;adjust for centre
	move.w	d0,(a6)+	;move y into onscreen co-ord list
	dbf	d7,cpl
	rts

downcount:
	move.w	myxvel,down2
	move.w	myyvel,down
	rts

	addq.w	#8,downbig
	move.w	downbig,d0
	asr.w	#2,d0
	move.w	d0,down
	tst.w	d0
	ble	dcback
	move.w	#0,downbig
dcback:
	rts
	addq.w	#8,downbig2
	move.w	downbig2,d0
	asr.w	#1,d0
	move.w	d0,down2
	tst.w	d0
	ble	dcback2
	move.w	#0,downbig2
dcback2:
	rts


down:	blk.w	1,0
downbig:
	blk.w	1,0
down2:	blk.w	1,0
downbig2:
	blk.w	1,0
****************************************
drawpoints:
*	lea	sortlist,a6
	move.w	#7,pixelcolor
	move.w	#4,d7
dp:
	move.l	(a6)+,a0
*	move.l	#opoints1,a0
	move.w	(a0)+,pixelx
	move.w	(a0)+,pixely
	bsr	myplot
	move.w	(a0)+,pixelx
	move.w	(a0)+,pixely
	bsr	myplot
	move.w	(a0)+,pixelx
	move.w	(a0)+,pixely
	bsr	myplot
	move.w	(a0)+,pixelx
	move.w	(a0)+,pixely
	bsr	myplot
	move.w	(a0)+,pixelx
	move.w	(a0)+,pixely
	bsr	myplot
	dbf	d7,dp
	rts

drawsquares:
	move.l	linepar,a5	;set up necessary params
	move.w	#0,36(a5)	;wrtmode
	move.l	#patmsk,46(a5)
	move.w	#0,50(a5)
	move.w	#1,54(a5)
	move.w	#96,56(a5)	;xmin for clip
	move.w	#10,58(a5)	;ymin for clip
	move.w	#303,60(a5)	;xmax for clip
	move.w	#100,62(a5)	;ymax for clip

	tst.w	pflag1
	bmi	s2
	move.l	#opoints1,a6
	move.w	#1,24(a5)	;planes
	move.w	#0,26(a5)
	move.w	#0,28(a5)
	move.w	#0,30(a5)
	bsr	dsl
s2:
	tst.w	pflag2
	bmi	s3
	move.l	#opoints2,a6
	move.w	#0,24(a5)	;planes
	move.w	#1,26(a5)
	move.w	#0,28(a5)
	move.w	#0,30(a5)
	bsr	dsl

s3:	tst.w	pflag3
	bmi	s4
	move.l	#opoints3,a6
	move.w	#1,24(a5)	;planes
	move.w	#1,26(a5)
	move.w	#0,28(a5)
	move.w	#0,30(a5)
	bsr	dsl

s4:	tst.w	pflag4
	bmi	s5
	move.l	#opoints4,a6
	move.w	#0,24(a5)	;planes
	move.w	#0,26(a5)
	move.w	#1,28(a5)
	move.w	#0,30(a5)
	bsr	dsl
s5:	rts

dsl:
	move.w	(a6)+,38(a5)	;x1
	move.w	(a6)+,40(a5)	;y1
	move.w	(a6)+,42(a5)	;x2
	move.w	(a6)+,44(a5)	;y2
	dc.w	$a005
	move.w	(a6)+,38(a5)	;x1
	move.w	(a6)+,40(a5)	;y1
	move.w	(a6)+,42(a5)	;x2
	move.w	(a6)+,44(a5)	;y2
	dc.w	$a005
	move.w	(a6)+,38(a5)	;x1
	move.w	(a6)+,40(a5)	;y1
	move.w	(a6)+,42(a5)	;x2
	move.w	(a6)+,44(a5)	;y2
	dc.w	$a005
	move.w	(a6)+,38(a5)	;x1
	move.w	(a6)+,40(a5)	;y1
	move.w	(a6)+,42(a5)	;x2
	move.w	(a6)+,44(a5)	;y2
	dc.w	$a005
	rts



patmsk:	dc.w	$ffff
cxmin:		equ	96
cxmax:		equ	302
cymin:		equ	10
cymax:		equ	188
cbits:	blk.w	1,0
cbits2:	blk.w	1,0
xsav:	blk.w	1,0
ysav:	blk.w	1,0
*dx:	blk.w	1,0
*dy:	blk.w	1,0
*/**//*/*//*//*/*//*//*/*/*//*/*/*/*//*/*/*/*//*//*//*///*/*/
bitcode:clr.l   d4
        cmpi.w  #cxmin,d0
        bge     b1
        or.b    #8,d4
b1:     cmpi.w  #cxmax,d0
        ble     b2
        or.b    #4,d4
b2:     cmpi.w  #cymin,d1
        bge     b3
        or.b    #1,d4
b3:     cmpi.w  #cymax,d1
        ble     b4
        or.b    #2,d4
b4:     move.w  d4,cbits
        rts
*****
bitc2:   clr.l   d5
        cmpi.w  #cxmin,d2
        bge     b5
        or.b    #8,d5
b5:     cmpi.w  #cxmax,d2
        ble     b6
        or.b    #4,d5
b6:     cmpi.w  #cymin,d3
        bge     b7
        or.b    #1,d5
b7:     cmpi.w  #cymax,d3
        ble     b8
        or.b    #2,d5
b8:     move.w  d5,cbits2
        rts
********************************************************
clipit:
	move.w	d7,-(sp)
	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
*       bra     cliploop        
cc4:    bsr     bitc2
        bra     cliploop

cliploop:
        bra     clipit2
cliphome:
*        move.l  linepar,a0
        move.w  d0,x1
        move.w  d1,y1
        move.w  d2,x2
        move.w  d3,y2
	bsr	myline
clipb:
	move.w	(sp)+,d7
	rts
*********************************************************
linecolor:
	blk.w	1,0
***********************************************
*	lets plot a fucking line
*	but lets do it fast
*	first some conventions
*	draws line on hiden screen
*	between x1,y1,x2,y2 
***********************************************
myline:
	movem.l	d4-d7/a0,-(sp)
calcdx:
	move.w	x2,d0
	sub.w	x1,d0	;x2-x1
	move.w	d0,dx	;d0 is dx
	bpl	calcdy
	neg	d0
calcdy:
	move.w	y2,d1
	sub.w	y1,d1	;y2-y1	
	move.w	d1,dy	;d6 is dy
	bpl	cmparedxdy
	neg	d1
cmparedxdy:
	cmp.w	d0,d1
	bgt	ymajor	;if dy is greater then ymajor
xmajor:
	tst.w	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:
	move.l	#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
	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

xmnloop:
	addq.w	#1,d2
	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:
	dbf	d7,xmnloop
	move.w	d2,d3
	and.w	#15,d3
	sub.w	#15,d3
	neg	d3
	bset	d3,d4
	bsr	putlinein
	movem.l	(sp)+,d4-d7/a0
	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
xmploop:
	addq.w	#1,d2
	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:
	dbf	d7,xmploop
	move.w	d2,d3
	and.w	#15,d3
	sub.w	#15,d3
	neg	d3
	bset	d3,d4
	bsr	putlinein
	movem.l	(sp)+,d4-d7/a0
	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:
	move.l	#0,d0
	move.w	dy,d0
	divs	dx,d0
	bmi	ypositive
ynegative:
	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:
	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

dump:	blk.w	1,0
gradient:	blk.w	1,0
x1:	blk.w	1,0
x2:	blk.w	1,0
y1:	blk.w	1,0
y2:	blk.w	1,0
dx:	blk.w	1,0
dy:	blk.w	1,0

*********************************************************
polytest:
	bsr	clearfast
	lea	surf_dfn,a0
	move.w	#4,(a0)		;is this the color
	lea	surf_vrt,a0
	move.w	#5,(a0)+	;or is this the color
	move.w	#100,(a0)+	;these must be the coords
	move.w	#10,(a0)+	;these must be the coords
	move.w	#300,(a0)+	;these must be the coords
	move.w	#0,(a0)+	;these must be the coords
	move.w	mx,(a0)+	;these must be the coords
	move.w	my,(a0)+	;these must be the coords
*	move.w	#250,(a0)+	;these must be the coords
*	move.w	#150,(a0)+	;these must be the coords
	move.w	#100,(a0)+	;these must be the coords
	move.w	#199,(a0)+	;these must be the coords
	move.w	#100,(a0)+	;these must be the coords
	move.w	#10,(a0)+	;these must be the coords

	lea	surf_dfn,a6
	bsr	draw_polygon
	bsr	flip2
	addq.w	#1,score
pt:
	bsr	keyboard
	bra	polytest
	
**************************************************************************
*               POLYGON WORKSPACE DECLARATION

poly_par:	blk.w	20,0	;Polygon parameter block

verticies:	equ	0	;number of verticies
vert_min:	equ	2	;Pointer to 1st vertex in data list
vert_max:	equ	6	;Pointer to last vertex in data list
left_vdx:	equ	10	;Left line x increment
right_vdx:	equ	14	;Right line x increment
left_vcnt:	equ	18	;Left line increment counter
right_vcnt:	equ	20	;Right line increment counter

surf_dfn:	blk.w	1,0
		dc.l	surf_vrt
surf_vrt:	blk.w	1,0
		blk.w	64,0        
***************************************************************************
*               DRAW A FILLED POLYGON
*               On entry, a6 = pointer to polygon data

draw_polygon:
        movem.l D0-D7/A0-A6,-(SP)       ;Save work registsers
        bsr     init_poly_draw          ;Initialise the polygon draw routine
draw_p0:
	swap    d3		;Correct format
        swap    d4

        move.l  a6,-(SP)	;Save parameter block pointer
        move.w  d3,d6		;Calculate start a6 address
        move.w  d5,d7
        bsr     calc_vsa
bp:     bsr     draw_hline	;Connect left and right edges
        move.l  (SP)+,a6

        swap    d4		;Next co-ordinates
        swap    d3
        add.l   left_vdx(a6),d3
        add.l   right_vdx(a6),d4
                
        subq.w  #1,left_vcnt(a6)	;Check if left vertex reached
        bpl     draw_p1			;Branch if <>
        subq.w  #1,verticies(a6)	;Check if finished
        bmi     draw_p3			;Branch if finished
        bsr     next_lvertex		;Calculate new vectors
        add.l   left_vdx(a6),d3
                
draw_p1:
	subq.w  #1,right_vcnt(a6)	;Check if right vertex reached
        bpl     draw_p2			;Branch if <>
        subq.w  #1,verticies(a6)	;Check if finished
        bmi     draw_p3			;Branch if finished
        bsr     next_rvertex		;Calculate new vectors
        add.l   right_vdx(a6),d4
                
draw_p2:
	addq.w  #1,d5			;Next line up
        bra     draw_p0

draw_p3:
	movem.l (SP)+,D0-D7/A0-A6
        rts				;Polygon drawn!!! I hope

***************************************************************************
*               INITIALISE POLYGON DRAW
*               On entry, a6 = polygon data pointer
*       Initialise the polygon draw routine. The 1st word of the polygon
* data specifies the logical color number to draw the polygon in. The
* next long word points to the vertex data.
init_poly_draw:
        move.w  (a6)+,D0	;Set color of polygon
        bsr     init_hcol
        move.l  (a6),a4		;Point to vertex data
        lea     poly_par,a6	;Point to paramter block
        bsr     find_vbase	;Set up vertex pointers
        move.w  2(a5),d5
        move.l  a5,a1
        move.l  a5,a2

        bsr     next_lvertex	;Calculate start vectors
        bsr     next_rvertex
        subq.w  #1,verticies(a6)
        subq.w  #1,verticies(a6)
        lea     hline_mask,a5	;Set up line mask pointers
        rts

***************************************************************************
*               NEW LEFT VERTEX
*               On entry, a1 = pointer to current vertex data
*               On exit ,    d3 = start x co-ordinate of line
*                          left_vdx = x co-ordinate increment
*                         left_vcnt = height of line
*************************************************************************
next_lvertex:
        move.w  (a1),d3		;Save current x co-ordinate
        ext.l   d3
        subq.l  #4,a1		;Point to destination vertex
        cmp.l   vert_min(a6),a1	;Check for wrap round
        bpl     nxt_lv0
        move.l  vert_max(a6),a1
                
nxt_lv0:
	move.w  (a1),d2		;Get destination x co-ord
        sub.w   d3,d2		;Calculate line d2
        ext.l   d2                
        move.w  2(a1),left_vcnt(a6)	;Calculate height of line
        sub.w   d5,left_vcnt(a6)
        beq     nxt_lv1
                
        move.w  left_vcnt(a6),d1
        bsr     vert_div

nxt_lv1:
	move.l  d2,left_vdx(a6)
        swap    d3         
        rts

***************************************************************************
*               NEW RIGHT VERTEX
*               On entry, a2 = pointer to current vertex data
*               On exit ,    d4 = start x co-ordinate of line
*                          right_vdx = x co-ordinate increment
*                         right_vcnt = height of line
*************************************************************************
next_rvertex:
        move.w  (a2),d4		;Save current x co-ordinate
        ext.l   d4
        addq.l  #4,a2		;Point to destination vertex
        move.l  vert_max(a6),d2	;Check for wrap round
        cmp.l   a2,d2
        bpl     nxt_rv0
        move.l  vert_min(a6),a2
nxt_rv0:
	move.w  (a2),d2		;Get destination x co-ord
        sub.w   d4,d2		;Calculate line d2
        ext.l   d2
                
        move.w  2(a2),right_vcnt(a6)	;Calculate height of line
        sub.w   d5,right_vcnt(a6)
        beq     nxt_rv1
                
        move.w  right_vcnt(a6),d1
        bsr     vert_div        

nxt_rv1:
	move.l  d2,right_vdx(a6)
        swap    d4
	rts
                
***************************************************************************
*               VERTEX DIVISION ROUTINE
*               On entry, d1 = bit divisor
*                          d2 = dividend
*               On exit ,  d2 = 32 bit quotient
*	Divide a 16 bit value into a signed 32 bit value giving a 32 bit
*	quotient.
*       Note, the dividend is always greter than $10000.
************************************************************************
vert_div:	bclr    #31,d1
                btst    #15,d2		;Check if dividend -ve
                beq     vert_div0	;Branch if positive
                neg     d2		;Make dividend +ve
                bset    #31,d1		;flag dividend -ve

vert_div0:	ext.l   d2
                divu    d1,d2
		move.w  d2,d0
                swap    d0
                clr     d0
                clr     d2                

                divu    d1,d2
                and.l   #$FFFF,d2
                add.l   d0,d2

                btst    #31,d1		;Check if need to fix sign
                beq     vert_div1	;Branch if dividend was +ve
                neg.l   d2		;Negate result

vert_div1:       rts

***************************************************************************
*               FIND LOWEST VERTEX
*               On entry, a4 = pointer to vertex data list
*               On exit , a5 = pointer to 1st vertex to draw from
*                         vert_min = pointer to lst vertex in list
*                         vert_max = pointer to last vertex in list
*                         d7 = number of verticies in list
**************************************************************************
find_vbase:
        move.w  (a4)+,d7		;Get number of verticies
        move.w  d7,verticies(a6)
        subq.w  #1,d7

        move.l  a4,vert_min(a6)		;1st vertex in list
                
        move.w  #1024,d6		;Initialise lowest y co-ord
        addq.l  #2,a4			;Point to y co-ordinate

fnd_vb0:
	cmp.w   (a4),d6			;Check if this vertex lower
        bmi     fnd_vb1			;Branch if <>
        move.w  (a4),d6
        move.l  a4,a5
                
fnd_vb1:
	addq.l  #4,a4			;Point to next vertex
        dbf     d7,fnd_vb0		;Loop until all vericies
	subq.l  #2,a5			;Adjust to x co-ordinate
        subq.l  #6,a4			;Adjust to last vertex
        move.l  a4,vert_max(a6)
        rts

***************************************************************************
*               DRAW A HORIZONTAL LINE
*               On entry,  d3 = start x co-ordinate
*                         d4 = end x co-ordinate
*                          a6 = a6 address of start of line
*       Registers corrupted,
*       Draw a horizontal line from left to right.
*************************************************************************
draw_hline:     cmp.w   d3,d4		;Glitch fix
                bmi     draw_hline0
                move.w  d4,d2		;Calculate length in pixels
                sub.w   d3,d2
                addq.w  #1,d2		;d2 } length of line

                cmp.w   #16,d2		;Check for special case
                bmi     drw_hls

                jsr     draw_start	;Draw start section
                jsr     draw_mid
                jsr     draw_end
        
draw_hline0:
		rts

**************************************************************************
draw_mid:       move.w  d2,D0		;Calculate number of centre sections
                lsr.w   #4,D0
                beq     drwmid1		;Branch if no centre sections
                subq.w  #1,D0		;Pre-decrement counter
        
drwmid0:	move.w  (a3),(a6)+	;Fill 1 section
                move.w  2(a3),(a6)+
                move.w  4(a3),(a6)+
                move.w  6(a3),(a6)+
                dbf     D0,drwmid0	;Loop until centre section complete
		and.w   #15,d2
drwmid1:
		rts

**************************************************************************
*               SPECIAL CASE - DRAW ALL OF LINE
*       This is the special case when the line is less then 16 pixels
* long. In this case, the whole line is plotted as 1 section.
************************************************************************
drw_hs:		bsr     draw_start
                bra     draw_end
drw_hls:
		move.w  d3,D0
                and.w   #15,D0
                move.w  d4,D1
                and.w   #15,D1
                addq.w  #1,D1
                add.w   D0,D0
                add.w   D1,D1           

                cmp.w   D0,D1		;Check for special case
                bmi     drw_hs
                
                move.w  (a5,D0.w),D6
                and.w   34(a5,D1.w),D6
                move.w  D6,D1
                not.w   D6

                and.w   D6,(a6)		;Colour plane 0
                move.w  (a3),D0
                and.w   D1,D0
                or.w    D0,(a6)+            

                and.w   D6,(a6)		;Colour plane 1
                move.w  2(a3),D0
                and.w   D1,D0
                or.w    D0,(a6)+
                
                and.w   D6,(a6)		;Colour plane 2
                move.w  4(a3),D0
                and.w   D1,D0
                or.w    D0,(a6)+            
                
                and.w   D6,(a6)		;Colour plane 3
                move.w  6(a3),D0
                and.w   D1,D0
                or.w    D0,(a6)+
                rts

**************************************************************************
*               DRAW START SECTION OF LINE
*               On entry, A6 = a6 address
*                         D2 = length of line in pixels
*                         D3 = start x co-ordinate of line
*       Draw the start section of the horizontal line. The start section
* can be up to 15 pixels long.
***************************************************************************
draw_start:
		move.w  d3,D6		;Check pixel start position
                andi.w  #15,D6
                beq     drwstr0		;Branch if no need to draw

                move.w  D6,D7		;Subtract start section pixel length
                eor.w   #15,D7
                sub.w   D7,d2
                subq.w  #1,d2
        
                add.w   D6,D6		;calculate pixel masks
                move.w  34(a5,D6.w),D1
                move.w  D1,D7
                not.w   D7
                
                and.w   D1,(a6)		;Colour plane 0
                move.w  (a3),D6
                and.w   D7,D6
                or.w    D6,(a6)+

                and.w   D1,(a6)		;Colour plane 1
                move.w  2(a3),D6
                and.w   D7,D6
                or.w    D6,(a6)+
        
                and.w   D1,(a6)		;Colour plane 2
                move.w  4(a3),D6
                and.w   D7,D6
                or.w    D6,(a6)+

                and.w   D1,(a6)		;Colour plane 3
                move.w  6(a3),D6
                and.w   D7,D6
                or.w    D6,(a6)+

drwstr0:        rts
        
***************************************************************************
*               DRAW END SECTION OF LINE
*               On entry, A6 = a6 address
*                         D4 = end x co-ordinate of line
*       Draw the end section of the horizontal line. The end section
* can be up to 15 pixels long.
**************************************************************************
draw_end:       cmp.w   #0,d2		;Check if need to draw end section
                beq     drwend0		;Branch if no need to draw

                move.w  d4,D6
                andi.w  #15,D6
                addq.w  #1,D6
        
                add.w   D6,D6
                move.w  (a5,D6.w),D1
                move.w  D1,D7
                not.w   D7
                
                and.w   D1,(a6)		;Colour plane 0
                move.w  (a3),D6
                and.w   D7,D6
                or.w    D6,(a6)+    
                
                and.w   D1,(a6)		;Colour plane 1
                move.w  2(a3),D6
                and.w   D7,D6
                or.w    D6,(a6)+

                and.w   D1,(a6)		;Colour plane 2
                move.w  4(a3),D6
                and.w   D7,D6
                or.w    D6,(a6)+

                and.w   D1,(a6)		;Colour plane 3
                move.w  6(a3),D6
                and.w   D7,D6
                or.w    D6,(a6)+

drwend0:
		rts

***************************************************************************
*               INITIALISE HORIZONTAL LINE COLOUR
*               On entry,     D0 = a3 number
*               On exit , a3 = a3 start address
*       Initialise the a3 pointer to the correct a3 planes.
************************************************************************
init_hcol:
		asl.w   #3,D0		;index a3 table
                lea     col_table,a3
                lea     (a3,D0.w),a3 
                rts
                
col_table:
		DC.w      00,00,00,00     ;Colour 0
                DC.w      -1,00,00,00     ;Colour 1
                DC.w      00,-1,00,00     ;Colour 2
                DC.w      -1,-1,00,00     ;Colour 3
                DC.w      00,00,-1,00     ;Colour 4        
                DC.w      -1,00,-1,00     ;Colour 5        
                DC.w      00,-1,-1,00     ;Colour 6        
                DC.w      -1,-1,-1,00     ;Colour 7        
                DC.w      00,00,00,-1     ;Colour 8        
                DC.w      -1,00,00,-1     ;Colour 9
                DC.w      00,-1,00,-1     ;Colour 10
                DC.w      -1,-1,00,-1     ;Colour 11
                DC.w      00,00,-1,-1     ;Colour 12
                DC.w      -1,00,-1,-1     ;Colour 13
                DC.w      00,-1,-1,-1     ;Colour 14       
                DC.w      -1,-1,-1,-1     ;Colour 15

***************************************************************************
*               MASK TABLES
*                RSRESET
**************************************************************************
even
hline_mask:
start_mask:
*		RS      17
                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
end_mask:
*		RS      17
                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

********************************
delay:
	move.w	#5000,d0
d:	dbf	d0,d
	rts		

putballs:
*	move.l	masterimage,a0
	move.w	d0,d2		;get copy of x
	and.w	#15,d0		;last 4 bits is offset
	move.w	d0,d3
	mulu	#240,d0
	adda.w	d0,a0		;now pointing at correct image
	move.l	a0,imageptr
*	move.l	mastermask,a0
	asr.w	#1,d0
	adda.w	d0,a0
	move.l	a0,maskptr
	move.l	hiden,a0
	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
	and.w	#$fff0,d2	;mask off last 4 bits gives word across
	lsr.w	#1,d2
	adda.w	d2,a0
	move.l	a0,screenloc
	move.w	#1,width
	move.w	#15,height
	bsr	pdrawimage
	rts
*****************************************
myreset:
	rts
*****************************************
ramware:
	move.w	#0,let1c
	move.w	#326,let2c
	move.w	#308,let3c
	move.w	#290,let4c
	move.w	#272,let5c
	move.w	#254,let6c
	move.w	#236,let7c
	rts

rw2:
	bsr	clearfast
*	bsr	clearsmall
	bsr	doletters
	bsr	keyboard
	bsr	flip2
	tst.w	buttondat
	beq	rw2
	rts

clearsmall:
	move.l	hiden,a0
	add.l	#56,a0
	move.w	#36,d7
clsm:
	move.l	#0,(a0)+
	move.l	#0,(a0)+
	move.l	#0,(a0)+
	move.l	#0,(a0)+
	move.l	#0,(a0)+
	move.l	#0,(a0)+
	move.l	#0,(a0)+
	move.l	#0,(a0)+
	move.l	#0,(a0)+
	move.l	#0,(a0)+
	move.l	#0,(a0)+
	move.l	#0,(a0)+
	move.l	#0,(a0)+
	move.l	#0,(a0)+
	move.l	#0,(a0)+
	move.l	#0,(a0)+
	move.l	#0,(a0)+
	move.l	#0,(a0)+
	move.l	#0,(a0)+
	move.l	#0,(a0)+
	move.l	#0,(a0)+
	move.l	#0,(a0)+
	move.l	#0,(a0)+
	move.l	#0,(a0)+
	add.w	#64,a0
	dbf	d7,clsm
	rts

doletters:
	move.l	#rampat,a0
	move.w	let1c,d0
	cmpi.w	#344,d0
	blt	dl1
	move.w	#0,let1c
dl1:
	asl.w	#2,d0		;mul by 4
	move.w	(a0,d0.w),d2	;thats x
	move.w	2(a0,d0.w),d1	;thats y
	add.w	#100,d1
	move.l	#rsprite,spblock+8
	bsr	doit		;put the sucker up
	addq.w	#1,let1c
*	rts

	move.l	#rampat,a0
	move.w	let2c,d0
	cmpi.w	#344,d0
	blt	dl2
	move.w	#0,let2c
dl2:
	asl.w	#2,d0		;mul by 4
	move.w	(a0,d0.w),d2	;thats x
	move.w	2(a0,d0.w),d1	;thats y
	add.w	#100,d1
	move.l	#asprite,spblock+8
	bsr	doit		;put the sucker up
	addq.w	#1,let2c

	move.l	#rampat,a0
	move.w	let3c,d0
	cmpi.w	#344,d0
	blt	dl3
	move.w	#0,let3c
dl3:
	asl.w	#2,d0		;mul by 4
	move.w	(a0,d0.w),d2	;thats x
	move.w	2(a0,d0.w),d1	;thats y
	add.w	#100,d1
	move.l	#msprite,spblock+8
	bsr	doit		;put the sucker up
	addq.w	#1,let3c

	move.l	#rampat,a0
	move.w	let4c,d0
	cmpi.w	#344,d0
	blt	dl4
	move.w	#0,let4c
dl4:
	asl.w	#2,d0		;mul by 4
	move.w	(a0,d0.w),d2	;thats x
	move.w	2(a0,d0.w),d1	;thats y
	add.w	#100,d1
	move.l	#wsprite,spblock+8
	bsr	doit		;put the sucker up
	addq.w	#1,let4c

	move.l	#rampat,a0
	move.w	let5c,d0
	cmpi.w	#344,d0
	blt	dl5
	move.w	#0,let5c
dl5:
	asl.w	#2,d0		;mul by 4
	move.w	(a0,d0.w),d2	;thats x
	move.w	2(a0,d0.w),d1	;thats y
	add.w	#100,d1
	move.l	#asprite,spblock+8
	bsr	doit		;put the sucker up
	addq.w	#1,let5c

	move.l	#rampat,a0
	move.w	let6c,d0
	cmpi.w	#344,d0
	blt	dl6
	move.w	#0,let6c
dl6:
	asl.w	#2,d0		;mul by 4
	move.w	(a0,d0.w),d2	;thats x
	move.w	2(a0,d0.w),d1	;thats y
	add.w	#100,d1
	move.l	#rsprite,spblock+8
	bsr	doit		;put the sucker up
	addq.w	#1,let6c

	move.l	#rampat,a0
	move.w	let7c,d0
	cmpi.w	#344,d0
	blt	dl7
	move.w	#0,let7c
dl7:
	asl.w	#2,d0		;mul by 4
	move.w	(a0,d0.w),d2	;thats x
	move.w	2(a0,d0.w),d1	;thats y
	add.w	#100,d1
	move.l	#esprite,spblock+8
	bsr	doit		;put the sucker up
	addq.w	#1,let7c
	rts


doit:
	move.w  d2,spblock
        move.w  d1,spblock+2
        move.w  #14,spblock+4
        move.w  #1,spblock+6
        move.l  #gtemp,spblock+12
        move.w  #1,spblock+26
        move.l  #gmask,spblock+38
*	move.l	,spblock+8
*	movem.l	d2-d7/a0/a6,-(sp)
	jsr	putsprite
*	movem.l	(sp)+,d2-d7/a0-a6
	rts

spblock:
	blk.w	50,0
let1c:	blk.w	1,0
let2c:	blk.w	1,0
let3c:	blk.w	1,0
let4c:	blk.w	1,0
let5c:	blk.w	1,0
let6c:	blk.w	1,0
let7c:	blk.w	1,0
********************************
clearfast:
	move.l	hiden,a0
	move.w	#90,d0
	addi.l	#1648,a0
	move.l	#0,d1
cf:
	move.l	d1,(a0)+
	move.l	d1,(a0)+
	move.l	d1,(a0)+
	move.l	d1,(a0)+
	move.l	d1,(a0)+
	move.l	d1,(a0)+
	move.l	d1,(a0)+
	move.l	d1,(a0)+
	move.l	d1,(a0)+
	move.l	d1,(a0)+
	move.l	d1,(a0)+
	move.l	d1,(a0)+
	move.l	d1,(a0)+
	move.l	d1,(a0)+
	move.l	d1,(a0)+
	move.l	d1,(a0)+
	move.l	d1,(a0)+
	move.l	d1,(a0)+
	move.l	d1,(a0)+
	move.l	d1,(a0)+
	move.l	d1,(a0)+
	move.l	d1,(a0)+
	move.l	d1,(a0)+
	move.l	d1,(a0)+
	move.l	d1,(a0)+
	move.l	d1,(a0)+
	adda.l	#56,a0
	dbf	d0,cf
	rts
********************************
joydir:
	bsr	cint
	tst.b	joyport1
	beq	jdback
	move.b	joyport1,d0
	btst	#7,d0
	beq	northa
	move.w	#1,firebutton
	bclr	#7,d0
	bra	north
northa:	move.w	#-1,firebutton
north:	cmpi.b	#1,d0
	bne	neast
	move.w	minusvel,myyvel
	move.w	#0,myxvel
	rts
neast:	cmpi.b	#9,d0
	bne	east
	move.w	minusvel,myyvel
	move.w	plusvel,myxvel
	rts
	
east:	cmpi.b	#8,d0
	bne	seast
	move.w	#0,myyvel
	move.w	plusvel,myxvel
	rts
seast:	cmpi.b	#10,d0
	bne	south
	move.w	plusvel,myyvel
	move.w	plusvel,myxvel
	rts

south:	cmpi.b	#2,d0
	bne	swest
	move.w	plusvel,myyvel
	move.w	#0,myxvel
	rts
swest:	cmpi.b	#6,d0
	bne	west
	move.w	plusvel,myyvel
	move.w	minusvel,myxvel
	rts

west:	cmpi.b	#4,d0
	bne	nwest
	move.w	#0,myyvel
	move.w	minusvel,myxvel
	rts

nwest:	cmpi.b	#5,d0
	bne	jdback
	move.w	minusvel,myyvel
	move.w	minusvel,myxvel
	rts
jdback:
	move.w	#0,myyvel
	move.w	#0,myxvel
	rts

minusvel:	blk.w	1,0
plusvel:	blk.w	1,0
myx:	blk.w	1,0
myy:	blk.w	1,0
myxvel:	blk.w	1,0
myyvel:	blk.w	1,0
firebutton:	blk.w	1,-1
*******************************
gtemp:	blk.w	1000,0
gmask:	blk.w	1000,0
*****************************************
*	set up joystick handler		*
*****************************************
joystuff:
init_joy:
	move.w	#$14,-(sp)
	move.w	#4,-(sp)
	move.w	#3,-(sp)
	trap	#13
	addq.l	#6,sp

	move.w	#34,-(sp)
	trap	#14
	addq.l	#2,sp
	move.l	d0,a0
	adda.l	#24,a0
	move.l	(a0),old_packh		;save the old handler
	move.l	#joy_packet,(a0)	;put in mine
	rts
*****************************************	
*	this is the joy pak handler	*
*****************************************
joy_packet:
	movem.l	a0/a1,-(sp)
	lea	joyport0,a1
	move.b	1(a0),(a1)
	move.b	2(a0),1(a1)
	movem.l	(sp)+,a0/a1
	rts

joyport0:	blk.b	1,0
joyport1:	blk.b	1,0
	even

res_mouse:
	move.w	#34,-(sp)
	trap	#14
	addq.l	#2,sp
	move.l	d0,a0
	adda.l	#24,a0
	move.l	old_packh,(a0)

	move.w	#128,-(sp)
	move.w	#4,-(sp)
	move.w	#3,-(sp)
	trap	#13
	addq.l	#6,sp

	move.w	#1,-(sp)
	move.w	#4,-(sp)
	move.w	#3,-(sp)
	trap	#13
	addq.l	#6,sp
	rts

old_packh:	blk.l	1,0
*************************************************
prestuff:
	move.w	#0,d7
*	move.l	#myship,origptr
	move.l	#myshipbuffer,imageptr
	move.w	#0,offset
ps1:
	move.w	#1,width
	move.w	#15,height
	jsr	pshiftimage	
	addq.w	#1,offset
	add.l	#240,imageptr
	addq.w	#1,d7
	cmpi.w	#15,offset
	ble	ps1

	move.w	#0,d7
	move.l	#myshipmask,maskptr
	move.l	#myshipbuffer,imageptr
	move.w	#0,offset
psm1:
	move.w	#1,width
	move.w	#15,height
	bsr	pmakemask	
	addq.w	#1,offset
	add.l	#240,imageptr
	add.l	#120,maskptr
	cmpi.w	#15,offset
	ble	psm1


*****************************************
*	height- height			*
*	width				*
*	offset				*
*	origptr				*
*	imageptr			*
*****************************************

pshiftimage:
        move.w  height,d1        ;height in d1
        move.w  offset,d2       ;offset to d2
        subq.w  #1,d1           ;height - 1 = height if count starts at zero
        subq.w  #1,width        ;width - 1 = width if count starts at zero
        move.l  origptr,a0      ;object pointer to a0
        move.l  imageptr,a1     ;image pointer to a1
psi1:   move.w  width,d0		;width in d0
        clr.l   (a1)            ;for each line, the first word of the
        clr.l   4(a1)           ;image must be cleared
psi0:    clr.l   d4              ;make sure that the top halves of these
        clr.l   d5              ;registers are zeroed out
        clr.l   d6
        clr.l   d7
        move.w  (a0)+,d4        ;load in one word (four planes)
        move.w  (a0)+,d5        ;to be rotated
        move.w  (a0)+,d6
        move.w  (a0)+,d7
        ror.l   d2,d4           ;rotate all planes by the offset(d2)
        ror.l   d2,d5
        ror.l   d2,d6
        ror.l   d2,d7
        or.w    d4,(a1)+        ;add low order bits to the high order bits
        or.w    d5,(a1)+        ;stored by move instructions farther
        or.w    d6,(a1)+        ;down in this routine
        or.w    d7,(a1)+
        swap    d4              ;move high order bits into lower halves
        swap    d5              ;of the registers
        swap    d6
        swap    d7
        move.w  d4,(a1)         ;save the high orders bits to be ORed
        move.w  d5,2(a1)        ;in the loop (do not increment a1 because
        move.w  d6,4(a1)        ;the ORs in the loop must function on
        move.w  d7,6(a1)        ;the same addresses as these moves.
        dbf     d0,psi0          ;repeat width times
        addq.l  #8,a1           ;new line, move to next word( * 4 planes = 8)
        dbf     d1,psi1          ;repeat height times
        rts                     ;done

pmakemask:
        move.w  height,d1        ;height in d1
        subq.w  #1,d1           ;height - 1 = height if count starts at zero
        move.l  imageptr,a0        ;image pointer to a0
        move.l  maskptr,a1       ;mask pointer to a1
pmm1:    move.w  width,d0        ;width in d0
pmm0:    move.w  (a0)+,d2        ;load first plane of bit image in d2
        or.w    (a0)+,d2        ;OR it with the 3 other planes
        or.w    (a0)+,d2
        or.w    (a0)+,d2
        move.w  d2,d3           ;store inverse mask in d3 (temporary)
        swap    d2              ;move inverse mask to top half of register
        move.w  d3,d2           ;and also in bottom half
        eor.l   #-1,d2          ;mask no longer inverse
        move.l  d2,(a1)+        ;store mask in buffer
        dbf     d0,pmm0          ;repeat 'width' times
        dbf     d1,pmm1          ;repeat 'height' times
        rts                     ;done
**************************************************
*	routine to draw image of prerotated
*	sprite
*	must load width,height,screenloc,imageptr,maskptr
pdrawimage:
        move.w  height,d1        ;height to d1
        subq.w  #1,d1           ;height - 1 = height if count starts at zero
        move.l  imageptr,a1       ;image pointer to a1
        move.l  maskptr,a2       ;mask pointer to a2
        move.l  screenloc,a3       ;screen buffer pointer to a3
pdi1:    move.w  width,d0        ;width to d0
        move.l  screenloc,a0        ;absolute screen address to a0
pdi0:    move.l  (a2)+,d3        ;load mask data into d3
        move.l  (a1)+,d6        ;load screen image into d6 and d7
        move.l  (a1)+,d7        ;2 words each covers all 4 planes
        move.l  (a3)+,d4        ;do the same for the background
        move.l  (a3)+,d5        ;in d4 and d5 (from buffer, not screen)
        and.l   d3,d4           ;mask background
        and.l   d3,d5
        or.l    d6,d4           ;copy image onto background
        or.l    d7,d5           ;giving final image on top of background
        move.l  d4,(a0)+        ;copy final image into screen memory
        move.l  d5,(a0)+
        dbf     d0,pdi0          ;repeat for 'width' times
        add.l   #160,screenloc      ;move to next screen line
	add.l	#144,a3
        dbf     d1,pdi1          ;repeat 'height' times
        rts                     ;done

shadow:
	tst.w	shad
	bmi	sback
	move.w	height,d1
	subq.w	#1,d1
	move.l	screenloc,a0
	move.l	maskptr,a1
	add.l	#1592,a0
sd:
	move.l	(a1)+,d0
	and.l	d0,(a0)+
	and.l	d0,(a0)+
	move.l	(a1)+,d0
	and.l	d0,(a0)+
	and.l	d0,(a0)+
	add.l	#144,a0
	dbf	d1,sd
	move.w	#-1,shad
	rts
sback:	
	move.w	#1,shad
	rts

shad:	blk.w	1,0
height:	blk.w	1,0
width:	blk.w	1,0
screenloc:	blk.l	1,0
imageptr:	blk.l	1,0
maskptr:	blk.l	1,0
****************************************
keyboard:
        move.w  #$ff,-(sp)
        move.w  #6,-(sp)
        trap    #1
        addq.l  #4,sp
        tst.l   d0
        beq     keyback
        swap    d0
quit:   cmpi.w  #$10,d0
        bne     space
        bra     gem
space:
	cmpi.w	#$39,d0
	bne	up
	bra	pause
up:
	cmpi.w	#$48,d0
	bne	downa
	sub.w	#20,updown
	rts
downa:
	cmpi.w	#$50,d0
	bne	keyback
	add.w	#20,updown
	rts
keyback:rts
updown:	blk.w	1,0

*****************************
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
*        bra     tmode

gkey:
        move.w  #$ff,-(sp)
        move.w  #6,-(sp)
        trap    #1
        addq.l  #4,sp
        tst.l   d0
        beq     gkey
        swap    d0
        rts

************code to determine  x offset *****************
*               and absolute screen address             *
*               parameters to pass on stack as follows  *
*               1-      x of sprite                     *
*               2-      y of sprite                     *
*               3-      screen address                  *
*       paremeters returned are x offset in d0          *
*       absolute screen address in d2                   *
*********************************************************
*	note use of a6					*
*********************************************************
putsprite:
	lea	spblock,a6
        move.l  hiden,16(a6)
	move.l  #0,d0
        move.w  (a6),d0       ;put x value in d0
        divu    #16,d0          ;divide by 16 leaves word boundry in d0
        move.w  2(a6),d1     ;put y value in d1
        mulu    #160,d1         ;gives offset in words of line
        move.w  d0,d3
        asl.w	#3,d3
        add.w	d3,d1           ;gives word to poke sprite
        move.l  hiden,d2    ;put screen address in d2
        add     d1,d2           ;gives actual screen address for sprite
        move.l  d2,20(a6)
        asr.l   #8,d0
        asr.l   #8,d0           ;leaves x offset in d0          
        move.w  d0,24(a6)

*************CODE TO ROTATE A SPRITE IMAGE***********************
*****************************************************************
shiftimages:
        move.w  4(a6),d1        ;height in d1
        move.w  24(a6),d2       ;offset to d2
        subq.w  #1,d1           ;height - 1 = height if count starts at zero
        subq.w  #1,6(a6)        ;width - 1 = width if count starts at zero
        move.l  8(a6),a0        ;object pointer to a0
        move.l  12(a6),a1       ;image pointer to a1
ssi1:	move.w  6(a6),d0        ;width in d0
        clr.l   (a1)            ;for each line, the first word of the
        clr.l   4(a1)           ;image must be cleared
ssi0:	clr.l   d4              ;make sure that the top halves of these
        clr.l   d5              ;registers are zeroed out
        clr.l   d6
        clr.l   d7
        move.w  (a0)+,d4        ;load in one word (four planes)
        move.w  (a0)+,d5        ;to be rotated
        move.w  (a0)+,d6
        move.w  (a0)+,d7
        ror.l   d2,d4           ;rotate all planes by the offset(d2)
        ror.l   d2,d5
        ror.l   d2,d6
        ror.l   d2,d7
        or.w    d4,(a1)+        ;add low order bits to the high order bits
        or.w    d5,(a1)+        ;stored by move instructions farther
        or.w    d6,(a1)+        ;down in this routine
        or.w    d7,(a1)+
        swap    d4              ;move high order bits into lower halves
        swap    d5              ;of the registers
        swap    d6
        swap    d7
        move.w  d4,(a1)         ;save the high orders bits to be ORed
        move.w  d5,2(a1)        ;in the loop (do not increment a1 because
        move.w  d6,4(a1)        ;the ORs in the loop must function on
        move.w  d7,6(a1)        ;the same addresses as these moves.
        dbf     d0,ssi0          ;repeat width times
        addq.l  #8,a1           ;new line, move to next word( * 4 planes = 8)
        dbf     d1,ssi1          ;repeat height times
        addq.w  #1,6(a6)
smake_mask:
        move.w  4(a6),d1        ;height in d1
        subq.w  #1,d1           ;height - 1 = height if count starts at zero
        move.l  12(a6),a0        ;image pointer to a0
        move.l  38(a6),a1       ;mask pointer to a1
smm1:	move.w  6(a6),d0        ;width in d0
smm0:	move.w  (a0)+,d2        ;load first plane of bit image in d2
        or.w    (a0)+,d2        ;OR it with the 3 other planes
        or.w    (a0)+,d2
        or.w    (a0)+,d2
        move.w  d2,d3           ;store inverse mask in d3 (temporary)
        swap    d2              ;move inverse mask to top half of register
        move.w  d3,d2           ;and also in bottom half
        eor.l   #-1,d2          ;mask no longer inverse
        move.l  d2,(a1)+        ;store mask in buffer
        dbf     d0,smm0          ;repeat 'width' times
        dbf     d1,smm1          ;repeat 'height' times

*********code to put sprite on screen********************
*********parameters to be passed on the stack are********
*********1-     shifted sprite address (tempsp) *********
*********2-     absolute screen address to put image*****
*********3-     height in pixels                *********
*********4-     width in words -1               *********
sdraw:
        move.w  4(a6),d1     ;height to d1
        subq.w  #1,d1           ;height - 1 = height if count starts at zero
        move.l  12(a6),a1    ;image pointer to a1
        move.l  38(a6),a2    ;mask pointer to a2
        move.l  20(a6),a3    ;screen buffer pointer to a3
sdi1:	move.w  6(a6),d0     ;width to d0
        move.l  20(a6),a0    ;absolute screen address to a0
sdi0:	move.l  (a2)+,d3        ;load mask data into d3
        move.l  (a1)+,d6        ;load screen image into d6 and d7
        move.l  (a1)+,d7        ;2 words each covers all 4 planes
        move.l  (a3)+,d4        ;do the same for the background
        move.l  (a3)+,d5        ;in d4 and d5 (from buffer, not screen)
        and.l   d3,d4           ;mask background
        and.l   d3,d5
        or.l    d6,d4           ;copy image onto background
        or.l    d7,d5           ;giving final image on top of background
        move.l  d4,(a0)+        ;copy final image into screen memory
        move.l  d5,(a0)+
        dbf     d0,sdi0          ;repeat for 'width' times
        addi.l	#160,20(a6)  ;move to next screen line
        addi.l  #144,a3
        dbf     d1,sdi1          ;repeat 'height' times
	rts
************code to determine  x offset *****************
*               and absolute screen address             *
*               parameters to pass on stack as follows  *
*               1-      x of sprite                     *
*               2-      y of sprite                     *
*               3-      screen address                  *
*       paremeters returned are x offset in d0          *
*       absolute screen address in d2                   *
*********************************************************
shipsp:

calc:
        clr.l   d0
        move.w  pblock,d0       ;put x value in d0
        divu    #16,d0          ;divide by 16 leaves word boundry in d0
        move.w  pblock+2,d1     ;put y value in d1
        mulu    #160,d1         ;gives offset in words of line
        move.w  d0,d3
        mulu    #8,d3
        add     d3,d1           ;gives word to poke sprite
        move.l  pblock+16,d2    ;put screen address in d2
        add     d1,d2           ;gives actual screen address for sprite
        move.l  d2,pblock+20
        asr.l   #8,d0
        asr.l   #8,d0           ;leaves x offset in d0          
        move.w  d0,pblock+24


*************CODE TO ROTATE A SPRITE IMAGE***********************
*       parameters to be passed on the stack in order are       *       
*       1-      x offset from start of word                     *
*       2-      address of place to put shifted image(tempsp)   *
*       3-      address of sprite data                          *
*       4-      height of object in pixels                      *
*       5-      width of object in words - 1                    *
*****************************************************************
shiftimage:
        move.w  pblock+4,d1        ;height in d1
        move.w  pblock+24,d2       ;offset to d2
        subq.w  #1,d1           ;height - 1 = height if count starts at zero
        subq.w  #1,pblock+6        ;width - 1 = width if count starts at zero
        move.l  pblock+8,a0        ;object pointer to a0
        move.l  pblock+12,a1       ;image pointer to a1
si1:    move.w  pblock+6,d0        ;width in d0
        clr.l   (a1)            ;for each line, the first word of the
        clr.l   4(a1)           ;image must be cleared
si0:    clr.l   d4              ;make sure that the top halves of these
        clr.l   d5              ;registers are zeroed out
        clr.l   d6
        clr.l   d7
        move.w  (a0)+,d4        ;load in one word (four planes)
        move.w  (a0)+,d5        ;to be rotated
        move.w  (a0)+,d6
        move.w  (a0)+,d7
        ror.l   d2,d4           ;rotate all planes by the offset(d2)
        ror.l   d2,d5
        ror.l   d2,d6
        ror.l   d2,d7
        or.w    d4,(a1)+        ;add low order bits to the high order bits
        or.w    d5,(a1)+        ;stored by move instructions farther
        or.w    d6,(a1)+        ;down in this routine
        or.w    d7,(a1)+
        swap    d4              ;move high order bits into lower halves
        swap    d5              ;of the registers
        swap    d6
        swap    d7
        move.w  d4,(a1)         ;save the high orders bits to be ORed
        move.w  d5,2(a1)        ;in the loop (do not increment a1 because
        move.w  d6,4(a1)        ;the ORs in the loop must function on
        move.w  d7,6(a1)        ;the same addresses as these moves.
        dbf     d0,si0          ;repeat width times
        addq.l  #8,a1           ;new line, move to next word( * 4 planes = 8)
        dbf     d1,si1          ;repeat height times
        addi.w  #1,pblock+6
make_mask:
        move.w  pblock+4,d1        ;height in d1
        subq.w  #1,d1           ;height - 1 = height if count starts at zero
        move.l  pblock+12,a0        ;image pointer to a0
        move.l  pblock+38,a1       ;mask pointer to a1
mm1:	move.w  pblock+6,d0        ;width in d0
mm0:	move.w  (a0)+,d2        ;load first plane of bit image in d2
        or.w    (a0)+,d2        ;OR it with the 3 other planes
        or.w    (a0)+,d2
        or.w    (a0)+,d2
        move.w  d2,d3           ;store inverse mask in d3 (temporary)
        swap    d2              ;move inverse mask to top half of register
        move.w  d3,d2           ;and also in bottom half
        eor.l   #-1,d2          ;mask no longer inverse
        move.l  d2,(a1)+        ;store mask in buffer
        dbf     d0,mm0          ;repeat 'width' times
        dbf     d1,mm1          ;repeat 'height' times

draw:
        move.w  pblock+4,d1     ;height to d1
        subq.w  #1,d1           ;height - 1 = height if count starts at zero
        move.l  pblock+12,a1    ;image pointer to a1
        move.l  pblock+38,a2    ;mask pointer to a2
        move.l  pblock+20,a3    ;screen buffer pointer to a3
di1:	move.w  pblock+6,d0     ;width to d0
        move.l  pblock+20,a0    ;absolute screen address to a0
di0:	move.l  (a2)+,d3        ;load mask data into d3
        move.l  (a1)+,d6        ;load screen image into d6 and d7
        move.l  (a1)+,d7        ;2 words each covers all 4 planes
        move.l  (a3)+,d4        ;do the same for the background
        move.l  (a3)+,d5        ;in d4 and d5 (from buffer, not screen)
        and.l   d3,d4           ;mask background
        and.l   d3,d5
        or.l    d6,d4           ;copy image onto background
        or.l    d7,d5           ;giving final image on top of background
        move.l  d4,(a0)+        ;copy final image into screen memory
        move.l  d5,(a0)+
        dbf     d0,di0          ;repeat for 'width' times
        add.l   #160,pblock+20  ;move to next screen line
        add.w   pblock+46,a3
        dbf     d1,di1          ;repeat 'height' times
	rts
***********************************
printscore:
	tst.b	numsflag
*	bmi	noput
	move.w	#0,numwhere
	move.w	score,number
	bsr	prtnum
*	subq.b	#1,numsflag
	rts
noput:
	move.b	#-1,numsflag
printships:
	tst.b	shipsflag
	bmi	noputs
	move.w	#14104,numwhere
	move.w	ships,number
	bsr	prtnum
	subq.b	#1,shipsflag
	rts
noputs:
	move.b	#-1,numsflag
	rts

emancnt:	blk.w	1,0
numwhere:	blk.w	1,0
numsflag:	blk.b	1,0
shipsflag:	blk.b	1,0
levelflag:	blk.b	1,0
even
**************************************************************************

*               RETURN TO GEM

gem:
	move.w	#0,$452
	move.l	oldvbl1,a0
	move.l	#0,(a0)
	move.w	#1,$452

	jsr	res_mouse
        move.b  #7,$484

        move.w  ressave,-(sp)
*	move.w	#-1,-(sp)
        move.l  screen1,-(sp)
        move.l  screen1,-(sp)
        move.w  #5,-(sp)
        trap    #14
        addi.l  #12,sp
        

        move.l  spv_sp,-(SP)    ;Back to user mode
        move.w  #$20,-(SP)
        trap    #1
        addq.l  #6,(SP)

illegal
        CLR.W   -(SP)           ;RETURN TO GEM
   
        TRAP    #1

spv_sp: blk.l   1               ;supervisor SP store
ressave:	blk.w	1,0

beamer:
	move.l	#$ff8205,a0
	move.l	#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
	rts
flip_scr:
	move.l	seen,d1
	move.l	d1,d2
	add.l	#11000,d1
	add.l	#31000,d2
skloop:
	bsr	beamer
	cmp.l	d1,d0
	blt	skloop
	cmp.l	d2,d0
	bgt	skloop

        move.l  seen,A6
        move.l  hiden,seen
        move.l  A6,hiden
	jsr	clearfast
        move.l  sytable,A6
        move.l  ytable,sytable
        move.l  A6,ytable
*       rts
df:     move.w  #-1,-(sp)
        move.l  seen,-(sp)
        move.l  hiden,-(sp)
        move.w  #5,-(sp)
        trap    #14
        addi.l  #12,sp  
        rts
************************************************************
flip2:
        move.l  seen,A6
        move.l  hiden,seen
        move.l  A6,hiden
        move.l  sytable,A6
        move.l  ytable,sytable
        move.l  A6,ytable
*       rts
df2:     move.w  #-1,-(sp)
        move.l  seen,-(sp)
        move.l  hiden,-(sp)
        move.w  #5,-(sp)
        trap    #14
        addi.l  #12,sp  
	move.w	#37,-(sp)
	trap	#14
	addq.l	#2,sp
        rts
*************************************************
calc_vsa:
	swap	d7
	move.w	#0,d7
	swap	d7
	swap	d6
	move.w	#0,d6
	swap	d6

	mulu	#160,d7
	asr.w	#4,d6
	asl.w	#3,d6
	add.w	d6,d7
	move.l	hiden,a6
	add.w	d7,a6
	rts


movem.l	d0-d3/a0-a1,-(sp)
move.w d6,d0      ;x coordinate in D0
move.w d0,d3         ;duplicate in D3
andi.w #15,d3        ;mask off lower 4 bits
move.w d7,d1      ;get y coordinate,
lsl.w #2,d1          ;mult by 4 for index
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 0(a1,d1.w),a6 ;got final pixel addr!
movem.l	(sp)+,d0-d3/a0-a1
rts
********************************************
* Atari ST hi-speed plotting subroutine    *
********************************************
* For Low-resolution mode only		   *
********************************************
**************************************
* INITIALIZE THE PLOTTING ROUTINE:   *
* BUILDS PLOT ADDRESS TABLE (YTABLE) *
* FOR FAST PLOTTING.                 *
*                                    *
* CALL WITH:                         *
* pinit(SCREENADDRESS)               *
**************************************
plotinit:
move.l seen,a0    ;screen addr in A0
move.b #200,d1     ;200 Y positions
move.l #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
move.l #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!
*move.l	#ytable2,ytable
rts

pixelx:	blk.w	1,0
pixely:	blk.w	1,0
pixelcolor:
	blk.w	1,0
ytable1:	blk.l	200,0
ytable2:	blk.l	200,0
ytable:		blk.l	1,0
sytable:		blk.l	1,0

**************************************
* PLOT A PIXEL WITH MY ROUTINE       *
*                                    *
* CALL WITH:                         *
* myplot(X,Y,COLOR)                  *
**************************************
myplot:
movem.l	d0-d5/a0-a1,-(sp)
move.w pixelx,d0      ;x coordinate in D0
cmp.w #303,d0
bcc pltxit
cmpi.w	#96,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,
cmpi.w	#10,d1
blt	pltxit
cmp.w #189,d1
bcc 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 0(a1,d1.w),a0 ;got final pixel addr!
cmpi.w	#15,d3
beq	singlepix
move.w #$c000,d4     ;set ON pixel mask
lsr.w d3,d4          ;shift right D3 times
move.l #$c000c000,d5 ;set OFF pixel mask
lsr.l d3,d5          ;shift right D3 times
eor.l #$ffffffff,d5  ;toggle all bits in D5
bra	myphere

singlepix:
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
and.l d5,(a0)        ;turn off old pixel
and.l d5,4(a0)       ;(both longwords)

******************************
* Now turn on the new pixel! *
******************************

* BIT 1 *

btst #0,d2           ;set the bit?
beq bbit2             ;no!
or.w d4,(a0)         ;turn it on!

* BIT 2 *

bbit2:
btst #1,d2           ;set it?
beq bbit4             ;no!
or.w d4,2(a0)        ;turn it on!

* BIT 4 *

bbit4:
btst #2,d2           ;set bit?
beq bbit8             ;no!
or.w d4,4(a0)        ;turn it on!

* BIT 8 *

bbit8:
btst #3,d2           ;set bit?
beq mysec           ;no, exit.
or.w d4,6(a0)        ;turn it on!

mysec:
adda.l	#8,a0
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
and.l d5,(a0)        ;turn off old pixel
and.l d5,4(a0)       ;(both longwords)

******************************
*    Turn off old pixel!     *
******************************
myphere:

and.l d5,(a0)        ;turn off old pixel
and.l d5,4(a0)       ;(both longwords)

******************************
* Now turn on the new pixel! *
******************************

* BIT 1 *

btst #0,d2           ;set the bit?
beq bit2             ;no!
or.w d4,(a0)         ;turn it on!

* BIT 2 *

bit2:
btst #1,d2           ;set it?
beq bit4             ;no!
or.w d4,2(a0)        ;turn it on!

* BIT 4 *

bit4:
btst #2,d2           ;set bit?
beq bit8             ;no!
or.w d4,4(a0)        ;turn it on!

* BIT 8 *

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!

**********************
* get low-rez pixel  *
* get0(scrnbase,x,y) *
**********************
*gets pixel in hiden screen

mygetpix:
move.l hiden,a1
clr.w d0		;zero result register
move.w pixely,d3	;get Y coordinate
and.l #$0000ffff,d3	;mask off for multiply
mulu #160,d3		;multiply by 160 (# of bytes per scan line)
adda.l d3,a1		;add to screen base address
move.w pixelx,d1	;get X coordinate
move.w d1,d2		;duplicate it in D2
lsr.w #1,d1		;divide it by 2
and.w #$00f8,d1		;turn off lower 3 bits
adda.w d1,a1		;add to screen address register

move.w (a1),d3		;grab screen word
and.l #15,d2		;mask X to 0-15
move.w #$8000,d1	;set up bit mask
lsr.w d2,d1		;shift bit mask 0-15 bits
and.w d1,d3		;mask off bit 0
beq bit0b		;bit's off, go get next color bit
move.w #1,d0		;turn on bit 0 in result

bit0b:
move.w 2(a1),d3		;get screen word for bit 1 of color
and.w d1,d3		;get bit 1
beq bit0c		;it's off, try bit 2
or.w #2,d0		;turn on bit 1 in result

bit0c:
move.w 4(a1),d3		;get screen word for bit 2
and.w d1,d3		;get bit 2
beq bit0d		;it's off, try bit 3
or.w #4,d0		;turn on bit 2 in result

bit0d:
move.w 6(a1),d3		;get word for bit 3
and.w d1,d3		;get bit 3
beq getx0		;it's off!
or.w #8,d0		;turn on bit 3 in result

getx0:
rts
*************************************************
linea:  dc.w    $a000
        move.l  a0,linepar
        move.l  8(a0),intin
        move.l  12(a0),ptsin
        rts

*************************************************

***********************fancy clear screen****************
clearsc:move.l  #99,d0
        move.l  screen,a0
cl1:    move.w  #159,d1
cl2:    move.w  #0,(a0)+
        dbf     d1,cl2
        addi.l  #160,a0
        dbf     d0,cl1
        move.w  #99,d0
        move.l  screen,a0
        addi.l  #160,a0
cl3:    move.w  #159,d1
cl4:    move.w  #0,(a0)+
        dbf     d1,cl4
        addi.l  #160,a0
        dbf     d0,cl3
        rts


cldel:  move.w  #3000,d2
cdel1:  nop
        dbf     d2,cdel1
        rts
********************************
copyintoboth:
        move.l  hiden,a0
        move.l  seen,a1
        move.w  #4000,d0
cib3:
        move.l  (a0)+,(a1)+
        move.l  (a0)+,(a1)+
        dbf     d0,cib3
	rts
********************fancy copy screen*************
copysc: move.w  #99,d0
        move.l  screen,a0
        move.l  screen2,a1
cop1:   move.w  #159,d1
cop2:   move.w  (a1)+,(a0)+
        dbf     d1,cop2
        addi.l  #160,a0
        addi.l  #160,a1
        dbf     d0,cop1
        move.w  #99,d0
        move.l  screen,a0
        addi.l  #160,a0
        move.l  screen2,a1
        addi.l  #160,a1
cop3:   move.w  #159,d1
cop4:   move.w  (a1)+,(a0)+
        dbf     d1,cop4
        addi.l  #160,a0
        addi.l  #160,a1
        dbf     d0,cop3
        rts
**********************routine to print a dec nuber*************
prtnum: 
	move.w	#0,times
        move.l  #0,d7
        move.w  number,d7
        andi.l  #$ffff,d7
        move.l  #line,a5

dodec:  move.l  d7,d6
        divu    #10,d6
        move.w  d6,d7
        swap    d6
*        addi.w  #16,d6
        move.b  d6,(a5)+
        cmpi.w  #0,d7
        bne     dodec
	
out:    cmpa.l  #line,a5
        beq     decback
        move.b  -(a5),d7
        andi.w  #$ff,d7
	lea	numbers,a0
	mulu	#40,d7
	add.w	d7,a0
	move.w	#9,d0
	move.l	hiden,a1
	adda.w	numwhere,a1
oloop:
	move.b	(a0)+,(a1)
	move.b	(a0)+,2(a1)
	move.b	(a0)+,4(a1)
	move.b	(a0)+,6(a1)
	add.l	#160,a1
	dbf	d0,oloop
	addq.w	#1,times
	cmpi.w	#2,times
	blt	oh
	move.w	#0,times
	addq.w	#6,numwhere
oh:	addq.w	#1,numwhere
	
	bra	out
	rts        
decback:
	rts
times:	blk.w	1,0

prtnum2: 
        move.l  #0,d7
        move.w  number,d7
        andi.l  #$ffff,d7
        move.l  #line,a5

dodec2:  move.l  d7,d6
        divu    #10,d6
        move.w  d6,d7
        swap    d6
        addi.w  #48,d6
        move.b  d6,(a5)+
        cmpi.w  #0,d7
        bne     dodec2
	
out2:
	cmpa.l  #line,a5
        beq     decback2
        move.b  -(a5),d7
        andi.w  #$ff,d7
        move.w  d7,-(sp)
        move.w  #2,-(sp)
        trap    #1
        addq.l  #4,sp
        bra     out2

decback2:
	rts
*************puts my mouse interupt in***************** 

mmin:	blk.w	1,0
mmax:	blk.w	1,0
************get screen address***************
getscrn:move.w  #2,-(sp)
        trap    #14
        addq.l  #2,sp
        move.l  d0,screen
        move.l  d0,screen1
        move.l  d0,screen2
        subi.l  #$8000,screen2
        move.l  screen1,seen
        move.l  screen2,hiden
	move.l	#ytable2,ytable
	move.l	#ytable1,sytable
        rts

map:	blk.l	1,0
************change colors****************
docolors:
	move.l temppal,-(sp)
        move.w #6,-(sp)
        trap #14
        addq.l #6,sp
        rts
************change colors****************

darkcolors:
        move.l #palette2,-(sp)
        move.w #6,-(sp)
        trap #14
        addq.l #6,sp
        rts

*****************wait for a key*********************
wait:   move.w  $26e6,d0
        cmpi.w  #2,d0
        beq     wback
        bra     wait
wback:  rts
***************turn mouse off***********************
mousof: dc.w    $a00a   
        rts

*******************************************************************
; SYSNOPSIS
;    RandomSeed( SeedValue )
;                   D0

randomseed:     ADD.L   D0,D1           ;user seed in d0 (d1 too)
                MOVEM.L D0/D1,RND

; drops through to the main random function (not user callable)

LongRnd:        MOVEM.L D2-D3,-(SP)     
                MOVEM.L RND,D0/D1       ;D0=LSB's, D1=MSB's of random number
                ANDI.B  #$0E,D0         ;ensure upper 59 bits are an...
                ORI.B   #$20,D0         ;...odd binary number
                MOVE.L  D0,D2
                MOVE.L  D1,D3
                ADD.L   D2,D2           ;accounts for 1 of 17 left shifts
                ADDX.L  D3,D3           ;[D2/D3] = RND*2
                ADD.L   D2,D0
                ADDX.L  D3,D1           ;[D0/D1] = RND*3
                SWAP    D3              ;shift [D2/D3] additional 16 times
                SWAP    D2
                MOVE.W  D2,D3
                CLR.W   D2
                ADD.L   D2,D0           ;add to [D0/D1]
                ADDX.L  D3,D1
                MOVEM.L D0/D1,RND       ;save for next time through
                MOVE.L  D1,D0           ;most random part to D0
                MOVEM.L (SP)+,D2-D3
                RTS

; SYSNOPSIS
;    RndNum = Random( UpperLimit )
;      D0                 D0

random:
	        MOVE.W  D2,-(SP)
                MOVE.W  D0,D2           ;save upper limit
                BEQ.S   r1              ;range of 0 returns 0 always
                BSR.S   LongRnd         ;get a longword random number
                CLR.W   D0              ;use upper word (it's most random)
                SWAP    D0
                ext.l   d0
                DIVs    D2,D0           ;divide by range...
                CLR.W   D0              ;...and use remainder for the value
                SWAP    D0              ;result in D0.W
r1:             MOVE.W  (SP)+,D2
                RTS

randomplus:     MOVE.W  D2,-(SP)
                MOVE.W  D0,D2           ;save upper limit
                BEQ.S   r2              ;range of 0 returns 0 always
                BSR.S   LongRnd         ;get a longword random number
                CLR.W   D0              ;use upper word (it's most random)
                SWAP    D0
                DIVu    D2,D0           ;divide by range...
                CLR.W   D0              ;...and use remainder for the value
                SWAP    D0              ;result in D0.W
r2:             MOVE.W  (SP)+,D2
                RTS
*********************************************************
*       a brilliant routine courtesy of janko to        *
*       insert the vbi addresses in the jump table      *
*       lea address of routine in a0 do a jsr           *
*       putvbl and thats it!!!                          *
*********************************************************


putvbl: lea     $452,a1
        move.w  #1,(a1)
        moveq   #7,d1
        lea     $456,a1
        move.l  (a1),a1
vbl3:   subq.b  #1,d1
        cmpi.b  #0,d1
        beq.s   vbl4
        move.l  (a1)+,d0
        cmpi.l  #0,d0
        bne.S   vbl3
        suba.l  #4,a1
        move.l  a0,(a1)
vbl4:   rts


oldvbl1:	
	blk.l	1,0
oldvbl2:
	blk.l	1,0
oldvbl3:
	blk.l	1,0

*********************************************************
*       my routines for loading in the screens          *
*********************************************************
loadscreen:
	move    #0,-(SP)        ;Open file
        move.l  #filename,-(SP) ;Address of filename
        move    #$3D,-(SP)
        trap    #1              ;Get handle number in D0
        addq.l  #8,SP
                
        move    D0,-(SP)        ;Save handle

        move.l  #dummy,-(SP)    ;load pallette into safe area
        move.l  #128,-(SP)       ;length to read in
        move    D0,-(SP)        ;Handle
        move    #$3F,-(SP)      ;bios number
        trap    #1              ;Read file in
        addi.l   #12,SP
        move    (sp),d0        
               
        move.l  hiden,-(SP)    ;load it straight onto screen
        move.l  #32000,-(SP)    ;length to read in
        move    D0,-(SP)        ;Handle
        move    #$3F,-(SP)      ;bios number
        trap    #1              ;Read file in
        addi.l   #12,SP
                
        move    #$3E,-(SP)      ;Handle already on stack
        trap    #1              ;Close file
        addq.l  #4,SP
        rts
filename:
	dc.b	'frac.neo',0
even

*********************************************************
*********************************************************
loadtitle:
	move    #0,-(SP)        ;Open file
        move.l  #filescreen3,-(SP) ;Address of filename
        move    #$3D,-(SP)
        trap    #1              ;Get handle number in D0
        addq.l  #8,SP
                
        move    D0,-(SP)        ;Save handle

        move.l  #dummy,-(SP)    ;load pallette into safe area
        move.l  #128,-(SP)       ;length to read in
        move    D0,-(SP)        ;Handle
        move    #$3F,-(SP)      ;bios number
        trap    #1              ;Read file in
        addi.l   #12,SP
        move    (sp),d0        
               
*        move.l  screen4,-(SP)    ;load it straight onto screen
        move.l  #32000,-(SP)    ;length to read in
        move    D0,-(SP)        ;Handle
        move    #$3F,-(SP)      ;bios number
        trap    #1              ;Read file in
        addi.l   #12,SP
                
        move    #$3E,-(SP)      ;Handle already on stack
        trap    #1              ;Close file
        addq.l  #4,SP
        rts

filescreen3:
	dc.b	'title.neo',0
	even
******************************
*******************blocks for rotated sprites*************
myshipbuffer:
	blk.w	1920,0

myshipmask:
	blk.w	960,0
offset:	blk.w	1,0
origptr:	blk.l	1,0
screen3:blk.l   1,0
pblock: blk.l   50
screen: blk.l   1
screen2:blk.l   1
screen1:blk.l   1
dummy:  blk.l   32
line:   blk.b   10
number: blk.w   1
even
ships:	blk.w	1,0
intin:  blk.l   1
ptsin:  blk.l   1
putpix: equ     $a001
getpix: equ     $a002
seen:   blk.l   1
hiden:  blk.l   1
palette2:
        dc.w    $0000,$0000,$0000
        dc.w    $0000,$0000,$0000
        dc.w    $0000,$0000,$0000
        dc.w    $0000,$0000,$0000
        dc.w    $0000,$0000,$0000
        dc.w    $0000
rnd:            blk.l   2,0
score:          blk.w   1,0
level:          blk.w   1,0
linepar:        blk.l   1,0
pulsecol:	blk.w	1,0

titlepalette:
	dc.w	$0000,$0777,$0555,$0333,$0007,$0005,$0004,$0477
	dc.w	$0366,$0244,$0570,$0460,$0340,$0700,$0600,$0700
land1palette:
	dc.w	$0000,$0223,$0334,$0556,$0667,$0700,$0400,$0070
	dc.w	$0030,$0507,$0406,$0305,$0304,$0333,$0555,$0777

temppal:
	blk.l	1,0

numbers:
	 dc.b	$7F,$FF,$FF,$FF,$81,$01,$FF,$81
	 dc.b	$81,$1D,$FF,$9D,$81,$1D,$FF,$9D
	 dc.b	$81,$1D,$FF,$9D,$81,$1D,$FF,$9D
	 dc.b	$81,$1D,$FF,$9D,$81,$01,$FF,$81
	 dc.b	$81,$01,$FF,$81,$FE,$01,$FF,$FF
	 dc.b	$7F,$FF,$FF,$FF,$81,$67,$FF,$E7
	 dc.b	$81,$47,$FF,$C7,$81,$67,$FF,$E7
	 dc.b	$81,$67,$FF,$E7,$81,$67,$FF,$E7
	 dc.b	$81,$67,$FF,$E7,$81,$67,$FF,$E7
	 dc.b	$81,$67,$FF,$E7,$FE,$01,$FF,$FF
	 dc.b	$7F,$FF,$FF,$FF,$81,$01,$FF,$81
	 dc.b	$81,$3D,$FF,$BD,$81,$7D,$FF,$FD
	 dc.b	$81,$01,$FF,$81,$81,$1F,$FF,$9F
	 dc.b	$81,$1F,$FF,$9F,$81,$1D,$FF,$9D
	 dc.b	$81,$01,$FF,$81,$FE,$01,$FF,$FF
	 dc.b	$7F,$FF,$FF,$FF,$81,$01,$FF,$81
	 dc.b	$81,$3D,$FF,$BD,$81,$7D,$FF,$FD
	 dc.b	$81,$41,$FF,$C1,$81,$79,$FF,$F9
	 dc.b	$81,$79,$FF,$F9,$81,$39,$FF,$B9
	 dc.b	$81,$01,$FF,$81,$FE,$01,$FF,$FF
	 dc.b	$7F,$FF,$FF,$FF,$81,$1D,$FF,$9D
	 dc.b	$81,$1D,$FF,$9D,$81,$1D,$FF,$9D
	 dc.b	$81,$01,$FF,$81,$81,$79,$FF,$F9
	 dc.b	$81,$79,$FF,$F9,$81,$79,$FF,$F9
	 dc.b	$81,$79,$FF,$F9,$FE,$01,$FF,$FF
	 dc.b	$7F,$FF,$FF,$FF,$81,$01,$FF,$81
	 dc.b	$81,$1F,$FF,$9F,$81,$1F,$FF,$9F
	 dc.b	$81,$01,$FF,$81,$81,$7D,$FF,$FD
	 dc.b	$81,$7D,$FF,$FD,$81,$3D,$FF,$BD
	 dc.b	$81,$01,$FF,$81,$FE,$01,$FF,$FF
	 dc.b	$7F,$FF,$FF,$FF,$81,$01,$FF,$81
	 dc.b	$81,$1D,$FF,$9D,$81,$1F,$FF,$9F
	 dc.b	$81,$01,$FF,$81,$81,$1D,$FF,$9D
	 dc.b	$81,$1D,$FF,$9D,$81,$1D,$FF,$9D
	 dc.b	$81,$01,$FF,$81,$FE,$01,$FF,$FF
	 dc.b	$7F,$FF,$FF,$FF,$81,$01,$FF,$81
	 dc.b	$81,$39,$FF,$B9,$81,$79,$FF,$F9
	 dc.b	$81,$79,$FF,$F9,$81,$79,$FF,$F9
	 dc.b	$81,$79,$FF,$F9,$81,$79,$FF,$F9
	 dc.b	$81,$79,$FF,$F9,$FE,$01,$FF,$FF
	 dc.b	$7F,$FF,$FF,$FF,$81,$01,$FF,$81
	 dc.b	$81,$1D,$FF,$9D,$81,$1D,$FF,$9D
	 dc.b	$81,$01,$FF,$81,$81,$1D,$FF,$9D
	 dc.b	$81,$1D,$FF,$9D,$81,$1D,$FF,$9D
	 dc.b	$81,$01,$FF,$81,$FE,$01,$FF,$FF
	 dc.b	$7F,$FF,$FF,$FF,$81,$01,$FF,$81
	 dc.b	$81,$1D,$FF,$9D,$81,$1D,$FF,$9D
	 dc.b	$81,$01,$FF,$81,$81,$79,$FF,$F9
	 dc.b	$81,$79,$FF,$F9,$81,$79,$FF,$F9
	 dc.b	$81,$79,$FF,$F9,$FE,$01,$FF,$FF
rsprite:
	 dc.w	$0000,$0000,$FFF0,$0000,$0000,$0008,$9040,$0000
	 dc.w	$0000,$0000,$9024,$0000,$0000,$0000,$9024,$0000
	 dc.w	$0000,$0000,$9024,$0000,$0000,$0000,$9058,$0000
	 dc.w	$4000,$0000,$9FE0,$4000,$6600,$0000,$9900,$6600
	 dc.w	$6300,$0000,$9480,$6300,$0000,$0000,$9240,$6180
	 dc.w	$0000,$0000,$9120,$60C0,$6060,$6060,$F0F0,$0000
	 dc.w	$6030,$6030,$F078,$0000,$0000,$0000,$F03C,$0000

asprite:
	 dc.w	$0000,$0010,$3FE0,$0000,$0008,$0000,$4840,$0000
	 dc.w	$0000,$0000,$9024,$0000,$0000,$0000,$9024,$0000
	 dc.w	$0000,$0000,$9024,$0000,$0000,$0000,$9024,$0000
	 dc.w	$4008,$0000,$9024,$4008,$6018,$0000,$9FE4,$6018
	 dc.w	$6018,$0000,$9024,$6018,$0000,$0000,$9024,$6018
	 dc.w	$0000,$0000,$9024,$6018,$6018,$6018,$F03C,$0000
	 dc.w	$6018,$6018,$F03C,$0000,$0000,$0000,$F03C,$0000

msprite:
	 dc.w	$2000,$4000,$8007,$0000,$0000,$0000,$9009,$0000
	 dc.w	$0000,$0000,$8811,$0000,$0000,$0000,$8421,$0000
	 dc.w	$0000,$0000,$9249,$0000,$0000,$0000,$9999,$0000
	 dc.w	$4242,$0000,$9429,$4242,$6186,$0000,$9249,$6186
	 dc.w	$6006,$0000,$9189,$6006,$0000,$0000,$9009,$6006
	 dc.w	$0000,$0000,$9009,$6006,$6006,$6006,$F00F,$0000
	 dc.w	$6006,$6006,$F00F,$0000,$0000,$0000,$F00F,$0000

wsprite:
	 dc.w	$0041,$0002,$F38C,$0000,$0000,$0001,$9248,$0000
	 dc.w	$0000,$0000,$9249,$0000,$0000,$0000,$9249,$0000
	 dc.w	$0002,$0000,$9249,$0002,$0086,$0000,$9249,$0086
	 dc.w	$4186,$0000,$9249,$4186,$6180,$0000,$9249,$6186
	 dc.w	$6000,$0000,$9249,$6186,$0006,$0006,$924F,$6180
	 dc.w	$0186,$0186,$93CF,$6000,$6184,$6184,$F3CF,$0000
	 dc.w	$6000,$6000,$F7DE,$0000,$0000,$0000,$FEF8,$0000

esprite:
	 dc.w	$0004,$0008,$FFF0,$0000,$0000,$0000,$9000,$0000
	 dc.w	$0000,$0000,$9000,$0000,$0000,$0000,$9000,$0000
	 dc.w	$0000,$0000,$9000,$0000,$0000,$0000,$9000,$0000
	 dc.w	$2010,$0020,$9FC0,$2000,$6000,$0000,$9000,$6000
	 dc.w	$6000,$0000,$9000,$6000,$0000,$0000,$9000,$6000
	 dc.w	$0000,$0000,$9000,$6000,$6000,$6000,$F000,$0000
	 dc.w	$6000,$6000,$F000,$0000,$0000,$0000,$FFFC,$0000

even
*350
rampat:
 dc.w 161,022
 dc.w 160,022
 dc.w 159,022
 dc.w 158,022
 dc.w 157,022
 dc.w 156,022
 dc.w 154,022
 dc.w 152,022
 dc.w 150,022
 dc.w 149,022
 dc.w 147,022
 dc.w 146,022
 dc.w 144,022
 dc.w 142,022
 dc.w 140,022
 dc.w 139,022
 dc.w 137,022
 dc.w 136,022
 dc.w 134,022
 dc.w 132,022
 dc.w 131,021
 dc.w 129,020
 dc.w 127,020
 dc.w 126,019
 dc.w 124,018
 dc.w 122,017
 dc.w 121,016
 dc.w 119,015
 dc.w 118,014
 dc.w 117,013
 dc.w 116,012
 dc.w 116,011
 dc.w 116,010
 dc.w 116,009
 dc.w 116,008
 dc.w 117,007
 dc.w 118,006
 dc.w 118,005
 dc.w 120,004
 dc.w 121,003
 dc.w 122,002
 dc.w 123,001
 dc.w 125,001
 dc.w 126,000
 dc.w 127,000
 dc.w 128,000
 dc.w 129,000
 dc.w 130,000
 dc.w 131,000
 dc.w 132,000
 dc.w 133,000
 dc.w 134,000
 dc.w 135,001
 dc.w 135,002
 dc.w 136,003
 dc.w 137,004
 dc.w 138,005
 dc.w 138,007
 dc.w 138,009
 dc.w 138,010
 dc.w 138,011
 dc.w 138,012
 dc.w 138,013
 dc.w 138,014
 dc.w 137,015
 dc.w 135,016
 dc.w 133,017
 dc.w 132,017
 dc.w 131,017
 dc.w 129,017
 dc.w 127,017
 dc.w 126,017
 dc.w 124,017
 dc.w 123,017
 dc.w 122,017
 dc.w 121,017
 dc.w 121,016
 dc.w 120,016
 dc.w 120,014
 dc.w 120,013
 dc.w 120,011
 dc.w 120,010
 dc.w 120,008
 dc.w 121,007
 dc.w 122,006
 dc.w 123,005
 dc.w 124,004
 dc.w 126,003
 dc.w 127,002
 dc.w 129,001
 dc.w 131,000
 dc.w 133,000
 dc.w 135,000
 dc.w 138,000
 dc.w 140,000
 dc.w 142,000
 dc.w 144,000
 dc.w 146,000
 dc.w 148,000
 dc.w 150,000
 dc.w 151,000
 dc.w 154,000
 dc.w 156,000
 dc.w 159,000
 dc.w 161,000
 dc.w 164,000
 dc.w 166,000
 dc.w 168,000
 dc.w 171,000
 dc.w 173,000
 dc.w 175,000
 dc.w 178,000
 dc.w 180,000
 dc.w 183,000
 dc.w 186,000
 dc.w 188,000
 dc.w 190,000
 dc.w 192,000
 dc.w 194,000
 dc.w 197,000
 dc.w 200,000
 dc.w 202,000
 dc.w 204,000
 dc.w 207,000
 dc.w 210,000
 dc.w 212,000
 dc.w 215,000
 dc.w 217,000
 dc.w 219,000
 dc.w 221,000
 dc.w 223,000
 dc.w 225,000
 dc.w 226,000
 dc.w 228,000
 dc.w 230,000
 dc.w 231,000
 dc.w 234,000
 dc.w 236,000
 dc.w 238,000
 dc.w 240,000
 dc.w 242,000
 dc.w 243,000
 dc.w 245,000
 dc.w 246,000
 dc.w 248,000
 dc.w 250,000
 dc.w 251,000
 dc.w 253,000
 dc.w 254,000
 dc.w 256,000
 dc.w 258,000
 dc.w 259,000
 dc.w 261,000
 dc.w 263,000
 dc.w 265,000
 dc.w 266,000
 dc.w 268,000
 dc.w 270,001
 dc.w 272,001
 dc.w 273,001
 dc.w 274,001
 dc.w 276,002
 dc.w 277,002
 dc.w 278,003
 dc.w 279,003
 dc.w 280,004
 dc.w 280,005
 dc.w 280,006
 dc.w 281,007
 dc.w 281,008
 dc.w 282,009
 dc.w 282,011
 dc.w 282,012
 dc.w 282,013
 dc.w 282,015
 dc.w 282,016
 dc.w 282,017
 dc.w 282,018
 dc.w 281,019
 dc.w 281,020
 dc.w 280,021
 dc.w 279,022
 dc.w 278,022
 dc.w 276,022
 dc.w 274,022
 dc.w 272,022
 dc.w 270,022
 dc.w 268,022
 dc.w 267,022
 dc.w 265,022
 dc.w 263,022
 dc.w 262,022
 dc.w 261,020
 dc.w 260,019
 dc.w 259,018
 dc.w 259,016
 dc.w 259,015
 dc.w 259,014
 dc.w 259,012
 dc.w 259,011
 dc.w 259,010
 dc.w 259,009
 dc.w 260,008
 dc.w 261,007
 dc.w 262,006
 dc.w 263,005
 dc.w 264,004
 dc.w 265,003
 dc.w 266,003
 dc.w 267,002
 dc.w 268,002
 dc.w 269,002
 dc.w 270,002
 dc.w 272,002
 dc.w 274,002
 dc.w 275,002
 dc.w 276,002
 dc.w 277,003
 dc.w 278,003
 dc.w 278,004
 dc.w 279,005
 dc.w 279,007
 dc.w 280,007
 dc.w 280,009
 dc.w 280,011
 dc.w 280,012
 dc.w 280,013
 dc.w 280,014
 dc.w 279,015
 dc.w 279,016
 dc.w 279,017
 dc.w 278,018
 dc.w 277,019
 dc.w 275,020
 dc.w 274,021
 dc.w 273,022
 dc.w 272,022
 dc.w 271,022
 dc.w 270,022
 dc.w 269,022
 dc.w 267,022
 dc.w 266,022
 dc.w 265,022
 dc.w 263,022
 dc.w 262,022
 dc.w 261,022
 dc.w 259,022
 dc.w 258,022
 dc.w 257,022
 dc.w 256,022
 dc.w 255,022
 dc.w 254,022
 dc.w 253,022
 dc.w 252,022
 dc.w 251,022
 dc.w 250,022
 dc.w 249,022
 dc.w 248,022
 dc.w 247,022
 dc.w 246,022
 dc.w 245,022
 dc.w 244,022
 dc.w 243,022
 dc.w 242,022
 dc.w 241,022
 dc.w 240,022
 dc.w 239,022
 dc.w 238,022
 dc.w 237,022
 dc.w 236,022
 dc.w 235,022
 dc.w 234,022
 dc.w 233,022
 dc.w 232,022
 dc.w 231,022
 dc.w 230,022
 dc.w 229,022
 dc.w 228,022
 dc.w 227,022
 dc.w 226,022
 dc.w 225,022
 dc.w 224,022
 dc.w 223,022
 dc.w 222,022
 dc.w 221,022
 dc.w 220,022
 dc.w 219,022
 dc.w 218,022
 dc.w 217,022
 dc.w 216,022
 dc.w 215,022
 dc.w 214,022
 dc.w 213,022
 dc.w 212,022
 dc.w 211,022
 dc.w 210,022
 dc.w 209,022
 dc.w 208,022
 dc.w 207,022
 dc.w 206,022
 dc.w 205,022
 dc.w 204,022
 dc.w 203,022
 dc.w 202,022
 dc.w 201,022
 dc.w 200,022
 dc.w 199,022
 dc.w 198,022
 dc.w 197,022
 dc.w 196,022
 dc.w 195,022
 dc.w 194,022
 dc.w 193,022
 dc.w 192,022
 dc.w 191,022
 dc.w 190,022
 dc.w 189,022
 dc.w 188,022
 dc.w 187,022
 dc.w 186,022
 dc.w 185,022
 dc.w 184,022
 dc.w 183,022
 dc.w 182,022
 dc.w 181,022
 dc.w 180,022
 dc.w 179,022
 dc.w 178,022
 dc.w 177,022
 dc.w 176,022
 dc.w 175,022
 dc.w 174,022
 dc.w 173,022
 dc.w 172,022
 dc.w 171,022
 dc.w 170,022
 dc.w 169,022
 dc.w 168,022
 dc.w 167,022
 dc.w 166,022
 dc.w 165,022
 dc.w 164,022
 dc.w 163,022
 dc.w 162,022
 dc.w 161,022
 dc.w 160,022
 dc.w 159,022
 dc.w 158,022
 dc.w 157,022
 dc.w 156,022
 dc.w 175,022
