Martin_H wrote:
* The most immediate is a lack of detailed knowledge of the IEC protocol. I have a high level overview and Rich's source code for his ehBasic mods, so with code reading I might get somewhere here.
I can't help you here, but what you're looking for is random access to the disk and/or random access to a file on the disk.
Quote:
* What syntax and semantics are used by FORTH to access a file system? I know that early FORTH's used block mode I/O and structure is imposed by the programmer. But that low level interaction isn't how things seem to be done with IEC drives. Looking at the command set it looks like your program is talking to a file server rather than a block I/O device.
There's an ANS standard File word set that can be used. I've not used it, I'm mostly familiar with old school blocks.
In F83, a specific Forth-83 implementation for the PC, they use the OPEN word to open a block file, and then use the normal block words.
Quote:
* When a FORTH programmer saves a program what are they saving? A snapshot of RAM with the compiled words, or FORTH source to be recompiled when the file loads? I suspect the latter would result in better code longevity, but that would see to require a way to output compiled FORTH words in their source versions.
In the past, the disk was used to load Forth source. Any "Save" commands were very implementation specific. For example, on the Atari, you would use their save command to snapshot the existing Forth image so that it would boot off of a floppy.
F83 will let you dump the image as a new executable ala F83.com.
What they didn't have was some kind of facility to save, in a binary format, fragments of the running system. Specifically, you couldn't load in a bunch of Forth source, and save the results as a binary component, and then reload just that binary component. Who knows what a may be possible in a modern Forth. But the old systems you basically started with a virgin image, load in source, then saved the entire thing back out.
Using the Block word set, you only need random access to the disk in some way. If you're talking to an actual filesystem, then you don't want to randomly access sectors of the disk (you can, you just probably don't want to). Doing that will stomp on the existing file system. So, instead, you'll want to access a file on the system, and then have random access to the file.
In Forth, Blocks are 1K bytes long. Blocks are also numbered from 0 to 65535 (16b Forth). Block 0 is "reserved" (since its typically used by the operating system to boot the disk or something else), but for a File based system that's less of a problem.
In any case, to save, say, Block 15, you seek 15 * 1024 bytes in to the disk/file, and write 1024 bytes out. Similarly for reading.
Now, for you work, you only need to learn how to randomly seek and read/write blocks. Your SC2IEC thing can no doubt do this, a disk file system that can not be randomly accessed is almost useless. So the capability is there.
For your system, you can use simply dedicate a hard coded file name (FORTH.DAT) on your drive, and use that, or you can use something like the F83 OPEN command: OPEN FORTH.DAT.
To use block I/O in Forth, you want to focus on the BLOCK command.
12 BLOCK will return the address of the internal buffer that contains Block #12 from mass storage. It will read the disk if necessary. You can the change the contents of that buffer, however you want, it's just memory. When you are done, you issue a 12 UPDATE command. This tells the system that Block 12 has changed.
Now, you can issue a SAVE-BUFFERS command, which will write ALL of the changed blocks back to disk.
The Forth block system is a crude virtual memory system. You load a page, then "use it" (UPDATE), and then…nothing. You're done. As new blocks are loaded, old blocks are flushed back out. The original Forth I/O system is distinctly unlike the modern streaming APIs, where you simply point a block of memory at an open file and say "write this" whether it's 1 byte or 1M bytes.
But it's effective.
So, in the end, you need random access to something -- ideally a file. And you can add a mechanism to your Forth to specify what that file name is at run time, or just use the same name over and over.