Propeller Manual

Table Of Contents
2: Spin Language Reference – FILE
Propeller Manual v1.1 · Page 107
FILE
Directive: Import external file as data.
DAT
FILE "FileName"
FileName is the name, without extension, of the desired data file. Upon compile, a file
with this name is searched for in the editor tabs, the working directory and the library
directory. FileName can contain any valid filename characters; disallowed characters
are \, /, :, *, ?, ", <, >, and |.
Explanation
The
FILE directive is used to import an external data file (usually a binary file) into the DAT
block of an object. The data can then be accessed by the object just like any regular
DAT
block data.
T
Using FILE
FILE is used in DAT blocks similar to how BYTE would be used, except that following it is a
filename in quotes instead of data values. For example:
DAT
Str byte "This is a data string.", 0
Data file "Datafile.dat"
In this example, the DAT block is made up of a byte string followed by the data from a file
called Datafile.dat. Upon compile, the Propeller Tool will search through the editor tabs, the
working directory or the library directory for a file called Datafile.dat and will load its data
into the first byte following the zero-terminated string,
Str. Methods can access the imported
data using the
T
BYTE, WORD or LONG declarations as they would normal data. For example:
PUB GetData | Index, Temp
Index := 0
repeat
Temp := byte[Data][Index++] 'Read data into Temp 1 byte at a time
<do something with Temp> 'Perform task with value in Temp
while Temp > 0 'Loop until end found
This example will read the imported data, one byte at a time, until it finds a byte equal to 0.