NVEM string formatting function nz({Ptr}{,Item})
Used to look up and print zero terminated strings stored in NVEM. Useful for multiple language support and other places where it’s useful to have table based control of what’s printed.
The function can have 0, 1 or 2 arguments, and supports direct and indirect (table of addresses of strings) addressing
- Direct addressing: The NVPtr and NVRecNum point to the string.
- Indirect addressing: NVPtr/NVRecNum point to a table of 16-bit pointers, which in turn point to the desired string. This is provides a mechanism for multiple language support – the language is selected simply by changing NVPtr.
The function does not alter NVPage.
In all cases the string to be printed must be stored in zero terminated form, for example:-
strHello NV0Byte "Hello World!",0
The zero at the end terminates the string.
The three forms of this formatting function are:
No arguments – nz()
If you don’t supply any arguments the existing settings of NVPage, NVPtr, NVRecLen and NVRecNum determine the string to be printed. It is entirely your responsibility to get them right.
Example:
NVSetPage 0
NVSetRecNum 0
NVSetPtr strHello
#HMI Print(nz())
strHello: NVByte "Hello World",0
One argument – nz(Ptr)
The argument Ptr determines where the string will be found. The functions loads the NVPtr with a value specified by Ptr, and sets NVRecNum to zero. That means you must specify a single value that points directly at the required string. Ptr specifiers are described in the table below.
#HMI Print(nz(strHello))
strHello NVByte "Hello World",0
Two arguments – nz(Ptr, Item)
This is the most complicated, and the most powerful form. It uses indirect addressing. The pointer does not point to the string itself, it points to a separate table of NVEM pointers. The Item argument selects a pointer out of that pointer table table. That pointer in turn points at the desired string. Once you get your head around that, you will see that it can be used for cool things like easily switching between languages.
Example, a basic language management system.
;Define constants that define the order of the message
;pointers in NVEM
kmsgHello EQU 0
kmsgGoodBye EQU 1
...
;Say hello in the current language.
;The language pointer is in fLangPntr
fRecallW fLangPntr ;Now points to the pointer table
LoadX kmsgHello
#HMI Print(nz(=w, =x))
;English strings
enHello NV0Byte "Hello World",0
enGoodBye NV0Byte "Good bye",0
;French strings
frHello NV0Byte "Bon jour, tout le mond",0
frGoodBye NV0Byte "Au revoir",0
;Pointer tables for the languages. These must be in the
;same order as defined in the constants kmsgHello etc above
;Language pointer table, English
enPntrs NV0Ptr enHello
NV0Ptr enGoodBye
;Language pointer table, French
frPntrs NV0Ptr frHello
NV0Ptr frGoodBye
The Ptr argument
The Ptr argument has several possibilities
| Ptr | Resulting pointer value |
| =w | The number in W, interpreted as an (integer) NVEM base address |
| =q | The number in Q, interpreted as an (integer) NVEM base address |
| =p | The existing contents of NVPtr |
| cc | A symbolic (named) NVEM address |
| *ww | A 16-bit integer in RAM, interpreted as an NVEM base address. IasJ + and NoJ – modifiers are supported e.g. *+ww |
The Item argument
In the form of nz() that uses two arguments, the second argument, Item, can be any of the following
| Form | Meaning | Example |
=x | Contents of the X register | #HMI Print(nz(=p, =x)) |
=y | Contents of the Y register | #HMI Print(nz(=p, =y)) |
=h | Contents of the H register | #HMI Print(nz(=p, =h)) |
=m | Contents of the M register | #HMI Print(nz(=p, =m)) |
=s | Contents of the S register | #HMI Print(nz(=p, =s)) |
=i | Contents of the I register | #HMI Print(nz(=p, =i)) |
Constant | Contents of an EQUated constant | Foo EQU 56...#HMI Print(b(nz(=p, Foo)) |
| A number 0 – 255 | An immediate numeric value | #HMI Print(nz(=p, 165)) |
*Label | Contents of a RAM byte (variable) | Temperature defBYTE...#HMI Print(nz(=p, *Temperature)) |