|Top Previous Next|
The romfile. object provides access to resource files of your project (resource files appear in the "Resource Files" branch of your project tree).
Resource files are not processed by the compiler in any way — they are just added to the compiled binary.
Resource files are for storing permanent data that never changes (hence, the "rom" in "romfile" — as in "Read-Only Memory").
Opening resource files
Calling the romfile.open method opens a resource file. Only one resource file can be opened at any given time. There is no need to close resource files.
The size of the opened file can be checked through the romfile.size read-only property.
If you attempt to open a non-existent or empty file its size will be returned as 0.
The current file position in a resource file is indicated by the file pointer.
When you open or reopen a resource file the pointer is set to 1 (the first position in the file), unless the file does not exist or is empty, in which case the pointer will be at 0.
The value of the pointer can't exceed romfile.size+1 (unless the file does not exist or is empty, in which case the only possible pointer value is 0).
Reading from resource files
Use the romfile.getdata method to read from the currently opened resource file.
The following example demonstrates a loop that exists once there is nothing left to read from the file:
As you read from the file the pointer will move — each time by the number of bytes you've read.
Here is another file reading loop. This one is based on the pointer value:
Searching within resource files
One of the primary uses for resource files is to store configuration data. For example, our own STG (settings) library relies on a resource file that describes available settings, their types, minimum and maximum values, and so on.
What's required for efficient work with configuration files is fast search, and the romfile.find32 method implements just that.
The search speed offered by this method far exceeds anything you would be able to achieve through a search function written in Tibbo BASIC or C.
In addition, romfile.find32 allows you to specify the starting search position and the occurrence number you are interested in (more).
As an example, let's assume there is a configuration file with parameters:
Here is the code that will find the value of the IP parameter: