Programming Your Atari Computer
Programming Your Atari Computer
YOUR
ATARI® COMPUTER
BY MARK THOMPSON
FIRST EDITION
FIRST PRINTING
Thompson. Marti S.
Programming YOOf Aiarl computer.
Includes indeK.
1. Atan 600 (Computer)-programming. I. Trt1e.
QA76.8.A814T4S 1963 001 .64'2 82·19334
ISBN 0-8306-0453-7
ISBN D-8306-1453-2 (pbI<.)
Contents
Preface vii
1 Number Systems and Codes
The Decimal Number System-The Binary Number System-
Converting Decimal Numbers to Binary Numbers--<:onverting Bi·
nary Numbers to Decimal Numbers-Octal Number System-
Hexadecimal Number System-Binary Codes
2 Microcomputer Basics 12
Computer Struc1ure-Software--lnterconnectlon 01 Elements-
Scatlng 01 Computers-Microprocessors-Computer Bus
Systems-Types of Storage---8us Control 01 1/0
3 Computer Arithmetic 31
Addition and SUbtraction 01 Binary Numbers--Multiplicalion and
Division of BInary Numbers-Fractions and Decimals
4 Boolean Operations 44
Boolean Algebra-Classes and Elements-Venn Diagrams-
Connectives and VariableS-Applications to Switching Cir-
cuits-fundarnental Laws and Axioms 01 Boolean Algebra-
Boolean Equation SimplificatiOn and Mechanization
5 Introduction to Programming 80
BASIC-The Programming Process-let's Write a Program-
Una Numbers-BASIC Statemeots
Index 270
Preface
This book is directed to the person interested in obtaining a com-
plete understanding of the design and capabil it ies of the ATARI 800
computer. It opens the door to many 3pplications of the ATARI BOO.
It differs from many books in that it explains fundamental micro-
processor techniques whi le it enables you to use your own ATARI
effectively.
Software packages are available that will enable the user of an
ATARI 800 to begin running programs without spending time
learning the basic fundamentals. However . to write and run pro-
grams effectively, the programmer should have a fundamental un-
derstanding of the components that make up the ATARISOO. This
knowledge begins with the microprocessor ch ips. memory chips.
and va chips. It extends to the keyboard and switches for setting up
an instrument or device, transducers for sensing inputs, actuators
for control, devices for communicating with remote computers and
other instruments, devices to provide extra storage capabi lity, and
printers and displays for informing the user of results.
Once the basic components of the machine are understood, the
programmer must thorough ly understand programming processes
and be able to translate these into the language of the ATARI BOO. It
is also helpful for the programmer to understand how the extensive
requirements of the ATARI 800 can be broken down into manage-
able parts and how sections of programs can be written to meet each
requirement. Finally, the programmer must be able to put the
vii
software parts together into a coordinated whole so that the overall
goals of the program are met,
To the novice, all of these requirements may seem a little
much to conquer right at the beginning, but this book is designed to
lead you step-by-step-taking first things first-until even the
beginner wi ll be able to program the ATARI 800 just like a seasoned
pro.
Some of the initial data may seem immaterial at first, but as you
get more and more into actual programming , all of this material will
"gel"-and result in a thorough knowledge of the ATAR1800 and
how to program it to suit personal needs.
vIII
Chapter 1
1
base, in this case 10. The value of each Uf, 101, I e?, and so forth,
Condensed, they are as fot!ows:
10° = 1
10' = 10
10' = 100
10' = 1.000
104 = 10,000
1O~ = 100,000
106 = 1,000,000
10' = 10,000,000
108 = 100,000.000
109 = 1,000,000,000
It is easy to see that for most uses. we seldom have the need to
go higher than l ~-except to balance our national budget!
The smat! figure used to indicate the power to which a number
is raised is called an exponent, and the number raised to that power
is cal led the base number , or simply the base . Thus. in the previous
example. 100, 10 1 , 1()2. etc., the number 10 is the base , and 0,1. 2,
3,4,5,6, 7, 8, and 9 are exponents.
The total quantity of a number is evaluated by considering the
specific digi ts and the values of their positions. For example. the
number 6403 is meaningful as written. but it may also be written in
positional notation as,
2
I
10- 1 = 10
or 0.1
I
10- 2 = 100
or 0.01
_l_
10- 3 = I()()() or 0.001
I
10- 4 = 10,()()()
or 0.0001
I
10- ' = loo,()()() or 0.00001
I
10- 6 = I ,()()() ,()()() or 0.000001
We could continue, but the point should be clear for our purposes.
You also know that a decimal point separates the whole and
fractional parts of a number. The whole number is to the left of the
decimal point and the fractional part is written to the right of the
decimal point. To illustrate this , the decimal number 3.17 can be
written with positional notation as follows:
3
Tablt 1-1. Dethul alld Binary Positional V. lun.
4
you will often need to determine the decimal value of binary num-
bers. In addition, you will find it necessary to convert a specific
decimal number into its binary equivalent.
The chan in Table 1-2 gives the decimallbinary equivalents for
numbers from 0 to 16. Th is would be very helpful if they were the
only numbers encountered in programming. Actually, this is not the
case: you will need to convert many different numbers and an easier
method must be used. Since a binary number is based on powers of
2, we can convert a decimal number to binary by repeatedly dividing
by two.
To simplify matters, let's take the number 1010 • Set up your
division as follows:
2[!L
2t2- 0
21L- I
2!!- ~ 1010
Notice we firs t take the number 10and divide by 2. Two goes into 10
five times wi th a remainder of zero. We write the 5 beneath the 10
and the 0 to the right of the vertical line. Now divide 2 into 5, it goes
two times wi th a remainder of one. Write the 2 beneath the 5 and the
remainder 1 beneath the 0 to the right of the vertical line. Divide 2
Decimal Bil"l8ry
,, ,,
2 10
3
4
5
'00"
10'
6 ",
rlOll 1· 2. Dechull
liury ~i'talents. 7
8
",
'000
9
10
'00'
1010
"'3
12
1011
"00
1101
11 10
"'5 1111
'6 '0000
5
into 2; it goes 1 time with a remainderofO. Write the 1 beneath the 2
to the right of the vertical line. Finally. divide 2 into 1; it goes 0
times with a remainder of 1. so write the remainder to the right of
the vertical line. The digits to the right of the vertical line are the
binary equ ivalent of the decimal number. The number is wri tten
from right to left working from top to bottom, or from left to right
working from bottom to top. Therefore, the binary equivalent of 10
is 1010, as listed in Table 1·2.
The same procedure can be used no matter how large the
numbers. Just continually divide by 2, placing either a Oar a 1 to the
right of the vertical line. If you haven't tried converting decimal
numbers to binary. work a few examples from numbers, say. 12 to
16 and then check your answers with Table 1·2.
Example of this type of method (using fractions) is shown in
Table 1·3. The decimal fraction 0.90625 isconlinually multiplied by
2! Did you say multiply? Yes, to convert a decimal fraction to a
binary number, multiply the frac tion successively by the desired
base (two in our case) and record any integers produced by the
multiplication as an overflow. These calculations will result in
numbers with a 1 or 0 in the units position. Subtract the unit and
multiply the rest by 2 again. The decimal fraction 0.90625 is con·
verted as follows:
Tabl, 1·3. collftltinl I*ilul FrKtIDftI to Binary. N. . ThIt dI,
Orilinal Number II First Multlpilld by 2, ttIt ProdUct of wtlitll il
Multiplied by 2, 1l1li la on Untillhl NUlllber t:omeI o.t Eftn. Tlttr1
Will .. nm.., H....,.r. WM,.. till Nulllblr May Mot c.. OUt h.n--JIIlt
like In till D1ei.11 $,....... But All tin Be CIrri... 011 hK Prlctttli AttuflCY.
0 .90625 , 2
0 ,81250 , -
1.8125
2 = 1.6250 =
0.8125 with
0.6250
overflow 1
1
0.6250 ,
2 = 1.2500 = 0.2500 1
0.25000 ,
2 = 0 .5000 = 0.5000 0
0.50000 , 2 = 1.0000 = 0 1
6
CONVERTING BINARY NUMBERS TO DECIMAL NUMBERS
The easiest way (and the way recommended initially) to con-
vert binary fractions to decimal numbers is to use a table. such as
the one shown in Table 1-4. To use this table , let's take a number,
say binary 1011010 and convert it to its decimal equivalent. There
are seven digits in the number 1011010. The first 1 (the digit
farthest left) is in the 'Z' column and is equal to the decimal number
64. There is a zero under ~ , so there is nothing taken from this
column. Under zt there is a 1. so we write the value 16 next to our
previous number 64. There is a 1 in the Z'column. so an 8 is placed
next lothe 16.In the '}}column there is a 0, and therefore , the value
will be omiued. But there is a 1 beneath the 21 column and this
means a 2 is placed next to the previous 8. There is a 0 beneath ii,
so we omit this value also . Now the numbers 64, 16, 8 and 2 are
totalled for a sum of OO-the decimal number equivalent to
1011010.
Refer again to the table in Table 1-4 and follow the description
of the conversion step-by-step until you are certain that you under-
stand how the conversion was made, Then practice some conver-
sions of your own. Check your answers by reversing the conversion
process; that is, use repeated divisions (or multiplications, de-
pending upon the case) by 2.
2-'
O.S
2- '
0.25
2- '
0 .125
2- '
0 .0625
2- '
0.03125 I 2-'
0,015625
I I I 2-
0.0078125
7
2- '
0.00390625
2- '
0.001953125
I 2 - 10
0 .0009765625
7
Table 1-5. Binary-to-Oc:tal Con, " 'n.
Binary
"""
0 000
1 001
2 010
3 011
•5
,
100
101
01
1
010
2 ,
110 011
3
(binary)
(octal)
110
7 111
number. mark off groups of three bits. Now, using Table 1-5, write
down the equivalent octal value in each group. Notice that this
conversion is exactly like binary-te-decimal conversion, except that
the decimal digits 8 and 9 don't exist in the octal system.
Converting a decimal number to octal is accomplished in the
same manner as decimal to binary except that the base number is
now 8 rather than 2. Therefore. write the decimal number and
divide by 8. For example, to convert the decimal number 469 to
octal, set up your division as shown in Fig. 1-1. Note that the
decimal number 469 is equal to 725 octal number .Just keep dividing
the decimal number by 8 until 0 results.
To convert from an octal number back to a decimal number. we
use the same procedure as we used to convert a binary number back
to a decimal number. In the binary conversion. a table showing
different powers of2 was used. In the octal system, a table based on
the values of powers of 8, as might be expected. is used. Decimal-
octal equivalents are shown in Table 1-6.
'~ 5
'Eo 2
7 ~ 725
Fig. 1-1 . Example of converting decimal number 10 the octal number system.
B
Tabl. 1-6. DecimallOctal Equivalents.
0 0 10 12
I I 13
2 2 "
"""
12
,3 ,3 13
"""
5
6
5
6
7
20 "
7
•
9
10 "I. "
22
23
"Decimal "
"""
20
21
22
"
25
26
23 27
"
25
26
30
31
32
27 33
28
29 "
35
octal number system. and allows easy conversion with the binary
number system.
As might be imagined, the base is 16 for the hexadecimal
system. The symbols are 0,1,2,3,4,5,6,7,8,9, A, B, C, D, E,
and F. In hex, A, B, C, 0, E, F, are digits, not letters; that is,just as
the next digit after 8 (8 + 1) is 9, the next digit after 9 (9 + 1) is A.
the next digit (A + 1) is B. and so forth.
Conversion of binary numbers to hex is simi lar to converting
binary numbers to octal except that 4-bit groups are used instead.
The conversions are shown in Table 1-7.
You can convert from a decimal number to a hex number the
same way you did from a decimal number to an octal number, except
that you divide by 16 instead of 8. ln converting from decimal to hex.
it's recommended that you first convert the decimal number to
binary, and then convert the binary value to hexadecimal. Similarly.
to conven from hexadecimal to decimal. first convert from hex to
binary and then go from binary to decimal.
To illustrate, to convert decimal 685 to hex. convert decimal
685 to binary, which will be OOlD 10lD 1101. Mark the numbers off
in groups of fou r bits from the right: that is .
9
101101011101
2 A 0
BINARY CODES
Has the converting of decimal number to binary or binary
shorthand systems reminded you of anything ? Sure , it's obviously a
form of code just like you see in the cloak and dagger films. The act
of conversion is called "coding" and codes and coding is what this
section is all about.
The decimal number system is easy to use because it has more
than likely been the system you have used most in your life. The
binary number system is less convenient to use because it is less
familiar, and few people can glance at a binary number and recognize
its decimal equivalent. You can readily calculate its value within a
few minutes, but you probably won't recognize it at a glance.
Therefore, the amount of time it takes to convert or recognize a
binary number quantity is a distinct disadvantage in working with
this code despite the numerous hardware advantages. Computer
designers have therefore come up with a special fonn of binary code
that is more compatible with the decimal system . This part icular
code is known as binary coded decimal, which combines some of the
0 0 0000
1 1 0001
2 2 0010
3 3 0011
•
5
•5 0100
0101
6 6 0110
7 7 0111
T.ble 1· 7. 81 ...,,- 8 8 1000
to-+tu: CoItW'IBion.
10 • •
A
1001
1010
11 B lOll
12 C 1100
,."
>5
0
E
F
1101
1110
1111
10
Table 1-8. Standard 8421 BCO Cod. and ttl. Decimal Equlval.lIb.
0 0000 0000
1 0001 0001
2 0010 0010
,3 0011
0100
0011
0100
5 0101 0101
6 0110 0110
,7
9
0111
1000
1001
0111
1000
1001
10 0001 0000 1010
11 0001 0001 1011
12 0001 0010 1100
13 0001 0011 1101
0001 1110
"
15 0001
0100
0101 1111
11
Chapter 2
Microcomputer Basics
A microcomputer is a very complex e lectronic device consisting of
thousands of microscopic transistors squeezed onto a tiny chip of
silicon, related leads, keyboard, housing, and other mechanical and
electronic components. Regardless of the type of microcomputer
used, the programmer should have a basic knowledge of how these
devices operate.
In general, there are two basic types of computers: digital and
analog. Digital computers represent everything in terms of digits.
That is, all data is discrete and discontinuolls. There are some
hybrid computers that connect digital computers to analog comput-
ers , but most of today's computers are of the purely digital kind. You
should now be getting an idea of why certain number systems were
covered in Chapter 1.
An analog computer uses a Quantity, such as an electrical
voltage, as an analog of some other Quantity. For example, 3.145
volts in an e lectrical circuit might represent a velocity of 3,145 feet
per second in a ballistics simu lation program. Analog computers are
fast for certain specialized applications, but they are not practical
for many purposes.
To help you understand the essential elements of a digital
computer , well-known analogy will be presented. Imagine a fai th-
ful, loyal, dedicated employee, such as a secretary, who follows
every instruction to a "T : ' This secretary , given a manual of
procedures and some documents to work with . can refer to history
12
files and produce required reports for your company. He or she
needs only a calculator (to perform computations) and a sheet of
instructions. If he unerringly follows those instructions, he will
produce a stack of papers in his out-basket that represents a trans-
formed version of the information contained on papers in the in-
basket. If the secretary transfonns legi timate inputs into correct
outputs by following the instruction sheet, those instructions can be
considered a correct and valid "program."
In the example above , the secretary performs five distinct
functions.
13
Documents
Instructions
(program)
Keyboard
r 1
Printed
Computer reports
p.
Teletypewriter
QJ)
Tape unit
Files
fig . 2-1 . A computer performs functions Itlat are similar to those performed by a
secretary.
14
complex. As you learned in an earlier chapter , computers perform
all arithmetic operations using binary numbers. The computer can
also perform other "logical" functions such as determining whether
or not one number is greater than another.
We create output by our actions. We write, speak, or change a
situation appropriately. The computer produces output in the form
of rewritten magnetic tapes, disks, and drums; printed reports; and
even motor on/off controls. Since the computer operates electron-
ically, it can also control electronic circuitry, such as the circuitry
necessary to automatically open or close a flow valve in a water
supply system.
We can control both ourselves and our machines. Machines can
control only what they are instructed and permined to control.
When the secretary does some work, he or she is responsible for
controlling the order in which various steps of the procedure are
performed. He can, under the guidance of the detailed instruction
list, read some information , perform some computations, and pro-
duce some output in the order specified in the program.
Computers are controlled by computer program's. The pro-
gram is a description of a detailed procedure that is to be followed.
Just as a theater program outlines the events that are to follow, a
computer program outlines the steps to be followed to arrive at a
solution to the problem presented, The program is interpreted by
the computer which tum various circuits on and off in the sequence
necessary to produce the solution.
COMPUTER STRUCTURE
The diagram in Fig. 2-2 shows the five basic elements of a
digital computer. Every digital computer, no maHer how large or
small, has these five elements plus the set of instructions that tells
the computer what to do. A computer must be able to accept input
data, process it through arithmetic or logical operations, store some
intermediate results, and eventually produce output data-all under
the guidance of a central control e lement. The control element is
guided in its operations by the instructions supplied by a program-
mer. The five basic elements comprise the hardware of the com-
puter , Hardware can be touched, squeezed, observed: it is tangible.
The instructions, on the other hand, represent the software of a
computer. We may be able to observe, touch, or squeeze a storage
medium, but the specific bit patterns held within are not physical;
they are information,
Inputs : Nearly all computers require inputs from one or more
15
external sources. A computer that receives no input signals can only
repeat the same sequence of instructions over and over again. Some
small computers are used in precisely this way, but most computers
have inputs that can be brought into the computer for subsequent
processing.
To compute a payroll check. for example . the computer must
have the ability to fetch an employee record from a file and to read in
the number of hours worked in the week. These both require an
input path to the computer. In some simple applications where small
computers are used to replace older electromechanical logic. inputs
may not be required. A programmable controller of a numerically-
controlled mill ing machine may not require inputs. The program
contains the sequence of instructions which cause the machine to
mill the same part repeatedly. External inputs are of no value in this
case.
Inputs to the computer may take the fo rm of punched cards ,
magnetic tapes or disks, or simple switch closures. When a
keyboard is operated by a human, each key depression results in a
switch closure. The computer can accept this switch closure as a
binary signal and convert the key depression into a binary pattern.
Central
processing
unit (CPU)
-- - --I
I Arithmetic- 1
I lOgic unit I
(ALU)
1,--.:---, 1
1 1
I r-L----, 1
Input --:t Control Ll.....-
1 11 •
1 ' --.:----' 1
1_ - _ _ I
Storage
(memory)
16
That binary pattern, in turn, can be used to print a selected charac-
ter on a printer or display it on a cathode-ray tube (CRT).
Outputs: A computer must produce outputs to be useful. A
computer's output may be in the form of printed results, graphic
plots drawn with special plotting equipment, or simply an electrical
s ignal that can turn a lamp on or off. The range of possible outputs
from a computer is virtually unlimited. The output e lement of a
computer is selected when the control unit executes an instruction
that transfers data from the arithmetic-and-Iogic unit (ALU) storage
area, or when an input is to be output. Most often, the data comes
from storage, and was created by a comp lex combination of inputs
that were modified by the ALU.
The input and output devices are points at which humans
interact with the computer. Much care must be taken to make
computers easy for people to use, rather than making people adapt
to poorly designed or poorly programmed computers.
Storage: In most computer applications, data must be s tored
before it is processed completely or used to produce outputs. The
electrical digital signals that represent the data values are placed in
the storage element, or memory. Instructions can also be read into
storage and held for future use.
Arithmetic: A computer processes information. That pro-
cessing is perlormed by the ALU which accepts data from input and
storage elements, and produces computed results for storage or
output. To add a pair of numbers, the ALU is directed to fetch the
va lues from storage, and to place the sum back into storage. The
ALU may include capabilities for addition, subtraction, comparison,
logical operations, and even mUltiplication and division.
Control : All elements of a computer operate under the direc-
t ion of the control element which opens and closes the various
pathways for data from input to storage, from storage to the ALU,
and from the ALU to output. The control element operates as
directed by the instructions provided in storage. By writing the
proper sequence of instructions, the computer programmer can
completely control the detailed transfers of data within the com-
puter to produce desired results. Thus, with different programs,
the computer can be made to perform different functions, even
though the underlying e lectronic circuitry remains unchanged.
SOFTWARE
Software consists of a collection of instructions that can be
followed by the control e lement of the computer. These instruc-
17
tions must be detailed step-by-step instructions. Unlike humans.
who can inject common sense into the completion of a task. a
computer is not capable of logical reasoning. A computer must be
ordered to do even the simplest part of a task. There are four major
classes of computer instructions:
INTERCONNECTION Of TH E ELEMENTS
Each element of a computer can be treated as a subsystem.
Each element has certain inputs and outputs , and certain actions
that take place internally to transform those inputs into outputs. A
revised view of the five-block model of the computer is shown in
Fig. 2-3. Here, all of the inputs and outputs to each element of the
computer are identified. Note that except for the interfaces be-
18
"-"
. ••
H ,.
- ....' --
",."
,...,
Com..
0,,,,,,,
-~
"",,"'
r-:
"..
iii
• ..
""""
".
i iU ~
''''..go
Fig. 2·3. The interconnections between eiements consist of both data and control
signals.
tween the computer and the outside world. the output from one
element becomes the input for another element. By analyzing how
these paths between elements operate, we can discover how a
computer functions in detai l.
Most of the pathways for data are bidirectional. However,
issuing data to an input source, or attempting to acquire data from an
output destination is meaningless. These data pathways can be
easily limited to a single direction. On the other hand. data must
move in both directions between control and storage, and between
control and the ALU. Since data may now both ways, these paths
are called bidirectional.
Notice that all of the control signals originate in the control
element, and that all data passes through the control element.
"Control" may be thought of asa gigantic switch-board that operates
at microsecond rates to switch data from one source to another
destination. In fact, this is precisely how contemporary computers
work.
At anyone t ime, control may be directing one of the other four
e lements to perform some operation. In very complex computers,
more than one element may be accessed at one time. The input
19
element of the computer has many possible data sources, but only
one of them is to be selected at a time. W'hen reading from input
sources, the control element must first specify which input source
is to be selected. Control places some bit pattern on the wi res that
comprise the input selection lines. The selected data is then placed
on the input data lines. Once input data has been acquired. the
control element must store that data somewhere for future use. The
data might be shipped off to the ALU, or to storage. or even to one of
the output dest inations.
If the input data is to be saved in s torage, the control e lement
must specify where in storage the data is to be placed. Since many
numbers can be stored, each one must be stored in a unique place so
each can be selectively retrieved. The data is placed on the data
lines. and the storage module is commanded to write (store) the
data. The command is sent by the control element through the
Read/Write selection line. The specific register into which the data
is to be stored is specified by a pattern of bits on the register
selection lines.
The specification of which input lines to read and into which
register to place the data in storage. is carried in an instruction.
That instruction contains three essential items of information:
20
ALU, commanding the ALU to add it to the previously saved
number.
5. Accept the sum from the ALU and pass it to output desti-
nation 7.
21
Each of the items named in this brief example is a regi ster in
the computer . One of the control registers (which happens. in this
example. to contain the number 5) supplies its contents to the input
selection register.
Now. reconsider the application posed earlier: the production
of the sum of two numbers . In the following example. each of the
original instructions has been broken down into a number of detailed
steps. These steps are represented in the shorthand form . You
should fill in the descriptive shorthand for the last instruction
yourself to be certain that you understand exactly how the computer
works:
22
Storage register selection
Data storage (102);
Temporary data
Function selection control (Add);
ALU data temporary (102)
Sl:AUNG OF COMPUTERS
It might appear that the size of numbers is limited by the widths
(number of data lines) of the data paths tha t exist betweenelements.
Actually, in the example . data path widths of eight bits wou ld be
sufficient, since the numbers never got larger than 215 (an B-bit
register can hold numbers up to decimal 255). However. even
larger numbers can be handled by breaking them up into pieces.
Then each part of the number has to be handled independently, and
that would require more instructions.
Large computers have wide data paths; smaller computers
have narrower paths. Some of the largest computers have paths as
wide as 64 bits for numbers. Programmers seldom have to resort to
the slow technique of breaking a number up into pieces and pro-
cessing each piece separately. On the other hand. a small micro-
processor may have paths as narrow as four bits. Processing a 64·bit
number would take at least 16 times as long as it would take on the
larger data path.
There are special electronics techniques that can be used with
large computers to make them operate much. much faster. How·
ever , because these techniques are only economical with very large
computers, they are seldom used with microprocessors. Some of
the largest computers can execute instructions 400 times faster
than a typical microprocessor. That speed advantage, multiplied by
the speed advantage of wide data paths. marks the difference be·
tween large, medium. and small computers.
Large·scale computers, or supercomputers, have thousands of
les and require huge rooms for installation. Purchasing one hour of
computer time may cost more than $3000. The only way these fast,
powerful computers can be economical is to have a large number of
23
users. Each user occupies only a small percentage of the computer
resources, and for only a short period of time.
These large computers have large inputlolltput systems with
millions (or even trillions) of bits of storage on magnetic tapes and
disks. The main storage module of the computer may have over one
million registers, and the ALU-control element may be designed to
permit hundreds of people to use the computer simultaneously.
Most of these people use supercomputers to solve mathematical
and engineering problems. These kinds of computers are seldom
used for commercial data processing .
Commercial data processing is most often done on a computer
scaled to the size of the business. For example, large insurance
firms use complex medium-scale computers. Accessing information
about policies and billing data requires a large input/output capac-
ity, but the need for processing is relatively small. However. a
relatively large computer is required to support hundreds of com-
puter terminals in agents' offices throughout the country.
A typical medium-scale computer might have disk and tape
storage that rivals that are used with a supercomputer for capacity.
However, the central processing unit (CPU) will seldom be as large
or complex, and storage may be limited to 250,000 registers or so.
An hour of computer time on such a system might cost $BOO. By
using Y. of the computer's capacity for three minutes. a business
executive can perform all the computations required for a small
office at a cost of about $10.
Small-scale computers are usually called minicomputers.
Some minicomputers are used in small- to medium-sized organiza-
tions for business data processing. However, more of them are used
to perform communication chores for a larger computer. The
minicomputer may service hundreds of telephone lines on the
"front-end" of the computer, passing data to the central medium-
sized computer over a set of highs peed wires. Other minicomputers
are used to effect on-line control of production processes.
A typical minicomputer might have 65,000 registers of main
storage, and a relatively simple ALU-control element. Some appli-
cations might demand disk or tape storage, but many do not. The
operating cost of a minicomputer might be as low as $40.00 an hour.
By occupying the entire computer for 15 minutes, an engineer may
be able to control an experimental process at a cost of about $10.
The least expensive computers are microcomputers. Some of
these are used in small businesses as data processing tools; others
24
are used for personal entertainment: and st ill others are installed
inside other equipment for internal control. These computers are so
inexpensive that dedicating one toa single application is feasible. A
small retai l establishment might use a microcomputer with disk
storage, 16,000 bytes registers of main storage. and a simple
ALU-control e lement. The cost of operating such a microcomputer
system might be as low as $10 a day. By having the entire computer
available at all times, the retailer may be able to better control store
operations at a cost of about $10 a day.
Technologically, all of these computer alternatives are alike
except for their underlying capacity. The lower capacity computers
cost less, but take longer to perform their tasks. Finding an account
balance for a customer in a bank might require 1/ 10,000 of a second
on a large supercomputer and two seconds on a microcomputer.
Will the customer notice? Is the faster speed necessary , especially
in view of the fact that the teller's terminal may require 20 seconds
to print out the account information? In other words, for many
applications, time is not a critical issue, and a less expensive
computer can be used.
MICROPROCESSORS
When the CPU (the ALU and the control element) of a com-
puter is implemented in a single integrated circuit (lC), we call that
the central processor a microprocessor. The term microprocessor is a
contraction of microelectronics and central processor, and indicates
the technology used in the heart of the computer.
A microprocessor is not an entire computer: it is only the ALU
and the control portion of a computer. When the microprocessor is
combined with storage, and input/output devices, however, the
result may be properly called a microcomputer. A microcomputer is
any computer based on a microprocessor.
At this point, it is important to distinguish between two dif-
ferent kinds of microcomputers. One kind integrates all computer
e lements on one IC or on a very small number of ICs. A "one-chip
microcomputer" cannot be distinguished from its microprocessor
counterpart by simple inspection. However , one-chip microcom-
puters are small, powerful computers that are useful for a wide
range of special applications. They are found in consumer goods,
electronic games, and electronic interfaces between larger
computers and peripheral devices like cassette tape drives.
One-chip microcomputers are inexpensive, but limited . They
25
are useful in certain low-cost applications that demand little in the
way of computing power or storage capacity. However, because the
pins of the Ie are devoted to input and output wires. these devices
have little expansion capability.
The more popular kind of microcomputer is made up of sepa-
rate les for the CPU. storage, input. and output. All these e lements
are interconnected by wiring etched on a printed circuit board.
When a microcomputer is created out of many individual elements,
as are many of the popular single-board computers, more power is
available to the user. If the application demands more memory.
more memory boards can be added to the configuration. If special
VO capabilities are required. they can be installed as special
boards. Although more expensive than the one-chip microcomput-
ers, microcomputers in printed circuit board fonn may be used in
vastly more complex configurations. and may contain an almost
limitless variety of storage and I/O capabilities.
Many of the general-purpose single-board computers use many
one-chip microcomputers to act as VO interfaces. A single com-
puter complex might have dozens of one-chip microcomputers per-
forming periphe ral interface chores under internal software
control-all supporting a single fast microprocessor with a large
amount of storge on other boards. More and more interface systems
are composed of one-chip microcomputers that have been suitably
programmed. Most of these can be treated. however, as dedicated
les. Internally. they've been programmed to perfonn some specific
task. However. since the user or maintenance technician cannot
change any of that programming. the programmed one-chip mi-
crocomputer is effectively a special-purpose Ie developed for the
intended interface application. The trend is away from huge cen-
tralized computer systems to systems of computers in which the
computing power is distributed among many small one-chip mi-
crocomputers.
26
that data can be sent rapidly to storage while other operations are
being performed. The more complex the computer , the more likely
it is to have some special interelement paths. However , most
microcomputers are designed with only simple pathways. Effi·
ciency is sacrificed for the simplicity of a more organized structure .
Writini to Storale
Writing or storing data takes place in a fashion analogous to
27
reading or retrieving data. The data is put on the data bus by the
CPU. (For those who are curious, Fig. 2-4 shows a detai led view of
the address bus. VMA and /W (low) signals are produced just like
the equivalent signals used during reading.) However, the storage
element cannot take the data from the data bus until the specific
register has been addressed. It takes time to gain access to the
required register. This is called the access time. (In most comput-
ers with a sequence of this kind, the storage element would cause
writing to occur at the instant the E signal made the end-of-cycle
high-to-low transition.)
Transferring data from one storage register to another simply
requires two successive read-and-write storage cycles. Some in-
structions in the computer cause successive cycles like this to
happen automatically. Invariably, however, the process ends with
another storage read operation which will retrieve another instruc-
tion from the program that is in memory for execution.
Master Clocks
To create the enable (preparation) signal for controlling the
~: ~_=~\\~CYC1.1:
bus Data
'.om
LEGEND CPU
~: J ~igh
1 --,
0_ .
I. _Low
~: l\\\\\\'i Data
changing
~ Datamay
be high or
lOw. but
slable
28
Ik
+5
-" 07
Ik
+5
/0 06
Ik
+5
I OS
Ik
+S
-"~ I 04
+S
Ik '1
-" I D3
Ik
+S
-" I 02
Ik
+S
/0 I 01
Ik
+S
-"- I 00
1
A1S
Input ---(
<l- A1'
VMA
A/W
Fig. 2·5. A simple Input port places the input data on the data bus only when
addressed for reading with a valid memory address.
29
Sometimes there may be digital logic external to the microproces-
sor itself required to create all of these signals. but these external
ICs are considered part of the microprocessor complex. How these
signals are used determines the complexity of the input. output. and
storage elements of the microcomputer.
TYPES OF STORAGE
Storage in a microcomputer is usually made up of read-only
memory (ROM) ICs for permanent storage. and random-access
memory (RAM) ICs for temporary storage. The ROMs are written
once before installation in the microcomputer. Since these storage
elements are not written to by the microprocessor. they can be
permanently encoded with a program. and that program will be
ready to execute whenever power is turned on. On the other hand.
the RAM uses semiconductor ICs that can be both read and written
to. However, when power is first applied their initial data contents
are random. Data cannot be stored in semiconductor RAMs while
the power is off.
BUS CONTROL OF 1/ 0
Input signals can be connected to the data bus for use when the
instructions call for the reading of input data. A simplified version of
the techniques used for storage shown in Fig. 2-5 can be used. The
address bus and parts of the control bus are combined to create an
input signal. When that signal is high, the input data is sent to the
data bus lines.
30
Chapter 3
Computer Arithmetic
In Chapter 1 of this book you were introduced to how to use the
binary number system, how to convert decimal numbers to binary
numbers (and vice versa), and how to convert between other
number systems. This chapter is designed to introduce you to the
fundamenta ls of binary mathematics-addition, subtraction, mul-
tiplication. and division. Since microprocessors use binary numbers
for data and control, it is extremely important that you become
familiar with them.
31
In the binary system, there are four rules that help to make
addition quite simple. They are summarized as follows:
1. 0 +0 0
2. 0 +1=1
3. 1 + 1 = 0 with a carry of 1 equals 10
4. 1 + 1 + 1 = 1 with a carry of 1 equals 11
Before continuing, let's review the dedmallbinary equivalents
shown in Table 3-1.
With the above table in mind. let's look at the following addi-
tion problem.
1010
+101
1111
11111
+1111
lOWO
At first glance you might have thought the sum of the two numbers
in the example above should have been 12222. but you must re-
member that we are working with the binary number system, and
our only digits are 0 and 1. We must go back to the four rules given
earlier in this chapter . Starting with the first column at the right, we
add binary 1 to binary 1 (Rule #3). The result is a Owhich is written
under the first column, and a 1 that must be carried to the second
column. In the second column, 1 plus 1 equals 0 with a carry of 1. To
this sum, you must add the 1 you carried from the first column .
Thus, 0 plus 1 (Rule #2) equals 1; this result is written under the
32
DECIMAL BINARY
o o
1 1
2 10
3 11
4 100
•• 101
110
r.1I1. 3·1. O.el •• I· 7 111
•.....,E4M~. •
9
1000
1001
10 1010
11 1011
12 1100
13 1101
,."
14 1110
1111
10000
33
llO101
llOll
+ 101111
111llll
To add these three binary numbers, start at the extreme right
as before and add the first column. We have 1 + 1 which equals zero
(with a carry of one) plus 1 which equals 1 (1 + 1 = 0; 0 + 1 = 1 with
a carry of 1 to the second column). Adding this carried 1 to 0 (the top
digit in the second colurrm) , gives us 1 (Rule 112). This 1 added to
the remaining two Is in the column gives us 1 with a carry of 1 (Rule
#4).10 the third column, the carried 1 plus the top 1 in the column
equals 0 with a carry of 1; 0 plus 0 (the second digit from the lOp)
equals 0; then Oplus 1equals 1 (Rule #2). Thus the digit 1 is written
for the sum of the third column and we have a carry of 1.
This procedure is continued until we have a total sum of
1111111 in binary. To check th~addition. convert the binary num-
bers to decimal numbers. They are, from top to bottom, 53, 27, and
47 respectively. These three decimal numbers added together
gives a sum of 127. The decimal number 127 is equal to the binary
number 1111111. So our addition is correct.
In performing binary addition, do not use a pocket calculator as
this will only confuse you. Also, you might find it helpful to make a
small pencil mark at the top of the column to indicate each 1 carried.
The carries of our last example could be indicated as follows:
11111
110101
11011
+ 101111
1111111
You may not need these marks in simple binary addition, but in
the more complex problems you'll certainly find a need for them.
For example , let's look at the following addition of four binary
numbers.
11 ()()I
10101
11101
+ 10101
34
1 111 11 11 1 11
) ) 00)
) 0 ) 0 )
) ) ) 0 1
+10101
11 00000
To add these figures. first deal with the column on the extreme right
as discussed previously; we have 1 plus 1 equals 0 with a carry of 1.
Asmall l is then placed above the second column before we proceed
to add the rest to the first column . We have another 1 plus 1 which
again gives us 0 plus another 1 to carry. So a second small! is placed
above the second column as shown in the example above . The total
of the first column is therefore O.
In the second column, we have four zeros which would total 0;
then the two l 's (from our carries) are added. Since 1plus 1equals 0
with a 1 to carry, 0 is written as the sum of the second column and a
I
25
21
29
+ 21
96
35
Subtraction
Binary subtraction is perfonned exactly as decimal subtraction
is perfonned, so a review of decimal subtraction is in order . You
know, for example, that if decimal 1827 is subtracted from 6845. the
difference obtained is 5018.
6845 Minuend
- 1827 Subtrahend
S018 Difference
In the right-hand column, the digit 7 is larger than the digit 5 in the
minuend, so a 1 is borrowed from the next higher-order digit in the
minuend (the 4 in our case). The 5 in the minuend becomes 15 and
the 4 becomes 3. No other borrowing is necessary in our example.
When subtracting binary numbers there are a few basic rules to
remember.
1.0-0=0
2. 1 - 1 = 0
3. 1 - 0 = 1
These are three of the four subtractions you will have to
perform in binary. The other is to subtract 1 from O.ln this case, you
must borrow from the next digit to the left as you would in decimal
subtraction. Thus the fourth rule is:
10-1=1
11011
-1001
10010
36
10010 in binary. If we add this to 1001, we get an answer of 11 011,
again proving our subtraction correct.
Now let's look at another example which requires borrowing.
101101
-1l01l
JOOj(j
llloo
-1001
TOOIT
MUlTiPUCATION ANO OIVISION OF BINARY NUMBERS
Multiplication is a short method of adding a number to itse lf the
number of times specified by the multiplier . Binary multiplication
follows the same general principles as decimal multiplication.
However , with only two possible multipliers (1 or 0), binary mul-
tiplication is much simpler than decimal multiplication. As with
binary addition and subtraction, there are a few simple rules to
fo llow when mu ltiplying binary numbers.
1. 0xO=0
2. 0 x 1 = 0
3. 1 x 0 = 0
4. 1 x 1 = 1
37
As in addition and subtraction, once the multiplication is perfonned
in binary, the answer may be checked by converting all numbers to
their decimal equivalents and doing the problem again.
Let's multiply the binary number 1010 by binary il; the
problem is written as follows:
1010 Multiplicand
xl1 Multiplier
1010
1010
iTiiii Product
1110
x 111
1110
x 111
1110
1110
1110
1100010
Using the four rules of binary addition, the first 0 is merely brought
=
down . In the second column, 1 + 0 1. In the third column . 1 + 1 =
owith a carry of 1. ln the fourth column, 1 + 1 = 0 with a carry of 1;
then 1 plus the 1 carried from the third column = 0 with another
carry of 1. In the fifth column, 1 + 1 = 0 with a carry of 1. Then ,
adding the two I's carried from the fourth column , we get 0 with
38
another carry of one. In the sixth column. 1 + 1 + 1 equals 1 with a
carry of 1 (or 11 since there are no other digits to add in the seventh
column). The answer, therefore , is 1100010.
If the process seems difficult to you at first, practice several
problems with carries, and then check your answer by convening
.the problems to the decimal number system. If any problem does
not work out correctly , be sure to repeat it until you locate your
mistake.
Binary Division
Division is the reverse of multiplication. Therefore. since
multiplication primarily involves addition, division primarily in-
volves subtraction. If you learned the basic principles of binary
subtraction earlier in this chapter. you should have little trouble
doing binary division.
The numbers in binary division are set up in much the same
way as decimal numbers are set up in conventional decimal division.
Forexample, in dividing binary 100 into binary 1000, the problem is
set up as follows:
100fTOOii
In the above example , the divisor is 100 and the first three digits in
the dividend are 100. so 100 will go into these three digits once.
Then the divisor is multiplied by this 1 and the results written
beneath the first three digits. Now we subtract. The remaining 0 is
brought down. The divisor 0(0) wilt go into 0 zero times, SO we
place a 0 in the quotient for a total of 10.
10
100J1OOO
100
00
11
101 JTIIT
101
101
101
o
39
Binary 101 goes into binary III once, so we place a 1 above the third
1 from the left. Then we subtract WI from III leaving 10. The
remaining 1 in the dividend is brought down and the divisor (I01)
goes into this 1 time with no remainder. Thus, the result of this
division is binary 11 .
The preceding examples were relatively short and quite sim-
ple, but they should suffice to introduce you to binary division. In
longer problems, the division is essentially the same. There may be
many more steps and more chances to make errors, but the division
is done the same way . It is important todo your borrowing when you
subtract. When you borrow 1 from 1, for example, you get binary 10
and leave obehind. if you borrow 1 from 10, you get 10. and leave 1
behind. To remind yourself that you have borrowed, put the appro-
priate figure near the original digit. if you don't do this, chances are
that you will forget what the digit should be and make a mistake.
Learning binary arithmetic is mostly a matter of getting prac-
tice , so do several problems daily until the procedure becomes
second nature to you. Always convert the binary numbers to deci-
mal ones and check your math for errors. If any are found, rework
the problem until you find your mistakes .
40
r.b" 3-2. ~" Powtn of 2.
2-' = -21 = 0.5
2- ' = = 025
4
2-' = = 0.125
8
2- ' = 1
16
= 0.0625
1
2- ' = 32
= 0.03125
2- ' = -L = 0.D15625
64
2- 1
126 = 0.0078'25
2- ' = 256
= 0.00390625
2- ' = 512
= 0.001953125
2 - 10 = = 0.0009765625
1024
41
,
", .,.
L
= 0.1)625
'" 0.125
= 0.1875
= 0.001
= 0.0010
= 0.0011
, = 0.250 = 0.0100
,
4
= 0.3125 = 0.0101
is
1- :E 0.375 = 0.0110
8
,.,
7 '" 0.4375 = 0 .0111
TMIte 3-3. Binary
~1..1eftIIof FlXtions in 51.......
= 0.500 = 0.1000
T
9 = 0.5625 = 0 .1001
16
, = 062' = 0.1010
8
"
16
= 0.6875 = 01011
,.
.!1. = 0.8125 = 0.1101
7
= 0.875 = 0 .11 10
8
,.
15
= 09375 = 01111
,.
2i = , 000 = '0000
dividing with a decimal number, get rid of the decimal in the divisor
by moving the decimal point to the right in both the divisor and the
dividend. In other words, you have the same basic problem in both
number systems-keeping track of the decimal point. Here are
some examples of binary multiplication and division.
42
10.1
x 10.1
iiiT
101
ITO:Oi
om ) 0.0001
0.01
I/OF!
I
--0
43
Chapter 4
Boolean Operations
Along with the basic mathematical processes examined earlier, the
microprocessor in the ATARJ 800 can manipulate binary numbers
logically. This system was conceived using the theorems developed
by the English mathematician George Boole (1815-1864). Boolean
values are used in the process of reasoning (Boolean algebra), or in
a deductive system of theorems using a symbol ie logic. and dealing
with classes, propositions. or on-off circuit elements. Boolean
algebra employs symbols to represent operations such as AND,
OR, NOT, EXCEPT, and in some cases (in programming) if ... then
to pennit mathematical calcula tion.
The simples t kind of Boolean expression states a re la tionship
which mayor may not be true, between two quantities. If the
quantities are numeric. then the possible relations are strict in-
equalities; < , > ; and reflexive inequalities: less than or equal,
< =, and greater than or equal , > = , equals, =; and does not equal,
~ . If the quantities are non-numeric, for instance, the address of
apartments, it makes no sense to talk about inequalities which
derive from an ordering of values, but the re lationships "equals" and
"does not equal" are still meaningful.
A relational expression results in a Boolean value, 1 or 0,
depending on whether the two quantities compared in the relational
expression do or do not satisfy the given relation. If variables or
numerical expressions are written to represent the related quan-
tities, the values of these variables or expressions are first obtained
44
and then examined to detennine whether or not the indicated
relationship holds for these values.
Relational expressions are the most obvious, but they are not
the only kind of Boolean expression. We sometimes wish to base a
decision on whether or not several relational conditions hold
simultaneously or on whether or not at least one of several possible
conditions hold. Consider the following:
The U.s. Postal service has recently imposed restrictions on
the maximum size and weight of a package to be sent by parcel post .
The weight must not exceed 44 pounds, and the sum of the length
plus the girth must not exceed 72 inches. Assume that for parcels of
rectangular cross-section, the dimensions are given as values of the
variables A, B, and C in units of inches. and the weight as the value
of WGHT in pounds. However , the dimensions are not necessarily
given in order from greatest to least. We must Write a procedure to
detennine whether or not any given parcel is acceptable.
In order to calculate the postal dimension, we need to know
which of the three dimensions is the largest. for the equation
restricts girth more than it does length. We can compute a value for
the postal dimension by making use of conditional assignment.
IFA=B&A= CTHEN
POSTALDIMENSIONS = A + 2' (B+C);
ELSE IF B = C THEN
POSTALDIMENSION = B + 2 ' (MC)
ELSE
POSTALDIMENSION = C + 2' (A+B);
BOOLEAN ALGEBRA
Before going further into conditional execution, the reader
should have a good knowledge of Boolean Algebra. This will help
him or her to approach the work more intelligently.
45
In the spring of 1847, George Boole wrote a pamphlet entitled
"A Mathematical Analysis of Logic:' Later, in 1854, he wrote a
more exhaustive treatise on this subject which was entitled. "An
Investigation of the Laws of Thought." It is this later work which
forms the basis for our present day mathematical theories used for
the analysis of logical processes.
Although conceived in the 18th Century, little practical appli-
cation was found for Boolean algebra until 1938 when it was found
that Boolean algebra could be adapted for the analysis of telephone
relay and switching circuits. Since that time, the extent of its use
has expanded rapidly, roughly paralleling the development and use
of more complex switching circuits such as those found in present
day automatic telephone dialing systems and digital computers.
Thus Boolean algebra has become an important subject which must
be learned if the operation of digital computers and other devices
using complex switching circuits is to be understood.
46
A true and B false
A true and B true
A false and B true
A false and B false
VENN mAGRAMS
The Venn diagram is a topographical picture of logic, com-
posed of the universal class divided into classes depending on the
number of elements. Venn diagrams may be used to illustrate
Boolean logic as follows:
Consider the universal class as containing submarines and
atomic-powered items. Let A equal submarines and B equal
atomic-powered items. We have four classes which are:
47
A VennOiagram
submarines, fIOI
alOmic powered
2 2
~[QJ .m:J~3 4 3 4
c o
Fig. 4-1 . The Venn diagram.
48
The vinculum serves a dual purpose . It is at the
same time a symbol of grouping and of opera·
tion. As a sign of operation it indicates that the
term(s) so overlined are to be compkmented.
Complement can be defined as "a Boolean op-
eration whose result is the same as that of
another operation but with the opposite s ign ;
thus, OR and NOR operations are comple-
mentary ." As a symbol of grouping it collects
all terms to be complemented together. Terms
so overlined are often said to be negated, the
process of taking the complement is then called
negation.
f(A.B) = A-B
49
~ A B !(A,B) - AS
~
0 0 0
0 1 0
1 0 0
o Venn Diagram e
1 1 1
Truth table
,;;-'~ o
"1" ~ " 0"
D-
e8 A ND swltchil'lQCircul1
CD Logic diagram
mechanization oIl(A,S) =< AS
The other three classes are also indicated in Fig. 4-2A. This ex-
pression is cal led an AND operation because it represents one of the
four mimerms previously discussed. Recall t hat AND indicates
class intersection and both A and B must be considered simultane-
ously.
We can conclude then that a minterm of n variables is a logical
product of these n variables with each variable present in either its
noncomplemented or its complemented form. It is considered an
AND operation.
For any Boolean function there is a corresponding truth table
which shows, in tahular form, the true conditions of the funct ion for
each state its variables can be in. In Boolean algebra, oand 1 are the
symbols assigned to the variables of any function. Figure 4-2B
shows the AND operation func tion of two vari ables and its corre-
sponding truth table.
You can see that this function is true if you think of the logic
involved; AB is equal to A and B which is the function f(A,B). Thus,
if either A or B takes the condition of 0, or both take this condition,
the fWlction f(A,S) = AB is equal to O. But if both A and B take the
condition of 1, the AND operation function has the condition of 1.
Figure 4-2C shows a switching circuit for the function f(A, B) =
AB. There will be an output only if both A and B are closed. An
output in this case equals 1. If either switch is open (0 condition) ,
there will be no output or O.
50
In any digital equipment, there will be many ci rcuits like the
one shown in Fig. 4--2C. ln order to analyze circui t operation, it is
necessary to refe r frequently to these circuits without looking at
their switch arrangements. This is done by doing a logic diagram
mechanization as shown in Fig. 4-2D. This figure indicates that
there are two inputs, A and B. into an AND operation circuit
producing the function (in Boolean algebra fonn) of AS. This dia-
gram simplifies the circu it diagram by indicating operations without
drawing all the circuit details.
It should be understood that while the previous discussion
concerning the AND operation dealt with only two variables the
same ideas can be appl ied to any number of variables. For example,
in Fig. 4-3 three variables are shown along with their Venn diagram,
truth table . switching circuit . and logic diagram mechanization.
Consider the Venn diagram in Fig. 4-4A; note that there are
two elements. or variables . A and B. The shaded area represents
the class of elements that are A+B in Boolean notation and is
expressed in Boolean algebra as:
«A.B) = A + B
51
A B I(A ,B) - A+B
,
, ,0 ,
•
0 00
0
1
o Venn diagram
1
G
1
Truth table
~Ro' ~ T f
~
-----
Load }- e Logic diagram
mechanization 01 t(A,B) =A+B
e Or swi;;ht'ng circuit
52
The shaded area in Fig. 4-6A represents the complement of A
which in Boolean algebra is Aand read as "NOT A". The expression
f(A) equals A is called a NOT operation. The truth table for the NOT
operation (Fig. 4-68) is explained by the NOT switching circuit. A
NOT circuit must take a signal that is injected at the input and
produce the complement of this signal at the output. Thus, in Fig.
4-6C it can be seen that when switch A is closed (equal to 1), the
relay opens the circuit to the load. When switch A is open (equal to
0) the relay completes a closed circuit to the load. The logic diagram
for the NOT operation is given in Fig. 4-6D. It shows that A is the
input to a NOT operation circuit and gives an output of A. The NOT
operation may be appl ied to any operation circuit such as AND or
OR.
The shaded area in Fig. 4-7A represents the quantity A OR B
negated. This figu re represents the minterm expression ill; that
is, A OR B negated is A OR B and by application of DeMorgan's
Theorem is equal to AB.
The truth table for the NOR operation is shown in Fig. 4-7B.
The table shows that if neither A or B is equal to 1, then f(A,B) is
equal toO. Furthennore, if A and Bare equal 0, thenf(A,B)equais 1.
A B C I(A,B,C) A+B+C
0 0 0 0
0 0 1 1
•
0 1 0 1
0 1 1 1
1 0 0 1
1 0 1 1
1 1 0 1
" Venn diagram 1 1 1 1
e
~~,. ,bt' ,~o,
Truth table
~
---
Load }- re
~Loge d;a9"m
mechanizatiOn 01 f(A,B,C) = A+B+C
e ~
OR switching circuit
53
I 0
o I
0 -- _ mechanizaIion oj I(A) ,. A
. T"IIII""
~ I
~
A B
A +8 "+8
" 1" • "0" ",.' rV "- B '
e Logic diagram _
ffi8ch8nizatioo 01 I(A.8) • A + 8
''0''
54
The NOR operation is a combination of the OR operation and
the NOT operation. The NOR switching circu it in Fig. 4-7C is the
OR circuit placed in series with the NOT ci rcuit. If either switch A,
switch B, or both are in the closed position (equal to 1), then there is
no transmission to the load.lfboth switches A and Bareopen (equal
to 0), then current is transmitted to the load.
The logic diagram mechanization of f(A,B) = A+B (NOR
operation) is shown in Fig. 4-70.11 uses both the OR logic diagrams
and the NOT logic diagrams. The NOR logic diagram mechanization
shows there are two inputs, A and B. into an OR circuit producing
the function in Boolean form of A+B. This function is the input to
the NOT (inverter) which gives the output, in Boolean form, of
A+B. Note that the whole quantity of A+B is complemented and
not the separated variables.
The shaded area in Fig. 4-8A represents the quantity A AND B
negated (NOT), and is a maxterm~ression. Notice that AB is
equal to the maxterm expression A+B.
A B AB I(A .B) = AS
0 0 0 I
0 I 0 I
0 0 I
I 0
e Truth table
O venn diagfam
A
Aii
B
e LogiC olagram
ffiactIanil:ation OII(A ,B)=AIi
55
The truth table is shown for the NAND operation in Fig. 4-8B.
When A and B equal 1 , then f(A,B) is equal to O. In all other cases,
the function is equal to 1.
The NAND operation is a combination of the AND operation
and the NOT operation. The NAND switching circuit is shown in
Fig. 4-8C. Note that the AND circuit is in series with the NOT
circuit. If either swi tch A or B is open (equal to 0) , then current is
transmitted to the load. Ifboth switches A and B are closed (equal to
1), then there is no transmission to the load.
The logic diagram mechanization off(A,B) = AB (NAND oper-
ation) is shown in Fig . 4-8D. The AND part of the diagram and the
NOT part of the diagram show that there are two inputs, A and B,
put into the AND circuit. The result is then input to the NOT circuit
which gives the output, in Boolean form, of AB. Note that the entire
quantity AB is complemented and not the separate variables.
NOTE: The logic diagrams in Figs. 4-7 and 4-8 do not conform
to the American Standard Logic Symbology (MIL-STD). They were
drawn in this fashion to illustrate a point in the text, normally they
will be drawn as shown in Fig . 4-9.
The exclusive OR operation is actually a special application of
the OR operation. In this operation either A or B must be true in
order for the function to be true; however, if both are true at the
same time the function will be false.
As shown by the Venn diagram (Fig. 4-lOA), this operation
must be assigned a special class since it does not conform to any of
the minterm or maxtenn classes previously discussed.
In the mechanization of this operation (Fig. 4-10C) the
switches are mechanically linked together so that one or the other,
but not both, may be closed at a time. The truth table for this
operation is shown in Fig. 4-1OB and the logic symbol in Fig . 4-100.
~A+B
NAND
~ NOR
Fig. 4-9. AmeOcan Standard lOgic symlX>k>gy fOr the NOR and the NAND
operations.
56
A , ItA.S) • •
II 0
•• •
0
•
0
0
0
•
•
0
~V"'dJapn e TruIh~
,!; I
A ___ + e~
__
IneG EDIIi¥e"CA"~
Cl:.,.
.~ "OA "
"-
through 4-20 show the truth tables , logic diagrams, and mechaniza-
tion for these Jaws and axioms.
I. Law of Identity
A=A
A= A
• rn o
•
A
0
•
57
IV. Commutative Law
I. AB = BA
2. A + B = B + A
V. Associative Law
I. (AB)C = A(BC)
2. (A + B) + C = A + (B + C)
IX . Law of Absorption
I.A(A+B)=A
2. A + (AB) = A
Axioms
I. A+O=A
2. A • 0 = 0
3.A+l=1
4. A • 1 = A
e
~ ......
;~ ~ 00
'"
r
,00
,---
,
. r-'"j
"1r \ . ,..
. "' /11 .0
_
........
.,G
, NOD... /II o G
58
•::r:Y- A
•
A ..
•
• • •
.... A· ...
f = AC+AD+BC+BD
f = AC + AD + BC + BD
A(C + D) + B(C + D)
(A + B) (C + D)
59
• AS=SA
~ AS :=O--+8A
P:J
"0" "0"
C~ dAB
y , ANDckt
BA
A B AS B A BA
, , , , , ,
, , , , , ,
, , , , , ,
, , , , , ,
~-,~
•:=D--+ ,,"O' J>
AB_,.
A
+
A+B::B+A
B
:=r=r B
+
A
~
, B':"
., ,"
r- "0" t- ~ "0" I--
B> A" P
~
, A'B
~
."'.
B'A
QReII,
Of' '"
A B A.B B A B'A
, , , , , ,
, , , , , ,
, , , , , ,
, , , , , ,
~E~ '---=- A+B:8+A
60
SOLUTION: Rearrange tenns and facto r as follows:
f = AB + AC + ABO + AC + ABO
f = (AB + ABO) + AC + AC + ABO
f = AB + AC + AC + ABO
This equation is the easiest to mechanize. However, the simplifica-
tion process could be carried one step further by factoring, in which
case:
f = A(B + C) + A(C + BO)
The foregoing examples of simplifica tion show the process to
be rather difficult at first. For the beginner there is no positive
indication that the simplest possible logic equat ion has been
reached. You must learn by experience. Repeated use of these
theorems is the only solution. Simplification theorems are of
greatest value in the preliminal)' stages of s implification, or in the
s implification of e lementary function s.
A second way approach to equation simplification is to use the
Veitch diagram. This type of diagram provides a very qu ick and easy
way for finding the s implest logic equation needed to express a
given function. Veitch diagrams for two, three, or four variables are
readi ly constructed (Fig. 4-22). Any number of variables may be
plotted on a Veitch diagram, although the diagrams are difficult to
construct and use when more than four variables are involved.
Because each variable has two possible states (true or false),
the number of squares needed is the number of possible s tates (two)
raised to a power dictated by the number of variables. Thus, for four
variables the Veitch diagram must contain 24 or 16 squares. Five
variables require 2~ or 32 squares. An eight-variable Veitch diagram
za
needs or 256 squares-a rather unwieldy diagram. If it becomes
61
Rl (A'B ) ' C = A' (B' C)
o AD AB
1
: D I A Blc .
B
A 00 (SCI
"0" "0"
+ LL~'O" (AB)'C
I .. ~~~ +b,0" B
.».,....';?; Load -I
" (ABIC .. "".. -0"" '1"" "" . AlB-C)
r .""
- "'"
~"
I
A B C AB (AS)' C IBeI A(BC)
0 0 0 0 0 0 0
0 , 0 0 0 0 0
0 , 0 0 0 0
0
, 0, 0 0 0 0
, 0 0 0 0 0 0
, 0 , 0 0 0 0
, , 0 , 0 0 0
, , , , , , ,
~ Equal .::::::r-'
(A'8) ' C = A'(B'C)
(A+ B)+C = A+(B +C)
c A
e A D A + B V+B1+ j 5 I D A+IB+Cl
B • B B+ G ..
C C
+ '0" + A "0- " -
"~ - -
" .. ..
, - ' ~ .Po ··0 ··
(A+BJ
t--
-B......:.O·· load
~ .. ..
, A + (B +C)
~ <>:., .. '·0" load
C .......:·0·· (A+B)+C C 51' B+C
.. - .. -<>' .. • ..
:~ :1:
~ooo 0 0 0 _ _
~
0 0 _0 0 0 •
Ha
~
~
•
'i~
< •
'i~
<
0
i2J 'i
•
<
0
000
0 _
o _
0 0
•
~
<
<
••
i o o 0
00 __ _
.~
~
• ~ 0 0
•
0 0 _0_ 0 0
0 __
• 0 00
< 0 000
< • 0
64
•
Joo<:>-- --- >-
•
~oo __
•
00
,~ • o
.., <:> <:> - - <:> <:> - -
•1. «0000_
•
• ~
~ ••
•• ~
••
~ooo----
•
0
al°<:>o-ooo_
;,
• "•
1<0
1<
I
1<0
.<
f-
V V V
0
-
1<
1<0
1< _0 0 0
>-
P
0
--
- ,
,<0 - - 0 0
V V
1< 'CD
-
,
<0
1<
-- 0 0
<
p,~~.
<0 0
- - 0
<0 < 0
--
0
< <0 +
1<0
1<0 1<
1<
" "
I! l l~
I!
<0
'" 0 0 _ -
< <0
+
66
<
c .,
,., +
,~
"
I~
,
rx-Y
j
v < 0 0 __ I
I
p ~
J~ c I"
.,
o
c
+
!
~---~ 67
=A_A
A A A A A
I I
, A
0
, 0 ,
0
~_-O"
" 1"
"t.~ 1"
A:: A.
~O"
~- -;:
" 1"
''0'' :=:
A
" 1"
"""
Fig, 4-1 a. Law 01 double negatiOn.
58
~
+
<
~
.-
•
OO ~ _
<
" , , ~ 0 00 _
~+ ? , a,
< ~ 0 _ 0 _
< <
• 00 _ _
< < +
iii
+
~
•
00 _
-k-
~ x-..,.J ~ <
0 - --
~<
~
+ +
"
j
< < iii
+
~
~ 0_0 _ <
<
00 __ 1
.~
< < I
•
"----------------------------------------------------- ~
~
t
69
°•
g
000
•
o+}q
0.
°•
'i
'i ,
o '
:Iu
° •
• °
o ..
.
~h BJ~
• . •
000 ~ ';:
• 0. p' •
?"
•
·,
•
··
•"
I •?
70
A
AC
C
A
AD
0
t"' ACTADTBC+BO
B
~
C BC
5o'nplilylrlg
B '(A,B,e,D, '" AC+AD+BC+60
'" A(C+D)+8(C+ O)
:: (C+C) (MB)
0 BO
0
(C+O)
"
L-
A t=AC+AO+BC+BD=
(A + 6 ) I (A+B}(C+D)
B
e
Fig. 4-21 . Simplified lOgic circuitry resulting from simplifying logic equations.
AC = AC(l)
=AC1B+BL
= ABC + ABC
= ABC (I) + ABC (1)
= ABC (15 + D) + ABC(D + D)
= ABCD + ABeD + ABCD + ABCD
The final expression represents four of the maxtenns of the
term AC. Also note that a two-variable term is represented by four
SQuares, A study of the diagram will reveal that a term with one
variable i s represented by eight squares, a three-variable term by 2
squares, and a four-variable term by 1 square.
To illustrate the use of the Veitch diagram, the logic equation
B
5 Variables -B o F
D
cl e c I e Ie
6 Variables
72
• ,.
73
A
-A
AB~i5 ABeD ABeD ABeD -D
1 2 3 4
B
ABeD .lloBCD ABeD ABeD
- --
5 6 7 8
--
ABeD ABeD - --
ABeD ABeD
D
-B 9 10 11 12
--
ABeD ABeD
----
-ABeD ABeD -
D
13 14 15 16
C C C
A A
- 1 1
B ---
ABeD ABeD ABeD
-- - ---
ABeD -
D
1 1 1
-c c c-
FIQ. 4-25. Plottmg of the logic function.
74
a. If 1's are located in adjacent squares or at opposite ends of
any row or column, one of the variables may be dropped.
b. If I's fill any ofthe following locations, two of the variables
may be dropped: any row or column of squares, any block of four
squares, the four end squares of any adjacent rows or columns, or
the four comer squares.
c . If I 's fill any of the fo llowing locations, three of the variables
may be dropped: any two adjacent rows or columns, the top and
bottom rows , or the right and left columns.
d. To reduce the original equation to its simplest form. you
must simplify until aliI's have been included in the final equation.
The digit "1" may be used more than once, and the largest possible
combination of 1'5. in groups of 8, 4, 2, or as a single 1 (block).
should be used.
Squares 1,5.9, and 13 are combined (Fig. 4-26) using rule (b) to
yield AC (1's in Band B cancel).
Squares 3,7, 11 , and 15 are combined using rule (b) to yield AC.
Squares 1,2,5 , and 6 are combined using rule (b) to yield AB.
Squares 15 and 16 are combined using rule (a) to yield ABO.
To keep track of the squares combined , draw loops around the
combined squares. When you do this, the Veitch diagram takes on
the appearance shown in Fig. 4-26 .
AU I's have been used; therefore, a logic equation can now be
written
-
A A
B
I, 2,
" •
3, Ii
5, 6, 7,• 0
10 12
-B 9,
13, I.
11,
15,
-
16, 0
- "
c c C
75
A
B 1 2, 3 4
5 6 7 8
c I c c
Fig. 4-27. Three-variaOie Veitctl diagram showing statement True.
which agrees with the simplified logic equation obtained by the use
of the simplifying theorems.
A Veitch diagram provides a convenient means of fi nding the
complement of a logic equation. This is done by plotting the original
equation on a Veitch diagram and then putting 1's on another Veitch
diagram everywhere except where the original diagram has l 's. An
example will illustrate the procedure.
EXAMPLE,
If, f = ABC
What is f?
f=A+B+C
76
A
B
,.-...
"
5,
2
6,
< :>
7,
4,
B,
c I c Ic
Fig. 4·28. Three-variable Veitch diagram showing statement complemented.
using the actual logic symbols, the conventional switches are again
used to mechanize an equation. The equation:
f = AB + AC + AC + ABD
will be mechanized.
It will be recalled that the AND function used a series switch~
ing circuit, and the OR function used a paralle l switching circuit.
Therefore . the mechanization of the above equation is as illustrated
in Fig. +29. This diagram illustrates the AND and OR functions.
The AND funct ions are each series-connected switch grouping of
the four possible parallel paths-the OR function. The logic dia-
gram for the above equation and mechanization are shown in Fig.
4-30, which uses the logic symbols for the AND and OR gates. A
~FA
,
,,, T
,
..
"""'.
/'
I T
I
Switcf1C Swilct\O
i~'
I
, ,
,, ,T I
, ,'T
, ,, ~j,.'
,,'T,
.T
,,
.T
T
,
.T
-
Of
r :: True wNon UT and FalH when noI LIT
n
logic equation can be always mechanized by a switching network.
This involves the fo llowing four steps:
\. f=AB+AB+AB
2, f = A + ii
A _ _' - '
' = AB +AC+AC+AC+ A8D
C-- ,--_./
A_ --r-___,.
A+B+C
-
3 --
ABC
14
A+B+C
5 -ABC- 12
A+B+C
7 --
ABC
10 -
A+B+C
9 -ABC 8
A+B+C
11 -
ABC • -
A+B+C
13 -
ABC 4 A+B+C
15 2 A+8+C
ABC
terms of two variables . and they are (AB. AB, AS AND AS).
Likewise. there are four maxterms of two variables. They are (A +
B), (A + 8), (A + B) and (A + B) .
There are eight minterms and e ight maxlerms of three vari·
abies as shown in Fig. 4-31. As might be expected. there are 2"
minterms and 2" maxlerms when n variables are considered.
Observe that the mimenn identified by an odd number in the
upper left comer of each block in the left column relates to the next
higher even number in the right column in accordance with DeMor·
gan's Theorem. For example. the maxtenn in block 'H2 is the
complement of the mintenn in block 'HI.
79
Chapter 5
Introduction to Programming
The process of writing instructions to control the operation of a
computer is called programming. Most of the remaining chapters in
this book will deal with programming in one form or another so we
will only briefly describe the basic technique at this point.
In general, computer programming refers to the analysis and
planning of a problem solution. The phase of instruction writing is
referred to as coding. Here are a few of the concepts involved in
programming.
Binary Operation: The programming process will be de-
scribed in terms of the most common form of digital computer. This
machine operates internally entirely in binary (base 2) arithmetic
logic, and is arranged so that information is stored and accessed in
units termed words. The ATARI uses words that are 8 bits in size.
Decimal Operation: The other broad class of computers
operates logically in the decimal system (although decimal digits
are fabricated within the machine by combinations of bits) and
stores and accesses its information in units of individual characters
such as digits or letters. This machine is referred to asa character-
addressable or variable-ward-length computer.
Notation: The ATARI operates internally using the binary
number system. Skilled programmers often work using the octal
(base 8), or hexadecimal (base 16) systems . These systems are
simply conveniences for programmers to use while they work.
However, the discussion here will be in terms of decimal values to
80
simplify understanding of computer principles. It must be kept in
mind that the basic nature of the machine is binary.
Number Operations: The purpose of a computer is to ma-
nipulate infonnation that is stored within the machine in the fonn of
binary numbers. These numbers can be treated as symbols and can
represent alphabetical infonnation. They can also be treated as
numbers and can be used arithmetically. Each word contains one
number and its associated algebraic sign (positive or negative). The
instructions which dictate the operations to be performed on such
numbers (data) are also numbers and are also as a single word in the
same physical medium as the data . The stored programming con-
cept presumes that there is no physical difference between these
two types of numbers and that the instruction numbers may also be
manipulated, in the proper context, as data.
Addresses: Each word in storage is assigned an address in
order to refer to it, in a manner analogous to postal addresses. The
addressing scheme is part of the hardware of the machine, and is
wired in pennanently. Word addresses range from zero to the
storage size of the machine. Any word may be loaded with any
desired information. Some of this information is the data of the
problem being processed; the rest is the instructions to be exe-
cuted. The machine is designed basically to execute instructions in
the order in which they are stored, advancing sequentially through
the instruction words at addresses that increase by one.
Instruction Format: Each instruction contains two basic
parts: (1) a coded number that dictates what operation is to be
performed and (2), the address of the word (data) on which to
perform that operation.
Programming for a digital computer could be done in binary,
but becomes increasingly difficult as programs get longer. For this
reason , programmers prefer to work in languages that are at a
higher level. In higher-level languages, mnemonic operation codes
are used in place of numbers, and all absolute machine addresses
are replaced by symbols. These alterations greatly speed up the
work of the programmer. High-level languages permit a format that
fits the problem rather than the machine. BASIC is one such lan-
guage that is readily adapted to both home and business applica-
tions.
BASIC
BASIC means Beginner's All-Purpose Symbolic Instruction
Code.It is a high-level language that a beginning programmer can
81
understand with relative ease. An interpreter that changes the in-
structions in BASIC to terms that can be used by the machine must
be present in the computer when a BASIC program is used. BASIC
was developed at Dartmouth College in the sixties for educational
purposes. It is, in fact, probably the simplest higher-level language
available at this time.
BASIC is widely implemented on microcomputers like the
ATARl800, and it is also available on most large scale computers.
1. Economy of s torage
2. Speed of computation
3. Accuracy
4. Simplicity
With these four basic objectives in mind, let's see what steps
are involved when programming a computer.
82
four basic objectives of programming . especially simplicity.
When you define a problem and then propose a feasible solution
to it, you are developing what is called an algorithm, or a s tep-by-
s tep solution to a specific problem. Once this is accomplished, you
must tai lor the solution to fit the computer's capabilities. or the
solution will be useless. You must define both the problem and
solution in tenns of what the computer can do.
Next, you should draw a fl owchart of the solution. Basically . a
flowchart is the algorithm illustrated in graphical fonn. See Chapter
13 for more details. After the solution is flowchaned, it can be
coded into a language that the computer understands. You must then
check the program for errors and finally, document it.
83
This precise definition of what the program is to accomplish is
the first and most important part of program writing. With this out of
the way , we can continue to the second step.
Make a step-by-step plan of how the progTam goals will
be achieved: There will usually be more than one solution to a
problem , so the exact method of developing the step-by-step plan
will differ with each programmer. In most cases , however, it is best
to rely on the technique known as flowcharting. A flowchart is
simply a set of symbols that indicate the steps of program execu-
tion. Each block in a flowchart usually contains one and only one
instruction. The standard flowcharting symbols appear in Fig. 5-1.
The tenninal symbol is used to indicate the beginning and
ending points of a program; words like "s tart ," "end ," or "stop" are
nonnally written ins ide it. The input/output symbol is used to
indicate an input or output operation. The decision symbol indicates
a decision or yes/no question , with the nature of the decision
nonnally written inside the symbol. As might be imagined, the yes
and no paths provide two directions for the program to continue in ,
depending upon the result of the decision.
(~-)
(A) TenTWII 5''''
~-
o <>
(8 ) inp.n IDlrtpul (e ) 0ecW0r!
D (0 ) Proeest:
o
(E) Conoector (F) KeytIoerCI
i
[J +-- ---+
84
The process symbol is a rectangle. It indicates operations such
as add. subtract. toad accumulator. or SLOre . The circte is used to
refer from one point to another when it is difficult or impossible to
physically connect them with a line . For example, corresponding
letters placed in these circles could show the continuation of a
program from one sheet of paper to another.
The keyboard symbol is used to represent an output to a video
terminal or input from a keyboard. The document symbol generally
represents an output on a printer. Finally, the arrowheads and the
flow lines depict the relationship between symbols and identify
operational sequences.
To write a flowchart for our sample program. we must take the
description of exactly what the program is to accomplish and pro-
vide the appropriate flowchart symbol for each step.
Slap
An programs must have an Ending Point.
85
Imple me nt t h e step-by-step pla n with progra mming
s ta te ments : Before we can actually write the program, we must
have an understanding of standard programming statements. The
BASIC programming statements used in this program are shown in
Table 5-1. Let's apply these statements to accomplish the steps
shown in the program nowchart.
The first step in the nowchart is "Begin". Since we do not need
a program line to "begin", we will take this opportunity to write a
REMark statement that gives the title of the program:
30 INPUT C
The next step in the nowchart calls for printing the resu lts of
the computation.
The last step on the nowchart is the end of the program sowe'l!
write
60 END
86
Tlbl, 5-1. BAstC Proiralllmlni StIteMnts.
87
10 REM .. CELSIUS TO FAHRENHEIT ..
20 PRINT "CELSIUS TEMP"
30 INPUT C
40 LET F = I.S'C + 32
50 PRINT C; "C EQUALS " ;F; "F"
60 END
CELSIUS TEMP?
15
15 C EQUALS 59F
59 F EQUALS 15 C
UNE NUMBERS
From the previous discussion. we know that a BASIC program
is composed of a series of statements which manipulate data. Each
BASIC statement occupies one line. Each line is identified by a
number which appears at the beginning of the line . Obviously, no
two lines may use the same number. In most cases, the computer
88
executes the statements in the order of their line number, and
these line numbers are normally increments of ten; that is, 10,20.
30, etc. This gives the programmer nine numbers between state-
ments to add other statements later to expand the program if
necessary .
BASIC STATEMENTS
Earlier in this chapter you were introduced to BASIC state-
ments, but since these must be thoroughly understood to program
in BASIC, let's review these statements and go into more detail.
There aren't really very many to learn . so make sure you know and
understand each before continuing with programming.
Let: The let or replacement statement is used to assign a value
to a variable name. For example, in our temperature conversion
program , 40 LET C = 5/9.(F-32) assigns C the value of 5/9 times
the Fahrenheit temperature minus 32 degrees.
Successive let statements can be used to place a number of
constants into different variables. For example, suppose we wish to
place the four constants 22, 32, 43, - 12 in variables A, B. C, and 0
respectively. Four let statements could be written as follows:
10 LET A = 21
20 LETB=32
30 LETC=43
40 LETD=-12
The four constants 21, 32, 43, and -12 are then assigned to the four
variables A. B. C, and D.
Read and Data Statem ents: While the let statement allows
for the placement of a constant into a variable, its use becomes
unwieldy if a large number of constants are to be entered. In the
above example , four statements were required to enter four con-
stants. The read and data statements are used to overcome this
difficulty. To assign the four constants in the above example. only
two statements are required. One statement identifies the con-
stants (data). It would be written:
89
20 READ A,B,C,D
The first constant is assigned to the fi rst variable listed , the second
constant to the second variable. and so forth. Thus, with only two
statements we could assign dozens of constants to corresponding
variables. The read and data statements are the most common way
of entering cons tants into the computer.
Print Stateme nt: Once the program has finished, we need a
means of displaying the results. The print statement is used for this
purpose. It consists of the word print followed by a list of the data
and variables to be put on the screen. For example, if we wished to
prim out the values of variables A,B,C, and V, we would write:
20 PRINT A,B,C,D
SOLETX=3
60 PRINT " X=" ,X
X=3
90
r ..... 5-2. Symbols Used in tile BASIC Proaran!mina LaIllUIJI.
Symbol Meaning
= is equal to
< is less than
> Is greater than
<= Is less than or equal 10
>= is greater than or eqI.Iallo
<> Is not equal to
The two constants can be compared in any of six different ways. The
symbol explaining the relationship of the two constants are shown in
Table ~2.
The if.. .then statement takes the form:
10 ON X GOTO 20,30,40
91
For... To and Next Statement: These statements are used
to control the repeated execution of a program loop. When using
these statements, the program loop begins with the for ... to state-
ment and ends with a next statement. The format of the fo r ... to
statement is
15 FOR X = 1 to 100
NEXT X
This infonns the computer that the first pass through the loop is
complete and that X should be set to its next sequential value. In
this case, X is incremented by 1 to the value 2 and the loop is
repeated . The loop is repeated again and again with X being set to
every value from 1 to 100. Each time the next X statement is
executed, the new value of X is compared with the final value of 100.
This continues until X has assumed all values called for in the
for .. .to statement. The loop is repeated for the last time when X is
set to 100 . At this time, the program leaves the loop and executes
the first statement following the next.
As a simple example, consider the loop below
10 FOR X = 1 TO 5
20 PRINT X
30 NEXT X
The computer will set X = 1, then print it. X will then be in-
cremented and the loop repeated. The program above will produce
the following output:
1
2
3
4
5
92
In our example, X was set to all values for 1 to 5. The for ... to
statement could just as easily have called for all values from 1 to
l OOOorfrom 13 to 20, etc. The variable which assumes these values
need not be X. Any variable could have been assigned. Most of the
time when a for ... to statement is written, a step size of 1 is used. In
our example, X was stepped (incremented) by 1 each time through
the loop. However, other size steps can be specified by the fo r ... to
statement. For example the statement:
93
row and first column is A(l, 1). By the same token, the third number
in the second column is A(3,2). Arrays are useful when large
amounts of data must be handled nonsequentially or when alterna-
tions of data must be achieved.
Dim Statement: The dim or dimension statement is used to
deal with lists and two-dimensional arrays in BASIC. It allocates
storage and assigns names to the lists and tables to be used. The
dim statement has two formats:
30 DIM A(6)
40 DIM F(lO,4)
94
puterto be displayed in its entirety. This allows you to review, edit,
or modify the program conveniently without retyping it.
REM Statement: The remark statement lets the program·
mer insert notes, comments, or messages of any kind into the
program. The remarks do not affect the program itself. They simply
allow you to tell what the program is, how it is used, and how to use
it. For example, 10 REM PROGRAM FOR COMPUTING GRADE
AVERAGE will cause the statement PROGRAM FOR COMPUT·
ING GRADE AVERAGE to be printed when the program is listed.
Input St atement: We have seen that data can be assigned to
variables by using the let statement or by using the read and data
statements in pairs. There is also a third method of assigning
values. It involves the use of the input statement. The format of the
input statement is
50 INPUT A,B ,C
95
Without the print statement the computer simply prints a
question mark. However , with the print statement the computer
prints:
96
Chapter 6
97
modules. The Console also holds the keyboard, cartridge slots,
controller jacks. and a serial va Port for connecting to peripheral
components.
The TV switch box allows you to change from regular TV
reception to computer display by moving the sliding switch on the
box. The ac power adapter plugs into a nonnal wall socket and
converts it to the low voltage used by the ATARI BOO.
The ATARI program recorder provides software storage in
computer readable fonn. You may purchase preprogrammed cas-
settes from your AT ARI retailer or other software and computer
dealers and you may use any blank, high-quality audio cassette tape
to save programs you write yourself.
UNDERSTANDING SOFTWARE
The ATARI BOO Basic System is very much likeanemptysheet
of paper. It has the potential for an unlimited number of applications,
but that potential remains donnant until you add the software.
The software that accompanies the ATARl computer consists
of programs considerably more complex than those you studied in
the preceding chapter. The foundation programs are supplied in
the operating system ROM module. They activate the keyboard and
the screen display so that you can create pictures and text one
screenful at a time. These programs control the flow of all infonna-
tion within the computer.
Usually you add a second level of software to the ATARI BOO.
This can be done by inserting a cartridge into the cartridge slot.
This software transfonns the AT ARI 800 into a special purpose
machine for playing a game, presenting educational material. ma-
nipulating infonnation or entering programs through the keyboard.
The program recorder and optional floppy disk drive provide addi-
tional methods for loading programs into the computer.
ATARJ application canridges contain programs that are per-
manently recorded in a ROM within the cartridge. They control the
computer in machine language, the most intricate level on which to
manipulate the computer. These cartridge programs produce full-
color. animated displays and complex electronic decision-making.
Many entertaining game cartridges are available. and each is de-
signed to be easy to learn but difficult to master .
Other ATARI Cartridges have a more serious purpose. They
are tools for increasing your speed and accuracy in handling words
and numbers . ATARl programmers identify and analyze problems
of interest such as checkbook or mail list management. They then
98
design a generalized solution to each problem, program that solu-
tion in machine language, and record it in the cartridge. When you
insen the cartridge, the AT ARI 800 repeats this preprogrammed
solution, substituting your data from the keyboard into its equa-
tions. Although all cartridges operate in the same general fash ion,
each cartridge causes the AT AR! 800 to use the screen display ,
keyboard , and/or controllers in a different way. You will need to
read the instructions which accompany each cartridge for specific
details.
KEYBOARD
The ATARI 800 Keyboard (Fig. 6-1) has alphabetic, numeric .
graphic and screen editing functions which are detailed in the
paragraphs to follow. Most keystrokes produce a visible change on
the display screen. However, there are a few keys which are only
used in combination with others. To investigate the effects of each
key , power up your AT ARI 800 without a cartridge in the cartridge
slot and you will see the display pictured in Fig. 6-2. Notice the
SQuare below the A in ATAR!. This square is called the cursor. A
cursor is a mark which indicates where the next character you type
will appear on the screen. The ability to move the cursor to any
position on the screen and change the characters being displayed is
one of ATAR! 8oo's most useful features.
A glance at the keyboard (Fig. 6-1) tells you that it closely
resembles that of an ordinary typewriter. In using this keyboard,
remember that each key will repeat its function rapidly if you
depress it for longer than one second.
Special Keys
Pressing either of the ~ keys and holding it down while
pressing another key will produce the upper case letter or the
character shown on the upper half of the key , the exclamation mark
or quotation mark, etc.
The control key,.ktd, functions as a second type of shift. When
it is depressed in conjWlction with the escape (esc) key and another
key , a character from a completely new set of characters appears on
the screen. These "graphic" characters can be used to produce
interesting pictures, designs,and graphs either with or without the
ATAR! BASIC cartridge. Striking a key while holding down the ctrl
key will produce the upper-left symbol on those keys having three
functions.
Find the caps/lowr key on the right hand side of the keyboard
99
Fig. 6-2. The "memo page mode."
and press it once. You can then type lower case letters, numbers,
some punctuation marks, and math symbols by pushing single keys.
You can see that the caps/lowr key locks all the alphabet keys
into their alternate character displays. The non-alphabet keys-
those which show two or three characters on the keytops-remain
unchanged. Note that this is not the way the shift lock works on an
ordinary typewriter. Try out the caps/lowr function following the
chart in Fig. 6-3. You will find this feature useful when creating
pictures with graphic characters and when programming in BASIC.
The return key has three functions. First , it moves the printing
mechanismtothe left margin and down one line. The ATARI 800
will do this automatically after 38 characters even if the return key
hasn't been pushed. The largest number of characters that will fit on
a single physical line across the screen is 38. However, the com-
puter allows as many as three display lines (116 characters) to be
combined into a single entity called a logical line. Logical lines will
be important when using the screen editor and when programming
in BASIC language.
Second, the return key can be pushed to indicate the end of a
logical line for the computer. At times it will be convenient to push
the return key at the end of each physical line, making it coincide
with each logical line . At other times the end of a logical line will not
coincide with the end of a display line .
Third , the return key activates the computer. The specific
action taken depends on the software that is controlling the com-
puter at the time the return key is pushed.
The dr-set-tab key operates much the same as the tab keyon a
regular typewriter. The shift and dr-set-tab keys set a tab stop at
the cursor position. The ctrl and dr-set-tab keys dear the tab stop
under the cursor. The dr-set-tab key by itself spaces the cursor
101
DOTHIS SEE THIS COMMENTS
PRESS TYPE
HOLD DOWN 1mABCD ••• UPPERCASE
em
PUSH
TYPE
ABeD •••
ALPHABET
LOWERCASE
ALPHABET
liD
HOLD DOWN
PRESS TYPE
l3ABCD ••• CONmOL
GRAPHICS
eJ ON ALL
LETTER KEYS
RetumKey
over to the next tab stop. This key operates on logical lines so you
can set tabs at any position as far as the 116th character.
The AI.. Key switches characters into inverse video. Press it
again to go back to normal display.
The Break Key intelTIlpts the computer while it is busy fol-
lowing instructions. Refer to the cartridge instruction sheet that
came with your computer and to Fig. 6-4 for its exact function.
The Four Keys to the right of the keyboard allow you to select
different starting positions within a cartridge. Each starting posi-
tion is the beginning of a game or an application stored within a
single cartridge. Push the system reset key to stop the computer
and start from the beginning of the next game or application. Push
the option key to choose among the variations possible within a
game or application. After you have made your choices with the
select and option keys, push the start key to begin the action. More
complete instructions are provided with each cartridge.
Edit Features
In addition to these special function keys, there are keys that
allow inunediate editing capabilities. These keys move the cursor
and modify the display. They are used in conjunction with the shift
and ctrl keys.
The following key functions are described in this section.
CTRL CLEAR J~
SHIFT CLEAR
CTRLINSERT
CTRL DELETE
CTRL+ SHIFT INSERT
CTRL-. BREAK
102
CTRL+ SHIFT DELETE ESC
CTRL + DELETE
Homing the Cursor. Pressing the shift and clear or ctrl and
clear keys simultaneously erases all characters on the screen and
moves the cursor to the heme position at the upper left comer of the
screen.
Moving the Cursor. To move the cursor press the ctd key
I
--
-,
--
Inserts one character apace.
_._3
Deletes one character or s~.
Rings buzzer.
Indicates e nd-.of-nle.
Key' UR<! W l t h _
_ _ InSl'rls one physical line.
103
CTRL'" : Moves cursor down one physical line without chang-
ing the program or display.
CTRL+: Moves cursor one space to the left without disturbing
the program or display.
Like the other keys on the ATARI keyboard, holding the cursor
control keys for more than If.! second causes the keys to repeat.
When the cursor is placed on top of a letter , that letter is shown in
"inverse video" on the screen. When the cursor is moved away from
the letter, the letter returns to its normal state. If the cursor is
placed on top of a character and then another key is pushed, the new
character will replace the original one.
Line Insert Function: Press the shift and insert keys simul-
taneously to create a space for a new line. The logical line that
contained the cursor, and all lines below, it will be moved down one
line. Be aware that any information on the bottom line of the screen
will be lost.
Character Insert Function: Press the control and insert
keys simultaneously to a space for a new character. The character
under the cursor will be moved to the right. The rest of the line will
also s hift to the right. The cursor remains on the space which is now
available for a new character .
Character Erase Function: Pressing the delete back s key
erases each character as the cursor moves back one space at a time.
The total length of the line remains unchanged.
Line Delete Function: Pressing the shift and delete back s
keys simultaneously removes one whole logical line. If there are
lines below the one that was deleted, they will all move up one line
leaving a new blank line at the bottom of the screen.
Character Delete Function: Pressing the ctrl and delete
back s keys erases the character under the cursor by moving all the
characters to the right of the cursor one space to the left. The lines
become shorter.
The Esc (escape) Key disables the cursor control move-
ments and prints a graphic character instead. For example, press
the esc key; then hold down the ctrl key while pressing the delete
back s key. Instead of the text moving to the left. you will see a
special graphics character displayed. This function will prove very
useful when you begin programming in BASIC. The characters
produced in this manner are shown in Fig. &-5.
TheJlKey switches characters into inverse video. Press it
again to go back to normal display.
The Break Key interrupts the computer while it is busy
104
00 THIS
•• ••
PUSH PUSH
• •
••
PUSH
••
•
•• ••
PUSH PUSH SIMULTANEOUSLY
•• ••
••
•• ••
••
- • ••
••
Computer Keys
The e k~ 'Iwitc~ cNracten into inv_ video Prt'u it allin to 10 back 10 normll
displjy
_ intl!'fTUptJ tM cornputl!'< whil@ it I! busy followi"1 instruction'! Rri@ftolM
cartridl@instructlOnsheet for ih@UCI function.
PROGRAM RECORDER
The ATARI program recorder is used with a cassette to hold
blocks of software too large to be maintained in cartridge fonn.
Programs, recorded on magnetic tape, are copied by the computer
from the tape into RAM memory. You can nut or modify these
105
programs by entering instructions through the keyboard. You can
also type your own programs into memory, and then store them on
tape for later use or modification.
The ATARI program recorder resembles an ordinary audio
cassette tape recorder. Its playback and recording levels have been
pennanently set at the correct volume for use with the AT ARI
Computer.
The instructions with each program cassette type on the
keyboard to have the computer begin to load the tape. After the
program is completely loaded into the computer, the tape will stop
automatically. Press the stop-eject button on your recorder to tum
off the motor . Now type a command or press the computer system
key labeled "start" -whichever is specified on the instruction
sheet-to begin using the program.
106
are usually created in three stages-design, coding and debugging.
During design you choose a task for the computer and analyze it into
its component parts. During coding you translate these parts from
their English or mathematical form into a computer language, in this
case ATARI BASIC. Next you type your coded program into the
ATARJ 800 computer. As each line is typed, ATARI BASIC will
check it and report any mistakes in coding. After you have corrected
these mistakes in coding, you can try to run your program. In other
words, you can direct the computer to follow the set of instructions
you have given it. Often you find you have made an error some-
where. The ATARI 800 may succeed in running your program, but
the result is not exactly what you wanted. Perhaps you have made
an error in design and need to go back and plan your program more
carefu11y. At other times the computer will tell you that it can't
follow your instructions as given because they contain logical or
grammatical errors. You have made an error in coding or typing. At
the third stage, debugging, you find and correct all of your remain-
ing errors. You continue to run and debug your program until the
ATARI 800, under the control of your program, produces the re-
sults you desire.
Note that no computer actually "solves problems" or "answers
questions" by itself. Using your design . the computer performs the
instructions you have given it. It mechanically produces a "solution"
to a problem whenever you run the program.
As mentioned in Chapter 5, BASIC (Beginners All-Purpose
Symbolic Instruction Code) was invented so that people could learn
to write programs quickly and easily. To you, the user , the BASIC
language is a set of rules stated in English which tells you how to
give the computer the instructions it needs to do your bidding. To
the computer , BASIC is the same set of rules written in machine
language. The rules enable it to translate your BASIC instructions
into action. We call this machine language program that "translates"
BASIC into machine language the BASIC language interpreter. It is
contained in the AT ARI BASIC Language Cartridge. The program
which you write is called the BASIC source program. You enter
your source program into the ATARI's random access memory by
typing it on the keyboard while the BASIC cartridge is in the
cartridge slot. The ATARI uses the operating system programs (in
the operating system ROM), the BASIC language interpreter (in
the cartridge), and your BASIC source program (typed on the
keyboard or loaded from cassette and stored in RAM) in order to
follow the instruction you have written in your program.
107
WRITING BASIC SOURCE PROGRAMS
This section will give yOll a brief introduction to actually
programming the ATARI 800 computer-in ATARI BASIC. You
were given a brief introduction to fundamental BASIC programming
in an earlier chapter , but here you will actually start to press keys on
the keyboard and see the results on the screen. Follow the instruc-
tions exactly. but don't expect to understand all of them at this time.
You'll eventually have a good understanding of programming, but it
will have to come with time and experience. If you are a program-
mer experienced in using other forms of BASIC, the followi ng
paragraphs will give you insights into ATARI BASIC specifically.
Remember, however, there is a great deal more to learn than is
presented in this chapter.
Firstofal l, let's explore the use of nine BASIC commands: run,
break. return , dim, print, input,list, if ... then, and goto. Start out
by inserting the BASIC cartridge and powering up. In the upper left
hand comer of the screen, you'll see the word ready. This is the
BASIC prompt. It is a message from BASIC to you telling you that
the computer is waiting for a command. You'll also see a small
square mark directly beneath the word ready. This mark is the
CUrsbr. It tells you where the next character will be printed.
Since ATARI BASIC language can only read upper case let-
ters, press the shift and capsJlOWT keys. This locks all letters into
upper case. Now type an English sentence
and push return. The screen will now appear as shown in Fig. 6-6.
Yes, ATARI 800 is awake. It is sending you a prerecorded
message saying that you have typed in, or entered, a line of charac-
ters which is not in its list of correct BASIC language codes. You
may find out more about your mistakes in the chapter on Error
Messages in ATARI BASIC in your ATARI owners' manual. Before
you look at this chapter , however, try entering the line again with
these changes. Type the line exactly as shown, including the word
print and the quotation marks:
Be meticulous when you type. The computer cannot guess what you
meant to include nor can it ignore extra characters. The computer
will display each character on the screen as you type. The line above
108
DO THIS COMMENTS
TYPE 1. BASIC prompt • This will disappear off the
top of the screen as new lines are added
at the bottom.
PUSH
2. You typed this line.
E5I 3. This Is an ERROR MESSAGE from
SEE THIS BASIC telling you that your source pr0-
gram cannot be interpreted.
The Nght and dart< colors are reversed at
the first Illegal character.
4. BASIC prompt
5. The cursor agaln.
is correct BASIC code. Now push the return key and the new screen
should appear as shown in Fig. 6-7.
If your screen display doesn't look like the one in Fig. 6-7,
check the display to make sure you have copied every character
exactly. Be sure to start your line with the cursor at the left margin.
When you have found your mistake push the return key and try
again.
Play around with the print command for a few minutes . You
may put any characters you like inside the quotation marks including
all the graphic and control characters described earlier in this
chapter. Experiment with the cursor controls and with logical lines
of up to 116 characters. What happens if you forget to put in the
quotation marks? Try it and see.
Occasionally you may "lose control" of your computer by
inadvertantly commanding it to do something you didn't anticipate.
H this happens, press the break key . U you have been using a
program the computer should display
U the break key doesn't work, press the system reset key. The
initial (blank) screen will be displayed.
You can also use the print command to turn your ATARI 800
into a calculator. Type the following on the keyboard.
1. READ Y
and push return . The display should appear as shown in Fig. ~8.
The ATARl 800 evaluates expressions in the same way you
were taught to do it in elementary school . Everything inside
parentheses ( ) will be done first. Then exponentiation (I\) will be
done . Exponentiation involves multiplying a number by itself a
DO THIS
TYPE
PRINT 45782 + 1111 1
PUSH
I RETURN'
SEE THIS
/
1, READY
2. PRINT 45782 + 111 11
3. 56893
4. READY
110
specified number of times. For example, 5 /\ 3 means 5 times 5
times 5 and is equal to 125. You will often see this expression
written 53. It is read "five raised to the third power". Type the
exponentiation symbol on the computer by pressing the shift key
and the key with the symbol /\ on it (The /\ symbol will be found in
the upper right-hand comer of a key near the right side of the
keyboard.)
All multiplication (. ) and division 1 is done next. Addition +
and subtraction - are pertormed last. If you have forgotten that the
order in which calculations are done is important, try a few prob-
lems. You will find that (4+6)/5 = 2, while 4+6/5 = 5.2, and 4/5+6
= 6.S.
The ATARI 800 will print any whole number value in the range
-999999999 to 999999999. It will express fractions and numbers
outside this range in scientific notation as a decimal number be-
tween one and ten times a power of ten. Forexample, if the value of
your expression is 12,345,678,909 the ATARI 800 will write it as
1.23456789E + 10. E + 10 means you must move the decimal point
ten places to the right to obtain the original number. You read
this number as 1.23456789 t imes ten to the tenth power
(1 0 ,()()() ,()()() ,()()()) .
You can enter any expression and the ATARI 800 will do the
arithmetic. Remember that the BASIC language does not tell you
the correct expression to use to solve number problems. You must
figure out how to calculate interest payments, sales commissions,
expected time of arrival, or whatever you want to know. BASIC
does have a large repertoire of arithmetic. algebraic. and trig-
onometric functions available, but you , the programmer, must tell
the computer how to combine them to produce meaningful results .
You will find a complete discussion of BASIC language arithmetic in
a later chapter.
Thus far, we have been using ATARI BASIC language in the
direct mode; that is. the ATARI 800 follows your command as soon
as you give it and then forgets about it. In the program mode, you
may give the computer as many as about two hundred lines of
instructions. Each line is then stored until the nm command is
entered. Then the computer follows one instruction after another
until the whole task is completed.
Although most BASIC commands can be given in direct mode.
only a few of them are useful to the beginner. The run command is
almost always used in direct mode. It is used to start a program at
the beginning . It is typed as a three letter sequence in upper case
111
only. No action occurs unti l you press the return key . This key
signals the computer to read what you have typed and to execute the
entire series of instructions. Pressing the break key stops the
program from running and displays the cursor. Break and return are
the only single key commands in BASIC. All others are typed as a
series of letters fo llowed by the return key.
If you wish to enter a program into the ATARlBOO using the
program mode, start each line at the left margin of the screen with a
line number. You may number your lines with any whole numbers
between one and 32767. You may enter program lines in any order .
However, the computer will rearrange them and execute them
s tarting with the line with the smallest number and proceeding to
the next higher numbered line until all instructions have been
followed. Most BASIC language programmers number their lines
by tens so that they have nine line numbers available in case they
wish to add new lines between the original ones.
To get started, power down and up once again. This will clear
out your RAM memory. Then print:
Continue by pushing return and then typing run; then press return
again. The display should appear as shown in Fig. 6-9 . You have just
entered and run a BASIC program!
To edit any line of BASIC code, use the display control keys.
Position the cursor over the character you wish to change and make
the corrections within a logical line. When the line is correct , press
the return key . The ATARlSOOwil1 put the corrected line in place of
DO THIS COMMENT S
TYPE 1 . ........ ,.,...._ ... progrwn:
'10 PRINT " WIZARD . ARE YOU I'IWAKEf"
SEE THIS
2. The 0CIn'Ip!hr fI:uw:I yow IIIoIIId irIIIIrucIion
PUSH
••- 1 '
""-,
3. A"" COII'IIlIIIhV III --. ". 0CJmIllMf •
..... you wIt1 hi BASIC PfIlII¥Il.
TYPE
"'.
PUSH
lEI
FIg. 6-9. Printing In the deferred mode.
112
the original one in RAM. To remove a whole line, type its line
number and press the return key. For practice, replace the word
"Wizard" in line 10 with your own name . Be sure to make your
changes in the numbered line 10, not the JinedispJayedafter"run."
List is the command that makes the computer display your
BASIC source program. Any time you wish to see the instructions
your computer is following, press break, type list, and press the
return key. Note that you may use the break key to interrupt the
computer even if it is running a program or calculating. All other
commands must be given only after the cursor is displayed. Com-
mands must be typed in uppercase or you will get an error message.
Now add the following lines to your program. Remember to press
the return key before beginning a new line that starts with a line
number. Be sure not to leave out the colons.
5 DlMA$(IO)
20 Input A$
30 IF A$ = "YES" THEN PRINT ''YOUR PROG
RAMMING CAREER HAS BEGUN.":GOTO 60
40 IF A$ = "NO" THEN PRINT "TECHNOLO
GY MAY PASS YOU BY ... ":GOTO 10
60 PRINT ''TIDS PROGRAM HAS ENDED."
You should know that BASIC ignores blank spaces unless they
are inside quotation marks so you can leave them out when you need
to save space. However, do put them in when yOll can so your
listings will be easier for people to read.
Run this program and answer the question "Are you awake?"
several times. Type your answer after the ? and then push the
return key. Run the program several times more. Try responding
Yes; lli; yss; No; and maybe. What happens when your answer is
neither 'YE "n'Or"NO"? The program should print the message in
line 60 and then end.
To understand what the computer is doing, examine the pro-
gram line by line . Line 5 sets aside a place in the computer's
memory for your answer to the question in line 10. Line 10 has the
command print "something." This something that you put be-
tween the quotation marks is called a string constant: string be--
cause it is a string of letters , numbers , and/or graphic characters,
and constant because it will remain the same every time you run this
program.
Line 20 has the command "input something". This means:
113
"Computer, wait until something is typed on the keyboard. Show
whatever is typed on the screen and store it in a space in RAM
memory labeled M. When the return key is pressed, go on to the
instruction with the next higher line number." A$ (read A string) is
called a string variable because it is a string of letters, numbers,
and/or graphic characters which will be different every time you run
this program. Each string variable within a single program must
have a different label. Many labels are available in BASIC, but for
now, limit yourself to A$ through Z$. Line 5 gave us space to store
ten characters in A$. If we expected a long answer we could save
more memory for A$ by using a large number within the paren-
theses.
Line 30 has if ... then print "something": GOTO 60. When the
condition fo llowing if is met, that is, when the computer finds the
letters Y-E-5 stored in the place in memory labeled A$, the instruc-
tions in the rest of the line are followed. It prints "Your Program-
ming career has just begun." The computer encounters the colon (:)
next. This tells it that another command is coming. The GOTO
command says "skip down to line 60 and ignore the lines in be-
tween."
When the condition is not met, that is. when the computer finds
that anything besides Y-E-S has been entered at line 20, the rest of
the line is ignored and the computer goes on to the next numbered
line. in this case, line 40.
Line 40 operates the same way as line 30 does. If anything but
N-O has been entered at line 20 . its condition isn't met. and line 40
doesn't print anything. The computer just goes on to the next
numbered line which is line 60. Line 60 prints its message, and
since there are no more lines, the program ends and ready is
displayed.IfN-O has been entered at line 20. all of the line 40 would
be executed . The message in line 40 would be printed and program
control would jump back to line 10. The program would begin over
again.
Suppose the programmer wants to demand an answer of"YE5"
or "NO" before the program will end . The computer must be
programmed to print a message whenever something other than
"YES" or "NO" has been entered. After this message, the question
should be repeated on the display screen. Try to figure out what line
to add to make the computer do this. There are many ways, but one
solution would be:
10 DIMN$(lOO)
20 DlMA$(20)
30 DlMP$(20)
110 PRINT "TillS IS THE OCEANS PROGRAM."
120 PRINT "HELLO, WHAT IS YOUR NAME";
130 INPUT N$
140 PRINT "OK, ";N$;
ISO PRINT ".NAME AN OCEAN THAT BEGINS WITH P."
160 INPUT P$
170 IF P$ = "PACIFIC" THEN PRINT "PERFECT.",GOTO
190
160 PRINT"THATISN'T THE ONE WE ARE LOOKING FOR.
TRY AGAIN."; GOTO ISO
190 PRINT "NOW NAME ONE THAT BEGINS WITH A."
200 INPUT A$
210 IF A$ = "ATLANTIC" THEN PRINT "YOU'RE TOO
GOOD, "N$;" . NOW GIVE SOMEONE ELSE A
TURN.",GOTO 120
220 PRINT "TRY AGAIN . REMEMBER SPELLING
COUNTS!", GOTO 190
The display on the screen will appear as shown in Fig. 6-6 for
this particular program. See if you can follow the program and the
answers on the screen. Does it make sense?
To delete line 20 from the above program, type the line number
and press the retum key. Merely deleting the line from the screen
display does not delete it from the program.
116
anotherprogmn, but the copy on the tape will be available until you
choose to erase it.
Set up your program recorder according to the instructions
provided by the manufacturer. See Fig. 6-11. If you already have a
program in the computer , be sure not to shut the power off at any
time. If you have not yet written a BASIC Source Program, write
one.
To transfer a program to tape:
1. Insert a blank cassette tape into the program recorder with
the recording surface toward you and the label so that you can
read it.
2. Push the rewind button and wait until the tape stops.
3. Push the tape-counter reset button until it reads 0000.
4. Push the stop-eject button once.
5. Type eSA VE on the computer keyboard. Then press the
return key. You should hear two beeps.
6. Push the record and play buttons simultaneously. Now
push the return key on again. You will hear a series of tones
indicating that the recorder is now being controlled by the
computer. The recorder will erase the beginning of the tape
surface for eighteen seconds; write the introductory header
needed by the computer; copy your program onto the tape;
then stop.
1.
117
7. It is always good programming technique to create a
backup copy of each program you wish to save. ATARI re-
comends that you store one program on each cassette and
keep a backup on a separate cassette-just in case!
8. If you are planning to store more than one copy of the
program on the tape, you may make your backup by repeating
steps 5 and 6. Be sure to write down the starting tape-counter
number for your backups as well as for your original pro-
grams.
9. Push the stop button on the program recorder.
10. Finally, write the name at your new program and its tape-
counter number on the cassette label and on a page which you
keep in the binder with your manuals.
To load a program from tape to the computer.
1. Insert BASIC source tape into the program recorder.
2. Rewind tape to the beginning and press the stop-eject
button.
3. Press the tape-counter reset button until it reads 000. If
you have put more than one program on a single tape, advance
the tape to the number where your program starts.
4. Type CLOAD on the computer keyboard. Then press the
return key. You will hear one beep.
5. Push the play button on the program recorder. Then push
the return key again. You will hear a series of tones as your
program is loaded.
6. When the tape stops, your program has been transfered
from the cassette tape to the computer.
7. Push the stop-eject button on the program recorder.
We have covered Quite a lot of material in this chapter so don't
be discouraged if you're somewhat confused at this point. Many
people are inexperienced in the kind of logical thinking required to
write programs, so allow yourself plenty of time to become com-
fortable with the step-by-step nature of the computer, and the
sometimes infuriating attention you must pay to detail. Remember
that inexperience does not mean inability. There are a tremendous
number of new and sophisticated concepts presented in this book.
You will want to read it many times and keep it handy so that you can
look up details when you forget them.
The chapters that follow will give you more experience in
BASIC programming on the AT ARI 800. They will include methods
of using graphics and sound.
118
Chapter 7
8K COMPUTER SYSTEMS
The ATARI 800 basic system contains 8K of random-access
memory and the ATARI 410 program recorder. This system config-
uration will accommodate all of the preprogrammed cartridges and
cassettes which make up ATARI'S 8K library. Some of the software
in the 8K library will require the use of hand held controllers which
are available from ATARI retailers.
In addition to the preprogrammed 8K library , the BASIC lan-
guage cartridge may be used in conjunction with the 410 program
recorder and any high-quality audio cassette to create and store an
Wllimited number of programs that you may want to write yourself.
The ATARI BASIC language offers you the opportunity to use
sophisticated graphic displays , four-voice sound, and input from the
controllers of your choice in programs limited only by your imagi-
nation.
THE PRINTER
The ATARI 820 printer may be added to any ATARI 800
119
system. Some programs in the BK library will offer the option of
printing program results as well as displaying them on the screen.
The 820 is a high-resolution. dot-matrix, impact printer which uses
standard 4-inch roll paper and will output up to forty characters per
second. Your printer should be connected in a "daisy chain" series
between the serial jack labeled PERIPHERAL on the side panel of
the ATARl console and the program recorder. See your manual for
details .
120
Ag. 7-1. The ATARI console.
CONTROUERS
There are several different controllers used with the ATARI
800. Each of them can be attached directly to the computer or to
external mechanical devices so that outside events can be fed
directly to the computer for processing and control purposes.
Pa ddle : A paddle consists of a knob that can be turned to send
a number between 1 and 228 to the computer. The number in-
creases as the knob is rotated counterclockwise. This number can
121
be used with other functions or commands to "cause" further actions
such as changes in sound or graphics. For example, you can use the
statement IF PADDLE(3) = 14 THEN PRINT "PADDLE AC-
TIVE." The ATARI console can control eight paddle controllers
numbered zero through seven from left to right.
Paddle Trigger (PTRIG): The paddle trigger is a button on
the paddle. You can use the PTRIG statement to detennine whether
the button is pressed (returns a value of 0) or not pressed (returns a
value of 1) on a particular paddle (0-7). For example. you can use the
statement IF PTRIG (3) = OTHEN PRINT "BOMBS DROPPED!"
Joystick: Many game cartridges available for the ATARI use
"joystick controllers to move images on the screen. All four joy-
sticks in a set are identical and can plug into any of the controller
jacks provided on the console. Each joystick has one button and a
stick which can be pointed in eight possible positions. Hold the
joystick with the button in the upper left-hand corner and push the
top of the stick in the direction that you want to move the object on
the screen. Always consult the instructions that came with the
cartridge to detennine whether or not joystick should be used and, if
so, what each position means.
If you wish to use the joystick in programs you write yourself,
use the stick command just as you used the paddle command. Each
joystick position will return a different number as shown in Fig. 7-2.
The joystick controllers are numbered from 0-3 from left to right.
122
14
11_--;
9 5
13
FIg. 7-2. Joystick oontroller movement.
123
""TNU ... '''' -W....
S,ln d h Hob
124
initial code in that file. DOS SYS contains both the file management
subsystem and the disk utility package.
When DOS is loaded into the computer RAM, it occupies a
special area in RAM that does not imeIiere wilh lhe memory
locations allocated for BASIC or assembly language programs. The
memory map in Fig. 7-4 shows lhe RAM locations occupied by the
DOS. After the disk drive system has been booted and the DOS SYS
file is loaded, the ATARI operating system turns control of the
system to the canridge. If na canridge has been insened, OS gives
cantrol of the system directly ta the disk utility package WUP).
The executive program in the DUP allows you to display the
DOS menu which lists the commands available to you. For example,
DELETE FILESPEC is menu selection D. It then executes the
selected utility. The DUP program also allows easy access to the
file management subsystem (FMS) without your having to under-
stand the logical structure of FMS.
""DOIIESS COHTENT!i
DlEC 1-.. I€'''''D€C ,-..
OPE~""TINQ SYST~ ~~
-,--
OISl' OP£~AnN(;: SVST~ IOIA"-1OO)
OISl' 110 '''FERS C, ,,Hen' DOS)
" ..
'00
C... rrenl COS)
FIIEE II......
\7.,
l!~ __________ ~F __ ._.. ___ __________
~ _.____ .. ________ . ____________ '
DPE~""TINC IYS1~ II""" C47'-2OO1
...
115'
10011 CASS£TTE '''FE~
P~INTEA .UFFEII
.~ '"
XO
", ".
,,.
'" ..
'00
PAIIE lEIIO
FLDATtNC "OINT '''''SIC )
C.. . . . ,~
... "
'"--------_.-_.--"-,---------_.--------- -----------------------------
"0
"
~EE ,ASIC II"""
"
Fig. 7-4. MerrIOI'y map (partial).
125
file Management Subsystem
This system provides a simple way of storing data on a diskette
by putting a logical structure on top of the fonnatted diskette.
Because of the file manager program. it is not necessary to keep
track the number of the sectors a program occupies . which sectors
they are, orhow to find a particuiarfile. FMS relieves the user of all
that responsibility.
Operations on a file, such as open, close, put. and get are also
controlled by the FMS. In addition, it defines the subfunctions
displayed on the DOS menu and are accessed by the DUP. The
subfunctions that are not defined by FMS are binary load, binary
save, run at an address, run cartridge. copy file, duplicate file and
duplicate disk.
The FMS organizes files using filenames you have assigned to
your files.
The disk directory contains a list of all the files on a diskette.
On demand, it displays the filename. the extender, and the number
of sectors allocated to that file. It will either display a partial list ora
complete list depending on the parameters entered. Wild cards can
be used in the parameters.
The ATARl DOS recognizes two "wild cards" which can be
substituted for characters in a filename. They are represented by
the special characters? and • . The first. ?, is used in place of any
single valid character . lfthere are 25 filesona diskette and you want
to display a list of those five-letter file names that begin with PROB
and have the extender (ending) .BAS, you would type PROB? .BAS.
This wild card can only be substituted for a single character. To
substitute for a variable number of characters, there is another,
more flexible wild card.
The • stands for any valid combination of characters in a
filename or an extender. The following examples illustrate the use
of the • .
PRO- .BAS will list all the program files on the diskette in
drive 1 that begin with PRO and have .BAS as
the extender.
126
A program may be loaded from the diskette using a wildcard in
the file name if there is no more than one file to which it is
applicable.
The ATARl 810 also has the capabilities to copy files. For
example. if you desire to copy a file from one diskette in drive 1 to a
second diskette in drive 2. this can be easily done. You can also
create a backup copy of a file on the same diskette by using the same
filename with a different extender, or even by using a completely
different filename.
BASIC COMMANDS USED WITH DISK DPERATIDNS
BASIC commands used to store and retrieve files are load,
save, list. and enter. Other BASIC commands used with disk oper·
ations are note. point, and DOS.
LDAD(LD.)
Fonnat: LOAD filespec
Example , LOAD ··DIJANINE.BRY"
This command causes the computer system to load the file
from the disk drive specified into the RAM. (Note here that it loads
the tokenized version of the program. The tokenized version is
shorter than the untokenized version in that, when recorded. this
version contains shorter interrecord gaps. However, when a
tokenized version is loaded, it also loads the program's symbol
table. If the program is altered or deletions are made, the symbol
table is NOT changed. This means that all variables which are
defmed in the original program still exist in the symbol table.
Therefore, it is recommended that load and save be used only when
saving a program is its final form.) When loading a file from drive 1,
it is not necessary to specify the drive number.
The load command can also be used as a BASIC statement to
"chain" programs. If you have a program that is too big to run in the
available RAM, you can use the load statement as the last line of the
first program. When the program encounters the load statement, it
will automatically read in the next part of the program from the
diskette. However, the second program must be able to stand alone
without depending on any variables, and the like from the first
program.
SAYE(S.)
Fonnat: SAVE "filespec"
Example, SAVE ·'D I JANINE.BRY"
127
This command causes the computer system to save a program
on a diskette using the file name designated in the command. Save is
the complement of load and stores programs in tokenized tonn.
UST(l.)
Fonnae LIST "filespec"
Example: LIST "D: DEMOPR.INS"
When a disk drive is spe<:ified, the list command causes the
computer system to move the program currently in RAM to a file on
the diskette using the filename specified in the command. This
command unlike save, saves the file in untokenized format.
ENTER(E.)
Format: ENTER "filespec"
Example: ENTER "O:OEMOPR.lNS"
This command causes the computer to move the file you
specify from the diskette into RAM. The program is entered in
untokenized form and is interpreted as the data is received. Enter,
unlike load, will not destroy a RAM-resident BASIC program, but
will merge the RAM-resident program and the disk file being
loaded. Uthere are duplicate line numbers in the two programs, the
line in the program being entered will replace the same line in the
RAM-resident program.
NOTE(NO.)
Format: NOTE #ae.xp,avar ,avar
Example: 100 NOTE 1I1,X,Y
This command is used to store the current disk sector number
in the first arithmetic variable, (avar) and the current byte number
(within the sector) in the second avar. The numbers specify the
current read or write position and thus indicate where the next byte
to be read or written is located. The note command is ~d when
writing data to a disk file. The information in the note command is
written into a second file which is then used as an index into the first
file.
Note: aexp indicates an arithmetical expression. The item
placed here must have a nwnerical. not a string value.
POINT(P.)
Format: POINT #aexp ,avar ,avar
Example: 100 POINT 112, A,S
This command is used when reading a file into RAM. The first
avar specifies the sector number and the second avar specifies the
128
byte within that sector where the next byte will be read or written.
Essentially, it moves a software-controlled pointer to the specified
location in the file. This gives the user "random" access to the data
stored on a disk file. The point and note commands are discussed in
more detail in your DOS Manual.
DOS(DD.)
Fonnat: DOS
Example: DOS
The DOS command is used to go from BASIC to the disk
operating system (DOS). If the disk operating system has not been
booted into memory , the computer will go into "Memo Pad" mode
and the user must press the system reset button to return to the
direct mode. If the disk operating system has been booted, the DOS
menu is displayed. To clear the DOS menu from the screen, press
the system reset button. Control then returns to BASIC. Control
can also be returned to BASIC by selecting B (Run Cartridge) on the
DOS menu.
DIRECTORY DF BASIC WORDS USED WITH DISK DPERATlDNS
The fo llowing is an alphabetical directory of BASIC reseroed
words (words reserved for BASIC) used with disk operations. Note
that the period (.) is mandatory after all abbreviated keywords.
130
RESERVED ABBREVIATION BRIEF SUMMARY
Word: OF BASIC STATEMENT
TRAP T. Directs execution to a
specified line number in case
of an input error, allowing the
user to maintain contro l of
program.
ERROR
CODE NO. ERROR CODE MESSAGE
131
9 Array or String Dim Error: Dim size is greater than
32767 or an array/matrix reference is out of the range
of the dimensioned size, or the array/matrix or string
has already been dimensioned, or a reference has been
made to an undimensioned array or string.
132
20 Device Number Larger than 7 or Equal to O.
128 Break Abort: User hit the break key during 110 oper-
ation.
136 EOF: End of File read has been reached. (NOTE: This
message can occur when using cassette files.)
133
141 Cursor Out of Range for particular mode.
134
Chapter 8
I/O Operations
This chapter describes input/output (VO) devices and how data is
moved between them. The commands explained in this chapter are
those that allow access to the input/output devices. The input
commands are those associated with getting data into the RAM.
The output commands are those associated with retrieving data
from RAM.
As stated before , in order for the computer to be a useful
machine, it must be able to communicate with its user. The user
must be able to supply the computer with the programs and data
which enable it to perform some useful operation. In addition, the
computer must be able to provide an output showing the results of
the computations. The input/output section of the ATARJ 800
provides this communications capability between the centra l pro-
cessing unit and the outside world.
The liD section of the computer buffers (stores temporarily)
and controls data transfers between the computer memory and the
various peripheral devices. In the ATARI 800, the data transfers
take place in the central processing unit. They are under the control
of a computer program being executed by the CPU .
In small digital computers the va section is extremely simple,
consisting generally of nothing more than some gating (devices that
output a signal when specified input conditions are met) and simple
control circuitry. In such computers , the data transfers take place
through the accumulator register. To read a word in from a
135
peripheral device. the computer executes an input instruction and
stores that word in the accumulator. Other instructions in the
program then cause that word to be stored in some specified mem·
ory location and/or used in a calculation.
Output operations are performed by first loading the ac·
cumulator with the desired word. An output instruction then causes
that word in the accumulator to be transferred to the peripheral
device. This basic form of VO system is simple and desirable for
many types of computer operations. However, it is very slow and
inefficient.
The simplest form of input/output for any digital computer is a
system of binary switches and lights. A group of switches can act as
a temporary storage resister for a data word. The switches can be
set to their off or on positions corresponding to the binary ones and
zeros in the word to be used or entered. A button on the computer
can be used to store that word. At the same time, output can be
accomplished by placing lights on the various registers in the
machine. The lights will indicate the ones and zeros stored, for
example, in the accumulator register. The operator can read the
numbers stored there by interpreting the binary number rep·
resented by the lights. Binary switches and lights provide a low
cost, simple means of input/output operations in a computer. All
digital computers have this type of VO capability.
Although binary lights and switches are widely used, they are
entirely inadequate for the bulk of most computer applications.
Consider the problem involved in storing, say. a 1000 word instruc-
tion program plus data in the computer's memory by using only a set
of input switches. The process would be extremely time-con-
suming. and the chances of making an error would be great. This
large program may produce a substantial number of output results
that the programmer wishes to observe. In such case, the pro-
grammer would have to observe the result ingworos one at a time on
the binary lights of the accumulator register. This would be time-
consuming and inconvenient. As a result, more sophisticated
input/output methods are required.
Most of the VO data in a digital computer is handled by
peripheral devices. Peripheral devices are machines that communi-
cate with the computer through the input/output section. You have
already seen several of these devices in Chapter 7. Peripheral
devices are, in effect, a man-made interface. These peripheral
devices not only speed up the input/output process tremendously,
136
but they also make it more convenient for the programmer and the
operator. Most peripheral devices use the decimal number system
and alphabet so that the operators and programmers do not have to
deal with binary numbers. In the ATARI 800. the input/output
keyboard simplifies the VO process.
137
16K or RAM is installed, the ATARI can use from one to four disk
drives. If only one disk drive is attached, there is no need to add a
number after the device eo<le D.
Screen Editor: (E:) Input and Output device. This device
uses the keyboard and the display to simulate a screen-editing
tenninal. Writing to this device causes data to appear on the display
starting at the current cursor position. Reading from this device
activates the screen-ed iting process and allows the user to enter
and ed it data. Whenever the return key is pressed, the entire logical
line within which the ansor resides is selected as the current
record to be transferred to the user program.
TV Monitor: (5:) Input and Output device. This device allows
the user to read characters from the display and write characters to
it using the cursor as the screen addressing mechanism. Both text
and graphics operations are supported.
Interface, RS·232 : (R:) The RS·232 device enables the
ATAR! system to interface with RS·232-compatible devices such as
printers. tenninals, and plotters. It contains a port to which the
8O-column printer (ATARI 825) can be attached.
138
1/ Mandatory character that must be entered by the
user.
"D 1 "AT A ~I 80 9. ~
Dev;ce
Code
~ t'L---+--f-_ F;le
Name
Device Period
Number required
(Optional) as separator
if extender
is used.
Required Colon - ' - -Extender
The close command simply closes files that have previously
been opened with an open command. Note in the example that the
139
aexp number following the mandatory # character must be the same
as the aexp reference number in the open statement.
Other commands which are most often associated with a single
device. but which may be used to control other devices, are de·
scribed on the following pages under the topics "Controlling
Keyboard VO" and "Controlling Output to the Screen"
Fonnat: CSAVE
Examples: CSAVE
100 CSAVE
100 CS.
This command is usually used in Direct mode to save a RAM·
resident program onto cassette tape. Csave saves the tokenized
version of the program. When you enter csave two bells ring to
indicate that you should press the play and record buttons simul·
taneouslyand then press the return key. Do not, however. press
these buttons until the tape has been positioned. It is faster to save a
program using this conunand rather than a save "e" command
because short interrecord gaps are used.
Notes: Tapes saved using the two commands, save and csave, are
not compatible.
It may be necessary to enter an Jprint before using csave.
Otherwise, csave may not work properly.
ENTER(E.)
140
Fonnat: ENTER filespec
Examples: ENTER "C"
This statement causes a program originally recorded using the
list command to be loaded into RAM. The program is entered in
unprocessed (untokenized) form. and is interpreted as the data is
received. When the loading is complete, it may be run in the normal
way. The enter command may also be used with the disk drive as
outlined in Chapter 7. Note that both load and cload clear the old
program from memory before loading the new one. Enter merges
the old and new programs. This enter statement is usually used in
direct mode .
141
This statement causes the computer to print data on the line
printer rather than on the screen. It can be used in either direct or
deferred modes. It requires no device specifier and no open or dose
statement.
The following program listing illustrates a program that will
add 5 numbers entered by the user.
10 PRINT "ENT ER 5 NUMBERS TO BE SUMMED"
20 FOR N=1 TO 5
30 INPUT X
40 C=C+X
50 NEXT N
60 PRINT "THE SUM OF YOUR NUMBERS IS ";C
70 END
142
Chapter 9
ARITHMETIC FUNCTIONS
ABS: This function returns the absolute value of a number
without regard to whether it is positive or negative. The returned
value is always positive.
CLOG: Returns the logarithm to the base 10 equivalent of the
143
variable or expression in parentheses. CLOG(O) should give an
error and CLOGO) should be O.
EXP: Returns the value of e raised to the power specified by
the expression in parentheses. In some cases, EXP is accurate only
to six significant digits.
[NT: Returns the greatest integer less than or equal to the
value of the expression. This is true whether the value of the
expression is a positive or negative number. This INT function
should not be confused with the function used on calculators that
simply truncates (cuts ofo all decimal places.
LOG: Returns the natural logarithm of the number or expres-
sion in parentheses . LOG(O) should give an error and LOG(l)
should be O.
RND: Returns a hardware-generated random number between
oand 1, bUl never returns 1. The variable or expression in paren-
theses following RNDis a dummy and has no effect on the numbers
returned. However, the dummy variable must be used. Generally,
the RND funct ion is used in combination with other BASIC state-
ments or functions to return a number for games, decision making.
and the like. Here's a simple routine that returns a random number
between 0 and 999.
10 X=RND(O)
20 RX=INT(lOOO.X)
30 PRINT RX
SGN: Returns a -1 if the value of an expression is a negative
number: a 0 if it is O. or a 1 if it is a positive number.
SQR: Returns the square root of an expression whose value is
positive.
TRIGONOMETRIC FUNCTIONS
ANT: Returns the arctangent of the variable or expression in
parentheses.
COS: Returns the trigonometric cosine of the expression in
parentheses.
SIN: Returns the trigonometric sine of the expression in
parentheses.
DEG/RAD: These two statements allow the programmer to
specify degrees or radians for trigonometric function computations.
The computer de faults to radians unless DEG is specified. Once the
DEG statement has been executed. RAD must be used to return to
radians.
144
SPECIAL PURPOSE fUNCTIONS
ADR: Returns the decimal memotY address of the string
specified by the expression in parentheses. Knowing the address
enables the programmer to pass the information to USR routines I
etc.
FRE: This function returns the number of bytes of user RAM
left. Its primary use is in the direct mode using a dummy variable (0)
to inform the programmer how much memory space remains for
completion of a program. Of course FRE can also be used with a
BASIC program in the deferred mode.
PEEK: Returns the contents of a specified memory address
location . The address specified must be an integer, or an arithmetic
expression that evaluates to an integer. between 0 and 65535. It
must represent the memory address in decimal notation. The
number returned will also be a decimal integer with a range from 0
to 255. This function a llows the user to examine either RAM or
ROM locations. In the first example below, the peek is used to
determine whether location 4000 (decimal) contains the number
255. In the second example below, the peek function is used to
examine the left margin.
Format: PEEK(aexp)
Example" 1000 IF PEEK (4000) = 255 THEN PRINT 255
100 PRINT "LEFT MARGIN IS";PEEK (82)
POKE: Although this is not a function, it is included in this
chapter because it is closely associated with the peek function. The
poke command inserts data into the memory location or modifies
data already stored there. Note that the data must be a decimal
number between 0 and 255. Poke cannot be used to alter ROM
locations. While you are gaining familiarity with this command, you
should look at the memory location using a peek and write down the
contents of the location . Then, if the poke doesn't work as antici-
pated, the original contents can be poked back into the location.
USR: This function returns the results of a machine-language
subroutine. The first expression (aexpl) must be an integer, or an
arithmetic expression whose value is an integer, that represents
the decimal memory address of the machine language routine to be
performed. Subsequent input arguments, aexp2, aexp3, etc., are
optional. These should be arithmetic expressions within a decimal
range of 0 through 65535. IT a noninteger value is used it will be
rounded off to the nearest integer.
145
N (Number of arguments on the stack-may be 0)
XI (High byte 01 argument X)
X2 (Low byte of argumen t X)
Y, (High byte 01 argument Y)
y2 (Low byte of argument Y)
ZI (High byte 01 argumen t Z)
Z2 (Low byte of argumen t Z)
146
Chapter 10
Programming
Techniques to Save Memory
This chapter includes hints on increasing programming efficiency
and conserving memory. These hints give ways of conserving
memory on the ATARI BOO. Some of these methods make programs
less readable and harder to modify, but there are cases when this is
necessary due to memory limitations.
1. In many small computers, eliminating blank spaces be-
tween words and characters as they are typed into the
keyboard will save memory. This is not true of the ATARl
800. which automatically removes extra spaces. Statements
are always displayed in the same manner no matter how many
spaces were used on program entry. Spaces should be used
Gust as in typing on a conventional typewriter) between suc-
cessive words and between words and variable names. Here
is an example:
10 IF A = 5 THEN PRINT A
Note the space between IF and A and between then and print.
In most cases, a statement will be interpreted correctly by the
computer even if all spaces are left out , but this is not always true.
Therefore use conventional spacing.
2. Each new line number represents the beginning of what is
called a new "logical line" . Each logical line takes 6 bytes of
"overhead", whether it is used to full capacity or not. Adding
147
an additional BASIC statement by using a colon (:) to separate
each pair of statements on the same line takes only 3 bytes. If
you need to save memory, avoid programs like the fo llowing:
10 X;Y+l
20 Y; Y+l
30 Z;X+Y
40 PRINT Z
50 GOTO 50
10 X;X+LY;Y+LZ;X+Y,PRlNT Z, GOTO 10
148
Chapter 11
ClJRRENCY EXCHANGE
More and more Americans are traveling to fo reign countries
each year, and as you know, monetary values are different. Let's
assume that you plan a trip to Britain and France and you wish to
convert monetary values among three systems: British pound,
French franc, and U.S. dollar. In order to facilitate these conver·
sians, you decide to write a program to compute them for you. Each
currency system is to be denoted by a code number. You must
initialize the program each time you use it by entering equivalent
monetary values for each currency. Then you can enter the currency
code and the amount to be converted. The currency system and the
equivalent amount will be printed.
On a certain morn ing. 1 British pound is equivalent to 8.3981
francs and 1.8248 U.S. dollars. At these rates. find how much an
airplane ticket worth 284 British pounds wi ll cost in dollars and in
francs. Do the same fo r an EngUsh double-barreled shotgun valued
at 1205 U.S. dollars.
149
10 REM' CURRENCY EXCHANGE
20 PRINT "ENTER CODE, AMT FOR 3
SYSTEMS"
30 PRINT "I=SR, 2=FR , 3=US"
40 INPUT CI,AI,C2,A2,C3,A3
50 PRINT
60 PRINT "CODE, AMT TO CONVERT (
O,O=STOP)"
70 INPUT C,A
80 IF c=o THEN STOP
90 REM' DETERMINE REFERENCE
100 ON C GOTO 110,130,150
110 R=AI
120 GOTO 160
130 R=A2
140 GOTO 160
150 R=A3
160 VI=A.AI/R
170 V2=A.A2/ R
180 V3=A.A3/R
190 PRINT "EQUIVALENT AMOUNTS,"
200 PRINT "SR. POUND ";VI
2\0 PRINT "R.F. FRANC ";V2
220 PRINT "U.S. DOLLAR ";V3
230 PRINT
240 GOTO 50
250 END
Display
When the following is run, you will see the following on your
screen:
150
u.s. DOLLAR SIS
CODE, AMT TO CONVERT (O,O=STOP)
?
3.1205
EQUIVALENT AMOUNTS
SR. POUND 669
R.F. FRANC 5622
U.S. DOLLAR 1205
CODE, AMT TO CONVERT (O,O=STOP)
?
0,0
METRIC CONVERSIONS
The metric system will eventually become universal-or so it
seems at this time-and the ATARl can be programmed to make
these conversions for you. The program which follows allows con-
versions of length, area, mass (weight), and liquid volume. The
conversion can be either to or from the metric Wlits.
152
630 PRINT
640 PRINT"ENTER THE NUMBER OF THE CONVERSION
TO BE USED (0 WHEN DONE)"
650 INPUT N
660 IF N =0 THEN 990
670 PRINT'ENTER THE NUMBER OF ";AI$(N);
680 INPUT AO
690 A=AOoA3(N)
700 PRINTAO;AI$(N);"=";A;A2$(N)
710 GOTO 630
720 REM •••••••• PRINT OF MASS •••••••••
730 FOR I = I TO M2
740 PRINTT AB(IO);I;T AB(15); WI$(I);TAB(40);W2$(1)
750 NEXT I
760 PRINT
770 PRINT'ENTER THE NUMBER OF THE CONVERSION
TO BE USED (0 WHEN DONE)";
780 INPUT N
790 IF N=O THEN 990
880 PRINT'ENTER THE NUMBER OF ";WI$(N);
810 INPUT WO
820 W=WO'W3(N)
830 PRINTWO/WI$(N); "=";W;W2$(N)
840 GOTO 760
850 REM •••• PRINT OF LIQVID VOLUME ••••
860 FOR I = I TO M3
870 PRINTT AB(10);I;TAB(15); VI$(O;TAB(40); V2$(l)
880 NEXT I
890 PRINT
900 PRINT'ENTER THE NUMBER OF THE CONVERSION
TO BE USED (0 WHEN DONE)";
910 INPUT N
920 IF N=O THEN 990
930 PRINT'ENTER THE NUMBER OF ";VI$(N);
940 INPUT VO
950 V=VO'V3(N)
960 PRINTVO;VI$(N);"=";V;V2$(N)
970 GOTO 890
980 REM ........ .
990 REM •••••• PROGRAM TERMINATION POINT ......
1000 PRINT
1010 PRINT "END"
153
1020 END
1030 REM ........... .
1040 REM ••••• DATA FOR INITIALIZATION ...... .
1050 REM •••••• LENGTH •••••
1060 DATA I NCHES, MILLIMETERS, 25.4,FE ET ,ME-
TERS,.3048
1070 DATA YARDS, METERS,.0144 ,MILES,KILOME -
TERS,I.6093
l OBO DATA MILLIMETERS, INCHES,.0394,METERS, FEET,
3.2806
1090 DATA METERS, YARDS, 1.0936, KILOMETERS,
MILES ,.6214
1100 REM ....... AREA
1110 DATA SQ I NCHES, SQ CENTI METERS,6.4516,SQ
FEET,SQ METERS,,0929
1120 DATA SQ YARDS,SQ METERS,.8361,SQ MILES,SQ
KILOMETERS,2.59
1130 DATA ACRES,SQ HECTOMETERS(HECTARES), .4047
1140 DATA SQ CENTIMETERS,SQ INCHES,.115,SQ MET-
ERS,SQ YARDS,l.196
1150 DATA SQ KILOMETERS,SQ MILES,.3861
1160 DATA SQ HECTOMETERS(HE CTARES),ACRES.2.471
1170 REM •••• MASS
1180 DATA OUNCES , GRAMS,28.3495 ,POUNDS.KILO-
GRAMS, .4536
1190 DATA SHORT TONS, MEGAGRAMS,.9,GRAMS,
OUNCES,.0353
2000 DATA KILOGRAMS,POUND S,2 .2046,MEGAGRAMS
,SHORT TONS,l.1
1200 REM ....... LIQUID VOLUME
1220 DATA OUNCE,MILLILITERS,30,PINTS,L1TERS,,4732
1230 DATA QUARTS ,LITERS ,.9464,GALLONS,L1T ERS,
3.7856
1240 DATA MILLILITERS ,QUNCES,.03 ,LlTERS,PINTS,
2.1134
1250 DATA LlTERS.QUARTS,1.0567,L1TERS ,GALLONS ,
.2642
1260 REM •••••••••
Display: When the program is nm, you may see the following
on your screen:
154
DO YOU WISH TO CONVERT LE NGTH (L), AREA (A),
MASS (M) , OR LIQUID
VOLUME (V)?
?L
CONVERSIONS AVAILABLE
NBR FROM
~---- ----.. _--- -TO----
1 INC HES MILLIMETERS
2 FEET METERS
3 YARDS METERS
4 MILES KILOMETERS
5 MILLIMETERS INCHES
6 METERS FEET
7 METERS YARDS
8 KILOMETERS MILES
ENTER THE NUMBER OF THE CONVERSION TO BE USED (0
WHEN DONE)? 3
ENTER THE NUMBER OF YARDS' 10
10 YARDS= 9.144 METERS
ENTER THE NUMBER OF THE CONVERSION TO BE USED (0
WHEN DONE) ? 0
END
If you run the program again and do a different conversion. you
may see the following:
DO YOU WISH TO CONVERT LENGTH (L), AREA(A),
MASS (M), OR LIQUID VOL-
UME(V)?
?A
CONVERSIONS AVAfLABLE
NBR FROM TO
1 SQ INCHES SQCENi'iMffERS'
2 SQ FEET SQ METERS
3 SQ YARDS SQ METERS
4 SQ MILES SQ KILOMETERS
5 ACRES SQ HECTOMETERS
(HECTARES)
6 SQ CENTIMETERS SQINCHES
7 SQ METERS SQ YARDS
8 SQ KILOMETERS SQ MfLES
9 SQ HECTOMETERS(HECTARES) ACRES
1S5
ENTER THE NUMBER OF THE CONVERSION TO BE USED (0
WHEN DONE)? 4
ENTER THE NUMBER OF SQUMILES? IO
IO SQ MILES=25.9 SQ KILOMETERS
ENTER THE NUMBER OF THE CONVERSION TO BE USED (0
WHEN DONE)? 0
END
156
Chapter 12
More Programs
The following programs in BASIC can be run as they are for experi·
ence and then modified to suit your own personal needs. For
example, the one on gun collecting could be modified to be used to
organize a coin collection . . . or perhaps your bottle or old canning
jar collection.
To give you some experience with you ATAR1800, some of the
programs will require a slight modification to make them work. Can
you make them work?
157
Data Format
The format to put the data in is:
1. Number of greatest common divisors needed.
2. First number of first pair.
3. Second number of first pair.
4. First number of second pair, etc.
Output Description
Appropriate headings with columns of supplied data and the
calculated G.C.D. (if you add the right lines).
RUN
Number of G.C.D.s to be found is 3
A B G.C.D.
256 243 1
158
5 15 5
130 169 13
Data Format
The fonnat to put the data in is: manufacturer, model number,
serial number, type of action, caliber or gauge , condition, value.
Output Descriptio.
See the example below . Output is either a fonnatted list of all
items or a list of those items that satisfy the selection criteria.
Important Variables
M . .Maximum number of data reads
(total number of guns to be entered)
M2 .. Manufacturer of gun
N .. Model number
S .. Serial number
C .. Caliber or gauge
A .. Type of action
C2 .. Condition
V .. Current Value
159
10 REM GUN CO LLECTION PROGRAM
20 REM"· READ DATA •••
30 PRINT "ENTER TOTAL NUMBER OF GUNS TO BE
RECORDED"
40 INPUT M
50 PRINT "DO YOU WISH TO HAVE ALL ENTRIES
LISTED? (Y OR N)"
60 INPUT L$
70 PRINT
SO IF L$ = " Y" THEN 110
90 PRINT"ENTER MANUFACTURER YOU WISH LISTED"
100 INPUT LO
110 PRINT
120 PRINT
130 PRINT "MANUFACTURER", TAB(l S); "Model"
TAB(l O); "Serial" ;
140 PRINT TAB(lO); "CaIiber";TAB(IO): "Action";TAB(lO) ;
150 PRINT "Condition"; TABOO); "Value"
155 PRINT
160 FOR 1=1 TO M
170 READ 11$
I SO IF 11$ = "END" THEN 320
190 READ M2,N,S,C,A,C2 ,V
200 IF Z$ < > "Y" THEN 240
210 PRINT 11$: TAB(lO); A; TAB(lS); C2; TAB(r);V
230 GOTO
240 IF 11$ < > AO THEN 310
250 C=C+l
260 IF C=1 THEN 290
270 11$=""
280 PRINT 11$: TAB (IS);M2; TAB(lO);S:TAB(lO);
300 PRINT C; TAB(10); A; TAB(IS);C2; TAB(S);V
310 NEXT I
320 PRINT
330 PRINT
340 STOP
350 REM··· DATA ···
360 DATA Winchester, 70, 44271, .270W,Bolt,Good, 450
370 DATA Remington , 1100, 00714, 12, Auto, Ex. 312
380 DATA H and R, 158C, 77431, 20, single, good, 95
390 DATA Remington , 742, 00853, .3(),-06 . auto, ex, 375
400 DATA END
160
RUN
ENTER TOTAL NUMBER OF GUNS TO BE RECORDED ?4
DO YOU WISH TO HAVE ALL ENTRIES LISTED ? (YOR N)? Y
Manufacturer Model Serial Caliber Action Condition Value
Winchester 70 44371 .270W Bolt Good 450
Remington 1100 00714 12 Auto Ex 312
Hand R 158C 77431 20 Single Good 95
Remington 742 00853 30-06 Auto Ex 375
RUN
ENTER MAXIMUM NUMBER OF GUNS TO BE RECORDED
?4
DO YOU WISH TO HAVE ALL ENTRIES LISTED? (Y OR N) N
?Remington
Manufacturer Model Serial Caliber Action Condition Value
Remington 1100 00714 12 Auto Ex 312
742 00853 30-06 Auto Ex 375
CHECKBOOK BALANCER
This is one of the "traditional" programs that every beginning
computerist writes. It allows the entry of outstanding checks and
uncredited deposits as well as cleared checks and credited deposits.
Remember that the Question mark is simply a symbol for print.
10 DIM A$(3O),MSG$(40),MSGl$(30),MSG2$(30)
,MSG3$(30) ,MSG4$(3O) ,MSG5$(3O) ,MSG6$(30)
20 OUTSTAND=O
30 GRAPIflCS O,? ,?" CHECKBOOK BALANCER",?
40 ? "You may make corrections at any time by entering a
negative dollar value."
50 MSGI$="OLD CHECK - STILL OUTSTANDING"
60 MSG2$="OLD DEPOSIT -- NOT CREDITED"
70 MSG3$= "OLD CHECK - JUST CLEARED"
SO MSG4$= "OLD DEPOSIT -- JUST CREDITED"
90 MSG5$= "NEW CHECK (OR SERVICE CHARGE)"
100 MSG6$="NEW DEPOSIT (OR INTEREST)"
150 TRAP ISO :? "Enter beginning balance from your
checkbook";,INPUT YOURBAL
160 TRAP 160 :? "Enter beginning balance from your
bankstatement";:INPUT BANKBAL
165 TRAP 4()()()()
170 GOTO 190
ISO CLOSE Ill, ? "PRINTER IS NOT OPERATIONAL."
161
185 ? "PLEASE CHECK CONNECTORS."
190 PERM=O
200 ? "Would you like a pennanenl record on the printer";:IN-
PUTA$
210 IF LEN(A$)=O THEN 200
220 IF A$(1, I) ="N" THEN 400
230 IF A$(1,1) "Y" THEN 200
240 TRAP 180
250 LPRINT ,REM TEST PRINTER
260 PERM=1
280 LPRINT "YOUR BEGINNING BALANCE IS $";YOUR-
BAL
290 LPRINT "BANK STATEMENT BEGINNING BALANCE
IS $";BANKBAL,LPRINT
400 TRAP 4OO:? :? "Choose one of the following:"
410 ? "(1) ",MSG1$
415 ? "(2) ";MSG2$
420 ? "(3) ";MSG3$
425 , "(4) ";MSG4$
430 ? "(5) ";MSG5$
435 ? "(6) ";MSG6$
440 ? "(7) ";NO MORE ENTRIES"
490 ?
500 INPUT N JF N<1 OR N> 7 THEN 400
505 TRAP 40000
510 ON N GOSUB 1000,2000.3000.4000.5000,6000,7000
520 MSG$="NEW CHECKBOOK BALANCE IS", AMOUNT
=YOURBAL,GOSUB 8000
530 MSG$ ="NEW BANK STATEMENT BALANCE
IS",AMOUNT=BANKBAL,GOSUB 8000
540 MSG$ ="OUTSTANDI NG CHECKS - DEPOSITS="
,AMOUNT=OUTSTAND,GOSUB 8000
545 IF PERM THEN LPRINT
550 GOTO 400
1000 REM OLD CHECK -- STILL OUTSTANDING
1010 MSG$=MSG1$,GOSUB 8100
1020 OUTSTAND=OUTSTAND+AMOUNT
1030 RETURN
2000 REM OLD DEPOSIT -- STILL NOT CREDITED
2010 MSG$=MSG2$,GOSUB 8100
2020 OUTSTAND=OUTSTAND-AMOUNT
162
2030 RETURN
3000 REM OLD CHECK - - JUST CLEARED
3010 MSG$=MSG3$,GOSUB 8100
3020 BANKBAL=BANKBAL-AMOUNT
3030 RETURN
4000 REM OLD DEPOSIT -- JUST CREDlTED
4010 MSG$=MSG4$,GOSUB 8100
4020 BANKBAL=BANKBAL+AMOUNT
4030 RETURN
SOOO REM NEW CHECK (OR SERVICE CHARGE) -- JUST
CLEARED
SOlO MSG$=MSGS$,GOSUB 8100
S020 YOURBAL=YOURBAL-AMOUNT
S030 '''IS NEW CHECK STILL OUTSTANDlNG""INPUT A$
5040 IF LEN(A$)=O THEN S030
SOSO IF A$(l.l) "N" THEN 5060
S055 BANKBAL=BANKBAL-AMOUNT
S057 IF PERM THEN LPRlNT "CHECK HAS CLEARED,"
S058 RETURN
5060 IF A$(l,l)< >"Y" THEN 5030
S070 OUTSTAND=OUTSTAND+AMOUNT
S075 IF PERM THEN LPRINT "CHECK IS STILL OUT-
STANDING,"
S080 RETURN
6000 REM NEW DEPOSIT (OR INTEREST) -- JUST CRE-
DITED
6010 MSG$=MSG6$,GOSUB 8100
6020 YOURBAL=YOURBAL+AMO UNT
6030 ? "HAS YOUR NEW DEPOSIT BEEN CREDITED" "IN-
PUT A$
6040 IF LEN(A$)=O THEN 6030
6OSO IF A$(l,l)< >"Y" THEN 6060
6052 BANKBAL=BANKBAL+AMOUNT
6053 IF PERM THEN LPRlNT'DEPOSIT HAS BEEN CRE-
DlTED,"
6055 RETURN
6060 IF A$(l,I) < >"N" THEN 6030
6070 OUTSTAND=OUTSTAND-AMOUNT
6075 IF PERM THEN LPRlNT "DEPOSIT HAS NOT BEEN
CREDlTED,"
6080 RETURN
163
7000 REM DONE
7010 ? "BAN K'S BALANCE MINUS <OUTSTAND-
ING CHECKS- DEPOSITS) SHOULD NOW EQUAL
YOUR CHECKBOOK BALANCE."
7020 DIF;YOURBAL-(BANKBAL-OUTSTAND)
7030 IF DIF< >0 THEN 7040
7035 ?"IS$";BANKBAL;" THE ENDING BALANCE ON YOUR
BANK STATEMENT";,INPUT A$
7036 IF LEN(A$);O THEN 7035
7037 IF A$( I,I);"Y" THEN? CONGRATULATIONS, YOUR
CHECKBOOK BALANCES!",END
7038 GOTO 7060
7040 IF DIF>O THEN? "YOUR CHECKBOOK TOTAL IS
$" ;DIF;" OVER YOUR BANK's TOTAL. ",GOTO 7060
7050 ? "WOULD YOU LIKE TO MAKE CORRECTIONS?"
7070 ? "REMEMBER, YOU CAN ENTER A NEGATIVE DOL-
LAR VALUE TO MAKE A CORRECTION,
7080 ? "ENTER Y OR N"; ;lNPUT A$
7090 IF LEN(A$);O THEN END
7100 IF A$O,l);"Y" THEN RETURN
7110 END
7999 REM MSG PRINTING ROUTINE
8000 ? MSG$;" $";AMOUNT
8010 IF PERM;1 THEN LPRINT MSG$;" $" ;AMOUNT
8020 RETURN
8100 REM MSG PRINT & INPUT ROUTINE
8110 TRAP 8110,? "ENTER AMOUNT FOR ";MSG$; ;lNPUT
AMOUNT
8120 TRAP 40000
8130 IF PERM;1 THEN LPRINT MSG$;" $";AMOUNT
164
Chapter 13
Flowcharting Techniques
U you are a beginning programmer, you may be interested in
learning some of the techniques that allow you to more easily
advance a programming task from a conceptual s tage to a fma lized
stage.
Flowcharts, which pictorialize the solution to a programming
task, are valuable programming tools. They are often drawn long
before the actual program statements are written .
While flowcharting your program, you might change or
s implify your approach, or see a flaw in yOUT logic . After several
attempts, you should have a workable flowchart and, once you do,
your programming task is greatly reduced.
Any flowchart that you draw is useful ; but a few basic conven-
tions aTe described in this chapter. Terminal (that is, s tarting or
ending) activities are represented by ovals. Arrows, ind icate the
direction of program flow between operations. Most calculator
operations are represented by rectangles. A diamond represents a
decision point.
To illustrate , in the fo llowing example we have labeled each
flowcharting operation with the corresponding program line
number . See Fig. 13-1. As you can see, once the flowchart is
final ized, the program can be written relatively easily.
10 REM -THIS PROGRAM AVERAGES UP TO 20 POSI-
TIVE NUMBERS
20 REM- IF YOU HAVE FEWER THAN 20 NUMBERS TO
165
line Number
START)
40
--'-
INITIAUZE
TOTALING
VARIABLE
I
50 START lOOP
,
WITH
COUNT VARIABL
60
/ INPUT
NUMBER
/
~
70 NUMBER < 0
NO
80 TOTAL = TOTAL
&
NUMBER
1
90 - < 20
NEXT )
\
--,->20
110
I 1=1-1 J--
1
120
/ , j
PRINT
I;AII
130
( END )
Fig. 13-1 .
166
ENTER_
30 REM-ENTER A NEGATrVE NUMBER TO END THE
INPUTTING_
40 A=O
50 FOR 1=1 TO 20
60 INPUT B
70 IF B < 0 THEN 110
80 A=A+B
90 NEXT I
110 1=1- 1
120 PRINT "THE AVERAGE OF THE -'I'- NUMBERS IS "All
130 END
As mentioned previously, flowcharts use boxes and lines ,
following a few simple rules. to represent a program design. Only a
few shapes and a few ways of drawing the connecting lines are used.
These restrictions are intended to make the resulting flowcharts
easy to understand by displaying the relationship of parts very
clearly. After a correct flowchart has been drawn, translation to a
program (writing statements corresponding to the boxes) is rela-
tively simple.
FlIlWCHARTlNG SYMBOLS
Five different shapes of boxes are required for most flow-
charts .
RectanEle
A rectangle indicates any processing operation except input!
output or a decision.
Diamond
A diamond indicates a decision. The lines leaving the box are
labeled with the results that cause each path to be followed.
Paral1elocram
A parallelogram indicates an input or output operation.
Oval
An oval indicates the begirming or ending point of a program or
program segment.
167
Circle
A small circle indicates a collection point, where lines from
other boxes join.
CONTROL STRUCTURES
The fundamental funct ion of a flowchart , as of any other pro-
gram design tool. is to show in exact and unambiguous detai l the
sequence in which actions are to be carried out and the conditions
under which alternatives are to be taken. In depicting these matters
in flowcharts, three control structures are normally used.
Sequence
When an arrow leads from one box to the next, that means
simply that the two are to be executed in sequence in the order
shown.
Selection
The choice indicated by the decision box always has just two
outcomes, depending on whether the condition is true or false.
Iteration
Processing actions are executed repeatedly until a stated con-
dition tenninates the repetition. The number of repeats may in
some cases be zero.
The basic structures stated above may be combined. For exam-
pie, a path coming out of a decision box may lead to another decision
or perhaps an iteration . Furthennore , it wilt commonly happen thaI
the act ions specified in a loop will include decisions. This is per-
fectly acceptable so long as only the three basic structures are used.
TltE IF STATEMENT
Often there are times when you want to make a decision. In the
averaging program discussed previously, we wanted the program to
branch to either the end of the program, or to the inquiry for more
infonnation. The branch was dependent on the outcome of a
specified condition, using the if .. . then statemenl.
IF numeric expression THEN statement
The if ... then statement makes a decision based upon the
outcome of the numeric expression. If the expression is true, the
then part of the statement is executed. H the outcome is false,
168
execution continues with the statement following the if ... then
statement.
For example, suppose an accountant wishes to write a program
that will calculate and print the amount of tax to be paid by a number
of persons. For those with incomes of$lQ,OOO per year or less, the
amount of tax is 17.5%. For those with incomes of over$10,OOO, the
tax is 20% . A flowchart for the program might look like the one in
Fig. 13-2. The diamond in the flowchart would be represented by an
if ... then statement in a program. The program may look like the
following:
10 PRINT " INCOME"
20 INPUT I
30 IF I > 10000 THEN 60
40 PRINT "TAX ="; I- .175
SO GOTO 70
60 PRINT "TAX="; I- .2
70 END
As you can see, we used a relational operation in the if ... then
statement. The if . . . then statement is most often used with
relational operators, although the decision can be based on the value
of any numeric expression.
If the condition is true-the income is greaterthan $10,000-
program control is transferred to statement 60. If the cond ition is
false-the income is less than or equal to $lO,()()()-the rest of the if
statement is ignored and the program continues at statement 40. To
test this program , use the values of $20,000 and $9,000.
169
Una Number
10 START
PRINT
20 PROMPT
30
40 YES
50
GOTO
END
60 OUTPUT
INCOME·
2
70
Fig. 13-2.
170
indicated else statement is executed. Look at the following exam-
ple .
A Quadratic equation is of the form O::;ax2 +bx+c. If a=O, its
two roots may be found by the formulas
r = :.b!t+tV~b~
' ~4[a!!C~ and r = - b Vb
2
4 ac
I ": 2a 2 2a
171
, •-, GOTOICO
"
.
,
•
D> _0
ooro ".
'"
FIg. 13-3.
172
x2 +2x_l=O
RUN
IF A QUADRATIC EQ
EQUATION IS OF THE
FORM O;A'X A2+B'X+C
ENTER A. B. C
?
1,1, -6 (x 2 + X - 6)
COEFFICIENTS; 1 1 - 6
ROOTS;2 - 3
RUN
IF A QUADRATIC
EQUATION IS OF THE
FORM O=A-X A2+S-X+C
ENTER A. B. C
?
1,2.2 (X' + 2 X + 2)
COMPLEX ROOTS: CANNOT COMPUTE
REENTER VALUES
?
3, 2, -1 (3X' + 2X - 1)
COEFFICIENTS;3 2 -
ROOTS ; .333333333333 - 1
PSEUDOCODE
Pseudocode may be used as an alternative to flowcharting for
program design . the logic that determines the sequence in which
processing operations are earned out. In general. this technique
uses a code notation which has similarities to BASIC. but is not
quite the same.
In pseudocode, we are restricted to just three logic control
elements: sequence, selection, and iteration. In pseudocode, the
selection element is if ... then . .. else and the iteration element is
perform . .. until. However , the overall structure of the pseudocode
need not show all the details of processing. just as a flowchart need
not show them.
Sequence requires no special notation. It is simply a conven-
tion that unless specified otherwise, operations are carried out from
top to oottom in the order written.
173
Chapter 14
174
Teb.. 14- t Modes.1Id SCreeII Fonut.
•• ,- , ,'M,,
-.," -.l:"
,~
,<01, •
-.
,
0
,
,,
run"
"'"
""
G\WOOOCS
"" '" "'"
(brightness) default mode for the ATARlSOO.It contains a 24 by 40
character screen matrix. The default margin settings at 2 and 39
allow 38 characters per line. Margins may be changed by poking
LMARGN and RMARGN (82 and 83). Some systems have different
margin default settings. The color of the characters is determined
by the background color . Only the luminance of the characters can
be different . To display characters at a specified location . use one of
the following two methods . Note: "sexp" denotes a string expres·
s ion; "aexp" denotesanarithmeticexpression. "Lineoo" means line
number .
Method 1
lineno POSITION aexpl , aexp2 Puts cursor at location
lineno PRlNT sexp specified by aexp 1
and aexp2.
Method 2
lineno GR .O Specifies graphics mode .
lineno POKE 752,1 Suppresses cursor.
lineno COLOR ASC(sexp) Specifies character to be
printed .
lineno PLOT aexpl, Specifies where to print
aexp2 character.
lineno GOTO Iineno Start loop to prevent READY
from being printed. (GOTO)
same lineno.)
Press BREAK to tenninate
loop.
Graphics 0 is also used as a clear screen command either in the
direct mode or the deferred mode. It temunates any previously
175
selected graphics mode and returns the screen to the default mode
(graphics 0).
Graphics Modes 1 and 2: As defmed in Table 14--1, these
two five-color modes are text modes. However, they are both
split-screen modes. Characters printed in Graphics Mode 1 are
twice the width of those printed in graphics 0, but are the same
height. Characters printed in Graphics Mode 2 are twice the width
and height of those in Graphics Mode O. In the split-screen mode, a
print command is used to display characters in either the text
window or the graphics window. To print characters in the graphics
window, specify device #6 after the PRINT command.
Example: GRAPfDCS 1 + 16
176
FIg. 14-1. The graphics and tex1 windoWs.
modes are also split-screen displays in their default state, but may
be changed to full screen by adding +16to the mode number. Modes
3, 5, and 7 are alike except that modes 5 and 7 use more points
(pixels) in plotting, drawing, and positioning the cursor. The points
are smaller, thereby giving a much higher resolution than that in
modes 0, ], and 2.
Graphics Modes 4 and 6: These graphics modes are like
modes 5 and 7 respectively except that they use only two colors,
and therefore use less memory.
Graphics Mode 8: This graphics mode gives the highest
resolution of all the modes. As it takes a lot of RAM to obtain this
kind of resolution, it can only accommodate a maximum of one color
and two different luminances.
Color (C.): The value ofthe expression in the color statement
determines the data to be stored in the display memory and used by
all subsequent plot and drawto commands until the next color
statement is executed. The value must be positive and is usually an
integer from 0 through 255. Nonintegers are rounded to the nearest
integer. The graphics-display hardware interprets this data in dif-
ferent ways in the different graphics modes. In Text Modes 0
through 2, the number can be from 0 through 255 (8 bits) and
determines the character to be displayed and its color.
Tables 14-4 and 14-5 later in this chapter illustrate the internal
character set and the character/color assignment.
Graphics Modes 3 through 8 are not text modes, so the data
stored in the display RAM simply determines the color of each
pixel. Two-color or two-luminance modes require either 0 or 1
(I-bit) and four-color modes require 0,1,2, or 3. The actual color
which is displayed depends on the value in the color register which
corresponds to the data of 0.1 ,2, or 3 in the particular graphics mode
being used. This may bedetennined by looking in Table 14-2, which
gives the default colors and the corresponding register numbers.
Colors may be changed by using the setcolorcommand described on
the following pages.
Note that when BASIC is frrst powered up, the color data is 0,
and when a graphics command (without +32) is executed, all of the
pixels are set to O. Therefore, nothing seems to happen when the
plot and drawto commands are used in graphics 3 through 7 when no
colorstalement has been executed. Correct by doing a color 1 first.
Drawto: This statement causes a line to be drawn from the
last point displayed by a plot to the location specified by aexp1 and
aexp2. The first expression represents the X coordinate and the
second represents (he Y coordinate . The color of the line is the
same color as the point displayed by plot.
Locate: This command positions the invisible graphics cursor
at the specified location in the graphics window. retrieves the data
at that pixel, and stores it in the specified arithmetic variable. This
gives a number from Oto 255 for Graphics Modes othrough 2; Oor 1
for the 2-color graphics modes; and 0,1.2, or 3 for the 4-color
modes. The two arithmetic expressions specify the X and Y coordi-
nates of the point. locate is equivalent to:
Doing a print after a locate may cause the data in the pixel
which was examined to be modified. This problem is avoided by
repositioning the cursor and putting the data that was read back into
the pixel before doing the PRINT. The foJlowing program illus-
trates the use of the locate command.
10 GRAPIflCS 3 + 16
20 COLOR I
30 SETCOLOR 2,10,8
40 PLOT 10.15
50 DRAWTO 15,15
60 LOCATE 12, 15,X
70 PRINT X
178
T.... 1~2...... SetceW, Color T....,
(..... p1)
"""""".
on.uk .-
....... Cond..... ~4't'N'o • C.,_p) DE8CIUrnON AND COMMEHn
OOLOR da.a
UCIfT BI.Ut:
DARK BI.UE
--
MODE O.nd
AUTtxT
,, --
actually
delrrmiM'Ol
-
Char..:ter lumi......,.I_ color. bKkground)
Back grou nd
WINDOWS
,,
chir"'"r '0 -
be plonK!
....'"
OIlA NCE COWl dill'
""'"
LlGIfT GR£EN NODES I
,•,
acto".)' delennu-
""""n
DAU SLUt:
""""n
a--.on
,...
, ,, m.no:tto> 'Ol be
"",., a--.on
IT"•• ModNl •
....""'"
(}lANGE Graphk'l porn.
I,J(;trT GREEN MODI:S3, S,
,,
GBphitw point
DAII BLUE
....0<
.... ,
trou.-..roklr
,, ,,,
,-
--
Graphics poil>!
-Cnpho poInt!bllckgound <In,IlI.). Border
OlANG!:
""""
MOO'" ,•, , Gr.ph"" poIn.
",," -
,, - --
'''''-- - -
8LACK , Gnphk:s point (bodgroond def.ult), IIordrr
......• ,
LlGtrT GRaN ,, -
DAB RLUE ,-
, Graphb point luminance ' ...III t . . . . . ~
Graphics poIn' ~ default)
~
""""
U.- . ,,
- -
ZLumi~ .......
ill ....'" •
On execution, the program prints the data 0) detennined by
the color statement which was stored in pixe112, 15.
Plot: The plot command is used in Graphics Modes 3 through 8
to display a point in the graphics window. The aexpl specifies the
X-coordinate and the aexp2, the Y--coordinate. The color of the
plotted point is determined by the hue and luminance in the color
register determined by the last color statement executed. To
change this color register. and the color of the plotted point. use
setoolor. Points that can be plotted on the screen are dependent on
the graphics mode being used. The range of points begins at 1 and
extends to one less than the total number of colunms (X--coordinate)
or rows (Y-roordinate) shown in Table 14-1-
Position: The position statement is used to place the invisible
graphics·window cursor at a specified location on the screen. This
statement can be used in all modes. Note that the cursor does not
actually move until an VO command which involves the screen is
issued.
Put: In graphics work. put is used to output data to the screen
display. This statement works hand·in·hand with the position
statement. After a put, the cursor is moved to the next location on
the screen. Doing a put to device #6 causes the one·byte input to be
displayed at the cursor position. The byte is either an ATASCII
code byte for a particular character or the color data.
Get: Is used to input the code byte of the character displayed at
the cursor position into the specified arithmetic variable. The val·
ues used in put and get correspond to the values in the color
statement. (Print and input may also be used.)
Doing a print after get from the screen may cause the data in
the pixel which was examined to be modified. To avoid this prob-
lem. reposition the cursor and put the data that was read, back into
the pixel before doing the print.
Setcolor: This statement is used to choose the particular hue
and luminance to be stored in the specified color register . The
parameters of the setcolor statement are defined below:
180
'Ible 14-3. Hue (Setcolor eom.... ndl NVIIIHn and Colon.
G".y o
Ugh! orange (gold) 1
0".",. 2
Rod-<><ange 3
Pink 4
p,-
8'""
8'"" ,•
7
9
Ught blue
T, ...... 10
G....._ 11
G..... 12
Yellow-green 13
I.
"''''''''''''''''''
l.\llrt<><ango 15
Hore: QMors will vary with type and adfustmeot of TV Of monitor used.
10 GRAPHICS 3
20 SETCOLOR 0,2.8, COLOR I
30 PLOT 17,1' DRAwrO 17,10, DRAwrO 9.18
40 PLOT 19,1, DRAwrO 19, 18
50 PLOT 20.1' DRAwrO 20,18
60 PLOT 22,1' DRAwrO 22 , 10, DRAwrO 30,18
70 POKE 752,1
181
SetcolO< Defaults To lorninance Actual Color
(Color Register) ColO<
0
1
2
2
12
9
•
10
4
o.ange
G....
Dark blue
3
4 0
4
•0
Pk'* or blue
BIaci<
hDefaulf' ocrurs If no setooIor statement Is used.
Note: Colors may vary depending upon the televisiOn
monitor type, conditiOn, and adjustment.
182
2. Drawto upper right comer (point 2). This outlines the right
edge of the area to be filled.
3. Drawto upper left comer (point 3).
4. Position cursor at lower left comer (point 4).
5. Poke address 765 with the fill color data (1,2, or 3) .
This method is used to fill each horizontal line from top to
bottom of the specified area. The fill starts at the left and proceeds
across the line to the right until it reaches a pixel which contains
non-zero data. Fill cannot be used to change an area which has been
filled in with a non-zero value so the fill will stop. The fill command
will go into an infmite loop if a fill-with-zero command is attempted
on a line which has no non-zero pixels. Press the break key or the
system reset button to stop the fill if this happens.
The following program creates a shape and fills it with a data
(color) of 3. Note that the XlO command draws in the lines on the
left and bottom of the figure.
10 GRAPIflCS 5+ 16
20 COLOR 3
30 PLOT 70,45
40 DRAWTO 50,10
50 DRAWTO 30,10
60 POSITION 10,45
70 POKE 765,3
80 XIO 18,116.0,0,"5: "
90 GOTO 90
Tab.. T4-5. lnternal CNrIctIf s.t.
Column 1 Column 2
# CHR # CHR # CHR # CHR
o Space 16 o 32 @ 48 P
1 17 1 33 A 49 Q
2 " 18 2 34 B 50 R
3 • 3 35 c 51 S
4 $ 20 4 36 o 52 T
5 21 5 37 E 53 U
6 22 6 38 F 54 V
7 23 7 39 G 55 W
8 24 8 40 H 56 X
9 25 9 41 57 Y
to 26 42 J 58 z
11 + 27 43 K 59
12 28 < 44 L 60 \
13 29 - 45 M 61
14 30 > 46 N 62
15 / 31 47 o 63
184
Column 4
# CHR # CHR # CHR # CHR
64 11 2 P
65 97 a 113 q
66 98 b 114 r
67 99 c 115 s
68 100 d 116 t
69 101 e 117 u
70 102 f 118 v
71 119 w
72 h 120 x
73 105 121
74 106 j 122 z
75 107 k 123
76 108 124 I
77 109 m 125 <D ...
78 110 n 126 -4
79 111 0 127
1. In modt' 0 tht'R ch.racft'rs must be pl""('("t'(jcd wi th an tlleapt', CHR$(27),
10 be prinltd.
185
-, -, -, _.
rl bl. 14-8. Cfalracter/Color AssI~
-,
-,
I
- -
'''''''''t
- ..»
~
..» .-»
~-
-,-, -,
-,-, - .- .-.-.,.
-m ••» .-» .-»
.~ ' _k
...,. .-
~
h'«I ".'«1
"'3
2 ~_I1\<_'.o . UJM .
186
H~h C 29
Not..
•
At, Of
A
B~
3t
33
35
OWorA~ 37
0
FWorG ~
F
'"42
45
E 47
OW or E 50
0 53
CWorO~ 57
C 60
187
117 OPEN III, S, 0, "S;"
liS GRAPHICS L
120 PRINT "GRAPHICS "; L
130 FOR J=O TO 7;REM SLINES
140 FOR 1=0 TO 31 ;REM 32 CHARS/LINE
150 K=32.J+1
155 REM DON'T DISPLAY "CLEAR SCREEN" OR "RE-
TURN"
160 IF K=ASC(")") OR K=155 THEN 180
165 IF L=O THEN PUT III, ASC (" ");REM ESCAPE
170 PUT III ,K;REM DISPLAY CHARS
180 NEXT I
190 PRINT Ill;" " ;REM END OF LINE
200 IF L< > 2 or J< >3 THEN 240
210 REM SCREEN GULL
220 GOSUB WAIT
230 PRINT 1I1 ;"j";REM CLEAR SCREEN
240 NEXT J
250 GOSUB WAIT
265 PRINT "LOW CASE AND GRAPHICS"
270 IF L< > 0 THEN POKE CHBAS, LOWER;GOSUB WAIT
275 CLOSE III
280 NEXT L
300 GRAPHICS O;END
1000 REM WAIT FOR "RETURN"
1010 PRINT "HIT RETURN TO CONTINUE";
1020 INPUT A$
1030 RETURN
UGHT SHOW PROGRAM
The following program demonstrates another aspect of ATARI
graphics. It uses Graphics Mode 7 for high resolution and the plot
and drawto statements to draw the lines. In line 20, the title will be
more effective if it is entered in inverse video using the ATARI logo
key.
1GB
60 NEXT DR: FOR N=I TO 800: NEXT N: NEXT ST
70 FOR N= I TO 2000: NEXT N"GOTO 10
189
370 COLOR WHITE
380 K:O,REM START WITH ROW OF 6 STARS
390 FOR 1:0 TO 8
395 Y=I+I o 5
400 FOR J:O TO 4, REM 5 STARS IN A ROW
410 X:K+5+J o I4, GOSUB 1000
420 NEXT J
430 IF K< >0 THEN K:O, GOTO 470
440 REM ADD 6TH STAR EVERY OTHER LINE
450 X:5+5014,GOSUB 1000
460 K:7
470 NEXT I
500 REM IF KEY HIT THEN STOP
510 IF PEEK (764) : 255 THEN 410
515 REM OPEN TEXT WINDOW WITHOUT CLEARING
SCREEN
520 GRAPHICS 7+32
525 REM CHANGE COLORS BACK
530 SETCOLOR 0,4,4, SETCOLOR 1,0.14
550 STOP
1000 REM DRAW 1 STAR CENTERED AT X,Y
1010 PLOT X-I,Y,DRAWTO X+l,Y
1020 PLOT X,Y-I, PLOT X,HI
1030 RETURN
VIDEO GRAFFITI
This program requires a joystick controller for each player.
Each joystick has one color associated with it. By maneuvering the
joystick, different patterns are created on the screen. Note the use
of the stick and strig commands.
1 GRAPHICS 0
2 ? "VIDEO GRAFFITI"
5 REM X&Y ARRAYS HOLD COORDINATES
6 REM FOR UP TO 4 PLAYERS' POSITIONS.
7 REM COLR ARRAY HOLDS COLORS.
10 DIM A$(l),X(3),Y(3),COLR(3)
128 ? "USE JOYSTICKS TO DRAW PICTURES"
129 ? "PRESS BUTTONS TO CHANGE COLORS"
130 ? "INITIAL COLORS,"
131 ? "JOYSTICK 1 IS RED"
132 ? "JOYSTICK 2 IS WHITE"
190
133 ? "JOYSTICK 3 IS BLUE"
134 ? "JOYSTICK 4 IS BLACK (BACKGROUND)"
135 ? "BLACK LOCATION IS INDICATED BY A BRIEF
FLASH OF RED."
136 ? "IN GRAPHICS 8, JOYSTICKS I AND 3 ARE WHITE
AND 4 IS BLUE."
138 PRINT "HOW MANY PLAYERS (1·4)";
139 INPUT A$:IF LEN(A$)=O THEN A$="I"
140 JOYMAX=VAL(A$)- I
145 IF JOYMAX<O OR JOYMAX =4 THEN 138
147 PRINT "GRAPHICS 3 (40X24), 5 (80X48),"
150 PRINT "7 (lSOX96) , OR 8 (32OXI92),,;
152 INPUT A$:IF LEN(A$)=O THEN A$="3"
153 A=VAL(A$)
154 IF A=3 THEN XMAX=40:YMAX=24:GOTO 159
ISS IF A=5 THEN XMAX=80:YMAX=48:GOTO 159
156 IF A=7 THEN XMAX=ISO:YMAX=96:GOTO 159
157 IF A=8 THEN XMAX=320:YMAX=192:GOTO 159
156 GOTO 147:REM A NOT VALID
159 GRAPHICS A+l6
ISO FOR 1=0 TO JOYMAX:X(I) = XMAXl2+I:Y(O=YMAXI
2+I:NEXT I: REM START NEAR CENTER OF SCREEN
161 IF A< > 8 THEN 166
162 FOR 1=0 TO 2:COLR(O=I :NEXT I
163 SETCOLOR 1,9,14:REM LT . BLUE
165 GOTO 180
166 FOR 1=0 TO 2:COLR(O=I+l:NEXT I
167 SETCOLOR 0,4,6:REM RED
168 SETCOLOR 1,0,14:REM WHITE
180 COLR(3)=0
295 FOR J=O TO 3
300 FOR 1=0 TO JOYMAX:REM CHECK JOYSTICKS
305 REM CHECK TRIGGER
3\0 IF STRlG(o THEN 321
311 IF A< > 8 THEN 320
312 COLR(I)=COLR(I)+I:IF COLR(I)=2 THEN COLR(I)=
O:REM 2·COLOR MODE
313 GOTO 321
320 COLR(O=COLR(O+l :IF COLR(O > =4 THEN COLR(I)=
O:REM 4-COLOR MODE
321 IF J> O THEN COLOR COLR(I):GOTO 325
322 IF COLR(O=O THEN COLOR I:GOTO 325
191
323 COLOR O,REM BLINK CURRENT SQUARE ON AND
OFF
325 PLOT X(D, Y(D
330 JOYlN=STlCK(D,REM READ JOYSTICK
340 IF JOYlN=15 THEN 530,REM NO MOVEMENT
342 COLOR COLR(D,REM MAKE SURE COLOR IS ON
344 PLOT X(I),Y(I)
350 IF JOYIN> =8 THEN 390
360 X(D=X(I)+1,REM MOVE RIGHT
370 IF X(I»=XMAX THEN X(D=O
380 GOTO 430
390 IF JOYIN> =12 THEN 430
400 X(D=X(I)-I,REM MOVE LEFT
410 IF X(D < OTHEN X(D=XMAX-I
430 IF JOYIN< > 5 AND JOYlN < >9 AND JOYIN< > 13
THEN 470
440 Y(I)=Y(I)+ UF Y(D> =YMAX THEN Y(I)=O, REM MOVE
DOWN
460 GOTO 500
470 IF JOYlN< > 6 AND JOYlN< > 10 AND JOYlN< > 14
THEN 500
480 Y(I)=Y(I)-I,IF Y(I) < O THEN Y(I)=YMAX-I,REM
MOVE UP
500 PLOT X(I),Y(D
530 NEXT I
535 NEXT J
540 GO TO 295
USING SOUNO
In general, BASIC statements are used to generate musical
notes and sounds through the audio system of the television
monitor. Up to four different sounds can be "played" simultaneously
creating harmony. The sound statement can also be used to simu·
late explosions. whistles. and other interesting noises.
Sound: The sound statement causes the specified note to
begin playing as soon as the statement is executed. The note will
continue playing until the program encounters another sound
statement with the aexpl or an end statement. This conunand can
be used in either direct or deferred modes.
The sound parameters are described as follows:
192
aexpl= Voice. Can be 0-3, but each voice requires a separate
sound statement.
aexp2= Pitch. Can be any number between 0 and 255. The
larger the number, the lower the pitch. Table 14-7
shows the pitch numbers for the various musical
notes ranging from two octaves above middle C to one
octave below middle C.
aexp3= Distortion. Can be any even number between 0 and
14. A 0 is used to create a "pure" tone whereas a 12
gives an interesting buzzer sound. A buzzing sound
can be produced using two separate sound commands
with the distortion value alternating between 0 and 1.
aexp4= Volume control. Can be between 1 and 15. Using a 1
creates a sound barely audible whereas a 15 is loud. A
value of 8 is considered nonnal. If more than one
sound statement is being used, the total volume
should not exceed 32 or an unpleasant "clipped" tone
will result.
10 READ A
20 IF A=256 THEN END
30 SOUND O,A,lO,lO
40 FOR W=1 TO 4OO:NEXT W
50 PRINT A
60 GOTO 10
70 END
80 DATA 29 , 31,35, 40, 45, 47, 53, 60, 64, 72,81, 91, 96, l OS,
121
90 DATA 128, 144, 162, 182, 193, 217, 243, 256
Note that the data statement in line 90 ends with a 256. A glance at
Table 14-7 will tell us that this is outside of the designated range.
The 256 is used as an end-of-data marker.
TYPE-A-TUNE P1I06RAM
The following program turns the ATARI 800 into a single-scale
piano; that is, it assigns musical note values to the keys on the top
193
row of the computer keyboard. When you are using this program, do
not try to play harmony ; press only one key at a time .
10 DIM CHORD(37).TUNE(l2)
20 GRAPHI CS O,? ,?" TYPE-A-TUNE PROGRAM"
25 ? ,? "PRESS KEYS 1-9.0.<.> TO PRODUCE NOTES,";
27 ? " RELEASE ONE KEY BEFORE PRESSING THE
NEXT,"
28 ? "OTHERWISE THERE MAY BE A DELAY,"
30 FOR X=I TO 37, READ A;CHORD(X)=A,NEXT X
40 FOR X=I TO 12, READ A;TUNE(X) =A ,NEXT X
50 OPEN 1I1.4,O:·K,"
55 OLDCHR=-I
60 A=PEEK(764)JF A=255 THEN 60
63 IF A=OLDCHR THEN 100
65 OLDCHR=A
70 FOR X=I TO 12JF TUNE(X)=A THEN SOUND O.
CHORD(X) ,1O,8,GOTO 100
80 NEXT X
100 I=INT(PEEK(53775)/4) JF (V2) =INT(V2) THEN 60
llO POKE 764,255;SOUND O,O.O,O,OLDCHR=- I ; GOTO 60
200 DATA 243.230.217,204.193.182.173.162.153.144.136.
128.121 ,114,108.102 ,96.91.85.81.76.72 ,68,64 .60
210 DATA 57.53.50.47.45.42,40,37.35.33,31.29
220 DATA 31,30,26,24.29,27.51.53.48,50,54,55
194
1,1,8,8,0,0,8 6,6,5,5,3,3,1
8,8,6,6,5,5,3 8,8,6,6,5,5,3
1,1,8,8,0,0,8 <; ,6,5,5,3,3,1
1,5,8,8,8,8,8, 1,8
1,5,8,8,6,3, 1
COMPUTER BLUES
This program generates random musical notes to "write" some
very interesting melodies for the programmed bass.
195
lIO T=T+1
liS GOSUB 200
120 GOTO 100
200 REM PROCESS HIGH STUFF
205 IF RND(O)<O.25 THEN RETURN
210 IF RND(0)< 0.5 THEN 250
220 NT=NT+I
230 IF NT> 7 THEN NT=7
240 GOTO 260
250 NT=NT-I
255 IF NT< I THEN NT=I
260 SOUND 2JAM(CHORD.NT).10.NT. 2
280 RETURN
500 REM PROCESS BASE STUFF
510 IF BASS=I THEN 700
520 BDUR=BDUR+1
530 IF BDUR< > TEMPO THEN 535
531 BASS=I:BDUR=O
535 SOUND 0.LOW(CHORD).10.4
540 SOUND I .BASE(CHORD) .THNOT).10.4
550 RETURN
700 SOUND 0.0.0.0
710 SOUND 1.0.0.0
720 BDUR-BDUR+I
730 IF BDUR < > I THEN 600
740 BDUR=O:BASS=O
750 THNOT=THNOT +1
760 IF THNOT< > 5 THEN 600
765 THNOT=I
770 PTR=PTR=I
780 IF PTR=17 THEN PTR=I
790 CHORD=LlNE(PTR)
600 RETURN
1000 DATA 162.144.136.144,121 ,108.102,108,108,96,91,96
IOlO DATA 243.182,162
1020 DATA 1,1.1,1,2.2,2.2,1,1,1.1,3,2,1,1
1030 DATA 60,50.47.42.40,33,29
1040 DATA 60,50,45.42.40.33.29
1050 DATA 81,68,64.57.53.45.40
2000 PRINT 116:PRINT 116:PRINT 116
2005 PRINT #6;" Computer"
196
2006 PRINT 116
2010 PRINf 116;" Blue,"
2030 RETURN
197
Chapter 15
198
instruction to remove the number (N) of input arguments off the
stack. If this number is not 0, all of the input arguments must be
popped off the stack also using PLA.
The subroutine should end by placing the low byte of its result
in location 212 (decimal). It should then return to BASIC using an
RTS (Return from Subroutine) instruction. The BASIC interpreter
will convert the 2-byte binary number stored in locations 212 and
213 into an integer between 0 and 65535 in floating-point fonnat to
obtain the value returned by the USR funct ion.
The ADR (address) function may be used to pass data that is
stored in arrays or strings to a subroutine in machine language. Use
the ADR function to get the address of the array of strings, and then
use this address as one of the USR input arguments.
We will take a look at an actual program very soon, but before
we do, let's review assembly language. Assembly-language pro-
gramming is the next step up from machine language. It still uses
the individual computer instructions for writing programs, but in-
stead of referring to these instructions by binary, octa l, or
hexadecimal codes, each instruction is referred to by a shorthand
tenn. Each instruction is referred to by a short multiletter desig-
nator known as a mnemonic. For example, the instruction that
causes the addition of binary numbers is referred to by the
mnemonic ADD. The mnemonic for a store accumulator instruction
might be STA. These mnemonics eliminate the need to deal with
binary code .1n addition, assembly-language programming provides
the ability to identify memory locations by symbolic names rather
than by actual address numbers. For example, the memory location
designated to hold the sum of an arithmetic operation might simply
be referred to as SUM. The actual memory address of that memory
location need not be used.
When you use assembly language, you will usually also use a
program called an assembler. The assembler is a translator pro-
gram that resides in memory and converts your program, written in
mnemonics and symbol ic addresses, into machine code which can
be executed by the computer. The assembler looks at each
mnemonic operation code and symbolic address and converts it into
its appropriate binary operation code or address. Each mnemonic
typically results in the creation of one binary instruction.
Assembly language programming greatly speeds up and
simplifies the programming process. It eliminates many of the
complications of dealing with binary numbers. Yet because assem-
bly language programs are capable of using the individual computer
199
instructions. powerful and efficient programs can be written.
The following program , Hexcode Loader, provides the means
of entering hexadecimal codes, converting each hexadecimal
number to decimal, and storing the decimal number in an array. The
array is then executed as an assembly-language subroutine . To use
this program. first enter it. Then save it on disk or cassette for
future use.
200
999 REM " EXECUTION MODULE .,
WOO CLR ,BYTES =O
1010 TRAP 3OO,D1M E$ (I),E(lNT(BYTES/6) H)
1030 FOR 1= 1 TO BYTES
1040 READ A, IF A>255 THEN GOTO 1060
1050 POKE ADR(E$)+ I,A
1060 NEXT I
1070 REM BASIC PART OF USER'S PROGRAM FOLLOWS
Once this much of the program has been typed. add your own
BASIC language part of lhe program. Start at line 1080 and include
the USR func tion that calls the machine-language subroutine. Some
sample programs follow.
COUni the total number of hex codes to be entered and enter
this number on line 1000 when requested. If another number is
already entered, simply replace it.
Run the program and enter the hexadecimal codes of the
machine-level subroutine. Press the return key after each entry .
After the last entry. type done and press the re turn key.
Now the data line (1500) displays on the screen. It will not be
entered into the program Wl(il the cursor is moved to it and the
return key is pressed.
Add a program line 5 gole 1000 to bypass the hexcode loader
(or delete the hexcode loader through line 260). Now save the
completed program by using csave or save. It is important to save
the program before executing the part of the program containing the
USR call . A mistake in a machine-language routine may cause the
system to crash . If the system does hang up , press the system reset
button. If the system doesn't respond, tum power off and on again.
reload the program, and correct the mistake.
The following sample programs can each be entered into the
Hexcode Loader program. The first program prints NOTHING IS
MOVING while the machine-language program changes the colors.
The second simple program displays a BASIC graphics design and
then changes the colors .
lOBO GRAPHICS I+ 16
1090 FOR 1=1 TO 6
1100 PRINT #6; "nothing is moving'"
1110 PRINT #6: "NOTHING IS MOVING!"
1120 PRINT N6; "nothing is moving'"
1130 PRINT #6: "NOTHING IS MOVING!"
201
1140 NEXT 1
1150 Q=USR(ADR(E$)+l)
1160 FOR 1=1 TO 25,NEXTLGOTO 1150
After entering this program. change line 1000 to read:
1000 CLR,BYTES = 21
When you have entered them all, type DONE and press the
return key . Now place the cursor after the last entry (999) on the
data line and press the return key.
Now run the program by typing GOTO 1000 and pressing the
return key . or if line 5 has been added, type RUN and press the
return key . Press the break key to stop the program and delete line
5.
The second program, which follows . should be entered in place
of the NOTHING IS MOVING program. Be sure to check the
BYTES = count in line 1000.
1080 GRAPHICS 7+16
1090 SETCOLOR 0,9,4
1100 SETCOLOR 1,9,8
1110 SETCOLOR 2,9,4
1120 CR=I
1130 FOR X=O TO 159
1140 COLOR INT(CR)
1150 PLOT 80,0
1160 DRAWfO X,95
1170 CR=CR+O.125
1180 IF CR=4 THEN CR=I
202
·..
Ii L ;,; j
~. I fi rIx i ifI !
H! Um hh II t~R
§
! !
i ~~~6~~~g~~~~§§~~~~ ~ ~~
~ coooooo o ooo
U !~m~~ *~s
i m~ ~mm ~ ~~
Ii
203
1190 NEXT X
12()() X=USR(AOR(E$)+l)
1210 FOR 1= 1 TO lSoN£)(T 1
1220 GOTO 12()()
Type RUN and press the return key.
Enter the hexadecimal codes for this program column by col-
umn.
68 2
A2 E8
0 EO
AC 2
C4 90
2 F5
BO 8C
C5 C6
2 2
90 60
C4 BYTES = 21
When you have entered them all. type DONE and press the
return ke y. Now place the cursor after the last entry (999) on the
data line and press the return key.
Now run the program by typing GOTO 1000 and pressing the
return key, or add line 5 GOTO 1000. type RUN and press the
return key. Press the break key to stop program and delete line 5.
Table 15-1 illustrates an assembler subroutine used to rotate
colors which might prove useful. It is included here for your infor-
mation.
204
Chapter 16
Continuing Education
Computer technology isn't something you can learn quickly by
simply buying a microcomputer and studying a couple of books. Not
that it isn't possible to teach yourself this way. but you'll save a lot of
time if you start with some professional instruction.
Ideally. the best way to learn computer technology is to attend
one of the bona fide schools offering courses in computer science,
but for some of you, attending one of these colleges or schools may
not always be possible. You have to earn a living and, therefore,
full-time instruction is out of the quest ion. You may find that a
home-study school can solve the problem . Location, working hours,
age. and educational background are not barriers for the serious.
highly-motivated home-study student. Furthermore. a person tak-
ing a home-study course can progress at his or her own pace-as
fast as he or she can master the lessons or as slowly and irregularl y
(within reason) as necessary. Two correspondence schools offering
courses in computer technology include:
NRI
McGraw-Hill Continuing Education Center
3939 Wisconsin Avenue
Washington, DC 20016
and
National Technical Schools
4000 South Figueroa Street
Los Angeles. CA 90037
205
NRI
NRI's advanced course of study called the Professional Course
is designed to get qualified individuals into the exciting and rapidly
growing field of computer technology as quickly as possible. The
course was created by selecting the lessons from NRI's Master
Course that deal specifically with computers. The Professional
Course lesson texts are described in detail later on. The first lesson
in the course is "Introduction to Computers," The final lesson is
"Digital Troubleshooting Equipment."
The Professional Course lesson texts are supplemented with
thorough training on the Radio Shack TRS-SO model nr microcom-
puter. This training is accomplished by interlacing the NRI Discov-
ery Lab with the TRS-SO. The lab is the only equipment that is not
included in the tuition price of the course. If you've previously taken
an NRI electronics course perhaps you have a Discovery Lab al-
ready. If not, you can order the Discovery Lab through NRI for
$100.
The TRS-80 model III with 16K RAM is included in their
Professional Course training. This Radio Shack microcomputer
comes fully assembled and ready to use. It has many practical
applications that you can utilize after you've finished using it as a
training device. Training on the TRS-80 will give you the hands-on
experience you will need to move ahead in the world of microcom-
puter technology.
The NRl Professional Course in Microcomputer training pre-
pares you for the tremendous employment surge in the field of
computer service technicians-a growth that has soared from
63,000 back in 1978 and will reach 160,000 in 1990. This phe-
nomenal growth predicted by the U.S. Department of Labor ,
Bureau of Labor Statistics will occur in an incredibly short
period-154% growth in 12 years!
In the fields of computers and electronics. education is not only
necessary to get a job but also important to advance in your career.
NRI courses provide a sound technical education as a foundation for
entry level jobs at the technician level. In addition, NRI courses are
ideal for continuing education, the on-going process of refreshing
your fundamentals and gaining new knowledge of high technology
subjects. Continuing education will keep you competent and pro-
vide the kind of knowledge you will need to advance on the job or
land a new, better job. If you are serious about a technical career, an
NRI course can get you into one sooner and keep you going longer.
206
An NRI course can open many opponunities for earning extra
income in your spare time. Many NRI graduates have opened
part-time service shops in their homes to make extra money. That
opportunity and many others still exists today. Completion of an
NRI course could help you get an FCC license that would allow you
to do part-time service and installation work on mobile, marine,
aircraft, or CB radios. There is also a great need for parHime
technicians to repair microcomputers . Part-time and "moon light-
ing" opportunities abound in electronics, and an NRJ course will let
you take advantage of them. Part-time work will often open up
unexpected opportunities that blossom into a full-time business ora
rewarding career.
Electronics and computers are great hobbies and leisure-time
activities. There are literally thousands of individuals that enjoy
e lectronics as a general-interest, spare-time diversion. Electronics
is fun, interesting, challenging, and exciting. It involves a variety of
interests including amateur radio , CB, personal computing, hi-fi!
audio, model trains, radio control, and just plain experimenting, kit
building and the like. An NRI course can get you into a hobby Quickly
and easily or enhance and enrich your present electronic hobby.
After all, a major part of any hobby is learning more about a subject
in your spare time . What better way than with a home-study course
such as those offered by NRI?
207
TYPICAL CORRESPONOENCE LESSONS
The following is a sampling of the lessons and kits found in
typical correspondence courses. Of course, the exact contents wi ll
vary from school to school, but these examples should give the
reader a good idea of what is in store for him or her .
Introduction to Electronics: Vou get off to a fast start with
an overview of the microcomputer industry. You get right to the
heart of the business with the study of what electricity is, how
electrical current is made to fl ow in a circuit. and the relations hip
between current, voltage, and resistance.
Ho w Electrici ty is Produced for Electronics: You explore
the important types of batteries such as dry ce lls. mercury cells.
manganese cells. lead-acid cells and nickle-cadmium cells. You are
then introduced to direct current (de) and to altematingcurrent (ae)
generators , and you carefully analyze how they work.
Cu rrent, Voltage, and Resis ta n ce: You are now ready for a
close-up examination of current, voltage, and resistance, discov-
ering how units of each are measured and how voltage sources act
when connected. You also learn how resistance limits the flow of
current. Since no discussion of electricity is complete without
carefully considering Ohm's Law (which is one of the most impor-
tant laws of electronics), it is presented here in a readily under-
standable manner. You quickly learn how to use it to determine
circuit parameters.
Series a nd P ara lle l Circu its : In this lesson you get into
more complex circuits, learning the difference between series and
parallel circuits. You learn all about resistance in series circuits,
voltage drops, and the very important relationship between the
voltage drops in a series circuit and the source voltage. Building on
this knowledge, you learn how to find the resistance in a parallel
circuit. The lesson concludes with a study of voltage and current in
parallel circuits.
How Resis tors a re Used: Now that you have the basic
background to understand resistors and how they are used in cir-
cuits, you study the watt, the wattage rating of resistors, and the
transfer of power. You learn about resistor values, the color code
used to indicate the value of a resistor, and about resis tors with
special characteristics, such as the temperature-sensitive ther-
mistor and the voltage-dependent varistor.
How Coils Are Used : You discover the different types of
coils. their uses and their basic function in electronic circuits. You
learn about magnetic circuits and compare them to circuits you have
208
already covered. You learn about induclive reactance and the op·
position that a coil offers to alternating current. You study Lenz's
Law for coils and learn how changing flux linkages can produce a
voltage. You study Kirchhoffs Voltage Law , and learn how Ohm's
Law is appl ied to simple circuits having resistance and inductance .
How Capacitors Are Used : In this lesson you study
capacitors (once called condensers) and examine the differences
between the various types (variable, paper , mica. ceramic and
electrolytic). You learn how these capaci tors are made. and how
they are used . You learn howa capacitor stores electricity, and how
it works in ac circuits. You also learn about capacitive reactance.
How Re sistors, Coils. and Capacitors Are Used To·
gether: Now that you understand resistance. capacitance, and
inductance, you see how ci rcuits which contain all three can form
resonant circuits. You learn about both series·resonant and
parallel-resonant circuits. You learn how important resonant ci r-
cuits are and how they are used in e lectronics.
How Transistors Work : You begin your study of the theory
behind transistors. You learn what a semiconductor is and how
semiconductor materials are combined to fonn diodes and transis·
tors . You learn about the junction diode, the Zener diode. the tunnel
diode . the pin diode. and the varactor diode. You study npn transis·
tors and pnp transistors and learn how field-effect transistors work.
By the time you have completed this lesson, you will know what a
MOSFET is. and how it works .
How Transistors Are Used: You learn about the three prin·
cipal transistor circuits: the common·base circuit , the common·
emi tter circuit, and the common·collector circuit. You learn how
these circuits are used in amplifiers. You learn how the field·effect
transistor is used as an amplifier and how the gain of a dual·gate
field-e ffect transistor can be controlled.
Integrated Circuits: Here is an invaluable lesson showing
how transistors can be integrated into entire circuits and used in
computers and other equipment. This lesson is rounded out with a
study of both linear and digital integrated circuits.
Printed Circuit Boards: You get your firs t exposure to how
printed circuit boards are used to provide a convenient. low·cost.
and reliable means of mounting and interconnecting electronic com-
ponents. You learn how these boards are made and what materials
are used. You also learn how to layout typical printed circuit boards
and how to repair them.
Periodic Waves and Time Constants: This lesson pro-
209
vides an in·depth study of the types of signals and circuits used in
control systems, computers, and other advanced electronic sys-
tems. You study periodic wavefonns and pulses as well as the RC
and RL circuits which are used to shape the pulses and other
wavefonns.
Cathode Ray Oscilloscopes: This lesson explains in detail
how the cathode-ray tube is combined with various circuits to form a
complete cathode-ray oscilloscope. You see how the oscilloscope is
used as a tool to observe and measure waveforms in circuits.
Relays and Relay Circuits: Now you analyze the construc-
tion and operation of various types of relays. You see how they
perfonn remote switching operations and are able to control large
amounts of power under the control and direction of small signals.
Regulated Power Supplies: You explore the basic half·
wave and full-wave rectifier circuits and elementary filter circuits.
You even get a full explanation of how active regulators are used to
provide pure dc for electronic circuits. You also become fam iliar
with the basic series and shunt regulators , as well as with the
special switching and other feedback regulators.
Transistor Amplifier Circuits: In this lesson you study
common transistor amplifier circuits in detail and see how various
configurations affect input and output impedance, voltage and power
gain, and phase shift. You also consider the differential amplifiers
and special compensating techniques used for stabil ization.
How Oscillators Work: Now you can concentrate on how
transistors and integrated circuits can be used with LC circuits , RC
circuits, and crystals to produce oscillation. You study practical
circuits that generate the sinusoidal and pulse wavefonns useful in
rf and computer timing applications. You investigate the operation
of several types of special digital circuits including the monostable
multivibrator and the astable multivibrator .
Introduction to Computers: You are now ready for a
close-up look at computers and their applications. You learn the
basic structure of computers, with special emphasis on the different
types of computers and their various circuits.
How Computers Are Used: The entire thrust of this lesson
is a well organized overview of how computers are used. A wide
variety of computer applications are discussed , paying particular
attention to their business and scientific applications. You explore
special topics such as simulation, time sharing, and process control.
Basic Computer Arithmetic: This lesson provides a review
of the decimal number system. It then teaches you what binary
210
numbers are and how they relate to decima l numbers. You go on to
study the forms used for binary addition. subtractions, multiplica-
t ionand division in whole and fractional number applications. When
you complete this lesson you'll see the relationships between bi-
nary, octal. hexadecimal, and decimal numbers clearly.
Dig ita l Codes and Computer Arit hme tic: Now you begin a
close examination of fixed and floating point numbers . and the
methods used by computers to handle these numbers. You investi-
gate special codes such as the Gray code and the BCD code. You
learn about the complement representation of negative numbers in
binary and the popular ASCII code used by computers.
Digita l Logic Circuits : Here you observe the basic transis-
tor inverter used as a switch to represent the two binary states. one
and zero. Basic. AND, and OR gates are covered using simple diode
logic . And, you learn all about the more complex logic elements
such as NAND, NOR, and EXCLUSIVE OR using RTL, DTL, TTL,
ECL , MOS, and CMOS logic elements. The characteristics of the
various logic fam ilies are discussed clearly and simply.
Boole an Alge bra and Digital Logic: This lesson contains
an introduction to the special Boolean math used to analyze, design,
and optimize combinational logic circuits. This is the math that
permits complex logic networks to be expressed in easily manipu-
lated equations which can be translated directly into optimized
circuits using simple logic gates.
F lip-Flops, Regis ters, and Counters: You now look at the
various types of flip-flop circuits used to store and manipulate
binary data. Here you learn that specia l registers are made up of
combinations of flip-flops to store and shift large numbers of binary
digits . You also see how other combinations of special flip-flops
form binary and BCD counter or divider circuits.
How Digita l Logic Is Used : You gain an understanding of
how easily any complex logic function can be perlormed using only
basic NAND and NOR gates. The most widely used combinational
logic circuits are presented in such detail that you'll have no trouble
understanding them. They include encoders, multiplexers, demul-
t iplexers, comparators, and parity generators.
Comput e r Arithmetic Opera tion s: You learn how the
arithmetic section of this computer uses logic to perlorm its func-
tions and operations on fixed and float ing point numbers. You
become familiar with methods that are used to handle negative
numbers and you discuss hardware versus software handling of the
multiply and divide operations.
211
How Digital Computers Operate: You study the major
elements of the digital computer and discover how each section
depends on the others for proper operation and execution of stored
programs.
Register Transfer and Addressing: You learn the impor-
tance of registers in the computer. Special registers such as ac-
cumulators, index registers, program counters, and data registers
are discussed in detail. You find out how memory as well as input
and output can be considered to be registers when you are dealing
with the flow of data through the computer.
Computer Memories: Here you are introduced to the vari-
ous types of memories used in computers. You consider volatile as
well as nonvolatile memory . paying particular attention to semicon-
ductor memory and magnetic memory such as tape and disk.
Computer Input/Output: You learn how the 1/0 section of a
computer operates. In this lesson, special emphasis is placed on
becoming acquainted with some of the more popular types of
peripheral equipment used with computers.
Compute r Pe ripheral Equipment: Peripheral equipment
makes up a large portion of any computer system so it is important
for you to learn how the different types of devices operate. This
lesson carefully surveys printers. magnetic tapes, floppy disks . and
tenninals.
Data Convers ion Systems: Analog-to-digital (AID) and
digital-ta-analog (DI A) conversion techniques are covered in detail.
Here you also get into related topics such as multiplexing and
sample-and-hold amplifiers. You round out this lesson by consider-
ing how these units are combined with computers to fonn various
types of data conversion and data acqu isition systems.
Microprocessors and Microcomputers: The computer-
on-a-chip is the most poweriul kind of electronic component. Called
the microprocessor , these devices are used in complete systems
called microcomputers. The elements that make up microcomput-
ers of all kinds are described, and examples of some popular mi-
croprocessors are shown. The ways that microprocessors are com-
bined with memory and inpu t/output chips to create complete
computers for business and industrial applications are clearly and
concisely illustrated.
Microcomputer Applications: Already, mill ions of micro-
processors and microcomputers have been installed in consumer
products, industrial -process control systems, and small business-
es. In this lesson, several examples of popular applications are
212
illustrated. Examples include: (a) one-chip microcomputers in
higtHolume consumer appliances; (b) single-board microcomput-
ers used in industrial control; (c) special-purpose computers de-
veloped for industrial applications like automatic bowling scoring
systems and telephone PABX's; and for small business computer
uses, including payroll, inventory control, and project scheduling.
Microprocessors and Support Circuits: To adequately un-
derstand the operation of a microprocessor, you must be thoroughly
familiar with the electrical characteristics of major products and the
support chips required to make them work in practical circuits.
Support circuits covered here include clock generators, bus buffers,
and status latches. Also pinpointed are the differences between
synchronous and asynchronous storage reference systems, and the
means by which these systems are supported by additional les .
Memories and Input/ Output Ports: The structure of
memory systems and input/output ports are amazingly similar, and
are treated together. You learn the various ways the different
memory technologies are used. You also study the support circuitry
required to decode and select memory chips for both eight and
sixteen-bit word systems. You discover that some of the popular
methods of implementing simple serial and parallel 110 ports are
really special cases of memory architectures, and that the same
decoding methods apply.
Inte rface Circuits: Although input/output ports are essen-
tial to a microcomputer , most applications require specialized ways
of interfacing to unique sensors and actuators. In this lesson you
concentrate on those additional circuits and see how they work. You
explore the general rules that all interfaces follow and study some
specific examples of interfaces. Included in these examples are
audio cassette interfaces and simple analog interfaces for driving
conventional meters.
Registe r Transfers in Software: Now you are ready to
learn the simplest approach to programming any microcomputer.
This technique depends upon understanding all of the registers that
exist. and transferring data among these registers to achieve some
objective. You learn the techniques used for analyzing a computer's
instruction set and register complement. You also get detailed
step-by-step instructions for writing simple programs that use that
instruction set effectively.
Software and Programming: The important subject of
programming is introduced here. You get a general overview of
computer software including types of programming languages,
213
machine language, assembly language, higher-level languages,
higher-level compiler languages such as FORTRAN, and interpret-
ers such as BASIC, and programming and software systems.
Higher Level Languages: This lesson discusses the need
for the higher level languages and how they are used by computing
machines. Many popular languages are covered. A detailed expla-
nation, examples, and practice problems are included for the BASIC
and FORTRAN languages.
Programming Languages: Although programming can be
done in binary and assembly forms, the use of higher-level pro-
gramming languages is more popular and productive. In this lesson
you study the major features of the BASIC language, as well as some
features of the FORTRAN, PASCAL, and COBOL languages. Also
covered are other languages like FORTH and PUM.
Development Environments: You begin a careful analysis
of the various ways to develop microcomputer hardware and
software, including simple kits , software deve lopment systems,
and complete multiterminal systems. You discover the differences
between cross-support and native-support products, and the need
for compatible program storage media in the cross-support envi-
ronment. You also become familia r with various software tools,
including assemblers, compilers, editors, interpreters and operat-
ing systems.
Digital Troubleshooting Equipment: This lesson care-
fully surveys the basic tools used with microcomputers that are
different from the more conventional electronics instrumentation.
You discover the advantages of using equipment such as the digital
delayed-sweep scope. You also learn how to use such special
troubleshooting equipment as portable front panels (such as the
Intel 820 Scope). logic state analyzers, and in-circuit emulation.
After studying topics like those described in this chapter,
you'll be one of the new breed of computer tech.nician familiar not
only with programming and operations, but with the mechanical and
electronic nature of the expanding world of computers.
The following describes the various kits that currently accom-
pany correspondence courses in microcomputers and microproces-
sors. The examples are specifically from NRI's courses.
Kit No.1: In your first training kit, you begin your study of
actual electronic circuits , the ones you need to know about to be the
new breed of computer specialist; the parts you need are included.
Even if you don't know one end of a soldering iron from the
other, you can use this kit. The instructions in your first training kit
214
take you step-by-step through ten carefully-written experiments
which develop your basic electronics skills. You learn how to
identify and install parts and make good solder connections to both
component terminals and printed circuit boards. It isn't long before
you recognize symbols and know how to construct circuits using
schematic diagrams. These fundamentals are your foundation for
sound troubleshooting and repair techniques.
Using your batteries. resistors. and the LED (light-emitting
diode) supplied as part of your kit. you work on actual circuits. You
see the effect of changing the resistance or voltage in the circuit as
you study both series and parallel circuits. Using NRl's new Action
Audio cassettes and specially coordinated diagrams. you learn the
operation and practical applications of your Beckman 3~ digit digi-
tal muhimeter. You learn the professional way to take vohage.
current, and resistance measurements. The DMM becomes an
integral part of your tra ining when you use it in your experiments to
demonstrate the basic fundamentals of electronics. You'lI use it
later to measure power supply voltage and to verify the perfor-
mance of discrete components such as diodes. resistors. and tran-
sistors found on circuit boards in computers.
Specifications
Display :
3~ digit liquid crystal display (LCD) with a maximum read-
ing of 1999.
Power:
Single, standard 9-volt transistor battery.
Maximum Voltage:
1500 Vdc or peak ac.
Dimensions:
6.85" long x 3.65" wide x 1.8" high.
Weight:
16 ounces including battery.
Case:
High-impact ABS plastic. recessed switch and display.
Dc Volts:
lOOV to lOOOV in 5 ranges.
Ac Volts:
l00V to lOOOV in 5 ranges.
Dc Current:
100 nA to 2A in 5 ranges.
Ac Current:
215
100 nA to 2A in 5 ranges.
Resistance:
0.1 to 20 M in 6 ranges.
Kit No.2: You receive as part of your second kit, a profes-
sional hand-held digital mult.imeter. It's the basic, indispensible
tool for all computer specialists. You'll use this precision instru-
ment for all voltage, resistance and current measurements in the
experiments you perlonn in this kit, and you'll find it invaluable
after you've completed your course . You'll use it then to measure
voltages of power supplies and to verify the performance of discrete
components such as diodes, resistors, and transistors found on
most circuit boards in computers.
Using new audio cassettes and carefully coordinated diagrams
and schematics, you're personally talked through the operation and
practical applications of your digital multimeter (DMM) . By fol-
lowing the step-by-step instructions on the cassette, you learn why
it is important to establish a reference point when taking measure·
ments and that a point in the circuit can be both positive and
negative.
You learn about voltage dividers and discover how a shunt
resistor, called a bleeder, can reduce variations in the output
voltage. You also learn how to check continuity by making voltage
measurements with your DMM. As you listen to the carefully-
sequenced instructions, you put the ohmmeter section of your
DMM into operation, learning how to trace circuits and measure
series and parallel resistor combinations .
Because you are working with NRI's Action Audio cassette,
your hands are free to perlonn the necessary operations and you can
make your visual observations at the same time. You avoid the
necessity of looking back and forth between printed instructions and
your digital multimeter, thus saving time and reinforcing your
learning.
Kit No. 3: This kit introduces you to ac circuits and the
particular components used in them. To perlorm the experiments in
this kit, you get a special chassis, a power transformer, an iron-core
choke (inductor) . an ac line cord, resistors, capacitors. and miscel·
laneous hardware.
You explore the ac and de characteristics of tubular and elec-
trolytic capacitors, learning first-hand about "RC time constants,"
capacitor leakage, and capacitive voltage dividers. You see how a
capacitor can pass ac current and block dc current.
You also examine in detail the characteristics of inductors in de
216
and ac circuits and you determine how special resonant circuits can
be made by combining inductors and capacitors. You also look at
series and parallel resonance, seeing how these circuits can be
tuned by changing component values.
By the time you've completed this kit, you'll have no trouble
using your OMM to make both ac and de current readings and
resistor measurements.
The special design of the kits give you a complete breadboard·
ing system for setting up and modifying prototype circuits. per-
forming tests, and evaluating electronic components . You are intra--
duced to the kind of high technology that's at the heart of today's
astounding electronics revolution.
You'll perform an incredible array of tests and experiments.
Even as you assemble the Lab. you perfonn 10 specific experiments
demonstrating the nature of electronic principles; then you perform
10 experiments using parts that range from transistors through
integrated circuits.
Specifications
Power Supply:
±lOV unregulated
±5V regulated, 50 mA max
Function Generator:
Switch selectable waveform:
Triangle: lOY p--p
Square: 0 to 5V ITUCMOS compatible
Frequencies: 2Hz, 1Hz , 1kHz switch selectable.
Logic Indicators:
(4) identical LEO circuits with drivers TTUCMOS com-
patible inputs
Pushbuttons:
(1) debounced and buffered; ITUCMOS rompatible output
Slide Switch:
(1) 0 or +5V with lK pullup resistor
Line Clock:
60 Hz buffered output, TIlJCMOS compatible
Other Features:
2·5k free potentiometer
SPOT meter switch:
Breadboarding socket, solderless ronnections for ICs and
discrete components.
217
Kit No. 4: The successful operation of any computer depends
on a correctly operating power supply. In this kit you study the
fundamentals of power supplies.
You start by demonstrating counter-electromotive force and
showing that it can be used to produce a high voltage. Then you
study and compare the characteristics of the half-wave rectifier and
the full-wave bridge rectifier circuit. You demonstrate the former's
operation , see the effects of circuit defects, and compare its opera-
tion with that of a conventional full-wave rectifier. You go on to
observe how a simple filter increases the dc component and de-
creases the ac component of a rectifier's output. You also take a
good look at the operation of the pi filter and simulate a leaky
electrolytic capacitor to observe the problem of the power factor in
fi lters .
At this point you're ready to experiment with voltage doubler
rectifiers and observe how they produce twice the dc output voltage
of the basic half-wave and full-wave rectifiers. You go on to investi-
gate the operation of shunt voltage regultors using reverse-biased
Zener diodes. You examine the basic dc operation of npn and pnp
transislOrs. You wrap up this kit by studying the series voltage
regulator, and you actually assemble a dual polarity regulated
power supply on an etched circuit board. You'll use this power
supply in later parts of your course.
Kit No.5: You're given detailed instruction for assembling the
major portion of your kits. Their special design gives you a com-
plete breadboarding system for setting up and modifying prototype
circuits. perlorming tests, and evaluating components. Later, you'll
use these kits to demonstrate the action of various computer func-
tions.
Connecting components is quick and easy with the universal
components matrix of your kits. You simply plug in component leads
and you're ready to conduct experiments.
The experiments in this kit cover transistor fundamenta ls, and
solid-state amplifiers and oscillators. You begin by demonstrating
different methods of biasing npn and pnp transistors , and you build
the basic amplifier types: common-emitter, common-collector, and
common-base .
Now having experimented with the basic circuits, you are
ready to use the transistor in more complex configurations. First
you observe the operation ofa phase spl itter: then the operation of a
common-emitter stage used as a switch and as a voltage amplifier.
You learn about direct-coupled (DC) and resistance-capacitance
218
coupled (RC) amplifiers. and you construct and verify the operation
of an LC oscillator circuit. You investigate the workings of two
types of RC oscillators: phase-shift and multivibrator.
You'll quickly discover that the field-effect transistor plays an
important role in computer electronics. Consequently. you round
out this kit by experimenting with the methods of FET biasing and
the three basic FET amplifiers: common-source, common-drift. and
common-gate.
Kit No.6: Now you're ready to move into high tech advanced
electronic components and systems. To perform the experiments,
you receive 2 dual operational amplifier (op amp) integrated circuits
(ICs), 7 digitallCs, a 6-digit LED numeric display, an LED and
phototransistor, a unijunction transistor (uJD, and a silicon con-
trolled rectifier (SCR).
After you learn the basics of operational amplifier ci rcuits you
use a special dual op-amp IC to build a versatile funct ion generator.
This circuit provides you with a permanent signal source to furnish
variable-frequency square and triangular waves. You use an LED
level detector to see how these two waveforms differ.
You constuct and examine digital logic circuits-circuits just
like those that make up all computers. You work with the basic
digital storage element. the flip-flop and see how it can be used as a
frequency divider. You also learn how a binary<oded-decimal
(BCD) counter works, and how to connect the BCD output to a
decoder and numeric display unit.
219
Appendix A
Alphabetical Directory
of Basic Reserved Words
11It followmg material is coones), of ATA RL Inc., a Warner Communications
Company and is used with their pennission.
Note: The period is mandatory after all abbreviated keywords.
ASC """.
String function returns the
numenc value of a single
stnng character.
ATN Function ret urns the arctan·
gent of a number or expres-
SIOn In radians or degrees.
BYE B. EXII from BASIC and return
to the resident operating sys-
tem or console processor.
CLOAD CLOA . Loads data from Program Re-
corder into RAM.
CH" String function returns a sin-
gle SIring byte equivalent to
a numeric value between 0
and 255 In ATASCU code.
220
RESERVED BRIEF SUMMARY
WORD: ABBREVIATION: OF BASIC STATEMENT
CLOG Function returns the base 10
logarithm of an expression.
CLOSE CL- VO statement used to close a
ftle at the conclusion of VO 0p-
erations.
CLR The opposite of DIM :
Undimensions all strings:
matrices.
COLOR C. Chooses color register to bI!
used in color graphics work.
COM Same as DIM .
CONT CON . Continue. Causes a program
to restan execution on the
next line following use of the
_ key or encounlering
a stop.
COS Function returns the cosine
of the variable or expression
(degrees or radians) .
CSAVE OUtpulS data from RAM 10
the program recorder for
tape storage.
DATA D. Part of read/data combi-
nation. Used to identify the suc-
ceeding items (which must bI!
separated by cornrnas) as indi-
vidual data items.
DEG DE . Statement deg tells com-
puter to perform trigo-
nometric functions in degrees
instead of radians . (Default in
radians.)
DIM 01. Reserves the specified amount
of memory for matrix, array,
or string. All string variables,
arrays. matrices must be di·
mensioned with a dim state-
ment.
DOS DO. Reserved word for disk oper.
ators. Causes the menu to be
displayed . (See DOS Manual .)
DRAWl'O DR. Draws a straight line be-
tween a plotted point and
specified point.
END Stops progrwn execution: clos-
es files ; turns off sounds. ~
gram may be restaned using
cont. (Note: end rnay bI!
used more than once in a pro-
grnm.)
ENTER E. VO command used to store
data or progrnms in untok-
enized (SO\lJ"Ce) form.
221
RESERVED BRIEF SUMMARY
WORD: ABBREVIATION: OF BASIC STATEMENT
EXP Function returns e (2.7182818)
raised to the specirled powe r .
FOR F. Used with next to estaJ>..
lish for/next loops. Intro-
duces the range that the loop
variable will operate in dur-
ing the execution of loop.
FRE Function returns the amount
of remaining user memory
(in bytes).
GET GE. Used mostly with disk opera-
tions to input a single byte of
data.
GQSUB GOS. Branch to a subroutine begin-
ning at the specified line
number.
GOTO G. Unconditional branch to a
specified line number .
GRA PHI CS GR. Spedfles which of the eight
graphiC! modes is to be used.
Gr.O may be used to clear
~"
IF Used to cause conditional
branching or to execute
another statement on the saJrn!
line (only if the first expres-
sion is true).
IN PlIT I. Causes computer to ask for
input from keyboard. Execu-
tion continues only when the
CI8CI:I key is pressed after input-
ting data.
INT Function returns the next low-
est whole integer below the
specified value. Rounding is
al ways dowowan:\, even
when number is negative.
LEN String function returns the
leRgth of the specified string
in bytes or characters (l byte
contains 1 character).
LET LE. Assigns a value to a specific
variable name. Let is option-
al in ATARl BASIC, and may be
simply omitted.
LIST L. Display or otherwise outpUt
the program list.
LOAD LO. Input from disk . etc. into the
computer.
LOCATE LOC. Graphics: Stores. in a speci-
fied variable. the value that
controls a specified graphics
point.
222
RESERVED BRIEF SUMMARY
WORD: ABBREVIATION: OF BASIC STATEMENT
LOG Function returns the natural
logarithm 01 a number.
LPRINT LP. Command to line print ~r to
print the spedfJt:d message .
NEW Erases all contents of user RAM.
NEXT N. Causes a for/ next loop
10 terminate Of continue de-
pending on the particular
variables or expressions. All
loops an!' executed at least once.
NOT A " l ~ is returned only if the
expression is NOT true . If it
is true, a w()'" is returned.
NOTE NO. See DOS/FMS MatuUJi ... used
only in disk operations .
ON Used with goto or iOfUb
for branching pull)OSt:S . Mul-
tiple branches to different line
numbers are possible depend-
ing on the value 01 the ON
variable or expression .
OPEN O. Opens the specified file for in-
put 01 output operations.
OR Logical operator used be-
tween two expressiorl!l. If
either one il true, a wI' is eval-
uated. A w()'" results only if
both an!' false .
PADDLE Function returns position of
the paddle game controller.
PEEK Function returns decimal
fonn of contents of spedfied
memory location (RAM or
ROM).
PLOT PL. Causes a single point to be
plol:ted at the X,V location
specified .
POINT P. Used with disk openlllions
only.
POKE PO •. Insert the specifJt:d byte into
the specified memory location.
May be used only with RAM.
000'1 try 10 POKE ROM or
you'll get an error.
POP Removes the loop variable
from the KOSub stadt . Used
when departure from the
loop is made in other than
!lOnnal manner .
POSITION POS. Sets the cursor to the sped-
f.ed screen position.
PRINT PRoor ? UO command causes output
from the computer to the spec·
ifled output devklt:.
223
RESERVED BRIEF SUMMARY
WORD: ABBREVIATION: OF BASIC STATEMENT
224
RESERVED BRIEF SUMMARY
WORD: ABBREVIATION: OF BASIC STATEMENT
STEP Used with for/next. De-
termi ~ Quality to be
skipped between each pair of
loop variable values.
STICK Function returns position of
stick game controller.
STRIG Function returns 1 if stick
trigger button not plftsed, 0
if pressed.
STOP ST~. Causes execution to Stop, but
doH oot close filet or tum off
ST"
""""',.
Function returns a chaTllCter
string equal to numeric value
given. For exam ple: STRS(65)
~turns 65 as a Strilll.
THEN Used with if: If expres-
sion is true, W th!n
statements are extcUled . If W
expression is false, control
passes to next line.
TO Used with for as in "FOR X
'" 1 TO 10". Separates the loop
range expressions.
TRAP T. Takes control of program in
case of an INPUT error and
directs extcUtion to a speci-
ned line number.
US. Function returns results
of a machine-language suD-
rOl.ltine.
VAL Function returns the equiva-
lent numeric value of a string.
X10 x. General 110 statement used
with disk operations {see
OOS/FMS MflI'IlUJ{J and In
gaphics work (Fill).
225
Appendix B
Error Messages
ERROR
CODE NO. ERROR CODE MESSAGE
2 Memory Insufficient to store the statement or the
new variable name or 10 dim a new string variable .
3 Value Error: A value e)CJ)eC\ed to be a positive in-
teger is negative. a value expected to be within a
, specified range is not.
Too Many Variable.: A maximum of 128 differen t
variable names is allowed. (See Variable Name
Limit.)
5 Siring Length Error. Attempted to store beyond the
DIMensioned string length.
6 Out of Data Error: Read statement requires more
data items than supplied by DATA statement(s).
7 Numbe r greater t han 32161: Value is IlOt a posi·
tive integer or is greater than 32167.
8 Input Statement Error. Attempted to input a
non-numeric value into a numeric variable.
9 Array or String DIM Error. Dim size is greater
than :rJ.767 or an array/matrix refereoce is OUt 01 the
range of the dimensioned size, or the array/matrix or
string has been already dimensioned, or a reference
has been made to an undimensioned amy or string.
10 Argument Stack Overflow: 1bere are too many
gosubs or too large an expression.
II Floating Point Overflow/UnderfJow Error:
Attempted to divide by zero or refer to a number
larger than 1 x lO98 or smaller than 1 )( lO-99.
12 Line Not Found: A gosub, goto, or then ref-
erenced a oon-existent line number.
13 No Ma tching For Statement : A next was en-
countered without a previ()Us for, or nested forI
226
ERROR
CODE NO. ERROR CODE MESSAGE
".,
129
131
IOC8 already open
Nonexis tent Device was specified.
IOCB Write Only. Read command to a write-only
device (Printer).
132 Invalid Command: The conunand is invalid for this
device.
133 Device or File not Open: No open specified for the
device.
134 Bad IOCB Number. Illegal device number.
135 IOCB Re ad Onl y Error. Write command to a
read-only device.
136 EOF: End of File read has been reached. (NOTE:
This message may occur when using cassette files.)
137 Truncated Record: Attempt to read a reconllonger
thlll1 256 characters.
Device Timeout. Device doesn't respond.
'"
139 Device NAK: Garbage at serial pan or bad disk
drive .
,,<) Serial bus input framing error.
141 CUl'8Or out of ra nge for partirular mode.
142 Serial bus data fra me overrun.
143 Serial bua da ta fra me checksum e rror.
144 Device done e rror (invalid "done" byte): Attempt to
write on a write-protected diskette.
227
ERROR
CODE NO. ERROR CODE MESSAGE
145 Read after write compare error (disk handler) or
-.
bad screen mode handler.
146 Function not implemented in handler.
147 Insufficienl RAM for operaling selected graphics
160 Drive number error.
1'1 Too many OPEN files (00 sector buffer available).
162 Disk full (no free sectors)
163 Unrecoverable system data 110 error.
164 File number mismatch: Links on disk are messed
165
"File. na me error.
166 Poini dala lellJth error.
167 File locked.
168 Command invalid (special operation code).
I'" Direclory full (64 files).
110 File DOl round.
171 Point invalid.
110C8 refers 10 inpuUout]>llt cootrol block. 1lIe device number is the same as the
loeB number.
228
Appendix C
ATASCII
Character Set
#..fI'
...
~
"
+v
";.l~"'.#
..: -'.,.,-.
~ ,.
,.~
.$'
...:-"
,;,~..~...
...' ¢
",,"" ¢~
..'
...~~'
~¢",.,,;,.
...:-+'"
..'I'
",>
,::-"
;,~)0"+,,,.
...' ¢
.~..." ."
....,\..,v
.j-' ;.~
...,,, ¢'
:-
""
.' .,.....
0 0 C 13 0 Iii 26 lA ~
G 14 E I!!! 27 lB ~
2 2 II 15 F 1'1 28 lC D
3 3 g 16 10 g 29 10 0
, , CJ 11 11 12 30 IE e
5
6
5
6
CI
~
18
I'
12
13
=
C
31
32
IF
20
=
Sp;H..-
7 7 ~ 20 14 D 33 21
~ ~ 22
8
• •
8
II
21
22
15
16 ~
" 35 23 •
10 A ~ 23 17 ~ 36
" •
II B iii " 18 e 37 25
•
12 C iii 25 I' [J 38 26 .
229
_
,,>- .<?
# ->? .,.- ,- 1I.I'.<? f.?;t,- ///
$'. ~~ d't' ..~..~+' +~:~ $'t- .... • <i'
39 27 62 3E > 85 55 u
40 28 63 3F 86 56 ,
41 29 54 40 0 87 57 w
42 2A 85 41 A 88 58 X
43 2. 66 42 , 89 59 ,
..
44 2C 67 43 c 90 SA z
4S 20 68 0 91 5• [
2. , \
46
47 2F /
59
7Q
4S
46 , "
93
5C
50 J
48 71 47 G 94 5.
30
" A
49 31 72 48 H 95 SF
50 32
, 73 49 96 60 a
51 33 , 74 4A 97 61 •
52 34 • 75 4. , 98 62 b
53 35 5 76 4C I 99 63 ,
54 36 , 77 40 100 54
, " d
55 37 78 4. N IO! 65 •
56 38
, 79 4F 0 102 66 f
, •
..
9 50 103 67
57 39 50
58 3A 81 51 Q 104 h
59 3. 82 52 , 105 69
60 3C < 83 53 5 106 6A J
61 30 • 84 54 T 107 6B •
230
h ~/~ IJ ,<II'/~ ~;; /j~/
-
108 tiC 131 83 154 9A
,~,
n6 74 139 8B 162 A2
126 7E D 149
"
95 112 AC
127 7F D ISO 96 113 AD
128 151
129
80
81 152
'"
98
174
175
AE
AF
181 B5 204 CC m E3
B'
206
207
208
CE
CF
DO
229
230
231
E5
E.
E7
186 SA m Dl 232 E8
187 BB 210 D2 233 E'
188 BC 2ll D3 234 EA
189 SD 212 D. 235 E.
190 BE 213 D5 236 EC
1'1 SF 21. D< 237 ED
192 CO 215 D7 238 EE
193 CI 21' D8 239 EF
194 C2 217 D9 240 FO
195 C3 218 DA 241 FI
196 C4 21' DB 242 F2
197 C5 220 DC 243 F3
232
F6 250 FA 254 FE
247 F7 251 FB 255 FF
248 F8 252 Fe
249 F9 253 FD
IITI\!CII "ando IiIor *I\T" ~II\.'CI" · ...... , ......... n .... oI>ff> ..... I ...... m<' "aI ....... , _ In ASCII. buo
....... 0(, ... ap«Vl_............ dill....."
~. u"",,," ......... n. door......... r""" 1~' .... ""' ....... rol"n<~1 I 10 ,27
233
Appendix 0
ADDRESS CONTENTS
Dedmal Heudedmal
65535 FFFF OPERATING SYSTEM ROM
57344 EOOO
57343 OFFF fLOATING POINT ROM
55296 DBOO
55295 D7FF
HARDWARE REGISTERS
53248 DOOO
53241 CFFP
NOT USED
49152 COOO
234
ADDRESS CONTENTS
Decima] Hexadecimal
DISPLAY LIST (si~e varies)
31755 7CIF
..
(7C IF if 32K system, (GRAPHICS 0)
i OSMEMTOP i
FREE RAM
(size varies)
.. I BASIC MEMTOa
BASIC program, buffers. tables. rwl-time staCk.
..
(2A80 if DOS, may vary)
1_ 2ASO cn:l OS MEMLQ
BASIC LOMEM
I
10819 2A7F DISK OPERATING SYSTEM (2A7F-700)
9856 2680 DISK 1/0 BUFFERS (current OOS)
9855 267F DISK OPERATING SYSTEM RAM (current DOS)
4864 1300
4863 12FF FILE MANAGEMENT SYSTEM RAM (current DOS)
1792 700
1791 'FF FREE RAM
1536 600
1535 5FF
FLOATING POINT (used by BASIC)
1406 57E
1405 57D
BASIC CARTRIDGE
US2 480
USI
1021
.7F
3FD ] OPERATING SYSTEM RAM (47F-2()())
CASSETIE BUFFER
1020 3Fe
RESERVED
1000 3E8
999 3E7 PRINTER BUFFER
900 3CO
959
832
3BF
340 ] 10CB's
831
512
33F
200 J MISCELLANEOUS OS VARIABLES
235
ADDRESS CONTENTS
Decimal Hexadecimal
236
Appendix E
Derived Functions
Derived Functionl Deri ved Functions in Terml
of ATARI Functions
""",
eo..a.,
SEC(X)=UCOSOO
CSC(X)::USIN(X)
Inverse Sine ARCSIN(X)::ATN(XISQR(-XoX+I))
Inverse Cosine ARCCOS(X)=-ATN(XISQR(- X. + U+ x
CONSTANT
Inverse Secant ARSEC(X)::ATN(SQR(X.X-l»+{SGN(X-l)o
CONSTANT
Inverse Cosecant ARCCSC(JO=ATN(l/SQR(Xo X-l»+(SGN(X-lJ
_CONSTANT
Inverse Cotangent ARCCOT(X)=ATN(X)+CONSTANT
Hyperbolic Sine SINH(X):(EXPOO-EXP(-X»12
Hyperbolic Cosine COSH(X)=(EXP(X)+Exp(-X»/2
Hyperbolic Tangent TANH(X):- EXP(- X)/(EXP(X)+EXP( - X) o2+ 1
Hyperbolic Secant SECH(X)=21(EXPOO+EXP(-X)
Hyperbolic Cosecant CSCH(X):2I(Exp(x)-EXp(-X)
Hyperbolic Cotangent COTH(X) :EXP(- X)/(EXP(X)- EXP(- X»o2+ 1
Inverse Hyperbolic Sine ARCSINH(X)=LOG(X+SQR(XoX+l»
Inverse Hyperbolic Cosine ARCCOSH(X)+LOG{X +SQR(X· X-I))
Inverse Hyperbolic Tangent ARCTANH(X)=LOG«(l+X)/(l-X)12
Inverse Hyperbolic Secant ARCSECHOQ=LOG«SQR(-XoX+lHlIX)
Invente Hyperbolic Cosecant ARCCSCH(X)::LOG«SGN(X)oSQR(XoX+l)+lJ
IX)
lnVfne Hyperbolic Cotanaent ARCCOTH(X)=LOG«X+ t)/(X- l))12
Noks:
1. H in RAD (default) mode, constant:: 1.57079633
Hin DEG mode, constant 90. =
2. In this chart, the variable X in parentheses represents the value or expression to
be evaluated by the derived function. Obviously. any variable name is pennissi-
ble, as long as it represents the number or 6J)ression to be evaluated.
237
Appendix F
Printed Versions
of Control Characters
TI!e cursor and screen control characters can be placed in a string in a program or
used as a direct mode statement by pressing the _ key before entering the
_m.
cllaracter from the keyboard. This causes the special symbols which are shown
n_
-••
below to be displayed.
••
•"- •a _~o
•• aa
~ nom
&I
&I
•• aa •
II
&I
~.
•• •aa ••
•• • ••
••
•• a.
•• ••
a •
238
Appendix G
Memory Locations
Note: Many of these locations are of primary int~rest to expen programmers and are
incll.lded here as aconvenience. The labels given arc used by AT ARI programmers to
make programs more readab~ .
DECIMAL HEXADECIMAL COMMENTS
LABiL LOCATION LOCATION AND DESCRIPTIONS
APPMIn 14.15 DE Highest location used by
BASIC (LSB. MSB)
RTCLOK 18,19,20 12.13,14 TV frame counter (V60
sec.) (LSB, NSB, MSB)
SOUNDR 65 41 Noisy VO Flag (O=quiet)
n Attract Moeit' Flag
028=Attract mode)
LMARGlN ,
RMARGIN
ROWeRS
COLCRS
..
82,83
85,86
52,53
54
55,55
Left, RighI Margin (De-
faults 2, 39)
Current cunor row
(graphics window).
Current cUl'Xlr column
(graphics window)
OLDROW 90 SA Previous cursor row
(graphics window).
OLDCOL 91,92 58 Previous CIUW)!" column
(graphics window).
93 50 Data under C'Uf!Or (graph-
ics window unJesa mode
0),
NEWROW 96 60 CUr.iOr row to which
drawto will go.
NEWCOL 97,98 61.62 CUno!" column to which
drawto goes .
RAMTQP 106 6A Actual top of memory
(nwnber of pages),
239
DECIMAL HEXADECIMAL COMMENTS
LABEL LOCATION LOCATION AND DESCRIPT IONS
LOMEM 128.129 80.81 BASIC low memory
pointer.
MEMTOP 144.145 90.91 BASIC top of memory
pointer.
STOPLN 186. 187 BA.BB Line number at which
stop or trap occurred
(2-byte binary nwnber) .
ERRSAV 195 C3 Error number.
PTABW 201 C' Print tab width
(defaults to 10)
FRO 212,213 04.05 Low and high bytes of
value to be returned to
BASIC from USR function.
RADFLG 251 FB RAD/DEG flag (O=ra-
dians.6=degrees) .
LPENH 564 234 Light Pen· Horizontal
value .
LPENV 565 235 Light Pen· Vertical value .
TXTROW 656 290 CUf"$()r row (text window)
TXTCOL 657.658 291.292 Cursor column (text
window)
COWRO 708 204 Color Register 0
COLORI 709 2C5 Color Register I
COLOR2 710 2C6 Color Register 2
COLORJ 711 2C7 Color Register 3
COLOR4 712 2C8 Color Regisu~r 4
MEMTOP 741.742 2E5.2E6 OS top of available
user memory pointer
(LSB. MSB)
MEMLO 743.744 2E7.2E8 OS low memory pointer
CRSINH 752 2F0 Cursor inhibit (O=cursor.
on. 1 =cursor off)
CHACT 755 2F3 Character mode register
4 = vertical reflect; 2 =
normal; l =blankl
CHSAS 756 2F. Character base register
(defaults to 224) (224 =
upper case. 226 = lower
case cnaracter.;)
ATACHR 763 2FB Last ATASCII character.
CH 764 2FC LaSt keyboard key
pressed; internal code;
(255 clears character) .
FILDAT 765 2m Fill data for graphics
Fill (XIQ) .
DSPFLG 766 2FE Display Flag (l =
SSFUG
HATABS
767
79.
2FF
31A
_1.
display control character).
Start/Stop flag for paging
O=nonnallisling) Set by
240
DECIMAL HEXADECIMAL COMMENTS AND
lABEL WCATION WCATION DESCRIPTION
VO control blocks (16
IOCB 832
1664-1791
""
680-6FE
byteslIOCB)
Spare RAM
CONSOL 53279 OOIF Console switch6 (bit 2 =
Option; bit 1 = Select; bit
o = Start. Poke 53279,
o before readina. 0 =
switch pressed .)
PORTA 54016 O>JO PIA Port A Controller
Jack VO pons.
PORTB 54017 0"'1 PIA Port B lnitialiled to
hex lC.
PACTL 54018 0Jll2 Port A Control Refister
(on Program Recorder 52
'" ON. 60 '" OFf').
PBCTL 54019 0303 Port B control refister.
SKCTL S3775 020F Serial Port control reg-
ister. Bit 2 "" 0 (last key
still pressed) .
• Future product .
241
Appendix H
242
Analog-to-digital conversion-A8sembly language
243
ATASCD-Binary Load
244
Binary ~ve- Bug
245
Byte-Chip
246
Cto-Console
247
Console -CPU
248
CPU-Decode
249
Decoder-Di8k file
250
Disk pack-Eraee
251
Erase-Flowchart
252
Flowchart-Graphic display
253
Halt-Information bits
254
Infonnation bits-Instruction
255
Instruction-Keyboard
256
KeywOrd -List
257
Load-Matrix printer
258
Memory-Microprocessor
259
Microprocessor -Monitor system
260
Most Significant Byte-Numerical control
NOR: A logical operation that has a true output only if all inpu s are
zero (false) . The negative·OR operation.
NOT: A logic operator having the property: ifP is a statement, then
the NOT of P is true if P is false; and it is false if P is true. The
NOT operator is represented by an overline.
NOT AND: The NAND operation.
NOT AND gate: An AND gating circuit combined with an inverter;
a NAND gate.
Notation: The act, process, or method used to represent technical
facts or quantities. In computer practice, the term typically
describes the number radix, as follows:
NOTATION RADIX
BINARY 2
TERNARY 3
QUATERNARY 4
QUINARY 5
DECllMAL 10
DUODECIMAL 12
HEXADECIMAL 16
DUOTRICENARY 32
BIQUINARY 2.5
NOT if·then gate: A gate that performs the A AND NOT B and B
AND NOT A operations.
Null String: A string consisting of no character whatever. For
example. A$="" stores the null string as A$.
Numerical control: The automatic control of a machine or process
using numerical data that is introduced using punched tapes or
other input methods. Most numerical-control devices have lim·
ited logical capability, and they rely on the input medium for
261
Numerical control-Operator coMOle
262
OR-Precedence
263
Problem language-Programming
264
Programming-Random number generator
1. Definition of problem.
2. Preparation of flowchart.
3. Listing of computer instructions.
4. Selecting circuit patterns or control modes.
Programming flowchart: A (]owchart used to represent the
sequence of operations in a program.
Prompt: A symbol that appears on the monitor screen that indi-
cates the computer is ready to accept keyboard input . In ATARI
BASIC , this takes the form of the word "READY". A "?" is also
used to prompt a user to enter (input) information or take other
appropriate action.
Pseudo code: A code that requires translation prior to execution.
Pseudo codes are often used to link a subroutine into the main
routine, and they usually express programs in terms of source
language by referring to locations and operations using symbolic
names and addresses.
Pseudo instruction: A group of characters having the same gen-
eral form as an instruction, but never executed as an actual
instruction. Pseudo instructions are used as symbolic represen-
tations in compilers, interpreters, and assemblers to designate
groups of instructions for petforming a particular task.
265
Record-Selector
Save: To copy a program or data into some location other than RAM
(for example, diskette or tape).
Screen: The TV screen,In ATARI BASIC, aparticuiar VO device
codes "5:"
Sector: The smallest block of data that can be written to a disk file
or read from one. Sectors can store up to 128 bytes (single
density) or 256 bytes (double density).
Segment: 1. To divide a routine into parts with each one capable of
being completely stored in internal s torage and containing the
necessary instructions to jump to other segments. 2. A part of a
routine short enough to be sorted entirely in the internal storage
of a computer, yet containing the coding necessary to call in and
jump to other segments. A segment can be placed anywhere in
memory and addressed relative to a common origin.
Selector: 1. A switching operation based on previo~s processing
which allows a logical choice to be made in the program or
system. 2. A mechanical multiposition switch . 3. Cursor.
266
Separator--Sto~e
267
Storage-Track
268
Variable-Zone Bit
Variable: A variable may be thought of as a box in which a value
may be stored. Such values are typically numbers and strings.
Visual display tenninal: This is a device that permits inputs to a
computer system through a keyboard or other manual terminal or
input device such as a light pen, and whose primary output is
visual through a CRT unit or other type of display. The terminals
allow keyboarding, verification, editing, correction, and refor-
matting of material.
269
Index
Ac:c:eas time, 28 • Caooooo """","" _ _
from the, 118
-,
Adcftion, binary. 31--35 C8S9Itte 1'ICOI'dIf. UVing progI8ITII
Addresees, 81 on,he,116-118
Algebra, Boolean, 44·79 Cathode rrry tube, 17
AnaJog computers, 12
AND (Boolean operation). 50, 51 .....
Celslus-Fahrenhelt temperature con-
~.81 , 82.
•
107
~ Input loutput, 138-142
Commands, eound, 192, 183
BASIC commands, 127-'3' ~Its, BootMn, 53
BASIC I8f'9J8Q8 cartridge, 107 CornputM blUes program, 1915
BASIC programming statements. Corraptaer QOI'TIPOI tents, 97·'08
87-96 Computer elements. basic, 1~17
BASIC ntserved worda. directory. Compu1e<S, analog, '2
220-22. Computers, digital. 12, 15
BCOoode,11 Computer structure, 15-17
BiNwy artttvnetic, 31-<43 Conthulng edocation, 205-219
BInaty coded decimal, 10 ~. 18, 17,19,20
Bina'y codes, 10 Control charw:ters, pr1nIed WfIIons.
"""'<IglI, 4 238
BInary runber codes, 198 ControIenJ, 121, 122
Binary numbers, 1 Conver8Iona between number sys-
Blnaty runber system, 3 , .. tems. BCD to decimal, 11
"',3 CooversIone between numbM sys..
Boolean algebra eppIcationS to terns. blnaty to decimal, 7
swI1chIng ci'culs, 49-58 ConversIons between number sys..
Boo6tan algebra laws, 56-59
Boo6Nn cIasaes. 46, 47
Boo6Nn element. 46, 47
,.
terns, binafy to hexadecmel, 8,
C
cartrlclges, program, 98, 99
•
Data manipulation, 19-23
Data storage, 20, 21
C8s:Iette Input loutput, 140, '4'
Cauette recorder, 105. 106, 137 DecImal number system, 1-3
270
OeMorglrl's Theorem. 78, 79 Inputs, computer, 15, 16
0eriYecI functions, 237 instruc::tlons, arithmelic-loglc, 18
DIgttaI oomptners, 12, 15 instructions, control, 18
DIrect memory access. 26 Instructions, data movement. 18
DIsk 01Yes. 122-134. 137, 138 Instructions, Input /output. 18
Di8k8tt88. 123 Integer, 2
DIsk opeurtlug system (DOS). 124- Instruction set, 18
'27 Integrated ci'cuits, 25, 26
Otatt opeIaflOlls, 127-134 Interconnection of computer ele-
DIsk op8IatiollB, BASIC cornmands ments, 18
uaad with. 127-131 Interface, RS-232, 138
o.Ik utiIty pacQge (OUP), 124, 125 t0C8 (Input /output control block),
,
"""""'• ....,.. 39. '"
Edt Ieaturn, 102-105
'37
I 10 operations, 1~142
GIos8Iry,242
Graphics, 174-192
• MachIne language. 198-204
Margins, 175
Master bus control, 27
Master element, 27
Graphics oommands, 174-186 MathematIcs, binary, 31~
Graphics modes. 174-1n Maxtenns. BocMean, 47
Graphk::s modes. color, 178, 1n McGraw-Hili Continuing Education
GrtphIcs window, 1n Center, 205
Greatest common diviBOf program, Medlum-teale computers, 24
157-159 ~, ~, 14, 16
Gun ooISdor program, 159-161
Memory lOcations, 239
H Memory map, 234-236
Hardware, 15 Memory modules, 97, 120
Hexadecima1 numbers, 1 Memory saving techniques, 147, 148
Heudeclmal number sysIem, 8-10 Metrtc 000Y8I'8i0n program, 151-156
Hexcode loader program, 200 MiclocoolJ)Utef basics, 12
His;;HevelIangUage, 81 Mlctocompul8rs, 24. 25
Mlc!oooo.!pUters, one chip, 26
MicrooompuIer terms, 242
IC, 25. 26 MIcropt0C88SOfS, 23, 25, 26
lCa, dedicated, 26 Minicomputers, 24
Input, 16 Mlnterms, Boolean, 47
Input /output commands, 138-142 MultipllCatkln, binary, 37-39
Input /output de'IIc8I, 137, 138 Multiply instruction, 18
271
• Pwudoc:oM, 173
-'
NAND (Boolean opeiatfol,), 55
National TechnicaJ Schools, 205, 207
NOR (_ _1, ...55
NAI (correspollclence achooI), 205
•
RAM, 3O, 107
Number systems, 1 . Random-access memory, 30
NumCer~s, ~nmy, 3. 4 Re.t command, 20, 21
Number systemS. decimal, 1-3 Re8(k:)nly memory, 30
NurrtIer aystems, hexaclec:imal, 8·' 0 RegI""', 20
Number systems, octal, 7, 8 Regln.,_, 28
Number sysaeme and oodrIs, 1 ROM, 30, 98, 107
• AS-232 Irlterta::e, 138
Octal numbers, 1
Octal nuntler system, 7, 8
OR (Boolean operation), 52
•
Savtng programs on tape, 116-118
. . . _zr
OR (Boolean term), 47
ScnooIs, OOIT8&po1Idence, 205-208
Output devIoea, 15 Screen edflor, 138
Screen output, 142
" " - _,'7 SIze, computer. ~26
Paddle, 121 , 122 •
Pathways, bidI, ectIoI .... 19
Software, 15, 17, 18
Sound, I82·197
Pathways, data. 19, 23,26, 'Z7 Sound commands, 192, 193
PeriphenUs, 97, 106, 11~134
Printer, 137
PrWer Inputloutput, '4' , 142
_ ,_,'7
SpecIal purpoee functions, 146, 148
..
PrInters. 119, 120
,
Program, cIledd:look beIIncet, 161-
_ , _ _ '96
Subtraction, binary, 36, 37
Symbology, Boolean, 47~
T
Program. currency exChange, 1 4~ Techniques. fIowchewtIng, 185-173
_ '5'
157-159
.....
, ........ oommon_, Tempemure oonveraIon progr.n.
Text modes character print ~,
Program, gun COllector, 169-181 '88
Program, hexoode loader, 200 Text window, In
Progran,lIght show, 188 TranaIstoIa, 12
Program, metric: 00fMtI'160n, 151-156 TrIgonomeIrlc functiona, '44
~, IIIn ITIOdea cheracter pr1rt, TV monitor, 138
'88 Type • tune ptt98m, 183
Program, type a rune, 193
_ , Unilod _nag, '80 U
Prognrn, video graffiti, 190 United States nag program, 189
Programming, 80-96 USR function , 198
ProgrMlmIng, PlIrpo8H lor, 106
•
11.
---_ .......... ,..
ProgrammIng, slmp6e stepe In, 108-
VeHctI cIagIams, 61-78
f'rogfarmllng In ~, Vem cIegI'arns. <47, 4&-56
'88-204_ , 82
_
~ng statements, BASIC, 87, W
" , 88 Write command, 20, 21
ProgIatM'llng steps. 82-88 Writing to 1StOfage, 27, 28
Program 1'9COrder, 105, 106, 137
p~ , ~, 13, 15 X
ProgIaons. sample, 149-1S8 XOR (Boo6aIIn opeIatlOIl), 58
272