Skip to content

charmap()

drmortalwombat edited this page Feb 1, 2022 · 4 revisions

#pragma charmap(char, code [,count])

  • char - 'source' character code (e.g. ASCII, PETSCII or screen)
  • code - 'destination' character code
  • count - optional range of source characters to remap (calculated from 'char')

The character map for string and char constants can be changed with a pragma to match a custom character set or PETSCII.

Example:

This function can be used to remap characters within a string by a given offset, making it easy to create strings that are reversed and similar. The following example will add 128 ($80) to any given string - useful to make characters reversed.

Macro definition:

#define reversed(x) \
""\
#pragma charmap(1, 129, 127)\
x\
#pragma charmap(1, 1, 127)

Note: pragma is used twice - first time to enable character shift, then to revert it back to normal.

Usage:

const char TXT_EN_TASK_LIST_HEADER[] = s" Task ";

Binary 20 20 54 01 13 0b 20 20

With 'reversed' macro:

const char TXT_EN_TASK_LIST_HEADER[] = reversed(s" Task ");

Binary a0 a0 d4 81 93 8b a0 a0

Clone this wiki locally