Compucolor.org – Virtual Media

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

10 REM  *** SINGLE FREQUENCY GENERATOR ***
15 REM
20 PLOT 6,6,14,12:PRINT "FREQUENCY GENERATOR":PLOT 15,6,2
25 REM
30 REM   THE CLOCK FREQUENCY FOR THE AY-3-8910 MUST BE
40 REM   CORRECT. USUALLY 2.000 MHZ OR 1.78977 MHZ.
50 DF= 1.7897725E06:FC= DF
55 REM   THIS IS FOR TESTING ONLY.
60 REM  INPUT "CLOCK FREQUENCY FOR AY-3-8910 : ";FC
70 REM  IF FC<=0 THEN FC=DF
75 REM   THE I/O PORT ADDRESSES MUST BE SET UP CORRECTLY
80 SA= 176:SC= 177:REM  FOR INTECOLOR 3650 (48 AND 49 ON CCII)
85 REM   #### NOTE #### DO NOT USE 48 AND 49 ON A 3650 !
90 OUT SA,7:OUT SC,62:REM  CHANNEL 'A' ONLY
95 OUT SA,8:OUT SC,0:REM  ZERO AMPLITUDE
100 PRINT :INPUT "TONE FREQUENCY IN HERTZ (0=EXIT) : ";FQ
105 IF FQ< = 0THEN END
110 TP= INT (FC/ (16* FQ)+ 0.5):REM  CALCULATE THE PERIOD
115 PH= INT (TP/ 256):REM  GET THE HIGH BYTE OF THE PERIOD
120 PL= TP- 256* PH:REM  AND THE LOW BYTE
125 PH= PHAND 15:REM  MASK OFF HIGH BYTE TO 4 BITS
130 AF= FC/ (16* (PH* 256+ PL)):REM  ACTUAL FREQUENCY
135 ER= 100* (AF- FQ)/ FQ:REM  PERCENTAGE ERROR
140 OUT SA,0:OUT SC,PL:REM  LOAD THE PERIOD INTO SOUND CHIP
150 OUT SA,1:OUT SC,PH
160 PRINT "TONE PERIOD HIGH BYTE = ";PH,"LOW BYTE = ";PL
165 PRINT "ACTUAL TONE FREQUENCY = ";AF," % ERROR = ";ER
170 OUT SA,8:OUT SC,15
180 INPUT "HIT <RETURN> TO STOP THE SOUND ";A$
190 OUT SC,0
200 GOTO 100