
	Section titlemenu,code
	opt	c-,o+,w-

	; i assume you have use one these before, if you have any
	; problems ring me (shagratt).
	
	; in this menu you can change all text, music, bobs, font, logo

	; if you want to change the bobs, this is the format for it!
	;
	;	bobs - ball: 16x15 (8 colours) - cmap before
	;	       mask: 16x15 (8 colours) - no cmap
	;
	; cut out with kefrens iff conv


forecol		equ	$180		; back ground colour
textcol		equ	$190		; text colour
linecol		equ	$008		; text colour
topcur		equ	$5c01		; start of selector line
tall		equ	10		; height of text


xstep1		equ	2		; after every snake
ystep1		equ	2		; after every snake

xstep2		equ	3		; after every bob
ystep2		equ	1		; after every bob

loop		= 0			; 0=exit, 1=no exit

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

	; to make the menu return after each programme set loop to
	; 1 (above) on final assemblly
		
	************************************************************
	
begin1:	bsr	vcheck

	clr.l	d0
	clr.l	d1
	clr.l	d2
	clr.l	d3
	clr.l	d4
	clr.l	d5
	clr.l	d6
	clr.l	d7

	move.l	4.w,a6
	jsr	-132(a6)	; forbid

	move.l	#0,quit
	move.l	#scrolltext,scrollptr

	lea	$dff120,a0	; kill sprites
	moveq.w	#15,d0
sprloop:	move.w	#-1,(a0)+
	dbf	d0,sprloop

	move.l	4.w,a6
	move.l	#scrsize*4,d0
	move.l	#$10002,d1
	jsr	-198(a6)
	beq	reset
	move.l	d0,screen

	move.l	4.w,a6
	move.l	#40*256,d0
	move.l	#$10002,d1
	jsr	-198(a6)
	beq	reset
	move.l	d0,scr

	lea	ball,a0
	lea	cmap,a1
	add.l	#2,a1
	move.w	#7,d0
cmaploop:
	move.w	(a0)+,(a1)
	add.l	#4,a1
	dbf	d0,cmaploop

	move.l	screen,a0
	move.l	a0,screen1
	add.l	#scrsize,a0
	move.l	a0,screen2
	
	move.w	#(maxx*32)-1,d0
	lea	coords1,a0
	lea	coordsend1,a2
block_move:
	move.l	(a0)+,(a2)+	
	dbf	d0,block_move

	clr.l	d0
	move.b	$dff00a,d0
	move.l	d0,oldy

	lea	glib,a1
	moveq	#0,d0
	move.l	4.w,a6
	jsr	-$228(a6)
	tst	d0
	beq	error
	move.l	d0,graphics

	lea	logocmap+2,a0
	lea	logo,a1
	move.w	#15,d0
cmap2loop:
	move.w	(a1)+,(a0)
	add.l	#4,a0
	dbf	d0,cmap2loop	

	move.l	#logo+32,d0
	move.w	d0,bplane0_lo
	swap	d0
	move.w	d0,bplane0_hi
	swap	d0
	add.l	#40*50,d0	
	move.w	d0,bplane1_lo
	swap	d0
	move.w	d0,bplane1_hi
	swap	d0
	add.l	#40*50,d0	
	move.w	d0,bplane2_lo
	swap	d0
	move.w	d0,bplane2_hi
	swap	d0
	add.l	#40*50,d0	
	move.w	d0,bplane3_lo
	swap	d0
	move.w	d0,bplane3_hi

	move.l	#info,page
	bsr	setup_screen
	move.l	#page1,page
	bsr	setup_screen

	move.l	#-1,step
	
	move.l	graphics,a6
	add.l	#$32,a6
	move.w	#$80,$dff096		; dma control write
	move.l	(a6),old_copper		; store the address of the
	lea	my_copper,a0
	move.l	a0,(a6)			; old copperlist
	move.w	#$8080,$dff096		; dma control write
	move.w	#$8010,$dff09a		; interupt enable bits
	move.l	$6c.w,old_interupt	; store old level 3 int
	lea	new_interupt,a0
	move.l	a0,$6c.w		; store my routine

	bsr	help

	bsr	mt_init
	bsr	waitmouse
	bsr	mt_end
	
	move.l	old_interupt,$6c.w	; resore old level 3 int
	move.l	#$10,$dff09a 		; Disable Level 3 Interupt
	move.l	graphics,a6
	add.l	#$32,a6
	move.w	#$0080,$dff096
	move.l	old_copper,(a6)		; restore old copper list
	move.w	#$8080,$dff096
	
	move.l	4.w,a6
	move.l	screen,a1
	move.l	#scrsize*4,d0
	jsr	-210(a6)

	move.l	4.w,a6
	move.l	scr,a1
	move.l	#40*256,d0
	jsr	-210(a6)

	move.l	4.w,a6
	jsr	-138(a6)		; permit

	bsr	loadfile

	move.l	filename,a0
	cmp.l	#"run ",(a0)
	beq	error
	cmp.l	#"RUN ",(a0)
	beq	error

	IFNE	loop
	bra	begin1
	ENDC

Error:	move.w	#0,$bfec00		; empty buffer
	moveq	#0,d0			; fin
	rts


loadfile:
	bsr	checksum
	move.l	d5,$f0
	
	move.l	#256,d0
	sub.l	ypos,d0
	
	divu	#tall,d0
	and.l	#$ffff,d0
	
	mulu	#4,d0
	lea	flist,a0
	add.l	d0,a0
	
	move.l	(a0),filename

	lea	doslib,a1
	moveq	#0,d0
	move.l	4.w,a6
	jsr	-$228(a6)
	tst	d0
	beq	err
	move.l	d0,dosbase
	
	move.l	d0,a6
	clr.l	d0
	move.l	filename,d1
	move.l	#0,d2
	move.l	#0,d3	
	jsr	-222(a6)

	move.l	graphics,a6
	add.l	#$32,a6
	move.l	old_copper,(a6)		; restore old copper list

EndCode:

	Clr.l	d0
	Rts

Err:	move.w	#$fffe,d0
errloop:
	Move.w	$dff006,$dff180
	dbf	d0,errloop

	move.l	graphics,a6
	add.l	#$32,a6
	move.l	old_copper,(a6)		; restore old copper list

	Bra	EndCode



waitmouse:
	cmp.l	#0,quit
	beq	waitmouse

	move.l	#256,d0
	sub.l	ypos,d0
	
	divu	#tall,d0
	and.l	#$ffff,d0
	
	mulu	#4,d0
	lea	flist,a0
	add.l	d0,a0
	
	move.l	(a0),a0
	cmp.b	#0,(a0)
	bne	error			; do a rts
	
	move.l	#0,quit
	bra	waitmouse

vcheck:
	rts
	move.l	4.w,a6
	tst.l	$2a(a6)		; check execbase,
	bne.s	virus
	tst.l	$2e(a6)		; ptrs and
	bne.s	virus
	tst.l	$22a(a6)		; coolcapture
	bne.s	virus
	rts
	
virus:	lea	$dff000,a3
	move.l	#$40000,d0
	move.w	#$7fff,$96(a3)
	
vloop:	
	move.w	$06(a3),d1
	and.w	#$f00,d1
	move.w	d1,$180(a3)
	subq.l	#1,d0
	bne.s	vloop

reset:	move.l	4.w,a6
	clr.l	$026(a6)		; hard reset
	lea	$fc00d0,a5
	jmp	-$1e(a6)

setcopper:
	move.l	a0,d0
	move.w	d0,bp0_lo
	swap	d0
	move.w	d0,bp0_hi

	move.l	graphics,a6
	add.l	#$32,a6
	lea	copper2,a0
	move.l	a0,(a6)			; old copperlist

	rts


checksum:
	lea	begin1(pc),a0
	lea	begin2(pc),a1
	move.l	a1,d2
	sub.l	a0,d2
	
	clr.l	d5
	clr.l	d0
checkloop:
	move.b	(a0),d0
	add.l	d0,d5
	
	sub.l	#1,d2
	bpl.s	checkloop
	
	rts

readjoy:
	move.w	$dff00c,d0
	and.w	#$100,d0
	bne	joyup
	move.w	$dff00c,d0
	and.w	#$001,d0
	bne	joydown
	
	btst	#7,$bfe001
	beq	keyquit
	
	rts
	
joyup:	add.l	#1,ypos
	move.l	#+1,step	
	rts	

joydown:sub.l	#1,ypos
	move.l	#-1,step	
	rts	
 	
changesnake:	
	move.b	$bfec01,d0
	cmp.b	#161,d0
 	beq	xsplus
	cmp.b	#165,d0
 	beq	xsmin
	cmp.b	#131,d0
 	beq	ysplus
	cmp.b	#195,d0
 	beq	ysmin
	cmp.b	#115,d0
 	beq	help
	cmp.b	#065,d0
 	beq	del
 	
snakeerror:
 	rts

help:	
	move.l	#xs1,modpointerx
	move.l	#ys1,modpointery
	rts
del:	
	move.l	#xs2,modpointerx
	move.l	#ys2,modpointery
	rts
 	
xsplus:
	move.l	modpointerx,a0
	move.l	(a0),d0
	add.l	#2,d0
	cmp.l	#20,d0
	bgt.s	snakeerror	
	move.l	d0,(a0)
	rts
xsmin:
	move.l	modpointerx,a0
	move.l	(a0),d0
	sub.l	#2,d0
	bmi	snakeerror
	move.l	d0,(a0)
	rts
ysplus:
	move.l	modpointery,a0
	move.l	(a0),d0
	add.l	#2,d0
	cmp.l	#20,d0
	bgt.s	snakeerror	
	move.l	d0,(a0)
	rts
ysmin:
	move.l	modpointery,a0
	move.l	(a0),d0
	sub.l	#2,d0
	bmi	snakeerror
	move.l	d0,(a0)
	rts
 		
readkeyboard:
	move.b	$bfec01,d0
	cmp.b	#103,d0
	beq	keyup
	cmp.b	#101,d0
	beq	keydown
	cmp.b	#119,d0
	beq	keyquit
	rts
	
keyup:	add.l	#10,ypos
	move.l	#+10,step	
	rts
	
keydown:sub.l	#10,ypos
	move.l	#-10,step	
	rts
	
keyquit:move.l	#-1,quit
	rts
 		
readmouse:
	btst	#6,$bfe001
	bne.s	nomouse
	
	move.l	#-1,quit
	rts
	
nomouse:
	bsr	changesnake
	bsr	readkeyboard
	bsr	readjoy

	clr.b	$bfec01			; clear keyboard buffer

	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:

	cmp.l	#0,step
	bne.s	no_change_step

	cmp.l	#0,yp
	bpl.s	yp_neg
	
	move.l	#-10,step
	bra	no_change_step
	
yp_neg:	move.l	#+10,step

no_change_step:
	move.l	yp,d0
	add.l	d0,ypos
mouse_move_again:
	move.l	ypos,d6
	move.l	lines,d7
	
	cmp.l	d7,d6
	bgt.s	ypos_ok1
	move.l	d7,ypos
	move.l	#0,d5
	move.l	step,d6
	sub.l	d6,d5
	move.l	d5,step
	
ypos_ok1:
	cmp.l	#255,ypos
	blt.s	ypos_ok2
	move.l	#255,ypos

	move.l	#0,d5
	move.l	step,d6
	sub.l	d6,d5
	move.l	d5,step
	
ypos_ok2:
	move.l	maxlines,d1

	move.l	#256,d0
	sub.l	ypos,d0
	
	divu	#tall,d0
	mulu	#tall,d0

	asl.l	#8,d0
	add.l	#topcur,d0
	
	
	move.l	#256,d7
	sub.l	ypos,d7
	
	divu	#tall,d7
	and.l	#$ffff,d7
	
	mulu	#4,d7
	lea	flist,a0
	add.l	d7,a0
	
	move.l	(a0),a0
	cmp.b	#0,(a0)
	bne	mouse_move_valid

	move.l	step,d7
	move.l	ypos,d6
	add.l	d7,d6
	move.l	d6,ypos

	bra	mouse_move_again
	
mouse_move_valid:
	move.w	d0,cursor1
	add.l	#$0100,d0
	move.w	d0,cursor2
	add.l	#$0100,d0
	move.w	d0,cursor3
	add.l	#$0100,d0
	move.w	d0,cursor4
	add.l	#$0100,d0
	move.w	d0,cursor5
	add.l	#$0100,d0
	move.w	d0,cursor6
	add.l	#$0100,d0
	move.w	d0,cursor7
	add.l	#$0100,d0
	move.w	d0,cursor8
	add.l	#$0100,d0
	move.w	d0,cursor9
	add.l	#$0100,d0
	move.w	d0,cursor10
	add.l	#$0100,d0
	move.w	d0,cursor11
	add.l	#$0100,d0
	move.w	d0,cursor12
	add.l	#$0100,d0
	
	move.l	#0,step
	
	rts	
	
new_interupt:
	movem.l	d0-d7/a0-a6,-(sp)	; my scroll text
	
	and.w	#$10,$dff01e		; check for copper interupt
	beq 	no_music
	move.w	#$10,$dff09c

	bsr	gen_balls
	bsr	scroller

	cmp.l	#$12345678,mt_data
	beq	no_music
	bsr	mt_music
no_music:
	bsr	readmouse	
	
	movem.l	(sp)+,d0-d7/a0-a6	
	dc.w	$4ef9			; jmp
old_interupt:	dc.l	0		; the old int lev 3


scroller:
	move.w	scrollpos2,d0
	sub.w	#2,d0
	bmi	scrolled
	move.w	d0,scrollpos2
	mulu	#16,d0
	move.w	d0,scrollpos
	rts
scrolled:
	
	bsr	do_blit
	
	move.w	#0,d5
	mulu	#8192,d5
	or.w	#(%1001*256)+$f0,d5
	
	move.l	scr,a2
	add.l	#190*40,a2
	add.l	#24,a2
	move.l	a2,a3
	add.l	#2,a2
	
	Move.l	a3,$dff054		; dest mem d
	Move.l	a2,$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	d5,$dff040
	move.w	#0,$dff042		; blit cont reg 1
	Move.w	#0,$dff066		; modulo for dest
	Move.w	#(10*64)+22,$dff058	; blit height,width

	
	move.w	#4,d5
	mulu	#8192,d5
	or.w	#(%1001*256)+$f0,d5

	add.l	#48,a3
	lea	font,a2
	bsr	getscrbyte

	bsr	do_blit

	Move.l	a3,$dff054		; dest mem d
	Move.l	a2,$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	d5,$dff040
	move.w	#0,$dff042		; blit cont reg 1
	Move.w	#42,$dff066		; modulo for dest
	Move.w	#(9*64)+1,$dff058	; blit height,width
	
	move.w	#0,d5
	mulu	#8192,d5
	or.w	#(%1011*256)+$fa,d5

	add.l	#44,a3

	lea	font,a2
	bsr	getscrbyte

	bsr	do_blit

	Move.l	a3,$dff054		; dest mem d
	Move.l	a2,$dff050		; source mem a
	Move.l	a3,$dff048		; source mem c
	Move.w	#$ffff,$dff044		; blit 1st word mask source 
	move.w	#$ffff,$dff046		; blit last word mask source 
	move.w	#0,$dff064		; blit modulo for source a
	move.w	d5,$dff040
	move.w	#0,$dff042		; blit cont reg 1
	Move.w	#42,$dff060		; modulo for source c
	Move.w	#42,$dff066		; modulo for dest
	Move.w	#(8*64)+1,$dff058	; blit height,width

	move.w	#15,scrollpos2
	move.w	#15*16,scrollpos
	
	rts	

getscrbyte:
	clr.l	d0
	move.l	scrollptr,a0
	move.b	(a0)+,d0
	beq	scrollfin
	sub.b	#32,d0
	mulu	#16,d0
	add.l	d0,a2
	move.l	a0,scrollptr
	rts
scrollfin:
	move.l	#scrolltext,scrollptr
	rts	




setup_screen:
	bsr	do_blit

	move.l	scr,$dff054				; dest mem d
	move.w	#(%0001)*256,$dff040			; blit cont reg 0
	move.w	#%0000000000000100,$dff042			; blit cont reg 1
	move.w	#0,$dff066				; modulo for dest
	move.w	#(170*64)+20,$dff058			; blit height,width

	bsr	do_blit

	move.l	scr,a2
	move.l	page,a1
	add.l	#40*4,a2

	move.l	#0,lines

plot_again:
	add.l	#1,lines
	bsr	blit_message
	add.l	#40*tall,a2

	move.b	(a1),d0
	bne.s	plot_again

	move.l	#topcur,d1
	move.l	lines,d0
	sub.l	#1,d0
	mulu	#tall*$100,d0
	add.l	d0,d1
	move.l	d1,maxlines
	
	move.l	lines,d0
	sub.l	#1,d0
	mulu	#10,d0
	move.l	#256,d1
	sub.l	d0,d1
	move.l	d1,lines
	
	rts
	
blit_message:

	movem.l	d0-d7/a2-a6,-(sp)

	move.l	#0,midadd

	move.l	a1,a6
	clr.b	d0
	moveq.l	#-1,d1
	
blit_message_loop1:

	addq.l	#1,d1
	move.b	(a6),d0
	addq	#1,a6
	cmp.b	#0,d0
	bne.s	blit_message_loop1

	move.w	d1,d5
	and.w	#1,d5
	asl.w	#1,d5
	move.w	d5,mid
	
	move.l	a2,midadd
	move.w	d1,d5

	addq.l	#1,d1
	lsr.l	#1,d1

	moveq.l	#20,d6			; centre - lo res

	sub.l	d1,d6
	add.l	d6,a2
	move.l	a2,d2
	and.l	#$fffffffe,d2
	move.l	a2,d3
	and.l	#1,d3
	move.l	d2,a2
	
	move.w	#12,d6
	cmp.l	#1,d3
	beq.s	cont_blit_message
	
	add.w	#12,mid
	subq.l	#2,midadd
	
cont_blit_message:
	
	move.w	d6,d7
	mulu	#8192,d7
	
	subq.w	#4,d6
	cmp.w	#4,d6
	bne.s	other_half
	
	move.w	#12,d6
	add.l	#80,a2
	
other_half:

	sub.l	#40,a2
	clr.w	d0
	lea	font,a0
	move.b	(a1),d0
	addq.l	#1,a1
	cmp.b	#0,d0
	bne.s	mess_is_ok

	movem.l	(sp)+,d0-d7/a2-a6	
	
	move.w	mid,d5
	mulu	#8192,d5
	or.w	#(%1001*256)+$f0,d5
	
	move.l	midadd,a3
	jsr	do_blit
	
	Move.l	a3,$dff054		; dest mem d
	Move.l	a2,$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	d5,$dff040
	move.w	#0,$dff042		; blit cont reg 1
	Move.w	#0,$dff066		; modulo for dest
	Move.w	#(8*64)+40,$dff058	; blit height,width

	jsr	do_blit

dont_centre:
	rts
	
	
mess_is_ok:

	cmp	#32,d0
	beq	space

	sub	#32,d0
	mulu	#16,d0
	add	d0,a0
	
	Move.l	a2,$dff054		; dest mem d
	Move.l	a0,$dff050		; source mem a
	move.l	a2,$dff048		; source mem c
	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	#38,$dff060		; blit modulo for source c	
	or.w	#(%1011*256)+$fa,d7
	move.w	d7,$dff040		; blit cont reg 0
	move.w	#0,$dff042		; blit cont reg 1
	Move.w	#38,$dff066		; modulo for dest
	Move.w	#(8*64)+1,d0		; blit height,width
	cmp.l	#12,d6
	beq.s	not_12
	Move.w	#(9*64)+1,d0
not_12:	
	move.w	d0,$dff058	; blit height,width
	jsr	do_blit
	
space:
	
	addq.l	#1,a2
	bra	cont_blit_message

do_blit:
wait_blit:
	btst.b	#6,$dff002
	bne.s	wait_blit
	
	rts

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_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
	BSR.S	mt_PlayVoice
	LEA	$DFF0B0,A5
	LEA	mt_chan2temp(PC),A6
	BSR.S	mt_PlayVoice
	LEA	$DFF0C0,A5
	LEA	mt_chan3temp(PC),A6
	BSR.S	mt_PlayVoice
	LEA	$DFF0D0,A5
	LEA	mt_chan4temp(PC),A6
	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)
	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
	MOVE.W	#300,D0
mt_WaitDMA
	DBRA	D0,mt_WaitDMA
	MOVE.W	mt_DMACONtemp(PC),D0
	OR.W	#$8000,D0
	MOVE.W	D0,$DFF096
	MOVE.W	#300,D0
mt_WaitDMA2
	DBRA	D0,mt_WaitDMA2

	LEA	$DFF000,A5
	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
	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.S	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
	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
	MOVE.W	#300,D0
mt_rtnloop1
	DBRA	D0,mt_rtnloop1
	MOVE.W	n_dmabit(A6),D0
	BSET	#15,D0
	MOVE.W	D0,$DFF096
	MOVE.W	#300,D0
mt_rtnloop2
	DBRA	D0,mt_rtnloop2
	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 */

		
gen_balls:
	move.l	Screen1,d0
	add.l	#44*40,d0
	move.w	d0,bitplane0_lo
	swap	d0
	move.w	d0,bitplane0_hi
	swap	d0
	add.l	#wide*down,d0	
	move.w	d0,bitplane1_lo
	swap	d0
	move.w	d0,bitplane1_hi
	swap	d0
	add.l	#wide*down,d0	
	move.w	d0,bitplane2_lo
	swap	d0
	move.w	d0,bitplane2_hi

	move.l	scr,d0
	move.w	d0,bitplane3_lo
	swap	d0
	move.w	d0,bitplane3_hi

	move.l	screen2,a0
	add.l	#42*40+6,a0

	bsr	do_blit	
	move.l	a0,$dff054 			; dest mem d
	move.w	#%0001*256,$dff040		; blit cont reg 0
	move.w	#%0,$dff042			; blit cont reg 1
	Move.w	#10,$dff066			; modulo for dest
	Move.w	#(171*64)+15,$dff058		; blit height,width
	
	add.l	#wide*down,a0
	bsr	do_blit	
	move.l	a0,$dff054 			; dest mem d
	Move.w	#(171*64)+15,$dff058		; blit height,width

	add.l	#wide*down,a0
	bsr	do_blit	
	move.l	a0,$dff054 			; dest mem d
	Move.w	#(171*64)+15,$dff058		; blit height,width


	lea	coordsend1,a0
	move.l	offset1,a1
	cmpa.l	a0,a1
	blt.s	coords_ok1
	move.l	#coords1,offset1
coords_ok1:

	lea	coordsend1,a0
	move.l	offset2,a1
	cmpa.l	a0,a1
	blt.s	coords_ok2
	move.l	#coords1,offset2
coords_ok2:

	move.l	offset1,a0
	move.l	offset2,a1
	add.l	#1,a1

	move.w	#maxx,d7

	lea	$dff000,a5		; set base address of hardware
	
more_balls1:	
	
	move.l	#0,d0
	move.l	d0,d1
	
	move.b	(a0),d0
	move.b	(a1),d1
	
	add.l	xs2,a0
	add.l	ys2,a1

	bsr	do_ball
	dbf	d7,more_balls1

	move.l	screen1,a1
	move.l	screen2,a0
	move.l	a0,screen1
	move.l	a1,screen2

	move.l	xs1,d0
	move.l	ys1,d1

	add.l	d0,offset1
	add.l	d1,offset2
	rts
	

do_ball:
	movem.l	d0-d7/a0-a6,-(sp)

	add.w	#20,d0

	move.w	d0,d2
	and.w	#$000f,d2
	ror.w	#4,d2				; mul by 4096
	and.w	#$fff0,d0
	lsr.w	#3,d0				; div by 8

	move.w	d1,d7
	mulu	#40,d7

	add.w	d0,d7
	move.w	#%1111*256+$ca,d4
	add.w	d2,d4

	move.l	screen2,a0
	add.l	d7,a0
	
	bsr	do_blit

	move.l	a0,$54(a5)			; dest mem d
	Move.l	#mask+(0*15),$50(a5)		; source mem a
	move.l	#ball+(0*15)+16,$4c(a5)		; source mem b
	move.l	a0,$48(a5)			; source mem c
	move.w	#-2,$64(a5)			; source a modulo
	move.w	#wide-4,$60(a5)			; source b modulo
	move.w	#-2,$62(a5) 			; source c modulo
	Move.w	#$ffff,$44(a5)			; blit 1st word mask source a
	Move.w	#$0000,$46(a5)			; blit last word mask source a	
	move.w	d4,$40(a5)			; blit cont reg 0
	move.w	d2,$42(a5)			; blit cont reg 1
	Move.w	#wide-4,$66(a5)			; modulo for dest
	Move.w	#(15*64)+2,$58(a5)		; blit height,width

	add.l	#wide*down,a0
	bsr	do_blit

	move.l	a0,$54(a5)			; dest mem d
	Move.l	#mask+(2*15),$50(a5)		; source mem a
	move.l	#ball+(2*15)+16,$4c(a5)		; source mem b
	move.l	a0,$48(a5)			; source mem c
	;move.w	#-2,$64(a5)			; source a modulo
	;move.w	#wide-4,$60(a5)			; source b modulo
	;move.w	#-2,$62(a5) 			; source c modulo
	;Move.w	#$ffff,$44(a5)			; blit 1st word mask source a
	;Move.w	#$0000,$46(a5)			; blit last word mask source a	
	;move.w	d4,$40(a5)			; blit cont reg 0
	;move.w	d2,$42(a5)			; blit cont reg 1
	;Move.w	#wide-4,$66(a5)			; modulo for dest
	Move.w	#(15*64)+2,$58(a5)		; blit height,width

	add.l	#wide*down,a0	
	bsr	do_blit

	move.l	a0,$54(a5)			; dest mem d
	Move.l	#mask+(4*15),$50(a5)		; source mem a
	move.l	#ball+(4*15)+16,$4c(a5)		; source mem b
	move.l	a0,$48(a5)			; source mem c
	;move.w	#-2,$64(a5)			; source a modulo
	;move.w	#wide-4,$60(a5)			; source b modulo
	;move.w	#-2,$62(a5) 			; source c modulo
	;Move.w	#$ffff,$44(a5)			; blit 1st word mask source a
	;Move.w	#$0000,$46(a5)			; blit last word mask source a	
	;move.w	d4,$40(a5)			; blit cont reg 0
	;move.w	d2,$42(a5)			; blit cont reg 1
	;Move.w	#wide-4,$66(a5)			; modulo for dest
	Move.w	#(15*64)+2,$58(a5)		; blit height,width


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


begin2:		dc.l	0

	
	Section	copdat,Data_C

old_copper:	dc.l	0
graphics:	dc.l	0

my_copper:	
		dc.w	$100,$4200	; 4 bp - lo res
		dc.w	$104,$4a		; bp control reg
		dc.w	$108,0		; bp modulo - odd
		dc.w	$10a,0		; bp modulo - even
		dc.w	forecol,0	; colour 0 to black
		dc.w	$102,0
		
		dc.w	$08e,$287b	; bp window start left
		dc.w	$090,$2fc1	; bp window bot right
		dc.w	$94,$d0		; bp stop horz
		dc.w	$92,$38
		dc.w	$120
sprite1_hi:	dc.w	0
		dc.w	$122
sprite1_lo:	dc.w	0

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

		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

		dc.w	$5a01,$ff00
		
		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
		
		dc.w	forecol,$000
		dc.w	$182,$0
		dc.w	$184,$0
		dc.w	$186,$0
		dc.w	$188,$0
		dc.w	$18a,$0
		dc.w	$18c,$0
		dc.w	$18e,$0
		dc.w	$190,$fff
		dc.w	$192,$fff
		dc.w	$194,$fff
		dc.w	$196,$fff
		dc.w	$198,$fff
		dc.w	$19a,$fff
		dc.w	$19c,$fff
		dc.w	$19e,$fff
	
cmap:		dc.w	$1fe,$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

a set topcur
cursor1:		dc.w	a+$000,$ff00
		dc.w	forecol,$444
		dc.w	$190,linecol
		dc.w	$192,linecol
		dc.w	$194,linecol
		dc.w	$196,linecol
		dc.w	$198,linecol
		dc.w	$19a,linecol
		dc.w	$19c,linecol
		dc.w	$19e,linecol
cursor2:	dc.w	a+$100,$ff00
		dc.w	forecol,$666
cursor3:	dc.w	a+$200,$ff00
		dc.w	forecol,$888
cursor4:	dc.w	a+$300,$ff00
		dc.w	forecol,$aaa
cursor5:	dc.w	a+$400,$ff00
		dc.w	forecol,$ccc
cursor6:	dc.w	a+$500,$ff00
		dc.w	forecol,$eee
cursor7:	dc.w	a+$600,$ff00
		dc.w	forecol,$ccc
cursor8:	dc.w	a+$700,$ff00
		dc.w	forecol,$aaa
cursor9:	dc.w	a+$800,$ff00
		dc.w	forecol,$888
cursor10:	dc.w	a+$900,$ff00
		dc.w	forecol,$666
cursor11:	dc.w	a+$a00,$ff00
		dc.w	forecol,$444
cursor12:	dc.w	a+$b00,$ff00
		dc.w	forecol,$000

		dc.w	$190,$fff
		dc.w	$192,$fff
		dc.w	$194,$fff
		dc.w	$196,$fff
		dc.w	$198,$fff
		dc.w	$19a,$fff
		dc.w	$19c,$fff
		dc.w	$19e,$fff

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

		dc.w	$0101,$ff00

		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	$0501,$ff00,forecol,$fff
		dc.w	$0601,$ff00,forecol,$000,textcol,$f00



v set $1001
		dc.w	v,$ff00,$094,$d8,$92,$30,$102
scrollpos:	dc.w	0


		dc.w	v+$100,$ff00,forecol,$fff
		dc.w	v+$200,$ff00,forecol,$000,textcol,$fff

v set v+$1000
		dc.w	v,$ff00
		dc.w	$10a,-44*2

a set $8
b set $fff
c set v+$100
		rept 8
		dc.w	c,$ff00
		dc.w	forecol,a
		dc.w	textcol,b
	
a set a-1
b set b-$222
c set c+$100
		endr
		
		dc.w	$100,0		
		
		dc.w	$3001,$ff00	; end of pal screen
		dc.w	$9c,$8010	; irq set bits
		dc.w	$ffff,$fffe	; end of copper list


ball:		incbin	"bulb.bin"
mask:		incbin	"bulb.msk"


copper2:
		dc.w	$102,0
		dc.w	$100,$1200	; 1 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	forecol,0	; colour 0 to black

		dc.w	$08e,$7f81	; bp window start left
		dc.w	$090,$7fc1	; bp window bot right
		dc.w	$94,$c0		; bp stop 
		dc.w	$92,$40		; bp start
		dc.w	$120,0,$122,0
		
		dc.w	  $e0
bp0_hi:		dc.w	0,$e2
bp0_lo:		dc.w	0
	
		
		dc.w	forecol,$000
		dc.w	$182,$fff

a set $7f01
b set $00f
c set $0f0
		rept	14
		dc.w	a,$ff00,$182,b,$102,4
a set a+$100
b set b+$110
		endr
		rept	14
		dc.w	a,$ff00,$182,b,$102,4
a set a+$100
b set b-$110
		endr
		
		dc.w	$9c01,$ff00,$100,$0,$102,0

		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

font:		incbin	"fonts/keff12.wrd"	;

		***** logo goes here ****

		; it must be lo-res, 16 colours
		; 320 x 50, colour map before!
		; cut out with kefrens converter

logo:		incbin	"logo.bin"




		;**********************************
		;********   module name  **********
		;**********************************
		
mt_data:	incbin	"df2:mod.daffy4"
		dc.l	$12345678	; rem the above line for no module

	section	miscdata,data
		
down		equ	256
wide:		equ	40
	
maxx:		equ	24
	
scrsize:		equ	wide*down*3

screen:		dc.l	0
screen1:	dc.l	0
screen2:	dc.l	0 
		
offset1:		dc.l	coords1
offset2:		dc.l	coords1

mid:		dc.l	0
midadd:		dc.l	0
page:		dc.l	0
scr:		dc.l	0

glib:		dc.b	"graphics.library",0
	even
	
modpointerx:	dc.l	$1f0
modpointery:	dc.l	$1f4

xs1:		dc.l	xstep1*2
ys1:		dc.l	ystep1*2
xs2:		dc.l	xstep2*2
ys2:		dc.l	ystep2*2

scrollmask:	dc.l	0
delay:		dc.l	400
maxlines:	dc.l	0
lines:		dc.l	0
ypos:		dc.l	256
xpos:		dc.l	0
oldy:		dc.l	0
yp:		dc.l	0
quit:		dc.l	0
step:		dc.l	0
oldintena:	dc.w	0
oldintreq:	dc.w	0

filename:	dc.l	0

	
scrollpos2:	dc.l	0
SegAdd:		dc.l	0
DOSBase:	dc.l	0
doslib:		dc.b	"dos.library",0
		even		


info:
	dc.b	" ",0," ",0," ",0," ",0," ",0," ",0," ",0," ",0," ",0," ",0," ",0," ",0," ",0," ",0," ",0," ",0," ",0
	dc.b	"VECTORS CHECKED - YOU ARE VIRUS FREE!",0,0
	even	
	
flist:	dc.l	file1	
	dc.l	file2
	dc.l	file3	
	dc.l	file4	
	dc.l	file5	
	dc.l	file6	
	dc.l	file7	
	dc.l	file8	
	dc.l	file9	
	dc.l	file10	
	dc.l	file11
	dc.l	file12
	dc.l	file13
	dc.l	file14
	dc.l	file15
	
coords1:	incbin	"sine/introlist12"	; can be 1 - 19
coordsend1:	dcb.l	maxx*32,0
		even
		
page1:
	dc.b	"SOME DEMOS",0
	dc.b	" ",0
	dc.b	"1",0
	dc.b	"2",0
	dc.b	"3",0
	dc.b	"4",0
	dc.b	"5",0
	dc.b	"6",0
	dc.b	"7",0
	dc.b	"8",0
	dc.b	"9",0
	dc.b	"a",0
	dc.b	0,0

	even

file1:	dc.b	"",0
	even
file2:	dc.b	"",0
	even
file3:	dc.b	"1",0
	even
file4:	dc.b	"2",0
	even
file5:	dc.b	"3",0
	even
file6:	dc.b	"4",0
	even
file7:	dc.b	"5",0
	even
file8:	dc.b	"6",0
	even
file9:	dc.b	"7",0
	even
file10:	dc.b	"8",0
	even
file11:	dc.b	"9",0
	even
file12:	dc.b	"a",0
	even
file13:	dc.b	"",0
	even
file14:	dc.b	"",0
	even
file15:	dc.b	"",0
	even

scrolltext:
	dc.b	"PLEASE ONLY USE LSD MUSIC, RIP SOME FROM PAZZAs MENUS OR ASK IF YOU NEED ANY.       "
	dc.b	"MENU CODED BY SHAGRATT, LOGO BY WATCHMAN, FONTS BY KEFRENS, MUSIC BY ??/LSD"
	dc.b	""
	dc.b	""
	dc.b	""
	dc.b	""
	dc.b	0
	even

scrollptr:	dc.l	scrolltext

	end

