.w	(a3)+,(a0)+
		move.w	#$0160,(a0)+
		move.w	d2,(a0)+
		addq.w	#8,d2
		dbra	d6,.l8
		move.l	#$01640000,(a0)+
		move.l	#$01800000,(a0)+
		move.l	#$01800000,(a0)+
		move.l	(a7)+,a3
		lea	40(a3),a3
		dbra	d7,.l7
		
		addq.l	#8,a2
		move.w	#143,d7
.l9		move.b	d1,(a0)+
		move.b	#$e1,(a0)+
		move.w	#$fffe,(a0)+
		addq.b	#1,d1
		move.l	a0,d0
		add.l	#4*8,d0
		move.l	a0,(a1)+
		move.w	#$0084,(a0)+
		swap	d0
		move.w	d0,(a0)+
		swap	d0
		move.w	#$0086,(a0)+
		move.w	d0,(a0)+
		move.l	#$008a0000,(a0)+
		move.l	#$00e60000,(a0)+
		move.l	#$00e80000,(a0)+
		move.l	#$00ea0000,(a0)+
		move.l	#$00ec0000,(a0)+
		move.l	#$00ee0000,(a0)+
		move.l	#$016c0000,(a0)+
		move.b	d1,(a0)+
		move.b	#$49,(a0)+
		move.w	#$fffe,(a0)+
		move.w	#$0180,(a0)+
		tst.l	(a2)
		bne.s	.c3
		move.l	a0,(a2)	
.c3		move.w	#0,(a0)+		;(a4)+
		move.b	d1,(a0)+
		move.b	#$d5,(a0)+
		move.w	#$fffe,(a0)+
		move.l	#$01800000,(a0)+
		move.l	#$01800000,(a0)+
		dbra	d7,.l9
		
		lea	modulo1,a0
		add.l	d5,a0
		move.w	#$0108,(a0)+
		move.w	#(_scrwidth*_scrdepth*3)-40,(a0)+
		move.w	#$010a,(a0)+
		move.w	#(_scrwidth*_scrdepth*3)-40,(a0)+

		lea	planes1,a0
		add.l	d5,a0
		move.l	show-d(a5),d0
		subq.l	#2,d0
		move.w	#$00e0,d1
		moveq	#_scrdepth-1,d7
.l1		swap	d0
		move.w	d1,(a0)+
		move.w	d0,(a0)+
		addq.w	#2,d1
		swap	d0
		move.w	d1,(a0)+
		move.w	d0,(a0)+
		addq.w	#2,d1
		add.l	#_scrwidth*3,d0
		dbra	d7,.l1
		
		lea	lplanes,a0
		add.l	d5,a0
		move.l	show-d(a5),d0
		subq.l	#2,d0
		move.w	#$00e0,d1
		moveq	#_scrdepth-1,d7
.l5		swap	d0
		move.w	d1,(a0)+
		move.w	d0,(a0)+
		addq.w	#2,d1
		swap	d0
		move.w	d1,(a0)+
		move.w	d0,(a0)+
		addq.w	#2,d1
		add.l	#_scrwidth*3,d0
		dbra	d7,.l5
		
		lea	planes2,a0
		add.l	d5,a0
		move.l	#status+30,d0
		add.l	d5,d0
		move.w	#$00e0,d1
		moveq	#3,d7
.l2		swap	d0
		move.w	d1,(a0)+
		move.w	d0,(a0)+
		addq.w	#2,d1
		swap	d0
		move.w	d1,(a0)+
		move.w	d0,(a0)+
		addq.w	#2,d1
		add.l	#36,d0
		dbra	d7,.l2

		lea	colors1,a0
		add.l	d5,a0
		lea	lgraph+2,a1
		add.l	d5,a1
		move.w	#$0182,d0
		moveq	#30,d7
.l3		move.w	d0,(a0)+
		move.w	#0,(a0)+	;(a1)+
		addq.w	#2,d0
		dbra	d7,.l3

		lea	colors2,a0
		add.l	d5,a0
		lea	status,a1
		add.l	d5,a1
		move.w	#$0180,d0
		moveq	#15,d7
.l4		move.w	d0,(a0)+
		move.w	(a1)+,(a0)+
		addq.w	#2,d0
		dbra	d7,.l4

;		lea	waterpalette+2,a0
;		add.l	d5,a0
;		lea	watercols+2,a1
;		add.l	d5,a1
;		moveq	#14,d7
;.l10		move.w	(a0)+,(a1)+
;		addq.l	#2,a1
;		dbra	d7,.l10

		lea	watertab,a0
		add.l	d5,a0
		move.w	#$b9,d0
		moveq	#63,d7
.l11		move.w	#$0108,(a0)+
		move.w	#(_scrwidth*_scrdepth*3)-40,(a0)+
		move.w	#$010a,(a0)+
		move.w	#(_scrwidth*_scrdepth*3)-40,(a0)+
		move.l	#$01020000,(a0)+
		move.w	#$0180,(a0)+
		move.w	#$0000,(a0)+
		move.b	d0,(a0)+
		move.b	#$49,(a0)+
		move.w	#$fffe,(a0)+
		move.w	#$0180,(a0)+
		move.w	#$0008,(a0)+
		move.b	d0,(a0)+
		move.b	#$d5,(a0)+
		move.w	#$fffe,(a0)+
		move.w	#$0180,(a0)+
		move.w	#$0000,(a0)+
		addq.w	#1,d0
		dbra	d7,.l11
		
		lea	statsprdata,a0
		add.l	d5,a0
		move.l	#statusspr-4,d0
		add.l	d5,d0
		move.w	d0,6(a0)
		swap	d0
		move.w	d0,2(a0)
		swap	d0
		add.l	#(objectspr-statusspr)/2,d0
		move.w	d0,14(a0)
		swap	d0
		move.w	d0,10(a0)

		rts
;------------------------------------------------
initmusic	initmusic_m
;------------------------------------------------
setblk		setblk_m

setbob		setbob_m

drawroom	drawroom_m

drawstart	drawstart_m
;------------------------------------------------
dispinventory	dispinventory_m
;------------------------------------------------
dispacticon	dispacticon_m
;------------------------------------------------
dispicontext	dispicontext_m
;------------------------------------------------
;------------------------------------------------
;------------------------------------------------
mainrout	bsr	geta5
		lea	$dff000,a6
		vblank

		lea	nm-d(a5),a0
		
		bsr	getstick

		tst.w	pauseflag-d(a5)
		bne	.pause

		bsr	getbutton	*
		bsr	setybgnd	*
		bsr	setplanes	*
		bsr	setybgnd2	*

		bsr	setsun
		bsr	setmananim
		bsr	setwavespr

;		bsr	setbgcols2
		bsr	blitbgnd
		bsr	setbgcols
		bsr	setwaves
		bsr	setwater

		bsr	setwaveanim

		bsr	testbgpri
	
		bsr	stick
		move.w	agamanxpos-d(a5),d0
		asr.w	#2,d0
		move.w	d0,manxpos-d(a5)
		move.l	agaabsmanxpos-d(a5),d0
		asr.l	#2,d0
		move.l	d0,absmanxpos-d(a5)
		move.l	agaxsoftabs-d(a5),d0
		asr.l	#2,d0
		move.l	d0,xsoftabs-d(a5)
		
	
		bsr	jump
		
		bsr	testxborders
		bsr	testyborders
		bsr	scrollx
		bsr	scrolly

		tst.w	testflag-d(a5)
		bne.s	.c1
		bsr	testmancoll
.c1		bsr	updstatus
		
;		move.w	#$777,$dff180
		bsr	clrbobs
		bsr	fganim
		bsr	blitbobs

		bsr	getnewstartpos		
		bsr	chgplanes

		bsr	geta5
		clr.w	intensity-d(a5)

.chkkeys	bsr	chkkeys
		tst.w	testbarflag-d(a5)
		beq.s	.endmain
		move.w	#$555,$dff180
.endmain	rts
		
.pause		btst	#7,$bfe001
		bne.s	.chkkeys
		move.w	#0,pauseflag
		bra.s	.chkkeys

enter		cmp.w	#2,enterflag-d(a5)
		beq.s	.cont1
		cmp.w	#3,enterflag-d(a5)
		beq.s	.cont
		addq.w	#1,enterflag-d(a5)
		rts

.cont1		lea	doortab-d(a5),a0
		move.w	roomlevel-d(a5),d3
		moveq	#12,d0
		add.l	absmanxpos-d(a5),d0
		lsr.l	#4,d0
		moveq	#8,d1
		add.l	absmanypos-d(a5),d1
		lsr.l	#4,d1
.l1		move.w	(a0),d2
		bmi	.nodoor
;		cmp.w	4(a0),d3
;		bne	.nodoor
		cmp.w	2(a0),d1
		bne.s	.next
		cmp.w	d0,d2
		beq.s	.found
		addq.w	#1,d2
		cmp.w	d0,d2
		beq.s	.found
.next		lea	16(a0),a0
		bra.s	.l1

.found		move.w	12(a0),roomlevel-d(a5)
		move.w	14(a0),d2
		and.w	#$ff,d2
		move.w	d2,roomno-d(a5)
		move.l	8(a0),doorpos-d(a5)
		move.w	#1,fadeflag-d(a5)
		addq.w	#1,enterflag-d(a5)
		rts
		
.nodoor		clr.w	enterflag-d(a5)
		clr.w	enterflag2-d(a5)
		rts
		
.cont		bsr	initpositions
		clr.w	ouchflag-d(a5)

		move.w	roomno-d(a5),d4
		lsl.w	#4,d4
		lea	roomtab-d(a5),a4
		move.w	(a4,d4.w),d0
		ext.l	d0
		move.w	2(a4,d4.w),d1
		ext.l	d1
		move.w	8(a4,d4.w),d2
		ext.l	d2
		move.w	10(a4,d4.w),d3
		ext.l	d3	

		moveq	#0,d5
		move.w	(a4,d4.w),d5
		lsr.w	#3,d5
		move.l	d5,roomxstart-d(a5)
		
		move.w	2(a4,d4.w),d5
		lsr.w	#4,d5
		mulu	#_levwidth,d5
		move.l	d5,roomystart-d(a5)

		move.w	6(a4,d4.w),d5
		lsr.w	#4,d5
		mulu	#_levwidth,d5
		sub.l	#12*_levwidth,d5
;		sub.l	roomystart-d(a5),d5
		move.l	d5,roomysize-d(a5)	

		moveq	#0,d5
		move.w	4(a4,d4.w),d5
		lsr.w	#3,d5
		sub.l	#19*2,d5
;		sub.l	roomxstart-d(a5),d5
		move.l	d5,roomxsize-d(a5)	

		move.w	12(a4,d4.w),d0
		move.w	14(a4,d4.w),d1
		bsr	setscrnpos

		bsr	drawroom

		move.l	#_rdatofs,ldatofs-d(a5)
		move.w	#1,roomflag-d(a5)
		move.w	#15,intensity-d(a5)
		move.w	#2,fadeflag-d(a5)
		clr.w	enterflag-d(a5)
		clr.w	enterflag2-d(a5)
		rts

leave		cmp.w	#2,leaveflag-d(a5)
		beq.s	.cont1
		cmp.w	#3,leaveflag-d(a5)
		beq	.cont
		move.l	#30*928,d1
		bsr	doanim
		addq.w	#1,leaveflag-d(a5)
		rts

.cont1		lea	doortab-d(a5),a0
		move.w	roomlevel-d(a5),d3
		moveq	#12,d0
		add.l	absmanxpos-d(a5),d0
		lsr.l	#4,d0
		moveq	#8,d1
		add.l	absmanypos-d(a5),d1
		lsr.l	#4,d1
.l1		tst.w	(a0)
		bmi	.nodoor
		move.w	8(a0),d2

		cmp.w	12(a0),d3
		bne	.next
		cmp.w	10(a0),d1
		bne.s	.next
		cmp.w	d0,d2
		beq.s	.found
		addq.w	#1,d2
		cmp.w	d0,d2
		beq.s	.found
.next		lea	16(a0),a0
		bra.s	.l1

.found		move.w	4(a0),roomlevel-d(a5)
		move.l	(a0),doorpos-d(a5)
		move.w	6(a0),d2
		and.w	#$ff,d2
		move.w	d2,roomno-d(a5)
		move.w	#1,fadeflag-d(a5)
		addq.w	#1,leaveflag-d(a5)
		rts
		
.nodoor		clr.w	leaveflag-d(a5)
		rts
		
.cont		tst.w	roomlevel-d(a5)
		bne	.inside
		move.l	#_ldatofs,ldatofs-d(a5)
		clr.w	roomflag-d(a5)
		clr.w	leaveflag-d(a5)

		bsr	initstatus
		bsr	initpositions2
		clr.w	ouchflag-d(a5)

		moveq	#0,d0
		move.w	doorpos-d(a5),d0
		asl.l	#4,d0
		move.l	d0,d2
		sub.l	#128,d0
		bpl.s	.c1
		moveq	#0,d0
.c1		moveq	#0,d1
		move.w	doorpos+2-d(a5),d1
		asl.l	#4,d1
		move.l	d1,d3
		sub.l	#8,d3
		sub.l	#96,d1
		bpl.s	.c2
		moveq	#0,d1
.c2		bsr	setscrnpos

		bsr	initfganim
		bsr	initbobpos
		bsr	drawstart
		clr.w	resetflag-d(a5)
		move.w	#2,fadeflag-d(a5)
		rts

.inside		bsr	initpositions
		clr.w	ouchflag-d(a5)

		move.w	roomno-d(a5),d4
		lsl.w	#4,d4
		lea	roomtabi-d(a5),a4
		move.w	(a4,d4.w),d0
		ext.l	d0
		move.w	2(a4,d4.w),d1
		ext.l	d1
		move.w	8(a4,d4.w),d2
		ext.l	d2
		move.w	10(a4,d4.w),d3
		ext.l	d3	

		moveq	#0,d5
		move.w	(a4,d4.w),d5
		lsr.w	#3,d5
		move.l	d5,roomxstart-d(a5)
		
		move.w	2(a4,d4.w),d5
		lsr.w	#4,d5
		mulu	#_levwidth,d5
		move.l	d5,roomystart-d(a5)

		move.w	6(a4,d4.w),d5
		lsr.w	#4,d5
		mulu	#_levwidth,d5
		sub.l	#12*_levwidth,d5
;		sub.l	roomystart-d(a5),d5
		move.l	d5,roomysize-d(a5)	

		moveq	#0,d5
		move.w	4(a4,d4.w),d5
		lsr.w	#3,d5
		sub.l	#19*2,d5
;		sub.l	roomxstart-d(a5),d5
		move.l	d5,roomxsize-d(a5)	

		move.w	12(a4,d4.w),d0
		move.w	14(a4,d4.w),d1
		bsr	setscrnpos

		bsr	drawroom

		clr.w	leaveflag-d(a5)
		clr.w	resetflag-d(a5)
		move.w	#2,fadeflag-d(a5)
		rts


statrout	statrout_m

textprint	textprint_m

dospeak		dospeak_m

turnback	turnback_m
		
dofade		dofade_m

fadein		fadein_m

fadestatus	fadestatus_m

;------------------------------------------------
;------------------------------------------------
;---------------  Ingame-Debugger  --------------
;------------------------------------------------
;------------------------------------------------
monrout		monrout_m
;------------------------------------------------
;------------------------------------------------
;------------------------------------------------
;------------------------------------------------
getnewstartpos	lea	d(pc),a5
		move.l	absmanxpos-d(a5),d0
		cmp.l	absmanxold-d(a5),d0
		bne.s	.end2
		move.l	absmanypos-d(a5),d0
		cmp.l	absmanyold-d(a5),d0
		bne.s	.end2
		cmp.w	#$d0,manypos-d(a5)
		bpl.s	.end2

		addq.w	#1,standcount-d(a5)
		cmp.w	#5,standcount-d(a5)
		bne.s	.end
.dosave		clr.w	standcount-d(a5)
		lea	saveto-d(a5),a1
		lea	savestart-d(a5),a0
		move.w	#(saveend-savestart)/2-1,d7
.l1		move.w	(a0)+,(a1)+
		dbra	d7,.l1
.end		move.l	absmanxpos-d(a5),absmanxold-d(a5)
		move.l	absmanypos-d(a5),absmanyold-d(a5)
		rts
.end2		clr.w	standcount-d(a5)
		bra.s	.end
;------------------------------------------------
getstick	getstick_m
;------------------------------------------------
chkkeys		chkkeys_m
;------------------------------------------------
cleartext	cleartext_m
;------------------------------------------------
printinit	printinit_m

printchar	printchar_m

printstatline	printstatline_m

printmenu	printmenu_m
;------------------