;Sound Effect Demo
;-----------------
;An example of modulating a sound sample.
;
;LMB plays the sound.
;RMB exits the demo.

	opt	o+

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

CALL	MACRO
	jsr	_LVO\1(a6)
	ENDM

	SECTION	"Sound",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
	sub.l	a0,a0
	CALL	SetUserPrefs

	CALL	AllocAudio
	tst.w	d0
	bne.s	.Error_Audio

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

	bsr.s	Main

.ReturnToDOS
	move.l	GMS_Base(pc),a6
	lea	Sound_Lightning(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
.loop	CALL	Wait_OSVBL

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

	lea	Sound_Lightning(pc),a0
	CALL	PlaySoundPri
	lea	Sound_Modulus(pc),a0
	CALL	PlaySoundPri

.held	moveq	#JPORT1,d0
	CALL	Read_Mouse
	btst	#MB_LMB,d0
	bne.s	.held
	bra.s	.loop
.done	rts

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

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

Sound_Modulus:
	dc.l	SMV1,0	;Structure version.
	dc.w	CHANNEL1	;Channel to play through.
	dc.w	1	;Priority
	dc.l	0	;Header
	dc.l	Modulus	;Address
	dc.l	8	;Length
	dc.w	OCT_A7S	;Period
	dc.w	100	;Volume
	dc.l	SBIT8|SREPEAT|SMODPER	;Attributes
	dc.l	0	;File

Sound_Lightning:
	dc.l	SMV1,0	;Structure version.
	dc.w	CHANNEL2	;Channel to play through.
	dc.w	1	;Priority
	dc.l	0	;Header
	dc.l	0	;Address
	dc.l	0	;Length
	dc.w	OCT_C2S	;Period
	dc.w	100	;Volume
	dc.l	SBIT8	;Attributes
	dc.l	.Light	;File
.Light	dc.b	"GAMESLIB:data/SND.Lightning",0
	even

;===========================================================================;
;                            SOUND DATA (CHIP)
;===========================================================================;

	SECTION	"SoundArea",DATA_C

Modulus:
	dc.w	600,550,500,450,400,450,500,550

