Compucolor.org – Virtual Media

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

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;	SOUNDWARE ROUTINE (A LA CAP ELECTRONICS)
;
;	MODIFIED TO TREAT STEPS AS 16-BIT VALUES I.E. ALLOWS
;	A MUCH LARGER DYNAMIC RANGE.
;
;	CALLING SEQUENCE:
;	   CALL SOUND(PITCH,DURN,NSTEPS,STEP1,STEP2)
;	PITCH, DURN - INTEGER
;	NSTEPS, STEP1, STEP2 - BYTE
;
;	RETURNS:
;	   NOTHING
;
;	DESTROYS:
;	   ALL REGISTERS
;

	ENTRY	SOUND

SOUND:	MOV	A,M	;GET PARAMETERS
	STA	PITCH
	INX	H
	MOV	A,M
	STA	PITCH+1
	LDAX	D
	STA	DURN
	INX	D
	LDAX	D
	STA	DURN+1
	MVI	A,3	;NOW THE STEPS
	LXI	H,NSTEPS
GETPRM:	PUSH	PSW
	LDAX	B
	MOV	E,A
	INX	B
	LDAX	B
	MOV	D,A
	INX	B
	LDAX	D
	MOV	M,A
	INX	H
	POP	PSW
	DCR	A
	JNZ	GETPRM

	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:	EI		;REENABLE INTERRUPTS
	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