	section andy,code_c
	opt c-

	*************************
	* Setup V2.1 Rev.3/3/90 *
	*************************

startlist1	equ	38
startlist2	equ	50

plnw		equ	40
plnh		equ	256
plnsize		equ	plnw*plnh
plnnum		equ	1
plndata		equ	plnsize*plnnum

	move.l	4,a6
	move.l	#$10002,d1
	move.l	#plndata,d0
	jsr	-198(a6)
	cmp.l	#$00,d0
	beq	error
	move.l	d0,plnbase

	move.l	4,a6
	move.l	#gfxname,a1
	moveq.l	#0,d0
	jsr	-552(a6)
	move.l	d0,gfxbase

	MOVE.W	#$0080,$dff096
	move.w	$dff01c,sysint
	or.w	#$c000,sysint
	move.w	#$7fff,$dff09a
	move.w	#$c020,$dff09a
	move.l	$6c,intsave
	move.l	#newcopper,$dff080
	clr.w	$dff088
	move.w	#$8480,$dff096	
	move.l	plnbase,a1
	move.l	#plnsize,d0
	move.l	a1,stor
	move.l	stor,pln1
	move.w	stor,bp1+2
	move.w	stor+2,bp1+6

	jsr	killspr
	jsr	stars_on

	move.w	#0,$dff180
	move.l	#isr,$6c

wait:	jsr	task			;jmp to our sub.
	btst	#6,$bfe001		;wait for mouse.
	bne	wait
	move.l	gfxbase,a4
	move.l	startlist1(a4),$dff080
	move.l	startlist2(a4),$dff084
	clr.w	$dff088	
	move.l	intsave,$6c
	move.w	sysint,$dff09a
	move.w	#$8080,$dff096
	move.w	#$0400,$dff096
	move.l	4,a6
	move.l	plnbase,a1
	move.l	#plndata,d0
	jsr	-210(a6)
	move.l	gfxbase,a1
	jsr	-414(a6)

error:	move.w	#$0fff,$dff180
	rts				;exit.

newcopper:					
	dc.w	$0100,$1200
scrl:	dc.w	$0102,$0000

bp1:	dc.w	$00e0,$0000,$00e2,$0000
bp2:	dc.w	$00e4,$0000,$00e6,$0000
bp3:	dc.w	$00e8,$0000,$00ea,$0000
bp4:	dc.w	$00ec,$0000,$00ee,$0000
bp5:	dc.w	$00f0,$0000,$00f2,$0000

	dc.w	$008E,$2c81,$0090,$2cc1                                 
	dc.w	$0092,$0038,$0094,$00d0
mod:	dc.w	$0108,$0000,$010a,$0000

sp0:	dc.w	$0120,$0000,$0122,$0000	
sp1:	dc.w	$0124,$0000,$0126,$0000	
sp2:	dc.w	$0128,$0000,$012a,$0000	
sp3:	dc.w	$012c,$0000,$012e,$0000	
sp4:	dc.w	$0130,$0000,$0132,$0000	
sp5:	dc.w	$0134,$0000,$0136,$0000	
sp6:	dc.w	$0138,$0000,$013a,$0000	
sp7:	dc.w	$013c,$0000,$013e,$0000	

	dc.w	$01a2,$0fff
	dc.w	$01a4,$088f
	dc.w	$01a6,$000f
	dc.w	$01aa,$0fff
	dc.w	$01ac,$088f
	dc.w	$01ae,$000f

	dc.w	$ffff,$fffe
	
gfxname:dc.b	'graphics.library',0
	even
gfxbase:dc.l	0

stor:	dc.l	0
pln1:	dc.l	0
pln2:	dc.l	0
pln3:	dc.l	0
pln4:	dc.l	0
pln5:	dc.l	0
sysint:	dc.w	0
intsave:dc.l	0
plnbase:dc.l	0

isr:	movem.l	d0-d7/a0-a6,-(sp)
	move.w	#$0020,$dff09c
	movem.l	(sp)+,d0-d7/a0-a6
	rte

task:	move.w	$dff006,d0
	and.w	#$ff00,d0
	cmp.w	#$ff00,d0
	bne	task
	jsr	Star_move
	rts


	*****************************
	*Note:-       		    *
	* A-Obj       		    *
	* B-Msk                     *
	* C-Bck                     *
	* D-Bck                     *
	* M-00001111 10111000       *
	*****************************



killspr:
	move.l	#blnkspr,d0

	move.w	d0,sp0+6
	move.w	d0,sp1+6
	move.w	d0,sp2+6
	move.w	d0,sp3+6
	move.w	d0,sp4+6
	move.w	d0,sp5+6
	move.w	d0,sp6+6
	move.w	d0,sp7+6
	swap	d0
	move.w	d0,sp0+2
	move.w	d0,sp1+2
	move.w	d0,sp2+2
	move.w	d0,sp3+2
	move.w	d0,sp4+2
	move.w	d0,sp5+2
	move.w	d0,sp6+2
	move.w	d0,sp7+2
	rts	
blnkspr:ds.l	4

	****************************************
	*    Multi-purpose Stafield Creator    *
	*				       *	
	*        Written by Andy Clark         *	
	*				       *	
	*           3rd August 1990	       *	
	*				       *	
	*      Strictly for use by anyone      *	
	****************************************

	****************************************
	*     Use the four equates for fx      *	
	****************************************
	
star_top	equ	$2c		;first line
star_height	equ	250		;number of lines
density		equ	2		;density of stars (0-3)
direction	equ	0		;0-right 1-left

	****************************************
	*     Use the four equates for fx      *	
	****************************************

star0:	dc.w	%0000000000000110,%0000000000000111		;slow
star1:	dc.w	%0000000000011001,%0000000000011110		;med
star2:	dc.w	%0000000111000111,%0000000111111000		;fast

den:	dc.b	3,7,15,31

numst0:	dc.w	0
numst1:	dc.w	0
numst2:	dc.w	0

stary:	dc.w	0	;current y position
stardat:dc.l	0	;data for display
starcnt:dc.l	0	;number of lines used
msb:	dc.w	0	;gmt check
dens:	dc.l	0	;density store

	** Call this once to set up stars
	** Attention: You must have sp0-2 defined on copper list	

Stars_on:
	lea	den,a0
	move.l	#density,d0
	move.b	(a0,d0),dens+3

	lea	st0,a0
	move.l	star0,d0
	jsr	setstars
	lea	st1,a0
	move.l	star1,d0
	jsr	setstars
	lea	st2,a0
	move.l	star2,d0
	jsr	setstars

	move.l	#st0,d0
	move.w	d0,sp0+6
	swap	d0
	move.w	d0,sp0+2

	move.l	#st1,d0
	move.w	d0,sp1+6
	swap	d0
	move.w	d0,sp1+2

	move.l	#st2,d0
	move.w	d0,sp2+6
	swap	d0
	move.w	d0,sp2+2

	rts

	** Call this every frame

Setstars:
	move.b	#0,msb
	move.b	#star_top,stary
	move.l	d0,stardat
	move.l	#0,starcnt

.lp2:	jsr	random
	and.l 	dens,d1
	add.b	d1,stary	;updt stary position
	bcc	.lp3		;over gmt?
	move.b	#1,msb
.lp3:	add.l	d1,starcnt	;inc count
	move.l	#star_height,d0
	cmp.l	starcnt,d0
	blt	.lp		;reached end
	move.b	stary,(a0)	;set ystart
	bclr.b	#2,3(a0)
	tst.b	msb		;check over
	beq	.lp5
	bset.b	#2,3(a0)
.lp5:	move.b	stary,2(a0)	
	add.b	#1,2(a0)	;set ystop
	bcc	.lp4
	move.b	#1,msb
.lp4:	bclr.b	#1,3(a0)
	tst.b	msb		;check over
	beq	.lp6
	bset.b	#1,3(a0)
.lp6:	jsr	random
	move.b	d1,1(a0)	;set xpos
	add.b	#2,stary	;updt for next y position
	add.l	#4,a0		;point to data
	move.l	stardat,(a0)+	;put data into display
	add.l	#2,starcnt	;in count
	move.l	#star_height,d0
	cmp.l	starcnt,d0
	blt	.lp		;reached end
	bra	.lp2		;get next star
.lp:	move.l	#0,(a0)
	rts

Star_move:
	lea	st0,a0
	move.l	#1,d0		;speed
	jsr	stmov
	lea	st1,a0
	move.l	#2,d0		;speed
	jsr	stmov
	lea	st2,a0
	move.l	#3,d0		;speed
	jsr	stmov
	rts
stmov:	move.l	#direction,d1
	beq	.lp
	neg.l	d0
.lp	add.b	d0,1(a0)
	add.l	#8,a0
	tst.l	(a0)
	bne	.lp
	rts

random	moveq.l	#0,d1
	lea	$fc0000,a6
	move.l	framecount,d5
	move.b	(a6,d5),d1
	subq.l	#1,a6
	and.l	#$07,d5
	lea	rseed,a6
	move.b	(a6,d5),d5
	eor.b	d5,d1
	add.l	#$01,framecount
	cmp.l	#2000,framecount
	blt	noz2
	move.l	#0,framecount
noz2	rts
rseed	dc.b	$94,$2f,$47,$e2,$13,$c5,$76,$89
framecount:
	dc.l	0

st0:	ds.b	200*4
st1:	ds.b	200*4
st2:	ds.b	200*4

	****************************************
	*     Bottom of Starfield Routine      *	
	****************************************

