Atari Sound and Graphics - Herb Moore, Judy Lower, Bob Albrecht - Zhelper-Search 2
Atari Sound and Graphics - Herb Moore, Judy Lower, Bob Albrecht - Zhelper-Search 2
AND GRAPHICS
HERB MOORE
JUDY LOWER
BOB ALBRECHT
Dymax Corporation
Menlo Park, California
Cover graphic: " Hexrotate" by Michael Dubno and Comp uter Center New
York, photographed on the ATARI 800 Computer at Digibyte, New York
City.
82 83 10 9 8 7 6 5 4 3
Contents
To the Reader iv
In trod uction vi
Appendix A 219
Appendix B 224
Appendix C 225
Appendix D 230
Appendix E 233
Index 234
iii
To the Reader
iv
How to Use This Book
._ ._- - - - - - _ . _ - - -
v
Introduction
The language you will be learning in this book is AT ARI® BASIC, a very
simple form of an English-based language for computers. BASIC is under-
stood by many computers. ATARI BASIC also has some special vocabulary
for creating sound and color graphics.
As you use this book, keep in mind a few things about your interaction
with your AT ARI 400 or 800 Computer.
First, remember you are learning ways to tell your computer what you
want it to do. You'll learn to speak a language the computer understands.
Computer programmers of all skill levels think in terms of computer lan-
guages.
Second, although this book focuses mainly on sound and graphics, you
will also learn many skills that will be valuable to you as you find other
ways to use your AT ARI 400 or 800 Computer.
You will learn many introductory programming techniques. Many of the
sounds you will learn to create can be found in today's arcade games, and
the graphics can be equally innovative-creations that are fun and exciting
as you devise your own ways to use them. If you wish to learn more
conventional music, we suggest you also consider the Music Composer®
and the Video Easel ®, programs for the AT ARI Computer.
When you are learning to speak another language-such as Spanish or
French-the more you practice and learn, the more you understand. The
same is true with AT ARI BASIC. As you begin to understand the machine
more fully, you will find it easier to get the machine to do what you want it
to do.
Remember also, if the machine doesn't understand you, it's not because
of any lack of intelligence on your part. The computer has a very specific
language, and if you start to speak another dialect or become too subtle, it
can easily become confused .
Be patient with your computer. And most of all, remember it's not the
computer telling you what to do, but you telling the computer what to do!
vi
CHAPTER ONE
Getting Started-
The Sound Statement
Hi.
I'm Please Note.
You ' ll hear from me
throughout the book.
When you turn on the ATARI * Computer,** you 'll know that it is ready
when the screen looks like this:
--
.---
RE ADY _ - - -
1
2 ATARI SOUND AND GRAPHICS
••••••••••••••• §
IIIImllaaDDmama • • • ,t
ElIIDa.amaaaBillIl. ~
_aDa.a •••••••
Now that yo u 've looked over th e key board , yo u 're ready to give th e
machine a command. Type
SOUND 91,121,191,8
o is a zero
o is the le tter "0"
What if, whil e typin g your SOUND statement, you press a wrong number
or spell "SUUND " or "SOUD," and rea li ze yo u 've mad e a mistake? It's easy
to fix .
Just press th e DELETE BACK S key n ear th e upper right side of the
GETTING STARTED-THE SOUND STATEMENT 3
keyboard. This moves the cursor back (to the left) as many spaces as you
want and erases the error . Then type the correct letters or numbers .
Okay , do you have a SOUND command that looks like this?
SOUND 0,121,10,8
If you do, press the RETURN key and the machine will produce a single
tone that is approximate ly the note middle C.
Can you hear it? Be sure the volume on your TV is turned up to a
comfortable listening level.
The tone will stay on. To stop the tone type:
END
READY
But what happens if you make a typing error in your SOUND statement
and don't notice it? Suppose you put a period instead of a comma between
10 and 8, so it looks like this:
If you do this and press the RETURN key, instead of a tone you'll get an
ERROR message that looks something like this:
PARAMETERS
Voice Parameter
The first parameter in the SOUND statement you've been using is the voice
parameter. Your AT ARI Computer has four voices, just like a barbershop
quartet. AT ARI BASIC counts voices a little differently from people
though. It numbers its four voices 0,1,2,3.
SOUND 0 , 121 , 10 , 10
~----
Voice 1 can play the same note like this:
SOUND 1,121,10 , 10
~---
Now you type a SOUND statement for voices 2 and 3 to play the same note.
You'll get a chance to combine the voices with different notes soon, but
for the moment let's stick with the first voice. That's voice 0 (zero) in the
AT ARI BASIC's SOUND statement.
GETT ING STARTED-THE SOUND STATEMENT 5
Note Parameter
The second parameter in your SOUND statement is the note parameter. To
get a feel for the note parameter, try this exercise:
First type:
SOUND 0,243, 10 ,8
Using ATARI BASIC , you can play 256 different notes numbered from Ii)
to 255. When it comes to notes , not only does the computer start counting at
zero, but it also counts backwards from the way we humans count. That is,
it gives the highest notes the lowest numbers and the lowest notes the
highest numbers. So 243 for the note parameter is a low note , while 26 is a
high one.
Let's write a SOUND statement so the note parameter is a variable called
N. That 's simply a way of saying you can make N equal to different
numbers, in this case numbers between Ii) and 255 inclusive.
Now it looks like this:
SOUND 0, N, 10, 10
(The letter "N" here represents a number. You may substitute a number
from Ii) to 255 for N in this SOUND statement.)
Try different numbers for the variable N to get a feeling for some of the
notes that your AT ARI Computer can generate. Remember to use the
RETURN key after each new command!
6 ATARI SOUND AND GRAPHICS
Tone Parameter
The third parameter in the SOUND statement is th e ton e parameter. "Tone "
here is different from the tone control on yo ur radio. To get the idea of some
possible "tones" you can produce , try thi s.
First go back to the original SOUND statem ent:
SOUND 0, 121 , 10 , 10
SOUND 0, 121,4 , 10
You can make a variable out of the tone parameter in th e same way you
did with the note parameter. The statement would th en take the following
form:
SOUND 0,121, T, 10
r---
There are eight possible "tones" ava ilable in AT ARI BASIC, indicated by
even numbers from 0 to 14. There 's no particular reason for them being
even numbers other th an that 's the way the machin e was designed .
If you use an odd numb er like:
Note: 0 to 255
Ton e: 0 ,2,4 ,6 ,8, 10 ,12 ,14
Try different numbers for the variable "T" in the SOUND statement to see
which ones you like. The va lu es 10 and 14 should give you a very pure
sounding tone. The other values give a vari ety of buzzing and scratching
sounds. You 'll ex plore these later when yo u get into creating sound effects.
GETTING STARTED-THE SOUND STATEMENT 7
Loudness Parameter
The final parameter in the SOUND statement is the loudness parameter. It
has sixteen possible values , numbered from 0 to 15. The lowest value ,
which is 0, makes no sound. Later , you will see how this can be used as a
way to turn off a note .
The highest value of the loudness parameter is 15, the loudest tone. (Of
course, all this depends on where yo u have the volume on your TV.)
First, try a valu e of 2 for "L" in this statement:
SOUND0,121,10,2
SOUND 0, 121,10 , 15
Now try a few more values of your own cho ice to get a feeling for the
loudness parameter.
You have now explored all four parameters of the SOUND statement.
Here 's a brief summary of what you 've learned so far. This section may be
helpful as a quick reference as you continue to explore on your own.
Defining each parameter as a variab le, yo u can write the SOUND state-
ment like this:
SOUND V, N, T, L *
*You can use any nam e you wish for th ese var ia bl es. For examp le . in th e ATARI 4(/}(/}/8(/}(/}
BAS IC Refe rence'Manual , Pilc h is used for th e parameter we've ca lled Note, Distortion is used
for what we've called Tone, and Vo lum e is used for th e fourth parameter where we've used the
name Loudness. Use whatever variable n ames yo u li ke.
8 ATARI SOuND AND GRAPHICS
COMBINING VOICES
Suppose yo u want to h ear two vo ices togeth er. To do this, type one SOUND
statement for voice 0, and then , without pressing SYSTEM RESET (but do
press RETURN), typ e anoth er statement for voice 1. For exampl e, you
might have:
Be sure the second statement is for voice 1 and not voice again. This °
tells the machin e to play middle C with th e first voi ce and the note C an
octave higher with th e second voice. You ca n play up to four different
voices at once in this way. You might have something like this :
60 -...........
8 1 --.....
96
iJ2
~
/
____ ~
_:.-/'
C one octave higher
12 1 - MiddleC
Remember, you can play any of 256 n otes for th e note variable. The
following chart gives th e number values for different notes in our western
musical scale. You might want to make up some chords of your own before
going on to the n ext section.
C# I ID# F# G# A# C# D# F# G# A# C# 0# F# G# ~
A"
A II 8 C D E F C
Ifcr&L4/1/1 j![,[JJ, G JAT\,
Gl
/l /I / /l / / / I IMiddl / II f II ! r \ \ \ \ \ \ \\\\ \\\ m
C C# D D# E F F# G G# A A# 8 C C# D D# E F F# G G# A A'if 8 C C# D D# E F# G G# A ~
I I I I I I
I I I I
Z
Gl
(f)
I I I I I I I
~
: :: i ; I ~ j j"" I : I I iii ; i I I' I JJ
,-+-: ' , , , ' : , , , , , " " 50 " 45 42 40 37 35 33 31 29 -!
,,,,,,,r m
I ~
I '): f f f f f t~ i 1 ! ! ! iii i i ! i
I I I I I I I I I I I I I I I I I I I I I I I I I
f* ? r II!
243 230 217204193 182173 162 153144 136 128 121 11 4 108 102 96 91 85 83 76 72 68 64 60
tC
Middle
Ii
s
m
s::
m
z
-!
co
10 ATARI SOUND AND GRAPHICS
EDITING
SO UND 0,121,10 , 10
SOUND 0,243, 10 , 10
Got it?
Okay, now on th e other side of the keyboard are four keys with littl e
arrows on them. They look like this:
I
Once you've done that , hold down the co ntrol key, I CTRL with one
hand and while still holding it down , press the key with the arrow pointing
GETTING STARTED-THE SOUND STATEMENT 11
up [lJ. When you do this, the cursor will move towards the top of the
screen.
Try to move it up until it covers the S in the SOUND statement. If the
cursor goes past the S, don't worry about it. There's another key with the
arrow pointing down [[] .
Sure enough! you just have to hold the CTRL key and press the key with
the arrow pointing down to make the cursor go the other way.
You've probably guessed by now that the other two keys G and EJ
make the cursor move back and forth across the screen. Be sure to hold the
CTRL key down when you do it , though! Now, try to move the cursor
around with these keys until it is over the 2 in the note parameter of the
SOUND statement:
SOUND 0 , ~1, 10 , 10
Once you've got that, type a 9 and press RETURN. Now you get:
SOUND 0,191,10, 10
If you do this while the SOUND statement is playing, the note will
change. You can practice this editing feature and also explore the sounds
made by different values for the parameters of the SOUND statement, as
demonstrated below.
This kind of editing takes a while to get the hang of, so don't be too
discouraged if everything didn 't work for you the first time you tried it.
If you do have problems , it might help to just practice moving the cursor
around first and then use it to change the parameters in a SOUND state-
ment.
SOUND 0 , 121,10 , 10
SOUND 1,96, 10, 10
SOUND 2,81,10,10
SOUND 3,60, 10 , 10
Now while the chord is playing, move the cursor up and change any
parameter in any SOUND statement y{)U want. As soon as you change a
number and press RETURN , a new sound will occur.
12 ATARI SOUND AND GRAPHICS
For examp le, put th e cursor over th e 9 in the note parameter for voice 1
and change it to 2. Or change th e ton e parame ter to 6 in voi ce 3 , and so on .
Have fun exploring!
In this chapter you 've learn ed to make so me different so unds with your
Atari computer. In th e next chapter yo u w ill lea rn some graphics com-
m ands that wi ll a ll ow yo u to draw fi gures and put co lors on th e screen.
Self-Test
Complete the follo wing Self-Tes t to see what yo u alread y ca n do with your
computer.
1. Using th e note chart in Figure 1 on page g , see if yo u can pl ay the
note C# above midd le C in th e follo wing SOUND s tatement:
I
SOUND 0, N, 10 , 10
Answers
SOUND 0,12 1 , 10 , 2 _ . - - -
4. Something like:
SOUND 0 , 12 1 , 10,15
5. You can use an y of the va lu es for the notes G-B- D in the note chart.
Yo u need to use three different vo ices .
Example:
G SOUND 0,81 , 10, 10
D SOUND 1 , 108 , 10 , 10
Picture Yourself
Doing Graphics
GRAPHICS MODE 3
GRA PHIC S 3
or
GR. 3 - . - - - - -
If you use the short version, be sure to include the period. When you type
this graphics command and press the RETURN key, the screen changes to
look like this:
Blank
screen
I ~EADY
13
14 ATARI SOUND AND GRAPHICS
The area at the bottom of the screen with the word READY and th e cursor
is called the text window. It displays written information (text).
Use the rest of the screen for creating graphics. To do this, you tell the
machine to use a color-even if your TV is bla ck and white .
Type:
COLOR 1
Plotting a Point
Let's plot a point. The PLOT cOll1lfa nd looks like this:
PLOT 10 .5
Try entering PLOT 10,5 an d see what happe ns . You should end up with a
screen that looks like this:
Hi . I'm
PLOT 10,5.
I PLOT 10,5
RE A DY
•
This dot should be orange. Adjust the co lor on yo ur TV until the dot is
orange.
Do yo u see a little sq uare on th e screen?
PICTURE YOURSELF DOING GRAPHI CS 15
By now you may be saying to yourself, "That's great, but what does .. .
PLOT 10,5
reall y mean?"
Well ...
When you ENTER a graphics mod e, th e computer div ides the screen into
a number of columns and rows , something like this:
CO L UMNS
o 1 2 3 ••• 39
o
1
2
3
(/)
so
a:
20
[P[WU TI w~ ~
/
Column " Row
The first number in the PLOT statement te lls the computer in which
column to plot the point. The second n umber te lls it in w h ich row to p lot
the point. You 've told the ma chin e to plot a point in colu mn 10 , row 5.
Graphics mode 3 has 40 co lumns (numbered 0 through 39) and 20 rows
(nu mbered 0 through 19).
In graphics mode 3 (GRAPHICS 3 or GR. 3):
Columns (0-39)
Rows (0- 19)
16 ATARI SOUND AND GRAPHICS
PLOT 0,0
PLOT 39,0
PLOT 39, 19
PLOT 0,19
39,0
• •
Now type:
COLOR 2
and then:
PLOT 1,0
You should get a li ght green dot in the upp er left corner now :
- •
READY
• 1
PICTURE YOURSELF DOING GRAPHICS 17
COLOR 3
COLOR 0
and press RETURN .
Then typ e:
PLOT 39 , 0
ULOT 39 , 0
READY
• J
Colors
The following chart shows the d ifferent co lors for plot points en th e screen
in graphics mode 3 u sing values of 0 through 3 for the COLOR command:
In Chapter 7 you 'Ul earn to put several more co lors on the screen as you
learn to use the SETCOLOR command.
Try plotting a few m ore points on yo ur own to get the id ea. Then press the
SYSTEM RESET key to clear the screen.
Drawing a Line
Another GRAPHICS command! Use ORA WTO to draw lines. Before you
us e this command, you must plot a po int.
Do the followin g very carefull y.
First typ e:
Now type:
Now you get to draw a line. Let's say you want to draw the line over to
column 30 , row 5. Yo u u se a
to draw a line from a point yo u've just plotted to another point on the
screen.
To do thi s, ju st type:
Last time.
From now on,
DRAWTO 30 .5 we won't rem ind
you to press
R ETU RN to enter
a command .
PICTURE YOURSELF DOING GRAPHICS 19
Be sure to type DRA WTO as one word or the computer won't understand.
(Try DRAW TO and dravv an ERROR message).
When you type this command and press RETURN, you' ll get a screen
display that looks like this:
Orange
I DRAWTO
READY
35. 5
•
The computer draws a li ne from column 10 , row 5 to column 30 , row 5.
Staircase
Horizontal and vertical lines wi ll be straight , but lines drawn at an angle
will have a staircase effect in graph ics mode 3. To see this staircase effect,
push the SYSTEM RESET key to start over again.
Now ENTER:
GR.3
and then:
CO LOR 2
then:
PLOT !C,!C
and finally:
DRAWTO 39 , 19
20 ATARI SOUND AND GRAPHICS
... ...........................
IDRAWTO
READY
39,19
The text window will show the las t comm and you 've typed , the word
READY, and the cursor.
Drawing a Figure
Let's draw a n ew figur e on the screen. First clear the screen by pressing
SYSTEM RESET.
Now type:
GRAPHICS 3
then:
COLOR 1
and:
PLOT 10,8
DRAWTO 20,8
DRAWTO 10 , 18
DRAWTO 15 ,3
DRAW TO 20,18
DRAWTO 10 ,8
By the time yo u fini sh , yo u should have a figure that looks like thi s:
PICTURE YOURSELF DOING GRAPH ICS 21
COLOR 2
DRAWTO 20,8
I DRAWT
RE A D Y
O 20. 8
•
22 ATARI SOUND AND GRAPHICS
Can you color th e n ext lin e dark blue ? Hint: COLOR 3 is clark blue.
Try experimenting a bit on your own to get a feeling for PLOT statements
and DRA WTO statements.
GRAPHICS MODE 4
Okay, let's have a look at another graphics mode . Graphics mod e 4 fills the
screen with 80 columns and 40 rows numbered as follows:
o 1 2 3 ••• 79
o
1
2
3
39
To fill the same amount of screen s pace with twi ce as many columns and
rows , the computer must plot sma ller points.
To see this, ENTER:
GR.4
then:
COLOR 1
and then:
PLOT 10, 8
Now, you should see a mu ch small er dot on the screen than you saw
using graphics mod e 3.
PICTURE YOURSELF DOING GRAPHICS 23
ENTER the same DRA WTO commands you used for the figure in
graphics mode 3. You should end up with the same fi gure, but it will be
smaller and will be lo ca ted in the upper left on the screen.
I DRAWTO 10,8
READY
•
GRAPHICS MODE 6
Now let's try graphics mod e 6, vv hi ch has even more co lumns and rows,
and plots even sma ller dots.
First press the SYSTEM RESET, and then ENTER:
GR.6
and then:
COLOR 1
Now ENTER:
PLOT 50,30
DRAWTO 80, 15
24 ATARI SOUND AND GRAPHICS
then:
and finally:
DRAWTO 50,30
Be sure to press RETURN after each new statement you type. What did
you get? Did you get a triangle? If you did, that's grea t! If you didn't, try it
again and see what happens.
Before you clear the screen , try adding:
DRAWTO 80,45
DRAWTO 110 ,30
DRAWTO 80,55
DRAWTO 80,5
DRAWTO 50,30
I DRAWTO 50, 30
READY
•
The following chart shows the numb er of co lumns and rows in several
different graphics mod es available in AT ARI BASIC.
3 40 20 4 I nes
4,5 80 40 4 Illes
6,7 158 80 4 Illes
PICTURE YOURS ELF DOING GRAPHICS 25
Although some graphics mod es have the same numb er of co lumns and
rows , th e colors th ey are able to make are different. These differenc es
dep end upon some other commands which yo u hav e not yet learned.
In Chapter 7 you w ill learn about the SETCOLOR command which
enab les you to create a variety of co lors for the figure, the background
screen , and the text w indow.
Self-Test
GRAP HIC S 7
COLOR 2
PLOT 35 , W
DRAW TO 55 , 10'
DRAWTO 55,30'
DRAWTO 35, W
Answers
GR.4
COLOR 1
PLOT 12, 10'
DRAWTO 12 ,3 0'
Challenges
A Graphics Program
The instructions you've been giving the computer are called direct com-
mands. This simply means the machine exec utes the command right away
or "directly." The computer do esn't remember direct commands, so if you
want it to do the same thing again, you have to type the instruction again.
Frequently, you will want to give the machine an instruction it can
remember and use later. A set of this kind of instructions is called a
program.
To make sure your computer doesn 't already have some information in
its memory , there are a few things to do whenever starting a new program.
You 're ready to start your program . To write a program, use the same
commands you've learned so far. But now, you give each command a line
number as you type it.
For example, you would write a graphics program to plot a point like this :
First type:
l~ GR. 3
\'------
and press RETURN . What happ ens?
"Nothing happen ed," you say.
Actually, something has happ ened . The machine has remembered the
instruction.
Now type:
2~ COLOR 1
27
28 ATARI SOUND AND GRAPH ICS
Next type:
30 PLOT 10 . 5
And finally:
40 END
LISTING A PROGRAM
If you've type d each command correctly and pressed RETURN after eac h
command, there should be a program in the computer's memory. Let's
make sure it's all there:
First press SYSTEM RESET.
Then type:
LIST
10 GRAPHICS 3
20 COLOR 1
30 PLOT 10 .5
40 END
Make sure your listing is th e sa me as this.
RUNNING A PROGRAM
RUN
When you RUN the program, the comp uter plots the point for you .
RUN
ADDING TO A PROGRAM
You might have wondered , "Does the computer only understand line
numbers in multiples of 10 (that is 10,20,30 .... )?"
The answer is no. However, it 's a good idea to leave some space between
commands in case you want to add more instructions later.
Suppose, for example, you want to plot another point before the end of
the program . First, you'll want to have a look at your program again.
30 ATARI SOUND AND GRAPHICS
LIST
Now when you press RETURN, your program is shown on the screen
again.
10 GRAPHICS 3
20 COLOR 1
30 PLOT 10 ,5
40 END
35 PLOT 14 ,4 --_ __
10 GRAPHICS 3
20 COLOR 1
30 PLOT 10 ,5
35 PLOT 14,4
40 END
When you RUN this program (by typing RUN and pressing RETURN),
you get two dots.
• •
I ~EADY
A GRAPHICS PROGRAM 31
You might decide you want the computer to draw a verticle line before
plotting 14, 4. Easy enough , just add another line, something like:
32 DRAWTO 10 , 10
When you type the RUN command and press RETURN to execute this
program, it will look like this:
•
I
I ~EADY
10 GRAPHICS 3
20 COLOR 1
30 PLOT 10,5
32 DRAWTO 10, 10
35 PLOT 14,4
40 END
When you RUN a program, the computer will execute each line of the
program in sequence. By leaving some space in the original line numbers,
you can add instructions to this sequence as you go along.
CHANGE COLORS
34 COLOR 2
32 ATARI SOUND AND GRAPHICS
10 GRAPHICS 3
20 COLOR 1
30 PLOT 10,5
32 DRAWTO 10, 10 _____
34 COLOR 2 - - - - - -
35 PLOT 14,4
40 END
Try adding another color (0-3 ) and a few DRAWTO statements of your
own between lines 35 and 40 .
REM STATEMENTS
As programs begin to get longer and more involved , you'll need ways to
keep track of what you are doing. A us eful tool for marking different parts of
a program is the REM statement. The REM statement does not affect how
the program runs. To see this , ENTER the following short program and then
RUN it. ,
10 GRAPHICS 3
20 COLOR 1
30 PLOT 5,5
110 DRAWTO 30 , 5
I ~EADY
A GRAPHICS PROGRAM 33
10 GRAPHICS 3
2(.1 COLOR 1
3(.1 PLOT 5,5
11(.1 DRAWTO 3(.1,5
Now RUN the program again. It should work exactly as it did before .
We're going to add more lines to draw a figure , so let's put another REM
statement in the program to m ark the starting point of the drawing.
BUILDING BLOCKS
Let 's add another block with a blue line . ENTER these lines:
10 GRAPHICS 3
20 COLOR 1
25 REM ** STARTING POINT
30 PLOT 5,5
100 REM ** ORANGE LINE
110 DRAWTO 30,5
200 REM ** BLUE LINE
210 COLOR 3
220 DRAWTO 5, 15
Then RUN the program and this should appear on the screen:
The program should now look like thi s when you RUN it :
'......
•• ••.
,. .,
READY
•
36 ATARI SOUND AND GRAPHICS
10' GRAPHICS 3
20' COLOR 1
25 REM ** STARTING POINT
30' PLOT 5,5
DRAW A CUBE
We're going to give you a program listing to draw a cube on the screen.
ENTER each block of the program and occasionally RUN it before you enter
the next block. For example, RUN it after line 240 and then after line 350,
and so on. Save the listing for the exercises that follow .
A GRAPHICS PROGRAM 37
500 END
<>
I~EADY
38 ATARI SOUND AND GRAPHICS
READY
•
And finally:
I~EAD Y
A GRAPHICS PROGRAM 3~1
- - - - --- -----_._- - - - - - - - - -
In Chapter 7 you will learn to use a much greater variety of colors for both
the figures you draw and the background screen. This is done with the
SETCOLOR command , but you need to learn a few more programming
tools to easily understand this command.
In the next chapter you will learn to combine sound and graphics.
Self-Test
1. What do you call a set of instructions (with line numbers) that tells the
computer what you want it to do?
2. How would you store this command in the computer's memory?
GRAPHICS 3
Answers
1. A program
2. Give it a line number and press RETURN. For example:
20 GRAPHICS 3
Challenges
So far you have learned to make some sounds and also to create some
graphics with your AT ARI Computer. In this chapter you will learn to make
sound and graphics together. You will also learn an easy way to make the
computer playa melody with READ and DATA statements.
Let's start with a graphics program using some of the things you learned
in the last chapter:
I ~EADY
40
SOUND AND GRAPHICS TOGETHER 41
- - - - - - -- - -- _._ - - - - -_ .. .. _- . .... ---..- . ..-
When you RUN the program , you don 't hear the voice! What happened?
Well, the machine executed lin e 210 so fas t yo u didn't h ear the note
played. It then finish ed the program and printed READY in the text win -
dow. To stay in the program , the machine must be given a command like
thi s :
FOR-NEXT LOOPS
Instead of h aving voice 0 stay on , suppose you want to have it play for a
while and then turn it off.
Since the computer does things so fas t, it is sometimes necessary to tell it
to pause before going on.
You do this by telling it to coun t to itself for a vvhi/e. Th e machine counts
by using a:
FOR-NEXT lo op
You want the computer to pause after it plays the note , so put the
FOR-NEXT loop after line 210.
It will look like this:
When yo u ENTER these lines (by typing each one an d pressing RE-
TURN), th ey will replace th e previous lines 300 and 310. The FOR-NEXT
loop in lines 310 and 320 is now telling the computer to count to 500.
Your complete program listing now looks like this:
The spaces make it easier for yo u to read the program. They won't show
up that way in your listing.
SOUND AND GR,A.PHICS TOGETHER 43
Now RUN the program. Th e dot s hould appea r on th e screen. The note
plays for a while and th en turn s off. When the note stops pl ay ing, the word
READY appears again in the tex t w indow.
The value of 0 in the COLOR command in line 410 tells the computer to
plot a point the same co lor as the background screen. If we tell it to plot a
dot with COLOR 0 in a place where another dot already exists, it will erase
the dot that's there,
When yo u RUN thi s program, it puts the dot on the screen while it is
playing the note, then erases the dot as the note stops playing.
RUN it again to make sure you rea lly saw and heard what you thought
you saw and heard!
SOUND AND GRAPHICS TOGETHER 45
Wh il e the no t e
is playi ng: •
When t he note
stops:
READY
The word READ Y and the cursor appear in the text window when the
program ends .
46 ATARI SOUND AND GRAPHICS
INPUT STATEMENTS
What if you want to change the note this program plays without typing line
210 over again? You can do this by using an INPUT statement.
Here 's how it works.
First change line 210 to:
210 SOUND 0, N , 10 , 10
\
The INPUT statement must come befo re th e SOUND statement where the
N occurs here. We purpose ly skipped line 110 here beca use we 're going to
add a line there soon. You'll see!
SOUND AND GRAP HICS TOGETHER 47
Now add:
Input Duration
You can u se an INPUT statement for the length of th e pause in line 310 like
this:
Change line 310 to:
310 FOR P = l TO Z
Then add :
Then when you ENTER another no te value, you get anoth er question
mark.
Type a number for duration and press RETURN. Now it plays the note !
50 ATARI SOUND AND GRAPHICS
PRINT STATEMENTS
and:
I ~~TE VALUE
And then:
NOTE VALUE
121
HOW LONG DOES IT PLAY
?
Then it plays your note and asks for another one, and so on .
52 ATARI SOUND AND GRAPHICS
Before you start the exe rcises, Y OLl mi ght like to know about another
convenient point of gramm ar in AT ARI BASIC.
Multiple-Line Statements
AT ARI BASIC allows you to combine two or more commands on one line of
a program. To do this , you must separate the commands with a colon (:).
For example, a COLOR command and a graphics mode 3 command might
be combined as follows:
instead of:
110 GRAPHIC S 3
120 COLOR 2
SOUND AND GRAPHICS TOGETHER 53
You actually won 't see too m any uses of multipl e- line statements in this
book because we want to list the programs in a way th a t is easy for you to
read . We wanted you to know about this co ncept though, so yo u can use it if
you wish .
To play an entire melo dy, yo u can enter a SOUND statement for each note,
but there are easier ways to do it.
One way is to use READ and DATA statements together. This allows you
to ENTER several note values as DATA an d have the compu ter READ them
into the SOUND statement.
Type NEW and press RETURN to clear the last program from the compu-
ter 's memory. Now ENTER this program which plays ten notes:
This doesn't mean there is anything wrong; it just means the computer
can't find any more DATA to READ .
Here's how this program works. In lines 510 and 520 you've entered note
values from the chart on page 9 as DATA.
When the program RUNs, the READ statement in line 110 tells the
computer to READ the first note value from the DATA statement. That
value is 121. It plays that note in line 210.
When it gets to line 410, the machine goes back to line 110, and this time
it READs the second value for N (which is 81) in the DATA statement and
then plays it. It does this until it has read all the DATA.
We've used just ten notes here , but you can use as many as you want. You
can put more than five numbers per line in a DATA statement, but it's
easier to see what you're doing if you put only a few numbers on each line .
How about some dots with this one? Just add lines:
Graphics mode 5 has 80 columns and 80 rows. Since none of the values
for N in the DATA statement are more than 160, we can di vide N by 2 and
use that value for the column in a PLOT statement (line 280), if we use
graphics mode 5. All of the dots will be plotted in row 10
In this program, the machine enters the graphics mode each time it goes
through the loop . When it does this, it erases what it had plotted on the
screen before. That's why each dot disappears before the next one appears.
SOUND AND GRAPHICS TOGETHER 55
Self-Test
4. What value for COLOR do yo u use in lin e 410 to erase the dot?
56 ATARI SOUND AND GRAPHICS
Answers
7. Yes, but you need an INPUT statement for each variable. For example:
110 INPUT N
120 INPUT T
210 SOUND 0,N,T,0
Challenges
1. Write a program that lets you INPUT tone as a variable in the SOUND
statement.
2. Write a program using READ and DATA to plot some points.
CHAPTER FIVE
~
1 REM H·* OESCENOHJG PITCH
57
58 ATARI SOUND AND GRAPHICS
here on, but yo u don' t need to incl ud e them in order for the programs to
RUN properly.
Want to hear it repeat? Ju st add:
Now when you RUN the program you hear it play the cycle just as it did
before, but when it gets to line 310 it will go back to line 110 and start the
cycle again. This continues until you press the SYSTEM RESET key to get
out of the program. Giv e it a try to hear it for yourself.
There's another way to get out of a program and then back into it that will
produce an interesting result with this particular program .
First RUN the program and leave it going.
Now press th e BREAK key at the upp er right corner of the keyboard .
What happens ?
You'll get a message like this on the screen:
Meanwhile, the sound stays on, but th e pitch stops falling and remains
constant at some single note (it might be high ; it might be low).
Now type CO NT and press RETURN.
What happens this tim e?
It goes back to a falling ton e, picking up the cycle from wherever it was
when you pressed the BREAK key . Leave the cycle going for a while again.
Now press the BREAK key again .
You'll most probably ge t 8. different note when it stops this time. This is
because when you press the BREAK key, although the machine stops
SOME SPEC IAL EFFECTS WITH SOUND 59
running the program, it leaves th e voice on with whatever note value has
just been entered in the SOUND statement. So wherever you are in the
FOR-NEXT loop when you press BREAK, that's the note you'll get.
A little more experimentation w ith this idea wi ll give you a good sense of
how the FOR-NEXT loop is working in this program.
RUN the program.
Press BREAK.
Type CONT and press RETURN.
Press BREAK.
Type CONT and press RETURN.
And so on ....
If you want to slow down the rate at which the cycle occ urs and thus stretch
the sound out, you can us e the FOR-NEXT loop to pause the way you
learned in the last chapter. For example, add the following lines to the
program:
Make sure you h ave thi s listing before goi ng on to the next section :
Often yo u will wish to remove or delete lin es from a program. The way to
do this with ATARI BASIC is to simpl y type th e lin e number of the line you
wish to delete and then press RETURN.
Suppose, for exampl e, yo u 'wa nted to remove the REM statement from
the following program:
If you have something slightly different it 's okay because we're going to
delete several lines anyway. Let's delete some lines as follows:
You've just removed the PRINT statement , the INPUT statement, and th e
pause loop. The program shou ld now look li ke this:
This is the high end of th e spectrum, and also a short cycle, so it produces
a rapidly repeating, high-pitched sound, sort of like a bird chirping. The
complete listing should now look like this:
ENTER and RUN the program so you 'll hear it for yourself.
Before you look at the next program, see if you can think of a way to use
an INPUT statement to vary th e length of the sequence.
64 ATARI SOUND AND GRAPHICS
Playa Portion
from the Middle of the Spectrum
You don't ha ve to start counting with 0 in a FOR-NEXT loop , so it 's possibl e
to play a sequ enc e of notes from somewhere within the spectrum of notes.
For example, to playa sequ en ce with note values from lQi0 to 150, change
line 110 to:
~
20 PRINT II BE GINNING OF LOOp l1
30 INPUT A
50 INPUT Z
Vary both end s of ~
not e seque nce ~
~ 100 REM ** BEGIN S LOOP
110 FOR N== A TO Z
120 SOUND 0 , N , 10 , 10
We encourage you to ENTER these programs (don 't forget your editing
tools) and then give these concepts a thorough exp loration before going on.
This will give yo u many ideas to use in later programs.
COUNTING BY STEPS
Just as you might run up stairs skipping two or three steps at a time, the
computer can count in multiples of 2,5,10 , or whatever. To do this, use the
STEP function with the FOR-NEXT loop , as in line 110 of the program
below.
Rather than acting as a separate command, the STEP function becomes a
part of the FOR statement.
ENTER and RUN this program to hear what it sounds like. Values of 0,10,
20, and so on are now being entered for note in the SOUND statement in
lin e 120. Consequently , onl y twenty-five notes are played each time
through the sequence. This makes th e loop shorter and, as you can hear,
makes a sound that your ears can hear better than our words can describe.
If you want to count by 5's, just change line 110 to:
Now make the STEP function a variable and use an INPUT statement to
explore counting at different intervals.
66 ATARI SOUND AND GRAPHICS
Counting Backwards
You can also have the computer count backwards. For example, here's a
program to playa sequence starting with the lowest note (N = 255) and
going to the highest (N = 0):
ENTER and RUN this program to hear the note spectrum played in
reverse. Save yourself some typing by editing out lines 40 and 50 of the
previous program and th en changing line 110.
You can also play different portions of th e spectrum in reverse just as you
did going from high pitch to low pitch. For example:
SOME SPECIAL EFFECTS WITH SOUND 67
ENTER and RUN this program to experiment with how counting back-
wards at different intervals affects the sound.
Now see if you can change the program to use an INPUT statement to play
part of the note sp ectrum backwards. We'll give one example; you try a few
others.
Back-to-Back Loops
You can get some interesting effects by having a loop with falling pitch
followed by a loop with rismg pitch, like this:
When you ENTER and RUN this program, you'll get another kind of bird
sound than w h en you used a loop go ing in only one direction.
For an experiment , try making the first loop playa longer cycle of notes,
like this:
ENTER these lines and RUN the program to hear the latest sound. Of
course, you can do it the other "vay around . That is, make the first loop short
and the second loop long .
There's room to add a FOR-NEXT to pause between lines 12(,) and 19(,) or
between 22(,) and 29(,), so be sure to experiment with the effects created by
doing that.
70 ATARI SOUND AND GRAPHICS
A BRIEF REVIEW
You have also learned to us e a nested loop to pause after each note.
We suggest that you thoroughly exp lore th ese possibilities before going
on . You'll undoubtedl y discover many things we haven't thought to men-
tion.
Try to write programs using INPUT statements to explore some different
parameters. For examp le, try to INPUT different values for tone (even
numbers 0 to 14). Remember, tone is the third parameter in the SOUND
statement.
As you do this , you'll probably get some ERROR messages. Don 't be
discouraged. Every programmer, no matter how skilled, experiences this.
Sometimes you find out what th e rules of a particular language (in this case
AT ARI BASIC) are by just trying things to see if they work.
As a matter of fact , we didn 't just sit down and type in the programs you
see in this book. We got several ERROR messages before we got them the
way we wanted them.
There's an ancient Chinese proverb that goes something like:
* * * * * * * * * * * * * * * * * * * * * * * *
RIGHTEOUS PERSISTENCE BRINGS GOOD FORTUNE
* * * * * * * * * * * * * * * * * * * * * * * *
Another way to have the computer count is shown in lines 110 and 120 of
the following program:
310 NEXT N
410 GO TO 110
SOME SPECIAL EFFECTS WITH SOUND 71
ENTER an d RUN this program and you 'll hear th e pitch of the sound
rising just as it wou ld if lines 110 and 210 were :
In the vers ion we 've used above , where th e computer subtracts the value
of N fro m 255 in the SOUND statemen t eac h tim e through the loop , h ere 's
what happ ens .
First, line 110 gives N a value of 0. Then, in th e SOUND statement in line
210 th e note va lue becomes :
255 - 0 = 255
Next tim e through the cycle, N gets a va lu e of 1. So the note value in the
SOUND statement becomes:
255 - 1 = 254
210 SOUND 0, N, 10 , 10
260 SOUND 1 , 2 55-N , 10 , 10
310 NEXT N
410 GO TO 110
ENTER and RUN this program to h ear the sound it creates . Line 210 is
playing note values beginning at 0 and increasing to 255, thus causing a
rising pitch . Line 260 is playing notes go ing in th e opposite direction; that
is from 255 to 0 , thu s creating a falling pitch . Figure 5-1 pictures what's
happening.
You can us e this techniqu e to have a rising and falling pitch converge
upon some note in the middl e of th e spectrum . That is, they stop rising or
falling when they get to the same n ote and continu e to play that note.
72 ATARI SOUND AND GRAPH ICS
Note va lu es
ENTER and RUN thi s program to hear a risin g and fallin g pitch co nverge
upon a single note:
31(0 NEXT N
41(0 GO TO 41 (0
Figure 5- 2 Two Voi ces Co nverge il nd Playa Sin gle Sustain ed Note
f----- - - - - - ---~
T he two voices
meet here
You can us e this technique playing part of the spectrum as well. You
might have something like this:
210 SOUND 0, N, 10 , 10
Plays note va lu es _ _ _._. 260 SOUND 1, 100-N , 10', 10'
from 60 to 50
310 NEXT N
ENTER and RUN this program and then try some variations on lines 110
and 260 for yourself.
A short loop to pause between the two vo ices w ill give you yet anoth er
sound, but it will be most effective if yo u turn off each voice (as you learned
in Chapter 4) while the other voice is playing. The following program gives
an example of how this might be done:
310 NEXT N
410 GO TO 410
try using different 'va lues for the tone parameter in th e SOUND statement
with this program. Remember , tone is eve n numb ers from!il to 14 inclusive .
We'll look at some ways to use three and four vo ices to create sound
effe cts later, bu t don 't be afraid to try programs using three or fo ur voices on
yo ur own now. You'll proba bly find plen ty of thin gs we h aven' t thought of.
Have you ever wondered what makes a piano playin g the note middl e C
sound different from a violin play in g th e same note?
Actually many fac tors contribute to th e ch aracteristic sound of a particu-
lar instrument. As a matter of fact, a very exc iting science called psycho-
acoustics studies th ese factors in detail. We won't be abl e to go very deepl y
into the nature of so und in thi s book, but we will loo k at a few ways to
"sh ape" notes with AT ARI BASIC.
Two very imp ortant factors co ntributing to the shape of a note are its
attack and its decay.
Attack
The attack of a note refers to how fas t it reach es its maximum volume. A
note with a fast a ttac k (typ ica l of the piano) w ill reac h its maximum volum e
very qui ckly. A note w ith a s low attack (typ ica l of the violin) will take
longer to reach its maximum vo lum e. This is pi ctured in Figure 5-3.
You can affect the attack of a note with AT ARI BASIC by using a
FOR-NEXT loop ,,,,ith th e loudn ess parameter of th e SOUND statement. To
explore this, first ENTER and RU N the following program:
It briefly plays th e note middl e C as you would ex pect. Now RUN the
Time
SOME SPECIAL EFFECTS WITH SOUND 75
program a few more tim es , paying very close attention to how the sound
starts. If you type RUN and th en wait a few seconds before you press
RETURN , it will help you with this exp eriment.
Once you've done that, add the following lines to the program:
When you ENTER and RU N this program , you' ll hear that the note
doesn't have such an abrupt beginning as it did before. This is because the
attack is much slower.
You can slow the attack of the note in this program even further by
adding a very short pause loop as follows:
190 NEXT L
299 REM
310 FOR P=0 TO 100
320 NEXT P
76 ATARI SOUND AND GRAPHICS
Changes in the length of the pause in lines 160 and 170 will produce
variations in the attack of the note. It is worth exp loring. See if you can
make some changes in the program to do this with an INPUT statement:
then have a look at our program below.
Program to INPUT changes in attack of note:
Decay
The speed with which the loudness of a note falls off after reaching its
maximum loudness is call ed the decay of the note.
To affect the decay of a note , use the FOR-NEXT loop to count the
loudness parameter in reverse. For example:
390' NEXT L
ENTER and RUN this short program. It plays the note pretty fast, but
there is a slight decay on the note. Run it a few more times , and then add
this nested loop to pause within the decay loop .
390 NEXT L
50 INPUT A
300 REM ** DECAY LO OP
310 FOR L = 15 TO 0 STEP -1
320 SOUND 0 , 121 , 10 , L
350 REM ** PAUSE
360 FOR P= 1 TO A
370 NEXT P
390 NEXT L
Now delete all th e li nes of th is program up to lin e 300 by typing eac h line
number and then pressing RETURN. Change line 360 to:
360 FOR P= 1 TO 10
78 ATARI SOUND AND GRAPHICS
Time
Keep lines 300 through 390 for the next section though. Here's what you
should have:
390 NEXT L
190 NEXT L
If not, simply type NEW, press RETURN , and ENTER the following
program:
190 NEXT L
390 NEXT L
410 GO TO 110
Experiment with changes in lin es 160 and 360 to affect the attack and
decay of the note befor e going on to the next section.
80 ATARI SOUND AND GRAPHICS
Another way to shape th e note is to use two voices and h ave th e loudn ess
going in both direction s within th e same loop. ENTER and RUN the follow-
ing program to h ea r h ow this affec ts th e s hap e of th e note:
250 NEXT L
Try some var iations in th e len gth of th e pause in lin e 150 on your own.
Many of th e c hanges we've been mak in g in th e a ttack and d ecay of th e
note are very subtle. They are worth exp loring both to increase yo ur
knowledge of AT ARI BASIC and to better und erstand th e n ature of sound.
910 GO TO 120
ENTER and RUN this program. It 's a little different in structure from the
version in Chapter 4 (there are no graphics and so me of the line numbers
are slightly different), but it is still YOUR OWN SONG.
Restore Data
and Repeat the Melody
Now that yo u 've become familiar w ith FOR-NEXT loops, h ere's a way to
RESTORE DATA and READ the melody repeatedly instead of just once.
You'll also finally be ab le to stop getting the same ERROR message you get
every tim e you RU N the program above. Add these lines:
Line 510 replaces the GOTO statement that was there. Line 910 sends us
to lin e 110 instead. Here's the comp lete listing:
1 REM ** YO UR OWN SO NG
RUN the program like this, and you' ll hear the melody repeat.
We want to count ten notes in the DATA tabl e in lines 1110 and 1120.
This is done with the FOR-NEXT CYCLE loop in lines 110 through 510.
Each time throu gh the cycle, another note value is re ad from the DATA
tabl e and played in the SOUND sta tement in line 220. Lines 310 and 320
keep the note on briefly and then the next note is read, and so on until the
82 ATARI SOUND AND GRAPHICS
cycle has been completed ten times. In this way, it reads the ten note values
in the DATA table.
If you have the cycle play only five times:
it will play the first five notes over and over. The cycle must be repeated
once for each piece of DATA (in this case note values).
If you made line 110:
it will play the first ten notes , and you'll get an out-of-data error (ERROR-6
AT LINE 120).
The READ statement (line 120), the SOUND statement (line 220), and the
pause loop (lines 310 and 320) shou ld all be within the FOR-NEXT CYCLE
loop (lines 110 through 510).
Now add:
You can change the decay by changing line 310 if you wish, or you can
completely replace th e decay loop (lines 200 through 390) with an attack
loop , by making line 210 :
Try to replace the decay lo op we've used with one or more of these. Be
sure that any loop you use to change the shape of the notes occurs within
SOME SPECIAL EFFECTS WITH SOUND 83
the FOR-NEXT CYCLE and begins after the READ statement , and that all
loops are properly n ested.
You could also include a lo op for ascending or descending pitch within
the FOR-NEXT CYCLE loop , but the nesting gets a little tricky. Try it if you
wish.
We've chosen to hav e a descending pitch loop outside the FOR-NEXT
CYCLE loop an d after the RESTORE statement in line 520, like this:
910 GO TO 110
After adding lines 600 through 610 above, RUN the program and you
should hear the melody played . You then hear th e descending pitch cycle
yo u learned at the beginning of the chapter.
84 ATARI SOUND AN D GRAPHICS
Finally add:
390 NEXT L
500 REM ** PLAYS NEXT NOTE
'----- 510 NEXT CYC LE
520 RESTORE
~
710 FOR CYCLE = l TO 12
720 FOR N= 0 TO 10
[ 730 SOUND 0, N , 10, 10
740 NEXT N
750 NEXT CYC L E
910 GOTO 11 0
This is a n ested loop that plays a high, descending pitch (lines 720
through 740). This is repeated twelve times by the FOR-NEXT CYCLE loop
in lines 710 through 750. When you RUN the program after adding these
lines , you'll hear an examp le of how sound effects can follow one after th e
other.
Now add a sound effect of your ovvn beginning at line 800. Spend some
time practicing the art of moving different routines aro und by deleting
some of th e routines we 've used and replacing them with yo ur own
routines.
In the n ex t chapter you w ill learn to make these into subroutines to be
called upon at different places in a program.
Self-Test
1. To play note values from 50 throu gh 100 , what should you make line
110 below?
110_______________
120 SOUND 0, N, 10, 10
130 NEXT N
3. How would you co unt by 5's backwards in the same program '?
4. What 's wrong with the following program?
Answers
4. The pause loop is not properl y nested w ithin the loudness loop.
5. Type th e line number for the line yo u wish to dele te and then press
RETURN.
6. Attack
7. The decay of the note
8. RESTORE
Challenges
1. Write a program with a very slow attack that allows you to INPUT
tone as a variab le.
2. Write a program using four voices where two voices stay the same .
CHAPTER SIX
In this chapter you will learn abou t graphi c modes without text windows .
You will also learn to use FOR-NEXT loops to create various graphics
effects and how to make subroutines.
The graphics modes we have used so far (3-7) have had a text window at
the bottom of the screen.
87
88 ATARI SOUND AND GRAPHICS
ENTER and RUN the following short program to plot a point in graphi cs
mode 19 , which h as no text w indo w:
RUN this program to see what happen s. Th e screen s hould look like thi s :
The computer plots the same point that it wo ul d if yo u h ad used graph ics
mode 3, but th ere's no text window.
You may reca ll that the maximum numb er of rows available in graphics
mode 3 was tw e nty (numbe red til throu gh 19). Using grap hics mode 19
SUBROUTINES FOR GRAPH ICS AND SOUND 89
instead gives you four more rows in which to plot points. The number of
columns is the same. Graphics mod e 19 has:
40 columns (0-39 )
24 rows (0-2 3)
Novv let's use thes e limits to plot points in each co rner of th e screen with
graphics mode 19. To do thi s, first change line 210 to :
Remember this can be done by simpl y typing the n ew line and pressing
RETURN.
Then add these lines:
You 'll see more of th ese graphics mod es without text windows in this
chapter. Try some other gra phi cs mod es without text windows on your
own.
90 ATARI SOUND AND GRAPHICS
Now RUN the program and the screen shou ld look like this:
• • • • • • •
• • • • • • • •
• • • • • • • •
• • • • • • • •
• • • • • • • •
Changing the value of th e STEP function in li nes 210 and 220 wi ll change
the pattern of dots that appear on th e screen. Can you think of a way to make
these changes using an INPUT statement?
See what happens if you remove the STEP func tion from one of the lines
and then from both lines.
Let's nest these loops w ithin yet another loop to change the color of the
dots . First, add these lines:
120 COLOR C
By now we assume you know that REM statements are always optional
when adding new lines to a program.
The program listing should look like this:
ENTER and RUN this program and you 'll see the colors continually go
from orange to yellow , to green, and then to orange again, and so on. This
occurs as rapid waves going across the screen .
We didn't use COLOR 0 in line 110 of the program because we didn't
want to erase the dots . Try having line 110 count from 0 through 3 to see
what happens.
In this chapter and in Chapter 5 , you 've been learning a lot about construct-
ing routines to manipulate sound and graphics. Often you will want a
particular routine to be repeated at various times during the RUN of a
program . A convenient way to accomplish this is to make that routine a
subroutine .
Although it isn't absolutely necessary, it's generally a good idea to put
subroutines after the main body of the program. The following program
makes a subroutine out of a section of the "Color Dots" program above that
plots the dots:
SUBROUT INES FOR GRAPHICS AND SOUND 93
If you don 't want to do a lot of extra typ in g, you ca n change the number of a
program lin e by typing the new line number ove r th e old line number and
pressing RETURN. For examp le, to make lin e 2000 out of this line:
use the CTRL key an d the arrovv keys as desc rib ed in Cha pter 1 to move the
cursor until it covers the 2 , li ke this:
Delete line 200 by typ ing 200 and pressing RETURN. If you still have the
"Color Dots" program without a subroutine, change lines 210 through 240
to 2010 through 2040 in this way.
If you get hung up trying to do this , you can always retype the new lines
(2010 through 2040) and delete the old ones (210 through 240).
In whatever way it's easiest for you, make sure you have the listing we've
shown above, and then RUN the program. It does just what it did before ;
that is , it plots the dots and then sends waves of color through them. The
way the present program does this is a little different though.
In this version, instead of having the loop that plots the dots nested
within the loops to change colors (lines 110 through 410), we've placed it at
the end of the program beginning at line 2010, or as a subroutine .
When the program runs, a value is picked in line 110 and entered in the
COLOR statement in line 120. As the name would imply, the GOSUB
statement at line 210 takes us out of the main body of the program and
sends us to line 2010. The computer then executes line 2010 and all the
lines that follow, until it reaches the RETURN statement in line 2110. As
the name of that statement would imply, it tells the computer to return to
the main body of the program. It always returns to the program line
immediately after the GOSUB statement. In this case it returns to line 400,
which th e computer ignores since it is a REM statement. So it actua ll y picks
up at line 410, which completes the COLOR Loop in lines 110 through 410.
Each time the computer gets to the GOSUB statement in line 210, it
executes the entire subroutine to plot dots as though it were still nested
within the FOR-NEXT loop for co lor.
Now let's look at some ways to exec ute routines within the main body of
the program and then occasionall y use the subroutine again. For example,
suppose you want to overlay another figure on the screen while the dots are
still there (and then have the dots blink off and on each time they change
colors).
First add these lines to draw a figure :
SUBROUTINE S FOR GRAPHICS AND SOUND 95
If yo u 've been experimenting with add ing COLOR 0 in line 110, make
sure 110 is:
ENTER and RUN the program and you'll get this on the screen, with the
colors changing as they did before.
Notice that the color of the dots changes just an instant before the figure.
After each new color is selected in line 120, the GOSUB statement in line
210 plots the dots in that color before the figure is drawn in the new color at
line 310 .
Also notice that we've begun the routine to draw the figures with DRAW-
TO statements at line 310. If you look carefully at lines 2010 and 2020 in the
subroutine , you 'll see that the last point it plots is at column 37, row 20 , at
the bottom right corner of the screen. The RETURN statement then brings
us back to line 310, which draws a line from the dot in the bottom right
corner of the screen to the dot in the upper left corner of the screen. That's
the diagonal in the figure. The next four DRAWTO statements (lines 310
through 350) draw the border by drawing clockwise from one corner dot to
the next.
Now we can take advantage of the subroutine to erase the dots "vhile th e
figure stays on the screen. Just add the following lines:
Now after drawing the figure. the co lor changes to 0 in lin e 370 and the
GOSUB statement sends us down to plot all the dots in COLOR 0. As you
may recall from Chapter 2, this will erase the dots beca us e it plots them in
the same co lor as the background screen .
._ - - - - - - - - - - -- - - - - - - - _._._---
98 ATARI SOUND AND GRAPHICS
We're going to give you one more idea that demonstrates just how much
one line can sometimes change a program , and then we'll offer some
suggestions on how you might explore the concepts before going on.
Take a careful look at the subroutine to plot the dots . If you put a
DRAWTO statement after the PLOT statement in line 2030, but before
either of the NEXT statements in lines 2080 and 2090, the machine will
draw a line to whatever point you indicated after it plots each of the dots.
That adds quite a few lines to the drawing. To get a sense of this, add this
line to the program:
This tells the computer to draw a line from each point it plots to a point
more or less in the center of the screen.
Since the way this new figure comes on and off the screen is a major part
of the effect created by adding this line, we won't try to picture it for you.
RUN the program and you'll see what we mean .
If you have an ATARI 410© Program Recorder or an ATARI 810© Disk
Drive system, we suggest you save this program before experimenting since
we will continue to build upon it in the second half of the chapter. The
manual that accompanies each of these systems explains their use. We will
not attempt to do so here.
2050 DRAWTO A, B
and then add a few INPUT statements to change the location of the point
to which the lines are drawn. Move line 2050 to line 2085 between the
NEXT Y and NEXT X statements and exp lore that using INPUT statements.
NESTED SUBROUTINES
Just as you are able to nest FOR-NEXT loops within other loops , you can
also nest subroutines. One subroutine is not actually placed within the
other as with FOR-NEXT loops, but you can use a GOSUB statement to
temporarily leave a subroutine. Take a look at the subroutine for the
graphics program we've been working with in this chapter.
SUBROUTINES FOR GRAPHICS AND SOUND 99
The main body of the program remains the same. RUN the program and
you'll hear it playa rapid sequence of notes as it is drawing th e figure . It
100 ATARI SOUND AND GRAPHICS
plays the note sequence again as it erases the figure, then again as it redraws
the figure, and so on until you stop the run.
Each time through the FOR-NEXT loop in lines 2010 through 2110, after
plotting a point and drawing a line , we come to the GOSUB statement at
line 2060. This sends us to line 3010 where a note is played with decay
loop . The note value used is the sum of the values of X and Y chosen in the
original subroutine.
Before looking at how we've done it below, see if you can add a sub-
routine to playa rising pitch with note values from 50 to 0 similar to what
you learned in Chapter 5. Have this occur after the figure is drawn and the
notes played. HINT: The GOSUB statement to send you to the new sub-
routine should occur after the FOR-NEXT loops for X and Y in the original
subroutine.
We added the following lines to do it:
and:
Make sure you have the rising pitch subroutine added properly, and RUN
the program. First you'll hear the note sequence played as the figure is
drawn, then a whistle before it starts to erase. Once it's erased, you hear the
whistle again before it draws the next figure , and so on until you stop the
run.
Here's the complete listing of the program:
5
I
I
.
3030
3040
NEXT L
RETURN
The numb ers 1 through 6 indicate the ord er in which program parts are
executed.
102 ATARI SOUND AND GRAPHICS
You can also place a GOSUB statement in the main program to make use
of this second subroutine. For example , add these lines and hear what
happens when you RUN it:
Now after it has drawn and erased the figure in each color while making
sounds (after it has completed the loop in lines 110 through 410), it
whistles three times before it starts again.
But what happens if you try to go from the main program to the sub-
routine to play notes in lines 3010 through 3040, by adding a line some-
thing like:
490' NEXT G
SUBROUT INES FOR GRAPH ICS AN D SOUND 103
510 GOTO 40
Add these lines and RUN th e program. You 'll see the same cycle of co lors
and sounds as before , but th e fi gure w ill occur in th ree different sizes
starting in the upper right corn er of the screen .
The STEP -2 in line 40 ca us es the co mputer to enter graphics mode 23
(equivalent to GR. 7), then Mode 21 (equiva lent to GR. 5), and fina lly
graphics mode 19 (equivalent to GR . 3) . We 've skipped the even numbered
modes 20 through 22 which are equiv alent to mod es 4 and 6 with text
windows. This is becau se, as we m entioned in Chapter 3, these are two-
color modes and we are using four co lors (0 through 3) in this program .
You can use modes 20 and 22 if you wish , but these modes use only
va lues of 0 and 1. Whenever a va lue of 2 is entered by the FOR-NEXT loop
for COLOR in li nes 110 through 410, the compuer wi ll treat it as though it
were a 0 and erase the figure . This is ca ll ed a defau lt. Actua ll y, when it sees
a va lue of 3 for COLOR in th ese mod es, it d efau lts to 1 and draws the figure
in COLOR 1.
In th e four-co lor mod es (3, 5, and 7) or (19 , 21, and 23) any number above
3 wi ll d efault to a value of 0,1 , 2. or 3. For examp le:
120 COLOR 5
120 CO LOR 1
And:
120 CO LOR 1 1
120 CO LOR 3
The FOR-NEXT loop for gra ph ics must comp lete ly encompass th e loop
for COLOR. Or to say it the other way around, the FOR-NEXT loop for
COLOR must be nested within th e FOR-NEXT loop for graphics.
104 ATARI SOUND AND GRAPH ICS
In Chapter 7 yo u ' ll learn about grap hi cs modes 8 and 24, the SETCOLOR
command , and how to do " hi gh-resoluti on" graphi cs-graphics with mu ch
small er plot points that let you draw fin e li nes .
Se lf-Test
1. To chan ge from a graphics mod e with text window to one with the
same size p lot poin ts and no tex t "vind ow, w hat numb er do you add?
2. What statem ent is used to leave the main program and execute a
subroutine?
3. What's n eeded befo re th ese lines can fun ction as a subroutin e?
4 6 10 FOR CY CLE = 1 TO 3
4710 GO SUB 310610
4810 NEXT CYCLE
Answers
1. 16
2. A COSUB statemen t
3. A RETURN statement to bring yo u bac k to th e main program
4. To the program line im me diate ly foll owing th e COSUB statem ent
that activated the subroutin e
5. Typ e the n ew line numb er over th e ol d on e
6. Yes . This is called a n ested subroutine.
7. Back to co m p lete the subroutin e from \,v hi ch yo u ca me
8. Three tim es
SUBROUTINES FOR GRAPHICS AND SOUND 107
Challenges
1. In this chapter, we drew a figure on the screen and then erased it. See
if you can construct a program that draws two separate figures and
leaves one on the screen and erases the other, and th en switches by
redrawing the figure it has just erased and eras ing the one it has just
drawn.
2. Try adding some routines for so und to accompa ny each of the figures .
CHAPTER SEVEN
You've learned to us e both two- and four-color graphics with and without
text windows . In this chapter you will learn to use the SETCOLOR com-
mand, which gives you greater variety of options for color grahics with your
ATARI Computer. You w ill also learn to use a high-resolution graphics
mode (8 or 24). Finally , you will learn to use IF-THEN statements to have
the computer select variabl es or execute routines.
SETCOLOR COMMAND
108
THE FINER POINTS OF GRAPHICS 1 ml
- - - - - - - - - - - - - - - _. _ . _ - - - -- - - - -- _._- - -
This program is structure d so that it w ill be easy to add more lines and
routines later.
When yo u RUN this program. you should get an orange h exagram on the
screen :
<--->
110 ATARI SOUND AND GRAPHICS
The extra PRINT statement at line 25 wi ll print a blank line so that the text
is easier to read when it's printed. It 's not essential to the function of the
program, so you don 't have to use extra print statements if you don't wish.
Now change line 220 to:
To save yourself having to RUN the program each time you want to INPUT a
new value for color register, replace line 510 with:
This will ca use the hexagram to stay on the screen bri efl y after you INPUT a
valu e for color register and then go back an d wait for yo u to INPUT another
variable .
Make sure you hav e thi s li stin g and then RUN th e program:
Different values for th e co lor register wi ll allow you to change the hue of
either the figure , the ba ckgro und screen , or the text window. Color register
doesn't change thes e by itself, but determines which (figure, background,
or text window) will change hu e w hen yo u vary th e hue parameter. For
example, when you enter a va lu e of 0 for co lor register , the hexagram will
be blue. In COLOR 1 , a va lu e of 0 for color register allows the hue of the
figure to be changed. It is actu all y the value 8 for hue , which changes the
color.
To see this , enter a va lu e of 4 for color register. Now the figure becomes
orange and the background screen beco mes blue. Orange is th e "default"
112 ATARI SOUND AND GRAPH ICS
INPUT Hue
The second parameter in the SETCOLOR command is hu e. It can have
values for 0 through 15. To INPUT hu e as a variab le in the program w e've
been using, making th e following additi ons and changes .
Add:
35 PRINT
40 PRINT "ENTER 0-15"
50 PRINT "FOR HUE"
60 INPUT H
ll~ GRAPHICS 3
65 PRINT
7~ PRINT "ENTER EVEN NUMBER (0-14)"
8~ PRINT "FOR LUMINANCE"
9~ INPUT LU
L
35PRINT
40 PRINT "ENTER 0-15"
50 PRINT "FOR HUE"
/ _____ 60 INPUT H
:....------- 65 PRINT
a ll three 70 PRINT "ENTER EVEN NUMBER (0-14)"
parameters of
SETCOLOR. ______ 80 PRINT "FOR LUMINANCE"
------ 90 INPUT LU
RUN the program and try many combinations of the variables. Remember,
values of 1, 2, or 3 for color register (the first variable you INPUT) will
default to an orange figure and won't be affected by hue or color luminance .
So INPUT 0 or 4 for color register. Also be sure to explore the results of
changing the value for COLOR in line 120.
Be careful not to crash the program by trying to enter a variable while th e
figure is on the screen or by trying to enter an incorrect value for one of the
parameters. These co nc epts will take some time to fully grasp. Careful
study of Appendix D should be helpful.
FOR-NEXT HUE
and:
230 NEXT H
Also add:
220 SETCOLOR 0, H, 6
THE FINER POINTS OF GRAPHICS 117
It may be just as easy for yo u to type NEW and start over. However you
accomplish it , make sure you have this listing:
Now RUN· th e program an d yo u should see the figure appear on the screen,
continually changing colors .
Each time through the loop in lines 210 through 290 the machine EN-
TERs a value for hu e in line 220 and then uses the subroutine to draw the
figure. When all sixteen valu es for hue have been us ed, line 510 sends us
back to start the loop again .
Hue changes happen pretty fast this way, so if you want to see each hue a
little more distinctly, you can ad d a pause each time the figure is drawn
with these lines.
Add these lin es and RUN th e program to pause at each hue.
We've put th e pause inside th e subroutine. It would have the same effect if
you put it inside the FOR-NEXT loop for hue , for example, at lines 240 and
250. Either way will result in a pause after each hue has been entered. If you
put the pause outside of the loop, for exam pl e, at line 410, the machine will
RUN through all sixteen hues without pausing and pause on ly at the last
value for hu e, that is 15. So if yo u "vant to see each hue distinctly, you must
put the pause within the lo op.
118 ATARI SOUND AND GRAPHICS
Here's a complete listing of the program with the pause in the subroutine:
and:
350 NEXT CR
This will nest the FOR-NEXT loop for hu e wi thin the color register loop.
Finally, change line 220 to:
SETCOLOR CR, H , 6
THE FINER POINTS OF GRAPHICS 119
RUN this program to see the figures and the background change hue.
In the next section we're go in g to build on the "Changing Hues" program
that appeared earli er. You can either retype the program or make the
following changes and deletions.
220 SETCO L OR 0, H, 6
120 ATARI SOUND AND GRAPH ICS
Make any other changes you need to come up with this listing:
Suppose you were creating a game in vvhich yo u wanted to use a figure like
the one in the program \,v e've bee n using as a star ship that co uld be moved
around on the screen. Obviously yo u don't want to type in a whole routine
every time the figure is to move. You can save yourself the trouble by
entering variables for the intial plot point in line 301(/J and then having the
DRAWTO statements in lines 302 0 change in relationship to th ese vari-
ab les.
For example, change line 3010 to:
3010 PLOT X, Y
Now assume for a moment that X and Yare still 10 and 10. Looking at line
3020 yo u can see that the values for column and row in the DRA WTO
statement can be changed to X + 5 [10 + 5) for column and Y - 5 [Hi - 5) for
row . So line 3020 becomes :
In the same way, lines 3030 through 3070 can be changed to:
To provide room to move the figure around, let's change line 110 to:
110 GRAPHICS 23
~?
30 PRINT
50 PRINT "ENTER 5 - 90 FOR ROW"
60 INPUT Y
A ll ows you to
place the figu re 100 REM ** SETUP FOR GRA PHIC S
at different
locations on 110 GRAPHICS 23
the screen.
120 COLOR 1
Notice that, although graphics mode 23 has co lumns from 0 through 159,
we've indicated in the PRINT statement in line 10 that you should not
exceed a value of 139 for column. This is because in line 3040 of the
subroutine to draw the figure, we will have a value of 139 + 20 = 159 if we
INPUT 139 for column. Likewise, th e minimum value for row must be 5 to
allow for the Y - 5 in lines 3020 and 3030 . And since lines 3050 and 3060
add 5 to the value of Y, we make the maximum limit for row 90 instead of
95.
Now RUN the program and place the figure at different places on the
screen by INPUTing values for X and Y.
THE FINER POINTS OF GRAPHICS 123
Let's add a subroutine that introduces some sound each time the figure
appears. We'll set it up so that the lower the figure appears on the screen,
the lower the sound. Since the higher row numbers correspond to lower
screen positions and higher note values correspond to lower notes, we can
accomplish this by making the note value a function of Y. While we're at it,
let's have the value for hue (H) also affect the note value . This is done in line
5020 of the following subroutine:
We've used a value of 12 for the tone parameter here to get a different
effect.
Now add a GOSUB statement at line 3080 to call this routine. Finally, add
these lines to briefly sustain the last note played and then turn off the sound
before the figure disappears .
35~ FOR P= 1 TO 1~ ~
36~ NEXT P
37~ REM ** TURN OFF VOICE ~
38~ SO UND ~ , ~ , ~ , ~
RUN the program to hear how the sound works with th e different posi-
tions of the figure .
Each tim e through the hu e lo op in lines 210 through 290, the GOSUB
statement at line 260 calls the subroutine to draw the figure. Line 5080 of
that routine calls the sound routin e (nested subroutines). Note gets a value
of Y that you have en tered, plus the va lu e for H that the hue loop has
reached. For example, if you've entered a value of 40 for Y, then N will be
40 + 0 = 40 the first tim e through the loop and 40 + 1 = 41 the next time ,
and so on up to 40 + 15 = 55 .
After each of the hu es has bee n reg istered and eac h of the notes played,
we return to lines 350 through 380, which very bri efly sustain the note and
then turn off the sound. And fin all y lin e 510 starts us over again.
For a challenge:
Use FOR-NEXT loops in stead of INPUT statements to move th e figure
around. HINT: For bes t results, these loops should begin before lin e 210
and end after line 380 . Don 't forg et to remove the INPUT statements if you
try this experiment.
126 ATARI SOUND AND GRAPHICS
Make sure you have this listing before go ing on to the next section:
360 NEXT P
370 REM ** TURN OFF VOICE 0
380 SOUND 0, 0,0, 0
IF -THEN DECISIONS
While you were experimenting "vith this program, you may have occa-
sionally slipped and entered a va lu e that was too sma ll or too large for X or
Y , thus getting an ERROR message and having to start aga in.
A programming tool that can be used to catch these mistakes without
crashing the program is the IF-THEN statement. Essentia ll y, what this
statement says is:
For examp le, suppose in the program we've been using to move the figure
on th e screen , we want th e machine to reprint the instr uctions in line 10 if a
value greater than 139 is entered. We can do this w ith a line like this:
~ Symbo l for "is
40 IF X > 139 THEN 10 greater than "
Add this lin e and RUN the program. Then try enter ing a value greater
than 139 a few times to get the idea. Instead of giving you an ERROR
message this time , the m ac hine just prints:
over again. This w ill happen as many times as you e nter incorrect values.
When the conditions of the IF part of the s tatement are not met-that is ,
when X is not great er than 139-the THEN part of the statement is ignored
and the next line of th e program is exec uted. Have a look at th e lin e aga in
with arrows indicating the different directions the program might take.
Th e condition If X is greater than
• , /~------ 139 . it goes this
If X is not greater
4(;( IF X
'P
> 139 - - - " ' '- - THEN 4(;('P way
than 139. it goes ~ J
this way r
50· . - -. - - . - . .
Now let's add a few more lines to account for incorrect values for Y being
entered:
~
70 IF Y < 5 THEN 5(0 Less than
80 If Y > 90 THEN 50
Rather than reprint the instru ctions , we can default to 139 any time a
value greater than 139 is entere d for X by makin g lin e 40:
With these conditions , any tim e yo u ENTER a va lu e greater than 139 for
X, it wi ll plot th e starting point for the figure in co lumn 139 . In the same
way, lines 80 and 90 can be changed to:
Add these lines , RUN th e program , and try some va lu es greater than 139
for co lumn and less than 5 or greater than 90 for row. This time, when you
ENTER an incorrect val ue for co l umn or row the machine will still draw the
figure.
See if you can us e thi s m ethod to limit the area in which the figure is
drawn to a specific area of the screen , for example, th e left side or th e
bottom half.
IF-THEN statements ca n be used to make a number of different kinds of
comparisons. We 've looked at compari sons based on whether one variable
is greater than the other and com parisons based on w h ether one variable is
less than th e other. Th e following chart s hows some other comparisons that
can be mad e:
The ATARI Computer has a high-reso lution graphics mode that enabl es
yo u to plot much smaller points and th erefore draw mu ch finer lin es. This
is graphics mode 8 , with th e text window. or 24, without the text window.
Although it is possible to draw without it, you need the SETCOLOR
co mmand to introduce color in mode 8 or 24. That's why we've waited
until you 've learned abo ut the SETCOLOR command before discussing the
high-resolution mode .
130 ATARI SOUND AND GRAPHICS
Columns Rows
Graphics 8 (0 - 319) (0 - 159)
Graphics 24 (0 - 319) (0 - 191)
The "Moving Star Ship" program yo u've been working with so far will
serve as a good starting place to explore high-resolution graphics in AT ARI
BASIC. Start by changing line 110 to :
110' GRAPHICS 24
The significant variable in the SETCOLOR co mmand for this mode will
be the color register. Values of 2 and 4 affect the color. Make the color
register 4 in the SETCOLOR command in line 220:
220' SETCOLOR 4, H , 12
The PRINT statements and IF-THEN statements in the begi nning of the
program also need to be changed to allow for the larger number of columns
and rows available in this graphics mod e. Make lines 10 through 80:
/ \
ENTE R 0 - 299 FOR COLUMN
?
THE FINER POINTS OF GRAPHICS 133
Finall y, INPUT 250 for column and 154 for row and the entire figure
shows up aga in:
Play around with a few more values for row n ea r 154. You might find this
useful in making a figure appear to "ri se up out of" th e text window area.
Can you think of a way to do this usin g a FOR-NEXT loop to enter values
for X and Y? HINT: Th e FOR statement for th e Y shou ld start at about 170
and use the STEP- 1 fun ction. Th e loops for both X and Y sho uld begin after
line 120 and before line 130. and they should end som ew here after line 380.
134 ATARI SOUND AND GRAPHICS
In this chapter you h ave built the skeleton of one program and then made
several variations in that program to exp lore different parameters of the
SETCOLOR command and to learn a new graphics mode.
You've gained quite a bit of experience in the art of programming by
practicing the process of deleting lines , add ing others, and moving routines
from one place to another. As w ith anything new, this process may be
difficult at first, but as you continue to do it, you 'll get better at it.
Self-Test
2. What value for CR (color register) will enable you to change the color
of the background screen below?
110 GRAPHICS 19
120 COLOR 1
130 SET COLOR CR, 8,6,
5. The following program draws a square. How might you change it to let
the user move the square to different places using INPUT statements?
110 GRAPHICS 7
120 COLOR 1
130 SET COLOR 1,6, 10
210 PLOT 10,10
220 DRAWTO 20, 10
230 DRAWTO 20 , 20
240 DRAWTO 10,20
250 DRAWTO 10 , 10
6. What do you think will happen if the machine sees a value greater
than 139 in the following line?
7. What symbol do yo u think sho uld go after the letter X in line 100
below?
Answers
1. Hue
2. 4
3. The color luminance, which is the brightness of the color
4. Color luminance should have even numb ered values from 0 through
14 . The SETCOLOR command shown here has an odd number for
color luminance.
5. Something like this:
110 GRAPHICS 7
120 COLOR 1
130 SETCOLOR 1,6, 10
150 INPUT X
160 INPUT Y
210 PLOT X, Y
220 DRAWTO X + 10 , Y
230 DRAWTO X+10 , Y+10
240 DRAWTO X , Y + 10
250 DRAWTO X , Y
260 GOTO 150
In this program , the INPUT statements occur after line 130 , which will
leave the squares on the scree n. Otherwise it would draw it so fast that you
probably wouldn't see it , and then put the question mark bac k on the
screen.
6. It will print:
on th e screen.
7. The greater than symbol (»
8. With text window, 8
Without text window , 24
136 ATARI SOUND AND GRAPHICS
Challenges
Chance Music
and Graphics
RANDOM NUMBERS
If you've ever been to a raffl e where they put 100 tickets numbered from 1 to
100 in a box and someone reac hes in the box to pull out the ticket with the
vvinning number, then you've vvitnesseel the se lection of a random number
between 1 anel 100.
To generate a random numb er in AT ARI BASIC , us e th e RND function.
To see how it works, ENTER and RUN the following program:
137
138 ATARI SOUND AND GRAPHICS
0.2732238796
0.1437530517
0.8118743896
0.3042620539
0. _ _ __
0. _ _ __
0. _ _ __
0. _ _ __
The numbers you get on the screen won't be the same as the ones here,
because th ey are random (i. e., they are different every time) .
Notice that each number has a zero followed by a decimal point and lots
of other numbers. This is because it is choosing and printing random
numbers between zero and one.
Now change line 10 to:
ATARI BASIC's
/ multiplication sign
10' PRINT 10'*RND ( 1 )
8.569757631
4.36538696
7.41912841
3.74877929
0. _ __
9. _ __
2. _ __
3
7. _ __
CHANCE MUSIC AND GRAPHICS 139
RANDOM INTEGERS
For most exp eriments yo u 'll want to do, yo u won't n eed numb ers with all
that information after the decimal point. You 'll only n eed "w hole num-
bers," or integers like 8, 42, or 256,
To ha ve th e computer select random integers cha nge line 10 to:
8
7
3
4
4
9
5
3
6
9
1
4
8
5
2
This will generate a random integer betw een 100 and 200,
140 ATARI SOUND AND GRAPHICS
Suppose you want to generate random integers that are only intervals of
10. Here's how you ca n do it: Outs ide of
~ parenthesis
10 PRINT INT ( 10*RND ( 1) + 1) * 10
RANDOM NOTES
You can use random integers jLlst as yo u wou ld other variables. For exam-
ple, you might say: '
ENTER and RUN this program to hear a note random ly selected and
played, then another note , and so on.
The same thing can be accomp lished like this:
The advantage of this version is that now the value N can be used in other
ways. For example, here 's a program that continually enters different
random note values in each of the four voices:
ENTER and RUN the program to hear what it sounds like before we
describe it.
The first time through the FOR-NEXT loop for voice in lines 50 through
250, voice 0 is given a random value for note . This voice continues to play
that note until the remaining three voices have each been given a random
note value of their own and then played. The second time through the loop,
voice 1 is given a random note value , vvhich it plays.
When all four voices have been played, line 550 starts it over again and
voice 0 gets a new note. Each voice continues to play its note while the
other three voices are being assigned note values. Thus any given voice gets
a new note only every fourth time through the cycle. This is what creates
the kind of ongoing but ever-changing, chord-like sound you hear.
Now let's add some random graphics to the program . First add these lines:
10 GRAPHICS 23
20 COLOR 1
and:
We're putting the SETCOLOR command within the voice loop (lines 50
through 250) so you will be able to do an experiment with it a little later. For
the moment add these lines:
130 SETCOLOR 4 , 8 , 10
Rather than us trying to describe what happens , RUN the program to see
for yourself.
Lines 160 through 180 plot a point in a random column and row. Line
190 then draws a line from that point to a fixed point n ear the center of the
screen. If you let it RUN for a while, the pattern fills out quite a bit.
CHANCE MUSIC AND GRAPHICS 143
In the next section we'll build a new program , but we suggest you have
this one on your ATARI 410 Program Recorder or ATARI 810 Disk Drive
system.
144 ATARI SOUND AND GRAPHICS
The use of random elements in an artistic program raises one of the most
misunderstood concepts in the creative process. That is the concept of
improvisation or free form. It is often thought that improvisation means "no
form." On the contrary, a truly well-crafted improvisation is one that makes
use of a deeper understanding of form without obviously manifesting
structure. This is truly the essence of art.
We won't get into the question of whether or not a computer can impro-
vise, but the program below is an exa mpl e of how you can use the RND
function to create a piece with slight variations in form each time it runs.
The program draws a mountain range that always consists of twelve
mountains . The peaks of the mountains, however, are randomly placed,
and the base points from which the sides are drawn are also randomly
selected. To get started , ENTER and RUN this initial program :
After setting up the initial graphics mode and colors in lines 10 through
30 , the FOR-NEXT loop for "Mountain" establishes a cycle in which twelve
mountains are drawn. All other routines will be nested within this larger
loop .
CHANCE MUSIC AND GRAPH ICS 145
Lines 110 and 120 randomly se lec t values for the columns and row (A for
column and B for row) in which a given mountain peak is to be plotted. The
mountain peak is actually determin ed a bit later by line 320. Line 110
chooses from any of the 320 co lumns available, but line 120 limits th e
location of the mountain peaks to the upper part of the screen. The first part
of the RND function in that lin e picks an integer from 0 to 69, and then the
second part of the express ion adds 10 to give a value between 9 and 79 for
the row.
The FOR-NEXT loop in li nes 210 through 510 randomly plots points
from which twelve lines are drawn to the peak of each mountain. Again line
260 allows these base points to occur in any column , but line 270 limits the
row in which a base point is plotted to those from 39 through 139, an area
towards the bottom of the screen.
As the FOR-NEXT loop for "s ide" goes through its tw e lve cycles, twelve
randomly sel ec ted base points are plotted at line 310. Line 320 draws a line
from each of th ese points to the mountain's peak , se lected in lines 110 and
120. It is important that the mountain peak (point A,B) is selected before the
beginning of th e FOR-NEXT lo op for the sides. This is necessary to have
one point to which each of the sides is drawn (i. e., the peak point A,B).
Finall y, when this cycle is comp leted and one mountain with its twelve
sides is drawn , line 910 goes back for the "next mountain " beginning at line
50. Th is larger cycle also occurs t"velve times to draw a total of tw elve
mountains with t"velve sides.
Run this program several more tim es to see how it draws a slightly
different mountain range eac h tim e.
As you develop your programming ski ll s and strive for more and more
sophisticated programs, you must be aware of the time required for the
machine to make certain calculations and perform certain functions. To get
a sense of this , we wi ll add a sequence of notes to the program after each
mountain is drawn and then have you see w hat happens when yo u move
this sequence to within the lo op to draw the sides. Begin by making the
additions to the program shown below :
146 ATARI SOUND AND GRAPHICS
Now when you run the program, you should hear a rapid sequence of
notes played after each mountain is drawn . This sequence will be different
each time.
This routine randomly selects a note value between 1 and 5 at line 620
and then plays the note with a decay in lines 630 through 650. The
FOR-NEXT loop in lines 610 through 690 repeats this cycle a total of 50
times.
Run this program a few more times to fully absorb how it is functioning .
CHANCE MUSIC AND GRAPHICS 147
We can take advantage of the fact that in graphics mode 24 the SETCOLOR
command all ows us to change the hu e of the perimeter of the screen to
make an "e lectric fram e" for our picture in this program. This is done by
using color register 4 in th e SETCOLOR command , which allows changing
the hue of the screen perim eter and then creating a FOR-NEXT loop for hue.
This can be accomp lished with the following program :
CHANCE MUSIC AND GRAPHICS 149
EXPLOSION SOUNDS
Since the process of a mountain range evolvi ng is really a verY 'stormy one
with many volcanic eruptions and such, let's add some explosion sounds
to the program. Make th e chan ges in the program as follows:
Now RUN the program. Occasionall y it shou ld stop after it has drawn a
mountain and create an explosion-type sound. If you RUN the program a
few times, you'll notice that this explosion occurs at different places in the
sequences of mountains being drawn and that the exp losion sounds a little
different each time.
Line 710 picks a random value between 1 and 3 for "EXPL." The IF-THEN
statement in line 720 says if EXPL equals 1 , then go down and exec ute the
explosion subroutine at line 2010. If the random va lu e chosen for EXPL is 2
or 3, then it goes on to line 910 with no explosion before it draws the next
mountain.
Whenever th e "explosion " subroutine is activated, line 2010 randomly
selects a value between 1 and 10 and th en multiplies this integer by 10 to
give N a random value of 10 , 20 , 30 , ... up to 100.
An explosion sound is actually a very complex wav e form often called
white noise in psycho-acoustics. This can be approximated as we have
done here by using a value of 0 for th e tone parameter , and playing note
values very close to eac h other with voices 0, 1 , and 2 (lines 2030 through
2(50) while voice 3 plays a note one octave high er than voice 0 (line 2(60).
The addition to the decay cycles (li nes 2020 through 2(90) with the slight
pause at each loudness (lines 2070 and 2(80) creates the loud percussive
beginning with an explosion that decreases in vo lum e.
The purpose of choosing different values for line 2010 is to give each
explosion a slightly varied effect. This would naturally occur if you were
located in one place and exp losions were happening around at different
distances and coming from different directions.
152 ATARI SOUND AND GRAPHICS
For a final addition to our program let's make use of the technique we
learned in the last chapter to move th e same figure from one place to
another on the screen. We 'll hav e a UFO fly across the bottom of the screen .
154 ATAR I SOUND AND GRAPH ICS
The UFO:
RUN the program with th ese lines added , and you should see the figure
move across the bottom of th e screen with a high note played and the
perimeter of th e screen changing each tim e th e figur e appears .
The FOR-NEXT loop in lin es 1010 establi shes p lot points for column (Al
at 10,13 , 16 , etc ., across th e scree n to column 300. The value for row (Bl is
constant at row 170.
Lines 1030 and 1040 enter COLOR 1 and then execute the subroutine to
draw the figure. Lines 1050 and 1060 erase the figure . After the figure has
been drawn and erased, a random note is played . Then the cycle begins
aga in. The value of COLOR 1 in line 1030 isn 't really necessary the first
CHANCE MUSIC AND GRAPHICS 155
- -- - -- - - - -- -- -- - - - - - - - - - - -- ._ - -
tim e through the cycle si nce it has been entered in line 20. However, once
the machine has used COLOR 0 at line 1050, it wi ll stay in COLOR 0 until it
is given another va lu e for co lor. So li ne 1030 becomes important after the
first time thro ugh the cycle.
Lin e 4010 of the " Draws UFO " subroutine is th e one that causes the
perimeter of the screen to change co lors. We've us ed an RND func tion to
choose one of the sixteen possible va lu es for hu e each tim e the subroutine
is executed .
Here's the com pl ete listing of the program:
10 GRA PHI CS 24
20 CO LOR 1
30 SETCOLOR 0 , 10 , 10
In this chapter you have learned several ways to use RND functions to
create varations in the sound and graphics of a program. Although th e two
programs in this chapter might be cons idered "fine art" (th at is they have no
particular purpose other than to be enjoyed), the techniques can just as
easily be us ed in "functional" programs, such as ed ucational aids or games.
CHANCE MUSIC AND GRAPH ICS 157
We'll make use of these tec hniques and others in the coming chapters to
create a pitch-matching game.
Heraclitus , the ancient Greek philosopher, was believed to hav e once
said:
Self-Test
10 PRINT 20*RND ( 1 )
20 GO TO 10
10 GRAPHICS 19
20 CO LOR 1
30 SETCOLOR 0,8, 10
130 PLOT A, B
140 GO TO 10
158 ATAR I SOUND AND GRAPH ICS
7. How would you change line 710 of the final program in this chapter to
make it equally likely that the explosion will or will not occur?
8. Change line 1020 of the final program from this chapter so that it picks
from all of the 256 possible note values.
Answers
1. From 0 through 19
2. Make line 10:
3. Line 10 becomes :
6. Low notes
7. Make line 710 :
Challenges
1. Change line 1020 so that the fi gure stays in th e bottom area of the
screen but moves up and dovm instead of going straight across . HINT:
You need to randoml y select values for rows between about 150 and
180.
2. Add some blinking stars to the picture.
CHAPTER NINE
String Variables
As you'v e been exp loring and learning aboll t your ATARI 400 or S00
Computer, you've made frequent use of INPUT statements to enter num eric
variables . You 've also learn ed to have th e comp uter compare different
numeric values and respond according to condition s yo u establish with
IF-THEN statements.
In this chapter we w ill look at ways to wo rk with strin g variables. This
will allow you to have the comp uter res pond to words and letters as
variables also. As yo u w ill see a bit la ter in th e chapter, thi s w ill be va luab le
when working with musical notes th at are usually defined by letters like C
or F#.
STRINGS
Although yo u may not have seen th e term before, yo u have already worked
w ith strings quite a bit in some of th e programs yo u' ve been using. Often
when you 've u sed a PRINT sta temen t, yo u have actuall y had the machine
print a string. For examp le:
In this case the strin g includes both a letter and a numb er.
160
STR ING VAR IABLES 161
Combinations of th ese are also appropriate as strings. For examp le, the
following are all strings:
C#
C MAJOR 7
F# MINOR
C2
Since the quotation marks are not part of the string, you can 't use them in
the string. For example , if you try to say:
String Variables
In ATARI BASIC the sym bol for a string variable is a letter of the alphabet
followed by a dollar sign ($). You might use someth in g like:
A$
Z$
P$
Before you use a string variab le , you must tell the comp uter how long the
string might be. That is , you must reserve a place in the computer's memory
to put the string wh il e it is wa iting to be used . This is done with a
DIMension statement. For examp le , th e following DIM statement tells th e
computer to make room for a string of up to five characters in length.
10 DIM A$ (5)
/
Dimens ion
t
String
~
Of fi ve ch aracters
162 ATARI SOUND AND GRAPHICS
To see the string A$ used as a variable, ENTER and RUN the following
program:
10 DIM A$ (5)
110 A$= "MUSIC"
120 PRINT A$
130 GO TO 120
MUSIC
MUSIC
MUS IC
MUSIC
MUSIC
MUS IC
MUSIC
MUSIC
MUSIC
MUSIC
MUSIC
MUS IC
MUSIC
10 DIM A$ ( 10)
10 DIM A$(4)
STRING VARIABLES 163
it would print:
MUSI
MUSI
MUSI
MUSI
MUSI
MUSI
MUSI
MUSI
MUSI
MUSI
MUSI
MUSI
MUSI
10 DIM A$(2)
10 DIM B$ (9)
110 B$= "NEW MUSIC"
120 PRINT B$
130 GO TO 120
10 DIM B$(4)
AZ$
PD$
164 ATARI SOUND AND GRAPHICS
A1$
G4$
but if you try to u se the symbol s at the top of the keyboard such as:
A%$
A#Z$
you'll get an ERROR message. Don 't get co nfus ed here between the symbol
for the string variabl e and the ac tual information in the string. For example :
I
10 DIM A#B$ ( 10 )
20 A#B$="MUSIC"
---~
10 DIM A$ ( 10)
20 A$= "MU SIC #4"
~
STR ING VAR IABLES 165
You can use strings as variables in many of the same ways that you've been
using numerals as variables in other programs. The following program uses
the string Z$ with an INPUT statement , an IF-THEN statement , and a
PRINT statement:
ENTER and RUN this program . After the instructions appear on the
screen, type either the word MUSIC or something else and press RETURN.
166 ATARI SOUND AND GRAPHICS
Line 490 goes back to line 110 where it prints two blank spaces and then
the instructions again.
Explorations
1. Could Z$ be dimension ed for fewer characters in line 10 and have the
program run the same?
2. Add a line at 520 to have the computer PRINT Z$ .
Answers
10 DIM Z$( 5)
520 PRINT Z$
You can use more than one string in a program, but you must be sure to
dimension each string you use . Here's an example of a program that has two
strings, A$ and B$:
STRING VARIABLES 167
95
REM *** OLD AND NEW
1 REM *** MUZIO CLEMENTI
2 REM *** HERB MOORE
Dimensions each - - - - - . 10' DIM A$ ( 10')
string 2(0 DIM B$ ( 1(0)
I
Randomly se lects 65(0 SOUND (0, N, 1(0 , 1(0
and pla ys notes for - - - 66(0 FOR P = 1 TO 15
new musi c 6795 NEXT P
68(0 NEXT CYCLE
69(0 GO TO 210
168 ATARI SOUND AND GRAPHICS
ENTER and RUN this program and you hear the computer randomly
choose between a theme by the Italian composer Muzio Clementi (1752-
1832) and some modern sounds. When it plays Clementi, it prints OLD
MUSIC on the screen; when it plays the modern theme , it prints NEW
MUSIC on the screen .
FANCY PRINTING
Since we've been using graphics mod es 3 through 8 so far, yo u may have
wondered about graphics modes 1 and 2. These modes are text mod es that
allow you to print information on the screen with fancy , colorful letters.
They will print information in the text window that is just like the text in
other graphics modes, but if you want to use big, co lorful letters in the
graphics display area, you must use a device numb er.
Many of the pieces of equipment associated with your ATARI Computer
are called input/output devices (sometimes abbrev iated I/O) . As th e name
would imply, th ey let you INPUT information to the comp uter and/or
OUTPUT information from the computer. The keyboard with which you
enter information into the computer's memory is an input device. The
AT ARI 400 Cassette Recorder and the AT ARI 800 Disk Drive system are
input/output devices. The TV monitor is also an input/output device.
It is not within th e scope of this book to give a detailed description of the
ATARI Computer 's hardware, but it is valuable to know that each of these
devices has a device number that must be used in certain operations.
In order to print in th e graphics display area in modes 1 or 2, the PRINT
statement must take the following form:
10' GR. 1
20' COLOR 1
110' PRINT #6; "NEW MUSIC"
ENTER and RUN th e following program to see what the fancy printing
looks like in graphics mod e 1:
10' GRAPHI CS 1
20' COLOR 1
30' SET COLOR 0' ,8,8
MLJS I c:
I ~EADY
10' GR. 2
I~EADY
If you think of each letter takin g up one plot poi nt, the word MUSIC
appears in columns 0 through 4 and in row 1. The number of columns and
rows avai lab le in graphics modes 1 and 2 is:
170 ATARI SOUND AND GRAPHI CS
l~ GRAPHICS 2
2~ COLOR 1
3~ SETCOLOR ~, 8, 8
GRAPHICS 1 + 16 or GRAPHICS 17
GRAPHICS 2 + 16 or GRAPHICS 18
In the "Old and New " program from earlier in this chapter, we printed
spaces between lines by adding PRINT statements with no strings, as in
lines 510 and 515 . AT ARI BASIC also has a command that allows you to
place text at different lo cations on the screen; it is the POSITION command.
If you wish to center th e strin gs "NEW" and "MUSIC " on the screen, you
can use the POSITION command like this:
RUN the program and the screen should look like this:
NEW
MUSI c:::
Lin e 110 tells the computer to begin the string "NEW" at co lum n 7 and
row 3.
Line 130 te lls it to beg in the string "MUSIC" at co lu mn 6 and row 5.
- - - - - - - --- ---
172 ATARI SOUND AND GRAPHICS
Explorations
See if you can create this on the screen:
MUSIC
OLD AND NEW
MU51C
Now let's go back to the "Old and New" program we were u sing earlier in
this chapter and instead of printing OLD MUSIC or NEW MUSIC in normal
text as it plays th e sounds like thi s:
NEW MUSIC
OLD MUSIC
OLD MUSIC
NEW MUSIC
OLD MUSIC
STRING VARIABLES 173
we 'll have it print either OLD MUSIC or NEW MUSIC in big letters in the
center of the screen like this:
OLD MUSIC
174 ATARI SOUND AND GRAPHICS
First look at the version of the program that prints in normal text:
30' GRAPHICS 18
40' COLOR 1
60' H= INT ( 16*RND ( 1 ) )
70' SETCOLOR 4, H , 4
610' POSITION 5 , 4
620' PRINT #6 ; B$
Since we're using the POSITION command to place the text on the
screen, we no longer need the PRINT statements at lines 515 and 615 which
had been used originally to print blank lines in the text. Delete lines 515
and 615.
Finally we want to get rid of the previous text on the screen each time
another passage of music is played. This can be done by changing lines 590
and 690 to:
In this way, once the machine has finished playing either passage , " Old"
or "New," it will go back to line 30 and enter graphics mode 18 again . Any
time you enter a new graphics mode , what was previously on the screen
will be erased.
176 ATARI SOUND AND GRAPHICS
Explorations
Instead of printing OLD MUSIC or NEW MUSIC , have the computer print
CLEMENTI or RANDOM NOTES each time it plays a passage.
HINT: You need to change lines 110 and 120.
The string RANDOM NOTES is a little longer than the other string in the
program. Change the POSITION statement in line 610 to center this string.
Now RUN the program and when the instructions appear in the text
window, type C, D, or E and press RETURN.
Instruct ions
I TYPE C, D, OR E
~~D PRESS RETURN
STR ING VARIABLES 179
Let's say you type th e letter D. Here's what should happen. The text
window changes to:
I THIS IS TH E NOTE
b~U HAVE ENTERED
RUN this program a few more times to m ake sure everything is working
as it should , and then we 'll make some additions.
50 GOSUB 1010
STRING VARIABLES 181
RUN this program now, and you should get this on the screen.
I TYPE C, 0 OR E
~~D PRESS RETURN
Otherwise it will operate the same as it did before. We'll add some lines
to plot the notes soon , but first let 's look carefully at how the staff was
drawn.
Putting the GOSUB statement at line 50 causes the subroutine to draw the
staff to be executed immediately after the graphics mode and color com-
mand have been executed .
We've used a FOR-NEXT loop for ROW. The first time through the lo op,
it plots a point at column 10, row 36 at line 1010. Then at line 1020 it draws
a line to column 140, row 36 . That's the top line of the staff. The second
time through the loop , it draws a line from column 10 to column 140 at row
42. This continues until all five staff lines are drawn. The RETURN state-
ment at line 1050 causes the program to pick up at line 110. From there it
operates the same as it did before this subroutine was added.
Make sure you have this listing before go ing on.
182 ATARI SOUND AND GRAPHICS
41(.3' N= 1(.3'8
43(.3' GOSUB 2(.3'10'
44(.3' GO TO 11(.3'
As you can see, we 've made the values of both column and row variables.
We want to plot in different rows dep ending upon the note played. This
will determine on which staff line a note appears. But we want to plot the
notes at equal distances from each other going from left to right across the
staff. Let's start with column 15 and put notes at columns 15, 25, 35, . . . 125.
This can be done with a FOR-NEXT lo op for COL at lines 80 and 890. Add
these lines:
and:
Since the value for ROW wi ll vary depending on the note played, it
should be entered in the main body of the program. The block for each note
played w ill have a different value for ROW. The note C presents some
additional considerations, so we'll look at D first.
The note "D" should appear just below the bottom line of the staff. Row
63 is the appropriate row to use, so add line 420:
420 ROW=63
The appropriate ROW for E is row 60, which is right on the bottom line of
the staff. Add line 470:
470 ROW=60
Now when the block for a particular note is executed, for example, line
410 through 440 for the note D, we don't want the machine to go directly
back to line 110. Instead we want it to finish the FOR-NEXT loop for COL at
line 810 . So change line 440 and 470 to:
We're still ignoring the block for C, but we'll get to it soon.
STR ING VARIABLES 185
- - - - - - - - - - - - - - - - - - - ---- - - - - - --- - ---- ---- ----
100IMA$(5)
20 GRAPHICS 7
30 COLOR 1
4 0 SE T COLOR 4 , 11, 12
50 GOSUB 1010
Puts note on bottom 800 REM *** MOVES NOTE ACROSS STAFF
staff lin e 810 NEXT CO L
186 ATARI SOUND AND GRAPHICS
o o o o
ITYPE C, 0, ORE
?~D PRESS RETURN
As you enter each new note, it app ears at the appropriate line of the staff
and to the right of the previous note.
The correct position on the music staff of the note middle C is shown
below:
o
partial/"
line ' " Middl e C
It appears one line below the bottom line of the staff and is generally
shown with a partial line as it has above . So when we plot the note middle
C, we want to include this partial line. This can be done by adding the
following lines:
360 GO TO 810
before middle C is played and the FOR-NEXT loop for COL is over to
column 55, for examp le, here 's what happens. Line 320 and 330 plot and
draw this:
COL - 1 66
PLOT 54, 66 55 - 1 66
DRAWTO 62, 66 55 + 7 66
Make sure you've added lines 320, 330, and 360 as shown above and
RUN the program. You'll now be able to ENTER C, D, or E and have the note
appear on the correct staff lin e whi le it plays.
One further addition can be made to improve this program. After you've
entered twelve notes , the staff will be full and the FOR-NEXT loop for COL
will be finished. It would be nice to have it erase the notes and start over .
Easily done. First renumber lines 800 and 810 so they become:
8(0(0 REM * * *
810 IF COL = 125 THEN 2(0
With th ese lines added , each time a note is played it checks the va lu e of
COL before going on to line 830 for the n ex t co lumn. When it gets to column
125, line 810 goes back and enters the graph ics mode again, thus erasing
everything and starting over.
You may have already noticed this , but if you try to enter another note
while one is playing, the computer may get a little confused and go to the
invalid choice subroutine in lin e 910. If this happens, just wait until the
instru ction appears in the text window and you can carryon.
STRING VAR IABLES 189
10 DIM A$ (5)
20 GRAPHIC S 7
30 COLOR 1
40 SETCOLOR 4, 11 , 12
50 GOSUB 1010
990 GO TO 110
1000 REM *** DRAWS MUSIC STAFF
1010 FOR ROW = 36 TO 60 STEP 6
1020 PLOT 10, ROW
1030 DRAWTO 140, ROW
1040 NEXT ROW
1050 RETURN
0 0
0 0
0 0
-4- 0
Middle C D E F G A B C' - One octave above
middle C
Self-Test
l. What is the minimum value that can be placed in the parentheses for
this program to work?
10DIMA$( )
20A$= "SOUND SCULPTURE"
30PRINT "SOUND SCULPTURE"
40GOTO 30
10 DIM Z$ ( 100)
20 INPUT Z$
30 PRINT Z$
40 PRINT Z$
10 DIM H$(5)
20 H$ = "SOUND SCULPTURE"
30 PRINT H$
192 ATARI SOUND AND GRAPHICS
4. What must be added to this program to have the text in lines 110 and
120 appear in the graphics display area of the screen?
10 GRAPHICS 2
20 COLOR 1
30 SETCOLOR 0,8,6
100 REM ***
110 PRINT" AUDITORY"
120 PRINT "TICKLE"
130 GOTO 130
5. In the program above, what command might you add to position the
text in the center of the screen?
6. In the "Note Practice" program from this chapter, if yo u type H, will a
note value be entered?
7. If you enter D in the "Note Practice" program, which value for N wil l
be used in the sound statement at line 3020?
8. In the same program , if you type "SOUNDS GOOD ," what will be
printed at line 920?
Answers
1. 15
2. It allows you to enter a string of up to 100 characters , and then it prints
that string twice.
3. It prints the word SOUND since the string H$ is only dimensioned for
five characters.
4. Lines 110 and 120 must become:
Challenges
1. Add a title to this program using fancy letters in the graphics display.
2. Complete the blocks for the rest of the notes in the C major scale as
described at the end of the chapter.
CHAPTER TEN
SUBSCRIPTED VARIABLES
N(0) 12 1
N( 1) 96
N(2) 81
N(3) 64
193
194 ATARI SOUND AND GRAPHICS
N(0) 12 1
N(l) 96
N(2) 81
N( 3) 64
N(4)
t - - -- . - ---I
N(5)
t - -- - -- - - I
N(6)
r---------j
N(7) L -_ _ _ _ _ ~
Using the note ch art from Chapter 1 , add four more note values to this
array to get an idea of th e process by w hi ch numbers are assigned to
subscripted variables.
In Chapter 9 yo u learned that it is n ecessary to use a DIM statement to
reserve space in th e comp uter's memory for th e strings th at were ass igned
to string variables. In a similar fashion , you must dimension arrays for the
maximum numb er of va lu es to be entered as su bscripted variables.
For the array of four note values we used as our original exampl e, yo u
would use a DIM state ment like this:
l~ DIM N (3)
Variable for w hi ch /' Maximum
space is being _ _ _-' ~ subscripl lo be
reserved per mill ed
l~ DIM N ( l~ )
l~ DIM N( 2)
l~ DIM ( ?)
WATCH THE MUSIC PLAY 195
N(5)~
N(6)
N(7)
N(8)
1. DIM(7 )
2. DIM (8)
No matter how man y sub scripted variab les are being used , you must
dimension for the maximum subscript to be permitted.
Once yo u 've dimension ed the su bscrip t, you can u se several different ways
to store values for the subscripted variabl es in th e array. Here's the long
way of using subscripted va riabl es to play th e notes of the C major scale .
Rather than spending a lo t of tim e typing thi s, ju st study it carefull y:
Lines 200 throu gh 240 of thi s program are the same as in th e previous
program listing. Their operati on has alread y been described .
Lines 110 thro ugh 180, however, have bee n rep lace d with a loo p that
reads note valu es from the DATA statement in lines 410 and 420.
The FOR-NEXT loop in lines 110 throu gh 170 assigns va lues of 1 through
8 to the subscript E in line 160 . At th e same tim e th e READ statement in line
120 gives N a note va lu e from th e DATA sta tements in lines 410 and 420.
The fi rst time through the loo p E is given a va lu e of 1 and N is given a value
of 121. In line 160 we get :
160N(E )= N
Says .. 160N(1 )= 12 1
WATCH THE MUSIC PLAY Hl7
----------- --------------------------------------------------
The second time through the loop:
160N(E)=N
160 N (2) = 108
160N(E)=N
160N(3)=96
In the same way that we 've just demonstrated, show what values wil l be
assigned to E and N in line 160 on the fifth and seventh time through the
loop.
The fifth time through the loop:
160N(E)=N
160 N( 5) =81
160N(E)=N
160N(7)=64
If you wish to play onl y a part of the scale, you can make line 210
something like:
210 FOR E= 1 TO 5
which would play the first five notes. Or to play notes from the middle of
the scale, line 210 might be:
Which note values do you think this version of line 210 will play?
96 , 91 , 81 , and 72
You can use the STEP function to skip notes and go either up or down the
scale . For example, make line 210 :
We' ve also changed the REM statement in line 200 to better describe what is
happening with the new line 210:
Lines 260 through 290 wi ll co m e back down the sca le. Rep lac e the two
ques tion marks with the correct note values :
If you 'd like to h ear the co m p uter make an attempt at something a little
more musi cal than simply go ing up and down the scale, rep lace lines 200
through 290 of the previo us program \,vith:
1~ DIM N (8)
1~~ REM *** READS NO TE VA LUES
ll~ FOR E= 1 TO 8
12~ READ N
Line 210 randomly chooses a value for th e subscript E. For the sake of
illustration, let's say it picked the number 5. The subscripted variable in
line 230 then becomes N(5). Since the READ and DATA statements have
given N(5) a value of 81, note value 81 will be played in the sound
statement.
Line 220 picks a random number from 1 to 4 and then multiplies that
number by 20 to give DUR possible values of 20, 40 , 60, or 80. Using the
variable DUR in the pause loop in line 240 results in one of these values for
the duration of the note. Keep this program because we'll add to it in a
moment.
Any time you go from one note to another in a musi cal scale, you are
playing an interval. For examp le, from D to E is an interval. Each interval
has a name derived from how far you move within the scale. You name an
interval by counting how many notes you jump up or down th e scale.
Include the note you start with and the note you finish with. For example:
C Major Scale
C. D , E, F, G, A, B, C
Jump From Interval Name
goin g up D to E seco nd
going up E to G thircl
going up F to G seconcl
going clown G to D fourth
going clow n B to F fourth
going up D to A fifth
goin g clown G to E third
The interval from any note to the note with th e same name going either
up or down is an octave ofthat note. From middle C to the next high est C is
an octave. If you start with D and go up or down to th e next D, then you are
playing the octave of D.
Fill in the names of the following intervals:
goin g up C to G
goin g down A to F
goin g up C to B
goin g clow n B to D
fifth
third
seventh
sixth
WATCH THE MUS IC PLAY 201
210 E=INT(6*RND(1) + 1)
10 DIM N( 10)
100 REM *** READS NOTE VALUES
110 FOR E = 1 TO 8
120 READ N
RUN the program to hear the computer 's idea of music for around the
campfire.
Line 210 picks a subscript from 1 to 6 that is used in line 230. It was
necessary to reduce the choices for Eta 1 through 6 since in lines 250 and
270 we are using subscripts of E -I- 2.
If the subscript 4 is chosen at line 2Hl and then at lines 250 and 270, note
value 72 (A, which is a third above F) is played.
If it picks 2 for the subscript E, you ' ll hear note values 108 and 91; that 's
the third D and F. Lines 260 and 280 give each note a random duration.
What note values are played in line 250 if the subscript E is:
Subscript E N o te Valu e
4
6
3
5
72
60
81
64
If you want someone who Llses the program to be able to specify the note
sequence and the duration of the notes , you can Llse an INPUT statement.
ENTER and RUN the following program to see an example of how an
INPUT statement can be used to assign values to subscripted variables:
10DIMN(10)
170N(E)=N
190 NEXT E
Each time through the loop in lin es 110 through 190 these instructions
will appear on the screen:
The first time through th e loop , th e not e value that is entered will be
assigned to N(l). For exampl e, s uppo se yo u enter 108. Here's what happens
at line 170:
170 N ( 1) = 108
Let's say the next time the instruction appears you type 91. This time
line 170 becomes:
170N(2)=91
This will happen eight times before the melody is played, so, if you
haven't done it already , add six more note values of your own choice .
After you've entered a total of eight note val ues , th e program continues at
line 210, which begins a loop to pla y the eight not es . Lin e 220 establishes a
randomly chosen duration for each note.
RUN this program again and ENTER a sequ ence of notes using several
thirds. For example :
C E G F A C G B
121 96 81 91 72 60 81 64
[ 1 [1 [1 l 1 [1 [1 l1
3rd 3rd 2nd 3rd 3rd 4th 3rd
Explorations
Make up some sequences of mostly thirds for yourse lf.
Try a sequence of mostly fifths.
Try one of mostly fourths.
Mix thirds, fourths, and fifths.
If you want to be able to ent er more notes, you can change lines 110 and
210 something like this:
110 FOR E = 1 TO 16
210 FOR E = 1 TO 16
10 DIM N( 16)
10 DIM N (10)
170N(E) = N
190 NEXT E
Now add:
1(ODIMN(l(O )
2(0 DIM DUR ( 1(0 )
Now when you run th e program , yo u 'll have the opportunity to enter a
note valu e and a duration for each note. For examp le, suppose the first time
through the loop you ENTER 96 for the note va lu e when the instruction:
ENTER DURATION
At line 17!il, a value of 96 is assigned to N(l), and at line 18!il a value of l!il!il
is assigned to DUR(l).
170 N ( E) =OUR
becomes:
170 N ( 1) =96
and:
becomes:
Suppose the next time through the loop you enter 6!il for the note value
and 5!il for the duration. What will happen at line 17!il and 18!il?
170N(E) =N
becomes:
170 ?
and:
becomes:
180 ?
We'll leave it to you to compose melodies you like with this program.
Remember you can increase the maximum value of the subscript in the DIM
statement in lines l!il and 2!il and then make the 8 in lines ll!il and 12!il a
larger number if you want to play more notes.
WATCH THE MUSIC PLAY 207
10 DIM N(8)
20 DIM A$ (5)
ENTER and RUN thi s program and type C, D, or E each time the question
mark and the cursor appear on the screen.
7.
After you ENTER eight notes , the computer will play them back for you.
208 ATARI SOUND AND GRAPHICS
310N(Z)=N
becom es:
31(a'N(1)=1(a'8
31(a'N(2)=121
Using the not e chart from Chapter 1 , add IF-THEN statements at line 240
through 280 that w ill allow you to ENTER th e notes F, G, A, B, and th e
octave G 1 when the program is over.
WATCH THE MUSIC PLAY 209
-------------------------------------
The program listing will look like this:
10 DIM N( 8)
20DIMA$(5)
1 270
280
IF' A$= "B" THEN N=64
IF' A$= "C1" THEN N=60
Now RUN the program and make up some note sequences from all eight
notes.
210 ATARI SOUND AND GRAPHICS
In Chapter 9 you learned how to have each note play and appear on the
music staff immediately after it was en tered . The following program uses
many of the same con cep ts . But this time, as th e letter for eac h note is
typed, the note value for that letter is assigned to a subscripted variable and
stored in an array. You are also able to determine the duration of each note.
After ten notes, each with a specific duration , have been entered, the entire
melody is played and shown on th e staff as it plays. This will repeat until
you stop th e run. Then you can ENTER another melody .
This may seem like a fair amount of typing, but it will be valuable to you
to take the time to ENTER this program , both for th e sake of your computer
education as well as the fun of making your own melody.
/ 235
240
245
IF A$="A" THEN 360
IF A$= "B" THEN 370
IF A$ = "Cl" THEN 380
\
Gi ves letter a note
290 GOTO 910
va lu e and a ro w
300 REM * * * VALUES FOR NOTE AND ROW
",'"' 310 N= 121: ROW=66
3 15 GOTO 510
320 N= 108: ROW=63
325 GO TO 510
330 N= 96: ROW = 60
335 GOTO 510
340 N= 91: ROW=57
345 GOTO 510
Assigns duratiOl1
to subscrI pled
va ri ab le
r 56rt REM *** ASSIGN DURATION
'P
570 INPUT DUR
580 DUR (Z) = DUR*25
590 NEXT Z
212 ATARI SOUND AND GRAPHICS
510N(Z)=N
becomes :
510N(1)=91
and:
becomes
Then the instructions to type a number for duration appear in the text
window. Suppose you type a 3 here. Line 570 becomes:
or :
Finally, line 580 goes back and picks the next subscript. To check your
understanding of this program , answer the following questions:
1. If the second time through the loop in lines 110 through 490
you type "B", which IF-THEN statement will find a match
and branch to another line'?
2. After N and ROW have been given numeric values at line 370,
what will happen at line 510 and 520?
3. If you type 4 for the duration when the instructions appear ,
what will be the value of DUR(2) in line 570?
214 ATARI SOUND AND GRAPHICS
Once you've entered ten notes , w ith a duration for each one , the entire
sequence is played by the loop from 610 to 710.
Since we ha ve entered "F" for N(l), th e SOUND statement in line 610
will playa note value of 91 the first time through the loop. At line 630 COL
is given a value multiplying 12 times the subscript Z, in this case:
12 * 1 = 12
Row (1) has already been given the value 57 at line 340 . Since N(l) does
not equal 121, line 650 will be ignored. Line 660 goes down to the sub-
routine at line 2020, which draws the note at co lumn 12 , row 57. It returns
to line 660, which goes back to lin e 610 and picks the next value for the
subscript Z; that is (2). Again , to check your und erstanding, answer these
qu estions:
Remember that middle C requires a line below the staff. Suppose on the
third time through the loop you type "C" for the note. In this case, N is given
a value of 121 and N(3 ) becomes 121 in line 510. Then when the loop to
-play the notes is being executed in lin es 610 through 680, the conditions of
the IF-THEN decision in line 650 will be met. That is , N(3) does equal 121 ,
so the program branches to line 710 and executes the routine to draw a line
below the staff. It then goes back to line 660 and continues as before.
If you type some letter other than C through C' for the note, none of the
conditions in the IF-THEN statements in lines 210 through 245 will be met.
Thus 290 will branch the program to lin e 910 and exec ute the "Incorrect
Letter" routine there. It then goes back to line 120 and lets yo u try again.
Line 610 begins the loop to play the notes. On ce all ten notes have
played , line 710 executes the subroutine to enter th e graphics mode, again
WATCH THE MUSIC PLAY 215
drawing the staff and thereby erasing everything els e on the screen. When
the comp uter returns to line 610, it repeats the melody and the notes.
In this chapter, you have learned to assign values for notes and plot
points to a group of subscripted variables, called an array. The subscripted
variab les can then be used to p lay different sequ ences of notes and draw
them on the music staff. This is just one examp le of how an array of
subscripted variables might be used. Anot her possible u se is suggested in
the challenges at the end of th e Self-Test this chapter.
If you've worked your way carefully through this book, you have un-
doubtedly begun to realize th e enormous potential of your ATARI 400 or
800 Computer as an artistic and musical instrument. We hope you will find
yourself returning to the pages of this book again and again for ideas you
can expand upon in your own way.
Artistic programming, like many things, is something you can enjoy
more as you get better. And of course, the better yo u get, th e more you'll
enjoy.
Self-Test
2. As the note va lu es are being read from the DATA statements in the
above program , what va lu e ,,\Till be assigned to the subs cripted vari-
able N(4) in line 160?
216 ATARI SOUND AND GRAPHICS
3. Add another FOR-NEXT loop at lines 260 through 290 to play note
values:
in that order.
4. If rath er than reading the note values into the array, you wish the user
to be able to enter val ues for eac h subscripted variables, you can drop
lines 400 through 420 , and change line 120 to:
120______________
210----__________
10 DIM N (10)
20 DIM DUR( 10)
7. If you wish to enter and p lay sixteen notes in the following program,
YO ll must change thre e lines. What changes must you make?
10DIMN(8)
20 DIM A$ (5)
8. If when the program abo ve is run, you type the letter " D" for th e first
note and the letter " F" for the second note , what musical interva l ha ve
YOll p layed?
Answers
1. Line 10 becomes:
10' DIM N (8 )
4. INPUT N
210 E = INT(8*RND( 1) + 1 )
10'0IMN (16)
110' FOR Z = 1 TO 16
410' FOR Z = 1 TO 16
8. A third
Challenges
1. Here are the note values and row positions of four more notes in the
next octave of th e C major sca le. Cont inu e the pattern establ ished in
lines 2 10 through 385 to ass ign the va lu es for note and row to sub-
scripted variables. Th e n RUN th e program and enjoy a wider range of
notes from which to make yo ur melody.
DI EI FI Gl
Note 53 47 45 4Vl
Va lu e
Row 42 39 33
Va lue
2. Look at Chapter 5 and see if you can think of some int eres ting ways to
c hange the s ha pe of the notes as th ey are p layed.
3. Draw a mountain range s imil ar to the one in Chapter 8 using an array
of subscrip ted variab les for the mountain peaks.
APPENDIX A
Here are a few program listings that make u se of concepts you have learned
in this book. Some of them might be us eful to yo u as subroutines in larger
programs you are writing. We encourage you to vary diHerent parameters in
eac h of these programs and to write other programs that expand upon these
ideas.
You know best what you \lvant to see and hear and if yo u persist, you'll
probably be able to make it happ en!
This program randoml y picks an d pla ys a note va lu e from 25 to 250. Try
it with 25 notes from elsewhere in th e note s pec trum. (See Chapter 8.)
219
220 ATARI SOUND AND GRAPHICS
If this routine doesn 't give you just the right sound for your space game ,
play around with the va lu es for N, L, and STEP in lines 110 and 120. Don't
forget to us e INPUT statements to make it easy on yourself. (See Chapter 5.)
50 INPUT N
100 REM ** PHASE SHIFT
120 SOUND 0, N , 10, 10
130 SOUND 1, N + 1, 10, 10
140 SOUND 2, N/2 , 10 , 10
150 SOUND 3, N/2 + 1 ,10,10
210 GOTO 2 10
To hear an interesting sequence of " beats," ENTER and RUN this prog-
ram, which is sim il ar to the one above but enters the values for N with a
FOR-NEXT loop. Can yo u think of a way to use the same concept w ith
READ and DATA statements to ENTER th e note values? Hm<\' about with
subscripted variables in an array'?
Here's another program that's fun to watch being drawn as it fills the
screen with little diamonds. Some interesting variations can be created by
making changes in the STEP functions in lines 110 and 120. Also try
different figures in lines 210 through 320.
If you like the "echo effect " often used by John Lennon in his recordings ,
you'll probably appreciate th e sound made by this program. By briefly
turning the voice on and off in lines 210 through 240, just before the decay
loop starts, an echo is created.
High notes C 29
B 31
A# or Bb 33
A 35
G# or Ab 37
G 40
F# or cb 42
F 45
E 47
D# or Eb 50
D 53
C# or Db 57
C 60
B 64
A# or Bb 68
A 72
G# or Ab 76
G 81
F# o r cb 85
F 91
E 96
D# or Eb 102
D 108
C# or Db 11 4
M id d le C C 12 1
B 128
A# or Bb 136
A 144
G# or Ab 153
G 162
F# or C b 173
F 182
E 193
D# or Eb 204
Low notes D 217
C# or Db 230
C 243
*Fro lll th e ATAHI 400/8 00 ' " BASIC Referen ce Manua l, page 58.
224
APPENDIX C
Graphics Mode 0
-- f---
12 J -- - I - X.f- 1 - - - ce nter 20, 12
16
20
24 ~ ____________________________________________________________ ~
NOTES: Text Mode - When th e mach ine is l u rned on, i l is in Graphics Mode 0 until otherwise specified
225
226 ATARI SOUND AND GRAPHICS
Graphics Mod e 1
4 8 12 16 20
8
center 10, 10
(if you have a
text w indow)
12
center 10, 12
16
20
21
tex t w indow
24 ~ __________________________~2~
4
NOTE S: Text Mode for large colored letters. You must use device # 6. (See Chapter 9)
4 8 12 16 20
4 center 10,5
(if you have a
tex t w indow)
center 10,6
8
NOTES : Text Mode for colored letters. You must use device # 6. (see Chapt er 9)
Graphics Mode 3
4 B 12 16 20 24 2B 32 36 40
B
center 20, 10
(if you have a
x tex t w indow)
12 X center 20,12
16
20
21
t ex t
window
24 ~ _______________________________________________________________2~4
NOTES: For same size plot POiMS without tex t window, use G RAPHICS 3 + 16.
Graphics Mode 4
B 16 24 32 40 48 56 64 72 80
1f-! u u u u u u u u u L
Bp
I
center 40,20
(if you have a
t ex t window)
24 P center 40,24
3 2 tJ
40 J ;:
41 o
"0
C
.~
4B u
l~ __________________________________________________________________4~B~
NOTES: For same size plot points with out text window, use GRAPHICS 4 + 16.
Graphics Mode 5
8 16 24 32 40 48 56 64 72 80
1f-l u u u u u u u u u
I
center 40,20
(if you have a
text window)
center 40,24
40P 41 ;:
,-8
c:
3
48wh__________________________________________________________________-24~8 Ix
IE
NOTES: For same size plot points without text window, use GRAPHICS 5 + 16.
Graphics Mode 6
16
32
center 80,40
(i f you have a
48
I t ex t window)
center 80,48
64
80 81
text
window
96 ~ __________________________________________________________~9~6
NOTE S: For same size plot points withou t text window, use GRAPHICS 6 or 16.
Graphics Mode 7
16
32
cente r 80,48
(if you have a
48
I t ex t windowl
cente r 80,48
64
80 81
t ext
w indow
96~ ________________________________________________________~96
NOTES : For same size plot points without text window, use GRAPHICS 7 + 16.
Graphics Mode 8
32
64 center 160,80
(if you have a
text windowl
96
center 160,96
128
160 161
te x t
window
192L-__________________________________________________________~19~2
NOTE S:
Value for
COLOR Valu e for l etters on Bac kground Tex t
command Col o r Register d ispl ay scree n scree n w indow
0
1
2
(Sa me as 3
COLOR 0) 4
0
2 1
(Sa me as 2
COLOR 0) 3
4
0
3 1
(Sam e as 2
COLOR 0) 3
4
0
4 1
(Same as 2
COLOR 0) 3
4
NOTE: A single col o r li sted in th e third , fo urth , or fi fth co lumn indi ca tes th e default co lor for th at combin ati o n of
COLOR and Color Register, For exa mpl e, in gra phi cs mode 3, a combin ati on of CO LO R 1 and Color Register 2 w ill
res ult in the fi gure remainin g orange, rega rdl ess of th e val ue entered fo r Hu e in the SETCOLOR cOlllm and .
230
APPENDIX D 231
Graphics Mode 3, 5, 7
RESU LTS ON SCREEN
Va lu e for
CO LO R Va lu e fo r Plo t po ints Ba ckgro und Tex t
com mand Co lor Register or figu re sc ree n w indow
(I)
4 1
(Sa me as 2
CO LOR (I)) 3
4
NOTE: A single co lor li sted in the th ird. fourt h. or fifth co lumn indi ca tes the defa ult co lor fo r th at co mbin ati on of
CO LO R and Co lor Register. Fo r example . in graphics mode 3. a comb in atio n of CO LO R 1 and Color Register 2 w ill
result in the figure remaining o range. rega rd less of the va lue entered fo r Hli e in the SE TCO LO R co mm and.
232 ATARI SOUND AND GRAPHICS
Va lue for
COLOR Va lu e for Plot po ints Backgrou nd Text
command Co lor Reg ister or fi gure sc ree n w indow
, bac kground
2 Changes hu e
3 Dark blue
4
,
0 Changes hue
Orange
Dark grey Dark blue
2 Changes hu e
3 Dark blu e
4
2 ,
0
(Sa me as 2
COLOR 0) 3
4
3 ,
0
(Same as 2
COLOR 1) 3
4
4 ,
0
(Sa me as 2
COLOR 0) 3
4
NOTE: A singl e co lo r li sted in the third . fo urth . or fiith colum n indi ca tes the default co lor for th at combi nat ion of
CO LOR and Color Reg ister. For exa mpl e. in graphi cs mode 3. a comb inati on of COLO R 1 and Co lor Register 2 w ill
result in th e figu re remainin g orange. rega rd less of th e va lu e entered for Hue in the SETCO LOR command.
APPENDIX E
The design of the AT ARI 400 and BOO computers provides superior sound
and graphics, among personal computers . This is partly because, while
other personal computers have tried to include the normal functions of the
computer as well as the sound and graphics in one processing unit (often
called a chip), ATARI uses separate chips for sound and graphics.
As this book was going to press, AT ARI announced the existence of a new
chip, the GTIA chip, on all AT ARI 400 and AT ARI 800 computers released
in 1982.
The GTIA will replace the CTIA chip currently controlling graphics
displays in the AT ARI 400 and 800 com puters. The GTIA functions are the
same as the CTIA chip in graphics modes 0 through B. However, three new
graphics modes are available with the new chip: graphics modes 9, 10, and
11. These additional modes are graphics modes only; no text can be dis-
played on the screen. Points plotted on the screen in these modes are
rectangular in shape, about four times wider than they are high. Using
graphics modes 9 through 11 will allow for a greater variety of hues and
luminance on the screen.
Although the graphics capability of the machine will be greatly en-
hanced, most of these functions are not executed in BASIC. The new chip
does not affect functions of the graphics mode, COLOR, or SETCOLOR
commands described in this book.
If you are, or may become, a more advanced programmer and would like
more information about the GTIA chip, we suggest that you consult the
publication DE RE ATARI by Chris Crawford, which is available through
the ATARI Program Exchange (Part #9000B , $19.95 plus $2 .50 for shipping
and handling). The address is:
233
INDEX
Array. 193. 195 FOR-NEXT loop , 42 . 57. 7-1. PRI NT s tal e nlOn l, 50. 122. 166.
Arrow ke ys . 10 102. 116.118.14 5. 193 168- 17 2
AT ARI BASIC. 4. 5 nes te d . 59. 67 . 86 Program. 27. 39
AT ARI BAS IC Refere n ce
Manua l. 7 COSUB sta teme nt. 93. 94. 96. Random integers. 139. 14 1.
AT AR I keyboard. 2 97. '100 . 10 2 199
Attack. 74- 76. 78- 80 GOTO stat e ment. 41 Randall! numbe rs. 137
Graphi cs mode . 13. 15. 22- 24. RE /\D s tal e m e nl, -10. 53- 54.
Bloc ks, 33 1l7. BIl. 102. '105. '129. '1GB. BI - 132
BREAK key, 58. 59 '170. 225- 229 READY. 2. 14. 4 3
RE M sta te m e nt. 32. 33. 57
Chart s: IF-TII EN s ta te m e nt. 100.127- RESTO RE s ta te m e nt. 81
gra phi cs. 24. 102. 1 70. 225- '129. '151 RETUR N key. 2. 3. 5. 14. 18.
232 INPUT s tat e me nt. -16 . 49. 6'1. 41
n o te . 9. 224 63.6-1. 67. 76 RETURN s ta te m e nt. 94. 96
C major sca le . 177. '195. 200 Int e rva l. 200 RND function. 137- 140
Co lor luminan ce, 114 110 d ev ices. '168 gra phi cs . 141 - 142
Co lor registe r. 110 so und. 14 0- 14 1
COLOR s tat ement. 14. 16- 18. Hi gh roso luti on grap hi cs. 129- Rows. 15. 4 0. 130. 181 ,184.
31.91 , 93 . 102.1 12. 1 25. 132 '188
156 HU G. 'Ill. 11 2. 118 RU N. 28. 29. 31. 33 , 35. 36
Co lumn . 15. 40. 130. '18'1. 184.
187 Key board. 2
Com ma nd. 2 SETCOLOR. 18. 108. 110- 11 8 .
125. 1 26, 't29. 143. 145
direc t. 27 Lin e number. 27 . 93
param e lc rs . '110- 118
CONT.58 LIST. 21l. 30. 32. 62
CONTROL ke y, 10. 93 S hap e of notes. 74
Loud ness. 7. 74- 80
SOU ND s ta te m e n t. 2. 3. 4- 7.
Coun ting, 42. 65. 66
4'1. 4fl. 53.57- 85. 123.
CTRL. 10. 93 Middl e C. 3.8. 9. -11.187. '19 '1.
'150- 15 1
Cu rso r. 1. 2 '199
param ete rs. 4- 7
Mult ip le-lin e s tal ements . 52 .
Siaff lin es. 180. 187
DATA s tat emeni, 40. 53- 54. 5:1
Sirin gs. 'IGO. 166
81 - 82. 196
Strin g va ria bl es. 160, 161. 207.
Decay. 74. 76- 80. 82 Nes led loops. 59. 6B. 90
208
Defa ult. 111 Nes ted su broutin es. 91l. '106
S ubroutine. 92. 94. 96
De le te. 61. 94 NEW . 27. 29
nested, 98.106
DELETE BACK S key. 2 No te. 5. 58. [;3 . 64. G6. [;9- 72
Dev ice number, 15
Subscrip led varia bl es . 193.
c ha rt s. 9. 224
2'10
DIM stat e ment. 161. 163 . '194 va ri able. 5
S YSTEM I{E SET key . 2 . 3. B.
Direc t co mmand s. 27
19.20. 27 .41.58
DRAWTO s tatem ent. '18- 20. Oclave. :<00
37. 120
Duration, 49. 146 Param eters. 4 T ext w indow . 13.14.87,88.
SETCO LOR. nO- 11 8 105
Ed iting. 10, 1'1 SOUN D. 4- 7 THE N s la leme nt. 108. 127-
END sta tement , 3 Pause. 42. ;.i9. G1 '129. 151
Enter, 14, 15. 19, 46 Pl ease No lo. '1- 223 Third. 200 , 201. 203
Erase . 17 , 44, 96 PLOT s lalomc nl , 14, 88. 119. T one 6.70. 151
Error message . 4. 54. 102. 't 05. 90. fJ2
n2 , 't64 PO SITIO N. 17'1. 175 Vo ice. 4
234