In the previous section, each block of data in ROM was anonymous and the return address of the subroutine was used a pointer to this block.
The ROM_ENTRY()
macro allows to attach an identifier to a location in ROM as following:
ROM_ENTRY(hello) { ROM_TXT("hello guys !\0") ; }
The hello identifier has the type ROMptr and can be passed to any routine receiving this kind of pointer. For example, this is the case of the void lcd_Rputs(ROMptr) ;
(from the LCD library).
void f() { lcd_Rputs(hello) ; // displays «hello guys !» }
As previously, it is easy to write such a code at C level.
For that purpose, the rom.h header provides a macro ROM_POINTER
that allows to declare that
a ROMptr will be used to access ROM.
For example, suppose we want to implement a new version of puts() that access the character to be printed from a ROM pointer.
void Rputs(ROMptr p) { ROM_POINTER(p) ; READ_ROMBYTE ; while( prodl ) { putchar( prodl ) ; READ_ROMBYTE ; } }
Not really complex, isn't it ? But the next way to access ROM is even more simple, and more powerful.
AG 2013-04-10