;Sound Effect Demo
;-----------------
;This is a simple demo that plays a sound effect, testing all the octaves.
;You have to supply your own IFF sound at the end of this file.
;
;Press LMB to play the sound.
;Press RMB to exit the demo.

	opt	o+,c+

	INCLUDE	"exec/exec_lib.i"
	INCLUDE	"games/games_lib.i"
	INCLUDE	"games/games.i"

CALL	MACRO
	jsr	_LVO\1(a6)
	ENDM

	SECTION	"Snd",CODE

;==========================================================================;
;                             INITIALISE DEMO
;==========================================================================;

Start:	MOVEM.L	A0-A6/D1-D7,-(SP)
	move.l	($4).w,a6
	lea	GMS_Name(pc),a1
	moveq	#$00,d0
	CALL	OpenLibrary
	move.l	d0,GMS_Base
	beq.s	.Error_GMS

	move.l	GMS_Base(pc),a6
	CALL	AllocAudio
	tst.w	d0
	bne.s	.Error_Audio

	lea	Sound(pc),a0
	CALL	InitSound
	tst.w	d0
	bne.s	.Error_Sound

	bsr.s	Main

.ReturnToDOS
	move.l	GMS_Base(pc),a6
	lea	Sound(pc),a0
	CALL	FreeSound
.Error_Sound
	CALL	FreeAudio
.Error_Audio
	move.l	GMS_Base(pc),a1
	move.l	($4).w,a6
	CALL	CloseLibrary
.Error_GMS
	MOVEM.L	(SP)+,A0-A6/D1-D7
	moveq	#$00,d0
	rts

;==========================================================================;
;                                MAIN LOOP
;==========================================================================;

Main:	move.l	GMS_Base(pc),a6
	CALL	Wait_OSVBL

	moveq	#JPORT1,d0
	CALL	Read_Mouse
	btst	#MB_RMB,d0
	bne.s	.done
	btst	#MB_LMB,d0
	beq.s	Main

	lea	Sound(pc),a0
	CALL	PlaySoundPri
	addq.w	#2,SAM_Octave(a0)
	cmp.w	#OCT_A4,SAM_Octave(a0)
	blt.s	.release
	move.w	#OCT_G0S,SAM_Octave(a0)

.release
	moveq	#JPORT1,d0
	CALL	Read_Mouse
	btst	#MB_LMB,d0
	bne.s	.release
	bra.s	Main
.done	rts

;===========================================================================;
;                                  DATA
;===========================================================================;

GMS_Name:
	dc.b	"games.library",0
	even
GMS_Base:
	dc.l	0

Sound:	dc.l	SMV1,0	;Structure version.
	dc.w	CHANNEL_ALL	;Channel to play through.
	dc.w	1	;Priority.
	dc.l	0	;Sample header
	dc.l	0	;Sample address.
	dc.l	0	;Sample length.
	dc.w	OCT_C0S	;Sample period.
	dc.w	100	;Sample volume.
	dc.l	0	;Sound attributes.
	dc.l	.File	;Sound file.
.File	dc.b	"GAMESLIB:data/SND.Lightning",0
	even

