I finally solved the problem of my ComputerOne FORTH screen editor (not working well on too fast QL emulations - like uQLx on the raspberry PI) in the simplest way : adding a word to load text files like SuperForth.
just compile (from a FORTh screen) these 4 objects : SOURCE LOAD-SOURCE EOF LOAD-FILE
Code: Select all
FCB SOURCE
: LOAD-SOURCE
SOURCE OPEN-FILE 0<>
IF
ABORT" File not found"
THEN
SOURCE CHANNEL IS-INPUT ;
: EOF
OUTPUT IS-INPUT
SOURCE CLOSE-FILE DROP ;
: LOAD-FILE
SOURCE FILENAME LOAD-SOURCE ;
But be SURE to call the EOF word in the last line of this file
Now, how does it work ?
ComputerOne FORTH needs for each file to be opened a special word, a data structure of type FCB that you have to create by :
FCB SOME_NAME (in our case, we created FCB SOURCE)
This data structure contains a 64 bytes header and a 128 bytes buffer (it may not manage file records longer than that !)
You may use and re-use this same data structure as often as you want, provided that you "closed" the previously attached file. To do this, FORTH has first to associate the given FCB with a file, executing for instance (like in LOAD-FILE) :
SOURCE FILENAME
Then Forth must open the file (like in LOAD-SOURCE) executing in this instance :
SOURCE OPEN-FILE
When OPEN-FILE is successful, it returns a status flag 0, otherwise it returns a non-zero error code, and LOAD-SOURCE then aborts with the message "file not found" (most likely).
If file opening was successful, FORTH must associate the file with the QDOS channel opened for FORTH input (like in LOAD-FILE), and from then on, the content of the file is scanned as if it were entered from the keyboard.
NOTE : at the end of the file FORTH must execute the word EOF, that redirect input to the keyboard and closes the file. So EOF must be the last word of the file.
However, there is a limitation (the same as in SuperForth) : you cannot nest text files !
You cannot use LOAD-FILE inside a text file you are loading. Because for each file you open, you have to create a new FCB (using 200 bytes of dictionnary space) and if you compiled new words in the meantime you cannot reclaim - FORGET - these data structures without forgetting everything else : thus cluttering your precious user application dictionnary space.
In order to convert automatically my applications stored in standard ComputerOne FORTH ..._SCR files to ..._FTH text files, I also added these two words :
Code: Select all
: PAGE
SCR ! 16 0 DO CR I SCR @ .LINE LOOP ;
: MAKE-SOURCE
SOURCE FILENAME SOURCE MAKE-FILE .
SOURCE CHANNEL IS-OUTPUT
1+ SWAP DO I PAGE LOOP CR ." EOF" CR CR
INPUT IS-OUTPUT SOURCE CLOSE-FILE . ;
30 35 MAKE-SOURCE mdv1_appli_fth
and you will get a text file named "appli_fth" on "mdv1_" that you may compile simply typing :
LOAD-FILE mdv1_appli_fth
BUT !!! if your "appli" uses FORTH word --> to chain automatically compilation of several pages, you MUST erase these words from the text file (with your favorite text editor).
AND !!! remember : inside your appli, you cannot use word LOAD to nest other page compilations. I am looking for a simple way to solve this issue.
May the FORTH be with you !
Paul