  ~    ߏߏߏߏߏߏ;-----------------------------------------------------------------------------
;	coding done by the ultimative galaxy/DYTEC. this is the
;	crackintro number 1.. hope you enjoy this one !!!!
;-----------------------------------------------------------------------------

a	=	$55000	;charset
b	=	$57174	;module
c	=	$60000	;bitplane
d	=	$55282	;logo
e	=	$54f3e	;ball

>extern	"sys:galaxy/intro/ball.raw",e		;$54f3e+00192=$54ffe
>extern	"sys:galaxy/intro/chars.raw",a		;$55000+00640=$55280
>extern	"sys:galaxy/intro/logo.raw",d		;$55282+07920=$57172
>extern	"sys:galaxy/intro/module.mod",b		;$57174+08418=$5f58c

;start	$50000
;end	$5f58e

	jmp	$50000
	org	$50000
	load	$50000

;-----------------------------------------------------------------------------
;	start of the code
;-----------------------------------------------------------------------------

start:
	bset	#1,$bfe001
	bclr	#3,$bfd100

	lea	$dff000,a0
	move.w	#$4000,$9a(a0)
	move.w	#$0080,$96(a0)
	move.l	#copper,$84(a0)
	move.w	#$8080,$96(a0)

cleaner:
	lea	c+$0000,a0
	move.w	#(320/8*256*5),d0

clear:
	clr.b	(a0)+
	dbra	d0,clear

	moveq	#$00,d0
	moveq	#$00,d1
	moveq	#$00,d2
	moveq	#$00,d3
	moveq	#$00,d4
	moveq	#$00,d5
	moveq	#$00,d6
	moveq	#$00,d7

	bsr.w	mt_init

	moveq	#$00,d0
	moveq	#$00,d1
	moveq	#$00,d2
	moveq	#$00,d3
	moveq	#$00,d4
	moveq	#$00,d5
	moveq	#$00,d6
	moveq	#$00,d7

loop:
	cmp.b	#$ff,$dff006
	bne.b	loop

	btst	#10,$dff016
	beq.b	lep

	bsr.w	textprint
	bsr.w	textprint

lep:
	bsr	tabmove
	bsr.w	bitplanechanger
	bsr.w	clearscreen
	bsr.w	routine
	bsr.w	timer

	bsr.w	mt_music

	btst	#6,$bfe001
	bne.b	loop

	bsr.w	mt_end

	moveq	#$00,d0
	rts

;-----------------------------------------------------------------------------
;	text printer
;-----------------------------------------------------------------------------

textprint:
	moveq	#$00,d0
	moveq	#$00,d1
	moveq	#$00,d2
	moveq	#$00,d3
	moveq	#$00,d4
	moveq	#$00,d5
	moveq	#$00,d6
	moveq	#$00,d7

	move.w	wert1(pc),d2
	move.w	wert2(pc),d3
	move.w	wert3(pc),d4
	move.w	wert4(pc),d5

	lea	text(pc),a0
	move.b	$00(a0,d2.w),d0

	addq.w	#$0001,d2
	move.w	d2,wert1

	cmp.b	#$10,d0
	beq.b	setalltonextline

	cmp.b	#$11,d0
	beq.b	setscreenaddress

	cmp.b	#$12,d0
	beq.w	clearscreenandsetnew

	cmp.b	#$13,d0
	beq.w	set5seconds

	cmp.b	#$14,d0
	beq.w	set10seconds

	cmp.b	#$15,d0
	beq.w	set15seconds

	cmp.b	#$16,d0
	beq.w	waitseconds

	cmp.b	#$1f,d0
	beq.w	restart

	sub.b	#$20,d0
	lsl.b	#$02,d0

prozessor:
	lea	offset(pc),a0
	move.l	$00(a0,d0.w),a0
	lea	c,a1
	add.w	d4,a1
	add.w	d3,a1
	moveq	#$07,d1		;--- hoehe des charsets

label:
	move.b	(a0),(a1)	;--- .b = 8 pixel; .w = 16 pixel; .l = 32 pixel

	add.w	#(320/8),a0
	add.w	#(320/8),a1

	dbra	d1,label

	addq.w	#$0001,d3
	move.w	d3,wert2
	rts

setalltonextline:
	moveq	#$00,d3
	add.w	#(320/8*8),d4
	move.w	d3,wert2
	move.w	d4,wert3
	rts

setscreenaddress:
	lea	c+$9b0,a5	;--- adresse bildmitte
	lea	c+$9b0,a6
	move.b	#62,d5		;--- graphic zeilen /2
	move.w	d5,wert4
	rts

clearscreenandsetnew:
	moveq	#$40,d1		;--- loeschende bytes per line

cleanitup:
	clr.b	-(a5)
	clr.b	(a6)+
	dbra	d1,cleanitup
	subq.b	#$01,d5
	cmp.b	#$00,d5
	beq.b	clean

	subq.w	#$0001,d2

clean:
	moveq	#$00,d3
	moveq	#$00,d4
	move.w	d2,wert1
	move.w	d3,wert2
	move.w	d4,wert3
	move.w	d5,wert4
	rts

set5seconds:
	move.w	#0200,d5	;--- -50
	move.w	d5,wert4
	rts

set10seconds:
	move.w	#0450,d5
	move.w	d5,wert4
	rts

set15seconds:
	move.w	#0700,d5
	move.w	d5,wert4
	rts

waitseconds:
	subq.w	#0001,d5
	cmp.w	#0000,d5
	beq.b	wait
	subq.w	#$0001,d2
	move.w	d2,wert1

wait:
	move.w	d5,wert4
	rts

restart:
	moveq	#$00,d2
	move.w	d2,wert1
	rts

wert1:
	dc.w	0

wert2:
	dc.w	0

wert3:
	dc.w	0

wert4:
	dc.w	0

;-----------------------------------------------------------------------------
;	player, set here becoz not own routine
;-----------------------------------------------------------------------------

bitplanechanger:
	moveq	#$00,d0
	lea	bpl1(pc),a0
	lea	bpl2(pc),a1
	lea	bpl3(pc),a2
	move.l	wert(pc),d0
	swap	d0
	move.l	d0,wert
	move	d0,2(a0)
	move	d0,2(a1)
	move	d0,2(a2)
	rts

wert:
	dc.w	c/$10000,(c+$10000)/$10000

clearscreen:
	moveq	#$00,d0
	move.l	wert(pc),d0
	swap	d0
	move.b	#$00,d0
	add.w	#$2800,d0
	move.l	d0,a0

	lea	$dff000,a2

clearscr:
	btst	#14,$02(a2)
	bne.b	clearscr
	move.l	a0,$54(a2)
	move.w	#$0000,$66(a2)
	move.w	#%0000000100000000,$40(a2)
	move.w	#$0000,$42(a2)
	move.w	#$ffff,$44(a2)
	move.w	#$ffff,$46(a2)
	move.w	#(125*3*64)+(320/16),$58(a2)
	rts

routine:
	move.w	#$0000,$62(a2)
	move.w	#$0000,$64(a2)

	move.w	#%1111111111111111,$44(a2)
	move.w	#%0000000000000000,$46(a2)

	move.w	#(objektend-objekt)/12-1,d5

objektloop:
	moveq	#$00,d0
	move.l	wert(pc),d0
	swap	d0
	move.b	#$00,d0
	add.w	#$2800,d0
	move.l	d0,a0

	lea	objekt(pc),a1

	move.w	2(a1,d6),d2
	add.w	4(a1,d6),d2

	subq.w	#1,8(a1,d6)
	cmp.w	#0,8(a1,d6)
	bne.b	goto
	move.w	10(a1,d6),8(a1,d6)
	addq.w	#1,4(a1,d6)

goto:
	move.w	d2,2(a1,d6)

	add.w	#50,d2
	cmp.w	#256,d2
	ble.b	goto2
	move.w	#256,2(a1,d6)
	bsr.w	goto3
	rts

goto2:
	mulu	#40*3,d2
	add.w	d2,a0

	move.w	(a1,d6),d2
	add.w	6(a1,d6),d2
	move.w	d2,(a1,d6)

	add.w	#152,d2
	move.w	d2,d0
	lsr.w	#3,d2
	add.w	d2,a0

	and.w	#15,d0
	ror.w	#4,d0
	or.w	#%0000111111001010,d0

	lea	$dff000,a2

blitter:
	btst	#14,$02(a2)
	bne.b	blitter

	move.l	#e,$4c(a2)
	move.l	#e+2,$50(a2)
	move.l	a0,$48(a2)
	move.l	a0,$54(a2)

	move.w	#(320-32)/8,$60(a2)
	move.w	#(320-32)/8,$66(a2)

	move.w	d0,$40(a2)

	lsr.b	#8,d0
	sub.w	#$0f00,d0
	move.w	d0,$42(a2)

	move.w	#(15*3*64)+(32/16),$58(a2)

goto3:
	add.w	#12,d6
	dbra	d5,objektloop
	moveq	#$00,d6
	rts

timer:
	move.w	timewert(pc),d0
	cmp.b	#$0,d0
	beq.b	retur
	subq.w	#$0001,d0
	move.w	d0,timewert
	rts

retur:
	move.w	#$0099,timewert
	bsr.w	reset
	rts

timewert:
	dc.w	$0099

objekt:
;bobstruktur fuer den bobshit
;x, y, (-hoch)(+runter), (-links)(+rechts), timedelay, restoretime

obenlinks:
	dc.w	0,	0,	-3,	-1,	10,	10
	dc.w	0,	0,	-5,	-2,	5,	5
	dc.w	0,	0,	-1,	-2,	10,	10
	dc.w	0,	0,	-2,	-1,	10,	10
	dc.w	0,	0,	-7,	-3,	2,	2

mitteoben:
	dc.w	0,	0,	-4,	0,	8,	8

obenrechts:
	dc.w	0,	0,	-2,	1,	10,	10
	dc.w	0,	0,	-1,	2,	10,	10
	dc.w	0,	0,	-3,	2,	5,	5
	dc.w	0,	0,	-3,	1,	10,	10

untenlinks:
	dc.w	0,	0,	2,	-2,	10,	10
	dc.w	0,	0,	3,	-5,	10,	10
	dc.w	0,	0,	6,	-6,	10,	10
	dc.w	0,	0,	1,	-1,	10,	10
	dc.w	0,	0,	1,	-10,	1,	1
	dc.w	0,	0,	6,	-1,	10,	10

untenmitte:
	dc.w	0,	0,	0,	0,	2,	2

untenrechts:
	dc.w	0,	0,	2,	2,	10,	10
	dc.w	0,	0,	3,	5,	10,	10
	dc.w	0,	0,	6,	6,	10,	10
	dc.w	0,	0,	1,	1,	10,	10
	dc.w	0,	0,	1,	10,	1,	1
	dc.w	0,	0,	6,	1,	10,	10

objektend:

reset:
	move.w	#(objektend-objekt)/2-1,d0
	move.w	#(restoreobjektend-restoreobjekt)/2-1,d1
	cmp.w	d0,d1
	bne.b	return
	moveq	#$00,d2

go:
	lea	restoreobjekt(pc),a0
	lea	objekt(pc),a1
	move.w	(a0,d2),(a1,d2)
	addq.w	#2,d2
	dbra	d0,go

return:
	rts

restoreobjekt:
;bobstruktur fuer den bobshit muss identisch zur obigen tabelle sein.
;x, y, (-hoch)(+runter), (-links)(+rechts), timedelay, restoretime

restoreobenlinks:
	dc.w	0,	0,	-3,	-1,	10,	10
	dc.w	0,	0,	-5,	-2,	5,	5
	dc.w	0,	0,	-1,	-2,	10,	10
	dc.w	0,	0,	-2,	-1,	10,	10
	dc.w	0,	0,	-7,	-3,	2,	2

restoremitteoben:
	dc.w	0,	0,	-4,	0,	8,	8

restoreobenrechts:
	dc.w	0,	0,	-2,	1,	10,	10
	dc.w	0,	0,	-1,	2,	10,	10
	dc.w	0,	0,	-3,	2,	5,	5
	dc.w	0,	0,	-3,	1,	10,	10

restoreuntenlinks:
	dc.w	0,	0,	2,	-2,	10,	10
	dc.w	0,	0,	3,	-5,	10,	10
	dc.w	0,	0,	6,	-6,	10,	10
	dc.w	0,	0,	1,	-1,	10,	10
	dc.w	0,	0,	1,	-10,	1,	1
	dc.w	0,	0,	6,	-1,	10,	10

restoreuntenmitte:
	dc.w	0,	0,	0,	0,	2,	2

restoreuntenrechts:
	dc.w	0,	0,	2,	2,	10,	10
	dc.w	0,	0,	3,	5,	10,	10
	dc.w	0,	0,	6,	6,	10,	10
	dc.w	0,	0,	1,	1,	10,	10
	dc.w	0,	0,	1,	10,	1,	1
	dc.w	0,	0,	6,	1,	10,	10

restoreobjektend:

;-----------------------------------------------------------------------------
;	tabmove
;-----------------------------------------------------------------------------

tabmove:
	lea	tab1(pc),a0
	lea	tab2(pc),a1
	moveq	#$00,d0
	move.l	werter1,d0

	btst	#0,d0
	bne	lopp

	sub.w	#$0100,(a0)
	sub.w	#$0100,(a1)

	cmp.w	#$3301,(a0)
	bne	rt1
	swap	d0
	move.l	d0,werter1

rt1:
	rts

lopp:
	add.w	#$0100,(a0)
	add.w	#$0100,(a1)

	cmp.w	#$7401,(a1)
	bne	rt2

	swap	d0
	move.l	d0,werter1

rt2:
	rts

werter1:
	dc.l	$00010000

;-----------------------------------------------------------------------------
;	player, set here becoz not own routine
;-----------------------------------------------------------------------------

dmawait		=	300
n_note		=	00
n_cmd		=	02
n_cmdlo		=	03
n_start		=	04
n_length	=	08
n_loopstart	=	10
n_replen	=	14
n_period	=	16
n_finetune	=	18
n_volume	=	19
n_dmabit	=	20
n_toneportdirec	=	22
n_toneportspeed	=	23
n_wantedperiod	=	24
n_vibratocmd	=	26
n_vibratopos	=	27
n_tremolocmd	=	28
n_tremolopos	=	29
n_wavecontrol	=	30
n_glissfunk	=	31
n_sampleoffset	=	32
n_pattpos	=	33
n_loopcount	=	34
n_funkoffset	=	35
n_wavestart	=	36
n_reallength	=	40

mt_init:
	lea	b,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.b	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.b	mt_nonewnote
	clr.b	mt_counter
	tst.b	mt_pattdeltime2
	beq.b	mt_getnewnote
	bsr.b	mt_nonewallchannels
	bra.w	mt_dskip

mt_nonewnote:
	bsr.b	mt_nonewallchannels
	bra.w	mt_nonewposyet

mt_nonewallchannels:
	lea	$dff0a0,a5
	lea	mt_chan1temp(pc),a6
	bsr.w	mt_checkefx
	lea	$dff0b0,a5
	lea	mt_chan2temp(pc),a6
	bsr.w	mt_checkefx
	lea	$dff0c0,a5
	lea	mt_chan3temp(pc),a6
	bsr.w	mt_checkefx
	lea	$dff0d0,a5
	lea	mt_chan4temp(pc),a6
	bra.w	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.b	mt_playvoice
	lea	$dff0b0,a5
	lea	mt_chan2temp(pc),a6
	bsr.b	mt_playvoice
	lea	$dff0c0,a5
	lea	mt_chan3temp(pc),a6
	bsr.b	mt_playvoice
	lea	$dff0d0,a5
	lea	mt_chan4temp(pc),a6
	bsr.b	mt_playvoice
	bra.w	mt_setdma

mt_playvoice:
	tst.l	(a6)
	bne.b	mt_plvskip
	bsr.w	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.w	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.b	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.b	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.w	mt_checkmoreefx	; if no note
	move.w	2(a6),d0
	and.w	#$0ff0,d0
	cmp.w	#$0e50,d0
	beq.b	mt_dosetfinetune
	move.b	2(a6),d0
	and.b	#$0f,d0
	cmp.b	#3,d0	; toneportamento
	beq.b	mt_chktoneporta
	cmp.b	#5,d0
	beq.b	mt_chktoneporta
	cmp.b	#9,d0	; sample offset
	bne.b	mt_setperiod
	bsr.w	mt_checkmoreefx
	bra.b	mt_setperiod

mt_dosetfinetune:
	bsr.w	mt_setfinetune
	bra.b	mt_setperiod

mt_chktoneporta:
	bsr.w	mt_settoneporta
	bra.w	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.b	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.w	mt_checkmoreefx

	move.w	n_dmabit(a6),$dff096
	btst	#2,n_wavecontrol(a6)
	bne.b	mt_vibnoc
	clr.b	n_vibratopos(a6)

mt_vibnoc:
	btst	#6,n_wavecontrol(a6)
	bne.b	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.w	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.b	mt_dskc
	move.b	d0,mt_pattdeltime2
	clr.b	mt_pattdeltime

mt_dskc:
	tst.b	mt_pattdeltime2
	beq.b	mt_dska
	subq.b	#1,mt_pattdeltime2
	beq.b	mt_dska
	sub.w	#16,mt_patternpos

mt_dska:
	tst.b	mt_pbreakflag
	beq.b	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.b	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.b	mt_nonewposyet
	clr.b	mt_songpos

mt_nonewposyet:
	tst.b	mt_posjumpflag
	bne.b	mt_nextposition
	movem.l	(sp)+,d0-d4/a0-a6
	rts

mt_checkefx:
	bsr.w	mt_updatefunk
	move.w	n_cmd(a6),d0
	and.w	#$0fff,d0
	beq.b	mt_pernop
	move.b	n_cmd(a6),d0
	and.b	#$0f,d0
	beq.b	mt_arpeggio
	cmp.b	#1,d0
	beq.w	mt_portaup
	cmp.b	#2,d0
	beq.w	mt_portadown
	cmp.b	#3,d0
	beq.w	mt_toneportamento
	cmp.b	#4,d0
	beq.w	mt_vibrato
	cmp.b	#5,d0
	beq.w	mt_toneplusvolslide
	cmp.b	#6,d0
	beq.w	mt_vibratoplusvolslide
	cmp.b	#$e,d0
	beq.w	mt_e_commands

setback:
	move.w	n_period(a6),6(a5)
	cmp.b	#7,d0
	beq.w	mt_tremolo
	cmp.b	#$a,d0
	beq.w	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.b	mt_arpeggio2
	cmp.w	#2,d0
	beq.b	mt_arpeggio1
	moveq	#0,d0
	move.b	n_cmdlo(a6),d0
	lsr.b	#4,d0
	bra.b	mt_arpeggio3

mt_arpeggio1:
	moveq	#0,d0
	move.b	n_cmdlo(a6),d0
	and.b	#15,d0
	bra.b	mt_arpeggio3

mt_arpeggio2:
	move.w	n_period(a6),d2
	bra.b	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.b	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.b	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.b	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.w	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.b	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.b	mt_stpfound
	addq.w	#2,d0
	cmp.w	#37*2,d0
	blo.b	mt_stploop
	moveq	#35*2,d0

mt_stpfound:
	move.b	n_finetune(a6),d2
	and.b	#8,d2
	beq.b	mt_stpgoss
	tst.w	d0
	beq.b	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.b	mt_cleartoneporta
	bge.w	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.b	mt_toneportnochange
	move.b	d0,n_toneportspeed(a6)
	clr.b	n_cmdlo(a6)

mt_toneportnochange:
	tst.w	n_wantedperiod(a6)
	beq.w	mt_return2
	moveq	#0,d0
	move.b	n_toneportspeed(a6),d0
	tst.b	n_toneportdirec(a6)
	bne.b	mt_toneportaup

mt_toneportadown:
	add.w	d0,n_period(a6)
	move.w	n_wantedperiod(a6),d0
	cmp.w	n_period(a6),d0
	bgt.b	mt_toneportasetper
	move.w	n_wantedperiod(a6),n_period(a6)
	clr.w	n_wantedperiod(a6)
	bra.b	mt_toneportasetper

mt_toneportaup:
	sub.w	d0,n_period(a6)
	move.w	n_wantedperiod(a6),d0
	cmp.w	n_period(a6),d0
	blt.b	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.b	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.b	mt_glissfound
	addq.w	#2,d0
	cmp.w	#36*2,d0
	blo.b	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.b	mt_vibrato2
	move.b	n_vibratocmd(a6),d2
	and.b	#$0f,d0
	beq.b	mt_vibskip
	and.b	#$f0,d2
	or.b	d0,d2

mt_vibskip:
	move.b	n_cmdlo(a6),d0
	and.b	#$f0,d0
	beq.b	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.b	mt_vib_sine
	lsl.b	#3,d0
	cmp.b	#1,d2
	beq.b	mt_vib_rampdown
	move.b	#255,d2
	bra.b	mt_vib_set

mt_vib_rampdown:
	tst.b	n_vibratopos(a6)
	bpl.b	mt_vib_rampdown2
	move.b	#255,d2
	sub.b	d0,d2
	bra.b	mt_vib_set

mt_vib_rampdown2:
	move.b	d0,d2
	bra.b	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.b	mt_vibratoneg
	add.w	d2,d0
	bra.b	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.w	mt_toneportnochange
	bra.w	mt_volumeslide

mt_vibratoplusvolslide:
	bsr.b	mt_vibrato2
	bra.w	mt_volumeslide

mt_tremolo:
	move.b	n_cmdlo(a6),d0
	beq.b	mt_tremolo2
	move.b	n_tremolocmd(a6),d2
	and.b	#$0f,d0
	beq.b	mt_treskip
	and.b	#$f0,d2
	or.b	d0,d2

mt_treskip:
	move.b	n_cmdlo(a6),d0
	and.b	#$f0,d0
	beq.b	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.b	mt_tre_sine
	lsl.b	#3,d0
	cmp.b	#1,d2
	beq.b	mt_tre_rampdown
	move.b	#255,d2
	bra.b	mt_tre_set

mt_tre_rampdown:
	tst.b	n_vibratopos(a6)
	bpl.b	mt_tre_rampdown2
	move.b	#255,d2
	sub.b	d0,d2
	bra.b	mt_tre_set

mt_tre_rampdown2:
	move.b	d0,d2
	bra.b	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.b	mt_tremoloneg
	add.w	d2,d0
	bra.b	mt_tremolo3

mt_tremoloneg:
	sub.w	d2,d0

mt_tremolo3:
	bpl.b	mt_tremoloskip
	clr.w	d0

mt_tremoloskip:
	cmp.w	#$40,d0
	bls.b	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.b	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.b	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.b	mt_volslidedown

mt_volslideup:
	add.b	d0,n_volume(a6)
	cmp.b	#$40,n_volume(a6)
	bmi.b	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.b	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.b	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.b	mt_pj2
	move.b	d0,mt_pbreakpos
	st	mt_posjumpflag
	rts

mt_setspeed:
	move.b	3(a6),d0
	beq.w	mt_return2
	clr.b	mt_counter
	move.b	d0,mt_speed
	rts

mt_checkmoreefx:
	bsr.w	mt_updatefunk
	move.b	2(a6),d0
	and.b	#$0f,d0
	cmp.b	#$9,d0
	beq.w	mt_sampleoffset
	cmp.b	#$b,d0
	beq.w	mt_positionjump
	cmp.b	#$d,d0
	beq.b	mt_patternbreak
	cmp.b	#$e,d0
	beq.b	mt_e_commands
	cmp.b	#$f,d0
	beq.b	mt_setspeed
	cmp.b	#$c,d0
	beq.w	mt_volumechange
	bra.w	mt_pernop

mt_e_commands:
	move.b	n_cmdlo(a6),d0
	and.b	#$f0,d0
	lsr.b	#4,d0
	beq.b	mt_filteronoff
	cmp.b	#1,d0
	beq.w	mt_fineportaup
	cmp.b	#2,d0
	beq.w	mt_fineportadown
	cmp.b	#3,d0
	beq.b	mt_setglisscontrol
	cmp.b	#4,d0
	beq.w	mt_setvibratocontrol
	cmp.b	#5,d0
	beq.w	mt_setfinetune
	cmp.b	#6,d0
	beq.w	mt_jumploop
	cmp.b	#7,d0
	beq.w	mt_settremolocontrol
	cmp.b	#9,d0
	beq.w	mt_retrignote
	cmp.b	#$a,d0
	beq.w	mt_volumefineup
	cmp.b	#$b,d0
	beq.w	mt_volumefinedown
	cmp.b	#$c,d0
	beq.w	mt_notecut
	cmp.b	#$d,d0
	beq.w	mt_notedelay
	cmp.b	#$e,d0
	beq.w	mt_patterndelay
	cmp.b	#$f,d0
	beq.w	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.w	mt_return2
	move.b	n_cmdlo(a6),d0
	and.b	#$0f,d0
	beq.b	mt_setloop
	tst.b	n_loopcount(a6)
	beq.b	mt_jumpcnt
	subq.b	#1,n_loopcount(a6)
	beq.w	mt_return2

mt_jmploop:
	move.b	n_pattpos(a6),mt_pbreakpos
	st	mt_pbreakflag
	rts

mt_jumpcnt:
	move.b	d0,n_loopcount(a6)
	bra.b	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.b	mt_rtnend
	moveq	#0,d1
	move.b	mt_counter(pc),d1
	bne.b	mt_rtnskp
	move.w	(a6),d1
	and.w	#$0fff,d1
	bne.b	mt_rtnend
	moveq	#0,d1
	move.b	mt_counter(pc),d1

mt_rtnskp:
	divu	d0,d1
	swap	d1
	tst.w	d1
	bne.b	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.w	mt_return2
	moveq	#0,d0
	move.b	n_cmdlo(a6),d0
	and.b	#$f,d0
	bra.w	mt_volslideup

mt_volumefinedown:
	tst.b	mt_counter
	bne.w	mt_return2
	moveq	#0,d0
	move.b	n_cmdlo(a6),d0
	and.b	#$0f,d0
	bra.w	mt_volslidedown2

mt_notecut:
	moveq	#0,d0
	move.b	n_cmdlo(a6),d0
	and.b	#$0f,d0
	cmp.b	mt_counter(pc),d0
	bne.w	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.w	mt_return2
	move.w	(a6),d0
	beq.w	mt_return2
	move.l	d1,-(sp)
	bra.w	mt_doretrig

mt_patterndelay:
	tst.b	mt_counter
	bne.w	mt_return2
	moveq	#0,d0
	move.b	n_cmdlo(a6),d0
	and.b	#$0f,d0
	tst.b	mt_pattdeltime2
	bne.w	mt_return2
	addq.b	#1,d0
	move.b	d0,mt_pattdeltime
	rts

mt_funkit:
	tst.b	mt_counter
	bne.w	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.w	mt_return2

mt_updatefunk:
	movem.l	a0/d1,-(sp)
	moveq	#0,d0
	move.b	n_glissfunk(a6),d0
	lsr.b	#4,d0
	beq.b	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.b	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.b	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

;-----------------------------------------------------------------------------
;	copperlist
;-----------------------------------------------------------------------------

copper:
	dc.w	$008e,$3381,$0090,$ffc1
	dc.w	$0092,$0038,$0094,$00d0
	dc.w	$0120,$0000,$0122,$0000
	dc.w	$0102,$0000

;-
	dc.w	$0180,$0005,$0182,$0bbb
	dc.w	$0184,$0ddd,$0186,$0999
	dc.w	$0188,$0777,$018a,$0666
	dc.w	$018c,$0555,$018e,$0444

;-
	dc.w	$00e0,d/$10000,$00e2,d&$ffff+$0000
	dc.w	$00e4,d/$10000,$00e6,d&$ffff+$0028
	dc.w	$00e8,d/$10000,$00ea,d&$ffff+$0050

	dc.w	$0108,$0050,$010a,$0050
	dc.w	$0100,$3200

;-
	dc.w	$2c3b,$fffe
	dc.w	$0180,$04aa,$0180,$05aa
	dc.w	$0180,$06aa,$0180,$07aa
	dc.w	$0180,$08aa,$0180,$09aa
	dc.w	$0180,$0aaa,$0180,$0baa
	dc.w	$0180,$0caa,$0180,$0daa
	dc.w	$0180,$0eaa,$0180,$0faa
	dc.w	$0180,$0fab,$0180,$0fac
	dc.w	$0180,$0fad,$0180,$0fae
	dc.w	$0180,$0faf,$0180,$0fba
	dc.w	$0180,$0fbb,$0180,$0fbc
	dc.w	$0180,$0fbb,$0180,$0fbc
	dc.w	$0180,$0faf,$0180,$0fba
	dc.w	$0180,$0fad,$0180,$0fae
	dc.w	$0180,$0fab,$0180,$0fac
	dc.w	$0180,$0eaa,$0180,$0faa
	dc.w	$0180,$0caa,$0180,$0daa
	dc.w	$0180,$0aaa,$0180,$0baa
	dc.w	$0180,$08aa,$0180,$09aa
	dc.w	$0180,$06aa,$0180,$07aa
	dc.w	$0180,$04aa,$0180,$05aa
	dc.w	$0180,$03aa,$0180,$0303

;-
tab1:
	dc.w	$7201,$fffe
	dc.w	$0108,$ffd8,$010a,$ffd8
	dc.w	$0100,$3200

;-
tab2:
	dc.w	$7401,$fffe
	dc.w	$0108,$0050,$010a,$0050
	dc.w	$0100,$3200

;-

	dc.w	$7501,$fffe
	dc.w	$00e0,d/$10000,$00e2,d&$ffff+$0000-$28
	dc.w	$0108,$ffd8,$010a,$ffd8
	dc.w	$0100,$1200

;-
	dc.w	$7a3b,$fffe
	dc.w	$0180,$04aa,$0180,$05aa
	dc.w	$0180,$06aa,$0180,$07aa
	dc.w	$0180,$08aa,$0180,$09aa
	dc.w	$0180,$0aaa,$0180,$0baa
	dc.w	$0180,$0caa,$0180,$0daa
	dc.w	$0180,$0eaa,$0180,$0faa
	dc.w	$0180,$0fab,$0180,$0fac
	dc.w	$0180,$0fad,$0180,$0fae
	dc.w	$0180,$0faf,$0180,$0fba
	dc.w	$0180,$0fbb,$0180,$0fbc
	dc.w	$0180,$0fbb,$0180,$0fbc
	dc.w	$0180,$0faf,$0180,$0fba
	dc.w	$0180,$0fad,$0180,$0fae
	dc.w	$0180,$0fab,$0180,$0fac
	dc.w	$0180,$0eaa,$0180,$0faa
	dc.w	$0180,$0caa,$0180,$0daa
	dc.w	$0180,$0aaa,$0180,$0baa
	dc.w	$0180,$08aa,$0180,$09aa
	dc.w	$0180,$06aa,$0180,$07aa
	dc.w	$0180,$04aa,$0180,$05aa
	dc.w	$0180,$03aa,$0180,$0005

;-
	dc.w	$823b,$fffe
	dc.w	$0180,$04aa,$0180,$05aa
	dc.w	$0180,$06aa,$0180,$07aa
	dc.w	$0180,$08aa,$0180,$09aa
	dc.w	$0180,$0aaa,$0180,$0baa
	dc.w	$0180,$0caa,$0180,$0daa
	dc.w	$0180,$0eaa,$0180,$0faa
	dc.w	$0180,$0fab,$0180,$0fac
	dc.w	$0180,$0fad,$0180,$0fae
	dc.w	$0180,$0faf,$0180,$0fba
	dc.w	$0180,$0fbb,$0180,$0fbc
	dc.w	$0180,$0fbb,$0180,$0fbc
	dc.w	$0180,$0faf,$0180,$0fba
	dc.w	$0180,$0fad,$0180,$0fae
	dc.w	$0180,$0fab,$0180,$0fac
	dc.w	$0180,$0eaa,$0180,$0faa
	dc.w	$0180,$0caa,$0180,$0daa
	dc.w	$0180,$0aaa,$0180,$0baa
	dc.w	$0180,$08aa,$0180,$09aa
	dc.w	$0180,$06aa,$0180,$07aa
	dc.w	$0180,$04aa,$0180,$05aa
	dc.w	$0180,$03aa,$0180,$0000

;-
	dc.w	$8301,$fffe
	dc.w	$0180,$0000,$0182,$0bbb	;fuer ball
	dc.w	$0184,$00f0,$0186,$00f0	;
	dc.w	$0188,$00f0,$018a,$0999	;fuer ball
	dc.w	$018c,$00f0,$018e,$00f0	;

	dc.w	$0190,$00f0,$0192,$00f0
	dc.w	$0194,$00f0,$0196,$00f0	;farbe pen
	dc.w	$0198,$00f0,$019a,$00f0
	dc.w	$019c,$00f0,$019e,$00f0

	dc.w	$01a0,$0777,$01a2,$0666	;fuer ball
	dc.w	$01a4,$00f0,$01a6,$00f0
	dc.w	$01a8,$0555,$01aa,$0444	;fuer ball
	dc.w	$01ac,$00f0,$01ae,$00f0	;

	dc.w	$01b0,$00f0,$01b2,$00f0	;
	dc.w	$01b4,$00f0,$01b6,$00f0	;
	dc.w	$01b8,$00f0,$01ba,$00f0	;
	dc.w	$01bc,$00f0,$01be,$00f0	;

	dc.w	$8401,$fffe
;-

bpl1:	dc.w	$00e0,c/$10000,$00e2,c&$ffff+$2800
	dc.w	$00e4,c/$10000,$00e6,c&$ffff+$0000
bpl2:	dc.w	$00e8,c/$10000,$00ea,c&$ffff+$2828
	dc.w	$00ec,c/$10000,$00ee,c&$ffff+$0000
bpl3:	dc.w	$00f0,c/$10000,$00f2,c&$ffff+$2850

	dc.w	$0108,$0050,$010a,$0000
	dc.w	$0100,$5200

;-
	dc.w	$ff3b,$fffe
	dc.w	$0180,$04aa,$0180,$05aa
	dc.w	$0180,$06aa,$0180,$07aa
	dc.w	$0180,$08aa,$0180,$09aa
	dc.w	$0180,$0aaa,$0180,$0baa
	dc.w	$0180,$0caa,$0180,$0daa
	dc.w	$0180,$0eaa,$0180,$0faa
	dc.w	$0180,$0fab,$0180,$0fac
	dc.w	$0180,$0fad,$0180,$0fae
	dc.w	$0180,$0faf,$0180,$0fba
	dc.w	$0180,$0fbb,$0180,$0fbc
	dc.w	$0180,$0fbb,$0180,$0fbc
	dc.w	$0180,$0faf,$0180,$0fba
	dc.w	$0180,$0fad,$0180,$0fae
	dc.w	$0180,$0fab,$0180,$0fac
	dc.w	$0180,$0eaa,$0180,$0faa
	dc.w	$0180,$0caa,$0180,$0daa
	dc.w	$0180,$0aaa,$0180,$0baa
	dc.w	$0180,$08aa,$0180,$09aa
	dc.w	$0180,$06aa,$0180,$07aa
	dc.w	$0180,$04aa,$0180,$05aa
	dc.w	$0180,$03aa,$0180,$0005

	dc.w	$ffff,$fffe

;-----------------------------------------------------------------------------
;	offset and text
;-----------------------------------------------------------------------------

offset:
	;         [ ]    [!]    ["]    [#]    [$]    [%]    [&]    [']    [(]
	dc.l	a+$000,a+$001,a+$002,a+$003,a+$004,a+$005,a+$006,a+$007,a+$008
	;         [)]    [*]    [+]    [,]    [-]    [.]    [/]    [0]    [1]
	dc.l	a+$009,a+$00a,a+$00b,a+$00c,a+$00d,a+$00e,a+$00f,a+$010,a+$011
	;         [2]    [3]    [4]    [5]    [6]    [7]    [8]    [9]    [:]
	dc.l	a+$012,a+$013,a+$014,a+$015,a+$016,a+$017,a+$018,a+$019,a+$01a
	;         [;]    [<]    [=]    [>]    [?]    [@]    [A]    [B]    [C]
	dc.l	a+$01b,a+$01c,a+$01d,a+$01e,a+$01f,a+$020,a+$021,a+$022,a+$023
	;         [D]    [E]    [F]    [G]    [H]    [I]    [J]    [K]    [L]
	dc.l	a+$024,a+$025,a+$026,a+$027,a+$140,a+$141,a+$142,a+$143,a+$144
	;         [M]    [N]    [O]    [P]    [Q]    [R]    [S]    [T]    [U]
	dc.l	a+$145,a+$146,a+$147,a+$148,a+$149,a+$14a,a+$14b,a+$14c,a+$14d
	;         [V]    [W]    [X]    [Y]    [Z]    [[]    [\]    []]    [^]
	dc.l	a+$14e,a+$14f,a+$150,a+$151,a+$152,a+$153,a+$154,a+$155,a+$156
	;         [_] 
	dc.l	a+$157

;-------------------------------------------------------------------------
;		$10=set all to next line ; $11=set screen address
;		$12=clearscreen and set new ; $13=set 5 seconds
;		$14=set 10seconds ; $15=set 15 seconds ; $16=wait seconds
;		$1f=restart text
;-------------------------------------------------------------------------

text:
;		-1234567890123456789012345678901234567890-
	dc.b	"",$10	;01
	dc.b	"",$10	;02
	dc.b	"",$10	;03
	dc.b	"    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>    ",$10	;04
	dc.b	"    >                              >    ",$10	;05
	dc.b	"    >            THIS              >    ",$10	;06
	dc.b	"    >          CRACKTRO            >    ",$10	;07
	dc.b	"    >       HAS BEEN CODED         >    ",$10	;08
	dc.b	"    >             BY               >    ",$10	;09
	dc.b	"    >     - GALAXY - DYTEC -       >    ",$10	;10
	dc.b	"    >                              >    ",$10	;11
	dc.b	"    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>    ",$10	;12
	dc.b	"",$10	;13
	dc.b	"",$10	;14
	dc.b	"",$10	;15
	dc.b	$15,$16
	dc.b	$11,$12

	dc.b	$1f
	even
