Accessing data in ROM with a ROM accessor

In the previous sections, ROM data were traversed in sequence. Using a ROM accessor, ROM data can be traversed randomly. A ROM accessor is simply a function that mimic the behaviour of an access to array's elements.

Five macros are available to declare a ROM accessor. For example, the ROMF_TXT macro allows to declare a text, and the way to access it:

ROMF_TXT( atext , "whiizz !\0")

Here, atext is a ROM accessor for the specified string. It means that atext(0) returns 'w', atext(1) returns 'h' , and so on. The type of atext is ROMF_i8_t. The F stands for function, because accessors are technically functions receiving an unsigned int.

Here is another flavor of the usual puts() function :

void RFputs(ROMF_i8_t p)
{
  uint8_t k ;
  for( k = 0 ; p(k) ; ++k)
    putchar(p(k)) ;
}

The following table shows the available accessors, and their corresponding types.

accessor declaration accessor type value type example
ROMF_TXT ROMF_i8_t int8_t ROMF_TXT(a,"hello\0")
ROMF_DATA8 ROMF_i8_t int8_t ROMF_DATA8(b,"-1,2,0xFF")
ROMF_DATA8U ROMF_ui8_t uint8_t ROMF_DATA8U(c,"1,2,0xFF")
ROMF_DATA16 ROMF_i16_t int16_t ROMF_DATA16(d,"-1,0xFF34")
ROMF_DATA16U ROMF_ui16_t uint16_t ROMF_DATA16U(e,"1,12300")

AG 2013-04-10