THE VISIBLE-PASCAL MANUAL (C) Copyright 1984, William Hapgood all rights reserved William Hapgood Associates 10 Sycamore Road Wayland, MA 01778 PREFACE VISIBLE-PASCAL is user-supported software. While it is copyrighted by the author, you are authorized and encouraged to copy and distribute the disk with the Visible-Pascal program files on it, provided that you do not distribute any files that have been modified, and that you distribute all the files on the disk. If you find it useful, you are encouraged to send a contribution ($35 suggested) to the author. If you include your name and address, you will receive a future update. Comments on features you would like to see in Visible-Pascal or reports on program bugs or other problems are always welcome, too. REQUIRED EQUIPMENT You can run VISIBLE-PASCAL on IBM-PC (or compatible) computers, including the IBM-PCjr, with 128K of memory, at least 1 disk drive, and DOS 2.0 or higher. If you write programs that use graphics, then a graphics display adapter is required (this is built into the PCjr). You CAN use, if you want: both mono and graphics adapters; a printer; or more than 1 disk drive, including a hard disk or RAM disk. An 80 column display is suggested, but not required. TABLE OF CONTENTS CHAPTER 1: INTRODUCTION CHAPTER 2: GETTING STARTED CHAPTER 3: LET'S RUN A PROGRAM CHAPTER 4: SCREEN PLAY CHAPTER 5: AN INTRODUCTION TO EDITING CHAPTER 6: ADVANCED EDITING CHAPTER 7: RUNNING VISIBLE-PASCAL PROGRAMS CHAPTER 8: VISIBLE-PASCAL SYNTAX CHAPTER 9: TECHNICAL DETAILS AND INSTALLATION CHAPTER 10: SUMMARIES OF DEMONSTRATION PROGRAMS CHAPTER 11: PRETTY PRINTING CHAPTER 12: CUSTOMIZING THE KEYBOARD CHAPTER 1: INTRODUCTION Pascal is a programming language that is being used more and more today, both in education (for example, the College Entrance Examination Board offers an advanced placement test based on Pascal) and in industry (many programs you see in computer stores were written in Pascal). Pascal is both well-structured (which means that the logic of the program you want to write can be easily written in Pascal) and powerful (which means that large and complex programs can be written in it). It is a good idea to learn Pascal: it is a good example of what programming is about; and if you choose to become a prog 1. I recommend that you make a copy of the Visible-Pascal disk, and keep the original put away 'just in case'. To make a copy, you will need to run the DOS program called DISKCOPY. To do this, after you see A> on your screen a) put your DOS disk (version 2.0 or higher) in drive A; b) type DISKCOPY A: B: c) follow the instructions for putting disks in your disk drives. The Source diskette is the Visible-Pascal disk; the Target diskette is the new disk. If you need help, your DOS manuals will help you do this; the procedure differs a little depending whether you have 1 or 2 disk drives in your computer. 2. Now you need to put the operating system files onto the Visible-Pascal disk that you will be using. To do this, after you see A> on your screen a) put your DOS disk in drive A; b) if you have 2 disk drives, put your new Visible-Pascal disk in drive B; c) type SYS B: d) type COPY COMMAND.COM B: e) type COPY ANSI.SYS B: If you are told to switch disks in steps c, d, or e (this will happen if you have only 1 disk drive), follow the instructions. 3. Re-boot the computer by pressing Ctrl-Alt-Del. If you have all the required files on the disk, you should see a welcome message and a list of the demonstration files that are on the disk. If you have a problem at this point, read chapter 9 on installation. CHAPTER 3: LET'S RUN A PROGRAM In this chapter I will show you how to start VISIBLE-PASCAL and how to RUN and EDIT a simple program, and what happens when the program contains an error. You will run a program called SOUNDS that comes with Visible-Pascal. Start by placing your Visible-Pascal working disk (the one you made in chapter 2) in drive A of your computer. If the computer if off, turn it on; if the computer is already on, press Ctrl-Alt-Del to reset it. You should see a welcome message, a list of program files that are on the disk, instructions on how to print this manual, and a request for your command: Command? A> When you see this, Visible-Pascal is ready for you. FIRST TIME THROUGH THE SOUNDS PROGRAM: stepping through 1 statement at a time. Type: RUN SOUNDS and then press carriage return . Now you will see Visible-Pascal get the program SOUNDS ready to run. First it checks for errors; then, if there are no errors it shows you a copy of the program with the first line that will execute highlighted. There is a menu of commands at the bottom of the screen; we will learn some of them in this chapter. Pascal, like any language, has grammar rules that you have to follow to write correct programs. I won't try to teach you the Pascal rules in these chapters - there are some good books that can help you with this. I will help you see how programs execute and how to use Visible-Pascal to learn what your programs are doing. As you look at the program SOUNDS, notice the line that is highlighted: DURATION := 500; This line is the way Pascal tells the computer to make the variable DURATION take on the value (become equal to) 500. Notice that on the 4th line of the program the variable DURATION is declared to be an integer; when a program starts, all integers are given the value 0, and this value is shown inside angle brackets to the right of the declaration: DURATION : INTEGER; <<0>> Visible-Pascal shows you the current values of variables by putting the value on the screen like this automatically. You can run the program one line at a time and see what happens at each step. To do this, press , the space bar, once. The highlighting moves to the next line, and you see that the value of DURATION has indeed changed from 0 to 500: DURATION : INTEGER; <<500>> Press once more and see what happens to the value of NOTE. Now the line that is highlighted is: TONE(NOTE,DURATION); This statement uses the TONE command which is part of Visible-Pascal; TONE needs two pieces of information to work: a NOTE and a DURATION of the note. This statement shows the way this is written using Pascal's rules. Press . Did you hear the note? If your computer's speaker is working, you should! Continue to press through the rest of the program until the line Program complete. appears. As you use to step through the program, watch the value of NOTE change, and listen to the tone that is produced at each TONE statement. SECOND TIME THROUGH THE SOUNDS PROGRAM; Watching a program run in slow motion. Type: RUN SOUNDS again. Again Visible-Pascal gets the program ready to run. You know how to step through the program one statement at a time with the space bar, so this time try a new command: press 'W', which stands for 'Watch the program'. Visible-Pascal does the stepping for you, and you can watch the program run in slow motion. Notice how the value of NOTE in the 3rd line of the program changes. THIRD TIME THROUGH THE SOUNDS PROGRAM; Running at full speed. Type: RUN SOUNDS again. Now you will try the R for Run command, which runs the program at full speed without giving you the special Visible-Pascal aids. Press 'R' and listen to the program execute. You see only a blank screen because Visible-Pascal doesn't display a program when you Run it, and the SOUNDS program doesn't write anything on your computer screen itself. Soon, however, you will see how easy it is to put statements in a program that write to the screen. FOURTH TIME THROUGH THE SOUNDS PROGRAM; learning to edit by making mistakes! To learn to write your own programs you must learn how to create and modify programs like SOUNDS. You can start by modifying SOUNDS like this: Type: EDIT SOUNDS Now instead of Visible-Pascal getting SOUNDS ready to run, you will use the editor to make changes in the program. The chapters on the editor will explain how to use it fully; for now, we will use just a few commands to change the SOUNDS program and re-run it. The editor shows you the SOUNDS program, much as it did when running it, except that there are only two lines of menu information at the bottom of the screen. The editor uses the underline blinking cursor to control where you make editing changes; right now, it should be under the 'P' of PROGRAM on the first line of the screen. To add characters at this location, all you need to do is type, so try typing 'X' and a space. PROGRAM becomes X PROGRAM; since this violates one of the rules of Pascal (namely, that all programs begin with the word 'program'), your program is no longer correct. Let's see what happens when you try to RUN it. To run a program after editing it, do the following: 1) Press and you see a menu of editing commands; 2) Press the function key to use the filing system; 3) Press 'R' to select Replace and Run. Visible-Pascal will check the program for errors, as before, but this time it finds one and puts you back editing, with an error message and a pointer to the place where the error was discovered: X PROGRAM SOUNDS; ^ -----Error at or before this line:-------------- 'PROGRAM' expected. Correct the program and RUN it again! Visible-Pascal is pointing to the word 'X' and saying that it expected to find the word 'PROGRAM' at this point. To correct this error, delete the character 'X' by pressing the key once. Now re-run the program by doing the same three steps you did before: , , and 'R'. Now the program should run correctly as it did at the beginning of the chapter. In this chapter you learned how to RUN a program, and how to EDIT one; you learned how to step through a program with , how to WATCH a program, and how to RUN one at full speed. You learned how to insert and delete characters with the editor, and how to fix an error and re-run the program. In the next chapter, we will see some more ways to RUN a program, and see how a program can write on the computer's screen. CHAPTER 4: SCREEN PLAY When you write programs, you will often want to print things on the computer's screen and have the program use things that you type at the computer's keyboard. In this chapter, we will use a small program called WORDS to learn how to do these operations. You will also learn more about running programs. To get started, let's type: RUN WORDS The program that is displayed on your screen uses several statements that write on the screen; it also reads information from your keyboard. To start, type . Since the highlighting moved down a line, the line: WRITELN('this is the WORDS program;'); should have executed. However, it says to WRITE a LiNe on the screen, and you don't see any new line of text on the screen, do you? Well, the reason is this: Visible-Pascal is using the screen to show you the program and the variables and the command menu; there is no place to put the line that the program is supposed to WRITE! And here is the solution: Visible-Pascal uses one 'screen', and the program that is running uses another. You can switch between them whenever you like; Visible-Pascal keeps track of the information that is on each screen, so that you don't have to. There are two 'information screens' in use, and either one of them can show on your computer's 'physical screen' as you wish. To switch from the screen you see now (let's call this the command screen) to the one with the results of the program that is running (let's call this the program screen), just press 'S'. You should see the line: this is the WORDS program; press 'S' again to see the command screen. Press 'S' some more to get used to it; when a program is writing information to the screen, watching both the command and program screens by switching between them like this is very useful. Switch to the command screen; press again; switch to the program screen and see the new line added to it. Step through the program with until the highlighted line is: READLN(COUNT); Switch to the program screen; it looks like the program is asking you to type in a number, doesn't it? Switch back to the command screen and press one more time. The lower menu region is replaced with this: ------------------------------------------------------ Program is requesting input! ------->_ which is your cue to type in the number that the program wants. You must also press at the end of typing stuff for a READLN statement. Until you type , you can back-space to correct errors; the sends your number, etc. to the program. Note now that on the command screen, the variable COUNT has taken on the value that you typed in. Switch to the program screen; your number is there, too. Switch to the command screen and step the program along through a FOR statement, which is used to do something several times. The program is not 'stuck' on one line; it is executing that line the number of times that you typed in. You can switch to the program screen anytime to check on what is happening. RUN WORDS again, and this time give the 'W' command to Watch the program. Everything you did above will happen automatically. But you will never get to see the program screen if you let the program run automatically until it is finished. One way you can get to see the program screen is to press when the FOR statement is executing. This stops the program, and you can switch screens then. You will learn another way, later. Finally, RUN WORDS again, and this time give the 'R' command to run the program at full speed. Now you see only what the program was written to do, with no aid from Visible-Pascal. Congratulations! You are doing quite a lot with Pascal, especially if you have not yet read the chapters on editing or running programs or on the syntax of Visible-Pascal. At this point you can either continue reading this manual, or jump right in, using the built-in menus to guide yourself. There are other demonstration programs listed in chapter 10 you can try; and you can edit any of the programs if you wish. However, note that Visible-Pascal does not contain every language feature of full Pascal, so you will need to skim the syntax chapter sooner or later. You will also want to read about the extras in Visible-Pascal that are missing in standard Pascal, such as color, graphics, and sound! CHAPTER 5: AN INTRODUCTION TO EDITING. The Visible-Pascal editor makes the job of writing and modifying Pascal programs really easy. These instructions are in two parts: this introduction tells you how to begin, and ADVANCED EDITING tells about powerful features that make editing larger programs a breeze. You should read it after you feel comfortable using the basics. PRELIMINARIES. These instructions assume that your keyboard is an IBM-PC one; for the PCjr, you have to learn some special key combinations to use for the function keys, etc. For all computers, we will use the following abbreviations for some of the keys: CR means press the carriage return key; BS means press the backspace key; ESC means press the escape key; DEL means press the delete key; F1 means press function key F1 (or F2..F10); CTRL-x means hold the Ctrl key and press x (like SHIFT); ALT-x means hold the Alt key and press x. STARTING and LEAVING the editor. To edit a file that is named (or will be named) 'MYFILE', just type EDIT MYFILE 'MYFILE' can be an old file (already on your disk) or new (not yet there). If it is an old file, the editor will present you with its first page (screenful), and you can begin editing. If it is new, the editor will beep at you and give you a blank screen to write on. To leave the editor when you are done, press function key F1 to bring the filing system menu to the screen. (Forgot which key?? Press ESC for some memory jogs!) Now press 'R' to Replace your disk file with an updated copy, leave the editor, and Run your program. ENTERING text. The first step in writing a program, using any editor, is to type in your program. Use CR to start a new line, and BS to backspace over typing mistakes as you go. The blinking cursor shows where the next letter you type will go; the 'shadow' cursor shows where the end of the current line is. --Note that CR starts a new line under the start of the one above; this AUTO-INDENTING makes neat program writing easy. You can adjust the margin with spaces or BS; following lines will line up until you change the margin again. --Note that the editor also AUTO-CAPITALIZEs for you. On each line, all letters are capitalized except between comment braces {...} or between quotes '...' or "..." . This makes your program statements easily distinguishable from comments with no work on your part. MOVING the CURSOR. There are several ways to move the cursor around in your file. The left, right, up, and down arrows are all you really need, but other keys like PGUP (page up) and PGDN (page down) make larger moves and are handy. CTRL-left arrow and CTRL-right arrow (or END) move the cursor to the start and end of the current line, respectively. --Note that if you move the cursor or type past the right edge of the screen, the editor scrolls right to keep the cursor on the screen; lines that are partially off-screen to the left are clearly marked. Use CTRL-left arrow to return to the 1st column position; the right portion of the line (past the edge of the screen) will also be cleared marked. --If pressing the cursor-arrow keys puts numbers into you file, instead of moving the cursor, you much press Ctrl-NumLock to activate the cursor control function keys. DELETING and MOVING text. You can backspace (BS) back over text; or, move the cursor to the letter to remove and press DEL. Hold it down for longer deletions. To delete 1 or more entire lines, use the cut and paste keys F5, F6, and F7. F5 marks the line where the cursor is, highlighting it. Move the cursor up or down to mark more lines. F5 pressed again finishes marking text and puts a copy of it in a special copy buffer; the word 'TEXT' on the status line tells you a copy has been stored. F6 deletes the marked lines. Now, if you wish, you can move the cursor elsewhere and press F7 to put a copy back into the text. It's hard to make a serious mistake since each time you delete lines, you can always copy them back if you want! To delete one line, just press F5-F5-F6. That's all you need for now. See the EXTRAS chapter for commands that make your editing even easier, such as: 1. search for words and change them if you want; 2. find a line by number; 3. delete words or part of a line; 4. switch between files; 5. move text between files; 6. print parts of your file; 7. center your work on the screen.