Compucolor.org – Virtual Media

Listing of file='SOUND.MAC;01' on disk='vmedia/joystick_sound-sector.ccvf'

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;	SOUNDWARE ROUTINE (A LA CAP ELECTRONICS)
;
;	MODIFIED TO TREAT STEPS AS 16-BIT VALUES I.E. ALLOWS
;	A MUCH LARGER DYNAMIC RANGE.
;
;	VALUES ON ENTRY:
;	   THE PUBLIC VARIABLES BELOW MUST BE INITIALISED FOR
;	THE REQUIRED SOUND.
;
;	RETURNS:
;	   NOTHING
;
;	DESTROYS:
;	   ALL REGISTERS
;	   THE PUBLIC VARIABLES ARE ALSO DESTROYED AND MUST
;	BE RELOADED BEFORE EACH CALL. (DEFAULT IS 'PING')
;

	ENTRY	SOUND
	PUBLIC	PITCH,DURN,NSTEPS,STEP1,STEP2

SOUND:	MVI	C,8	;MASK FOR 5501
	DI		;INTERRUPTS MUST BE DISABLED
	LDA	STEP1
	MOV	B,A
	LDA	STEP2
	CPI	0	;MAKE STEP2 = STEP1 IF IT IS ZERO
	JNZ	LOOP
	MOV	A,B
	STA	STEP2
LOOP:	LHLD	DURN	;OUTER LOOP - DURATION AND NO. STEPS
	XCHG
SND10:	LHLD	PITCH
WAIT:	DCX	H	;INNER LOOP - GENERATE THE SOUND
	MOV	A,H
	ORA	L	;CHECK HL (PITCH) EMPTY
	JNZ	WAIT	;AND WAIT IF NOT
	MOV	A,C
	XRI	02	;TOGGLE THE BREAK BIT
	OUT	04	;SEND IT TO THE 5501 CHIP
	MOV	C,A
	DCX	D
	MOV	A,D
	ORA	E	;CHECK IF DURATION EXPIRED
	JNZ	SND10	;END OF INNER LOOP FOR ONE STEP
	LDA	NSTEPS
	CPI	0	;SEE IF ANY STEPS LEFT TO GO
	JZ	FINISH
	DCR	A
	STA	NSTEPS
	PUSH	B	;CALCULATE NEW PITCH
	PUSH	H
	MOV	C,B	;PITCH IS A 16-BIT VALUE, SO MAKE THE
	MVI	B,0	;   STEP INTO 16 BITS ALSO
	MOV	A,C
	ORA	A
	JP	SND20
	MVI	B,0FFH	;SIGN EXTEND THE STEP SIZE IF NEEDED
SND20:	LHLD	PITCH
	DAD	B
	SHLD	PITCH
	POP	H
	POP	B
	LDA	STEP2	;SWAP STEP1 AND STEP2
	MOV	H,A
	MOV	A,B
	STA	STEP2
	MOV	B,H
	JMP	LOOP	;REPEAT MAIN OUTER LOOP
FINISH:	STA	STEP2	;STORE ZEROS (TRICKY!)
	STA	STEP1
	STA	NSTEPS
	LXI	H,000FH	;SET UP FOR A 'PING' SOUND
	SHLD	DURN
	LXI	H,0032H
	SHLD	PITCH
	EI		;RE-ENABLE INTERRUPTS AT LAST,
	RET		;   REAL-TIME CLOCK WILL HAVE LOST TIME

;
;	SOUND PARAMETERS
;

PITCH:	DB	50,0	;DEFAULTS FOR 'PING' SOUND
DURN:	DB	15,0
NSTEPS:	DB	0
STEP1:	DB	0
STEP2:	DB	0

	END