****************************************************************
*                                                              *
*     THE_SIN_INTRO_II  by HAEGAR/LORD PERFORMER of THRUST     *
*                                                              *
*     start	:	08/24/88			       *
*     end 	:	08/26/88			       *
*     muzak	:	LORD PERFORMER			       *
*                                                              *
*     ŠOPYRIGHT 1988   	T H R U S T                            *
*                                                              *
****************************************************************

;RI	'SINDATCR'	nach	'CRUNCH'
;VOR 'WO'	'JTEXT' und semikolon in zeile 46 rausmachen

;brush = 320 * 44 *3bpl
copperram = $7e000
flip = copperram - 2000
screen = flip - 27200 
scrollscreen = screen - 17000
screen_brush = scrollscreen - 28800	
screen_brush_end = screen_brush + 7040
fontram = screen_brush - 16128 
sinline = screen - 3680   
clear_line = sinline + 76
muzak=	fontram-50000
clear = screen_brush_end
dat = muzak
mit = screen_brush + 3520
beg:	move.l #start,$80
	trap #0
	rts

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

;-------floppystop-------

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

;****************************
;	init_copper_for turn
;****************************
	;find turn
	move.l	#copperram,a0
	move.l	#turn,a1
	move.l	#newcopper,a2
	sub.l	a2,a1
	add.l	a1,a0
	move.l	a0,turn_ram
	bsr	init_turn

;****************************
;	clear_blit
;****************************

	move.l	#screen_brush_end,a0
	move.l	#copperram,a1
clear_loop:
	clr.l	(a0)+
	cmp.l	a0,a1
	bhi	clear_loop
	bsr	msin
	bsr copy_copper
	bsr fillit
	bsr start_muzak
	
	move.w #$80,$dff096
	move.l #copperram,$dff080
	clr.w $dff088
	move.w #$8080,$dff096

;testtab
;	cmp.b	$bfec01
;85 = 7	
;83 = 8	
;81 = 9	
;a5 = 4	
;a3 = 5	
;a1 = 6
;c5 = 1
;c3 = 2
;c1 = 3

wait:
	cmp.b #$24,$dff006
	bne wait
	bsr	sin_move
	bsr	scroll_rout

	bsr	replay_muzak
	bsr	blitze
	bsr	lpa
	tst.w	scrollcont
	beq	no_tast
	cmp.b	#$85,$bfec01
	beq	tc7
	cmp.b	#$81,$bfec01
	beq	tc9
	cmp.b	#$a5,$bfec01
	beq	tc4
	cmp.b	#$a1,$bfec01
	beq	tc6
	cmp.b	#$c5,$bfec01
	beq	tc1
	cmp.b	#$c1,$bfec01
	beq	tc3
back_tast:
no_tast:
	btst #6,$bfe001
	bne wait
	btst #10,$dff016
	beq wait

end:
	move.w #15,$dff096	;sound aus
copperinit:
	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
	rte

gfxname:	dc.b	"graphics.library",0
even
tast_time:	dc.w	0
deck_con:	dc.w	0
deck_counter:	dc.w	93

turn_ram:	dc.l	0
tc9:
add.w	#2,val_a
cmp.w	#30,val_a
ble	weiter_tc9
move.w	#30,val_a
weiter_tc9:
bra	back_tast
tc7:
sub.w	#2,val_a
cmp.w	#0,val_a
bge	weiter_tc7
clr.w	val_a
weiter_tc7:
bra	back_tast
tc6:
add.w	#2,val_b
cmp.w	#20,val_b
ble	weiter_tc6
move.w	#20,val_b
weiter_tc6:
bra	back_tast
tc4:
sub.w	#2,val_b
cmp.w	#0,val_b
bge	weiter_tc4
clr.w	val_b
weiter_tc4:
bra	back_tast
tc3:
add.w	#100,divi
cmp.w	#10000,divi
ble	weiter_tc3
move.w	#10000,divi
weiter_tc3:
bra	back_tast
tc1:
sub.w	#100,divi
cmp.w	#1500,divi
bge	weiter_tc1
move.w	#1500,divi
weiter_tc1:
bra	back_tast
;*****************************
;	tast
;*****************************
tast_an:
move.w	#1,scrollcont
add.l	#1,zeiger
bra	get_sign
tast_aus:
clr.w	scrollcont
add.l	#1,zeiger
bra	get_sign

c9:
add.w	#2,val_a
cmp.w	#30,val_a
ble	weiter_c9
move.w	#30,val_a
weiter_c9:
add.l	#1,zeiger
bra	get_sign
c7:
sub.w	#2,val_a
cmp.w	#0,val_a
bge	weiter_c7
clr.w	val_a
weiter_c7:
add.l	#1,zeiger
bra	get_sign
c6:
add.w	#2,val_b
cmp.w	#20,val_b
ble	weiter_c6
move.w	#20,val_b
weiter_c6:
add.l	#1,zeiger
bra	get_sign
c4:
sub.w	#2,val_b
cmp.w	#0,val_b
bge	weiter_c4
clr.w	val_b
weiter_c4:
add.l	#1,zeiger
bra	get_sign
c3:
add.w	#100,divi
cmp.w	#10000,divi
ble	weiter_c3
move.w	#10000,divi
weiter_c3:
add.l	#1,zeiger
bra	get_sign
c1:
sub.w	#100,divi
cmp.w	#1500,divi
bge	weiter_c1
move.w	#1500,divi
weiter_c1:
add.l	#1,zeiger
bra	get_sign

nichts:
add.l	#1,zeiger
bra	get_sign


;********************************
;	scrollrout
;********************************
deck_o:	dc.l	0


scroll_rout:

;-------time_scroll---------
tst.w scroll_time
beq scroll_sign_l
move.w scroll_time,d0
sub.w #1,d0
move.w d0,scroll_time
cmp.w #0,d0
bne ende
scroll_sign_l:
move.l #fontram,zeichensatz
bsr blit
sub.b	#$01,pixel
bne.L	ende
bsr blitpixel_scroll
move.b	#4,pixel
get_sign:
move.l #scrolltext,a0
add.l	deck_o,a0
add.l zeiger,a0
moveq	#0,d0
move.b (a0),d0
;test auf tast
cmp.b	#10,d0
beq	tast_an
cmp.b	#11,d0
beq	tast_aus
tast1_back:
cmp.w	#1,scrollcont
beq	tast_back





cmp.b	#1,d0
beq	c1
cmp.b	#3,d0
beq	c3
cmp.b	#4,d0
beq	c4
cmp.b	#6,d0
beq	c6
cmp.b	#7,d0
beq	c7
cmp.b	#9,d0
beq	c9
tast_back:

cmp.b #0,d0
bne weiter_o
add.l #1,a0
moveq	#0,d5
move.b (a0),d5
asl.w	#8,d5
move.b	1(a0),d5
move.w	d5,scroll_time
add.l #3,zeiger
bra get_sign
weiter_o:

cmp.b #$40,d0
ble weiter_i
move.l zeichensatz,d7
add.l #8064+124,d7
move.l d7,zeichensatz
weiter_i:
sub.b #$20,d0
asl #2,d0
add.l zeichensatz,d0
move.l d0,sign_scroll
addq.l	#$01,zeiger
cmp.l	#endtext-1,a0
blt.L	ende
clr.l	zeiger
move.l	#2,deck_o
move.w	#8,val_a
move.w	#20,val_b
move.w	#3000,divi
ende:
rts
sign_blit: dc.l 0
sign_ziel: dc.l 0
zeichensatz:	dc.l	0
blit:
bsr blitwait

move.l 		#scrollscreen+4032,$dff050	;A 
move.l		#scrollscreen+4030,$dff054 ;D
clr.l		$dff064
clr.w		$dff042
move.l		#$ffffffff,$dff044
move.w		#$89f0,$dff040	;bltcon1
move.w		#%0000111110101010,$dff058	;high&bright
;	          hhhhhhhhhhwwwwww		;10bit=1024lines
						;6bit =64*16bit=1024br
rts
blitpixel_scroll:
bsr blitwait
move.l		sign_scroll,$dff050
move.l		#scrollscreen+4032+80,$dff054
move.w		#$7a,$dff064
move.w		#$50,$dff066
clr.w		$dff042
move.l		#$ffffffff,$dff044
move.w		#$9f0,$dff040
move.w		#%0001000000000010,$dff058
rts
rts
pixel: dc.b 8
even
zeiger: dc.l 0
even
scrollcont:	dc.w	0
;	10 = tast an steuercode aus
;	11 = tast aus steuercode an
scrolltext:
DC.B "#      ",10,"                      "	;DIESE ZEILE MUSS SEIN
DC.B "                 THRUST PRESENT       NEW  STUFF      ",0,0,100
DC.B "     CALL OUR BBS IN CANADA ...      416-481-9455     ",0,0,100
DC.B "24 H  ONLINE ...   300   1200   2400  AND  9600     BAUD !!"
DC.B "              "
DC.B "IF YOU WANT TO CONTACT US WRITE TO    PLK 007553 D     ",0,0,110
DC.B "     8510 FUERTH     ",0,0,110,"      WEST-GERMANY     ",0,0,60
DC.B "                "
R > GREETS > to this place !
endtext:
even
text_checker:
move.l	#scrolltext,a0
move.l	#endtext,a1
moveq	#0,d0
text_loop:
add.w	(a0)+,d0
cmp.l	a0,a1
bge	text_loop
move.w	d0,d1
swap	d0
add.w	d1,d0
move.w	d0,test
move.w	text_val,d1
cmp.w	d0,d1
bne	reset
rts
reset:
bra	killer
text:
move.l	#scrolltext,a0
move.l	#endtext,a1
moveq	#0,d0
text__loop:
add.w	(a0)+,d0
cmp.l	a0,a1
bge	text__loop
move.w	d0,d1
swap	d0
add.w	d1,d0
move.w	d0,text_val
rts
killer:
move.l	#$7f000,a0
move.l	#killdat,a1
move.l	#killdat_end,a2
kill_loop:
move.l	(a1)+,(a0)+
cmp.l	a1,a2
bge	kill_loop
move.l	#$7f000,a0
jmp	(a0)

killdat:	
	dc.l	$207c0007,$eff0227c,$00000000,$33f900df
	dc.l	$f18000df,$f18042a0,$6000fff2,$00000000

killdat_end:
dc.l
text_val:	dc.w	0	
eor:		dc.w	$5678
even
sign_scroll: dc.l fontram

scroll_time: dc.w 0

blitwait:
btst #14,$dff002
bne blitwait
rts


sin_blit_deck_l:
bsr blitwait
add.l	#3520,d6
move.l		#fontram+12,$dff050
move.l		d6,$dff054
move.w		#$7a,$dff064
move.w		#$4c,$dff066
clr.w		$dff042
move.l		#$ffffffff,$dff044
move.w		#$9f0,$dff040
move.w		#%0001000100000010,$dff058
rts
sin_deck_r:
bsr blitwait
add.l	#3680,d6
move.l		#fontram+16,$dff050
move.l		d6,$dff054
move.w		#$7a,$dff064
move.w		#$4c,$dff066
clr.w		$dff042
move.l		#$ffffffff,$dff044
move.w		#$9f0,$dff040
move.w		#%0001000100000010,$dff058
rts

clear_flip:
bsr blitwait
move.l		#flip,$dff050
move.l		#clear_line,$dff054
clr.w		$dff064
move.w		#$48,$dff066
clr.w		$dff042
move.l		#$ffffffff,$dff044
move.w		#$9f0,$dff040
move.w		#%0011001000000100,$dff058
rts

;------copy_copper---------------------
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
subq.l	#4,a0
move.l	a0,copmerk
rts
copmerk:	dc.l	0

;**************************
;	drehrout
;***************************
init_turn:
	lea	turn,a0
	move.w	#43,d0
	move.l	#screen_brush,d3
	move.w	#$2807,d1
loop1:
	move.w	#$00e0,d2
	
	move.w	d1,(a0)+
	move.w	#$fffe,(a0)+
move.w	#3,d4
loop2:
	swap	d3
	move.w	d2,(a0)+
	move.w	d3,(a0)+
	swap	d3
	add.w	#2,d2
	move.w	d2,(a0)+
	move.w	d3,(a0)+

	add.w	#2,d2
	add.l	#40,d3
	dbra	d4,loop2
	add.w	#$100,d1
	dbra	d0,loop1	
rts


newcopper:
	dc.l $0101fffe
	dc.l $008e2681
	dc.l	$009026d1
	dc.l	$00920038
	dc.l	$009400d0
	dc.l $01080078
	dc.l $00960020
	dc.l $010a0078
	dc.l $01020000
color:
	dc.l $01820111
	dc.l $01840222
	dc.l $01860333
	dc.l $01880444
	dc.l $018a0555
	dc.l $018c0666
	dc.l $018e0777
	dc.l $01900888
	dc.l $01920999
	dc.l $01940aaa
	dc.l $01960bbb
	dc.l $01980ccc
	dc.l $019a0ddd
	dc.l $019c0eee
	dc.l $019e0fff
	dc.l $2407fffe
	dc.l $01004200
turn:	blk.l	396,0
	blk.l	12,$01800000
copper_end:

;************************************************
;	sin	move
;************************************************
test:	blk.l	2,0
val_a:	dc.w	8
val_b:	dc.w	20
divi:	dc.w	3000
sin_tab_pointer:	dc.w	0
sin_move:

move.w sin_tab_pointer,d0
add.w val_a,d0
cmp.w #720,d0
ble weiter_sin
sub.w #720,d0
weiter_sin:
move.w d0,sin_tab_pointer
bsr	clear_flip
	move.l	#76,d7
;	hauptschleife
	lea	sin,a0	;sintab
	moveq	#0,d4		;intern_sin_tab_pointer
	moveq	#0,d2		;intern sintab_pointer2
	moveq	#0,d3		;rechenregister
	move.l	#scrollscreen,d5	;sourcescreen
	add.l	d7,d5
	move.l	#sinline,d6		;destination
	moveq	#0,d1		;intern sinval_halter
	move.w	d0,d2		;d0 retten
	add.w	d4,d2		;und d4 fuer nachste spalte
	move.w	0(a0,d2.w),d1	;hole sinwert
	move.w	d1,d3
	move.w	#$7fff,d1
	sub.w	d3,d1

;berechne	wert

	divs	divi,d1
	and.l	#$ffff,d1
	muls	#160,d1		;sin_zeile
	and.l	#$ffff,d1	;loesche highword
	add.l	d7,d1		;spalte destination
	add.l	d1,d6		;destination
	bsr	sin_deck_r

;	erhoehe den intern zaehler
	add.w	val_b,d4
	move.w	#720,d1
	sub.w	d0,d1
	cmp.w	d4,d1
	bge	weiter_d4_de
	sub.w	#720,d4
weiter_d4_de:

	
	sub.l	#2,d7



;	hauptschleife
	lea	sin,a0	;sintab
	moveq	#0,d4		;intern_sin_tab_pointer
	moveq	#0,d2		;intern sintab_pointer2
	moveq	#0,d3		;rechenregister
sin_loop:
	move.l	#scrollscreen,d5	;sourcescreen
	add.l	d7,d5
	move.l	#sinline,d6		;destination
	moveq	#0,d1		;intern sinval_halter
	move.w	d0,d2		;d0 retten
	add.w	d4,d2		;und d4 fuer nachste spalte
	move.w	0(a0,d2.w),d1	;hole sinwert
	move.w	d1,d3
	move.w	#$7fff,d1
	sub.w	d3,d1

;berechne	wert

	divs	divi,d1
	and.l	#$ffff,d1
	muls	#160,d1		;sin_zeile
	and.l	#$ffff,d1	;loesche highword
	add.l	d7,d1		;spalte destination
	add.l	d1,d6		;destination
	bsr	sin_blit_r

;	erhoehe den intern zaehler
	add.w	val_b,d4
	move.w	#720,d1
	sub.w	d0,d1
	cmp.w	d4,d1
	bge	weiter_d4
	sub.w	#720,d4
weiter_d4:

	
	sub.l	#2,d7
	cmp.l	#2,d7
	bne	sin_loop
	sub.l	#2,d7
	cmp.w	#1,deck_con
	beq	deck_weiter
	sub.w	#1,deck_counter
	bne	deck_e
	move.w	#1,deck_con
	bra	deck_weiter	
deck_e:
	rts
deck_weiter:


	move.l	#sinline,d6		;destination
	moveq	#0,d1		;intern sinval_halter
	move.w	d0,d2		;d0 retten
	add.w	d4,d2		;und d4 fuer nachste spalte
	move.w	0(a0,d2.w),d1	;hole sinwert
	move.w	d1,d3
	move.w	#$7fff,d1
	sub.w	d3,d1

;berechne	wert

	divs	divi,d1
	and.l	#$ffff,d1
	muls	#160,d1		;sin_zeile
	and.l	#$ffff,d1	;loesche highword
	add.l	d7,d1		;spalte destination
	add.l	d1,d6		;destination
	bsr	sin_blit_deck_l

;	erhoehe den intern zaehler
	add.w	val_b,d4
	move.w	#720,d1
	sub.w	d0,d1
	cmp.w	d4,d1
	bge	weiter_d4_deck
	sub.w	#720,d4
weiter_d4_deck:

rts

sin_blit_r:
bsr	blitwait
move.l		d5,$dff050
move.l		d6,$dff054
move.w		#$52,$dff064
move.w		#$4e,$dff066
clr.w		$dff042
move.w		#$ffff,$dff044
move.w		#$9f0,$dff040
	move.w	#%0011000000000001,$dff058
rts

	

;***************************************
;	install sintab
;***************************************
msin:
	jsr init
rts
CoSin:					; Winkel in D0.w
	lea	sin,a0			; Addresse der erw. Tabelle
	lsl.w	#1,d0			; Winkel*2 = relative Addresse
	and.l	#$ffff,d0		; HiWord loeschen
	add.l	d0,a0			; relative Addresse+Tabelle
	move.w	(a0),d0			; Sin nach D0
	move.w	180(a0),d1		; Cos nach D1
	rts
Init:					; Erweiterung der Tabelle von
	lea	sin,a0			; 0-90 Grad auf 0-360 Grad
	lea	sin+[2*181],a1		; fuer Sinus und Cosinus
makesin:move.w	(a0)+,d0
	cmp.l	#sin,a1
	beq	makecos
	move.w	d0,-(a1)
makecos:neg.w	d0
	move.w	d0,358(a0)
	cmp.l	#sin+[2*271],a0
	bne	makesin
	rts
Sin:
 DC.W $0000,$023C,$0478,$06B3,$08EE,$0B28,$0D61,$0F99,$11D0,$1406
 DC.W $163A,$186C,$1A9D,$1CCB,$1EF7,$2121,$2348,$256C,$278E,$29AC
 DC.W $2BC7,$2DDF,$2FF3,$3203,$3410,$3618,$381D,$3A1C,$3C18,$3E0E
 DC.W $4000,$41ED,$43D4,$45B7,$4794,$496B,$4B3D,$4D08,$4ECE,$508E
 DC.W $5247,$53FA,$55A6,$574C,$58EB,$5A82,$5C13,$5D90,$5F1F,$609A
 DC.W $620E,$637A,$64DE,$663A,$678E,$68DA,$6A1E,$6B5A,$6C8D,$6DB8
 DC.W $6EDA,$6FF4,$7104,$720D,$730C,$7402,$74EF,$75D3,$76AE,$7780
 DC.W $7848,$7907,$79BC,$7A68,$7B0B,$7BA3,$7C33,$7CB8,$7D34,$7DA6
 DC.W $7E0E,$7E6D,$7EC1,$7F0C,$7F4C,$7F83,$7F80,$7FD3,$7FEC,$7FFB
Cos:	DC.W $7FFF
	blk.w	360
 DC.W $0000,$023C,$0478,$06B3,$08EE,$0B28,$0D61,$0F99,$11D0,$1406
 DC.W $163A,$186C,$1A9D,$1CCB,$1EF7,$2121,$2348,$256C,$278E,$29AC
 DC.W $2BC7,$2DDF,$2FF3,$3203,$3410,$3618,$381D,$3A1C,$3C18,$3E0E
 DC.W $4000,$41ED,$43D4,$45B7,$4794,$496B,$4B3D,$4D08,$4ECE,$508E
 DC.W $5247,$53FA,$55A6,$574C,$58EB,$5A82,$5C13,$5D90,$5F1F,$609A
 DC.W $620E,$637A,$64DE,$663A,$678E,$68DA,$6A1E,$6B5A,$6C8D,$6DB8
 DC.W $6EDA,$6FF4,$7104,$720D,$730C,$7402,$74EF,$75D3,$76AE,$7780
 DC.W $7848,$7907,$79BC,$7A68,$7B0B,$7BA3,$7C33,$7CB8,$7D34,$7DA6
 DC.W $7E0E,$7E6D,$7EC1,$7F0C,$7F4C,$7F83,$7F80,$7FD3,$7FEC,$7FFB
sin_end:

coltab:
dc.w	$0fd2,$0db0,$0b90,$0970,$0750,$0530
dc.w	$055f,$077f,$099f,$0bbf,$0ddf,$0fff
dc.w	$0dbf,$0caf,$0b9f,$0a8f,$097f,$086f
dc.w	$075f,$064f,$053f,$042f,$053f,$075f
dc.w	$097f,$0b9f,$0dbf,$0fdf,$0fff,$0eee
dc.w	$0ddd,$0ccc,$0bbb,$0aaa,$0999,$0888
dc.w	$0777,$0666,$0555,$0444,$0854,$0965
dc.w	$0a76,$0b87,$0c98,$0da9,$0eba,$0fcb
dc.w	$0fdc,$0bcf,$0abf,$09af,$089f,$078f
dc.w	$067f,$056f,$045f,$0642,$0753,$0864
dc.w	$0975,$0a86,$0b97,$0ca8,$0db9,$0eca
dc.w	$0fd2,$0db0,$0b90,$0970,$0750,$0530
dc.w	$055f,$077f,$099f,$0bbf,$0ddf,$0fff
dc.w	$0dbf,$0caf,$0b9f,$0a8f,$097f,$086f
dc.w	$075f,$064f,$053f,$042f,$053f,$075f
dc.w	$097f,$0b9f,$0dbf,$0fdf,$0fff,$0eee
dc.w	$0ddd,$0ccc,$0bbb,$0aaa,$0999,$0888
dc.w	$0777,$0666,$0555,$0444,$0854,$0965
dc.w	$0a76,$0b87,$0c98,$0da9,$0eba,$0fcb
dc.w	$0fdc,$0bcf,$0abf,$09af,$089f,$078f
dc.w	$067f,$056f,$045f,$0642,$0753,$0864
dc.w	$0975,$0a86,$0b97,$0ca8,$0db9,$0eca
colend:

fillit:	move.l	copmerk,a0
	move.l	#$5407,d1
	move.l	#132,d0
	move.l	#$100,d3
	move.l	#$f00,d4
coloope:move.w	d1,(a0)+
	add.w	#$100,d1
	move.w	#$fffe,(a0)+
	move.w	#$180,(a0)+
	move.w	#0,(a0)+
	dbra	d0,coloope
	move.l	#$01800000,(a0)+
	move.l	#$01800000,(a0)+
	move.l	#$01800000,(a0)+
init_hires:
	move.l	#$e007fffe,(a0)+
	move.l	#$01000200,(a0)+
	move.l	#$e207fffe,(a0)+
	move.l	#$0092003c,(a0)+
	move.l	#$009400d0,(a0)+
	move.l	#$008e2c89,(a0)+
	move.l	#$00902cd9,(a0)+
	move.l	#$01080050,(a0)+
	move.l	#$010a0050,(a0)+
	move.l	#$00e00000,d3
	move.l	#$01820a84,(a0)+
	move.l	#$01860000,(a0)+
	move.l	#$0100a200,(a0)+

	move.l	#screen,d0
	move.w	#1,d1
sc_loop:
	swap	d0
	move.w	d0,d3
	move.l	d3,(a0)+
	swap	d0
	move.w	d0,d3
	add.l	#$20000,d3
	move.l	d3,(a0)+
	add.l	#80,d0
	add.l	#$20000,d3
	dbra	d1,sc_loop

	lea	coltab(pc),a1
	MOVE.L	#$e309fffe,d0
	move.l	#120,d1
xj:	move.l	d0,(a0)+
	move.w	#$184,(a0)+
	move.w	(a1)+,(a0)+
	cmp.l	#colend,a1
	bne.S	nodang
	lea	coltab(pc),a1
nodang:	add.l	#$01000000,d0
	cmp.l	#$0009fffe,d0
	bne.S	nopal
	move.l	#$ffe1fffe,(a0)+
nopal:	dbra	d1,xj
	move.l	#-2,(a0)+
	rts

blitze:	move.l	copmerk,a0
	add.l	#3*32,a0
	move.l	xchan0,d0
	move.l	#0,d1
	bsr.S	writebr
	move.l	copmerk,a0
	add.l	#[7*32]+8,a0
	move.l	xchan1,d0
	move.l	#1,d1
	bsr.S	writebr
	move.l	copmerk,a0
	add.l	#[17*32],a0
	move.l	xchan2,d0
	move.l	#2,d1
	bsr.S	writebr
	move.l	copmerk,a0
	add.l	#[21*32]+8,a0
	move.l	xchan3,d0
	move.l	#3,d1
	bsr.S	writebr
	rts

writebr:clr.l	d4
	clr.l	d5
	cmp.w	#15,d0
	bne.S	bar2
	move.w	#14,d0
bar2:	cmp.l	#0,d1
	bne.S	bar3
	move.w	#$fff,d4
	move.w	#$111,d5
bar3:	cmp.l	#1,d1
	bne.S	bar4
	move.w	#$f00,d4
	move.w	#$100,d5
bar4:	cmp.l	#2,d1
	bne.S	bar5
	move.w	#$ff0,d4
	move.w	#$110,d5
bar5:	cmp.l	#3,d1
	bne.S	nobars
	move.w	#$00f,d4
	move.w	#$001,d5
nobars:	add.l	#6,a0
	move.l	a0,a1
	move.l	d0,d3
	add.w	#1,d3
	mulu	d5,d3
	neg.w	d3
	sub.w	d3,d4
	move.w	d4,d6
	move.l	a1,a0
	add.l	#4*32,a0
	move.l	a0,a1			;a0 oben a1 unten
	move.l	a0,a2
	move.l	a0,a3
lo_lo1:	move.w	d4,(a0)
	move.w	d6,(a1)
	add.l	#16,a1
	sub.l	#16,a0
	sub.w	d5,d4
	sub.w	d5,d6
	dbra	d0,lo_lo1

	clr.w	16(a0)
	clr.w	16(a1)
	clr.w	(a0)
	clr.w	(a1)
	clr.w	-16(a0)
	clr.w	-16(a1)
	clr.w	-32(a0)
	clr.w	-32(a1)
	rts

lpa:	cmp.l	#1,xchan0
	beq.S	no0
	subq.l	#1,xchan0
no0:	cmp.l	#1,xchan1
	beq.S	no1
	subq.l	#1,xchan1
no1:	cmp.l	#1,xchan2
	beq.S	no2
	subq.l	#1,xchan2
no2:	cmp.l	#1,xchan3
	beq.S	no3
	subq.l	#1,xchan3
no3:	rts

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.S	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


; decruncher v1.1

; changes made : all fixed branches are now relatives
;		 (faster,shorter,easier to work with)

read  = $5c6d4
lowwr = $30000

s:
lea 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	44352,0
crunch_end:
