Use defines for text chars

This commit is contained in:
DizzyEggg 2018-10-14 15:04:25 +02:00
parent 0c1d33da4f
commit 541043a661
4 changed files with 88 additions and 87 deletions

View File

@ -24,7 +24,7 @@ u8 *ConvertUIntToDecimalStringN(u8 *dest, u32 value, enum StringConvertMode mode
u8 *ConvertIntToHexStringN(u8 *dest, s32 value, enum StringConvertMode mode, u8 n); u8 *ConvertIntToHexStringN(u8 *dest, s32 value, enum StringConvertMode mode, u8 n);
u8 *StringExpandPlaceholders(u8 *dest, const u8 *src); u8 *StringExpandPlaceholders(u8 *dest, const u8 *src);
u8 *StringBraille(u8 *dest, const u8 *src); u8 *StringBraille(u8 *dest, const u8 *src);
u8 *GetExpandedPlaceholder(u32 id); const u8 *GetExpandedPlaceholder(u32 id);
u8 *StringFill(u8 *dest, u8 c, u16 n); u8 *StringFill(u8 *dest, u8 c, u16 n);
u8 *StringCopyPadded(u8 *dest, const u8 *src, u8 c, u16 n); u8 *StringCopyPadded(u8 *dest, const u8 *src, u8 c, u16 n);
u8 *StringFillWithTerminator(u8 *dest, u16 n); u8 *StringFillWithTerminator(u8 *dest, u16 n);

View File

@ -76,6 +76,7 @@
#define CHAR_y 0xED #define CHAR_y 0xED
#define CHAR_z 0xEE #define CHAR_z 0xEE
#define CHAR_SPECIAL_F7 0xF7 #define CHAR_SPECIAL_F7 0xF7
#define CHAR_SPECIAL_F8 0xF8
#define CHAR_SPECIAL_F9 0xF9 #define CHAR_SPECIAL_F9 0xF9
#define CHAR_COLON 0xF0 #define CHAR_COLON 0xF0
#define CHAR_PROMPT_SCROLL 0xFA // waits for button press and scrolls dialog #define CHAR_PROMPT_SCROLL 0xFA // waits for button press and scrolls dialog

View File

@ -20,20 +20,20 @@ static const s32 sPowersOfTen[] =
1000000000, 1000000000,
}; };
extern u8 gExpandedPlaceholder_Empty[]; extern const u8 gExpandedPlaceholder_Empty[];
extern u8 gExpandedPlaceholder_Kun[]; extern const u8 gExpandedPlaceholder_Kun[];
extern u8 gExpandedPlaceholder_Chan[]; extern const u8 gExpandedPlaceholder_Chan[];
extern u8 gExpandedPlaceholder_Sapphire[]; extern const u8 gExpandedPlaceholder_Sapphire[];
extern u8 gExpandedPlaceholder_Ruby[]; extern const u8 gExpandedPlaceholder_Ruby[];
extern u8 gExpandedPlaceholder_Emerald[]; extern const u8 gExpandedPlaceholder_Emerald[];
extern u8 gExpandedPlaceholder_Aqua[]; extern const u8 gExpandedPlaceholder_Aqua[];
extern u8 gExpandedPlaceholder_Magma[]; extern const u8 gExpandedPlaceholder_Magma[];
extern u8 gExpandedPlaceholder_Archie[]; extern const u8 gExpandedPlaceholder_Archie[];
extern u8 gExpandedPlaceholder_Maxie[]; extern const u8 gExpandedPlaceholder_Maxie[];
extern u8 gExpandedPlaceholder_Kyogre[]; extern const u8 gExpandedPlaceholder_Kyogre[];
extern u8 gExpandedPlaceholder_Groudon[]; extern const u8 gExpandedPlaceholder_Groudon[];
extern u8 gExpandedPlaceholder_Brendan[]; extern const u8 gExpandedPlaceholder_Brendan[];
extern u8 gExpandedPlaceholder_May[]; extern const u8 gExpandedPlaceholder_May[];
u8 *StringCopy10(u8 *dest, const u8 *src) u8 *StringCopy10(u8 *dest, const u8 *src)
{ {
@ -348,7 +348,7 @@ u8 *StringExpandPlaceholders(u8 *dest, const u8 *src)
{ {
u8 c = *src++; u8 c = *src++;
u8 placeholderId; u8 placeholderId;
u8 *expandedString; const u8 *expandedString;
switch (c) switch (c)
{ {
@ -383,9 +383,9 @@ u8 *StringExpandPlaceholders(u8 *dest, const u8 *src)
case EOS: case EOS:
*dest = EOS; *dest = EOS;
return dest; return dest;
case 0xFA: case CHAR_PROMPT_SCROLL:
case 0xFB: case CHAR_PROMPT_CLEAR:
case 0xFE: case CHAR_NEWLINE:
default: default:
*dest++ = c; *dest++ = c;
} }
@ -394,8 +394,8 @@ u8 *StringExpandPlaceholders(u8 *dest, const u8 *src)
u8 *StringBraille(u8 *dest, const u8 *src) u8 *StringBraille(u8 *dest, const u8 *src)
{ {
u8 setBrailleFont[] = { 0xFC, 0x06, 0x06, 0xFF }; u8 setBrailleFont[] = { EXT_CTRL_CODE_BEGIN, 0x06, 0x06, EOS };
u8 gotoLine2[] = { 0xFE, 0xFC, 0x0E, 0x02, 0xFF }; u8 gotoLine2[] = { CHAR_NEWLINE, EXT_CTRL_CODE_BEGIN, 0x0E, 0x02, EOS };
dest = StringCopy(dest, setBrailleFont); dest = StringCopy(dest, setBrailleFont);
@ -408,7 +408,7 @@ u8 *StringBraille(u8 *dest, const u8 *src)
case EOS: case EOS:
*dest = c; *dest = c;
return dest; return dest;
case 0xFE: case CHAR_NEWLINE:
dest = StringCopy(dest, gotoLine2); dest = StringCopy(dest, gotoLine2);
break; break;
default: default:
@ -419,32 +419,32 @@ u8 *StringBraille(u8 *dest, const u8 *src)
} }
} }
static u8 *ExpandPlaceholder_UnknownStringVar(void) static const u8 *ExpandPlaceholder_UnknownStringVar(void)
{ {
return gUnknownStringVar; return gUnknownStringVar;
} }
static u8 *ExpandPlaceholder_PlayerName(void) static const u8 *ExpandPlaceholder_PlayerName(void)
{ {
return gSaveBlock2Ptr->playerName; return gSaveBlock2Ptr->playerName;
} }
static u8 *ExpandPlaceholder_StringVar1(void) static const u8 *ExpandPlaceholder_StringVar1(void)
{ {
return gStringVar1; return gStringVar1;
} }
static u8 *ExpandPlaceholder_StringVar2(void) static const u8 *ExpandPlaceholder_StringVar2(void)
{ {
return gStringVar2; return gStringVar2;
} }
static u8 *ExpandPlaceholder_StringVar3(void) static const u8 *ExpandPlaceholder_StringVar3(void)
{ {
return gStringVar3; return gStringVar3;
} }
static u8 *ExpandPlaceholder_KunChan(void) static const u8 *ExpandPlaceholder_KunChan(void)
{ {
if (gSaveBlock2Ptr->playerGender == MALE) if (gSaveBlock2Ptr->playerGender == MALE)
return gExpandedPlaceholder_Kun; return gExpandedPlaceholder_Kun;
@ -452,7 +452,7 @@ static u8 *ExpandPlaceholder_KunChan(void)
return gExpandedPlaceholder_Chan; return gExpandedPlaceholder_Chan;
} }
static u8 *ExpandPlaceholder_RivalName(void) static const u8 *ExpandPlaceholder_RivalName(void)
{ {
if (gSaveBlock2Ptr->playerGender == MALE) if (gSaveBlock2Ptr->playerGender == MALE)
return gExpandedPlaceholder_May; return gExpandedPlaceholder_May;
@ -460,44 +460,44 @@ static u8 *ExpandPlaceholder_RivalName(void)
return gExpandedPlaceholder_Brendan; return gExpandedPlaceholder_Brendan;
} }
static u8 *ExpandPlaceholder_Version(void) static const u8 *ExpandPlaceholder_Version(void)
{ {
return gExpandedPlaceholder_Emerald; return gExpandedPlaceholder_Emerald;
} }
static u8 *ExpandPlaceholder_Aqua(void) static const u8 *ExpandPlaceholder_Aqua(void)
{ {
return gExpandedPlaceholder_Aqua; return gExpandedPlaceholder_Aqua;
} }
static u8 *ExpandPlaceholder_Magma(void) static const u8 *ExpandPlaceholder_Magma(void)
{ {
return gExpandedPlaceholder_Magma; return gExpandedPlaceholder_Magma;
} }
static u8 *ExpandPlaceholder_Archie(void) static const u8 *ExpandPlaceholder_Archie(void)
{ {
return gExpandedPlaceholder_Archie; return gExpandedPlaceholder_Archie;
} }
static u8 *ExpandPlaceholder_Maxie(void) static const u8 *ExpandPlaceholder_Maxie(void)
{ {
return gExpandedPlaceholder_Maxie; return gExpandedPlaceholder_Maxie;
} }
static u8 *ExpandPlaceholder_Kyogre(void) static const u8 *ExpandPlaceholder_Kyogre(void)
{ {
return gExpandedPlaceholder_Kyogre; return gExpandedPlaceholder_Kyogre;
} }
static u8 *ExpandPlaceholder_Groudon(void) static const u8 *ExpandPlaceholder_Groudon(void)
{ {
return gExpandedPlaceholder_Groudon; return gExpandedPlaceholder_Groudon;
} }
u8 *GetExpandedPlaceholder(u32 id) const u8 *GetExpandedPlaceholder(u32 id)
{ {
typedef u8 *(*ExpandPlaceholderFunc)(void); typedef const u8 *(*ExpandPlaceholderFunc)(void);
static const ExpandPlaceholderFunc funcs[] = static const ExpandPlaceholderFunc funcs[] =
{ {
@ -574,7 +574,7 @@ u8 *StringCopyN_Multibyte(u8 *dest, u8 *src, u32 n)
else else
{ {
*dest++ = *src++; *dest++ = *src++;
if (*(src - 1) == 0xF9) if (*(src - 1) == CHAR_SPECIAL_F9)
*dest++ = *src++; *dest++ = *src++;
} }
} }
@ -589,7 +589,7 @@ u32 StringLength_Multibyte(u8 *str)
while (*str != EOS) while (*str != EOS)
{ {
if (*str == 0xF9) if (*str == CHAR_SPECIAL_F9)
str++; str++;
str++; str++;
length++; length++;
@ -600,7 +600,7 @@ u32 StringLength_Multibyte(u8 *str)
u8 *WriteColorChangeControlCode(u8 *dest, u32 colorType, u8 color) u8 *WriteColorChangeControlCode(u8 *dest, u32 colorType, u8 color)
{ {
*dest = 0xFC; *dest = EXT_CTRL_CODE_BEGIN;
dest++; dest++;
switch (colorType) switch (colorType)
@ -630,7 +630,7 @@ bool32 IsStringJapanese(u8 *str)
while (*str != EOS) while (*str != EOS)
{ {
if (*str <= 0xA0) if (*str <= 0xA0)
if (*str != 0) if (*str != CHAR_SPACE)
return TRUE; return TRUE;
str++; str++;
} }
@ -645,7 +645,7 @@ bool32 sub_800924C(u8 *str, s32 n)
for (i = 0; *str != EOS && i < n; i++) for (i = 0; *str != EOS && i < n; i++)
{ {
if (*str <= 0xA0) if (*str <= 0xA0)
if (*str != 0) if (*str != CHAR_SPACE)
return TRUE; return TRUE;
str++; str++;
} }
@ -692,7 +692,7 @@ u8 GetExtCtrlCodeLength(u8 code)
static const u8 *SkipExtCtrlCode(const u8 *s) static const u8 *SkipExtCtrlCode(const u8 *s)
{ {
while (*s == 0xFC) while (*s == EXT_CTRL_CODE_BEGIN)
{ {
s++; s++;
s += GetExtCtrlCodeLength(*s); s += GetExtCtrlCodeLength(*s);
@ -716,11 +716,11 @@ s32 StringCompareWithoutExtCtrlCodes(const u8 *str1, const u8 *str2)
if (*str1 < *str2) if (*str1 < *str2)
{ {
retVal = -1; retVal = -1;
if (*str2 == 0xFF) if (*str2 == EOS)
retVal = 1; retVal = 1;
} }
if (*str1 == 0xFF) if (*str1 == EOS)
return retVal; return retVal;
str1++; str1++;
@ -729,7 +729,7 @@ s32 StringCompareWithoutExtCtrlCodes(const u8 *str1, const u8 *str2)
retVal = 1; retVal = 1;
if (*str1 == 0xFF) if (*str1 == EOS)
retVal = -1; retVal = -1;
return retVal; return retVal;
@ -743,9 +743,9 @@ void ConvertInternationalString(u8 *s, u8 language)
StripExtCtrlCodes(s); StripExtCtrlCodes(s);
i = StringLength(s); i = StringLength(s);
s[i++] = 0xFC; s[i++] = EXT_CTRL_CODE_BEGIN;
s[i++] = 22; s[i++] = 22;
s[i++] = 0xFF; s[i++] = EOS;
i--; i--;
@ -755,7 +755,7 @@ void ConvertInternationalString(u8 *s, u8 language)
i--; i--;
} }
s[0] = 0xFC; s[0] = EXT_CTRL_CODE_BEGIN;
s[1] = 21; s[1] = 21;
} }
} }
@ -764,9 +764,9 @@ void StripExtCtrlCodes(u8 *str)
{ {
u16 srcIndex = 0; u16 srcIndex = 0;
u16 destIndex = 0; u16 destIndex = 0;
while (str[srcIndex] != 0xFF) while (str[srcIndex] != EOS)
{ {
if (str[srcIndex] == 0xFC) if (str[srcIndex] == EXT_CTRL_CODE_BEGIN)
{ {
srcIndex++; srcIndex++;
srcIndex += GetExtCtrlCodeLength(str[srcIndex]); srcIndex += GetExtCtrlCodeLength(str[srcIndex]);
@ -776,5 +776,5 @@ void StripExtCtrlCodes(u8 *str)
str[destIndex++] = str[srcIndex++]; str[destIndex++] = str[srcIndex++];
} }
} }
str[destIndex] = 0xFF; str[destIndex] = EOS;
} }

View File

@ -3095,13 +3095,13 @@ u32 GetStringWidthFixedWidthFont(const u8 *str, u8 fontId, u8 letterSpacing)
temp = strLocal[strPos++]; temp = strLocal[strPos++];
switch (temp) switch (temp)
{ {
case 0xFE: case CHAR_NEWLINE:
case 0xFF: case EOS:
lineWidths[line] = width; lineWidths[line] = width;
width = 0; width = 0;
line++; line++;
break; break;
case 0xFC: case EXT_CTRL_CODE_BEGIN:
temp2 = strLocal[strPos++]; temp2 = strLocal[strPos++];
switch (temp2) switch (temp2)
{ {
@ -3135,21 +3135,21 @@ u32 GetStringWidthFixedWidthFont(const u8 *str, u8 fontId, u8 letterSpacing)
break; break;
} }
break; break;
case 0xF7: case CHAR_SPECIAL_F7:
case 0xFD: case PLACEHOLDER_BEGIN:
++strPos; ++strPos;
break; break;
case 0xFA: case CHAR_PROMPT_SCROLL:
case 0xFB: case CHAR_PROMPT_CLEAR:
break; break;
case 0xF8: case CHAR_SPECIAL_F8:
case 0xF9: case CHAR_SPECIAL_F9:
++strPos; ++strPos;
default: default:
++width; ++width;
break; break;
} }
} while (temp != 0xFF); } while (temp != EOS);
for (width = 0, strPos = 0; strPos < 8; ++strPos) for (width = 0, strPos = 0; strPos < 8; ++strPos)
{ {
@ -3201,16 +3201,16 @@ u32 GetStringWidth(u8 fontId, const u8 *str, s16 letterSpacing)
lineWidth = 0; lineWidth = 0;
bufferPointer = 0; bufferPointer = 0;
while (*str != 0xFF) while (*str != EOS)
{ {
switch (*str) switch (*str)
{ {
case 0xFE: case CHAR_NEWLINE:
if (lineWidth > width) if (lineWidth > width)
width = lineWidth; width = lineWidth;
lineWidth = 0; lineWidth = 0;
break; break;
case 0xFD: case PLACEHOLDER_BEGIN:
switch (*++str) switch (*++str)
{ {
case 0x2: case 0x2:
@ -3225,10 +3225,10 @@ u32 GetStringWidth(u8 fontId, const u8 *str, s16 letterSpacing)
default: default:
return 0; return 0;
} }
case 0xF7: case CHAR_SPECIAL_F7:
if (bufferPointer == NULL) if (bufferPointer == NULL)
bufferPointer = DynamicPlaceholderTextUtil_GetPlaceholderPtr(*++str); bufferPointer = DynamicPlaceholderTextUtil_GetPlaceholderPtr(*++str);
while (*bufferPointer != 0xFF) while (*bufferPointer != EOS)
{ {
glyphWidth = func(*bufferPointer++, isJapanese); glyphWidth = func(*bufferPointer++, isJapanese);
if (minGlyphWidth > 0) if (minGlyphWidth > 0)
@ -3240,13 +3240,13 @@ u32 GetStringWidth(u8 fontId, const u8 *str, s16 letterSpacing)
else else
{ {
lineWidth += glyphWidth; lineWidth += glyphWidth;
if (isJapanese && str[1] != 0xFF) if (isJapanese && str[1] != EOS)
lineWidth += localLetterSpacing; lineWidth += localLetterSpacing;
} }
} }
bufferPointer = 0; bufferPointer = 0;
break; break;
case 0xFC: case EXT_CTRL_CODE_BEGIN:
switch (*++str) switch (*++str)
{ {
case 0x4: case 0x4:
@ -3299,9 +3299,9 @@ u32 GetStringWidth(u8 fontId, const u8 *str, s16 letterSpacing)
break; break;
} }
break; break;
case 0xF8: case CHAR_SPECIAL_F8:
case 0xF9: case CHAR_SPECIAL_F9:
if (*str == 0xF9) if (*str == CHAR_SPECIAL_F9)
glyphWidth = func(*++str | 0x100, isJapanese); glyphWidth = func(*++str | 0x100, isJapanese);
else else
glyphWidth = GetKeypadIconWidth(*++str); glyphWidth = GetKeypadIconWidth(*++str);
@ -3315,12 +3315,12 @@ u32 GetStringWidth(u8 fontId, const u8 *str, s16 letterSpacing)
else else
{ {
lineWidth += glyphWidth; lineWidth += glyphWidth;
if (isJapanese && str[1] != 0xFF) if (isJapanese && str[1] != EOS)
lineWidth += localLetterSpacing; lineWidth += localLetterSpacing;
} }
break; break;
case 0xFA: case CHAR_PROMPT_SCROLL:
case 0xFB: case CHAR_PROMPT_CLEAR:
break; break;
default: default:
glyphWidth = func(*str, isJapanese); glyphWidth = func(*str, isJapanese);
@ -3333,7 +3333,7 @@ u32 GetStringWidth(u8 fontId, const u8 *str, s16 letterSpacing)
else else
{ {
lineWidth += glyphWidth; lineWidth += glyphWidth;
if (isJapanese && str[1] != 0xFF) if (isJapanese && str[1] != EOS)
lineWidth += localLetterSpacing; lineWidth += localLetterSpacing;
} }
break; break;
@ -3372,7 +3372,7 @@ u8 RenderTextFont9(u8 *pixels, u8 fontId, u8 *str)
temp = strLocal[strPos++]; temp = strLocal[strPos++];
switch (temp) switch (temp)
{ {
case 0xFC: case EXT_CTRL_CODE_BEGIN:
temp2 = strLocal[strPos++]; temp2 = strLocal[strPos++];
switch (temp2) switch (temp2)
{ {
@ -3421,16 +3421,16 @@ u8 RenderTextFont9(u8 *pixels, u8 fontId, u8 *str)
continue; continue;
} }
break; break;
case 0xF7: case CHAR_SPECIAL_F7:
case 0xF8: case CHAR_SPECIAL_F8:
case 0xF9: case CHAR_SPECIAL_F9:
case 0xFD: case PLACEHOLDER_BEGIN:
++strPos; ++strPos;
break; break;
case 0xFA: case CHAR_PROMPT_SCROLL:
case 0xFB: case CHAR_PROMPT_CLEAR:
case 0xFE: case CHAR_NEWLINE:
case 0xFF: case EOS:
break; break;
default: default:
switch (fontId) switch (fontId)
@ -3450,7 +3450,7 @@ u8 RenderTextFont9(u8 *pixels, u8 fontId, u8 *str)
break; break;
} }
} }
while (temp != 0xFF); while (temp != EOS);
RestoreTextColors(&colorBackup[0], &colorBackup[1], &colorBackup[2]); RestoreTextColors(&colorBackup[0], &colorBackup[1], &colorBackup[2]);
return 1; return 1;