Compucolor.org – Virtual Media

Listing of file='SNDCHP.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.
;
;	   COMPATIBLE WITH THE AY-3-8910 SOUND CHIP ALSO.
;
;
;	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')
;

SNDADR	EQU	30H	;ADDRESS REGISTER ON AY-3-8910,
			;   AND READ FROM CHIP
SNDDAT	EQU	31H	;LOAD (WRITE) DATA INTO AY-3-8910

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

SOUND:	MVI	C,8	;MASK FOR 5501
	DI		;INTERRUPTS MUST BE DISABLED
;
;***	CODE FOR THE SOUND CHIP (INDICATED BY ***)
;
	MVI	A,8
	OUT	SNDADR
	XRA	A
	OUT	SNDDAT
	MVI	A,7
	OUT	SNDADR
	IN	SNDADR
	ORI	62
	OUT	SNDDAT
;***
	LDA	STEP1
	MOV	B,A
	LDA	STEP2
	ORA	A	;MAKE STEP2 = STEP1 IF IT IS ZERO
	JNZ	LOOP
	MOV	A,B
	STA	STEP2
;***
	CALL	SND
;***
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
	ORA	A	;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
;***
	CALL	SND
;***
	LDA	STEP2	;SWAP STEP1 AND STEP2
	MOV	H,A
	MOV	A,B
	STA	STEP2
	MOV	B,H
	JMP	LOOP	;REPEAT MAIN OUTER LOOP
FINISH:
;
;***	SOUND CHIP MOD
;
	MVI	A,8
	OUT	SNDADR
	XRA	A
	OUT	SNDDAT
;***
	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

;
;	SOUND ROUTINE FOR THE AY-3-8910
;
SND:	LHLD	PITCH
	MOV	D,H
	MOV	E,L
	DAD	D
	DAD	D
	MVI	A,1
	OUT	SNDADR
	MOV	A,H
	OUT	SNDDAT
	XRA	A
	OUT	SNDADR
	MOV	A,L
	OUT	SNDDAT
	MVI	A,8
	OUT	SNDADR
	MVI	A,15
	OUT	SNDDAT
	RET

	END