;REQUESTER TEST
execbase	=4
openlib		=-408
closelib	=-414
dmacon		=$96
cop1lc		=$80
copjmp1		=$88
openlibrary	=-30-552
forbid		=-30-102
permit		=-30-108
open		=-30
read		=-42
close		=-36
mode_old	=1005
startlist	=38
custom		=$dff000
bplcon0		=$100
bplcon1		=$102
bplcon2		=$104
bpl1pth		=$0e0
bpl1mod		=$108
bpl2mod		=$10a
diwstrt		=$08e
diwstop		=$090
ddfstrt		=$092
ddfstop		=$094
color00		=$180
color01		=$182
color17		=$1a2
color18		=$1a4
color19		=$1a6
vhposr		=$006

opendos:
	move.l	execbase,a6		;open the dos library
	lea	dosname(pc),a1		;name of library
	moveq	#0,d0			;existing file
	jsr	openlib(a6)		;open library
	move.l	d0,dosbase		;store base address 

openint:				;open intuition library
	lea	intname(pc),a1		;name of library
	moveq	#0,d0			;existing file
	jsr	openlib(a6)		;open it
	move.l	d0,intbase		;store base address
taskoff:
	jsr	forbid(a6)		;muti-tasking off	

copbuild:				;make bitplane copperlist
	move.l	#bitmap,d2		;bit plane address no 1
	moveq	#1,d4			;2 planes=2 loops to run
	move.l	cladr,a0		;copper list address in a0
	move.l	d2,d1			;1st bit plane address in d1
	move.w	#bpl1pth,d3		;first register to d3
makecl:
	move.w	d3,(a0)+		;bplxpth ins ram
	addq.w	#2,d3			;next register
	swap 	d1
	move.w	d1,(a0)+		;hi word of plane address
	move.w	d3,(a0)+		;bplxptl ins ram
	addq.w	#2,d3			;next register
	swap	d1
	move.w	d1,(a0)+		;lo word of plane address
	add.l	#10240,d1		;plane size for next address
	dbf	d4,makecl		;continue untill end
	bsr	cop0build		;display etc
	jmp 	joy2			;go and check firbutton etc

cop0build:		
	
	lea	sprtno,a1	 	;make sprite0 copperlist
	move.l	(a1),d1			;sprite0 address
	moveq	#0,d4			;0=1 sprites -1 loop to run
	move.l	cladr0,a0		;copper list address in a0
	move.w	#$120,d3		;high byte to d3
	bsr.s	makecl0
	add.l	#168,(a1)
	move.l	(a1),d1
	moveq	#0,d4
	bsr.s	makecl0
	add.l	#168,(a1)
	move.l	(a1),d1
	moveq	#0,d4
	bsr.s	makecl0
	add.l	#168,(a1)
	move.l	(a1),d1
	moveq	#0,d4
	bsr.s	makecl0
	move.l	#sprite47,d1
	moveq	#3,d4
	bsr.s	makecl0
	bra.s	copset
makecl0:
	move.w	d3,(a0)+		;spr0pth stored in ram
	addq.w	#2,d3			;next register
	swap	d1
	move.w	d1,(a0)+		;high word of address
	move.w	d3,(a0)+		;spr0ptl stored in ram
	addq.w	#2,d3			;next register
	swap	d1
	move.w	d1,(a0)+		;lo word of address
	dbf	d4,makecl0		;continue till all done
	rts				;return done
	
copset:					;initialise copper list
	lea	custom,a5		;register base address
	move.l	cladr,cop1lc(a5)	;address of copper list
	move.w	#$2981,diwstrt(a5)	;upper left of screen
	move.w	#$29c1,diwstop(a5)	;lower right of screen
					;ddfs's set for low res
	move.w	#$0038,ddfstrt(a5)	;start of bit plane dma
	move.w	#$00d0,ddfstop(a5)	;end of bit plane dma
					;0010 (10)=2 bit planes
	move.w	#%0010001000000000,bplcon0(a5)	;no of planes (2)
	clr.w	bplcon1(a5)		;no scrolling ?
	clr.w	bplcon2(a5)		;priority makes no diffrence
	clr.w	bpl1mod(a5)		;modulo for all planes=null?
	clr.w	bpl2mod(a5)		;same
	clr.w	copjmp1(a5)		;load copper list to pc	
	rts				;end of display
	
enda:	
	move.l	#grname,a1		;set for open library
	clr.l	d0			;existing file
	jsr	openlib(a6)		;open graphics library
	move.l	d0,a4			;address of graphics base
	move.l	d0,grbase		;store base address
	move.l	startlist(a4),cop1lc(a5)	;old copperlist
	clr.w	copjmp1(a5)		;load into pc
	move.w	#$83e0,dmacon(a5)	;all dma on
	jsr	permit(a6)		;enable muti-tasking

endb:
	move.l	execbase,a6
	move.l	dosbase(pc),a1		;close dos.library
	jsr	closelib(a6)
	move.l	intbase(pc),a1		;close intuition library
	jsr	closelib(a6)
	move.l	grbase(pc),a1		;close graphics library
	jsr	closelib(a6)
	rts				;all done finished

dosname:
	dc.b	'dos.library',0,0
	even
dosbase:
	blk.l	1,0
intname:
	dc.b	"intuition.library",0
	even	
intbase:
	blk.l	1,0
grname:
	dc.b	"graphics.library",0
	even
grbase:
	blk.l	1,0
cladr:	
	dc.l	list
cladr0:
	dc.l	list0
list:	
	blk.l	4,0	;BITPLANE COPPER LIST (2*2planes=4)
list0:
	blk.l	16,0	;SPRITE COPPER LIST (2*8sprites=16 lwords)
list2:			
			;COLOR MAP COPPER LIST
	dc.w	$0180,$0000,$0182,$0555,$0184,$0E52,$0186,$0AAA
	dc.w	$0188,$0455,$018A,$0500,$018C,$0060,$018E,$0000
	dc.w	$0190,$0000,$0192,$0000,$0194,$0000,$0196,$0006
	dc.w	$0198,$0000,$019A,$0400,$019C,$0000,$019E,$0500
	dc.w	$01A0,$0000,$01A2,$0f00,$01A4,$0fff,$01A6,$00bf
	dc.w	$01A8,$0000,$01AA,$0f00,$01AC,$0fff,$01AE,$00bf
	dc.w	$01B0,$0000,$01B2,$0000,$01B4,$0000,$01B6,$0000
	dc.w	$01B8,$0000,$01BA,$0000,$01BC,$0000,$01BE,$0000
	dc.w	$ffff,$fffe	
bitmap:
	blk.b	20480,0		;BIT PLANE INFORMATION	(2 planes)
	even
sprtno:
	dc.l	sprites
sprites:
	blk.b	15456,0			;sprites A to 20 info 
	even
sprites1:
	blk.b	3360,0			;sprites 21 to 25 info
	even
sprites2:
	blk.b	5376,0			;sprites a to g eqalizer
	even
sprite47:
	blk.l	42,0			;4-7 dummy sprite info
	even
store:
	dc.l	sprites
count:
	blk.l	1,0
joy2:
	btst	#6,$bfe001
	beq.L	out

delay:
	move.l	#12000,d1
loop1:	
	sub.l	#1,d1
	cmp.l	#0,d1
	bne.s	loop1
checkcount:
	lea	store,a0
	move.l	(a0),a0
	move.l	a0,sprtno
	add.l	#672,a0
	move.l	a0,store
	move.l	count,d0
at1:	cmp.l	#22,d0
	beq.s	cntup
	add.l	#1,count
	cmp.l	#3,d0			;intro sprite?
	bgt.s	rebeam			;no so display next
	move.l	#300000,d1		;intro frame
loop2:					;delay next frame
	sub.l	#1,d1			;decrement count
	cmp.l	#0,d1			;end of delay?
	bne.s	loop2			;nope then next decrement
	cmp.l	#3,d0			;is this the 3rd screen
	beq.s	setmus			;yes go and run music
rebeam:
	bsr.s	beamcheck		;check beam postion
	jsr	cop0build		;go and display sprite
	bra.s	joy2			;re-check fire button
beamcheck:
	lea	custom,a1		;check the beam position
	move.b	vhposr(a1),d6		;
	cmp.b	#$24,d6			;on last line ?
	bne.s	beamcheck			;nope then re-check
	rts				;return 
	
cntup:					;top sprite reached
					
	move.l	#4,count		;reset counter
	move.l	#23,at1+2
	lea	sprites+2016,a0		;set sprite pointer to start
	move.l	a0,store		;store for future recall
	bra.s	rebeam			;go and display next jobby
out:
	bsr.L	stopmus			;end this part/stop mus
	bsr.s	scr3set			;transfer new music etc
	bra.s	changecol		;goto next section
setmus:
	bsr.L	gomus			;go and set up music
	bra.s	rebeam			;return to check beam pos

scr3set:
	lea	mt_data1,a0		;copy new music to data
	move.l	mtpoint,a1		;pointer to go to
	move.l	#61004,d0		;number of bytes to copy
copy:
	move.b	(a0)+,(a1)+
	dbf	d0,copy
	rts

changecol:	
	bsr.s	beamcheck		;check beam position
	move.w	#$0f90,list2+70		;set up copper colors
	move.w	#$01f0,list2+74		;for new screen
	move.w	#$0f90,list2+86
	move.w	#$01f0,list2+90
	bsr.L	gomus			;restart music
		
screen3:
	lea	sprites1,a0		;set sprites pointer
	move.l	a0,store		;pointer in store
	move.l	#0,count		;reset counter to zero
	move.l	#0,newdo
nextspr:
	lea	store,a0		;get stored pointer
	move.l	(a0),a0			;from store
	move.l	a0,sprtno		;save to pointer
	move.l	count,d0		;get counter
	cmp.l	newdo,d0		;is new reqd same?
	beq.s	update			;yes so display same
	add.l	#672,a0			;setup next sprite
	move.l	a0,store		;save for next display run
	add.l	#1,count		;increment counter
	cmp.l	#5,count		;check counter number
	beq.s	screen3			;reset if > last sprite
update:
	bsr.L	beamcheck		;check beam position
	jsr	cop0build		;display sprite

next1:
	bsr.L	beamcheck		;check beam position
	move.l	#8000,d1		;load delay to check
next2:
	sub.l	#1,d1			;count down delay
	bne.s	next2			;not finished yet
next3:
	btst	#6,$bfe001		;left button?
	beq.s	addspr			;yes so update sprite
	btst	#10,$dff016		;right button?
	beq.s	options			;yes so goto options
	bra.s	nextspr			;no buttons so re-display
addspr:
	cmp.l	#0,olddo		;check button delay=0?
	beq.s	incdo			;yes so new press
	sub.l	#1,olddo		;no so dec counter
	cmp.l	#0,olddo		;is counter at zero?
	bne.L	nextspr			;no so display as is
	add.l	#1,newdo		;yes so update display	
	bra.L	nextspr			;and display new sprite
incdo:
	add.l	#2,olddo		;set button delay
	bra.L	nextspr			;and display old jobbie
options:
	move.l	count,d0		;check which sprite display
	cmp.l	#0,d0			;up when right button
	beq.s	music0			;was hit?
	cmp.l	#1,d0			;and select music
	beq.s	music1			;accordingly
	cmp.l	#2,d0
	beq.s	music2
	cmp.l	#3,d0
	beq.s	music3
	cmp.l	#4,d0			;check quit displayed
	beq.s	quit			;yes so quit
	bra.L	nextspr			;no selection re-display
quit:
	bsr.L	stopmus
	jmp	enda	
olddo:
	blk.l	1,0
newdo:	
	blk.l	1,0
filehd:
	blk.l	1,0
mus0:
	dc.b	"music0",0
	even
mus1:
	dc.b	"music1",0
	even
mus2:
	dc.b	"music2",0
	even
mus3:
	dc.b	"music3",0
	even
music0:
	move.l	#mus0,d1
	bra.s	loader
music1:
	move.l	#mus1,d1
	bra.s	loader
music2:
	move.l	#mus2,d1
	bra.s	loader
music3:
	move.l	#mus3,d1
	bra.s	loader

loader:
	move.l	#mode_old,d2		;load data from disk
	move.l	dosbase,a6		;filename in d1
	jsr	open(a6)
	move.l	d0,filehd
	move.l	#$ffffff,d3		;size of file		
	move.l	#mt_data1,d2		;destination address
	move.l	dosbase,a6
	move.l	filehd(pc),d1
	jsr	read(a6)
	move.l	d0,d6
	move.l	dosbase,a6
	move.l	filehd(pc),d1
	jsr	close(a6)
	bsr.L	stopmus			;stop soundtrack
	bsr.L	scr3set			;copy new music to buffer
	bsr.L	gomus			;restart soundtrack
	bra.s	graphic			;next screen

ec1:					;graphic eqalizer counters
	blk.l	1,0			;holds time value
ec2:					;higher the newer
	blk.l	1,0
ec3:
	blk.l	1,0
ec4:
	blk.l	1,0

graphic:
	bsr	beamcheck	
	move.w	#$0f00,list2+70
	move.w	#$0ff0,list2+74
	move.w	#$00f0,list2+78
	move.w	#$0f00,list2+86
	move.w	#$0ff0,list2+90
	move.w	#$00f0,list2+94
	bsr.L	cop1info
graphica:
	move.l	#8000,d0
loop3:
	sub.l	#1,d0
	cmp.l	#0,d0
	bne.s	loop3
	btst	#6,$bfe001
	beq.s	back
	lea	ec1,a1
	bsr.s	deceqalizer	
	lea	ec2,a1
	bsr.s	deceqalizer
	lea	ec3,a1
	bsr.s	deceqalizer
	lea	ec4,a1
	bsr.s	deceqalizer
	bsr.s	cop1info
	bra.s	graphica
back:
	bsr	beamcheck
	move.w	#$0f90,list2+70
	move.w	#$01f0,list2+74
	move.w	#$00bf,list2+78
	move.w	#$0f90,list2+86
	move.w	#$01f0,list2+90
	move.w	#$00bf,list2+94
	bra	nextspr
deceqalizer:
	move.l	(a1),d0
	cmp.l	#0,d0
	beq.s	nodec
	sub.l	#1,d0
	move.l	d0,(a1)
nodec:
	rts

cop1info:
	jsr	beamcheck
	move.l	cladr0,a0
	move.w	#$120,d3
	lea	sprites2,a1		;base sprite info value
	lea	ec1,a2			;get display value
	bsr.s	cop1build		;make that copper
	lea	sprites2+168,a1
	lea	ec2,a2
	bsr.s	cop1build
	lea	sprites2+336,a1
	lea	ec3,a2
	bsr.s	cop1build
	lea	sprites2+504,a1
	lea	ec4,a2
	bsr.s	cop1build
	move.l	#sprite47,d1
	moveq	#3,d4
	jsr	makecl0	
	jmp	copset

cop1build:
	move.l	(a2),d0			;value in display
	mulu	#672,d0			;multiply by next block 
	add.l	d0,a1			;add to base value
	move.l	a1,d1			;transfer
	moveq	#0,d4			;number of runs = 0
	jsr	makecl0			;go to it !
	rts

;NOISETRACKER INTERUPT PLAY ROUTINE
;A.R. NELSON 1990 
mtpoint:
	dc.l	mt_data
gomus:
	bsr	mt_init			;set up music etc
	lea	inter(pc),a1
	moveq	#5,d0
	move.l	4,a6
	jsr	-168(a6)
	rts 				;music up and running
stopmus:
	move.l	4,a6			;stop music etc
	moveq	#32,d0
	lea	inter(pc),a1
	jsr	-174(a6)
	move.w	#$f,$dff096
	clr.l	d0
	rts				;music stopped return
mt_init:lea	mt_data(pc),a0
	move.l	a0,a1
	add.l	#$3b8,a1
	moveq	#$7f,d0
	moveq	#0,d1
mt_loop:move.l	d1,d2
	subq.w	#1,d0
mt_lop2:move.b	(a1)+,d1
	cmp.b	d2,d1
	bgt.s	mt_loop
	dbf	d0,mt_lop2
	addq.b	#1,d2
	lea	mt_samplestarts(pc),a1
	asl.l	#8,d2
	asl.l	#2,d2
	add.l	#$43c,d2
	add.l	a0,d2
	move.l	d2,a2
	moveq	#$1e,d0
mt_lop3:clr.l	(a2)
	move.l	a2,(a1)+
	moveq	#0,d1
	move.w	42(a0),d1
	asl.l	#1,d1
	add.l	d1,a2
	add.l	#$1e,a0
	dbf	d0,mt_lop3
	or.b	#$2,$bfe001
	move.b	#$6,mt_speed
	clr.w	$dff0a8
	clr.w	$dff0b8
	clr.w	$dff0c8
	clr.w	$dff0d8
	clr.b	mt_songpos
	clr.b	mt_counter
	clr.w	mt_pattpos
	rts
mt_end:	clr.w	$dff0a8
	clr.w	$dff0b8
	clr.w	$dff0c8
	clr.w	$dff0d8
	move.w	#$f,$dff096
	rts
spadgewirq:
	movem.l	d0-d7/a0-a6,-(a7)
	bsr	mt_music
	movem.l	(a7)+,d0-d7/a0-a6
	moveq	#0,d0
	rts
mt_music:
	movem.l	d0-d4/a0-a3/a5-a6,-(a7)
	lea	mt_data(pc),a0
	addq.b	#$1,mt_counter
	move.b	mt_counter,D0
	cmp.b	mt_speed,D0
	blt.s	mt_nonew
	clr.b	mt_counter
	bra.L	mt_getnew

mt_nonew:
	lea	mt_voice1(pc),a6
	lea	$dff0a0,a5
	bsr.L	mt_checkcom
	lea	mt_voice2(pc),a6
	lea	$dff0b0,a5
	bsr.L	mt_checkcom
	lea	mt_voice3(pc),a6
	lea	$dff0c0,a5
	bsr.L	mt_checkcom
	lea	mt_voice4(pc),a6
	lea	$dff0d0,a5
	bsr.L	mt_checkcom
	bra.L	mt_endr

mt_arpeggio:
	moveq	#0,d0
	move.b	mt_counter,d0
	divs	#$3,d0
	swap	d0
	cmp.w	#$0,d0
	beq.s	mt_arp2
	cmp.w	#$2,d0
	beq.s	mt_arp1

	moveq	#0,d0
	move.b	$3(a6),d0
	lsr.b	#4,d0
	bra.s	mt_arp3
mt_arp1:moveq	#0,d0
	move.b	$3(a6),d0
	and.b	#$f,d0
	bra.s	mt_arp3
mt_arp2:move.w	$10(a6),d2
	bra.s	mt_arp4
mt_arp3:asl.w	#1,d0
	moveq	#0,d1
	move.w	$10(a6),d1
	lea	mt_periods(pc),a0
	moveq	#$24,d7
mt_arploop:
	move.w	(a0,d0.w),d2
	cmp.w	(a0),d1
	bge.s	mt_arp4
	addq.l	#2,a0
	dbf	d7,mt_arploop
	rts
mt_arp4:move.w	d2,$6(a5)
	rts

mt_getnew:
	lea	mt_data(pc),a0
	move.l	a0,a3
	move.l	a0,a2
	add.l	#$c,a3
	add.l	#$3b8,a2
	add.l	#$43c,a0

	moveq	#0,d0
	move.l	d0,d1
	move.b	mt_songpos,d0
	move.b	(a2,d0.w),d1
	asl.l	#8,d1
	asl.l	#2,d1
	add.w	mt_pattpos,d1
	clr.w	mt_dmacon

	lea	$dff0a0,a5
	lea	mt_voice1(pc),a6
	bsr.s	mt_playvoice
	lea	$dff0b0,a5
	lea	mt_voice2(pc),a6
	bsr.s	mt_playvoice
	lea	$dff0c0,a5
	lea	mt_voice3(pc),a6
	bsr.s	mt_playvoice
	lea	$dff0d0,a5
	lea	mt_voice4(pc),a6
	bsr.s	mt_playvoice
	bra.L	mt_setdma

mt_playvoice:
	move.l	(a0,d1.l),(a6)
	addq.l	#4,d1
	moveq	#0,d2
	move.b	$2(a6),d2
	and.b	#$f0,d2
	lsr.b	#4,d2
	move.b	(a6),d0
	and.b	#$f0,d0
	or.b	d0,d2
	tst.b	d2
	beq.s	mt_setregs
	moveq	#0,d3
	lea	mt_samplestarts(pc),a1
	move.l	d2,d4
	subq.l	#$1,d2
	asl.l	#2,d2
	mulu	#$1e,d4
	move.l	(a1,d2.l),$4(a6)
	move.w	(a3,d4.l),$8(a6)
	move.w	$2(a3,d4.l),$12(a6)
	move.w	$4(a3,d4.l),d3
	tst.w	d3
	beq.s	mt_noloop
	move.l	$4(a6),d2
	asl.w	#1,d3
	add.l	d3,d2
	move.l	d2,$a(a6)
	move.w	$4(a3,d4.l),d0
	add.w	$6(a3,d4.l),d0
	move.w	d0,8(a6)
	move.w	$6(a3,d4.l),$e(a6)
	move.w	$12(a6),$8(a5)
	bra.s	mt_setregs
mt_noloop:
	move.l	$4(a6),d2
	add.l	d3,d2
	move.l	d2,$a(a6)
	move.w	$6(a3,d4.l),$e(a6)
	move.w	$12(a6),$8(a5)
mt_setregs:
	move.w	(a6),d0
	and.w	#$fff,d0
	beq.L	mt_checkcom2
	move.b	$2(a6),d0
	and.b	#$F,d0
	cmp.b	#$3,d0
	bne.s	mt_setperiod
	bsr.L	mt_setmyport
	bra.L	mt_checkcom2
mt_setperiod:
chan:
	move.l	#8,d0
	cmp.l	#$dff0a0,a5
	beq.s	chan1
	cmp.l	#$dff0b0,a5
	beq.s	chan2
	cmp.l	#$dff0c0,a5
	beq.s	chan3
	cmp.l	#$dff0d0,a5
	beq.s	chan4
	bra.s	non
chan1:
	move.l	d0,ec1
	bra.s	non
chan2:
	move.l	d0,ec2
	bra.s	non
chan3:
	move.l	d0,ec3
	bra.s	non
chan4:
	move.l	d0,ec4
non:

	move.w	(a6),$10(a6)
	and.w	#$fff,$10(a6)
	move.w	$14(a6),d0
	move.w	d0,$dff096
	clr.b	$1b(a6)

	move.l	$4(a6),(a5)
	move.w	$8(a6),$4(a5)
	move.w	$10(a6),d0
	and.w	#$fff,d0
	move.w	d0,$6(a5)
	move.w	$14(a6),d0
	or.w	d0,mt_dmacon
	bra.L	mt_checkcom2

mt_setdma:
	move.w	#$12c,d0
mt_wait:dbf	d0,mt_wait
	move.w	mt_dmacon,d0
	or.w	#$8000,d0
	move.w	d0,$dff096
	move.w	#$12c,d0
mt_wai2:dbf	d0,mt_wai2
	lea	$dff000,a5
	lea	mt_voice4(pc),a6
	move.l	$a(a6),$d0(a5)
	move.w	$e(a6),$d4(a5)
	lea	mt_voice3(pc),a6
	move.l	$a(a6),$c0(a5)
	move.w	$e(a6),$c4(a5)
	lea	mt_voice2(pc),a6
	move.l	$a(a6),$b0(a5)
	move.w	$e(a6),$b4(a5)
	lea	mt_voice1(pc),a6
	move.l	$a(a6),$a0(a5)
	move.w	$e(a6),$a4(a5)

	add.w	#$10,mt_pattpos
	cmp.w	#$400,mt_pattpos
	bne.s	mt_endr
mt_nex:	clr.w	mt_pattpos
	clr.b	mt_break
	addq.b	#1,mt_songpos
	and.b	#$7f,mt_songpos
	move.b	mt_songpos,d1
	cmp.b	mt_data+$3b6,d1
	bne.s	mt_endr
	clr.b	mt_songpos
mt_endr:tst.b	mt_break
	bne.s	mt_nex
	movem.l	(a7)+,d0-d4/a0-a3/a5-a6
	rts

mt_setmyport:
	move.w	(a6),d2
	and.w	#$fff,d2
	move.w	d2,$18(a6)
	move.w	$10(a6),d0
	clr.b	$16(a6)
	cmp.w	d0,d2
	beq.s	mt_clrport
	bge.s	mt_rt
	move.b	#$1,$16(a6)
	rts
mt_clrport:
	clr.w	$18(a6)
mt_rt:	rts

mt_myport:
	move.b	$3(a6),d0
	beq.s	mt_myslide
	move.b	d0,$17(a6)
	clr.b	$3(a6)
mt_myslide:
	tst.w	$18(a6)
	beq.s	mt_rt
	moveq	#0,d0
	move.b	$17(a6),d0
	tst.b	$16(a6)
	bne.s	mt_mysub
	add.w	d0,$10(a6)
	move.w	$18(a6),d0
	cmp.w	$10(a6),d0
	bgt.s	mt_myok
	move.w	$18(a6),$10(a6)
	clr.w	$18(a6)
mt_myok:move.w	$10(a6),$6(a5)
	rts
mt_mysub:
	sub.w	d0,$10(a6)
	move.w	$18(a6),d0
	cmp.w	$10(a6),d0
	blt.s	mt_myok
	move.w	$18(a6),$10(a6)
	clr.w	$18(a6)
	move.w	$10(a6),$6(a5)
	rts

mt_vib:	move.b	$3(a6),d0
	beq.s	mt_vi
	move.b	d0,$1a(a6)

mt_vi:	move.b	$1b(a6),d0
	lea	mt_sin(pc),a4
	lsr.w	#$2,d0
	and.w	#$1f,d0
	moveq	#0,d2
	move.b	(a4,d0.w),d2
	move.b	$1a(a6),d0
	and.w	#$f,d0
	mulu	d0,d2
	lsr.w	#$6,d2
	move.w	$10(a6),d0
	tst.b	$1b(a6)
	bmi.s	mt_vibmin
	add.w	d2,d0
	bra.s	mt_vib2
mt_vibmin:
	sub.w	d2,d0
mt_vib2:move.w	d0,$6(a5)
	move.b	$1a(a6),d0
	lsr.w	#$2,d0
	and.w	#$3c,d0
	add.b	d0,$1b(a6)
	rts

mt_nop:	move.w	$10(a6),$6(a5)
	rts

mt_checkcom:
	move.w	$2(a6),d0
	and.w	#$fff,d0
	beq.s	mt_nop
	move.b	$2(a6),d0
	and.b	#$f,d0
	tst.b	d0
	beq.L	mt_arpeggio
	cmp.b	#$1,d0
	beq.s	mt_portup
	cmp.b	#$2,d0
	beq.L	mt_portdown
	cmp.b	#$3,d0
	beq.L	mt_myport
	cmp.b	#$4,d0
	beq.L	mt_vib
	move.w	$10(a6),$6(a5)
	cmp.b	#$a,d0
	beq.s	mt_volslide
	rts

mt_volslide:
	moveq	#0,d0
	move.b	$3(a6),d0
	lsr.b	#4,d0
	tst.b	d0
	beq.s	mt_voldown
	add.w	d0,$12(a6)
	cmp.w	#$40,$12(a6)
	bmi.s	mt_vol2
	move.w	#$40,$12(a6)
mt_vol2:move.w	$12(a6),$8(a5)
	rts

mt_voldown:
	moveq	#0,d0
	move.b	$3(a6),d0
	and.b	#$f,d0
	sub.w	d0,$12(a6)
	bpl.s	mt_vol3
	clr.w	$12(a6)
mt_vol3:move.w	$12(a6),$8(a5)
	rts

mt_portup:
	moveq	#0,d0
	move.b	$3(a6),d0
	sub.w	d0,$10(a6)
	move.w	$10(a6),d0
	and.w	#$fff,d0
	cmp.w	#$71,d0
	bpl.s	mt_por2
	and.w	#$f000,$10(a6)
	or.w	#$71,$10(a6)
mt_por2:move.w	$10(a6),d0
	and.w	#$fff,d0
	move.w	d0,$6(a5)
	rts

mt_portdown:
	clr.w	d0
	move.b	$3(a6),d0
	add.w	d0,$10(a6)
	move.w	$10(a6),d0
	and.w	#$fff,d0
	cmp.w	#$358,d0
	bmi.s	mt_por3
	and.w	#$f000,$10(a6)
	or.w	#$358,$10(a6)
mt_por3:move.w	$10(a6),d0
	and.w	#$fff,d0
	move.w	d0,$6(a5)
	rts

mt_checkcom2:
	move.b	$2(a6),d0
	and.b	#$f,d0
	cmp.b	#$e,d0
	beq.s	mt_setfilt
	cmp.b	#$d,d0
	beq.s	mt_pattbreak
	cmp.b	#$b,d0
	beq.s	mt_posjmp
	cmp.b	#$c,d0
	beq.s	mt_setvol
	cmp.b	#$f,d0
	beq.s	mt_setspeed
	rts

mt_setfilt:
	move.b	$3(a6),d0
	and.b	#$1,d0
	asl.b	#$1,d0
	and.b	#$fd,$bfe001
	or.b	d0,$bfe001
	rts
mt_pattbreak:
	not.b	mt_break
	rts
mt_posjmp:
	move.b	$3(a6),d0
	subq.b	#$1,d0
	move.b	d0,mt_songpos
	not.b	mt_break
	rts
mt_setvol:
	cmp.b	#$40,$3(a6)
	ble.s	mt_vol4
	move.b	#$40,$3(a6)
mt_vol4:move.b	$3(a6),$8(a5)
	rts
mt_setspeed:
	move.b	$3(a6),d0
	and.w	#$1f,d0
	beq.s	mt_rts2
	clr.b	mt_counter
	move.b	d0,mt_speed
mt_rts2:rts

mt_sin:
dc.b $00,$18,$31,$4a,$61,$78,$8d,$a1,$b4,$c5,$d4,$e0,$eb,$f4,$fa,$fd
dc.b $ff,$fd,$fa,$f4,$eb,$e0,$d4,$c5,$b4,$a1,$8d,$78,$61,$4a,$31,$18

mt_periods:
dc.w $0358,$0328,$02fa,$02d0,$02a6,$0280,$025c,$023a,$021a,$01fc,$01e0
dc.w $01c5,$01ac,$0194,$017d,$0168,$0153,$0140,$012e,$011d,$010d,$00fe
dc.w $00f0,$00e2,$00d6,$00ca,$00be,$00b4,$00aa,$00a0,$0097,$008f,$0087
dc.w $007f,$0078,$0071,$0000,$0000

mt_speed:	dc.b	$6
mt_songpos:	dc.b	$0
mt_pattpos:	dc.w	$0
mt_counter:	dc.b	$0

mt_break:	dc.b	$0
mt_dmacon:	dc.w	$0
mt_samplestarts:blk.l	$1f,0
mt_voice1:	blk.w	10,0
		dc.w	$1
		blk.w	3,0
mt_voice2:	blk.w	10,0
		dc.w	$2
		blk.w	3,0
mt_voice3:	blk.w	10,0
		dc.w	$4
		blk.w	3,0
mt_voice4:	blk.w	10,0
		dc.w	$8
		blk.w	3,0
inter:
		dc.l	0,0
		dc.b	2,127
		dc.l	0,0
		dc.l	spadgewirq
mt_data:
		blk.b	67414,0
mt_data1:
		blk.b	61004,0
done:
