Skip to content
kscheff edited this page Nov 15, 2016 · 12 revisions

Syntax

OPEN <0-3>, READ|TRUNCATE|APPEND "<A-Z>"
READ #<0-3>, <variable> [, ...]
WRITE #<0-3>, <variable>|<number> [, ...]
<variable> = EOF(<0-3>)
CLOSE <0-3>

Description

The file system supports opening four streams identified by the indices 0..3 as filenames from 'A' to 'Z'
The streams (files) may be opened in read, truncate(write) or append mode. Streams may be closed, which closes the file.
Data can be written to, appended to, or read from the file using the stream selector.
Files are organised as up to 255 records, each record being up to 250 bytes long (so, more space than there's FLASH to support).

Note:
26 files are supported, named A-Z. You can open the same file on two different streams, one for writing, one for reading.

EOF reports if the file exists or not. EOF does not reflect if the end of the file has been reached. Consequently when opening a file in TRUNCATE mode the file is deleted and EOF reports 1.

10 OPEN 0, READ "A"
20 IF EOF(0) = 0
30  PRINT "File A exists."
40 ELSE
50  PRINT "File A does not exist."
60 END

I am not sure how EOF works. It returns a value of 0 or 1, but does not seem to indicate that you have reached the end of data. (Opening a file in READ mode, EOF() always seems to return 0, while opening a file in TRUNCATE|APPEND mode EOF() returns 1?)


Examples

10 OPEN 0, TRUNCATE "A" // Open file 'A' on stream 0 for writing
20 WRITE # 0, W // Writes variable W to file 'A'
21 CLOSE 0 // Close file 'A'
22 OPEN 1, READ "A" // Open file 'A' on stream 1 for reading
30 READ # 1, B // Read file 'A' into variable B
40 L = EOF(1)
50 CLOSE 1