algu:
	bra.w	beginning
P50_data	incbin	"wdh0:music/pack/p50.paranormaalit aivot"

fade  = 0	;0 = normal
		;1 = use master volume
CIA = 0		;0 = disabled
		;1 = enabled
system = 0	;0 = killer
		;1 = friendly
channels = 4	;amount of channels to be played

use = -1 	;The Usecode

	include Player.i

Plane_height=75
Plane_width2 = 44
Plane_width = 42
Wait_time = 2*50
N_of_Planes=3
Plane_Size=10240+2048

beginning:

	move.l	4,a5
	move.l	156(a5),a5
	move.l	38(a5),d0

	lea	oldcop(pc),a6
	move.l	d0,(a6)
	
	lea	$dff000,a6

	lea	filet(pc),a1
	lea	file1(pc),a2
	move.l	a2,d0
	move.l	d0,(a1)+
	lea	file2(pc),a2
	move.l	a2,d0
	move.l	d0,(a1)+
	lea	file3(pc),a2
	move.l	a2,d0
	move.l	d0,(a1)+
	lea	file4(pc),a2
	move.l	a2,d0
	move.l	d0,(a1)+
	lea	file5(pc),a2
	move.l	a2,d0
	move.l	d0,(a1)+
	lea	file6(pc),a2
	move.l	a2,d0
	move.l	d0,(a1)+
	lea	file7(pc),a2
	move.l	a2,d0
	move.l	d0,(a1)+
	lea	file8(pc),a2
	move.l	a2,d0
	move.l	d0,(a1)+
	lea	file9(pc),a2
	move.l	a2,d0
	move.l	d0,(a1)+
	lea	file0(pc),a2
	move.l	a2,d0
	move.l	d0,(a1)+
	
	lea	logo(pc),a1
	move.l	a1,d0
	lea	planes1(pc),a1
	moveq	#3,d7
mg_l:	move.w	d0,6(a1)
	swap.w	d0
	move.w	d0,2(a1)
	swap.w	d0
	add.l	#$aa8,d0
	add.l	#$8,a1
	dbf	d7,mg_l
	
	lea	tausta(pc),a2
	lea	planes0(pc),a1
	move.l	a2,d0
	move.w	d0,6(a1)
	swap.w	d0
	move.w	d0,2(a1)
	swap.w	d0
	lea	planes2(pc),a1
	add.l	#$2c*103,d0
	move.w	d0,6(a1)
	swap.w	d0
	move.w	d0,2(a1)
	swap.w	d0
	lea	planes3(pc),a1
	add.l	#$2c*98,d0
	move.w	d0,6(a1)
	swap.w	d0
	move.w	d0,2(a1)
	swap.w	d0
	
	lea	scrpl(pc),a1
	move.l	a1,d0
	lea	scplane(pc),a1
	move.w	d0,6(a1)
	swap.w	d0
	move.w	d0,2(a1)

	lea	scrf(pc),a1
	move.l	a1,d0
	lea	sfpl(pc),a1
	move.w	d0,6(a1)
	swap.w	d0
	move.w	d0,2(a1)

	bsr	typemenu
	
	lea	safe(pc),a1

	move.w	$1c(a6),(a1)+
	move.w	#$3fff,$9a(a6)
	move.w	$2(a6),(a1)+
	move.w	#%1000011111111111,$96(a6)
	move.w	#%0000000000110000,$96(a6)

	lea	copl(pc),a1
	move.l	a1,$80(a6)

	lea	P50_data(pc),a0
	sub.l	a1,a1
	moveq	#0,d0		;Auto Detect

	bsr.w	_apu1				;laita bsr.s
;	jsr	P50_motuuli+P50_InitOffset

l0	cmp.b	#-1,$6(a6)
	bne.s	l0
;	move.w	#$222,$dff180
	bsr	scroll
	bsr	swap_planes
	bsr	vector
	bsr	animaze
	bsr	colorani
	bsr	mouse
	bsr.w	_apu2
;	move.w	#$111,$dff180
l0b	cmp.b	#-2,$6(a6)
	bne.s	l0b
l1	btst	#6,$bfe001
	bne.s	l0

	bsr.w	_apu3				;laita bsr.s
;	jsr	P50_motuuli+P50_EndOffset

	lea	safe(pc),a1
	move.w	2(a1),d0
	or.w	#$8000,d0
	move.w	d0,$96(a6)
	move.w	(a1),d0
	or.w	#$8000,d0
	move.w	d0,$9a(a6)
	lea	oldcop(pc),a6
	move.l	(a6),d0
	move.l	d0,$dff080
	move.l	#0,d0


	move.l	#0,d0
	lea	dosname(pc),a1
	move.l	4,a6
	jsr	-$0228(a6)
	move.l	d0,a6


loadinggi:
	lea	filet(pc),a1
	move.l	#0,d0
	move.b	kohta(pc),d0
	muls	#4,d0
	add.l	d0,a1
	move.l	(a1),d1
	move.l	#0,d2
	move.l	#0,d3
	jsr	-$00de(a6)
	move.l	#0,d0
	rts


mouse:	lea	mouse_dat(pc),a1
	move.w	$dff00a,d1
	and.w	#$ff00,d1
	ror.w	#8,d1
testay:	cmp.w	6(a1),d1
	beq.s	mouseende
	move.w	6(a1),d2
	move.w	d1,6(a1)
	sub.b	d2,d1
	ext.w	d1
	move.w	2(a1),d2
	add.w	d1,d2
	cmp.w	14(a1),d2
	bmi.s	ysuurenee1
	move.w	14(a1),d2
ysuurenee1:
	cmp.w	12(a1),d2
	bpl.s	ysuurenee2
	move.w	12(a1),d2
ysuurenee2:
	move.w	d2,2(a1)
mouseende:

set:	lea	mousey(pc),a1
	lea	kohta(pc),a3
	move.w	(a1),d0
	lea	k_set(pc),a2
	cmp.w	#19*2,d0
	bmi.s	_10a
	move.b	#1,9(a2)
	move.w	#-1,d0
	move.b	#09,(a3)
	bra.s	_10b
_10a:	move.b	#0,9(a2)
_10b:		
	cmp.w	#17*2,d0
	bmi.s	_09a
	move.b	#1,8(a2)
	move.w	#-1,d0
	move.b	#08,(a3)
	bra.s	_09b
_09a:	move.b	#0,8(a2)
_09b:		
	cmp.w	#15*2,d0
	bmi.s	_08a
	move.b	#1,7(a2)
	move.w	#-1,d0
	move.b	#07,(a3)
	bra.s	_08b
_08a:	move.b	#0,7(a2)
_08b:		
	cmp.w	#13*2,d0
	bmi.s	_07a
	move.b	#1,6(a2)
	move.w	#-1,d0
	move.b	#06,(a3)
	bra.s	_07b
_07a:	move.b	#0,6(a2)
_07b:		
	cmp.w	#11*2,d0
	bmi.s	_06a
	move.b	#1,5(a2)
	move.w	#-1,d0
	move.b	#05,(a3)
	bra.s	_06b
_06a:	move.b	#0,5(a2)
_06b:		
	cmp.w	#09*2,d0
	bmi.s	_05a
	move.b	#1,4(a2)
	move.w	#-1,d0
	move.b	#04,(a3)
	bra.s	_05b
_05a:	move.b	#0,4(a2)
_05b:		
	cmp.w	#07*2,d0
	bmi.s	_04a
	move.b	#1,3(a2)
	move.w	#-1,d0
	move.b	#03,(a3)
	bra.s	_04b
_04a:	move.b	#0,3(a2)
_04b:		
	cmp.w	#05*2,d0
	bmi.s	_03a
	move.b	#1,2(a2)
	move.w	#-1,d0
	move.b	#02,(a3)
	bra.s	_03b
_03a:	move.b	#0,2(a2)
_03b:		
	cmp.w	#03*2,d0
	bmi.s	_02a
	move.b	#1,1(a2)
	move.w	#-1,d0
	move.b	#01,(a3)
	bra.s	_02b
_02a:	move.b	#0,1(a2)
_02b:		
	cmp.w	#01*2,d0
	bmi.s	_01a
	move.b	#1,0(a2)
	move.w	#-1,d0
	move.b	#00,(a3)
	bra.s	_01b
_01a:	move.b	#0,0(a2)
_01b:	cmp.w	#-1,d0
	beq.s	kset
	move.b	#1,0(a2)	
	move.b	#00,(a3)


kset:
	lea	kcolor(pc),a1
	lea	k_color(pc),a2
	lea	k_set(pc),a3
	moveq	#9,d7
_debfi:	add.l	#$4,a1
	cmp.b	#0,(a3)+
	bne.s	white
	move.w	(a2)+,2(a1)
	move.w	(a2)+,6(a1)
	add.l	#$8,a1
	dbf	d7,_Debfi
	rts
white:	move.w	#$fff,2(a1)
	move.w	#$eee,6(a1)
	add.l	#$8,a1
	add.l	#$4,a2
	dbf	d7,_debfi
	rts
	
	
astral	dc.l	0

colorani:
	move.l	astral(pc),d0
	btst	#0,d0
	beq.w	ca_o
	btst	#1,d0
	beq.w	ca_o
	cmp.l	#400,d0
	bpl.s	_n0
	lea	blue(pc),a2
	bra.s	ca_here
_n0:	cmp.l	#800,d0
	bpl.s	_n1
	lea	red(pc),a2
	bra.s	ca_here
_n1:	cmp.l	#1200,d0
	bpl.s	_n2
	lea	green(pc),a2
	bra.s	ca_here
_n2:
	lea	red2(pc),a2

ca_here:
	lea	clrs(pc),a1
	moveq.l	#11,d7
colloop	move.w	(a1)+,d3
	move.w	(a1),d3
	move.w	(a2)+,d0
	move.w	d0,d1
	move.w	d1,d2
	move.w	d3,d4
	move.w	d4,d5
	and.w	#$f,d0
	and.w	#$f,d3
	and.w	#$f0,d1
	and.w	#$f0,d4
	and.w	#$f00,d2
	and.w	#$f00,d5
	cmp.w	d0,d3
	bmi.s	ohi1a
	beq.s	ohi1
	sub.w	#$1,d3
	bra.s	ohi1
ohi1a	add.w	#$1,d3		
ohi1	cmp.w	d1,d4
	bmi.s	ohi2a
	beq.s	ohi2
	sub.w	#$10,d4
	bra.s	ohi2
ohi2a	add.w	#$10,d4
ohi2	cmp.w	d2,d5
	bmi.s	ohi3a
	beq.s	ohi3
	sub.w	#$100,d5
	bra.s	ohi3
ohi3a	add.w	#$100,d5	
ohi3	or.w	d3,d4
	or.w	d4,d5
	move.w	d5,(a1)+
	dbf	d7,colloop
ca_o	rts
		
animaze:
	move.l	astral(pc),d0
	cmp.l	#1600,d0
	bmi.s	haaa
	lea	astral(pc),a4
	move.l	#0,(a4)
	rts
haaa	cmp.l	#1200,d0
	bmi.s	haa2
	bra.s	a_kuutio
haa2	cmp.l	#800,d0
	bmi.s	haa3
	bra.s	a_kartio
haa3	cmp.l	#400,d0
	bpl.s	a_kolmio
	bra.s	a_pallo

a_kolmio
	lea	astral(pc),a4
	add.l	#1,(a4)
	lea	koords1(pc),a4
	lea	kolmio(pc),a5
hobs:	moveq	#41,d7
dobs:	move.w	(a4),d1
	cmp.w	(a5)+,d1
	beq.s	a_daa
	bpl.s	iso
	add.w	#1,(a4)+
	dbf	d7,dobs
	rts
iso	sub.w	#1,(a4)+
	dbf	d7,dobs
	rts
a_daa:	move.w	(a4)+,d1
	dbf	d7,dobs
	rts

a_pallo
	lea	astral(pc),a4
	add.l	#1,(a4)
	lea	koords1(pc),a4
	lea	pallo(pc),a5
	bra.s	hobs
a_kuutio
	lea	astral(pc),a4
	add.l	#1,(a4)
	lea	koords1(pc),a4
	lea	kuutio(pc),a5
	bra.s	hobs
a_kartio
	lea	astral(pc),a4
	add.l	#1,(a4)
	lea	koords1(pc),a4
	lea	kartio(pc),a5
	bra.s	hobs

scroll:
	lea	scrbit(pc),a4
	cmp.b	#0,(a4)
	beq.s	newfont
	sub.b	#1,(a4)
_backs	lea	scrpl(pc),a1
wsc:	btst	#14,$2(a6)
	bne.s	wsc
	move.l	a1,$50(a6)
	sub.l	#1,a1
	move.l	a1,$54(a6)
	move.l	#-1,$44(a6)
	move.l	#0,$64(a6)
	move.w	#0,$42(a6)
	move.w	#%1110100111110000,$40(a6)
	move.w	#$2d6,$58(a6)
	rts
newfont:
	move.b	#3,(a4)
	lea	scrolltxt(pc),a3
	move.l	smerkki(pc),d0
	add.l	d0,a3
	lea	scrpl(pc),a2
	add.l	#$2b,a2
	move.l	#0,d0
	bsr	i_font
	lea	smerkki(pc),a2
	add.l	#1,(a2)
	bra.s	_backs
	
	even
	
smerkki
	dc.l	0

scrbit	dc.b	0
	even
safe	dc.w	0
safed	dc.w	0
oldcop	dc.l	0
	dc.l	0
	dc.l	0
	
dosname	dc.b	"dos.library",0
kohta	dc.b	0
	even
		
typemenu:
	lea	menutxt(pc),a3
	lea	pic6,a2
	bsr	type_it
	lea	menutxt(pc),a3
	lea	pic6,a2
	add.l	#$3000,a2
	bsr	type_it
	lea	menutxt(pc),a3
	lea	pic6,a2
	add.l	#$6000,a2
	bsr	type_it
	lea	menutxt(pc),a3
	lea	pic7,a2
	bsr	type_it
	lea	menutxt(pc),a3
	lea	pic7,a2
	add.l	#$3000,a2
	bsr	type_it
	lea	menutxt(pc),a3
	lea	pic7,a2
	add.l	#$6000,a2
	bsr	type_it
	rts	
type_it
	add.l	#$2c0,a2
	add.l	#$16,a2
	moveq	#12,d5
i_2l	moveq	#20,d6
i_1l	bsr	i_font
	dbf	d6,i_1l
	add.l	#$8*$2c,a2
	add.l	#$17,a2
	dbf	d5,i_2l
	rts

i_font	lea	font(pc),a1
	move.b	(a3)+,d0
	cmp.b	#$ff,d0
	beq.s	over_o
	cmp.b	#$48,d0
	bpl.s	i_rivi2
	sub.b	#$20,d0
i_back1	add	d0,a1
	moveq.l	#6,d7
i_loop1	move.b	(a1),(a2)
	add.w	#$28,a1
	add.w	#$2c,a2
	dbf	d7,i_loop1
	sub.w	#$7*$2c,a2
	add.w	#1,a2
	rts
i_rivi2	lea	font+$168-$28(pc),a1
;	move.l	#font(pc)+$168-$28,a1
	sub.b	#$48,d0
	bra	i_back1	
over_o:
	lea	smerkki(pc),a2
	move.l	#0,(a2)
	rts

SWAP_PLANES
	lea	show_planes(pc),a0	
	lea	planes(pc),a1		
					
	movem.l	(a0),d0/d1
	exg	d0,d1	
	movem.l	d0/d1,(a0)

	move.w	d0,6(a1)
	swap.w	d0
	move.w	d0,2(a1)
	swap	d0
	add.l	#plane_size,d0
	move.w	d0,14(a1)
	swap	d0
	move.w	d0,10(a1)
	swap	d0
	add.l	#plane_size,d0
	move.w	d0,22(a1)
	swap	d0
	move.w	d0,18(a1)	
	rts
	
show_planes	dc.l	pic6
work_planes	dc.l	pic7

Bpl1:	dc.w	-1,-1,0,0	
Bpl2:	dc.w	-1,-1,0,0
Bpl3:	dc.w	-1,-1,0,0
Bpl4:	dc.w	-1,-1,0,0

;CLEAR

clr:	cmp.w	#-1,(a1)	
	bne.s	cleari		
	cmp.w	#-1,2(a1)
	bne.s	cleari
	tst.w	4(a1)
	bne.s	cleari
	tst.w	6(a1)
	bne.s	cleari
	rts

cleari:	movem.w	(a1),d0/d1/d2/d3	
	move.w	d1,d4
	subq.w	#1,d1
	mulu	#Plane_width2,d1
	ext.l	d1
	add.l	d1,a0
	sub.w	d4,d3
	addq.w	#2,d3
	lsl.w	#6,d3	
	
	move.w	d0,d1		
	lsr.w	#3,d0
	ext.l	d0
	add.l	d0,a0

	sub.w	d1,d2	
	lsr.w	#4,d2	
	addq.w	#2,d2
	add.w	d2,d3

	move.w	#Plane_width2/2,d0
	sub.w	d2,d0
	add.w	d0,d0
		
clri:	btst	#14,2(a6)	 
	bne.s	clri	

	move.l	a0,$54(a6)
	move.l	#$01000000,$40(a6)
	move.w	d0,$66(a6)
	move.w	d3,$58(a6)
	rts

vector:
	lea	$dff000,a6

	move.l	work_planes(pc),a0
	lea	Bpl1(pc),a1
	bsr.w	clr	

;Y-AKSELI

	move.l	coords(pc),a5		
	lea	sin(pc),a0		
	lea	cos(pc),a1		
	lea	z_coords(pc),a2		
	lea	store(pc),a3		
vector1:
	move.w	ky(pc),d7
	move.w	(a0,d7.w),d0	
	move.w	d0,d4
	move.w	(a1,d7.w),d1
	move.w	d1,d5
	
	movem.w	(a5)+,d2/d3/d6	

	muls	d2,d1
	muls	d6,d0
	add.l	d1,d0
	asr.l	#7,d0		

	muls	d2,d4		
	muls	d6,d5		
	sub.l	d4,d5
	asr.l	#8,d5	
	
;X-AKSELI
	move.w	kx(pc),d7
	move.w	(a0,d7.w),d2
	move.w	d2,d6
	move.w	(a1,d7.w),d1
	move.w	d1,d7
	
	muls	d3,d1
	muls	d5,d2
	sub.l	d2,d1
	asr.l	#7,d1	

	muls	d3,d6
	muls	d5,d7
	add.l	d6,d7
	asr.l	#8,d7		
	
;Z-AKSELI
	move.w	kz(pc),d6
	move.w	(a0,d6.w),d2
	move.w	d2,d4
	move.w	(a1,d6.w),d3
	move.w	d3,d5
	
	muls	d0,d3
	muls	d1,d2
	sub.l	d2,d3

	muls	d0,d4
	muls	d1,d5
	add.l	d4,d5
	
;PROJEKTIO
	movem.w	x_pos(pc),d0/d1/d2	
	move.w	d7,(a2)+
	add.w	d2,d7
	divs 	d7,d3
	add.w	d0,d3
	move.w	d3,(a3)+	
	
	divs 	d7,d5
	add.w	d1,d5
	move.w	d5,(a3)+
			
	cmp.w	#9999,(a5)		
	bne.w	vector1

	move.l	work_planes(pc),a0
	lea	Plane_Size(a0),a0
	lea	Bpl2(pc),a1
	bsr.w	clr			
	bsr.w	rotate			
	move.l	work_planes(pc),a0
	lea	plane_size(a0),a0
	lea	plane_size(a0),a0
	lea	Bpl3(pc),a1
	bsr.w	clr
	
;COUNT DISTANCE
	move.l	prefs(pc),a0		
	lea	store(pc),a1		
	lea	colly+2(pc),a3		
	
geti:	move.w	10(a0),d7
	add.w	d7,d7
	add.w	d7,d7
	movem.w	(a1,d7.w),d0/d1		

	move.w	14(a0),d7
	add.w	d7,d7
	add.w	d7,d7
	movem.w	(a1,d7.w),d2/d3	

	move.w	18(a0),d7
	add.w	d7,d7
	add.w	d7,d7
	movem.w	(a1,d7.w),d4/d5		

	sub.w	d2,d4
	move.w	d1,d6
	sub.w	d3,d6
	muls.w	d4,d6

	sub.w	d3,d5
	sub.w	d2,d0
	muls.w	d5,d0

	sub.l	d0,d6
	tst.w	d6
	bgt.s	safei
	moveq	#0,d6	

safei	move.w	d6,4(a0)	

	add.w	6(a0),a0
	cmp.w	#9999,(a0)	
	bne.s	geti

	add.w	#2,a0

geti2:	move.w	10(a0),d7
	add.w	d7,d7
	add.w	d7,d7
	movem.w	(a1,d7.w),d0/d1		

	move.w	14(a0),d7
	add.w	d7,d7
	add.w	d7,d7
	movem.w	(a1,d7.w),d2/d3	

	move.w	18(a0),d7
	add.w	d7,d7
	add.w	d7,d7
	movem.w	(a1,d7.w),d4/d5		

	sub.w	d2,d4
	move.w	d1,d6
	sub.w	d3,d6
	muls.w	d4,d6

	sub.w	d3,d5
	sub.w	d2,d0
	muls.w	d5,d0

	sub.l	d0,d6
	tst.w	d6
	bgt.s	safei2
	moveq	#0,d6	

safei2	move.w	d6,4(a0)	

	add.w	6(a0),a0
	cmp.w	#9999,(a0)	
	bne.s	geti2

;COMPARE DISTANCE
hops	move.l	prefs(pc),a1
	lea	store(pc),a2
	lea	oct(pc),a4

	move.l	#-1,$44(a6)
	move.l	#-$8000,$72(a6)
	move.w	#plane_width2,$60(a6)

Com_dist:
	move.l	work_planes(pc),a0
	tst.w	4(a1)
	beq.L	variv
	tst.w	2(a1)
	beq.s	nexti

	btst	#0,3(a1)	
	beq.s	nxti		
	lea	bpl1(pc),a5	
	bsr.w	lets_do_it	
nxti	lea	plane_size(a0),a0
	btst	#1,3(a1)
	beq.s	nexti
hop	lea	bpl2(pc),a5
	bsr.w	lets_do_it	

nexti	add.w	6(a1),a1
	cmp.w	#9999,(a1)
	bne.s	com_dist
;
	add.w	#2,a1

Com_dist2:
	move.l	work_planes(pc),a0
	lea	plane_size(a0),a0
	lea	plane_size(a0),a0
	tst.w	4(a1)
	beq.s	nexti2
	tst.w	2(a1)
	beq.s	nexti2

	lea	bpl3(pc),a5	
	bsr.w	lets_do_it	

nexti2	add.w	6(a1),a1
	cmp.w	#9999,(a1)
	bne.s	com_dist2
;
	move.l	work_planes(pc),a0	
	lea	Bpl1(pc),a1
	bsr.w	Fill			
	move.l	work_planes(pc),a0
	lea	Plane_Size(a0),a0
	lea	Bpl2(pc),a1
	bsr.w	Fill			

;
	move.l	work_planes(pc),a0
	lea	Plane_Size(a0),a0
	lea	Plane_Size(a0),a0
	lea	Bpl3(pc),a1
	bsr.w	Fill
;
	rts

variv	lea	plane_size(a0),a0
	bra.s	hop


;DRAW LINES

lets_do_it:	
	btst	#14,$2(a6)
	bne.s	lets_do_it

	move.w	8(a1),d7
	lea	10(a1),a3

draw:	move.l	#Plane_Width2,d5

	move.w	(a3)+,d4	
	add.w	d4,d4		
	add.w	d4,d4
	move.w	(a2,d4.w),d0		
	move.w	2(a2,d4.w),d1		
	move.w	(a3)+,d4
	add.w	d4,d4
	add.w	d4,d4
	move.w	(a2,d4.w),d2		
	move.w	2(a2,d4.w),d3		

	cmp.w	(a5),d0			
	bhi.s	nextii
	move.w	d0,(a5)
nextii:	
	cmp.w	2(a5),d1		
	bhi.s	next1i
	move.w	d1,2(a5)
next1i:	
	cmp.w	4(a5),d0		
	blo.s	next2i
	move.w	d0,4(a5)
next2i:	
	cmp.w	6(a5),d1		
	blo.s	next3i
	move.w	d1,6(a5)
next3i:				
	cmp.w	d1,d3
	bgt.s	line1
	exg	d0,d2
	exg	d1,d3
	beq.s	out
line1:	move.w	d1,d4
	muls	d5,d4
	move.w	d0,d5
	add.l	a0,d4
	asr.w	#3,d5
	add.l	d5,d4
	moveq	#0,d5
	sub.w	d1,d3
	sub.w	d0,d2
	bpl.s	line2
	moveq	#1,d5
	neg.w	d2
line2:	move.w	d3,d1
	add.w	d1,d1
	cmp.w	d2,d1
	dbhi	d3,line3
line3:	move.w	d3,d1
	sub.w	d2,d1
	bpl.s	line4
	exg	d2,d3
line4:	addx.w	d5,d5
	add.w	d2,d2
	move.w	d2,d1
	sub.w	d3,d2
	addx.w	d5,d5
	and.w	#15,d0
	ror.w	#4,d0
	or.w	#$a4a,d0
waitblt:btst	#6,2(a6)
	bne.s	waitblt
	move.w	d2,$52(a6)
	sub.w	d3,d2
	lsl.w	#6,d3
	addq.w	#2,d3
	move.w	d0,$40(a6)
	move.b	(a4,d5.w),$43(a6)
	move.l	d4,$48(a6)
	move.l	d4,$54(a6)
	movem.w	d1/d2,$62(a6)
	move.w	d3,$58(a6)
out:	dbf	d7,draw		
	rts
	
;FILL BITPLANES

Fill:	cmp.w	#-1,(a1)
	bne.s	wfilli
	cmp.w	#-1,2(a1)
	bne.s	wfilli
	tst.w	4(a1)
	bne.s	wfilli
	tst.w	6(a1)
	bne.s	wfilli
	rts

wfilli:	movem.w	(a1),d0/d1/d2/d3	
	move.w	d3,d4
	addq.l	#1,d3
	mulu	#Plane_width2,d3
	add.l	d3,a0
	subq.l	#2,a0
	
	sub.w	d1,d4
	addq.w	#1,d4
	lsl.w	#6,d4

	move.w	d2,d3			
	lsr.w	#3,d2
	addq.w	#2,d2
	ext.l	d2
	add.l	d2,a0

	sub.w	d0,d3		
	lsr.w	#4,d3		
	addq.w	#2,d3
	add.w	d3,d4

	move.w	#Plane_width2/2,d0
	sub.w	d3,d0
	add.w	d0,d0

filli:	btst	#14,$2(a6)
	bne.s	filli

	move.l	a0,$50(a6)
	move.l	a0,$54(a6)
	move.l	#$09f00012,$40(a6)
	move.l	#$ffffffff,$44(a6)
	move.w	d0,$64(a6)
	move.w	d0,$66(a6)
	move.w	d4,$58(a6)
	rts

;ROTATE

rotate:	add.w	#X_angle*2,kx
	cmp.w	#720,kx
	blo.s	gee1
	move.w	#0,kx
gee1:	add.w	#Y_angle*2,ky
	cmp.w	#720,ky
	blo.s	gee2
	move.w	#0,ky
gee2:	add.w	#Z_angle*2,kz
	cmp.w	#720,kz
	blo.s	gee3
	move.w	#0,kz
gee3:	rts

oct:	dc.l	$3431353,$b4b1757   
			
colly:	dc.w	$0180,$0000,$0182,$0def,$0184,$0025,$0186,$0abc
	dc.w	$0188,$0014,$018a,$0def,$018c,$0025,$018e,$0abc


copl	dc.w	$01fc,$0000
	dc.w	$0100,$1000,$0102,$0000,$0108,$0000,$010a,$0000
	dc.w	$008e,$0510,$0090,$7ff0,$0092,$0030,$0094,$00d8
planes0	dc.w	$00e0,$0000,$00e2,$0000,$0180,$0222,$0182,$0000
	dc.w	$2e07,$fffe,$0100,$0000,$0180,$0000
	dc.w	$2f07,$fffe,$0180,$075f
	dc.w	$3107,$fffe,$0180,$0000,$0102,$0000
	dc.w	$0180,$0000,$0182,$0fff,$0184,$0eee,$0186,$0ddd
	dc.w	$0188,$0ccd,$018a,$0bbc,$018c,$0abb,$018e,$09ab
	dc.w	$0190,$089a,$0192,$0789,$0194,$0578,$0196,$0467
	dc.w	$0198,$0356,$019a,$0245,$019c,$0234,$019e,$0123
planes1	dc.w	$00e0,$0000,$00e2,$0000,$00e4,$0000,$00e6,$0000
	dc.w	$00e8,$0000,$00ea,$0000,$00ec,$0000,$00ee,$0000
	dc.w	$3207,$fffe,$0100,$4000,$0180,$0000
	dc.w	$6f07,$fffe,$0100,$0000,$0180,$0000,$0102,$0000
	dc.w	$7007,$fffe,$0180,$075f,$7207,$fffe,$0180,$0000
	dc.w	$7307,$fffe,$0100,$1000,$0180,$0222,$0182,$0000
planes2	dc.w	$00e0,$0000,$00e2,$0000

	dc.w	$7407,$fffe
planes	dc.w	$00e4,$0000,$00e6,$0000,$00e8,$0000,$00ea,$0000
	dc.w	$00ec,$0000,$00ee,$0000
clrs:	dc.w	$0184,$0abc,$0186,$09ab,$0188,$0025,$018a,$0014
	dc.w	$018c,$0def,$018e,$0cde,$0190,$0014,$0192,$0003
	dc.w	$0194,$0abc,$0196,$09ab,$0198,$0025,$019a,$0014
	dc.w	$019c,$09c4,$019e,$08b3
	dc.w	$7507,$fffe,$0100,$4000

	dc.w	$8507,$fffe,$019c,$000f,$019e,$000e
	dc.w	$8e07,$fffe,$019c,$010e,$019e,$000d
	dc.w	$9707,$fffe,$019c,$020d,$019e,$010c
kcolor:	
	dc.w	$a007,$fffe,$019c,$040b,$019e,$030a
	dc.w	$a907,$fffe,$019c,$050a,$019e,$0409
	dc.w	$b207,$fffe,$019c,$0609,$019e,$0508
	dc.w	$bb07,$fffe,$019c,$0708,$019e,$0607
	dc.w	$c407,$fffe,$019c,$0807,$019e,$0706
	dc.w	$cd07,$fffe,$019c,$0906,$019e,$0805
	dc.w	$d607,$fffe,$019c,$0a05,$019e,$0904
	dc.w	$df07,$fffe,$019c,$0b04,$019e,$0a03
	dc.w	$e807,$fffe,$019c,$0c03,$019e,$0b02
	dc.w	$f107,$fffe,$019c,$0d02,$019e,$0c01

	dc.w	$ffe1,$fffe
	dc.w	$0207,$fffe,$0100,$1000
	dc.w	$0807,$fffe,$0180,$0000,$0100,$0000
	dc.w	$0907,$fffe,$0180,$075f
	dc.w	$0b07,$fffe,$0180,$0000
	dc.w	$0d07,$fffe,$0100,$2000
scplane	dc.w	$00e0,$0000,$00e2,$0000,$0180,$0000,$0182,$0def
sfpl	dc.w	$00e4,$0000,$00e6,$0000,$0184,$0000,$0186,$0000

	dc.w	$0d37,$fffe
	dc.w	$0182,$00ff,$0182,$00ff,$0182,$00ff,$0182,$00ff
	dc.w	$0182,$00ff,$0182,$00ff,$0182,$00ff,$0182,$00ff
	dc.w	$0182,$00ff,$0182,$01ff,$0182,$01fe,$0182,$02fe
	dc.w	$0182,$02fd,$0182,$03fd,$0182,$03fc,$0182,$04fc
	dc.w	$0182,$04fb,$0182,$05fb,$0182,$05fa,$0182,$06fa
	dc.w	$0182,$06f9,$0182,$07f9,$0182,$07f8,$0182,$08f8
	dc.w	$0182,$08f7,$0182,$09f7,$0182,$09f6,$0182,$0af6
	dc.w	$0182,$0af5,$0182,$0bf5,$0182,$0bf4,$0182,$0cf4
	dc.w	$0182,$0cf3,$0182,$0df3,$0182,$0df2,$0182,$0ef2
	dc.w	$0182,$0ef1,$0182,$0ff1,$0182,$0ff0,$0182,$0ff0
	dc.w	$0182,$0ff0,$0182,$0ff0,$0182,$0ff0,$0182,$0def

	dc.w	$0e37,$fffe
	dc.w	$0182,$00ff,$0182,$00ff,$0182,$00ff,$0182,$00ff
	dc.w	$0182,$00ff,$0182,$00ff,$0182,$00ff,$0182,$00ff
	dc.w	$0182,$00ff,$0182,$01ff,$0182,$01fe,$0182,$02fe
	dc.w	$0182,$02fd,$0182,$03fd,$0182,$03fc,$0182,$04fc
	dc.w	$0182,$04fb,$0182,$05fb,$0182,$05fa,$0182,$06fa
	dc.w	$0182,$06f9,$0182,$07f9,$0182,$07f8,$0182,$08f8
	dc.w	$0182,$08f7,$0182,$09f7,$0182,$09f6,$0182,$0af6
	dc.w	$0182,$0af5,$0182,$0bf5,$0182,$0bf4,$0182,$0cf4
	dc.w	$0182,$0cf3,$0182,$0df3,$0182,$0df2,$0182,$0ef2
	dc.w	$0182,$0ef1,$0182,$0ff1,$0182,$0ff0,$0182,$0ff0
	dc.w	$0182,$0ff0,$0182,$0ff0,$0182,$0ff0,$0182,$0def

	dc.w	$0f37,$fffe
	dc.w	$0182,$00ff,$0182,$00ff,$0182,$00ff,$0182,$00ff
	dc.w	$0182,$00ff,$0182,$00ff,$0182,$00ff,$0182,$00ff
	dc.w	$0182,$00ff,$0182,$01ff,$0182,$01fe,$0182,$02fe
	dc.w	$0182,$02fd,$0182,$03fd,$0182,$03fc,$0182,$04fc
	dc.w	$0182,$04fb,$0182,$05fb,$0182,$05fa,$0182,$06fa
	dc.w	$0182,$06f9,$0182,$07f9,$0182,$07f8,$0182,$08f8
	dc.w	$0182,$08f7,$0182,$09f7,$0182,$09f6,$0182,$0af6
	dc.w	$0182,$0af5,$0182,$0bf5,$0182,$0bf4,$0182,$0cf4
	dc.w	$0182,$0cf3,$0182,$0df3,$0182,$0df2,$0182,$0ef2
	dc.w	$0182,$0ef1,$0182,$0ff1,$0182,$0ff0,$0182,$0ff0
	dc.w	$0182,$0ff0,$0182,$0ff0,$0182,$0ff0,$0182,$0def

	dc.w	$1037,$fffe
	dc.w	$0182,$00ff,$0182,$00ff,$0182,$00ff,$0182,$00ff
	dc.w	$0182,$00ff,$0182,$00ff,$0182,$00ff,$0182,$00ff
	dc.w	$0182,$00ff,$0182,$01ff,$0182,$01fe,$0182,$02fe
	dc.w	$0182,$02fd,$0182,$03fd,$0182,$03fc,$0182,$04fc
	dc.w	$0182,$04fb,$0182,$05fb,$0182,$05fa,$0182,$06fa
	dc.w	$0182,$06f9,$0182,$07f9,$0182,$07f8,$0182,$08f8
	dc.w	$0182,$08f7,$0182,$09f7,$0182,$09f6,$0182,$0af6
	dc.w	$0182,$0af5,$0182,$0bf5,$0182,$0bf4,$0182,$0cf4
	dc.w	$0182,$0cf3,$0182,$0df3,$0182,$0df2,$0182,$0ef2
	dc.w	$0182,$0ef1,$0182,$0ff1,$0182,$0ff0,$0182,$0ff0
	dc.w	$0182,$0ff0,$0182,$0ff0,$0182,$0ff0,$0182,$0def

	dc.w	$1137,$fffe
	dc.w	$0182,$00ff,$0182,$00ff,$0182,$00ff,$0182,$00ff
	dc.w	$0182,$00ff,$0182,$00ff,$0182,$00ff,$0182,$00ff
	dc.w	$0182,$00ff,$0182,$01ff,$0182,$01fe,$0182,$02fe
	dc.w	$0182,$02fd,$0182,$03fd,$0182,$03fc,$0182,$04fc
	dc.w	$0182,$04fb,$0182,$05fb,$0182,$05fa,$0182,$06fa
	dc.w	$0182,$06f9,$0182,$07f9,$0182,$07f8,$0182,$08f8
	dc.w	$0182,$08f7,$0182,$09f7,$0182,$09f6,$0182,$0af6
	dc.w	$0182,$0af5,$0182,$0bf5,$0182,$0bf4,$0182,$0cf4
	dc.w	$0182,$0cf3,$0182,$0df3,$0182,$0df2,$0182,$0ef2
	dc.w	$0182,$0ef1,$0182,$0ff1,$0182,$0ff0,$0182,$0ff0
	dc.w	$0182,$0ff0,$0182,$0ff0,$0182,$0ff0,$0182,$0def

	dc.w	$1237,$fffe
	dc.w	$0182,$00ff,$0182,$00ff,$0182,$00ff,$0182,$00ff
	dc.w	$0182,$00ff,$0182,$00ff,$0182,$00ff,$0182,$00ff
	dc.w	$0182,$00ff,$0182,$01ff,$0182,$01fe,$0182,$02fe
	dc.w	$0182,$02fd,$0182,$03fd,$0182,$03fc,$0182,$04fc
	dc.w	$0182,$04fb,$0182,$05fb,$0182,$05fa,$0182,$06fa
	dc.w	$0182,$06f9,$0182,$07f9,$0182,$07f8,$0182,$08f8
	dc.w	$0182,$08f7,$0182,$09f7,$0182,$09f6,$0182,$0af6
	dc.w	$0182,$0af5,$0182,$0bf5,$0182,$0bf4,$0182,$0cf4
	dc.w	$0182,$0cf3,$0182,$0df3,$0182,$0df2,$0182,$0ef2
	dc.w	$0182,$0ef1,$0182,$0ff1,$0182,$0ff0,$0182,$0ff0
	dc.w	$0182,$0ff0,$0182,$0ff0,$0182,$0ff0,$0182,$0def

	dc.w	$1337,$fffe
	dc.w	$0182,$00ff,$0182,$00ff,$0182,$00ff,$0182,$00ff
	dc.w	$0182,$00ff,$0182,$00ff,$0182,$00ff,$0182,$00ff
	dc.w	$0182,$00ff,$0182,$01ff,$0182,$01fe,$0182,$02fe
	dc.w	$0182,$02fd,$0182,$03fd,$0182,$03fc,$0182,$04fc
	dc.w	$0182,$04fb,$0182,$05fb,$0182,$05fa,$0182,$06fa
	dc.w	$0182,$06f9,$0182,$07f9,$0182,$07f8,$0182,$08f8
	dc.w	$0182,$08f7,$0182,$09f7,$0182,$09f6,$0182,$0af6
	dc.w	$0182,$0af5,$0182,$0bf5,$0182,$0bf4,$0182,$0cf4
	dc.w	$0182,$0cf3,$0182,$0df3,$0182,$0df2,$0182,$0ef2
	dc.w	$0182,$0ef1,$0182,$0ff1,$0182,$0ff0,$0182,$0ff0
	dc.w	$0182,$0ff0,$0182,$0ff0,$0182,$0ff0,$0182,$0def

	dc.w	$1407,$fffe,$0180,$0000,$0100,$0000
	dc.w	$1607,$fffe,$0180,$075f,$1807,$fffe,$0180,$0000
	dc.w	$1907,$fffe,$0100,$1000,$0180,$0222,$0182,$0000
planes3	dc.w	$00e0,$0000,$00e2,$0000

	dc.w	$ffff,$fffe,$ffff,$fffe	


k_color:
	dc.w	$040b,$030a,$050a,$0409,$0609,$0508,$0708,$0607
	dc.w	$0807,$0706,$0906,$0805,$0a05,$0904,$0b04,$0a03
	dc.w	$0c03,$0b02,$0d02,$0c01

k_set:	dc.b	1,0,0,0,0,0,0,0,0,0

blue:
	dc.w	$0abc,$09ab,$0025,$0014,$0def,$0cde,$0014,$0003
	dc.w	$0abc,$09ab,$0025,$0014
red:
	dc.w	$0520,$0410,$0cba,$0ba9,$0410,$0300,$0fed,$0edc
	dc.w	$0520,$0410,$0cba,$0ba9
green:
	dc.w	$0acb,$09ba,$0052,$0041,$0dfe,$0ced,$0041,$0030
	dc.w	$0acb,$09ba,$0052,$0041

red2:
	dc.w	$0f20,$0e10,$0cba,$0ba9,$0e10,$0d00,$0fed,$0edc
	dc.w	$0f20,$0e10,$0cba,$0ba9

mouse_dat:
mousex:	dc.w	0
mousey:	dc.w	0
mx:	dc.w	0
my:	dc.w	0
minx:	dc.w	0
maxx:	dc.w	0
miny:	dc.w	1
maxy:	dc.w	40

kx:		dc.w	0*2
ky:		dc.w	0*2
kz:		dc.w	0*2

x_pos:		dc.w	94
y_pos:		dc.w	73
dist2:		dc.w	1900

store:		blk.w	1000,0
z_coords:	blk.w	500,0

X_angle=3
Y_angle=4
Z_angle=1

prefs:	dc.l	obj1
coords:	dc.l	koords1

;OBJECT


;----------Object------------

OBJ1:	
	dc.w	00,01,00,4*4+10,03, 00,01,01,02,02,00,00,00
	dc.w	00,01,00,4*4+10,03, 00,03,03,04,04,00,00,00

	dc.w	00,01,00,4*4+10,03, 05,01,01,04,04,05,05,05
	dc.w	00,01,00,4*4+10,03, 05,06,06,07,07,05,05,05

	dc.w	00,01,00,4*4+10,03, 08,06,06,04,04,08,08,08
	dc.w	00,01,00,4*4+10,03, 08,03,03,09,09,08,08,08

	dc.w	00,01,00,4*4+10,03, 10,03,03,02,02,10,10,10
	dc.w	00,01,00,4*4+10,03, 10,11,11,09,09,10,10,10

	dc.w	00,01,00,4*4+10,03, 12,06,06,09,09,12,12,12
	dc.w	00,01,00,4*4+10,03, 12,11,11,07,07,12,12,12

	dc.w	00,01,00,4*4+10,03, 13,01,01,07,07,13,13,13
	dc.w	00,01,00,4*4+10,03, 13,11,11,02,02,13,13,13
	dc.w	9999

	dc.w	00,01,00,4*4+10,03, 00,04,04,01,01,00,00,00
	dc.w	00,01,00,4*4+10,03, 00,02,02,03,03,00,00,00

	dc.w	00,01,00,4*4+10,03, 05,07,07,01,01,05,05,05
	dc.w	00,01,00,4*4+10,03, 05,04,04,06,06,05,05,05

	dc.w	00,01,00,4*4+10,03, 08,04,04,03,03,08,08,08
	dc.w	00,01,00,4*4+10,03, 08,09,09,06,06,08,08,08

	dc.w	00,01,00,4*4+10,03, 10,02,02,11,11,10,10,10
	dc.w	00,01,00,4*4+10,03, 10,09,09,03,03,10,10,10

	dc.w	00,01,00,4*4+10,03, 12,07,07,06,06,12,12,12
	dc.w	00,01,00,4*4+10,03, 12,09,09,11,11,12,12,12

	dc.w	00,01,00,4*4+10,03, 13,07,07,11,11,13,13,13
	dc.w	00,01,00,4*4+10,03, 13,02,02,01,01,13,13,13

	dc.w	9999

;objekti:         X    Y    Z

KOORDS1:

	dc.w	0000,0000,0220	;0
	dc.w	-150,0150,0150	;1
	dc.w	0150,0150,0150	;2
	dc.w	0150,-150,0150	;3
	dc.w	-150,-150,0150	;4
	dc.w	-220,0000,0000	;5
	dc.w	-150,-150,-150	;6
	dc.w	-150,0150,-150	;7
	dc.w	0000,-220,0000	;8
	dc.w	0150,-150,-150	;9
	dc.w	0220,0000,0000	;10
	dc.w	0150,0150,-150	;11
	dc.w	0000,0000,-220	;12
	dc.w	0000,0220,0000	;13
	dc.w	9999

pallo:
	dc.w	0000,0000,0220	;0
	dc.w	-150,0150,0150	;1
	dc.w	0150,0150,0150	;2
	dc.w	0150,-150,0150	;3
	dc.w	-150,-150,0150	;4
	dc.w	-220,0000,0000	;5
	dc.w	-150,-150,-150	;6
	dc.w	-150,0150,-150	;7
	dc.w	0000,-220,0000	;8
	dc.w	0150,-150,-150	;9
	dc.w	0220,0000,0000	;10
	dc.w	0150,0150,-150	;11
	dc.w	0000,0000,-220	;12
	dc.w	0000,0220,0000	;13
	dc.w	9999

kolmio:
	dc.w	0000,0000,0220	;0
	dc.w	-050,0050,0100	;1
	dc.w	0050,0050,0100	;2
	dc.w	0050,-050,0100	;3
	dc.w	-050,-050,0100	;4
	dc.w	-100,0000,0000	;5
	dc.w	-100,-100,-100	;6
	dc.w	-100,0100,-100	;7
	dc.w	0000,-100,0000	;8
	dc.w	0100,-100,-100	;9
	dc.w	0100,0000,0000	;10
	dc.w	0100,0100,-100	;11
	dc.w	0000,0000,-100	;12
	dc.w	0000,0100,0000	;13
	dc.w	9999

kuutio:
	dc.w	0000,0000,0150	;0
	dc.w	-150,0150,0150	;1
	dc.w	0150,0150,0150	;2
	dc.w	0150,-150,0150	;3
	dc.w	-150,-150,0150	;4
	dc.w	-150,0000,0000	;5
	dc.w	-150,-150,-150	;6
	dc.w	-150,0150,-150	;7
	dc.w	0000,-150,0000	;8
	dc.w	0150,-150,-150	;9
	dc.w	0150,0000,0000	;10
	dc.w	0150,0150,-150	;11
	dc.w	0000,0000,-150	;12
	dc.w	0000,0150,0000	;13
	dc.w	9999

kartio:
	dc.w	0000,0000,0100	;0
	dc.w	-100,0030,0100	;1
	dc.w	0100,0030,0100	;2
	dc.w	0100,-030,0100	;3
	dc.w	-100,-030,0100	;4
	dc.w	-100,0000,0000	;5
	dc.w	-100,-030,-100	;6
	dc.w	-100,0030,-100	;7
	dc.w	0000,-100,0000	;8
	dc.w	0100,-030,-100	;9
	dc.w	0100,0000,0000	;10
	dc.w	0100,0030,-100	;11
	dc.w	0000,0000,-100	;12
	dc.w	0000,0100,0000	;13
	dc.w	9999


filet
	dc.l	file1,file2,file3,file4,file5,file6,file7,file8,file9,file0
	dc.l	0
	dc.l	0
	dc.l	0
	
file1	dc.b	"dfn_01.exe",$a,"pack.exe",0
	even
file2	dc.b	"dfn_02.exe",$a,"pack.exe",0
	even
file3	dc.b	"dfn_03.exe",$a,"pack.exe",0
	even
file4	dc.b	"dfn_04.exe",$a,"pack.exe",0
	even
file5	dc.b	"dfn_05.exe",$a,"pack.exe",0
	even
file6	dc.b	"dfn_06.exe",$a,"pack.exe",0
	even
file7	dc.b	"dfn_07.exe",$a,"pack.exe",0
	even
file8	dc.b	"dfn_08.exe",$a,"pack.exe",0
	even
file9	dc.b	"dfn_09.exe",$a,"pack.exe",0
	even
file0	dc.b	"dfn_10.exe",$a,"pack.exe",0
	even

;SIN & COS TABLE

SIN	DC.W	$0000,$0004,$0008,$000D,$0011,$0016,$001A,$001F
	DC.W	$0023,$0028,$002C,$0030,$0035,$0039,$003D,$0042
	DC.W	$0046,$004A,$004F,$0053,$0057,$005B,$005F,$0064
	DC.W	$0068,$006C,$0070,$0074,$0078,$007C,$007F,$0083
	DC.W	$0087,$008B,$008F,$0092,$0096,$009A,$009D,$00A1
	DC.W	$00A4,$00A7,$00AB,$00AE,$00B1,$00B5,$00B8,$00BB
	DC.W	$00BE,$00C1,$00C4,$00C6,$00C9,$00CC,$00CF,$00D1
	DC.W	$00D4,$00D6,$00D9,$00DB,$00DD,$00DF,$00E2,$00E4
	DC.W	$00E6,$00E8,$00E9,$00EB,$00ED,$00EE,$00F0,$00F2
	DC.W	$00F3,$00F4,$00F6,$00F7,$00F8,$00F9,$00FA,$00FB
	DC.W	$00FC,$00FC,$00FD,$00FE,$00FE,$00FF,$00FF,$00FF
	DC.W	$00FF,$00FF
;	DC.W	$0100,$00FF,$00FF,$00FF,$00FF,$00FF
;	DC.W	$00FE,$00FE,$00FD,$00FC,$00FC,$00FB,$00FA,$00F9
;	DC.W	$00F8,$00F7,$00F6,$00F4,$00F3,$00F2,$00F0,$00EE
;	DC.W	$00ED,$00EB,$00E9,$00E8,$00E6,$00E4,$00E2,$00DF
;	DC.W	$00DD,$00DB,$00D9,$00D6,$00D4,$00D1,$00CF,$00CC
;	DC.W	$00C9,$00C6,$00C4,$00C1,$00BE,$00BB,$00B8,$00B5

COS
	DC.W	$0100,$00FF,$00FF,$00FF,$00FF,$00FF
	DC.W	$00FE,$00FE,$00FD,$00FC,$00FC,$00FB,$00FA,$00F9
	DC.W	$00F8,$00F7,$00F6,$00F4,$00F3,$00F2,$00F0,$00EE
	DC.W	$00ED,$00EB,$00E9,$00E8,$00E6,$00E4,$00E2,$00DF
	DC.W	$00DD,$00DB,$00D9,$00D6,$00D4,$00D1,$00CF,$00CC
	DC.W	$00C9,$00C6,$00C4,$00C1,$00BE,$00BB,$00B8,$00B5
	DC.W	$00B1,$00AE,$00AB,$00A7,$00A4,$00A1,$009D,$009A
	DC.W	$0096,$0092,$008F,$008B,$0087,$0083,$0080,$007C
	DC.W	$0078,$0074,$0070,$006C,$0068,$0064,$005F,$005B
	DC.W	$0057,$0053,$004F,$004A,$0046,$0042,$003D,$0039
	DC.W	$0035,$0030,$002C,$0028,$0023,$001F,$001A,$0016
	DC.W	$0011,$000D,$0008,$0004,$0000,$FFFB,$FFF7,$FFF2
	DC.W	$FFEE,$FFE9,$FFE5,$FFE0,$FFDC,$FFD7,$FFD3,$FFCF
	DC.W	$FFCA,$FFC6,$FFC2,$FFBD,$FFB9,$FFB5,$FFB0,$FFAC
	DC.W	$FFA8,$FFA4,$FFA0,$FF9B,$FF97,$FF93,$FF8F,$FF8B
	DC.W	$FF87,$FF83,$FF80,$FF7C,$FF78,$FF74,$FF70,$FF6D
	DC.W	$FF69,$FF65,$FF62,$FF5E,$FF5B,$FF58,$FF54,$FF51
	DC.W	$FF4E,$FF4A,$FF47,$FF44,$FF41,$FF3E,$FF3B,$FF39
	DC.W	$FF36,$FF33,$FF30,$FF2E,$FF2B,$FF29,$FF26,$FF24
	DC.W	$FF22,$FF20,$FF1D,$FF1B,$FF19,$FF17,$FF16,$FF14
	DC.W	$FF12,$FF11,$FF0F,$FF0D,$FF0C,$FF0B,$FF09,$FF08
	DC.W	$FF07,$FF06,$FF05,$FF04,$FF03,$FF03,$FF02,$FF01
	DC.W	$FF01,$FF00,$FF00,$FF00,$FF00,$FF00,$FF00,$FF00
	DC.W	$FF00,$FF00,$FF00,$FF00,$FF01,$FF01,$FF02,$FF03
	DC.W	$FF03,$FF04,$FF05,$FF06,$FF07,$FF08,$FF09,$FF0B
	DC.W	$FF0C,$FF0D,$FF0F,$FF11,$FF12,$FF14,$FF16,$FF17
	DC.W	$FF19,$FF1B,$FF1D,$FF20,$FF22,$FF24,$FF26,$FF29
	DC.W	$FF2B,$FF2E,$FF30,$FF33,$FF36,$FF39,$FF3B,$FF3E
	DC.W	$FF41,$FF44,$FF47,$FF4A,$FF4E,$FF51,$FF54,$FF58
	DC.W	$FF5B,$FF5E,$FF62,$FF65,$FF69,$FF6D,$FF70,$FF74
	DC.W	$FF78,$FF7C,$FF7F,$FF83,$FF87,$FF8B,$FF8F,$FF93
	DC.W	$FF97,$FF9B,$FFA0,$FFA4,$FFA8,$FFAC,$FFB0,$FFB5
	DC.W	$FFB9,$FFBD,$FFC2,$FFC6,$FFCA,$FFCF,$FFD3,$FFD7
	DC.W	$FFDC,$FFE0,$FFE5,$FFE9,$FFEE,$FFF2,$FFF7,$FFFB
	DC.W	$0000,$0004,$0008,$000D,$0011,$0016,$001A,$001F
	DC.W	$0023,$0028,$002C,$0030,$0035,$0039,$003D,$0042
	DC.W	$0046,$004A,$004F,$0053,$0057,$005B,$005F,$0064
	DC.W	$0068,$006C,$0070,$0074,$0078,$007C,$007F,$0083
	DC.W	$0087,$008B,$008F,$0092,$0096,$009A,$009D,$00A1
	DC.W	$00A4,$00A7,$00AB,$00AE,$00B1,$00B5,$00B8,$00BB
	DC.W	$00BE,$00C1,$00C4,$00C6,$00C9,$00CC,$00CF,$00D1
	DC.W	$00D4,$00D6,$00D9,$00DB,$00DD,$00DF,$00E2,$00E4
	DC.W	$00E6,$00E8,$00E9,$00EB,$00ED,$00EE,$00F0,$00F2
	DC.W	$00F3,$00F4,$00F6,$00F7,$00F8,$00F9,$00FA,$00FB
	DC.W	$00FC,$00FC,$00FD,$00FE,$00FE,$00FF,$00FF,$00FF
	DC.W	$00FF,$00FF,$0100,$00FF,$00FF,$00FF,$00FF,$00FF
	DC.W	$00FE,$00FE,$00FD,$00FC,$00FC,$00FB,$00FA,$00F9
	DC.W	$00F8,$00F7,$00F6,$00F4,$00F3,$00F2,$00F0,$00EE
	DC.W	$00ED,$00EB,$00E9,$00E8,$00E6,$00E4,$00E2,$00DF
	DC.W	$00DD,$00DB,$00D9,$00D6,$00D4,$00D1,$00CF,$00CC
	DC.W	$00C9,$00C6,$00C4,$00C1,$00BE,$00BB,$00B8,$00B5
	DC.W	$00B1,$00AE,$00AB,$00A7,$00A4,$00A1,$009D,$009A
	DC.W	$0096,$0092,$008F,$008B,$0087,$0083,$0080,$007C

menutxt	dc.b	"TOMAATTI&SOSE PACK 00"
	dc.b	"---------------------"
	dc.b	"                     "
	DC.B	"DIFFUSION  PARTYINVIT"	
	DC.B	"MOVEMENT   40KB INTRO"
	DC.B	"SPACEBALLS 40KB INTRO"
	DC.B	"DIFFUSION  KAURAPUURO"
	DC.B	"DIFFUSION       INTRO"
	DC.B	"VD/FLT          INTRO"
	DC.B	"GENOCIDE        INTRO"
	DC.B	"SANITY       HOSPITAL"
	DC.B	"PARADOX   CRACK-INTRO"
	DC.B	"M&K             INTRO"

scrolltxt
	dc.b	" HELLO ! AND WELCOME TO TOMAATTISOSE PACK "
	DC.B	"0000 BETA... FIRST DA CREDITS FOR THIS PACK "
	DC.B	"* CODE AND FONT - ASTRAL @ * MUSIC - BEATHAWK @ "
	DC.B	"* LOGO - ROCK LOBSTER @ * MINI-DFN - BRAINIAK @ * "
	DC.B	"PACKED - ASTRAL @    ... PRESS RIGHT MOUSE BUTTON "
	DC.B	"FOR MAG-PART ... GREETINGS FROM ME GOES TO: * "
	DC.B	"QUACKBUSTER/STATIC BYTES - SCAVY/TRANCE - IRON/MAD "
	DC.B	"ELKS - ATOMIC/ORION - DARREN/SCOOPEX - ELVIS/LIMBO - "
	DC.B	"CHARON SOFTWARE - LENIN/FREEZERS - WARHAWK/OBSESSION - "
	DC.B	"QBA/ILLUSION - GODFATHER - LINUS BLOM - AND ALL THE "
	DC.B	"REST ... @    WELL, JUST WAIT FOR THE FIRST PACK, MADE"
	DC.B	" BY VIPER...     C U ..                              "
	dc.b	"                                       "
	DC.B	$FF,$20,$20

	even
	
scrpl:	blk.b	$2c0,0
	even

font	incbin	"Wdh0:Gfx/Raw/partyfont.raw"
scrf	incbin	"Wdh0:Gfx/Raw/scrfade.raw"
_apu1:	bra.w	_apu1b
_apu2:	bra.w	_apu2b
_apu3:	bra.w	_apu3b
logo	incbin	"Wdh0:Gfx/Raw/diflogo11.raw"
tausta	incbin	"Wdh0:Gfx/Raw/mini-dfn.raw"
	even
_apu1b:	
	bsr	P50_Init
	rts
_apu2b:	
	bsr.w	P50_Music
	rts
_apu3b:	
	bsr.w	P50_End
	rts
	
;	section	Player5.0A,code

	rts

;P50_IRQsave	dc	0
;P50_DMAsave	dc	0
;P50_raster	dc.l	0
;P50_raster2	dc.l	0
;P50_frames	dc.l	0
;P50_diri	dc	1

*********************************
*        Player v5.0A ฎ		*
*      All in one-version	*
*     MC68000/68010-version	*
*        Version 503.1		*
*    ฉ 1992 Jarno Paananen	*
*     All rights reserved	*
*********************************


******** START OF BINARY FILE **************

P50_motuuli
	bra	P50_Init
	ifeq	CIA
	bra	P50_Music
	else
	rts
	rts
	endc
	bra	P50_End
	rts				;no P50_SetRepeat
	rts

P50_master	dc	64		;Master volume (0-64)
P50_Tempo	dc	1		;Use tempo? 0=no,non 0=yes
P50_play	dc	1		;Stop flag (0=stop)

P50_Temp0Offset
	dc.l	P50_temp0-P50_motuuli
P50_Temp1Offset
	dc.l	P50_temp1-P50_motuuli
P50_Temp2Offset
	dc.l	P50_temp2-P50_motuuli
P50_Temp3Offset
	dc.l	P50_temp3-P50_motuuli

P50_getnote	macro
	moveq	#$7e,d0
	and.b	(a5),d0
	beq.b	.nonote\@
	ifne	P50_vib
	clr.b	P50_VibPos(a5)
	endc

	ifne	P50_ft
	add	P50_Fine(a5),d0
	endc
	move	d0,P50_Note(a5)
	move	(a2,d0),P50_Period(a5)

.nonote\@
	endm

	ifne	CIA

	ifeq	system
P50_intti
	movem.l	d0-a6,-(sp)
	tst.b	$bfdd00
	move.b	#$7e,$bfdd00

	lea	$dff000,a6
;	move	#$fff,$180(a6)
	bsr	P50_Music
;	move	#0,$180(a6)
	move	#$2000,$9c(a6)
	movem.l	(sp)+,d0-a6
	rte

	else
P50_lev6server
	movem.l	d2-d7/a2-a6,-(sp)
	lea	$dff000,a6
	lea	P50_cn(pc),a3
	move	P50_server(pc),d0
	bne.b	P50_eieka
	pea	P50_ohi(pc)
	bra	P50_Music
P50_eieka
	subq	#1,d0
	beq	P50_dmason
	bra	P50_setrepeat
P50_ohi	movem.l	(sp)+,d2-d7/a2-a6
	moveq	#1,d0
	rts
	endc
	endc

;ญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญ
;ญ Call P50_Init to initialize the playroutine	ญ
;ญ D0 --> Timer detection (for CIA-version)	ญ
;ญ A0 --> Address to the module			ญ
;ญ A1 --> Address to samples/0			ญ
;ญ A6 --> Customchip baseaddress ($DFF000)	ญ
;ญ D0 <-- 0 if succeeded			ญ
;ญ 		Uses A0-A5/D0-D6		ญ
;ญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญ


P50_Init
	cmp.l	#"P50A",(a0)+
	beq.b	.modok
	subq.l	#4,a0

.modok	basereg	P50_cn,a3
	lea	P50_cn(pc),a3

	ifne	CIA
	move	d0,-(sp)
	endc

	move.l	a1,d0
	bne.b	.redirect

	moveq	#0,d0
	move	(a0),d0
	lea	(a0,d0.l),a1
.redirect
	lea	4(a0),a2
	lea	P50_Samples(pc),a4
	moveq	#0,d1
	move.b	3(a0),d1
	subq	#1,d1
	moveq	#0,d4
P50_lopos
	move.l	a1,(a4)+
	move	(a2)+,d4
	bpl.b	P50_kook
	neg	d4
	asl	#4,d4
	lea	P50_Samples-16(pc),a5
	move.l	(a5,d4),d6
	move.l	d6,-4(a4)
	move	4(a5,d4),d4
	sub.l	d4,a1
	sub.l	d4,a1
	bra.b	P50_jatk

P50_kook
	move.l	a1,d6
P50_jatk
	move	d4,(a4)+
	moveq	#0,d2
	move.b	(a2)+,d2
	moveq	#0,d3
	move.b	(a2)+,d3
	moveq	#0,d0
	move	(a2)+,d0
	bmi.b	.norepeat

	move	d4,d5
	sub	d0,d5
	add.l	d0,d0
	move.l	d6,a5
	lea	(a5,d0.l),a5
	move.l	a5,(a4)+
	move	d5,(a4)+
	bra.b	P50_gene
.norepeat
	move.l	d6,(a4)+
	move	#1,(a4)+
P50_gene
	move	d3,(a4)+
	mulu	#74,d2
	move	d2,(a4)+
	add.l	d4,a1
	add.l	d4,a1
	dbf	d1,P50_lopos

	lea	P50_temp0(pc),a1
	lea	P50_temp1(pc),a2
	lea	P50_temp2(pc),a4
	lea	P50_temp3(pc),a5
	moveq	#Channel_Block_SIZE/2-2,d0
	moveq	#0,d1
.cl	move	d1,(a1)+
	move	d1,(a2)+
	move	d1,(a4)+
	move	d1,(a5)+
	dbf	d0,.cl

	moveq	#0,d0
	move.b	3(a0),d0
	mulu	#6,d0
	lea	4(a0,d0.l),a1
	move.l	a1,P50_positionbase(a3)

	move.b	2(a0),d1
	lsl	#3,d1
	lea	(a1,d1.l),a4
	move.l	a4,P50_possibase(a3)

	move.l	a4,a2
	moveq	#-1,d0
.search	cmp.b	(a2)+,d0
	bne.b	.search
	move.l	a2,P50_patternbase(a3)	

	ifd	start
	lea	start(a4),a4
	endc

	moveq	#0,d0
	move.b	(a4)+,d0
	move.l	a4,P50_spos(a3)
	lsl	#2,d0
	add.l	d0,a1

	move.l	a2,a4
	moveq	#0,d0	
	move	(a1)+,d0
	lea	(a4,d0.l),a2
	move.l	a2,P50_ChaPos+P50_temp0(a3)
	move	(a1)+,d0
	lea	(a4,d0.l),a2
	move.l	a2,P50_ChaPos+P50_temp1(a3)
	move	(a1)+,d0
	lea	(a4,d0.l),a2
	move.l	a2,P50_ChaPos+P50_temp2(a3)
	move	(a1)+,d0
	lea	(a4,d0.l),a2
	move.l	a2,P50_ChaPos+P50_temp3(a3)

	lea	P50_setrepeat(pc),a0
	move.l	a0,P50_intaddr(a3)

	move	#63,P50_rowpos(a3)
	move	#6,P50_speed(a3)
	move	#5,P50_speed2(a3)
	clr	P50_speedis1(a3)

	ifne	P50_pl
	clr	P50_plflag(a3)
	clr	P50_plcount(a3)
	endc

	ifne	P50_pde
	clr	P50_pdelay(a3)
	endc
	clr	(a3)

	bset	#1,$bfe001

	ifeq	system
	move.l	4.w,a6
	moveq	#0,d0
	btst	d0,297(a6)
	beq.b	.no68010

	lea	P50_liko(pc),a5
	jsr	-$1e(a6)

.no68010
	move.l	d0,P50_vektori(a3)
	move.l	d0,a0
	move.l	$78(a0),P50_oldlev6(a3)
	endc

	moveq	#0,d0
	lea	$dff000,a6
	move	d0,$a8(a6)
	move	d0,$b8(a6)
	move	d0,$c8(a6)
	move	d0,$d8(a6)
	move	#$f,$96(a6)

	ifeq	system
	move	#$2000,$9a(a6)
	lea	$bfd000,a0
	move.b	#$7f,$d00(a0)
	move.b	#8,$e00(a0)
	endc

	ifeq	CIA
	move.b	#$4a,$400(a0)
	move.b	#1,$500(a0)
.wati
	btst	d0,$d00(a0)
	beq.b	.wati
	move.b	#$81,$d00(a0)
	move	#$e000,$9a(a6)
	endc

	ifne	CIA
	move	(sp)+,d0
	subq	#1,d0
	beq.b	P50_ForcePAL
	subq	#1,d0
	beq.b	P50_NTSC
	move.l	4.w,a1
	cmp.b	#60,$212(a1)	;VBlankFrequency
	beq.b	P50_NTSC
P50_ForcePAL
	move.l	#1773447,d0	;PAL
	bra.b	P50_setcia
P50_NTSC
	move.l	#1789773,d0	;NTSC
P50_setcia
	move.l	d0,P50_timer(a3)
	divu	#125,d0
	move	d0,P50_thi2(a3)
	sub	#$1c8*2,d0
	move	d0,P50_thi(a3)

	ifeq	system
	move.b	d0,$400(a0)
	lsr	#8,d0
	move.b	d0,$500(a0)

	lea	P50_intti(pc),a1
	move.l	a1,P50_tintti(a3)
	move.l	P50_vektori(pc),a2
	move.l	a1,$78(a2)

	move.b	#$81,$d00(a0)
	move.b	#$19,$e00(a0)
	moveq	#0,d0
	endc
	endc

	ifeq	system
	move	#$e000,$9a(a6)
	rts

P50_liko
	dc.l	$4E7A0801		;MOVEC	VBR,d0
	rte
	endc

	ifne	system
	move.l	4.w,a6
	moveq	#-1,d0
	jsr	-$14a(a6)
	move.b	d0,P50_sigbit(a3)
	bmi	P50_err

	lea	P50_allocport(pc),a1
	move.l	a1,P50_portti(a3)
	move.b	d0,15(a1)
	move.l	a1,-(sp)
	suba.l	a1,a1
	jsr	-$126(a6)
	move.l	(sp)+,a1
	move.l	d0,16(a1)
	lea	P50_reqlist(pc),a0
	move.l	a0,(a0)
	addq.l	#4,(a0)
	clr.l	4(a0)
	move.l	a0,8(a0)

	lea	P50_dat(pc),a1
	move.l	a1,P50_reqdata(a3)
	lea	P50_allocreq(pc),a1
	lea	P50_audiodev(pc),a0
	moveq	#0,d0
	moveq	#0,d1
	move.l	4.w,a6
	jsr	-$1bc(a6)
	tst.b	d0
	bne	P50_err
	st.b	P50_audioopen(a3)

	lea	P50_timerint(pc),a1
	move.l	a1,P50_timerdata(a3)
	lea	P50_lev6server(pc),a1
	move.l	a1,P50_timerdata+8(a3)

	moveq	#8,d3
	lea	P50_cianame(pc),a1
	move.b	#'b',3(a1)
P50_openciares
	moveq	#0,d0
	jsr	-$1f2(a6)
	move.l	d0,P50_ciares(a3)
	beq.b	P50_tryCIAA
	move.l	d0,a6
	lea	P50_timerinterrupt(pc),a1
	moveq	#0,d0
	jsr	-6(a6)
	tst.l	d0
	beq.b	P50_gottimer
	addq.l	#4,d3
	lea	P50_timerinterrupt(pc),a1
	moveq	#1,d0
	jsr	-6(a6)
	tst.l	d0
	beq.b	P50_gottimer
P50_tryCIAA
	lea	P50_cianame(pc),a1
	cmp.b	#'b',3(a1)
	bne.b	P50_err
	subq.b	#1,3(a1)
	moveq	#0,d3
	bra	P50_openciares

P50_gottimer
	lea	P50_craddr+8(pc),a6
	move.l	P50_ciaaddr(pc,d3),d0
	move.l	d0,(a6)
	sub	#$100,d0
	move.l	d0,-(a6)
	moveq	#2,d3
	btst	#9,d0
	bne.b	P50_timerB
	subq.b	#1,d3
	add	#$100,d0
P50_timerB
	add	#$900,d0
	move.l	d0,-(a6)
	move.l	d0,a0
	and.b	#%10000000,(a0)
	move.b	d3,P50_timeropen(a3)
	moveq	#0,d0

	move.l	P50_craddr+4(pc),a1
	move.b	P50_tlo(pc),(a1)
	move.b	P50_thi(pc),$100(a1)
	or.b	#$19,(a0)
	rts

P50_err	moveq	#-1,d0
	rts

P50_ciaaddr
	dc.l	$bfe501,$bfe701,$bfd500,$bfd700
	endc

;ญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญ
;ญ     	Call P50_End to stop the music		ญ
;ญ   A6 --> Customchip baseaddress ($DFF000)	ญ
;ญ		  Uses D0/A0			ญ
;ญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญ
	
P50_End	moveq	#0,d0
	move	d0,$a8(a6)
	move	d0,$b8(a6)
	move	d0,$c8(a6)
	move	d0,$d8(a6)
	bclr	#1,$bfe001
	move	#$f,$96(a6)

	ifeq	system
	move	#$2000,$9a(a6)
	move.l	P50_vektori(pc),a0
	move.l	P50_oldlev6(pc),$78(a0)

	else
	lea	P50_cn(pc),a3
	moveq	#0,d0
	move.b	P50_timeropen(pc),d0
	beq.b	P50_rem1
	move.l	P50_ciares(pc),a6
	lea	P50_timerinterrupt(pc),a1
	subq.b	#1,d0
	jsr	-$c(a6)
P50_rem1
	move.l	4.w,a6
	tst.b	P50_audioopen(a3)
	beq.b	P50_rem2
	lea	P50_allocreq(a3),a1
	jsr	-$1c2(a6)
	clr.b	P50_audioopen(a3)
P50_rem2
	moveq	#0,d0
	move.b	P50_sigbit(pc),d0
	bmi.b	P50_rem3
	jsr	-$150(a6)
	st	P50_sigbit(a3)
P50_rem3
	endc
	rts

	ifne	fade
P50_mfade
	move	P50_master(pc),d0
	move	P50_temp0+P50_Shadow(pc),d1
	mulu	d0,d1
	lsr	#6,d1
	move	d1,$a8(a6)

	ifgt	channels-1
	move	P50_temp1+P50_Shadow(pc),d1
	mulu	d0,d1
	lsr	#6,d1
	move	d1,$b8(a6)
	endc

	ifgt	channels-2
	move	P50_temp2+P50_Shadow(pc),d1
	mulu	d0,d1
	lsr	#6,d1
	move	d1,$c8(a6)
	endc

	ifgt	channels-3
	move	P50_temp3+P50_Shadow(pc),d1
	mulu	d0,d1
	lsr	#6,d1
	move	d1,$d8(a6)
	endc
	rts
	endc
	
;ญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญ
;ญ Call P50_Music every frame to play the music	ญ
;ญ A6 --> Customchip baseaddress ($DFF000)	ญ
;ญ          	Uses A0-A5/D0-D7		ญ
;ญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญ

P50_Music
	lea	P50_cn(pc),a3

	tst	P50_play(a3)
	bne.b	P50_ohitaaa
	ifne	CIA
	ifeq	system
	move.l	P50_vektori(pc),a5
	move.l	P50_tintti(pc),$78(a5)
	move.b	P50_tlo2(pc),$bfd400
	move.b	P50_thi2(pc),$bfd500

	else
	clr	P50_server(a3)
	move.l	P50_craddr+4(pc),a0
	move.b	P50_tlo2(pc),(a0)
	move.b	P50_thi2(pc),$100(a0)
	endc
	endc
	rts

P50_ohitaaa
	ifne	fade
	pea	P50_mfade(pc)
	endc

	moveq	#Channel_Block_SIZE,d6
	moveq	#16,d7

	move	(a3),d4
	addq	#1,d4
	cmp	P50_speed(pc),d4
	beq	P50_playtime

	move	d4,(a3)

P50_delay
	ifne	CIA
	ifeq	system
	move.l	P50_vektori(pc),a5
	move.l	P50_tintti(pc),$78(a5)
	move.b	P50_tlo2(pc),$bfd400
	move.b	P50_thi2(pc),$bfd500

	else
	clr	P50_server(a3)
	move.l	P50_craddr+4(pc),a0
	move.b	P50_tlo2(pc),(a0)
	move.b	P50_thi2(pc),$100(a0)
	endc
	endc

	lea	P50_temp0(pc),a5
	lea	$a0(a6),a4

	moveq	#channels-1,d5
P50_lopas
	tst	P50_OnOff(a5)
	beq	P50_contfxdone
	moveq	#$f,d0
	and	(a5),d0
	add	d0,d0
	move	P50_jtab2(pc,d0),d0
	jmp	P50_jtab2(pc,d0)

P50_jtab2
	dc	P50_contfxdone-P50_jtab2

	ifne	P50_pu
	dc	P50_portup-P50_jtab2
	else
	dc	P50_contfxdone-P50_jtab2
	endc

	ifne	P50_pd
	dc	P50_portdwn-P50_jtab2
	else
	dc	P50_contfxdone-P50_jtab2
	endc

	ifne	P50_tp
	dc	P50_toneport-P50_jtab2
	else
	dc	P50_contfxdone-P50_jtab2
	endc

	ifne	P50_vib
	dc	P50_vib2-P50_jtab2
	else
	dc	P50_contfxdone-P50_jtab2
	endc

	ifne	P50_tpvs
	dc	P50_tpochvslide-P50_jtab2
	else
	dc	P50_contfxdone-P50_jtab2
	endc

	ifne	P50_vbvs
	dc	P50_vibochvslide-P50_jtab2
	else
	dc	P50_contfxdone-P50_jtab2
	endc

	ifne	P50_tre
	dc	P50_tremo-P50_jtab2
	else
	dc	P50_contfxdone-P50_jtab2
	endc

	ifne	P50_arp
	dc	P50_arpeggio-P50_jtab2
	else
	dc	P50_contfxdone-P50_jtab2
	endc

	dc	P50_contfxdone-P50_jtab2

	ifne	P50_vs
	dc	P50_volslide-P50_jtab2
	else
	dc	P50_contfxdone-P50_jtab2
	endc

	dc	P50_contfxdone-P50_jtab2
	dc	P50_contfxdone-P50_jtab2
	dc	P50_contfxdone-P50_jtab2

	ifne	P50_ec
	dc	P50_contecommands-P50_jtab2
	else
	dc	P50_contfxdone-P50_jtab2
	endc
	dc	P50_contfxdone-P50_jtab2

	ifne	P50_ec
P50_contecommands
	move.b	P50_Info(a5),d0
	and.b	#$f0,d0
	lsr	#3,d0
	move	P50_etab2(pc,d0),d0
	jmp	P50_etab2(pc,d0)

P50_etab2
	dc	P50_contfxdone-P50_etab2

	ifne	P50_fsu
	dc	P50_fineup2-P50_etab2
	else
	dc	P50_contfxdone-P50_etab2
	endc

	ifne	P50_fsd
	dc	P50_finedwn2-P50_etab2
	else
	dc	P50_contfxdone-P50_etab2
	endc

	dc	P50_contfxdone-P50_etab2
	dc	P50_contfxdone-P50_etab2

	dc	P50_contfxdone-P50_etab2
	dc	P50_contfxdone-P50_etab2

	dc	P50_contfxdone-P50_etab2
	dc	P50_contfxdone-P50_etab2

	ifne	P50_rt
	dc	P50_retrig-P50_etab2
	else
	dc	P50_contfxdone-P50_etab2
	endc

	ifne	P50_fvu
	dc	P50_finevup2-P50_etab2
	else
	dc	P50_contfxdone-P50_etab2
	endc

	ifne	P50_fvd
	dc	P50_finevdwn2-P50_etab2
	else
	dc	P50_contfxdone-P50_etab2
	endc

	dc	P50_notecut-P50_etab2

	ifne	P50_nd
	dc	P50_notedelay-P50_etab2
	else
	dc	P50_contfxdone-P50_etab2
	endc

	dc	P50_contfxdone-P50_etab2
	dc	P50_contfxdone-P50_etab2
	endc

	ifne	P50_fsu
P50_fineup2
	tst	(a3)
	bne	P50_contfxdone
	moveq	#$f,d0
	and.b	P50_Info(a5),d0
	sub	d0,P50_Period(a5)
	moveq	#113,d0
	cmp	P50_Period(a5),d0
	ble	.jup
	move	d0,P50_Period(a5)
.jup	move	P50_Period(a5),6(a4)
	bra	P50_contfxdone
	endc

	ifne	P50_fsd
P50_finedwn2
	tst	(a3)
	bne	P50_contfxdone
	moveq	#$f,d0
	and.b	P50_Info(a5),d0
	add	d0,P50_Period(a5)
	cmp	#856,P50_Period(a5)
	ble	.jup
	move	#856,P50_Period(a5)
.jup	move	P50_Period(a5),6(a4)
	bra	P50_contfxdone
	endc

	ifne	P50_fvu
P50_finevup2
	tst	(a3)
	bne	P50_contfxdone
	moveq	#$f,d0
	and.b	P50_Info(a5),d0
	add	d0,P50_Volume(a5)
	moveq	#64,d0
	cmp	P50_Volume(a5),d0
	bge.b	.jup
	move	d0,P50_Volume(a5)
.jup	move	P50_Volume(a5),8(a4)
	bra	P50_contfxdone
	endc

	ifne	P50_fvd
P50_finevdwn2
	tst	(a3)
	bne	P50_contfxdone
	moveq	#$f,d0
	and.b	P50_Info(a5),d0
	sub	d0,P50_Volume(a5)
	bpl.b	.jup
	clr	P50_Volume(a5)
.jup	move	P50_Volume(a5),8(a4)
	bra	P50_contfxdone
	endc

	ifne	P50_nc
P50_notecut
	moveq	#$f,d0
	and.b	P50_Info(a5),d0
	cmp	(a3),d0
	bne	P50_contfxdone
	ifeq	fade
	clr	8(a4)
	else
	clr	P50_Shadow(a5)
	endc
	clr	P50_Volume(a5)
	bra	P50_contfxdone
	endc

	ifne	P50_nd
P50_notedelay
	moveq	#$f,d0
	and.b	P50_Info(a5),d0
	cmp	(a3),d0
	bne	P50_contfxdone

	moveq	#$7e,d0
	and.b	(a5),d0
	beq	P50_contfxdone
	move	P50_DMABit(a5),d0
	move	d0,$96(a6)
	or	d0,P50_dma(a3)
	move.l	P50_Sample(a5),a1
	move.l	(a1)+,(a4)+
	move	(a1),(a4)+
	move	P50_Period(a5),(a4)
	subq.l	#6,a4
	ifeq	system
	lea	P50_dmason(pc),a1
	move.l	a1,d0
	move.l	P50_vektori(pc),a1
	move.l	d0,$78(a1)
	endc

	ifeq	CIA
	move.b	#$19,$bfde00
	else
	ifeq	system
	move.b	#$4a,$bfd400
	move.b	#1,$bfd500
	else
	move	#1,P50_server(a3)
	move.l	P50_craddr+4(pc),a1
	move.b	#$4a,(a1)
	move.b	#1,$100(a1)
	endc
	endc

	bra	P50_contfxdone
	endc

	ifne	P50_rt
P50_retrig
	subq	#1,P50_RetrigCount(a5)
	bne	P50_contfxdone
	move	P50_DMABit(a5),d0
	move	d0,$96(a6)
	or	d0,P50_dma(a3)
	move.l	P50_Sample(a5),a1
	move.l	(a1)+,(a4)
	move	(a1),4(a4)

	ifeq	system
	lea	P50_dmason(pc),a1
	move.l	a1,d0
	move.l	P50_vektori(pc),a1
	move.l	d0,$78(a1)
	endc

	ifeq	CIA
	move.b	#$19,$bfde00
	else
	ifeq	system
	move.b	#$4a,$bfd400
	move.b	#1,$bfd500
	else
	move	#1,P50_server(a3)
	move.l	P50_craddr+4(pc),a1
	move.b	#$4a,(a1)
	move.b	#1,$100(a1)
	endc
	endc

	moveq	#$f,d0
	and.b	P50_Info(a5),d0
	move	d0,P50_RetrigCount(a5)
	bra	P50_contfxdone
	endc

	ifne	P50_arp
P50_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

P50_arpeggio
	move	(a3),d0
	move.b	P50_arplist(pc,d0),d0
	beq.b	.arp0
	ror.b	#1,d0
	bcc.b	P50_arp1
	moveq	#$f,d0
	and.b	P50_Info(a5),d0
	bra.b	P50_arp3
.arp0
	move	P50_Note(a5),d0
	move	P50_periods(pc,d0),6(a4)
	bra	P50_contfxdone
P50_arp1
	move.b	P50_Info(a5),d0
	lsr	#4,d0
P50_arp3
	add	d0,d0
	add	P50_Note(a5),d0
	move	P50_periods(pc,d0),6(a4)
	bra	P50_contfxdone
	endc

P50_periods
	ifne	P50_ft
	incbin	periodtable
	else
	incbin	periods.nft
	endc

	ifne	P50_vs
P50_volslide
	move.b	P50_Info(a5),d0
	sub.b	d0,P50_Volume+1(a5)
	bpl.b	.test
	clr	P50_Volume(a5)
	ifeq	fade
	clr	8(a4)
	else
	clr	P50_Shadow(a5)
	endc
	bra	P50_contfxdone
.test	moveq	#64,d0
	cmp	P50_Volume(a5),d0
	bge.b	.ncs
	move	d0,P50_Volume(a5)
	ifeq	fade
	move	d0,8(a4)
	else
	move	d0,P50_Shadow(a5)
	endc
	bra.b	P50_contfxdone
.ncs	ifeq	fade
	move	P50_Volume(a5),8(a4)
	else
	move	P50_Volume(a5),P50_Shadow(a5)
	endc
	bra.b	P50_contfxdone
	endc

	ifne	P50_tpvs
P50_tpochvslide
	move.b	P50_Info(a5),d0
	sub.b	d0,P50_Volume+1(a5)
	bpl.b	.test
	clr	P50_Volume(a5)
	ifeq	fade
	clr	8(a4)
	else
	clr	P50_Shadow(a5)
	endc
	bra.b	P50_toneport
.test	moveq	#64,d0
	cmp	P50_Volume(a5),d0
	bge.b	.ncs
	move	d0,P50_Volume(a5)
.ncs	ifeq	fade
	move	P50_Volume(a5),8(a4)
	else
	move	P50_Volume(a5),P50_Shadow(a5)
	endc
	endc

	ifne	P50_tp
P50_toneport
	move	P50_ToPeriod(a5),d0
	beq.b	P50_contfxdone
	move	P50_TPSpeed(a5),d1
	cmp	P50_Period(a5),d0
	blt.b	.topoup

	add	d1,P50_Period(a5)
	cmp	P50_Period(a5),d0
	bgt.b	P50_toposetper
	move	d0,P50_Period(a5)
	clr	P50_ToPeriod(a5)
	move	d0,6(a4)
	bra.b	P50_contfxdone

.topoup
	sub	d1,P50_Period(a5)
	cmp	P50_Period(a5),d0
	blt.b	P50_toposetper
	move	d0,P50_Period(a5)
	clr	P50_ToPeriod(a5)
P50_toposetper
	move	P50_Period(a5),6(a4)
	else
	nop
	endc

P50_contfxdone
	add.l	d6,a5
	add.l	d7,a4
	dbf	d5,P50_lopas

	cmp	P50_speed2(pc),d4
	beq.b	P50_preplay
	rts

	ifne	P50_pu
P50_portup
	moveq	#0,D0
	move.b	P50_Info(a5),d0
	sub	d0,P50_Period(a5)
	moveq	#113,d0
	cmp	P50_Period(a5),d0
	ble.b	.skip
	move	d0,P50_Period(a5)
	move	d0,6(a4)
	bra.b	P50_contfxdone
.skip
	move	P50_Period(a5),6(a4)
	bra.b	P50_contfxdone
	endc

	ifne	P50_pd
P50_portdwn
	moveq	#0,d0
	move.b	P50_Info(a5),d0
	add	d0,P50_Period(a5)
	cmp	#856,P50_Period(a5)
	ble.b	.skip
	move	#856,d0
	move	d0,P50_Period(a5)
	move	d0,6(a4)
	bra.b	P50_contfxdone
.skip
	move	P50_Period(a5),6(a4)
	bra.b	P50_contfxdone
	endc

P50_preplay
	ifne	P50_pde
	tst	P50_pdelay(a3)
	beq.b	.djdj
	rts
.djdj
	endc

	lea	P50_temp0(pc),a5
	lea	P50_Samples-16(pc),a0

	moveq	#channels-1,d5
P50_loaps
	ifne	P50_pl
	move.l	(a5),P50_TData(a5)
	move.l	P50_ChaPos(a5),P50_TChaPos(a5)
	move.l	P50_TempPos(a5),P50_TTempPos(a5)
	move	P50_TempLen(a5),P50_TTempLen(a5)
	endc

	tst.b	P50_Pack(a5)
	beq.b	P50_takeone
	bmi.b	.keepsame

	subq.b	#1,P50_Pack(a5)
	clr	P50_OnOff(a5)
	add.l	d6,a5
	dbf	d5,P50_loaps
	rts

.keepsame
	addq.b	#1,P50_Pack(a5)
	bra.b	P50_dko

P50_takeone
	tst.b	P50_TempLen+1(a5)
	beq.b	P50_takenorm

	subq.b	#1,P50_TempLen+1(a5)
	move.l	P50_TempPos(a5),a2

P50_jedi
	move.l	(a5),P50_TData(a5)
	move.b	(a2)+,(a5)
	bpl.b	P50_normal
	not.b	(a5)+
	move.b	(a2)+,(a5)+
	move.b	(a2)+,(a5)+
	move.b	(a2)+,(a5)+
	subq.l	#4,a5
	move.l	a2,P50_TempPos(a5)
	bra.b	P50_dko
	
P50_normal
	move.b	(a2)+,1(a5)
	move.b	(a2)+,2(a5)
	move.l	a2,P50_TempPos(a5)
	bra.b	P50_dko

P50_takenorm
	move.l	P50_ChaPos(a5),a2
	move.b	(a2)+,(a5)
	bmi.b	P50_packed
	move.b	(a2)+,1(a5)
	move.b	(a2)+,2(a5)
	move.l	a2,P50_ChaPos(a5)
	bra.b	P50_dko

P50_kuiskus
	move.b	(a2)+,P50_TempLen+1(a5)
	moveq	#0,d0
	move.b	(a2)+,d0
	lsl	#8,d0
	move.b	(a2)+,d0

	move.l	a2,P50_ChaPos(a5)
	sub.l	d0,a2
	bra.b	P50_jedi

P50_packed
	cmp.b	#$80,(a5)
	beq.b	P50_kuiskus
	not.b	(a5)+
	move.b	(a2)+,(a5)+
	move.b	(a2)+,(a5)+
	move.b	(a2)+,(a5)+
	subq.l	#4,a5
	move.l	a2,P50_ChaPos(a5)

P50_dko	st	P50_OnOff(a5)
	move	(a5),d0
	and	#$1f0,d0
	beq.b	.koto
	lea	(a0,d0),a1
	move.l	a1,P50_Sample(a5)
	ifne	P50_ft
	move.l	P50_SampleVolume(a1),P50_Volume(a5)
	else
	move	P50_SampleVolume(a1),P50_Volume(a5)
	endc

.koto
	add.l	d6,a5
	dbf	d5,P50_loaps
	rts

P50_playtime
	clr	(a3)
	ifne	P50_pde
	tst	P50_pdelay(a3)
	beq.b	.djdj
	subq	#1,P50_pdelay(a3)
	bra	P50_delay
.djdj
	endc

	tst	P50_speedis1(a3)
	beq.b	.mo
	bsr	P50_preplay

.mo	lea	P50_temp0(pc),a5
	lea	$a0(a6),a4

	ifne	system
	moveq	#1,d4
	move	d4,P50_server(a3)
	move.l	P50_craddr+4(pc),a1
	move.b	#$4a,(a1)
	move.b	d4,$100(a1)
	else
	lea	P50_dmason(pc),a1
	move.l	P50_vektori(pc),