CHAPTER 6: ADVANCED EDITING. HELP menus: You can press ESC anytime to see a HELP screen that reviews the basic editing commands. You can also press F1 from the HELP screen or while editing to use the filing system menu to update a file, print parts of a file, switch to another file, or stop editing. MOVING the CURSOR -- on the line: left or right arrow = move 1 character left or right; End = move to end of this line; Ctrl left/right arrow = move to start/end of line; TAB, Shift-TAB = move to next/prev. TAB position; F2, Shift-F2 = move to next/previous word; MOVING the CURSOR -- up or down: up or down arrow = move 1 line up or down; PGUP/PGDN = move 20 lines up/down; Ctrl-PGUP/PGDN = move to start/end of file; F4 + linenumber = go to this line number in file; Hint: you can use either F4 CR or Ctrl-PGUP to go to the start of the file quickly. Hint: also see SEARCHING for Text, another way to move around in the file. Hint: the HOME key doesn't move the cursor in the file, but it places the line with the cursor near the middle of your screen. It is handy when you are entering text near the bottom of the screen and you want to look ahead a bit as you go. SEARCHING for text: Searching starts with the character just after the cursor position. Press: F3 and enter the text you are looking for. Upper and lower case don't matter. Press CR to start the search. The message 'Ctrl-F3= Replace' or 'Not Found!' will appear. To search for another occurrence of the same word, just press: F3 CR. Hint: to search for text starting from the beginning of the file, do this: F4 CR F3 text CR Hint: you can edit or move around in the file and later search again for the same word last searched with: F3 CR Hint: you can leave a place marker in the file, such as zzzz; later, to return to this point, just search for it: F3 zzzz CR Searching for and Replacing text: After searching for and finding some text, the message: Ctrl-F3 = Replace is shown. If you press Ctrl-F3, you will be asked what to replace the text that you found with: Replace with:_ You can type in whatever you want to replace the text you found. When you press CR, the text is replaced, and you will be asked if you want to find another occurrence of the text you found. If you answer 'Y', and another occurrence is found, you will be asked if you want to replace this one also. You can continue to find and replace many occurrences of the same text by answering 'Y'; you can bypass and not change a particular occurrence of the text by answering 'N' to the question: 'Replace this one?', and you can stop searching for more occurrences by answering 'N' to the question: 'Find Another?'. ENTERING text. TYPING inserts text, pushing the rest of the line over. You can move the cursor past the actual end of a line (which is shown by a shadow-box character). If you type out here, the line is automatically extended with spaces. You can enter text anywhere on the screen without worrying about the actual line length; the shadow-box is there just in case you want to know where the actual end of a line is (some printers might be limited in line width, for example). Hint: END and Ctrl-right-arrow always move to the actual end of line; if your cursor is past the end of line, it will move to the left in this case. Hint: as described in THE BASICS, the editor capitalizes what you type automatically. But if you don't like this, just press F8 to toggle this feature on or off. A NEW LINE is created by typing CR when the cursor is anywhere on a line. A new line is started below, with the same left margin as its upper neighbor. SPLITTING a LINE is done by putting the cursor on the character which is to start the new (2nd) line, and pressing Ctrl-CR. JOINING 2 LINES is done by putting the cursor on the 1st of the 2 lines to join and pressing Ctrl-BS. INDENTING is controlled by F9 and F10. F9(UNDENT) moves the margin of the current line left by 2 spaces; F10(INDENT) moves the margin right 2 spaces. It doesn't matter where the cursor is on the line when you use F9 or F10, so you can move down a program, re-formatting it line by line, quite easily. DELETING text. BS deletes the character to the left of the cursor; DEL deletes the character at the cursor; Ctrl-F2 deletes a word (if the cursor is on a word) or up to the next word (if not); Ctrl-F4 deletes the rest of the current line; Note that F9 (UNDENT) deletes leading spaces, and Ctrl-BS deletes the line separator characters. Deleting entire lines and blocks of lines is done with the cut and paste commands. CUT (Delete lines) and CUT & PASTE (Move lines). As described in the BASICS chapter, you use: F5 to start or end marking text, and move it to the copy buffer; F6 to cut (delete) the block you have just marked; F7 to paste (copy) the text from the buffer to the current location of the cursor. Hint: the last text you put into the buffer stays there until you quit the editor, so you can switch files and copy the text into the new one. Warning: Each time you mark text, it becomes the only text in the copy buffer. So if you are going to move text around, be sure to copy it into the program BEFORE marking the next block of text (because the new block will over-write the old block in the buffer). Hint: in re-arranging text in a program, you can store pieces of text at the end of the program, and later move them to a final location. Hint: you can print the text that is in the buffer with the filing system (see below). THE FILING SYSTEM. F1 brings the filing menu to the screen. The filing system allows you to switch files, make backup copies of a program, print text, and quit the editor, with the most common actions carried out by pressing CR. The commands available are: R to REPLACE (update) a file and RUN it; Q to QUIT the editor; B to BACKUP a file, using any name and any disk drive; S to SWITCH to another file; P to PRINT marked text on the printer. REPLACE means to update the same disk file you started editing with the changes you made in the current editing session, and then compile and run the same program. QUIT means stop editing and leave the editor. If you have changed your file at all since loading it, you will be asked if you are sure you want to quit. BACKUP prompts you for the file name to write the edit file to. You can specify any legal DOS filename, including a drive prefix, and even a full pathname if you want. Afterwards, you stay in the editor, so you can use this command to write an extra copy of your file to another disk, as a backup. You can also select S for SWITCH FILES. The current file will be updated if it has been modified, and you will be prompted for a new file name. Type the new name and CR, and edit the new file. Note that the copy buffer is still intact, so you can move blocks of text between files this way. The 2nd time you select SWITCH FILES, the last file you edited will be the default(suggested) file name, so you can switch between 2 files repeatedly without entering their names more than once. This makes it easy to build a new file from parts taken from other files. The editor keeps track of the line you were on in each file. Finally, you can select P for PRINT BUFFER to send the contents of the copy buffer (the marked text) to the printer. Use this to print out portions of a program for proofreading, etc. Note: File names may include drives and extensions, like a:myfile.txt and may include sub-directory pathnames if you are using them. (If you are not sure what these are, you aren't using them and don't worry about it!) ERROR MESSAGES AND PROMPTS. On the lowest screen line, to the right of 'Press ESC for HELP', is an area used for messages to help you with some commands or warn you of errors that have occurred. First, an explanation of the serious errors: WHAT FILE?? -- the file name you have typed is not a valid PC-DOS file name; check your spelling and try again. FILE TOO LARGE! -- if you try to edit a file that is too large for the editor or your computer's memory, the edit is cancelled after this message. If you edit a file containing TAB characters, the editor converts these to spaces and the file could possibly grow too large during this conversion, with the same result. TOO MANY LINES! -- if you try to edit a file with over 3000 lines, the edit is cancelled with this message. DISK ERROR!! -- this message occurs when attempting to update a file if the drive's door is open, or the disk has too little room on it for the file, or no room in its directory. An additional message is also given to indicate what you should do. Generally, you must fix the problem (switch disks, etc) and try again. When you get this error, you have not updated your disk file yet! Try to do it before quitting the editor, or you will lose the editing you have been doing. CHECK PRINTER! -- this means that your printer is off, or off-line, or otherwise not properly connected or functioning. Fix the problem and re-try the print command. LINE TOO LONG! -- this means that you have tried to make a line longer than 250 characters; the editor can't do this, and you probably didn't want to do it either! Del. all lines? -- this message is given if you try to delete the entire file with the cut command (F6). The editor assumes that you don't want to do this. Block too large. -- given if you try to mark too large a block of text for your copy buffer. This can only happen with computers that have 128K of memory or less. Messages that are less serious and more for guidance are: Low on memory! -- you are within 1000 characters of the maximum file size you can edit. NEW FILE! -- the file with the name you typed was not found on the disk, so the editor assumes you will type in text for a new file of that name. Of course, you might have misspelled the file name, so the editor beeps (in case you are not looking!). Converting tabs. -- the editor found TAB characters in your file and is expanding them into spaces at intervals of 8 columns. LONG lines split -- the file you are editing had lines longer than 250 characters in it, and these lines have been split. This editor is not intended for editing files, such as word processor output, with lines this long, although in a pinch you can split the lines up as you like with Ctrl-CR. Writing... -- the editor is writing a file to disk after an UPDATE command was given. Written. -- the UPDATE operation is complete. Autocaps is on. Autocaps is off. -- these tell state of the auto-capitalization feature. Scrolling right. -- the screen is moving right, following the cursor, and the left-most screen column is no longer column 1 of your file. To return to the left-most 'standard' position, you can use Ctrl-left arrow or ESC-ESC. Printing... -- printing of the copy buffer is in progress. Searching... -- a search command is in progress. Ctrl-F3 = Replace -- a search has found what you wanted; you may, if you like, replace it with text you specify by pressing Ctrl-F3 and following the prompts. Not found! -- a search did not find what you wanted. Note that the search command starts just after the current cursor position, so you may need to return to the beginning of the file before searching to find every occurrence of the text you want. Marking... -- you pressed F5 once. Move the cursor to mark the text you want, then press F5 again. Text in buffer. -- you pressed F5 again, and the text you marked has been copied into the copy buffer. The word TEXT appears on the next-to-last screen line as a reminder. Text deleted. -- you pressed F6 and the marked text has been removed. goto marked text -- you pressed F6 but the cursor was not in the marked text. You can only delete text while the cursor is in the block, so move the cursor into it and try again. mark text first -- you pressed F6 but either you had not marked some text first OR you have done some line-editing since marking the lines. The editor only allows you to delete text BEFORE adding or deleting lines anywhere in the file. No text to copy. -- you pressed F7 but there is nothing in the copy buffer to copy into the file. Text copied. -- you pressed F7 and text was copied from the copy buffer into the file. TECHNICAL SPECS FOR THE EDITOR The editor will run on computers which are compatible with the IBM-PC to the extent of having the same screen memory addresses. This includes all IBM models plus most 'close' compatibles. Dos 2.0 or later is required. BIOS functions are used for cursor and screen mode control; MS-DOS functions are used for keyboard input and all disk and printer I/O. 40 column screens can be used as well as 80. Full Dos 2.0 pathnames can be used for the edited files. Files to be edited must use CR,LF pairs to separate lines. TAB characters in the file will be expanded to spaces; no other characters will be converted, and 'strange' characters in the file will be displayed in the standard IBM character set. Only characters from 32 to 126 ASCII can be entered into files. The maximum line length is 250 characters; longer lines are broken when the file is loaded if necessary. There is an absolute limit of 3000 lines per file. The editor makes use of what memory is available in the computer to create an edit buffer and a copy buffer. In a 128K machine, the edit buffer will be about 60,000 characters, and the copy buffer will be about 10,000. In a larger machine, the copy buffer will expand to 60,000 characters. In a 64K machine, both the edit and copy buffers will be small, about 5000 characters. The editor is named VISED.EXE as distributed; a batch file EDIT.BAT is used to edit VISIBLE-PASCAL files and controls the filing system command to compile and Run the program. The batch file places a '/' after the program file name: VISED demofile/ and this enables the Replace and Run filing option. When used with the companion compiler, the editor will locate errors in the source file automatically. This is done by entering the edit file with '/e' after the filename: VISED demofile/e The editor then inspects BIOS RAM locations for information concerning the line, column, and number of the error that occurred. An error file named ERR.TXT is opened, if present, and the correct error message is read form it and displayed right below the portion of the source file where the error occurred. However it is entered, using the 'R' command exits the editor with an exitcode of 1, which can be read by a .BAT file to decide what to do next. Since the exitcode from the 'Q' exit command is 0, the file RUN.BAT which controls the system ends if the exitcode is 0, and starts the compile and run process if the exitcode is 1. SUMMARY OF CURSOR MOTION COMMANDS cursor-arrow-keys move 1 character up, down, left, right; Ctrl-left-arrow go to start of line; Ctrl-right-arrow go to end of line; End go to end of line; PgUp, PgDn move up or down 20 lines; Ctrl-PgUp, Ctrl-PgDn go to start, end of file; SUMMARY OF EDITING KEY COMMANDS Esc look at help menu; Home place the current line near the screen center; Del delete the character over the cursor; BS (backspace) delete the character to left of cursor; CR start a new line below the current one; Ctrl-CR split the line at the cursor location; Ctrl-BS join the current line with the next one. SUMMARY OF FUNCTION KEY OPERATIONS F1 go to filing system to update, run, quit, switch files, or print parts of a file; F2 move right one word; Shift-F2 move left one word; Ctrl-F2 delete a word or delete up to next word; F3 ____ search for text and optionally replace it; Ctrl-F3 replace text (after finding it with F3); F4 ____ go to line ____. F4 CR = go to line 1; Ctrl-F4 delete from the cursor to the end of line; F5 mark the start or end of a block of text; F6 delete the marked block of text; F7 copy last block marked to the cursor location; F8 toggle auto-capitalization on or off; F9 move the margin left two spaces; F10 move the margin right two spaces. SUMMARY OF FILING SYSTEM COMMANDS R (after EDIT file) Replace a Visible-Pascal file and Run it; R (after VISED file) Replace file and quit editing; Q Quit editing; B Backup to a file with any drive and name; S Switch to another file; P Print the marked text on the printer. CHAPTER 7: RUNNING VISIBLE-PASCAL PROGRAMS To RUN a program you use the part of the Visible-Pascal system called the DEBUGGER -- it helps you find and fix program bugs, or errors. You use it by issuing the command 'RUN myfile' or by using 'EDIT myfile' and selecting 'R' from the editor's filing system menu. The debugger allows you to watch the operation of the program as it runs, to see whether it does what you want it to. The debugger allows you to step through a program, one statement at a time, while watching the program listing to see what statement is being executed, and what the values of program variables are. It also allows you to control how fast the program runs and when it should stop, and allows you to look at the output of the program (if it writes or draws on the screen) as well as the information made available by the debugger. Using it is automatic; the Visible-Pascal compiler creates program files which, when 'fed into' the debugger, automatically make the 'connections' required for all the above to happen. Chapters 2 and 3 tells how to run a program using the debugger. Using these quick introductions, try running a program or two to get the feel of how it operates, and experiment with some of the commands. Then read this chapter, which will describe each of the functions of the debugger in full. The Program and Debugger screens When a program runs it often uses the computer screen to write text or draw graphics. You will want to watch this output as the program runs, to see what it is doing. However, there is other information about a program which can be useful, including a listing of the statements as they execute, the values of program variables, etc. which can also help tell you what your program is doing. The program output and the debugger's information about the program would both ideally have separate screens for display. However, since you probably only have one computer display, Visible-Pascal manages the information coming from the program and the debugger so that you can watch whichever one you want. A command to switch screens is used to view either the program or the debugger output, and Visible-Pascal makes sure that 1) the debugger information is always accurate, and 2) the program output is always accurate and complete, with nothing lost during the times that you are watching the debugger screen. In this way, the two kinds of information can be viewed as separate windows on the computer screen. Pressing 'S' is the command to switch to the other screen. Looking at the values of variables The debugger screen shows a copy (or LISTING) of your program, and looks a lot like the screen looks when you are editing, except for a window at the bottom with summaries of the debugger commands, and some information which is inserted into the listing. The most important of this is the value of all program variables, which is placed between angle brackets on the same line with any variable declaration, like this: YOUR_NAME : STRING; <> COUNT : INTEGER; <<15>> The variable COUNT has the value 15 at the moment, and YOUR_NAME is Harrold. All variables except arrays have their current values right in the listing like this. Local variables also have values if the procedure in which they are declared is being executed. To see the values of variables that are 'off screen', you can use the editing commands (such as PgUp, etc) to look around in the listing. The Home key returns you to the line which is next to execute. The debugger will try to place the variable values at the end of the line with the declaration; if the line is very long, they will be crowded to the right and may overwrite part of your program line. Leave more space (by putting comments on a separate line) if you want to improve the appearance of the program listing in the debugger. Controlling program execution There are several ways to use the debugger to control the execution of your program. One way is to press 'R' for RUN: you will see the program run at full speed, with the program output on the screen. This is essentially like running without the debugger, except that you can always stop the program and return to the debugger to look at variables or single step, etc. To stop a program that is running, just press Ctrl-Break. The program will be stopped and the debugger screen shown. You can switch screens between the program and debugger output with the 'S' key, or do any other command (to be discussed soon). The Debugger Commands R = RUN until BREAK or Checkpoint. The RUN command always puts the program output on the screen and starts the program running at full speed. It continues until one of four things happen: 1. You press Ctrl-Break; 2. The checkpoint line is reached; 3. An error occurs while the program is running; 4. The program finishes normally. Except for the last case, the result is the same: the program is stopped, the debugger is brought to the screen, and you can continue with any available command. The checkpoint line is a line you have selected for the program to stop at; it is discussed below under 'set checkpoint'. If the program stops because of an error, you will be told the reason, and can look around in the program to inspect variables; but the program cannot be re-started from the point of the error. You must re-run it from the beginning. = do 1 line. Pressing the space bar causes the program to execute one statement and stop. This is often called 'single stepping' a program, and lets you follow what it does as slowly as you like. You can inspect variables at any time. If you have some doubt about what your program is doing, single stepping will show you the sorry truth! If you have lots of time, it is the only debugging command you need; other commands are actually time-savers, allowing you to mix some full-speed execution with single stepping. You can single step with either the debugger on the screen (to see the lines of the program as they execute) or with the program output on the screen. You can switch screens (with the 'S' command) to the screen you want, then single step with . Switch screens any time you like. If you single step at a line with a READ or READLN statement, then if the debugger is showing, you will be clearly told that the program is asking for input, and you will be prompted to type it in. Single step the program WORDS to see this in action. If the program output is on the screen, then your program should prompt you for some input, and as you press , you will see the cursor move to the right for each space. This is the time to type in the information your program is expecting. Try this with the WORDS program, too. N = Next line down. The Next line command is a short-cut. If you are stepping through some statements and you don't want to follow a procedure call statement into a new procedure, but want to go to the next line in the procedure you are in, then press 'N' instead of . 'N' will also complete statements like: FOR COUNT := 1 TO 5 DO WRITELN('something'); in one operation, whereas would stop once for each time the WRITELN is executed. Therefore, use 'N' to go to the Next program line after the current one, no matter what the current line is. W = watch the program execute slowly. Watching a program means to execute each statement at a rate of about 1 statement per second, showing you the result on either the debugger or the program screen. It is good for either automatically showing you the progress of the program, or just to run a program in super-slo-mo. You can stop the program anytime with Ctrl-Break, as always. S = Switch to/from program screen. 'S' switches between the debugger screen and the program output screen. It is a good habit to form to switch screens as a program runs, so you can see what it is producing. When you are watching the debugger, all the output from the program is captured and saved until you switch to the program screen; then all the saved output is sent to the screen rapidly. It is possible to save more information than will fit in memory, in which case some program output will be lost. This won't happen if you occasionally switch screens as you debug the program (and in any event, you usually have room for several screens full of output in the buffer). Ins = set, Del = clear the checkpoint. You can set a checkpoint on a program line, which will cause the program to stop and return to the debugger screen when that line is executed. It is used when you want the program to execute at full speed up to a point which you want to examine in greater detail (by single stepping, etc). To do this, just use the cursor keys (up and down arrow, PgUp/PgDn, etc) to move the brackets < > in the left margin of the listing to the line where you want the program to stop. Then press Ins to insert the checkpoint there. A '!' will appear inside the brackets: . There is only one checkpoint at a time, so any previous one set will be cleared. If you want to clear the checkpoint without setting one, press Del at any time. After setting a checkpoint, you can return to the current line by pressing Home. Now if you RUN or WATCH the program, it will stop at the checkpoint line. Of course, if the program never executes the line with the checkpoint, then it won't stop there! Hint: If you put a checkpoint on the last line in the listing, the program will stop after it is done, allowing you to check the final program screen and any interesting program variables. Cursor control keys. To look around in the program and read the listing, or to inspect variables, or to insert a checkpoint, you can use the cursor control keys that cause up and down motion: up and down arrow, PgUp, PgDn, Ctrl-PgUp, Ctrl-PgDn, and Home. They have the same meaning as in the editor, except that Home returns you to the current line that is ready to execute. The left and right motion keys don't do anything; if a long program line is partly off screen right, there is no way to read the rest of it while in the debugger (although you can return to the editor to do so). If the program is very large, the longer lines in the listing may be abbreviated to save memory for the program. Q = Quit, E = Edit : leaving the debugger. If your program executes correctly and completely, it will end and the debugger will exit, like any program would. But you can stop the debugger in two other ways: 'Q' just stops, so you can do something else, or perhaps re-run the program from the beginning; and 'E' goes directly to the editor, and in fact directly to the line you are on, so you can fix the program and re-run it. During the development of a program, you will find it convenient to run, trace, or step the program until an error becomes apparent, then use 'E' to exit directly to the editor, fix the error, and then select 'R' = RUN from the filing system menu in the editor to re-run the program. You can repeat the edit & run process quickly and easily until your program is perfect! SUMMARY OF DEBUGGER COMMANDS R Run program until or checkpoint; Run 1 statement and stop; N run to the Next lower line and stop; W Watch the program run slowly; S Switch between debugger and program screen; Ins,Del Insert and Delete the checkpoint; E go directly to the Editor; Q Quit the debugger, return to DOS; up/down arrow PgUp/PgDn Ctrl-PgUp/PgDn look around in listing; move < > for setting the checkpoint . CHAPTER 8: VISIBLE-PASCAL SYNTAX This chapter is to help you understand the limitations and special features of Visible-Pascal; it isn't a complete Pascal manual or study course. Visible-Pascal is a special version of Pascal, with the purpose of giving the first-time Pascal programmer an easy time writing and programming his or her first programs. Therefore, an easy editor, fast and automatic program execution and running, and a full symbolic debugger with the program operation and variable values easily visible have been supplied at the expense of other possible programming features. For example, Visible-Pascal is not a complete implementation of Pascal; it does not generate programs that run as fast as possible; and it does not include such advanced features as low level machine access and modular program construction and linking. It is an adequate language to allow the writing of interesting and significant programs, however. Disk files can be read and written; strings are included; and the various screen modes possible on the IBM-PC can be used, including the drawing of graphics in color. All these features are fully supported by the debugger. This chapter will describe some of the significant features of Visible-Pascal; the supplied demonstration programs also have useful examples of various features. Pascal Language Features Included & Excluded Visible-Pascal includes the following data types: INTEGER 1, 32000, -55 BOOLEAN TRUE, FALSE CHAR 'a', CHR(65) STRING 'this is a string' Enumerated (MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY) TEXT files with integer, boolean, character, or string components Missing is the real data type. Variables can be both global and local; types can be declared in a TYPE section, and used in variable declarations or in parameter lists. Single-dimensioned arrays with positive indexes are included: ARRAY[1..10] OF INTEGER ARRAY[1..100] OF CHAR ARRAY[1..1000] OF BOOLEAN Four text files are pre-declared: INPUT = standard keyboard input, redirectable OUTPUT = standard screen output, also redirectable CON = screen output, not redirectable PRN = printer output Re-entrant use of procedure and functions is OK, but they cannot be declared FORWARD nor are local procedures allowed. Full parameter passing is allowed, by value or by address (VAR - parameters). These Pascal control statement types are included: IF...THEN... IF...THEN...ELSE... REPEAT...UNTIL... WHILE...DO... FOR...TO/DOWNTO...DO... CASE...OF......END But the GOTO statement is specifically excluded, as encouraging bad habits! Set constants are included, so you can write: IF X IN ['A'..'Z'] THEN... but set variables are not included. Records, pointers, and dynamic memory allocation are not included. The following string procedures and functions are built-in: CHR(int) returns character value of int ORD(ch) returns integer value of char. ch LENGTH(str):INTEGER returns the length of str POS(str1,str2):INTEGER returns the position of str2 in str1 CONCAT(str1,str2) concatenates str2 to str1 COPY(str1,str2,pos,cnt) copies str2[pos]..str2[pos+cnt] to str1 DELETE(str,pos,num) deletes num chars at str[pos] INSERT(str1,pos,str2) inserts str2 at str1[pos] All strings have a maximum length of 80 characters, and a dynamic length of 0 to 80 which is stored as element 0. Thus, to set the length of S, do: S[0] := CHR(LEN); if LEN is the length to set S to. The following additional routines can be used for direct keyboard input: KEYPRESSED:BOOLEAN is true if a key was pressed and its value is waiting in the keyboard buffer INKEY:CHAR function returning the next key from keyboard. Returns keys immediately, without waiting for CR; also returns extended (double) codes for function keys and other special cases. The following routines are supplied to control the screen: CLS clears the screen, homes the cursor CURSOR(X,Y) sets cursor position. upper left = 0,0 SETMODE(M) sets screen mode to one of the following: 0 = black&white, 40 columns; 1 = color, 40 columns; 2 = black&white, 80 columns; 3 = color, 80 columns; 4 = 320x200 color graphics 5 = 320x200 black&white graphics 6 = 640x200 black&white graphics 7 = monochrome display adapter TEXTTYPE(T) sets all characters following to attribute: 0 = normal white on black; 1 = bold intensity 4 = underlined (monochrome adapter only) 5 = blinking 7 = reverse video 8 = invisible TEXTCOLOR(C) sets following characters to color: 0 = black 1 = blue 2 = green 3 = cyan 4 = red 5 = magenta 6 = yellow 7 = white TEXTBACKGR(C) sets the background color as above BORDER(C) sets the border color to colors 0..7, or to colors 8..15 which are light versions PALETTE(X) Graphics only, selects palette 0 or 1 BACKGROUND(X) graphics only, selects color 0..15 as background This routine is supplied for sound production: TONE(NOTE,DURATION) makes a NOTE of DURATION msec. NOTE is 1..15. This routine is supplied to draw graphics on the screen: DRAW(X1,Y1,X2,Y2,COLOR) draws a line from x1,y1 to x2,y2 in COLOR An Outline of a Visible-Pascal Program The following model program will show some of the basic structural parts of a Visible-Pascal program. PROGRAM DEMO; {no program parameters are needed} CONST (* this is an alternative comment form *) INTCONST = 1; BOOLCONST = TRUE; CHARCONST = 'x'; CHARCONST2 = "y"; {either ' or " can be used for quotes} STRINGCONST = 'this is a string constant'; TYPE ATYPE = ARRAY[1..100] OF INTEGER; {only positive indexes} VAR A,B,C : INTEGER; {you can do multiple definitions, but} D : ATYPE; {it's not neat} S1 : STRING; F1 : TEXT; {the file type declaration} PROCEDURE COUNTEMUP(INVAL:INTEGER; VAR OUT:INTEGER); {note value parameter for input and VAR parameter for output} VAR {note local variable with same name as global} D : BOOLEAN; BEGIN D := INVAL > 6; IF D THEN OUT := 12 ELSE OUT := INVAL; END; FUNCTION ANOTHER:INTEGER; {a function returning an integer} BEGIN ANOTHER := ORD(INKEY); {built-in proc., gives next key} END; { from keyboard (a char) } BEGIN {this is the start of the program itself} A := 1; B := 2; COUNTEMUP(A+B, C); {note expression for the value parameter} WRITELN(C); A := ANOTHER; COUNTEMUP(A+C, C); WRITELN(C); WRITELN('all done now'); WRITELN("that's all, folks!"); {note use of ' or " } END. Syntax of Visible-Pascal Identifiers in Visible-Pascal consist of the normal alphanumeric characters, plus the underline character _ which is legal inside identifiers for improved readability. Identifiers can be any length, but must differ from other identifiers in the program in the first 10 characters. Numbers are normal decimal numbers or hexadecimal numbers which are formed by using the dollar sign as a prefix: $F000 for example. Comments are formed by pairs of braces {...} or these alternates: (* ... *). You can put one kind of comment around text that includes the other kind. String quotes can be put in either single or double quotes (' or "), and the alternate type of quote can be included in the string (see the last statement of the example above). The editor automatically capitalizes characters typed except when they are within single or double quotes or comment braces. Note that the alternate comment form (* ... *) does not affect capitalization; for neat programs, use the { ... } form for normal comments, and the alternate form to 'comment out' a procedure or region of the program temporarily. A Visible-Pascal program consists of a PROGRAM statement, a declarations section which consists of any number of CONST, TYPE, and VAR sections, followed by any number of PROCEDUREs or FUNCTIONs, followed by the main program part: a BEGIN ... END block, finally ended with a period. There are no compiler directives, pseudo-comments, or other complications. A PROCEDURE or FUNCTION consists of the heading, including an optional parameter list, and, in the case of a function, a return type, followed by a declarations section and a BEGIN ... END block finally ended with a semicolon. Procedures cannot be nested inside other procedures. Function return values must be simple types: INTEGER, CHAR, BOOLEAN, or enumerated, but not arrays, strings, or files. See the demonstration programs for examples of various procedures and functions. Statements follow the syntax of standard Pascal closely. The CASE statement also allows ranges of case labels to be expressed just like a set: CASE X OF 1..5: STATEMENT1; 6..10: STATEMENT2; END; and their is no OTHERWISE clause in the case statement, as in some Pascals. You should test for legal values of the case selector before the case statement, unless you wish the run-time error trapping to report it for you! Arrays are restricted to a single dimension, and thus an array of STRING is not possible. In addition, the array index cannot be negative; all arrays start with element 0 and go up to the maximum you declare (the minimum array bounds that you specify is ignored). There is no GOTO statement, since it encourages bad habits! RESERVED AND PREDECLARED WORDS IN VISIBLE-PASCAL The following words are keywords in the language, and must not be re-declared by the programmer. AND ARRAY BEGIN BOOLEAN CASE CHAR CHR CONST DO DOWNTO ELSE END FOR FUNCTION GOTO IF IN INTEGER MOD NOT OF OR ORD PRED PROCEDURE READ READLN REPEAT STRING SUCC TEXT THEN TO TYPE UNTIL VAR WHILE WRITE WRITELN There are two predeclared constants: TRUE, and FALSE. There are four predeclared files: INPUT, OUTPUT, CON, PRN. The following are built-in functions: EOF EOLN ODD KEYPRESSED INKEY LENGTH POS CHR ORD PRED SUCC The following are built-in procedures: ASSIGN RESET REWRITE CLOSE CLS CURSOR DRAW TONE CONCAT COPY DELETE INSERT SETMODE TEXTTYPE TEXTCOLOR TEXTBACKGR BORDER PALETTE BACKGROUND Operators are: + - * / MOD AND OR NOT IN CHAPTER 9: TECHNICAL DETAILS AND INSTALLATION Visible-Pascal consists of three major programs: VISED, VISBUG, and VISPAS, which do the editing, debugging, and compiling functions of the Visible-Pascal system. They are fairly small disk files (20-25K), but need considerable memory for internal buffers and so require computers with 128K total memory. Visible-Pascal is actually run using some batch (.BAT) files to control the sequence of execution of the three major parts. For example, the EDIT command executes the EDIT.BAT command file, which executes the editor, and then depending on a return code which the editor gives back to the operating system either executes the RUN batch file or simply stops. The EDIT.BAT file is: echo off (this prevents display of the commands) cls (clears the screen) vised %1/ (edits the file, with / added to command line if errorlevel 1 run %1 (Run the program if return = 1, else quit) The command to use to edit a non-Visible-Pascal file, such as this documentation, is simply: VISED manual.1 this uses the editor directly. The RUN.BAT file also uses return codes to control execution. The following notes will help to understand it. -VISPAS uses standard input and output for the source and code (.COM) files; -VISPAS returns errorlevel 5 if a fatal error occurred (such as program too long), and errorlevel 1 if a syntax error was found; -VISBUG, the debugger, returns errorlevel 1 if the editor is requested, and 0 to just quit; -If Vised is entered with /e on command line, a syntax error will be displayed as the first edit screen. -After a succesful compilation, a .COM file is left on the disk, and the program can be executed without the debugger's aids; for example, to execute WORDS directly, type: WORDS INSTALLATION Programs generated by Visible-Pascal use standard DOS operations for input and output in all cases except graphics drawing, changing screen modes, and making sound. To do standard DOS I/O, a program called ANSI.SYS which is supplied with DOS must be used when the computer is started or reset. The steps required to do this are: 1. Remember to start the computer with a DOS 2.0 or later disk; 2. This disk must have the file ANSI.SYS on it; 3. This disk must also have a file called CONFIG.SYS on it; 4. CONFIG.SYS must have the line: DEVICE=ANSI.SYS included in it (it can have other lines if your system requires). If all the Visible-Pascal files on are this boot disk, then the supplied AUTOEXEC.BAT file will cause the execution of the batch file G.BAT which will give a sign on message to Visible-Pascal and a directory display, after which you are off and running. A separate disk can be used for Visible-Pascal; just insert it in the default drive and type G. CHAPTER 10: DEMONSTRATION PROGRAMS SOUNDS -the first program to try WORDS -another introductory program TURTLE -a simple program to draw on the screen PRETTY2 -a prettyprinter (neatens your programs) BOX -draws boxes SOUNDS2 -a program that makes noise PATTERN -controls cursor position and text attributes COLOR -allows you to set screen mode and text color STRINGS -shows the use of the INSERT string procedure FILEDEMO -writes, then reads a disk file INKEY -shows how to read keys, including function keys TESTCASE -brief program to test CASE error trapping LISTER -creates a listing with line numbers WEATHER -uses boolean function to answer questions MATH -a trivial 4-function calculator KEYDFINE -program to re-define any key on keyboard etc.(there may be more, soon) CHAPTER 11: PRETTY-PRINTING Sometimes your program has lost its nicely indented appearance, due to a lot of editing changes, and while it is easy to use the indent and undent commands in the editor to fix it up, there is a program supplied with Visible-Pascal that does this for you, if you prefer. PRETTY1 is a program which reads a file, which should be a valid Pascal program, and creates another file which has been neatly indented and auto-capitalized. To use it to neaten up a file called 'myfile', you would do: PRETTY1 newfile The arrows are the commands for using standard input and output under DOS 2.0. Done this way, a file called 'newfile' will be created and will be the neatened version of 'myfile', which is not changed by the process. If you want, you can then copy newfile to myfile and then erase newfile. Note that using standard output can be useful; you could, for example, do: PRETTY1 prn in which case the neatened file goes directly to the printer. Do not, however, make the input file and the output file the same! Dust will fly if you do... PRETTY2 is the text of a program which can be RUN by Visible-Pascal. You can customize this program if you want a different format for your programs. The use of standard input and output is not compatible with stepping the program with the debugger, so at the first debugger menu, Quit; then type: PRETTY2 newfile to run the program without the debugger. If you just type PRETTY2 you will have to type in the program, line by line; as you do so, each line will be re-typed with the correct indenting on the screen. Type F6 CR to send and end-of-file to the program. CHAPTER 12: KEYBOARD RE-DEFINITION If you don't like the way certain keys are used, in the Visible-Pascal editor or in many other programs, you can fix things to your liking with programs like KEYDFINE, a demonstration program which re-defines the Ctrl-A key to mean ' := ' , a key sequence you use a lot in Pascal. The IBM technical manual has a chapter on using extended screen and keyboard control, which gives some hints on how to do this. For now, RUN KEYDFINE; press 'R' at the debugger menu. Now try pressing Ctrl-A and see what prints on the screen. You can define any key to be any sequence of characters or other keys, and you could make a second program that reversed, or undid, the actions of the first, allowing you to re-define keys when using one program, but not changing the key definitions permanently. ----------------------------------------------------------------------------- This disk copy provided by THE PUBLIC (Software) LIBRARY P.O. BOX 61565 HOUSTON, TX 77208 Send self-addressed envelope with two stamps for the latest library listing and monthly public domain software newsletter.