	lea	5120(a2),a2		
.c2		add.l	(_nmem).w,a2
		move.l	#$80000000,d7
		
		moveq	#7,d4
loop3		moveq	#0,d0
		moveq	#0,d1
		moveq	#0,d2
		moveq	#0,d3
		moveq	#31,d6
fireloop	move.w	(a0)+,d5
		add.w	(a0),d5
		add.w	(a3)+,d5
		add.w	(a5)+,d5
		lsr.w	#2,d5
		beq.s	.c1
		subq.w	#1,d5
.c1		move.w	d5,(a4)+
		lsr.w	#2,d5
		add.w	d5,d5
		move.w	(a1,d5.w),d5
		jmp	(a6,d5.w)
c1		ror.l	#1,d7
		dbra	d6,fireloop
		move.l	d0,(a2)+
		move.l	d1,36(a2)
		move.l	d2,76(a2)
		move.l	d3,116(a2)
		
		lea	(40-4)+40*3(a2),a2

		dbra	d4,loop3

fireend		
;		bsr	geta5
;		lea	lgraph+32+36,a2
;		tst.w	firebuf-d(a5)
;		bne.s	.c1
;		lea	5120(a2),a2
;.c1		lea	fganimstart-d(a5),a1
;		move.l	a2,(a1)
;		addq.l	#2,a2
;		move.l	a2,4(a1)
;		lea	2560(a2),a2
;		move.l	a2,12(a1)
;		subq.l	#2,a2
;		move.l	a2,8(a1)
;		
;		tst.w	firecount-d(a5)
;		bne.s	.c2
;		eor.w	#1,firebuf-d(a5)

.c2		bsr	geta5
		lea	$dff000,a6
fireret		rts


ps
l15		or.l	d7,d2
l11		or.l	d7,d1
l9		or.l	d7,d0
l8		or.l	d7,d3
		ror.l	#1,d7
		dbra	d6,fireloop
		move.l	d0,(a2)+
		move.l	d1,36(a2)
		move.l	d2,76(a2)
		move.l	d3,116(a2)
		lea	(40-4)+40*3(a2),a2
		dbra	d4,loop3
		bra.s	fireend
		
l14		or.l	d7,d2
l10		or.l	d7,d1
		or.l	d7,d3
		ror.l	#1,d7
		dbra	d6,fireloop
		move.l	d0,(a2)+
		move.l	d1,36(a2)
		move.l	d2,76(a2)
		move.l	d3,116(a2)
		lea	(40-4)+40*3(a2),a2
		dbra	d4,loop3
		bra	fireend

l13		or.l	d7,d0
l12		or.l	d7,d2
		or.l	d7,d3
		ror.l	#1,d7
		dbra	d6,fireloop
		move.l	d0,(a2)+
		move.l	d1,36(a2)
		move.l	d2,76(a2)
		move.l	d3,116(a2)
		lea	(40-4)+40*3(a2),a2
		dbra	d4,loop3
		bra	fireend



pixtab		dc.w	c1-ps,l8-ps,l9-ps,l10-ps,l11-ps,l12-ps,l13-ps,l14-ps
		dc.w	l15-ps,l15-ps,l15-ps,l15-ps,l15-ps,l15-ps,l15-ps,l15-ps
		dc.w	l15-ps,l15-ps,l15-ps,l15-ps,l15-ps,l15-ps,l15-ps,l15-ps

;------------------------------------------------
setbgcols	bsr	geta5
		lea	linejmptab+46,a0
		add.l	(_nmem).w,a0
		lea	_skycols1,a1
		tst.w	colintflag-d(a5)
		bne.s	.c1
		tst.w	scolcount-d(a5)
		beq.s	.c1
		lea	_skycols2,a1
.c1		add.l	(_nmem).w,a1
		lea	$dff000,a6
		waitblt
		move.l	a1,$50(a6)
		move.l	a0,$54(a6)
		move.w	#0,$64(a6)
		move.w	#58,$66(a6)
		move.l	#$09f00000,$40(a6)
		move.l	#$ffffffff,$44(a6)
		move.w	#208*64+1,$58(a6)
		
		eor.w	#1,scolcount-d(a5)
		rts

setbgcolsii	lea	d(pc),a5
		move.w	intensity-d(a5),d7

		lea	colors1+2,a0
		add.l	(_nmem).w,a0
		lea	lgraph+2,a1
		add.l	(_nmem).w,a1
		moveq	#30,d0
.l3		move.w	(a1)+,d6
		bsr	fade
		move.w	d6,(a0)+
		addq.w	#2,a0
		dbra	d0,.l3

		lea	sprcoltab-d(a5),a0
		lea	sprcols+2,a1
		add.l	(_nmem).w,a1
		moveq	#14,d0
.l1		move.w	(a0)+,d6
		bsr	fade
		move.w	d6,(a1)+
		addq.w	#2,a1
		dbra	d0,.l1

		eor.w	#1,scolcount-d(a5)
		rts


cols3		rts
		lea	d(pc),a5
		move.w	intensity-d(a5),d7
		lea	watercoltab-d(a5),a1
		lea	waterofstab-d(a5),a0
		lea	wcol1,a2
		add.l	(_nmem).w,a2
		moveq	#11,d0
.m1		move.w	(a0)+,d1
		move.w	(a1)+,d6
		bsr	fade
		move.w	d6,(a2,d1.w)
		dbra	d0,.m1

		lea	wcol2,a2
		add.l	(_nmem).w,a2
		moveq	#3,d0
.m2		move.w	(a0)+,d1
		move.w	(a1)+,d6
		bsr	fade
		move.w	d6,(a2,d1.w)
		dbra	d0,.m2

		lea	wcol3,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

;------------------------------------------------
testbgpri	testbgpri_m
;------------------------------------------------
testfall	lea	d(pc),a5
		tst.w	deathflag-d(a5)
		bne	.fall
		tst.w	bobstand-d(a5)
		bne	.nofall3
		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-d(a5),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
		addq.l	#8,d1
		lsr.l	#4,d1
		mulu	#_levwidth,d1
		move.l	d1,d5
		lea	blocktab-d(a5),a4
;		move.l	d0,d2
;		add.l	#_levwidth,d2

		lea	(a3,d1.l),a3
		move.w	(a3),d2
		and.w	#$3ff,d2
		cmp.b	#255,(a4,d2.w)
		beq	.lava


;		cmp.b	#3,(a4,d2.w)
;		beq	.rough
		lea	(a0,d1.l),a3
		move.w	(a3),d2
		and.w	#$3ff,d2
		cmp.b	#19,(a4,d2.w)
		bpl.s	.ta2
		cmp.b	#13,(a4,d2.w)
		bpl	.rough2
.ta2		lea	(a2,d1.l),a3
		move.w	(a3),d2
		and.w	#$3ff,d2
		cmp.b	#19,(a4,d2.w)
		bpl.s	.ta1
		cmp.b	#13,(a4,d2.w)
		bpl	.rough2
.ta1		lea	(a0,d1.l),a1
		lea	(a0,d0.l),a0
		lea	(a2,d1.l),a3
		lea	(a2,d0.l),a2
		move.w	(a0),d2
		move.w	d2,d6
		and.w	#$fc00,d6
		and.w	#$3ff,d2
		move.w	(a1),d1
		move.w	d1,d5
		and.w	#$fc00,d5
		and.w	#$3ff,d1
		cmp.b	#1,(a4,d1.w)
		beq.s	.tst1
		cmp.w	#$e800,d5
		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.w	#$e800,d6
		beq.s	.testfall2
		cmp.b	#1,(a4,d2.w)
		bne	.nofall
;		cmp.b	#10,(a4,d2.w)
;		bne	.nofall

.testfall2	move.w	(a2),d2
		move.w	d2,d6
		and.w	#$fc00,d6
		and.w	#$3ff,d2
		move.w	(a3),d1
		move.w	d1,d5
		and.w	#$fc00,d5
		and.w	#$3ff,d1
		cmp.b	#1,(a4,d1.w)
		beq.s	.tst2
		cmp.w	#$e800,d5
		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.w	#$e800,d6
		beq.s	.fall
		cmp.b	#1,(a4,d2.w)
		bne.s	.nofall
;		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)
		rts
		
		
.nofall2	clr.w	fallspeed-d(a5)
.nofall3	bsr	teststauch
		clr.w	fallpos-d(a5)
		clr.w	fallflag-d(a5)
		rts

.nofall4	move.w	#1,fallspeed-d(a5)
		;move.w	#8,fallpos-d(a5)
		rts				

.lava		tst.w	ouchflag-d(a5)
		bne	.nofall
		bsr	setjump
		move.w	#1,ouchsetflag-d(a5)
		bra	.nofall
		sub.w	#32,energy-d(a5)
		move.w	#19,ouchflag-d(a5)
		move.l	#83*928,d0
		tst.w	animdir-d(a5)
		beq.s	.lleft
		move.l	#82*928,d0
.lleft		move.l	d0,animadr-d(a5)
		cmp.w	#4,energy-d(a5)
		bpl	.nofall
		move.w	#1,deathflag-d(a5)
		move.w	#$10,priority-d(a5)
		bra	.nofall

		
.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	orig-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	_scrwi