
; Audio Example 6: 		Supplied spot sound effect system

; Press fire button on joystick to exit program.
; Wiggle joystick for noise.

		include		hardware.i		hardware equates
		include		hw_macros.i
		include		hw_start.i		startup code
		include		hw_input.i		for joystick routine
		include		hw_sound.i		for sample player

; Set processor level 3 autovector

Main		move.l		#NewLevel3,$6c

; Enable VERTB interrupts

		move.w		#SETIT!INTEN!VERTB,INTENA(a5)

; Wait for user to joystick fire button 

StickButton	btst		#7,CIAAPRA		button pressed
		bne.s		StickButton		no, keep looping

; And exit

		rts

;*****	Level 3 interrupt handler

NewLevel3	lea		$dff000,a5		hardware base

		bsr		SEPlayer		do spot effects

; The following counter ensures joystick is only chequed for movement every
;5 VB. This allows a sample time to be played before cutting it off with a
;new request. Try altering the counter reset value and hear the e e e effect!

		subq.w		#1,VBIFlag
		bne.s		NoCheck
		move.w		#5,VBIFlag		counter reset value
		
		bsr		CheckStick		check for movement

; Clear interrupt bit and exit

NoCheck		move.w		INTREQR(a5),d0		get bit
		and.w		#$7fff,d0		clear bit 15
		move.w		d0,INTREQ(a5)		clear request
		
		rte					back to User Mode

VBIFlag		dc.w		5

;*****	Check for stick movement

; A different sample is played depending on which direction the joystick is
;moved.

CheckStick	jsr		ReadJoy1
		move.l		d0,d7			save bits
		
		btst		#0,d7			right?
		beq.s		TryLeft			no, skip!
		
		lea		Sample1,a0		sample 1
		moveq.l		#0,d0			channel 0
		jsr		SEFX			do it!

TryLeft		btst		#1,d7			left?
		beq.s		TryDown			no, skip!
		
		lea		Sample2,a0		sample 2
		moveq.l		#1,d0			channel 1
		jsr		SEFX			do it!

TryDown		btst		#2,d7			down?
		beq.s		TryUp			no, skip!
		
		lea		Sample3,a0		sample 3
		moveq.l		#2,d0			channel 2
		jsr		SEFX			Do it!

TryUp		btst		#3,d7			up?
		beq.s		StickDone		no, skip!
		
		lea		Sample4,a0		sample 4
		moveq.l		#3,d0			channel 3
		jsr		SEFX			Do it!

StickDone	rts					and exit

;*****	Data -- Nots that sample structures need not be in CHIP memory
;			  ~~~~~~~~~~~~~~~~~

; Note that all Sample use the same raw binary file. The sound is altered by
;specifying different frequencies


Sample1		dc.w		0			default frequency
		dc.w		Smp1Len			sample word length
		dc.l		Smp1			address of raw data

Sample2		dc.w		$12c<<1			double default freq
		dc.w		Smp1Len			sample word length
		dc.l		Smp1			address of raw data

Sample3		dc.w		$12c>>1			half default freq
		dc.w		Smp1Len			sample word length
		dc.l		Smp1			address of raw data

Sample4		dc.w		$12c<<2			4 * default freq
		dc.w		Smp1Len			sample word length
		dc.l		Smp1			address of raw data



;*****	Sample data -- must be in CHIP memory

section		data custom,chip		****  Use this for A68K  ****

;		Section		custom,data_C	**** Use this for Devpac ****


Smp1		dc.w		0		
		incbin		'Sample.raw'		sample data
Smp1Len		equ		(*-Smp1)>>1

		end


