Radio Shack Hardware Manual Color Computer Disk System Owners 1981 Tandy Text

User Manual: manual pdf -FilePursuit

Open the PDF directly: View PDF PDF.
Page Count: 104 [warning: Documents this large are best viewed by clicking the View PDF Link!]

Radio /haeK
O©MMS
©©MPonnsiR
Owners Manual &Programming Guide
CUSTOM MANUFACTURED IN U.S.A. BY RADIO SHACK, ADIVISION OF TANDY CORPORATION
Important Notice: Your computer must be off when you connect the
disk interface. Otherwise, you could damage the system.
"wwSgS^fij^lsSwwwSjgji^
TERMS AND CONDITIONS OF SALE AND LICENSE OF RADIO SHACK COMPUTER EQUIPMENT AND SOFTWARE
PURCHASED FROM ARADIO SHACK COMPANY-OWNED COMPUTER CENTER. RETAIL STORE OR FROM A
RADIO SHACK FRANCHISEE OR DEALER AT ITS AUTHORIZED LOCATION
LIMITED WARRANTY
CUSTOMER OBLIGATIONS
A. CUSTOMER assumes full responsibility that this Radio Shack computer hardware purchased (the "Equipment"), and any copies ot Radio
Shack software included with the Equipment or licensed separately (the "Software") meets the specifications, capacity, capabilities,
versatility, and other requirements of CUSTOMER.
BCUSTOMER assumes full responsibility for the condition and effectiveness of the operating environment in which the Equipment and Software
are to function, and for its installation
II. RADIO SHACK LIMITED WARRANTIES AND CONDITIONS OF SALE
A. For aperiod of ninety (90) calendar days from the date of the Radio Shack sales document received upon purchase of the Equipment, RADIO
SHACK warrants to the original CUSTOMER that the Equipment and the medium upon which the Software is stored is free from manufacturing
defects. THIS WARRANTY IS ONLY APPLICABLE TO PURCHASES OF RADIO SHACK EQUIPMENT BY THE ORIGINAL CUSTOMER FROM
RADIO SHACK COMPANY-OWNED COMPUTER CENTERS, RETAIL STORES AND FROM RADIO SHACK FRANCHISEES AND DEALERS AT ITS
AUTHORIZED LOCATION. The warranty is void if the Equipment's case or cabinet has been opened, or if the Equipment or Software has been
subjected to improper or abnormal use. If amanufacturing defect is discovered during the stated warranty period, the defective Equipment
must be returned to aRadio Shack Computer Center, aRadio Shack retail store, participating Radio Shack franchisee or Radio Shack dealer
for repair, along with acopy of the sales document or lease agreement The original CUSTOMER'S sole and exclusive remedy in the event of
adefect is limited to the correction of the defect by repair, replacement, or refund of the purchase price, at RADIO SHACK'S election and sole
expense. RADIO SHACK has no obligation to replace or repair expendable items.
B. RADIO SHACK makes no warranty as to the design, capability, capacity, or suitability for use of the Software, except as provided in this
paragraph. Software is licensed on an "AS IS" basis, without warranty. The original CUSTOMER'S exclusive remedy, in the event of a
Software manufacturing defect, is its repair or replacement within thirty (30) calendar days of the date of the Radio Shack sales document
received upon license of the Software, The defective Software shall be returned to aRadio Shack Computer Center, aRadio Shack retail store,
participating Radio Shack franchisee or Radio Shack dealer along with the sales document.
C. Except as provided herein no employee, agent, franchisee, dealer or other person is authorized to give any warranties of any nature on behalf
of RADIO SHACK.
D. Except as provided herein, RADIO SHACK MAKES NO WARRANTIES, INCLUDING WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A
PARTICULAR PURPOSE.
E. Some states do not allow limitations on how long an implied warranty lasts, so the above limitation(s) may not apply to CUSTOMER.
III. LIMITATION OF LIABILITY
A. EXCEPT AS PROVIDED HEREIN, RADIO SHACK SHALL HAVE NO LIABILITY OR RESPONSIBILITY TO CUSTOMER OR ANY OTHER PERSON
OR ENTITY WITH RESPECT TO ANY LIABILITY, LOSS OR DAMAGE CAUSED OR ALLEGED TO BE CAUSED DIRECTLY OR INDIRECTLY BY
"EQUIPMENT" OR "SOFTWARE" SOLD, LEASED, LICENSED OR FURNISHED BY RADIO SHACK, INCLUDING, BUT NOT LIMITED TO. ANY
INTERRUPTION OF SERVICE, LOSS OF BUSINESS OR ANTICIPATORY PROFITS OR CONSEQUENTIAL DAMAGES RESULTING FROM THE
USE OR OPERATION OF THE "EQUIPMENT" OR "SOFTWARE". IN NO EVENT SHALL RADIO SHACK BE LIABLE FOR LOSS OF PROFITS, OR
ANY INDIRECT, SPECIAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF ANY BREACH OF THIS WARRANTY OR IN ANY MANNER
ARISING OUT OF OR CONNECTED WITH THE SALE, LEASE, LICENSE, USE OR ANTICIPATED USE OF THE "EQUIPMENT" OR "SOFTWARE".
NOTWITHSTANDING THE ABOVE LIMITATIONS AND WARRANTIES, RADIO SHACK'S LIABILITY HEREUNDER FOR DAMAGES INCURRED BY
CUSTOMER OR OTHERS SHALL NOT EXCEED THE AMOUNT PAID BY CUSTOMER FOR THE PARTICULAR "EQUIPMENT" OR "SOFTWARE"
INVOLVED.
B. RADIO SHACK shall not be liable for any damages caused by delay in delivering or furnishing Equipment and/or Software.
C. No action arising out of any claimed breach of this Warranty or transactions under this Warranty may be brought more than two (2) years
after the cause of action has accrued or more than four (4) years after the date of the Radio Shack sales document for the Equipment or
Software, whichever first occurs.
D. Some states do not allow the limitation or exclusion of incidental or consequential damages, so the above limitation(s) or exclusion(s) may
not apply to CUSTOMER.
IV. RADIO SHACK SOFTWARE LICENSE
RADIO SHACK grants to CUSTOMER anon-exclusive, paid-up license to use the RADIO SHACK Software on one computer, subject to the following
provisions:
A. Except as otherwise provided in this Software License, applicable copyright laws shall apply to the Software.
B. Title to the medium on which the Software is recorded (cassette and/or diskette) or stored (ROM) is transferred to CUSTOMER, but not title to
the Software.
C. CUSTOMER may use Software on one host computer and access that Software through one or more terminals if the Software permits this
function.
D. CUSTOMER shall not use, make, manufacture, or reproduce copies of Software except for use on one computer and as is specifically
provided in this Software License. Customer is expressly prohibited from disassembling the Software.
E. CUSTOMER is permitted to make additional copies of the Software only for backup or archival purposes or if additional copies are required in
the operation of one computer with the Software, but only to the extent the Software allows abackup copy to be made. However, for
TRSDOS Software, CUSTOMER is permitted to make alimited number of additional copies for CUSTOMER'S own use.
F. CUSTOMER may resell or distribute unmodified copies of the Software provided CUSTOMER has purchased one copy of the Software for each
one sold or distributed. The provisions of this Software License shall also be applicable to third parties receiving copies of the Software from
CUSTOMER.
G. All copyright notices shall be retained on all copies of the Software.
V. APPLICABILITY OF WARRANTY
A. The terms and conditions of this Warranty are applicable as between RADIO SHACK and CUSTOMER to either asale of the Equipment and/or
Software License to CUSTOMER or to atransaction whereby RADIO SHACK sells or conveys such Equipment to athird party for lease to
CUSTOMER.
B. The limitations of liability and Warranty provisions herein shall inure to the benefit of RADIO SHACK, the author, owner and/or licensor of the
Software and any manufacturer of the Equipment sold by RADIO SHACK.
VI. STATE LAW RIGHTS
The warranties granted herein give the original CUSTOMER specific legal rights, and the original CUSTOMER may have other rights which vary
from state to state.
WW®
"Una m%
I
•Ji.\&H
a
£•?•»: :•'•:•;
The FCC wants you to know:
This equipment generates and uses radio frequency energy. If it is not installed and used properly,
that is, in strict accordance with the manufacturer's instructions, it may cause interference to radio
and television reception. It has been type tested and found to comply with the limits for aClass B
computing device in accordance with the specifications in Subpart Jof Part 15 of FCC Rules, which
are designed to provide reasonable protection against such interference in aresidential installa-
tion. However, there is no guarantee that interference will not occur in aparticular installation. If
this equipment does cause interference to radio or television reception, which can be determined by
turning the equipment off and on, the user is encouraged to try to correct the interference by one
or more of the following measures:
reorient the receiving antenna
relocate the computer with respect to the receiver
move the computer away from the receiver
plug the computer into adifferent outlet so that computer and receiver are on different branch
circuits.
If necessary, the user should consult the dealer or an experienced radio /television technician for
additional suggestions. The user may find the following booklet prepared by the Federal Commu-
nications Commission helpful: How to Identify and Resolve Radio-TV Interference Problems. This
booklet is available from the United States Government Printing Office, Washington, DC 20402,
Stock No. 004-000-0035-4.
TRS-80 Disk Extended Color
BASIC System Software: Copyright ©
1981 Tandy Corporation and Microsoft.
All rights reserved.
The system software in the disk system is retained in aread-only
memory (ROM) format. All portions of this system software,
whether in the ROM format or other source code format, and the
ROM circuitry, are copyrighted and are the proprietary and trade
secret information of Tandy Corporation and Microsoft. Use,
reproduction, or publication of any portion of this material, with-
out the prior written authorization by Tandy Corporation, is
strictly prohibited.
Color Computer Disk System:
Copyright ©1981 Tandy Corporation,
Fort Worth, Texas 76102, U.S.A.
All rights reserved.
Reproduction or use, without express written permission from
Tandy Corporation, of any portion of this manual, is prohibited.
While reasonable efforts have been taken in the preparation of the
manual to assure its accuracy, Tandy Corporation assumes no
liability resulting from any errors or omissions in this manual or
from the use of the information obtained herein.
Printed in the United States of America
10 98765432
WHYADISKIS FAST
Adisk is for storing your information. The precise
term for it is a"mini-diskette," but in this book we'll
just call it adisk. It is far superior to tape, the other
alternative.
Adisk is especially designed to "file" your infor-
mation so the Computer can immediately get the
information you want. For you, this means storing
and retrieving information which takes along
time on tape now can be done quickly and
efficiently.
ABOUT THIS BOOK
This book shows how to read and write on adisk. When
we wrote it, we had three different groups of people in
mind.
The first group includes all of you accomplished Radio
Shack programmers. We are referring, of course, to
those of you who learned to program by reading Getting
Started with Color BASIC and Going Ahead with
Extended Color BASIC. You'll find Sections Iand II of
this book another delightful experience. If you're espe-
cially ambitious, you'll also enjoy Section III.
How about those of you who have never programmed
and intend to use application programs written by
Radio Shack or someone else? You're the second
group. Read Chapter 1, "To Get Started." Then, if you're
interested in and want to take full advantage of your
disk system, go on to Section I, "The Disk." You don't
need to know anything about programming to under-
stand it.
If you don't belong to either of these two groups, you
probably already know how to program disk systems.
Read Chapter 1first to find out how to connect your sys-
tem. Then, go straight to the "BASIC Summary" at the
end of the book. Everything is summarized there with
page number references, for the things you want to read
more about.
TABLE OF CONTENTS
Chapter II To Get Started 1
SECTION I. The Disk
Chapter 21 Meet Your Disk 7
Chapter 31 AGarbled Up Disk 13
Chapter 41 You're the Boss 19
SECTION II. The Disk Program
Chapter 51 One Thing at aTime 25
(Sequential Access to aFile)
Chapter 61 Changing It All Around 29
(Updating aSequential Access File)
Chapter 71 AMore Direct Approach 33
(Direct Access to aFile)
SECTION III. The Refined Disk Program
Chapter 81 How Much Can One Disk Hold? 41
(What the Computer Writes in aDisk File)
Chapter 91 Trimming the Fat Out of Direct Access 47
(Formatting aDirect Access File)
Chapter 101 Shuffling Disk Files 53
(Merging Programs, Using Many File Buffers)
Chapter 111 Technical Information 57
(Machine-Language Input/Output)
Appendixes
Appendix Al Programming Exercise Answers 64
Appendix Bl Chapter Checkpoint Answers 66
Appendix CI Sample Programs 68
Appendix Dl ASCII Character Codes 79
Appendix El Memory Map 81
Appendix Fl Specifications 82
Appendix Gl Error Messages 83
Appendix HI BASIC Summary 85
i
TO GET STARTED
Before you install your Disk System, you need to
connect your Color Computer to the T.V. If you
haven't done it yet, refer to the Color Computer
Operation Manual.
A. CONNECT DISK SYSTEM
Your Disk System is easy to connect. Do it
before you turn on your Computer by simply
plugging in all the parts:
Note: the dotted lines represent tke connection of additional add-on drive
TO GET STARTED
1. Connect the Disk Interface to the plug
in the opening of your Computer.
IMPORTANT NOTICE: YOUR COM-
PUTER MUST BE OFF WHEN YOU
CONNECT THE DISK INTERFACE.
OTHERWISE, YOU COULD DAMAGE
THE SYSTEM.
2. Connect Plug Aof the Disk Cable to the
Disk Interface.
B
Connect Plug Bof your Disk Cable to
the plug on back of your Disk Drive.
Plug in the power cord to astandard
(120 V) electrical outlet.
If You Have Additional
Disk Drives
If you have more than one disk drive, do
step 3differently. Connect the 26-3023
Drive to the inside plug (Plug B). If you
have more 26-3023 Drives and an expanded
cable, connect these Drives to inside plugs
also. The 26-3029 Drive must be connected
to the last plug in the series.
You'll also need to number your Drives.
Number them from the inside out. starting
with Drive 0. The Drive connected to Plug
Bis drive number 0, the Drive connected to
Plug Cis drive number 1,etc.
B. POWER IT UP
Since your Disk System has several parts, you
need to turn ON several buttons to power-up
the entire system;
Turn ON your television set.
Select Channel 3or 4.
Set the antenna switch on the TV. to
COMPUTER.
Turn ON the Computer. (The power but-
ton is on the back left-hand side of your
keyboard.)
TO GET STARTED
Turn ON the Disk Drives. (The power
buttons are on the rear.)
Have you turned ON all the buttons? This
message should appear on your screen:
DISK EXTENDED COLOR BASIC v.r,
COPYRIGHT (C) 1981 BY TANDY
UNDER LICENSE FROM MICROSOFT
(v.r, is two numbers specifying which version
and release you have.)
If not, turn off the Computer, check your con-
nections, and power it up again.
C. INSERT ADISK
After powering the system up, you can insert
adisk. If you plan to go through Section I, use
the blank, unformatted disk which comes
with your disk system. Otherwise, you can
insert your "application program" disk, (If
you have more than one drive, insert, the disk
in drive 0).
^
Open the DRIVE DOOR.
Position the disk with the notch on top,
as we show in the picture above.
Gently insert the disk until it stops-
Close the DRIVE DOOR.
Note: You cannot use ablank disk until you "format"
it. The next chapter shows how.
Now that your system is connected and powered-
up, you're ready to begin. Begin what? Well, if you
want to know how to take full advantage of your
disk system, we'd like you to read Section I. You'll
find alot of helpful information there.
If you're in ahurry to run your application pro-
gram, that's O.K., too. But please read these
guidelines first. We want your disks to last along
time.
When storing the disk, keep it in its storage
envelope
Do not turn the system ON or OFF with the
disk in the drive.
Keep disks away from magnetic fields
(transformers, AC motors, magnets, TVs,
radios, etc.)
Handle disks by the jacket only. Don't touch
any of the exposed surfaces, even to dust
them.
Keep disks out of direct sunlight and away
from heat.
Avoid contamination of disks with cigarette
ashes, dust, or other particles.
Use afelt-tipped pen only to write on the
disk label.
Store disks upright in avertical file.
Note: Your disk drives should be on the right side of
your television set.
IMPORTANT NOTE!
If you have an earlier model of the Color Computer, the disk system might cause
interference on your screen. If so, bring the computer to aRadio Shack Repair
Center for additional grounding connections. (There will be no charge for this
service.)
SECTION I
TMH2 BMK
Adisk is like afiling system. Everything on it is
organized.
This makes disks easy to work with. In this section,
we'll show you how your Computer organizes
everything on your disk, and how you can take
advantage of this.
We invite all of you to read this section. You don't
need to know anything about computers to under-
stand it.
MEET YOUR DISK
ALOOK INSIDE OF IT
Although your disk looks like arecord, it is really
more like amultitude of tiny magnets. One disk
can hold more than amillion magnetic charges.
1,290,240 of them are for your information. That's
what we mean when we say adisk will hold
1,290,240 bits or 161,280 bytes of information
(there are eight bits in abyte).
Some of these bits are magnetically charged and
some aren't. The pattern formed by these mag-
netic charges is what's important. It forms a code
which the Computer can read.
With more than amillion of these bits on adisk,
you can appreciate how your Computer must orga-
nize them in order to find anything. It does this by
building amassive disk filing system. First it cre-
ates the file cabinets by dividing your disk into
"tracks." Then it puts drawers in the cabinets by
dividing each track into "sectors" Then ...we're
not finished yet .. . each sector is divided into bytes
and each byte is divided into bits.
Note: To be precise, there are 35 tracks on adisk, 18
sectors in each track, 256 bytes in each sector, and 8
bits in each byte.
;
After creating this filing system, the Computer
puts amaster directory on the disk. There, it
indexes where everything is stored. Whenever it
wants to find something aprogram, amailing
list, your letters it uses the directory to find the
tracks and sectors where it is stored. It can then
go directly to that spot.
This whole filing system is, of course, what makes
the disk system so powerful. You can quickly find
anything you have stored on your disk.
Putting this filing system on your disk is called
"formatting" it. The last thing we had you do in
Chapter 1was to insert an "unformatted" disk.
Before you can use it, you must format it into
tracks and sectors.
FORMATTING ADISK
How do you format adisk? Well .. . why not just tell
your Computer to do it? If you went through the
MEET YOUR OISK
instructions in the last chapter, you have already
powered-up your system and inserted an "unfor-
matted" disk. Be sure you have your DRIVE
DOOR closed.
Now, type any letters and press the (ENTER) key so
that:
OK
is the last line on your screen. (OK means "OK,
I'm ready to do something") Now type what you
want it to do. Type:
DSKINI0
and press the CENTER) key. Your Computer might
print ?SN ERROR. If so, don't let this bother you.
This "error" simply means you typed the com-
mand incorrectly. Type it again.
Whenever anything goes wrong, the Computer
will let you know immediately with an error mes-
sage. This way you can correct the error right
away. If you get any other error message besides
SN, look it up in Appendix G. It lists all the error
messages and what to do about them.
After typing DSKINI0 (ENTER), you'll hear some
noises from your disk drive and its red light will
come on. Sounds promising . .
.
After about 40 seconds of noises, your Computer
will then print OK. It has finished formatting the
disk. You can now store your information.
Remember that you cannot store anything on an
unformatted disk. Whenever you get anew, unfor-
matted disk, you need to format it before you can
use it.
Later on, you might not remember if adisk has
been formatted. Aquick way to find out is to check
the directory. (See "Checking the Master Direc-
tory" at the end of this Chapter.) If you get an
"error message'' the disk is not formatted.
Note: It does no harm to reformat a disk. Thin
common way to erase everything on it.
If you have more than one disk drive, you can for-
mat adisk in one of the other drives by substitut-
ing the appropriate drive number for drive 0. For
example, DSKINI1 formats the disk in drive 1.
PUTTING AFILE ON YOUR DISK
Adisk file can contain any kind of information
aprogram, amailing list, an essay, some checks.
We'll make your first file contain aBASIC pro-
gram, since it's the simplest thing to store.
If you don't know how to program in BASIC, type
this program anyway. Type each line exactly as it
is shown below. Press the (ENTER) key after typing
each line. Type:
10 PRINT "STORE ME IN ADISK FILE" (ENTER)
20 PRINT "AND YOU'LL NEUER LOSE ME" (ENTER]
Finished? Now that you've typed the program into
your Computer's "memory," you can put it on a
disk. To do this, we'll call it afile and name the file
"SIMPLE/PRO" (all files have aname). To store it,
type:
SAME "SIMPLE/PRO" [ENTER)
Once you press the (ENTER) key, your disk drive will
whirr and grind some and the red light on it will
come on. Your Computer is:
finding aplace on the disk to store "SIMPLE/
PRO"
telling the directory where "SIMPLE/PRO" will
be stored.
storing "SIMPLE/PRO" on your disk.
Note: The Computerstores "SIMPLEPRO" the same
way it stores everything else in a code of magnetic
charges.
At this point, we must warn you about something.
Do not remove your disk while you see the red
light on. This confuses the Computer. It might dis-
tort the contents, not only of the file you are pres-
ently storing, but of other things you have stored
on the disk.
When your Computer finishes storing "SIMPLE/
PRO," it prints the OK message on your screen.
8
MEET YOUR DISK
Note: Upgrading your tape system? Note the differ-
ence: SAVE stores aprogram on disk; CSAVE stores
it on tape I
RUN CENTER)
MEMORY VS DISK STORAGE
To those of you new to computers, we would like to
expound alittle on computer "memory." If you
already know what it is, skip down to the next
heading "Loading aFile from Disk!'
Whenever you type aBASIC program line and
press (ENTER) ,the Computer automatically puts it
in its memory. Once it's in memory, you can do
things with it. For example, type:
RUN [INTER]
Your Computer PRINTs:
STORE ME IN ft DISK FILE
AND YOU'LL NEVER LOSE ME
To list the program as you have it above, type:
LIST dNTEFD
Memory is where the Computer keeps track of
everything you tell it. Once you put your infor-
mation in its memory, the Computer can print it,
rearrange it, combine it, or any of the other things
you want done with it.
Later on, you'll probably want to put other things,
such as your mailing list, in memory. To do this,
you'll need to write or purchase aprogram written
especially for that application. This "application
program" will get the Computer to put the infor-
mation you type into memory.
The important thing to remember about memory
is that turning off your Computer erases it. Once
memory has been erased, there's no way to recover
it. The only way to keep apermanent copy of what
you've typed into memory is by storing it on adisk
(or tape).
LIST [ENTER)
Although NEW erased the program from memory,
"SIMPLE/PRO" is still safely stored on your disk.
You can put "SIMPLE/PRO" back into memory
anytime you want by "loading" it from disk. To do
this, type LOAD "SIMPLE/PRO" [ENTER] .
Again, you'll hear some promising noises from
your disk drive. The Computer is:
reading the directory to find where "SIMPLE/
PRO" is stored.
going to that location on the disk and reading the
contents of "SIMPLE/PRO."
putting "SIMPLE/PRO" into its memory.
You can now type one or both of these commands
to verify that "SIMPLE/PRO" is in memory:
LIST (ENTER)
RUN (ENTER)
LOADING AFILE FROM DISK
Type NEW [ENTER) to erase everything in your Com-
puter's memory. To make sure everything's erased,
you can type one or both of these commands:
MORE ABOUT MEMORY VS DISK
STORAGE
If you're still alittle fuzzy about what's in memory
and what's on your disk, try this exercise. You've
9
MEET YOUR DISK
just LOADed aprogram called "SIMPLE/PRO"
into memory, right? Change it by typing:
20 PRINT "WITH THIS CHANGE" (ENTER]
LIST the program again to see that the Computer
has registered the changed line 20 in its memory:
10 PRINT "STORE ME IN ADISK FILE"
20 PRINT "WITH THIS CHANGE"
Store it in adifferent file by typing SAME
"CHANGE" [ENTER) ...
Hear the whirring and grinding from your disk
drive? You have two disk files now: "SIMPLE/
PRO" and "CHANGE" What do you think each of
them contains? Try LOADing and then LISTing
both of them.
[Note: You don't need to type NEW (EBTER] before LOAD-
ing anew program into memory. The Computer will
automatically erase everything you presently have in
memory before LOADing the new program.
??????????????????????????????????????????????????
"CHANGE" contains the changed program:
10 PRINT "STORE ME IN ADISK FILE"
20 PRINT "WITH THIS CHANGE"
However, "SIMPLE/PRO" still contains the old
program:
10 PRINT "STORE ME IN ADISK FILE"
20 PRINT "AND YOU'LL NEUER LOSE ME"
NEW [INTEH]
10 PRINT "CHANGED FILE" (ENTER]
SfliJE "SIMPLE/PRO" (ENTER)
FILENAMES
You have already used one filename:
"SIMPLE/PRO"
If you did our memory vs. disk storage exercise,
you've used asecond filename:
"CHANGE"
We gave the name "SIMPLE" an "extension"
"PRO." You must give everything you store a
name. The extension is up to you. It's optional.
What names can you give your files? Anything
you want, as long as you follow these rules:
1. The name may have no more than eight
characters.
2. If you give it an extension, the extension may
have no more than three characters.
3. There must be aslash (/) or aperiod (.) between
the name and the extension.
Fair enough? Good.
Note: You may use any characters in the filename
except acolon (:) or a zero (0). You can only use a
slash (I) or aperiod (.) to separate the name from th
extension.
The only way to change adisk file is by ...well,
you answer it. How can you make the file "SIM-
PLE/PRO" contain:
10 PRINT "CHANGED FILE"
??????????????????????????????????????????????????
Answer:
T>pe:
10
FILENAMES WHEN YOU HAVE
MORE THAN ONE DRIVE
If you have more than one disk drive, you can add
the drive number to your filename. (Remember,
you numbered all of your drives in Chapter 1), For
example:
LOAD "SIMPLE/PRO:!"
MEET YOUR DISK
LOADs "SIMPLE/PRO" from the disk in drive
number 1. Or
SAVE "CHANGE:1"
stores "CHANGE" on the disk in drive number 1.
If you don't include adrive number, the Computer
assumes you want it to use drive number 0.
CHECKING THE MASTER
DIRECTORY
As we've said earlier, adisk has amaster directory
which the Computer can use to find out what's on
the disk. If the Computer can use it, you can use
it, too. TypeDlR tEHTEH).
The Computer prints information on all the files
you have stored on your disk. If the only files
you've stored so far are "SIMPLE/PRO" and
"CHANGE," the Computer prints this:
SIMPLE
CHANGE
PRO
BAS
The first and second columns list the filename.
The first is the name and the second is the exten-
sion. Notice that even though you did not assign
"CHANGE" an extension when you stored it, the
Computer still assigned it the extension "BAS."
The Computer prefers for all filenames to have an
extension. If you do not give a file an extension
when you store it, the Computer will automati-
cally assign one of these extensions:
"BAS" if it's aBASIC program
"DAT" if it's data (such as names, numbers, etc.)
"BIN" if it's amachine-language program)
Note: Amachine-language program is ahighly tech-
nical program which talks directly to the Computer.
The next three columns contain information
which is primarily for the use of technical pro-
grammers. Interested? Then read on ..
.
The third column lists the type of file it is:
BASIC program
1data created by aBASIC program
2data created by amachine-language program
3asource program created by an editor/
assembler
Note: An eriitnrtasxembler ix aprogram you can buy
to help you create amachine-language program.
The fourth column lists the format the file is
stored in:
AASCII
BBinary
We'll explain the meaning of this in Chapter 10.
The fifth column shows how many "granules" each
file consumes. "SIMPLE/PRO" and "CHANGE/
BAS" consume one granule each. (The Computer
uses "granules" to allocate file space on adisk. A
disk contains 68 of these "granules").
If you have disks inserted and formatted in other
drives, you can check their directories also. For
instance DIRl fjNTEl) displays the directory of the
disk in drive number 1.
Impressed? You'll be even more impressed when
you see how fast you can SAVE and LOAD long
programs. But before you get too involved, please
read the next chapter. It'll help ensure that your
experience with your Disk System is smooth and
enjoyable.
Note: To stop the directory from scrolling, press the
SHIFT) and (W) keys simultaneously. Then press
MB®.
CHAPTER CHECKPOINT
1. Why can't you store things on an unformat-
ted disk?
2. What is the disk's directory?
3. What is adisk Sle?
4. What is the difference between what's in
memory and what's on the disk?
5. How do you change the contents of adisk
Sie?
Do you like quizzes? The answers are in
Appendix B.
11
AGARBLED UP DISK
With more than amillion magnetic charges on a
disk, you can see why it is so delicate. Any small
particle such as a piece of dust or acigarette ash
could distort its contents. Ascratch could ruin it.
That's why we suggest that you keep the disk in
its envelope when you're not using it preferably
upright in adust-free container and only use a
felt-tipped pen when labeling it.
To help protect the disk, we encased most of it in
ablack plastic container. However, as you can see,
we weren't able to cover the entire disk. The mid-
dle section and two other small areas are exposed
so the Computer can read and write to it. Be care-
ful not to touch the exposed areas, not even to dust
them. They scratch very easily.
Since the disk is made up of magnetic charges,
putting it next to another magnetic device, such as
your television set, could completely rearrange its
magnetic code. Your information would be lost.
Heat and sunlight could have the same effect. The
same goes for turning your Computer ON or OFF
while the disk is in its drive.
One more thing ... If you're in the middle of run-
ning adisk program, and need to switch disks, we
recommend that you type this command:
UNLOAD fIRTER)
before you switch disks. This way the Computer
can put its closing information on the proper disk.
If you don't type this command, the Computer
might put this information on the wrong disk and
garble the contents of both disks.
:
Note for BASIC programmers;All open files must
be closed before switching disks, UNLOAD closes al,
open files.
'
BACK IT UP
All of this might sound alittle gloomy to you, even
if you are a careful person. This is why we've
included acommand called BACKUP. BACKUP
will enable you to make aduplicate or "backup"
copy of any of your disks by copying the contents
of one disk to another.
13
AGARGLED UP DISK
We suggest you regularly make abackup copy of
any disk which contains important programs or
data. This way you won't have to worry about los-
ing them.
Also, since adisk can actually get worn out from
too much use, it's agood idea to make abackup
copy of an old disk on anew, unused disk. Then,
when the Computer begins having its problems
reading and writing to the disk, you can use your
backup copy.
Want to make abackup copy? Get your two disks
ready:
1. Your "source" disk This is the disk you want
to duplicate. Use any disk which has files stored
on it. If you're just getting started, use the disk
which you worked with in Chapter 2.
2. Your "destination" disk This is the disk which
you want to be your duplicate copy. Use ablank
disk or, if you've been using your disk system
for awhile, use any disk which contains files
you won't need anymore.
After making some noise while it reads aportion
of your "source" disk, the Computer will print:
\'ote:Everything preciously on your destination dish
it- ill be erased. It will be replaced with all the data i
your source disk.
If your "destination" disk is blank, you must
first format it. Remember how? Insert it in your
disk drive, shut the door, and type DSKINio
CENTER) .
Now make the backup copy. The procedure you fol-
low depends on whether you have one disk drive
or several.
Backup with One Disk Drive
If you have only one disk drive, it will take you
about five minutes to make abackup copy. Insert
your "source" disk in your disk drive and shut the
DRIVE DOOR. Type OIR (ENTER) to see which files
you will be copying.
Now start the backup procedures. Type:
INSERT DESTINATION DISKETTE AND PRESS CENTER;
Take the "source" disk out and insert the "desti-
nation" disk. Shut the DRIVE DOOR. Then press
(ENTER). You'll hear some more noise while the
Computer "writes" some things on the "destina-
tion" disk. Then it will print:
INSERT SOURCE DISKETTE AND PRESS CENTER)
The Computer will have you continue switching
disks until you have copied everything from your
source disk. During this process, make sure you
insert the correct disk and insert it properly. When
you've finished, the Computer will print the OK
message on your screen.
To make sure BACKUP worked, you can insert
your "destination" disk and type DIR(ENTER) .
Backup with More Than One Disk
Drive
If you have more than one disk drive, backing up
adisk is much easier. It will take about two
minutes.
Insert your "source" disk in drive and your "des-
tination" disk in drive 1(Chapter 1shows how to
label your drives). Then type:
BACKUP CENTER)
BACKUP TO i(ENTER)
You will hear some noise as the Computer backs
up the contents of the disk in drive to the disk in
drive 1. When it's finished, it will print the OK mes-
sage. You can then make sure BACKUP worked
by typing DIRi CENTER) .
You can use different drives, if you want. For
instance:
BACKUP 1TO (INTER)
backs up the contents of the disk in drive 1to the
one in drive 0.
14
AGARBLED UP DISK
If You have Problems During
Backup
If you get an error message while you're backing
up adisk, it's probably because you've inserted the
disk incorrectly or there is something wrong with
the disk. At the end of this chapter, we discuss
error messages to help you determine the prob-
lem. If you have abad disk, you will need to try
BACKUP with another disk.
After determining the problem, press the RESET
button to get out of BACKUP. Then start the
BACKUP procedure all over again.
I
Note: The RESET button is ore the right-hand rear
ofyour Computer (when you're facing it).
"WRITE" PROTECT IT
"Write-protecting" is one more way to protect your
disk files. Let's assume you have adisk which con-
tains some valuable information such as agood
program which you don't plan to change. You
plan to "read" its contents daily, by loading the
program into memory, yet you never plan to
"write" (store information) on it.
Putting alittle gummed label on the WRITE-
PROTECT NOTCH will enable the Computer to
read the disk, but not to write on it. Any gummed
label will do. There is one which comes with your
new, unformatted disk:
SALVAGE IT
We mentioned earlier that a disk doesn't live for-
ever. Before you throw away an old disk, though,
see if you can salvage it. You may be able to do this
by formatting it all over again as if it were ablank
disk.
Although this might salvage the disk, it will not
salvage the contents of the disk. By reformatting
the disk, you will erase everything on it. However,
it will save you the expense of purchasing anew
disk.
If you get an 10 error while trying to reformat it
(see "Error Messages" at the end of this chapter),
the disk has probably reached its limit. If you have
a"bulk-eraser," you can try "bulk-erasing" the
disk and reformatting it. Otherwise, throw it
away and use another one.
I
Note:Ifyou have more than one disk drive, you might
be able to COPY some of the files on a bad disk to a
good disk. We discuss COPY in the next chapter.
VERIFY IT
The Computer "writes" data on your disk at avery
fast speed. In almost all cases, it can do this
flawlessly.
There might be times when you want to be abso-
lutely certain that there are no flaws in what the
Computer is writing. If so, you can turn ON the
Computer's VERIFY command. To do this, type:
VERIFY ON (ENTER)
Now the Computer will notify you, whenever it is
writing on adisk, if there are any flaws in what it
is writing. The only catch is that it will take twice
as long for the Computer to write.
For example, let's assume you now make a
BACKUP copy of your disk. The Computer will
take twice as long doing this, but will notify you
if there is aflaw in the BACKUP copy.
This VERIFY command will remain ON until you
turn it off. To do this, type:
VERIFY OFF (ENTER)
15
AGARBLED UP DISK
WHEN THINGS GO WRONG
Your Computer realizes nobody's perfect. When
you make amistake, it'll try to notify you imme-
diately and tell you what kind of "error" you
made.
You've probably already been notified that you
made a"SN ERROR." If you haven't, type DIIR
[ENTER) deliberately mispelling DIR.
SN means "Syntax" error. It's the Computer's way
of telling you that "DIIR" doesn't make sense to it.
The word is not in its vocabulary. An SN error
usually means you made atypographical error.
Here are some other error messages you're likely
to get with your disk system:
AE You are trying to RENAME afile (discussed
in the next chapter) to afilename which
Already Exists.
DF The Disk you are trying to store your file on
is Full. Use another disk.
DN You are using aDrive Number higher than
3. You will also get this error if you do not
specify adrive number when using DSKINI
or BACKUP. If you have only one drive
specify drive with these two commands
(DSKINIO or BACKUP 0)
FN You used an unacceptable format to name
your file. The last Chapter explains which
File Names are acceptable to the Computer.
FS There is something wrong with your disk
file. See 10 for instructions on what to do.
/0 Technically, this means you have asked the
Computer to divide anumber by 0, which is
impossible. However, you might also get
this error when you don't enclose afilename
in quotation marks.
10 The Computer is having trouble Inputting
or Outputting information to the disk.
(1) Make sure there is adisk inserted
properly in the indicated drive and the
drive door is closed.
(2) If you still get this error, there might
be something wrong with your disk.
Try reinserting the disk first. Then try
using adifferent one or reformatting
it. (Remember that reformatting a
disk erases its contents.)
(3) If you still get this error, you probably
have aproblem with the Computer
System itself. Call the Radio Shack
Repair Center.
NE The Computer can't find the disk file you
want. Check the disk's directory to see if the
file is there. If you have more than one disk
drive, you might not have included the
appropriate drive number in the filename. If
you are using COPY, KILL, or RENAME
(discussed in the next chapter), you might
have left off the extension.
TM Technically this is caused by aprogram
which mixes "strings" with "numbers."
However, you might get this error if you
don't enclose afilename in quotation marks.
UF You will only get the error when you have
the VERIFY command ON and are writing
to adisk. The Computer is informing you
that there is aflaw in what it wrote. See 10
for instructions on what to do.
WPYou are trying to store information on adisk
which is Write Protected. Either take the
label off the write protect notch or use adif-
ferent disk. If your disk is not Write Pro-
tected, then there is an input/output prob-
lem. See 10 for instructions on what to do
about this.
All other errors you might get are errors in the
program you are using. If you did not write the
program and get one of these errors, you need to
contact the people who wrote it. If you did write it,
check Appendix G, where you'll find an explana-
tion of all the error messages.
16
AGARBLED UP DISK
Caring for your disk might seem alittle awkward
at first. It should. You've spent most of your life
protecting your papers and now you're dealing
with a different medium.
After awhile, though, protecting your disk from
dust and magnetic devices will seem as natural to
you as protecting your papers from a strong gust
of wind. And once you get used to keeping your
disk "ungarbled," you'll never want to go back to
pencils and paper again (we hope).
\Z CHAPTER CHECKPOINT
1. Why shouldn't you turn the Computer ON
or OFF while the disk is in its drive?
2. What type of pen can you use to write on
the disk's label?
3. What are error messages?
4. What does write-protect mean? How do
you do it?
5. How do you backup adisk?
17
YOU'RE THE BOSS
Thanks to your disk filing system, you are able to
command the Computer to do alot of very helpful
things. For example, you can rename afile. If
you've taken your formatted disk out, re-insert it.
Note: Can't remember if your disk's formatted?
Check the directory by typing DIB (EBBS) (or DIBB or
DIRi ifyou have more than one drive).
Type this to put afile on your disk:
10 PRINT "THIS IS AFILE" (ENTER)
SAVE "ORIGINAL/NAM" (ENTER)
Check the directory to see that the program file is
stored on your disk under the name ''ORIGINAL/
NAM" ...Now rename it. Type:
RENAME "ORIGINAL/NAM" TO "NEW/NAM" (ENTER)
Hear the disk drive working? Check your DIRec-
tory again. If you'd like, LOAD and LIST "NEW/
NAM." The program file has simply been renamed.
Everything else is the same.
RENAME is easy to use, but there is one thing you
need to remember. Save afile without an exten-
sion and then try to rename it. Type:
13 PRINT "FILE
IE "AFILE" (E
JAME "AFILE"
NUMESER TWO
BFILE"
'(ENTER)
Sfli NTER)
TO '
rei* (ENTER)
The Computer gives you an NE error. This means
the Computer can't find the file.
When you RENAME afile, you must type in the
complete name of the file so that the Computer can
find it. This includes the name and the extension.
As we discussed in Chapter 2, whenever you SAVE
afile the Computer will make sure it has an exten-
sion. If you don't assign it one, the Computer will.
You can check the directory to find out the exten-
sion of "AFILE." Then RENAME it. Type:
RENAME "AFILE/BAS" TO "BFILE/BAS" (ENTER)
If you're renaming aprogram file, be sure that
your new filename has an extension. In other
19
YOURE THE BOSS
words, don't type RENAME "AFILE/BAS" TO "BFILE"
[INTER) .The Computer would RENAME the file,
however "BFILE" would not have an extension.
This would cause aproblem when you try to
LOAD "BFILE," since all files you LOAD must
have an extension.
This might seem to conflict with what we said
above. You were able to SAVE "AFILE" without
assigning it an extension because the Computer
automatically assigned it one when it saved it.
RENAME works differently The Computer won't
automatically assign an extension to aprogram
you rename.
NotesThere is one way toLOAD "BFILE" wlthoutan
extension. This is by indicating that there Is no exten-
sion by typing LOAD "BFILE/" (ERIEE). This is awk-
ward. That's why we suggest, when renaming afile,
you always assign it an extension.
Multi-Disk Drives
You can RENAME afile on another disk drive,
simply by typing the appropriate drive number.
Insert a formatted disk in drive 1 {if it's not
already inserted). Store a file on it:
10 PRINT "ACCOUNTING" 1ENTER]
SAME "0LDACC/DAT:1" (INTER]
and RENAME it by typing:
RENAME "0LDACC/DAT:1" TO "NEWACC/DAT :1"
(enteB)
Nate: If you want your renamed file on adifferent
drive, you can't use RENAME. Use COPY. I
ALMOST OUT OF DISK SPACE?
Sooner or later, you'll want to know how much
space you have left on your disk. Type:
PRINT FREE(0) (ENTER]
The Computer prints the number of FREE "gran-
ules" remaining on your disk.
There are 68 granules in all. If the Computer tells
you that you have only one granule FREE, you'd
better do one of the following: start using another
disk or "KILL" some of your disk files.
KILLing adisk file does just what the name
implies. For example, if you put "CHANGE" on
your disk in Chapter 2, type:
KILL "CHANGE/BAS" (ENTER)
Check your directory and the FREE space remain-
ing on your disk. "CHANGE/BAS" is no longer on
your disk. The space it occupied is now FREE for
new files.
Notice, we had to include CHANGE'S extension,
"BAS" in order to KILL it. The Computer insists
you type the complete filename as one extra pre-
caution. It doesn't want to KILL afile you don't
want destroyed.
Note: Want to get very technical? The data will still
exist on the disk after you KILL afile. However, the
Computer won't know it's there because KILL deletes
all reference to it in the dish's directory. Therefore,
you'll no longer be able to access the data and the
Computer will be able to write over it with anew file.
Multi-Disk Drives
You can use FREE and KILL on other disk drives,
as you can with RENAME, by typing the drive
number. Examples:
PRINT FREE(l) INTER)
tells you how much FREE space is on the disk in
drive 1.
KILL "NEWACC/DAT: 1" (ENTER]
deletes "NEWACC/DAT" from the disk in drive 1.
SPECIAL MULTI-DRIVE
COMMANDS
In the rest of this chapter, we'll talk about two
commands which you can use if you have amulti-
drive system. If you don't have one, go on to
"Chapter Checkpoint" at the end of this chapter.
20
YOU'RE THE BOSS
The first one copies a disk file. You should, at this
point, have aprogram file stored in the disk in
drive named "NEW/NAM." Make aCOPY of it.
Type:
COPY "NEW/NAM:0" TO "NEW/NAM: 1" (ENTER).
If you want, you can rename the file when you
copy it. For instance, COPY "NEW/NAM :1" TO
"ANOTHER/NAM :0" (ENTER) copies "NEW/NAM"
from the disk in drive 1to the file "ANOTHER/
NAM" on the disk in drive 0.
The second command changes the drive number
the Computer goes to if you do not specify one. Up
to now, this has been drive 0. For example, by typ-
ing SAOE "ANYTHING/EX" (ENTER), the Computer
will assume you want to use drive 0. It will then
SAVE this program on the disk in drive 0.
To change this assumption, you can type:
DRIVE 1CENTER)
This makes the Computer assume you want it to
use DRIVE 1, unless you tell it otherwise.
After changing this DRIVE assumption, the Com-
puter will respond differently to the same com-
mand. By typing SAUE "ANYTHING/EX" (ENTER) ,the
Computer will store "ANYTHING/EX" on the
disk in drive 1. You would now need to type SAVE
"ANYTHING/EX :0" (ENTER] to SAVE it in drive 0.
CHAPTER CHECKPOINT
1. How do you rename afile? Why do you
have to specify the file's extension?
2. What can you do when you think you're
running out of disk space?
3. If you have more than one disk drive and
do not specify the drive number, which
drive will the Computer use? How can you
change this?
Congratulations. You are now a bonafide disk sys-
tem operator. You should now have agood under-
standing of how your disk system works and how
to take full advantage of it.
21
SECTION II
TTDDIE IMSBS IPMDCSIEA
Storing aBASIC program is easy. You only need to
use the SAVE command. Storing data takes alittle
more effort. You need aprogram.
Some of you might prefer to buy aready-made pro-
gram. However, if you want more control and are
willing to invest alittle time, you will enjoy writing
your own.
In this section, we'll show you how to write aBASIC
program which stores data on disk. We are assum-
ing you already know some BASIC. If you don't,
read Section Iof Getting Started with Color BASIC.
It will give you all the background you need.
23
ONE THING AT ATIME
(Sequential Access to aFile)
Atape is simple. There's only one way to put data
on it and one way to read it off. Adisk is more com-
plex. There are several ways to "file" your data on
it.
In this chapter and the next, we'll show how to
write aprogram which stores data in a"sequential
access" disk file. It's the simplest file to create and
is actually very similar to atape "file" In Chapter
7, we'll introduce "direct access," an alternate type
of disk file.
In showing how to store things on disk, we'll fre-
quently use the words disk file and disk directory.
We discussed these concepts in Chapter 2, but we'll
summarize them now.
Everything you store on disk must go in adisk file
and be assigned afilename. Your Computer will
index the location of the disk file in the disk's
directory. For example, if you want to store the
names of your friends, you could put them in a
disk file named "FRIENDS'' Your disk's directory
would then index where, on the disk, "FRIENDS"
is stored.
There is, of course, agood reason for all of this.
Using the disk filing system, the Computer will be
able to immediately find any file on the disk.
WRITING ADISK FILE
Let's assume you want to "write" your checks on
the disk:
CHECKS
DR. HORN
SAFEWAY
FIRST CHRISTIAN
OFFICE SUPPLY
Weil start with ashort, simple program which
writes the first check, "DR. HORN|' on the disk.
Insert aformatted disk in your disk drive. (If you
have more than one disk drive, use drive 0.)
25
ONE THING AT ATIME
Note: Chapter 2shows how to format adi-sk. (Type
DIB JN.TEE- ifyou can't remember whether adisk is for-
matted.) Chapter 1explains the drive numbers.
Then type:
10 OPEN "0"t *lr "CHECKS/DAT"
20 WRITE »1 t"DR. HORN"
38 CLOSE »1
RUN the program. You'll hear the motor of the
disk drive and see the red light. The Computer is
at work, doing several tasks.
First, it OPENs communication to the disk so you
can send your checks out to it. Then, it finds an
empty location to store the checks and notes the
beginning location of that disk file in the directory.
All of this happens in line 10. Notice the meaning
of the "O", #1, and "CHECKS/DAT":
1. #1 is aspecial "buffer" area in memory called
buffer #1. It communicates with the disk drive.
Line 10 OPENs this buffer. (If you've been
using tape, you might remember that buffer
-1communicates with the tape recorder.)
2. "0" is the letter "O" not azero. It stands for out-
put. It tells the Computer that buffer #1 will be
sending out data to the disk.
3. "CHECKS/DAT" is the name of the disk file.
The disk's directory uses this name to index its
beginning and ending locations.
In line 20, the Computer sends out the words "DR.
HORN" to buffer #1 which WRITEs it on the disk.
Then, in line 30, the Computer CLOSEs commu-
nication with buffer #1. In doing this, it:
sends out all the data remaining in buffer #1
to the disk file.
notes in the disk's directory where "CHECKS/
DAT" ends.
Note: Abuffer temporarily stores data so the Com-
puter can input and output data to the disk in Mocks of
249 characters Ibytes) .Since buffer #1 only contains 8
characters ("DR .HORN"), they would not be sent out
to the dish without closing the file.
It is very important that you CLOSE communi-
cation with buffer #1. Why? Well, let's leave
buffer #1 OPEN. Delete line 30 and RUN the pro-
gram several times.
The program appears to work the same every time
you RUN it. This is because every time you RUN
(or LOAD) aprogram, the Computer will auto-
matically CLOSE communication with any buff-
ers you've left OPENed.
Now, let's assume you switch disks and RUN or
LOAD aprogram. The Computer will automati-
cally CLOSE communication with buffer #1. In
doing this, it will send out its closing information
to the new disk (thinking it's the old one). This
will very possibly garble the contents of both
disks.
Now that we've warned you of the importance of
line 30, re-insert this line in your program and
RUN it again. This is what the program writes on
your disk:
<cne Vys
*»r-
"DR. HORN"
Vote: Like our drawing of the disk? The en
"CHECKS/DAT" file consists of the words "DR
HORN'' The disk's directory notes the beginning and
ending locations of this file.
You can verify that the Computer has done this by
checking the disk's directory. You remember how
to do that. (Type DIR(ENTER))
Because this program sends your data out to the
disk file, we'll call it an output program.
READING THE DISK FILE
To get the Computer to read this data from the
disk back into its memory, you need an input pro-
gram. Erase the output program you now have in
26
NETHINGATA1
memory by typing NEW (ENTER) .Then type and RUN
this input program:
100 OPEN "I". #li "CHECKS/DAT"
110 INPUT #1 .A*
120 PRINT At
130 CLOSE #1
This is actually just the reverse of the output
program . .
.
Line 100 again OPENs communication to buffer
#1. This time communication is OPEN for "F
input. The Computer goes to the disk's directory to
find where to start inputting the file named
"CHECKS/DAT"
In line 110, the Computer INPUTs the first data
item from the disk file named "CHECKS/DAT"
and labels it A$. Line 120 PRINTs A$.
Finally, line 130 CLOSEs communication to
buffer #1. In doing this, the Computer inputs any
data remaining in the buffer.
JVoie: You can compare an input program to the
LOAD command. An input program inputs adat<
file: LOAD inputs aprogram file.
:
©V
ONE CHECK AT ATIME
At this point, we've used an output program and
an input program. Let's combine them into one
program. Type:
10 OPEN "0" i*1 i"CHECKS/DAT"
20 WRITE *1 ."DR. HORN"
30 CLOSE #1
100 OPEN "I" t«li "CHECKS/DAT"
110 INPUT *1 ,A$
120 PRINT A*
130 CLOSE *1
Now add these lines and RUN the program:
25 WRITE *1 i"SAFEWAY"
115 INPUT «1 tB$
120 PRINT A$ tB*
Lines 10-30 output two checks into your disk file:
"DRHORNt" "SAFEWAY"
Lines 100-130 input them. Try to input more than
two checks. Change line 115 and 120:
115 PRINT A$
120 GOTO 110
and RUN the program ...The Computer prints:
?IE ERROR IN 110
The Computer is notifying you that you are asking
it to input more checks than are in the file.
Technically, the IE error means you've attempted
to Input past the End of the File.
This error makes things difficult when you want
to input all the data, but you don't know how
much is in the file. We showed you this error so
you would appreciate our new word EOF. Type:
105 IF EOF(l)
120 GOTO 105
1THEN 130
and RUN . . .EOF checks to see if you've reached
the end of buffer #1 {the number in parentheses).
If you have, EOF(l) equals a-1. If you haven't,
EOF equals 0.
27
ONE THING AT A TIME
By adding line 105 to the program, the Computer
checks to see if you've reached the End before
inputting the next check. If you have, line 130 clo-
ses communication to the file.
DETAILS...
So far, "CHECKS/DAT" has been easy to handle,
but not very useful. You would probably like to
add more details:
CHECKS
PAYABLE TO AMOUNT EXPENSE
DR. HORN 45.78 MEDICAL
SAFEWAY 22.50 FOOD
FIRST CHRISTIAN 20.00 CONTRIB.
OFFICE SUPPLY 13.67 BUSINESS
Change lines 25 and 115, and add some lines by
typing:
25 WRITE ttl t^5. 78
27 WRITE #1 t"MEDICAL"
110 INPUT #1 tft$i Ct
115 PRINT At tB>Ct
LIST the program. This is the way it should look
now:
#1 >"CHECKS/DAT"
"DR. HORN"
#1 ."CHECKS/DAT 1
=-1 THEN 130
10 OPEN "0" t
20 WRITE *1 >
25 WRITE «1 ,a5. 78
27 WRITE «1 t"MEDICAL"
30 CLOSE «1
100 OPEN "I" »
105 IF E0F(1)
110 INPUT #1 ,A$i Bt C$
115 PRINT A$ >Bi Ct
120 GOTO 105
130 CLOSE *1
Now RUN it.
AGOOD TIGHT PROGRAM
What if you need to store awhole list of checks?
Continue to plod along with this program, and it'll
soon be unbearable.
Here, we have atight program which asks you to
INPUT all your data, stores it on disk, and reads
it back into memory. Erase memory and type:
5CLS
10 OPEN "O" **1 i"CHECKS/DAT"
20 INPUT "CHECK PAYABLE TO :"i A$
30 IF At ="" THEN 80
40 INPUT "AMOUNT :*"! B
50 INPUT "EXPENSE :" iC$
GO WRITE «li At tBtC$
70 GOTO 20
80 CLOSE *1
80 CLS
100 PRINT "YOUR CHECKS ARE STORED ON DISK"
110 INPUT "PRESS <ENTER> TO READ THEM"! At
120 OPEN "I" talt "CHECKS/DAT"
130 IF E0F( 1)=-1 THEN 170
140 INPUT *li At iBt Ct
150 PRINT a$; b; Ct
1G0 GOTO 130
170 CLOSE »1
RUN it. Input any checks. When you want to quit,
simply press (ENTER)in answer to the check pay-
able to :prompt. For example:
(ENTER)
CHECK PAYABLE TO :? GOODY BANK (INTER)
AMOUNT :$? 230.97
EXPENSE
CHECK
CAR (ENTER)
PAYABLE TO :? (ENTER)
YOUR CHECKS ARE STORED ON DISK
PRESS (ENTER) TO READ THEM? (ENTER)
GOODY BANK 230.87 CAR
PROGRAMMING EXERCISE
#5.1
Write aprogram which will print
only those checks which were for
JAR expenses.
The answers to all the "Programming Exercises"
are in Appendix A.
CHAPTER CHECKPOINT
1. What is a buffer #1?
2. Why must you OPEN adisk Hie?
3. Why must you CLOSE it?
4. What is the difference between afile OPEN
for input and output?
28
Try saving many different graphics
programs on disk and calling them
from one main program. Sample
Program 7in Appendix C shows
how.
You can quickly store, organize, and
update all your financial information with
adisk system. See Sample Program 1, 2,
and 8in Appendix Cfor program listings.
izr
^k
°°«
'' \^,*
"-,. ;«^
CHANGING IT ALL AROUND
(Updating aSequential Access File)
Everything you put on the disk and take off of it
goes through aspot in memory called abuffer.
When we told you how to put data on tape in Get-
ting Started With Color BASIC, we didn't talk
about these buffers. We didn't need to. There is
only one buffer which communicates with the tape
recorder buffer #- 1.
With your disk system, you can use up to 15 buff-
ers. This means you can have up to 15 spots in
memory communicating with 15 different disk
files at the same time.
The reason we brought this subject up is that we
want to demonstrate how to change some of the
data in your file. Tb do this, it is very helpful to use
two buffers.
Note: In Chapter 10, we'll demonstrate how to take
advantage of more of these buffers
Type this program:
10 OPEN "0", Mi "ANIMALS/DAT"
20 WRITE «1 i"HORSE"
30 WRITE *1 t"COW"
am CLOSE *1
RUN it. Now, let's assume you want to change
"COW" to "GIRAFFE!' First, you need to read the
data items into memory with an input program.
Erase memory. Type NEW (ENTEffl and then type:
10 OPEN "I" iM, "ANIMALS/DAT"
20 IF E0F(1) =-1 THEM 110
30 INPUT «1 tA$
40 CLS :PRINT @LOG ."DATA ITEH :" A*
i
109 GOTO 20
112 CLOSE «1
Then you need to add lines which will allow you to
change one of these data items and store the
change in the disk file. Type:
50 PRINT @451 t"PRESS <ENTER> IF NO
CHANGE" ;
G0 PRINT %2G3, "CHANGE :"!
70 INPUT X%
29
CHANGING IT ALL AROUND
SO IF X* ="" THEN X$ =
90 WRITE *1 iX*
A$
RUN the program. As soon as the Computer gets
to line 90, it prints:
?FM ERROR IN 90
LIST the program. Line 10 opens buffer #1 to
input data. Line 90, however, is attempting to out-
put data to buffer #1. The Computer won't output
data to abuffer opened for input.
This is where the additional buffer becomes
handy. To output your changed data to the disk,
you can open another buffer for output. Add these
lines:
15 OPEN "0" .*2, "NEW/DAT"
90 WRITE »2* X*
120 CLOSE »2
RUN the program. Change "COW" to "GIRAFFE"
This is the way the entire program looks:
10 OPEN "I". «1 ."ANIMALS/DAT"
15 OPEN "0" .«2. "NEW/DAT"
20 IF EOFt 1) =-1 THEN 110
30 INPUT 81 ,A*
40 CLS :PRINT @10E, "DATA ITEM :" A$
i
50 PRINT @451. "PRESS <ENTER> IF NO
CHANGE" ;
S0 PRINT @2G3» "CHANGE :"i
70 INPUT X*
B0 IF X$ ="" THEN X* =A*
90 WRITE 82. K$
100 GOTO 20
110 CLOSE »1
120 CLOSE *2
Line 10 OPENs communication to buffer #1 for
input from adisk file named "ANIMALS/DAT."
Line 15 OPENs communication to buffer #2 for
output to adisk file named "NEW/DAT:7
Line 30 inputs A$ from buffer #1. Line 70 allows
you to INPUT X|, which will replace A$. If you
input X$, line 90 outputs it. Line 90 outputs X$ to
buffer #2, which, in turn, WRITEs it to "NEW/
DAT!'
Line 110 CLOSEs communication to buffer #1
and line 120 CLOSEs communication to #2.
Now you have two files. "ANIMALS/DAT" con-
tains the old data and "NEW/DAT" contains the
new. Add these lines to the program and RUN it:
130 KILL "ANIMALS/DAT"
140 RENAME "NEW/DAT" TO "ANIMALS/DAT"
Now the old "ANIMALS/DAT" file is deleted from
the disk and the "NEW/DAT" file has been
renamed to "ANIMALS/DAT." To see what this
updated file contains, SAVE this program if you
want, erase memory, and type and RUN:
10 OPEN "I") 81 ,"ANIMALS/DAT"
20 IF E0F(1) =-1 THEN B0
30 INPUT 81 ,A$
40 PRINT A*
50 GOTO 20
G0 CLOSE «1
Understand? Try these exercises:
PROGRAMMING EXERCISE #0.1
Write aprogram which will allow
you to add animals to "ANIMALS/
DAT'
Hint You must add them to the
end of the file.
PROGRAMMING EXERCISE #6.2
Write aprogram which will allow
you to delete animals from "ANI-
MALS/DATT'
Ready for the big time? Our next exercise is apro-
gram many of you will want amailing list pro-
gram. We'll start you out with these lines which
input the names, addresses, and phone numbers of
your club members:
30
CHANGING IT ALL AOUND
BO OPEN "0". »lf "MEMBERS/DAT"
90 GOSUB 430
100 IF N*="" THEM CL0SE«1:END
110 WRITE *1 iN$t A*. P*
120 GOTO 90
430 CLS: PRINT "PRESS <ENTER> WHEN
FINISHED" :PRINT
440 INPUT "NAME OF MEMBER: "iN$
450 IF N$ ="" THEN 480
4G0 INPUT "ADDRESS :"?A*
470 INPUT "PHONE NUMBER :"! P$
480 RETURN
Now finish it by solving this Programming Exer-
cise. It'll be difficult, but we think you can do it.
Remember, no one's watching. If you get bogged
down, refer to the answer in Appendix Afor help.
PROGRAMMING EXERCISE #6.3
Write aprogram in which you can:
1. See the names, addresses, and
phone numbers ofyour club's
members.
2. Change the addresses ofsome of
the members.
3. Add new members.
4. Delete some of the members.
All of this works quite well on asmall scale, but
how would it work in alarge file? What if you had
500 members in your "MEMBERS/DAT" file and
you wanted to change only the address of the
453rd member?
The process would still be the same. You would
have to input each of the 500 members from one
file and then output them all to another file. All of
this just to change one record. There must be an
easier way!
The easier way is called the direct access method
of programming. It makes your files easier and
faster to update, but in many cases it will make
them take up more space in your disk. The choice
is yours. We'll talk about direct access in the next
chapter.
Note: We've demonstrated short example programs.
There are many ways you could improve them. See
the "Sample Programs" in Appendix Cfor ideas.
CHAPTER CHECKPOINT
Why can 't you input and output data to the
same buffer at the same time?
Can you input data from afile OPENed for
"O"— output?
31
DISK FILE
STORAGE AftEA
Mo MxwTMice u>mwor HumeeR
AMORE DIRECT APPROACH
(Direct Access to aFile)
Up to now, we haven't been concerned with how
your data is stored on the disk. For example, you
might have put this in a disk file:
/
"MARIE ALEXANDER*" "J* DO
E»""MARK JONES*" "BILL S
h/DAT it
MITH
*S
'jtout o£>
KMME5/DAT **
What if you want to change "J. DOE," to
"ELLIOTT HOBBS"? You could not ask the Com-
puter to go directly to "J. DOE" The Computer
does not know where it is.
All the files we've created so far have been
"sequential access!' To find aparticular item in a
sequential access file, the Computer must start at
the beginning and search through each item. It
can't go directly to the item. In short, asequential
access file does not take full advantage of your
disk's "filing system."
USING THE DISK FILING SYSTEM
In Chapter 2we talked about how formatting your
disk creates this filing system. In our analogy, the
file cabinets are the disk "tracks" and the file
drawers are the disk "sectors!' You can use tracks
and sectors to immediately find any item you
want.
To do this, you can divide your file into something
which we call "records." You can then write a pro-
gram which stores each record in a sector and
allows you to put data in the records. The next
page shows how your new disk file will look:
33
AMORE DIRECT APPROAC H
>*
"MARIE ALEXANDER"
record 1
"J.DOE"
record 2
"MARK JONES"
record 3
"BILL SMITH"
record 4
//
With each record the same length (the length of a
sector), the Computer can go directly to "J. DOE!'
All it has to do is count down to the second record.
We call this a"direct access" file. By direct access,
we mean you can directly access any record you
want in the file.
Adirect access file has one shortcoming. Each
record is the size of asector 256 bytes. Since one
of these bytes holds one character of data, each
record is large enough to hold 256 characters.
This means that our drawing above is alittle mis-
leading. If we illustrated all the empty space in
each record, they would each have to be nearly ten
times as long. We simply don't have enough room
on the page.
If you're abeginner, all this empty space probably
won't bother you. An empty disk can hold up to
612 records each 256 bytes long. Later on, when
you become more comfortable with programming,
you'll probably want to pack more records into a
disk file. You can then progress to Chapter 9,
where we will demonstrate how to make smaller
records.
PUTTING ARECORD ON DISK
Enough theory! Let's put one record in adisk file.
Since it'll beadirect access file, we don't have to
start with the first. We'll start with the second.
Erase memory and type:
10 OPEN "D" ttil, "NAMES/DAT"
20 WRITE *1 t"J. DOE"
30 PUT *1 .2
40 CLOSE *1
The program looks familiar ...except for the word
PUT in line 30 and the "D" in line 10. More on that
later . .
.
Now let's add some lines so the Computer will
read this record back into its main memory. Type:
34 GET 81 t2
3G INPUT #1 ,A*
38 PRINT A$
Note that line 34 uses another new word GET
Hmmm ...any ideas? Let's look at the entire
program:
10 OPEN "D"i »1
i
"NAMES/DAT"
2(3 WRITE »1 ,"J. DOE"
30 PUT *1 .2
3 a GET «1 i2
36 INPUT »1 pA$
38 PRINT A$
40 CLOSE *1
RUN it . . . You'll hear the now familiar sound from
your disk drive. The Computer is writing "J.
DOE" in the disk file and then reading it back into
memory. Here's how ..
.
Line 10 OPENs buffer #1 which will communi-
cate with adisk file named "NAMES/DAT." As we
said in the last two chapters, buffer #1 is one of
the 15 "buffer" areas which can communicate with
your disk.
Communication is being OPENed for "D." "D"
stands for direct access. Unlike sequential access,
you don't have to specify whether you're OPENing
34
AMORe DIRECT APPROACH
communication for output or input. The "D" suf-
fices for both.
Line 20 WRITEs "J. DOE" to buffer #1. Since this
program is open for direct access, "J. DOE" will
remain in buffer #1 until the program sends it
elsewhere.
Line 30 does just that. It PUTs the contents of
buffer #1 into the disk file as record 2:
Notice our drawing shows only two records in the
file. GET record 4. Type:
34 GET »1 .a
and RUN ...The Computer gives you an IE (Input
past the End of the File) error. This is because the
last record the program PUT in the file was record
number 2. Hence, record 2became the end of the
file.
it
Note: Didn't get this error? You must already have
"NAMES/DAT" file on your disk with three or mo.
records.
:
record 1
"JDOE"
record 2/
W^MES/DAT" ^
To PUT more records in the file, add these lines.
Then RUN the program:
31 WRITE »1 t"BILL SMITH"
32 PUT si ,a
Now your "NAMES/DAT" file will have these four
records:
At this point, "J. DOE" is no longer in buffer #1.
It is in record 2of the disk file.
Line 34 GETs record 2and reads it back into
buffer #1. Now "J. DOE" is in both the disk file
and buffer #1.
Line 36 INPUTs the record from buffer #1 into
main memory and labels it A$. Now "J. DOE" is
in both the disk file and main memory. It is no
longer in buffer #1.
With "J. DOE" in main memory, line 38 can
PRINT it.
record 1
"J.DOE" .
record 2
record 3
"BILL SMITH"
record 4
Note: In the sequential access programs in Chapters
5and 6, you didn't need PUT and GET. The Com-
puter did this automatically. The OPEN line specified
whether the buffer should output (PUT) data into the
disk file or input (GET) data from the disk file.
JtMdb
XW/)M£S
r
5/DA7 >*
35
AMORE DIRECT APPROACH
PROGRAMMING EXERCISE 7.1
Change lines 32 and 34 so that your
Computer will use record 3 to PUT
and GET "BILL SMITH."
itV-,
:*W ;*&*&&* ,1 -
DEALING WITH GARBAGE
You have not yet PUT anything in record 1.Ask
the Computer to GET record 1and see what hap-
pens. Type this and RUN:
34 GET »1 >1
Since the Computer didn't PUT anything in
record 1, record 1contains whatever "garbage" is
already there.
When you ask the Computer to GET and INPUT
it, it will either get the "garbage" or give you an
OS (Out of String Space) error. The OS error sim-
ply means the garbage consumes more than 200
bytes (characters).
Since your empty records will contain garbage
until you fill them with something, it's agood idea
to put some kind of data in all of them in advance.
Erase memory and type this program:
10 OPEN "D" t*1 i"NAMES/DAT"
20 FOR ;; =1TO 10
30 WRITE *1 ."NO NAME"
40 PUT »l ,X
50 NEXT X
G0 CLOSE «1
RUN it. This program sets up adisk file named
"NAMES/DAT" which has ten records. Each
record contains "NO NAME":
KMtie$fD#r"
"NO NAME "
record 1
36
"NO NAME"
record 2
"NO NAME"
record 3
"NO NAME"
record 4
"NO NAME"
record 5
"NO NAME"
record 6
"NO NAME"
record 7
"NO NAME"
record 8
"NO NAME"
record 9
"NO NAME"
record 10
juhjL
xWfiM5S/D#T"
Now erase memory and type this:
10 OPEN "D" i#1 >"NAMES/DAT"
20 INPUT "RECORD NO. (1-10) "i R
30 IF R>10 THEN 20
40 IF R<1THEN 130
50 GET «1 .R
G0 INPUT «1 .A$
70 PRINT A$ "-- IS THE NAME IN RECORD" R
AMORE OIRECT APPROACH
90 INPUT "TYPE NEW NAME ELSE PRESS
<ENTER>"; At
90 if fi* ="" THEN 20
100 WRITE »1 ,A*
110 PUT *1 tR
120 GOTO 20
130 CLOSE *1
RUN it. See how all your records initially contain
"NO NAME." Then, you can change the data in
any of the records at will, as many times as you
want. (To end the program, type aas the
RECORD NO.)
READING ALL THE RECORDS
At this point, you might like the Computer to
print all of the records in your "NAMES/DAT" file
with their appropriate record numbers. SAVE
your program, if you want, erase memory, type,
and RUN:
10 OPEN "D" ,*1 »"NAMES/DAT"
20 R=1
32 GET *1 .R
40 INPUT «1 tAt
50 PRINT At "
60 IF R=10 THEN 90
70 R=R+1
80 GOTO 30
90 CLOSE *1
13 IN RECORD" R
Line 20 makes Requal to 1. In the next lines, the
Computer GETs, INPUTs, and PRINTs record 1.
Line 70 then makes Requal to 2and the whole
process is repeated with record 2. When Requals
10 the last record in the file the program ends.
There are many occasions when you will not know
the last record number in the file. Change line 60
and RUN the program:
G0 IF RL0F( 1)THEN 90
LOF looks at the file which buffer #1 (the number
in parenthesis) is communicating with. It tells
the Computer what the last record number in that
file is.
MORE POWER TO A RECORD
So far, we have been PUTting only one "field" of
data in each record. We can make the file more
organized by subdividing each record into several
fields.
Erase memory, type, and RUN this program:
*1 ."BUG9/DAT"
"FLIE9" t1000000* "HAIRY"
10 OPEN "D"
20 WRITE *1
30 PUT »1 .2
34 GET #1 .2
35 INPUT *i .D*. N. T$
38 PRINT Dt ,Nt Tt
WCLOSE #1
Line 20 WRITEs three fields of data into buffer
#1. Then, line 30 PUTs the entire contents of
buffer #1 (all three fields) into record 2of the file:
*BU&S/DfilT
"
record 1
"FLIES tI000000 »"HAIRY"
record 2/
Line 34 GETs everything in record 2and reads it
into buffer #1. Then, line 36 INPUTs all three
fields of data from buffer #1 and labels them as
D$, N, and T$.
Try substituting this for line 36 and RUN . .
.
38 INPUT *1 iDt
Since this line asks the Computer to INPUT only
the first field of data in buffer #1, it INPUTs only
"FLIES."
37
A MORE DIP.ECT APPP.OACH
PROGRAMMING EXERCISE 7.2
What do you think the Computer
would print if you ran the pro-
gram, using this for line 36? Why?
3G INPUT «1. N
PROGRAMMING EXERCISE 7.3
CHAPTER CHECKPOINT
1. What are records? Why must you use them
to access data directly?
2. What are Gelds?
3. Whatis the difference between asequential
access and adirect access file?
4. Why is it quicker to update adirect access
Hie?
Change the program which stores
the "NAMES/DAT" file so that
each record will contain five fields
of data:
1. name
2. address
3. city
4. state
5. zip
38
SECTION III
TOIE IBEIFMIEID) ©nSDS IPMDOISAKfl
After writing disk programs for awhile, you might
want to make them more efficient. Perhaps you'll
want to put more data on the disk. You might also
want to economize on memory space or use some
extra buffer space.
At that time, we invite all of you ambitious people
to read this section. The subject matter is more
advanced and technical. Once you finish it, though,
you'll have all the information you need to write the
best possible disk programs.
39
ra
HOW MUCH CAN ONE DISK HOLD?
(What the Computer writes in aDisk File)
Your disk is divided into thousands of equal-sized
units. Each unit is a"byte." One of these bytes can
hold one character. Thus, the word STRAW will
consume five bytes of disk space.
An empty disk contains 161,280 bytes. 4,608 of
them house the directory. This leaves you 156,672
for your disk files.
Note: Adisk contains 35 tracks. Each track contains
18 256-byte sectors, or 18x256 =4,608 bytes. One of
the tracks is for the directory. This leaves 156,672
bytes (4,608 bytes per track x34 tracks).
Does this mean you can use the entire 156,672
bytes for data? Possibly. There are two factors
which will determine this.
The first has to do with the way the Computer
allocates space for adisk file. It stores afile in clus-
ters. (We call them granules.) Each granule con-
tains 2,304 bytes.
Because of this, all of your disk files will contain
amultiple of 2,304 bytes. If your file contains
2,305 bytes of data, for example, the Computer
will allocate 2granules for it, or 4,608 bytes (2,304
x2).
The Computer allocates file space in this manner
because it's the most efficient way to create afile.
It is very tricky to change this and is something
that only very technical people would want to do.
(See Chapter 11, Technical Information, for addi-
tional information.)
The second factor which affects how much data
you can put in adisk file is your program. Some
disk programs are very efficient. Others put alot
of overhead and empty space in the file.
In the next two chapters, we're going to compare
eight different types of programs. Each will store
the same data 5, 'TEN;' -16, and "PAPER"
in adisk file named "OFFICE/DAT." The amount
of overhead and empty space each program will
put in "OFFICE/DAT" will vary greatly.
41
HOW MUCH CAN ONE DISK HOLD?
WRITING ON THE DISK
Program 1uses WRITE to put this data on the
disk. Type and RUN it:
PROGRAM 1
21 bytes
10 OPEN "0% «lf "OFFICE/DAT"
20 WRITE *1 ,5, "PEN"
30 WRITE «1 i-16 »"PAPER"
40 CLOSE #1
There is an easy way to see what lines 20 and 30
wrote on your disk. Type these two lines exactly as
they are above, but leave off the #1 in each line.
This will prevent the Computer from writing the
data on your disk (via buffer #1). The Computer
will write it on your screen instead. Type:
WRITE 5, "PEN" (ENTER)
WRITE -IS, "PAPER" (HDIE)
Look very carefully at what the Computer
WRITEs. Every blank space and punctuation
mark counts.
Notice the way the Computer WRITEs the two
strings (PEN and PAPER). It puts quotation
marks around them. It WRITEs the numbers (5
and -16) differently. If the number's negative, the
Computer puts aminus sign in front of it. If it's
positive, the Computer simply puts a blank space
in front of it.
There are two characters you typed which the
Computer didn't WRITE on the screen. These are
the two (ENTER) characters which you typed at the
end of the WRITE lines. It skipped down to the
next line instead:
5
OK
"PEN'
-IS, "PAPER"
OK
When writing on the disk, the Computer actually
WRITEs each (ENTER) character exactly as you
typed it. This illustration shows what Program 1
WRITEs on your disk. (We used asterisks to rep-
resent the [ENTER) characters):
of
0f
fi<*/dat»
//
5t"PE N "*-16i"PAPER"*
Note: Want to be precise? What the Computer
actually WRITEs on the disk are binary codex. Each
character has an ASCII code (see Appendix D) which
the Computer converts to abinary number.
Count the characters. Make each (ENTER) (repre-
sented by an asterisk), comma, and quotation
mark count for one character each. Don't forget
the blank space preceding 5. What you should
come up with is 21 characters. Program 1puts 21
bytes in "OFFICE/DAT."
Since the Computer allocates file space in clusters,
"OFFICE/DAT" will actually consume 1granule
of disk space or 2,304 bytes. However, for the pur-
pose of comparison, we'll only look at the 21 bytes
which Program 1puts in "OFFICE/DAT:'
ADISK-EYE VIEW
To input "OFFICE/DAT," type and RUN this
"INPUT Program" (erase memory first):
INPUT PROGRAM
10 CLS
20 OPEN "I", #1» "OFFICE/DAT"
30 IF E0F< 1)=-1 THEN 80
40 INPUT #1 ,A, Bt
50 PRINT: PRINT "DATA ITEM :" A
60 PRINT "DATA ITEM :"B$
70 GOTO 30
B0 CLOSE *l
It did input your data items. However, it did not
input the quotation marks, commas, and blank
spaces which we told you were interspersed with
your data.
To actually see what Program 1wrote on your
disk, you can use a"LINE INPUT Program." First
42
HOW MUCH CAN ONE DISK HOLD?
SAVE the "INPUT Program" you now have in
memory. (You'll be using it later.)
Now change it into a"LINE INPUT Program."
Delete line 50 and change lines 40 and 60. Type:
40 LINE INPUT #1 ,L*
50
G0 PRINT "DATA LINE :" L*
and RUN ...Line 40 INPUTs an entire LINE,
rather than one single data item from the disk file.
This LINE includes everything up to the (ENTER)
character punctuation marks, spaces and all.
In the "OFFICE/DAT" file, the first LINE contains
5, "PEN." Line 40 labels this line as L$ and line 60
PRINTs it on your screen.
The program then INPUTs and PRINTs -16,
"PAPER" the second and final line in the file.
We can easily alter this program so that it will
count how many bytes are in the file. Add these
lines and RUN it:
25 PRINT "THIS FILE CONTAINS :"
27 PRINT: PRINT: PRINT: PRINT
57 m=Lt+ "*"
G0 PRINT Mt!
G5 L=LEN(Mt) +L
90 PRINT @394t L"BYTES"
Line 57 adds an asterisk to each LINE. This aster-
isk represents the (ENTER) character. Line 65 then
counts the total number of characters (bytes) in
each line.
This is the entire "LINE INPUT Program":
PLINE INPUT PROGRAM
10 CLS
20 OPEN "I"* «li "OFFICE/DAT"
25 PRINT "THIS FILE CONTAINS ;
27 PRINT: PRINT: PRINT: PRINT
30 IF EOFU) =-1 THEN 80
40 LINE INPUT *1 fL*
57 M* =L* +"*"
G0 PRINT M$!
G5 L=LEN(M$) +L
70 GOTO 30
B0 CLOSE *l
90 PRINT @394 >L"BYTES'
SAVE it. It will be useful in comparing what Pro-
grams 2, 3, and 4put in your disk file.
PRINT—FOR A CHANGE
So far, we've used only WRITE to put data in a
disk file. If you've used other forms of BASIC, you
might be accustomed to using PRINT rather than
WRITE.
The Color Computer disk system allows you to do
this. However, PRINT is much more tricky to use.
If you're not used to it, don't bother learning all
this. Skip to Program 4.
...Still with us? KILL your old "OFFICE/DAT"
file by typing:
KILL "OFFICE/DAT" (ENTER)
Now erase memory, and type and run Program 2.
Then RUN the INPUT or the LINE INPUT Pro-
gram, if you'd like.
Here's Program 2:
PROGRAM 2
42 bytes
10 OPEN "0" ,*1 ,"OFFICE/DAT"
20 PRINT 81 ,"PEN"
30 PRINT *1 ,-1G »"PAPER"
40 CLOSE »1
Lines 20 and 30 PRINT your data to buffer #1
which, as you know, is one of the 15 buffers which
will send your data to the disk file. To see what
Program 2PRINTs, type:
PRINT "PEN" (ENTER)
PRINT -1G "PAPER" [ENTER)
Notice the Computer did not enclose the strings
PEN and PAPER in quotes, as WRITE did.
This will be important to know later.
Now look at the blank spaces. We'll start with the
first one the one before the 5. This means the
43
HOW MUCH CAN ONE DISK HOLD?
same thing it did with WRITE. 5is apositive
number.
Now for the other blank spaces ... Whenever the
Computer PRINTs anumber, it PRINTs one
"trailing" blank space after it. This explains the
first blank space after the 5 and -16.
How about all the additional spaces? Remember,
from Getting Started With Color BASIC, what a
comma in the PRINT line does? It causes the Com-
puter to PRINT your data in columns, inserting
spaces between the columns.
The Computer will PRINT every single one of
these blank spaces in your disk file:
Cn{L>
*OFFICE/DAT'
PEN*- IB
PAPER*^.
JtMxL *g "OFFICE/DAT "
Count all the characters. Program 2puts 42 bytes
into "OFFICE/DAT."
Note: Unclear about what commas do in aPRINT
line? Type some more PRINT lines with commas
between data items:
PRINT 1. 2, 3* H, 5, 6> 1, BHHTEffi
PRINT 'HORSE 11
,"COW'f ''RABBIT", "OOG
I
PRINTING LESS
You might feel that all the blank spaces PRINT
inserts in your disk file are awaste of space. They
are. The way to get around this waste is to use
semi-colons. You might again recall, from Getting
Started With Color BASIC, that semi-colons in a
PRINT line compress your data. Type:
"OFFICE/DAT" file. Then type and RUN this
program:
PROGRAM 3
17 bytes
10 OPEN "0" .*1 ,"OFFICE
20 PRINT #1 .5i "PEN"
30 PRINT *1 r-lGi "PflPEf?
40 CLOSE *1
This is what Program 3PRINTs on your disk. (Use
the LINE INPUT Program to test this, if you'd
like):
*0FFIC£/P*T \
/
5PEN*-1G PAPER*
Very efficient. Only 17 bytes. There are only three
blank spaces in this disk file. There is aspace
before the 5(to indicate that it is positive) and
spaces after 5and -16 (to indicate that they are
numbers). There are no blank spaces around the
strings.
PRINT 5! "PEN" (ENTER]
PRINT -lGi "PAPER" (EHTEB)
You can compress your data on the disk in the
same manner. Erase memory and KILL your old
THE TRICKY PART
There are certain types of PRINT lines which are
tricky. (We did warn you, didn't we?) Type:
44
HOW MUCH CAN ONE DISK HOLD?
PRINT "PEN"! "PAPER" fEHTER)
PRINT "JONES. MARY" (iNTEff)
print "pen". 5(mm
The line PRINT «l >"PEN" i"PAPER" (in your disk
program) would print this in your disk file:
PENPAPER*
The Computer would read PEN 5
(with all the blank spaces) back into memory as
one item. (Reason; although the Computer nor-
mally interprets blank spaces as adelimeter, it will
not interpret them in this way when they follow a
string and precede anumber).
For more information on using PRINT in disk pro-
grams, see the TRS-80 Model I, Model II, or Model
III Disk System Owner's Manual.
AN ATTRACTIVE DISK FILE
The Computer would read PENPAPER back into
memory as one item. (Reason: there is not a"deli-
meter" acomma, quotation mark, or space to
separate PEN from PAPER).
The line PRINT *l ,"JONES >MARY" would print
this in your disk file:
7
JONES tMARY*
The Computer would read JONES, MARY back
as two items: JONES and MARY. (Reason: The
Computer interprets the comma as a delimeter).
The line PRINT «i ,"PEN" ,5, would print this
in your disk file:
PRINT USING is another word you can substitute
for WRITE. We discussed PRINT USING in Going
Ahead With Extended Color BASIC). Type:
PRINT USING "1
(ENTER)
PRINT USING "I
'ENTER)
*,$+#«.**" 5"PEN" <5
!$+»#,»»" !"PAPER" ,-16
You can get the Computer to print these same
images on your disk with this program. KILL
"OFFICE/DAT," erase memory, and type and
RUN:
PROGRAM 4
32 bytes
10 OPEN "0" t#1 t"OFFICE/DAT"
20 PRINT #1. USING "X **+##,«#"!
"PEN" f5
30 PRINT tl, USING "X 2$+*» (#t"i
"PAPER"* -IB
40 CLOSE #1
i
PEN
which prints this in your disk file:
PEN $+ 5.00*PAPER
*-1B.130*
\
45
HOW MUCH CAN ONE DISK HOLD?
Note: There are five blank spaces between the %char-
acters in lines 20 and 30. Counting the two %char-
acters, this string field (for printing PEN and
PAPER) contains seven bytes.
Now the data is already in an attractive print for-
mat. You can input and print it using asimple line
input program. Erase memory, type and RUN:
more programs which will put the same data in
direct access files.
CHAPTER CHECKPOINT
sen INPUT and
IINT line cause
iaPRINT tine
IINT strings?
10 OPEN "I" >*1 >
20 IF EOFtl) =-1
30 LINE INPUT »1 *
40 PRINT At
50 GOTO 20
G0 CLOSE *1
1. What is the minimum size of adisk Sle?
Why can 't it be smaller?
9. Hnvr rfnan th* Cnmngter WJRJtTFf ntimhe
OFFICE/DAT"
"'""
THEN G0
A*
All of the files we've created in this chapter are
sequential access. The next chapter compares four
m^diMjftlef}
3. How does it WRITE strings
4. What is the' difference betwi
LINE INPUT?
5. What does a comma in aPI
the Computer to do?
6. What does asemi-colon it
cause it to do?
7. How does the Computer PE
46
f"l
9
TRIMMING THE FAT OUT OF DIRECT ACCESS
(Formatting aDirect Access File)
Direct access files often contain alot of empty
space. For example, our first program is very sim-
ilar to Program 1from the last chapter. The
WRITE lines are identical. However, because it is
direct access, it will put 512 bytes in "OFFICE/
DAT":
PROGRAM 5
512 bytes
10 OPEN "D"
.
20 WRITE #1 t
30 PUT «1 ,1
40 WRITE «1 ,
50 PUT *1 i2
60 CLOSE «1
•It "OFFICE/DAT'
"PEN"
-16» "PAPER"
Adirect access program puts your data inside rec-
ords. Each record is 256 bytes. Program 5puts two
records in the "OFFICE/DAT" file. Therefore, it
will consume 2x256, or 512 bytes:
V
IfiliiiiililiilllUiiii!
miimiiiiiiiflimim
HBiiiiiiiimmiinii
miifiiiiiHHHim
miiiiiiiiiiii11111111
1
BIIBilllllillllieiiiilll
iiiiiiliiiiiiiiiiaiii i i
i
Bisiiiiaiiiiiiinigiim
iiniaagiiiBBaBBiaeiiiii
TRIMMING THE FAT OUT OF OIRECT ACCESS
record 1
IB PAPER"*
record 2
*o?Fice/mT"
This obviously wastes amassive amount of space.
Notice that what the Computer actually writes in
each record:
5, "PEN"*
-IB, "PAPER"*
is the same as what Program 1wrote. Count the
bytes. That's nine bytes in the first record and 12
in the second. You'll need to know this for our next
program.
Note: We could have used PRINT or PRINT USING
rather than WRITE, The Computer would have then
PRINTed your data inside each record using the
PRINT or PRINT USING format.
TRIMMING THE FAT
Program 6is the same as Program 5, except that
we inserted anumber 12 at the end of line 10, This
tells the Computer to make each record 12 bytes
long:
PROGRAM 6
24 bytes
10 OPEN "B"i «lt "OFFICE/DAT". 12
20 WRITE »1 t5,"PEN"
30 PUT »1 .I
40 WRITE *1 ,-IB. "PAPER"
50 PUT «1 t2
B0 CLOSE *1
and really whittles this file down:
/"OFFICE/DAT"
5,"pE N "*
record 1
1G*"PAPE R "*
record 2
"0FFIC£/DAT"
In adirect access file, all records must be the same
length. {We explained why in Chapter 7.) If you
don't tell the Computer how long to make them,
they will all be 256 bytes.
In this program, we made each record 12 bytes, the
size of the largest record. Type and RUN Program
6, if you'd like, (Be sure to erase memory and
KILL your old "OFFICE/DAT" file first.) After
RUNning Program 6you can use this program to
input the file:
48
TRIMMING THE FAT OUT OF DIRECT ACCESS
DIRECT INPUT PROGRAM
*1 'OFFICE/DAT
10 OPEN "D".
20 R=R+1
30 GET #1 ,R
38 INPUT Hi A, B$
50 PRINT "RECORD" R":" A
G0 IF LOF(l) <> RTHEN 20
70 CLOSE »1
Note: You can't use the "LINE INPUT Program" to
determine how many bytes this file consumes. LINE
INPUT does not input the spaces in arecord which
follow the ;ENTER) character.
EFFICIENCY, EFFICIENCY . .
.
We can get even more efficient. Our next direct
access program consumes only 16 bytes. Erase
memory, KILL the old "OFFICE/DAT" file, and
type and RUN Program 7.
PROGRAM 7
16 bytes
10 OPEN "D"» *1 ."OFFICE/DAT" i8
20 FIELD »1
t
3AS At t5AS Bt
30 LSET At ="5"
40 LSET 8$ ="PEN"
50 PUT »1 .1
S0 LSET A$ ="-IS"
70 LSET B$ ="PAPER"
90 PUT «1 .2
90 CLOSE *1
There are two new words in this program which
we'll talk about later. Let's see what the program
does first. SAVE it. Then erase memory and input
the file with this program:
FIELDED INPUT PROGRAM
10 OPEN "D" ,1t'OFFICE/DAT" .S
20 FIELD *i ,3AS A* >5AS B*
30 R=R+1
mGET »1 ,R
50 PRINT "RECORD" R":" At! Bt
60 IF LOF(l) <> RTHEN 30
70 CLOSE »1
By using FIELD and LSET, your program will
work the same as any direct access program. The
difference is what FIELD and LSET put in each
record:
PEN
record 1
-16PAPE R
record 2
"OFF/CS/OAT
Only the bare essentials. Here's how Program 7
works ..
.
Line 20 tells the Computer to divide each record
into two fields. The first field is A$ and the second
is B$. These two fields will be the same size in
every record, A$ will always be 3bytes and B$
will always be 5 bytes.
Now that we've established this, we can put data
in each field. Line 30 LSETs 5in the A$ field
(SETs the character 5to the Left of A$). Since the
character 5only consumes 1byte and there are 3
bytes in the A$ field, there are 2empty spaces at
the end of 5.
Notice we had to convert the number 5to astring
by putting quotes around it. You cannot LSET a
number. You must convert it to astring.
Line 40 LSETs the word PEN in the B$ field.
Again, this leaves 2empty spaces at the end of A$,
since PEN is 3bytes.
Line 50 PUTs all this in record 1. Then, the same
process is repeated for record 2.
49
TRIMMING THE FAT OUT OF DIRECT ACCESS
Now let's look at the "Fielded INPUT Program:'
Notice we used aFIELD line. RUN the program
without line 20 and see what happens ..
.
Without aFIELD line, the Computer does not
know where the two fields are. Whenever you
input FIELDed records, use aFIELD line in your
input program.
Can you guess what the Computer would do if you
tried to LSET along string, such as "123456789,"
into one of the fields? LOAD Program 7, change
line 30, and RUN the program. (First, SAVE the
"Fielded INPUT Program" with line 20 reinstated.):
30 LSET A* ="lZGaSGTSa"
Now load and RUN the "Fielded INPUT
Program."
A$ is only 3 bytes. Therefore, the Computer only
LSETs the first 3bytes of "123456789." It chops
the remaining characters off:
^OFFICE /OA7"
/
Mmm
record 1
record 2
"OFF/C&/ DAT
More on this later .. . Before going on to the next
program, try writing your own FIELDed program:
PROGRAMMING EXERCISE
#9.1
Write a direct access program to
put amailing list in adisk Hie.
Make each record 57 bytes with
these six fields:
1. last name15 bytes
2. first name10 bytes
3. address 15 bytes
4. city10 bytes
5. state 2bytes
6. zip code 5bytes
^£3§§§i^
:.\l Vjl ;"''.-. :'-
PROGRAMMING EXERCISE
#9.2
Write aprogram to input the file
you created in Exercise #9.1.
ascs-ffira-afi
ANUMBER IS ANUMBER, ..
.
Let's assume you will be putting alot of numbers
in your disk file. Every number might be adiffer-
ent length:
-5.237632 31 673285
However, it is very important that the Computer
not chop any of the digits off. This might entirely
change the number's value.
The word MKN$ will solve this problem:
PROGRAM 8
20 bytes
10 OPEN "D" t»1 p"OFFICE/DAT"
t
10
20 FIELD *l t5AS A* ,5AS Bt
30 LSET ft* =MKNt<5)
40 LSET B* ="PEN"
50 PUT *1 p1
60 LSET At =MKN$t-iG)
70 LSET Bt ="PAPER"
80 PUT *1 >2
90 CLOSE »1
The only difference between this program and pro-
gram 7is lines 10, 20, 30, and 60. This is what it
stores in your disk file:
50
THIMMING THE FAT OUT OF DIRECT ACCESS
f
Jfi€JUM*U*Utf' off
/%bFF!C£/DAT"
record 1
SAPER
1
*office:/dat
Coda, ^&tr/6
MKN$ converts anumber to acoded string.
Regardless of how long the number is, MKN$ will
always convert it to astring that is five bytes long.
For example, change line 30 to LSET anumber
with more than five digits:
30 LSET A$ =MKN$(12345G7B9)
Erase memory, KILL "OFFICE/DAT," and type
and RUN the program. This is what it stores in
your disk file:
I
^CfcflCE/mT 9
'
To read this program in, you need to decode the
string. LOAD the "Fielded INPUT Program" and
make these changes to it:
10 OPEN "D" ,#1 ,"OFFICE/DAT" ,10
20 FIELD *i ,5AS A* ,5AS B$
50 PRINT "RECORD" R":";CYN(A$)i B$
and RUN it ...CVN (in line 50) decodes A$ to the
number it represents.
Note: The Computer only sees the first 9digits of a
number. It rounds the rent off.
PROGRAMMING
EXERCISE #0.3
Write afielded direct access pro-
gram which will store the popula-
tions of all the countries. Make
each record contain 15 bytes with
these two fields:
1. country 10 bytes
2. population 5bytes
WBPI^^^H^BOWi^PBBB
--— 5Jswbu
Ofdc j*v /23f56>7&7
"OFFICE/OfiT"
PROGRAMMING
EXERCISE #9.4
Write aprogram which will input
the Hie you created in Exercise
#9.3.
CHAPTER CHECKPOINT
1. Ifyou do not specify the record length, how
many bytes will each record contain?
2. Why must you include aFIELD line when
you LSETyour data?
3. Howmanybytes will MKN$ convert anum-
ber into?
51
•t %
t*
II
SHUFFLING DISK FILES
(Merging programs, using many buffers)
Because storing and retrieving disk files is so easy,
you will want to use them as much as you can. In
this chapter, we're going to talk about some spe-
cial ways you can use them.
MERGING PROGRAM FILES
With the first method, you can build aprogram
out of related program "modules" SAVEd on disk.
You can then MERGE any of these program files
with whatever program you have in memory.
Type and SAVE these two related programs:
10 REM AGE CONVERSION TO MONTHS
20 N=N*12
30 A* =STR*(N) +"MONTHS"
SAUE"MONTHS/AGE", A(ENTER)
10 REM AGE CONVERSION TO WEEKS
20 N=N*52
30 A* =STRt(N) +"WEEKS"
Be sure to type the Awhen you SAVE these pro-
grams. We'll explain why later ...Erase memory.
Now put this program in memory:
5INPUT "TYPE YOUR AGE" iN
40 PRINT "YOU HAVE LIVED" A$
and combine it with one of the programs you
SAVEd. Type:
SAVE "WEEKS/AGE", A(ENTER)
MERGE "MONTHS/AGE" (ENTERl
LIST the program ...The Computer has MERGEd
"MONTHS/AGE" with the program you have in
memory. Notice the line numbers are the same as
they were in each individual program.
At this point, this is the program you have in
memory:
5INPUT "TYPE YOUR AGE" iN
10 REM AGE CONVERSION TO MONTHS
20 N=N*12
53
SHUFFLING DISK FILES
30 A* =STR*(N) +"MONTHS"
40 PRINT "YOU HAVE LIVED ABOUT' A$
MERGE "WEEKS/AGE" with it by typing MERGE
"WEEKS/AGE" (ESTER) .Then LIST the MERGEd
program.
Notice that lines 10, 20, and 30 of the program you
had in memory were replaced by lines 10, 20, and
30 of the "WEEKS/AGE" program.
The line numbers tell the Computer how to merge
the two programs. When there is aconflict of line
numbers (two line 10s) fthe line from the disk file
prevails.
Now we'll get technical (for those of you who are
interested). What the Computer normally writes
in your disk file is the ASCII code for each char-
acter of data. For example, it writes the word AT
with two codes the ASCII code for "A" (65) and
the ASCII code for *T" (84). (The ASCII codes are
all listed in Appendix D).
However, when it SAVEs aprogram, it writes the
BASIC words differently. To save space, it com-
presses each BASIC word into aone-byte "binary"
code.
You can't MERGE afile which contains these
binary codes. This is why we had you type the A
when you SAVEd the two programs above. The A
tells the Computer to write the ASCII codes for
each BASIC word rather than the binary code.
By checking the directory, you can see if the data
in your files are in ASCII or binary codes. If there
is an "A" in the fourth column, it's all in ASCII
codes. A"B" indicates that some of the words are
in binary codes.
Note: Try typing MERGE "MONTHS/AGE" ,ft ^HTFffi.
The Rtells the Computer to RUN the program after
it's MERGEd.
USING MORE BUFFER SPACE
When you start-up your disk system, it sets aside
two buffer areas in memory for disk communica-
tion. You can use either or both of them for read-
ing or writing data to a disk file.
Up to now, that's all we've used buffers #1 and
#2. But, as we've said earlier, you can use up to 15
disk buffer areas.
To use more than 2buffers, you must first reserve
space in memory for them. To do this, use the word
FILES. For example, FILES 3reserves 3buffers.
Making use of all these buffers will greatly sim-
plify your programs. For example, let's assume
you own acomputer school. To organize it, you
first put all your students in afile named "COM-
PUTER/SCHr Erase memory, type and RUN:
10 OPEN "0". *1 ."C0NPUTER/SCH"
20 FOR X=1TO B
30 READ At
40 PRINT *1 .A$
50 NEXT X
G0 CLOSE #1
70 DATA JON iSCOTT ,CAROLYN
80 DATA DONNA. BILL rBOB
Now you can write this program to assign the stu-
dents to aBASIC or assembly-language class.
Erase memory and type this "Class Assignment
Program":
ICLASS ASSIGNMENT PROGRAM
»l
*Z
»3
10 FILES 3
20 OPEN "0" i
30 OPEN "0" .
WOPEN "I"
i
50 IF E0F(3)
G0 INPUT «3.
70 PRINT
80 INPUT
LANGUAGE"! R
90 IF R>2THEN 80
100 WRITE 8R tST$
110 GOTO 50
120 CLOSE 81
130 CLOSE 82
140 CLOSE 83
"BA5IC/CLS"
"ASSEMBLY/CLS"
"C0MPUTER/SCH"
1THEN 120
ST4
PRINT ST$
(IS BASIC
RUN it. After assigning all the students to aclass,
you can print a class roster with this program.
Erase memory, type, and RUN:
54
SHUFFLING DISK FILES
CLASS ROSTER PROGRAM
10 cls
28 PRINT "BASIC/CLS" :PRINT
30 OPEN "I". «1» "BASIC/CLS"
38 IF EOFU) =-1 THEN 80
50 INPUT »1» A*
S0 PRINT A$
70 goto aa
B0 CLOSE »1
Note: Substitute "ASSEMBLY/CLS" for "BASIC/
CLS" in lines 20 and 30 to print the class roster of the
assembly language class.
The "Class Assignment Program" has three buff-
ers open at the same time. Because of this, you are
able to communicate with three disk files at the
same time.
Line 10 reserves memory for these three buffers.
Lines 20-40 OPENs the three buffers. Then, line
60 INPUTs astudent from "COMPUTER/SCH"
into buffer #3.
Line 100 WRITEs the name of the student to
either buffer #1 ("BASIC/CLS") or buffer #2
("ASSEMBLY/CLS").
When all the students from buffer #3 ("STU-
DENT/SCH") have been input, line 50 sends the
Computer to lines 120-140, which CLOSEs the
three buffers.
CROWDING THE BUFFER
There's one more thing you'll like about FILES.
Erase memory, type, and RUN:
10 CLEAR £100
20 files 1,am
30 A$ ="NORMALLY tYOU WILL NOT BE ABLE TO
PUT ALL OF THESE SENTENCES IN ADISK
FILE AT THE SAME TIME. "
£10 B$ ="THIS IS BECAUSE, WITHOUT USING
FILES, YOU WILL ONLY HAVE ATOTAL OF
25G BYTES OF BUFFER SPACE. "
50 C$ ="IN THIS PROGRAM* WE'VE RESERVED
£100 BYTES OF BUFFER SPACE, "
E0 D$ ="THIS WAY YOU CAN SEND ALL OF
THESE SENTENCES TO THE BUFFER AT THE
SAME TIME. "
70 E* ="WHICH WILL OUTPUT THEM ALL TO THE
DISK FILE AT ONCE, "
80 OPEN "0" ,»1 ,"WORD/DAT"
90 WRITE #1 .A*. B$ ,C$ ,Dt ,Et
100 CLOSE #1
Want to input this paragraph? Add these lines and
RUN:
200 OPEN "I" ,#1 ,"WORD/DAT"
210 INPUT #1 ,At, Bt, Ct, Dt tE$
220 CLS
230 PRINT At; Bt; Cti Dt !E$
240 CLOSE #1
Note: You can make the buffer as targe as you want
CHAPTER CHECKPOINT
Howmustyou SAVE aprogram which yo,
wUl want to MERGE?
When the two programs you're mergin
both have the same line numbers, whic.
lines prevail?
How many buffers does the Compute
reserve when it starts-up?
How much hunter space does it reserve?
What does FILES 3, 3000 mean?
2.
3,
4.
5.
55
HtvttT^Ci^ ^<5^
"PR^ck
^/
•:
:-.
TECHNICAL INFORMATION
(Machine-Language Input/Output)
In this chapter, we'll discuss the technical details
which are happening "behind the scenes" You
don't need to know this information when you are
programming in BASIC. In fact, you won't even be
aware that these details are happening.
However, if you plan to write machine-language
disk programs or are simply interested in know-
ing all you can, you'll definitely want to read this
chapter. We'll begin by discussing how the Com-
puter organizes all the bytes on the disk. Then,
we'll show how to access them through machine-
language programming and other advanced
techniques.
WHAT ADISK CONTAINS
When you power-up the Computer, it organizes
the bytes on the disk into tracks and sectors. Some
of these bytes control the system. The great major-
ity of them are for data.
TVacks
The Computer organizes the disk into 35 tracks,
numbered 0-34. Each track contains approxi-
mately 6,250 bytes* 6,084 of them are divided into
sectors; the remaining are for system controls.
Byte# Contents
0-31 System controls
32-6115 Sectors
6116-6249* System controls
The system control bytes all contain the value of
4E (hexadecimal).
*the number of system control bytes at the end of
each track might vary slightly due to slight speed
variations.
Note: One byte contains 8bits. Each bit contains
either a1or a0. Normally, we express the contents of
these bits as ahexadecimal (base 16) number. For
example, if we say a byte contains the value of hexa-
decimal 4B, it contains this bit pattern 0100110.
kYou can find more information on hexadecimal and
binary number systems in amath textbook.
57
TECHNICAL INFORMATION
Sectors
Each track contains 18 sectors, numbered 1-18.
Each sector contains 338 bytes. 256 of them are for
data. The remaining bytes are for system controls.
Byte# Contents
0-55 System controls
56-311 Data
312-337 System controls
The hexadecimal contents of the system control
bytes are:
Byte# Hexadecimal Contents
0-7 00
8-10 F5
11 FE
12 Track Number
13 00
14 Sector Number
15 01
16-17 Cyclic Redundancy Check <CRC)
18-39 4E
40-51 00
52-54 F5
55 FB
312-313 Cyclic Redundancy Check (CRC)
314-337 4E
HOW THE DATA IS ORGANIZED
Each track contains 4,608 bytes which the Com-
puter can use for data:
18 sectors per track
x256 data bytes per sector
4,608 data bytes per track
The data bytes in the 17th track contain the disk's
directory. The data bytes in the remaining 34
tracks are for disk files:
Track #
0-16
17
18-34
Disk Files
Contents of Track's Data Bytes
Disk Files
Disk Directory
Disk Files
The Computer divides the 34 tracks for disk files
into 68 granules. Since each track contains two
granules, one granule is 2,304 bytes long:
9sectors in V2 track
x 256 data bytes per sector
2,304 bytes in agranule
The Computer uses granules to allocate space for
disk files in 2,304-byte clusters. Thus, if afile con-
tains 4,700 bytes, the Computer allocates 3gran-
ules (6,912 bytes) of disk space for it.
The location of the 68 granules, numbered 0-67, is
as follows:
Track 0, Sectors 1-9
Track 0, Sectors 10-18
Track 1, Sectors 1-9
Track 16, Sectors 10-18
Track 17, Sectors 1-18
Track 18, Sectors 1-9
Track 34, Sectors 10-18
Granule
Granule 1
Granule 2
Granule 33
Directory
Granule 34
Granule 67
Note: The minimum size of adisk file is one granule
or 2,304 bytes. Adi.sk will hold amaximum of68 disk
files.
Disk Directory
The directory track (track 17) contains afile allo-
cation table and directory entries. The sectors on
this track which contain this information are:
Sector #Contents
2File allocation table
3-11 Directory entries
The remaining sectors in the directory track are
for future use.
Directory Entries
The 9sectors of the directory containing directory
entries (sectors 3-11) will hold up to 72 entries.
Each entry is 32 bytes long and contains:
58
TECHNICAL INFORMATION
Byte #Contents
0-7 Filename, left justified, blank-filled.
If byte =0, the file has been deleted
and the entry is available.
If byte =FF (hexadecimal), the
entry (and all following entries) have
not yet been used.
8-10 Filename extension, left justified,
blank-filled.
11 File Type
=BASIC program
1=BASIC data file
2=Machine-language program
3=Text Editor source file
12 ASCII flag
=the file is in binary format
FF (hexadecimal) =the file is in
ASCII format
13 The number of the first granule in the
file (0-67).
14-15 The number of bytes in use in the last
sector of the file.
16-31 Reserved for future use.
File Allocation Table
Sector 2of the directory contains afile allocation
table for each of the 68 granules on the disk. This
information is located on the first 68 bytes of the
sector. The remaining bytes contain zeroes:
Byte #Contents
0-67 Granule information
68-255 Zeroes
Each of the first 68 bytes corresponds with agran-
ule. For example, byte 15 corresponds with gran-
ule 15.
These bytes will either contain avalue of FF, 0-43,
or C0-C9 (hexadecimal):
FF The corresponding granule is free. It is
not part of adisk file.
00-43 The corresponding granule is part of a
disk file. The value, converted to dec-
imal, points to the next granule in the
file. For example, if the value in abyte
is 0A, 10 is the next granule in the file.
C0-C9 The corresponding granule is the last
granule in the file. The value contained
in bits 0-5 of this byte tells how many
of the sectors in that granule are part
of the disk file. (Bits 7and 8both equal
1.)
SKIP FACTOR
The Computer reads or writes data to the disk one
sector at atime. Between sector reads or writes, it
does some processing.
The disk does not stop and wait for the Computer
to do this processing. It spins continuously.
For example, the Computer might read Sector 1
first. But by the time it's finished processing Sec-
tor 1, the disk will have spun to Sector 6.
To allow for this time differential, the Computer
sets a"skip factor" of 4when it formats the disk.
This notes on the disk that the computer should
skip 4"physical" sectors between each "logical"
sector:
PHYSICAL LOGICAL
SECTOR SECTOR
11
212
35
416
59
62
713
86
917
10 10
11 3
12 14
59
TECHNICAL INFORMATION
PHYSICAL LOGICAL
SECTOR SECTOR
13 7
14 18
15 11
16 4
17 15
18 8
JSR [$C004]
Thus, after reading Sector 1, the Computer will
skip "physical" sectors 2, 3, 4, and 5. The second
"logical" sector it reads will be "physical" Sector 6.
Askip factor of 4 is the optimum setting for
BASIC LOADs and SAVEs. However, if you're not
using BASIC, you might be able to use afaster
skip factor. For example:
DSKINI 0r 3
tells the Computer to skip 3physical sectors
between each logical sector.
.Vote: It's difficult to determine the optimum skip fac-
tor. We recommend you leave it at 4unless you have
agood understanding of how it works.
MACHINE-LANGUAGE DISK
PROGRAMMING
The disk system contains amachine-language
routine called DSKCON which you can call for all
disk input/output operations. To call this routine,
you need to write instructions to the Color Com-
puter's 6809 Microprocessor.
See "Using Machine-Language Subroutines" with
Color BASIC in Getting Started with Color BASIC
for the procedures to use in accessing amachine-
language subroutine. See 6809 Assembly Lan-
guage Programming, by Lance Leventhal
(published by Osborne/McGraw-Hill) for the spe-
cific 6809 instructions.
Information on DSKCON
DSKCON's entry address is stored in locations
C004 and C005 (hexadecimal). You can call it with
this assembly-language instruction:
DSKCON's parameters are located in six memory
locations, organized as follows:
DCOPC RMB 1
DCDRV RMB 1
DCTRK RMB 1
DSEC RMB 1
DCBPT RMB 2
DCSTA RMB 1
The address of the first, DCOPC, is contained in
locations C006 and C007 (hexadecimal). You can
use the first five memory locations to pass param-
eters to DSKCON. DSKCON returns astatus byte
to the sixth location, DCSTA.
These are the parameters you can pass to the first
five memory locations:
DCOPC Operation Code
=Restore head to track
1=No operation
2=Read sector
3=Write sector
DCDRV Drive Number
to 3
DCTRK Track Number
to 34
DCSEC Sector Number
1to 18
DCBPT Buffer Pointer
the address of a256-byte buffer. For read
sector, the data is returned in the buffer.
For write sector, the data in the buffer is
written on the disk.
This is the meaning of the status byte which the
DSKCON routine returns to location DCSTA:
DCSTA Status
Bit 7=1Drive Not Ready
Bit 6=1Write Protect
Bit 5=1Write Fault
Bit 4=1Seek Error or Record Not
Found
Bit 3=1CRC Error
Bit 2=1Lost Data
60
TECHNICAL INFORMATION
If all the bits contain 0, no error
occurred. (See the disk service manual
for further details on the error bits)
After returning from DSKCON, you can turn off
the drive motor by putting the value of in the
memory location FF40 (hex).
Sample Programs Using DSKCON
This program uses DSKCON to restore the head
to track 0:
RLDX $C00G SET XAS APOINTER TO THE
PARAMETERS
CLR ,){ DCOPC =0 FOR RESTORE
LDA 9\ DCDRO =1 TO SELECT DRIVE
ONE
STA 1»x
JSR ttcoaa] CALL DSKCON
IDA #$0Q TURN OFF THE DRIVE MOTOR
STA $FF40
TBT GtX CHECK FOR ERRORS
BNE ERRORS GO REPORT THE ERRORS
RTS
LDA *$i)5 "E" FOR ERROR
STA *41D TOP RIGHT OF THE DISPLAY
RTS
This program uses DSKCON to read track 3, sec-
tor 17 of drive into memory locations 3800
through 38FF:
LDX $C00B
LDA *2
STA ,X
CLR 1tX
LDA «3
STA 2,X
LDA *17
STA 3.X
LDU **3B00
SET XAS APOINTER TO THE
PARAMETERS
DCOPC =2FOR READ ASECTOR
SELECT DRIVE
SELECT TRACK 3
SELECT SECTOR 17
DCBPT=3B00(HEX) FOR
STORING DATA
STU a,x
JSR [*C004] CALL DSKCON
LDA »$00 TURN OFF THE DRIVE MOTOR
STA SFF40
TST BtX CHECK FOR ERRORS
BNE ERRORS GO REPORT THE ERRORS
RTS
LDA **45
STA $aiD
RTS
"E" FOR ERROR
TOP RIGHT OF THE DISPLAY
CNote: DSKCON preserves the contents ofall registers
except CC.
You can write asimilar program to write to asec-
tor by setting DCOPC to 3instead of 2.
Saving aMachine-Language
Program
You can use the SAVEM command to store a
machine-language program on disk. You need to
specify where in memory the program resides (its
starting and ending addresses). You also need to
specify the address where it should be executed.
Use the hexadecimal numbers for all of these
addresses.
For example, let's assume you have amachine-
language program which resides in addresses
5000-5FFF of memory. The address where it
should be executed is 500A. You would store this
program on disk by typing:
SAVEM "PROG/MAC" >&H5000 ,&H5FFF ,1H500A
To load it back into memory, you could use the
LOADM command:
LOADM "PROG/MAC"
This would load "PROG MAC" back into memory
locations 5000-5FFF. The Computer would begin
executing it at location 500A.
If you want to load it into adifferent memory loca-
tion, you could specify an offset address to add to
the program's loading address. For example:
LOADM "PROG/MAC" ,1000
would load "PROG/MAC" into memory locations
6000-6FFF. The Computer would begin executing
it at address 600A.
61
TECHNICAL INFORMATION
SPECIAL INPUT/OUTPUT
COMMANDS
BASIC offers two special input/output commands.
These commands input and output data directly to
aparticular sector. They do this through bypass-
ing the entire disk's filing system.
The first, DSKI$, inputs the data from the sector
you specify. This is its format:
DSKI$ drive number, track, sector, string vari-
ablel, string variable2
The first 128 bytes of the sector are input into
string variablel. The second 128 bytes are input
into string variable2. For example:
50 EXT$(0)
60
DSKI$ 0, 17, 1,A*, B$ (ENTER)
inputs the contents of sector 1, track 17 of the disk
in drive 0. It inputs the first 128 bytes into A$ and
the second 128 bytes into B$. After typing this
command, you can display the contents of this sec-
tor with:
PRINT A$i B$ (ENTER)
Since DSKI$ will read any sector on the disk, it is
the only BASIC command which will read the
directory sector. This sample program uses DSKI$
to search the directory for filenames with the
extension "DAT":
10 FOR X=3TO 11
20 DSKI$ 0,17»X»A$»B$
30 C$ =A$ +LEFT$(B$»127)
40 NAH$(0) =LEFT$(C$,8)
=MID*(C*,9,3)
TO 7
=MID$(C*»N*32+1 ,8)
=MID$(C$,9+N*32»3)
FOR N=l
70 NAM*(N)
80 EXT$(N)
90 NEXT N
100 FOR N=0 TO 7
110 IF EXT$(N) ="DAT" AND
LEFT*(NAM$(N) ,1)<>CHR$(0) THEN PRINT
NAM$(N)
120 NEXT N
130 NEXT X
The second command, DSKO$, outputs data
directly to the sector you specify. Since it bypasses
the disk filing system, it will output data without
opening afile and listing its location in the direc-
tory. For this reason you need to be careful:
1. not to output data over the directory sectors
unless you no longer plan to use the directory.
2. not to output data over other data you presently
have stored on the disk.
The format of DSKO$ is:
DSKO$ drive number, track, sector, stringl,
string2
Stringl will go in the first 128 bytes of the sector.
String2 will go in the next 128 bytes. For example:
DSKO* 0, 1. 3, "FIRST STRING", "SECOND
STRING" (ENTER)
Outputs data to sector 3, track 1, on the disk in
drive 0. "FIRST STRING" will go in the first 128
bytes of this sector. "SECOND STRING" will go in
the second 128 bytes.
62
AIPDPEMMIXEi
APPENDIX A.
PROGRAMMING EXERCISE
ANSWERS
PROGRAMMING EXERCISE #5-1
10 PRINT: PRINT "CHECKS FOR CAR EXPENSES"
20 OPEN "I" ,*1 ."CHECKS"
30 IF E0F( 1) =-1 THEN 100
40 INPUT *1 ,A$,B,C$
50 IF C$ ="CAR" THEN 70
60 GOTO 90
70 PRINT: PRINT "CHECK PAYABLE T0:"iA$
80 PRINT "AMOUNT:" SB
90 GOTO 30
100 CLOSE *1
PROGRAMMING EXERCISE #6.1
10 OPEN "I" ,«1 t"ANIMALS/DAT"
20 OPEN "0"
t
»2 >"NEW/DAT"
30 IF EOF(l) =-1 THEN 70
40 INPUT *1 .A*
50 WRITE «2i A*
G0 GOTO 30
70 CLOSE «1: CLS
80 PRINT "INPUT ANIMALS YOU WANT TO ADD"
90 PRINT "PRESS <ENTER> WHEN FINISHED"
100 INPUT A*
110 IF A* ="" THEN 140
120 WRITE «2, A$
130 GOTO 80
140 CLOSE *2
150 KILL "ANIMALS/DAT"
160 RENAME "NEW/DAT" TO "ANIMALS/DAT"
PROGRAMMING EXERCISE #6.2
10 OPEN "I" .*1 ,"ANIMALS/DAT"
20 OPEN "0" ,#2. "NEW/DAT"
30 IF EOF(l) =-1THEN 100
40 INPUT *1 ,A$
50 PRINT: PRINT A$
60 INPUT "DO YOU WISH TO DELET
70 IF R$ ="YES" THEN 90
80 WRITE *2, A$
90 GOTO 30
1021CLOSE *1
HE1CLOSE *2
1201KILL "ANIMALS/DAT"
1301RENAME "1NEW/DAT" TO "ANIMA
THIS" R$
PROGRAMMING EXERCISE #6.3
10 CLS: PRINT
20 PRINT "(1)
"DO YOU WISH TO --
STORE ANEW FILE"
30 PRINT "(2) SEE THE FILE"
40 PRINT "(3) END"
50 INPUT 01
60 ON 01 GOTO 80. 130, 420
70 GOTO 10
80 OPEN "0". tli "MEMBERS/DAT"
90 1:OSUB 430
100 IF N$ ="" THEN CLOSE *1: GOTO 10
110 WRITE *1 ,N$, A$. P$
120 GOTO 90
130 OPEN "I" ,*1 ,"MEMBERS/DAT"
140 OPEN "0" i*2i "TEMP/DAT"
150 CLS :INPUT "DO YOU WANT TO CHANGE THE
FILE"! 02$
160 IF EOF(l) =-1 THEN 320
170 INPUT *li N$. A* ,P$
180 PRINT: PRINT "NAME :" N$
190 PRINT "ADDRESS :" A$
200 PRINT "TELEPHONE :" P$
210 IF 02$ ="NO" THEN 300
220 PRINT: PRINT "DO YOU WISH TO:"
230 PRINT "1) CHANGE THE ADDRESS?"
240 PRINT "2) DELETE THE MEMBER?"
250 PRINT "3) GO ON TO THE NEXT MEMBER?"
2G0 INPUT N
270 ON NGOTO 290. 160, 300
280 GOTO 230
290 INPUT "INPUT NEW ADDRESS"! A$
300 WRITE *2, N$» A$, P$
310 GOTO 160
320 PRINT: INPUT "DO YOU WISH TO ADD ANEW
MEMBER" i03$
330 IF 03$ ="NO" THEN 380
340 GOSUB 430
350 IF N$ ="" THEN 380
360 WRITE #2, N$, A$, P$
370 GOTO 340
380 CLOSE *1 .*2
390 KILL "MEMBERS/DAT"
400 RENAME "TEMP/DAT" TO "MEMBERS/DAT"
410 GOTO 10
420 END
430 CLS: PRINT "PRESS <ENTER> WHEN FINISHED
:PRINT
440 INPUT "NAME OF MEMBER:" iN$
450 IF N$ ="" THEN 480
460 INPUT "ADDRESS:"! A$
470 INPUT "PHONE NUMBER:" iP$
480 RETURN
PROGRAMMING EXERCISE 7.1
10 OPEN "D"
.
«1. "NAMES/DAT
20 WRITE «1 ,"J. DOE"
30 PUT *1 ,2
31 WRITE *1 ,"BILL SMITH"
32 PUT *1 ,3
34 GET «1 ,3
36 INPUT *1 .A$
38 PRINT A$
40 CLOSE *1
64
.APPENDIX A
PROGRAMMING EXERCISE 7.2
This produces an FD Bad File Data error in line
36. The first field in record 2 is "FLIES," astring. Line
36 INPUTs it into N, anumeric variable.
PROGRAMMING EXERCISE 7.3
10 OPEN "D" ,«1 ,"NAMES/DAT"
20 GOTO 70
30 FOR X=1TO 10
40 PRINT: PRINT "RECORD" X
50 GOSUB 180
G0 NEXT X
70 INPUT "WHICH RECORDd-10)"
80 IF X>10 THEN 170
80 IF X <1THEN END
100 GET #1 iX
110 INPUT *li N*. A*. C»i S$i
120 PRINT: PRINT "RECORD" X
130 PRINT N*, ,A*,.C*,,S*,,Z*
140 INPUT "DO YOU WANT TO CHANGE THIS"! R*
150 IF R* ="YES" THEN GOSUB 180
1B0 GOTO 70
170 CLOSE «1: END
180 INPUT "NAME" iN*
"ADDRESS "i A$
'CITY :"i C$
'STATE: 1'! S*
'ZIP :"i Z*
N*. A*. C$i
X
Z$
190 INPUT
200 INPUT
210 INPUT
220 INPUT
230 WRITE »1
240 PUT «1 ,X
250 RETURN
S*: 1$
PROGRAMMING EXERCISE #9.1
10 OPEN "D" ,81 ,"MAIL/DAT" ,57
20 FIELD 81,15 AS LAST*. 10 AS FIRST*, 15 AS
ADDRESS* .10 AS CITY* ,2 AS STATE* .5 AS ZIP*
+130 R=R
40 CLS
50 INPUT
G0 INPUT
70 INPUT
80 INPUT
90 INPUT
100 INPUT
110 LSET LAST*
120 LSET FIRST*
LAST NAME'SL*
FIRST NAME" iF*
ADDRESS" !A*
CITY" iC*
STATE" iS*
"ZIP CODE"iZ*
L*
F*
140 LSET CITY* =C*
150 LSET STATE* =S*
160 LSET ZIP* =Z*
170 PUT #1 ,R
180 PRINT
190 INPUT "MORE DATA( Y/N) "iAN*
200 IF AN* ="Y" THEN 30
210 CLOSE *1
PROGRAMMING EXERCISE #9.2
10 OPEN "D"i «1. "MAIL/DAT". 57
20 FIELD *1. 15 AS LAST*, 10 AS FIRST*:,15 AS
ADDRESS*. 10 AS CITY*. 2AS STATE*, 5AS ZIP*
30 R=R+1
40 CLS
50 GET *1 ,R
60 PRINT LAST* "," FIRST*
70 PRINT ADDRESS*
80 PRINT CITY* "." STATE*
90 PRINT ZIP*
100 PRINT
110 IF LOF(l)=R THEN 140
120 INPUT "PRESS <ENTER> FOR NEXT NAME"'!E*
130 GOTO 30
140 CLOSE #1
PROGRAMMING EXERCISE #9.3
,5 AS POP*
10 OPEN ''D" ,#1 ."POP" .15
20 FIELD *1 ,10 AS COUNTRY*
30 R=R+1
40 CLS
50 INPUT "COUNTRY" !C*
60 INPUT "POPULATION" !P
70 LSET COUNTRY* =C*
80 LSET POP* =MKN*(P)
85 PUT *1 ,R
90 PRINT
INPUT "MORE DATA(Y/N)'100
110 IF AN* =
120 CLOSE *1
iAN*
"Y" THEN 30
PROGRAMMING EXERCISE #9.4
10 OPEN "D" ,#1 ,"POP" ,15
20 FIELD «1 .10 AS COUNTRY*,
30 R=R+1
40 GET 81 ,R
50 PRINT COUNTRY*,
5AS POP*
CON (POP*)
130 LSET ADDRESS* A*
60
70
IF LOFUJOR
CLOSE 81
THEN 30
65
APPENDIX B.
CHAPTER CHECKPOINTANSWERS
CHAPTER 2
1. Unless the disk has been formatted, there is no way
to locate any given area on the disk.
2. The disk directory is an index of the names, loca-
tions, and types of all the files on the disk.
3. Adisk file is an individual block of information
stored on the disk, under afilename.
4. Information stored in memory will only be there
temporarily. It will be destroyed if the Computer is
turned OFF or if you execute aNEW, LOAD, DIS-
KINI, BACKUP, or COPY command. (We'll discuss
BACKUP and COPY in the next chapters). Infor-
mation stored on disk will be there permanently. It
won't be destroyed if the Computer's turned off or if
memory is cleared. (Don't leave adisk in the drive
when you turn the Computer off. We'll explain why
in the next chapter.)
5. The only way to change the contents of adisk file is
by storing different information under the same
filename.
CHAPTER 3
1. Turning the Computer ON or OFF while the disk is
in its drive may damage the disk.
2. Only felt tip pens may be used to write on the disk's
label. Hard point pens and pencils may damage the
disk and garble the information on it.
3. Error messages tell you that something is wrong
with either the program you are running or the last
command that you used.
4. "Write-protecting" is away of protecting your disks
from alteration. It is done by putting agummed label
over the write-protect notch. You can read from a
"write-protected" disk, but you can't write to it.
5. On aone-drive system, insert the source disk into the
drive and type BACKUP0 (ENTER) .The Computer will
ask you to insert the destination disk and press
(ENTER) .This procedure is repeated until the Com-
puter prints OK. On amulti-drive system, type the
BACKUP command specifying the drive number
with the source disk and the destination disk. For
example, BACKUP TO 1backs up the source disk
(in Drive 0) to the destination disk (in Drive 1).
CHAPTER 4
1. Afile can be renamed with the RENAME command.
For example, RENAME "OLDFILE/NAM" TO
"NEWFILE/NAM" renames OLDFILE/NAM to
NEWFILE/NAM. You must specify the extension for
both filenames so the Computer can find them.
2. You can find out how much space you have remain-
ing on the disk by typing PRINT FREE ()(ENTER) .This
will tell you the number of granules left on the disk
in Drive 0. If you are running out of granules, you
might want to KILL afew files or switch to another
disk.
3. Unless otherwise specified, the Computer always
uses Drive 0. This can be changed by typing DRIVE
1, which enables you to access Drive 1without hav-
ing to specify the number in your command, (i.e.,
now DIR and DIR1 would both get you the directory
of the disk in Drive 1.
CHAPTER 5
1. Buffer #1 is atemporary storage area for informa-
tion going between the disk and memory.
2. Adisk file must be OPENed before any information
can go between the disk and memory.
3. Adisk must be CLOSEd so that the information still
in the buffer will end up where it's supposed to and
so that the file can be reopened. All files must be
closed before you switch disks.
4. Afile OPENed for input allows information to go
from the disk file into the memory of the Computer.
Afile OPENed for output allows information to go
from memory to the disk file.
CHAPTER 6
1. When you OPEN a"sequential access" file, you can
only OPEN it for "I" or "O"—not both. You can't out-
put to afile opened for "I," nor can you input from a
file opened for "O."
2. No. The file must first be closed and then reopened
for input.
66
.APPENDIX B
CHAPTER 7
1. Records are equal-sized divisions in your disk file
where you can put your data. Since each is the same
size, the Computer can use them to access your data
directly.
2. Fields are subdivisions of records.
3. In asequential access file, the only locations the
Computer knows are the beginning and ending of
the file. In adirect access file, it can determine where
each individual record is (by the size of the records).
4. Since each record of the file has aknown location, the
Computer can access it without going through the
preceding parts of the file, as it would if the file was
sequential.
5. Acomma causes the Computer to space over to the
next print column before printing another data item.
6. Asemicolon causes the Computer to print the data
items immediately next to each other.
7. Astring is printed simply as the string itself. It is not
enclosed in quotation marks.
CHAPTER 9
1. The Computer will set the record length at 256 bytes.
2. The data must have afield with aspecific length for
it to be LSET This length is assigned in the FIELD
line.
3. MKN$ converts anumber into a5-byte coded string.
CHAPTER 8
1. The minimum size of adisk file is 2,304 bytes (one
granule). Since the Computer allocates disk space in
granules, afile can be no smaller than one granule.
2. The Computer first WRITEs the number's sign (a
minus sign if it's negative or ablank space if it's pos-
itive). Then it WRITEs the number itself. Immedi-
ately following the number, it WRITEs on trailing
blank space.
3. Astring is written with quotation marks around it.
4. INPUT inputs only the data items listed, while LINE
INPUT inputs everything up to the (ENTER) character.
CHAPTER 10
1. You must type an Aat the end of your SAVE com-
mand if you plan to ever MERGE it with aprogram
in memory.
2. The line number of the program saved on disk
prevails.
3. The Computer reserves two buffers when you power-
up.
4. The Computer reserves atotal of 256 bytes of buffer
space when you power-up.
5. FILES 3, 3000 get the Computer to reserve 3buffers
with atotal of 3000 bytes of buffer space.
67
APPENDIX C.
SAMPLE PROGRAMS
SAMPLE PROGRAM #1
BALANCING YOUR CHECKBOOK
This program creates amaster disk file which contains
all your checks and deposits for the entire year. You can
print them out by the month or the year. If you want to
use your printer, change the appropriate PRINT lines
to PRINT #-2. (See Chapter 21 in Getting Started
with Color BASIC).
10 'Checkbook Program
20 '
30 'This program provides a
recordofyour chec k s?
40 'deposits? and balances.
The checks can be labeled
50 'with an account number to
show to what expense
60 'they were paid* such as
medical ?rent ?food? etc
.
70 'The program uses direct
addressing? each file record
80 'being 40 bytes long? and
formatted as follows! 8
90 'bytes for the date? 4bytes
for the check or deposit
100 'slip number? 20 bytes for
the recipient of the check
110 73bytes for the account
number? and 5bytes for the
120 'amount of the check or
deposi t
.
130 '
140 CLEAR 1000
150 DIM CHK*<50)
160 CLS
170 PRINT 3107? "SELECTIONS:"
180 PRINT a162? "1) ADD CHECKS
TO YOUR FILE"
190 PRINT a194? "2) LIST YOUR
CHECKS? DEPOSITS?
"
200 PRINT a229? "AND BALANCES"
230 PRINT 3322? "3) END JOB?"
240 PRINT a394? "(1?2? OR 3>"
250 AN*= INKEY*
260 IF AN*="" THEN 250
270 ON VAL(AN*) GOSUB 310? 700?
1080? 1560
280 GOTO 160
290 '
300 '
31'This subroutineinputs
the data.
320 '
330 OPEN "D" ?#1 ?"CHECKS/DAT" ?40
340 FIELD #1?8 AS DATE*? 4AS CHNO*?
20 AS PDTO*? 3AS ACNO*? 5AS AMT*
350 REC =L0F<1)
360 REC =REC +1
370 CLS
380 PRINT a 64? "CHECK OR
DEPOSIT (C/D)"
390 AN* =INKEY*
400 IF AN* ="D" THEN 430
410 IF AN* ="C" THEN 490
420 GOTO 390
430 INPUT "DEPOSIT DATE
(MM/DD/YY)";D*
440 INPUT "DEPOSIT SLIP NUMBER
<NNNN )";C*
450 P* ="
"
460 INPUT "ACCOUNT NUMBER* NNN) "? A*
470 INPUT "AMOUNT OF DEPOSIT" 5AMT
480 GOTO 550
490 INPUT "CHECK DATE (MM/DD/YY) ";D*
500 INPUT "CHECK NUMBER <NNNN >"? C*
510 INPUT "PAID TO" ?P*
520 INPUT "ACCOUNT NUMBER <NNN) ";A*
530 INPUT "AMOUNT OF CHECK"; AMT
540 AMT =-AMT
550 LSET DATE* =D*
560 LSET CHNO* =C*
570 LSET PDTO* =P*
580 LSET ACNO* =A*
590 LSET AMT* =MKN* (AMT
)
600 PUT #1?REC
61.0 PRINT 3320? "MORE INPUT(Y/N)"
620 AN* =INKEY*
630 IF AN* ="N" THEN 660
640 IF AN* ="Y" THEN 360
650 GOTO 620
660 CLOSE #1
670 RETURN
680 '
690 '
700 'This subroutine balances the
checkbook and outputs the results.
710 '
720 OPEN "D" ?#1 ?"CHECKS/DAT" ?40
730 FIELD #1,8 AS DATE*? 4AS CHNO*?
20 AS PDTO*? 3AS ACNO*? 5AS AMT*
740 CLS
750 PRINT 3160? "DO YOU WANT A
LISTING FOR AMONTH OR FOR THE"
760 PRINT 3192? "WHOLE YEAR? (Y/M)"
770 INPUT A*
780 IF A* ="M" THEN PRINT 3254?
68
-APPENDIX C
"WHAT MONTH(MM)" :INPUT MN*
790 BAL =
800 FOR REC =1TO LOF (
1
)
810 GET #1,REC
820 BAL =BAL +CVN(AMT*)
830 IF A* ="M" AND LEFT*< DATE** 2)
<> MN* THEN 1030
840 CLS
850 IF PDTO* ="
THEN 930
860 PRINT a645 "DATE OF CHECK:":
PRINT a84, DATE*
870 PRINT "CHECK NUMBER: ": PRINT
3116,CHN0*
880 PRINT "PAID TO:" ."PRINT a
148, PDTO*
890 PRINT a160> "ACCOUNT NUMBER:":
PRINT 3180,ACNO*
900 PRINT "AMOUNT OF CHECK: ": PRINT
3211, USING "**###.##" ;-CVN<AMT*>
910 PRINT "BALANCE:" :PRINT a243,
USING "**###„##"*; BAL
920 GOTO 980
930 PRINT:PRINT:PRINT "DATE OF
DEPOSIT:" SPRINT 385, DATE*
940 PRINT "DEPOSIT SLIP NUMBER:":
PRINT 3117,CHN0*
950 PRINT "ACCOUNT NUMBER: ": PRINT
3149,ACN0*
960 PRINT "AMOUNT OF DEPOSIT:":
PRINT a180, USING "**###.##";
CVN<AMT*>
970 PRINT "BALANCE:" :PRINT a
212,US ING "**### .##''; BAL
980 PRINT a256, "PRESS <ENTER>
FOR NEXT RECORD OR <R> TO RETURN
TO 'SELECTIONS'"
990 AN* =INKEY*
1000 IF AN* =CHR*(13) THEN 1030
1010 IF AN* ="R" THEN 1040
1020 GOTO 990
1030 NEXT REC
1040 CLOSE #1
1050 RETURN
1540 '
1550 '
1560 'This subroutine terminates
the pro gram.
15 70 '
1580 END
SAMPLE PROGRAM #2
SORTING YOUR CHECKS.
This subroutine will be especially helpful at tax time.
It takes the checks file which you created in "Sample
Program #1" and sorts all the checks by account. Want
to know exactly how much you spent on medical bills
(or business expenses, contributions, etc.)? This pro-
gram will let you know right away.
210 PRINT a258, "3) SORT YOUR
CHECKS BY"
220 PRINT 3293, "ACCOUNT NUMBER?"
230 PRINT a322, "4) END JOB?"
240 PRINT 3394, "(1,2, 3, OR 4)"
270 ON VAL(AN*> GOSUB 310,700.
1080, 1560
1060 '
1070 '
1080 'This subroutine sorts the
checks from those with the
1090 'smallest account numbers
to the largest account numbers
1100 'using a"bubble sort".
Each check is handled as one
1110 'data string to make the
swaps easier.
1120 '
1130 OPEN "D",#l, "CHECKS/DAT", 40
1140 FIELD #1,40 AS INFO*
1150 FOR 1=1 TO LOF(l)
1160 GET #1,
I
1170 CHK*(I) =INFO*
1180 NEXT I
1190 CNT =
1200 FOR I=1TO LOFU) -1
1210 IF MID*(CHK*(I),33,3> <=
MID*<CHK*<I+1),33,3> THEN 1260
1220 TEMP* =CHK*(I)
1230 CHK*<I) =CHK*<I+1)
1240 CHK*(I+1) =TEMP*
1250 CNT =1
1260 NEXT I
1270 IF CNT =1THEN 1190
1280 CLS
1.290 PRINT 3194, "WHAT ACCOUNT
NUMBER (NNN/ ALL)"
1300 INPUT AN*
1310 FOR I=1TO LOF(l
)
1320 IF AN* <> "ALL" AND AN* <>
MID*(CHK*<I>,33,3) THEN 1510
1330 CLS
1340 PRINT 366, "ACCOUNT NUMBER:"
:PRINT a85,MID*(CHK*(I),33,3>
1350 IF MID*(CHK*(I ), 13,20) =
"THEN 1410
1360 PRINT a98, "DATE OF CHECK:":
PRINT a117,LEFT*<CHK*(I),8)
1370 PRINT 3130, "CHECK NUMBER:"
:PRINT a149,MID*<CHK*<I),9,4)
1380 PRINT a162, "PAID TO:":
69
APPENDIX C.
PRINT a181, MID*<CHK*(I>, 13,20)
1390 PRINT 3194 i"AMOUNT OF CHECK:
PRINT a212, USING "**###.##";
-CVN<RIGHT*<CHK*(I>,5)
)
1400 GOTO 1440
1410 PRINT a98? "DATE OF DEPOSIT:"
PRINT a117,LEFT*<CHK*<I>,8)
1420 PRINT 3130, "DEPOSIT NUMBER:"
PRINT a149,MID*<CHK*(I),9,4>
1430 PRINT 3162* "AMOUNT
OF DEPOSIT: "
:
PRINT 3180 ,USING "**###.
CVN<RIGHT*(CHK*<I>,5> )
1440 PRINT 3290, "(PRESS
TO SEE NEXT"
1450 PRINT 3322? "RECORD OR <R> TO
RETURN TO"
1460 PRINT 3354, "'SELECTIONS' )"
A2* =INKEY*
IF A2* =CHR*<13>
IF A2* ="R" THEN
GOTO 1470
##"
<ENTER
>
1470
1480
1490
1500
THEN
1520 1510
1510 NEXT I
1520
1530 CLOSE #1
RETURN
SAMPLE PROGRAM #3
MEMBERSHIP LIST
Want to store the names and telephone numbers of all
your club members? This program puts them all in a
disk file in alphabetical order. Add a few lines to it, and
it will store their addresses and phone numbers also.
10 'Create list and alphabetize.
20 '
30 'The object of this program
is to create afile of
40 'alphabetically arranged names
and phone numbers. The
50 'names and numbers are first
input into an array, ARRAY* (I)
,
60 'then put into alphabetical
order, and finally put into
70 'adisk file called "NAMES/NOS".
The file is 35 bytes
80 'lor.9, all of it allotted to
one variab 1e, INFO*. The
90 'file can be added to anytime
afterit s c reationan d will
100 'automatically be alphabetised.
The program can be used
110 'in conjunction with the "Search
a1ist"program(sampl
e
120 'program #4)
.
130 7
140 CLEAR 1050
150 DIM ARRAY*<30)
160 OPEN "D",#l, "NAMES/NOS", 35
170 FIELD #1,35 AS INFO*
180 •}
190 'First the file is checked
to 2:.ee if there are any
200 'records currently on it.
210 t
220 IF L0F(1) =THEN 1=1: GO TO 310
230 FOR 1=1 TO LOF(l)
240 GET #1,1
250 ARRAY* U) =INFO*
260 NEXT I
270 t
280 'The new names and numbers
are input and then concatenated
290 into 1stringi ARRAY* (I)
300 •J
310 CLS
320 PRINT a64
330 INPUT "LAST NAME"?L*
340 INPUT "FIRST NAME" 5F*
350 INPUT "MIDDLE INITIAL" ;M*
360 INPUT "AREA CODE" 5A*
370 INPUT "PHONE NUMBER" ?P*
380 ARRAY*(I) =LEFT*<L*+" ,"+F*+" "
+M*+" ",24)+A*+P*
390 PRINT a288, "MORE DATA <Y/N>?"
400 AN* =INKEY*
410 IF AN* ="Y" THEN 1=1+1 :
GOTO 310
420 IF AN* ="N" THEN 470
430 GOTO 400
440 •>
450 'Then, ARRAY*(I) is put into
al ptiabetical order.
460 '
470 FOR J=l TO I
480 FOR K=J TO I
490 IF ARRAY* (J)
THEN 530
ARRAY* (K)
500
510
520
530
540
55'
560 '
fer r ed
570 '
580 FOR N=l TO
590 L.SET INFO*
600 PUT #1,N
TEMP* =ARRAY* <J)
ARRAY*(J) =ARRAY*(K)
ARRAY* <K> =TEMP*
NEXT K
NEXT J
Fi nal 1y,the list
into "NAMES/NOS".
tran s -
ARRAY* (N)
70
.APPENDIX C
610 NEXT N
620 CLOSE #1
630 END
SAMPLE PROGRAM #4
SEARCH FOR ANAME
Since the file you created in "Sample Program #3" is
already in alphabetical order, you can immediately
find the name you want. This program shows how.
10 'Search a1ist
20 '
30 '(NOTEs This program requires
that afile called "NAMES/NOS
40 'exists see "Create list and
alphabetize Sample program #3)
50 'This program searches adisk
file which holds names and
60 'phone numbers in alphabetical
order. The file is adirect
70 'access file called "NAMES/NOS",
is 35 bvtes long* and
80 'is formatted as follows: 24
bvtes for the name; 3bvtes
90 'for the area code? 8bvtes
for the phone number. The
100 'program uses iterative
searching.
110 '
120 OPEN "D",#l, "NAMES/NOS" ,35
130 FIELD #1,24 AS NAME*, 3AS
AREA*, 8AS PHONE*
140 CLS
150 PRINT 399 ,"ENTER NAME(LAST,
FIRST MI)
160 LINE INPUT NM*
170 '
180 'Initialization of variables
190 *
200 Nl* =NM*
210 IF LEN(NM*> <24 THEN 800
220 IF LEN(NM*) >24 THEN 820
230 FIRST =1
240 MID -INT( (L0F(l)+l)/2)
250 LAST =LOF(l)
260 CNT =
270 '
280 'Program checks the last
record first because it won't
290 'be checked in the regular-
search
300 '
310 GET #1,LAST
320 IF NAME* =NM* THEN 450
330 '
340 'Program keeps comparing NM*
with NAME* from record MID
350 'until NM* is found or enough
records have been seen
360 'to show that it isn't in
the file
370 '
380 GET #1,MID
390 IF CNT >(L0F(l)+l)/2 THEN 710
400 IF NAME* <NM* THEN 570
410 IF NAME* >NM* THEN 640
420 '
430 'When NM* is found it is
printed out
440 '
450 CLS
460 PRINT 3104, NAME*
470 PRINT a136, "(" ?AREA* 5" )" ;PHONE*
480 PRINT 3195, "PRESS <ENTER>
TO CONTINUE,
"
490 PRINT 3227, "ELSE PRESS <Q>
TO QUIT"
500 AN* =INKEY*
510 IF AN* ="Q" THEN CLOSE: END
520 IF AN* =CHR*(13) THEN 140
530 GOTO 500
540 '
550 'Subprogram for when NAME*<NM*
560 '
570 FIRST =MID
580 MID =(MID+LAS'D/2
590 CNT =CNT +1
600 GOTO 380
6.1.0 '
620 'Subprogram for when NAME*>NM*
630 '
640 LAST =MID
650 MID =<MID+FIRST)/2
660 CNT =CNT +1
670 GOTO 380
680 '
690 'Subprogram for when NM* is
not foun
d
700 '
710 CLS
720 PRINT 3100, Nl*;" NOT FOUND"
730 PRINT 3132, "TO TRY AGAIN
PRESS <ENTER>"
740 AN* =INKEY*
750 IF AN* =""THEN 740
760 GOTO 140
770 '
780 'Subprograms for modifving
NM* to a20 bvte string
71
APPENDIX C.
790 '
800 NM* =NM*+" "
810 GOTO 210
820 NM* =LEFT* (NM*, 24)
830 GOTO 220
SAMPLE PROGRAM #5
UPDATE THE LIST
Update anything you want in the file you created in
"Sample Program #3." You can do it in ahurry with
this program.
10 'Edit your names file
20 '
30 'The object of this program
is to edit the "NAMES/NOS" file
40 'from "Create list and alpha-
betize" (Sample program #3). The
50 'program can either retain a
record vchange one of the variables
60 'in that record? or delete the
record entirely from the file.
70 '
80 CLS
90 PRINT 3106, "SELECTIONS:"
100 PRINT 3I685 "1) EDIT RECORD"
110 PRINT a200, "2) DELETE RECORD"
120 PRINT 3232, "3) END JOB"
130 PRINT 3298, "1,2, OR 3"
140 AN* =INKEY*
150 IF AN*="" THEN 140
160 ON VAL(AN*) GOSUB 180,590,850
170 GOTO 80
180 OPEN "D",#1,"NAMES .NOS ",35
190 FIELD #1,24 AS NAME*, 3AS AREA*,
8AS PHONE*
200 FOR 1=1 TO LOF(l)
210 GET #1,
I
220 CLS
230 PRINT 368, "RECORD NUMBER:" ;I
240 PRINT a100, "NAME:" ;NAME*
250 PRINT a132, "AREA CODE:"; AREA*
260 PRINT 3 164, "PHONE NUMBER";
PHONE*
270 PRINT 3228, "EDIT THIS
RECORD? (Y/N)"
280 AN* =INKEY*
290 IF AN* ~"Y" THEN 320
300 IF AN* ="N" THEN 560
310 GOTO 280
320 PRINT 3260, "EDIT NAME? (Y/N)"
330 AN*= INKEY*
340 IF AN* ="N" THEN NM* =NAME*:
GOTO 400
350 IF AN* ="Y" THEN 370
360 GOTO 330
370 LINE INPUT "NEW NAME" ;NM*
380 IF LEN(NM*) <24 THEN NM* =
NM*+ GOTO 380 ELSE 390
390 IF LEN(NM*> >24 THEN NM* =
LEFT* (NM*, 24)
400 PRINT 3292, "EDIT AREA
CODE? (Y/N)"
410 AN* =INKEY*
420 IF AN* ="Y" THEN 450
430 IF AN* ="N" THEN A* =AREA* :
GO TO 460
440 GOTO 410
450 INPUT "NEW AREA CODE"; A*
460 PRINT 3324, "EDIT PHONE
NUMBER? (Y/N)"
470 AN* =INKEY*
480 IF AN* ="Y" THEN 510
490 IF AN* ="N" THEN P* =PHONE* :
GOTO 520
500 GO TO 470
510 INPUT," NEW PHONE NUMBER" ;P*
520 LSET NAME* =NM*
530 LSET AREA* =A*
540 LSET PHONE* =P*
550 PUT #1,1
560 NEXT I
570 CLOSE #1
580 RETURN
590 OPEN "D",#l, "NAMES. NOS", 35
600 FIELD #1,24 AS NAME*, 3AS AREA*,
8AS PHONE*
610 OPEN "D" ,#2, "TEMP/FIL",35
620 FIELD #2,24 AS TNAME*,3 AS
TAREA*, 8AS TPHONE*
630 FOR 1=1 TO LOF( 1
)
640 GET #1,1
650 CLS
6/.0 PRINT 368, "RECORD #";I
670 PRINT a100, "NAME: "5NAMF*
600 PRINT 3132, "AREA CODE:"; AREA*
690 PRINT a164, "PHONE NUMBER:";
PHONE*
700 PRINT 3228, "DELETE THIS
RECORD? (Y/N)"
710 AN* =INKEY*
720 IF AN* ="Y" THEN 800
730 IF AN* ="N" THEN 750
740 GOTO 710
72
.APPENDIX C
750 LSET TNAME* =NAME*
760 LSET TAREA* =AREA*
770 LSET TPHONE* =PHONE*
780 J=J+1
790 PUT #2, J
800 NEXT I
810 CLOSE
820 KILL "NAMES/NOS"
830 RENAME "TEMP/FIL" TO "NAMES/NOS"
840 RETURN
850 END
SAMPLE PROGRAM #6
GRADING TESTS
This program is ideal for teachers. It creates several
disk files of students and their test score. You can then
immediately find averages and standard deviation for
the entire class or for each individual student.
10 'Test pros ram
20 '
30 'The object of this, program
is to input several
40 'files anames file and several
test files.
50 'The files can then he accessed
as desired and the
60 'test scores processed to find
averages and standard
70 'deviations. The files are all
sequential access files.
80 '
90 '
100 'Main module of program
110 '
120 DIM NAME* <30), GRADE <6, 30)
130 CLS
140 PRINT a107," SELECT IONS"
160 PRINT a164, M1) CREATE A
'NAMES' FILE"
170 PRINT a196, H2) ADD ANEW
TEST FILE"
180 PRINT a228, "3) PROCESS SCORES"
190 PRINT a260, H4) END"
210 PRINT a331, "1,2,3 OR 4"
220 AN*=INKEY*
230 IF AN*="" THEN 220
240 ON VAL<AN*) GOSUB 290,430,
640, 1430
250 GOTO 130
260 '
270 'This subroutine builds a
"NAMES" file.
280 '
290 OPEN "0",#1,"NAME/FIL"
300 CLS
310 PRINT a96, "ENTER NAME OF
STUDENT :
320 LINE INPUT NAME*
330 WRITE #1,NAME*
340 PRINT 3196, "(PRESS <ENTER> TO
ENTER" :PRINT 3228, "ANOTHER NAME,
PRESS <0>": PRINT a260, "TO QUIT)"
350 AN*=INKEY*
360 IF AN*="" THEN 350
370 IF AN*O"0" THEN 300
380 CLOSE #1
390 RETURN
400 '
410 'This subroutine builds test
files.
420 '
430 CLS
440 PRINT 364
450 INPUT "NUMBER OF NEW TEST
FILE";TF*
460 IF TF* ="THEN 450
470 TF* ="TEST" +TF*
480 OPEN "I",#1,"NAME/FIL"
490 OPEN "0",#2,TF*
500 IF EOF(l) THEN 560
510 INPUT #1,NAME*
520 PRINT "NAME:"?NAME*
530 INPUT "SCORE" ;SCORE
540 WRITE #2, SCORE
550 GOTO 500
560 CLOSE #1,#2
570 RETURN
580 '
590 'This subroutine inputs the
"NAMES" file and the
600 'desired test files and then
processes them either
610 'on aclass basis or an
individual basis, and
620 'then prints out the results.
630 »
640 OPEN "I",#1,"NAME/FIL"
650 IF EOF(l) =-1 THEN 690
660 Y=Y+1
670 INPUT #1,NAME*(Y)
680 GOTO 650
690 YEND =Y
700 CLOSE #1
710 CLS
720 PRINT 396
730 INPUT "HOW MANY TESTS ARE
THERE" 5N
73
APPENDIX C
740 FOR X=l TO N
750 TF* ="TEST" +RIGHT*(STR*( X),1
)
760 OPEN "I",#1,TF*
770 FOR Y»l TO YEND
780 INPUT #1,GRADE(X,Y)
790 NEXT Y
800 CLOSE #1
810 NEXT X
820 CLS
830 PRINT a130* "INDIVIDUAL TOTALS
OR CLASS"
840 INPUT "TOTALS (I/O"? AN*
850 IF AN* ="I" THEN 900
860 IF AN* ="C" THEN 1130
870 '
880 'This portion processes the
scores bv the student.
890 '
900 FOR Y=l TO YEND
910 CLS
920 PRINT a105>NAME*(Y)
930 PRINT a137 »"SCORES:"
940 STUTOT =
950 FOR X=l TO N
960 PRINT TAB(10) GRADE<X*Y>
970 STUTOT =STUTOT +GRADE(X»Y)
980 NEXT X
990 AVE(Y) =STUTOT /N
1000 NUM =
1010 FOR X=l TO N
1020 NUM =<AVE(Y) -GRADE <Y) >+2
+NUM
1030 NEXT X
1040 SD =SOR(NUM /N)
1050 PRINT USING ""/. /.##.##";
"AVERAGE: "?AVE(Y)
1060 PRINT USING "V. '/.
##.##";» STANDARD DEVIAT ION :";SD
1070 PRINT "PRESS <ENTER> TO SEE
NEXT NAME"
1080 AN* =INKEY*
1090 IF AN* =CHR*<13) THEN 1100
ELSE 1080
1100 NEXT Y
1110 CLS
1120 PRINT 3105? "NO MORE NAMES"
1130 GOTO 1350
1140 '
1150 'This portion processes the
scores bv the test number
1160 'for the whole class.
1170 '
1180 INPUT "WHICH TEST NUMBER" ?X
1190 CLS
1200 PRINT 34»"DATA FOR TEST
NUMBER ";
X
1210 PRINT »NAME" STAB <25) "SCORE"
1220 TTOT =
1230 FOR Y=l TO YEND
1240 TTOT =TTOT +GRADED Y>
1250 PRINT TABU) NAME*( Y) ;TAB<25)
GRADE(X»Y>
1260 NEXT Y
1270 AVE TTOT /YEND
1280 NUM =
1290 FOR Y=l TO YEND
1300 NUM =NUM +(AVE -GRADE <X,Y) H2
1310 NEXT Y
1320 SD =SQR(NUM /(YEND -1))
1330 PRINT: PRINT USING
""/ •/.#•/.•/.##.##"?
"AVERAGE FOR TEST #" ;X ;":"?AVE
1340 PRINT USING "7. "/.
##.##"; "STANDARD DEVIATION: "!SD
1350 PRINT: PRINT "PRESS <ENTER>
FOR MORE"
1360 PRINT "PROCESSING* <Q>
TO QUIT"
1370 AN* =INKEY*
1380 IF AN* =CHR*(13) THEN 820
1390 IF AN* ="Q" THEN 1400
ELSE 1370
1400 RETURN
1410 '
1420 'This subroutine terminates
the program.
1430 '
1440 END
SAMPLE PROGRAM #7
CREATE-A-GAME
These four programs will display 3scenes ahouse
and two rooms. Each scene is stored on disk as apro-
gram file.
10 '"DISPLAY/BAS"
20 '
30 'The ob-Ject of this program
is to show you how you can
40 'access another program from
Your main program. It uses
50 'amain program called
"DISPLAY/BAS" and three graphics
6(3 'pr o gram sca11ed"HOUSE /BAS "»
"FOYER/BAS'S and "STAIRS/BAS"
.
70 '(Natural 1y thev must be on
dis k b efo r eyoucani- u n this
74
-APPENDIX C
80
90
100
110
120
130
140
150
160
170
180
190
200
210
220
THIS
230
240
250
260
270
280
290
program.
)
106?
170,
202,
234
,
266,
330,
INKEY*
u^i
10
CLS
PRINT
PRINT
PRINT
PRINT
PRINT
PRINT
AN* =
IF AN* =
IF AN* =
CLS
PRINT 398,
SELECTION
PRINT 3130, "PRESS ANY KEY"
FOR 1=1 TO 40: NEXT I
ON VAL (AN*) GOTO 260,270,280,290
LOAD "HOUSE /BAS ",R
LOAD "FOYER/BAS",R
LOAD "STAIRS/BAS" ,R
END
"HOUSE /BAS"
"SELECTIONS:"
"1) HOUSE"
"2) FOYER"
"3) STAIRS"
"4) END JOB"
"1,2,3, OR 4"
THEN 180
'THEN 250
'TO RETURN FROM
30
40
50
60
70
3, 1
PMODE
PCLS
SCREEN 1,0
DRAW "BM66 ,108 "D48 ;R32 ;U48 5L32
"
DRAW "BM66,68;R132;BM46,96;R132;
BM50, 156;R128"
80 DRAW "BM50,96;D60;BM178,96?D60;
BM206,88;D50"
90 DRAW "BM0, 136 ;R50; BM206, 136;R50"
(46,96)-(66,68>,PSET
<178, 96>-< 198,68) ,PSET
(198, 68) -(206, 88), PSET
(174, 156)~<206, 136), PSET
CIRCLE (92, 130), 5,0
PAINT (0,0), 3,
4
(0, 149), 1,4
(67,70) ,4,4
(55, 105), 2*
4
(194, 96), 2,
4
(82, 128) ,3,4
INKEY*
IF AN* ="" THEN 210
LOAD "DISPLAY/BAS'SR
100
110
120
130
140
150
160
170
180
190
200
210
220
230
LINE
LINE
LINE
LINE
PAINT
PAINT
PAINT
PAINT
PAINT
AN* =
40
50
60
70
BL4
80
BM2
90
100
110
120
130
140
150
160
170
180
190
200
210
220
230
240
250
260
270
280
290
300
310
320
330
340
350
360
370
380
390
400
410
420
430
440
PMODE 3,
1
SCREEN 1,0
DRAW "BM104,60;D92;R48;U92;L48"
DRAW "BM44,20;R16B;D132;L132;
;L12?BL4?L16;BM44, 102;U82"
DRAW "BM220,60;D100;
44,58?D126"
DRAW "BM42 ,102; D38 ;R8 ;U38 ?L8
"
DRAW "BM16, 148;D40;R4;U40"
DRAW "BM64, 14B;D40;L4;U40"
DRAW "BM80 ,124; D40 ;L4 ?U36
"
CIRCLE (144, 108),
4
(238, 117),
4
(45, 140), 15,4, .3,0, .7
(45,140), 15,4, .3, .95,
1
(53, 136),
4
(0, 192) -< 16, 176), PSET
(20, 172)-(44, 152), PSET
(256, 192)-(212, 152), PSET
(28, 8), 3,
4
(0,0) -(44, 20), PSET
(256, )-(212, 20 ),PSET
(220,60)-(244,59)
(16, 148>-(44, 124)
(16, 148)-(64, 148)
(64, 148)-(80, 124)
(80, 124)-(52, 124)
(10, 10), 3,
4
(60, 32), 3,
4
(240, 20), 3,
4
10
20
30
40
50
60
CIRCLE
CIRCLE
CIRCLE
CIRCLE
LINE
LINE
LINE
PAINT
LINE
LINE
LINE
LINE
LINE
LINE
LINE
PAINT
PAINT
PAINT
PAINT-
PAINT
PAINT
PAINT
PAINT
PAINT
PAINT
PAINT
PAINT
CIRCLE
PSET
PSET
PSET
PSET
PSET
(128 ,64 ),2,
4
(228, 70), 2,
4
(62, 156) ,4,4
(78, 150), 4,
4
(18, 156), 4,
4
(68, 128), 1,4
(128, 156), 2,
4
(40, 140), 4,
4
(48, 120), 2,
4
(46, 98), 5, 2,;
AN* =INKEY*
IFAN* =""THEN 420
LOAD "DISPLAY/BAS'SR
"STAIRS/BAS"
10 '
20 '
30 PCLS
"FOYER/BAS"
PCLS
PMODE 3,
1
SCREEN 1,0
DRAW "BM60,20;R140;D120;L40?U32;
L4;D52;R4;U20;BM160, 160-L128;U150"
70 DRAW "BM4,62;D130;BM28, 166?U102;
BM144, 148; R12"
80 DRAW "BM40,72;D24;R36;U24;L36;
75
APPENDIX C-
BM44,76;D16;R2S;U16;L28"
90 LINE (32, 12)-(92, 12),PSET
100 LINE (92, 12)~(100,20),PSET
11.0 LINE <0,0)-(60,20),PSET
120 LINE <200,20)-<255,0>,PSET
130 LINE (200, 140) -(255? 192), PSET
140 LINE (0, 192>-(32, 160),PSET
150 LINE <4,62>-<28,64),PSET
160 PAINT (120,4), 2,
4
170 PAINT (20, 20), 2,
4
180 PAINT (230, 20), 2,
4
190 PAINT (120, 40), 2,
4
200 PAINT (60, 16), 3,
4
210 PAINT (20, 64), 3,
4
220 PAINT (158, 124) ,4,4
230 PAINT (42, 74), 4,
4
240 LINE (28,8)-( 144, 148), PSFT
250 LINE (64, 12) --(156, 122),PSET
260 LINE (68, 12)-(156, 116),PSET
270 DRAW "BM144, 148;U38"
280 FOR 1=0 TO 9
290 DRAW "BM~8,28?U38"
300 NEXT I
310 DRAW "BM56,40;U28?BM48,31 i111 85
BM40,22"U10"
320 PAINT (56, 84), 2,
4
330 CIRCLE(56,86),10,3, .4,0, .5
340 LINE (51,86)-(63,86) ,PSET
350 DRAW "BM56,84;L4;E7?D8"
360 FOR 1=1 TO 32
370 CIRCLE (120, 176), 1*2, 1/4, .25
380 NEXT I
382 DRAW "BM232 ,176 5U100 ;R2 ;D100
"
383 CIRCLE (232, 180) ,15 ,4, 1, . 5,
384 CIRCLE (232, 178) ,6, 4, 2, .55 ,.
1
385 CIRCLE (232, 80) ,15 ,4, 1,0, .
5
386 CIRCLE (232, 82) ,6, 4, 2, .1, . 55
390 AN* =INKEY*
400 IF AN* ="" THEN 390
410 LOAD "DISPLAY/BAS'SR
SAMPLE PROGRAM #8
BUDGETING
This organizes your finances and prints out ajournal on
your printer. You need aline printer with aline length
of at least 80 characters to run it.
10 'Budget program
20 '
30 'The object of this program
is to build three direct access
40 'files, one alisting of a
balanced budget, another, alisting
50 'of transactions, and the
third, alisting of the updated
60 'budget. The program allows
for carryover from the previous
70 'period's budget. AJournal
can be printed out giving alist
80 'of the budget ,expenses, and
balances. (NOTE: As written,
90 'this program requires aprinter
for outputting the Journal.
100 'However, with slight modifi-
cation, it could be used without
110 'aprinter.
)
120 '
130 '
140 'Main module of program
150 '
160 CLS
170 PRINT 3106, "SELECTIONS:"
180 PRINT 3165, "1) BUILD BUDGET"
190 PRINT a197, "2) UPDATE AN
ACCOUNT"
200 PRINT 3229, "3) PRINT OUT A
JOURNAL"
210 PRINT 3261, "4) END JOB"
220 PRINT 3329, "1,2,3, OR 4?"
230 AN*= INKEY*
240 IF AN*="" THEN 230
250 ON VAL(AN*) GOSUB 360,950,
1450, 1970
260 GOTO 160
270 '
280 'This subroutine builds the
budget file (cal led
290 'BUDGET.ORG), and builds or
updates the file BUDGET. UPD
300 'It allows you to input the
start date of the budget
310 'and the total amount yolt
have to divide up to accounts.
320 'Tentative amounts are entered
for each account and a
330 'running balance is kept to
advise you of the amount
340 'left in Your total budget.
350 '
360 OPEN "D" ,#1 ,"BUDGET/ORG" ,
5
370 OPEN "D",#2, "BUDGET/UPD" ,5
380 FIELD #1,5 AS OAMT*
390 FIELD #2,5 AS UPDAMT*
400 GOSUB 1810
410 IF L0F(2) =THEN 470
420 FOR 1=1 TO 9
430 GET #2,
I
440 AMT(I) =CVN( UPDAMT*)
76
.APPENDIX C
450 PTOT =PTOT +AMT(I)
460 NEXT I
470 CLS
480 PRINT a130. "DATE(MM/DD/YY) :"
490 PRINT 3162, "PROJECTED INCOME
FROM:"
500 PRINT a196, "SALARY:"
510 PRINT a228, "OTHER:"
520 PRINT a96
530 INPUT "DATE(MM/DD/YY> :";DATE*
540 PRINT 3162, "PROJECTED INCOME
FROM:"
550 INPUT "SALARY: ";SAL
560 INPUT "OTHER:" ;OTHER
570 BTOT =SAL +OTHER
580 CLS
600 PRINT 39, "CURRENT BUDGET"
610 PRINT "ACCT# DESCRIPTION
BALANCE"
620 SUMBUD =
630 FOR 1=1 TO 9
640 PRINT USING "####7. 7.
"/. 7.####. ##-" ;ACNO< I) ;
SPACE* ;DESC* (I )?AMT (I
)
650 SUMBUD =SUMBUD +AMT(I)
660 NEXT I
670 PRINT 386, USING "*####.##-"
?AMT(1)
680 PRINT 3419, USING
"7. 7.**###.##";
"REMAINING MONEY: "5BTOT -(SUMBUD
-PTOT)
690 PRINT a451, "ENTER ACCT# OF
ITEM TO BE"
700 INPUT "CHANGED (000 TO
QUIT)" ;AN
710 IF AN =THEN 790
720 CLS
730 N=AN /100
740 PRINT a105,ACNO(N)
750 PRINT 3138,DESC*(N>
760 PRINT a170, "*" ;AMT(N)
770 PRINT: INPUT »NEW
AMOUNT" ;AMT(N)
780 GO TO 580
790 DATE =VAL( LEFT* (DATES, 2) +
M:i.'D*(DATE*,4,2) +RIGHT* (DATE*, 2) )
800 LSET OAMT* =MKN*(DATE)
810 PUT #1,
1
820 FOR 1=1 TO 9
8;<0 LSET OAMT* =MKN* (AMT (I) )
840 LSET UPDAMT* =MKN*(AMT(I))
850 PUT #1,1+1
860 PUT #2,
I
8/0 NEXT I
880 CLOSE
890 RETURN
900 '
910 'This subroutine builds a
transaction file called TFILE.DAT
920 'which contains anv updates
to the budget, and updates the
930 'file BUDGET. UPD .
940 '
950 OPEN "D",#l, "BUDGET/UPD-,5
960 OPEN "D",#2,"TFILE/DAT",36
970 FIELD #1,5 AS UPDAMT*
980 FIELD #2,3 AS ACN0*,8 AS DATE*,
20 AS DESC*,5 AS TAMT*
990 FOR 1=1 TO 9
1000 GET #1,
I
1010 AMT(I) =CVN(UPDAMT*>
1020 NEXT I
1030 GOSUB 1810
1040 CLS
1050 SUMBUD =
1060 PRINT a9, "CURRENT BUDGET"
1070 PRINT "ACCT# DESCRIPTION
BALANCE"
1080 FOR 1=1 TO 9
1090 PRINT USING "####7. 7.
7.####.##-" ;ACNO(I) ;
SPACES* ;DESC* (I);AMT (I
)
1100 SUMBUD =SUMBUD +AMT(I)
11.1.0 NEXT I
1120 PRINT 386, USING
"*####.##-" 5AMT(1)
1130 PRINT a419, USING "7. '/.
**### .## ";»TOTAL BALANCE :";SUMBUD
1140 PRINT a451, "ENTER ACCT# OF
ITEM TO BE
1150 INPUT "UPDATED (000 TO QUIT)"; AN
1160 IF AN =THEN 1350
1170 CLS
1180 N=AN /100
1190 PRINT a95, AN
1200 PRINT DESC*(N)
1210 PRINT USING "7. %
**###.##" CURRENT BALANCE" ;AMT (N)"
1220 PRINT: INPUT "DATE (MM/DD/YY) ";DT*
1230 PRINT "DESCRIPTION OF
TRANSACTION:"
1240 INPUT DS*
1250 PRINT "AMOUNT OF TRANSACTION:"
1260 PRINT "(NEGATIVE NUMBER FOR A
CREDIT)"
1270 INPUT TRANS
1280 AMT(N) =AMT(N) -TRANS
1290 LSET ACNO* =RIGHT* (STR* (AN) ,3)
77
APPENDIX C.
1300
1310
1320
1330
1340
1350
1360
1370
1380
1390
1400
1410
1420
DT*
DS*
LBET DATE* =
LSET DESC* =
LBET TAMT* =MKN* <TRANS)
PUT #2,L0F<2)+1
GOTO 1040
FOR 1=1 TO 9
LSET UPDAMT* =MKN*(AMT(
PUT #1,1
NEXT I
CLOSE
RETURN
I) )
This prints o u
t
subrout ine
aJour-nal listing the
1430 'budget ,transact icms, and
balances.
1440 '
1450 OPEN "D",#l, "BUDGET/0RG",5
1460 FIELD #1,5 AS AMT*
1470 OPEN "D",#2, "TFILE/DAT",36
1480 FIELD #2,3 AS TACNO*, 8AS
TDATE*,20 AS TRDESC*,5 AS TMT*
1490 GOSUB 1810
1500 CLS
1510 PRINT 3172, "PRINTING"
1520 Get #1, I
1530 DATE* =STR*(CVN(AMT*)
)
1540 IF LEN(DATE*) <6THEN DATE*
=" " +DATE*
1550 DATE* =LEFT* (DATE*, 2) +
"/" +MID*(DATE*,3,2) +"/"+
RIGHT* (DATE*, 2)
1560 PRINT #-2, TAB (30) "BUDGET FOR
THE PERIOD"
1570 PRINT
"STARTING
1580 PRINT
1590 PRINT
1600 PRINT OR"
#-2, TAB (31)
";DATE*
#-2: PRINT #-2
#-2 ,TAB (28 )"ACCOUNT
#-2, TAB (10)
"ACCOUNT" ?TAB(27) "TRANSACTION"
1610 PRINT #-2, TAB (10) "NUMBER"
?
TAB (14)" DATE "?TAB (27 )"DESCR IPT ION
"
TAB (47 )"TRANSACTION" ;TAB (61
)
"BALANCE"
1620 FOR 1=2 TO LOF(l)
1630 GET #1,
I
1640 PRINT #-2
1650 PRINT #-2,TAB(12)ACN0(I-l>
;
TAB (17) DATE* ;TAB (27 )DESC* (I-1)
;
TAB(61)CVN(AMT*)
1660 BAL=CVN(AMT*)
1670 FOR J=l TO L0F(2)
1680 GET #2,
J
1690 IFACNO (I-1)<>VAL (TACNO*
)
THEN 1730
1700 BAL=BAL -CVN(TMT*>
1710 IF CVN(TMT*) <,0 THEN CR*="CR"
ELSE CR*=""
1720 PRINT #-2,TAB(17)TDATE*?TAB(27)
TRDESC* 5TAB (47 )ABS (CVN (TMT* ))!CR*
?TAB (61 )BAL
1730 NEXT J
1740 NEXT I
1750 CLOSE
1760 RETURN
1770 '
1780 'This subroutine sets the
values of the account numbers,
1790 'ACNO(I), and account
de scriPt io n s ,DESC* (I)
.
1800 '
FOR 1=1 TO 9
ACNO(I) =I*100
NEXT I
1810
1820
1830
1840 DESC*( 1)
1850 DESC*<2)
1860 DESC*(3)
1870 DESC* (4)
1880 DESC*(5)
1890 DESC*(6)
1900 DESC* (7)
1910 DESC*(8)
1920 DESC* (9)
1930 RETURN
1940 '
1950 'This subroutine
the program.
1960 '
1970 END
"FOOD"
"RENT"
"CAR"
"UTILITIES"
"INSURANCE"
"TAXES"
"CLOTHING"
"ENTERTAINMENT"
"MISCELLANEOUS"
terminates
78
-APPENDIX D
ASCII CHARACTER CODES
These are the ASCII codes for each of the characters on your keyboard. The first column is the character; the second
is the code in decimal notation; and the third converts the code to ahexadecimal Q6-based number).
Chapter 15 shows how to use these codes with CHR$ to produce acharacter.
CHARACTER DECIMAL
CODE HEXADECIMAL
CODE
SPACEBAR
CHARACTER DECIMAL
CODE HEXADECIMAL
CODE
*If shifted, the codes for these characters are as follows: (CLEAR) is 92 (hex 5C); ®is 95 (hex 5F); ©is 91 (hex SB);
CD is 21 (hex 15); and CD is 93 (hex 5D).
79
APPENDIX D
LOWER-CASE CODES
These are the ASCII codes for lower-case letters. You can produce these characters by pressing the (SHIFT! and
®keys simultaneously to get into an upper/lower case mode. The lower case letters will appear on your screen in
reversed colors (green with ablack background).
CHARACTER DECIMAL
CODE HEXADECIMAL
CODE
a97 61
b^^H 98
c99 63
e101 65
102 66
g103 67
h104 WflaBfiHHHHflBi
i1105 69
k107 6B
108 kec mm
m109 6D
DECIMAL
CODE HEXADECIMAL
CODE
80
^APPENDIX E
MEMORYMAP
DECIMAL
0-255
256-1023
1024-1535
1536-2440
2441-top
ofRAM
top ofRAM is
16383 for 16K
systems;
32767 for
32K systems
HEX
0000-00FF
0100-03FF
0400-05FF
0600-0988
0989-top ofRAM
top ofRAM is
3FFF for 16K
systems; 7FFF
for 32K systems
32768-40959
40960-49151
49152-57343
57344-65279
"
8000-9FFF
A000-BFFF
C000-DFFF
65280-65535
E000-FEFF
FF00-FFFF
CONTENTS
System Direct
Page RAM
Extended Page RAM
Video Text Memory
Additional System
RAM
DESCRIPTION
See Section IV of Getting Started with COLOR
BASIC for detailed information.
This is used exclusively by DISK BASIC.
These Random Access Memory locations are allocated dynamically and
contain the following:
1. Random File Buffer
Area
2. File Control Blocks
(FCBs)
3. Graphics Video
Memory
Total buffer space for random access files, 256
bytes are reserved for this on start-up. This value
can be reset by the FILES statement.
Control data on each user buffer. 843 bytes are
reserved for this on start-up. This value can be
reset by the FILES statement: (number of buffers
set by FILES +1) x281 bytes.
4. BASIC Program
Storage
5. BASIC Variable
Storage
6. Stack
7. String Space
8. User Memory
Extended COLOR
BASIC ROM
COLOR BASIC ROM
COLOR DISK BASIC
ROM
Unused
Space reserved for graphics video pages. 6144
bytes or 4pages are reserved for this on start-up.
This value can be reset by the PCLEAR
statement: number of pages reserved by PCLEAR
X1,536 bytes per page. (Note: All pages must
start at a256-byte page boundary i.e., a
memory location divisible by 256.)
Space reserved for BASIC Programs and
Variables. 6455* bytes (16K systems) or 22,839*
bytes (32K systems) are reserved for this on start-
up. This value can be reset by different settings of
Random File Buffers, FCBs, Graphics Video
Memory, String Space or User Memory.
Total space for string data. On start-up, 200 bytes
are reserved, but this can be reset by the CLEAR
statement.
Total space for user machine-language routines.
No space is reserved for this on start-up, but this
can be reset by the CLEAR statement.
Read Only Memory
Read Only Memory
Read Only Memory
Input/Output
*Ifyou execute aPRINT MEM command, on start-up, you will, get anumber alittle lower than this because of the
overhead necessary to execute this command.
81
APPENDIX F,
SPECIFICATIONS
Type of disks
Disk Organization
(Formatted disk)
Operating Temperature
Memory Capacity
Unformatted
Soft sector
(I/O sector/track)
Access Time
Track to track
Average
Settling time
Number of indexes
Weight of Disk Drive
Disk Controller
5V4" mini-diskettes
Radio Shack Catalog
Number 26-305
26-405 (package of three)
or 26-406 (package of 10)
Single-sided
Double-density
35 tracks
18 sectors per track
256 data bytes per sector
Directory on track 17
18 to 113 degrees Fahrenheit
10 to 45 degrees Centigrade
218.8 kilobytes per disk
6.2 kilobytes per track
179.1 kilobytes per disk
5.1 kilobytes per track
Data transmission speed 250 kilobits per second
5msec.
100 msec.
15 msec.
1
3.8 kg.
WD1793
82
APPENDIX G
ERROR MESSAGES
/O Division by zero. The Computer was asked to
divide anumber by 0, which is impossible. You
could also get this error message if you do not
enclose afilename in quotation marks.
AE File Already Exists. You are trying to RENAME
or COPY afile to afilename which Already
Exists.
DS Direct Statement. There is adirect statement in
the data file. This could be caused if you load a
program with no line numbers.
ER Write or Input past End of Record (direct access
only). You are attempting to PUT more data in the
record than it can hold or INPUT more data than
it contains.
AO Attempt to open adata file which is Already
Open.
BR Bad Record Number. You have used an impossible
record number in your PUT or GET line. Either it
is too low (less than 1) or too high (higher than the
maximum number of records the Computer can fit
on the disk). Use adifferent record number in the
PUT or GET line, or assign asmaller record
length in the OPEN line.
BS Bad Subscript. The subscripts in an array are out
of range. Use DIM to dimension the array. For
example, if you have A(12) in your program, with-
out apreceding DIM line which dimensions array
Afor 12 or more elements, you will get this error.
CN Can't continue. If you use the command CONT
and you are at the END of the program, you will
get this error.
DD Attempt to redimension an array. An array can
only be dimensioned once. For example, you can-
not have DIM A(12) and DIM A(50) in the same
program.
DF Disk Full. The Disk you are trying to store your
file on is Full. Use another disk.
DN This is either aDrive Number or Device Number
error.
Drive Number Error. You are using adrive num-
ber higher than 3. You will also get this error if
you do not specify adrive number when using
DSKINI or BACKUP. If you have only one drive
specify drive with these two commands
(DSKINIO or BACKUP 0).
Device Number error. You are using more buffers
than the Computer has reserved. Use FILES to
reserve more. You might also get this error if you
use anonexisting buffer number (such as buffer
#-3) or omit the buffer (such as FIELD 1AS A$
rather than FIELD #1, 1AS A$).
FC
FD
FM
FN
FO
FS
ID
IE
IO
Illegal Function Call. This happens when you use
aparameter (number) with aBASIC word that is
out of range. For example SOUND (260,260) or
CLS(IO) will cause this error. Also RIGHT$(S$,20),
when there are only 10 characters in S$, would
cause it. Other examples are anegative subscript,
such as A( -1), or aUSR call before the address
has been POKEd in.
Bad File Data. This error occurs when you PRINT
data to afile, or INPUT data from the file, using
the wrong type of variable for the corresponding
data. For example, INPUT #1, A, when the data
in the file is astring, causes this error.
Bad File Mode. You have specified the wrong file
mode ("O," "I," or "D") in your OPEN line for what
you are attempting to do. For example, you are
attempting to GET arecord from afile OPENed
for "I" (use "D") or WRITE data to afile OPENed
for "I" (use "O").
Bad File Name. You used an unacceptable format
to name your file.
Field Overflow. The field length is longer than the
record length.
Bad File Structure. There is something wrong
with your disk file. Either the data was written
incorrectly or the directory track on the disk is
bad. See IO for instructions on what to do.
Illegal Direct statement. You can only use INPUT
as aline in the program, not as acommand line.
Input past End of file. Use EOF or LOF to check
to see when you've reached the end of the file.
When you have, CLOSE it.
Input/Output error. The Computer is having trou-
ble inputting or outputting information to the
disk.
83
APPENDIX G.
LS
NE
NF
(1) Make sure there is adisk inserted properly
in the indicated drive and the drive door is
closed.
(2) If you still get this error, there might be
something wrong with your disk. Try rein-
serting the disk first. Then try using adif-
ferent one or reformatting it. (Remember
that reformatting adisk erases its contents.)
(3) If you still get this error, you probably have
aproblem with the Computer System itself.
Call the Radio Shack Repair Center.
This error could also be caused by input/output
problems with another device, such as the tape
recorder.
String too Long,
characters.
NO
Astring may only be 255
The Computer can't find the disk file you want.
Check the disk's directory to see if the file is there.
If you have more than one disk drive, you might
not have included the appropriate drive number
in the filename. If you are using COPY, KILL, or
RENAME (discussed in the next chapter), you
might have left off the extension.
NEXT without FOR. NEXT is being used without
amatching FOR statement. This error also occurs
when you have the NEXT lines reversed in a
nested loop.
File Not Open. You cannot input or output data to
afile until you have OPENed it.
OB Out of Buffer space. Use FILES to reserve more
space.
OD Out of Data. A READ was executed with insuffi-
cient DATA for it to READ. ADATA statement
may have been left out of the program.
OM Out of Memory. All available memory has been
used or reserved.
OS Out of String Space. There is not enough space in
memory to do your string operations. Use CLEAR
at the beginning of your program to reserve more
string space.
OV Overflow. The number is too large for the Com-
puter to handle.
RG RETURN without GOSUB. ARETURN line is in
your program with no matching GOSUB.
SE Set to non-fielded string. The field in which you
are attempting to LSET or RSET data in has not
yet been FIELDed. Check the FIELD line.
SN Syntax error. This could result from amisspelled
command, incorrect punctuation, open parenthe-
sis, or an illegal character. Type the program line
or command over.
ST String formula too complex. Astring operation
was too complex to handle. Break up the operation
into shorter steps.
TM Type Mismatch. This occurs when you try to
assign numeric data to astring variable (A$ =3)
or string data to anumeric variable (A =
"DATA"). This could also occur if you do not
enclose afilename in quotes.
UL Undefined Line. You have aGOTO, GOSUB, or
other branching line in the program asking the
Computer to go to anonexisting line number.
VF Verification. You will only get the error when you
have the VERIFY command ON and are writing
to adisk. The Computer is informing you that
there is aflaw in what it wrote. See 10 for instruc-
tions on what to do.
WP Write Protected. You are trying to store informa-
tion on adisk which is Write Protected. Either
take the label off the write protect notch or use a
different disk. If your disk is not Write Protected,
then there is an input/output problem. See 10 for
instructions on what to do about this.
84
.APPENDIX H
DISKBASIC SUMMARY
This is ashort summary on each new DISK BASIC "command." You may also use any of the EXTENDED COLOR
BASIC commands. (See Getting Started with Extended Color BASIC or the Color Computer Quick Reference Card
for acomplete listing.)
The first line gives the format to use in typing the command. The italicized words represent "parameters" values
which you can specify with the command.
This is the meaning of some of the parameters you may specify:
filename
All information stored on adisk must have afilename. The filename should be in this format:
name/extension:drive number
The name is mandatory. It must have 1to 8characters.
The extension is optional. It can have 1to 3characters.
The drive number is optional. If you do not use it when opening adisk file, the Computer will use drive (or
the drive specified in the DRIVE command).
number
This may be anumber (1, 5.3), anumeric variable (A, BL), anumeric function (ABS(3)), or anumeric operation
(5 +3, A-7).
string
This may be characters ("B," "STRING"), astring variable (A$, BL$), astring function (LEFT$(S$, 5)), or astring
operation ("M" +A$).
data
This may be number or string.
BASIC WORD PAGES
DISCUSSED
BACKUP source drive TO destination drive 13-15
Duplicates the contents of the source drive to the destination drive. If you only
have one drive, specify it as the source drive. The Computer will prompt you to
switch disks as it makes the backup copy. Executing this command will erase
memory.
BACKUP 13 TO 1BACKUP
CLOSE #buffer, . .
.
26-27
Closes communication to the buffers specified. (See OPEN for buffer numbers).
If you omit the buffer, the Computer will close all open files.
CLOSE «1 CLOSE *1 ,*2
COPY filenamel TO filename2 21
Copies the contents of filenamel to filename2. Each filename must include an
extension. (See format for filenames above.) Executing this command will erase
memory.
COPY "FILE/BAS" TO "NEWFILE/BAS"
COPY "ORG/DAT:0" TO "ORG/DAT: 1"
85
APPENDIX H.
BASIC WORD DISCUSSED
CVNistring variable) 50
Converts a5-byte coded string (created by MKN$) back to the number it
represents.
x=cvnia$)
DIRdrive number 11
Displays a directory of the disk in the drive number you specify. If you omit the
drive number, the Computer will use drive 0. (Unless you use the DRIVE com-
mand to change this default.) This is atypical directory display:
MYPROG BAS B 3
Y0URPR0G BAS A1
HERDATA DATA 1A 5
USRPROG BIN 2B2
The first column is the name of the file. The second column is its extension. The
third is the file type (0 =BASIC program, 1=BASIC data file, 2=machine lan-
guage file, 3=editor source file). The fourth column is the storage format
(A =ASCII, B=Binary). The fifth column is the file length in granules.
DIR0 DIR
DRIVE drive number 11-15
Changes the drive default to the drive number you specify. If you do not use the
DRIVE command, the Computer will default to drive 0.
DRIVE 1
DSKINIdriue number 8
Formats adisk in the drive number you specify. Executing this command will
erase memory.
DSKINI0 DSKINI1
DSKI$ drive number, track, sector, string variablel, string variable2 61-62
Inputs data from acertain sector within acertain track on the disk in drive
number. The first 128 bytes of data are input into string variablel; the second
128 bytes into string variable2.
DSKI$ 0. 12 .3i M* tN$
DSKO$ drive^number, track, sector, stringl, string2 61-62
Outputs stringMata into the sector, track, and drive number you specify, stringl
is output into the first 128 bytes of the sector; string2 is output into the second
128 bytes. Used improperly, this command could garble the contents of the disk.
DSK0$ 0, 2, 1,"FIRST DATA", "SECOND DATA"
EOF (buffer) 27
Returns aif there is more data to be read in the buffer and a-1if there is no
more data in it. (See OPEN for buffer numbers.)
IF EOFU) =-1 THEN CLOSE «1
FIELD #buffer, field size AS field name, . .
.
48-49
Organizes the space within adirect access buffer into fields. (See OPEN for
buffer numbers.) You specify the size and name of each field.
FIELD »1» 10 AS A*. 12 AS B$ .5AS C$
86
.APPENDIX H
BASIC WORD PAGES
DISCUSSED
FILES buffer number, buffer size
Tells the Computer how many buffers to reserve in memory (buffer number),
and the total bytes to reserve for these buffers (buffer size). If you do not use
FILES, the Computer will reserve enough memory space for buffers 1and 2,
and will reserve atotal of 256 bytes for those buffers.
FILES 1.1000 FILES 5
54-55
FREE(drive number)
Returns the number of free granules on the disk in the drive number you
specify.
PRINT FREE(0)
20
GET #buffer, record number
Gets the next record or the record number you specify, and puts it in the buffer.
(See OPEN for buffer numbers).
GET «1 ,5 GET *2. 3
34-36
INPUT #buffer, variable name, . .
.
Inputs data from the buffer you specify and assigns each data item in the buffer
to the variable name you specify. (See OPEN for buffer numbers.)
INPUT «1. A$. B$
26-28
KILL filename
Deletes the filename you specify from the disk directory. (See the format for file-
names above.) You must include the extension with the filename.
KILL "FILE/BAS" "KILL FILE/DAT:1"
20
LINE INPUT #buffer, data
Inputs aline (all the data up to the (ENTER) character) from the buffer you specify.
(See OPEN for buffer numbers).
LINE INPUT «1 ,X$
42-43
LOAD filename, R
Loads the BASIC program file you specify from adisk into memory. By includ-
ing R, the Computer will RUN the program immediately after loading it. If
your filename does not have an extension, the Computer assumes it is BAS. (See
the format for filenames above.) Executing this command will erase memory.
LOAD "PROGRAM", RLOAD "ACCTS/BAS: 1"
LOADM filename, offset address
Loads amachine-language program file from disk. You can specify an offset
address to add to the program's loading address. If your filename does not have
an extension, the Computer assumes it is BIN. (See the format for filenames
above.)
LOADM "PROG/BIN. 3522
61
LOC(buffer)
Returns the current record number of the buffer you specify. (See OPEN for
buffer numbers.)
PRINT L0C(1)
87
APPENDIX H.
basic word magnSro
LOF(buffer) 37
Returns the highest numbered record of the buffer you specify. (See OPEN for
buffer numbers.)
FOR R=1TO L0F(1)
LSET field name =data 48-50
Left justifies the data within the field name you specify. If the data is larger
than the field, the RIGHT characters will be truncated (chopped off).
LSET A$ ="BANANAS" LSET B$ =T$
MERGE filename, R53-54
Loads aprogram file from disk and merges it with the existing program in
memory. If you include R, the Computer will immediately run the program
after merging it. (See the format for filenames above.) The disk program file
cannot be MERGEd unless it was SAVEd with the A(ASCII) option.
MERGE "SUB/BAS" MERGE "NEW". R
MKN$(number) 50
Converts anumber to a5-byte coded string, for storage in aformatted disk file.
LSET B$ =MKN*(53B78310)
OPEN "mode" #buffer, filename, record length 26-28,
Opens aplace in memory called abuffer which will communicate data to and 29-31,
from acertain device. The buffers and the devices they communicate with are: 33-38
screen or printer (it is not necessary to open this buffer)
-1tape recorder
-2 printer
1-15 disk drive
The communication modes you can use are:
Iinputting data from asequential access file
OOutputting data to asequential access file
DInputting or outputting data to adirect access file
The filename you use should be in the format defined above. If you do not give
filename an extension, the Computer will give it the extension DAT.
If you are opening communication to adirect access file, you can also specify
the record length. If you don't, the record length will be 256 bytes.
OPEN "D" f«1 ."FILE" ,15
OPEN "I" »*2 "CHGE/DAT"
PRINT #buffer, data list 27-28
PRINTs the data to the buffer. (See OPEN for buffer numbers.) You may use a
comma or asemi-colon to separate each item in the data list.
PRINT «1 ."DATA"
PRINT #buffer, USING format; data list 45-46
Prints data to the buffer using the format you specify. The format is astring
which can either specify anumerical or string format,
numerical formats may consist of any of the following:
#sets the field of anumber
formats adecimal point
88
.APPENDIX H
BASIC WORD DlIcufsED
,formats acomma every third number
** fills leading spaces with asterisks
$places $ahead of number
$$ floating dollar sign
+in first position, causes sign to be printed before number; in last
position causes sign to be printed after the number
-•-•"• prints number in exponential notation
-prints a-minus sign after negative numbers
PRINT USING *1 ."*«.*"; 53.76
PRINT USING #2. "#*$#.«*-"! -3.G78
string formats may consist of either:
%%fields the length of astring.
!!prints the first character of the string
PRINT USING *1 ."!"i "WHITE"
PRINT USING *1. "X Z"i "YELLOW"
See Going Ahead With Extended Color BASIC for more information on the
formats.
PUT #buffer, record number 34
Assigns arecord number to the data in the buffer. If you do not specify arecord
number, the Computer will assign it to the current record. (See OPEN for buffer
numbers.)
PUT *2. 3PUT «1 >H
RENAME old filename TO new filename 19-20
Renames afile on disk to anew filename. You must specify the extension ofboth
filenames.
RENAME "MFILE/DAT:1" TO "BFILE/DAT: 1
"
RSET field name =data
Right justifies the data within the field name you specify. If the data is larger
than the field, the RIGHT characters will be truncated (the same as with
LSET).
RSET M$ ="SOAP"
RUN filename, R9
Loads filename from disk and runs it. If Ris included, all open files will remain
open. (See the format for filenames above.)
RUN "FILE' RUN "PROG/BAS" ,R
SAVE filename, A8
Saves filename on disk. If you do not give filename an extension, the Computer
will give it the extension BAS. By using the Aoption, your program will be
saved in ASCII format. (See the format for filenames above.)
SAVE "PROG/BAS" SAVE "TEST:1" ,A
SAVEM filename, first address, last address, execution address 61
Saves filename amachine language program beginning at first address (in
memory) and ending at last address. You also specify the address in which it
will be executed. If you do not give filename an extension, the Computer will
give it the extension BIN. (See the format for filenames above.)
SAVEM "FILE/BIN: 1" ,&H5200 ,&H5800 .&H5300
89
APPENDIX H,
PAPFS
BASIC WORD DISCUSSED
UNLOAD drive number 13
Closes any open files in the drive number you specify. If you don't specify adrive
number the Computer will use drive (or the drive number you specified with
DRIVE).
UNLOAD UNLOAD
VERIFY ON 15
VERIFY OFF
Turns the verify function ON or OFF. When VERIFY is ON, the Computer will
verify all disk writes.
WRITE #buffer, data list 25"26'
Writes the data to the buffer you specify. (See OPEN for buffer numbers.) Use 34-35
acomma to separate each item in the data list.
WRITE *1 >A$ .B$i C
90
JNDEX
SUBJECT PAGES
ASCII 11,54, 59, 78, 79
BACKUP 13, 14, 84
Binary 11,54
Bits 7, 57
Buffer 26, 29, 54, 55, 84
Bytes 7, 41 ,57, 58, 59
CLOSE 26, 27, 34, 84
Connections 1,2
COPY 21,84
CRC 58
CVN 50, 85
DCBPT 60
DCDRV 60
DCODC 60
DCSEC 60
DCSTA 60
DCTRK 60
DECIMAL CODE 78, 79
Destination Disk 14
Direct Access File 33-38, 47, 48
DIR 11,85
Directory 11,25, 58
Directory Entries 58
Direct Input 48
Disk
Care of disk 13-17
Formatting 7-8
Inserting 3
Disk Drive 2, 8
Disk System 1,57
Drive Number 11,85
DSKCON 60, 60
DSKINIO 8,14,85
DSKI$ 61,62
DSKO$ 61 ,62, 85
EOF 27, 45, 85
Error Messages 16, 82, 83
Field 86
FIELDED INPUT 49
File Allocation Table 59
Files 8, 25, 54, 55, 58, 86
Filename 10, 59, 84
Filename Extension 59, 84
File number 84
FORMAT 7, 8, 47
FREE 86
GET 34, 35, 36, 86
Granule 58, 59
Hexadecimal 57
SUBJECT PAGES
INPUT 26, 27, 34, 36, 37, 42,
43,61,86
Interface 2
KILL 20, 86
LINE INPUT 42, 43, 86
LIST 9
LOAD 9, 86
LOADM 61 ,87
LOC 87
LOF 37, 87
Logical Sector 59, 60
LSET 48, 49, 50, 87
Machine-Language 57, 60, 61
Memory 9
MERGE 53, 54, 87
MKN$ 50, 87
Multi-Disk Drives 20
NEW 9
Numerical Formats 88
OPEN 26, 27, 34, 87
OUTPUT 26, 27, 61
Physical Sector 59, 60
PRINT 19, 27, 43, 44, 45, 48, 88
PRINT FREE 20
PRINT USING 45, 88
PUT 34, 35, 36, 88
READ 54
Records 33, 34, 36, 37, 55
RENAME 19, 88
RESET 15
RMB 60
RSET 89
RUN 9,89
Salvage aDisk 15
SAVE 8,19,89
SAVEM 61,89
Sector 7, 57, 58
Sequential Access File 29-31
SKIP FACTOR 59
Source Disk ,.14
Specifications 81
Start-up 2-3
Storing on Disk
ABASIC Program 8
AData File 23-39
AMachine-Language Program 61
Machine-Language Routine 60
String 84
String Format 88
System Controls 57
91
INDEX
SUBJECT PAGES
Technical Information 57-62
Tracks 57, 58
UNLOAD 13,89
VERIFYOFF 15, 89
VERIFYON 15, 89
WRITE 25, 34, 35, 37, 42, 89
WRITE PROTECT 15
92
SERVICE POLICY
Radio Shack's nationwide network of service facilities provides quick, conve-
nient, and reliable repair services for all of its computer products, in most
instances. Warranty service will be performed in accordance with Radio
Shack's Limited Warranty. Non-warranty service will be provided at reasonable
parts and labor costs.
Because of the sensitivity of computer equipment, and the problems which can
result from improper servicing, the following limitations also apply to the
services offered by Radio Shack:
1
.
If any of the warranty seals on any Radio Shack computer products are
broken, Radio Shack reserves the right to refuse to service the equipment or
to void any remaining warranty on the equipment.
2. If any Radio Shack computer equipment has been modified so that it is not
within manufacturer's specifications, including, but not limited to, the in-
stallation of any non-Radio Shack parts, components, or replacement
boards, then Radio Shack reserves the right to refuse to service the equip-
ment, void any remaining warranty, remove and replace any non-Radio
Shack part found in the equipment, and perform whatever modifications are
necessary to return the equipment to original factory manufacturer's speci-
fications.
3. The cost for the labor and parts required to return the Radio Shack com-
puter equipment to original manufacturer's specifications will be charged to
the customer in addition to the normal repair charge.
RADIO SHACK, ADIVISION OF TANDY CORPORATION
U.S.A.
FORT WORTH, TEXAS 76182
CANADA
BARRIE, ONTARIO, L4M4W5
TANDY CORPORATION
AUSTRAUA BELGIUM UNITED KINGDOM
91 KURRAJONG ROAD PARC INDUSTRIE!. NANINNE BILSTON ROAD, WEDNESBURY
MOUNT DRUITT, N.S.W. 2770 5140 NANINNE WEST MIDLANDS WS1B 7JN
874947OBC0 PRINTED IN U.S.A.

Navigation menu