
	Section	Demo,Code_f
	
	output	dh0:Six.exe

	Opt	C-,O+,w-

OzDMA		= 4

scrollin		= 36

ymax		= 270
ymin		= 161
xshift		= 38+(1*40)
offset		= 10

ciacra		= $e00
ciaicr		= $d00
ciatalo 		= $400
ciatahi 		= $500

size		= 105000
largesize		= 150000

maxdots		= 999		;119
speed		= 2

headspeed		= 5
time		= 716*headspeed	
load		= 14		; trap number to nondos load


Start:	lea	loadtracks(pc),a0
	move.l	a0,$80+(4*load)
	move.b	#-1,current_track

	move.l	$80,d0		; address of fastmem
	move.l	d0,loc
	add.l	#size,d0
	move.l	d0,buffer

	;move.l	4.w,a6
	;move.l	#size,d0
	;move.l	#$10001,d1	
	;jsr	-198(a6)
	;move.l	d0,loc
	;move.l	4.w,a6
	;move.l	#largesize,d0
	;move.l	#$10001,d1	
	;jsr	-198(a6)
	;move.l	d0,buffer
	
	lea	water1,a0
	move.l	loc,a1
	move.w	#(size/4)-1,d0
wat_loop:
	move.l	(a0)+,(a1)+
	dbf	d0,wat_loop
	
	move.l	#water_pic1,d0
	move.w	d0,bplane0_lo
	swap	d0
	move.w	d0,bplane0_hi
	swap	d0
	add.l	#1220,d0
	move.w	d0,bplane1_lo
	swap	d0
	move.w	d0,bplane1_hi
	swap	d0
	add.l	#1220,d0
	move.w	d0,bplane2_lo
	swap	d0
	move.w	d0,bplane2_hi
	swap	d0
	add.l	#1220,d0
	move.w	d0,bplane3_lo
	swap	d0
	move.w	d0,bplane3_hi
	
	lea	cmap+2,a0
	lea	display,a1
	move.w	#31,d0
cmap_loop:
	move.w	(a1)+,(a0)
	add.l	#4,a0
	dbf	d0,cmap_loop

	lea	filecmap+2,a0
	lea	filescreen,a1
	move.w	#31,d0
fmap_loop:
	move.w	(a1)+,(a0)
	add.l	#4,a0
	dbf	d0,fmap_loop

	lea	menucmap+2,a0
	lea	menuscreen,a1
	move.w	#15,d0
fmap2_loop:
	move.w	(a1)+,(a0)
	add.l	#4,a0
	dbf	d0,fmap2_loop

	lea	loading,a0
	lea	loadcmap+2,a1
	move.w	#15,d0
cmap_loop1:
	move.w	(a0)+,(a1)
	add.l	#4,a1
	dbf	d0,cmap_loop1

	move.l	#filescreen+64,d0
	move.w	d0,fplane0_lo
	swap	d0
	move.w	d0,fplane0_hi
	swap	d0
	add.l	#40*90,d0
	move.w	d0,fplane1_lo
	swap	d0
	move.w	d0,fplane1_hi
	swap	d0
	add.l	#40*90,d0
	move.w	d0,fplane2_lo
	swap	d0
	move.w	d0,fplane2_hi
	swap	d0
	add.l	#40*90,d0
	move.w	d0,fplane3_lo
	swap	d0
	move.w	d0,fplane3_hi
	swap	d0
	add.l	#40*90,d0
	move.w	d0,fplane4_lo
	swap	d0
	move.w	d0,fplane4_hi

	move.l	#menuscreen+32,d0
	move.w	d0,mplane0_lo
	swap	d0
	move.w	d0,mplane0_hi
	swap	d0
	add.l	#40*128,d0
	move.w	d0,mplane1_lo
	swap	d0
	move.w	d0,mplane1_hi
	swap	d0
	add.l	#40*128,d0
	move.w	d0,mplane2_lo
	swap	d0
	move.w	d0,mplane2_hi
	swap	d0
	add.l	#40*128,d0
	move.w	d0,mplane3_lo
	swap	d0
	move.w	d0,mplane3_hi

	bsr	setload

	move.l	#display+64,d0
	move.w	d0,bitplane0_lo
	swap	d0
	move.w	d0,bitplane0_hi
	swap	d0
	add.l	#40*292,d0
	move.w	d0,bitplane1_lo
	swap	d0
	move.w	d0,bitplane1_hi
	swap	d0
	add.l	#40*292,d0
	move.w	d0,bitplane2_lo
	swap	d0
	move.w	d0,bitplane2_hi
	swap	d0
	add.l	#40*292,d0
	move.w	d0,bitplane3_lo
	swap	d0
	move.w	d0,bitplane3_hi
	swap	d0
	add.l	#40*292,d0
	
	move.l	d0,screen1a
	
	move.w	d0,bitplane4_lo
	swap	d0
	move.w	d0,bitplane4_hi
	swap	d0
		
	lea	$dff000,a5		; hardware base address

	Move.w	$1c(a5),OldInt	; Save Old Interupts
	Move.w	$02(a5),OldDma	; Save Old DMA

	Move.w	#$7fff,$9a(a5)	; Clear DMA
	Move.w	#$7fff,$96(a5)	; Clear Interupts
	Move.w	#$7fff,$9c(a5)	; Clear Interupt Requests
	
	Move.b	#$7f,$bfed01	; kill timers (rem me for disk)
	Move.l	$6c.w,OldV3		; save level 3 int

	Move.l	#my_level3,$6c.w	; put new copper interupt
	Move.w	#$c010,$9a(a5)	; Start interupts

	Move.l	#null_copper,$80(a5)
	Move.w	#$83ff,$96(a5)	; Start DMA ( 83ff for disk dma)
	Move.w	#$83ff,$84(a5)	; foad action replay
	Move.w	#1,$88(a5)		; Strobe for copper start

	bsr	Callibrate

loadagain:	bsr	loadmusic
	move.l	filesptr,oldfile
dontloadagain:
	Move.l	#my_copper,$dff080 	; Address of copper 1

wait3:	;btst	#2,$dff016
	;beq	quit
	btst	#6,$bfe001
	bne.s	wait3		; wait for lmb

	bsr	waitmouse
	bsr	choosefile

	move.l	oldfile,d0
	cmp.l	filesptr,d0
	beq	dontloadagain

	bra	loadagain


quit:	lea	$dff000,a5		; hardware base address
	move.l	#0,$80(a5)		; blank copper list
	move.l	#0,$84(a5)		; if gfx lib not open (slayer boot)
	move.w	#0,$180(a5)		; bgc to black
	
	Move.l	OldV3,$6c.w		; restore old l3

	Lea	GfxLib,a1		; Pointer to Library Text
	move.l	4.w,a6
	jsr	-132(a6)		; forbid
	Move.l	4.w,a6		; Exec
	Moveq.l	#0,d0		; Clear D0
	Jsr	-$228(a6)		; Open Library
	cmp.l	#0,d0
	beq	no_gfx_lib		; if gfx lib not open dont restore copper lib (slayer boot)
	
	Move.l	d0,a1			
	Move.l	$26(a1),$80(a5)	; restore copper 1
	Move.l	$32(a1),$84(a5)	; restore copper 2
no_gfx_lib:

	Move.w	OldInt,d0		; start old interupts
	Or.w	#$8000,d0
	Move.w	d0,$9a(a5)
	Move.w	OldDma,d0		; start old DMA
	Or.w	#$8000,d0
	Move.w	d0,$96(a5)
	Move.b	#$9b,$bfed01	; Start Timers
	Move.l	4.w,a6		; Close Gfx lib
	Jsr	-$19e(a6)
	move.l	4.w,a6
	jsr	-138(a6)		; permit

	move.l	4.w,a6
	move.l	loc,a1
	move.l	#size,d0
	jsr	-210(a6)

	move.l	4.w,a6
	move.l	buffer,a1
	move.l	#largesize,d0
	jsr	-210(a6)

	bsr	mt_end

	move.w	#0,$bfec00		; clear kbd

	Moveq.l	#0,d0		; No errors
	Rts			; Exit

show_insert_pic:
	rts

Callibrate:	move.l	#2,playing
	
.loop	move.l	FrameCount,d0
.vb	cmp.l	FrameCount,d0
	beq	.vb
		
	move.l	FrameCount,-(a7)
	
	bsr	scroller
	REPT 6
	move.l	#Start,a1
	move.l	#maxdots,a2
	moveq.l	#1,d0
	moveq.l	#0,d4
	moveq.l	#0,d3
	bsr	show_dots
	ENDR
	REPT 6
	bsr	mt_WaitDMA
	ENDR
	
	move.l	(a7)+,d0
	cmp.l	FrameCount,d0
	beq	.ok
	sub.l	#10,DotCount
	add.l	#1,d0
	cmp.l	FrameCount,d0
	beq	.loop
	sub.l	#50,DotCount
	bra	.loop
		
.ok	rts
	
setload:	move.l	#loading+32,d0
	move.w	d0,bp0_lo
	swap	d0
	move.w	d0,bp0_hi
	swap	d0
	add.l	#100*40,d0
	move.w	d0,bp1_lo
	swap	d0
	move.w	d0,bp1_hi
	swap	d0
	add.l	#100*40,d0
	move.w	d0,bp2_lo
	swap	d0
	move.w	d0,bp2_hi
	swap	d0
	add.l	#100*40,d0
	move.w	d0,bp3_lo
	swap	d0
	move.w	d0,bp3_hi
	rts

setdecr:
	move.l	#decrunch,d0
	move.w	d0,bp0_lo
	swap	d0
	move.w	d0,bp0_hi
	swap	d0
	add.l	#100*40,d0
	move.w	d0,bp1_lo
	swap	d0
	move.w	d0,bp1_hi
	swap	d0
	add.l	#100*40,d0
	move.w	d0,bp2_lo
	swap	d0
	move.w	d0,bp2_hi
	swap	d0
	add.l	#100*40,d0
	move.w	d0,bp3_lo
	swap	d0
	move.w	d0,bp3_hi
	rts


waitmouse:	bsr	pause
wait1:	btst	#6,$bfe001
	bne.s	wait1		; wait for lmb
	bsr	pause
wait2:	btst	#6,$bfe001
	beq.s	wait2		; wait for lmb
	rts

choosefile:	Move.l	#file_copper,$dff080 	; Address of copper 1
	clr.l	d0
	move.b	$dff00a,d0
	move.l	d0,oldy
	
	move.l	#1,playing
	move.l	DotCount,-(a7)
	move.l	#5,DotCount
	
	move.w	#$ff01,menu_wait
	move.w	#$2801,menu_wait2
	move.w	#121,d7

menu_popup:	bsr	wait_beam
	cmp.w	#89,d7
	bgt.s	no_top_logo

	move.l	#filescreen+64,d0
	move.l	d7,d1
	mulu	#40,d1
	add.l	d1,d0
	move.w	d0,fplane0_lo
	swap	d0
	move.w	d0,fplane0_hi
	swap	d0
	add.l	#40*90,d0
	move.w	d0,fplane1_lo
	swap	d0
	move.w	d0,fplane1_hi
	swap	d0
	add.l	#40*90,d0
	move.w	d0,fplane2_lo
	swap	d0
	move.w	d0,fplane2_hi
	swap	d0
	add.l	#40*90,d0
	move.w	d0,fplane3_lo
	swap	d0
	move.w	d0,fplane3_hi
	swap	d0
	add.l	#40*90,d0
	move.w	d0,fplane4_lo
	swap	d0
	move.w	d0,fplane4_hi
	add.w	#$100,menu_wait2

no_top_logo:
	sub.w	#$100,menu_wait
	dbf	d7,menu_popup

	bsr	waitmouse
	
	move.l	ypos,d0
	add.l	#offset,d0	
	divu	#18,d0
	mulu	#12,d0
	add.l	#files,d0

	cmp.l	oldfile,d0
	beq	no_new_file

	move.l	d0,filesptr
	
	move.l	#2,playing
	bsr	mt_end

	bsr	pause
	
	move.l	#-1,showsound1
	move.l	#-1,showsound2
	move.l	#-1,showsound3
	move.l	#-1,showsound4
	move.w	#-1,showlen1
	move.w	#-1,showlen2
	move.w	#-1,showlen3
	move.w	#-1,showlen4

	lea	mt_chan1temp,a6
	move.l	0,00(a6)
	move.l	0,04(a6)
	move.l	0,08(a6)
	move.l	0,12(a6)
	move.l	0,16(a6)
	move.l	0,24(a6)
	move.l	0,28(a6)
	move.l	0,32(a6)
	move.l	0,36(a6)
	move.l	0,40(a6)

	lea	mt_chan2temp,a6
	move.l	0,00(a6)
	move.l	0,04(a6)
	move.l	0,08(a6)
	move.l	0,12(a6)
	move.l	0,16(a6)
	move.l	0,24(a6)
	move.l	0,28(a6)
	move.l	0,32(a6)
	move.l	0,36(a6)
	move.l	0,40(a6)
	
	lea	mt_chan3temp,a6
	move.l	0,00(a6)
	move.l	0,04(a6)
	move.l	0,08(a6)
	move.l	0,12(a6)
	move.l	0,16(a6)
	move.l	0,24(a6)
	move.l	0,28(a6)
	move.l	0,32(a6)
	move.l	0,36(a6)
	move.l	0,40(a6)
	
	lea	mt_chan4temp,a6
	move.l	0,00(a6)
	move.l	0,04(a6)
	move.l	0,08(a6)
	move.l	0,12(a6)
	move.l	0,16(a6)
	move.l	0,24(a6)
	move.l	0,28(a6)
	move.l	0,32(a6)
	move.l	0,36(a6)
	move.l	0,40(a6)

	move.l	(a7)+,DotCount
	rts

no_new_file:
	move.l	(a7)+,DotCount
	move.l	#-1,playing
	rts
	
pa:	cmp.b	$dff006,d0
	bne.s	pa
	rts
	
pause:	move.b	#$30,d0
	bsr	pa
	move.b	#$2f,d0
	bsr	pa
	move.b	#$30,d0
	bsr	pa
	rts
	
	
readmouse:	clr.l	d0
	clr.l	d1
	
	move.b	$dff00a,d0
	move.l	oldy,d1
	sub.l	d0,d1
	move.l	d1,yp
	
	move.l	d0,oldy
	
	cmp.l	#127,yp
	ble.s	mouse_not_128
	sub.l	#256,yp
mouse_not_128:
	cmp.l	#-127,yp
	bge.s	mouse_not_minus
	add.l	#256,yp
mouse_not_minus:
	move.l	yp,d0
	add.l	d0,yp2

	cmp.l	#ymin,yp2
	bge.s	ypos_ok1
	move.l	#ymin,yp2
ypos_ok1:
	cmp.l	#ymax,yp2
	blt.s	ypos_ok2
	move.l	#ymax,yp2
ypos_ok2:

	move.l	#270,d0
	sub.l	yp2,d0
	move.l	d0,ypos

	rts	
hide_ptr:
	move.l	ypos,d0
	mulu	#40,d0
	lea	menuscreen+34,a0	;+32,a0
	add.l	d0,a0
	add.l	#xshift,a0
	
	bsr	do_clr

	add.l	#40*128,a0
	bsr	do_clr

	add.l	#40*128,a0
	bsr	do_clr

	add.l	#40*128,a0
	bsr	do_clr

	rts
	
show_ptr:	move.l	ypos,d0
	mulu	#40,d0
	lea	menuscreen+34,a0	;+32,a0
	add.l	d0,a0
	add.l	#xshift,a0
	
	lea	pointer,a1
	
	bsr	do_blit

	add.l	#40*128,a0
	add.l	#32,a1
	bsr	do_blit

	add.l	#40*128,a0
	add.l	#32,a1
	bsr	do_blit

	add.l	#40*128,a0
	add.l	#32,a1
	bsr	do_blit

	rts



do_blit:	bsr	wtblit

	Move.l	a0,$dff054		; dest mem d
	Move.l	a1,$dff050		; source mem a
	Move.w	#$ffff,$dff044	; blit 1st word mask source a
	move.w	#$ffff,$dff046	; blit last word mask source a
	move.w	#0,$dff064		; blit modulo for source a
	move.w	#(%1001*256)+$f0,$dff040; blit cont reg 0
	move.w	#0,$dff042		; blit cont reg 1
	Move.w	#38,$dff066		; modulo for dest
	Move.w	#(16*64)+1,$dff058	; blit height,width

	rts

do_clr:	bsr	wtblit

	Move.l	a0,$dff054		; dest mem d
	Move.w	#$0,$dff044		; blit 1st word mask source a
	move.w	#$0,$dff046		; blit last word mask source a
	move.w	#(%0001*256)+$0,$dff040	; blit cont reg 0
	move.w	#0,$dff042		; blit cont reg 1
	Move.w	#38,$dff066		; modulo for dest
	Move.w	#(16*64)+1,$dff058	; blit height,width

	rts

scroller:	sub.l	#speed,pos
	bmi.s	scroll_new
	
	move.l	#display+64+scrollin,a1
	move.l	#display+64+scrollin+(speed*40),a0
	bsr	do_scroll
	
	add.l	#292*40,a1
	add.l	#292*40,a0
	bsr	do_scroll
	
	add.l	#292*40,a1
	add.l	#292*40,a0
	bsr	do_scroll
	
	add.l	#292*40,a1
	add.l	#292*40,a0
	bsr	do_scroll
	
	rts

scroll_new:
	move.l	scroll_ptr,a0
	add.l	#1,scroll_ptr
	clr.l	d0
	move.b	(a0),d0
	cmp.b	#0,d0
	bne.s	scroll_ok
	move.b	#32,d0
	move.l	#scroll_text,scroll_ptr

scroll_ok:
	move.l	#font,a0
	sub.w	#32,d0
	mulu	#544,d0
	add.l	d0,a0
	
	move.l	#display+64+scrollin+(40*256),a1
	bsr	do_chr
	
	add.l	#292*40,a1
	add.l	#136,a0
	bsr	do_chr
	
	add.l	#292*40,a1
	add.l	#136,a0
	bsr	do_chr
	
	add.l	#292*40,a1
	add.l	#136,a0
	bsr	do_chr
	
	move.l	#34,pos
	bra	scroller




do_chr:	bsr	wtblit

	Move.l	a1,$dff054		; dest mem d
	Move.l	a0,$dff050		; source mem a
	Move.w	#$ffff,$dff044	; blit 1st word mask source a
	move.w	#$ffff,$dff046	; blit last word mask source a
	move.w	#(%1001*256)+$f0,d7
	move.w	d7,$dff040		; blit cont reg 0
	move.w	#0,$dff042		; blit cont reg 1
	move.w	#0,$dff064		; blit modulo for source a
	Move.w	#36,$dff066		; modulo for dest
	Move.w	#(34*64)+2,$dff058	; blit height,width

	rts

do_scroll:	bsr	wtblit

	Move.l	a1,$dff054		; dest mem d
	Move.l	a0,$dff050		; source mem a
	Move.w	#$ffff,$dff044	; blit 1st word mask source a
	move.w	#$ffff,$dff046	; blit last word mask source a
	move.w	#(%1001*256)+$f0,d7	
	move.w	d7,$dff040		; blit cont reg 0
	move.w	#0,$dff042		; blit cont reg 1
	move.w	#36,$dff064		; blit modulo for source a
	Move.w	#36,$dff066		; modulo for dest
	Move.w	#(291*64)+2,$dff058	; blit height,width

	rts



my_level3:	Movem.l	d0-d7/a0-a6,-(a7)	; New copper
	Move.w	#$10,$dff09c	; Serviced Interupt

	add.l	#1,FrameCount

	cmp.l	#0,playing
	beq	water_exit
	cmp.l	#1,playing
	beq	file_exit
	cmp.l	#2,playing
	beq	len_ok4

	bsr	scroller

	bsr	extract_sound	

	bsr	wtblit
	move.l	screen1a,a1
	move.l	a1,$dff054			; dest mem d
	Move.w	#$0000,$dff044		; blit 1st word mask source a
	Move.w	#$0000,$dff046		; blit last word mask source a
	move.w	#%0001*256+0,$dff040		; blit cont reg 0
	move.w	#0,$dff042			; blit cont reg 1
	Move.w	#4,$dff066			; modulo for dest
	Move.w	#256*64+18,$dff058		; blit height,width

	bsr	mt_music
	
	moveq.l	#0,d0
	cmp.w	#0,showlen1
	bmi	len_ok1

	LEA	mt_chan1temp,A6
	MOVE.W	n_period(A6),D0
	sub.w	d0,showlen1
	add.l	d0,showsound1

len_ok1:	cmp.w	#0,showlen2
	bmi	len_ok2
	LEA	mt_chan2temp,A6
	MOVE.W	n_period(A6),D0
	sub.w	d0,showlen2
	add.l	d0,showsound2

len_ok2:	cmp.w	#0,showlen3
	bmi	len_ok3
	LEA	mt_chan3temp,A6
	MOVE.W	n_period(A6),D0
	sub.w	d0,showlen3
	add.l	d0,showsound3

len_ok3:	cmp.w	#0,showlen4
	bmi	len_ok4
	LEA	mt_chan4temp,A6
	MOVE.W	n_period(A6),D0
	sub.w	d0,showlen4
	add.l	d0,showsound4

len_ok4:	btst	#7,$bfe001
	bne	Exit

	move.w	#$008,$dff180
	bsr	wtblit
	move.w	#$00f,$dff180

Exit:	Movem.l	(a7)+,d0-d7/a0-a6
	Rte			; Return from Interupt

water_exit:
	sub.l	#1,water_delay
	bpl.s	water_ok
	
	move.l	#2,water_delay
	move.l	#1,$dff084

	move.l	water_ptr,a2
	move.l	loc,d2
	
	move.l	(a2),a0
	add.l	d2,a0
	
	lea	water_pic1,a1
	move.w	#1219,d0
water_loop:
	move.l	(a0)+,(a1)+
	dbf	d0,water_loop

	move.l	water_dir,d0
	add.l	d0,water_ptr
	move.l	water_ptr,a0	
	cmp.l	#0,(a0)
	bne.s	water_ok
	
	move.l	water_start,water_ptr
water_ok:	

	Movem.l	(a7)+,d0-d7/a0-a6
	Rte			; Return from Interupt

file_exit:	bsr	hide_ptr
	bsr	readmouse
	bsr	show_ptr

	bsr	mt_music
	
	Movem.l	(a7)+,d0-d7/a0-a6
	Rte			; Return from Interupt


loadmusic:	add.w	#$3300,load_wait
	bsr	setload
	
	Move.l	#wet_copper,$dff080 	; Address of copper 1
	move.l	#0,playing
	move.l	#4,water_dir
	move.l	#water_table,water_start
	
	move.l	anim_pal_ptr,a0	
	move.l	(a0),a1
	lea	anim_cols+2,a0
	move.w	#15,d0
acmap_loop:
	move.w	(a1)+,(a0)
	add.l	#4,a0
	dbf	d0,acmap_loop

	add.l	#4,anim_pal_ptr
	move.l	anim_pal_ptr,a0	
	cmp.l	#0,(a0)
	bne.s	anim_pal_ok
	
	move.l	#anim_pal_list,anim_pal_ptr
anim_pal_ok:	
	
	move.w	#49,d0
downx3:	sub.w	#$100,load_wait
	bsr	wait_beam
	dbf	d0,downx3

reload:	move.l	filesptr,a1

	move.l	buffer,a0		; start address
	move.l	0(a1),d0		; byte address of data on disk
	move.l	4(a1),d1		; number of bytes to transfair
	trap	#load		; load data from non-dos

	move.l	8(a1),d2		; checksum
	move.l	4(a1),d1		; number of bytes to transfair

	; a0 = address of data read

	clr.l	d0
	clr.l	d3
	sub.l	#1,d1
	move.l	a0,a6
checkloop:
	move.b	(a6),d0
	add.l	d0,d3
	add.l	#1,a6
	dbf	d1,checkloop

	cmp.l	d2,d3
	bne.s	reload

good:	move.l	#-4,water_dir
	move.l	#water_end-4,water_start

	move.w	#49,d0
downx1:	add.w	#$100,load_wait
	bsr	wait_beam
	dbf	d0,downx1

	bsr	setdecr

	move.w	#50,d0
downx2:	sub.w	#$100,load_wait
	bsr	wait_beam
	dbf	d0,downx2

	move.l	a0,a5
	add.l	#4,a5		; unpack info
	add.l	4(a1),a0
	move.l	#mt_data,a1		; address to unpack to (start)
	move.l	a1,a3		; address to unpack to (start)
	
	bsr	unpack

	Move.l	#my_copper,$dff080 	; Address of copper 1
	bsr	mt_init
	move.l	#-1,playing
	rts

wait_beam:	cmp.b	#$2c,$dff006
	bne.s	wait_beam
	
wait_beam2:	cmp.b	#$30,$dff006
	bne.s	wait_beam2
	rts

bad_pic:	move.w	#$ffff,d0
bad_loop:
	move.w	$dff006,$dff180
	mulu	#99,d1
	dbf	d0,bad_loop
	
	add.l	#12,filesptr
	rts
	
	include	sc:load.i

unpack:	MOVEQ	#3,D6
	MOVEQ	#1,D4
	MOVEQ	#7,D7
	MOVEQ	#1,D5
	MOVEA.L	A3,A2
	MOVE.L	-(A0),D1
	TST.B	D1
	BEQ.S	ppB52
	BSR.S	ppB76
	SUB.L	D4,D1
	LSR.L	D1,D5
ppB52	LSR.L	#8,D1
	ADDA.L	D1,A3
ppB56	BSR.S	ppB76
	BCS.S	ppB98
	MOVEQ	#0,D2
ppB5C	MOVE.W	D4,D0
	BSR.S	ppB84
	ADD.W	D1,D2
	CMP.W	D6,D1
	BEQ.S	ppB5C
ppB66	MOVEQ	#7,D0
	BSR.S	ppB84
	MOVE.B	D1,-(A3)
	DBF	D2,ppB66
	CMPA.L	A3,A2
	BCS.S	ppB98
	RTS
ppB76	LSR.L	D4,D5
	BEQ.S	ppB7C
	RTS
ppB7C	MOVE.L	-(A0),D5
	ROXR.L	D4,D5
	RTS
ppB82	SUB.W	D4,D0
ppB84	MOVEQ	#0,D1
ppB86	LSR.L	D4,D5
	BEQ.S	ppB92
ppB8A	ROXL.L	D4,D1
	DBF	D0,ppB86
	RTS
ppB92	MOVE.L	-(A0),D5
	ROXR.L	D4,D5
	BRA.S	ppB8A
ppB98	MOVE.W	D4,D0
	BSR.S	ppB84
	MOVEQ	#0,D0
	MOVE.B	0(A5,D1.W),D0
	MOVE.W	D1,D2
	CMP.W	D6,D2
	BNE.S	ppBBE
	BSR.S	ppB76
	BCS.S	ppBAE
	MOVEQ	#7,D0
ppBAE	BSR.S	ppB82
	MOVE.W	D1,D3
ppBB2	MOVEQ	#2,D0
	BSR.S	ppB84
	ADD.W	D1,D2
	CMP.W	D7,D1
	BEQ.S	ppBB2
	BRA.S	ppBC2
ppBBE	BSR.S	ppB82
	MOVE.W	D1,D3
ppBC2	ADD.W	D4,D2
	;move.w	d2,$dff180
ppBC4	MOVE.B	0(A3,D3.W),-(A3)
	DBF	D2,ppBC4
upk:	CMPA.L	A3,A2
	BCS	ppB56
	RTS
	

extract_sound:
	move.w	#$f00,d0
	bsr	sjoy
	move.l	showsound1,a1
	move.l	showlen1,a2
	move.l	#1,d0
	LEA	mt_chan1temp,a6
	move.w	n_period(A6),d4
	clr.l	d3
	move.b	n_volume(A6),d3
	bsr	show_dots

	move.w	#$c00,d0
	bsr	sjoy
	move.l	showsound2,a1
	move.l	showlen2,a2
	move.l	#18,d0
	LEA	mt_chan2temp,a6
	move.w	n_period(A6),d4
	clr.l	d3
	move.b	n_volume(A6),d3
	bsr	show_dots	

	move.w	#$00f,d0
	bsr	sjoy
	move.w	#0,d0
.wait	move.b	$dff006,d0
	cmp.w	#$80,d0
	blt	.wait

	move.w	#$800,d0
	bsr	sjoy
	move.l	showsound3,a1
	move.l	showlen3,a2
	move.l	#40*128+1,d0
	LEA	mt_chan3temp,a6
	move.w	n_period(A6),d4
	clr.l	d3
	move.b	n_volume(A6),d3
	bsr	show_dots

	move.w	#$400,d0
	bsr	sjoy
	move.l	showsound4,a1
	move.l	showlen4,a2
	move.l	#40*128+18,d0
	LEA	mt_chan4temp,a6
	move.w	n_period(A6),d4
	clr.l	d3
	move.b	n_volume(A6),d3
	bsr	show_dots

	move.w	#$000,d0
	bsr	sjoy
	rts

sjoy:	btst	#7,$bfe001
	bne	.no
	move.w	d0,$dff180
.no	rts

wtblit:	Btst.b	#6,$dff002
	Bne.s	wtblit
	rts

show_dots:	cmp.w	#63,d3
	blt.s	vol_ok
	
	move.w	#63,d3			; volume should be 0-63
					; any more is max!
vol_ok:	move.l	#63,d7
	sub.l	d3,d7
	move.l	d7,d3
	
	move.l	screen1a,a0
	add.l	d0,a0
	add.l	#40,a0
	
	cmp.l	DotCount,a2
	bgt	sound_ok
	
	lea	null,a1
	moveq.l	#0,d4	
	moveq.l	#0,d3

sound_ok:	lea	invertx,a2
	lea	inverty,a5
	mulu	#258,d3
	add.w	d3,a2
	add.w	d3,a5
	
	lea	times40,a3

	move.l	a1,a4
	add.l	d4,a4
	
	moveq.l	#0,d4
	move.b	256(a2),d4
	lsr.w	#1,d4
	moveq.l	#0,d5
	move.b	256(a5),d5

	move.l	DotCount,d7

show_loop1:	moveq.l	#0,d0
	moveq.l	#0,d1
	move.b	(a1)+,d0			; xpos
	move.b	(a4)+,d1			; ypos
	
	move.b	(a2,d0.w),d0		; correct
	move.b	(a5,d1.w),d1		; correct

	add.w	d4,d0			; centre x
	add.w	d5,d1			; centre y

	move.b	d0,d2			; calculate
	and.b	#7,d2			; x bit
	not.b	d2			; flip x bit
	
	lsr.w	#3,d0			; x div 8
	
	and.w	#$fffe,d1			; make even
	add.w	(a3,d1.w),d0		; add depth to d0
	
	bset	d2,(a0,d0.w)		; set dot

	dbf	d7,show_loop1
no_sound:	rts	

;********************************************
;* ----- Protracker V1.1B Playroutine ----- *
;* Lars "Zap" Hamre/Amiga Freelancers 1991  *
;* Bekkeliveien 10, N-2010 STRØMMEN, Norway *
;********************************************

DMAWait = 300 ; Set this as low as possible without losing low notes.

n_note		EQU	0  ; W
n_cmd		EQU	2  ; W
n_cmdlo		EQU	3  ; B
n_start		EQU	4  ; L
n_length		EQU	8  ; W
n_loopstart	EQU	10 ; L
n_replen		EQU	14 ; W
n_period		EQU	16 ; W
n_finetune	EQU	18 ; B
n_volume		EQU	19 ; B
n_dmabit		EQU	20 ; W
n_toneportdirec	EQU	22 ; B
n_toneportspeed	EQU	23 ; B
n_wantedperiod	EQU	24 ; W
n_vibratocmd	EQU	26 ; B
n_vibratopos	EQU	27 ; B
n_tremolocmd	EQU	28 ; B
n_tremolopos	EQU	29 ; B
n_wavecontrol	EQU	30 ; B
n_glissfunk	EQU	31 ; B
n_sampleoffset	EQU	32 ; B
n_pattpos	EQU	33 ; B
n_loopcount	EQU	34 ; B
n_funkoffset	EQU	35 ; B
n_wavestart	EQU	36 ; L
n_reallength	EQU	40 ; W

mt_WaitDMA	movem.l	d0-d7,-(a7)

	moveq	#OzDMA,d1
.loop1	move.w	$dff006,d0
	and.w	#$000f,d0
	bne	.loop1
	dbf	d1,.loop1
	
	movem.l	(a7)+,d0-d7	
	rts


mt_init	LEA	mt_data,A0
	MOVE.L	A0,mt_SongDataPtr
	MOVE.L	A0,A1
	LEA	952(A1),A1
	MOVEQ	#127,D0
	MOVEQ	#0,D1
mtloop	MOVE.L	D1,D2
	SUBQ.W	#1,D0
mtloop2	MOVE.B	(A1)+,D1
	CMP.B	D2,D1
	BGT.S	mtloop
	DBRA	D0,mtloop2
	ADDQ.B	#1,D2
			
	LEA	mt_SampleStarts(PC),A1
	ASL.L	#8,D2
	ASL.L	#2,D2
	ADD.L	#1084,D2
	ADD.L	A0,D2
	MOVE.L	D2,A2
	MOVEQ	#30,D0
mtloop3	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	#30,A0
	DBRA	D0,mtloop3

	OR.B	#2,$BFE001
	MOVE.B	#6,mt_speed
	CLR.B	mt_counter
	CLR.B	mt_SongPos
	CLR.W	mt_PatternPos

mt_end	CLR.W	$DFF0A8
	CLR.W	$DFF0B8
	CLR.W	$DFF0C8
	CLR.W	$DFF0D8
	MOVE.W	#$F,$DFF096
	RTS

mt_music
	MOVEM.L	D0-D4/A0-A6,-(SP)
	ADDQ.B	#1,mt_counter
	MOVE.B	mt_counter(PC),D0
	CMP.B	mt_speed(PC),D0
	BLO.S	mt_NoNewNote
	CLR.B	mt_counter
	TST.B	mt_PattDelTime2
	BEQ.S	mt_GetNewNote
	BSR.S	mt_NoNewAllChannels
	BRA	mt_dskip

mt_NoNewNote
	BSR.S	mt_NoNewAllChannels
	BRA	mt_NoNewPosYet

mt_NoNewAllChannels
	LEA	$DFF0A0,A5
	LEA	mt_chan1temp(PC),A6
	BSR	mt_CheckEfx
	
	LEA	$DFF0B0,A5
	LEA	mt_chan2temp(PC),A6
	BSR	mt_CheckEfx

	LEA	$DFF0C0,A5
	LEA	mt_chan3temp(PC),A6
	BSR	mt_CheckEfx

	LEA	$DFF0D0,A5
	LEA	mt_chan4temp(PC),A6
	BRA	mt_CheckEfx

mt_GetNewNote
	MOVE.L	mt_SongDataPtr(PC),A0
	LEA	12(A0),A3
	LEA	952(A0),A2	;pattpo
	LEA	1084(A0),A0	;patterndata
	MOVEQ	#0,D0
	MOVEQ	#0,D1
	MOVE.B	mt_SongPos(PC),D0
	MOVE.B	(A2,D0.W),D1
	ASL.L	#8,D1
	ASL.L	#2,D1
	ADD.W	mt_PatternPos(PC),D1
	CLR.W	mt_DMACONtemp

	LEA	$DFF0A0,A5
	LEA	mt_chan1temp(PC),A6
	move.l	#showsound1,ss
	move.l	#showlen1,sl
	BSR	mt_PlayVoice
	
	LEA	$DFF0B0,A5
	LEA	mt_chan2temp(PC),A6
	move.l	#showsound2,ss
	move.l	#showlen2,sl
	BSR.S	mt_PlayVoice
	
	LEA	$DFF0C0,A5
	LEA	mt_chan3temp(PC),A6
	move.l	#showsound3,ss
	move.l	#showlen3,sl
	BSR.S	mt_PlayVoice
	
	LEA	$DFF0D0,A5
	LEA	mt_chan4temp(PC),A6
	move.l	#showsound4,ss
	move.l	#showlen4,sl
	BSR.S	mt_PlayVoice
	
	BRA	mt_SetDMA

mt_PlayVoice
	TST.L	(A6)
	BNE.S	mt_plvskip
	BSR	mt_PerNop
mt_plvskip
	MOVE.L	(A0,D1.L),(A6)
	ADDQ.L	#4,D1
	MOVEQ	#0,D2
	MOVE.B	n_cmd(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	mt_SetRegs
	
	MOVEQ	#0,D3
	LEA	mt_SampleStarts(PC),A1
	MOVE	D2,D4
	SUBQ.L	#1,D2
	ASL.L	#2,D2
	MULU	#30,D4
	MOVE.L	(A1,D2.L),n_start(A6)
	MOVE.W	(A3,D4.L),n_length(A6)
	MOVE.W	(A3,D4.L),n_reallength(A6)
	MOVE.B	2(A3,D4.L),n_finetune(A6)
	MOVE.B	3(A3,D4.L),n_volume(A6)
	
	***********

	movem.l	a0-a6,-(a7)

	cmp.b	#0,n_volume(a6)
	beq	no_vol

	move.l	ss,a0		; sample start at
	move.l	n_start(a6),(a0)

	move.l	sl,a0		; sound length
	move.w	n_length(a6),(a0)

no_vol:	movem.l	(a7)+,a0-a6
	
	************

	MOVE.W	4(A3,D4.L),D3 ; Get repeat
	TST.W	D3
	BEQ.S	mt_NoLoop
	
	MOVE.L	n_start(A6),D2	; Get start
	ASL.W	#1,D3
	ADD.L	D3,D2		; Add repeat
	MOVE.L	D2,n_loopstart(A6)
	MOVE.L	D2,n_wavestart(A6)
	MOVE.W	4(A3,D4.L),D0	; Get repeat
	ADD.W	6(A3,D4.L),D0	; Add replen
	MOVE.W	D0,n_length(A6)
	MOVE.W	6(A3,D4.L),n_replen(A6)	; Save replen
	MOVEQ	#0,D0
	MOVE.B	n_volume(A6),D0
	MOVE.W	D0,8(A5)	; Set volume
	BRA.S	mt_SetRegs

mt_NoLoop
	MOVE.L	n_start(A6),D2
	ADD.L	D3,D2
	MOVE.L	D2,n_loopstart(A6)
	MOVE.L	D2,n_wavestart(A6)
	MOVE.W	6(A3,D4.L),n_replen(A6)	; Save replen
	MOVEQ	#0,D0
	MOVE.B	n_volume(A6),D0
	MOVE.W	D0,8(A5)	; Set volume
	
mt_SetRegs
	MOVE.W	(A6),D0
	AND.W	#$0FFF,D0
	BEQ	mt_CheckMoreEfx	; If no note
	MOVE.W	2(A6),D0
	AND.W	#$0FF0,D0
	CMP.W	#$0E50,D0
	BEQ.S	mt_DoSetFineTune
	MOVE.B	2(A6),D0
	AND.B	#$0F,D0
	CMP.B	#3,D0	; TonePortamento
	BEQ.S	mt_ChkTonePorta
	CMP.B	#5,D0
	BEQ.S	mt_ChkTonePorta
	CMP.B	#9,D0	; Sample Offset
	BNE.S	mt_SetPeriod
	BSR	mt_CheckMoreEfx
	BRA.S	mt_SetPeriod

mt_DoSetFineTune
	BSR	mt_SetFineTune
	BRA.S	mt_SetPeriod

mt_ChkTonePorta
	BSR	mt_SetTonePorta
	BRA	mt_CheckMoreEfx

mt_SetPeriod
	MOVEM.L	D0-D1/A0-A1,-(SP)
	MOVE.W	(A6),D1
	AND.W	#$0FFF,D1
	LEA	mt_PeriodTable(PC),A1
	MOVEQ	#0,D0
	MOVEQ	#36,D7
mt_ftuloop
	CMP.W	(A1,D0.W),D1
	BHS.S	mt_ftufound
	ADDQ.L	#2,D0
	DBRA	D7,mt_ftuloop
mt_ftufound
	MOVEQ	#0,D1
	MOVE.B	n_finetune(A6),D1
	MULU	#36*2,D1
	ADD.L	D1,A1
	MOVE.W	(A1,D0.W),n_period(A6)
	MOVEM.L	(SP)+,D0-D1/A0-A1

	MOVE.W	2(A6),D0
	AND.W	#$0FF0,D0
	CMP.W	#$0ED0,D0 ; Notedelay
	BEQ	mt_CheckMoreEfx

	MOVE.W	n_dmabit(A6),$DFF096
	BTST	#2,n_wavecontrol(A6)
	BNE.S	mt_vibnoc
	CLR.B	n_vibratopos(A6)
mt_vibnoc
	BTST	#6,n_wavecontrol(A6)
	BNE.S	mt_trenoc
	CLR.B	n_tremolopos(A6)
mt_trenoc
	MOVE.L	n_start(A6),(A5)	; Set start
	MOVE.W	n_length(A6),4(A5)	; Set length
	MOVE.W	n_period(A6),D0
	MOVE.W	D0,6(A5)		; Set period
	MOVE.W	n_dmabit(A6),D0
	OR.W	D0,mt_DMACONtemp
	BRA	mt_CheckMoreEfx
 
mt_SetDMA
	bsr	mt_WaitDMA
	MOVE.W	mt_DMACONtemp(PC),D0
	OR.W	#$8000,D0
	MOVE.W	D0,$DFF096
	bsr	mt_WaitDMA
	
	************



	LEA	mt_chan1temp(PC),A6
	move.w	n_period(a6),a5
	cmp.w	showlen1,a5
	ble	no_sound1
	cmp.w	#160,n_replen(a6)
	ble	no_sound1
	cmp.b	#0,n_volume(a6)
	beq	no_sound1
	move.l	n_loopstart(a6),showsound1
	move.w	n_replen(a6),showlen1
no_sound1:

	LEA	mt_chan2temp(PC),A6
	move.w	n_period(a6),a5
	cmp.w	showlen2,a5
	ble	no_sound2
	cmp.w	#160,n_replen(a6)
	ble	no_sound2
	cmp.b	#0,n_volume(a6)
	beq	no_sound2
	move.l	n_loopstart(a6),showsound2
	move.w	n_replen(a6),showlen2
no_sound2:

	LEA	mt_chan3temp(PC),A6
	move.w	n_period(a6),a5
	cmp.w	showlen3,a5
	ble	no_sound3
	cmp.w	#160,n_replen(a6)
	ble	no_sound3
	cmp.b	#0,n_volume(a6)
	beq	no_sound3
	move.l	n_loopstart(a6),showsound3
	move.w	n_replen(a6),showlen3
no_sound3:

	LEA	mt_chan4temp(PC),A6
	move.w	n_period(a6),a5
	cmp.w	showlen4,a5
	ble	no_sound4
	cmp.w	#160,n_replen(a6)
	ble	no_sound4
	cmp.b	#0,n_volume(a6)
	beq	no_sound4
	move.l	n_loopstart(a6),showsound4
	move.w	n_replen(a6),showlen4
no_sound4:



	************

	LEA	$DFF000,A5
	
	move.l	#1,$dff084
	
	LEA	mt_chan4temp(PC),A6
	MOVE.L	n_loopstart(A6),$D0(A5)
	MOVE.W	n_replen(A6),$D4(A5)
	
	LEA	mt_chan3temp(PC),A6
	MOVE.L	n_loopstart(A6),$C0(A5)
	MOVE.W	n_replen(A6),$C4(A5)

	LEA	mt_chan2temp(PC),A6
	MOVE.L	n_loopstart(A6),$B0(A5)
	MOVE.W	n_replen(A6),$B4(A5)

	LEA	mt_chan1temp(PC),A6
	MOVE.L	n_loopstart(A6),$A0(A5)
	MOVE.W	n_replen(A6),$A4(A5)

mt_dskip
	ADD.W	#16,mt_PatternPos
	MOVE.B	mt_PattDelTime,D0
	BEQ.S	mt_dskc
	MOVE.B	D0,mt_PattDelTime2
	CLR.B	mt_PattDelTime
mt_dskc	TST.B	mt_PattDelTime2
	BEQ.S	mt_dska
	SUBQ.B	#1,mt_PattDelTime2
	BEQ.S	mt_dska
	SUB.W	#16,mt_PatternPos
mt_dska	TST.B	mt_PBreakFlag
	BEQ.S	mt_nnpysk
	SF	mt_PBreakFlag
	MOVEQ	#0,D0
	MOVE.B	mt_PBreakPos(PC),D0
	CLR.B	mt_PBreakPos
	LSL.W	#4,D0
	MOVE.W	D0,mt_PatternPos
mt_nnpysk
	CMP.W	#1024,mt_PatternPos
	BLO.S	mt_NoNewPosYet
mt_NextPosition	
	MOVEQ	#0,D0
	MOVE.B	mt_PBreakPos(PC),D0
	LSL.W	#4,D0
	MOVE.W	D0,mt_PatternPos
	CLR.B	mt_PBreakPos
	CLR.B	mt_PosJumpFlag
	ADDQ.B	#1,mt_SongPos
	AND.B	#$7F,mt_SongPos
	MOVE.B	mt_SongPos(PC),D1
	MOVE.L	mt_SongDataPtr(PC),A0
	CMP.B	950(A0),D1
	BLO.S	mt_NoNewPosYet
	CLR.B	mt_SongPos
mt_NoNewPosYet	
	TST.B	mt_PosJumpFlag
	BNE.S	mt_NextPosition
	MOVEM.L	(SP)+,D0-D4/A0-A6
	RTS

mt_CheckEfx	
	movem.l	d0-d7/a0-a6,-(a7)

	LEA	mt_chan1temp(PC),A6
	cmp.w	#0,n_cmd(A6)
	beq	no_restart_1a
	cmp.w	#32,showlen1
	bgt.s	no_restart_1a
	cmp.w	#32,n_length(a6)
	blt.s	no_restart_1a
	move.l	n_loopstart(a6),showsound1
	move.w	n_length(a6),showlen1
no_restart_1a:
	
	LEA	mt_chan2temp(PC),A6
	cmp.w	#0,n_cmd(A6)
	beq	no_restart_2a
	cmp.w	#32,showlen2
	bgt.s	no_restart_2a
	cmp.w	#32,n_length(a6)
	blt.s	no_restart_2a
	move.l	n_loopstart(a6),showsound2
	move.w	n_length(a6),showlen2
no_restart_2a:
	
	LEA	mt_chan3temp(PC),A6
	cmp.w	#0,n_cmd(A6)
	beq	no_restart_3a
	cmp.w	#32,showlen3
	bgt.s	no_restart_3a
	cmp.w	#32,n_length(a6)
	blt.s	no_restart_3a
	move.l	n_loopstart(a6),showsound3
	move.w	n_length(a6),showlen3
no_restart_3a:
	
	LEA	mt_chan4temp(PC),A6
	cmp.w	#0,n_cmd(A6)
	beq	no_restart_4a
	cmp.w	#32,showlen4
	bgt.s	no_restart_4a
	cmp.w	#32,n_length(a6)
	blt.s	no_restart_4a
	move.l	n_loopstart(a6),showsound4
	move.w	n_length(a6),showlen4
no_restart_4a:

	movem.l	(a7)+,d0-d7/a0-a6

	BSR	mt_UpdateFunk
	
	MOVE.W	n_cmd(A6),D0
	AND.W	#$0FFF,D0
	BEQ.S	mt_PerNop
	MOVE.B	n_cmd(A6),D0
	AND.B	#$0F,D0
	BEQ.S	mt_Arpeggio
	CMP.B	#1,D0
	BEQ	mt_PortaUp
	CMP.B	#2,D0
	BEQ	mt_PortaDown
	CMP.B	#3,D0
	BEQ	mt_TonePortamento
	CMP.B	#4,D0
	BEQ	mt_Vibrato
	CMP.B	#5,D0
	BEQ	mt_TonePlusVolSlide
	CMP.B	#6,D0
	BEQ	mt_VibratoPlusVolSlide
	CMP.B	#$E,D0
	BEQ	mt_E_Commands
SetBack	MOVE.W	n_period(A6),6(A5)
	CMP.B	#7,D0
	BEQ	mt_Tremolo
	CMP.B	#$A,D0
	BEQ	mt_VolumeSlide
mt_Return2
	RTS

mt_PerNop
	MOVE.W	n_period(A6),6(A5)
	
	RTS

mt_Arpeggio
	MOVEQ	#0,D0
	MOVE.B	mt_counter(PC),D0
	DIVS	#3,D0
	SWAP	D0
	CMP.W	#0,D0
	BEQ.S	mt_Arpeggio2
	CMP.W	#2,D0
	BEQ.S	mt_Arpeggio1
	MOVEQ	#0,D0
	MOVE.B	n_cmdlo(A6),D0
	LSR.B	#4,D0
	BRA.S	mt_Arpeggio3

mt_Arpeggio1
	MOVEQ	#0,D0
	MOVE.B	n_cmdlo(A6),D0
	AND.B	#15,D0
	BRA.S	mt_Arpeggio3

mt_Arpeggio2
	MOVE.W	n_period(A6),D2
	BRA.S	mt_Arpeggio4

mt_Arpeggio3
	ASL.W	#1,D0
	MOVEQ	#0,D1
	MOVE.B	n_finetune(A6),D1
	MULU	#36*2,D1
	LEA	mt_PeriodTable(PC),A0
	ADD.L	D1,A0
	MOVEQ	#0,D1
	MOVE.W	n_period(A6),D1
	MOVEQ	#36,D7
mt_arploop
	MOVE.W	(A0,D0.W),D2
	CMP.W	(A0),D1
	BHS.S	mt_Arpeggio4
	ADDQ.L	#2,A0
	DBRA	D7,mt_arploop
	RTS

mt_Arpeggio4
	MOVE.W	D2,6(A5)
	RTS

mt_FinePortaUp
	TST.B	mt_counter
	BNE.S	mt_Return2
	MOVE.B	#$0F,mt_LowMask
mt_PortaUp
	MOVEQ	#0,D0
	MOVE.B	n_cmdlo(A6),D0
	AND.B	mt_LowMask(PC),D0
	MOVE.B	#$FF,mt_LowMask
	SUB.W	D0,n_period(A6)
	MOVE.W	n_period(A6),D0
	AND.W	#$0FFF,D0
	CMP.W	#113,D0
	BPL.S	mt_PortaUskip
	AND.W	#$F000,n_period(A6)
	OR.W	#113,n_period(A6)
mt_PortaUskip
	MOVE.W	n_period(A6),D0
	AND.W	#$0FFF,D0
	MOVE.W	D0,6(A5)
	RTS	
 
mt_FinePortaDown
	TST.B	mt_counter
	BNE	mt_Return2
	MOVE.B	#$0F,mt_LowMask
mt_PortaDown
	CLR.W	D0
	MOVE.B	n_cmdlo(A6),D0
	AND.B	mt_LowMask(PC),D0
	MOVE.B	#$FF,mt_LowMask
	ADD.W	D0,n_period(A6)
	MOVE.W	n_period(A6),D0
	AND.W	#$0FFF,D0
	CMP.W	#856,D0
	BMI.S	mt_PortaDskip
	AND.W	#$F000,n_period(A6)
	OR.W	#856,n_period(A6)
mt_PortaDskip
	MOVE.W	n_period(A6),D0
	AND.W	#$0FFF,D0
	MOVE.W	D0,6(A5)
	RTS

mt_SetTonePorta
	MOVE.L	A0,-(SP)
	MOVE.W	(A6),D2
	AND.W	#$0FFF,D2
	MOVEQ	#0,D0
	MOVE.B	n_finetune(A6),D0
	MULU	#37*2,D0
	LEA	mt_PeriodTable(PC),A0
	ADD.L	D0,A0
	MOVEQ	#0,D0
mt_StpLoop
	CMP.W	(A0,D0.W),D2
	BHS.S	mt_StpFound
	ADDQ.W	#2,D0
	CMP.W	#37*2,D0
	BLO.S	mt_StpLoop
	MOVEQ	#35*2,D0
mt_StpFound
	MOVE.B	n_finetune(A6),D2
	AND.B	#8,D2
	BEQ.S	mt_StpGoss
	TST.W	D0
	BEQ.S	mt_StpGoss
	SUBQ.W	#2,D0
mt_StpGoss
	MOVE.W	(A0,D0.W),D2
	MOVE.L	(SP)+,A0
	MOVE.W	D2,n_wantedperiod(A6)
	MOVE.W	n_period(A6),D0
	CLR.B	n_toneportdirec(A6)
	CMP.W	D0,D2
	BEQ.S	mt_ClearTonePorta
	BGE	mt_Return2
	MOVE.B	#1,n_toneportdirec(A6)
	RTS

mt_ClearTonePorta
	CLR.W	n_wantedperiod(A6)
	RTS

mt_TonePortamento
	MOVE.B	n_cmdlo(A6),D0
	BEQ.S	mt_TonePortNoChange
	MOVE.B	D0,n_toneportspeed(A6)
	CLR.B	n_cmdlo(A6)
mt_TonePortNoChange
	TST.W	n_wantedperiod(A6)
	BEQ	mt_Return2
	MOVEQ	#0,D0
	MOVE.B	n_toneportspeed(A6),D0
	TST.B	n_toneportdirec(A6)
	BNE.S	mt_TonePortaUp
mt_TonePortaDown
	ADD.W	D0,n_period(A6)
	MOVE.W	n_wantedperiod(A6),D0
	CMP.W	n_period(A6),D0
	BGT.S	mt_TonePortaSetPer
	MOVE.W	n_wantedperiod(A6),n_period(A6)
	CLR.W	n_wantedperiod(A6)
	BRA.S	mt_TonePortaSetPer

mt_TonePortaUp
	SUB.W	D0,n_period(A6)
	MOVE.W	n_wantedperiod(A6),D0
	CMP.W	n_period(A6),D0
	BLT.S	mt_TonePortaSetPer
	MOVE.W	n_wantedperiod(A6),n_period(A6)
	CLR.W	n_wantedperiod(A6)

mt_TonePortaSetPer
	MOVE.W	n_period(A6),D2
	MOVE.B	n_glissfunk(A6),D0
	AND.B	#$0F,D0
	BEQ.S	mt_GlissSkip
	MOVEQ	#0,D0
	MOVE.B	n_finetune(A6),D0
	MULU	#36*2,D0
	LEA	mt_PeriodTable(PC),A0
	ADD.L	D0,A0
	MOVEQ	#0,D0
mt_GlissLoop
	CMP.W	(A0,D0.W),D2
	BHS.S	mt_GlissFound
	ADDQ.W	#2,D0
	CMP.W	#36*2,D0
	BLO.S	mt_GlissLoop
	MOVEQ	#35*2,D0
mt_GlissFound
	MOVE.W	(A0,D0.W),D2
mt_GlissSkip
	MOVE.W	D2,6(A5) ; Set period
	RTS

mt_Vibrato
	MOVE.B	n_cmdlo(A6),D0
	BEQ.S	mt_Vibrato2
	MOVE.B	n_vibratocmd(A6),D2
	AND.B	#$0F,D0
	BEQ.S	mt_vibskip
	AND.B	#$F0,D2
	OR.B	D0,D2
mt_vibskip
	MOVE.B	n_cmdlo(A6),D0
	AND.B	#$F0,D0
	BEQ.S	mt_vibskip2
	AND.B	#$0F,D2
	OR.B	D0,D2
mt_vibskip2
	MOVE.B	D2,n_vibratocmd(A6)
mt_Vibrato2
	MOVE.B	n_vibratopos(A6),D0
	LEA	mt_VibratoTable(PC),A4
	LSR.W	#2,D0
	AND.W	#$001F,D0
	MOVEQ	#0,D2
	MOVE.B	n_wavecontrol(A6),D2
	AND.B	#$03,D2
	BEQ.S	mt_vib_sine
	LSL.B	#3,D0
	CMP.B	#1,D2
	BEQ.S	mt_vib_rampdown
	MOVE.B	#255,D2
	BRA.S	mt_vib_set
mt_vib_rampdown
	TST.B	n_vibratopos(A6)
	BPL.S	mt_vib_rampdown2
	MOVE.B	#255,D2
	SUB.B	D0,D2
	BRA.S	mt_vib_set
mt_vib_rampdown2
	MOVE.B	D0,D2
	BRA.S	mt_vib_set
mt_vib_sine
	MOVE.B	0(A4,D0.W),D2
mt_vib_set
	MOVE.B	n_vibratocmd(A6),D0
	AND.W	#15,D0
	MULU	D0,D2
	LSR.W	#7,D2
	MOVE.W	n_period(A6),D0
	TST.B	n_vibratopos(A6)
	BMI.S	mt_VibratoNeg
	ADD.W	D2,D0
	BRA.S	mt_Vibrato3
mt_VibratoNeg
	SUB.W	D2,D0
mt_Vibrato3
	MOVE.W	D0,6(A5)
	MOVE.B	n_vibratocmd(A6),D0
	LSR.W	#2,D0
	AND.W	#$003C,D0
	ADD.B	D0,n_vibratopos(A6)
	RTS

mt_TonePlusVolSlide
	BSR	mt_TonePortNoChange
	BRA	mt_VolumeSlide

mt_VibratoPlusVolSlide
	BSR	mt_Vibrato2
	BRA	mt_VolumeSlide

mt_Tremolo
	MOVE.B	n_cmdlo(A6),D0
	BEQ.S	mt_Tremolo2
	MOVE.B	n_tremolocmd(A6),D2
	AND.B	#$0F,D0
	BEQ.S	mt_treskip
	AND.B	#$F0,D2
	OR.B	D0,D2
mt_treskip
	MOVE.B	n_cmdlo(A6),D0
	AND.B	#$F0,D0
	BEQ.S	mt_treskip2
	AND.B	#$0F,D2
	OR.B	D0,D2
mt_treskip2
	MOVE.B	D2,n_tremolocmd(A6)
mt_Tremolo2
	MOVE.B	n_tremolopos(A6),D0
	LEA	mt_VibratoTable(PC),A4
	LSR.W	#2,D0
	AND.W	#$001F,D0
	MOVEQ	#0,D2
	MOVE.B	n_wavecontrol(A6),D2
	LSR.B	#4,D2
	AND.B	#$03,D2
	BEQ.S	mt_tre_sine
	LSL.B	#3,D0
	CMP.B	#1,D2
	BEQ.S	mt_tre_rampdown
	MOVE.B	#255,D2
	BRA.S	mt_tre_set
mt_tre_rampdown
	TST.B	n_vibratopos(A6)
	BPL.S	mt_tre_rampdown2
	MOVE.B	#255,D2
	SUB.B	D0,D2
	BRA.S	mt_tre_set
mt_tre_rampdown2
	MOVE.B	D0,D2
	BRA.S	mt_tre_set
mt_tre_sine
	MOVE.B	0(A4,D0.W),D2
mt_tre_set
	MOVE.B	n_tremolocmd(A6),D0
	AND.W	#15,D0
	MULU	D0,D2
	LSR.W	#6,D2
	MOVEQ	#0,D0
	MOVE.B	n_volume(A6),D0
	TST.B	n_tremolopos(A6)
	BMI.S	mt_TremoloNeg
	ADD.W	D2,D0
	BRA.S	mt_Tremolo3
mt_TremoloNeg
	SUB.W	D2,D0
mt_Tremolo3
	BPL.S	mt_TremoloSkip
	CLR.W	D0
mt_TremoloSkip
	CMP.W	#$40,D0
	BLS.S	mt_TremoloOk
	MOVE.W	#$40,D0
mt_TremoloOk
	MOVE.W	D0,8(A5)
	MOVE.B	n_tremolocmd(A6),D0
	LSR.W	#2,D0
	AND.W	#$003C,D0
	ADD.B	D0,n_tremolopos(A6)
	RTS

mt_SampleOffset
	MOVEQ	#0,D0
	MOVE.B	n_cmdlo(A6),D0
	BEQ.S	mt_sononew
	MOVE.B	D0,n_sampleoffset(A6)
mt_sononew
	MOVE.B	n_sampleoffset(A6),D0
	LSL.W	#7,D0
	CMP.W	n_length(A6),D0
	BGE.S	mt_sofskip
	SUB.W	D0,n_length(A6)
	LSL.W	#1,D0
	ADD.L	D0,n_start(A6)
	RTS
mt_sofskip
	MOVE.W	#$0001,n_length(A6)
	RTS

mt_VolumeSlide
	MOVEQ	#0,D0
	MOVE.B	n_cmdlo(A6),D0
	LSR.B	#4,D0
	TST.B	D0
	BEQ.S	mt_VolSlideDown
mt_VolSlideUp
	ADD.B	D0,n_volume(A6)
	CMP.B	#$40,n_volume(A6)
	BMI.S	mt_vsuskip
	MOVE.B	#$40,n_volume(A6)
mt_vsuskip
	MOVE.B	n_volume(A6),D0
	MOVE.W	D0,8(A5)
	RTS

mt_VolSlideDown
	MOVEQ	#0,D0
	MOVE.B	n_cmdlo(A6),D0
	AND.B	#$0F,D0
mt_VolSlideDown2
	SUB.B	D0,n_volume(A6)
	BPL.S	mt_vsdskip
	CLR.B	n_volume(A6)
mt_vsdskip
	MOVE.B	n_volume(A6),D0
	MOVE.W	D0,8(A5)
	RTS

mt_PositionJump
	MOVE.B	n_cmdlo(A6),D0
	SUBQ.B	#1,D0
	MOVE.B	D0,mt_SongPos
mt_pj2	CLR.B	mt_PBreakPos
	ST 	mt_PosJumpFlag
	RTS

mt_VolumeChange
	MOVEQ	#0,D0
	MOVE.B	n_cmdlo(A6),D0
	CMP.B	#$40,D0
	BLS.S	mt_VolumeOk
	MOVEQ	#$40,D0
mt_VolumeOk
	MOVE.B	D0,n_volume(A6)
	MOVE.W	D0,8(A5)
	RTS

mt_PatternBreak
	MOVEQ	#0,D0
	MOVE.B	n_cmdlo(A6),D0
	MOVE.L	D0,D2
	LSR.B	#4,D0
	MULU	#10,D0
	AND.B	#$0F,D2
	ADD.B	D2,D0
	CMP.B	#63,D0
	BHI.S	mt_pj2
	MOVE.B	D0,mt_PBreakPos
	ST	mt_PosJumpFlag
	RTS

mt_SetSpeed
	MOVE.B	3(A6),D0
	BEQ	mt_Return2
	CLR.B	mt_counter
	MOVE.B	D0,mt_speed
	RTS

mt_CheckMoreEfx
	BSR	mt_UpdateFunk
	MOVE.B	2(A6),D0
	AND.B	#$0F,D0
	CMP.B	#$9,D0
	BEQ	mt_SampleOffset
	CMP.B	#$B,D0
	BEQ	mt_PositionJump
	CMP.B	#$D,D0
	BEQ.S	mt_PatternBreak
	CMP.B	#$E,D0
	BEQ.S	mt_E_Commands
	CMP.B	#$F,D0
	BEQ.S	mt_SetSpeed
	CMP.B	#$C,D0
	BEQ	mt_VolumeChange
	BRA	mt_PerNop

mt_E_Commands
	movem.l	d0-d7/a0-a6,-(a7)

	LEA	mt_chan1temp(PC),A6
	cmp.b	#0,n_cmdlo(A6)
	beq	no_restart_1
	cmp.w	#32,showlen1
	bgt.s	no_restart_1
	cmp.w	#32,n_length(a6)
	blt.s	no_restart_1
	move.l	n_loopstart(a6),showsound1
	move.w	n_length(a6),showlen1
no_restart_1:
	
	LEA	mt_chan2temp(PC),A6
	cmp.b	#0,n_cmdlo(A6)
	beq	no_restart_2
	cmp.w	#32,showlen2
	bgt.s	no_restart_2
	cmp.w	#32,n_length(a6)
	blt.s	no_restart_2
	move.l	n_loopstart(a6),showsound2
	move.w	n_length(a6),showlen2
no_restart_2:
	
	LEA	mt_chan3temp(PC),A6
	cmp.b	#0,n_cmdlo(A6)
	beq	no_restart_3
	cmp.w	#32,showlen3
	bgt.s	no_restart_3
	cmp.w	#32,n_length(a6)
	blt.s	no_restart_3
	move.l	n_loopstart(a6),showsound3
	move.w	n_length(a6),showlen3
no_restart_3:
	
	LEA	mt_chan4temp(PC),A6
	cmp.b	#0,n_cmdlo(A6)
	beq	no_restart_4
	cmp.w	#32,showlen4
	bgt.s	no_restart_4
	cmp.w	#32,n_length(a6)
	blt.s	no_restart_4
	move.l	n_loopstart(a6),showsound4
	move.w	n_length(a6),showlen4
no_restart_4:

mt_no_effect:
	movem.l	(a7)+,d0-d7/a0-a6
	MOVE.B	n_cmdlo(A6),D0
	AND.B	#$F0,D0
	LSR.B	#4,D0
	BEQ.S	mt_FilterOnOff
	CMP.B	#1,D0
	BEQ	mt_FinePortaUp
	CMP.B	#2,D0
	BEQ	mt_FinePortaDown
	CMP.B	#3,D0
	BEQ.S	mt_SetGlissControl
	CMP.B	#4,D0
	BEQ	mt_SetVibratoControl
	CMP.B	#5,D0
	BEQ	mt_SetFineTune
	CMP.B	#6,D0
	BEQ	mt_JumpLoop
	CMP.B	#7,D0
	BEQ	mt_SetTremoloControl
	CMP.B	#9,D0
	BEQ	mt_RetrigNote
	CMP.B	#$A,D0
	BEQ	mt_VolumeFineUp
	CMP.B	#$B,D0
	BEQ	mt_VolumeFineDown
	CMP.B	#$C,D0
	BEQ	mt_NoteCut
	CMP.B	#$D,D0
	BEQ	mt_NoteDelay
	CMP.B	#$E,D0
	BEQ	mt_PatternDelay
	CMP.B	#$F,D0
	BEQ	mt_FunkIt
	RTS

mt_FilterOnOff
	MOVE.B	n_cmdlo(A6),D0
	AND.B	#1,D0
	ASL.B	#1,D0
	AND.B	#$FD,$BFE001
	OR.B	D0,$BFE001
	RTS	

mt_SetGlissControl
	MOVE.B	n_cmdlo(A6),D0
	AND.B	#$0F,D0
	AND.B	#$F0,n_glissfunk(A6)
	OR.B	D0,n_glissfunk(A6)
	RTS

mt_SetVibratoControl
	MOVE.B	n_cmdlo(A6),D0
	AND.B	#$0F,D0
	AND.B	#$F0,n_wavecontrol(A6)
	OR.B	D0,n_wavecontrol(A6)
	RTS

mt_SetFineTune
	MOVE.B	n_cmdlo(A6),D0
	AND.B	#$0F,D0
	MOVE.B	D0,n_finetune(A6)
	RTS

mt_JumpLoop
	TST.B	mt_counter
	BNE	mt_Return2
	MOVE.B	n_cmdlo(A6),D0
	AND.B	#$0F,D0
	BEQ.S	mt_SetLoop
	TST.B	n_loopcount(A6)
	BEQ.S	mt_jumpcnt
	SUBQ.B	#1,n_loopcount(A6)
	BEQ	mt_Return2
mt_jmploop	MOVE.B	n_pattpos(A6),mt_PBreakPos
	ST	mt_PBreakFlag
	RTS

mt_jumpcnt
	MOVE.B	D0,n_loopcount(A6)
	BRA.S	mt_jmploop

mt_SetLoop
	MOVE.W	mt_PatternPos(PC),D0
	LSR.W	#4,D0
	MOVE.B	D0,n_pattpos(A6)
	RTS

mt_SetTremoloControl
	MOVE.B	n_cmdlo(A6),D0
	AND.B	#$0F,D0
	LSL.B	#4,D0
	AND.B	#$0F,n_wavecontrol(A6)
	OR.B	D0,n_wavecontrol(A6)
	RTS

mt_RetrigNote
	MOVE.L	D1,-(SP)
	MOVEQ	#0,D0
	MOVE.B	n_cmdlo(A6),D0
	AND.B	#$0F,D0
	BEQ.S	mt_rtnend
	MOVEQ	#0,D1
	MOVE.B	mt_counter(PC),D1
	BNE.S	mt_rtnskp
	MOVE.W	(A6),D1
	AND.W	#$0FFF,D1
	BNE.S	mt_rtnend
	MOVEQ	#0,D1
	MOVE.B	mt_counter(PC),D1
mt_rtnskp
	DIVU	D0,D1
	SWAP	D1
	TST.W	D1
	BNE.S	mt_rtnend
mt_DoRetrig

	MOVE.W	n_dmabit(A6),$DFF096	; Channel DMA off

	MOVE.L	n_start(A6),(A5)	; Set sampledata pointer

	MOVE.W	n_length(A6),4(A5)	; Set length
	
	bsr	mt_WaitDMA
	
	MOVE.W	n_dmabit(A6),D0
	BSET	#15,D0
	MOVE.W	D0,$DFF096
	
	bsr	mt_WaitDMA

	MOVE.L	n_loopstart(A6),(A5)

	MOVE.L	n_replen(A6),4(A5)
mt_rtnend
	MOVE.L	(SP)+,D1
	RTS

mt_VolumeFineUp
	TST.B	mt_counter
	BNE	mt_Return2
	MOVEQ	#0,D0
	MOVE.B	n_cmdlo(A6),D0
	AND.B	#$F,D0
	BRA	mt_VolSlideUp

mt_VolumeFineDown
	TST.B	mt_counter
	BNE	mt_Return2
	MOVEQ	#0,D0
	MOVE.B	n_cmdlo(A6),D0
	AND.B	#$0F,D0
	BRA	mt_VolSlideDown2

mt_NoteCut
	MOVEQ	#0,D0
	MOVE.B	n_cmdlo(A6),D0
	AND.B	#$0F,D0
	CMP.B	mt_counter(PC),D0
	BNE	mt_Return2
	CLR.B	n_volume(A6)
	MOVE.W	#0,8(A5)
	RTS

mt_NoteDelay
	MOVEQ	#0,D0
	MOVE.B	n_cmdlo(A6),D0
	AND.B	#$0F,D0
	CMP.B	mt_Counter,D0
	BNE	mt_Return2
	MOVE.W	(A6),D0
	BEQ	mt_Return2
	MOVE.L	D1,-(SP)
	BRA	mt_DoRetrig

mt_PatternDelay
	TST.B	mt_counter
	BNE	mt_Return2
	MOVEQ	#0,D0
	MOVE.B	n_cmdlo(A6),D0
	AND.B	#$0F,D0
	TST.B	mt_PattDelTime2
	BNE	mt_Return2
	ADDQ.B	#1,D0
	MOVE.B	D0,mt_PattDelTime
	RTS

mt_FunkIt
	TST.B	mt_counter
	BNE	mt_Return2
	MOVE.B	n_cmdlo(A6),D0
	AND.B	#$0F,D0
	LSL.B	#4,D0
	AND.B	#$0F,n_glissfunk(A6)
	OR.B	D0,n_glissfunk(A6)
	TST.B	D0
	BEQ	mt_Return2
mt_UpdateFunk
	MOVEM.L	A0/D1,-(SP)
	MOVEQ	#0,D0
	MOVE.B	n_glissfunk(A6),D0
	LSR.B	#4,D0
	BEQ.S	mt_funkend
	LEA	mt_FunkTable(PC),A0
	MOVE.B	(A0,D0.W),D0
	ADD.B	D0,n_funkoffset(A6)
	BTST	#7,n_funkoffset(A6)
	BEQ.S	mt_funkend
	CLR.B	n_funkoffset(A6)

	MOVE.L	n_loopstart(A6),D0
	MOVEQ	#0,D1
	MOVE.W	n_replen(A6),D1
	ADD.L	D1,D0
	ADD.L	D1,D0
	MOVE.L	n_wavestart(A6),A0
	ADDQ.L	#1,A0
	CMP.L	D0,A0
	BLO.S	mt_funkok
	MOVE.L	n_loopstart(A6),A0
mt_funkok
	MOVE.L	A0,n_wavestart(A6)
	MOVEQ	#-1,D0
	SUB.B	(A0),D0
	MOVE.B	D0,(A0)
mt_funkend
	MOVEM.L	(SP)+,A0/D1
	RTS


mt_FunkTable dc.b 0,5,6,7,8,10,11,13,16,19,22,26,32,43,64,128

mt_VibratoTable	
	dc.b   0, 24, 49, 74, 97,120,141,161
	dc.b 180,197,212,224,235,244,250,253
	dc.b 255,253,250,244,235,224,212,197
	dc.b 180,161,141,120, 97, 74, 49, 24

mt_PeriodTable
; Tuning 0, Normal
	dc.w	856,808,762,720,678,640,604,570,538,508,480,453
	dc.w	428,404,381,360,339,320,302,285,269,254,240,226
	dc.w	214,202,190,180,170,160,151,143,135,127,120,113
; Tuning 1
	dc.w	850,802,757,715,674,637,601,567,535,505,477,450
	dc.w	425,401,379,357,337,318,300,284,268,253,239,225
	dc.w	213,201,189,179,169,159,150,142,134,126,119,113
; Tuning 2
	dc.w	844,796,752,709,670,632,597,563,532,502,474,447
	dc.w	422,398,376,355,335,316,298,282,266,251,237,224
	dc.w	211,199,188,177,167,158,149,141,133,125,118,112
; Tuning 3
	dc.w	838,791,746,704,665,628,592,559,528,498,470,444
	dc.w	419,395,373,352,332,314,296,280,264,249,235,222
	dc.w	209,198,187,176,166,157,148,140,132,125,118,111
; Tuning 4
	dc.w	832,785,741,699,660,623,588,555,524,495,467,441
	dc.w	416,392,370,350,330,312,294,278,262,247,233,220
	dc.w	208,196,185,175,165,156,147,139,131,124,117,110
; Tuning 5
	dc.w	826,779,736,694,655,619,584,551,520,491,463,437
	dc.w	413,390,368,347,328,309,292,276,260,245,232,219
	dc.w	206,195,184,174,164,155,146,138,130,123,116,109
; Tuning 6
	dc.w	820,774,730,689,651,614,580,547,516,487,460,434
	dc.w	410,387,365,345,325,307,290,274,258,244,230,217
	dc.w	205,193,183,172,163,154,145,137,129,122,115,109
; Tuning 7
	dc.w	814,768,725,684,646,610,575,543,513,484,457,431
	dc.w	407,384,363,342,323,305,288,272,256,242,228,216
	dc.w	204,192,181,171,161,152,144,136,128,121,114,108
; Tuning -8
	dc.w	907,856,808,762,720,678,640,604,570,538,508,480
	dc.w	453,428,404,381,360,339,320,302,285,269,254,240
	dc.w	226,214,202,190,180,170,160,151,143,135,127,120
; Tuning -7
	dc.w	900,850,802,757,715,675,636,601,567,535,505,477
	dc.w	450,425,401,379,357,337,318,300,284,268,253,238
	dc.w	225,212,200,189,179,169,159,150,142,134,126,119
; Tuning -6
	dc.w	894,844,796,752,709,670,632,597,563,532,502,474
	dc.w	447,422,398,376,355,335,316,298,282,266,251,237
	dc.w	223,211,199,188,177,167,158,149,141,133,125,118
; Tuning -5
	dc.w	887,838,791,746,704,665,628,592,559,528,498,470
	dc.w	444,419,395,373,352,332,314,296,280,264,249,235
	dc.w	222,209,198,187,176,166,157,148,140,132,125,118
; Tuning -4
	dc.w	881,832,785,741,699,660,623,588,555,524,494,467
	dc.w	441,416,392,370,350,330,312,294,278,262,247,233
	dc.w	220,208,196,185,175,165,156,147,139,131,123,117
; Tuning -3
	dc.w	875,826,779,736,694,655,619,584,551,520,491,463
	dc.w	437,413,390,368,347,328,309,292,276,260,245,232
	dc.w	219,206,195,184,174,164,155,146,138,130,123,116
; Tuning -2
	dc.w	868,820,774,730,689,651,614,580,547,516,487,460
	dc.w	434,410,387,365,345,325,307,290,274,258,244,230
	dc.w	217,205,193,183,172,163,154,145,137,129,122,115
; Tuning -1
	dc.w	862,814,768,725,684,646,610,575,543,513,484,457
	dc.w	431,407,384,363,342,323,305,288,272,256,242,228
	dc.w	216,203,192,181,171,161,152,144,136,128,121,114

mt_chan1temp	dc.l	0,0,0,0,0,$00010000,0,  0,0,0,0
mt_chan2temp	dc.l	0,0,0,0,0,$00020000,0,  0,0,0,0
mt_chan3temp	dc.l	0,0,0,0,0,$00040000,0,  0,0,0,0
mt_chan4temp	dc.l	0,0,0,0,0,$00080000,0,  0,0,0,0

mt_SampleStarts	dc.l	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
		dc.l	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

mt_SongDataPtr	dc.l 0

mt_speed	dc.b 6
mt_counter	dc.b 0
mt_SongPos	dc.b 0
mt_PBreakPos	dc.b 0
mt_PosJumpFlag	dc.b 0
mt_PBreakFlag	dc.b 0
mt_LowMask	dc.b 0
mt_PattDelTime	dc.b 0
mt_PattDelTime2	dc.b 0,0

mt_PatternPos	dc.w 0
mt_DMACONtemp	dc.w 0

;/* End of File */

		
	
	Section	copdat,Data_C

my_copper:	
		dc.w	$100,$0200	; 2 bp - lo res
		dc.w	$104,$a		; bp control reg
		dc.w	$108,0		; bp modulo - odd
		dc.w	$10a,0		; bp modulo - even
		dc.w	$102,$cc
		dc.w	$1fc,0
		
		dc.w	$08e,$2c7c	; bp window start left
		dc.w	$090,$2cbc	; bp window bot right
		dc.w	$94,$ca		; bp stop horz
		dc.w	$92,$32

		dc.w	$120,0,$122,0
		dc.w	$124,0,$126,0
		dc.w	$128,0,$12a,0
		dc.w	$12c,0,$12e,0
		dc.w	$130,0,$132,0
		dc.w	$134,0,$136,0
		dc.w	$138,0,$13a,0
		dc.w	$13c,0,$13e,0
		
cmap:		dc.w	$180,$000
		dc.w	$182,$000
		dc.w	$184,$000
		dc.w	$186,$000
		dc.w	$188,$000
		dc.w	$18a,$000
		dc.w	$18c,$000
		dc.w	$18e,$000
		dc.w	$190,$000
		dc.w	$192,$000
		dc.w	$194,$000
		dc.w	$196,$000
		dc.w	$198,$000
		dc.w	$19a,$000
		dc.w	$19c,$000
		dc.w	$19e,$000
		dc.w	$1a0,$000
		dc.w	$1a2,$000
		dc.w	$1a4,$000
		dc.w	$1a6,$000
		dc.w	$1a8,$000
		dc.w	$1aa,$000
		dc.w	$1ac,$000
		dc.w	$1ae,$000
		dc.w	$1b0,$000
		dc.w	$1b2,$000
		dc.w	$1b4,$000
		dc.w	$1b6,$000
		dc.w	$1b8,$000
		dc.w	$1ba,$000
		dc.w	$1bc,$000
		dc.w	$1be,$000

		dc.w	  $e0
bitplane0_hi:	dc.w	0,$e2
bitplane0_lo:	dc.w	0,$e4
bitplane1_hi:	dc.w	0,$e6
bitplane1_lo:	dc.w	0,$e8
bitplane2_hi:	dc.w	0,$ea
bitplane2_lo:	dc.w	0,$ec
bitplane3_hi:	dc.w	0,$ee
bitplane3_lo:	dc.w	0,$f0
bitplane4_hi:	dc.w	0,$f2
bitplane4_lo:	dc.w	0

		dc.w	$100,$5200	; 5 bp - lo res
		
		dc.w	$ffe1,$fffe	; end of ntsc screen
		dc.w	$3001,$ff00	; end of pal screen
		dc.w	$9c,$8010	; irq set bits
		dc.w	$ffff,$fffe	; end of copper list


wet_copper:		dc.w	$100,$0200	; 0 bp - lo res
		dc.w	$104,$a		; bp control reg
		dc.w	$108,0		; bp modulo - odd
		dc.w	$10a,0		; bp modulo - even
		dc.w	$102,$00
		
		dc.w	$08e,$2c71	; bp window start left
		dc.w	$090,$40c1	; bp window bot right

		dc.w	$94,$8c		; bp stop horz
		dc.w	$92,$6c

		dc.w	$120,0,$122,0
		dc.w	$124,0,$126,0
		dc.w	$128,0,$12a,0
		dc.w	$12c,0,$12e,0
		dc.w	$130,0,$132,0
		dc.w	$134,0,$136,0
		dc.w	$138,0,$13a,0
		dc.w	$13c,0,$13e,0

anim_cols:	dc.w	$0180,$0000,$0182,$0210,$0184,$0310,$0186,$0420
		dc.w	$0188,$0531,$018a,$0631,$018c,$0741,$018e,$0852
		dc.w	$0190,$0862,$0192,$0963,$0194,$0a74,$0196,$0b84
		dc.w	$0198,$0c95,$019a,$0da6,$019c,$0eb7,$019e,$0fc8
		
		dc.w	  $e0
bplane0_hi:	dc.w	0,$e2
bplane0_lo:	dc.w	0,$e4
bplane1_hi:	dc.w	0,$e6
bplane1_lo:	dc.w	0,$e8
bplane2_hi:	dc.w	0,$ea
bplane2_lo:	dc.w	0,$ec
bplane3_hi:	dc.w	0,$ee
bplane3_lo:	dc.w	0
		
a set $30
		dc.b	a,1
		dc.w	$ff00

		dc.w	$102,0		
		dc.w	$100,$4200	; 5 bp - lo res

a set a+121
		dc.b	a,1
		dc.w	$ff00

		dc.w	$100,$0200
		
		dc.w	$94,$ca		; bp stop horz
		dc.w	$92,$32	

		dc.w	$102,$88

loadcmap:	dc.w	$180,$000
		dc.w	$182,$000
		dc.w	$184,$000
		dc.w	$186,$000
		dc.w	$188,$000
		dc.w	$18a,$000
		dc.w	$18c,$000
		dc.w	$18e,$000
		dc.w	$190,$000
		dc.w	$192,$000
		dc.w	$194,$000
		dc.w	$196,$000
		dc.w	$198,$000
		dc.w	$19a,$000
		dc.w	$19c,$000
		dc.w	$19e,$000

		dc.w	  $e0
bp0_hi:		dc.w	0,$e2
bp0_lo:		dc.w	0,$e4
bp1_hi:		dc.w	0,$e6
bp1_lo:		dc.w	0,$e8
bp2_hi:		dc.w	0,$ea
bp2_lo:		dc.w	0,$ec
bp3_hi:		dc.w	0,$ee
bp3_lo:		dc.w	0
		
load_wait:	dc.w	$b001,$ff00
		dc.w	$100,$4200	; 3 bp - lo res		
		
		dc.w	$ffe1,$fffe	; end of ntsc screen
		dc.w	$1301,$ff00

		dc.w	$180,$000
		dc.w	$182,$001
		dc.w	$184,$002
		dc.w	$186,$003
		dc.w	$188,$004
		dc.w	$18a,$005
		dc.w	$18c,$006
		dc.w	$18e,$007
		dc.w	$190,$008
		dc.w	$192,$009
		dc.w	$194,$00a
		dc.w	$196,$00b
		dc.w	$198,$00c
		dc.w	$19a,$00d
		dc.w	$19c,$00e
		dc.w	$19e,$00f
		
		dc.w	$108,-80
		dc.w	$10a,-80

		dc.w	$9c,$8010	; irq set bits
		dc.w	$ffff,$fffe	; end of copper list

		;----

null_copper:	;dc.w	$100,$0200
		;dc.w	$FFE1,$FFFE
		;dc.w	$9C,$8010
		;dc.w	$3001,$FF00
		;dc.w	$FFFF,$FFFE

		dc.w	$100,$200
		dc.w	$104,10
		dc.w	$108,0
		dc.w	$10A,0
		dc.w	$180,0
		dc.w	$102,$55
		dc.w	$8E,$2C81
		dc.w	$90,$29C1
		dc.w	$94,$9C
		dc.w	$92,$60
		dc.w	$120,0
		dc.w	$122,0
		dc.w	$124,0
		dc.w	$126,0
		dc.w	$128,0
		dc.w	$12A,0
		dc.w	$12C,0
		dc.w	$12E,0
		dc.w	$130,0
		dc.w	$132,0
		dc.w	$134,0
		dc.w	$136,0
		dc.w	$138,0
		dc.w	$13A,0
		dc.w	$13C,0
		dc.w	$13E,0
		dc.w	$E0,$0007
		dc.w	$E2,$DE74
		dc.w	$E4,$0007
		dc.w	$E6,$E22E
		dc.w	$E8,$0007
		dc.w	$EA,$E5E8
		dc.w	$EC,$0007
		dc.w	$EE,$E9A2
		dc.w	$180,$000
		dc.w	$182,$420
		dc.w	$184,$640
		dc.w	$186,$860
		dc.w	$188,$A80
		dc.w	$18A,$CA0
		dc.w	$18C,$EE0
		dc.w	$18E,$FF0
		dc.w	$190,$200
		dc.w	$192,$300
		dc.w	$194,$F00
		dc.w	$196,$D00
		dc.w	$198,$B00
		dc.w	$19A,$900
		dc.w	$19C,$700
		dc.w	$19E,$FFF
		dc.w	$3001,$FF00
		dc.w	$100,$4200
		dc.w	$6501,$FF00
		dc.w	$100,$200
		dc.w	$94,$A0
		dc.w	$92,$59
		dc.w	$102,$EE
		dc.w	$6A01,$FF00
		dc.w	$100,$5200
		dc.w	$E0,$0007
		dc.w	$E2,$93B8
		dc.w	$E4,$0007
		dc.w	$E6,$A2A4
		dc.w	$E8,$0007
		dc.w	$EA,$B190
		dc.w	$EC,$0007
		dc.w	$EE,$C07C
		dc.w	$F0,$0007
		dc.w	$F2,$CF68
		dc.w	$180,$000
		dc.w	$182,$FFF
		dc.w	$184,$FFC
		dc.w	$186,$FEB
		dc.w	$188,$FDA
		dc.w	$18A,$EC9
		dc.w	$18C,$DB8
		dc.w	$18E,$CA7
		dc.w	$190,$B96
		dc.w	$192,$A85
		dc.w	$194,$974
		dc.w	$196,$863
		dc.w	$198,$752
		dc.w	$19A,$641
		dc.w	$19C,$530
		dc.w	$19E,$420
		dc.w	$1A0,$310
		dc.w	$1A2,$200
		dc.w	$1A4,$945
		dc.w	$1A6,$21
		dc.w	$1A8,$132
		dc.w	$1AA,$243
		dc.w	$1AC,$354
		dc.w	$1AE,$465
		dc.w	$1B0,$576
		dc.w	$1B2,$687
		dc.w	$1B4,$798
		dc.w	$1B6,$8A9
		dc.w	$1B8,$9BA
		dc.w	$1BA,$ACB
		dc.w	$1BC,$BDC
		dc.w	$1BE,$CED
		dc.w	$FFE1,$FFFE
		dc.w	$3001,$FF00
		dc.w	$9C,$8010
		dc.w	$FFFF,$FFFE
	
file_copper:	dc.w	$100,$0200	; 4 bp - lo res
		dc.w	$104,$a		; bp control reg
		dc.w	$108,0		; bp modulo - odd
		dc.w	$10a,0		; bp modulo - even
		dc.w	$102,0
		
		dc.w	$08e,$2981	; bp window start left
		dc.w	$090,$40c1	; bp window bot right
		dc.w	$94,$d0		; bp stop horz
		dc.w	$92,$38

		dc.w	$120,0,$122,0
		dc.w	$124,0,$126,0
		dc.w	$128,0,$12a,0
		dc.w	$12c,0,$12e,0
		dc.w	$130,0,$132,0
		dc.w	$134,0,$136,0
		dc.w	$138,0,$13a,0
		dc.w	$13c,0,$13e,0
		
		dc.w	  $e0
fplane0_hi:	dc.w	0,$e2
fplane0_lo:	dc.w	0,$e4
fplane1_hi:	dc.w	0,$e6
fplane1_lo:	dc.w	0,$e8
fplane2_hi:	dc.w	0,$ea
fplane2_lo:	dc.w	0,$ec
fplane3_hi:	dc.w	0,$ee
fplane3_lo:	dc.w	0,$f0
fplane4_hi:	dc.w	0,$f2
fplane4_lo:	dc.w	0

filecmap:		dc.w	$180,$000
		dc.w	$182,$000
		dc.w	$184,$000
		dc.w	$186,$000
		dc.w	$188,$000
		dc.w	$18a,$000
		dc.w	$18c,$000
		dc.w	$18e,$000
		dc.w	$190,$000
		dc.w	$192,$000
		dc.w	$194,$000
		dc.w	$196,$000
		dc.w	$198,$000
		dc.w	$19a,$000
		dc.w	$19c,$000
		dc.w	$19e,$000
		dc.w	$1a0,$000
		dc.w	$1a2,$000
		dc.w	$1a4,$000
		dc.w	$1a6,$000
		dc.w	$1a8,$000
		dc.w	$1aa,$000
		dc.w	$1ac,$000
		dc.w	$1ae,$000
		dc.w	$1b0,$000
		dc.w	$1b2,$000
		dc.w	$1b4,$000
		dc.w	$1b6,$000
		dc.w	$1b8,$000
		dc.w	$1ba,$000
		dc.w	$1bc,$000
		dc.w	$1be,$000

		dc.w	$100,$5200	; 5 bp - lo res
menu_wait2:		dc.w	$8201,$ff00
		dc.w	$100,$0200

		dc.w	  $e0
mplane0_hi:		dc.w	0,$e2
mplane0_lo:		dc.w	0,$e4
mplane1_hi:		dc.w	0,$e6
mplane1_lo:		dc.w	0,$e8
mplane2_hi:		dc.w	0,$ea
mplane2_lo:		dc.w	0,$ec
mplane3_hi:		dc.w	0,$ee
mplane3_lo:		dc.w	0

menucmap:		dc.w	$180,$000
		dc.w	$182,$000
		dc.w	$184,$000
		dc.w	$186,$000
		dc.w	$188,$000
		dc.w	$18a,$000
		dc.w	$18c,$000
		dc.w	$18e,$000
		dc.w	$190,$000
		dc.w	$192,$000
		dc.w	$194,$000
		dc.w	$196,$000
		dc.w	$198,$000
		dc.w	$19a,$000
		dc.w	$19c,$000
		dc.w	$19e,$000

menu_wait:		dc.w	$8201,$ff00
		dc.w	$100,$4200	; 4 bp - lo res

		dc.w	$ffe1,$fffe	; end of ntsc screen

		dc.w	$0401,$fffe
		dc.w	$180,$000
		dc.w	$182,$001
		dc.w	$184,$002
		dc.w	$186,$003
		dc.w	$188,$004
		dc.w	$18a,$005
		dc.w	$18c,$006
		dc.w	$18e,$007
		dc.w	$190,$008
		dc.w	$192,$009
		dc.w	$194,$00a
		dc.w	$196,$00b
		dc.w	$198,$00c
		dc.w	$19a,$00d
		dc.w	$19c,$00e
		dc.w	$19e,$00f
		
		dc.w	$108,-80
		dc.w	$10a,-80

		dc.w	$3001,$ff00	; end of pal screen
		dc.w	$9c,$8010	; irq set bits - ?
		dc.w	$ffff,$fffe	; end of copper list

display:		incbin	"dh0:data/tripple/main.bin"
		dcb.b	40*100
loading:		incbin	"dh0:data/tripple/loading.bin"
decrunch:		incbin	"dh0:data/tripple/decrunch.bin"
pointer:		incbin	"dh0:data/tripple/pointer.bin"
font:		incbin	"dh0:data/tripple/font.bin"

	section	ddp,data_f
	
old_copper:	dc.l	0
graphics:	dc.l	0

showsound1:	dc.l	0
showsound2:	dc.l	0
showsound3:	dc.l	0
showsound4:	dc.l	0
showlen1:	dc.l	0
showlen2:	dc.l	0
showlen3:	dc.l	0
showlen4:	dc.l	0

times40:	
a set 0
	rept	256
	dc.w	a*40
a set a+1
	endr
	
	
invertx:		incbin	"dh0:data/tripple/volumex"
inverty:		incbin	"dh0:data/tripple/volumey"
		

shift:		dc.l	0

scroll_pos:		dc.l	15
screen1a:		dc.l	0

ss:		dc.l	0
sl:		dc.l	0
	
OldV3:		dc.l	0
GfxBse:		dc.l	0
OldInt:		dc.w	0
OldDma:		dc.w	0

GfxLib:		dc.b	"graphics.library",0
		even

buffer:		dc.l	0
	
data_at:		dc.l	0
data_len:		dc.l	0
playing:		dc.l	0
pos:		dc.l	0
scroll_ptr:		dc.l	scroll_text
	
ypos:		dc.l	0
oldy:		dc.l	0
yp:		dc.l	0
yp2:		dc.l	ymax

DotCount:		dc.l	maxdots
FrameCount:		dc.l	0

filesptr:		dc.l	files+(0*12)

oldfile:		dc.l	0
null:		dcb.b	maxdots,127

mt_volume_exit:	dc.l	0

anim_pal1:		dc.w	$000,$210,$310,$420,$531,$631,$741,$852
		dc.w	$862,$963,$a74,$b84,$c95,$da6,$eb7,$fc8
anim_pal2:		dc.w	$000,$110,$220,$330,$441,$551,$661,$773
		dc.w	$884,$995,$aa6,$bb8,$cc9,$ddb,$eed,$fff
anim_pal3:		dc.w	$000,$011,$022,$033,$144,$155,$266,$377
		dc.w	$488,$599,$6aa,$8bb,$9cc,$bdd,$dee,$fff
anim_pal4:		dc.w	$000,$101,$202,$303,$414,$515,$626,$737
		dc.w	$848,$959,$a6a,$b8b,$c9c,$dbd,$ede,$fff
anim_pal5:		dc.w	$000,$010,$020,$130,$240,$251,$461,$572
		dc.w	$682,$893,$9a3,$ab5,$bc7,$dd9,$eec,$fff

anim_pal_ptr:	dc.l	anim_pal_list

anim_pal_list:
		dc.l	anim_pal1
		dc.l	anim_pal2
		dc.l	anim_pal3
		dc.l	anim_pal4
		dc.l	anim_pal5
		dc.l	0
	

files:	dc.l	$37E00,123440,$70CDE6
	dc.l	$1FA00,098920,$43D8B1
	dc.l	$00400,128068,$79AB44
	dc.l	$56200,119340,$68354D
	dc.l	$73600,022572,$2C6A86
	dc.l	$79000,147896,$26F8F9
	dc.l	$9D200,119336,$696D1F
	
	dc.l	$200,0,0
	dc.l	$400,0,0
	dc.l	$BA600,0,0		; stop!
	

water_delay:	dc.l	0
water_dir:		dc.l	0
water_ptr:		dc.l	water_table
water_start:	dc.l	0

		dc.l	0
water_table:	
a set 0

		rept 21
		dc.l	a*4880
a set a+1
		endr
water_end:		dc.l	0
		
loc:		dc.l	0

drive:		dc.w	0
temp:		dc.l	0
label:		dc.l	0
looklabel:		dc.l	0
loadaddress:	dc.l	0
diskaddress:	dc.l	0
loadlength:		dc.l	0
retries:		dc.l	0
current_track:	dc.l	0
		
	section	music,data_c

filescreen:		incbin	"dh0:data/tripple/logo.bin"
menuscreen:		incbin	"dh0:data/tripple/menu.bin"

water_pic1:		ds.b	10*122*4

***************************************************************************

scroll_text:	dc.b	"        "
		dc.b	"WELCOME TO THE TRIPPLE BREASTED WHORE OF EROTICON SIX.    "
		dc.b	"CODING BY SHAGRATT, EQUALIZER SCREEN AND VERTICAL FONT BY MOZ, "
		dc.b	"MENU LOGO AND INTRO SCREEN BY WATCHMAN, LOADING/DECRUNCHING LOGOS, LOADING ANIM BY SPIRIT, "
		dc.b	"ORIGINAL CONCEPT FOR THESE EQUALISERS BY MONTY PYTHON, ADDITIONAL IDEAS BY SPIRIT.   "
		dc.b	"MUSIC BY ECHO/DIGGER/SPIRIT.     "
		
		
		dc.b	"SPECIAL THANKS GO TO MOZ: WHO DREW THE GRAPHICS FOR THIS WITH A SLIPPED DISK, MANY THANKS MATE.    "
		dc.b	"GREETS GO TO: FLAKE OF THE SPECIAL BROTHERS, IS YOUR MUSIC DISK FINISHED YET?       "  
		dc.b	"SHADOWSTORM: GAMESPLAYER!      "
		dc.b	0
		even

***************************************************************************


mt_data:
volumespace:	
water1:		incbin	"dh0:data/tripple/water.anim"
		even
		
workspace:	;ds.b	30*1000		; dma buffer for td loader
	;ds.b	120*1000		; and mt_data!

	end


