Commodore CBM 2001-16N, CBM 2001-16, CBM 2001-32, CBM 2001-32N User Manual

Page 1
BUSINESS
COMPUTER
BUSINESS
BUSINESS
BUSINESS
CBM
MODEL
USER
16N,
COMPUTER
COMPUTER
COMPUTER
32,
32N,
3016,
MANUAL
3016N,
3032,
3Q32N
Page 2
LJ
0
0
L
Page 3
Page 4
.
j
! |
n
i t
1
'
n
^
•'
,
n
r7
The
informationinthis
no
responsibility
PET
PERSONAL
manual
is
assumed
purposes
has been
for
inaccuracies.
only
and
©
Commodore
2001-16,
16N.32,
COMPUTER
USER
FEBRUARY
is
"All
MANUAL
1979
reviewed
subject
first
Business Machines,
rights
andisbelievedtobe
The
materialinthis
to
change
edition
reserved"
32N
entirely
manualisfor
without
Inc.,
notice.
1979
reliable.
However,
information
Commodore
t
Santa
Business
3330
Scott
Clara,
Blvd.
Ca.
95051
Machines
Page 5
TABLE
OF
CONTENTS
Chapter1.Welcometo
Chapter2.
UnpackingyourPETandturningiton
Chapter3.Basic
PET
keyboard
Screen
Chapter4.Beginning
The
PRINT
Variables
Direct
Literals
Functions
your
PET
keyboard
editor
input
BASIC
statement
and
program
statements
computer
Chapter5.Eiementaryprogramming
Unconditional
Data
Chapter6.
Advancedprogrammingtechniques
String
Subroutines
FOR
Subscrpted
entry
variables
NEXT
and
conditional
and
functions
loops
variables
looping
1
3
n
19
32
38
Chapter7.PET
communication
PET
interfaces
Commands
peripheral
IEEE-488bus
and
devices
withtheoutsideworld
and
lines
operations
for
Chapter8.Machinelanguageprogramming
Allocation
Commands
Machine
Chapter9.Errorsanddiagnostics
Debug
BASIC
OS
error
of
memory
from
BASIC
language
techniques
error
messages
messages
monitor
57
91
113
Page 6
LIST
OF
FIGURES
2.1
2.2
2.3
2.4
2.5
2.6
3.1
6.1
6.2
7.1
Rear
viewofPET
PET
memory
Memory
ASCII
codeinmain
ASCII6bit
PET
graphic
PET
keyboard
Functions
Principal
Simplified
bus
mapbyfunctional
code
character
scan
expressedintermsofbuilt-in
pointers
viewofPET
2001
memory
codes
lines
into
PET
blocks
RAM
BASIC
functions
3
4
6
7
7
8
12
43
55
57
7.2
7.3
7.4
7.5
7.6
7.7
7.8
7.9
7.10
7.11
Edge
connectorsJ1and
PET
IEEE
connector
Receptacles
IEEE
standard
Parallel
6522
VIA
Parallel
ConnectorJ3contact
Second
PET
second
for
user
port
addressesinPET
user
port
cassette
pinout
the
IEEE
connectors
information
example
identification
interface
edge
J2
interface
port
connector
J3
57
58
58
59
59
61
62
62
62
63
7.12
Edge
connector
J4
63
iii
Page 7
LISTOFFIGURES(continued)
7.13
7.14
7.15
7.16
7.17
7.18
7.19
7.20
7.21
7.22
Memory
Multiple
OPEN
OPEN
Status
Default
Examplesofdefault
IEEE
Transfer
Byte
expansion
file
structure
for
write
from
for
readtoPET
word
errors
parameters
bus
contact
bus
transfer
identification
handshake
from
talker to
connector
PET
parameters
sequence
listener
'
63
69
73
74
80
82
82
83
84
85
7.23
7.24
7.25
7.26
8.1
8.2
Signals
Status
IEEE-488
Code
Example
Machine
describedbyIEEE
codes
register
assignments
Floating
Language
for
IEEE
bus
addressesinPET
for
command
Point
Numbers
Monitor
bus
groups
mode
Listing
operation
87
88
88
89
94
100
IV
Page 8
LIST
OF
APPENDICES
A.
B.
C.
D.
E.
F.
Detailed
BASIC
BASIC
Expressions
Space
Suggested
PET
memory
statements
commands—intrinsic
and
and
speed
reading
map
functions
operators
hints
Page 9
1-
WELCOME
TO
YOUR
PET
COMPUTER
Congratulations
the
PET
2001
is
now
available
procedures
a
short
period
The
potentials
arise
that
this
WritetousatCommodore
withanewsletter
Commodore
3330
Santa
USA
360
Euston
London
England
3370
Agincourt
and
welcome
you
have
eliminated
for
learning
outlined
Scott
Clara,
Pharmacy
in
this
after
unpacking
of
your
PET
book
has
not
we'llbesending
Systems
Blvd.
Ca.
95050
Road
NWI
3B1
Avenue
M1W2k4
to
the
manual,
the
are
virtually
coveredoreven
with
Divisions:
the
exciting
the
problems
functions
you
shouldbeabletoachieve
shipping
new
of
and
capabilities
container.
limitless.
anticipated.
your
questions.
out
from
We
timetotimetousers.
world
of
personal
getting
This
a personal
of
your
book,byits
will
answer
computers.
computer
system
PET.Infact,ifyou
initial
operation
very
many
that
nature,
is
you
and
By
selecting
running.
Your
followafew
of
your
Pet
2001
limited.
other
Questions
users
will
time
simple
within
will
pose
PETisa
board,
white
by
At
the
operation
The
cannotbedestroyed
memory.
use
In
ordertosatisfy
have used
Summary
programmer.
more
PETabit,
instruction
The
sections
sections
more
PETiscalled
Personal
keyboard,
television
twenty-five
Electronic
computer
monitor,
lines.
heartofyour
of
the
screen,
productisso
(Called
the
PET
three
discussions
detailed
the
works.
third
typeofformat
are
difficult
familiar
construed
Read-Only-Memory)
with
impunity.
the
formatsinthis
When
you
explanations
italicized
for
people
to
with
the
BASIC,anacronym
which
PET
2001isan
keyboard,
because
needsofthe
in
this
are
summary
givesadetailed
who
follow
PET
Transactor.
board,
andaCommodore
displays
cassettes,
that
you
the
computer
serious
manual.
type
font
first
using
which
areinthe
sections
use
the
andwerecommend
operating
for
Everything
characters
MCS
6502
microprocessor.
and
cannot
damage
software,
This
allows both
useraswellasthe
are
designedtoanswer
your
PET
manual,
type
willbeuseful
description
PETatthe
system.
Beginners
machine
he/she
The
is
complete
supplied
inaformat
in
cassette.
that
This
additional
the
or
font
of.the
of
language
All-purpose
peripherals
PET
from
operating
the
first
time
first
the
read
these
preceding
when
you
how
the
PET
level.
The
use
them
onlyonre-reading
which you
Symbolic
one
steel
cabinet.
Thereisa
appeartoyoutobe
microprocessor
which
the
keyboard.
instructions
user
time
userofa
questions
sections
paragraph.
wanttoreview
implementsasection.
first
time
will
Instruction
canbeaddedtothe
are
and
the
of a
lightly
reader
usetocommunicate
It
contains
built-in
forty
totally
The
operating
contained
sophisticated
computer
professional
and
spend
After
you
have
howaparticular
may
find
the
material
Code.
a
CRT
black
and
characters
controls
PET.
system
inafixed
user
to
product,
timeonthe
These
these
with
used
the
when
your
we
Page 10
It
shouldbenoted
of
usageinmind,
the
appendix.
in
this
particular
The
ultimate
ask
youtouse
case,
this
documentation
examplesofyour
we
invite
commentsonthis
to
resolve
any
which
Someofthese
manual.
teaching
the
own,
unclear
that
there
are
available
manuals
device
PET
along
is
sufficient
any
questions
material
statement.
are
other
to
maybemore
for
learning
with
the
to
which
and
reference
the
material
public.Wehave
usefultosatisfy
how
the
PET
worksisthe
text,
rather
allow
particularly
than
youtoget
might
arise
on
just
startedonan
are
examples
written
about
included
continuously
BASIC,
a
listofsuch
a
specific
PET
itself.Insome
reading
example.Byconstructing
answeredbythe
which you
with
different
suggested
need
whichisnot
cases,wewill
whattodo.Inany
machine
as an
itself.Ofcourse,
individual
types
reading
in
covered
similar
have
used
Lastly,
programming
publications:
descriptions
operate.
book
purchased
since
this
aspectsofthe
Thereisa
of
Detailed
called
Programming
from
manual
the
auxilliary
specifications
Commodore
cannot
MCS
manual
available
devices
of
Manual.
directly.
presumetoprovide
6502
microprocessor,
from
your
which
the
Thisisavailable
generate
computer
all
dealer
the
and
the
for
NOTES
purchase
technical
we
direct
called
control
languageinwhichitoperates
information
youtotwo
Hardware
signals
from
your
of
hardware
other
Manual
necessarytoallow
PET
dealeroreither
Commodore
which
are
or
also
includes
the
PET
to
availableina
can
be
Page 11
Chapter
2.
UNPACKING
YOUR
PET
AND
TURNINGITON
Please
concealed
shipping
Remove
surface,
check
the
damage.Ifanythingisamiss,
agent.
your
PET
then
plugitinto
carton
from
for
its
protective
any
TV
BRIGHTNESS
ADJUSTMENT
any
special
unpacking
reportly
shipping
standard,
grounded
instructions
this
immediately
carton
and
placeiton
electrical
outlet.
and
carefully
to
both
the
the
counter,
(In
some
countries
examine
placeofpurchase
your
PET
for
and
desk,orother
no
plugisprovided.)
suitable
any
the
The
power
closingitto
position,oran
Immediately,
time-out
screen
characters
The
screen
microprocessor,
current
switchislocatedinthe
the
right
turnsitoff.
ON/OFF
when
circuitina
has
had
power
which
memory
and
contentsofthe
label.)
the
power
special
immediately
reflect
transfertothe
so,
screen
MEMORY
EXPANSION
J4
CONNECTOR
Figure
2.1.
fuse,
line
left
rearofthe
(Thereisa
switchisturned
condition
(reset
priortothis
the
current
contentsofthe
screenisdone
even
when
the
memory.
2NO
CASSETTE
INTERFACE
Rear viewofPET
cord
and
white
J3
USER
2001-8
interfacing
PET.
Closing
dotonthe
on,
powerissuppliedtothe
condition)
time,
you
computer
with
computerisnot
PARALLEL
PORT
J2
SERIAL
NUMBER
ANO
ELECTRICAL
showing
connectors
power
which
will
switch,
the
switchtothe
switchtoindicateitisinthe
initializes
seeonthe
memory
circuitry
operational,
outside
the
3-WIRE
AC
POWER
CORD
SPEC.
left
turns
the
PETonand
poweron
internal
them
circuits.
intoaknown
state.Ifthe
Thereisa
screenavarietyofstrange
whichiscontrolling
controlofthe
screen
always
the
screen.
main
displays
the
Page 12
At
the
endofthe
temporarily,
power-on
and
then
cycle,
displaysonthe
the
computer
screenamessage
initializes
the
internal
like
the
following:
memory,
blanks
the
screen
The
15359/31743
the
PET
computer
bytes
free
anda32K
If
you
failtoget the
To
get
the
(Input/Output),
The
relationship
referstoavailable
and
corresponds
PET
power-up
display,
and
four
Screen
between
***COMMODORE
15359/31743
READY.
users1
programmable
roughlytoone
will
display
display
different
Memory.
these
31743
the
typesofmemory
memoriesisshowninfigure
letterordigitofinformation.
bytes
first
time,
BYTES
FREE
memory.Abyteisthe
free.
try
turning
are
used:
the
power
ROM,
2.2.
fundamental
A16K
PET
switch
User
Read/Write,
slowly
data
will
display
off,
then
I/O
element
of
15359
back
on.
/
\
ROM
14k
address
\
/
/
RAM
16/32K
TV
\
RAM
1k
and
data-bus
\
/
I/O
2k
7V7v7\
keyboard
\/
IEEE-488
user
port
Figure
2.2.
PET
memory
bus
Page 13
ROM
(READ
ROM
causes
programs
the
real
the
lowest
operation
keyboard,
powered
I/O
MEMORY
The
second
devices
computer.
interfere
ordertoperform
ONLY
the
PETtoperform
writtenbyCommodore
time
clock,
cost
memory
of
his
machine.
or
from
the
on,
but
also
typeofmemoryisthat
called
PIA*
Except
in
any
way
legitimate
when
MEMORY)
and
execute
for
storing
Thisisbecause
user's
program.
the
user
and
VIA**
special
with
these
Input/Output
mostofits
which
commands
this
Not
program
whichisdevotedtoInput/output
which
allow
I/O
operations
areas.
The
operations.
scan
the
keyboard,
that
the
user
data,
but
also
give
the
operating
onlyisthe
cannot
the
operating
operations.
machine
damage
the
PETtoindividually
are
desired,
system
In
each
PET,
print
the
types
in.
Read
the
user
the
system
memoryisindestructible
available
BASIC
operating
operations.
control
the
user
should
automatically
14KofROM
display,
to
control
Only
most
run
BASIC
system.
memories
protection
from
This
the
bits
not
allow
handles
contains
input/output,
memory
that
his
these
a
series
are
not
and
the
from
the
momentitis
contains
manipulate
program
locations
of
count
only
fastest
the
I/O
the
to
in
USER
The
throughout
$1FFF.Adetailed
RAM,
for
The
location
performing
If
BASIC
memory
is
Later
program
SCREEN
The
makeupthe
which
ROM,
READ-WRITE
third
typeofmemoryisthe
this
I/O,
and
by
the
map,
its
various
message
1024
a
the
number
can
automatically
that
where
programs
on,wewill
overlays.
MEMORY
screen
memoryisphysically
takes
thus
displaying
MEMORY-R.A.M.(RANDOM
book.)Ina
mapofall
Screen
the
tasks,
'7167
and
checkonwhetherornot
was
comes
PET's
the
Memory
first
1024
including
BYTES
cycles
less
than
furnished
are
loaded
discuss
standard
individual
charactersonthe
User
Program
standard8KPET,itis
the
memoryisincluded
are
located
bytesofmemory
the
buffering
FREE"isa
through
the
15359/31743,
checkupto
with
the
and
BASIC
some
techniquestoexpand
composedofthe
memory.Itis
bytesofmemory
fromaprogramming
resultofan
memorytodetermine
the
Read/Write
you
32KofRAMaslongasthe
PET.
This
holds
constantly
and
screen.
ACCESS
Memory
located
are
reserved
of
data
MEMORY)
Space.
from
in
figure
for
from
the
the
cassettes
analysisofBASIC
which
Memoryisworking
may
haveahardware
memoryisreally
allofthe
uses
program
this
memorybyusing
same
kindofchips
being
usedbythe
themtoaddressaspecial
(We
will
call
this
area
location
2.3,
standpoint.
operating
locations
$0000tohexidecimal
showing
where
As
you
systemtouse
and
other
which
starts
are
available,
correctly.
problem.
added
memoryiscontinuous
the
working
memoryinthe
variables.
tape
that
are
used
CRT
control
character
RAM
the
ROM,
can
see
I/O
devices.
at
thereby,
to
the
machine;
files
and
to
electronics,
generator
it
As
mentioned
no
direct
*PIA-Peripheral
**VIA-Versatile
For
information
during
control
over
Interface
Interface
about
the
power-up
it.
Adaptor
Adaptor
these
and
related
discussion,
this
chips,
see
processistotally
6502
automatic,
Hardware
Manual.
and
the
programmer
has
Page 14
o
1024
8192
16384
32767
32768
33792 34816
RAM
RAM
RAM
RAM
Expansion
Operating
BASIC
User
~UseT
16K
32K
RAM
RAM
system
working
BASIC
Variables
PET
PET
area-24K
TV
ImagesofTV
and
storage
program
RAM
35840
36864
Expansion
49152
59392
61440
n
On
every
cycleoftheTVscreen
($8000)inthe
cornerofthe
givingusan8row
8
dots
each
toptobottom.
controller
on
whetherornotitis
character,
screen
screen.
timeitis
high
This
givesan8
memory
Each
characteronthe
addressed.
automatically
scanning
etc.
65536
(i/©oofa
and
processes
characterinthe
These
bit
wide8bit
changes
the
addressingofthe
the
top
Figure
second),
memoryisaddressed
screen.
dots
lineofa
ImagesofTV
ImagesofTV
ROM
ROM
I/O
ROM
2.3.
PET
memory
the
hardware
the
screen
The
character
are
serially
tall
character
character,
BASIC
operating
data
fedtothe
character
RAM
RAM
area-12K
system
map
starts
with
the
startingatthe
into
the
character
ROM
thatisused
screen,
withnospaces
working
between
generating
the
second
lineofof
least
address
upper
left-hand
generator
generates
from
characters.
ROM,
depending
a
eight
times,
lefttoright
The
and
CRT
There
are
two
character
screenbyPOKEing
the
second
to
try
lower
To
understand
character
this
featuretoseeifyour
case
letters
memory
for
this,
sets
storedinthe
address
set.
After
you
PET
the
graphic
letusreview
set
how
ROM.
You
can
59468
have
performs
witha14(a12turnsitback)
played
thatisavailableinthe
characters
with
this
way.
are
the
The
representedinthe
change
screenalittle
the
second
first
character
set.
character
which
bit,
PET
setonthe
turnsitto
you
may
set
substitutes
andinthe
want
memory.
Page 15
CHARACTER
The
standard
In
the
PET,
screen.
B
tflfcii
yiii
itjdb
idbl
ikjifcj
ibil
iiwu
iiyi
iiiu
iiil
Exampleinthe
Aisrepresented
Shifted
REPRESENTATIONINPET
ASCII
the
8th
b
i
i
t>
1
i
4
1
1
1
1
1
I
I
I
1
1
1
1
I
1
l
1
1
3
PET:
A
(a
MEMORY
codeisusedtorepresent
bit
(bit7)is
NUL
bOH
b
IX
tift
toi
tNti
H'vK
tftL
Bb
HI
Lh
VI
Hh
CK
bO
bl
spade)
is
usedtosignify
Id
i
i
JL>Lt
L'Ci
D^tL
i;»Cb
i>lJ4
NHK
SYN
t
IB
tw
bUii
Lb'w
hb
•ob
Kb
Vb
Figure
2
Figure
2.4.
ASCII
0100
0001
1100
0001
characters
BASIC
u
1
i
i
b
4
b
V
b
y
in
the
command
wordsorgraphics
i
H
t
Y
'o
H
i
J
K
L
h
H
character
set(7bit
code)
main
memory.
1
y
i
Q
k
b
i
U
V
w
K
V
L
\
J
i
i
1
bh'
a
b
c
d
e
f
h
i
J
k
i
rn
n
o
(RAM)
characters
i
i
1
p
s
t
u
X
2
I
for
the
PET
u
u
Li
U
0
0
The
screen
There
are
memoryisorganized
only64characters
1
fcJbil
i<i
iltli
111U
ilii
withadifferent
from
Figure
the
standard
tt
ft
B
c
t
h
H
1
J
K
L
M
N
0
2.5.
ASCII64character
representation
ASCII
set
that
K
b
i
U
V
X
Y
L
\
j
t
set(6bit
from
are
normally
1
y
code)
the
main
printable.
i
i
b
V
b
y
PET
memory.
0
LJ
U
U
LI
LJ
J
U
Page 16
These
The
6;
The
additional64dispiayable
This
characters
are
the
same
characters
representation
givingusa
graphic,orshifted
gives
the
are
in
screen
six
bit
code
characters,
following
organizedsothat
memoryisderived
for
characters.
table
that
are
directly
availableonthe
from
the
keyboard
characters.
setisrepresented
for
PET
dispiayable
they
are
justashift
PET
the
standard
by a1in
characters.
from
the
ASCII
bit
sixofthe
It
shouldbenoted
normal
keyboard.
setbydropping
screen
memory,
that
keyboard
character.
bit
giving
allofthe
graphics
an
n
£
b!
i
*s>
I
141
bum*
ki tl tl
i
!JL
fcjtfil
tflltf
Mill
1
i
Itfiu
itfll
11MU
11M1
llltf
1111
i
1
1
i
1
t
a
w
H
c
i>
L
\-
»o
H
i
j
K
L
M
N
0
1
Q
K
b
1
U
V
W
K
Y
^
L
\
J
V
Figure
i
u
11
%
be
*
+
-
/
2.6.
PET
i
••■
»;
graphic
y
1
i
i
y
id
i
4
b
V
b
y
;
>
y
character
i
*•»
-•*
L.
\
/
i
set(7bit
i
'->
l
i
1
X
D
*
if
code)
/•
i
i
i
u
1
i
■i
I
1
1
i
r
T
I
1
1
1
1
r-
L
1
J
fa.
-
J
kc
This
givesusthe
Character
A
f
1
_l
Note
the
reduction
ofAand1.In
field
consistsoftaking
a
white
dot
If
the
operating
memory
translation
screen
with
representation.
between
following
In
main
memory
0100
0001
1100
0001
00110001
10110001
from
seven
memory,
the
dot
black
andablack
systemisused,itautomatically
Both
PRINT
the
screen
conversions:
bit
ASCIItosix
the
8th
bitisusedtostore
pattern
memory
from
dot
withawhite.
and
direct
and
In
screen
memory
00000001 00110001
01110001
bit
gives
the
character
translates
input
the
main
from
memory.
8
the
effectofchanging
reverse
generator
the
the
field.
The
and
values
keyboard
from
resultinautomatic
the
order
reverse
reversing
ASCII
it,
replacing
into
the
screen
Page 17
USEOFTHE
There
the
normal
As
and
are
appropriate
longasthe
the
memory
the
useofthe
however,
thatisbeing
shouldbedisplayedatthat
it
runs
the
The
second
enabled,
The
third
SCREEN
three
waystoget
MEMORY
memory
updatingofthe
PET
directly
PET
are
contending
only
during
screen
times
memory
givesavisual
passed
more
waytoget
the
character
approachisby
from
flashing
data
being
data
address
screenistoo
controls
for
when
effect of
the
particular
there
onto
useofthe
into
the
screen
the
desired
slow.
the
screen,
accesstothe
the
screen
memory.
translated
thereisno
memory.
memoryisnot
The
character.
apparent
The
routines
being
downtoabout40percentofthe
flashing
PETtothe
will
be.
the
struckonthe
dots,
because
screen
position.
memory,
Whenaprogram
screenisthe
keyboardisautomatically
PRINT
commandinBASIC.
the
screenisdisplaying
rather
keyboard.
firstoftheseisto
Thisisprogrammed
effect
used
speed
obtainable
from
in
the
PET
for
display.
the
change
withaPOKE.
the
than
the
character
pokestothe
Duringatime
displayedonthe
When
screen,
when
POKE
into
only
fact
that
the
This
slows
when
the
screen
The
character
that
the
faster
keyboard
input
screen.
screen
POKE,
is
is
typedtoBASIC,itresultsinthe
Thisisa
The
byaflashing
print
Whatisphysically
i/6othofa
computer
the
be
showninalternating
By
moving
of
the
controlofthe
printofa
next
positionatwhichacharacter
positioninscreen
literal
signal
calledacursor.
fieldinwhich
memory.
happeninginthe
second,aninterrupt
(the
PET)
and
stepsablinker
screen
memory
the
pointer,wecan
keyboard
and
keyboard.
pointerisreversedinthe
normal
some
software
next
line
all
willbedisplayed
The
cursorisa
machineisthat
to
the
PETisgenerated.
counter/When
and
reverse
print
output
called
PRINT
"ABC"
being
printed
ABC
characters
between
visual
everytime
This
this
8th
bit.
This
field,
givingasvisual
any
placeonthe
the
screen
editor,
as:
the
quotes
if
typedonthe
indication
generates
counter
causes
screen.
which
to
the
screenisrecycled,
a
reads
the
reference
effectofblinking.
Thisisdonebyusingacombination
manipulates
are
printed.
keyboardisindicated
the
userofthe
next
about
real-time
37,
the
clockonthe
character
character
screen
referenced
to
memory
under
by
Page 18
NOTES
10
Page 19
Chapter
3.
BASIC
KEYBOARD
UNIT
Whenever
keyboardtothe
Keyboard
keyisstruck.
program,
There
is
the
the
keyboard
The
is
similartothat ofatypewriter
However,
PET
The
the
upperorshifted
are
always
a
thin,
leftinplacetoprotect
peelitoffbyusing
the
blinking
screen
cursor
memory.
dataistransferred
Only
afteracarriage
and
thenawhole
are
two
exceptions
useofGET,
which
to
willbediscussedina
dataisaccessed
PET
keyboard
some
1.
Becauseofthe
number
2.
The
number
3.
The
various
4.
The
characters
longer
convenienttohave
5.
All
standard
available
keyboard
has
been
important
changes
high
pad
has
been
pad
has
keys
for
which
require
shifting.
them
characters
by
useofthe
consistsof73
characters
used
unless
transparent
oneofthe
plastic
film
the
the
sticky
appearsonthe
by
the
lineistransferred
this,
directly
optimized
soatouch
useofnumbers
addedtothe
allofthe
screen
are
normally
These
available
are
shift
keys,
displayedonthe
covering
keys
against
sideofa pieceofmasking
screen,
interrupt
returnisthe
neither
routinetothe
keyboard
at
once.
oneofwhich
later
using
for
have
machine
useasa
typist
does
been
made:
and
calculations
rightofthe
mathematical
movement
characters
unshifted,
keys.
including
and
the
shiftofthe
without
These
are
shifting.
so
thatacomplete
graphics
two
shift
editing
keyboardtobe
two
shift
keysispressed
the
keytop
scratching
which
during
the
computer
screen
data
causes
section,
language
computer
not
feel
with
main
keyboard.
operators
are
transfers
memory
transferred
the
cursortoblink.
and
the
programs.
keyboard,
totally
the
inaform
locatedonthe
numbersona
quite
often
usedinBASIC,
64-character
give
the
PET
keys,
either
oneofwhich
operational.
simultaneously.
shouldberemoved.
shipping.Toremove
tapesoastoavoid
data
from
the
each
timeanew
to
the
operating
Oneofthem
other
oneiswhen
though
the
organization
outofplace.
computer,
thatisnormal
standard
significant
a
calculator-like
for
numeric
pad.
keyboard
anditis
graphics
set
line
drawing
maybepressedtocause
Lower
Each
scratching
characters
key
has
This
protection
the
film,
carefully
the
BASIC.
no
is
ability.
was
keytops.
There
the
are
be
The
function
(the
throughtothe
the
The
routine
usingalefttoright
being
over,
Until
is
are64printed
same
keys.
obvious:
diplayedinreverse
reverse
shifted
like
keyisoperational
is
operational
reverse
characters
The
restofthe
carriage
key).
function
shiftofthe
keyboardisscanned
from
repeated8times
the
that
struck.
other.
the
CRT
controller.
scan.
keyboard
keyisreleased,noother
The
scan
later
scanned
on
the
keyboard
keyboard
returnorcursor
field-blackonwhite.
onamemory
untilitis
This
terminatedby
conceptofreversaloffunction,
keys,sothat
usinga6520
Each
The
keyboardisorganizedona
across
routine
the
keeps
keyisthen
consistsoffunction
right
and
basis.
the
complementary
PIA,afour
time
the
keyboard.Toimplement
the
final
keyboard
scans
consideredtobe
with64upper
characters.
left.
Reverseonallows
From
timetotime
a
RETURN
pressedorprinted,
up
functions
linetoten
interrupt
valueofthe
are
11
line
occurs
2 x5row
noise
last
acknowledged
the
next
case,orshifted
characters
Someofthe
all
subsequent
the
keyisstruck,
orbypressing
and
down,
are
usually
decoder
from
the
matrix
protection
scanina
key
right
and
combined,
and
the
interrupt
CRT,
the
keyboardisscanned
with
the
andNkey
buffer.
unlessalater
closure.
The
on
functions
characters
the
reverse-off
leftiscarried
with
one
being
matrix
roll
scanned
algorithm
key
does
to
not
Page 20
~
^ ^
2
^k
«
a
iilljl
«
o
$
<Z
s
-1
1
CD
Q.
i
IS
Q.
CO
I
S
<D
(0
3
(C
o
AITT
M
a
12
Page 21
give
classical
in
the
order
The
keyboard
BASIC,
of
for
The
is
All
bit8of
Once
queue.
characters
This
input
to
queue.
characters
that
the
normal
that
row.
shift
pressed,
key
closures
the
the
The
input
stack
determine
The
N
that
is left
checks
functions
keyisa
the
ASCII
hardware
keyboard
canbetransferred
queueisscannedbythe
maybescannedbya
whetherornotitis
keyboard
moved
key
roll
over
but
does
allow
they
are
struck.
scanning
for
the
of
special
software
are
translated
character
translation
queueisloaded
the
last
row,
stop
keytosample
scanning.
multiple
setsaspecial
The
user
key
ciosure
shift
usingaROM-based
whichisthen
is
done,
translated
the
every
to
the
screen.
GET
routine
user
program.
greater
than
queueislocatedat623-632.
down,
andaload
index
pointer
for
legitimate
which
contains
the
input
can
take
advantageofthisbyreading
I/O
andistreated
switch
encoded
timeanew
zero;
whichisusedtochange
look-up
table
into
the
valueistransferred
key
closureissensed
directly
The
decrementedbyone.
user
if it
The
to
allow
program
is,
that
first
character
rejection
the
device,
separately.
screen
of
noise
stop
key.
This
without
If
eitherofthe
for
the
key.
The
representation
intoa10
input
without
can
lookatthe
means
that
thereisdatainthe
maybetaken
and
trappingofthe
allows
the
routine
havingtoperform
the
input
two
the
decodeofthe
shift
keyisencoded
in
the
standard
character
andisunloadedassoon
goingtothe
pointeratlocation
screen.
keys
in
any
character
shift
keys
key.
into
way.
keyboard
as
The
158
keyboard
out;
all
subsequent
Thisisa
new
Both
interruptorwith
Whenever
first
cursor
repeated,
The
keyboard
carriage
the
typed
operating
An
printing
controltoBASIC,
keyboard
shift-run
RETURN"
runisautomatically
dangerous
key
closure
the
GET
the
level
enables
position.
tryingtokeep
second
operating
interesting
level
queue.
return.
system.
andacarriage
system.
outalinetothe
queueisthe
is
encountered,
into
routine,
could
and
keyboard
the
interrupt
screen
the
The
routine
flashes
Meanwhile,
After
trick
for
new
the
keyboard
transferredinthe
storeanew
editor
cursortoflash
the
the
the
carriage
The
returnissent.
the
screen,
line
LOAD/RUN
the
unless
writtenina
machine
value duringatime
input
routine
masked.
routineisoperational,
then
moves
keyboard
cursor
the
first
returnisprinted,
restofthe
more
advanced
forcingacarriage
numbers
sequence
routine
queue.
When
take
careofthat
a
special
and
writes
the
queue
and
translates
level
operating
This
allows
maybeentered
automatically
controlisreturnedtothe
proper
data
from
cursor
one
empty.
character
and
operating
programmeristo
whichisimplementedbythe
order.
system
this
routine
system
for
does
total
return
into
forces
language
that
automatically
the
stores
editingofthe
into
the
memory.
"LOAD,
with
the
interrupt
you
are
scanning
by
two-level
operating
keyboardtoscreen
further
characters
always
automatically
not
see
use
the
the
CARRIAGE
downinmemory.
from
watches
the
characters
line,
PETtowrite
keyboard
Another
keyboard
input
routine,
masked, because
and
changing
only
operating
systemisin
memoryatthe
the
keyboard
the
input
transfers
until
priortohandingitto
its
own
queue
and
exampleofthe
scan
RETURN,
the
load
the
queue.
during
play.
current
The
process
into
stream
the
they
then
program
RUN
followedbythe
for
entire
have
programs.
returning
useofthe
when
CARRIAGE
a
the
The
is
the
a
line
to
been
the
By
a
It
shouldbenoted
bad
effects
can
that
this
keyboard
happentoyour
system.
queueisonly
The
only
known
13
ten
characters
recovery
long
from
andifitisexceeded,
exceeding
this
dramatically
queueisto
power
Page 22
the
system
keyboard
backonand
and
start
youdonot
over.
have
the
When
fooling
interrupt
with
turned
the
queue,
off,
the
remember
operating
thatifthe
systemisgoingtokill
useristypingonthe
you.
SCREEN
Typingonthe
the
until
understood
examples
To
follow
systemisgolingtointerpret
The
countered,
are
In
this
programming
and
does
The
done
the
EDITOR
keyboard,
screen.
you
This
getitright,
functionislikeasimple
while
but
the cursorisactive,
the
PET
withaPETtoillustrate
are
much
these
more
difficulttodescribe
examples,
two
concepts
the?the
second
treatedbyBASICascharacters
hit
make
first
this
line:
conceptisthat
section
carriage
you
mode).
return.Wewill
the
machine
thing
thatwewanttodoishave
with
your
whenwefollowa?bya
are
operating
BASICisexecuting
the
seeinthe
usefulasa
users'
guide.
transfers
lets
you
it.
The
computer
edit
user
are
necessary.
terminal
your
mistakes
should
thantosee.
follow
Oneisthat
sameasPRINT.
",all
that
you
will
wanttohave
computerinwhatisknown
each
instruction
future
super
calculator.
the
machine
that
like
thisisnot
typeasimple
However,wehopebynow
whatistypedonthe
which
discussions
requires
before
you
youtoretypeawhole
enteraline.
on
his
whenwetypea?
characters
printed
as a
printassoonasyou
the
after
the",
onto
the
direct
mode.
way
most
programs
message.
that
you
understand
keyboard
The
own
PET,asmanyofthe
the
until
screen.
(i.e.
rather
typeitinto
You
should
a
little
directly
editorisbest
BASIC
the
operating
next"is
than
the
are
operated.
have
better.Wetype
to
line
en
system
It
already
?"HI
THERE"
You
will
see
that
BASIC
a
keyonthe
next
character,
occurred,
Letustalk
?HI
THEREB.Whatwewere
For
thoseofyou
keys.Inordertoallow
previously
keyboard.
Ifwestrike
overstrike
outHITHERE
The
delete
want
from
keyboard,
and
nothing
theHITHERE
about
struck
of that
keyisthe
where
the
simplest
who
are
youtoimmediately
character.
the
delete
position.Wecan
PET, a blank
fundamental
you
are
key
respondsbyprintingHITHERE.Itshouldbenoted
the
cursor
appeared
touch
once,
and
moved
else
happened
almost
function;
tryingtotype
typists,
This
keyiscalled
you
line,
and
then
that
you
will
now
finish
READY.
editing
retype.
automatically
until
after
immediatelyonthe
is,
immediately
wasHITHERE
may
correct
the
see
that
typing
tool
which
Thisisthe
one
the
carriage
PET,
have
already
this
mistake,
delete
theBhas
key,
ET;
then
allows
simplest
placetothe
correctingamistake.
disappeared.
hit
youtostrike
right,
return.
screen.
butwehit
made
this
thereisa
locatedinthe
carriage
formofediting.Itis
key
return,
outasmany
that
each
timewestruck
allowingusto
When
the
mistake
Typing
the
carriage
Retype
characterBrather
with
the
which
upper
allowsusto
right-hand
thePresultsinan
causing
the
charactersasyou
implemented
typeinthe
return
the
line
than
P.
PETs
close
erase
a
sideofthe
PETtoprint
by
14
Page 23
decrementing
pointer
striking
one
before
as
is.
character
you
it
does
organized
Because
the
character
deletes
line
There
movesitup
the
above,
are
the
screen
We
can
go
back
the
delete
see
to
so
of
the
40th
however,
three
and
key.
atatime,
it
blink.
overstrike
that
deleting
fact
that
at
the
beginning
character
thisisa
cursor
movement
down,
Notice
This
one.
and
pointer
and
from
and
erase
two
(2)ifyou
where
the
factsasyou
strike
phenomenon
Also,
notice
the
previous
the
characters
of
of
the
pretty
the
third
character
scan
the
line,
previous
slow
keys
on
your
key
you
are
by
one
and
READY
occurs
that
and
line.
wayofediting.
movesithome
that
are
striking;
fast,
the
because
the
PET
in
memory
from
right
then
striking
Just
keying
PET.
One
is
right
(1)ifyou
cursor
will
it
takes
wraps
moves
to
left
the
back
key
moves
(upper
striking
in
front
actually
15
around
in
40-column
delete
40
the
left-hand
a blank
of
our
cursor
strike
slowly,
move
times
as
the
screen.
the
pointer
chunks,
keyatthe
strokes
erases
cursor
corner)
over
where
by
just
the
cursor
several
long
The
back
right
and
characters
to
blink2characters
screen
over
for
example
beginning
the
READY
or
left;
the
clears
the
screen
continuously
will
move
memory
that
character.
is
deleting
of
the
line,
from
the
second
the
key
screen.
CURSOR
The
see
The
type
we
strike
moves
time.
achieved by
CURSORUPAND
The
same
positions
To cause
getsusbacktoour
Cursor
characters
SCREEN
We
can
PET
all
the
now
substituting
RIGHT
cursor
that
it
moves
cursor
that
four
it
the
Obviously,
cursor
visual
with
the
up
moves
EDITING
now
message.
characters
see
the
AND
right
key
us
left
key
times,
two
more
cursor
pointer
by doing
useofthe
DOWN
down
moves
effectasmovingitdown
the
cursor
cursor
the
lessinscreen
use
the
Once
to
deleteisactually
a
blank.
LEFT
moves
five
is
on
you
times,
the
columns
the
same
will
see
it
moves
one
character
this,
cursorupand
the
pointer
right.
to
move
up,
original
screen
cursor
you
the
position.
memory
memory
movement
are
there,
rightofthe
a
pointer
we
The
hold
matterofmoving
one
character
over.
It
accomplishes
key
as
the
cursor
that
now
we
are
us
around
less
are
able
down
40
columns
one
cursor
down
pointer
than
the
the
in
memory.
to
edit
keys.
to
lineonthe
is
now
the
shift
"up"
current
characters
you
can
now
delete
character
being
on
to
all
to
the
right.
If
this
by
changing
right
and
is
evoked
back
one
character
corner
the
the
40
of
the
previous
Going
screen.
right
screen.
the
same
key
while
characters
position.
get
up
theTby
deleted
the
characters
to
the
However,
from
its
Foranexample,
position
striking
from
in
position
striking
are
movedtothe
we
strike
by
to
left,
current
on
the
its
on
the
in
memory
it
now
the
cursor
shifting
the
right
line.
Cursor
it
moves
faster
editing
position.
try
the
screen,
cursor
up/down
current
the
secondHin
delete
key.
left
one
left
five
times,
pointer
prior
to
of
where
left,
of
one
character
can
This
spacing
but
down
position,
the
You
will
character.
one,
rather
you
in
memory.
striking.
we
If
started.
course,
at
often
be
gives
it
the
over
forty
one
line.
key once;
or
notice
this
rather,
HI
THERE
that
You
than
just
will
we
If
just
a
40
will
INSERT/DELETE
Before
any
concerned
starting
the
replaced
The
analyzing
single
left,
last
line
from
replacing
character.
character
may
with
the
the
insert
position
consistof40or80
characters
the
in
and
delete,weshouldbereminded
characters.
onaline.
of
the
cursor,tothe
character
the
lineisautomatically
preceding
Whenever
endofthe
the
blanked.
that
(See
sectiononscreen
the
delete
line,
cursor.
The
Insertisthe
15
the
screen
keyisstruck,
are
automatically
cursoristhen
reverseofthis
memoryisorganized
memory.)
movedtothe
Insert
allofthe
shifted
characters,
process.
such
that
and
delete
one
character
positionofthe
Ifwewant
are
to
to
Page 24
fix
the
line
thatwejust
HERE.Inordertodo
the
shifted
which
than
one
right,
charactersonthe
positioned
in
the
noted
the
screen.
complete.
insert
key
saysHITHERE
character,
and
the
cursor
line.
over
theH,then
lineisautomatically
thatinno
time
Thisisbecausewehave
got
through
taking
theTout
of,weneedtoputaT
that,wehavetomakeaspaceinwhichtotype
withasingle
PET,
with
strike
the
pointstothe
For
example,ifwe
delete
handled
has
the
stroke.
the cursor
insert
key
more
first
characterofthe
ailofthe
andweendupwithaperfectly
computer
respondedtothese
not
yet
After
strikingT,you
blinking
hit
extra
pressed
over
than
once;
the
insert
Ts;wewill
carriage
will
the
first
characterofthe
this
moves
insert.
key
This
three
times,
then
see
commands,
returntotell
back
between
theT.To
note
accomplish
that
this
now
insert.Toinsert
all
the
charactersonthe
then
allowsusto
type
T's
until
that
the
back and
recomposed
other
message.Itshould
than
makingachange
the
PET
the
blank
and
this,westrike
createsascreen
more
linetothe
insert
that
several
the
cursor
forth
movement
the
line
is
is
the
be
on
Thatiswhywehave
and
the
screen
the
usertocompose
data,
whetheritbe
corrections.
What
You
LINESONA
Physically,
computer
data
canbeput
characters
allowing
Itisbest
SeeIsWhat
PET
a
lineonthe
business,
per
the
screentodefine
beginningofthe
COMETOTHE
next
line.
You
right
aboveisonly
The
thing
that
beginningofthe
continuation
uporcursor
PETtotheir
kept
whichisthe
positionisthen
Whenever
second
memory
line.
down
proper
scrolling
lineismaintained
locations
been
memory,
BASICorthe
SCREEN
many
into80columns
line,
the
line
AIDOFTHE
will
soon
consideredtobe a
allows
line.
This
occurs,
line
beginning
keptasa
occurs,
224-248.
talking
without
perfect
symbolized
You
screen
userisgiven
belowHITHERE,
see
the
Each
aboutascreen
interfering
text
and
handitto
user
program,toworry
by:
Get.
consistsof40
data
inputs
are
than
into
all
more
than40charactersasa
and
PARTY,wewill
the
screen
considers
40-column
PETtoaccomplish
line
hasamarker
pointeriskeptinthe
the
editor
number.Atany
pointer
the
until
examines
for
the
pointer
line
pointers
the
line
time
disappearsonthe
editor.
in
any
columnsofinformation.
organized
40.
Therefore,
the
flexibility
start
see
that
All
way
with
the
computer
for80column
ofan80-column
typing
after
thistobean80-column
line.
thisisthat
that
indicates
negative
while
first
telling
are
bit
the
statusofthese
the
complete
the
PET
movedupin
editingisaccomplished
the
restofthe
without
about
the intermediate
data
although
line.Ifwe
the
NOWISTHE
typing
theE,the
internally,
whetheritis
positionofthe
line
cursorison
line
whetheritis
suchaway
screen.
from
which
the
This
operating
the
programmer
stepsofmaking
However,
cards
and,ofcourse,
PET
screen
line.
Thisisaccomplished
move
our
cursor overtothe
TIME
FOR
ALL
spaceisautomatically
line
although
thereisa
index
tableofpointersatthe
the
beginningofa
pointer.
pointersinordertoinitialize
screen,
the
greaterorless
that
line
thereisa
cursor
the
conceptofthe
pointer
between
system.
traditionally
can
the
keyboard
This
allows
whoisusing
much
display
in
the
more
only
the
40
by
GOOD
theHITHERE
MEN
on
line
or a
TO
the
PET
Wheneveracursor
the
separate
operates.
than40characters.
tableislocated
The
screen
first
value
line
in
Now
thatweunderstand
insertatthe
the
cursorupand
(it
shouldbenoted
return,
beginning.Toprint
the
PET
prints
that
left,
until
that
this
NOWISTHE
the
PET
this
the
cursor
causes
the
TIMEontwo
can
allow80columns,
line,wehavetoputa?"atthe
blinksontheNof
charactersonthe
consecutive
16
letussee
NOW.Ifwe
linetoall
lines,
what
happens
beginningofthe
insert
twice,wecan
movetothe
spacesaline
right).Ifwe
and
whenwedo
characters.Wemove
then
now
types
READY.Ifwe
the
typea?"
carriage
Page 25
goupand
the
carriage
even
basic
is
transferred,
apparentasyou
SCROLLING
Now
whenwetrytomove
baseofthe
we
attempttoprint
the
entire
Lines
screen.
istobe
the
screen
lineistobemoved
at
the
screenasit
printing,
makeachangeinthe
returninthe
though
ruleisthat
the
cursorisblinkingontheP,a
whenacarriage
line.Ifwe
whetheritbea40-or
useitwhen
writing
thatwehaveamixtureof40-and
the
cursor
screen.
screenupone
moveupon
Thisisaccomplished
scrolled
memory,
bottomofmemory.
was
the
cursorismoved
Hitting
past
the
the
screenbya
off
the
top,
and
the
off
the
when
you
the
next
thousandth
line.
in
the
bottom80characters
top,
the
The
cursorispositioned
triedtomove
automatically
middleofthe
spaceupto
returnisstruck,
80-column
programs.
80-column
off
the
bottom.Todo
cursor
character
one
lineortwo
hardwarebychecking
81st
character
41st
character
line,wecan
the
word
carriage
regardless
line.
Sophistication
linesonthe
this,wejust
down
causes
on
the
line
jump
the
throughtothe
of
memory
is
movedtothe
PARTY
return
the
automatically
the
cursor
to
down;orin
the
left-hand
see
thatitmakesnodifference
the
first
time
thatitisonthe
causes
of
screen;
entire
screen,
depending
top
line
thousanth
are
sideofthe
the
entire
whereitoccursinthe
in
using
linetobe
the
editor
line,
will
letusinvestigate
cursor
down
until
the
screentomoveupone
the
screen
on
pointer
filled
first,
etc.,
in
the
same
the
caseofa
editor
the
statusofthe
plus
character
with
blanks.Ifonlya40-column
automatically
one.Ifan
are
movedtothe
and40characters
position
at
carriage
bottom
line.
the
wherewehit
screen,
reprinted.
the
become
what
cursorisat
line.
top
lineonthe
80-column
are
now
The
entire
line
more
happens
the
Any
time
moves
line
top
of
blanked
bottomofthe
return
and/or
This
processistotally
bottomofthe
a
program
held
down
HOME
AND
Striking
the
screen
the
cursor
screen
The
moves
screen
providedtoallow
on
positions
PET
the
without
the
screen.
screen.
that
causes
while
printingisoccurring,
CLEAR
the
home
key
memory).
blinkinginthe
and
basically
screen
moves
data
having
movement
This
automatic
Thereisno
scrolling,
moves
Holding
upper
again
data
intoaprogram.
any
effectonthe
allows
the
andiscausedbyattempting
other
the
the
cursortothe
the
shift
left-hand
homing
from
the
around
entire
program
scrolling
the
control
speedonthe
scrolling
willbeslowerbya
upper
key
down
and
pressing
corner.
the
cursor.
keyboardtothe
This
program
the
screen
screentoactasan
Thisisaccomplished
Clearorhome
allows
the
thatisgoingtoreceive
andtoinsertordelete,aswellastype
to
print
over
the
movement.Aswe
PETistoo
left-hand
screen
user
cornerofthe
the
clear
canbegivenatany
and
then
the
flexibility
editing
place
carriage
fasttoread.Ifthe
factorof20.
key
by
moving
whenacarriage
of
the
for
returnorspace
will
see
screen
gives
makingacorrectiononthe
corrected
user-controlled
(the
first
youablank screen
blanks
into
placeonthe
returnisstruck
version.
over
off
the
whenwewrite
reverse
key
is
location of
with
all
thousand
screen.
Keys
are
any
character
input.
17
Page 26
NOTES
18
Page 27
Chapter
The
creative
figure
all
problems.
use
THE
A
computer
We
4.
combination
process.
out
instruction
the
PET
canbe-
This
book
the
PETasan
PRINT
will
STATEMENT
can
calculate
begin
our
of
instructions
Someone
sequences
except
whenitis
cannot
instrument.
numbers
discussion
to
solveaparticular
who
knows
to
allow
teach
youtosolve
all
of
BASIC
provided
day
BEGINNING
howtouse
solution
but
with
the
of
with
pre-programmed
your
particular
it
is
of
no
the
PRINT
BASIC
problem
computer
his
cannotbetaughtina
uses
problem.
All
problem.
value
unless
statement
for
text
his
intuition
that
we
softrware
It
can,
the
computations
that
reason.
or
careful
can
cover
-isa
tooltouse
however,
can
book.Itis
planning
in
this
book
for
teach
you
be
displayed.
a
to
and
solving
how
to
When
isaninstruction
this
isaninstruction
Itisusefultonote
it
which
contained
as
Unless
directedtothe
screen,
the
is
computer
characteronthe
typing
caseawordofgreeting.Onthe
writealine,
will
you
physical
accomplished
text,
to
to
print
print
the
in
the
next
can
write
down.
the
computer
built-in
under
the
PRINT
that
controlofBASIC
canbeabbreviated
the
computer
print
the
BASIC
'A1
andona
square
of 1024,afew
section.
has
been
screen.
representation
by
the
screen
automatically
screen.
scrolls
as?.A
PRINT
telling
productof1024
allows
second
ittodisplayonthe
other
hand:
PRINT
multiplied
youtoprint
line
print
PRINT
1024t2,1024f3
spaces,
The
point
hereisthat
instructed
The
characters
andaneditor
on
the
screenis25
automatically
the
otherwise
are
linesby40
folding
screenuponeortwo
statement
"HELLO"
1024
*8
*8.
more
than
'B',itis
and
then
you can
by
meansofCMD
printedinthe
whichiskeeping
suchasthis:
screen
one
possibletowrite
the
all
characters
valueata
cube
of 1024. Details
printasmany
next
trackofthe
characters,
over
the
41st
character
full
lines
whenitreaches
between
given
time.
Rather
the
line:
of
the
values
command,
available
the
printing
acrossaseriesoflines
all
print
print
positiononthe
screen
position.
ofupto80characters
onto
the
the
the
quotes-in
than having
exact
format
outputs
Although
next
line.
one-thousandth
is
are
The
The
command
character
print
variable.
position
automatically
characters,
return
extra
than
BASIC
no
If
the
notation.
the
and
afterB,a;(semicolon)
spaces,
seven
obeys
leadingortrailing
numberisless
number
PRINT
which
For
allows
If
the
dataispresentedinthis
followedbya
tabulates
prints
characters,
falls
'B'
followedbya
variable
the
following
characters
than
example,
between
has
two
major
for
printing
carriage
printing
is
'B'is
printed.
'B'
willbeprinted
roles
.01orgreater
.0034isprintedas3.4
these
forms
the
field
return.
'A'
startingatthe
carriage
used.
PRINT
The
cursorisleftatthe
after
for
printing
sent.Ifthe
thanorequalto999999999.2,
values,
the
under
(2)
the
controlofBASIC.
specified
form,
Data
return.Inordertocause
A;B;
spacing20characters,when
characters.
fieldtobe
E-03
most
after
the
print
the
fieldisprinted
presentedinthe
current
resultsinthe
and-1234567890.5
significant
19
screen
'A'
endofthe
When
the
fieldtobe
printedisa
9
digits
(1)
The
statement
startingatthe
form
PRINTA,B,
position
being
number,
are
then
BASICtonot
printed,
'B'
field.Ifthe
using
printedisa
BASIC
BASIC
is
printsitusing
printedas-J.2345678E
printed,
standard
has
spacing
then
PRINT
plusadecimal
print
single
endedinthe
current
then
send
variable
first
screen
BASIC
over
10
the
carriage
followedbyno
Aismore
AfB.
string,
checks
there
scientific
form
are
its
size.
+
09.
If
point
if
Page 28
needed.
a
number
It
shouldbenoted
screen,
the
of
Trailing
(unlessitis
unlike
PET,
which
the
data
most
causes
screen
zeroes
after
the
decimal
printedasa
string).
thatinordertotake
BASICS,
being
the
apparent
the
screentoadvance
covered.
point
are
not
full
advantageofthe
space
between
the
screen
printed.
pointerbyone
BASIC
PET's
fieldsisalwaysaskip
always
abilitytocompose
character;
printsaskip
(cursor
it
character
text
materialonthe
right)
does
not
after
character
resultinany
in
Because
programmer
as
literals
compose
display
We
locatedatmemory
ASCII
is
the
When
characters
characters
screen.
representation
In
which
does
floating
VARIABLES
We
functions
intermediate
implement
of
programmingasa
thenabookonbeginning
Allofour
the
PET
allows
has
full
are
clear
screen,
fieldsofany
ableonthe
previously
PET
discussed
location
code,
concatenated
upper-lower
printing
into
for
The
BASIC,
numbers
are
represented
floating
point
have
already
and
case
to
the
the
screen
the
screen
clear
character
for
blankinallofthe
point
numbers.Infact,
print
routine
seen
then
can
valuesorperforming
programmingatany
valuesatany
discussions
one
variable.
the
inclusionofall
controlofthe
home
length
screen.
how
8000
with
bit.
screen,
the
memory
printer.
moves
are
represented
in
two
converts
that
the
print
time.Afunction
If
algebra,orperhaps
after
this
cursor
screen
cursor,
andinany
the
PET
print
cursor
size startinginany
screen
hexa-decimal.
two
additional
print
subroutine
form.
The
The
home
character
the
printer
1000
charactersonthe
as
5-byte
bytes.Asfarasprinting
BASIC
the
PET
canbeusedasa
the
results.
automatically
floating
However,inmany
operations
positioning
position.
right,
memory
The
left,upand
consistsofa
Characters
bits.
Oneofthese
in
the
operating
various
screen
moves
pointertothe
binary
quantities,
is
concerned,
converts
point
numbers
large
until
something
level,weneedtoestablish
that
can
have
any
valueisdefinedinboth
you
are
not
will
concern
familiar
with
the
oneofthe
themselves
very
with
as
literal
cursor
down.Byuseofthese
oneofthe
characters
control
characters
1,000
thousand
are
represented
bitsisa
system
control
the
characters
printer
in
reverse
automatically
pointertothe
beginningofthe
screen.
exceptinthe
BASIC
prints
integerstofloating
into
printable
calculator
cases,
which
programming
equalsacertain
the
useoffunctions
conceptofa
rudimentary
the
variable
textsonBASIC
useofvariables.
withinastring,
availabletouse
literals,
character
characters
screen
field
positions
of
storage
memoryinsix
and
the
second
translates
are
simply
movement
the
one
can
bit
one
ASCII
beginningofthe
screen,
special
characters.
performs
and
inserts
the
caseofintegers,
integers
the
sameasit
point
and
then
mathematical
the
consistsofdeveloping
value.Inorder
which
can
algebra
through
to
haveavariety
and
in
mathematics;
might
help
you.
In
BASIC,
it
hasnotrailing
different
variable
A
andA$are
from
alphabetic
ends
ARRAYS
Arrays
variables
character.
variable.
contains
AA,
etc.
character.
with%,e.g.A%.
are
the
alphanumeric
numeric
BASIC
fourth
are
definedbytwo
The
CharactersA1isathird
and
string
distinguishes
The
second
typeofvariable
character
characterAis
variable,
data,itis
values
a
character
definedasa
respectively
variablebythe
maybeeither
which
can be
alpha
numerics.Ifthe
consideredtobe
but
all
three
string.Astring
and
are
different
fact
that
the
numericoralphabetic.
definedinBASIC.
20
variableisa
the
variableA.CharactersAAis
are
definedasnumeric
variable
variables.
first
characterisalways
Arrays
numeric
values.Ifthe
now
ends
witha$.
AA$,
likewise,
An
integer
are
differentiated
variable
an
then
a
Thus,
is
different
variable
by
the
Page 29
parentheses
usedinan
A(0,1)
referstothe
A%.
All
for
eachofthe
a
variable.
which
expression.
maybespecified
typesofvariables
follow
first
them.
character
in
the
Parentheses
in
the
second
same
program.
follows,
define
rowofa
Specific
but
first letusaddress
the
particular
two-column
definitions
value
some
withinanarray
array
andisdifferent
and
memory
examplesofhow
allocation
whichisto
fromA,A$
techniques
one
be
and
uses
Equal
mathematical
the
value
Originally
and
To
press
is
used
in
two
function:
right.
Otherwise,
inAwith
BASIC
maybeomitted.
understand
RETURN
when
the
resultant
required
A=2isequivalent
how
variables
after
each
CLR
?A
PET
prints
Now
A=2+2
?A
This
Now
?B
PET
prints
Now
B=2*A
?B
PET
prints
Now
A=2+3
?A
PET
prints5.If
?B
PET
prints8,the
saysB=
0.
type
time
PET
prints
type
0.
replace
the
8.
change
the
2*A,
the
4.
valueofB
valueofAbytyping
you
now
same
valueofB
ways:
If
encountered
the
valuetothe
following
of
the
the
word
leftofthe
a
variable
expression
LET
before
to
operate
command
with
type
valueasbefore.
will
in
BASIC,
you
twice
the
Untilwegiveanew
remain
8.-
in
an
IF-THEN
expressioniscompared
suchasin
to
the
any
LETA=2.The
try
enter.
valueinA,bytyping
type
of
the
expression
right.
variable
the
assignment,
command
following
expression
statement,
CLR
examples
equal
means
and
must
equal
A=2+2,=means
butinPET
sets
all
on
the
LETisoptional
variables
your PET.
forBor
re-execute
the
standardI'
the
value
of
replace
in
PETtozero.
Remember
the
one
the
to
which
r
f
JJ
_
I
|
^
\
I
U
ij
(J
|j
-,
^J
{
^
FLOATING
BASIC
variable
Four
bytes
9
digits
Each
less
thgan
STRING
A
string
character.
POINT
always
variable
assumes
is
assigned
containabinary
precision
is
also
-34
yield
VARIABLES
variable
Thereisa
can
VARIABLES
operation,
space
ofadecimal
specific
in'memory
representation
assigneda1-byte
numbers
containafunction,
or
operates
forastandard
number.
too
setofvariables
Accuracyofmost
exponent
smalltodistinguish
totally,
of
that
whetheritbeanumber,
that
in
floating
floating
precision.
limitedtohavingamaximum
from
allow
extraction
21
point
point
number.
It
givesusthe
calculations
zero.
graphics
and
arithmetic.
capability
is
limitedtothis
packingofdata
Therefore,
of
specifying
representation.
valueof+33.
character,
or
standard
into
each
normal
about
Exponents
ASCII
strings
which
Page 30
willbediscussed
set of
INTEGERS
functions
Aswehave
with
five
bytes;
many
cases,
memory
PET
value
highest
efficiency,
has
implemented
between
bitofthe
later
on.
that
allow
indicated,
one
variables
an
for
particularly
the
minus
32,767toplus
number
The
stringislimitedtothe80characters
the
construction
integer
the
canbeexpressedinmuch
is
simplyawhole
exponent
and
in
the
caseofarrays
conceptofstoring
32,767
containing
the
of
stringsupto
four
for
certain
maybestoredinthe
sign.
of
the
255
characters
number.
the
simpler
which
Floating
mantissa,
numbers.Inordertoallow the
can
point
which
take
givesanaccuracyof9
significant
numbersastwo-byte
formofa
input
buffer.
(see
variables
Thereisa
later
text).
are
storedinBASIC
amountsofmemory,
integer
two-byte
values.
number
specific
digits.
user
most
Any
integer
with
the
In
the
USEOFPROGRAM
Throughout
PETtorespond
it
directly,
mode,wecan
divide
should
keyboard,
super
computer
program
working
commands,
debuggingorin
true
computing
direct
BASIC
Supposewewant
easily
very
simple.
byaline
the
text,
directly
aswetypeitfrom
use
the
the
resultbya
get
the
answerof2
except
calculator
programs.
canbeexecuted
correctly.
whenitisinthe
and
Break
againindirect
the
element,
mode
andaprogramisthat
will
execute
BASICtoprint
accomplish
number.Aline
thisina
Any
statement
AND
DIRECT
until
now,wehave
to
the
PETasa
STATEMENTS
print
statement.
the
keyboard
super
third,wecan
followedbya
processofexecuting
for
teaching
Variables
with
points
mode,
caseofusing
one
allofthe
program
number
with
can be
GOTO
canbeputinprograms
without
the
hastowrite or
several
statements
ourHITHERE
you
wanttobe
maybeany
been
using the
In
this
and
hit
calculator.
askitthe
For
question
READY.
the
PET,
the
assigned
statementstoassess
intermediate
program
case,
carriage
instance,
?(2+8)/5.Ifyou
The
PET
a
direct
and
havingtomodify
PETasa
but
not
super
loadaBASIC
statements
before
very
treatedbyBASICasa
number
calculator,
canbegrouped
asking
message
easilyina
the
from0to
technique
BASICisobeying
return.
Thisisso-called
ifwewant
will
obey
any
BASIC
program.Inadditiontousingitas
modeisquite
values
why
current
your
program.
user
vertically
direct
and
any
statusofvariables
main
in
ordertoget
The
for
control.
as
statement.
program
63,999.
which
the
the
PETtoadd
have
typed
statement
useful
then
small
particular
program.
difference
togetherinlogical
opposedtohorizontally.
Rules
statement
allowedusto
commandweare
direct
two
thatonthe
givenitfrom
for
debugging
sectionsofthe
pieceofcodeisnot
checked
However,
the
computertoactasa
between
order
for
program
mustbepreceded
get
giving
mode.Inthis
numbers
PET,
the
of
with
print
except
execution
for
and
then
We
entry
the
and
you
a
in
can
are
A
good
habittodevelop
1,2,3,
program.
To
to
Whether
tell
etc.,
use
All
you
printHITHERE,
start
with
line10and
30?'T"
40?"H"
50?"E"
60?"R"
70?"E"
you
are
the
PETtotakealookatwhat
when
typinginlinesofa
10,
20,
30.
This
will
give
you
needtorememberisthat
vertically,
typingina
each
lineofour
make
each
lineamultipleof10.
programorgiving
you
have
programisto
space
BASIC
typed
latertoadd
interprets
program
direct
and
22
use
lines
each
will
type
one
commands
act
like
accordingly.
increnments
and
make
line
numberinorder.
letterofthe
RUN,
you
The
of10or
corrections
message,weare
have
gottohit
lines
ten
100.
Instead
in
your
RETURN
through
seventy
of
going
to
Page 31
constitute
The
programisnow
printedinthe
H
T
H
You
will
the
multipleoftenisthatwecan
programbytyping
10?
20?
30?
40?
50?
60?
70?
Now
25?""
Press
run
the
H
a
program
I
E
R
E
note
thatwedo
PRINT
PRINT
PRINT
PRINT
PRINT
PRINT
PRINT
type:
return
I
and
program
which
resident
vertical
format:
not
LIST.
This
"H"
"I"
"T"
"H"
"E"
"R"
"E"
relist
the
now,weget:
tells
the
PETtoprint
in
memory.Toexecute
haveaspace
now
givesusthe
program,
between
insertacorrection
program
andwewill
outHITHERE.
the
program,
type
theIandT.Oneofthe
between
printedasfollows:
see
that
line25is
inserted
RUN.
This
reasonsweuse
lines20and
between
givesustheHITHERE
the
30.
First,
display
lines20and
numbers
30.Ifwe
in
the
T
H
E
R
E
This
example
correctionina program.
Thereisanother
return.
Then
following
down
key,ifyou
inserted
executed.Donot
Whenwenow
would
the
have
The
the
takes
L-hS-T
not
PET
which
received
screen
screen.
programs
startsatthe
demonstrates
waytoget
list
the
program
theIon
the
line
20,
don't
hit
cursor-down
forgettohold
run
the
program,
alwaysbetrue,
clears
suchanice
editor
The
out the
will
allow
list
command
and
prints
first
line
(it
the
useofline
the
same
and
see
that
and
insertacursor
the
insert
key
looks
likeareverse
down
you
see
exceptwehad
field.
Hadweprogrammedahome
result.
Try
programmingahome
numbers
effect.
First
line25has been
down.
first,
the
field
shift
before
this
also
gives
been
cheating
youtotakeaprogram
has
several
the
contentsofthe
numberinmemory
featurestohelp
basic
and
and
the
abilitytoinsert
delete
the
spacebytyping25followedbya
deleted.
Firstbyhitting
cursor
will
move
Q),
the
cursor
striking
insert.
you
the
and
effectofa
using
priortoprinting
5?"HOME",
and
make
changesonanyofthe
you
get
the
program
liststothe
whichisstoredinmemory.
screen
lines
Now
position
the
insert
down
immediately.
will
not
spaceonthe
the
automatic
then
right linestothe
device
the
key,
move
scrolling
a
program,wewould
tryaclear
all
the
numberstomake
carriage
cursoronthe
and
then
But
because
until
instruction
next
line.
space
the
cursor
This
20
capability
5?"CLEAR".
lines
you
display
screentoedit.
The
command
instructions
to
a
you
is
of
not
on
List
the
23
Page 32
end.
The
longer
lists
just
line
numbers
lines
correct
your
from
from
line50to
any
PET
justtosee
programs
20,
LIST
the
beginningofthe
pieceofprogram
featuresoflist
10-50
which
the
endofthe
whichiscurrently
what
theydowith
which
lists
lines10through50included,
program
program.
allow
youtolist
through
Some
line50included,
combinationofthe
onlyasingle
storedinmemory.
our
little
program.
LIST-50
and
LIST
above
Try
eachofthe
line
number
which
50-
which
LIST20which
means
list
lists
allofthe
all
canbeusedtofind
above
commands
the
and
on
BASICisan
commandbytaking
words
whichisthe
Command
Asaprogram
line
number
itisthe
In
the
pre-interpreted
This
allows
is
the
data
PRINT,
BASICiscalledaninterpreter
keyword
a
seriesofsubroutines.
longer
tokensinmemory
codingofdataontapeorin
use
BASIC
When
editor
and
delete
To
deletealine,
listitfirstonthe
same
line
interpretive
the
and
expressions
token
for
words
are
storedinmemory
lineisentered
and
searches
same
line
number,
state
the
interpreter
typedinby
even
thoughittakes
that
needstobe
execution
you
createaBASIC
and
the
return
number
times
and
instructions
BASIC
transfersitto
old
lines.
you
screen
with
language
last
line
relatedtothe
typedtoit
whichitrecognizes.
PRINT),itinterprets
into
RAM
through
then
all
to
the
programmer
memory,
the
entire
the
key
store
five
characterstotype,
because
executedinthe
Thisisa
than
stores
typedinfrom
program
line
editor.
type
the
and
new
trade-off
wouldbetrueofa
themonI/O
memoryisnot
The
main
memory.
line
number
alteritthen
text
and
direct
and
analyzing
Every
this
word
with
bit8ontotell
memory
through
untilitfinds
commandsweare
the
timeitencounters
intoacommand
the
the
lineinmemoryisdeleted
words
commandsinthe
you
screen
are
replaced
with
most
suchasliterals,
the
actual
program
which
executionofthe
line,
resultsinvery
machine
devices
transferable
other
machines.
are
operating
editor
allows
The
BASIC
immediately
typeacarriage
type
carriage
pointerstothe
only
then
language
wheneveraprogramisloaded
to
under
youtochange
line
followedbya
returntore-enter
return.
executing.
line
working
BASIC
thatitisacommand
useofthe
same
the
single
memory-efficient
from
lefttoright
a
key
word
suchasPRINT
which
means
carriage
return,
number,orthe
andanew
lineisinsertedinmemory.
character
token
form.
number
variables,
takes
one
characterinmemory.
instructions
executing
memory-efficient
program.
other
machines.Itis
two
levelsofeditor:
editor
allows
carriage
that
characters
youtoadd
is
donebyanalyzing
keyword
storage
Because
and
generally
the
return.Tomodifyaline,
it.Toreplacealine,
BASIC
executes
looking
for
(or
a
key
?
somethingtoBASIC.
word,orkey word.
BASIC
for
The
only
and
the
under
PET
saved,
screen
withinaline
new
lines
takes
the
just
greater.
the
key word.
data
stored
keywords.
the
the
control
programs
BASIC
the
not
character
and
but
uses
actual
until
the
modify
enter
the
If
of
to
There
are
two
waystoexecuteaBASIC
first
clears
instructionofthe
more
numberofthe
print
direct
course,
LITERALS
In
ourHITHERE
quotes.Inthe
all
the
instructions,
first
THERE
mode,
insteadofHI
operates
must
specify
PET
program
programinorder,
and
instructiontobe
exampleswehave
these
variables
ENDisencountered,orthe
THERE.
the
sameasRUN
the
line
numberofthe
are
called
and
startingatthe
executed.
RUNisexecutedindirect
used
literal
program.
initializes
except
PRINT
strings.
The
firstoftheseisto
the
lowest
stop
keyispressed.
For
example,ifyou
that
noneofthe
first
statementtobe
Dataisalso
24
program
number.
pointers.
mode.AGOTO
variables
with
keptinthe
type
RUN.
Thenitexecutes
Execution
type
executed,
characterstobe
continues
RUN
may
haveasan
RUN30,
our
statement,
are
re-initialized.
e.g.
PETinbinary
GOTO
The
command
each
until
there
are
argument
sample
printed
program
also
executed
The
GOTO,
30.
floating-point
RUN
no
the
will
in
of
in
Page 33
numbers.
we
talk
These
contained
To
allow
the
more
We
Graphics
original
the
printHITHERE.
Any
cursor
you
is
typed
the
control
You
quote
heart.
bracket
dots.
Muchofthe
back
and
characters
withinaset of
the
maximum
ability
have
to
store
sophisticated
already
characters
64
character
lower
characters
combinationofcharacters
movement
are
typingina
until
the
screenina
charactersifthatisappropriate.
can
see
and
Cursor
and
Insertisa
formatsothat
the cursor
see
this
downisa
cursor
data
you
forthashuman
are
specified
quotes.
composition
and
execute
techniques.
discussed
are
storedasan
set
and
on
the
and
the
reverse
literal
wheneveraquotation
time
thataclosing
movement
happen.
"Q"
leftisthe
shifted
"T"
wanttowork
beings.
to
the
of
cursor
withinprogramsisnot
PET
with
screen
control
data,
characters
inasectiononPET
extension
they
are
storedinmemory
keys.Aliteral
within
field.
the
software
characters
Reverse
and
cursorupis
shift
of that
which
looks
canbeusedtodrawaline
the
PET
keyboard
PET
hasaspecial
markistyped.
quotation
field
character
markisentered,
which
flagged
looks
likean"R".
the
likeasecond
literal
strings.
the
PET
hasaspecial
which
keyboard
to
this
input
set.
Graphics
withaspecial
maybetypedinasaliteral
modeinthe
From
transfers
shifted
and
the
with
reverse
Homeisan
"Q"orhole
looks
likeavertical
vertical
numeric
More
specifically
are fedtoitbymeansofliterals
how
the
are
indicator
justaseasilyasit
screen
the
all
characters
input
linetoBASIC
field
character.
line.
but
alphanumeric
a
literal
setofgraphics
PET
stores
its
datainASCII.
producedbyshifting
to
differentiate
-the
is
any
characters
from
them
canbeused
and
this
includes
editor
time
that
withinaliteral.
"S"
and
line
which
the
are
transferred
will
clearisa
Cursor
through
assumes
first
quotation
transfer
Typeasingle
shifted
rightisa
the
5th
directly
column
way
value
and
or
other
the
from
that
mark
them
"S"
right
to
all
to
as
or
of
You
cannot
character
between
Deleteisthe
been
typedona
oracarriage
You
should
of
tryingtomove
return,
Another
function.
trytodoacursor
modeiseasytoget
you
struck
Examples
The
abilitytoreadily
depthofgraphical
recommend
with
the
enteracharacterinreverse
before
quotes
then
methodofinserting
It
may
useofimbedded
your
characterisprinted.
are
those
only
editing
line,
you
returnistyped.
noteatleast
the
cursor
cursorupto
has
the
same
movement,
outofbecause
the
insert
that
function.Itis
alsobesuggestedtoyouasyou
manipulate
capability
you
develop
which
character
lose
one
edit
effectasan
graphics
are
interpretedascontrol
that
the
abilitytomove
time
while
afteraquote
your
mistake.
cursor
the
you
control
opening
control
you
suggested
the
graphics
have
the
your
own
and
field
intoaliteral
The
only
will
still
work
the
you
are
editing
has
been
characters
quote.
characters
need
only
that
makeafew
and
time
and
programming
cursor
movement
but
characters
withinaliteral.
cursor
that
typed.
into
For
willbeflagged
enterasmany
you
makeupyour
the
cursor
patiencetoprogram.
skills
you can
characters.
about
you
Either
already
example,ifyou
editing
with
characters.
turnonreverse
that
are
allowedtoappearinreverse
Onceanodd
the
screen
have
fallen
typeaphoney
existing
type
with
reverse
new
charactersasthe
own
mistakes.
movement
the
characters
The
text
and
Remember
field
with
the
control
numberofquotes
until
eitheraclosing
into
the
aforementioned
closing
textisto
insert
examplestoplay with
computer
contionually
quoteora
use
the
three
times
field
justasbefore.
numberoftimes
can
allow
shouldbefun.
experiment
that
you
cannot
quote
carriage
insert
and
this.
whatever
hurt
field
has
trap
then
This
We
the
25
Page 34
machine-the
stuff.
worst
that
can
happenisthat
you
clear
the
screen
accidently
after
typingina
bunch
of
REVERSE
We
have
line,
carriage
is
typedora
As
describedina
bitonto
spots
effect
useful
as
well.
Hereisan
fieldonand
This
Reverse
subsequently
previously
string.
To
get
inserted.
characters
THEREisnotinreverse
until
screen
is
receivedbythe
characterora
FIELD
showninthe
the
PET
will
return.
carriage
Reverse
examplesofquote
continue
field
returnisentered.
previous
indicate
the
black
willbeblack.Asyou
and
doubles
thatitis
the
not
numberofpotential
only
implementedonthe
exampleofhow
type
givesusa
field
THERE
lineinwhichwehave
remainsonfrom
typedonthe
mentioned.
the
PETtotype
TYPE
?"HI
This
outinreverse
(reverse
occupyaspaceonthe
field
the
literalisinterpreted.
memory,ascreen
positionisnot
program
carriage
returnistyped.
mode
with
that
function
worksinthe
sectiononscreen
spotsinthe
will
see
when
untilitis
same
way.ttremainsineffect
memory,
characters
you
typeanexample,
characters
PET
reverse
.Finally
screen
applies
field
the
works:
type
reverse
highlighted
first
time
Clear
the
willbeprintedinreverse
equallytokeyboard
fieldweusealiteral
field
on)THERE
screen
yet.
The
Since
which
printsiton
effectofthe
the
(reverse
when
programming
reverse
required
the
and
insert
how
onceamode
either
reverse
coming
cancelledbya
field
from
ROM
this
which
display
the
field
off,
THERE.
control
the
PET
butinsomeofthe
screen
(shifted
characteristyped
and
reverse
field
until
inputasweliascharacters
with
the
control
field
off)
PET".
and
that
quoteisto
postpone
fieldisturnedonby
for
reverse
screen.
fieldonor
Reverse
field
has
been
established
new
control
untilareverse
characters
willbeall
givesavery
can
are
stored
white
desirable
display.
PET
hard
typeHI(space).
field
on),
type
and
all
characters
the
modeisterminatedaswe
printed
character
Note
that
the
reverse
they
appearinreverse
the
actionofa
settingabitofeach
off
when
the
streamofcharacters
characterora
field
off
character
withaspecial
and
all
the
highlighting
This
featureisso
copy
printers
Next
hit
(space),
from a
for
reverse-field-on
fieldonand
field,
control
character
character
remainsonuntilareverse
for
a
white
reverse
PET
.
literal
off
but
the
in
field
off
TERMS
The
presentedindecimal
to
representing
precededbya
As
commands,
perform.
A
the
An
in
Plus
AND
OPERATORS
communication
keep
the
two
itindecimal
BASIC
function
operatorisa
evaluatinganexpression.
recieves
functions
canbesomething
keyboard,
sign
(+)
with
BASICiseither
form even
straight,
$--e.g.
you
getaconstantof3.14159265,
character
causes
PET
form.
$0010is
lines,
the
and
operators.
thatisinterpretedbyBASICasan
two
valuestobe
with
numbersorwith
though
will
Later
equalto16.
interpreter
like
The
the
microprocessor
assume
square
following
that
whenwetalk
divides
PRINTisa
rootora
setofoperators
added
alphanumeric
in
the
PET
wheneverweare
about
the
characters
commandtoBASIC
variable,ora
which
canbeusedinan
using
26
talking
hexadecimal
it
sees
special
arithmetic
are
defined
literals.
operatesinbinary
aboutanumber,weare
numbers,
into
several
withaspecific
function.
expression.
for
BASIC:
point
representation
Numbers
they
classes.
function
Whenever
whichistobeperformed
are
always
mode.Inorder
will
always
Such
that
you
with
be
as
PET
typenon
the
results
can
Page 35
being
subtracts
calculated
the
valuetothe
inafloating
point
rightofthe
accumulator.
minus
The
from
the
accuracyislimitedto9
valuetothe
leftofthe
significant
minus
digits.
sign.
Minus
*isthe
/isBASIC'S
the
slash.
t
means
Open
parentheses
starting
Sally5'
Subtraction.
parentheses.
operators
Addition
?2+2
Subtraction
?4-2
Multiplication
?6*2
Division
7
12/2
BASIC
multiply.
divide.
exponentiation.
and
close
parentheses
are
evaluatedasa
from
the
innermost
will
help
you
remember
Expressions
The
following
and
their
precedence.
The
All
the
within
valuetothe
numberstothe
All
the
valuestothe
cause
values
single
setofparentheses.
the
precedenceofoperators
parentheses
setofexamples
rightofthe
rightofthe
leftoft
inside
value.
themtobe
Parentheses
In
orderofprecedence,
are
evaluated
shouldbetriedonyour
multiplyismultiplied
slash
are
divided
are
raisedtopowerofthe
single
expressions.
maybenested
Multiplication
first
starting
from
PETtoshow
by
into
the
and
are
the
memory
first,
the
the valuetothe
expression
All
evaluated
then
innermost
the
left.
to
the
left
valueonthe
expressions
right.
inside
outward,
aid
"My
Dear
Aunt
Division,
Addition,
set
of
operationofthe
of
UseofParenthesis
?4+
8/2
?(4+8)/2
OrderofOperations
?(2+4*(8-4)/2)*3
FUNCTIONS
There
Tl$
valueismeasuredasa
expression
three
the
Tl$
are
three
functions
PET.
The
firstofthese
keyboard
alwaysbeevaluatedasthis
indicated,
beginningofthe
used,italways'
and
character
and
the
valueTlare
every
Tl,
which
byte
binary
the
amountoftime
end.
This
functionisaccurateto1/60ofa
presents
two
and
characters
ofTTto
timeascreen
number
sequence
accepts
which
isTT:
Whenever
the
number.
two
waystocommunicate
24-hour
gives
the
whose
and
datainthe
datainstring
for
are
availableinBASIC
this
characterisusedinan
valueof3.14159265
Example:
refresh
value
thataparticular
occurs,
real-time
valueisstatedinnumbersof60thsofa
then
The
clock.Itis
the
current
the
difference
formofhours,
form
valueoftimeinthe
etc.Itcanbeused
?TT
(1/60thofa
number
operation
second.
with
two
which
with
the
availabletothe
that
has
calculatedbysubtracting
minutes,and
characters
are,atthe
real
second),avalue
BASICiskeeping.
taken,Tlcanbestoredina
computeriskeptina
timeofwriting,
expression,
anywhereinany
time
clock
programmerinits
seconds.
for
hours,
BASIC
within
within
the
This
second,orso
that
variable
When
the
two
characters
24-hour
uniquetothe
translates
expression
it
from
and
the
will
BASIC.Aspreviously
PETisupdated.
binary
numberiskept
expression
formbythe
called
variableatthe
from
for
clock.Ifitisten
This
as a
jiffies.
To
theTlat
Tl$
is
27
Page 36
minutes
clock,
set
past1p.m.inthe
type
the
clock
the
expression
to 2:45
and30secondsinthe
afternoon,
Tl$=
Tl$
with
the
wouldbeprintedas131000.Toset
number
being
typedinquotesin24-hour
afternoon,
type
T!$="144530".
the
valueofthe
time.
real
For
example,
time
to
Asapersonal
some
additional
the
computer
Care
mustbetakeninuseofthe
zeroatmidnight.
waited
screen.
until
This
compensate
value
whenitmight.
Functions
range
anywhere
compute
for
the
function,
simple.IfA
In
this
statement,weare
by
expanding
space
after
forA.In
the
experience,
reading,
zeros the
Oneofthe
the
variableTlis
expression
for
thisisto
are
preprogrammed
from
tt,
the
sineofa
number.
calculates
equals
sineiscomputed,itis
sineofn
the
valueofn,
the
expression:
you
should
go back
real
time
and
clock.
value
authors
greater
never
reached
watch
for
capabilities
whichisa
When
the
resulting
radians,
actually
using
evaluating
multipliedby2
set
the
value
Tl$=tothe
print
it.Aswith
Tl.
Remember
wrotealoopina
thanaconstant
the
computed
when
the
time
mightgothrough
of
BASIC
predefined
BASIC
the
two
function,tosine,
encounters
value,
the
and
uses
expression
A=SIN(n)
functions,
function
A=2*SIN(tt)
and
right
time
all
the other
that
the
program
and
the
valueasTl
variables,
expressionTlautomatically
for
graphics
valueofTl
goes
when
through
midnight,
which
wouldbewritten:
sine
storedinA.
canbetreated
whichisa
the
code
for
the
value
in
n,
and
sine;
BASIC
and
finally
capability
function,
the
command.
would
storing
now
and
after
the
power-on
display
as a
where
the
displayisputonthe
midnight.
and
readjust
single
of
it
evaluates
The
evaluate
the
resultinthe
you
have
sequence
goes
the
program
The
only
the
value.
BASIC
use
Functions
to
the
expression
is
really
this
expression
variable
done
to
back
to
is
way
to
stored
quite
The
trigonometric
expressions
degreestoradians,
calculates
To
compute
Eachofthese
values
The
radians.
onlytotentothe
BASIC.
Answers
resultisin
To
convert
Sinof90
shouldbeless
accuracyofBASIC
Expressions
The
function
are
radians.
the
functions,
for
SIN,
COS,
multiply
degrees.Toobtain
the
tangentof40
functions
than 1000
which
ninth.
arc
always
given
numbertodegrees
sine,
cosine,
TAN
all
haveastheir
the
numberofdegreesbytt/180.
degrees.
are
computedbytables.
degreesor6n.
functionsisfive
use
the
Arc
tangentisthe
tangent
computes
between
plusorminus
use
tangent
the
cosineof45
PRINT
For
partsintentothe
valuesinradians
only
the
the
following
and
arc
tangent
only
argumentanangle
For
?SIN(90*tt/180)
degrees:
COS
(45*tt/180)
example:
?TAN
(4O*tt/7SO;
Becausenis
areafunctionofthe
inverse
valueinradiansofthe
?ATN(.5)
?180/n*ATN(.5)
trigonometric
17.
The
example:
limitedto9
tenthaslongasthe
accuracyis5
are
all
availableinPET
giveninradians.Toconvert
example:
significant
valueofn
function
expression
specified
partsin1010.Innormal
digits,ingeneral,
argumentisbelow
whichisaccurate
as a
givenonthe
BASIC.
The
from
20
function
argument.
use
in
the
28
Page 37
The
following
functionofarc
Both
the
expression
division
checked
valueofone.
general
tangent.
above
by
for
expressions
by
180/*.
zero
which
zero
and
expressions
ARC
give
(It
shouldbenoted
will
resultina
before
using
canbeusedtocompute
ARC
SIN
COS
(X).»-ATN(X/SQR(-X*X
the
results
basic
the
expression
the valueofarc
(X)=ATN(X/SQR(-X*X
+1)
in
radianstobe
thatinboth
error.
the
Before
arc
converted
expressions
using
the
sine,Xshouldbechecked
sine
and
arc
cosineasa
+
1)
+1.5708
to
degreesbymultiplying
thereisa
expression,
possibility
the
foritbeing
of
arc
cosine
performing
equaltothe
the
total
a
should
be
MATHEMATICAL
The
largest
?overflow
smaller
number
ABS
Absolute
positive
INT
This
For
Other
additional
the
number
argument
SGN
This
-1ifthe
error.
will
valueisspecified
number.
expression
than
the
inaccuracy.
foraninteger,
expression
signisnegative.
FUNCTIONS
legal
number
The
resultinan
Thereisno
basically
inherent
four
might,infact,bestoredinBASICas3.99999999.
returns
that
BASIC
smallest
underflow.
magnitude
in
the
inherent
rounds
inaccuracy
However,
the
result
a1if
the
For
example:
can
form
the
current
of
small
is 3,
signofthe
handleis±1.70141183
that
canbedistinguished
ABS(X).
accuracy
dropping
inaccuracies
not
The
function
loss.
For
PRINT
ABS(-145).
valueofthe
INT(.23)=0
INT(-2.5)=-3
INT(1.79)=1
significant
in
the
4.
numberisgreater
?SGN(-45)
-1
?SGN(+10)
1
returns
example:
parametertothe
digits,
argument
than
E+
38.
Any
larger
from0is
the
valueofthe
this
expression
could
cause
When
this
2.93873588
next
lowest
introduces
problems.
numberisusedinthe
zero,azeroifthe
number
expression
gives
an
E-39.
integer.
Any
as
no
For
example,
valueiszero,
and
a
a
SQR
This
function
resultisan
entire
The
following
is
2.71828183.
EXPONENT
The
parameter
7ILLEGAL
range.
calculates
the
square
QUANTITY
two
functions
defines
send
the
powertowhich
rootofany
ERROR.
themselves
number
Accuracyofthe
with
natural
the
baseEis
29
greater
raised.
than
zero.Ifa
expression
algorithms.
The
is5partsin10tothe
The
limitofthe
minus
numberisused,
tenth
algorithms
parameter
are
baseEwhich
is
88.02969189.
the
for
the
Page 38
A
number
only
Basic
To
calculate
RANDOM
The
provided.
argument
number
from
numberisobtainablebyusing
are
RND(O)isconnected
the
accesstothe from
the
theoretically
for
The
number
predictable
discussed,itis
number
Another
purposes,itis
Supposeina
random
Subsequently,
PEEK,
PEEKisa
contains
number
than
company
greater
allows
logrithmic
random
The
canbeeither
sequence
power-on.
countingsofast
than
that
the
flow
function
functionisgiven
the
LOGtobase
functions
random
are
number
positive,
generatedbya numerical
However,
relativetothe
with
questioninBlack
random
the
time
that
first
one.Asolutiontothisisto
pure
game
play.
RNDofa
minus
generation
repeatable
generator.
techniqueisto
notasdesirableasthe
game
number
you can
POKE:
function
the
memory
between0and
hexadecimal
who
wrote
Jack,DOYOU
functionina
the
programisinitialized.
random
numberisnot
sequence.
also
the
wayinwhich
take
program
generator
compute
which
addressindecimalinthe
255.
C000isautomatically
the
will
forE,other
useful
generator
the
seed
a zero
some
number
This
the
you
with
allows
BASICiscurrently
BASIC
resultinan
with
10,
the
for
many
overflow.
functions
the
parameter
expressioniswritten:
LOG(X)/LOG(10)
statistical
A
are
?EXP(1)
programs
usesanalgorithm
zero,ornegative.
Positive
algorithminBASIC.Italways
for
the
random
parameter.
occurrenceofreal
external
event
WANTAHIT?
programisnot
use
the
RND
for
statistical
truly
randomatall.
technique
canbeobtainedbyRND
the
RNDofzero
RNDoftime
useofRND
wanttosimulate
the
instruction
the
valueofthe
canbeinitialized
The
basic
time
suchasprogram
Eitherofthese
random
Soina
fixed
(0)togenerateatruly
canbeusedindebugging
whichisalsoarandom
zero.
rollingasix-headed
D=RND(-TI)
die
D=INT(6*RND(1)
the
usertolookatany
PET
constructedsothat
returnedaszero.
softwaretoprotect
their
formofthe
expression
is
EXP(X).
availablebyratioingtothe
LOG(X)
events,
program
and
The
whichisloggedtobase
and
games.
which
developsavalue
numbers
Three
always
return
starts
by
using
the
program
reads
four
unrelated
thatatrue
initialization,
random
or
givesatruly
because
the
relationship
sequence,
definitely
parameterispassedasa
the
random
seed,
givesanadequate
basic
between
the
with
minus
numberisobtainedifthe
strikingakeyinresponse
random
of
only
use
programsina
minus
canbepassedasthe
with
locationinthe
whichtowanttolookatthe
copyright.
for
+
1)
Thisisa
program
number,
die.
the
legal
development.Aspreviously
parametertothe
although
Initially,
PET
memory.
contentsofany
constraint,
Although
the
PET
Log:
E.
random
next valueofa
the
value.Atruly
interval
the
truly
the
seedtothe
you
resultisa
functions
zero
and
are
one.
The
random
same
value,orseed
random
timers
which
number.
Repetitive
timeispredictable
random
number
RND(-AND(0)
random
sense
for
can
The
address
posedbythe
random
that
a
random
gaming
seed
the
parameter
decimal
greater
to
is
to
Example:Tolookatmemory
POKE
POKEisnotafunction
read/write
memory
the
actual
characterAat
Some
system
memory.
addressofwheretoput
valuetobe
the
locationsinmemory
variable
RAMorI/O).Ifyou
butiswritten
The
parameters
deposited.Itmustbebetween0and
first
locationofthe
cannotbechanged
location
25,
likeacommand.Itallows
are specifiedina
the
information.
screen
POKE
the
expressioniswritten:
?PEEK(25)
the
list
after
the
It
may
range
from0to
255.
For
memorywewould
POKE
the
32768,1
(ROM)
latter,bepreparedtoreset
30
and
others
write
should
usertodepositanumber
command.
example,ifwe
The
first
parameteristhe
65536.
The
second
wantedtoput
notbechanged
your
machine.
parameter
(BASIC
into
I/O
and
or
is
the
Page 39
USR
The
USRisa
address
programming
FRE
This
function
usedinan
FRE
forcesaBASIC
blocksothat
function
locatedatmemory
foradetailed
tells
expression,
they
whichisdesignedtopassaparametertoa
location
description
you
how
many
itisnormally
action
canbeefficiently
called
one
and
twointhe
and
useofthis
bytes
are
left in
usedindirect
garbage
collection.
allocated.
function.
memory.
modeinthe
?FRE(0)
This
language
PET.
See
the
Althoughitisatrue
form:
consolidates
program
sectiononmachine
all
unused
using
the
jump
language
function
sinceitcan
bytes
into
one
u
LI
be
large
Several
TAB
This
through
ignored.
POS
This
Note:
SPC
This
Legal
functions
format
function
format
function
the
INT
Note:
HOME
function
range
existtoaidinformatting
places
routine.
TAB
uses
returns
and
is
(KX<255.
the
CLEARdonot
prints
the
cursoratthe
The
legal
rangeis(KX<255.Ifthe
skip
characters,
positionofthe
affect
out the
Note:
numberofskips
SPC(O)
put
data
whenitis
column
not
spaces.
cursor.
POS
The
even
256
skips.
NOTES
printedonthe
specified
positionisresettozeroateach
though
the
specifiedinthe
in
the
cursorispast
cursorissettothe
argument
screenorhardcopy
argument.
the
location
(which
printer.
The
argument
specified,
carriage
first
column.
goes
the
return.
through
goes
tab
INT).
is
II
31
LJ
Page 40
Chapter
S.
ELEMENTARY
PROGRAMMING
Useofdecision
A
major
maybedoneintwo
advanceinBASIC
GOTOiswrittentospecifyatarget
written
IF-THEN
withaspace
has
logicinwriting
programmingisthe
ways-unconditionally
betweenGOand
three
forms:
programs.
line
IF
IF
IF
Conditions
provides
Until
familiar
ascending
Ifwewantedtotake
screen,wecould
are
writtenastwo
six
relational
nowwehave
with
the
concept
order.
write
10
20
30
operators:
been
developing
that
and
print
the
linear
PRINT
PRINT
PRINT
1,1,1
2,2*2,
3,3*3,
arithmetic
<,>,=,<>,<=,>=.
programs
says
that
numbers
programasbefore:
abilitytoloop
withaGOTO
number
TO.
(condition)
(condition)
(condition)
expressions
PET
where
BASIC
GO
TO
GOTO
THEN
GOTO
THEN
50
100
separatedbya
whichdosingle
first
line10is
executed,
betwenn1and
SQR(2)
SQR(3)
back
and
and
conditionally
execution
will
(statement)
(line
(line
will
always
recognize
both
number)
number)
functionsinserial
then
20,
their
square
re-execute
withanIF-THEN.
forms.
relational
lines
branch.
GOTO
operator.
order.
line
20,
and
other
and
square
root
of a
program.
may
also
be
PET
BASIC
You
should
line
numbers
be
valuesonthe
It
in
The
big
disadvantageofthisisthatwewould
UNCONDITIONAL
However,
computes
The
Line10printsaheading
Line20computes
never
Line30is
variable.
Line40containsaGOTO
BASIC
interpreter
executiontothat
with
values
program
been
referencedsoit
like
stores
can
LOOPING
our
conceptsofvariables
and
prints
readsasfollows:
for
the
next
lines
10-200ofthe
text
linessothatapointertothe next
quickly
examine
line.
200
PRINT
and
them
out
without
10
PRINT
the
numbertouse.
hasaninitial
command
"VALUE'V'SQUARE",
columnofnumbers.Itis
The
valueof0.
30
PRINT
previous
which
only
the
line
program
directs
havetokeep
20,20*20,
the
additionofa
havingtotype
201=1+1
first
l,l*l,
except
40
GOTO
execution
numbers,
SQR(20)
executed
time
this
SQR(I)
that
20
line
precedes
determineifa
typinginlines
loop,wecan
suchalong
SQUARE
only
lineisexecuted,Ihas
the
constants
backtostart
each
until
writeaprogram
program.
ROOT'
once.
againatline
line.
line
does
have
Using
the
20th
"
been
20.
this
exist,
and
line.
that
replacedbya
technique,
transfer
the
GOTOisnot
limitedtobranchingtoa
lesser
line
number
32
butitcan
branchtoa
greater
number
too.
You
Page 41
will
seeafuture
As
before,wetype
keyispressed.
useofthe
factorof20.
To
stop
the
programtoresume
While
this
address-printing
small
mistake
and
then
execute,
with
the
computed
programming.
editortocorrect
exampleofthe
RUNtostart
Rapid
scrolling
reverse
loop,
program
key
slows
press
the
whereitleft
makes
just20numbersonthe
into
the
program.
insteadofprinting
value.
Luckilyitis
line40togoto
conceptofusing
our
program.
of
the
screen
the
scrolling
STOP
key.
When
offorRUNtobeginatthe
useofthe
Jumpingtothe
most
GOTO,itdoes
You
should
a
headingatthe
wrong
visibleinthis
line
20.
You
GOTOtoskipaportionofcode.
The
program
memory
rate.
Holding
you
wanttorestart
screen.
However,
seeacommon
40
GOTO
will
makes
down
beginning.
not
really
10
beforeweaddress
error
topofour
placeinthe
programisthe
case.Bystopping
have
now
fixed
continue
the
the
a
helpusto
to
print
screen
reverse
program
almost
key
either
solve
and
its
cure.Ifwe
slows
program.Wewill
most
the
programwecan
the
firstina
long
valuesofI
impossible
type
the
that,
until
the
to
read,
the
scrolling
CONTtocause
problemwetried
letusintroduce
retype:
intersperse
common
lifeofprogram
error
use
the
the
heading
made
screen
bugs.
STOP
but
by
a
the
to
a
in
CONDITIONAL
The
IF-THEN
THENisexecuted.
=
equal
<>
not
>
greater
<
less
> =
greater
<=less
If
A<B
then
If
the
expression
expression
what
they
In
ourexample,wecan
The
IF-THEN
to
limit
the
then
finally
We
can
also
restore
line
LOOPING
statement
equal
than
than
thanorequal
thanorequal
print"ALESS
Is
false,
mean,
remember
allows
A
testisspecified
is
true,
the
program
add
letsusmakeavarietyofdecisions
program
drop
write
40:
and
through
theIFstatementtoskip
youtospecifyacasetotest
by
putting
to
to
THAN
the
cause
the
B"
instructions
jumpstothe
that
the
arrow
the
statement:
40IFl<=20THEN
actionstohappen.Inthis
instruction.
oneofsix
on
the
same
next
numbered
pointstothe
at
the
timeweare
around
35IFI
40
the
=20
GOTO
50
END
GOTO
andifthe
relational
line
with
line.Ifyou
value
you
GOTO
case,weexecute
unconditional
50
20
caseistrue,
operators
theIFstatement
areindoubt
would
20
executing
liketosee
the
the
GOTO.
the
statement
between two
are
executed.
about<and>and
less
than
program.
program
Add
from1to20and
two
new
after
the
expressions.
If
the
the
other.
This
allows
lines
us
and
The
program
Most
BASIC
vestigeofwhen
to
force
IF-THEN
IF-THEN
will
interpreters
program
instructions
line
number
execute
BASIC
executiontoendata
through20values
required
operated
have
three
where
youtoincludeanEND
non-interactively
forms:
GOTOisimplied.
and
whenIis
from
The
point.
firstisIF
The
third
33
equalto20,goto
statementtofinish
cards.
expression
END
GOTO
formisIF
canbeused
line
expression
the
END
statement.
your
program.
optionally
number.
THEN
in
The
second
followedbya
Thisisa
PET
BASIC
is
Page 42
statementtobe
tabletodrawaline
executed
between
before
proceedingtothe
the
10th
32IFI=10
and
11th
valueonthe
THEN
next
line.
PRINT"
Expressionsinthis
screen.
"
form
might
change
our
Ifwetrytoexecute
screen
IF-THEN
when
theZwould
50.
the
The
to
jump
legitimate
makesaprogram
DATA ENTRY
becauseofthe
are
placing
notbeexecuted,
However,
PRINTXandZ=AwillbeexecutedifX=5.
IF-THEN
limit
the
program
plus
the
computing
Beforeacomputer
The
program
more
complex
waystoget
information
this,
you
will
see
thatalineisnow
statement
only
two;
either
additional
in
programming
at line
the
next
because
IFX=5THEN
lineisexecuted,orthe
statementsonthe
the
letsusmakeavarietyofdecisionsatthe
and
cause
conceptoftesting
element.
really
work.
program
could
require
payroll
program
actionstohappenatvarious
values
The
intelligent
can
perform
only
simple
might
into
variables.
need
drawn
between
32.Itshouldbenoted
line.
IFX=5THEN
line
either
50:Z=A
drops
throughorexecutes
PRINT.X:Z=A
timeweare
points.Itis
that
allows
the
computertobe
combinationoflogical
useful
data
work,ithastobe
suchasYESorNO
rates,
hours,
and
tax
the
tenth
and
eleventh
that
the
logical
THEN
For
statementisexecuted.
example,
executing
the
conditionsoftheIFand
in:
statement
the
program.
conceptofthe
usedasboth
decisions
with
repetitive
abletoaccessadata
responsestoa
information.
gameorsimulation.
In
PET
valueonthe
Take
This
allows
unconditional
control
element
operations
baseofsome
BASIC
there
are
care
us
and
sort.
A
two
READ
Onlyashort
cards
program.
the
When
GET
parameters
The
READ
and30mightbeprocessedbya
and
quotes
String
AND
DATA
STATEMENTS
time
ago
included
program.
BASIC
allowed
syntaxofREADisthe
processes
endoflines
Blanks
and
are
data
with
The
command
began
direct
that
change
DATA
are
graphic
consideredtobe
canbetyped
when
there
the
program.
READ
runninginan
communication
but notasoften
verb
READA,B,C,D
statementsasthey
considered
10
20
30
characters
delimiters
without
50
werenotimeshare
Thus,
was
followedbya
READ
terminators
DATA2,-53,
READ
DATA
are
quotesifit
DATA
DATA
statements
designedtopull
interactive
with
statementatline
A,B
3.14,
automatically
ABC,
environment
the
BASIC
-e.g.
tables,
listofvariables
are
encounteredinthe
IE10
1,06E23
thrown
for
literal
DEF
characters.
does
systems,
were
out
this.
DATA
through
program.
etc.
20.
DATAisprocessed
away
not
contain
BASIC
READ
into
unless
literals.
could
typed
and
into
variables
timeshare,
has
been
which
program.
they
not
accept
scattered
which
verbs
input
other
throughout
couldbeused
suchasINPUT
relegatedtoinputting
the
DATAistoberead.
DATA
statementsatline
sequentially
are
surroundedbyquotes.
and
than
the
by
and
10
commas
The
34
Page 43
Commas
Itisalso
within
possibletotype
quotes
will
notbetreatedbyBASICasfield
60
DATA
mixed
10
DATA
20
READA,A$,
",",","
alphanumeric
123,
ABC,
B
and
345
data
fields.
terminators.
Numeric
fields
maybetreatedasalpha.
Itisadvisable
use
some
program
will
occur.
because
SYNTAX
READ
and
really
not
data
statement
command
Thereisone
RESTORE
The
following
10
DATA
201=
30
READA:PRINT
40I=I+
50IFK8THEN
60
RESTORE
70GOTO
for
the
kindofa
will
index
Sometimes
the
PET
thinks
error
results
DATA
are
partofthe
pointerisdirectedtothis
initiates
other
restart
the
program
10,
20,
1
1
20
programmertoknow
delimeter
its
way
at
through
the
next
you
may
you
already
the
endofthe
allofthe
READisencounteredan?OUTOFDATA
also
see
this
tolditto
whenanattempttoread
implementedinthe
first
line
butisa
a
search
command
DATA
30, 40,
30
foraDATA
available
search
would
correctly
50,
A
60,
following
dummy
statement
to
backtothe
operate
70
how
many
data
data.Ifitisnot
data
statements.
errorifyou
READ
alpha
manner:
line
consisting
byte.
Sinceitis
the
programmer
beginningofmemory.
carriage
Y.
field
intoanumeric
The
pointingtoa
token.
which
continuously
statementshehas
done,
the
dataiscontinuously
Finally,
DATA
ERROR
return
through
willbeexhausted
variableismade.
first
byte
of text
onlyofa
terminator.
terminator,
allows
re-reading
himtoreuse
DATA;
put
Into
the
machine
read,
and
and
READYonthe
containsazero.
When
RUNistyped,
the
first
the
stored
screen
This
READ
data.
or
the
when
is
a
INPUT
When
keyboard
statements
OperationofINPUTisconsiderably
sequence.
editor,
characters
interpretedbyBASIC
Leading
necessarytoenclose
The
interactive
was
The
formofthe
When
BASIC
blinking
After
carriage
blanks
editor
4
picksuponly
responsetoDATA
introduced.
was
limitedbythis
statementisthe
encounters
the
cursor
are
allowedupuntil
returnisreceived,
are
supressed,soif
Since
this
instruction,
for
input.
using
its
input
the
input
the
characters
requirements
the
classical
device.
enhanced
verb
INPUT
it
Because
the
carriage
dataishanded
buffer
you
are
characters
between
became
input
devicetoBASIC
when
followedbya
INPUTA,B,
printsaquestion
you
are
under
returnisissuedasa
backtoBASIC
and
rulesofinterpretation.
inputting
within
quotes.
the
question
35
possible,
coupled
with
variable
C
marktothe
controlofthe
a
string
which
mark
the
the
list.
terminator.
one
characterata
and
conceptofINPUT
wasaTTY,
powerful
INPUT
screen
screen
requires
the
current
the
PET
satisfies
then
activates
editor,
time.
blanksorliterals,
positionofthe
from
the
formatofinput
screen
editor.
the
variables
the
cursor
movement
Dataisthen
it
cursor.
screen
is
in
Page 44
This
allows
inputofdata
fromapre-constructed
formonthe
screen.
INPUT
than
and
On
and
Ifanalphabetic
In
termination
teletype
The
INPUT
andinwhat
it
and
to
data
maybedelimitedbycommasaswith
are
actually
takes
the
other
begin
only
blinking
required,
those
hand,
when
the cursor
BASIC
charactersitrequires
not
responds
enough
againtoget
fieldisencountered
7EXTRA
dataisinputted,
during
7REDO
PET,ifinputisfollowedbyonlyacarriage
of
the
BASIC
stop
keyisnot
when
hasaspecial
form
returnistyped.
would
print:
wait
for
youtoinput
calculate
10
20
30IFA=0ORB=
40?
50
the
INPUT
INPUT
"THIRD
GOTO
"FIRST
"SECOND
10
program,
this
operative
feature
they
third
legofa
IS";
SQR
sameasa
was
the
most
while the
which
are
to be.Aliteral
For
your
LEG";
LEG";B
0THEN
(A*A+B*B)
allows
birthdayinstandard
right
triangle:
A
10
stop
convenient
PET
youtoindicatetothe
which
10
INPUT
the
DATA
with
IGNORED
to satisfy
additional
the
interpretation
return
key.
waits
the
??
input.
FROM
withnoother
This
particular
wayofterminating
for
input.
follows
"BIRTHDAY";
BIRTHDAY?
numeric
statement.
INPUT
BASIC
will
ofanumeric
START
the
input
formtovalueA.Hereisan
When
list.
respond
typing,itis
featureisa
a
user
what
commandisprinted
A
more
fields
with
field,
BASIC
consideredbyBASICtobe
carryover
program.
input
from
characters
priortothe
exampleofINPUT
are
provided
responds
with
the
days
are
desired
time
a:
a
of
the
If
you
run
this
program
We
can
change
and
changeitto:
This
change,
acceptable,
many
fieldsgoonaparticular
to
mix
alpha
GET
A
major
grinding
been
ifakey
The
problem
halt
equipped
has been
commandisGET.
our
when
however,
and
with
while-the
withaspecial
and
programtose
you
execute
good
numeric
INPUTisthatitdoes
user
pressed.
GETisidenticalinsyntaxtoINPUT.Itis
putinvalues3and4respectively,
howtocombine
10
INPUT
it,
programming
line,
values.
10
takes
function
"FIRST
will
accept
practice
althoughitis
INPUT
his
timetoenter
which
"NAME,
not
valuesona
LEG,
SECOND
values
typedas3,4.You
protects
definitely
BIRTHDAY";
allow
real-time
some
will
yield
one
36
you
single
LEG";A,B
the
user
not
good
A$,
programming.
characters
characterata
possibletospecifyalistofvariables
will
geta5.
line.Wedelete
will
see
from
getting
programming
A
All
and
strike
time
line
that
confusedasto
practice,
processing
RETURN.
from
the
20,
list
line
either
form
is
how
itispossible
comestoa
PET
BASIC
has
keyboardortell
but
10,
Page 45
u
generally
single
only
Useofthe
Otherwiseitwill
The
will
that
GET
containsavalueofnullorzero.Ifthere
Since
queueisempty
The
thisisnotagood
key
closure.
numeric
numeric
most
desireable
haveanull
was
pressed.
callsaroutine
the
lengthofqueueis10
following
Whenanumeric
keys
willbeacceptedasinput.
valueisconfusing
haveavalue
value
See
which
when
routine
idea
because
1-9
waytouse
(length=0);
the
waiting
will
wait
GETiswithastring
otherwise
next
section
examines
characters,
foraresponse.
for
value
becauseifno
for
keys
foradetailed
the
keyboard
are
a keytobe pressed
20IFA$=""THEN
In
this
case,
""isaliteral
which
contains
the
purposeofGETisto
is
specified
GET
A
All
others
7SYNTAX
1-9.
the
string
characters,
calling
Thisisparticularly
10
GET
will
cause
ERROR
key
has
been
variable.Ifa
will
contain
explanationofhow
interrupt
GET10timesina
buffer.Ifthe
the
firstistaken
and
exit
A$
only
10
no
characters
and
isanull
scan
the
keyboard
the
message:
struck,
key
the
loopisa
usefulininteractive
the
value
has
not
been
character
with
corresponding
strings
bufferisempty,
outofthe
good
the
valueofa key
and
return
returnediszero.
pressed,
work.
the
queue
waytoinsure
and
games.
string.
with
a
the
string
to
the
key
variable
returned.
that
the
closure:
i
I
^
|J
I
I
'-'
NOTES
u
u
37
u
Page 46
n
Chapter
We
with
maybeexpressedasa
single
PET
Allofthe
6.
have
been
describing
alphanumeric
variable.
BASIC,
hasa$
rules
data.
notation
which
ADVANCED
numeric
BASIC
continuous
functions
hasasetoffunctionstodeal with
connectionofcharacters
whichisusedtoexpress
applytonormal
variables
PROGRAMMING
primarily,
but
almost
variables
applytothe
TECHNIQUES
any
useful
these
data.
whichisviewedbyBASICasthe
which
string
are
variable.
program
Also,
also
hastodeal
all
alphanumeric
stringsofalphanumeric
data
valueofa
data.
n
Following
TypeA$=
stringofa
all
that
inastringis255.
an
I/O
thatisusedis+
We
can
A$
and
formattedbyBASIC,
including
illustrated
BASIC
output
characters
substrings
individual
COMPARISONOFSTRINGS
The
represented
the
leftmost
the
naming
"NOWISTHE
lengthupto
canbeenteredona
device
and
modify
you
the
can
see
those
soon.
allows
device
string
which
conventions,wecan
TIME"
about70characters,
You
can
the
construction
.
expressionA$whichwehave
that
the
the
valueofthe
that
form
expressionsupto
accepts
becauseofthe
before
characters
ASCII
tableisdefinedinFigure
they
are
can
when
two
strings
charactertothe
line.
build
control
sizeofthe
inputorby
thenberecombined
createavariableA$not
and
PRINTA$to
However,
strings
larger
of
dataisaccomplishedbythe
show
the
valueofthe
dependingonthe
the
limitationonthe
than
canbeentered.
been
developingbytypingA$=A$+"FOR
numberofcharactersofthe
numberofcharacters
concatenationofstrings.
literalwetypedinhadaspaceatthe
literalistaken
characters
255
more
than 79
input
using
2.6.Itcontains
are
compared.
endofthe
characters
characters.
buffer.
GETtoinput
field
Nterally.
suchascursor
This
A
string
down,
long.
These
Input,
however,isusually
problem
each
into
the
original
the
orderinwhich
Characters
specified.
withinasetofstrings
canbehandledbybreaking
character
stringbyconcatenation.
equaltoA%
string.
The
accumulationofcharacters
beginning.
can
contain
and
carriage
canbeoutputtothe
and
This
technique
Unlike
numbers
all
combinationsofbits
return.
not
equal
can
line
that
canbestored
The
ALL".
which
This
will
screenorto
restrictedto79
strings
individually.
characters
are
The
substrings
within
compared
the
PET
starting
to A.
define
number
a
-
from
operator
Print
are
be
any
into
or
are
at
Using
the
ASCII
table,wecan
position.
A
string
string
are
Thus
Immediately
check
a
telephone
The
resultisthat
containing
"A"isless
comparedinsequence
the
same
<>for
=
for
<
for
>
for
the
fileora
directory.
a blankisless
than
relational
unequal
equal
less
than
greater
string
telephone
compareastring
the
second
than a
the
string
functions
than
comparison
directory.
"ABC"orany
with
the
first
feature
Comparisons
containingan"A"toone
stringisgreater
"1",
whichisless
string
unequal
maybeused
character
for
canbeappliedtohelp
can
containinga"B"inthe
than
the
first.
thanan"A",
containing
both
"A"asthe
defining
strings
the
and
you
whichisless
first
relationship
numbers.
construct
alsobeusedtosearch
38
character.
between
ordered
ordered
lists
than a
"B".
All
characters
the
strings.
lists
such
suchasa
same
The
as a
file
or
Page 47
Try
the
following
10
INPUT
20
INPUT
30IFA$=B$THEN?"A$=B$"iGOTO
40IFA$
50
PRINT
programtodevelopafeeling
A$
B$
<$B
THEN?"A$
"A$
>B$":
GOTO
<B$":GOTO
10
for
sequences
10
10
and
matching
u
functions:
NUMBERS
Two
complementary
into
character
STR$
AND
ASCII
strings.
CODES
pairs of
STR$isa functionofone
numeric
Positive
corresponding
VAL
VAListhe
the
non-blank
expression:
10X=3.1
20
?STR$
RUN
3.1
READY
(X)
numbers
position.
complementofSTR$.Itconvertsastringtoa
first
characterofthe
?VAL("Z")
0
READY
are
precededbya
operationsonstrings
argument.Itreturnsastring
blankinthe
and
numbers
thatisthe
STR$
equivalent.
number
stringisnot
numeric,
then
the
valueofthe
allowusto
character
Negative
which
numbers
may
be used
functioniszero.
put
unconventional
representation
of
the
things
haveasigninthe
for
computations.If(J
I
|
On
the
other
hand,
VAL
?VAL("3.14AB")
3.14
VALisan
REDO
CHR$
We
INPUT,
example,aPET
withnoline
giving
representation.
In
the
before
excellent
from
START.
have
shown
but
some
feed
the
ASCII
10A$=CHR$(65)+CH
20
PRINT
RUN
AB
READY.
above
examples,65is
concatenating
functiontouse
that
strings
devices
printer
whenitperforms
code
number.
The
valueofthe
A$
them
will
convertasmany
with
maybeassigned
require
uses
R$(66)
control
shifted
the
and
carriage
overprinting.
CHR$isa
argument mustbe0<=X<=255.
ASCII
printing
digitsasit
INPUT
sinceitcan
printable
characters
returnasa
CHR$
functiontoconvertanumber
code
for
"A"
and66isa"B".Weconverted
them
out.
canuptoaninvalid
preventaninexperienced
ASCII
characters
which
cannot
special
allows
youtospecify
terminatortoindicateacarriage
character.
through
be
produced
into
either
by
such
control
internal
the
user
from
causing
literalsordirect
normal
ASCII
codestocharacters
means.
return
characters
a
For
by
I
39
Page 48
ASC
ASC
turnsacharacter
parameterisa
?ASC("A")
65
If
the
string
of
the
string.
?ASC("123")
49
The
ASCII
SEGMENTOFSTRINGS
In
many
casesitis
problem
middle
that
In
ordertobe
whereinresponsetoan
intitial,
the
listbeorderedbylast
functions.
analyze
piecesofa
onceasthey
convenience.
string.
consistsofmultiple
code
for
and
abletoseparate
Mostofyour
are
essentially
intoanASCII
"1"is49.
desirabletoaccess
last
name.Itis
programming
constructed
code
number
characters,
just
INPUT,aperson's
important
name.
partsofstrings
with
strings
string.Wewill
the
same
function.
which
then
this
partofa
nameistyped
that
for
and
use
will
present
Three
maybeusedinnumerical
function
will
return
the
code
calculations.
for
the
stringindevelopinganordered
in.Itmight
sorting,
however,
that
theminexpressions,
consistofusing
the
useofthe
combinations
functions
are
provided
consistoftheir
not
all
Johnsbetogether,
PET
BASIC
oneofthese
three
and
define
mainly
The
first
character
list.
Consider
first
name,
provides
three
functions
all
three
for
programming
the
but
to
at
LEFT$,
The
specified.IfI
is
VARIABLE,I)gives
than
There
expression
lengthofthe
ILLEGAL
the
The
the
returned.
or
Allofthese
of
the
RIGHT$,
function
negative,
and
specifiedasLEFT$(string
or
zero,orgreater
the
255,anILLEGAL
are
two
expressions
gives
"J"
string,
QUANTITY
characters
second
lengthofthe
greater
characters,
string.
from
expressionisMID$(STRING
string.
If
"I"isgreater
than
255,
variables
right
numberofcharacters,
MID$
variable,
than
255,
thenanILLEGAL
rightmost
QUANTITY
characters
then
this
ERRORisprinted.
"I"tothe
All
than
and
ILLEGAL
combined
"I"
characters
ERRORisprinted.
for
MID$.
The
from
the
will
giveanull
endofthe
the
characters
the
lengthofthe
QUANTITY
will
defineanew
first
string
For
"J"
string
VARIABLE,I)whichisthe
oragiven
I)
gives
the
QUANTITY
of
the
string
expression.
most
general
starting
string.Ifeither
greater
are
returned.
startinginthe
string,
ERRORisprinted.
function
oneisMID$(STRING
with
the
"I"or"J"
than
the
"I"
position
thenanull
which
numberofcharacters
leftmost
"I"
charactersofthe
ERRORisprinted.
WhenT'Is
less
RIGHT$(STRING
than
zero,orgreater
VARIABLE,I,J).
"P'th
character.
If
"I"isgreater
negative,orgreater
numberofcharacters
sameasspecifying
until
the
stringisreturned
allowsusto
take
leftinthe
a "J"
endofthe
andif"I"isnegative,
either
the
startingata given
string
This
than
the
than
255,
string,
greater
string
left
than
are
number
position
an
all
of
To
find
the
last
name
characterofthe
function.
LENGTHOFA
The
LEN
STRING
function
from
our
previous
string
until
the
givesanexact
example,wecan
first
blankisencountered.Toimplement
countofthe
numberofcharacters
analyze
40
characters
starting
this
programweneed
containedina
from
the
rightmost
one
string.
Non-printing
more
Page 49
characters
and
blanks
are
all
countedaspartoflength.
u
Strings
the
We
Two
parameter.Weare
specifyalengthinthe
STRING
Strings
As
Storageisoptimizedbynever
the
executed,
concatenationorINPUTisexecuted.
A
Using
us
bridge.
are
storedinBASIC
stringisstored
can
now
writeageneral
10
INPUT"NAME:FIRST,
20l=LEN(A$)
30
IFM/D$(A$,I,1)
40I=I-
50IFl>0
60
1
PRINT
variantsofMID$
and
GOTO
"LAST
the
="'THEN
30
NAME=";MIID$(A$,
are
usingalengthof1tosearch
MID$.
STORAGE
are
storedinthe
each
new
stringisadded,achain
string
pointstowhere
bothASandBSwill
LARGER
and
EXAMPLEOFSTRING
the
string
deal
Note
functions
them
out
oneata
useofthe
PET
witha3-byte vector.
third
byteisthe
purpose
Ml,
used
programtoextract
LAST",A$
60
here.
Line30uses
Everything
space
between
grows
creating
the
literal
share
described
time.
graphics
a
occursintextinmemory.
the
FUNCTIONS
thus
The
card
Two
bytes
length,
/
+1)
beyond
the
endofyour
downward
copyofa
same
farwecan
following
symbols:
the
the
case
for
the
the
positionofthe
string
copyofthe
writearoutine
routine
areapointertothe
LEN
function
the
last
extracts
name
fromafull
location
this
byte.
name.
wherealengthisspecifiedasthe
blank
delimiting
the
last
name.
blankistaken.
BASIC
from
program and
the
topofmemory.
assignedtoa
literal.
Likewise,
string.
New
stringisrequired
which
has
applications
the
highest
In
this
case
ifanexpressionAS=BSis
will
shuffleadeckofcards
in
many
games
in
memory
where
first
Line60does
RAM
locations.
the
vector
onlyifa
like
poker
not
for
for
or
. .
M
286
28i
436
433
*±£
The
stringC$is
rank.Asa
timesothat
Statement
of
cards.C$is
assignmentistoo
initialized
cardisdealt,N$contains
unique
105
clears
initialized
185
PRINT-"t".:REM
128
Ci=Ci+T'ii¥2¥
138
-Zi=£$+':ii+2.+
146
Ci=C*+MH^2^J
1SB
RZH
FULLHCjiRD
R:=2*IMT^LE;UC*>*RNDk1)/2+l)-
Ni=HID£\Ci
REH
SHRINK
432
iFR>iTHEHTi=LEF7*
Ti-::
435Ci=
^33
FEN
"
■»•
•-■i"fc—•.
cards
the
largetofitonone
r
T£+!a;
IDi
?F
INTiiCrtRD
I.1U'vi
INFUT'^KC
to
containadeckofcards.
the
are
always
screen.
in
Thisisdone
statements
SET
,R,i>:
THE
s.'C'i'R
*.•I—i-I■•.
THER
rank
dealt.
110
line.
Vi=M
DECK
*2>
DEAL
andY$contains
just
through
UP
DECK
ID*
<X$
vl*
>R-i>
Two
characters
for
showsothat
140.C$is
WITH
:£0
the
*LL
52
CARDS
.R
represent
suit.
The deck
the
program
concatenated
each
string,
can
because
card;
the
suit
C$,
shrinks
illustrate
the
the
literal
each
dealing
and
u
i
i
41
Page 50
n
Statement
In
201
432
through
argumentofLEFTS
440
prints
usertoreshuffle.
USER
To
this
usedtomany
approximate
simple
functionsintermsofother
A
functionisdefinedina
The
nameofthe
letterora
Thus
200
uses
RNDtogenerateanindex
the
indexisusedtopull
435
removes
cannotbezero,
each
card
for
DEFINABLE
FUNCTIONS
pointwehave
more
functionsinthat
certain
expression
100
INPUT
110
INPUT
120
DEFFNA(V)=V/B+C
letter
the
following
FNX
FNJ7
FNKO
FNR2
functionsinlineitbecomes
might
B
C
functionis''FN"
followedbya
are
the
our
programasitispulled.
covered
become
functions.
DEF
valid
into
C$.
N$(rank)Y$(suit)
card
from
the
the
R>1
all
the
functions
realm,
unreadable.
statement:
followedbyany
letterordigit.
function
names:
fromC$by
stringsothatitwill
testin432
intrinsictoBASIC.
especially
very
Fortunately
legal
The
random
the
index
MID$
function.
notbedealt
preventsanILLEGAL
450
tests
for
the
endofthe
Those
trigonometric.
tedious
and
,the
facility
variable
While
fromadocumentation
name.
is in
the
range1to
again.
QUANTITY
deck
familiar
one
with
could
existsinPET
Recall
thatavariableiseither
Since
the
LEN(C$)
-1.
second
ERROR..
and
460
allows
mathematics
write
code
standpoint
the
are
to
BASICtodefine
a
a
The
most
severe
one
line
(80-characters).
The
variableinparentheses
definedtobe
are
consideredtobe
are
usedinthe
After
the
funtion
example:
130Z=FNA(3)
140?Z
When
the
DEFFN
characterofthe
with
the
name
where
be
spaceisconsumedbyrecursion.
Figure
the
dummy
definedintermsofother
6.1
limitationofuser-defined
any
expression
global
evaluation.
definition
statementisexecuted,asimple
name
are
two
variableisstored.
shows
some
String
has
functions
following
butitmay
(have
the
has
been
bit7,the
most
same
executed, a
pointers:anaddressofthe
The
DEF
FN.Anoutofmemory
user-defined
functions
functionsisthat
cannotbedefined.
the
variable
have
valueasin
nameiscalledadummy
only
one
user
variable
significant
bit,
text
they
mustbecontainedintheir
variable.Afunction
argument.
the
restofthe
defined
Other
variables
program),
function
canbeusedasin
entryismadeinthe
usedinthe
and
their
variable
settoindicateitisafunction
where
the
functionisstored
andanaddress
current
the
table.
name.
entirely
may
expression
following
The
Associated
codetoexecuteafunctionisre-entrantsothatafunction
error
will
which
are
occurintimeasthe
readytobe
usedinPET
available
BASIC
programs.
on
be
values
first
of
may
stack
42
Page 51
FUNCTIONS
EXPRESSEDINTERMSOFBUILT-IN
BASIC
FUNCTIONS
SECANT,
SEC(X)
DEFFNA(X)=1/COS(X)
FORX<
COSECANT,
>n/2
CSC(X)
DEFFNB(X)=1/SIN(X)
FOR
X< >0
CONTANGENT,
DEF
FNC(X)=COS(X)/SIN(X)
FORX<>0
INVERSE
SINE,
COT(X)
ARCSIN(X)
DEFFND(X)=ATN(X/SQR(-X*X+1))
FOR
ABS(X)<1
INVERSE
INVERSE SECANT,
COSINE,
DEF
FNE(X)=-
FOR
ABS(X)<1
DEFFNF(X) =
FOR
ABS(X)>1
ARCCOS(X)
ATN
(X/SQR(-X*X
ARCSEC(X)
ATN(SQR(X*X-1)) +
+1))+nil
(SGN(X)-1)*rr/2
i
i
[J
INVERSE
INVERSE
HYPERBOLIC
HYPERBOLIC
HYPERBOLIC
HYPERBOLIC
COSECANT,
DEF
FNG(X)=ATN
FOR
ABS(X)>1
COTANGENT,
DEF
FNH(X)=-
FOR
ANY
SINE,
DEF
FNI(X)=(EXP(X)-EXP(-X))/2
FOR
ANY
COSINE,
DEFFNJ(X)=(EXP(X)+EXP(-X))/2
FOR
ANY
TANGENT,
DEF
FNR(X)=-
FOR
ANY
SECANT,
DEF
FNL(X)=2/(EXP(X)+EXP(-X))
FOR
ANY
ARCCSC(X)
(1/SQR(X*X-1))+(SGN(X)-1)*n/2
ARCCOT(X)
ATN(X)+it/2
X
SINH(X)
X
COSH(X)
X
TANH(X)
EXP(-X)/(EXP(X)
X
SECH(X)
X
+
EXP(-X))*2+1
, ,
U
u
.I
43
Page 52
HYPERBOLIC
DEF
COSECANT,
FNM(X)=2/EXP(X)-EXP(-X))
FOR
X < >
COSH(X)
0
n
HYPERBOLIC
DEF
INVERSE
DEF
INVERSE
DEF
INVERSE
DEF
INVERSE
DEF
INVERSE
DEF
COTANGENT,
FNN(X)=EXP(—X)/(EXP(X)+EXP(—X))*2+1
FOR
X <>0
HYPERBOLIC
FNO(X)
FOR
ANY
HYPERBOLIC
FNP(X)
FORX> =
HYPERBOLIC
FNQ(X)=LOG((1+X)/(1-X))/2
FOR
ABS(X)<1
HYPERBOLIC
FNR(X)=LOG((SQR(-X*X+1)+1)/X)
FOR0<X<
HYPERBOLIC
FNS(X)=LOG((SGN(X)*SQR(X*X
FOR
X < >
COTH(X)
SINE,
ARCSINH(X)
= LOG(X+SQR(X*X+1))
X
COSINE,
= LOG(X+SQR(X*X
1
TANGENT,
SECANT,
=1
COSECANT,
0
ARCCOSH(X)
-1))
ARCTANH(X)
ARCSECH(X)
ARCCOSH(X)
+1)+
1)/X)
H
INVERSE
GOSUB-RETURN
We
have seen
intrinsic
expression
Often
several
one
place
The
linesofcode
that
GOSUB
automatically
A
subroutineisstoredasa
The
last
executing
howtouse
function.
anditmust
and
The
linesofcode
executedbya
are
remembersatwhich
to
the
following
lineofthe
the
subroutine
mainline
HYPERBOLIC
FNT(X)=LOG((X
DEF
FNT(X)=LOG((X+1)/(X
FOR
ABS(X)>1
the
DEFFNto
major
limitationofDEFFNis
fitonone
willberepeated
line.
GOSUB
command:
calledasubroutine.
line
numberitwas
line
after
COTANGENT,
createasingle
throughaprogram.
GOSUB
GOSUB
executing
seriesoflinesinBASIC
code
mustbea
after
the
RETURN
GOSUB.
ARCCOTH(X)
-1))/2
variable
thatitcan
5000
meansgoto
executing
the
subroutine
function
consistofonlyasingle
These
the
before
startingatthe
statement.
This
which
program
subroutine.
the
GOSUB
canbeused
lines
It
differs
code.
line
number
tells
specifiedbythe
BASIC
you
like
any
algebraic
canbecollected
from
GOTO
and
can
return
in
in
GOSUB.
wanttoresume
44
Page 53
Example;
10
REM
20
GOSUB
30
STOP
50
REM
60
RETURN
THIS
IS
THE
50
THISISA
MAINLINE
SUBROUTINE
CODE
LJ
U
I
]
LJ
Ifwecould
Five
bytes
the
line
currently
number
GOSUB
The
physical
little
stack
Exampleofsubroutines
n!=1x2x
You
cannot
simple
10
100
110
120
130
140
The
routineonlines
example,
takeasnapshotofexecution,wewould
are
pushed
number
executing
and
text
entry
are
limitation
space
the
factorial
3x...xn
define
routinetofindn!for
INPUT
I=1:NF=1
NF=NF*I
1=1+1
IFI< =NGOTO
PRINT
suppose
onto
and
text
addressofthe
line
number
address
also
left.
this
you
from
eliminated.
on
the
function:
function
N
NF
100-140
wantabinomial
the
any
couldbeused
see
the
lines
10-20-50-60-30
stack
whenaGOSUBisexecuted:
GOSUB.
and
the
GOTO
the
stacktoresume
The
line
number
routine
handles
mainline
a
following
the
execution.
numberofGOSUB'sineffectatone
with
the
DEFFNcommand.Onthe
given
110
n (upto34).
many
times
coefficient:
(NF
denotesnfactorial)
duringaprogram
executedinthis
GOSUB
branch.
timeis23.
other
token,
the
AllFORentriesinfrontofthe
hand,
using
and
GOSUBisstuffed
RETURN
After
this
you
different
order
two
bytes
restores
many
thereisvery
can use
the
values
each
for
into
the
the
line
following
forN.For
,
LJ
J
(7)
The
program
10
15
20
30
40
50
60
70
100
110
120
130
140
m!
would
be
PRINT"M=";
PRINT"R=";
N=M:GOSUB100:X=NF
N=R:GOSUB100:Y=NF
N=M-R:GOSUB100:Z=NF
BC=X
PRINT
END
I=1:NF=1
NF=NF*I
1=1+1
IFI<=N
RETURN
BC
/ (
INPUT
INPUT
Y*Z
GOTO
M
R
)
110
LJ
u
u
LI
45
Page 54
TYPE
RUN
for
the
valuesM=
RESULTIS462
R=6.
Subroutines
usedtoinput
results.
outputasshown:
WhenwemakeNequaltoM,R,and
Of
course,
NESTED
The
subroutineonpage
the
The
subroutine,
act
likea"black
the
data
and
For
example,inthe
N
some
subroutinesdonot
suchasprintingaspecial
SUBROUTINES
coefficient.
denoted
box"orcomplex
other
fixed
subroutineonlines
SUB100
NF=N!
SUB
6-14
itself
couldbeusedasa
Merely
SUB
change
10,
beginningonline10and
function
variables
NF
M-R
respectively,
need
inputted
formonthe
print
line70to
70
within
(or
sometimes
100-140,
the
variableNis
we
getNFequaltoM!,R!and
variablesasthey
screen:
form
subroutineina
RETURN
endingonline70has
the
program.
the
same
might
program
Certain
variable)
input
just
that
fixed
are
usedtooutput
and
the
performaspecified
repeatedly
the
following
variables
variableNFis
(M-R)!.
calculates
structure:
are
the
Subroutines
nestedinSUB20.
only
limitisthe
Subroutines
accepts
on
the
subroutines.
CAUTIONS
A
common
and
resultina
that
are
Many
amountofmemory
can
alsobenestedinmore
specific
screen,
characters
mightbecalledonmany
errorinusing
RETURN
M
R
N
SUB100
usedbyother
programs
from
subroutines
WITHOUT
BC
f
NF
subroutines
have
subroutines
available.
than
the
keyboard,
timesinthe
are
called
nestedinsubroutines
one
subroutine.
printsawinking
main
istoallowamainline
GOSUB
ERROR.
PutaSTOPorENDstatementinyour
BC
=
nested
subroutines.
in
An
input
subroutine,
cursor,
program
executiontofall
and
itself
and
prints
intoafollowing
In
this
case,
SUB100
nested
alsoinvarious
subroutines...The
for
example,
the
given
characters
other
subroutine
codetoprevent
is
that
46
Page 55
this
10
GOSUB
20
RETURN
20
10
15
GOSUB
END
20
20
RETURN
Sometimes,
just
once,
memory
to
structure
FOR-NEXT
FOR-NEXT
withasingle
The
end
Nested
variable
Exiting
to
assign
We
have
you
might
thenitshouldbeincorporated
space.Onthe
your
program
LOOPS
simplifies
statement.
of the
FOR
names
a
loopisspecifiedbythe
NEXT
may
FOR-NEXTIoop
the
maximum
seen
how
routine.
10
1=1
201=1+
30
1
IFI<=10
haveatendency
other
hand,
subroutines
into
blocks.
the
writingofBASIC
loops
are
permitted
resultinNEXT
WITHOUT
viaabranch
limit
to
the
variable
repeated
THEN
operations
GOTO
20
to
make
everything
intoaprogram
are
incredibly
intoasubroutine.
whereitis
programsbyallowing
FOR
I=ATO
statement
as
long
as
FOR
will
leave
the
then
canbeperformed
BSTEPC
NEXT
each
loop
errors.
FOR
entryonthe
exit
the
usesaunique
loop
usingacounting
Ifagiven
usedtosave
powerful
programming
onetospecify
variable.
stack.
through
The
a
NEXT.
variable
subroutine
execution
tools
and
complex
best
loop
Use
of
identical
waytohandle
suchasIinthe
is
used
time
and
allow
you
structures
loop
this
is
M
I
j
LI
\ ;
M
|
U
In
this
case,
any
routine
have
values
This
looping
10
20I=
30IFI<=
The
valuesofI
Since
10
20
Iisthe
A,B,C
10
On
the
subscripted
10
20
30
which
process
I=A
l+C
BTHEN
will
this
processiscumbersometouse,
FORI=ATOBSTEPC
NEXT
counting
may
FOR
other
REM
NF=1
FORI=1TO
variable,
not
onlybeconstants,
I=A(2)+1TOJ*2STEP-1
hand,
1(1,4).
When
COMPUTATIONOFFACTORIAL
appearinginlines
range from1to10in
canbegenralizedinthe
GOTO
range
the
fromAtoBin
Aisthe
counting
the
N
20
variable
increments
incrementsof1.
incrementsofsize C.
initial
value,Bis
but
they
areofsize
21-29
willberepeated
case:
BASIC
canbeany
also
the
canbeany
1(C=1)
10 times.Inaddition,
provides
ending
valid
floating
you need
you
value,
arithmetic
variable
with
the
FOR-NEXT
and
Cis
expression
but
cannotbeinteger
not
include
the
the
variable
statement:
the
increment.
STEPinthe
I
will
(l%)
or
program.
<_.
47
Page 56
40
NF=NF*I
50
NEXT
Note
how
much
computing
program
shorter
and
written
more
clearly
without
FOR-NEXT.
this-routine
is
written
comparedtothe
same
factorial
WheneveraFORisexecuted,a16-byte entryispushed
madetoseeifthere
and
all
other
FOR
program
each
NEXT
to
that
GOSUB
foraFOR
pointer
is
leftona
entered
RETURN
NESTED
FOR-NEXT
andsoon.
which
time.
matches
point.Ifno
execution
entry
GOSUB
but
never
eliminates
FOR-NEXT
loops,
When
are
any
entries
entries
jumps
the
most
matchisfound,aNEXT
also
that
existed,
like
doing
that
were
outofthe
recent
middleofa
stack
putsa5-byte
cannotbematched,
entry.
This
assures
the
RETURN
the
GOSUB
LOOPS
subroutines,
so,itis
?NEXT
10
FOR1=1TO
15
PRINT
20
FORJ=1TO
25
PRINT
30
FORK=1TO
35
PRINT
40
NEXT
50
NEXT
60
NEXT
stack
canbenested,
important
WITHOUT
"I"
"J"
"K"
alreadyonthe
made
afteritare
FOR
entryorthe
entryonthe
When
variable
WITHOUT
stack.
all
thatifyou
will
stillbeabletofind
entry
and
all
That
nottouse
FOR
ERROR
10
10
10
onto
stack
for
eliminated
loop
again
FOR
When
the
FOR
GOSUBtoa
FOR
is,aFOR-NEXT
the
the
stack.
the
same
from
will
not
specifiedasa
error
occurs.
Before
loop
the
thisisdone,acheck
variable.
stack.
Thisisdonesothat
useup16-bytesofstack
parameter
RETURNisexecuted,
entriesonthe
stack
have
sectionofcodeinwhichaFOR
the
most
entries
same
made
recent
after
loop
variableasthis
GOSUB
the
GOSUB
maybecontainedinanother
If
so,
that
FOR
entry
space
and
resets
the
stackissearched
been
the
stack
searched,
loop
entry.
entry.
will
result
is
a
a
is
in
Lines
40-60ofthe
correspondstowhich
the
counting
the
NEXT.
PET
A
NEXT
BASIC
will
WITHOUT
Itisinteresting,
expressions
above
FOR.
variable
40
50
60
also
40
allow
usedinthe
NEXT
NEXT
NEXT
NEXTK,J,
FOR
however,tosee
canbewhen
example
youtowrite
error
are
Optionally
corresponding
K
J
I
I
will
result,
how
they
are
confusingatfirst
one
may
specifyavariable
FOR
one
NEXT
that
however,ifyou
compact
nested.
the
notation
48
glance
butinno
terminates
are
because
following
wayisit
all
three
one
requiredbyBASICtoexecute
carelessinspecifying
appears
and
how
cannot
NEXT.
FORsatone
powerful
tell
The
variable
the
orderofK,J,I.
the
which
time
NEXT
refers to
FOR-NEXT
Page 57
Some
hints
You
may
For
will
compute
change
the
the
value
valueofthe
10
FOR1=1TO
20X=X +
30IFI=7THENI=8
40
NEXT
50
PRINT
counting
8
1
X
variable
during
the
looping
u
LI
sequence.
Similarly,
end
instead
SUBSCRIPTED
Array
less
(numberofelementsineach
elements.
Limitsonthe
and
array
when
you
exitaFOR-NEXT
value
and
then
exit
the
10
FOR1=1TO
20IFFNA(l)=0THEN1=
30
NEXT.'RETURN
of
10
FOR1=1TO
20IFFNA(l)=0THEN
30
NEXT
VARIABLES
variables
than10elements.
A(0,0)
A(9,0)
space
elementsto256.
need
notbedeclared
The
Subscripts
A(0,8)
A(9,8)
numberofdimensions
availableona
startat0
line
Each
loop
total
array
loop usingabranch,
viaaNEXT
10
statement.
10
10
RETURN
withaDIM
numberofelementsinan
dimension)+1by
andgouptothe
and
sizeofa
followingaDIM.
element
statementifthey
the
maximum
dimension
PET
requiresatleast
you
For
instance,
array
other
subscripts.
value
are
BASIC
restrict
5-bytesofstorage.
should
determinedbysize of
assign
you
have
only
canbecomputedbymultiplying
Thus
the
total
the
counting
should
A(9,8)
use
one
dimension
contains
number
variable
and
(9+1)*(8+1)
memory
of
available
the
contain
the
D
U
J
Ifasingle
the
first
Example:
Supposeweneedtowriteasimple
transaction
dimension
reference.
Listofaccount
1
2
3
4
5
6
7
8
9
and
array
Otherwise,aREDIM'ED
$100
$135
$57.86
<$987>
$22
<$6
3>
$50
<$21>
$2
1
keeparunning
requires
balances
more
program
total
than10elements,
ARRAY
on each
which
account.Wecould
error
allowed
49
the
DIM
statement
will
occur.
youtoINPUTanaccount
refertoeach
mustbeexecuted
account
before
number
balanceasA1, A2,
and
a
L
Q
Q
U
Page 58
A3, A4, A5,
10
INPUT
20IF1=1
30IFI
etc.
This
list
canbestoredina
values
program
The
table
andanindividual
canbereduced
10
INPUT
20A(l)=A(l)+C
30
GOTO
listwehave
can
alsoberepresented.
etc.
Thisisacceptable
"ACCOUNT,
THEN
=2 THENA2=A2+
CHARGE";I,C
A1=A1+C
single
valueisaccessedbyan
to:
"account,
10
represented
Account
charge";
Balance
#
has9rows
but
would
C
variable
I,C
Thisisa
requirealotofparallel
logictoaccomplish
whichisactuallyalistofvariables.
index.
and1column.
two
dimensional
The
indexwecan
Thusitisa1
array.
#of
transactions
useisthe
dimensional
the
summation
This
listisan
account
array.Amultiple
array
number.
column
of
Our
1
2
3
4
5
6
7
8
9
Our
table
has9rows
and
column
In
ordertouse
rows
and
indexofwhereitis
suchatableina
columns
Suchadescription
Letusrewrite
10
INPUT
20
A(I,1)=A(I,1)+C
30
A(I,2)=A(I,2)+1
40
GOTO
our
"ACCOUNT,
10
<$987>
and2columns.Toaccessacertain
containedinthe
isaDIMension
programtoupdate
$100
$135
$57.86*
$22
<$63>
$50
<$21>
$21
contained.
BASIC
CHARGE";I,C
For
program,
array
statement.
the
you
variable.
For
DIM
column
containing
1
1
1
1
1
1
1
1
1
entry
the
must
provideastatement,todescribe
our
tableof9
A(9,2)
position,
rows
the
numberoftransactions
you
must
specify
denotedbya*isinrow3,column
and2columnswecould
the
row
the
number
index
1.
of
write
Now
suppose
account
sheetsofpaperontopofeach
thatwehadatable
hadabalance
and
each
for
eachof5
balance
other
and
companies
hadanumberoftransactions.Wecan
referingtoeach
50
and
each
company
sheetbynumber.
had9accounts
describe
thisaspiling
and
each
Page 59
We
have
createdbythis
In
mathematics,
The
For
isavectorofdimension
usedinmathematics.
a
v=(v1t
v2,...,vn)
above
example,
v=(3,9,2)
vector
hasncomponents
exampleamulti-dimensional
vectorisan
3.
subscripted
ordered
collection
of
numbers:
andiscalledavectorofdimension
variable.
These
n.
arrays
correspond
to
Orderisimporatant
w=(3,2,9)
Vectors
as
can be
the
variableswehave seensofar
here
since
if
storedinmemory
using
subscripted
-X,
l%,
variableorreturnazeroornull("")ifthe
Like
vectors,
notation.
The
dot
For
example,inthe
v=(v,,
andw=
Then
v«w
Supposewehad
subscripted
Theyare
Dot
especially
Product
productoftwo
v2,
v3,
v4)
(w1}
w2, w3,
=(^ x
w4)
wi}v2x
variables
have
useful
when
the
vectorsv&wisavector,
four
dimensional
w2,v3x
case,
w3,v4x
v=(5,6,7,11,4,6,1/
w=
(9,5,2,1,0,3,2)
Thenaprogramtocompute
the
dot
productv•wmight
A$,
etc.
value
has
variables.
That
not
These
is,
they
call
been
previously
powertoexecutealarge
combined
if
w4)
with
FOR-NEXT
denotedbyv•w,
look
like
whose
variables
whatever
are
usedinthe
same
valueisstoredinthat
specified.
numberofoperations
loopsasthe
ith
next
component
usingasingle
example
(v«w).isv.xw..
way
shows.
FORI=1TO
FORI=1TO
FORI=1TO
FORI=1TO7:?VW(I):NEXT
7:READ
7:READ
7:VW(I)=V(I)*W(I):N
V(I):NEXT
W(I):NEXT
EXT
51
Page 60
DATA
5,6,7,11,4,6,1
DATA
9,5,2,1,0,3,2
SUBSCRIPTED
It
was
mentioned
decimal:
integer:
string:
Subscripted
of
the
U.S.
STRING
previously
A(l)
A%(l)
A$(l)
string
GNP
variables are
from
VARIABLES
that
subscripted
extremely
1966
through
!
72
usefulasshowninthe
1974.
GROSS
$
936
$
1063
$
1171
S
1307
variables
NATIONAL
(IN$BILLIONS)
can
be
PRODUCTS
next
program
which
printsabar
graph
The
program
listing
READY
is:
10
SPACE$=
20
FORI=1TO7:READ
30
FORI=0 TO8:READ
40
PRINT"<?SPC(8)"GROSS
50
PRINTSPC(12)"(IN
100
FOR
110X=V(1)/45:Y=INT(X)
120
PRINT
130
PRINT"G
140
NEXT
200
DATA"3"
210DAT
READY
"
l=0TO
"R"LEFT$(SPACE$,Y)A$(S*(X-Y))
8
R"STR$(66
"5" "B"
A753,796,869,936,982,1063,1171,1307,1413
A$(I):NEXT
V(I):NEXT
NATIONAL
$BILLIONS)Q"
+1)"
$"STR$(V(I))"Q"
"5"
"■"
"I"
"]"
PRODUCTQ"
52
Page 61
The
subscripted
A$(0),
A$(1),...A$(7)
values
V(0),
V(1),...,V(8)
give
accuracytothe
are
the
GNP's
graphbyprinting
for
eachofthe9years.
these
The
graphics:
subscripted
strings
A$(1)
A$(2)
A$(3)
A$(4)
A$(5)
A$(6)
A$(7)
THE
HEADING
is
printedinlines40and50and
prints
STR$(V(I)).
out
each
bar
and
line
prints
null(by
I
MM
■■
■■■
GROSS
thenaFOR-NEXT
130
printsacursorupand
NATIONAL
(IN
PRODUCT
$BILLIONS)
looponlines
then
100-140
the
prints
out
the
associated
year,
STR$(66
ASC
165
180
181
161
182
170
167
eight
bars.
+1)
(R)
(R)
(R)
Line
and
GNP,
120
Each
barismadeupofYreverse
formula
Y=INT(V(l)/45;
=
INT(GNP/45)
Here,45is
than45are
Fine
tuningonthe
A$(8*(X-Y))
Here
decimal
DIMENSION
When
form,
redimensioned
been
in
memory
programming
Because
additional
storage
the
simple
purelyascale
used.
bar lengthisaccomplished
8*(X-Y)
using
DIM
will
range
part.
STATEMENTS
more
than
A$(K),
whereKis
over
10 subscripts
withoutaCLR
used,a?REDIM'D
for
the
sense,
the
variables
simple
area
mustbeblock
variable
ARRAY ERROR
given
numberofvariables,
therefore,tobegin
are
dividedinstorage
variableisa
canbeinsertedatthe
adjustment.
field
the
decimal
the
largest
spaces
The
for
any
subscript
and
the
string
proportions
using
values0through
variable,
of
the
the
subscripted
7.99...9
a
dimension
ofA$usedinthe
statementorwhenadimension
bit
more
moved
upwardbyseven
occurs.
subscriptsat0
complicated
Whenadimension
including
between
endofsimple
the
variable
and
not
arrays
onceanarray
bytes
and
and
variable
A$(8*(X-Y)).
bars
TheYis
remain
the
string
variable
determined
same
when
butA$automatically
statement
program.
statement
statementismade,
whose
1.
simple
has
been
the
pointers
storage.
mustbegiven.Ittakes
When
variables
appears
after
spaceisreserved
subscriptis0.Itis
variables
insertionofan
defined.
adjusted
First,
upward+7.
by
the
values
truncates
other
the
the
are
the
variable
the
entire
has
good
array
Finally,
53
Page 62
If
large
arrays
assigned,
simple
variableisdefined.
assignavaluetoall
will
are
defined
much
execution
execution
known
and
initiaiized
time
canbelost
The
best
simple
speed.
first
before
moving
simple
the
arrays
variabies
strategytofollowinthis
variables
btfore
assigning
are
each
time
caseisto
arrays.
This
a
Functionsofnew
CLR
String
Data
Endofarray
Endofsimple
NEW
String
Data
Endofarray
pointer
pointertostartoftext
pointer
pointertostartoftext
Endofsimple
and
CLRondata
equatedtotopofmemory
tabletostartofvariables
variablestostartofvariables
equatedtotopofmemory
tabletostartoftext+3
variablestostartoftext+3
Startofvariablestostartoftext+3
-1
-1
54
Page 63
s
o
CO
topofmemory-
startofstrings
CM
00
CO
O)
"S5
oo
<
Q.
o
tr
LU
o
Q.
Q.
O
z
tr
a.
m
CO
s
LU
LU
Q_
CO
CM
CM
CO
O
LU
LU
Q.
endofarray
endofvariables
startofvariables
data
statement
startoftext
table
1
<
^
CO
CM
o
CM
^8?.
/
o
s
03
N
To
E
CO
CO
la
CO
■>
CO
CD
-Q
CO
van
CO
"c
^
°
2
o
CO o
55
<
<
CD
E
2
03
03
"co
■>552
/
in
oc
Q.
CO
o
Q.
CM
O
CO
I
111
109
sinl
intei
poi
Prin
CVJ
o
\
CsJ
55
Page 64
NOTES
56
Page 65
Chapter
As
sideofthe
As
PET
contact
7.
indicatedinFigure
PET
that
outlinedinFigure
main
logic
assembly
identification
7.1,
there
are
enable
the
usertointerface
7.2,
edge
card
board
convention
itself.
forJ1andJ2is
MEMORY
*
PET
INTERFACES
four
connectors
the
connectors
There
EXPANSION
CONNECTOR
are
are
two
AND
provided,
computer
utilized
accessible
with
which
contactstoeach
also
illustrated
PARALLEL
USER
PORT
J2
SERIAL
ELECTRICAL
LINES
through
external
devices.
are,infact,
positionofthe
in
Figure
NUMBER
ANO
SPEC.
7.2.
3-WIRE
POWER
slotsinthe
direct
extensionsofthe
connector.
AC
CORD
rear
and
The
IEEE-488
The
connector
with
INTERFACES
standard IEEE-488
with
.156
allofthe
other
Figure
7.1.
fuse,
FROM
PET
ABCDEFHJ
RearorEdge-on
Figure
7.2.
Simplified
to
illustrate
(Connector
J1)
connectorisnot
inch
spacing
between
connectionstothe
Simplified
line
cord
MAIN
view
and
interfacing
LOGIC
View
viewsofedge
contact
identification
usedonthe
contact
PET.
off
PET
showing
connectors.
ASSEMBLY
through
PET.
slotsinPET
connectorsJ1and
Instead,astandard12position,24contact
centersisprovided.
switch,
BOARD
KLM
convention.
N
J2
This
(or
Pin)
permitsitto
be compatible
edge
Keying
Table
slots
7.3
are
shows
located
the
between
PET
contact
pins
2-3
and
9-10.
identification
characters,
57
the
connection
fora
standard
IEEE
connector,
Page 66
the
IEEE
mnemonics
and
the
signal
definitions.
Electrical
drive
capability
and
line
PET
Pin
Characters
Upper
Pins
1
2
3
4
5
6
7
8
9
10
11
12
Lower
Pins
A
B
C
D
E
F
Lower
Pins
H
J
K
L
M
N
impedance
Standard
IEEE
Connector
Pin
Numbers
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
matchingisin
Mnemonic
IEEE
Signal
DI01
DI02
DI03
DI04
EOI
DAV
NRFD
NDAC
IFC
SRQ
ATN
GND
DI05
DI06
DI07
OI08
REN
GND
GND
GND
GND
GND
GND
GND
accordance
Definition/Label
Data
input/output
Data
input/output
Data
input/output
Data
input/output
Endoridentify
Data
valid
Not
ready
Data
not
Interface
Service
Attention
Chassis
cable
Data
input/output
Data
input/output
Data
input/output
Data
input/output
Remote
DAV
ground
NRFD
ground
NDAC
ground
IFC ground
SRQ
ground
ATN
ground
Data
ground
with
Signal
for
data
accepted
clear
request
ground
shield
and.IEEE
drain
enable
\
(DI01-8)
line
line
line
line
wire
line
line
line
line
IEEE-488
#1
specifications.
#2
#3
#4
#5
#6
#7
#8
RECEPTACLES
A
listoffrequently
edge
card
FOR
THE
used12position,
connectorJ1andJ2is
Table
IEEE
INTERFACE
Table
7.3.
PET
IEEE-488
associated
shown
7.4.
contact
24
contact
here:
Manufacturer
Cinch
Sylvania
Amp
Amp
Amp
Receptacles
connectorsorparallel
identification
identification
labels
receptacles
recommended
characters.
characters,
and
descriptions.
that
Part
Number
251-12-90-160
6AG0M2-1A1-01
530657-3
530658-3
530654-3
for
PET
user
port.
58
are
suitable
IEEE-488
for
connection
to
the
PET
Page 67
IEEE-488
The
these
are
CONNECTORS
IEEE-488
are
showninTable
their
matching
standard
receptacles
7.5,
plugs.
are
and
belongtothe
not
directly
Cinch
connectabletothe
Series57or
Champ
PET
edge
Series
connector;
(Amphenol).
some
Also
of
shown
Commodore
contact
PARALLEL
The
lines
edge
connector
connectors.
Keying
Table
3-1
Note
that
the
PET
connectorisused;
that
the
has
availablea1
your
local
USER
for
PORT
this
interface
witha.156
slots
are
located
shows
the
service
top
the
connections
departmentorqualified
connectors
dealerorCommodore
this
Connector
Manufacturer
Cinch
Cinch
Amp
Amp
meter
(Connector
are
brought
inch
between
PET
pin
identification
1-12,
the
jumpers
someofthe
1-12beused
identifier
5710240
5720240
552301-1
552305-1
Table
7.5.
long
IEEE-488
for
J2)
out
spacing
pins
between
1-2
and
top
lineofcontacts
dealers.
only
with
Solder-plug
Solder-receptacle
Insulation
Insulation
IEEE
price
from
the
standard
and
contact
connectors
dual
connector-PET
delivery.
PET
main
centers.
10-11.
characters,
When
top
extreme
the
corresponding
(see
Figure
using
contactstothe
caution.
Description
displacement
displacement
plug
receptacle
edge
logic
boardtoa12position,24contact
See
Table
labels
7.6),
are
primarily
the
incorporated
bottom
contacts.Itis
connector,
7.4
for
and
cable.
suitable
their
descriptions.
Intended
ROM
diagnostic,
strongly
Please
mating
for
use
by
a
special
advised
Pin
Identification
Character
1
2
3
4
5
PET
pin
Table
continuedonnext
Signal
Label
Ground
T.V.
Video
IEEE-SRQ
IEEE-EOI
Diagnostic
Sense
Table
7.6.
Parallel
identification
signal
labels
page.
Digital
Video
usedindiagnostic
the
video
Direct
the
IEEE-488
ing
operationofthe
nostic
Direct
the
IEEE-488
ing
operationofthe
nostic
When
up
the
nostic
routine.
user
characters,
and
their
Signal
Description
ground.
output
used
for
external
routine
circuittothe
connectiontothe
port.Itis
routine.
connectiontothe
port.Itis
routine.
this
pinisheld
PET
software
routine,
port
descriptions.
rather
information.
the
corresponding
display
SRQinthe
EOIinthe
low
jumpstothe
than
display,
for
verifying
board.
SRQ
signal
on
usedinverify
diag
EOI
signal
on
usedinverify
diag
during
power
diag
the
BASIC
59
Page 68
Table
7.6.
Parallel
user
port
information
(continued).
Pin
Identification
Character
6
7
8
9
10
11,
12
A
B
C
D
E
F
H
J
K
L
M
N
Signal
Label
Tape
READ
Tape
READ
Tape
TV.
Vertical
TV
Horizontal
GND
GND
CA1
PA0
PA1
PA2
PA3
PA4
PA5
PA6
PA7
CB2
GND
#1
=2
Write
Description
Used
with
the
diagnostic
verify
cassette
Used
with
verify
cassette
Used
with
verify
operationofthe
tionofboth
TV
vertical
diagnostic.
TV
display.
TV.
horizontal
diagnostic
Digital
Digital
Standard
6522VIA.
Input/output
and
entlyofeach
or
output.
Special
Digital
tape=1read
the
diagnostic
tape=2read
the
diagnostic
cassette
sync
Maybeused
signal
maybeused
ground.
ground.
edge
sensitive
canbeprogrammed
I/O
pinofVIA.
ground.
Signal
routine
routine
routine
WRITE
ports.
signal
verified
for
verified
forTVdisplay.
input
linestoperipherals,
other
for
to
function.
to
function.
to
func
in
external
in
of
independ
input
VERSATILE
The
linesonthe
(VIA
MOS
The
signals
address
The
parallel
for
the
connection,
shift
register.
A
detailed
port
are
signalsinany
INTERFACE
bottom
Technology
CA1,
PAO-7,
E840.
port
consistsofeight
eight
lines,CA1,
CB2.
This
specification
utilizedbythe
way.
ADAPTER
sideofthe
part
#6522).
and
CB2,
address
which
has
PET
can
mostofthe
for
the
for
Internal
user
port
connector
are
directly
connectedtoa
59456).
programmable
alsobeused
abilities
VIAisbelow.
controls.
for
of
All
Please
originate
bi-directional
other
edge-sensative
CA1,
but
can
signalsonthe
note
fromaVersatile
standard
I/O
also
VIA
that
6522
lines
actasthe
that
the
user
60
Interface
VIA
locatedathexadecimal
PAO-7,aninput
inputs
andavery
handshake
inputoroutputofthe
are
not
connectedtothe
should
avoid
interfacing
Adapter
line
powerful
VIA
user
these
Page 69
Table
7.7
shows
the
decimal
and
hexadecimal
addressesinthe
PET
associated
with
the
VIA.
Decimal
59456
59457
59458
59459
59460
59461
59462
59463
59464
59465
59466
59467
59468
59469
59470
59471
Hexa-
Decimal
E840
E841
E842
E843
E844
E845
E846
E847
E848
E849
E84A
E84B
E84C
E84D
E84E
E84F
$E840+
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111
Addressed
Output
Output
I/O
I/O
Read
Read
Access
Access
Read
Access
Serial
Auxiliary
Peripheral
Interrupt
Interrupt
Output
register
register
with
handshaking.
PortBData
register.
PortAData
register.
Timer1Counter
byte
WritetoTimer1Latch
low
order
Timer1Counter
order
Latch
initiate
Timer1Latch
byte.
Timer1Latch
byte.
low
and
reset
Writetolow
Timer2butdonot
interrupt.
high
2;
reset
write.
I/O
register
without
for
for
byte.
byte.
WritetoTimer
high
order
count.
order
byteofTimer
Counter
order
order
Counter
Shift
register.
Control
Control
Flag
register
Enable
for
handshaking.
Location
I/O
port
B.
I/O
port
A
Direction
Direction
low
order
high
1
byte
and
low
order
high
order
interrupt.
byte
of
reset
byteofTimer
interrupt
register.
register.
register.
I/O
on
(IFR).
Port
A,
2
PROGRAMMING
Data
lines
PAO-7
usingasoftware
showsapractical
The
programming
drive
the
pins
THE
are
individually
POKE
exampleofinput/output
need
programmedasoutputs,
Table
7.7.
VIA
6522
USER
PORT
programmedtofunction
59459
commandtoplace a
onlybecarried
Decimal
and
selection.
outatthe
and
beginning.
PEEK(59471)
61
Hexadecimal
number
addressesinPET.
for
input or
into
the
From
will
read
outputasrequired.
data
direction
thenonPOKE
all
the
inputs.
register.
59471
Thisisdone
Table
7.8
canbeused
by
to
Page 70
Command
Statement
POKE
59459,255
POKE
59459,0
POKE
59459,240
Programmingoflines
Table
Binary
Representation
11111111
00000000
11110000
7.8.
Parallel
user
PAO-7
for
port
input/output
Lines
PA0-7
PA0-7
PA0-3
PA4-7
example.
operation.
Mode
Output
Input
Input
Output
SECOND
This
with
A
keying
This
are
CASSETTE
interfaceisbrought
.156
inch
spacing
slotislocated
portisintended
madeatthe
riskofthe
supply.
Table
7.10
shows
typical
receptacles
INTERFACE
out
between
between
for
use
user.
the
PET
pin
that
are
Insulation
(Connector
from
the
PET
contact
pins
2-3.
with
the
Commodore
Please
identification
suitable
for
FROM
Figure
PET
RearorEdge-on
7.9.
J3)
main
logic
centers
note
(See
that+5voltsisnot
characters,-labels
the
second
MAIN
LOGIC
BCD
View
Simplified
with
viewofedge
contact
boardtoa 6
Figure
second
cassette
7.9).
position,12contact
system
intended
and
descriptions.
cassette
through
identification.
connector.
ASSEMBLY
slotinPET
connector
BOARD
only.
for
Top
View
Upper
Contact
(or
Pin)
Lower
Contact
(or
Pin)
J3
Any
use
as an
Table
edge
connector
other
connections
external
7.11
shows
power
some
Note
A-1,
B-2,
In
some
Pin
Identification
Characters
A-1
B-2
C-3
D-4
E-5
F-6
PET
pin
etc.,
special
units,
Label
GND
+5
Motor
Read
Write
Sense
Table
identification
implyapinAto
pins1through6were
Digital
Positive5voltstooperate
Computer
Read
Write
Monitors
7.10.
Second
characters,
pin1,
ground.
only.
controlled
cassette
cassette
motor.
line
from
linetocassette.
closureofmechanical
when
cassette
labels
62
pinBto
cassette.
interface
and
pin2,connection.
not
connected.
Description
positive6volts
any
buttonispressed.
port.
associated
cassette
circuitry
for
switch
on
descriptions.
Page 71
u
Manufacturer
Sylvania
Viking
Viking
Viking
Amp
Sullins
Cinch
Table
7.11.Aselection
with
the
PET
The
PET
main
expansion
suitable
J4
daughter
Daughter
pin
connectors
andJ9are
board
board
12
3 4 5 6
#
function
-5V
Raw
-5V
Raw
connectorsJ4and
6AJ07-6-1A1-01
2KH6/1AB5
2KH6/9AB5
2KH6/21AB5
530692-1
ESM6-SREH
250-06-90-170
off
suitable
second
BOARD
logic
which
2x25
(row,
power
power
7
power
power
key
+12V
Raw
power
+12V
Raw
power
Ground
Ground
Manufacturer
Spectra-strip
Spectra-strip
Spectra-strip
Spectra-strip
Circuit-Assembly
Circuit-Assembly
Table
7.12.Aselectionofsuitable
for
connecting
connectors
with
J4,
J9,
J10,
Identifier
MEMORY
The
and
7.12
spacing
Note
returns
receptacles
cassette
EXPANSION
board
edge
connector
CONNECTORS
has
been
J9,
and
the
user
column)
configuration,
connections
connections
o o••
123456
*
p[
1
+9
key
2
key
3
4
+9
5
ground
6
+9
7
Ground
contact
2x7
2x7
2x25
2x25
2x7
2x25
PET
grid
daughter
and
J11
board
EXPANSION
memory
decoded
expansion
input/output
showsasimplified
between
that
the40top
for
for
connecting
J3.
contact
the
corresponding40lower
(J4,
designedtosupportadaughter
expansion
may
attach
power
for
his
and
and
table
7.13B
lists
table
7.13A
• •
7
function
unregulated
unregulated
unregulated
identifier
802-104
802-114
802-050
802-150
CA-14-IDSC
CA-50-IDSC
receptacles
pin
CONNECTOR
connector
lines
viewofthe
centersis0.1
edge
"B"
connections
J9,
J10,
J11)
connectors
own
boards.
J10
and
J11
the
memory
Memory
1
2 3
45678
pin#
SideAl
11
12
13
pin
#
SideAl
10
11
12
13
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
ground
BA0
BA1
BA2
BA3
BA4
BA5
BA6
BA7
BA8
BA9
BA10
BA11
function
ground
BD0
BD1
BD2
BD3
BD4
BD5
BD6
BD7
SEL2
SEL3
SEL4
SEL5
from
board
J10
All
are
expansion
expansion
(ConnectorJ4and
the
80-position
and
connector
2x7.
accesstothe
6502
microprocessor.
connectors
inch.
(or
pins)
edge
"A"
which
attachestomemory
J11.
Table
pins
Table
7.13A
connections.
areon.1"
connections.
bus
9
101112 131415
pin
14
15
16
17
18
19
20
21
22
23
24
25
table
16
#
Memory
SideB1-25
(J4j
pin
#
14
15
16
17
18
19
20
21
22
23
24
25
Side
B1-25
J9
Figure
used.
The
are
ground
7.12
shows
grid.
lists
the
7.13B
17 1819202122 23 24
function
BA12
BA13
BA14
BA15
SYNC
IRQ
Management
B02
BR/W
BR/W
DMA
ground
ground
function
SET6
selT
SEL"8
SEL"9
SEL
A
seTb
CAS
RAS
RES
RDY
NMT
ground
ground
0
n
u
I"*
U
25
U
0
63
D
Page 72
Table
7.13C
shows
the
PET
pin
numbers,
line
labels
and
line
descriptions.
Connector
Pin
Numbers
J9-1
J9-2
J9-3
J9-4
J9-5
J9-6
J9-7
J9-8
J9-9
J9-25
J9-10
J9-11
J9-12
J9-13
J9-14
J9-15
J9-16
J9-17
J9-19
J9-21
J9-22
J4-10
J4-11
J4-12
J4-13
J4-14
J4-15
J4-16
J4-17
J4-18
J4-19
J4-22
J4-23
J4-24
J9-1
J4-2
J4-3
J4-4
J4-5
J4-6
J4-7
J4-8
J4-9
J4-20
J4-21
J4-25
Line
Labels
GND
BA0
BA1
BA2
BA3
BA4
BA5
BA6
BA7
GND
BA8
BA9
BA10
BA11
BA12
BA13
BA14
BA15
IRQ
B02
BR/W
SEL2
SEL3
SEL4
SEL5
SEL6
SEL7
SEL~8
SEL~9
SEL
A
SELB
RES
R"DY
NMI
GND
BD0
BD1
BD2
BD3
BD4
BD5
BD6
BD7
RAS
CAS
GND
Logic
Ground
Address
Address
Address
Address
Address
Address
Address
Address
Logic
Address
Address
Address
Address
Address
Address
Address
Address
Interrupt
Buffered
Buffered
4K
4K
4K
4K
4K
4K
4K
4K
4K
4K
Reset
Ready
Non
Logic
Data
Data
Data
Data
Data
Data
Data
Data
Dynamic
Dynamic
Logic
bit0,used
bit1,used
bit2,used
bit3,used
bit4,used
bit5,used
bit6,used
bit7,used
Ground.
bit8,used
bit9,used
bit
10,
bit
11,
bit
12,
bit
13,
bit
14,
bit
15,
request
phase2clock.
read/write
byte
page
byte
page
byte
page
byte
page
byte
page
byte
page
byte
page
byte
page
byte
page
byte
page
for
6502
linetothe
maskable
ground.
bit0.Buffered.
bit1.Buffered.
bit2.Buffered.
bit3.Buffered.
bit4.Buffered.
bit5.Buffered.
bit6.Buffered.
bit7.Buffered.
RAM
RAM
Ground.
Line
Description
for
memory
for
memory
for
memory
for
memory
for
memory
for
memory
for
memory
for
memory
for
memory
for
memory
used
for
memory
used
for
memory
used
for
memory
used
for
memory
used
for
memory
used
for
memory
linetothe
from
6502
address
address
address
address
address
address
address
address
address
address
microprocessor.
interrupttomicroprocessor.
RAS.
CAS.
select
select
select
select for
select
select
select for
select
select
select
microprocessor.
expansion.
expansion.
expansion.
expansion.
expansion.
expansion.
expansion.
expansion.
expansion.
expansion.
expansion.
expansion.
expansion.
expansion.
expansion.
expansion.
microprocessor.
microprocessor.
for
memory
for
memory
for
memory
memory
for
memory
for
memory
memory
for
memory
for
memory
for
memory
Note:
Buffered.
Buffered.
Buffered.
Buffered.
Buffered.
Buffered.
Buffered.
Buffered.
Buffered.
Buffered.
Buffered.
Buffered.
Buffered.
Buffered.
Buffered.
Buffered.
locations
locations
locations
locations
locations
locations
locations
locations
locations
locations
connectedto74LS00
2000-2FFF.
3000-3FFF.
4000-4FFF.
5000-5FFF.
6000-6FFF.
7000-7FFF.
8000-8FFF.
9000-9FFF.
A000-AFFF.
B000-Bfff.
output.
64
Page 73
ADDITIONAL
By
this
permits
To
add
flexibility
the
PET,
enhanced
the
useofthese
To
communicate
BASIC
time,
the
the
outputordisplayofdata.
and
future
flexibility
a)
b)
c)
d)
e)
COMMANDS
userisprobably
to
the
PET
Commodore
of
data
extra
commands.
with
any
device,acombination
OPEN/CLOSE
PRINTS
CMD
INPUT*
GET#
familiar
computer
system,
products
interchange
Openorclose
Write
SameasPRINT*
listener
Read
PET
with
the
These
commands
several
will
take
between
data
from
on bus
data
from
accepts
use
of the
commands
are
commontoall
commands
advantage
the
PET
of
the
logical
PETtoI/O
but
after
I/O
one
character
of
the
and
peripheral
additional
file.
device.
leaves
executionofcommand.
devicetoPET.
from
INPUT
have
been
resulting
and
PRINT.
formsofBASIC.
addedtoclassical
extra
capability.
devicesispossible,
commandsisused:
IEEE
deviceanactive
I/O
device.
INPUT
BASIC
In
thanks
in
general,
to
INPUT/OUTPUT
In
ordertouse
consideration:
These
statement:
LOGICAL
Files
parameters
are
usedtostore
convenient
logical
storage
For
upon
file.Tothe
system
example,
requesttothe
havetoopenafile
PET
can
usea"read"
Whennofurther
COMMAND
the
additional
a)
Logical
b)
Device
c)
Secondary
d)
File-name
can
OPEN#LF,D,SA,FN
FILES
extension
PET
suchasmagnetic
imagine
that
PET
and
dataisrequired
PARAMETERS
commands
file
number
number
appear,
and
retrieve
of
this
operating
an
via
the
(D)
address
(FN)
for
example,
ideaisto
system,
tape.
external
IEEE
assignalogical
command
(INPUT#)
from
referred
(LF)
(SA)
data,asfor
regard
data
digital
bus.
Sometime
file
numbertorefertothe
which
the
voltmeter,
tointhe
when
using
above,
the
OPEN#
exampleinthe
any
device
might
voltmeter
uses
which
justaswell
is
set
during
the
the
logical
the
logical
four
parameters
commandinthe
caseofa
can
have
up
so
that
"voltmeter
voltmeter.
file
file
magnetic
receive
and/or
come
from,orbe
it
can
transmit
program"
Once
number
to
canbeclosed.
mustbetaken
formofthe
tapeordisc
generate
going
voltage
the
programmer
this
has
been
refer
to
the
voltmeter.
into
file.
A
dataasa
to,
a
readings
will
done,
The
More
generally,
the
advantages
a)
Every
device
canbeassociated
withinaprogram.
b)
Multiple
by
meansofdistinct logical
tobeusedinthe
the
PET.
c)
Oncealogical'file
offeredbythe
number
with
files
withinasingle
newly
secondary
its
developed
number
own
useoflogical
address
unique
file
numbers.
has
dev
disc
been
65
ice
logical
canberefered
This
storage
definedinan
files
are:
combination
file
number
to
approach
system
is
for
OPEN
Page 74
statement,
in
the
need
address
withinaprogram,
following
for
further
(where
only
this
input/output
statements.
restatementofdevice
used)
and
file
name
(where
number
number,
needbeused
This
eliminates
secondary
used).
the
Althoughitis
system
that
range1through
DEVICE
All
for
All
the
cases,aspecific
to
On
of less
hastokeep
canbecontrolledbythe
devices
the
following
other
device
communicate
many
expensive
permissabletoidentify
255.
NUMBERS
which
devices
which
IEEE
the
peripherals:
Number
Default-1Cassette1panel
are
will
number
using
devices,
products,bythe
and
trackofthe
PET
Device
automatically
have
the
the
files
that
PETatone
communicates
Device
0
Keyboard
2
Cassette2add-on
3
Video
screen
assumedbythe
been
allocatedanumber
wouldbeallocatedtoeach
parallel
allocationofthe
IEEE-488
connectionofjumpers.
use
many
logical
are
currently
timeisten.Alogical
with
are
mounted
in
PETtobe
within
IEEE
bus.
device
numberismadebymeansofa
filesina
useinthe
file
IEEE
the
devicetoallow
given
program,
program.
number
range4through
The
canbeany
The
first
and
the
greatest
fourofthese
controlistransferred
30.
PET
andaparticular
the
PET
operating
numberoffiles
integerinthe
are
Exceptinspecial
device
switch,orin
the
case
to
SECONDARY
The
conceptofsecondary
The
useofa
modes.
ADDRESSES
secondary
For
example,ina
address
address
PET
Secondary
Address
permitsanintelligent
printer,
Operation
Default-0Normal
1
2
3
Set
variable
4
Use
5
Byte
In
short,bychanging
operating
particular
canbeobtainedbyconsulting
The
characteristics
secondary
PET
tape
units
the
secondary
canbetotally
address
haveaspecial
Secondary
Address
conventions
Operation
the
Default-0Tapeisbeing
1
Tapeisbeing
2
Tapeisbeing
tape"
maybenewtothose people
who
peripheraltofunctioninany
there
are
six
secondary
addresses:
printing
under
format
data
from
lines
expanded
data
address
manual
set of
diagnostic
for
programmable
changed,ifso
which
for
secondary
opened
opened
opened
header
being
statement
control
PETtoformat
per
page
messages
character
usedtocommunicate
desired.
mustbefollowed.
that
particular
address
for
for
for
forced
device.
rules:
"read"
"write"
"write"
when
the
have
never
statement
with a
Manyofthe
Specific
withan"end
file is
given
IEEE
closed.
worked
with
the
oneofa
physical
devices
dataonthese
of
device,
have
conventions
IEEE
bus.
number
their
of
its
own
Page 75
The
secondary
FILE
NAMES
In
random
filesismandatory.Inthe
facilitates
address
storage
the
devices
identification
can
have
values
where
caseoftapes,afile
thereismore
of
tapes.
over
nameisdesirable,
the
range0through
than
one
filetobe
evenifthereisonly
31.
accessed,
the
useofnamestoidentify
one
fileonthe
tape,
since
it
For the
Whenafile
Assume
be
three
unwanted
It
For
ordertoascertain
TAPE
The
are
It
by
Note
think
Becauseofthe
and
simultaneously
two
cassette
nameissearched
thataneight
searched
consecutive
is,
therefore,
other
CASSETTE
PET
specially
can
also
meansofa
that
that
eject
for
file
names
devices
devotes
modifiedsothat
sense
single
the
same
you
pushed
tapes.Hemust
tape
withanabbreviated
characters
advisabletospecify
which
the
OPERATION
special
when
switch
switchisusedtosense
typeofmechanism
with,orbefore
unitsofthe
for,itis
character
will
suchasCOUNTorCOUNTRY,aswellasCOUNTING.
use
named
specific
requirements
FOR
attention
the
the
PLAY,
mountedinthe
the
PLAY
also
put
the
PET,afile
matchedonan
file
name
COUNTING
name
suchasCOU.
thenbeopened
the
complete
files,
the
individual
for
file
FILES
to
the
two
tape
PET
has
control
REWIND,orFAST
tape
all
three
button
and
will
usedinthe
the
unit
into
PLAY
buttonispressed.
respond
tape
the
name
maybeany
ascending
was
specified
The
and
positioned
file
nameinordertoavoid
description
name
usage.
cassette
over
unit.
write
units
the
motor
FORWARD
buttons:ifanyofthe
accordingly.
unit,
the
modebypushing
combination
character
first
file
on.Inprinciple,
of
that
canbeattachedtoit.
movementofthe
buttons
user
must
basis.
when
writing.
header
errors.
the
device
have
been
threeispushed,
rewind,
the
ofupto
thatisfound
128
characters.
If
desired,
with
this
could
this
could
these
include
shouldbeconsulted
The
tape
units
cassette.
pushed;
fast
forward,
record
thisisdone
the
stop,
button
either
PET
will
load
in
The
PET
has
total
control
to
engage
Messages
functionofplayorrecord.
The
two
of
data
control
FILE
The
data
reliability
To
accomplish
of
the
software,itis
redundant
In
ordertocorrect
characteristics
individual
the
motor.
displayed
tape
unitsofthe
from
cassette
for
cassette#2andacommon
RECORDING
structure
of
dataistotally
data
start/stop
TECHNIQUE
embodiedinthe
recording.
this,
possible
storedinthe
for
of
tapes,aspeed
over
throughout
Logic
PET
#1,
the
the
PET
records
repeated
for
most
(a),
the
characteristics
the
movementofthe
thfc
program
dictates
are
handled
the
independently,
readingofdata
write
tape
files
dataattwo
andbymeansoferror
audio
dropoutstobe
second
fact
data
block.
that
tape
units
correlation
on
the
tape
tape
will
tell
the
times
from
line.
will
techniqueisused
when
cassette
ensure
audio
recordatdifferent
and
syncronize
67
once
the
appropriate
user
whenitis
the
user
should
and
the
various
#2,
motor
the
maximum
frequencies
Ghecking
correctedbythe
in
two
techniques
speeds,
during
correctly
buttons
necessary
rewind
control
controlofcassette
memory
operating
reading.Tocorrect
utilization
consecutive
incorporated
and
between
have
been
for
himtoinitiate
and
fast
forward.
lines
permit
the
#1,
and
blocksofdata.
in
the
system
(b),
each
utilizing
the
normal
for
blockontape,
pushed
the
reading
motor
maximum
All
PET
the
drag
the
a
Page 76
single
tape.
writing
leader.
An
record
checking,
exactly
an
data
The
whichissearched
toneiswritten
Varying
about
Individual
FILE
HEADERS
important
more
identification
blocks,
PET
lengthsoftone
ten
secondsofthe
assumption
than
the
first
the
sameasthe
character
file
headers
allows
forupto
tape
one
physical
for
between
blocks.
are
usedatthe
toneoneach
blocks
are
separatedbyshorter
underlying
fileofdataona
data
recordedontape
normal
and
data
which
and
128
enables
endoftape
charactersofa
matchedonin
This
signalisusedtosyncronize
beginning
openingofa
the
tape
system
tape.Inordertofacilitate
for
block,
except
the
headers.
the
that
operating
file
nametobe
various
and
between
file,
the
PET
tone
durations.
design
was
this
any
operationisa
the
first
characterofevery
systemtodifferentiate
storedinthe
OPEN/CLOSE
both
position
the
data
blocksofthe
automatically
that
the
user
would
andtoallow
file
header.
for
This
blockontape
between
file
header.
options.
and
speedofthe
tape.
corrects
often
proper
for
normal
want
label
file
header
program
blocks,
Thisisthe
By
to
looks
name
TAPE
tape
BUFFERS
Another
systembypermanently
bufferislocatedatdecimal
address
Data
either
buffer.
Tape
the
header
written
MULTIPLE
In
a
tapeisat
tape"
In
to
is
basic
premiseinthe
independently
826
for
cassette
files
are
accumulatedinthe
writtenontape
Tape
file
headers
buffers
memoryinwhich
ordertohave
indication.
the
caseofdata
the
userina
closed.
are
not
foraprogram
onto
tapeinthe
FILES
its
end.Itis,
files,an"endoffile"
status
designofthe
of
whatisoccurringontapeata
assigningablockofmemoryasa
address
#2.
The
for
write,orif
and
usedinthe
the
program
file
contains
usual
filesontape,
therefore,
wordonreading;
tape
operating
given
system
moment.
data
634
for
tape
file
headeriswritten
tape
buffer
the
all
data
blocks
caseofprogram
resides.Inordertoaccomodate
the
beginning
formoftwo
the
important
markerisappended
the
until
programisreading
are,
consecutive
user
needs
that
"endoffile"
#1,
followedbya
into
192
characters
therefore,
files,
since
and
ending
redundant
the
abilitytoadd
the operating
after
markerisautomatically
was
Thisisaccomplishedinthe
buffer
tape,
192
these
address
for
the
buffer
are
the
next
characters
are
written
the
variable
for
blocks.
filestoa
system
the
last
that
the
user
would
each
cassette.A192
192
character
first
and
then
exceeded,
blockofdataisread
the
givean"endoffile"
data
then
long.
onto
the
memory
program.
tape
and
character.
inserted
wanttowrite
bufferatdecimal
writtenontape.
the
contents
tape
location,
The
full
also
Thisisavailable
whenawrite
operating
character
are
into
the
from
the
file
program
know
and
when
"end
file
is
of
In
the
caseofprogram
signifies
To
is
encountered
found"tothe
byan"endoftape"
the
endofthe
signify
that
the
endofthe
duringasearch
user.Atypical
headerasillustrated
files,
because
program.
tape
for
multiple
all
dataisalways
has been
files,
the
file
tape
in
containedina
reached,aspecial
PET
automatically
could
contain
the
exampleoffigure
68
separate
stops
firstadata
single
file
the
file,
7.14.
.
block,
headeriswritten.
tape
thenaprogram
the
endofthe
and
indicates
When
"file
file,
block
this
not
followed
Page 77
Data
file
Program
file
10
secondsofleader
192
character
2
secondsofleader
192
character
2
secondsofleader
file
header
data
block
I
Last
blockofthis
10
secondsofleader
192
character
I2secondsofleader
10
byte
file
file
header
block
block
LOGICAL
These
a)
b)
c)
These
OPENING
In
ordertotell
donebythe
FILE
operations
Open
the
Read
data
Close
the
steps
FILES
Figure
I/O
OPERATIONS:
GENERAL
canbesubdivided
file
-tell
the
PET
everythingitneedstoknow
from,orwrite
file-allow
are
discussedindetailonthe
BASIC
following
about
statement:
datatothe
the
PETtoclearupthe
the
file
OPEN
logical
32K
byte
program
optional
7.14.Anexampleofmultiple
into
three
steps:
logical
files.
following
you
wanttooperate
file,
device,
block
2
secondsofleader
192
end
of tape
device
and
pages.
on,itis
secondary
characters
header
file
structure.
about
the
file.
terminate
first
address,
the
necessarytoopen
file
active
name
file.
the
file.
This
is
More
specifically,
then
the
device
communicated
the
numbertowhich
during
statement
consistsofthe
the
the
interaction
command
fileisassigned,
of
BASIC
with
69
then
the
file,
OPEN
the
and
followedbythe
secondary
last,
the
logical
address
data
nameofthe
file
number,
(if
any)
file
(if
any).
Page 78
This
statement,orexpression,isinterpretedbyBASIC,
numbers,
The
deviceinpreparation
The
A
file
storage
device
file
keyword
device
nameisoptional,
unit.
numbersorsecondary
devices
OPEN
numberisoptional;ifnot
suchasdiscs.
and
the
fora"read"
though
address
logical
file
numbers
(INPUT#)ora"write"(PRINT
entered,
preferred,
for
the
the
and
could,
data.
This
capabilityisextremely
are
essentialinordertoopenafile;
default
tape
value
units:
however,aname
therefore,
#).
"1"
willbeused.
wouldbeessential
use
computed
useful
logical
when
thatisaddress
file
handling
a
foradisc
EXAMPLESOFOPEN
The
statement
OPEN
Parameter
(LF)
(D)
(SA)
(FN)
Similarly,
OPEN3is
Parameter
(LF)
(D)
(SA)
(FN)
IfaPET
printerisassigned
Parameter
(LF)
(D)
(SA)
(FN)
STATEMENTS
1,2,1isinterpretedbythe operating
Logical
Logical
Tape
A
interpretedassaying:
Logical
Logical
Tape
No
"4"
Logical
Logical
Printer
File
file#1has been
file#1has
unit#2has been
file
name
has
file#3has
file#3
has
unit#1has
file
name
referred
as a
device
file
file
has
name
number,
#12
#12
been
not
applicable
been
not
been
(F)
been
been
been
to
has
been
has
been
instructed
systemassaying:
opened
assignedtotape
instructedtowriteontape
assignedtothe
opened
assignedtotape
instructedtoread
then
OPEN
opened
assignedtodevice
to
unit#2
tape
record
unit#1(default
from
tape
(default
12,4,1isinterpreted
#4
print
under
format
statement
"1")
"0")
as:
control
LOAD
A
special
The
"load".
automatically
header.
At
the
caseofthe
operating
This
system
OPEN
read
Most
reading
endofthe
load
causes
from
OPEN
commandisthe
automatically
the
the
device
errorsonthe
generatesanOPEN
loading
devicetosearch
and
loaded
first
pass
cycle,achecksum
LOADofa
LOAD
name,
into
memory
through
error,ofthe
70
named
device
file:aLOADisdone
number
using
the
foraprogram
startingatan
that
program
total
programismade.Ifa
with
appropriate
name.
are
automatically
secondary
After
the
address
specifiedinthe
checksum
the
following
addresses
statement:
for
programisfound,itis
file
fixedonthe
second
error,orif
an
pass.
Page 79
uncoverable
the load
If
the
program
initializing
If
the
LOADiscalled
loaded
from
the
programs.
The
only
read
error
program.
load
all
variables.
into
the
space
previous
program.
restriction
occurred,
was
from
fromaprogram,
usedbythe
on
thisisthat
the
direct
previous
This
allows
all
operating
mode,
then
the
system
the
clear
the
PET
program,
for
one
programtocall
called
programs
automatically
function
treats
but
is
this
LOADasan
the valuesofallofthe
prints
performed
another
must
fitinthe
same,
7LOAD
at
the
endofthe
overlay.
variables
and
pass
parameters
or less
ERROR
and
stops
load,
The
new
program
are
maintained
to
the
spaceasthe
first
thereby
is
called
program.
Because
program
same
The
programsofappreciable
VERIFY
This
The
data
pass
again
SAVE
SAVE
BASIC
and
effect
combination
very
instruction
command
does
errors
beforeitis
also
totally
several
is
obtained
replaces
subroutine
of
the
useofnamed
isaspecial
causes
not
get
occur,
performsanautomatic
BASICtogo
loaded
the
PET
lost.OnVERIFY,
Code
4
8
16
32
with
some
complexity.
into
memory,
will
Meaning
Short
Long
Checksum
Checksum
the
current
overlays,
loss
program,itis
however,byincluding
of
speed.
files
and
overlays
caseofLOAD.Itshould
through
type
out
the
block
block
open
all
the
but,
instead,
7VERIFY
status
word
error
on
ERROR
and
close.
SAVE
name,
stepsofa
gets
ERROR
has
the
tape
on
tape
The
SAVEisspecifiedbythe
device
not
directly
the
main
allows
the
be used
after
writingofvery
program
compared
which
following
number
with
means
possibletohaveasingle
program
with
each
main
overlay,
'
large
structured
every
program
LOAD,
with
memory.Ifeither
that
the
program
meanings
SAVE.
the
exception
firstorsecond
shouldbesaved
statement:
that
the
the
p
i
I
I
/
If
the
physical
header
ending
If
program
The
If
againtogive
positioned
IEEE-488
In
In
two
and
opensatape
address.
the
deviceisan
file.
programisthen
the
SAVEison
the
for
SPECIAL
the
tape,
the
ordertomore
bytesofdataona
deviceisoneofthe
file
written
tape,achecksumiscomputed
redundant
the
next
FEATURES
program
efficiently
device,aspecial
directly
recording.Atthe
data.
beginning
use
SAVE
two
tape
with
the
appropriate
from
and
ending
the
and
retrieved
its
from
units,
the
name.
open
messageissent
memory
and
endofthe
address
data,
the
those
71
operating
The
locationstothe
also
saved
program,
are
positions
system
file
headeriswritten
indicating
and
the
storedinand
addressofthe
ohaLOAD.
automatically
that
tapeorthe
then
the
whole
tapeisautomatically
retrieved
programissentasthe
initiates
with
the
beginning
the
PETissending
IEEE-488
from
bus.
programiswritten
stopped
the
tape
a
tape
file
and
a
and
header.
first
Page 80
If
the
that
If
the
a
file
specifiedinthe
secondary
OPEN
OPEN
the
deviceisan
OPEN
nameisspecified,
CONSIDERATIONS
command
does
OPEN
address
selectsadevice
IEEE-488
not
specifyafile
along
specifiedinthe
device.
the
operating
withasecondary
which
name,
system
OPEN
hasavalueof4ormore,
then
nothingiscommunicatedonthe
sendsalisten
address
statement.
attention
whichistheORof
the
operating
IEEE-488
sequencetothe
hexadecimal
system
assumes
bus.
However,
device
"FO"
and
if
number
the
Commodore-supplied
address
latertothe
TAPE
tape
OPEN
The
for
Note
displayed.
previously,
the
OPEN
The
for
and
also
open
FILE
OPERATION
files
canbeopened
a)Inordertowrite
b)Inordertoread
FOR
WRITEONTAPE
flow
diagramofFigure
writeontape.
a)
OPEN
b)
SAVE-writeaprogram
for
thatifthe
If
the
thennomessage
current
flow
programisnot
FOR
READ
diagramofFigure
readingontape.
a)
OPEN
b)
LOAD
for
program
peripherals,
the
file
name,
file.
MODES
for
from
from
tapetothe
7.15
The
initial
write-data
tape
fileisopened
tape.
fileisopened
disturbed.
FROM
PETTOTAPE
7.16
The
initial
read
data
tape.
into
memory.
suchasthe
whichisthen
two
distinct
the
PET
FROM
outlines
block
shows
tape.
under
appearsonthe
outlines
block
purposes:
onto
tape.
PET.
PET
the
that
directly
from
program
the
shows
floppy
transmittedtothe
PET-user
there
control,
screen.Inthis
PET-user
that
disc
storage
interaction
are
two
waysofopening
the
keyboard,
and
the
manner,
interaction
there
are
two
PLAY
system,
listening
and
then
the
and
any
and
waysofopening
will
use
deviceinordertotransfer
PET
function
the
file:
message
RECORD
display
PET
function
buttons
material
the
this
secondary
when
openingafile
WRITING
NAME
are
placed
when
openingafile
file:
data
is
depressed
there
by
Note
thatifthe
SEARCHING
of
the
loaded
If
the
fileisopened
previously,
program.
Initialization
fileisopened
FOR
program
no
messages
NAME
are
under
of
directly,
and
FOUND
initialized.
program
appearonthe
the
BASIC
thatisfrom
NAME
control
video
variables
the
are
displayed.
and
provided
keyboard,
that
If
LOAD
the
then
was
PLAY
screeninordertodisturb
does
not
occur.
72
the
messages
used,
then
the
button
material
had
been
displayedbythe
PRESS
PLAY,
BASIC
pressed
variables
current
Page 81
PRESSPLAY
AND
RECORD
OPEN
—**
in
Tape
PLAY
and
RECORD
Wait
Switch
Closure
for
Header
Buffer
Down?
for
WriteorSAVE
Name
Buttons
Program
Direct
Figure
7.15.
OPEN
for
write
OP=operating
from
system
PET:
PRINT#,CMDorSAVE.
takes
over.
Message:
WRITING
Header
Goes
to
Tape
NAME
73
Page 82
Di
rectos.
or
Program
Operation
Direct
Message:
SEARCHING
FOR
NAME
Direct^Direct
or
Program
Operation
Program
Read
Full
Program
to
Memory
in
Message:
LOADING
NAME
1
Figure
7.16.
OP=Operating
OPEN
system
for
readtoPET:
takes
74
INPUT#orLOAD
over.B=
BASIC
takes
over.
Page 83
DATA
The
useofthe
INPUT:
GENERAL
word
"input"inthis
context
implies
inputofdatatothe
PET
from
any
device.
INPUT#-String
INPUT#isthe
statement
Where
A,A$,B,
filetothe
Because
commas,
are
automatically
Itisnot
always
specified,
DATA
If
various
ERROR
thereisany
string
Exampleoflnput#
and
Variable
command
format
is:
usedtoinitiate
andB$are
operating
the
rules
terminate
system
for
the
fields,
deleted.
possibletomix
only
numeric
messageisdisplayed.
ambiguity
manipulation
datainthe
about
Statement
IfXrepresentsaseriesof50
button
oneata
has
just
been
time
and
display
10
OPEN
20
FORK=1to
30INPUT#1,X
40
PRINT
50
NEXT
60
CLOSE
1,1,0"VECTOR"
X
K
1
depressedonthe
50
Input
data
INPUT#
numerical
one
BASIC
nulls,
both
the
commandstoprocess
numbers
themonthe
logical
and
character
interpreter
preceeding
numeric
data
coming
number
string
variablestobe
ata
time.
applytothese
blanks
and
form
in,
storedona
tape
unit#1.
video
screen.
Open
logical
"read".
Read50numbersatone
Display
When50numbers
Look
numbersonvideo
from
I/O
devicestothe
file,
A,A$,B,B$,etc.
inputted
input
statements,
(exceptinstrings),
alphabetic
dataonthe
and
expectedbyBASICisaccepted,
the
user
the
data
tape
file
Then
the
file
#1.
Assign
for
physical
have been
should
named
input
onlytostrings
into
the
appropriate
VECTOR
following
program
filetocassette1.Open
file
named
time
from
cassette
screen
read,
close
operating
(read)
from
all
carriage
other
control
I/O
device.Ifa
otherwisea?BAD
variables.
andweassume
will
read
VECTOR.
1.
logical
system.
the
selected
returns,
characters
numeric
and
then
that
the
the50numbers
tape
for
file
#1.
The
logical
field
is
use
the
PLAY
GET
#-CHARACTER
Not
all
devices
data
and
with
data
In
addition,insome
they
are
transferedtothe
time,
puttingacharacterina
TAPE
INPUT
When
INPUT#orGET#
called,
As
bufferisempty,
each
into
the
reading
which
buffer
transfer
combinations
formats
from
fromalogical
initiates
characterisrequested
the
and
TRANSFERS
dataina
which
which
are
acceptabletobasic,
cases,itis
system.
the
tape
file,
tape
input.
tape
input
then
transfers
form
whichisaccceptable
BASIC
desirable
field
ignores
for
GET-
fetches
specified
GET#
the
data
device
routine
from
the
which
BASIC,itis
suspends
next
directlytoBASIC.
and
although
not
the
programmertohave
from
the
following
logical
comestothe
was
opened
fetched
the
many
all
do.
IEEE-488,ortape
the
GET#.
file,
field
user
I/O
for
readontape1or2,a
from
user
program
charactertoBASIC.Ifa
75
Thereisa
IEEE
devicesdocorrectly
immediate
accesstocharacters
device,asingle
THE
FORM
independent.
the
appropriate
and
read
IS:
Each
reads
the
error
occurs,itis
tape
seriesofbinary
respond
characterata
time
BASIC
special
data
subroutine
buffer.
When
block
notedinthe
starts
the
from
tape
as
on
is
Page 84
status
When
and
At
tells
word.
the
carriage
the
endofa
the
endoffile
returns
endoffile
markisencounteredinthe
command,
operation
are
forced
BASIC
buffer,
automatically
calls
another
thatacommandiscomplete.
out
routine
the
until
the
which
endoffile
commandisfinished.
reinitializes
positionofthe
the
inputtobe
status
wordisset
the
keyboard
on
and
IEEE-488
All
the
secondary
attention
indicatingasingle
characterishandedtoBASIC
IEEE-488
waiting
will
terminated
If
during
endofinformationinthe
has
termination
IEEE-488
INPUT
accumulates
carriage
DEVICE
address
sequence,
routineiscalled,itwillgothrough
foratime
automatically
the
the
been
currently
bus,
BUFFER
dataistransferred
return.
INPUT
GET#
input
outtooccur.Ifthe
terminate
sequence.
courseofreading
subroutine
thereby,
LIMITATIONS
these
SEQUENCES
commandsgothrough
initiation
which
the
character
operating
routineiscalled,
was
PET
establishes
has
the
status
under
which
freeing
from
characters
the
same
which
specified
been
and/ortothe
sequence;
the
word
reinitializes
the
the operating
intoan80
for
that
logical
itselfina
received.Ifthe
other
the
same
bus
does
not
givingaread
character,
and
has
bus
will
been
the
for
the
column
the
IEEE-488
continuetoreturn
terminated.Atthe
devicetothe
next
system
sequence.
sendsatalk
fileinthe
listener
DAVisreceived
program
sequenceofgettingasingle
respondin65
When
attention
OPEN
mode
and
calling
errorinthe
routine
the
milliseconds,
senses
carriage
endofthe
keyboard
the
commandisfirst
sequencetothe device
sequence.Atthe
attemptstowait
within65milliseconds,
IEEE-488
status
an EOI
returns,
and
sendsanuntalktothe
command.
one
input
buffer.
characterata
This
buffer
time,inordertoedit,
mustbeterminated by
encountered,
endofthe
foraDAV
that
routine.
then
wordtoindicate
line,itwill
Each
time
character
the
IEEE-488
thatithas
indicate
until
the
command
BASIC
calls
while
and
signal
the
routine
the
it
a
BASIC
a
On
the
PET,
should
operating
supply
This
This
not
IfanI/O
without
DATA
The
PRINT#
The
that
system
off
and
constraint
means
more
that
than 80
device
running
OUTPUT:
useofthe
command
would
follow
Dataistransferred
specified
in
the
more
than80charactersberead,
variables
on.
mustbekeptinmind
carriage
returns
characters
sends
into
the
more
buffer
GENERAL
words
PRINT*
"print"
mustbefollowedbya
PRINT:
a
single
relevant
OPEN
are
overwritten.
when
The
PET
using
canbemadetofunction
tape
mustbewrittenontapes,
per
field
are
written
than80characters,
limitation.
and
"write"
PRINT*
character
statement.
referstodata
logical
at
a timetothe
Manyofthe
without
the
GET
logical
file
file
the
operating
and
disc
file
discs,orother
being
separatedbycarriage
command
output
number,
number,
physical
file
delimiters
canbeusedtobuild
from
and
data
device
system
will
malfunction,
againbyswitching
I/O
devicesinsuchaway
as
the
the
returns.
your
own
string
the
PETtoany
thenacommatoseparate
correlated
suchascommas
device.
with
the
logical
are
automatically
the
data
file
line
that
76
Page 85
deletedbyBASIC;
reading
by
which
back
inserting
will
force
insteadofwriting
PRINT#LF,A;B$;C$
which
withnodelimiters:
or:
which
or:
willbesent
AB$C$
PR\U7#LF,A;CHR$(44)B$;CHR$(44);C$
Pfl/A/r#LF,A'7';B$;'7';C$
will
A,B$,C$,CR
PRINT#LF,A
although
from
tapeoranother
a
CHR$(44)or","
as
output:
(Note:CRmeans
PRINT#LF,B$
PRINT#LF,C$
which
will
A
CR
output:
B$
CR
C$
this
does
I/O
between
returns
CR
between
not
greatly
device
that
fieldsorby
fields.
carriage
return)
effect
the
printing,
file
delimiters
only
printing
it
shouldberemembered
mustbeforced.
single
fieldsineach
This
that
forcing
canbedone
PRINT#
statement
when
Because
PRINT#LF,A,B
extra
An
Note:
equivalent
placeofPRINT,
token
ERROR
Examplesofthe
This
To
write
modified,ifthe
BASIC
skips.
always
has
several
formats
exceptiontothis ruleisthe
Although
characters
whenanattemptismadetoexecute
program
the
both
INPUT
and
does
when
will
10OPEN
20
FORK=1to
30
PRINT#5,K
40
NEXT
50
CLOSE
above
same
the
PRINT
not
processedbyBASIC.?#will
PRINT*
print
the
5,4,0
K
seriesofnumbersona
logical
outputstoany
skip
characters
tape
where
INPUT#
AND
statementsdoin
PRINT#
devicesasthoughitwere
between
the
first
commands
BASIC,
applytoPRINT*.?#and
it.
Statement
seriesofnumbers
50
5
file
numbers
1,2,3...5O,
Open
logical
printer)innormal
address
Print
the
Close
logical
cassetteintape
were
chosen:
outputtingtothe
the
valuesofA
andB,while
A;B
skiponoutputissupressed.
operateinvirtually
the
abbreviated
PRINT*
look
"0".
are
like
oneata
file
#5.
print
seriesof50
file
#5.
unit
command?which
recognized
PRINT*
Assign
when
timeona
logical
mode
correspondingtosecondary
numbersonprinter.
#2,
only
the
the
and
reducedtotwo
listed
but
PET
printer.
file#5to
OPEN
line
screen,
does
not
have
same
wayastheir
can be
used
different
gives
7SYNTAX
device#4(PET
would
havetobe
any
in
10OPEN
5,2,1
Open
logical
#2)
withawrite
correspondingtosecondary
77
file
#5.
Assign
without
logical#5to
"endoftape"
address
device#2(tape
designation
T.
unit
Page 86
20
FORK=1to
30
PRINT#5,K
40
NEXT
K
50
CLOSE
In
the
above
a
time.
the
buffer
programisallowedtoproceed.
I
EEE-488
The
PRINT*
output.
to
the
the
IEEE
cassette
When
the
capacityofthe
contents
BUS
OUTPUT
command
The
first
stepinthe
physical
device
bustothe
example,
writtentotape.
causes
that
physical
50
5
the
bufferisexceeded,
BASICtocallanoutput
commandisthat
was
chosen
device
Record
Close
data
wouldbeaccumulatedina
the
seriesof50
logical
file
then
The
bufferisinitialized
subroutine
the
PET
reassigns
for
the
logical
andasecondary
fileinthe
addressd
numbersontape.
#5.
192
character
data
entryissuspended,
to
acceptupto
which
its
normal
open
routine.Alisten
specified
192
initializes
output
for
that
buffer
characters
one
character
the
tape
started,
and
anIEEE-488
from
the
device
screen
then
commandissent
logical
fileinthe
at
and
the
for
device
on
OPEN.
BASIC
character
When
sendsan"unlisten"
the
This
BASIC.Toaccomplish
and
CMD
Normally,
busisunlistened.Insome
facilitate
the
a
The
output
the
then
hands
over
BASIC
whole
unlisten
the
COMMAND
endofthe
listener.
operating
video
has
bus
sequence
previous
each
this,
the
device
for
screen.
one
characterata
the
bus
with
finished
commandtothe
for
the
next
also
this,
characterissent.
print
command
special
data
transfer,
system
continuestotreat
BASIC.
More
PRINTorLIST
specifically,
timetoanother
the
PET
actingasa
the
PRINT*,
another
entire
operation.
sendsanEOI
each
characterisstoredina
deals
only
instances,itis
command
the
CMDisprovided.
unlisten
the
talker
subroutineinthe
bus
and
restores
signalonthe
with
one
logical
advisabletohave
CMDisvirtually
routineisnot
the
last
devicetobe
commands
CMDofthe
are
printer
subroutine
and
all
which
addressed
operating
the
primary
bus,
along
with
buffer
priortotransmissionbythe
device
called,
then
directedtothis
device,
andatthe
more
than
thereby
commandedbythe
followedbyLIST,
proceedstotransfer
devices
systemiscalled
addresstothe
the
one
deviceonthe
identicaltoPRINT*,
leaving
primary
responding
screen.
last
character
endofthe
the
deviceonthe
CMDasthe
device,
resultsinhard
and
sent
IEEE
command
bus;inorder
except
rather
that
listeners.
the
PET
This.frees
from
routines
entire
to
that
at
bus
as
primary
than
to
copy
78
Page 87
printed
terminate
listing,
insteadofa
bus
operation
video
for
the
screen
device,aPRINT#isrequiredtoterminate
listing.
However,
since
neither
the
CMD
a
CMD
nor
LIST
command
command.
Examplesofa
To
list:
CMD
Command
OPEN
CMD
3
3,4
LIST
to
print
and
writeadiscatthe
*CMD
PRINT#15,A,B,C
will
resultinA,B,
To
monitoraninput
**CMD
INPUT#15,A,B,C
This
will
resultinthe
are
being
transferred.
CLOSING
Any
required,
shouldbekeptinmind:
FILES
logical
files
andinthe
a)Ifthe
PET
b)Ifa
mark
loaded
ended,
previous
3
andCbeing
device:
3
data
which
have
caseoftapeordisc
total
operation
logical
willberecordedatthe
into
andifthe
recording,
where4is
will
list
same
time:
where
where15is
(previously
storedonthe
from
the
floppy
been
opened
floppy
turnonprinter
read
being
duringaprogram
files,
mustbeclosed
numberoflogical
will
result.
file
assignedtoa
endofthe
memory,
the
PET
will
unwanted
it
will
and
alsoberead
the
printer
just
the
logical
file3is
the
opened),
but
also
from
floppy
transferred
files
currently
tape
unitisnot
physical
havenowayofknowing
erroneous
into
device
sameasthe
opentothe
floppy disc
being
toA,B
should
before
logical
displayedonthe
andCbut
preferably
the
exceeds
closed,no"endoffile"
tape
file.Ifthis
dataispresent
memory.
number
screen,
exceptonthe
printer.
file
number
printer.
also
being
be
closed
program
ten,
then
ends.
loss
tapeisthen
the
file
from
printer,
printedasthey
whennolonger
The
following
of
has
a
EXAMPLEOFA
To
close
any
If itisrequiredtoclose
TAPE
*Mustbegiven
**Need
FILE
Ifafile
recordedinthe
If
forced
had
during
OPEN
outonthe
notbegiven
CLOSE
file,
the
CLOSURE
been
openedonthe
next
the
"endoftape"
cassette.
each
time
because
each
time,
STATEMENT
following
logical
data
simple
file
character,
PRINT#
more
code
statementissufficient:
number5,then
tape,
there
then
option
unlistens
canbeincluded
CLOSE
the
was
the
logical
this
CLOSE
are
two
tape
chosen,an"endoftape
bus.
between
79
file
becomes:
5
operations
bufferisforced
instructions.
that
occur:an"endoffile"
out
onto
the
cassette.
file"
header
blockisalso
marker
is
Page 88
IEEE-488
For
with
OPENissent.
NAMED
IEEE-4888
the
devices,
special
This
DEVICE
secondary
allows
CLOSURE
which
were
addressofthehexadecimal
devices
opened
suchasdisc
with
file
names,aspecial
EOOR'ed
filestobe
closedbythe
listener
with
the
peripheral
command
secondary
address
controller.
sequence,
from
the.
ERROR
The
format;
Because
informing
STATUS
In
DETECTION:
basic
conceptofthe
reading
I/Oistotally
the
user
WORDS
ordertofacilitate
GENERAL
PET
and
writingontapes,
free-form,
when
transmission
INPUT/OUTPUT
operating
itismost
systemisthat
discs,
and
important
errorsorendofdata
operation
printers,
that
error
detection,
whichabyteinmemoryismanipulatedbyeachofthe
the
programmeratany
for
all
operations
Table
7.17
shows
operations,
tape
timebycalling
andaspecific
the
errorsasa
verify
and
ST
Bit
Position
0
1
2
3
4
5
6
7
meaning
functionoftheSTword
load
operations.
ST
Numeric
Value
-128
1
2
4
8
16
32
64
the
function
for
the
Cassette
Short
Long
Unrecoverable
read
Checksum
error
Endoffile
Endoftape
ST.
individual
Read
block
block
error
the
user
willbeallowedtooperateina
in
the
manner
the
operating
conditions
the
PET
I/O
operations
Each
bitinthe
I/O
device.
value
for
the
IEEE
R/W
Time
out
on
write
Time
out
on
read
EOI
line
Device
not
present
thatismost
system
comfortable
should
occur.
uses
the
"status
for
the
PET,
and
canbesampled
staus
word
hasageneral
tape cassette
+
Short
Long
Any
mismatch
Checksum
error
End
tape
units.
Tape
Verify
Load
block
block
of
have
means
word"
concept
IEEE
read/write
free-form
for
him.
of
in
by
meaning
IEEE
DEVICE
There
the
are
basically
respondtoan
bit(7or
bus
-128).
physical
device
The
not
present
second
ERRORS
three
errors
attention
The
sequence.Ifthis
PET
also
correctlytothe
deviceisnot
indication.
error
occurs
during
Table
7.17.
Status
Word
(ST)
tape
cassette,
that
can
terminates
attention,
unit
occur
duringanIEEE-488
occurs,
the
current
but
when
and
the
presentasindicatedbyhaving
the
processoftransferring
values
IEEE
bus
IEEE-488
program
the
PET
goestowrite
NRFDorNDAC
80
read/write
correlated
with
errors.
transfer.
subroutine
with
7DEVICE
the
datatothe
device.
First,
sets
the
NOT
first
low,
the
entire
bus
DEVICE
PRESENT
NOT
ERROR.Ifthe
charactertothe
the
PET,
again,
The
bus
does
does
PRESENT
bus
gives
not
respond
not
and
a
Page 89
in
the
appropriate
write
error
indicationisgiveninbit
The
third
error
milliseconds;
sets
the
bit6oninthe status
times
occurs
bit1of
when
the
and/orifit
during
status
ceasestorespondbymeansofbringing
readonan
wordisthen
word
0.
IEEE-488,
set.
Whenever
and
continuestoforce
the
IEEE
the
EOI
carriage
NRFD
and
NDAC
device
has
not
sent
DAVinless
lineisencountered,
returns.
both
high,
a
than
65
the
subroutine
TAPE
The
EXAMPLESOFST
As
printing
alsoaseriesoferrors
UNIT
ERRORS
cassette
only
encountered
block.
2)
encountered
block.
3)
first
becauseitoccuredinthe
4)
computed
input
5)
encounteredina
6)
you
can
see,
to
and
checks
1)
SHORT
Possible
LONG
BLOCK
Possible
UNRECOVERABLE
blockofredundant
CHECKSUM
device.Iftheydonot
ENDOFFILE(64).This
ENDOFTAPE
USE
thereisno
reading
from
detectedoninputting
dataonread.
BLOCK
(4).When
before
the
cause:
expected
attempting
(8).When
after
the
expected
cause:
readingalong
READ
ERROR
over
the
status
the
(32).After
bytesinRAM
tape
record.
(-128).An
that
the
screen.
The
errors
readingablock
readingablock
ERROR
blocks-oranerror
same
match,
bitisset
EOT
PET
Thereisan
deleted
are:
from
numberofbytes
to
readashort
from
tape,aspacer
numberofbytes
load
fileasdata.
(16).Cause:
that
placeinboth
a
LOADorreadingofdata,achecksum
and
comparedtoa
this
bitisset.
when
record
was
detects
error'on
from
the
IEEE-488orfrom
blocks.
the
read.
for
the
writing
tape,aspacer
has
been
load
fileasa
had
been
more
than31errorsonthe
could
notbecorrected
byte
received
endofdata
writingoftapes,
data
outtothe
tape.
tone
read
from
data
tone
read
from
file
record.
was
from
mark
nor
IEEE-488
was
that
not
that
is
the
is
errors
detected
and
for
there
is
The
normal
of
status.Asthisisonlyasingle
statusisvery
This
code
file2is
In
this
A
correct
programming
transient.
100
INPUT#2,A
110INPUT#5,B
120IFST=0THEN
only
checks
forever
case,
lost.
Similarly:
.
100
INPUT#2,A
110
PRINT
120IFST=0THEN
theSTreflects
waytouseSTis
100
INPUT#2,A,B,C
110IFST=0
120IFST=64
technique
the
resultofthe
A
the
the
THEN
THEN
istofollow
INPUT#oraGET#byeitheratestorstorageofthe
byteofmemory
200
transferofdata
200
print
status,
folllowing:
200
300
rather
and
the
status
from
logical
than
the
resultsofreading
process
endofdata
81
normally
changesoneach
file5.The
processed
withnoerrors
value
new
I/O
command,
resultsofreading
#2.
logical
the
Page 90
Each
error
can
130IFST=2
nowbeprocessed
140IFST
AND
THEN
mask
400
with
the
THEN
time
out
withnoerrors
following:
Mask
represents
the
bit
being
tested
POLLING
One
respond,isto
TECHNIQUES
techniquetopoll
use
slow
the
routinesorlooponthe
finally
By
foreground
occassionally
DEFAULT
read
using
this
and
one
can
sampling
programbyuseofthe
poll
devices.
PARAMETERS
Statement
OPEN
OPEN
OPEN
OPEN
"DAT"
IEEE-488
INPUT#
from
devices
the
device;
INPUT#untilnoerror
process
technique,awhole
Parameter
Device
Secondary
address
1
1,2
1,2,1
1,2,1,
that
data
real
time
Default
~
Table
Equivalent
(Default)
Parameter
OPEN
OPEN^1,2,0
OPEN#1,2,1
OPEN=1,2,1,
"DAT"
information.
seriesofslow
clock
D=1
SA=0
Values
1,1,0
suchassampling
thenifthe
occurs.Ifthere
devices,
status
arenoerrors,
devices
(TI,TI$)
Value
7.18.
Default values.
and
the
Default
Cassette^1selected
On
tape
files
On
IEEE-488
secondary
Open
logical
no
file
Open
logical
no
file
Open
logical
no
file
Open
logical
file
named
name
name
name
addressissent.
Operation
file=1for
file=1for
file-1for
file=1for
"DAT"
which
indicates
canbeserviced,
INPUT#/timeout
Operation
open
for
devices,
cassette-1read
cassette^2read
cassette#2write
cassette~2write
time
the
read
no
take
many
out,
process
correct
along
error
minutes
to
other
data
has
been
with
running
sequence,
to
a
INTRODUCTIONTOTHE
This
bus
consistsof16
a)
The
data
2)
The
control
3)
The
management
Furthermore,
the
IEEE
bus
a)
Talkers:atany
datatothe
b)
Listeners:asmany
simultaneously
c)
Controller:
Table
IEEE-488
signal
BUS
lines
that
transmission
bus
bus
can
support
given
data
bus.
devicesasrequired
from
the
the
PETisthe
7.19.
Exampleofdefault
are
divided
bus
three
classesofdevice:
moment,
only
bus.
only
controller
parameters.
functionally
one
deviceispermittedtotransmit
may
82
into
three
receive
data
allowedonthe
groups,
IEEE
bus.
those
are:
Page 91
BUS/DEVICE
The
line-pin
assembly
Certain
CONTROL
connections
board
physical
for
the12position,24contact
(see
Table
7-19).
limitations
a)
The
b)
The
c)
The
shouldbenoted
maximum
maximum
maximum
edge
For
further
advisable
interdevice
information,
when
bus
extension
spacingis5
please
connecting
from
meters.
numberofdevicesis15.
card
connector,
refertoFigure
devicestothe
the
PETis20
emanate
from
7.2
IEEE
bus:
meters.
the
PET
u
0
main
u
0
PET
Contact
Identifi
cation
1
2
3
4
5
6
7
8
9
10
11
12
A
B
C
D
E
F
H
J
K
L
M
N
Bus
DATA
MANAGER
TRANSFER
MANAGER
DATA
MANAGER
GROUNDS
IEEE
Label
DI01
DI02
DI03
DI04
EOI
DAV
NRFD
NDAC
IFC
SRQ
ATN
SHIELD
DI05
DI06
DI07
DI08
REN
GND6
GND7
GND8
GND9
GND10
GND11
LOGIC
GND
PET
Contact
Identifi
cation
1
2
3
4
5
6
7
8
9
1*0
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Label
Description
Data
INPUT/OUTPUT
Data
INPUT/OUTPUT
Data
INPUT/OUTPUT
Data
INPUT/OUTPUT
Endoridentify
Data
valid
Not
ready
for
Data
not
Interface
SameasPET
Service
Attention
Chassis
cable
Data
Data
Data
Data
Remote
groundinthe
DAV
NFRD
NDAC
IFC
ground
SRQ
ground
ATN
Data
ground
data
accepted
clear
reset
request
ground
and
shield
INPUT/OUTPUT
INPUT/OUTPUT
INPUT/OUTPUT
INPUT/OUTPUT
enable
(REN)
PET
ground
ground
ground
ground
(DI01-8)
LINE
LINE
LINE
LINE
IEEE
LINE
LINE
LINE
LINE
always
#1
#2
*3
*4
=±5
#6
*7
~8
0
D
U
D
0
U
i
I
U
Table
THE
DATA
This
busiscomprisedof8
slowest
one
byteata
Peripheral
differentiated
The
most
Foranexplanation
Data
All
possible
THE
TRANSFER
This
three
BUS
deviceinuseonthe
time,
bit
parallel.
addresses
and
from databyATN
significant
Transmission
bit
line
bus
bit
of
signal
Modes
patterns
BUS
controls
(MSB)ison
are
7.20.
IEEE
bus
group,
bi-directional lines
busata
control
abbreviations
validonthe
the
given
time
information
(true)
during
line
are also
their
DI08.
suchasDI-08,
data
bus
transfer
of
data
label
and
contact
that
transmit
controls
the
transmitted
transfer.
when
sending
over
the
data
83
identification
the
active
rateofdata
see
Figure
number.
low
data
transfer;
on
the
data
7.23.
datatodevices.
bus.
The
signals
signals
the
bus.
transmitted
D101-8.
The
modeoftransfer
They
are
are
used
is
in
u
0
Page 92
the
handshake
procedure
outlinedin7-21,
These
Note
See
The
Whenatalker
ensure
The
The
interconnection
The
showninthe
signals
that
Table
Handshake
are:
a)
b)
c)
the
talker
7-23
for
NRFD
NDAC
DAV
originates
detailed
Procedure
transmits
that
the operationissuccessful.
essential
transferofdata
functionofthe
a)
All
listeners
b)
That
thereisvalid
c)
That
the
occursata
of
devices
sequenceofevents
flow
diagramoffigure
Not
ready
for
Data
not
accepted
Data
valid
the
DAV
description
a
data
bytetooneormore
of
handshakeisto
are
readytoaccept
dataonthe
data
has
been
rate
determinedbythe
which
that
handle
occur
during
7-21.
data
signal
and
the
listeners
signals.
listeners,
ensure;
data.
data
bus.
acceptedbyall
listeners.
slowest
dataatdifferent
the
transferofa
speeds.
data
the
NFRD
this
control
active
deviceonthe
byte
from
and
NDAC
procedureisusedinorder
the
talkertothe
signals.
bus;
this
allows
listeners
to
the
is
Not
NRFD
(Listener)
DAV
(Talker)
NDAC
(Listener)
Data
Bus
Signals
Settling
Greater
(2)'
Data
Signal
Interval
than64msec.
(5) (7)
Ready
for
Data
Not
Ready
Data
Not
Valid
Data
Valid
Data
Accepted
Data
Not
Accepted
Bit
High
Bit
(Being)
Value=0
Impedance
Value=1
for
Data
Figure
7.21.
Transfer
bus
handshake
84
sequence.
Page 93
COMMENTS
TALKER
COMMENTS
All
Listeners
are
Ready
for
Data
Is
the
Data
Valid
Data
Not
Valid
Figure
7.22.
listners.
Sequenceofevents
Broken
lines
duringadata
indicate
byte
the
testingoftransfer
transfer
bus
from
the
signal
logic
Not
ready
for
Data
Data
Accepted
Data
Not
Accepted
talkertothe
levels.
85
Page 94
Figure
7-22
shows
numbersinthe
1)
next
2)
signalstosettle.
3)
DAV
4)Assoonasa
NRFD
rate,
5)
the
6)
invalid.
7)
low
the
data
required
the
relative
following
NRFD
byteofdata.
The
talker
The
talker
low
low;
each
NDAC
data.
The
talker
The
listeners
(true)
data,
transfer.
data
timingoftransfer
sequence
goes
high
puts
tests
(true)toinform
dataisnow
of
goes
high
sets
completing
they
release
The
transfers
refertothe
(false)
the
indicating
next
data
This
could
NFRD, whenitis
listeners
single
listener
acceptedbyall
whom
DAV
note
release
(false)
when
high
(false)
that
the
handshake.
NFRD.
sequence
have
This
will
been
bus
signals
duringatypical
changesinsignal
that
all
listeners
byteonthe
happen
foundtobe
that
detects
NDAC
the
slowestofthe
indicating
DAV
has
terminates
repeat
completed.
data
before,
too
the
bus
that
DAVislow,
the
individual
as they
that
gone
When
each
the
again,
beginningat(a),
bus
listeners
the
high
listener
handshake;
logic
levelsinthe
are
ready
and
allows
for
the
the
data
Figure:
afterorduring
high,
the
talker
dataisnow
that
listenersattheir
accept
have
bus
signals
and
has
sequence
makes
valid.
listener
the
sets
own
data.
accepted
are
now
sets
NDAC
processed
for
the
first
until
the
(1).
all
bracketed
PET/IEEE
The
If
these
See
THE
This
concerned
The
Bus
following
limitations
Table
7-24.
MANAGEMENT
groupoffive
with
five
management
Timing
limitations
a)
afterithas
b)
afterithas
a)
b)
c)
d)
e)
Constraints
shouldbenotedinordertoavoidalossofdata:
When
data,
PETisa
set
NFRD
When
PETisa
set
NRFD
are
exceeded,
BUS
signal
ATN
EOI
IFC
SRQ
REN
lines
controls
addresses,orcontrol
signals
Attention
End
identify
Interface
clear
Service
request
Remote
are:
or
I
enable
listener,
talker,itexpects
the
,
it
expects
high.
NDACtogo
high.
PET
ceasestotransfer
the
stateofthe
information
Assigns
or
Indicates being
Initializes
listeners
resetinthe
Device
required.
but
Permanently
devicestoactaslisteners
talkers.
that
transferred.
tells
availableinPET.
the
the
data
set
idle.
PET.
controller
Not
implementedinBASIC
tiedtogroundinthe
PET.
DAVtogo
data
(device
last
data
bus.
Talkers
Same
signal
that
low
within64milliseconds
high
within64milliseconds
and
sets
the
appropriate
bus
and
defines
commands).
byte
is
and
as
service
is
its
signals;
status
word
these
can
(ST).
be
86
Page 95
IEEE
SIGNALS
The16transmission
bus
group,
AND
name,
abbreviation
DEFINITIONS
linesofthe
IEEE-488
and
functional
bus
are
each
assigned
description
for
a
eachofthese
specific
signai.
signals.
Table
7-23
gives
the
LOGIC
The
businthe
LEVEL
CONVENTION
"true"orlogical
"true"orlogical
"1"is
low
"1"
Bus
Group
Manager
Transfer
Manager
Manager
Transfer
Transfer
Manager
Manager
with
common
state.
Signal
Abbrev.
ATN
DAV
EOI
IFC
NDAC
NRFD
SRQ
REN
collector
Name
Attention
Data
End
Identify
Interface
Clear
Data
Accepted
Not
for
Service
Request
Remote
Enable
Valid
or
Not
Ready
Data
type
outputs.
The
signal
commandsonthe
When
eral
addresses
messages
When
veiously
transfer
When
fies
that
data
When
being
has
the
low.
low
while
being
PET.
The
set signalasIFC
initialize
state.
onorreset,
about
This
by
the
When
read,
high.
that
When
oneormore
ready
data.
ready,
Not
implementedinBASIC,
but
availabletothe*PET
RENisheld
controller.
grounded
permanently
This
allows
Functional
Description
PET
(controller)
low
while
ATNislow,
areonthe
ATNishigh,
assigned
data.
DAVislow,
dataisvalid
bus.
the
last
transferred,
optionofsetting
The
PET
the
transferred
PET
sends
all
devicestothe
When
PETisswitched
IFC
100
milliseconds.
signalisheld
listener
the
data
the
listener
This
signals
data
has
been
NRFDislow
listeners
for
the
NRFD
The
that
next
all
goes
lowbythe
low.
When
sets this
it is
sending
data
only
and
control
data
only
devices
this
on
byteofdata
the
always
sets
last
data
from
its
internal
low
(true)
goes
low
low
while
reading.
byte
has
sets
NDAC
the
talker
accepted.
(true),
are
byte
devices
high.
PET
hasapin
keeps
REN
any
bus.
periph
bus.
pre-
can
signi
is
talker
EOI
EOI
byte
is
the
re
to
idle
for
(true)
been
not
of
are
user.
bus
devicetohold
the
Table
continuedonnext
Table
page.
7.23.
IEEE-488
87
bus
signal.
Page 96
Table
7.23.
IEEE-488
bus
signal
(continued).
STATUS
STisa
have
IEEE-488
WORD
BASIC
certain
bus.
Group
Data
General
(ST)
variable
values
which
over
ST
1
2
64
-128
Bus
Signal
Abbrev.
DI01-8
GND
canbeusedtocheck
the
range
-128
Error
Time
out
on
listener
Time
*out
on
talker
End
or
identify
(EOI)
Device
not
present
to 127.
Name
Data
input/
output
lines
1
through
Ground
Table
The
IEEE
milliseconds
The
IEEE
valid"
signal
time
out
EOI
has
being
transferredonIEEE
do
not
generateanEOI
instrument
Device
did
eratesanerror
returns
the
8
the
outcomeofINPUT/OUTPUT
7-24
device
has
time
out
device
has
(DAV
interval.
gone
low
manual.
not
respond
message
PETtoBASIC
Functional
Description
These
signals
of
informationonthe
WhenaDIO
represents1and
Ground
are
six
ment
one
data
and one
lead.
shows
Explanation
not
responded
inverval.
not
providedanactive
low)
within
(true),onthe
signal.
when
and
signalislow,
connections:
control
signal
ground
signal
chassis
the
status
the65millisecond
last
bus.
Note
Consult
addressed;
the
operating
command
represent
when
the
data
it
high
There
and
manage
returns,
ground
return
shield
ground
code
within
the
65
"data
byteofdata
that
all
devices
relevant
this
gen
system
level.
bits
bus.
0.
operations.STcan
that
appertainstothe
IEEE-488
Table
of
the
REGISTER
7-24
shows
PEEK
and
ADDRESSES
the
IEEE-488
POKE
commands
Table
Table
hardware
will
Hex
Address
E820
E822
E821
E823
E810
E840
7.25.
IEEE-488
7.24.STstatus
addresses
fail,ifthe
Decimal
Address
59424
59426
59425
59427
59408
59456
hardware
code
for
time
Bits
0-7
0-7
3
3
7
6
0
1
2
6
7
addresses
88
for
IEEE-488
the
PET.Anattempttocontrol
out
intervals
DI01-8
0101-8
NDAC
DAV
SRQ
EOI
NDAC
NRFD
ATN
NRFD
DAV
and
IEEE
signal
bus.
for
the
488
devices
Mode
Input
Output
Output
Input
Input
Input
Output
Output
Input
Output
information.
the
busbymeans
are
exceeded.
Page 97
cr
cr
1
A
f
UJ
O
>■
CL
m
aUJz
Q
UJ
MSG
1
1
7
0
1
0
1
0
1
0
P
A
6
|
I
\
5
P
A
4
0
A
1
3
0
2
SP
1
OLE
0
NUL
1
0
ROW
COLUMN
I
010
b1
1
0
b2
1
0
b3
1
0
b4
1
MSG
i
1
MSG
\
MSG
0
1 1
MSG
1
1
0
MSG
1
0
MSG
o
0
MSG
o
0
C|
t
a
Q
T
!
LLO
DC1
GTL
SOU
1
0
0
0
1
It
R
A
T
1
i
UJ
B
2
DC2
STX
2
1
0
0
1
s
O
c
cl
!.
T
S
1
UJ
O
D
C
J,
MH
3
4
J
i
o
-
S
DCL
DC3
DC4
SDC
EOT
ETX
3
4
1
0
1
0
1
0
0
0
u
V
CD
I
e
V
U
UJ
Q
O
F
M «
p
5
6
LU
"o
&
PPU
NAK
SYN
PPC(3)
ENO
ACK
5
6
1
0
1
0
1
1
0
0
a
w
X
L
y
LU
Q
LU
o
pz
i
ol
'
X
Y
z
W
Q
U O
7
-i4i-K-
5—
Q
z
(
)
'
SPD
SPE
EM
ETB
SUB
CAN
TCT
GET
LF
HT
BS
BEL
7
8
9
101112
1
1
0
0
1
1
0
0
1
0
0
0
1
1
1
0
b5
i
UJ
i
1
LU
.
1
k
I
\
K
h
5
t-
ESC
FS
VT
FF
101
1
0
1
0
1
1
f
1
1
1
DEL
s
n
in
C)
i
T
■■
I
M
n
o
1
1
T
■■
|
-
--
?
]
1
t
-
RS
US
GS
CR
SI
SO
15
13
14
1
0
1
1
0
1
1
1
1
1
1
zti
LJ
I
TALK
(TAG)
GROUP
ADDRESS
bid
\_
J
I
(LAG)
LISTEN
GROUP
ADDRESS
(UCG)
GROUP
COMMAND
UNIVERSAL
T
(ACG)
GROUP
COMMAND
ADDRESSED
I
COMMAND
SECONDARY
J\_
(PCG)
GROUP
COMMAND
PRIMARY
V_
MESSAGE
INTERFACE
MSG
(P
(SCG)
GROUP
MODES.
DATA &
COMMAND
BOTH
IN
USED
CHARACTERS
ALL
b)
THROUGH 2
COMMAND
DI07
(COLUMN
l)7
SECONDARY
SUBSET
DI01
HtOUIRES
DENSE
h,
0
(?)
CD
ASSIGNE
TA
operation.
ASSIGNE
TA
of
TRUE)
Mode"
ATN
WITH
"Command
for
RECEIVED
AND
assignments
(SENT
Code
7.26.
Table
cr
cr
-
vb\
OD
<0
NOTES
Page 98
NOTES
90
Page 99
Chapter
8.
USEOFTHE
PET
FOR
MACHINE
LANGUAGE
PROGRAMMING
Machine
first
music,orwrite
microprocessor,
before
In
PET
BASIC.Aspreviously
machine
individual
A
monitor
execute
BASICisthat
to
work
seesisbinary.
MACHINE
Itispossible
instructions
implement
do,
BASIC.
the
language
then
executed.OnPET,
you
proceed
there
are
language
memory
essentially
code.
entirelyinhexadecimal
LANGUAGE
these
(2)
howtoimplement
The
decisiononwhat
programming
programs
the
screen
itisprobably
with
this
two
waystocreateamachine
discussed,
operation
locations.
has
These
all
to build
which
functions
bytes
mustbeconvertedtodecimal
The
PET
monitor
PROGRAMMING
intoastringofmemory
areamachine
subroutines,
it,
manual
execute
machine
memory
advisable
chapter.
much
faster
language
with
blinding
that
you
thandoBASIC
canbeusedtocommunicate
speed.Ifyou
get
language
there
are
two
BASIC
relativetocontrolling
The
second
only
three
are
availableasPEEK,
notation
does
language
there
(3)
wheretoput
the
programisto
(6502).
methodtoprogramisbyamonitor.
functions:
but
have
FROM
are
four
examine
the
6502
some
other
BASIC
locationsbymeansofa
subroutine
basic
considerations:
the
program,
do and
programs
have
never
holdofthe
two
books
programinmemory
commands,
input/output
and
POKE
before
does
not
useful
whichisusable
and
PEEK
instructions
deposit
and
SYSinBASIC.
use.Amonitor
care
what
features
(1)
what
(4)
howtocommunicate
which
with
programmed
mentionedinChapter
and
execute
and
POKE
or
influencingorsampling
bytesinmemory,
The
available
base
you
whichwewill
POKE
command,aset
by an
individual
the
subroutineissupposed
howtoimplementitis lefttothe
havetobe
the
which
chief
for
workinbecause
discuss
the
interpreted
user
port,
play
the
6502
1
it.
The
firstisby
give
equivalent
and
branch
limitation
PET
allows
later.
of
program.
To
subroutine
programmer
to
of
one
all
it
to
from
and
To
locate
or
whetheritisaprogram
operatinginthe
To
understand
All
the
changed
1isused.
memory
using
If
only
during
between
to
the
indicates
margin
whichisnot
FRE
cassette
The
language
user.
the
co'de,
you
machine.
how
besttokeep
zero
page
programs
throughout
the
Page2hasaseriesofvariables
locations
tape
I/O,
the
first
the
program,orif
the
634
then
these
cassetteisused,
endofthe
programmer.Atany
the
beginning
whichisproportional
affectedbyBASIC
statement.
locations.
final
problemishowtoget'the
monitor,
First,
Once
the
machine
machine
must
decide
you
wanttohave
the
address
programs.
through
1023
areas
will
the
this
areaisnot
BASIC
program and
time
during
locationofthe
to
the
during
programs
language
have
language
program
whether
programinmemory,weshould
are
Between
are
notbetouchedbyBASIC.
second
amountofdata
been
program
you
haveasmall
operational
consumedbythe
the
normal
which
used
for
the
are
again
first
cassette
enough
into
where
BASIC
which
executionofthe
BASIC
execution.
programs
variables.
space
These
written
into
the
are
and
memory
loadable,
mustbeloaded,
program
throughput
operating
useofstack
used
throughout
and
second
bufferisavailable.
the
useristo
stores
its
variables
program,aPEEK
Working
thatisusedinthe
are
debugged,
back
memory
this
location.
this
involvesatwo-step
followedbythe
thatistobeused
the
entire
time
the
BASIC
review
system
and
cassette
locations
the
memory
and
are
tape
I/O
corrections,
the
program.
buffers.Ifa
If
both
the
write
some
is
the
space
into
location
down
these
program,isa
which
spaceisas
usually
cassettes
code,
withasmall
are
usefulasare
Althoughbyuseofthe
loadingofthe
only
temporarily
program
mapofthe
is
PET.
being
allofpage
However,
programisnot
are
used
then
the
space
thatisavailable
124
and
125
safety
memory
area
countedbythe
the
machine
process
for
BASIC
the
91
Page 100
program.
buffers.
machine
of
the
SYS
Whenitis
The
returnedbymeansofa
program
following
at
Line
for
The
than
has
soonasyou
may
the
case,
Obviously,
Another
techniqueisto
language
executionofthe
COMMAND
necessarytotransfer
preferred
approachisthe
suchasa
codeisencountered
10,
BASIC
the
SYS
command
start
address
65535.
built
cause
machine
NOTE:
intoitto
transfer
the
machinetoceasetofunction.Inordertohelp
language
when
controlofsystemislost,itcanberegainedbyrepowering
this
program
machine
will
can beacomputed
Executionofmachine
allow the
control
technique
into
BASIC
does
not
assemble
data
program
the
statements.
and
controltothe
SYS
command
routine
hand
is
monitortodevelop
from
subroutine
language
controlofthe
BASIC
from
monitororfuture
value,ineither
interpreter
BASICtoyour
computertothe
SYS
workatall,ifthe
program,
POKEd
machine
which
instruction.
into
The
data
into
the
language
transfers
languages
10
SYS
(634)
(start
case,itmust
code,
to
continue
own
program,
anything
other
than
programistobeloaded
the
BASIC
statements
appropriate
control
It
can be
program
removes
functioning
any
solve
the
program,bymeansofputting
can
thenbereadatthe
memory
program,
usedtotransfer
when
locatedat634.
resultina
almost
mistakes
this
most
there
totally
from
they
become
positive
all
protection
without
which
typeofproblem,
trivial
the
amountofcode.Inany
system
into
the
beginning
locations.
are
two
waystodo
BASIC
until
control
controltoany
available.
The
general
number
regardtouser
occurinyour
on.
not
that
you
should
the
cassette
the
it.
is
other
If
the
format
greater
ROMs
error.
As
program
use
In
ordertoreturn
beaRTS
ordertopass
command,
the
follows
USR
There
to/from
specified
the
parameterispassed,
asitis
USR
be
analyzedbythe
called
instruction.
data
BASIC
routine.
the
FUNCTION
are
some
BASIC
withaparameter.
evaluationina
usedbyBASICina
callsaroutine,
useraspartofa
willbepassedtothe
the
user
returnstoBASIC,
The
SYS
commandismore
variables
are
command.
from
BASIC
the
variablesofdata
hastobe
The
calltoSYS.
programs,
using
the
floating
the
which
BASIC
USR
not
being
Thisisan
important
the
resultsofthe
BASIC
acted
locations1and2.These
in
which
the
machine
language
SYS
command,
will
then
back
POKEd
into
particularly
USR
function
BASIC
evaluates
accumulator
floating
accumulatorisnot
varietyofways
the
start
interpreting
and
forth
temporarily
SYS
operation
mathematical
andtoget
the
which
priortoexecuting
executesamachine
expression.
Because
instructionasin:IFUSR
functioninthe
floating
wouldbecomparedto1
useful
for
transferring
on.
USRismore
consideration
locations
mustbeinitialized
programisstored.
last
instructioninthe
the
next
between
undisturbed
would
the
memory
havetobe
ones,inwhichitis
the
results
expression
BASIC
uses
initializeable
directly
for
for
the
language
USRisa
program.Aresultinthe
function,
(A)=1,
accumulator.
and
the
logical
control
useful
in
using
This
for
machine
when
oneistryingtoimplement
USR.
USR
with
the
hexadecimal
canbedone
program,
statement
user
program
locations
PEEKed
whichisexecuted,
after
the
SYS
and
BASIC
during
back
into
easiertopass
processedinBASIC.
its
parameter
allofits
by
the
USR
function.
and
leaves
functions.
userorby
Itisnoted
any
floating
itispossibletoinclude
THEN
The
etc.Inthis
resulting
function
floating
wouldbeexecuted.
language
uses
preassigned
case
accumulator,
processing
variable
valueofthe
anywhere
throughout
should
command.
using
the
execution
the
program
the
In
SYS
of
that
parameters
USR
is
the
results
of
thatifno
other
techniques
accumulator
the
the
parameter
to
function
A
when
in
which
anew
BASIC
locations:
starting
address
the
program
92
Loading...