Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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 |.

...

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:

Code Block
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 BYTE, WORD or LONG declarations as they would normal data. For example:

Code Block
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.