the ibm personal computer made easy

247

Upload: others

Post on 11-Sep-2021

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: The IBM Personal Computer Made Easy
Page 2: The IBM Personal Computer Made Easy

THEIBM PERsonAL

COMPUTER MADEEASV Robert M. Rinder

1')11 Macmillan Education

Page 3: The IBM Personal Computer Made Easy

Copyright © 1983 by Robert M. Rinder All rights reserved including the right of reproduction in whole or in part in any form Published by MONARCH PRESS A Division of Simon & Schuster, Inc. Simon & Schuster Building 1230 Avenue of the Americas New York, New York 10020

MONARCH PRESS and colophon are trademarks of Simon & Schuster, Inc. registered in the U.S. Patent and Trademark Office. Designed by Irving Perkins Associates

10 9 8 7 6 5 4 3 2 1

M

ISBN 978-1-349-81225-7 ISBN 978-1-349-81223-3 (eBook)DOI 10.1007/978-1-349-81223-3

Page 4: The IBM Personal Computer Made Easy

conTEnTS

Introduction

Part 1 An Introduction to the IBM Personal Computer Chapter 1 What Is a Personal Computer?

Unique Features of Personal Computers 4 How Are Personal Computers Used? 4

Word Processing 8 Electronic Worksheets 9 Small Business Systems 10

The Office of the Present 11 A Personal Computer on Your Desk? 11 Down-loading 13 Up-loading 13

Chapter 2 How Do Personal Computers Work? An Example 15 Input, Processing, and Output 17 Computer Concepts and Terms 20

Memory 21 Bits and Bytes 22 Codes 23 The Processor 23 Words 24 Inside the Micro 25 Addressing Memory 25 Disk Drives 26 Diskettes 26 Power Supply 27

Inside the Computer 27 Operating Systems 28

DOS 28 Functions of DOS 29

3

15

Page 5: The IBM Personal Computer Made Easy

Chapter 3 How to Select the Right Equipment What Is Available 30

The Minimum System 30 Optional Equipment 31 Adapters 31

The Selection Process 32 Requirements 32 Programs 32 Equipment 33 Selection 33 Shop Around 33

Equipment Descriptions 33 The System Unit 33 The System Board 34 Expansion 35 Power Supply 35 Disk Drives 36 Displays 37 Printers 38 Game-Control Adapter 38 Other Equipment 39

Using the IBM PC to Communicate 40 Asynchronous Communication Adapter 40 SDLC Communication Adapter 40 SNA 3270 Emulation and RJE Support 40 IBM 3101 Emulation 40 Asynchronous Communication Support 41

Typical Systems and Their Costs 41 A Minimum System 41 A Low-End Word-Processing System 42 A Professional Word-Processing System 42 A Low-End Business System 44 An Expanded Business System 44 A Low-End Professional System 45 An Expanded Professional System 46 A Communication Terminal System 46

30

Chapter 4 How to Select the Right Program 53 What You Need to Know When Buying Programs

53 Program Reviews 53 Try Out the Program 54 Demos and Manuals 54

Page 6: The IBM Personal Computer Made Easy

Buy It and Try It 54 Work With a Consultant 54 What You Need to Know in All Cases 55 What You Need to Know About Specific Program

Areas 55 How to Select a Word-Processing Program 56

Word-Processing Terms 57 Word-Processing Programs Checklist 58

How to Select an Electronic Worksheet 59 Electronic Worksheets Program Checklist 60

How to Select Graphics Programs 61 Graphics Program Checklist 62

How to Select a Mailing-List Program 63 Mailing-List Program Checklist 64

How to Select a Communication Program 64 Communication Program Checklist 67

How to Select a Program for Business Applications 68 Data Managers and Program Generators 68 Application Programs 69 Business Application Program Checklist 70

Part 2 How to Use the IBM Personal Computer Introduction to Part 2

Chapter 5 Exploring the Territory Turning On 73 Keyboard Calisthenics 73

U sing the ENTER Key 76 Simple BASIC 77

The CLS Command 77 The PRINT Statement 77 Editing a Line 79 Arithmetic Operations 80 Addition and Subtraction 80 Multiplication and Division 81

Higher Mathematics 82 Exponents 82 Parentheses 82 Trigonometric Functions 83 Logarithm and Exponential Functions 83 Miscellaneous Functions 84

72

73

Page 7: The IBM Personal Computer Made Easy

Chapter 6 How to Use BASIC How to Write a Program 91

Direct and Indirect Modes 91 Program Line Numbers 92 How to LIST a Program 93 Renumbering Lines 94 Deleting Lines 94 Function Keys 94 Entering a New Program 95 Coding and Testing 96

Chapter 7 Working With Disks What's on a Disk? 97

Files 97 File Names 98 File Name Extensions 98 Filespec 99

How Disks Are Used 100 DOS 101

Rules for Working With Disks 101 Write-Protecting Disks 102

How to Start DOS 102 The DOS Prompt Message 103 How to Specify a Drive 103 How to Change the Default Drive 103

Copying a Disk 104 How to Use BASIC With DOS 105 Formatting a Disk With FORMAT 106 Copy 106 Finding Files on a Disk 107

The DOS Way Using DIR 107 The BASIC Way With FILES 108

Saving, Loading, and Deleting Files 108 Specifying a Tape Cassette 109

Part 3 Learning the BASIC Programming Language Chapter 8 BASI~ession I

BASIC and BASICA U5 Automatic Line Numbering U6 Variables U7

Numeric Variables U7

91

97

115

Page 8: The IBM Personal Computer Made Easy

Rules for Numeric Variable Names 119 String Variables 120

Substrings 121 LEFT$, MID$, and RIGHT$ 122

Changing Strings to Numbers 123 Changing Numbers to Strings 123 Keyboard Shortcuts 124 How to Format Numbers 124

The PRINT USING Statement 124 Integers, Single-Precision, and Double-Precision

Numbers 125

Chapter 9 BASI~ession II Tapping the Computer's Power 129

Looping and Branching the GOTO Way 129 Looping and Branching the IF ... GOTO Way

130 Relational Operators 131 Examples of the IF ... GOTO Statement 131 Looping and Branching the FOR ... NEXT Way

132 Stepping and Nesting FOR ... NEXT Loops 133

Documenting Programs 134 Using the REM Statement to Document 134 Using the Single-Quote to Document 134

Data Entry 135 Using the INPUT Statement for Data Entries

136 More IF Statements 137

Using the IF Statement to Make Performance Conditional 137

129

Chapter 10 BASIC-Session III 139 Subroutines 139

The GOSUB and RETURN Statements 141 The DATA, READ, and RESTORE Statements 142

The DATA Statement 142 The READ Statement 143 The RESTORE Statement 143

Arrays 144 The DIM Statement 146 Arrays With More Than One Dimension 147 The OPTION BASE Statement 148

Page 9: The IBM Personal Computer Made Easy

Part 4 How to Use the Special Features of the IBM PC Chapter 11 Screen Magic

Adjusting the Screen 153 The DOS Adjustment 154 The BASIC Adjustment 154

How to Learn Screen-Related Statements 155 Screen Pages 155 The SCREEN Statement 156 The WIDTH Statement 157

How to Determine the Screen Mode You Are In 158

What Can You Display on the Screen? 158 Text 159 40- and 80-Column Text 159 Graphics in Text Mode 159

A World of Color 160 Colored Text 160 The COLOR Statement in Text Mode 161 COLOR Graphics 162 The COLOR Statement in Graphics Mode 162

153

Chapter 12 Cut-n-Paste Programming 169 How to Create Your Own Screens 170

The LOCATE Statement 170 The SAVE Command 172 Naming BASIC Files 172 The LOAD Command 173 Creating Your Own Menu 174 More Than One Statement Per Line 174 Editing a Menu 175 Reversing an Image With the COLOR

Statement 176 Reversing the Menu Heading 176 Highlighting Characters Using the COLOR

Statement 176 Turning Line 25 OFF and ON-The KEY

Command 177 Putting the Final Touches on the Menu 177 Resume 178 The LOCATE Statement Revisited 179 The INKEY$ and LEN Statements 179

Page 10: The IBM Personal Computer Made Easy

Chapter 13 Computer Sounds of MUllc BEEPing the Speaker 183 Computer Music 184

The SOUND Statement 184 The PLAY Statement 186

Chapter 14 Computer Graphics Graphics in the Text Mode 192 Graphics in the Graphics Mode 197

The COLOR Statement in the Graphics Mode 197

Drawing Points 199 The PSET Statement 200 The PRESET Statement 201

Drawing Lines 202 The LINE Statement 203 Line Limits 203 Connecting Lines 204 Coloring Lines 204 Erasing Lines 205 Moving Lines 205 Making Boxes 206 Moving Boxes 206 A Test Pattern 207

Chapter 15 Advanced Graphics The DRAW Statement 208

Scale Factors 209 Locating Objects on the Screen 210 Returning to Square One 210 Rotations 210 Color Control 211 Using Variables With DRAW 211 Using Subroutines With DRAW 212

The CIRCLE Statement 214 Slicing the Pie 216 Ellipses 217

The PAINT Statement 217

Appendix 1 Summary and Index of BASIC Statements, Commands, and Functions

Appendix 2 IBM PC Character Set

183

192

208

221

228

Page 11: The IBM Personal Computer Made Easy

Appendix 3 Reserved Words

Appendix 4 Words Generated by Alternate (ALl) Key

QUICK REFERENCE CHARTS

232

234

3-1 Power Supply 48 3-2 Disk Characteristics 48 3-3 Summary of Display Adapter Capabilities 49 3-4 IBM Printer Characteristics 50 3-5 Asynchronous Communications Adapter 51 3-6 Approximate Sizes and Cable Lengths 52 5-1 The Most Common Errors and What to Do About Them 85 5-2 Edit Keys 87 5-3 Print Statement Rules 88 5-4 Actions That Do and Don't Change Your Programs 89 7-1 External System Programs on the DOS Master 110 7-2 Steps in Formatting a Disk 111 7-3 Summary of Backup and Copy Operations 112 8-1 Simplified Rules for Variable Names 127 8-2 PRINT USING Statements 127 8-3 Constant and Variable Types 128

10-1 Arrays 149 11-1 The SCREEN Statement 163 11-2 Color-in-Text Mode 164 11-3 Noncolor Displays in Text Mode 165 11-4 The COLOR Statement With the Color/Graphic Adapter

and Noncolor Monitor 166 11-5 Color in Medium-Resolution Graphics 167 11-6 Noncolor Displays in Graphics Mode 168 12-1 The LOCATE Statement 182 12-2 Summary of INKEY$ Action 182 13-1 The PLAY Statement 190 15-1 The DRAW Statement 219

TABLES

1-1 How PCs Are Used by Managers and Professionals 1-2 How PCs Are Used in Business and Industry

13-1 Frequencies for the SOUND Statement

6 7

185

Page 12: The IBM Personal Computer Made Easy

FIGURES

2-1 Input, Processing, and Output 2-2 Viewing the Inside of the System Unit 2-3 Memory Levels 2-4 The Processor and Memory 5-1 Keys and Key Combinations

lO-1 Calling a Subroutine 11-1 Screen Pages in Text Mode 14-1 Screen Addressing for Graphics 14-2 Color Selection

ILLUSTRATIONS

18 20 21 25 74

140 155 197 198

1-1 The IBM Personal Computer 3 1-2 A Computer in the Home 5 1-3 The Personal Computer and the Electronic Worksheet lO 1-4 The Office of the Present 12 2-1 Memory Expansion 22 2-2 The Anatomy of a Computer 28 3-1 Inside the System Unit 34 3-2 A Winchester Hard Disk Substitutes for a Floppy in the

System Unit 36 3-3 Expanding the System While Conserving Space 39 3-4 Affordable Word Processing 43 4-1 A Modem 66

14-1 Computer Graphics 193 14-2 Graphics in Text Mode 196

Page 13: The IBM Personal Computer Made Easy

InTRODUCTion

This book describes the IBM Personal Computer and explains how to use it. The book is for both experienced and inexperienced com­puter users who want to take advantage of this special computer in their professional or personal activities, and, yes, in their recreational activities, too.

The IBM Personal Computer-often called the IBM PC-is spe­cial because of the vast installed base of IBM equipment that domi­nates data processing and related activities. More than other personal computers, the IBM PC is finding its way into the mainstream of the business world and other areas where IBM equipment is widely used. In these environments, the IBM PC is being linked by communication lines to other IBM equipment. It is serving as terminal, work station, information station, and data-entry station. Use of the IBM Personal Computer is also spilling over into education, research, and engi­neering. And the IBM PC has also become a popular home computer.

Many people who have no previous computer experience now want to learn how to use this personal computer. Others, whose experience has been with large mainframes or minicomputers, want to add a knowledge of the IBM PC to their working skills. They will find a personal computer quite different in terms of how it is used and what it can be used for. In this book, I shall stress these differences, emphasizing the concept of the personal computer as an electronic scratchpad.

The computer novice will learn the basic tools of computer use, data processing, and programming. The experienced computer user, if not already familiar with BASIC, will quickly pick up this excellent personal computing language. In all cases, you will learn how to operate, use, and benefit from the IBM PC's special features.

The book consists of four parts. Part 1 is an introduction to personal computers-and to the IBM

Personal Computer in particular. The equipment is described, and representative systems and their approximate costs are presented.

Page 14: The IBM Personal Computer Made Easy

Guidelines are given on how to select the right programs for your needs, supplemented by checklists showing major application areas.

In Part 2, I describe how to operate the IBM PC. Included is such information as how to work with disks, the disk-operating system, and the various levels of operation in the IBM Pc.

In Part 3, I introduce you to the BASIC programming language by taking you through three hands-on working sessions. The power of the personal computer as a teaching tool is its ability to provide immediate response, as well as a scratchpad environment for exper­imentation. After this, I hope you will be motivated to explore and expand on the text material, working at your own pace.

In Part 4, on special features of the IBM PC, I introduce and apply additional statements in BASIC to round out your knowledge of this language.

You will learn how to create screen displays, use color, flip screen pages, and create forms and charts. Two chapters on computer graph­ics explain how to draw objects, move them and color them. Finally, the fascinating subject of computer-generated sound and music is explored. You will learn ways for programming the computer to gen­erate notes, octaves and rhythms, separately and in combination.

Throughout the book, liberal use is made of figures and Quick Reference Charts to encapsulate key points and provide ready ref­erence of often-used material. The Quick Reference Charts add im­portant details to the material discussed in the text which uses examples rather than formal rules to explain how to use the computer. The most common problems, the kind that are repeatedly encountered by novices and experts alike, are listed along with possible solutions.

This book aims to make learning about the IBM Personal Computer an easy and pleasurable task. This does not mean that there will be no work, or that everything will pr~ceed smoothly in all cases. Part of learning about computers has to include finding out what problems can occur and how to deal with them. However, readers should find the work stimulating and feel well rewarded when they have mastered the use of this powerful tool. NOTE: Zeros will appear as 0 to avoid any possible confusion.

EQUIPMENT AND SOFTWARE TO BE USED WITH THIS BOOK

The equipment and software described in this book is basic to most computer applications, and was chosen because it was considered to

Page 15: The IBM Personal Computer Made Easy

be of interest to the greatest number of readers. The components that can be used in connection with the material covered include the following:

• The IBM Personal Computer or Personal Computer XT • Cassette BASIC, Disk BASIC, and Advanced BASIC • IBM's Disk-Operating System, PC DOS • Systems having one to four disk drives • Single or dual-sided drives • Most types of monitors, including color and black-and-white

IV sets, 40-character and 80-character screens • Both the Color/Graphics Monitor Adapter and the IBM Mono­

chrome Display and Parallel Printer Adapter • Any type of printer that is compatible with the IBM PC

The book was written using release 1.10 of DOS and 1.10 of BASIC. Because IBM maintains upward compatibility, readers who have later versions, such as DOS 2.0 and BASIC 2.0, should have no trouble following this book. However, some of the operations described may optionally be performed by alternative methods in later releases.

Page 16: The IBM Personal Computer Made Easy

Part 1

An Introduction to the IBM Personal Computer

Page 17: The IBM Personal Computer Made Easy

Chapter 1

What Is a Personal Computer?

Mr. X owns a small computer, which he uses at home to organize his personal finances. His family plays games on it. He also finds increasing use for it as a budgeting tool in his work as a manager. Mr. X's computer can quickly be labeled a personal computer.

Now let us put the same computer in a different environment. The computer is purchased by company Y for use by its sales department.

Illustration 1-1 The IBM Personal Computer. The pictured system includes the IBM high resolution monochrome display, the IBM 80-character-per-second matrix printer, two disk drives housed in the System Unit and IBM's 83-key adjustable keyboard. (Photograph reproduced courtesy of IBM Corp.)

3

Page 18: The IBM Personal Computer Made Easy

4 THE IBM PERSONAL COMPUTER MADE EASY

The computer is linked to the company's communication network, and five salespeople share its facilities. The computer is no longer a personal computer in the original sense, yet it is the same piece of equipment.

The term personal computer is well established today, but as this example illustrates, we shall have to broaden our view of this expres­sion if we are to include all the ways these small computers are being used. On the simplest level, a personal computer is any computer with a display screen and a keyboard that is small enough to sit on a table or desk.

UNIQUE FEATURES OF PERSONAL COMPUTERS

In addition to their use for traditional tasks such as word processing and business applications, personal computers can be used in unique ways.

A key feature of a personal computer is the complete control you have over it while using it. You need not be concerned about hogging the system, how your actions may affect others, or how long you are logged onto the system. You are free to explore possibilities, try this and that, cut-n-paste and, yes, crash the system. Recovery is quick and simple, and, if you back up your disks, little is lost if you have to reset the computer.

Personal computers are open to many new uses. A personal com­puter can be used as an electronic scratchpad in which the traditional concepts of programming are replaced with a try-this, try-that ap­proach. The BASIC language is ideally suited for this type of appli­cation. So are the electronic worksheet programs that provide for what is known as "what ... if' programming. This will all be discussed in more detail later.

A personal computer can also be a terminal to larger, more so­phisticated systems. When used in this way, entirely new areas of use are opened up. Using the IBM PC for communication is one of its more rewarding applications for those working in large organiza­tions.

HOW ARE PERSONAL COMPUTERS USED?

Personal computers are general-purpose machines. They can be used in many ways. The key to using them, though, is a computer

Page 19: The IBM Personal Computer Made Easy

What Is a Personal Computer? 5

program. Programs can be loaded into a computer, used, and then replaced by another prbgram. A program can make the computer do such diverse things as accounting, word processing, and communi­cations-all with pretty much the same hardware.

Entertainment is, of course, another popular use for personal com­puters. Although computer games will not be discussed in this book, I will cover such topics as computer music and the basic operations of color graphics-all of which you can use to create your own games (see Illustration 1-2).

In a large business, the PC is a small adjunct to the total infor­mation-processing facility. In a small business, the PC can perform a large part of the information-processing workload. It is often the

Illustration 1-2 A Computer in the Home. The IBM Personal Computer is not all work and no play. (Photograph reproduced courtesy of IBM Corp.)

Page 20: The IBM Personal Computer Made Easy

6 THE IBM PERSONAL COMPUTER MADE EASY

only computer used in a small business. Obviously, under these con­ditions, the tasks assigned the PC are more inclusive; the PC is used for general business functions such as record-keeping and accounting as well as for the more typical personal computer tasks of word proc­essing and electronic-worksheet processing.

TABLE 1-1 HOW PCs ARE USED BY MANAGERS AND PROFESSIONALS

Word Processing

Text creation, storage and revision of reports, letters, memos, etc. Storage and insertion of standard, often used sections (boilerplate) Spelling corrections Forms Printing of single or-multiple copies

Information Exchange Electronic mail Electronic memo Electronic mailbox Electronic bulletin board

Inquiry Table scan File lookup Data-base search

Spreadsheets

Budgeting Financial planning Resource allocation Modeling

Business Billing Client records Patient records Mailing list

Page 21: The IBM Personal Computer Made Easy

What Is a Personal Computer? 7

TABLE 1-2 HOW pes ARE USED IN BUSINESS AND INDUSTRY

Accounting Accounts receivable Accounts payable General ledger Billing and statements

Inventory

Order entry Inventory maintenance Purchase orders

Purchasing

Purchase orders Order tracking Vendor file

Sales

Sales records Sales projections Sales presentations

Production

Job estimating Job control Materials management Scheduling Assembly monitoring Process control

Distribution

Routing Scheduling Tracking

Data Entry

With Diskette interface 3770 RJE emulation 3270 emulation 3101 emulation

Page 22: The IBM Personal Computer Made Easy

8 THE IBM PERSONAL COMPUTER MADE EASY

Technical Modeling Testing Control Analysis

Planning

Budgets Modeling Financial projections

Communication

Electronic mail Down-loading Up-loading Data-base inquiry TTY ASR 33/35 emulation

Tables 1-1 and 1-2 list only some of the possible applications. When you consult the catalogs of program vendors, you will find many additional areas listed. Perusal of these catalogs is an excellent way to begin thinking about ways to use a personal computer.

For readers who may be unfamiliar with any of these applications, here are some brief descriptions of the most commonly used appli­cations of personal computers, which are word processing, electronic worksheets, and small-business systems.

Word Processing

In word processing, the computer is used instead of a typewriter. Word processing greatly Simplifies the preparation and revision of printed documents. It is applicable to documents as brief as a I-page letter or as a 400-page manuscript.

In word processing, material is keyed in just as it would be if you were using a typewriter. Instead of immediately printing what is entered, however, the word processor stores the entries in its memory and displays the entries on a TV-like screen. The advantage of having a document stored in the computer is that it can be manipulated at electronic speeds with little effort. Sections can be deleted, inserted, revised, moved, highlighted, indented, and so on-all with just a few strikes of the keys to specify the operations you want performed.

Page 23: The IBM Personal Computer Made Easy

What Is a Personal Computer? 9

When you are satisfied that a document is correct, a single key strike is usually all that is necessary to start printing a document. You can store the document permanently on a disk. Then, iflater revisions are called for, it is a simple matter to load the document back into memory and make the desired revisions, again using the speed and power of the electronic word processor.

Word processors have proven so beneficial that they are one of the most widely used applications of small computers and of personal computers in particular.

Electronic Worksheets

Until the invention of the electronic worksheet, anyone preparing a budget, financial statement, or similar document with many parallel entries could expect to spend many hours with a calculator before arriving at a satisfactory result. No more. Several years ago, two graduate students invented VisiCalc, the first electronic worksheet for PCs. It was originally designed to run on the Apple computer. Apple sales took off, propelling the Apple to the forefront of the personal computer market.

Now there are several VisiCalc imitators, with each new version adding some new wrinkles.

Electonic worksheets (see Illustration 1-3) are based on an orga­nization of data into tables of rows and columns. Many applications fit this mold, but budgets and financial projections are the classic examples. Typically, the table entries are interrelated. Changes in cash flow or interest rates and most other entries will have to be recalculated. The power of electronic worksheets is that these recal­culations are done automatically. The results are displayed quickly on the screen. And with little effort on your part, you can try new values. This is referred to as "what if" processing: What if I try this sales projection? What if prices fall 2 percent? Electronic worksheets allow you to concentrate your efforts where they belong-on finding the right solutions rather than on cranking out long computations.

Of course, the screen can display only a small part of a worksheet at one time. Worksheets can be 64 columns by 254 rows or more, depending on the program and how much memory your computer has. Worksheet programs accommodate the limited screen-viewing area by scrolling, that is, by shifting the contents of the screen up and down, left and right.

Page 24: The IBM Personal Computer Made Easy

10 THE IBM PERSONAL COMPUTER MADE EASY

Illustration 1-3 The Personal Computer and the Electronic Worksheet. This combination is saving professionals and managers hours upon hours of detailed calculations. (Photograph reprduced courtesy of IBM Corp.)

Along with word processing, worksheet applications are one of the more popular uses of personal computers.

Small Business Systems

Very small businesses can use the IBM PC for accounting, inven­tory, order entry, and other typical business data processing. Business data processing involves critical areas of a firm's operations. This is the most demanding area of application of personal computers and requires careful, knowledgeable planning, so the prospective buyer for these types of applications should carefully weigh his present and future needs. The IBM PC requires added equipment and software for multi-user operation. Its expansion capabilities are limited, thus requiring the added expense of an expansion unit.

Page 25: The IBM Personal Computer Made Easy

What Is a Personal Computer? 11

THE OFFICE OF THE PRESENT

Much has been written recently about the office of the future. Office equipment linked by Local Area Networks (LANs) will create a more productive working environment.

The office of the present, however, is already overtaking the office of the future, and personal computers rather than local-area networks are the catalyst. Put a computer on a desk and watch how work patterns change. Paperwork is replaced by video-screen work. It makes no sense to produce results at electronic speeds only to have those results linger in a typing pool, waiting for a slow-speed, manual print­out. The accomplished personal-computer user takes pride in his ability to use the computer to edit and process his copy into a finished document. With the need for secretarial revision of rough drafts by­passed, the next logical step is direct output from the personal com­puter to a shared printer that has all the features needed for top­quality letters, reports, and manuals. Revisions are so simple with PC word processors that every version that is printed can be a "final" version.

When you have a computer on your desk (see Illustration 1-4) and your colleagues have computers on their desks, are you going to draft a memo by hand, give it to a secretary so she can type it, make copies, insert the copies in envelopes, and wait until the next day, or more, for delivery? Hardly. You will soon be contacting vendors of local networks to find out how to link your personal computers so electronic memos can be sent by electronic mail to your colleagues' electronic mailboxes.

If there are other local computers, they, too, can become part of the Local Area Networks. So will dedicated word processors, and so will other types of work stations. This is how personal computers are turning the office of the future into the office of the present.

A Personal Computer on Your Desk?

More and more PCs are showing up on the desks of managers and professionals. You might take a few minutes to consider how you might benefit from having a PC reserved for your exclusive use on your desk. Assume that your PC will communicate with other PCs and larger computers. What functions could a PC perform for you? What functions especially require the making of revisions, updating

Page 26: The IBM Personal Computer Made Easy

12 THE IBM PERSONAL COMPUTER MADE EASY

Illustration 1-4 The Office of the Present. Personal computers are showing up on desks of managers and staffers in increasing numbers. (Photograph reproduced courtesy of IBM Corp.)

Page 27: The IBM Personal Computer Made Easy

What Is a Personal Computer? 13

records, finding data, or exchanging information? These are the kinds of tasks that can be performed more easily and quickly if you have a PC on your desk, or at least, within easy reach.

Down-loading

Moving data from a large· computer to a personal computer or to a terminal is referred to as down-loading. Down-loading allows many small computers to share the resources of a larger computer. The large computer provides:

• Mass storage for data bases and backup of data bases • Tape files for sort/merge operations and generation data sets • High-performance printers for large-quantity printing

Thus, many users can share expensive computer facilities that would be prohibitive on an individual basis. In this respect, the situation is the same as the time-sharing that has been done on large computers. Where down-loading differs from time-sharing, though, is in the power of the personal computer compared to a terminal. Down-loading transfers whole programs or files to the personal computer, leaving the large computer free to pursue other tasks. It is unencumbered by the constant interruptions required by time-sharing. Down-load­ing can often be scheduled for off-peak hours so the communication network in not degraded. Even if peak hour transfer is required, delays of several minutes are usually tolerable. Once the down-loading is completed, the personal computer becomes your exclusive proc­essor, with a predictable response time. The result is more efficient processing and more productive use of the information resources of the organization.

Sometimes, down-loading is not practical, however, because the amount of data is too large. Where this is the case, the personal computer is fully capable of acting as a terminal to a time-sharing system in the usual manner.

Up-loading

Up-loading is the transfer of data from a personal computer to a large computer. The results of processing by the personal computer

Page 28: The IBM Personal Computer Made Easy

14 THE IBM PERSONAL COMPUTER MADE EASY

are transmitted to the host computer in order to perform the following functions:

• Update a data base • Store a new or revised program • Save data on mass storage device (disk, tape, etc.) • Sort/merge data • Print data

Up-loaded data can be queued at the host where it competes on a priority basis for the resources of the host.

In this chapter, I described personal computers in general and what you can do with them. In the next chapter, I will describe how personal computers work. This will provide you with important back­ground in the concepts and terms that are frequently used in later chapters.

Page 29: The IBM Personal Computer Made Easy

Chapter 2

How Do Personal Computers Work?

Here are some definitions of computers:

• A computer is a data processor. • A computer takes input information, processes it, and produces

output information. • A computer is a calculator with a program. • A computer is a powerful tool for extending human intellectual

capabilities and amplifying intelligence. • A computer is a dumb piece of hardware that can be pro­

grammed to do routine tasks.

These definitions all describe some important aspect of computers. The key points to understand are:

1. A computer requires input data. On personal computers, most input is entered manually from a keyboard. The keyboard has a set of standard typewriter keys, plus a number of additional keys that will be described later.

2. A computer requires programs to process the data that is entered. Without a program, a computer can do nothing­not even accept input data.

3. A computer requires an output device, so that you can see the results.

AN EXAMPLE

The processing of an order can be used to illustrate these basic operations on a personal computer:

15

Page 30: The IBM Personal Computer Made Easy

16 THE IBM PERSONAL COMPUTER MADE EASY

Mr. Farnsworth recently bought an IBM Personal Computer to use for recording orders and updating inventory in his industrial-parts distributorship. When he arrives at work in the morning, he removes two disks from a diskette case. One disk stores his order-entry pro­gram. The other disk stores his inventory file. Mr. Farnsworth has two disk drives. In the left drive, he inserts his program disk; in the right drive, he inserts his inventory disk.

Mr. Farnsworth turns on the computer, and while the computer is coming up to speed and performing diagnostic tests on itself, he opens his coffee container and takes a few sips of hot, black coffee. The computer gives a beep to indicate that its diagnostic tests are completed and that it is ready for the day's work. The screen displays a message asking for today's date. Mr. Farnsworth enters the month, day, and year. Now the computer asks for the time of day. Mr. Farnsworth looks at his watch and enters hours, minutes, and seconds.

The IBM Personal Computer has an internal clock that it uses to update the time, second by second. Hence, the date and time will remain valid until the computer is turned off at night.

After entry of the time, there are several possible tasks that the computer might do:

• List order index • Enter an order • Add a record • Delete record

The computer has no way of knowing which one to do next, so it displays these possibilities on the screen and asks Mr. Farnsworth to select one. This kind of display is called a menu. The computer will wait patiently while Mr. Farnsworth drinks his coffee and ponders his course of action. (Since Mr. Farnsworth became the owner of a computer, he has had plenty of time for his morning coffee.)

The phone rings. A customer wants ten LX-408-6 ball bearings. Does Farnsworth have them in stock?

Farnsworth keys in an L to list his order index. He has not yet learned all the part numbers in his system, so the computer responds with the first "page" of the index. Another key calls up subsequent pages, until the LX-408-6 ball bearings are found. The part number in the computer is 1849. When this number is entered in the com­puter, it retrieves the record for the LX-408-6 ball bearings. Farns­worth has eight instock and one hundred on order, due next week.

Page 31: The IBM Personal Computer Made Easy

How Do Personal Computers Work? 17

The customer says OK. With a single strike of the key, Farnsworth goes back to the menu, selects the order-entry routine, and keys in the order, entering the same information he used to write in his record books. The computer then performs the following fuctions:

• Subtracts from the inventory amount the eight ball bearings Farnsworth agreed to deliver to his customer.

• Places two ball bearings on back order, thus creating a new record in the order file.

• Creates an invoice in the customer file from which an invoice will later be printed and an accounts receivable form will be processed.

• Writes a transaction record that serves as an audit trail and input to a file-recovery program, if any of the master files be­come damaged.

Farnsworth already has one program of an integrated business system. He will be adding a General Ledger and Accounts Payable when he has confidence in his inventory program.

Although orders for ball bearings may seem remote from the com­puter applications you are interested in, the processing steps Farns­worth performed are fairly typical of all applications: the insertion of disks, the use of menus to select the operation to be performed, the keying in of new data, and the postponement of printing to a more appropriate time.

INPUT, PROCESSING, AND OUTPUT

The starting point for all computer operations is the entry of data. When you enter data on a keyboard, the computer immediately dis­plays the entry on the display screen so you see what has been keyed in. If you have a printer, you can arrange things so that your entries are printed on paper as well as displayed on the screen. However, a printer is seldom used in this way. More often, you will want to make several entries, correct any errors, do some processing, and then, only as a final step, call for a printout.

The entry of data at the keyboard provides input to the computer. This is the first of three operations that invariably take place in any computing process. The other two are processing and output. It is always convenient to break any computer job, no matter how complex, into input, processing, and output (see Figure 2-1).

Page 32: The IBM Personal Computer Made Easy

18 THE IBM PERSONAL COMPUTER MADE EASY

System ~~:::====;;=:;:::p;::roc=;esso=r ;:::;~~ / Speaker r Output Iffilllllllil ijdLJ=sle:€9

orTV Output \

iSPlav Monitor

~/ __ /

Figure 2-1 Input, Processing, and Output

Input

Printer Output

v

The keyboard is not the only means of input. The IBM Personal Computer also supports the following input devices:

• Cassette tape • Diskettes (magnetically coated disks that store data) • Light pen • Communication line • Game paddles

More devices may be added to this list by IBM, and other vendors

Page 33: The IBM Personal Computer Made Easy

How Do Personal Computers Work? 19

already provide additional products. (There will be more on the sub­ject of input devices later.)

Input into a computer can be divided into three types:

1. Data that you want the computer to process. For example, this could be a record of sale, musical notes, graphic infor­mation, hours worked, or projected profits, to name but a few of the possibilities.

2. Programs that tell the computer what to do with the data that has been entered. In the above examples, there would be a sales program, a music program, a graphics generator, a pay­roll program, and a financial modeling program.

3. Commands that tell the computer what mode of operation to perform. In the above example, you could enter a RUN com­mand to tell the computer to run the sales program. Other commands allow you to stop a program, write a program, edit a program, save data, and delete data.

All three types of input are required before and during processing.

Processing

When you have entered a program, data, and the appropriate command, the computer takes over and processes the data. At some point, it will generate output. This may occur at an intermediate point, in order to ask for more data input or show intermediate results, or the program may run to completion and then generate all output at one time. In either case, the output of data is the ultimate goal.

Output

Output, like input, can use a variety of devices. Those supported by the IBM Personal Computer are:

• Screen displays (Your home television set or a similar, but more capable, device can perform this function.)

• Printer • Speaker • Cassette tape • Diskette • Communication line

Page 34: The IBM Personal Computer Made Easy

20 THE IBM PERSONAL COMPUTER MADE EASY

Note that cassettes, diskettes, and communication lines serve as both input and output.

COMPUTER CONCEPTS AND TERMS

No basic difference exists between a personal computer and its bigger brothers-the minis and mainframes. There are, however, differences in the speed of operation, the amount of storage, and the flexibility. In this section, I will discuss the computer concepts and terms that any knowledgable user needs to know.

In Figure 2-1, the item labeled System Unit is nothing more than an uninteresting box. However, if you were to remove the cover­which is easy to do-you would see a world of the latest electronic wonders. There are circuit boards populated by the microprocessor and the memory chips, the disk drives, the power supply and, of course, a small speaker for those all-important sound effects.

Figure 2-2 shows the System Unit, which consists of:

Memory

Speaker

System Board

Cassette BASIC

Five Slots for Adapters

DOS BASIC BASICA

a ____ o_f -_I/---,~ l

Figure 2-2 Viewing the Inside of the System Unit

Page 35: The IBM Personal Computer Made Easy

How Do Personal Computers Work? 21

• Memory • Processor • Disk drives • Power supply

Memory

Memory-also referred to as main storage, RAM (random-access memory), and ROM (read-only memory)-is always required when dealing with information. Forms of information storage that you are probably already familiar with are the printed page, tape recordings, and photographs. A computer, however, needs information stored in a way that allows it to read and write fast-less than a millionth of a second. For this, devices called memory chips, are used (see Figure 2-3).

8088 Micro--

Figure 2-3 Memory Levels

Disk Memory Slow. inexpensive

Memory chips (main memory) Fast, expensive

Register Memory Very fast but limited by technical constraints and costs

Page 36: The IBM Personal Computer Made Easy

22 THE IBM PERSONAL COMPUTER MADE EASY

Illustration 2-1 Memory Expansion. This memory expansion board gives you 256 kilobytes of memory for those big processing jobs. Smaller, 192K boards are also available. (Photograph reproduced courtesy of Davong Systems, Inc.)

Memory chips are encased in small oblong packages with rows of prongs on each side that permit them to be inserted or removed from sockets in the computer. This means you can easily add memory, since the IBM PC basic system board comes with spare, unpopulated sockets. In fact, the amount of memory you will need will be a major consideration when buying-and later operating-a personal com­puter.

The amount of memory in a personal computer determines how fast programs run and how easy the system is to use. With too little memory, a word processing program can slow down to an unaccept­able pace. Give it another 32K and it will speed along sweetly and smoothly.

Bits and Bytes

Memory is measured in bytes. One byte stores one character­either a letter or a number. Since most memory systems store thou­sands of characters, the term kilobyte is used. It is often abbreviated with the letter K. K actually stands for 1024 bytes, but is often rounded down to 1,000.

Thus, 16,384 actual bytes, the smallest amount on an IBM personal computer, would be written: 16K. 16K is a common memory incre­ment. So is 64K, and soon, 256K will be. The amount of memory attached to computers tends to quadruple every four years. It is all

Page 37: The IBM Personal Computer Made Easy

How Do Personal Computers Wort? 23

a function of how many electronic components engineers can cram onto those tiny chips.

Another unit of measure for memory-and for that matter, of information-is the hit. A bit is the smallest possible unit of storage, corresponding, as it does, to the opening or closing of one switch. There are eight bits in one byte. If you imagine eight switches, any of which can be open or closed, it is easy to see that there are enough combinations to store all the letters and numbers. For example, all switches open could represent the number 0, one switch closed could be a 1 and so on. There are a possible 256 open and closed combi­nations of eight switches, enough for all the characters usually re­quired in computer systems.

Codes

All information stored in computers is in the form of a code. The assignment of numbers and letters to combinations of bits is called a code. Several codes are used in computers, but there is only one you need to know about in the beginning. It is the American National Standard Code for Information Interchange, which, for obvious rea­sons, is invariably abbreviated to ASCII and pronounced "asky."

The full ASCII code is given in Appendix 2. If you look at it now, you will see that it contains many special characters. Some of these characters are important in communication between computers, which was a prime consideration of the ASCII committee that developed the code. Today, ASCII is widely used, not only on communication, but also internally in the computer, as well as in keyboards and displays. However, the keyboard in the IBM Personal Computer departs from ASCII by using a special IBM expanded code. You can learn more about this code from the IBM Technical Reference Man­ual. However, most personal-computer users will not have occasion to get that deeply into the keyboard code.

Codes are of critical importance for communication. Two com­puters that use different codes are like two people who speak different languages. The widespread use of the ASCII code facilitates the in­terchange of data between computers.

The Processor

The processor is the heart, brains, and soul of the computer. All the other components exist only to support its operation. All data

Page 38: The IBM Personal Computer Made Easy

24 THE IBM PERSONAL COMPUTER MADE EASY

passes through the processor. In addition, the processor controls the overall operation of the computer through sequencing, control, and clock signals.

In computers such as the IBM PC, the processor is actually a microprocessor, often called a "micro." Like memory, micros are fabricated on silicon chips and packaged similarly. However, a micro is three to four times bigger than a memory unit.

A number of microprocessors are available for use in personal com­puters. Each microprocessor has its own personality, which basically means some good things and some bad things can be said about each.

The microprocessor used in the IBM Personal Computer is Intell's 8088. This is a powerful micro, but by no means the most powerful available today. However, it should be fully capable of satisfYing the needs of most personal-computer users.

Words

One of the most commonly used measures of a micro's power is its word length. In computer terminology, a word is the number of bits that a processor handles at one time. Until recently, all personal computers had word lengths of 8 bits, or 1 byte. That is, they could process only one character at a time. Through technological ingenuity, the microprocessor manufacturers have been able to develop micros with 16- and 32-bit words, meaning they can process 2 to 4 characters at a time, instead of just 1 character.

In addition to increased speed, longer words provide for more memory by increasing the amount that can be addressed, or, as it is often said, larger word lengths provide for more memory space.

The word lengths used to address memory are usually different from the word lengths used for data. The popular 8-bit micros used in Apple, Radio Shack, and many other personal computers have 16-bit address words. With 16 bits, a computer can address 65,536 mem­ory locations. This may seem like a lot, but it is not. Many applications require more memory space, and with the newer generation of mi­cros, they get it.

The Intel 8088 micro used in the IBM PC is something of an 8-bit and 16-bit hybrid. It has a 16-bit data word internally, an 8-bit word for transferring data from and to memory, and a 20-bit word for addressing 1 million memory locations. If this seems complicated, Figure 2-4 should help clarifY things.

Page 39: The IBM Personal Computer Made Easy

How Do Personal Computers Work? 25

System Unit

/

Memory 16,000 to 1,000,000 Bytes

e

8 Data Lines External (moves on character a time.)

at

Write t Read J

I Arithmetic

Unit

/ /

8088 Microprocessor

...

I

~Memory Address Lines (provide for

____ 1 megabyte of . .. Storage.)

r Address Register

· Data · · Register

\ \ \

16 Data Lines Internal (moves two characters at a time.)

Control Unit

Figure 2-4 The Processor and Memory

Inside the Micro

Figure 2-4 shows some of the internals of a microprocessor. There is an Arithmetic Unit and a set of registers. The function of the Arithmetic Unit is obvious, but the registers need some explanation. Registers are nothing more than very high-speed memory. When the adder requires input data, that data must be close at hand to achieve rapid operations. If the processor had to go outside to memory to get the operands, processing would be painfully slow. Hence, data is continually transferred between external memory and the internal processor registers to keep the adder operating at maximum speed and efficiency.

Addressing Memory

In Figure 2-4, note the special register labeled Address Register. This stores memory addresses that are used to select the area of

Page 40: The IBM Personal Computer Made Easy

26 THE IBM PERSONAL COMPUTER MADE EASY

memory to be read from or written into. Remember that memory contains thousands of storage locations (bytes). How does the com­puter specify which locations are to be read from or written into? Through the address register, of course. The computer gets these addresses from the program being executed and transfers them to the Address Register, thus selecting a location in the memory.

The IBM PC has 20 address lines-called the address bus-pro­viding about 1 million different address locations. This is a fairly respectable memory space, compared to the measly 64K memory space of other popular, but older, 8-bit personal computers such as the Apple II or the Radio Shack Z80-based systems. However, it pales in comparison to the 16-million bytes of the powerful Motorola 68000.

Disk Drives

Disk drives provide a computer with additional memory. The mem­ory chip referred to previously is fast but relatively expensive. It also has the unfortunate failing of losing data every time power is turned off. Disk memory, on the other hand, is relatively cheap, and although much slower than memory chips, it retains data when power is turned off. Disks provide permanent storage of data as long as no magnets or other alien objects destroy it. Thus, disk memory supplements main memory-the name often given to memory composed of chips.

Figure 2-3 shows the relationship between memories. Data flows in both directions. Large amounts of data are transferred from disk memory to main memory. The main memory feeds data to register memory one word at a time. The output of the processor is accu­mulated in main memory. When there is sufficient data to warrant access to disk memory, a transfer of the data is made from main memory to disk.

Diskettes

Disk memory resides on a magnetically coated disk that can be inserted and removed from the disk drive. The magnetic disk is per­manently enclosed in a 5V4-inch protective jacket. An oblong slot is cut away to expose the magnetic coating for reading and writing. These packaged disks go by several names-mini-floppies, floppy disks, flexible disks, and floppies. IBM calls them diskettes. In this book they will often be called simply "disks."

Diskettes made a major contribution to the success of personal

Page 41: The IBM Personal Computer Made Easy

How Do Personal Computers Work? 27

computers. Their low cost and ease of useprovide PCs with the thousands of bytes needed for practical applications.

Power Supply

The power supplies are generally stable and do not need attention, unless you are operating in an area where machinery or other elec­trical equipment causes excessive noise on the power lines. Then you may want to investigate the use of a device that protects against this sort of thing.

In other cases, you may want to protect against power outages such as blackouts and brownouts. Devices are available for providing backup battery power for a limited period. A dealer can advise you on this.

INSIDE THE COMPUTER

Imagine that everybody in New York City suddenly decided to drive across the George Washington Bridge, and you will get some idea of what the traffic flow is like in a computer. An IBM Personal Computer can easily store millions of characters. What are these characters doing in storage? Their mission is to get inside the micro­processor. The microprocessor sits inside the System Unit of your computer. Its connection to the millions of characters in storage is through a narrow single path in and out. This path is called a bus, and its width is measured in bits. The need to channel masses of data down a narrow bus explains much of what goes on in a computer and why things are done the way they are. Buried deep inside the mi­croprocessor is the Arithmetic Unit. The data in storage has to reach the Arithmetic Unit to fulfill its mission in life. It is there that it is processed, an operation that takes less than a millionth of a second for one word. Data in storage might wait days, weeks or even years for this brief encounter, after which it, or newly generated data, is summarily ushered out of the microprocessor, again over a narrow bus, and back into storage (see Illustration 2-2).

Upon consideration, this whole process may seem wasteful and illogical. Why not spread Arithmetic Units throughout storage, with lots of wide data highways in and out? People have tried. The Japanese are putting a big effort into achieving this now. But, so far, nobody has solved the problem satisfactorily.

Page 42: The IBM Personal Computer Made Easy

28 THE IBM PERSONAL COMPUTER MADE EASY

Illustration 2-2 The Anatomy of a Computer. No, you don't have to understand how this works, but circuit boards are essential objects with a certain aesthetic appeal.

OPERATING SYSTEMS

With so much traffic heading in the same direction, there has to be some kind of traffic cop to control the flow of data. This is provided by special control programs.

DOS

IBM calls its control program a disk-operating system. It is referred to as DOS, and is pronounced "Doss" or 0-0-5. DOS is a product of Microsoft and is sold through IBM for its computer. (IBM, and others, also sell operating systems other than the DOS that will be discussed later in this book. They are more suited to experienced users. You are encouraged to look into what they have to offer when

Page 43: The IBM Personal Computer Made Easy

How Do Personal Computers Work? 29

you finish this book. However, one operating system is all you should be concerned with at this time.)

Functions of DOS

Operating systems perform the following functions:

• Transfer data between memory and disk or tape • Start-up the computer and perform diagnostic tests of circuits

and memory • Accept commands entered at the keyboard that allow you to

control the computer • Copy files from one disk to another • Transfer data and commands to the printer • Transfer data and cursor movements to the screen

Page 44: The IBM Personal Computer Made Easy

Chapter 3

How to Select the Right Equipment

Like people, computers have a certain personality. Some are clearly playful; some are powerful but cranky; others are friendly but weak. The IBM is clearly all business. No executive has to worry that he will be thought frivilous if he has an IBM PC in his office. Plant managers trust it for process control and on the factory floor. The IBM Personal Computer is made for work.

That is not to say that you can't have fun with this computer. The IBM PC is loaded with game-playing potential. But its real mission? Strictly business.

In order to make the IBM PC work for you, you have to know what components to buy and what programs to use. In this chapter, I will describe the equipment that is available and how to go about putting together a system that meets your needs.

WHAT IS AVAILABLE

The IBM Personal Computer is built around a basic unit, to which various optional components can be connected.

The basic unit consists of the System Unit and a keyboard. The keyboard is attached to the System Unit by a coiled cord, allowing the keyboard to be moved to a convenient working position.

The Minimum System

The basic unit is not a working system, because there is no provision for output. At a minimum, you will have to add a display unit so you

30

Page 45: The IBM Personal Computer Made Easy

How to Select the Right Equipment 31

can see the results of the computer's processing. For this, you can use your own TV set. But you will still need an adapter board and an RF modulator to drive your TV. The simple addition of a cassette tape player will prOVide some much-needed storage.

With just this entry-level system, you will already have a powerful computer with 16K of memory that you can use for learning computer fundamentals and programming. Of the 16K memory, 4K is used by the system, leaving 12K for running BASIC or other programs. You can also do considerable mathematical work with this system, although it would not be suitable for business applications or word processing. For these, you will need disk storage, a printer, and more memory. But these can always be added later. In any case, as of this writing, the 16K system is only available on special request with a 2-3 week waiting period. However, it still comprises the basic building block from which more powerful systems are assembled.

The alternative to a TV set is a display monitor. The monitor can display computer output, but it can't receive TV signals. It connects directly to the computer, so an RF modulator is not necessary.

Optional Equipment

Optional units, which can be connected to the basic unit to form a working system, are:

• Cassette tape recorder • Home TV set or display monitor • Printer • Diskette drives • Hard disk drives

In addition, IBM and other vendors offer numerous add-oDS such as joysticks, light pens, and plotters. These will be described in more detail later. These units are sold and priced separately, allowing you to select the combination of options that best fit your needs.

Adapters

In addition to the units themselves, you must buy the electronics that drive them. This comes on printed circuit boards called adapters. Thus, there is a Parallel Printer Adapter, a Diskette Drive Adapter, and so on.

Page 46: The IBM Personal Computer Made Easy

32 THE IBM PERSONAL COMPUTER MADE EASY

The adapters plug into slots in the System Unit. There are five such slots, limiting ,your expansion capability (unless you buy a special expander). In orde'r to partially compensate for limited expansion capability, and also save money, an adapter card can serve more than one device. For example, the IBM Monochrome Display and Parallel Printer Adapter drives both the IBM monitor display and the IBM 80-character-per-second matrix printer.

If you want an IBM Personal Computer, you must buy the System Unit and attached keyboard. Mter that, you have a number of choices. How do you select the ones that are best for you?

THE SELECTION PROCESS

The selection of the right equipment is performed in the following steps:

Requirements

Determine, as well as you can, all the things you want to do with your PC. Here are some of the broad categories you should consider as possible areas of use:

• Business applications • Word processing • Electronic worksheets • Graphics • Music • Communication

Then define your requirements further. Do you need color? Special programs? If you overlook something, or don't have all the necessary cash, it is possible to expand later. But you can usually save money by anticipating future needs.

Programs

Find programs that meet your requirements. There are many sources of programs, including IBM. Programs for the same appli­cation vary widely in quality, price, and their specific areas of appli­cability. Investigate carefully before you buy.

Page 47: The IBM Personal Computer Made Easy

How to Select the Right Equipment 33

Equipment

When you have selected your programs, find out what equipment and software they will work with. The program documentation will tell you this. Programs require a minimum amount of memory. Some options may require more memory. A program may require a certain kind of printer, display, or other equipment.

Selection

Consult with, but don't rely on, a dealer, store, or computer center to select the actual equipment for purchase. Determine what com­bination of adapters to purchase. If you are going to do word proc­essing, discuss your printing requirements. There are many types of printers and the selection of the wrong one can cause problems.

Shop Around

Prices vary. Not all retailers carryall equipment. Check if help is available to get non-IBM equipment properly initialized and working, before payment. Check on repair and maintenance policies.

EQUIPMENT DESCRIPTIONS

In the following sections, each of the components of the IBM Personal Computer will be described in some detail. This will allow you to learn about specific features that may be important to you. Don't let the technical details put you off. They are included for completeness, but won't figure in most reader's selections. With a little judgment, you can tell what is significant for you.

The System Unit

The System Unit is a 20 x 16 x 6-inch steel cabinet, with pro­vision for housing two 5Y4-inch diskette drives. Connector slots are provided in the rear for connecting displays, cassette recorder, joy sticks, modems, and other optional add-ons.

The cover is easily removable from the chassis by anyone with a reasonable amount of mechanical dexterity.

The System Unit is the centerpiece of the computer system. All

Page 48: The IBM Personal Computer Made Easy

34 THE IBM PERSONAL COMPUTER MADE EASY

units are either inside it or connected to it. Inside the System Unit are:

• The System Board with memory and microprocessor • Optionally, one or two disk drives • Power supply • Speaker

The System Board

The System Board contains the electronics of the IBM Personal Computer. Numerous components are on this board, and a knowledge of these components will help you visualize what the computer is all about and how the optional add-ons relate to it.

The System Boardcontains the following:

• Five expansion slots for adapter boards, which drive the various optional units

Illustration 3-1 Inside the System Unit. On the right is a 12-Megabyte hard disk that fits right into one of the two disk slots. In the center is a floppy disk drive with the controller circuit board on top. Five adapters are plugged into the five expansion slots on the left. The rectangular box in back is the power supply. (Photograph reproduced courtesy of Davong Systems, Inc.)

Page 49: The IBM Personal Computer Made Easy

How to Select the Right Equipment 35

• An 8088 microprocessor • Switches for selecting memory configurations, screen-display

features, and the number of diskette drives • Processor support units, including 20-bit direct memory access

(DMA), 16-bit timer/counters, and 8 levels of interrupt • 40 KB of ROM (read-only memory), which stores Cassette BA­

SIC, self-testing programs, DOS bootstrap loader and graphic­character dot patterns. There is one spare ROM socket for an additional 8K bytes

• 16 KB of RAM (read/write memory), with sockets for an ad­ditional 48 KB. More than 64 KB requires the use of circuit boards in the expansion slots. Memory words are 9 bits, with one bit serving as a parity check on the other eight

• Various circuits for driving an audio-cassette tape player, a speaker, and the keyboard

• A spare socket for another processor, such as a specialized mathematical co-processor, for performing rapid mathematical processing

Expansion

Expansion is provided by the five expansion slots on the System Board in the System Unit. When you want to add more memory or other functions, you must:

• Purchase an Adapter Board, as well as any external unit, such as printer or modem.

• Remove the cover of the System Unit by unscrewing two flat screws in the rear. Carefully slide the cover back and tilt it up .

• Plug in the adapter cord and fasten to the frame. • Set the System Board switches, as required. Correct settings

are described in the IBM documentation . • Replace the cover.

If you are uncertain about doing any of these steps yourself, play it safe and send your PC to a service unit or dealer.

Power Supply

The power supply provides power for all internal circuits and most optional equipment. Specifications are given in Quick Reference Chart 3-1.

Page 50: The IBM Personal Computer Made Easy

36 THE IBM PERSONAL COMPUTER MADE EASY

Disk Drives

IBM supplies 5Y4-inch diskette drives, both single and double­sided. These may be internal or external units. The internal drives mount inside the System Unit, with room for two drives, side by side. For those needing more storage capacity, self-contained external drives can be connected to the same adapter that is required for internal drives. The adapter takes up one of the five expansion slots on the System Board. It can connect to up to four drives-two internal and two external.

IBM supplies 5Y4-inch diskettes for use with their diskette drives. These diskettes are a type widely used throughout the industry and are available from many sources. Never buy cheap diskettes unless you can be sure of their quality. You will lose more time and effort than you will save (see Quick Reference Chart 3-2).

IBM offers a hard disk, fixed disk drive. Other vendors do also. Check with your dealer for information on these faster, higher­capacity drives (see Illustration 3-2).

Illustration 3-2 A Winchester Hard Disk Substitutes for a Floppy in the System Unit. Five to 12 megabytes of usable storage provide large file space for business appli­cations. (Photograph reproduced ccourtesy of Davong Systems, Inc.)

Page 51: The IBM Personal Computer Made Easy

How to Select the Right Equipment 37

Displays

The IBM PC supports two types of display, referred to as Mono­chrome display and Color/Graphics display. This assures you of the versatility that comes from greater possibilities and the frustration that comes when you have to decide between two attractive choices­unless, of course, you can afford both display units. (See Quick Ref­erence Chart 3-3.)

The Monochrome display screen presents green characters on a black background or black characters on a green background. As its name implies, no other color combinations are possible. Up to 80 characters per line and 25 lines can be entered. The last line is reserved for special functions.

Besides the familiar alphabetic and numeric characters you are used to, the Monochrome display generates Greek and math symbols, table-making constructs, and some elemental graphical constructs­for a total of 256 separate characters.

If you want the Monochrome display, you have to buy the display and the Parallel Printer Adapter card, which plugs into one of the system Unit's five card slots (now you have only four left). You must also buy the display unit itself.

Suitable displays for color and graphics are TV sets or various types of monitors; black-and-white is OK if no color is needed. Color mon­itors are expensive, but they are necessary for quality color graphics. Unfortunately, some color monitors do not provide all possible colors. Get a demonstration at your dealer.

TV sets and low-resolution monitors can only display 40 characters per line with clarity, so you must get a high-resolution monitor if you want to display 80 characters per line.

The difference between a TV set and a monitor is that the TV set has additional electronics for receiving TV broadcasts. When you connect your PC to your TV set, you turn the output from the PC into a TV signal. The device for doing this is called an RF modulator, and it costs in the range of $24 to $40.

The color and graphics functions-except for the elemental graph­ical constructs referred to above-require the Color/Graphics Mon­itor Adapter. This adapter is needed if you plan to use an RF modulator for driving TV sets. It generates 40 or 80 columns by 25 rows of text. The twenty-fifth row is usually reserved for special functions described later.

Page 52: The IBM Personal Computer Made Easy

38 THE IBM PERSONAL COMPUTER MADE EASY

Printers

The IBM printer is a matrix printer (see Quick Reference Chart 3-4). This means that characters are formed by an assemblage of dots made by a matrix of moving wires that press against an inked ribbon. The result is considered to be of inferior quality to that of printers that use formed characters, as in a typewriter, for example. Computer printers with fully formed characters are often referred to as daisy­wheel printers, after their print mechanism, which is shaped like the flower.

Matrix printers are cheaper, faster, and capable of more flexibility of font and graphic output than daisy-wheel printers. If your needs are for a printer that will produce letters and other documents of high quality, however, you ' should get a daisy-wheel printer. Both types of printers can be obtained through IBM or other sources.

Never purchase a non-IBM printer unless you are sure that it is compatible with the IBM Personal Computer and the programs you will be using. Also, consider speed and quality of service. Remember th'at printers being mechanical devices are more susceptible to failure than the other components of your system.

All printers require a printer adapter that plugs into one of the five expansion slots in the System Unit. The IBM Monochrome Display and Parallel Printer Adapter is designed for use with the IBM matrix printer. Use of this combination saves the cost of an adapter and saves one expansion slot for other uses, but it precludes the use of color and graphics on any monitor that is connected to this Adapter.

Do not buy a printer adapter until you know what printer you will be using since printers have different requirements.

Game-Control Adapter

Although intended primarily for use with joysticks and paddles, the Game Control Adapter is a general-purpose analog/digital card that provides four inputs for analog and four inputs for digital signals. The card can be used by hobbyists and engineers for connecting the IBM Personal Computer to real-world input. Up to four paddles and two joysticks can be accommodated for use in games.

Page 53: The IBM Personal Computer Made Easy

How to Select the Right Equipment 39

Other Equipment

Not even a company as large as IBM can supply all the equipment that users may want to connect to their PCs, so IBM has encouraged other vendors to design and sell add-ons to the IBM PC. The result is that the IBM PC is supported by a wide range of products from many different manufacturers. Here is a list of some of the products that may be of interest to readers.

• Expansion chassis that provides additional card slots for adapters

• CP/M card that allows 8-bit CP/M programs to run on the IBM PC

• Modems • Light pens • Joysticks • Memory expansion boards (These can go as high as 1 megabyte.

Many include, in addition to memory: calendar clocks, serial ports, and parallel ports.)

The best way to learn what is currently available, and the prices, is from the ads in personal computer magazines, which are available at computer stores.

Illustration 3-3 Expanding the System While Conserving Space. This card when inserted in an expansion slot provides up to 8 separate facilities including two serial ports, one printer port, a clock-calendar and 512 kilobytes of parity-checked memory. (Photograph reproduced courtesy of AST Research, Inc.)

Page 54: The IBM Personal Computer Made Easy

40 THE IBM PERSONAL COMPUTER MADE EASY

USING THE IBM PC TO COMMUNICATE

Sooner or later, you will want to take advantage of the PC's ability to reach out and talk to other computers. Two units manufactured by IBM that make this possible are the Asynchronous Communication Adapter and the Synchronous Data Link Control (SDLC) Commu­nication Adapter.

Asynchronous Communication Adapter

This adapter is a 4 x 5-inch card that plugs into one of the five card slots in the Systems Unit (See Quick Reference Chart 3-5). Asynchronous transmission provides low-cost communication where speed is not important, and where character rates may vary. The equipment at the other end of the line must also be asynchronous.

SOLC Communication Adapter

SDLC is an IBM communication protocol that is used on most of its latest computers. PCs that use SDLC will be able to talk to IBM mainframes and some smaller computers, thus opening a new area for personal computer applications.

When connected to an external modem, the SDLe adapter can communicate over the switched network (public telephone system) or private (leased) lines to other SDLC equipment. The adapter plugs into any of the five expansion slots in the System Unit.

As a further aid in communication support, IBM provides software that allows the IBM PC to emulate other IBM equipment.

SNA 3279 Emulation and RJE Support

This is a software package that permits one or two modes of op­eration by the PC:

• As a 3270 SNA terminal • As a 3770 SNA, RJE (Remote Job Entry) terminal

IBM 3191 Emulation

This program emulates the IBM 3101 Display Terminal, Model 20. There are certain differences, depending on user-selected options

Page 55: The IBM Personal Computer Made Easy

How to Select the Right Equipment 41

related to files and diskette storage. The program provides conversion of ASCII-formatted disk files to and from binary format.

Asynchronous Communication Support

This program allows the IBM PC to emulate TTY 33 and 35 ter­minals. TTY protocol can be selected, and program and data files can be exchanged with a host computer or another PC.

TYPICAL SYSTEMS AND THEIR COSTS

In this section, I will describe some typical personal computer systems and list their component costs. All prices are list prices at the time of writing. By shopping around or through mail order, it is possible to get 20 percent or more off the list price on some com­ponents. Usually, but not always, deep discounts also mean little or no support when problems occur. You may find yourself having to deal directly with the manufacturer.

Computer prices and equipment change often, so you should use these equipment descriptions and costs only as a guide. Recheck all information before buying. In addition, costs are broken out by device and program package, so you can configure your own systems and add up the costs of the equipment that best meets your needs.

A Minimum System (Only available on special order)

System Unit with Keyboard and 16K of memory

RF Modulator for use on a home TV set Color/Graphics Monitor Adapter to drive

TV set

Total

$1,265 50

244

$1,559

This system can be used to program in cassette BASIC. It is suitable for learning elementary BASIC and playing games. However, few commercially available programs will work with this system. Most require more memory and at least one disk drive. Any tape cassette player of reasonable quality can be added to provide low-cost program and data storage.

Page 56: The IBM Personal Computer Made Easy

42 THE IBM PERSONAL COMPUTER MADE EASY

For game playing, the following equipment can be added:

Game Control Adapter Pair of paddles or joystick

Total

A Low-End Word-Processing System

(See Illustration 3-4) System Unit with keyboard and 16K memory 48 K additional memory

Three 16 K memory-expansion kits 1 @ $30 per kit

One 320K disk drive Disk Drive Adapter Display/Printer Adapter 80-Column Display Monitor

Subtotal 1

Low-cost, quality printer Printer cable

Subtotal 2

DOS and BASIC software Word processing program Total

$ 55 50

$ 105

$1,265

90 529 220 335 345

2,784

880 55

3,719

40 175

$3,934

This is- not an absolute minimum word-processing system. You might use a 40-column TV set in place of an 80-column monitor, a 160K disk drive instead of 320K, and a dot matrix printer in place of a better quality printer. However, the system listed is about the minimum practical for "serious" word processing. Still, it is a bare­bones system. For those who can afford it, the following system is recommended.

A Professional Word-Processing System

Low-end system, Subtotal 1 Add: Second 320K disk drive

64K memory expansion option

Subtotal 1

$2,784 529 350

3,663

Page 57: The IBM Personal Computer Made Easy

How to Select the Right Equipment 43

Illustration 3-4 Affordable Word Processing. The first letter quality printer to break the $1,000 barrier. The Smith-Corona TP-1 sells for under $900. It pokes along at only 12 characters per second, but for light print jobs it provides quality printing at a reasonable price.

Printer equipment Letter-quality printer, medium cost Cut-sheet paper gUide Bidirectional tractor feed Cable Forms stand Ribbon Print element

Subtotal 2

DOS and BASIC software Word Processing program

Total

2,290 115 265 55 55 19 20

$6,482

40 500

$7,022

This system has 128K bytes of memory, two 320K-byte disk drives, a professional quality printer, and a top-of-the-line word-processing program. If you don't want to spend this much, decide where you can compromise and substitute less expensive equipment.

Page 58: The IBM Personal Computer Made Easy

44 THE IBM PERSONAL COMPUTER MADE EASY

A Low-End Business System

System Unit, 16K memory and keyboard 48K Memory expansion Two 320K disk drives Disk drive adapter Display/printer adapter Monochrome display (green) Matrix, 80 CPS printer Printer cable Printer forms stand

Equipment Subtotal

Software DOS and BASIC

Programs General Accounting Accounts Receivable Inventory Control

Programs subtotal

Total

$1,265 90

1,058 220 335 345 555

55 55

$3,978

40

425 425 425

1,275

$5,293

This system has 64K bytes of memory, two 320K byte disk drives, and an 80-character-per-second printer. Two accounting programs and an inventory program turn the computer into a working business system.

An Expanded Business System

Low-End Business System, Equipment subtotal

Add: Expansion Unit, 10 Megabyte hard disk system with disk drive adapter

Color/Graphic Adapter Color Monitor 64K Memory Expansion Option

Subtotal

$3,978

3,390 244 680 350

$8,642

Page 59: The IBM Personal Computer Made Easy

How to Select the Right Equipment 45

Software DOS and BASIC 2.0

Programs General Ledger Accounts Receivable Accounts Payable Inventory

Total

60

595 595 595 595

$11,082

This system has 128K of memory, two 360K byte diskette drives, 10 million-byte hard-disk drive, a color monitor for color graphics and sales presentations, plus a monochrome monitor for data pro­cessing display. Four accounting and inventory programs make this a working small business system. If you don't like this selection, custo­mize for your own business.

A Low-End Professional System

System Unit, 16K Memory and keyboard 48K memory expansion 180K disk drive Disk drive adapter Printer adapter Color/graphic adapter Matrix printer, 80CPS Printer cable RF modulator for TV display

Subtotal 1

Software CP/M-86 UCSD FORTRAN or Pascal Compiler

Subtotal 2

Programs Electronic work sheet

Total

$1,265 90

289 220 150 244 555

55 50

$2,918

240 175

$3,333

200

$3,533

Page 60: The IBM Personal Computer Made Easy

46 THE IBM PERSONAL COMPUTER MADE EASY

An Expanded Professional System

Low-End Professional System, basic equip­ment

Add: Two 320 disk drives (First drive replaces lOOK second drive)

64K memory expansion option High-resolution color monitor

Subtotal

Software Operating System UCSD P-System with FORTRAN or

Pascal Compiler Subtotal

Programs Electronic work sheet Electronic work sheet graphic and chart

generator Color slide generator

Total

$2.918

240 529 350 680

$4,717

625

$5.342

290

300 50

$5,982

This professional system is meant for experienced programmers who want to work in graphics and spreadsheet graphics for presen­tation with a slide projector.

A Communication Terminal System

System Unit, keyboard, 160-byte drive, adapter and 64K-byte memory

64K-byte Memory Expansion Option (required)

Monochrome display (or other 80-column monitor)

Display/printer adapter SDLC Communication Adapter Up to 4800 BPS modem SNA 3270 emulation and RJE support DOS and BASIC (required)

Total

$1,864

350

345 335 300 700 700 40

$4,634

Page 61: The IBM Personal Computer Made Easy

How to Select the Right Equipment 47

This system allows the IBM PC to act as a terminal, emulating either a 3270 or Remote-Job Entry 3770 for data entry, up-loading and down-loading, or for backing up existing terminals. The host must be SNAiSDLC compatible. 1TY emulation is also available for $150 for the Asynchronous Adapter and $60 for the Asynchronous­Communication support. The 3101, Model 20, emulation is also avail­able for $140.

These systems are only a tiny sample of possible confIgurations. You are urged to study personal computer magazines, catalogs, and to visit retailers to learn about other configurations.

Page 62: The IBM Personal Computer Made Easy

QUICK REFERENCE CHART 3-1

POWER SUPPLY

Type

Voltage levels

Protection

Rating

External Availability

Fuse

Auxiliary AC Power

QUICK REFERENCE CHART 3-2

DISK CHARACTERISTICS

Available capacity (formatted) Transfer rate, bits per second Tracks per inch Number of tracks (total) Number of sides Size Maximum operating Temperature Maximum operating Humidity Error rate

Head life Media life

48

Switching

+5V @ 7A +12V @ 2A -5V @ 300ma -12V @ 250 rna

Overvoltage Overcurrent

63.5 watts, continuous

All voltages are available to all five expansion slots. About 4A @ 5 volts is available to the slots and external devices.

2 SOC SD4

110-volt, AC, nonstandard socket is available for the IBM Monochrome Display only. Will not fit standard plugs.

Single Sided

163,840 bytes 250K 48 40

Double Sided

322,560 bytes 250K 48 80

1 2 5.87"W X 8.00 X 3.38 H

95% (noncondensing) 1 per 109 recoverable 1 per 1012 nonrecoverable 1 per 106 seeks 20,000 hrs 30 X 106 passes per track

Page 63: The IBM Personal Computer Made Easy

QUICK REFERENCE CHART 3-3

SUMMARY OF DISPLAY ADAPTER CAPABILITIES

Monochrome Colorl Display Graphics and Parallel Monitor Printer Adapter Adapter

Can drive IBM Monochrome Display Yes No Can drive IBM 80-character printer Yes No Can drive TV set with 40 columns No Yes Can drive black-and-white TV set with

80 columns No Most sets: No Can use color TV with 40 columns No Yes Can use color monitor with 40 and 80

columns No Yes Underline Yes No Reverse video Yes Yes Intensity control Yes Yes Blink Yes Yes Light pen with IBM Monochrome

Display No N/A Light pen with P39 Phosphor No No color No Yes 25 lines Yes Yes 80 columns Yes Yes Direct-monitor drive Yes Yes Composite-video drive

(RF Modulator) No Yes 256-character set Yes Yes Paging No Yes Graphics-200 x 320 points with 4 colors No Yes Graphics-200 x 640 points, black-and-

white only No Yes Graphics-200 X 640 points, color No No

49

Page 64: The IBM Personal Computer Made Easy

QUICK REFERENCE CHART 3-4

IBM PRINTER CHARACTERISTICS

Characters per inch

Type Speed Print direction Line spacing

Character set Graphics Paper feed

Copies Ribbon Ribbon life Power

Size

50

5 8.25 10 16.5

Print Sizes

Characters per line

Matrix

40 66 80 132

80 characters per second Bidirectional Y6"- or ih2"-programmable

increments 96 ASCII and 9 international 64 block characters Sprocket pin feed adjustable:

4" to 10" 1 original and 2 copies Black ink, cartridge 3 million characters 120V AC @ 1 amp max

100VA max 4.2"(H) X 14.7"(W) X 12"(D)

Page 65: The IBM Personal Computer Made Easy

QUICK REFERENCE CHART ~

ASYNCHRONOUS COMMUNICATIONS ADAPTER

Interface Transmission mode Transmission rates Character length Number of stop bits Diagnostic Buffering Parity

RS-232C or current loop selectable by jumper Asynchronous 50-9600 BAUD, program selectable 5, 6, 7, or 8 bits, program selectable 1, 1 Y2, or 2 bits, program selectable Loopback on both 110 and communication sides Double buffering Even, odd or none, program selectable

Current Loop and RS-232C Connector Interfaces Pin Receiver

Modem Adapter Modem Adapter Adapter NfA Adapter Modem

Transmit data Receive data Request to send (RTS) Clear to send (CTS) Data set ready (DSR) Signal ground Carrier detect + Transmit current loop Return @ 20m a - Transmit current loop Data @ 20ma + Receive current loop Data @ 20ma Data terminal ready

(DTR) Ring indicator (RI) - Receive current loop Return @ 20m a

2 3 4 5 6 7 8 9

11

18

20

Modem

Adapter

Modem

22 Adapter 25 Adapter All other pins have no connec­tion.

51

Page 66: The IBM Personal Computer Made Easy

QUICK REFERENCE CHART ~

APPROXIMATE SIZES AND CABLE LENGTHS

Unit

System Unit Keyboard

IBM Monochrome Display

IBM 80 CPS matrix Printer

52

Size 20" (L) x 16" (D) x 5.5" (H) 20" (L) x 8" (D) x 2.2" (H)

15" (L) x 14" (D) x 11" (H)

16" (L) x 15" (D) x 4.3" (H)

Cable Length

Power: 6 ft Signal: 6 ft when uncoiled Power: 3 ft Signal: 4 ft Power: 6 ft Signal: 6 ft

Page 67: The IBM Personal Computer Made Easy

Chapter 4

How to Select the Righi Program

In selecting a program, the first rule is: Know your needs. The second rule is: Know the market. Shop around at computer stores and dealers. Read a few of the many periodicals on personal computers and business data processing for small computers. Get one of the catalogs on programs for small computers that are sold at computer stores. In particular, get all the literature on programs marketed by IBM.

The third rule is: Pick a program that fits your needs. How do you do this? It is not always easy. The best way is to ask friends and colleagues who have similar requirements what they use. For ex­ample, accountants know business programs. Professional societies may be helpful. The aim is to find somebody who has hands-on ex­perience doing what you will be doing. Other hints are discussed in the following section.

WHAT YOU NEED TO KNOW WHEN BUYING PROGRAMS

Program Reviews

Program reviews appear in most of the periodicals on personal computers. How good are they? You will soon learn that reviewers can give opposite assessments of the same program, based on their experience. For example, the writer of short articles may not properly review a word processor intended for use on long, complex docu­ments. Generally, though, there seems to be a consensus among many

53

Page 68: The IBM Personal Computer Made Easy

54 THE IBM PERSONAL COMPUTER MADE EASY

of the reviews. In any case, we will continue to fall back on program reviews just as we do on reviews of other subjects.

Try Out the Program

Spend a Saturday afternoon or an evening at a computer store. Many programs now have demo disks that do not require any hands­on knowledge to follow the sales pitch. It is better to get the real thing and sit down at a computer with the manual. You will quickly learn how well the manufacturer explains his product. If you cannot understand the manual, move on.

Demos and Manuals

You can sometimes order demo disks through the mail or on 800 numbers. Check periodical ads for these. Also, you can order manuals without the program, usually with a credit towards purchase. A good manual should tell you what input and what output to expect-most of what you need to evaluate a program. It will not tell you, however, how long the program takes or how good the program is at handling errors and equipment malfunctions-or how many bugs are still in the program.

Buy It and Try It

Most programs sell for $300 or less and many are under $100. Some \

data-base management systems cost up to $800 or $900, but few programs for small computers cost more than $1000. At these prices, a mistake on a purchase is not a disaster; you will simply be poorer but wiser about what to look for next time.

This approach doesn't work so well, however, if you are installing a major business system, such as inventory or general ledger. Then you have to invest in creating files, learning the system, and teaching others. A mistake in program selection could cost many times the price of the program itself, and also impact your business operations.

Work With a Consultant

If you are going to put a major business function on your personal computer, the results could be beneficial or a nightmare, depending

Page 69: The IBM Personal Computer Made Easy

How to Select the Right Program 55

on the circumstances. By working with a consultant, you could save yourself some trouble.

The next section contains some guidelines and checklists for se­lecting the most popular types of programs.

When considering a program, there are a number of things you must know in all cases. Then there are those things that depend on the specific area of application.

What You Need to Know in All Cases

A. Hard Facts

1. Is the program compatible with the IBM Personal Computer? 2. What is the minimum memory required? (Also check the

amount of memory required by any special features or options you plan to get.)

3. What is the number of disk drives required? 4. Under what operating system does the program run? 5. What adapter(s) are required by the program? 6. What makes of printers will the program work with, and what

print features are supported?

B. Intangibles

7. What is the quality of documentation, including provision of help screens and user prompts?

8. What is the speed of operation? (This can be hard to pin down as it varies with application, as does its importance. For ex­ample, a word processor that is "slow" for a professional writer may be perfectly acceptable to an occasional user.)

9. What vendor support for problem-solving and repair can you expect?

What You Need to Know About Specific Program Areas

For each program, I will first give you a general description of each area, and then give you a checklist that will help you evaluate how each program measures up to your requirements. The checklists item­ize the features that are important in program evaluation. There is one column for checking off or entering data on your requirements;

Page 70: The IBM Personal Computer Made Easy

56 THE IBM PERSONAL COMPUTER MADE EASY

the other four columns are for checking off or entering data about programs that you are considering.

The checklists were derived from the basic requirements of an application area, plus additional features available in programs now on the market. This means that you are unlikely to find anyone program that has all the items in the checklist. Often, you will have to reconcile what you want with what is available. Keep in mind, though, that programs are continually improving, and vendors are constantly coming out with new features. Therefore, if you don't find what you want in the checklist, it doesn't mean that it's not available.

HOW TO SELECT A WORD-PROCESSING PROGRAM

Word processing allows you to enter letters, reports, articles, manu­scripts, and documents into your PC. Once the basic material is stored on disk, the PC is used as an electronic scratch pad to delete, insert, add, change, edit, and generally prepare for printing a final copy. The material also can be retained on disk for later revisions. Retyping is eliminated. All editing and revisions are performed electronically, and they are only printed when all editing is complete. The result is much faster than either handwriting or typing.

It takes between a few hours and a few weeks to learn word proc­essing, depending on the level of complexity of the word-processing operations you will be using. Word-processing programs vary greatly in complexity, depending on their intended use.

Consideration of the kind of material you will be writing is the key to selecting the right word-processing program. Simple one- or two­page letters have different requirements than lengthy reports. Some material is too complicated for the best of today's personal computer programs, and requires a full word-processing system. For example, where extensive forms capability and multiple fonts are required, you would do better with a word processor. However, the average user who wants a general purpose word processor that can handle anything from memos to manuscripts, will find a number of programs from which to choose. This book was written with an IBM PC. I used a word processor on the IBM Personal Computer, 5 double-sided disk­ettes plus 5 for backup for a total of 10. There are about 70 word­processing and word-processing-related programs that can run on the IBM PC. They range in price from $30 to $600, with a fairly even price distribution between $50 and $500.

Page 71: The IBM Personal Computer Made Easy

How to Select the Right Program 57

Word-Processing Terms

The following discussion of word-processing terms should help to clarify some of the operations that can be performed with a word processing program.

Screen and Line Edit

A line-editing capability allows you to designate a line, usually by line number, and then make necessary changes in the line. A one­key operation calls up the next line, as needed.

Screen edit is preferable to line edit because it allows you to edit all data on the screen. A cursor is used to designate where editing is to be done.

Block Operations

Whole sentences, paragraphs, or larger groups, can be moved, copied, inserted, or deleted with one command. Methods of marking the block vary, but usually a cursor is used.

Distance

An important consideration in evaluating block operations is dis­tance. Distance specifies for how much of the text a command is valid. Thus, a block move may be valid over a page, a chapter or the complete text, in which case it is said to be global.

Find and Replace

Find, also called Search, is a powerful editing tool that allows you to specify a string of characters and ask the word processor to find all examples of that string. For example, if you wanted to find all the instances of "data," you would have the word processor search the text and display the portion of text containing the first occurrence. You might then change "data" to "information," and then call for the next instance of data. .

When Find is supplemented by Replace, "data" and "information" could be specified once, and all instances of data would be changed automatically to information by the word processor.

Although the basic idea is simple, the Find function can be com­plicated in practice. Does it distinguish between upper case and lower case? Does it pick up the designated string when it is embedded in other text? Sometimes this may be desired, sometimes not. A word­processing program should let you specify how FIND will be used each time it is applied.

Page 72: The IBM Personal Computer Made Easy

58 THE IBM PERSONAL COMPUTER MADE EASY

Utilities

Utilities can be integrated into the word processor or sold as a separate program or as an add-on option. Utilities include programs that check spelling or dictionaries that look up such things as technical terms or phrases that are entered by the user. Spelling checkers vary in their performance, depending on the size of their vocabulary and their ability to deal with hyphens and other special situations.

Word-Processing Programs Checklist

Item

1. Full-screen edit 2. Line edit 3. Horizontal centering 4. Vertical centering 5. Justification 6. Hyphenation 7. Margins B. Tabs 9. Tabs to decimal point

10. Proportional spacing 11. Reverse indentation 12. Changeable format during typing 13. Split screen 14. Boldface (overstriking) 15. Underline 16. Subscripts 17. Superscripts lB. Headers 19. Trailers 20. Page numbering 21. Selective page print 22. Selective chapter print 23. Selective file print 24. Single-sheet printing 25. Continuous forms printing 26. Find (also called Search) 27. Find and Replace 2B. Find, irrespective of capitals 29. Find, only if not imbedded in other

text 30. Global Find/Replace

Required Provided

Page 73: The IBM Personal Computer Made Easy

How to Select the Right Program 59

Item

31. Block move 32. Block copy 33. Block delete 34. Blocks of any size 35. Blocks of one sentence 36. Blocks of one paragraph 37. Blocks of one chapter 38. Pre-defined blocks 39. Vertical scroll up and down 40. Horizontal scroll left and right 41. User-defined keys 42. Simultaneous keying and printing 43. Form letters 44. Check spelling 45. Add-on spelling dictionary 46. Dictionary for recall of words and

phrases 47. Merge addresses and letters 48. Other program interfaces (e.g., use of

electronic worksheet data)

Required

HOW TO SELECT AN ELECTRONIC WORKSHEET

Provided

Electronic worksheets, also called spreadsheets, allow you to fore­cast and plan, using a "what if' analysis of related items that are entered in a table. Worksheets are laid out in rows and columns, and data is entered in a tabular format. Each table entry is called a cell.

Electronic worksheets must be evaluated in terms of size, com­putational power, reporting capability, and support.

A typical size is 63 columns by 254 rows. Most spreadsheets are limited by memory size. Some provide for disk overlays of memory, thus expanding the sheet size beyond memory boundaries.

Computational power is determined by the mathematical relation­ships that the system can handle and also by whether and how much the user can combine operations into expressions. The number of parentheses levels can be ten or more.

Reporting capability is determined by the availability of functions that allow you to print results in convenient formats, with user-sup­plied text and the optional sorting of data. On large spreadsheets, the

Page 74: The IBM Personal Computer Made Easy

60 THE IBM PERSONAL COMPUTER MADE EASY

ability to print sections that can be arranged to show the whole sheet becomes important.

Support refers to supplementary features or programs that can be supplied by the worksheet vendor or other vendors. One example is templates, which are used to customize a worksheet to a particular application. Numerous templates are available, such as real estate investment, balance sheets, cash flow, internal rate of return, am­ortization, and common depreciation methods.

Other support features include the capability to interface with other programs, such as graphics, word processors, or other worksheets. In the latter case, worksheets are combined or merged in various ways to form new worksheets. Graphics is a natural addition to an electronic worksheet concept for presenting results in an easy-to-read format. Other valuable support features are those that allow access to external files or tables for input data, and for storing results.

Several features make worksheets easier to use. These include various editing capabilities, the ability to enter data during calcula­tions or suspend calculation during entry, the ability to write-protect those cells storing information that must not be overwritten, and provision for sufficient space for entering labels that are not cryptic (room for 76 to 110 characters is typical). The ability to specifY column width, as required, is another important feature. So are variable col­umn widths.

Under the category "Other" in the checklist, you might want to enter special arithmetic functions or special templates or interfaces that are important in your work.

For anyone involved in technical or scientific applications, the number of digits of precision is a matter of concern. Typical values range from 11 to 16 digits.

There are some 18 electronic worksheets available on the IBM PC, ranging in price from $50 to $500. Most cost $100 to $300.

Electronic Worksheets Program Checklist Item

1. Number of columns 2. Number of rows 3. Selectable column width 4. Variable column width 5. Number of digits of precision 6. Number of characters in labels

Required Provided

Page 75: The IBM Personal Computer Made Easy

How to Select the Right Program 61

Item Required Provided

7. Scrolling in all four directions 8. Number of windows 9. Scrolling of windows

10. Templates 11. Report generation 12. Text insertion in reports 13. Sorting for reports 14. Selective exclusion of cells from computation 15. Table Look-up 16. Not memory dependent 17. Number of levels of parentheses 18. Referencing of a cell by relative position 19. Editing of a cell 20. Editing of a new entry when originally entered 21. Write protect cells 22. Copy blocks of cells 23. Naming of blocks for use in formulas 24. Formatting of cell for

dollars and cents rounded integers

25. Formatting by cell column row global

26. Suspend calculation during entry 27. Keyboard buffering of entry during computation 28. Consolidation or merging or more than one work-

sheet. 29. Use of color 30. Three dimensions 31. Other (specific templates, math functions and in­

terfaces)

HOW TO SELECT GRAPHICS PROGRAMS

Programs for graphics range from those that simply provide for ease of programming in BASIC to sophisticated graphic generators that have their own high-level language or menu drivers.

Color is an important part of graphics, but quality color graphics is still expensive. A color TV set is acceptable only for rudimentary

Page 76: The IBM Personal Computer Made Easy

62 THE IBM PERSONAL COMPUTER MADE EASY

displays. Graphic printers can be another drain on your pocketbook. Low-cost, dot-matrix printers can do a fair job in black-and-white, but for real quality printing in black-and-white or color, you will need a pen plotter or expensive dot-matrix printer, which costs several thousand dollars. These are the things to keep in mind as you read the enticing promotional literature for graphics programs.

Graphic programs for personal computers are mostly applied to these areas:

• Business graphics that show business-related information in the form of line graphs, bar charts, and pie charts.

• Mathematical graphics that show on an x-y axis plots of math­ematical relationships. The program may provide for multiple plots of several functions on the same axis .

• Text graphics that allow you to select, or design, your own alphabetic, numeric and special text characters. Text graphics can be used to advantage in business or any other area where special text characters are wanted to enhance a document or display.

Programs can generate graphs based on data from various sources­files, keyboard entry or from other programs-and may provide for modification in various ways through keyboard entry.

Certain capabilities and special features, such as motion, sound, and 3-D, are just now being explored for use in personal computers. We can expect some interesting products in this area as memory prices drop.

Graphics programs should proliferate in the coming years. As of now, about 30 graphics programs are available for the IBM Pc. Prices range from $25 to $5,500, but most fall in the $100 to $400 range.

Graphics Program Checklist

Item

1. Bar charts 2. Pie charts 3. Line graphs 4. x - y axis plots 5. Flow charts 6. Block diagrams 7. 35mm slides

Required Provided

Page 77: The IBM Personal Computer Made Easy

How to Select the Right Program 63

Item Required Provided

8. 8 x 10 overheads 9. User-designed text characters

10. Multiple plots 11. Merging of graphs 12. Editing of text on graphs 13. Keyboard entry of scale changes 14. Automatic modification to changed data 15. Keyboard input of data 16. Disc-file input of data 17. Data input from electronic worksheets 18. User-created symbols 19. Graphs saved on disk 20. Graphs printed 21. Graphics output to a pen plotter 22. Color 23. Motion 24. Sound 25. 3-D

HOW TO SELECT A MAILING-LIST PROGRAM

Mailing lists were one of the first and most successful applications of small computers. Many small businesses and other organizations engage in regular mailings and maintain mailing lists which must be updated, as needed. Personal computers can automate the mailing function and help to maintain more accurate mailing lists.

Mailing lists provide:

• Automatic addressing of letters, envelopes and labels • Sorting by various indexes, such as name, state or ZIP • Special features, such as maintaining and printing telephone

directories • Ability to select sublists for printing

Although the basic mailing list function is a straightforward one, as the checklist indicates, a number of variations are possible.

There are about 30 mailing-list programs available on the IBM PC, some of which are adjuncts to word processors. Prices range from $30 to $200.

Page 78: The IBM Personal Computer Made Easy

64 THE IBM PERSONAL COMPUTER MADE EASY

Mailing-List Program Checklist

Item

1. Number of entries 2. Display list on screen 3. Print name and address on labels 4. Print name and address on envelopes 5. Print name and address on letters 6. Single-paper feed printing 7. Tractor-feed printing 8. Return address printing 9. Sort facility

10. Number of sort keys 11. Selection criteria 12. Search facility 13. Number of search keys 14. Customized format 15. Number of lines per label 16. Entry of expiration dates 17. Entry of last-reference dates 18. Entry of creations 19. Printed report of new, referenced,

and expired listings 20. Multiple lists per disk 21. Promotional messages

Required

HOW TO SELECT A COMMUNICATION PROGRAM

Provided

Communication programs allow you to use your personal computer as a terminal in a communication network. This can be the same network that is used for telephone conversations. Other arrangements include the use of leased lines or local-area networks. Whatever the communication system, the program must provide for the transmis­sion and reception of data over the communication line. This is done by the use of protocol, a set of rules that govern the sending of messages. Protocols specify the format of a message, provide for error detection and correction, connect-disconnect rules, and so on. Com­munication is performed in a number of ways by different terminals. The power of computer programming can be used to make your PC

Page 79: The IBM Personal Computer Made Easy

How to Select the Right Program 65

emulate various types of terminals. Programs are available in which the IBM PC will emulate teletype terminals, several of the more widely used IBM terminals, and others.

Therefore, in selecting a communication program, your goal should be to properly interface with other equipment with which you will communicate. This will pretty much dictate what the communication program can or cannot do. Once you have decided this, program selections rests mainly with the special features, if any, that are pro­vided. Most interesting are auto-dial and auto-answer. The former programs the computer to dial the number of any telephone. If an­other computer is on the receiving end of the call, a data path is established, and messages can be exchanged. If a busy signal is re­ceived, some programs will auto-redial. Auto-dial can be initiated by some keyboard action or automatically by the program.

Auto-answer allows dialed computers to respond to a dial-up with­out any attention from human operators. These features can be useful in taking advantage of off-hours telephone rates.

Communication networks will only accept data that is in the format for which its communication protocol is designed. This might not correspond to the way data is stored in files. The communication program must make any necessary translations. Therefore, the type of files that can be transmitted are a consideration in program selec­tion. Terms commonly used to describe files of data are: text, data, ASCII, binary, and program files.

Another consideration is communication speed, that is, the number of bits transmitted per second, or, as communication people say, the baud rate. Bauds are not the same as bits, but for nontechnical read­ers, they can be equated. Communication programs are designed to work at different transmission speeds. Some work at only one speed; others can operate at several speeds. Commonly used speeds are: 110, 300, 600, 1200, 4800, 9600 bits per second.

Some programs allow you to program the protocol, that is, to select the rules of transmission, so that several types of terminals can be simulated with the same program.

Electronic mail is becoming a popular feature of communication systems. Programs are available using a number of approaches to provide this function.

You cannot connect a computer directly to a telephone or telegraph communication line because they don't talk the same language. A device called a modem (also called a data set) or DSU (for digital lines)

Page 80: The IBM Personal Computer Made Easy

66 THE IBM PERSONAL COMPUTER MADE EASY

is needed to provide translation. When selecting a communication program, find out what modems it can work with (see Illustration 4-1).

Illustration 4-1 A Modem. The modem pictured here is a smart modem, which means it can auto-dial, redial, pulse dial, touch-tone dial, operate at more than one speed and more. (Photograph reproduced courtesy of Hayes Microcomputer Products, Inc.)

In the checklist, you will find a number of technical items of interest only to those who are familiar with data communication. If these are foreign to you, concentrate on how you want to use your PC. If the program provides for this, the technical details will take care of them­selves.

IBM is strongly committed to the concept of the PC as a terminal. This is reflected in the programs they supply for terminal emulation. In addition, other vendors offer communication programs, so that there are now over 35 communication programs for the IBM PC. These programs support non-IBM terminals as well as IBM terminals, which means you can communicate with the non-IBM world of DEC, H-P, and others.

Prices range from $25 to $650, with considerable product availa­bility in the $40 and the $125-$150 range.

Page 81: The IBM Personal Computer Made Easy

How to Select the Right Program 67

Communication Program Checklist

Item

1. Communication with: Information utility News service Time-sharing service Data-base service

2. Terminal to be emulated 3. Controller to be emulated 4. Non-IBM connection 5. Up-loading of files 6. Down-loading of files 7. ASCII files B. Binary files 9. Program files

10. BO-column line files 11. Files of spreadsheets 12. Automatic dialing 13. Automatic answering 14. Automatic redial 15. Automatic logon 16. Automatic retry on error 17. Automatic transmission at a set time lB. Display list of files transferred 19. Print message as received

Required

20. Stop to allow disk replacement for large files 21. Keyboard conversations 22. Data compression 23. Electronic mail 24. BISYNC protocol 25. SDLC protocol Programmed Protocol: 26. Start bits 27. Stop bits 2B. Parity bits 29. Half/full duplex 30. RS232 lines 31. Synchronous 32. Asynchronous

Provided

Page 82: The IBM Personal Computer Made Easy

68 THE IBM PERSONAL COMPUTER MADE EASY

Item

33. Baud rate

Required

75, 110, 300, 600, 1200, 1800, 2400, 4800, 9600 34. ASCII 35. EBCIDIC

Provided

HOW TO SELECT A PROGRAM FOR BUSINESS APPLICATIONS

In a broad sense, all the previous programs discussed in this chapter can be considered business applications. In this section, however, we will use the term business application to refer to main-line business functions such as accounting, inventory, and orders.

For business applications, there are three ways to go:

• Write the program in a programming language, such as BASIC. • Purchase a data-manager system or program generator and use

it to develop applications. • Purchase applications programs.

Data Managers and Program Generators

Data managers and program generators are not really the same thing, but since these terms are not precise descriptions of the range of programs available, there is overlap and ambiguity.

A data-management program is anything from a simple file handler that will search for and retrieve records to a full data-base management system with an English-like query language. The more powerful data managers have become quite popular in small business applications. The data-management program consists of general-purpose software that can be used to develop inventory, accounting, mailing lists, and reports, to name but a few applications. As you might suspect, the more powerful the data manager, the harder it is to learn and use­other things being equal.

Program generators are more recent additions to the personal com­puter scene. Generally, they allow you to create programs without programming. Most use a fill-in-the-blanks approach. In some cases, the result is a program in BASIC; in others, it may be in machine language. The idea seems to have merit, but when and how they are preferable to data managers is not yet clear.

Page 83: The IBM Personal Computer Made Easy

How 10 Selecllhe Righi Program 69

Application Programs

Application programs are specialized programs that are designed to do one thing and do it well. Thus, one application program will do inventory; another, general ledger; and so on. Some application programs allow a limited amount of customizing to a user's needs through the entry of parameters. In general, though, application pro­grams are inflexible. If they fit your way of doing business, you can benefit. If not, you can change your operation so it fits or look else­where for programs that are compatible. Although one application program at $200 to $600 is less than one powerful data-management system at $700-900, if you add up inventory, accounting and sales packages, application program costs can reach into several thousands of dollars.

Here are the advantages and disadvantages of each approach.

Method Write your own programs

Data-base management system

Application programs

Advantages Lowest up-front cost. Most flexible. Can customize to your specific needs and ways of doing busi­ness. Less costly to pur­chase than applica­tion program. Pro­vides more flexible programs. Can ac­commodate consid­erable change. No special skills re­quired. Lowest in­vestment in time.

Disadvantages Most costly in terms of time to develop. Requires the most specialized talent.

Requires some ex­pertise in the system. Slowest in operation. High initial cost for first application.

Limited flexibility to tailor to your opera­tions. May require you to change pro­cedures. Highest to­tal program cost if a full business system is purchased.

For business applications, the format of the checklist has been changed to better reflect the generality of this area of program selection.

Page 84: The IBM Personal Computer Made Easy

70 THE IBM PERSONAL COMPUTER MADE EASY

Business Application Program Checklist

1. The master file can accommodate all your records. 2. Reports and screen output has all the information

you need. 3. Key fields such as account number are large enough

and provide the format you use. 4. The program produces sufficient audit trails. 5. All legal requirements are met. 6. There is adequate provision for recovering master

files if the system crashes. 7. The program can be integrated with other business

programs without repeated data entry. 8. There are validation checks of critical fields. 9. There are batch total checks of money amount en­

tries. 10. System performs reasonably fast. 11. If sorting is used, you have checked the time it

takes to sort your size files. 12. There is room to add records to the master file of

at least 15-20 percent. p. You have examined the procedures required for

day-to-day operations. 14. Error messages give clear indications of the prob­

lem and what to do about it. 15. You have examined the documentation and it is

clear and detailed. 16. If you are buying a program less than one-year-old,

you have checkt:d with somebody with hands-on experience for adequacy and reliability.

YES NO

Page 85: The IBM Personal Computer Made Easy

Part 2

HOUlIO UselhelBM PersOnal Compuler

Page 86: The IBM Personal Computer Made Easy

INTRODUCTION TO PART 2

Part 2 is a hands-on tutorial on how to use the IBM Personal Computer. In the following pages, you will be asked to make keyboard entries and observe the results on the screen. Often, you will not get the results called for in the book. Do not panic. Do not get discour­aged. Do not think you cannot learn to use a computer. This is perfectly normal. Experienced users make entry errors and program­ming errors. For a beginner, errors are inevitable.

The remedy for errors is to treat them as necessary evils, and to learn how to correct them quickly. For your peace of mind, you should know that you cannot hurt the computer by any combination of key entries. You can get some very weird images on the screen, but there is always a way to clear them up.

When you don't get the results you are looking for, often the computer will have displayed an error message on the screen. One error message you will see often is syntax error, which means that you didn't follow the rules for a particular type of entry. Error mes­sages clue you in to what is wrong-sometimes. Unfortunately, some error messages are cryptic, and others are downright misleading. Sometimes, there will be no error message, because even the com­puter cannot figure out what you have done.

Quick Reference Chart 5-1 shows the most common causes of errors and what to do about them. It will help solve most problems and explain some of the more puzzling error messages. Some of the terms in the chart are explained in later chapters. The thing to re­member about typographical and syntax errors is that you can stare right at them and not see them.

Some combinations of keys can cause you to lose control. Even Ctrl-Alt-Del (RESET) fails to work. The computer is said to be hung­up. It is probably caught in an endless loop or some essential instruc­tion has been temporarily destroyed. The solution may be painful, but it is simple. Just switch the computer off. Wait for the fan to stop and switch it back on. The computer will go back to normal. If you had data in the memory, it will be gone, but at least the computer will be perfectly healthy.

You can avoid loss of data, and maybe save hours of work, by frequently saving your work to disk, where it is safely stored when the power is off. I will show you how easy this is to do in a later section.

72

Page 87: The IBM Personal Computer Made Easy

Chapter 5

Exploring the Territory

In this chapter, I will firstcover the preliminaries that are required each time the computer is turned on. Then, I will explore how the keyboard works and some of the simpler things the PC can do. This should whet your appetite for the more intriguing subjects that follow in later chapters.

TURNING ON

Remove any disks in the disk drive. Turn on the computer and your monitor or TV. For several seconds, nothing will happen. You will hear the fan come up to speed while the computer runs through a series of diagnostic tests on the hardware. If you have a disk drive, you will also hear the drive chugging away as it initializes for oper­ation. If they are not unduly loud, any sounds you hear are normal. When the computer completes its diagnostic test, it will give a short beep, indicating that everything is okay. The computer will also dis­play the word OK on the screen and a flashing line, called a cursor, will appear. The cursor marks the screen position where your next keyboard entry will appear when you hit a key (see Figure 5-1).

Function key definitions will appear on the last line of the screen. I will talk about these later.

KEYBOARD CALISTHENICS

Type the key marked A. A lower case a will appear on the screen, and the cursor will move one position to the right.

73

Page 88: The IBM Personal Computer Made Easy

Cle

ar s

cree

n lin

e b

ut

no

t m

emor

y,

Esc

Fu

nct

ion

ke

ys

Inte

rru

pt

and

Ret

urn

to C

omm

and

Leve

l fr

om

RU

N a

nd A

UT

O,

,..--------

Ctr

l-B

reak

-------~

Pau

se i

n L

IST

or

pri

nti

ng.

,------

-C

trl-

Nu

m Lock-----~

Cle

ar s

cree

n, h

ome

curs

or.

~---

Ctrl

-Home----~

Typ

ew

rite

r ke

yboa

rd

.... C

trl-~

//

Mov

e cu

rsor

one

wor

d.

'-------

Ctr

l-E

nd

----

---

-/

Cle

ar t

o e

nd o

f lin

e.

'-------------

Ctr

l-A

lt-D

el

/ R

ES

ET

and

ent

er D

OS

or

case

tte B

AS

IC.

Nu

me

ric

keyp

ad

and

curs

or

con

tro

l ke

ys

Figu

re ~ 1

Keys

and

Key

Com

bina

tions

..... .... -

t :::c

m

iii

~

"'CI

m

::zJ

en

c z ,. r­ n c ~

"'CI

c:

-t m

::zJ

~ ,. C

I m ~ -<

Page 89: The IBM Personal Computer Made Easy

Exploring the Territory 75

Now hold down the A key. Surprise! You will see that a's are continuously printed across the screen. Keep your finger on the key until you have two or three lines of a's.

Press the ESC key. Your a's are gone-forever. Remember this: You must avoid hitting the ESC key accidentally, or you will lose the last line entered.

Now press one of the two shift keys, the keys with the t mark on them.

NOTE: that the left-hand shift key is one key farther left than most keyboards. This will take some getting used to by experienced typists. Hold the shift key down; press A again; and hold down the key to get a string of upper case A's.

Press the Caps Lock key, and notice how the output shifts to upper case. The Caps Lock key affects only the letters A-Z. The other keys are still under control of the shift keys. Test this by pressing the semicolon/colon key with, and without, the shift key. What effect does the shift key have on letters A-Z now? If you hit the Caps Lock key again, you will find yourself back in lower case because the key acts as a toggle.

Hit the backspace key, the one in the top row with a +- mark on it. This key deletes your previous entry. Hold the key down. It will continue to delete until the whole line is wiped out.

Look at the group of keys on the right of the keyboard with the numbers 1 through 9 in the upper-left corner of the key. This is a numeric pad that is used for fast entry of numeric data. It is activated by pressing the key above the pad labeled Num Lock. It is deactivated by pressing Num Lock again. Try it.

It makes no difference whether you use the keypad or the top row of keys for numeric entry and other symbols, such as + and -. Choose whichever is the most convenient.

With the numeric pad deactivated, press the pad's 6 key, the one with a ~ mark. Hold this key down, and watch the cursor move to the right. What happens when the cursor reaches the last column? Now, try each of the other arrow keys on 2, 4 and 8. What happens when the cursor reaches the top or bottom row? These are cursor control keys. They let you position the cursor quickly in any screen position. Practice moving the cursor around the screen and making keyboard entries.

Cursor movements do not erase or otherwise affect previously en­tered data, even when the cursor moves right over previously entered

Page 90: The IBM Personal Computer Made Easy

76 THE IBM PERSONAL COMPUTER MADE EASY

data. If you type over previously entered data, however, the new data replaces the old on the screen.

Press the Home key. The cursor jumps home to the top left corner. Move the cursor away from home. Now press the Ctrl key, hold it down, and press the Home key at the same time:

Ctrl-Home

Again the cursor jumps home, but now the screen is also cleared. Place the numbers 1, 2, and 3 in the first, second, and third rows

respectively. Now move the cursor to the bottom of the screen. Press the Z key, and hold it down until the line fills up. Release the key, and then hit it once or twice. See what happens. The whole screen moves up one line. The 1 you entered in the top row is gone, and the 2 you entered has taken its place. A new blank line has appeared at the bottom. This is called scrolling. When you are entering more data than one screen can hold, scrolling allows you to keep going while retaining the most recently entered information. This is usually more convenient than erasing the whole screen and starting over on top. However, you are always free to do the latter if you want to.

Using the ENTER Key

The ENTER key is used to signal the computer to save everything that you have entered since the previous use of the ENTER key. Unfortunately, this important key is not marked Enter. Instead, it is marked with a +oJ to signify next line, or in typewriter language, carriage return, line feed. After you press the ENTER key, the cursor moves to the far left on the next line.

You will find the extra-large ENTER key on the right side of the keyboard, next to the numeric pad.

First Important Point: I will always designate the +oJ key by calling it Enter. Thus, when you are told to press the ENTER key, it means press +oJ

Second Important Point: When I say to Enter something, type in the data and hit the ENTER key. For example: Enter NEW and AUTO, means type in NEW, hit the ENTER key, and then type in AUTO and hit the ENTER key.

Other keys are discussed in Quick Reference Chart 5-2.

Page 91: The IBM Personal Computer Made Easy

Exploring the Territory 77

SIMPLE BASIC

In this section, you will be introduced to the BASIC language. BASIC is an ideal language for the PC, especially when it is used as an electronic scratchpad. BASIC is easy to learn, a pleasure to use, and lends itself to the creation of quick, cut-n-paste programming. Let's try it.

In order to make sure we all start this session with a clean slate, turn off your PC, wait for the fan to stop and turn back on. This will initialize the PC.

We communicate with BASIC by issuing statements and "com­mands," telling BASIC what you want to do. However, BASIC will only obey a statement or command that is entered under its OK prompt, preferably on a clear line. If the line is not clear, the results are unpredictable.

Is your cursor on a clear line under the OK prompt? If not, clear the line with the Esc key, or hit ENTER until it moves into position. If you get a Syntax error message, ignore it. If the screen is full, you may have to go to the last line to get a clear line. Then the screen will scroll up, providing a clear line in the next-to-Iast row. The twenty-fifth line, showing function key definitions at the bottom, is never scrolled or run over by the cursor.

The CLS Command

With the cursor on a blank line under OK prompt, the way BASIC likes to see it, enter CLS on the keyboard. This is the clear screen command, which gives you a fresh new screen to work with and sets the cursor in the Home position in the upper-left corner. If you haven't already done so, press enter and see it happen.

The PRINT Statement

Enter the statement:

PRINT "BASIC IS EASY·

Hit ENTER. If you don't see BASIC IS EASY displayed, check your typing. Note that the quotes are gone in the new line. Did you enter quotes on the PRINT line?

Page 92: The IBM Personal Computer Made Easy

78 THE IBM PERSONAL COMPUTER MADE EASY

PRINT is a statement in BASIC that tells the computer to write on the screen the data that follows. It dates back to when all computer output went to printers. Now there are screen displays, but the PRINT statement has been carried over. Other statements are used for ac­tually printing.

In BASIC, a statement is one instruction or operation. A program is composed of one or more statements-possibly thousands-exe­cuted one after the other (see Quick Reference Chart 5-3).

Upper and Lower Case Make No Difference

Enter in lower case:

print "Lower case is OK"

Hit ENTER. Whether you use upper or lower case for statements or commands

makes no difference to BASIC. Try this:

pRiNt "Mixed upper and lower"

It is up to you whether you use upper case, lower case, or mix them up. However, throughout this book, for ease of presentation, statements and commands will be shown in upper case.

Enter:

PRINT 1 2 3 4

separating each digit with a space and not using quotes. Hit ENTER. Compare the result with the following entries.

PRINT 1; 2; 3; 4; PRINT 1 ;2;3;4; PRINT 1, 2, 3, 4,

As you can see, various options are available with the PRINT state­ment. Quick Reference Chart 5-3 summarizes the applicable rules.

Try these entries to see what you get:

PRINT A PRINT1 ;2;3;4;

(Omit Quotes on alpha characters.) (Omit spaces.)

Page 93: The IBM Personal Computer Made Easy

PRINT 1; 2; 3; 4; PRINT 1 2; 3;4;

Editing a Line

Exploring the Territory 79

(Use two spaces.) (Use mixed style.)

Now press the Caps Lock key and enter:

PRINT NO QUOTES IN THIS ENRY

ENTRY is purposely misspelled: ENRY .. When you hit ENTER, you will get 5 zeros separated by two blank

spaces. BASIC was fooled into interpreting these words as numbers because there are no quotes around the alpha characters. You could retype the entry, but there is another way. Instead, use the keyboard edit keys to make changes to the original entry.

Using the cursor keys (the keys on the numeric pad with the ar­rows), locate the cursor under N in the word NO. Now hit the DEL (delete) key. The N will disappear. Hit DEL again to erase the O. Notice that all the characters to the right of the cursor move left.

Enter a quote. Then zip the cursor right by, holding down the cursor key with the arrow sign (~) and stop under R in ENRY. Hit the Ins (Insert) key. Now type a T. The T is inserted at the original cursor position. All characters to the right of the cursor move over to make room. The cursor also shifts right to be in position for more insertions. Take a close look at the cursor. When you are in insert mode, the cursor expands to half-character height. The Ins key toggles insert ON and OFF.

Now hit ENTER. This time BASIC has no problem interpreting the entry. Note that only a quote on the left was required to clue BASIC to the fact that the entry was not a number. Note also that you did not have to retype the invalid first entry. You just moved the cursor up and corrected the errors. Remember this, because it can save you lots of frustration if you are not the world's best typist. Get in the habit of correcting mistakes instead of retyping. BASIC's edit capability makes this easy.

Move up several lines to a previously entered PRINT statement. Make some changes. Hit ENTER. BASIC does its thing. BASIC acts on the last entry at which the cursor is located. This is a very powerful feature. It means you can repeat a statement over and over simply by moving the cursor to the statement you want. Make a change in

Page 94: The IBM Personal Computer Made Easy

80 THE IBM PERSONAL COMPUTER MADE EASY

the statement, and BASIC executes the new statement. Try this for the PRINT statements.

The Edit Keys

Get a dear line by pressing the ESC key. Enter CLS. Enter the following, but don't hit ENTER.

PRINT "THE EDIT KEYS MAKE PROGRAM WRITING MUCH EASIER.·

Now explore the use of the edit keys described in Quick Reference Chart 5-2. Learn what each key does. A dash between the keys means you should hold down one key while pressing the other.

Examples:

Ctrl- -+ Hold down Ctrl and press -+.

Ctrl-Brk Hold down Ctrl and press Brk. Ctrl-Alt-Del Hold down Ctrl and Alt and Del.

Arithmetic Operations

Owners of personal computers sometimes forget that they have a powerful calculator at hand. Using the IBM Personal Computer as a pocket calculator may seem like overkill, but one of the features of computers is that they can be used for many things. Get in the habit of using your PC as an electronic scratchpad. We will use calculator­like operations to demonstrate how to do arithmetic in BASIC.

Each of the examples in this section demonstrates some feature of the IBM Pc. Try to learn how BASIC works from these examples.

To make the entry of numbers easier, use the numeric keypad at the right of the keyboard. To activate the keypad, press the Num Lock key. Now verify that the keypad is working. Do the keys repeat if held down? Do the cursor keys still work?

Addition and Subtraction

BASIC recognizes the commonly used symbols for addition, sub­traction, decimal point, and negative numbers.

Enter:

CLS.

Page 95: The IBM Personal Computer Made Easy

Exploring the Territory 81

Ignore any "Syntax error" message from BASIC. Use the + and - keys by the keypad, and the decimal point on the Del key. Key in:

PRINT 5+6; .05+9.95; 7 -2; 2-7; 5+6+ 7 -2+810

Press ENTER and check the result. Now try this: Enter:

PRINT 999999999999999 + 1

Now hit Num Lock to activate the cursor keys, and use them to set the cursor back at the last entry. Insert one more 9, making sixteen 9s. Hit ENTER and see:

1D + 16

BASIC has switched to double precision, floating-point notation. I will not go into floating point here, but if you are going to be working with large numbers, you should read the discussion about this in the IBM BASIC manual.

Multiplication and Division

The BASIC symbol for multiply is the asterisk. Enter:

PRINT 2*4; 999*999; -1*100; - 10*-10+6-2

The BASIC symbol for division is the slash, "f". Enter:

PRINT 20/5; -20/4; 10/3

Try this:

PRINT 1/0

And this:

PRINT 1 + 2 * 3/4 - 5

Page 96: The IBM Personal Computer Made Easy

82 THE IBM PERSONAL COMPUTER MADE EASY

Can you figure out the order in which BASIC processed these arithmetic operations?

HIGHER MATHEMATICS

If you are not up on subjects such as trigonometry and logarithms, you can skip this section. If you are knowledgeable in these areas, you will find that the PC has important features not shared by cal­culators.

Exponents

The symbol for an exponent is a caret n, which is found on the "6" key.

Enter:

PRINT 5'2; 2'2'3; - 5'2; 5' - 2; 5'0;

Here is an example using mixed operators. Can you figure out the order of processing in this example?

PRINT 8-4'2+3*4/2'2-1

Parentheses

As the last example demonstrates, predicting the order that BASIC will use in processing arithmetic operations is not always easy. You can memorize rules of precedence, but it is easier and safer to use parentheses in BASIC, just as you were taught in school. Then you will write the previous example as follows:

PRINT 8 - (4'2) + (3*4/(2'2))-1

That is how BASIC interpreted the above expression. Another interpretation might be:

PRINT 8 + ( - 4)'2 + 3*(4/(2'2))-1

Liberal use of parentheses will lead to correct arithmetic expres­sions.

Page 97: The IBM Personal Computer Made Easy

Exploring the Territory 83

Test BASIC's proficiency with the following:

PRINT (3 - 5)(5 - 2)

Use the edit keys to change the above statement so Basic will perform the indicated multiplication.

Trigonometric Functions

For X in radians, BASIC will calculate:

SIN(X) COS(X) TAN(X) ATN(X) (Arctangent)

Enter:

PRINT SIN (0); SIN(3.141 /2); (SIN(2))*2 + (COS(2)P PRINT (SIN(2)/COS(2)) - TAN(2) PRINT TAN(ATN(2))

logarithm and Exponential Functions

BASIC calculates the natural logarithm of x and raises e to the x power with these operations,

LOG(X) EXP(X)

Enter:

PRINT LOG(3); LOG(2); LOG(0)

BASIC doesn't allow LOG(0). It issues an error message: Illegal function call.

PRINT EXP(1); EXP(0); EXP( -1) PRINT EXP(10)*EXP( -10)

Page 98: The IBM Personal Computer Made Easy

84 THE IBM PERSONAL COMPUTER MADE EASY

Miscellaneous Functions

Other useful functions provided by BASIC are illustrated by the following examples:

PRINT SQR(S) PRINT INT(S0.6)

PRINT SGN( -0.1) PRINT SGN(.01) PRINT FIX(S0.6) PRINT ABS( - .01) PRINT CINT(S0.6)

Try these:

PRINT S - SQR(S2) PRINT SGN(SIN(3.2)) PRINT ABS(SGN(SIN(3.2)))

(Take the square root of a number.) (Get the largest integer less or equal to a given number.) (Get the sign of a number in the form: 1 or -1) (Truncate a number to an integer.) (Get the absolute value of a number.) (Round a number to an integer.)

You have laid some of the groundwork for programming in BASIC. I hope you have also begun to gain confidence in working with your personal computer and are anxious to learn more. I will pause here, however, to allow you some time for practice and review. Remember, you can't hurt the personal computer by pressing keys. Don't be afraid to try things on your own. This is the best way to learn.

Page 99: The IBM Personal Computer Made Easy

QUICK REFERENCE CHART 5-1

THE MOST COMMON ERRORS AND WHAT TO DO ABOUT THEM

Error/Symptom

Typo, general

Typo, specific

Syntax, general

Syntax, specific: Commas, spaces, quotes, and dashes very often used-or not used-in­correctly

Syntax, specific: Parameters in wrong order Bad command or file name

Command entered with no response

Too-many-files error mes­sage, although you have less than 64 files (single side) or 112 files (double side)

Computer doesn't return cor­rect data after LOAD or RUN command

Forgot to hit ENTER after last entry

Remedy/Cause

Try to avoid retyping because you may make another error. Get in the habit of using the powerful edit capability. The letter "0" was entered instead of zero or vice versa. Zero is written with a slash: 0. The letter "1" was entered instead of a "1" or vice versa. Use the direct mode to try for the correct combination. This is usually the fastest. Or go back to the original description in this book or in the IBM BASIC manual. Same as above.

Same as above.

Check the prompt character. Are you at the wrong level for the command entered? Also check syntax. You are not in Command level. Press Ctrl­Break. This is a misleading error message, occurring on syntax error for SAVE or OPEN. Put quotes on both sides of the file name.

You forgot to save the latest version of your file. Think back. Check the directory for the presence of the file on disk. You SAVE the file with the wrong name. You use the wrong name in the LOAD or RUN command. You SAVED another file, using the wrong name, over this file (the ultimate sin). If you have made additional entries, edit them out or reenter the line.

85

Page 100: The IBM Personal Computer Made Easy

Error/Symptom

Entered a command when not in the command mode

When you LIST your pro­gram, there are more en­tries than you expect, or the wrong entries

Key combination does not work right

You edited a line and you're "sure" it is correct, but the change does not appear in LISTing

86

Remedy/Cause

Ctrl-Break will usually get you into the com­mand mode You did not enter NEW before starting your program entries, or you made program changes incorrectly-often lines are added or deleted incorrectly. Keys that must be pressed together are writ­ten with a dash separator, e.g. Ctrl-Break. Press the Ctrl first. Keep it down. Then press Break. The correct sequence is in the se­quence the keys are written. You forgot to hit the ENTER key after the line was edited. This is most common when you edit more than one line at a time.

Page 101: The IBM Personal Computer Made Easy

QUICK REFERENCE CHART 5-2

EDIT KEYS

Key

t, +-, '" , ~ Ins

Del

~ End Ctrl- ~ Ctrl- +­

Home

Ctrl- ~

Ctrl-End

Ctrl-Break

Function

Move cursor up, left, down or right. Allows insertion of one or more char­acters at the cursor position. Remains in effect until a cursor or ENTER key is pressed, or until the Ins key is pressed again. When Insert is in ef­fect, the cursor expands to one-half character height. Allows deletion of characters at the cursor position. Tab right. Tab left not operative. Jumps cursor to end of the logical line. Jumps cursor to the next word. Jumps cursor to the previous word. Jumps cursor to top row, first column. Does not clear screen. Fills remainder of line with blanks. Jumps cursor to next line, first col­umn. No line feed character is en­tered. Backspace. Erases from the cursor to the end of the logical line. A logical line consists of all characters entered between two hits of the ENTER key. Returns BASIC to the command level. Unlike Esc, the line is not erased. On the other hand, it is not entered ei­ther, since the ENTER key was not pressed. The OK prompt is not dis­played.

87

Page 102: The IBM Personal Computer Made Easy

QUICK REFERENCE CHART 5-3

PRINT STATEMENT RULES

• Quotes PRINT "letters and 1234" Alphabetic characters must be enclosed in quotation marks. Numbers are able to be in quotes.

• Semicolon and Spaces PRINT 1;"cl2";"ABC";5; -312 "letters" Numbers followed by a semicolon result in one space inserted before the next character. Any character in quotes is not separated from following character in quotes. Numbers are allowed one place for a sign character whether printed or not, but only the minus sign is printed .

• Commas PRINT 25, "letters", 5, - 5 Items following a comma go into the next print zone. Print zones are spaced every fourteen characters.

• Staying on the Same Line PRINT 44; or PRINT 44, or PRINT 44 SPC(5) or PRINT 44 TAB(1) If PRINT ends in semicolon, comma, SPC, or TAB, the next PRINT statement follows on the same line.

• Blank Line PRINT When PRINT is not followed by any items, a blank line is printed.

88

Page 103: The IBM Personal Computer Made Easy

QUICK REFERENCE CHART 5-4

ACTIONS THAT DO AND DON'T CHANGE YOUR PROGRAMS

Program in Program on Action Memory Disk

BASIC Commands LIST No No RUN No No LOAD Yes No SAVE No Yes, if name is iden-

tical. No otherwise. ,CONTinue No No NEW Yes. Program is No

erased. SYSTEM Yes. Program is No

erased. Keys

Esc No. Only data No on screen is erased, pro-gram line is saved.

Upper or Lower No No case

Ctrl-Break (to stop a No No program)

Ctrl-Alt-Del (Reset) Yes. Your pro- No gram is lost.

Ctrl-Num Lock No No (Pause)

Cursor movement No No Ins (Insert charac- Yes, if ENTER No

ters) key pressed. No otherwise.

Del (Delete charac- Yes, if ENTER No ters) key pressed.

No otherwise. Home No No End No No Entries on a LISTed Yes, if ENTER No

program key is pressed. No otherwise.

89

Page 104: The IBM Personal Computer Made Easy

Program in Program on Action Memory Disk

DOS Commands FORMAT Yes, program Yes

erased. DISKCOPY Yes, program Yes

erased. COpy Yes, program Yes, only if names

erased. are same on same disk.

90

Page 105: The IBM Personal Computer Made Easy

Chapter 6

How to Use BASIC

In this chapter, you will learn how to write a program.

HOW TO WRITE A PROGRAM

You have already learned to enter statements in BASIC. In order to write programs with many statements, a different mode of operation is required.

Direct and Indirect Modes

BASIC has two modes of operation: Direct and Indirect. (Some systems use the more descriptive terms, Immediate and Deferred.) All your work with BASIC up to now has been in the direct mode. In the direct mode, BASIC performs the requested operation im­mediately after you press the ENTER key. When you entered the PRINT statements, you saw the results instantly displayed on the screen. The direct mode is useful for calculator-type operations and for testing your memory of the correct way to enter a BASIC command or statement. You can try what you think is right and, if it is not, BASIC will immediately return syntax error, a sign that something is wrong with the entry. Don't be afraid to try things. You can't hurt BASIC.

In the indirect mode, a number of statements are entered, but they are not executed until the command RUN is entered. This group of statements is called a program or a routine. If it does a complete job, it is called a program. If it does only a part of a job, it is called a routine, or often, it is called a subroutine or subprogram. A program can be only one statement, or it can be many hundreds of statements, all depending on what you want to do.

91

Page 106: The IBM Personal Computer Made Easy

92 THE IBM PERSONAL COMPUTER MADE EASY

All indirect statements are preceded by a number. This tells BASIC that you are entering a program and want to defer execution.

Type:

NEW 10 PRINT "DEFERRED ";

NEW is a command that tells BASIC to start a new program. It is executed as soon as you hit ENTER. Note the space in Line 10 between D and ". Now press ENTER. BASIC stores your entry, but does not execute it. The cursor is moved to the next line. Type the next line:

20 PRINT "MODE"

Now enter this line by pressing the ENTER key. BASIC accepts each line and waits for the next command.

Type RUN and hit ENTER. BASIC will display:

DEFERRED MODE

Congratulations! You have just written and run a two-line program.

Program Line Numbers

Remember that whenever you want to say Enter, you should type in the entry and hit the "~" key.

Type:

15 PRINT "INSERT

Then enter:

3 PRINT "START

The next entry is a command, not a program line, so don't enter a number. Type:

RUN

Page 107: The IBM Personal Computer Made Easy

How to Use BASIC 93

Notice that the output includes both the latest lines entered as well as the lines entered in the previous section. BASIC saves all program lines until you enter NEW. This example illustrates the following rules for line numbers:

• Line numbers can start with any number. • Line numbers can be incremented by any amount . • Line numbers can be entered in any order. BASIC will reorder

them in sequence. • BASIC processes lines in sequential order of their line num­

bers, irrespective of the order in which they were entered.

Incrementing line numbers by 10 rather than 1 provides the ca­pability for the insertion of new lines. Programming always seems to require additional lines to make a program run right, and leaving gaps for these lines avoids having to reenter many entries. Get in the habit of numbering by ten, at least. However, IBM's BASIC RE­NUMbering command makes this easier than in some other BASICS. More on this later.

How to LIST a Program

Enter the command:

LIST

BASIC displays all the lines you have entered in line sequence order, letting you inspect your handiwork.

Now enter:

LIST 10

This time, only line 10 will be displayed. Finally, type:

LIST 10-20

All lines from 10 through 20 are listed. In long programs that don't fit on the screen, you will need to list specific lines. SpecifY line numbers, as in the above examples.

Page 108: The IBM Personal Computer Made Easy

94 THE IBM PERSONAL COMPUTER MADE EASY

Renumbering Lines

Our program has an oddball line number in the first line. It would be nice to have equal increments, starting with 10. To do this, enter:

RENUM

and then:

LIST

Now all line numbers increment by 10. When you are developing programs, you will have many occasions to use RENUM.

NOTE: RENUM never changes the sequence of the lines, only the line number.

Deleting Lines

A line can be deleted simply by entering the line number and then pressing the ENTER key. Enter:

10 LIST

Now line 10 is gone. You can delete a group of lines with the DELETE command.

DELETE Line I-Line 2 deletes all lines from Line 1 through Line 2 inclusively.

Function Keys

On the left ofthe keyboard are two rows of keys, marked Fl through F10. These are function keys. They can be set to display a group of characters, saving you time and effort.

Press F1

Fl causes LIST to be displayed. Now hit ENTER. Each function key generates a different character group. Usually,

these are BASIC or DOS commands, but they do not have to be.

Page 109: The IBM Personal Computer Made Easy

How to Use BASIC 95

How do you remember what each function key does? Look at the last line (line 25) on your screen. Each entry on that line tells you what the corresponding function key does. For example, 1 LIST shows that Fl key performs the LIST command. The leftward-pointing arrow (~) on three of the bottom line commands are Entry keys that mean the command will be entered and carried out when the function key is hit. Try this with F2. Pressing it will cause your program to RUN.

BASIC and DOS set their own different values for the function keys. There are also default values in BASIC that you can override. To do this for the Fl key, enter:

KEY 1, "TRANSMIT MODE

Now press the Fl key. TRANSMIT MODE is displayed just with a single key stroke. Note that the cursor is in the next character position. This is because you usually will add something or hit ENTER after a function key.

Now try:

KEY 1, "TRANSMIT MESSAGE

When Fl is hit, you don't get an E at the end, because you ex­ceeded the maximum 15 characters that are allowed.

To restore F to the previous value, enter:

KEY 1, "LIST

Verify by pressing Fl and the ENTER key.

Entering a New Program

With the cursor under the OK prompt character, enter:

NEW

Now enter:

LIST

Nothing is listed. Your program is gone. NEW tells BASIC to prepare for a new program. BASIC, accordingly, destroys any pro-

Page 110: The IBM Personal Computer Made Easy

9& THE IBM PERSONAL COMPUTER MADE EASY

gram entered previously. Therefore, don't enter NEW unless you have saved your program, or you don't want it. You will learn how to save programs and files in a later section.

Coding and Testing

You have learned that programs are made up of statements that are strung together. Each statement performs one small task. In most cases, many statements are required to produce a useful program. The process of writing statements and putting them in the correct order is called coding.

When coding is complete, a program is tested. This usually requires the entry of test values, so the program can simulate an actual run. Programs seldom run correctly the first time. The more experienced a programmer is, the less he or she expects a new program to be error-free. The process of correcting a program-finding the bugs­is called debugging. Testing and debugging is easier in BASIC than in most languages because you can use your PC as an electronic scratchpad.

Page 111: The IBM Personal Computer Made Easy

Chapter 7

Working With Disks

Disks provide computers with millions of bits of storage that can be accessed in a fraction of a second. They have become more or less standard equipment on personal computers. In this chapter we will describe what is stored on disks and how to use them.

WHAT'S ON A DISK?

Disks store programs, data and directories. The programs may be those you write or buy in order to perform some useful function for you, in which case they are called application programs. Or they may be programs used by the computer to run other programs, in which case they are called system programs.

The data stored on disk is used by the programs as input data, which the program may change and write back on the disk as new data or as an update of previously stored data. Data may consist of large business files, large text files for word processing, or just a few parameters for performing a computation. Often data is stored in the form of tables, as is the case of spreadsheets.

One table stored on disks is of particular interest. This is the di­rectory, which the computer uses to find all the other items stored on the same disk. How this works is described below.

Files

Data stored on a disk is grouped into files. Each program is stored as a separate file. Input and output data is also stored as files. A program will use one, or more, files for input and output data. Tables, too, are stored as files. Files can vary in size and the way in which their information is coded. 97

Page 112: The IBM Personal Computer Made Easy

98 THE IBM PERSONAL COMPUTER MADE EASY

Every file must have a name. When a file is first stored on disk, you assign a name, entering that name on the keyboard. The computer then reads the directory, looking for empty space on the disk. When the file is stored on disk, the name you assigned is entered by the computer into the directory, together with the storage location on disk. Now the file can be found when next you call for it. We won't go into the specifics of disk-addressing, except to say that the disk is organized into tracks and sectors. The combination of track and sector specifies a starting address for a file. If the file is long, it may require more than one sector or track for storage.

File Names

There are rules for naming files which must be carefully followed. The full set of rules, given in the IBM manuals, is rather complex. For most purposes it is sufficient to use only the following simple naming conventions:

• A file name must not be greater than eight characters • No spaces are allowed • Use only the characters A-Z and 1-9 • Both upper and lower case are acceptable

Generally you try to make the name as descriptive of the file's contents as the eight character limitation will allow.

Examples

Name I

INVENTRY TABLE1 1table Incorrect Names INVENTORY TABLE 1

Comments Not descriptive, but short. Useful while de­veloping a program. Later it can be renamed. Descriptive Numbers are useful qualifiers. Leading numbers and lower case is OK.

Comments More than eight characters. Space not allowed.

File Name Extensions

A file name extension is an addition to a file name, used for qual­ifying the file as to type or other category. Before explaining this

Page 113: The IBM Personal Computer Made Easy

Working With Disks 99

further, here are simplified rules for extensions. (See the IBM man­uals for the full set of rules.)

• An extension can have from one to three characters. • Permissible characters are the same as for file names. • Extensions are separated from names by a period (.). • No spaces are allowed anywhere in the combination offile name

and its extension. • The use of extensions is optional when naming a file. • If a file does have an extension, specify this extension when

using DOS.

Examples

Name 8. Extension 1.1 INVENTRY.BAS

CHKDSK.COM

INVNTRY.RUG

Incorrect Name 8. Extension ORDER. HAT HAT

ORDER.HATS

Comments Acceptable, but not very meaningful. Extension BAS is used for BASIC program files. Extension COM is used for DOS and files called by DOS. Extension RUG might be used to desig­nate a subclass of inventory.

Comments Space not allowed. No file name. More than three character extension.

For the purpose of this book, you will have little need to use extensions. This is because BASIC automatically adds the extension BAS to new programs that you save on disk, and does not require the extension if you later retrieve the file. In other cases, the use of extensions is optional, except where noted.

Filespec

When there is more than one drive, the drive as well as the file name and extension may be required. The disk drive is designated by the letters A for one drive, A and B for two drives. The combination of drive, filename and extension is called by IBM a filespec (file specification). With D representing a drive, the format of the filespec is: D :filename. extension

Page 114: The IBM Personal Computer Made Easy

100 THE IBM PERSONAL COMPUTER MADE EASY

For example:

A:INVENTRY.BAS B:BASIC.COM

As with the extension, the use of the device (D:) is optional. If it is omitted, the computer will use the default drive. How the default drive is determined will be described later.

HOW DISKS ARE USED

Programs and data are stored on disk. In order to use this data, the PC must move one or more files into memory. This operation is called reading or loading from disk. The IBM PC uses the command LOAD to perform disk to memory transfer. If this command is fol­lowed by the filespec, the PC will know what file to transfer.

Examples

Command LOAD "B:INVENTRY.BAS· LOAD "INVENTRY.BAS·

LOAD "INVENTRY·

Comments Complete filespec Drive not specified. Default used. No extension specified.

When the file is in memory, a program can go to work on it if it is data, or if it is a program it can be changed or run.

Periodically, during processing it is usual to save what has been accomplished on disk. The operation of transferring from memory to disk is called writing or saving to disk. The IBM PC uses a command called SAVE to accomplish this task. Again, a filespec is required to tell the PC where to store the file.

Examples

SAVE:" A: I NVNTRY. BAS· SAVE "INVNTRY.BAS· SAVE "INVNTRY·

Aside from the LOAD and SAVE commands (and some special cases), the disk is isolated from memory. This means that files on disk are relatively safe from computer errors, user errors and power fail-

Page 115: The IBM Personal Computer Made Easy

Working With Disks 101

ures. It also means that everything stored on disk is inaccessible to the PC unless it has been transferred to memory by LOAD. You can not run a program or process data while it resides on disk. First it must be LOADed into memory.

DOS

Disks require numerous and complex operations for their use. Fortunately we users don't have to be concerned with all this com­plexity-it is performed for us by something called a disk operating system, or DOS for short.

DOS is a number of programs that are stored on disk in files just like any other programs. Some of these programs are involved directly in data transfer between disks and memory. These are hidden files that you never see, even if you display the directory, as you will learn to do. Other DOS files, such as COMMAND. COM, allow users to work with DOS. And others, such as DISKCOPY. COM and CHKDSK.COM are utilities for copying disks or checking the disk for available space.

Since DOS is stored on disk, its files must be loaded into memory prior to use. Some of its files are loaded automatically by the PC, the only files so loaded. This is called booting DOS. Mter DOS is booted, other files can be loaded.

When you purchase DOS, you receive a disk labeled DOS, which contains all the DOS programs, plus Disk BASIC, plus Advanced BASIC. Needless to say, this is a valuable disk that you don't want damaged or worn out. The original DOS disk should be copied onto a ~ew disk and labeled "Working DOS Disk." The original is kept in a safe place, and used only to make more copies.

Have your dealer make a copy of the DOS disk, or you can do it yourself, following the procedure given later.

RULES FOR WORKING WITH DISKS

For the most part, you have to work hard to damage the compo­nents of the IBM PC. This is not so with disks. Here, reasonable care is required. However, follow these rules, and you should have no problems:

Page 116: The IBM Personal Computer Made Easy

102 THE IBM PERSONAL COMPUTER MADE EASY

o Never lift or close the flap on a disk drive when the red light is on.

o Never insert or remove a disk when the red light is on. o Never insert a disk in a drive right after turning the computer

on. Insert it first or wait for the completion of the diagnostic cycle.

o Avoid turning on a printer when a disk drive is operating (red light on) or is about to operate.

Write-Protecting Disks

Disks should be write-protected when:

o They have critically important data recorded on them o They are being copied o They are used to provide DOS programs for formatting another

disk (Formatting destroys any files that may be on a disk.)

In all these cases, inadvertant errors can cause the loss of valuable data.

Write-protection is easy. Adhesive tabs are usually supplied with disks or can be supplied by a dealer that are suitable for using to cover the notch in the side of the diskette cover. The tabs can be peeled off when they are no longer needed.

HOW TO START DOS

With the PC turned off, insert a DOS disk in the disk drive slot. H you have a copy of the original DOS disk, of course, you use that. If not, use the original and immediately make a copy, as described below.

Turn on the PC and you will hear the same sounds as previously, when starting without disks. However, now instead of the familiar BASIC prompt, you will see a new message, asking for the date. You can Enter the date or just hit the ENTER key. DOS now asks for the time. Again, enter it or skip it with the ENTER key. Now DOS displays its own prompt message:

A>

The above procedure is not the only way to get or boot DOS. Here is a summary of three methods:

Page 117: The IBM Personal Computer Made Easy

Working With Disks 103

• If the computer is off, insert the copy of the DOS master in drive A, and turn on the computer. You will be asked for the date and time. Enter these, or just hit ENTER twice, and get the DOS prompt: "A>".

• If the computer is on, insert the copy of the DOS master in disk drive A. Press Ctrl-Alt-Del, and proceed as above.

• If you are in BASIC, En~er SYSTEM. You will immediately get the prompt character "A>". You can not boot DOS this way, it must already be in memory.

The DOS Prompt Message

The DOS prompt message is: "A>" displayed on the left-hand columns. Whenever you see the ">" prompt character, you can be sure you are in DOS. The A tells you which drive DOS is using as a default drive. DOS uses the default drive unless you explicitly specify another drive. You can change the default drive with a com­mand to DOS. Depending on how many drives are attached to your system, you could select drives A or B as the default drive, in which case you would see prompt messages like this: A>, B>.

The prompt message is followed by a flashing cursor, inviting you to enter a command.

How to Specify a Drive

If you want DOS to work with files on drive B when the prompt character shows A, before the file name you must enter:

B:

Examples

B:INVNTRY A:I B:PAYROLL.BAS

Selects drive B, File Invntry Selects drive A, File I Selects drive B, File Payroll. Bas

How to Change the Default Drive

To change the default from drive A to B, enter B colon after the prompt character:

A>B:

Page 118: The IBM Personal Computer Made Easy

104 THE IBM PERSONAL COMPUTER MADE EASY

For the DOS prompt, you will then get:

B>

Switch back with A:

NOTE: that default always applies to the drive and not to the diskette in the drive.

Note, too, that whenever you don't enter a drive letter before a file name, DOS goes to the default drive for the file name specified. If this is the incorrect drive, you will receive afile not found message.

COPYING A DISK

You copy a complete disk when all or most files on that disk are important. The source disk is saved for backup, and the new disk becomes a working disk. A good example is the DOS disk which was described previously.

Insert a DOS disk in drive A, the left drive, and start DOS as described above. When your PC displays the DOS prompt, A>, you can start the copy procedure.

(A) Using Two Disk Drives Enter,

DISKCOPY A: B:

Press the ENTER key and follow the instructions DOS displays on the screen.

a. If your source disk is the DOS disk, leave it in drive A and insert the working DOS disk, the target of the copy, in drive B. Press a key and you're on your way. DOS formats and copies the disk at the same time. You do not need to format the target disk beforehand.

b. If your source disk is not the DOS disk, remove the DOS disk (the copy program is now in memory) and replace it with the disk you want to use for the copy. Otherwise, the procedure is the same as for (a).

(B) Using One Disk Drive Enter,

DISKCOPY

Page 119: The IBM Personal Computer Made Easy

Working With Disks 105

Press the ENTER key. DOS displays:

Insert source diskette in drive A

Now you either leave the DOS disk in the drive, or you replace it with any other disk you want to copy. Then press a key. DOS displays:

Insert target diskette in drive A

Replace the source disk with the target disk and hit any key. This process is repeated four or more times, until the copy is completed.

I think you can see from this the wisdom in write-protecting your source disk when copying disks. It is all too easy to mix up source and target disks.

HOW TO USE BASIC WITH DOS

If you have DOS, you also have the BASIC extensions Disk BASIC and Advanced BASIC. These increase the capabilities of Cassette BASIC, which we have been using up until now. If you have at least 48K of memory, you can used Advanced BASIC. Otherwise, you must use Disk BASIC. Advanced BASIC is more powerful, but also larger, reducing your available memory.

Both these BASICs are stored on the DOS disk with filenames,

BASIC.COM BASICA.COM

for Disk and Advanced BASIC, respectively. Therefore, to run either BASIC, you must first insert a DOS disk, boot DOS and get the DOS prompt" A>. Then enter either

BASIC or

BASICA

When you hit the ENTER key, the BASIC OK prompt will be displayed. All three BASICs use the same prompt. You will see no differences, unless you enter an invalid statement for the BASIC you are using, in which case an error message is displayed.

To return to DOS from BASIC or BASICA, enter,

SYSTEM

Page 120: The IBM Personal Computer Made Easy

106 THE IBM PERSONAL COMPUTER MADE EASY

FORMATTING A DISK WITH FORMAT

All new disks must be formatted. Formatting creates sectors on the disk, so that DOS knows where to locate data. Formatting also creates a directory for file-related data, and it eliminates from use sectors with defects.

There are two ways to format a disk. One is to copy an already­formatted disk with the command DISKCOPY. This command was described above in more detail. The second method uses the FOR­MAT command described in this section.

The FORMAT command varies, depending on whether you want to have DOS files on the new disk and on whether you want to format one or two sides. Although DOS uses valuable disk space, DOS is convenient to have on a disk when you are writing programs. Disks formatted on two sides will not work in single-side drive systems. Those formatted for one side will work in both types of drives. The steps required for formatting are listed in Quick Reference Chart 7-2.

COpy

Backup and copy can be performed on selected files. Some disks are designed to make copying impossible. In other cases, it is illegal to make copies. This has come about because the copying of programs has become extensive, and has cut into the sales of legitimate pro­ducers. Check with your software source on these matters.

If you had just written a new program, you would want to back up that program without having to copy a complete disk. Then you could selectively write to a partially full disk without destroying existing files. With the help of Quick Reference Chart 7-3 and the directions given by the computer on the display screen, there should be no problem, especially when you are using two drives.

When using one drive, you must switch disks several times, de­pending on the amount of material that is copied. You will be in­structed by the computer on the display screen. There is one case, however, when these instructions are not clear and that is when you are using the COpy command with a single drive. Then the computer asks you to "Insert diskette in drive B; and strike any key when ready" even though there is no drive B. What the computer means is: Re-

Page 121: The IBM Personal Computer Made Easy

Working With Disks 107

move the original diskette and insert the backup, then strike any key. It will then ask for the diskette for drive A, which means, of course, the original. This will probably be corrected in later versions.

Note that when you copy a file, you must include the file extension to the name. For example, to copy a BASIC file called MENU, enter:

COPY MENU.BAS B:

If you don't know the extension, look in the directory, using the command DIR in DOS or FILES in BASIC.

FINDING FILES ON A DISK

The DOS Way Using DlR

Insert the DOS Master backup disk into one of the drives, say, B. In DOS, enter:

A>DIR B:

DOS will display a list of the directory showing all the files. If the disk is in a default drive, then B: can be omitted.

For example, entering the following will give you the same results as above:

B>DIR

This is true for all DOS-related commands such as LOAD, SAVE, and so on. The rules are:

1. The prompt message tells you whether A or B is the default drive.

2. If a command applies to the default drive, no drive has to be specified in the command.

If the directory listing runs past the top of the screen, you can stop scrolling by pressing the Ctrl-NumLock keys at the same time. To continue the listing, press any character key.

Page 122: The IBM Personal Computer Made Easy

108 THE IBM PERSONAL COMPUTER MADE EASY

The BASIC Way With FILES

Get into BASIC with:

A>BASIC or A>BASICA

Enter:

FILES

For the default drive, the directory is again listed, but in a different format. For a nondefault drive, say, B, enter:

FILES "B:*.*"

The comments about drive and scrolling given for the DIR com­mand also apply to FILES.

SAVING, LOADING, AND DELETING FILES

In BASIC, enter:

10 PRINT "LEARNING DOS" 20 PRINT 5*5

Now key in SAVE"TEST, and hit the ENTER key. The program is saved on disk with the name TEST. Is it in the directory?

Enter NEW to destroy the program in memory. Use LIST to check this. Now key in LOAD"TESTand hit ENTER. The program is loaded into memory from disk. Is it there? Enter RUN to find out.

Repeat the above with the following changes:

o Use the F4 key to generate the SAVE" command. o Use TEST2 for the file name (no space before the 2) o Use F3 key to generate the LOAD" command. o Use Fl to LIST the program. o Use F2 to RUN the program.

You have now learned how to save a program on disk and how to load it back into memory. The same steps can be used for any program.

Page 123: The IBM Personal Computer Made Easy

Working With Disks 109

You will not want to leave useless programs on disk, so delete what you do not want by typing:

KILL "TEST"

OOPS! Error message. BASIC can't find this. If you check the directory with FILES, you will see that BASIC has added the exten­sion BAS. You must enter,

KILL "TEST. BAS"

Check the result with FILES. Test2 should still be there, so to get into DOS, enter:

SYSTEM DEL TEST2.BAS

Goodbye TEST2, you served your purpose. Remember the following:

In BASIC, use: KILL "name.ext" In DOS, use: DEL name.ext

SPECIFYING A TAPE CASSETTE

A tape-cassette player is specified in a manner similar to a disk drive but with a different designation. To specify a cassette, instead of A: or B:, use CASl: Thus,

LOAD "CAS1 :MAIL3" or

SAVE "CAS1 :MAIL3

will transfer the file, MAIL3, between memory and tape. However, in cassette BASIC, CAS! is the default device and may be omitted.

Page 124: The IBM Personal Computer Made Easy

QUICK REFERENCE CHART 7-1

EXTERNAL SYSTEM PROGRAMS ON THE DOS MASTER

Name Booted? Function

IBMBIO.COM Yes Operating system basic input/output programs. This is a hidden file, which does not appear in the directory list-ing and cannot be deleted.

IBMDOS.COM Yes Operating system programs. This is a hidden file, which does not appear in directory listing and cannot be de-leted.

COMMAND.COM Yes Processes DOS commands and per-forms DOS functions.

FORMAT.COM No Formats a disk. CHKDSK.COM No Checks integrity of files and issues a

report on: Total disk space Bytes in hidden files Bytes in user files Bytes in bad sectors Bytes available on the disk Total bytes in memory Bytes available in memory

SYS.COM No Transfers DOS files, IBMBIO, and IBMDOS from a source disk to a disk formatted with the system option. Use this when you buy a program that requires the addition of DOS to run.

DISKCOPY. COM No Copies a complete disk. DISKCOMP.COM No Compares two complete disks. COMP.COM No Compares two files. MODE. COM No Sets mode. Use this to adjust display

position on screen with MODE ,R,T or MODE ,L, and T.

EDLlN.COM No Line editor DEBUG.COM No Debugger for assembly language. BASIC.COM No Disk BASIC. BASICA.COM No Advanced BASIC.

110

Page 125: The IBM Personal Computer Made Easy

QUICK REFERENCE CHART 7-2

STEPS IN FORMATTING A DISK

One-Disk Drive Two-Disk Drives 1. Select a disk with DOS

on it? Yes Yes 2. Temporarily write-pro-

tect the DOS disk with adhesive tab? Yes Yes

3. Insert DOS disk in drive A? Yes Yes

4. Insert target disk in drive B? N/A Yes

5. FORMAT will destroy any files on the target disk? Yes Yes

6. Enter FORMAT com-mand (a) format with DOS and single side FORMAT A:/S/l FORMAT B:/S/l (b) format without DOS, single side FORMAT A:/l FORMAT B:/l (c) format with DOS, double-sided FORMAT A:/S FORMAT B:/S (d) format without DOS, doubled-sided FORMAT A: FORMAT B:

7. Should you follow com-puter instructions dis-played on screen? Yes Yes

8. DOS diskette must be removed? Yes No

9. Label disk using felt-tipped marker? Yes Yes

111

Page 126: The IBM Personal Computer Made Easy

QUICK REFERENCE CHART 7-3

SUMMARY OF BACKUP AND COPY OPERATIONS

Complete Disk Selected Files l. DOS must be loaded

before starting? Yes Yes 2. A>prompt

required? Yes Yes 3. Command used for

single drive. DISKCOPY COPY filename B: 4. Command used for

two drives(source A, target B). DISKCOPY A: B: COPY filename B:

5. File name must in-clude extension? N/A Yes

6. Write protect origi-nal with removable tab? Yes Yes

7. Formatted disk re-quired? No Yes

8. Single side to dou-ble side? No Yes

9. Destroys previously written files? Yes No

10. File name required? No Yes 11. Global file names

apply? No Yes 12. Copy all DOS and

BASIC? Yes, if on original Yes with file name *.COM

13. Screen displays in-structions on how to proceed? Yes Yes, but confusing; see

text 14. When used? l. For backup of For single file backup,

newly pur- whenever data is added chased disks or changed

2. When disk ap-proaches end of life

112

Page 127: The IBM Personal Computer Made Easy

Part 3

Learning IheBASIC PrOgramming Language

Page 128: The IBM Personal Computer Made Easy

Chapter 8

BASIC-Session I

Although you have learned only a few things that BASIC can do, you are now in a position to progress much faster. When you have completed the next three chapters, you will know how to program in BASIC, and you will· be able to move on to some of the more interesting features of the IBM Personal Computer.

If you do not have a disk drive, you can still do most of what follows, so just follow along, bypassing the reference to the disk and using cassette BASIC just as you have been doing.

BASIC AND BASICA

Up until now, you have been using cassette BASIC. It is time to become familiar with the other BASICs available in the PC. For this, you will need a copy of the DOS Master disk that came with your system. Do not use the original disk. Follow the instructions in Chap­ter 7 for making copies. If you don't feel confident enough to do this yet, ask a dealer or a friend to make a copy for you.

From now on, when reference is made to the DOS Master, this means the copy. Put the original in a safe place.

Insert the DOS Master in the left-disk-drive unit. Close the flap over the entrance slot and turn on the PC. DOS will be loaded from the disk into memory, and the DOS date and time prompts will be displayed. Enter a new date and time, or just hit ENTER twice.

The DOS prompt

A>

will appear. If you have less than 48K of memory, enter:

BASIC 115

Page 129: The IBM Personal Computer Made Easy

116 THE IBM PERSONAL COMPUTER MADE EASY

This entry calls Disk BASIC. If you have 48K or over, enter:

BASICA

This entry calls Advanced BASIC. Except in a few cases, all that follows will apply to all three versions of BASIC. All three BASICs will give the "OK" prompt.

AUTOMATIC LINE NUMBERING

Press Caps Lock key. Enter:

NEW

Get:

OK

Enter:

AUTO

Get:

10

Enter, on line 10:

10 PRINT "LINE 10

When you hit ENTER, you will see:

10 PRINT "LINE 10 20

You are in AUTO Mode, which gives you automatic line number­ing. The line numbers start with 10 and increase by 10 each time you hit ENTER. Try it.

When you are in AUTO Mode, you are out of Command mode. You cannot give commands. You can not edit lines previously entered and you cannot RUN a program.

Page 130: The IBM Personal Computer Made Easy

BASIC-Session I 117

NOTE: that to leave AUTO mode, you must press Ctrl and Break at the same time.

Press Ctrl-Break. To start numbering at 100 and incrementing by 50 enter:

NEW AUTO 100,50 100 PRINT 100

Hit the ENTER key several times to verify the result. A useful variation is this. Press Ctrl and Break to leave AUTO mode. Enter:

AUTO .,10

Hit ENTER several times. The new numbers started with the previous last line. The period makes the first line of AUTO the current line. When AUTO prints line numbers you have already used, it warns you by printing an asterisk sign (*). If you do not want to change that line, just hit ENTER.

VARIABLES

Values of inventory, profit, and sales rarely remain constant. To work with these and other units, you must have ways of representing items that have more than one value. BASIC does this with variables.

In BASIC, there are two types of variables: numeric variables and string variables. The latter are used for alphabetic items. String var­iables can also include numerals if they are not used in calculations.

Numeric Variables

Enter NEW and:

AUTO 10 1=1 20 PRINT I 30 1=1 +1 40 PRINT I 50 PRINT 1+1 60 Ctrl-Break

Page 131: The IBM Personal Computer Made Easy

118 THE IBM PERSONAL COMPUTER MADE EASY

RUN this program and you will get:

1 2 3 OK

In this program, I is a numeric variable. It is the name of the variable. The letter I was chosen arbitrarily; it could as easily have been J, K, L, or even a word, such as NUMBER.

In line 10, the value of 1 was assigned to I. This is the LET statement, and its full representation is: LET I = X, where X is a number or algebraic expression. In this version of BASIC, the word LET is optional. I will follow the common practice of dropping it.

Line 30 assigns a new value to I. The new value is the old value, plus one.

Line 50 gets the same result as lines 30 and 40 by entering 1+1 directly in the PRINT statement. Algebraic expressions are allowed in the PRINT statement, and can save program lines. However, note that line 30 changes the value of I while line 50 doesn't.

Enter NEW, AUTO, and then type:

10 PRINT I 20 1=2"1 + 1 30 J = I +SQR(I) 40 PRINT J - 12 50 Gtrl-Brk

RUN the program and get:

o - 8.5857863

Line 10 says to print I before a value has been assigned to it. Since all numeric variables are initially given the value of zero, BASIC correctly printed 0. The preceding lines were examples of using var­iables and arithmetic expressions. Practice the use of these by making up your own programs. See how good BASIC is at evaluating com­plicated expressions.

Enter NEW, AUTO, and then type:

Page 132: The IBM Personal Computer Made Easy

10 INVENTORY = 10000 20 ORDER = 250 30 INVENTORY = INVENTORY - ORDER 40 PRINT INVENTORY 50 Ctrl-Brk

BASIC-Session I 119

When you RUN this program, BASIC will print the new inventory. Here, names that have been used for variables describe the variable item, an obviously useful device.

Rules for Numeric Variable Names

Enter:

PRINT EXP (back to Direct mode)

BASIC returns:

SYNTAX ERROR

Try:

PRINT EX

BASIC returns the expected value for an unassigned variable: 0. Why does BASIC object to EXP but accept EX? Because in BASIC,

EXP is a reserved word. A reserved word is a word BASIC reserves for special meaning. If you use it in the wrong way, you get a syntax or other error message.

A list of reserved words is given in Appendix 3. Now try:

PRINT 1EX

BASIC returns:

1 0

BASIC thought you meant:

PRINT 1 EX

Page 133: The IBM Personal Computer Made Easy

120 THE IBM PERSONAL COMPUTER MADE EASY

Clearly, there are certain restrictions on numeric variable names. Quick Reference Chart 8-1 gives a list of simplified rules that will keep you out of trouble.

There are ways of declaring to BASIC the amount of precision you want in a numeric variable. This will be described in a later section.

String Variables

Enter NEW, AUTO, then type:

10 A$ = "A$ IS A STRING VARIABLE" 20 INVENTORY$ = "SO IS INVENTORY$" 30 PRINT A$ 40 PRINT INVENTORY$ 50 Ctrl-Break

String variable names end with a dollar sign. The string itself can have up to 255 characters. BASIC does not care if you space after the equal sign or omit the quote at the end of the string as long as nothing else follows, but in writing programs, you risk fewer errors by including it.

Enter without AUTO,

50 B$ = "2" 60C$=2 70 D = "2" 80 PRINT B$ C$ D

When RUN, BASIC returns:

TYPE MISMATCH

We specified a string variable, but gave BASIC a numeric constant. BASIC will not accept this. Enter:

EDIT 60

Use your proficiency with the edit keys to insert quotes. Then enter:

RUN.

Page 134: The IBM Personal Computer Made Easy

BASI~asslon I 121

Another mismatch. This time you tried to make BASIC put a string in a numeric variable (D). Correct line 70 and RUN. Is line 80 correct? Notice that PRINT on line 80 prints the strings without spaces be­tween them. Try it with commas and semicolons between the strings in 80.

String variables allow manipulation of long strings by assigning them short names.

Type NEW and enter:

10 A$="

Now hold down the A key until you get a couple of lines or so of As. Hit ENTER and continue:

20 PRINT A$

RUN it. String variable names have the same rules as numeric variable

names, except that they must end in a dollar sign. Numeric variables can only have numeric entries, but string var­

iables can have alphabetic and 0-9 numeric entries. Then why not use only strings? Because numeric entries are stored in the computer so they can be used in mathematical calculations, and strings cannot be used this way. Whenever you want to do arithmetic operations, then, you must use numeric variables (see Quick Reference Chart 8-1).

SUBSTRINGS

The following type of situation occurs frequently. We are presented a string variable in the following form:

BIRTH.DATE$= "02/05/70"

The computer needs the year to perform some calculations and comparisons, but the year is a substring, embedded in the string variable BIRTH. DATE$.

Page 135: The IBM Personal Computer Made Easy

122 THE IBM PERSONAL COMPUTER MADE EASY

LEFT$, MID$, and RIGHT$

BASIC provides three statements to use in extracting substrings. In this example, you would use the RIGHT$ function.

Enter NEW, AUTO, and then type:

10 BIRTH.OATE$= "02/05/70" 20 R$ = RIGHT$(BIRTH.OATE$,2) 30 PRINT R$ 40 Ctrl-Brk

Line 20 tells BASIC to retrieve the two characters on the far right from the string BIRTH. DATE $ and assign that value to R$. You now have the year 70 in R$, but it is a string variable, and you cannot do calculations with strings. BASIC comes to the rescue with ways to convert strings to numbers that will be explained in the next section. Here is another example:

NEW AUTO 10 BO$ = "08/30/82 20 Y$ = RIGHT$(BO$,2) 30 M$ = LEFT$(BO$,2) 40 0$ = MID$(BO$,4,2) 50 PRINT M$"/"O$"/"Y$ 60 Ctrl-Brk

In line 10, BD is less clear than BIRTH. DATE, but it serves the purpose with less typing. Line 30 gets the two left characters from BD$. Line 40 gets the middle characters (two characters starting with the fourth character). The first character of the day is the fourth character from the left, and it is two characters long, hence:

MIO$(BO$,4,2)

Other frequently used strings and their substrings are:

String

Full name Full address Full account number Telephone number Quantity and units

Substring

Last name ZIP code, street number Sub account Area code Quantity alone

Page 136: The IBM Personal Computer Made Easy

BASIC-Session I 123

Make up examples of these strings, and then practice the fine art of pulling off substrings.

CHANGING STRINGS TO NUMBERS

In the previous section, you started out with a date and wanted to extract the year, in order to perform calculations. The year was Y$, but since you cannot perform calculations on a string, you must enter NEW and then type:

10 Y$ = "80· 20 PRINT "AGE = "83-Y$

RUN it and get:

TYPE MISMATCH IN 20

Therefore enter:

15 Y = VAL (Y$)

And delete the $ in line 20. Now the program will run. VAL returned the value of Y$ to Y.

Use VAL(X$) to change strings to numbers. Practice on the ex­amples in the previous section.

CHANGING NUMBERS TO STRINGS

STR$ performs the inverse function of VAL(Y$). Enter NEW and:

10 Y = 80 20 Y$ = STR$(Y) 30 PRINT y$

RUN it, and then LIST and change to:

10 Y = 80 20 Y = VAL(STR$(Y)) 30 PRINT Y

Page 137: The IBM Personal Computer Made Easy

124 THE IBM PERSONAL COMPUTER MADE EASY

KEYBOARD SHORTCUTS

In addition to the function keys, BASIC has other tricks for re­ducing keystrokes. For example, enter CLS and then press:

Alt-P (First the Alternate key and then P) Alt-A Alt-R

Hold down Alt and experiment with other letters. Most enter fre­quently used words, but not all. A list of the words and the key that generates the word is given in Appendix 4.

HOW TO FORMAT NUMBERS

There are a number of ways that numbers are formatted for re­porting purposes-dollar signs, zero suppression, and decimal points, to name but a few. In BASIC, formatting is done with an extension of the PRINT statement.

The PRINT USING Statement Enter:

PRINT USING "###.##"; 12.1

The three number signs (#) in front of the decimal suppress leading zeros. The number signs following the decimal point suppress trailing zeros.

Note the quotes around the number signs. This is a string that defines the format of the printed number. It may be thought of as a template. The general form of the statement is (see Quick Reference Chart 8-2):

PRINT USING "String template"; Number(S)

Several numbers can follow the string template, as long as they are separated by commas.

Enter:

PRINT USING "$$##.##"; 21.23, 2.569, 057.00, 557.00

Page 138: The IBM Personal Computer Made Easy

BASIC--Session I 125

Two dollar signs are required to format one dollar sign in the printout. Notice that 2.569 is rounded to 2.57 (only two decimal points were called for (.##). 557 pushes to the left, because it overflows the formatted space (##) to the left of the decimal.

Enter:

PRINT USING "$$#######,.##-"; -1995632.85, 1,555,670.00

In the first number, commas will be inserted every three digits to the left of the decimal along with a trailing minus sign, which is common in financial reports. The second number will be broken into three numbers on the printout, because BASIC thinks commas in this context always mean number separators. Therefore, you should never enter commas in a BASIC number. The minus sign is correctly missing from the positive numbers.

Change the trailing minus sign in the above format to a plus sign (+) and see what happens.

Change the plus sign (+ ) from trailing to leading (in front of $$). (The leading sign in the format template is not valid.)

Finally, put an extra digit in front of the 1 in the first number. When this is PRINTed, a percent sign (%) will appear on the left, signifying overflow of the format template.

Other, less frequently used format characters are available. See the IBM BASIC manual for a complete list.

The string template can include a literal. Enter:

PRINT USING "AMOUNT OWED: ####,.##";456.91

INTEGERS, SINGLE-PRECISION, AND DOUBLE-PRECISION NUMBERS

In BASIC, there are three types of numbers: integers, single pre­cision, and double precision.

Integers are whole numbers, that is, numbers that do not require decimal points. Of all the kinds of numbers, they require the least storage and processing time. Examples are page numbers and irtven­tory counts of discrete items.

Single-precision numbers are used to specify numbers that have

Page 139: The IBM Personal Computer Made Easy

126 THE IBM PERSONAL COMPUTER MADE EASY

both integer and decimal values. They require more storage than integers. With a few exceptions, all the numeric variables used in this book will be single-precision numbers.

Double-precision numbers have more storage requirements than single-precision numbers. Double-precision numbers are used mostly in scientific and technical applications, and they will not be discussed further.

You can tell BASIC the type of number you want to use by adding a symbol to the variable name. If no symbol is added, BASIC will assume that a single-precision is called for. Quick Reference Chart 8-3 details these points. As shown in the chart, constants can be defined either by a symbol or by the number of digits; variables, by a symbol or, optionally for a single-precision number, by no symbol at all.

For simplicity while learning, no special symbols will be used. Variables without a trailing symbol default to single-precision num­bers. Constants do not need symbols.

Page 140: The IBM Personal Computer Made Easy

QUICK REFERENCE CHART 8-1

SIMPLIFIED RULES FOR VARIABLE NAMES • Do not use more than 40 characters. • Do not start a name with a number. • Do not use a reserved word. If a numeric is entered as the last character,

you will never produce a reserved word. It is helpful in long programs to use the numbers to identify variables by groups or types, starting with 1 and counting up. Reserved words can also be avoided by using a single letter for a name.

• String names must end in a dollar sign. This will not avoid the reserved­word problem. In this case, enter a number in the next-to-Iast position.

• Use only the characters A-Z, ~9, and decimal point with the first charcter A-Z.

• Do not start a variable name with the characters FN, which has special meaning to BASIC.

QUICK REFERENCE CHART 8-2

PRINT USING STATEMENTS Format: PRINT USING "String Template"; Number, Number,

Symbol #

$$ +

, (comma in front of decimal point)

(decimal point)

%

Function Specify digit position.

Specify dollar sign ($). Causes plus (+) or mi­nus sign (-) to be printed. Causes minus sign to be printed at the end of the number. Causes commas to print every three positions left of the decimal.

Prints decimal point.

Signifies overflow of po­sition to left of decimal.

Comments Overflow on left of decimal causes percent sign (%) to print. Overflow on right of decimal is rounded. Add two digit positions. The plus sign can be at the beginning or the end of the format template. The minus sign can be only at the end of the format tem­plate. Adds one character posi­tion.

If no decimal places in ac­tual number, zeros are en­tered. Entered by BASIC on over­flow. 127

Page 141: The IBM Personal Computer Made Easy

QUICK REFERENCE CHART 8-3

CONSTANT AND VARIABLE TYPES

A. CONSTANTS Defined by Defined by number

Type a symbol of digits Comments

Integer None - 32768 to + 32768 No decimal points

Single Trailing"!" Seven or less digits Examples: 42. 391056! precision 42.391

Double Trailing"#" Eight or more digits Examples: 42.391# precision 42.391056

B. VARIABLES Bytes of

Type Symbol Storage Examples

Integer % 2 PAGE% Single ! or no 4 AMOUNT! or AMOUNT precision symbol Double # 8 ATOMS# precision

128

Page 142: The IBM Personal Computer Made Easy

Chapter 9

BASIC-Session II The two keys to computer power are looping and branching.

Looping and branching allow computers to perform complex feats of processing. Without looping and branching, computers would be little more than automatic calculators. You will now learn how to instruct a computer in these operations, using BASIC to do so. Then you will be in a position to put the computer to work and obtain meaningful results.

TAPPING THE COMPUTER'S POWER

looping and Branching the GOTO Way

In previous examples, you wrote a PRINT statement each time you computed a new quantity. Thus you had lines like this:

10 I = 1 20 PRINT I 301=1+1 40 PRINT I

This provided for two values of I. Often though, many more values are needed for one variable, and it would be time-consuming and wasteful of memory to add two lines of program for each new value. By looping back, however, you can repeat previous lines over and over.

Enter NEW,AUTO, and then type:

10 CLS 20 PRINT I; 30 I = 1+1 40 GOTO 20 50 129

Page 143: The IBM Personal Computer Made Easy

130 THE IBM PERSONAL COMPUTER MADE EASY

GOTO 20 tells BASIC to loop back to line 20 and print I. Remem­ber, I, a numeric variable, is initialized to zero by BASIC, so line 20 will start by PRINTing 0. Then Line 30 increments I by 1. Line 40 loops back, so Line 20 now PRINTs 1. But does it go on forever?

Well, eventually, the equipment will wear out. Imagine, all these numbers were produced from just three lines of code. (The CLS merely clears the screen; it is not in the loop.) Now you see what can be accomplished with loops. How do you stop this?

Freeze the screen image with Ctrl-NumLock. Unfreeze it with the ENTER key or space bar. Now use the Ctrl-Break (twice) to return to command mode. There is the OK prompt. BASIC never tires-it's even asking for more.

Obviously, a loop that cannot stop itself is of limited value. There are a number of ways, however, to provide for exiting a loop. They all are a form of what is called conditional branching that is discussed in the next section.

Looping and Branching the IF . .. GOlO Way

Conditional branching allows a program to take different paths, depending on the outcome of a test. A "different path" refers to the execution of a different set of program lines. For example, enter NEW, AUTO, and then type:

10 CLS 20 PRINT I; 30 I = 1+1 40 IF I < 100 GOTO 20 50 PRINT "END" 60 END 70

In lin~ 40, conditional branching has been achieved. The symbol < is called a relational operator and means "less than."

Thus, line 40 says: if I is less than 100 go to line 20, repeating the loop. If I is not less than 100, fall through to the next line, which is 50. Now we are out of the loop and processing proceeds in. the usual order of ascending line numbers.

Run the program. Did it work? Did you remember to enter Ctrl­Break? Notice how the IF ... GOTO statement neatly takes care of looping and branching with just one program line.

Page 144: The IBM Personal Computer Made Easy

BASI~ession II 131

Relational Operators

BASIC provides the following relational operators, all of which can be used in an IF ... GOTO statement.

Operator Expression A=B

< A<B <= A<= B

> A>B >= A >= B <> A <> B

Examples of the IF . .. GOIO Statement

Enter NEW, AUTO, and then type:

10 CLS 20 PRINT I; 30 PRINT· • 40 I = 1+1 50 IF 81 > I GOTO 20 60 PRINT

Meaning A equal to B A less than B A less than or equal to B A greater than B A greater or equal to B A not equal to B

Again, enter NEW, AUTO, and then type:

10 CLS 20 PRINT r2, 30 I = SIN(J) 40 J = J+ I 50 PRINT J, 60 IF I < LOG J + .01 GOTO 90 70 IF J <> 1 GOTO 20 80 END 90 I = 0 100 GOTO 20

The IF ... GOTO statement is the only weapon you need to attack the looping and branching problem. With it, you can handle all pos­sible situations. However, BASIC provides another loop and branch that is easier to use and processes faster. This is done by using a FOR ... NEXT statement.

Page 145: The IBM Personal Computer Made Easy

132 THE IBM PERSONAL COMPUTER MADE EASY

Looping and Branching the FOR . .. NEXT Way

Enter NEW, AUTO, and then type:

10 CLS 20 FOR I = 1 to 499 30 PRINT I 40 NEXT I 50 PRINT "END" 60 END

RUN the program. This is the same output you got from a previous program using the

IF ... GOTO statement. Compare the two programs and notice how the FOR ... NEXT statement improves readability. Line 20 sets I equal to 1 and tests for I > 499. Line 30 is the body of the loop. Line 40 marks the end of the loop and tells BASIC to increment I; it is equivalent to the previous I = 1+1. When I becomes greater than 499, BASIC leaves the loop, going to the line following NEXT I.

LIST the program again, and with edit keys, enter:

Insert two spaces in Line 30 before PRINT I Delete I in Line 40 Delete END in Line 60

Now the program LISTs as:

10 CLS 20 FOR I = 1 TO 499 30 PRINT I 40 NEXT 50 PRINT "END"

Did you hit the ENTER key after each line change? RUN the program. Did you get the same result? This indicates the following:

• Statements can be indented from the line numbers. Indenting the body of a loop makes programs more readable.

• The variable does not have to be present in the NEXT state­ment. BASIC runs faster without them. However, branching out of the loop requires the variable and its presence increases readability.

Page 146: The IBM Personal Computer Made Easy

BASIC-Session II 133

• The END statement is not necessary at the end of a program. Sometimes, it is useful at other program locations when you want a condition to end the program.

Stepping and Nesting FOR . .. NEXT Loops

There are a number of ways the FOR ... NEXT loop can be used. In the following program, you will see some of the more useful op­erations.

Enter:

10 CLS 20 FOR I = 0 TO 499 STEP 5 30 PRINT I; 40 NEXT 50 STOP 60 FOR I = 10 to 20 70 PRINT I; 80 FOR J = 1 to 10 90 PRINT SQR(J)*I 100 NEXT J 110 NEXT I 120 STOP 130 FOR L = 100 TO 1 STEP -5 140 PRINT L 150 NEXT 160 STOP 170 GOTO 10

Lines 30 through 40 will be familiar, but line 20 is new. You now start at 0 and have added STEP 5. This increments I by 5 on each pass through the loop. The program stops at 495 because the next value would be 500, which exceeds the 499 limit.

Key in CONT to continue after a programmed STOP. In lines 60-110, a nested loop is introduced in which a FOR ... NEXT

loop has another FOR ... NEXT loop within it. Lines 60 and 70 of the outer loop are executed in the usual way.

Line 80 sets up an inner loop. This loop will print the square root of J times the current value of I for J ranging from 1 to lO. During these ten cycles of the inner loop, I does not change. The inner loop cycles until J = 11. Then it falls through to line 110, which completes the first cycle of the outer loop. Then go back to lines 60 and 70. Now

Page 147: The IBM Personal Computer Made Easy

134 THE IBM PERSONAL COMPUTER MADE EASY

lines 80 through 100 are looped through ten more times. The whole process repeats until the limit, I greater than 20 is reached.

Nesting can be carried to several levels, although in practice, it rarely goes beyond two or three. The improvement in format due to the indenting ofloops is most important when several loops are nested.

Keep in mind that there must be no crossover; all loops must be fully nested. You cannot end a previous loop before ending the current loop. You can branch out of an inner loop with a GOTO, however, although this is not advisable because it leads to complex program structures.

The last lines in the program illustrate the use of a down counter. The STEP value is set to - 5 so that the variable I is decremented, or reduced, on each pass. The count stops at 5, since the next value of the counter, L, would be 0, which is below the limit of 1.

Experiment with this program on your own. Learn what happens when the initial value of the variables is made greater or lesser than the final value. A word of warning, though, as you experiment: Try not to lose this program. You will use it again in the next section.

DOCUMENTING PROGRAMS

The last example was rather complex. It would have been easier to follow had it contained remarks describing the purpose of each section and what the program was doing at various points. Programs often run many hundreds of lines, and providing remarks about what is going on helps immeasurably, both in the original writing and later, when the inevitable changes are required.

Using the REM Statement to Document

The REM statement is one way of entering remarks in a program because when BASIC sees REM, it by-passes that program line. Therefore, you are free to enter anything you wish on a REM line. This allows you to document your programs as you see fit.

Using the Single-Quote to Document

Another method for adding remarks is the use of the single quote n. When entered on a line, all following entries on that line are disregarded by BASIC.

Page 148: The IBM Personal Computer Made Easy

BASIC-Session II 135

To demonstrate how REM and single-quote statements work, some examples of documentation follow. LIST the program and enter:

1 REM DEMONSTRATION PROGRAM: STEP PARAMETERS, NESTED LOOPS AND NEGATIVE STEP VALUES.

2 PRINT 'LINE SPACE FOR READABILITY 3 REM FIRST MODULE: ILLUSTRATES USE OF STEP PARAMETER

OTHER THAN ONE 4 PRINT 'LINE SPACE FOR READABILITY 5 REM SECOND MODULE: ILLUSTRATES NESTED LOOPS 124 PRINT 'LINE SPACE FOR READABILITY 125 REM THIRD MODULE: ILLUSTRATES USE OF NEGATIVE STEP

VALUES

The remarks on lines 2, 4 and 124 illustrate the use of the single quote and are not really necessary once you learn that a PRINT statement without a value is used to space one line. This makes the program easy to read when printed on paper. Key in RENUM and hit ENTER to renumber the program. Now LIST the program.

Note that the program is too long to fit on the screen. To see the top of the program, enter:

LIST 1-30

Run the program to test correctness of your entries. There are times when documentation is useful and times when it

is not. When using PC as an electronic scratchpad, detailed docu­mentation becomes counterproductive. Save documentation for the end, if you decide to save the program. But don't put off using it­you will not believe how easy it is to forget a program after only a few weeks.

DATA ENTRY Until now, all the data used by the programs in this book has been

written into the programs. This kind of data is said to be hard-coded. It can't be changed without changing the program. There is just one problem with this: Just about all programs require the entry of some data from the outside world. In the case of personal computers, this means keyboard entry or entry from a file or a communication line. In the next section, you will learn how data can be entered into programs from a keyboard.

Page 149: The IBM Personal Computer Made Easy

136 THE IBM PERSONAL COMPUTER MADE EASY

Using the INPUT Statement for Data Entries

The INPUT statement is used for keyboard entry. It combines a print function with an input function in order to print a prompt message to the keyboard operator. The prompt message lets you specifY data that is expected at various points in a program.

Enter NEW and:

10 CLS 20 INPUT I 30 PRINT "YOU ENTERED "I 40 Print 50 GOTO 20

This is the simplest form of INPUT. It does not even specifY a prompt message. When RUN, INPUT displays only a question mark for a prompt. Then the program stops to allow an entry. If you enter a number and press the ENTER key, the program resumes by giving you back your entry for verification. INPUT then requests another entry.

What happens if you enter a letter? Remember that the program specifies a numeric variable. Enter Ctrl-Brk and change this to a string variable (1$ in lines 20 and 30) and see what happens when you enter letters or numbers. Hit ENTER without making an entry. Restore the input to a numeric variable and repeat. BASIC interprets no entry as a 0. List the program and use the edit keys to insert a prompt into line 20 as follows:

20 INPUT "ENTER ANY NUMBER: "; I

Notice that when you run the program, the question mark appears at the end of the prompt. If you want to suppress the question mark, simply replace the semicolon with a comma.

If you are working with a screen display that already has prompt messages displayed, you may want to suppress all prompts by INPUT. To do so, use the following:

20 INPUT "",I

Page 150: The IBM Personal Computer Made Easy

BASIC-Sesslon" 137

Go to command level, LIST and edit lines 20 and 30 as follows:

20 INPUT "ENTER 3 NUMBERS: ",I,J,K 30 PRINT "YOU ENTERED: "I,J,K

This format provides for multiple entries, in this case, three. All keyboard entries must be separated by commas.

Can you cheat BASIC by entering more or less than three items? Will BASIC accept mixed numeric and string variables for input? Did you change both line 20 and 30?

For Disk BASIC and Advanced BASIC Users Only: Insert a semicolon right after INPUT on line 20. RUN the program. The semicolon suppresses the line feed and carriage return. Make three entries, hit the space bar several times, and then enter. The next output starts wherever you place the cursor.

MORE IF STATEMENTS

The IF ... GOTO statement is only one example of the more gen­eral IF statement, which can be used for the conditional performance of another statement.

Using the IF Statement to Make Performance Conditional

Here is the general form of the IF statement:

IF (condition) THEN (clause) ELSE (clause)

The ELSE clause is optional. Here are some examples:

IF A=B THEN C=5 IF A=B THEN C=5 ELSE C=B*A+1 IF TIME1 <8 THEN C = A: D = 4 + B: PRINT D ELSE GOTO 60 IF A=B*4 THEN 60

The first example is a simple IF statement without the ELSE clause: If A is not equal to B, BASIC goes directly to the next program line. The second example illustrates the use of the ELSE clause and

Page 151: The IBM Personal Computer Made Easy

138 THE IBM PERSONAL COMPUTER MADE EASY

shows that arithmetic expressions can be used in the clause. The third example shows multiple statements in the THEN clause, separated by mandatory colons and the use of GOTO in the ELSE clause. The last example shows an arithmetic expression in the condition clause, as well as an alternative to the IF ... GOTO statement. Instead of entering a GOTO, a line number follows THEN, and is branched to if the condition is true.

Practice using the IF statement in these forms by creating simple programs in which you can test the correctness of the results. Do you have a question about the validity of a particular IF statement? Then try it. The worst that can happen is that you will get a syntax error message. Learn by doing.

You should note that the condition clause is considered to be zero (0) if false and not zero if true. Thus,

IF 0 THEN PRINT "TRUE"

will bypass the THEN clause and go directly to the next program line because 0 is the same as a false condition. If 1 or 2 or any nonzero number is substituted for 0 in this IF statement, TRUE will be printed.

Page 152: The IBM Personal Computer Made Easy

Chapter 10

BASIC-Session III

In this chapter, you will learn some useful program devices to make programs shorter and programming easier. Although the ma­terial here is not needed to understand later material, this chapter provides you with the remaining tools you will need to program effectively in BASIC.

SUBROUTINES

To learn about subroutines, it is helpful to use a program whose function is to check that a date was entered correctly. This validity check would pick out the month and check that it was greater than o and less than 13. Similar validity checks would be made on day and year. Call this date checking routine CHECK DATE.

CHECK DATE might be required at several points in a program. For example, if you were tracking orders, dates would be entered when an order was received, when it was due, when it was picked, when it was shipped, when it was billed, and when payment was received. Instead of entering CHECK DATE at each point in the program where it is required, it makes sense to code it once and reuse it each time it is needed. (See Figure 10-1.)

There are many such instances where the same group of instruc­tions can be used in different parts of a program. In order to avoid duplicating these instructions, they are written once as a subroutine. Each time a subroutine is needed, processing branches to the sub­routine in a manner similar to the branching operation performed by GOTO. The subroutine is said to be called by the calling program. The calling program is sometimes referred to as the main routine. A subroutine can call another subroutine.

The distinguishing feature of a subroutine is its ability to return 139

Page 153: The IBM Personal Computer Made Easy

140 THE IBM PERSONAL COMPUTER MADE EASY

GOSUB

Calling Routine

Figure 1 B-1 Calling a Subroutine

Subroutine

t

Return

processing to the point in the calling program from which it was called. The following example will make this clear.

100 REM * w" REM ORDER ENTRY * * *

180 REM ** CHECK ORDER DATE ** 190 GOSUB 2000 200 INPUT "Quantity";Q

260 REM ** CHECK SHIP BY DATE" * * 270 GOSUB 2000 280 INPUT "CARRIER";C$

510 REM **CHECK PICKED DATE"** 520 GOSUB 2000 530 INPUT "ITEM";I$

2000 REM ***CHECK DATE SUBROUTINE***

Page 154: The IBM Personal Computer Made Easy

BASIC-Session III 141

2120 RETURN

Subroutines can start anywhere in a program, but for convenience in readability and making changes, they are often at the end of a program. The CHECK DATE subroutine starts on line 2000. It is called from three places in the main routine, at lines 190, 270, and 520. The GOSUB statement is used to call it.

The GOSUB and RETURN Statements

When BASIC sees a GOSUB statement, it does two things. First, it remembers the line number of the GOSUB statement; then it branches to the program line specified in GOSUB, in this example, to line 2000. Processing now resumes in the normal way, with each statement being executed in order of ascending line number. At least one statement in a subroutine, usually the last, is always RETURN. When BASIC sees RETURN, it does just that. It returns to the next program line following the most recent GOSUB in the calling routine, and then resumes processing. Thus, using GOSUB, you can call a subroutine from any point in a program and always come back to the next statement.

There are several ways to use GOSUB. GOSUB can be uncondi­tional or conditional on an IF condition. For example, all the GOSUBs in the previous example were unconditional, since they are always executed when read by BASIC. On the other hand, consider these statements:

120 IF A = B THEN GOSUB 1000 230 ON N GOSUB 1000, 1500, 2000, 2500

The first example is just the usual IF ... THEN statement, which allows any BASIC statement in the THEN clause. All we have done here is insert the GOSUB statement.

In the second case, four possible subroutines can be branched to, starting at line numbers, 1000, 1500, 2000, and 2500.

The line number is selected when the program is run, depending on the number in the ON phrase, in this example, whatever N hap-

Page 155: The IBM Personal Computer Made Easy

142 THE IBM PERSONAL COMPUTER MADE EASY

pens to be at the time ON ... GOSUB is executed. ON N can specify any number between 0 and 255. N determines the GOSUB address as follows.

If N = 1, the first COSUB line number is used. If N = 2, the second COSUB line number is used. If N = 3, the third COS UB line number is used. etc.

IfN is 0, or greater than the number ofline numbers in the GOSUB clause, GOSUB is ignored and processing continues at the next line. In the present example, if N = 3, the program will branch to line 2000. Where N was used for illustration, you can use an arithmetic expression.

This ON ... GOSUB replaces four IF ... THEN statements. Thus, ON ... GOSUB is just a faster, shorter way to do a conditional branch to a subroutine.

THE DATA, READ, AND RESTORE STATEMENTS

DATA, READ, and RESTORE statements are always used to­gether. They provide 'data for the program to use during processing. Unlike the INPUT statement, READ does not require the program to stop and wait for a keyboard entry-the values are already stored in the program. The use of READ is limited, of course, to where the programmer knows beforehand what data will be entered. However, with the IBM Personal Computer, the powerful editing features make it easy to change program entries.

The DATA Statement

Here is the general information you need to use a DATA statement:

• The DATA statement stores numeric values or strings for use later by a READ statement.

• DATA statements can be placed anywhere in a program. • DATA statements are not executed by the program. They are

used by the READ statement. • More than one DATA statement is allowed. They will be used

by READ statements in the order they appear in the program. • Entries in a DATA statement are picked up by the READ

statement in the order they appear, from left to right.

Page 156: The IBM Personal Computer Made Easy

BASIC-Session III 143

• Strings in DATA statements do not require quotes, unless there are commas, colons, and leading or trailing blanks.

Example:

DATA 5,ABC,31.65,IBM PC, "ENTER:"

The READ Statement

READ statements pick up entries from DATA statements and enter them in variables specified in the READ statement. For example:

10 DATA "STORE SITES:","NEW YORK, NY","DANBURY, cr, "BOS-TON, MA"

20 DATA TOTAL SITES ARE, 3 30 READ TITLE$, SITE1$, SITE2$, SITE3$, TOTAL$, NO 40 PRINT TITLE$, SITE1$, SITE2$, SITE3$ 50 PRINT 60 PRINT TOTAL$; NO

In the DATA statement, only entries with commas, colons, and lead­ing or trailing blanks require quotes.

You can think of DATA statements as having a pointer to an entry in the DATA statement. The pointer starts at the first entry of the first DATA statement, and steps to the next for each variable in a READ. When all items for a DATA statement have been read, the pointer moves on to the next DATA statement. The following rules apply:

• If the DATA entry pointed to by READ is not the same type as the corresponding variable in the READ, BASIC returns a syntax error message, that is, numeric and string DATA entries must go to numeric and string variables in READ .

• If there are more DATA entries than READ variables, the pointer will remain set at the entry following the last one used by READ. Later READ statements will begin picking up data at the pointer's current position.

• If there are less DATA entries than READ variables, BASIC returns an Out-of-data error message.

The RESTORE Statement

The RESTORE statement resets the pointer of a specified DATA statement to the first item. The DATA statement is specified by giving

Page 157: The IBM Personal Computer Made Easy

144 THE IBM PERSONAL COMPUTER MADE EASY

the line number. The next READ will take the data from the new pointer setting, or if no line number is specified, RESTORE will default to the first DATA statement in the program.

In the previous example, a RESTORE could be added later in the program:

150 RESTORE 20

Since line 10 is the first DATA in the program, to restore line 10 you could write:

150 RESTORE

ARRAYS

Suppose you want to create a table of customer names with their associated customer numbers. Using the techniques described so far, you would write something along the following lines:

100 INPUT "NAME",NAME1$ 110 INPUT "NUMBER",NUM1 120 INPUT "NAME",NAME2$ 130 INPUT "NUMBER",NUM2

For anything over a handful of customers, it quickly becomes ap­parent that a better way is needed. BASIC provides this better way by allowing you to enter similar items, using just one variable name and a subscript (sometimes called an index). It works like this:

100 INPUT "NAME "NAMEX$(I) 110 INPUT "NUMBER "NUMX(I) 120 I = I + 1 130 GOTO 100

NAMEX$(I) stands for a table of names, in which (I) is the number of the table entry. Thus, NAMEX$(l) is the first entry, NAMEX$(2) the second, and so on. This simple device can save hundreds of lines of code.

BASIC uses the more general term array instead of table, but it amounts to the same thing. The symbol I is called the array subscript, even though it is not a subscript in the usual sense. By simply as­signing a number to I, you can specifY one out of many entries in a

Page 158: The IBM Personal Computer Made Easy

BASI~esslon III 145

table. This is a powerful tool. Just two items-a variable name and a subscript-can be used to process an entire table and to specifY anyone of its entries. The subscript can range from 0 to 32767. Thus, as many as 32,768 table entries are possible.

Now you can experiment with arrays. Be careful not to confuse subscripts with entries. Subscripts designate an entry; they are always numeric. Entries can be numbers or strings (use Quick Reference Chart 10-1 as a guide).

Enter NEW, AUTO 100, and then type:

100 REM *** ARRAYS *** 110 REM 120 REM **BUILD TABLE OF CUSTOMER NAMES AND NUMBERS** 130 FOR I = 0 to 2 140 INPUT "ENTER A NAME: ",N$(I) 150 INPUT "ENTER A NUMBER: ",NUM(I) 160 NEXT I 170 REM 180 REM ** SEARCH TABLE FOR A CUSTOMER NUMBER ** 190 INPUT "WHAT NAME";NX $ 200 FOR 1=0 TO 2 210 IF NX$ = N$(I) THEN 240 220 NEXT I 230 GOTO 190 240 PRINT NUM(I) 250 GOTO 190

'SEARCH TABLE 'IF MATCH, GOTO PRINT NUMBER

'NAME NOT IN TABLE 'PRINT CUSTOMER NUMBER 'GO GET NEXT CUSTOMER

First, build a table of three entries, consisting of a customer name and a corresponding customer number. Then go to a search routine, which allows you to enter one customer name and receive that cus­tomer's number in return. Table searches of this sort are common in computer programs. The FOR ... NEXT loop makes it easy. If the name is not in the table, the program falls through to line 230, which loops back for another try. However, if a match is found, the program displays the customer number, branches out of the loop, and then loops back for another customer name.

To get a feel for search speed with BASIC-a slow language-let's write a large array, say, 1,000 entries. We don't want to key in 1,000 entries, so we will let the computer write the array with dummy records, just for this experiment.

Before we can write 1,000 entries, we have to warn BASIC that we will need a lot of space. BASIC allows subscripts to have a max-

Page 159: The IBM Personal Computer Made Easy

146 THE IBM PERSONAL COMPUTER MADE EASY

imum value of 10 without requesting space. This corresponds to 11 entries in the array, since the subscript can range from 0 to 10. You request more space by using the DIM statement.

The DIM Statement

The DIM statement dimensions an array. That is, it tells BASIC the maximum value a subscript can have. DIM specifies the array name, followed by the maximum value of the subscript. For example:

DIM N$(3),NUM(3)

This DIM statement dimensions arrays N$ and NUM to 3, as per the previous example.

Strings in an array can be of variable length, a very convenient feature. The DIM statement must precede the use of the array. When DIM is executed, all array elements are set to 0, if numbers, or to null, if strings.

To dimension the two arrays in the previous example to 999 for 1,000 entries, enter:

125 DIM N(999), NUM(999)

If you also want the program to generate the array, add to and modify the previous statements by entering the following:

130 FOR 1=0 to 999 140 N (1)=1 150 NUM(I) = 1000+ I 200 FOR I =0 to 999

'USE NUMBERS AS DUMMY NAMES

To keep this simple, use numbers in place of names, since these are much easier to generate automatically, and, for purposes here, serve just as well. Be sure to delete the dollar sign ($) from all array names in lines 190 and 210, or BASIC will respond with a Type mismatch error message.

Now enter RUN-and please be patient. It will take BASIC about seven seconds to build all 1,000 entries. When it is finished, it will display:

WHAT NAME?

Page 160: The IBM Personal Computer Made Easy

BASIC-Session III 147

Enter 1 and immediately BASIC comes back at you with 1001. Impressed? BASIC found one out of a thousand entries. Next, enter 999, and prepare to wait again. At last, BASIC returns with the correct answer: 1999.

There are faster ways to search a table. When you look up a tele­phone number, you don't start at the beginning and look at every entry until you find the one you want. Yet, this is exactly what you have told BASIC to do in the above example. This is a good place to test your ingenuity and programming skills by seeing if you can devise a more rapid search program. If you don't see how to go about it, the following paragraph may help.

A commonly used search strategy, referred to as binary search, works like this:

1. Select an entry close to the middle of a table. 2. If that entry equals the desired entry, exit the search. 3. If that entry is less than the desired entry, select an entry

near the middle of the upper half of the table. In one stroke, you have eliminated half the entries from your search.

4. If that entry is greater than the desired entry, select an entry near the middle of the lower half of the table.

Steps 2, 3, and 4 are repeated until a match is found. At each step, half the remaining entries are eliminated, thus providing a very fast search.

This process requires:

• The entries must be sorted in ascending or descending order. Strings are OK; they work in alphabetical order .

• You must take care not to go past the table limits or miss entries . • You must provide for the case of not finding an entry.

Arrays With More Than One Dimension

In creating a table of names, you might want a breakdown by department. To see how to do this easily, enter:

NEW 100 REM ***TWO DIMENSIONAL ARRAY*** 110 REM 120 DIM N$(2,3) 130 REM

Page 161: The IBM Personal Computer Made Easy

148 THE IBM PERSONAL COMPUTER MADE EASY

140 REM **BUILD TABLE OF NAMES** 150 FOR J=0 to 1: FOR 1=0 TO 2 160 INPUT "ENTER NAME: ",N$(I,J) 170 NEXT I,J 180 REM 190 REM **FIND EMPLOYEE'S DEPARTMENT** 200 INPUT "WHAT NAME"; NX$ 210 for J = 0 TO 1: FOR 1=0 TO 2 220 IF NX$=N$(I,J) THEN PRINT "DEPARTMENT" J:GOTO 200 230 NEXT I,J 240 GOTO 200

You have entered two FOR ... TO statements on the same line and both subscripts in the same NEXT statement because, in this case, they are both closely related. J is, of course, the department number, providing three names in two departments each.

The program works, but it returns a department number of 0, which is an uncommon usage. This can be changed with OPTION BASE.

The OPTION BASE Statement

OPTION BASE allows minimum values of subscripts to be changed from 0 to 1 or from 1 to 0.

In the above program, enter:

115 OPTION BASE 1 'ENTER BEFORE OTHER ARRAY STATEMENTS

Then change all J ranges to go from 1 TO 2 and I ranges to go from 1 TO 3, and line 120 to DIM N$(3,4).

You can have as many as 255 dimensions in an array with up to 32,767 entries per dimension. Calculate on your PC how much mem­ory this would require for various size entries. The answers will be displayed in exponential notation. In practice, the number of dimen­sions rarely exceeds two or three.

Try creating a three-dimensional array that stores parts by aisle, by rack, and by shelf.

Page 162: The IBM Personal Computer Made Easy

QUICK REFERENCE CHART 10-1

ARRAYS

A(I,J,K, ... )

A is a numeric array with subscripts I, J, K ...

A$(I,J, K, ... )

A$ is a string array with subscripts I, J, K .. , String entries can vary in length.

No. of Dimensions (number of subscripts) I to 255 Maximum entries per dimension 32,767 Maximum subscript value without DIM statement 10

DIM Statement

DIM A(I,J, ... ), B$(K,L, ... )

A and B$ are array names. I,J, ... and K, L, ... are numeric constants, specifying the maximum values of array subscripts.

OPTION BASE Statement OPTION BASE n

n is 0 or 1 OPTION BASE sets minimum value of subscripts. It must be the first array­related statement.

Examples A(I)

Subscript,!: 0 1 2 3 4

Entry, A(I): 100 3 241 1000 8 A(2) = 241 A(0) = 100

OPTION BASE 1 A(I,J)

149

Page 163: The IBM Personal Computer Made Easy

J II: 1 2 3 4

1 100 3 241 1000 2 65 109 55 1112 3 110 30 75 11

A(2,3) =30 A(3,2) =55

150

Page 164: The IBM Personal Computer Made Easy

Part 4

How to Use the SpeCial Features 01 the IBM PC

Page 165: The IBM Personal Computer Made Easy

Chapter 11

Screen Magic

The IBM Personal Computer's ability to perform seemingly mag­ical tricks on the display screen is one of its most attractive features. I can only hope to touch on the limitless possibilities in this area. In this chapter, I will explore screen manipulation and color in text mode and lay the groundwork for working in graphics mode and color.

Unfortunately, the split of functions among the Monochrome Dis­play, Parallel Printer Adapter, and the Color/Graphics Monitor Adapter make it impossible to do justice to the available features and also treat only material that will be of interest and useful to all readers. There­fore, readers who do not have the particular adapter that is discussed here may want to pass over some sections of this chapter.

To perform these screen operations, you need not have read all previous material on BASIC. However, a knowledge of BASIC is certainly necessary in exploiting these features fully.

ADJUSTING THE SCREEN

Some monitors display the screen shifted too far left. In some cases, it might not be possible to read the most left-hand columns. If you have a horizontal adjustment on your display screen, the solution is simple. If not, you have to enter adjustment commands each time you turn the set on-a nuisance. The screen can be adjusted in either BASIC or DOS, although the methods are different. DOS is easier and more permanent. A WIDTH or SCREEN statement will reset the BASIC adjustment; a DOS adjustment holds until you enter a reset. (All these terms will be explained later. For now, just follow the directions.)

153

Page 166: The IBM Personal Computer Made Easy

154 THE IBM PERSONAL COMPUTER MADE EASY

The DOS Adjustment

Insert the DOS Master, and turn on the computer. When the screen comes on, you may not see the cursor, but enter on the keyboard:

MODE ,R,T

The R stands for shift right, and the T asks for a test pattern. Both upper and lower case will work. Hit the ENTER key. DOS shifts one character to the right if you are set for 40 columns, and two characters if you are displaying 80 columns. The first comma guarantees this, and that is why it is necessary. Then DOS displays a test pattern and asks you if you like what you see. Enter N and DOS shifts again. When you are satisfied, enter Y to exit the command.

If you shift too far right, exit the command, and enter:

MODE ,L,T

The L will produce a leftward shift instead of one to the right. Otherwise, the procedure is the same. Copy MODE (actually, MODE.COM) from the DOS disk to any other disk so you do not have to insert the DOS disk each time you turn the computer on.

The BASIC Adjustment

Note: This can only be used on 80-column widths. Enter any of the BASICs with the cursor on the far left, even if

you cannot see it. Enter in either upper or lower case:

OUT 980,2: OUT 981,87

Check for correct spacing and punctuation. Then hit the ENTER key. The display will shift two columns to the right. To move further right, change the 87 to 86. Keep going till you like what you see. The lower that last number after 981, the further right you will shift. To go left, just increase the value. When satisfied, you can immediately proceed with BASIC operations.

Page 167: The IBM Personal Computer Made Easy

Screen Magic 155

HOW TO LEARN SCREEN-RELATED STATEMENTS

BASIC statements about screen text, color, and graphics are all interrelated. You may have difficulty getting a complete understand­ing on first reading because what happens in one statement affects what happens in others. The best way is to make an initial quick pass through the material, not trying to understand it all the first time. Then come back to this point and work through the details.

Screen Pages

Screen manipulation with the IBM PC in text mode is based on the concept of screen pages. A screen page is one full screen of display,

Program writes on apage

8 pages with 4O-column width

Visual page appears on

screen

vpage

Figure 11-1 Screen Pages in Text Mode

Format: SCREEN "apage, vpage

SCREEN" 2, 3

Page 168: The IBM Personal Computer Made Easy

156 THE IBM PERSONAL COMPUTER MADE EASY

whether or not it is being displayed. By selecting a page number, you select what page will be displayed. This is the visual page. While one page is visual, the other pages store the last-entered data and are available for instant switching to the visual page. This feature provides rapid switching of screen material for "page flipping" op­eration (see Figure 11-1).

Any page can be selected for writing on. This is the active page. The active page can be different from the visual page, but it is not always. While the visual page is being viewed, the active page, un­seen, can be written on and then switched to visual status. The active page can, of course, be the same as the visual page.

When a screen is set to display 40 characters per line, 8 pages are available. With 80 characters per line, the number of pages is halved to 4.

The SCREEN Statement

The SCREEN statement is the foundation for all display wizardry. It specifies text or graphic mode, color or no color, active page and visual page (active and visual page designations are valid only in text mode). For example:

SCREEN 0,0,1,3

specifies mode 0 (text), burst 0 (no color), apage 1 (page 1 is active), vpage 3 (page 3 is visible). Remember that the active page is not necessarily visible-it is the page that is being written.

Mode, burst, apage, and vpage are all optional entries. Leading commas must be entered for any missing items. If the vpage is not specified, BASIC assigns it to apage. If mode, burst, or apage is not specified, the previous value is retained. BASIC sets apage and vpage to 0 when they are first called.

Quick Reference Chart 11-1 summarizes the use of the SCREEN statement. Note that the meaning of the burst value changes with the mode value.

As an example of using the chart to construct a SCREEN statement, suppose you want high-resolution graphics, color on, visual screen page 1, and active screen page 2. Consulting the chart, you see that mode must be 2, that no color is available in this mode, and that visual and active screen cannot be selected in this mode. You write the screen statement:

Page 169: The IBM Personal Computer Made Easy

Screen Magic 157

SCREEN 2

Now suppose you wish to change to text mode with the previous wish list. Consulting the table, you learn that the SCREEN statement would be:

SCREEN 0,1,2,1

Now when you make the following entry nothing will appear on the screen, because you have switched the active screen on which char­acters are entered to an invisible screen. Type in, even though you see nothing, the following:

SCREEN,,1,2

When you hit the ENTER key, the visible screens are switched. Now you see a previous entry. See Figure 11-1 for a description of page flipping.

You can always get back into normal operation by hitting function key F10. Do so. This puts you into text mode, with the active screen and the visible screens both 0.

NOTE: The visible screen and active screen must be the same in order for you to see entries as they are typed.

Try this and other variations on your computer. Go from one mode to another. Note that switching to medium resolution also causes a switch from 80 to 40 columns. Switching out of medium resolution leaves 40 columns. To get back to an 80-column width requires the use of the WIDTH statement.

The WIDTH Statement

The WIDTH statement is used mainly in conjunction with SCREEN to set the number of characters per line (which is the same as the number of columns in the display) to 40 or 80.

To set the width, enter:

WIDTH 40 or WIDTH 80

Page 170: The IBM Personal Computer Made Easy

158 THE IBM PERSONAL COMPUTER MADE EASY

The WIDTH statement can affect the mode as follows:

Width Old New Ent~ Mode Width Mode Width 25th Line

40 2 80 1 40 Normal 40 0 80 0 40 Inverse 80 0 40 0 80 Inverse 80 1 40 2 80 Normal

HOW TO DETERMINE THE SCREEN MODE YOU ARE IN

In the IBM Personal Computer, unlike some other PCs, it is not always apparent whether you are in a graphics or a text mode. This is because the distinction between graphics and text modes is less sharp in the graphics mode in order to simplify the labeling of graphic objects. You can determine the mode as follows: Note that the char­acters on the twenty-fifth line (last row) are normal (light on dark) in modes 1 and 2 and inverse (dark on light) in mode 0. In mode 1, five function keys are displayed; in mode 2, ten are displayed. Thus, to determine the mode use this table.

Number of Function No. of

Display Keys Cursor Mode Columns

Inverse 5 line o (Text) 40 Inverse 10 line o (Text) 80 Normal 5 square 1 (medium res) 40 Normal 10 rectangle 2 (high res) 80

WHAT CAN YOU DISPLAY ON THE SCREEN?

For the user of a personal computer, the screen is the focal point of all activity. The ability to control and manipulate images is one meas­ure of a personal computer's success. IBM has provided a rich as­sortment of screen features that will be described in this section.

Screen display depends on the equipment you have, and the mode of display you select with your programs. Four major selections can be made. These are:

Page 171: The IBM Personal Computer Made Easy

Screen Magic 159

• Color or monochrome • Text or graphics • Medium- or high-resolution graphics • 40- or 80-column text

Within each possible selection, there are a number of options, and each selection can be used in combination with others. Some graphics are possible in the text mode, and text can be readily used with graphics. Finally, the facilities IBM provides for controlling color are used in somewhat different ways with monochrome displays. All this will become clear with a little explanation.

Text

Text is the mode you are in when you turn the system on and call up BASIC. You leave the text mode by giving the BASIC command SCREEN 1 for medium-resolution graphics or SCREEN 2 for high-resolution graphics. You return to text with the command SCREEN 0.

Med res graphics, SCREEN 1, always puts you in 40 character line width, even if your system is set up for 80. Now, if you return to text mode with SCREEN 0, you will still be in 40 character width. Enter WIDTH 80 if you want to return to 80 character width.

In the text mode, the screen is divided into 25 rows and either 40 or 80 columns. The characters are located in the squares where these rows and columns intersect.

41- and BI-Column Text

40-column text must be used with TV sets and low-resolution mon­itors. Otherwise, some of the detail on letters is lost and may be unreadable. Either 80-column or 40-column text can be used with high-resolution monitors. Usually, 80 columns is preferred, but 40 columns provides larger characters and might be useful in some cases. The selection of the number of columns is under program control, and is done with the command: WIDTH 40 or WIDTH 80.

Graphics in Text Mode

Tnere are some limited but useful graphic capabilities in the text mode. The text mode provides all the characters usually found on

Page 172: The IBM Personal Computer Made Easy

160 THE IBM PERSONAL COMPUTER MADE EASY

typewriters, plus a number not usually present, such as square brack­ets, Greek letters, and math symbols. In addition to these, a number of graphic characters are available. Each graphic character is the size of a normal character, but is shaped so that with repeated use (not difficult to do with program techniques), extended images can be drawn. Special graphic characters are provided for drawing borders and lines so that forms can be designed and displayed on the screen. Most screen displays can be greatly enhanced by employing border and lines to delineate rows and columns of figures at appropriate places. Finally, bar graphs and other graphs can be created by the imaginative use of text graphics.

Thus, while crude compared to the graphic-mode capability, text graphics can be employed to advantage with the Monochrome/Parallel Adapter even though this adapter does not operate in graphics mode per se.

When IBM refers to graphics, it refers to the graphic modes of the Color/Graphics Adapter and not to the text mode graphics described in this section.

A WORLD OF COLOR

Things look better in color. Objects come alive, seem brighter, are easier to see, and make more sense. You will be challenged and fascinated by the IBM PC's capability in this area.

The color commands may seem a little complex at first, but stick with it for the results are worth the effort. In this section, I will describe colored text and the operation of the COLOR statement in text and graphics mode. In later sections, I will describe the color capability of other statements such as LINE and PAINT.

Colored Text

If you have a Color/Graphics Adapter, colored text on the IBM Personal Computer provides for coloring the characters (called the foreground) one color and the background a different color. In ad­dition, a border around the text area can be colored a third color. With these three selection possibilities, quite colorful displays can be designed. You will find that borders greatly enhance a display. Each

Page 173: The IBM Personal Computer Made Easy

Screen Magic 161

paragraph line, or even a single character, can be assigned its own color for greater readability and emphasis.

The COLOR Statement in Text Mode

Let's explore the possibilities of colored text. Get into text mode by entering: SCREEN 0.

Then key in:

COLOR 4,7,2

Press the ENTER key. If you have a Color/Graphics Adapter and color monitor, you should

see a green border, white background, and red letters. If your monitor is not color, you should see a striped border and dark characters on a light background. You are in reverse video, with dark characters on light background. Enter:

CLS

Surprised? Well, clearing the screen in reverse video makes the full screen light, instead of dark. If you look carefully, keyboard entries are just visible.

Return to normal with,

COLOR 1,0

Key in:

CLS

Press ENTER. The screen will clear, except for the prompt and the cursor, and the border.

Key in some characters to see how colored text looks. Try other values for COLOR. The first digit can go from 0 to 31, the second from 0 to 7, the third from 0 to 15. Just be sure the OK prompt is displayed before keying in COLOR. If not, press the ENTER key.

What happens when you hold down the space bar? When you press backspace ( +- )? Depending on the quality of your monitor, you will find considerable differences in the readability of certain color com­binations.

Page 174: The IBM Personal Computer Made Easy

162 THE IBM PERSONAL COMPUTER MADE EASY

COLOR Graphics

Unlike text mode, in a graphics mode, a number of commands control color. The COLOR statement merely sets the stage, so to speak, for these other graphic statements. In this chapter, I will limit discussion to describing how COLOR is used to select the background and the palettes that other graphic commands use.

The COLOR Statement in Graphics Mode

In graphic mode, use this format for the COLOR statement:

COLOR background, palette.

By entering a number for the background and a number for the palette, you select a background color and one of two palettes. Each palette contains three colors. The actual color is selected later by a graphic statement, such as LINE, DRAW, or PAINT. COLOR pre­sents these graphic statements with a palette from which to choose. This presents the following possibilities to the programmer:

• Pick a palette and then pick a color. • Switch colors, using a graphic statement . • Switch color palette using the COLOR statement.

Unfortunately this cannot be demonstrated until the graphic state­ments have been described. Then you will have plenty of opportu­nities for color exploration. Until then, review Quick Reference Charts 11-1 through 11-5 on the COLOR statement, and refer to them as needed when working with COLOR.

For those readers who don't have a color display, don't despair. If you have the Color/Graphics Adapter, you can at least get shadings that will enhance your displays.

Page 175: The IBM Personal Computer Made Easy

..... ~

W

QUIC

K RE

FERE

NCE

CHAR

T 11

-1

THE

SCRE

EN S

TATE

MEN

T

Form

at

SC

RE

EN

mod

e, b

urst

, ap

age,

vpa

ge

Mod

e, b

urst

, ap

age,

and

vpa

ge a

re a

ll op

tion

al.

Lea

ding

co

mm

as r

equi

red,

e.g

., S

CR

EE

N",

vpag

e

MOD

E AN

D BU

RST

Mod

e M

ode

Char

acte

rs

Gra

phic

s pl

ottin

g de

scrip

tion

valu

e pe

r ro

w po

ints

al

low

ed1

Horiz

onta

l Ve

rtica

l

Tex

t m

ode

0 40

or

80

Non

e N

one

Med

ium

-res

olu-

1 40

onl

y 32

0 20

0 ti

on g

raph

ics

Hig

h-re

solu

tion

2

80

640

200

grap

hics

1 U

se W

IDT

H S

tate

men

t to

sel

ect

char

acte

rs p

er r

ow .

Burs

t ¥p

age

and

FlO

ap

age

Func

tion

key

Valu

e Co

lor

valid

? ON

?

0 N

o Y

es

Dis

play

s sc

reen

1

Yes

0,

0,0

0 Y

es

No

Sw

itch

es t

o 1

No

mod

e 0

,40

ch

arac

ter

0 N

o N

o S

wit

ches

to

1 N

o m

ode

0

Page 176: The IBM Personal Computer Made Easy

QUICK REFERENCE CHART 11-2

COLOR-IN-TEXT MODE

Adapter: Color/Graphics

Display: RGB color monitor or color TV and RF Modulator. TV sets and some RGB monitors have limited capability and will not

display the light colors listed below.

Screen is in text mode, unless SCREEN 1 or SCREEN 2 statements have put screen in a graphics mode. Return to text mode with SCREEN 0.

Use COLOR statement to select colors ofJoreground, background, and border.

Format: COLOR foreground, background, border.

Foreground, background, and border are all optional. Their absence leaves previous color unchanged.

Foreground: selects the color of the characters displayed and controls whether they are steady or blinking. Foreground entries are numbers 0-31, as fol­lows:

Dark Colors o Black 1 Blue 2 Green 3 Cyan 4 Red 5 Magenta 6 Brown 7 White

Light Colors 8 Gray 9 Light blue 10 Lig~t green 11 Light cyan 12 Light Red 13 Light magenta 14 Yellow 15 Bright white

The colors will vary with the monitor used. BLINKING characters: Add 16 to the above numbers. The color stays the same.

Background: 0-7. Only the dark colors listed above can be selected.

Border: 0-15. Any of the light or dark colors listed above can be selected.

164

Page 177: The IBM Personal Computer Made Easy

QUICK REFERENCE CHART 11-3

NONCOLOR DISPLAYS IN TEXT MODE

Adapter: Monochrome/Printer Color/Graphics

Display: Monochrome monitors Black-and-white TVs and RF modulator

The COLOR statement controls light values from dark to bright and also controls underlining and blinking.

Format: COLOR foreground, background

Foreground: 0 is dark characters (often called inverse video) 1 is underlined light characters (Monochrome Printer

Adapter only) 2-7 is light characters (normal video) 8 is dark characters 9 is underlined bright characters 10-15 is bright characters

BLINK: All the above values can be made to blink by adding 16 to the number.

Background: 0-6 is dark 7 is light when used with dark foreground

165

Page 178: The IBM Personal Computer Made Easy

QUICK REFERENCE CHART 11-4

THE COLOR STATEMENT WITH THE COLOR/GRAPHIC ADAPTER AND NONCOLOR MONITOR

The COLOR statement controls light, dark and shadings, blinking char­acters, border, and inverse/normal video.

Format: COLOR foreground, background, border

Foreground: 0 is dark 7 is light 15 is bright

BLINK:

23 is light blink 31 is bright blink

Background: 0 is dark 7 is light

Border: 0 is dark 1-6 shaded 7 is light 15 is bright

Various effects can be obtained by using intermediate values for those shown above.

166

Page 179: The IBM Personal Computer Made Easy

QUICK REFERENCE CHART 11-5

COLOR IN MEDIUM-RESOLUTION GRAPHICS

Adapter: Color/Graphics

Display: RGB color monitor or color TV and RF modulator. TV sets and some RGB monitors have limited capability and cannot display the light colors listed below.

Use SCREEN statement first to get into graphics:

SCREEN 1

Use COLOR statement to select colors of background and palette (no border in graphics mode).

Format: COLOR background, palette

Background: 0--15 as follows Dark Colors Light Colors o Black 8 Gray 1 Blue 9 Light blue 2 Green 10 Light green 3 Cyan 11 Light Cyan 4 Red 12 Light red 5 Magenta 13 Light magenta 6 Brown 14 Yellow 7 White 15 Bright white

The colors may vary with the monitor used. Palette: 0-255 as follows

1 2 3

An EVEN number An ODD number Selects PaleHe II Selects PaleHe 1

Green Red Brown

Cyan Magenta White

L These numbers are selected from the designated palette by later state­ments: PSET, PRESET, LINE, CIRCLE, PAINT, and DRAW. Number 3 is default. If these statements select number 0 (not in palette), the back­ground color is chosen and the figure is invisible.

167

Page 180: The IBM Personal Computer Made Easy

Examples

10 SCREEN 1 20 COLOR 5,8

30 PSET (10,20),2

40 COLOR X+ 1,Y-l

70 COLOR B

90 COLOR,3

QUICK REFERENCE CHART 11-6

'Selects graphics mode 'Selects magenta background and

palette 0 (even number) 'Plots a red point (palette 0, line

2 at location 10,20) 'Numeric expressions allowed, but

must be in range 'If palette left out, palette remains

the same 'If background left out, its color

remains the same

NONCOLOR DISPLAYS IN GRAPHICS MODE

Adapter: Color/Graphics

Display: Monochrome monitors Black-and-white T'Vs

The COLOR statement can be used to produce .shadings in graphics mode when the Color/Graphics Adapter is used with a noncolor monitor. Select medium resolution graphics with

SCREEN 1

Use COLOR to produce shadings

Format: COLOR background, palette

Background: 0

168

Page 181: The IBM Personal Computer Made Easy

Chapter 12

Cut-n-Paste Programming

Conventional wisdom in programming stipulates that programs should be carefully planned in advance, flow charted, and fully doc­umented. Structured programming techniques should be used and programming languages that force structured programming should be employed. Cut-n-paste programming breaks every one of these rules. In using cut-n-paste techniques, programs are quickly thrown to­gether, cut up, merged with other programs, and modified on an ad hoc basis until the desired results are obtained.

Cut-n-paste is a mode of programming that is especially appropriate to the personal computer when it is being used as an electronic scratchpad, whereas traditional programming rules are designed for the development of large programs by teams of programmers. But the personal computer can be programmed under very different con­ditions that involve creativity and experimentation on the user's part. For example, you might develop a screen and then notice that a field looks better highlighted. You try it, but then decide, no, it might look better underlined. So you try that. BASIC is an ideal language for this kind of programming. Everything about BASIC that makes it unsuitable for use by programming teams also recommends it for cut-n-paste. You can go right into the BASIC program, tear it apart, and reassemble it in another form. You can shuffle statements like cards in a deck. Statements can be added, deleted, or changed in any order. And then after all this, the program can be run immediately and results displayed. If BASIC had not been there, somebody would have invented it just for the personal computer. And yet, in spite of all this, people still debate whether owners of personal computers should learn BASIC or Pascal.

169

Page 182: The IBM Personal Computer Made Easy

170 THE IBM PERSONAL COMPUTER MADE EASY

First-time users approaching the personal computer without any preconceived notions about how to program should realize that there is more than one way to program. There are techniques suitable for scratch pad programming and techniques suitable for large programs that may be used and modified by others than yourself. Don't let traditionalists talk you out of learning BASIC and using cut-n-paste techniques. Let's create a screen menu using cut-n-paste program­ming.

HOW TO CREATE YOUR OWN SCREENS

The ability to make your own screen displays gives you a powerful tool with which you can create a colorful sales presentation, a business form, a menu from which to select programs, computer art, or just games. The design and layout of various types of screens is a key part of personal computer programming. BASIC provides the tools with which you can do this yourself. No extensive programming skills are required.

The LOCATE Statement

The LOCATE statement tells BASIC to put the cursor at a des­ignated row and column of the screen. It can also be used to turn the cursor ON or OFF.

Enter NEW and:

10 CLS 20 LOCATE 10,20,1 30 GOTO 30 RUN

You have LOCATEed the cursor on the tenth row, twentieth col­umn. Line 30 is branching to itself. This is a trick used to stop BASIC from doing anything. This gives you a nice clear screen with nothing but the cursor displayed.

Now enter Ctrl-Break to break out of this endless loop. BASIC displays a Break in 30 message, telling us the last line of the program that was executed before the break. It also displays the AC sign with the caret indicating where the cursor was hefore the break: in the caret character position.

Page 183: The IBM Personal Computer Made Easy

eut-n-Paste Programming 171

The LOCATE statement is a powerful tool. Remember that the PRINT statement will place data on the screen at the cursor location. Knowing how to locate the cursor means that you can locate any PRINTable character on the screen. Try it. Enter:

25 PRINT "A"

LIST the program to check that BASIC inserted your PRINT state­ment before the GOTO statement. OK? Now RUN it.

An A appears where the cursor was before. And since a PRINT was entered without a comma or semicolon, BASIC performs a next­line operation (carriage retumlline feed), placing the cursor on the next line, first column.

But maybe you don't want the cursor displayed; you just want the A. All right, enter Ctrl-Break and LIST the program. Use the Edit keys to change the 1 in the LOCATE statement to a 0. When this is RUN, the cursor will be gone and you will have a clean screen with a solitary A. You can use this new-found power to design a menu, a screen that is typical of the kind of displays often used in purchased programs.

We will want to SAVE the next program on disk or tape. If you have a disk drive, insert a FORMATted diskette in the default drive. Tum on if the system is off. If already on, reset (Ctrl-Alt-Del) to load DOS. Remember, DOS must always be loaded to use a disk (DOS = disk-operating system).

Enter BASIC and AUTO and the following program. Don't worry if you don't understand some of the entries; they will be explained later. Work carefully, paying special attention to the punctuation. Remember, if you make an error while using AUTO you can not go back to a previous line to correct it. Make all corrections when finished with AUTO.

10 REM ***********************************************

20 REM ****INVENTORY PROGRAM: FIRST MENU SCREEN **** 30 REM ***********************************************

40 REM 50 REM *** INITIALIZE *** 60 CLS 70 REM 80 REM * * * SET PARAMETERS * * * 90 REM R = ROW; C = COLUMN; INC = INCREMENT OF ROW 100 R=2: C1 =5: C2345=4: C6=10: INC1 =3: INC2=1

Page 184: The IBM Personal Computer Made Easy

172 THE IBM PERSONAL COMPUTER MADE EASY

110 REM 120 REM *** FORMAT SCREEN *** 130 LOCATE R,C1 140 PRINT "Inventory System Menu" 150 R=R+INC1 160 LOCATE R,C2345 170 PRINT "To INSPECT inventory enter: I" 180 R=R+INC2 190 LOCATE R,C2345 200 PRINT "To CHANGE inventory enter: C" 210 R=R+INC2 220 LOCATE R,C2345 230 PRINT "To perform file MAINTENANCE enter: M" 240 R=R+INC2 250 LOCATE R,C2345 260 PRINT "To print a REPORT enter: R" 270 R=R+INC2+1 280 LOCATE R,C6 290 PRINT "Select one: ---300 K$ = INKEY$ 310 IF K$="" GOTO 300

The SAVE Command

As soon as you have finished keying in, use the SAVE command to store programs on disk. Get in the habit of SA VEing your work frequently. Don't wait until you have all the bugs out. You may lose the program and have to reenter. SAVEing a program takes only a few seconds.

To SAVE a program, you key in SAVE" or press the F4 key, which does the work for you. Then you must enter a file name.

Naming BASIC Files

If you stick to these rules, a file name will be accepted in all three BASICs:

• No more than eight characters • Only the characters A-Z and 0--9 • No 00 or FF sequences (required only in cassette BASIC)

If you want to specify a drive other than the default drive, precede the file name with the drive letter and a colon (:).

Page 185: The IBM Personal Computer Made Easy

Cut-n-Paste Programming 173

For example, to SAVE the program created in the previous section, enter:

SAVE "MENU

Or if you want to SAVE it on drive B, enter:

SAVE "B:MENU

Or if you want to SAVE it on cassette tape, enter:

SAVE "CAS1 :MENU

When you have entered the SAVE command, press ENTER, and listen for the disk drive to go into action. If all is well, BASIC will come back with the OK prompt. If not, it will display a message indicating the problem (more or less). Note that this BASIC may not give an audible alarm for an error. If you are used to other BASICs that beep the speaker, be on guard for silent error conditions with this BASIC.

Always check the result of a SAVE because if you miss an error message and shut the system down, you will lose the program. What reply did you get from BASIC on your last entry? If OK, enter FILES to see if MENU is listed in the directory. Look first at the end of the directory. This is where most, but not all, new files go. Note that BASIC adds a three-letter extension to most names, in this case, it is BAS for BASIC program.

Enter NEW and LIST. Nothing is listed, as expected, since NEW kills any program in

memory. But you want your program back. To get it, use the LOAD command.

The LOAD Command

Key in LOAD" or press the F3 key. Now enter the exact same· name as you used in the SAVE command. Usually, the device name also will be the same. However, this could change if you moved the disk from one drive to another.

In the present example, enter:

LOAD "MENU

Page 186: The IBM Personal Computer Made Easy

174 THE IBM PERSONAL COMPUTER MADE EASY

Now LIST it. You have retrieved the program from disk, so now RUN it.

Creating Your Own Menu

Enter RUN. If all is well you should see:

Inventory System Menu

To INSPECT inventory, enter: I To CHANGE inventory, enter: C To perform file MAINTENANCE, enter: M To print a REPORT, enter: R

Select one: ---

This is typical of screens used to allow users to interact with pro­grams in well-designed software. Instead of having to remember com­mands, the operator is given a menu of possible choices to select. Here, letters have been keyed to meaningful words. Alternately, the selections are often numbers, and you are then asked to enter the appropriate selection number. In this case, enter I, C, M or R. This ends the program, so BASIC returns to the command level with an OK prompt. You can add to the program later, but the next step is to edit this screen menu.

The menu could be used as is, but it can also be improved. You will use the IBM Personal Computer's powerful editing features to do this quite easily.

Enter:

LIST 100

Line 100 is displayed, showing the row, column, and increment values. These values were selected without much thought, because it is easier with BASIC to make adjustments than to try for first-time accuracy. Note that line 100 contains six statements. This requires some explanation.

More Than One Statement Per Line

Several statements can be entered on one BASIC line by separating them with colons. A BASIC line extends until the ENTER key is pressed, and can be longer than a physical line. A line in BASIC that

Page 187: The IBM Personal Computer Made Easy

Cut-n-Paste Programming 175

extends from one ENTER to the next is called a logical line. It can be shorter or longer than the 40- or 80-column screen width which determines a physical line.

The advantage of several statements per line is a saving in memory space. Also, if the statements are related, they can be easier to read if grouped this way, and editing is easier. However, you can only branch to line numbers, so only the first statement on a line can be the entry point of a branch.

Editing a Menu

You can now make the following changes to the menu:

• Center the screen heading • Increase the line spacing • Shift lines 2, 3, 4, and 5 down and to the right • Shift line 6 so the cursor lines up with I, C, M, and R • Reverse the display of the heading to dark on light • Increase the brightness of the letters I, C, M, and R

Depending on your current screen width, move the cursor up to line 100, and make the following changes, using the Ins (Insert) key:

48 Cl = 70 C6 = 23 INCI = 5 INC2 = 3

Width Screen

88 Cl = 23 C2345 = 16 C6 = 34 INCI = 5 INC2 = 3

These entries will be explained later. For now, we want to con­centrate on changing and manipulating BASIC statements. Refer to Quick Reference Chart, "Non-color Displays in Text Mode" for ex­planation of the COLOR statements we will be using to modifY the BASIC statements.

Hit ENTER only after all the above entries are made. Now you will perform some screen magic on the display itself.

Page 188: The IBM Personal Computer Made Easy

176 THE IBM PERSONAL COMPUTER MADE EASY

Reversing an Image With the COLOR Statement

The image display can be reversed on any type monitor by entering:

COLOR 0,7

The display will "reverse print" by entering dark characters on a light background. Entering COLOR 7,0 will return the screen to "normal print" by entering light characters on a dark background.

Reversing the Menu Heading

Bring the cursor to the bottom of the screen, under OK. Enter new lines 135 and 145 as follows:

135 COLOR 0,7 145 COLOR 7,0 RENUM LlST50-170

Check your entries, and when you are satisfied, RUN the program. The display could still use three improvements. First, I, C, M,

and R could be highlighted. And you don't want line 25 showing on a menu where it has no relevance, so that could be deleted. Finally, you need an escape hatch. An operator must always have an exit to the next lower level.

Highlighting Characters Using the COLOR Statement

Characters can be highlighted with any monitor by entering:

COLOR 15,0

Return to normal with:

COLOR 7,0

Page 189: The IBM Personal Computer Made Easy

eut-n-Paste Programming 177

Turning Line 25 OFF and ON-The KEY Command

Line 25, the Soft Key Display for FI-FI0, can be turned off by entering:

KEY OFF

The function keys remain active when the twenty-fifth line is erased. KEY ON turns on line 25. If the screen width is 40 characters,

only the first five functions of the FI-F5 are displayed. If screen width is 80 characters, all ten functions are displayed.

Putting the Final Touches on the Menu

To highlight I, C, M, and R, you add COLOR commands. If you have followed along and RENUMbered the program, you

should have PRINT statements on lines 190, 220, 250, and 280. Start­ing with line 190, do the following:

1. Set the cursor to the upper case I, just before the quote. 2. Key a quote over the I, replacing the I with ". 3. Key in right after the quote:

;:COLOR 15,0:PRINT "I":COLOR 7 4. Hit ENTER. 5. Repeat for lines 220, 250, and 280, letters C, M, and R.

The result should be that the letters I, C, M and R are highlighted. Check your entries. Then RUN the prograp1. OK?

An escape hatch will be programmed on line 25. Enter:

315 KEY OFF 'TURNS OFF LINE 25 317 LOCATE or 25,26 317 LOCATE 25,17 318 PRINT "To EXIT enter E";

(for 80-column width) (for 40-column width)

Now place a flashing cursor at the selection position. Enter:

319 LOCATE R,C6+16, 1,0,7 RENUM

RUN it and admire the result. If you want to change it, you are urged to do so, but SAVE what you have now as MENU.

Page 190: The IBM Personal Computer Made Easy

178 THE IBM PERSONAL COMPUTER MADE EASY

You have now created a reasonably attractive menu using a cut-n­paste approach. Cut-n-paste is a very efficient design procedure for use with a personal computer. At electronic speeds, you can move, merge, and delete characters, lines, or paragraphs, or quickly try one approach, discard it if you don't like it, keep it if you do.

You can use this menu program as a kind of prototype for creating other screens, cutting and pasting instead of always starting from the beginning. SAVE it again as MENU2 because you will change this version again.

While we are on the subject of screen design, one word of advice. Try to keep the screen uncluttered. Clean lines, blocked data, and plenty of open space contribute to easy reading and accurate use.

Resume

In the hurry to get a good-looking menu screen, I left some loose ends that require explanation.

LIST the menu program, by pressing F1 and entering 1-150 to list the top of the final program.

Note the blocking and use of REM statements to name sections of the program: Initialize, Set Parameters, and Format Screen. You might practice line insertion by inserting more comments, perhaps one to introduce each of the statements on the display.

In line 90, symbols are defined. You can improve on this by in­serting more precise definitions, such as: "cx = column for x line of display."

Line 100 is the key to this method offormatting. Row R is initialized to 2. By adding INC1 and INC2, all lines are positioned relative to row 2. This facilitates moving lines around in groups. Remember that to adjust the display, only line 100 need be changed.

Enter LIST to display the rest of the program. Line 290 contains a + 1 to provide a minor adjustment. This violates

the rule that all positioning should be controlled from one line, namely, line 100. You can remove the + 1 if you want to.

Line 320 has a comment introduced by an apostrophe instead of a REM. The program could use more such comments on statement lines. Use the cursor keys to position the cursor, and then add com­ments where you feel they are needed.

Line.340 ends with a semicolon. Although line 25 is not supposed to scroll, if the semicolon is left out, the display will move up one line when line 25 is PRINTed.

Page 191: The IBM Personal Computer Made Easy

eut-n-Paste Programming 179

Lines 350, 360, and 370 introduce some new features that will be discussed in the following sections. For your purposes here, however, line 350 is the arithmetic expression for the column parameter. Com­pare this to lines 260 and 270, where two lines were required to accomplish a similar purpose. As an exercise, shorten the program by consolidating all such statements. If this works, SAVE it.

The LOCATE Statement Revisited

This section applies to text mode only (SCREEN 0) with either adapter (see Quick Reference Chart 12-1).

Previous discussion of the LOCATE statement was limited to po­sitioning the cursor, but the LOCATE statement can also be used to turn the cursor on and off and to adjust its shape. Enter NEW and CLS and then type:

10 LOCATE 10,30,1,0,1 20 GOTO 20 RUN

The cursor is placed at location 10,30 with a single line displayed at the top of the character position. The shape of the cursor is con­trolled by the last two digits of the LOCATE statement. The third digit sets the cursor ON and OFF. Test this and experiment with various combinations for the last two digits. Remember you are in a program loop; break out with Ctrl-Break.

You will notice even when the cursor is invisible, it is still present as indicated by the hC displayed when you enter a break. Try these combinations for the last two digits: 7,0 and 7,6. Can you guess the rules of cursor formatting? Any parameter can be omitted by just entering a comma, so BASIC knows what position you are interested in. For example, to turn the cursor off, enter:

LOCATE ,,0 (Drop following commas at the end.) Once again, you have seen an example of how the LOCATE state­

ment is a powerful tool that makes possible all manner of wizardry with screen text. You can use it to create your own screen displays.

The INKEY$ and LEN Statements

INKEY$ allows you to incorporate single-keyboard entries in your program. INKEY$ registers the key you have pressed and makes the

Page 192: The IBM Personal Computer Made Easy

180 THE IBM PERSONAL COMPUTER MADE EASY

information available to following program statements. Use INKEY$ when you want to use the function keys, or any other key, to control program operation (See Quick Reference Chart 12-2).

Enter NEW, CLS, AUTO, and:

10 PRINT "PRESS A KEY· 20 K$ = INKEY$ 30 L = LEN(K$) 40 PRINT L; 50 IF L = 0 GOTO 20 60 CLS: PRINT L 70 PRINT "YOU ENTERED "K$

In line 20, INKEY$ picks up the keyboard entry and delivers it to the string variable K$.

In line 30, LEN(K$) finds out how many characters there are in K$, and gives that number, a numeric variable, to L. If no key is pressed, L will be 0. If a single key is pressed, L will be 1. If Alt is pressed with another key, L will be 2.

Thus, when line 40 PRINTs L, you will see a string of 0s-you are in a loop-until a key is pressed. Then you fall through the loop at line 50, and print the value of Land K$ on a cleared screen.

In the menu program, you used another method to test for zero characters. You entered:

If K$ = "" GOTO 320

Using the LEN function is more useful since it gives you the actual count.

Run this program a few times, entering only letters and numbers. Observe that the number printed on the top line is a 1. Now try several function keys. The first letter returned is the first letter of the corresponding soft-key definition on the bottom line of the display. Thus, Fl returns L for LIST, and LIST is put under the OK prompt. Remember that you are free to give these keys any value you want through the KEY statement.

Now RUN the program and press first the Alt (Alternate) Key and then any other key while the Alt key is still down. Observe that the number on top of the display is a 2, meaning that two characters were returned from this key combination. Try several key combos. Alt

Page 193: The IBM Personal Computer Made Easy

Cul-n-Paste Programming 181

stretches the character set into the range of special characters, such as percentages or Greek letters.

Now that you know how to pick up keyboard characters, try your hand at writing a short program that tests for a specific entry and returns a message of either "Wrong, dummy. Try again." or "Right you are!"

Page 194: The IBM Personal Computer Made Easy

QUICK REFERENCE CHART 12-1

THE LOCATE STATEMENT

Format: LOCATE R,C,ON/OFF,S,E Where,

R = row number 1 to 25 C = column number 1 to 40, or 1 to 80 ON/OFF = 0 for cursor OFF

1 for cursor ON S (start) = mini cursor-line at which cursor is turned ON E (end) = mini cursor-line at which cursor is turned OFF

Mini cursor-lines are numbered vertically along the character position where the cursor is located. There are 8 such lines, numbered 0-7.

QUICK REFERENCE CHART 12-2

SUMMARY OF INKEY$ ACTION

INKEY$ gets a keyboard character and passes it to a string variable: K$ = INKEY$

Action

No key pressed One nonfunction key pressed One function key pressed Alt plus another key

182

Number of Characters Returned

o 1 1 2

Value of Characters Returned

Null Actual key value Assigned soft-key value Extended ASCII char­acter

Page 195: The IBM Personal Computer Made Easy

Chapter 13

Computer Sounds of Music You have worked hard to learn some elements of BASIC, so now

you will be rewarded with a musical interlude. I don't promise any masterpieces, but I think you will be fascinated by the combination of sounds that computer programs can generate. Use the Quick Ref­erence Chart at the end of the chapter to supplement the discussion in the text.

BEEPING THE SPEAKER

BEEP is the simplest of the sound statements. Enter in direct mode:

BEEP

You heard an 800Hz, Y4-second beep. Enter NEW, CLS, AUTO, and then type:

10 INPUT ·PRESS A NUMBER KEY"; N 20 IF N < 5 GOTO 110 30 FOR X = 1 TO 3 40 FOR Y = 1 TO 4 50 BEEP 60 NEXT Y 70 FOR Y = 1 TO 500 80 NEXT Y 90 NEXT X 100 GOTO 10 110 PRINT ·SPEED OK, KEEP-A-GO'N" 120 GOTO 10

183

Page 196: The IBM Personal Computer Made Easy

184 THE IBM PERSONAL COMPUTER MADE EASY

This program performs a typical test in which, if some condition is not met, a warning or attention signal will sound. In this case, an entry of a number less than 5 is OK; anything larger gets a warning beep. This program generates a more elaborate sound than usually needed just to show off how nested FOR ... NEXT loops can be used to produce sound patterns. Now you can take over and see what you can do with computer sound effects. Modify this program in various ways. Then try six or seven nested loops as a sound effects experiment.

COMPUTER MUSIC

I will now describe BASIC's way of making music. In the following exercises, you will get a chance to hear the range of sounds available and will learn how to use the power of computer programming to produce sound effects. No attempt will be made to produce anything resembling a melody. Coaxing any real music out of this beast requires somebody with a knowledge of music, and, no doubt, a lot of patience.

Two statements are provided for creating computer sounds and computer music: SOUND and PLAY. SOUND can be used with any BASIC. For PLAY, you must have Advanced BASIC.

The SOUND Statement

In the SOUND statement we specify a pitch (frequency) and a duration in the format,

SOUND frequency, duration

Enter NEW, CLS, and then type:

SOUND 440,100

Did you hear a nice tone? That was the note A, 440 cycles per second at a duration of about 5 seconds.

Actually, the duration was 100/18.2 = 5.5 seconds because a value of 18.2 gives a one-second duration. You can test this by entering:

SOUND 37,18.2

Page 197: The IBM Personal Computer Made Easy

Computer Sounds of Music 185

TABLE 1~1 FREQUENCIES FOR THE SOUND STATEMENT

Note Frequency Note Frequency

C 130.810 C* 523.250 D 146.830 D 587.330 E 164.810 E 659.260 F 174.610 F 698.460 G 196.000 G 783.990 A 220.000 A 880.000 B 246.940 B 987.770 C 261.630 C 1046.500 D 293.660 D 1174.700 E 329.630 E 1318.500 F 349.230 F 1396.900 G 392.000 G 1568.000 A 440.000 A 1760.000 B 493.880 B 1975.500

*middle C

To create periods of silence, use SOUND 32767,duration. You can enter a frequency as high as 32,767 without getting an

error message, but you are not likely to hear anything. Enter NEW, CLS, AUTO, and then type:

10 INPUT "ENTER DURATION";D 20 FOR F = 37 TO 9000 30 SOUND F, D 40 NEXT 50 GOTO 10

D can have any value between 0 and 32767, but you will hear sounds starting only at 0.5.

When you are through experimenting with F and D values, list the program, enter AUTO 40, and add:

40 *FOR W = 1 TO 20 50 *NEXT W 60 SOUND 400,100 70 FOR W = 1 TO 20 80 NEXT W 90 SOUND 400,0 100 NEXT F 110 GO TO 10

Page 198: The IBM Personal Computer Made Easy

186 THE IBM PERSONAL COMPUTER MADE EASY

When this is RUN, and the duration has been set at 0.5, you will hear superimposed rhythms, one of constant frequency at 400 and one of increasing frequency. The vibrato effect is caused by line 90. When a SOUND statement with zero duration is executed, a pre­viously initiated sound is stopped. Otherwise, it continues for its specified duration while the program is running.

Lines 40, 50, 70, and 80 are wait loops, designed merely to provide program delay. Changing the parameters of these loops results in some interesting effects. For example, change line 70 to read:

70 FOR W = 1 TO 5

And try:

20 FOR F = 37 TO 9000 STEP 100 110 GOTO 20

As you have probably noted, the possibilities here are endless. You may linger here for a while, but if you have Advanced BASIC, you also may want to move on to the PLAY statement.

The PLAY Statement

The PLAY statement provides a kind of minilanguage for composing and playing music by computer. Within the PLAY statement, you can insert minicommands to playa note A to G, control the duration of the note (called a length by IBM), the octave, tempo, pause, flats, and sharps, and other timing and control commands. Octave, tempo, and length are remembered by the PLAY statement, and they will apply to all the notes that are entered until you override with another command. Length can apply to an individual note or to all succeeding notes. The PLAY statement rules are given in Quick Reference Chart 13-1. Refer to this chart to interpret the following program state­ments.

In the following examples you will learn what commands are avail­able and how to use them.

Now enter NEW:

10 FOR I = 0 TO 6 20 PRINT I + 1

Page 199: The IBM Personal Computer Made Easy

30 PLAY "0 = I; ABCDEFG 40 NEXT

Computer Sounds of Music 187

Line 10 is a typical FOR statement that you will be familiar with by now. Line 20 is inserted only so you can keep track of the octave being played; it has nothing to do with the sound. Line 30 is the key line. The octave (0) is set equal to (=) I and followed by a semicolon (;), which is required. This is rollowed by all notes A through G.

The same principals apply to all PLAY command variables, which can be any of the numeric constants just described. For example, you might use 03, L2, P20, and T42.

Here is an example using all four of the above. Starting line count at 110 instead of 10 provides better formatting of the following FOR ... NEXT loops.

Enter NEW, AUTO 110:

110 CLS 120 FOR OCTAVE = 0 TO 4 130 PRINT, 140 PRINT "OCTAVE = " OCTAVE + 1 150 FOR LENGTH = 9 TO 11 160 PRINT "LENGTH =. " LENGTH 170 FOR TEMPO = 90 TO 255 STEP 40 180 PRINT "TEMPO = " TEMPO 190 PLAY "0 = OCTAVE; L=LENGTH; T=TEMPO; ABCP=LENGTH;

DEFGP2 200 NEXT TEMPO 210 PRINT 220 NEXT LENGTH 230 NEXT OCTAVE

Here you are varying the tempo within the length within an octave. After notes A, B, and C in the PLAY statement, strike NO (pause) to produce a variable duration equal to the LENGTH. Note that the semicolon (;) is required after a variable. At the end, use NO for a constant time 2 in order to catch your breath before the next series of notes.

Musicians might want to save this program as a basic reference to the different possible sounds. It is easy to change the ranges, as desired. Just be sure to insert a REM statement at the beginning to describe the program. This should be done with all SAVEd programs.

PLAY provides an alternative way of specifying notes that allows

Page 200: The IBM Personal Computer Made Easy

188 THE IBM PERSONAL COMPUTER MADE EASY

you to treat notes as variables. Instead of notes A through G, you can specify a note as Nn, which causes note n to be played, in which n can be any of the notes 1 through 84 in the 7 octaves, with 12 possible notes per octave, including sharps ( + ) and flats ( -). The n can also be set to 0, which means reset. An example will make this clear.

Enter NEW:

10 CLS 20 COUNT = 13 30 FOR NOTE = 1 TO 84 40 IF COUNT < 13 GOTO 100 50 COUNT = 1 60 OCTAVE = OCTAVE + 1 70 PRINT 80 PRINT "OCTAVE = "OCTAVE 90 PLAY "NO 100 PRINT "NOTE = " NOTE 110 PLAY"N = NOTE; 120 COUNT = COUNT + 1 130 NEXT NOTE

This program plays all notes. The octave changes every 12 notes. Therefore, in order to PRINT each new octave number, you set up a counter (COUNT) and initialize it to 13 in line 20. In line 40, as long as the counter is 12 or less, you pass lines 50-90, which reset COUNT to 1; increase the octave number; skip a line; PRINT the octave number; and pause (NO) before starting the next octave. All these things are done the first time through because COUNT is in­itialized to 13, thus printing octave 1 (remember that BASIC initializes OCTAVE to 0 as a default value in line 60).

Note the format of the PLAY statement in line 110. It is similar to that for the minicommand variables 0, L, P and T, and also includes the required semicolon (;).

Here is another example, using falling as well as rising notes:

NEW 100 INPUT "INPUT LENGTH: ",L 110 INPUT "INPUT OCTAVE: ",0 120 INPUT "INPUT STEP: ",S 130 FOR N=1 TO 84 STEP S 140 PLAY "N = n; 150 NEXT

Page 201: The IBM Personal Computer Made Easy

160 FOR N = 84 TO 1 STEP - S 170 PLAY "N = n; 180 NEXT 190 GOTO 100

Computer Sounds of Music 1 n

Note that PLAY correctly interprets the letter N as both the com­mand N and the variable n. However, this could lead to confusion and is not recommended.

In music, tunes and rhythms are often repeated. PLAY provides a way to avoid reentering repeated notes, saving keystrokes and stor­age. Here is how its done.

Enter NEW, AUTO, and then type:

10 S$= "ABCDEFG" 20 PLAY "01 T32 XS$; P3 30 PLAY "02 T100 XS$; P1 40 PLAY "03 T200 XS$;

In line 10, you define a string, setting the variable S to the notes A through C. In the PLAY statements, X is used to call S. When PLAY sees the X, it picks up the string named by the following variable, in this example S$, and inserts the string into PLAY just as if you had entered it there. The semicolon (;) after the variable is mandatory. In this example, S$ is called three times with different octaves and tempos. A pause separates each case.

Examples:

PLAY "04 L10 ACB C4 P3 FAG H .. P. PLAY "G# G+ G- N45 T165 A+BE-A30 .. PLAY "ML AFB MS AFB MN AFB PLAY "MF GBE MB GBE MF GBE MB GBE MF GBE TUNE$ = "DEL 1IDE" PLAY "C XTUNE$; BCD 1=6 PLAY "0 = I; BBA"

Now you have tools to create sounds, manipulate them, combine them and vary them all through computer programming. Depending on your interest, see how you can apply computer-generated sounds to enhance other programs, or just create musical effects.

Page 202: The IBM Personal Computer Made Easy

QUICK REFERENCE CHART 13-1

THE PLAY STATEMENT

Command Example Description

On 04 Sets octave for all following notes until changed. n = 0 to 6. Octave 3 starts with middle C. Default is octave 4.

Ln Lll Sets length duration of all notes until changed. n = 1 to 64. Length = (whole note)/n

A thru G ACB Plays corresponding notes A thru G.

An thru Gn C4 Plays corresponding note A thru G for length corresponding to n for one note only. n = 1 to 64

Pn P3 Pause for time corresponding to n. n = 1 to 64. Dura-tion = (whole note)/n

. (period or A .. P. Change length of n or Pause by decimal) 3/2 per dot. For example, if

length of A has been set by Ln, then A ... has length lin (3/2)(3/ 2)(3/2) = (lIn)(27/8)

# or + G#&G+ Sharp G- Flat

Nn N45 Alternative method of specifying a note. Here n stands for a note. Nn says: PLAY note n, and n ranges from 0 to 84. n = 1 corre-sponds to octave 0, note A. n = 2 corresponds to octave 0, note B, and so on up to n = 84 corresponds to octave 6, note C. n = 0 means rest.

Tn Tl65 Tempo. n ranges from 32 to 255. Tempo = n quarter notes per minute. Default is n = 120

ML MLAFB Legato. Note Length = L given in L command.

MS MS AFB Staccatto. Note Length = 3/4 L given in L command.

190

Page 203: The IBM Personal Computer Made Easy

Command

MN

MF

MB

X

Example

MN AFB

MFGBE

MBGBE

TUNE$="DELIDE" PLAY "XTUNE$;"

J = 6 PLAY "0 = J;"

Description

Normal. Note Length = 7/8 L given in L command. Foreground. Each note com­pletes before next note starts. Foreground is the default mode. Background. Notes following MB play while the BASIC pro­gram continues to run. X calls a substring. The substr­ing is a series of commands named by a string variable. Use­ful when a series of PLAY com­mands is repeated in a program. Semicolon is required. Permits use of a variable in place of a constant, n. Allows programs to modify 0, L, P, T, and N. Semicolon is required.

Unless specifically stated otherwise, semicolons and spaces are optional. However, they can be used to make the strings more readable.

191

Page 204: The IBM Personal Computer Made Easy

Chapter 14

Computer Graphics

In this chapter and the next, you will explore the fascinating world of computer graphics. The ability to draw shapes, move them around, color them and otherwise change them opens exciting possibilities to the PC user. IBM has provided some new statements in their BASIC that help considerably in writing graphics programs on a PC. These statements make it easy to draw points, lines, circles, elipses, and to color them in as well.

The first type of graphics we will describe is text graphics. This is a form of graphics that can be produced in the text mode and does not require, but can use, a color/graphics adapter. Later I will treat true graphic statements, those that draw points, lines, boxes, and so on. In this latter mode, graphic statements require a Color/Graphics Adapter Card, but they do not require a color TV or monitor (see Illustration 14-1).

GRAPHICS IN THE TEXT MODE

The graphics described in this section can be produced with either the Monochrome/Printer Adapter or the Color/Graphics Adapter. Any monitor can be used. The graphics is produced in text mode, using the IBM PC graphic characters listed in Appendix 2. This character set contains a number of useful and intriguing shapes and symbols. Upon first seeing them, your reaction is likely to be: What possible use can these odd shapes have? But the odd shapes can be used to design forms, graphs, and anything else your imagination can conjure up.

To demonstrate the use of graphic characters, you will write a program to draw a border on the screen. Not very exciting, you might

192

Page 205: The IBM Personal Computer Made Easy

Computer Graphics 193

Illustration 14-1 Computer Graphics. Whether for business or entertainment, graph­ics livens things up. The monitor on the left provides color graphics with 560 X 240 line resolution. The monochrome monitor on the right displays graphics with an amber color screen. The objects on the lower left are the new micro-floppy disk drive and a 3" cartridge, storing 1 megabyte, unformatted. (Photograph reproduced courtesy of Amdek Corp., Elk Grove Village, IL.)

think, but you will note that the same technique can be used to create forms and graphs.

The technique consists of selecting the right graphic characters and then stringing them together. Look in Appendix 2 at the characters numbered 200, 201, 187, and 188. These will form the lower left, upper left, upper right and lower right corners of the border. Now, look at numbers 205 and 186. These are the elements of horizontal and vertical lines.

Any character in the set can be displayed on the screen using:

PRINT CHR$(n)

Page 206: The IBM Personal Computer Made Easy

194 THE IBM PERSONAL COMPUTER MADE EASY

An n is the ASCII number (ASCII code) given in Appendix 2. CHR$ is a BASIC function that gives the character a string character asso­ciated with the ASCII number. Thus CHR$(200) will create the lower­left-hand corner of the border.

Enter NEW, AUTO 400, and then type:

400 REM * * * SCREEN BORDER * * * 410 PRINT CHR$(11) 'HOME CURSOR 420 PRINT SPC(5) 'LEFT MARGIN 430 FO R I = 1 TO 70 440 PRINT CHR$(205); 'TOP LINE 450 NEXT 460 PRINT CHR$(187); 'UPPER RIGHT CORNER 470 FOR 1= 1 TO 24 480 PRINT CHR$(29); CHR$(31); CHR$(186); 'RIGHT SIDE 490 NEXT 500 PRINT CHR$(29); CHR$(31); CHR$(188); CHR$(30) 'BOnOM

RT. CORNER 510 REM NO SEMICOLON AFTER LAST PRINT RETURNS CURSOR

TO LEFT SIDE, DOWN 1 LINE 520 PRINT SPC(5) 'CURSOR STAYS ON SAME LINE FOR SPC OR

TAB 530 FOR 1=1 TO 70 540 PRINT CHR$(205); 'BOnOM LINE 550 NEXT 560 PRINT CHR$(30) 'UP ONE LINE, BACK TO LEFT SIDE, AND DOWN

ONE LINE 570 PRINT SPC(4) 580 PRINT CHR$(200); 'BOnOM LEFT CORNER 590 FOR I = 1 TO 21 600 PRINT CHR$(30); CHR$(29); CHR$(186); 'LEFT SIDE 610 NEXT 620 PRINT CHR$(30); CHR$(29); CHR$(201) 'UPPER LEFT CORNER

AND FINIS! 630 GOTO 630

For 40 column screens, change as follows:

In Lines 420 and 520, change SPC(5) to SPC(1) In Line 570, change SPC(4) to SPC(0) In Lines 430 and 530, change 70 to 38 Add Line,

505 PRINT CHR$(30); CHR$(30)

Page 207: The IBM Personal Computer Made Easy

Computer Graphics 195

The key to this program is control of the PRINT statement and the use of the cursor-movement characters 29, 30, and 31 to position the PRINTing. When PRINT values are followed by semicolons, repeated PRINT statements march across the screen, building up a pattern of print characters.

Vertical lines require that you move down (or up) and left after each PRINT with 31 (or 30) and 29.

Enter CLS and RUN the program. You should see a border of closely spaced double lines around the screen.

This program was developed using cut-n-paste methods. It is not a particularly elegant program as is, but it demonstrates the use of several graphic characters. You can improve it by reducing the num­ber of statements and by using LOCATE statements in place of 29, 30, and 31 to position the cursor.

Now we are going to "paste" this program onto the menu created earlier. To do this, we must SAVE this program as an ASCII file. Do this by entering:

SAVE "FORM", A

The second quote is a must. Now enter:

LOAD "MENU (or whatever name you used to save the menu)

With the menu loaded, enter:

MERGE "FORM"

When you LIST the result, you will find the ~ORM program added to MENU. You have now learned how to build larger programs out of smaller programs. Before running, change line numbers as follows:

350 to 700 360 to 710 370 to 720 LIST and change 360 in line 720 to 710

Then enter:

DELETE 350--370, and 630

Page 208: The IBM Personal Computer Made Easy

196 THE IBM PERSONAL COMPUTER MADE EASY

This puts the changed lines at the end and removes line 630. Now RUN it. It works, but there are some problems. The heading has been erased in 40-column screens, or is outside the border in 80 columns; the menu is too close to the right side of the border in 40-column screens; and the EXIT line is outside the border. All this is easily fixed by going into the program and entering the necessary changes. Test your skills by doing this yourself.

Notice how the border enhances the menu and gives it a profes­sional look. To test your form design skills, add a double line just under the menu heading, using ASCII character values of 185 and 204 for connectors. Now see if you can create a bar chart using graphic characters 219 through 223, 179 and 176 (see Illustration 14-2).

Illustration 14-2 Graphics in Text Mode. This display was created using the text graph­ics available on bOth the monochrome printer and color/graphics adapter. (Color Monitor is courtesy of Amdek Corp., Elk Grove Village, IL. Color Monitor is Amdek Color II)

Page 209: The IBM Personal Computer Made Easy

GRAPHICS IN THE GRAPHICS MODE

The graphics mode is set by entering:

SCREEN 1 (for Med Res graphics) or SCREEN 2 (for Hi Res graphics)

The COLOR Statement in the Graphics Mode

Computer Graphics 197

The COLOR statement in graphics mode controls color only in medium-resolution graphics (SCREEN 1). (See Figure 14-1.)

In high-resolution graphics, and with noncolor monitors, the COLOR statements still can be used, but only foreground and back­ground values are affected, as will be demonstrated.

Color is used in conjunction with the following graphic statements: PSET, PRESET, LINE, DRAW, CIRCLE, and PAINT (see Figure 14-2).

COLOR first sets up one background color and one of two sets of

Point (0, 0)

200 Rows in Both Res

1------320 Columns in Med-Res -----i

640 Columns in Hi-Res Point (319,0) /----- ------1 or (639,0)

o

Point (X, Y)

Point (0, 199) Point (319, 199) or (639, 199)

Figure 14-1 Screen Addressing for Graphics

Page 210: The IBM Personal Computer Made Easy

198 THE IBM PERSONAL COMPUTER MADE EASY

colors for the foreground. These sets are called palettes because they provide three colors from which the following statements can choose. Thus, the actual foreground color is chosen in various graphic state­ments from a palette selected in the previous COLOR statement. All this will become clear in the following examples and discussion.

Examples of the COLOR statement follow. Enter them in the direct mode and in a program loop of about 100 passes. Enter color 0,1 for normal.

FORMAT' COLOR """~

COLOR,O COLOR, 1 , , EVEN: ODD: Selects Selects

/aletteO palett~

Figure 14-2 Color Selection

Color Statements:

PSET OR

PRESET OR

LINE OR

CIRCLE OR

PAINT OR

DRAW

Page 211: The IBM Personal Computer Made Easy

Computer Graphics 199

The format for the COLOR statement is: COLOR background, palette. Here are some examples:

COLOR Statement

COLOR 4,6

COLOR ,9

COLOR I+B

COLOR 15, 3 + F

COLOR 0

DRAWING POINTS

Description

4 specifies a background color of red. Background colors can range from 0-15 as described for COLOR in the text mode. 6 is an even number, specifying palette 0. Palette 0 has these colors

Color 1 2 3

Palette (/) Green Red Brown

No background color is specified. The previously se­lected background color is retained. 9 is an odd number, specifying Palette 1. Palette 1 has these colors:

Color 1 2 3

Palette 1 Cyan Magenta White

Sets background color to the computed value 1 + B, where B must be given a value in a previous state­ment. Palette is not specified, so previous value is retained. Sets background to high-intensity white. Palette is set from the computed value 3 + F. 3 + F must be between 0 and 255. If 3 + F is even, Palette o is chosen. Background reset to normal. Palette not changed.

Start with the simplest geometric form-the point. You can draw, or plot, points to display mathematical function or just to draw a curve on the screen.

Page 212: The IBM Personal Computer Made Easy

200 THE IBM PERSONAL COMPUTER MADE EASY

The PSET Statement

PSET enters a point on the screen of a specified color. Color ranges from 0 to 3 in Med Res, selecting the color from the current palette. In Hi Res, use 0 for dark and 1 for light. With noncolor monitors, only foreground and background are applicable. PSET has this format:

PSET (column,row),color

Color can be omitted. Enter in immediate mode (you must be in graphic mode with SCREEN 1 or 2):

PSET (1,1) PSET (25,40),2 PSET (200,200),1

Think of columns and rows as X and Y coordinates, remembering that screen numbering always starts from the upper left-hand corner. Decreasing Y will move points up rather than down, as is usual with X-Y coordinates.

Experiment with PSET. Enter SCREEN 1 and then type:

AUTO 100 100 CLS 110 REM PSET EXPERIMENT 120 KEY OFF 130 COLOR 0,1 140 PRINT 150 PRINT 160 FOR C = 3 TO 0 STEP -1 170 PRINT ·COLOR = ·C 180 FO R I = 1 To 320 190 PSET (1,1),C 200 NEXT 210 STOP 220 NEXT

The inner FOR ... NEXT loop, lines 180 to 200, displays a row of 320 points along row 1 of the 320 X 200 dot, medium-resolution display area. STOP interrupts the program to let you see the results of setting: background = 0 (black), palette = 1 (odd), and color = 3 (white). Each time you enter CONT, the outer loop changes color: to 2 (magenta), then 1 (cyan), and finally 0 (background). You can

Page 213: The IBM Personal Computer Made Easy

Computer Graphics 201

then go back into the COLOR statement on line 130 to try other COLOR values by using the edit keys.

Note that unlike the LOCATE statement, PSET does not affect the cursor position; the PRINT function is independent of the points being displayed.

Notice that if you are using a non color monitor, color = 3 is the best value in the PSET statement. The color can be left blank, re­sulting in a default to 3. Try it. If you delete the color from PSET, you must also delete the preceding comma (,).

Now fill the whole graphics area to see how much room you have. Enter:

10 CLS: REM "Fill Graphics Screen" 20 KEY OFF 'Turn off last line 30 FOR J = 1 to 200 40 REM 50 REM 60 FOR 1=1 TO 320 70 PSET(I,J) 80 NEXT I 90 NEXT J 100 STOP RUN

You can see that the PC provides just about a full screen of graphics. With this program, you also can see one of the weaknesses of the BASIC language: It is slow. Thus, despite its ease of use, this is one of the reasons that so many programs are coded in other languages.

Get out of the endless loop in line 100 by entering Ctrl-Break, and set the screen for high-resolution graphics with SCREEN 2 in the direct mode. Set I for 1 to 640 in line 60. Now RUN it. Note how the densely packed points increase the brightness of the display.

The PRESET Statement

PRESET is used to erase (RESET) what PSET hath writ. For this, PRESET uses the same format as PSET, but its default is different. PRESET defaults to 0 (black) when the color parameter is left out; PSET defaults to 3 (white).

To the previous program, add the following lines:

75 PRESET (1-10,J-3)

Page 214: The IBM Personal Computer Made Easy

202 THE IBM PERSONAL COMPUTER MADE EASY

When this is run, PRESET goes into action when J reaches 4 and I = 11. Note that PRESET doesn't mind out-of-bound values. Both 1-10 and J-3 are negative at the beginning; PRESET ignores this. Can you explain the vertical column on the far right that this program produces?

Change line 75 to:

75 PSET (1-10,J-3),0

PSET can do the same thing as PRESET simply by specifying background color. Whether PRESET or PSET is used, the important point is that the ability to erase what has been written is the key to producing animated graphic displays.

The following example shows how to set points on the screen rel­ative to a previous setting (relative form). This is like a relay, with each statement passing its position to the next statement, which then increments (plus or minus) the values.

Enter:

10 CLS 20 PSET (1,200) 'Absolute form for coordinates 30 FOR 1=1 TO 200 40 PSET STEP (1, -1) 'Relative form for coordinates 50 NEXT 60 GO TO 60

In this program, first, a point at 1,200 (absolute form) is set, and then moved in increments of 1, - 1 (relative form) by using STEP with PSET. When you RUN the program, is the direction of the line what you would expect on the basis of the signs of the increments?

DRAWING LINES

By specifying two points, the LINE statement can draw a line between them. By specifying two opposite corners, the LINE state­ment can draw a rectangle between them.

By specifying a color, the LINE statement can draw a colored line or fill a rectangle with the color.

Page 215: The IBM Personal Computer Made Easy

Computer Graphics 203

The LINE Statement

Clear screen with, CLS, and KEY OFF. Enter:

LINE (99,75) - (150,180)

This statement draws a diagonal line, sloping down and towards the right. The first parentheses (99,75) is the starting point of the line. It specifies column 99, row 75.

The second parentheses (150,180), is the end point of the line. It specifies column 150, row 180.

Columns and rows start counting at the left and top of the screen, respectively. The first column or row is 0, not 1. The maximum column number in medium res graphics is 319; in high res graphics, 639. The maximum row number in both graphics is 199. Using the X, Y conventions, X designates a column and Y designates a row, so the LINE statement can be written:

LINE (X1 ,Y1) - (X2,Y2)

Xl, Y1 is always the starting point, and X2, Y2 is always the ending point, irrespective of whether Xl, Y1 are larger or smaller than X2, Y2.

Experiment with the LINE statement on your screen. Enter it with the cursor keys and change the starting and end point values. You will notice some striking variations in the appearance of the lines, depending on the slope. This is an unfortunate but necessary result of the way the lines must be built up from discreet, fixed-dot positions on the screens, instead of making smooth continuous connections.

Line Limits

Enter SCREEN 1, KEY OFF, and then type:

LINE (160,100)-(319,100)

This operation draws a line from the center of the screen at the starting point (160,100) to the farthest right-hand column at the end point (319,100). Now go back into LINE with the cursor and change 319 to 400. When this is entered, LINE does not send an error message for an out-of-bounds value; it performs the statement up to the limit of 319.

Page 216: The IBM Personal Computer Made Easy

204 THE IBM PERSONAL COMPUTER MADE EASY

Change the values in the above LINE statement to test the other three boundary values (use negative numbers for top rows and left­hand columns). You will find that out-of-bound values are the maxi­mum values allowed by LINE. This can make some programming tasks easier, but you have to be careful that you are not unknowingly working with out-of-bounds values.

Connecting Lines

The LINE statement can be used to display a series of connected lines by specifying only the final point of each line. Enter the first line in a series this way:

LINE (300,190)-(200,100)

(We will be using direct mode so hit ENTER key after each entry.) Now, using the edit keys on the original LINE statement, delete

the starting point and enter the following end points one after the other. Be sure to leave in the hyphen when you delete.

LINE -(230,150) LINE - (240,5) LINE - (0,199)

Write a program that uses the connecting feature of LINE to draw rectangles or any other figures that meet your fancy. Note that an entry on the same row as line points will erase these points. Also, all line points to the right of the cursor are erased if the backspace key ( +- ) is pressed.

Coloring Lines

Line color can be specified in the LINE statement. It comes right after the end point specifications.

Enter CLS and then type:

LINE (20,45)-(300,70),1 LINE (20,50) - (300,75),2 LINE (20,55) - (300,80),3 LINE (20,60) - (300,85)

Page 217: The IBM Personal Computer Made Easy

Computer Graphics 205

With a color display, colors 1, 2, and 3 are selected from the active palette, 0 or 1. With a non color display, color 3 produces a bright line and colors 1 and 2 produce equal intensity subdued lines. With no color specified, LINE defaults to color 3. Be sure to delete comma after the last parentheses.

Erasing Lines

Lines can be erased by coloring them the same as the background. Background color is 0, so you can erase any line color by changing the specification to 0.

The ability to erase lines is an important part of any program in which you move objects around.

Moving Lines

Here is a simple example of a program that moves lines around. The READ statement provides a useful way to store positions to which you wish to move objects. Enter SCREEN 1, NEW, CLS, AUTO and then type:

10 CLS 20 DATA 20,50,250,25,35,55,100,200,319 30 DATA 250,55,20 40 READ Y1 , Y2 50 FOR 1=1 TO 10 60 LINE (X,Y1) - (X,Y2),0 70 READ X 80 LINE (X,Y1)-(X,Y2) 81 FOR J = 1 TO 500 'DELAY LOOP 82 NEXT J 90 NEXT 100 RESTORE 110 GO TO 40

For a smoother motion, use the FOR statement and a constant increment of X.

10 FOR 1=1 TO 310 20 LINE (X,20)-(X,150),0 30 X=X+1 40 LINE (X,20) - (X, 150)

'Erase old line 'Advance X one point 'Write new line

Page 218: The IBM Personal Computer Made Easy

206 THE IBM PERSONAL COMPUTER MADE EASY

50 NEXT 60 X=0 70 GO TO 10

'Reset to restart

This program demonstrates a common problem when working with loops. Everything works well until you exit from the loop, and then the last line is not erased because line 20 never gets to it.

The solution is easy. Change line 20 to write the new line and line 40 to erase the old line. Line 40 becomes:

40 LINE (X -1,20) - (X -1,150),0

Many fascinating displays can be generated just by incrementing line-end points. Use both positive and negative increments.

Making Boxes

To draw a box, add a B to LINE:

LINE (10,20)-(60,150)"B

Note that since color was left out, defaulting to color 3, a comma had to be added, to tell LINE that B means box, not a color.

To fill a box with color, add F after B:

LINE (20,40)-(100,180),2,BF

Guess what you have to do to erase the box. Try running the cursor through a colored box.

Moving Boxes

Here is a program that shows you how to move a box.

NEW 10 CLS 20 FOR 1=1 TO 100 STEP 5 30 LINE (10+1,20)-(60+1,100),0,BF 40 LINE (15+1,20)-(65+1,100),3,BF 50 NEXT

Page 219: The IBM Personal Computer Made Easy

Computer Graphics 207

Line 30 erases a box, Line 40 draws the next box. Since you are moving this box, the program correctly exits the loop without erasing the last incarnation of the box.

How significant is the difference between medium-resolution and high-resolution graphics? The following program provides a test pat­tern with which the two can be compared.

A Test Pattern

Enter NEW, SCREEN 1, KEY OFF and then type:

10 REM TEST PATIERN 20 CLS 30 LINE (0,0) - (319,0) 40 LINE (0,0) - (319,100) 50 LINE (0,0) - (319,199) 60 LINE (0,0) - (159,199) 70 LINE (0,0) - (0,199) 80 GO TO 80

The first item in parentheses specifies column number; the second, row number. Line 30 specifies a horizontal line that is, a line that runs from column 0(X), row 0(Y) to column 319, row 0. Line 40 specifies a sloping line; line 50 specifies a diagonal from center to corner; line 60 another sloping line; line 70 a vertical. Note that rows and columns range from 0-199 and 0-319, respectively.

When this program is run, a noticeable difference can be observed in line appearance, depending on the line angle. The line generated by line 40 is the most jagged. Switch to high-resolution graphics with SCREEN 2 and compare test patterns after increasing all 319 entries to 639 and the 159 entry to 319.

A comparison of medium- and high-resolution graphics reveals no significant difference in line appearance. Text, however, is more com­pact in high res and is, therefore, more suitable for labeling graphs.

There are many uses for graphics. For example, they are used in electronics, architecture, aircraft, music, mathematics, and business. Each category has different operational requirements. As of now, the personal computer is most suited for generating business and math­ematical graphics. Many useful displays can be generated for these fields with a modest amount of programming.

Page 220: The IBM Personal Computer Made Easy

Chapter 15

Advanced Graphics

The statements described in this chapter all require Advanced BASIC. Although they do not provide any results that cannot be achieved with the graphics statements discussed previously, Ad­vanced BASIC does make it much easier to produce certain shapes and to move or orient these shapes. For example, imagine construct­ing an ellipse with PSET statements. The CIRCLE statement dis­cussed in this chapter, however, lets you draw an ellipse using just one statement

In this chapter, you will be drawing shapes on the screen and writing programs. When you write program lines, it is important that no extraneous data left over from previously drawn objects be in the same line. Otherwise, BASIC will become confused, returning a mes­sage of either syntax error or unpredictable results. These problems can be easily avoided by using one of the following methods:

• Clear the screen before writing a new program with CLS . • First, clear each line by hitting the Esc key. • After writing the line, clear out all extraneous data by keying

Ctrl-End.

THE DRAW STATEMENT

The DRAW statement provides a set of minicommands that, when grouped together in a string, generate shapes on the screen. (Refer to Quick Reference Chart 15-1 as you read this section.) You did something similar to this when you used the LINE statement to connect lines, but DRAW has greater built-in functionality. 208

Page 221: The IBM Personal Computer Made Easy

Advanced Graphics 20t

Here is an example of DRAW. Be sure you are in Advanced BASIC and that the screen is set to SCREEN 1. Enter:

10 CLS 20 DRAW "U80 R80 080 L80 E80 080 H80

U, R,D, and L stand for up, right, down, and left, respectively. This is a string, so it must be preceded by a quote. E stands for a diagonal going upwards from left to right. H stands for a diagonal going upwards from right to left. Notice that all distances in this DRAW statement equal 80. Now RUN the program.

Were you surprised to see that the diagonals meet the corners, even though their length is equal to the sides. Evidently, in computer graphics, the Pythagorean theorem does not apply. Can you explain this paradox? (Hint: The graphics area is made up of discrete dots.)

DRAW has two other diagonal movements that were not used in the above example:

• F moves diagonally down and from right to left • G moves diagonally down and from left to right

If not instructed otherwise, DRAW always starts at the midpoint of the graphics screen, which is 159,99.

The previous commands allowed movement in fixed directions. There is a general purpose minicommand in DRAW that allows move­ment in any direction. It takes the form:

M X,Y

M X, Y tells DRAW to move an X amount horizontally and a Y amount vertically. X and Yare absolute values, unless preceded by plus or minus signs, in which case they are increments, that is, they become relative values.

10 CLS 20 DRAW "020 M300,5 020 M - 50, + 75 L89

Scale Factors

DRAW provides a scale factor that can be used to increase or decrease the values specified by U, D, L, R, E, F, G, Hand M in relative mode only. The scale factor command is Sn, and n can be

Page 222: The IBM Personal Computer Made Easy

218 THE IBM PERSONAL COMPUTER MADE EASY

any value from 1 to 255. The actual scale factor is % of n or 0/4. The default value when 5n is not specified is n = 4, which provides a default scale factor of 1. This means that the actual amounts moved are the amounts specified in the commands. For example, DRAW "51 D20 will reduce D20 by Y4.

Insert 51 through 58 in the previous DRAW statement at various points. Can you account for what you see?

Try scaling the square with diagonals that were discussed previ­ously.

Locating Objects on the Screen

Now try:

10 CLS 20 DRAW "BM0,199 U80 R80 080 L80 E80 080 H80

The square has moved to the lower left corner. It was put there by the BM0,199. B (for blank) turns off the writing of any command to which it is attached (the next following command), which, in this case, was an absolute move to the lower left-hand corner. This is how you locate graphic objects at any point on the screen.

Try to think of DRAW as having an invisible cursor that moves in response to DRAW's minicommands. Then M functions like a LO­CATE statement in moving the cursor to an initial, or new, position.

Returning to Square One

There are times when you will want to make several moves, all from the same point. The minicommand N provides for this:

DRAW "NU30 ND30 NL30 NR30 NE30 NF30 NG30 NH30

N-prefixing any move command causes the invisible DRAW cursor to return to the starting point. N is useful whenever you are creating screen objects with symmetry about a point.

Rotations

The minicommand A rotates through a right angle between 0 and 270 degrees.

Page 223: The IBM Personal Computer Made Easy

Advanced Graphics 211

DRAW "A0 U40 A1 U40 A2 U40 A3 U40

This statement draws a box, using only the U (up) minicommand, because A rotates 90 degrees at each step. Rotation is as follows:

A0 Zero degrees Al 90 Degrees A2 180 degrees A3 270 degrees

By writing the degree as a variable, An, a program can draw a complex shape using only one DRAW statement.

Color Control

Cn sets the color of the following draw minicommand. In medium resolution, n ranges from 0 to 3 in the usual way, that is, the color is selected from the current palette as determined by the last previous COLOR statement. In high res, n can be 0 or 1 (dark or light) or 2 or 3 (dark or light). 0 is always the background color and can be used in a manner similar to the minicommand B. In medium res, 3 is the foreground and the default value when no Cn command is used.

DRAW "C0 U40 C1 R40 C2 D40 C3 L40

If you do not know why only three sides of the square are visible, try changing C0 to C2. .

Using Variables With DRAW

All this, although useful, will be of limited value in a computer unless you can introduce variables, thereby allowing the computer to calculate the distance moved in the minicommands. IBM BASIC provides for the use of DRAW variables. However, the way they are used with a minicommand is different from the way you have been using them in statements. First, choose a name for the variable: I, UP, LEFT, SCALE, and so on. Then, set the command equal to the variable name right inside the DRAW statement. Finally, place a semicolon (;) after the variable.

Page 224: The IBM Personal Computer Made Easy

212 THE IBM PERSONAL COMPUTER MADE EASY

For example:

10 CLS 20 FOR 1=1 TO 100 30 DRAW "U=I; R=I; D=I; L=I; 40 NEXT

You can do something similar with the following:

10 CLS 20 FOR 1=1 TO 100 30 FOR J=0 T03: DRAW "A=J; U=I; 40 NEXT J 50 NEXT 1

Or try this:

10 CLS 20 FOR 1 =4 TO 255 30 DRAW "S=I; U1 R1 D1 L1 40 NEXT

Now add STEP 20 to line 20:

20 FOR 1 = 4 TO 255 STEP 20

Try other step values. The use of STEP in FOR ... NEXT loops lets you create all manner of patterns.

Using Subroutines With DRAW

In drawing screen displays, a pattern or object may be repeated a number of times. Obviously, it would be helpful to avoid having to repeat the commands each time something is repeated. The DRAW statement provides for this by allowing you to set up a string of minicommands-a substring or subroutine of DRAW-that can be called repeatedly in various parts of your program. The letter X fol­lowed by the string variable is used for this purpose. For example:

10 CLS 20 SUB$= "U=Y; R=Y; D=Y; L=Y; 30 Y=35

Page 225: The IBM Personal Computer Made Easy

Advanced Graphics 213

40 X=45 50 DRAW "XSUB$; BM + =X;, + =X; XSUB$; BM+ =X;, - =X; XSUB$;

BM - =X;, + =X; XSUB$;

Don't worry about line 50 going past the right margin and wrapping around to the left. Just keep tying as if nothing had happened. And don't try to correct split commands with spaces.

Line 20 defines a subroutine, which you will recognize as being a square.

Line 40 defines a variable X used in the Move command. Line 50 is a little complex. Here is what it does:

• The letter X calls SUB$ each time it is used. When DRAW sees an X in its string of commands, it looks at the following string variable name (SUB$), picks up the corresponding string in Line 20 and inserts that string in its list of commands.

• Since SUB$ is a variable, a following semicolon is mandatory. • The M (Move) commands are all preceeded by a B, suppressing

display of their movement. The M destination points, row and column, are both variables and are both equal to X, which is set at 45 in line 40.

• All M commands are relative moves, because a plus or minus sign preceeds the equal sign.

• Each appearance of a variable in M must be followed by a semicolon.

• The two variables in M must be separated by a comma.

All these rules are simply restatements of things you already have learned. They can be summarized briefly:

• All variables must be followed by a semicolon (;). • Equal signs (=) are used to set commands designating a vari­

able. One equal sign is required for each variable in the M command.

Note that DRAW allows the use of X as a variable, even though X has special meaning in calling subroutines. However, it is probably wise to avoid this use of X.

As a demonstration of what can be done with loops, do not enter NEW, but add to the preceeding program:

45 DRAW "BM0,5 60 GOTO 50 'USE CTRL-BREAK TO LEAVE THIS LOOP

Page 226: The IBM Personal Computer Made Easy

214 THE IBM PERSONAL COMPUTER MADE EASY

In lines 30 and 40, set X = 5 and Y = 5. See what a few lines of code can do. You can do more. Try your hand at creating patterns. When you are tired of boxes, go to the next section to learn about circles.

THE CIRCLE STATEMENT

Circles are widely used components of graphic displays. The IBM PC provides a simple means of producing circles-and parts of circles. This method allows greater use of graphics by users at all skill levels.

The CIRCLE statement actually produces elipses. A circle is a special kind of elipse, in which the major and minor axes are equal. Also, CIRCLE allows you to specify that only a portion of an elipse (or circle) be drawn. By combining these features in various ways, many useful graphic objects can be created.

Start by drawing circles at various locations and of various sizes. With screen set to SCREEN 1, enter:

CIRCLE (200,85),70

This draws a circle with its center at column 200, row 85, and radius 70.

If your circles appear elipsoid, disregard this for the time being. When I discuss aspect ratio in a later section, you will learn how to create perfect circles.

With the edit keys, change the radius to produce a series of con­centric circles. What does a circle with a radius of 1 look like? Zero radius?

The next entry in the CIRCLE statement specifies color. In this case, color 2 is requested:

CIRCLE (200,85),70,2

In medium-res graphics, color 2 will be taken from the current color palette, which means palette 0 or palette 1. Remember that the current palette is whatever was selected in the previous COLOR statement.

Color can range from 0 to 3. In both medium- and high-res graphics, o is the background color (nonvisible circle), and 3 is the foreground color. In noncolor displays, color 3 produces normal intensity; color

Page 227: The IBM Personal Computer Made Easy

Advanced Graphics 215

2, subdued intensity; color 1, unpredictable results, and color 0, no display. In high-res, color 0 is no display; color 1, normal; color 2, no display; color 3, normal.

Insert line 10 and add a space in front of the CIRCLE statement to change from the direct to the indirect mode. Hit ENTER with the cursor on line 10, and RUN it using the F2 key. (If you have an 80-column display, enter SCREEN 2 and see the difference. Return to SCREEN 1.)

LIST the one-line program and add to it, by entering:

20 CIRCLE STEP ( - 50,0),50 5 CLS

STEP specifies relative positioning. The smaller circle is positioned at 50 columns less ( - 50) than the larger circle; the row remains the same (0).

At the end of a CIRCLE statement, an invisible cursor goes to the center of the circle. Any relative positioning then is relative to the center of the circle.

After experimenting with this program, try:

5 CLS 10 CIRCLE (200,85),100 20 LINE - STEP(100,0)

Line 20 specifies only the ending point of the LINE statement; the starting point defaults to the invisible cursor position. The STEP command results in the end point being incremented (relative posi­tioning) by 100 columns.

Are you ready for some loops? Then enter:

10 CLS 20 CIRCLE (200,85),50 30 FOR X = 1 TO 100 40 CIRCLE STEP (0,0),50,0 50 CIRCLE STEP ( -1 ,0),50 60 NEXT

Line 20 establishes the invisible cursor at 200,85. Line 40 erases (color 0) the current circle (relative movement (0,0). Line 50 moves the circle left one point ( -1,0) in relation to the previous center.

BASIC is slow, as can be seen when this program is run. With

Page 228: The IBM Personal Computer Made Easy

218 THE IBM PERSONAL COMPUTER MADE EASY

STEP in Line 50 changed to STEP (- 20,0), things move faster, while maintaining a fairly smooth motion.

Slicing the Pie

Pie graphs are often used in business. To create one, you generate sections of a circle:

NEW 10 CLS 20 CIRCLE (200,85),50,3,0,1

Following the color parameter (3) will be the start (0) and end (1) points of the circle, measured in radians. A radian is 57.3 degrees. Thus, the CIRCLE statement says to start drawing a circle at 0 radians and end it at 1 radian. This calls for an obvious loop:

10 CLS 15 FOR C = ° to 6.28 STEP .01 20 CIRCLE (200,85),50,3,0,C 30 NEXT

Try different step values. Here is a useful cut-n-paste method for generating parts of a circle

when you know the shape, but not the angle. Add to the above program:

24 LOCATE 1,1 25 PRINT 'C= • C

Run the program until you see the shape you want. Stop the pro­gram with Ctrl-Brk. (You can always restart with CONT.) The last C printed is the angle you want. Enter it in your program in a CIRCLE statement.

Interchange C and 0 in this program and run. Then insert a minus sign in front of C.

When an end point is negative (except in the case of - 0), you get a line from the center to the end point.

Page 229: The IBM Personal Computer Made Easy

Advanced Graphics 217

Ellipses

Ellipses are drawn by specifying the aspect ratio in the CIRCLE statement. The aspect ratio is the last entry in CIRCLE. When the aspect ratio is 1, the default value, or the ellipse, becomes a circle. If the aspect ratio is less than 1, the X-axis corresponds to the radius specified in CIRCLE; if greater than 1, the Y-axis corresponds to this radius.

NEW 10 CLS 20 CIRCLE (200,85),50,3,0,6.28,.2

This works, but you don't have to include unnecessary entries if the default values are acceptable. Leave out the unwanted parameter, but keep all commas, unless the comma is the last entry, in which case, zap it out. Thus, line 20 can be written:

20 CIRCLE (200,85),50,,,,.2

Try this, then change the aspect ratio to 5. You should get the same ellipse rotated 90 degrees.

Everything that has been said about circles applies also to ellipses. You may want to go back and apply some of the circle features de­scribed above to ellipses.

If the circles are not symmetric, you can shape them by playing with the aspect ratio. Entering 1 in the aspect ratio should do the trick for medium-res screens. If not, vary slightly, plus or minus, about l. For high res, start with an aspect ratio of .5 and work from there.

THE PAINT STATEMENT

PAINT is used to color areas on the screen. Any area with a bound­ary can be colored. The area can be the same color as, or a different color from, the boundary. Enter:

10 CLS 20 CIRCLE (200,85),85"" 1 30 PAINT (180,80),2,3

Page 230: The IBM Personal Computer Made Easy

211 THE IBM PERSONAL COMPUTER MADE EASY

Line 30 fills in the circle drawn by line 20. The numbers (180,80) specify a point in the circle. Any point in the bounded area (circle) is all right. It does not have to be the center. The next entry (2) specifies the paint color, that is, the color of the bounded area. This value can range from 0 to 3. 0 is the background color. In medium­res, on color screens, colors 1, 2 and 3 are taken from the current palette, 0 or 1. The current palette is the palette specified in the most recently executed COLOR statement. If not specified, PAINT color defaults to the foreground color (3).

Noncolor screens in medium res show PAINT colors 1 and 2 as subdued brightness, and PAINT color 3 as normal.

In high-res, PAINT colors 1 and 3 are normal, PAINT color 2 is black, but only if the paint color is the last entry in the PAINT statement.

The last entry in PAINT specifies the boundary color. The same rules apply as for above. This entry is not used in high res. It is required on med res without color, if the paint color is 1 or 2. Keep the boundary value = 3.

The nice thing about PAINT is the ease of filling in irregular shapes. As an example of a shape that might be used as a pie chart in business graphics, try:

5 CLS 10 CIRCLE (200,85),85" -1, -6,1 15 CIRCLE (200,85),85,,6,1,1 20 PAINT (180,80),1,3 30 LOCATE 14,22 40 PRINT ·PROFIT" 50 LOCATE 16,19 60 PRINT "FROM OPERATIONS·

The LOCATE statement uses text rows and columns even though the screen is in the graphics mode.

Page 231: The IBM Personal Computer Made Easy

QUICK REFERENCE CHART 15-1

THE DRAW STATEMENT

General Format DRAW "String of Commands"

Examples DRAW "D50 Ll0 U50 R10 H25 G25 F25 E25" DRAW "DI00 M30,60 M +40, -80" DRAW "BDI00 BM30,60 NE50 NH50" DRAW "S2 DI00 S4 A3 C2 R80 XSUB$; XA$;" DRAW "D=DOWN; M+ =X;,- =Y S=SC;

Command Command Example Comments TI~e 8Imbol(s)

Relative Un,Dn,Ln,Rn U50,D50,Ll0,RI0 Up, down, left and move right, n is number

of points moved. Relative En, Fn, Gn, Hn E2,F25,GI00,Hl Diagonals. E:up, right; move F:down, right;

G:down, left; H:up, left; n is number of points moved.

Absolute Mx,y M30,60 Absolute move. Moves move to column 30, row

60. X=0-199; Y=0-319 (or 639 in high resolution).

Relative M ±x,±y M +40,-80 Relative move. Exam-move pIe would move

right 40 columns, up 80 rows.

Control B BDI00 Next command blanked Blanking out. It moves with-

out drawing. Return N NE50 Next command draws, Move but jumps back to

starting point when finished.

219

Page 232: The IBM Personal Computer Made Easy

Command Command Example Comments TI~e 51mbol{s}

Control Ss S2 Scale Factor. S = 1 to Size 255. Multiplies n in

move commands by s/4. Default is s = 4.

Rotate Aa A3 Rotate through 0 to 3 move right angles

(0,90,180 & 270 de-grees) a=0-3.

Control Cc C2 Sets color. c = 0 - 3, Color med resolution.

Current palette used. c = 0 - 1 in high resolution.

Control Xv$; XSUB$ X calls substring V$, Processing DRAW "XSUB$;" where V is a variable

name of any string of valid DRAW com-mands.

Control = Variable; D=DOWN; Sets n,s,a,c,x, or y in processing M+ =X;,- =y; above commands

equal to a variable in the specified com-mand.

220

Page 233: The IBM Personal Computer Made Easy

Appendix 1

Summary and Index of BASIC Statements, Commands, and Functions

Page numbers are included for statements that are described in this book. If no page number is given, the statement was not described in this book, and is probably a specialized statement or one used for advanced program­ming. Refer to the IBM BASIC manual for descriptions on how to use these statements.

Statement Page Description ABS 84 Gives the absolute value. ASC Gives the ASCII code of a character. ATN 83 Computes the arctangent of an angle. AUTO 116 Automatically generates BASIC pro-

gram line numbers. BEEP 183 Sounds a Y4-second beep. BLOAD Disk-to-memory transfer of binary

data. BSAVE Memory-to-disk transfer of binary

data. CALL Calls a machine-language subroutine. CDBL Converts to double precision. CHAIN Transfers to another program. Not in

cassette BASIC. CHR$ 193 Converts ASCII code to internal code. CINT 84 Converts a number to an integer. CIRCLE 214 Draws a circle or elipse. BASICA

only. CLEAR Sets variables to zero or null. Sets

memory and stack space. CLOSE Closes a file.

221

Page 234: The IBM Personal Computer Made Easy

222 THE IBM PERSONAL COMPUTER MADE EASY

CLS 77 Clears screen. COLOR 161 Sets color of foreground, background,

and border. COM Controls trapping of events to a com-

munications adapter. BASICA only. COMMON Passes variables to a chained program. CONT 216 Continues a program after a break. COS 83 Computes the cosine of an angle. CSNG Converts a number to single precision. CSRLIN Gives the location of the cursor. CVI,CVS,CVD Converts string variables to numeric

variables. Not valid in cassette BASIC. DATA 142 Stores numbers and characters for use

by the program, using the READ statement.

DATE$ Enters or gives the date. DEF FN Gives a name to a numeric or string

function. DEF SEG Specifies a segment of memory. DE Ftype Specifies the type of variable to be

used. DEF USR Defines the starting address of a ma-

chine-language program. DELETE 94 Deletes program lines. DIM 146 Specifies the maximum value to be

used by an array subscript. DRAW 208 Provides for drawing objects by means

of a series of minicommands. BASICA only.

EDIT 120 Displays a program line for editing. END 133 Ends a program. EOF Signals the end of a file. ERASE Erases arrays from a program in order

to gain space. ERR Gets error code oflast error. ERL Gets line number where last error oc-

curred. ERROR Simulates or allows you to define your

own error code. EXP 83 Calculates e to a specified power. FIELD Defines a random-file record. Not in

cassette BASIC. FILES 108 Displays directory information. Not in

cassette BASIC.

Page 235: The IBM Personal Computer Made Easy

Summary and Index of BASIC Statements, Commands, and Functions 223

FIX FOR ... NEXT FRE

GET

GOSUB

GOTO HEX$

IF

INKEY$ INP INPUT INPUT # INSTR

INT KEY

KEY(n)

KILL

LEFT$ LEN LET LINE

LINE INPUT

LIST LOAD

LOC LOCATE

84 132

141

129

130

179

136

84 95, 177

109

122 179 118 203

93 100, 173

170

Truncates a number to an integer. Loops a given number of times. Cleans up a string area in memory and tells how much space is available. Reads a random-file record. Not in cassette BASIC. Also reads points on a screen in graphics mode and BASICA only. Branches to a subroutine and provides for return. Branches with no provision for return. Converts a number to a hexadecimal string. Performs an operation if a condition is true. Reads a keyboard character. Reads the byte from an input port. Requests keyboard input by the user. Reads a sequential file. Searches a string for a match with an­other string. Converts a number to an integer. Turns function key assignment display (twenty-fifth line) on and off. Provides for reassignment Controls a GOSUB if a specified key is pressed. BASICA only. Deletes a disk file. Not in casette BA­SIC. Gets the left part of a string. Gets the length of a string. Sets a variable to a value. Draws a line or a box, in graphics mode only. Reads a keyboard line or sequential file into a string variable. Delimitors are ignored. Displays program (listing) on screen. Loads a program from disk or cassette to memory. Gives the current position of a file. Sends cursor to a screen position, de­fines shape of cursor, andturns it on and off.

Page 236: The IBM Personal Computer Made Easy

224 THE IBM PERSONAL COMPUTER MADE EASY

LOF

LOG LPOS LPRINT

LPRINT USING

LSET

MERGE

MIO$ MKI$

MKS$

MKO$

MOTOR NAME

NEW

OCT$ ON COM(n)

ON ERROR

ON ... GOSUB

ON ... GOTO

ON KEY(n)

ON PEN

ON STRIG(n)

83

195

92

Gives the length of a disk file. Not valid in cassette BASIC. Computes a natural logarithm. Gives position of the printer. Characters go to the printer instead of the screen. Provides for formatting of numerical data that LPRINT sends to the printer. Moves data into a random-file record, left justified. Not in cassette BASIC. Merges an ASCII program file on disk or cassette into a program in memory. Gets or replaces part of a string. Converts integers to string. Not in cassette BASIC. Converts single precision to string. Not in cassette BASIC. Converts double precision to string. Not in cassette BASIC. Turns cassette player on and off. Changes the name of a disk file. Same as RENAME in ~OS. Not in cassette BASIC. Deletes any BASIC program in mem­ory. Gives string with octol value. Provides for a subroutine branch, if characters are received on a communi­cation line. BASICA only. Provides branching when there is an error. Provides conditional branching to one of several subroutines. Provides conditional branching to one of several program lines. Goes to a subroutine when one of the function or cursor keys is pressed. BASICA only. Goes to a subroutine when a light pen is activated. BASICA only. Goes to a subroutine when one of the joystick buttons is pressed. BASICA only.

Page 237: The IBM Personal Computer Made Easy

OPEN

Summary and Index of BASIC Statements. Commands. and Functions 225

Prepares for data transfer to and from disk or cassette.

OPEN "COM

OPTION BASE

OUT PAINT

PEEK PEN PLAY

POINT

POKE POS

PRINT PRINT USING

PRINT #-

PRINT # USING

PSET PRESET

PUT

RANDOMIZE

READ

REM RENUM RESET

RESTORE

148

154 217

186

77 124

200 201

142

134 94

142

Prepares for data transmission on a communication line, using the Asyn­chronous Communications Adapter. Not in cassette BASIC. Sets minimum value to 0 or 1 for array subscripts. Sends a byte to an output port. Colors a selected screen area with a selected color. BASICA only. Reads a memory location. Reads a light pen. Plays music, using a set of minicom­mands. BASICA only. Gets the color of a specified screen point. Writes to a memory location. Gets the column at which the cursor is positioned. Writes data on the screen. Writes data on the screen using a specified format. Writes data to a sequential file without compression. Writes data to a sequential file using a specified format. Writes a point on the screen. Writes a point on the screen with background color of 0 as default. Writes data to a random file. Not in cassette BASIC. Also, writes color ob­jects to a specified screen area. BAS­ICA only. Initializes the random-number genera­tor. Reads values stored in a DATA state­ment. Indicates a remark; is not processed. Renumbers program lines. Closes disk files and clears system buffer. Not in cassette BASIC. Sets program line at which READ gets DATA items.

Page 238: The IBM Personal Computer Made Easy

226 THE IBM PERSONAL COMPUTER MADE EASY

RESUME

RETURN

RIGHT$

RND

RUN SAVE

SCREEN

SCREEN

SGN

SIN

SOUND

SPACE$

SPC

SQR STICK

STOP

STR$

STRIG

STRING$

SWAP SYSTEM

TAB TAN

TIME$

141

122

91 100, 172

156

84

83

184

88, 194

84

123

109

88 83

Continues program after an error-re­covery procedure. Ends a subroutine and returns to a calling routine. Gets a portion of a string from the right side. Gets a random number between 0 and 1. Runs a program. Transfers a BASIC program from memory to disk or cassette. Prepares screen for later statements by setting mode, burst, apage, and vpage. When used as a function, it gets AS­CII character code at the specified row and column of an active screen. Produces the algebraic sign of a num­ber. Produces the sine of an angle in radi­ans. Creates a sound of specified frequency and duration. Produces a string of spaces of specified length. Skips a specified number of space in a PRINT statement. Produces the square root of a number. Produces the X or Y coordinate of one of two joysticks. Stops a program and enters the com­mand level. Changes a number to a string, sign in­cluded. Gets status of joystick trigger buttons or controls tripping of these buttons. Selectively generates a string, depend­ing on parameters entered. Swaps the values of two variables. Leaves BASIC and enters DOS com­mand level. Not in cassette BASIC. Tabs to position specified. Produces the tangent of an angle in ra­dians. Sets or gets the current time.

Page 239: The IBM Personal Computer Made Easy

TRON

TROFF USR VAL

VARPTR

VARPTR$

WAIT

Summary and Indel of BASIC Statements. Commands. and Functions 227

For program debugging, prints line numbers as they are executed.

123

Turns off TRON. Calls a machine-language subroutine. Produces a numerical value from a string. Gets the address of the file-control block. Produces a character form of the memory address of a variable. Not in cassette BASIC. Waits for a specified bit pattern at an input port.

WHILE ... Loops while a specified condition holds. WEND

WIDTH

WRITE

WRITE #

157, 159 Sets screen to 40 or 80 columns. Also sets printer line width and other de-vices. Writes data on screen, but handles commas and quotes differently from PRINT. Transfers data from memory to a se­quential file on disk.

Page 240: The IBM Personal Computer Made Easy

Appendix 2

IBM PC Character Set ASCII Codes ASCII Control ASCII value Character character value Character

000 (null) NUL 032 (space) 001 g SOH 033 002 • STX 034 003 • ETX 035 #= 004 • EaT 036 $ 005 + ENQ 037 % 006 • ACK 038 & 007 (beep) BEL 039 008 a BS 040 009 (tab) HT 041 010 (line feed) LF 042 * 011 (home) VT 043 + 012 (form feed) FF 044 013 (carriage return) CR 045 014 n SO 046 015 ~ SI 047 / 016 ~ OLE 048 0 017 • DCl 049 1 018 * DC2 050 2 019 !! DC3 051 3 020 qr DC4 052 4 021 § NAK 053 5 022 - SYN 054 6 023 i ETB 055 7 024 + CAN 056 8 025 ~ EM 057 9 026 - SUB 058 027 - ESC 059 028 (cu rsor ri ght) FS 060 < 029 (cursor left) GS 061 030 (cursor up) RS 062 > 031 (cursor down) US 063 ?

228

Page 241: The IBM Personal Computer Made Easy

IBM PC Character Set 229

ASCII ASCII value Character value Character

064 @ 096 065 A 097 a 066 B 098 b

067 C 099 c

068 D 100 d

069 E 101 e 070 F 102 f

071 G 103 9 072 H 104 h

073 I 105 074 J 106 j

075 K 107 k

076 L 108 077 M 109 m

078 N 110 n

079 0 111 0

080 P 112 p

081 Q 113 q

082 R 114 083 S 115 084 T 116 085 U 117 u

086 V 118 v

087 W 119 w

088 X 120 x 089 y 121 Y 090 Z 122 z

091 [ 123 092 \ 124 093 1 125 094 /\ 126 095 127 L:l

Page 242: The IBM Personal Computer Made Easy

230 THE IBM PERSONAL COMPUTER MADE EASY

ASCII ASCII value Character value Character

128 c; 160 a 129 U 161 130 e 162

, 0

131 a 163 u 132 a 164 ii

133 a 165 N 134 a 166 ~

135 I( 167 <2 136 A 168 e

137 e 169 r-

138 e 170 ---,

139 I 171 Yz 140 172 y"

141 173 142 A 174 « 143 A 175 » 144 E 176 145 iE 177 "::::::::

146 A: 178 :::;:::=::: .:.:.:.:.:.

147 " 179 0

148 0 180 --1 149 0 181 =j

150 " 182 -ll u

151 U 183 -n

152 y 184 ~

153 0 185 =ll 154 u 186 155 ¢ 187 =;J

156 £ 188 dJ

157 l 189 -lJ

158 Pt 190 ..I

159 f 191 --,

Page 243: The IBM Personal Computer Made Easy

IBM PC Character Set 231

ASCII ASCII

value Character value Character

192 L 224 a

193 ...L 225 {3

194 -r 226 I' 195 I- 227 7r

196 228 ~

197 + 229 cr 198 ~ 230 !1

199 I~ 231 T

200 IJ: 232 Q

201 I? 233 -B-

202 db 234 n 203 =;r: 235 6 204 I~ 236 00

205 237 0 206 ..IL 238 E ,r

207 --'- 239 n 208 .JL 240 209 =r 241 ±

210 -rr 242 2

211 lL 243 ~

212 b 244 r 213 F 245 J

214 rr 246 215 11- 247 ::::::

216 +- 248 0

217 ...J 249 • 218 r 250 219 • 251 " 220 - 252 n

221 I 253 222 I 254 • 223 - 255 (blank 'FF')

(Reprinted courtesy of IBM Corp.)

Page 244: The IBM Personal Computer Made Easy

Appendix 3

Reserved Words

Words set aside for use in BASIC.

ABS DEFSNG INSTR AND DEFSTR INT ASC DELETE KEY ATN DIM KILL AUTO DRAW LEFT$ BEEP EDIT LEN BLOAD ELSE LET BSAVE END LINE CALL EOF LIST CDBL EQV LLIST CHAIN ERASE LOAD CHRS ERL LOC CINT ERR LOCATE CIRCLE ERROR LOF CLEAR EXP LOG CLOSE FIELD LPOS CLS FILES LPRINT COLOR FIX LSET COM FNxxxxxxxx MERGE COMMON FOR MID$ CONT FRE MKD$ COS GET MKI$ CSNG GOSUB MKS CSRLIN GOTO MOD CVD HEXS MOTOR CVI IF NAME CVS IMP NEW DATA INKEY$ NEXT DATE$ INP NOT DEF INPUT OCT$ DEFDBL INPUT# OFF DEFINT INPUT$ ON

232

Page 245: The IBM Personal Computer Made Easy

Reserved Words 233

OPEN RESTORE SWAP OPTION RESUME SYSTEM OR RETURN TAB( OUT RIGHTS TAN PAINT RND THEN PEEK RSET TIME$ PEN RUN TO PLAY SAVE TROFF POINT SCREEN TRON POKE SGN USING POS SIN USR PRESET SOUND VAL PRINT· SPACE$ VARPTR PRINT# SPC( VARPTR$ PSET SQR WAIT PUT STEP WEND RANDOMIZE STICK WHILE READ STOP WIDTH REM STR$ WRITE RENUM STRIG WRITE # RESET STRING$ XOR

Page 246: The IBM Personal Computer Made Easy

Appendix 4

Words Generated by Alternate (AL T) Key

To generate the following words, hold down the AIt key and then press the key shown below.

Key Word Key A AUTO N NEXT B BSAVE 0 OPEN C COLOR P PRINT D DELETE Q (no word) E ELSE R RUN F FOR S SCREEN G GOTO T THEN H HEX$ U USING I INPUT V VAL J (no word) W WIDTH K KEY X XOR L LOCATE Y (no word) M MOTOR Z (no word)

234

Page 247: The IBM Personal Computer Made Easy

About the Author

ROBERT RINDER has over 25 years of experience in the computer industry, where he has applied computers in numerous areas of business and govern­ment, including manufacturing, finance and insurance. Mr. Rinder has served as a consultant to major insurance companies and government agencies. He holds several patents in the area of small computers and peripheral devices.

Mr. Rinder has written numerous articles and books on computers. His previous book, A Practical Guide to Small Computers, continues to provide small-computer users with a comprehensive guide to the application of mi­cros and minis in the world of business.

In The IBM Personal Computer Made Easy, Mr. Rinder uses his extensive experience in the computer industry to identify the strategic significance of the IBM Personal Computer and to guide readers into those personal-com­puter applications that they are likely to find most beneficial.