Congratulations and welcometothe exciting new worldofpersonal computers.Byselecting
the
PET
2001
you have
is now available for learning the
procedures
outlinedinthis
eliminated
manual,
the
problemsofgetting
functions
you
and
should
a personal
capabilitiesofyour
be abletoachieve
computer
system running. Your
PET.Infact,ifyou
initial
operationofyour Pet
follow
a few simple
a short period after unpacking the shipping container.
The potentials
arise
that
this book has
to
Write
us at Commodore
with a newsletter we'll
are virtually limitless. This book,byits
not
coveredoreven anticipated.
with
your questions. We will answer many
be
sending out from timetotimetousers.
very nature,islimited.
that
you and other users
Questions
of
your
PET
Commodore Systems Divisions:
901
California Avenue
Palo Alto, California 94304
USA
360
Euston Road
London NWI 381
England
3370
Pharmacy Avenue
Agincourt
Ofjario,
M1W 2k4
Canada
2001
will
time
within
will
pose
PET
is a Personal Electronic Transactor. Everything is complete in one steel cabinet. It contains a
board, keyboard, computer board, and a Commodore supplied cassette. There is a built-in black and
that
white television monitor, which displays characters in a format
by
twenty-five lines.
of
your
PET
At the heart
2001isan
MCS 6502 microprocessor. This microprocessor
appeartoyoutobe forty characters
totally
controls
operationofthe screen, keyboard, cassettes, and additional peripherals which can be addedtothe
The product is so construed
be
cannot
destroyed because the computer software,oroperating instructions are contained in a fixed
memory. (Called Read-Only·Memory) This allows both the first
use the
In
PET
with impunity.
order to satisfy the needsofthe serious user as well as the
have used three formats in
Summary discussionsinthis type font are designed to answer the questions
programmer.
When
you are first using your
more detailed explanations which are in the type font
PET
a bit, the italicized summary sections will be useful when you want
that
you cannot damage the
this
manual.
PET
PET
from the keyboard. The operating system
time
user and the sophisticated user
first
time userofa computer product, we
manual, read these sections
of
the preceding paragraph. Afteryou have used the
lightly
to
of
a professional
andspend time on the
review
howaparticular
instruction works.
The third typeofformat gives a detailed descriptionofhow
PET
sections are for people who use the
sections
difficulttofollow
more familiar
with
the
and we recommend helshe use them
PET
operating systel\1.The languagewhich you
at the machine level. The
the
PET
Implements a section. These
first
time
reader may
only
on re
...
eading the material when
will
usetocommunicate
find
these
with
PETiscalled BASIC, an acronym for Beginners All-purpose Symbolic Instruction Code.
CRT
PET.
to
your
1
It shouldbenoted that there are
of
usage in mind, which are availabletothe public.
the appendix. Someofthese manuals maybe more' usefultosatisfy
in
this
particular manual.
The ultimate teaching device for learning how the
PET
ask you to use the
case,
this
documentation is
of
examples
we
invite comments on
to
resolve any unclear statement.
Lastly, since
your own, any questions which
this
programming aspects
along with the text, rather than Just continuously reading whattodo.Inany
this
manual cannot presumetoprovide all technical informationofhardware or
of
the MCS 6502 microprocessor, we direct you to two other Commodore
other"'EY~~enCEt;
'1Ji:"teri~lwritten
We
have included a
PET
worksisthe
aRput BASIC, with different
listofsuch suggested reading
aspecffic
PET
need whichisnot covered
itself.Insome cases, we will
tYPlilS
in
sufficienttoallow youtoget started onanexample.Byconstructing similar
might
arise are answered by the machine itself. Of course,
material and particularly on examples which you asanindividual have used
publications: There is a manual available from your dealer called Hardware Manual which also includes
descriptions
the auxilliary devices which generate the control signals necessarytoallow the
PET
to
of
operate. Detailed specificationsofthe computer and the language in which it operates are availableina
book called Programming Manual. This
is
available for purchase from your
PET
dealeroreither can
be
purchased from Commodore directly.
NOTES
2
Chapter
2.
UNPACKtNGYOUA
PET
AN'lfTURNINGITON
Please check the carton for any special unpacking instnl-cti9ns and carefully examine your
is
concealed damage. If anything
amiss, reportly this immediatelytoboth the placeofpurchase and the
shipping agent.
PET
from
its
Remove your
surface, then plug
it
into
protective shipping carton and placeiton the counter, desk,orother suitable
any standard, grounded electrical
Tv
BRIGHTNESS
ADJUSTMENT
outlet.
(In
some countries no plug is provided.)
PET
for any
MEMORY EXPANSION
J4 CONNECTOR
Figure
2.1.
Rear
fuse, line cord and interfacing connectors
The power
closing
position,
Immediately, when the power
time-out
switchislocated in the
it
to the right turnsitoff.
oranON/OFF label.)
circuit
in a special condition (reset condition) which initializes them into a known state. If the
left
rearofthe
(Thereisa white
switchisturned on, power is suppliedtothe internal circuits. There is a
screen has had power immediately prior
characters which reflect the current contents
to
The screen memory transfer
the screen is done
,3:~~,~,
INTERFACE
view of
to
PET
PET.
dot
this
time, you will see on
of
the computer memory which is controlling the screen.
microprocessor, and so, even when the computer is
of
current contents
the screen memory.
1.6A
FUSE -.,..:=/
ISlO
.d
I
PARAllEL
USER PORT J2
2001·8 showing switch,
SERIAL NUMBER
ELECTRICAL SPEC.
'""
Closing the switchtothe
on the power
with
circuitry outside controlofthe main
not
operational,
switchtoindicateitis
BW)
3-WIRE
POWER
CoRO
left
the
screen a varietyofstrange
the
screen always displays the
AC
turns the
PET
on and
in the power-on
3
At the endofthe
,..,
.....
temporarily, and then displa)'s on the
power~n
,."j...
, ,•.
cycje,
the
.•
,, "':.16,,"
computer initializes the internal membrv, biank's the
sc.r13~n
",'
',.-,','
a m13ssage.llke the followir:tg:
.-'
s'c~reen
,
:'.
u*COMMODOREBASIC***
7167
BYTES
FREE
READY,
o
The 7167 referstoavailable users'programmable memory. A byteIsthe fundamental data elementofthe
PET
computer and corresponds roughlytoone letter or
theory·
In
"S192
bytes".
But a few hundred are used by the
net available bytes.
If
you failtoget the power·updisplay the
To get the display, four different types
first
of
memory
time,
(Input/Output), and Screen Memory.
The relationship between these memories Is shown In figure
microprocessor
digitofInformation.TheSKmodel should show-
PET
internally. The balance shown "7167" is
try
turning the power switch slowly
are
used:
ROM,
User ReadlWrite,
off,
then back on.
1/0
2.2.
6502
r-
ROM
14k
RAM
Bk
address and
TV RAM
1k
data-bus
/
keyboard
110
2k
\I
,
/
IEEE·4BB
I
[\
\
II
user port
Figure 2.2.
PET
memory bus
4
ROM
(READ ONLY MEMORY)
ROM
causes the
programs writtenbyCommodore which scan the keyboard, print the display, control inputfoutput, count
the real
the
operation
keyboard,
powered on, but also
1/0
The second typeofmemory is
devices called PIA* and
computer. Except when special
interfere in any way with these areas. The operating system automatically handles these locations in
order
time
lowest cost memory for storing
of
or
MEMORY
to
perform legitimate Input/Output operations.
PETtoperform
clock, and execute commands that the user types in.
his
machine. This is because the operating system memory Is indestructible from the
from the user's program. Notonly is the machine availabletorun basic from the moment it is
operations are desired, the user should not allow his program
operations.Ineach
data, but also give the user the
the
the
PETtoindividually control the
PET,
Read
basic operating system.
14K
of
ROM
contains a series
Only memories are not only
most
protection and
bits
that manipulate the
the
of
fastest
110
to
USER READWRITE
The third typeofmemoryisthe User Program Memory Space.
throughout
$1FFF. A detailed map
RAM,
by
the
for
its
The message "7167 BYTES FREE" is a result
locxation
performing a check on whether or not
If the number was less than
greater than
upto32KofRAM
furnished with the
are
loaded and BASIC holds allofthe program variables.
Later on, we
program overlays.
this
110,
and Screen Memory are located from a programming standpoint.Asyou can see
map,
the
various tasks, including
1024
7167,
will
MEMORY·
book.) In a standard 8K
of
first
1024 bytesofmemory are reserved for the operating systemtouse
and cycles through the memorytodetermine which locations are available, thereby,
you probably have added your own memory. BASIC can automatically check
as long as the added memory is continuoustothe memory
PET.
This memoryisreally the working memory in the machine;itis where programs
discuss some techniques to expand
R.A.M.(RANDOM ACCESS MEMORY)
all
PET,itis
the
memory is included in figure 2.3, showing where the
the
bufferingofdata from the cassettes and other
the
ReadlWrite Memory is working correctly.
7167,
you may have a hardware problem.11the number is
located from location
of
an
analysisofBASIC which starts at
this
memory by using tape files and
(We
will call
this
area
$0000tohexidecimal
that
RAM
ROM,
110
devices.
comes
SCREEN MEMORY
The screen memory is physically composedofthe
make up the PET's standard memory. It is constantly being used by the
which takes
ROM,
thus displaying characters on the screen.
As
mentioned during the power-up discussion,
no direct control over it.
*PIA - Peripheral Interface Adaptor
**VIA - Versatile Interface Adaptor
For information about these and related chips, see 6502 Hardware Manual.
the
individual bytesofmemory and uses themtoaddress a special character generator
same kindofchips that are used
CRT
this
process is
totally
automatic, and
5
to
control electronics,
the
programmer has
1024
8192
o
RAM
RAMUser BASIC program
Operating system and
BASIC working storage
-------------
User Variables
Expansion RAM area-24K
32768
33792
34816
35840
36864
49152
59392
61440
65536
RAM TV
1---------------
ImagesofTV RAM
Images
ImagesofTV RAM
Expansion ROM area·12K
ROM
1/0
ROM operating system
FIgure 2.3. PET memory map
of
TV RAM
BASIC
On
every
cycleofthe
($8000) in
corner
giving us
8
dots
toptobottom.
controller
on
whether or
character, etc.
There are
screen by POKEing
the
second character set. After you have played
to try
lower
To understand
the
screen
of
the screen. Each character in
an
8 row
each
timeitis
This givesan8
automatically
notitis
two
character sets stored in
this
featuretoseeifyour
case letters
this,
TV screen
memory
high
addressed. These
scanning
memory
for
the
let us review
and processes
characteronthe
bit
changes
address 59468 with a 14(a12turnsitback) which
graphic set
(1/60ofa second),
wide 8 bit
the
addressingofthe
the top
PET
performs
thatisavailable in
how
characters are represented in
the
hardware
the
screen
the
memoryisaddressed
screen. The character ROM
dots
are
serially
tall
character with no spaces between characters. The CRT
lineofa character,
the
ROM. You can change
with
this
data
starting
fedtothe
character generating ROM, depending
the
the
screen a
way. The second character set
the
first
6
starts
into
second
with
the
least
at
the
upper left-hand
the
character generator
thatisused generates
screen, working from
lineofof
the
character set on
turnsitto
little
set.
the
bit, you
PET
may
and in
address
lefttoright
a
the
want
substitutes
the
memory.
eight
times,
and
CHARACTER
The standard ASCII code is used to represent charactersinthe
In
the PET,
screen.
REPRESENTATION IN PET
the
8th bit (bit 7) is used to signify BASIC command words or graphics characters forthe PET
MEMORY
main memory. (RAM)
~
1
I
;;"1~
tf\:Si::Ild
1:.lC1\:S1
tJ\::Jlt:l
~~'1
~1~"
e1e,
e11e
e111
1e~"
il:l'"
1"1"
11:111
11CSld
11'"
111"
1111
Exampleinthe
Aisrepresented
Shifted
A (a
"I
~I
41
PET:
spade)
~
~
"
NUL
::>OH
!,;IX
c.IX
1:.01
I;.N~
tH..':K
~c.L
lJ:;
HI
L'
VI
H
t..:H
:;0
:;1
is
~~
~
1
VLc.
1)(,;1
11
~
:;~
V("
VL3
.1)(,;4
NIlK
:;YN
c.llJ
LIlN
c.~1
bUJ;l:
I;.~'.,;
,:;
fj~
kti
V:;
Figure 2.... ASCII ch8r8ct
0100 0001
11000001
~
$
:<
..
(
)
•
+
/'t'
~
1
"
1f\
;;
"
4VI
~
b
'(
'"
~
1
~
~
~
~
(;
c.
,
(;
HXh
1
J
K
<.
~
~
L
'1
N
•
...
set (7 bit
code)
111
~
1
~
Q
kbr
:;
11
~
i,W
a
cs
dt
u
Vfv
W
y
Lk
"
"
Jm
tn
..
"
..
i
0z
1
0
1
p
..
u
..
x
"
The
screen
There are only64characters from the standard ASCII set that are normally printable.
memoryisorganized
with
a different
representatIon
from
the
main
PET
.
lJ
"I
~I
1
41
I
;;<:1~
i::It:H'JI:I
e~e,
i::Ildl\::J
ee11
e,
••
"'1~1
tl11\::1
~111
1,,~~
1,,~,
1",e
1~11
11ee
11~'
11W
1111
"
"
•
•
1
"
p
"
11
~
(;
V
c.
,
(;
HX
1
J
KL+
L
N
N
0
Q
k
:;
I$4
U
V
W
Y
"
"
J
,.
~
1
"
~
..
~
:<
..
(
)
•
/
(j
1
,
e
1
;;
"
~
b
'{
~
"
<.
~
>
"t'
memory.
figure 2.5.
ASCII
64
ch.,.cler
.'1(6bll code)
7
These are the same characters that are directly available on the
is
The representation in screen memory
6;
giving us a six bit code for the keyboard characters.
or
The graphic,
additional
shifted characters, setIsrepresented by a 1Inbit sixofthe screen memory, giving an
64
displayable characters.
derived from the standard ASCII set by dropping bit
PET
keyboard.
This gives the
characters are organized so that they are
Ii
I
I
~,1i:::J
~
......
I:H:U::H
."1"
1l~11
• 1
....
111..,
1111
..
11111GW
111
....
111111
1..,
..
11111K
lUIl::J
11111
111
..
1111
following table for
01
~I
41
~~
~
~
~
AQ1
Ii
(;
j)
t.U
tV
H
IV
J
L
M
N1
0
PET
displayable characters.Itshouldbenoted that allofthe graphics
~
1
p
k"
S
1
X
"
L
,
J=
+-
justashift
~
11
~
"
•
"
..
<
)
*
+
•
/
from the normal keyboard character.
~
1
..
~
~
4
~
0
'(
II
Y
(
)
"
111
~
~
•
I
I0
I
,
,
J
L1
\
/
I
~
1
1
•
II
"
rI
)<.
4-
1
•
+
I
..
"
1
~
•
•
..
I
•
~
I
•
•
,
,
-
1
1
1
,
...
T
~
I
I
-
-
.J
•
,
"
,
'.
,
FIgure 2.8.
Example: This gives us the following conversions:
In
Character
A
+
1
~
Note the reduction from seven
of
A and1.In
field consists
a white
If
memory representation. Both PRINT and direct Input from the keyboard result in automatic
translation between the screen memory and the main memory.
dot
the operating systemisused, it automatically translates the values from ASCII Into the screen
screen memory, the 8th bitisusedtostore reverse field. The reverse
of
taking the dot pattern from the character generator and reversing It, replacing
with black and a black dot with a white.
main memory
01000001
1100
0001
0011000100110001
1011000101110001
bit
ASCIItosix bit gives the effectofchanging the order
PET
graphic charaet...
In
screen memory
00000001
00000oo1
Nt
(7 bit
code)
8
USE OF THE SCREEN MEMORY,
There are three waystoget data
the appropriate memory addreSs
normal updating
As
longasthe
and the
PET
memory only during
the useofthe screen
of
the
screenistoo
PET
directly
are contending
times
memory
controls
when
r"
into
the screen memory. The
the
desireci'translatedc"fiara:cter. This is programmed only when
slow.
the screen, thereisno
for
accesstothe memory. The routines In
the
screen memoryisnot being used for display. This slows
downtoabout40percentofthe
apparent
speed
firstofthese;stoPOKE into
effect
obtainable
from the fact
the
PET
that
change the screen
with
a POKE. The POKE,
the screen
however, gives a visual effectofflashing dots, because the screen Is displaying the character
that
Is being passed from the
shouldbedisplayed at
it
runs the more flashing there will
that
PETtothe
particular
be.
screen memory, rather
position. When a program pokestothe screen,
than
the character
that
the
faster
The second waytoget data
onto
the screen is
the
keyboard. During a
time
when keyboard input
enabled, the character being struck on the keyboard is automatically displayed on the screen.
The third approach
is
by useofthe PRINT commandinBASIC. When
PRINT
"ABC"
..
is typedtoBASIC,itresults in the next line being printed as:
ABC
Thisisa printofa literal field in which all characters between the quotes are printed.
The next position at which a character
by a flashing signal called a cursor. The cursor is a visual indication
will
be displayediftyped on the keyboard is indicated
to
the userofthe next
print position in screen memory.
What Is
1/60thofa second, an
computer
the screen memory
be
By moving
of
controlofthe
physically
(the PET) and steps a
showninalternating normal and reverse
the
the
keyboard and some software
happeninginthe
interrupttothe
pointer
pointer,
keyboard.
we can
machine Is
PETisgenerated. This generates a real-time
blinker
Is reversed in the 8th
print
counter. When
output
called
that
every
time
the screenisrecycled, about
clock
this
counter reads
bit.
This causes the reference character
field,
giving as visual
any place on the screen. Thisisdone by using a
the screen editor,
effectofblinking.
which
37,
the character referenced
manipulates
screen memory under
on the
to
combination
is
by
9
Chapter
3.
BASIC KEYBOARD UNIT
Whenever
keyboardtothe
Keyboard
key is struck. Only after a carriage return is
program, and then a
There are
is
the
the keyboard
The
is
similartothatofa
However, some
the
blinking
screen memory.
data
;s transferred by the
two
exceptionstothis,
useofGET,
dataisaccessed
PET
keyboard
important
1.
Becauseofthe
number
2.
The
3.
The various keys
4.
The characters
longer require
convenient
5.
All standard characters are
available by useofthe
pad
number
cursor
whole
which
has
has
pad
to have them available
line
willbediscussed
been optimized for use as a
typewriter
changes have been made:
high
been added to
has
for
which
shifting.
appears on
is transferred at once.
neither oneofwhich
directly
so a
useofnumbers and
allofthe
screen movement and
are normally
These characters are
unshifted,sothatacomplete
shift
keys. These
the
interrupt
using
touch
the
mathematical
without
screen,
routinetothe
the
keyboard
in a
later
machine
typist
rightofthe
the
does
calculations
editing
shiftofthe
shifting.
graphics
the
computer
screen memory each
data
causes
section,
language programs.
computer
not
feel
with
main keyboard.
operators in a form
are
numbers on a standard keyboard no
quite
often
give
transfers
transferredtothe operating
the
cursortoblink. Oneofthem
and
the
other one is when
keyboard,
totally
locatedonthe
used in BASIC, anditis
the
outofplace.
the
computer, a calculator-like
64-character
PET
significant
data
though
that
the
is normal for BASIC.
numeric pad.
graphics
from
the
time
a new
organization
set is
line
drawing
,
ability.
PET
KEYBOARD
The keyboard
the
upper or
are always used
a
thin,
transparent
left in placetoprotect
peelitoff
There are 64 printed characters on
the
same keys. The restofthe
are obvious:
be diplayed in reverse
The reverse key ;s operational
function
(the
shifted
throughtothe
the
shiftofthe
The keyboardisscanned
routine
using a
being repeated 8
over,
Until
Is struck. The
from
the
that
consistsof73 keys,
shifted
by uSing
like
is operational untilitis terminated by a RETURN pressed or printed, or by pressing reverse-off
reverse key). This
the
lefttoright
keyboard scan
keyisreleased,noother
later
characters
unless
character
function
other.
CRT
times
oneofthe
plastic
the
the
sticky
field·
keys, so
using
controller.
scan. The keyboardisorganizedona 2 x 5
across
routine
scanned keyisthen
displayedonthe
film
covering
keys against
sideofa pieceofmasking tape so astoavoid
keyboard
return or
blackonwhite.
on
conceptofreversaloffunction,
that
a 6520 PIA, a four
the
keeps
including
two
the
cursor
a memory basis. From
the
Each
keyboard. To
keyboard
two
shift
keyboardtobe
shift
keys is pressed
the
key
top
which should be removed. This
scratching
keyboard with 64 upper case,orshifted
consistsoffunction
right and
complementary
time
the
the
final
scans
consideredtobe
dUring
linetoten
Interrupt
implement
valueofthe
are acknowledged
keys,
left.
Reverse on
timetotime
functions
occurs
either
shipping.Toremove
the
oneofwhich
operational.
simultaneously.
characters. Someofthe
allows
up and down, right and
are usually combined, with one being
line
decoder
from
row
matrix
noise
last
next
protection
scan
key
all subsequent characters to
the
keyisstruck,
and
the
CRT,
with
in a buffer.
unlessalater
closure.
may
be pressedtocause
Lower characters
Each key has
protection
the
film,
carefully
scratching
characters on
the
the
the
and N key
The
the
functions
the
left
is carried
interrupt
keyboardisscanned
matrix
roll
scanned key
algorithm
was
keytops.
does
I
I
not
11
I
M.
-
'"
O-l:a.~:g
~E!!!6"><:l:
OIIa.l:«Cal
E'-°c-III°
:::I
CD
zi)!?O~!?
0
~
./;;
III
to
•
a
•
•
..
•
•
..
"
•
..
"
•
..
•
•
..
..
•
..
~@J~[EJ[!J
O@C!J[!J[!J
~@J@[EJ(!)
O@(!)~[!J
•
o
@[
~@)~[E)@
ID
](!)
O@C!J[!J@
~~[!)(B[!J
O@[!)~G
~@][!JlE
O@C!J[!J(!)
~@[!JlEC!J
0
-
;l;
on
:
~
• m
1!
·
'"
t
J•
Iii
~
-
..
••
·"
, -
l~
c
'"
0:
~
"
~
~
"
~
:
~
~
.
~
•
"
O@(!)@](!)
a
•
..
~@~(B(!)
o@C!l~[!J
apoo9(J
/
D'"•
)
pJeoQ,';a)j
/\1
II
::::
12
give classical N key roll over
in
the order
The keyboard Is
BASIC,
of
the normal
that
for
shift
The
Is pressed, the software sets a special
All key closures are translated using a ROM·based look·up table for the key. The
bit8of
Once the hardware translation
queue. The keyboard queue is loaded every time a new key closure
characters can be transferred
ThiS
input
input
stack
to
determine whetherornotitis
queue. The keyboard queue
characters moved down, and a load index pointer decremented by one.
that
they are struck.
left
scanning the
that
checks for
functionsofscanning. The user can take advantageofthis
row.
keyisa special mUltiple key closure andistreated separately. If
the ASCII character whichisthen translated
queueisscannedbythe
may be scanned by a user program. The user program can look at the
but
does
allow
last
row, which contains
the
stop keytosample the
shift
is
done, the encoded valueistransferred Into a10character keyboard
to
the screen."
GET
routine
greater than zero;ifIt is,
is
located at 527·536. The
for
legitimate
input
switch
whichisusedtochange the decodeofthe key.
into
directlytoallow
first
rejectionofnoise and trappingofthe
the
stop
key. This
1/0 device, Without having
by reading the
eitherofthe
the
screen representationinthe standard way.
is
sensed and is unloaded as soon as
input
without
that
means
character may be taken
that
thereisdata in the keyboard
keys
allows
goingtothe screen. The
the routine in
to
perform any
input
character
two
shift
shift
keyisencoded
pointeratlocation
out;
all subsequent
keys
into
525
is
This
new key closure
Both the GET and keyboard
interrupt or
Whenever the screen
first level enables the cursor
cursor
repeated, tryingtokeep th keyboard queue empty.
The second level flashes the cursor and translates and stores characters from the keyboard
keyboard queue. Meanwhile, the first level operating system always watches the
carriage return. After the carriage return
the operating system. The restofthe operating system does not see the characters until they have been
typed and a carriage return
operating system.
An
printing
control
keyboard queue
shift-run Is encountered, the routine
RETURN"
run
a dangerous routine, unless
could
with
the Interrupt masked.
position.
interesting
out
to
is
automatically transferred in the proper order.
The routine then moves
trick
a linetothe
BASIC, new line numbers may be entered
is
into
the
store a new value during a time
input
editor
for the more advanced programmeristo
the
keyboard queue. When controlisreturnedtothe
routineisoperational, a special two·level operating systemisin play. The
to
is
screen, forcing a carriage return
LOADJRUN
writtenina
routine take careofthat
flash and writes data from the keyboardtoscreen memory at the current
the
is
sent. This
sequence whichisimplemented by the keyboard scan program when a
allows
automatically
machine
cursor one character further down in memory. The process
printed,
for total
language
that
you are scanning and changing the queue.
automatically by only operating during the
this
routine automatically transfers the entire line
editingofthe line, priortohandingitto
into
into
the memory. Another exampleofthe useofthe
forces "LOAD, CARRIAGE RETURN,
with
the interrupt masked, because a
input
stream for a
use the
the keyboard queue and then returning
PETtowrite
input
routine,the load followed by the
its
own programs.
RUN
into
the
the
CARRIAGE
to
By
is
be
It should
bad effects can happen
noted
that
this
keyboard queueisonly
to
your system. The
ten characters long and
only
known recovery from exceeding
13
ifit
is exceeded, dramatically
this
queueisto
power
j
..
..,......back
--lftyboanl and you do
SCREEN EDITOR
Typing on the keyboard, while the cursorisactive, transfers what is typed on the keyboard
the screen. This function is like a simple computer terminal which requires youtoretype a whole line
until you get
understood with a
examples are much more
To
follow these examples, two concepts are necessary. One is
system
The second concept is
countered,
are treated by BASIC as characters
In
programming mode). BASIC is executing each instruction like print as soon as you type
and
does make
The
done
the line:
is
golingtointerpret
this
section you are operating the computer in what is known as a direct mode. (i.E. rather than
hit
carriage return.
first thing
this
with your users' guide. However,
on
and
start
over. When fooling with
not
have the Interrupt turned
it
right, but
PETtoIllustrate
the
PET
difficult
the?
that
when we follow
lets
you edit your mistakes before you enter a line.
it.
The user should follow discussions on his own
to describe thantosee.
the same as PRINT.
that
you will wanttohave printed onto the screen.
•
We
will
see in
the
machine useful as a super calculator.
that
we wanttodo is have
the
future that
the
we
the
queue, remember
off,
the
operating systemIsgoingtokill
that
when we type a ? the BASIC operating
a?
by a ",all characters after
this
is not the way most programs are operated. It
machine type a simple message.
hope by now that you understand a
thatifthe userIstypingon the
the",
you.
directly
The
editorisbest
PET,
as manyofthe
until
the
next"
it
into
the
You
should have already
little
better.
is
system
We
type
to
en-
R
E
?"HI THERE"
T
U
R
N
You will see
a key on the keyboard, the cursor moved automatically one place
next character, and nothing else happened until after the carriage return. When the carriage return
occurred, the
Let us
?HI THERE
For thoseofyou who are touch typists, you may have already made
keys.
previously struck character. This key is called the delete key, located
keyboard.
If
overstrikeofthat
out HI THERE
talk
In
we
strike the delete key once, you
that
BASIC responds by printingHITHERE. It shouldbenoted that each timewestruck
to
the right, allowingusto
HI THERE appeared almost immediately on
about the simplest function; that is, immediately correcting a mistake. Retype
B.
What we were tryingtotype wasHITHERE
ordertoallow
PET,
youtoimmediately correct
will
position.
a blank line, and READY.
We
can now finish typing
this
see that the B has disappeared. Typing the P results in
the
screen.
PET,
but we
mistake, there is a key which allowsusto
ET;
then
hit
carriage return, causing the
hit
the character B ratherthan
this
mistake with the PET's close
in
the upper right-hand sideofthe
type in the
the
line
erase a
PET
to print
P.
an
the
The delete key is
want from where you are and then retype. This is the simplest form
fundamental editing tool which allows youtostrike
14
out
as many charactersasyou
of
editing. It is implemented by
decrementing the
pointer is.
We
screenpolnter
can go back and erase the
striking the delete key. Notice two
one character at a time, and
before you see
as
it
doestooverstrike one. Also, notice
organized so
Because
of
it
blink. This phenomenon occurs becauseittakes15times as longtoblink
that
deleting
the
fact
that
the character at the beginning
deletes
line above, however,
the
40th characterofthe
thisisa pretty slow wayofediting.
(2)ifyou strike fast,
the
previous character in memory moves the pointer back over
the characters scan from righttoleft
of
fr9m where you are by one and striking a blank over where the screen
READY
facts
as you are striking;
thatisright.in .frontofour
cursor by
just
(1)ifyou strike slowly, the cursor
the
cursor will actually move several characters
continuously
will
move
2characters
that
1.'he
PET
wraps around the screen. The screen memory is
that
character.
in
40~01umn
the line, and then striking the delete
chunks, for example deleting
key
at the beginningofthe
line,
previous line. Just keying back40strokes erases the READY from the
There are three cursor movement keys on your
it
moves
CURSOR RIGHT AND LEFT
up and down, and the third key movesithome (upper left-hand corner) and clears the screen.
PET.
One key moves the cursorrightorleft;
the second key
The cursor right key mbves the pointer one charactertothe right. If we strikeitnow five times, you
see
thatitmoves us five columns over. It accomplishes
left
The cursor
that
type
we strikeittwo
moves
the
time. Obviously, by doing this, we are able
achieved by use
CURSOR
keyison the same key as the cursor right andisevoked by shifting priortostriking. If we
four times, you will see that now we are back one charactertothe
more times,itmoves us around the cornerofthe previous line. Cursor left,ofcourse,
cursor pointer one character lessinmemory. Goingtothe
to
edit the screen. However, faster editing can often be
of
the
cursor up and down keys.
UP
AND DOWN
The cursor down moves the pointer40columns to the right from
same Visual effect as moving
positions with
To cause
the
cursor right. The cursorisnow on the same position on the screen, but down one line.
the
cursortomove up, hold down the shift key while striking the cursor up/down key once;
it
down one line on
the
this
by changing the cursor pointer in memory.
rightofwhere we started. If
left,itmoves one character at a
its
current position. This givesitthe
screen. Foranexample,
try
spacing over forty
gets us backtoour original position.
Cursor up moves
the
screen memory pointer
"up"40characters from
its
current position, or rather,
characters less in screen memory than the current position.
will
just
this
40
SCREEN EDITING
We
can now use
PET
message. Once you are there, you can now delete the T by striking the delete key.
all the characters
now see the deleteisactually a matterofmOVing
substituting
INSERTIDELETE
Before analYZing insert and delete, we should be reminded
any single line may
concerned with
starting from the position
the
left,
replacing the character preceding the cursor. The cursor is then movedtothe positionofthe
the
t9
a blank.
the
cursor movement characterstogetupin position on the second H in
the rightofthe character being deleted are movedtothe
all
the
characters in memory
that
the
screen memory is organized such
consistof40or80
characters on a line. Whenever
of
the cursor,tothe endofthe
characters.
(See
section on screen memory.) Insert and delete are
the
delete key is struck, allofthe characters,
line, are automatically shifted one character
replaced character.
is
The last character in the line
automatically blanked. Insertisthe reverseofthis
15
the
You
will
left
one character. You
left
one, rather than just
process, If we want
HI THERE
notice
that
will
that
to
to
fix the line that we just
HERE.
In ordertodo that, we have to make a spaceinwhich to type theT.To
the shifted insert key with a single stroke. After striking
which says HI THERE
than one character, strike the insert key more than once; this moves all the characters on the linetothe
right, and the cursor pointstothe first character
characters on the line. For example,
positioned over the H, then delete allofthe extra
got
through taking the T out of, we need to put a T back between the blank and the
accomplish this, we strike
T,
you will note
PET,
with the cursor blinking over the first characterofthe insert.Toinsert more
that
this
now creates a screen
•
of
the~nsert.
if
we
hit
the
insert key three times, type
1's;
we will then see that the back and forth movement
This then allowsusto insert several
1's
until the cursor
is
in the line is automatically handled and we end up with a perfectly recomposed message. It should be
noted
the screen. This
that
in no time has the computer respondedtothese commands, other than making a change on
is
because we have not yet pressed carriage return to tell the
PET
that
the line is
complete.
That
is
why we have been talking about a screen editor. All editing is accomplished between the keyboard
the
and the screen memory, without interfering in any way with
the user
data, whether
corrections.
to
compose perfect text and handitto
itbeBASICorthe
It is best symbolized by:
user program,toworry about the intermediate stepsofmaking
the computer without the programmer whoisusing the
rest of the operating system. This allows
What You
LINES ON A
Physically, a line on the screen consistsof40
computer business, many data inputs are organized for
data can be put into ao columns than into
characters per line, the user is given all the flexipilityofan
allowing the screen
beginning
COMETOTHE AID OF THE
next line.
right above is only consideredtobe
The thing that allows the
beginning
See
Is What You Get.
PET
SCREEN
columnsofinformation. However, traditionally in the
ao
column data cards and,ofcourse, much more
40.
Therefore, although the
80-eolumn line. Thisisaccomplished by
to
define more than40characters as a line. If we move our cursor overtothe
of
the line below HI THERE, and start typing NOWISTHE TIME
PARTY,
You
will soon see the screen considers
we will see that after typing theE,the space is automatically on
thistobe an aO-column line although the HI THERE
a 40-column line.
PETtoaccomplish thisisthat
of
the line. Each line has a marker that indicates whetheritis
Internally, thereisa tableofpointers at the
continuation line. This pointer Is kept In the negative bit position
up
or
cursor down occurs,
PETtotheir
kept which
proper
Is
the
line
beginning pointerfor the first complete
position Is then kept as a separate pointer telling the
Whenever scrolling occurs,the line pointers are moved up
second line
is
maintained
the
editor
examines
number. At any
until
the
line
the
statusofthese line pointersinordertoInitialize the
time
while the cursor is on the screen, thereisa separate value
line
from which the cursoroperates. The screen
PET
whetheritis
in
such a way that the conceptofthe first line
disappears on the screen. This line pointer tableislocated
memory locations 553·577.
PET
screen can display only
FOR
ALL GOOD MEN
the beginning of a
of
the indexpointer. Whenever a cursor
lineora
greaterorless than40characters.
40
TO
the
PET
in
Now
that
we understand
insert at the beginning.
the curSor
up
and left, until the cursor blinks on the NofNOW. If we insert twice, we can then type a
To
that
print
the
PET
can allow80columns, let us see what happens when we do the
this
line, we havetoput a1"at the beginningofthe characters.
(it shouldbenoted that this causes the characters on the linetoall movetothe
PET
return, the
prints NOWISTHE TIME on two consecutive lines, spaces a line and types
16
right).lfwenow
READY.
We
move
carriage
If we
1"
go up and make a change in the middleofthe line, we can
the carriage returninthe
the
even though
basic rule is
cursorisblinking on theP,a carriage return causes the entire linetobe
that
when a carriage returnisstruck, regardlessofwhereitoccurs in the line, the entire line
is transferred, whether
apparent
SCROLLING
Now
when we try
base
we attempt
as
you useitwhen writing programs.
that
we have a mixtureof40-and
to
move
of
the screen. Hitting the next cursor down causes the entire screentomove up one line. Any time
to
print past the thousandth character on the screen, the screen editor automatically moves
line. If we spaceupto
the
word PARTY the first time
itbea 40-or 80-eolumn line. Sophistication in using the editor will become more
the
cursor
BO-eolumn
off
the bottom. To do this, we just cursor down until the cursor is at the
lines on the screen; let us investigate what happens
See
thatitmakes no difference wherewehit
thatitis
on the screen, now
the entire screen up one line.
the
Lines move upon
I screen. This Is accomplished
to
be scrolled
Is
screen by a one lineortwo
off
the top,
in
hardware by checking
the
81st characterthroughtothe thousanth character are movedtothe
line
jump
depending on the statusofthe top
the top
line
pointer plus one.Ifan
the screen memory, and the bottom80charactersofmemory are filled with blanks. If only a
line Istobe moved
the
bottomofmemory.The cursorispositioned automaticallyinthe same position at the bottomofthe
at
screen as
it
was when you triedtomove the cursor down;orin the caseofa carriage return and/or
printing, the cursor
off
the
top, the 41st characterismovedtothe
is
moved automaticallytothe
first, etc., and40characters are blanked
left
....
and sideofthe bottom line.
reprinted. The
line on
80~01umn
the
line
top
4O~0lumn
of
This processistotally automatic andiscaused by attemptingtoprint carriage returnorspace
off
the
bottomofthe screen. Thereisno other program control over the movement.Aswe will see when we write
that
a program
held down
HOME AND CLEAR
causes scrolling, the scrolling speed on the
while printing is occurring, the scrolling will be slower by a factorof20.
Striking the home key moves
the
cursortothe upper left-hand cornerofthe screen (the first location
PETistoo
fast to read. If the reverse key is
the screen memory). Holding the shift key down and pressing the clear key gives you a blank screen with
the cursor blinking in the upper left-hand corner. This is accomplished
screen positions and again homing the cursor. Clear
The
PET
basically moves data from the keyboardtothe screen and then when a carriage return is struck
moves the screen data
into
a program. This allows the user the
screen without having any effect on the program that
prOVided
on the screen. This allows the entire screen
to
a//ow movement around the screen and to insertordelete,aswelf as type over any character
to
or
home can be given at any place on the screen-.
is going
to
act as an editing place for user-controfled input.
by
moving blanks into all thousand
flexibilityofmaking a correction on the
receIve the corrected version. Keys are
of
17
j
Chapter
The combination
creative process. Someone who knows how
4.
of
instructionstosolve a particular problem cannot be taughtina text book. It is a
BEGINNING BASIC
to
use the computer uses his intuitionorcareful planning
figure out instruction sequencestoallow solutionofhis problem. All that we can coverinthis
all the
problems. This book cannot teach you
use the
PET
can be -except whenitis provided with pre-programmed softrware -is a tooltouse for solving
to
solve your particular problem. It can, however, teach you how
PETasan
instrument.
THE PRINT STATEMENT
A computercan calculate numbers all day but
We
will begin our discussionofBASIC with the PRINT statement for
itisof
no value unless the computations can be displayed.
that
reason.
to
book and
to
When typing text, PRINT can be abbreviated
as
? A statement such
PRINT
"HELLO"
as
this:
isanInstruction to the computer tellingitto displayonthe screen all characters between the quotes--in
this
case a wordofgreeting.
isaninstructiontoprint the productof1024
Itisusefultonote
it
write a line, print 'A' and on a second line print 'B',itis possibletowrite the line:
which
contained
as
Unless the
directed to the built-in screen.
screen, under the
the
is accomplished by the screen
computer
character
will
print the squareof1024, a few spaces, and then the cubeof1024. Detailsofthe exact format is
in
you can write down.
computer
physical
automatically
on the screen.
that
BASIC allows youtoprint more than one value at a given time. Rather than having
the next section. The point hereisthat
has been
controlofBASIC andan
representation on the screen is25fines by40characters, the
On
the other hand:
PRINT
1024·S
multiplied
PRINT
10241
2,
you can printasmany values across a seriesoflines
instructed
The
characters are
automatically
scrolls the screen up oneortwo
otherwise by meansofCMD command,
printedinthe
editor
which is keeping trackofthe screen position. Although
folding over the 41st character onto the
·8.
1024 t 3
all
print
next
available
full
lines whenitreaches the one-thousandth
print
position
printingofup to 80 characters
next
outputs
on the
line.
The
are
The
command
character which
print
variable.Ifthe data is presented in this form, the
position
automatically
characters,
return
extra spaces, variable
than seven characters,
BASIC obeys the foffowing roles for
and
after
no leading
If
the
number
notation. For example, .0034 is
the
number
PRINT has two
allows
followed
tabulates printing
prints
B,
a ; (semicolon) is used. PRINT A;B; results
or
trailing characters sent.Ifthe field to be
is fess than
falls between these values, the
for
by
'B'
followed by a carriage return.Inorder to cause BASIC to
'B'
'B'
major
printing
forms under the
the field specified
a carriage return. (2) Data presented in the form PRINT A,
'A'
startingatthe current screen
is printed.
will
.01orgreater thanorequal to 999999999.2, BASIC printsitusing
The
be printed
printing
printed
as 3.4
cursor is
after
controlofBASIC. (1)
after
the
print
fieldisprinted
position
in
the
'A'
being printed, then foffowedbyno
left
at the endofthe
spacing 20 characters, when using PRINT A,B.
characters.
E-03
most
significant9digits
When
the
field
printed
and - 1234567890.5 is
is a number, BASIC
The
standard
statement has ended in the form
startingatthe current screen
B,
then spacing over
not
send the carriage
'B'
field.Ifthe variable A is more
to be
printed
printed
are printed, plus a decimal
is a string, there are
first
as
- 1.2345678E +
19
print
single
then BASIC
10
checks
its
scientific
point
size.
Og.
If
if
needed. Trailing zeroes
a number (unless
It
shouldbenoted
screen, unlike
the
PET,
of
the data screen being covered.
most
which causes the screen to advance the screen
after
it
is
printed
that
in order to
BASICs, the apparent space between fields is always a skip (cursorright)characterin
the decimal
as
a string).
tak.
lull
point
are
not
printed. BASIC always
advantageofthe
PET's
pointer
prints
ability
byone character;
to compose text material on the
a skip character
it
does
not
resultin any
after
Because the PET allows the inclusion
programmer has
as literals are clear screen, home cursor, cursor right, left, up anddown. By use
compose fields
displayable on the PET screen.
We
previously discussed
located at memory location
full
controlofthe screen
of
any length and in any siZe starting in
how
the
8000
ASCII code.concatenated with two additional bits. Oneofthese
is
the upper·lower case bit.
When printing
characters
to
the
scr,en,
Into
the screen memory form.
the print subroutine In the operating system automatically translates ASCII
characters for the screen printer. The home character moves the printer pointer
screen.
representation for blank
In
The
clear character moves the printer pointertothe
in
allofthe 1000 characters on the screen.
BASIC, numbers are representedas5-byte binary quantities, exceptinthe special caseofinlegers,
performing operations until something equals a certain value.Inorder
to
implement programming al any level, we needtoestablish the useoffunctions which can have a variety
of
values at
programming as a variable. If you
then a book on beginning algebra,
anyone
time. A function
are
or
that
can have any valueisdefined in both algebra and in
not familiar with the conceptofa variable through mathematics;
perhaps oneofthe very rUdimentary texts on BASIC might helpyou.
Allofour discussions after this witt concern themselves with the useofvariables.
In
BASIC, variables are defined by two character alpha numerics. If the variable is a numeric variablethen
it has no
trailing character. The character A is consideredtobe
different variable. Characters
A1isa third variable, but all three are definedasnumeric values. If
the variableA.Characters AA is a
the
variable contains alphanumeric data,itIs defined as a string. A string variable now ends with a$.Thus,
Aand
A$
are numeric and string values respectively and are different variables. AA$, likewise, is different
is
from AA, etc. BASIC distinguishes a variable by the fact that the first character
alphabetic character. The second character maybeeither numericoralphabetic.
always
An
an
integer variable
ends with %, e.g.A%.
ARRAYS
Arraysisthe fourth typeofvariable which can be definedinBASIC. Arrays are differentiated by the
20
parentheses which
used
inanexpression.
follow
them. Parentheses define the particular value withinanarray whichisto
be
A(D,1)refers to
A%.
All may be specified in the same program. Specific
for each
a variable.
Equal is used in two ways: If encountered in
mathematical function: the value to the left
the right. Otherwise, when following a variable such as in the expression A
value in A with the resultantofthe expressiontothe right.
Originally BASIC required the word LET before any variable assignment, but in
and may be
To
understand how variables operate in BASIC, try the following examples on your
press
RETURN
CLR
the
first character in the second rowofa two-column array and is different fromA,A$
definitions
of
the typesofvariables follows, but first let us address some examplesofhow one uses
an
IF-THEN typeofstatement, equal means
of
the expression is compared and must equal
omitted.
A =2 is equivalenttoLET
after each command you enter.
A =
2.
The command CLR sets all variables in
and memory allocation techniques
=2+2,
?A
PET
prints
Now type
A=2+2
D.
?A
This time
Now type
PET
prints
4.
?B
PET
prints
Now replace
B=2"A
O.
the
valueofB with
twice
the value inA,by
typing
?B
PET
prints
Now change
A=2+3
8.
the
valueofAbytyping
?A
PET
prints5.If you now type
?B
PET
prints8,the
says B
= 2*
same value as before. Untilwegive a new expression for B or re-execute the one which
A,
the valueofB will remain
8.
the
the
=means replace
PET
the
LET
PETtozero.
PET.
Remember
and
standard
value
of
the
is optional
to
FLOATING POINT VARIABLES
BASIC always assumesoperation, oroperates
variable is assigned space in memory for a standard floating point number.
Four bytes contain a binary representation
9
digits
Each variable is also assigned a 1-byte exponent limited
less thgan
STRING VARIABLES
A string variable can contain a function, whether it
character. There is a specific set
precisionofa decimal number. Accuracyofmost
-34
yield numbers too smalltodistinguish from zero.
of
variables that allow extraction and packingofdata into strings which
totally,
of
that precision. It gives us the capabilityofspecifying about
in floating point arithmetic.The:refore, each normal
calculations
to
having a maximum value
be
a number, graphics character, or standard ASCII
21
is limitedtothis
representation.
of
+33. Exponents
willbediscussed later on. The stringislimitedtothe80charactersofthe
set 'of functions th'at allow the constructionofstrings upto255
INTEGERS
characters
input
buffer. Thereisa specific
(see
later text).
As we have indicated, an integerissimply a whole number. Floating point variables are stored in BASIC
with five bytes; one for the exponent and four for the mantissa, which gives
accuracyof9 digits.
In
an
many cases, variables can be expressedinmuch simpler numbers.Inordertoallow the user most
in
memory efficiency, particularly
PET
has implemented the conceptofstoring certain numbers as two-byte integer values. Any integer
value between minus 32,767
of
highest bit
USE
OF
the number containing the Sign.
PROGRAM
AND
DIRECT STATEMENTS
Throughout the text, until now, we have been using the program technique which allowedusto
to
PETto respond directly
it
directly, as we typeitfrom the keyboard and hit carriage return. Thisisso-called direct mode.Inthis
mode, we can use the
the print statement.Inthis
PET
as a super calculator. For Instance, if we want the
divide the result by a third, we can ask
get
should
the answerof2 followed by a
keyboard, except when it is
super calculator and for teaching with the
the caseofarrays which can take significant amountsofmemory, the
to
plus 32,767 may be storedinthe formofa two-byte number with the
case, BASICisobeying the command we are giving
PETtoadd two numbers and
it
the question
READY.
in
the processofexecuting a BASIC program.Inaddition to using it as a
PET,
the direct mode is quite useful for debugging
The
?(2+8)/5.
PET
If you have typed that on the
will obey any statement given it from the
PET,
of
get the
you
computer programs. Variables can be assigned intermediate values and then small sectionsofthe
be
program can
executed with
working correctly. Break points can
commands, again in direct mode, without having
or
debugging
in the caseofusing the
true computing element, one has
GOTO
statementstoassess why any particular pieceofcode is not
be
put in programs and current statusofvariables checked with print
to
modify your main program. However, except for
PETasa super calculator, in ordertoget the computertoact as a
to
write or load a BASIC program. The difference between execution
direct mode and a program is that several statements canbegrouped together in logical order and then
of
BASIC will execute all
the statements before asking the user for control.
tn
Suppose
easily accomplish
very simple. Any statement you want
by a
A good habittodevelop when typing in linesofa programisto
1,2,3,
program. All you need
To
print HI THERE, vertically, each lineofour program will type one letterofthe message. we are going
to
start with line10and make each line a multipleof10.
we
want BASICtoprint ourHITHERE message vertically as opposedtohorizontally.
this
in a program but not very easily in adirect statement. Rules for program entry are
to
be treatedbyBASIC as a program statement must be preceded
line number. A line number may be any number from 0to63,999.
use increnmentsof10or100.
etc., use
10,
20,
30.
This will give you space latertoadd
to
remember is that BASIC interprets each line number in order.
lines and make corrections in your
Instead
10?"H"
20?"1"
3O?"T"
40?"H"
50?"E"
60?"R"
70?"E"
Whether you are typing
tell the
PETtotake a look at what you have typed and act accordingly. The lines ten through seventy
a programorgiving direct commands like
RUN,
you have gottohit
RETURN
in
22
We
can
of
to
constitute a program which
The program is now resident in memory.
tells
the
PETtoprint out HI THERE.
To
execute the program, type
printed in the vertical format:
H
I
T
H
E
R
E
T.
You will note that we do not have a space between the Iand
of
the multiple
program by typing LIST. This gives
10?
PRINT
20?
PRINT
30?
PRINT"T"
40?
PRINT
50?
PRINT
50?
PRINT
70?
PRINT
tenisthat we can now insert a correction between lines20and
us
the program printed as follows:
"H"
"I"
"H"
"E"
"R"
"E"
Oneofthe reasons we use the numbers in
Now type:
25?""
Press return and relist the program, and we will see that line25is
run the program now, we get:
H
I
RUN.
This gives us theHITHERE
30.
First, display the
inserted between lines20and
30.
If we
T
H
E
R
E
This example demonstrates the useofline numbers and the abilitytoinsert lines numberstomake a
correction in a program.
There
return. Then
following the I on line
down key,
inserted the cursor-down (it looks like a reverse field
executed.Donot forgettohold down
When we now run the program, you see
is
another waytoget the same effect. First delete the space by typing25followed by a carriage
list
the program and see that line25has been deleted. Now position the cursor on the space
20,
and insert a cursor down. First by hitting the insert key, and then the cursor
if
you
don't
hit the insert key first, the cursor will move down immediately. But because you
Q), the cursor will not move until instruction
shift
before striking insert.
this
also gives you the effectifa space on the next line. This
20
would not always be true, except we had been cheating and using the automatic scrolling capability
the
PET
which clears
have received such a nice result. Try programming a home 5?"HOME", then try a clear
The
screen
the screen.
takes programs and
L·I·S·T starts
editor
The
at
out
the field. Had we programmed ahome priortoprinting a program, we would not
will
allow
you to take a program and make changes on anyofthe lines you display on
list
commandhas several features to help you
prints
the first line number in memory and
the contentsofthe basic program which is stored in memory.
get
the right lines to the screen to edit. List
lists
to the screen device
5?"ClEAR".
The
command
all
the instructions to the
is
of
23
e,nd.
The
longer-programsteaturesoflist
lists
just
line
20,
LIST 10-50 which
numbers
lines from line 50 to
correct
your PET
fromth~·fJeginning
any
pieceofprogram
just
to see
which
lists
lines
of
the program through line50included,
the
endofthe program. Some
whichiscurrently
what
they do with
our
allow
you to
10
through50included,
combinationofthe above can be use(nO
little
stored
program.
in memory.
list
onlyasingle
Try
line-nurtlber
LIST-50 which
and
LIST
50-
which
eachofthe above commands,on,
lIST
means'
list
Iists-aH'oUhe"
find"and'
2fJwiifcft'
61Pt#e
BASIC is an interpretive language relatedtothe direct commands we are executing. BASIC executes a
command by taking the last line typed
words and expressions which
it
which Is the token for PRINT),Itinterprets
Command words are stored In memory
As
a program
lineisentered
into
line number and searches through memory,
it
is the same line number, then the entire lineinmemoryisdeleted and a new line is inserted In memory.
toItand analyzing
recognizes. Every timeitencounters a key word such as PRINT
this
word
with
bit
8ontotell BASIC
RAM
memory through the useofthe carriage return, BASiC
untilitfinds the same number,orthe number Just greater. If
In the pre·interpreted stateall the key words are replaced
to
This allows the interpreter
by
is the data typed in
PRINT, even though
BASIC is called
an
keyword that needs
the programmer such as literals, pointerstothe variables, and the keywords.
it
takes five characterstotype,
interpreter because the actual execution of the instructions is donebyanalyzing the
tobeexecuted in the program line,then executing that keyword under the control
store commandsinthe most memory·efflcient form. The
the
line working from
into
a command which means somethingtoBASIC.
lefttoright looking
thatitIs a command word,orkey word.
with
the single character token forthe keyword.
only
data stored
only
takes one character in memory.
fOr'
(or?
takes
key
the
of
a seriesofsubroutines. This is a trade-off which results in very memory-efficient storage programs but
longer execution
times
tokens in memory and stores them on
of
coding
use BASIC
data on tape or in memoryisnot transferabletoother machines. Itisgenerally not possible to
instructions
than wouldbetrueofa machine language program. Because
I/O
devices whenever a programisloaded and saved, the actual
typed in from other machines.
PET
BASIC uses
,
When
editor
carriage
and
To
listitfirstonthe
same
There are two ways to execute a BASIC program.
first
instructionofthe
more
numberofthe
print
direct mode, operates
course,
LITERALS
In
quotes.
you create a BASIC program you are
and
the
BASIC line editor.
retumtransfersitto
delete
delete a line, you type the line
clears
old
lines.
line
number
all
the program variables
instructions,
first
THERE
insteadofHI THERE. RUNisexecutedindirect
must
specify
screen
program
and
with
new
and
ENDisencountered,orthe stoP keyispressed. RUN
instruction
the
same as RUN except
the line
The
main
memory.
number
aiteritthen type a carriage return to re-enter it.Toreplace a line,
text
and
in order,
to be executed. For example,ifyou type RUN30,
numberofthe
screen
type carriage return.
and
startingatthe
operating
editor
The
immediately
initializes
allows
BASIC line
The
lowest
that
first
statementtobe
the program pointers.
noneofthe variables are re·initialized.
our HI THERE examples we have used PRINT commands
In
the
PET
these are called literal strings. Dataisalso kept in the
under two levelsofeditor:
you to change characters within a
editor
followed
firstoftheseisto type RUN.
number. Execution
allows
by
mode. A GOTO statement,
with
you to
a carriage return.
Thenitexecutes each
may
executed, e.g. GOTO
characterstobe printed enclosed in
the screen
add
new
continues
have as an
our
PET
in binary floating·point
character
line
until
lines
and
modify
To
modify
The
command
until
sample program
also
The
30.
a line,
enter
there are
argument
executed
GOTO,
the
the
RUN
no
the
will
in
of
24
numbers. Muchofthe data you wanttowork with in programsisnot numeric but alphanumeric••the way
talk
we
These characters are specified
contained within a set
To
the
more sophisticated techniques.
We
Graphics characters are stored as
original 64 character set and they are stored
the lower characters on the keys. A literal can be used
print HI THERE.
back and forth as human beings.
to
the
PET
with literal strings. More specifically a literalisany value
of
quotes.
allowthe maximum compositionofscreen data,the
abilitytostore and execute cursor control characters which are fedtoIt by meansofliteralsorother
have already discussed in a section on
an
PET
keyboard input how the
extensiontothis
in
memory with a special indicatortodifferentiatethem from
PET
has a special setofgraphics characters and
PET
stores
set. Graphics are produced by shifting from the
to
draw a line just as easily as it can be used
its
data in ASCII.
to
Any combinationofcharacters within the
cursor movement and the reverse field.
you are typing in a literal whenever a quotation mark
t1"lP
is typed until the
the screen in a format so that the software which transfers the input linetoBASIC will transfer them as
control characters
You can see the cursor movement characters flagged with reverse field within a literal. Type a single
quote and see
heart. Cursor down Is a
bracket and cursor left
dots. Insertisa shifted
You cannot entera character in reverse field into a literal but you can turn on reverse field with the control
character before your character
between quotes are those which are interpretted as control characters.
Delete
been typed on a line, you lose the
or
You should note at least one time while you are editing that you have fallen into the aforementioned trap
of
return, then cursor up
is
a carriage returnistyped.
tryingtomove the cursor after a quote has been typed.
the
this
only
that a closing quotation mark is entered, all characters are transferred directly
if
thatisappropriate.
happen. Reverse field looks likean"R".
"a" and cursor up
is
the
shiftofthat character and looks like avertical linethrough the 5th column
"T"
which looks like a second vertical line.
is
printed. The only characters that are allowedtoappear in reverse field
editing character that will still work within a literal. Once an odd numberofquotes has
abilitytomove the cursor about the screen until either a closing quote
to
edit your mistake.
PET
keyboard may be typedinas a literal and
PET
has a special modeinthe screen editor which assumes that
is
typed. From the
Home isan"S"
is
the shifted "a" or hole character. Cursor right
EithM
type a phoney closing quoteoracarriage
time
that the first quotation mark
and clear is a shifted
this
includes all
is
"S"
a right
to
or
of
Another method
function.
to
try
mode
you struck the insert function.Itis suggested that you make up your own examplestoplay with this.
Examples may also be suggested
The
depth
recommend
with the use
It
do a cursor movement, the control characters will be flagged with reverse field
is
easytoget
abilitytoreadily manipulate the graphics and the cursor movement characters can allow whatever
of
graphicalcapabilityyou have thetime and patiencetoprogram.The computershould be fun.
of
inserting cursor control characters into already existing
has the same effect asanopening quote. For example,ifyou type insert three
outofbecause you need only enter as many new characters as the numberoftimes
to
you as you make a few editing mistakes.
that
you develop your own programming
of
Imbedded graphics and cursor movement characters. Remember
skills
with the text and contlonually experiment
textisto
that
use the insert
just
you cannot
times
and then
as before. This
hurt
25
We
the
machine;..
stuff.
REVERSE FIELD
We
have shown in the examplesofquote mode and insert how once a mode has been established for a
line, the
carriage return. Reverse field works in the same way. It remains
is
typed or a carriage return is entered.
As
describedina previous section on screen memory, reverse field characters are stored with a special
bit on
spots
effect and doubles the number
useful that
as well.
Here is
field on and type
This gives us a
Reverse field remains on from the first
subsequently typed on the screen
previously mentioned. This applies equally to keyboard inputaswellascharacters printed from a literal
string.
the"
worst
PET
will
to
indicate the black spots in the characters coming from
willbeblack.
it
is not only implemented on the
an
exampleofhow reverse field works: Clear the screen and typeHI(space). Next
that
can happen Is
continue with that function untilitis either cancelled by a new control characterora
As
you will see when you typeanexample,
of
TH
ERE
line in which we have highlighted THERE.
.Finallytype reverse field
that
you clear the screen accidently after typingina bunch
in
effect until a reverse field
ROM
will be all white and all the white
this
gives a very desirable highlighting
potential characters which the
PET
display but in someofthe
off,
(shifted reverse field on), type (space),PET.
time
the control characteristyped and alt characters
will
be printed in reverse field until the mode is terminated as
PET
can display. This feature is so
PET
hard copy printers
off
character
hit
of
reverse
we
To get the
inserted.
characters
THERE
until the titeral
screen memory, a screen position
is received
character or a carriage return is typed.
TERMS AND OPERATORS
The
communication with BASICiseitherwith numbersorwith alphanumeric literals. Numbers are always
presented in decimal form even though the microprocessor in the
to
keep the
representing
precededbya $··e.g. $0010 is equalto16.
As
BASIC recieves Jines, the interpreterdivides the charactersitsees into several classes. Such
commands, functions and operators. PRINT is a commandtoBASIC with a specific function
perform.
A function can be something
the keyboard, you get a constantof3.14159265, which can be usedinan
PETtotype
TYPE
?"HI (reverse field on) THERE (reverse field
occupy
is not in reverse field yet. The effectofthe quoteisto postpone the actionofa control character
is
by
the program which printsiton the screen. Reverse field remains on until a reverse field
two
straight,
itindecimal
out
in reverse field we use a literal with the control character for reverse-field-on
off)
PET". Note that the reverse field on and
a space on the screen when programming and
interpreted. Since the reverse field is turned on by setting a bitofeach character in
is
not required for reverse field onoroff
PET
will
assume that whenever we are talking about a number,
form. Later when we
like square rootora variable, or a special function. Whenever you type
talk
about hexadecimal numbers, they will always
that
they appear in reverse field, but the
when the streamofcharacters
PET
operatesinbinary mode.Inorder
we
that
expression.
are
as
PET
off
off
be
can
non
An
operator is a character
in
evaluating an expression. The following setofoperators are defined for BASIC:
Plus sign
(+)
causes
thatisinterpreted by BASICasan
two
valuestobe added together using floating point representation with the results
arithmetic function which istobe
26
performed
Loading...
+ 118 hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.