Commodore VIC-20 User Manual page 87

Hide thumbs Also See for VIC-20:
Table of Contents

Advertisement

Line 150 simply POKEs the note we READ in line 120 into voice
1, while line 160 creates a delay for the duration we READ in
line 130. Similarly, lines 170 and 180 turns off voice 1 for a short
period. Line 190 sends the VIC back to line 120 to READ the
next note.
Now we have to write our ending section. Remember that our
"end of melody" marker, -1, sends the program to line 200.
Line 210 turns the voice off, and line 220 tells the VIC to stop
performing the instructions in this program.
Even though we've written the ending section, we're not quite
done. We still have to write our "mystery statements" to tell
the program what notes to READ. These mystery statements
are called DATA statements because they contain information,
or data. DATA statements can be located anywhere in a
program. Whenever the VIC encounters a READ instruction, it
looks around for a DATA statement to READ.
This module contains the DATA for a C major scale. Line 300
contains the first three notes. The first number is the POKE
value for the first note, 225 — low C. The second number sets
its duration, 1000 — about 1 second. Line 310 contains the next
three notes, and line 320 the last two. The values themselves
are taken from the table of musical notes above.
If the lines look correct, you're ready to RUN. You should hear a
fairly accurate C major scale! If you have a "clinker" or two, try
adjusting the values in your DATA statements, starting at line
300.
Once again: You can put DATA statements anywhere in your
program. They will be READ one by one, starting with the
lowest line number, and working through each DATA statement
from the beginning to the end.

Advertisement

Table of Contents
loading

Table of Contents