save=1
	if	save=1
	AUTO	e\

DosCheck="This"
org	$7f000
load	$7f000

c:	lea	DiskStart+8+$25800,a0
	move.l	#$444f5300,d0	;"DOS",0
	move.w	#$fd,d1
c_0:	add.l	(a0)+,d0
	bcc.s	c_1
	addq.l	#1,d0
c_1:	dbf	d1,c_0
	not.l	d0
	move.l	#DosCheck,d1
	sub.l	d1,d0
	bcc.s	c_2
	subq.l	#1,d0
c_2:	move.l	#DosCheck,DiskStart+4+$25800	;dos-checksum
	move.l	#ol,d1
	and.l	#$2,d1
	beq.s	c_3
	swap	d0
c_3:	move.l	d0,ol+$25800	;place to insert mychecksum
	rts

	Auto	jc\
	Auto	wt\DiskStart+$25800\0\[[exend-DiskStart]/$1600]+1

	endc

	ORG	$a800
	LOAD	$30000
TrackShit=$5c000	;$3400

>extern "sin255",sin255+$25800
>extern "flax.raw",flax+$25800
>extern "blaj",blaj+$25800
>extern "umb1spr.bin",umbspr+$25800
>extern "finalexplosion",exp+$25800
>extern "swimlevelclear",efter+$25800
>extern "unobrushr",uno+$25800
>extern "BlomBrushR",Anim+$25800
>extern "mod.wait2",mt_data+$25800
>extern "3pR",Pr3+$25800
>extern "5pR",Pr5+$25800
>extern "Crun",Crun+$25800

pl_s1=$60000	;$5d80*2=$bb00
blajlen=6336
explen=13240
efterlen=45960

;x_hast,y_hast,X_pos,y_pos
AntalDelar=256
pl_dat:	blk.l	4*AntalDelar,0
mulu88:	blk.w	$111,0

Start:

DiskStart:
	dc.b "DOS",0
	dc.b "This is "
	bra.s	s	;="`H"
	dc.b "is Master's Noise' - a musicdisk by Mahoney & Kaktus"
	dc.b " finished Oct. 1991!"

S:	move.l	$04.w,a6
	move.w	#2,28(a1)
	move.l	#Start,40(a1)	;dest
	clr.l	44(a1)		;diskpos
	move.l	#$2c00,36(a1)	;length
	jsr	-456(a6)

	clr.l	0.w
	move.l	$04.w,a6
	moveq	#2,d1
	jsr	-216(a6)
	cmp.l	#$80000,d0
	blt.s	.kollafast
	move.l	#$80000,0.w
	bra.s	.goon
.kollafast:
	tst.l	78(a6)
	beq.s	.goon
	move.l	#$c00000,0.w

.goon:	jmp	st

ol:	dc.l	0

st:	lea	$7fff0,a7
	lea	$dff000,A6
	move.w	#$7fff,$9a(a6)
;	move.w	#$c000,$9a(a6)
	move.w	#$3fff,$9c(a6)
	move.w	#$03df,$96(a6)
	lea	super(pc),a0
	move.l	a0,$80.w
	trap	#0
	lea	$7fff0,a7

	lea	$dff000,A6
.Sync:	move.l	$04(a6),d0
	and.l	#$1ff00,d0
	cmp.l	#$13600,d0
	bne.s	.Sync
	clr.w	$dff180

	bsr	rnd_init
	bsr	pl_init
	bsr	u_init

	lea	$dff000,a6
	MOVE.L	#COP,$80(a6)
Sync:	move.l	$04(a6),d0
	and.l	#$1ff00,d0
	cmp.l	#$13000,d0
	bne.s	Sync
	move.w	#$83e0,$96(a6)
	bsr	SetLv2Irq

	bsr	Loader
	bsr	Decrunch
	jmp	$3a046

super:	move.w	#$2000,(a7)
	rte

;----------------------------------------------------------------

loader:	lea	$dff000,a6
	move.w	#$8210,$96(a6)	;diskdma on!
	moveq	#%0001,d0	;select drive #0
	lea	floppystatus(pc),a0
	lea	motorstatus(pc),a1
	moveq	#-1,d1		;$ffffffff -> d1
	lsl.w	#3,d0		;shift selectbit to right position
	eor.b	d0,d1		;selectbit must be zero
	move.b	d1,(a0)		;save byte ->floppystatus.b
	eori.b	#$80,d1		;clear DSKMOTOR-bit
	move.b	d1,(a1)		;save byte ->motorstatus.b

	move.b	#$7f,$bfd100	;Bits 0-6 HIGH/Bit 7 LOW
	nop
	nop
	move.b	motorstatus(pc),d0
	move.b	d0,$bfd100	;DSKMOTOR and DSKSELx LOW

.ready:	btst	#5,$bfe001	;wait for DRIVEREADY
	bne.s	.ready

	lea	$bfd100,a0	;move head to track zero
	move.b	Floppystatus(pc),d1
	bset	#2,d1
	bset	#1,d1
	move.b	d1,Floppystatus
	clr.w	CurrTrack
	clr.w	Track
.Headzero:
	btst	#4,$bfe001		;test if zero
	beq.s	.zero1
	bsr	Step
	bra.s	.Headzero
.zero1:	bclr	#1,Floppystatus
	bsr	Step
	bset	#1,Floppystatus
	bsr	Step


	move.l	#Destination,load_dest
	move.w	#2,track
	move.w	#LoadLength,trackct


	lea	$dff000,a6
	move.w	#$8210,$96(a6)	;diskdma on!
	move.b	#$7f,$bfd100	;drivemotor on
	nop
	nop
	move.b	motorstatus(pc),d0
	move.b	d0,$bfd100	;DSKMOTOR and DSKSELx LOW
.ryady:	btst	#5,$bfe001	;wait for DRIVEREADY
	bne.s	.ryady

;Init_Read:
	clr.w	$24(a6)		;DSKLEN->forbid diskdma and writing
	move.w	#$4489,$7e(a6)	;set standard SYNC
	move.w	#$7f00,$9e(a6)	;clear ADKCON
	move.w	#$9500,$9e(a6)	;set required bits
	move.w	#$0002,$9c(a6)	;clear DSKBLK bit


Load_tracks:
	move.w	track(pc),d0	;move head to starttrack
	bsr.l	head_pos
	btst	#2,$bfe001	;test_disk
	beq.w	LoError

;-----------Read_Track
	clr.w	$24(a6)		;DSKLEN->forbid diskdma
	lea	TrackShit,a0
	move.l	a0,$20(a6)	;set DSKPTH and DSKPTL
	move.w	#$9a00,$24(a6)	;enable diskdma and set amount of
	move.w	#$9a00,$24(a6)	;words+2 to transfer.
.Wait_Dma:
	btst	#1,$1f(a6)	;DSKBLK=0 ?
	beq.s	.Wait_Dma	;yeah=> wait
	clr.w	$24(a6)		;forbid writing
	move.w	#$0002,$9c(a6)	;clear DSKBLK

;-----------Decode track
	move.l	Load_Dest(pc),a0		;pointer to decodebuffer
	lea	TrackShit,a1	;pointer to MFMbuffer
	moveq	#11-1,d5		;decode 11 blocks (-1 coz dbf)
	move.l	#$55555555,d3		;filter for tactbits

decode_all_blocks:
	cmpi.w	#$4489,(a1)+		;1st sync-word found ?
	bne.s	decode_all_blocks	;no=> go on searching
sync_found:
	cmpi.w	#$4489,(a1)		;2. sync-word found ?
	bne.s	syncs_ok		;no=> all syncs skipped
	addq.w	#2,a1			;yes=>
	bra.s	sync_found		;search for remaining syncs
syncs_ok:				;decode infoblock
	move.l	(a1)+,d0		;odd bits
	move.l	(a1)+,d1		;even bits
	and.l	d3,d0
	and.l	d3,d1
	add.l	d0,d0
	or.l	d1,d0

	swap	d0
	andi.w	#$ff00,d0		;mask format-sign (must be $ff)
	cmpi.w	#$ff00,d0		;right value?
	bne.s	Loerror		;no==>ERROR!
	swap	d0

	andi.w	#$ff00,d0		;mask sector number*256
	add.w	d0,d0			;d0=d0*2 (=sector number*512)
	move.l	a0,a2			;address of decodebuffer ->a2
	adda.w	d0,a2			;calc. correct destination

	adda.w	#40,a1			;address of checksum ->a1
	move.l	(a1)+,d4		;decode checksum
	move.l	(a1)+,d1
	and.l	d3,d4
	and.l	d3,d1
	add.l	d4,d4
	or.l	d1,d4			;store checksum ->d4

	moveq	#128-1,d6		;decode 128*2 longs to 512 bytes 
	moveq	#0,d2			;clear datachecksum
decodeblock:				;decode datablock
	move.l	512(a1),d1		;even bits
	move.l	(a1)+,d0		;odd bits
	eor.l	d0,d2			;calc checksum
	eor.l	d1,d2			;dito
	and.l	d3,d0			;decode longword
	and.l	d3,d1
	add.l	d0,d0
	or.l	d1,d0
	move.l	d0,(a2)+		;store longword in buffer
	dbf	d6,decodeblock		;decode next longword
	and.l	d3,d2			;remove tactbits
	cmp.l	d4,d2			;checksum correct ?
	bne.s	Loerror		;no=>ERROR!
	adda.w	#512,a1			;reach next block
	dbf	d5,decode_all_blocks
	adda.w	#$1600,a0		;bufferadr.+ 1track (5632bytes)
	move.l	a0,Load_Dest		;store new address


load_ok:addq.w	#1,track	;next track (add/sub=increase/decrease)
	subq.w	#1,trackct	;decrease trackcounter
	bne.w	load_tracks
	bra.s	EndLoad

Loerror:
	moveq	#-1,d7
.g:	move.w	#$f00,$dff180
	dbf	d7,.g



EndLoad:
	move.b	#$ff,$bfd100	;Bits 0-7 HIGH
	nop
	nop
	move.b	motorstatus(pc),d0
	ori.b	#$80,d0		;DSKMOTOR HIGH DSKSELx LOW
	move.b	d0,$bfd100
	rts

floppystatus:	dc.b	0
motorstatus:	dc.b	0
Load_Dest:	dc.l	$50000
track:		dc.w	0	;starttrack
trackct:	dc.w	0	;trackcounter
CurrTrack:	dc.w	0

step:	move.b	floppystatus(pc),d0
	move.b	d0,d1
	bclr	#0,d0		;clear DSKSTEP after setting it...STEP!
	move.b	d0,(a0)		;a0=$bfd100 (CIA-B PRB)
	nop			;wait a little
	nop
	move.b	d1,(a0)		;set DSKSTEP back to 1
	move.w	#$2000,d0
.je:	dbf	d0,.je
	rts


;This rut moves the r/w-head to a track with the number stored in d0.

Head_Pos:
	lea	$bfd100,a0
	move.w	Currtrack(pc),d2
	cmp.w	d2,d0			;oldtrack=newtrack ?
	beq.s	Head_end		;yes=>don't move head
	move.w	d0,d3
	move.b	Floppystatus(pc),d1
	bset	#2,d1			;select head 0 (lower side)
	btst	#0,d3			;track number even ?
	beq.s	Down_Right		;yes=>head 0 is the right one
	bclr	#2,d1			;no, select head 1 (upper side)
Down_Right:
	move.b	d1,Floppystatus
	move.b	d1,(a0)
	move.w	d3,CurrTrack		;save new track-number
	lsr.w	#1,d2			;d2=current cylinder
	lsr.w	#1,d3			;d3=new cylinder
	sub.w	d3,d2			;make difference
	bmi.s	Seek_in			;diff. negativ=> step in
	beq.s	Head_end
;	bra.s	Seek_out		;diff. positiv=> step out
Seek_out:
	bset	#1,d1			;step out
	move.b	d1,Floppystatus
	bra.s	Step_Ok
Seek_in:
	bclr	#1,d1			;step in
	move.b	d1,Floppystatus
	neg.w	d2			;make number positive
	bra.s	Step_Ok
HeadStep:
	bsr	Step			;call step-macro
Step_Ok:
	dbf	d2,HeadStep
Head_end:
rts:	rts	

;ญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญ

kottecou:	dc.w	0
kotteon:	dc.w	0

kottrut:tst.w	kotteon
	beq	rts

	cmp.b	#$e0,kotte+2
	beq	endrts
	add.b	#1,kotte+2
	rts

endrts:	clr.w	kotteon
	rts

;----------------------------------------------------------------

lets_cou:	dc.w	$0

lets_go:addq.w	#1,lets_cou
	move.w	lets_cou(pc),d0
	lea	$dff000,a6

	cmp.w	#$28,d0
	bne.s	.noinit

	move.w	#$f,$96(a6)
	move.l	#blaj,$a0(a6)
	move.w	#blajlen/2,$a4(a6)
	move.w	#$1fe,$a6(a6)
	move.w	#$40,$a8(a6)
	move.l	#blaj,$b0(a6)
	move.w	#blajlen/2,$b4(a6)
	move.w	#$1fe,$b6(a6)
	move.w	#$40,$b8(a6)

	move.w	#$8003,$96(a6)
	rts

.noinit:cmp.w	#$29,d0
	bne.s	.expr
	move.l	#dummysound,$a0(a6)
	move.w	#2,$a4(a6)
	move.l	#dummysound,$b0(a6)
	move.w	#2,$b4(a6)
	rts

.expr:	cmp.w	#$6e,d0
	bne.s	.noexp

	move.w	#$f,$96(a6)
	move.l	#exp,$a0(a6)
	move.l	#exp,$b0(a6)
	move.l	#exp,$c0(a6)
	move.l	#exp,$d0(a6)
	move.w	#explen/2,$a4(a6)
	move.w	#explen/2,$b4(a6)
	move.w	#explen/2,$c4(a6)
	move.w	#explen/2,$d4(a6)
	move.w	#$200,$a6(a6)
	move.w	#$350,$b6(a6)
	move.w	#$100,$c6(a6)
	move.w	#$180,$d6(a6)
	move.w	#$40,$a8(a6)
	move.w	#$40,$b8(a6)
	move.w	#$40,$c8(a6)
	move.w	#$40,$d8(a6)
	move.w	#$800f,$96(a6)
	rts

.noexp:	cmp.w	#$70,d0
	bne.s	.bl
	move.l	#dummysound,$a0(a6)
	move.l	#dummysound,$b0(a6)
	move.l	#dummysound,$d0(a6)
	move.l	#dummysound,$c0(a6)
	move.w	#2,$a4(a6)
	move.w	#2,$b4(a6)
	move.w	#2,$d4(a6)
	move.w	#2,$c4(a6)
	rts


.bl:	cmp.w	#$ce,d0
	bne.s	.nobl

	move.w	#$c,$96(a6)
;	move.l	#efter,$a0(a6)
;	move.w	#efterlen/2,$a4(a6)
;	move.w	#$190,$a6(a6)
;	move.w	#$40,$a8(a6)
;	move.l	#efter,$b0(a6)
;	move.w	#efterlen/2,$b4(a6)
;	move.w	#$180,$b6(a6)
;	move.w	#$40,$b8(a6)
	move.l	#efter,$c0(a6)
	move.w	#efterlen/2,$c4(a6)
	move.w	#$192,$c6(a6)
	move.w	#$40,$c8(a6)
	move.l	#efter,$d0(a6)
	move.w	#efterlen/2,$d4(a6)
	move.w	#$192,$d6(a6)
	move.w	#$40,$d8(a6)

	move.w	#$800c,$96(a6)
	rts

.nobl:
	cmp.w	#$d0,d0
	bne.s	.ble
	move.l	#dummysound,$a0(a6)
	move.l	#dummysound,$b0(a6)
	move.l	#dummysound,$d0(a6)
	move.l	#dummysound,$c0(a6)
	move.w	#2,$a4(a6)
	move.w	#2,$b4(a6)
	move.w	#2,$d4(a6)
	move.w	#2,$c4(a6)
.ble:
	cmp.w	#$168,d0
	bne.s	.ko
	bra	mt_init

.ko:	cmp.w	#$169,d0
	bge	mt_music
	rts

dummysound:	dc.l	0,0

;----------------------------------------------------------------

m_go:	dc.w	1
m_pos:	dc.l	$00000
m_cou:	dc.w	$40

m_rut:	or.b	#2,$bfe001
	tst.w	m_go
	beq.L	pl_rut

	cmp.w	#$a3,m_pos
	bne.s	m_goon

	clr.w	m_go
	move.l	#cop1,$dff080
	bra	pl_rut

m_goon:	add.b	#3,m_cou+1
	lea	sin255,a5
	move.w	m_cou(pc),d0
	move.b	(a5,d0.w),d0

	lsr.b	#$3,d0
	add.w	#4,d0
	move.w	d0,d2
	and.b	#$f,d0
	move.b	d0,d1
	asl.w	#4,d1
	add.w	d0,d1
	move.b	d1,m_sid+3
	lsr.w	#4,d2
	asl.w	#3,d2
	add.w	#$70,d2
	move.w	d2,m_sid2+2
	add.w	#$10,d2
	move.w	d2,m_sid2+6

	add.l	#$018000,m_pos
	moveq	#0,d0
	move.w	m_pos(pc),d0

	cmp.w	#76,d0
	bge.s	m_movecop

	move.w	d0,d7
	move.l	#flax+[76*6],d1
	mulu	#6,d0
	sub.l	d0,d1
	move.l	d1,d0
	bsr	m_setbplpois
	move.b	#$20,m_cop
	add.b	#$20,d7
	move.b	d7,m_cop2
	rts

m_movecop:
	move.w	d0,d7
	move.l	#flax,d0
	bsr	m_setbplpois

	sub.w	#44,d7
	move.b	d7,m_cop
	add.w	#76,d7
	move.b	d7,m_cop2
	rts

m_Setbplpois:
	move.l	d0,d1
	move.l	d0,d2
	add.l	#$1c8,d1
	add.l	#$1c8*2,d2
	move.w	d0,m_1+6
	swap	d0
	move.w	d0,m_1+2
	move.w	d1,m_2+6
	swap	d1
	move.w	d1,m_2+2
	move.w	d2,m_3+6
	swap	d2
	move.w	d2,m_3+2
	rts

;----------------------------------------------------------------

pl_xcolspoi:	dc.l	pl_xcols

pl_xcols:
	dc.w $08f,$08f,$18f,$28f,$39f,$49f,$5af,$6af
	dc.w $7bf,$8bf,$9cf,$adf,$bef,$cff,$dff,$efc
	dc.w $fbf,$ffa,$eee,$ae9,$edc,$fdc,$cef,$be8
	dc.w $8cc,$afa,$9e8,$8d8,$ac7,$4ca,$6ba,$5c3
	dc.w $5bc,$6e8,$8a8,$aa4,$696,$786,$676,$886
	dc.w $758,$5a6,$696,$575,$575,$575,$575,$575
	dc.w $575,$575,$575,$575,$574,$564,$564,$464
	dc.w $464,$464,$454,$454,$453,$453,$453,$353
	dc.w $353,$353,$343,$343,$342,$342,$342,$242
	dc.w $242,$242,$232,$232,$231,$231,$231,$131
	dc.w $131,$121,$121,$121,$120,$110,$110,$010

	dc.w	-1
pl_scr1:	dc.l	pl_s1

pl_scrno:	dc.w	0
pl_suddno:	dc.w	0
updownaddstart=$0
pl_updownadd:	dc.l	updownaddstart

pl_off:	dc.w	0

pl_rut:	tst.w	pl_off
	bne.w	bilden
	bsr	u_rut
	sub.l	#88*1,pl_updownadd
	subq.b	#1,xtracop
	bpl.s	xtrok
	subq.b	#1,xtra2cop
xtrok:


	eor.w	#1,pl_scrno

	move.w	pl_scrno(pc),d0
	mulu	#$5d80,d0
	add.l	#pl_s1,d0
	move.w	d0,pl_cop1+6
	swap	d0
	move.w	d0,pl_cop1+2
	swap	d0
	add.l	#44,d0
	move.w	d0,pl_cop2+6
	swap	d0
	move.w	d0,pl_cop2+2

	swap	d0
	add.l	#$5d80-132,d0
	add.l	pl_updownadd(pc),d0
	move.w	d0,pl_updowncop1+6
	swap	d0
	move.w	d0,pl_updowncop1+2

	move.w	pl_scrno(pc),d0
	addq.w	#1,d0
	and.w	#$1,d0
	mulu	#$5d80,d0
	add.l	#pl_s1,d0
	move.l	d0,pl_scr1

pl_wait:btst	#14,$dff002
	bne.s	pl_wait
	move.l	pl_scr1(pc),$dff054
	move.l	#$01000000,$dff040
	move.w	#0,$dff066
	move.w	#[$110*$40]+[88/2],$dff058

	tst.l	pl_xcolspoi
	beq.s	pl_w2it
	move.l	pl_xcolspoi(pc),a0
	move.w	(a0)+,d0
	bpl.s	pl_xcok
	sub.l	a0,a0
	moveq	#0,d0
pl_xcok:
	move.w	d0,xtracols+2
;	move.w	d0,xtracols+6
;	move.w	d0,xtracols+10
;	move.w	d0,xtracols+14
	move.l	a0,pl_xcolspoi

pl_w2it:btst	#14,$dff002
	bne.s	pl_w2it


	move.w	#[antalDelar/3]-1,d7
	move.l	pl_scr1(pc),a1
	add.l	#43,a1
	lea	pl_dat(pc),a0
	lea	mulu88(pc),a2
	moveq	#0,d2
	move.w	#$160,d3
	move.w	#$110,d4
	move.l	#$1000,d5
	move.l	#$c,a6

pl1_loop:move.l	(a0)+,d0	;xhast
	beq.s	pl1_skipdot
	add.l	d5,(a0)		;#$1000	;gravity
	move.l	(a0)+,d1	;yhast
	add.l	d0,(a0)
	move.l	(a0)+,d0	;xpos
	add.l	d1,(a0)		;ypos
	move.l	(a0)+,d1
	swap	d0
	cmp.w	d3,d0		;#$160
	bcc.s	pl1_skipclr
	swap	d1
	cmp.w	d4,d1		;#$110
	bcc.s	pl1_skipclr
	add.w	d1,d1
	move.w	(a2,d1.w),d1
	move.b	d0,d2
	lsr.w	#3,d0
	sub.w	d0,d1
	bset	d2,(a1,d1.w)
	bset	d2,88(a1,d1.w)
pl1_skip:dbf	d7,pl1_loop
	bra.s	pl2_r
pl1_skipdot:
	add.l	a6,a0	;#$c
	dbf	d7,pl1_loop
	bra.s	pl2_r
pl1_skipclr:
	clr.l	-$10(a0)
	dbf	d7,pl1_loop

pl2_r:	move.w	#[antalDelar/3]-1,d7
pl2_loop:move.l	(a0)+,d0	;xhast
	beq.s	pl2_skipdot
	add.l	d5,(a0)		;#$1000	;gravity
	move.l	(a0)+,d1	;yhast
	add.l	d0,(a0)
	move.l	(a0)+,d0	;xpos
	add.l	d1,(a0)		;ypos
	move.l	(a0)+,d1
	swap	d0
	cmp.w	d3,d0		;#$160
	bcc.s	pl2_skipclr
	swap	d1
	cmp.w	d4,d1		;#$110
	bcc.s	pl2_skipclr
	add.w	d1,d1
	move.w	(a2,d1.w),d1
	move.b	d0,d2
	lsr.w	#3,d0
	sub.w	d0,d1
	bset	d2,44(a1,d1.w)
	bset	d2,88(a1,d1.w)
pl2_skip:dbf	d7,pl2_loop
	bra.s	pl3_r
pl2_skipdot:
	add.l	a6,a0	;#$c
	dbf	d7,pl2_loop
	bra.s	pl3_r
pl2_skipclr:
	clr.l	-$10(a0)
	dbf	d7,pl2_loop


pl3_r:	move.w	#[antalDelar/3]-1,d7
pl3_loop:move.l	(a0)+,d0	;xhast
	beq.s	pl3_skipdot
	add.l	d5,(a0)		;#$1000	;gravity
	move.l	(a0)+,d1	;yhast
	add.l	d0,(a0)
	move.l	(a0)+,d0	;xpos
	add.l	d1,(a0)		;ypos
	move.l	(a0)+,d1
	swap	d0
	cmp.w	d3,d0		;#$160
	bcc.s	pl3_skipclr
	swap	d1
	cmp.w	d4,d1		;#$110
	bcc.s	pl3_skipclr
	add.w	d1,d1
	move.w	(a2,d1.w),d1
	move.b	d0,d2
	lsr.w	#3,d0
	sub.w	d0,d1
	bset	d2,(a1,d1.w)
	bset	d2,44(a1,d1.w)
pl3_skip:dbf	d7,pl3_loop
	rts
pl3_skipdot:
	add.l	a6,a0	;#$c
	dbf	d7,pl3_loop
	rts
pl3_skipclr:
	clr.l	-$10(a0)
	dbf	d7,pl3_loop
	rts

pl_init:move.l	#pl_xcols,pl_xcolspoi
	move.l	#updownaddstart,pl_updownadd
	move.b	#$ff,xtra2cop
	move.b	#$36,xtracop

	lea	mulu88(pc),a0
	move.w	#$110,d7
	moveq	#0,d1
pl_mulo:move.w	d1,d2
	mulu	#88,d2
	move.w	d2,(a0)+
	addq.w	#1,d1
	dbf	d7,pl_mulo

	lea	pl_s1,a0
	moveq	#0,d0
	move.w	#[[[$110*44*2]*4]/$10]-1,d7
pl_ikl:	move.l	d0,(a0)+
	move.l	d0,(a0)+
	move.l	d0,(a0)+
	move.l	d0,(a0)+
	dbf	d7,pl_ikl

	move.w	#antalDelar-1,d7
	lea	pl_dat(pc),a0

pl_ilo:	bsr	random

	moveq	#0,d0
	move.b	rnd+2(pc),d0

	lea	sin255,a5
	moveq	#0,d1
	move.b	(a5,d0.w),d1

	add.b	#$80,d1
	ext.w	d1
	muls	rnd(pc),d1
	asr.l	#3,d1
	move.l	d1,(a0)+	;xhast

	add.b	#$40,d0
	move.b	(a5,d0.w),d1
	add.b	#$80,d1
	ext.w	d1
	muls	rnd(pc),d1
	asr.l	#3,d1
	sub.l	#$20000,d1
	move.l	d1,(a0)+	;yhast

	moveq	#0,d1
	move.l	#$b80000,d0
	move.w	rnd+4(pc),d1
	ext.l	d1
	asl.l	#4,d1
	add.l	d1,d0
	move.l	d0,(a0)+	;xpos

	move.l	#$880000,d0
	move.w	rnd+6(pc),d1
	ext.l	d1
	asl.l	#5,d1
	add.l	d1,d0
	move.l	d0,(a0)+	;ypos

	dbf	d7,pl_ilo
	rts

;----------------------------------------------------------------

u_init:	lea	u1(pc),a0
	moveq	#5,d7
	move.l	#umbspr,d0

u_lo:	move.w	d0,6(a0)
	swap	d0
	move.w	d0,2(a0)
	swap	d0
	add.l	#[29*4]+8,d0
	addq.l	#8,a0
	dbf	d7,u_lo

	lea	umbspr,a0
	move.l	#$70808d00,(a0)
	move.l	#$70808d80,[[29*4]+8](a0)

	move.l	#$70888d00,2*[[29*4]+8](a0)
	move.l	#$70888d80,3*[[29*4]+8](a0)

	move.l	#$70908d00,4*[[29*4]+8](a0)
	move.l	#$70908d80,5*[[29*4]+8](a0)
	rts

u_cou:	dc.w	$0078
u_rut1go:	dc.w	1

u_rut:	tst.w	u_rut1go
	beq.s	u_rut2

	subq.b	#4,u_cou+1

	cmp.w	#$10,u_cou
	bne.s	u_ki
	clr.w	u_rut1go
u_ki:
	move.w	u_cou(pc),d0

	lea	umbspr,a0
	move.b	d0,(a0)
	move.b	d0,[[29*4]+8](a0)
	move.b	d0,[2*[[29*4]+8]](a0)
	move.b	d0,[3*[[29*4]+8]](a0)
	move.b	d0,[4*[[29*4]+8]](a0)
	move.b	d0,[5*[[29*4]+8]](a0)

	add.w	#29,d0
	move.b	d0,2(a0)
	move.b	d0,2+[[29*4]+8](a0)
	move.b	d0,2+[2*[[29*4]+8]](a0)
	move.b	d0,2+[3*[[29*4]+8]](a0)
	move.b	d0,2+[4*[[29*4]+8]](a0)
	move.b	d0,2+[5*[[29*4]+8]](a0)
	rts

u_ypos:	dc.l	$200000

u_rut2:	add.l	#$10000,u_ypos
	cmp.w	#$00a0,u_ypos
	bne	rts

	move.l	#bildcop,$dff080
	move.w	#1,pl_off
	rts

;----------------------------------------------------------------

animwait:dc.w	1
animno:	dc.w	0

bilden:	and.w	#3,animno

	move.w	animno(pc),d0
	asl.w	#2,d0
	lea	anim,a0
	lea	(a0,d0.w),a0
	lea	uno+[96*44]+20,a1
	moveq	#9,d7

.l:	move.l	(a0),(a1)
	move.l	10*16(a0),122*44(a1)
	move.l	2*10*16(a0),2*122*44(a1)
	move.l	3*10*16(a0),3*122*44(a1)
	move.l	4*10*16(a0),4*122*44(a1)

	lea	44(a1),a1
	lea	16(a0),a0
	dbf	d7,.l
	rts

bildcop:dc.w $0100,$5200,$0102,$0000,$0104,$0000,$0108,00,$010a,00
	dc.w $0096,$8020
	dc.w $120,dummy/$10000,$122,dummy&$ffff
	dc.w $124,dummy/$10000,$126,dummy&$ffff
	dc.w $128,dummy/$10000,$12a,dummy&$ffff
	dc.w $12c,dummy/$10000,$12e,dummy&$ffff
	dc.w $130,dummy/$10000,$132,dummy&$ffff
	dc.w $134,dummy/$10000,$136,dummy&$ffff
	dc.w $138,dummy/$10000,$13a,dummy&$ffff
	dc.w $13c,dummy/$10000,$13e,dummy&$ffff

kotte:	dc.w $008e,$6671,$0090,$e0c7,$0092,$0030,$0094,$00d8

	dc.w $00e0,[Uno+[122*44*0]]/$10000,$00e2,[uno+[122*44*0]]&$ffff
	dc.w $00e4,[Uno+[122*44*1]]/$10000,$00e6,[uno+[122*44*1]]&$ffff
	dc.w $00e8,[Uno+[122*44*2]]/$10000,$00ea,[uno+[122*44*2]]&$ffff
	dc.w $00ec,[Uno+[122*44*3]]/$10000,$00ee,[uno+[122*44*3]]&$ffff
	dc.w $00f0,[Uno+[122*44*4]]/$10000,$00f2,[uno+[122*44*4]]&$ffff

	dc.w	$0180,$0000
	dc.w	$0182,$0FFF
	dc.w	$0184,$0CCE
	dc.w	$0186,$0AAC
	dc.w	$0188,$088A
	dc.w	$018a,$0668
	dc.w	$018c,$0446
	dc.w	$018e,$0224
	dc.w	$0190,$0B96
	dc.w	$0192,$0975
	dc.w	$0194,$0864
	dc.w	$0196,$0753
	dc.w	$0198,$0642
	dc.w	$019a,$0531
	dc.w	$019c,$0420
	dc.w	$019e,$0310
	dc.w	$01a0,$0BC1
	dc.w	$01a2,$0AB1
	dc.w	$01a4,$09A1
	dc.w	$01a6,$0891
	dc.w	$01a8,$0781
	dc.w	$01aa,$0671
	dc.w	$01ac,$0561
	dc.w	$01ae,$0451
	dc.w	$01b0,$0340
	dc.w	$01b2,$0230
	dc.w	$01b4,$0120
	dc.w	$01b6,$0EA8
	dc.w	$01b8,$0D86
	dc.w	$01ba,$0B64
	dc.w	$01bc,$0842
	dc.w	$01be,$0620
	dc.w	$ffff,$fffe





;----------------------------------------------------------------



NewLv6Int:
	movem.l	d0-d7/a0-a6,-(a7)
Sunc:	move.l	$dff004,d0
	and.l	#$1ff00,d0
	cmp.l	#$12600,d0	;e6
	blt.s	Sunc
	move.w	#$3700,d0	;$3752
	tst.b	$bfdd00
	tst.b	$bfde00		;ctrl a - stop timer a
	move.w	d0,d1
	lsr.w	#$8,d1
	move.b	d0,$bfd400	;timer a low
	move.b	d1,$bfd500	;timer a high
	move.b	#$81,$bfdd00	;irq ctrlreg - set irq from timer a
	move.b	#$11,$bfde00	;force load+start timer a - continuos

.ever:	bsr	Random		;get new rnd
	bsr	kottrut

	tst.w	expogo
	beq.s	.no
	bsr	expo
.no:	tst.w	ceolgo
	beq.s	.no2
	bsr	ceolrut
.no2:	bsr	m_rut
	bsr	lets_go
	addq.w	#1,kottecou
	cmp.w	#$22e,kottecou
	bne.s	.hej
	move.w	#1,kotteon
.hej:	cmp.w	#$2b8,kottecou
	bne.s	.er
	move.l	#PrCop,$dff080
	move.w	#1,ceolgo
.er:	cmp.w	#$336,kottecou
	bne.s	.re
	move.l	#cop2,$dff080
	move.w	#1,expogo
.re:
	movem.l	(a7)+,d0-d7/a0-a6
	move.w	#$2000,$dff09c
	rte

OldLv2Irq:	dc.l	0
OldLv6Irq:	dc.l	0
SetLv2Irq:	move.l	$68.w,OldLv2Irq
		move.l	#NewLv2Int,$68.w
	move.w	#$3781,d0
	tst.b	$bfee01		;ctrl a - stop timer a
	tst.b	$bfef01
	move.b	d0,$bfe401	;timer a low
	lsr.w	#$8,d0
	move.b	d0,$bfe501	;timer a high
	move.b	#$7f,$bfed01	;clr irq ctrlreg
	move.b	#$89,$bfed01	;irq ctrlreg - from timer a + sp full
	move.w	#$8008,$dff09a

	move.l	$78.w,OldLv6Irq
	move.b	#$7f,$bfdd00	;clr irq ctrlreg
	move.l	#NewLv6Int,$78.w
	move.w	#$3700,d0	;$3781
	tst.b	$bfde00		;ctrl a - stop timer a
	tst.b	$bfdf00
	move.b	d0,$bfd400	;timer a low
	lsr.w	#$8,d0
	move.b	d0,$bfd500	;timer a high
	move.b	#$81,$bfdd00	;irq ctrlreg - from timer a
	move.b	#$11,$bfde00	;- start timer a one-shot
	move.w	#$e000,$dff09a	;enable lv6	+ main
	rts


ClrLv2Irq:	move.w	#$2008,$dff09a
		tst.b	$bfee01
		tst.b	$bfde00
		tst.b	$bfef01
		tst.b	$bfdf00
		tst.b	$bfed01
		tst.b	$bfdd00

		move.b	#$7f,$bfed01
		move.b	#$7f,$bfdd00
		move.b	#$9f,$bfed01
		move.b	#$9f,$bfdd00
		move.l	OldLv2Irq(pc),$68.w
		move.l	OldLv6Irq(pc),$78.w
		rts



NewLv2Int:	movem.l	d0-d2,-(a7)
		move.b	$bfed01,d0
		bclr	#7,d0
		bclr	#3,d0
		beq	NII_Ex
		moveq	#0,d2
		move.b	$bfec01,d2
		bset	#6,$bfee01
		not.b	d2
		ror.b	#1,d2
		moveq	#60,d1
NII_Wait:	dbf	d1,NII_Wait
		bclr	#6,$bfee01
		btst	#7,d2
		bne.s	NII_UpKey
		move.w	d2,ActKey
NII_UpKey:	move.w	d2,AllKey
NII_Ex:		move.w	#$0008,$dff09c
		movem.l	(a7)+,d0-d2
		rte

ActKey:		dc.w	0
AllKey:		dc.w	0

;----------------------------------------------------------------

rnd_init:
	move.w	$dff004,rnd
	move.w	$dff006,rnd+2
	move.b	$dff00b,rnd+4
	move.b	$dff006,rnd+5
	move.w	$dff00a,rnd+6
	rts

RANDOM:	MOVEM.L	RND,D0/D1	;D0=LSB's, D1=MSB's of rnd num
	ANDI.B	#$0E,D0		;ensure upper 59 bits are an...
	ORI.B	#$20,D0		;...odd binary number
	MOVE.L	D0,D2
	MOVE.L	D1,D3
	ADD.L	D2,D2		;accounts for 1 of 17 left shifts
	ADDX.L	D3,D3		;[D2/D3] = RND*2
	ADD.L	D2,D0
	ADDX.L	D3,D1		;[D0/D1] = RND*3
	SWAP	D3		;shift [D2/D3] additional 16 times
	SWAP	D2
	MOVE.W	D2,D3
	CLR.W	D2
	ADD.L	D2,D0		;add to [D0/D1]
	ADDX.L	D3,D1
	add.w	$dff006,d0
	add.w	$dff00a,d1
	MOVEM.L	D0/D1,RND	;save for next time through
;	MOVE.L D0,D1
	RTS
RND:	DC.L 0,0



;ญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญ
;ญ   NoisetrackerV2.0 Normal replay   ญ
;ญ     Uses registers d0-d3/a0-a5     ญ
;ญ Mahoney & Kaktus - (C) E.A.S. 1990 ญ
;ญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญ


mt_init:movem.l	d0-d2/a0-a2,-(a7)
	lea	mt_data,a0
	lea	$3b8(a0),a1
	moveq	#$7f,d0
	moveq	#0,d2
	moveq	#0,d1
mt_lop2:move.b	(a1)+,d1
	cmp.b	d2,d1
	ble.s	mt_lop
	move.l	d1,d2
mt_lop:	dbf	d0,mt_lop2
	addq.b	#1,d2
	asl.l	#8,d2
	asl.l	#2,d2
	lea	4(a1,d2.l),a2
	lea	mt_samplestarts(pc),a1
	add.w	#42,a0
	moveq	#$1e,d0
mt_lop3:clr.l	(a2)
	move.l	a2,(a1)+
	moveq	#0,d1
	move.w	(a0),d1
		clr.b	$2(a0)
	asl.l	#1,d1
	add.l	d1,a2
	add.l	#$1e,a0
	dbf	d0,mt_lop3

	move.b	#6,mt_speed
	moveq	#0,d0
	lea	$dff000,a0
	move.w	d0,$a8(a0)
	move.w	d0,$b8(a0)
;	move.w	d0,$c8(a0)
;	move.w	d0,$d8(a0)
	move.w	#$192,mt_voice3+$10
	move.w	#$192,mt_voice4+$10

	move.l	#dummysound,mt_voice3+$a
	move.w	#1,mt_voice3+$e
	move.l	#dummysound,mt_voice4+$a
	move.w	#1,mt_voice4+$e


	clr.b	mt_songpos
	clr.b	mt_counter
	clr.w	mt_pattpos
	move.w	#$3,$dff096
	movem.l	(a7)+,d0-d2/a0-a2
	rts

mt_end:	clr.w	$dff0a8
	clr.w	$dff0b8
	clr.w	$dff0c8
	clr.w	$dff0d8
	move.w	#$f,$dff096
	rts


mt_music:
	movem.l	d0-d3/a0-a5,-(a7)
	lea	mt_data,a0
	addq.b	#1,mt_counter
	move.b	mt_counter(pc),d0
	cmp.b	mt_speed(pc),d0
	blt	mt_nonew
	clr.b	mt_counter

	lea	mt_data,a0
	lea	$c(a0),a3
	lea	$3b8(a0),a2
	lea	$43c(a0),a0

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

	lea	$dff0a0,a5
	lea	mt_voice1(pc),a4
	bsr	mt_playvoice
	addq.l	#4,d1
	lea	$dff0b0,a5
	lea	mt_voice2(pc),a4
	bsr	mt_playvoice
	addq.l	#4,d1
	lea	$dff0c0,a5
	lea	mt_voice3(pc),a4
	bsr	mt_playvoice
	addq.l	#4,d1
	lea	$dff0d0,a5
	lea	mt_voice4(pc),a4
	bsr	mt_playvoice

	move.w	mt_dmacon(pc),d0
	beq.s	mt_nodma

	bsr	mt_wait
	or.w	#$8000,d0
	move.w	d0,$dff096
	bsr	mt_wait
mt_nodma:
	lea	mt_voice1(pc),a4
	lea	$dff000,a3
	move.l	$a(a4),$a0(a3)
	move.w	$e(a4),$a4(a3)
	move.l	$a+$1c(a4),$b0(a3)
	move.w	$e+$1c(a4),$b4(a3)
	move.l	$a+$38(a4),$c0(a3)
	move.w	$e+$38(a4),$c4(a3)
	move.l	$a+$54(a4),$d0(a3)
	move.w	$e+$54(a4),$d4(a3)

	add.w	#$10,mt_pattpos
	cmp.w	#$400,mt_pattpos
	bne.s	mt_exit
mt_next:clr.w	mt_pattpos
	clr.b	mt_break
	addq.b	#1,mt_songpos
	and.b	#$7f,mt_songpos
	move.b	-2(a2),d0
	cmp.b	mt_songpos(pc),d0
	bne.s	mt_exit
	move.b	-1(a2),mt_songpos
mt_exit:tst.b	mt_break
	bne.s	mt_next
	movem.l	(a7)+,d0-d3/a0-a5
	rts

mt_wait:moveq	#3,d3
mt_wai2:move.b	$dff006,d2
mt_wai3:cmp.b	$dff006,d2
	beq.s	mt_wai3
	dbf	d3,mt_wai2
	moveq	#8,d2
mt_wai4:dbf	d2,mt_wai4
	rts

mt_nonew:
	lea	mt_voice1(pc),a4
	lea	$dff0a0,a5
	bsr	mt_com
	lea	mt_voice2(pc),a4
	lea	$dff0b0,a5
	bsr	mt_com
	lea	mt_voice3(pc),a4
	lea	$dff0c0,a5
	bsr	mt_com
	lea	mt_voice4(pc),a4
	lea	$dff0d0,a5
	bsr	mt_com
	bra.s	mt_exit

mt_playvoice:
	move.l	(a0,d1.l),(a4)
	moveq	#0,d2
	move.b	2(a4),d2
	lsr.b	#4,d2
	move.b	(a4),d0
	and.b	#$f0,d0
	or.b	d0,d2
	beq.s	mt_oldinstr

	cmp.w	#$1c,d2
	bne.s	no
	eor.w	#1,animno
no:
	cmp.w	#$1a,d2
	beq.s	.go
	cmp.w	#$1e,d2
	bne.s	on
.go:	eor.w	#2,animno
on:

	lea	mt_samplestarts-4(pc),a1
	asl.w	#2,d2
	move.l	(a1,d2.l),4(a4)
	lsr.w	#2,d2
	MULU	#$1E,D2
	move.w	(a3,d2.w),8(a4)
	move.w	2(a3,d2.w),$12(a4)
	moveq	#0,d3
	move.w	4(a3,d2.w),d3
	tst.w	d3
	beq.s	mt_noloop
	move.l	4(a4),d0
	asl.w	#1,d3
	add.l	d3,d0
	move.l	d0,$a(a4)
	move.w	4(a3,d2.w),d0
	add.w	6(a3,d2.w),d0
	move.w	d0,8(a4)
	bra.s	mt_hejaSverige
mt_noloop:
	move.l	4(a4),d0
	add.l	d3,d0
	move.l	d0,$a(a4)
mt_hejaSverige:
	move.w	6(a3,d2.w),$e(a4)
	moveq	#0,d0
	move.b	$13(a4),d0
	move.w	d0,8(a5)

mt_oldinstr:
	move.w	(a4),d0
	and.w	#$fff,d0
	beq	mt_com2
	tst.w	8(a4)
	beq.s	mt_stopsound
	tst.b	$12(a4)
	bne.s	mt_stopsound
	move.b	2(a4),d0
	and.b	#$f,d0
	cmp.b	#5,d0
	beq.s	mt_setport
	cmp.b	#3,d0
	beq.s	mt_setport

	move.w	(a4),$10(a4)
	and.w	#$fff,$10(a4)
	move.w	$1a(a4),$dff096
	clr.b	$19(a4)

	move.l	4(a4),(a5)
	move.w	8(a4),4(a5)
	move.w	$10(a4),6(a5)

	move.w	$1a(a4),d0	;dmaset
	or.w	d0,mt_dmacon
	bra	mt_com2

mt_stopsound:
	move.w	$1a(a4),$dff096
	bra	mt_com2

mt_setport:
	move.w	(a4),d2
	and.w	#$fff,d2
	move.w	d2,$16(a4)
	move.w	$10(a4),d0
	clr.b	$14(a4)
	cmp.w	d0,d2
	beq.s	mt_clrport
	bge	mt_com2
	move.b	#1,$14(a4)
	bra	mt_com2
mt_clrport:
	clr.w	$16(a4)
	rts

mt_port:move.b	3(a4),d0
	beq.s	mt_port2
	move.b	d0,$15(a4)
	clr.b	3(a4)
mt_port2:
	tst.w	$16(a4)
	beq.s	mt_rts
	moveq	#0,d0
	move.b	$15(a4),d0
	tst.b	$14(a4)
	bne.s	mt_sub
	add.w	d0,$10(a4)
	move.w	$16(a4),d0
	cmp.w	$10(a4),d0
	bgt.s	mt_portok
	move.w	$16(a4),$10(a4)
	clr.w	$16(a4)
mt_portok:
	move.w	$10(a4),6(a5)
mt_rts:	rts

mt_sub:	sub.w	d0,$10(a4)
	move.w	$16(a4),d0
	cmp.w	$10(a4),d0
	blt.s	mt_portok
	move.w	$16(a4),$10(a4)
	clr.w	$16(a4)
	move.w	$10(a4),6(a5)
	rts

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

mt_vib:	move.b	$3(a4),d0
	beq.s	mt_vib2
	move.b	d0,$18(a4)

mt_vib2:move.b	$19(a4),d0
	lsr.w	#2,d0
	and.w	#$1f,d0
	moveq	#0,d2
	move.b	mt_sin(pc,d0.w),d2
	move.b	$18(a4),d0
	and.w	#$f,d0
	mulu	d0,d2
	lsr.w	#7,d2
	move.w	$10(a4),d0
	tst.b	$19(a4)
	bmi.s	mt_vibsub
	add.w	d2,d0
	bra.s	mt_vib3
mt_vibsub:
	sub.w	d2,d0
mt_vib3:move.w	d0,6(a5)
	move.b	$18(a4),d0
	lsr.w	#2,d0
	and.w	#$3c,d0
	add.b	d0,$19(a4)
	rts


mt_arplist:
	dc.b 0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1,2,0,1

mt_arp:	moveq	#0,d0
	move.b	mt_counter(pc),d0
	move.b	mt_arplist(pc,d0.w),d0
	beq.s	mt_arp0
	cmp.b	#2,d0
	beq.s	mt_arp2
mt_arp1:moveq	#0,d0
	move.b	3(a4),d0
	lsr.b	#4,d0
	bra.s	mt_arpdo
mt_arp2:moveq	#0,d0
	move.b	3(a4),d0
	and.b	#$f,d0
mt_arpdo:
	asl.w	#1,d0
	move.w	$10(a4),d1
	and.w	#$fff,d1
	lea	mt_periods(pc),a0
	moveq	#$24,d2
mt_arp3:cmp.w	(a0)+,d1
	bge.s	mt_arpfound
	dbf	d2,mt_arp3
mt_arp0:move.w	$10(a4),6(a5)
	rts
mt_arpfound:
	move.w	-2(a0,d0.w),6(a5)
	rts

mt_normper:
	move.w	$10(a4),6(a5)
	rts

mt_com:	move.w	2(a4),d0
	and.w	#$fff,d0
	beq.s	mt_normper
	move.b	2(a4),d0
	and.b	#$f,d0
	tst.b	d0
	beq.s	mt_arp
	cmp.b	#1,d0
	beq.s	mt_portup
	cmp.b	#2,d0
	beq.s	mt_portdown
	cmp.b	#3,d0
	beq	mt_port
	cmp.b	#4,d0
	beq	mt_vib
	cmp.b	#5,d0
	beq.s	mt_volport
	cmp.b	#6,d0
	beq.s	mt_volvib
	move.w	$10(a4),6(a5)
	cmp.b	#$a,d0
	beq.s	mt_volslide
	rts

mt_portup:
	moveq	#0,d0
	move.b	3(a4),d0
	sub.w	d0,$10(a4)
	move.w	$10(a4),d0
	cmp.w	#$71,d0
	bpl.s	mt_portup2
	move.w	#$71,$10(a4)
mt_portup2:
	move.w	$10(a4),6(a5)
	rts

mt_portdown:
	moveq	#0,d0
	move.b	3(a4),d0
	add.w	d0,$10(a4)
	move.w	$10(a4),d0
	cmp.w	#$358,d0
	bmi.s	mt_portdown2
	move.w	#$358,$10(a4)
mt_portdown2:
	move.w	$10(a4),6(a5)
	rts

mt_volvib:
	 bsr	mt_vib2
	 bra.s	mt_volslide
mt_volport:
	 bsr	mt_port2

mt_volslide:
	moveq	#0,d0
	move.b	3(a4),d0
	lsr.b	#4,d0
	beq.s	mt_vol3
	add.b	d0,$13(a4)
	cmp.b	#$40,$13(a4)
	bmi.s	mt_vol2
	move.b	#$40,$13(a4)
mt_vol2:moveq	#0,d0
	move.b	$13(a4),d0
	move.w	d0,8(a5)
	rts

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

mt_com2:move.b	$2(a4),d0
	and.b	#$f,d0
	cmp.b	#$e,d0
	beq.s	mt_filter
	cmp.b	#$d,d0
	beq.s	mt_pattbreak
	cmp.b	#$b,d0
	beq.s	mt_songjmp
	cmp.b	#$c,d0
	beq.s	mt_setvol
	cmp.b	#$f,d0
	beq.s	mt_setspeed
	rts

mt_filter:
	move.b	3(a4),d0
	and.b	#1,d0
	asl.b	#1,d0
	and.b	#$fd,$bfe001
	or.b	d0,$bfe001
	rts

mt_pattbreak:
	move.b	#1,mt_break
	rts

mt_songjmp:
	move.b	#1,mt_break
	move.b	3(a4),d0
	subq.b	#1,d0
	move.b	d0,mt_songpos
	rts

mt_setvol:
	cmp.b	#$40,3(a4)
	bls.s	mt_sv2
	move.b	#$40,3(a4)
mt_sv2:	moveq	#0,d0
	move.b	3(a4),d0
	move.b	d0,$13(a4)
	move.w	d0,8(a5)
	rts

mt_setspeed:
	moveq	#0,d0
	move.b	3(a4),d0
	cmp.b	#$1f,d0
	bls.s	mt_sp2
	moveq	#$1f,d0
mt_sp2:	tst.w	d0
	bne.s	mt_sp3
	moveq	#1,d0
mt_sp3:	move.b	d0,mt_speed
	rts

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

mt_speed:	dc.b	6
mt_counter:	dc.b	0
mt_pattpos:	dc.w	0
mt_songpos:	dc.b	0
mt_break:	dc.b	0
mt_dmacon:	dc.w	$c
mt_samplestarts:blk.l	$1f,0
mt_voice1:	blk.w	13,0
		dc.w	1
mt_voice2:	blk.w	13,0
		dc.w	2
mt_voice3:	blk.w	13,0
		dc.w	4
mt_voice4:	blk.w	13,0
		dc.w	8

;----------------------------------------------------------------

dummy:	dc.l	0

;----------------------------------------------------------------

cop:	dc.w $0100,$0200,$0104,$0020,$0108,$0000,$010a,$00
	dc.w $0096,$8020
	dc.w $120,dummy/$10000,$122,dummy&$ffff
	dc.w $124,dummy/$10000,$126,dummy&$ffff
	dc.w $128,dummy/$10000,$12a,dummy&$ffff
	dc.w $12c,dummy/$10000,$12e,dummy&$ffff
	dc.w $130,dummy/$10000,$132,dummy&$ffff
	dc.w $134,dummy/$10000,$136,dummy&$ffff
	dc.w $138,dummy/$10000,$13a,dummy&$ffff
	dc.w $13c,dummy/$10000,$13e,dummy&$ffff
m_sid:	dc.w	$0102,$0000
	dc.w $008e,$2071,$0090,$38c7
m_sid2:	dc.w $0092,$0078,$0094,$0088

	dc.w $180,$000,$182,$225,$184,$06d,$186,$049
	dc.w $188,$1a0,$18a,$fff,$18c,$ecb,$18e,$b99
m_1:	dc.w $00e0,flax/$10000,$00e2,flax&$ffff
m_2:	dc.w $00e4,[flax+$1c8]/$10000,$00e6,[flax+$1c8]&$ffff
m_3:	dc.w $00e8,[flax+[$1c8*2]]/$10000,$00ea,[flax+[$1c8*2]]&$ffff

m_cop:	dc.w $2001,$fffe,$0100,$3200
m_cop2:	dc.w $2001,$fffe,$0100,$0200
	dc.w	$ffff,$fffe

;----------------------------------------------------------------

cop1:	dc.w $0100,$3200,$0102,$0000,$0104,$0028,$0108,44,$010a,-132
	dc.w $0096,$8020

u1:	dc.w $120,dummy/$10000,$122,dummy&$ffff
u2:	dc.w $124,dummy/$10000,$126,dummy&$ffff
u3:	dc.w $128,dummy/$10000,$12a,dummy&$ffff
u4:	dc.w $12c,dummy/$10000,$12e,dummy&$ffff
u5:	dc.w $130,dummy/$10000,$132,dummy&$ffff
u6:	dc.w $134,dummy/$10000,$136,dummy&$ffff
	dc.w $138,dummy/$10000,$13a,dummy&$ffff
	dc.w $13c,dummy/$10000,$13e,dummy&$ffff

	dc.w $008e,$2671,$0090,$36c7,$0092,$0030,$0094,$00d8

pl_cop1:dc.w $00e0,pl_s1/$10000,$00e2,pl_s1&$ffff
pl_cop2:dc.w $00e8,pl_s1/$10000,$00ea,pl_s1&$ffff

pl_updowncop1:
	dc.w $00e4,[pl_s1+$5d80-44]/$10000,$00e6,[pl_s1+$5d80-44]&$ffff

	dc.w $0180,$0000,$0182,$06d
	dc.w $0188,$fff,$018a,$1a0
xtracols:	dc.w $184,$fff,$186,$16e,$18c,$0ff,$18e,$2b4

	dc.w $1a2,$225,$1a4,$06d,$1a6,$049
	dc.w $1a8,$1a0,$1aa,$fff,$1ac,$ecb,$1ae,$b99

xtra2cop:
	dc.w $ffe1,$fffe
xtracop:dc.w $3607,$fffe
	dc.w $184,$000,$186,$06d,$18c,$fff,$18e,$1a0


	dc.w	$ffff,$fffe


;----------------------------------------------------------------

ceolpoi:	dc.l	ceoldat
ceolgo:	dc.w	0
ceolx:	dc.w	0

ceolrut:eor.w	#1,ceolx
	beq	rts
	move.l	ceolpoi(pc),a0
	lea	ceol1+6(pc),a1
	move.w	(a0)+,(a1)
	move.w	(a0)+,4(a1)
	move.w	(a0)+,8(a1)
	move.w	(a0)+,12(a1)
	move.w	(a0)+,16(a1)
	move.w	(a0)+,20(a1)
	move.w	(a0)+,24(a1)

	move.l	a0,ceolpoi
	tst.w	(a0)
	bpl	rts
	clr.w	ceolgo
	rts

ceoldat:
 dc.w $0000,$0000,$0220,$0000,$0000,$0110,$0000
 dc.w $0000,$0000,$0440,$0000,$0000,$0330,$0000
 dc.w $0000,$0000,$0880,$0000,$0000,$0550,$0000
 dc.w $0000,$0001,$0cc0,$0000,$0000,$0770,$0000
 dc.w $0001,$0002,$0ff1,$0000,$0000,$0881,$0000
 dc.w $0001,$0003,$0ee2,$0001,$0000,$0872,$0000
 dc.w $0002,$0004,$0dd3,$0001,$0000,$0773,$0000
 dc.w $0003,$0005,$0cc4,$0002,$0001,$0764,$0000
 dc.w $0004,$0006,$0bb5,$0002,$0001,$0665,$0000
 dc.w $0004,$0007,$0aa6,$0003,$0001,$0656,$0000
 dc.w $0005,$0008,$0997,$0003,$0002,$0557,$0000
 dc.w $0006,$0009,$0888,$0004,$0002,$0548,$0000
 dc.w $0007,$000a,$0779,$0004,$0002,$0449,$0000
 dc.w $0007,$000b,$066a,$0005,$0003,$043a,$0000
 dc.w $0008,$001c,$055b,$0005,$0003,$033b,$0000
 dc.w $0009,$001d,$044c,$0006,$0003,$032c,$0000
 dc.w $0009,$002e,$033d,$0006,$0004,$022d,$0000
 dc.w $0019,$002E,$022D,$0006,$0004,$021D,$0000
 dc.w $0019,$003E,$012D,$0016,$0004,$012D,$0000
 dc.w $0019,$003E,$003D,$0016,$0004,$013D,$0000
 dc.w $0029,$004E,$004D,$0016,$0004,$003D,$0000
 dc.w $0029,$004E,$005D,$0016,$0014,$004D,$0000
 dc.w $0029,$005E,$006D,$0026,$0014,$005D,$0000
 dc.w $0039,$005E,$007D,$0026,$0014,$006D,$0000
 dc.w $0039,$006E,$008D,$0026,$0014,$006D,$0000
 dc.w $0039,$006E,$009D,$0026,$0014,$007D,$0000
 dc.w $0049,$007E,$00aD,$0036,$0014,$008D,$0000
 dc.w $0049,$007E,$00bD,$0036,$0024,$008D,$0000
 dc.w $0049,$008E,$00cD,$0036,$0024,$009D,$0000
 dc.w $0159,$008E,$00dD,$0136,$0024,$01AD,$0000
 dc.w $0159,$008E,$01DD,$0136,$0024,$01AD,$0000
 dc.w $0259,$008E,$02DD,$0136,$0024,$02AD,$0000
 dc.w $0259,$008E,$03DD,$0136,$0124,$02AD,$0000
 dc.w $0259,$008E,$04DD,$0236,$0124,$03AD,$0000
 dc.w $0359,$008E,$05DD,$0236,$0124,$03AD,$0000
 dc.w $0359,$008E,$06DD,$0236,$0124,$04AD,$0000
 dc.w $0359,$008E,$07DD,$0236,$0124,$04AD,$0000
 dc.w $0359,$008E,$07DD,$0236,$0124,$04AD,$0f00
 dc.w $0359,$008E,$07DD,$0236,$0124,$04AD,$0e00
 dc.w $0359,$008E,$07DD,$0236,$0124,$04AD,$0d00
 dc.w $0359,$008E,$07DD,$0236,$0124,$04AD,$0c00
 dc.w $0359,$008E,$07DD,$0236,$0124,$04AD,$0b00
 dc.w $0359,$008E,$07DD,$0236,$0124,$04AD,$0a00
 dc.w $0359,$008E,$07DD,$0236,$0124,$04AD,$0900
 dc.w $0359,$008E,$07DD,$0236,$0124,$04AD,$0800
 dc.w $0359,$008E,$07DD,$0236,$0124,$04AD,$0700
 dc.w $0359,$008E,$07DD,$0236,$0124,$04AD,$0600
 dc.w $0359,$008E,$07DD,$0236,$0124,$04AD,$0500
 dc.w -1

;----------------------------------------------------------------

expocou:dc.w	$30
expogo:	dc.w	0


expo:	moveq	#0,d0
	move.b	rnd(pc),d0
	move.w	expocou(pc),d1
	muls	d1,d0
	lsr.l	#$8,d0
	lsr.w	#$2,d0
	add.w	#$0,d0
	move.w	d0,d2
	asl.w	#$4,d2
	add.w	d0,d2
	move.w	d2,cop2+2

	moveq	#0,d0
	move.b	rnd+1(pc),d0
	mulu	d1,d0
	lsr.l	#8,d0
	lsr.w	#1,d0

	move.w	d0,d2
	moveq	#$56,d2
	sub.w	d0,d2
	moveq	#$04,d1
	sub.w	d0,d1
	move.b	d2,cop3+2
	move.b	d1,cop3+6

	subq.w	#1,expocou
	bne	rts
	clr.w	expogo
	rts

;----------------------------------------------------------------

cop2:	dc.w $0102,$0000,$0104,$0000,$0108,00,$010a,00
cop3:	dc.w $008e,$5671,$0090,$04c7,$0092,$0038,$0094,$00d0

	dc.w $120,dummy/$10000,$122,dummy&$ffff
	dc.w $124,dummy/$10000,$126,dummy&$ffff
	dc.w $128,dummy/$10000,$12a,dummy&$ffff
	dc.w $12c,dummy/$10000,$12e,dummy&$ffff
	dc.w $130,dummy/$10000,$132,dummy&$ffff
	dc.w $134,dummy/$10000,$136,dummy&$ffff
	dc.w $138,dummy/$10000,$13a,dummy&$ffff
	dc.w $13c,dummy/$10000,$13e,dummy&$ffff

	dc.w $00e0,[Pr5+[174*40*0]]/$10000,$00e2,[Pr5+[174*40*0]]&$ffff
	dc.w $00e4,[Pr5+[174*40*1]]/$10000,$00e6,[Pr5+[174*40*1]]&$ffff
	dc.w $00e8,[Pr5+[174*40*2]]/$10000,$00ea,[Pr5+[174*40*2]]&$ffff
	dc.w $00ec,[Pr5+[174*40*3]]/$10000,$00ee,[Pr5+[174*40*3]]&$ffff
	dc.w $00f0,[Pr5+[174*40*4]]/$10000,$00f2,[Pr5+[174*40*4]]&$ffff

	dc.w $180,$000,$182,$FFF,$184,$EEE,$186,$DDD
	dc.w $188,$CCC,$18a,$BBB,$18c,$AAA,$18e,$999
	dc.w $190,$888,$192,$777,$194,$666,$196,$555
	dc.w $198,$444,$19a,$333,$19c,$222,$19e,$111
	dc.w $1a0,$F56,$1a2,$D45,$1a4,$C34,$1a6,$A22
	dc.w $1a8,$811,$1aa,$611,$1ac,$500,$1ae,$300
	dc.w $1b0,$200,$1b2,$100,$1b4,$322,$1b6,$0F0
	dc.w $1b8,$0F0,$1ba,$0F0,$1bc,$0F0,$1be,$0F0

	dc.w $0100,$5200

	dc.w $ffff,$fffe


Prcop:	dc.w $0100,$3200,$0102,$0000,$0104,$0000,$0108,00,$010a,00
	dc.w $0096,$8020
	dc.w $120,dummy/$10000,$122,dummy&$ffff
	dc.w $124,dummy/$10000,$126,dummy&$ffff
	dc.w $128,dummy/$10000,$12a,dummy&$ffff
	dc.w $12c,dummy/$10000,$12e,dummy&$ffff
	dc.w $130,dummy/$10000,$132,dummy&$ffff
	dc.w $134,dummy/$10000,$136,dummy&$ffff
	dc.w $138,dummy/$10000,$13a,dummy&$ffff
	dc.w $13c,dummy/$10000,$13e,dummy&$ffff

	dc.w $008e,$6671,$0090,$28c7,$0092,$0060,$0094,$00a0

	dc.w $00e0,[Pr3+[194*18*0]]/$10000,$00e2,[Pr3+[194*18*0]]&$ffff
	dc.w $00e4,[Pr3+[194*18*1]]/$10000,$00e6,[Pr3+[194*18*1]]&$ffff
	dc.w $00e8,[Pr3+[194*18*2]]/$10000,$00ea,[Pr3+[194*18*2]]&$ffff

ceol1:	dc.w $180,$0,$182,$0,$184,$0,$186,$0
	dc.w $188,$0,$18a,$0,$18c,$0,$18e,$0
	dc.w $ffff,$fffe

;TimeDecruncher - av Mahoney Juni -90
Decrunch:
	lea	Crun,a0
	add.l	(a0),a0
	addq.l	#8,a0
	lea	$39000,a1
	move.l	-(a0),a2
	add.l	a1,a2
	tst.l	-(a0)
	move.l	-(a0),d0
	moveq	#$10,d4
	moveq	#2,d5
	moveq	#3,d6
	moveq	#1,d7
	lea	7.w,a4

Z03a:	moveq	#3,d1
	bsr	Z132
	tst.w	d2
	beq.s	Z0a2
	cmp.w	a4,d2	;a4=#7
	bne.s	Z078
	lsr.l	#1,d0
	bne.s	Z05c
	 move.l	-(a0),d0
	 move	d4,ccr
	 roxr.l	#1,d0
Z05c:	bcc.s	Z070
	moveq	#10,d1
	bsr	Z132
	tst.w	d2
	bne.s	Z078
	moveq	#$12,d1
	bsr	Z132
	bra.s	Z078

Z070:	moveq	#4,d1
	bsr	Z132
	addq.w	#7,d2
Z078:	subq.w	#1,d2
Z07a:	moveq	#7,d1
Z07c:	lsr.l	#1,d0
	beq.s	Z08e
	roxl.l	#1,d3
	dbra	d1,Z07c
	move.b	d3,-(a2)
	dbra	d2,Z07a
	bra.s	Z0a2

Z08e:	move.l	-(a0),d0
	move	d4,ccr
	roxr.l	#1,d0
	roxl.l	#1,d3
	dbra	d1,Z07c
	move.b	d3,-(a2)
	dbra	d2,Z07a
Z0a2:	cmp.l	a2,a1
	bge.s	Z122
	moveq	#2,d1
	bsr.s	Z132
	moveq	#2,d3
	moveq	#8,d1
	tst.w	d2
	beq.s	Z110
	moveq	#4,d3
	cmp.w	d5,d2	;d5=#2
	beq.s	Z0fa
	moveq	#3,d3
	cmp.w	d7,d2	;d7=#1
	beq.s	Z0ec
	moveq	#2,d1
	bsr.s	Z132
	cmp.w	d6,d2	;d6=#3
	beq.s	Z0e4
	cmp.w	d5,d2	;d5=#2
	beq.s	Z0da
	addq.w	#5,d2
	move.w	d2,d3
	bra.s	Z0fa

Z0da:	moveq	#2,d1
	bsr.s	Z132
	addq.w	#7,d2
	move.w	d2,d3
	bra.s	Z0fa

Z0e4:	moveq	#8,d1
	bsr.s	Z132
	move.w	d2,d3
	bra.s	Z0fa

Z0ec:	moveq	#8,d1
	lsr.l	#1,d0
	bne.s	Z0f4
	 move.l	-(a0),d0
	 move	d4,ccr
	 roxr.l	#1,d0
Z0f4:	bcs.s	Z110
	moveq	#14,d1
	bra.s	Z110

Z0fa:	moveq	#$10,d1
	lsr.l	#1,d0
	bne.s	Z102
	 move.l	-(a0),d0
	 move	d4,ccr
	 roxr.l	#1,d0
Z102:	bcc.s	Z110
	moveq	#8,d1
	lsr.l	#1,d0
	bne.s	Z10c
	 move.l	-(a0),d0
	 move	d4,ccr
	 roxr.l	#1,d0
Z10c:	bcs.s	Z110
	moveq	#12,d1
Z110:	bsr.s	Z132
	subq.w	#1,d3
Z114:	move.b	-1(a2,d2.l),-(a2)
	dbra	d3,Z114
	cmp.l	a2,a1
	blt	Z03a
Z122:	rts

Z132:	subq.w	#1,d1
	moveq	#0,d2
Z136:	lsr.l	#1,d0
	beq.s	Z142
	roxl.l	#1,d2
	dbra	d1,Z136
	rts
Z142:	move.l	-(a0),d0
	move	d4,ccr
	roxr.l	#1,d0
	roxl.l	#1,d2
	dbra	d1,Z136
	rts

rend:

sin255=rend		;$0100=  256
flax=sin255+$100	;$0568= 1384
blaj=flax+$568		;$18c0= 6336
umbspr=blaj+$18c0	;$02e8=  744
exp=umbspr+$2e8		;$33b8=13240
efter=exp+$33b8		;$b388=45960
uno=efter+$b388		;$6918=26904
Anim=uno+$6918		;$0320=  800
mt_data=anim+$320	;$8116=33046
Pr3=mt_data+$811a	;$28ec=10476
Pr5=Pr3+$28ec		;$87f0=34800
crun=Pr5+$8f70		;$1789c=96412
exend=crun+$1789c

Destination=Start+$2c00
LoadLength=[[Exend-DiskStart-$2c00]/$1600]+1

	end

