广告
广告
PERSONAL COMPUTER
PET USER MANUAL
MODEL 2001-8
PET 2001-8
PERSONAL COMPUTER
USER MANUAL
OCTOBER 1978
The information in this manual has been reviewed and is believed to be entirely reliable. However,
no responsibility is assumed for inaccuracies. The material in this manual is for information
purposes only and is subject to change without notice.
first edition
O Commodore Business Machines, Inc., 1978
“All rights reserved”
Commodore Business Machines
901 California Avenue
Palo Alto, California 94303
TABLE OF CONTENTS
Chapter 1. WelcometoyourPETcomputer. ..... oii iii tiie ieee en 1
Chapter 2. Unpackingyour PETandturningiton ......... ee 3
Chapter 3. Basickeyboardinput ................ PS 11
PET keyboard
Screen editor
Chapter 4. Beginning BASIC .............—._7.e0xsvrsarenavedererevmeno, 19
The PRINT statement
Variables
Direct and program statements
Literals
Functions
Chapter 5. Elementary programming ....... —.—.r—.—rersrerercenorererenenes 32
Unconditional and conditional looping
Data entry
Chapter 6. Advancedprogrammingtechniques .............. ccna... 38
String variables and functions
Subroutines
FOR NEXT loops
Subscrpted variables
Chapter 7. PETcommunicationwiththeoutsideworld .................... 57
PET interfaces and lines
Commands and operations for
peripheral devices
IÈEE-488 bus
Chapter 8. Machinelanguageprogramming .............._rerereesverono 91
Allocation of memory
Commands from BASIC
Machine language monitor
Chapter 9. Errorsanddiagnostics. . o.oo iii ere 113
Debug techniques
BASIC errormessages
OS error messages
- al bg
que
2.1
2.2
2.3
2.4
2.5
2.0
3.1
6.1
6.2
7.1
7.2
7.3
7.4
7.5
7.6
7.7
7.8
7.9
7.10
7.11
7.12
LIST OF FIGURES
Rearviewof PET 2001... i.
PET Memory bus «ee ea
Memory map by functional blocks .............eoeeeradanenao
ASCILcode in main memory ......... e e.eenrdea0r0ad ies ara
ASCII 6 bitcode ...........—......000r0s00ra rea a ea aa na ae
PET graphic character codes ........... TT e.
PET keyboard scan lines. ...........eoeceeesranacieoraranD.
Functions expressed in terms of built-in BASIC functions .......
Principal pointers into PET RAM ............ user.
Simplified view of PET .................. e..sraariaa,
Edge connectors J1 and J2...........—... rm .esrioree ,eaanaa,
PET tEEE connector pinout .......eeee eses aranedenannano
Receptacies for the IEEE interface ................_. eme...
IEEE standard cCOonneCcCtorS ...0 As
Parallel user port information... cc iin...
6522 VIA addresses in PET ......... ii iii кваку..
Parallel userportexample ........... iii 4 ae a en
Connector J3 contact identification .........c... ui...
Second cassette interface port ........... ii...
PET second cassette edge connector J3 ............e_ eva.
Edge connector J4................0arereerereaeennanene oo
12
43
55
57
57
58
58
59
59
61
62
62
62
63
63
7.13
7.14
7.15
7.16
7.17
7.18
7.19
7.20
7.21
7.22
7.23
7.24
7.25
7.26
8.1
8.2
LIST OF FIGURES(continued)
Memory expansion connector aia
Multiple file structure ........220000 04444 44 4 a a ea ea eee eue
OPEN for write from PET ..............e0reserenrevaveeen.
OPEN for read to PET .........2.2220 4000 ea eee a 11 0e ea ana 0
Status word errors .........242424000 000124 ea a a a ee eau 06
Default parameters .......... ccc vias. a a au a a ea eu 00
Examples of default paraméters ......222 20000010 a a es sa ea a 00
IEEE bus contact identification ............... o.oo lL
Transfer bus handshake sequence ...... CO
Byte transfer from talker to listener..........—.—e_e-eeorenevana
Signals described by IEEE bus groups ............e——.e==.—.
Status codes for IEEEbus ......-220200 0044504 a a aa ae ea een 00
|IEEE-488 register addresses in PET... ...... oii eee
Code assignments for command mode operation. .............
Example Floating Point Numbers ............... cv iain,
Machine Language Monitor Listing ............. cc iil,
63
69
73
74
80
82
82
83
84
85
87
88
88
89
34
LIST OF APPENDICES
Detailed PET memory map
BASIC statements
BASIC commands
Expressions and operators
Space and speed hints
Main logic board assembly
Suggested reading
Chapter 1. WELCOME TO YOUR PET COMPUTER
Congratulations and welcome to the exciting new world of personal computers. By selecting
the PET 2001 you have eliminated the problems of getting a personal computer system running. Your time
is now available for learning the functions and capabilities of your PET. In fact, if you follow a few simple
procedures outlined in this manual, you should be able to achieve initial operation of your Pet 2001 within
a short period after unpacking the shipping container.
The potentials of your PET are virtually limitless. This book, by its very nature, is limited. Questions will
arise that this book has not covered or even anticipated.
Write to us at Commodore with your questions. We will answer many that you and other users will pose
with a newsletter we'll be sending out from time to time to users.
Commodore Systems Divisions:
901 California Avenue
Palo Alto, California 94304
USA
360 Euston Road
London NWI 3B1
England
3370 Pharmacy Avenue
Agincourt
Ogtario, MIW 2k4
Canada
PET is a Personal Electronic Transactor. Everything is complete in one steel cabinet. It contains a CRT
board, keyboard, computer board, and a Commodore supplied cassette. There is a built-in black and
white television monitor, which displays characters in a format that appear to you to be forty characters
by twenty-five lines.
At the heart of your PET 2001 is an MCS 6502 microprocessor. This microprocessor totally controls
operation of the screen, keyboard, cassettes, and additional peripherals which can be added to the PET.
The product is so construed that you cannot damage the PET from the keyboard. The operating system
cannot be destroyed because the computer software, or operating instructions are contained in a fixed
memory. {Called Read-Only-Memory) This allows both the first time user and the sophisticated user to
use the PET with impunity.
In order to satisfy the needs of the serious user as well as the first time user of a computer product, we
have used three formats in this manual.
Summary discussions in this type font are designed to answer the questions of a professional
programmer. When you are first using your PET manual, read these sections lightly and spend time on the
more detailed explanations which are in the type font of the preceding paragraph. After you have used the
PET a bit, the italicized summary sections will be useful when you want to review how a particular
instruction works.
The third type of format gives a detailed description of how the PET Implements a section. These
sactions are for people who use the PET at the machine level. The first time reader may find these
sections difficult to follow and we recommend he/she use them only on re-reading the material when
more familiar with the PET operating systen:. The language which you will use to communicate with your
PET is called BASIC, an acronym for Beginners All-purpose Symbolic Instruction Code.
It should be noted that there are otherrefarence. material written ajout BASIC, with different types
of usage in mind, which are available to the public. We have included a list of such suggested reading in
the appendix. Some of these manuals may be more useful to satisfy a specific need which is not covered
in this particular manual. Ts
The ultimate teaching device for learning how the PET works is the PET itself. In some cases, we will
ask you to use the PET along with the text, rather than just continuously reading what to do. In any
case, this documentation is sufficient to allow you to get started on an example. By constructing similar
examples of your own, any questions which might arise are answered by the machine itself. Of course,
we invite comments on this material and particularly on examples which you as an individual have used
to resolve any unclear statement.
Lastly, since this manual cannot presume to provide all technical information of hardware or
programming aspects of the MCS 6502 microprocessor, we direct you to two other Commodore
publications: There is a manual available from your dealer called Hardware Manual which also includes
descriptions of the auxilliary devices which generate the control signals necessary to aliow the PET to
operate. Detailed specifications of the computer and the language in which it operates are available in a
book called Programming Manual. This is available for purchase from your PET dealer or either can be
purchased from Commodore directly.
NOTES
Chapter 2. о oo “UNPACKING YOUR PET AND TURNING iT ON
Please check the carton for any y special unpacking instructions and carefully examine your PET for any
concealed damage. !f anything is amiss, reportly this immediately to both the place of purchase and the
shipping agent.
Remove your PET from its protective shipping carton and place it on the counter, desk, or other suitable
surface, then plug it into any standard, grounded electrical outlet. Un some countries no plug is provided.)
~_ SN
je I
Tv BRIGHTNESS
ADJUSTMENT
—] Jo
== —
SWITCH
=F 1.54 FUSE
MEMORY | Вы ING © = INTERFACE J1 (SLO BLO}
INTERFACE J3
PARALLEL WINE AC
USER PORT Jé POWER CORD
SERIAL NUMBER
AND
ELECTRICAL SPEC.
Figure 2.1. Rear view of PET 2001-8 showing switch,
fuse, line cord and interfacing connectors
The power switch is located in the left rear of the PET. Closing the switch to the left turns the PET on and
closing it to the right turns it off. (There is a white dot on the power switch to indicate it is in the power-on
position, or an ON/OFF label.)
Immediately, when the power switch is turned on, power is supplied to the internal circuits. There is a
time-out circuit in a special condition {reset condition) which initializes them into a known state. If the
screen has had power immediately prior to this time, you will see on the screen a variety of strange
characters which reflect the current contents of the computer memory which is controlling the screen.
The screen memory transfer to the screen is done with circuitry outside control of the main
microprocessor, and so, even when the computer is not operational, the screen always displays the
current contents of the screen memory.
=
At the end of the power-on cycle, the computer initializes the internal memory, ‘blanks the screen
temporarily, and then displays on the screen a message. like the following:
+++ COMMODORE BASIC*** . -
7167 BYTES FREE
READY.
J
The 7167 refers to available users’ programmable memory. A byte is the fundamental data element of the
PET computer and corresponds roughly to one letter or digit of information. The 8K model should show-
in theory - “8192 bytes”. But a few hundred are used by the PET internally. The balance shown “7167” is
net available bytes.
If you fail to get the power-up display the first time, try tuming the power switch slowly off, then back on.
To get the display, four different types of memory are used: ROM, User Read/Write, 1/0
(Input/Output), and Screen Memory.
The relationship between these memories is shown in figure 2.2.
6502
microprocessor
AN
vd
address and data-bus
A В A №. A
Y | Y y “Y
ROM RAM TV RAM 10
14k Bk 1k 2K
N
keyboard user port
NY
IEEE-488
Figure 22. PET memory bus
ROM (READ ONLY MEMORY)
ROM causes the PET to perform most of its operations. In each PET, 14K of ROM contains a series of
programs written by Commodore which scan the keyboard, print the display, control input/output, count
the rea! time clock, and execute commands that the user types in. Read Only memories are not only
the lowest cost memory for storing this data, but also give the user the most protection and the fastest
operation of his machine. This is because the operating system memory is indestructible from the
keyboard, or from the user's program. Not only is the machine available to run basic from the moment itis
powered on, but also the user program cannot damage the basic operating system.
/O MEMORY
The second type of memory is that which is devoted to Input/output operations. This memory contains НО
devices called PIA* and VIA** which allow the PET to individually contro! the bits that manipulate the
computer. Except when special 1/0 operations are desired, the user should not allow his program to
interfere in any way with these areas. The operating system automatically handles these locations in
order to perform legitimate Input/Output operations.
USER READ-WRITE MEMORY - R.A.M.(RANDOM ACCESS MEMORY)
The third type of memory is the User Program Memory Space, (We will call this area RAM
throughout this book.) In a standard 8K PET, it is located from location $0000 to hexidecimal
$1FFF. A detailed map of all the memory is included in figure 2.3, showing where the ROM,
RAM, 1/0, and Screen Memory are located from a programming standpoint. As you can see
by the map, the first 1024 bytes of memory are reserved for the operating System to use
for its various tasks, including the buffering of data from the cassettes and other 1/O devices.
The message “7167 BYTES FREE" is a result of an analysis of BASIC which starts at
locxation 1024 and cycles through the memory to determine which locations are available, thereby,
performing a check on whether or not the Read/Write Memory is working correctly.
If the number was less than 7167, you may have a hardware problem. If the number is
greater than 7167, you probably have added your own memory. BASIC can automatically check
up to 32K of RAM as long as the added memory is continuous to the memory that comes
furnished with the PET. This memory is really the working memory in the machine; it is where programs
are loaded and BASIC holds all of the program variables.
Later on, we will discuss some techniques to expand this memory by using tape files and
program overlays.
SCREEN MEMORY
The screen memory is physically composed of the same kind of chips that are used to
make up the PET's standard memory. It is constantly being used by the CRT control electronics,
which takes the individual bytes of memory and uses them to address a special character generator
ROM, thus displaying characters on the screen.
As mentioned during the power-up discussion, this process is totally automatic, and the programmer has
no direct control over it.
*PlA - Peripheral Interface Adaptor
""VIA - Versatile Interface Adaptor
For information about these and related chips, see 6502 Hardware Manual.
a a a ОНО
0
Operating system and
RAM BASIC working storage
1024 9 9
RAM _ _ ser BASIC program
User Variables
8192
Expansion RAM area-24K
33792 2 ToT — — — — == — — —
34816 Images of TV RAM
35840 Images of TV RAM
36864 Images of TV RAM
Expansion ROM area-12K
49152
ROM BASIC
59392
Vo
61440
ROM operating system
65536
Figure 2.3. PET memory map
On every cycle of the TV screen (1/60 of a second), the hardware starts with the least address
($8000) in the screen memory and processes the screen data starting at the upper left-nand
corner of the screen. Each character in the memory is addressed into the character generator eight times,
giving us an 8 row high character on the screen. The character ROM that is used generates
8 dots each time it is addressed. These dots are serially fed to the screen, working from left to right and
top to bottom. This gives an 8 bit wide 8 bit tall character with no spaces between characters. The CRT
controller automatically changes the addressing of the character generating ROM, depending
on whether or not it is scanning the top line of a character, the second line of of a
character, etc.
There are two character sets stored in the ROM. You can change the character set on the
screen by POKEing memory address 59468 with a 14(a 12 turns it back) which turns it to
the second character set. After you have played with the screen a little bit, you may want
lo try this feature to see if your PET performs this way. The second character set substitutes
lower case letters for the graphic set that is available in the first set.
To understand this, let us review how characters are represented in the PET and in the memory.
CHARACTER REPRESENTATION IN PET MEMORY |
The standard ASCII code is used to represent characters in the main memory. (RAM)
In the PET, the 8th bit (bit 7) is used to signify BASIC command words or graphics characters for the PET
screen.
В o! i e в ka 1 1 i i
1 Hl i y i 1 u 5 1 1
1 41 Y i Y 1 a] i e 1
218 |
Неве | NUL PLE SFr y @ H SH о
вена | SUH nel 4 1 A G a a
НН | six vie i z 5 k b r
il | Lix Des # > с > с 5
Gil | EVI 4 + 4 X 1 a t
Gigi | ENG NAK A > E U e Ч
diis | HACK SYN & b F + y
Gill | BEL £iB 7 G id a ww
1866 | Bo CHIN Ç ti H A ki X
18021 | Hi En ) y } + i y
118 | LF SUB # : J Fl J #
111 | vi ESC + ; К L к
ile | +t Fo , < E x 1 |
1181 | CR 55 - = i 4 rh
111 | SU Ks . > N T ri
1111 | si Vin 7 7 5 € o
Figure 2.4. ASCII character set (7 bit code)
Example in the PET:
A is represented 0100 0001
Shifted A (a spade) is 1100 0001
The screen memory is organized with a different representation from the main PET memory.
There are only 64 characters from the standard ASCH set that are normally printable.
В 61 в y b ki
1 wi e ki 1 i
| 41 ti 1 e 3
del |
весы
Bei
uly
BELA
Yigg
divi
11H
uili
1606
1641
181
1611
118
1161
1lid
1111
=
-
=
сот опоголс об. не) ПО бо ОПГ DR
ток ан о„огбобо со омоЖо к со — AL"
| = + LA ERA E
Pe = CU SCRHC
"e. Nr #
Figure 2.5. ASCII 64 character set (6 bit code)
7
These are the same characters that are directly available on the PET keyboard.
The representation in screen memory is derived from the standard ASCII set by dropping bit
6; giving us a six bit code for the keyboard characters,
The graphic, or shifted characters, set Is represented by a 1 in bit six of the screen memory, giving an
additional 64 displayabie characters.
This gives the following table for PET displayable characters. It should be noted that ail of the graphics
characters are organized so that they are just a shift from the normal keyboard character.
В 6 |
l Si
1 41
selu |
ECC
=> a
CPC
pa = С
& >
— >
© > >
+ => >
Udy
Baul
Uely
gil
vido
Givi
Blip
ili
1809
1841.
1616
1013
1166
1161
1118
1111
| = ETAPE SN 4e >
LLC Сб бо К
r >> |
me TT À FE
YL o,= 1
CEL EN AL об тост
T= ACC NE LOHNT
Ch f
se +
A ELLO. El ...
Fm
NS
Г +
a’
Figure 2.6. PET graphic character set (7 bit code)
Example: This gives us the foliowing conversions:
Character In main memory In screen memory
A 0100 0001 00000001
+ 1100 0001 00000001
1 0011 0001 00110001
— 1011 0001 01110001
Note the reduction from seven bit ASCII to six bit gives the effect of changing the order
of A and 1. In screen memory, the 8th bit is used to store reverse field. The reverse
field consists of taking the dot pattern from the character generator and reversing it, replacing
a white dot with black and a black dot with a white.
If the operating system is used, it automatically translates the values from ASCH into the screen
memory representation. Both PRINT and direct input from the keyboard result in automatic
translation between the screen memory and the main memory.
USE OF THE SCREEN MEMORY |
There are three ways to get data into the screen memory. The “first of these is to POKE into
the appropriate memory address the desired’ translated character. This is programmed only when
normal updating of the screen is too slow.
As long as the PET directly controls the screen, there is no apparent effect from the fact that the screen
and the PET are contending for access to the memory. The routines in the PET change the screen
memory only during times when the screen memory is not being used for display. This slows
the use of the screen memory down to about 40 percent of the speed obtainable with a POKE. The POKE,
however, gives a visual effect of flashing dots, because the screen Is displaying the character
that Is being passed from the PET to the screen memory, rather than the character that
should be displayed at that particular position. When a program pokes to the screen, the faster
it runs the more flashing there will be.
The second way to get data onto the screen is the keyboard. During a time when keyboard input is
enabled, the character being struck on the keyboard is automatically displayed on the screen.
The third approach is by use of the PRINT command in BASIC. When »
PRINT “ABC”
is typed to BASIC, it results in the next line being printed as:
ABC
This is a print of a literal field in which all characters between the quotes are printed.
The next position at which a character will be displayed if typed on the keyboard is indicated
by a flashing signal called a cursor. The cursor is a visual indication to the user of the next
print position in screen memory.
What is physically happening in the machine is that everytime the screen is recycled, about
1/a0th of a second, an interrupt to the PET is generated. This generates a real-time clock on the
computer (the PET) and steps a blinker counter. When this counter reads 37, the character referenced by
the screen memory pointer is reversed in the Bth bit. This causes the reference character to
be shown in alternating normal and reverse field, giving as visual effect of blinking.
By moving the pointer, we can print output any place on the screen. This is done by using a combination
of the keyboard and some software called the screen editor, which manipulates screen memory under
control of the keyboard.
Chapter 3. BASIC KEYBOARD UNIT
Whenever the blinking cursor appears on the screen, the computer transfers data from the
keyboard to the screen memory.
Keyboard data is transferred by the interrupt routine to the screen memory each time a new
key is struck. Only after a carriage return is the keyboard data transferred to the operating
program, and then a whole line is transferred at once.
There are two exceptions to this, neither one of which causes the cursor to blink. One of them
is the use of GET, which will be discussed in a later section, and the other one is when
the keyboard data is accessed directly using machine language programs.
The PET keyboard has been optimized for use as a computer keyboard, though the organization
is similar to that of a typewriter so a touch typist does not feel totally out of place.
However, some important changes have been made:
i. Because of the high use of numbers and calculations with the computer, a calculator-like
number pad has been added to the right of the main keyboard.
2. The number pad has all of the mathematical operators in a form that is normal for BASIC.
2. The various keys for screen movement and editing are located on the numeric pad.
4. The characters which are normally the shift of the numbers on a standard keyboard no
longer require shifting. These characters are quite often used in BASIC, and it is
convenient to have them available without shifting.
5. All standard characters are unshifted, so that a complete 64-character graphics set is
available by use of the shift keys. These graphics give the PET significant line drawing ability.
PET KEYBOARD
The keyboard consists of 73 keys, including Two shift keys, either one of which may be pressed to cause
the upper or shifted characters displayed on the keyboard to be operational. Lower characters
are always used unless one of the two shift keys is pressed simultaneously. Each key has
a thin, transparent plastic film covering the keytop which should be removed. This protection was
left in place to protect the keys against scratching during shipping. To remove the film, carefully
peel it off by using the sticky side of a piece of masking tape so as to avoid scratching the keytops.
There are 64 printed characters on the keyboard with 64 upper Case, or shifted characters on
the same keys. The rest of the keyboard consists of function characters. Some of the functions
are obvious: like character return or cursor right and left. Reverse on allows all subsequent characters to
be diplayed in reverse field - black on white.
The reverse key is operational on a memory basis. From time to time the key is struck, the
function is operational until it is terminated by a RETURN pressed or printed, or by pressing reverse-off
(the shifted reverse key). This concept of reversal of function, up and down, right and left is carried
through to the function keys, so that the complementary functions are usually combined, with one being
the shift of the other.
The keyboard is scanned using a 6520 PIA, a four line to ten line decoder and the interrupt
routine from the CRT controller. Each time the interrupt occurs from the CRT, the keyboard is scanned
using a left to right scan. The keyboard is organized on a 2 x 5 row matrix with the matrix
being repeated 8 times across the keyboard. To implement noise protection and N Key roll
over, the keyboard scan routine keeps the final value of the last scan in a buffer.
Until that key is released, no other keyboard scans are acknowledged unless a later scanned key
is struck. The later scanned key is then considered to be the next key closure. The algorithm does not
11
OLVES 94 8909659 = ус sessosppe i8)s|Bas eleq vid
USS pasogisy 13а "с эпбы
SEE OOOO!
)(e)(<)(e)(e)e)(e)e
=)(2)(2)(2) (8) (2) (9) (2)
*Peuueos ei
Aey UBA
fe
E)
ll
E)
0
JUSIUCO 5]
undead
9JeWNy
ea) e)
aja
|=)(®) (9) (5) (2)
(9) (а) (9) () (2)
Ce Ju
ae)
eee
spcoag pieogAay
12
l
give classical N key roll over but does allow for legitimate rejection of noise and trapping of the keys
in the order that they are struck.
The keyboard is left scanning the last row, which contains the stop key. This allows the routine in
BASIC, that checks for the stop key to sample the input VO device, without having to perform any
of the normal functions of scanning. The user can take advantage of this by reading the input character
for that row.
The shift key is a special multiple key closure and is treated separately. If either of the two shift keys
is pressed, the software sets a special shift switch which is used to change the decode of the key.
All key closures are translated using a ROM-based look-up table for the key. The shift key is encoded into
bit 8 of the ASCII character which is then translated into the screen representation in the standard way.
Once the hardware translation is done, the encoded value is transferred into a 10 character keyboard
queue. The keyboard queue is loaded every time a new key closure is sensed and is unloaded as soon as
characters can be transferred to the screen. *
This input queue is scanned by the GET routine directly to allow input without going to the screen. The
input stack may be scanned by a user program. The user program can look at the pointer at location 525
to determine whether or not it is greater than zero; if it is, that means that there is data in the keyboard
queue. The keyboard queue is located at 527-536. The first character may be taken out; all subsequent
characters moved down, and a load index pointer decremented by one.
This is a dangerous routine, unless written in a machine language with the interrupt masked, because a
new key closure could store a new value during a time that you are scanning and changing the queue.
Both the GET and keyboard input routine take care of that automatically by only operating during the
interrupt or with the interrupt masked.
Whenever the screen editor routine is operational, a special two-level operating system is in play. The
first level enables the cursor to flash and writes data trom the keyboard to screen memory at the current
cursor position. The routine then moves the cursor one character further down in memory. The process is
repeated, trying to keep th keyboard queue empty.
The second level flashes the cursor and translates and stores characters from the keyboard into the
keyboard queue. Meanwhile, the first level operating system always watches the input stream for a
carriage return. After the carriage return is printed, this routine automatically transfers the entire line to
the operating system. The rest of the operating system does not see the characters until they have been
typed and a carriage return is sent. This allows for total editing of the line, prior to handing it to the
operating system.
An interesting trick for the more advanced programmer is to use the PET to write its own programs. By
printing out a line to the screen, forcing a carriage return into the keyboard queue and then returning
control to BASIC, new line numbers may be entered into the memory. Another example of the use of the
keyboard queue is the LOAD/RUN sequence which is implemented by the keyboard scan program when a
shift-run is encountered, the routine automatically forces «) OAD, CARRIAGE RETURN, RUN CARRIAGE
RETURN” into the keyboard queue. When control is returned to the input routine, the load followed by the
run is automatically transferred in the proper order.
it should be noted that this keyboard queue is only ten characters long and if it is exceeded, dramatically
bad effects can happen to your system. The only known recovery from exceeding this queue is to power
13
. "a . .
E ee mmm
a aa A то.
the system back on and start over. When tooling with the queue, remember that if the user is typing on the
Néyboard and you do not have the Interrupt turned off, the operating system is going to kill you.
SCREEN EDITOR
Typing on the keyboard, while the cursor is active, transfers what is typed on the keyboard directly to
the screen. This function is like a simple computer terminal which requires you to retype a whole line
until you get it right, but the PET lets you edit your mistakes before you enter a line. The editor is best
understood with a PET to illustrate it. The user should follow discussions on his own PET, as many of the
examples are much more difficult to describe than to see.
To follow these examples, two concepts are necessary. One is that when we type a ? the BASIC operating
system is goling to interpret the ? the same as PRINT.
The second concept is that when we follow a 7 by a “all characters after the”, until the next ” is en-
countered,
are treated by BASIC as characters that you will want to have printed onto the screen.
In this section you are operating the computer in what is known as a direct mode. (I.E. rather than
programming mode). BASIC is executing each instruction like print as soon as you type it into the system
and hit carriage return. We will see in the future that this is not the way most programs are operated. It
does make the machine useful as a super calculator.
The first thing that we want to do is have the machine type a simple message. You should have already
done this with your users’ guide. However, we hope by now that you understand a little better. We type
the line:
?*HI THERE”
a DC тт
You will see that BASIC responds by printing HI THERE. It should be noted that each time we struck
a key on the keyboard, the cursor moved automatically one place to the right, allowing us to type in the
next character, and nothing else happened until after the carriage return. When the carriage return
occurred, the Hl THERE appeared almost immediately on the screen.
Let us talk about the simplest function; that is, immediately correcting a mistake. Retype the line
?HI THERE B. What we were trying to type was HI THERE PET, but we hit the character B rather than P.
For those of you who are touch typists, you may have already made this mistake with the PET's close
keys. In order to allow you to immediately correct this mistake, there is a key which allows us to erase a
previously struck character. This key is called the delete key, located in the upper right-hand side of the
keyboard.
If we strike the delete key once, you will see that the B has disappeared. Typing the P results in an
overstrike of that position. We can now finish typing ET; then hit carriage return, causing the PET to print
out HI THERE PET, a blank line, and READY.
The delete key is the fundamental editing tool which allows you to strike out as many characters as you
want from where you are and then retype. This is the simplest form of editing. It is implemented by
14
decrementing the screen pointer from where you are by one and striking a blank over where the screen
pointer is. We can go back and erase the READY that is right in front of our cursor by just continuously
striking the delete key. Notice two facts as you are striking; (1} if you strike slowly, the cursor will move
one character at a time, and {2} if you strike fast, the cursor will actually move several characters
before you see it blink. This phenomenon occurs because it takes 15 times as long to blink 2 characters
as it does to overstrike one. Also, notice that the PET wraps around the screen. The screen memory is
organized so that deleting the previous character in memory moves the pointer back over that character.
Because of the fact that the characters scan from right to left in 40-column chunks, for example deleting
the character at the beginning of the line, and then striking the delete key at the beginning of the line,
deletes the 40th character of the previous line. Just keying back 40 strokes erases the READY from the
line above, however, this is a pretty siow way of editing.
There are three cursor movement keys on your PET. One key moves the cursor right or left; the second key
moves it up and down, and the third key moves it home (upper left-hand corner) and clears the screen.
CURSOR RIGHT AND LEFT
The cursor right key mdves the pointer one character to the right. If we strike it now five times, you will
see that it moves us five columns over. It accomplishes this by changing the cursor pointer in memory.
The cursor left key is on the same key as the cursor right and is evoked by shifting prior to striking. If we
type that four times, you will see that now we are back one character to the right of where we started. if
we strike it two more times, it moves us around the corner of the previous line. Cursor left, of course, just
moves the cursor pointer one character less in memory. Going to the left, it moves one character at a
time. Obviously, by doing this, we are able to edit the screen. However, faster editing can often be
achieved by use of the cursor up and down keys.
CURSOR UP AND DOWN
The cursor down moves the pointer 40 columns to the right from its current position. This gives it the
same visual effect as moving it down one line on the screen. For an example, try spacing over forty
positions with the cursor right. The cursor is now on the same position on the screen, but down one line.
To cause the cursor to move up, hoid down the shift key while striking the cursor up/down key once; this
gets us back to our original position.
Cursor up moves the screen memory pointer “up” 40 characters from its current position, or rather, 40
characters less in screen memory than the current position.
SCREEN EDITING
We can now use the cursor movement characters to get up in position on the second H in the HI TH ERE
PET message. Once you are there, you can now delete the T by striking the delete key. You will notice that
all the characters to the right of the character being deleted are moved to the left one character. You will
now see the delete is actually a matter of moving all the characters in memory left one, rather than just
substituting a blank.
INSERT/DELETE
Before analyzing insert and delete, we should be reminded that the screen memory is organized such that
any single line may consist of 40 or 80 characters. (See section on screen memory.) Insert and delete are
concerned with the characters on a line. Whenever the delete key is struck, all of the characters,
starting from the position of the cursor, to the end of the line, are automatically shifted one character to
the left, replacing the character preceding the cursor. The cursor is then moved to the position of the
replaced character.
The last character in the line is automatically blan ked. Insert is the reverse of this process. If we want to
15
fix the line that we just got through taking the T out of, we need to put a T back between the blank and the
HERE. In order to do that, we have to make a space in which to type the T. To accomplish this, we strike
the shifted insert key with a single stroke. After striking T, you will note that this now creates a screen
which says HI THERE PET, with the cursor blinking over the first character of the insert. To insert more
than one character, strike the insert key more than once; this moves all the characters on the line to the
right, and the cursor points to the first character of the insert. This then allows us to insert several
characters on the line. For example, if we hit the insert key three times, type T's until the cursor is
positioned over the H, then delete all of the extra T's; we will then see that the back and forth movement
in the fine is automatically handled and we end up with a perfectly recomposed message. It should be
noted that in no time has the computer responded to these commands, other than making a change on
the screen. This 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
and the screen memory, without interfering in any way with the rest of the operating system. This allows
the user to compose perfect text and hand it to the computer without the programmer who is using the
data, whether it be BASIC or the user program, to worry about the intermediate steps of making
corrections. It is best symbolized by:
What You See Is What You Get.
LINES ON A PET SCREEN
Physically, a line on the screen consists of 40 columns of information. However, traditionally in the
computer business, many data inputs are organized for 80 column data cards and, of course, much more
data can be put into 80 columns than into 40. Therefore, although the PET screen can display only 40
characters per line, the user is given all the flexibility of an 80-cotumn line. This is accomplished by
allowing the screen to define more than 40 characters as a line. If we move our cursor over to the
beginning of the line below HI THERE, and start typing NOW IS THE TIME FOR ALL GOOD MEN TO
COME TO THE AID OF THE PARTY, we will see that after typing the E, the space is automatically on the
next line. You will soon see the screen considers this to be an 80-column line although the HI THERE PET
right above is only considered to be a 40-column line.
The thing that allows the PET to accomplish this is that internally, there is a table of pointers at the
beginning of the line. Each line has a marker that indicates whether it is the beginning of a line or a
continuation line. This pointer is kept in the negative bit position of the index pointer. Whenever a cursor
up or cursor down occurs, the editor examines the status of these line pointers in order to initialize the
PET to their proper line number. At any time while the cursor is on the screen, there is a separate value
kept which is the beginning pointer for the first complete line from which the cursor operates. The screen
position is then kept as a separate pointer telling the PET whether it is greater or less than 40 characters.
Whenever scrolling occurs, the line pointers are moved up in such a way that the concept of the first line
second line is maintalned until the line disappears on the screen. This line polnter table is located in
memory locations 553-577.
Now that we understand that the PET can allow 80 columns, let us see what happens when we do the
insert at the beginning. To print this line, we have to put a? at the beginning of the characters. We move
the cursor up and left, until the cursor blinks on the N of NOW. If we insert twice, we can then type a ?"
(it should be noted that this causes the characters on the line to all move to the right). If we now carriage
return, the PET prints NOW IS THE TIME on two consecutive lines, spaces a line and types READY. If we
16
go up and make a change in the middle of the line, we can see that it makes no difference where we hit
the carriage return in the line. if we space up to the word PARTY the first time that it is on the screen, now
even though the cursor is blinking on the P, a carriage return causes the entire line to be reprinted. The
basic rule is that when a carriage return is struck, regardless of where it occurs in the line, the entire line
is transferred, whether it be a 40-or 80-column line. Sophistication in using the editor will become more
apparent as you use it when writing programs.
SCROLLING
Now that we have a mixture of 40-and 80-column lines on the screen; let us investigate what happens
when we try to move the cursor off the bottom. To do this, we just cursor down until the cursor is at the
base of the screen. Hitting the next cursor down causes the entire screen to move up one line. Any time
we attempt to print past the thousandth character on the screen, the screen editor automatically moves
the entire screen up one line.
Lines move up on the screen by a one line or two line jump depending on the status of the top line on the
screen. This is accomplished in hardware by checking the top line pointer plus one. If an 80-column line
is to be scrolled off the top, the 81st character through to the thousanth character are moved to the top of
the screen memory, and the bottom 80 characters of memory are filled with blanks. If only a 40-column
line is to be moved off the top, the 41st character is moved to the first, etc., and 40 characters are blanked
at the bottom of memory. The cursor is positioned automatically in the same position at the bottom of the
screen as it was when you tried to move the cursor down; or in the case of a carriage return andior
printing, the cursor is moved automatically to the left-hand side of the bottom line.
This process is totally automatic and is caused by attempting to print carriage return or space off the
bottom of the screen. There is no other program control over the movement. As we will see when we write
a program that causes scrolling, the scrolling speed on the PET Is too fast to read. If the reverse key is
held down while printing is occurring, the scrolling will be slower by a factor of 20.
HOME AND CLEAR
Striking the home key moves the cursor to the upper left-hand corner of the screen (the first location of
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 by moving blanks into all thousand
screen positions and again homing the cursor. Clear or home can be given at any place on the screen.
The PET basically moves data from the keyboard to the screen and then when a carriage return is struck
moves the screen data into a program. This allows the user the flexibility of making a correction on the
screen without having any effect on the program that is going to receive the corrected version. Keys are
provided to allow movement around the screen and to insert or delete, as well as type over any character
on the screen. This allows the entire screen to act as an editing place for user-controfled input.
17
Chapter 4. BEGINNING BASIC
The combination of instructions to solve a particular problem cannot be taught in a text book. it is a
creative process. Someone who knows how to use the computer uses his intuition or careful planning to
figure out instruction sequences to allow solution of his problem. All that we can cover in this book and
all the PET can be - except when it is provided with pre-programmed softrware - is a tool to use for solving
problems. This book cannot teach you to solve your particular problem. It can, however, teach you how to
use the PET as an instrument.
THE PRINT STATEMENT
A computer can calculate numbers all day but it is of no value unless the computations can be displayed.
We will begin our discussion of BASIC with the PRINT statement for that reason.
When typing text, PRINT can be abbreviated as ?. A statement such as this:
PRINT “HELLO”
is an instruction to the computer telling it to display on the screen all characters between the quotes -- in
this case a word of greeting. On the other hand:
PRINT 1024 *8
is an instruction to print the product of 1024 multiplied *8.
It is useful to note that BASIC allows you to print more than one value at a given time. Rather than having
it write a line, print ‘A’ and on a second line print ‘B’, it is possible to write the line:
PRINT 10241 2, 1024 $ 3
which will print the square of 1024, a few spaces, and then the cube of 1024. Details of the exact format is
contained in the next section. The point here is that you can print as many values across a series of lines
as you can write down.
Unless the computer has been instructed otherwise by means of CMD command, all print outputs are
directed to the built-in screen. The characters are printed in the next available print position on the
screen, under the control of BASIC and an editor which is keeping track of the screen position. Although
the physical representation on the screen is 25 lines by 40 characters, the printing of up to 80 characters
is accomplished by the screen automatically folding over the 41st character onto the next line. The
computer automatically scrolls the screen up one or two full lines when it reaches the one-thousandth
character on the screen.
The command PRINT has two major forms under the contro! of BASIC. (1) The standard print single
character which allows for printing the field specified after the print statement has ended in the form
print variable. If the data is presented in this form, the field is printed starting at the current screen
position and followed by a carriage return. (2) Data presented in the form PRINT A, B, then BASIC
automatically tabulates printing ‘A’ starting at the current screen position then spacing over 10
characters, prints 'B' followed by a carriage return. In order to cause BASIC to not send the carriage
return after B, a ; (semicolon) is used. PRINT A;B; results in the ‘A’ being printed, then followed by no
extra spaces, variable ‘B’ is printed. The cursor is left at the end of the 'E' field. If the variable A is more
than seven characters, 'B' will be printed after spating 20 characters,when using PRINT A,B.
BASIC obeys the following roles for printing characters. When the field to be printed is a string, there are
no leading or trailing characters sent. If the field to be printed is a number, BASIC first checks its size.
If the number is less than .01 or greater than or equal to 999999999.2, BASIC prints it using scientific
notation. For example, .0034 is printed as 3.4 E-03 and ~ 1234567890.5 is printed as - 1.2345678E + 09. If
the number falls between these values, the most significant 9 digits are printed, plus a decimal point if
19
needed. Trailing zeroes after the decimal point are not printed. BASIC always prints a skip character after
a number (unless it is printed as a string).
it should be noted that in order 10 taka full advantage of the PET's ability to compose text material on the
screen, untike most BASICs, the apparent space between fields is always a skip (cursor right) character in
the PET, which causes the screen to advance the screen pointer by one character; it does not result in any
of the data screen being covered.
Because the PET allows the inclusion of all cursor positioning as literal characters within a string, the
programmer has full contro! of the screen print position. The cursor control characters available to use
as literals are clear screen, home cursor, cursor right, left, up and down. By use of these literals, one can
compose fields of any length and in any size Starting in any one of the 1,000 character positions
displayable on the PET screen.
We previously discussed how the PET screen memory consists of a thousand characters of storage
located at memory location 8000 hexa-decimal. Characters are represented in screen memory in six bit
ASCII code, concatenated with two additional bits. One of these bits is a reverse field and the second one
is the upper-lower case bit.
When printing to the screen, the print subroutine in the operating system automatically translates ASCII
characters into the screen memory form. The various screen control characters are simply movement
characters for the screen printer. The home character moves the printer pointer to the beginning of the
screen. The clear character moves the printer pointer to the beginning of the screen, and inserts the
representation for blank in ali of the 1000 characters on the screen.
In BASIC, numbers are represented as 5-byte binary quantities, except in the special case of integers,
which are represented in two bytes. As far as printing is concerned, BASIC prints integers the same as it
does floating point numbers. In fact, BASIC automatically converts integers to fioating point and then the
floating point print routine converts the floating point numbers into printable characters.
VARIABLES a
We have already seen that the PET can be used as a large calculator which performs mathematical
functions and then can print the results. However, in many cases, programming consists of developing
intermediate values or performing operations until something equals a certain value. In order to
implement programming at any level, we need to establish the use of functions which can have a variety
of values at any one time. A function that can have any value is defined in both algebra and in
programming as a variable. If you are not familiar with the concept of a variable through mathematics:
then a book on beginning algebra, or perhaps one of the very rudimentary texts on BASIC might help you.
All of our discussions after this will concern themselves with the use of variables.
In BASIC, variables are defined by two character alpha numerics. If the variable is a numeric variable then
it has no trailing character. The character A is considered to be the variable A. Characters AA is a
different variable. Characters A1 is a third variable, but all three are defined as numeric values. If the
variable contains alphanumeric data, it is defined as a string. A string variable now ends with a $. Thus,
A and A} are numeric and string values respectively and are different variables. AAS, likewise, is different
from AA, etc. BASIC distinguishes a variable by the fact that the first character is always an
alphabetic character. The second character may be either numeric or alphabetic. An integer variable
ends with %, e.g. A%.
ARRAYS
Arrays is the fourth type of variable which can be defined in BASIC. Arrays are differentiated by the
20
parentheses which follow them. Parentheses define the particular value within an array which is to be
used in an expression.
A(0,1) refers to the first character in the second row of a two-column array and is different from A, A$ and
A%. All may be specified in the same program. Specific definitions and memory allocation techniques
for each of the types of variables follows, but first let us address some examples of how one uses
a variable.
Equal is used in two ways: If encountered in an IF-THEN type of statement, equal means the standard
mathematical function: the value to the left of the expression is compared and must equal the value of
the right. Otherwise, when following a variable such as in the expression A=2 +2, = means replace the
value in A with the resultant of the expression to the right.
Originally BASIC required the word LET before any variable assignment, but in PET the LET is optional
and may be omitted. À = 2 is equivalent to LET À = 2. The command CLR sets all variables in PET to zero.
To understand how variables operate in BASIC, try the following examples on your PET. Remember to
press RETURN after each command you enter.
CLR
7A
PET prints O.
Now type
A=2+2
?A
This time PET prints 4.
Now tyne
?В
PET prints 0.
Now replace the value of B with twice the value in A, by typing
B=2"A
?B
PET prints 8.
Now change the value of À by typing
A=2+3
ЗА
PET prints 5. If you now type
7B
PET prints 8, the same value as before. Until we give a new expression for B or re-execute the one which
says B=2"A, the value of B will remain 8.
FLOATING POINT VARIABLES
BASIC always assumes operation, or operates totally, in floating point arithmetic. Therefore, each normal
variable is assigned space in memory for a standard floating point number.
Four bytes contain a binary representation of that precision. lt gives us the capability of specifying about
9 digits precision of a decimal number. Accuracy of most calculations is limited to this representation.
Each variable is also assigned a 1-byte exponent limited to having a maximum value of + 33. Exponents
less thgan — 34 yield numbers too small to distinguish from zero.
STRING VARIABLES
A string variable can contain a function, whether it be a number, graphics character, or standard ASCII
character. There is a specific set of variables that aliow extraction and packing of data into strings which
21
will be discussed later on. The string is limited to the 80 characters of the input buffer. There is a specific
set of functions that allow the construction of strings up to 255 characters (see later text).
INTEGERS
As we have indicated, an integer is simply a whole number. Floating point variables are stored in BASIC
with five bytes; one for the exponent and four for the mantissa, which gives an accuracy of 9 digits. In
many cases, variables can be expressed in much simpler numbers. In order to allow the user most
memory efficiency, particularly in the case of arrays which can take significant amounts of memory, the
PET has implemented the concept of storing certain numbers as two-byte integer values. Any integer
value between minus 32,767 to plus 32,767 may be stored in the form of a two-byte number with the
highest bit of the number containing the sign.
USE OF PROGRAM AND DIRECT STATEMENTS
Throughout the text, until now, we have been using the program technique which allowed us to get the
PET to respond directly to the print statement. In this case, BASIC is obeying the command we are giving
it directly, as we type it from the keyboard and hit carriage return. This is so-called direct mode. In this
mode, we can use the PET as a super calculator. For Instance, if we want the PET to add two numbers and
divide the result by a third, we can ask it the question ?(2 + 8Y5. If you have typed that on the PET, you
should get the answer of 2 followed by a READY. The PET will obey any statement given it from the
keyboard, except when it is in the process of executing a BASIC program. In addition to using it as a
super calculator and for teaching with the PET, the direct mode is quite useful for debugging of
computer programs. Variables can be assigned intermediate values and then small sections of the
program can be executed with GOTO statements to assess why any particular piece of code is not
working correctly. Break points can be put in programs and current status of variables checked with print
commands, again in direct mode, without having to modify your main program. However, except for
debugging or in the case of using the PET as a super calculator, in order to get the computer to act as a
true computing element, one has to write or load a BASIC program. The difference between execution In
direct mode and a program is that several statements can be grouped together in logical order and then
BASIC will execute all of the statements before asking the user for control.
Suppose we want BASIC to print our HI THERE message vertically as opposed to horizontally. We can
easily accomplish this in à program but not very easily in a direct statement. Rules for program entry are
very simple. Any statement you want to be treated by BASIC as a program statement must be preceded
by a line number. A line number may be any number from 0 to 63,999.
A good habit to develop when typing in lines of a program is to use increnments of 10 or 100. Instead of
1, 2, 3, etc., use 10, 20, 30. This will give you space later to add lines and make corrections in your
program. All you need to remember is that BASIC interprets each line number in order.
To print HI THERE, vertically, each line of our program will type one letter of the message. we are going
to start with line 10 and make each line a multiple of 10.
107°'H"
207"
307 "T"
40?‘H”
507 "E”
60?"R”
70%" Е”
Whether you are typing in a program or giving direct commands like RUN, you have got to hit RETURN to
tell the PET to take a look at what you have typed and act accordingly. The lines ten through seventy
22
constitute a program which tells the PET to print out HI THERE.
The program is now resident in memory. To execute the program, type RUN. This gives us the HI THERE
printed in the vertical format:
mIDmI—-<—T
You will note that we do not have a space between the | and T. One of the reasons we use the numbers in
the multiple of ten is that we can now insert a correction between lines 20 and 30. First, display the
program by typing LIST. This gives us the program printed as follows:
107 PRINT “H”
207? PRINT "I
307 PRINT “T”
407 PRINT “H"
50? PRINT “E”
607 PRINT “R”
70? PRINT “E”
Now type:
Day E
Press return and relist the program, and we will see that line 25 is inserted between lines 20 and 30. If we
run the program now, we get:
H
mI mI —
This example demonstrates the use of line numbers and the ability to insert lines numbers to make a
correction in a program.
There is another way to get the same effect. First delete the space by typing 25 followed by a carriage
return. Then list the program and see that line 25 has been deleted. Now position the cursor on the space
following the | on line 20, and insert a cursor down. First by hitting the insert key, and then the cursor
down key, if you don't hit the insert key first, the cursor will move down immediately. But because you
inserted the cursor-down (it looks like a reverse field Q), the cursor will not move until instruction 20 is
executed. Do not farget to hold down shift before striking insert.
When we now run the program, you see this also gives you the effect if a space on the next line. This
would not always be true, except we had been cheating and using the automatic scrolling capability of
the PET which clears out the field. Had we programmed a home prior to printing a program, we would not
have received such a nice result. Try programming a home 5?7*HOME”, then try a clear 5? CLEAR".
The screen editor will allow you to take a program and make changes on any of the lines you display on
the screen. The list command has several features to help you get the right lines to the screen to edit. List
takes programs and prints the contents of the basic program which is stored in memory. The command
L-I-S-T starts at the first line number in memory and lists to the screen device all the instructions to the
23
end. The longer programs features of list which allow you to list only a single line.number LIST 20 which
lists just line 20, LIST 10-50 which lists lines 10 through 50 included; LIST-50 which means list all the
numbers from the-beginning of the program through line 50 included, and LIST 50- which lists ali of the:
lines from line 50 to the end of the program. Some combination of the above can be used to find and
correct any piece of program which is currently stored in memory, Try each ef the above commands, on,
your PET just to see what they do with our little program. |
BASIC is an interpretive language related to the direct commands we are executing. BASIC executes a
command by taking the last line typed to it and analyzing the line working from left to right looking for key
words and expressions which it recognizes. Every time it encounters a key word such as PRINT (or ?
which is the token for PRINT), it interprets this word into a command which means something to BASIC.
Command words are stored in memory with bit 8 on to tell BASIC that it is a command word, or key word.
As a program line is entered into RAM memory through the use of the carriage return, BASIC takes the
line number and searches through memory, until it finds the same number, or the number Just greater. Н
it is the same line number, then the entire line in memory is deleted and a new line is inserted in memory.
In the pre-interpreted state all the key words are replaced with the single character token for the key word.
This allows the interpreter to store commands in the most memory-efficient form. The only data stored
is the data typed in by the programmer such as literals, pointers to the variables, and the keywords.
PRINT, even though it takes five characters to type, only takes one character in memory.
BASIC is called an interpreter because the actual execution of the instructions is done by analyzing the
keyword that needs to be executed in the program line, then executing that keyword under the control of
a series of subroutines. This is a trade-off which results in very memory-efficient storage programs but
lenger execution times than would be true of a machine language program. Because PET BASIC uses
tokens in memory and stores them on I/O devices whenever a program is loaded and saved, the actual
coding of data on tape or in memory is not transferable to other machines. It is generally not possible to
use BASIC instructions typed in from other machines.
When you create a BASIC program you are operating under two levels of editor: the screen character
editor and the BASIC line editor. The screen editor allows you to change characters within a line until the
carriage returrrtransfers it to main memory. The BASIC line editor allows you to add new lines and modify
and delete old lines.
To delete a line, you type the line number immediately followed by a carriage return. To modify a line,
list it first on the screen and alter it then type a carriage return to re-enter it. To replace a line, enter the
same line number with new text and type carriage return.
There are two ways to execute a BASIC program. The first of these is to type RUN. The command RUN
first clears all the program variables and initializes the program pointers. Then it executes each
instruction of the program in order, starting at the lowest number. Execution continues until there are no
more instructions, and END is encountered, or the stop key is pressed. RUN may have as an argument the
number of the first instruction to be executed. For example, if you type RUNS30, our sample program will
print THERE instead of HI THERE. RUN is executed in direct mode. A GOTO statement, also executed in
direct mode, operates the same as RUN except that none of the variables are re-initialized. The GOTO, of
course, must specify the line number of the first statement to be executed, e.g. GOTO 30.
LITERALS
In our HI THERE examples we have used PRINT commands with characters to be printed enclosed in
quotes. In the PET these are called literal strings. Data is also kept in the PET in binary floating-point
24
numbers. Much of the data you want to work with in programs is not numeric but alphanumeric -- the way
we talk back and forth as human beings.
These characters are specified to the PET with literal strings. More specifically a literal is any value
contained within a set of quotes.
To allow the maximum composition of screen data, the PET has a special set of graphics characters and
the ability to store and execute cursor control characters which are fed to It by means of literals or other
more sophisticated techniques.
We have already discussed in a section on PET keyboard input how the PET stores its data in ASCII
Graphics characters are stored as an extension to this set. Graphics are produced by shifting from the
original 64 character set and they are stored in memory with a special indicator to differentiate them from
the lower characters on the keys. A literal can be used to draw a line just as easily as it can be used to
print Hl THERE.
Any combination of characters within the PET keyboard may be typed in as a literal and this includes all
cursor movement and the reverse field. PET has a special mode in the screen editor which assumes that
you are typing in a literal whenever a quotation mark is typed. From the time that the first quotation mark
is typed until the timg that a closing quotation mark is entered, all characters are transferred directly to
the screen in a format so that the software which transfers the input line to BASIC will transfer them as
contro! characters if that is appropriate.
You can see the cursor movement characters flagged with reverse field within a literal. Type a single
quote and see this happen. Reverse field looks like an “R”. Home is an "'S” and clear is a shifted “S” or
heart. Cursor down Is a “Q" and cursor up is the shifted “Q” or hole character. Cursor right is a right
bracket and cursor left is the shift of that character and looks like a vertical line through the Sth column of
dots. Insert is a shifted “T” which looks like a second vertical line.
You cannot enter a character in reverse field into a literal but you can turn on reverse field with the control
character before your character is printed. The only characters that are allowed to appear in reverse fieid
between quotes are those which are interpretted as control characters.
Delete is the only editing character that will still work within a literal. Once an odd number of quotes has
been typed on a line, you lose the ability to move the cursor about the screen until either a closing quote
or a carriage return is typed.
You should note at least one time while you are editing that you have falien into the aforementioned trap
of trying to move the cursor after a quote has been typed. Eithéf type a phoney closing quote or a carriage
return, then cursor up to edit your mistake.
Another method of inserting cursor control characters into already existing text is to use the insert
function. It has the same effect as an opening quote. For example, if you type insert three times and then
try to do a cursor movement, the control characters will be flagged with reverse field just as before. This
mode is easy to get out of because you need only enter as many new characters as the number of times
you struck the insert function. It is suggested that you make up your own examples to play with this.
Examples may also be suggested to you as you make a few editing mistakes.
The ability to readily manipulate the graphics and the cursor movement characters can allow whatever
depth of graphical capability you have the time and patience to program. The computer should be fun. We
recommend that you devetop your own programming skills with the text and contionually experiment
with the use of imbedded graphics and cursor movement characters. Remember that you cannot hurt the
25
machine - the worst that can happen is that you clear the screen accidently after typing in a bunch of
stuff.
REVERSE FIELD
We have shown in the examples of quote mode and insert how once a mode has been established for a
line, the PET will continue with that function until it is either cancelled by a new control character or a
carriage return. Reverse field works in the same way. it remains in effect until a reverse field off character
is typed or a carriage return is entered.
As described in a previous section on screen memory, reverse field characters are stored with a special
bit on to indicate the black spots in the characters coming from ROM will be all white and all the white
spots will be black. As you will see when you type an example, this gives a very desirable highlighting
effect and doubles the number of potential characters which the PET can display. This feature is so
useful that it is not only implemented on the PET display but in some of the PET hard copy printers
as well.
Here is an example of how reverse field works: Clear the screen and type. HI (space). Next hit reverse
field on and type THERE Finally type reverse field off, (shifted reverse field on), type (space), PET.
This gives us a line in which we have highlighted THERE.
Reverse field remains on from the first time the control character is typed and all characters
subsequently typed on the screen will be printed in reverse field until the mode is terminated as we
previously mentioned. This applies equally to keyboard input as well as characters printed from a literal
string.
To get the PET to type out in reverse field we use a literal with the control character for reverse-field-on
inserted. TYPE ?7*'HI (reverse field on} THERE (reverse field off) PET”. Note that the reverse field on and off
characters occupy a space on the screen when programming and that they appear in reverse field, but the
THERE is not in reverse field yet. The effect of the quote is to postpone the action of a control character
until the literal is interpreted. Since the reverse field is turned on by setting a bit of each character in
screen memory, a screen position is not required for reverse field on or off when the stream of characters
Is received by the program which prints it on the screen. Reverse field remains on until a reverse field off
character or a carriage return is typed.
TERMS AND OPERATORS
The communication with BASIC is either with numbers or with alphanumeric literals. Numbers are always
presented in decimal form even though the microprocessor in the PET operates in binary mode. In order
to keep the two straight, PET will assume that whenever we are talking about a number, we are
representing it in decimal form. Later when we talk about hexadecimal numbers, they will always be
preceded by a $-e.g. $00 10 is equal to 16.
As BASIC recieves lines, the interpreter divides the characters it sees into several classes. Such as
commands, functions and operators. PRINT is a command to BASIC with a specific function that PET can
perform.
À function can be something like square root or a variable, or a special function. Whenever you type Non
the keyboard, you get a constant of 3.14159265, which can be used in an expression.
An operator is a character that is interpreted by BASIC as an arithmetic function which Is to be performed
in evaluating an expression. The following set of operators are defined for BASIC:
Plus sign (+) causes two values to be added together using floating point representation with the results
26
being calculated in a floating point accumulator. The accuracy is limited to 9 significant digits. Minus
subtracts the value to the right of the minus from the value to the left of the minus sign.
*
is the BASIC multiply. The value to the right of the multiply is multiplied by the value to the left.
! is BASIC's divide. All the numbers to the right of the slash are divided into the expression to the left of
the slash.
t means exponentiation. All the values to the left of + are raised to power of the value on the right.
Open and close parentheses cause values inside them to be single expressions. All expressions inside
parentheses are evaluated as a single value. Parentheses may be nested and are evaluated outward,
starting from the innermost set of parentheses. In order of precedence, the memory aid “My Dear Aunt
Sally” will help you remember the precedence of operators Multiplication first, then Division, Addition,
Subtration. Expressions within parentheses are evaluated first starting from the innermost set of
parentheses. The following set of examples should be tried on your PET to show the operation of the
operators and their precedence.
Addition
242
Subtraction
?4—2
Multiplication
?6*2
Division
? 12/2
Use of Parenthesis
?74+8/2
? (4 +8)2
Order of Operations
2 (2 + 4*(В - 4)/2)*3
FUNCTIONS
There are three functions which are available in BASIC which are, at the time of writing, unique to the
PET. The first of these is TT: Whenever this character is used in an expression, BASIC transiates it from the
keyboard character of TT to the value of 3.14159265 etc. It can be used anywhere in any expression and will
always be evaluated as this number. Example: ? 11.
TI$ and the value Tl are two ways to communicate with the real time clock within BASIC. As previously
indicated, every time a screen refresh occurs, (1/60th of a second), a value within the PET is updated. This
value is measured as a 24-hour real-time clock. It is available to the programmer in its binary form by the
expression TI, which gives the value the current number that BASIC is keeping. This number is kept as a
three byte binary number whose value is stated in numbers of 60ths of a second, or so called jiffies. To
evaluate the amount of time that a particular operation has taken, Tl can be stored in a variable at the
beginning of the sequence and then the difference calculated by subtracting that variable from the TI at
the end. This function is accurate to 1/60 of a second.
T!$ presents and accepts data in the form of hours, minutes,and seconds. When the expression Tl$ is
used, it always presents data in string form with two characters for hours, two characters for minutes,
and two characters for seconds. The value of time in the computer is kept in a 24-hour clock. If it is ten
27
minutes past 1 p.m. in the afternoon, TI$ would be printed as 131000. To set the value of the real time
clock, type the expression TI$= with the number being typed in quotes in 24-hour time. For example, to
set the clock to 2:45 and 30 seconds in the afternoon, type T1$ =144530"".
As a personal experience, you should set the value TI$ = to the right time now and after you have done
some additional reading, go back and print it. As with all the other variables, the power-on sequence to
the computer zeros the real time clock.
Care must be taken in use of the value TI. Remember that the expression TI automatically goes back to
zero at midnight. One of the authors wrote a loop in a program for graphics display where the program is
waited until the variable Tl is greater than a constant and the value of Tl when the display is put on the
screen. This expression never reached the computed value as Tl goes through midnight. The only way to
compensate for this is to watch for when the time might go through midnight, and readjust the stored
value when it might.
Functions are preprogrammed capabilities of BASIC which can be treated as a single value. Functions
range anywhere from n, which i § a predefined function, to sine, which is a capability of BASIC to
compute the sine of a number. When BASIC encounters the code for function, it evaluates the expression
for the function, calculates the resulting value, and uses the value in the command. The use is really quite
simple. If A equals sine of n radians, the expression would be written:
À = SIN(n)
In this statement, we are actually using two functions, n, and sine; BASIC would evaluate this expression
by expanding the value of rn, evaluating the function sine and finaliy storing the result in the variable
space for A. In the expression:
À = 2*SIN(n)
after the sine is computed, it is multiplied by 2 and stored in À.
The trigonometric functions, sine, cosine, tangent and arc tangent are all available in PET BASIC. The
expressions for SIN, COS, TAN all have as their only argument an angle given in radians. To convert from
degrees to radians, multiply the number of degrees by n/180. For example:
?SIN(90*n/180)
calculates Sin of 90 degree. To obtain the cosine of 45 degrees:
PRINT COS (45*n/180)
To compute the tangent of 40 degrees. For example:
TAN (40"n/780}
Each of these functions are computed by tables. Because n is limited to 9 significant digits, in general,
values should be less than 1000 degrees or br.
The accuracy of BASIC functions is five parts in ten to the tenth as long as the argument is below 20
radians. Expressions which use the values in radians are a function of the value of n which is accurate
only to ten to the ninth. Arc tangent is the only inverse trigonometric function specified as a function in
BASIC. The function arc tangent computes the value in radians of the expression given on the argument.
Answers are always given between plus or minus 17. The accuracy is 5 parts in 10%, In normal use the
result is in radians.
?ATN(.5)
To convert the number to degrees use the following example:
?180/7 * ATN(.5)
28
The following general expressions can be used to compute the value of arc sine and arc cosine as a
function of arc tangent.
ARC SIN (X) = ATNQUSQR( — X*X +1)
ARC COS (X)= — ATN(X/SQR(- X*X +1}+1.5708
Both the above expressions give the results in radians to be converted to degrees by multiplying the total
expression by 180/r. (It should be noted that in both the expressions there is a possibility of performing a
division by zero which will result in a basic error. Before using the expression, the arc cosine should be
checked for zero and before using the expression arc sine, X should be checked for it being equal to the
value of one.
MATHEMATICAL FUNCTIONS
The largest legal number that BASIC can handle is +1.70141183 E + 38. Any larger number gives an
?overflow error. The smallest magnitude that can be distinguished from 0 is 2.93873588 E — 39. Any
smaller
number will result in an underflow.
ABS
Absolute value is specified in the form ABS(X). The function returns the value of the expression as a
positive number. There is no inherent accuracy loss. For example:
PRINT ABS(— 145).
INT
This expression basically rounds the current value of the parameter to the next lowest integer.
For example:
INT(.23) =0
INT(— 25) = —3
INT(1.79) = 1
Other than the inherent inaccuracy of dropping significant digits, this expression introduces no
additional inaccuracy. However, small inaccuracies in the argument could cause problems. For exampie,
the number four might, in fact, be stored in BASIC as 3.99999999. When this number is used in the
argument for an integer, the result is 3, not 4.
SGN
This expression returns a 1if the sign of the number is greater than zero, a zero if the value is zero, anda
— 1 if the sign is negative. For example:
?7SGN(— 45)
—1
?75GN{(+ 10)
1
SQR
This function calculates the square root of any number greater than zero. If a minus number is used, the
result is an ?ILLEGAL QUANTITY ERROR. Accuracy of the expression is 5 parts in 10 to the tenth for the
entire range.
?SQR(16)
The following two functions send themselves with natural algorithms. The algorithms are base E which
is 2.71828183.
EXPONENT
The parameter defines the power to which the base E is raised. The limit of the parameter is 88.02969189.
29
A number greater than that will result in an overflow. A form of the expression is EXP{X). Although the PET
only allows the flow function for E, other functions are available by ratioing to the Log:
?EXP(1)
Basic logrithmic function is given with the parameter LOG(X) which is logged to base E.
To calculate the LOG to base 10, the expression is written:
LOG(XVLOG(10)
RANDOM
The random functions are useful for many statistical programs and games. Basic random functions are
provided. The random number generator uses an algorithm which develops a value between zero and one.
The argument can be either non-zero, or negative. Positive numbers always return the next value of the
random number sequence generated by a numerical algorithm in BASIC. |t always starts with the same
value, or seed power-on. However, the seed for the random can be initialized by using the minus value.
Repetitive access to the random function in a program is not random because the relationship of the time
is predictable from the time that the program is initialized. So in a fixed program sequence, the only truly
random number is the first one. A solution to this is to use the time to generate random seed, use the
RND{ — Ti) to seed a number sequence, and use RND{ + 1} for the numbers in the sequence. This should
give a close to theorhetically pure random number for statistical analysis and definitely gives a random
sequence for game play.
The AND of a minus number is not truly random at all. The parameter is passed as a seed to the random
number generation sequence. This technique can be used in debugging programs in a sense that a
predictable repeatable sequence can be obtained by RND minus for program development. Suppose in a
game program you want to simutate rolling a six-headed die. initially, you can see the random number
generator with the instruction
D=RND(— FI}
Subsequently, you can compute the value of the die with
D=INT(6*RND(1) + 1}
PEEK, POKE:
PEEK is a function which allows the user to look at any location in the PET memory. The parameter
contains the memory address in decimal in the PET which to want to look at the result is a decimal
number between 0 and 255. BASIC is currently constructed so that the contents of any address greater
than hexadecimal C000 is automatically returned as zero. This is a legal constraint, posed by the
company who wrote the BASIC software to protect their copyright.
Example: To look at memory location 25, the expression is written:
?PEEK(25)
POKE
POKE is not a function but is written like a command. It allows the user to deposit a number into 1/0 or
read/write memory. The parameters are specified in a list after the command. The first parameter is the
memory address of where to put the information. lt may range from 0 to 65536. The second parameter is
the actual value to be deposited. It must be between 0 and 255. For example, if we wanted to put the
character A at the first location of the screen memory we would write
POKE 32768,1
Some locations in memory cannot be changed (ROM) and others should not be changed (BASIC and
system variable RAM or I/O). If you POKE the latter, be prepared to reset your machine.
30
USR
The USR is a function which is designed to pass a parameter to a lanuage program using the jump
address located at memory location one and two in the PET. See the section on machine language
programming for a detailed description and use of this function.
FRE
This function tells you how many bytes are left in memory. Although it is a true function since it can be
used in an expression, it is normally used in direct mode in the form:
?FRE(O)
FRE forces a BASIC action called garbage collection. This consolidates all unused bytes into one large
block so that they can be efficiently allocated.
Several functions exist to aid in formatting data when it is printed on the screen or hardcopy printer.
TAB
This format function places the cursor at the column specified in the argument. The argument goes
through the INT routine. The legal range is 0< X<255. If the cursor is past the location specified, the tab is
ignored. Note: TAB uses skip characters, not spaces.
POS
This function returns the position of the cursor. The position is reset to zero at each carriage return.
Note: HOME and CLEAR do not affect POS even though the cursor is set to the first column.
SPC
This format function prints out the number of skips specified in the argument (which goes through INT).
Legal range is D<X<255. Note: SPC(O) put 256 skips.
NOTES
31
Chapter 5. ELEMENTARY PROGRAMMING
Use of decision logic in writing programs.
A major advance in BASIC programming is the ability to loop back and re-execute lines of a program. it
may be done in two ways -- unconditionally with a GOTO and conditionally with an IF-THEN.
GOTO is written to specify a target line number where execution will always branch. GOTO may also be
written with a space between GO and TO. PET BASIC will recognize both forms.
GO TO 50
GOTO 100
НЕ-ТНЕМ has three forms:
IF (condition) THEN (statement)
IF (condition) GOTO (line number)
IF (condition) THEN (line number)
Conditions are written as two arithmetic expressions separated by a relational operator. PET BASIC
provides six relational operators: <,>, =, < >, < =, >=,
Until now we have been developing programs which do single functions in serial order. You should be
familiar with the concept that says that first line 10 is executed, then line 20, and other line numbers in
ascending order.
If we wanted to take and print numbers betwenn 1 and 20, their square and square root values on the
screen, we could write the linear program as before:
10 PRINT 1,1,1
20 PRINT 2,2*2, SQR(2)
30 PRINT 3,3*3, SOR(3)
The big disadvantage of this is that we would have to keep typing in lines until the 20th line.
200 PRINT 20,20*20, SOR(20)
UNCONDITIONAL LOOPING
However, with our concepts of variables and the addition of a loop, we can write a program that
computes values and prints them out without having to type such a long program.
The program reads as follows:
10 PRINT “VALUE”, SQUARE”, SQUARE ROOT”
Line 10 prints a heading for the column of numbers. It is executed only once.
20 |= 1+ 1
Line 20 computes the next number to use. The first time this line is executed, | has
never been referenced 50 it has an initial value of O.
30 PAINT 1,1*1, SQR (b
Line 30 is like lines 10-200 of the previous program except that the constants have been replaced by a
variable.
40 GOTO 20
Line 40 contains a GOTO command which directs execution back to start again at line 20.
BASIC stores text lines so that a pointer to the next line precedes each line. Using this technique, the
interpreter can quickly examine only the line numbers, determine if a line does exist, and transfer
execution to that line.
GOTO is not limited to branching to a lesser line number but it can branch to a greater number too. You
32
will see a future example of the congept of using GOTO to skip a portion of code.
As before, we type RUN to start our program. The program will continue to print values of | until the STOP
key is pressed. Rapid scrolling of the screen memory makes the screen almost impossible to read, but
use of the reverse key slows the scrolling rate. Holding down the reverse key slows the scrolling by a
factor of 20.
To stop the loop, press the STOP key. When you want to restart a program either type CONT to cause the
program to resume where it left off or RUN to begin at the beginning.
While this program makes use of the GOTO, it does not really help us to solve the problem we tried to
address -- printing just 20 numbers on the screen. However, before we address that, let us introduce a
small mistake into the program. You should see a common error and its cure. If we retype:
40 GOTO 10
and then execute, instead of printing a heading at the top of our program. We will intersperse the heading
with the computed value. Jumping to the wrong place in the program is the most common error made in
programming. Luckily it is most visible in this case. By stopping the program we can use the screen
editor to correct line 40 to go to line 20. You have now fixed the first in a long life of program bugs.
CONDITIONAL LOOPING
The IF-THEN statement allows you to specify a case to test and if the case is true, the statement after the
THEN is executed. A test is specified by putting one of six relational operators between two expressions.
= equal
<> not equal
> greater than
< less than
> = greater than or equal to
< = less than or equal to
If A<B then print “A LESS ТНАМ В”
И the expression is true, the instructions on the same line with the IF statement are executed. If the
expression is false, the program jumps to the next numbered line. If you are in doubt about < and > and
what they mean, remember that the arrow points to the value you would like to see less than the other.
In ourexample, we can add the statement:
40 IF | <=20 THEN GOTO 20
- The IF-THEN lets us make a variety of decisions at the time we are executing the program. This allows us
to limit the program and cause actions to happen. In this case, we execute the program from 1 to 20 and
then finally drop through the instruction.
We can also write the 1F statement to skip around the unconditional GOTO, Add two new lines and
restore line 40:
351F 1=20 GOTO 50
40 GOTO 20
50 END
The program will execute through 20 values and when | is equal to 20, go to the END statement.
Most BASIC interpreters required you to include an END statement to finish your program. This is a
vestige of when BASIC operated non-interactively from cards. END can be used optionally in PET BASIC
to force program execution to end at a specific point.
IF-THEN instructions have three forms: The first is IF expression GOTO line number. The second is
IF-THEN line number where GOTO is implied. The third form is IF expression THEN followed by a
33
statement to be executed before proceeding to the next line. Expressions in this form might change our
table to draw a line between the 10th and 11th value on the screen.
32 IF 1= 10 THEN PRINT “ i
If we try to execute this, you will see that a line is now drawn between the tenth and eleventh value on the
screen because of the statement at line 32. It should be noted that the logical conditions of the IF and
IF-THEN are only two; either the next line is executed, or the THEN statement is executed. Take care
when placing additionai programming statements on the line. For example, in:
IF X=5 THEN 50:2 =A
the Z would not be executed, because the líne either drops through or executes statement
50. However, in
IF X=5 THEN PRINT XZ=A
the PRINT X and Z = A will be executed if X =5.
The IF-THEN lets us make a variety of decisions at the time we are executing the program. This allows us
to limit the program and cause actions to happen at various points. It is the concept of the unconditional
jump plus the concept of testing values that allows the computer to be used as both control element and
legitimate computing element. The inteHigent combination of logical decisions with repetitive operations
makes a program really work.
DATA ENTRY
Before a computer program can perform useful work, it has to be able to access a data base of some sort.
The program could require only simple data such as YES or NO responses to a game or simulation. A
more complex payroll program might need rates, hours, and tax information. In PET BASIC there are two
ways to get information into variables.
READ AND DATA STATEMENTS
Only a short time ago when there were no timeshare systems, BASIC could not accept input other than
cards included with the program. Thus, DATA statements were typed and scattered throughout the
program. The command READ was designed to pull out this DATA into variables which could be used by
the program.
When BASIC began running in an interactive environment through timeshare, verbs such as INPUT and
GET allowed direct communication with the BASIC program. READ has been relegated to inputting
parameters that change but not as often -- e.g. tables, etc.
The syntax of READ is the verb followed by a list of variables into which the DATA is to be read.
READ A, B, C, D
READ processes DATA statements as they are encountered in the program, DATA statements at line 10
and 30 might be processed by a READ statement at line 20. DATA is processed seguentially and commas
and end of lines are considered terminators
10 DATA 2, — 53, [E10
20 READ A,B
30 DATA 3.14, 1,06E23
Blanks and graphic characters are automatically thrown away untess they are surrounded by quotes. The
quotes are considered to be delimiters for literal characters.
String data can be typed without quotes if it does not contain literals.
50 DATA ABC, DEF
34
Commas within quotes will not be treated by BASIC as field terminators.
60 DATA “7
It is also possible to type mixed alphanumeric and data fields. Numeric fields may be treated as alpha.
10 DATA 123, АВС, 345
20 READ A, AS, B
It is adviseable for the programmer to know how many data statements he has put into the machine or
use some kind of a delimeter at the end of the data. If it is not done, the data is continuously read, and the
program will index its way through all of the data statements. Finally, DATA will be exhausted and when
the next READ is encountered an ?0OUT OF DATA ERROR
will occur. Sometimes you may also see this error if you carriage return through READY on the screen
because the PET thinks you already told it to READ Y.
SYNTAX error results when an attempt to read alpha field into a numeric variable is made.
READ and DATA are implemented ín the following manner: The first byte of text contains a zero. This is
really not part of the first line but is a dummy line consisting only.ofa terminator. When RUN is typed, a
data statement pointer is directed to this byte. Since it is pointing to a terminator, the first READ
command initiates a search for a DATA statement token.
There is one other command available to the programmer which allows him to reuse the stored data.
RESTORE restart the DATA search back to the beginning of memory.
The following program would correctly operate continuously re-reading DATA;
10 DATA 10, 20, 30, 40, 50, 60, 70
20 1=1
30 READ A: PRINT A
40 1=1+1
50 IF K8 THEN 30
60 RESTORE
70 GO TO 20
INPUT
When interactive response to DATA requirements became possible, the concept of INPUT from the
keyboard was introduced. Since the classical input device to BASIC was a TTY, the format of input
statements was limited by this device.
Operation of INPUT is considerably enhanced when coupled with the powerful PET screen editor.
The form of the statement is the verb INPUT followed by a variable list. INPUT satisfies the variables in
sequence.
INPUT A, B,C
When BASIC encounters this instruction, it prints a question mark to the screen then activates the screen
editor, blinking the cursor for input. Because you are under control of the screen editor, cursor movement
characters are allowed up until the carriage return is issued as a terminator.
After carriage return is received, data is handed back to BASIC one character at a time. Data is then
interpreted by BASIC using its input buffer and rules of interpretation.
Leading blanks are supressed, so if you are inputting a string which requires blanks or literals, it is
necessary to enclose the input characters within quotes.
The editor picks up only the characters between the question mark and the current position of the cursor.
35
This allows input of data from a pre-constructed form on the screen.
INPUT data may be delimited by commas as with the DATA statement. When more fields are provided
than are actualiy required, BASIC responds with
?EXTRA IGNORED
and takes only those characters it requires to satisfy the INPUT list.
On the other hand, when not enough data is inputted, BASIC will respond with
7?
and begin blinking the cursor again to get additional input.
If an alphabetic field is encountered during the interpretation of a numeric field, BASIC responds with a:
?REDO FROM START
In PET, if input is followed by only a carriage return with no other typing, it is considered by BASIC to be a
termination of the program, same as a stop key. This particular feature is a carryover from the days of
teletype BASIC when this was the most convenient way of terminating a program.
The stop key is not operative while the PET waits for input.
INPUT has a special feature which allows you to indicate to the user what input characters are desired
and in what form they are to be. A literal which follows the input command is printed prior to the time the
carriage return is typed. For example:
10 INPUT “BIRTHDAY”; À
it would print:
BIRTHDAY?
and wait for you to input your birthday in standard numeric form to value A. Here is an example of INPUT
to calculate the third leg of a right triangle:
10 INPUT “FIRST LEG”: A
20 INPUT “SECOND LEG”:B
30 IF A=0OR B=0THEN 10
407? “THIRD IS”; SQOR (A*A + B*B)
50 GOTO 10
If you run this program and put in values 3 and 4 respectively, you will get a 5.
We can change our program to se how to combine values on a single line. We delete line 20, list line 10,
and change it to:
10 INPUT “FIRST LEG, SECOND LEG”; A, B
This change, when you execute it, will accept values typed as 3, 4. You will see that either form is
acceptable, however, good programming practice protects the user from getting confused as to how
many fields go on a particular line. although it is definitely not good programming practice, it is possible
to mix alpha and numeric values.
10 INPUT “NAME, BIRTHDAY"; AS, À
GET
À major problem with INPUT is that it does not allow real-time programming. All processing comes to a
grinding halt while the user takes his time to enter some characters and strike RETURN. PET BASIC has
been equipped with a special function which will yield one character at a time from the keyboard or tell
if a key has been pressed.
The command is GET. GET is identical in syntax to INPUT. It is possible to specify a list of variables but
36
generally this is not a good idea because the purpose of GET is to scan the keyboard and return with a
single key closure. When a numeric value is specified
GET A
only numeric keys will be accepted as input. All others will cause the message:
7SYNTAX ERROR
Use of the numeric value is confusing because if no key has been struck, the value returned is zero.
Otherwise it will have a value 1-9 for keys 1-9.
The most desireable way to use GET is with a string variable. If a key has not been pressed, the string
will have a null value {length = 0}; otherwise the string will contain the character corresponding to the key
that was pressed. See the next section for a detailed explanation of how strings work.
GET calls a routine which examines the keyboard interrupt buffer. if the buffer is empty, the variable
contains a value of null or zero. If there are characters, the first is taken out of the queue and returned.
Since the length of queue is 10 characters, calling GET 10 times In a loop is a good way to insure that the
queue is empty when waiting for a response. This is particularly useful in interactive games.
The following routine will wait for a key to be pressed and exit only with the value of a key closure:
10 GET A$
20 IF AS =""THEN 10
In this case, "is a literal which contains no characters and is a null string.
NOTES
37
Chapter 6. ADVANCED PROGRAMMING TECHNIQUES
We have been describing numeric functions primarily, but almost any useful program also has to deal
with alphanumeric data. BASIC has a set of functions to deal with these data. Also, all alphanumeric data
may be expressed as a continuous connection of characters which is viewed by BASIC as the value of a
single variable.
PET BASIC, has a $ notation which is used to express variables which are strings of alphanumeric data.
All of the rules which apply to normal variables apply to the string variable.
Following the naming conventions, we can create a variable AS not equal to A% and not equal to A.
Type AS ="NOW IS THE TIME” and PRINT A$ to show the value of the string. This technique can define a
string of a length up to about 70 characters, depending on the number of characters of the line number --
all that can be entered on a line. However, the limitation on the number of characters that can be stored
In a string is 255. You can build strings larger than can be entered. The accumulation of characters from
an I/O device and the construction of data is accomplished by the concatenation of strings. The operator
that is used is + .
We can modify the expression A$ which we have been developing by typing A$ =A$ +“ FOR ALL". Print
AS and you can see that the literal we typed in had a space at the beginning. Unlike numbers which are
formatted by BASIC, the value of the literal is taken literally. A string can contain all combinations of bits
including those that form control characters such as cursor down, and carriage return. This will be
Hlustrated soon.
BASIC allows string expressions up to 255 characters long. These can be output to the screen or to any
Output device which accepts more than 79 characters. Input, however, is usually restricted to 79
characters because of the size of the input buffer. This problem can be handled by breaking strings into
substrings before they are input or by using GET to input each character individually. The substrings or
individual characters can then be recombined into the original string by concatenation.
COMPARISON OF STRINGS
The ASCII table is defined in Figure 2.6. it contains the order in which characters within the PET are
represented when two strings are compared. Characters within a set of strings are compared starting at
the leftmost character to the end of the field specified.
Using the ASCII table, we can compare a string containing an “A” to one containing à “B” in the same
position. The result is that the second string is greater than the first.
A string containing a blank is less than a “1”, which is less than an “A”, which is less than a “B”. The
string “A” is less than the string “ABC” or any string containing “A” as the first character. All characters
are compared in sequence with the first unequal character defining the relationship between the strings.
Thus the same relational functions may be used for both strings and numbers.
< > for unequal
= for equal
< for less than
> for greater than
Immediately the string comparison feature can be applied to help you construct ordered lists such as a
check file or a telephone directory. Comparisons can also be used to search ordered lists such as a file or
a telephone directory.
38
Try the following program to develop a feeling for sequences and matching functions:
10 INPUT A$
20 INPUT BS
30 IF A$ = B$ THEN ? “AS = B$" GOTO 10
40 IF AS <$B THEN ? “A$ <B$" GOTO 10
50 PRINT “AS >B$": GOTO 10
NUMBERS AND ASCII CODES
Two complementary pairs of operations on strings and numbers allow us to put unconventional things
into character strings.
STRS
STR$ is a function of one argument. It returns a string that is the character representation of the
numeric expression:
10X=3.1
20 ?STR$ (X)
RUN
3.1
READY
Positive numbers are preceded by a blank in the STR$ equivalent. Negative numbers have a sign in the
corresponding position.
VAL
VAL is the complement of STR$. It converts a string to a number which may be used for computations. If
the first
non-blank character of the string is not numeric, then the value of the function is zero.
WALZ")
0
READY
On the other hand, VAL will convert as many digits as it can up to an invalid character.
?VAL (3.14 AB”)
3.14
VAL is an excellent function to use with INPUT since it can prevent an inexperienced user from causing a
REDO from START.
CHR$
We have shown that strings may be assigned printable ASCII characters through either literals or direct
INPUT, but some devices require control characters which cannot be produced by normal means. For
example, a PET printer uses shifted carriage return as a specialterminator to indicate a carriage
return with no line feed when it performs overprinting. CHR$ allows you to specify such control
characters by giving the ASCII code number. CHRS is a function to convert a number into internal
ASCII representation. The vaiue of the argument must be 0 = X< = 255.
10 A$ = CHR$(65) + CHR$(66)
20 PRINT A$
RUN
AB
READY.
In the above examples, 65is the ASCII code for “A” and 66is a “B”. We converted the codes to characters
before concatenating them and printing them out.
39
ASC
ASC turns a character into an ASCII code number which may be used in numerical calculations. The
parameter is a string.
7ASC(A
65
If the string consists of multiple characters, then this function will return the code for the first character
of the string.
?ASC( 123)
49
The ASCII code for “1” is 49.
SEGMENT OF STRINGS
In many cases it is desirable to access just part of a string in developing an ordered list. Consider the
problem where in response to an INPUT, a person's name is typed in. It might consist of their first name,
middie intitial, and last name. It is important that for sorting, however, that not all Johns be together, but
that the list be ordered by last name.
In order to be able to separate parts of strings and use them in expressions, PET BASIC provides three
functions. Most of your programming with strings will consist of using one of these three functions to
analyze pieces of a constructed string. We will present the use of the functions and define all three at
once as they are essentially the same function. Three combinations are provided mainly for programming
convenience,
LEFT$, RIGHTS, and MID$
The function specified as LEFTS(string variable, I) gives the leftmost “|” characters of the string
specified. If |
is negative, or zero, or greater than 255, then an ILLEGAL QUANTITY ERROR is printed. RIGHTS(STRING
VARIABLE, gives the rightmost “i” characters of the string expression. When *1” is less than, or equal
to Zero,
or greater than 255, an ILLEGAL QUANTITY ERROR is printed.
There are two expressions for MID$. The first most general one is MIDS(STRING VARIABLE, |, J). This
expression gives “J” characters from the string starting with the “th character. If “1” is greater than the
length of the string, then this will give a null string. If either “I” or “J” negative, or greater than 255, an
ILLEGAL QUANTITY ERROR is printed. For “J” greater than the number of characters left in the string, all
the characters from “1” to the end of the string are returned.
The second expression is MIDS(STRING VARIABLE, I) which is the same as specifying a “J” greater than
the length of the string. All the characters starting in the “I” position until the end of the string are
returned. If “[ is greater than the length of the string, then a null string is returned and if “lis negative,
Zéro, Or greater than 255, and ILLEGAL QUANTITY ERROR is printed.
All of these variables combined will define a new function which allows us to take either the left number
of characters, right number of characters, or a given number of characters starting at a given position of
the string.
To find the last name from our previous example, we can analyze characters starting from the rightmost
character of the string until the first blank is encountered. To implement this program we need one more
function.
LENGTH OF A STRING
The LEN function gives an exact count of the number of characters contained in a string. Non-printing
40
characters and blanks are all counted as part of length.
Strings are stored in BASIC with a 3-byte vector. Two bytes are a pointer to the location in memory where
the string is stored and the third byte is the length, the LEN function extracts this byte.
We can now write a general purpose program to extract the last name from a full name.
10 INPUT“NAME:FIRST, MI, LAST ¡AS
20 | = LEN(A$)
30 IF mid$(A$,1,1) =" "THEN 60
40 |=1-1
50 IF 1>0 GOTO 30
60 PRINT “LAST NAME = "; MIDS(AS, 1+1)
Two variants of MID$ are used here. Line 30 uses the case where a length is specified as the first
parameter. We are using a length of 1 to search for the blank delimiting the last name. Line 60 does not
specify a length in the MID$. Everything beyond the position of the blank is taken.
STRING STORAGE
Strings are stored in the space between the end of your BASIC program and the highest RAM locations.
As each new string is added, a chain grows downward from the top of memory.
Storage is optimized by never creating a copy of a string assigned to a literal. in this case the vector for
the string points to where the literal occurs in text in memory. Likewise, if an expression A$ = B$ is
executed, both AS and B$ will share the same copy of the string. New string is required only If a
concatenation or INPUT is executed.
A LARGER EXAMPLE OF STRING FUNCTIONS
Using the string functions described thus far we can write a routine which will shuffle a deck of cards for
us and deal them out one at a time. The following routine has applications In many games like poker or
bridge. Note use of the PET graphics card symbols:
183 REM SET UP DECK WITH ALL 52 CARDS
119 C$="A424364454047054948T2J 404:
128 C$=C+4+"AYIV405 CET YE VIV TJ EQ O"
138 C$=CH+"A062030445 46007 05430 T9J EQ"
148 C$=C5+"'AF24I4445PC97A5A3A TAJTPQSCA"
198 REM PULL À CARD
206 R=26INTLEMLCC4) ERND:C1>.,2+17)-1
291 NA=MIDS(C$,R.1): Y1=MIDFLCS,R+1,1)
430 REM SHRINK THE DECK
432 IFR>1THENT$=LEFT$CC$,R-1) :5OTO435
435 T3=""
435 CI=THHMIDÉSCHOR+Z2
433 REM FRINT A CARD
435 PRINTS: Y+,
456 IFLEHN(C4)2=1THEN206
455 REM END OF DECK
468 INFUT ANOTHER DEAL FE 17%
478 GOTU185
READY.
The string C$ is initialized to contain a deck of cards. Two characters represent each card; the suit and
rank. As a card is dealt, N$ contains the rank and Y$ contains the suit. The deck string, C$, shrinks each
time so that unique cards are always dealt. |
Statement 105 clears the screen. This is done just for show so that the program can illustrate the dealing
of cards. C$ is initialized in statements 110 through 140. C$ is concatenated because the literal
assignment is too large to fit on one line.
41
Statement 200 uses RNDto generate an.index into CS. The random index is in the range 1 to LEN(CS) — 1.
In 201 the index is used to pull N$(rank)Y$(suit) from C$ by the MIDS function.
432 through 435 removes the card from the string so that it will not be dealt again. Since the second
argument of LEFT$ cannot be zero, the R>1 test in 432 prevents an ILLEGAL QUANTITY ERROR.
440 prints each card for our program as it is pulled. 450 tests for the end of the deck and 460 allows the
user to reshuffle.
USER DEFINABLE FUNCTIONS
To this point we have covered all the functions intrinsic to BASIC. Those familiar with mathematics are
used to many more functions in that realm, especially trigonometric. While one could write code to
approximate certain functions in line it becomes very tedious and from a documentation standpoint a
simple expression might become unreadable. Fortunately ,the facility exists in PET BASIC to define
functions in terms of other functions.
A function is defined in a DEF statement:
100 INPUT B
110 INPUT C
120 DEF FN A(V)=VIB + C
The name of the function is “FN” followed by any legal variable name. Recall that a variable is either a
letter or a letter followed by a letter or digit.
Thus the following are valid function names:
FNX
FNJ7
FNKO
FNR2
The most severe limitation of user-defined functions is that they must be contained in their entirely on
one line (80-characters). String functions cannot be defined.
The variable in parentheses following the variable name is called a dummy variable. A function may be
defined to be any expression but it ma y have only one argument. Other variables used in the expression
are considered to be global (have the same value as in the rest of the program), and their current values
are used in the evaluation.
After the funtion definifion has been executed, a user defined function can be used as in the following
example:
130 Z = FNA(3)
140?Z
When the DEFFN statement is executed, a simple variable entry is made in the variable table. The first
character of the name has bit 7, the most Significant bit, set to indicate it is a function name. Associated
with the name are two pointers: an address of the text where the function is stored and an address of
where the dummy variable is stored. The code to execute a function Is re-entrant so that a function may
be defined in terms of other DEF FN. An out of memory error will occur in time as the available stack
space is consumed by recursion.
Figure 6.1 shows some user-defined functions which are ready to be used in PET BASIC programs.
42
FUNCTIONS EXPRESSED IN TERMS OF BUILT-IN BASIC FUNCTIONS
SECANT, SEC(X)
DEF FNA(X)= 1/COS(X)
FOR X < >nf2
COSECANT, CSC(X)
DEF FNB(X) = 1/SIN(X)
FOR X< >0
CONTANGENT, COT(X)
DEF FNC(X) = COS(X)/SIN{X)
FOR X< >0
INVERSE SINE, ARCSIN(X)
FND(X) = AINQUSQR( — XX + 1)
FOR ABS(X) < 1
INVERSE COSINE, ARCCOS(X)
DEF FNE(X) = — AIN(X/SQR(— X*X + 1)) + 1/2
FOR ABS(X) < 1
INVERSE SECANT, ARCSEC(X)
DEF FNF (X) = AIN(SQR(X*X — 1)} + (SGN(X)-— 1)"r/2
FOR ABS(X) > 1
INVERSE COSECANT, ARCCSC(X)
DEF FNG(X) = AIN(1/SQR(X*X — 1)) + (SGN(X} — 1)*n/2
FOR ABS(X) > 1
INVERSE COTANGENT, ARCCOT(X)
DEF FNH(X)= — ATN{X) + n/2
FOR ANY X
HYPERBOLIC SINE, SINH(X)
DEF FNI(X) = {EXP(X) — EXP{— X})/2
FOR ANY X
HTPERBOLIC COSINE, COSH(X)
DEF FNJ(X) = (EXP(X) + EXP(— X)/2
FOR ANY X
HYPERBOLIC TANGENT, TANH(X)
DEF FNH(X)= — EXP(— XMEXP(X) + EXP(— X)"2+1
FOR ANY X
HYPERBOLIC SECANT, SECH(X}
DEF FNL{X) = 2KEXP(X) + EXP(— X))
FOR ANY X
43
HYPERBOLIC COSECANT, COSH(X)
. DEF FNM(X) = 2/EXP(X) — EXP(— X))
РОВ Хх < > 0
HYPERBOLIC COTANGENT, COTH(X)
DEF FNN(X)= EXP( — XYWEXP (X)-+EXP (-X) ) #2+1
FORX< >0
INVERSE HYPERBOLIC SINE, ARCSINH(X)
DEF FNO(X) = LOG(X + SQRX*X +1)
FOR ANY X:
INVERSE HYPERBOLIC COSINE, ARCCOSH(X)
DEF FNP(X) = LOG(X + SOR(X*X — 1))
FORX> =1
INVERSE HYPERBOLIC TANGENT, ARCTANH(X)
DEF FNQ(X) = LOG({1 + XX(1 - Х)у2
FOR ABS(X) < 1
INVERSE HTPERBOLIC SECANT, ARCSECH(X)
DEF FNR(X) = LOG((SQR( — X*X + 1) + 1150
FORO < X < =1
INVERSE HYPERBOLIC COSECANT, ARCCOSH(X)
DEF FNS(X) = LOG(SGN(X)*SQR(X*X + 1) + 1/X)
FOR X < > 0
INVERSE HYPERBOLIC COTANGENT, ARCCOTH(X)
DEF FNT(X) = LOG((X + 1V(X — 1)у2
FOR ABS(X) > 1
GOSUB-RETURN |
We have seen how to use the DEF FN to create a singie variable function which can be used like any
intrinsic function. The major limitation of DEF FN is that it can consist of only a single algebraic
expression and it must fit on one line.
Often several lines of code will be repeated through a program. These program lines can be collected in
one place and executed by a GOSUB command:
GOSUB 5000
The lines of code are called a subroutine. GOSUB means go to the subroutine. It differs from GOTO in
that GOSUB remembers at which line number it was executing before the GOSUB and can return
automatically to the following line after executing the subroutine code.
A subroutine is stored as a series of lines in BASIC starting at the line number specified by the GOSUB.
The last line of the subroutine must be a RETURN statement. This tells BASIC you want to resume
executing the mainline code after the GOSUB.
Example;
10 REM THIS IS THE MAINLINE CODE
20 GOSUB 50
30 STOP
50 REM THIS IS A SUBROUTINE
60 RETURN
If we could take a snapshot of execution, we would see the lines executed in this order
10 - 20 - 50 - 60 - 30
Five bytes are pushed onto the stack when a GOSUB is executed: a GOSUB token, and two bytes each for
the line number and text address of the GOSUB. The line number following the GOSUB is stuffed into the
currently executing line number and the GOTO routine handles the branch. RETURN restores the line
number and text address from the stack to resume mainline execution. All F O R entries in front of the
GOSUB entry are also eliminated.
The physical limitation on the number of GOSUB’s in effect at one time is 23. After this many there is very
little stack space left.
Example of subroutines
Consider the factorial function:
nl=1x2x3x..xn
You cannot define this function with the DEF FN command. On the other hand, you can use the following
simple routine to find n! for any given n (up to 34). (NF denotes n factorial)
10 INPUT N
100 |= 1:МЕ = 1
110 NF=NF"|
120 |=|+1
130 IF | <=N GOTO 110
140 PRINT NF
The routine on lines 100-140 could be used many times during a program using different values for N. For
example, suppose you want a binomial coefficient:
The program would be
10 PRINT “M ="";: INPUT M
15 PRINT “R ="; INPUT R
20 N = M:GOSUB100:X = МЕ
30 N =R:GOSUB100:Y =NF
40 N=M-R:GOSUB100:Z=NF
50 BC=X/{Y"Z)
60 PRINT BC
70 END
100 I=1:NF=1
110 NEF=NF"1
120 |=|+1
130 IF| <=N GOTO 110
140 RETURN
45
TYPE RUN
for the values M=11 R=86.
RESULT IS 462
Subroutines act like a “black box” ог complex function within the program. Certain fixed variables are
used to input the data and other fixed variables (or sometimes the same variable) are used to output the
results, For example, in the subroutine on lines 100-140, the variable N is input and the variable NF is
output as shown:
№ — SUB100 —> NF
NF =N!
When we make N equal to M, R, and M-R respectively, we get NF equal to Mi, R! and (M-R)!.
Of course, some subroutines do not need in putted variables as they might just perform a specified
function such as printing a special form on the screen:
SUB — print form
NESTED SUBROUTINES
The subroutine on page 6-14 itself could be used as a subroutine in a program that repeatedly calculates
the binomial coefficient. Merely change line 70 to
70 RETURN
The subroutine, denoted SUB 10, beginning on line 10 and ending on line 70 has the following structure:
M— ("
SUB10 — BC BC= Ip
R—
Ny TNF
SUB100
Subroutines that are used by other subroutines are called nested subroutines. In this case, SUB100 is
nested in SUB20. Many programs have subroutines nested in subroutines in nested subroutines... The
only limit is the amount of memory available,
Subroutines can also be nested in more than one Subroutine. An input subroutine, for example, that
accepts specific characters from the keyboard, prints a winking cursor, and prints the given characters
on the screen, might be called on many times in the main program itself and also in various other
subroutines.
CAUTIONS
A common error in using subroutines is to allow a mainline execution to fall into a following subroutine
and result in a RETURN WITHOUT GOSUB ERROR. Put a STOP or END statement in your code to prevent
46
this
10 GOSUB 20 10 GOSUB 20
20 RETURN 15 END
20 RETURN
Sometimes, you might have a tendency to make everything into a subroutine. If a given subroutine is used
just once, then it should be incorporated into a program where it is used to save execution time and
memory space. On the other hand, subroutines are incredibly powerful programming tools and allow you
to structure your program into blocks.
FOR-NEXT LOOPS
FOR-NEXT simplifies the writing of BASIC programs by allowing one to specify complex loop structures
with a single statement.
FORI= ATO BSTEPC
The end of the loop is specified by the statement
NEXT
Nested FOR NEXT loops are permitted as long as each loop uses a unique variable. Use of identical loop
variable names may result in NEXT WITHOUT FOR errors.
Exiting a FOR-NEXT loop via a branch will leave the FOR entry on the stack. The best way to handle this is
to assign the maximum limit to the variable then exit the loop through a NEXT.
We have seen how repeated operations can be performed using a counting variable such as lin the
routine.
10 |=1
20 I=1+1
30 IFI<=10 THEN GOTO 20
In this case, any routine appearing in lines 21-29 will be repeated 10 times. in addition, the variable | will
have values which range from 1 to 10 in increments of 1.
This looping process can be genralized in the case:
10 1=A
20 I=1+C
30 IFI<=BTHEN GOTO 20
The values of | will range from A to B in increments of size C.
Since this process is cumbersome to use, BASIC also provides you with the FOR-NEXT statement:
10 FORI=ATOBSIEPC
20 NEXT
| is the counting variable, A is the initial value, B is the ending value, and C is the increment.
A, B, C may not only be constants, but they can be any valid arithmetic expression
10 FOR 1= A(2) +1 TO J*2 STEP -1
On the other hand, the counting variable can be any floating variable but cannot be integer (1%1d or
subscripted (1,4). When the increments are of size (С = 1) you need not include the STEP in the program.
10 REM COMPUTATION OF FACTORIAL
20 NF=1
30 FORI=1TON
47
40 NF=NF"l
50 NEXT
Note how much shorter and more clearly this routine is written compared to the same factorial
computing program written without FOR-NEXT.
Whenever a FOR is executed, a 16-byte entry is pushed onto the stack. Before this is done, a check is
made to see if there are any entries already on the stack for the same loop variable. If so, that FOR entry
and all other FOR entries that were made after it are eliminated from the stack. This is done so that a
program which jumps out of the middie of a FOR loop again will not use up 16-bytes of stack space
each time.
NEXT matches the most recent stack entry or the variable specified as a parameter and resets the stack
to that point. If no match is found, a NEXT WITHOUT FOR error occurs.
GOSUB execution also puts a 5-byte entry on the stack. When RETURN is executed, the stack is searched
for a FOR entry that cannot be matched, When all the FOR entries on the stack have heen searched, a
pointer |
is left on a GOSUB entry. This assures that if you GOSUB to a section of code in which a FOR loop is
entered but never existed, the RETURN will still be able to find the most recent GOSUB entry.
RETURN eliminates the GOSUB stack entry and all FOR entries made after the GOSUB entry.
NESTED FOR-NEXT LOOPS
FOR-NEXT loops, like subroutines, can be nested, That Is, a FOR-NEXT loop may be contained in another
and so on. When doing so, it is important not to use the same counting variable as this will result in
NEXT WITHOUT FOR ERROR
10 FOR 1=1 TO 10 -
15 PRINT “1”
20 FOR J=1 TO 10
25 PRINT “J*
30 FOR K=1 TO 10
35 PRINT К“
40 NEXT
50 NEXT
60 NEXT
Lines 40-60 of the above example are confusing at first glance because one cannot tell which NEXT
corresponds to which FOR. Optionally one may specify a variable following NEXT. The variable refers to
the counting variable used in the corresponding FOR but in no way is it required by BASIC to execute
the NEXT.
40 NEXT K
50 NEXT J
60 NEXT |
FET BASIC will also allow you to write one NEXT that terminates all three FORs at one time
40 NEXT K, J, |
A NEXT WITHOUT FOR error will result, however, if you are careless in specifying the order of K,J.1.
It is interesting, however, to see how com pact the notation appears and how powerful the FOR-NEXT
expressions can be when they are nested.
Some hints
You may change the value of the counting variable during the looping sequence.
For example,
‚10 FOR 1=1708
20 X=X+1
30 IF 1=7 THEN 1=8
40 NEXT
50 PRINT X
will compute the value
X=1+2+4+3+4+5+6+7=286
Similarly, when you exit a FOR-NEXT loop using a branch, you should assign the counting variable the
end value and then exit the loop via a NEXT statement. For instance, you should use
10 FOR 1=1 TO 10
20 1F FNA()=0 THEN |=10
30 NEXT:RETURN
instead of
10 FOR |=1 TO 10
20 1Р FNA(D) = 0 THEN RETURN
30 NEXT
SUBSCRIPTED VARIABLES
Array variables need not be declared with a DIM statement if they have only one dimension and contain
fess than 10 elements. The total number of elements in an array can be computed by multiplying the
(number of elements in each dimension) + 1 by the other subscripts. Thus A{9,8) contains (9%1)*(8%1)
elements. Subscripts start at 0 and go up to the maximum value
A(0,0)-------A(0,8)
A(9,0) — A(9,8)
Limits on the number of dimensions and size of a dimension are determined by size of memory available
and space available on a line following a DIM. PET BASIC restrict the total number of
array elements to 256. Each array element requires at least 5-bytes of storage.
If a single dimension array requires more than 10 elements, the DIM statement must be executed before
the first reference. Otherwise, a REDIM’ED ARRAY error will occur.
Example: List of account balances
$100
$135
$567.86
<$987>
$22
<$63>
$50
<$21>
$21
O Cor СО EN Aa CO ВО a
Suppose we need to write a simple program which allowed you to INPUT an account number and a -
transaction and keep a running total on each account. We could refer to each account balance as Al, A2,
49
A3, A4, A5, etc. This is acceptable but would require a lot of parallel logic to accomplish the summation
10 INPUT “ACCOUNT, CHARGE": LC
201F 1=1 THEN A1=A1+C
30 IF 1=2 THEN A2=A2+C
etc.
This list can be stored in a single variable which is actually a list of variables. This list is an array of
values and an individual value is accessed by an index. The index we can use is the account number. Our
program can be reduced to:
10 INPUT “account, charge”; 1,C
20 А) = А) + С
30 GOTO 10
The list we have represented has 9 rows and 1 column. Thus it is a 1 dimensional array. A multiple column
table can also be represented, This is a two dimensional array.
Account # Balance #¥of transactions
$100
$135
$57.86"
<$987>
$22
<363>
$50
<$21>
$21
O AO UN A CON -+
A La A Aa e e A
Our table has 9 rows and 2 columns. To access a certain entry position, you must specify the row index
and column index of where it is contained. For example, the quantity denoted by a * is in row 3, column 1.
In order to use such a table in a BASIC program, you must provide a statement, to describe the number of
rows and columns contained in the array variable.
Such a description is a DIMension statement. For our table of 9 rows and 2 columns we could write
DIM A(9,2)
Let us rewrite our program to update the column containing the number of transactions
10 INPUT "ACCOUNT, CHARGE”; I, C
20 All, 1) = A(1,1)+C
30 A(l,2) = A{l,2) + 1
40 GOTO 10
Now suppose that we had a table for each of 5 companies and each company had 9 accounts and each
account had a balance and each balance had a number of transactions. We can describe this as piling
sheets of paper on top of each other and refering to each sheet by number.
50
NA
7
We have created by this example a multidimensional subscripted variable. These arrays correspond to
matrices used in mathematics.
In mathematics, a vector is an ordered collection of numbers:
VEÍA, Ya... Va)
The above vector has n components and is called a vector of dimension n.
For example,
v=(3,9,2)
Is a vector of dimension 3.
Order is imporatant here since if
w=(3,2,9)
WEY,
Vectors can be stored in memory using subscripted variables. These variables are used in the same way
as the variables we have seen so far -X, 1%, AS, etc. That is, they call whatever value is stored in that
variable or return a zero or null (* *) if the value has not been previously specified.
Like vectors, subscripted variables have the power to execute a large number of operations using a single
notation. They are especially useful when combined with FOR-NEXT loops as the next example shows.
Example: Dot Product
The dot product of two vectors v & w is a vector, denoted by v * w, whose ith component (vew) is и, X w
For example, in the four dimensional case, if ;
у = (ми, уз, Va, V4) I
and w =(w,, wy, Wy, Ww.)
Then vew = (y, Xx wr, Y: x Wa, Va X Ws, Уд X Wa)
Suppose we had
v=(5,6,7,11,4,6 |
w=(9,5,2,1,0,3,2)
Then a program to compute the dot product y * w might look like
FORI=1TO7:READ V(IHNEXT
FORI=1TO7:READ WIINEXT
FOR 1= 170 7:VW(1) = VII WII.NEXT
FORI=1TO 7:?VWIN:NEXT
51
DATA 5,6,7,11,4,6.1
DATA 9,5,2,1,0,3,2
SUBSCRIPTED STRING VARIABLES
It was mentioned previously that subscripted variables can be
decimal: A(h
integer: À %(l)
string: AS(l)
Subscripted string variables are extremely useful as shown in the next program which prints a bar graph
of the U.S. GNP from 1966 through 1974.
GROSS NATIONAL PRODUCTS
(№ $ BILLIONS)
The program listing is:
READY
10 SPACE $=" -
20 FOR 1=1 TO 7: READ AS(NNEXT
30 FOR T=0 TO 8: READ V(INEXT
40 PRINT" 7 SPE(SY'GROSS NATIONAL PRODUCTO"
50 PRINTSPC(1)“(IN $BILLIONS)Q”
100 FOR 1=0 TO B
110 X=V(1)45:Y = INT(X)
120 PRINT “R”LEFTS(SPACES, Y)AS(S* (X — Y)
130Q” PRINT “ £* R"STRS(66 +1)” $“STAS(VUN“Q”
140 NEXT
200 DATA“, ‘P" “|” “]"
210 DATA753,796,869,936,982,1063,1171,1307,1413
READY
The subscripted values Y(0), Y(1),..., Y (8) are the GNP's for each of the 9 years. The subscripted strings
AS(0), AS(1),...AS(7) give accuracy to the graph by printing these graphics:
string prints ASC
А$(0) null{by
default)
AS(1) | 165
А$(2) | 180
А$(3) || 181
AS(4) Ни 161
А$(5) Ни 182 (R)
А$(6) HE 170 (R)
AS(7) L 167 (A)
THE HEADING
GROSS NATIONAL PRODUCT
(IN $BILLIONS)
is printed in lines 50 and 60 and then a FOR-NEXT loop on lines 100-140 prints out the eight bars. Line 120
prints out each bar and line 130 prints a cursor up and then the associated year, STR${(66 + |) and GNP,
STR$(V(I)).
Each bar is made up of Y reverse field spaces and the string A$(8*(X-Y)). The Y is determined by the
formula
Y =INT(V(1V45;
= INT (GNP/45)
Here, 45 is purely a scale adjustment. The proportions of the bars remain the same when values other
than 45 are used.
Fine tuning on the bar length is accomplished using the subscripted string variable
AS(8* (X-Y))
Here 8" (X-Y) will range over the decimal values 0 through 7.99...9 but A$ automatically truncates the
decimal part.
DIMENSIÓN STATEMENTS
When using more than 10 subscripts for any variable, a dimension statement must be given. It takes the
form, DIM ASK), where K is the largest subscript of A$ used in the program. When variables are
redimensioned without a CLR statement or when a dimension statement appears after the variable has
been used, a ?REDIM'D ARRAY ERROR occurs. When a dimension statement is made, space is reserved
in memory for the given number of variables, including the variable whose subscript is 0. It is good
programming sense, therefore, to begin subscripts at 0 and not 1.
Because the variables are divide in storage between arrays and simple variables insertion of an
additional simple variable is a bit more complicated once an array has been defined. First, the entire array
storage area must be block moved upward by seven bytes and the pointers adjusted upward +7. Finally,
the simple variable can be inserted at the end of simple variable storage.
53
If large arrays are defined and initialized first before simple variables are
assigned, much execution time can be lost moving the arrays each time a
simple variable is defined. The best strategy to follow in this case is to
assign a value to all known simple variables before assigning arrays. This
will optimize execution speed.
Functions of new and CLR on data pointer:
CLR
String pointer equated to top of memory
Data pointer to start of text -1
End of array table to start of variables
End of simple variables to start of variables
NEW
String pointer equated to top of memory
Data pointer to start of text -1
End of array table to start of text +3
End of simple variables to start of text +3
Start of variables to start of text +3
54
WYy L2d olu¡ siejuiod j2diouud zg enbBig
7818 GZLL ELLE c60l | - 5201
sBu.Ss SABLE SO|GELIBA suswsjels
SY
/N A AN AN AN AN /N\ Wweiboud [edidAy
8c0l SCOL #20
2618 000
/N\ A uvonezienul ye
7
\
\
\
end of array table
end of variables
start of variables
data statement
top of memory
start of strings
start of text
ctl OC} Bel 921 vet РУ! cel )M33d
cer LEL Gel ¿cl Get avi ECT 33d . 996
WYd 13d OLNI SHILNIOd TYdIONIHd
55
Chapter 7. PET INTERFACES AND LINES
As indicated in Figure 7.1, there are four connectors provided, accessible through slots in the rear and
side of the PET that enable the user to interface the computer with external devices.
As outlined In Figure 7.2, edge card connectors are utilized which are, in fact, direct extensions of the
PET main logic assembly board itself. There are two contacts to each position of the connector. The
contact identification convention for J1 and J2 is also illustrated in Figure 7.2.
| IEEE-485 1.6 A FUSE
To as aH IND CASSETTE INTERFACE 11 | (& 0 BLO)
INTERFACE J3
PARALLEL 2. WIRE AC
USER PORT J2 POWER CORD
SERIAL NUMBER
ELECTRICAL SPEC.
Figure 7.1. Simplified view of PET showing switch,
fuse, line cord and interfacing connectors.
FROM PET MAIN LOGIC ASSEMBLY BOARD
Top View
ANY Upper
Insulation Contact
\ 2 3 4 5 6 7 8 9 10 11 2 y” tor Pin)
Lower
AB C DEF HJ KLM N™ contact
Hear or Edge-on View through slots in PET {or Pin}
Figure 7.2. Simplified views of edge connectors J1 and J2
to illustrate contact identification convention.
IEEE-488 INTERFACES (Connector J1)
The standard |EEE-488 connector is not used on the PET. Instead, a standard 12 position, 24 contact edge
connector with .156 inch spacing between contact centers is provided. This permits it to be compatible
with all of the other connections to the PET.
Keying slots are located between pins 2-3 and 9-10.
Table 7.3 shows the PET contact identification characters, the connection for a standard IEEE connector,
a7
the IEEE mnemonics and the signal definitions.
Eiectrical- drive capability and line impedance matching is in accordance with |EEE-488 specifications.
Standard
PET Pin IEEE IEEE Signal
Characters Connector mona ic Definition/Label
Numbers
Upper Pins
1 1 D101 Data input/output line #1
2 2 D102 Data input/output line #2
3 3 DIOS Data input/output line #3
4 4 D104 Data input/output line #4
5 5 EOI End or identify
6 6 DAV Data valid
Fi 7 NRFD Nat ready for data
8 8 NDAC Data not accepted
9 9 FFC Interface clear
10 10 SRO Service request
11 11 ATN Attention
12 12 GND Chassis ground and 1EEE
cable shield drain wire
Lower Pins
A 13 DIOS Data input/output line #5
B 14 DI06 Data input/output line #6
С 15 DIO? Data input/output line #7
D 16 DIOS Data input/output line #8
E 17 REN Remote enable
F 18 GND DAY ground
Lower Pins
H 19 GND NRFD ground
J 20 GND NDAC ground
K 21 GND IFC ground
L 22 GND SRQ ground
M 23 GND ATN ground
N 24 GND Data ground (DI01-8)
Table 7.3. PET contact identitication characters.
IEEE-488 identification characters,
associated labels and descriptions.
RECEPTACLES FOR THE IEEE INTERFACE
A list of frequently used 12 position, 24 contact receptacles that are suitable for connection to the PET
edge card connector J1 and J2 is shown here:
Manufacturer Part Number
Cinch 251-12-90-160
Sylvania BAGGB1-12-1A1-61
Amp 530657-3
Amp 530658-3
Amp 530654-3
Table 7.4. Receptacles recommended for PET IEEE-488
connectors or parallel user port.
58
|EEE-488 CONNECTORS
The IEEE-488 standard receptacles are not directly connectable to the PET edge connector; some of
these are shown in Table 7.5, and belong to the Cinch Series 57 or Champ Series (Amphenol). Also shown
are their matching plugs.
Connector €: e
Manufacturer Identifier Description
Cinch 5710240 Solder-plug
Cinch 5720240 Soider-receptacle
Amp 552301-1 Insulation displacement plug
Amp 552305-1 insulation displacement receptacle
Table 7.5. IEEE standard connectors
Commodore has available a 1 meter long |EEE-488 dual connector-PET edge connector, cable. Please
contact your local dealer or Commodore for price and delivery.
PARALLEL USER PORT {Connector J2)
The lines for this interface are brought out from the PET main logic -board to a 12 position, 24 contact
edge connector with a .156 inch spacing between contact centers. See Table 7.4 for suitable mating
connectors.
Keying slots are located between pins 1-2 and 10-11.
Table 3-1 shows the PET pin identification characters, the corresponding labels and their descriptions.
Note that the connections 1-12, the top line of contacts (see Figure 7.6), are primarily intended for use by
the PET service department or qualified dealers. When using the incorporated ROM diagnostic, a special
connector is used; this jumpers some of the top contacts to the bottom contacts. /t is strongly advised
that the top connectors 1-12 be used only with extreme caution.
Pin
Identification | -Signa Signal
Character abel Description
Ground Digitel ground.
2 T. Y. Video Video output used for external display,
used in diagnostic routine for verifying
the video circuit to the display board.
3 IECE-SRO Direct connection to the SRQ signal on
the IEEE-488 port. 11 is used in verify-
ing operation of the SRQ in the diag
nostic routine,
4 IEEE-EQI Direct connection to the EOI signal on
the IEEE-4838 port. It is used in verify-
ing operation of the EOI in the diag-
nostic routine.
5 Diagnostic When this pin is held low during power
Sense up the PET software jumps to the diag-
nostic routine, rather than the BASIC
routine.
Table 7.8. Parallel user port information.
PET pin identification characters, the corresponding
signal labels and their descriptions.
Table continued on next page.
59
Table 7.6. Parallel user port information (continued).
Pin Signai Signal
Identification Label Description
Character Р
6 Таре #1 Used with the diagnostic routine to
READ verify cassette tape #1 read function,
7 Tape #2 Used with the diagnostic routine to
READ verify cassette tape #2 read function.
8 Tape Write Used with the diagnostic routine to
verify operation of the WRITE func:
tion of both cassette ports.
9 TV Т.М vertical sync signal verified in
Vertical diagnostic. May be used for external
TY display.
10 TV T.V. horizontal signal verified in
Horizontal diagnostic may be used for TV display.
11, 12 GND Digital ground.
A GND Digital ground. |
B CAT Standard edge sensitive input of
6522VÍA,
С PAD
D PAI Input/output lines to peripherals,
E PAZ and can be programmed independ-
F РАЗ ently of each other for input
or output.
H PA4
J PAS
K PAB
E PAT
M CB2 Special 1/0 pin of VIA.
N GND Digital ground.
VERSATILE INTERFACE ADAPTER
The lines on the bottom side of the user port connector originate from a Versatile Interface Adapter
(VIA MOS Technology part #6522).
The signals CA1, PAO-7, and CB2, are directly connected to a standard 6522 VIA located at hexadecimal
address E840. (Decimal address 59456).
The parallel port consists of eight programmable bi-directional 1/O lines PAO-7, an input handshake line
for the eight lines,CA1, which can also be used for other edge-sensative inputs and a very powerful
connection, CB2. This has most of the abilities of CA1, but can also act as the input or output of the VIA
shift register.
A detailed specification for the VIA is below. All signals on the VIA that are not connected to the user
port are utilized by the PET for internal controls. Please note that the user should avoid interfacing these
signals in any way.
Table 7.7 shows the decimal and hexadecimal addresses in the PET associated with the VIA.
Decimal Hexa- $E840+ Addressed Location
Decimal
59456 E84 0000 Output register for 1/0 port B.
59457 E841 0001 Output register for 1/0 port A
with handshaking.
59458 EB42 0810 1/0 Port 8 Data Direction
register.
59459 EB43 0011 1/0 Port A Data Direction
register.
59460 Е844 #100 Read Timer 1 Counter low order
by te Write to Timer 1 Latch
low arder byte.
59461 EB45 0101 Read Timer 1 Counter high
order byte, Write to Timer 1
Latch high order byte and
initiate count.
59462 EB46 0118 Access Timer 1 Latch low order
byte.
59463 EB47 0111 Access Timer 1 Latch high order
byte.
59464 E848 1000 Read low order byte of Timer 2
and reset Counter interrupt.
Write to low order byte of
Timer 2 but do not reset
interrupt.
59465 £849 1901 Access high order byte of Timer
2: reset Counter interrupt on
write,
59466 E84A 1010 Serial 1/0 Shift register.
59467 EB4B 1011 Auxiliary Control register,
59468 Е84С 1160 Peripheral Control register.
59469 E84D 1101 Interrupt Flag register (FR),
59470 EB4E 1110 Interrupt Enable register.
59471 EB4F 1111 Qutput register for 1/0 Port A,
without handshaking.
Table 7.7. VIA 6522 Decimal end Hexadecimal addresses in PET.
PROGRAMMING THE USER PORT
Data lines PA0-7 are individually programmed to function for input or output as required. This is done by
using a software POKE 59459 command to place a number into the data direction register. Table 7.8
shows a practical example of input/output selection.
The programming need only be carried out at the beginning. From then on POKE 59471 can be used to
drive the pins programmed as outputs, and PEEK(59471) will read all the inputs.
61
Command Binary .
Statement Representation Lines Mode
POKE 59459, 255 11111111 PAG-7 Output
POKE 594590 000000008 PAQ-7 Input
PORKE 59459, 240 11119600 PAG-3 Input
РА4-7 Output
Table 7.6. Parallel user port example.
Programming of lines PAO-7 for input/output operation.
SECOND CASSETTE INTERFACE (Connector J3)
This interface is brought out from the PET main logic board to a 6 position, 12 contact edge connector
with .156 inch spacing between contact centers (See Figure 7.9).
A keying slot is located between pins 2-3.
This port is intended for use with the Commodore second cassette system only. Any other connections
are made at the risk of the user. Please note that +5 volts is not intended for use as an external power
supply.
Table 7.10 shows the PET pin identification characters, labels and descriptions. Table 7.11 shows some
typical receptacles that are suitable for the second cassette connector.
| FROM PET MAIN LOGIC ASSEMBLY BOARD
Top
View
Upper
Contact
4 5 6 pd (or Pin)
rl
Insulation
a t 23
Lower
ABC DE F Contact
{or Pin}
Rear or Edge-on View thhough slot in PET
Figure 7.9. Simplified view of edge connector J3
with contact identification.
Note A-1, B-2, etc., imply a pin A to pin, pin B to pin 2, connection.
tn some special units, pins 1 through 6 were not connected,
Pin
identification Label Description
Characters
A-1 GND Digital ground.
B-2 +5 Positive S volts to operate cassette circuitry
only.
C-3 Motor Computer controlled positive 6 volts for
cassette motor.
D-4 Read Read tine from cassette.
E-5 Write Write line to cassette.
F-6 Sense Monitars closure of mechanical switch on
cassette when any button is pressed.
Table 7.10. Secand cassette interface port.
PET pin identification characters, labels and associated descriptions.
62
Manufacturer Identifier
Sylvania BAJO7-6-1A 1-07
Viking 2KHE/1AB5
Viking 2KH6/9AB5
Viking 2KH6/21AB5
Amp 5:306972-1
Sutlins ESM6-SREH
Cinch 250-06-909-179
Table 7.11. A selection of suitable receptacles for connecting
with the PET second cassette edge connector J3.
MEMORY EXPANSION CONNECTOR (Connector J4)
The memory expansion connector provides access to the buffered and decoded input/output lines from
the 6502 microprocessor. Figure 7.12 shows a simplified view of the 40-position-80 contact edge
connector used. The spacing between contact centers is 0.1 inch.
Note that the 40 top edge “B” connections (or pins) are ground returns for the corresponding 40 lower
edge “A” connections.
o SIDE B x Upper
a Contact
+ dr Pin)
Se 33 34 35 36 37 38 39 40
SIDE A | Lower
Rear or Edge on View through slot in PET Contact
far Pin)
Figure 7.12. Simplified view of edge connector J4 with contact
identification. All side B contacts grounded.
Table 7.13 shows the PET pin numbers, line labels and line descriptions.
Side A Line . en
Pin Numbers Labels Line Description
Al BAG Address hit @, used for memory expansion.
Buffered.
A? BAT Address bit 1, used for memory expansion.
Buffered.
A3 BAZ Address bit 2, used for memory expansion.
Buffered.
Ad ВАЗ Address bit 3, used for memory expansion.
Buffered.
A5 BA4 Address bit 4, used for memory expansion.
Buffered.
A6 BAb Address hit 5, used for memory expansion.
Buffered.
A? BAG Address bit 6, used for memory expansion.
Buffered.
AB ВА7 Address bit 7, used for memory expansion.
Buffered.
Table 7.13. Memory expansion connector. PET pin numbers.
Line labels and line descriptions.
Table continued on next page.
63
- os ow aa. u
Table 7.13. Memory expansion connector. PET pin numbers.
Line labels and line descriptions (continued).
Side A Line . Le
Pin Numbers Labels Line Description
A9 BAS Address bit 8, used for memory expansion.
Buffered.
A108 BAO Address bit 9, used for memory expansion,
Buffered.
All ВАЛО Address bit 19, used for memory expansion.
Buffered.
A12 BAJI Address bit 11, used for memory expansión.
Buffered,
A13 NC No connection.
A14 NC No connection,
A115 NC No connection.
AE SEL 1 4K byte page address select for memory
locations 1000-1FFF.
A17 SEL 2 AK byte page address select for memory
locations 2000-2FFF.
A18 SEL 3 4K pyte page address select for memory
locations 3000-3F FF.
A19 SEL 4 4K byte page address select for memory
locations 4903-4F FF.
A20 SEL 5 4K byte page address select for memory
locations 5000-5F FF.
А21 SEL 6 АК byte page address select for memory
locations 6000-6FFF.
А22 SEL 7 4K byte page address select for memory
locations 7008-7FFF.
A?3 SEL © 4K byte page address select for memory
locations 9908-9F FF.
A24 SEL À 4K byte page address select for memory
locations ADOO-AFFF.
А25 SEL B 4K byte page address select for memory
locations BOG&-8FFF.
A26 NC No connection.
AZT RES Reset for 6502 microprocessor, Note:
connected to 741500 output.
A28 IRQ Interrupt request line to the microprocessor,
A29 BO? Buffered phase 2 clock.
A30 RAY Buffered read/write from 6502 micro-
processor.
A31 NC No connection,
A32 NC No connection.
A33 BDO Data bit 0. Buffered.
A34 BD1 Data bit 1. Buffered.
A35 BD? Data bit 7, Buffered.
A36 BD3 Data bit 3, Buffered.
A37 BD4 Data bit 4. Buffered.
A38 BD5 Data bit 5, Buffered,
A39 BD6 Data bit 6. Buffered.
A40 BD? Data hit 7. Buffered.
64
ADDITIONAL BASIC COMMANDS
By this time, the user is probably familiar with the use of the commands INPUT and PRINT. INPUT
permits the output or display of data. These commands are common to all forms of BASIC.
To add flexibility to the PET computer system, several commands have been added to classical BASIC in
the PET, and future Commodore products will take advantage of the resulting extra capability. in general,
enhanced flexibility of data interchange between the PET and peripheral devices is possible, thanks to
the use of these extra commands.
To communicate with any device, a combination of the additional commands is used:
a) OPEN/CLOSE Open or close logical file.
b) PRINTk Write data from PET to 1/0 device.
c) CMD Same as PRINT# but leaves IEEE device an active
listener on bus after execution of command.
d) INPUT# Read data from 1/0 device to PET.
e) GET# PET accepts one character from МО device.
INPUT/OUTPUT COMMAND PARAMETERS
In order to use the additional commands referred to in the above, four parameters must be taken into
consideration:
a) Logical file number (LF)
b) Device number (D)
c) Secondary address (SA)
dy Filename (РМ)
These parameters can appear, for example, when using the OPEN# command in the form of the
statement:
OPEN#LF,D,S,FN
LOGICAL FILES
Files are used to store and retrieve data, as for example in the case of a magnetic tape or disc file. À
convenient extension of this idea is to regard any device which can receive and/or generate data as a
logical file. To the PET operating system, data might just as well have come from, or be going to, a
Storage system such as magnetic tape.
For example, imagine that an external digital voltmeter is set up so that it can transmit voltage readings
upon request to the PET via the IEEE bus. Sometime during the ‘voltmeter program’ the programmer will
have to open a file and assign a logical file number to refer to the voltmeter. Once this has been done, The
PET can use a “read” command (INPUT#) which uses the logical fite number to refer to the voltmeter.
When no further data is required from the voltmeter, the logical file can be closed.
More generally, the advantages offered by the use of logical files are:
a) Every device number secondary address combination
can be associated with its own unique logical file number
within a program.
b) Multiple files within a single dev ice can be refered to
by means of distinct logical file numbers. This approach is
to be used in the newly developed disc storage system for
the PET.
с) Once a logical file number has been defined in an OPEN
65
statement, within a program, only this number need be used
in the following input/output statements. This eliminates the
need for further restatement of device number, secondary
address (where used) and file name (where used).
Although it is permissable to identify and use many logical files in a given program, the PET operating
system has to keep track of the files that are currently in use in the program. The greatest number of files
that can be controlled by the PET at one time is ten. Note that exceeding ten will result in loss of PET
operation; this can be restored by switching the computer oft and on. A logical file number can be any
integer in the range 1 through 255.
DEVICE NUMBERS
All devices which the PET communicates with are assigned numbers. The first four of these are reserved
for the following peripherals:
Device
Number Device
O Keyboard
Default- 1 Cassette 1 pane! mounted
2 Cassette 2 add-on
3 Video screen
All other devices are automatically assumed by the PET to be IEEE devices, and control is transferred to
the device which will have been allocated a number within the range 4 through 30. Except in special
cases, a specific number would be allocated to each IEEE device to allow the PET and a particular device
to communicate using the parallel IEEE-488 bus,
On many IEEE devices, the allocation of the device number is made by means of a switch, or in the case
of less expensive products, by the connection of jumpers.
SECONDARY ADDRESSES
The concept of secondary address may be new to those people who have never worked with the IEEE bus.
The use of a secondary address permits an intelligent peripheral to function in any one of a number of
modes. For example, in a PET printer, there are six secondary addresses:
Secondary
Address Operation
Default- 0 Normal printing
Printing under format statement control
Transfer data from PET to format statement
Set variable lines per page
Use expanded diagnostic messages
Byte data for programmable character
Nn > CI MN —
In short, by changing the secondary address used to communicate with a given physical device, its
operating characteristics can be totally changed, if so desired. Many of the IEEE devices have their own
particular secondary address conventions which must be followed. Specific data on these conventions
can be obtained by consulting the manual for that particular device.
The PET tape units have a special set of secondary address rules:
Secondary
Address Operation
Default- 0 Tape is being opened for “read”
t Tape is being opened for “write”
2 Tape is being opened for “write” with an “endof
tape” header being forced when the file is closed.
66
The secondary address can have values over the range 0 through 31.
FILE NAMES
In random storage devices where there is more than one file to be accessed, the use of names to identify
files is mandatory. In the case of tapes, a file name is desireable, even if there is only one file on the tape,
since it facilitates the identification of tapes.
For the two cassette tape units of the PET, a file name may be any combination of up to 128 characters.
When a file name is searched for, it is matched on an ascending character basis.
Assume that an eight character file name COUNTING was specified when writing. If desired, this could
be searched for with an abbreviated name such as COU. The first file header that is found with these
three consecutive characters will then be opened and positioned on. In principle, this could include
unwanted file names such as COUNT or COUNTRY, as well as COUNTING.
It is, therefore, adviseable to specify the complete file name in order to avoid errors.
For other devices which use named files, the individual description of the device should be consulted in
order to ascertain the specific requirements for file name usage.
TAPE CASSETTE OPERATION FOR FILES
The PET devotes special attention to the two tape cassette units that can be attached to it. The tape units
are specially modified so that the PET has control over the motor movement of the cassette.
It can also sense when the PLAY, REWIND, or FAST FORWARD buttons have been pushed; this is done
by means of a single switch mounted in the tape unit.
Note that the same switch is used to sense all three buttons: if any of the three is pushed, the PET will
think that you pushed the PLAY button and wiil respond accordingly.
Because of the type of mechanism used in the tape unit, the user must rewind, fast forward, stop, load
and eject tapes. He must also put the unit into the write mode by pushing the record button either
simultaneously with, or before the PLAY button is pressed.
The PET has total control over the movement of the tape once the appropriate buttons have been pushed
to engage the motor.
Messages displayed throughout the program will tell the user when it is necessary for him to initiate the
function of play or record. Logic dictates the times when the user should rewind and fast forward.
The two tape units of the PET are handied independently, and the various control lines permit the reading
of data from cassette #1, the reading of data from cassette #2, motor control of cassette #1. motor
control for cassette #2 and a common write line.
FILE RECORDING TECHNIQUE
The data structure embodied in the tape files will ensure the maximum memory utilization and maximum
reliability of recording.
To accomplish this, the PET records data at two audio frequencies in two consecutive blocks of data. All
of the data is totally repeated and by means of error checking techniques incorporated in the PET
software, it is possible for most audio dropouts to be corrected by the operating system utilizing the
redundant data stored in the second data block.
In order to correct for (a), the fact that tape units record at different speeds, and (b), the normal drag
characteristics of tapes, a speed correlation technique is used during reading. To correct for the
individual start/stop characteristics on the tape and syncronize correctly between each block on tape, a
67
single tone is written between blocks. This signal is used to syncronize both position and speed of the
tape. Varying lengths of tone are used at the beginning and between the data blocks of the tape. By
writing about ten seconds of the tone on each opening of a file, the PET automatically corrects for normal
leader. Individual tape blocks are separated by shorter tone durations.
FILE HEADERS
An important assumption underlying the tape system design was that the user would often want to
record more than one file of data on a tape. In order to facilitate this and to allow for proper label
checking, the first physical data recorded on tape for any operation is a file header. This file header looks
exactly the same as the normal data block, except that the first character of every block on tape contains
an identification character which enables the operating system to differentiate between program blocks,
data blocks, file headers and end of tape headers.
The PET allows for up to 128 characters of a file name to be stored in the file header. This is the name
which is searched for and matched on in the various OPEN/CLOSE options.
TAPE BUFFERS
Another basic premise in the design of the tape operating system was that the user would want to write
tape independently of what is occurring on tape at a given moment. This is accomplished in the operating
system by permanently assigning a block of memory as a data buffer for each cassette. A 192 character
buffer is located at decimal address 634 for cassette #1, followed by a 192 character buffer at decimal
address 826 for cassette #2. The tape file header is written into the buffer first and then written on tape.
Data files are accumulated in the tape buffer until 192 characters are exceeded, then the contents are
either written on tape for write, or if the program is reading tape, the next block of data is read into the
buffer. Tape file headers and all data blocks are, therefore, 192 characters long.
Tape buffers are not used in the case of program files, since these are written onto the tape directly from
the memory in which the program resides. In order to accomodate the variable memory location, the file
header for a program file contains the beginning and ending address for the program. The full program is
written onto tape in the usual form of two consecutive redundant blocks.
MULTIPLE FILES
In order to have multiple files on tape, the user needs the ability to add files to a tape and also know when
a tape is at its end. lt is, therefore, important that the operating system give an “end of file” and “end of
tape” indication.
Inthe case of data files, an “end of file” marker is appended after the last data character. This is available
to the user in a status word on reading; the ‘’end of file” marker is automatically inserted when a write file
IS closed.
In the case of program files, because all data is always contained in a single block, the end of the block
signifies the end of the program.
To signify that the end of the tape has been reached, a special separate file header is written. When this
is encountered during a search for files, the PET automatically stops the tape and indicates “file not
found” to the user. Atypical multiple file tape could contain first a data file, then a program file, followed
by an “end of tape” header as illustrated in the example of figure 7.14.
10 seconds of leader
192 character file header block
2 seconds of leader
192 character data block
Data file
2 seconds of leader
EN
Last block of this file
10 seconds of leader
192 character file header block
| 2 seconds of leader
Program file
10 byte
Y
32K byte
program block
2 seconds of leader
optional 197 characters
endof tape header
Figure 7.14. An example of multiple file structure.
LOGICAL FILE VO OPERATIONS: GENERAL
These operations can be subdivided into three steps:
a) Open the file - tell the PET everything it needs to know about the file.
b) Read data from, or write data to the logical files.
c) Close the file - allow the PET to clear up the device and terminate the active file.
These steps are discussed in detail on the following pages.
OPENING FILES
In order to tell BASIC about the file you want to operate on, it is first necessary to open the file. This is
done by the following statement:
OPEN logical file, device, secondary address, file name
More specifically, the statement consists of the command OPEN followed by the logical file number,
then the device number to which the file is assigned, then the secondary address data (if any)
communicated during the interaction of BASIC with the file, and last, the name of the physical file (if any).
69
This statement, or expression, is interpreted by BASIC, and could, therefore, use computed logical file
numbers, device numbers or secondary address data. This capability is extremely useful when handling
multiple file devices such as discs.
The keyword OPEN and the logical file numbers are essential in order to open a file; that is address a
device in preparation for a “read” (INPUT $ or a “write” (PRINT #).
The device number is optional; if not entered, the default value “1” will be used.
A filename is optional, though preferred, for the tape units: however, a name would be essential for a disc
storage unit.
EXAMPLES OF OPEN STATEMENTS
The statement OPEN 1,2,1 is interpreted by the operating system as saying:
Parameter
(LF) Logical file #1 has been opened
\ (D) Logical file #1 has been assigned to tape unit#2
(SA) Tape unit #2 has been instructed to write on tape
{FN} A file name has not been assigned to the tape record
Similarly, OPEN 3 is interpreted as saying: (F)
Parameter
(LF) Logical file 43 has been opened
(D) Logical file#3 has been assigned to tape unit 41 (default “1”
(SA) Tape unit #1 has been instructed to read from tape (default “0”
(FN) No file name referred to
If a PET printer is assigned “4” as a device number, then OPEN 12,41 is interpreted as:
Parameter
(LF) Logical file #12 has been opened
(D) Logical file #12 has been assigned to device #4
(SA) Printer has been instructed to print under format statement control
(FN) File name not applicable
Note: The PET has a special system with OPEN far tape files. The opening of the tape is automatic, but
the tape header may not always be written at the beginning of the tape buffer; this implies that the
operating system does not always correctly initialize the buffer point. For consistent and reliable
operation of the tape file header, the following statements should be used:
1) For tape #1: РОКЕ 243,122
POKE 244,2
2) For tape #2: POKE 243,58
POKE 244,3
These should be written prior to each OPEN for write.
LOAD
À special case of the OPEN command is the LOAD of a named file: a LOAD is done with the following statement:
LOAD name, device number
The operating system automatically generates an OPEN using the appropriate secondary addresses for
“load”. This OPEN causes the loading device to search for a program name. After the program is found, it is
automatically read from the device and loaded into memory starting at an address specified in the file
header. Most reading errors on the first pass through that program are automatically fixed on the second pass.
Ât the end of the load cycle, a checksum error, of the total program is made. If a checksum error, or if an
70
uncoverable read error occurred, the operating system automatically prints ?LOAD ERROR and stops
the load program.
If the program load was from direct mode, the clear function is performed at the end of the load, thereby
initializing all variables.
If the LOAD is called from a program, then the PET treats this LOAD as an overlay. The new program is
loaded into the space used by the previous program, but the values of ali of the variables are maintained
from the previous program. This allows for one program to call another and pass parameters to the called
programs.
The only restriction on this is that all the called programs must fit in the same, or less space as the first program.
Because BASIC totally replaces the current program, it is not directly possible to have a single main
program and several subroutine overlays, however, by including the main program with each overlay, the
same effect is obtained with some loss of speed.
The combination of the use of named files and overlays allows the writing of very large structured
programs of appreciable complexity.
VERIFY
This very instruction is a special case of LOAD. It should be used after every program SAVE.
The command causes BASIC to go through all the steps of a program LOAD, with the exception that the
data does not get loaded into memory, but, instead, gets compared with memory. If either first or second
pass errors occur, the PET will type out ?VERIFY ERROR which means that the program should be saved
again before it is lost. On VERIFY, the status word has the following meanings
Code Meaning
4 Short block
8 Long block
16 Checksum error on tape
32 Checksum ERROR on tape
SAVE
SAVE also performs an automatic open and close. The SAVE is specified by the statement:
SAVE name, device number
If the physical device is one of the two tape units, the operating system automatically initiates a tape
header and opens a tape file with the appropriate name. The file header is written with the beginning and
ending address.
if the device is an 1EEE-488 device, a special open message is sent indicating that the PET is sending a
program file.
The program is then written directly from its memory locations to the tape or the IEEE-488 bus.
If the SAVE is on tape, a checksum is computed and also saved and then the whole program is written
again to give the redundant recording. At the end of the program, the tape is automatically stopped and
positioned for the next gata.
IEEE-488 SPECIAL FEATURES
In the tape, the program beginning and ending address are stored in and retrieved from the tape file header.
In order to more efficiently use the !EEE-488 data, the starting address of the program is sent as the first
two bytes of data on a SAVE and retrieved from those positions on a LOAD.
ni
IEEE-488 OPEN CONSIDERATIONS
If the OPEN command selects a device which has a value of 4 or more, the operating system assumes
that the device is an IEEE-488 device.
If the OPEN does not specify a file name, then nothing is communicated on the IEEE-488 bus. However, if
a file name is specified, the operating system sends a listen attention sequence to the device number
specified in the OPEN along with a secondary address which is the OR of hexadecimal “Fo” and the
secondary address specified in the OPEN statement.
Commodore-supplied peripherals, such as the floppy disc storage system, will use this secondary
address and also the file name, which is then transmitted to the listening device in order to transfer data
later to the open file.
TAPE FILE OPERATION MODES
tape files can be opened for two distinct purposes:
a) In order to write from the PET onto tape.
b) In order to read from tape to the PET.
OPEN FOR WRITE ON TAPE FROM PET
The flow diagram of Figure 7.15 outlines the PET-user interaction and PET function when opening a file
for write on tape. The initial block shows that there are two ways of opening the file:
a) OPEN for write-data tape.
b) SAVE-write a program tape.
Note that if the tape file is opened directly from the keyboard, then the message WRITING NAME is
displayed. If the file is opened under program control, and the PLAY and RECORD buttons are depressed
previously, then no message appears on the screen. In this manner, any display material placed there by
the current program is not disturbed.
OPEN FOR READ FROM PET TO TAPE
The flow diagram of Figure 7.16 outlines the PET-user interaction and PET function when opening a file
for reading on tape. The initial block shows that there are two ways of opening the file:
a) OPEN for read data tape.
5) LOAD program into memory.
Note that if the file is opened directly, that is from the keyboard, then the messages PRESS PLAY,
SEARCHING FOR NAME and FOUND NAME are displayed. If LOAD was used, then the BASIC variables
of the loaded program are initialized.
If the file is opened under program control and provided that the PLAY button had been pressed
previously, no messages appear on the video screen in order to disturb material displayed by the current
program. Initialization of the BASIC variables does not occur.
72
OPEN for
Write or SAVE
Name —» Header
in Tape Buffer
Message:
PRESS PLAY
AND RECORD
and RECORD
Buttons Down?
Yes
Wait for
i Switch
Closute
Program
Direct
or Program
Message:
WRITING NAME
Header Goes
to Tape
Figure 7.15. OPEN for write from PET: PRINT#,CMD or SAVE.
= operating system takes over.
73
OPEN for
Read or LOAD
Message: No No “Play”
PRESS PLAY Button Down
+ Yes
Wait for N
Switch Closure
Message: Direct Direct
SEARCHING TE” or Program
FOR NAME Operation
—
Read 192
Character Block
Header Found
Direct Direct
or Program
Ope ration
Message:
FOUND NAME
Program
? File Not
Found Error
Correct
Mame?
Direct Direct
or Program
Operation
Message:
LOADING
NAME
—
Read m
Full Program -
to Memory
Program
Program
Direct
or Program
Operation
Direct
Initialize
BASIC
Variables
Figure 7.16. OPEN for read to PET: INPUT# or LOAD
OP = Operating system takes over. B = BASIC takes over.
74
DATA INPUT: GENERAL
The use of the word “input” in this context implies input of data to the PET from any device.
INPUT#-String and Variable Input
INPUT# is the command used to initiate data transfer from WHO devices to the operating system. The
statement format is:
INPUT# logical number file, A,A$,B,B§ etc.
Where A,AS,B, and B$ are numerical and string variables to be inputted (read) from the selected logical
file to the operating system one character at a time.
Because the rules for the BASIC interpreter apply to these input statements, all carriage returns,
commas, terminate fields, nuils, preceeding blanks (except in strings), and other control characters
are automatically deleted.
It is not always possible to mix both numeric and alphabetic data on the VO device. if a numeric field is
specified, only numeric data in the standard form expected by BASIC is accepted, otherwise a ?BAD
DATA ERROR meesage is displayed.
If there is any ambiguity about the data coming in, the user should input only to strings and then use the
various string manipulation commands to process the data into the appropriate variables.
Example of Input Statement
If Xrepresents a series of 50 numbers stored on a tape file named VECTOR and we assume that the PLAY
bution has just been depressed on the tape unit#1. Then the following program will read the 50 numbers
one at a time and display them on the video screen.
10 OPEN 1,1,0“VECTOR" Open logical file #1. Assign file to cassette 1. Open tape for
“read”. Look for physical file named VECTOR.
20 FOR K = 1 to 50 Read 50 numbers at one time from cassette 1.
30 INPUTH1,X
40 PRINT X Display numbers on video screen
50 NEXT K
60 CLOSE 1 When 50 numbers have been read, close logical file #1.
GET #CHARACTER TRANSFERS
Not all devices transfer data in a form which is accceptable directly to BASIC. There is a series of binary
data and combinations which BASIC ignores and although many EEE devices do correctly respond
with data formats which are acceptable to basic, not all do.
In addition, in some cases, it is desirable for the programmer to have immediate access to characters as
they are transfered to the system. GET- fetches from the |EEE-488, or tape device, a single character at a
time, putting a character in a field specified following the GET#. THE FORM IS:
GET# logical file, field
TAPE INPUT
When reading from the tape file, the data comes to the user 10 independent. Each time BASIC starts on
INPUT# or GET from a logical device which was opened for read on tape 1 or 2, a special subroutine is
called, which initiates tape input.
As each character is requested from BASIC, it is fetched from the appropriate tape buffer. When the
buffer is empty, the tape input routine suspends the user program and reads the data biock from tape
into the buffer and then transfers the next character to BASIC. If a read error occurs, it is noted in the
75
status word.
When the end of file mark is encountered in the buffer, the end of file position of the status word is set on
and carriage returns are forced automatically out until the command is finished.
At the end of a command, BASIC calls another routine which reinitializes the input to be the keyboard and
tells the end of file operation that a command is complete.
IEEE-488 DEVICE INPUT SEQUENCES
All INPUT# or GET# commands go through the same sequence. When the command is first encountered,
the IEEE-488 input initiation routine is called, which sends a talk attention sequence to the device and
secondary address which was specified for that logical file in the OPEN sequence. At the end of the
attention sequence, the PET establishes itself in a listener mode and attempts to wait for a DAV signal
indicating a single character has been received. If the DAV is received within 65 milliseconds, that
character is handed to BASIC and/or to the other program calling the [EEE-488 routine. Each time the
IEEE-488 routine is called, it will go through the same sequence of getting a single character while
waiting for a time out to occur. If the bus does not respond in 65 milliseconds, then the IEEE-488 routine
will automatically terminate the sequence: giving a read error in the status word to indicate that it has
terminated the sequence.
If during the course of reading the character, the |IEEE-488 routine senses an EOI line, it will indicate the
end of information in the status word and will continue to return carriage returns, until the command it
has been currently operating under has been terminated. At the end of the command, BASIC calis a
termination subroutine which reinitializes the device to the keyboard and sends an untalk to the
IEEE-488 bus, thereby, freeing the bus for the next command.
INPUT BUFFER LIMITATIONS
Although data is transferred from the operating system one character at a time, in order to edit, BASIC
accumulates these characters into an 80 column input buffer. This buffer must be terminated by a
carriage return.
On the PET, should more than 80 characters be read, the operating system will malfunction, as the
operating system variables are overwritten. The PET can be made to function again by switching the line
supply off and on.
This constraint must be kept in mind when using tape and disc file systems.
This means that carriage returns must be written on tapes, discs, or other HO devices in such a way that
not more than 80 characters per field are written without being separated by carriage returns.
If an I/O device sends more than 80 characters, the GET command can be used to build your own string
without running into the buffer limitation.
DATA OUTPUT: GENERAL
The use of the words “print” and “write” refers to data output from the PET io any device.
PRINT#
The command PRINT# must be followed by a logical file number, and then a comma to separate the data
that would follow PRINT:
PRINT# logical file number, data
Data is transferred a single character at a time to the physical device correlated with the logical file
specified in the relevant OPEN statement. Many of the file delimiters such as commas are automatically
76
deleted by BASIC; although this does not greatly effect the printing, it should be remembered that when
reading back from tape or another I/O device that file delimiters must be forced. This forcing can be done
by inserting a CHR$(44) or *“,” between fields or by only printing single fields in each PRINT# statement
which will force carriage returns between fields. Example:
instead of writing
PRINT#LF A;B3,C$
which will be sent as
АВ$С$
with no delimiters:
PRINTAHLF, A;CHAS(44)BS;:CHR3(44);C3
or:
PRINTELF,A ¡BS;.:CS
which will output: (Note: CR means carriage return)
A,B$,CS,CR
or:
PRINT#LF,À
PRINT#LF,B$
PRINT#LF,G$
which will output:
A CR B$ CR C$ CR
Because BASIC always formats outputs to any devices as though it were outputting to the screen,
PRINT#LF.A.B has several skip characters between the values of A and B, while A;B does not have any
extra skips.
An exception to this rule is the tape where the first skip on output is supressed.
Note: Although both the INPUT# AND PRINT# commands operate in virtually the same way as their
equivalent INPUT and PRINT statements do in BASIC, the abbreviated command ? which can be used in
place of PRINT, does not apply to PRINTK. ?8 and PRINT# are recognized and reduced to two different
token characters when processed by BASIC. ?# will look like PRINT# when listed but gives ?5YNTAX
ERROR when an attempt is made to execute it.
Examples of the PRINT# Statement
This program will print the series of numbers 1.2.3...50, one at a time on a PET printer.
100PEN 5,4,0 Open logical file 45. Assign logical file *5 to device #4 (PET
printer) in normal print mode corresponding to secondary
address “O”.
20 FOR K= i to 50 Print the series of 50 numbers on printer.
30 PRINT#5,K
40 NEXT K
50 CLOSE 5 Close logical file 45.
To write the above series of numbers on a cassette in tape unit #2, only the OPEN line would have to be
modified, if the same logical file numbers were chosen:
100PEN 5,2,1 Open logical file #5. Assign logical #5 to device #2 (tape unit
#2) with a write without “end of tape” designation
corresponding to secondary address ‘4’.
77
20 FOR K=1 to 50 Fecord the series of 50 numbers on tape.
30 PRINT#5,K
40 NEXT K
50 CLOSE 5 Close logical file #5.
In the above cassette example, the data would be accumuiated in a 192 character buffer one character at
a time. When the capacity of the buffer is exceeded, then data entry is suspended, the tape started, and
the buffer contents written to tape. The buffer is initialized to accept up to 192 characters and then the
program is allowed to proceed.
Note: Not ail tape units currently operate with the same START/STOP characteristic as defined for the
original tape operating system. In order to obtain reliable operation of the tape recorders, the 192
characters of the buffer should be monitored by the program. Prior to transferring 192 characters, the
programmer should turn on the appropriate cassette motor and then wait for at least .1 second
before transferring the last character.
There are several ways to accomplish this. The simplest is to just POKE 59411,53 for cassette #71 and
РОКЕ 59456,207 for cassette #2 after every PRINT statement, this keeps the motor on ail of the time and
eliminates the problem.
On the other hand, if your programs have time consuming functions like human input, sorting, or other
long program run times, you should not run the motor alí the time, but obtain the delay either putting a
delay loop before each print, or turning the motor off with a POKE 59411,61 for cassette #1 ora
PORKE 59456,223 for cassette #2 before the tong function and turning it back on after it.
IEEE-488 BUS QUTPUT
The PRINT# command causes BASIC to call an output subroutine which initializes an IEEE-488 device for
output. The first step in the command is that the PET reassigns its normal output from the screen device
to the physical device that was chosen for the logical file in the open routine. A listen command is sent on
the IEEE bus to the physical device and a secondary addressd specified for that logical file in the OPEN.
BASIC then hands one character at a time to another subroutine which proceeds to transfer that
character over the bus with the PET acting as a talker and all addressed devices responding listeners.
When BASIC has finished the PRINT#, another subroutine in the operating system is called and the PET
sends an “untisten” command to the entire bus and restores the primary address to the screen. This frees
the whole bus for the next operation.
This unlisten sequence also sends an EO] signal on the bus, along with the last character sent from
BASIC. To accomplish this, each character is stored in a buffer prior to transmission by the IEEE routines
and the previous character is sent.
CMD COMMAND
Normally, each print command deals only with one logical device and at the end of the command entire
bus is unlistened. In some instances, it.is advisable to have more than one device on the bus; in order to
facilitate this, the special command CMD is provided. CMD is virtually identical to PRINT#, except that at
the end of the data transfer, the unlisten routine is not called, thereby leaving the device on the bus as
a listener.
The operating system continues to treat the last device to be commanded by the CMD as the primary
output device for BASIC. PRINT or LIST commands are then directed to this primary device, rather than to
the video screen. More specifically, the CMD of the printer device, followed by LIST, results in hard copy
78
printed listing, instead of a video screen listing. However, since neither the CMD nor LIST command
terminate bus operation for the device, a PRINT# is required to terminate a CMD command.
Examples of a CMD Command
To list:
OPEN 3,4 where 4 is the printer device number
CMD 3
LIST will list just the same as the screen, except on the printer.
to print and write a disc at the same time:
*CMD 3 where logical file 3 is open to the printer.
PRINT#15,A,B,C where 15 is the floppy disc logical file number
(previously opened).
will result in A,B, and C being stored on the floppy but also being displayed on the printer.
To monitor an input device:
**CMD 3 turn on printer
INPUT#15,A,B,C read from floppy
This will result in the data from the floppy being transferred to A, B and C but also being printed as they
are being transferred.
CLOSING FILES
Any logical files which have been opened during a program shoutd preferably be closed when no longer
required, and in the case of tape or disc files, must be closed before the program ends. The tollowing
should be kept in mind: |
а) If the total number of logical files currently exceeds ten, then loss of
PET operation will result.
b) If a logical file assigned to a tape unit is not closed, no “end of file”
mark will be recorded at the end of the physical tape file. If this tape is then
ioaded into memory, the PET will have no way of knowing the file has
ended, and if the unwanted and erroneous data is present from a
previous recording, it will also be read into memory.
EXAMPLE OF A CLOSE STATEMENT
To close any file, the following simple statement is sufficient:
CLOSE logical file
if it is required to close logica! file number 5, then this becomes:
| CLOSE 5
TAPE FILE CLOSURE
If a file had been opened on the tape, there are two operations that occur: an “end of file” marker is
recorded in the next data character, then the tape buffer is forced out onto the cassette.
If during OPEN the “end of tape” option was chosen, an “end of tape file” header block is also
forced out on the cassette.
“Must be given each time because PRINT# unlistens the bus.
**Nead not be given each time, more code can be included between instructions.
79
IEEE-488 NAMED DEVICE CLOSURE
For IEEE-4888 devices, which were opened with file names, a special listener command sequence,
with the special secondary address of thehexadecimal EO OR'ed with the secondary address from the
OPEN is sent. This allows devices such as disc files to be closed by the peripheral controller.
ERROR DETECTION: GENERAL
The basic concept of the PET operating system is that the user will be aliowed to operate in a free-form
format; reading and writing on tapes, discs, and printers, in the manner that is most comfortable for him.
Because I/O is totally free-form, it is most important that the operating system should have means of
informing the user when transmission errors or end of data conditions occur.
STATUS WORDS
In order to facilitate INPUT/OUTPUT operation error detection, the PET uses the “status word” concept in
which a byte in memory is manipulated by each of the 1/0 operations for the PET, and can be sampled by
the programmer at any time by calling the function ST. Each bit in the staus word has a general meaning
for all operations and a specific meaning for the individual 1/0 device.
Table 7.17 shows the errors as a function of the ST word value for the tape cassette units. IEEE read/write
operations, tape verify and load operations.
ST ST Tape
Bit Numeric Cassette ¡EEE AM Verify
Position Value + Load
0 1 Time out
on write
1 2 : Time out
on read
2 4 Short block Short block
3 8 Long block Long block
4 16 Unrecoverable Any
read error mismatch
5 32 Checksum Checksum
error error
6 64 End of file EOf line
-128 End of tape Device not End of
present tape
Table 7.17. Status Word (ST) values correlated with
tape cassette, unit and IEEE bus read/write errors.
IEEE DEVICE ERRORS
There are basically three errors that can occur during an IEEE-488 transfer. First, the entire bus does not
respond to an attention sequence. If this occurs, the |EEE-488 subroutine sets the DEVICE NOT PRESENT
bit (7 or -128). The PET also terminates the current program with ?DEVICE NOT PRESENT ERROR. If the
bus responds correctly to the attention, but when the PET goes to write the first character to the bus and
the physical device is not present as indicated by having NRFD or NDAC low, the PET, again, gives a
device not present indication.
The second error occurs during the process of transferring data to the device. The bus does not respond
80
in the appropriate times andlor if it ceases to respond by means of bringing NRFD and NDAC both high, a
write error indication is given in bit 0.
The third error occurs when during read on an |EEE-488, the IEEE device has r not sent DAV in less than 65
milliseconds: bit 1 of the status word is then set. Whenever the EOI line is encountered, the subroutine
sets the bit 6 on in the status word and continues to force carriage returns.
TAPE UNIT ERRORS
The cassette only checks data on read. The errors deleted are:
1) SHORT BLOCK (4).When reading a block from tape, a spacer tone was
encountered before the expected number of bytes has been read from that
block. Possible cause: attempting to read a short load file as a data record.
2) LONG BLOCK (8).When reading a block from tape, a spacer tone was not
encountered after the expected number of bytes had been read from that
block. Possible cause: reading a long load file as data.
3) UNRECOVERABLE READ ERROR (16).Cause: more than 31 errors on the
first block of redundant blocks-or an error that could not be corrected
because it occured in the same place in both blocks.
4) CHECKSUM ERROR (32).After a LOAD or reading of data, a checksum is
computed over the bytes in RAM and compared to a byte received from the
input device. If they do not match, this bit is set.
5) END OF FILE (64).This bit is set when the end of data file mark is
encountered in a tape record.
6) END OF TAPE (-128).An EOT record was read.
EXAMPLES OF ST USE
As you can see, there is no status that the PET detects for the writing of tapes, nor errors detected for
printing to and reading from the screen. There is an error on writing data out to the IEEE-488 and there is
also a series of errors detected on inputting from the |EEE-488 or from tape.
The normal programming technique is to follow INPUT# or a GET# by either a test or storage of the value .
of status. As this is only a single byte of memory and the status changes on each new I/O command, the
status is very transient.
100 INPUT#2,A
110 INPUT#5,B
120 IF ST=0 THEN 200
This code only checks the result of the transfer of data from logical file 5. The results of reading logical
file 2 is forever lost. Similarly:
100 INPUT#2,A
110 PRINT A
120 IF ST=0 THEN 200
In this case, the ST reflects the print status, rather than the results of reading #2.
A correct way to use ST is the folllowing:
100 INPUT#2,A,B,C
110 IF ST=0 THEN 200 process normally
120 IF ST =64 THEN 300 end of data processed with no errors
81
130 IF ST =2 THEN 400 time out with no errors
Each error can now be processed with the following:
140 IF ST AND mask THEN Mask represents the bit being tested
POLLING TECHNIQUES
One technique to poll siow IEEE-488 devices such as sampling devices, which take many minutes to
respond, is to use the INPUT# from the device; then if the status indicates time out, process other
routines or loop on the INPUT # until no error occurs. If there are no errors, the correct data has been
finally read and one can process that data information.
By using this sampling technique, a whole series of slow devices can be serviced, along with running a
foreground program by use of the real time clock (TI, TI$) and the INPUTMtimeout error sequence, to
occassionally poll devices.
DEFAULT PARAMETERS
Parameter Default Value Default Operation
Device + D=1 Cassette +1 selected
Secondary SA=0 On tape files open for read
address On (EEE-488 devices, no
secondary address is sent.
Table 7.18. Default values.
Equivalent
Statement (Default) Operation
Parameter Values
OPEN 1 OPEN 1,10 Open logical file #1 for cassette #1 read
no file name
OPEN 1,2 OPEN 2,0 Cpen logical file #1 for cassette #2 read
no file name
OPEN 1,2,1 OPEN#1,2,1 Open logical file #1 for cassette #2 write
no file name
OPEN 1,21, OPEN#1,2.1. Open logical file #1 for cassette 42 write
“DAT “DAT” file named “DAT”
Table 7.19. Example of default parameters.
INTRODUCTION TO THE IEEE-488 BUS |
This bus consists of 16 signal lines that are divided functionally into three groups, those are:
a) The data transmission bus
2) The contro! bus
3) The management bus
Furthermore, the IEEE bus can support three classes of device:
a) Talkers: at any given moment, only one device is permitted to transmit
data to the data bus.
b) Listeners: as many devices as required may receive data
simultaneously from the bus.
c) Controller: the PET is the only controller allowed on the IEEE bus.
82
BUS/DEVICE CONTROL
The line-pin connections for the 12 position, 24 contact edge card connector, emanate from the PET main
assembly board (see Table 7-19). For further information, please refer to Figure 7.2
Certain physical limitations should be noted when connecting devices to the IEEE bus:
a) The maximum advisable bus extension from the PET is 20 meters.
b) The maximum interdevice spacing is 5 meters.
c} The maximum number of devices is 15.
PET PET
Contact Bus IEEE Contact Label
Identifi- Label Identifi- Description
cation cation
1 DATA DI01 1 Data INFUT/OUTPUT LINE #1
2 DIO? 2 Data INPUT/OUTPUT LINE #2
3 D103 3 Data INFUT/OUTPUT LINE #3
4 D104 4 Data INPUT/OUTPUT LINE #4
5 MANAGER EOI 5 End or identify
6 TRANSFER | DAV 6 Data valid
7 NRFD 7 Not ready. tor data
a NDAC 8 Data not accepted
g MANAGER | IFC 9 Interface clear
Same as PET reset
10 SRG 10 Service request
11 ATN 11 Attention
17 SHIELD 12 Chassis ground and IEEE
cable shield
A DATA DIOS 13 Data INPUT/OUTPUT LINE #5
B DIOG 14 Data INPUT/OUTPUT LINE #6
С D107 15 Data INPUT/OUTPUT LINE #7
D 0198 16 Data INPUT/OUTPUT LINE #8
E MANAGER | REN 17 Remote enable (REN) always
ground in the PET
F GROUNDS | GNDE 18 DAY ground
H GND7 19 NFRD ground
J ENDS 20 NDAC ground
к GSNDS 21 IFC ground
E GND1G 22 SRA ground
М GND 23 ATN around
М LOGIC GND 24 Data ground (0101-8)
\
Table 7.20. IEEE bus group, label and contact identification number.
THE DATA BUS
This bus is comprised of 8 bi-directional lines that transmit the active low data signals D101-8. The
slowest device in use on the bus at a given time controls the rate of data transfer; the mode of transfer is
one byte at a time, bit parallel.
Peripheral addresses and control information are also transmitted on the data bus. They are
differentiated from data by ATN (true) during their transfer.
The most significant bit (MSB) is on line D 108.
For an explanation of signal abbreviations such as D1-08, see Figure 7.23.
Data Transmission Modes
All possible bit patterns are valid on the data bus when sending data to devices.
THE TRANSFER BUS
This three line bus controls the transfer of data over the data bus. The signals transmitted are used in
83
the handshake procedure outlined in 7-21.
These signals are:
a) NAFD Not ready for data
b) NDAC Data not accepted
c) DAV Data valid
Note that the talker originates the DAV signal and the listeners the NFRD and NDAC signals.
See Table 7-23 for detailed description of signals.
The Handshake Procedure
When a talker transmits a data byte to one or more listeners, this control procedure is used in order to
ensure that the operation is successful.
The essential function of the handshake is to ensure;
a) All listeners are ready to accept data.
b) That there is valid data on the data bus.
c) That the data has been accepted by all listeners.
The transfer of data occurs at a rate determined by the slowest active device on the bus: this aliows the
interconnection of devices which handle data at different speeds.
The sequence of events that occur during the transfer of a data byte from the talker to the listeners is
shown in the flow diagram of figure 7-21.
Not Greater than 64 msec.
| Ready for Data
МАРО |! Not Ready for Data
{Listener} (1) i“ |
| |
Е!
|!
DAV | Data Not Valid
Talker] Data Valid
(3) | (6)
— — ata Accepted
NDAC | ‚a Data Not (Being)
{Listener) ı (5) (7) Accepted
|
|
| Bit Value = @
Data Bus | — High Impedance
Signals (2) | Bit Value = 1
|
|
/
Data Signal
Sattling Interval
Figure 7.21. Transfer bus handshake sequence.
84
COMMENTS TALKER LISTENER COMMENTS
Data on Not Ready
Data Bus DAV — High ai > Low for Data
Not Valid ow Data Not
Accepted
NRFD and Error Ready to
NDAC High Accept Data
No
New Data on
Listeners
Ready No
All
NRFD — High Listeners
are Ready
for Data
Data i Is the
a ;
Valid DAV — Low Data Valid
Data Byte
Accepted
i Los] J
NDAC - Data
High ~~ —| NDAC-— High | Accepted
No
Yes
Data Not . DAV
Valid DAV — High | — — — *— — High
No
Yes
End Data Not
NDAC — Low Accepted
Figure 7.22. Sequence of events during a data byte transfer from the talker to the
listners. Broken lines indicate the testing of transfer bus signal logic levels.
85
Figure 7-22 shows the relative timing of transfer bus signals during a typical handshake; the bracketed
numbers in the following sequence refer to the changes in signal logic levels in the Figure:
1} NRFD goes high (false) indicating that all listeners are ready for the
next byte of data.
2) The talker puts the next data byte on the data bus and allows the data
signals to settle. This could happen before, after or during (1).
3) The talker tests NFRD, when it is found to be too high, the talker makes
DAY low (true)to inform listeners that the bus data is now valid.
4) As soon as a single listener detects that DAV is iow, that listener sets
NRFD low; data is now accepted by all the individual listeners at their own
rate, each of whom release NDAC as they accept the data.
5) NDAC goes high (false) when the slowest of the listeners have accepted
the data.
6) The talker sets DAY high {false} indicating that the bus signals are now
invalid.
7) The listeners note that DAV has gone high and sets NDAC
low (true) completing the handshake. When each listener has processed
the data, they release NFRD. This terminates the sequence for the first
data transfer. The sequence will repeat again, beginning at (a), until all
required data transfers have been completed.
PET/IEEE Bus Timing Constraints
The following limitations should be noted in order to avoid a loss of data:
a) When PET is a listener, it expects DAV to go low within 64 milliseconds
after it has set NFRD high.
b) When PET is atalker, it expects NDAC to go high within 64 millisecond
after it has set NRFD high.
If these limitations are exceeded, the PET ceases to transfer and sets the appropriate status word (ST).
See Table 7-24,
THE MANAGEMENT BUS
This group of five signal lines controls the state of the data bus and defines its signals; these can be
concerned with data, addresses, or control information (device commands).
The five management signals are:
a) ATN Attention Assigns devices to act as listeners
or talkers.
b) EOI End ог Indicates that the last data byte is
identify being transferred.
с} IFC Interface Initializes the data bus. Talkers and
clear listeners set idle. Same signal as
reset in the PET.
d) SRQ Service Device tells controller that service is
request required. Not implemented in BASIC
but available in PET.
e) REN Remote Permanently tied to ground in the
PET.
enable
86
IEEE SIGNALS AND DEFINITIONS
The 16 transmission lines of the !EEE-488 bus are each assigned a specific signal. Table 7-23 gives the
bus group, name, abbreviation and functional description for each of these signals.
LOGIC LEVEL CONVENTION
The “true” or logical “1"is low with common collector type outputs. This allows any device to hold the
bus in the “true” or logical “1” state.
Bus Signal
Group Abbrev.
Name
Functional
Description
Manager ATN
Attention
The PET (controller) sets this
signal low while It Is sending
commands on the data bus,
When ATN is tow, only periph-
eral addresses and contro!
messages are on the data bus,
When ATN is high, only pre-
veiously assigned devices can
transfer data.
Transfer DAV
Data Valid
When DAV is low, this signi-
fies that data 1s valid on
data bus.
Manager EOI
End or
Identify
When the last byte of data is
being transferred, the talker
has the option of setting EOI
low. The PET always sets EOI
low while the last data byte is
being transferred from the
PET.
Manager IFC
Interface
Clear
The PET sends its internal re-
set signal as 1FC {ow {true} to
initialize all devices to the idle
state. When PET 15 switched
on or reset, IFC goes law for
about 100 milliseconds.
Transfer NDAC
Data Not
Accepted
This signal 15 held low (true)
by the listener white reading.
When the data byte has been
read, the listener sets NDAC
high. This signals the talker
that data has been accepted.
Transfer NRFD
Not Ready
for Data
When NRFD is low (true),
one or mare listeners are not
ready for the next byte of
data. When all devices are
ready, NRFD goes high.
Manager SRO
Service
Request
Not implemented in BASIC,
but available to the PET user.
Manager REN
Remote
Enable
REN is held low by the bus
controller, The PET has a pin
grounded that keeps REN
permanently low.
Table 7.23. |EEE-488 bus signal.
Table continued on next page,
87
Table 7.23. IEEE-488 hus signal (continued).
Bus Signal Functional
Group Abbrev. Name Description
Data DI01-8 Data input/ | These signals represent the bits
output lines | of information on the data bus.
1 through 8 | When a DIO signal is low, it
represents 1 and when high G.
General GND Ground Ground connections: There
are six control and manage-
ment signal ground returns,
one data signal ground return
and one chassis shield ground
lead,
STATUS WORD (ST)
ST is a BASIC variable which can be used to check the outcome of INPUT/OUTPUT operations. ST can
have certain values over the range -128 to 127. Table 7-24 shows the status code that appertains to the
IEEE-488 bus.
ST Error Explanation
1 Time The IEE£ device has not responded within the 65
out on milliseconds time out inverval.
listener
2 Time The IEEE device has not provided an active "data
out an valid” signal {DAV low} within the 65 millisecond
talker time out interval,
64 End or EOI has gone low ftrue), on the last byte of data
identify being transferred on IEEE bus, Note that al! devices
(EOI do not generate an EOI signal. Consult relevant
instrument manual.
-128 Device Device did not respond when addressed; this gen-
not erates an error message and the operating system
present returns the PET to BASIC command level.
/
Table 7.24. ST status code for IEEE-488 bus.
IEEE-488 REGISTER ADDRESSES
Table 7-24 shows the IEEE-488 hardware addresses for the PET. An attempt to control the bus by means
of the PEEK and POKE commands will fail, if the time out intervals for the 488 devices are exceeded.
Hex Decimal
Address Address Bits IEEE Mode
E820 50424 0-7 DIO?-8 Input
E822 59426 0-7 | DI018 | Output
E821 59425 3 NDAC Output
E823 59427 3 DAV Input
7 SRG
E810 59408 6 EQ Input
F840 59456 0 NDAC Input
1 NRFD Output
2 ATN Output
6 NAFD Input
7 DAV Output
Table 7.25, IEEE-488 hardware addresses and signal information.
88
(FNYl NLY HLIM O3AI323H ONV LN3S)
‘uoljelsado jo poy puewiwon,, 10} sjuawubisse apo '97'7 Igel
SIGOWN VI Ya Y ANYANO9 H108 NI dasn SHILOVHVYHD T1V (SG HONOYHL Z NWNT0D) 13S8NS 3SNIA ($)
ONYWWOI AHVONOIIS SIHINDIH ©
(DOS)
апоно ¿00 =9 "1010 = '9 ©
ANVIWNOO 39VSSIW 39V4Y3LNI = 9SM (7) SALON
AHYONOJ3S © (90d) dNOYD ONVIWWOD AHVIIHd
| |
/ \/
(DVI) (Ov) (99N) (DOV)
апоно dNOHD dNOHD dNOH9D
ssaugav SS3H0OV ONVWWOI ONVWWOI
XIV N3LSIT TWSYZAINA O3SS3HOGV
| |
f \ ® \/
130 0 — oc TIN / sn IS SI 1 TI TI TA о
~ u _ N < Sy 0S pl ott jl o
| = | = | “ [ и = - s9 HO El | loft ii
|» > | = \ = 7 = > > Si 44 a о Го ii
WS ALS LAS] [5] a 5] 15] 253 iA т (ji fo ji
_ 2 2 © > 2 7 | > > . ans 37 ol o|t|0|1
| om A m | SA = = 6 = { PJ OdS| w3 | 1921| 1H 6 : {o|o |!
| = x = Ч = X = H = 8 = ) $ 3ds| NYO | 139 | Ss 8 о ро | с |!
ERE О 6 Sm м > © L © 813 139 / L|tj1|0
z A < } O | A © 5 O 9 © E NAS ADV 9 о |+ |1 |0
| о о о о ,
3 n 3 9 T Nn т 3 т 9 m % } Ndd{ XVN [© Idd | ON3 § в | ого
© vi etre ral alal v | a s Jwal wal Das] 103 b o|o|i jo
| © s [ol oI Tl ss Tl ol Tl el T= £00 X13 € в |: Го |0
H 1 Н 9 e 8 Z р 220 X1S Z ооо
b е D \ L i 4011? 190 | 119 | HOS L EL TOO O
d d © 0 dS 310 INN 0 о |0 | 0 |0
1 MOY + | + | т 11
ё 9 5 v E ¢ 9 | NWN109 | La | Za | £a | va ‘©
L 0 L 0 L 0 L 0 sq €}
OSW| 1 |9SA! L |DSW} O [DSW| O |9SWI 1 |9sw| ı |9sw| A | DSW | O 99
L | L | 0 0 of D 0 La
Chapter 8.- USE OF THE PET FOR MACHINE LANGUAGE PROGRAMMING
Machine language programs execute much faster than do BASIC programs which have to be interpreted
tirst then executed. On PET, machine language can be used to communicate with the user port, play
music, or write the screen memory with blinding speed. If you have never programmed the 6502
microprocessor, it is probably adviseable that you get hold of the two books mentioned in Chapter 1
before you proceed with this chapter.
In PET there are two ways to create a machine language program in memory and execute it. The first is by
BASIC. As previously discussed, there are two BASIC commands, PEEK and POKE which give equivalent
machine language operation relative to controlling input/output instructions or influencing or sampling
individual memory locations. The second method to program is by a monitor.
A monitor essentially has only three functions: examine and deposit bytes in memory, and branch to
execute code. These functions are available as PEEK, POKE and SYS in BASIC. The chief limitation of
BASIC is that all bytes must be converted to decimal before use. A monitor available for PET allows one
to work entirely in hexadecimal notation but the 6502 does not care what base you work in because all it
sees is binary. The PET monitor does have some other useful features which we will discuss later.
MACHINE LANGUAGE PROGRAMMING FROM BASIC
It is possible to build into a string of memory locations by means of a POKE command, a set of
instructions which are a machine language subroutine which is usable by an individual program. To
implement these subroutines, there are four basic considerations: (1) what the subroutine is supposed to
do, (2) how to implement it, {3) where to put the program, and (4) how to communicate the subroutine from
BASIC. The decision on what the program is to do and how to implement it is left to the programmer and
the programming manual (6502).
To locate the code, you must decide whether you have a small program that is to be used only temporaril
or whether it is a program you want to have operational throughput the entire time the BASIC program is
operating in the machine. |
To understand how best to keep the program in memory, we should review the memory map of the PET.
All the zero page programs address are consumed by the operating system and are usually being
changed throughout the programs. Between the normal use of stack and tape I/O corrections, all of page
1 is used. Page 2 has a series of variables which are again used throughout the program. However,
memory locations 634 through 1023 are used for the first and second cassette buffers. If a program is not
using tape 1/0, then these areas will not be touched by BASIC.
M only the first cassette is used, the second cassette buffer is available. If both the cassettes are used
during the program, or if this area is not enough into which the user is to write some code, then the space
between the end of the BASIC program and where BASIC stores its variables is the space that is available
to the programmer. At any time during execution of the program, a PEEK into location 124 and 125
indicates the beginning location of the BASIC variables. Working back down these with a small safety
margin which is proportional to the amount of data space that is used in the program, is a memory area
which is not affected by BASIC during execution. These are memory locations which are counted by the
FRE statement. Once programs have been written and debugged, this space is as useful as are the
cassette locations.
The final problem is how to get the program into the memory location. Although by use of the machine
language monitor, machine language programs are loadable, this involves a two-step process for the
user. First, the machine language program must be loaded, followed by the loading of the BASIC
91
program. Obviously, this technique does not work at all, if the program is to be loaded into the cassette
buffers. Another technique is to assemble the program, into the BASIC program, by means of putting the
machine language program into data statements. The data statements can then be read at the beginning
of the execution of the BASIC program and POKEd into the appropriate memory locations.
SYS COMMAND
When it is necessary to transfer control to the machine language program, there are two ways to do it.
The preferred approach is the SYS command which transfers control totally from BASIC until control is
| returned by means of a routine from subroutine instruction. It can be used to transfer control to any other
program such as a machine language monitor or future languages when they become available. If the
following code is encountered
10 SYS (634)
at Line 10, BASIC will hand control of the computer to the program located at 634. The general format
for the SYS command is
SYS (start address)
The start address can be a computed value, in either case, it must result in a positive number not greater
than 65535. NOTE: Execution of machine language code, removes almost all protection that the ROMs
has built into it to allow the BASIC interpreter to continue functioning without regard to user error. As
soon as you transfer contro! from BASIC to your own program, any mistakes which occur in your program
may cause the machine to cease to function. In order to help solve this type of problem, you should use
the machine language monitor to develop anything other than the most trivial amount of code. In any
case, when control of system is lost, it can be regained by repowering the system on.
in order to return from the SYS command, the last instruction in the program, which is executed, should
be a RTS instruction. BASIC will then start interpreting the next statement after the SYS command. In
order to pass the variables of data back and forth between the user program and BASIC using the SYS
command, data has to be POKEd into temporarily undisturbed memory locations during the execution of
the BASIC routine. The results of the SYS operation would have to be PEEKed back into the program that
follows the call to SYS.
USR FUNCTION
There are some programs, particularly mathematical ones, in which it is easier to pass parameters
to/from BASIC using the USR function and to get the results directly processed in BASIC. USR is
specified with a parameter. BASIC evaluates the expression for its parameter and {eaves the results of
the evaluation in a floating accumulator which BASIC uses for all of its functions. It is noted that if no
parameter is passed, the floating accumulator is not initializeable by the user or by any other techniques
as it is used by BASIC in a variety of ways prior to executing the USR function.
+
USR calis a routine, which executes a machine language program. A result in the floating accumulator to
be analyzed by the BASIC expression. Because USR is a function, it is possible to include the function
called user as part of a BASIC instruction as in: IF USA (A) = 1, THEN etc. In this case the parameter A
will be passed to the USR function in the floating accumulator. The resulting floating accumulator, when
the user returns to BASIC, would be compared to 1 and the logical function would be executed.
The SYS command is more useful for transferring control for machine language processing in which
variables are not being acted on. USR is more useful when one is trying to implement a new BASIC
command. This is an important consideration in using USR. USR uses preassigned variable locations:
locations 1 and 2. These locations must be initialized with the hexadecimal value of the starting address
in which the machine language program is stored. This can be done anywhere throughout the program
92
with a POKE of the decimal equivalent of the lower address to location 2 and POKE of the high order ad-
dress in location 2. Example:
10POKE 1,122
20POKE 2,2
30 FF USR (A)=1 THEN etc.
USEFUL BASIC SUBROUTINES -
There are a series of subroutines in BASIC which can allow the machine language program to evaluate
values in the floating accumulator. These functions are called jump to Subroutines instruction (JSR)to
the address,
The parameter specified in the USR functon is evaluated, converted to a binary floating point equivalent
with signs, exponent, and mantissa, and placed in a series of 6 bytes which we will call the floating
accumulator
$B0 sign and exponent
$B1 mantissa MSB
$82 mantissa
$B3 mantissa
$B4 mantissa
$B5 mantissa LSB
$B6 sign of mantissa
The exponent is computed such that the mantissa 0 = 1 x 1. It is stored as a signed 8 hit binary + $80.
Negative exponents are not stored 2's complement. Maximum exponent is 10%, Minimum exponent is
10 3 which is stored as $00. A zero exponent is used to flag the number as zero.
Exponent Approximate Value
FF 10%
A2 10
TF 101
02 10 #
00 10 *
Since the exponent is really a power of 2, it should best be described as the number of left shifts
(EXP>$80) or right shifts (EXP< = $80) to be performed on the normalized mantissa to create the actual
binary representation of the value.
Since the mantissa is always normalized, the high order bit of the most significant byte is always set.
This guarantees always at least 40 bits precision which is roughly equivalent to 8 significant digits plus a
few bits for rounding. If a number has a value of zero, itmay not always have zero bytes in the mantissa.
The only true flag for a zero number is the exponent. See Figure 8.1 for example exponents and
mantissa's.
If the mantissa is positive, then the sign byte is zero -- $00. A negative mantissa causes this byte to be
-1--8FF.
93
EXAMPLE FLOATING POINT NUMBERS
1E38 FF 96 76 99 52 00
4E10 Ad 95 02 F9 00 00
2E10 A3 95 02 F9 00 00
1E10 A? 95 02 F9 00 00
1 81 80 00 00 00 00
5 80 80 00 00 00 00
25 fF 80 00 00 00 00
1E-4 73 D1 B7 59 59 00
1E-37 06 88 je 14 14 00
1E-38 02 D9 C7 EE EE 00
1E-39 00 AQ 00 00 00 00
0 00 00 00 00 00
— 1 81 80 00 00 00 FF
— 10 84 AO 00 00 00 FF
es
A
æ
E
<
= < e с xs =
© 0 a © a Ne
= — — = — O
9 E E = = с
> © © © „m
Ф Е E E E AN
Figure 8.1.Exampie floating point numbers.
Actual floating point BASIC variables are stored in 5 bytes, rather than 6 bytes as is the floating
accumulator. Upon examination, one will note that the most significant byte of the mantissa is always
set. If we always assure the number will be in this format, we can use that bit to indicate the sign of the
mantissa -- thus freeing the byte used for sign. The sixth byte is used in the fioating accumulator to
simplify operations when shifting the mantissa.
The contents of the floating accumulator may be converted to a double byte integer by calling a
subroutine FLPINT which is located at SDOA7. The most significant byte of the integer is returned in $B3
and the least significant byte in $B4.
e.g
10 A = USR(2)
contents of FAC after USR call
82 80 00 00 00 00
JSR FLPINT
contents of FAC after conversion
82 00 00 00 02 00 00
integer value
It is not necessary to return a vaiue in the FAC after a USR call. The value of USR can be left as just the
current contents of FAC. An integer can be converted back to floating by loading the most significant
byte into index register Y then calling INTFLP at $D278.
94
eg LDA MSB
LDY LSB
JSR INTFLP
USEABLE I/O ROUTINES
Read a line, pass a character
$FFCF return char in 0
no other regs changed
Print a character on screen
$FFD2 Char in A
no regs changed
Test for stop key
$FFE1 returns =, <>
only A changed
Get a character from keyboard
$FFE4
char or if none then null (00)
SUMMARY
There are two ways to communicate from BASIC to machine language program. The simplest of these is
SYS in which the control of the computer is turned over to the machine language program located at the
address specified in thesys command. For implementing your own functions in BASIC, there is a function
called USR which when memory locations of 1 and 2 are properly initialized to point in a machine
language program, evaluate a parameter specified in the user function and pass the results back to the
program using the floating accumulator. A series of useful subroutines, available in BASIC, can allow
either the USR or SYS function to perform operations on the floating accumulator without the user
running any program other than the calling routines.
In all cases, the use of the machine language program is only for the more sophisticated BASIC user.
The protection of the ROM fail safe coding is lost. Machine language programs should only be used when
BASIC is neither fast enough nor the function which is desired is implemented.
MACHINE LANGUAGE MONITOR
TIM is the Terminal Interface Monitor program for MOS Technology's 65XX microprocessors. It has been
expanded and adapted to function on the Commodore PET. PET uses a cassette tape version of this
monitor. Execution is transfered from the PET BASIC interpreter to TIM by the SYS command.
To LOAD your MONITOR, take the cassette with MONITOR and put it in the tape unit with the MONITOR
side up. Then type: LOAD “MONITOR” and, when ready, RUN.
Commands typed on the PET keyboard can direct TIM to start executing a program, display or modify
registers and memory locations, and load or save binary data. On modifying memory, TIM performs
automatic read after write verification to insure that addressed memory exists, is R/IW type, and is
responding correctly.
TIM also provides several subroutines which may be called by user programs. These inciude reading and
writing characters on the video display, typing a byte in hexadecimal and typing a CRLF sequence.
95
TIM COMMANDS
M display memory
R display register
G begin execution
X exit to BASIC
L load
S save
EXAMPLES
M DISPLAY MEMORY
.M CO00,C010
: CO00 1D C7 48 C6 35 CC EF C7
.: C008 C5 CA DF CA 70 CF 23 CB
.: CO10 96 C8 96 C7 74 G7 1F CB
In a Display Memory command, the start and ending addresses must be completely specified as 4 digit
hex numbers. To modify a memory location, move the cursor up in the display, type the correction and
press RETURN to enter the change. When you move the cursor to a line to do a screen edit, and press
RETURN, the colon tells the monitor that you are re-entering data.
R DISPLAY REGISTERS
.R PC SR AC XR YR SP
.. CB ED D0 20 C0 F5
Registers are saved and restored upon each entry or exit from TIM. They may be modified or preloaded as
in the display memory example above. The semicolon tells the monitor you are modifying registers.
G BEGIN EXECUTION
G C388
The GO command may have an optional address for the target. If none is specified, the PC from the R
command is taken as the target.
X EXIT TO BASIC
X
READY
Causes a warm start of BASIC. In a warm start memory is not altered in any way and BASIC resumes
operation the way it was before a monitor was made.
L LOAD
L 0% MONITOR
PRESS PLAY ON TAPE #1
OK
FOUND MONITOR
LOADING
No defaults are allowed on a LOAD command. The device number and the file name must be completely
specified. Operating system prompts for operator intervention are the same as for BASIC. Memory
addresses are loaded as specified in the file header which is set up by the SAVE command. Machine
language subroutines may be loaded from BASIC but care must be taken not to use BASIC variables as
the variable pointer is set to the last byte loaded +1.
5 SAVE
.5 01,MONITOR,0400 ,076D
PRESS PLAY ON TAPE#1
OK
96
WRITING MONITOR
Likewise, no defaults on the SAVE command. Any start and ending address may be specified.
To cancel a command either type RETURN or press STOP to cancel a Dispiay Memory, LOAD or SAVE.
e
INTERRUPT AND BREAKPOINT ACTION |
BRK is a software interrupt instruction which causes the CPU to interrupt execution, save PC and P
registers on the stack and then branch through a vector at locations $021B and $021C. TIM initializes this
vector to point at itself on entry by CALL. Unless the user modifies this vector, TIM will gain control when
a BRK instruction is executed, print B* indicating entry via breakpoint (instead of C* entry via call) and
the registers (as in the R command), and wait for user commands. Note that after a BRK which vectors to
TIM, the user's PC points to the byte following the BRK: however, users who choose to handle BRK
instructions themselves should note that BRK acts as a two-byte instruction, leaving the PC (on return
via RTbfwo bytes past the BRK instruction.
IRQ is vectored normally in PET to an ISR which updates the clock and scans the keyboard every 60th of a
second. If the vector is altered and the machine language subroutine does not restore it, a power-on reset
must be performed.
NM! is not provided for in the PET. The processor line corresponding to this interrupt is permanently
pulled UP.
REST vectors to a cold-start of BASIC. Memory is cleared. Reload and re-enter TIM via SYS command.
TIM MONITORS CALLS AND SPECIAL LOCATIONS
JSR WRT $FFD2 type a character
JSR RDT $FFCF input a character '
JSR GET $FFE4 Get a character _
JSR CRLF $04F2 type a CR —
JSR SPACE $063A type a space
JSR WROB $0613 type a byte
JSR RDOB $065E read a byte
JSR HEXIT $0685 Ascii to hex in A
MEMORY USAGE
| $0A-$22 zero page
$400-$76A absolute RAM
$23-S5A are zero page locations in the BASIC input buffer which may be used when BASIC is not using
these locations. The second cassette buffer $33A-$3FF is a well protected location if that device is not
used. Other memory locations may be used with considerable risk, depending upon which piece of PET
software wants to use it also.
MONITOR CHECKOUT PROCEDURE
1) Power up your PET normally into BASIC command mode. Insert the cassette containing a monitor and
use the SHIFT-RUN sequence to initiate a program load. You should see a display something like:
C* PC SRAC XR YR SP
; +29 00 88 89 FE
Exact values may vary, although the first and last values should be as shown.
2) The display of registers is the standard entry display message. it consists of C* to identify entry by
call, followed by the CPU register contents: program counter, processor status, accumulator, X index,
Y index, and stack pointer. Note that all TIM inputs and outputs are in base 16 which is referred to as
97
hexadecimal, or just hex. In hexadecimal, the digits are 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F. After printing the
CPU registers, TIM is ready to receive commands from you. TIM indicates this “ready” status by typing
the prompting character “.” on a new line.
3) The user's CPU register may also be displayed with the R command. Type an R and press RETURN.
The monitor should respond as above, but without the asterisk.
4) Displayed values may be monitored by screen edit and re-entry of the line via return. Remember to type
spaces to delimit fields and type 4 digit hex numbers for addresses and 2 digits for byte contents.
5) Memory may be displayed and modified using the M command. Type:
.M 0100 0107
You will see a display something like:
0 1 3 4 5 6 7
0100 20 00 30 30 30 30 30
Now use the screen edit to modify in place on the screen, type RETURN and display again.
6) Use M and ; to enter the following test program called CHSET because it prints the ASCII 64 character
set on the terminal. The M command is used to display memory locations on the PET screen and it is then
possible to use the screen edit on each line and type RETURN to alter memory.
* = $33A
CRLF = $4F2
WRT =$FFD2
33A 20 F2 04; CHSET JSR CRLF
33D A2 20 LDX #$20
33F 8A LOOP TXA
340 20 D2 FF JSR WRT
343 ES INX
344 EQ 60 CPX — 4560
346 DO F7 BNE LOOP
348 00 BRK
349 4C 3A 03 JMP CHSET
M 033A,034B
: O33A 20 F2 04 A2 20 BA 20 D2
: 0342 FF E8 EC 60 DO F7 00 4C
: 034A ЗА 03
7) CHSET was assembled to reside in the 2nd cassette buffer. Type:
. G 033A
to execute the program.
The listing should look like this:
l"#H$%'(",-./0123456789:;=?@ ABCDEFG
HIJKLMNOPQRSTUYWXYZI[!]
B" PCE SR AAC XR YR SP
.; 0349 3B5F 6OBDFE
Note the address contained in the PC. It is possible to type G execute the program again without
specifying an address.
8) Next we will link CHSET with BASIC. First replace the BRK instruction in location $348 with an RTS
(return subroutine} (change $348 from 00 to 60).
9) Change the USR function vector in locations 1 and 2 to point at the subroutine $33A.
98
.: 0000 4C 3A 03
10) Exit from the monitor and re-enter BASIC.
‚X
READY
11) Prove that the linkage is established by using both SYS and USR.
А = USR(0)
SYS (3'256 + 3*16 + 10) (Enter these as direct commands.)
PET MONITOR 13.1
LINE & LOC
8882 8668
8983 BEBA
Bas 068688
tete BOU
Bap? 0680
Bega 00680
82889 vana
8818 0880
8011 8088
adi? ages
5813 8888
9014 9880
9815 0968660
#016 806082
6617 0888
8%:8 0069080
9819 8600
8020 eves
8021 29909
BO22 8988
0823 DEBA
B824 B8éb
9925 $888)
8926 AUN
9027? B88F
8828 0811
6829 9813
B830 DEIS
BASI 081?
8932 819
6933 GUIA
8034 0018
86135 UIC
Baie 861)
88027 QUÍE
8038 961F
8039 0628
8848 68821
B841 0622
88472 6623
8843 9623
B844 0623
8843 8813
Bodie 8460
B647 84/9
8847 04901
8647 0462
8847 0483
8047 0404
8847 28405
Bé48 8485
B848 848€
#845 48D
8540 048E
dE
eb
#4
8h
ев
SE
28
86
ев
CODE
31
88
E OE + EF =
PAGE BUG!
LINE
iCOPYRIGHY 1978 BY
¡COMMODORE INTERNATIONAL LIMITED
VARTAB=#7C
TATPT=$CÉ
NCHIS=&
UPLISS91
ROT=$FFCF
URI=$FFD?
CERINY:=5021:05
UARM=SC38B
FR=5F 1
FNLEN=$Et
FNALNR=$F9
STAL=3E7
STRH=$F §
ЕВ! = $Е5
ЕЁ Н- $ Еб
¡CLERO PAGE MONITOR RESERYE ARER
»= SEA
YRAF жа * + 1 ; ABDRESS WRAP-AROUND FLAG
DIFF 2 =#+2
URKF жа я + } ¿BREAK FLAG
PREYC #==#+#1
ACME #=#+;2
TKPH Se = # +2
TMF2 *= +2
TKHFd #=#+2
THP A #5 à +27
PEL #33 +]
PCH ж= +]
FLGS же + }
ACL FE ES
XK went]
YR sand]
SP ж= + +]
SAVY TERY!
THPC umd]
ТИРЕ? +=x+i
RCNT=TMPL
LCHT=THPL 2
ISTR pux+ié ¡FILEID BUFFER
*=$400
ENTER COMPILED BASIC TEXT
.BYT 0, 13,4. 1H, 6.158
- .BYT ‘(1839)’, В, &, 8
100
PET
LIRE A LOC
MONITOR 13.1
8849 B48F
8858 048F
8051 046
8052 848
8853 84BF
8854 84B8F
8955 8048F
8036 9411
Bas? 9414
B58 60416
8809 8413
B68 B41IEB
886! 0413
8862 B41F
88065 8421
BES 80423
8865 842%
- 8066 0427
B67 94?3
#8868 428
B69 842€
68780 8427}
997: B42E
B872 8438
8673 9431
8074 0433
8875 0434
8076 0436
Pav? 8437
0678 8439
8879 0438
BORN 8430
988} B43E
8982 043F
6085 8441
8884 9443
8805 0444
BABE 0446
BBR? 8447
8889 #444
#889 044€
8898 B44E
BASI 8451
0832 8453
8893 8455
8094 94535
BASS 0453
Basé 0455
6857 9457
agse 8459
8899 8458
Bigs 0450
Gigi BASF
Bing 8462
B153 0464
CODE
AS 27
gD ip 82
AS #4
gn 1C 82
49% Er
85 70
AS 68
85 ?C
AS 43
85 21
ba 12
A9 42
BS 21-
ES
4 8
68
85 1E
68 7
85 1)
68
85 IC
62
85 В
68
69 FF
85 19
6%
69 FF
BS 1A
BA
86 IF
58
28 F2 84
A6 21
89 ZA
26 22 06
A9 52
BS ED
DA 728
AS 98
85
ES 8A
28 F2 94
A9 ZE
28 Ne FF
* = = = w= A
LINE
¡CALL E
+
i BRE RK
y
CALLE
BRKE
B3
BO
START
PAGE B@a2
NYRY POINT
STACK
ENTRY POINT
STALK CONTRINS
LIA
STR
LDR
STA
LDA
STA
LBA
STA
LDA
STA
BHE
LDA
STA
CLD
LSR
PLA
5TH
PLA
STA
PLA
STA
PLA
STA
PLA
ADE
STA
PLA
ABC
STR
15%
STE
CL:
JSR
LDZ
LDA
JER
LBA
STA
BRE
LDA
STA
STA
STA
JSR
LDR
JSR
#{BRKE
CBIRY
#>2RKE
CRINY+!
#>E0#
YARTREB+!
*<EDM
YARTAB
“E
THPC
83
#'E
ТИРЕ
R
YR
XR
ACE
FLGS
NSFF
РС!
NEFF
PCH
SP
CRLF
ТИРЕ
# "+
URTYO
e
BREF
sa
10
TRYPT
RRKF
WRAP
CRLF
E
MRT
101
CONTRINS Y, Хх. В, $, РС
Ys KA E, PL
i INIT BRK YEC.
; SET A=C TO INDICRIE
¿CALL ENTRY, THEN JMP TO E3
;SET A=B8 FOR BRERK
¿SET CY FOR PC CORRECTION
¡SAYE Y
¿RAND €
i AND ACCUMULATOR
; AND FLAGS
¡CY SET TO PC-1 FOR BREAK
¡SAYE ORIGINAL SP
¿CLEAR INTS
; SET % EQUAL TO 8 OR C
¡SET FER R DISPLAY TE
PERMIT IMMEDIATE
ALTER FOLLOWING
BREAKPOINT
; SET BREAK FLAG
;NERT COMMAND FROM USER
¡CLEAR BREAK FLAG
i CLEAR ABR GRAP-ARGUND FLAG
¿TYPE A PROMPTIRG *
PET MONITOR 13.1... ...PAGE 80863
LINE
8164
8185
6156
Bray
Biss
BIBI
6118
8111
8112
Bi13
8114
8115
8116
B1i?
8118
8119
6128
Bici
#122
9123
B124
8125
8126
6i27
BizZB
8129
8136
Bilt
8132
8133
0134
elas
81368
8137
8138
8149
8146
Bi4i
B142
8143
8144
8145
8146
8147
8148
8149
8158
9151
8152
8153
B154
Biss
#156
8157
Bios
LUC
8467
8969
8463
8469
6468
6462
ed6t
0471
8474
8477
847
47h
947
847E
8488
8482
8484
8487
8489
8488
848D
848F
8492
8493
8496
8497
8498
8493
8498
8497
EE
B4h3
B4R4
0486
84438
é4an
64AC
B4hE
B4 AF
8481
0452
0484
0486
8483
84BR
6488
8488
asea
8488
8488
8488
84BD
04BF
84?
84C4
Ro
ЕВ
Fa
ЕВ
De
20
28
Ze
Co
Ре
C3
FB
R2
BD
Da
AS
85
86
ВР
48
8D
48
68
CA
16
A9
28
4C
38
AS
ES
BT
65
ES
A8
65
68
AS
85
AD
85
68
85
RO
28
Bi
28
CODE
28
B2
64
83
86
3A
37
98
2E
F3
24
ES
97
62
aF
28
GE
28
8A
12
ÈS
3F
22
Sr
13
11
#B
14
12
ER
if
19
12
IR
21
he
3A
ti
13
46
Gé
sé
во
85
BO
FF
84
B6
Be
LINE
srta
sr
58
5i
se
ERROPR
DEMP
PUTP
7
;HISPLAY MEM SUBR.
LDX
CPX
BER
CPR
ВНЕ
JSR
JSR
JER
CHP
BEA
tne
BEG
ОХ
СИР
BNE
LDA
STA
STx
LDA
PHA
LDA
PHA
RTS
DEX
BPL
LDA
JER
JAP
SEC
LBA
sec
STa
LDR
SEC
Tay
Ока
RTS
LDR
STA
LBA
STA
RTS
SAYX
#2
318
$3
511
SPACE
SPAEZ
RDUC
4‘.
STi
ET
511
#HCMDS-1
CMDS. X
52
SAY XL
PREVC
SAVX
RDRH, X
ADRL,%
51
‚В Ко.
WRT
START
FMP2
TMP8
RIFF
TAPZ2+1
THPB +1
DIFF
TAPA
PEL
TMPB+i
PCH
i IF CURRENT CHD IS R OR M,
SET CURSOR TO
ALTER POSITION
; POSITION UNDER PE DATA
;READ COMMAND, CHARRCTER
IS RETURHED IN A
¿IGNORE PROMPTING *."
; IGRORE SPACES
i LOOKUP COMMAND
; SÂYE PREYICUS COMMAND
i SAVE CURRENT COMMAND INDEX
¡LOOP FOR ALL COMMANDS
OPERATOR ERROR RESTRRT
i JMP START (MRT RETURNS Cyz=
; THF2-THPB DOUBLE SUBTRACT
; RETURN HIGH ORDER PART 18 Y
;UR LO FOUR EQU TEST
¿MOYE TMPO TO PER, PCL
SET AR=HUMBER
;OF MEMORY BYTES DISPLAYED.
; TMPR=ADR OF MEM DISPLAYED
DM
DH:
STA
LDY
JSR
LDA
JSR
TMPC
#9
SPACE
CTMPO), $
WROB
102
¡UR N BYTES
: < THPA)=ADR
¿CHAR IN Я, CY=8 IF SP
i SPRCE
; STORE BYTE
; TEST FOR YALID WRITE (RANK?
;ERRGR: CLEAR JSR ABR IN STA
; GO INC THMP® ADR
; SET TO ACCESS REGS
» BY 1
; LOW BYTE
‚HIGH BYTE
¡POINTER HAS WRAPPEDT
AROUNE. SET FLAG
PET MONITOR 13.%1..... PAGE 88804
LINE $ LOC CODE LINE
B159 84C7 20 F7 84 JSR INETMP
8168 B4CR C6 21 DEC TMPE
Bisl @4CC DA Fi BNE DMI
Bis? 84CE 869 RTS
8153 84CF ;
81564 84CF iREAD AND STORE BYTE.
Bi63 @4CF ¡NO STORE IF SPACE OR RENT = 8.
8166 B4CF ;
8167 84CF 28 SE 86 BYTE JSR KDEB
8163 #402 90 BD BLE Bs
8159 84D4 AZ MU LBX #6
9178 6406 Bi 11 STR (TAPA, X>
Bi71 8479 El 11 CHP CTNPO, XD
8172 @4DAa FO ES BEU ВУЗ
6i73 0@84DC 68 PLA
Bi74 B84BD 68 PLA
8175 940Е 4C 98 84 JAP ERROPR
B176 94£1 28 Е? B84 BY3 JER INCTHP
8177 @4E4 C6 21 DEC RCHT
8178 B4E6 680 RTS
8179 B4E7 #93 1B SETR LOA #FLGS
8188 B4E9 85 11 SFA TNPE
0131 B4EB 43 dE LBA #8
B182 @4ED BS 12 STA THPO+1
0183 O4EF AS BS LDA #5
B184 84Fi 6B RTS
8185 84F2 AS BD CRLF LDR #%D
B186 84F4 456 D2 FF JAP NRT
B137 B4F7 ;
8188 B4F7 ; INCREMENT CTHPO, THPO+:
9183 B4F7 j
8198 B4F7 Ee 11 INCTMP INC TMPB
B19: @4F3 16 66 BRE SETWR
8132 B4FB E6 12 INC THMPB+1
Bi%3 A4+FD DO 82 ВНЕ SETUR
8194 Q4FF Ee BA IHC WRAP
#155 850i ;
0156 858i EN SETUR RTS
103
PET MONITOR 13.1..... PAGE 9885
LINE
8198
8139
9206
8281
B2R2
8283
B294
8285
B2u6
6287
8298
8289
8218
8211
0212
#213
8214
#215
8216
8217
8218
8215
8220
B22i
4 LOC
8582
6383
6584
8585
8586
8587
6588
0509
8584
8585
gsec
esep
B5BE
858F
95190
83it
8512
8513
8514
0515
8516
8517
8518
0519
3h
3B
32
4D
47
58
4C
33
85
85
85
85
85
as
86
56
Ci
Bi
гс
SE
D7
Fi
SE
SE
CODE
LINE
CMDS
AÏRH
ADRL
104
PET MONITOR 13.1..... PRGE 0896
LINE # LOC
B223 8318
8224 852)
8225 852)
8226 032F
B227 9531
8228 8334
8229 6537
8236 8538
9231 SIT
8232 BS3r
B233 8542
B234 0543
8235 0545
6236 0547
8237 834A
8238 854C
6233 854E
8248 8551
9241 89354
B242 9557
0243 8334
B244 B55)
8245 955F
8246 9562
B247 0565
8248 8367
8249 0568
8258 036)
8251 $570
8252 20572
8253 8575
B254 0577
8255 057A
8236 057C
8257 957F
0258 8588
8259 8582
8260 8584
8261 8587
8262 80582
8253 8580
8264 O58E
8265 8590
8266 9593
8267 6555
B268 2533
8269 8594
8279 B5IC
8271 959F
B272 0582
82/3 B85AS
8274 05A7
8275 08058
8276 B5AC
8277
BAF
a mm a a amg
28
AS
DO
28
28
a
A?
8D
28
ES
ES
ре
28
Az
#9
28
20
28
28
28
FO
28
28
78
28
28
28
38
28
#9
89
3B
28
Ca
Ве
29
208
2a
FO
E
ba
28
98
2d
A2
A3
28
ce
za
#3
ca
Fa
+C
4C
CODE
5
aD
as
F2
37
37
80
if
12
13
F5
F2
2E
3B
22
37
ва
Е?
BB
4D
90
4F
48
3F
9e
4F
3D
3F
BO
sa
86
D2
ES
7F
D2
26
28
an
iC
a3
17
F2
2E
ЗА
22
37
64
88
BB
DB
57
38
84
86
Gé
85
FF
B4
86
fe
Be
84
8d
Bo
#6
dé
Be
06
E
87
FF
FF
F3
84
84
be
Bo
Be
G4
B4
B4
LIME
RE GK
J
DSPLYR
1
Be
PSPLYM
COLA
COLH2
DEP!
BEQS!
ERRSI
. BYTE * PC
LBA
BRE
JSR
JSR
JER
LD%
LDA
JSR
INX
CPR
BNE
JSR
LDX
LDA
JSR
JSR
JER
JSR
JER
BEA
JSR
JSR
ВСС
JER
JSR
JSR
ВСС
JSR
LOY
LIA
BMI
JER
ТНУ
ВНЕ
AND
JSR
JSR
BES
LDX
BNE
JSR
BEC
JSR
LDX
LDA
JSR
JSR
JER
LOA
JER
BEN
JAP
JAF
BREF
Di
ERLF
SPAC2
SPACE
18
REGK, %
BRT
#15
D2
CRLF
1”.
#" ;
HRTWO
SPRL?
WRPC
SETR
DM
BENSI
RDOC
ROCA
ERRS 1
T2T2
RPOC
RDOR
ERRS
T2TZ2
#9
HDR. Y
CULHZ
BRT
COLH
#$°F
#RT
TSTP
BERS
WREP
BEES
DCLHP
BE&S1
ERLF
#°.
$
IRTUO
SFACZ
WRIA
#3
DN
DSPi
START
ERROPR
105
SR AC XR YR SP”
i IF ROT BREAK ENTRY,
i CRLF, SPRCEZ
¡WRITE PC
; USE DN SUBR
; READ START ADR
ERR IF MO SA
; SA TU TAPE
i SKIP DELIMITER
¿READ END ABR
;ERR IF NO EA
:SÁ TO TMPO,
ER TQ TMPZ
; TEST FOR STOP KEY
; IF ABRS WURAP-ARCUND,
STOP
¡STOP IF ER LESS THAN SR
¿BEGIN NEW OUTPUT LINE
; DISPLAY 8,
INCR TRPE
PET MONITOR 13.1..... PAGE 8897
LINE
8278
8279
B288
8231
8282
8283
8284
8285
8286
8287
8288
8289
8238
8291
8252
8253
8294
8295
8296
8297
B298
8293
8380
ELE
B3Be
8383
0394
8385
8366
8387
8359
8389
8318
8311
9312
8313
8314
8315
8316
8317
a3i3
8319
83:28
832i
8322
8323
6324
8325
8326
8327
8328
8329
0330
8331
8332
* LOC
85B2
8582
8582
e382
8585
8589
8584
8580
aca
esca
85C2
asc?
8502
8305
B3C8
BSCH
ate
85CE
8501
8554
8516
8528
8508
82525
95DF
@SEi
83E3
8556
05ES
85EB
BSED
BSEE
a5ráa
OSFi
95F3
B5F 4
85F¢
0SF?
UI3FA
BSFB
BSF D
OSFE
8648
0601
05804
Вей 4
8604
0684
8586
8688
860K
BEBC
860)
asar
Bé12
28
28
50
20
29
DB
28
ce
98
43
85
28
28
DB
FÜ
28
Es
Fo
cg
ne
2e
sa
28
Ab
ЗА
RO
48
85
48
AS
48
65
RE
À 4
48
Ab
IA
4C
û 2
ne
#2
BS
48
BT
28
68
COBE
JE 86
4Р 86
83
B2 84
E7 84
Ba
SE B6
ar #86
ES
68
21
39 Bt
CF Ad
Рё
D4
CF FF
gl
sc
20
EC
4F 86
as
Be 84
1F
LA
€
iB
1c
iD
LE
LF
88 LI
Bi
B2
#9
18
ti
13 Be
LINE
7
ALTER REGISTERS
AL TR
AL 2
‚ALTER
ALTH
A4
AS
AS
60
Gi
EXIT
¿WRITE
WROGA
УКРЕ
URDAI
JSR
JSR
BCC
JER
JSR
ВНЕ
MEMORY
JER
JSR
ВЕС
LDR
STA
JSR
JSR
BNE
BEC
JSR
СИР
BEQ
CHP
BNE
JER
ВСС
JSR
LDH
TAS
LDA
PRA
LDA
PHA
LDA
PHA
LDA
LDX
LEY
RTI
LD¥
TRS
JEEP
ADR
LOS
BNE
L DAX
LDA
PHR
LDA
JSR
PLA
RDOEB
RIGA
AL2
FUTP
SETR
A 4
RDOB
RBOA
ERRSI
#9
RENT
RDOC
BYTE
ÁS
BERS
ROT
505
61
$524
ERRSI
RICA
G 1
PUTP
SP
РСН
PCL
FLGS
ACE
RE
TR
Sp
WARM
¡SKIP 2 SPACES
;CYs8 IF SP
; SPREE
; ALTER PC
iSET TG ALTER R°S
READ ADR AND DATA
:5KIP 2 SPACES
¿READ MEM ALTER ADE
;CY=0, IF SPACE, ERR
¿SET CHT = 8
‚IF CR, EXIT
¿1F NOT SPACE, ERE
iORIG OR NEW SP VALUE TO SP
¿EXIT TO BASIC WARM START
FROM TMPB STORES
#i
WRAL
+5
TMP8-1, К
THPB. X
WRB
106
PET MONITOR 13.%f..... PAGE 8608
LINE # LOC
8333 0613
8324 0613
a335 0613
8336 9613
8737 6613
08328 0613
— B339 061%
8340 28615
8341 8616
8342 0617
8343 0619
R244 861B
9345 @615
8346 6615
8347 W6iF
9348 9672
8349 8622
8350 8622
8351, 0622
8352 0623
8353 0624
8354 0627
. 8355 9628
8356 B62b
8357 062€
8359 BEE
0359 6638
8360 6632
836i 90634
8362 8636
8363 9637
8364 B63A
8365 80630
8366 MEF
B357 0641
8368 0643
0369 80644
8378 8545
2371 0648
8372 8649
8373 86548
8374 BES
0375 MEE
0376 B64F
8377 BE4F
8378 Be4r
8379 064F
8388 0064F
8791 864F
8382 8652
8383 8654
0784 0656
8385 6659
8386 @6S5B
6387 8655
48
4 À
4A
4h
4A
28
AR
68
29
2a
48
8h
20
68
4C
18
£9
63
98
63
69
68
ca
AY
Gl
A2
85
48
859
35
68
95
CA
DB
68
2a
98
85
28
39
85
60
CIDE
28
er
ZB
D2
#2
86
РЭ
82
86
3A
3A
28
D2
az
19
12
18
12
F3
JE
az
12
ot
82
ti
96
FF
FF
as
FF
Be
dE
LINE
WRITE BYTE --- A = BYTE
;UNPARCK BYTE DATA IHTO TWO ASCII
CHARACTERS. A=BYTE: К, # = СНАЕ 5
WROB
Г
¡WRITE
URTEO
ASCII
ASCH
SPAC?
SPACE
T21e
T2721
PHA
LSR
LSR
LSR
LSR
JER
TAX
PLA
AND
JSR
A
a
fA
A
A
SCI! ; CONVERT TO ASCII
USB
ASCII
2 CHARS--E,A=CHARS
PHA
TEA
JSR
PLA
JAP
ELE
ADE
ADC
BEL
ABC
ABC
RIS
JER
LBA
JP
LDA
COR
PHA
LBA
БТА
PLA
STA
BEX
BRE
RTS
WRT
BRT
#5
Fa
ASCI
#586
#430
SPaLE
$420
WRT
#2
TMPB-1,%
; TYPE SP
THP2-1, &
THPB-1, 8
TMP2-1,%
T2121
;READ HEX ADR. RETURN HI IN TAPO,
+
RDOA
ROSA?
RDEXIT
JSR
BCC
STA
JSR
BCC
STA
RTS
"LD IN THP9+I. AND CT=1
;1F SP CY=8
RDOB ; READ 2-CHAR BYTE
RDOAZ i SPACE
THPB +1
RDGE
RDEXIT i SP
ТИРВ
107
>
PET MONITOR
LINE
2388
8385
8390
8391
8392
8353
8354
8395
8396
8337
8338
8393
846€
048 i
84582
8483
8484
8485
8486
9487
8498
B485
84138
B411
B412
B413
8414
6415
8416
B417
8418
9419
8428
942!
8422
8423
9424
8425
8426
“8427
8428
8423
8439
6431
8432
8433
8434
8435
8436
B 437
94:38
84359
8448
8441
0442
# LGC
865E
865E
865E
86SE
865E
6669
8662
8665
8657
0569
856
dEGE
0578
8671
8672
8675
8678
867?
8678
8679
8678
967E
0681
8683
0684
8635
8687?
8638
8584
B68B
06872
BEBF
86938
8693
8695
8637
9699
8693
869€
869F
BEAZ
ERA
BHR6
VERA
B6AR
Géant
BEAF
9681
8683
BEBO
0588
8588
BEBE
VEBF
BELI
13.
R3
85
ca
Ca
DE
26
C3
De
18
68
28
ВА
BR
GR
BA
83
ès
20
83
38
68
CS
B8
29
28
38
65
60
20
£5
Dh
68
68
4C
4C
28
A5
85
85
RI
85
20
25
85
28
AZ
28
£59
Fa
£9
F8
i.
.....PAGE 9099
CODE
98
ВЕ
36
28
89
su
28
GE
83
BF
sa
85
BF
3n
BF
82
ва
CF
8
Fa
a7
ЭВ
30
ae
EE
FA
23
Bo
Ro
Be
Be
06
FF
B4
94
86
РЭ.
SE
Br
Fi
38
Be
CF
2C
55
&D
ge
96
86
FF
LINE
A O RO Ma
DOB
RDOB1
REOB2
RBOb3
HEXIT
HEX89
REDE
ERRL
LD
RD2
=.
READ HEX
AND CY=1
LBA
STA
JSR
CHP
BRE
JSR
СИР
ВНЕ
CLC
RTS
JSR
ASL
RSL
ASL
ASL
STA
JSR
JSR
ORA
SEC
RTS
CHP
PHP
AND
PLP
BEC
ABC
RTS
JSR
СИР
ВНЕ
PLA
PLA
JAP
JAP
JSR
LDA
STA
STA
LDA
STA
JER
AHD
STA
JSR
LOX
JSR
Cup
BEN
СИР
BES
BYTE AND RETURN 1H A
IF SP CY=8
+68
REND
RDUL
}*
RDOB2
RDAC
#
RDG83
i SPACE
¿READ NEXT CHAR
i READ HEXT CHAR
¡CY=B
RESIT
fA
A
A
A
ACH)
RDOC
HERIT
ACAD
¿TO HEX
i 2ND CHAR ASSUMED НЕХ
¿CY=1
$434
i SAVE FLAGS
#$BF
HEXB9
#8
; 8-9
iRLPHA ADD B+CY=9
RDT
#48)
HEXB9
;READ CHAR
:18$ IT A CR
i NG: RTS
¿; YES, CLEAN STACK,EXIT
START
ERROPR
RDOC
$0
FHLEN
FNADR+1
#CISTR
FNADR
RDOB READ FA
"SF
FA .
RDOC
18
ROT
#°,
1-4
#3]
L3
108
¿FIRST ABR
; SKIP COMA
PET MONITOR 13.1......PAGE 8810
LINE
9443
4444
8445
B446
8447
8448
0449
0450
6451
0452
8453
9454
0455
9456
9457
8458
B459
B460
B461
a462
8463
0464
8465
B466
0467
0468
8469
8470
B47 1
9472
8473
8474
8475
8476
8477
0478
8479
9430
0481
8432
8423
8424
8485
8426
2487
0488
9489
9456
8431
8492
8497
8494
8455
8496
0497
# LOC
05C3
8625
BECT?
del”
asc
asc
dECE
9606
BED:
85D4
BEBO
В5 03
QL LB
ВБ БВ
BEER
96EZ
B6ES
GéE7
BEER
84ED
BEEF
A6F |
BEF 4
Beko
BEF 3
BEF C
BEF E
8791
9784
8787
san
878D
d7ar
8/11
8/14
Briz
8719
Q7iB
0710
871iF
8/22
8/24
8726
0773
872
720
Br 2E
a7 31
0734
8/36
0733
B7 3a
eric
В7 ЗЕ
0748
al
ей
CORE
10
Fi
23
EE
EA
28
56
Ce
ue
HB
Fi
a
sB
Bd
F9
67
ЗВ
FF
EE
as
35
ag
9B
AE
F8
43
ce
BA
13
ac
19
ES
57
4F
il
F7
i2
Fa
СЕ
29
F9
UD
A4
26
63
9С
4F
li
ES
12
Ee.
28
86
9?
82
a4
F3
24
FJ
F6
F4-
Fe
Fg
82
94
66
FF
a5
Be
LINE
L3
tbe
LD126
LISO
Life
LS
CPR
BEQ
STA
IRC
INK
BNE
LDA
CHP
BHE
LDA
515
LEA
BNE
Jar
CMP
BES
JSR
JSR
JER
LDA
BEG
JSR
ENE
JAP
JSR
BEC
JSR
JSR
JSR
JSR
LOA
ANT
BNE
JP
JS A
Lin
STA
LDA
STA
JSR
ERP
BEG
CHF
BER
CHP
BEA
JAP
JER
LDA
STA
LOA
STA
LDn
CMP
BE Q
116
RBZ
ISTR,K
FNLEN
Ke
S AY X
+6
ERRL
$0
YERCK
FA
x +5
ERROPR
"3 .
¿DIO
222,
CSTEL.
LDS9O
FNLEN
LUIS
FAF
LE178
ERROPR
FRK
LII128
LHRD2
LD4 HW
TRI
TWIT
EATUS
#SPERR
iD128
START
REGA
TMPM
STAL
TMPB+1
STAH
KOT
15:28
LS
*sE
Ed:
A
* +5
EREL
ROOA
TMPB
ERL
THFB +1
ERH
Savy
#6
LIZ
109
;15 TAIS A LUAD
NO. ERROR
; RB, STORE BEGIN'G ADK
+ RD NET CHAR
; IGNORE BLARKS
;CR: GO TEST IF LOAD
;RD, STORE ENRING ADRS
; TEST IF LOAD OR SAVE
; 60 LOAD
PET MONITOR 13.1
. 8521
LINE * LOC
8478 8742 AZ
04399 0744 28
B588 8747 dt
8581 0748 Вр
958: 29748 28
8592 8755 39
8582 A76A В?
8583 BPéB
2584 #8268
8585 0768
8506 8768
8507 768
8598 8768
8589 8768
9510 8768
Bolt 676B
8512 8768
9513 076B
8514 4768
8515 8768
893156 8768
8917 @76B
8518 0768
8513 8766
25720 6768
8768
Bf 8768
8523 ©9768
8524 @reB
9525 B7rER
8526 8748
ERRORS = ages
В PAGE 901:
CODE LINE
ea LN se
BI Fg 52158 JSR SAVE
57 #4 JMP START
HBR ‚87T san:
20
28 BYT ‘B $
TSTP=#F328
SY=LD
272=3F667
CSTEL=$FB3O
LDIDB=SFIFF
SPERR=16
SATUS=#28C
TUAIT=$F513
TRYU=$F88A
LU408=$F422
LEAD2=$F64D
FAN=SFEAE
SAYE=SF6BI1
VERCK=%288
FAF=$F495
Z21=ALTM-1
Z22=ALTR-1
2L2E3=DSFLYR-1
224=BSPLYM-1
Z23=60-1
Z26=EXIT-1
227=LD-1
2ÉB=SY-1
ECM END
110
2
3
i SAVE
4
>
6
",$57
SYMBOL TABLE
SYMBOL
A4
ACHI
ALTM
B3
BRKF
EBINV
CRLF
DCMP
DSP1
EAL
ERRSÍ
FAN
Gi
HEXIT
L4
1.318
LO?
NCMDS
POTP
RDOA
RDOB2
REGK
SATUS
SETWR
SPERR
STAL
T2T21
TMPé
ISTP
VARTAB
WROA
URY
221
£29
£22
END OF ASSEMBLY
VALUE
Восс
BOBF
B5C2
8439
eau
B2if
B4F 2
B443
8587
BRED
83AF
FIRE
BIES
8685
8714
BEDI
BEDA4
08838
8482
B64F
8672
Bila
8B28C
8581
89818
perf?
8641
8817
ЕЗ2га
ВВС
0684
FF9Z
a5ci
85D?
F667
AS
ADRH
ALTR
BS
ВУЗ
CMDS
CSTEi
DIFF
DSPLYM
EON
EXIT
FLGS
GO
INCTMP
LS
LDIZ8
LD308
РЕН
RENT
RDOAZ
RDOB3
se
SAVE
SP
5789
START
TMPB
TMPE
TUALT
VERCK
VROAI
WRTWE
222
226
BCE
0508
0582
8447
B4E1
350:
F83B
BOSE
BSSE
8768
BOFE
#818
8558
per?
B7if
B6F6
FIFF
Ве ТА
Bazi
8656
867E
8482
F6B1
ВВ ТЕ
В471
8457
8811
8821
£913
a290B
8698
8622
8561
85FD
AS
ADRL
ASCÍ
BENSI
BYTE
COLH
Bi
DM
DSPLYR
ERRL
FR
FNADR
НОЕ
ISTR
ЦЕНТ
LDISO
LD488
PCL
RDZ
RDOE
RDEC
Si
SAYX
SPAC2
STi
БУ
TMP2
TMPC2
TXTPT
WARM
BROB
KR
23
ZZ?
111
9306
9512
8634
GDRAC
aser
8577
8337
94B8
052D
vEIT
ОВР
aBF5
Я? В
9623
8622
Gers
F422
9813
9688
26 3E
86386
8434
9628
8637
0477
a69F
enla
gga
ВСВ
C388B
8613
8915
CAR
069E
ACC
AL2
ASCII
BRKE
CALLE
EO0LH2Z
B2
Dmi
EAH
ERRGPK
FAF
FNLEN
REXHS
L3
LD
LDhive
LDIADZ
PREYC
RDERIT
RDOH 1
RDT
Se
SETR
SPACE
STAH
Tate
TMPA
TRY
UPLI
RAP
WRPC
УК
224
228
E
8580
B628
9427
B4BF
8582
asac
848F
OUE6
9498
F495
BREE
B68F
AECE
96 9F
BEFE
F643
BREE
B650
BEES
FFCF
0459
04E7
B63A
gare
85 3F
0815
FROA
8891
BORA
8603
BBE
955E
0E9E
Chapter 9. ERRORS AND DIAGNOSTICS
One of the advantages of the highly interactive way in which you are able to use your PET is that errors
are easily correctable, due to the fact that the languages that are used within the machine have specific
rules under which the not so smart computer can operate. These rules are necessary to allow the
language to be able to understand what you are trying to tell it. Whenever BASIC cannot perform a
function, it will tell you about it in the form of an error message. A total list of the error messages and
some examples of what causes them follows.
The advantage of having this immediate response on the screen is that you can use the screen editor to
immediately fix the problem as it occurs. In most cases, the problem is going to be obvious to you. The
most common error is the syntax error problem, which means that you have typed the line to BASIC that it
doesn't understand. The correction for this type of problem is to list the line that is being complained
about and compare the typed data to what you thought you were going to type. About 90 percent of the
time, you will discover the mistake by superficial inspection. If not, you may have to make reference to
the appendix which defines the form for all the BASIC statements and if that does not clarify it for you, go
to the individual write-up to understand what you are doing wrong.
The common problems are you have got a comma in the wrong place, or you used a variable that cannot
be used in this particular kind of format. The basic premise to remember when correcting errors is that
although the language is forgiving of exact requirements for spaces verses no spaces etc., that the rules
are explicit. If you violate the rules, the computer is going to continue to complain about an error until you
give it a problem it understands. Sometimes, the error is not as easy to undestand, although in almost
all cases while executing a problem, if an error is encountered, the line number will be indicated.
Sometimes a problem is the result of a programming mistake that you have made in a previous
computation. For instance, if you get a divide by zero in line 75 and you know you shouldn't be dividing by
zero because, in your opinion, the value that is in the divisor should never be zero. The error is probably
not on line 75, but somewhere further up your program where you define the variable. In order to attack
this kind of problem, the use of temporary print statements is the common technique. In other words, if
the variable is zero on line 75 and you don't think it shouid be, then you should list the portion that defines
the variable. More often than not, an inspection of this area will show the problem to you immediately. If
not, insert lines at appropriate places where the variable is computed to see when the variable acquires a
value that you don’t expect. This technique will usually allow you to figure out the problem in your
programming.
The error messages in PET BASIC have been expanded over those other BASICs to give you a readily
English format for what the message is. However, other than using the techniques which we have just
described, the computer cannot fix a problem for you, it is in this area that programmers are made or
broken. Just remember that nobody is looking over your shoulder and use the machine to help you
understand the problem. If necessary, write little test routines which do only a piece of your program,
until you understand what is causing your problem.
ERROR MESSAGES
On encountering an error in interpretation of a statement, whether in direct or program
execution, BASIC displays a diagnostic message then returns to direct mode.
MESSAGE ERROR IN LINE NUMBER
READY.
113
Resumption of execution is not permitted with a CONT command. Variables within the statement or
program retain their values so they may be scrutinized to determine a cause of error, if
necessary. GOSUB and FOR entries on the stack at the time of error are cleared So resumption of
execution is not possible by RETURN or NEXT.
POSSIBLE BASIC MESSAGES AND MEANINGS
Bad subscript- An attempt was made to reference a matrix element which is outside the dimensions of
the matrix. This may happen by specifying the wrong number of dimensions or a subscript larger than
specified in the original dimension.
DIM A(2,2)
A(1,1,1)=2
?BAD SUBSCRIPT ERROR
READY.
A(10,10) = 2
?BAD SUBSCRIPT ERROR
READY.
Can’t continue-Program execution cannot be resumed via a CONT command in four cases:
1) no program exists.
2) a new line was just typed in.
3) the program has not recently been run.
4) an error just ocurred.
10A$ = ‘HELLO’
CONT
‘CAN'T CONTINUE ERROR’
READY.
Division by zero-Zero as a divisor would result in numeric overflow--thus it is not allowed. When this
message appears, it is most expedient to list the statement and look for division operators.
?DIVISION BY ZERO ERROR IN 10
LIST 10
10A = B/C
7C
0
Formula too complex-This message concerns only string expressions when BASIC runs out of string
temporary pointers to keep track of substrings in evaluating a string expression.
?FORMULA TOO COMPLEX ERROR
READY.
Break the string expression into two smaller parts to cure the problem.
illegal direct-A single 80 column buffer area is used by BASIC to process Incoming characters. This same
buffer is used to hold a statement that is being interpreted in direct mode. INPUT will not work because
incoming characters would overwrite the variable list following INPUT to be processed.
DEF cannot be used in direct mode for a different but similar reason. The name of a function is stored in
the BASIC variable area with pointers to the string of caharacters which define the function. Since the
function exists only in the input buffer, it would be wiped out the first time a new command is typed-in.
114
INPUT A
ILLEGAL DIRECT ERROR
READY.
lllegal quantity--Occurs when a function is accessed with a parameter out of range. This error may be
caused by:
1. A matrix subscript out of range 0< X «1 32767
X(—1)=Y
?ILLEGAL QUANTITY ERROR
2. LOG (negative or zero argument)
3. SQR (negative argument)
4. A + Bwhere A=0 and B not integer.
?(—57 is illegal because it would give a complex result.
5. Call of USR before machine language subroutine has been patched in.
6. Use of string functions MID$, LEFTS, RIGHTS, with length parameters out of
range{1< X < 255).
7, Index on ....GOTO out of range.
8. addresses specified for PEEK, POKE, WAIT and SYS out of range.
(0 < X <65535). |
9. Byte parameters of WAIT, POKE, TAB and SPC out of range
(0< X<255).
POKE 32768,1000
?1LLEGAL QUANTITY ERROR
READY.
Next without for--Either a NEXT is improperly nested or the variable in a NEXT statement corresponds to
no previously executed FOR statement.
РОВ 1= 1 ТО 10:МЕХТ:МЕХТ
NEXT WITHOUT FOR ERROR
READY.
РОН |= 1 ТО 10:МЕХТ y
NEXT WITHOUT FOR ERROR
READY,
OUT OF DATA--A READ statement was executed but all of the data statements in the program have been
read. The program tried to read too much data, or insufficient
OUT OF DATA--A READ statement was executed but ail of the data statements in the program have been
nt data, was included in the program. Carriage
OUT OF DATA--A READ statement was executed but all of the data statements in the program have been
read. The program tried to read too much data, or insufficient data, was included in the program. Carriage
returning through a line READY on the PET TV display, sometimes yields this error because the message
is interpreted as READY.
READY.
?0UT OF DATA ERROR
READY.
OUT OF MEMORY--May appear while entering or editing a program as the text completely fills memory.
At run time, assignment and creation of variables may also fill all variable memory. Array available
declarations consume large areas of memory even though a program may be rather short. The maximum
number of FOR loops and simultaneous GOSUBs are dependent on each other. This context is stored on
the 6502 hardware stack whose capacity may be exceeded. To determine the type of memory error, print
FRE (0). If there are a large number of bytes variables, it is most likely a FOR-NEXT or GOSUB problem.
115
10GOSUB10
RUN
?QUT OF MEMORY ERROR IN 10
_ READY.
?FRE(0)
7156 -
OVERFLOW--Numbers resulting from computations or input that are larger than 1.70141184 E + 38 cannot
be represented in BASIC's number format. Underflow is not a detectable error but less than 2.93873587
E-39 are indistinguishable from zero.
?1E40 |
?0VERFLOW ERROR
READY.
REDIM'D ARRAY--After a matrix was dimensioned, another dimension statement for the same matrix was
encountered. For example, an array variable is defined by default when it is first used, and later a DIM
statement is encountered.
A(5)=6
DIM A(10,10)
?REDIM'D ARRAY ERROR
READY.
REDO FROM START--Is not actually a fatal error printed in the standard format but is a diagnostic printed
when data in response to INPUT is alpha when a numeric quantity is required.
10 INPUT A
RUN
7ABC
?REDO FROM START
7
INPUT continues to function until acceptable data has been received. The complement to this diagnostic
on files is BAD DATA ERROR which is fatal When not enough data has been typed in response to INPUT,
a double ? is printed until enough data is received.
10 INPUT A,B,C
RUN
21
772
223
READY.
RETURN WITHOUT GOSUB--A RETURN statement was encountered without a previous GOSUB
statement being executed.
CLR
RETURN
7RETURN WITHOUT GOSUB ERROR
STRING TOO LONG--Attempt by use of the concatenation operator to create a string more than 255
characters long.
AS =
FOR |= 1 TO 10:A$ = A$ + AS:-NEXT
?STRING TOO LONG ERROR
READY.
SYNTAX--BASIC cannot recognize the statement you have typed. Caused by such things as missing
parenthesis, illegal characters, incorrect punctuation, mispelied keyword.
116
RUIN
?5YNTAX ERROR
READY.
TYPE MISMATCH--The left-handed side of an assignment statement was a numeric variable and the
righthand side was a string, or vice versa; or a function which expected a string argument was given a
numeric one, or vice versa.
А$ = 5
TYPE MISMATCH ERROR
READY.
UNDEF'D STATEMENT--An attempt was made to GOTO, GOSUB, or THEN to a statement which does not
exist.
GOTO A
UNDEF’D STATEMENT ERROR
READY.
UNDEF'D FUNCTION--Reference was made to a user defined function which had never been defined.
X =FNA(3)
?UNDEF'D FUNCTION ERROR
READY.
Operating System Messages and Meanings
BAD DATA--Numeric data was expected but alpha data was received when inputing from a special
device.
DEVICE NOT PRESENT-- No device on the IEEE was present to handshake an
attention sequence. Status will have a value of 2 which corresponds to a time out. May happen on OPEN,
CLOSE, CMD, INPUT#, GET#, PRINT#
OPEN 5,4,3, ‘FILE’
?DEVICE NOT PRESENT ERROR
READY.
FILE NOT FOUND--The named files specified in OPEN or LOAD was not found on the device specified. In
the case of tape 1/0, an end of tape mark was encountered. In disk 1/O, the disk timed out when
attempting to open the file, thus producing this message:
LOAD ‘FILE’, 15
?FILE NOT FOUND ERROR
READY.
FILE NOT OPEN--The operating system must have device number and command information provided by
the OPEN statement. If an attempt is made to read or write a file without having done this previously, then
this message appears:
CLR
INPUT#10,A
?FILE NOT OPEN ERROR
READY.
FILE OPEN--An attempt to redefine file parameter information by repeating an OPEN command on the
same file twice.
OPEN 1,4,1
OPEN 1,4,1
?FILE OPEN ERROR
READY.
LOAD-Only ccurs when loading a program from cassette tape. This means that there were more than 31
errors in the first tape block or that there were errors in exactly the same corresponding positions of both
117
blocks.
NOT INPUT FILE --Tape files, once opened for writing, cannot be read without first CLOSE rewinding tape
and OPEN for INPUT. This message appears when an attempt is made to read on output file:
10 OPEN 1,1,1
20 INPUT #1,A
?NOT INPUT FILE ERROR
READY.
NOT OUTPUT FILE-Tape files cannot be read and updated in ptace. Device 0 is the keyboard and it
cannot be written to:
10 OPEN 1,0
20 PRINT 4H
?NOT OUTPUT FILE ERROR
READY.
VERIFY--The contents of memory and a specified file do not compare.
NOTES
118
Appendix A.
BLOCK #
“0
0 60 © Mm A WM =
— oh wk wb
LW № =O
*14
15
PAGE
veg
vey
ves
veg
4-15
PAGE
TYPE
RAM
RAM
TYPE
RAM
RAM
RAM
RAM
RAM
TYPE
ROM
10
Detailed PET Memory Map
PET Memory Allocation By 4K Blocks
START
ADDRESS
$0000
$1000
$2000
$3000
$4000
$5000
$6000
$7000
$8000
$9000
$A000
$BO00
$C000
$D000
$E000
$E800
$F000
START
ADDRESS
0000
0100
0200
0300
0400
START
ADDRESS
$E000
$E800
FUNCTION
Working, text, variable storage.
Test variable storage (8K only)
Expansion RAM
Expansion RAM
Expansion RAM
Expansion RAM
Expansion RAM
Expansion RAM
Screen memory (1K)
Expansion ROM
Expansion ROM
Expansion ROM
BASIC {principally statement interpreter).
BASIC (principally math package).
Screen editor.
All internal PET МО.
OS diagnostics
*see expanded description
Block 0 By 256 Byte Pages
FUNCTION
BASIC OS working storage
Stack
O $ working storage
Cassette buffers.
BASIC text area
** see expanded description by page
Block 14 By 2K Segment
FUNCTION
Screen editor
PET 1/0
A-1
PAGE
TYPE
PIA
PIA
VIA
IO Device Base Addresses
START
ADDRESS FUNCTION
$E810 Keyboard
ФЕ820 IEEE-488
$E840 USA PORT cassette
Location not specified are used but have no clear one function definition.
PET PAGE ZERO MEMORY MAP
FROM TO
000 a
001 002
Terminal VO maintenance
003 --
004 .
005 --
006 --
007 --
008 --
009 --
- 010 089 -
090 --
091 -
092 --
Evaluation of variables
093 -
094 -
095 -
096 -
097 --
098 --
099 -
100 -
101 -
102 103
104 111
112 113
114 115
116 121
Data storage maintenance
122 123
124 125
126 127
128 129
130 131
132 133
| $b 134 135
| 136 137
138 139
140 141
142 143
144 145
DESCRIPTION
$4С constant (8502 JMP instruction).
USR function address lo, hi.
Active 1/O channel +.
Nulls to print for CRLF (unused).
Column BASIC is printing next.
Terminal width (unused).
Limit for scanning source columns (unused).
Line number storage before buffer.
$2C constant (special comma for INPUT process).
BASIC INPUT buffer (80 bytes).
General counter for BASIC.
$00 used as delimeter.
General counter for BASIC.
Flag to remember dimensioned variables.
Flag for variable type; O#numeric; 1 — string.
Flag for integer tape.
Flag to crunch reserved words (protects '& remark).
Flag which allows subscripts in syntax.
Flags INPUT or READ.
Flag sign of TAN.
Flag to suppress OUTPUT (+ normal; — suppressed).
Index to next available descriptor.
Pointer to last string temporary lo; hi.
Table of double byte descriptors which point to vaiables.
Indirect index #1 lo; hi.
Indirect index #2 lo; hi.
Pseudo register for function operands.
Pointer to start of BASIC text area lo; hi byte.
Pointer to start of variables lo; hi byte.
Pointer to array table lo; hi byte.
Pointer to end of variables lo; hi byte.
Pointer to start of strings lo; hi byte.
Pointer to top string space lo; hi byte.
Highest RAM adr lo; hi byte.
Current line being executed. A zero in 136 means statement
executed in a direct command.
Line # for continue command lo; hi.
Pointer to next STMNT to execute lo: hi.
Data line # for errors lo: hi.
Data statement pointer lo; hi.
A-2
Expression evatuation
146 147 Source of INPUT lo; hi.
148 149 Current variable name.
150 151 Pointer to variable in memory lo; hi.
152 153 Pointer to variable referred to in current FOR-NEXT.
154 155 Pointer to current operator in table lo, hi.
156 - Special mask for current operator.
157 158 Pointer to function definition lo; hi.
159 160 Pointer to a string description lo; hi.
161 - Length of a string of above string.
162 -- Constant used by garbage collect routine.
163 - $4C constant (6502 JMP inst).
164 165 Vector for function dispatch lo; hi.
166 171 Floating accumulator #3.
172 173 Block transfer pointer #1 lo; hi.
174 175 Block transfer pointer #2 lo; hi.
176 181 Floating accumulator #1. (USR function evaluated here).
182 - Duplicate copy of sign of mantissa of FAC 41.
183 - Counter for # of bits fo shift to normalize FAC $ 1.
184 189 Floating accumulator #2.
190 - Overflow byte for floating argument.
191 — Duplicate copy of sign of mantissa.
192 193 Pointer to ASCII rep of FAC in conversion routine lo; hi.
RAM subroutines
194 199 CHRGOT RAM code. Gets next character from BASIC text.
200 - CHRGOT RAM code regets current characters.
201 202 Pointer to source text lo; hi.
203 223 Next random number in storage.
OS page zero storage
J Fo 224 225 Pointer to start of line of cursor loc lo; hi.
226 - Column position of cursor.
227 228 General purpose start address indirect lo; hi. °
229 233 General purpose and address direct lo; hi.
234 -- Flag for quote mode on/off.
238 - Current file name length.
239 - Current logical file number.
240 - Current primary address.
241 242 Current secondary address.
243 244 Pointer to start of current tape buffer lo; hi.
245 -- Current screen line $.
246 - Data temporary for 1/0. |
247 248 Pointer to start loc for O.S. lo; Ai.
249 250 Pointer to current file name lo; hi.
251 254 Unused.
255 - Overflow byte that BASIC uses when doing FAC to
ASCII conversions.
Page 1
62 byte on bottom are used for error correction in tape reads. Also, buffer for ASCII when BASIC is
expanding the FAC into a printable number. The rest of page 1 is used for storage of BASIC GOSUB and
for NEXT context and hardware stack for the machine.
A-3
FROM
512
517
519
523
524
525
526
527
537
539
549
551
553
578
588
598
610
611
612
613
621
624
625
627
628
629
630
632
633
634
826
1018
PET PAGE TWO MEMORY MAP
—_—
214
518
520
536
538
540
577
987
597
609
631
825
1017
1023
DESCRIPTION
24-hour clock in 1/60 sec.
Correction factor for ciock LSB; MSB.
Interrupt driver fiag for cassette #1. switches; #2 switches.
Flag means verify not load into memmory.
IO status byte.
Index into keystroke buffer.
Flag to indicate reverse-field on.
Interrupt driven key stroke buffer.
IRQ RAM VECTOR lo; hi.
BRK instruction RAM VECTOR lo; hi.
Count down to flip cursor.
Flag for cursor on/off.
Table of LSB of start addresses of video dislay lines (25).
Table of logic addresses.
Table of primary addresses.
Table of secondary addresses.
Index into LA, FA, SA tables.
Default input device #.
Default output device #.
Computation of parity on cassette write.
Count of redundant tape blocks.
Count down synchronization or cassette write.
Index next character infout tape buffer #1; #2.
Countdown synchronization on cassette read.
Flag to indicate bit/byte tape error,
Flag to indicate tape routine reading shorts.
Index to addresses to correct on tape read pass 1; pass 2.
Flag for cassette read-tells current function--countdown, read, etc.
Count of seconds of shorts to write before data.
Buffer for cassette #1 (192 bytes).
Buffer for cassette #2 (192 bytes).
Unused.
A-4
VARIABLE ALLOCATION
Space is allocated for variables only as they are encountered. It is not possible to allocate an array on
the basis of 2single elements, hence the reason to execute DIM statement before array references.
Seven bytes are allocated for each simple variable whether it is a string, number, or user defined
function.
The first two bytes give the name of the variable:
byte 1 byte?
INTEGER firstehr + Second chr + 128
128 or 128
FLOATING first chr second chr
or0
STRING first chr second chr + 128
or 128
The last five bytes give the value of a variable, or a descriptor to the rest of the data:
INTEGER
actual value
256 * HI LO 0 0 0
FLOATING Le , .
actual value in binary floating point
STRING pointer
chr
count LO HI 0 0
The simple string variable points to alocation in high memory, where the actual characters are stored.
Examples of declaration and storage
15% = 90
201 181 0 9 0 0 0
C$ = “HELLO”
67 128 5 . . ©
A-5
Locations 124 and 125 contain the first address of memory where a simple variable name will be
found.By incrementig the address by 7 each time the ext simple variable name in the table is
encountered.The end of the variables is defined-by the address in 126 and 127.
Locations 126 and 127 also define the start of array storage. The first two bytes of array descriptors
arethe same as simple variables but the next five bytes are special as follows:
byte 3 byte 4 byte 5 byte 6 byte 7
VECTOR / +(size + 1)*
ARRAYS (dim) A 0 1 0 size +1
where A = 2forinteger, = 3forstring,or = 5 for floating.
By incrementing the search address by the current byte #3 of the descriptor each time, the next array
variable is reached. Locations 128 and 129 contain the ending address of this table.
BASIC TEXT
(124,125)
simple variable pointers involved in BASIC
storage vaiable storage.
(126,127)
array variable
storage
Y
(128,129)
high
memory
Because the variables are divided in storage between arrays and simple variables insertion of an
additional simple variable is a bit more complicated once an array has been defined. First, the entire array
storage area must be block moved upward by seven bytes and the pointers adjusted upward + 7.
Finally, the simple variable can be inserted at the end of simple variable storage.
If large arrays are defined and initialized first before simple variables are
assigned, much execution time can be lost moving the arrays each time a
simple variable is defined. The best strategy to followin this case is to
assign a value to all known simple variables before assigning arrays.
This will optimize execution speed.
Functions of NEW and CLR on data pointer:
CLR
String pointer equated to top of memory data pointerto
start of text — 1 end of array table to start of variables end
of simple variables to start of variables.
NEW
String pointer equated to top of memory data pointer to
start of text — 1 endofarraytableto startoftext +3
end of simple variables to start of text + start of variables
to start of text + 3.
A-7
PRINCIPAL POINTERS INTO PET RAM
256 * PEEK( 123 145 125 127 129 131 133
+ PEEK( 122 144 124 126 128 130 132
a = a ® a = o
QD — mM a "a oo =
+ 5 + +
о. 2 o 2 2 o, =
5 + 5 5 3 а
X 3 = 5 2 = 3
D D с + © 9
= = D о 2
E © =
| {D
PA CE Y
at initialization \ 8192
000
1024 1025 1028
typical program Ÿ Y \ Y у Y у
BASIC
statements variables arrays strings
1025 1092 1113 1175 8184
A-8
HOW BASIC STATEMENTS ARE STORED
1024 1025 1027 1029
0 Link Line # compressed BASIC text 0 Ko
endof
statement
is flagged
и by zero byte
Link Line # compressed BASIC text 0
end of text is
stored as zero
link bytes
A-9
Appendix B.
DEF FN
DIM
END
FOR-TO-STEP-NEXT
GET
GOSUB-RETURN
GOTO
iF-THEN
INPUT
LET
ON-{GOSUB-GOTO)
POKE-PEEK
PRINT
READ-DATA-RESTORE
REM
STOP-CONT
WAIT
BASIC STATEMENTS
1
ala wa = „я -
ma mam EK ‚Жо Ar -
195”
in the following description of statements, an argument of V or W denotes a numeric variable. X denotes
a numeric expression, X$ denotes a string expression and an | or J denotes an expression that is
truncated to an integer begore the statement is executed. Truncation means that any fractional part of
the number is lost, e.g. 3.9 becomes 3, 4.01 becomes 4.
DEF 100 DEF FNA (V)=V/B+C
B-1
The user can define functions like the
built-in functions (SQR, SGN, ABS, etc)
through the use of the DEF statement. The
name of the function is ‘FN’ followed by
any legal variable name, for example: FNX,
FNJ7, FNKO, FNR2. User-furnished
functions are restructed to one line.
A function may be defined to be any
expression, but may only have one
argument. In the example, B & C are
variables that are used in the program.
Executing the DEF statement defines the
function. User-defined functions can be
redefined by executing another DEF
statement for the same function.
User-defined string functions are not
allowed. ‘'V' is called the dummy variable.
DIM
END
FOR
110 Z=FNA(3}
200 DEF FNA(V)= FNB(V)
113 DIM A(3),B(10)
114 DIM R3(5,5), D$(2,2,2)
115 DIM Q1(N).Z(2" 1)
117 A(8)=4
999 END
300 FOR \ = 1 ТО 9.3 STEP .6
310 РОВ У = 1 ТО 9.3
В-2
Execution of this statement following the
above would cause Z to be set to 3/B + C,
but the value of V would be unchanged.
A function definition may be recursive.
A DEF statement may be written in terms
of other functions, however.
Allocates space for matrices. All matrix
examples are set to zero by the DIM
statement.
Matrices can have more than one
dimension. Up to 255 elements
Matrices can be dimensioned dynamically
during program execution. If a matrix is
not explicitly dimensioned with a DIM
statement, it is assumed to have as many
subscripts as implied in its first use and
whose subscripts may range from Ô to 10
{eleven elements).
If this statement was encountered before
a DIM statement for A was found in the
program, it would be as if a DIM A(10) had
been executed prévious to the execution of
line 117. All subscripts start at zero (0),
which means that DIM x (100) really
allocates 101 matrix elements.
Terminates program execution without
printing a BREAK message. (See STOP)
CONT after an END statement causes
execution to resume at the statement
after the END statement. END can be used
anywhere in the program, and is optional.
V is set equal to the value of the
expression following the equal sign, in this
case 1. This value is called the initial value.
Then the statements between FOR and
NEXT are executed. The final value is the
value of the expression following the TO.
The step is the value for the expression
following STEP. When the NEXT
statement is encountered, the step is
added to the variable.
H no STEP was specified, it is assumed to
be one. If the step is positive and the new
value of the variable is < =to the final
value (9.3 in this example), or the step value
GET
GOSUB
315 FOR Y =10"N TO 3.4/Q0 STEP
SQR(R)
340 NEXT V
345 NEXT
350 NEXT VW
GET A
GET AS
10 GET AS: TFAS ==" "THEN 10
10 GOSUB 910
8-3
is negative and the new value of the
variable is =>the final value, then the first
statement following the FOR statement is
executed, Otherwise, the statement
following the NEXT statement is executed.
All FOR loops execute the statements
between the FOR and the NEXT at least
once, even in the case like FOR V=1 TO C.
Note that expressions (formulas) may be
used for the initial, final and step values in
the FOR loop. The variables of the
expressions are computed only once,
before the body of the FOR...NEXT loop to
terminate. The statement between the FOR
and its corresponding NEXT in both
example above (310) would be
executed 9 times.
Marks the end of a FOR loop.
If no variable is given, matches the most
recent FOR loop.
A single NEXT may be used to match
multiple FOR statements. Equivalent to
NEXT V: NEXT W. Specification the former
way saves 1 byte of BASIC text storage.
Works like INPUT or INPUT# on a single
character basis. Unlike INPUT though, this
function scans the keyboard and does not
wait for carriage return to be pressed. If no
key has been pressed, A$ =" "(null string}
and A =0 after executing this statement.
This example stays in a loop until a key
has been
pressed.
Branches to the specified statement (910)
until a RETURN is encountered; when a
branch is then made to the statement after
the GOSUB. GOSUB nesting is limited to
23 levels.
Subroutines line numbers are searched for
from the beginning of text. To increase
execution speed, define subroutines first
with low line numbers. Fewer digits in line
numbers will also save storage space.
50 RETURN Causes a subroutine to return to the
statement after the most recently executed
| GOSUB.
GOTO 50 GOTO 100 Branches to the statement specified.
Keeping line numbers low will save space
on GOSUB statements.
IF...GOTO 32 IF x< = Y + 23x4 GOTO 92 Equivalent to IF...THEN, except that IF...
GOTO must be followed by a line number,
while IF... THEN can be followed by either a
line number or another statement.
IF... THEN 15 IF x<0 THEN 5 Branches to specified statement if the
relation is True.
25 IF X=5 THEN 50:2 = А WARNING. The “Z= A" will never be
executed because if the relation is true,
BASIC will branch to line 50. if the relation
is a false, BASIC will proceed to the line
after line 25.
26 IF X<0 THEN PRINT “ERROR X NEGATIVE": GOTO 350
In this example, if X is less than O, the
PRINT statement will be executed and then
the GOTO statement will branch to line
350. If the X was À or positive, BASIC wil!
proceed to execute the lines after line 26.
Binary floating point representations of
decimal fractions may not alwys be exact.
sometimes a comparison will fail because
of this. In this case, compare the number to
a + range.
INPUT Request information character by character
until carriage return from the keyboard,
turning the characters into numbers or
strings of a maximum length of 79
“characters.
3 INPUT Y, W,W2 Requests data from the terminal (to be
typed in). Each value must be separated
from the preceeding value by a comma (,).
The last value typed should be followed by
a carriage return. A “7?” is typed as a
prompt character. However, only constants
may be typed in as a response to an
INPUT statement, such as 4.5E-3 or "CAT".
If more data was requested in an INPUT
statement than was typed in, a “77” is
printed (if INPUT is from terminal) and the
rest of the data should be typed in. If more
B-4
5 INPUT “VALUE”: Y
LET 300 LET W=X
310 Y =5.1
ON..GOTO 100 ON | GOTO 10,20,30,40
105 ON SGN (X) +2 GOTO
40,50,60
ON...GOSUB 110 ON 1 GOSUB 50,60
POKE 357 POKE |J
B-5
data was typed in than requested, the extra
data will be ignored and a warning “EXTRÁ
IGNORED” will be printed when this
happens. String must be input in the same
format as they are specified in DATA
statements.
Optionally types a prompt string (“VALUE”)
before requesting data from the terminal.
Typing CONT after an INPUT command
has been interrupted will cause execution
to resume at the INPUT statement.
An INPUT command is interrupted if a
carriage return is the only character
entered.
Assigns a value to a variable.
“LET” is optional. The type of variable
(numeric or string) must be the same as the
evaluated expression.
Branches to the line indicated by the I'th
number after the GOTO.
That is :
If 1=1, THEN GOTO LINE 10
If 1=2 THEN GOTO LINE 20
If |=3, THEN GOTO LINE 30
If I =4, THEN GOTO LINE 40.
If | =0 or | attempts to select a nonexistent
line (>=) in this case, the statement after
the ON statement is executed. However,
if | is <255 or >0, an "ILLEGAL QUANTITY”
error message will result. As many line
numbers as will fit on a 79-byte line can
follow an ON..GOTO.
This statement will branch to line 40 if the
expression X is less than zero, to line 50 if
it equals zero, and to line 60 if it is equal
tc one.
Identical to “ON...GOTO”, except that a
subroutine called (GOSUB), is executed
instead of a GOTO. RETURN from the
GOSUB branches to the statement after the
ON...GOSUB.
The POKE statement stores the byte
specified by its second argument (J) into
the location given by its first argument (l).
PEEK 10A = РЕЕК(!)
PRINT
360 PRINT X,Y,Z
370 PRINT
380 PRINT X,Y
390 PRINT "VALUE" 1S”;A
400 PRINT A2,B,
410 PRINT MIDS(AS,2);
READ 490 READ V,W
B-6
The byte to be stored must be =>0 and
<=255, or an “ILLEGAL QUANTITY" error
will occur. The address {I) must be =>0
and <=65535, or an “ILLEGAL QUANTITY"
error will result. POKE works only on RAM
and O POKEIng. Certain locations will
disturb normal PET operation unless reset.
lt is not possible to POKE the PEEK of a
location into a location inPET ROM.
PEEK is a function of an address and
returns a byte value contained in that
location. BASIC cannot be PEEKed and
PEEK of locations $C000 to $E1D9 yields a
value of zero.
Sends the data to PET TV display. BASIC
software calls a subroutine in the system
software and loads the character in the
accumulator.
Prints the value of expressions on the
terminal. If the list of values to be printed
out does not end with a comma {,) or a
semicolon (i), then a carriage returnfline
feed is executed after all the values have
been printed. Strings enclosed in quotes
{(”) may also be printed. if a semicolon
separates two expressions in the list,
their values are printed nest to each other.
If a comma appears after an expression in
the list, then spaces are printed until the
carriage is at the beginning of the next N
column field {until the carriage is at column
N,2N,3N,4N...). If there is no list of
expressions to be printed, then a carriage
return is executed.
String expressions may be printed. A
semicolon is not neeeded between string
expressions such as PRINT A$B$ “HELLO”
that are to be concatenated.
Heads data into specified variable from a
DATA statement. The first piece of data
read will be the first piece of data listed in
the first data statement of the program.
The second piece of data read will be the
second piece listed in the first DATA
statement, and so on. When all of the data
DATA
RESTORE
REM
STOP
CONT
WAIT
10DATA1,3,— 1E3,.04
20 DATA “CBM ANC”
30 DATA PET, “2001”
510 RESTORE
500 REM NOW SET V=0
505REM SET V =0: Y =0
506 V=0: REM SET V=0
9000 STOP
WAIT 1,J,K
B-7
have been read from the first DATA
statement, the next piece of data to be
read will be the first piece listed in the
second DATA statement of the program.
Attémpting to read more data then there is
in all the DATA statements in a program
will cause an “OUT OF DATA” error. The
line number given in the “SYNTAX ERROR”
will refer to the line number where the error
actually is located.
Specifies data, read from left to right.
Information appears in data statements in
the same order as it will be read in the
program.
Strings may be read from DATA
statements. If you want the string to
contain a colon (:) or commas (,), or leading
blanks, you must enclose the string in
double quotes. It is impossible to have a
double quote within string data or a string
literal. (* “ANYTHING” tis illegal.
Allows the rereading of DATA statements.
After a RESTORE, the next piece of data
read will be the first piece listed in the
first DATA statement, and so on as in a
normal READ operation.
Allows the programmer to put comments
in his program. REM statements are not
executed, but can be branched to. A REM
statement is terminated by end of line, but
not by a”.
In this case, the Y =0 will never be
executed by BASIC.
In this case Y = 0 will be executed.
Causes a program to stop execution and to
enter command mode. Prints BREAK IN
LINE 9000 {as per this example}. CONT
after a STOP branches to the statement
following the STOP.
A command that can be executed only in
direct mode. Resumes program execution
after STOP, END, or use of STOP key.
A program cannot be resumed after error
condition, editing, CLR, or NEW. |
This statement reads the status of memory
B-8
location |, exclusive OR’s K with status,
then AND’s the result with J untill a non-
zero result is obtained. Execution of the
program continues at the statement -
following the WAIT.
If the WAIT statement only has two
arguments, K is assumed to be zero. If you
are waiting for a bit to become zero, there
should be a one in the corresponding
position of K. 0< = |< = 65536 J,K must be
< =0 and > = 255,
The STOP key cannot interrupt a WAIT.
Appendix C
BASIC COMMANDS
CLR
LIST
LOAD
NEW
RUN
SAVE
VERIFY
A command is usually given after BASIC has typed READY. This is called the “Command Level”.
Commands may be used as program statements. Certain commands, such as LIST and NEW will
terminate program execution when they finish.
CLR
LIST LISTX
LIST or LIST-
LIST X-
LIST -X
LIST Y-X
LOAD LOAD
LOAD “HURKLE”
LOAD “HURKLE", 2
10 LOAD “HURKLE”
С.
Deletes all stored references to variables,
arrays, functions, GOSUB and FOR-NEXT
context.
Lists line “X" if there is one.
Lists the entire program.
Lists all lines in a program with a line
number equal to, or greater than, “X”.
Lists all of the lines in a program
with a line number less than, or
equal to, “X”.
Lists all of the lines within a program with
line numbers equal to, or greater than, “Y”,
and less than or equal to X”.
If LIST is used as a program statement, the
program will terminate after it is executed.
Load first program found on cassette #1
into memory.
Search for named file on cassette #1 and
then load it into memory.
Same as previous, except from device #2.
When LOAD is specified as a program
statement, execution of the current
program in memory stops at this point.
A normal load of program proceeds. The
new program begins execution from its
lowest line number. Variables and their
values are passed from the load to the new
program. Strings and function definitions
cannot be relied upon because BASIC
maintains pointers into the old text
NEW
RUN RUN
RUN 200
SAVE SAVE
SAVE “HURKLE”
SAVE “HURKLE”, 2
SAVE “HURKLE”, 2,1
VERIFY VERIFY “HURKLE”
C-2
where they used to be. Strings can be
forced to exist in permanent string
variable storage by performing an operation
on them prior to LOAD, e.g. A$ =A$ +“ “.
WARNING: On an overiay LOAD, the
overlaying program must have a text
storage requirement less than or equal to
the previous program. If this is not true,
then the variables will be overwritten
because they are stored immediately after
text in memory.
Deletes current program and all variables.
Starts execution of the program currently
in memory at the lowest numbered
statementment. RUN deletes all variables
{like CLR) and restores DATA. If you have
stopped your program and wish to continue
execution at some point in the program,
use a direct GOTO statement to start
execution of your program at the desired
line.
Optionally starts RUN at the specified line
number.
Save BASIC text on cassette #1.
Save and name the file on cassette #1.
Save on 2nd cassette unit.
Save and write end of tape block.
Same parameters as LOAD. Compares
contents of memory with file and reports
success/faiture of compare.
Appendix D
EXPRESSIONS AND OPERATORS
RELATIONAL OPERATORS
= equal
< less than
> greater than
<= L.E.
>= С.Е.
<> not equal
BOOLEAN OPERATORS
AND
OR
NOT
ARITHMETIC OPERATORS
+ add
— subtract
* multiply
/ divide
1 exponentiation
— (negation)
STRING OPERATOR
+ (concatenation)
D-1
ARITHMETIC OPERATORS
SYMBOL SAMPLE STATEMENT PURPOSE/USE
= A=100 Assigns a value to a variable,
НЕТ 27 = 2.5 the LET is optional.
— В = - А Negation. Note that 0 — A is subtraction,
while — A is negation.
1 130 PRINT X13 Exponentation {equal to X*X*X
in the sample statement). 0t0 =1. Oto any
other power = O.AtB, with A negative and
B not an integer gives an FC error.
* 140 X = R*(B*D} Multiplication.
! 150 PRINT x/1.3 Division.
+ 160.Z=R+T+Q Addition.
— 170 J=100-1 Subtraction.
RELATIONAL OPERATORS
Relational operators can be used as part of any expression.
Relational operator expressions will always have a value of True (— 1) or a value of False (0).
Therefore, (5=4)=0, (5=5)= -1, ete.
The THEN clause of an IF statement is executed whenever the formula after the IF is not equal to 0. That
is to say, IF X THEN...is equivalent to IF X<> 0 THEN...
SYMBOL SAMPLE STATEMENT PURPOSE/USE
= 10 IF A=15 THEN 40 Expression Equals Expression.
<> /0 IF A< > 0 THEN 5 Expression Does Not Equal Expression.
> 30 IF B >100 THEN 8 Expression Greater Than Expression.
< 160 IF B<2 THEN 10 Expression Less Than Expression.
<=, =< 180 IF 100<=B + C THEN 10 Expression Less Than Or Equal To
Expression.
>= => 190 IF Q>=R THEN 50 Expression Greater Than Or Equal To
Expression.
BOOLEAN OPERATORS
AND 2 IF A<B AND B<2 THEN 7 If expression 1 (A <5) AND expression 2
(B <2} are both true, then branch to line 7.
OR IF A<1 OR B<2 THEN 2 If either expression 1 (A <1) OR expression
5 2 (B<?)is true, then branch to line 2.
NOT IF NOT Q3 THEN 4 If expression “NOT Q3” is true (because
Q3 is false), then branch to line 4.
МОТ - 1 =0 (NOT true = false).
AND, OR and NOT can be used for bit manipulation, and for performing boolean operations.
These thrée operators convert their arguments to sixteen bit, signed two's, complement integers in the
D-2
range — 32768 to + 32767. They then perform the specified logical operation on them and return a result
within the same range. If the arguments are not in this range, an ?ILLEGAL QUANTITY ERROR results.
The operations are performed in bitwise fashion, this means that each bit of the result is obtained by
examining the bit in the same position for each argument.
The following truth table shows the logical relationship between bits:
OPERATOR ARG. 1 ARG. 2 RESULT
AND 1 1 1
0 1 0
1 0 0
0 0 0
OR 1 1 1
1 0 1
0 1 1
0 0 0
NOT 1 - 0
EXAMPLES OF BOOLEAN EXPRESSIONS
63 AND 16 =16 Since 63 equals binary 111111 and 16 equals binary 10000, the result of the AND
is binary 10000 or 16.
15 AND 14=14 15 equals binary 1111 and 14 equals binary 1110, so 15 and 14 equals binary 1110
or 14.
— 1 AND 8=8 — 1 equals binary 1111111111111111 and 8 equals binary 1000, so the result is
binary 1000 or 8 decimal.
4 AND 2=0 4 equals binary 100 and 2 equals binary 10, so the result is binary 0 because none
of the bits in either argument match to give a 1 bit in the result.
10 OR 10= 10 Binary 1010 OR'd with binary 1010, or 10 decimal.
—1 OH —2= —1 Binary 1t11111111111111 (— 1} OR’d with binary 1111111111111110 (— 2) equals
binary 1111111111111111, or — 1.
NOT 0= —-1 The bit complement of binary O to 16 places is sixteen ones (1111111111111111)
or —1. Also NOT —1=0.
NOT X NOT X is equal to —(X + 1). This is because to form the sixteen bit two's
complement of the binary, you take the bit {one’s) complement and add one.
NOT 1=-2 The sixteen bit complement of 1 is 1111111111111110, which is equal to — (1 +1)
or —2.
D-3
RULES FOR EVALUATING EXPRESSIONS
Rules for Evaluating Expressions:
1. Operations of higher precedence are performed before operations of lower precedence. This means the
multiplications and divisions are performed before additions and subtracions. As an example,
2 + 10/5 equals 4, not 2.4. When operations of equal precedence are found in a formula, the left-hand one
is executed first: 6—3+5=8, not —2,
2. The order in which operations are performed can always be specified explicitiy through the use of
parentheses. For instance, to add 5 to 3 and then divide that by 4, we would use (6+ 3), \ which eqals 2.
If, instead, we had used 5+ 3/4, we would get 5.75 as a result (5 plus 3/4).
The precedence of operators used in evaluating expressions is as follows, in order beginning with the
highest precedence: (Note: Operators listed on the same line have the same precedence).
1) FORMULAS ENCLOSED IN PARENTHESIS ARE ALWAYS EVALUATED FIRST
2) t EXPONENTATION
3) NEGATION — X WHERE X MAY BE A FORMULA
4) * } MULTIPLICATION AND DIVISION
5) + — ADDITION AND SUBTRACTION
6) RELATIONAL OPERATORS: = EQUAL
<> NOT EQUAL
(equal precedence + LESS THAN
for all six). > GREATER THAN
<= LESS THAN OR EQUAL
>= GREATER THAN OR EQUAL
7) NOT LOGICAL AND BITWISE “NOT” LIKE NEGATION, NOT TAKES ONLY THE FORMULA TO
ITS RIGHT AS AN ARGUMENT
8) AND LOGICAL AND BITWISE “AND”
9) OR LOGICAL AND BITWISE “OR”
D-4
Appendix E
SPACE HINTS
In order to make your program smaller and save space, the following hints may be useful.
1) Use multiple statements per line. There is a small amount of overhead. (5 bytes) associated with each
line in the program. Two of these five bytes contain the line number of the line in binary. This means that
no matter how many digits you have in your line number (minimum line number is 0, maximum is 63999) it
takes the same number of bytes. Putting as many statements as possible in a line will cut down on the
number of bytes used by your program.
2) Delete all unnecessary spaces from your program. For instance:
10 PRINT X, Y, Z
uses three more bytes than
10 PRINTX,Y,Z
Note: All spaces between the line number and the first non-blank character are ignored.
3) Delete all REM statements. Each REM statement uses at least one byte plus the number of bytes in the
text. For instance, the statement 130 REM THIS IS A COMMENT uses up 24 bytes of memory.
In the statement 140 X =X + Y:REM UPDATE SUM, the REM uses 14 bytes of memory including the colon
before the REM.
4) Use variables instead of constants. Suppose you use the constant 1.02369 ten times in your program.
H you insert a statement
10Q = 1.02369
in the program, and use Q instead of 1.02369 each time it is needed, you will save 40 bytes. This will also
result in a speed improvement.
5) A program need not end with an END; so, an END statement at the end of a program may be deleted.
6) Re-use the same variables. If you have a variable T which is used to hold a temporary result in one part
of the program and you need a temporary variable later in your program, use it again. Or, if you are asking
the terminal user to give a YES or NO answer to two different questions at two ditferent times during the
execution of the program, use the same temporary variable A$ to store the reply.
7) Use GOSUB’s to execute sections of program statemnts that perform identical actions.
8) Use the zero elements of matrices; for instance, A(O), B(O,X)
SPEED HINTS
The hints below should improve the execution time of your BASIC program. Note that some of these hints
are the same as those used to decrease the space used by your programs. This means that in many cases
you can increase the efficiency of both the speed and size of your programs at the same time.
1) Delete all unnecessary spaces and REM'’s from the program. This may cause a small decrease in
execution time because BASIC would otherwise have to ignore or skip over spaces and REM statements.
2) THIS 1S PROBABLY THE MOST IMPORTANT SPEED HINT BY A FACTOR OF 10. Use variables instead
of constants. It takes more time to convert a constant to its floating point representation than it does to
fetch the value of a simple or matrix variable. This is especially important within FOR...NEXT loops or
other code that is executed repeatedly.
E-1
3) Order your definitions of variables carefully. Variables which are encountered first during the execution
of a BASIC program are allocated at the start of the variable table. This means that a statement such as
5 À =O:B = A:C = À, will place À first, B second, and C third in the symbol täble (assuming line 5 is the
first statement executed in the program). Later in the program, when BASIC finds a reference to the
variable A,it will search only one entry in the symbol table to find À, two entries to find B and three entries
to find C, etc.
4) Use NEXT statements without the index variable. NEXT is somewhat faster than NEXT J because no
check is made to see if the variable specified in the NEXT is the same variable in the most recent FOR
statement.
Е-2
Appendix F
MAIN LOGIC ASSEMBLY PARTS CROSS REFERENCE
REF. DES.
C1,C2,C14
C3
Ca
C5,611,012,013
C6
C7-C10
C15-C49
CR1,CR2,CR3
DS1
JS
J7
J8
Q1,04
Q2,Q5
Q3,Q6
R1,R4
R2,R6,R12,R13,R14
R18-R25
R3,R5,R26-R46
R7,R8,R9
R10
R11
R15,R16
R17
UA1,UB5,UC9
UA?
UA?
UAS
UA7,UA8,UA9
UB1,UEB,UE9
UB2
UB3,UB4,UG5,UGE,
UH8,UH9
UB6,UC5,UC7,UC8, UD5
UB8,UGB8
UCA
UC2,UD8,UG3
UC3,UCa,U11-U18
UJ1,UJ8
DESCRIPTION
- .O1MF 100Y Ceramic
82 pF 500V Ceramic
10pF 500V Ceramic
1.O0MF 25V Tantalum
AMF 50V Ceramic
47MF 16V Electrolytic
AMF 10V Ceramic
IN5402 3A/200V
LED Indicator
20 Pin Header (Molex)
7 Pin Header (Molex)
5 Pin Header (Molex)
TIP 29
2N 4401
2N 3904
1.5K 1/4W 5%
10k 1/4W 5%
10K 1/4W 5%
1K 1/4W 5%
470 1/4W 15%
2.4kK 1/4W 5%
5.1K 1/4W 5%
IM 1/4W 5%
3.3K 1/4W 5%
741.583 Counter
6540-010 MOS Char. Gen.
23168-08 Char Gen.
6522 VIA
MC 3446 Interface Bus
74L520 Nand Gate
741. 5165 Shift Reg.
741.5244 Buffer
74L5107 Flip-Flop
6520 PIA
74.574 Flip-Flop
74LS00 Nand Gate
6550 RAM
F-1
PART NO.
900010-38
900010-40
900010-35
900402-13
900010-20
900100-33
900010-39
900753-01
900701-01
903307-02
903307-02
903302-02
902653-01
902652-01
902658-01
901550-69
901550-20
901550-20
901550-01
901550-58
901550-85
901550-03
901550-84
901550-02
901521-07
901439-08
901447-08
901437-01
901524-01
901521-04
901521-12
901521-13
901521-08
901436-01
901521-06
901521-01
901438-01
UC3,UC4,U11-U18
UJ',UJE
UC6,UE?
UD2,UD3,UD4
UD6,UD7
UD9,UES
UDES9
UE3,UE4
UEG
UF3
UG?
UG4
UGS
UH1
UH1
UH2
UH?
UM3
UH3
UHA
UH4
UH5
UHS
UH6
UH6
UH?
UH7
UA2,UH1-UH7
UA2,UH1-UH7
UAS UBS, UF3,UG8
UC3,UC4,UJ1-UJ8,U11-U18
2114, НАМ
741-508
741. 5157 Data Sel
74177 Counter
74L504 Hex Inv
LM555 Timer
7417 Hex Bufter
74100 Latch
6502 MPU
741.5154 Decoder
74LS21 And Gate
74L5145
6540-011 ROM
2316B-01 ROM
6540-013 ROM
2316B-03 ROM
6540-015 ROM
2316-B-05 ROM
6540-016 ROM
2316B-06 ROM
6540-012 ROM
2316B-02 ROM
6540-014 ROM
2316B-04 ROM
6540-018 ROM
2318B-07 ROM
Socket28 PIN
Socket 24PIN
Socket 40PIN
Socket 22PIN
F-2
901453-01
901521-03
901521-11
901522-03
901521-02
901523-01
90152201
901522-02
901435-01
801521-10
901521-05
901521-09
901439-01
901447-01
901439-02
901447-03
801439-03
901447-05
901439-04
901447-06
901439-05
901447-02
901439-06
901446-04
901439-07
901446-07
904153-05
904153-04
904153-06
904153-03
Appendix G
SUGGESTED READING wsa produced)
Entering BASIC. J.Sack and J. Meadows. Science Research Associates,1973
BASIC:A Computer Programming Language. C. Pegels, Holden-Day, Inc. 1973
BASIC Programming. J. Kemeny and T. Kurtz, Peoples Computer Co., 1010 Doyle(P.O.Box 3100),
Menlo Park, Ca 94025, 1967
BASIC. Albrecht, Finkle and Brown. Peoples Computer Co., 1010 Doyle(P.Q.Box 3100), Menlo Park,
Ca 94025, 1973
A Guided Tour of Computer Programming in BASIC. T. Dwyer, Houghton Mifflin Co., 1973
Programming Time Shared Computer in BASIC. Eugene H. Barnett. Wiley-Interscience LIC 72-175789
($12.00)
Programming Language #2. Digital Equipment Corp., Maynard, MA 01754
101 BASIC Computer Games. Software Distribution Center. Digital Equipment Corp., Maynard,
MAO1754 ($7.50)
What to Do After You Hit Return. Peoples Computer Co., 1010 Doyle(P.O.Box 310),
Menlo Park, Ca 94025 ($6.95)
Basic BASIC. James S. Coan, Hyden Book Co., Rochelle Park, NJ
WORKBOOKS 1-5, T. 1. S., P.O.Box 921, Los Almos, NM 87544
G-1
Commótóre Business Machines, Inc.
901 California Avenue
Palo Alto, California 94304, USA
Commodore/MOS
Valley Forge Corporate Center
950 Rittenhouse Road
Norristown, Pennsylvania 19401, USA
Commodore Business Machines Limited
3370 Pharmacy Avenue
Agincourt, Ontario, Canada MiW2K4
Commodore Business Machines (UK) Limited
360 Euston Road
London NW1 3BL, England
Commodore Buromaschinen GmbH
Frankfurter Strasse 171-175
6078 Neu isenburg
West Germany
Commodore Japan Limited
Taisei-Denshi Building
8-14 ikue 1-ChomeAsahi-Ku, Osaka 535, Japan
Commodore Electronics (Hong Kong) Ltd.
Watsons Estates
Block CG, 11th floor
Hong Kong, Hong Kong
4
">
/
广告