OPERATING SYSTEM INTERFACE
This is an advanced section. Most FORTH users will have no need to interface with an underlying operating system. Parhaps you are one of those who should skip this section.
The Language FORTH in its earliest days grew out of the need for an efficient operating system. With the expanding availability of computer memory, the system programmers have gotten carried away with the progressive "enhancements" to operating systems. Because systems also seem to be running faster, the cumbersome size and speed penalties are less obvious.
They are less obvious until you have a chance to see what an efficient operating system will do. FORTH programs have no need for the existing operating system. The only advantage is to have access to the succession of drivers. Aside from this feature, one whould do well to get rid of any underlying operating system.
But there are always a few who will insist on mixing their work. It is possible to access any system file with MVP-FORTH. It does require that you understand what you are doing. You can use FORTH to strip the special codes in the text files produced by some word procesors.
You have to decide how to use the facilities of the computer system.
Well, in spite of this tirade, there are occsions when access to the operating system might be desirable. A few simple routines make this process relatively easy. Most implementations of MVP-FORTH have a function SYSCALL. This function requires as parameters the desired function of the operating system and the necessary parameter or a dummy parameter. The system function will be executed and any error message will be returned.
To make use of the system functions you will need to know what they are. That is beyond the scope of this section. You can look them up in your system documentation. Much of the discussion will apply to most systems. A few system functions take more than one parameter or return something unusual. These functions will not work with the implementated function of SYSCALL. However, you could model the necessary function on the implementation included and do anything you wish.
The most interesting use of the system is to read and write program and system files. All disk accesses using system calls require a file control block. This is a block of 32 bytes which contains file information. Seven bytes before the file control block and 3 bytes after it may also be used by some systems. Therefore you really need to allocate 42 bytes to a space for the file control block. The pointer to the file control block is actually seven bytes above its beginning. If you understand this you could make space in the FORTH dictionary for a file control block.CREATE fcb 44 ALLOT : FCB fcb 7 + ;
You could make as many such file control blocks as you wish. Each would have to be given a separate name.
The next problem is to set up the necessary information in the block for the system to access. Why you do what you do you will have to learn from other materials. There are several FORTH functions and techniques which are well illustrate with the example below:: MAKE-FCB ( --- ) 14 0 SYSCALL DROP \ Reset disk CR CR ." Enter [d:]file name.typ ---" FCB 37 0 FILL FCB 1+ 11 BLANK QUERY 46 WORD DUP 2+ C@ 58 = \ ? [d:] IF DUP 1+ C@ 65 - 14 SWAP SYSCALL DROP \ Select drive COUNT 2- SWAP 2+ SWAP ELSE COUNT THEN 8 MIN FCB 1+ SWAP CMOVE BL WORD COUNT 3 MIN FCB 9 SWAP CMOVE CR ;
This imposing looking definition is a step by step advance through the proces required. A prompt is used to indicate the imput form. The square brackets are commonly used in operating system documentation to indicate optional inclusion of the data indicated. Note that this does not allow for a path.
The current contents of the file control block are cleared and the name field is set to spaces. Then the FORTH function to collect data is issued. After that the first word returned is parsed up to the period which has the decimal code balue 46. The word is inspected to see if the second character is a colon, ( 58 ). If it is the first character is converted to the drive number and used to select the drive. Then the rest of the file name is placed in its field and finally the file type is placed in its field.
The paragraph describing the function is moderately long, nor does it include all of the necessary details. Presumably, by now you can read and understand FORTH.
There is no reason not to include the entire function as a single FORTH word. With this file control block you can perform any of the system functions on files. You can make the file, open the file, close the file, read and write randomly to the file as well as sequentially. But you have to decide what you want to do.
The file control block can also be used to select a file and send it out a modem or another computer on an RS-232 connection. A reciprocal function can be used to write a file from a modem or another computer.
This modification and the examples of the use of SYSCALL and SAVE-FORTH in ALL ABOUT FORTH should give you sufficient models with which to work. FORTH is a programming language. You as the programmer must decide what you want to analyze and then program for your specific application.
Perhaps this is a place to show how to deal with one of the most difficult problems in using multiple disk formats with one of the IBM-PC operating systems. IBM has several times changed their disk operating system. Somehow it is necessary to inform the disk operating system of the format of the disks currently in the system. A means for doing this automatically has avoided solution for some time. It was a much simpler matter to tell the FORTH COFIGURE routine what you know the format to be.
First you would have to cause the operating system to read the disk being used. For this you would have to leave FORTH and do a directory on the disk in each drive. You could change the disks in a drive without trouble as long as you always used the same disk format. This works well for your standard mode of operation in which all disks will have the same format.
Only when you try to read a single sided disk formatted under DOS 1.0, for example, would you have trouble while using FORTH under DOS 2.1. A solution which can be executed from FORTH has been found.
It turned out that one of the advanced function calls in the disk operating system will do the job.: RESET-DRIVES MAX-DRV 0 DO I DR-DEN 3 < IF 54 I 1+ SYSCALL DROP THEN LOOP ;
Once the solution was found it was easy enough to implement. See your system documentation.
An interesting embellishment on the CONFIGURE function is to reset the existing floppy disks automatically. To do this you will have to understand the scheme used by IBM to code the current disk format. That information is in the zero track of the disk and can be accessed with from the data included in the 0 BLOCK of FORTH. The following code will then do the job. You do not even need to know what format a disk has.: RECONFIGURE EMPTY-BUFFERS RESET-DRIVES 0 OFFSET ! MAX-DRI 0 DO I DR-DEN 3 < IF 0 BLOCK 3 + C@ DUP 0= IF 0 ELSE DUP 3 = IF 1 ELSE 8 = IF 0 ELSE 0 BLOCK 512 = C@ 07 AND DUP 5 = IF 2 ELSE DUP 6 = IF 1 ELSE 7 = IF 0 ELSE 1 ABORT" Non-IBM Disk" THEN THEN THEN THEN THEN THEN I 2* DEN + ! BPDRV OFFSET +! THEN LOOP ;
It is highly unlikely that you will use a single sided disk with nine sectors per track. Therefore, no provisions for this format has been made.
The high level FORTH code checks the appropriate bytes in the first and second sector of the zero track and according to the value found sets the necessary values for reconfiguring the IBM floppy drives.
Next Previous Contents