;*******************************************************
;*
;*	WATER-INTRO by HAEGAR / THRUST
;*       for KURIAKY from GOSLAR
;*	startdate: 10/24/88		>ri
;*					>DATCR
;*	enddate:   11/10/88		>CRUNCH
;*
;*	WATER_SHOCK © 1988 THRUST
;*
;*******************************************************

copperram = $7f000
spriteram = copperram - 2048
scrollfield = spriteram - 6000	;50 * 37 * 3
scrollfield2 = scrollfield - 6000
pic = scrollfield - 30000
font = pic - 42624
muzak = font - 52734
kdat = pic + 960
picr =	pic+3200
dat = muzak
trap:
	move.l #start,$80
	trap #0
	rts

start:
	move.w #$2700,sr
	movem.l d0-d7/a0-a6,-(sp)
	move.w	#$4000,$dff09a
;-------floppystop-------

	ori.b #$80,$bfd100
	ori.b #$8,$bfd100
	andi.b #$f7,$bfd100
	ori.b #$10,$bfd100
	andi.b #$ef,$bfd100

;	jsr	s

	lea	scrollfield2,a0
	lea	copperram,a1
cl_loop:
	clr.l	(a0)+
	cmp.l	a0,a1
	bge	cl_loop

	move.l	#sintab,a0
	move.l	#sintab_end,a1
	sub.l	a0,a1
	move.l	a1,d0
	move.w	d0,sintab_save

	bsr	prep_font

;------init haus

	move.l	#copperram,a0
	move.l	#newcopper,a1
	move.l	#bitplanes,a2
	sub.l	a1,a2
	add.l	a2,a0
	move.l	a0,bitplanes_ram

;-------	init scrollfield

	move.l	#scrollfield,d0
	move.l	#scrollplane,a0
	move.w	#2,d1
scroll_loop:
	swap	d0
	move.w	d0,2(a0)
	swap	d0
	move.w	d0,6(a0)
	add.l	#50,d0
	add.l	#8,a0
	dbra	d1,scroll_loop

	move.l	#scrollfield2,d0
	move.l	#scrollplane2,a0
	move.w	#2,d1
scroll_loop2:
	swap	d0
	move.w	d0,2(a0)
	swap	d0
	move.w	d0,6(a0)
	add.l	#50,d0
	add.l	#8,a0
	dbra	d1,scroll_loop2
	bsr	sprite_copy

;------------------------------------------------------------------
;	spritead to chip
;------------------------------------------------------------------

	lea	spritead,a0
	move.l	#spriteram,d0
	move.l	d0,(a0)+
	lea	sptab1,a1
	lea	sptab2,a2
	sub.l	a1,a2
	add.l	a2,d0
	move.l	d0,(a0)+
	lea	sptab2,a1
	lea	sptab3,a2
	sub.l	a1,a2
	add.l	a2,d0
	move.l	d0,(a0)+
	lea	sptab3,a1
	lea	sptab4,a2
	sub.l	a1,a2
	add.l	a2,d0
	move.l	d0,(a0)+
	lea	sptab4,a1
	lea	sptab5,a2
	sub.l	a1,a2
	add.l	a2,d0
	move.l	d0,(a0)+
	lea	sptab5,a1
	lea	sptab6,a2
	sub.l	a1,a2
	add.l	a2,d0
	move.l	d0,(a0)+
	lea	sptab6,a1
	lea	sptab7,a2
	sub.l	a1,a2
	add.l	a2,d0
	move.l	d0,(a0)+
	lea	sptab7,a1
	lea	sptab8,a2
	sub.l	a1,a2
	add.l	a2,d0
	move.l	d0,(a0)+

;------------------------------------------------------------------
;	write spritelist to copper
;------------------------------------------------------------------

	move.w	#$0120,d0
	lea	spritead,a0
	lea	sprite_pointer,a1
	move.w	#7,d2
sprite_pointer_loop:
	move.w	d0,(a1)+
	move.l	(a0)+,d1
	swap	d1
	move.w	d1,(a1)+
	add.w	#2,d0
	move.w	d0,(a1)+
	swap	d1
	move.w	d1,(a1)+
	add.w	#2,d0
	dbra	d2,sprite_pointer_loop		






	bsr copy_copper

	bsr	init_copperlist



	move.w #$80,$dff096
	move.l #copperram,$dff080
	clr.w $dff088
	move.w #$8080,$dff096

	bsr	start_muzak
wait:
	cmp.b #$a0,$dff006

	bne wait
	bsr	replay_muzak
	bsr	scroll_rout
	btst	#10,$dff016
	beq	no_scroll
	bsr	scroll_rout2

no_scroll:
	bsr	write_line
	bsr	asr_init
	bsr	stars
	move.b	$dff006,rast	;rast auslesen (byte)	
	btst #6,$bfe001		;soviel rasterzeilen braucht die
	bne wait		;intro

end:
	move.w #15,$dff096	;sound aus
copperinit:
	move.w	#-$4000,$dff09a
	move.l	4,a6
	move.l	#gfxname,a1
	jsr	-408(a6)
	move.l	d0,a1
	move.w #$80,$dff096
	move.l	38(a1),$dff080
	clr.w $dff088
	move.w #$8080,$dff096
	
	jsr	-414(a6)

	move.w #$8020,$dff096	;mouse an
	movem.l (a7)+,d0-d7/a0-a6
	move.w #$2000,sr
	rte
rast:	dc.w	0
gfxname:	dc.b	"graphics.library",0
	even
;********************************************************
;* waverout
;********************************************************
sintab_pointer:	dc.w	0
write_line:
	move.l	bitplanes_ram,a0
	move.l	#sintab,a1	;sintabelle
	add.w	#4,sintab_pointer	;erhoehe pointer
	move.w	sintab_save,d1
	move.w	sintab_pointer,d2	
	cmp.w	d1,d2
	ble	sintab_weiter
	move.w	#0,sintab_pointer
sintab_weiter:
	move.w	sintab_pointer,d0	;zeiger auf sintab
	
	move.l	#pic,d1		;bildadd
	move.w	#90,d4		;schleifen_zaehler
write_loop:
	moveq	#0,d2
	move.w	0(a1,d0.w),d2	;sin_nach d2
	tst.w	asr_
	bne	no_0
	moveq	#0,d2
no_0:
	move.w	#100,d6
	muls	asr_,d6
	add.w	#1000,d6
	divs	d6,d2
	mulu	#160,d2		;= zeile
	move.l	d1,d3	
	add.l	d2,d3		;zeile
	and.l	#$fffff,d3
	add.l	#4,a0		;offset copperlist to adresse bplpoin
	move.w	#3,d7		;little_loop
l_loop:
	swap	d3
	move.w	d3,2(a0)
	swap	d3
	move.w	d3,6(a0)
	add.l	#40,d3
	add.l	#8,a0
	dbra	d7,l_loop
	add.w	#6,d0
	sub.l	a3,a3
	move.w	d0,a3
	add.l	#sintab,a3
	move.l	#sintab_end,a4
	cmp.l	a3,a4
	bge	weiter_d0
	moveq	#0,d0
	weiter_d0:

	add.l	#160,d1
	dbra	d4,write_loop
rts

;------copy_copper---------------------
clear_copper:
	move.l #copperram,a0
clr_loop:
	clr.l	(a0)+
	cmp.l	#$7fff0,a0
	ble	clr_loop
	rts
copy_copper:
	move.l #copperram,a0
	move.l #newcopper,a1
	move.l #copper_end,a2
	copper_schleife:
	move.l (a1)+,(a0)+
	cmp.l a1,a2
	bge copper_schleife
	rts




;**************************************************
;*	asr_
;**************************************************

asr_init:
	sub.w	#1,asr_time
	tst.w	asr_time
	beq	asr_weiter
	rts
asr_weiter:
	move.w	asr_time_save,asr_time
	move.l	#asr_data,a0
	add.l	asr_pointer,a0
	move.w	(a0),asr_
	add.l	#2,asr_pointer
	move.l	#asr_dataend,d1
	move.l	#asr_data,d0
	add.l	asr_pointer,d0
	cmp.l	d0,d1
	ble	gleich
	rts
gleich:
	clr.l	asr_pointer
	rts

;**************************************************
;*	init copperliste
;**************************************************

init_copperlist:
	move.w	#90,d0		;schleifenzaehler
	move.l	bitplanes_ram,a0
	move.w	#$00e0,d1	;first bitplane
	move.l	#pic,d3		;picadd
	move.w	#$5307,d2	;wait_copper
init_copper_list:
	move.w	d1,d4		;save bitplaneadressedesti	

	move.w	d2,(a0)+	;write waitline
	move.w	#$fffe,(a0)+	;write waitmask
	move.w	d4,(a0)+	;first bitplane hi add
	swap	d3
	move.w	d3,(a0)+	;and write high
	add.w	#2,d4			;next adresse for bitplane
	move.w	d4,(a0)+	;and write
	swap	d3
	move.w	d3,(a0)+	;write low

	add.l	#40,d3			;next bitplane

	add.w	#2,d4

	move.w	d4,(a0)+	;first bitplane hi add
	swap	d3
	move.w	d3,(a0)+	;and write high
	add.w	#2,d4			;next adresse for bitplane
	move.w	d4,(a0)+	;and write
	swap	d3
	move.w	d3,(a0)+	;write low

	add.l	#40,d3			;next bitplane

	add.w	#2,d4

	move.w	d4,(a0)+	;first bitplane hi add
	swap	d3
	move.w	d3,(a0)+	;and write high
	add.w	#2,d4			;next adresse for bitplane
	move.w	d4,(a0)+	;and write
	swap	d3
	move.w	d3,(a0)+	;write low

	add.l	#40,d3			;next bitplane

	add.w	#2,d4
	
	move.w	d4,(a0)+	;first bitplane hi add
	swap	d3
	move.w	d3,(a0)+	;and write high
	add.w	#2,d4			;next adresse for bitplane
	move.w	d4,(a0)+	;and write
	swap	d3
	move.w	d3,(a0)+	;write low

	add.l	#40,d3			;next bitplane

	add.w	#2,d4


	add.w	#$100,d2
	dbra	d0,init_copper_list
	rts

;18 words

newcopper:
	dc.l	$0101fffe
	dc.l	$01800000
	dc.l	$008e2c79
	dc.l	$009031c9
	dc.l	$00920034
	dc.l	$009400cc
	dc.l	$01020000
	dc.l	$01040000
sprite_pointer:
	blk.l	16,0	

	dc.l	$01a20fff
	dc.l	$01aa0888
	dc.l	$2e07fffe
	dc.l	$01800005
	dc.l	$2f07fffe
	dc.l	$01800006
	dc.l	$3107fffe
	dc.l	$01800007
	dc.l	$3407fffe
	dc.l	$01800008
	dc.l	$3807fffe
	dc.l	$01800009
	dc.l	$3d07fffe
	dc.l	$0180000a
	dc.l	$4307fe00
	dc.l	$01000000
	dc.l	$01800009
	dc.l	$4807fffe
	dc.l	$01800008
	dc.l	$4c07fffe
	dc.l	$01800006
	dc.l	$4f07fffe
	dc.l	$01800004
	dc.l	$5107ffe
	dc.l	$01800003
	dc.l	$5207ffe
	dc.l	$01800004,$01820eca,$01840550,$01860770
	dc.l	$01880880,$018a0aa0,$018c0cb0,$018e0dd0
	dc.l	$01900ff0,$01920f0d,$01940d0c,$01960c0a
	dc.l	$01980a09,$019a0908,$019c0806,$019e0605
	dc.l	$52e1fffe
	dc.l	$01004200
	
bitplanes:
	blk.w	1638,0	
bpldma: 
	dc.l	$01004200


	dc.l	$b007fffe
	dc.l	$01000220
	dc.l	$01800113
	dc.l	$b107fffe
	dc.l	$01800220
	dc.l	$b307fffe

;color first font
	dc.l	$01820004
	dc.l	$01840006
	dc.l	$01860008
	dc.l	$0188000a
	dc.l	$018a000c
	dc.l	$018c000e
	dc.l	$018e000f

	dc.l	$01800330
	dc.l	$b607fffe
	dc.l	$01800440

	dc.l	$0108006a
	dc.l	$010a006a

	dc.l	$ba07fffe
	dc.l	$01800550

	dc.l	$008e2c71
	dc.l	$00902ce1
	dc.l	$00920030
	dc.l	$009400d8

	dc.l	$bf07fffe
	dc.l	$01800660
scrollplane:
	dc.l	$00e00000
	dc.l	$00e20000
	dc.l	$00e40000
	dc.l	$00e60000
	dc.l	$00e80000
	dc.l	$00ea0000

	dc.l	$c007fffe
	dc.l	$01003220
	dc.l	$e4e1fffe
	dc.l	$01000220

	dc.l	$e507fffe
	dc.l	$01800550
	dc.l	$ea07fffe
	dc.l	$01800440
	dc.l	$ee07fffe
	dc.l	$01800330
	dc.l	$f107fffe
	dc.l	$01800220
	dc.l	$f307fffe
	dc.l	$01800110
	dc.l	$f407fffe
	dc.l	$01800000
;scroll_II

	dc.l	$f607fffe
	dc.l	$01800000
	dc.l	$f907fffe
	dc.l	$01800000
	dc.l	$fd07fffe

;color second font
	dc.l	$01820400
	dc.l	$01840600
	dc.l	$01860800
	dc.l	$01880a00
	dc.l	$018a0c00
	dc.l	$018c0e00
	dc.l	$018e0f00


	dc.l	$01800000
	dc.l	$ffe1fffe
	dc.l	$0007fffe
	dc.l	$0207fffe
	dc.l	$01800000
	dc.l	$0307fffe
scrollplane2:
	dc.l	$00e00000
	dc.l	$00e20000
	dc.l	$00e40000
	dc.l	$00e60000
	dc.l	$00e80000
	dc.l	$00ea0000
	dc.l	$01003000




	dc.l	$27e1fffe
	dc.l	$01000000
	dc.l	$2807fffe
	dc.l	$01800000
	dc.l	$2d07fffe
	dc.l	$01800000
	dc.l	$3107fffe
	dc.l	$01800000

	dc.l	$3407fffe
	dc.l	$01800000
	dc.l	$3607fffe
	dc.l	$01800000
	dc.l	$3707fffe
	dc.l	$01800002
	dc.l	$fffffffe

copper_end:

sintab:	;86
	dc.l	$7fff7f80
	dc.l	$7ec17d34
	dc.l	$7b0b7848
	dc.l	$74ef7104
	dc.l	$6c8d678e
	dc.l	$620e5c13
	dc.l	$55a64ece
	dc.l	$47944000
	dc.l	$381d2ff3
	dc.l	$278e1ef7
	dc.l	$163a0d61
	dc.l	$0478023c
	dc.l	$04780d61
	dc.l	$163a1ef7
	dc.l	$278e2ff3
	dc.l	$381d4000
	dc.l	$47944ece
	dc.l	$55a65c13
	dc.l	$620e678e
	dc.l	$6c8d7104
	dc.l	$74ef7848
	dc.l	$7b0b7d34
	dc.l	$7ec17f80

sintab_end:
	dc.l	$7fff7fff
;*************************************
;*	data
;*************************************

sintab_save:	dc.w	0
data:
bitplanes_ram:	dc.l	0
;	hier ein paar werte reinschreiben von 1 bis 200
;	0 = stehen
asr_data:
	dc.w	0,0,0,0,0,0,0,0,0,0,0
	dc.w	0,0,400,350,300,280,260,230,200,175,150,130,110,100,90,80
	dc.w	70,65,60,55,50,45,40,37,34,31,28,25,22,20,18,16,14,12,10,8
	dc.w	7,6,5,4,3,2,1,1,2,3,4,5,6,7,8,10,12,14,16,18,20,22,25,28
	dc.w	31,34,37,40,45,50,55,60,65,70,80,90,100,110,130,150,175,200
	dc.w	230,260,280,300,350,400,400,400,400,0,0,0,0
asr_dataend:	
asr_:	dc.w	0
asr_pointer:	dc.l	0
asr_time:	dc.w	10
asr_time_save:	dc.w	30	;wie lange schwabbeln

****************************************************
*	scrollrout
****************************************************
prep_font:
	move.l	#font_tab,a0
	move.w	#63,d0
font_loop:
	moveq	#0,d1
	move.b	(a0,d0.w),d1
	bne	no_00
	move.b	#1,d1
	bra	o0
no_00:
	asr.b	#2,d1		;durch 4
o0:
	move.b	d1,(a0,d0.w)
	dbra	d0,font_loop
	rts

pixel:	dc.b	255
	even
zeiger:	dc.w	0
stop_time:	dc.w	0
	even

scroll_rout:
	
	tst.w	stop_time
	beq	scroll
	sub.w	#1,stop_time
	tst.w	stop_time
	bne	ende_scroll
scroll:
	bsr	blit_scrollfield	;scroll um 4 pixel
	sub.b	#1,pixel		;zeichen ende ?
	bne	ende_scroll		; nein
; get char
	moveq	#0,d2			;loesche datregister fuer char
	moveq	#0,d1
	move.w	zeiger,d1		;hole pointer
g_char:
	lea	scrolltext,a2		;scrolltext in a0
	move.b	(a2,d1.w),d2		;hole zeichen
	bne	no_stop
	move.b	1(a2,d1.w),d5
	asl.w	#8,d5
	move.b	2(a2,d1.w),d5
	move.w	d5,stop_time
	add.w	#3,d1	
	bra	g_char	
no_stop:	
	sub.b	#$20,d2			;loesche erste 64 zeichen
	lea	font_tab,a1		;font_tab fuer scrollen
	move.b	(a1,d2.w),pixel		;init scroll
	
; berechne zeichen
	lea	font,a1			;zeichensatz
	ext.w	d2
	move.l	d2,d3			;rette zeichenpointer
	divu	#8,d3			;zeile
	move.w	d3,d4			;rette zeile
	asl.w	#3,d3			; mal 8
	sub.w	d3,d2			;- -> spalte
	and.w	#$ffff,d4		;loesche highword
	mulu	#5328,d4		;zeile
	mulu	#6,d2

	add.l	d2,d4			;d4 = pointer char
	add.l	d4,a1

	bsr	blit_sign		;blitte_zeichen
zeiger_init:
	add.w	#1,d1
	cmp.b	#-1,(a2,d1.w)
	bne	no_scrollend
	moveq	#0,d1
no_scrollend:
	move.w	d1,zeiger
ende_scroll:
	rts

blit_scrollfield:
	btst	#14,$dff002
	bne	blit_scrollfield

	move.l	#scrollfield,$dff050	;source
	move.l	#scrollfield-2,$dff054	;dest
	clr.l	$dff064
	clr.w	$dff042
	move.l	#-1,$dff044
	move.w	#$c9f0,$dff040		;4 zeichen
	move.w	#%0001101111011010,$dff058
	rts

blit_sign:
	btst	#14,$dff002
	bne	blit_sign

	move.l	a1,$dff050
	move.l	#scrollfield+44,$dff054	
	move.w  #$2a,$dff064
	move.w	#$2c,$dff066
	move.l	#-1,$dff044
	clr.w	$dff042
	move.w	#$9f0,$dff040
	move.w	#%0001101111000011,$dff058
	rts


;	kuriaky font tabelle
;	384 breit * 296 hoch * 3 tief
;	
;	sonder
;
;	#	= 	Totenkopf
;	$	=	Shit
;	%	= 	Disk
;	&	=	TM
;	'	=	/
;	*	=	/
;	/	=	/
;	<	=	/
;	=	=	/
;	>	=	/
;	@	=	/
;	[	=	/
;	\	=	/
;	]	=	/
;	^	=	/
;	_	=	/

font_tab:
	dc.b	20,12,24,32,28,28,28,0
	dc.b	20,20,0,28,16,28,12,0
	dc.b	32,28,28,28,32,28,32,28
	dc.b	32,28,16,16,0,0,0,28
	dc.b	0,32,32,32,32,32,32,32
	dc.b	32,12,32,32,32,32,32,32
	dc.b	32,32,32,32,32,32,28,32
	dc.b	32,32,32,0,0,0,0,0

pixel2:	dc.b	255
	even
zeiger2:	dc.w	0
	even

scroll_rout2:
	bsr	blit_scrollfield2	;scroll um 4 pixel
	sub.b	#1,pixel2		;zeichen ende ?
	bne	ende_scroll2		; nein
; get char
	moveq	#0,d2			;loesche datregister fuer char
	moveq	#0,d1
	lea	scrolltext2,a2		;scrolltext in a0
	move.w	zeiger2,d1		;hole pointer
	move.b	(a2,d1.w),d2		;hole zeichen
	sub.b	#$20,d2			;loesche erste 64 zeichen
	lea	font_tab,a1		;font_tab fuer scrollen
	move.b	(a1,d2.w),d7
	asl.b	#1,d7
	move.b	d7,pixel2	;init scroll
	
; berechne zeichen
	lea	font,a1			;zeichensatz
	ext.w	d2
	move.l	d2,d3			;rette zeichenpointer
	divu	#8,d3			;zeile
	move.w	d3,d4			;rette zeile
	asl.w	#3,d3			; mal 8
	sub.w	d3,d2			;- -> spalte
	and.w	#$ffff,d4		;loesche highword
	mulu	#5328,d4		;zeile
	mulu	#6,d2

	add.l	d2,d4			;d4 = pointer char
	add.l	d4,a1

	bsr	blit_sign2		;blitte_zeichen
	add.w	#1,d1
	cmp.b	#-1,(a2,d1.w)
	bne	no_scrollend2
	moveq	#0,d1
no_scrollend2:
	move.w	d1,zeiger2
ende_scroll2:
	rts

blit_scrollfield2:
	btst	#14,$dff002
	bne	blit_scrollfield2

	move.l	#scrollfield2,$dff050	;source
	move.l	#scrollfield2-2,$dff054	;dest
	clr.l	$dff064
	clr.w	$dff042
	move.l	#-1,$dff044
	move.w	#$e9f0,$dff040		;4 zeichen
	move.w	#%0001101111011010,$dff058
	rts

blit_sign2:
	btst	#14,$dff002
	bne	blit_sign2

	move.l	a1,$dff050
	move.l	#scrollfield2+44,$dff054	
	move.w  #$2a,$dff064
	move.w	#$2c,$dff066
	move.l	#-1,$dff044
	clr.w	$dff042
	move.w	#$9f0,$dff040
	move.w	#%0001101111000011,$dff058
	rts

scrolltext:	; 	-->  " = $22

	dc.b    "  KURIAKY PRESENTS THEIR WATER - DEMO !! "

	dc.b	"  THRUST ?  ",0,1,0," NO HERE IS   KURIAKY    ",0,1,0
 	dc.b    "  THE GRAPHIX ARTISTS    WANT YOU PI"
	dc.b    "CTURES  BRUSHES OR SOMETHING ELSE ? THEN WRITE U"
   	dc.b    "S    WE PAINT FOR EVERYBODY AND LOSERS (ONL"
	dc.b    "Y FOR MONEY)    OUR HYPER PLK IS COMING       "
	dc.b    "PLK       ",0,1,0,"  025124 C   ",0,1,0,"     "
	dc.b    "  3380 GOSLAR",0,1,0,"   WRITE FAST OR DIE"
	dc.b    " NOW TO CREDITS ABOUT THE DEMO :  ",0,1,0,"   GRAPHIX"				

	DC.B    ":   ",0,1,0,"         KURIAKY   ",0,1,0,"    MUSIC:   ",0,1,0

	DC.B    "  VICTORY   ",0,1,0,"     CODINGS:    ",0,1,0
	DC.B    "   HAEGAR OF: ",0,1,0,"     THRUST   NOW,YOU MEAN"
	DC.B 	" THE SCHWABBEL-ROUTINE IS STOLEN ??? NOOO WE MADE"
	DC.B 	" IT LIKE THRUST ALREADY SAID :     OPEN"
	DC.B	" MONITOR      TAKE 2 GALLONS WATER     FILL YOUR"
	DC.B    " MONITOR     SHAKE IT     AND LOOK AT YOUR SCREEN"
	DC.B   	"     NOTHING HAPPENED BUT , YOUR MONITOR MUST BE "
	DC.B    "REPAIRED !! IN FACT , WE WAS ALLOWED TO USE THE"
	DC.B 	" SAME ROUTINE AS THRUST ! AT THE AOFCF WE MET "
	DC.B    "HAEGAR . WE ASKED HIM IF WE WAS ALLOWED TO USE "
	DC.B    "THIS SCHWABBEL-ROUTINE ! OHH FOR THE STUPID ONES"
	DC.B    ":    THE RED SCROLLER IS ABLE TO BE STOPPED BY"
	DC.B    " PRESSING THE RIGHT MOUSEBUTTON , IF YOU WANNA "
	DC.B 	"LEAVE THIS INTRO PRESS 3 KEYS .... OR PRESS THE"
	DC.B    " LEFT MOUSEBUTTON !!                 "
	
      
	
	dc.b	-1	;ende
even
scrolltext2:	; 	-->  " = $22
	
	dc.b	" YYYYEEEEEEEPPPPPPAAAAAA   HERE IS THE"
	dc.b	" NEW GROUP ON AMIGA    KURIAKY    WE M"
	dc.b    "AKE ONLY GRAPHIX   AND YOU CAN GET IT "
	dc.b    "FOR PAYING SOFTWARE OR 5 DM AND A % ... W" 
	dc.b    "AIT 1 WEEK AND YOU HAVE A WOUNDERFUL N"
	dc.b    "ICE PICTURE OR BRUSH OR CHARTSET AND T"
	dc.b    "HAT ALL FOR 5 MARK DEUTSCH......NOW CO"
	dc.b    "MES A HYPER SPECIAL GREETINGS TO HEAGE"
	dc.b    "R FROM THRUST   FOR THE GREAT HELP OF "
    	dc.b    "THIS WONDERFUL DEMO.......NOTE TO TMT "
  	dc.b    "MEMBER MADLORD .....  YOU ARE A $ BOY OF TMT "
	dc.b    "ALL THE OTHER MEMBERS OF TMT GET A MEG"
	dc.b    "A HELLO FROM ME....OHHH HELLO TOP BOYS"
	dc.b    ",AND VICTORY GET A LOVELY KISS FROM US"
 	dc.b    " FOR THE BEST SONG ALL OVER THE WORLD!"
	dc.b    " LORD EVIL WHAT ABOUT DEMO WE WANTED MAKE"
	dc.b    " TOGETHER???  HI POWER BOYS  DIE HARD #"
	dc.b    "  NOW THE LONG LIST OF GREETS: THRUST ,"
	dc.b    " SUNRIDERS , TTB , DOC , PROPHETES AG ,"
	dc.b    " DEADLINE , TGM CREW , AFL , MGF AND JO"
	dc.b    "Y , SNACKY OF PHR CREW , X-AMPLE , RED WAR"
	DC.B	" , MAD MONKS , TRISTAR , GENESIS PROJECT , "
	DC.B	" STRIKEFORCE , HOTLINE , OVERKILL , SHINING 8"
	DC.B	" , MANDY OF DREAMTEAM , IKARI , THE GUARDIANS"
	DC.B    " , MCG , NFC , LAZER , RAZOR , POWER RUN  , AMOK"
	DC.B    " , SUB ZERO , BYTERAPERS , FINISH GOLD , TMT , "
	DC.B	"LEGEND , MAGIC DISK , VEDA TEAM , SCRAP SYSTEMS "
	DC.B 	", SPHINX , ACKERLIGHT ... THAT WAS ALL FOR THIS"
	DC.B	" ... LAMERS , DONT WORRY THAT YOU ARENT AMONG THE"
	DC.B	" OTHERS ...... ! # JUBBA ! WHEN I SEE YOUR FETT"
	DC.B    "WAMPE , I COULD BREAK ON MY MACHINE #$  !!"
	DC.B    "  NOW YOU HAVE ENOUGH READ THIS TIME ! SWITCH"
	DC.B    " OFF YOUR MONITOR UND LEG EINE GEDENKPAUSE FUER "
	DC.B    " KURIAKY EIN ..DANKE YOUR KURIAKY ---- (C) BY KU"
 	dc.b    "RIAKY& 1988 .......# DIE HARD # ! ! ! ! ! !....."


   

	dc.b	-1	;ende
	even
stars:
		move.l 	#23,d2	;sprite1
		move.l	#spritead,a0
		move.l	(a0),a0
sprloop:
		move.w	(a0),d0
		add.b 	#$05,d0
		cmp.b 	#$e0,d0
		bne 	wei
		sub.b 	#$ae,d0
wei:		move.w 	d0,(a0)
		add.l 	#$08,a0
		dbra	d2,sprloop

		move.l 	#22,d2	;sprite2
		move.l	#spritead,a0
		move.l	4(a0),a0
sprloop1:
		move.w	(a0),d0
		add.b 	#$04,d0
		cmp.b 	#$e0,d0
		bne 	wei1
		sub.b 	#$ae,d0
wei1:		move.w 	d0,(a0)
		add.l 	#$08,a0
		dbra	d2,sprloop1

		move.l 	#42,d2	;sprite3
		move.l	#spritead,a0
		move.l	8(a0),a0
sprloop2:
		move.w	(a0),d0
		add.b 	#$03,d0
		cmp.b 	#$e0,d0
		bne 	wei2
		sub.b 	#$ae,d0
wei2:		move.w 	d0,(a0)
		add.l 	#$08,a0
		dbra	d2,sprloop2


		move.l 	#43,d2	;sprite4
		move.l	#spritead,a0
		move.l	12(a0),a0
sprloop3:
		move.w	(a0),d0
		add.b 	#$02,d0
		cmp.b 	#$e0,d0
		bne 	wei3
		sub.b 	#$ae,d0
wei3:		move.w 	d0,(a0)
		add.l 	#$08,a0
		dbra	d2,sprloop3



		move.l 	#22,d2	;sprite5
		move.l	#spritead,a0
		move.l	16(a0),a0
sprloop4:
		move.w	(a0),d0
		add.b 	#$01,d0
		cmp.b 	#$e0,d0
		bne 	wei4
		sub.b 	#$ae,d0
wei4:		move.w 	d0,(a0)
		add.l 	#$08,a0
		dbra	d2,sprloop4


lloop:
	rts



sprite_copy:
	move.l #spriteram,a0
	move.l #sp_an,a1
	move.l #sp_aus,a2
sprite_schleife:
	move.l (a1)+,(a0)+
	cmp.l a1,a2
	bge sprite_schleife
	rts

star_zaehler_tab:	dc.w	0

star_zaehler:	dc.w	8
control_scrollbit:	dc.w	0
sp_color2_ram:	dc.l	0
sp_color1_ram:	dc.l	0
sp_color3_ram:	dc.l	0
action_ram:	dc.l 0


spritead:	blk.l	8,0

sp_an:
sptab1:
spr15:	dc.w $5350,$5400
	dc.w $0001,$0000
spr16:	dc.w $5890,$5900
	dc.w $0001,$0000
spr17:	dc.w $5c70,$5d00
	dc.w $0001,$0000
spr18:	dc.w $6040,$6100
	dc.w $0001,$0000
spr19:	dc.w $64d0,$6500
	dc.w $0001,$0000
spr1a:	dc.w $6820,$6900
	dc.w $0001,$0000
spr1b:	dc.w $6c80,$6d00
	dc.w $0001,$0000
spr1c:	dc.w $7062,$7100
	dc.w $0001,$0000
spr1d:	dc.w $7432,$7500
	dc.w $0001,$0000
spr1e:	dc.w $78b6,$7900
	dc.w $0001,$0000
spr1f:	dc.w $7c76,$7d00
	dc.w $0001,$0000
spr100:	dc.w $803e,$8100
	dc.w $0001,$0000
spr101:	dc.w $84b0,$8500
	dc.w $0001,$0000
spr102:	dc.w $8854,$8900
	dc.w $0001,$0000
spr103:	dc.w $8cc0,$8d00
	dc.w $0001,$0000
spr104:	dc.w $90a0,$9100
	dc.w $0001,$0000
spr105:	dc.w $9450,$9500
	dc.w $0001,$0000
spr106:	dc.w $9890,$9900
	dc.w $0001,$0000
spr107:	dc.w $9c70,$9d00
	dc.w $0001,$0000
spr10e:	dc.w $a3b6,$a400
	dc.w $0001,$0000
spr10f:	dc.w $a776,$a800
	dc.w $0001,$0000
spr110:	dc.w $aa3e,$ab00
	dc.w $0001,$0000
spr111:	dc.w $aeb0,$af00
	dc.w $0001,$0000
	dc.w $0000,$0000

sptab2:
spr29:	dc.w $57d3,$5800
	dc.w $0001,$0000
spr23:	dc.w $5b45,$5c00
	dc.w $0001,$0000
spr26:	dc.w $5f87,$6000
	dc.w $0001,$0000
spr2a:	dc.w $63a7,$6400
	dc.w $0001,$0000
spr27:	dc.w $6736,$6800
	dc.w $0001,$0000
spr28:	dc.w $6b9a,$6c00
	dc.w $0001,$0000
spr2c:	dc.w $6fb6,$7000
	dc.w $0001,$0000
spr2d:	dc.w $7352,$7400
	dc.w $0001,$0000
spr2e:	dc.w $7731,$7800
	dc.w $0001,$0000
spr2f:	dc.w $7bc8,$7c00
	dc.w $0001,$0000
spr200:	dc.w $7fd0,$8000
	dc.w $0001,$0000
spr205:	dc.w $8334,$8400
	dc.w $0001,$0000
spr204:	dc.w $8762,$8800
	dc.w $0001,$0000
spr20b:	dc.w $8bb4,$8c00
	dc.w $0001,$0000
spr201:	dc.w $9f87,$9000
	dc.w $0001,$0000
spr202:	dc.w $9330,$9400
	dc.w $0001,$0000
spr209:	dc.w $97d3,$9800
	dc.w $0001,$0000
spr203:	dc.w $9b45,$9c00
	dc.w $0001,$0000
spr206:	dc.w $9f82,$a000
	dc.w $0001,$0000
spr20e:	dc.w $a331,$a400
	dc.w $0001,$0000
spr20f:	dc.w $a7c8,$a800
	dc.w $0001,$0000
spr210:	dc.w $abd0,$8c00
	dc.w $0001,$0000
spr215:	dc.w $b334,$b400
	dc.w $0001,$0000
spr214:	dc.w $b792,$b800
	dc.w $0001,$0000
	dc.w $0000,$0000

sptab3:
spr32:	dc.w $5636,$5700
	dc.w $0001,$0000
spr306:	dc.w $585e,$5900
	dc.w $0001,$0000
spr39:	dc.w $5aac,$5b00
	dc.w $0001,$0000
spr307:	dc.w $5c48,$5d00
	dc.w $0001,$0000
spr33:	dc.w $5e90,$5f00
	dc.w $0001,$0000
spr308:	dc.w $605e,$6100
	dc.w $0001,$0000
spr36:	dc.w $6246,$6300
	dc.w $0001,$0000
spr309:	dc.w $64d0,$6500
	dc.w $0001,$0000
spr3a:	dc.w $6670,$6700
	dc.w $0001,$0000
spr30a:	dc.w $683e,$6900
	dc.w $0001,$0000
spr37:	dc.w $6acd,$6b00
	dc.w $0001,$0000
spr30b:	dc.w $6c50,$6d00
	dc.w $0001,$0000
spr38:	dc.w $6e4a,$6f00
	dc.w $0001,$0000
spr30c:	dc.w $70db,$7100
	dc.w $0001,$0000
spr3c:	dc.w $7233,$7300
	dc.w $0001,$0000
spr30d:	dc.w $74af,$7500
	dc.w $0001,$0000
spr3d:	dc.w $7677,$7700
	dc.w $0001,$0000
spr30e:	dc.w $7840,$7900
	dc.w $0001,$0000
spr3e:	dc.w $7a4c,$7b00
	dc.w $0001,$0000
spr30f:	dc.w $7cb1,$7d00
	dc.w $0001,$0000
spr3f:	dc.w $7eaf,$7f00
	dc.w $0001,$0000
spr310:	dc.w $8042,$8100
	dc.w $0001,$0000
spr314:	dc.w $8240,$8300
	dc.w $0001,$0000
spr311:	dc.w $84b3,$8500
	dc.w $0001,$0000
spr312:	dc.w $869e,$8700
	dc.w $0001,$0000
spr313:	dc.w $8860,$8900
	dc.w $0001,$0000
spr315:	dc.w $8a37,$8b00
	dc.w $0001,$0000
spr316:	dc.w $8c72,$8d00
	dc.w $0001,$0000
spr317:	dc.w $8ed3,$8f00
	dc.w $0001,$0000
spr318:	dc.w $90a4,$9100
	dc.w $0001,$0000
spr319:	dc.w $9267,$9300
	dc.w $0001,$0000
spr31a:	dc.w $94c0,$9500
	dc.w $0001,$0000
spr31b:	dc.w $9636,$9700
	dc.w $0001,$0000
spr31c:	dc.w $985e,$9900
	dc.w $0001,$0000
spr31d:	dc.w $9aac,$9b00
	dc.w $0001,$0000
spr31e:	dc.w $9c48,$9d00
	dc.w $0001,$0000
spr31f:	dc.w $9e90,$9f00
	dc.w $0001,$0000
spr32b:	dc.w $a377,$a400
	dc.w $0001,$0000
spr32c:	dc.w $a840,$a900
	dc.w $0001,$0000
spr32d:	dc.w $aa4c,$ab00
	dc.w $0001,$0000
spr32f:	dc.w $acb1,$ad00
	dc.w $0001,$0000
spr330:	dc.w $aeaf,$af00
	dc.w $0001,$0000
	dc.w $0000,$0000

sptab4:
spr405:	dc.w $5559,$5600
	dc.w $0001,$0000
spr42:	dc.w $57a2,$5800
	dc.w $0001,$0000
spr406:	dc.w $5941,$5a00
	dc.w $0001,$0000
spr49:	dc.w $5b94,$5c00
	dc.w $0001,$0000
spr407:	dc.w $5d54,$5e00
	dc.w $0001,$0000
spr43:	dc.w $6f43,$6000
	dc.w $0001,$0000
spr408:	dc.w $61d6,$6200
	dc.w $0001,$0000
spr46:	dc.w $6376,$6400
	dc.w $0001,$0000
spr409:	dc.w $6530,$6600
	dc.w $0001,$0000
spr4a:	dc.w $67c3,$6800
	dc.w $0001,$0000
spr40a:	dc.w $695f,$6a00
	dc.w $0001,$0000
spr47:	dc.w $6b45,$6c00
	dc.w $0001,$0000
spr40b:	dc.w $6dd3,$6e00
	dc.w $0001,$0000
spr48:	dc.w $6f30,$7000
	dc.w $0001,$0000
spr40c:	dc.w $71a4,$7200
	dc.w $0001,$0000
spr4c:	dc.w $7376,$7400
	dc.w $0001,$0000
spr40d:	dc.w $754e,$7600
	dc.w $0001,$0000
spr4d:	dc.w $7741,$7800
	dc.w $0001,$0000
spr40e:	dc.w $79ba,$7a00
	dc.w $0001,$0000
spr4e:	dc.w $7ba6,$7c00
	dc.w $0001,$0000
spr40f:	dc.w $7d47,$7e00
	dc.w $0001,$0000
spr4f:	dc.w $7fcf,$8000
	dc.w $0001,$0000
spr410:	dc.w $816a,$8200
	dc.w $0001,$0000
spr411:	dc.w $839a,$8400
	dc.w $0001,$0000
spr412:	dc.w $8562,$8600
	dc.w $0001,$0000
spr413:	dc.w $8743,$8800
	dc.w $0001,$0000
spr414:	dc.w $897a,$8a00
	dc.w $0001,$0000
spr415:	dc.w $8bd8,$8c00
	dc.w $0001,$0000
spr416:	dc.w $8dae,$8e00
	dc.w $0001,$0000
spr417:	dc.w $8f67,$9000
	dc.w $0001,$0000
spr418:	dc.w $91c2,$9200
	dc.w $0001,$0000
spr419:	dc.w $9334,$9400
	dc.w $0001,$0000
spr41a:	dc.w $9559,$9600
	dc.w $0001,$0000
spr41b:	dc.w $97a2,$9800
	dc.w $0001,$0000
spr41c:	dc.w $9941,$9a00
	dc.w $0001,$0000
spr41d:	dc.w $9b94,$9c00
	dc.w $0001,$0000
spr41e:	dc.w $9d54,$9e00
	dc.w $0001,$0000
spr41f:	dc.w $9f43,$a000
	dc.w $0001,$0000
spr42a:	dc.w $a54e,$a600
	dc.w $0001,$0000
spr42b:	dc.w $a741,$a800
	dc.w $0001,$0000
spr42c:	dc.w $a9ba,$aa00
	dc.w $0001,$0000
spr42d:	dc.w $aba6,$ac00
	dc.w $0001,$0000
spr42e:	dc.w $ad47,$ae00
	dc.w $0001,$0000
spr42f:	dc.w $afcf,$b000
	dc.w $0001,$0000
	dc.w $0000,$0000

sptab5:
spr50:	dc.w $57a0,$5800
	dc.w $0001,$0000
	dc.w $5940,$5a00
	dc.w $0001,$0000
	dc.w $5b90,$5c00
	dc.w $0001,$0000
	dc.w $5e50,$5f00
	dc.w $0001,$0000
	dc.w $6040,$6100
	dc.w $0001,$0000
	dc.w $62d0,$6300
	dc.w $0001,$0000
	dc.w $6470,$6500
	dc.w $0001,$0000
	dc.w $6638,$6700
	dc.w $0001,$0000
	dc.w $68c0,$6900
	dc.w $0001,$0000
	dc.w $6a58,$6b00
	dc.w $0001,$0000
	dc.w $6c40,$6d00
	dc.w $0001,$0000
	dc.w $6ed0,$6f00
	dc.w $0001,$0000
	dc.w $7038,$7100
	dc.w $0001,$0000
	dc.w $724f,$7300
	dc.w $0001,$0000
	dc.w $7470,$7500
	dc.w $0001,$0000
	dc.w $7640,$7700
	dc.w $0001,$0000
	dc.w $7844,$7900
	dc.w $0001,$0000
	dc.w $7abf,$7b00
	dc.w $0001,$0000
	dc.w $7ca0,$7d00
	dc.w $0001,$0000
	dc.w $7e40,$7f00
	dc.w $0001,$0000
	dc.w $80c8,$8100
	dc.w $0001,$0000
	dc.w $826f,$8300
	dc.w $0001,$0000
	dc.w $0000,$0000

sptab6:
spr606:	dc.w $4550,$4600
	dc.w $0000,$0000
spr69:	dc.w $0000,$0000

sptab7:
sptab8:
spr4t8:	dc.w $0150,$0200
	dc.w $0000,$0000
	dc.w $0000,$0000
sp_aus:
;------------------------------------------------------------------


start_muzak:
	move.l	#muzak,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(pc),a1
	lsl.l	#8,d2
	lsl.l	#2,d2
	add.l	#600,d2
	add.l	a0,d2
	moveq	#14,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:	clr.w	$dff0a8			;** clear used values
	clr.w	$dff0b8
	clr.w	$dff0c8
	clr.w	$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
	rts
stop_muzak:
	clr.w	$dff0a8
	clr.w	$dff0b8
	clr.w	$dff0c8
	clr.w	$dff0d8
	move.w	#$f,$dff096
	rts
replay_muzak:
	movem.l	d0-d7/a0-a6,-(a7)
	addq.w	#1,timpos
speed:	cmp.w	#6,timpos
	beq.L	replaystep
chaneleffects:				;** seek effects
	lea	datach0(pc),a6
	tst.b	3(a6)
	beq.s	ceff1
	lea	$dff0a0,a5
	bsr.s	ceff5
ceff1:	lea	datach1(pc),a6
	tst.b	3(a6)
	beq.s	ceff2
	lea	$dff0b0,a5
	bsr.s	ceff5
ceff2:	lea	datach2(pc),a6
	tst.b	3(a6)
	beq.s	ceff3
	lea	$dff0c0,a5
	bsr.s	ceff5
ceff3:	lea	datach3(pc),a6
	tst.b	3(a6)
	beq.s	ceff4
	lea	$dff0d0,a5
	bsr.s	ceff5
ceff4:	movem.l	(a7)+,d0-d7/a0-a6
	rts
ceff5:	move.b	2(a6),d0		;room for some more
	and.b	#$f,d0			;implementations below
	tst.b	d0
	beq.s	arpreggiato
	cmp.b	#1,d0
	beq.L	pitchup
	cmp.b	#2,d0
	beq.L	pitchdown
	cmp.b	#12,d0
	beq.L	setvol
	cmp.b	#14,d0
	beq.L	setfilt
	cmp.b	#15,d0
	beq.L	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	#$f,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.s	newrou
	clr.l	d0
	move.b	3(a6),d0
	and.b	#$f,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.s	newrou
	clr.l	d0
	move.b	3(a6),d0
	and.b	#$f,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	#1,d0
	lsl.b	#1,d0
	and.b	#$fd,$bfe001
	or.b	d0,$bfe001
	rts
setspeed:
	clr.l	d0
	move.b	3(a6),d0
	and.b	#$f,d0
	move.w	d0,speed+2
	rts
newrou:	cmp.l	#datach0,a6
	bne.s	next1
	lea	voi1(pc),a4
	rts
next1:	cmp.l	#datach1,a6
	bne.s	next2
	lea	voi2(pc),a4
	rts
next2:	cmp.l	#datach2,a6
	bne.s	next3
	lea	voi3(pc),a4
	rts
next3:	lea	voi4(pc),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
	lsl.l	#8,d1
	lsl.l	#2,d1
	add.l	patpos,d1		;get ptr to current step
	clr.w	enbits
	lea	$dff0a0,a5		;chanel 0
	lea	datach0(pc),a6
	bsr.L	chanelhandler
	lea	$dff0b0,a5		;chanel 1
	lea	datach1(pc),a6
	bsr.L	chanelhandler
	lea	$dff0c0,a5		;chanel 2
	lea	datach2(pc),a6
	bsr.L	chanelhandler
	lea	$dff0d0,a5		;chanel 3
	lea	datach3(pc),a6
	bsr.L	chanelhandler
	move.w	#400,d0			;** wait a while and set len
rep1:	dbf	d0,rep1			;   of oneshot to 1 word
	move.w	#$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.s	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.s	rep6
	clr.l	trkpos
rep6:	movem.l	(a7)+,d0-d7/a0-a6
	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.L	chan2			;no soundchange !
	move.l	d2,d4			;** calc ptr to sample
	lsl.l	#2,d2
	mulu	#30,d4
	lea	pointers-4(pc),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)

	tst.b	1(a6)
	beq.S	keinstep
nokan0:	cmp.l	#$dff0a0,a5
	bne.S	nokan1
	move.l	#$f,xchan0	
	bra.S	keinstep
nokan1:	cmp.l	#$dff0b0,a5
	bne.S	nokan2
	move.l	#$f,xchan1	
	bra.S	keinstep
nokan2:	cmp.l	#$dff0c0,a5
	bne.S	nokan3
	move.l	#$f,xchan2	
	bra.S	keinstep
nokan3:	cmp.l	#$dff0d0,a5
	bne.S	nokan4
	move.l	#$f,xchan3	
	bra.W	keinstep
nokan4:
keinstep:move.b	2(a6),d0
	and.b	#$f,d0
	cmp.b	#$c,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:	tst.w	(a6)
	beq.s	chan4			;no new note set !
	move.w	22(a6),$dff096		;clear dma
	tst.w	14(a6)
	bne.s	chan3			;no oneshot-sample
	move.w	#1,14(a6)		;allow resume (later)
chan3:	bsr.L	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:	blk.w	11,0
		dc.w	1
datach1:	blk.w	11,0
		dc.w	2
datach2:	blk.w	11,0
		dc.w	4
datach3:	blk.w	11,0
		dc.w	8
voi1:		dc.w	0
voi2:		dc.w	0
voi3:		dc.w	0
voi4:		dc.w	0
pointers:	blk.l	15,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
trkpos:		dc.l	0
patpos:		dc.l	0
numpat:		dc.w	0
enbits:		dc.w	0
timpos:		dc.w	0

xchan0:		dc.l	1
xchan1:		dc.l	1
xchan2:		dc.l	1
xchan3:		dc.l	1



s:
	move.l #crunch_end,a0
	move.l #dat,a1		
	move.l -(a0),a2		
	add.l a1,a2		
	move.l -(a0),d5		
	move.l -(a0),d0		
	eor.l d0,d5		

notfinished:
	lsr.l #1,d0
	bne.S notempty1
	bsr getnextlwd
notempty1:
	bcs.S bigone		

	moveq #8,d1	
	moveq #1,d3	
	lsr.l #1,d0
	bne.S notempty2
	bsr getnextlwd
notempty2:
	bcs.S dodupl	

	moveq #3,d1	
	clr.w d4	

dojmp:		
		
	bsr rdd1bits	
	move.w d2,d3	
	add.w d4,d3	

getd3chr:

	moveq #7,d1	
get8bits:
	lsr.l #1,d0
	bne.S notempty3
	bsr getnextlwd
notempty3:
	roxl.l #1,d2
	dbf d1,get8bits	

	move.b d2,-(a2)
	dbf d3,getd3chr	
	bra nextcmd

bigjmp:
	moveq #8,d1	
	moveq #8,d4	
		
		
		
	bra dojmp

bigone:
	moveq #2,d1	
	bsr rdd1bits
	cmp.b #2,d2	
	blt.S midjumps	
	cmp.b #3,d2	
	beq.S bigjmp	


	moveq #8,d1	
	bsr rdd1bits	
	move.w d2,d3	
	move.w #12,d1	
	bra dodupl	

midjumps:
	move.w #9,d1	
	add.w d2,d1
	addq #2,d2
	move.w d2,d3	
	
dodupl:
	bsr rdd1bits	
		
		
copyd3bytes:
	subq #1,a2

	move.b (a2,d2.w),(a2)

	dbf d3,copyd3bytes

nextcmd:
	cmp.l a2,a1
	blt.L notfinished
	rts


getnextlwd:
	move.l -(a0),d0
	eor.l d0,d5
	move.w #$10,ccr
	roxr.l #1,d0
	rts

rdd1bits:	
	subq.w #1,d1
	clr.w d2

getbits:
	lsr.l #1,d0
	bne.S notempty
	move.l -(a0),d0
	eor.l d0,d5
	move.w #$10,ccr
	roxr.l #1,d0

notempty:
	roxl.l #1,d2
	dbf d1,getbits
	rts
crunch:
	;blk.b	55220,0
crunch_end:
