; Play Sample
; (C)1989 by Brian Postma
; J.v.Hartenstraat 51
; 7576VX Oldenzaal (NL)

start:	lea		buffer,a1
	subq.l		#2,d0		;Command Line Empty
	blt		quit		;Yes ??
copy:	move.b		(a0)+,(a1)+	;Copy Commandline
	dbra		d0,copy
	clr.b		(a1)		;End with 0->filename
	lea		dosname,a1	;Library Name
	move.l		4,a6		;Execbase
	jsr		-408(a6)	;Open Library
	move.l		d0,dosbase
	move.l		dosbase,a6
	move.l		#buffer,d1	;FileName
	move.l		#2,d2		;Read
	jsr		-84(a6)		;GetLock
	move.l		d0,handle	;LockHandle
	beq		quit		;File Found ??
	move.l		dosbase,a6
	move.l		#block,d2	;Fileinfo block
	move.l		handle,d1	;LockHandle
	jsr		-102(a6)	;Examine
	beq		quit		;Error ?
	lea		block,a0
	move.l		124(a0),length	;Fetch length from fileinfo
	move.l		dosbase,a6
	move.l		handle,d1
	jsr		-90(a6)		;UnLock
	move.l		4,a6		;Execbase
	move.l		length,d0	;Length of file
	move.l		#2,d1		;ChipMem
	jsr		-198(a6)	;AllocMem
	move.l		d0,memblock	;Pointer to memory
	beq		quit		;Error
	move.l		dosbase,a6
	move.l		#1005,d2	;Mode=OLDFILE
	move.l		#buffer,d1	;FileName
	jsr		-30(a6)		;Open
	move.l		d0,handle	;FileHandle
	beq		quit2		;Error ??
	move.l		handle,d1	;FileHandle
	move.l		length,d3	;FileLength
	move.l		memblock,d2	;Buffer
	jsr		-42(a6)		;Read
	move.l		handle,d1	;FileHandle
	jsr		-36(a6)		;Close
	move.l		memblock,$dff0a0;Pointer to Sample
	move.l		length,d0	;Length
	lsr.l		#1,d0		;Divide by 2->Length in Words
	move.w		d0,$dff0a4	;Length Sample in words
	move.w		#$1ac,$dff0a6	;Replay Rate
	move.w		#64,$dff0a8	;Volume
	move.w		#$8001,$dff096	;Audio DMA for Voice1 on
wait:	btst		#6,$bfe001	;MouseButton Pressed
	bne		wait		;No ??
	move.w		#$1,$dff096	;Audio DMA for Voice1 off
quit2:	move.l		memblock,a1	;Memory Pointer
	move.l		length,d0	;Length in bytes
	move.l		4,a6		;Execbase
	jsr		-210(a6)	;Freemem
quit:	clr.l		d0
	rts
; Some Vars
dosbase:dc.l		0
length:	dc.l		0		;FileLength
handle:	dc.l		0		;FileHandle
memblock:dc.l		0
buffer:	blk.b		128,0		;Command Line Buffer
block:	blk.b		256,0		;FileInfoBlock buffer
dosname:dc.b		"dos.library",0	;Name of doslibrary

