l3,a2
		add.l	(_nmem).w,a2
		moveq	#4,d0
.m3		move.w	(a0)+,d1
		move.w	(a1)+,d6
		bsr	fade
		move.w	d6,(a2,d1.w)
		dbra	d0,.m3

		lea	wcol4,a2
		add.l	(_nmem).w,a2
		moveq	#6,d0
.m4		move.w	(a0)+,d1
		move.w	(a1)+,d6
		bsr	fade
		move.w	d6,(a2,d1.w)
		dbra	d0,.m4


		lea	wcol5,a2
		add.l	(_nmem).w,a2
		move.w	(a0)+,d1
		move.w	(a1)+,d6
		bsr	fade
		move.w	d6,(a2,d1.w)

		lea	wcol6,a2
		add.l	(_nmem).w,a2
		move.w	(a0)+,d1
		move.w	(a1)+,d6
		bsr	fade
		move.w	d6,(a2,d1.w)

		lea	watertab+22,a0
		add.l	(_nmem).w,a0
		moveq	#63,d0
.m5		move.w	#$008,d6
		bsr	fade
		move.w	d6,(a0)
		lea	32(a0),a0
		dbra	d0,.m5

		rts




fade		move.w	d6,d4
		lsr.w	#8,d4
		sub.w	d7,d4
		bpl.s	.c1
		moveq	#0,d4	
.c1		move.w	d6,d3
		lsr.w	#4,d3
		and.w	#$f,d3
		sub.w	d7,d3
		bpl.s	.c2
		moveq	#0,d3
.c2		and.w	#$f,d6
		sub.w	d7,d6
		bpl.s	.c3
		moveq	#0,d6
.c3		lsl.w	#4,d3
		or.w	d3,d6
		lsl.w	#8,d4
		or.w	d4,d6
		rts

setbgcols2	lea	d(pc),a5
		move.w	#64*64+1,d5
		waitblt
		move.l	#$ffffffff,$44(a6)
		move.l	#$0000003a,$64(a6)
		move.w	#$01b2,$74(a6)
		move.l	#$01f00000,$40(a6)
		move.l	#linejmptab+56,$54(a6)
		move.w	#64*140+1,$58(a6)
		waitblt
		move.l	#linejmptab+60*140+204*64+56,$54(a6)
		move.w	#64*144+1,$58(a6)
		waitblt
		move.w	#$00ca,$66(a6)
		move.l	#linejmptab+60*140+200,$54(a6)
		move.w	d5,$58(a6)
		waitblt

		move.l	ysoftabs-d(a5),d4
		move.l	d4,d1
		and.w	#$7,d4
		move.w	absypos-d(a5),d0
		addq.w	#8,d0
		move.w	d0,d6
		sub.w	d4,d0
		move.l	fgcoltab-d(a5),a0
		lea	normpalette+192-d(a5),a2
		lsr.l	#3,d1
		add.w	d1,d1
		move.w	#$019f,d3
		lea	(a2,d1.w),a2
		and.w	#$1f,d1
		add.w	#$0180,d1

		move.l	a2,a4
		sub.l	#$20,a4
		move.w	d1,d5
		lea	colors1,a3
		add.l	(_nmem).w,a3
		moveq	#15,d7
.l2		move.w	d5,(a3)+
		move.w	(a4)+,(a3)+
		addq.w	#2,d5
		and.w	d3,d5
		dbra	d7,.l2

		add.w	d6,d6
		add.w	d6,d6
		move.l	(a0,d6.w),a1
		move.w	d1,(a1)+
		move.w	(a2)+,(a1)+
		addq.w	#2,d1
		and.w	d3,d1
		
		addq.w	#8,d0
		add.w	d0,d0
		add.w	d0,d0
		lea	(a0,d0.w),a0
		moveq	#24,d7
.l1		move.l	(a0),a1
		move.w	d1,(a1)+
		move.w	(a2)+,(a1)+
		addq.w	#2,d1
		and.w	d3,d1
		lea	8*4(a0),a0
		dbra	d7,.l1
		
		rts
;------------------------------------------------
testbgpri	testbgpri_m
;------------------------------------------------
testfall	lea	d(pc),a5
		tst.w	deathflag-d(a5)
		bne	.fall
		tst.w	swsinkflag-d(a5)
		bne	.sink
		clr.w	swsinkflag-d(a5)
		tst.w	bobstand-d(a5)
		bne	.nofall3
		tst.w	bstandflag-d(a5)
		bne	.nofall2
		clr.w	crstandflag-d(a5)
		move.w	#-1,blktype-d(a5)
		tst.w	jumpflag-d(a5)
		bne	.end
		move.l	_xmem,a0
		add.l	#_ldatofs,a0
		move.l	absmanxpos-d(a5),d0
		add.l	#15,d0
		move.l	d0,d1
		move.l	d0,d2
		lsr.l	#4,d0
		add.l	d0,d0
		add.l	#6,d1
		lsr.l	#4,d1
		add.l	d1,d1
		move.l	d2,d4
		addq.l	#3,d2
		lsr.l	#4,d2
		add.l	d2,d2
		lea	(a0,d2.l),a3
		lea	(a0,d1.l),a2
		lea	(a0,d0.l),a0
		move.l	absmanypos-d(a5),d0
		add.l	#64,d0
		move.l	d0,d1
		lsr.l	#4,d0
		mulu	#_levwidth,d0
		add.l	#8,d1
		lsr.l	#4,d1
		mulu	#_levwidth,d1
		move.l	d1,d5
		lea	blocktab-d(a5),a4
		move.w	(a3,d1.l),d2
		and.w	#$3ff,d2
		cmp.b	#3,(a4,d2.w)
		beq	.rough
		lea	(a0,d1.l),a3
		move.w	(a3),d2
		and.w	#$3ff,d2
		cmp.b	#13,(a4,d2.w)
		bpl	.rough2
		lea	(a2,d1.l),a3
		move.w	(a3),d2
		and.w	#$3ff,d2
		cmp.b	#13,(a4,d2.w)
		bpl	.rough2
		lea	(a0,d1.l),a1
		lea	(a0,d0.l),a0
		lea	(a2,d1.l),a3
		lea	(a2,d0.l),a2
		move.w	(a0),d2
		and.w	#$3ff,d2
		move.w	(a1),d1
		and.w	#$3ff,d1
		cmp.b	#1,(a4,d1.w)
		beq.s	.tst1
		cmp.b	#10,(a4,d1.w)
		beq.s	.tst1
		cmp.b	#9,(a4,d1.w)
		beq	.swamp
		cmp.b	#2,(a4,d1.w)
		bne.s	.testfall2
		cmp.b	#2,(a4,d2.w)
		bne	.testcrumble
		bra.s	.testfall2
;.tst3		cmp.b	#9,(a4,d2.w)
;		beq	.swamp
;		bra.s	.testfall2
.tst1		cmp.b	#1,(a4,d2.w)
		beq.s	.testfall2
		cmp.b	#10,(a4,d2.w)
		bne	.nofall

.testfall2	move.w	(a2),d2
		and.w	#$3ff,d2
		move.w	(a3),d1
		and.w	#$3ff,d1
		cmp.b	#1,(a4,d1.w)
		beq.s	.tst2
		cmp.b	#10,(a4,d1.w)
		beq.s	.tst2
		cmp.b	#9,(a4,d1.w)
		beq	.swamp
		cmp.b	#2,(a4,d1.w)
		bne.s	.fall
		cmp.b	#2,(a4,d2.w)
		bne	.testcrumble
		bra.s	.fall
;.tst4		cmp.b	#9,(a4,d2.w)
;		beq.s	.swamp
;		bra.s	.fall
.tst2		cmp.b	#1,(a4,d2.w)
		beq.s	.fall
		cmp.b	#10,(a4,d2.w)
		bne.s	.nofall

.fall		lea	falltab-d(a5),a0
		move.w	fallpos-d(a5),d0
		moveq	#0,d1
		move.w	(a0,d0.w),d1
		add.w	d1,manypos-d(a5)
		add.l	d1,absmanypos-d(a5)
		move.w	d1,fallspeed-d(a5)
		move.w	#1,fallflag-d(a5)
		clr.w	punchcount-d(a5)
		clr.w	punchflag-d(a5)

		cmp.w	#88,d0
		beq.s	.end
		addq.w	#2,fallpos-d(a5)
.end		rts

.nofall		bsr	teststauch
		move.l	absmanypos-d(a5),d0
		and.w	#$7,d0
		and.l	#$fffffff8,absmanypos-d(a5)
		sub.w	d0,manypos-d(a5)
		clr.w	fallpos-d(a5)
		clr.w	fallspeed-d(a5)
		clr.w	fallflag-d(a5)
		clr.w	swsinkflag2-d(a5)
		rts
		
.nofall2	clr.w	fallspeed-d(a5)
.nofall3	bsr	teststauch
		clr.w	fallpos-d(a5)
		clr.w	fallflag-d(a5)
		clr.w	swsinkflag2-d(a5)
		rts

.nofall4	move.w	#1,fallspeed-d(a5)
		;move.w	#8,fallpos-d(a5)
		clr.w	swsinkflag2-d(a5)
		rts				
		
.swamp		move.w	#1,swsinkflag-d(a5)
		move.w	#1,jumped-d(a5)
		clr.w	swsinkcount-d(a5)

		cmp.b	#9,(a4,d2.w)
		beq	.nofall
		
		move.l	nm-d(a5),a0
		moveq	#_nmeno-1,d7
.sl1		tst.w	nmenable(a0)
		beq.s	.sc1
		addq.l	#4,a0
		dbra	d7,.sl1
		bra	.nofall
.sc1		move.w	#1,nmenable(a0)
		move.l	absmanxpos-d(a5),d0
		add.w	#66,d0
		move.w	d0,nmxpos(a0)
		move.l	absmanypos-d(a5),d0
		add.w	#64,d0
		and.w	#$fff0,d0
		subq.w	#8,d0
		move.w	d0,swampystart-d(a5)
		move.w	d0,swampypos-d(a5)
		move.w	d0,nmstartypos(a0)
		move.w	#48,nmxsize(a0)
		clr.l	nmmove(a0)
		clr.w	nmanimpos(a0)
		clr.w	nmanimcount(a0)
		bra	.nofall

		
.sink		tst.w	fallflag-d(a5)
		bne.s	.sinkend
		tst.w	jumpflag-d(a5)
		bne.s	.sinkend
		move.w	swsinkcount-d(a5),d0
		btst	#0,d0
		bne.s	.sinkc1
		moveq	#1,d0
		add.w	d0,manypos-d(a5)
		add.l	d0,absmanypos-d(a5)
.sinkc1		eor.w	#1,swsinkcount-d(a5)
		move.l	absmanypos-d(a5),d0
		cmp.w	swampystart-d(a5),d0
		bmi.s	.sinkend
		move.w	#1,resetflag-d(a5)
		move.w	#1,fadeflag-d(a5)
		clr.w	swsinkflag-d(a5)
.sinkend	rts

		
.testcrumble	moveq	#0,d0
		move.w	manxpos-d(a5),d0
		add.l	xsoftabs-d(a5),d0
		add.l	#50,d0
		move.w	d0,d2
		lsr.l	#4,d0
		add.l	d0,d0
		move.l	multab-d(a5),a0		
		move.w	manypos-d(a5),d1
		add.w	ysoft-d(a5),d1
		add.w	ysoftpos-d(a5),d1
		add.w	#72,d1
		cmp.w	#_scrheight,d1
		bmi.s	.c011
		sub.w	#_scrheight,d1
.c011		add.w	d1,d1
		add.w	d1,d1
		add.l	(a0,d1.w),d0
		add.l	draw-d(a5),d0
		move.l	d0,a0
		move.w	(a0),d1
		or.w	_scrwidth*3(a0),d1
		or.w	_scrwidth*3*2(a0),d1
		or.w	_scrwidth*3*3(a0),d1
		tst.w	d1
		beq	.fall
		move.w	#1,crstandflag-d(a5)
		bra	.nofall
		
.rough		cmp.w	#$94,manypos-d(a5)
		bpl	.nofall4
		moveq	#0,d0
		move.w	manxpos-d(a5),d0
		add.l	xsoftabs-d(a5),d0
		add.l	#50,d0
		move.w	d0,d2
		lsr.l	#4,d0
		add.l	d0,d0

		move.l	multab-d(a5),a0		
		move.w	manypos-d(a5),d1
		add.w	ysoft-d(a5),d1
		add.w	ysoftpos-d(a5),d1
		add.w	#70,d1
		cmp.w	#_scrheight,d1
		bmi.s	.c11
		sub.w	#_scrheight,d1
.c11		move.w	d1,d7
		add.w	d1,d1
		add.w	d1,d1
		add.l	(a0,d1.w),d0
		add.l	draw-d(a5),d0
		move.l	d0,a0
		
		move.l	#$80000000,d3
		and.w	#$f,d2
		lsr.l	d2,d3

		move.l	_scrwidth*3*3(a0),d1
		and.l	d3,d1
		bne	.sub2
		
		lea	_scrwidth*_scrdepth*3(a0),a0
		addq.w	#1,d7
		cmp.w	#_scrheight,d7
		bmi.s	.c16
		sub.w	#_scrheight,d7
		sub.l	#_scrwidth*_scrdepth*3*_scrheight,a0
.c16		move.l	_scrwidth*3*3(a0),d1
		and.l	d3,d1
		bne	.sub1
		
		lea	_scrwidth*_scrdepth*3(a0),a0
		addq.w	#1,d7
		cmp.w	#_scrheight,d7
		bmi.s	.c15
		sub.w	#_scrheight,d7
		sub.l	#_scrwidth*_scrdepth*3*_scrheight,a0
.c15		move.l	_scrwidth*3*3(a0),d1
		and.l	d3,d1
		bne	.add0
		
		lea	_scrwidth*_scrdepth*3(a0),a0
		addq.w	#1,d7
		cmp.w	#_scrheight,d7
		bmi.s	.c12
		sub.w	#_scrheight,d7
		sub.l	#_scrwidth*_scrdepth*3*_scrheight,a0
.c12		move.l	_scrwidth*3*3(a0),d1
		and.l	d3,d1
		bne	.add1
		
		lea	_scrwidth*_scrdepth*3(a0),a0
		addq.w	#1,d7
		cmp.w	#_scrheight,d7
		bmi.s	.c13
		sub.w	#_scrheight,d7
		sub.l	#_scrwidth*_scrdepth*3*_scrheight,a0
.c13		move.l	_scrwidth*3*3(a0),d1
		and.l	d3,d1
		bne	.add2

		lea	_scrwidth*_scrdepth*3(a0),a0
		addq.w	#1,d7
		cmp.w	#_scrheight,d7
		bmi.s	.c14
		sub.w	#_scrheight,d7
		sub.l	#_scrwidth*_scrdepth*3*_scrheight,a0
.c14		move.l	_scrwidth*3*3(a0),d1
		and.l	d3,d1
		bne	.add3
	
		lea	_scrwidth*_scrdepth*3(a0),a0
		addq.w	#1,d7
		cmp.w	#_scrheight,d7
		bmi.s	.c17
		sub.w	#_scrheight,d7
		sub.l	#_scrwidth*_scrdepth*3*_scrheight,a0
.c17		move.l	_scrwidth*3*3(a0),d1
		and.l	d3,d1
		bne	.add4
	
		lea	_scrwidth*_scrdepth*3(a0),a0
		addq.w	#1,d7
		cmp.w	#_scrheight,d7
		bmi.s	.c18
		sub.w	#_scrheight,d7
		sub.l	#_scrwidth*_scrdepth*3*_scrheight,a0
.c18		move.l	_scrwidth*3*3(a0),d1
		and.l	d3,d1
		bne	.add5
	
		lea	_scrwidth*_scrdepth*3(a0),a0
		addq.w	#1,d7
		cmp.w	#_scrheight,d7
		bmi.s	.c19
		sub.w	#_scrheight,d7
		sub.l	#_scrwidth*_scrdepth*3*_scrheight,a0
.c19		move.l	_scrwidth*3*3(a0),d1
		and.l	d3,d1
		bne	.add6
	
		lea	_scrwidth*_scrdepth*3(a0),a0
		addq.w	#1,d7
		cmp.w	#_scrheight,d7
		bmi.s	.c20
		sub.w	#_scrheight,d7
		sub.l	#_scrwidth*_scrdepth*3*_scrheight,a0
.c20		move.l	_scrwidth*3*3(a0),d1
		and.l	d3,d1
		bne	.add7
		bra	.fall
	
.testnofall2	cmp.b	#18,(a4,d2.w)
		bne	.nofall4
		bra	.fall

	
	
.rough2		cmp.w	#$94,manypos-d(a5)
		bpl.s	.testnofall2
		lea	falltab-d(a5),a0
		move.w	fallpos-d(a5),d0
		move.w	(a0,d0.w),d4
		
		moveq	#0,d0
		move.b	(a4,d2.w),d0
		sub.w	#14,d0
		move.w	d0,blktype-d(a5)
		moveq	#0,d0
		move.w	manxpos-d(a5),d0
		add.l	xsoftabs-d(a5),d0
		add.l	#47,d0
		move.w	d0,d2
		lsr.l	#4,d0
		add.l	d0,d0

		move.l	multab-d(a5),a0		
		move.w	manypos-d(a5),d1
		add.w	ysoft-d(a5),d1
		add.w	ysoftpos-d(a5),d1
		add.w	#67,d1
		cmp.w	#_scrheight,d1
		bmi.s	.c1
		sub.w	#_scrheight,d1
.c1		move.w	d1,d7
		add.w	d1,d1
		add.w	d1,d1
		add.l	(a0,d1.w),d0
		add.l	draw-d(a5),d0
		move.l	d0,a0
		
		move.l	#$fe000000,d3
		and.w	#$f,d2
		lsr.l	d2,d3

		move.l	_scrwidth*3(a0),d1
		not.l	d1
		and.l	(a0),d1
		and.l	_scrwidth*3*2(a0),d1
		and.l	_scrwidth*3*3(a0),d1
		and.l	d3,d1
		bne	.sub4
		
		lea	_scrwidth*_scrdepth*3(a0),a0
		addq.w	#1,d7
		cmp.w	#_scrheight,d7
		bmi.s	.c22
		sub.w	#_scrheight,d7
		sub.l	#_scrwidth*_scrdepth*3*_scrheight,a0
.c22		move.l	_scrwidth*3(a0),d1
		not.l	d1
		and.l	(a0),d1
		and.l	_scrwidth*3*2(a0),d1
		and.l	_scrwidth*3*3(a0),d1
		and.l	d3,d1
		bne	.sub3
		
	