	include	mystartup
	STARTUP

	lea	500*1024,a0
	move.l	#rndloc,d0
rndmake	move.l	-(a0),d1
	eor.l	d1,d0
	move.l	a0,d1
	bpl.s	rndmake
	move.l	d0,rndR
	bsr.w	kkkk
	move.l	#text,d0
	move.l	d0,txt

rndloc	lea	$dff000,a5
	move.l	#screen,d0
	move.w	d0,pl1l	
	swap	d0
	move.w	d0,pl1h
	move.l	#screen+80*256,d0
	move.w	d0,pl2l
	swap	d0
	move.w	d0,pl2h
	move.l	#screen+80*256*2,d0
	move.w	d0,pl3l
	swap	d0
	move.w	d0,pl3h
	move.l	#screen+80*256*3,d0
	move.w	d0,pl4l
	swap	d0
	move.w	d0,pl4h

	move.l	#sprites,d0
	moveq	#7,d1
	lea	sprite+2,a0
nexspr	swap	d0
	move.w	d0,(a0)
	add.l	#4,a0
	swap	d0
	move.w	d0,(a0)
	add.l	#4,a0
	dbf.w	d1,nexspr

	move.w	#$83c0,dmacon(a5)
	move.l	#server,$6c.w
	move.w	#$c020,$9a(a5)
	move.l	#new_copper,$80(a5)


loop
	btst	#6,$bfe001
	bne.s	loop


	STARTEND


kkkk
	move.l	#screen,d4
	move.l	d4,a0
	bsr.w	kkkk2
	move.l	#screen+256*80,d4
	move.l	rndR,d0
	and.l	rndR+4,d0
	move.l	d0,rndR
	move.l	rndR+4,d0
	and.l	rndR+8,d0
	move.l	d0,rndR+4
	move.l	rndR,d1
	eor.l	d1,d0
	and.l	rndR+8,d0
	move.l	d0,rndR+8
	move.l	d4,a0
	bsr.w	kkkk2
	move.l	rndR,d0
	and.l	rndR+4,d0
	move.l	d0,rndR
	move.l	rndR+4,d0
	and.l	rndR+8,d0
	move.l	d0,rndR+4
	move.l	rndR,d1
	eor.l	d1,d0
	and.l	rndR+8,d0
	move.l	d0,rndR+8

	move.l	#screen+256*80*2,d4
	move.l	d4,a0
kkkk2	moveq	#31,d3
nexrnsp	move.l	rndR,d0
	move.l	rndR+4,d1
	move.l	d1,rndR
	add.l	d1,d0
	move.l	rndR+8,d1
	move.l	d1,rndR+4
	add.l	d1,d0
	rol.l	#1,d0
	move.l	d0,rndR+8
	move.l	d0,(a0)
	move.l	d0,16(a0)
	move.l	d0,32(a0)
	move.l	d0,48(a0)
	move.l	d0,64(a0)
	moveq	#31,d2
nexrot1	lsr.l	#1,d0
	roxl.l	#1,d1
	dbf.w	d2,nexrot1
	move.l	d1,12(a0)
	move.l	d1,12+16(a0)
	move.l	d1,12+32(a0)
	move.l	d1,12+48(a0)
	move.l	d1,12+64(a0)

	move.l	rndR,d0
	move.l	rndR+4,d1
	move.l	d1,rndR
	add.l	d1,d0
	move.l	rndR+8,d1
	move.l	d1,rndR+4
	add.l	d1,d0
	rol.l	#1,d0
	move.l	d0,rndR+8
	move.l	d0,4(a0)
	move.l	d0,4+16(a0)
	move.l	d0,4+32(a0)
	move.l	d0,4+48(a0)
	move.l	d0,4+64(a0)
	moveq	#31,d2
nexrot2	lsr.l	#1,d0
	roxl.l	#1,d1
	dbf.w	d2,nexrot2
	move.l	d1,8(a0)
	move.l	d1,8+16(a0)
	move.l	d1,8+32(a0)
	move.l	d1,8+48(a0)
	move.l	d1,8+64(a0)

	add.l	#80,a0
	dbf.w	d3,nexrnsp

	move.l	#80*31,a1
	add.l	d4,a1
	moveq	#31,d3
copy2rd	swap	d3
	move.w	#19,d3
copy1rd	move.l	(a1)+,(a0)+
	dbf.w	d3,copy1rd
	sub.l	#160,a1
	swap	d3
	dbf.w	d3,copy2rd

	move.l	d4,a1
	move.w	#64*20*3-1,d0
copy3rd	move.l	(a1)+,(a0)+
	dbf.w	d0,copy3rd
	rts

server
	movem.l	d0-d7/a0-a6,-(a7)
	lea	$dff000,a5
	move.w	#$20,intreq(a5)	

	move.l	vott,d0
	sub.l	#1,d0
	bne.s	nonew
	move.l	txt,a0
	cmp.b	#10,(a0)
	bne.s	nonewc
	lea	text,a0
nonewc	move.b	(a0)+,d0
	move.l	a0,txt
	sub.w	#32,d0
	asl.w	#3,d0
	lea	font,a0
	add.l	d0,a0
	lea	buffer,a1
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	move.l	#8,d0
nonew	move.l	d0,vott
	lea	screen+3*256*80+125*80,a0
	lea	buffer,a1
	moveq	#7,d1
nexpri1	moveq	#39,d0
	clr.w	d2
	move.b	(a1),d2
	roxl.b	d2
	move.b	d2,(a1)+
nexpri2	roxl	-(a0)
	dbf.w	d0,nexpri2
	add.l	#160,a0
	dbf.w	d1,nexpri1

	lea	$dff000,a5
	movem.l	(a7)+,d0-d7/a0-a6
	rte

	section	chip,data_c
new_copper
	dc.w	bplcon0,$c201
	dc.w	bplcon1,0
	dc.w	bplcon2,$0
	dc.w	bpl1mod,0
	dc.w	bpl2mod,0
	dc.w	ddfstrt,$3c
	dc.w	ddfstop,$d4
	dc.w	diwstrt,$2c81
	dc.w	diwstop,$2cc1

	dc.w	$180,0
copcol	dc.w	$182,$113
	dc.w	$184,$325
	dc.w	$186,$436
	dc.w	$188,$648
	dc.w	$18a,$85a
	dc.w	$18c,$a6b
	dc.w	$18e,$b7c
overcol	set	$190
	rept	8
	dc.w	overcol,$fff
overcol	set	overcol+2
	endr

sprite	dc.w	$0120,$0000,$0122,$0000,$0124,$0000,$0126,$0000
	dc.w	$0128,$0000,$012a,$0000,$012c,$0000,$012e,$0000
	dc.w	$0130,$0000,$0132,$0000,$0134,$0000,$0136,$0000
	dc.w	$0138,$0000,$013a,$0000,$013c,$0000,$013e,$0000
	dc.w	bpl1pth
pl1h	dc.w	0,bpl1ptl
pl1l	dc.w	0,bpl2pth
pl2h	dc.w	0,bpl2ptl
pl2l	dc.w	0,bpl3pth
pl3h	dc.w	0,bpl3ptl
pl3l	dc.w	0,bpl4pth
pl4h	dc.w	0,bpl4ptl
pl4l	dc.w	0

	dc.w	$1FC,$0
;	dc.w	$106,$c40
	dc.w	$ffff,$fffe

	cnop	0,8
sprites	dc.l	0,0,0,0
screen		ds.b	4*(80*256)
rndR	dc.l	$0,0,0

buffer	dc.l	0,0
vott	dc.l	8
txt	dc.l	0
text	incbin	begtro.txt
font	incbin	ibm.fnt

bpl1pth		equ	$e0
bpl1ptl		equ	$e2
bpl2pth		equ	$e4
bpl2ptl		equ	$e6
bpl3pth		equ	$e8
bpl3ptl		equ	$ea
bpl4pth		equ	$ec
bpl4ptl		equ	$ee
