FORTH GUIDE
FORTH SCREENS
If you have started with one of the standard implementations of MVP-FORTH, you will have an option available under the FORTH function, CONFIGURE. Try it.
CONFIGURE <cr>You will be shown the number of drives available and a density code which corresponds to the density of the disk you have on each of the drives. You will note that FORTH starts with drive 0 and increases. For two drives the designations will be DR0 and DR1. Hopefully, these designations will be properly set for your system. If so, simply respond with a carriage return. The function will abort unchanged.
The designation of the drives beginning with 0 is the way the system actually identifies each drive. If your system uses drive A , the A is converted to a 0 for access to the drive. Why not just call it drive 0? Your system may have different densities than in the options give. Later we will see how to modify that.
Return to your operating system with BYE.
BYE <cr>You will need a special disk for use with FORTH. It is called a FORTH SCREENS disk. This disk will have no system files on it. It can only be used from FORTH. This is why the distribution FORTH SCREENS disk cannot be read by your system. You cannot use your system COPY command but DISKCOPY will work. Later you will learn how to duplicate the distribution FORTH SCREENS disk with FORTH. For now you will not need it.
Note: In the Documentation for this disk you will see how to use SCREENS in DOS files and even use text files as a source for MVP-FORTH applications.
Use the operating system on your computer to format a new disk. Label that disk FORTH SCREENS.
You can use your newly formatted FORTH SCREENS disk in any drive. For the present, load FORTH from a copy of your MVP-FORTH system disk in drive 0 ( drive A ). Then remove the SYSTEM disk and replace it with your newly made FORTH SCREENS disk. At this point, it is necessary for the System Disk and the Screens disk to be in the same format. See if the disk part of the system is working under FORTH.
75 LIST <cr>You should see a screen full of a single character or symbol. When the disk was formatted, a value was placed in each byte on the disk. That byte will print as some symbol or perhaps a lower case e . So far so good. Now see if you can clear the screen of those symbols.
WIPE <cr> 75 LIST <cr>You should now see a blank FORTH screen. At the top is indicated the screen number, 75 . Then 16 blank lines numbered 0 through 15 should appear. Many FORTH programs are written on such screens.
A number of editors are available to write on FORTH screens. You do not have to learn a whole new editor at this point. The MVP-FORTH kernel has a very rudimentary editor. It is not a full screen editor. It consists of a single command. Now try it.
0 PP ( THIS IS LINE 0 ) <cr> 75 LIST <cr>Everything following the single space after PP will be placed on line 0. The PP is a mnemonic for put except P has already been used.
If all is well, you should see the text following the PP on line 0. If not you might try again. Should that fail, try reading the documentation supplied with your program. In a worse case Mountain View Press will support you.
Now save the screen to disk.
FLUSH <cr>The drive should activate and the screen will be written to disk. Check to be sure.
75 LIST <cr>The disk drive should again activate and you will see the screen with what you had written on line 0.
Try writing other material on other lines.
FLUSH <cr>The screen will be saved back to the disk. Without FLUSHing the screen to disk, it only remains in a RAM buffer. Now reLIST it. Remember you will need to tell LIST which screen to list by entering the desired screen number first.
75 LIST <cr>If you forget to enter the screen number you will get an error with SCR marked and the message EMPTY STACK. The function needs a value which you did not give it. Try again.
This rudimentary editor is very useful. You can enter any keystroke which is not possible with some other editors. However, there is no way to correct part of a line with it. You must type the line over. If you are a good typist you can do that as fast as you can move the cursor. It will encourage you to keep the lines short. Later you will learn about the line EDITOR available in MVP-FORTH, but this is not the time to learn another editor. Stay with the rudimentary one for now. Ultimately, you may want to add one of the screen editors available for your system.
Each line on a screen contains room for 64 characters. You do not need to use them all. In the example we placed the comment on line 0 within parentheses. It is a custom to place a name for each screen on line 0. Often it is convenient to include your initials and a date. This will help you keep track of what is on each screen.
70 80 INDEX <cr>This will list line 0 from each of the screens 70 through 80. It makes a sort of table of contents. You will note that all screens except for 75 contain only the format character. Line 0 of screen 75 has its title.
Make the title you choose, meaningful to you. Perhaps you can list the functions you have defined on that screen.
The comment is placed in parentheses so that it will be treated as a comment when you later load, compile, the screen. Screen 75 has been chosen for example because most disk systems have at least 75 screens. But you can try any screen number you wish. You can check the limit of screens on your disk by doing INDEX through a large number.
75 999 INDEX <cr>You can interrupt the scrolling by hitting any key. Hitting any key again will restart the scrolling. To leave the scrolling, first stop it with a single key, and then hit any key twice in rapid succession. You may have to adjust the delay for the speed of your computer.
The system will list the 0 line of each screen up to the limit on the disk and then stop. INDEX will not go on to the next disk. If, however, you try to list a screen number larger than that on your 0 drive, the system will automatically move on to DR1. You will notice that your second drive activates. It will be better for the present to stay within the range of screens on DR0. You will have to learn to be responsible. There is no safety check on this feature.
MVP-FORTH presumes the programmer is responsible. It will not limit your access to the system and will happily destroy everything if you wish, or even if you only enter the wrong information.
It is often good to use one screen as a directory to the location of material on the other screens on a disk. An early screen number is good for this. On the other hand you do not want to use the first few screens. Those on the zero track of a disk often have some formatting information about the disk. It is best not to write over this information. Therefore you might make screen 10 a directory.
10 LIST <cr> WIPE <cr> 0 PP ( DIRECTORY ) <cr> 1 PP 75 A TEST SCREEN <cr> FLUSH <cr> 10 LIST <cr>You could now define a word to show you your directory.
: DIR 10 LIST ; <cr> DIR <cr>There is no need to indicate a carriage return at the end of each line. By now that should become a reflex for you. You will also have learned by this time that each FORTH function is separated by a space.
Now return to screen 75 and enter the function CRS which you defined earlier.
75 LIST WIPE 0 PP ( CRS ) 2 PP : CRS ( n --- ) 3 PP 0 4 PP DO CR 5 PP LOOP ; FLUSH 75 LISTYour definitions should be neatly laid out on a screen. Several conventions have been used but they are only conventions. You are free to adopt them or not as you see fit. But you and others will probably find the screens easier to understand later if you adopt some clear conventions.
The placement of the name of the function being defined on line 0 within parentheses as a comment has also been mentioned. Place it within parentheses so that it will not be loaded later. Especially during development, but even later extra spaces and white space can be used to advantage to set things off.
Line 1 is left blank as a matter of style. It serves to set off the beginning of a definition on the next line.
On line 2, the colon definition is started in the first column. When the screen is loaded later this line will perform exactly the same function as when it was entered interactively.
Following CRS, the name for multiple carriage returns, you have another comment within parentheses. This is not necessary but later it will serve to remind you what you did. The "n" indicates that a number must be entered before the name of the function. The parentheses indicate that this information is just a comment and is not necessary for the definition.
The placement of a 0 on line 3 all by itself seems like a waste of space. But it is necessary if we are going to start the DO structure on the beginning of a line. Again, the 0 is the beginning of the range of iterations for the structure. The number of iterations will have been entered before the command.
Start structures as DO on the beginning of a line. It makes them easy to spot. You will note that the entries on all lines within a definition have been indented 3 spaces. The spaces make the definition easier to read. Then enter the functions to be performed within the DO ... LOOP . Each DO must be paired with a LOOP. It is easy to see if this is done if the LOOP is entered with the same indent as the DO.
Finally, end a colon definition with a semicolon.
In order not to lose what you have done, it is a good idea to FLUSH a new screen back to disk immediately. You can then LIST it again and see what you have done. At this point, since the lines are so short, it is very easy to retype any line using PP which appears incorrect. Then FLUSH the corrected version.
Now, you can test the screen.
75 LOADLOAD compiles what is on the selected screen just as if you had entered it interactively at the terminal. Writing a definition on a screen and loading it is almost as interactive as writing it at the terminal. The time to load a screen is usually only a fraction of a second. Though this is not strictly interactive programming, it is certainly much faster than the old way of editing, compiling, loading and running. When you have made a mistake or wish to change you program, it is quicker to edit the screen and then load it than it is to interactively type in the definition again.
The response will be the familiar OK --- that is, if all is well. If not you will get an error message showing the screen number and line number where the error occurred. Then you can reLIST the screen, use the rudimentary editor to make the necessary corrections, FLUSH and LOAD the screen again.
Next debug the routine. Perhaps the definition of the function you wrote would LOAD, but will it do what you wanted?
Now you can repeat a series of commands you used earlier:
PAGE 12 CRS 37 SPACES ." HELLO" 12 CRSThe old program should come out the same.
Try writing the program as a colon definition on screen 76. Follow the example above. Put each function on a separate line. Perhaps you can include the number on the line with CRS and SPACES. The ." HELLO" can be on a separate line. Gradually, you will learn to think in FORTH.
76 LIST WIPE 0 PP ( HELLO ) 2 PP : HELLO 3 PP PAGE 4 PP 12 CRS 5 PP 37 SPACES 6 PP ." HELLO" 7 PP 12 CRS 8 PP ; FLUSH 76 LISTIf what you entered is correct, you can LOAD it:
76 LOADThis lesson is a little long, but there are a few more related functions to learn. If you wanted to have several programs which would put different messages in the middle of the display you could just modify the screen 76. But you might want to keep that screen too.
76 77 COPY FLUSH 77 LISTA copy of screen 76 is now present on screen 77. You can now edit this screen by changing the name of the function and the message. FLUSH that one too.
The copy function is trivial. The buffer containing screen 76 is simply renumbered 77. FLUSH then writes the newly numbered screen to the disk.
Next time you load FORTH from your copy of the MVP-FORTH system disk, be sure to replace it with your FORTH SCREENS disk before proceeding. Then you can reload your programs.
75 77 THRUThese relatively simple FORTH commands and techniques should serve as examples for you to expand upon. An exact functional definition of each of the resident commands can be found in ALL ABOUT FORTH. You have saved your new definitions on your FORTH SCREENS disk.