Code: Select all
MORE MUSIC FOR THE VIC
Now that you know about the USER PORT, there is a little surprise
left. Up to now, the VIC has had 4 musical voices...three music
registers and a white noise register. By connecting a small amplifier
and speaker to the USER PORT, and doing a little programming,
you can get another musical voice.
THEORY
Most music is made up of square waves of different amplitudes
and frequencies. One of the functions of the 6522 chip is to
generate square waves through the CB2 line. If we connect the
CB2 line to a speaker, we will be able to hear the square waves
generated by the VIC.
NOTE: Connecting a speaker directly to CB2 may damage your
VIC. You must connect the speaker through an amplifier to protect
the VIC.
PARTS NEEDED
1. Small battery powered speaker/amplifier
2. User Port Connector (12 position, 24 contact edge connector
with .156" spacing
3. Wire
CONNECTING TO YOUR VIC
1. Wire the GROUND of the amplifier to the GROUND of the USER
PORT (pin N).
2. Wire the SIGNAL of the amplifier to the CB2 output of the USER
PORT (pin M).
You are now ready to add your other voice through a BASIC
program.
BASIC PROGRAM STEPS:
1. Set the 6522 shift register to free running mode by:
POKE 37147,16
2. Set the shift rate by:
POKE 37144,C where C is an integer from 0 to 255
C in the note to be played.
3. Load the shift register by:
POKE 37146,D where D = 15,51, or 85 for a square wave.
This step sets the octave for the note.
This step must be done last, since as soon as it is set, the VIC
starts generating the square waves.
The frequency of the square wave can be found by the following
formula:
500000 Hz
FREQUENCY = --------- Where D1 = 8 when D = 15
(C+2)(D1) D1 = 4 when D = 51
D1 = 2 when D = 85
When you are in this mode, the VIC will not read or write to
cassette. To restore normal operations, you must:
POKE 37147,0
The following program demonstrates music using this method.
By hitting a letter the note will be played.
10 PRINT "MUSICAL USING CB2."
15 PRINT "HIT + TO GO UP AN OCTAVE"
16 PRINT "HIT - TO GO DOWN AN OCTAVE"
17 PRINT:PRINT "USE E TO EXIT."
20 POKE37147,16:DIMA(30):FORK=1TO30:READA(K):
NEXT
40 GETA$:IFA$=""THEN40
42 IFA$="E"THEN POKE37147,0:END
45 IFA$="+"THEN SF=SF-(SF<2):GOTO40
50 IFA$="-"THEN SF=SF+(SF<0):GOTO40
60 A=8-ASC(A$)+64:IF A>7 OR A<1 THEN 40
70 POKE37144,A(A-(SF=1)*10-(SF=2)*20)
80 POKE37146,-(SF=0)*15-(SF=1)*51-(SF=2)*85
90 GOTO40
100 DATA 59,61,65,69,73,77,82,87,90,93
110 DATA 99,104,111,117,120,124,132,140,149,157
120 DATA 167,177,182,188,199,211,224,237,244,251