ZBasic Language Reference
44
ZX Microcontroller Family
Note that the UBound() function is useful with Program Memory data items to determine the dimensions
of the vectors and tables. LBound() will always return 1 since initialized Program Memory data items
are always 1-based.
For special situations, the data initialization file may be supplied in raw form. This means that the
initialization file contains actual binary data as opposed to containing formatted data items. You instruct
the compiler to interpret the initialization file in raw mode by appending Attribute(raw) to the end of
the definition as in the example below. Note, particularly, that raw mode can only be used for numeric
types (i.e. not String types) and can only be used for vector types (i.e. not table types). Also, the data file
must contain an integral number of data elements. For example, for IntegerVectorData the data file
must contain an even number of bytes.
Dim d1 as ByteVectorData("mydata.dat") Attribute(raw)
Program Memory variables may also be defined using a syntax similar to that used for defining RAM-
based variables, using the keyword attribute ProgMem preceding the type name. For example,
Dim d1(1 to 20) as ProgMem Byte
This defines and reserves space for an array of bytes in Program Memory. Variables defined in this way
will be zero-filled. Strings in Program Memory may be defined as well using the bounded string syntax.
In this case, the string will have an initial value representing an empty (zero length) string.
Dim ps as ProgMem BoundedString(15)
Program memory structures may also be defined, see Section 3.25 for more details. A Program Memory
variable may also be defined using Based keyword, see Section 3.22 for more details.
Caution: although Program Memory data items can be modified, the memory in which they are stored
has a write cycle limit. For ZX devices with external Program Memory (e.g. the ZX-24a), the limit is
approximately a million writes. For ZX devices with internal Program Memor (e.g. the ZX-24n), the limit is
approximately 100,000 writes. Writing to a particular address more than this may cause the memory to
become unreliable. Also, writing to Program Memory is much slower than writing to RAM-based
variables.
BasicX Compatibility Note
In BasicX mode, Program Memory string types are not supported nor are any vector types other
than the Byte types. Also, in-line initializers are not supported, the DataAddress property
cannot be used to determine the address of an individual Program Memory data element, and
quoted strings cannot be used to specify data values. Finally, Program Memory data items may
only be defined at the module level.
You may completely omit the initialization data from the definition of a Program Memory data item,
including the parentheses that normally enclose it. If you do this, you must use the Source method to
specify the initialization data as shown below. This alternate initialization mechanism is supported for
backward compatibility with BasicX and is not recommended for new applications. Note, particularly, that
this somewhat odd construction involving a Call does not produce any run-time executable code. It is
merely a signal to the compiler to read the initialization data from the specified file.
Dim d1 as New ByteVectorData
Sub Main()
Dim b as Byte
' specify the initialization data
Call d1.Source("mydata.txt")