LOL. You are reading my mind. Thank you.
I had played with some of this before and I am just testing my ideas now.
The Forth Standard specifies something called a "file access method" (FAM)
So CREATE-FILE is defined as:
CREATE-FILE ( c-addr u fam -- fileid ior )
There are also 3 words, R/W R/O W/O that return the "FAM".
I was struggling with how to do this with all the variations possible in the 99-4a file system. Just recently I had a small epiphany.
So here is what I came up with. The file mode control words assemble all the bits that define a file in a variable called, what else FAM.
2 BASE !
VARIABLE FAM \ we build the file mode bits in this variable
: FAM@ FAM @ ;
: FAM! FAM ! ;
\ mask bits added bits store
\ --------- ----------- --------
: DISPLAY ( -- ) FAM@ 11101111 AND FAM! ; \ Text file
: INTERNAL ( -- ) FAM@ 00010000 OR FAM! ; \ binary file
: VARI ( -- ) FAM@ 11110111 AND 00001000 OR FAM! ; \ VARIABLE is a keyword in Forth
: UPDATE ( -- ) FAM@ 11111001 AND FAM! ;
: OUTPUT ( -- ) FAM@ 11111001 AND 00000010 OR FAM! ;
: INPUT ( -- ) FAM@ 11111001 AND 00000100 OR FAM! ;
: APPEND ( -- ) FAM@ 00000110 OR FAM! ;
: SEQUENTIAL ( -- ) FAM@ 11111110 AND FAM! ;
: RELATIVE ( -- ) FAM@ 00000001 OR FAM! ;
: fixed ( -- ) FAM@ 11110111 AND FAM! ;
\ set record length and set mode for FIXED files
: FIXED ( c --) PAB 4 + V! fixed ;
These are doing exactly the same thing as the TI-Forth code but are keeping track inside the FAM variable instead of in the FLAGS field in the PAB.
Then I defined the ANS words like this:
\ ANS/ISO Forth FILE ACCESS METHODs (FAM)
: R/W ( -- fam) UPDATE FAM @ ;
: R/O ( -- fam) INPUT FAM @ ;
: W/O ( -- fam) OUTPUT FAM @ ;
So I figure you can type file mode words until the cows come home and then when you create-file or open-file etc. you just insert the R/W or whatever and the hi-level word takes care of it.
This is as far as I have gotten . I refactored the pab creation and magic address writing to the word NEWFILE just now.
Then I made my file operations all lowercase primitives ( open,read,write,close etc.)
They just fill in the OPCODE in PAB and do the BLWP magic and return the error bits to the stack.
Then the final interface will look like ANS Forth. (UNTESTED!) Once it's working I will get to file handles for 3 files. "Make it work first"
: CREATE-FILE ( c-addr u fam -- fileid ior ) \ fam is the "read/write" file access method.
-ROT NEWFILE FLG! \ create PAB, set the file mode
open ( -- err) \ call open primitive
1 SWAP ; \ return a file id (ALWAYS 1) and error
As you can see I had lots of time to dream about the innards before I could make it work. That only took me oh... well let's say... I started thinking about it a year ago.
As I look at the TI-Forth code I can probably simplify further.
And I see that need to fix my error words.
Thanks again for all your support. It makes a real difference.
Edited by TheBF, Fri Mar 16, 2018 1:32 PM.