;org	$30000
;load	$30000
**********************
*** Bootchooser by ***
*** BTC of SARGON! ***
**********************
s:
	clr.w	$100
	clr.l	d0
	movem.l	a0-a6/d0-d7,-(sp)
	move.l	$80,oldirq
	move.l	#newjmp,$80
	trap	#0
	move.l	#oldirq,$80
	movem.l	(sp)+,a0-a6/d0-d7
	rts
newjmp:
	bsr	writecop1
	bsr	start_muzak
	bsr	makeline
	bset	#1,$bfe001
	lea	$dff000,a6
	move.w	2(a6),help
	move.w	28(a6),help+2
	move.w	#$3fff,154(a6)
	move.w	#$87e0,150(a6)
	move.l	#newclist,128(a6)
	move.w	136(a6),d0
	clr.w	$dff1bc
maus:
	cmp.b	#$ff,$dff006
	bne	maus
wait30:
	cmp.b	#$30,$dff006
	bne	wait30
	bsr	scrollcolors
	bsr	writecol1
	bsr	check
	bsr	replay_muzak
	btst	#6,$bfe001
	bne	maus
	move.l	$4,a6
	lea	gfxbase,a1
	jsr	-408(a6)
	lea	$dff000,a6
	move.l	d0,a0
	move.w	#$7fff,150(a6)
	move.l	38(a0),128(a6)
	move.w	136(a6),d0
	or.l	#$80008000,help
	move.w	help,150(a6)
	move.w	help+2,154(a6)
	bclr	#1,$bfe001
	move.w	#$2700,SR
	bsr	stop_muzak
	rte
Help:
	dc.l	0
gfxbase:
	dc.b	"graphics.library",0,0
oldirq:
	dc.l	0

getchar:
	move.w	#7,d0
loop1:
	move.b	(a0)+,(a1)
	add.l	#40,a1
	dbf	d0,loop1
	rts

makeline:
	lea	$50000,a1
	move.w	#18,d4
	lea	text,a2
oneline:
	move.w	#39,d1
noline:
	lea	$70000,a0
	lea	ascii,a3
	move.l	a3,a4
	move.b	(a2)+,d0
cont:
	cmp.b	(a3)+,d0
	bne	cont
	sub.l	#1,a3
	sub.l	a4,a3
	move.l	a3,d3
	lsl.l	#3,d3
	add.l	d3,a0
	bsr	getchar
	sub.l	#[8*40]-1,a1
	dbf	d1,noline
	add.l	#[8*40],a1
	dbf	d4,oneline
	rts

writecop1:
	lea	coolone,a0
	move.l	#$683ffffe,d0
	move.l	#$01820f00,d1
	move.w	#7,d4

nextline:
	move.w	#39,d2
	move.l	d0,(a0)+
loop2:
	move.l	d1,(a0)+
	sub.l	#2,d1
	dbf	d2,loop2
	move.l	#$01820000,(a0)+
	add.l	#$01000000,d0
	dbf	d4,nextline
	rts

writecol1:
	lea	coolone+6,a1
	lea	colors,a0
	move.w	#7,d1
nextcline:
	move.l	a0,a2
	move.w	#39,d0
newone:
	move.w	(a2)+,(a1)
	add.l	#4,a1
	dbf	d0,newone
	add.l	#8,a1
	add.l	#2,a0
	dbf	d1,nextcline
	rts

scrollcolors:
	lea	colors,a0
	lea	ecolors,a1
	move.w	(a0),d0
wait2:
	move.w	2(a0),(a0)
	add.l	#2,a0
	cmp.l	a0,a1
	bne	wait2
	move.w	d0,ecolors-2
	rts

check:
	move.b	$dff00a,d0
	move.b	btc4,d1
	cmp.b	d0,d1
	beq	b180
	bge	b18a
	ble	b1de
b180:
	move.b	d0,btc4
	clr.l	d0
b188:
	rts
b18a:
	move.w	btca,d3
	add.w	#1,btc6
	cmp.w	btc6,d3
	bne	b1da
	clr.w	btc6
	clr.w	btc8
	clr.w	d5
	move.w	#$100,d4
	cmp.w	d5,d4
	beq	b1da
	tst.w	$100
	beq	b180
	sub.w	#1,$100
	sub.w	#$0900,coolone
	sub.w	#$0900,coolone+168
	sub.w	#$0900,coolone+[2*168]
	sub.w	#$0900,coolone+[3*168]
	sub.w	#$0900,coolone+[4*168]
	sub.w	#$0900,coolone+[5*168]
	sub.w	#$0900,coolone+[6*168]
	sub.w	#$0900,coolone+[7*168]
b1da:
	bra	b180
b1de:
	move.w	btca,d2
	add.w	#1,btc8
	cmp.w	btc8,d2
	bne	b230
	clr.w	btc8
	clr.w	btc6
	move.w	btcc,d5
	move.w	#$100,d4
	cmp.w	d4,d5
	beq	b230
	cmp.w	#9,$100
	beq	b180
	add.w	#1,$100
	add.w	#$0900,coolone+[0*168]
	add.w	#$0900,coolone+[1*168]
	add.w	#$0900,coolone+[2*168]
	add.w	#$0900,coolone+[3*168]
	add.w	#$0900,coolone+[4*168]
	add.w	#$0900,coolone+[5*168]
	add.w	#$0900,coolone+[6*168]
	add.w	#$0900,coolone+[7*168]
b230:
	bra	b180
	rts

start_muzak:
	move.l	#data,muzakoffset	;** get offset

init0:	move.l	muzakoffset,a0		;** get highest used pattern
	add.l	#472,a0
	move.l	#$80,d0
	clr.l	d1
init1:	move.l	d1,d2
	subq.w	#1,d0
init2:	move.b	(a0)+,d1
	cmp.b	d2,d1
	bgt.s	init1
	dbf	d0,init2
	addq.b	#1,d2

init3:	move.l	muzakoffset,a0		;** calc samplepointers
	lea	pointers,a1
	mulu	#1024,d2
	add.l	#600,d2
	add.l	a0,d2
	move.l	#15-1,d0
init4:	move.l	d2,(a1)+
	clr.l	d1
	move.w	42(a0),d1
	lsl.l	#1,d1
	add.l	d1,d2
	add.l	#30,a0
	dbf	d0,init4

init5:	move.w	#$0,$dff0a8		;** clear used values
	move.w	#$0,$dff0b8
	move.w	#$0,$dff0c8
	move.w	#$0,$dff0d8
	clr.w	timpos
	clr.l	trkpos
	clr.l	patpos

init6:	move.l	muzakoffset,a0		;** initialize timer irq
	move.b	470(a0),numpat+1	;number of patterns
	move.l	#240,d0
	sub.b	471(a0),d0
	mulu	#122,d0
	move.b	#$0,$bfde00
	move.b	d0,$bfd400
	lsr.w	#8,d0
	move.b	d0,$bfd500
	rts

stop_muzak:
	move.w	#$0,$dff0a8
	move.w	#$0,$dff0b8
	move.w	#$0,$dff0c8
	move.w	#$0,$dff0d8
	move.w	#$f,$dff096
	rts


replay_muzak:
	addq.w	#1,timpos
speed:	cmp.w	#6,timpos
	beq	replaystep

chaneleffects:				;** seek effects
	lea	datach0,a6
	tst.b	3(a6)
	beq.s	ceff1
	lea	$dff0a0,a5
	bsr.s	ceff5
ceff1:	lea	datach1,a6
	tst.b	3(a6)
	beq.s	ceff2
	lea	$dff0b0,a5
	bsr.s	ceff5
ceff2:	lea	datach2,a6
	tst.b	3(a6)
	beq.s	ceff3
	lea	$dff0c0,a5
	bsr.s	ceff5
ceff3:	lea	datach3,a6
	tst.b	3(a6)
	beq.s	ceff4
	lea	$dff0d0,a5
	bsr.s	ceff5
ceff4:	rts

ceff5:	move.b	2(a6),d0		;room for some more
	and.b	#$0f,d0			;implementations below
	tst.b	d0
	beq.s	arpreggiato
	cmp.b	#1,d0
	beq	pitchup
	cmp.b	#2,d0
	beq	pitchdown
	cmp.b	#12,d0
	beq	setvol
	cmp.b	#14,d0
	beq	setfilt
	cmp.b	#15,d0
	beq	setspeed
	rts

arpreggiato:				;** spread by time
	cmp.w	#1,timpos
	beq.s	arp1
	cmp.w	#2,timpos
	beq.s	arp2
	cmp.w	#3,timpos
	beq.s	arp3
	cmp.w	#4,timpos
	beq.s	arp1
	cmp.w	#5,timpos
	beq.s	arp2
	rts

arp1:	clr.l	d0			;** get higher note-values
	move.b	3(a6),d0		;   or play original
	lsr.b	#4,d0
	bra.s	arp4
arp2:	clr.l	d0
	move.b	3(a6),d0
	and.b	#$0f,d0
	bra.s	arp4
arp3:	move.w	16(a6),d2
	bra.s	arp6
arp4:	lsl.w	#1,d0
	clr.l	d1
	move.w	16(a6),d1
	lea	notetable,a0
arp5:	move.w	(a0,d0.w),d2
	cmp.w	(a0),d1
	beq.s	arp6
	addq.l	#2,a0
	bra.s	arp5
arp6:	move.w	d2,6(a5)
	rts

pitchdown:
	bsr	newrou
	clr.l	d0
	move.b	3(a6),d0
	and.b	#$0f,d0
	add.w	d0,(a4)
	cmp.w	#$358,(a4)
	bmi.s	ok1
	move.w	#$358,(a4)
ok1:	move.w	(a4),6(a5)
	rts

pitchup:bsr	newrou
	clr.l	d0
	move.b	3(a6),d0
	and.b	#$0f,d0
	sub.w	d0,(a4)
	cmp.w	#$71,(a4)
	bpl.s	ok2
	move.w	#$71,(a4)
ok2:	move.w	(a4),6(a5)
	rts

setvol:	move.b	3(a6),8(a5)
	rts

setfilt:move.b	3(a6),d0
	and.b	#$01,d0
	asl.b	#$01,d0
	and.b	#$fd,$bfe001
	or.b	d0,$bfe001
	rts

setspeed:
	clr.l	d0
	move.b	3(a6),d0
	and.b	#$0f,d0
	move.w	d0,speed+2
	rts

newrou:	cmp.l	#datach0,a6
	bne.s	next1
	lea	voi1,a4
	rts
next1:	cmp.l	#datach1,a6
	bne.s	next2
	lea	voi2,a4
	rts
next2:	cmp.l	#datach2,a6
	bne.s	next3
	lea	voi3,a4
	rts
next3:	lea	voi4,a4
	rts

replaystep:				;** work next pattern-step
	clr.w	timpos
	move.l	muzakoffset,a0
	move.l	a0,a3
	add.l	#12,a3			;ptr to soundprefs
	move.l	a0,a2
	add.l	#472,a2			;ptr to pattern-table
	add.l	#600,a0			;ptr to first pattern
	clr.l	d1
	move.l	trkpos,d0		;get ptr to current pattern
	move.b	(a2,d0),d1
	mulu	#1024,d1
	add.l	patpos,d1		;get ptr to current step
	clr.w	enbits
	lea	$dff0a0,a5		;chanel 0
	lea	datach0,a6
	bsr	chanelhandler
	lea	$dff0b0,a5		;chanel 1
	lea	datach1,a6
	bsr	chanelhandler
	lea	$dff0c0,a5		;chanel 2
	lea	datach2,a6
	bsr	chanelhandler
	lea	$dff0d0,a5		;chanel 3
	lea	datach3,a6
	bsr	chanelhandler
	move.l	#400,d0			;** wait a while and set len
rep1:	dbf	d0,rep1			;   of oneshot to 1 word
	move.l	#$8000,d0
	or.w	enbits,d0
	move.w	d0,$dff096
	cmp.w	#1,datach0+14
	bne.s	rep2
	clr.w	datach0+14
	move.w	#1,$dff0a4
rep2:	cmp.w	#1,datach1+14
	bne.s	rep3
	clr.w	datach1+14
	move.w	#1,$dff0b4
rep3:	cmp.w	#1,datach2+14
	bne.s	rep4
	clr.w	datach2+14
	move.w	#1,$dff0c4
rep4:	cmp.w	#1,datach3+14
	bne.s	rep5
	clr.w	datach3+14
	move.w	#1,$dff0d4

rep5:	add.l	#16,patpos		;next step
	cmp.l	#64*16,patpos		;pattern finished ?
	bne	rep6
	clr.l	patpos
	addq.l	#1,trkpos		;next pattern in table
	clr.l	d0
	move.w	numpat,d0
	cmp.l	trkpos,d0		;song finished ?
	bne	rep6
	clr.l	trkpos
rep6:	rts

chanelhandler:
	move.l	(a0,d1.l),(a6)		;get period & action-word
	addq.l	#4,d1			;point to next chanel
	clr.l	d2
	move.b	2(a6),d2		;get nibble for soundnumber
	lsr.b	#4,d2
	beq.s	chan2			;no soundchange !
	move.l	d2,d4			;** calc ptr to sample
	lsl.l	#2,d2
	mulu	#30,d4
	lea	pointers-4,a1
	move.l	(a1,d2.l),4(a6)		;store sample-address
	move.w	(a3,d4.l),8(a6)		;store sample-len in words
	move.w	2(a3,d4.l),18(a6)	;store sample-volume

	move.l	d0,-(a7)
	move.b	2(a6),d0
	and.b	#$0f,d0
	cmp.b	#$0c,d0
	bne.s	ok3
	move.b	3(a6),8(a5)
	bra.s	ok4
ok3:	move.w	2(a3,d4.l),8(a5)	;change chanel-volume
ok4:	move.l	(a7)+,d0

	clr.l	d3
	move.w	4(a3,d4),d3		;** calc repeatstart
	add.l	4(a6),d3
	move.l	d3,10(a6)		;store repeatstart
	move.w	6(a3,d4),14(a6)		;store repeatlength
	cmp.w	#1,14(a6)
	beq.s	chan2			;no sustainsound !
	move.l	10(a6),4(a6)		;repstart  = sndstart
	move.w	6(a3,d4),8(a6)		;replength = sndlength
chan2:	cmp.w	#0,(a6)
	beq.s	chan4			;no new note set !
	move.w	22(a6),$dff096		;clear dma
	cmp.w	#0,14(a6)
	bne.s	chan3			;no oneshot-sample
	move.w	#1,14(a6)		;allow resume (later)
chan3:	bsr	newrou
	move.w	(a6),(a4)
	move.w	(a6),16(a6)		;save note for effect
	move.l	4(a6),0(a5)		;set samplestart
	move.w	8(a6),4(a5)		;set samplelength
	move.w	(a6),6(a5)		;set period
	move.w	22(a6),d0
	or.w	d0,enbits		;store dma-bit
	move.w	18(a6),20(a6)		;volume trigger
chan4:	rts

datach0:	dc.w	0,0,0,0,0,0,0,0,0,0,0,1
datach1:	dc.w	0,0,0,0,0,0,0,0,0,0,0,2
datach2:	dc.w	0,0,0,0,0,0,0,0,0,0,0,4
datach3:	dc.w	0,0,0,0,0,0,0,0,0,0,0,8
voi1:		dc.w	0
voi2:		dc.w	0
voi3:		dc.w	0
voi4:		dc.w	0
pointers:	dc.l	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
notetable:	dc.w	856,808,762,720,678,640,604,570
		dc.w	538,508,480,453,428,404,381,360
		dc.w	339,320,302,285,269,254,240,226  
		dc.w	214,202,190,180,170,160,151,143
		dc.w	135,127,120,113,000
muzakoffset:	dc.l	0
lev6save:	dc.l	0
trkpos:		dc.l	0
patpos:		dc.l	0
numpat:		dc.w	0
enbits:		dc.w	0
timpos:		dc.w	0
data = $33000
newclist:
	dc.w	$008e,$2c81,$0090,$2cc1,$0092,$0038,$0094,$00d0
	dc.w	$0102,$0000,$0104,$0000,$0108,$0000,$010a,$0000
	dc.w	$120,0,$122,0,$124,0,$126,0,$128,0,$12a,0,$12c,0,$12e,0
	dc.w	$130,0,$132,0,$134,0,$136,0,$138,0,$13a,0,$13c,0,$13e,0
	dc.w	$192,$00

	dc.w	$0100,$0200,$0180,$0000
	dc.w	$2c11,$fffe,$0180,$0444
	dc.w	$2d11,$fffe,$0180,$0666
	dc.w	$2e11,$fffe,$0180,$0777
	dc.w	$3011,$fffe,$0180,$0888
	dc.w	$3111,$fffe,$0180,$0999
	dc.w	$3211,$fffe,$0180,$0aaa

	dc.w	$3611,$fffe
	dc.w	$00e0,$0005,$00e2,$0000,$0100,$1200,$0108,$ffd8,$182,$eee
	dc.w	$3811,$fffe,$108,0
	dc.w	$3911,$fffe,$108,$ffd8
	dc.w	$00e4,$0005,$00e6,$0000,$0100,$2400,$102,$20,$010a,$ffd8
	dc.w	$3b11,$fffe,$108,0,$10a,$0
	dc.w	$3c11,$fffe,$108,$ffd8,$10a,$ffd8
	dc.w	$3e11,$fffe,$108,0,$10a,0
	dc.w	$3f11,$fffe,$108,$ffd8,$10a,$ffd8
	dc.w	$4111,$fffe,$108,0,$10a,0
	dc.w	$4211,$fffe,$108,$ffd8,$10a,$ffd8
	dc.w	$4411,$fffe,$108,0,$10a,0
	dc.w	$4511,$fffe,$108,$ffd8,$10a,$ffd8
	dc.w	$4711,$fffe,$108,0,$10a,0
	dc.w	$4811,$fffe,$108,$ffd8,$10a,$ffd8
	dc.w	$4a11,$fffe,$108,0,$10a,0
	dc.w	$4b11,$fffe,$10a,$ffd8
	dc.w	$4d11,$fffe,$10a,0

	dc.w	$4f11,$fffe,$0100,$0200
	dc.w	$5011,$fffe,$0180,$0999
	dc.w	$5111,$fffe,$0180,$0888
	dc.w	$5211,$fffe,$0180,$0777
	dc.w	$5311,$fffe,$0180,$0666
	dc.w	$5411,$fffe,$0180,$0444
	dc.w	$5511,$fffe,$0180,$0000,$0102,$0,$108,0,$182,0


	dc.w	$6011,$fffe,$0180,$0444
	dc.w	$6111,$fffe,$0180,$0666
	dc.w	$6211,$fffe,$0180,$0777
	dc.w	$6311,$fffe,$0180,$0888
	dc.w	$6411,$fffe,$0180,$0999
	dc.w	$6511,$fffe,$0180,$0aaa
	dc.w	$6611,$fffe,$0182,$0000
	dc.w	$6811,$fffe,$0100,$1200
	dc.w	$00e0,$0005,$00e2,$0000+[18*40]
coolone:
	blk.l	[8*42],0

	dc.w	$ffe1,$fffe,$0190,$0000
	dc.w	$0111,$fffe,$0180,$0999
	dc.w	$0211,$fffe,$0180,$0888
	dc.w	$0311,$fffe,$0180,$0777
	dc.w	$0411,$fffe,$0180,$0666
	dc.w	$0511,$fffe,$0180,$0444
	dc.w	$0611,$fffe,$0180,$0000
	dc.w	$ffff,$fffe
textzeiger:
	dc.l	text
text:
	dc.b	"        sargons^s copy disk v1.0        "
	dc.b	"                                        "
	dc.b	"x-copy                                  "
	dc.b	"fast lightning                          "
	dc.b	"diskmaster v1.3                         "
	dc.b	"a-copy                                  "
	dc.b	"main menu                               "
	dc.b	"smart disk                              "
	dc.b	"mastercoperer                           "
	dc.b	"cli-mate                                "
	dc.b	"fast^em                                 "
	dc.b	"burstnibbler                            "
	dc.b	"                                        "
	dc.b	" this cool bootselector was written by  "
	dc.b	"     btc , yankee and fog of sargon     "
	dc.b	"                                        "
	dc.b	"contact sargon at : plk 073976 c        "
	dc.b	"                    5060 berg.gladbach2 "
	dc.b	"                    w.germany           "
	dc.b	0
ascii:
	dc.b	"abcdefghijklmnopqrstuvwxyz0123456789:^/?.,!-+ ",0
colors:
	dc.w	$100,$200,$300,$400,$500,$600,$700,$800,$900,$a00,$b00
	dc.w	$c00,$d00,$e00,$f00,$f10,$f20,$f30,$f40,$f50,$f60,$f70
	dc.w	$f80,$f90,$fa0,$fb0,$fc0,$fd0,$fe0,$ff0,$ef0,$df0,$cf0
	dc.w	$bf0,$af0,$9f0,$8f0,$7f0,$6f0,$5f0,$4f0,$3f0,$2f0,$1f0;44
	dc.w	$f0,$f1,$f2,$f3,$f4,$f5,$f6,$f7,$f8,$f9,$fa,$fb,$fc,$fd
	dc.w	$fe,$ff,$ef,$df,$cf,$bf,$af,$9f,$8f,$7f,$6f,$5f,$4f,$3f
	dc.w	$2f,$1f,$0f,$0e,$d,$c,$b,$a,9,8,7,6,5,4,3,2,1	;89
ecolors:
btc4:
	dc.b	$ac,0
btc6:
	dc.b	0,0
btc8:
	dc.b	0,0
btca:
	dc.b	0,3
btcc:
	dc.b	0,3
helper:
	dc.w	0
