os2-d(a5)
		move.w	d0,xsetspos-d(a5)
		move.l	yshard-d(a5),actypos-d(a5)
		move.l	yhard-d(a5),actyhard-d(a5)
		move.l	ysoftabs-d(a5),actysoftabs-d(a5)
		bra	.end
;------------------------------------------------
testyborders	lea	d(pc),a5
		cmp.w	#99,manypos-d(a5)
		bpl	.down
		cmp.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	#8,d1
		bmi.s	.rc02
		moveq	#8,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	#2,d0
		and.w	#$2,d0
		move.w	xsoft-d(a5),d1
		lsr.w	#2,d1
		and.w	#$2,d1
		cmp.w	d0,d1
		bne.s	.rc9
		rts



.rc9		addq.w	#1,sunxpos-d(a5)
		subq.l	#1,absxpos-d(a5)
		bpl.s	.rc002
		add.l	#640,absxpos-d(a5)
.rc002		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)
		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)

		addq.l	#8,xsetsoft1-d(a5)
		addq.l	#8,xsetsoft1-d(a5)
		add.l	#_levwidth,xsetlpos1-d(a5)
		add.l	#_scrwidth*_scrdepth*3*16,xsetpos1-d(a5)
		subq.l	#8,xsetsoft2-d(a5)
		subq.l	#8,xsetsoft2-d(a5)
		sub.l	#_levwidth,xsetlpos2-d(a5)
		sub.l	#_scrwidth*_scrdepth*3*16,xsetpos2-d(a5)
.rc3		subq.w	#1,xscrflag-d(a5)
		rts

.left		move.w	xsoft-d(a5),d0
		lsr.w	#2,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	#8,d1
		bmi.s	.lc02
		moveq	#8,d1
.lc02		add.w	xsoft-d(a5),d1
		lsr.w	#2,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)
		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	.lc5
		sub.l	#_scrwidth*_scrdepth*3*_scrheight,d2
.lc5		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	.lc13
		move.w	-4(a0),d5
		and.w	d6,d5
		beq.s	.lc11
		cmp.w	#$c400,d5
		bhi.s	.lc11

		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	xsetsoft2-d(a5),d1
		bsr	setbobl
		movem.l	(a7)+,d0-a6
		bra.s	.lc11

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

.lc11		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)
		
		addq.l	#8,xsetsoft1-d(a5)
		addq.l	#8,xsetsoft1-d(a5)
		add.l	#_levwidth,xsetlpos1-d(a5)
		add.l	#_scrwidth*_scrdepth*3*16,xsetpos1-d(a5)
		subq.l	#8,xsetsoft2-d(a5)
		subq.l	#8,xsetsoft2-d(a5)
		sub.l	#_levwidth,xsetlpos2-d(a5)
		sub.l	#_scrwidth*_scrdepth*3*16,xsetpos2-d(a5)

.lc3		addq.l	#1,absxpos-d(a5)
		subq.w	#1,sunxpos-d(a5)
		cmp.l	#640,absxpos-d(a5)
		bmi.s	.lc2
		sub.l	#640,absxpos-d(a5)
.lc2		addq.w	#1,xscrflag-d(a5)

.left2		move.w	#103*4,d1
		sub.w	agamanxpos-d(a5),d1
		cmp.w	#4,d1
		bpl.s	.lc03
		moveq	#4,d1
.lc03		cmp.w	#8,d1
		bmi.s	.lc04
		moveq	#8,d1
.lc04		ext.l	d1
		sub.l	d1,agaxsoftabs-d(a5)
		add.w	d1,xsoft-d(a5)
		cmp.w	#64,xsoft-d(a5)
		bmi.s	.lc7
		sub.w	#64,xsoft-d(a5)
		subq.l	#2,xpos-d(a5)
.lc7		add.w	d1,agamanxpos-d(a5)
		move.w	agamanxpos-d(a5),d0
		lsr.w	#2,d0
		move.w	d0,manxpos-d(a5)
		move.l	agaabsmanxpos-d(a5),d0
		lsr.l	#2,d0
		move.l	d0,absmanxpos-d(a5)
		move.l	agaxsoftabs-d(a5),d0
		lsr.l	#2,d0
		move.l	d0,xsoftabs-d(a5)
		
		rts
		

.end		rts
*****
;------------------------------------------------
showenergy	showenergy_m
;------------------------------------------------
scrolly		lea	d(pc),a5
		tst.w	yscrflag-d(a5)
		beq	.end
		bpl	.down
.up		move.l	scycount-d(a5),d0
		sub.l	d0,ysoftabs-d(a5)
		sub.l	d0,yscrollofs-d(a5)
		sub.w	d0,ysoft-d(a5)
;		add.w	d0,manypos
		move.l	scyhard-d(a5),d0
		sub.l	d0,ypos-d(a5)
		bpl.s	.uc2
		add.l	#_scrwidth*_scrdepth*3*_scrheight,ypos-d(a5)
		add.w	#_scrheight,ysoft-d(a5)

.uc2		
		move.l	scycount-d(a5