Understanding Apple Basic 1983.Pdf
Total Page:16
File Type:pdf, Size:1020Kb
~ :.9E UNDERSTANDING J.S.A / _/ APPLE® IAlll: Step-by-step Instruction for the Beginner An Alfred Handy Guide E:':] by Richard G. Peddicord UNDERSTANDING APPLE® BASIC by Richard G. Peddicord AN ALFRED HANDY GUIDE Computer Series Editor: George Ledin Jr. ~ ALFRED PUBLISHING CO., INC. ~ ~ SHERMAN OAKS, CA 91403 This Handy Guide is not a publication of Apple Computer Inc. and should not be used in lieu of the instruction manuals that accompany their products. All information regarding Apple computers may not be accurate or completely up to date. Editorial Supervision: Joseph W. Cellini Cover Design: Paula Bingham Goldstein Copyright © 1983 by Alfred Publishing Co. Inc. Printed in the United States of America All rights reserved. No part of this book shall be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information or retrieval system without written permission of the publisher. Alfred Publishing Co., Inc. 15335 Morrison St. PO Box5964 Sherman Oaks, CA 91413 Library of Congress Cataloging in Publication Data Peddicord, Richard G. Underst.anding Apple BASIC. (An Alfred Handy Guide) Bibliography: p. Includes index. 1. Apple .// (Computer)-Programming. 2. Basic (Computer program language). I. Title. QA76.8.A662P43 1983 001.64'2 83-15654 ISBN 0-88284-246-3 CONTENTS 1. INTRODUCTION • • . • • • • • • • • . • • • . • • . •. • . • 4 2. ABOUT YOUR APPLE ..•.••.•......•.•....• 5 3. A PRINTING CALCULATOR............... 9 4. LINE NUMBERS AND STATEMENTS • • • 12 5. VARIABLES AND ASSIGNMENT STATEMElfrS •••••••••••••••••••••..•••.•.••• 14 6. INPUTTING DATA FROM THE KEYBOARD • • • • • • • • • • • • • • • • • • • • • • • • • • • • • . • • • • • 16 7. READING DATA FROM YOUR PROGRAM ••••.•••••• ••••••.•••••• •. ••••.. •••• 18 8. A COMPUTERIZED SHOPPING LIST • • • 20 9. ARITHMETIC EXPRESSIONS • • • • • • . • • • • • 22 10. LOGICAL EXPRESSIONS • • . • . • • • • • • • • • • • 24 11. IF ••• THEN .~................................ 26 12. FOR • • • NEXT • • • • • • • . • . • . • • • • • • • . • • • • • 28 13. LOAN AMORTIZATION . • • . • . • • • • • • • . • • • . 31 14. MAGIC SUMS • . • • . • • • • • • • • • . • . • • . • • • . • 33 15. STRING VARIABLES . • . • . • . • . • • • . • 34 16. ONE-DIMENSIONAL ARRAYS • • • . • • • • . 36 17. ACCOUlfrS RECEIVABLE • . • • • • • • • • . • • • • • 38 18. BUBBLE SORTING . • . • • . • • • • • • . • • • . • . • . • 41 19. TWO-DIMENSIONAL ARRAYS • • • • • • • • • • . 43 20. LOW-RESOLUTION COLOR GRAPIDCS • • . • • . • . • . • • • . • . • • • 46 21. HIGH-RESOLUTION COLOR GRAPmcs • • • • • • • • • • • • • • . • • • . • • • • • 48 22. SYSTEM AND EDITOR COMMANDS . • . 50 23. DISK OPERATION • . • • • • • • • • • • • . • . • . • • • 51 24. SEQUENTIAL FILES • • • • • • • • • • . • • • • • • • • . • • • 53 25. WHERE TO GO FROM HERE • • • • • • • • • • • • • 56 26. BIBLIOGRAPHY • • • • . • • • . • • • . • • • • • • • • • • • • • • 57 27. INDEX • • . • . • • • • • • • • . • • • • • • • • • • • • . • . •• • • . • • 58 3 1. INTRODUCTION The Apple II computer continues to be one of the most popular microcomputers of all time. The version of BASIC that has become standard on these machines is called Appleso:ft BASIC, and it is one reason why the Apple is so popular. Appleso:ft BASIC lets you do things that other versions of BASIC do not, such as put many state ments on the same line, use long variable names, and omit certain parameters. Kids like it because it permits lots of variation, and because it is user-friendly. If you want to learn Applesoft BASIC, this Handy Guide is a good place to start. It is very important that you work the examples on an Apple computer and that you try some of the exercises. Otherwise you may for get, or never understand, some of the concepts. Many schools and libraries have one or more Apples. Phone around and ask if you can use one. Many computer stores have Apples, and perhaps even some of your friends have them. And of course you can always buy one. The important thing is to be able to use an Apple when you want to. 4 2. ABOUT YOUR APPLE A great variety of software and hardware are available for the Apple II computer, and its Applesoft BASIC has become one of the more flexible BASICs in operation today. THE SCREEN The Apple II features a high-resolution color screen of 280 columns and 196 rows, with six different colors (black, white, orange, pink, blue, and green) available for each pi:cel, or picture element. This is about the same resolution and color range as the personal game computers on the market today. It follows that you can program games on your Apple II. It is not possible to attain the same speed as these commercial programs, however, because you will be working in Applesoft BASIC, and the commercial programs are written in assembly language, which is faster because it's closer to the machine language itself. The low-resolution screen on the Apple II has 40 columns and 40 rows, and each pixel can be one of 16 different colors from black to white. The reason why you have more choice of color with the lower resolution has to do with the way the color TV signal is generated and how the color image is stored. HOOKING UP YOUR APPLE The configuration that has proven to be most cost effective and useful consists of an Apple II computer with one disk drive connected to a TV set via an RF modulator. The RF modulator converts the Apple's TV signal into the same kind of signal that the televi sion receiver is expecting. Most RF modulators for computers generate an output signal that is picked up on Channel 3 or 4. The first thing you must do before turning on the power is to check the connections on your system. Your Apple II computer has a power cord that plugs into the back (see Figure 2.1). Plug this into a grounded 115- volt AC circuit. If you try to use an ungrounded circuit, the manufacturer's warranty is void, and for good reason. Coming out of the Apple will be what looks like a hi-fi cable, and indeed it has the same kind of plug on the end, a so-called RCA phono plug. This plugs into a little metal box that attaches to your TV set antenna, and to your outside TV antenna. There will be a sliding switch on the box that switches power between the computer and the antenna. This arrange ment permits the family color TV set to be used as your Apple's output device. You may or may not have a disk drive connected to your Apple. If one is connected, so much the better. If one is not connected, do not attempt to connect one using only this Handy Guide. You must use the instruc tions supplied with the drive. You can, however, hook up your Apple II to a TV set and turn on the power to 5 Figure 2.1 Hooking up your Apple//. both. The Apple's power switch is located in the back on the far left. It is a rocker switch; push the top part in to turn the power on. The power light in the lower left corner of the keyboard will come on. THE KEYBOARD A diagram of the Apple II keyboard is shown in Figure 2.2. Your first step is to try out a few of the essential keys. The RESET key is most useful. Try it. You will hear a bleep from the Apple's speaker and the flashing square cursor will be immediately to the right of the Applesoft prompt character, ] . Whatever pro gram you were working on will still be in memory, and whatever shapes you had entered will still be there. In other words, no real harm is done if you press RESET. The SHIFT key works the same as in a type writer: hold it down while you strike a key; the upper case version of the character will be sent to the central processing unit. In Applesoft, you enter characters one at a time and then press RETURN. Until you press RETURN, the machine has no idea what you have typed in. There fore you can make all the corrections you want to a line before sending it centrally. The arrow or cursor keys (on the right side of the keyboard) are extremely useful 6 ~ i' t.:> Resets system ~ I Causes repetition of ~ <t> any key held down I ~ Returns to beginning 'E.. of new line <t> I ::.::::: Hold down while striking Moves right past another key. Nothing will characters ~C"' appear on screen, but I 0 special character will be ---Moves left past ~ sent centrally characters Press for upper case POWER I 48 K I -.l in making corrections, since they move the cursor across text on the screen without changing it. Only when you press another key will the indicated change be made. You will use these keys often. If you want to move the cursor over many char acters, you can hold down the repeat key (REPT) while you hold down one of the arrow keys. This same REPT key will cause any character to be repeated. Some commands that you should be aware of are listed below: HOME Clears text and moves cursor to top left. DEL Put beginning line number after DEL, then a comma, then the ending line number. Every line from begin to end will be DELeted from program. LIST Lists your program. RUN Runs your program. PR#l Enables printer in slot 1. PR#6 Enables disk drive in slot 6. PR#O Disables printer. EXERCISES 1. Play follow the leader with us. Simply do each thing listed below as many times as indicated: a. Press RESET 3 times b. Press SPACE BAR 2 times c. Press RETURN 1 time d. Press your nose 1 time e. Press letter M 10 times f. Press left arrow(+-) 10 times g. Type PRINT ''GOTCHA'' 1 time h. Press RETURN 10 times 8 3. A PRINTING CALCULATOR Applesoft BASIC has a feature that is quite use ful ifyou have some arithmetic calculations to perform. Basically all you have to do is type the word PRINT I followed by an arithmetic expression that the machine can understand, hit RETURN, and the machine will give you the correct answer.