mp.w	#22,manypos-d(a5)
		bmi	.up
.end		rts


.down		tst.w	roomlevel-d(a5)
		beq.s	.dc001
		move.l	yhard-d(a5),d0
		move.l	roomysize-d(a5),d1
		add.l	roomxstart-d(a5),d1
		cmp.l	d1,d0
		bpl	.testman

.dc001		cmp.l	#(_levheight-13)*_levwidth,yhard-d(a5)
		beq	.testman
		cmp.w	#208,manypos-d(a5)
		bpl.s	.dostop
		tst.w	deathflag-d(a5)
		bne	.end
		move.w	manypos-d(a5),d0
		sub.w	#98,d0
		cmp.w	#4,d0
		bmi.s	.dc1
		moveq	#4,d0
.dc1		sub.w	d0,manypos-d(a5)
		move.w	d0,ybstopspeed-d(a5)
		move.w	#8,ybstopcount-d(a5)
		add.w	d0,ysoftpos-d(a5)
		cmp.w	#4,ysoftpos-d(a5)
		bmi.s	.end
		sub.w	#4,ysoftpos-d(a5)
		move.l	xpos-d(a5),actxpos-d(a5)
		moveq	#4,d0
		move.l	d0,scycount-d(a5)
		move.w	#1,yscrflag-d(a5)
		bra	.end

.dostop		move.w	ybstopspeed-d(a5),d0
		beq	.fadeout
		subq.w	#1,ybstopcount-d(a5)
		bne.s	.ds1
		move.w	#8,ybstopcount-d(a5)
		subq.w	#1,ybstopspeed-d(a5)
.ds1		add.w	d0,ysoftpos-d(a5)
		cmp.w	#4,ysoftpos-d(a5)
		bmi	.end
		sub.w	#4,ysoftpos-d(a5)
		move.l	xpos-d(a5),actxpos-d(a5)
		moveq	#4,d0
		move.l	d0,scycount-d(a5)
		move.w	#1,yscrflag-d(a5)
		bra	.end
.fadeout	move.w	#1,fadeflag-d(a5)
		move.w	#1,resetflag-d(a5)
		bra	.end

.testman	cmp.w	#256,manypos-d(a5)
		bpl.s	.fadeout
		bra	.end

.up		tst.w	roomlevel-d(a5)
		beq.s	.uc001
		move.l	yhard-d(a5),d0
		sub.l	#_levwidth,d0
		cmp.l	roomxstart-d(a5),d0
		bmi	.end

.uc001		tst.l	yhard-d(a5)
		beq	.end
		moveq	#22,d0
		sub.w	manypos-d(a5),d0
		cmp.w	#4,d0
		bmi.s	.uc1
		moveq	#4,d0
.uc1		add.w	d0,manypos-d(a5)
		sub.w	d0,ysoftpos-d(a5)
		tst.w	ysoftpos-d(a5)
		bpl	.end
		add.w	#4,ysoftpos-d(a5)
		move.l	xpos-d(a5),actxpos-d(a5)
		moveq	#4,d0
		move.l	d0,scycount-d(a5)
		move.w	#-1,yscrflag-d(a5)
		bra	.end
;------------------------------------------------
scrollx		lea	d(pc),a5
		tst.w	xscrflag-d(a5)
		beq	.end
		bmi	.left
.right		move.w	xsoft-d(a5),d0
		
		move.w	agamanxpos-d(a5),d1
		sub.w	#184*4,d1
		cmp.w	#4,d1
		bpl.s	.rc01
		moveq	#4,d1
.rc01		cmp.w	#16,d1
		bmi.s	.rc02
		moveq	#16,d1
.rc02		ext.l	d1		
		add.l	d1,agaxsoftabs-d(a5)
		sub.w	d1,xsoft-d(a5)
		bpl.s	.rc7
		add.w	#64,xsoft-d(a5)
		addq.l	#2,xpos-d(a5)
.rc7		sub.w	d1,agamanxpos-d(a5)
		
.rc001		move.w	agamanxpos-d(a5),d1
		lsr.w	#2,d1
		move.w	d1,manxpos-d(a5)
		move.l	agaabsmanxpos-d(a5),d1
		lsr.l	#2,d1
		move.l	d1,absmanxpos-d(a5)
		move.l	agaxsoftabs-d(a5),d1
		lsr.l	#2,d1
		move.l	d1,xsoftabs-d(a5)

		lsr.w	#3,d0
		and.w	#$2,d0
		move.w	xsoft-d(a5),d1
		lsr.w	#3,d1
		and.w	#$2,d1
		cmp.w	d0,d1
		bne.s	.rc9
		rts



.rc9		waitblt
		move.l	#-1,$44(a6)
		move.l	#$09f00000,$40(a6)
		move.w	#$0026,$64(a6)
		move.w	#(_scrwidth*3)-2,$66(a6)
		move.l	_xmem,a0
		add.l	ldatofs-d(a5),a0
		add.l	#_viewwidth+4,a0
		add.l	xpos-d(a5),a0
		add.l	actyhard-d(a5),a0
		moveq	#4,d0
		add.l	#_viewwidth+4,d0
		add.l	xpos-d(a5),d0
		move.l	d0,a3
		move.l	actypos-d(a5),d2
		moveq	#0,d3
		move.w	#64*_scrdepth*16+1,d4
		move.l	index-d(a5),a1

		cmp.l	#_levwidth*6,xsetlpos2-d(a5)
		beq	.rc3

		move.w	#$fc00,d6
		move.w	#$03ff,d1
		movem.l	d2/a0,-(a7)
		add.l	xsetlpos1-d(a5),a0
		add.l	xsetpos1-d(a5),d2
		cmp.l	#_scrwidth*_scrdepth*3*_scrheight,d2
		bmi.s	.rc4
		sub.l	#_scrwidth*_scrdepth*3*_scrheight,d2
.rc4		lea	(a3,d2.l),a4
		moveq	#0,d3
		move.w	(a0),d3
		move.w	d3,d5
		and.w	d6,d5
		beq.s	.rc10

		cmp.w	#$f000,d5
		bhi.s	.rc12
		cmp.w	#$c400,d5
		bhi.s	.rc10
		movem.l	d0-a6,-(a7)
		move.l	xpos-d(a5),d0
		lsl.l	#3,d0
		add.l	#384,d0
		move.l	actysoftabs-d(a5),d1
		and.l	#$fffffff0,d1
		add.l	xsetsoft1-d(a5),d1
		bsr	setbobr
		movem.l	(a7)+,d0-a6
		bra.s	.rc10
		
.rc12		movem.l	d0/d3/d2/d4/a0/a5/a6,-(a7)
		move.l	xsetsoft1-d(a5),d4
		bsr	setblkr
		movem.l	(a7)+,d0/d3/d2/d4/a0/a5/a6
;		moveq	#0,d3
		
.rc10		and.w	d1,d3
		add.l	d3,d3
		add.l	d3,d3
		move.l	(a1,d3.l),a2
		move.l	orig-d(a5),d0
		lea	(a4,d0.l),a4
		waitblt
		move.l	a2,$50(a6)
		move.l	a4,$54(a6)
		move.w	d4,$58(a6)
		lea	_scrwidth(a4),a4
		waitblt
		move.l	a2,$50(a6)
		move.l	a4,$54(a6)
		move.w	d4,$58(a6)
		lea	_scrwidth(a4),a4
		waitblt
		move.l	a2,$50(a6)
		move.l	a4,$54(a6)
		move.w	d4,$58(a6)
		
		add.l	#_scrwidth*_scrdepth*3*16,d2
		cmp.l	#_scrwidth*_scrdepth*3*_scrheight,d2
		bmi.s	.rc0001
		sub.l	#_scrwidth*_scrdepth*3*_scrheight,d2
.rc0001		lea	_levwidth(a0),a0
		
		lea	(a3,d2.l),a4
		moveq	#0,d3
		move.w	(a0),d3
		move.w	d3,d5
		and.w	d6,d5
		beq.s	.rc210

		cmp.w	#$f000,d5
		bhi.s	.rc212
		cmp.w	#$c400,d5
		bhi.s	.rc210
		movem.l	d0-a6,-(a7)
		move.l	xpos-d(a5),d0
		lsl.l	#3,d0
		add.l	#384,d0
		move.l	actysoftabs-d(a5),d1
		and.l	#$fffffff0,d1
		add.l	xsetsoft1-d(a5),d1
		addq.l	#8,d1
		addq.l	#8,d1
		bsr	setbobr
		movem.l	(a7)+,d0-a6
		bra.s	.rc210
		
.rc212		movem.l	d0/d3/d2/d4/a0/a5/a6,-(a7)
		move.l	xsetsoft1-d(a5),d4
		addq.l	#8,d4
		addq.l	#8,d4
		bsr	setblkr
		movem.l	(a7)+,d0/d3/d2/d4/a0/a5/a6
;		moveq	#0,d3
		
.rc210		and.w	d1,d3
		add.l	d3,d3
		add.l	d3,d3
		move.l	(a1,d3.l),a2
		move.l	orig-d(a5),d0
		lea	(a4,d0.l),a4
		waitblt
		move.l	a2,$50(a6)
		move.l	a4,$54(a6)
		move.w	d4,$58(a6)
		lea	_scrwidth(a4),a4
		waitblt
		move.l	a2,$50(a6)
		move.l	a4,$54(a6)
		move.w	d4,$58(a6)
		lea	_scrwidth(a4),a4
		waitblt
		move.l	a2,$50(a6)
		move.l	a4,$54(a6)
		move.w	d4,$58(a6)
		
		movem.l	(a7)+,d2/a0
		add.l	xsetlpos2-d(a5),a0
		add.l	xsetpos2-d(a5),d2
		cmp.l	#_scrwidth*_scrdepth*3*_scrheight,d2
		bmi.s	.rc5
		sub.l	#_scrwidth*_scrdepth*3*_scrheight,d2
.rc5		lea	(a3,d2.l),a4
		moveq	#0,d3
		move.w	(a0),d3
		move.w	d3,d5
		and.w	d6,d5
		beq.s	.rc11

		cmp.w	#$f000,d5
		bhi.s	.rc13
		cmp.w	#$c400,d5
		bhi.s	.rc11

		movem.l	d0-a6,-(a7)
		move.l	xpos-d(a5),d0
		lsl.l	#3,d0
		add.l	#384,d0
		move.l	actysoftabs-d(a5),d1
		and.l	#$fffffff0,d1
		add.l	xsetsoft2-d(a5),d1
		bsr	setbobr
		movem.l	(a7)+,d0-a6
		bra.s	.rc11
		
.rc13		movem.l	d0/d3/d2/d4/a0/a5/a6,-(a7)
		move.l	xsetsoft2-d(a5),d4
		bsr	setblkr
		movem.l	(a7)+,d0/d3/d2/d4/a0/a5/a6
;		moveq	#0,d3

.rc11		and.w	d1,d3
		add.l	d3,d3
		add.l	d3,d3
		move.l	(a1,d3.l),a2
		move.l	orig-d(a5),d0
		lea	(a4,d0.l),a4
		waitblt
		move.l	a2,$50(a6)
		move.l	a4,$54(a6)
		move.w	d4,$58(a6)
		lea	_scrwidth(a4),a4
		waitblt
		move.l	a2,$50(a6)
		move.l	a4,$54(a6)
		move.w	d4,$58(a6)
		lea	_scrwidth(a4),a4
		waitblt
		move.l	a2,$50(a6)
		move.l	a4,$54(a6)
		move.w	d4,$58(a6)
		
		sub.l	#_scrwidth*_scrdepth*3*16,d2
		bpl.s	.rc0002
		add.l	#_scrwidth*_scrdepth*3*_scrheight,d2
.rc0002		lea	-_levwidth(a0),a0

		lea	(a3,d2.l),a4
		moveq	#0,d3
		move.w	(a0),d3
		move.w	d3,d5
		and.w	d6,d5
		beq.s	.rc211

		cmp.w	#$f000,d5
		bhi.s	.rc213
		cmp.w	#$c400,d5
		bhi.s	.rc211

		movem.l	d0-a6,-(a7)
		move.l	xpos-d(a5),d0
		lsl.l	#3,d0
		add.l	#384,d0
		move.l	actysoftabs-d(a5),d1
		and.l	#$fffffff0,d1
		add.l	xsetsoft2-d(a5),d1
		subq.l	#8,d1
		subq.l	#8,d1
		bsr	setbobr
		movem.l	(a7)+,d0-a6
		bra.s	.rc211
		
.rc213		movem.l	d0/d3/d2/d4/a0/a5/a6,-(a7)
		move.l	xsetsoft2-d(a5),d4
		subq.l	#8,d4
		subq.l	#8,d4
		bsr	setblkr
		movem.l	(a7)+,d0/d3/d2/d4/a0/a5/a6
;		moveq	#0,d3

.rc211		and.w	d1,d3
		add.l	d3,d3
		add.l	d3,d3
		move.l	(a1,d3.l),a2
		move.l	orig-d(a5),d0
		lea	(a4,d0.l),a4
		waitblt
		move.l	a2,$50(a6)
		move.l	a4,$54(a6)
		move.w	d4,$58(a6)
		lea	_scrwidth(a4),a4
		waitblt
		move.l	a2,$50(a6)
		move.l	a4,$54(a6)
		move.w	d4,$58(a6)
		lea	_scrwidth(a4),a4
		waitblt
		move.l	a2,$50(a6)
		move.l	a4,$54(a6)
		move.w	d4,$58(a6)

		moveq	#32,d0
		add.l	d0,xsetsoft1-d(a5)
		add.l	#_levwidth*2,xsetlpos1-d(a5)
		add.l	#_scrwidth*_scrdepth*3*32,xsetpos1-d(a5)
		sub.l	d0,xsetsoft2-d(a5)
		sub.l	#_levwidth*2,xsetlpos2-d(a5)
		sub.l	#_scrwidth*_scrdepth*3*32,xsetpos2-d(a5)
.rc3		subq.w	#2,xscrflag-d(a5)
		rts

.left		move.w	xsoft-d(a5),d0
		lsr.w	#3,d0

		move.w	#103*4,d1
		sub.w	agamanxpos-d(a5),d1
		cmp.w	#4,d1
		bpl.s	.lc01
		moveq	#4,d1
.lc01		cmp.w	#16,d1
		bmi.s	.lc02
		moveq	#16,d1
.lc02		add.w	xsoft-d(a5),d1
		lsr.w	#3,d1
		and.w	#$2,d0
		and.w	#$2,d1
		cmp.w	d0,d1
		beq	.left2

		waitblt
		move.l	#-1,$44(a6)
		move.l	#$09f00000,$40(a6)
		move.w	#$0026,$64(a6)
		move.w	#(_scrwidth*3)-2,$66(a6)
		move.l	_xmem,a0
		add.l	ldatofs-d(a5),a0
		subq.l	#2,a0
		add.l	xpos-d(a5),a0
		add.l	actyhard-d(a5),a0
		move.l	xpos-d(a5),d0
		addq.l	#2,d0
		move.l	d0,a3
		move.l	actypos-d(a5),d2

		moveq	#0,d3
		move.w	#64*_scrdepth*16+1,d4
		move.l	index-d(a5),a1
	
		cmp.l	#_levwidth*6,xsetlpos2-d(a5)
		beq	.lc3
		
		move.w	#$fc00,d6
		move.w	#$03ff,d1
		movem.l	d2/a0,-(a7)
		add.l	xsetlpos1-d(a5),a0
		add.l	xsetpos1-d(a5),d2
		cmp.l	#_scrwidth*_scrdepth*3*_scrheight,d2
		bmi.s	.lc4
		sub.l	#_scrwidth*_scrdepth*3*_scrheight,d2
.lc4		lea	(a3,d2.l),a4
		moveq	#0,d3
		move.w	(a0),d3
		move.w	d3,d5
		and.w	d6,d5
		cmp.w	#$f000,d5
		bhi.s	.lc12
		move.w	-4(a0),d5
		and.w	d6,d5
		beq.s	.lc10
		cmp.w	#$c400,d5
		bhi.s	.lc10
		
		movem.l	d0-a6,-(a7)
		lea	-4(a0),a0
		move.l	xpos-d(a5),d0
		subq.l	#4,d0
		lsl.l	#3,d0
		move.l	actysoftabs-d(a5),d1
		and.l	#$fffffff0,d1
		add.l	xsetsoft1-d(a5),d1
		bsr	setbobl
		movem.l	(a7)+,d0-a6
		bra.s	.lc10

.lc12		movem.l	d0/d3/d2/d4/a0/a4/a5/a6,-(a7)
		move.l	xsetsoft1-d(a5),d4
		bsr	setblkl
		movem.l	(a7)+,d0/d3/d2/d4/a0/a4/a5/a6
;		moveq	#0,d3

.lc10		and.w	d1,d3
		add.l	d3,d3
		add.l	d3,d3
		move.l	(a1,d3.l),a2
		move.l	orig-d(a5),d0
		lea	(a4,d0.l),a4
		waitblt
		move.l	a2,$50(a6)
		move.l	a4,$54(a6)
		move.w	d4,$58(a6)
		lea	_scrwidth(a4),a4
		waitblt
		move.l	a2,$50(a6)
		move.l	a4,$54(a6)
		move.w	d4,$58(a6)
		lea	_scrwidth(a4),a4
		waitblt
		move.l	a2,$50(a6)
		move.l	a4,$54(a6)
		move.w	d4,$58(a6)

		add.l	#_scrwidth*_scrdepth*3*16,d2
		cmp.l	#_scrwidth*_scrdepth*3*_scrheight,d2
		bmi.s	.lc00003
		sub.l	#_scrwidth*_scrdepth*3*_scrheight,d2
.lc00003	lea	_levwidth(a0),a0

		lea	(a3,d2.l),a4
		moveq	#0,d3
		move.w	(a0),d3
		move.w	d3,d5
		and.w	d6,d5
		cmp.w	#$f000,d5
		bhi.s	.lc212
		move.w	-4(a0),d5
		and.w	d6,d5
		beq.s	.lc210
		cmp.w	#$c400,d5
		bhi.s	.lc210
		
		movem.l	d0-a6,-(a7)
		lea	-4(a0),a0
		move.l	xpos-d(a5),d0
		subq.l	#4,d0
		lsl.l	#3,d0
		move.l	actysoftabs-d(a5),d1
		and.l	#$fffffff0,d1
		add.l	xsetsoft1-d(a5),d1
		addq.l	#8,d1
		addq.l	#8,d1
		bsr	setbobl
		movem.l	(a7)+,d0-a6
		bra.s	.lc210

.lc212		movem.l	d0/d3/d2/d4/a0/a4/a5/a6,-(a7)
		move.l	xsetsoft1-d(a5),d4
		addq.l	#8,d4
		addq.l	#8,d4
		bsr	setblkl
		movem.l	(a7)+,d0/d3/d2/d4/a0/a4/a5/a6
;		moveq	#0,d3

.lc210		and.w	d1,d3
		add.l	d3,d3
		