SMPLPLAY


;******************************************************************************
;***************************SAMPLE-PLAYER 0.9**********************************
;***************************BY HENRIK STOLPE***********************************
;******************************************************************************
aud0lch = $dff0a0
aud0len = $dff0a4
aud0per = $dff0a6
aud0vol = $dff0a8
aud1lch = $dff0b0
aud1len = $dff0b4
aud1per = $dff0b6
aud1vol = $dff0b8
aud2lch = $dff0c0
aud2len = $dff0c4
aud2per = $dff0c6
aud2vol = $dff0c8
aud3lch = $dff0d0
aud3len = $dff0d4
aud3per = $dff0d6
aud3vol = $dff0d8
execbase = 4
GetMsg = -372
Wait = -318
ReplyMsg = -378
DrawBorder = -108
PrintLText = -216
OpenWorkBench = -210	
OpenIff = -90
len = 17728				

	incdir	"dh0:assembler/include/"
	include	exec/exec_lib.i
	include	intuition/intuition.i
	include	intuition/intuition_lib.i


s:
	bsr	openall
	bsr	interface
	bsr	inithardware
	bsr	again		;set to again to debug
	rts


openall:
	moveq	#100,d4			
	moveq	#INTUITION_REV,d0	
	lea	int_name(pc),a1
	CALLEXEC OpenLibrary
	tst.l	d0
	beq	exit_false		
	move.l	d0,_IntuitionBase	
	move.l	_IntuitionBase,a6
	jsr	OpenWorkBench(a6)
	moveq.l	#0,d0
	lea	iff_name(pc),a1
	CALLEXEC Openlibrary
	move.l	d0,IffBase
	
openwin:
	lea	windowdef,a0	
	CALLINT	OpenWindow
	move.l	d0,MyWindow		
	rts


interface:
	bsr	lines
	bsr	textpr
	rts


lines:
	lea	box,a1
	move	#9,d0
	move	#14,d1
	bsr	drawit
	rts	

drawit:
	move.l	_IntuitionBase,a6
	move.l	MyWindow,a0
	move.l	50(a0),a0
	jsr	DrawBorder(a6)
	rts
		
textpr:
	lea	text,a1
	move	#10,d0
	move	#80,d1
	bsr	printit
	rts	
	

printit:
	move.l	_IntuitionBase,a6
	move.l	MyWindow,a0
	move.l	50(a0),a0
	jsr	PrintLText(a6)
	rts


loop:
	move.l	MyWindow(pc),a0
        move.l	wd_UserPort(a0),a0
	moveq	#0,d1
	move.b	MP_SIGBIT(a0),d1
	moveq	#0,d0
	bset	d1,d0
	move.l	execbase,a6
	CALLEXEC Wait
	move.l	#0,d4
	bsr	again

again:
	move.l	MyWindow,a0
	move.l	wd_UserPort(a0),a0
	move.l	execbase,a6
	jsr 	GetMsg(a6)
	move.l	d0,a1
	moveq.l	#0,d6
	moveq	#0,d7
	move.l	$14(a1),d6		;IDCPM Class
	move.l	$1c(a1),a2		;Adress	
	move	38(a2),d7		;gadget Id in Adress
*;	jsr	ReplyMsg(a6)		;disable to debug
	cmp.l	#$200,d6
	beq	slut
*;	cmp	#1,d7
*;	beq	load
	cmp	#2,d7
	beq	play
	cmp	#3,d7
	beq	filter
	cmp	#4,d7
	beq	changevol
	cmp	#5,d7
	beq	changerate
	cmp	#6,d7
	beq	changeloop	
	bne	again			;set to again to debug
	rts

;routines

inithardware:

	move.l	 filename,a0
	move.l	d0,ifffile
	move.l	iffbase,a6
	jsr	OpenIff(a6)
	
ifffile:	blk.b			30000,0		
		even

filename:	dc.b	'ram:test',0
		even

vol = 0064				;initial volume
rate =0200				;initial read DMA rate


kanal0:
	move.l	#ifffile,aud0lch
	move	#[len/2],aud0len
	move	#rate,aud0per
	move	#vol,aud0vol
		
kanal1:
	move.l	#ifffile,aud1lch
	move	#[len/2],aud1len
	move	#rate,aud1per
	move	#vol,aud1vol
	
kanal2:
	move.l	#ifffile,aud2lch
	move	#[len/2],aud2len
	move	#rate,aud2per
	move	#vol,aud2vol
	
kanal3:
	move.l	#ifffile,aud3lch
	move	#[len/2],aud3len
	move	#rate,aud3per
	move	#vol,aud3vol
	rts

filter:
	bchg	#1,$bfe001
	bsr	again			;set to again to debug
	rts

play:
	cmp	#1,d3
	beq	killDMA	
		
activateDMA:
	move.w	#$800f,$dff096
	moveq	#1,d3
	bsr	again			;set to again to debug
	rts

killDMA:
	move.w	#$000f,$dff096
	moveq	#0,d3
	bsr	again			;set to again to debug
	rts


changevol:
	moveq	#0,d5
	move	propinfo4+3,d5
	divu	#4,d5			;divide to get 0-63 bounds
	move	d5,aud0vol
	move	d5,aud1vol
	move	d5,aud2vol
	move	d5,aud3vol
	bsr	again			;set to again to debug
	rts

changerate:
	moveq	#0,d5
	move	propinfo5+3,d5
	mulu	#2,d5			;mulu to get a nice range
	add	#100,d5			;set min value
	move	d5,aud0per
	move	d5,aud1per
	move	d5,aud2per
	move	d5,aud3per
	bsr	again			;set to again to debug
	rts
	

changeloop:
	moveq	#0,d5
	moveq	#0,d2
	move	#len,d2			;ljud length
	divu	#256,d2			;dela med max slider get index
	move	propinfo6+3,d5		;get value of slider
	mulu	d2,d5			;ggr the index w value
	divu	#2,d5			;halve
	move	d5,aud0len
	move	d5,aud1len
	move	d5,aud2len
	move	d5,aud3len
	bsr	again			;set to again to debug
	rts
	
slut:
closewin:
	move.l	MyWindow(pc),a0
	CALLINT CloseWindow

closeint
	move.l	_IntuitionBase(pc),a1
	CALLEXEC CloseLibrary

exit_false
	moveq	#0,d4
	move.l	d4,d0			
	rts

;structures
_IntuitionBase	dc.l	0		
IffBase		dc.l	0
MyWindow	dc.l	0
INTUITION_REV	equ	31		v1.1
int_name	INTNAME
iff_name	dc.l	'iff.library',0
windowdef:
	dc.w	365
	dc.w	15
	dc.w	264
	dc.w	100
	dc.b	2
	dc.b	1
	dc.l	$220
	dc.l	$200320e
	dc.l	gad1
	dc.l	0
	dc.l	windowname
	
screenhd:
	dc.l	0
	dc.l	0
	dc.w	230
	dc.w	100
	dc.w	320
	dc.w	200
	dc.w	1

windowname:
	dc.b	'SAMPLEPLAYER V0.9',0
	even
	
windowhd:
	dc.l	0
        even

gad1:
	dc.l	gad2
	dc.w	17,20
	dc.w	80,9
	dc.w	%00000000
	dc.w	$3		;relverify,$100 = toggleselect
	dc.w	1
	dc.l	bord
	dc.l	0
	dc.l	gad1text
	dc.l	0
	dc.l	0
	dc.w	1
	dc.l	0

gad1text:
	dc.b	3,0
	dc.b	1
	even
	dc.w	22,1
	dc.l	0
	dc.l	gd1txt
	dc.l	0

gd1txt:
	dc.b	"LOAD",0
	even



gad2:
	dc.l	gad3
	dc.w	17,40
	dc.w	80,9
	dc.w	%00000000
	dc.w	$3		;relverify/gadgimmediate,($100 = toggleselect)
	dc.w	1
	dc.l	bord
	dc.l	0
	dc.l	gad2text
	dc.l	0
	dc.l	0
	dc.w	2
	dc.l	0

gad2text:
	dc.b	3,0
	dc.b	1
		even
	dc.w	22,1
	dc.l	0
	dc.l	gd2txt
	dc.l	0

gd2txt:
	dc.b	"PLAY",0
	even



gad3:
	dc.l	gad4
	dc.w	17,60
	dc.w	80,9
	dc.w	%00000000
	dc.w	$3		;relverify/gadgimmediate,($100 = toggleselect)
	dc.w	1
	dc.l	bord
	dc.l	0
	dc.l	gad3text
	dc.l	0
	dc.l	0
	dc.w	3
	dc.l	0

gad3text:
	dc.b	3,0
	dc.b	1
	even
	dc.w	16,1
	dc.l	0
	dc.l	gd3txt
	dc.l	0

gd3txt:
	dc.b	"FILTER",0
	even


gad4:
	dc.l	gad5
	dc.w	125,14
	dc.w	24,50
	dc.w	3
	dc.w	2
	dc.w	3
	dc.l	propimage
	dc.l	0
	dc.l	gad4text
	dc.l	0
	dc.l	propinfo4
	dc.w	4
	dc.l	0

gad4text:
	dc.b	3,0
	dc.b	1
	even
	dc.w	-11,52
	dc.l	0
	dc.l	gad4txt
	dc.l	0

gad4txt:
	dc.b	"Volume",0
	even

propinfo4:
	dc.w	$6
	dc.w	0
	dc.w	0
	dc.w	0
	dc.w	$ffff/12
	dc.w	0
	dc.w	0
	dc.w	0
	dc.w	12
	dc.w	0
	dc.w	0
	dc.w	0
gad5:
	dc.l	gad6
	dc.w	175,14
	dc.w	24,50
	dc.w	3
	dc.w	2
	dc.w	3
	dc.l	propimage
	dc.l	0
	dc.l	gad5text
	dc.l	0
	dc.l	propinfo5
	dc.w	5
	dc.l	0
gad5text:
	dc.b	3,0
	dc.b	1
	even
	dc.w	-4,52
	dc.l	0
	dc.l	gad5txt
	dc.l	0

gad5txt:
	dc.b	"Rate",0
	even

propinfo5:
	dc.w	$6
	dc.w	0
	dc.w	0
	dc.w	0
	dc.w	$ffff/12
	dc.w	0
	dc.w	0
	dc.w	0
	dc.w	12
	dc.w	0
	dc.w	0
	dc.w	0

gad6:
	dc.l	0
	dc.w	225,14
	dc.w	24,50
	dc.w	3
	dc.w	2
	dc.w	3
	dc.l	propimage
	dc.l	0
	dc.l	gad6text
	dc.l	0
	dc.l	propinfo6
	dc.w	6
	dc.l	0
gad6text:
	dc.b	3,0
	dc.b	1
	even
	dc.w	-4,52
	dc.l	0
	dc.l	gad6txt
	dc.l	0

gad6txt:
	dc.b	"Loop",0
	even

propinfo6:
	dc.w	6
	dc.w	0,0
	dc.w	0
	dc.w	$ffff/12
	dc.w	0
	dc.w	0
	dc.w	12
	dc.w	0
	dc.w	0
	dc.w	0


propimage:
	dc.w	0,0
	dc.w	16,7
	dc.w	1
	dc.l	propimdata
	dc.b	1,0
	dc.l	0

propimdata:
	dc.w	%0111111111111110
	dc.w	%0111111111111010
	dc.w	%0101011111101010
	dc.w	%0101010110101010
	dc.w	%0101011111101010
	dc.w	%0101111111111010
	dc.w	%0111111111111110


bord:
	dc.w	0,0
	dc.b	1,3
	dc.b	0
	dc.b	5
	dc.l	cords
	dc.l	border2

border2:
	dc.w	0,0
	dc.b	2,3
	dc.b	0
	dc.b	3
	dc.l	cords2
	dc.l	0

cords:
	dc.w	-2,-2
	dc.w	80,-2
	dc.w	80,9
	dc.w	-2,9
	dc.w	-2,-2

cords2:
	dc.w	80,-2
	dc.w	-2,-2
	dc.w	-2,9


box:
	dc.w	0,0
	dc.b	1,3
	dc.b	0
	dc.b	5
	dc.l	boxcords
	dc.l	box2


box2:
	dc.w	0,0
	dc.b	2,3
	dc.b	0
	dc.b	3
	dc.l	box2cords
	dc.l	0

boxcords:
	dc.w	0,0
	dc.w	94,0
	dc.w	94,59
	dc.w	0,59
	dc.w	0,0

box2cords:
	dc.w	94,0
	dc.w	0,0
	dc.w	0,59

text:
	dc.b	1,0
	dc.b	1
	even
	dc.w	0,0
	dc.l	0
	dc.l	txt
	dc.l	text2

txt:
	dc.b	"By Henrik Stolpe",0
	even

text2:
	dc.b	1,0
	dc.b	1
	even
	dc.w	0,8
	dc.l	0
	dc.l	txt2
	dc.l	0
txt2:
	dc.b	"100% assembler!",0